(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; } }); $.fn.extend({ "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() }); } }); // enhance window.console.log if (!window.console) { window.console = { log: function () { } }; } window.console = window.console || {}; console.log || (console.log = opera.postError); $.fn.extend({ autoValidate: function (options) { // validate $(this).validate({ ignore: "ignore", rules: $.extend({}, options), unhighlight: function (element, errorClass, validClass) { $.validator.defaults.unhighlight(element, errorClass, 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'); } }); } }); $.fn.extend({ 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); } }); })(jQuery); $(function () { 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').animate({ scrollTop: 0 }, 200); }); });