调整文件结构,为全面优化javascript代码做准备

This commit is contained in:
yubaolee
2016-04-06 23:28:27 +08:00
parent 38e2628b15
commit 4ced496da9
449 changed files with 70356 additions and 44446 deletions

View File

@@ -0,0 +1,513 @@
/*!
* iCheck v1.0.2, http://git.io/arlzeA
* ===================================
* Powerful jQuery and Zepto plugin for checkboxes and radio buttons customization
*
* (c) 2013 Damir Sultanov, http://fronteed.com
* MIT Licensed
*/
(function($) {
// Cached vars
var _iCheck = 'iCheck',
_iCheckHelper = _iCheck + '-helper',
_checkbox = 'checkbox',
_radio = 'radio',
_checked = 'checked',
_unchecked = 'un' + _checked,
_disabled = 'disabled',
_determinate = 'determinate',
_indeterminate = 'in' + _determinate,
_update = 'update',
_type = 'type',
_click = 'click',
_touch = 'touchbegin.i touchend.i',
_add = 'addClass',
_remove = 'removeClass',
_callback = 'trigger',
_label = 'label',
_cursor = 'cursor',
_mobile = /ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);
// Plugin init
$.fn[_iCheck] = function(options, fire) {
// Walker
var handle = 'input[type="' + _checkbox + '"], input[type="' + _radio + '"]',
stack = $(),
walker = function(object) {
object.each(function() {
var self = $(this);
if (self.is(handle)) {
stack = stack.add(self);
} else {
stack = stack.add(self.find(handle));
}
});
};
// Check if we should operate with some method
if (/^(check|uncheck|toggle|indeterminate|determinate|disable|enable|update|destroy)$/i.test(options)) {
// Normalize method's name
options = options.toLowerCase();
// Find checkboxes and radio buttons
walker(this);
return stack.each(function() {
var self = $(this);
if (options == 'destroy') {
tidy(self, 'ifDestroyed');
} else {
operate(self, true, options);
}
// Fire method's callback
if ($.isFunction(fire)) {
fire();
}
});
// Customization
} else if (typeof options == 'object' || !options) {
// Check if any options were passed
var settings = $.extend({
checkedClass: _checked,
disabledClass: _disabled,
indeterminateClass: _indeterminate,
labelHover: true
}, options),
selector = settings.handle,
hoverClass = settings.hoverClass || 'hover',
focusClass = settings.focusClass || 'focus',
activeClass = settings.activeClass || 'active',
labelHover = !!settings.labelHover,
labelHoverClass = settings.labelHoverClass || 'hover',
// Setup clickable area
area = ('' + settings.increaseArea).replace('%', '') | 0;
// Selector limit
if (selector == _checkbox || selector == _radio) {
handle = 'input[type="' + selector + '"]';
}
// Clickable area limit
if (area < -50) {
area = -50;
}
// Walk around the selector
walker(this);
return stack.each(function() {
var self = $(this);
// If already customized
tidy(self);
var node = this,
id = node.id,
// Layer styles
offset = -area + '%',
size = 100 + (area * 2) + '%',
layer = {
position: 'absolute',
top: offset,
left: offset,
display: 'block',
width: size,
height: size,
margin: 0,
padding: 0,
background: '#fff',
border: 0,
opacity: 0
},
// Choose how to hide input
hide = _mobile ? {
position: 'absolute',
visibility: 'hidden'
} : area ? layer : {
position: 'absolute',
opacity: 0
},
// Get proper class
className = node[_type] == _checkbox ? settings.checkboxClass || 'i' + _checkbox : settings.radioClass || 'i' + _radio,
// Find assigned labels
label = $(_label + '[for="' + id + '"]').add(self.closest(_label)),
// Check ARIA option
aria = !!settings.aria,
// Set ARIA placeholder
ariaID = _iCheck + '-' + Math.random().toString(36).substr(2,6),
// Parent & helper
parent = '<div class="' + className + '" ' + (aria ? 'role="' + node[_type] + '" ' : ''),
helper;
// Set ARIA "labelledby"
if (aria) {
label.each(function() {
parent += 'aria-labelledby="';
if (this.id) {
parent += this.id;
} else {
this.id = ariaID;
parent += ariaID;
}
parent += '"';
});
}
// Wrap input
parent = self.wrap(parent + '/>')[_callback]('ifCreated').parent().append(settings.insert);
// Layer addition
helper = $('<ins class="' + _iCheckHelper + '"/>').css(layer).appendTo(parent);
// Finalize customization
self.data(_iCheck, {o: settings, s: self.attr('style')}).css(hide);
!!settings.inheritClass && parent[_add](node.className || '');
!!settings.inheritID && id && parent.attr('id', _iCheck + '-' + id);
parent.css('position') == 'static' && parent.css('position', 'relative');
operate(self, true, _update);
// Label events
if (label.length) {
label.on(_click + '.i mouseover.i mouseout.i ' + _touch, function(event) {
var type = event[_type],
item = $(this);
// Do nothing if input is disabled
if (!node[_disabled]) {
// Click
if (type == _click) {
if ($(event.target).is('a')) {
return;
}
operate(self, false, true);
// Hover state
} else if (labelHover) {
// mouseout|touchend
if (/ut|nd/.test(type)) {
parent[_remove](hoverClass);
item[_remove](labelHoverClass);
} else {
parent[_add](hoverClass);
item[_add](labelHoverClass);
}
}
if (_mobile) {
event.stopPropagation();
} else {
return false;
}
}
});
}
// Input events
self.on(_click + '.i focus.i blur.i keyup.i keydown.i keypress.i', function(event) {
var type = event[_type],
key = event.keyCode;
// Click
if (type == _click) {
return false;
// Keydown
} else if (type == 'keydown' && key == 32) {
if (!(node[_type] == _radio && node[_checked])) {
if (node[_checked]) {
off(self, _checked);
} else {
on(self, _checked);
}
}
return false;
// Keyup
} else if (type == 'keyup' && node[_type] == _radio) {
!node[_checked] && on(self, _checked);
// Focus/blur
} else if (/us|ur/.test(type)) {
parent[type == 'blur' ? _remove : _add](focusClass);
}
});
// Helper events
helper.on(_click + ' mousedown mouseup mouseover mouseout ' + _touch, function(event) {
if (helper.hasClass('readonly')) {
event.stopPropagation();
return false;
}
var type = event[_type],
// mousedown|mouseup
toggle = /wn|up/.test(type) ? activeClass : hoverClass;
// Do nothing if input is disabled
if (!node[_disabled]) {
// Click
if (type == _click) {
operate(self, false, true);
// Active and hover states
} else {
// State is on
if (/wn|er|in/.test(type)) {
// mousedown|mouseover|touchbegin
parent[_add](toggle);
// State is off
} else {
parent[_remove](toggle + ' ' + activeClass);
}
// Label hover
if (label.length && labelHover && toggle == hoverClass) {
// mouseout|touchend
label[/ut|nd/.test(type) ? _remove : _add](labelHoverClass);
}
}
if (_mobile) {
event.stopPropagation();
} else {
return false;
}
}
});
});
} else {
return this;
}
};
// Do something with inputs
function operate(input, direct, method) {
var node = input[0],
state = /er/.test(method) ? _indeterminate : /bl/.test(method) ? _disabled : _checked,
active = method == _update ? {
checked: node[_checked],
disabled: node[_disabled],
indeterminate: input.attr(_indeterminate) == 'true' || input.attr(_determinate) == 'false'
} : node[state];
// Check, disable or indeterminate
if (/^(ch|di|in)/.test(method) && !active) {
on(input, state);
// Uncheck, enable or determinate
} else if (/^(un|en|de)/.test(method) && active) {
off(input, state);
// Update
} else if (method == _update) {
// Handle states
for (var each in active) {
if (active[each]) {
on(input, each, true);
} else {
off(input, each, true);
}
}
} else if (!direct || method == 'toggle') {
// Helper or label was clicked
if (!direct) {
input[_callback]('ifClicked');
}
// Toggle checked state
if (active) {
if (node[_type] !== _radio) {
off(input, state);
}
} else {
on(input, state);
}
}
}
// Add checked, disabled or indeterminate state
function on(input, state, keep) {
var node = input[0],
parent = input.parent(),
checked = state == _checked,
indeterminate = state == _indeterminate,
disabled = state == _disabled,
callback = indeterminate ? _determinate : checked ? _unchecked : 'enabled',
regular = option(input, callback + capitalize(node[_type])),
specific = option(input, state + capitalize(node[_type]));
// Prevent unnecessary actions
if (node[state] !== true) {
// Toggle assigned radio buttons
if (!keep && state == _checked && node[_type] == _radio && node.name) {
var form = input.closest('form'),
inputs = 'input[name="' + node.name + '"]';
inputs = form.length ? form.find(inputs) : $(inputs);
inputs.each(function() {
if (this !== node && $(this).data(_iCheck)) {
off($(this), state);
}
});
}
// Indeterminate state
if (indeterminate) {
// Add indeterminate state
node[state] = true;
// Remove checked state
if (node[_checked]) {
off(input, _checked, 'force');
}
// Checked or disabled state
} else {
// Add checked or disabled state
if (!keep) {
node[state] = true;
}
// Remove indeterminate state
if (checked && node[_indeterminate]) {
off(input, _indeterminate, false);
}
}
// Trigger callbacks
callbacks(input, checked, state, keep);
}
// Add proper cursor
if (node[_disabled] && !!option(input, _cursor, true)) {
parent.find('.' + _iCheckHelper).css(_cursor, 'default');
}
// Add state class
parent[_add](specific || option(input, state) || '');
// Set ARIA attribute
if (!!parent.attr('role') && !indeterminate) {
parent.attr('aria-' + (disabled ? _disabled : _checked), 'true');
}
// Remove regular state class
parent[_remove](regular || option(input, callback) || '');
}
// Remove checked, disabled or indeterminate state
function off(input, state, keep) {
var node = input[0],
parent = input.parent(),
checked = state == _checked,
indeterminate = state == _indeterminate,
disabled = state == _disabled,
callback = indeterminate ? _determinate : checked ? _unchecked : 'enabled',
regular = option(input, callback + capitalize(node[_type])),
specific = option(input, state + capitalize(node[_type]));
// Prevent unnecessary actions
if (node[state] !== false) {
// Toggle state
if (indeterminate || !keep || keep == 'force') {
node[state] = false;
}
// Trigger callbacks
callbacks(input, checked, callback, keep);
}
// Add proper cursor
if (!node[_disabled] && !!option(input, _cursor, true)) {
parent.find('.' + _iCheckHelper).css(_cursor, 'pointer');
}
// Remove state class
parent[_remove](specific || option(input, state) || '');
// Set ARIA attribute
if (!!parent.attr('role') && !indeterminate) {
parent.attr('aria-' + (disabled ? _disabled : _checked), 'false');
}
// Add regular state class
parent[_add](regular || option(input, callback) || '');
}
// Remove all traces
function tidy(input, callback) {
if (input.data(_iCheck)) {
// Remove everything except input
input.parent().html(input.attr('style', input.data(_iCheck).s || ''));
// Callback
if (callback) {
input[_callback](callback);
}
// Unbind events
input.off('.i').unwrap();
$(_label + '[for="' + input[0].id + '"]').add(input.closest(_label)).off('.i');
}
}
// Get some option
function option(input, state, regular) {
if (input.data(_iCheck)) {
return input.data(_iCheck).o[state + (regular ? '' : 'Class')];
}
}
// Capitalize some string
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// Executable handlers
function callbacks(input, checked, callback, keep) {
if (!keep) {
if (checked) {
input[_callback]('ifToggled');
}
input[_callback]('ifChanged')[_callback]('if' + capitalize(callback));
}
}
})(window.jQuery || window.Zepto);

