From ddad4fa9871bbe8450c1dba04f72c328bdbb3387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Wed, 19 Apr 2017 19:17:41 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=A7=BB=E9=99=A4]=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8js=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/plugs/jquery/jquery.admin.js | 474 ------------------ public/static/plugs/jquery/jquery.validate.js | 383 -------------- 2 files changed, 857 deletions(-) delete mode 100644 public/static/plugs/jquery/jquery.admin.js delete mode 100644 public/static/plugs/jquery/jquery.validate.js diff --git a/public/static/plugs/jquery/jquery.admin.js b/public/static/plugs/jquery/jquery.admin.js deleted file mode 100644 index 8415cb098..000000000 --- a/public/static/plugs/jquery/jquery.admin.js +++ /dev/null @@ -1,474 +0,0 @@ -/* global layer, ZeroClipboard, Pace */ - -(function ($) { - - /*! - * jQuery placeholder, fix for IE6,7,8,9 - */ - var JPlaceHolder = { - _check: function () { - return 'placeholder' in document.createElement('input'); - }, - init: function () { - !this._check() && this.fix(); - }, - fix: function () { - $(':input[placeholder]').map(function () { - var self = $(this), txt = self.attr('placeholder'); - self.wrap($('
').css({position: 'relative', zoom: '1', border: 'none', background: 'none', padding: 'none', margin: 'none'})); - var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left'); - var holder = $('').text(txt).css({position: 'absolute', left: pos.left, top: pos.top, height: h, lineHeight: h + 'px', paddingLeft: paddingleft, color: '#aaa'}).appendTo(self.parent()); - self.on('focusin focusout change keyup', function () { - self.val() ? holder.hide() : holder.show(); - }); - holder.click(function () { - self.get(0).focus(); - }); - self.val() && holder.hide(); - }); - } - }; - JPlaceHolder.init(); - - - /** - * 定义消息处理构造方法 - * @returns {common_L11._msg} - */ - function msg() { - this.version = '2.0'; - this.shade = [0.01, '#0f0']; - } - - /** - * 关闭消息框 - */ - msg.prototype.close = function () { - return layer.close(this.index); - }; - /** - * 弹出警告消息框 - * @param {type} msg - * @param {type} callback - * @returns {undefined} - */ - msg.prototype.alert = function (msg, callback) { - layer.close(this.index); - return this.index = layer.alert(msg, { - end: callback, - scrollbar: false - }); - }; - /** - * 确认对话框 - * @param {type} msg 提示消息内容 - * @param {type} ok 确认的回调函数 - * @param {type} no 取消的回调函数 - * @returns {undefined} - */ - msg.prototype.confirm = function (msg, ok, no) { - layer.close(this.index); - return this.index = layer.confirm(msg, { - btn: ['确认', '取消'] - }, ok, no); - }; - /** - * 显示成功类型的消息 - * @param {type} msg 消息内容 - * @param {type} time 延迟关闭时间 - * @param {type} callback 回调函数 - */ - msg.prototype.success = function (msg, time, callback) { - layer.close(this.index); - return this.index = layer.msg(msg, {icon: 1, shade: this.shade, scrollbar: false, end: callback, time: (time || 2) * 1000}); - }; - /** - * 显示失败类型的消息 - * @param {type} msg 消息内容 - * @param {type} time 延迟关闭时间 - * @param {type} callback 回调函数 - */ - msg.prototype.error = function (msg, time, callback) { - layer.close(this.index); - return this.index = layer.msg(msg, {icon: 2, shade: this.shade, scrollbar: false, time: (time || 3) * 1000, end: callback}); - }; - /** - * 状态消息提示 - * @param {type} msg - * @param {type} time - * @param {type} callback - * @returns {unresolved} - */ - msg.prototype.tips = function (msg, time, callback) { - layer.close(this.index); - return layer.msg(msg, {time: (time || 3) * 1000, shade: this.shade, end: callback}); - }; - /** - * 显示正在加载中的提示 - * @param {type} msg 提示内容 - * @param {type} callback 回调方法 - */ - msg.prototype.loading = function (msg, callback) { - layer.close(this.index); - if (msg) { - return this.index = layer.msg(msg, {icon: 16, scrollbar: false, shade: this.shade, time: 0, end: callback}); - } - return this.index = layer.load(2, {time: 0, scrollbar: false, shade: this.shade, end: callback}); - }; - /** - * 自动处理显示Think返回的Json数据 - * @param {type} data JSON数据对象 - * @param {type} time 延迟关闭时间 - */ - msg.prototype.auto = function (data, time) { - if (data.code === 'SUCCESS') { - $.msg.success(data.info, time, function () { - if (data.referer === 'back') { - window.history.back(); - } else if (data.referer === 'reload') { - $.form.reload(); - } else if (data.referer) { - window.location.href = data.referer; - } else { - $.form.reload(); - } - }); - } else { - $.msg.error(data.info, 3, function () { - if (data.code === 'FAILD_LOGIN') { - if (data.referer.indexOf('http') === 0) { - window.location.href = data.referer; - } - } - }); - } - }; - /** - * 将消息对象挂载到Jq - */ - $.msg = new msg(); - /** - * 表单构造函数 - * @returns {common_L11._form} - */ - function _form() { - this.version = '2.0'; - this._model = null; - this.errMsg = '{status}服务器繁忙,请稍候再试!'; - } - - /** - * 异步加载的数据 - * @param {type} url 请求的地址 - * @param {json|form|$form} data 额外请求数据 - * @param {type} type 提交的类型 GET|POST - * @param {type} callback 成功后的回调方法 - * @param {type} loading 是否显示加载层 - * @param {type} tips 提示消息 - * @param {type} time 消息提示时间 - */ - _form.prototype.load = function (url, data, type, callback, loading, tips, time) { - var self = this; - if (loading !== false) { - var index = $.msg.loading(tips); - } - var send_data = data; - if (typeof data === 'object' && data.tagName === 'FORM') { - send_data = $(data).serialize(); - } - Pace && Pace.restart(); - $.ajax({ - type: type || 'GET', - url: url, - data: send_data || {}, - statusCode: { - 404: function () { - $.msg.tips(self.errMsg.replace('{status}', 'E404 - ')); - }, - 500: function () { - $.msg.tips(self.errMsg.replace('{status}', 'E500 - ')); - } - }, - error: function (XMLHttpRequest, textStatus, errorThrown) { - $.msg.tips(self.errMsg.replace('{status}', 'E' + textStatus + ' - ')); - }, - success: function (res) { - if (loading !== false) { - $.msg.close(index); - } - if (typeof callback === 'function' && callback.call(self, res) === false) { - return false; - } - if (typeof (res) === 'object') { - return $.msg.auto(res, time); - } - if (res.indexOf('A PHP Error was encountered') !== -1) { - return $.msg.tips(self.errMsg.replace('{status}', 'E505 - ')); - } - self.show(res); - } - }); - }; - /** - * 加载HTML到目标位置 - * @param {type} url - * @param {type} data - * @param {type} target - * @param {type} callback - * @param {type} loading - * @param {type} tips - * @returns {undefined} - */ - _form.prototype.open = function (url, data, target, callback, loading, tips) { - data && (typeof (data) === 'object') && (data = $.param(data)); - data && (url += (url.indexOf('?') === -1 ? '?' : '&') + data); - this.load(url, data, 'GET', function (res) { - if (typeof (res) === 'object') { - return $.msg.auto(res); - } - var $container = $('.layer-main-container').html(res); - if (url !== $container.attr('data-location')) { - $container.attr('data-backurl', $container.attr('data-location')).attr('data-location', url); - } - function reinit() { - $.validate.listen.call(this); - $('[data-copy]').map(function () { - var client = new ZeroClipboard(this); - client.on("ready", function () { - client.on("copy", function (event) { - event.clipboardData.setData("text/plain", event.target.getAttribute('data-copy')); - }); - client.on("aftercopy", function () { - $.msg.tips('内容复制成功!'); - }); - }); - }); - JPlaceHolder.init(); - /* 自动给必填字符加上样式 @zoujingli @by 2016-05-11 */ - $container.find('[required]').parent().prevAll('label').addClass('label-required'); - } - reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000); - return (typeof callback === 'function') && callback.call(this); - }, loading, tips); - }; - - /** - * 显示HTML到中主内容区 - * @param {type} html - * @returns {undefined} - */ - _form.prototype.show = function (html) { - var $container = $('.layer-main-container').html(html); - function reinit() { - $.validate.listen.call(this); - $container.find('h3').addClass('animated fadeIn container-animated'); - } - reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000); - }; - /** - * 打开一个iframe窗口 - * @param {type} url - * @returns {unresolved} - */ - _form.prototype.iframe = function (url, title) { - return layer.open({title: title || '窗口', type: 2, area: ['800px', '530px'], fix: true, maxmin: false, content: url}); - }; - /** - * 关闭FORM框 - * @returns {undefined} - */ - _form.prototype.close = function () { - return $(this._modal).modal('hide'); - }; - - /*刷新当前页面*/ - _form.prototype.reload = function () { - window.onhashchange.call(this); - }; - - /*!表单实例挂载*/ - $.form = new _form(); - - - /** URL转URI */ - function _parse_uri(url, obj) { - url = url.indexOf(window.location.hostname) !== -1 ? url.split(window.location.hostname)[1] : url; - url = url.replace(/spm=[\d\-m]+/ig, ''); - if (obj && (node = obj.getAttribute('data-menu-node'))) { - url += ((url.indexOf('?') === -1 ? '?' : '&') + 'spm=' + node); - } else { - window.location.href.replace(/spm=([\d\-m]+)/ig, function (str, node) { - url += ((url.indexOf('?') === -1 ? '?' : '&') + 'spm=' + node); - }); - } - return url; - } - - /** 事件委派 */ - $('body').on('click', '[data-load]', function () { - $.form.load($(this).attr('data-load'), {}, 'GET', null, true, $(this).attr('data-tips')); - }).on('click', '[data-open]', function () { - var url = $(this).attr('data-open'); - window.location.href = '#' + _parse_uri(url, this); - }).on('click', 'a[data-page-href]', function () { - window.location.href = '#' + _parse_uri(this.href, this); - }).on('submit', 'form[data-form-href]', function () { - return $.form.open(this.action, $(this).serialize(), 'main'), false; - }).on('click', '[data-back]', function () { - window.history.back(); - }).on('click', '[data-reload]', function () { - $.form.reload(); - }).on('click', '[data-check-target]', function () { - var checked = !!this.checked; - $($(this).attr('data-check-target')).map(function () { - this.checked = checked; - }); - }).on('click', '[data-update]', function () { - var id = $(this).attr('data-update') || (function () { - var data = []; - return $($(this).attr('data-list-target') || 'input.list-check-box').map(function () { - (this.checked) && data.push(this.value); - }), data.join(','); - }).call(this); - if (id.length < 1) { - return $.msg.tips('请选择需要操作的数据!'); - } - var action = $(this).attr('data-action') || $(this).parents('[data-location]').attr('data-location'); - var value = $(this).attr('data-value') || 0, field = $(this).attr('data-field') || 'status'; - $.msg.confirm('确定要操作这些数据吗?', function () { - $.form.load(action, {field: field, value: value, id: id}, 'POST'); - }); - }).on('click', '[data-href]', function () { - var href = $(this).attr('data-href'); - if (href && href.indexOf('#') !== 0) { - window.location.href = href; - } - }).on('click', '[data-file]', function () { - var type = $(this).attr('data-type') || 'image'; //jpg,png - var field = $(this).attr('data-field') || type; - var method = $(this).attr('data-one') ? 'one' : 'index'; - var title = $(this).attr('data-title') || '文件管理'; - var uptype = $(this).attr('data-uptype') || 'qiniu'; - var url = window.APP_URL + '/plugs/file/' + method + '.html?uptype=' + uptype + '&type=' + type + '&field=' + field; - $.form.iframe(url, title || '文件管理'); - }).on('click', '[data-iframe]', function () { - $.form.iframe($(this).attr('data-iframe'), $(this).attr('data-title') || '窗口'); - }).on('click', '[data-icon]', function () { - var field = $(this).attr('data-field') || 'iconv'; - var url = window.APP_URL + '/plugs/icon.html?field=' + field; - $.form.iframe(url, '图标选择'); - }).on('click', '[data-tips-image]', function () { - var src = this.getAttribute('data-tips-image') || this.src, img = new Image(), index; - img.onload = function () { - index = layer.open({ - type: 1, area: '480px', title: false, closeBtn: 1, skin: 'layui-layer-nobg', shadeClose: true, - content: $(img).appendTo('body').css({background: '#fff', width: '480px', height: 'auto'}), - end: function () { - $(img).remove(); - } - }); - }; - img.src = src; - }).on('mouseenter', '[data-tips-text]', function () { - var text = $(this).attr('data-tips-text'); - var placement = $(this).attr('data-tips-placement') || 'auto'; - $(this).tooltip({title: text, placement: placement}).tooltip('show'); - }).on('click', '[data-phone-view]', function () { - var src = this.getAttribute('data-phone-view') || this.href; - var $container = $('
').appendTo('body'); - var $iframe = $container.find('iframe').attr('src', src); - $container.find('img').on('click', function () { - $iframe.attr('src', src); - }); - var index = layer.open({ - type: 1, scrollbar: false, area: ['320px', '600px'], title: false, closeBtn: 1, skin: 'layui-layer-nobg', shadeClose: true, - content: $container.removeClass('hide'), - end: function () { - $container.remove(); - } - }); - layer.style(index, {boxShadow: 'none'}); - }); - - /** - * 后台页面初始化操作 - * @returns {undefined} - */ - $(function () { - /*! 左侧菜单状态切换 */ - $('ul.sidebar-trans .nav-item a').on('click', function () { - $(this).parents('.sidebar-nav.main-nav').addClass('open').find('ul.sidebar-trans').show(); - $('.sidebar-trans .nav-item').not($(this).parent().addClass('active')).removeClass('active'); - }); - $('body').on('click', '.framework-sidebar-full .sidebar-title', function () { - var $trans = $(this).next('ul.sidebar-trans'), node = $trans.attr('data-menu-node') || false; - node && $.cookie(node, $(this).parent().toggleClass('open').hasClass('open') ? 2 : 1); - $(this).parent().hasClass('open') ? $trans.show() : $trans.hide(); - }); - $('ul.sidebar-trans').map(function () { - var node = this.getAttribute('data-menu-node') || false; - node && (parseInt($.cookie(node) || 2) === 2) && $(this).show().parent().addClass('open'); - }); - /*! Mini Tips 显示*/ - $('body').on('mouseenter mouseleave', '.framework-sidebar-mini .sidebar-trans .nav-item,.framework-sidebar-mini .sidebar-title', function (e) { - $(this).tooltip({ - template: '', - title: $(this).text(), placement: 'right', container: 'body' - }).tooltip('show'); - (e.type === 'mouseleave') && $(this).tooltip('destroy'); - }); - /*! 切换左侧菜单 */ - function showLeftMenu(menuNode, $openNode) { - var $leftmenu = $('[data-menu-box=' + menuNode + ']').removeClass('hide'); - $("[data-menu-box]").not($leftmenu).addClass('hide'); - $openNode ? $openNode.trigger('click') : $leftmenu.find('[data-open]:first').trigger('click'); - } - var $menutarget = $('[data-menu-target]').on('click', function () { - $menutarget.not($(this).addClass('active')).removeClass('active'); - showLeftMenu($(this).attr('data-menu-target')); - }); - /*! 左侧菜单样式切换 */ - var $targetmenu = $('.sidebar-fold').on('click', function () { - var $body = $('.framework-body').toggleClass('framework-sidebar-mini framework-sidebar-full'); - $.cookie('menu-style', $body.hasClass('framework-sidebar-mini') ? 'mini' : 'full'); - }); - ($.cookie('menu-style') !== 'mini') && $targetmenu.trigger('click'); - /*! URI路由处理 */ - window.onhashchange = function () { - var hash = (window.location.hash || '').substring(1); - if (hash.length < 1) { - return $('.topbar-home-link:first').trigger('click') - } - $.form.open(hash); - function _get_menu_by_spm() { - window.location.href.replace(/spm=([\d\-m]+)/ig, function (str, node) { - $menu = $('[data-menu-node="' + node + '"]'); - }); - if ($menu && $menu.size() > 0) { - return $menu; - } else { - return null; - } - } - var uris = hash.split('?')[0].split('/'), $menu = null; - for (var i = uris.length; i > 0; i--) { - if ($('.framework-sidebar [data-open*="' + uris.join('/') + '"]').size() < 1) { - delete uris[uris.length - 1]; - } else { - $menu = $('.framework-sidebar [data-open*="' + uris.join('/') + '"]'); - if ($menu.size() > 1 && /spm=/ig.test(window.location.href)) { - $menu = _get_menu_by_spm(); - } - break; - } - } - if ($menu) { - $menu.parent('li').addClass('active'); - $menu.parents('.sidebar-trans').removeClass('hide').show(); - $menu.parents('.main-nav').addClass('open'); - $menu.parents('[data-menu-box]').removeClass('hide').siblings('[data-menu-box]').addClass('hide'); - } - }; - window.onhashchange.call(this); - }); -})(jQuery); \ No newline at end of file diff --git a/public/static/plugs/jquery/jquery.validate.js b/public/static/plugs/jquery/jquery.validate.js deleted file mode 100644 index 24a5cad6d..000000000 --- a/public/static/plugs/jquery/jquery.validate.js +++ /dev/null @@ -1,383 +0,0 @@ -(function ($) { - - /** - * 定义模块函数 - * @returns {validate_L1.validate} - */ - var validate = function () { - // 模式检测 - this.isSupport = ($('').attr("type") === "email"); - // 表单元素 - this.inputTag = 'input,textarea,select'; - // 检测元素事件 - this.checkEvent = {change: true, blur: true, keyup: false}; - }; - - /** - *获取表单元素的类型 - */ - validate.prototype.getElementType = function (ele) { - return (ele.getAttribute("type") + "").replace(/\W+$/, "").toLowerCase(); - }; - - /** - *去除字符串两头的空格 - */ - validate.prototype.trim = function (str) { - return str.replace(/(^\s*)|(\s*$)/g, ''); - }; - - - /** - * 标签元素是否可见 - * @returns {Boolean} - */ - validate.prototype.isVisible = function (ele) { - return $(ele).is(':visible'); - }; - - /** - * 检测属性是否有定义 - * @param {type} ele - * @param {type} prop - * @param {type} undefined - * @returns {Boolean} - */ - validate.prototype.hasProp = function (ele, prop, undefined) { - if (typeof prop !== "string") { - return false; - } - var attrProp = ele.getAttribute(prop); - return (attrProp !== undefined && attrProp !== null && attrProp !== false) - }; - - /** - * 设置文件选择范围 - * @param {type} ele - * @param {type} start - * @param {type} end - * @returns {validate_L1.validate.prototype} - */ - validate.prototype.selectRange = function (ele, start, end) { - if (ele.createTextRange) { - var range = ele.createTextRange(); - range.collapse(true); - range.moveEnd('character', end); - range.moveStart('character', start); - range.select(); - } else { - //ele.focus(); - ele.setSelectionRange(start, end); - } - return this; - }; - - /** - * 判断表单元素是否为空 - * @param {type} ele - * @param {type} value - * @returns {Boolean} - */ - validate.prototype.isEmpty = function (ele, value) { - value = value || ele.getAttribute('placeholder'); - var trimValue = ele.value; - trimValue = this.trim(trimValue); - if (trimValue === "" || trimValue === value) { - return true; - } - return false; - }; - - /** - * 正则验证表单元素 - * @param {type} ele - * @param {type} regex - * @param {type} params - * @returns {Boolean} - */ - validate.prototype.isRegex = function (ele, regex, params) { - var self = this; - // 原始值和处理值 - var inputValue = ele.value; - var dealValue = inputValue; - var type = this.getElementType(ele); - - if (type !== "password") { - // 密码不trim前后空格 - dealValue = this.trim(inputValue); - if (dealValue !== inputValue) { - if (ele.tagName.toLowerCase() !== "textarea") { - ele.value = dealValue; - } else { - ele.innerHTML = dealValue; - } - } - } - // 获取正则表达式,pattern属性获取优先,然后通过type类型匹配。注意,不处理为空的情况 - regex = regex || ele.getAttribute('pattern'); - if (dealValue === "" || !regex) { - return true; - } - // multiple多数据的处理 - var isMultiple = this.hasProp(ele, 'multiple'), newRegExp = new RegExp(regex, params || 'i'); - // number类型下multiple是无效的 - if (isMultiple && !/^number|range$/i.test(type)) { - var isAllPass = true; - var dealValues = dealValue.split(","); - for (var i in dealValues) { - var partValue = self.trim(dealValues[i]); - if (isAllPass && !newRegExp.test(partValue)) { - isAllPass = false; - } - } - return isAllPass; - } else { - return newRegExp.test(dealValue); - } - return true; - }; - - /** - * 检侧所的表单元素 - */ - validate.prototype.isAllpass = function (elements, options) { - if (!elements) { - return true; - } - var params = options || {}; - var allpass = true; - var self = this; - if (elements.size && elements.size() === 1 && elements.get(0).tagName.toLowerCase() === "form") { - elements = $(elements).find(self.inputTag); - } else if (elements.tagName && elements.tagName.toLowerCase() === "form") { - elements = $(elements).find(self.inputTag); - } - elements.each(function () { - if (self.checkInput(this, params) === false) { - $(this).focus(); - allpass = false; - return false; - } - }); - return allpass; - }; - - /** - * 验证标志 - */ - validate.prototype.remind = function (input, type, tag) { - var text = ''; - // 如果元素完全显示 - if (this.isVisible(input)) { - if (type === "radio" || type === "checkbox") { - this.errorPlacement(input, this.getErrMsg(input)); - } else if (tag === "select" || tag === "empty") { - // 下拉值为空或文本框文本域等为空 - this.errorPlacement(input, (tag === "empty" && text) ? "您尚未输入" + text : this.getErrMsg(input)); - } else if (/^range|number$/i.test(type) && Number(input.value)) { - // 整数值与数值的特殊提示 - this.errorPlacement(input, "值无效"); - } else { - // 文本框文本域格式不准确 - var finalText = this.getErrMsg(input); - if (text) { - finalText = "您输入的" + text + "格式不准确"; - } - this.errorPlacement(input, finalText); - } - } - return false; - }; - - /** - * 检测表单单元 - */ - validate.prototype.checkInput = function (input, options) { - var type = this.getElementType(input); - var tag = input.tagName.toLowerCase(); - var isRequired = this.hasProp(input, "required"); - var isNone = this.hasProp(input, 'data-auto-none'); - //无需要验证 - if (isNone || input.disabled || type === 'submit' || type === 'reset' || type === 'file' || type === 'image' || !this.isVisible(input)) { - return; - } - var allpass = true; - // 需要验证的有 - if (type === "radio" && isRequired) { - var eleRadios = input.name ? $("input[type='radio'][name='" + input.name + "']") : $(input); - var radiopass = false; - eleRadios.each(function () { - if (radiopass === false && $(this).is("[checked]")) { - radiopass = true; - } - }); - if (radiopass === false) { - allpass = this.remind(eleRadios.get(0), type, tag); - } else { - this.successPlacement(input); - } - } else if (type === "checkbox" && isRequired && !$(input).is("[checked]")) { - allpass = this.remind(input, type, tag); - } else if (tag === "select" && isRequired && !input.value) { - allpass = this.remind(input, type, tag); - } else if ((isRequired && this.isEmpty(input)) || !(allpass = this.isRegex(input))) { - allpass ? this.remind(input, type, "empty") : this.remind(input, type, tag); - allpass = false; - } else { - this.successPlacement(input); - } - return allpass; - }; - - /** - *获取错误提示的内容 - */ - validate.prototype.getErrMsg = function (ele) { - return ele.getAttribute('title') || ''; - }; - - /** - * 错误消息显示 - * @param {type} ele - * @param {type} content - * @param {type} options - * @returns {undefined} - */ - validate.prototype.errorPlacement = function (ele, content) { - $(ele).addClass('validate-error'); - this.insertErrorEle(ele); - $($(ele).data('input-info')).addClass('fadeInRight animated').css({width: 'auto'}).html(content); - }; - - /** - * 错误消息消除 - */ - validate.prototype.successPlacement = function (ele) { - $(ele).removeClass('validate-error'); - this.insertErrorEle(ele); - $($(ele).data('input-info')).removeClass('fadeInRight').css({width: '30px'}).html(''); - }; - - /** - * 错误消息标签插入 - * @param {type} ele - * @returns {undefined} - */ - validate.prototype.insertErrorEle = function (ele) { - var $html = $(''); - $html.css({top: $(ele).position().top + 'px', paddingTop: $(ele).css('paddingTop'), paddingBottom: $(ele).css('paddingBottom'), lineHeight: $(ele).css('lineHeight')}); - $(ele).data('input-info') || $(ele).data('input-info', $html.insertAfter(ele)); - }; - - /** - * 表单验证入口 - * @param {type} callback - * @param {type} options - * @returns {$|Function|Zepto} - */ - validate.prototype.check = function (form, callback, options) { - var self = this; - var defaults = { - // 取消浏览器默认的HTML验证 - novalidate: true, - // 禁用submit按钮可用 - submitEnabled: true, - // 额外的其他验证 - validate: function () { - return true; - } - }; - var params = $.extend({}, defaults, options || {}); - if (this.isSupport) { - if (params.novalidate) { - $(form).attr("novalidate", "novalidate"); - } else { - params.hasTypeNormally = true; - } - } - - // disabled的submit按钮还原 - if (params.submitEnabled) { - $(form).find("[disabled]").each(function () { - if (/^image|submit$/.test(this.type)) { - $(this).removeAttr("disabled"); - } - }); - } - - //元素动态监听 - $(form).find(self.inputTag).map(function () { - for (var i in self.checkEvent) { - if (self.checkEvent[i] === true) { - $(this).off(i).on(i, function () { - self.checkInput(this); - }); - } - } - }); - - $(form).bind("submit", function (event) { - var elements = $(this).find(self.inputTag); - if (self.isAllpass(elements, params) && params.validate() && $.isFunction(callback)) { - var sdata = {}; - var data = $(form).serializeArray(); - for (var i in data) { - var key = data[i].name, value = data[i].value; - if (sdata.hasOwnProperty(key)) { - if (typeof sdata[key] === 'object') { - sdata[key].push(value); - } else { - sdata[key] = [sdata[key], value]; - } - } else { - sdata[key] = value; - } - } - callback.call(this, sdata); - } - event.preventDefault(); - return false; - }); - return $(form); - }; - - /** - * 注册对象到Jq - * @param {type} form - * @param {type} callback - * @param {type} options - * @returns {undefined} - */ - $.validate = function (form, callback, options) { - (new validate()).check(form, callback, options); - }; - - /** - * 注册对象到JqFn - * @param {type} callback - * @param {type} options - * @returns {jquery.validate_L1.$|Function|Zepto|$} - */ - $.fn.validate = function (callback, options) { - return (new validate()).check(this, callback, options); - }; - - if ($.form && typeof $.form.load === 'function') { - $.validate.listen = function () { - $('form[data-auto]').map(function () { - if ($(this).attr('data-listen') === 'true') { - return; - } - var callback = $(this).attr('data-callback'); - $(this).attr('data-listen', "true").validate(function (data) { - $.form.load(this.getAttribute('action') || window.location.href, data, - this.getAttribute('method') || 'POST', - window[callback || '_default_callback'] || undefined, true, - this.getAttribute('data-tips') || undefined, - this.getAttribute('data-time') || undefined); - }); - }); - }; - $.validate.listen.call(this); - } -})(jQuery);