BootstrapAdmin/Bootstrap.Admin/Content/js/Longbow.Common.js

136 lines
4.9 KiB
JavaScript
Raw Normal View History

(function ($) {
2016-10-20 17:55:29 +08:00
// 增加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() });
}
});
$.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');
}
});
}
});
2016-10-20 17:55:29 +08:00
})(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地址");
}
2016-10-23 23:18:18 +08:00
$(".go-top").click(function (e) {
e.preventDefault();
$('#main-content').animate({
scrollTop: 0
}, 200);
});
2016-10-20 17:55:29 +08:00
});