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