@ -17,137 +17,137 @@
focusColor : "#333"
focusColor : "#333"
//blurColor: "#999
//blurColor: "#999
} ;
} ;
var settings = $ . extend ( { } , defaults , options || { } ) ;
// var settings = $.extend({}, defaults, options || {});
//页面装载CSS样式
// //页面装载CSS样式
if ( settings . autoClass && $ ( "#mailListAppendCss" ) . size ( ) === 0 ) {
// if(settings.autoClass && $("#mailListAppendCss").size() === 0){
$ ( '<style id="mailListAppendCss" type="text/css">.mailListBox{border:1px solid #369; background:#fff; font:12px/20px Arial;}.mailListDefault{padding:0 5px;cursor:pointer;white-space:nowrap;}.mailListFocus{padding:0 5px;cursor:pointer;white-space:nowrap;background:#369;color:white;}.mailListHlignt{color:red;}.mailListFocus .mailListHlignt{color:#fff;}</style>' ) . appendTo ( $ ( "head" ) ) ;
// $('<style id="mailListAppendCss" type="text/css">.mailListBox{border:1px solid #369; background:#fff; font:12px/20px Arial;}.mailListDefault{padding:0 5px;cursor:pointer;white-space:nowrap;}.mailListFocus{padding:0 5px;cursor:pointer;white-space:nowrap;background:#369;color:white;}.mailListHlignt{color:red;}.mailListFocus .mailListHlignt{color:#fff;}</style>').appendTo($("head"));
}
// }
var cb = settings . boxClass , cl = settings . listClass , cf = settings . focusClass , cm = settings . markCalss ; //插件的class变量
// var cb = settings.boxClass, cl = settings.listClass, cf = settings.focusClass, cm = settings.markCalss; //插件的class变量
var z = settings . zIndex , newArr = mailArr = settings . mailArr , hint = settings . textHint , text = settings . hintText , fc = settings . focusColor , bc = settings . blurColor ;
// var z = settings.zIndex, newArr = mailArr = settings.mailArr, hint = settings.textHint, text = settings.hintText, fc = settings.focusColor, bc = settings.blurColor;
//创建邮件内部列表内容
//创建邮件内部列表内容
$ . createHtml = function ( str , arr , cur ) {
// $.createHtml = function(str, arr, cur){
var mailHtml = "" ;
// var mailHtml = "";
if ( $ . isArray ( arr ) ) {
// if($.isArray(arr)){
$ . each ( arr , function ( i , n ) {
// $.each(arr, function(i, n){
if ( i === cur ) {
// if(i === cur){
mailHtml += '<div class="mailHover ' + cf + '" id="mailList_' + i + '"><span class="' + cm + '">' + str + '</span>@' + arr [ i ] + '</div>' ;
// mailHtml += '<div class="mailHover '+cf+'" id="mailList_'+i+'"><span class="'+cm+'">'+str+'</span>@'+arr[i]+'</div>';
} else {
// }else{
mailHtml += '<div class="mailHover ' + cl + '" id="mailList_' + i + '"><span class="' + cm + '">' + str + '</span>@' + arr [ i ] + '</div>' ;
// mailHtml += '<div class="mailHover '+cl+'" id="mailList_'+i+'"><span class="'+cm+'">'+str+'</span>@'+arr[i]+'</div>';
}
// }
} ) ;
// });
}
// }
return mailHtml ;
// return mailHtml;
} ;
// };
//一些全局变量
//一些全局变量
var index = - 1 , s ;
var index = - 1 , s ;
$ ( this ) . each ( function ( ) {
// $(this).each(function(){
var that = $ ( this ) , i = $ ( ".justForJs" ) . size ( ) ;
// var that = $(this), i = $(".justForJs").size();
if ( i > 0 ) { //只绑定一个文本框
// if(i > 0){ //只绑定一个文本框
return ;
// return;
}
// }
var w = that . outerWidth ( ) , h = that . outerHeight ( ) ; //获取当前对象(即文本框)的宽高
// var w = that.outerWidth(), h = that.outerHeight(); //获取当前对象(即文本框)的宽高
//样式的初始化
// //样式的初始化
that . wrap ( '<span style="display:inline-block;position:relative;"></span>' )
// that.wrap('<span style="display:inline-block;position:relative;"></span>')
. before ( '<div id="mailListBox_' + i + '" class="justForJs ' + cb + '" style="min-width:' + w + 'px;_width:' + w + 'px;position:absolute;left:-6000px;top:' + h + 'px;z-index:' + z + ';"></div>' ) ;
// .before('<div id="mailListBox_'+i+'" class="justForJs '+cb+'" style="min-width:'+w+'px;_width:'+w+'px;position:absolute;left:-6000px;top:'+h+'px;z-index:'+z+';"></div>');
var x = $ ( "#mailListBox_" + i ) , liveValue ; //列表框对象
// var x = $("#mailListBox_" + i), liveValue; //列表框对象
that . focus ( function ( ) {
// that.focus(function(){
//父标签的层级
// //父标签的层级
$ ( this ) . css ( "color" , fc ) . parent ( ) . css ( "z-index" , z ) ;
// $(this).css("color", fc).parent().css("z-index", z);
//提示文字的显示与隐藏
// //提示文字的显示与隐藏
if ( hint && text ) {
// if(hint && text){
var focus _v = $ . trim ( $ ( this ) . val ( ) ) ;
// var focus_v = $.trim($(this).val());
if ( focus _v === text ) {
// if(focus_v === text){
$ ( this ) . val ( "" ) ;
// $(this).val("");
}
// }
}
// }
//键盘事件
// //键盘事件
$ ( this ) . keyup ( function ( e ) {
// $(this).keyup(function(e){
s = v = $ . trim ( $ ( this ) . val ( ) ) ;
// s = v = $.trim($(this).val());
if ( /@/ . test ( v ) ) {
// if(/@/.test(v)){
s = v . replace ( /@.*/ , "" ) ;
}
if ( v . length > 0 ) {
//如果按键是上下键
if ( e . keyCode === 38 ) {
//向上
if ( index <= 0 ) {
index = newArr . length ;
}
index -- ;
} else if ( e . keyCode === 40 ) {
//向下
if ( index >= newArr . length - 1 ) {
index = - 1 ;
}
index ++ ;
} else if ( e . keyCode === 13 ) {
//回车
if ( index > - 1 && index < newArr . length ) {
//如果当前有激活列表
$ ( this ) . val ( $ ( "#mailList_" + index ) . text ( ) ) ;
}
} else {
if ( /@/ . test ( v ) ) {
index = - 1 ;
//获得@后面的值
// s = v.replace(/@.*/, "");
// s = v.replace(/@.*/, "");
//创建新匹配数组
// }
var site = v . replace ( /.*@/ , "" ) ;
// if(v.length > 0){
newArr = $ . map ( mailArr , function ( n ) {
// //如果按键是上下键
var reg = new RegExp ( site ) ;
// if(e.keyCode === 38){
if ( reg . test ( n ) ) {
// //向上
return n ;
// if(index <= 0){
}
// index = newArr.length;
} ) ;
// }
} else {
// index--;
newArr = mailArr ;
// }else if(e.keyCode === 40){
}
// //向下
}
// if(index >= newArr.length - 1){
x . html ( $ . createHtml ( s , newArr , index ) ) . css ( "left" , 0 ) ;
// index = -1;
if ( e . keyCode === 13 ) {
// }
//回车
// index++;
if ( index > - 1 && index < newArr . length ) {
// }else if(e.keyCode === 13){
//如果当前有激活列表
// //回车
x . css ( "left" , "-6000px" ) ;
// if(index > -1 && index < newArr.length){
}
// //如果当前有激活列表
}
// $(this).val($("#mailList_"+index).text());
} else {
// }
x . css ( "left" , "-6000px" ) ;
// }else{
}
// if(/@/.test(v)){
} ) . blur ( function ( ) {
// index = -1;
if ( hint && text ) {
// //获得@后面的值
var blur _v = $ . trim ( $ ( this ) . val ( ) ) ;
// //s = v.replace(/@.*/, "");
if ( blur _v === "" ) {
// //创建新匹配数组
$ ( this ) . val ( text ) ;
// var site = v.replace(/.*@/, "");
}
// newArr = $.map(mailArr, function(n){
}
// var reg = new RegExp(site);
$ ( this ) . css ( "color" , bc ) . unbind ( "keyup" ) . parent ( ) . css ( "z-index" , 0 ) ;
// if(reg.test(n)){
x . css ( "left" , "-6000px" ) ;
// return n;
// }
} ) . keydown ( function ( event ) {
// });
if ( event . keyCode == 13 ) {
// }else{
return false ;
// newArr = mailArr;
}
// }
} ) ;
// }
//鼠标经过列表项事件
// x.html($.createHtml(s, newArr, index)).css("left", 0);
//鼠标经过
// if(e.keyCode === 13){
$ ( ".mailHover" ) . on ( "mouseover" , function ( ) {
// //回车
index = Number ( $ ( this ) . attr ( "id" ) . split ( "_" ) [ 1 ] ) ;
// if(index > -1 && index < newArr.length){
liveValue = $ ( "#mailList_" + index ) . text ( ) ;
// //如果当前有激活列表
x . children ( "." + cf ) . removeClass ( cf ) . addClass ( cl ) ;
// x.css("left", "-6000px");
$ ( this ) . addClass ( cf ) . removeClass ( cl ) ;
// }
} ) ;
// }
$ ( ".mailHover" ) . on ( "click" , function ( ) {
// }else{
$ ( "#mail" ) . val ( $ ( this ) . html ( ) ) ;
// x.css("left", "-6000px");
} ) ;
// }
// }).blur(function(){
// if(hint && text){
} ) ;
// var blur_v = $.trim($(this).val());
// if(blur_v === ""){
x . bind ( "mousedown" , function ( ) {
// $(this).val(text);
that . val ( liveValue ) ;
// }
} ) ;
// }
} ) ;
// $(this).css("color", bc).unbind("keyup").parent().css("z-index",0);
// x.css("left", "-6000px");
//
// }).keydown(function(event){
// if(event.keyCode == 13){
// return false;
// }
// });
// //鼠标经过列表项事件
// //鼠标经过
// $(".mailHover").on("mouseover", function(){
// index = Number($(this).attr("id").split("_")[1]);
// liveValue = $("#mailList_"+index).text();
// x.children("." + cf).removeClass(cf).addClass(cl);
// $(this).addClass(cf).removeClass(cl);
// });
// $(".mailHover").on("click", function(){
// $("#mail").val($(this).html());
// });
//
//
// });
//
// x.bind("mousedown", function(){
// that.val(liveValue);
// });
// });
} ;
} ;
} ) ( jQuery ) ;
} ) ( jQuery ) ;