View File

@@ -0,0 +1,2 @@
/*! iCheck v1.0.1 by Damir Sultanov, http://git.io/arlzeA, MIT Licensed */
!function(a){function u(a,b,c){var n,d=a[0],g=/er/.test(c)?j:/bl/.test(c)?h:f,m=c==k?{checked:d[f],disabled:d[h],indeterminate:"true"==a.attr(j)||"false"==a.attr(i)}:d[g];if(/^(ch|di|in)/.test(c)&&!m)v(a,g);else if(/^(un|en|de)/.test(c)&&m)w(a,g);else if(c==k)for(n in m)m[n]?v(a,n,!0):w(a,n,!0);else b&&"toggle"!=c||(b||a[q]("ifClicked"),m?d[l]!==e&&w(a,g):v(a,g))}function v(d,k,m){var C,D,n=d[0],q=d.parent(),r=k==f,t=k==j,u=k==h,v=t?i:r?g:"enabled",x=y(d,v+z(n[l])),B=y(d,k+z(n[l]));n[k]!==!0&&(!m&&k==f&&n[l]==e&&n.name&&(C=d.closest("form"),D='input[name="'+n.name+'"]',D=C.length?C.find(D):a(D),D.each(function(){this!==n&&a(this).data(b)&&w(a(this),k)})),t?(n[k]=!0,n[f]&&w(d,f,"force")):(m||(n[k]=!0),r&&n[j]&&w(d,j,!1)),A(d,r,k,m)),n[h]&&y(d,s,!0)&&q.find("."+c).css(s,"default"),q[o](B||y(d,k)||""),q.attr("role")&&!t&&q.attr("aria-"+(u?h:f),"true"),q[p](x||y(d,v)||"")}function w(a,b,d){var e=a[0],k=a.parent(),m=b==f,n=b==j,q=b==h,r=n?i:m?g:"enabled",t=y(a,r+z(e[l])),u=y(a,b+z(e[l]));e[b]!==!1&&((n||!d||"force"==d)&&(e[b]=!1),A(a,m,r,d)),!e[h]&&y(a,s,!0)&&k.find("."+c).css(s,"pointer"),k[p](u||y(a,b)||""),k.attr("role")&&!n&&k.attr("aria-"+(q?h:f),"false"),k[o](t||y(a,r)||"")}function x(c,d){c.data(b)&&(c.parent().html(c.attr("style",c.data(b).s||"")),d&&c[q](d),c.off(".i").unwrap(),a(r+'[for="'+c[0].id+'"]').add(c.closest(r)).off(".i"))}function y(a,c,d){return a.data(b)?a.data(b).o[c+(d?"":"Class")]:void 0}function z(a){return a.charAt(0).toUpperCase()+a.slice(1)}function A(a,b,c,d){d||(b&&a[q]("ifToggled"),a[q]("ifChanged")[q]("if"+z(c)))}var b="iCheck",c=b+"-helper",d="checkbox",e="radio",f="checked",g="un"+f,h="disabled",i="determinate",j="in"+i,k="update",l="type",m="click",n="touchbegin.i touchend.i",o="addClass",p="removeClass",q="trigger",r="label",s="cursor",t=/ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);a.fn[b]=function(g,i){var A,B,C,D,E,F,G,H,s='input[type="'+d+'"], input[type="'+e+'"]',y=a(),z=function(b){b.each(function(){var b=a(this);y=b.is(s)?y.add(b):y.add(b.find(s))})};return/^(check|uncheck|toggle|indeterminate|determinate|disable|enable|update|destroy)$/i.test(g)?(g=g.toLowerCase(),z(this),y.each(function(){var b=a(this);"destroy"==g?x(b,"ifDestroyed"):u(b,!0,g),a.isFunction(i)&&i()})):"object"!=typeof g&&g?this:(A=a.extend({checkedClass:f,disabledClass:h,indeterminateClass:j,labelHover:!0},g),B=A.handle,C=A.hoverClass||"hover",D=A.focusClass||"focus",E=A.activeClass||"active",F=!!A.labelHover,G=A.labelHoverClass||"hover",H=0|(""+A.increaseArea).replace("%",""),(B==d||B==e)&&(s='input[type="'+B+'"]'),-50>H&&(H=-50),z(this),y.each(function(){var N,i,j,s,y,z,B,I,J,K,L,M,g=a(this);x(g),i=this,j=i.id,s=-H+"%",y=100+2*H+"%",z={position:"absolute",top:s,left:s,display:"block",width:y,height:y,margin:0,padding:0,background:"#fff",border:0,opacity:0},B=t?{position:"absolute",visibility:"hidden"}:H?z:{position:"absolute",opacity:0},I=i[l]==d?A.checkboxClass||"i"+d:A.radioClass||"i"+e,J=a(r+'[for="'+j+'"]').add(g.closest(r)),K=!!A.aria,L=b+"-"+Math.random().toString(36).substr(2,6),M='<div class="'+I+'" '+(K?'role="'+i[l]+'" ':""),K&&J.each(function(){M+='aria-labelledby="',this.id?M+=this.id:(this.id=L,M+=L),M+='"'}),M=g.wrap(M+"/>")[q]("ifCreated").parent().append(A.insert),N=a('<ins class="'+c+'"/>').css(z).appendTo(M),g.data(b,{o:A,s:g.attr("style")}).css(B),!!A.inheritClass&&M[o](i.className||""),!!A.inheritID&&j&&M.attr("id",b+"-"+j),"static"==M.css("position")&&M.css("position","relative"),u(g,!0,k),J.length&&J.on(m+".i mouseover.i mouseout.i "+n,function(b){var c=b[l],d=a(this);if(!i[h]){if(c==m){if(a(b.target).is("a"))return;u(g,!1,!0)}else F&&(/ut|nd/.test(c)?(M[p](C),d[p](G)):(M[o](C),d[o](G)));if(!t)return!1;b.stopPropagation()}}),g.on(m+".i focus.i blur.i keyup.i keydown.i keypress.i",function(a){var b=a[l],c=a.keyCode;return b==m?!1:"keydown"==b&&32==c?(i[l]==e&&i[f]||(i[f]?w(g,f):v(g,f)),!1):("keyup"==b&&i[l]==e?!i[f]&&v(g,f):/us|ur/.test(b)&&M["blur"==b?p:o](D),void 0)}),N.on(m+" mousedown mouseup mouseover mouseout "+n,function(a){if(N.hasClass("readonly"))return a.stopPropagation(),!1;var b=a[l],c=/wn|up/.test(b)?E:C;if(!i[h]){if(b==m?u(g,!1,!0):(/wn|er|in/.test(b)?M[o](c):M[p](c+" "+E),J.length&&F&&c==C&&J[/ut|nd/.test(b)?p:o](G)),!t)return!1;a.stopPropagation()}})}))}}(window.jQuery||window.Zepto);