+function ($) {
"use strict";
$.format = function(o) {
var newObj = {
success: 0
},
str = o;
if (typeof str == "undefined") {
return newObj;
}
if (str.indexOf("{") != -1) {
str = str.substring(str.indexOf("{"), str.lastIndexOf("}") + 1);
newObj = $.extend({}, newObj, str.toJSON());
newObj.success = 1;
}
return newObj;
};
$.fn.Options = function(options) {
return options == null ? $.format($(this).attr("class")) : (typeof(options) == "object" ? options : $.format($(this).attr(options)));
};
}($);
(function(){
String.prototype.trim = function() {
return this.replace(/^\s+/, "").replace(/\s+$/, "");
};
String.prototype.isEmpty = function() {
var s = this.trim();
return s.length == 0;
};
String.prototype.toText = function() {
var str = this;
str = str.replace(//g, ">");
str = str.replace(/\n\r/g, "
");
str = str.replace(/\n/g, "
");
str = str.replace(/\r/g, "
");
return str;
};
String.prototype.toHtml = function() {
var str = this;
str = str.replace(/</g, "<");
str = str.replace(/>/g, ">");
str = str.replace(/\n\r/g, "
");
str = str.replace(/\n/g, "
");
str = str.replace(/\r/g, "
");
return str;
};
String.prototype.format = function(args) {
var result = this;
if (arguments.length > 0) {
if (arguments.length == 1 && typeof(args) == "object") {
for (var key in args) {
if (args[key] != undefined) {
var reg = new RegExp("({" + key + "})", "g");
result = result.replace(reg, args[key]);
}
}
} else {
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] != undefined) {
var regStr = "",
num = i.toString();
for (j = 0; j < num.length; j++) {
regStr += "[" + num.substr(j, 1) + "]{1}";
}
var reg = new RegExp("{" + regStr + "}", "g");
result = result.replace(reg, arguments[i]);
}
}
}
}
return result;
};
String.prototype.formatMoney = function(s) {
var num = this.toString().replace(/[^\d.]/g, "").split("."),
s = s || "";
num.length = 2;
num = num.join(".");
if (isNaN(num)) {
num = "0";
}
var sign = (num == (num = Math.abs(num)));
num = Math.floor(num * 100 + 0.50000000001);
var cents = num % 100;
num = Math.floor(num / 100).toString();
if (cents < 10) {
cents = "0" + cents;
}
for (var i = 0, j = Math.floor((num.length - (1 + i)) / 3); i < j; i++) {
num = num.substring(0, num.length - (4 * i + 3)) + s + num.substring(num.length - (4 * i + 3));
}
return (((sign) ? '' : '-') + num + '.' + cents);
};
String.prototype.toMoney = function(s) {
var str = this.toString().replace(/[^\d.]/g, "").split(".");
str.length = 2, s = s || "", num = ((str[0] || 0) * 1000 / 1000).toString();
str[1] = str[1] || 0;
str[1] = Number("0." + str[1]).toString().substring(2, str[1].length + 2);
var nums = this.toString().substr(0, 1) == '-' ? true : false;
if (str[1].length < 2) {
for (var i = str[1].length; i < 2; i++) {
str[1] += "0";
}
}
for (var i = 0, j = Math.floor((num.length - (1 + i)) / 3); i < j; i++) {
num = num.substring(0, num.length - (4 * i + 3)) + s + num.substring(num.length - (4 * i + 3));
}
str[0] = num;
return (nums ? "-" : "") + str.join(".");
};
Number.prototype.toMoney = String.prototype.toMoney;
Number.prototype.formatMoney = String.prototype.formatMoney;
Date.prototype.Format = function(format) {
var format = format || "yyyy-MM-dd hh:mm:ss",
o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length))
}
}
return format;
};
String.prototype.toDate = function(f) {
return new Date(parseInt(this) * 1000).Format(f || "yyyy-MM-dd hh:mm:ss");
};
Date.prototype.add = function(milliseconds){
var m = this.getTime() + milliseconds;
return new Date(m);
};
Date.prototype.addSeconds = function(second){
return this.add(second * 1000);
};
Date.prototype.addHours = function(hour){
return this.addMinutes(hour*60);
};
Date.prototype.addMinutes = function(minute){
return this.addSeconds(minute*60);
};
Date.prototype.addDate = function(format) {
var format = parseInt(format, 10) || 0,
time = 0;
time = this.getTime() + (format * 60 * 60 * 24 * 1000);
return new Date(time);
};
String.prototype.dateDiff = function(date, interval) {
var objInterval = {
'D': 1000 * 60 * 60 * 24,
'H': 1000 * 60 * 60,
'M': 1000 * 60,
'S': 1000,
'T': 1
},
Time = (interval || "D").toUpperCase(),
start = new Date(this.replace(/-/g, "/")),
end = new Date(date.replace(/-/g, "/"));
try {
return Math.round((end.getTime() - start.getTime()) / parseInt(eval("objInterval." + Time), 10));
} catch (e) {
return e.message;
}
};
String.prototype.decode = function(args) {
var result = this;
if (arguments.length > 0) {
if (arguments.length == 1) {
result = args;
} else {
for (var i = 0; i < arguments.length; i = i + 2) {
if (arguments[i] != undefined) {
if (arguments[i + 1] != undefined) {
if (result == arguments[i]) {
result = arguments[i + 1];
break;
}
} else {
result = arguments[i];
}
}
}
}
}
return result;
}
String.prototype.toJSON = function() {
return new Function("return " + this.toText())();
};
String.prototype.unhtml = function(reg) {
return this ? this.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp|#\d+);)?/g, function (a, b) {
if (b) {
return a;
} else {
return {
'<':'<',
'&':'&',
'"':'"',
'>':'>',
"'":'''
}[a]
}
}) : '';
};
String.prototype.html = function() {
return this ? this.replace(/&((g|l|quo)t|amp|#39|nbsp);/g, function (m) {
return {
'<':'<',
'&':'&',
'"':'"',
'>':'>',
''':"'",
' ':' '
}[m]
}) : '';
};
$.showIndicator = function () {
$(document.body).append('
');
};
$.hideIndicator = function () {
$('.preloader-indicator-overlay, .preloader-indicator-modal').remove();
};
})(jQuery);
+function ($) {
"use strict";
$.cookie = {
set:function(name, value, iDay){
iDay = iDay || 1;
var oDate=new Date();
oDate.setDate(oDate.getDate()+iDay);
document.cookie=name+'='+encodeURIComponent(value)+';expires='+oDate;
},
get:function(name){
var arr=document.cookie.split('; ');
var i=0;
for(i=0;ia").live("click",function(){
var $this = $(this),
childNode = $this.parent().children("ul");
if(childNode.length > 0){
$("ul",_this).addClass("contentTxt");
$(_this).find(">li>a").removeClass("active");
childNode.removeClass("contentTxt");
$($this).addClass("active");
}
});
}
}($);
+function ($) {
"use strict";
$.fn.serializeJSON = function(options){
var $this = $(this),
opts = $.fn.Options.call(this, options),
data = opts.data || $this.serializeArray(),
list = [];
$.each(data, function(i, filed){
list.push('"'+filed.name+'":"'+filed.value.trim().unhtml()+'"');
});
var newdata = "{" + list.join(',') + "}";
return newdata.toJSON();
}
}($);
/*input tip检测下拉*/
+function ($) {
"use strict";
$.fn.autocomplete = function(urlOrData, options) {
var isUrl = typeof urlOrData == "string";
options = jQuery.extend({}, jQuery.Autocompleter.defaults, {
url: isUrl ? urlOrData : null,
data: isUrl ? null : urlOrData,
delay: isUrl ? jQuery.Autocompleter.defaults.delay : 10,
max: options && !options.scroll ? 10 : 150
}, options);
// if highlight is set to false, replace it with a do-nothing function
options.highlight = options.highlight ||
function(value) {
return value;
};
// if the formatMatch option is not specified, then use formatItem for backwards compatibility
options.formatMatch = options.formatMatch || options.formatItem;
return this.each(function() {
new jQuery.Autocompleter(this, options);
});
}
$.fn.result = function(handler) {
return this.bind("result", handler);
}
$.fn.search = function(handler) {
return this.trigger("search", [handler]);
}
$.fn.flushCache = function() {
return this.trigger("flushCache");
}
$.fn.setOptions = function(options) {
return this.trigger("setOptions", [options]);
},
$.fn.unautocomplete = function() {
return this.trigger("unautocomplete");
}
}($);
/*
url -- ajax查询数据地址
length -- 输入的字符长度搜索
returnId -- 接收返回数据ID
width -- 下拉列表的宽度
fun -- 回调方法
是否展示可输的下拉菜单
*/
+function ($) {
"use strict";
$.fn.inputTips = function(url, len, back, width, fun, clickStatus) {
var url = url || "",
back = back || "",
len = len || 2,
width = width || 166,
clickStatus = clickStatus == null ? false : clickStatus;
if (url == "") {
return false;
}
$(this).unbind();
$(this).autocomplete(url, {
"max": 30,
"minChars": len,
"clickStatus":clickStatus,
"width": width,
"dataType": "json",
parse: function(data) {
return $.map(data.d.list, function(item, row) {
return {
data: item,
value: item.value,
result: item.text
}
});
},
formatItem: function(item, i, max) {
return item.text;
}
}).result(function(e, data, formatted) {
if (back != "") {
$(back).val(data.id);
}
if (fun != null) {
fun.call(this, data);
}
}).focusout(function() {
var val = $(this).val().trim();
if (back != "" && val == "") {
$(back).val("");
}
if (fun != null && val == "") {
fun.call(this, {});
}
}).keyup(function() {
var val = $(this).val().trim();
if (back != "" && val == "") {
$(back).val("");
}
});
}
}($);
/*输入强制转换数字类型*/
+function ($) {
"use strict";
$.fn.number = function(options) {
if (typeof options === 'function') {
var opts = {
fun: options
};
} else {
var opts = $.fn.Options.call(this, options);
opts = $.extend({}, {
fun: null
}, opts);
};
$(this).bind('keyup afterpaste focusout', function(e) {
var oldVal = this.value,
val = oldVal.replace(/[^\d.]/g, '').replace(/^\./g, "").replace(/\.{2,}/g, ".").replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
opts.place && val > opts.place ? this.value = "":"";
if (e.type == 'focusout') {
if (typeof opts.fun === 'function') {
var val = this.value * 1;
opts.fun.call(this, val);
};
};
if (oldVal != val) {
this.value = val;
};
});
}
}($);
+function ($) {
"use strict";
$.fn.hoverTable = function(tr) {
var $Class = $(this),
tr = tr || false;
$Class.find("tbody").find("tr").removeClass("trSplit").off("click mouseenter mouseleave");
if (tr) {
$Class.each(function(index, element) {
$(this).find("thead").find("th").last().addClass("lastTh");
$Class.eq(index).find("tbody").find("tr").each(function(i, element) {
if (i % 2 == 1) {
$(this).addClass("trSplit");
}
});
});
}
$Class.find("tbody").find("tr").bind({
mouseenter: function() {
$(this).addClass("trHover");
},
mouseleave: function() {
$(this).removeClass("trHover");
}
});
}
}($);
/*没有数据时显示提示*/
+function ($) {
"use strict";
$.fn.info = function(msg, type) {
var $this = $(this), msg = msg || '', $thead = $this.closest("table").find("thead");
if(type == 1){
$this.addClass("noInfo").html(""+msg);
}else{
if($thead.length > 0)
$this.html(""+msg+" |
");
else
$this.html(""+msg+" |
");
}
}
}($);
/*获取地址栏参数值*/
+function ($) {
"use strict";
$.getParam = function(name){
var url = window.location.href,
urlArr = url.split("?");
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
if(urlArr.length > 1){
var r = urlArr[1].match(reg);
if (r != null) return unescape(encodeURIComponent(r[2])); return null;
}else
return null;
}
}($);
+function ($) {
"use strict";
uiAlert.MyAlert = function(json, flag, fun) {
var fun = fun || null,
flag = flag || (json != undefined && json.flag || 0);
uiAlert.first(new uiAlert.Tostring(typeof(json) != "object" ? "" + json + "" : json), flag, fun);
};
window.alert = uiAlert.MyAlert;
$.fn.alert = function(options) {
return this.each(function(e) {
var name = new uiAlert.Tostring(options);
uiAlert.first(name, e);
});
}
}($);
function uiAlert(data, flag) {
this.data = data;
this.flag = flag || data.flag;
if (typeof uiAlert._initialized == "undefined") {
uiAlert.prototype.Append = function() {
// 创建弹出
// $(".Uialert_Bbox").length > 0 ? $(".Uialert_Bbox").remove() : "";
uiAlert.Close();
$("body").append("");
// 创建盒子
var $Box = $(".Uialert_box");
//$Box.append("" + this.data.title + "关闭 ");
// 创建title
$Box.append("
"+(this.data.title != "" ? "
" + this.data.title + "
":"") + this.data.nav + "
");
// 创建正文
$Box.append("");
// 创建底部按钮
$(".Uialert_bj").fadeTo(0, this.data.opacity);
// 更改遮挡层透明度
$(".Uialert_Bbox").show();
$Box.fadeIn(300);
uiAlert.ChangeCss();
// 更改css
this.B_Click();
// 绑定点击事件
this.Auto();
// 绑定自动关闭事件
uiAlert.next = this.data.next;
// 光标焦点处于按钮上
$(".Uialert_button>input").focus();
};
uiAlert.prototype.Auto = function() {
// 自动
if (this.data.close) {
var AutoT = null;
AutoT = setTimeout(function() {
clearTimeout(AutoT);
uiAlert.GoNext();
},
this.data.time);
}
};
uiAlert.prototype.B_Click = function() {
// 点击遮挡层
var z = $(".Uialert_title").css("background-color");
$(".Uialert_Bbox,#TB_HideSelect body").bind({
click: function() {
$(".Uialert_Binput").focus();
}
});
};
uiAlert._initialized = true;
}
}
uiAlert._object = function(){
var obj = {box:document.body};
obj.type = false;
obj.height = $(obj.box).outerHeight();
obj.width = $(obj.box).outerWidth();
obj.top = $(obj.box).offset().top;
obj.left = $(obj.box).offset().left;
uiAlert.object = obj;
}
uiAlert.Tostring = function(o) {
this.nav = typeof o == "object" ? o.nav.replace(/\n\r/g, "
").replace(/\n/g, "
").replace(/\r/g, "
") : o.replace(/\n\r/g, "
").replace(/\n/g, "
").replace(/\r/g, "
");
// 替换\n为
this.close = o.close || false;
this.time = o.time || 3000;
this.title = o.title || "提示";
this.opacity = o.opacity || 0.3;
this.next = o.next || function() {};
this.flag = o.flag || false;
return {
"nav": this.nav,
"close": this.close,
"time": this.time,
"title": this.title,
"opacity": this.opacity,
"next": this.next,
"flag": this.flag
};
};
uiAlert.first = function(data, n, fun) {
// 添加和执行处理
if (typeof fun == "function") {
data.next = fun;
}
var Alert = new uiAlert(data, n);
Alert.Append();
};
uiAlert.GoNext = function() {
uiAlert.Close();
uiAlert.next();
};
uiAlert.ChangeCss = function() {
// 更改css
$(window).resize(uiAlert.ChangeCss);
// 当window窗口变化时
if (typeof uiAlert.object == "undefined" || uiAlert.object.type) {
var $Box = $(".Uialert_box");
$(".Uialert_Bbox,.Uialert_bj").css({
"height": $(window).height()
});
$Box.css({
// 重置提示框位置
"top": ((window.screen.availHeight - $Box.height()) / 2),
"left": (($(window).width() - $Box.width()) / 2)
});
} else {
$(".Uialert_Bbox").css({
position: "absolute",
top: uiAlert.object.top,
left: uiAlert.object.left,
height: uiAlert.object.height,
width: uiAlert.object.width
});
}
};
uiAlert.ie = function() {
var userAgent = navigator.userAgent.toLowerCase();
$.browser = {
version: (userAgent.match( /.+(?:rv|it|ra|ie)[/: ]([d.]+)/ ) || [])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)
};
!$.browser.msie ? "" : ($.browser.version == 6.0 ? uiAlert.scroll() : "");
// 当ie6时绑定
};
uiAlert.B_Click_ = function(x, y, z) {
// 更改背景色触发
var x = x,
y = y,
T = null,
z = z;
clearInterval(T);
T = setInterval(function() {
if (x <= y) {
uiAlert.Change_b();
x++;
} else {
$(".Uialert_title").css({
"background-color": z
});
clearInterval(T);
}
},
100);
};
uiAlert.Change_b = function() {
// 更改背景颜色
$(".Uialert_title").css({
"background-color": "rgb(" + uiAlert.B_Click_B() + "," + uiAlert.B_Click_B() + "," + uiAlert.B_Click_B() + ")"
});
};
uiAlert.B_Click_B = function() {
// 随机数字_背景色
return Math.round(Math.random() * 255);
};
uiAlert.Close = function() {
// 关闭
$(".Uialert_Bbox").remove();
if (typeof uiAlert.scroll._init != "undefined") {
$("html").css("overflow", "");
delete uiAlert.scroll._init;
}
$(window).unbind("resize scroll");
typeof uiAlert.object != "undefined" ? delete uiAlert.object : "";
if (typeof CollectGarbage != "undefined") {
CollectGarbage();
}
};
uiAlert.scroll = function() {
// 绑定滚动条滚动事件
if (typeof uiAlert.scroll._init == "undefined") {
// iframe to hide select elements in ie6
// $("html").css("overflow","hidden");
$(".Uialert_Bbox").append("");
uiAlert.scroll._init = true;
}
uiAlert.scroll.css();
$(window).bind({
scroll: function() {
uiAlert.scroll.css();
}
});
};
uiAlert.scroll.css = function() {
$(".Uialert_Bbox").css({
"top": $(window).scrollTop()
});
};
+function ($) {
"use strict";
uiConfirm.MyConfirm = function(n, fun, o) {
var o = o || true;
if (typeof fun == "undefined") {
top.uiConfirm.type = false;
} else if (typeof fun == "function") {
uiConfirm.type = true;
uiConfirm.fun = fun;
}
o == true ? uiConfirm.call(this, uiConfirm.toJson(n, name)) : _confirm(n);
};
window.confirm = uiConfirm.MyConfirm;
$.fn.uiConfirm = function(options) {
return this.each(function(e) {
var name = uiConfirm.toJson(options);
uiConfirm(name, e);
});
}
$.fn.uiConfirm.defaults = {
title: "温馨提示", // 标题
content: "", // 确认提示内容
width: 350,
data: null, // 开放自定义接口,为方法之间数据传输
opacity: 0.1,
button: 0, // 确认回调方法 0/1,0表示取消,1表示确认
flag:1,
fontcolor:"#434343",
alertsubmit:'确认',
alertcancle:'取消',
fun: false // 用户选择后回调方法
};
}($);
function uiConfirm(n) {
var data = n || $.fn.uiConfirm.defaults;
uiConfirm.data = data;
this._init = function() {
uiAlert.Close();
var $Uialert_Bbox = $("");
// 创建盒子
var $Box = $Uialert_Bbox.find(".Uialert_box");
// 创建title
$Box.append(""+(data.title != "" ? "
" + data.title + "
":"") + data.content + "
");
// 创建正文
$Box.append("");
// 创建底部按钮
$("body").append($Uialert_Bbox);
$(".Uialert_bj").fadeTo(0, data.opacity);
// 更改遮挡层透明度
$(".Uialert_Bbox").show();
$Box.fadeIn(300);
this.ChangeCss();
// 光标焦点处于取消按钮上
$(".Uialert_button>input").eq(0).focus();
};
this.ChangeCss = function() {
// 更改css
$(window).resize(this.ChangeCss);
// 当window窗口变化时
var $Box = $(".Uialert_box");
$(".Uialert_Bbox,.Uialert_bj").css({
"height": $(window).height()
});
$Box.css({
// 重置提示框位置
"top": ((window.screen.availHeight - $Box.height()) / 2),
"left": (($(window).width() - $Box.width()) / 2)
});
uiAlert.ie();
};
this._init();
}
uiConfirm.data = {};
uiConfirm.close = function(type) {
this.data.button = type || 0;
uiAlert.Close();
if (uiConfirm.type && this.data.button) {
uiConfirm.fun();
return false;
} else if (uiConfirm.data.fun) {
uiConfirm.data.fun.call(this.data, this.data.button);
}
};
uiConfirm.toJson = function(n, name) {
if (typeof n == "object") {
$.fn.uiConfirm.defaults = $.extend({}, $.fn.uiConfirm.defaults, n);
} else {
$.fn.uiConfirm.defaults.content = n;
}
$.fn.uiConfirm.defaults.content = $.fn.uiConfirm.defaults.content.toHtml();
return $.fn.uiConfirm.defaults;
};
/*
错误提示
*/
+function ($) {
"use strict";
$.fn.tips = function(msg, callback){
var $this = $(this),
text = "";
$this.html(text);
$(".errorTips").fadeIn("last");
typeof callback == "function" ? callback.call(this) : "";
$(".errorTips .owClose").live("click",$.closeTips);
}
$.closeTips = function(){
$(this).closest(".errorTips").fadeOut('fast',function(){
$(this).remove();
});
};
}($);
/*
设置input提示语
*/
+function ($) {
"use strict";
$.fn.input = function(options) {
return this.each(function(e) {
var opts = $.fn.Options.call(this, options);
opts = $.extend({}, {text: "", color: "#c5c5c5"}, opts);
new fInput(this, opts);
});
}
function fInput(o, opts) {
var $this = $(o),
padding = parseInt(getCss(o, "paddingLeft")),
width = $this.outerWidth() - padding,
height = $this.outerHeight(),
top = $this.position().top,
left = $this.position().left + parseInt(getCss(o, "marginLeft")),
vid = $this.attr("id") || "";
if (typeof fInput._init == "undefined") {
fInput.num = 0;
fInput._init = true;
} else {
fInput.num++;
}
if (vid == "") {
vid = "input" + fInput.num;
$this.attr("id", vid);
}
$this.attr("data-input", "lInput" + fInput.num).after("");
if ($this.val() != "") {
$("#lInput" + fInput.num).hide().text("");
}
$this.bind({
keyup: function() {
var length = o.value.length,
id = "#" + $this.attr("data-input");
if (length > 0) {
$(id).hide().text("");
} else {
$(id).show().text(opts.text);
}
},
click: function() {
var id = "#" + $this.attr("data-input"),
length = o.value.length;
if (length <= 0) $(id).hide().text("");
},
blur: function() {
var id = "#" + $this.attr("data-input"),
length = o.value.length;
if (length <= 0) $(id).show().text(opts.text);
}
});
}
function getCss(o, key) {
return o.currentStyle ? o.currentStyle[key] : document.defaultView.getComputedStyle(o, false)[key];
};
}($);
/*
初始化所有input textarea文件框
*/
+function ($) {
"use strict";
var resetText = function(o){
var o = o || ".text,.textarea";
$(o).each(function(i, item) {
var $this = $(this),
attr = $this.attr("icon") ? $this.attr("icon") : "",
Class = attr != "" ? " " + attr + "Lable" : "",
type = $this.attr("type") || "",
clone = $this.attr("copy") || false,
name = parseInt(Math.random() * 100000);
Class += type == "button" || type == "submit" ? " labelButton" : "";
if ($this.hasClass("textarea")) {
Class = " textareaRadius";
}
if (typeof $this.data("cache") == "undefined") {
$this.data("cache", "true");
if(clone){
var $obj = $this.parent().find("input[icon=" + clone + "]"),
$search = $("");
$obj.hide();
$this.wrap($("")).after($search).attr("autocomplete", "off");
$search.click(function() {
$obj.click();
});
new resetText.inputEnter({
input: this,
func: function() {
$obj.click();
}
});
}else{
$this.wrap(function() {
return "";
}).attr("tautocomplete", "off");
if($this.attr("arrow") == "true") $this.before("");
}
}
});
resetText.inputHover();
}
resetText.inputHover = function(){
$("input,.borderRadius").bind("mouseenter mouseleave", function(e) {
var Class = ($(this).attr("icon") || $(this).attr("type")) + "Hover";
if (e.type == "mouseenter") {
$(this).addClass(Class);
} else {
$(this).removeClass(Class);
}
});
}
resetText.inputEnter = function(obj) {
if (typeof obj != "object") {
return false;
}
var obj = $.extend({}, {input: false,func: false}, obj);
if (!obj.input) {
return false;
}
$(obj.input).bind({
keyup: function(event) {
var event = event || window.event;
if (event.keyCode == 13) {
obj.func.call(this);
}
}
});
};
$.resetText = resetText;
}($);
/*
重置系统复选框样式
*/
+function ($) {
"use strict";
$.fn.checkbox = function(options) {
return this.each(function() {
var opt = $.fn.Options.call(this, options);
opt = $.extend({}, {skin: "checkboxs", check: "check", disabled: "disabled", text: false, click: false, readonly: false}, opt);
var $this = this,
e = $(this),
next = e.next("label"),
text = opt.text === false ? e.val() : opt.text,
disabled = e.is(":disabled");
e.hide();
if (next.attr("data-d")) {
next.removeClass(opt.skin + "-" + opt.check);
next.unbind("click mouseover mouseout");
} else {
if (next.length <= 0) {
e.after("");
} else {
next.addClass(opt.skin).attr({
tabindex: 0,
unselectable: "on",
"data-d": "true"
});
}
}
// 重置label
next = e.next("label");
// 初始化
if (disabled == false) {
if (e.is(":checked")) {
next.addClass(opt.skin + "-" + opt.check);
}
} else {
next.addClass(opt.skin + "-" + opt.disabled);
}
// 移除只读复选框
if (opt.readonly && opt.remove) {
e.remove();
}
// 绑定事件
next.bind({
click: function(event) {
if (opt.readonly) {
return false;
}
if (e.is(":disabled")) {
alert(opt.alert);
return false;
}
if (!next.prev().is(':checked')) {
next.addClass(opt.skin + "-" + opt.check);
next.prev()[0].checked = true;
} else {
next.removeClass(opt.skin + "-" + opt.check);
next.prev()[0].checked = false;
}
if (opt.click == false) {
} else {
opt.click.call(this, $this);
}
}
});
});
}
$.checkbox = function(){
$("input[type='checkbox']").checkbox();
};
}($);
/*
重置系统单选按钮样式
*/
+function ($) {
"use strict";
$.fn.radio = function(options) { // 鍗曢€夋
return this.each(function(e) {
var opt = $.fn.Options.call(this, options);
opt = $.extend({}, {skin: "radiobox", check: "check", disabled: "disabled", text: false, alert: "已禁用", click: false, readonly: false, remove: true}, opt);
var $this = this,
e = $(this),
next = e.next("label"),
text = opt.text === false ? e.val() : opt.text,
disabled = e.is(":disabled");
e.hide();
if (next.attr("data-d")) {
next.removeClass(opt.skin + "-" + opt.check);
next.unbind("click mouseover mouseout");
} else {
if (next.length <= 0) {
e.after("");
} else {
next.attr("data-d", "true").addClass(opt.skin);
}
}
// 重置label
next = e.next("label");
// 初始化
if (disabled == false) {
if (e.is(":checked")) {
next.addClass(opt.skin + "-" + opt.check);
}
} else {
next.addClass(opt.skin + "-" + opt.disabled);
}
// 移除只读复选框
// if(opt.readonly){
// e.remove();
// }
// 绑定事件
next.bind({
click: function(event) {
if (opt.readonly) {
return false;
}
if (e.is(":disabled")) {
// alert(opt.alert);
return false;
}
next.addClass(opt.skin + "-" + opt.check).siblings().removeClass(opt.skin + "-" + opt.check);
if (!next.prev().is(':checked')) {
next.prev()[0].checked = true;
}
if (opt.click === false) {
} else {
opt.click.call(this, $this);
}
}
});
});
}
$.radio = function(){
$("input[type='radio']").radio();
};
}($);
+function ($) {
"use strict";
$.fn.outClick = function(options) {
var name = $.extend({}, {idcache: "UiOutSide",remove: true,click: function() {}}, options),
$this = $(this);
name.obj = this;
if (typeof $this.data("idcache") == "undefined") {
setTimeout(function() {
name.clickNum = 0;
$this.data("idcache", name.idcache);
$this.find("*").data("idcache", name.idcache);
$(document).delegate("*", "mousedown", function(e) {
e = e || window.event;
var target = e.target || e.srcElement;
if ($(target).data("idcache") != name.idcache && $(name.obj).find(target).length <= 0 && name.clickNum == 0) {
name.click.call(this);
$this.removeClick();
name.clickNum++;
}
});
}, 50);
}
}
}($);
+function ($) {
"use strict";
$.fn.removeClick = function() {
$(this).removeData("idcache");
$(this).find("*").removeData("idcache");
$(document).undelegate("*", "mousedown");
}
}($);
/*
重置系统下拉菜单
*/
+function ($) {
"use strict";
$.fn.uiSelect = function(options) {
return this.each(function(e) {
typeof Select.Num == "undefined" ? Select.Num = 0 : Select.Num++;
var name = $.fn.Options.call(this, options),
index = Select.Num,
$this = $(this);
name = $.extend({}, {width: "100",height: "200",type: "click",change: true,onchange: false,ajax: false,box: null,input: false,text: ""}, name);
if ($this.data("ListNum") == undefined) {
$this.addClass("uiSelect" + index);
$this.data("ListNum", index);
} else {
index = $this.data("ListNum");
Select.Num--;
$this.find(".selectbox").remove();
}
name.box = ".uiSelect" + index;
if (name.change) {
Select(name, this, index);
}
});
}
function Select(data, obj, num) {
var Selected = null,
Option = [],
val = [],
box = data.box + " ",
$boxSelect = $(box + "select"),
boxHeight = new Array(),
text = "";
boxHeight[0] = parseInt(data.height, 10);
if ($boxSelect.length > 0) {
$boxSelect.hide();
Selected = $(data.box + " select option:selected").text();
text = data.input ? "" : "" + data.text + Selected + "";
$(obj).append("");
if (data.input) {
$("#selecttext" + num).bind({
keydown: function(e) {
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
if (keyCode == 13) {
return false;
}
},
focusout: function() {
var value = this.value;
if (!val.equal(value)) {
val.push(value);
$(box + ".selectul").find("li").removeClass("selected");
$(box + ".selectul li:eq(0)").after("" + value + "");
$(box + "select").append("");
Select.SelectLi(data, true);
}
}
});
}
// 创建select盒子
// 获取select项
$(box + "select option").each(function() {
var $this = $(this),
Class = $this.attr("selected") ? " class=\"optGroupLi selected\"" : " class=\"optGroupLi\"",
SelectVal = $this.text() || "",
icon = $this.attr("icon") ? "" : "";
if (SelectVal != "") {
// Option.push("" + SelectVal + "");
val.push(SelectVal);
Option.push("" + icon + SelectVal + "");
}
});
$(box + ".selectul").append(Option.join(""));
// 在指定class内添加select项
// 验证option高度
// boxHeight[1] = $(box + ".selectubox").height();
// boxHeight[2] = data.height = boxHeight[1] < boxHeight[0] &&
// boxHeight[1] != 0 ? boxHeight[1] : boxHeight[0];
// $(box + ".selectubox").height(boxHeight[2]);
// 执行绑定
Select.SelectOption(data, obj);
// 获取select分组
$(box + "select optgroup").each(function(i) {
var $this = $(this),
SelectVal = $this.attr("label") || "",
option = $this.find("option").eq(0).index(box + "select option");
$(box + ".selectul").find("li").eq(i + option).before($("" + SelectVal + ""));
});
}
}
$.uiSelect = function(){
$("select").uiSelect();
}
// 获取分组添加位置
Select.optgroup = function(a, c) {
for (var a = 0; a < c.length; a++) {
if (b == c[a]) {
return a;
break
}
}
};
// 绑定下拉
Select.SelectLi = function(data, type) {
var SelectTime = null,
$box = $(data.box + " .selecttbox"),
$option = $(data.box + " .selectubox"),
$ouclick = $(data.box + " .selectbox"),
_init = false,
hoverClass = "selecthover",
type = type || false,
Change = data.onchange ? data.onchange : ($(data.box + " select").attr("onChange") || false);
if (type) {
$(data.box + " .selectul li").unbind("mouseenter").unbind("mouseleave").unbind("click");
}
$(data.box + " .selectul li").bind({
// 选择项动作,以及点击项后触发动作
mouseenter: function() {
// 鼠标移入
$(this).addClass("Optionselect");
},
mouseleave: function() {
// 鼠标移出
$(this).removeClass("Optionselect");
},
click: function() {
// 鼠标点击
var $this = $(this),
Index = $this.index(data.box + " .optGroupLi");
$(data.box + " option").eq(Index).attr("selected", "selected"); // .siblings().removeAttr("selected");
// 控制select
if (data.input) {
$(data.box + " .selecttext").val($this.text());
} else {
$(data.box + " .selecttext").text(data.text + $this.text());
}
// 显示当前选择内容
$this.addClass("selected").siblings().removeClass("selected");
// 为当前选择添加指定class,并移除同辈元素的指定class
Selectremove();
if (typeof Change == "function") {
Change.call($(data.box + " select"));
}
}
});
function Selectremove() {
// 移出选择项盒子
$box.removeClass(hoverClass);
$option.css({
"top": "-9999px",
"left": "-9999px"
});
_init = false;
// 恢复初始默认状态
};
};
// select绑定
/**
* 2013-09-05 修正下拉项高度问题
*/
Select.SelectOption = function(data, obj) {
var SelectTime = null,
$box = $(data.box + " .selecttbox"),
$option = $(data.box + " .selectubox"),
$ouclick = $(data.box + " .selectubox"),
_init = false,
hoverClass = "selecthover";
if (data.type == "mouseover") {
// 根据用户自定义绑定动作
SelectBindM();
} else {
SelectBindC();
}
Select.SelectLi(data);
function SelectBindM() {
// 绑定鼠标移入显示选择项
$box.bind({
mouseenter: function() {
// 鼠标移入
var $this = this;
$(this).addClass(hoverClass);
SelectTime = setTimeout(function() {
SelectOver($this);
}, 300);
},
mouseleave: function() {
// 鼠标移出
_init ? "" : $box.removeClass(hoverClass);
clearTimeout(SelectTime);
}
});
};
function SelectBindC() {
// 绑定鼠标点击显示选择项
$box.bind({
mouseleave: function() {
// 鼠标移出
_init ? "" : $box.removeClass(hoverClass);
},
click: function() {
// 鼠标点击
_init ? "" : SelectOver(this);
},
mouseenter: function() {
// 鼠标移入
$(this).addClass(hoverClass);
}
});
};
function SelectOver(o) {
// 移入选择项盒子
_init = false;
SelectTop(o);
$ouclick.outClick({
click: function() {
Selectremove();
_init = false;
}
});
};
function Selectremove() {
// 移出选择项盒子
$box.removeClass(hoverClass);
$option.css({
"top": "-9999px",
"left": "-9999px"
});
_init = false;
// 恢复初始默认状态
};
function SelectTop(o) {
var $obj = $(o),
$window = $(window),
DHeight = $window.height() + $window.scrollTop(),
oTop = $obj.offset().top,
height = $(o).height(),
opHeight = $option.height(),
top = oTop + opHeight + height;
top = top > DHeight ? -opHeight : height;
$option.css({
"top": top,
"left": 0
});
return;
};
};
$.select = function(){
$(".select").uiSelect();
}
}($);
// 分页
/*
* count = 总数 page = 当前页码 pagesize = 每页条数 splitsize = 分页前后显示 使用示例: var newpage =
* new createPage(100,1,15,3); 输出: newpage.minHtml;//第n页/共n页
* newpage.pageHtml;//共技n条 当前第n/n页 每页n条 页码 重置分页 newpage.resetPage(页码); 输出: 同上
*/
var createPage = function(count, page, pagesize, splitsize, pageFun) {
this.pageFun = pageFun || "pageGo";
this.count = parseInt((count || 0), 10);
this.page = page || 1;
this.pagesize = pagesize || 15;
this.splitsize = splitsize || 3;
this.minTemplet = "第{0}页/共{1}页";
this.pageTemplet = "{4}";
//this.pageTemplet = "共计{0}条 当前第{1}/{2}页 每页{3}条 {4}";
this.minHtml = this.minTemplet;
this.pageHtml = this.pageTemplet.format(this.count, "{0}", "{1}", this.pagesize, "{2}");
this.init();
};
createPage.prototype = {
Size: function() { // 分页大小
this.pagelen = parseInt(this.count % this.pagesize > 0 ? this.count / this.pagesize + 1 : this.count / this.pagesize);
this.validatePage();
this.initPage();
},
initPage: function() { // 重置分页模板
this.minHtml = this.minTemplet.format(this.page, this.pagelen);
this.pageHtml = this.pageHtml.format(this.page, this.pagelen, "{0}");
},
concat: function() { // 装载分页链接
var s = this.page - this.splitsize < 1 ? 1 : this.page - this.splitsize,
e = this.page + this.splitsize > this.pagelen ? this.pagelen : this.page + this.splitsize,
html = "";
if(e > 0) html += "';
this.pageHtml = this.pageHtml.format(html);
},
validatePage: function() { // 验证有效分页
if (this.page > this.pagelen) {
this.page = this.pagelen;
}
},
resetPage: function(page) { // 切换分页
this.pageHtml = this.pageTemplet.format(this.count, "{0}", "{1}", this.pagesize, "{2}");
this.page = page || this.page;
this.initPage();
return this.concat();
},
init: function() { // 装载分页
this.Size();
return this.concat();
}
};
ajax = function(o, data, callBack) {
new ajax.ajax(o, data, callBack);
};
+function ($) {
"use strict";
ajax.ajax = function(o, data, callBack){
this.url = o.url || o;
this.type = o.type || "POST";
this.data = o.data || (data || "");
this.dataType = o.dataType || "json";
this.async = o.async || true;
this.loading = o.load == null ? true : o.load;
// this.contentType = o.contentType || "application/x-www-form-urlencoded";
this.callBack = o.callBack || callBack;
this.jsonp = o.jsonp || "";
typeof this.callBack == "undefined" ? this.callBack = ajax.ajaxback : "";
this.url = !this.url.isEmpty() ? (this.url.indexOf("?") != -1 ? this.url+"&t="+Math.random() : this.url+"?t="+Math.random()) : "";
var $this = this;
if (this.loading) $.showIndicator();
$.ajax({
url: $this.url,
type: $this.type,
data: $this.data,
//contentType: $this.contentType,
dataType: this.dataType,
jsonp : this.jsonp,
cache: false,
async:$this.async,
success: function(data) {
if(data.code == 100){
top.window.location.href = "/login.html";
return false;
}
setTimeout(function() {
$this.callBack.call(this, data);
}, 200);
},
error: function(xml, status) {
if (status == "error") {
try {
var json = eval("(" + xml.responseText + ")");
alert(json.Message + "\n" + json.StackTrace);
} catch (e) {
}
}
},
complete: function() {
if ($this.loading) {
$.hideIndicator();
}
}
});
}
ajax.ajaxback = function(o) {};
}($);
var windowIndex = 0,Windows = [null];
+function ($) {
"use strict";
$.openWindow = function(title,html,width,height,isUrl,fun,scrolling,flag){
var title = title || "",
html = html || "",
width = parseInt(width || 300) + "px",
height = parseInt(height || 100) + "px",
m_left = (top.$(document).width() - parseInt(width))/2 + "px",
m_top = ((document.documentElement.clientHeight || document.body.clientHeight) - parseInt(height))/2 + "px",
isUrl = isUrl || false,
flag = flag || 0,
scrolling = scrolling ? "yes" : "no";
windowIndex++;
if(isUrl){
html = '';
}
Windows[windowIndex] = new OpenWindow(title ,html,{
"width":width,
"height":height,
"top":m_top,
"left":m_left
},
(fun || null),flag);
}
$.closeWindow = function(){
Windows[windowIndex].close();
}
}($);
var OpenWindow = function(f, e, d, c, a) {
this.title = f || "";
this.name = parseInt(Math.random() * 100000);
this.defaults = {
left: "300px",
top: "100px",
width: "400px",
height: "400px"
};
this.flag = parseInt((a || 0), 10);
this.style = $.extend(this.defaults, (d || {}));
this.content = e;
this.type = typeof type == "undefined" ? "common": type;
this.height = $(document).height();
this.width = $(document).width();
this.fun = c || null;
this.init = function() {
var h = $(".owBj").length > 0 ? "none": "block";
var g = '\n\
';
if(this.title != "") g+='
' + this.title + '';
g+='
\n\
' + this.content + "
\n\
";
var i = '' + g + '
';
$("body").append(i);
OpenWindow.ArrayW.push(document.getElementById(this.name));
this.setCss();
this.startDrag();
this.setTop();
this.setCommond()
};
this.init();
return this
};
OpenWindow.ArrayW = new Array();
OpenWindow.Drag = function(d, c) {
var a = this;
this.obj = (typeof c != "undefined") ? c: d;
this.relLeft = 0;
this.relTop = 0;
a._move = false;
a.moveId = "moveWindow";
d.onselectstart = function() {
return false
};
d.onmousedown = function(g) {
var f = $(c).offset(),
h = $('');
$("body").append(h);
$("." + a.moveId).css({
left: f.left,
top: f.top,
width: $(c).outerWidth(),
height: $(c).outerHeight(),
opacity: 0.5
});
g = a.fixE(g);
a.relLeft = g.clientX - a.fixU(a.obj.style.left);
a.relTop = g.clientY - a.fixU(a.obj.style.top);
a._move = true;
document.onmousemove = function(i) {
a.drag(i)
};
document.onmouseup = function() {
a.end()
}
};
this.drag = function(h) {
h = this.fixE(h);
var f = h.clientX - this.relLeft;
var g = h.clientY - this.relTop;
if (g < 0) {
g = 0
}
$("#" + a.moveId).css({
left: f + "px",
top: g + "px"
})
};
this.end = function() {
a._move = false;
document.onmousemove = null;
document.onmouseup = null;
var e = $("#" + a.moveId).offset();
$(a.obj).css({
left: e.left + "px",
top: e.top + "px"
});
$("." + a.moveId).remove();
return false
};
this.fixE = function(f) {
if (typeof f == "undefined") {
f = window.event
}
return f
};
this.fixU = function(e) {
return parseInt(e.split("p")[0])
}
};
OpenWindow.prototype.setCss = function() {
var a = document.getElementById(this.name);
switch (this.flag) {
case 0:
if (typeof this.style.top != "undefined") {
a.style.top = parseInt(this.style.top, 10) < 0 ? "0": this.style.top
}
if (typeof this.style.width != "undefined") {
a.style.width = this.style.width
}
if (typeof this.style.left != "undefined") {
a.style.left = this.style.left
}
break;
case 1:
a.style.top = "91px";
a.style.height = ($(window).height() - 96) + "px";
a.style.width = "100%";
a.style.left = "0px";
$("#" + this.name).find("#minWindow").height((parseInt(a.style.height, 10) - 31) + "px");
break;
case 2:
a.style.top = 0;
a.style.height = ($(window).height() - 6) + "px";
a.style.width = "100%";
a.style.left = "0px";
$("#" + this.name).find("#minWindow").height((parseInt(a.style.height, 10) - 31) + "px");
break;
default:
break
}
this.height = a.style.height;
this.width = a.style.width;
$("#" + this.name).fadeIn(500)
};
OpenWindow.prototype.startDrag = function() {
var a = document.getElementById(this.name);
new OpenWindow.Drag(a.childNodes[0].childNodes[0], a)
};
OpenWindow.prototype.setTop = function() {
for (var a = 0; a < OpenWindow.ArrayW.length; a++) {
OpenWindow.ArrayW[a].style.zIndex = 10004;
}
this.style.zIndex = 100;
document.getElementById(this.name).onclick = document.getElementById(this.name).onmousedown = function() {
for (var c = 0; c < OpenWindow.ArrayW.length; c++) {
OpenWindow.ArrayW[c].style.zIndex = 10004;
}
this.style.zIndex = 10005;
}
};
OpenWindow.prototype.close = function(a) {
var a = a || this.name;
$("#box" + a).remove();
top.windowIndex = top.windowIndex - 1 < 0 ? 0 : top.windowIndex - 1;
if (typeof(this.fun) == "function") {
this.fun.call(this, {})
}
};
OpenWindow.prototype.setCommond = function() {
var a = this,
c = document.getElementById(this.name);
c.childNodes[0].getElementsByTagName("a")[0].onclick = function() {
a.close();
return false
}
};
OpenWindow.prototype.getValue = function() {
return this.content
};
OpenWindow.prototype.setValue = function(a) {
this.content = Vlaue;
this.setContent()
};
/*===========================
Template7 Template engine
===========================*/
/* global $:true */
/* jshint unused:false */
/* jshint forin:false */
+function ($) {
"use strict";
$.Template7 = $.t7 = (function () {
function isArray(arr) {
return Object.prototype.toString.apply(arr) === '[object Array]';
}
function isObject(obj) {
return obj instanceof Object;
}
function isFunction(func) {
return typeof func === 'function';
}
var cache = {};
function helperToSlices(string) {
var helperParts = string.replace(/[{}#}]/g, '').split(' ');
var slices = [];
var shiftIndex, i, j;
for (i = 0; i < helperParts.length; i++) {
var part = helperParts[i];
if (i === 0) slices.push(part);
else {
if (part.indexOf('"') === 0) {
// Plain String
if (part.match(/"/g).length === 2) {
// One word string
slices.push(part);
}
else {
// Find closed Index
shiftIndex = 0;
for (j = i + 1; j < helperParts.length; j++) {
part += ' ' + helperParts[j];
if (helperParts[j].indexOf('"') >= 0) {
shiftIndex = j;
slices.push(part);
break;
}
}
if (shiftIndex) i = shiftIndex;
}
}
else {
if (part.indexOf('=') > 0) {
// Hash
var hashParts = part.split('=');
var hashName = hashParts[0];
var hashContent = hashParts[1];
if (hashContent.match(/"/g).length !== 2) {
shiftIndex = 0;
for (j = i + 1; j < helperParts.length; j++) {
hashContent += ' ' + helperParts[j];
if (helperParts[j].indexOf('"') >= 0) {
shiftIndex = j;
break;
}
}
if (shiftIndex) i = shiftIndex;
}
var hash = [hashName, hashContent.replace(/"/g,'')];
slices.push(hash);
}
else {
// Plain variable
slices.push(part);
}
}
}
}
return slices;
}
function stringToBlocks(string) {
var blocks = [], i, j, k;
if (!string) return [];
var _blocks = string.split(/({{[^{^}]*}})/);
for (i = 0; i < _blocks.length; i++) {
var block = _blocks[i];
if (block === '') continue;
if (block.indexOf('{{') < 0) {
blocks.push({
type: 'plain',
content: block
});
}
else {
if (block.indexOf('{/') >= 0) {
continue;
}
if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) {
// Simple variable
blocks.push({
type: 'variable',
contextName: block.replace(/[{}]/g, '')
});
continue;
}
// Helpers
var helperSlices = helperToSlices(block);
var helperName = helperSlices[0];
var helperContext = [];
var helperHash = {};
for (j = 1; j < helperSlices.length; j++) {
var slice = helperSlices[j];
if (isArray(slice)) {
// Hash
helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1];
}
else {
helperContext.push(slice);
}
}
if (block.indexOf('{#') >= 0) {
// Condition/Helper
var helperStartIndex = i;
var helperContent = '';
var elseContent = '';
var toSkip = 0;
var shiftIndex;
var foundClosed = false, foundElse = false, foundClosedElse = false, depth = 0;
for (j = i + 1; j < _blocks.length; j++) {
if (_blocks[j].indexOf('{{#') >= 0) {
depth ++;
}
if (_blocks[j].indexOf('{{/') >= 0) {
depth --;
}
if (_blocks[j].indexOf('{{#' + helperName) >= 0) {
helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
toSkip ++;
}
else if (_blocks[j].indexOf('{{/' + helperName) >= 0) {
if (toSkip > 0) {
toSkip--;
helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
}
else {
shiftIndex = j;
foundClosed = true;
break;
}
}
else if (_blocks[j].indexOf('else') >= 0 && depth === 0) {
foundElse = true;
}
else {
if (!foundElse) helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
}
}
if (foundClosed) {
if (shiftIndex) i = shiftIndex;
blocks.push({
type: 'helper',
helperName: helperName,
contextName: helperContext,
content: helperContent,
inverseContent: elseContent,
hash: helperHash
});
}
}
else if (block.indexOf(' ') > 0) {
blocks.push({
type: 'helper',
helperName: helperName,
contextName: helperContext,
hash: helperHash
});
}
}
}
return blocks;
}
var Template7 = function (template) {
var t = this;
t.template = template;
function getCompileFn(block, depth) {
if (block.content) return compile(block.content, depth);
else return function () {return ''; };
}
function getCompileInverse(block, depth) {
if (block.inverseContent) return compile(block.inverseContent, depth);
else return function () {return ''; };
}
function getCompileVar(name, ctx) {
var variable, parts, levelsUp = 0, initialCtx = ctx;
if (name.indexOf('../') === 0) {
levelsUp = name.split('../').length - 1;
var newDepth = ctx.split('_')[1] - levelsUp;
ctx = 'ctx_' + (newDepth >= 1 ? newDepth : 1);
parts = name.split('../')[levelsUp].split('.');
}
else if (name.indexOf('@global') === 0) {
ctx = '$.Template7.global';
parts = name.split('@global.')[1].split('.');
}
else if (name.indexOf('@root') === 0) {
ctx = 'ctx_1';
parts = name.split('@root.')[1].split('.');
}
else {
parts = name.split('.');
}
variable = ctx;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if (part.indexOf('@') === 0) {
if (i > 0) {
variable += '[(data && data.' + part.replace('@', '') + ')]';
}
else {
variable = '(data && data.' + name.replace('@', '') + ')';
}
}
else {
if (isFinite(part)) {
variable += '[' + part + ']';
}
else {
if (part.indexOf('this') === 0) {
variable = part.replace('this', ctx);
}
else {
variable += '.' + part;
}
}
}
}
return variable;
}
function getCompiledArguments(contextArray, ctx) {
var arr = [];
for (var i = 0; i < contextArray.length; i++) {
if (contextArray[i].indexOf('"') === 0) arr.push(contextArray[i]);
else {
arr.push(getCompileVar(contextArray[i], ctx));
}
}
return arr.join(', ');
}
function compile(template, depth) {
depth = depth || 1;
template = template || t.template;
if (typeof template !== 'string') {
throw new Error('Template7: Template must be a string');
}
var blocks = stringToBlocks(template);
if (blocks.length === 0) {
return function () { return ''; };
}
var ctx = 'ctx_' + depth;
var resultString = '(function (' + ctx + ', data) {\n';
if (depth === 1) {
resultString += 'function isArray(arr){return Object.prototype.toString.apply(arr) === \'[object Array]\';}\n';
resultString += 'function isFunction(func){return (typeof func === \'function\');}\n';
resultString += 'function c(val, ctx) {if (typeof val !== "undefined") {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n';
}
resultString += 'var r = \'\';\n';
var i, j, context;
for (i = 0; i < blocks.length; i++) {
var block = blocks[i];
// Plain block
if (block.type === 'plain') {
resultString += 'r +=\'' + (block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'') + '\';';
continue;
}
var variable, compiledArguments;
// Variable block
if (block.type === 'variable') {
variable = getCompileVar(block.contextName, ctx);
resultString += 'r += c(' + variable + ', ' + ctx + ');';
}
// Helpers block
if (block.type === 'helper') {
if (block.helperName in t.helpers) {
compiledArguments = getCompiledArguments(block.contextName, ctx);
resultString += 'r += ($.Template7.helpers.' + block.helperName + ').call(' + ctx + ', ' + (compiledArguments && (compiledArguments + ', ')) +'{hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
}
else {
if (block.contextName.length > 0) {
throw new Error('Template7: Missing helper: "' + block.helperName + '"');
}
else {
variable = getCompileVar(block.helperName, ctx);
resultString += 'if (' + variable + ') {';
resultString += 'if (isArray(' + variable + ')) {';
resultString += 'r += ($.Template7.helpers.each).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
resultString += '}else {';
resultString += 'r += ($.Template7.helpers.with).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
resultString += '}}';
}
}
}
}
resultString += '\nreturn r;})';
return eval.call(window, resultString);
}
t.compile = function (template) {
if (!t.compiled) {
t.compiled = compile(template);
}
return t.compiled;
};
};
Template7.prototype = {
options: {},
helpers: {
'if': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
if (context) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
},
'unless': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
if (!context) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
},
'each': function (context, options) {
var ret = '', i = 0;
if (isFunction(context)) { context = context.call(this); }
if (isArray(context)) {
if (options.hash.reverse) {
context = context.reverse();
}
for (i = 0; i < context.length; i++) {
ret += options.fn(context[i], {first: i === 0, last: i === context.length - 1, index: i});
}
if (options.hash.reverse) {
context = context.reverse();
}
}
else {
for (var key in context) {
i++;
ret += options.fn(context[key], {key: key});
}
}
if (i > 0) return ret;
else return options.inverse(this);
},
'with': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
return options.fn(context);
},
'join': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
return context.join(options.hash.delimiter || options.hash.delimeter);
},
'urlcode': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
return options.hash.val == "encodeURIComponent" ? encodeURIComponent(context) : decodeURIComponent(context);
},
'date': function (context, options) {
if(!context) return "";
context = isFunction(context) ? context.call(this) : new Date(context);
options.hash.format = options.hash.format || "yyyy-MM-dd hh:mm:ss";
var o = {
"M+": context.getMonth() + 1,
"d+": context.getDate(),
"h+": context.getHours(),
"m+": context.getMinutes(),
"s+": context.getSeconds(),
"q+": Math.floor((context.getMonth() + 3) / 3),
"S": context.getMilliseconds()
};
if (/(y+)/.test(options.hash.format)) {
options.hash.format = options.hash.format.replace(RegExp.$1, (context.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(options.hash.format)) {
options.hash.format = options.hash.format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return options.hash.format;
},
'js': function (expression, options) {
var func;
if (expression.indexOf('return')>=0) {
func = '(function(){'+expression+'})';
}
else {
func = '(function(){return ('+expression+')})';
}
return eval.call(this, func).call(this);
},
'js_compare': function (expression, options) {
var func;
if (expression.indexOf('return')>=0) {
func = '(function(){'+expression+'})';
}
else {
func = '(function(){return ('+expression+')})';
}
var condition = eval.call(this, func).call(this);
if (condition) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
},
'if_compare': function (str, expression, options) {
var func;
if (expression.indexOf('return')>=0) {
str = "'"+str+"'";
console.log(str);
func = '(function(){'+str+expression+'})';
}
else {
func = '(function(){return ('+str+expression+')})';
}
var condition = eval.call(this, func).call(this);
if (condition) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
}
}
};
var t7 = function (template, data) {
if (arguments.length === 2) {
var instance = new Template7(template);
var rendered = instance.compile()(data);
instance = null;
return (rendered);
}
else return new Template7(template);
};
t7.registerHelper = function (name, fn) {
Template7.prototype.helpers[name] = fn;
};
t7.unregisterHelper = function (name) {
Template7.prototype.helpers[name] = undefined;
delete Template7.prototype.helpers[name];
};
t7.compile = function (template, options) {
var instance = new Template7(template, options);
return instance.compile();
};
t7.templateData = {};
t7.getTemplate = function(){
var templateDoc = $('script[type="text/html"]');
templateDoc.each(function(index, item){
t7.templateData[$(this).attr("id")] = $(item).html();
$(this).remove();
});
}
t7.renderTpl = function(markup,renderData){
this.getTemplate();
if(!t7.templateData.hasOwnProperty(markup)) return false;
var compiledTemplate = t7.compile(t7.templateData[markup]);
return compiledTemplate(renderData);
};
t7.removeTpl = function(id){
if(t7.templateData.hasOwnProperty(id))
delete t7.templateData[id];
}
t7.options = Template7.prototype.options;
t7.helpers = Template7.prototype.helpers;
return t7;
})();
}($);
//input用户输入提示
jQuery.Autocompleter = function(input, options) {
var KEY = {
UP: 38,
DOWN: 40,
DEL: 46,
TAB: 9,
RETURN: 13,
ESC: 27,
COMMA: 188,
PAGEUP: 33,
PAGEDOWN: 34,
BACKSPACE: 8
};
// Create $ object for input element
var jQueryinput = jQuery(input).attr("autocomplete", "off").addClass(options.inputClass);
var timeout;
var previousValue = "";
var cache = jQuery.Autocompleter.Cache(options);
var hasFocus = 0;
var lastKeyPressCode;
var config = {
mouseDownOnSelect: false
};
var select = jQuery.Autocompleter.Select(options, input, selectCurrent, config);
var blockSubmit;
// prevent form submit in opera when selecting with return key
jQuery.browser.opera && jQuery(input.form).bind("submit.autocomplete", function() {
if (blockSubmit) {
blockSubmit = false;
return false;
}
});
// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
jQueryinput.bind((jQuery.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
// track last key pressed
lastKeyPressCode = event.keyCode;
switch (event.keyCode) {
case KEY.UP:
event.preventDefault();
if (select.visible()) {
select.prev();
} else {
onChange(0, true);
}
break;
case KEY.DOWN:
event.preventDefault();
if (select.visible()) {
select.next();
} else {
onChange(0, true);
}
break;
case KEY.PAGEUP:
event.preventDefault();
if (select.visible()) {
select.pageUp();
} else {
onChange(0, true);
}
break;
case KEY.PAGEDOWN:
event.preventDefault();
if (select.visible()) {
select.pageDown();
} else {
onChange(0, true);
}
break;
// matches also semicolon
case options.multiple && jQuery.trim(options.multipleSeparator) == "," && KEY.COMMA:
case KEY.TAB:
case KEY.RETURN:
if (selectCurrent()) {
// stop default to prevent a form submit, Opera needs special handling
event.preventDefault();
blockSubmit = true;
return false;
}
break;
case KEY.ESC:
select.hide();
break;
default:
clearTimeout(timeout);
timeout = setTimeout(onChange, options.delay);
break;
}
}).focus(function() {
// track whether the field has focus, we shouldn't process any
// results if the field no longer has focus
hasFocus++;
}).blur(function() {
hasFocus = 0;
if (!config.mouseDownOnSelect) {
hideResults();
}
}).bind("search", function() {
// TODO why not just specifying both arguments?
var fn = (arguments.length > 1) ? arguments[1] : null;
function findValueCallback(q, data) {
var result;
if (data && data.length) {
for (var i = 0; i < data.length; i++) {
if (data[i].result.toLowerCase() == q.toLowerCase()) {
result = data[i];
break;
}
}
}
if (typeof fn == "function") fn(result);
else jQueryinput.trigger("result", result && [result.data, result.value]);
}
jQuery.each(trimWords(jQueryinput.val()), function(i, value) {
request(value, findValueCallback, findValueCallback);
});
}).bind("flushCache", function() {
cache.flush();
}).bind("setOptions", function() {
jQuery.extend(options, arguments[1]);
// if we've updated the data, repopulate
if ("data" in arguments[1]) cache.populate();
}).bind("unautocomplete", function() {
select.unbind();
jQueryinput.unbind();
jQuery(input.form).unbind(".autocomplete");
}).bind("input", function() {
onChange(0, true);
});
if(options.clickStatus){
jQuery(jQueryinput.prev()).bind("click",function(){
clearTimeout(timeout);
timeout = setTimeout(function(){
onChange(0, true);
}, options.delay);
});
}
function selectCurrent() {
var selected = select.selected();
if (!selected) return false;
var v = selected.result;
previousValue = v;
if (options.multiple) {
var words = trimWords(jQueryinput.val());
if (words.length > 1) {
v = words.slice(0, words.length - 1).join(options.multipleSeparator) + options.multipleSeparator + v;
}
v += options.multipleSeparator;
}
jQueryinput.val(v);
hideResultsNow();
jQueryinput.trigger("result", [selected.data, selected.value]);
return true;
}
function onChange(crap, skipPrevCheck) {
if (lastKeyPressCode == KEY.DEL) {
select.hide();
return;
}
var currentValue = jQueryinput.val();
if (!skipPrevCheck && currentValue == previousValue) return;
previousValue = currentValue;
currentValue = lastWord(currentValue);
if (currentValue.length >= options.minChars || options.clickStatus) {
jQueryinput.addClass(options.loadingClass);
if (!options.matchCase) currentValue = currentValue.toLowerCase();
request(currentValue, receiveData, hideResultsNow);
} else {
stopLoading();
select.hide();
}
};
function trimWords(value) {
if (!value) {
return [""];
}
var words = value.split(options.multipleSeparator);
var result = [];
jQuery.each(words, function(i, value) {
if (jQuery.trim(value)) result[i] = jQuery.trim(value);
});
return result;
}
function lastWord(value) {
if (!options.multiple) return value;
var words = trimWords(value);
return words[words.length - 1];
}
// fills in the input box w/the first match (assumed to be the best match)
// q: the term entered
// sValue: the first matching result
function autoFill(q, sValue) {
// autofill in the complete box w/the first match as long as the user hasn't entered in more data
// if the last user key pressed was backspace, don't autofill
if (options.autoFill && (lastWord(jQueryinput.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE) {
// fill in the value (keep the case the user has typed)
jQueryinput.val(jQueryinput.val() + sValue.substring(lastWord(previousValue).length));
// select the portion of the value not typed by the user (so the next character will erase)
jQuery.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length);
}
};
function hideResults() {
clearTimeout(timeout);
timeout = setTimeout(hideResultsNow, 200);
};
function hideResultsNow() {
var wasVisible = select.visible();
select.hide();
clearTimeout(timeout);
stopLoading();
if (options.mustMatch) {
// call search and run callback
jQueryinput.search(
function(result) {
// if no value found, clear the input box
if (!result) {
if (options.multiple) {
var words = trimWords(jQueryinput.val()).slice(0, -1);
jQueryinput.val(words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : ""));
} else jQueryinput.val("");
}
});
}
if (wasVisible)
// position cursor at end of input field
jQuery.Autocompleter.Selection(input, input.value.length, input.value.length);
};
function receiveData(q, data) {
if (data && data.length && hasFocus) {
stopLoading();
select.display(data, q);
autoFill(q, data[0].value);
select.show();
} else {
hideResultsNow();
}
};
function request(term, success, failure) {
if (!options.matchCase) term = term.toLowerCase();
var data = cache.load(term);
// recieve the cached data
/*if (data && data.length) {
success(term, data);
cache.add(term, parsed);
// if an AJAX url has been supplied, try loading the data now
} else */if ((typeof options.url == "string") && (options.url.length > 0)) {
var extraParams = {
timestamp: +new Date()
};
jQuery.each(options.extraParams, function(key, param) {
extraParams[key] = typeof param == "function" ? param() : param;
});
jQuery.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
data: jQuery.extend({
q: encodeURIComponent($.trim(term)),
limit: options.max
}, extraParams),
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
}
});
} else {
// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
select.emptyList();
failure(term);
}
};
function parse(data) {
var parsed = [];
var rows = eval('(' + data + ')');
for (var i = 0; i < rows.length; i++) {
var row = jQuery.trim(rows[i]);
if (row) {
row = row.split("|");
parsed[parsed.length] = {
data: row,
value: row[0],
result: options.formatResult && options.formatResult(row, row[0]) || row[0]
};
}
}
return parsed;
};
function stopLoading() {
jQueryinput.removeClass(options.loadingClass);
};
};
jQuery.Autocompleter.defaults = {
inputClass: "ac_input",
resultsClass: "ac_results",
loadingClass: "ac_loading",
minChars: 1,
delay: 400,
matchCase: false,
matchSubset: true,
matchContains: false,
cacheLength: 10,
max: 100,
mustMatch: false,
extraParams: {},
selectFirst: true,
formatItem: function(row) {
return row[0];
},
formatMatch: null,
autoFill: false,
width: 0,
multiple: false,
multipleSeparator: ", ",
highlight: function(value, term) {
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1");
},
scroll: true,
scrollHeight: 180
};
jQuery.Autocompleter.Cache = function(options) {
var data = {};
var length = 0;
function matchSubset(s, sub) {
if (!options.matchCase) s = (s || "").toString().toLowerCase();
var i = s.indexOf(sub);
if (i == -1) return false;
return i == 0 || options.matchContains;
};
function add(q, value) {
if (length > options.cacheLength) {
flush();
}
if (!data[q]) {
length++;
}
data[q] = value;
}
function populate() {
if (!options.data) return false;
// track the matches
var stMatchSets = {},
nullData = 0;
// no url was specified, we need to adjust the cache length to make sure it fits the local data store
if (!options.url) options.cacheLength = 1;
// track all options for minChars = 0
stMatchSets[""] = [];
// loop through the array and create a lookup structure
for (var i = 0, ol = options.data.length; i < ol; i++) {
var rawValue = options.data[i];
// if rawValue is a string, make an array otherwise just reference the array
rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
var value = options.formatMatch(rawValue, i + 1, options.data.length);
if (value === false) continue;
var firstChar = value.charAt(0).toLowerCase();
// if no lookup array for this character exists, look it up now
if (!stMatchSets[firstChar]) stMatchSets[firstChar] = [];
// if the match is a string
var row = {
value: value,
data: rawValue,
result: options.formatResult && options.formatResult(rawValue) || value
};
// push the current match into the set list
stMatchSets[firstChar].push(row);
// keep track of minChars zero items
if (nullData++ < options.max) {
stMatchSets[""].push(row);
}
};
// add the data items to the cache
jQuery.each(stMatchSets, function(i, value) {
// increase the cache size
options.cacheLength++;
// add to the cache
add(i, value);
});
}
// populate any existing data
setTimeout(populate, 25);
function flush() {
data = {};
length = 0;
}
return {
flush: flush,
add: add,
populate: populate,
load: function(q) {
if (!options.cacheLength || !length) return null;
/*
* if dealing w/local data and matchContains than we must make sure
* to loop through all the data collections looking for matches
*/
if (!options.url && options.matchContains) {
// track all matches
var csub = [];
// loop through all the data grids for matches
for (var k in data) {
// don't search through the stMatchSets[""] (minChars: 0) cache
// this prevents duplicates
if (k.length > 0) {
var c = data[k];
jQuery.each(c, function(i, x) {
// if we've got a match, add it to the array
if (matchSubset(x.value, q)) {
csub.push(x);
}
});
}
}
return csub;
} else
// if the exact item exists, use it
if (data[q]) {
return data[q];
} else if (options.matchSubset) {
for (var i = q.length - 1; i >= options.minChars; i--) {
var c = data[q.substr(0, i)];
if (c) {
var csub = [];
jQuery.each(c, function(i, x) {
if (matchSubset(x.value, q)) {
csub[csub.length] = x;
}
});
return csub;
}
}
}
return null;
}
};
};
jQuery.Autocompleter.Select = function(options, input, select, config) {
var CLASSES = {
ACTIVE: "ac_over"
};
var listItems, active = -1,
data, term = "",
needsInit = true,
element, list;
// Create results
function init() {
if (!needsInit) return;
element = jQuery("").hide().addClass(options.resultsClass).css("position", "absolute").appendTo(document.body);
list = jQuery("").appendTo(element).mouseover(function(event) {
if (target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
active = jQuery("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
jQuery(target(event)).addClass(CLASSES.ACTIVE);
}
}).click(function(event) {
jQuery(target(event)).addClass(CLASSES.ACTIVE);
select();
// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
input.focus();
return false;
}).mousedown(function() {
config.mouseDownOnSelect = true;
}).mouseup(function() {
config.mouseDownOnSelect = false;
});
if (options.width > 0) element.css("width", options.width);
needsInit = false;
}
function target(event) {
var element = event.target;
while (element && element.tagName != "LI")
element = element.parentNode;
// more fun with IE, sometimes event.target is empty, just ignore it then
if (!element) return [];
return element;
}
function moveSelect(step) {
listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
movePosition(step);
var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
if (options.scroll) {
var offset = 0;
listItems.slice(0, active).each(function() {
offset += this.offsetHeight;
});
if ((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
} else if (offset < list.scrollTop()) {
list.scrollTop(offset);
}
}
};
function movePosition(step) {
active += step;
if (active < 0) {
active = listItems.size() - 1;
} else if (active >= listItems.size()) {
active = 0;
}
}
function limitNumberOfItems(available) {
return options.max && options.max < available ? options.max : available;
}
function fillList() {
list.empty();
var max = limitNumberOfItems(data.length);
for (var i = 0; i < max; i++) {
if (!data[i]) continue;
var formatted = options.formatItem(data[i].data, i + 1, max, data[i].value, term);
if (formatted === false) continue;
var li = jQuery("").html(options.highlight(formatted, term)).addClass(i % 2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
jQuery.data(li, "ac_data", data[i]);
}
listItems = list.find("li");
if (options.selectFirst) {
listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
active = 0;
}
// apply bgiframe if available
if (jQuery.fn.bgiframe) list.bgiframe();
}
return {
display: function(d, q) {
init();
data = d;
term = q;
fillList();
},
next: function() {
moveSelect(1);
},
prev: function() {
moveSelect(-1);
},
pageUp: function() {
if (active != 0 && active - 8 < 0) {
moveSelect(-active);
} else {
moveSelect(-8);
}
},
pageDown: function() {
if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
moveSelect(listItems.size() - 1 - active);
} else {
moveSelect(8);
}
},
hide: function() {
element && element.hide();
listItems && listItems.removeClass(CLASSES.ACTIVE);
active = -1;
},
visible: function() {
return element && element.is(":visible");
},
current: function() {
return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
},
show: function() {
var offset = jQuery(input).offset();
element.css({
width: typeof options.width == "string" || options.width > 0 ? options.width : jQuery(input).width(),
top: offset.top + input.offsetHeight,
left: offset.left
}).show();
if (options.scroll) {
list.scrollTop(0);
list.css({
maxHeight: options.scrollHeight,
overflow: 'auto'
});
if (jQuery.browser.msie && typeof document.body.style.maxHeight === "undefined") {
var listHeight = 0;
listItems.each(function() {
listHeight += this.offsetHeight;
});
var scrollbarsVisible = listHeight > options.scrollHeight;
list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight);
if (!scrollbarsVisible) {
// IE doesn't recalculate width when scrollbar disappears
listItems.width(list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")));
}
}
}
},
selected: function() {
var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
return selected && selected.length && jQuery.data(selected[0], "ac_data");
},
emptyList: function() {
list && list.empty();
},
unbind: function() {
element && element.remove();
}
};
};
jQuery.Autocompleter.Selection = function(field, start, end) {
if (field.createTextRange) {
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", start);
selRange.moveEnd("character", end);
selRange.select();
} else if (field.setSelectionRange) {
field.setSelectionRange(start, end);
} else {
if (field.selectionStart) {
field.selectionStart = start;
field.selectionEnd = end;
}
}
field.focus();
};