重构Longbow.Common脚本符合代码规范

This commit is contained in:
Argo-Lenovo 2017-03-22 13:39:37 +08:00
parent c263feaf7a
commit 6093b8f1ad
1 changed files with 57 additions and 58 deletions

View File

@ -15,7 +15,7 @@
// 增加String扩展
if (!$.isFunction(String.prototype.trim)) {
String.prototype.trim = function () {
if (this == null) return "";
if (this === null) return "";
var trimLeft = /^\s+/, trimRight = /\s+$/;
return this.replace(trimLeft, "").replace(trimRight, "");
};
@ -27,7 +27,7 @@
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12,
"h+": this.getHours() % 12 === 0 ? 12 : this.getHours() % 12,
"H+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
@ -48,11 +48,11 @@
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()]);
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)));
format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
return format;
};
}
@ -97,18 +97,18 @@
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, //火狐内核
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应该程序没有头部与底部
webApp: u.indexOf('Safari') === -1 //是否web应该程序没有头部与底部
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
};
$.extend({
bc: function (options, callback) {
@ -125,7 +125,7 @@
callback: null
}, options);
if (!data.url || data.url == "") {
if (!data.url || data.url === "") {
lgbSwal({ title: '参数错误', text: '未设置请求地址Url', type: 'error' });
return;
}
@ -205,28 +205,28 @@
// Infos
Infos = {
url: '../api/Infos/'
}
};
// Profiles
Profiles = {
url: '../api/Profiles/',
title: '网站设置'
}
};
// Messages
Messages = {
url: '../api/Messages/'
}
};
// Tasks
Tasks = {
url: '../api/Tasks/'
}
};
// Notifications
Notifications = {
url: '../api/Notifications/'
}
};
$.fn.extend({
adjustDialog: function () {
@ -239,7 +239,7 @@
var that = this;
var getHeight = function () {
return ($(window).height() - $(that).outerHeight()) / 2 + $(document).scrollTop();
}
};
$(window).resize(function () {
$(that).css({
marginTop: getHeight()
@ -248,16 +248,16 @@
that.animate({ marginTop: "+=" + getHeight() });
},
lgbTooltip: function (option) {
if (option == undefined) option = { container: 'body', delay: { "show": 500, "hide": 100 } };
else if (typeof option == "object") option = $.extend({ container: 'body', delay: { "show": 500, "hide": 100 } }, option);
if (option === undefined) option = { container: 'body', delay: { "show": 500, "hide": 100 } };
else if (typeof option === "object") option = $.extend({ container: 'body', delay: { "show": 500, "hide": 100 } }, option);
$(this).tooltip(option);
if (option == 'destroy') $(this).removeAttr('data-original-title');
if (option === 'destroy') $(this).removeAttr('data-original-title');
return this;
},
autoValidate: function (rules, messages, handler) {
var parent = 'body';
var $wrapper = $('#dialogNew');
if ($wrapper.length == 1) parent = '#dialogNew';
if ($wrapper.length === 1) parent = '#dialogNew';
// validate
var $this = $(this);
if (messages && $.isArray(messages.button)) {
@ -319,8 +319,7 @@
uniqueId: "Id", //每一行的唯一标识,一般为主键列
showToggle: true, //是否显示详细视图和列表视图的切换按钮
cardView: false, //是否显示详细视图
detailView: false, //是否显示父子表
clickToSelect: false
detailView: false //是否显示父子表
}, options);
$(this).bootstrapTable(settings);
$('div.toolbar').on('click', 'a', function (e) {
@ -332,12 +331,12 @@
},
lgbDropdown: function (options) {
var $this = $(this);
var op = typeof options == 'object' && options;
var op = typeof options === 'object' && options;
if (/val/.test(options)) {
if (arguments.length == 1)
if (arguments.length === 1)
return $this.first().children('a').val();
else {
$this.first().children(':first').children(':first').text($this.find('[data-val="' + arguments[1] + '"]').text())
$this.first().children(':first').children(':first').text($this.find('[data-val="' + arguments[1] + '"]').text());
}
}
else {
@ -354,17 +353,17 @@
//fix bug
$.fn.modal.Constructor.prototype.adjustDialog = function () {
var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight
var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight;
this.$element.css({
paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '',
paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
})
});
// added by Argo
var $modal_dialog = $(this.$element[0]).find('.modal-dialog');
$modal_dialog.adjustDialog();
}
};
})(jQuery);
$(function () {