diff --git a/Bootstrap.Admin/wwwroot/js/longbow.validate.js b/Bootstrap.Admin/wwwroot/js/longbow.validate.js index bdeeb69a..7b8464c0 100644 --- a/Bootstrap.Admin/wwwroot/js/longbow.validate.js +++ b/Bootstrap.Admin/wwwroot/js/longbow.validate.js @@ -254,6 +254,11 @@ }; $(function () { + if ($.isFunction($.validator)) { + $.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地址"); + } $('[data-toggle="LgbValidate"]').lgbValidate(); }); })(jQuery); \ No newline at end of file diff --git a/Bootstrap.Client/wwwroot/js/common-scripts.js b/Bootstrap.Client/wwwroot/js/common-scripts.js index 8fb33135..cb64fd11 100644 --- a/Bootstrap.Client/wwwroot/js/common-scripts.js +++ b/Bootstrap.Client/wwwroot/js/common-scripts.js @@ -16,30 +16,36 @@ }; var $sideMenu = $(".sidebar"); - $sideMenu.dcAccordion({ autoExpand: true }); - - $("#gotoTop").on('click', function (e) { - e.preventDefault(); - $('body').animate({ - scrollTop: 0 - }, 200); - }); - - // breadcrumb var $breadNav = $('#breadNav'); var arch = $sideMenu.find('a.active').last(); $breadNav.removeClass('d-none').text(arch.text() || $('title').text()); - $('.sidebar-toggle-box').on('click', function () { - if ($(window).width() >= 768) return; + $(window).on('resize', function () { + $('.site-footer').footer(); + }); + + $("#gotoTop").on('click', function (e) { + e.preventDefault(); + $('html').animate({ + scrollTop: 0 + }, 200); + }); + + $('.sidebar-toggle-box').on('click', function (e) { + if ($(window).width() >= 768) { + e.preventDefault(); + return false; + } $('body').toggleClass('sidebar-open'); }); - $('[data-toggle="dropdown"].dropdown-select').dropdown('select'); + $('select[data-valid="true"]').on('input', function (e) { + e.stopPropagation(); + }).on('change', function () { + $(this).trigger('input.lgb.validate'); + }); - // tooltip - $('[data-toggle="tooltip"]').tooltip(); }); \ No newline at end of file diff --git a/Bootstrap.Client/wwwroot/js/longbow.common.js b/Bootstrap.Client/wwwroot/js/longbow.common.js index 5137fb6c..4d84dd20 100644 --- a/Bootstrap.Client/wwwroot/js/longbow.common.js +++ b/Bootstrap.Client/wwwroot/js/longbow.common.js @@ -116,7 +116,6 @@ id: "", url: "", data: {}, - htmlTemplate: '
', title: "", modal: false, loading: false, @@ -192,23 +191,6 @@ while (document.getElementById(prefix)); return prefix; }, - fullScreenStatus: function fullScreenStatus(value) { - if (value !== undefined) window.fullscreen = value; - return document.fullscreen || - document.mozFullScreen || - document.webkitIsFullScreen || window.fullscreen || - false; - }, - formatter: function (key) { - if (!this[key]) { - this[key] = {}; - var that = this; - $.each($('#' + key).children(), function (index, element) { - that[key][$(element).attr('value')] = $(element).text(); - }); - } - return this; - }, formatUrl: function (url) { if (!url) return url; if (url.substr(0, 4) === "http") return url; @@ -220,25 +202,6 @@ window.lgbSwal = $.lgbSwal; $.fn.extend({ - fixCollapse: function () { - var $root = this; - var $collapse = $root.find('a[data-toggle="collapse"]:visible'); - $collapse.each(function () { - var $this = $(this); - if ($this.attr('href') !== '#') return; - var $target = $this.parent().next(); - var tId = $.getUID('collapse'); - $target.attr('id', tId); - $this.attr('href', '#' + tId); - }); - return this; - }, - 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 (options) { options = $.extend({ top: 0 }, options); var that = this; @@ -253,8 +216,7 @@ return this; }, footer: function (options) { - if ($(window).width() >= 768) { return this.addClass('position-fixed'); } - var op = $.extend({ header: "header", content: ".main-content" }, options); + var op = $.extend({ header: "header", content: ".container-fluid" }, options); return $(op.header).outerHeight() + $(op.content).outerHeight() + this.outerHeight() > $(window).height() ? this.removeClass('position-fixed') : this.addClass('position-fixed'); }, lgbTable: function (options) { @@ -313,6 +275,102 @@ } return this; }, + lgbDatePicker: function (options) { + if (!$.isFunction(this.datetimepicker)) return this; + var option = $.extend({ + language: 'zh-CN', + weekStart: 1, + todayBtn: 1, + autoclose: 1, + todayHighlight: 1, + startView: 2, + minView: 2, + forceParse: 0, + format: 'yyyy-mm-dd', + pickerPosition: 'bottom-left', + fontAwesome: true + }, options); + this.datetimepicker(option); + return this; + }, + lgbIndicator: function (options) { + if (/update/.test(options)) { + var $indicator = this.data('radialIndicator'); + if ($indicator.indOption.percentage) $indicator.animate(this.attr('data-val') * 100 / this.attr('data-max')); + else $indicator.value(this.attr('data-val')); + return this; + } + this.each(function () { + var op = $.extend({ + barColor: { + 0: '#33CC33', + 70: '#c5c521', + 80: '#e46121', + 90: '#c92b2b', + 100: '#FF0000' + }, + radius: 34, + interaction: false, + barWidth: 5, + roundCorner: true, + percentage: true, + }, options); + var $this = $(this); + $this.radialIndicator(op); + if ($this.attr('data-val')) { + var $indicator = $this.data('radialIndicator'); + if ($indicator.indOption.percentage) $indicator.animate($this.attr('data-val') * 100 / $this.attr('data-max')); + else $indicator.value($this.attr('data-val')); + } + }); + return this; + }, + lgbCountUp: function (options) { + options = $.extend({}, options); + this.each(function () { + var option = { + useEasing: true, + useGrouping: false, + separator: ',', + decimal: '.' + }; + var $element = $(this); + var startVal = options.startVal || 0; + var endVal = $element.text() || 100; + var decimals = options.decimals || 0; + var count = new CountUp(this, startVal, endVal, decimals, 1, $.extend(option, options)); + count.start(); + }); + return this; + }, + lgbInfo: function (option) { + this.each(function () { + var $element = $(this); + $element.append($.format('')); + }); + var container = $(this).parent().attr('data-container') || '#dialogNew'; + this.find('[data-toggle="popover"]').popover($.extend({ + title: function () { + return $(this).parent().text(); + }, content: function () { + return $(this).parent().attr('data-content'); + }, trigger: 'focus', html: true, container: container + }, option)); + return this; + }, + getTextByValue: function (key, value) { + // 通过Key指定一个下拉框,通过value获得下拉框value值的text属性 + if (this.length !== 1) throw 'element must be one'; + var ele = this.get(0); + if (!ele[key]) { + ele[key] = {}; + var that = ele; + $.each($('#' + key).children(), function (index, element) { + that[key][$(element).attr('value')] = $(element).text(); + }); + } + return ele[key][value]; + }, msgHandler: function (options) { var settings = { url: 'api/WS', @@ -401,4 +459,12 @@ }); } }); + + $(function () { + $('[data-toggle="dropdown"].dropdown-select').dropdown('select'); + $('[data-toggle="tooltip"]').tooltip(); + $('[data-toggle="popover"]').popover(); + $('[data-toggle="lgbinfo"]').lgbInfo(); + $('.date').lgbDatePicker(); + }); })(jQuery); \ No newline at end of file diff --git a/Bootstrap.Client/wwwroot/js/longbow.validate.js b/Bootstrap.Client/wwwroot/js/longbow.validate.js index 050c470c..816caca5 100644 --- a/Bootstrap.Client/wwwroot/js/longbow.validate.js +++ b/Bootstrap.Client/wwwroot/js/longbow.validate.js @@ -139,31 +139,26 @@ var $firstElement = null; this.$element.find(op.childClass + ':visible').not(op.ignoreClass).each(function () { - if (!that.validElement(this) && $firstElement == null) $firstElement = $(this); + if (!that.validElement(this) && $firstElement === null) $firstElement = $(this); }); if ($firstElement) $firstElement.tooltip('show'); - return $firstElement == null; + return $firstElement === null; }; Validate.prototype.validElement = function (element) { var result = this.check(element); this.tooltip(element, result); - return result + return result; }; Validate.prototype.tooltip = function (element, valid) { - if (valid == "pending") return; + if (valid === "pending") return; var op = this.options; var $this = $(element); - try { - if (valid) $this.tooltip('dispose'); - else { - if (!$this.hasClass(op.errorClass)) $this.tooltip(); - } - } - catch (e) { - + if (valid) $this.tooltip('dispose'); + else { + if (!$this.hasClass(op.errorClass)) $this.tooltip(); } if (!valid) { $this.removeClass(op.validClass).addClass(op.errorClass); @@ -194,7 +189,7 @@ }; Validate.prototype.defaultMessage = function (element, rule) { - var message = $(element).attr('data-' + rule.method + '-msg') || (rule.method == 'required' && $(element).attr('placeholder')) || $.validator.messages[rule.method]; + var message = $(element).attr('data-' + rule.method + '-msg') || rule.method === 'required' && $(element).attr('placeholder') || $.validator.messages[rule.method]; var theregex = /\$?\{(\d+)\}/g; if (typeof message === "function") { message = message.call(this, rule.parameters, element); @@ -232,7 +227,7 @@ Validate.prototype.rules = function (element) { var $this = $(element); var rules = $this.data('lgb.Validate.Rules'); - if (!rules) $this.data('lgb.Validate.Rules', (rules = $.validator.normalizeRules($.extend({ required: true }, $.validator.classRules(element), $.validator.attributeRules(element), this.attributeRules(element))))); + if (!rules) $this.data('lgb.Validate.Rules', rules = $.validator.normalizeRules($.extend({ required: true }, $.validator.classRules(element), $.validator.attributeRules(element), this.attributeRules(element)))); return rules; }; @@ -240,13 +235,13 @@ return this.each(function () { var $this = $(this); var data = $this.data('lgb.Validate'); - var options = typeof option == 'object' && option; + var options = typeof option === 'object' && option; - if (!data && /valid|defaults/.test(option)) return - if (!data) $this.data('lgb.Validate', (data = new Validate(this, options))); - if (typeof option == 'string') data[option](); - }) - }; + if (!data && /valid|defaults/.test(option)) return; + if (!data) $this.data('lgb.Validate', data = new Validate(this, options)); + if (typeof option === 'string') data[option](); + }); + } $.fn.lgbValidate = Plugin; $.fn.lgbValidate.Constructor = Validate; @@ -255,10 +250,15 @@ }; $.fn.lgbValid = function () { var $this = this; - return $this.attr(Validate.DEFAULTS.validResult) == 'true'; + return $this.attr(Validate.DEFAULTS.validResult) === 'true'; }; $(function () { + if ($.isFunction($.validator)) { + $.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地址"); + } $('[data-toggle="LgbValidate"]').lgbValidate(); }); })(jQuery); \ No newline at end of file