217 lines
9.6 KiB
JavaScript
217 lines
9.6 KiB
JavaScript
(function ($) {
|
||
// 增加Array扩展
|
||
if (!$.isFunction(Array.prototype.filter)) {
|
||
Array.prototype.filter = function (callback, thisObject) {
|
||
if ($.isFunction(callback)) {
|
||
var res = new Array();
|
||
for (var i = 0; i < this.length; i++) {
|
||
callback.call(thisObject, this[i], i, this) && res.push(this[i]);
|
||
}
|
||
return res;
|
||
}
|
||
};
|
||
}
|
||
|
||
// 增加String扩展
|
||
if (!$.isFunction(String.prototype.trim)) {
|
||
String.prototype.trim = function () {
|
||
if (this == null) return "";
|
||
var trimLeft = /^\s+/, trimRight = /\s+$/;
|
||
return this.replace(trimLeft, "").replace(trimRight, "");
|
||
};
|
||
}
|
||
|
||
// 扩展Date
|
||
if (!$.isFunction(Date.prototype.format)) {
|
||
Date.prototype.format = function (format) {
|
||
var o = {
|
||
"M+": this.getMonth() + 1,
|
||
"d+": this.getDate(),
|
||
"h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12,
|
||
"H+": this.getHours(),
|
||
"m+": this.getMinutes(),
|
||
"s+": this.getSeconds(),
|
||
"q+": Math.floor((this.getMonth() + 3) / 3),
|
||
"S": this.getMilliseconds()
|
||
};
|
||
var week = {
|
||
0: "日",
|
||
1: "一",
|
||
2: "二",
|
||
3: "三",
|
||
4: "四",
|
||
5: "五",
|
||
6: "六"
|
||
};
|
||
|
||
if (/(y+)/.test(format))
|
||
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
||
|
||
if (/(E+)/.test(format))
|
||
format = format.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "星期" : "周") : "") + week[this.getDay()]);
|
||
|
||
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;
|
||
};
|
||
}
|
||
|
||
// 扩展format
|
||
$.extend({
|
||
"format": function (source, params) {
|
||
if (params === undefined) {
|
||
return source;
|
||
}
|
||
if (arguments.length > 2 && params.constructor !== Array) {
|
||
params = $.makeArray(arguments).slice(1);
|
||
}
|
||
if (params.constructor !== Array) {
|
||
params = [params];
|
||
}
|
||
$.each(params, function (i, n) {
|
||
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function () {
|
||
return n;
|
||
});
|
||
});
|
||
return source;
|
||
}
|
||
});
|
||
|
||
// enhance window.console.log
|
||
if (!window.console) {
|
||
window.console = {
|
||
log: function () {
|
||
|
||
}
|
||
};
|
||
}
|
||
window.console = window.console || {};
|
||
console.log || (console.log = opera.postError);
|
||
|
||
// client
|
||
jQuery.browser = {
|
||
versions: function () {
|
||
var u = navigator.userAgent;
|
||
return { //移动终端浏览器版本信息
|
||
trident: u.indexOf('Trident') > -1, //IE内核
|
||
presto: u.indexOf('Presto') > -1, //opera内核
|
||
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
|
||
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
|
||
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
|
||
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
|
||
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
|
||
iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
|
||
iPod: u.indexOf('iPod') > -1, //是否为iPod或者QQHD浏览器
|
||
iPad: u.indexOf('iPad') > -1, //是否iPad
|
||
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
|
||
};
|
||
}(),
|
||
language: (navigator.browserLanguage || navigator.language).toLowerCase()
|
||
}
|
||
|
||
$.fn.extend({
|
||
adjustDialog: function () {
|
||
var $modal_dialog = this;
|
||
var m_top = Math.max(0, ($(window).height() - $modal_dialog.height()) / 2);
|
||
$modal_dialog.css({ 'margin': m_top + 'px auto' });
|
||
return this;
|
||
},
|
||
autoCenter: function () {
|
||
var that = this;
|
||
var getHeight = function () {
|
||
return ($(window).height() - $(that).outerHeight()) / 2 + $(document).scrollTop();
|
||
}
|
||
$(window).resize(function () {
|
||
$(that).css({
|
||
marginTop: getHeight()
|
||
});
|
||
});
|
||
that.animate({ marginTop: "+=" + getHeight() });
|
||
},
|
||
autoValidate: function (options) {
|
||
// validate
|
||
$(this).validate({
|
||
validClass: "has-success",
|
||
errorClass: "has-error",
|
||
ignore: "ignore",
|
||
rules: $.extend({}, options),
|
||
highlight: function (element, errorClass, validClass) {
|
||
$(element).parents('.form-group').addClass(errorClass).removeClass(validClass);
|
||
},
|
||
unhighlight: function (element, errorClass, validClass) {
|
||
$(element).parents('.form-group').removeClass(errorClass).addClass(validClass);
|
||
$(element).popover('destroy');
|
||
},
|
||
errorPlacement: function (label, element) {
|
||
$(element).popover('destroy');
|
||
$(element).popover({
|
||
animation: true,
|
||
delay: { "show": 100, "hide": 100 },
|
||
container: 'form',
|
||
trigger: 'manual',
|
||
content: $(label).text(),
|
||
placement: 'auto'
|
||
});
|
||
$(element).popover('show');
|
||
}
|
||
});
|
||
},
|
||
smartTable: function (options) {
|
||
var settings = $.extend({
|
||
method: 'get', //请求方式(*)
|
||
toolbar: '#toolbar', //工具按钮用哪个容器
|
||
striped: true, //是否显示行间隔色
|
||
cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
|
||
pagination: true, //是否显示分页(*)
|
||
sortable: true, //是否启用排序
|
||
sortOrder: "asc", //排序方式
|
||
sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
|
||
pageNumber: 1, //初始化加载第一页,默认第一页
|
||
pageSize: 10, //每页的记录行数(*)
|
||
pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
|
||
search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
|
||
strictSearch: false,
|
||
showColumns: true, //是否显示所有的列
|
||
showRefresh: true, //是否显示刷新按钮
|
||
minimumCountColumns: 2, //最少允许的列数
|
||
clickToSelect: false, //是否启用点击选中行
|
||
//height: 500, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
|
||
idField: "Id",
|
||
uniqueId: "Id", //每一行的唯一标识,一般为主键列
|
||
showToggle: true, //是否显示详细视图和列表视图的切换按钮
|
||
cardView: false, //是否显示详细视图
|
||
detailView: false, //是否显示父子表
|
||
clickToSelect: false,
|
||
}, options);
|
||
$(this).bootstrapTable(settings);
|
||
$('.toolbar').insertBefore($('.bootstrap-table > .fixed-table-toolbar > .bs-bars'));
|
||
$('.toolbar a').click(function () {
|
||
var ctl = $('#' + $(this).attr('id').replace('tb_', 'btn_'));
|
||
ctl.trigger("click");
|
||
});
|
||
}
|
||
});
|
||
})(jQuery);
|
||
|
||
$(function () {
|
||
// breadcrumb
|
||
var breadcrumb = $('.sidebar-menu > li > a.active > span').text();
|
||
if (breadcrumb === "") $('.breadcrumb > li + li').hide();
|
||
else $('.breadcrumb > li + li').text(breadcrumb);
|
||
|
||
if ($.isFunction($.validator)) {
|
||
jQuery.validator.addMethod("ip", function (value, element) {
|
||
return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/.test(value);
|
||
}, "请填写正确的IP地址");
|
||
}
|
||
|
||
$(".go-top").click(function (e) {
|
||
e.preventDefault();
|
||
$('#main-content, .content-body, body').animate({
|
||
scrollTop: 0
|
||
}, 200);
|
||
});
|
||
|
||
$('.site-footer div span').text($('#footer').val());
|
||
}); |