')).parent().data('animated', false);
+ // releasing submit
+ me.submiting = false;
+ me.isValid = isValid;
- if ($element.data('animated') !== false)
- $div.addClass('switch-animate').data('animated', true);
+ // trigger callback and event
+ isFunction(opt[ret]) && opt[ret].call(me, form, errors);
+ me.$el.trigger(ret + CLS_NS_FORM, [form, errors]);
- $div
- .append($switchLeft)
- .append($label)
- .append($switchRight);
+ me._debug('log', '>>> ' + ret);
- $element.find('>div').addClass(
- $element.find('input').is(':checked') ? 'switch-on' : 'switch-off'
- );
+ if (!isValid) return;
+ // For jquery.form plugin
+ if (me.vetoed) {
+ $(form).ajaxSubmit(me.ajaxFormOptions);
+ }
+ else if (canSubmit && !me.isAjaxSubmit) {
+ document.createElement('form').submit.call(form);
+ }
+ }
+ );
+ },
- if ($element.find('input').is(':disabled'))
- $(this).addClass('deactivate');
+ _reset: function(e) {
+ var me = this;
- var changeStatus = function ($this) {
- $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
- };
+ me.errors = {};
+ if (e) {
+ me.reseting = true;
+ me.$el.find(INPUT_SELECTOR).each( function(){
+ me._resetElement(this);
+ });
+ delete me.reseting;
+ }
+ },
- $element.on('keydown', function (e) {
- if (e.keyCode === 32) {
- e.stopImmediatePropagation();
- e.preventDefault();
- changeStatus($(e.target).find('span:first'));
+ _resetElement: function(el, all) {
+ this._setClass(el, null);
+ this.hideMsg(el);
+ if (all) {
+ attr(el, ARIA_REQUIRED, null);
+ }
+ },
+
+ // Handle events: "focusin/click"
+ _focusin: function(e) {
+ var me = this,
+ opt = me.options,
+ el = e.target,
+ timely,
+ msg;
+
+ if ( me.validating || ( e.type==='click' && document.activeElement === el ) ) {
+ return;
+ }
+
+ if (opt.focusCleanup) {
+ if ( attr(el, ARIA_INVALID) === 'true' ) {
+ me._setClass(el, null);
+ me.hideMsg(el);
+ }
+ }
+
+ msg = attr(el, DATA_TIP);
+
+ if (msg) {
+ me.showMsg(el, {
+ type: 'tip',
+ msg: msg
+ });
+ } else {
+ if (attr(el, DATA_RULE)) {
+ me._parse(el);
+ }
+ if (timely = attr(el, DATA_TIMELY)) {
+ if ( timely === 8 || timely === 9 ) {
+ me._focusout(e);
+ }
+ }
+ }
+ },
+
+ // Handle events: "focusout/validate/keyup/click/change/input/compositionstart/compositionend"
+ _focusout: function(e) {
+ var me = this,
+ opt = me.options,
+ el = e.target,
+ etype = e.type,
+ etype0,
+ focusin = etype === 'focusin',
+ special = etype === 'validate',
+ elem,
+ field,
+ old,
+ value,
+ timestamp,
+ key, specialKey,
+ timely,
+ timer = 0;
+
+ if (etype === 'compositionstart') {
+ me.pauseValidate = true;
+ }
+ if (etype === 'compositionend') {
+ me.pauseValidate = false;
+ }
+ if (me.pauseValidate) {
+ return;
+ }
+
+ // For checkbox and radio
+ elem = el.name && _checkable(el) ? me.$el.find('input[name="'+ el.name +'"]').get(0) : el;
+ // Get field
+ if (!(field = me.getField(elem)) || !field.rule) {
+ return;
+ }
+ // Cache event type
+ etype0 = field._e;
+ field._e = etype;
+ timely = field.timely;
+
+ if (!special) {
+ if (!timely || (_checkable(el) && etype !== 'click')) {
+ return;
+ }
+
+ value = field.getValue();
+
+ // not validate field unless fill a value
+ if ( field.ignoreBlank && !value && !focusin ) {
+ me.hideMsg(el);
+ return;
+ }
+
+ if ( etype === 'focusout' ) {
+ if (etype0 === 'change') {
+ return;
+ }
+ if ( timely === 2 || timely === 8 ) {
+ old = field.old;
+ if (value && old) {
+ if (field.isValid && !old.showOk) {
+ me.hideMsg(el);
+ } else {
+ me._makeMsg(el, field, old);
+ }
+ } else {
+ return;
}
- });
+ }
+ }
+ else {
+ if ( timely < 2 && !e.data ) {
+ return;
+ }
- $switchLeft.on('click', function (e) {
- changeStatus($(this));
- });
+ // mark timestamp to reduce the frequency of the received event
+ timestamp = +new Date();
+ if ( timestamp - (el._ts || 0) < 100 ) {
+ return;
+ }
+ el._ts = timestamp;
- $switchRight.on('click', function (e) {
- changeStatus($(this));
- });
-
- $element.find('input').on('change', function (e) {
- var $this = $(this)
- , $element = $this.parent()
- , thisState = $this.is(':checked')
- , state = $element.is('.switch-off');
-
- e.preventDefault();
-
- $element.css('left', '');
-
- if (state === thisState) {
-
- if (thisState)
- $element.removeClass('switch-off').addClass('switch-on');
- else
- $element.removeClass('switch-on').addClass('switch-off');
-
- if ($element.data('animated') !== false)
- $element.addClass("switch-animate");
-
- $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
+ // handle keyup
+ if ( etype === 'keyup' ) {
+ if (etype0 === 'input') {
+ return;
}
- });
+ key = e.keyCode;
+ specialKey = {
+ 8: 1, // Backspace
+ 9: 1, // Tab
+ 16: 1, // Shift
+ 32: 1, // Space
+ 46: 1 // Delete
+ };
- $element.find('label').on('mousedown touchstart', function (e) {
- var $this = $(this);
- moving = false;
-
- e.preventDefault();
- e.stopImmediatePropagation();
-
- $this.closest('div').removeClass('switch-animate');
-
- if ($this.closest('.has-switch').is('.deactivate'))
- $this.unbind('click');
- else {
- $this.on('mousemove touchmove', function (e) {
- var $element = $(this).closest('.switch')
- , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
- , percent = (relativeX / $element.width()) * 100
- , left = 25
- , right = 75;
-
- moving = true;
-
- if (percent < left)
- percent = left;
- else if (percent > right)
- percent = right;
-
- $element.find('>div').css('left', (percent - right) + "%")
- });
-
- $this.on('click touchend', function (e) {
- var $this = $(this)
- , $target = $(e.target)
- , $myCheckBox = $target.siblings('input');
-
- e.stopImmediatePropagation();
- e.preventDefault();
-
- $this.unbind('mouseleave');
-
- if (moving)
- $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
- else
- $myCheckBox.prop("checked", !$myCheckBox.is(":checked"));
-
- moving = false;
- $myCheckBox.trigger('change');
- });
-
- $this.on('mouseleave', function (e) {
- var $this = $(this)
- , $myCheckBox = $this.siblings('input');
-
- e.preventDefault();
- e.stopImmediatePropagation();
-
- $this.unbind('mouseleave');
- $this.trigger('mouseup');
-
- $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
- });
-
- $this.on('mouseup', function (e) {
- e.stopImmediatePropagation();
- e.preventDefault();
-
- $(this).unbind('mousemove');
- });
+ // only gets focus, no validation
+ if ( key === 9 && !value ) {
+ return;
}
+
+ // do not validate, if triggered by these keys
+ if ( key < 48 && !specialKey[key] ) {
+ return;
+ }
+ }
+ if ( !focusin ) {
+ // keyboard events, reducing the frequency of validation
+ timer = timely <100 ? (etype === 'click' || el.tagName === 'SELECT') ? 0 : 400 : timely;
+ }
+ }
+ }
+
+ // if the current field is ignored
+ if ( opt.ignore && $(el).is(opt.ignore) ) {
+ return;
+ }
+
+ clearTimeout(field._t);
+
+ if (timer) {
+ field._t = setTimeout(function() {
+ me._validate(el, field);
+ }, timer);
+ } else {
+ if (special) field.old = {};
+ me._validate(el, field);
+ }
+ },
+
+ _setClass: function(el, isValid) {
+ var $el = $(el), opt = this.options;
+ if (opt.bindClassTo) {
+ $el = $el.closest(opt.bindClassTo);
+ }
+ $el.removeClass( opt.invalidClass + ' ' + opt.validClass );
+ if (isValid !== null) {
+ $el.addClass( isValid ? opt.validClass : opt.invalidClass );
+ }
+ },
+
+ _showmsg: function(e, type, msg) {
+ var me = this,
+ el = e.target;
+
+ if ( me.$el.is(el) ) {
+ if (isObject(type)) {
+ me.showMsg(type)
+ }
+ else if ( type === 'tip' ) {
+ me.$el.find(INPUT_SELECTOR +"["+ DATA_TIP +"]", el).each(function(){
+ me.showMsg(this, {type: type, msg: msg});
});
}
- );
- },
- toggleActivation: function () {
- $(this).toggleClass('deactivate');
- },
- isActive: function () {
- return !$(this).hasClass('deactivate');
- },
- setActive: function (active) {
- if (active)
- $(this).removeClass('deactivate');
- else
- $(this).addClass('deactivate');
- },
- toggleState: function (skipOnChange) {
- var $input = $(this).find('input:checkbox');
- $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
- },
- setState: function (value, skipOnChange) {
- $(this).find('input:checkbox').prop('checked', value).trigger('change', skipOnChange);
- },
- status: function () {
- return $(this).find('input:checkbox').is(':checked');
- },
- destroy: function () {
- var $div = $(this).find('div')
- , $checkbox;
-
- $div.find(':not(input:checkbox)').remove();
-
- $checkbox = $div.children();
- $checkbox.unwrap().unwrap();
-
- $checkbox.unbind('change');
-
- return $checkbox;
}
- };
+ else {
+ me.showMsg(el, {type: type, msg: msg});
+ }
+ },
- if (methods[method])
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
- else if (typeof method === 'object' || !method)
- return methods.init.apply(this, arguments);
- else
- $.error('Method ' + method + ' does not exist!');
+ _hidemsg: function(e) {
+ var $el = $(e.target);
+
+ if ( $el.is(INPUT_SELECTOR) ) {
+ this.hideMsg($el);
+ }
+ },
+
+ // Validated a field
+ _validatedField: function(el, field, ret) {
+ var me = this,
+ opt = me.options,
+ isValid = field.isValid = ret.isValid = !!ret.isValid,
+ callback = isValid ? 'valid' : 'invalid';
+
+ ret.key = field.key;
+ ret.ruleName = field._r;
+ ret.id = el.id;
+ ret.value = field.value;
+
+ me.elements[field.key] = ret.element = el;
+ me.isValid = me.$el[0].isValid = isValid ? me.isFormValid() : isValid;
+
+ if (isValid) {
+ ret.type = 'ok';
+ } else {
+ if (me.submiting) {
+ me.errors[field.key] = ret.msg;
+ }
+ me.hasError = true;
+ }
+
+ // cache result
+ field.old = ret;
+
+ // trigger callback
+ isFunction(field[callback]) && field[callback].call(me, el, ret);
+ isFunction(opt.validation) && opt.validation.call(me, el, ret);
+
+ // trigger event
+ $(el).attr( ARIA_INVALID, isValid ? null : true )
+ .trigger( callback + CLS_NS_FIELD, [ret, me] );
+ me.$el.triggerHandler('validation', [ret, me]);
+
+ if (me.checkOnly) return;
+ // set className
+ me._setClass(el, ret.skip || ret.type === 'tip' ? null : isValid);
+ me._makeMsg.apply(me, arguments);
+ },
+
+ _makeMsg: function(el, field, ret) {
+ // show or hide the message
+ if (field.msgMaker) {
+ ret = $.extend({}, ret);
+ if (field._e === 'focusin') {
+ ret.type = 'tip';
+ }
+ this[ ret.showOk || ret.msg || ret.type === 'tip' ? 'showMsg' : 'hideMsg' ](el, ret, field);
+ }
+ },
+
+ // Validated a rule
+ _validatedRule: function(el, field, ret, msgOpt) {
+ field = field || me.getField(el);
+ msgOpt = msgOpt || {};
+
+ var me = this,
+ msg,
+ rule,
+ method = field._r,
+ timely = field.timely,
+ special = timely === 9 || timely === 8,
+ transfer,
+ temp,
+ isValid = false;
+
+ // use null to break validation from a field
+ if (ret === null) {
+ me._validatedField(el, field, {isValid: true, skip: true});
+ field._i = 0;
+ return;
+ }
+ else if (ret === undefined) {
+ transfer = true;
+ }
+ else if (ret === true || ret === '') {
+ isValid = true;
+ }
+ else if (isString(ret)) {
+ msg = ret;
+ }
+ else if (isObject(ret)) {
+ if (ret.error) {
+ msg = ret.error;
+ } else {
+ msg = ret.ok;
+ isValid = true;
+ }
+ }
+
+ rule = field._rules[field._i];
+ if (rule.not) {
+ msg = undefined;
+ isValid = method === "required" || !isValid;
+ }
+ if (rule.or) {
+ if (isValid) {
+ while ( field._i < field._rules.length && field._rules[field._i].or ) {
+ field._i++;
+ }
+ } else {
+ transfer = true;
+ }
+ }
+ else if (rule.and) {
+ if (!field.isValid) transfer = true;
+ }
+
+ if (transfer) {
+ isValid = true;
+ }
+ // message analysis, and throw rule level event
+ else {
+ if (isValid) {
+ if (field.showOk !== false) {
+ temp = attr(el, DATA_OK);
+ msg = temp === null ? isString(field.ok) ? field.ok : msg : temp;
+ if (!isString(msg) && isString(field.showOk)) {
+ msg = field.showOk;
+ }
+ if (isString(msg)) {
+ msgOpt.showOk = isValid;
+ }
+ }
+ }
+ if (!isValid || special) {
+ /* rule message priority:
+ 1. custom DOM message
+ 2. custom field message;
+ 3. global defined message;
+ 4. rule returned message;
+ 5. default message;
+ */
+ msg = (_getDataMsg(el, field, msg || rule.msg || me.messages[method]) || me.messages.fallback).replace(/\{0\|?([^\}]*)\}/, function(m, defaultDisplay){
+ return me._getDisplay(el, field.display) || defaultDisplay || me.messages[0];
+ });
+ }
+ if (!isValid) field.isValid = isValid;
+ msgOpt.msg = msg;
+ $(el).trigger( (isValid ? 'valid' : 'invalid') + CLS_NS_RULE, [method, msg]);
+ }
+
+ if (special && (!transfer || rule.and)) {
+ if (!isValid && !field._m) field._m = msg;
+ field._v = field._v || [];
+ field._v.push({
+ type: isValid ? !transfer ? 'ok' : 'tip' : 'error',
+ msg: msg || rule.msg
+ });
+ }
+
+ me._debug('log', ' ' + field._i + ': ' + method + ' => ' + (isValid || msg));
+
+ // the current rule has passed, continue to validate
+ if ( (isValid || special) && field._i < field._rules.length - 1) {
+ field._i++;
+ me._checkRule(el, field);
+ }
+ // field was invalid, or all fields was valid
+ else {
+ field._i = 0;
+
+ if (special) {
+ msgOpt.isValid = field.isValid;
+ msgOpt.result = field._v;
+ msgOpt.msg = field._m || '';
+ if (!field.value && (field._e === 'focusin')) {
+ msgOpt.type = 'tip';
+ }
+ } else {
+ msgOpt.isValid = isValid;
+ }
+
+ me._validatedField(el, field, msgOpt);
+ delete field._m;
+ delete field._v;
+ }
+ },
+
+ // Verify a rule form a field
+ _checkRule: function(el, field) {
+ var me = this,
+ ret,
+ fn,
+ old,
+ key = field.key,
+ rule = field._rules[field._i],
+ method = rule.method,
+ params = rule.params;
+
+ // request has been sent, wait it
+ if (me.submiting && me.deferred[key]) {
+ return;
+ }
+ old = field.old;
+ field._r = method;
+
+ if (old && !field.must && !rule.must && rule.result !== undefined &&
+ old.ruleName === method && old.id === el.id &&
+ field.value && old.value === field.value )
+ {
+ // get result from cache
+ ret = rule.result;
+ }
+ else {
+ // get result from current rule
+ fn = _getDataRule(el, method) || me.rules[method] || noop;
+ ret = fn.call(field, el, params, field);
+ if (fn.msg) rule.msg = fn.msg;
+ }
+
+ // asynchronous validation
+ if (isObject(ret) && isFunction(ret.then)) {
+ me.deferred[key] = ret;
+
+ // whether the field valid is unknown
+ field.isValid = undefined;
+
+ // show loading message
+ !me.checkOnly && me.showMsg(el, {
+ type: 'loading',
+ msg: me.messages.loading
+ }, field);
+
+ // waiting to parse the response data
+ ret.then(
+ function(d, textStatus, jqXHR) {
+ var data = trim(jqXHR.responseText),
+ result,
+ dataFilter = field.dataFilter;
+
+ // detect if data is json or jsonp format
+ if (/jsonp?/.test(this.dataType)) {
+ data = d;
+ } else if (data.charAt(0) === '{') {
+ data = $.parseJSON(data);
+ }
+
+ // filter data
+ result = dataFilter.call(this, data, field);
+ if (result === undefined) result = dataFilter.call(this, data.data, field);
+
+ rule.data = this.data;
+ rule.result = field.old ? result : undefined;
+ me._validatedRule(el, field, result);
+ },
+ function(jqXHR, textStatus){
+ me._validatedRule(el, field, me.messages[textStatus] || textStatus);
+ }
+ ).always(function(){
+ delete me.deferred[key];
+ });
+ }
+ // other result
+ else {
+ me._validatedRule(el, field, ret);
+ }
+ },
+
+ // Processing the validation
+ _validate: function(el, field) {
+ var me = this;
+
+ // doesn't validate the element that has "disabled" or "novalidate" attribute
+ if ( el.disabled || attr(el, NOVALIDATE) !== null ) {
+ return;
+ }
+
+ field = field || me.getField(el);
+ if (!field) return;
+ if (!field._rules) me._parse(el);
+ if (!field._rules) return;
+
+ me._debug('info', field.key);
+
+ field.isValid = true;
+ field.element = el;
+ // Cache the value
+ field.value = field.getValue();
+
+ // if the field is not required, and that has a blank value
+ if (!field.required && !field.must && !field.value) {
+ if (!_checkable(el)) {
+ me._validatedField(el, field, {isValid: true});
+ return true;
+ }
+ }
+
+ me._checkRule(el, field);
+ return field.isValid;
+ },
+
+ _debug: function(type, messages) {
+ if (window.console && this.options.debug) {
+ console[type](messages);
+ }
+ },
+
+ /**
+ * Detecting whether the value of an element that matches a rule
+ *
+ * @method test
+ * @param {Element} el - input element
+ * @param {String} rule - rule name
+ */
+ test: function(el, rule) {
+ var me = this,
+ ret,
+ parts = rRule.exec(rule),
+ field,
+ method,
+ params;
+
+ if (parts) {
+ method = parts[1];
+ if (method in me.rules) {
+ params = parts[2] || parts[3];
+ params = params ? params.split(', ') : undefined;
+ field = me.getField(el, true);
+ field._r = method;
+ field.value = field.getValue();
+ ret = me.rules[method].call(field, el, params);
+ }
+ }
+
+ return ret === true || ret === undefined || ret === null;
+ },
+
+ _getDisplay: function(el, str) {
+ return !isString(str) ? isFunction(str) ? str.call(this, el) : '' : str;
+ },
+
+ _getMsgOpt: function(obj, field) {
+ var opt = field ? field : this.options;
+ return $.extend({
+ type: 'error',
+ pos: _getPos(opt.msgClass),
+ target: opt.target,
+ wrapper: opt.msgWrapper,
+ style: opt.msgStyle,
+ cls: opt.msgClass,
+ arrow: opt.msgArrow,
+ icon: opt.msgIcon
+ }, isString(obj) ? {msg: obj} : obj);
+ },
+
+ _getMsgDOM: function(el, msgOpt) {
+ var $el = $(el), $msgbox, datafor, tgt, container;
+
+ if ( $el.is(INPUT_SELECTOR) ) {
+ tgt = msgOpt.target || attr(el, DATA_TARGET);
+ if (tgt) {
+ tgt = isFunction(tgt) ? tgt.call(this, el) : this.$el.find(tgt);
+ if (tgt.length) {
+ if ( tgt.is(INPUT_SELECTOR) ) {
+ $el = tgt
+ el = tgt.get(0);
+ } else if ( tgt.hasClass(CLS_MSG_BOX) ) {
+ $msgbox = tgt;
+ } else {
+ container = tgt;
+ }
+ }
+ }
+ if (!$msgbox) {
+ datafor = (!_checkable(el) || !el.name) && el.id ? el.id : el.name;
+ $msgbox = this.$el.find(msgOpt.wrapper + '.' + CLS_MSG_BOX + '[for="' + datafor + '"]');
+ }
+ } else {
+ $msgbox = $el;
+ }
+
+ // Create new message box
+ if (!msgOpt.hide && !$msgbox.length) {
+ $msgbox = $('<'+ msgOpt.wrapper + '>').attr({
+ 'class': CLS_MSG_BOX + (msgOpt.cls ? ' ' + msgOpt.cls : ''),
+ 'style': msgOpt.style || undefined,
+ 'for': datafor
+ });
+
+ if ( _checkable(el) ) {
+ var $parent = $el.parent();
+ $msgbox.appendTo( $parent.is('label') ? $parent.parent() : $parent );
+ } else {
+ if (container) {
+ $msgbox.appendTo(container);
+ } else {
+ $msgbox[!msgOpt.pos || msgOpt.pos === 'right' ? 'insertAfter' : 'insertBefore']($el);
+ }
+ }
+ }
+
+ return $msgbox;
+ },
+
+ /**
+ * Show validation message
+ *
+ * @method showMsg
+ * @param {Element} el - input element
+ * @param {Object} msgOpt
+ */
+ showMsg: function(el, msgOpt, /*INTERNAL*/ field) {
+ if (!el) return;
+ var me = this,
+ opt = me.options,
+ msgShow,
+ msgMaker,
+ temp,
+ $msgbox;
+
+ if (isObject(el) && !el.jquery && !msgOpt) {
+ $.each(el, function(key, msg) {
+ var el = me.elements[key] || me.$el.find(_key2selector(key))[0];
+ me.showMsg(el, msg);
+ });
+ return;
+ }
+
+ if ($(el).is(INPUT_SELECTOR)) {
+ field = field || me.getField(el);
+ }
+
+ if (!(msgMaker = (field || opt).msgMaker)) {
+ return;
+ }
+
+ msgOpt = me._getMsgOpt(msgOpt, field);
+ el = (el.name && _checkable(el) ? me.$el.find('input[name="'+ el.name +'"]') : $(el)).get(0);
+
+ // ok or tip
+ if (!msgOpt.msg && msgOpt.type !== 'error') {
+ temp = attr(el, 'data-' + msgOpt.type);
+ if (temp !== null) msgOpt.msg = temp;
+ }
+
+ if ( !isString(msgOpt.msg) ) {
+ return;
+ }
+
+ $msgbox = me._getMsgDOM(el, msgOpt);
+
+ !rPos.test($msgbox[0].className) && $msgbox.addClass(msgOpt.cls);
+ if ( isIE === 6 && msgOpt.pos === 'bottom' ) {
+ $msgbox[0].style.marginTop = $(el).outerHeight() + 'px';
+ }
+ $msgbox.html( msgMaker.call(me, msgOpt) )[0].style.display = '';
+
+ if (isFunction(msgShow = field && field.msgShow || opt.msgShow)) {
+ msgShow.call(me, $msgbox, msgOpt.type);
+ }
+ },
+
+ /**
+ * Hide validation message
+ *
+ * @method hideMsg
+ * @param {Element} el - input element
+ * @param {Object} msgOpt optional
+ */
+ hideMsg: function(el, msgOpt, /*INTERNAL*/ field) {
+ var me = this,
+ opt = me.options,
+ msgHide,
+ $msgbox;
+
+ el = $(el).get(0);
+ if ($(el).is(INPUT_SELECTOR)) {
+ field = field || me.getField(el);
+ if (field) {
+ if (field.isValid || me.reseting) attr(el, ARIA_INVALID, null);
+ }
+ }
+
+ msgOpt = me._getMsgOpt(msgOpt, field);
+ msgOpt.hide = true;
+
+ $msgbox = me._getMsgDOM(el, msgOpt);
+ if (!$msgbox.length) return;
+
+ if ( isFunction(msgHide = field && field.msgHide || opt.msgHide) ) {
+ msgHide.call(me, $msgbox, msgOpt.type);
+ } else {
+ $msgbox[0].style.display = 'none';
+ $msgbox[0].innerHTML = null;
+ }
+ },
+
+ /**
+ * Get field information
+ *
+ * @method getField
+ * @param {Element} - input element
+ * @return {Object} field
+ */
+ getField: function(el, must) {
+ var me = this,
+ key,
+ field;
+
+ if (isString(el)) {
+ key = el;
+ el = undefined;
+ } else {
+ if (attr(el, DATA_RULE)) {
+ return me._parse(el);
+ }
+ if (el.id && '#' + el.id in me.fields || !el.name) {
+ key = '#' + el.id;
+ } else {
+ key = el.name;
+ }
+ }
+
+ if ( (field = me.fields[key]) || must && (field = new me.Field(key)) ) {
+ field.element = el;
+ }
+
+ return field;
+ },
+
+ /**
+ * Config a field
+ *
+ * @method: setField
+ * @param {String} key
+ * @param {Object} obj
+ */
+ setField: function(key, obj) {
+ var fields = {};
+
+ if (!key) return;
+
+ // update this field
+ if (isString(key)) {
+ fields[key] = obj;
+ }
+ // update fields
+ else {
+ fields = key;
+ }
+
+ this._initFields(fields);
+ },
+
+ /**
+ * Detecting whether the form is valid
+ *
+ * @method isFormValid
+ * @return {Boolean}
+ */
+ isFormValid: function() {
+ var fields = this.fields, k, field;
+ for (k in fields) {
+ field = fields[k];
+ if (!field._rules || !field.required && !field.must && !field.value) continue;
+ if (!field.isValid) return false;
+ }
+ return true;
+ },
+
+ /**
+ * Prevent submission form
+ *
+ * @method holdSubmit
+ * @param {Boolean} hold - If set to false, will release the hold
+ */
+ holdSubmit: function(hold) {
+ this.submiting = hold === undefined || hold;
+ },
+
+ /**
+ * Clean validation messages
+ *
+ * @method cleanUp
+ */
+ cleanUp: function() {
+ this._reset(1);
+ },
+
+ /**
+ * Destroy the validation
+ *
+ * @method destroy
+ */
+ destroy: function() {
+ this._reset(1);
+ this.$el.off(CLS_NS).removeData(NS);
+ attr(this.$el[0], NOVALIDATE, this._NOVALIDATE);
+ }
};
-}(jQuery);
+
+ /**
+ * Create Field Factory
+ *
+ * @class
+ * @param {Object} context
+ * @return {Function} Factory
+ */
+ function _createFieldFactory(context) {
+ function FieldFactory() {
+ var options = this.options;
+ for (var i in options) {
+ if (i in fieldDefaults) this[i] = options[i];
+ }
+ $.extend(this, {
+ _valHook: function() {
+ return this.element.contentEditable === 'true' ? 'text' : 'val';
+ },
+ getValue: function() {
+ var elem = this.element;
+ if (elem.type === "number" && elem.validity && elem.validity.badInput) {
+ return 'NaN';
+ }
+ return $(elem)[this._valHook()]();
+ },
+ setValue: function(value) {
+ $(this.element)[this._valHook()](this.value = value);
+ },
+ // Get a range of validation messages
+ getRangeMsg: function(value, params, suffix) {
+ if (!params) return;
+
+ var me = this,
+ msg = me.messages[me._r] || '',
+ result,
+ p = params[0].split('~'),
+ e = params[1] === 'false',
+ a = p[0],
+ b = p[1],
+ c = 'rg',
+ args = [''],
+ isNumber = trim(value) && +value === +value;
+
+ function compare(large, small) {
+ return !e ? large >= small : large > small;
+ }
+
+ if (p.length === 2) {
+ if (a && b) {
+ if (isNumber && compare(value, +a) && compare(+b, value)) {
+ result = true;
+ }
+ args = args.concat(p);
+ c = e ? 'gtlt' : 'rg';
+ }
+ else if (a && !b) {
+ if (isNumber && compare(value, +a)) {
+ result = true;
+ }
+ args.push(a);
+ c = e ? 'gt' : 'gte';
+ }
+ else if (!a && b) {
+ if (isNumber && compare(+b, value)) {
+ result = true;
+ }
+ args.push(b);
+ c = e ? 'lt' : 'lte';
+ }
+ }
+ else {
+ if (value === +a) {
+ result = true;
+ }
+ args.push(a);
+ c = 'eq';
+ }
+
+ if (msg) {
+ if (suffix && msg[c + suffix]) {
+ c += suffix;
+ }
+ args[0] = msg[c];
+ }
+
+ return result || me._rules && ( me._rules[me._i].msg = me.renderMsg.apply(null, args) );
+ },
+ // Render message template
+ renderMsg: function() {
+ var args = arguments,
+ tpl = args[0],
+ i = args.length;
+
+ if (!tpl) return;
+
+ while (--i) {
+ tpl = tpl.replace('{' + i + '}', args[i]);
+ }
+
+ return tpl;
+ }
+ });
+ }
+ function Field(key, obj, oldField) {
+ this.key = key;
+ this.validator = context;
+ $.extend(this, oldField, obj);
+ }
+
+ FieldFactory.prototype = context;
+ Field.prototype = new FieldFactory();
+
+ return Field;
+ }
+
+ /**
+ * Create Rules
+ *
+ * @class
+ * @param {Object} obj rules
+ * @param {Object} context context
+ */
+ function Rules(obj, context) {
+ if (!isObject(obj)) return;
+
+ var k, that = context ? context === true ? this : context : Rules.prototype;
+
+ for (k in obj) {
+ if (_checkRuleName(k))
+ that[k] = _getRule(obj[k]);
+ }
+ }
+
+ /**
+ * Create Messages
+ *
+ * @class
+ * @param {Object} obj rules
+ * @param {Object} context context
+ */
+ function Messages(obj, context) {
+ if (!isObject(obj)) return;
+
+ var k, that = context ? context === true ? this : context : Messages.prototype;
+
+ for (k in obj) {
+ that[k] = obj[k];
+ }
+ }
+
+ // Rule converted factory
+ function _getRule(fn) {
+ switch ($.type(fn)) {
+ case 'function':
+ return fn;
+ case 'array':
+ var f = function() {
+ return fn[0].test(this.value) || fn[1] || false;
+ };
+ f.msg = fn[1];
+ return f;
+ case 'regexp':
+ return function() {
+ return fn.test(this.value);
+ };
+ }
+ }
+
+ // Get instance by an element
+ function _getInstance(el) {
+ var wrap, k, options;
+
+ if (!el || !el.tagName) return;
+
+ switch (el.tagName) {
+ case 'INPUT':
+ case 'SELECT':
+ case 'TEXTAREA':
+ case 'BUTTON':
+ case 'FIELDSET':
+ wrap = el.form || $(el).closest('.' + CLS_WRAPPER);
+ break;
+ case 'FORM':
+ wrap = el;
+ break;
+ default:
+ wrap = $(el).closest('.' + CLS_WRAPPER);
+ }
+
+ for (k in preinitialized) {
+ if ($(wrap).is(k)) {
+ options = preinitialized[k];
+ break;
+ }
+ }
+
+ return $(wrap).data(NS) || $(wrap)[NS](options).data(NS);
+ }
+
+ // Get custom rules on the node
+ function _getDataRule(el, method) {
+ var fn = trim(attr(el, DATA_RULE + '-' + method));
+
+ if ( fn && (fn = new Function("return " + fn)()) ) {
+ return _getRule(fn);
+ }
+ }
+
+ // Get custom messages on the node
+ function _getDataMsg(el, field, m) {
+ var msg = field.msg,
+ item = field._r;
+
+ if ( isObject(msg) ) msg = msg[item];
+ if ( !isString(msg) ) {
+ msg = attr(el, DATA_MSG + '-' + item) || attr(el, DATA_MSG) || ( m ? isString(m) ? m : m[item] : '');
+ }
+
+ return msg;
+ }
+
+ // Get message position
+ function _getPos(str) {
+ var pos;
+
+ if (str) pos = rPos.exec(str);
+ return pos && pos[0];
+ }
+
+ // Check whether the element is checkbox or radio
+ function _checkable(el) {
+ return el.tagName === 'INPUT' && el.type === 'checkbox' || el.type === 'radio';
+ }
+
+ // Parse date string to timestamp
+ function _parseDate(str) {
+ return Date.parse(str.replace(/\.|\-/g, '/'));
+ }
+
+ // Rule name only allows alphanumeric characters and underscores
+ function _checkRuleName(name) {
+ return /^\w+$/.test(name);
+ }
+
+ // Translate field key to jQuery selector.
+ function _key2selector(key) {
+ var isID = key.charAt(0) === "#";
+ key = key.replace(/([:.{(|)}/\[\]])/g, "\\$1");
+ return isID ? key : '[name="'+ key +'"]:first';
+ }
-define("bootstrap-switch", ["jquery"], function(){});
+ // Fixed a issue cause by refresh page in IE.
+ $(window).on('beforeunload', function(){
+ this.focus();
+ });
-define('form',['jquery', 'bootstrap', 'backend', 'config', 'toastr', 'upload', 'bootstrap-validator', 'bootstrap-checkbox', 'bootstrap-radio', 'bootstrap-switch'], function ($, undefined, Backend, Config, Toastr, Upload, undefined) {
+ $(document)
+ .on('click', ':submit', function(){
+ var input = this, attrNode;
+ if (!input.form) return;
+ // Shim for "formnovalidate"
+ attrNode = input.getAttributeNode('formnovalidate');
+ if (attrNode && attrNode.nodeValue !== null || attr(input, NOVALIDATE)!== null) {
+ novalidateonce = true;
+ }
+ })
+ // Automatic initializing form validation
+ .on('focusin submit validate', 'form,.'+CLS_WRAPPER, function(e) {
+ if ( attr(this, NOVALIDATE) !== null ) return;
+ var $form = $(this), me;
+
+ if ( !$form.data(NS) && (me = _getInstance(this)) ) {
+ if ( !$.isEmptyObject(me.fields) ) {
+ // Execute event handler
+ if (e.type === 'focusin') {
+ me._focusin(e);
+ } else {
+ me._submit(e);
+ }
+ } else {
+ attr(this, NOVALIDATE, NOVALIDATE);
+ $form.off(CLS_NS).removeData(NS);
+ }
+ }
+ });
+
+ new Messages({
+ fallback: "This field is not valid.",
+ loading: 'Validating...'
+ });
+
+
+ // Built-in rules (global)
+ new Rules({
+
+ /**
+ * required
+ *
+ * @example:
+ required
+ required(anotherRule)
+ required(not, -1)
+ required(from, .contact)
+ */
+ required: function(element, params) {
+ var me = this,
+ val = trim(me.value),
+ isValid = true;
+
+ if (params) {
+ if ( params.length === 1 ) {
+ if ( !_checkRuleName(params[0]) ) {
+ if (!val && !$(params[0], me.$el).length ) {
+ return null;
+ }
+ }
+ else if ( me.rules[params[0]] ) {
+ if ( !val && !me.test(element, params[0]) ) {
+ attr(element, ARIA_REQUIRED, null);
+ return null;
+ } else {
+ attr(element, ARIA_REQUIRED, true);
+ }
+ }
+ }
+ else if ( params[0] === 'not' ) {
+ $.each(params.slice(1), function() {
+ return (isValid = val !== trim(this));
+ });
+ }
+ else if ( params[0] === 'from' ) {
+ var $elements = me.$el.find(params[1]),
+ VALIDATED = '_validated_',
+ ret;
+
+ isValid = $elements.filter(function(){
+ var field = me.getField(this);
+ return field && !!trim(field.getValue());
+ }).length >= (params[2] || 1);
+
+ if (isValid) {
+ if (!val) ret = null;
+ } else {
+ ret = _getDataMsg($elements[0], me) || false;
+ }
+
+ if ( !$(element).data(VALIDATED) ) {
+ $elements.data(VALIDATED, 1).each(function(){
+ if (element !== this) {
+ me._validate(this);
+ }
+ }).removeData(VALIDATED);
+ }
+
+ return ret;
+ }
+ }
+
+ return isValid && !!val;
+ },
+
+ /**
+ * integer
+ *
+ * @example:
+ integer
+ integer[+]
+ integer[+0]
+ integer[-]
+ integer[-0]
+ */
+ integer: function(element, params) {
+ var re, z = '0|',
+ p = '[1-9]\\d*',
+ key = params ? params[0] : '*';
+
+ switch (key) {
+ case '+':
+ re = p;
+ break;
+ case '-':
+ re = '-' + p;
+ break;
+ case '+0':
+ re = z + p;
+ break;
+ case '-0':
+ re = z + '-' + p;
+ break;
+ default:
+ re = z + '-?' + p;
+ }
+ re = '^(?:' + re + ')$';
+
+ return new RegExp(re).test(this.value) || this.messages.integer[key];
+ },
+
+ /**
+ * match another field
+ *
+ * @example:
+ match[password] Match the password field (two values must be the same)
+ match[eq, password] Ditto
+ match[neq, count] The value must be not equal to the value of the count field
+ match[lt, count] The value must be less than the value of the count field
+ match[lte, count] The value must be less than or equal to the value of the count field
+ match[gt, count] The value must be greater than the value of the count field
+ match[gte, count] The value must be greater than or equal to the value of the count field
+ match[gte, startDate, date]
+ match[gte, startTime, time]
+ **/
+ match: function(element, params) {
+ if (!params) return;
+
+ var me = this,
+ a, b,
+ key, msg, type = 'eq', parser,
+ selector2, elem2, field2;
+
+ if (params.length === 1) {
+ key = params[0];
+ } else {
+ type = params[0];
+ key = params[1];
+ }
+
+ selector2 = _key2selector(key);
+ elem2 = me.$el.find(selector2)[0];
+ // If the compared field is not exist
+ if (!elem2) return;
+ field2 = me.getField(elem2);
+ a = me.value;
+ b = field2.getValue();
+
+ if (!me._match) {
+ me.$el.on('valid'+CLS_NS_FIELD+CLS_NS, selector2, function(){
+ $(element).trigger('validate');
+ });
+ me._match = field2._match = 1;
+ }
+
+ // If both fields are blank
+ if (!me.required && a === "" && b === "") {
+ return null;
+ }
+
+ parser = params[2];
+ if (parser) {
+ if (/^date(time)?$/i.test(parser)) {
+ a = _parseDate(a);
+ b = _parseDate(b);
+ } else if (parser === 'time') {
+ a = +a.replace(/:/g, '');
+ b = +b.replace(/:/g, '');
+ }
+ }
+
+ // If the compared field is incorrect, we only ensure that this field is correct.
+ if (type !== "eq" && !isNaN(+a) && isNaN(+b)) {
+ return true;
+ }
+
+ msg = me.messages.match[type].replace( '{1}', me._getDisplay( element, field2.display || key ) );
+
+ switch (type) {
+ case 'lt':
+ return (+a < +b) || msg;
+ case 'lte':
+ return (+a <= +b) || msg;
+ case 'gte':
+ return (+a >= +b) || msg;
+ case 'gt':
+ return (+a > +b) || msg;
+ case 'neq':
+ return (a !== b) || msg;
+ default:
+ return (a === b) || msg;
+ }
+ },
+
+ /**
+ * range numbers
+ *
+ * @example:
+ range[0~99] Number 0-99
+ range[0~] Number greater than or equal to 0
+ range[~100] Number less than or equal to 100
+ **/
+ range: function(element, params) {
+ return this.getRangeMsg(this.value, params);
+ },
+
+ /**
+ * how many checkbox or radio inputs that checked
+ *
+ * @example:
+ checked; no empty, same to required
+ checked[1~3] 1-3 items
+ checked[1~] greater than 1 item
+ checked[~3] less than 3 items
+ checked[3] 3 items
+ **/
+ checked: function(element, params) {
+ if ( !_checkable(element) ) return;
+
+ var me = this,
+ elem, count;
+
+ if (element.name) {
+ count = me.$el.find('input[name="' + element.name + '"]').filter(function() {
+ var el = this;
+ if (!elem && _checkable(el)) elem = el;
+ return !el.disabled && el.checked;
+ }).length;
+ } else {
+ elem = element;
+ count = elem.checked;
+ }
+
+ if (params) {
+ return me.getRangeMsg(count, params);
+ } else {
+ return !!count || _getDataMsg(elem, me, '') || me.messages.required;
+ }
+ },
+
+ /**
+ * length of a characters (You can pass the second parameter "true", will calculate the length in bytes)
+ *
+ * @example:
+ length[6~16] 6-16 characters
+ length[6~] Greater than 6 characters
+ length[~16] Less than 16 characters
+ length[~16, true] Less than 16 characters, non-ASCII characters calculating two-character
+ **/
+ length: function(element, params) {
+ var value = this.value,
+ len = (params[1] === 'true' ? value.replace(rDoubleBytes, 'xx') : value).length;
+
+ return this.getRangeMsg(len, params, (params[1] ? '_2' : ''));
+ },
+
+ /**
+ * remote validation
+ *
+ * @description
+ * remote([get:]url [, name1, [name2 ...]]);
+ * Adaptation three kinds of results (Front for the successful, followed by a failure):
+ 1. text:
+ '' 'Error Message'
+ 2. json:
+ {"ok": ""} {"error": "Error Message"}
+ 3. json wrapper:
+ {"status": 1, "data": {"ok": ""}} {"status": 1, "data": {"error": "Error Message"}}
+ * @example
+ The simplest: remote(path/to/server);
+ With parameters: remote(path/to/server, name1, name2, ...);
+ By GET: remote(get:path/to/server, name1, name2, ...);
+ Name proxy: remote(path/to/server, name1, proxyname2:name2, proxyname3:#id3, ...)
+ Query String remote(path/to/server, foo=1&bar=2, name1, name2, ...)
+ */
+ remote: function(element, params) {
+ if (!params) return;
+
+ var me = this,
+ arr = rAjaxType.exec(params[0]),
+ rule = me._rules[me._i],
+ data = {},
+ queryString = '',
+ url = arr[3],
+ type = arr[2] || 'POST', // GET / POST
+ rType = (arr[1]||'').toLowerCase(), // CORS / JSONP
+ dataType;
+
+ rule.must = true;
+ data[element.name] = me.value;
+
+ // There are extra fields
+ if (params[1]) {
+ $.map(params.slice(1), function(name) {
+ var arr, key;
+ if (~name.indexOf('=')) {
+ queryString += '&' + name;
+ } else {
+ arr = name.split(':');
+ name = trim(arr[0]);
+ key = trim(arr[1]) || name;
+ data[ name ] = me.$el.find( _key2selector(key) ).val();
+ }
+ });
+ }
+
+ data = $.param(data) + queryString;
+ if (!me.must && rule.data && rule.data === data) {
+ return rule.result;
+ }
+
+ // Cross-domain request, force jsonp dataType
+ if (rType !== 'cors' && /^https?:/.test(url) && !~url.indexOf(location.host)) {
+ dataType = 'jsonp';
+ }
+
+ // Asynchronous validation need return jqXHR objects
+ return $.ajax({
+ url: url,
+ type: type,
+ data: data,
+ dataType: dataType
+ });
+ },
+
+ /**
+ * filter characters, direct filtration without prompting error (support custom regular expressions)
+ *
+ * @example
+ * filter filtering unsafe characters
+ * filter(regexp) filtering the "regexp" matched characters
+ */
+ filter: function(element, params) {
+ var value = this.value,
+ temp = value.replace( params ? (new RegExp("[" + params[0] + "]", "gm")) : rUnsafe, '' );
+ if (temp !== value) this.setValue(temp);
+ }
+ });
+
+
+ /**
+ * Config global options
+ *
+ * @static config
+ * @param {Object} options
+ */
+ Validator.config = function(key, value) {
+ if (isObject(key)) {
+ $.each(key, _config);
+ }
+ else if (isString(key)) {
+ _config(key, value);
+ }
+
+ function _config(k, o) {
+ if (k === 'rules') {
+ new Rules(o);
+ }
+ else if (k === 'messages') {
+ new Messages(o);
+ }
+ else if (k in fieldDefaults) {
+ fieldDefaults[k] = o;
+ }
+ else {
+ defaults[k] = o;
+ }
+ }
+ };
+
+ /**
+ * Config themes
+ *
+ * @static setTheme
+ * @param {String|Object} name
+ * @param {Object} obj
+ * @example
+ .setTheme( themeName, themeOptions )
+ .setTheme( multiThemes )
+ */
+ Validator.setTheme = function(name, obj) {
+ if ( isObject(name) ) {
+ $.extend(true, themes, name);
+ }
+ else if ( isString(name) && isObject(obj) ) {
+ themes[name] = $.extend(themes[name], obj);
+ }
+ };
+
+ /**
+ * Resource loader
+ *
+ * @static load
+ * @param {String} str
+ * @example
+ .load('local=zh-CN') // load: local/zh-CN.js and jquery.validator.css
+ .load('local=zh-CN&css=') // load: local/zh-CN.js
+ .load('local&css') // load: local/en.js (set ) and jquery.validator.css
+ .load('local') // dito
+ */
+ Validator.load = function(str) {
+ if (!str) return;
+ var doc = document,
+ params = {},
+ node = doc.scripts[0],
+ dir, el, ONLOAD;
+
+ str.replace(/([^?=&]+)=([^]*)/g, function(m, key, value){
+ params[key] = value;
+ });
+
+ dir = params.dir || Validator.dir;
+
+ if (!Validator.css && params.css !== '') {
+ el = doc.createElement('link');
+ el.rel = 'stylesheet';
+ el.href = Validator.css = dir + 'jquery.validator.css';
+ node.parentNode.insertBefore(el, node);
+ }
+ if (!Validator.local && ~str.indexOf('local') && params.local !== '') {
+ Validator.local = (params.local || doc.documentElement.lang || 'en').replace('_','-');
+ Validator.pending = 1;
+ el = doc.createElement('script');
+ el.src = dir + 'local/' + Validator.local + '.js';
+ ONLOAD = 'onload' in el ? 'onload' : 'onreadystatechange';
+ el[ONLOAD] = function() {
+ if (!el.readyState || /loaded|complete/.test(el.readyState)) {
+ el = el[ONLOAD] = null;
+ delete Validator.pending;
+ $(window).triggerHandler('validatorready');
+ }
+ };
+ node.parentNode.insertBefore(el, node);
+ }
+ };
+
+ // Auto loading resources
+ (function(){
+ var scripts = document.scripts,
+ i = scripts.length, node, arr,
+ re = /(.*validator(?:\.min)?.js)(\?.*(?:local|css|dir)(?:=[\w\-]*)?)?/;
+
+ while (i-- && !arr) {
+ node = scripts[i];
+ arr = (node.hasAttribute ? node.src : node.getAttribute('src',4)||'').match(re);
+ }
+
+ if (!arr) return;
+ Validator.dir = arr[1].split('/').slice(0, -1).join('/')+'/';
+ Validator.load(arr[2]);
+ })();
+
+ return $[NS] = Validator;
+}));
+
+
+define('../libs/require-css/css.min!../libs/nice-validator/dist/jquery.validator',[],function(){});
+/*********************************
+ * Themes, rules, and i18n support
+ * Locale: Chinese; 中文
+ *********************************/
+(function(factory) {
+ typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
+ typeof define === 'function' && define.amd ? define('validator',['jquery'], factory) :
+ factory(jQuery);
+}(function($) {
+
+ /* Global configuration
+ */
+ $.validator.config({
+ //stopOnError: true,
+ //focusCleanup: true,
+ //theme: 'yellow_right',
+ //timely: 2,
+
+ // Custom rules
+ rules: {
+ digits: [/^\d+$/, "请填写数字"]
+ ,letters: [/^[a-z]+$/i, "请填写字母"]
+ ,date: [/^\d{4}-\d{2}-\d{2}$/, "请填写有效的日期,格式:yyyy-mm-dd"]
+ ,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "请填写有效的时间,00:00到23:59之间"]
+ ,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "请填写有效的邮箱"]
+ ,url: [/^(https?|s?ftp):\/\/\S+$/i, "请填写有效的网址"]
+ ,qq: [/^[1-9]\d{4,}$/, "请填写有效的QQ号"]
+ ,IDcard: [/^\d{6}(19|2\d)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)?$/, "请填写正确的身份证号码"]
+ ,tel: [/^(?:(?:0\d{2,3}[\- ]?[1-9]\d{6,7})|(?:[48]00[\- ]?[1-9]\d{6}))$/, "请填写有效的电话号码"]
+ ,mobile: [/^1[3-9]\d{9}$/, "请填写有效的手机号"]
+ ,zipcode: [/^\d{6}$/, "请检查邮政编码格式"]
+ ,chinese: [/^[\u0391-\uFFE5]+$/, "请填写中文字符"]
+ ,username: [/^\w{3,12}$/, "请填写3-12位数字、字母、下划线"]
+ ,password: [/^[\S]{6,16}$/, "请填写6-16位字符,不能包含空格"]
+ ,accept: function (element, params){
+ if (!params) return true;
+ var ext = params[0],
+ value = $(element).val();
+ return (ext === '*') ||
+ (new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
+ this.renderMsg("只接受{1}后缀的文件", ext.replace(/\|/g, ','));
+ }
+
+ },
+
+ // Default error messages
+ messages: {
+ 0: "此处",
+ fallback: "{0}格式不正确",
+ loading: "正在验证...",
+ error: "网络异常",
+ timeout: "请求超时",
+ required: "{0}不能为空",
+ remote: "{0}已被使用",
+ integer: {
+ '*': "请填写整数",
+ '+': "请填写正整数",
+ '+0': "请填写正整数或0",
+ '-': "请填写负整数",
+ '-0': "请填写负整数或0"
+ },
+ match: {
+ eq: "{0}与{1}不一致",
+ neq: "{0}与{1}不能相同",
+ lt: "{0}必须小于{1}",
+ gt: "{0}必须大于{1}",
+ lte: "{0}不能大于{1}",
+ gte: "{0}不能小于{1}"
+ },
+ range: {
+ rg: "请填写{1}到{2}的数",
+ gte: "请填写不小于{1}的数",
+ lte: "请填写最大{1}的数",
+ gtlt: "请填写{1}到{2}之间的数",
+ gt: "请填写大于{1}的数",
+ lt: "请填写小于{1}的数"
+ },
+ checked: {
+ eq: "请选择{1}项",
+ rg: "请选择{1}到{2}项",
+ gte: "请至少选择{1}项",
+ lte: "请最多选择{1}项"
+ },
+ length: {
+ eq: "请填写{1}个字符",
+ rg: "请填写{1}到{2}个字符",
+ gte: "请至少填写{1}个字符",
+ lte: "请最多填写{1}个字符",
+ eq_2: "",
+ rg_2: "",
+ gte_2: "",
+ lte_2: ""
+ }
+ }
+ });
+
+ /* Themes
+ */
+ var TPL_ARROW = '
◆◆';
+ $.validator.setTheme({
+ 'simple_right': {
+ formClass: 'n-simple',
+ msgClass: 'n-right'
+ },
+ 'simple_bottom': {
+ formClass: 'n-simple',
+ msgClass: 'n-bottom'
+ },
+ 'yellow_top': {
+ formClass: 'n-yellow',
+ msgClass: 'n-top',
+ msgArrow: TPL_ARROW
+ },
+ 'yellow_right': {
+ formClass: 'n-yellow',
+ msgClass: 'n-right',
+ msgArrow: TPL_ARROW
+ },
+ 'yellow_right_effect': {
+ formClass: 'n-yellow',
+ msgClass: 'n-right',
+ msgArrow: TPL_ARROW,
+ msgShow: function($msgbox, type){
+ var $el = $msgbox.children();
+ if ($el.is(':animated')) return;
+ if (type === 'error') {
+ $el.css({left: '20px', opacity: 0})
+ .delay(100).show().stop()
+ .animate({left: '-4px', opacity: 1}, 150)
+ .animate({left: '3px'}, 80)
+ .animate({left: 0}, 80);
+ } else {
+ $el.css({left: 0, opacity: 1}).fadeIn(200);
+ }
+ },
+ msgHide: function($msgbox, type){
+ var $el = $msgbox.children();
+ $el.stop().delay(100).show()
+ .animate({left: '20px', opacity: 0}, 300, function(){
+ $msgbox.hide();
+ });
+ }
+ }
+ });
+}));
+
+define('form',['jquery', 'bootstrap', 'backend', 'config', 'toastr', 'upload', 'validator'], function ($, undefined, Backend, Config, Toastr, Upload, Validator) {
var Form = {
config: {
},
@@ -8342,11 +10801,14 @@ define('form',['jquery', 'bootstrap', 'backend', 'config', 'toastr', 'upload', '
return false;
},
bindevent: function (form, onBeforeSubmit, onAfterSubmit) {
- form.validator().on('submit', function (e) {
- if (e.isDefaultPrevented()) {
- //验证不通过
- Toastr.error("验证失败,请检查表单输入是否正确");
- } else {
+ form.validator({
+ validClass: 'has-success',
+ invalidClass: 'has-error',
+ bindClassTo: '.form-group',
+ formClass: 'n-default n-bootstrap',
+ msgClass: 'n-right',
+ stopOnError: true,
+ valid: function (ret) {
//验证通过提交表单
Form.api.submit(form, onBeforeSubmit, function (data) {
if (typeof onAfterSubmit == 'function') {
@@ -8364,16 +10826,6 @@ define('form',['jquery', 'bootstrap', 'backend', 'config', 'toastr', 'upload', '
}
});
- // Activate the switches with icons
- if ($('.switch').length != 0) {
- $('.switch')['bootstrapSwitch']();
- }
-
- // Activate regular switches
- if ($("[data-toggle='switch']").length != 0) {
- $("[data-toggle='switch']").wrap('
').parent().bootstrapSwitch();
- }
-
//绑定select元素事件
if ($(".selectpicker", form).size() > 0) {
require(['bootstrap-select'], function () {
@@ -8511,390 +10963,390 @@ define('form',['jquery', 'bootstrap', 'backend', 'config', 'toastr', 'upload', '
};
return Form;
});
-// jQuery List DragSort v0.5.2
-// Website: http://dragsort.codeplex.com/
-// License: http://dragsort.codeplex.com/license
-
-(function($) {
-
- $.fn.dragsort = function(options) {
- if (options == "destroy") {
- $(this.selector).trigger("dragsort-uninit");
- return;
- }
-
- var opts = $.extend({}, $.fn.dragsort.defaults, options);
- var lists = [];
- var list = null, lastPos = null;
-
- this.each(function(i, cont) {
-
- //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected
- if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody"))
- cont = $(cont).children().get(0);
-
- var newList = {
- draggedItem: null,
- placeHolderItem: null,
- pos: null,
- offset: null,
- offsetLimit: null,
- scroll: null,
- container: cont,
-
- init: function() {
- //set options to default values if not set
- opts.tagName = $(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase();
- if (opts.itemSelector == "")
- opts.itemSelector = opts.tagName;
- if (opts.dragSelector == "")
- opts.dragSelector = opts.tagName;
- if (opts.placeHolderTemplate == "")
- opts.placeHolderTemplate = "<" + opts.tagName + "> " + opts.tagName + ">";
-
- //listidx allows reference back to correct list variable instance
- $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit);
- this.styleDragHandlers(true);
- },
-
- uninit: function() {
- var list = lists[$(this).attr("data-listidx")];
- $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit");
- list.styleDragHandlers(false);
- },
-
- getItems: function() {
- return $(this.container).children(opts.itemSelector);
- },
-
- styleDragHandlers: function(cursor) {
- this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : "");
- },
-
- grabItem: function(e) {
- var list = lists[$(this).attr("data-listidx")];
- var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0);
- var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0;
-
- //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return
- if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem)
- return;
-
- //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved,
- //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude
- //e.preventDefault();
-
- //change cursor to move while dragging
- var dragHandle = e.target;
- while (!$(dragHandle).is(opts.dragSelector)) {
- if (dragHandle == this) return;
- dragHandle = dragHandle.parentNode;
- }
- $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor"));
- $(dragHandle).css("cursor", "move");
-
- //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work
- var listElem = this;
- var trigger = function() {
- list.dragStart.call(listElem, e);
- $(list.container).unbind("mousemove", trigger);
- };
- $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); });
- },
-
- dragStart: function(e) {
- if (list != null && list.draggedItem != null)
- list.dropItem();
-
- list = lists[$(this).attr("data-listidx")];
- list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName)
-
- //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items
- list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem));
-
- //calculate mouse offset relative to draggedItem
- var mt = parseInt(list.draggedItem.css("marginTop"));
- var ml = parseInt(list.draggedItem.css("marginLeft"));
- list.offset = list.draggedItem.offset();
- list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
- list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;
-
- //calculate box the dragged item can't be dragged outside of
- if (!opts.dragBetween) {
- var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight();
- list.offsetLimit = $(list.container).offset();
- list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth();
- list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
- }
-
- //create placeholder item
- var h = list.draggedItem.height();
- var w = list.draggedItem.width();
- if (opts.tagName == "tr") {
- list.draggedItem.children().each(function() { $(this).width($(this).width()); });
- list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true);
- list.draggedItem.after(list.placeHolderItem);
- //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); });
- list.placeHolderItem.children().each(function() { $(this).html(" "); });
- } else {
- list.draggedItem.after(opts.placeHolderTemplate);
- list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true);
- }
-
- if (opts.tagName == "td") {
- var listTable = list.draggedItem.closest("table").get(0);
- $("
").appendTo("body").children().append(list.draggedItem);
- }
-
- //style draggedItem while dragging
- var orig = list.draggedItem.attr("style");
- list.draggedItem.attr("data-origstyle", orig ? orig : "");
- list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });
-
- //auto-scroll setup
- list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() };
- list.scroll.scrollY = window.setInterval(function() {
- if (opts.scrollContainer != window) {
- $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY);
- return;
- }
- var t = $(opts.scrollContainer).scrollTop();
- if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
- $(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
- list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
- }
- }, 10);
- list.scroll.scrollX = window.setInterval(function() {
- if (opts.scrollContainer != window) {
- $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
- return;
- }
- var l = $(opts.scrollContainer).scrollLeft();
- if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
- $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
- list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
- }
- }, 10);
-
- //misc
- $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
- list.setPos(e.pageX, e.pageY);
- $(document).bind("mousemove", list.swapItems);
- $(document).bind("mouseup", list.dropItem);
- if (opts.scrollContainer != window)
- $(window).bind("wheel", list.wheel);
- },
-
- //set position of draggedItem
- setPos: function(x, y) {
- //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner
- var top = y - this.offset.top;
- var left = x - this.offset.left;
-
- //limit top, left to within box draggedItem can't be dragged outside of
- if (!opts.dragBetween) {
- top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
- left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
- }
-
- //adjust top & left calculations to parent offset
- var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin
- if (parent != null) {
- top -= parent.top;
- left -= parent.left;
- }
-
- //set x or y auto-scroll amount
- if (opts.scrollContainer == window) {
- y -= $(window).scrollTop();
- x -= $(window).scrollLeft();
- y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5);
- x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5);
- } else {
- var cont = $(opts.scrollContainer);
- var offset = cont.offset();
- y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
- x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
- }
-
- list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
- list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);
-
- //move draggedItem to new mouse cursor location
- this.draggedItem.css({ top: top, left: left });
- },
-
- //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over
- wheel: function(e) {
- if (list && opts.scrollContainer != window) {
- var cont = $(opts.scrollContainer);
- var offset = cont.offset();
- e = e.originalEvent;
- if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) {
- var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY;
- cont.scrollTop(cont.scrollTop() + deltaY);
- e.preventDefault();
- }
- }
- },
-
- //build a table recording all the positions of the moveable list items
- buildPositionTable: function() {
- var pos = [];
- this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) {
- var loc = $(this).offset();
- loc.right = loc.left + $(this).outerWidth();
- loc.bottom = loc.top + $(this).outerHeight();
- loc.elm = this;
- pos[i] = loc;
- });
- this.pos = pos;
- },
-
- dropItem: function() {
- if (list.draggedItem == null)
- return;
-
- //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
- //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
- var orig = list.draggedItem.attr("data-origstyle");
- list.draggedItem.attr("style", orig);
- if (orig == "")
- list.draggedItem.removeAttr("style");
- list.draggedItem.removeAttr("data-origstyle");
-
- list.styleDragHandlers(true);
-
- list.placeHolderItem.before(list.draggedItem);
- list.placeHolderItem.remove();
-
- $("[data-droptarget], .dragSortItem").remove();
-
- window.clearInterval(list.scroll.scrollY);
- window.clearInterval(list.scroll.scrollX);
-
- //if position changed call dragEnd
- if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem))
- if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order
- var pos = list.draggedItem.attr("data-origpos").split('-');
- var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]);
- if (nextItem.size() > 0)
- nextItem.before(list.draggedItem);
- else if (pos[1] == 0) //was the only item in list
- $(lists[pos[0]].container).prepend(list.draggedItem);
- else //was the last item in list
- $(lists[pos[0]].container).append(list.draggedItem);
- }
- list.draggedItem.removeAttr("data-origpos");
-
- list.draggedItem = null;
- $(document).unbind("mousemove", list.swapItems);
- $(document).unbind("mouseup", list.dropItem);
- if (opts.scrollContainer != window)
- $(window).unbind("wheel", list.wheel);
- return false;
- },
-
- //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of
- swapItems: function(e) {
- if (list.draggedItem == null)
- return false;
-
- //move draggedItem to mouse location
- list.setPos(e.pageX, e.pageY);
-
- //retrieve list and item position mouse cursor is over
- var ei = list.findPos(e.pageX, e.pageY);
- var nlist = list;
- for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) {
- ei = lists[i].findPos(e.pageX, e.pageY);
- nlist = lists[i];
- }
-
- //if not over another moveable list item return
- if (ei == -1)
- return false;
-
- //save fixed items locations
- var children = function() { return $(nlist.container).children().not(nlist.draggedItem); };
- var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); });
-
- //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after
- if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left)
- $(nlist.pos[ei].elm).before(list.placeHolderItem);
- else
- $(nlist.pos[ei].elm).after(list.placeHolderItem);
-
- //restore fixed items location
- fixed.each(function() {
- var elm = children().eq(this.idx).get(0);
- if (this != elm && children().index(this) < this.idx)
- $(this).insertAfter(elm);
- else if (this != elm)
- $(this).insertBefore(elm);
- });
-
- //misc
- $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
- lastPos = list.draggedItem.offset();
- return false;
- },
-
- //returns the index of the list item the mouse is over
- findPos: function(x, y) {
- for (var i = 0; i < this.pos.length; i++) {
- if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y)
- return i;
- }
- return -1;
- },
-
- //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position
- createDropTargets: function() {
- if (!opts.dragBetween)
- return;
-
- $(lists).each(function() {
- var ph = $(this.container).find("[data-placeholder]");
- var dt = $(this.container).find("[data-droptarget]");
- if (ph.size() > 0 && dt.size() > 0)
- dt.remove();
- else if (ph.size() == 0 && dt.size() == 0) {
- if (opts.tagName == "td")
- $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container);
- else
- //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8)
- $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true));
-
- list.placeHolderItem.attr("data-placeholder", true);
- }
- });
- }
- };
-
- newList.init();
- lists.push(newList);
- });
-
- return this;
- };
-
- $.fn.dragsort.defaults = {
- itemSelector: "",
- dragSelector: "",
- dragSelectorExclude: "input, textarea",
- dragEnd: function() { },
- dragBetween: false,
- placeHolderTemplate: "",
- scrollContainer: window,
- scrollSpeed: 5
- };
-
-})(jQuery);
+// jQuery List DragSort v0.5.2
+// Website: http://dragsort.codeplex.com/
+// License: http://dragsort.codeplex.com/license
+
+(function($) {
+
+ $.fn.dragsort = function(options) {
+ if (options == "destroy") {
+ $(this.selector).trigger("dragsort-uninit");
+ return;
+ }
+
+ var opts = $.extend({}, $.fn.dragsort.defaults, options);
+ var lists = [];
+ var list = null, lastPos = null;
+
+ this.each(function(i, cont) {
+
+ //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected
+ if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody"))
+ cont = $(cont).children().get(0);
+
+ var newList = {
+ draggedItem: null,
+ placeHolderItem: null,
+ pos: null,
+ offset: null,
+ offsetLimit: null,
+ scroll: null,
+ container: cont,
+
+ init: function() {
+ //set options to default values if not set
+ opts.tagName = $(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase();
+ if (opts.itemSelector == "")
+ opts.itemSelector = opts.tagName;
+ if (opts.dragSelector == "")
+ opts.dragSelector = opts.tagName;
+ if (opts.placeHolderTemplate == "")
+ opts.placeHolderTemplate = "<" + opts.tagName + "> " + opts.tagName + ">";
+
+ //listidx allows reference back to correct list variable instance
+ $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit);
+ this.styleDragHandlers(true);
+ },
+
+ uninit: function() {
+ var list = lists[$(this).attr("data-listidx")];
+ $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit");
+ list.styleDragHandlers(false);
+ },
+
+ getItems: function() {
+ return $(this.container).children(opts.itemSelector);
+ },
+
+ styleDragHandlers: function(cursor) {
+ this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : "");
+ },
+
+ grabItem: function(e) {
+ var list = lists[$(this).attr("data-listidx")];
+ var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0);
+ var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0;
+
+ //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return
+ if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem)
+ return;
+
+ //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved,
+ //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude
+ //e.preventDefault();
+
+ //change cursor to move while dragging
+ var dragHandle = e.target;
+ while (!$(dragHandle).is(opts.dragSelector)) {
+ if (dragHandle == this) return;
+ dragHandle = dragHandle.parentNode;
+ }
+ $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor"));
+ $(dragHandle).css("cursor", "move");
+
+ //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work
+ var listElem = this;
+ var trigger = function() {
+ list.dragStart.call(listElem, e);
+ $(list.container).unbind("mousemove", trigger);
+ };
+ $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); });
+ },
+
+ dragStart: function(e) {
+ if (list != null && list.draggedItem != null)
+ list.dropItem();
+
+ list = lists[$(this).attr("data-listidx")];
+ list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName)
+
+ //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items
+ list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem));
+
+ //calculate mouse offset relative to draggedItem
+ var mt = parseInt(list.draggedItem.css("marginTop"));
+ var ml = parseInt(list.draggedItem.css("marginLeft"));
+ list.offset = list.draggedItem.offset();
+ list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
+ list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;
+
+ //calculate box the dragged item can't be dragged outside of
+ if (!opts.dragBetween) {
+ var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight();
+ list.offsetLimit = $(list.container).offset();
+ list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth();
+ list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
+ }
+
+ //create placeholder item
+ var h = list.draggedItem.height();
+ var w = list.draggedItem.width();
+ if (opts.tagName == "tr") {
+ list.draggedItem.children().each(function() { $(this).width($(this).width()); });
+ list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true);
+ list.draggedItem.after(list.placeHolderItem);
+ //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); });
+ list.placeHolderItem.children().each(function() { $(this).html(" "); });
+ } else {
+ list.draggedItem.after(opts.placeHolderTemplate);
+ list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true);
+ }
+
+ if (opts.tagName == "td") {
+ var listTable = list.draggedItem.closest("table").get(0);
+ $("
").appendTo("body").children().append(list.draggedItem);
+ }
+
+ //style draggedItem while dragging
+ var orig = list.draggedItem.attr("style");
+ list.draggedItem.attr("data-origstyle", orig ? orig : "");
+ list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });
+
+ //auto-scroll setup
+ list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() };
+ list.scroll.scrollY = window.setInterval(function() {
+ if (opts.scrollContainer != window) {
+ $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY);
+ return;
+ }
+ var t = $(opts.scrollContainer).scrollTop();
+ if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
+ $(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
+ list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
+ }
+ }, 10);
+ list.scroll.scrollX = window.setInterval(function() {
+ if (opts.scrollContainer != window) {
+ $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
+ return;
+ }
+ var l = $(opts.scrollContainer).scrollLeft();
+ if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
+ $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
+ list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
+ }
+ }, 10);
+
+ //misc
+ $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
+ list.setPos(e.pageX, e.pageY);
+ $(document).bind("mousemove", list.swapItems);
+ $(document).bind("mouseup", list.dropItem);
+ if (opts.scrollContainer != window)
+ $(window).bind("wheel", list.wheel);
+ },
+
+ //set position of draggedItem
+ setPos: function(x, y) {
+ //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner
+ var top = y - this.offset.top;
+ var left = x - this.offset.left;
+
+ //limit top, left to within box draggedItem can't be dragged outside of
+ if (!opts.dragBetween) {
+ top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
+ left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
+ }
+
+ //adjust top & left calculations to parent offset
+ var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin
+ if (parent != null) {
+ top -= parent.top;
+ left -= parent.left;
+ }
+
+ //set x or y auto-scroll amount
+ if (opts.scrollContainer == window) {
+ y -= $(window).scrollTop();
+ x -= $(window).scrollLeft();
+ y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5);
+ x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5);
+ } else {
+ var cont = $(opts.scrollContainer);
+ var offset = cont.offset();
+ y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
+ x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
+ }
+
+ list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
+ list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);
+
+ //move draggedItem to new mouse cursor location
+ this.draggedItem.css({ top: top, left: left });
+ },
+
+ //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over
+ wheel: function(e) {
+ if (list && opts.scrollContainer != window) {
+ var cont = $(opts.scrollContainer);
+ var offset = cont.offset();
+ e = e.originalEvent;
+ if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) {
+ var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY;
+ cont.scrollTop(cont.scrollTop() + deltaY);
+ e.preventDefault();
+ }
+ }
+ },
+
+ //build a table recording all the positions of the moveable list items
+ buildPositionTable: function() {
+ var pos = [];
+ this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) {
+ var loc = $(this).offset();
+ loc.right = loc.left + $(this).outerWidth();
+ loc.bottom = loc.top + $(this).outerHeight();
+ loc.elm = this;
+ pos[i] = loc;
+ });
+ this.pos = pos;
+ },
+
+ dropItem: function() {
+ if (list.draggedItem == null)
+ return;
+
+ //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
+ //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
+ var orig = list.draggedItem.attr("data-origstyle");
+ list.draggedItem.attr("style", orig);
+ if (orig == "")
+ list.draggedItem.removeAttr("style");
+ list.draggedItem.removeAttr("data-origstyle");
+
+ list.styleDragHandlers(true);
+
+ list.placeHolderItem.before(list.draggedItem);
+ list.placeHolderItem.remove();
+
+ $("[data-droptarget], .dragSortItem").remove();
+
+ window.clearInterval(list.scroll.scrollY);
+ window.clearInterval(list.scroll.scrollX);
+
+ //if position changed call dragEnd
+ if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem))
+ if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order
+ var pos = list.draggedItem.attr("data-origpos").split('-');
+ var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]);
+ if (nextItem.size() > 0)
+ nextItem.before(list.draggedItem);
+ else if (pos[1] == 0) //was the only item in list
+ $(lists[pos[0]].container).prepend(list.draggedItem);
+ else //was the last item in list
+ $(lists[pos[0]].container).append(list.draggedItem);
+ }
+ list.draggedItem.removeAttr("data-origpos");
+
+ list.draggedItem = null;
+ $(document).unbind("mousemove", list.swapItems);
+ $(document).unbind("mouseup", list.dropItem);
+ if (opts.scrollContainer != window)
+ $(window).unbind("wheel", list.wheel);
+ return false;
+ },
+
+ //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of
+ swapItems: function(e) {
+ if (list.draggedItem == null)
+ return false;
+
+ //move draggedItem to mouse location
+ list.setPos(e.pageX, e.pageY);
+
+ //retrieve list and item position mouse cursor is over
+ var ei = list.findPos(e.pageX, e.pageY);
+ var nlist = list;
+ for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) {
+ ei = lists[i].findPos(e.pageX, e.pageY);
+ nlist = lists[i];
+ }
+
+ //if not over another moveable list item return
+ if (ei == -1)
+ return false;
+
+ //save fixed items locations
+ var children = function() { return $(nlist.container).children().not(nlist.draggedItem); };
+ var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); });
+
+ //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after
+ if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left)
+ $(nlist.pos[ei].elm).before(list.placeHolderItem);
+ else
+ $(nlist.pos[ei].elm).after(list.placeHolderItem);
+
+ //restore fixed items location
+ fixed.each(function() {
+ var elm = children().eq(this.idx).get(0);
+ if (this != elm && children().index(this) < this.idx)
+ $(this).insertAfter(elm);
+ else if (this != elm)
+ $(this).insertBefore(elm);
+ });
+
+ //misc
+ $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
+ lastPos = list.draggedItem.offset();
+ return false;
+ },
+
+ //returns the index of the list item the mouse is over
+ findPos: function(x, y) {
+ for (var i = 0; i < this.pos.length; i++) {
+ if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y)
+ return i;
+ }
+ return -1;
+ },
+
+ //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position
+ createDropTargets: function() {
+ if (!opts.dragBetween)
+ return;
+
+ $(lists).each(function() {
+ var ph = $(this.container).find("[data-placeholder]");
+ var dt = $(this.container).find("[data-droptarget]");
+ if (ph.size() > 0 && dt.size() > 0)
+ dt.remove();
+ else if (ph.size() == 0 && dt.size() == 0) {
+ if (opts.tagName == "td")
+ $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container);
+ else
+ //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8)
+ $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true));
+
+ list.placeHolderItem.attr("data-placeholder", true);
+ }
+ });
+ }
+ };
+
+ newList.init();
+ lists.push(newList);
+ });
+
+ return this;
+ };
+
+ $.fn.dragsort.defaults = {
+ itemSelector: "",
+ dragSelector: "",
+ dragSelectorExclude: "input, textarea",
+ dragEnd: function() { },
+ dragBetween: false,
+ placeHolderTemplate: "",
+ scrollContainer: window,
+ scrollSpeed: 5
+ };
+
+})(jQuery);
define("dragsort", function(){});
-/*!
+/*!
* jquery.event.drag - v 2.2
* Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
* Open Source MIT License - http://threedubmedia.com/code/license
@@ -8902,7 +11354,7 @@ define("dragsort", function(){});
;(function(e){e.fn.drag=function(k,g,j){var i=typeof k=="string"?k:"",h=e.isFunction(k)?k:e.isFunction(g)?g:null;if(i.indexOf("drag")!==0){i="drag"+i}j=(k==h?g:j)||{};return h?this.bind(i,j,h):this.trigger(i)};var b=e.event,a=b.special,d=a.drag={defaults:{which:1,distance:0,not:":input",handle:null,relative:false,drop:true,click:false},datakey:"dragdata",noBubble:true,add:function(i){var h=e.data(this,d.datakey),g=i.data||{};h.related+=1;e.each(d.defaults,function(j,k){if(g[j]!==undefined){h[j]=g[j]}})},remove:function(){e.data(this,d.datakey).related-=1},setup:function(){if(e.data(this,d.datakey)){return}var g=e.extend({related:0},d.defaults);e.data(this,d.datakey,g);b.add(this,"touchstart mousedown",d.init,g);if(this.attachEvent){this.attachEvent("ondragstart",d.dontstart)}},teardown:function(){var g=e.data(this,d.datakey)||{};if(g.related){return}e.removeData(this,d.datakey);b.remove(this,"touchstart mousedown",d.init);d.textselect(true);if(this.detachEvent){this.detachEvent("ondragstart",d.dontstart)}},init:function(i){if(d.touched){return}var g=i.data,h;if(i.which!=0&&g.which>0&&i.which!=g.which){return}if(e(i.target).is(g.not)){return}if(g.handle&&!e(i.target).closest(g.handle,i.currentTarget).length){return}d.touched=i.type=="touchstart"?this:null;g.propagates=1;g.mousedown=this;g.interactions=[d.interaction(this,g)];g.target=i.target;g.pageX=i.pageX;g.pageY=i.pageY;g.dragging=null;h=d.hijack(i,"draginit",g);if(!g.propagates){return}h=d.flatten(h);if(h&&h.length){g.interactions=[];e.each(h,function(){g.interactions.push(d.interaction(this,g))})}g.propagates=g.interactions.length;if(g.drop!==false&&a.drop){a.drop.handler(i,g)}d.textselect(false);if(d.touched){b.add(d.touched,"touchmove touchend",d.handler,g)}else{b.add(document,"mousemove mouseup",d.handler,g)}if(!d.touched||g.live){return false}},interaction:function(h,g){var i=e(h)[g.relative?"position":"offset"]()||{top:0,left:0};return{drag:h,callback:new d.callback(),droppable:[],offset:i}},handler:function(h){var g=h.data;switch(h.type){case !g.dragging&&"touchmove":h.preventDefault();case !g.dragging&&"mousemove":if(Math.pow(h.pageX-g.pageX,2)+Math.pow(h.pageY-g.pageY,2)
0){e.removeData(this,"suppress."+g.type);return}return f.apply(this,arguments)};var c=b.fixHooks.touchstart=b.fixHooks.touchmove=b.fixHooks.touchend=b.fixHooks.touchcancel={props:"clientX clientY pageX pageY screenX screenY".split(" "),filter:function(h,i){if(i){var g=(i.touches&&i.touches[0])||(i.changedTouches&&i.changedTouches[0])||null;if(g){e.each(c.props,function(j,k){h[k]=g[k]})}}return h}};a.draginit=a.dragstart=a.dragend=d})(jQuery);
define("drag", function(){});
-/*!
+/*!
* jquery.event.drop - v 2.2
* Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
* Open Source MIT License - http://threedubmedia.com/code/license
@@ -8910,193 +11362,193 @@ define("drag", function(){});
;(function(d){d.fn.drop=function(i,e,h){var g=typeof i=="string"?i:"",f=d.isFunction(i)?i:d.isFunction(e)?e:null;if(g.indexOf("drop")!==0){g="drop"+g}h=(i==f?e:h)||{};return f?this.bind(g,h,f):this.trigger(g)};d.drop=function(e){e=e||{};b.multi=e.multi===true?Infinity:e.multi===false?1:!isNaN(e.multi)?e.multi:b.multi;b.delay=e.delay||b.delay;b.tolerance=d.isFunction(e.tolerance)?e.tolerance:e.tolerance===null?null:b.tolerance;b.mode=e.mode||b.mode||"intersect"};var c=d.event,a=c.special,b=d.event.special.drop={multi:1,delay:20,mode:"overlap",targets:[],datakey:"dropdata",noBubble:true,add:function(f){var e=d.data(this,b.datakey);e.related+=1},remove:function(){d.data(this,b.datakey).related-=1},setup:function(){if(d.data(this,b.datakey)){return}var e={related:0,active:[],anyactive:0,winner:0,location:{}};d.data(this,b.datakey,e);b.targets.push(this);return false},teardown:function(){var f=d.data(this,b.datakey)||{};if(f.related){return}d.removeData(this,b.datakey);var e=this;b.targets=d.grep(b.targets,function(g){return(g!==e)})},handler:function(g,e){var f,h;if(!e){return}switch(g.type){case"mousedown":case"touchstart":h=d(b.targets);if(typeof e.drop=="string"){h=h.filter(e.drop)}h.each(function(){var i=d.data(this,b.datakey);i.active=[];i.anyactive=0;i.winner=0});e.droppable=h;a.drag.hijack(g,"dropinit",e);break;case"mousemove":case"touchmove":b.event=g;if(!b.timer){b.tolerate(e)}break;case"mouseup":case"touchend":b.timer=clearTimeout(b.timer);if(e.propagates){a.drag.hijack(g,"drop",e);a.drag.hijack(g,"dropend",e)}break}},locate:function(k,h){var l=d.data(k,b.datakey),g=d(k),i=g.offset()||{},e=g.outerHeight(),j=g.outerWidth(),f={elem:k,width:j,height:e,top:i.top,left:i.left,right:i.left+j,bottom:i.top+e};if(l){l.location=f;l.index=h;l.elem=k}return f},contains:function(e,f){return((f[0]||f.left)>=e.left&&(f[0]||f.right)<=e.right&&(f[1]||f.top)>=e.top&&(f[1]||f.bottom)<=e.bottom)},modes:{intersect:function(f,e,g){return this.contains(g,[f.pageX,f.pageY])?1000000000:this.modes.overlap.apply(this,arguments)},overlap:function(f,e,g){return Math.max(0,Math.min(g.bottom,e.bottom)-Math.max(g.top,e.top))*Math.max(0,Math.min(g.right,e.right)-Math.max(g.left,e.left))},fit:function(f,e,g){return this.contains(g,e)?1:0},middle:function(f,e,g){return this.contains(g,[e.left+e.width*0.5,e.top+e.height*0.5])?1:0}},sort:function(f,e){return(e.winner-f.winner)||(f.index-e.index)},tolerate:function(q){var k,e,n,j,l,m,g,p=0,f,h=q.interactions.length,r=[b.event.pageX,b.event.pageY],o=b.tolerance||b.modes[b.mode];do{if(f=q.interactions[p]){if(!f){return}f.drop=[];l=[];m=f.droppable.length;if(o){n=b.locate(f.proxy)}k=0;do{if(g=f.droppable[k]){j=d.data(g,b.datakey);e=j.location;if(!e){continue}j.winner=o?o.call(b,b.event,n,e):b.contains(e,r)?1:0;l.push(j)}}while(++k .navbar").width() - $(".sidebar-toggle").outerWidth() - $(".navbar-custom-menu").outerWidth() - 20);
- _drop();
- });
-
- _add = function (opts) {
- id = 'tab_' + opts.id;
- url = opts.url;
- url += (opts.url.indexOf("?") > -1 ? "&addtabs=1" : "?addtabs=1");
- navobj.find("[role='presentation']").removeClass('active');
- tabobj.find("[role='tabpanel']").removeClass('active');
- //如果TAB不存在,创建一个新的TAB
- if ($("#" + id).size() == 0) {
- //创建新TAB的title
- title = $('' + opts.title + '');
- //是否允许关闭
- if (options.close) {
- title.append(' ');
- }
- //创建新TAB的内容
- content = $('');
- //是否指定TAB内容
- if (opts.content) {
- content.append(opts.content);
- } else if (options.iframeUse && !opts.ajax) {//没有内容,使用IFRAME打开链接
- var height = options.iframeHeight;
- content.append(' ');
- } else {
- $.get(url, function (data) {
- content.append(data);
- });
- }
- //加入TABS
- if ($('.tabdrop li').size() > 0) {
- $('.tabdrop ul').append(title);
- } else {
- navobj.append(title);
- }
- tabobj.append(content);
- }
-
- //激活TAB
- $("#tab_" + id).addClass('active');
- $("#" + id).addClass("active");
- _drop();
- };
-
- _close = function (id) {
- //如果关闭的是当前激活的TAB,激活他的前一个TAB
- if (obj.find("li.active").attr('id') == "tab_" + id) {
- if ($("#tab_" + id).prev().not(".tabdrop").size() > 0) {
- $("#tab_" + id).prev().not(".tabdrop").find("a").trigger("click");
- } else if ($("#tab_" + id).next().size() > 0) {
- $("#tab_" + id).next().trigger("click");
- }
- }
- //关闭TAB
- $("#tab_" + id).remove();
- $("#" + id).remove();
- _drop();
- options.callback();
- };
-
- _drop = function () {
- //创建下拉标签
- var dropdown = $(''
- + (titype ? config.title[0] : config.title)
+ var titleHTML = (config.title ? '
'
+ + (titype ? config.title[0] : config.title)
+ '
' : '');
-
+
config.zIndex = zIndex;
callback([
//遮罩
config.shade ? ('
') : '',
-
+
//主体
'
'
+ (conType && config.type != 2 ? '' : titleHTML)
@@ -451,22 +451,22 @@ Class.pt.creat = function(){
,content = config.content
,conType = typeof content === 'object'
,body = $('body');
-
+
if($('#'+config.id)[0]) return;
if(typeof config.area === 'string'){
config.area = config.area === 'auto' ? ['', ''] : [config.area, ''];
}
-
+
//anim兼容旧版shift
if(config.shift){
config.anim = config.shift;
}
-
+
if(layer.ie == 6){
config.fixed = false;
}
-
+
switch(config.type){
case 0:
config.btn = ('btn' in config) ? config.btn : ready.btn[0];
@@ -491,7 +491,7 @@ Class.pt.creat = function(){
config.tipsMore || layer.closeAll('tips');
break;
}
-
+
//建立容器
that.vessel(conType, function(html, titleHTML, moveElem){
body.append(html[0]);
@@ -521,12 +521,12 @@ Class.pt.creat = function(){
config.type == 4 && that.tips();
});
}
-
+
config.time <= 0 || setTimeout(function(){
layer.close(that.index)
}, config.time);
that.move().callback();
-
+
//为兼容jQuery3.0的css动画影响元素尺寸计算
if(doms.anim[config.anim]){
that.layero.addClass(doms.anim[config.anim]).data('anim', true);
@@ -551,7 +551,7 @@ Class.pt.auto = function(index){
elem.height(area[1] - titHeight - btnHeight - 2*(parseFloat(elem.css('padding'))|0));
}
switch(config.type){
- case 2:
+ case 2:
setHeight('iframe');
break;
default:
@@ -575,12 +575,12 @@ Class.pt.offset = function(){
var type = typeof config.offset === 'object';
that.offsetTop = (win.height() - area[1])/2;
that.offsetLeft = (win.width() - area[0])/2;
-
+
if(type){
that.offsetTop = config.offset[0];
that.offsetLeft = config.offset[1]||that.offsetLeft;
} else if(config.offset !== 'auto'){
-
+
if(config.offset === 't'){ //上
that.offsetTop = 0;
} else if(config.offset === 'r'){ //右
@@ -604,20 +604,20 @@ Class.pt.offset = function(){
} else {
that.offsetTop = config.offset;
}
-
+
}
-
+
if(!config.fixed){
- that.offsetTop = /%$/.test(that.offsetTop) ?
+ that.offsetTop = /%$/.test(that.offsetTop) ?
win.height()*parseFloat(that.offsetTop)/100
: parseFloat(that.offsetTop);
- that.offsetLeft = /%$/.test(that.offsetLeft) ?
+ that.offsetLeft = /%$/.test(that.offsetLeft) ?
win.width()*parseFloat(that.offsetLeft)/100
: parseFloat(that.offsetLeft);
that.offsetTop += win.scrollTop();
that.offsetLeft += win.scrollLeft();
}
-
+
if(layero.attr('minLeft')){
that.offsetTop = win.height() - (layero.find(doms[1]).outerHeight() || 0);
that.offsetLeft = layero.css('left');
@@ -637,10 +637,10 @@ Class.pt.tips = function(){
top: follow.offset().top,
left: follow.offset().left
}, tipsG = layero.find('.layui-layer-TipsG');
-
+
var guide = config.tips[0];
config.tips[1] || tipsG.remove();
-
+
goal.autoLeft = function(){
if(goal.left + layArea[0] - win.width() > 0){
goal.tipLeft = goal.left + goal.width - layArea[0];
@@ -649,16 +649,16 @@ Class.pt.tips = function(){
goal.tipLeft = goal.left;
};
};
-
+
//辨别tips的方位
- goal.where = [function(){ //上
+ goal.where = [function(){ //上
goal.autoLeft();
goal.tipTop = goal.top - layArea[1] - 10;
tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]);
}, function(){ //右
goal.tipLeft = goal.left + goal.width + 10;
goal.tipTop = goal.top;
- tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
+ tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
}, function(){ //下
goal.autoLeft();
goal.tipTop = goal.top + goal.height + 10;
@@ -669,7 +669,7 @@ Class.pt.tips = function(){
tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]);
}];
goal.where[guide-1]();
-
+
/* 8*2为小三角形占据的空间 */
if(guide === 1){
goal.top - (win.scrollTop() + layArea[1] + 8*2) < 0 && goal.where[2]();
@@ -682,11 +682,11 @@ Class.pt.tips = function(){
}
layero.find('.'+doms[5]).css({
- 'background-color': config.tips[1],
+ 'background-color': config.tips[1],
'padding-right': (config.closeBtn ? '30px' : '')
});
layero.css({
- left: goal.tipLeft - (config.fixed ? win.scrollLeft() : 0),
+ left: goal.tipLeft - (config.fixed ? win.scrollLeft() : 0),
top: goal.tipTop - (config.fixed ? win.scrollTop() : 0)
});
}
@@ -700,7 +700,7 @@ Class.pt.move = function(){
,moveElem = layero.find(config.move)
,resizeElem = layero.find('.layui-layer-resize')
,dict = {};
-
+
if(config.move){
moveElem.css('cursor', 'move');
}
@@ -716,7 +716,7 @@ Class.pt.move = function(){
ready.moveElem.css('cursor', 'move').show();
}
});
-
+
resizeElem.on('mousedown', function(e){
e.preventDefault();
dict.resizeStart = true;
@@ -727,7 +727,7 @@ Class.pt.move = function(){
];
ready.moveElem.css('cursor', 'se-resize').show();
});
-
+
_DOC.on('mousemove', function(e){
//拖拽移动
@@ -735,35 +735,35 @@ Class.pt.move = function(){
var X = e.clientX - dict.offset[0]
,Y = e.clientY - dict.offset[1]
,fixed = layero.css('position') === 'fixed';
-
+
e.preventDefault();
-
+
dict.stX = fixed ? 0 : win.scrollLeft();
dict.stY = fixed ? 0 : win.scrollTop();
//控制元素不被拖出窗口外
if(!config.moveOut){
var setRig = win.width() - layero.outerWidth() + dict.stX
- ,setBot = win.height() - layero.outerHeight() + dict.stY;
+ ,setBot = win.height() - layero.outerHeight() + dict.stY;
X < dict.stX && (X = dict.stX);
- X > setRig && (X = setRig);
+ X > setRig && (X = setRig);
Y < dict.stY && (Y = dict.stY);
Y > setBot && (Y = setBot);
}
-
+
layero.css({
left: X
,top: Y
});
}
-
+
//Resize
if(config.resize && dict.resizeStart){
var X = e.clientX - dict.offset[0]
,Y = e.clientY - dict.offset[1];
-
+
e.preventDefault();
-
+
layer.style(that.index, {
width: dict.area[0] + X
,height: dict.area[1] + Y
@@ -781,7 +781,7 @@ Class.pt.move = function(){
ready.moveElem.hide();
}
});
-
+
return that;
};
@@ -798,7 +798,7 @@ Class.pt.callback = function(){
}
}
layer.ie == 6 && that.IE6(layero);
-
+
//按钮
layero.find('.'+ doms[6]).children('a').on('click', function(){
var index = $(this).index();
@@ -815,29 +815,29 @@ Class.pt.callback = function(){
close === false || layer.close(that.index);
}
});
-
+
//取消
function cancel(){
var close = config.cancel && config.cancel(that.index, layero);
close === false || layer.close(that.index);
}
-
+
//右上角关闭回调
layero.find('.'+ doms[7]).on('click', cancel);
-
+
//点遮罩关闭
if(config.shadeClose){
$('#layui-layer-shade'+ that.index).on('click', function(){
layer.close(that.index);
});
- }
-
+ }
+
//最小化
layero.find('.layui-layer-min').on('click', function(){
var min = config.min && config.min(layero);
- min === false || layer.min(that.index, config);
+ min === false || layer.min(that.index, config);
});
-
+
//全屏/还原
layero.find('.layui-layer-max').on('click', function(){
if($(this).hasClass('layui-layer-maxmin')){
@@ -859,11 +859,11 @@ ready.reselect = function(){
$.each($('select'), function(index , value){
var sthis = $(this);
if(!sthis.parents('.'+doms[0])[0]){
- (sthis.attr('layer') == 1 && $('.'+doms[0]).length < 1) && sthis.removeAttr('layer').show();
+ (sthis.attr('layer') == 1 && $('.'+doms[0]).length < 1) && sthis.removeAttr('layer').show();
}
sthis = null;
});
-};
+};
Class.pt.IE6 = function(layero){
//隐藏select
@@ -879,7 +879,7 @@ Class.pt.IE6 = function(layero){
//需依赖原型的对外方法
Class.pt.openLayer = function(){
var that = this;
-
+
//置顶当前窗口
layer.zIndex = that.config.zIndex;
layer.setTop = function(layero){
@@ -897,7 +897,7 @@ ready.record = function(layero){
var area = [
layero.width(),
layero.height(),
- layero.position().top,
+ layero.position().top,
layero.position().left + parseFloat(layero.css('margin-left'))
];
layero.find('.layui-layer-max').addClass('layui-layer-maxmin');
@@ -922,7 +922,7 @@ window.layer = layer;
//获取子iframe的DOM
layer.getChildFrame = function(selector, index){
index = index || $('.'+doms[4]).attr('times');
- return $('#'+ doms[0] + index).find('iframe').contents().find(selector);
+ return $('#'+ doms[0] + index).find('iframe').contents().find(selector);
};
//得到当前iframe层的索引,子iframe时使用
@@ -954,24 +954,24 @@ layer.style = function(index, options, limit){
,titHeight = layero.find(doms[1]).outerHeight() || 0
,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0
,minLeft = layero.attr('minLeft');
-
+
if(type === ready.type[3] || type === ready.type[4]){
return;
}
-
+
if(!limit){
if(parseFloat(options.width) <= 260){
options.width = 260;
};
-
+
if(parseFloat(options.height) - titHeight - btnHeight <= 64){
options.height = 64 + titHeight + btnHeight;
};
}
-
+
layero.css(options);
btnHeight = layero.find('.'+doms[6]).outerHeight();
-
+
if(type === ready.type[2]){
layero.find('iframe').css({
height: parseFloat(options.height) - titHeight - btnHeight
@@ -991,16 +991,16 @@ layer.min = function(index, options){
,titHeight = layero.find(doms[1]).outerHeight() || 0
,left = layero.attr('minLeft') || (181*ready.minIndex)+'px'
,position = layero.css('position');
-
+
ready.record(layero);
-
+
if(ready.minLeft[0]){
left = ready.minLeft[0];
ready.minLeft.shift();
}
-
+
layero.attr('position', position);
-
+
layer.style(index, {
width: 180
,height: titHeight
@@ -1013,7 +1013,7 @@ layer.min = function(index, options){
layero.find('.layui-layer-min').hide();
layero.attr('type') === 'page' && layero.find(doms[4]).hide();
ready.rescollbar(index);
-
+
if(!layero.attr('minLeft')){
ready.minIndex++;
}
@@ -1025,9 +1025,9 @@ layer.restore = function(index){
var layero = $('#'+ doms[0] + index), area = layero.attr('area').split(',');
var type = layero.attr('type');
layer.style(index, {
- width: parseFloat(area[0]),
- height: parseFloat(area[1]),
- top: parseFloat(area[2]),
+ width: parseFloat(area[0]),
+ height: parseFloat(area[1]),
+ top: parseFloat(area[2]),
left: parseFloat(area[3]),
position: layero.attr('position'),
overflow: 'visible'
@@ -1090,16 +1090,16 @@ layer.close = function(index){
layero.remove();
}
};
-
+
if(layero.data('anim')){
layero.addClass(closeAnim);
}
-
+
$('#layui-layer-moves, #layui-layer-shade' + index).remove();
layer.ie == 6 && ready.reselect();
ready.rescollbar(index);
typeof ready.end[index] === 'function' && ready.end[index]();
- delete ready.end[index];
+ delete ready.end[index];
if(layero.attr('minLeft')){
ready.minIndex--;
ready.minLeft.push(layero.attr('minLeft'));
@@ -1119,7 +1119,7 @@ layer.closeAll = function(type){
});
};
-/**
+/**
拓展模块,layui开始合并在一起
@@ -1127,15 +1127,15 @@ layer.closeAll = function(type){
var cache = layer.cache||{}, skin = function(type){
return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-'+type) : '');
-};
-
+};
+
//仿系统prompt
layer.prompt = function(options, yes){
var style = '';
options = options || {};
-
+
if(typeof options === 'function') yes = options;
-
+
if(options.area){
var area = options.area;
style = 'style="width: '+ area[0] +'; height: '+ area[1] + ';"';
@@ -1144,7 +1144,7 @@ layer.prompt = function(options, yes){
var prompt, content = options.formType == 2 ? '' : function(){
return '';
}();
-
+
return layer.open($.extend({
type: 1
,btn: ['确定','取消']
@@ -1220,7 +1220,7 @@ layer.photos = function(options, loop, key){
var photos = type ? options.photos : {}, data = photos.data || [];
var start = photos.start || 0;
dict.imgIndex = (start|0) + 1;
-
+
options.img = options.img || 'img';
if(!type){ //页面直接获取
@@ -1237,13 +1237,13 @@ layer.photos = function(options, loop, key){
});
})
};
-
+
pushData();
-
+
if (data.length === 0) return;
-
+
loop || parent.on('click', options.img, function(){
- var othis = $(this), index = othis.attr('layer-index');
+ var othis = $(this), index = othis.attr('layer-index');
layer.photos($.extend(options, {
photos: {
start: index,
@@ -1254,14 +1254,14 @@ layer.photos = function(options, loop, key){
}), true);
pushData();
})
-
+
//不直接弹出
if(!loop) return;
-
+
} else if (data.length === 0){
return layer.msg('没有图片');
}
-
+
//上一张
dict.imgprev = function(key){
dict.imgIndex--;
@@ -1270,7 +1270,7 @@ layer.photos = function(options, loop, key){
}
dict.tabimg(key);
};
-
+
//下一张
dict.imgnext = function(key,errorMsg){
dict.imgIndex++;
@@ -1280,7 +1280,7 @@ layer.photos = function(options, loop, key){
}
dict.tabimg(key)
};
-
+
//方向键
dict.keyup = function(event){
if(!dict.end){
@@ -1295,7 +1295,7 @@ layer.photos = function(options, loop, key){
}
}
}
-
+
//切换
dict.tabimg = function(key){
if(data.length <= 1) return;
@@ -1303,7 +1303,7 @@ layer.photos = function(options, loop, key){
layer.close(dict.index);
layer.photos(options, true, key);
}
-
+
//一些动作
dict.event = function(){
dict.bigimg.hover(function(){
@@ -1311,24 +1311,24 @@ layer.photos = function(options, loop, key){
}, function(){
dict.imgsee.hide();
});
-
+
dict.bigimg.find('.layui-layer-imgprev').on('click', function(event){
event.preventDefault();
dict.imgprev();
- });
-
- dict.bigimg.find('.layui-layer-imgnext').on('click', function(event){
+ });
+
+ dict.bigimg.find('.layui-layer-imgnext').on('click', function(event){
event.preventDefault();
dict.imgnext();
});
-
+
$(document).on('keyup', dict.keyup);
};
-
+
//图片预加载
- function loadImage(url, callback, error) {
+ function loadImage(url, callback, error) {
var img = new Image();
- img.src = url;
+ img.src = url;
if(img.complete){
return callback(img);
}
@@ -1339,9 +1339,9 @@ layer.photos = function(options, loop, key){
img.onerror = function(e){
img.onerror = null;
error(e);
- };
+ };
};
-
+
dict.loadi = layer.load(1, {
shade: 'shade' in options ? false : 0.9,
scrollbar: false
@@ -1353,7 +1353,7 @@ layer.photos = function(options, loop, key){
area: function(){
var imgarea = [img.width, img.height];
var winarea = [$(window).width() - 100, $(window).height() - 100];
-
+
//如果 实际图片的宽或者高比 屏幕大(那么进行缩放)
if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){
var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];//取宽度缩放比例、高度缩放比例
@@ -1365,8 +1365,8 @@ layer.photos = function(options, loop, key){
imgarea[1] = imgarea[1]/wh[1];
}
}
-
- return [imgarea[0]+'px', imgarea[1]+'px'];
+
+ return [imgarea[0]+'px', imgarea[1]+'px'];
}(),
title: false,
shade: 0.9,
@@ -1398,8 +1398,8 @@ layer.photos = function(options, loop, key){
}, function(){
layer.close(dict.loadi);
layer.msg('当前图片地址异常
是否继续查看下一张?', {
- time: 30000,
- btn: ['下一张', '不看了'],
+ time: 30000,
+ btn: ['下一张', '不看了'],
yes: function(){
data.length > 1 && dict.imgnext(true,true);
}
diff --git a/public/assets/less/backend-func.less b/public/assets/less/backend-func.less
index 3f4cb3b4..5c8ef31a 100644
--- a/public/assets/less/backend-func.less
+++ b/public/assets/less/backend-func.less
@@ -317,6 +317,10 @@ body {
border:none!important;
}
+.note-editor .note-editing-area .note-editable{
+ display: block !important;
+}
+
.pjax-loader-bar .progress {
position: fixed;
top: 0;