All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/vui) (push) Successful in 46s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/vui-data-loader) (push) Successful in 6s
26460 lines
818 KiB
JavaScript
26460 lines
818 KiB
JavaScript
/*!
|
|
* jQuery JavaScript Library v1.12.4
|
|
* http://jquery.com/
|
|
*
|
|
* Includes Sizzle.js
|
|
* http://sizzlejs.com/
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license
|
|
* http://jquery.org/license
|
|
*
|
|
* Date: 2016-05-20T17:17Z
|
|
*/
|
|
|
|
(function( global, factory ) {
|
|
|
|
if ( typeof module === "object" && typeof module.exports === "object" ) {
|
|
// For CommonJS and CommonJS-like environments where a proper `window`
|
|
// is present, execute the factory and get jQuery.
|
|
// For environments that do not have a `window` with a `document`
|
|
// (such as Node.js), expose a factory as module.exports.
|
|
// This accentuates the need for the creation of a real `window`.
|
|
// e.g. var jQuery = require("jquery")(window);
|
|
// See ticket #14549 for more info.
|
|
module.exports = global.document ?
|
|
factory( global, true ) :
|
|
function( w ) {
|
|
if ( !w.document ) {
|
|
throw new Error( "jQuery requires a window with a document" );
|
|
}
|
|
return factory( w );
|
|
};
|
|
} else {
|
|
factory( global );
|
|
}
|
|
|
|
// Pass this if window is not defined yet
|
|
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
|
|
|
|
// Support: Firefox 18+
|
|
// Can't be in strict mode, several libs including ASP.NET trace
|
|
// the stack via arguments.caller.callee and Firefox dies if
|
|
// you try to trace through "use strict" call chains. (#13335)
|
|
//"use strict";
|
|
var deletedIds = [];
|
|
|
|
var document = window.document;
|
|
|
|
var slice = deletedIds.slice;
|
|
|
|
var concat = deletedIds.concat;
|
|
|
|
var push = deletedIds.push;
|
|
|
|
var indexOf = deletedIds.indexOf;
|
|
|
|
var class2type = {};
|
|
|
|
var toString = class2type.toString;
|
|
|
|
var hasOwn = class2type.hasOwnProperty;
|
|
|
|
var support = {};
|
|
|
|
|
|
|
|
var
|
|
version = "1.12.4",
|
|
|
|
// Define a local copy of jQuery
|
|
jQuery = function( selector, context ) {
|
|
|
|
// The jQuery object is actually just the init constructor 'enhanced'
|
|
// Need init if jQuery is called (just allow error to be thrown if not included)
|
|
return new jQuery.fn.init( selector, context );
|
|
},
|
|
|
|
// Support: Android<4.1, IE<9
|
|
// Make sure we trim BOM and NBSP
|
|
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
|
|
|
|
// Matches dashed string for camelizing
|
|
rmsPrefix = /^-ms-/,
|
|
rdashAlpha = /-([\da-z])/gi,
|
|
|
|
// Used by jQuery.camelCase as callback to replace()
|
|
fcamelCase = function( all, letter ) {
|
|
return letter.toUpperCase();
|
|
};
|
|
|
|
jQuery.fn = jQuery.prototype = {
|
|
|
|
// The current version of jQuery being used
|
|
jquery: version,
|
|
|
|
constructor: jQuery,
|
|
|
|
// Start with an empty selector
|
|
selector: "",
|
|
|
|
// The default length of a jQuery object is 0
|
|
length: 0,
|
|
|
|
toArray: function() {
|
|
return slice.call( this );
|
|
},
|
|
|
|
// Get the Nth element in the matched element set OR
|
|
// Get the whole matched element set as a clean array
|
|
get: function( num ) {
|
|
return num != null ?
|
|
|
|
// Return just the one element from the set
|
|
( num < 0 ? this[ num + this.length ] : this[ num ] ) :
|
|
|
|
// Return all the elements in a clean array
|
|
slice.call( this );
|
|
},
|
|
|
|
// Take an array of elements and push it onto the stack
|
|
// (returning the new matched element set)
|
|
pushStack: function( elems ) {
|
|
|
|
// Build a new jQuery matched element set
|
|
var ret = jQuery.merge( this.constructor(), elems );
|
|
|
|
// Add the old object onto the stack (as a reference)
|
|
ret.prevObject = this;
|
|
ret.context = this.context;
|
|
|
|
// Return the newly-formed element set
|
|
return ret;
|
|
},
|
|
|
|
// Execute a callback for every element in the matched set.
|
|
each: function( callback ) {
|
|
return jQuery.each( this, callback );
|
|
},
|
|
|
|
map: function( callback ) {
|
|
return this.pushStack( jQuery.map( this, function( elem, i ) {
|
|
return callback.call( elem, i, elem );
|
|
} ) );
|
|
},
|
|
|
|
slice: function() {
|
|
return this.pushStack( slice.apply( this, arguments ) );
|
|
},
|
|
|
|
first: function() {
|
|
return this.eq( 0 );
|
|
},
|
|
|
|
last: function() {
|
|
return this.eq( -1 );
|
|
},
|
|
|
|
eq: function( i ) {
|
|
var len = this.length,
|
|
j = +i + ( i < 0 ? len : 0 );
|
|
return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] );
|
|
},
|
|
|
|
end: function() {
|
|
return this.prevObject || this.constructor();
|
|
},
|
|
|
|
// For internal use only.
|
|
// Behaves like an Array's method, not like a jQuery method.
|
|
push: push,
|
|
sort: deletedIds.sort,
|
|
splice: deletedIds.splice
|
|
};
|
|
|
|
jQuery.extend = jQuery.fn.extend = function() {
|
|
var src, copyIsArray, copy, name, options, clone,
|
|
target = arguments[ 0 ] || {},
|
|
i = 1,
|
|
length = arguments.length,
|
|
deep = false;
|
|
|
|
// Handle a deep copy situation
|
|
if ( typeof target === "boolean" ) {
|
|
deep = target;
|
|
|
|
// skip the boolean and the target
|
|
target = arguments[ i ] || {};
|
|
i++;
|
|
}
|
|
|
|
// Handle case when target is a string or something (possible in deep copy)
|
|
if ( typeof target !== "object" && !jQuery.isFunction( target ) ) {
|
|
target = {};
|
|
}
|
|
|
|
// extend jQuery itself if only one argument is passed
|
|
if ( i === length ) {
|
|
target = this;
|
|
i--;
|
|
}
|
|
|
|
for ( ; i < length; i++ ) {
|
|
|
|
// Only deal with non-null/undefined values
|
|
if ( ( options = arguments[ i ] ) != null ) {
|
|
|
|
// Extend the base object
|
|
for ( name in options ) {
|
|
src = target[ name ];
|
|
copy = options[ name ];
|
|
|
|
// Prevent never-ending loop
|
|
if ( target === copy ) {
|
|
continue;
|
|
}
|
|
|
|
// Recurse if we're merging plain objects or arrays
|
|
if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
|
|
( copyIsArray = jQuery.isArray( copy ) ) ) ) {
|
|
|
|
if ( copyIsArray ) {
|
|
copyIsArray = false;
|
|
clone = src && jQuery.isArray( src ) ? src : [];
|
|
|
|
} else {
|
|
clone = src && jQuery.isPlainObject( src ) ? src : {};
|
|
}
|
|
|
|
// Never move original objects, clone them
|
|
target[ name ] = jQuery.extend( deep, clone, copy );
|
|
|
|
// Don't bring in undefined values
|
|
} else if ( copy !== undefined ) {
|
|
target[ name ] = copy;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Return the modified object
|
|
return target;
|
|
};
|
|
|
|
jQuery.extend( {
|
|
|
|
// Unique for each copy of jQuery on the page
|
|
expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
|
|
|
|
// Assume jQuery is ready without the ready module
|
|
isReady: true,
|
|
|
|
error: function( msg ) {
|
|
throw new Error( msg );
|
|
},
|
|
|
|
noop: function() {},
|
|
|
|
// See test/unit/core.js for details concerning isFunction.
|
|
// Since version 1.3, DOM methods and functions like alert
|
|
// aren't supported. They return false on IE (#2968).
|
|
isFunction: function( obj ) {
|
|
return jQuery.type( obj ) === "function";
|
|
},
|
|
|
|
isArray: Array.isArray || function( obj ) {
|
|
return jQuery.type( obj ) === "array";
|
|
},
|
|
|
|
isWindow: function( obj ) {
|
|
/* jshint eqeqeq: false */
|
|
return obj != null && obj == obj.window;
|
|
},
|
|
|
|
isNumeric: function( obj ) {
|
|
|
|
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
|
|
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
|
|
// subtraction forces infinities to NaN
|
|
// adding 1 corrects loss of precision from parseFloat (#15100)
|
|
var realStringObj = obj && obj.toString();
|
|
return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
|
|
},
|
|
|
|
isEmptyObject: function( obj ) {
|
|
var name;
|
|
for ( name in obj ) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
isPlainObject: function( obj ) {
|
|
var key;
|
|
|
|
// Must be an Object.
|
|
// Because of IE, we also have to check the presence of the constructor property.
|
|
// Make sure that DOM nodes and window objects don't pass through, as well
|
|
if ( !obj || jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
|
|
// Not own constructor property must be Object
|
|
if ( obj.constructor &&
|
|
!hasOwn.call( obj, "constructor" ) &&
|
|
!hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
|
|
return false;
|
|
}
|
|
} catch ( e ) {
|
|
|
|
// IE8,9 Will throw exceptions on certain host objects #9897
|
|
return false;
|
|
}
|
|
|
|
// Support: IE<9
|
|
// Handle iteration over inherited properties before own properties.
|
|
if ( !support.ownFirst ) {
|
|
for ( key in obj ) {
|
|
return hasOwn.call( obj, key );
|
|
}
|
|
}
|
|
|
|
// Own properties are enumerated firstly, so to speed up,
|
|
// if last one is own, then all properties are own.
|
|
for ( key in obj ) {}
|
|
|
|
return key === undefined || hasOwn.call( obj, key );
|
|
},
|
|
|
|
type: function( obj ) {
|
|
if ( obj == null ) {
|
|
return obj + "";
|
|
}
|
|
return typeof obj === "object" || typeof obj === "function" ?
|
|
class2type[ toString.call( obj ) ] || "object" :
|
|
typeof obj;
|
|
},
|
|
|
|
// Workarounds based on findings by Jim Driscoll
|
|
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
|
|
globalEval: function( data ) {
|
|
if ( data && jQuery.trim( data ) ) {
|
|
|
|
// We use execScript on Internet Explorer
|
|
// We use an anonymous function so that context is window
|
|
// rather than jQuery in Firefox
|
|
( window.execScript || function( data ) {
|
|
window[ "eval" ].call( window, data ); // jscs:ignore requireDotNotation
|
|
} )( data );
|
|
}
|
|
},
|
|
|
|
// Convert dashed to camelCase; used by the css and data modules
|
|
// Microsoft forgot to hump their vendor prefix (#9572)
|
|
camelCase: function( string ) {
|
|
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
|
|
},
|
|
|
|
nodeName: function( elem, name ) {
|
|
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
|
|
},
|
|
|
|
each: function( obj, callback ) {
|
|
var length, i = 0;
|
|
|
|
if ( isArrayLike( obj ) ) {
|
|
length = obj.length;
|
|
for ( ; i < length; i++ ) {
|
|
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
for ( i in obj ) {
|
|
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return obj;
|
|
},
|
|
|
|
// Support: Android<4.1, IE<9
|
|
trim: function( text ) {
|
|
return text == null ?
|
|
"" :
|
|
( text + "" ).replace( rtrim, "" );
|
|
},
|
|
|
|
// results is for internal usage only
|
|
makeArray: function( arr, results ) {
|
|
var ret = results || [];
|
|
|
|
if ( arr != null ) {
|
|
if ( isArrayLike( Object( arr ) ) ) {
|
|
jQuery.merge( ret,
|
|
typeof arr === "string" ?
|
|
[ arr ] : arr
|
|
);
|
|
} else {
|
|
push.call( ret, arr );
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
},
|
|
|
|
inArray: function( elem, arr, i ) {
|
|
var len;
|
|
|
|
if ( arr ) {
|
|
if ( indexOf ) {
|
|
return indexOf.call( arr, elem, i );
|
|
}
|
|
|
|
len = arr.length;
|
|
i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
|
|
|
|
for ( ; i < len; i++ ) {
|
|
|
|
// Skip accessing in sparse arrays
|
|
if ( i in arr && arr[ i ] === elem ) {
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
},
|
|
|
|
merge: function( first, second ) {
|
|
var len = +second.length,
|
|
j = 0,
|
|
i = first.length;
|
|
|
|
while ( j < len ) {
|
|
first[ i++ ] = second[ j++ ];
|
|
}
|
|
|
|
// Support: IE<9
|
|
// Workaround casting of .length to NaN on otherwise arraylike objects (e.g., NodeLists)
|
|
if ( len !== len ) {
|
|
while ( second[ j ] !== undefined ) {
|
|
first[ i++ ] = second[ j++ ];
|
|
}
|
|
}
|
|
|
|
first.length = i;
|
|
|
|
return first;
|
|
},
|
|
|
|
grep: function( elems, callback, invert ) {
|
|
var callbackInverse,
|
|
matches = [],
|
|
i = 0,
|
|
length = elems.length,
|
|
callbackExpect = !invert;
|
|
|
|
// Go through the array, only saving the items
|
|
// that pass the validator function
|
|
for ( ; i < length; i++ ) {
|
|
callbackInverse = !callback( elems[ i ], i );
|
|
if ( callbackInverse !== callbackExpect ) {
|
|
matches.push( elems[ i ] );
|
|
}
|
|
}
|
|
|
|
return matches;
|
|
},
|
|
|
|
// arg is for internal usage only
|
|
map: function( elems, callback, arg ) {
|
|
var length, value,
|
|
i = 0,
|
|
ret = [];
|
|
|
|
// Go through the array, translating each of the items to their new values
|
|
if ( isArrayLike( elems ) ) {
|
|
length = elems.length;
|
|
for ( ; i < length; i++ ) {
|
|
value = callback( elems[ i ], i, arg );
|
|
|
|
if ( value != null ) {
|
|
ret.push( value );
|
|
}
|
|
}
|
|
|
|
// Go through every key on the object,
|
|
} else {
|
|
for ( i in elems ) {
|
|
value = callback( elems[ i ], i, arg );
|
|
|
|
if ( value != null ) {
|
|
ret.push( value );
|
|
}
|
|
}
|
|
}
|
|
|
|
// Flatten any nested arrays
|
|
return concat.apply( [], ret );
|
|
},
|
|
|
|
// A global GUID counter for objects
|
|
guid: 1,
|
|
|
|
// Bind a function to a context, optionally partially applying any
|
|
// arguments.
|
|
proxy: function( fn, context ) {
|
|
var args, proxy, tmp;
|
|
|
|
if ( typeof context === "string" ) {
|
|
tmp = fn[ context ];
|
|
context = fn;
|
|
fn = tmp;
|
|
}
|
|
|
|
// Quick check to determine if target is callable, in the spec
|
|
// this throws a TypeError, but we will just return undefined.
|
|
if ( !jQuery.isFunction( fn ) ) {
|
|
return undefined;
|
|
}
|
|
|
|
// Simulated bind
|
|
args = slice.call( arguments, 2 );
|
|
proxy = function() {
|
|
return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
|
|
};
|
|
|
|
// Set the guid of unique handler to the same of original handler, so it can be removed
|
|
proxy.guid = fn.guid = fn.guid || jQuery.guid++;
|
|
|
|
return proxy;
|
|
},
|
|
|
|
now: function() {
|
|
return +( new Date() );
|
|
},
|
|
|
|
// jQuery.support is not used in Core but other projects attach their
|
|
// properties to it so it needs to exist.
|
|
support: support
|
|
} );
|
|
|
|
// JSHint would error on this code due to the Symbol not being defined in ES5.
|
|
// Defining this global in .jshintrc would create a danger of using the global
|
|
// unguarded in another place, it seems safer to just disable JSHint for these
|
|
// three lines.
|
|
/* jshint ignore: start */
|
|
if ( typeof Symbol === "function" ) {
|
|
jQuery.fn[ Symbol.iterator ] = deletedIds[ Symbol.iterator ];
|
|
}
|
|
/* jshint ignore: end */
|
|
|
|
// Populate the class2type map
|
|
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
|
|
function( i, name ) {
|
|
class2type[ "[object " + name + "]" ] = name.toLowerCase();
|
|
} );
|
|
|
|
function isArrayLike( obj ) {
|
|
|
|
// Support: iOS 8.2 (not reproducible in simulator)
|
|
// `in` check used to prevent JIT error (gh-2145)
|
|
// hasOwn isn't used here due to false negatives
|
|
// regarding Nodelist length in IE
|
|
var length = !!obj && "length" in obj && obj.length,
|
|
type = jQuery.type( obj );
|
|
|
|
if ( type === "function" || jQuery.isWindow( obj ) ) {
|
|
return false;
|
|
}
|
|
|
|
return type === "array" || length === 0 ||
|
|
typeof length === "number" && length > 0 && ( length - 1 ) in obj;
|
|
}
|
|
var Sizzle =
|
|
/*!
|
|
* Sizzle CSS Selector Engine v2.2.1
|
|
* http://sizzlejs.com/
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license
|
|
* http://jquery.org/license
|
|
*
|
|
* Date: 2015-10-17
|
|
*/
|
|
(function( window ) {
|
|
|
|
var i,
|
|
support,
|
|
Expr,
|
|
getText,
|
|
isXML,
|
|
tokenize,
|
|
compile,
|
|
select,
|
|
outermostContext,
|
|
sortInput,
|
|
hasDuplicate,
|
|
|
|
// Local document vars
|
|
setDocument,
|
|
document,
|
|
docElem,
|
|
documentIsHTML,
|
|
rbuggyQSA,
|
|
rbuggyMatches,
|
|
matches,
|
|
contains,
|
|
|
|
// Instance-specific data
|
|
expando = "sizzle" + 1 * new Date(),
|
|
preferredDoc = window.document,
|
|
dirruns = 0,
|
|
done = 0,
|
|
classCache = createCache(),
|
|
tokenCache = createCache(),
|
|
compilerCache = createCache(),
|
|
sortOrder = function( a, b ) {
|
|
if ( a === b ) {
|
|
hasDuplicate = true;
|
|
}
|
|
return 0;
|
|
},
|
|
|
|
// General-purpose constants
|
|
MAX_NEGATIVE = 1 << 31,
|
|
|
|
// Instance methods
|
|
hasOwn = ({}).hasOwnProperty,
|
|
arr = [],
|
|
pop = arr.pop,
|
|
push_native = arr.push,
|
|
push = arr.push,
|
|
slice = arr.slice,
|
|
// Use a stripped-down indexOf as it's faster than native
|
|
// http://jsperf.com/thor-indexof-vs-for/5
|
|
indexOf = function( list, elem ) {
|
|
var i = 0,
|
|
len = list.length;
|
|
for ( ; i < len; i++ ) {
|
|
if ( list[i] === elem ) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
},
|
|
|
|
booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
|
|
|
|
// Regular expressions
|
|
|
|
// http://www.w3.org/TR/css3-selectors/#whitespace
|
|
whitespace = "[\\x20\\t\\r\\n\\f]",
|
|
|
|
// http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
|
|
identifier = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
|
|
|
|
// Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
|
|
attributes = "\\[" + whitespace + "*(" + identifier + ")(?:" + whitespace +
|
|
// Operator (capture 2)
|
|
"*([*^$|!~]?=)" + whitespace +
|
|
// "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
|
|
"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
|
|
"*\\]",
|
|
|
|
pseudos = ":(" + identifier + ")(?:\\((" +
|
|
// To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
|
|
// 1. quoted (capture 3; capture 4 or capture 5)
|
|
"('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
|
|
// 2. simple (capture 6)
|
|
"((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
|
|
// 3. anything else (capture 2)
|
|
".*" +
|
|
")\\)|)",
|
|
|
|
// Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
|
|
rwhitespace = new RegExp( whitespace + "+", "g" ),
|
|
rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
|
|
|
|
rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
|
|
rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
|
|
|
|
rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
|
|
|
|
rpseudo = new RegExp( pseudos ),
|
|
ridentifier = new RegExp( "^" + identifier + "$" ),
|
|
|
|
matchExpr = {
|
|
"ID": new RegExp( "^#(" + identifier + ")" ),
|
|
"CLASS": new RegExp( "^\\.(" + identifier + ")" ),
|
|
"TAG": new RegExp( "^(" + identifier + "|[*])" ),
|
|
"ATTR": new RegExp( "^" + attributes ),
|
|
"PSEUDO": new RegExp( "^" + pseudos ),
|
|
"CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
|
|
"*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
|
|
"*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
|
|
"bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
|
|
// For use in libraries implementing .is()
|
|
// We use this for POS matching in `select`
|
|
"needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
|
|
whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
|
|
},
|
|
|
|
rinputs = /^(?:input|select|textarea|button)$/i,
|
|
rheader = /^h\d$/i,
|
|
|
|
rnative = /^[^{]+\{\s*\[native \w/,
|
|
|
|
// Easily-parseable/retrievable ID or TAG or CLASS selectors
|
|
rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
|
|
|
|
rsibling = /[+~]/,
|
|
rescape = /'|\\/g,
|
|
|
|
// CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
|
|
runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
|
|
funescape = function( _, escaped, escapedWhitespace ) {
|
|
var high = "0x" + escaped - 0x10000;
|
|
// NaN means non-codepoint
|
|
// Support: Firefox<24
|
|
// Workaround erroneous numeric interpretation of +"0x"
|
|
return high !== high || escapedWhitespace ?
|
|
escaped :
|
|
high < 0 ?
|
|
// BMP codepoint
|
|
String.fromCharCode( high + 0x10000 ) :
|
|
// Supplemental Plane codepoint (surrogate pair)
|
|
String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
|
|
},
|
|
|
|
// Used for iframes
|
|
// See setDocument()
|
|
// Removing the function wrapper causes a "Permission Denied"
|
|
// error in IE
|
|
unloadHandler = function() {
|
|
setDocument();
|
|
};
|
|
|
|
// Optimize for push.apply( _, NodeList )
|
|
try {
|
|
push.apply(
|
|
(arr = slice.call( preferredDoc.childNodes )),
|
|
preferredDoc.childNodes
|
|
);
|
|
// Support: Android<4.0
|
|
// Detect silently failing push.apply
|
|
arr[ preferredDoc.childNodes.length ].nodeType;
|
|
} catch ( e ) {
|
|
push = { apply: arr.length ?
|
|
|
|
// Leverage slice if possible
|
|
function( target, els ) {
|
|
push_native.apply( target, slice.call(els) );
|
|
} :
|
|
|
|
// Support: IE<9
|
|
// Otherwise append directly
|
|
function( target, els ) {
|
|
var j = target.length,
|
|
i = 0;
|
|
// Can't trust NodeList.length
|
|
while ( (target[j++] = els[i++]) ) {}
|
|
target.length = j - 1;
|
|
}
|
|
};
|
|
}
|
|
|
|
function Sizzle( selector, context, results, seed ) {
|
|
var m, i, elem, nid, nidselect, match, groups, newSelector,
|
|
newContext = context && context.ownerDocument,
|
|
|
|
// nodeType defaults to 9, since context defaults to document
|
|
nodeType = context ? context.nodeType : 9;
|
|
|
|
results = results || [];
|
|
|
|
// Return early from calls with invalid selector or context
|
|
if ( typeof selector !== "string" || !selector ||
|
|
nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
|
|
|
|
return results;
|
|
}
|
|
|
|
// Try to shortcut find operations (as opposed to filters) in HTML documents
|
|
if ( !seed ) {
|
|
|
|
if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
|
|
setDocument( context );
|
|
}
|
|
context = context || document;
|
|
|
|
if ( documentIsHTML ) {
|
|
|
|
// If the selector is sufficiently simple, try using a "get*By*" DOM method
|
|
// (excepting DocumentFragment context, where the methods don't exist)
|
|
if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
|
|
|
|
// ID selector
|
|
if ( (m = match[1]) ) {
|
|
|
|
// Document context
|
|
if ( nodeType === 9 ) {
|
|
if ( (elem = context.getElementById( m )) ) {
|
|
|
|
// Support: IE, Opera, Webkit
|
|
// TODO: identify versions
|
|
// getElementById can match elements by name instead of ID
|
|
if ( elem.id === m ) {
|
|
results.push( elem );
|
|
return results;
|
|
}
|
|
} else {
|
|
return results;
|
|
}
|
|
|
|
// Element context
|
|
} else {
|
|
|
|
// Support: IE, Opera, Webkit
|
|
// TODO: identify versions
|
|
// getElementById can match elements by name instead of ID
|
|
if ( newContext && (elem = newContext.getElementById( m )) &&
|
|
contains( context, elem ) &&
|
|
elem.id === m ) {
|
|
|
|
results.push( elem );
|
|
return results;
|
|
}
|
|
}
|
|
|
|
// Type selector
|
|
} else if ( match[2] ) {
|
|
push.apply( results, context.getElementsByTagName( selector ) );
|
|
return results;
|
|
|
|
// Class selector
|
|
} else if ( (m = match[3]) && support.getElementsByClassName &&
|
|
context.getElementsByClassName ) {
|
|
|
|
push.apply( results, context.getElementsByClassName( m ) );
|
|
return results;
|
|
}
|
|
}
|
|
|
|
// Take advantage of querySelectorAll
|
|
if ( support.qsa &&
|
|
!compilerCache[ selector + " " ] &&
|
|
(!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
|
|
|
|
if ( nodeType !== 1 ) {
|
|
newContext = context;
|
|
newSelector = selector;
|
|
|
|
// qSA looks outside Element context, which is not what we want
|
|
// Thanks to Andrew Dupont for this workaround technique
|
|
// Support: IE <=8
|
|
// Exclude object elements
|
|
} else if ( context.nodeName.toLowerCase() !== "object" ) {
|
|
|
|
// Capture the context ID, setting it first if necessary
|
|
if ( (nid = context.getAttribute( "id" )) ) {
|
|
nid = nid.replace( rescape, "\\$&" );
|
|
} else {
|
|
context.setAttribute( "id", (nid = expando) );
|
|
}
|
|
|
|
// Prefix every selector in the list
|
|
groups = tokenize( selector );
|
|
i = groups.length;
|
|
nidselect = ridentifier.test( nid ) ? "#" + nid : "[id='" + nid + "']";
|
|
while ( i-- ) {
|
|
groups[i] = nidselect + " " + toSelector( groups[i] );
|
|
}
|
|
newSelector = groups.join( "," );
|
|
|
|
// Expand context for sibling selectors
|
|
newContext = rsibling.test( selector ) && testContext( context.parentNode ) ||
|
|
context;
|
|
}
|
|
|
|
if ( newSelector ) {
|
|
try {
|
|
push.apply( results,
|
|
newContext.querySelectorAll( newSelector )
|
|
);
|
|
return results;
|
|
} catch ( qsaError ) {
|
|
} finally {
|
|
if ( nid === expando ) {
|
|
context.removeAttribute( "id" );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// All others
|
|
return select( selector.replace( rtrim, "$1" ), context, results, seed );
|
|
}
|
|
|
|
/**
|
|
* Create key-value caches of limited size
|
|
* @returns {function(string, object)} Returns the Object data after storing it on itself with
|
|
* property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
|
|
* deleting the oldest entry
|
|
*/
|
|
function createCache() {
|
|
var keys = [];
|
|
|
|
function cache( key, value ) {
|
|
// Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
|
|
if ( keys.push( key + " " ) > Expr.cacheLength ) {
|
|
// Only keep the most recent entries
|
|
delete cache[ keys.shift() ];
|
|
}
|
|
return (cache[ key + " " ] = value);
|
|
}
|
|
return cache;
|
|
}
|
|
|
|
/**
|
|
* Mark a function for special use by Sizzle
|
|
* @param {Function} fn The function to mark
|
|
*/
|
|
function markFunction( fn ) {
|
|
fn[ expando ] = true;
|
|
return fn;
|
|
}
|
|
|
|
/**
|
|
* Support testing using an element
|
|
* @param {Function} fn Passed the created div and expects a boolean result
|
|
*/
|
|
function assert( fn ) {
|
|
var div = document.createElement("div");
|
|
|
|
try {
|
|
return !!fn( div );
|
|
} catch (e) {
|
|
return false;
|
|
} finally {
|
|
// Remove from its parent by default
|
|
if ( div.parentNode ) {
|
|
div.parentNode.removeChild( div );
|
|
}
|
|
// release memory in IE
|
|
div = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Adds the same handler for all of the specified attrs
|
|
* @param {String} attrs Pipe-separated list of attributes
|
|
* @param {Function} handler The method that will be applied
|
|
*/
|
|
function addHandle( attrs, handler ) {
|
|
var arr = attrs.split("|"),
|
|
i = arr.length;
|
|
|
|
while ( i-- ) {
|
|
Expr.attrHandle[ arr[i] ] = handler;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Checks document order of two siblings
|
|
* @param {Element} a
|
|
* @param {Element} b
|
|
* @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
|
|
*/
|
|
function siblingCheck( a, b ) {
|
|
var cur = b && a,
|
|
diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
|
|
( ~b.sourceIndex || MAX_NEGATIVE ) -
|
|
( ~a.sourceIndex || MAX_NEGATIVE );
|
|
|
|
// Use IE sourceIndex if available on both nodes
|
|
if ( diff ) {
|
|
return diff;
|
|
}
|
|
|
|
// Check if b follows a
|
|
if ( cur ) {
|
|
while ( (cur = cur.nextSibling) ) {
|
|
if ( cur === b ) {
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return a ? 1 : -1;
|
|
}
|
|
|
|
/**
|
|
* Returns a function to use in pseudos for input types
|
|
* @param {String} type
|
|
*/
|
|
function createInputPseudo( type ) {
|
|
return function( elem ) {
|
|
var name = elem.nodeName.toLowerCase();
|
|
return name === "input" && elem.type === type;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Returns a function to use in pseudos for buttons
|
|
* @param {String} type
|
|
*/
|
|
function createButtonPseudo( type ) {
|
|
return function( elem ) {
|
|
var name = elem.nodeName.toLowerCase();
|
|
return (name === "input" || name === "button") && elem.type === type;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Returns a function to use in pseudos for positionals
|
|
* @param {Function} fn
|
|
*/
|
|
function createPositionalPseudo( fn ) {
|
|
return markFunction(function( argument ) {
|
|
argument = +argument;
|
|
return markFunction(function( seed, matches ) {
|
|
var j,
|
|
matchIndexes = fn( [], seed.length, argument ),
|
|
i = matchIndexes.length;
|
|
|
|
// Match elements found at the specified indexes
|
|
while ( i-- ) {
|
|
if ( seed[ (j = matchIndexes[i]) ] ) {
|
|
seed[j] = !(matches[j] = seed[j]);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Checks a node for validity as a Sizzle context
|
|
* @param {Element|Object=} context
|
|
* @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
|
|
*/
|
|
function testContext( context ) {
|
|
return context && typeof context.getElementsByTagName !== "undefined" && context;
|
|
}
|
|
|
|
// Expose support vars for convenience
|
|
support = Sizzle.support = {};
|
|
|
|
/**
|
|
* Detects XML nodes
|
|
* @param {Element|Object} elem An element or a document
|
|
* @returns {Boolean} True iff elem is a non-HTML XML node
|
|
*/
|
|
isXML = Sizzle.isXML = function( elem ) {
|
|
// documentElement is verified for cases where it doesn't yet exist
|
|
// (such as loading iframes in IE - #4833)
|
|
var documentElement = elem && (elem.ownerDocument || elem).documentElement;
|
|
return documentElement ? documentElement.nodeName !== "HTML" : false;
|
|
};
|
|
|
|
/**
|
|
* Sets document-related variables once based on the current document
|
|
* @param {Element|Object} [doc] An element or document object to use to set the document
|
|
* @returns {Object} Returns the current document
|
|
*/
|
|
setDocument = Sizzle.setDocument = function( node ) {
|
|
var hasCompare, parent,
|
|
doc = node ? node.ownerDocument || node : preferredDoc;
|
|
|
|
// Return early if doc is invalid or already selected
|
|
if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
|
|
return document;
|
|
}
|
|
|
|
// Update global variables
|
|
document = doc;
|
|
docElem = document.documentElement;
|
|
documentIsHTML = !isXML( document );
|
|
|
|
// Support: IE 9-11, Edge
|
|
// Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936)
|
|
if ( (parent = document.defaultView) && parent.top !== parent ) {
|
|
// Support: IE 11
|
|
if ( parent.addEventListener ) {
|
|
parent.addEventListener( "unload", unloadHandler, false );
|
|
|
|
// Support: IE 9 - 10 only
|
|
} else if ( parent.attachEvent ) {
|
|
parent.attachEvent( "onunload", unloadHandler );
|
|
}
|
|
}
|
|
|
|
/* Attributes
|
|
---------------------------------------------------------------------- */
|
|
|
|
// Support: IE<8
|
|
// Verify that getAttribute really returns attributes and not properties
|
|
// (excepting IE8 booleans)
|
|
support.attributes = assert(function( div ) {
|
|
div.className = "i";
|
|
return !div.getAttribute("className");
|
|
});
|
|
|
|
/* getElement(s)By*
|
|
---------------------------------------------------------------------- */
|
|
|
|
// Check if getElementsByTagName("*") returns only elements
|
|
support.getElementsByTagName = assert(function( div ) {
|
|
div.appendChild( document.createComment("") );
|
|
return !div.getElementsByTagName("*").length;
|
|
});
|
|
|
|
// Support: IE<9
|
|
support.getElementsByClassName = rnative.test( document.getElementsByClassName );
|
|
|
|
// Support: IE<10
|
|
// Check if getElementById returns elements by name
|
|
// The broken getElementById methods don't pick up programatically-set names,
|
|
// so use a roundabout getElementsByName test
|
|
support.getById = assert(function( div ) {
|
|
docElem.appendChild( div ).id = expando;
|
|
return !document.getElementsByName || !document.getElementsByName( expando ).length;
|
|
});
|
|
|
|
// ID find and filter
|
|
if ( support.getById ) {
|
|
Expr.find["ID"] = function( id, context ) {
|
|
if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
|
|
var m = context.getElementById( id );
|
|
return m ? [ m ] : [];
|
|
}
|
|
};
|
|
Expr.filter["ID"] = function( id ) {
|
|
var attrId = id.replace( runescape, funescape );
|
|
return function( elem ) {
|
|
return elem.getAttribute("id") === attrId;
|
|
};
|
|
};
|
|
} else {
|
|
// Support: IE6/7
|
|
// getElementById is not reliable as a find shortcut
|
|
delete Expr.find["ID"];
|
|
|
|
Expr.filter["ID"] = function( id ) {
|
|
var attrId = id.replace( runescape, funescape );
|
|
return function( elem ) {
|
|
var node = typeof elem.getAttributeNode !== "undefined" &&
|
|
elem.getAttributeNode("id");
|
|
return node && node.value === attrId;
|
|
};
|
|
};
|
|
}
|
|
|
|
// Tag
|
|
Expr.find["TAG"] = support.getElementsByTagName ?
|
|
function( tag, context ) {
|
|
if ( typeof context.getElementsByTagName !== "undefined" ) {
|
|
return context.getElementsByTagName( tag );
|
|
|
|
// DocumentFragment nodes don't have gEBTN
|
|
} else if ( support.qsa ) {
|
|
return context.querySelectorAll( tag );
|
|
}
|
|
} :
|
|
|
|
function( tag, context ) {
|
|
var elem,
|
|
tmp = [],
|
|
i = 0,
|
|
// By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
|
|
results = context.getElementsByTagName( tag );
|
|
|
|
// Filter out possible comments
|
|
if ( tag === "*" ) {
|
|
while ( (elem = results[i++]) ) {
|
|
if ( elem.nodeType === 1 ) {
|
|
tmp.push( elem );
|
|
}
|
|
}
|
|
|
|
return tmp;
|
|
}
|
|
return results;
|
|
};
|
|
|
|
// Class
|
|
Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
|
|
if ( typeof context.getElementsByClassName !== "undefined" && documentIsHTML ) {
|
|
return context.getElementsByClassName( className );
|
|
}
|
|
};
|
|
|
|
/* QSA/matchesSelector
|
|
---------------------------------------------------------------------- */
|
|
|
|
// QSA and matchesSelector support
|
|
|
|
// matchesSelector(:active) reports false when true (IE9/Opera 11.5)
|
|
rbuggyMatches = [];
|
|
|
|
// qSa(:focus) reports false when true (Chrome 21)
|
|
// We allow this because of a bug in IE8/9 that throws an error
|
|
// whenever `document.activeElement` is accessed on an iframe
|
|
// So, we allow :focus to pass through QSA all the time to avoid the IE error
|
|
// See http://bugs.jquery.com/ticket/13378
|
|
rbuggyQSA = [];
|
|
|
|
if ( (support.qsa = rnative.test( document.querySelectorAll )) ) {
|
|
// Build QSA regex
|
|
// Regex strategy adopted from Diego Perini
|
|
assert(function( div ) {
|
|
// Select is set to empty string on purpose
|
|
// This is to test IE's treatment of not explicitly
|
|
// setting a boolean content attribute,
|
|
// since its presence should be enough
|
|
// http://bugs.jquery.com/ticket/12359
|
|
docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
|
|
"<select id='" + expando + "-\r\\' msallowcapture=''>" +
|
|
"<option selected=''></option></select>";
|
|
|
|
// Support: IE8, Opera 11-12.16
|
|
// Nothing should be selected when empty strings follow ^= or $= or *=
|
|
// The test attribute must be unknown in Opera but "safe" for WinRT
|
|
// http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
|
|
if ( div.querySelectorAll("[msallowcapture^='']").length ) {
|
|
rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
|
|
}
|
|
|
|
// Support: IE8
|
|
// Boolean attributes and "value" are not treated correctly
|
|
if ( !div.querySelectorAll("[selected]").length ) {
|
|
rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
|
|
}
|
|
|
|
// Support: Chrome<29, Android<4.4, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.8+
|
|
if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
|
|
rbuggyQSA.push("~=");
|
|
}
|
|
|
|
// Webkit/Opera - :checked should return selected option elements
|
|
// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
|
|
// IE8 throws error here and will not see later tests
|
|
if ( !div.querySelectorAll(":checked").length ) {
|
|
rbuggyQSA.push(":checked");
|
|
}
|
|
|
|
// Support: Safari 8+, iOS 8+
|
|
// https://bugs.webkit.org/show_bug.cgi?id=136851
|
|
// In-page `selector#id sibing-combinator selector` fails
|
|
if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
|
|
rbuggyQSA.push(".#.+[+~]");
|
|
}
|
|
});
|
|
|
|
assert(function( div ) {
|
|
// Support: Windows 8 Native Apps
|
|
// The type and name attributes are restricted during .innerHTML assignment
|
|
var input = document.createElement("input");
|
|
input.setAttribute( "type", "hidden" );
|
|
div.appendChild( input ).setAttribute( "name", "D" );
|
|
|
|
// Support: IE8
|
|
// Enforce case-sensitivity of name attribute
|
|
if ( div.querySelectorAll("[name=d]").length ) {
|
|
rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
|
|
}
|
|
|
|
// FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
|
|
// IE8 throws error here and will not see later tests
|
|
if ( !div.querySelectorAll(":enabled").length ) {
|
|
rbuggyQSA.push( ":enabled", ":disabled" );
|
|
}
|
|
|
|
// Opera 10-11 does not throw on post-comma invalid pseudos
|
|
div.querySelectorAll("*,:x");
|
|
rbuggyQSA.push(",.*:");
|
|
});
|
|
}
|
|
|
|
if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
|
|
docElem.webkitMatchesSelector ||
|
|
docElem.mozMatchesSelector ||
|
|
docElem.oMatchesSelector ||
|
|
docElem.msMatchesSelector) )) ) {
|
|
|
|
assert(function( div ) {
|
|
// Check to see if it's possible to do matchesSelector
|
|
// on a disconnected node (IE 9)
|
|
support.disconnectedMatch = matches.call( div, "div" );
|
|
|
|
// This should fail with an exception
|
|
// Gecko does not error, returns false instead
|
|
matches.call( div, "[s!='']:x" );
|
|
rbuggyMatches.push( "!=", pseudos );
|
|
});
|
|
}
|
|
|
|
rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
|
|
rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
|
|
|
|
/* Contains
|
|
---------------------------------------------------------------------- */
|
|
hasCompare = rnative.test( docElem.compareDocumentPosition );
|
|
|
|
// Element contains another
|
|
// Purposefully self-exclusive
|
|
// As in, an element does not contain itself
|
|
contains = hasCompare || rnative.test( docElem.contains ) ?
|
|
function( a, b ) {
|
|
var adown = a.nodeType === 9 ? a.documentElement : a,
|
|
bup = b && b.parentNode;
|
|
return a === bup || !!( bup && bup.nodeType === 1 && (
|
|
adown.contains ?
|
|
adown.contains( bup ) :
|
|
a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
|
|
));
|
|
} :
|
|
function( a, b ) {
|
|
if ( b ) {
|
|
while ( (b = b.parentNode) ) {
|
|
if ( b === a ) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
/* Sorting
|
|
---------------------------------------------------------------------- */
|
|
|
|
// Document order sorting
|
|
sortOrder = hasCompare ?
|
|
function( a, b ) {
|
|
|
|
// Flag for duplicate removal
|
|
if ( a === b ) {
|
|
hasDuplicate = true;
|
|
return 0;
|
|
}
|
|
|
|
// Sort on method existence if only one input has compareDocumentPosition
|
|
var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
|
|
if ( compare ) {
|
|
return compare;
|
|
}
|
|
|
|
// Calculate position if both inputs belong to the same document
|
|
compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
|
|
a.compareDocumentPosition( b ) :
|
|
|
|
// Otherwise we know they are disconnected
|
|
1;
|
|
|
|
// Disconnected nodes
|
|
if ( compare & 1 ||
|
|
(!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
|
|
|
|
// Choose the first element that is related to our preferred document
|
|
if ( a === document || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
|
|
return -1;
|
|
}
|
|
if ( b === document || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
|
|
return 1;
|
|
}
|
|
|
|
// Maintain original order
|
|
return sortInput ?
|
|
( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
|
|
0;
|
|
}
|
|
|
|
return compare & 4 ? -1 : 1;
|
|
} :
|
|
function( a, b ) {
|
|
// Exit early if the nodes are identical
|
|
if ( a === b ) {
|
|
hasDuplicate = true;
|
|
return 0;
|
|
}
|
|
|
|
var cur,
|
|
i = 0,
|
|
aup = a.parentNode,
|
|
bup = b.parentNode,
|
|
ap = [ a ],
|
|
bp = [ b ];
|
|
|
|
// Parentless nodes are either documents or disconnected
|
|
if ( !aup || !bup ) {
|
|
return a === document ? -1 :
|
|
b === document ? 1 :
|
|
aup ? -1 :
|
|
bup ? 1 :
|
|
sortInput ?
|
|
( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
|
|
0;
|
|
|
|
// If the nodes are siblings, we can do a quick check
|
|
} else if ( aup === bup ) {
|
|
return siblingCheck( a, b );
|
|
}
|
|
|
|
// Otherwise we need full lists of their ancestors for comparison
|
|
cur = a;
|
|
while ( (cur = cur.parentNode) ) {
|
|
ap.unshift( cur );
|
|
}
|
|
cur = b;
|
|
while ( (cur = cur.parentNode) ) {
|
|
bp.unshift( cur );
|
|
}
|
|
|
|
// Walk down the tree looking for a discrepancy
|
|
while ( ap[i] === bp[i] ) {
|
|
i++;
|
|
}
|
|
|
|
return i ?
|
|
// Do a sibling check if the nodes have a common ancestor
|
|
siblingCheck( ap[i], bp[i] ) :
|
|
|
|
// Otherwise nodes in our document sort first
|
|
ap[i] === preferredDoc ? -1 :
|
|
bp[i] === preferredDoc ? 1 :
|
|
0;
|
|
};
|
|
|
|
return document;
|
|
};
|
|
|
|
Sizzle.matches = function( expr, elements ) {
|
|
return Sizzle( expr, null, null, elements );
|
|
};
|
|
|
|
Sizzle.matchesSelector = function( elem, expr ) {
|
|
// Set document vars if needed
|
|
if ( ( elem.ownerDocument || elem ) !== document ) {
|
|
setDocument( elem );
|
|
}
|
|
|
|
// Make sure that attribute selectors are quoted
|
|
expr = expr.replace( rattributeQuotes, "='$1']" );
|
|
|
|
if ( support.matchesSelector && documentIsHTML &&
|
|
!compilerCache[ expr + " " ] &&
|
|
( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
|
|
( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
|
|
|
|
try {
|
|
var ret = matches.call( elem, expr );
|
|
|
|
// IE 9's matchesSelector returns false on disconnected nodes
|
|
if ( ret || support.disconnectedMatch ||
|
|
// As well, disconnected nodes are said to be in a document
|
|
// fragment in IE 9
|
|
elem.document && elem.document.nodeType !== 11 ) {
|
|
return ret;
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
|
|
return Sizzle( expr, document, null, [ elem ] ).length > 0;
|
|
};
|
|
|
|
Sizzle.contains = function( context, elem ) {
|
|
// Set document vars if needed
|
|
if ( ( context.ownerDocument || context ) !== document ) {
|
|
setDocument( context );
|
|
}
|
|
return contains( context, elem );
|
|
};
|
|
|
|
Sizzle.attr = function( elem, name ) {
|
|
// Set document vars if needed
|
|
if ( ( elem.ownerDocument || elem ) !== document ) {
|
|
setDocument( elem );
|
|
}
|
|
|
|
var fn = Expr.attrHandle[ name.toLowerCase() ],
|
|
// Don't get fooled by Object.prototype properties (jQuery #13807)
|
|
val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
|
|
fn( elem, name, !documentIsHTML ) :
|
|
undefined;
|
|
|
|
return val !== undefined ?
|
|
val :
|
|
support.attributes || !documentIsHTML ?
|
|
elem.getAttribute( name ) :
|
|
(val = elem.getAttributeNode(name)) && val.specified ?
|
|
val.value :
|
|
null;
|
|
};
|
|
|
|
Sizzle.error = function( msg ) {
|
|
throw new Error( "Syntax error, unrecognized expression: " + msg );
|
|
};
|
|
|
|
/**
|
|
* Document sorting and removing duplicates
|
|
* @param {ArrayLike} results
|
|
*/
|
|
Sizzle.uniqueSort = function( results ) {
|
|
var elem,
|
|
duplicates = [],
|
|
j = 0,
|
|
i = 0;
|
|
|
|
// Unless we *know* we can detect duplicates, assume their presence
|
|
hasDuplicate = !support.detectDuplicates;
|
|
sortInput = !support.sortStable && results.slice( 0 );
|
|
results.sort( sortOrder );
|
|
|
|
if ( hasDuplicate ) {
|
|
while ( (elem = results[i++]) ) {
|
|
if ( elem === results[ i ] ) {
|
|
j = duplicates.push( i );
|
|
}
|
|
}
|
|
while ( j-- ) {
|
|
results.splice( duplicates[ j ], 1 );
|
|
}
|
|
}
|
|
|
|
// Clear input after sorting to release objects
|
|
// See https://github.com/jquery/sizzle/pull/225
|
|
sortInput = null;
|
|
|
|
return results;
|
|
};
|
|
|
|
/**
|
|
* Utility function for retrieving the text value of an array of DOM nodes
|
|
* @param {Array|Element} elem
|
|
*/
|
|
getText = Sizzle.getText = function( elem ) {
|
|
var node,
|
|
ret = "",
|
|
i = 0,
|
|
nodeType = elem.nodeType;
|
|
|
|
if ( !nodeType ) {
|
|
// If no nodeType, this is expected to be an array
|
|
while ( (node = elem[i++]) ) {
|
|
// Do not traverse comment nodes
|
|
ret += getText( node );
|
|
}
|
|
} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
|
|
// Use textContent for elements
|
|
// innerText usage removed for consistency of new lines (jQuery #11153)
|
|
if ( typeof elem.textContent === "string" ) {
|
|
return elem.textContent;
|
|
} else {
|
|
// Traverse its children
|
|
for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
|
|
ret += getText( elem );
|
|
}
|
|
}
|
|
} else if ( nodeType === 3 || nodeType === 4 ) {
|
|
return elem.nodeValue;
|
|
}
|
|
// Do not include comment or processing instruction nodes
|
|
|
|
return ret;
|
|
};
|
|
|
|
Expr = Sizzle.selectors = {
|
|
|
|
// Can be adjusted by the user
|
|
cacheLength: 50,
|
|
|
|
createPseudo: markFunction,
|
|
|
|
match: matchExpr,
|
|
|
|
attrHandle: {},
|
|
|
|
find: {},
|
|
|
|
relative: {
|
|
">": { dir: "parentNode", first: true },
|
|
" ": { dir: "parentNode" },
|
|
"+": { dir: "previousSibling", first: true },
|
|
"~": { dir: "previousSibling" }
|
|
},
|
|
|
|
preFilter: {
|
|
"ATTR": function( match ) {
|
|
match[1] = match[1].replace( runescape, funescape );
|
|
|
|
// Move the given value to match[3] whether quoted or unquoted
|
|
match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
|
|
|
|
if ( match[2] === "~=" ) {
|
|
match[3] = " " + match[3] + " ";
|
|
}
|
|
|
|
return match.slice( 0, 4 );
|
|
},
|
|
|
|
"CHILD": function( match ) {
|
|
/* matches from matchExpr["CHILD"]
|
|
1 type (only|nth|...)
|
|
2 what (child|of-type)
|
|
3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
|
|
4 xn-component of xn+y argument ([+-]?\d*n|)
|
|
5 sign of xn-component
|
|
6 x of xn-component
|
|
7 sign of y-component
|
|
8 y of y-component
|
|
*/
|
|
match[1] = match[1].toLowerCase();
|
|
|
|
if ( match[1].slice( 0, 3 ) === "nth" ) {
|
|
// nth-* requires argument
|
|
if ( !match[3] ) {
|
|
Sizzle.error( match[0] );
|
|
}
|
|
|
|
// numeric x and y parameters for Expr.filter.CHILD
|
|
// remember that false/true cast respectively to 0/1
|
|
match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
|
|
match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
|
|
|
|
// other types prohibit arguments
|
|
} else if ( match[3] ) {
|
|
Sizzle.error( match[0] );
|
|
}
|
|
|
|
return match;
|
|
},
|
|
|
|
"PSEUDO": function( match ) {
|
|
var excess,
|
|
unquoted = !match[6] && match[2];
|
|
|
|
if ( matchExpr["CHILD"].test( match[0] ) ) {
|
|
return null;
|
|
}
|
|
|
|
// Accept quoted arguments as-is
|
|
if ( match[3] ) {
|
|
match[2] = match[4] || match[5] || "";
|
|
|
|
// Strip excess characters from unquoted arguments
|
|
} else if ( unquoted && rpseudo.test( unquoted ) &&
|
|
// Get excess from tokenize (recursively)
|
|
(excess = tokenize( unquoted, true )) &&
|
|
// advance to the next closing parenthesis
|
|
(excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
|
|
|
|
// excess is a negative index
|
|
match[0] = match[0].slice( 0, excess );
|
|
match[2] = unquoted.slice( 0, excess );
|
|
}
|
|
|
|
// Return only captures needed by the pseudo filter method (type and argument)
|
|
return match.slice( 0, 3 );
|
|
}
|
|
},
|
|
|
|
filter: {
|
|
|
|
"TAG": function( nodeNameSelector ) {
|
|
var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
|
|
return nodeNameSelector === "*" ?
|
|
function() { return true; } :
|
|
function( elem ) {
|
|
return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
|
|
};
|
|
},
|
|
|
|
"CLASS": function( className ) {
|
|
var pattern = classCache[ className + " " ];
|
|
|
|
return pattern ||
|
|
(pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
|
|
classCache( className, function( elem ) {
|
|
return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
|
|
});
|
|
},
|
|
|
|
"ATTR": function( name, operator, check ) {
|
|
return function( elem ) {
|
|
var result = Sizzle.attr( elem, name );
|
|
|
|
if ( result == null ) {
|
|
return operator === "!=";
|
|
}
|
|
if ( !operator ) {
|
|
return true;
|
|
}
|
|
|
|
result += "";
|
|
|
|
return operator === "=" ? result === check :
|
|
operator === "!=" ? result !== check :
|
|
operator === "^=" ? check && result.indexOf( check ) === 0 :
|
|
operator === "*=" ? check && result.indexOf( check ) > -1 :
|
|
operator === "$=" ? check && result.slice( -check.length ) === check :
|
|
operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
|
|
operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
|
|
false;
|
|
};
|
|
},
|
|
|
|
"CHILD": function( type, what, argument, first, last ) {
|
|
var simple = type.slice( 0, 3 ) !== "nth",
|
|
forward = type.slice( -4 ) !== "last",
|
|
ofType = what === "of-type";
|
|
|
|
return first === 1 && last === 0 ?
|
|
|
|
// Shortcut for :nth-*(n)
|
|
function( elem ) {
|
|
return !!elem.parentNode;
|
|
} :
|
|
|
|
function( elem, context, xml ) {
|
|
var cache, uniqueCache, outerCache, node, nodeIndex, start,
|
|
dir = simple !== forward ? "nextSibling" : "previousSibling",
|
|
parent = elem.parentNode,
|
|
name = ofType && elem.nodeName.toLowerCase(),
|
|
useCache = !xml && !ofType,
|
|
diff = false;
|
|
|
|
if ( parent ) {
|
|
|
|
// :(first|last|only)-(child|of-type)
|
|
if ( simple ) {
|
|
while ( dir ) {
|
|
node = elem;
|
|
while ( (node = node[ dir ]) ) {
|
|
if ( ofType ?
|
|
node.nodeName.toLowerCase() === name :
|
|
node.nodeType === 1 ) {
|
|
|
|
return false;
|
|
}
|
|
}
|
|
// Reverse direction for :only-* (if we haven't yet done so)
|
|
start = dir = type === "only" && !start && "nextSibling";
|
|
}
|
|
return true;
|
|
}
|
|
|
|
start = [ forward ? parent.firstChild : parent.lastChild ];
|
|
|
|
// non-xml :nth-child(...) stores cache data on `parent`
|
|
if ( forward && useCache ) {
|
|
|
|
// Seek `elem` from a previously-cached index
|
|
|
|
// ...in a gzip-friendly way
|
|
node = parent;
|
|
outerCache = node[ expando ] || (node[ expando ] = {});
|
|
|
|
// Support: IE <9 only
|
|
// Defend against cloned attroperties (jQuery gh-1709)
|
|
uniqueCache = outerCache[ node.uniqueID ] ||
|
|
(outerCache[ node.uniqueID ] = {});
|
|
|
|
cache = uniqueCache[ type ] || [];
|
|
nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
|
|
diff = nodeIndex && cache[ 2 ];
|
|
node = nodeIndex && parent.childNodes[ nodeIndex ];
|
|
|
|
while ( (node = ++nodeIndex && node && node[ dir ] ||
|
|
|
|
// Fallback to seeking `elem` from the start
|
|
(diff = nodeIndex = 0) || start.pop()) ) {
|
|
|
|
// When found, cache indexes on `parent` and break
|
|
if ( node.nodeType === 1 && ++diff && node === elem ) {
|
|
uniqueCache[ type ] = [ dirruns, nodeIndex, diff ];
|
|
break;
|
|
}
|
|
}
|
|
|
|
} else {
|
|
// Use previously-cached element index if available
|
|
if ( useCache ) {
|
|
// ...in a gzip-friendly way
|
|
node = elem;
|
|
outerCache = node[ expando ] || (node[ expando ] = {});
|
|
|
|
// Support: IE <9 only
|
|
// Defend against cloned attroperties (jQuery gh-1709)
|
|
uniqueCache = outerCache[ node.uniqueID ] ||
|
|
(outerCache[ node.uniqueID ] = {});
|
|
|
|
cache = uniqueCache[ type ] || [];
|
|
nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
|
|
diff = nodeIndex;
|
|
}
|
|
|
|
// xml :nth-child(...)
|
|
// or :nth-last-child(...) or :nth(-last)?-of-type(...)
|
|
if ( diff === false ) {
|
|
// Use the same loop as above to seek `elem` from the start
|
|
while ( (node = ++nodeIndex && node && node[ dir ] ||
|
|
(diff = nodeIndex = 0) || start.pop()) ) {
|
|
|
|
if ( ( ofType ?
|
|
node.nodeName.toLowerCase() === name :
|
|
node.nodeType === 1 ) &&
|
|
++diff ) {
|
|
|
|
// Cache the index of each encountered element
|
|
if ( useCache ) {
|
|
outerCache = node[ expando ] || (node[ expando ] = {});
|
|
|
|
// Support: IE <9 only
|
|
// Defend against cloned attroperties (jQuery gh-1709)
|
|
uniqueCache = outerCache[ node.uniqueID ] ||
|
|
(outerCache[ node.uniqueID ] = {});
|
|
|
|
uniqueCache[ type ] = [ dirruns, diff ];
|
|
}
|
|
|
|
if ( node === elem ) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Incorporate the offset, then check against cycle size
|
|
diff -= last;
|
|
return diff === first || ( diff % first === 0 && diff / first >= 0 );
|
|
}
|
|
};
|
|
},
|
|
|
|
"PSEUDO": function( pseudo, argument ) {
|
|
// pseudo-class names are case-insensitive
|
|
// http://www.w3.org/TR/selectors/#pseudo-classes
|
|
// Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
|
|
// Remember that setFilters inherits from pseudos
|
|
var args,
|
|
fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
|
|
Sizzle.error( "unsupported pseudo: " + pseudo );
|
|
|
|
// The user may use createPseudo to indicate that
|
|
// arguments are needed to create the filter function
|
|
// just as Sizzle does
|
|
if ( fn[ expando ] ) {
|
|
return fn( argument );
|
|
}
|
|
|
|
// But maintain support for old signatures
|
|
if ( fn.length > 1 ) {
|
|
args = [ pseudo, pseudo, "", argument ];
|
|
return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
|
|
markFunction(function( seed, matches ) {
|
|
var idx,
|
|
matched = fn( seed, argument ),
|
|
i = matched.length;
|
|
while ( i-- ) {
|
|
idx = indexOf( seed, matched[i] );
|
|
seed[ idx ] = !( matches[ idx ] = matched[i] );
|
|
}
|
|
}) :
|
|
function( elem ) {
|
|
return fn( elem, 0, args );
|
|
};
|
|
}
|
|
|
|
return fn;
|
|
}
|
|
},
|
|
|
|
pseudos: {
|
|
// Potentially complex pseudos
|
|
"not": markFunction(function( selector ) {
|
|
// Trim the selector passed to compile
|
|
// to avoid treating leading and trailing
|
|
// spaces as combinators
|
|
var input = [],
|
|
results = [],
|
|
matcher = compile( selector.replace( rtrim, "$1" ) );
|
|
|
|
return matcher[ expando ] ?
|
|
markFunction(function( seed, matches, context, xml ) {
|
|
var elem,
|
|
unmatched = matcher( seed, null, xml, [] ),
|
|
i = seed.length;
|
|
|
|
// Match elements unmatched by `matcher`
|
|
while ( i-- ) {
|
|
if ( (elem = unmatched[i]) ) {
|
|
seed[i] = !(matches[i] = elem);
|
|
}
|
|
}
|
|
}) :
|
|
function( elem, context, xml ) {
|
|
input[0] = elem;
|
|
matcher( input, null, xml, results );
|
|
// Don't keep the element (issue #299)
|
|
input[0] = null;
|
|
return !results.pop();
|
|
};
|
|
}),
|
|
|
|
"has": markFunction(function( selector ) {
|
|
return function( elem ) {
|
|
return Sizzle( selector, elem ).length > 0;
|
|
};
|
|
}),
|
|
|
|
"contains": markFunction(function( text ) {
|
|
text = text.replace( runescape, funescape );
|
|
return function( elem ) {
|
|
return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
|
|
};
|
|
}),
|
|
|
|
// "Whether an element is represented by a :lang() selector
|
|
// is based solely on the element's language value
|
|
// being equal to the identifier C,
|
|
// or beginning with the identifier C immediately followed by "-".
|
|
// The matching of C against the element's language value is performed case-insensitively.
|
|
// The identifier C does not have to be a valid language name."
|
|
// http://www.w3.org/TR/selectors/#lang-pseudo
|
|
"lang": markFunction( function( lang ) {
|
|
// lang value must be a valid identifier
|
|
if ( !ridentifier.test(lang || "") ) {
|
|
Sizzle.error( "unsupported lang: " + lang );
|
|
}
|
|
lang = lang.replace( runescape, funescape ).toLowerCase();
|
|
return function( elem ) {
|
|
var elemLang;
|
|
do {
|
|
if ( (elemLang = documentIsHTML ?
|
|
elem.lang :
|
|
elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
|
|
|
|
elemLang = elemLang.toLowerCase();
|
|
return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
|
|
}
|
|
} while ( (elem = elem.parentNode) && elem.nodeType === 1 );
|
|
return false;
|
|
};
|
|
}),
|
|
|
|
// Miscellaneous
|
|
"target": function( elem ) {
|
|
var hash = window.location && window.location.hash;
|
|
return hash && hash.slice( 1 ) === elem.id;
|
|
},
|
|
|
|
"root": function( elem ) {
|
|
return elem === docElem;
|
|
},
|
|
|
|
"focus": function( elem ) {
|
|
return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
|
|
},
|
|
|
|
// Boolean properties
|
|
"enabled": function( elem ) {
|
|
return elem.disabled === false;
|
|
},
|
|
|
|
"disabled": function( elem ) {
|
|
return elem.disabled === true;
|
|
},
|
|
|
|
"checked": function( elem ) {
|
|
// In CSS3, :checked should return both checked and selected elements
|
|
// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
|
|
var nodeName = elem.nodeName.toLowerCase();
|
|
return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
|
|
},
|
|
|
|
"selected": function( elem ) {
|
|
// Accessing this property makes selected-by-default
|
|
// options in Safari work properly
|
|
if ( elem.parentNode ) {
|
|
elem.parentNode.selectedIndex;
|
|
}
|
|
|
|
return elem.selected === true;
|
|
},
|
|
|
|
// Contents
|
|
"empty": function( elem ) {
|
|
// http://www.w3.org/TR/selectors/#empty-pseudo
|
|
// :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
|
|
// but not by others (comment: 8; processing instruction: 7; etc.)
|
|
// nodeType < 6 works because attributes (2) do not appear as children
|
|
for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
|
|
if ( elem.nodeType < 6 ) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
|
|
"parent": function( elem ) {
|
|
return !Expr.pseudos["empty"]( elem );
|
|
},
|
|
|
|
// Element/input types
|
|
"header": function( elem ) {
|
|
return rheader.test( elem.nodeName );
|
|
},
|
|
|
|
"input": function( elem ) {
|
|
return rinputs.test( elem.nodeName );
|
|
},
|
|
|
|
"button": function( elem ) {
|
|
var name = elem.nodeName.toLowerCase();
|
|
return name === "input" && elem.type === "button" || name === "button";
|
|
},
|
|
|
|
"text": function( elem ) {
|
|
var attr;
|
|
return elem.nodeName.toLowerCase() === "input" &&
|
|
elem.type === "text" &&
|
|
|
|
// Support: IE<8
|
|
// New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
|
|
( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
|
|
},
|
|
|
|
// Position-in-collection
|
|
"first": createPositionalPseudo(function() {
|
|
return [ 0 ];
|
|
}),
|
|
|
|
"last": createPositionalPseudo(function( matchIndexes, length ) {
|
|
return [ length - 1 ];
|
|
}),
|
|
|
|
"eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
|
|
return [ argument < 0 ? argument + length : argument ];
|
|
}),
|
|
|
|
"even": createPositionalPseudo(function( matchIndexes, length ) {
|
|
var i = 0;
|
|
for ( ; i < length; i += 2 ) {
|
|
matchIndexes.push( i );
|
|
}
|
|
return matchIndexes;
|
|
}),
|
|
|
|
"odd": createPositionalPseudo(function( matchIndexes, length ) {
|
|
var i = 1;
|
|
for ( ; i < length; i += 2 ) {
|
|
matchIndexes.push( i );
|
|
}
|
|
return matchIndexes;
|
|
}),
|
|
|
|
"lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
|
|
var i = argument < 0 ? argument + length : argument;
|
|
for ( ; --i >= 0; ) {
|
|
matchIndexes.push( i );
|
|
}
|
|
return matchIndexes;
|
|
}),
|
|
|
|
"gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
|
|
var i = argument < 0 ? argument + length : argument;
|
|
for ( ; ++i < length; ) {
|
|
matchIndexes.push( i );
|
|
}
|
|
return matchIndexes;
|
|
})
|
|
}
|
|
};
|
|
|
|
Expr.pseudos["nth"] = Expr.pseudos["eq"];
|
|
|
|
// Add button/input type pseudos
|
|
for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
|
|
Expr.pseudos[ i ] = createInputPseudo( i );
|
|
}
|
|
for ( i in { submit: true, reset: true } ) {
|
|
Expr.pseudos[ i ] = createButtonPseudo( i );
|
|
}
|
|
|
|
// Easy API for creating new setFilters
|
|
function setFilters() {}
|
|
setFilters.prototype = Expr.filters = Expr.pseudos;
|
|
Expr.setFilters = new setFilters();
|
|
|
|
tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
|
|
var matched, match, tokens, type,
|
|
soFar, groups, preFilters,
|
|
cached = tokenCache[ selector + " " ];
|
|
|
|
if ( cached ) {
|
|
return parseOnly ? 0 : cached.slice( 0 );
|
|
}
|
|
|
|
soFar = selector;
|
|
groups = [];
|
|
preFilters = Expr.preFilter;
|
|
|
|
while ( soFar ) {
|
|
|
|
// Comma and first run
|
|
if ( !matched || (match = rcomma.exec( soFar )) ) {
|
|
if ( match ) {
|
|
// Don't consume trailing commas as valid
|
|
soFar = soFar.slice( match[0].length ) || soFar;
|
|
}
|
|
groups.push( (tokens = []) );
|
|
}
|
|
|
|
matched = false;
|
|
|
|
// Combinators
|
|
if ( (match = rcombinators.exec( soFar )) ) {
|
|
matched = match.shift();
|
|
tokens.push({
|
|
value: matched,
|
|
// Cast descendant combinators to space
|
|
type: match[0].replace( rtrim, " " )
|
|
});
|
|
soFar = soFar.slice( matched.length );
|
|
}
|
|
|
|
// Filters
|
|
for ( type in Expr.filter ) {
|
|
if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
|
|
(match = preFilters[ type ]( match ))) ) {
|
|
matched = match.shift();
|
|
tokens.push({
|
|
value: matched,
|
|
type: type,
|
|
matches: match
|
|
});
|
|
soFar = soFar.slice( matched.length );
|
|
}
|
|
}
|
|
|
|
if ( !matched ) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Return the length of the invalid excess
|
|
// if we're just parsing
|
|
// Otherwise, throw an error or return tokens
|
|
return parseOnly ?
|
|
soFar.length :
|
|
soFar ?
|
|
Sizzle.error( selector ) :
|
|
// Cache the tokens
|
|
tokenCache( selector, groups ).slice( 0 );
|
|
};
|
|
|
|
function toSelector( tokens ) {
|
|
var i = 0,
|
|
len = tokens.length,
|
|
selector = "";
|
|
for ( ; i < len; i++ ) {
|
|
selector += tokens[i].value;
|
|
}
|
|
return selector;
|
|
}
|
|
|
|
function addCombinator( matcher, combinator, base ) {
|
|
var dir = combinator.dir,
|
|
checkNonElements = base && dir === "parentNode",
|
|
doneName = done++;
|
|
|
|
return combinator.first ?
|
|
// Check against closest ancestor/preceding element
|
|
function( elem, context, xml ) {
|
|
while ( (elem = elem[ dir ]) ) {
|
|
if ( elem.nodeType === 1 || checkNonElements ) {
|
|
return matcher( elem, context, xml );
|
|
}
|
|
}
|
|
} :
|
|
|
|
// Check against all ancestor/preceding elements
|
|
function( elem, context, xml ) {
|
|
var oldCache, uniqueCache, outerCache,
|
|
newCache = [ dirruns, doneName ];
|
|
|
|
// We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching
|
|
if ( xml ) {
|
|
while ( (elem = elem[ dir ]) ) {
|
|
if ( elem.nodeType === 1 || checkNonElements ) {
|
|
if ( matcher( elem, context, xml ) ) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
while ( (elem = elem[ dir ]) ) {
|
|
if ( elem.nodeType === 1 || checkNonElements ) {
|
|
outerCache = elem[ expando ] || (elem[ expando ] = {});
|
|
|
|
// Support: IE <9 only
|
|
// Defend against cloned attroperties (jQuery gh-1709)
|
|
uniqueCache = outerCache[ elem.uniqueID ] || (outerCache[ elem.uniqueID ] = {});
|
|
|
|
if ( (oldCache = uniqueCache[ dir ]) &&
|
|
oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
|
|
|
|
// Assign to newCache so results back-propagate to previous elements
|
|
return (newCache[ 2 ] = oldCache[ 2 ]);
|
|
} else {
|
|
// Reuse newcache so results back-propagate to previous elements
|
|
uniqueCache[ dir ] = newCache;
|
|
|
|
// A match means we're done; a fail means we have to keep checking
|
|
if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
function elementMatcher( matchers ) {
|
|
return matchers.length > 1 ?
|
|
function( elem, context, xml ) {
|
|
var i = matchers.length;
|
|
while ( i-- ) {
|
|
if ( !matchers[i]( elem, context, xml ) ) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
} :
|
|
matchers[0];
|
|
}
|
|
|
|
function multipleContexts( selector, contexts, results ) {
|
|
var i = 0,
|
|
len = contexts.length;
|
|
for ( ; i < len; i++ ) {
|
|
Sizzle( selector, contexts[i], results );
|
|
}
|
|
return results;
|
|
}
|
|
|
|
function condense( unmatched, map, filter, context, xml ) {
|
|
var elem,
|
|
newUnmatched = [],
|
|
i = 0,
|
|
len = unmatched.length,
|
|
mapped = map != null;
|
|
|
|
for ( ; i < len; i++ ) {
|
|
if ( (elem = unmatched[i]) ) {
|
|
if ( !filter || filter( elem, context, xml ) ) {
|
|
newUnmatched.push( elem );
|
|
if ( mapped ) {
|
|
map.push( i );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return newUnmatched;
|
|
}
|
|
|
|
function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
|
|
if ( postFilter && !postFilter[ expando ] ) {
|
|
postFilter = setMatcher( postFilter );
|
|
}
|
|
if ( postFinder && !postFinder[ expando ] ) {
|
|
postFinder = setMatcher( postFinder, postSelector );
|
|
}
|
|
return markFunction(function( seed, results, context, xml ) {
|
|
var temp, i, elem,
|
|
preMap = [],
|
|
postMap = [],
|
|
preexisting = results.length,
|
|
|
|
// Get initial elements from seed or context
|
|
elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
|
|
|
|
// Prefilter to get matcher input, preserving a map for seed-results synchronization
|
|
matcherIn = preFilter && ( seed || !selector ) ?
|
|
condense( elems, preMap, preFilter, context, xml ) :
|
|
elems,
|
|
|
|
matcherOut = matcher ?
|
|
// If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
|
|
postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
|
|
|
|
// ...intermediate processing is necessary
|
|
[] :
|
|
|
|
// ...otherwise use results directly
|
|
results :
|
|
matcherIn;
|
|
|
|
// Find primary matches
|
|
if ( matcher ) {
|
|
matcher( matcherIn, matcherOut, context, xml );
|
|
}
|
|
|
|
// Apply postFilter
|
|
if ( postFilter ) {
|
|
temp = condense( matcherOut, postMap );
|
|
postFilter( temp, [], context, xml );
|
|
|
|
// Un-match failing elements by moving them back to matcherIn
|
|
i = temp.length;
|
|
while ( i-- ) {
|
|
if ( (elem = temp[i]) ) {
|
|
matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( seed ) {
|
|
if ( postFinder || preFilter ) {
|
|
if ( postFinder ) {
|
|
// Get the final matcherOut by condensing this intermediate into postFinder contexts
|
|
temp = [];
|
|
i = matcherOut.length;
|
|
while ( i-- ) {
|
|
if ( (elem = matcherOut[i]) ) {
|
|
// Restore matcherIn since elem is not yet a final match
|
|
temp.push( (matcherIn[i] = elem) );
|
|
}
|
|
}
|
|
postFinder( null, (matcherOut = []), temp, xml );
|
|
}
|
|
|
|
// Move matched elements from seed to results to keep them synchronized
|
|
i = matcherOut.length;
|
|
while ( i-- ) {
|
|
if ( (elem = matcherOut[i]) &&
|
|
(temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
|
|
|
|
seed[temp] = !(results[temp] = elem);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add elements to results, through postFinder if defined
|
|
} else {
|
|
matcherOut = condense(
|
|
matcherOut === results ?
|
|
matcherOut.splice( preexisting, matcherOut.length ) :
|
|
matcherOut
|
|
);
|
|
if ( postFinder ) {
|
|
postFinder( null, results, matcherOut, xml );
|
|
} else {
|
|
push.apply( results, matcherOut );
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function matcherFromTokens( tokens ) {
|
|
var checkContext, matcher, j,
|
|
len = tokens.length,
|
|
leadingRelative = Expr.relative[ tokens[0].type ],
|
|
implicitRelative = leadingRelative || Expr.relative[" "],
|
|
i = leadingRelative ? 1 : 0,
|
|
|
|
// The foundational matcher ensures that elements are reachable from top-level context(s)
|
|
matchContext = addCombinator( function( elem ) {
|
|
return elem === checkContext;
|
|
}, implicitRelative, true ),
|
|
matchAnyContext = addCombinator( function( elem ) {
|
|
return indexOf( checkContext, elem ) > -1;
|
|
}, implicitRelative, true ),
|
|
matchers = [ function( elem, context, xml ) {
|
|
var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
|
|
(checkContext = context).nodeType ?
|
|
matchContext( elem, context, xml ) :
|
|
matchAnyContext( elem, context, xml ) );
|
|
// Avoid hanging onto element (issue #299)
|
|
checkContext = null;
|
|
return ret;
|
|
} ];
|
|
|
|
for ( ; i < len; i++ ) {
|
|
if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
|
|
matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
|
|
} else {
|
|
matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
|
|
|
|
// Return special upon seeing a positional matcher
|
|
if ( matcher[ expando ] ) {
|
|
// Find the next relative operator (if any) for proper handling
|
|
j = ++i;
|
|
for ( ; j < len; j++ ) {
|
|
if ( Expr.relative[ tokens[j].type ] ) {
|
|
break;
|
|
}
|
|
}
|
|
return setMatcher(
|
|
i > 1 && elementMatcher( matchers ),
|
|
i > 1 && toSelector(
|
|
// If the preceding token was a descendant combinator, insert an implicit any-element `*`
|
|
tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
|
|
).replace( rtrim, "$1" ),
|
|
matcher,
|
|
i < j && matcherFromTokens( tokens.slice( i, j ) ),
|
|
j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
|
|
j < len && toSelector( tokens )
|
|
);
|
|
}
|
|
matchers.push( matcher );
|
|
}
|
|
}
|
|
|
|
return elementMatcher( matchers );
|
|
}
|
|
|
|
function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
|
|
var bySet = setMatchers.length > 0,
|
|
byElement = elementMatchers.length > 0,
|
|
superMatcher = function( seed, context, xml, results, outermost ) {
|
|
var elem, j, matcher,
|
|
matchedCount = 0,
|
|
i = "0",
|
|
unmatched = seed && [],
|
|
setMatched = [],
|
|
contextBackup = outermostContext,
|
|
// We must always have either seed elements or outermost context
|
|
elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
|
|
// Use integer dirruns iff this is the outermost matcher
|
|
dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
|
|
len = elems.length;
|
|
|
|
if ( outermost ) {
|
|
outermostContext = context === document || context || outermost;
|
|
}
|
|
|
|
// Add elements passing elementMatchers directly to results
|
|
// Support: IE<9, Safari
|
|
// Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
|
|
for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
|
|
if ( byElement && elem ) {
|
|
j = 0;
|
|
if ( !context && elem.ownerDocument !== document ) {
|
|
setDocument( elem );
|
|
xml = !documentIsHTML;
|
|
}
|
|
while ( (matcher = elementMatchers[j++]) ) {
|
|
if ( matcher( elem, context || document, xml) ) {
|
|
results.push( elem );
|
|
break;
|
|
}
|
|
}
|
|
if ( outermost ) {
|
|
dirruns = dirrunsUnique;
|
|
}
|
|
}
|
|
|
|
// Track unmatched elements for set filters
|
|
if ( bySet ) {
|
|
// They will have gone through all possible matchers
|
|
if ( (elem = !matcher && elem) ) {
|
|
matchedCount--;
|
|
}
|
|
|
|
// Lengthen the array for every element, matched or not
|
|
if ( seed ) {
|
|
unmatched.push( elem );
|
|
}
|
|
}
|
|
}
|
|
|
|
// `i` is now the count of elements visited above, and adding it to `matchedCount`
|
|
// makes the latter nonnegative.
|
|
matchedCount += i;
|
|
|
|
// Apply set filters to unmatched elements
|
|
// NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount`
|
|
// equals `i`), unless we didn't visit _any_ elements in the above loop because we have
|
|
// no element matchers and no seed.
|
|
// Incrementing an initially-string "0" `i` allows `i` to remain a string only in that
|
|
// case, which will result in a "00" `matchedCount` that differs from `i` but is also
|
|
// numerically zero.
|
|
if ( bySet && i !== matchedCount ) {
|
|
j = 0;
|
|
while ( (matcher = setMatchers[j++]) ) {
|
|
matcher( unmatched, setMatched, context, xml );
|
|
}
|
|
|
|
if ( seed ) {
|
|
// Reintegrate element matches to eliminate the need for sorting
|
|
if ( matchedCount > 0 ) {
|
|
while ( i-- ) {
|
|
if ( !(unmatched[i] || setMatched[i]) ) {
|
|
setMatched[i] = pop.call( results );
|
|
}
|
|
}
|
|
}
|
|
|
|
// Discard index placeholder values to get only actual matches
|
|
setMatched = condense( setMatched );
|
|
}
|
|
|
|
// Add matches to results
|
|
push.apply( results, setMatched );
|
|
|
|
// Seedless set matches succeeding multiple successful matchers stipulate sorting
|
|
if ( outermost && !seed && setMatched.length > 0 &&
|
|
( matchedCount + setMatchers.length ) > 1 ) {
|
|
|
|
Sizzle.uniqueSort( results );
|
|
}
|
|
}
|
|
|
|
// Override manipulation of globals by nested matchers
|
|
if ( outermost ) {
|
|
dirruns = dirrunsUnique;
|
|
outermostContext = contextBackup;
|
|
}
|
|
|
|
return unmatched;
|
|
};
|
|
|
|
return bySet ?
|
|
markFunction( superMatcher ) :
|
|
superMatcher;
|
|
}
|
|
|
|
compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
|
|
var i,
|
|
setMatchers = [],
|
|
elementMatchers = [],
|
|
cached = compilerCache[ selector + " " ];
|
|
|
|
if ( !cached ) {
|
|
// Generate a function of recursive functions that can be used to check each element
|
|
if ( !match ) {
|
|
match = tokenize( selector );
|
|
}
|
|
i = match.length;
|
|
while ( i-- ) {
|
|
cached = matcherFromTokens( match[i] );
|
|
if ( cached[ expando ] ) {
|
|
setMatchers.push( cached );
|
|
} else {
|
|
elementMatchers.push( cached );
|
|
}
|
|
}
|
|
|
|
// Cache the compiled function
|
|
cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
|
|
|
|
// Save selector and tokenization
|
|
cached.selector = selector;
|
|
}
|
|
return cached;
|
|
};
|
|
|
|
/**
|
|
* A low-level selection function that works with Sizzle's compiled
|
|
* selector functions
|
|
* @param {String|Function} selector A selector or a pre-compiled
|
|
* selector function built with Sizzle.compile
|
|
* @param {Element} context
|
|
* @param {Array} [results]
|
|
* @param {Array} [seed] A set of elements to match against
|
|
*/
|
|
select = Sizzle.select = function( selector, context, results, seed ) {
|
|
var i, tokens, token, type, find,
|
|
compiled = typeof selector === "function" && selector,
|
|
match = !seed && tokenize( (selector = compiled.selector || selector) );
|
|
|
|
results = results || [];
|
|
|
|
// Try to minimize operations if there is only one selector in the list and no seed
|
|
// (the latter of which guarantees us context)
|
|
if ( match.length === 1 ) {
|
|
|
|
// Reduce context if the leading compound selector is an ID
|
|
tokens = match[0] = match[0].slice( 0 );
|
|
if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
|
|
support.getById && context.nodeType === 9 && documentIsHTML &&
|
|
Expr.relative[ tokens[1].type ] ) {
|
|
|
|
context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
|
|
if ( !context ) {
|
|
return results;
|
|
|
|
// Precompiled matchers will still verify ancestry, so step up a level
|
|
} else if ( compiled ) {
|
|
context = context.parentNode;
|
|
}
|
|
|
|
selector = selector.slice( tokens.shift().value.length );
|
|
}
|
|
|
|
// Fetch a seed set for right-to-left matching
|
|
i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
|
|
while ( i-- ) {
|
|
token = tokens[i];
|
|
|
|
// Abort if we hit a combinator
|
|
if ( Expr.relative[ (type = token.type) ] ) {
|
|
break;
|
|
}
|
|
if ( (find = Expr.find[ type ]) ) {
|
|
// Search, expanding context for leading sibling combinators
|
|
if ( (seed = find(
|
|
token.matches[0].replace( runescape, funescape ),
|
|
rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
|
|
)) ) {
|
|
|
|
// If seed is empty or no tokens remain, we can return early
|
|
tokens.splice( i, 1 );
|
|
selector = seed.length && toSelector( tokens );
|
|
if ( !selector ) {
|
|
push.apply( results, seed );
|
|
return results;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Compile and execute a filtering function if one is not provided
|
|
// Provide `match` to avoid retokenization if we modified the selector above
|
|
( compiled || compile( selector, match ) )(
|
|
seed,
|
|
context,
|
|
!documentIsHTML,
|
|
results,
|
|
!context || rsibling.test( selector ) && testContext( context.parentNode ) || context
|
|
);
|
|
return results;
|
|
};
|
|
|
|
// One-time assignments
|
|
|
|
// Sort stability
|
|
support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
|
|
|
|
// Support: Chrome 14-35+
|
|
// Always assume duplicates if they aren't passed to the comparison function
|
|
support.detectDuplicates = !!hasDuplicate;
|
|
|
|
// Initialize against the default document
|
|
setDocument();
|
|
|
|
// Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
|
|
// Detached nodes confoundingly follow *each other*
|
|
support.sortDetached = assert(function( div1 ) {
|
|
// Should return 1, but returns 4 (following)
|
|
return div1.compareDocumentPosition( document.createElement("div") ) & 1;
|
|
});
|
|
|
|
// Support: IE<8
|
|
// Prevent attribute/property "interpolation"
|
|
// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
|
|
if ( !assert(function( div ) {
|
|
div.innerHTML = "<a href='#'></a>";
|
|
return div.firstChild.getAttribute("href") === "#" ;
|
|
}) ) {
|
|
addHandle( "type|href|height|width", function( elem, name, isXML ) {
|
|
if ( !isXML ) {
|
|
return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
|
|
}
|
|
});
|
|
}
|
|
|
|
// Support: IE<9
|
|
// Use defaultValue in place of getAttribute("value")
|
|
if ( !support.attributes || !assert(function( div ) {
|
|
div.innerHTML = "<input/>";
|
|
div.firstChild.setAttribute( "value", "" );
|
|
return div.firstChild.getAttribute( "value" ) === "";
|
|
}) ) {
|
|
addHandle( "value", function( elem, name, isXML ) {
|
|
if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
|
|
return elem.defaultValue;
|
|
}
|
|
});
|
|
}
|
|
|
|
// Support: IE<9
|
|
// Use getAttributeNode to fetch booleans when getAttribute lies
|
|
if ( !assert(function( div ) {
|
|
return div.getAttribute("disabled") == null;
|
|
}) ) {
|
|
addHandle( booleans, function( elem, name, isXML ) {
|
|
var val;
|
|
if ( !isXML ) {
|
|
return elem[ name ] === true ? name.toLowerCase() :
|
|
(val = elem.getAttributeNode( name )) && val.specified ?
|
|
val.value :
|
|
null;
|
|
}
|
|
});
|
|
}
|
|
|
|
return Sizzle;
|
|
|
|
})( window );
|
|
|
|
|
|
|
|
jQuery.find = Sizzle;
|
|
jQuery.expr = Sizzle.selectors;
|
|
jQuery.expr[ ":" ] = jQuery.expr.pseudos;
|
|
jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort;
|
|
jQuery.text = Sizzle.getText;
|
|
jQuery.isXMLDoc = Sizzle.isXML;
|
|
jQuery.contains = Sizzle.contains;
|
|
|
|
|
|
|
|
var dir = function( elem, dir, until ) {
|
|
var matched = [],
|
|
truncate = until !== undefined;
|
|
|
|
while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
|
|
if ( elem.nodeType === 1 ) {
|
|
if ( truncate && jQuery( elem ).is( until ) ) {
|
|
break;
|
|
}
|
|
matched.push( elem );
|
|
}
|
|
}
|
|
return matched;
|
|
};
|
|
|
|
|
|
var siblings = function( n, elem ) {
|
|
var matched = [];
|
|
|
|
for ( ; n; n = n.nextSibling ) {
|
|
if ( n.nodeType === 1 && n !== elem ) {
|
|
matched.push( n );
|
|
}
|
|
}
|
|
|
|
return matched;
|
|
};
|
|
|
|
|
|
var rneedsContext = jQuery.expr.match.needsContext;
|
|
|
|
var rsingleTag = ( /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/ );
|
|
|
|
|
|
|
|
var risSimple = /^.[^:#\[\.,]*$/;
|
|
|
|
// Implement the identical functionality for filter and not
|
|
function winnow( elements, qualifier, not ) {
|
|
if ( jQuery.isFunction( qualifier ) ) {
|
|
return jQuery.grep( elements, function( elem, i ) {
|
|
/* jshint -W018 */
|
|
return !!qualifier.call( elem, i, elem ) !== not;
|
|
} );
|
|
|
|
}
|
|
|
|
if ( qualifier.nodeType ) {
|
|
return jQuery.grep( elements, function( elem ) {
|
|
return ( elem === qualifier ) !== not;
|
|
} );
|
|
|
|
}
|
|
|
|
if ( typeof qualifier === "string" ) {
|
|
if ( risSimple.test( qualifier ) ) {
|
|
return jQuery.filter( qualifier, elements, not );
|
|
}
|
|
|
|
qualifier = jQuery.filter( qualifier, elements );
|
|
}
|
|
|
|
return jQuery.grep( elements, function( elem ) {
|
|
return ( jQuery.inArray( elem, qualifier ) > -1 ) !== not;
|
|
} );
|
|
}
|
|
|
|
jQuery.filter = function( expr, elems, not ) {
|
|
var elem = elems[ 0 ];
|
|
|
|
if ( not ) {
|
|
expr = ":not(" + expr + ")";
|
|
}
|
|
|
|
return elems.length === 1 && elem.nodeType === 1 ?
|
|
jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
|
|
jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
|
|
return elem.nodeType === 1;
|
|
} ) );
|
|
};
|
|
|
|
jQuery.fn.extend( {
|
|
find: function( selector ) {
|
|
var i,
|
|
ret = [],
|
|
self = this,
|
|
len = self.length;
|
|
|
|
if ( typeof selector !== "string" ) {
|
|
return this.pushStack( jQuery( selector ).filter( function() {
|
|
for ( i = 0; i < len; i++ ) {
|
|
if ( jQuery.contains( self[ i ], this ) ) {
|
|
return true;
|
|
}
|
|
}
|
|
} ) );
|
|
}
|
|
|
|
for ( i = 0; i < len; i++ ) {
|
|
jQuery.find( selector, self[ i ], ret );
|
|
}
|
|
|
|
// Needed because $( selector, context ) becomes $( context ).find( selector )
|
|
ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
|
|
ret.selector = this.selector ? this.selector + " " + selector : selector;
|
|
return ret;
|
|
},
|
|
filter: function( selector ) {
|
|
return this.pushStack( winnow( this, selector || [], false ) );
|
|
},
|
|
not: function( selector ) {
|
|
return this.pushStack( winnow( this, selector || [], true ) );
|
|
},
|
|
is: function( selector ) {
|
|
return !!winnow(
|
|
this,
|
|
|
|
// If this is a positional/relative selector, check membership in the returned set
|
|
// so $("p:first").is("p:last") won't return true for a doc with two "p".
|
|
typeof selector === "string" && rneedsContext.test( selector ) ?
|
|
jQuery( selector ) :
|
|
selector || [],
|
|
false
|
|
).length;
|
|
}
|
|
} );
|
|
|
|
|
|
// Initialize a jQuery object
|
|
|
|
|
|
// A central reference to the root jQuery(document)
|
|
var rootjQuery,
|
|
|
|
// A simple way to check for HTML strings
|
|
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
|
|
// Strict HTML recognition (#11290: must start with <)
|
|
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
|
|
|
|
init = jQuery.fn.init = function( selector, context, root ) {
|
|
var match, elem;
|
|
|
|
// HANDLE: $(""), $(null), $(undefined), $(false)
|
|
if ( !selector ) {
|
|
return this;
|
|
}
|
|
|
|
// init accepts an alternate rootjQuery
|
|
// so migrate can support jQuery.sub (gh-2101)
|
|
root = root || rootjQuery;
|
|
|
|
// Handle HTML strings
|
|
if ( typeof selector === "string" ) {
|
|
if ( selector.charAt( 0 ) === "<" &&
|
|
selector.charAt( selector.length - 1 ) === ">" &&
|
|
selector.length >= 3 ) {
|
|
|
|
// Assume that strings that start and end with <> are HTML and skip the regex check
|
|
match = [ null, selector, null ];
|
|
|
|
} else {
|
|
match = rquickExpr.exec( selector );
|
|
}
|
|
|
|
// Match html or make sure no context is specified for #id
|
|
if ( match && ( match[ 1 ] || !context ) ) {
|
|
|
|
// HANDLE: $(html) -> $(array)
|
|
if ( match[ 1 ] ) {
|
|
context = context instanceof jQuery ? context[ 0 ] : context;
|
|
|
|
// scripts is true for back-compat
|
|
// Intentionally let the error be thrown if parseHTML is not present
|
|
jQuery.merge( this, jQuery.parseHTML(
|
|
match[ 1 ],
|
|
context && context.nodeType ? context.ownerDocument || context : document,
|
|
true
|
|
) );
|
|
|
|
// HANDLE: $(html, props)
|
|
if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
|
|
for ( match in context ) {
|
|
|
|
// Properties of context are called as methods if possible
|
|
if ( jQuery.isFunction( this[ match ] ) ) {
|
|
this[ match ]( context[ match ] );
|
|
|
|
// ...and otherwise set as attributes
|
|
} else {
|
|
this.attr( match, context[ match ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
return this;
|
|
|
|
// HANDLE: $(#id)
|
|
} else {
|
|
elem = document.getElementById( match[ 2 ] );
|
|
|
|
// Check parentNode to catch when Blackberry 4.6 returns
|
|
// nodes that are no longer in the document #6963
|
|
if ( elem && elem.parentNode ) {
|
|
|
|
// Handle the case where IE and Opera return items
|
|
// by name instead of ID
|
|
if ( elem.id !== match[ 2 ] ) {
|
|
return rootjQuery.find( selector );
|
|
}
|
|
|
|
// Otherwise, we inject the element directly into the jQuery object
|
|
this.length = 1;
|
|
this[ 0 ] = elem;
|
|
}
|
|
|
|
this.context = document;
|
|
this.selector = selector;
|
|
return this;
|
|
}
|
|
|
|
// HANDLE: $(expr, $(...))
|
|
} else if ( !context || context.jquery ) {
|
|
return ( context || root ).find( selector );
|
|
|
|
// HANDLE: $(expr, context)
|
|
// (which is just equivalent to: $(context).find(expr)
|
|
} else {
|
|
return this.constructor( context ).find( selector );
|
|
}
|
|
|
|
// HANDLE: $(DOMElement)
|
|
} else if ( selector.nodeType ) {
|
|
this.context = this[ 0 ] = selector;
|
|
this.length = 1;
|
|
return this;
|
|
|
|
// HANDLE: $(function)
|
|
// Shortcut for document ready
|
|
} else if ( jQuery.isFunction( selector ) ) {
|
|
return typeof root.ready !== "undefined" ?
|
|
root.ready( selector ) :
|
|
|
|
// Execute immediately if ready is not present
|
|
selector( jQuery );
|
|
}
|
|
|
|
if ( selector.selector !== undefined ) {
|
|
this.selector = selector.selector;
|
|
this.context = selector.context;
|
|
}
|
|
|
|
return jQuery.makeArray( selector, this );
|
|
};
|
|
|
|
// Give the init function the jQuery prototype for later instantiation
|
|
init.prototype = jQuery.fn;
|
|
|
|
// Initialize central reference
|
|
rootjQuery = jQuery( document );
|
|
|
|
|
|
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
|
|
|
|
// methods guaranteed to produce a unique set when starting from a unique set
|
|
guaranteedUnique = {
|
|
children: true,
|
|
contents: true,
|
|
next: true,
|
|
prev: true
|
|
};
|
|
|
|
jQuery.fn.extend( {
|
|
has: function( target ) {
|
|
var i,
|
|
targets = jQuery( target, this ),
|
|
len = targets.length;
|
|
|
|
return this.filter( function() {
|
|
for ( i = 0; i < len; i++ ) {
|
|
if ( jQuery.contains( this, targets[ i ] ) ) {
|
|
return true;
|
|
}
|
|
}
|
|
} );
|
|
},
|
|
|
|
closest: function( selectors, context ) {
|
|
var cur,
|
|
i = 0,
|
|
l = this.length,
|
|
matched = [],
|
|
pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
|
|
jQuery( selectors, context || this.context ) :
|
|
0;
|
|
|
|
for ( ; i < l; i++ ) {
|
|
for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
|
|
|
|
// Always skip document fragments
|
|
if ( cur.nodeType < 11 && ( pos ?
|
|
pos.index( cur ) > -1 :
|
|
|
|
// Don't pass non-elements to Sizzle
|
|
cur.nodeType === 1 &&
|
|
jQuery.find.matchesSelector( cur, selectors ) ) ) {
|
|
|
|
matched.push( cur );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
|
|
},
|
|
|
|
// Determine the position of an element within
|
|
// the matched set of elements
|
|
index: function( elem ) {
|
|
|
|
// No argument, return index in parent
|
|
if ( !elem ) {
|
|
return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
|
|
}
|
|
|
|
// index in selector
|
|
if ( typeof elem === "string" ) {
|
|
return jQuery.inArray( this[ 0 ], jQuery( elem ) );
|
|
}
|
|
|
|
// Locate the position of the desired element
|
|
return jQuery.inArray(
|
|
|
|
// If it receives a jQuery object, the first element is used
|
|
elem.jquery ? elem[ 0 ] : elem, this );
|
|
},
|
|
|
|
add: function( selector, context ) {
|
|
return this.pushStack(
|
|
jQuery.uniqueSort(
|
|
jQuery.merge( this.get(), jQuery( selector, context ) )
|
|
)
|
|
);
|
|
},
|
|
|
|
addBack: function( selector ) {
|
|
return this.add( selector == null ?
|
|
this.prevObject : this.prevObject.filter( selector )
|
|
);
|
|
}
|
|
} );
|
|
|
|
function sibling( cur, dir ) {
|
|
do {
|
|
cur = cur[ dir ];
|
|
} while ( cur && cur.nodeType !== 1 );
|
|
|
|
return cur;
|
|
}
|
|
|
|
jQuery.each( {
|
|
parent: function( elem ) {
|
|
var parent = elem.parentNode;
|
|
return parent && parent.nodeType !== 11 ? parent : null;
|
|
},
|
|
parents: function( elem ) {
|
|
return dir( elem, "parentNode" );
|
|
},
|
|
parentsUntil: function( elem, i, until ) {
|
|
return dir( elem, "parentNode", until );
|
|
},
|
|
next: function( elem ) {
|
|
return sibling( elem, "nextSibling" );
|
|
},
|
|
prev: function( elem ) {
|
|
return sibling( elem, "previousSibling" );
|
|
},
|
|
nextAll: function( elem ) {
|
|
return dir( elem, "nextSibling" );
|
|
},
|
|
prevAll: function( elem ) {
|
|
return dir( elem, "previousSibling" );
|
|
},
|
|
nextUntil: function( elem, i, until ) {
|
|
return dir( elem, "nextSibling", until );
|
|
},
|
|
prevUntil: function( elem, i, until ) {
|
|
return dir( elem, "previousSibling", until );
|
|
},
|
|
siblings: function( elem ) {
|
|
return siblings( ( elem.parentNode || {} ).firstChild, elem );
|
|
},
|
|
children: function( elem ) {
|
|
return siblings( elem.firstChild );
|
|
},
|
|
contents: function( elem ) {
|
|
return jQuery.nodeName( elem, "iframe" ) ?
|
|
elem.contentDocument || elem.contentWindow.document :
|
|
jQuery.merge( [], elem.childNodes );
|
|
}
|
|
}, function( name, fn ) {
|
|
jQuery.fn[ name ] = function( until, selector ) {
|
|
var ret = jQuery.map( this, fn, until );
|
|
|
|
if ( name.slice( -5 ) !== "Until" ) {
|
|
selector = until;
|
|
}
|
|
|
|
if ( selector && typeof selector === "string" ) {
|
|
ret = jQuery.filter( selector, ret );
|
|
}
|
|
|
|
if ( this.length > 1 ) {
|
|
|
|
// Remove duplicates
|
|
if ( !guaranteedUnique[ name ] ) {
|
|
ret = jQuery.uniqueSort( ret );
|
|
}
|
|
|
|
// Reverse order for parents* and prev-derivatives
|
|
if ( rparentsprev.test( name ) ) {
|
|
ret = ret.reverse();
|
|
}
|
|
}
|
|
|
|
return this.pushStack( ret );
|
|
};
|
|
} );
|
|
var rnotwhite = ( /\S+/g );
|
|
|
|
|
|
|
|
// Convert String-formatted options into Object-formatted ones
|
|
function createOptions( options ) {
|
|
var object = {};
|
|
jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
|
|
object[ flag ] = true;
|
|
} );
|
|
return object;
|
|
}
|
|
|
|
/*
|
|
* Create a callback list using the following parameters:
|
|
*
|
|
* options: an optional list of space-separated options that will change how
|
|
* the callback list behaves or a more traditional option object
|
|
*
|
|
* By default a callback list will act like an event callback list and can be
|
|
* "fired" multiple times.
|
|
*
|
|
* Possible options:
|
|
*
|
|
* once: will ensure the callback list can only be fired once (like a Deferred)
|
|
*
|
|
* memory: will keep track of previous values and will call any callback added
|
|
* after the list has been fired right away with the latest "memorized"
|
|
* values (like a Deferred)
|
|
*
|
|
* unique: will ensure a callback can only be added once (no duplicate in the list)
|
|
*
|
|
* stopOnFalse: interrupt callings when a callback returns false
|
|
*
|
|
*/
|
|
jQuery.Callbacks = function( options ) {
|
|
|
|
// Convert options from String-formatted to Object-formatted if needed
|
|
// (we check in cache first)
|
|
options = typeof options === "string" ?
|
|
createOptions( options ) :
|
|
jQuery.extend( {}, options );
|
|
|
|
var // Flag to know if list is currently firing
|
|
firing,
|
|
|
|
// Last fire value for non-forgettable lists
|
|
memory,
|
|
|
|
// Flag to know if list was already fired
|
|
fired,
|
|
|
|
// Flag to prevent firing
|
|
locked,
|
|
|
|
// Actual callback list
|
|
list = [],
|
|
|
|
// Queue of execution data for repeatable lists
|
|
queue = [],
|
|
|
|
// Index of currently firing callback (modified by add/remove as needed)
|
|
firingIndex = -1,
|
|
|
|
// Fire callbacks
|
|
fire = function() {
|
|
|
|
// Enforce single-firing
|
|
locked = options.once;
|
|
|
|
// Execute callbacks for all pending executions,
|
|
// respecting firingIndex overrides and runtime changes
|
|
fired = firing = true;
|
|
for ( ; queue.length; firingIndex = -1 ) {
|
|
memory = queue.shift();
|
|
while ( ++firingIndex < list.length ) {
|
|
|
|
// Run callback and check for early termination
|
|
if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false &&
|
|
options.stopOnFalse ) {
|
|
|
|
// Jump to end and forget the data so .add doesn't re-fire
|
|
firingIndex = list.length;
|
|
memory = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Forget the data if we're done with it
|
|
if ( !options.memory ) {
|
|
memory = false;
|
|
}
|
|
|
|
firing = false;
|
|
|
|
// Clean up if we're done firing for good
|
|
if ( locked ) {
|
|
|
|
// Keep an empty list if we have data for future add calls
|
|
if ( memory ) {
|
|
list = [];
|
|
|
|
// Otherwise, this object is spent
|
|
} else {
|
|
list = "";
|
|
}
|
|
}
|
|
},
|
|
|
|
// Actual Callbacks object
|
|
self = {
|
|
|
|
// Add a callback or a collection of callbacks to the list
|
|
add: function() {
|
|
if ( list ) {
|
|
|
|
// If we have memory from a past run, we should fire after adding
|
|
if ( memory && !firing ) {
|
|
firingIndex = list.length - 1;
|
|
queue.push( memory );
|
|
}
|
|
|
|
( function add( args ) {
|
|
jQuery.each( args, function( _, arg ) {
|
|
if ( jQuery.isFunction( arg ) ) {
|
|
if ( !options.unique || !self.has( arg ) ) {
|
|
list.push( arg );
|
|
}
|
|
} else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) {
|
|
|
|
// Inspect recursively
|
|
add( arg );
|
|
}
|
|
} );
|
|
} )( arguments );
|
|
|
|
if ( memory && !firing ) {
|
|
fire();
|
|
}
|
|
}
|
|
return this;
|
|
},
|
|
|
|
// Remove a callback from the list
|
|
remove: function() {
|
|
jQuery.each( arguments, function( _, arg ) {
|
|
var index;
|
|
while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
|
|
list.splice( index, 1 );
|
|
|
|
// Handle firing indexes
|
|
if ( index <= firingIndex ) {
|
|
firingIndex--;
|
|
}
|
|
}
|
|
} );
|
|
return this;
|
|
},
|
|
|
|
// Check if a given callback is in the list.
|
|
// If no argument is given, return whether or not list has callbacks attached.
|
|
has: function( fn ) {
|
|
return fn ?
|
|
jQuery.inArray( fn, list ) > -1 :
|
|
list.length > 0;
|
|
},
|
|
|
|
// Remove all callbacks from the list
|
|
empty: function() {
|
|
if ( list ) {
|
|
list = [];
|
|
}
|
|
return this;
|
|
},
|
|
|
|
// Disable .fire and .add
|
|
// Abort any current/pending executions
|
|
// Clear all callbacks and values
|
|
disable: function() {
|
|
locked = queue = [];
|
|
list = memory = "";
|
|
return this;
|
|
},
|
|
disabled: function() {
|
|
return !list;
|
|
},
|
|
|
|
// Disable .fire
|
|
// Also disable .add unless we have memory (since it would have no effect)
|
|
// Abort any pending executions
|
|
lock: function() {
|
|
locked = true;
|
|
if ( !memory ) {
|
|
self.disable();
|
|
}
|
|
return this;
|
|
},
|
|
locked: function() {
|
|
return !!locked;
|
|
},
|
|
|
|
// Call all callbacks with the given context and arguments
|
|
fireWith: function( context, args ) {
|
|
if ( !locked ) {
|
|
args = args || [];
|
|
args = [ context, args.slice ? args.slice() : args ];
|
|
queue.push( args );
|
|
if ( !firing ) {
|
|
fire();
|
|
}
|
|
}
|
|
return this;
|
|
},
|
|
|
|
// Call all the callbacks with the given arguments
|
|
fire: function() {
|
|
self.fireWith( this, arguments );
|
|
return this;
|
|
},
|
|
|
|
// To know if the callbacks have already been called at least once
|
|
fired: function() {
|
|
return !!fired;
|
|
}
|
|
};
|
|
|
|
return self;
|
|
};
|
|
|
|
|
|
jQuery.extend( {
|
|
|
|
Deferred: function( func ) {
|
|
var tuples = [
|
|
|
|
// action, add listener, listener list, final state
|
|
[ "resolve", "done", jQuery.Callbacks( "once memory" ), "resolved" ],
|
|
[ "reject", "fail", jQuery.Callbacks( "once memory" ), "rejected" ],
|
|
[ "notify", "progress", jQuery.Callbacks( "memory" ) ]
|
|
],
|
|
state = "pending",
|
|
promise = {
|
|
state: function() {
|
|
return state;
|
|
},
|
|
always: function() {
|
|
deferred.done( arguments ).fail( arguments );
|
|
return this;
|
|
},
|
|
then: function( /* fnDone, fnFail, fnProgress */ ) {
|
|
var fns = arguments;
|
|
return jQuery.Deferred( function( newDefer ) {
|
|
jQuery.each( tuples, function( i, tuple ) {
|
|
var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
|
|
|
|
// deferred[ done | fail | progress ] for forwarding actions to newDefer
|
|
deferred[ tuple[ 1 ] ]( function() {
|
|
var returned = fn && fn.apply( this, arguments );
|
|
if ( returned && jQuery.isFunction( returned.promise ) ) {
|
|
returned.promise()
|
|
.progress( newDefer.notify )
|
|
.done( newDefer.resolve )
|
|
.fail( newDefer.reject );
|
|
} else {
|
|
newDefer[ tuple[ 0 ] + "With" ](
|
|
this === promise ? newDefer.promise() : this,
|
|
fn ? [ returned ] : arguments
|
|
);
|
|
}
|
|
} );
|
|
} );
|
|
fns = null;
|
|
} ).promise();
|
|
},
|
|
|
|
// Get a promise for this deferred
|
|
// If obj is provided, the promise aspect is added to the object
|
|
promise: function( obj ) {
|
|
return obj != null ? jQuery.extend( obj, promise ) : promise;
|
|
}
|
|
},
|
|
deferred = {};
|
|
|
|
// Keep pipe for back-compat
|
|
promise.pipe = promise.then;
|
|
|
|
// Add list-specific methods
|
|
jQuery.each( tuples, function( i, tuple ) {
|
|
var list = tuple[ 2 ],
|
|
stateString = tuple[ 3 ];
|
|
|
|
// promise[ done | fail | progress ] = list.add
|
|
promise[ tuple[ 1 ] ] = list.add;
|
|
|
|
// Handle state
|
|
if ( stateString ) {
|
|
list.add( function() {
|
|
|
|
// state = [ resolved | rejected ]
|
|
state = stateString;
|
|
|
|
// [ reject_list | resolve_list ].disable; progress_list.lock
|
|
}, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
|
|
}
|
|
|
|
// deferred[ resolve | reject | notify ]
|
|
deferred[ tuple[ 0 ] ] = function() {
|
|
deferred[ tuple[ 0 ] + "With" ]( this === deferred ? promise : this, arguments );
|
|
return this;
|
|
};
|
|
deferred[ tuple[ 0 ] + "With" ] = list.fireWith;
|
|
} );
|
|
|
|
// Make the deferred a promise
|
|
promise.promise( deferred );
|
|
|
|
// Call given func if any
|
|
if ( func ) {
|
|
func.call( deferred, deferred );
|
|
}
|
|
|
|
// All done!
|
|
return deferred;
|
|
},
|
|
|
|
// Deferred helper
|
|
when: function( subordinate /* , ..., subordinateN */ ) {
|
|
var i = 0,
|
|
resolveValues = slice.call( arguments ),
|
|
length = resolveValues.length,
|
|
|
|
// the count of uncompleted subordinates
|
|
remaining = length !== 1 ||
|
|
( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
|
|
|
|
// the master Deferred.
|
|
// If resolveValues consist of only a single Deferred, just use that.
|
|
deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
|
|
|
|
// Update function for both resolve and progress values
|
|
updateFunc = function( i, contexts, values ) {
|
|
return function( value ) {
|
|
contexts[ i ] = this;
|
|
values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
|
|
if ( values === progressValues ) {
|
|
deferred.notifyWith( contexts, values );
|
|
|
|
} else if ( !( --remaining ) ) {
|
|
deferred.resolveWith( contexts, values );
|
|
}
|
|
};
|
|
},
|
|
|
|
progressValues, progressContexts, resolveContexts;
|
|
|
|
// add listeners to Deferred subordinates; treat others as resolved
|
|
if ( length > 1 ) {
|
|
progressValues = new Array( length );
|
|
progressContexts = new Array( length );
|
|
resolveContexts = new Array( length );
|
|
for ( ; i < length; i++ ) {
|
|
if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
|
|
resolveValues[ i ].promise()
|
|
.progress( updateFunc( i, progressContexts, progressValues ) )
|
|
.done( updateFunc( i, resolveContexts, resolveValues ) )
|
|
.fail( deferred.reject );
|
|
} else {
|
|
--remaining;
|
|
}
|
|
}
|
|
}
|
|
|
|
// if we're not waiting on anything, resolve the master
|
|
if ( !remaining ) {
|
|
deferred.resolveWith( resolveContexts, resolveValues );
|
|
}
|
|
|
|
return deferred.promise();
|
|
}
|
|
} );
|
|
|
|
|
|
// The deferred used on DOM ready
|
|
var readyList;
|
|
|
|
jQuery.fn.ready = function( fn ) {
|
|
|
|
// Add the callback
|
|
jQuery.ready.promise().done( fn );
|
|
|
|
return this;
|
|
};
|
|
|
|
jQuery.extend( {
|
|
|
|
// Is the DOM ready to be used? Set to true once it occurs.
|
|
isReady: false,
|
|
|
|
// A counter to track how many items to wait for before
|
|
// the ready event fires. See #6781
|
|
readyWait: 1,
|
|
|
|
// Hold (or release) the ready event
|
|
holdReady: function( hold ) {
|
|
if ( hold ) {
|
|
jQuery.readyWait++;
|
|
} else {
|
|
jQuery.ready( true );
|
|
}
|
|
},
|
|
|
|
// Handle when the DOM is ready
|
|
ready: function( wait ) {
|
|
|
|
// Abort if there are pending holds or we're already ready
|
|
if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
|
|
return;
|
|
}
|
|
|
|
// Remember that the DOM is ready
|
|
jQuery.isReady = true;
|
|
|
|
// If a normal DOM Ready event fired, decrement, and wait if need be
|
|
if ( wait !== true && --jQuery.readyWait > 0 ) {
|
|
return;
|
|
}
|
|
|
|
// If there are functions bound, to execute
|
|
readyList.resolveWith( document, [ jQuery ] );
|
|
|
|
// Trigger any bound ready events
|
|
if ( jQuery.fn.triggerHandler ) {
|
|
jQuery( document ).triggerHandler( "ready" );
|
|
jQuery( document ).off( "ready" );
|
|
}
|
|
}
|
|
} );
|
|
|
|
/**
|
|
* Clean-up method for dom ready events
|
|
*/
|
|
function detach() {
|
|
if ( document.addEventListener ) {
|
|
document.removeEventListener( "DOMContentLoaded", completed );
|
|
window.removeEventListener( "load", completed );
|
|
|
|
} else {
|
|
document.detachEvent( "onreadystatechange", completed );
|
|
window.detachEvent( "onload", completed );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The ready event handler and self cleanup method
|
|
*/
|
|
function completed() {
|
|
|
|
// readyState === "complete" is good enough for us to call the dom ready in oldIE
|
|
if ( document.addEventListener ||
|
|
window.event.type === "load" ||
|
|
document.readyState === "complete" ) {
|
|
|
|
detach();
|
|
jQuery.ready();
|
|
}
|
|
}
|
|
|
|
jQuery.ready.promise = function( obj ) {
|
|
if ( !readyList ) {
|
|
|
|
readyList = jQuery.Deferred();
|
|
|
|
// Catch cases where $(document).ready() is called
|
|
// after the browser event has already occurred.
|
|
// Support: IE6-10
|
|
// Older IE sometimes signals "interactive" too soon
|
|
if ( document.readyState === "complete" ||
|
|
( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
|
|
|
|
// Handle it asynchronously to allow scripts the opportunity to delay ready
|
|
window.setTimeout( jQuery.ready );
|
|
|
|
// Standards-based browsers support DOMContentLoaded
|
|
} else if ( document.addEventListener ) {
|
|
|
|
// Use the handy event callback
|
|
document.addEventListener( "DOMContentLoaded", completed );
|
|
|
|
// A fallback to window.onload, that will always work
|
|
window.addEventListener( "load", completed );
|
|
|
|
// If IE event model is used
|
|
} else {
|
|
|
|
// Ensure firing before onload, maybe late but safe also for iframes
|
|
document.attachEvent( "onreadystatechange", completed );
|
|
|
|
// A fallback to window.onload, that will always work
|
|
window.attachEvent( "onload", completed );
|
|
|
|
// If IE and not a frame
|
|
// continually check to see if the document is ready
|
|
var top = false;
|
|
|
|
try {
|
|
top = window.frameElement == null && document.documentElement;
|
|
} catch ( e ) {}
|
|
|
|
if ( top && top.doScroll ) {
|
|
( function doScrollCheck() {
|
|
if ( !jQuery.isReady ) {
|
|
|
|
try {
|
|
|
|
// Use the trick by Diego Perini
|
|
// http://javascript.nwbox.com/IEContentLoaded/
|
|
top.doScroll( "left" );
|
|
} catch ( e ) {
|
|
return window.setTimeout( doScrollCheck, 50 );
|
|
}
|
|
|
|
// detach all dom ready events
|
|
detach();
|
|
|
|
// and execute any waiting functions
|
|
jQuery.ready();
|
|
}
|
|
} )();
|
|
}
|
|
}
|
|
}
|
|
return readyList.promise( obj );
|
|
};
|
|
|
|
// Kick off the DOM ready check even if the user does not
|
|
jQuery.ready.promise();
|
|
|
|
|
|
|
|
|
|
// Support: IE<9
|
|
// Iteration over object's inherited properties before its own
|
|
var i;
|
|
for ( i in jQuery( support ) ) {
|
|
break;
|
|
}
|
|
support.ownFirst = i === "0";
|
|
|
|
// Note: most support tests are defined in their respective modules.
|
|
// false until the test is run
|
|
support.inlineBlockNeedsLayout = false;
|
|
|
|
// Execute ASAP in case we need to set body.style.zoom
|
|
jQuery( function() {
|
|
|
|
// Minified: var a,b,c,d
|
|
var val, div, body, container;
|
|
|
|
body = document.getElementsByTagName( "body" )[ 0 ];
|
|
if ( !body || !body.style ) {
|
|
|
|
// Return for frameset docs that don't have a body
|
|
return;
|
|
}
|
|
|
|
// Setup
|
|
div = document.createElement( "div" );
|
|
container = document.createElement( "div" );
|
|
container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
|
|
body.appendChild( container ).appendChild( div );
|
|
|
|
if ( typeof div.style.zoom !== "undefined" ) {
|
|
|
|
// Support: IE<8
|
|
// Check if natively block-level elements act like inline-block
|
|
// elements when setting their display to 'inline' and giving
|
|
// them layout
|
|
div.style.cssText = "display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1";
|
|
|
|
support.inlineBlockNeedsLayout = val = div.offsetWidth === 3;
|
|
if ( val ) {
|
|
|
|
// Prevent IE 6 from affecting layout for positioned elements #11048
|
|
// Prevent IE from shrinking the body in IE 7 mode #12869
|
|
// Support: IE<8
|
|
body.style.zoom = 1;
|
|
}
|
|
}
|
|
|
|
body.removeChild( container );
|
|
} );
|
|
|
|
|
|
( function() {
|
|
var div = document.createElement( "div" );
|
|
|
|
// Support: IE<9
|
|
support.deleteExpando = true;
|
|
try {
|
|
delete div.test;
|
|
} catch ( e ) {
|
|
support.deleteExpando = false;
|
|
}
|
|
|
|
// Null elements to avoid leaks in IE.
|
|
div = null;
|
|
} )();
|
|
var acceptData = function( elem ) {
|
|
var noData = jQuery.noData[ ( elem.nodeName + " " ).toLowerCase() ],
|
|
nodeType = +elem.nodeType || 1;
|
|
|
|
// Do not set data on non-element DOM nodes because it will not be cleared (#8335).
|
|
return nodeType !== 1 && nodeType !== 9 ?
|
|
false :
|
|
|
|
// Nodes accept data unless otherwise specified; rejection can be conditional
|
|
!noData || noData !== true && elem.getAttribute( "classid" ) === noData;
|
|
};
|
|
|
|
|
|
|
|
|
|
var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
|
|
rmultiDash = /([A-Z])/g;
|
|
|
|
function dataAttr( elem, key, data ) {
|
|
|
|
// If nothing was found internally, try to fetch any
|
|
// data from the HTML5 data-* attribute
|
|
if ( data === undefined && elem.nodeType === 1 ) {
|
|
|
|
var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
|
|
|
|
data = elem.getAttribute( name );
|
|
|
|
if ( typeof data === "string" ) {
|
|
try {
|
|
data = data === "true" ? true :
|
|
data === "false" ? false :
|
|
data === "null" ? null :
|
|
|
|
// Only convert to a number if it doesn't change the string
|
|
+data + "" === data ? +data :
|
|
rbrace.test( data ) ? jQuery.parseJSON( data ) :
|
|
data;
|
|
} catch ( e ) {}
|
|
|
|
// Make sure we set the data so it isn't changed later
|
|
jQuery.data( elem, key, data );
|
|
|
|
} else {
|
|
data = undefined;
|
|
}
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
// checks a cache object for emptiness
|
|
function isEmptyDataObject( obj ) {
|
|
var name;
|
|
for ( name in obj ) {
|
|
|
|
// if the public data object is empty, the private is still empty
|
|
if ( name === "data" && jQuery.isEmptyObject( obj[ name ] ) ) {
|
|
continue;
|
|
}
|
|
if ( name !== "toJSON" ) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function internalData( elem, name, data, pvt /* Internal Use Only */ ) {
|
|
if ( !acceptData( elem ) ) {
|
|
return;
|
|
}
|
|
|
|
var ret, thisCache,
|
|
internalKey = jQuery.expando,
|
|
|
|
// We have to handle DOM nodes and JS objects differently because IE6-7
|
|
// can't GC object references properly across the DOM-JS boundary
|
|
isNode = elem.nodeType,
|
|
|
|
// Only DOM nodes need the global jQuery cache; JS object data is
|
|
// attached directly to the object so GC can occur automatically
|
|
cache = isNode ? jQuery.cache : elem,
|
|
|
|
// Only defining an ID for JS objects if its cache already exists allows
|
|
// the code to shortcut on the same path as a DOM node with no cache
|
|
id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey;
|
|
|
|
// Avoid doing any more work than we need to when trying to get data on an
|
|
// object that has no data at all
|
|
if ( ( !id || !cache[ id ] || ( !pvt && !cache[ id ].data ) ) &&
|
|
data === undefined && typeof name === "string" ) {
|
|
return;
|
|
}
|
|
|
|
if ( !id ) {
|
|
|
|
// Only DOM nodes need a new unique ID for each element since their data
|
|
// ends up in the global cache
|
|
if ( isNode ) {
|
|
id = elem[ internalKey ] = deletedIds.pop() || jQuery.guid++;
|
|
} else {
|
|
id = internalKey;
|
|
}
|
|
}
|
|
|
|
if ( !cache[ id ] ) {
|
|
|
|
// Avoid exposing jQuery metadata on plain JS objects when the object
|
|
// is serialized using JSON.stringify
|
|
cache[ id ] = isNode ? {} : { toJSON: jQuery.noop };
|
|
}
|
|
|
|
// An object can be passed to jQuery.data instead of a key/value pair; this gets
|
|
// shallow copied over onto the existing cache
|
|
if ( typeof name === "object" || typeof name === "function" ) {
|
|
if ( pvt ) {
|
|
cache[ id ] = jQuery.extend( cache[ id ], name );
|
|
} else {
|
|
cache[ id ].data = jQuery.extend( cache[ id ].data, name );
|
|
}
|
|
}
|
|
|
|
thisCache = cache[ id ];
|
|
|
|
// jQuery data() is stored in a separate object inside the object's internal data
|
|
// cache in order to avoid key collisions between internal data and user-defined
|
|
// data.
|
|
if ( !pvt ) {
|
|
if ( !thisCache.data ) {
|
|
thisCache.data = {};
|
|
}
|
|
|
|
thisCache = thisCache.data;
|
|
}
|
|
|
|
if ( data !== undefined ) {
|
|
thisCache[ jQuery.camelCase( name ) ] = data;
|
|
}
|
|
|
|
// Check for both converted-to-camel and non-converted data property names
|
|
// If a data property was specified
|
|
if ( typeof name === "string" ) {
|
|
|
|
// First Try to find as-is property data
|
|
ret = thisCache[ name ];
|
|
|
|
// Test for null|undefined property data
|
|
if ( ret == null ) {
|
|
|
|
// Try to find the camelCased property
|
|
ret = thisCache[ jQuery.camelCase( name ) ];
|
|
}
|
|
} else {
|
|
ret = thisCache;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
function internalRemoveData( elem, name, pvt ) {
|
|
if ( !acceptData( elem ) ) {
|
|
return;
|
|
}
|
|
|
|
var thisCache, i,
|
|
isNode = elem.nodeType,
|
|
|
|
// See jQuery.data for more information
|
|
cache = isNode ? jQuery.cache : elem,
|
|
id = isNode ? elem[ jQuery.expando ] : jQuery.expando;
|
|
|
|
// If there is already no cache entry for this object, there is no
|
|
// purpose in continuing
|
|
if ( !cache[ id ] ) {
|
|
return;
|
|
}
|
|
|
|
if ( name ) {
|
|
|
|
thisCache = pvt ? cache[ id ] : cache[ id ].data;
|
|
|
|
if ( thisCache ) {
|
|
|
|
// Support array or space separated string names for data keys
|
|
if ( !jQuery.isArray( name ) ) {
|
|
|
|
// try the string as a key before any manipulation
|
|
if ( name in thisCache ) {
|
|
name = [ name ];
|
|
} else {
|
|
|
|
// split the camel cased version by spaces unless a key with the spaces exists
|
|
name = jQuery.camelCase( name );
|
|
if ( name in thisCache ) {
|
|
name = [ name ];
|
|
} else {
|
|
name = name.split( " " );
|
|
}
|
|
}
|
|
} else {
|
|
|
|
// If "name" is an array of keys...
|
|
// When data is initially created, via ("key", "val") signature,
|
|
// keys will be converted to camelCase.
|
|
// Since there is no way to tell _how_ a key was added, remove
|
|
// both plain key and camelCase key. #12786
|
|
// This will only penalize the array argument path.
|
|
name = name.concat( jQuery.map( name, jQuery.camelCase ) );
|
|
}
|
|
|
|
i = name.length;
|
|
while ( i-- ) {
|
|
delete thisCache[ name[ i ] ];
|
|
}
|
|
|
|
// If there is no data left in the cache, we want to continue
|
|
// and let the cache object itself get destroyed
|
|
if ( pvt ? !isEmptyDataObject( thisCache ) : !jQuery.isEmptyObject( thisCache ) ) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// See jQuery.data for more information
|
|
if ( !pvt ) {
|
|
delete cache[ id ].data;
|
|
|
|
// Don't destroy the parent cache unless the internal data object
|
|
// had been the only thing left in it
|
|
if ( !isEmptyDataObject( cache[ id ] ) ) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Destroy the cache
|
|
if ( isNode ) {
|
|
jQuery.cleanData( [ elem ], true );
|
|
|
|
// Use delete when supported for expandos or `cache` is not a window per isWindow (#10080)
|
|
/* jshint eqeqeq: false */
|
|
} else if ( support.deleteExpando || cache != cache.window ) {
|
|
/* jshint eqeqeq: true */
|
|
delete cache[ id ];
|
|
|
|
// When all else fails, undefined
|
|
} else {
|
|
cache[ id ] = undefined;
|
|
}
|
|
}
|
|
|
|
jQuery.extend( {
|
|
cache: {},
|
|
|
|
// The following elements (space-suffixed to avoid Object.prototype collisions)
|
|
// throw uncatchable exceptions if you attempt to set expando properties
|
|
noData: {
|
|
"applet ": true,
|
|
"embed ": true,
|
|
|
|
// ...but Flash objects (which have this classid) *can* handle expandos
|
|
"object ": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
|
|
},
|
|
|
|
hasData: function( elem ) {
|
|
elem = elem.nodeType ? jQuery.cache[ elem[ jQuery.expando ] ] : elem[ jQuery.expando ];
|
|
return !!elem && !isEmptyDataObject( elem );
|
|
},
|
|
|
|
data: function( elem, name, data ) {
|
|
return internalData( elem, name, data );
|
|
},
|
|
|
|
removeData: function( elem, name ) {
|
|
return internalRemoveData( elem, name );
|
|
},
|
|
|
|
// For internal use only.
|
|
_data: function( elem, name, data ) {
|
|
return internalData( elem, name, data, true );
|
|
},
|
|
|
|
_removeData: function( elem, name ) {
|
|
return internalRemoveData( elem, name, true );
|
|
}
|
|
} );
|
|
|
|
jQuery.fn.extend( {
|
|
data: function( key, value ) {
|
|
var i, name, data,
|
|
elem = this[ 0 ],
|
|
attrs = elem && elem.attributes;
|
|
|
|
// Special expections of .data basically thwart jQuery.access,
|
|
// so implement the relevant behavior ourselves
|
|
|
|
// Gets all values
|
|
if ( key === undefined ) {
|
|
if ( this.length ) {
|
|
data = jQuery.data( elem );
|
|
|
|
if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
|
|
i = attrs.length;
|
|
while ( i-- ) {
|
|
|
|
// Support: IE11+
|
|
// The attrs elements can be null (#14894)
|
|
if ( attrs[ i ] ) {
|
|
name = attrs[ i ].name;
|
|
if ( name.indexOf( "data-" ) === 0 ) {
|
|
name = jQuery.camelCase( name.slice( 5 ) );
|
|
dataAttr( elem, name, data[ name ] );
|
|
}
|
|
}
|
|
}
|
|
jQuery._data( elem, "parsedAttrs", true );
|
|
}
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
// Sets multiple values
|
|
if ( typeof key === "object" ) {
|
|
return this.each( function() {
|
|
jQuery.data( this, key );
|
|
} );
|
|
}
|
|
|
|
return arguments.length > 1 ?
|
|
|
|
// Sets one value
|
|
this.each( function() {
|
|
jQuery.data( this, key, value );
|
|
} ) :
|
|
|
|
// Gets one value
|
|
// Try to fetch any internally stored data first
|
|
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : undefined;
|
|
},
|
|
|
|
removeData: function( key ) {
|
|
return this.each( function() {
|
|
jQuery.removeData( this, key );
|
|
} );
|
|
}
|
|
} );
|
|
|
|
|
|
jQuery.extend( {
|
|
queue: function( elem, type, data ) {
|
|
var queue;
|
|
|
|
if ( elem ) {
|
|
type = ( type || "fx" ) + "queue";
|
|
queue = jQuery._data( elem, type );
|
|
|
|
// Speed up dequeue by getting out quickly if this is just a lookup
|
|
if ( data ) {
|
|
if ( !queue || jQuery.isArray( data ) ) {
|
|
queue = jQuery._data( elem, type, jQuery.makeArray( data ) );
|
|
} else {
|
|
queue.push( data );
|
|
}
|
|
}
|
|
return queue || [];
|
|
}
|
|
},
|
|
|
|
dequeue: function( elem, type ) {
|
|
type = type || "fx";
|
|
|
|
var queue = jQuery.queue( elem, type ),
|
|
startLength = queue.length,
|
|
fn = queue.shift(),
|
|
hooks = jQuery._queueHooks( elem, type ),
|
|
next = function() {
|
|
jQuery.dequeue( elem, type );
|
|
};
|
|
|
|
// If the fx queue is dequeued, always remove the progress sentinel
|
|
if ( fn === "inprogress" ) {
|
|
fn = queue.shift();
|
|
startLength--;
|
|
}
|
|
|
|
if ( fn ) {
|
|
|
|
// Add a progress sentinel to prevent the fx queue from being
|
|
// automatically dequeued
|
|
if ( type === "fx" ) {
|
|
queue.unshift( "inprogress" );
|
|
}
|
|
|
|
// clear up the last queue stop function
|
|
delete hooks.stop;
|
|
fn.call( elem, next, hooks );
|
|
}
|
|
|
|
if ( !startLength && hooks ) {
|
|
hooks.empty.fire();
|
|
}
|
|
},
|
|
|
|
// not intended for public consumption - generates a queueHooks object,
|
|
// or returns the current one
|
|
_queueHooks: function( elem, type ) {
|
|
var key = type + "queueHooks";
|
|
return jQuery._data( elem, key ) || jQuery._data( elem, key, {
|
|
empty: jQuery.Callbacks( "once memory" ).add( function() {
|
|
jQuery._removeData( elem, type + "queue" );
|
|
jQuery._removeData( elem, key );
|
|
} )
|
|
} );
|
|
}
|
|
} );
|
|
|
|
jQuery.fn.extend( {
|
|
queue: function( type, data ) {
|
|
var setter = 2;
|
|
|
|
if ( typeof type !== "string" ) {
|
|
data = type;
|
|
type = "fx";
|
|
setter--;
|
|
}
|
|
|
|
if ( arguments.length < setter ) {
|
|
return jQuery.queue( this[ 0 ], type );
|
|
}
|
|
|
|
return data === undefined ?
|
|
this :
|
|
this.each( function() {
|
|
var queue = jQuery.queue( this, type, data );
|
|
|
|
// ensure a hooks for this queue
|
|
jQuery._queueHooks( this, type );
|
|
|
|
if ( type === "fx" && queue[ 0 ] !== "inprogress" ) {
|
|
jQuery.dequeue( this, type );
|
|
}
|
|
} );
|
|
},
|
|
dequeue: function( type ) {
|
|
return this.each( function() {
|
|
jQuery.dequeue( this, type );
|
|
} );
|
|
},
|
|
clearQueue: function( type ) {
|
|
return this.queue( type || "fx", [] );
|
|
},
|
|
|
|
// Get a promise resolved when queues of a certain type
|
|
// are emptied (fx is the type by default)
|
|
promise: function( type, obj ) {
|
|
var tmp,
|
|
count = 1,
|
|
defer = jQuery.Deferred(),
|
|
elements = this,
|
|
i = this.length,
|
|
resolve = function() {
|
|
if ( !( --count ) ) {
|
|
defer.resolveWith( elements, [ elements ] );
|
|
}
|
|
};
|
|
|
|
if ( typeof type !== "string" ) {
|
|
obj = type;
|
|
type = undefined;
|
|
}
|
|
type = type || "fx";
|
|
|
|
while ( i-- ) {
|
|
tmp = jQuery._data( elements[ i ], type + "queueHooks" );
|
|
if ( tmp && tmp.empty ) {
|
|
count++;
|
|
tmp.empty.add( resolve );
|
|
}
|
|
}
|
|
resolve();
|
|
return defer.promise( obj );
|
|
}
|
|
} );
|
|
|
|
|
|
( function() {
|
|
var shrinkWrapBlocksVal;
|
|
|
|
support.shrinkWrapBlocks = function() {
|
|
if ( shrinkWrapBlocksVal != null ) {
|
|
return shrinkWrapBlocksVal;
|
|
}
|
|
|
|
// Will be changed later if needed.
|
|
shrinkWrapBlocksVal = false;
|
|
|
|
// Minified: var b,c,d
|
|
var div, body, container;
|
|
|
|
body = document.getElementsByTagName( "body" )[ 0 ];
|
|
if ( !body || !body.style ) {
|
|
|
|
// Test fired too early or in an unsupported environment, exit.
|
|
return;
|
|
}
|
|
|
|
// Setup
|
|
div = document.createElement( "div" );
|
|
container = document.createElement( "div" );
|
|
container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
|
|
body.appendChild( container ).appendChild( div );
|
|
|
|
// Support: IE6
|
|
// Check if elements with layout shrink-wrap their children
|
|
if ( typeof div.style.zoom !== "undefined" ) {
|
|
|
|
// Reset CSS: box-sizing; display; margin; border
|
|
div.style.cssText =
|
|
|
|
// Support: Firefox<29, Android 2.3
|
|
// Vendor-prefix box-sizing
|
|
"-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
|
|
"box-sizing:content-box;display:block;margin:0;border:0;" +
|
|
"padding:1px;width:1px;zoom:1";
|
|
div.appendChild( document.createElement( "div" ) ).style.width = "5px";
|
|
shrinkWrapBlocksVal = div.offsetWidth !== 3;
|
|
}
|
|
|
|
body.removeChild( container );
|
|
|
|
return shrinkWrapBlocksVal;
|
|
};
|
|
|
|
} )();
|
|
var pnum = ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source;
|
|
|
|
var rcssNum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" );
|
|
|
|
|
|
var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
|
|
|
|
var isHidden = function( elem, el ) {
|
|
|
|
// isHidden might be called from jQuery#filter function;
|
|
// in that case, element will be second argument
|
|
elem = el || elem;
|
|
return jQuery.css( elem, "display" ) === "none" ||
|
|
!jQuery.contains( elem.ownerDocument, elem );
|
|
};
|
|
|
|
|
|
|
|
function adjustCSS( elem, prop, valueParts, tween ) {
|
|
var adjusted,
|
|
scale = 1,
|
|
maxIterations = 20,
|
|
currentValue = tween ?
|
|
function() { return tween.cur(); } :
|
|
function() { return jQuery.css( elem, prop, "" ); },
|
|
initial = currentValue(),
|
|
unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
|
|
|
|
// Starting value computation is required for potential unit mismatches
|
|
initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
|
|
rcssNum.exec( jQuery.css( elem, prop ) );
|
|
|
|
if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
|
|
|
|
// Trust units reported by jQuery.css
|
|
unit = unit || initialInUnit[ 3 ];
|
|
|
|
// Make sure we update the tween properties later on
|
|
valueParts = valueParts || [];
|
|
|
|
// Iteratively approximate from a nonzero starting point
|
|
initialInUnit = +initial || 1;
|
|
|
|
do {
|
|
|
|
// If previous iteration zeroed out, double until we get *something*.
|
|
// Use string for doubling so we don't accidentally see scale as unchanged below
|
|
scale = scale || ".5";
|
|
|
|
// Adjust and apply
|
|
initialInUnit = initialInUnit / scale;
|
|
jQuery.style( elem, prop, initialInUnit + unit );
|
|
|
|
// Update scale, tolerating zero or NaN from tween.cur()
|
|
// Break the loop if scale is unchanged or perfect, or if we've just had enough.
|
|
} while (
|
|
scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations
|
|
);
|
|
}
|
|
|
|
if ( valueParts ) {
|
|
initialInUnit = +initialInUnit || +initial || 0;
|
|
|
|
// Apply relative offset (+=/-=) if specified
|
|
adjusted = valueParts[ 1 ] ?
|
|
initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
|
|
+valueParts[ 2 ];
|
|
if ( tween ) {
|
|
tween.unit = unit;
|
|
tween.start = initialInUnit;
|
|
tween.end = adjusted;
|
|
}
|
|
}
|
|
return adjusted;
|
|
}
|
|
|
|
|
|
// Multifunctional method to get and set values of a collection
|
|
// The value/s can optionally be executed if it's a function
|
|
var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
|
|
var i = 0,
|
|
length = elems.length,
|
|
bulk = key == null;
|
|
|
|
// Sets many values
|
|
if ( jQuery.type( key ) === "object" ) {
|
|
chainable = true;
|
|
for ( i in key ) {
|
|
access( elems, fn, i, key[ i ], true, emptyGet, raw );
|
|
}
|
|
|
|
// Sets one value
|
|
} else if ( value !== undefined ) {
|
|
chainable = true;
|
|
|
|
if ( !jQuery.isFunction( value ) ) {
|
|
raw = true;
|
|
}
|
|
|
|
if ( bulk ) {
|
|
|
|
// Bulk operations run against the entire set
|
|
if ( raw ) {
|
|
fn.call( elems, value );
|
|
fn = null;
|
|
|
|
// ...except when executing function values
|
|
} else {
|
|
bulk = fn;
|
|
fn = function( elem, key, value ) {
|
|
return bulk.call( jQuery( elem ), value );
|
|
};
|
|
}
|
|
}
|
|
|
|
if ( fn ) {
|
|
for ( ; i < length; i++ ) {
|
|
fn(
|
|
elems[ i ],
|
|
key,
|
|
raw ? value : value.call( elems[ i ], i, fn( elems[ i ], key ) )
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
return chainable ?
|
|
elems :
|
|
|
|
// Gets
|
|
bulk ?
|
|
fn.call( elems ) :
|
|
length ? fn( elems[ 0 ], key ) : emptyGet;
|
|
};
|
|
var rcheckableType = ( /^(?:checkbox|radio)$/i );
|
|
|
|
var rtagName = ( /<([\w:-]+)/ );
|
|
|
|
var rscriptType = ( /^$|\/(?:java|ecma)script/i );
|
|
|
|
var rleadingWhitespace = ( /^\s+/ );
|
|
|
|
var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|" +
|
|
"details|dialog|figcaption|figure|footer|header|hgroup|main|" +
|
|
"mark|meter|nav|output|picture|progress|section|summary|template|time|video";
|
|
|
|
|
|
|
|
function createSafeFragment( document ) {
|
|
var list = nodeNames.split( "|" ),
|
|
safeFrag = document.createDocumentFragment();
|
|
|
|
if ( safeFrag.createElement ) {
|
|
while ( list.length ) {
|
|
safeFrag.createElement(
|
|
list.pop()
|
|
);
|
|
}
|
|
}
|
|
return safeFrag;
|
|
}
|
|
|
|
|
|
( function() {
|
|
var div = document.createElement( "div" ),
|
|
fragment = document.createDocumentFragment(),
|
|
input = document.createElement( "input" );
|
|
|
|
// Setup
|
|
div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
|
|
|
|
// IE strips leading whitespace when .innerHTML is used
|
|
support.leadingWhitespace = div.firstChild.nodeType === 3;
|
|
|
|
// Make sure that tbody elements aren't automatically inserted
|
|
// IE will insert them into empty tables
|
|
support.tbody = !div.getElementsByTagName( "tbody" ).length;
|
|
|
|
// Make sure that link elements get serialized correctly by innerHTML
|
|
// This requires a wrapper element in IE
|
|
support.htmlSerialize = !!div.getElementsByTagName( "link" ).length;
|
|
|
|
// Makes sure cloning an html5 element does not cause problems
|
|
// Where outerHTML is undefined, this still works
|
|
support.html5Clone =
|
|
document.createElement( "nav" ).cloneNode( true ).outerHTML !== "<:nav></:nav>";
|
|
|
|
// Check if a disconnected checkbox will retain its checked
|
|
// value of true after appended to the DOM (IE6/7)
|
|
input.type = "checkbox";
|
|
input.checked = true;
|
|
fragment.appendChild( input );
|
|
support.appendChecked = input.checked;
|
|
|
|
// Make sure textarea (and checkbox) defaultValue is properly cloned
|
|
// Support: IE6-IE11+
|
|
div.innerHTML = "<textarea>x</textarea>";
|
|
support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
|
|
|
|
// #11217 - WebKit loses check when the name is after the checked attribute
|
|
fragment.appendChild( div );
|
|
|
|
// Support: Windows Web Apps (WWA)
|
|
// `name` and `type` must use .setAttribute for WWA (#14901)
|
|
input = document.createElement( "input" );
|
|
input.setAttribute( "type", "radio" );
|
|
input.setAttribute( "checked", "checked" );
|
|
input.setAttribute( "name", "t" );
|
|
|
|
div.appendChild( input );
|
|
|
|
// Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3
|
|
// old WebKit doesn't clone checked state correctly in fragments
|
|
support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
|
|
|
|
// Support: IE<9
|
|
// Cloned elements keep attachEvent handlers, we use addEventListener on IE9+
|
|
support.noCloneEvent = !!div.addEventListener;
|
|
|
|
// Support: IE<9
|
|
// Since attributes and properties are the same in IE,
|
|
// cleanData must set properties to undefined rather than use removeAttribute
|
|
div[ jQuery.expando ] = 1;
|
|
support.attributes = !div.getAttribute( jQuery.expando );
|
|
} )();
|
|
|
|
|
|
// We have to close these tags to support XHTML (#13200)
|
|
var wrapMap = {
|
|
option: [ 1, "<select multiple='multiple'>", "</select>" ],
|
|
legend: [ 1, "<fieldset>", "</fieldset>" ],
|
|
area: [ 1, "<map>", "</map>" ],
|
|
|
|
// Support: IE8
|
|
param: [ 1, "<object>", "</object>" ],
|
|
thead: [ 1, "<table>", "</table>" ],
|
|
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
|
|
col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
|
|
td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
|
|
|
|
// IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags,
|
|
// unless wrapped in a div with non-breaking characters in front of it.
|
|
_default: support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X<div>", "</div>" ]
|
|
};
|
|
|
|
// Support: IE8-IE9
|
|
wrapMap.optgroup = wrapMap.option;
|
|
|
|
wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
|
|
wrapMap.th = wrapMap.td;
|
|
|
|
|
|
function getAll( context, tag ) {
|
|
var elems, elem,
|
|
i = 0,
|
|
found = typeof context.getElementsByTagName !== "undefined" ?
|
|
context.getElementsByTagName( tag || "*" ) :
|
|
typeof context.querySelectorAll !== "undefined" ?
|
|
context.querySelectorAll( tag || "*" ) :
|
|
undefined;
|
|
|
|
if ( !found ) {
|
|
for ( found = [], elems = context.childNodes || context;
|
|
( elem = elems[ i ] ) != null;
|
|
i++
|
|
) {
|
|
if ( !tag || jQuery.nodeName( elem, tag ) ) {
|
|
found.push( elem );
|
|
} else {
|
|
jQuery.merge( found, getAll( elem, tag ) );
|
|
}
|
|
}
|
|
}
|
|
|
|
return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
|
|
jQuery.merge( [ context ], found ) :
|
|
found;
|
|
}
|
|
|
|
|
|
// Mark scripts as having already been evaluated
|
|
function setGlobalEval( elems, refElements ) {
|
|
var elem,
|
|
i = 0;
|
|
for ( ; ( elem = elems[ i ] ) != null; i++ ) {
|
|
jQuery._data(
|
|
elem,
|
|
"globalEval",
|
|
!refElements || jQuery._data( refElements[ i ], "globalEval" )
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
var rhtml = /<|&#?\w+;/,
|
|
rtbody = /<tbody/i;
|
|
|
|
function fixDefaultChecked( elem ) {
|
|
if ( rcheckableType.test( elem.type ) ) {
|
|
elem.defaultChecked = elem.checked;
|
|
}
|
|
}
|
|
|
|
function buildFragment( elems, context, scripts, selection, ignored ) {
|
|
var j, elem, contains,
|
|
tmp, tag, tbody, wrap,
|
|
l = elems.length,
|
|
|
|
// Ensure a safe fragment
|
|
safe = createSafeFragment( context ),
|
|
|
|
nodes = [],
|
|
i = 0;
|
|
|
|
for ( ; i < l; i++ ) {
|
|
elem = elems[ i ];
|
|
|
|
if ( elem || elem === 0 ) {
|
|
|
|
// Add nodes directly
|
|
if ( jQuery.type( elem ) === "object" ) {
|
|
jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
|
|
|
|
// Convert non-html into a text node
|
|
} else if ( !rhtml.test( elem ) ) {
|
|
nodes.push( context.createTextNode( elem ) );
|
|
|
|
// Convert html into DOM nodes
|
|
} else {
|
|
tmp = tmp || safe.appendChild( context.createElement( "div" ) );
|
|
|
|
// Deserialize a standard representation
|
|
tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
|
|
wrap = wrapMap[ tag ] || wrapMap._default;
|
|
|
|
tmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ];
|
|
|
|
// Descend through wrappers to the right content
|
|
j = wrap[ 0 ];
|
|
while ( j-- ) {
|
|
tmp = tmp.lastChild;
|
|
}
|
|
|
|
// Manually add leading whitespace removed by IE
|
|
if ( !support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
|
|
nodes.push( context.createTextNode( rleadingWhitespace.exec( elem )[ 0 ] ) );
|
|
}
|
|
|
|
// Remove IE's autoinserted <tbody> from table fragments
|
|
if ( !support.tbody ) {
|
|
|
|
// String was a <table>, *may* have spurious <tbody>
|
|
elem = tag === "table" && !rtbody.test( elem ) ?
|
|
tmp.firstChild :
|
|
|
|
// String was a bare <thead> or <tfoot>
|
|
wrap[ 1 ] === "<table>" && !rtbody.test( elem ) ?
|
|
tmp :
|
|
0;
|
|
|
|
j = elem && elem.childNodes.length;
|
|
while ( j-- ) {
|
|
if ( jQuery.nodeName( ( tbody = elem.childNodes[ j ] ), "tbody" ) &&
|
|
!tbody.childNodes.length ) {
|
|
|
|
elem.removeChild( tbody );
|
|
}
|
|
}
|
|
}
|
|
|
|
jQuery.merge( nodes, tmp.childNodes );
|
|
|
|
// Fix #12392 for WebKit and IE > 9
|
|
tmp.textContent = "";
|
|
|
|
// Fix #12392 for oldIE
|
|
while ( tmp.firstChild ) {
|
|
tmp.removeChild( tmp.firstChild );
|
|
}
|
|
|
|
// Remember the top-level container for proper cleanup
|
|
tmp = safe.lastChild;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fix #11356: Clear elements from fragment
|
|
if ( tmp ) {
|
|
safe.removeChild( tmp );
|
|
}
|
|
|
|
// Reset defaultChecked for any radios and checkboxes
|
|
// about to be appended to the DOM in IE 6/7 (#8060)
|
|
if ( !support.appendChecked ) {
|
|
jQuery.grep( getAll( nodes, "input" ), fixDefaultChecked );
|
|
}
|
|
|
|
i = 0;
|
|
while ( ( elem = nodes[ i++ ] ) ) {
|
|
|
|
// Skip elements already in the context collection (trac-4087)
|
|
if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
|
|
if ( ignored ) {
|
|
ignored.push( elem );
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
contains = jQuery.contains( elem.ownerDocument, elem );
|
|
|
|
// Append to fragment
|
|
tmp = getAll( safe.appendChild( elem ), "script" );
|
|
|
|
// Preserve script evaluation history
|
|
if ( contains ) {
|
|
setGlobalEval( tmp );
|
|
}
|
|
|
|
// Capture executables
|
|
if ( scripts ) {
|
|
j = 0;
|
|
while ( ( elem = tmp[ j++ ] ) ) {
|
|
if ( rscriptType.test( elem.type || "" ) ) {
|
|
scripts.push( elem );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
tmp = null;
|
|
|
|
return safe;
|
|
}
|
|
|
|
|
|
( function() {
|
|
var i, eventName,
|
|
div = document.createElement( "div" );
|
|
|
|
// Support: IE<9 (lack submit/change bubble), Firefox (lack focus(in | out) events)
|
|
for ( i in { submit: true, change: true, focusin: true } ) {
|
|
eventName = "on" + i;
|
|
|
|
if ( !( support[ i ] = eventName in window ) ) {
|
|
|
|
// Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP)
|
|
div.setAttribute( eventName, "t" );
|
|
support[ i ] = div.attributes[ eventName ].expando === false;
|
|
}
|
|
}
|
|
|
|
// Null elements to avoid leaks in IE.
|
|
div = null;
|
|
} )();
|
|
|
|
|
|
var rformElems = /^(?:input|select|textarea)$/i,
|
|
rkeyEvent = /^key/,
|
|
rmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/,
|
|
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
|
|
rtypenamespace = /^([^.]*)(?:\.(.+)|)/;
|
|
|
|
function returnTrue() {
|
|
return true;
|
|
}
|
|
|
|
function returnFalse() {
|
|
return false;
|
|
}
|
|
|
|
// Support: IE9
|
|
// See #13393 for more info
|
|
function safeActiveElement() {
|
|
try {
|
|
return document.activeElement;
|
|
} catch ( err ) { }
|
|
}
|
|
|
|
function on( elem, types, selector, data, fn, one ) {
|
|
var origFn, type;
|
|
|
|
// Types can be a map of types/handlers
|
|
if ( typeof types === "object" ) {
|
|
|
|
// ( types-Object, selector, data )
|
|
if ( typeof selector !== "string" ) {
|
|
|
|
// ( types-Object, data )
|
|
data = data || selector;
|
|
selector = undefined;
|
|
}
|
|
for ( type in types ) {
|
|
on( elem, type, selector, data, types[ type ], one );
|
|
}
|
|
return elem;
|
|
}
|
|
|
|
if ( data == null && fn == null ) {
|
|
|
|
// ( types, fn )
|
|
fn = selector;
|
|
data = selector = undefined;
|
|
} else if ( fn == null ) {
|
|
if ( typeof selector === "string" ) {
|
|
|
|
// ( types, selector, fn )
|
|
fn = data;
|
|
data = undefined;
|
|
} else {
|
|
|
|
// ( types, data, fn )
|
|
fn = data;
|
|
data = selector;
|
|
selector = undefined;
|
|
}
|
|
}
|
|
if ( fn === false ) {
|
|
fn = returnFalse;
|
|
} else if ( !fn ) {
|
|
return elem;
|
|
}
|
|
|
|
if ( one === 1 ) {
|
|
origFn = fn;
|
|
fn = function( event ) {
|
|
|
|
// Can use an empty set, since event contains the info
|
|
jQuery().off( event );
|
|
return origFn.apply( this, arguments );
|
|
};
|
|
|
|
// Use same guid so caller can remove using origFn
|
|
fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
|
|
}
|
|
return elem.each( function() {
|
|
jQuery.event.add( this, types, fn, data, selector );
|
|
} );
|
|
}
|
|
|
|
/*
|
|
* Helper functions for managing events -- not part of the public interface.
|
|
* Props to Dean Edwards' addEvent library for many of the ideas.
|
|
*/
|
|
jQuery.event = {
|
|
|
|
global: {},
|
|
|
|
add: function( elem, types, handler, data, selector ) {
|
|
var tmp, events, t, handleObjIn,
|
|
special, eventHandle, handleObj,
|
|
handlers, type, namespaces, origType,
|
|
elemData = jQuery._data( elem );
|
|
|
|
// Don't attach events to noData or text/comment nodes (but allow plain objects)
|
|
if ( !elemData ) {
|
|
return;
|
|
}
|
|
|
|
// Caller can pass in an object of custom data in lieu of the handler
|
|
if ( handler.handler ) {
|
|
handleObjIn = handler;
|
|
handler = handleObjIn.handler;
|
|
selector = handleObjIn.selector;
|
|
}
|
|
|
|
// Make sure that the handler has a unique ID, used to find/remove it later
|
|
if ( !handler.guid ) {
|
|
handler.guid = jQuery.guid++;
|
|
}
|
|
|
|
// Init the element's event structure and main handler, if this is the first
|
|
if ( !( events = elemData.events ) ) {
|
|
events = elemData.events = {};
|
|
}
|
|
if ( !( eventHandle = elemData.handle ) ) {
|
|
eventHandle = elemData.handle = function( e ) {
|
|
|
|
// Discard the second event of a jQuery.event.trigger() and
|
|
// when an event is called after a page has unloaded
|
|
return typeof jQuery !== "undefined" &&
|
|
( !e || jQuery.event.triggered !== e.type ) ?
|
|
jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :
|
|
undefined;
|
|
};
|
|
|
|
// Add elem as a property of the handle fn to prevent a memory leak
|
|
// with IE non-native events
|
|
eventHandle.elem = elem;
|
|
}
|
|
|
|
// Handle multiple events separated by a space
|
|
types = ( types || "" ).match( rnotwhite ) || [ "" ];
|
|
t = types.length;
|
|
while ( t-- ) {
|
|
tmp = rtypenamespace.exec( types[ t ] ) || [];
|
|
type = origType = tmp[ 1 ];
|
|
namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
|
|
|
|
// There *must* be a type, no attaching namespace-only handlers
|
|
if ( !type ) {
|
|
continue;
|
|
}
|
|
|
|
// If event changes its type, use the special event handlers for the changed type
|
|
special = jQuery.event.special[ type ] || {};
|
|
|
|
// If selector defined, determine special event api type, otherwise given type
|
|
type = ( selector ? special.delegateType : special.bindType ) || type;
|
|
|
|
// Update special based on newly reset type
|
|
special = jQuery.event.special[ type ] || {};
|
|
|
|
// handleObj is passed to all event handlers
|
|
handleObj = jQuery.extend( {
|
|
type: type,
|
|
origType: origType,
|
|
data: data,
|
|
handler: handler,
|
|
guid: handler.guid,
|
|
selector: selector,
|
|
needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
|
|
namespace: namespaces.join( "." )
|
|
}, handleObjIn );
|
|
|
|
// Init the event handler queue if we're the first
|
|
if ( !( handlers = events[ type ] ) ) {
|
|
handlers = events[ type ] = [];
|
|
handlers.delegateCount = 0;
|
|
|
|
// Only use addEventListener/attachEvent if the special events handler returns false
|
|
if ( !special.setup ||
|
|
special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
|
|
|
|
// Bind the global event handler to the element
|
|
if ( elem.addEventListener ) {
|
|
elem.addEventListener( type, eventHandle, false );
|
|
|
|
} else if ( elem.attachEvent ) {
|
|
elem.attachEvent( "on" + type, eventHandle );
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( special.add ) {
|
|
special.add.call( elem, handleObj );
|
|
|
|
if ( !handleObj.handler.guid ) {
|
|
handleObj.handler.guid = handler.guid;
|
|
}
|
|
}
|
|
|
|
// Add to the element's handler list, delegates in front
|
|
if ( selector ) {
|
|
handlers.splice( handlers.delegateCount++, 0, handleObj );
|
|
} else {
|
|
handlers.push( handleObj );
|
|
}
|
|
|
|
// Keep track of which events have ever been used, for event optimization
|
|
jQuery.event.global[ type ] = true;
|
|
}
|
|
|
|
// Nullify elem to prevent memory leaks in IE
|
|
elem = null;
|
|
},
|
|
|
|
// Detach an event or set of events from an element
|
|
remove: function( elem, types, handler, selector, mappedTypes ) {
|
|
var j, handleObj, tmp,
|
|
origCount, t, events,
|
|
special, handlers, type,
|
|
namespaces, origType,
|
|
elemData = jQuery.hasData( elem ) && jQuery._data( elem );
|
|
|
|
if ( !elemData || !( events = elemData.events ) ) {
|
|
return;
|
|
}
|
|
|
|
// Once for each type.namespace in types; type may be omitted
|
|
types = ( types || "" ).match( rnotwhite ) || [ "" ];
|
|
t = types.length;
|
|
while ( t-- ) {
|
|
tmp = rtypenamespace.exec( types[ t ] ) || [];
|
|
type = origType = tmp[ 1 ];
|
|
namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
|
|
|
|
// Unbind all events (on this namespace, if provided) for the element
|
|
if ( !type ) {
|
|
for ( type in events ) {
|
|
jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
|
|
}
|
|
continue;
|
|
}
|
|
|
|
special = jQuery.event.special[ type ] || {};
|
|
type = ( selector ? special.delegateType : special.bindType ) || type;
|
|
handlers = events[ type ] || [];
|
|
tmp = tmp[ 2 ] &&
|
|
new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" );
|
|
|
|
// Remove matching events
|
|
origCount = j = handlers.length;
|
|
while ( j-- ) {
|
|
handleObj = handlers[ j ];
|
|
|
|
if ( ( mappedTypes || origType === handleObj.origType ) &&
|
|
( !handler || handler.guid === handleObj.guid ) &&
|
|
( !tmp || tmp.test( handleObj.namespace ) ) &&
|
|
( !selector || selector === handleObj.selector ||
|
|
selector === "**" && handleObj.selector ) ) {
|
|
handlers.splice( j, 1 );
|
|
|
|
if ( handleObj.selector ) {
|
|
handlers.delegateCount--;
|
|
}
|
|
if ( special.remove ) {
|
|
special.remove.call( elem, handleObj );
|
|
}
|
|
}
|
|
}
|
|
|
|
// Remove generic event handler if we removed something and no more handlers exist
|
|
// (avoids potential for endless recursion during removal of special event handlers)
|
|
if ( origCount && !handlers.length ) {
|
|
if ( !special.teardown ||
|
|
special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
|
|
|
|
jQuery.removeEvent( elem, type, elemData.handle );
|
|
}
|
|
|
|
delete events[ type ];
|
|
}
|
|
}
|
|
|
|
// Remove the expando if it's no longer used
|
|
if ( jQuery.isEmptyObject( events ) ) {
|
|
delete elemData.handle;
|
|
|
|
// removeData also checks for emptiness and clears the expando if empty
|
|
// so use it instead of delete
|
|
jQuery._removeData( elem, "events" );
|
|
}
|
|
},
|
|
|
|
trigger: function( event, data, elem, onlyHandlers ) {
|
|
var handle, ontype, cur,
|
|
bubbleType, special, tmp, i,
|
|
eventPath = [ elem || document ],
|
|
type = hasOwn.call( event, "type" ) ? event.type : event,
|
|
namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split( "." ) : [];
|
|
|
|
cur = tmp = elem = elem || document;
|
|
|
|
// Don't do events on text and comment nodes
|
|
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
|
|
return;
|
|
}
|
|
|
|
// focus/blur morphs to focusin/out; ensure we're not firing them right now
|
|
if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( type.indexOf( "." ) > -1 ) {
|
|
|
|
// Namespaced trigger; create a regexp to match event type in handle()
|
|
namespaces = type.split( "." );
|
|
type = namespaces.shift();
|
|
namespaces.sort();
|
|
}
|
|
ontype = type.indexOf( ":" ) < 0 && "on" + type;
|
|
|
|
// Caller can pass in a jQuery.Event object, Object, or just an event type string
|
|
event = event[ jQuery.expando ] ?
|
|
event :
|
|
new jQuery.Event( type, typeof event === "object" && event );
|
|
|
|
// Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
|
|
event.isTrigger = onlyHandlers ? 2 : 3;
|
|
event.namespace = namespaces.join( "." );
|
|
event.rnamespace = event.namespace ?
|
|
new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ) :
|
|
null;
|
|
|
|
// Clean up the event in case it is being reused
|
|
event.result = undefined;
|
|
if ( !event.target ) {
|
|
event.target = elem;
|
|
}
|
|
|
|
// Clone any incoming data and prepend the event, creating the handler arg list
|
|
data = data == null ?
|
|
[ event ] :
|
|
jQuery.makeArray( data, [ event ] );
|
|
|
|
// Allow special events to draw outside the lines
|
|
special = jQuery.event.special[ type ] || {};
|
|
if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
|
|
return;
|
|
}
|
|
|
|
// Determine event propagation path in advance, per W3C events spec (#9951)
|
|
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
|
|
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
|
|
|
|
bubbleType = special.delegateType || type;
|
|
if ( !rfocusMorph.test( bubbleType + type ) ) {
|
|
cur = cur.parentNode;
|
|
}
|
|
for ( ; cur; cur = cur.parentNode ) {
|
|
eventPath.push( cur );
|
|
tmp = cur;
|
|
}
|
|
|
|
// Only add window if we got to document (e.g., not plain obj or detached DOM)
|
|
if ( tmp === ( elem.ownerDocument || document ) ) {
|
|
eventPath.push( tmp.defaultView || tmp.parentWindow || window );
|
|
}
|
|
}
|
|
|
|
// Fire handlers on the event path
|
|
i = 0;
|
|
while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) {
|
|
|
|
event.type = i > 1 ?
|
|
bubbleType :
|
|
special.bindType || type;
|
|
|
|
// jQuery handler
|
|
handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] &&
|
|
jQuery._data( cur, "handle" );
|
|
|
|
if ( handle ) {
|
|
handle.apply( cur, data );
|
|
}
|
|
|
|
// Native handler
|
|
handle = ontype && cur[ ontype ];
|
|
if ( handle && handle.apply && acceptData( cur ) ) {
|
|
event.result = handle.apply( cur, data );
|
|
if ( event.result === false ) {
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
}
|
|
event.type = type;
|
|
|
|
// If nobody prevented the default action, do it now
|
|
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
|
|
|
|
if (
|
|
( !special._default ||
|
|
special._default.apply( eventPath.pop(), data ) === false
|
|
) && acceptData( elem )
|
|
) {
|
|
|
|
// Call a native DOM method on the target with the same name name as the event.
|
|
// Can't use an .isFunction() check here because IE6/7 fails that test.
|
|
// Don't do default actions on window, that's where global variables be (#6170)
|
|
if ( ontype && elem[ type ] && !jQuery.isWindow( elem ) ) {
|
|
|
|
// Don't re-trigger an onFOO event when we call its FOO() method
|
|
tmp = elem[ ontype ];
|
|
|
|
if ( tmp ) {
|
|
elem[ ontype ] = null;
|
|
}
|
|
|
|
// Prevent re-triggering of the same event, since we already bubbled it above
|
|
jQuery.event.triggered = type;
|
|
try {
|
|
elem[ type ]();
|
|
} catch ( e ) {
|
|
|
|
// IE<9 dies on focus/blur to hidden element (#1486,#12518)
|
|
// only reproducible on winXP IE8 native, not IE9 in IE8 mode
|
|
}
|
|
jQuery.event.triggered = undefined;
|
|
|
|
if ( tmp ) {
|
|
elem[ ontype ] = tmp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return event.result;
|
|
},
|
|
|
|
dispatch: function( event ) {
|
|
|
|
// Make a writable jQuery.Event from the native event object
|
|
event = jQuery.event.fix( event );
|
|
|
|
var i, j, ret, matched, handleObj,
|
|
handlerQueue = [],
|
|
args = slice.call( arguments ),
|
|
handlers = ( jQuery._data( this, "events" ) || {} )[ event.type ] || [],
|
|
special = jQuery.event.special[ event.type ] || {};
|
|
|
|
// Use the fix-ed jQuery.Event rather than the (read-only) native event
|
|
args[ 0 ] = event;
|
|
event.delegateTarget = this;
|
|
|
|
// Call the preDispatch hook for the mapped type, and let it bail if desired
|
|
if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
|
|
return;
|
|
}
|
|
|
|
// Determine handlers
|
|
handlerQueue = jQuery.event.handlers.call( this, event, handlers );
|
|
|
|
// Run delegates first; they may want to stop propagation beneath us
|
|
i = 0;
|
|
while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) {
|
|
event.currentTarget = matched.elem;
|
|
|
|
j = 0;
|
|
while ( ( handleObj = matched.handlers[ j++ ] ) &&
|
|
!event.isImmediatePropagationStopped() ) {
|
|
|
|
// Triggered event must either 1) have no namespace, or 2) have namespace(s)
|
|
// a subset or equal to those in the bound event (both can have no namespace).
|
|
if ( !event.rnamespace || event.rnamespace.test( handleObj.namespace ) ) {
|
|
|
|
event.handleObj = handleObj;
|
|
event.data = handleObj.data;
|
|
|
|
ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle ||
|
|
handleObj.handler ).apply( matched.elem, args );
|
|
|
|
if ( ret !== undefined ) {
|
|
if ( ( event.result = ret ) === false ) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Call the postDispatch hook for the mapped type
|
|
if ( special.postDispatch ) {
|
|
special.postDispatch.call( this, event );
|
|
}
|
|
|
|
return event.result;
|
|
},
|
|
|
|
handlers: function( event, handlers ) {
|
|
var i, matches, sel, handleObj,
|
|
handlerQueue = [],
|
|
delegateCount = handlers.delegateCount,
|
|
cur = event.target;
|
|
|
|
// Support (at least): Chrome, IE9
|
|
// Find delegate handlers
|
|
// Black-hole SVG <use> instance trees (#13180)
|
|
//
|
|
// Support: Firefox<=42+
|
|
// Avoid non-left-click in FF but don't block IE radio events (#3861, gh-2343)
|
|
if ( delegateCount && cur.nodeType &&
|
|
( event.type !== "click" || isNaN( event.button ) || event.button < 1 ) ) {
|
|
|
|
/* jshint eqeqeq: false */
|
|
for ( ; cur != this; cur = cur.parentNode || this ) {
|
|
/* jshint eqeqeq: true */
|
|
|
|
// Don't check non-elements (#13208)
|
|
// Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
|
|
if ( cur.nodeType === 1 && ( cur.disabled !== true || event.type !== "click" ) ) {
|
|
matches = [];
|
|
for ( i = 0; i < delegateCount; i++ ) {
|
|
handleObj = handlers[ i ];
|
|
|
|
// Don't conflict with Object.prototype properties (#13203)
|
|
sel = handleObj.selector + " ";
|
|
|
|
if ( matches[ sel ] === undefined ) {
|
|
matches[ sel ] = handleObj.needsContext ?
|
|
jQuery( sel, this ).index( cur ) > -1 :
|
|
jQuery.find( sel, this, null, [ cur ] ).length;
|
|
}
|
|
if ( matches[ sel ] ) {
|
|
matches.push( handleObj );
|
|
}
|
|
}
|
|
if ( matches.length ) {
|
|
handlerQueue.push( { elem: cur, handlers: matches } );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add the remaining (directly-bound) handlers
|
|
if ( delegateCount < handlers.length ) {
|
|
handlerQueue.push( { elem: this, handlers: handlers.slice( delegateCount ) } );
|
|
}
|
|
|
|
return handlerQueue;
|
|
},
|
|
|
|
fix: function( event ) {
|
|
if ( event[ jQuery.expando ] ) {
|
|
return event;
|
|
}
|
|
|
|
// Create a writable copy of the event object and normalize some properties
|
|
var i, prop, copy,
|
|
type = event.type,
|
|
originalEvent = event,
|
|
fixHook = this.fixHooks[ type ];
|
|
|
|
if ( !fixHook ) {
|
|
this.fixHooks[ type ] = fixHook =
|
|
rmouseEvent.test( type ) ? this.mouseHooks :
|
|
rkeyEvent.test( type ) ? this.keyHooks :
|
|
{};
|
|
}
|
|
copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
|
|
|
|
event = new jQuery.Event( originalEvent );
|
|
|
|
i = copy.length;
|
|
while ( i-- ) {
|
|
prop = copy[ i ];
|
|
event[ prop ] = originalEvent[ prop ];
|
|
}
|
|
|
|
// Support: IE<9
|
|
// Fix target property (#1925)
|
|
if ( !event.target ) {
|
|
event.target = originalEvent.srcElement || document;
|
|
}
|
|
|
|
// Support: Safari 6-8+
|
|
// Target should not be a text node (#504, #13143)
|
|
if ( event.target.nodeType === 3 ) {
|
|
event.target = event.target.parentNode;
|
|
}
|
|
|
|
// Support: IE<9
|
|
// For mouse/key events, metaKey==false if it's undefined (#3368, #11328)
|
|
event.metaKey = !!event.metaKey;
|
|
|
|
return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
|
|
},
|
|
|
|
// Includes some event props shared by KeyEvent and MouseEvent
|
|
props: ( "altKey bubbles cancelable ctrlKey currentTarget detail eventPhase " +
|
|
"metaKey relatedTarget shiftKey target timeStamp view which" ).split( " " ),
|
|
|
|
fixHooks: {},
|
|
|
|
keyHooks: {
|
|
props: "char charCode key keyCode".split( " " ),
|
|
filter: function( event, original ) {
|
|
|
|
// Add which for key events
|
|
if ( event.which == null ) {
|
|
event.which = original.charCode != null ? original.charCode : original.keyCode;
|
|
}
|
|
|
|
return event;
|
|
}
|
|
},
|
|
|
|
mouseHooks: {
|
|
props: ( "button buttons clientX clientY fromElement offsetX offsetY " +
|
|
"pageX pageY screenX screenY toElement" ).split( " " ),
|
|
filter: function( event, original ) {
|
|
var body, eventDoc, doc,
|
|
button = original.button,
|
|
fromElement = original.fromElement;
|
|
|
|
// Calculate pageX/Y if missing and clientX/Y available
|
|
if ( event.pageX == null && original.clientX != null ) {
|
|
eventDoc = event.target.ownerDocument || document;
|
|
doc = eventDoc.documentElement;
|
|
body = eventDoc.body;
|
|
|
|
event.pageX = original.clientX +
|
|
( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
|
|
( doc && doc.clientLeft || body && body.clientLeft || 0 );
|
|
event.pageY = original.clientY +
|
|
( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
|
|
( doc && doc.clientTop || body && body.clientTop || 0 );
|
|
}
|
|
|
|
// Add relatedTarget, if necessary
|
|
if ( !event.relatedTarget && fromElement ) {
|
|
event.relatedTarget = fromElement === event.target ?
|
|
original.toElement :
|
|
fromElement;
|
|
}
|
|
|
|
// Add which for click: 1 === left; 2 === middle; 3 === right
|
|
// Note: button is not normalized, so don't use it
|
|
if ( !event.which && button !== undefined ) {
|
|
event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
|
|
}
|
|
|
|
return event;
|
|
}
|
|
},
|
|
|
|
special: {
|
|
load: {
|
|
|
|
// Prevent triggered image.load events from bubbling to window.load
|
|
noBubble: true
|
|
},
|
|
focus: {
|
|
|
|
// Fire native event if possible so blur/focus sequence is correct
|
|
trigger: function() {
|
|
if ( this !== safeActiveElement() && this.focus ) {
|
|
try {
|
|
this.focus();
|
|
return false;
|
|
} catch ( e ) {
|
|
|
|
// Support: IE<9
|
|
// If we error on focus to hidden element (#1486, #12518),
|
|
// let .trigger() run the handlers
|
|
}
|
|
}
|
|
},
|
|
delegateType: "focusin"
|
|
},
|
|
blur: {
|
|
trigger: function() {
|
|
if ( this === safeActiveElement() && this.blur ) {
|
|
this.blur();
|
|
return false;
|
|
}
|
|
},
|
|
delegateType: "focusout"
|
|
},
|
|
click: {
|
|
|
|
// For checkbox, fire native event so checked state will be right
|
|
trigger: function() {
|
|
if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) {
|
|
this.click();
|
|
return false;
|
|
}
|
|
},
|
|
|
|
// For cross-browser consistency, don't fire native .click() on links
|
|
_default: function( event ) {
|
|
return jQuery.nodeName( event.target, "a" );
|
|
}
|
|
},
|
|
|
|
beforeunload: {
|
|
postDispatch: function( event ) {
|
|
|
|
// Support: Firefox 20+
|
|
// Firefox doesn't alert if the returnValue field is not set.
|
|
if ( event.result !== undefined && event.originalEvent ) {
|
|
event.originalEvent.returnValue = event.result;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
// Piggyback on a donor event to simulate a different one
|
|
simulate: function( type, elem, event ) {
|
|
var e = jQuery.extend(
|
|
new jQuery.Event(),
|
|
event,
|
|
{
|
|
type: type,
|
|
isSimulated: true
|
|
|
|
// Previously, `originalEvent: {}` was set here, so stopPropagation call
|
|
// would not be triggered on donor event, since in our own
|
|
// jQuery.event.stopPropagation function we had a check for existence of
|
|
// originalEvent.stopPropagation method, so, consequently it would be a noop.
|
|
//
|
|
// Guard for simulated events was moved to jQuery.event.stopPropagation function
|
|
// since `originalEvent` should point to the original event for the
|
|
// constancy with other events and for more focused logic
|
|
}
|
|
);
|
|
|
|
jQuery.event.trigger( e, null, elem );
|
|
|
|
if ( e.isDefaultPrevented() ) {
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
};
|
|
|
|
jQuery.removeEvent = document.removeEventListener ?
|
|
function( elem, type, handle ) {
|
|
|
|
// This "if" is needed for plain objects
|
|
if ( elem.removeEventListener ) {
|
|
elem.removeEventListener( type, handle );
|
|
}
|
|
} :
|
|
function( elem, type, handle ) {
|
|
var name = "on" + type;
|
|
|
|
if ( elem.detachEvent ) {
|
|
|
|
// #8545, #7054, preventing memory leaks for custom events in IE6-8
|
|
// detachEvent needed property on element, by name of that event,
|
|
// to properly expose it to GC
|
|
if ( typeof elem[ name ] === "undefined" ) {
|
|
elem[ name ] = null;
|
|
}
|
|
|
|
elem.detachEvent( name, handle );
|
|
}
|
|
};
|
|
|
|
jQuery.Event = function( src, props ) {
|
|
|
|
// Allow instantiation without the 'new' keyword
|
|
if ( !( this instanceof jQuery.Event ) ) {
|
|
return new jQuery.Event( src, props );
|
|
}
|
|
|
|
// Event object
|
|
if ( src && src.type ) {
|
|
this.originalEvent = src;
|
|
this.type = src.type;
|
|
|
|
// Events bubbling up the document may have been marked as prevented
|
|
// by a handler lower down the tree; reflect the correct value.
|
|
this.isDefaultPrevented = src.defaultPrevented ||
|
|
src.defaultPrevented === undefined &&
|
|
|
|
// Support: IE < 9, Android < 4.0
|
|
src.returnValue === false ?
|
|
returnTrue :
|
|
returnFalse;
|
|
|
|
// Event type
|
|
} else {
|
|
this.type = src;
|
|
}
|
|
|
|
// Put explicitly provided properties onto the event object
|
|
if ( props ) {
|
|
jQuery.extend( this, props );
|
|
}
|
|
|
|
// Create a timestamp if incoming event doesn't have one
|
|
this.timeStamp = src && src.timeStamp || jQuery.now();
|
|
|
|
// Mark it as fixed
|
|
this[ jQuery.expando ] = true;
|
|
};
|
|
|
|
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
|
|
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
|
|
jQuery.Event.prototype = {
|
|
constructor: jQuery.Event,
|
|
isDefaultPrevented: returnFalse,
|
|
isPropagationStopped: returnFalse,
|
|
isImmediatePropagationStopped: returnFalse,
|
|
|
|
preventDefault: function() {
|
|
var e = this.originalEvent;
|
|
|
|
this.isDefaultPrevented = returnTrue;
|
|
if ( !e ) {
|
|
return;
|
|
}
|
|
|
|
// If preventDefault exists, run it on the original event
|
|
if ( e.preventDefault ) {
|
|
e.preventDefault();
|
|
|
|
// Support: IE
|
|
// Otherwise set the returnValue property of the original event to false
|
|
} else {
|
|
e.returnValue = false;
|
|
}
|
|
},
|
|
stopPropagation: function() {
|
|
var e = this.originalEvent;
|
|
|
|
this.isPropagationStopped = returnTrue;
|
|
|
|
if ( !e || this.isSimulated ) {
|
|
return;
|
|
}
|
|
|
|
// If stopPropagation exists, run it on the original event
|
|
if ( e.stopPropagation ) {
|
|
e.stopPropagation();
|
|
}
|
|
|
|
// Support: IE
|
|
// Set the cancelBubble property of the original event to true
|
|
e.cancelBubble = true;
|
|
},
|
|
stopImmediatePropagation: function() {
|
|
var e = this.originalEvent;
|
|
|
|
this.isImmediatePropagationStopped = returnTrue;
|
|
|
|
if ( e && e.stopImmediatePropagation ) {
|
|
e.stopImmediatePropagation();
|
|
}
|
|
|
|
this.stopPropagation();
|
|
}
|
|
};
|
|
|
|
// Create mouseenter/leave events using mouseover/out and event-time checks
|
|
// so that event delegation works in jQuery.
|
|
// Do the same for pointerenter/pointerleave and pointerover/pointerout
|
|
//
|
|
// Support: Safari 7 only
|
|
// Safari sends mouseenter too often; see:
|
|
// https://code.google.com/p/chromium/issues/detail?id=470258
|
|
// for the description of the bug (it existed in older Chrome versions as well).
|
|
jQuery.each( {
|
|
mouseenter: "mouseover",
|
|
mouseleave: "mouseout",
|
|
pointerenter: "pointerover",
|
|
pointerleave: "pointerout"
|
|
}, function( orig, fix ) {
|
|
jQuery.event.special[ orig ] = {
|
|
delegateType: fix,
|
|
bindType: fix,
|
|
|
|
handle: function( event ) {
|
|
var ret,
|
|
target = this,
|
|
related = event.relatedTarget,
|
|
handleObj = event.handleObj;
|
|
|
|
// For mouseenter/leave call the handler if related is outside the target.
|
|
// NB: No relatedTarget if the mouse left/entered the browser window
|
|
if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) {
|
|
event.type = handleObj.origType;
|
|
ret = handleObj.handler.apply( this, arguments );
|
|
event.type = fix;
|
|
}
|
|
return ret;
|
|
}
|
|
};
|
|
} );
|
|
|
|
// IE submit delegation
|
|
if ( !support.submit ) {
|
|
|
|
jQuery.event.special.submit = {
|
|
setup: function() {
|
|
|
|
// Only need this for delegated form submit events
|
|
if ( jQuery.nodeName( this, "form" ) ) {
|
|
return false;
|
|
}
|
|
|
|
// Lazy-add a submit handler when a descendant form may potentially be submitted
|
|
jQuery.event.add( this, "click._submit keypress._submit", function( e ) {
|
|
|
|
// Node name check avoids a VML-related crash in IE (#9807)
|
|
var elem = e.target,
|
|
form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ?
|
|
|
|
// Support: IE <=8
|
|
// We use jQuery.prop instead of elem.form
|
|
// to allow fixing the IE8 delegated submit issue (gh-2332)
|
|
// by 3rd party polyfills/workarounds.
|
|
jQuery.prop( elem, "form" ) :
|
|
undefined;
|
|
|
|
if ( form && !jQuery._data( form, "submit" ) ) {
|
|
jQuery.event.add( form, "submit._submit", function( event ) {
|
|
event._submitBubble = true;
|
|
} );
|
|
jQuery._data( form, "submit", true );
|
|
}
|
|
} );
|
|
|
|
// return undefined since we don't need an event listener
|
|
},
|
|
|
|
postDispatch: function( event ) {
|
|
|
|
// If form was submitted by the user, bubble the event up the tree
|
|
if ( event._submitBubble ) {
|
|
delete event._submitBubble;
|
|
if ( this.parentNode && !event.isTrigger ) {
|
|
jQuery.event.simulate( "submit", this.parentNode, event );
|
|
}
|
|
}
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
// Only need this for delegated form submit events
|
|
if ( jQuery.nodeName( this, "form" ) ) {
|
|
return false;
|
|
}
|
|
|
|
// Remove delegated handlers; cleanData eventually reaps submit handlers attached above
|
|
jQuery.event.remove( this, "._submit" );
|
|
}
|
|
};
|
|
}
|
|
|
|
// IE change delegation and checkbox/radio fix
|
|
if ( !support.change ) {
|
|
|
|
jQuery.event.special.change = {
|
|
|
|
setup: function() {
|
|
|
|
if ( rformElems.test( this.nodeName ) ) {
|
|
|
|
// IE doesn't fire change on a check/radio until blur; trigger it on click
|
|
// after a propertychange. Eat the blur-change in special.change.handle.
|
|
// This still fires onchange a second time for check/radio after blur.
|
|
if ( this.type === "checkbox" || this.type === "radio" ) {
|
|
jQuery.event.add( this, "propertychange._change", function( event ) {
|
|
if ( event.originalEvent.propertyName === "checked" ) {
|
|
this._justChanged = true;
|
|
}
|
|
} );
|
|
jQuery.event.add( this, "click._change", function( event ) {
|
|
if ( this._justChanged && !event.isTrigger ) {
|
|
this._justChanged = false;
|
|
}
|
|
|
|
// Allow triggered, simulated change events (#11500)
|
|
jQuery.event.simulate( "change", this, event );
|
|
} );
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Delegated event; lazy-add a change handler on descendant inputs
|
|
jQuery.event.add( this, "beforeactivate._change", function( e ) {
|
|
var elem = e.target;
|
|
|
|
if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "change" ) ) {
|
|
jQuery.event.add( elem, "change._change", function( event ) {
|
|
if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
|
|
jQuery.event.simulate( "change", this.parentNode, event );
|
|
}
|
|
} );
|
|
jQuery._data( elem, "change", true );
|
|
}
|
|
} );
|
|
},
|
|
|
|
handle: function( event ) {
|
|
var elem = event.target;
|
|
|
|
// Swallow native change events from checkbox/radio, we already triggered them above
|
|
if ( this !== elem || event.isSimulated || event.isTrigger ||
|
|
( elem.type !== "radio" && elem.type !== "checkbox" ) ) {
|
|
|
|
return event.handleObj.handler.apply( this, arguments );
|
|
}
|
|
},
|
|
|
|
teardown: function() {
|
|
jQuery.event.remove( this, "._change" );
|
|
|
|
return !rformElems.test( this.nodeName );
|
|
}
|
|
};
|
|
}
|
|
|
|
// Support: Firefox
|
|
// Firefox doesn't have focus(in | out) events
|
|
// Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787
|
|
//
|
|
// Support: Chrome, Safari
|
|
// focus(in | out) events fire after focus & blur events,
|
|
// which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order
|
|
// Related ticket - https://code.google.com/p/chromium/issues/detail?id=449857
|
|
if ( !support.focusin ) {
|
|
jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) {
|
|
|
|
// Attach a single capturing handler on the document while someone wants focusin/focusout
|
|
var handler = function( event ) {
|
|
jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ) );
|
|
};
|
|
|
|
jQuery.event.special[ fix ] = {
|
|
setup: function() {
|
|
var doc = this.ownerDocument || this,
|
|
attaches = jQuery._data( doc, fix );
|
|
|
|
if ( !attaches ) {
|
|
doc.addEventListener( orig, handler, true );
|
|
}
|
|
jQuery._data( doc, fix, ( attaches || 0 ) + 1 );
|
|
},
|
|
teardown: function() {
|
|
var doc = this.ownerDocument || this,
|
|
attaches = jQuery._data( doc, fix ) - 1;
|
|
|
|
if ( !attaches ) {
|
|
doc.removeEventListener( orig, handler, true );
|
|
jQuery._removeData( doc, fix );
|
|
} else {
|
|
jQuery._data( doc, fix, attaches );
|
|
}
|
|
}
|
|
};
|
|
} );
|
|
}
|
|
|
|
jQuery.fn.extend( {
|
|
|
|
on: function( types, selector, data, fn ) {
|
|
return on( this, types, selector, data, fn );
|
|
},
|
|
one: function( types, selector, data, fn ) {
|
|
return on( this, types, selector, data, fn, 1 );
|
|
},
|
|
off: function( types, selector, fn ) {
|
|
var handleObj, type;
|
|
if ( types && types.preventDefault && types.handleObj ) {
|
|
|
|
// ( event ) dispatched jQuery.Event
|
|
handleObj = types.handleObj;
|
|
jQuery( types.delegateTarget ).off(
|
|
handleObj.namespace ?
|
|
handleObj.origType + "." + handleObj.namespace :
|
|
handleObj.origType,
|
|
handleObj.selector,
|
|
handleObj.handler
|
|
);
|
|
return this;
|
|
}
|
|
if ( typeof types === "object" ) {
|
|
|
|
// ( types-object [, selector] )
|
|
for ( type in types ) {
|
|
this.off( type, selector, types[ type ] );
|
|
}
|
|
return this;
|
|
}
|
|
if ( selector === false || typeof selector === "function" ) {
|
|
|
|
// ( types [, fn] )
|
|
fn = selector;
|
|
selector = undefined;
|
|
}
|
|
if ( fn === false ) {
|
|
fn = returnFalse;
|
|
}
|
|
return this.each( function() {
|
|
jQuery.event.remove( this, types, fn, selector );
|
|
} );
|
|
},
|
|
|
|
trigger: function( type, data ) {
|
|
return this.each( function() {
|
|
jQuery.event.trigger( type, data, this );
|
|
} );
|
|
},
|
|
triggerHandler: function( type, data ) {
|
|
var elem = this[ 0 ];
|
|
if ( elem ) {
|
|
return jQuery.event.trigger( type, data, elem, true );
|
|
}
|
|
}
|
|
} );
|
|
|
|
|
|
var rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g,
|
|
rnoshimcache = new RegExp( "<(?:" + nodeNames + ")[\\s/>]", "i" ),
|
|
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi,
|
|
|
|
// Support: IE 10-11, Edge 10240+
|
|
// In IE/Edge using regex groups here causes severe slowdowns.
|
|
// See https://connect.microsoft.com/IE/feedback/details/1736512/
|
|
rnoInnerhtml = /<script|<style|<link/i,
|
|
|
|
// checked="checked" or checked
|
|
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
|
|
rscriptTypeMasked = /^true\/(.*)/,
|
|
rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
|
|
safeFragment = createSafeFragment( document ),
|
|
fragmentDiv = safeFragment.appendChild( document.createElement( "div" ) );
|
|
|
|
// Support: IE<8
|
|
// Manipulating tables requires a tbody
|
|
function manipulationTarget( elem, content ) {
|
|
return jQuery.nodeName( elem, "table" ) &&
|
|
jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
|
|
|
|
elem.getElementsByTagName( "tbody" )[ 0 ] ||
|
|
elem.appendChild( elem.ownerDocument.createElement( "tbody" ) ) :
|
|
elem;
|
|
}
|
|
|
|
// Replace/restore the type attribute of script elements for safe DOM manipulation
|
|
function disableScript( elem ) {
|
|
elem.type = ( jQuery.find.attr( elem, "type" ) !== null ) + "/" + elem.type;
|
|
return elem;
|
|
}
|
|
function restoreScript( elem ) {
|
|
var match = rscriptTypeMasked.exec( elem.type );
|
|
if ( match ) {
|
|
elem.type = match[ 1 ];
|
|
} else {
|
|
elem.removeAttribute( "type" );
|
|
}
|
|
return elem;
|
|
}
|
|
|
|
function cloneCopyEvent( src, dest ) {
|
|
if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) {
|
|
return;
|
|
}
|
|
|
|
var type, i, l,
|
|
oldData = jQuery._data( src ),
|
|
curData = jQuery._data( dest, oldData ),
|
|
events = oldData.events;
|
|
|
|
if ( events ) {
|
|
delete curData.handle;
|
|
curData.events = {};
|
|
|
|
for ( type in events ) {
|
|
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
|
|
jQuery.event.add( dest, type, events[ type ][ i ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
// make the cloned public data object a copy from the original
|
|
if ( curData.data ) {
|
|
curData.data = jQuery.extend( {}, curData.data );
|
|
}
|
|
}
|
|
|
|
function fixCloneNodeIssues( src, dest ) {
|
|
var nodeName, e, data;
|
|
|
|
// We do not need to do anything for non-Elements
|
|
if ( dest.nodeType !== 1 ) {
|
|
return;
|
|
}
|
|
|
|
nodeName = dest.nodeName.toLowerCase();
|
|
|
|
// IE6-8 copies events bound via attachEvent when using cloneNode.
|
|
if ( !support.noCloneEvent && dest[ jQuery.expando ] ) {
|
|
data = jQuery._data( dest );
|
|
|
|
for ( e in data.events ) {
|
|
jQuery.removeEvent( dest, e, data.handle );
|
|
}
|
|
|
|
// Event data gets referenced instead of copied if the expando gets copied too
|
|
dest.removeAttribute( jQuery.expando );
|
|
}
|
|
|
|
// IE blanks contents when cloning scripts, and tries to evaluate newly-set text
|
|
if ( nodeName === "script" && dest.text !== src.text ) {
|
|
disableScript( dest ).text = src.text;
|
|
restoreScript( dest );
|
|
|
|
// IE6-10 improperly clones children of object elements using classid.
|
|
// IE10 throws NoModificationAllowedError if parent is null, #12132.
|
|
} else if ( nodeName === "object" ) {
|
|
if ( dest.parentNode ) {
|
|
dest.outerHTML = src.outerHTML;
|
|
}
|
|
|
|
// This path appears unavoidable for IE9. When cloning an object
|
|
// element in IE9, the outerHTML strategy above is not sufficient.
|
|
// If the src has innerHTML and the destination does not,
|
|
// copy the src.innerHTML into the dest.innerHTML. #10324
|
|
if ( support.html5Clone && ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) ) {
|
|
dest.innerHTML = src.innerHTML;
|
|
}
|
|
|
|
} else if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
|
|
|
|
// IE6-8 fails to persist the checked state of a cloned checkbox
|
|
// or radio button. Worse, IE6-7 fail to give the cloned element
|
|
// a checked appearance if the defaultChecked value isn't also set
|
|
|
|
dest.defaultChecked = dest.checked = src.checked;
|
|
|
|
// IE6-7 get confused and end up setting the value of a cloned
|
|
// checkbox/radio button to an empty string instead of "on"
|
|
if ( dest.value !== src.value ) {
|
|
dest.value = src.value;
|
|
}
|
|
|
|
// IE6-8 fails to return the selected option to the default selected
|
|
// state when cloning options
|
|
} else if ( nodeName === "option" ) {
|
|
dest.defaultSelected = dest.selected = src.defaultSelected;
|
|
|
|
// IE6-8 fails to set the defaultValue to the correct value when
|
|
// cloning other types of input fields
|
|
} else if ( nodeName === "input" || nodeName === "textarea" ) {
|
|
dest.defaultValue = src.defaultValue;
|
|
}
|
|
}
|
|
|
|
function domManip( collection, args, callback, ignored ) {
|
|
|
|
// Flatten any nested arrays
|
|
args = concat.apply( [], args );
|
|
|
|
var first, node, hasScripts,
|
|
scripts, doc, fragment,
|
|
i = 0,
|
|
l = collection.length,
|
|
iNoClone = l - 1,
|
|
value = args[ 0 ],
|
|
isFunction = jQuery.isFunction( value );
|
|
|
|
// We can't cloneNode fragments that contain checked, in WebKit
|
|
if ( isFunction ||
|
|
( l > 1 && typeof value === "string" &&
|
|
!support.checkClone && rchecked.test( value ) ) ) {
|
|
return collection.each( function( index ) {
|
|
var self = collection.eq( index );
|
|
if ( isFunction ) {
|
|
args[ 0 ] = value.call( this, index, self.html() );
|
|
}
|
|
domManip( self, args, callback, ignored );
|
|
} );
|
|
}
|
|
|
|
if ( l ) {
|
|
fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
|
|
first = fragment.firstChild;
|
|
|
|
if ( fragment.childNodes.length === 1 ) {
|
|
fragment = first;
|
|
}
|
|
|
|
// Require either new content or an interest in ignored elements to invoke the callback
|
|
if ( first || ignored ) {
|
|
scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
|
|
hasScripts = scripts.length;
|
|
|
|
// Use the original fragment for the last item
|
|
// instead of the first because it can end up
|
|
// being emptied incorrectly in certain situations (#8070).
|
|
for ( ; i < l; i++ ) {
|
|
node = fragment;
|
|
|
|
if ( i !== iNoClone ) {
|
|
node = jQuery.clone( node, true, true );
|
|
|
|
// Keep references to cloned scripts for later restoration
|
|
if ( hasScripts ) {
|
|
|
|
// Support: Android<4.1, PhantomJS<2
|
|
// push.apply(_, arraylike) throws on ancient WebKit
|
|
jQuery.merge( scripts, getAll( node, "script" ) );
|
|
}
|
|
}
|
|
|
|
callback.call( collection[ i ], node, i );
|
|
}
|
|
|
|
if ( hasScripts ) {
|
|
doc = scripts[ scripts.length - 1 ].ownerDocument;
|
|
|
|
// Reenable scripts
|
|
jQuery.map( scripts, restoreScript );
|
|
|
|
// Evaluate executable scripts on first document insertion
|
|
for ( i = 0; i < hasScripts; i++ ) {
|
|
node = scripts[ i ];
|
|
if ( rscriptType.test( node.type || "" ) &&
|
|
!jQuery._data( node, "globalEval" ) &&
|
|
jQuery.contains( doc, node ) ) {
|
|
|
|
if ( node.src ) {
|
|
|
|
// Optional AJAX dependency, but won't run scripts if not present
|
|
if ( jQuery._evalUrl ) {
|
|
jQuery._evalUrl( node.src );
|
|
}
|
|
} else {
|
|
jQuery.globalEval(
|
|
( node.text || node.textContent || node.innerHTML || "" )
|
|
.replace( rcleanScript, "" )
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fix #11809: Avoid leaking memory
|
|
fragment = first = null;
|
|
}
|
|
}
|
|
|
|
return collection;
|
|
}
|
|
|
|
function remove( elem, selector, keepData ) {
|
|
var node,
|
|
elems = selector ? jQuery.filter( selector, elem ) : elem,
|
|
i = 0;
|
|
|
|
for ( ; ( node = elems[ i ] ) != null; i++ ) {
|
|
|
|
if ( !keepData && node.nodeType === 1 ) {
|
|
jQuery.cleanData( getAll( node ) );
|
|
}
|
|
|
|
if ( node.parentNode ) {
|
|
if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
|
|
setGlobalEval( getAll( node, "script" ) );
|
|
}
|
|
node.parentNode.removeChild( node );
|
|
}
|
|
}
|
|
|
|
return elem;
|
|
}
|
|
|
|
jQuery.extend( {
|
|
htmlPrefilter: function( html ) {
|
|
return html.replace( rxhtmlTag, "<$1></$2>" );
|
|
},
|
|
|
|
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
|
|
var destElements, node, clone, i, srcElements,
|
|
inPage = jQuery.contains( elem.ownerDocument, elem );
|
|
|
|
if ( support.html5Clone || jQuery.isXMLDoc( elem ) ||
|
|
!rnoshimcache.test( "<" + elem.nodeName + ">" ) ) {
|
|
|
|
clone = elem.cloneNode( true );
|
|
|
|
// IE<=8 does not properly clone detached, unknown element nodes
|
|
} else {
|
|
fragmentDiv.innerHTML = elem.outerHTML;
|
|
fragmentDiv.removeChild( clone = fragmentDiv.firstChild );
|
|
}
|
|
|
|
if ( ( !support.noCloneEvent || !support.noCloneChecked ) &&
|
|
( elem.nodeType === 1 || elem.nodeType === 11 ) && !jQuery.isXMLDoc( elem ) ) {
|
|
|
|
// We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
|
|
destElements = getAll( clone );
|
|
srcElements = getAll( elem );
|
|
|
|
// Fix all IE cloning issues
|
|
for ( i = 0; ( node = srcElements[ i ] ) != null; ++i ) {
|
|
|
|
// Ensure that the destination node is not null; Fixes #9587
|
|
if ( destElements[ i ] ) {
|
|
fixCloneNodeIssues( node, destElements[ i ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
// Copy the events from the original to the clone
|
|
if ( dataAndEvents ) {
|
|
if ( deepDataAndEvents ) {
|
|
srcElements = srcElements || getAll( elem );
|
|
destElements = destElements || getAll( clone );
|
|
|
|
for ( i = 0; ( node = srcElements[ i ] ) != null; i++ ) {
|
|
cloneCopyEvent( node, destElements[ i ] );
|
|
}
|
|
} else {
|
|
cloneCopyEvent( elem, clone );
|
|
}
|
|
}
|
|
|
|
// Preserve script evaluation history
|
|
destElements = getAll( clone, "script" );
|
|
if ( destElements.length > 0 ) {
|
|
setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
|
|
}
|
|
|
|
destElements = srcElements = node = null;
|
|
|
|
// Return the cloned set
|
|
return clone;
|
|
},
|
|
|
|
cleanData: function( elems, /* internal */ forceAcceptData ) {
|
|
var elem, type, id, data,
|
|
i = 0,
|
|
internalKey = jQuery.expando,
|
|
cache = jQuery.cache,
|
|
attributes = support.attributes,
|
|
special = jQuery.event.special;
|
|
|
|
for ( ; ( elem = elems[ i ] ) != null; i++ ) {
|
|
if ( forceAcceptData || acceptData( elem ) ) {
|
|
|
|
id = elem[ internalKey ];
|
|
data = id && cache[ id ];
|
|
|
|
if ( data ) {
|
|
if ( data.events ) {
|
|
for ( type in data.events ) {
|
|
if ( special[ type ] ) {
|
|
jQuery.event.remove( elem, type );
|
|
|
|
// This is a shortcut to avoid jQuery.event.remove's overhead
|
|
} else {
|
|
jQuery.removeEvent( elem, type, data.handle );
|
|
}
|
|
}
|
|
}
|
|
|
|
// Remove cache only if it was not already removed by jQuery.event.remove
|
|
if ( cache[ id ] ) {
|
|
|
|
delete cache[ id ];
|
|
|
|
// Support: IE<9
|
|
// IE does not allow us to delete expando properties from nodes
|
|
// IE creates expando attributes along with the property
|
|
// IE does not have a removeAttribute function on Document nodes
|
|
if ( !attributes && typeof elem.removeAttribute !== "undefined" ) {
|
|
elem.removeAttribute( internalKey );
|
|
|
|
// Webkit & Blink performance suffers when deleting properties
|
|
// from DOM nodes, so set to undefined instead
|
|
// https://code.google.com/p/chromium/issues/detail?id=378607
|
|
} else {
|
|
elem[ internalKey ] = undefined;
|
|
}
|
|
|
|
deletedIds.push( id );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
|
|
jQuery.fn.extend( {
|
|
|
|
// Keep domManip exposed until 3.0 (gh-2225)
|
|
domManip: domManip,
|
|
|
|
detach: function( selector ) {
|
|
return remove( this, selector, true );
|
|
},
|
|
|
|
remove: function( selector ) {
|
|
return remove( this, selector );
|
|
},
|
|
|
|
text: function( value ) {
|
|
return access( this, function( value ) {
|
|
return value === undefined ?
|
|
jQuery.text( this ) :
|
|
this.empty().append(
|
|
( this[ 0 ] && this[ 0 ].ownerDocument || document ).createTextNode( value )
|
|
);
|
|
}, null, value, arguments.length );
|
|
},
|
|
|
|
append: function() {
|
|
return domManip( this, arguments, function( elem ) {
|
|
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
|
|
var target = manipulationTarget( this, elem );
|
|
target.appendChild( elem );
|
|
}
|
|
} );
|
|
},
|
|
|
|
prepend: function() {
|
|
return domManip( this, arguments, function( elem ) {
|
|
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
|
|
var target = manipulationTarget( this, elem );
|
|
target.insertBefore( elem, target.firstChild );
|
|
}
|
|
} );
|
|
},
|
|
|
|
before: function() {
|
|
return domManip( this, arguments, function( elem ) {
|
|
if ( this.parentNode ) {
|
|
this.parentNode.insertBefore( elem, this );
|
|
}
|
|
} );
|
|
},
|
|
|
|
after: function() {
|
|
return domManip( this, arguments, function( elem ) {
|
|
if ( this.parentNode ) {
|
|
this.parentNode.insertBefore( elem, this.nextSibling );
|
|
}
|
|
} );
|
|
},
|
|
|
|
empty: function() {
|
|
var elem,
|
|
i = 0;
|
|
|
|
for ( ; ( elem = this[ i ] ) != null; i++ ) {
|
|
|
|
// Remove element nodes and prevent memory leaks
|
|
if ( elem.nodeType === 1 ) {
|
|
jQuery.cleanData( getAll( elem, false ) );
|
|
}
|
|
|
|
// Remove any remaining nodes
|
|
while ( elem.firstChild ) {
|
|
elem.removeChild( elem.firstChild );
|
|
}
|
|
|
|
// If this is a select, ensure that it displays empty (#12336)
|
|
// Support: IE<9
|
|
if ( elem.options && jQuery.nodeName( elem, "select" ) ) {
|
|
elem.options.length = 0;
|
|
}
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
clone: function( dataAndEvents, deepDataAndEvents ) {
|
|
dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
|
|
deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
|
|
|
|
return this.map( function() {
|
|
return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
|
|
} );
|
|
},
|
|
|
|
html: function( value ) {
|
|
return access( this, function( value ) {
|
|
var elem = this[ 0 ] || {},
|
|
i = 0,
|
|
l = this.length;
|
|
|
|
if ( value === undefined ) {
|
|
return elem.nodeType === 1 ?
|
|
elem.innerHTML.replace( rinlinejQuery, "" ) :
|
|
undefined;
|
|
}
|
|
|
|
// See if we can take a shortcut and just use innerHTML
|
|
if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
|
|
( support.htmlSerialize || !rnoshimcache.test( value ) ) &&
|
|
( support.leadingWhitespace || !rleadingWhitespace.test( value ) ) &&
|
|
!wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
|
|
|
|
value = jQuery.htmlPrefilter( value );
|
|
|
|
try {
|
|
for ( ; i < l; i++ ) {
|
|
|
|
// Remove element nodes and prevent memory leaks
|
|
elem = this[ i ] || {};
|
|
if ( elem.nodeType === 1 ) {
|
|
jQuery.cleanData( getAll( elem, false ) );
|
|
elem.innerHTML = value;
|
|
}
|
|
}
|
|
|
|
elem = 0;
|
|
|
|
// If using innerHTML throws an exception, use the fallback method
|
|
} catch ( e ) {}
|
|
}
|
|
|
|
if ( elem ) {
|
|
this.empty().append( value );
|
|
}
|
|
}, null, value, arguments.length );
|
|
},
|
|
|
|
replaceWith: function() {
|
|
var ignored = [];
|
|
|
|
// Make the changes, replacing each non-ignored context element with the new content
|
|
return domManip( this, arguments, function( elem ) {
|
|
var parent = this.parentNode;
|
|
|
|
if ( jQuery.inArray( this, ignored ) < 0 ) {
|
|
jQuery.cleanData( getAll( this ) );
|
|
if ( parent ) {
|
|
parent.replaceChild( elem, this );
|
|
}
|
|
}
|
|
|
|
// Force callback invocation
|
|
}, ignored );
|
|
}
|
|
} );
|
|
|
|
jQuery.each( {
|
|
appendTo: "append",
|
|
prependTo: "prepend",
|
|
insertBefore: "before",
|
|
insertAfter: "after",
|
|
replaceAll: "replaceWith"
|
|
}, function( name, original ) {
|
|
jQuery.fn[ name ] = function( selector ) {
|
|
var elems,
|
|
i = 0,
|
|
ret = [],
|
|
insert = jQuery( selector ),
|
|
last = insert.length - 1;
|
|
|
|
for ( ; i <= last; i++ ) {
|
|
elems = i === last ? this : this.clone( true );
|
|
jQuery( insert[ i ] )[ original ]( elems );
|
|
|
|
// Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get()
|
|
push.apply( ret, elems.get() );
|
|
}
|
|
|
|
return this.pushStack( ret );
|
|
};
|
|
} );
|
|
|
|
|
|
var iframe,
|
|
elemdisplay = {
|
|
|
|
// Support: Firefox
|
|
// We have to pre-define these values for FF (#10227)
|
|
HTML: "block",
|
|
BODY: "block"
|
|
};
|
|
|
|
/**
|
|
* Retrieve the actual display of a element
|
|
* @param {String} name nodeName of the element
|
|
* @param {Object} doc Document object
|
|
*/
|
|
|
|
// Called only from within defaultDisplay
|
|
function actualDisplay( name, doc ) {
|
|
var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
|
|
|
|
display = jQuery.css( elem[ 0 ], "display" );
|
|
|
|
// We don't have any data stored on the element,
|
|
// so use "detach" method as fast way to get rid of the element
|
|
elem.detach();
|
|
|
|
return display;
|
|
}
|
|
|
|
/**
|
|
* Try to determine the default display value of an element
|
|
* @param {String} nodeName
|
|
*/
|
|
function defaultDisplay( nodeName ) {
|
|
var doc = document,
|
|
display = elemdisplay[ nodeName ];
|
|
|
|
if ( !display ) {
|
|
display = actualDisplay( nodeName, doc );
|
|
|
|
// If the simple way fails, read from inside an iframe
|
|
if ( display === "none" || !display ) {
|
|
|
|
// Use the already-created iframe if possible
|
|
iframe = ( iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" ) )
|
|
.appendTo( doc.documentElement );
|
|
|
|
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
|
|
doc = ( iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument ).document;
|
|
|
|
// Support: IE
|
|
doc.write();
|
|
doc.close();
|
|
|
|
display = actualDisplay( nodeName, doc );
|
|
iframe.detach();
|
|
}
|
|
|
|
// Store the correct default display
|
|
elemdisplay[ nodeName ] = display;
|
|
}
|
|
|
|
return display;
|
|
}
|
|
var rmargin = ( /^margin/ );
|
|
|
|
var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
|
|
|
|
var swap = function( elem, options, callback, args ) {
|
|
var ret, name,
|
|
old = {};
|
|
|
|
// Remember the old values, and insert the new ones
|
|
for ( name in options ) {
|
|
old[ name ] = elem.style[ name ];
|
|
elem.style[ name ] = options[ name ];
|
|
}
|
|
|
|
ret = callback.apply( elem, args || [] );
|
|
|
|
// Revert the old values
|
|
for ( name in options ) {
|
|
elem.style[ name ] = old[ name ];
|
|
}
|
|
|
|
return ret;
|
|
};
|
|
|
|
|
|
var documentElement = document.documentElement;
|
|
|
|
|
|
|
|
( function() {
|
|
var pixelPositionVal, pixelMarginRightVal, boxSizingReliableVal,
|
|
reliableHiddenOffsetsVal, reliableMarginRightVal, reliableMarginLeftVal,
|
|
container = document.createElement( "div" ),
|
|
div = document.createElement( "div" );
|
|
|
|
// Finish early in limited (non-browser) environments
|
|
if ( !div.style ) {
|
|
return;
|
|
}
|
|
|
|
div.style.cssText = "float:left;opacity:.5";
|
|
|
|
// Support: IE<9
|
|
// Make sure that element opacity exists (as opposed to filter)
|
|
support.opacity = div.style.opacity === "0.5";
|
|
|
|
// Verify style float existence
|
|
// (IE uses styleFloat instead of cssFloat)
|
|
support.cssFloat = !!div.style.cssFloat;
|
|
|
|
div.style.backgroundClip = "content-box";
|
|
div.cloneNode( true ).style.backgroundClip = "";
|
|
support.clearCloneStyle = div.style.backgroundClip === "content-box";
|
|
|
|
container = document.createElement( "div" );
|
|
container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
|
|
"padding:0;margin-top:1px;position:absolute";
|
|
div.innerHTML = "";
|
|
container.appendChild( div );
|
|
|
|
// Support: Firefox<29, Android 2.3
|
|
// Vendor-prefix box-sizing
|
|
support.boxSizing = div.style.boxSizing === "" || div.style.MozBoxSizing === "" ||
|
|
div.style.WebkitBoxSizing === "";
|
|
|
|
jQuery.extend( support, {
|
|
reliableHiddenOffsets: function() {
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return reliableHiddenOffsetsVal;
|
|
},
|
|
|
|
boxSizingReliable: function() {
|
|
|
|
// We're checking for pixelPositionVal here instead of boxSizingReliableVal
|
|
// since that compresses better and they're computed together anyway.
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return boxSizingReliableVal;
|
|
},
|
|
|
|
pixelMarginRight: function() {
|
|
|
|
// Support: Android 4.0-4.3
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return pixelMarginRightVal;
|
|
},
|
|
|
|
pixelPosition: function() {
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return pixelPositionVal;
|
|
},
|
|
|
|
reliableMarginRight: function() {
|
|
|
|
// Support: Android 2.3
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return reliableMarginRightVal;
|
|
},
|
|
|
|
reliableMarginLeft: function() {
|
|
|
|
// Support: IE <=8 only, Android 4.0 - 4.3 only, Firefox <=3 - 37
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return reliableMarginLeftVal;
|
|
}
|
|
} );
|
|
|
|
function computeStyleTests() {
|
|
var contents, divStyle,
|
|
documentElement = document.documentElement;
|
|
|
|
// Setup
|
|
documentElement.appendChild( container );
|
|
|
|
div.style.cssText =
|
|
|
|
// Support: Android 2.3
|
|
// Vendor-prefix box-sizing
|
|
"-webkit-box-sizing:border-box;box-sizing:border-box;" +
|
|
"position:relative;display:block;" +
|
|
"margin:auto;border:1px;padding:1px;" +
|
|
"top:1%;width:50%";
|
|
|
|
// Support: IE<9
|
|
// Assume reasonable values in the absence of getComputedStyle
|
|
pixelPositionVal = boxSizingReliableVal = reliableMarginLeftVal = false;
|
|
pixelMarginRightVal = reliableMarginRightVal = true;
|
|
|
|
// Check for getComputedStyle so that this code is not run in IE<9.
|
|
if ( window.getComputedStyle ) {
|
|
divStyle = window.getComputedStyle( div );
|
|
pixelPositionVal = ( divStyle || {} ).top !== "1%";
|
|
reliableMarginLeftVal = ( divStyle || {} ).marginLeft === "2px";
|
|
boxSizingReliableVal = ( divStyle || { width: "4px" } ).width === "4px";
|
|
|
|
// Support: Android 4.0 - 4.3 only
|
|
// Some styles come back with percentage values, even though they shouldn't
|
|
div.style.marginRight = "50%";
|
|
pixelMarginRightVal = ( divStyle || { marginRight: "4px" } ).marginRight === "4px";
|
|
|
|
// Support: Android 2.3 only
|
|
// Div with explicit width and no margin-right incorrectly
|
|
// gets computed margin-right based on width of container (#3333)
|
|
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
|
|
contents = div.appendChild( document.createElement( "div" ) );
|
|
|
|
// Reset CSS: box-sizing; display; margin; border; padding
|
|
contents.style.cssText = div.style.cssText =
|
|
|
|
// Support: Android 2.3
|
|
// Vendor-prefix box-sizing
|
|
"-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
|
|
"box-sizing:content-box;display:block;margin:0;border:0;padding:0";
|
|
contents.style.marginRight = contents.style.width = "0";
|
|
div.style.width = "1px";
|
|
|
|
reliableMarginRightVal =
|
|
!parseFloat( ( window.getComputedStyle( contents ) || {} ).marginRight );
|
|
|
|
div.removeChild( contents );
|
|
}
|
|
|
|
// Support: IE6-8
|
|
// First check that getClientRects works as expected
|
|
// Check if table cells still have offsetWidth/Height when they are set
|
|
// to display:none and there are still other visible table cells in a
|
|
// table row; if so, offsetWidth/Height are not reliable for use when
|
|
// determining if an element has been hidden directly using
|
|
// display:none (it is still safe to use offsets if a parent element is
|
|
// hidden; don safety goggles and see bug #4512 for more information).
|
|
div.style.display = "none";
|
|
reliableHiddenOffsetsVal = div.getClientRects().length === 0;
|
|
if ( reliableHiddenOffsetsVal ) {
|
|
div.style.display = "";
|
|
div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";
|
|
div.childNodes[ 0 ].style.borderCollapse = "separate";
|
|
contents = div.getElementsByTagName( "td" );
|
|
contents[ 0 ].style.cssText = "margin:0;border:0;padding:0;display:none";
|
|
reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
|
|
if ( reliableHiddenOffsetsVal ) {
|
|
contents[ 0 ].style.display = "";
|
|
contents[ 1 ].style.display = "none";
|
|
reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
|
|
}
|
|
}
|
|
|
|
// Teardown
|
|
documentElement.removeChild( container );
|
|
}
|
|
|
|
} )();
|
|
|
|
|
|
var getStyles, curCSS,
|
|
rposition = /^(top|right|bottom|left)$/;
|
|
|
|
if ( window.getComputedStyle ) {
|
|
getStyles = function( elem ) {
|
|
|
|
// Support: IE<=11+, Firefox<=30+ (#15098, #14150)
|
|
// IE throws on elements created in popups
|
|
// FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
|
|
var view = elem.ownerDocument.defaultView;
|
|
|
|
if ( !view || !view.opener ) {
|
|
view = window;
|
|
}
|
|
|
|
return view.getComputedStyle( elem );
|
|
};
|
|
|
|
curCSS = function( elem, name, computed ) {
|
|
var width, minWidth, maxWidth, ret,
|
|
style = elem.style;
|
|
|
|
computed = computed || getStyles( elem );
|
|
|
|
// getPropertyValue is only needed for .css('filter') in IE9, see #12537
|
|
ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined;
|
|
|
|
// Support: Opera 12.1x only
|
|
// Fall back to style even without computed
|
|
// computed is undefined for elems on document fragments
|
|
if ( ( ret === "" || ret === undefined ) && !jQuery.contains( elem.ownerDocument, elem ) ) {
|
|
ret = jQuery.style( elem, name );
|
|
}
|
|
|
|
if ( computed ) {
|
|
|
|
// A tribute to the "awesome hack by Dean Edwards"
|
|
// Chrome < 17 and Safari 5.0 uses "computed value"
|
|
// instead of "used value" for margin-right
|
|
// Safari 5.1.7 (at least) returns percentage for a larger set of values,
|
|
// but width seems to be reliably pixels
|
|
// this is against the CSSOM draft spec:
|
|
// http://dev.w3.org/csswg/cssom/#resolved-values
|
|
if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
|
|
|
|
// Remember the original values
|
|
width = style.width;
|
|
minWidth = style.minWidth;
|
|
maxWidth = style.maxWidth;
|
|
|
|
// Put in the new values to get a computed value out
|
|
style.minWidth = style.maxWidth = style.width = ret;
|
|
ret = computed.width;
|
|
|
|
// Revert the changed values
|
|
style.width = width;
|
|
style.minWidth = minWidth;
|
|
style.maxWidth = maxWidth;
|
|
}
|
|
}
|
|
|
|
// Support: IE
|
|
// IE returns zIndex value as an integer.
|
|
return ret === undefined ?
|
|
ret :
|
|
ret + "";
|
|
};
|
|
} else if ( documentElement.currentStyle ) {
|
|
getStyles = function( elem ) {
|
|
return elem.currentStyle;
|
|
};
|
|
|
|
curCSS = function( elem, name, computed ) {
|
|
var left, rs, rsLeft, ret,
|
|
style = elem.style;
|
|
|
|
computed = computed || getStyles( elem );
|
|
ret = computed ? computed[ name ] : undefined;
|
|
|
|
// Avoid setting ret to empty string here
|
|
// so we don't default to auto
|
|
if ( ret == null && style && style[ name ] ) {
|
|
ret = style[ name ];
|
|
}
|
|
|
|
// From the awesome hack by Dean Edwards
|
|
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
|
|
|
|
// If we're not dealing with a regular pixel number
|
|
// but a number that has a weird ending, we need to convert it to pixels
|
|
// but not position css attributes, as those are
|
|
// proportional to the parent element instead
|
|
// and we can't measure the parent instead because it
|
|
// might trigger a "stacking dolls" problem
|
|
if ( rnumnonpx.test( ret ) && !rposition.test( name ) ) {
|
|
|
|
// Remember the original values
|
|
left = style.left;
|
|
rs = elem.runtimeStyle;
|
|
rsLeft = rs && rs.left;
|
|
|
|
// Put in the new values to get a computed value out
|
|
if ( rsLeft ) {
|
|
rs.left = elem.currentStyle.left;
|
|
}
|
|
style.left = name === "fontSize" ? "1em" : ret;
|
|
ret = style.pixelLeft + "px";
|
|
|
|
// Revert the changed values
|
|
style.left = left;
|
|
if ( rsLeft ) {
|
|
rs.left = rsLeft;
|
|
}
|
|
}
|
|
|
|
// Support: IE
|
|
// IE returns zIndex value as an integer.
|
|
return ret === undefined ?
|
|
ret :
|
|
ret + "" || "auto";
|
|
};
|
|
}
|
|
|
|
|
|
|
|
|
|
function addGetHookIf( conditionFn, hookFn ) {
|
|
|
|
// Define the hook, we'll check on the first run if it's really needed.
|
|
return {
|
|
get: function() {
|
|
if ( conditionFn() ) {
|
|
|
|
// Hook not needed (or it's not possible to use it due
|
|
// to missing dependency), remove it.
|
|
delete this.get;
|
|
return;
|
|
}
|
|
|
|
// Hook needed; redefine it so that the support test is not executed again.
|
|
return ( this.get = hookFn ).apply( this, arguments );
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
var
|
|
|
|
ralpha = /alpha\([^)]*\)/i,
|
|
ropacity = /opacity\s*=\s*([^)]*)/i,
|
|
|
|
// swappable if display is none or starts with table except
|
|
// "table", "table-cell", or "table-caption"
|
|
// see here for display values:
|
|
// https://developer.mozilla.org/en-US/docs/CSS/display
|
|
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
|
|
rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
|
|
|
|
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
|
|
cssNormalTransform = {
|
|
letterSpacing: "0",
|
|
fontWeight: "400"
|
|
},
|
|
|
|
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
|
|
emptyStyle = document.createElement( "div" ).style;
|
|
|
|
|
|
// return a css property mapped to a potentially vendor prefixed property
|
|
function vendorPropName( name ) {
|
|
|
|
// shortcut for names that are not vendor prefixed
|
|
if ( name in emptyStyle ) {
|
|
return name;
|
|
}
|
|
|
|
// check for vendor prefixed names
|
|
var capName = name.charAt( 0 ).toUpperCase() + name.slice( 1 ),
|
|
i = cssPrefixes.length;
|
|
|
|
while ( i-- ) {
|
|
name = cssPrefixes[ i ] + capName;
|
|
if ( name in emptyStyle ) {
|
|
return name;
|
|
}
|
|
}
|
|
}
|
|
|
|
function showHide( elements, show ) {
|
|
var display, elem, hidden,
|
|
values = [],
|
|
index = 0,
|
|
length = elements.length;
|
|
|
|
for ( ; index < length; index++ ) {
|
|
elem = elements[ index ];
|
|
if ( !elem.style ) {
|
|
continue;
|
|
}
|
|
|
|
values[ index ] = jQuery._data( elem, "olddisplay" );
|
|
display = elem.style.display;
|
|
if ( show ) {
|
|
|
|
// Reset the inline display of this element to learn if it is
|
|
// being hidden by cascaded rules or not
|
|
if ( !values[ index ] && display === "none" ) {
|
|
elem.style.display = "";
|
|
}
|
|
|
|
// Set elements which have been overridden with display: none
|
|
// in a stylesheet to whatever the default browser style is
|
|
// for such an element
|
|
if ( elem.style.display === "" && isHidden( elem ) ) {
|
|
values[ index ] =
|
|
jQuery._data( elem, "olddisplay", defaultDisplay( elem.nodeName ) );
|
|
}
|
|
} else {
|
|
hidden = isHidden( elem );
|
|
|
|
if ( display && display !== "none" || !hidden ) {
|
|
jQuery._data(
|
|
elem,
|
|
"olddisplay",
|
|
hidden ? display : jQuery.css( elem, "display" )
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Set the display of most of the elements in a second loop
|
|
// to avoid the constant reflow
|
|
for ( index = 0; index < length; index++ ) {
|
|
elem = elements[ index ];
|
|
if ( !elem.style ) {
|
|
continue;
|
|
}
|
|
if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
|
|
elem.style.display = show ? values[ index ] || "" : "none";
|
|
}
|
|
}
|
|
|
|
return elements;
|
|
}
|
|
|
|
function setPositiveNumber( elem, value, subtract ) {
|
|
var matches = rnumsplit.exec( value );
|
|
return matches ?
|
|
|
|
// Guard against undefined "subtract", e.g., when used as in cssHooks
|
|
Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
|
|
value;
|
|
}
|
|
|
|
function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
|
|
var i = extra === ( isBorderBox ? "border" : "content" ) ?
|
|
|
|
// If we already have the right measurement, avoid augmentation
|
|
4 :
|
|
|
|
// Otherwise initialize for horizontal or vertical properties
|
|
name === "width" ? 1 : 0,
|
|
|
|
val = 0;
|
|
|
|
for ( ; i < 4; i += 2 ) {
|
|
|
|
// both box models exclude margin, so add it if we want it
|
|
if ( extra === "margin" ) {
|
|
val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
|
|
}
|
|
|
|
if ( isBorderBox ) {
|
|
|
|
// border-box includes padding, so remove it if we want content
|
|
if ( extra === "content" ) {
|
|
val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
|
}
|
|
|
|
// at this point, extra isn't border nor margin, so remove border
|
|
if ( extra !== "margin" ) {
|
|
val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
|
}
|
|
} else {
|
|
|
|
// at this point, extra isn't content, so add padding
|
|
val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
|
|
|
// at this point, extra isn't content nor padding, so add border
|
|
if ( extra !== "padding" ) {
|
|
val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
|
}
|
|
}
|
|
}
|
|
|
|
return val;
|
|
}
|
|
|
|
function getWidthOrHeight( elem, name, extra ) {
|
|
|
|
// Start with offset property, which is equivalent to the border-box value
|
|
var valueIsBorderBox = true,
|
|
val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
|
|
styles = getStyles( elem ),
|
|
isBorderBox = support.boxSizing &&
|
|
jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
|
|
|
|
// some non-html elements return undefined for offsetWidth, so check for null/undefined
|
|
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
|
|
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
|
|
if ( val <= 0 || val == null ) {
|
|
|
|
// Fall back to computed then uncomputed css if necessary
|
|
val = curCSS( elem, name, styles );
|
|
if ( val < 0 || val == null ) {
|
|
val = elem.style[ name ];
|
|
}
|
|
|
|
// Computed unit is not pixels. Stop here and return.
|
|
if ( rnumnonpx.test( val ) ) {
|
|
return val;
|
|
}
|
|
|
|
// we need the check for style in case a browser which returns unreliable values
|
|
// for getComputedStyle silently falls back to the reliable elem.style
|
|
valueIsBorderBox = isBorderBox &&
|
|
( support.boxSizingReliable() || val === elem.style[ name ] );
|
|
|
|
// Normalize "", auto, and prepare for extra
|
|
val = parseFloat( val ) || 0;
|
|
}
|
|
|
|
// use the active box-sizing model to add/subtract irrelevant styles
|
|
return ( val +
|
|
augmentWidthOrHeight(
|
|
elem,
|
|
name,
|
|
extra || ( isBorderBox ? "border" : "content" ),
|
|
valueIsBorderBox,
|
|
styles
|
|
)
|
|
) + "px";
|
|
}
|
|
|
|
jQuery.extend( {
|
|
|
|
// Add in style property hooks for overriding the default
|
|
// behavior of getting and setting a style property
|
|
cssHooks: {
|
|
opacity: {
|
|
get: function( elem, computed ) {
|
|
if ( computed ) {
|
|
|
|
// We should always get a number back from opacity
|
|
var ret = curCSS( elem, "opacity" );
|
|
return ret === "" ? "1" : ret;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
// Don't automatically add "px" to these possibly-unitless properties
|
|
cssNumber: {
|
|
"animationIterationCount": true,
|
|
"columnCount": true,
|
|
"fillOpacity": true,
|
|
"flexGrow": true,
|
|
"flexShrink": true,
|
|
"fontWeight": true,
|
|
"lineHeight": true,
|
|
"opacity": true,
|
|
"order": true,
|
|
"orphans": true,
|
|
"widows": true,
|
|
"zIndex": true,
|
|
"zoom": true
|
|
},
|
|
|
|
// Add in properties whose names you wish to fix before
|
|
// setting or getting the value
|
|
cssProps: {
|
|
|
|
// normalize float css property
|
|
"float": support.cssFloat ? "cssFloat" : "styleFloat"
|
|
},
|
|
|
|
// Get and set the style property on a DOM Node
|
|
style: function( elem, name, value, extra ) {
|
|
|
|
// Don't set styles on text and comment nodes
|
|
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
|
|
return;
|
|
}
|
|
|
|
// Make sure that we're working with the right name
|
|
var ret, type, hooks,
|
|
origName = jQuery.camelCase( name ),
|
|
style = elem.style;
|
|
|
|
name = jQuery.cssProps[ origName ] ||
|
|
( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName );
|
|
|
|
// gets hook for the prefixed version
|
|
// followed by the unprefixed version
|
|
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
|
|
|
// Check if we're setting a value
|
|
if ( value !== undefined ) {
|
|
type = typeof value;
|
|
|
|
// Convert "+=" or "-=" to relative numbers (#7345)
|
|
if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
|
|
value = adjustCSS( elem, name, ret );
|
|
|
|
// Fixes bug #9237
|
|
type = "number";
|
|
}
|
|
|
|
// Make sure that null and NaN values aren't set. See: #7116
|
|
if ( value == null || value !== value ) {
|
|
return;
|
|
}
|
|
|
|
// If a number was passed in, add the unit (except for certain CSS properties)
|
|
if ( type === "number" ) {
|
|
value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
|
|
}
|
|
|
|
// Fixes #8908, it can be done more correctly by specifing setters in cssHooks,
|
|
// but it would mean to define eight
|
|
// (for every problematic property) identical functions
|
|
if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
|
|
style[ name ] = "inherit";
|
|
}
|
|
|
|
// If a hook was provided, use that value, otherwise just set the specified value
|
|
if ( !hooks || !( "set" in hooks ) ||
|
|
( value = hooks.set( elem, value, extra ) ) !== undefined ) {
|
|
|
|
// Support: IE
|
|
// Swallow errors from 'invalid' CSS values (#5509)
|
|
try {
|
|
style[ name ] = value;
|
|
} catch ( e ) {}
|
|
}
|
|
|
|
} else {
|
|
|
|
// If a hook was provided get the non-computed value from there
|
|
if ( hooks && "get" in hooks &&
|
|
( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
|
|
|
|
return ret;
|
|
}
|
|
|
|
// Otherwise just get the value from the style object
|
|
return style[ name ];
|
|
}
|
|
},
|
|
|
|
css: function( elem, name, extra, styles ) {
|
|
var num, val, hooks,
|
|
origName = jQuery.camelCase( name );
|
|
|
|
// Make sure that we're working with the right name
|
|
name = jQuery.cssProps[ origName ] ||
|
|
( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName );
|
|
|
|
// gets hook for the prefixed version
|
|
// followed by the unprefixed version
|
|
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
|
|
|
// If a hook was provided get the computed value from there
|
|
if ( hooks && "get" in hooks ) {
|
|
val = hooks.get( elem, true, extra );
|
|
}
|
|
|
|
// Otherwise, if a way to get the computed value exists, use that
|
|
if ( val === undefined ) {
|
|
val = curCSS( elem, name, styles );
|
|
}
|
|
|
|
//convert "normal" to computed value
|
|
if ( val === "normal" && name in cssNormalTransform ) {
|
|
val = cssNormalTransform[ name ];
|
|
}
|
|
|
|
// Return, converting to number if forced or a qualifier was provided and val looks numeric
|
|
if ( extra === "" || extra ) {
|
|
num = parseFloat( val );
|
|
return extra === true || isFinite( num ) ? num || 0 : val;
|
|
}
|
|
return val;
|
|
}
|
|
} );
|
|
|
|
jQuery.each( [ "height", "width" ], function( i, name ) {
|
|
jQuery.cssHooks[ name ] = {
|
|
get: function( elem, computed, extra ) {
|
|
if ( computed ) {
|
|
|
|
// certain elements can have dimension info if we invisibly show them
|
|
// however, it must have a current display style that would benefit from this
|
|
return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
|
|
elem.offsetWidth === 0 ?
|
|
swap( elem, cssShow, function() {
|
|
return getWidthOrHeight( elem, name, extra );
|
|
} ) :
|
|
getWidthOrHeight( elem, name, extra );
|
|
}
|
|
},
|
|
|
|
set: function( elem, value, extra ) {
|
|
var styles = extra && getStyles( elem );
|
|
return setPositiveNumber( elem, value, extra ?
|
|
augmentWidthOrHeight(
|
|
elem,
|
|
name,
|
|
extra,
|
|
support.boxSizing &&
|
|
jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
|
|
styles
|
|
) : 0
|
|
);
|
|
}
|
|
};
|
|
} );
|
|
|
|
if ( !support.opacity ) {
|
|
jQuery.cssHooks.opacity = {
|
|
get: function( elem, computed ) {
|
|
|
|
// IE uses filters for opacity
|
|
return ropacity.test( ( computed && elem.currentStyle ?
|
|
elem.currentStyle.filter :
|
|
elem.style.filter ) || "" ) ?
|
|
( 0.01 * parseFloat( RegExp.$1 ) ) + "" :
|
|
computed ? "1" : "";
|
|
},
|
|
|
|
set: function( elem, value ) {
|
|
var style = elem.style,
|
|
currentStyle = elem.currentStyle,
|
|
opacity = jQuery.isNumeric( value ) ? "alpha(opacity=" + value * 100 + ")" : "",
|
|
filter = currentStyle && currentStyle.filter || style.filter || "";
|
|
|
|
// IE has trouble with opacity if it does not have layout
|
|
// Force it by setting the zoom level
|
|
style.zoom = 1;
|
|
|
|
// if setting opacity to 1, and no other filters exist -
|
|
// attempt to remove filter attribute #6652
|
|
// if value === "", then remove inline opacity #12685
|
|
if ( ( value >= 1 || value === "" ) &&
|
|
jQuery.trim( filter.replace( ralpha, "" ) ) === "" &&
|
|
style.removeAttribute ) {
|
|
|
|
// Setting style.filter to null, "" & " " still leave "filter:" in the cssText
|
|
// if "filter:" is present at all, clearType is disabled, we want to avoid this
|
|
// style.removeAttribute is IE Only, but so apparently is this code path...
|
|
style.removeAttribute( "filter" );
|
|
|
|
// if there is no filter style applied in a css rule
|
|
// or unset inline opacity, we are done
|
|
if ( value === "" || currentStyle && !currentStyle.filter ) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
// otherwise, set new filter values
|
|
style.filter = ralpha.test( filter ) ?
|
|
filter.replace( ralpha, opacity ) :
|
|
filter + " " + opacity;
|
|
}
|
|
};
|
|
}
|
|
|
|
jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
|
|
function( elem, computed ) {
|
|
if ( computed ) {
|
|
return swap( elem, { "display": "inline-block" },
|
|
curCSS, [ elem, "marginRight" ] );
|
|
}
|
|
}
|
|
);
|
|
|
|
jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
|
|
function( elem, computed ) {
|
|
if ( computed ) {
|
|
return (
|
|
parseFloat( curCSS( elem, "marginLeft" ) ) ||
|
|
|
|
// Support: IE<=11+
|
|
// Running getBoundingClientRect on a disconnected node in IE throws an error
|
|
// Support: IE8 only
|
|
// getClientRects() errors on disconnected elems
|
|
( jQuery.contains( elem.ownerDocument, elem ) ?
|
|
elem.getBoundingClientRect().left -
|
|
swap( elem, { marginLeft: 0 }, function() {
|
|
return elem.getBoundingClientRect().left;
|
|
} ) :
|
|
0
|
|
)
|
|
) + "px";
|
|
}
|
|
}
|
|
);
|
|
|
|
// These hooks are used by animate to expand properties
|
|
jQuery.each( {
|
|
margin: "",
|
|
padding: "",
|
|
border: "Width"
|
|
}, function( prefix, suffix ) {
|
|
jQuery.cssHooks[ prefix + suffix ] = {
|
|
expand: function( value ) {
|
|
var i = 0,
|
|
expanded = {},
|
|
|
|
// assumes a single number if not a string
|
|
parts = typeof value === "string" ? value.split( " " ) : [ value ];
|
|
|
|
for ( ; i < 4; i++ ) {
|
|
expanded[ prefix + cssExpand[ i ] + suffix ] =
|
|
parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
|
|
}
|
|
|
|
return expanded;
|
|
}
|
|
};
|
|
|
|
if ( !rmargin.test( prefix ) ) {
|
|
jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
|
|
}
|
|
} );
|
|
|
|
jQuery.fn.extend( {
|
|
css: function( name, value ) {
|
|
return access( this, function( elem, name, value ) {
|
|
var styles, len,
|
|
map = {},
|
|
i = 0;
|
|
|
|
if ( jQuery.isArray( name ) ) {
|
|
styles = getStyles( elem );
|
|
len = name.length;
|
|
|
|
for ( ; i < len; i++ ) {
|
|
map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
|
|
}
|
|
|
|
return map;
|
|
}
|
|
|
|
return value !== undefined ?
|
|
jQuery.style( elem, name, value ) :
|
|
jQuery.css( elem, name );
|
|
}, name, value, arguments.length > 1 );
|
|
},
|
|
show: function() {
|
|
return showHide( this, true );
|
|
},
|
|
hide: function() {
|
|
return showHide( this );
|
|
},
|
|
toggle: function( state ) {
|
|
if ( typeof state === "boolean" ) {
|
|
return state ? this.show() : this.hide();
|
|
}
|
|
|
|
return this.each( function() {
|
|
if ( isHidden( this ) ) {
|
|
jQuery( this ).show();
|
|
} else {
|
|
jQuery( this ).hide();
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
|
|
|
|
function Tween( elem, options, prop, end, easing ) {
|
|
return new Tween.prototype.init( elem, options, prop, end, easing );
|
|
}
|
|
jQuery.Tween = Tween;
|
|
|
|
Tween.prototype = {
|
|
constructor: Tween,
|
|
init: function( elem, options, prop, end, easing, unit ) {
|
|
this.elem = elem;
|
|
this.prop = prop;
|
|
this.easing = easing || jQuery.easing._default;
|
|
this.options = options;
|
|
this.start = this.now = this.cur();
|
|
this.end = end;
|
|
this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
|
|
},
|
|
cur: function() {
|
|
var hooks = Tween.propHooks[ this.prop ];
|
|
|
|
return hooks && hooks.get ?
|
|
hooks.get( this ) :
|
|
Tween.propHooks._default.get( this );
|
|
},
|
|
run: function( percent ) {
|
|
var eased,
|
|
hooks = Tween.propHooks[ this.prop ];
|
|
|
|
if ( this.options.duration ) {
|
|
this.pos = eased = jQuery.easing[ this.easing ](
|
|
percent, this.options.duration * percent, 0, 1, this.options.duration
|
|
);
|
|
} else {
|
|
this.pos = eased = percent;
|
|
}
|
|
this.now = ( this.end - this.start ) * eased + this.start;
|
|
|
|
if ( this.options.step ) {
|
|
this.options.step.call( this.elem, this.now, this );
|
|
}
|
|
|
|
if ( hooks && hooks.set ) {
|
|
hooks.set( this );
|
|
} else {
|
|
Tween.propHooks._default.set( this );
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
|
|
Tween.prototype.init.prototype = Tween.prototype;
|
|
|
|
Tween.propHooks = {
|
|
_default: {
|
|
get: function( tween ) {
|
|
var result;
|
|
|
|
// Use a property on the element directly when it is not a DOM element,
|
|
// or when there is no matching style property that exists.
|
|
if ( tween.elem.nodeType !== 1 ||
|
|
tween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) {
|
|
return tween.elem[ tween.prop ];
|
|
}
|
|
|
|
// passing an empty string as a 3rd parameter to .css will automatically
|
|
// attempt a parseFloat and fallback to a string if the parse fails
|
|
// so, simple values such as "10px" are parsed to Float.
|
|
// complex values such as "rotate(1rad)" are returned as is.
|
|
result = jQuery.css( tween.elem, tween.prop, "" );
|
|
|
|
// Empty strings, null, undefined and "auto" are converted to 0.
|
|
return !result || result === "auto" ? 0 : result;
|
|
},
|
|
set: function( tween ) {
|
|
|
|
// use step hook for back compat - use cssHook if its there - use .style if its
|
|
// available and use plain properties where available
|
|
if ( jQuery.fx.step[ tween.prop ] ) {
|
|
jQuery.fx.step[ tween.prop ]( tween );
|
|
} else if ( tween.elem.nodeType === 1 &&
|
|
( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null ||
|
|
jQuery.cssHooks[ tween.prop ] ) ) {
|
|
jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
|
|
} else {
|
|
tween.elem[ tween.prop ] = tween.now;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
// Support: IE <=9
|
|
// Panic based approach to setting things on disconnected nodes
|
|
|
|
Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
|
|
set: function( tween ) {
|
|
if ( tween.elem.nodeType && tween.elem.parentNode ) {
|
|
tween.elem[ tween.prop ] = tween.now;
|
|
}
|
|
}
|
|
};
|
|
|
|
jQuery.easing = {
|
|
linear: function( p ) {
|
|
return p;
|
|
},
|
|
swing: function( p ) {
|
|
return 0.5 - Math.cos( p * Math.PI ) / 2;
|
|
},
|
|
_default: "swing"
|
|
};
|
|
|
|
jQuery.fx = Tween.prototype.init;
|
|
|
|
// Back Compat <1.8 extension point
|
|
jQuery.fx.step = {};
|
|
|
|
|
|
|
|
|
|
var
|
|
fxNow, timerId,
|
|
rfxtypes = /^(?:toggle|show|hide)$/,
|
|
rrun = /queueHooks$/;
|
|
|
|
// Animations created synchronously will run synchronously
|
|
function createFxNow() {
|
|
window.setTimeout( function() {
|
|
fxNow = undefined;
|
|
} );
|
|
return ( fxNow = jQuery.now() );
|
|
}
|
|
|
|
// Generate parameters to create a standard animation
|
|
function genFx( type, includeWidth ) {
|
|
var which,
|
|
attrs = { height: type },
|
|
i = 0;
|
|
|
|
// if we include width, step value is 1 to do all cssExpand values,
|
|
// if we don't include width, step value is 2 to skip over Left and Right
|
|
includeWidth = includeWidth ? 1 : 0;
|
|
for ( ; i < 4 ; i += 2 - includeWidth ) {
|
|
which = cssExpand[ i ];
|
|
attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
|
|
}
|
|
|
|
if ( includeWidth ) {
|
|
attrs.opacity = attrs.width = type;
|
|
}
|
|
|
|
return attrs;
|
|
}
|
|
|
|
function createTween( value, prop, animation ) {
|
|
var tween,
|
|
collection = ( Animation.tweeners[ prop ] || [] ).concat( Animation.tweeners[ "*" ] ),
|
|
index = 0,
|
|
length = collection.length;
|
|
for ( ; index < length; index++ ) {
|
|
if ( ( tween = collection[ index ].call( animation, prop, value ) ) ) {
|
|
|
|
// we're done with this property
|
|
return tween;
|
|
}
|
|
}
|
|
}
|
|
|
|
function defaultPrefilter( elem, props, opts ) {
|
|
/* jshint validthis: true */
|
|
var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
|
|
anim = this,
|
|
orig = {},
|
|
style = elem.style,
|
|
hidden = elem.nodeType && isHidden( elem ),
|
|
dataShow = jQuery._data( elem, "fxshow" );
|
|
|
|
// handle queue: false promises
|
|
if ( !opts.queue ) {
|
|
hooks = jQuery._queueHooks( elem, "fx" );
|
|
if ( hooks.unqueued == null ) {
|
|
hooks.unqueued = 0;
|
|
oldfire = hooks.empty.fire;
|
|
hooks.empty.fire = function() {
|
|
if ( !hooks.unqueued ) {
|
|
oldfire();
|
|
}
|
|
};
|
|
}
|
|
hooks.unqueued++;
|
|
|
|
anim.always( function() {
|
|
|
|
// doing this makes sure that the complete handler will be called
|
|
// before this completes
|
|
anim.always( function() {
|
|
hooks.unqueued--;
|
|
if ( !jQuery.queue( elem, "fx" ).length ) {
|
|
hooks.empty.fire();
|
|
}
|
|
} );
|
|
} );
|
|
}
|
|
|
|
// height/width overflow pass
|
|
if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
|
|
|
|
// Make sure that nothing sneaks out
|
|
// Record all 3 overflow attributes because IE does not
|
|
// change the overflow attribute when overflowX and
|
|
// overflowY are set to the same value
|
|
opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
|
|
|
|
// Set display property to inline-block for height/width
|
|
// animations on inline elements that are having width/height animated
|
|
display = jQuery.css( elem, "display" );
|
|
|
|
// Test default display if display is currently "none"
|
|
checkDisplay = display === "none" ?
|
|
jQuery._data( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
|
|
|
|
if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
|
|
|
|
// inline-level elements accept inline-block;
|
|
// block-level elements need to be inline with layout
|
|
if ( !support.inlineBlockNeedsLayout || defaultDisplay( elem.nodeName ) === "inline" ) {
|
|
style.display = "inline-block";
|
|
} else {
|
|
style.zoom = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( opts.overflow ) {
|
|
style.overflow = "hidden";
|
|
if ( !support.shrinkWrapBlocks() ) {
|
|
anim.always( function() {
|
|
style.overflow = opts.overflow[ 0 ];
|
|
style.overflowX = opts.overflow[ 1 ];
|
|
style.overflowY = opts.overflow[ 2 ];
|
|
} );
|
|
}
|
|
}
|
|
|
|
// show/hide pass
|
|
for ( prop in props ) {
|
|
value = props[ prop ];
|
|
if ( rfxtypes.exec( value ) ) {
|
|
delete props[ prop ];
|
|
toggle = toggle || value === "toggle";
|
|
if ( value === ( hidden ? "hide" : "show" ) ) {
|
|
|
|
// If there is dataShow left over from a stopped hide or show
|
|
// and we are going to proceed with show, we should pretend to be hidden
|
|
if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
|
|
hidden = true;
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
|
|
|
|
// Any non-fx value stops us from restoring the original display value
|
|
} else {
|
|
display = undefined;
|
|
}
|
|
}
|
|
|
|
if ( !jQuery.isEmptyObject( orig ) ) {
|
|
if ( dataShow ) {
|
|
if ( "hidden" in dataShow ) {
|
|
hidden = dataShow.hidden;
|
|
}
|
|
} else {
|
|
dataShow = jQuery._data( elem, "fxshow", {} );
|
|
}
|
|
|
|
// store state if its toggle - enables .stop().toggle() to "reverse"
|
|
if ( toggle ) {
|
|
dataShow.hidden = !hidden;
|
|
}
|
|
if ( hidden ) {
|
|
jQuery( elem ).show();
|
|
} else {
|
|
anim.done( function() {
|
|
jQuery( elem ).hide();
|
|
} );
|
|
}
|
|
anim.done( function() {
|
|
var prop;
|
|
jQuery._removeData( elem, "fxshow" );
|
|
for ( prop in orig ) {
|
|
jQuery.style( elem, prop, orig[ prop ] );
|
|
}
|
|
} );
|
|
for ( prop in orig ) {
|
|
tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
|
|
|
|
if ( !( prop in dataShow ) ) {
|
|
dataShow[ prop ] = tween.start;
|
|
if ( hidden ) {
|
|
tween.end = tween.start;
|
|
tween.start = prop === "width" || prop === "height" ? 1 : 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If this is a noop like .hide().hide(), restore an overwritten display value
|
|
} else if ( ( display === "none" ? defaultDisplay( elem.nodeName ) : display ) === "inline" ) {
|
|
style.display = display;
|
|
}
|
|
}
|
|
|
|
function propFilter( props, specialEasing ) {
|
|
var index, name, easing, value, hooks;
|
|
|
|
// camelCase, specialEasing and expand cssHook pass
|
|
for ( index in props ) {
|
|
name = jQuery.camelCase( index );
|
|
easing = specialEasing[ name ];
|
|
value = props[ index ];
|
|
if ( jQuery.isArray( value ) ) {
|
|
easing = value[ 1 ];
|
|
value = props[ index ] = value[ 0 ];
|
|
}
|
|
|
|
if ( index !== name ) {
|
|
props[ name ] = value;
|
|
delete props[ index ];
|
|
}
|
|
|
|
hooks = jQuery.cssHooks[ name ];
|
|
if ( hooks && "expand" in hooks ) {
|
|
value = hooks.expand( value );
|
|
delete props[ name ];
|
|
|
|
// not quite $.extend, this wont overwrite keys already present.
|
|
// also - reusing 'index' from above because we have the correct "name"
|
|
for ( index in value ) {
|
|
if ( !( index in props ) ) {
|
|
props[ index ] = value[ index ];
|
|
specialEasing[ index ] = easing;
|
|
}
|
|
}
|
|
} else {
|
|
specialEasing[ name ] = easing;
|
|
}
|
|
}
|
|
}
|
|
|
|
function Animation( elem, properties, options ) {
|
|
var result,
|
|
stopped,
|
|
index = 0,
|
|
length = Animation.prefilters.length,
|
|
deferred = jQuery.Deferred().always( function() {
|
|
|
|
// don't match elem in the :animated selector
|
|
delete tick.elem;
|
|
} ),
|
|
tick = function() {
|
|
if ( stopped ) {
|
|
return false;
|
|
}
|
|
var currentTime = fxNow || createFxNow(),
|
|
remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
|
|
|
|
// Support: Android 2.3
|
|
// Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
|
|
temp = remaining / animation.duration || 0,
|
|
percent = 1 - temp,
|
|
index = 0,
|
|
length = animation.tweens.length;
|
|
|
|
for ( ; index < length ; index++ ) {
|
|
animation.tweens[ index ].run( percent );
|
|
}
|
|
|
|
deferred.notifyWith( elem, [ animation, percent, remaining ] );
|
|
|
|
if ( percent < 1 && length ) {
|
|
return remaining;
|
|
} else {
|
|
deferred.resolveWith( elem, [ animation ] );
|
|
return false;
|
|
}
|
|
},
|
|
animation = deferred.promise( {
|
|
elem: elem,
|
|
props: jQuery.extend( {}, properties ),
|
|
opts: jQuery.extend( true, {
|
|
specialEasing: {},
|
|
easing: jQuery.easing._default
|
|
}, options ),
|
|
originalProperties: properties,
|
|
originalOptions: options,
|
|
startTime: fxNow || createFxNow(),
|
|
duration: options.duration,
|
|
tweens: [],
|
|
createTween: function( prop, end ) {
|
|
var tween = jQuery.Tween( elem, animation.opts, prop, end,
|
|
animation.opts.specialEasing[ prop ] || animation.opts.easing );
|
|
animation.tweens.push( tween );
|
|
return tween;
|
|
},
|
|
stop: function( gotoEnd ) {
|
|
var index = 0,
|
|
|
|
// if we are going to the end, we want to run all the tweens
|
|
// otherwise we skip this part
|
|
length = gotoEnd ? animation.tweens.length : 0;
|
|
if ( stopped ) {
|
|
return this;
|
|
}
|
|
stopped = true;
|
|
for ( ; index < length ; index++ ) {
|
|
animation.tweens[ index ].run( 1 );
|
|
}
|
|
|
|
// resolve when we played the last frame
|
|
// otherwise, reject
|
|
if ( gotoEnd ) {
|
|
deferred.notifyWith( elem, [ animation, 1, 0 ] );
|
|
deferred.resolveWith( elem, [ animation, gotoEnd ] );
|
|
} else {
|
|
deferred.rejectWith( elem, [ animation, gotoEnd ] );
|
|
}
|
|
return this;
|
|
}
|
|
} ),
|
|
props = animation.props;
|
|
|
|
propFilter( props, animation.opts.specialEasing );
|
|
|
|
for ( ; index < length ; index++ ) {
|
|
result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );
|
|
if ( result ) {
|
|
if ( jQuery.isFunction( result.stop ) ) {
|
|
jQuery._queueHooks( animation.elem, animation.opts.queue ).stop =
|
|
jQuery.proxy( result.stop, result );
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
jQuery.map( props, createTween, animation );
|
|
|
|
if ( jQuery.isFunction( animation.opts.start ) ) {
|
|
animation.opts.start.call( elem, animation );
|
|
}
|
|
|
|
jQuery.fx.timer(
|
|
jQuery.extend( tick, {
|
|
elem: elem,
|
|
anim: animation,
|
|
queue: animation.opts.queue
|
|
} )
|
|
);
|
|
|
|
// attach callbacks from options
|
|
return animation.progress( animation.opts.progress )
|
|
.done( animation.opts.done, animation.opts.complete )
|
|
.fail( animation.opts.fail )
|
|
.always( animation.opts.always );
|
|
}
|
|
|
|
jQuery.Animation = jQuery.extend( Animation, {
|
|
|
|
tweeners: {
|
|
"*": [ function( prop, value ) {
|
|
var tween = this.createTween( prop, value );
|
|
adjustCSS( tween.elem, prop, rcssNum.exec( value ), tween );
|
|
return tween;
|
|
} ]
|
|
},
|
|
|
|
tweener: function( props, callback ) {
|
|
if ( jQuery.isFunction( props ) ) {
|
|
callback = props;
|
|
props = [ "*" ];
|
|
} else {
|
|
props = props.match( rnotwhite );
|
|
}
|
|
|
|
var prop,
|
|
index = 0,
|
|
length = props.length;
|
|
|
|
for ( ; index < length ; index++ ) {
|
|
prop = props[ index ];
|
|
Animation.tweeners[ prop ] = Animation.tweeners[ prop ] || [];
|
|
Animation.tweeners[ prop ].unshift( callback );
|
|
}
|
|
},
|
|
|
|
prefilters: [ defaultPrefilter ],
|
|
|
|
prefilter: function( callback, prepend ) {
|
|
if ( prepend ) {
|
|
Animation.prefilters.unshift( callback );
|
|
} else {
|
|
Animation.prefilters.push( callback );
|
|
}
|
|
}
|
|
} );
|
|
|
|
jQuery.speed = function( speed, easing, fn ) {
|
|
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
|
|
complete: fn || !fn && easing ||
|
|
jQuery.isFunction( speed ) && speed,
|
|
duration: speed,
|
|
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
|
|
};
|
|
|
|
opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
|
|
opt.duration in jQuery.fx.speeds ?
|
|
jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
|
|
|
|
// normalize opt.queue - true/undefined/null -> "fx"
|
|
if ( opt.queue == null || opt.queue === true ) {
|
|
opt.queue = "fx";
|
|
}
|
|
|
|
// Queueing
|
|
opt.old = opt.complete;
|
|
|
|
opt.complete = function() {
|
|
if ( jQuery.isFunction( opt.old ) ) {
|
|
opt.old.call( this );
|
|
}
|
|
|
|
if ( opt.queue ) {
|
|
jQuery.dequeue( this, opt.queue );
|
|
}
|
|
};
|
|
|
|
return opt;
|
|
};
|
|
|
|
jQuery.fn.extend( {
|
|
fadeTo: function( speed, to, easing, callback ) {
|
|
|
|
// show any hidden elements after setting opacity to 0
|
|
return this.filter( isHidden ).css( "opacity", 0 ).show()
|
|
|
|
// animate to the value specified
|
|
.end().animate( { opacity: to }, speed, easing, callback );
|
|
},
|
|
animate: function( prop, speed, easing, callback ) {
|
|
var empty = jQuery.isEmptyObject( prop ),
|
|
optall = jQuery.speed( speed, easing, callback ),
|
|
doAnimation = function() {
|
|
|
|
// Operate on a copy of prop so per-property easing won't be lost
|
|
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
|
|
|
|
// Empty animations, or finishing resolves immediately
|
|
if ( empty || jQuery._data( this, "finish" ) ) {
|
|
anim.stop( true );
|
|
}
|
|
};
|
|
doAnimation.finish = doAnimation;
|
|
|
|
return empty || optall.queue === false ?
|
|
this.each( doAnimation ) :
|
|
this.queue( optall.queue, doAnimation );
|
|
},
|
|
stop: function( type, clearQueue, gotoEnd ) {
|
|
var stopQueue = function( hooks ) {
|
|
var stop = hooks.stop;
|
|
delete hooks.stop;
|
|
stop( gotoEnd );
|
|
};
|
|
|
|
if ( typeof type !== "string" ) {
|
|
gotoEnd = clearQueue;
|
|
clearQueue = type;
|
|
type = undefined;
|
|
}
|
|
if ( clearQueue && type !== false ) {
|
|
this.queue( type || "fx", [] );
|
|
}
|
|
|
|
return this.each( function() {
|
|
var dequeue = true,
|
|
index = type != null && type + "queueHooks",
|
|
timers = jQuery.timers,
|
|
data = jQuery._data( this );
|
|
|
|
if ( index ) {
|
|
if ( data[ index ] && data[ index ].stop ) {
|
|
stopQueue( data[ index ] );
|
|
}
|
|
} else {
|
|
for ( index in data ) {
|
|
if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
|
|
stopQueue( data[ index ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
for ( index = timers.length; index--; ) {
|
|
if ( timers[ index ].elem === this &&
|
|
( type == null || timers[ index ].queue === type ) ) {
|
|
|
|
timers[ index ].anim.stop( gotoEnd );
|
|
dequeue = false;
|
|
timers.splice( index, 1 );
|
|
}
|
|
}
|
|
|
|
// start the next in the queue if the last step wasn't forced
|
|
// timers currently will call their complete callbacks, which will dequeue
|
|
// but only if they were gotoEnd
|
|
if ( dequeue || !gotoEnd ) {
|
|
jQuery.dequeue( this, type );
|
|
}
|
|
} );
|
|
},
|
|
finish: function( type ) {
|
|
if ( type !== false ) {
|
|
type = type || "fx";
|
|
}
|
|
return this.each( function() {
|
|
var index,
|
|
data = jQuery._data( this ),
|
|
queue = data[ type + "queue" ],
|
|
hooks = data[ type + "queueHooks" ],
|
|
timers = jQuery.timers,
|
|
length = queue ? queue.length : 0;
|
|
|
|
// enable finishing flag on private data
|
|
data.finish = true;
|
|
|
|
// empty the queue first
|
|
jQuery.queue( this, type, [] );
|
|
|
|
if ( hooks && hooks.stop ) {
|
|
hooks.stop.call( this, true );
|
|
}
|
|
|
|
// look for any active animations, and finish them
|
|
for ( index = timers.length; index--; ) {
|
|
if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
|
|
timers[ index ].anim.stop( true );
|
|
timers.splice( index, 1 );
|
|
}
|
|
}
|
|
|
|
// look for any animations in the old queue and finish them
|
|
for ( index = 0; index < length; index++ ) {
|
|
if ( queue[ index ] && queue[ index ].finish ) {
|
|
queue[ index ].finish.call( this );
|
|
}
|
|
}
|
|
|
|
// turn off finishing flag
|
|
delete data.finish;
|
|
} );
|
|
}
|
|
} );
|
|
|
|
jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) {
|
|
var cssFn = jQuery.fn[ name ];
|
|
jQuery.fn[ name ] = function( speed, easing, callback ) {
|
|
return speed == null || typeof speed === "boolean" ?
|
|
cssFn.apply( this, arguments ) :
|
|
this.animate( genFx( name, true ), speed, easing, callback );
|
|
};
|
|
} );
|
|
|
|
// Generate shortcuts for custom animations
|
|
jQuery.each( {
|
|
slideDown: genFx( "show" ),
|
|
slideUp: genFx( "hide" ),
|
|
slideToggle: genFx( "toggle" ),
|
|
fadeIn: { opacity: "show" },
|
|
fadeOut: { opacity: "hide" },
|
|
fadeToggle: { opacity: "toggle" }
|
|
}, function( name, props ) {
|
|
jQuery.fn[ name ] = function( speed, easing, callback ) {
|
|
return this.animate( props, speed, easing, callback );
|
|
};
|
|
} );
|
|
|
|
jQuery.timers = [];
|
|
jQuery.fx.tick = function() {
|
|
var timer,
|
|
timers = jQuery.timers,
|
|
i = 0;
|
|
|
|
fxNow = jQuery.now();
|
|
|
|
for ( ; i < timers.length; i++ ) {
|
|
timer = timers[ i ];
|
|
|
|
// Checks the timer has not already been removed
|
|
if ( !timer() && timers[ i ] === timer ) {
|
|
timers.splice( i--, 1 );
|
|
}
|
|
}
|
|
|
|
if ( !timers.length ) {
|
|
jQuery.fx.stop();
|
|
}
|
|
fxNow = undefined;
|
|
};
|
|
|
|
jQuery.fx.timer = function( timer ) {
|
|
jQuery.timers.push( timer );
|
|
if ( timer() ) {
|
|
jQuery.fx.start();
|
|
} else {
|
|
jQuery.timers.pop();
|
|
}
|
|
};
|
|
|
|
jQuery.fx.interval = 13;
|
|
|
|
jQuery.fx.start = function() {
|
|
if ( !timerId ) {
|
|
timerId = window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
|
|
}
|
|
};
|
|
|
|
jQuery.fx.stop = function() {
|
|
window.clearInterval( timerId );
|
|
timerId = null;
|
|
};
|
|
|
|
jQuery.fx.speeds = {
|
|
slow: 600,
|
|
fast: 200,
|
|
|
|
// Default speed
|
|
_default: 400
|
|
};
|
|
|
|
|
|
// Based off of the plugin by Clint Helfers, with permission.
|
|
// http://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/
|
|
jQuery.fn.delay = function( time, type ) {
|
|
time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
|
|
type = type || "fx";
|
|
|
|
return this.queue( type, function( next, hooks ) {
|
|
var timeout = window.setTimeout( next, time );
|
|
hooks.stop = function() {
|
|
window.clearTimeout( timeout );
|
|
};
|
|
} );
|
|
};
|
|
|
|
|
|
( function() {
|
|
var a,
|
|
input = document.createElement( "input" ),
|
|
div = document.createElement( "div" ),
|
|
select = document.createElement( "select" ),
|
|
opt = select.appendChild( document.createElement( "option" ) );
|
|
|
|
// Setup
|
|
div = document.createElement( "div" );
|
|
div.setAttribute( "className", "t" );
|
|
div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
|
|
a = div.getElementsByTagName( "a" )[ 0 ];
|
|
|
|
// Support: Windows Web Apps (WWA)
|
|
// `type` must use .setAttribute for WWA (#14901)
|
|
input.setAttribute( "type", "checkbox" );
|
|
div.appendChild( input );
|
|
|
|
a = div.getElementsByTagName( "a" )[ 0 ];
|
|
|
|
// First batch of tests.
|
|
a.style.cssText = "top:1px";
|
|
|
|
// Test setAttribute on camelCase class.
|
|
// If it works, we need attrFixes when doing get/setAttribute (ie6/7)
|
|
support.getSetAttribute = div.className !== "t";
|
|
|
|
// Get the style information from getAttribute
|
|
// (IE uses .cssText instead)
|
|
support.style = /top/.test( a.getAttribute( "style" ) );
|
|
|
|
// Make sure that URLs aren't manipulated
|
|
// (IE normalizes it by default)
|
|
support.hrefNormalized = a.getAttribute( "href" ) === "/a";
|
|
|
|
// Check the default checkbox/radio value ("" on WebKit; "on" elsewhere)
|
|
support.checkOn = !!input.value;
|
|
|
|
// Make sure that a selected-by-default option has a working selected property.
|
|
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
|
|
support.optSelected = opt.selected;
|
|
|
|
// Tests for enctype support on a form (#6743)
|
|
support.enctype = !!document.createElement( "form" ).enctype;
|
|
|
|
// Make sure that the options inside disabled selects aren't marked as disabled
|
|
// (WebKit marks them as disabled)
|
|
select.disabled = true;
|
|
support.optDisabled = !opt.disabled;
|
|
|
|
// Support: IE8 only
|
|
// Check if we can trust getAttribute("value")
|
|
input = document.createElement( "input" );
|
|
input.setAttribute( "value", "" );
|
|
support.input = input.getAttribute( "value" ) === "";
|
|
|
|
// Check if an input maintains its value after becoming a radio
|
|
input.value = "t";
|
|
input.setAttribute( "type", "radio" );
|
|
support.radioValue = input.value === "t";
|
|
} )();
|
|
|
|
|
|
var rreturn = /\r/g,
|
|
rspaces = /[\x20\t\r\n\f]+/g;
|
|
|
|
jQuery.fn.extend( {
|
|
val: function( value ) {
|
|
var hooks, ret, isFunction,
|
|
elem = this[ 0 ];
|
|
|
|
if ( !arguments.length ) {
|
|
if ( elem ) {
|
|
hooks = jQuery.valHooks[ elem.type ] ||
|
|
jQuery.valHooks[ elem.nodeName.toLowerCase() ];
|
|
|
|
if (
|
|
hooks &&
|
|
"get" in hooks &&
|
|
( ret = hooks.get( elem, "value" ) ) !== undefined
|
|
) {
|
|
return ret;
|
|
}
|
|
|
|
ret = elem.value;
|
|
|
|
return typeof ret === "string" ?
|
|
|
|
// handle most common string cases
|
|
ret.replace( rreturn, "" ) :
|
|
|
|
// handle cases where value is null/undef or number
|
|
ret == null ? "" : ret;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
isFunction = jQuery.isFunction( value );
|
|
|
|
return this.each( function( i ) {
|
|
var val;
|
|
|
|
if ( this.nodeType !== 1 ) {
|
|
return;
|
|
}
|
|
|
|
if ( isFunction ) {
|
|
val = value.call( this, i, jQuery( this ).val() );
|
|
} else {
|
|
val = value;
|
|
}
|
|
|
|
// Treat null/undefined as ""; convert numbers to string
|
|
if ( val == null ) {
|
|
val = "";
|
|
} else if ( typeof val === "number" ) {
|
|
val += "";
|
|
} else if ( jQuery.isArray( val ) ) {
|
|
val = jQuery.map( val, function( value ) {
|
|
return value == null ? "" : value + "";
|
|
} );
|
|
}
|
|
|
|
hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
|
|
|
|
// If set returns undefined, fall back to normal setting
|
|
if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
|
|
this.value = val;
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
|
|
jQuery.extend( {
|
|
valHooks: {
|
|
option: {
|
|
get: function( elem ) {
|
|
var val = jQuery.find.attr( elem, "value" );
|
|
return val != null ?
|
|
val :
|
|
|
|
// Support: IE10-11+
|
|
// option.text throws exceptions (#14686, #14858)
|
|
// Strip and collapse whitespace
|
|
// https://html.spec.whatwg.org/#strip-and-collapse-whitespace
|
|
jQuery.trim( jQuery.text( elem ) ).replace( rspaces, " " );
|
|
}
|
|
},
|
|
select: {
|
|
get: function( elem ) {
|
|
var value, option,
|
|
options = elem.options,
|
|
index = elem.selectedIndex,
|
|
one = elem.type === "select-one" || index < 0,
|
|
values = one ? null : [],
|
|
max = one ? index + 1 : options.length,
|
|
i = index < 0 ?
|
|
max :
|
|
one ? index : 0;
|
|
|
|
// Loop through all the selected options
|
|
for ( ; i < max; i++ ) {
|
|
option = options[ i ];
|
|
|
|
// oldIE doesn't update selected after form reset (#2551)
|
|
if ( ( option.selected || i === index ) &&
|
|
|
|
// Don't return options that are disabled or in a disabled optgroup
|
|
( support.optDisabled ?
|
|
!option.disabled :
|
|
option.getAttribute( "disabled" ) === null ) &&
|
|
( !option.parentNode.disabled ||
|
|
!jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
|
|
|
|
// Get the specific value for the option
|
|
value = jQuery( option ).val();
|
|
|
|
// We don't need an array for one selects
|
|
if ( one ) {
|
|
return value;
|
|
}
|
|
|
|
// Multi-Selects return an array
|
|
values.push( value );
|
|
}
|
|
}
|
|
|
|
return values;
|
|
},
|
|
|
|
set: function( elem, value ) {
|
|
var optionSet, option,
|
|
options = elem.options,
|
|
values = jQuery.makeArray( value ),
|
|
i = options.length;
|
|
|
|
while ( i-- ) {
|
|
option = options[ i ];
|
|
|
|
if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 ) {
|
|
|
|
// Support: IE6
|
|
// When new option element is added to select box we need to
|
|
// force reflow of newly added node in order to workaround delay
|
|
// of initialization properties
|
|
try {
|
|
option.selected = optionSet = true;
|
|
|
|
} catch ( _ ) {
|
|
|
|
// Will be executed only in IE6
|
|
option.scrollHeight;
|
|
}
|
|
|
|
} else {
|
|
option.selected = false;
|
|
}
|
|
}
|
|
|
|
// Force browsers to behave consistently when non-matching value is set
|
|
if ( !optionSet ) {
|
|
elem.selectedIndex = -1;
|
|
}
|
|
|
|
return options;
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
|
|
// Radios and checkboxes getter/setter
|
|
jQuery.each( [ "radio", "checkbox" ], function() {
|
|
jQuery.valHooks[ this ] = {
|
|
set: function( elem, value ) {
|
|
if ( jQuery.isArray( value ) ) {
|
|
return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
|
|
}
|
|
}
|
|
};
|
|
if ( !support.checkOn ) {
|
|
jQuery.valHooks[ this ].get = function( elem ) {
|
|
return elem.getAttribute( "value" ) === null ? "on" : elem.value;
|
|
};
|
|
}
|
|
} );
|
|
|
|
|
|
|
|
|
|
var nodeHook, boolHook,
|
|
attrHandle = jQuery.expr.attrHandle,
|
|
ruseDefault = /^(?:checked|selected)$/i,
|
|
getSetAttribute = support.getSetAttribute,
|
|
getSetInput = support.input;
|
|
|
|
jQuery.fn.extend( {
|
|
attr: function( name, value ) {
|
|
return access( this, jQuery.attr, name, value, arguments.length > 1 );
|
|
},
|
|
|
|
removeAttr: function( name ) {
|
|
return this.each( function() {
|
|
jQuery.removeAttr( this, name );
|
|
} );
|
|
}
|
|
} );
|
|
|
|
jQuery.extend( {
|
|
attr: function( elem, name, value ) {
|
|
var ret, hooks,
|
|
nType = elem.nodeType;
|
|
|
|
// Don't get/set attributes on text, comment and attribute nodes
|
|
if ( nType === 3 || nType === 8 || nType === 2 ) {
|
|
return;
|
|
}
|
|
|
|
// Fallback to prop when attributes are not supported
|
|
if ( typeof elem.getAttribute === "undefined" ) {
|
|
return jQuery.prop( elem, name, value );
|
|
}
|
|
|
|
// All attributes are lowercase
|
|
// Grab necessary hook if one is defined
|
|
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
|
|
name = name.toLowerCase();
|
|
hooks = jQuery.attrHooks[ name ] ||
|
|
( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
|
|
}
|
|
|
|
if ( value !== undefined ) {
|
|
if ( value === null ) {
|
|
jQuery.removeAttr( elem, name );
|
|
return;
|
|
}
|
|
|
|
if ( hooks && "set" in hooks &&
|
|
( ret = hooks.set( elem, value, name ) ) !== undefined ) {
|
|
return ret;
|
|
}
|
|
|
|
elem.setAttribute( name, value + "" );
|
|
return value;
|
|
}
|
|
|
|
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
|
|
return ret;
|
|
}
|
|
|
|
ret = jQuery.find.attr( elem, name );
|
|
|
|
// Non-existent attributes return null, we normalize to undefined
|
|
return ret == null ? undefined : ret;
|
|
},
|
|
|
|
attrHooks: {
|
|
type: {
|
|
set: function( elem, value ) {
|
|
if ( !support.radioValue && value === "radio" &&
|
|
jQuery.nodeName( elem, "input" ) ) {
|
|
|
|
// Setting the type on a radio button after the value resets the value in IE8-9
|
|
// Reset value to default in case type is set after value during creation
|
|
var val = elem.value;
|
|
elem.setAttribute( "type", value );
|
|
if ( val ) {
|
|
elem.value = val;
|
|
}
|
|
return value;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
removeAttr: function( elem, value ) {
|
|
var name, propName,
|
|
i = 0,
|
|
attrNames = value && value.match( rnotwhite );
|
|
|
|
if ( attrNames && elem.nodeType === 1 ) {
|
|
while ( ( name = attrNames[ i++ ] ) ) {
|
|
propName = jQuery.propFix[ name ] || name;
|
|
|
|
// Boolean attributes get special treatment (#10870)
|
|
if ( jQuery.expr.match.bool.test( name ) ) {
|
|
|
|
// Set corresponding property to false
|
|
if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) {
|
|
elem[ propName ] = false;
|
|
|
|
// Support: IE<9
|
|
// Also clear defaultChecked/defaultSelected (if appropriate)
|
|
} else {
|
|
elem[ jQuery.camelCase( "default-" + name ) ] =
|
|
elem[ propName ] = false;
|
|
}
|
|
|
|
// See #9699 for explanation of this approach (setting first, then removal)
|
|
} else {
|
|
jQuery.attr( elem, name, "" );
|
|
}
|
|
|
|
elem.removeAttribute( getSetAttribute ? name : propName );
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
|
|
// Hooks for boolean attributes
|
|
boolHook = {
|
|
set: function( elem, value, name ) {
|
|
if ( value === false ) {
|
|
|
|
// Remove boolean attributes when set to false
|
|
jQuery.removeAttr( elem, name );
|
|
} else if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) {
|
|
|
|
// IE<8 needs the *property* name
|
|
elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name );
|
|
|
|
} else {
|
|
|
|
// Support: IE<9
|
|
// Use defaultChecked and defaultSelected for oldIE
|
|
elem[ jQuery.camelCase( "default-" + name ) ] = elem[ name ] = true;
|
|
}
|
|
return name;
|
|
}
|
|
};
|
|
|
|
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
|
|
var getter = attrHandle[ name ] || jQuery.find.attr;
|
|
|
|
if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) {
|
|
attrHandle[ name ] = function( elem, name, isXML ) {
|
|
var ret, handle;
|
|
if ( !isXML ) {
|
|
|
|
// Avoid an infinite loop by temporarily removing this function from the getter
|
|
handle = attrHandle[ name ];
|
|
attrHandle[ name ] = ret;
|
|
ret = getter( elem, name, isXML ) != null ?
|
|
name.toLowerCase() :
|
|
null;
|
|
attrHandle[ name ] = handle;
|
|
}
|
|
return ret;
|
|
};
|
|
} else {
|
|
attrHandle[ name ] = function( elem, name, isXML ) {
|
|
if ( !isXML ) {
|
|
return elem[ jQuery.camelCase( "default-" + name ) ] ?
|
|
name.toLowerCase() :
|
|
null;
|
|
}
|
|
};
|
|
}
|
|
} );
|
|
|
|
// fix oldIE attroperties
|
|
if ( !getSetInput || !getSetAttribute ) {
|
|
jQuery.attrHooks.value = {
|
|
set: function( elem, value, name ) {
|
|
if ( jQuery.nodeName( elem, "input" ) ) {
|
|
|
|
// Does not return so that setAttribute is also used
|
|
elem.defaultValue = value;
|
|
} else {
|
|
|
|
// Use nodeHook if defined (#1954); otherwise setAttribute is fine
|
|
return nodeHook && nodeHook.set( elem, value, name );
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
|
if ( !getSetAttribute ) {
|
|
|
|
// Use this for any attribute in IE6/7
|
|
// This fixes almost every IE6/7 issue
|
|
nodeHook = {
|
|
set: function( elem, value, name ) {
|
|
|
|
// Set the existing or create a new attribute node
|
|
var ret = elem.getAttributeNode( name );
|
|
if ( !ret ) {
|
|
elem.setAttributeNode(
|
|
( ret = elem.ownerDocument.createAttribute( name ) )
|
|
);
|
|
}
|
|
|
|
ret.value = value += "";
|
|
|
|
// Break association with cloned elements by also using setAttribute (#9646)
|
|
if ( name === "value" || value === elem.getAttribute( name ) ) {
|
|
return value;
|
|
}
|
|
}
|
|
};
|
|
|
|
// Some attributes are constructed with empty-string values when not defined
|
|
attrHandle.id = attrHandle.name = attrHandle.coords =
|
|
function( elem, name, isXML ) {
|
|
var ret;
|
|
if ( !isXML ) {
|
|
return ( ret = elem.getAttributeNode( name ) ) && ret.value !== "" ?
|
|
ret.value :
|
|
null;
|
|
}
|
|
};
|
|
|
|
// Fixing value retrieval on a button requires this module
|
|
jQuery.valHooks.button = {
|
|
get: function( elem, name ) {
|
|
var ret = elem.getAttributeNode( name );
|
|
if ( ret && ret.specified ) {
|
|
return ret.value;
|
|
}
|
|
},
|
|
set: nodeHook.set
|
|
};
|
|
|
|
// Set contenteditable to false on removals(#10429)
|
|
// Setting to empty string throws an error as an invalid value
|
|
jQuery.attrHooks.contenteditable = {
|
|
set: function( elem, value, name ) {
|
|
nodeHook.set( elem, value === "" ? false : value, name );
|
|
}
|
|
};
|
|
|
|
// Set width and height to auto instead of 0 on empty string( Bug #8150 )
|
|
// This is for removals
|
|
jQuery.each( [ "width", "height" ], function( i, name ) {
|
|
jQuery.attrHooks[ name ] = {
|
|
set: function( elem, value ) {
|
|
if ( value === "" ) {
|
|
elem.setAttribute( name, "auto" );
|
|
return value;
|
|
}
|
|
}
|
|
};
|
|
} );
|
|
}
|
|
|
|
if ( !support.style ) {
|
|
jQuery.attrHooks.style = {
|
|
get: function( elem ) {
|
|
|
|
// Return undefined in the case of empty string
|
|
// Note: IE uppercases css property names, but if we were to .toLowerCase()
|
|
// .cssText, that would destroy case sensitivity in URL's, like in "background"
|
|
return elem.style.cssText || undefined;
|
|
},
|
|
set: function( elem, value ) {
|
|
return ( elem.style.cssText = value + "" );
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
|
|
|
|
var rfocusable = /^(?:input|select|textarea|button|object)$/i,
|
|
rclickable = /^(?:a|area)$/i;
|
|
|
|
jQuery.fn.extend( {
|
|
prop: function( name, value ) {
|
|
return access( this, jQuery.prop, name, value, arguments.length > 1 );
|
|
},
|
|
|
|
removeProp: function( name ) {
|
|
name = jQuery.propFix[ name ] || name;
|
|
return this.each( function() {
|
|
|
|
// try/catch handles cases where IE balks (such as removing a property on window)
|
|
try {
|
|
this[ name ] = undefined;
|
|
delete this[ name ];
|
|
} catch ( e ) {}
|
|
} );
|
|
}
|
|
} );
|
|
|
|
jQuery.extend( {
|
|
prop: function( elem, name, value ) {
|
|
var ret, hooks,
|
|
nType = elem.nodeType;
|
|
|
|
// Don't get/set properties on text, comment and attribute nodes
|
|
if ( nType === 3 || nType === 8 || nType === 2 ) {
|
|
return;
|
|
}
|
|
|
|
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
|
|
|
|
// Fix name and attach hooks
|
|
name = jQuery.propFix[ name ] || name;
|
|
hooks = jQuery.propHooks[ name ];
|
|
}
|
|
|
|
if ( value !== undefined ) {
|
|
if ( hooks && "set" in hooks &&
|
|
( ret = hooks.set( elem, value, name ) ) !== undefined ) {
|
|
return ret;
|
|
}
|
|
|
|
return ( elem[ name ] = value );
|
|
}
|
|
|
|
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
|
|
return ret;
|
|
}
|
|
|
|
return elem[ name ];
|
|
},
|
|
|
|
propHooks: {
|
|
tabIndex: {
|
|
get: function( elem ) {
|
|
|
|
// elem.tabIndex doesn't always return the
|
|
// correct value when it hasn't been explicitly set
|
|
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
|
// Use proper attribute retrieval(#12072)
|
|
var tabindex = jQuery.find.attr( elem, "tabindex" );
|
|
|
|
return tabindex ?
|
|
parseInt( tabindex, 10 ) :
|
|
rfocusable.test( elem.nodeName ) ||
|
|
rclickable.test( elem.nodeName ) && elem.href ?
|
|
0 :
|
|
-1;
|
|
}
|
|
}
|
|
},
|
|
|
|
propFix: {
|
|
"for": "htmlFor",
|
|
"class": "className"
|
|
}
|
|
} );
|
|
|
|
// Some attributes require a special call on IE
|
|
// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
|
|
if ( !support.hrefNormalized ) {
|
|
|
|
// href/src property should get the full normalized URL (#10299/#12915)
|
|
jQuery.each( [ "href", "src" ], function( i, name ) {
|
|
jQuery.propHooks[ name ] = {
|
|
get: function( elem ) {
|
|
return elem.getAttribute( name, 4 );
|
|
}
|
|
};
|
|
} );
|
|
}
|
|
|
|
// Support: Safari, IE9+
|
|
// Accessing the selectedIndex property
|
|
// forces the browser to respect setting selected
|
|
// on the option
|
|
// The getter ensures a default option is selected
|
|
// when in an optgroup
|
|
if ( !support.optSelected ) {
|
|
jQuery.propHooks.selected = {
|
|
get: function( elem ) {
|
|
var parent = elem.parentNode;
|
|
|
|
if ( parent ) {
|
|
parent.selectedIndex;
|
|
|
|
// Make sure that it also works with optgroups, see #5701
|
|
if ( parent.parentNode ) {
|
|
parent.parentNode.selectedIndex;
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
set: function( elem ) {
|
|
var parent = elem.parentNode;
|
|
if ( parent ) {
|
|
parent.selectedIndex;
|
|
|
|
if ( parent.parentNode ) {
|
|
parent.parentNode.selectedIndex;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
jQuery.each( [
|
|
"tabIndex",
|
|
"readOnly",
|
|
"maxLength",
|
|
"cellSpacing",
|
|
"cellPadding",
|
|
"rowSpan",
|
|
"colSpan",
|
|
"useMap",
|
|
"frameBorder",
|
|
"contentEditable"
|
|
], function() {
|
|
jQuery.propFix[ this.toLowerCase() ] = this;
|
|
} );
|
|
|
|
// IE6/7 call enctype encoding
|
|
if ( !support.enctype ) {
|
|
jQuery.propFix.enctype = "encoding";
|
|
}
|
|
|
|
|
|
|
|
|
|
var rclass = /[\t\r\n\f]/g;
|
|
|
|
function getClass( elem ) {
|
|
return jQuery.attr( elem, "class" ) || "";
|
|
}
|
|
|
|
jQuery.fn.extend( {
|
|
addClass: function( value ) {
|
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
|
i = 0;
|
|
|
|
if ( jQuery.isFunction( value ) ) {
|
|
return this.each( function( j ) {
|
|
jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
|
|
} );
|
|
}
|
|
|
|
if ( typeof value === "string" && value ) {
|
|
classes = value.match( rnotwhite ) || [];
|
|
|
|
while ( ( elem = this[ i++ ] ) ) {
|
|
curValue = getClass( elem );
|
|
cur = elem.nodeType === 1 &&
|
|
( " " + curValue + " " ).replace( rclass, " " );
|
|
|
|
if ( cur ) {
|
|
j = 0;
|
|
while ( ( clazz = classes[ j++ ] ) ) {
|
|
if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
|
|
cur += clazz + " ";
|
|
}
|
|
}
|
|
|
|
// only assign if different to avoid unneeded rendering.
|
|
finalValue = jQuery.trim( cur );
|
|
if ( curValue !== finalValue ) {
|
|
jQuery.attr( elem, "class", finalValue );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
removeClass: function( value ) {
|
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
|
i = 0;
|
|
|
|
if ( jQuery.isFunction( value ) ) {
|
|
return this.each( function( j ) {
|
|
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
|
|
} );
|
|
}
|
|
|
|
if ( !arguments.length ) {
|
|
return this.attr( "class", "" );
|
|
}
|
|
|
|
if ( typeof value === "string" && value ) {
|
|
classes = value.match( rnotwhite ) || [];
|
|
|
|
while ( ( elem = this[ i++ ] ) ) {
|
|
curValue = getClass( elem );
|
|
|
|
// This expression is here for better compressibility (see addClass)
|
|
cur = elem.nodeType === 1 &&
|
|
( " " + curValue + " " ).replace( rclass, " " );
|
|
|
|
if ( cur ) {
|
|
j = 0;
|
|
while ( ( clazz = classes[ j++ ] ) ) {
|
|
|
|
// Remove *all* instances
|
|
while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
|
|
cur = cur.replace( " " + clazz + " ", " " );
|
|
}
|
|
}
|
|
|
|
// Only assign if different to avoid unneeded rendering.
|
|
finalValue = jQuery.trim( cur );
|
|
if ( curValue !== finalValue ) {
|
|
jQuery.attr( elem, "class", finalValue );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
toggleClass: function( value, stateVal ) {
|
|
var type = typeof value;
|
|
|
|
if ( typeof stateVal === "boolean" && type === "string" ) {
|
|
return stateVal ? this.addClass( value ) : this.removeClass( value );
|
|
}
|
|
|
|
if ( jQuery.isFunction( value ) ) {
|
|
return this.each( function( i ) {
|
|
jQuery( this ).toggleClass(
|
|
value.call( this, i, getClass( this ), stateVal ),
|
|
stateVal
|
|
);
|
|
} );
|
|
}
|
|
|
|
return this.each( function() {
|
|
var className, i, self, classNames;
|
|
|
|
if ( type === "string" ) {
|
|
|
|
// Toggle individual class names
|
|
i = 0;
|
|
self = jQuery( this );
|
|
classNames = value.match( rnotwhite ) || [];
|
|
|
|
while ( ( className = classNames[ i++ ] ) ) {
|
|
|
|
// Check each className given, space separated list
|
|
if ( self.hasClass( className ) ) {
|
|
self.removeClass( className );
|
|
} else {
|
|
self.addClass( className );
|
|
}
|
|
}
|
|
|
|
// Toggle whole class name
|
|
} else if ( value === undefined || type === "boolean" ) {
|
|
className = getClass( this );
|
|
if ( className ) {
|
|
|
|
// store className if set
|
|
jQuery._data( this, "__className__", className );
|
|
}
|
|
|
|
// If the element has a class name or if we're passed "false",
|
|
// then remove the whole classname (if there was one, the above saved it).
|
|
// Otherwise bring back whatever was previously saved (if anything),
|
|
// falling back to the empty string if nothing was stored.
|
|
jQuery.attr( this, "class",
|
|
className || value === false ?
|
|
"" :
|
|
jQuery._data( this, "__className__" ) || ""
|
|
);
|
|
}
|
|
} );
|
|
},
|
|
|
|
hasClass: function( selector ) {
|
|
var className, elem,
|
|
i = 0;
|
|
|
|
className = " " + selector + " ";
|
|
while ( ( elem = this[ i++ ] ) ) {
|
|
if ( elem.nodeType === 1 &&
|
|
( " " + getClass( elem ) + " " ).replace( rclass, " " )
|
|
.indexOf( className ) > -1
|
|
) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} );
|
|
|
|
|
|
|
|
|
|
// Return jQuery for attributes-only inclusion
|
|
|
|
|
|
jQuery.each( ( "blur focus focusin focusout load resize scroll unload click dblclick " +
|
|
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
|
|
"change select submit keydown keypress keyup error contextmenu" ).split( " " ),
|
|
function( i, name ) {
|
|
|
|
// Handle event binding
|
|
jQuery.fn[ name ] = function( data, fn ) {
|
|
return arguments.length > 0 ?
|
|
this.on( name, null, data, fn ) :
|
|
this.trigger( name );
|
|
};
|
|
} );
|
|
|
|
jQuery.fn.extend( {
|
|
hover: function( fnOver, fnOut ) {
|
|
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
|
|
}
|
|
} );
|
|
|
|
|
|
var location = window.location;
|
|
|
|
var nonce = jQuery.now();
|
|
|
|
var rquery = ( /\?/ );
|
|
|
|
|
|
|
|
var rvalidtokens = /(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g;
|
|
|
|
jQuery.parseJSON = function( data ) {
|
|
|
|
// Attempt to parse using the native JSON parser first
|
|
if ( window.JSON && window.JSON.parse ) {
|
|
|
|
// Support: Android 2.3
|
|
// Workaround failure to string-cast null input
|
|
return window.JSON.parse( data + "" );
|
|
}
|
|
|
|
var requireNonComma,
|
|
depth = null,
|
|
str = jQuery.trim( data + "" );
|
|
|
|
// Guard against invalid (and possibly dangerous) input by ensuring that nothing remains
|
|
// after removing valid tokens
|
|
return str && !jQuery.trim( str.replace( rvalidtokens, function( token, comma, open, close ) {
|
|
|
|
// Force termination if we see a misplaced comma
|
|
if ( requireNonComma && comma ) {
|
|
depth = 0;
|
|
}
|
|
|
|
// Perform no more replacements after returning to outermost depth
|
|
if ( depth === 0 ) {
|
|
return token;
|
|
}
|
|
|
|
// Commas must not follow "[", "{", or ","
|
|
requireNonComma = open || comma;
|
|
|
|
// Determine new depth
|
|
// array/object open ("[" or "{"): depth += true - false (increment)
|
|
// array/object close ("]" or "}"): depth += false - true (decrement)
|
|
// other cases ("," or primitive): depth += true - true (numeric cast)
|
|
depth += !close - !open;
|
|
|
|
// Remove this token
|
|
return "";
|
|
} ) ) ?
|
|
( Function( "return " + str ) )() :
|
|
jQuery.error( "Invalid JSON: " + data );
|
|
};
|
|
|
|
|
|
// Cross-browser xml parsing
|
|
jQuery.parseXML = function( data ) {
|
|
var xml, tmp;
|
|
if ( !data || typeof data !== "string" ) {
|
|
return null;
|
|
}
|
|
try {
|
|
if ( window.DOMParser ) { // Standard
|
|
tmp = new window.DOMParser();
|
|
xml = tmp.parseFromString( data, "text/xml" );
|
|
} else { // IE
|
|
xml = new window.ActiveXObject( "Microsoft.XMLDOM" );
|
|
xml.async = "false";
|
|
xml.loadXML( data );
|
|
}
|
|
} catch ( e ) {
|
|
xml = undefined;
|
|
}
|
|
if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
|
|
jQuery.error( "Invalid XML: " + data );
|
|
}
|
|
return xml;
|
|
};
|
|
|
|
|
|
var
|
|
rhash = /#.*$/,
|
|
rts = /([?&])_=[^&]*/,
|
|
|
|
// IE leaves an \r character at EOL
|
|
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg,
|
|
|
|
// #7653, #8125, #8152: local protocol detection
|
|
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
|
|
rnoContent = /^(?:GET|HEAD)$/,
|
|
rprotocol = /^\/\//,
|
|
rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
|
|
|
|
/* Prefilters
|
|
* 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
|
|
* 2) These are called:
|
|
* - BEFORE asking for a transport
|
|
* - AFTER param serialization (s.data is a string if s.processData is true)
|
|
* 3) key is the dataType
|
|
* 4) the catchall symbol "*" can be used
|
|
* 5) execution will start with transport dataType and THEN continue down to "*" if needed
|
|
*/
|
|
prefilters = {},
|
|
|
|
/* Transports bindings
|
|
* 1) key is the dataType
|
|
* 2) the catchall symbol "*" can be used
|
|
* 3) selection will start with transport dataType and THEN go to "*" if needed
|
|
*/
|
|
transports = {},
|
|
|
|
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
|
|
allTypes = "*/".concat( "*" ),
|
|
|
|
// Document location
|
|
ajaxLocation = location.href,
|
|
|
|
// Segment location into parts
|
|
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
|
|
|
|
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
|
|
function addToPrefiltersOrTransports( structure ) {
|
|
|
|
// dataTypeExpression is optional and defaults to "*"
|
|
return function( dataTypeExpression, func ) {
|
|
|
|
if ( typeof dataTypeExpression !== "string" ) {
|
|
func = dataTypeExpression;
|
|
dataTypeExpression = "*";
|
|
}
|
|
|
|
var dataType,
|
|
i = 0,
|
|
dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
|
|
|
|
if ( jQuery.isFunction( func ) ) {
|
|
|
|
// For each dataType in the dataTypeExpression
|
|
while ( ( dataType = dataTypes[ i++ ] ) ) {
|
|
|
|
// Prepend if requested
|
|
if ( dataType.charAt( 0 ) === "+" ) {
|
|
dataType = dataType.slice( 1 ) || "*";
|
|
( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
|
|
|
|
// Otherwise append
|
|
} else {
|
|
( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
// Base inspection function for prefilters and transports
|
|
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
|
|
|
|
var inspected = {},
|
|
seekingTransport = ( structure === transports );
|
|
|
|
function inspect( dataType ) {
|
|
var selected;
|
|
inspected[ dataType ] = true;
|
|
jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
|
|
var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
|
|
if ( typeof dataTypeOrTransport === "string" &&
|
|
!seekingTransport && !inspected[ dataTypeOrTransport ] ) {
|
|
|
|
options.dataTypes.unshift( dataTypeOrTransport );
|
|
inspect( dataTypeOrTransport );
|
|
return false;
|
|
} else if ( seekingTransport ) {
|
|
return !( selected = dataTypeOrTransport );
|
|
}
|
|
} );
|
|
return selected;
|
|
}
|
|
|
|
return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
|
|
}
|
|
|
|
// A special extend for ajax options
|
|
// that takes "flat" options (not to be deep extended)
|
|
// Fixes #9887
|
|
function ajaxExtend( target, src ) {
|
|
var deep, key,
|
|
flatOptions = jQuery.ajaxSettings.flatOptions || {};
|
|
|
|
for ( key in src ) {
|
|
if ( src[ key ] !== undefined ) {
|
|
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
|
|
}
|
|
}
|
|
if ( deep ) {
|
|
jQuery.extend( true, target, deep );
|
|
}
|
|
|
|
return target;
|
|
}
|
|
|
|
/* Handles responses to an ajax request:
|
|
* - finds the right dataType (mediates between content-type and expected dataType)
|
|
* - returns the corresponding response
|
|
*/
|
|
function ajaxHandleResponses( s, jqXHR, responses ) {
|
|
var firstDataType, ct, finalDataType, type,
|
|
contents = s.contents,
|
|
dataTypes = s.dataTypes;
|
|
|
|
// Remove auto dataType and get content-type in the process
|
|
while ( dataTypes[ 0 ] === "*" ) {
|
|
dataTypes.shift();
|
|
if ( ct === undefined ) {
|
|
ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
|
|
}
|
|
}
|
|
|
|
// Check if we're dealing with a known content-type
|
|
if ( ct ) {
|
|
for ( type in contents ) {
|
|
if ( contents[ type ] && contents[ type ].test( ct ) ) {
|
|
dataTypes.unshift( type );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check to see if we have a response for the expected dataType
|
|
if ( dataTypes[ 0 ] in responses ) {
|
|
finalDataType = dataTypes[ 0 ];
|
|
} else {
|
|
|
|
// Try convertible dataTypes
|
|
for ( type in responses ) {
|
|
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
|
|
finalDataType = type;
|
|
break;
|
|
}
|
|
if ( !firstDataType ) {
|
|
firstDataType = type;
|
|
}
|
|
}
|
|
|
|
// Or just use first one
|
|
finalDataType = finalDataType || firstDataType;
|
|
}
|
|
|
|
// If we found a dataType
|
|
// We add the dataType to the list if needed
|
|
// and return the corresponding response
|
|
if ( finalDataType ) {
|
|
if ( finalDataType !== dataTypes[ 0 ] ) {
|
|
dataTypes.unshift( finalDataType );
|
|
}
|
|
return responses[ finalDataType ];
|
|
}
|
|
}
|
|
|
|
/* Chain conversions given the request and the original response
|
|
* Also sets the responseXXX fields on the jqXHR instance
|
|
*/
|
|
function ajaxConvert( s, response, jqXHR, isSuccess ) {
|
|
var conv2, current, conv, tmp, prev,
|
|
converters = {},
|
|
|
|
// Work with a copy of dataTypes in case we need to modify it for conversion
|
|
dataTypes = s.dataTypes.slice();
|
|
|
|
// Create converters map with lowercased keys
|
|
if ( dataTypes[ 1 ] ) {
|
|
for ( conv in s.converters ) {
|
|
converters[ conv.toLowerCase() ] = s.converters[ conv ];
|
|
}
|
|
}
|
|
|
|
current = dataTypes.shift();
|
|
|
|
// Convert to each sequential dataType
|
|
while ( current ) {
|
|
|
|
if ( s.responseFields[ current ] ) {
|
|
jqXHR[ s.responseFields[ current ] ] = response;
|
|
}
|
|
|
|
// Apply the dataFilter if provided
|
|
if ( !prev && isSuccess && s.dataFilter ) {
|
|
response = s.dataFilter( response, s.dataType );
|
|
}
|
|
|
|
prev = current;
|
|
current = dataTypes.shift();
|
|
|
|
if ( current ) {
|
|
|
|
// There's only work to do if current dataType is non-auto
|
|
if ( current === "*" ) {
|
|
|
|
current = prev;
|
|
|
|
// Convert response if prev dataType is non-auto and differs from current
|
|
} else if ( prev !== "*" && prev !== current ) {
|
|
|
|
// Seek a direct converter
|
|
conv = converters[ prev + " " + current ] || converters[ "* " + current ];
|
|
|
|
// If none found, seek a pair
|
|
if ( !conv ) {
|
|
for ( conv2 in converters ) {
|
|
|
|
// If conv2 outputs current
|
|
tmp = conv2.split( " " );
|
|
if ( tmp[ 1 ] === current ) {
|
|
|
|
// If prev can be converted to accepted input
|
|
conv = converters[ prev + " " + tmp[ 0 ] ] ||
|
|
converters[ "* " + tmp[ 0 ] ];
|
|
if ( conv ) {
|
|
|
|
// Condense equivalence converters
|
|
if ( conv === true ) {
|
|
conv = converters[ conv2 ];
|
|
|
|
// Otherwise, insert the intermediate dataType
|
|
} else if ( converters[ conv2 ] !== true ) {
|
|
current = tmp[ 0 ];
|
|
dataTypes.unshift( tmp[ 1 ] );
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Apply converter (if not an equivalence)
|
|
if ( conv !== true ) {
|
|
|
|
// Unless errors are allowed to bubble, catch and return them
|
|
if ( conv && s[ "throws" ] ) { // jscs:ignore requireDotNotation
|
|
response = conv( response );
|
|
} else {
|
|
try {
|
|
response = conv( response );
|
|
} catch ( e ) {
|
|
return {
|
|
state: "parsererror",
|
|
error: conv ? e : "No conversion from " + prev + " to " + current
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return { state: "success", data: response };
|
|
}
|
|
|
|
jQuery.extend( {
|
|
|
|
// Counter for holding the number of active queries
|
|
active: 0,
|
|
|
|
// Last-Modified header cache for next request
|
|
lastModified: {},
|
|
etag: {},
|
|
|
|
ajaxSettings: {
|
|
url: ajaxLocation,
|
|
type: "GET",
|
|
isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
|
|
global: true,
|
|
processData: true,
|
|
async: true,
|
|
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
|
/*
|
|
timeout: 0,
|
|
data: null,
|
|
dataType: null,
|
|
username: null,
|
|
password: null,
|
|
cache: null,
|
|
throws: false,
|
|
traditional: false,
|
|
headers: {},
|
|
*/
|
|
|
|
accepts: {
|
|
"*": allTypes,
|
|
text: "text/plain",
|
|
html: "text/html",
|
|
xml: "application/xml, text/xml",
|
|
json: "application/json, text/javascript"
|
|
},
|
|
|
|
contents: {
|
|
xml: /\bxml\b/,
|
|
html: /\bhtml/,
|
|
json: /\bjson\b/
|
|
},
|
|
|
|
responseFields: {
|
|
xml: "responseXML",
|
|
text: "responseText",
|
|
json: "responseJSON"
|
|
},
|
|
|
|
// Data converters
|
|
// Keys separate source (or catchall "*") and destination types with a single space
|
|
converters: {
|
|
|
|
// Convert anything to text
|
|
"* text": String,
|
|
|
|
// Text to html (true = no transformation)
|
|
"text html": true,
|
|
|
|
// Evaluate text as a json expression
|
|
"text json": jQuery.parseJSON,
|
|
|
|
// Parse text as xml
|
|
"text xml": jQuery.parseXML
|
|
},
|
|
|
|
// For options that shouldn't be deep extended:
|
|
// you can add your own custom options here if
|
|
// and when you create one that shouldn't be
|
|
// deep extended (see ajaxExtend)
|
|
flatOptions: {
|
|
url: true,
|
|
context: true
|
|
}
|
|
},
|
|
|
|
// Creates a full fledged settings object into target
|
|
// with both ajaxSettings and settings fields.
|
|
// If target is omitted, writes into ajaxSettings.
|
|
ajaxSetup: function( target, settings ) {
|
|
return settings ?
|
|
|
|
// Building a settings object
|
|
ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
|
|
|
|
// Extending ajaxSettings
|
|
ajaxExtend( jQuery.ajaxSettings, target );
|
|
},
|
|
|
|
ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
|
|
ajaxTransport: addToPrefiltersOrTransports( transports ),
|
|
|
|
// Main method
|
|
ajax: function( url, options ) {
|
|
|
|
// If url is an object, simulate pre-1.5 signature
|
|
if ( typeof url === "object" ) {
|
|
options = url;
|
|
url = undefined;
|
|
}
|
|
|
|
// Force options to be an object
|
|
options = options || {};
|
|
|
|
var
|
|
|
|
// Cross-domain detection vars
|
|
parts,
|
|
|
|
// Loop variable
|
|
i,
|
|
|
|
// URL without anti-cache param
|
|
cacheURL,
|
|
|
|
// Response headers as string
|
|
responseHeadersString,
|
|
|
|
// timeout handle
|
|
timeoutTimer,
|
|
|
|
// To know if global events are to be dispatched
|
|
fireGlobals,
|
|
|
|
transport,
|
|
|
|
// Response headers
|
|
responseHeaders,
|
|
|
|
// Create the final options object
|
|
s = jQuery.ajaxSetup( {}, options ),
|
|
|
|
// Callbacks context
|
|
callbackContext = s.context || s,
|
|
|
|
// Context for global events is callbackContext if it is a DOM node or jQuery collection
|
|
globalEventContext = s.context &&
|
|
( callbackContext.nodeType || callbackContext.jquery ) ?
|
|
jQuery( callbackContext ) :
|
|
jQuery.event,
|
|
|
|
// Deferreds
|
|
deferred = jQuery.Deferred(),
|
|
completeDeferred = jQuery.Callbacks( "once memory" ),
|
|
|
|
// Status-dependent callbacks
|
|
statusCode = s.statusCode || {},
|
|
|
|
// Headers (they are sent all at once)
|
|
requestHeaders = {},
|
|
requestHeadersNames = {},
|
|
|
|
// The jqXHR state
|
|
state = 0,
|
|
|
|
// Default abort message
|
|
strAbort = "canceled",
|
|
|
|
// Fake xhr
|
|
jqXHR = {
|
|
readyState: 0,
|
|
|
|
// Builds headers hashtable if needed
|
|
getResponseHeader: function( key ) {
|
|
var match;
|
|
if ( state === 2 ) {
|
|
if ( !responseHeaders ) {
|
|
responseHeaders = {};
|
|
while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
|
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
|
|
}
|
|
}
|
|
match = responseHeaders[ key.toLowerCase() ];
|
|
}
|
|
return match == null ? null : match;
|
|
},
|
|
|
|
// Raw string
|
|
getAllResponseHeaders: function() {
|
|
return state === 2 ? responseHeadersString : null;
|
|
},
|
|
|
|
// Caches the header
|
|
setRequestHeader: function( name, value ) {
|
|
var lname = name.toLowerCase();
|
|
if ( !state ) {
|
|
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
|
|
requestHeaders[ name ] = value;
|
|
}
|
|
return this;
|
|
},
|
|
|
|
// Overrides response content-type header
|
|
overrideMimeType: function( type ) {
|
|
if ( !state ) {
|
|
s.mimeType = type;
|
|
}
|
|
return this;
|
|
},
|
|
|
|
// Status-dependent callbacks
|
|
statusCode: function( map ) {
|
|
var code;
|
|
if ( map ) {
|
|
if ( state < 2 ) {
|
|
for ( code in map ) {
|
|
|
|
// Lazy-add the new callback in a way that preserves old ones
|
|
statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
|
|
}
|
|
} else {
|
|
|
|
// Execute the appropriate callbacks
|
|
jqXHR.always( map[ jqXHR.status ] );
|
|
}
|
|
}
|
|
return this;
|
|
},
|
|
|
|
// Cancel the request
|
|
abort: function( statusText ) {
|
|
var finalText = statusText || strAbort;
|
|
if ( transport ) {
|
|
transport.abort( finalText );
|
|
}
|
|
done( 0, finalText );
|
|
return this;
|
|
}
|
|
};
|
|
|
|
// Attach deferreds
|
|
deferred.promise( jqXHR ).complete = completeDeferred.add;
|
|
jqXHR.success = jqXHR.done;
|
|
jqXHR.error = jqXHR.fail;
|
|
|
|
// Remove hash character (#7531: and string promotion)
|
|
// Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
|
|
// Handle falsy url in the settings object (#10093: consistency with old signature)
|
|
// We also use the url parameter if available
|
|
s.url = ( ( url || s.url || ajaxLocation ) + "" )
|
|
.replace( rhash, "" )
|
|
.replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
|
|
|
|
// Alias method option to type as per ticket #12004
|
|
s.type = options.method || options.type || s.method || s.type;
|
|
|
|
// Extract dataTypes list
|
|
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
|
|
|
|
// A cross-domain request is in order when we have a protocol:host:port mismatch
|
|
if ( s.crossDomain == null ) {
|
|
parts = rurl.exec( s.url.toLowerCase() );
|
|
s.crossDomain = !!( parts &&
|
|
( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
|
|
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
|
|
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
|
|
);
|
|
}
|
|
|
|
// Convert data if not already a string
|
|
if ( s.data && s.processData && typeof s.data !== "string" ) {
|
|
s.data = jQuery.param( s.data, s.traditional );
|
|
}
|
|
|
|
// Apply prefilters
|
|
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
|
|
|
|
// If request was aborted inside a prefilter, stop there
|
|
if ( state === 2 ) {
|
|
return jqXHR;
|
|
}
|
|
|
|
// We can fire global events as of now if asked to
|
|
// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
|
|
fireGlobals = jQuery.event && s.global;
|
|
|
|
// Watch for a new set of requests
|
|
if ( fireGlobals && jQuery.active++ === 0 ) {
|
|
jQuery.event.trigger( "ajaxStart" );
|
|
}
|
|
|
|
// Uppercase the type
|
|
s.type = s.type.toUpperCase();
|
|
|
|
// Determine if request has content
|
|
s.hasContent = !rnoContent.test( s.type );
|
|
|
|
// Save the URL in case we're toying with the If-Modified-Since
|
|
// and/or If-None-Match header later on
|
|
cacheURL = s.url;
|
|
|
|
// More options handling for requests with no content
|
|
if ( !s.hasContent ) {
|
|
|
|
// If data is available, append data to url
|
|
if ( s.data ) {
|
|
cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
|
|
|
|
// #9682: remove data so that it's not used in an eventual retry
|
|
delete s.data;
|
|
}
|
|
|
|
// Add anti-cache in url if needed
|
|
if ( s.cache === false ) {
|
|
s.url = rts.test( cacheURL ) ?
|
|
|
|
// If there is already a '_' parameter, set its value
|
|
cacheURL.replace( rts, "$1_=" + nonce++ ) :
|
|
|
|
// Otherwise add one to the end
|
|
cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
|
|
}
|
|
}
|
|
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
|
if ( s.ifModified ) {
|
|
if ( jQuery.lastModified[ cacheURL ] ) {
|
|
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
|
|
}
|
|
if ( jQuery.etag[ cacheURL ] ) {
|
|
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
|
|
}
|
|
}
|
|
|
|
// Set the correct header, if data is being sent
|
|
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
|
jqXHR.setRequestHeader( "Content-Type", s.contentType );
|
|
}
|
|
|
|
// Set the Accepts header for the server, depending on the dataType
|
|
jqXHR.setRequestHeader(
|
|
"Accept",
|
|
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
|
s.accepts[ s.dataTypes[ 0 ] ] +
|
|
( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
|
|
s.accepts[ "*" ]
|
|
);
|
|
|
|
// Check for headers option
|
|
for ( i in s.headers ) {
|
|
jqXHR.setRequestHeader( i, s.headers[ i ] );
|
|
}
|
|
|
|
// Allow custom headers/mimetypes and early abort
|
|
if ( s.beforeSend &&
|
|
( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
|
|
|
|
// Abort if not done already and return
|
|
return jqXHR.abort();
|
|
}
|
|
|
|
// aborting is no longer a cancellation
|
|
strAbort = "abort";
|
|
|
|
// Install callbacks on deferreds
|
|
for ( i in { success: 1, error: 1, complete: 1 } ) {
|
|
jqXHR[ i ]( s[ i ] );
|
|
}
|
|
|
|
// Get transport
|
|
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
|
|
|
|
// If no transport, we auto-abort
|
|
if ( !transport ) {
|
|
done( -1, "No Transport" );
|
|
} else {
|
|
jqXHR.readyState = 1;
|
|
|
|
// Send global event
|
|
if ( fireGlobals ) {
|
|
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
|
}
|
|
|
|
// If request was aborted inside ajaxSend, stop there
|
|
if ( state === 2 ) {
|
|
return jqXHR;
|
|
}
|
|
|
|
// Timeout
|
|
if ( s.async && s.timeout > 0 ) {
|
|
timeoutTimer = window.setTimeout( function() {
|
|
jqXHR.abort( "timeout" );
|
|
}, s.timeout );
|
|
}
|
|
|
|
try {
|
|
state = 1;
|
|
transport.send( requestHeaders, done );
|
|
} catch ( e ) {
|
|
|
|
// Propagate exception as error if not done
|
|
if ( state < 2 ) {
|
|
done( -1, e );
|
|
|
|
// Simply rethrow otherwise
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Callback for when everything is done
|
|
function done( status, nativeStatusText, responses, headers ) {
|
|
var isSuccess, success, error, response, modified,
|
|
statusText = nativeStatusText;
|
|
|
|
// Called once
|
|
if ( state === 2 ) {
|
|
return;
|
|
}
|
|
|
|
// State is "done" now
|
|
state = 2;
|
|
|
|
// Clear timeout if it exists
|
|
if ( timeoutTimer ) {
|
|
window.clearTimeout( timeoutTimer );
|
|
}
|
|
|
|
// Dereference transport for early garbage collection
|
|
// (no matter how long the jqXHR object will be used)
|
|
transport = undefined;
|
|
|
|
// Cache response headers
|
|
responseHeadersString = headers || "";
|
|
|
|
// Set readyState
|
|
jqXHR.readyState = status > 0 ? 4 : 0;
|
|
|
|
// Determine if successful
|
|
isSuccess = status >= 200 && status < 300 || status === 304;
|
|
|
|
// Get response data
|
|
if ( responses ) {
|
|
response = ajaxHandleResponses( s, jqXHR, responses );
|
|
}
|
|
|
|
// Convert no matter what (that way responseXXX fields are always set)
|
|
response = ajaxConvert( s, response, jqXHR, isSuccess );
|
|
|
|
// If successful, handle type chaining
|
|
if ( isSuccess ) {
|
|
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
|
if ( s.ifModified ) {
|
|
modified = jqXHR.getResponseHeader( "Last-Modified" );
|
|
if ( modified ) {
|
|
jQuery.lastModified[ cacheURL ] = modified;
|
|
}
|
|
modified = jqXHR.getResponseHeader( "etag" );
|
|
if ( modified ) {
|
|
jQuery.etag[ cacheURL ] = modified;
|
|
}
|
|
}
|
|
|
|
// if no content
|
|
if ( status === 204 || s.type === "HEAD" ) {
|
|
statusText = "nocontent";
|
|
|
|
// if not modified
|
|
} else if ( status === 304 ) {
|
|
statusText = "notmodified";
|
|
|
|
// If we have data, let's convert it
|
|
} else {
|
|
statusText = response.state;
|
|
success = response.data;
|
|
error = response.error;
|
|
isSuccess = !error;
|
|
}
|
|
} else {
|
|
|
|
// We extract error from statusText
|
|
// then normalize statusText and status for non-aborts
|
|
error = statusText;
|
|
if ( status || !statusText ) {
|
|
statusText = "error";
|
|
if ( status < 0 ) {
|
|
status = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Set data for the fake xhr object
|
|
jqXHR.status = status;
|
|
jqXHR.statusText = ( nativeStatusText || statusText ) + "";
|
|
|
|
// Success/Error
|
|
if ( isSuccess ) {
|
|
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
|
|
} else {
|
|
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
|
|
}
|
|
|
|
// Status-dependent callbacks
|
|
jqXHR.statusCode( statusCode );
|
|
statusCode = undefined;
|
|
|
|
if ( fireGlobals ) {
|
|
globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
|
|
[ jqXHR, s, isSuccess ? success : error ] );
|
|
}
|
|
|
|
// Complete
|
|
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
|
|
|
|
if ( fireGlobals ) {
|
|
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
|
|
|
|
// Handle the global AJAX counter
|
|
if ( !( --jQuery.active ) ) {
|
|
jQuery.event.trigger( "ajaxStop" );
|
|
}
|
|
}
|
|
}
|
|
|
|
return jqXHR;
|
|
},
|
|
|
|
getJSON: function( url, data, callback ) {
|
|
return jQuery.get( url, data, callback, "json" );
|
|
},
|
|
|
|
getScript: function( url, callback ) {
|
|
return jQuery.get( url, undefined, callback, "script" );
|
|
}
|
|
} );
|
|
|
|
jQuery.each( [ "get", "post" ], function( i, method ) {
|
|
jQuery[ method ] = function( url, data, callback, type ) {
|
|
|
|
// shift arguments if data argument was omitted
|
|
if ( jQuery.isFunction( data ) ) {
|
|
type = type || callback;
|
|
callback = data;
|
|
data = undefined;
|
|
}
|
|
|
|
// The url can be an options object (which then must have .url)
|
|
return jQuery.ajax( jQuery.extend( {
|
|
url: url,
|
|
type: method,
|
|
dataType: type,
|
|
data: data,
|
|
success: callback
|
|
}, jQuery.isPlainObject( url ) && url ) );
|
|
};
|
|
} );
|
|
|
|
|
|
jQuery._evalUrl = function( url ) {
|
|
return jQuery.ajax( {
|
|
url: url,
|
|
|
|
// Make this explicit, since user can override this through ajaxSetup (#11264)
|
|
type: "GET",
|
|
dataType: "script",
|
|
cache: true,
|
|
async: false,
|
|
global: false,
|
|
"throws": true
|
|
} );
|
|
};
|
|
|
|
|
|
jQuery.fn.extend( {
|
|
wrapAll: function( html ) {
|
|
if ( jQuery.isFunction( html ) ) {
|
|
return this.each( function( i ) {
|
|
jQuery( this ).wrapAll( html.call( this, i ) );
|
|
} );
|
|
}
|
|
|
|
if ( this[ 0 ] ) {
|
|
|
|
// The elements to wrap the target around
|
|
var wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
|
|
|
|
if ( this[ 0 ].parentNode ) {
|
|
wrap.insertBefore( this[ 0 ] );
|
|
}
|
|
|
|
wrap.map( function() {
|
|
var elem = this;
|
|
|
|
while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
|
|
elem = elem.firstChild;
|
|
}
|
|
|
|
return elem;
|
|
} ).append( this );
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
wrapInner: function( html ) {
|
|
if ( jQuery.isFunction( html ) ) {
|
|
return this.each( function( i ) {
|
|
jQuery( this ).wrapInner( html.call( this, i ) );
|
|
} );
|
|
}
|
|
|
|
return this.each( function() {
|
|
var self = jQuery( this ),
|
|
contents = self.contents();
|
|
|
|
if ( contents.length ) {
|
|
contents.wrapAll( html );
|
|
|
|
} else {
|
|
self.append( html );
|
|
}
|
|
} );
|
|
},
|
|
|
|
wrap: function( html ) {
|
|
var isFunction = jQuery.isFunction( html );
|
|
|
|
return this.each( function( i ) {
|
|
jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
|
|
} );
|
|
},
|
|
|
|
unwrap: function() {
|
|
return this.parent().each( function() {
|
|
if ( !jQuery.nodeName( this, "body" ) ) {
|
|
jQuery( this ).replaceWith( this.childNodes );
|
|
}
|
|
} ).end();
|
|
}
|
|
} );
|
|
|
|
|
|
function getDisplay( elem ) {
|
|
return elem.style && elem.style.display || jQuery.css( elem, "display" );
|
|
}
|
|
|
|
function filterHidden( elem ) {
|
|
|
|
// Disconnected elements are considered hidden
|
|
if ( !jQuery.contains( elem.ownerDocument || document, elem ) ) {
|
|
return true;
|
|
}
|
|
while ( elem && elem.nodeType === 1 ) {
|
|
if ( getDisplay( elem ) === "none" || elem.type === "hidden" ) {
|
|
return true;
|
|
}
|
|
elem = elem.parentNode;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
jQuery.expr.filters.hidden = function( elem ) {
|
|
|
|
// Support: Opera <= 12.12
|
|
// Opera reports offsetWidths and offsetHeights less than zero on some elements
|
|
return support.reliableHiddenOffsets() ?
|
|
( elem.offsetWidth <= 0 && elem.offsetHeight <= 0 &&
|
|
!elem.getClientRects().length ) :
|
|
filterHidden( elem );
|
|
};
|
|
|
|
jQuery.expr.filters.visible = function( elem ) {
|
|
return !jQuery.expr.filters.hidden( elem );
|
|
};
|
|
|
|
|
|
|
|
|
|
var r20 = /%20/g,
|
|
rbracket = /\[\]$/,
|
|
rCRLF = /\r?\n/g,
|
|
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
|
|
rsubmittable = /^(?:input|select|textarea|keygen)/i;
|
|
|
|
function buildParams( prefix, obj, traditional, add ) {
|
|
var name;
|
|
|
|
if ( jQuery.isArray( obj ) ) {
|
|
|
|
// Serialize array item.
|
|
jQuery.each( obj, function( i, v ) {
|
|
if ( traditional || rbracket.test( prefix ) ) {
|
|
|
|
// Treat each array item as a scalar.
|
|
add( prefix, v );
|
|
|
|
} else {
|
|
|
|
// Item is non-scalar (array or object), encode its numeric index.
|
|
buildParams(
|
|
prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
|
|
v,
|
|
traditional,
|
|
add
|
|
);
|
|
}
|
|
} );
|
|
|
|
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
|
|
|
|
// Serialize object item.
|
|
for ( name in obj ) {
|
|
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
|
}
|
|
|
|
} else {
|
|
|
|
// Serialize scalar item.
|
|
add( prefix, obj );
|
|
}
|
|
}
|
|
|
|
// Serialize an array of form elements or a set of
|
|
// key/values into a query string
|
|
jQuery.param = function( a, traditional ) {
|
|
var prefix,
|
|
s = [],
|
|
add = function( key, value ) {
|
|
|
|
// If value is a function, invoke it and return its value
|
|
value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
|
|
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
|
|
};
|
|
|
|
// Set traditional to true for jQuery <= 1.3.2 behavior.
|
|
if ( traditional === undefined ) {
|
|
traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
|
|
}
|
|
|
|
// If an array was passed in, assume that it is an array of form elements.
|
|
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
|
|
|
// Serialize the form elements
|
|
jQuery.each( a, function() {
|
|
add( this.name, this.value );
|
|
} );
|
|
|
|
} else {
|
|
|
|
// If traditional, encode the "old" way (the way 1.3.2 or older
|
|
// did it), otherwise encode params recursively.
|
|
for ( prefix in a ) {
|
|
buildParams( prefix, a[ prefix ], traditional, add );
|
|
}
|
|
}
|
|
|
|
// Return the resulting serialization
|
|
return s.join( "&" ).replace( r20, "+" );
|
|
};
|
|
|
|
jQuery.fn.extend( {
|
|
serialize: function() {
|
|
return jQuery.param( this.serializeArray() );
|
|
},
|
|
serializeArray: function() {
|
|
return this.map( function() {
|
|
|
|
// Can add propHook for "elements" to filter or add form elements
|
|
var elements = jQuery.prop( this, "elements" );
|
|
return elements ? jQuery.makeArray( elements ) : this;
|
|
} )
|
|
.filter( function() {
|
|
var type = this.type;
|
|
|
|
// Use .is(":disabled") so that fieldset[disabled] works
|
|
return this.name && !jQuery( this ).is( ":disabled" ) &&
|
|
rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
|
|
( this.checked || !rcheckableType.test( type ) );
|
|
} )
|
|
.map( function( i, elem ) {
|
|
var val = jQuery( this ).val();
|
|
|
|
return val == null ?
|
|
null :
|
|
jQuery.isArray( val ) ?
|
|
jQuery.map( val, function( val ) {
|
|
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
|
} ) :
|
|
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
|
} ).get();
|
|
}
|
|
} );
|
|
|
|
|
|
// Create the request object
|
|
// (This is still attached to ajaxSettings for backward compatibility)
|
|
jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ?
|
|
|
|
// Support: IE6-IE8
|
|
function() {
|
|
|
|
// XHR cannot access local files, always use ActiveX for that case
|
|
if ( this.isLocal ) {
|
|
return createActiveXHR();
|
|
}
|
|
|
|
// Support: IE 9-11
|
|
// IE seems to error on cross-domain PATCH requests when ActiveX XHR
|
|
// is used. In IE 9+ always use the native XHR.
|
|
// Note: this condition won't catch Edge as it doesn't define
|
|
// document.documentMode but it also doesn't support ActiveX so it won't
|
|
// reach this code.
|
|
if ( document.documentMode > 8 ) {
|
|
return createStandardXHR();
|
|
}
|
|
|
|
// Support: IE<9
|
|
// oldIE XHR does not support non-RFC2616 methods (#13240)
|
|
// See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx
|
|
// and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9
|
|
// Although this check for six methods instead of eight
|
|
// since IE also does not support "trace" and "connect"
|
|
return /^(get|post|head|put|delete|options)$/i.test( this.type ) &&
|
|
createStandardXHR() || createActiveXHR();
|
|
} :
|
|
|
|
// For all other browsers, use the standard XMLHttpRequest object
|
|
createStandardXHR;
|
|
|
|
var xhrId = 0,
|
|
xhrCallbacks = {},
|
|
xhrSupported = jQuery.ajaxSettings.xhr();
|
|
|
|
// Support: IE<10
|
|
// Open requests must be manually aborted on unload (#5280)
|
|
// See https://support.microsoft.com/kb/2856746 for more info
|
|
if ( window.attachEvent ) {
|
|
window.attachEvent( "onunload", function() {
|
|
for ( var key in xhrCallbacks ) {
|
|
xhrCallbacks[ key ]( undefined, true );
|
|
}
|
|
} );
|
|
}
|
|
|
|
// Determine support properties
|
|
support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
|
|
xhrSupported = support.ajax = !!xhrSupported;
|
|
|
|
// Create transport if the browser can provide an xhr
|
|
if ( xhrSupported ) {
|
|
|
|
jQuery.ajaxTransport( function( options ) {
|
|
|
|
// Cross domain only allowed if supported through XMLHttpRequest
|
|
if ( !options.crossDomain || support.cors ) {
|
|
|
|
var callback;
|
|
|
|
return {
|
|
send: function( headers, complete ) {
|
|
var i,
|
|
xhr = options.xhr(),
|
|
id = ++xhrId;
|
|
|
|
// Open the socket
|
|
xhr.open(
|
|
options.type,
|
|
options.url,
|
|
options.async,
|
|
options.username,
|
|
options.password
|
|
);
|
|
|
|
// Apply custom fields if provided
|
|
if ( options.xhrFields ) {
|
|
for ( i in options.xhrFields ) {
|
|
xhr[ i ] = options.xhrFields[ i ];
|
|
}
|
|
}
|
|
|
|
// Override mime type if needed
|
|
if ( options.mimeType && xhr.overrideMimeType ) {
|
|
xhr.overrideMimeType( options.mimeType );
|
|
}
|
|
|
|
// X-Requested-With header
|
|
// For cross-domain requests, seeing as conditions for a preflight are
|
|
// akin to a jigsaw puzzle, we simply never set it to be sure.
|
|
// (it can always be set on a per-request basis or even using ajaxSetup)
|
|
// For same-domain requests, won't change header if already provided.
|
|
if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) {
|
|
headers[ "X-Requested-With" ] = "XMLHttpRequest";
|
|
}
|
|
|
|
// Set headers
|
|
for ( i in headers ) {
|
|
|
|
// Support: IE<9
|
|
// IE's ActiveXObject throws a 'Type Mismatch' exception when setting
|
|
// request header to a null-value.
|
|
//
|
|
// To keep consistent with other XHR implementations, cast the value
|
|
// to string and ignore `undefined`.
|
|
if ( headers[ i ] !== undefined ) {
|
|
xhr.setRequestHeader( i, headers[ i ] + "" );
|
|
}
|
|
}
|
|
|
|
// Do send the request
|
|
// This may raise an exception which is actually
|
|
// handled in jQuery.ajax (so no try/catch here)
|
|
xhr.send( ( options.hasContent && options.data ) || null );
|
|
|
|
// Listener
|
|
callback = function( _, isAbort ) {
|
|
var status, statusText, responses;
|
|
|
|
// Was never called and is aborted or complete
|
|
if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
|
|
|
|
// Clean up
|
|
delete xhrCallbacks[ id ];
|
|
callback = undefined;
|
|
xhr.onreadystatechange = jQuery.noop;
|
|
|
|
// Abort manually if needed
|
|
if ( isAbort ) {
|
|
if ( xhr.readyState !== 4 ) {
|
|
xhr.abort();
|
|
}
|
|
} else {
|
|
responses = {};
|
|
status = xhr.status;
|
|
|
|
// Support: IE<10
|
|
// Accessing binary-data responseText throws an exception
|
|
// (#11426)
|
|
if ( typeof xhr.responseText === "string" ) {
|
|
responses.text = xhr.responseText;
|
|
}
|
|
|
|
// Firefox throws an exception when accessing
|
|
// statusText for faulty cross-domain requests
|
|
try {
|
|
statusText = xhr.statusText;
|
|
} catch ( e ) {
|
|
|
|
// We normalize with Webkit giving an empty statusText
|
|
statusText = "";
|
|
}
|
|
|
|
// Filter status for non standard behaviors
|
|
|
|
// If the request is local and we have data: assume a success
|
|
// (success with no data won't get notified, that's the best we
|
|
// can do given current implementations)
|
|
if ( !status && options.isLocal && !options.crossDomain ) {
|
|
status = responses.text ? 200 : 404;
|
|
|
|
// IE - #1450: sometimes returns 1223 when it should be 204
|
|
} else if ( status === 1223 ) {
|
|
status = 204;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Call complete if needed
|
|
if ( responses ) {
|
|
complete( status, statusText, responses, xhr.getAllResponseHeaders() );
|
|
}
|
|
};
|
|
|
|
// Do send the request
|
|
// `xhr.send` may raise an exception, but it will be
|
|
// handled in jQuery.ajax (so no try/catch here)
|
|
if ( !options.async ) {
|
|
|
|
// If we're in sync mode we fire the callback
|
|
callback();
|
|
} else if ( xhr.readyState === 4 ) {
|
|
|
|
// (IE6 & IE7) if it's in cache and has been
|
|
// retrieved directly we need to fire the callback
|
|
window.setTimeout( callback );
|
|
} else {
|
|
|
|
// Register the callback, but delay it in case `xhr.send` throws
|
|
// Add to the list of active xhr callbacks
|
|
xhr.onreadystatechange = xhrCallbacks[ id ] = callback;
|
|
}
|
|
},
|
|
|
|
abort: function() {
|
|
if ( callback ) {
|
|
callback( undefined, true );
|
|
}
|
|
}
|
|
};
|
|
}
|
|
} );
|
|
}
|
|
|
|
// Functions to create xhrs
|
|
function createStandardXHR() {
|
|
try {
|
|
return new window.XMLHttpRequest();
|
|
} catch ( e ) {}
|
|
}
|
|
|
|
function createActiveXHR() {
|
|
try {
|
|
return new window.ActiveXObject( "Microsoft.XMLHTTP" );
|
|
} catch ( e ) {}
|
|
}
|
|
|
|
|
|
|
|
|
|
// Install script dataType
|
|
jQuery.ajaxSetup( {
|
|
accepts: {
|
|
script: "text/javascript, application/javascript, " +
|
|
"application/ecmascript, application/x-ecmascript"
|
|
},
|
|
contents: {
|
|
script: /\b(?:java|ecma)script\b/
|
|
},
|
|
converters: {
|
|
"text script": function( text ) {
|
|
jQuery.globalEval( text );
|
|
return text;
|
|
}
|
|
}
|
|
} );
|
|
|
|
// Handle cache's special case and global
|
|
jQuery.ajaxPrefilter( "script", function( s ) {
|
|
if ( s.cache === undefined ) {
|
|
s.cache = false;
|
|
}
|
|
if ( s.crossDomain ) {
|
|
s.type = "GET";
|
|
s.global = false;
|
|
}
|
|
} );
|
|
|
|
// Bind script tag hack transport
|
|
jQuery.ajaxTransport( "script", function( s ) {
|
|
|
|
// This transport only deals with cross domain requests
|
|
if ( s.crossDomain ) {
|
|
|
|
var script,
|
|
head = document.head || jQuery( "head" )[ 0 ] || document.documentElement;
|
|
|
|
return {
|
|
|
|
send: function( _, callback ) {
|
|
|
|
script = document.createElement( "script" );
|
|
|
|
script.async = true;
|
|
|
|
if ( s.scriptCharset ) {
|
|
script.charset = s.scriptCharset;
|
|
}
|
|
|
|
script.src = s.url;
|
|
|
|
// Attach handlers for all browsers
|
|
script.onload = script.onreadystatechange = function( _, isAbort ) {
|
|
|
|
if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
|
|
|
|
// Handle memory leak in IE
|
|
script.onload = script.onreadystatechange = null;
|
|
|
|
// Remove the script
|
|
if ( script.parentNode ) {
|
|
script.parentNode.removeChild( script );
|
|
}
|
|
|
|
// Dereference the script
|
|
script = null;
|
|
|
|
// Callback if not abort
|
|
if ( !isAbort ) {
|
|
callback( 200, "success" );
|
|
}
|
|
}
|
|
};
|
|
|
|
// Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending
|
|
// Use native DOM manipulation to avoid our domManip AJAX trickery
|
|
head.insertBefore( script, head.firstChild );
|
|
},
|
|
|
|
abort: function() {
|
|
if ( script ) {
|
|
script.onload( undefined, true );
|
|
}
|
|
}
|
|
};
|
|
}
|
|
} );
|
|
|
|
|
|
|
|
|
|
var oldCallbacks = [],
|
|
rjsonp = /(=)\?(?=&|$)|\?\?/;
|
|
|
|
// Default jsonp settings
|
|
jQuery.ajaxSetup( {
|
|
jsonp: "callback",
|
|
jsonpCallback: function() {
|
|
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
|
|
this[ callback ] = true;
|
|
return callback;
|
|
}
|
|
} );
|
|
|
|
// Detect, normalize options and install callbacks for jsonp requests
|
|
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
|
|
|
var callbackName, overwritten, responseContainer,
|
|
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
|
|
"url" :
|
|
typeof s.data === "string" &&
|
|
( s.contentType || "" )
|
|
.indexOf( "application/x-www-form-urlencoded" ) === 0 &&
|
|
rjsonp.test( s.data ) && "data"
|
|
);
|
|
|
|
// Handle iff the expected data type is "jsonp" or we have a parameter to set
|
|
if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
|
|
|
|
// Get callback name, remembering preexisting value associated with it
|
|
callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
|
|
s.jsonpCallback() :
|
|
s.jsonpCallback;
|
|
|
|
// Insert callback into url or form data
|
|
if ( jsonProp ) {
|
|
s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
|
|
} else if ( s.jsonp !== false ) {
|
|
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
|
|
}
|
|
|
|
// Use data converter to retrieve json after script execution
|
|
s.converters[ "script json" ] = function() {
|
|
if ( !responseContainer ) {
|
|
jQuery.error( callbackName + " was not called" );
|
|
}
|
|
return responseContainer[ 0 ];
|
|
};
|
|
|
|
// force json dataType
|
|
s.dataTypes[ 0 ] = "json";
|
|
|
|
// Install callback
|
|
overwritten = window[ callbackName ];
|
|
window[ callbackName ] = function() {
|
|
responseContainer = arguments;
|
|
};
|
|
|
|
// Clean-up function (fires after converters)
|
|
jqXHR.always( function() {
|
|
|
|
// If previous value didn't exist - remove it
|
|
if ( overwritten === undefined ) {
|
|
jQuery( window ).removeProp( callbackName );
|
|
|
|
// Otherwise restore preexisting value
|
|
} else {
|
|
window[ callbackName ] = overwritten;
|
|
}
|
|
|
|
// Save back as free
|
|
if ( s[ callbackName ] ) {
|
|
|
|
// make sure that re-using the options doesn't screw things around
|
|
s.jsonpCallback = originalSettings.jsonpCallback;
|
|
|
|
// save the callback name for future use
|
|
oldCallbacks.push( callbackName );
|
|
}
|
|
|
|
// Call if it was a function and we have a response
|
|
if ( responseContainer && jQuery.isFunction( overwritten ) ) {
|
|
overwritten( responseContainer[ 0 ] );
|
|
}
|
|
|
|
responseContainer = overwritten = undefined;
|
|
} );
|
|
|
|
// Delegate to script
|
|
return "script";
|
|
}
|
|
} );
|
|
|
|
|
|
|
|
|
|
// data: string of html
|
|
// context (optional): If specified, the fragment will be created in this context,
|
|
// defaults to document
|
|
// keepScripts (optional): If true, will include scripts passed in the html string
|
|
jQuery.parseHTML = function( data, context, keepScripts ) {
|
|
if ( !data || typeof data !== "string" ) {
|
|
return null;
|
|
}
|
|
if ( typeof context === "boolean" ) {
|
|
keepScripts = context;
|
|
context = false;
|
|
}
|
|
context = context || document;
|
|
|
|
var parsed = rsingleTag.exec( data ),
|
|
scripts = !keepScripts && [];
|
|
|
|
// Single tag
|
|
if ( parsed ) {
|
|
return [ context.createElement( parsed[ 1 ] ) ];
|
|
}
|
|
|
|
parsed = buildFragment( [ data ], context, scripts );
|
|
|
|
if ( scripts && scripts.length ) {
|
|
jQuery( scripts ).remove();
|
|
}
|
|
|
|
return jQuery.merge( [], parsed.childNodes );
|
|
};
|
|
|
|
|
|
// Keep a copy of the old load method
|
|
var _load = jQuery.fn.load;
|
|
|
|
/**
|
|
* Load a url into a page
|
|
*/
|
|
jQuery.fn.load = function( url, params, callback ) {
|
|
if ( typeof url !== "string" && _load ) {
|
|
return _load.apply( this, arguments );
|
|
}
|
|
|
|
var selector, type, response,
|
|
self = this,
|
|
off = url.indexOf( " " );
|
|
|
|
if ( off > -1 ) {
|
|
selector = jQuery.trim( url.slice( off, url.length ) );
|
|
url = url.slice( 0, off );
|
|
}
|
|
|
|
// If it's a function
|
|
if ( jQuery.isFunction( params ) ) {
|
|
|
|
// We assume that it's the callback
|
|
callback = params;
|
|
params = undefined;
|
|
|
|
// Otherwise, build a param string
|
|
} else if ( params && typeof params === "object" ) {
|
|
type = "POST";
|
|
}
|
|
|
|
// If we have elements to modify, make the request
|
|
if ( self.length > 0 ) {
|
|
jQuery.ajax( {
|
|
url: url,
|
|
|
|
// If "type" variable is undefined, then "GET" method will be used.
|
|
// Make value of this field explicit since
|
|
// user can override it through ajaxSetup method
|
|
type: type || "GET",
|
|
dataType: "html",
|
|
data: params
|
|
} ).done( function( responseText ) {
|
|
|
|
// Save response for use in complete callback
|
|
response = arguments;
|
|
|
|
self.html( selector ?
|
|
|
|
// If a selector was specified, locate the right elements in a dummy div
|
|
// Exclude scripts to avoid IE 'Permission Denied' errors
|
|
jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
|
|
|
|
// Otherwise use the full result
|
|
responseText );
|
|
|
|
// If the request succeeds, this function gets "data", "status", "jqXHR"
|
|
// but they are ignored because response was set above.
|
|
// If it fails, this function gets "jqXHR", "status", "error"
|
|
} ).always( callback && function( jqXHR, status ) {
|
|
self.each( function() {
|
|
callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
|
|
} );
|
|
} );
|
|
}
|
|
|
|
return this;
|
|
};
|
|
|
|
|
|
|
|
|
|
// Attach a bunch of functions for handling common AJAX events
|
|
jQuery.each( [
|
|
"ajaxStart",
|
|
"ajaxStop",
|
|
"ajaxComplete",
|
|
"ajaxError",
|
|
"ajaxSuccess",
|
|
"ajaxSend"
|
|
], function( i, type ) {
|
|
jQuery.fn[ type ] = function( fn ) {
|
|
return this.on( type, fn );
|
|
};
|
|
} );
|
|
|
|
|
|
|
|
|
|
jQuery.expr.filters.animated = function( elem ) {
|
|
return jQuery.grep( jQuery.timers, function( fn ) {
|
|
return elem === fn.elem;
|
|
} ).length;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Gets a window from an element
|
|
*/
|
|
function getWindow( elem ) {
|
|
return jQuery.isWindow( elem ) ?
|
|
elem :
|
|
elem.nodeType === 9 ?
|
|
elem.defaultView || elem.parentWindow :
|
|
false;
|
|
}
|
|
|
|
jQuery.offset = {
|
|
setOffset: function( elem, options, i ) {
|
|
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
|
|
position = jQuery.css( elem, "position" ),
|
|
curElem = jQuery( elem ),
|
|
props = {};
|
|
|
|
// set position first, in-case top/left are set even on static elem
|
|
if ( position === "static" ) {
|
|
elem.style.position = "relative";
|
|
}
|
|
|
|
curOffset = curElem.offset();
|
|
curCSSTop = jQuery.css( elem, "top" );
|
|
curCSSLeft = jQuery.css( elem, "left" );
|
|
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
|
|
jQuery.inArray( "auto", [ curCSSTop, curCSSLeft ] ) > -1;
|
|
|
|
// need to be able to calculate position if either top or left
|
|
// is auto and position is either absolute or fixed
|
|
if ( calculatePosition ) {
|
|
curPosition = curElem.position();
|
|
curTop = curPosition.top;
|
|
curLeft = curPosition.left;
|
|
} else {
|
|
curTop = parseFloat( curCSSTop ) || 0;
|
|
curLeft = parseFloat( curCSSLeft ) || 0;
|
|
}
|
|
|
|
if ( jQuery.isFunction( options ) ) {
|
|
|
|
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
|
|
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
|
|
}
|
|
|
|
if ( options.top != null ) {
|
|
props.top = ( options.top - curOffset.top ) + curTop;
|
|
}
|
|
if ( options.left != null ) {
|
|
props.left = ( options.left - curOffset.left ) + curLeft;
|
|
}
|
|
|
|
if ( "using" in options ) {
|
|
options.using.call( elem, props );
|
|
} else {
|
|
curElem.css( props );
|
|
}
|
|
}
|
|
};
|
|
|
|
jQuery.fn.extend( {
|
|
offset: function( options ) {
|
|
if ( arguments.length ) {
|
|
return options === undefined ?
|
|
this :
|
|
this.each( function( i ) {
|
|
jQuery.offset.setOffset( this, options, i );
|
|
} );
|
|
}
|
|
|
|
var docElem, win,
|
|
box = { top: 0, left: 0 },
|
|
elem = this[ 0 ],
|
|
doc = elem && elem.ownerDocument;
|
|
|
|
if ( !doc ) {
|
|
return;
|
|
}
|
|
|
|
docElem = doc.documentElement;
|
|
|
|
// Make sure it's not a disconnected DOM node
|
|
if ( !jQuery.contains( docElem, elem ) ) {
|
|
return box;
|
|
}
|
|
|
|
// If we don't have gBCR, just use 0,0 rather than error
|
|
// BlackBerry 5, iOS 3 (original iPhone)
|
|
if ( typeof elem.getBoundingClientRect !== "undefined" ) {
|
|
box = elem.getBoundingClientRect();
|
|
}
|
|
win = getWindow( doc );
|
|
return {
|
|
top: box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
|
|
left: box.left + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
|
|
};
|
|
},
|
|
|
|
position: function() {
|
|
if ( !this[ 0 ] ) {
|
|
return;
|
|
}
|
|
|
|
var offsetParent, offset,
|
|
parentOffset = { top: 0, left: 0 },
|
|
elem = this[ 0 ];
|
|
|
|
// Fixed elements are offset from window (parentOffset = {top:0, left: 0},
|
|
// because it is its only offset parent
|
|
if ( jQuery.css( elem, "position" ) === "fixed" ) {
|
|
|
|
// we assume that getBoundingClientRect is available when computed position is fixed
|
|
offset = elem.getBoundingClientRect();
|
|
} else {
|
|
|
|
// Get *real* offsetParent
|
|
offsetParent = this.offsetParent();
|
|
|
|
// Get correct offsets
|
|
offset = this.offset();
|
|
if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
|
|
parentOffset = offsetParent.offset();
|
|
}
|
|
|
|
// Add offsetParent borders
|
|
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
|
|
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
|
|
}
|
|
|
|
// Subtract parent offsets and element margins
|
|
// note: when an element has margin: auto the offsetLeft and marginLeft
|
|
// are the same in Safari causing offset.left to incorrectly be 0
|
|
return {
|
|
top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
|
|
left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
|
|
};
|
|
},
|
|
|
|
offsetParent: function() {
|
|
return this.map( function() {
|
|
var offsetParent = this.offsetParent;
|
|
|
|
while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) &&
|
|
jQuery.css( offsetParent, "position" ) === "static" ) ) {
|
|
offsetParent = offsetParent.offsetParent;
|
|
}
|
|
return offsetParent || documentElement;
|
|
} );
|
|
}
|
|
} );
|
|
|
|
// Create scrollLeft and scrollTop methods
|
|
jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
|
|
var top = /Y/.test( prop );
|
|
|
|
jQuery.fn[ method ] = function( val ) {
|
|
return access( this, function( elem, method, val ) {
|
|
var win = getWindow( elem );
|
|
|
|
if ( val === undefined ) {
|
|
return win ? ( prop in win ) ? win[ prop ] :
|
|
win.document.documentElement[ method ] :
|
|
elem[ method ];
|
|
}
|
|
|
|
if ( win ) {
|
|
win.scrollTo(
|
|
!top ? val : jQuery( win ).scrollLeft(),
|
|
top ? val : jQuery( win ).scrollTop()
|
|
);
|
|
|
|
} else {
|
|
elem[ method ] = val;
|
|
}
|
|
}, method, val, arguments.length, null );
|
|
};
|
|
} );
|
|
|
|
// Support: Safari<7-8+, Chrome<37-44+
|
|
// Add the top/left cssHooks using jQuery.fn.position
|
|
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
|
|
// getComputedStyle returns percent when specified for top/left/bottom/right
|
|
// rather than make the css module depend on the offset module, we just check for it here
|
|
jQuery.each( [ "top", "left" ], function( i, prop ) {
|
|
jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
|
|
function( elem, computed ) {
|
|
if ( computed ) {
|
|
computed = curCSS( elem, prop );
|
|
|
|
// if curCSS returns percentage, fallback to offset
|
|
return rnumnonpx.test( computed ) ?
|
|
jQuery( elem ).position()[ prop ] + "px" :
|
|
computed;
|
|
}
|
|
}
|
|
);
|
|
} );
|
|
|
|
|
|
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
|
|
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
|
|
jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name },
|
|
function( defaultExtra, funcName ) {
|
|
|
|
// margin is only for outerHeight, outerWidth
|
|
jQuery.fn[ funcName ] = function( margin, value ) {
|
|
var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
|
|
extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
|
|
|
|
return access( this, function( elem, type, value ) {
|
|
var doc;
|
|
|
|
if ( jQuery.isWindow( elem ) ) {
|
|
|
|
// As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
|
|
// isn't a whole lot we can do. See pull request at this URL for discussion:
|
|
// https://github.com/jquery/jquery/pull/764
|
|
return elem.document.documentElement[ "client" + name ];
|
|
}
|
|
|
|
// Get document width or height
|
|
if ( elem.nodeType === 9 ) {
|
|
doc = elem.documentElement;
|
|
|
|
// Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
|
|
// whichever is greatest
|
|
// unfortunately, this causes bug #3838 in IE6/8 only,
|
|
// but there is currently no good, small way to fix it.
|
|
return Math.max(
|
|
elem.body[ "scroll" + name ], doc[ "scroll" + name ],
|
|
elem.body[ "offset" + name ], doc[ "offset" + name ],
|
|
doc[ "client" + name ]
|
|
);
|
|
}
|
|
|
|
return value === undefined ?
|
|
|
|
// Get width or height on the element, requesting but not forcing parseFloat
|
|
jQuery.css( elem, type, extra ) :
|
|
|
|
// Set width or height on the element
|
|
jQuery.style( elem, type, value, extra );
|
|
}, type, chainable ? margin : undefined, chainable, null );
|
|
};
|
|
} );
|
|
} );
|
|
|
|
|
|
jQuery.fn.extend( {
|
|
|
|
bind: function( types, data, fn ) {
|
|
return this.on( types, null, data, fn );
|
|
},
|
|
unbind: function( types, fn ) {
|
|
return this.off( types, null, fn );
|
|
},
|
|
|
|
delegate: function( selector, types, data, fn ) {
|
|
return this.on( types, selector, data, fn );
|
|
},
|
|
undelegate: function( selector, types, fn ) {
|
|
|
|
// ( namespace ) or ( selector, types [, fn] )
|
|
return arguments.length === 1 ?
|
|
this.off( selector, "**" ) :
|
|
this.off( types, selector || "**", fn );
|
|
}
|
|
} );
|
|
|
|
// The number of elements contained in the matched element set
|
|
jQuery.fn.size = function() {
|
|
return this.length;
|
|
};
|
|
|
|
jQuery.fn.andSelf = jQuery.fn.addBack;
|
|
|
|
|
|
|
|
|
|
// Register as a named AMD module, since jQuery can be concatenated with other
|
|
// files that may use define, but not via a proper concatenation script that
|
|
// understands anonymous AMD modules. A named AMD is safest and most robust
|
|
// way to register. Lowercase jquery is used because AMD module names are
|
|
// derived from file names, and jQuery is normally delivered in a lowercase
|
|
// file name. Do this after creating the global so that if an AMD module wants
|
|
// to call noConflict to hide this version of jQuery, it will work.
|
|
|
|
// Note that for maximum portability, libraries that are not jQuery should
|
|
// declare themselves as anonymous modules, and avoid setting a global if an
|
|
// AMD loader is present. jQuery is a special case. For more information, see
|
|
// https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
define( "jquery", [], function() {
|
|
return jQuery;
|
|
} );
|
|
}
|
|
|
|
|
|
|
|
var
|
|
|
|
// Map over jQuery in case of overwrite
|
|
_jQuery = window.jQuery,
|
|
|
|
// Map over the $ in case of overwrite
|
|
_$ = window.$;
|
|
|
|
jQuery.noConflict = function( deep ) {
|
|
if ( window.$ === jQuery ) {
|
|
window.$ = _$;
|
|
}
|
|
|
|
if ( deep && window.jQuery === jQuery ) {
|
|
window.jQuery = _jQuery;
|
|
}
|
|
|
|
return jQuery;
|
|
};
|
|
|
|
// Expose jQuery and $ identifiers, even in
|
|
// AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
|
|
// and CommonJS for browser emulators (#13566)
|
|
if ( !noGlobal ) {
|
|
window.jQuery = window.$ = jQuery;
|
|
}
|
|
|
|
return jQuery;
|
|
}));
|
|
|
|
/*!
|
|
Chosen, a Select Box Enhancer for jQuery and Prototype
|
|
by Patrick Filler for Harvest, http://getharvest.com
|
|
|
|
Version 1.1.0
|
|
Full source at https://github.com/harvesthq/chosen
|
|
Copyright (c) 2011 Harvest http://getharvest.com
|
|
|
|
MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
|
|
This file is generated by `grunt build`, do not edit it by hand.
|
|
*/
|
|
|
|
(function() {
|
|
var $, AbstractChosen, Chosen, SelectParser, _ref,
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
SelectParser = (function() {
|
|
function SelectParser() {
|
|
this.options_index = 0;
|
|
this.parsed = [];
|
|
}
|
|
|
|
SelectParser.prototype.add_node = function(child) {
|
|
if (child.nodeName.toUpperCase() === "OPTGROUP") {
|
|
return this.add_group(child);
|
|
} else {
|
|
return this.add_option(child);
|
|
}
|
|
};
|
|
|
|
SelectParser.prototype.add_group = function(group) {
|
|
var group_position, option, _i, _len, _ref, _results;
|
|
group_position = this.parsed.length;
|
|
this.parsed.push({
|
|
array_index: group_position,
|
|
group: true,
|
|
label: this.escapeExpression(group.label),
|
|
children: 0,
|
|
disabled: group.disabled
|
|
});
|
|
_ref = group.childNodes;
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
option = _ref[_i];
|
|
_results.push(this.add_option(option, group_position, group.disabled));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
|
|
if (option.nodeName.toUpperCase() === "OPTION") {
|
|
if (option.text !== "") {
|
|
if (group_position != null) {
|
|
this.parsed[group_position].children += 1;
|
|
}
|
|
this.parsed.push({
|
|
array_index: this.parsed.length,
|
|
options_index: this.options_index,
|
|
value: option.value,
|
|
text: option.text,
|
|
html: option.innerHTML,
|
|
selected: option.selected,
|
|
disabled: group_disabled === true ? group_disabled : option.disabled,
|
|
group_array_index: group_position,
|
|
classes: option.className,
|
|
style: option.style.cssText
|
|
});
|
|
} else {
|
|
this.parsed.push({
|
|
array_index: this.parsed.length,
|
|
options_index: this.options_index,
|
|
empty: true
|
|
});
|
|
}
|
|
return this.options_index += 1;
|
|
}
|
|
};
|
|
|
|
SelectParser.prototype.escapeExpression = function(text) {
|
|
var map, unsafe_chars;
|
|
if ((text == null) || text === false) {
|
|
return "";
|
|
}
|
|
if (!/[\&\<\>\"\'\`]/.test(text)) {
|
|
return text;
|
|
}
|
|
map = {
|
|
"<": "<",
|
|
">": ">",
|
|
'"': """,
|
|
"'": "'",
|
|
"`": "`"
|
|
};
|
|
unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g;
|
|
return text.replace(unsafe_chars, function(chr) {
|
|
return map[chr] || "&";
|
|
});
|
|
};
|
|
|
|
return SelectParser;
|
|
|
|
})();
|
|
|
|
SelectParser.select_to_array = function(select) {
|
|
var child, parser, _i, _len, _ref;
|
|
parser = new SelectParser();
|
|
_ref = select.childNodes;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
parser.add_node(child);
|
|
}
|
|
return parser.parsed;
|
|
};
|
|
|
|
AbstractChosen = (function() {
|
|
function AbstractChosen(form_field, options) {
|
|
this.form_field = form_field;
|
|
this.options = options != null ? options : {};
|
|
if (!AbstractChosen.browser_is_supported()) {
|
|
return;
|
|
}
|
|
this.is_multiple = this.form_field.multiple;
|
|
this.set_default_text();
|
|
this.set_default_values();
|
|
this.setup();
|
|
this.set_up_html();
|
|
this.register_observers();
|
|
}
|
|
|
|
AbstractChosen.prototype.set_default_values = function() {
|
|
var _this = this;
|
|
this.click_test_action = function(evt) {
|
|
return _this.test_active_click(evt);
|
|
};
|
|
this.activate_action = function(evt) {
|
|
return _this.activate_field(evt);
|
|
};
|
|
this.active_field = false;
|
|
this.mouse_on_container = false;
|
|
this.results_showing = false;
|
|
this.result_highlighted = null;
|
|
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
|
|
this.disable_search_threshold = this.options.disable_search_threshold || 0;
|
|
this.disable_search = this.options.disable_search || false;
|
|
this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
|
|
this.group_search = this.options.group_search != null ? this.options.group_search : true;
|
|
this.search_contains = this.options.search_contains || false;
|
|
this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
|
|
this.max_selected_options = this.options.max_selected_options || Infinity;
|
|
this.inherit_select_classes = this.options.inherit_select_classes || false;
|
|
this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
|
|
return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
|
|
};
|
|
|
|
AbstractChosen.prototype.set_default_text = function() {
|
|
if (this.form_field.getAttribute("data-placeholder")) {
|
|
this.default_text = this.form_field.getAttribute("data-placeholder");
|
|
} else if (this.is_multiple) {
|
|
this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
|
|
} else {
|
|
this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
|
|
}
|
|
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
|
|
};
|
|
|
|
AbstractChosen.prototype.mouse_enter = function() {
|
|
return this.mouse_on_container = true;
|
|
};
|
|
|
|
AbstractChosen.prototype.mouse_leave = function() {
|
|
return this.mouse_on_container = false;
|
|
};
|
|
|
|
AbstractChosen.prototype.input_focus = function(evt) {
|
|
var _this = this;
|
|
if (this.is_multiple) {
|
|
if (!this.active_field) {
|
|
return setTimeout((function() {
|
|
return _this.container_mousedown();
|
|
}), 50);
|
|
}
|
|
} else {
|
|
if (!this.active_field) {
|
|
return this.activate_field();
|
|
}
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.input_blur = function(evt) {
|
|
var _this = this;
|
|
if (!this.mouse_on_container) {
|
|
this.active_field = false;
|
|
return setTimeout((function() {
|
|
return _this.blur_test();
|
|
}), 100);
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.results_option_build = function(options) {
|
|
var content, data, _i, _len, _ref;
|
|
content = '';
|
|
_ref = this.results_data;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
data = _ref[_i];
|
|
if (data.group) {
|
|
content += this.result_add_group(data);
|
|
} else {
|
|
content += this.result_add_option(data);
|
|
}
|
|
if (options != null ? options.first : void 0) {
|
|
if (data.selected && this.is_multiple) {
|
|
this.choice_build(data);
|
|
} else if (data.selected && !this.is_multiple) {
|
|
this.single_set_selected_text(data.text);
|
|
}
|
|
}
|
|
}
|
|
return content;
|
|
};
|
|
|
|
AbstractChosen.prototype.result_add_option = function(option) {
|
|
var classes, option_el;
|
|
if (!option.search_match) {
|
|
return '';
|
|
}
|
|
if (!this.include_option_in_results(option)) {
|
|
return '';
|
|
}
|
|
classes = [];
|
|
if (!option.disabled && !(option.selected && this.is_multiple)) {
|
|
classes.push("active-result");
|
|
}
|
|
if (option.disabled && !(option.selected && this.is_multiple)) {
|
|
classes.push("disabled-result");
|
|
}
|
|
if (option.selected) {
|
|
classes.push("result-selected");
|
|
}
|
|
if (option.group_array_index != null) {
|
|
classes.push("group-option");
|
|
}
|
|
if (option.classes !== "") {
|
|
classes.push(option.classes);
|
|
}
|
|
option_el = document.createElement("li");
|
|
option_el.className = classes.join(" ");
|
|
option_el.style.cssText = option.style;
|
|
option_el.setAttribute("data-option-array-index", option.array_index);
|
|
option_el.innerHTML = option.search_text;
|
|
return this.outerHTML(option_el);
|
|
};
|
|
|
|
AbstractChosen.prototype.result_add_group = function(group) {
|
|
var group_el;
|
|
if (!(group.search_match || group.group_match)) {
|
|
return '';
|
|
}
|
|
if (!(group.active_options > 0)) {
|
|
return '';
|
|
}
|
|
group_el = document.createElement("li");
|
|
group_el.className = "group-result";
|
|
group_el.innerHTML = group.search_text;
|
|
return this.outerHTML(group_el);
|
|
};
|
|
|
|
AbstractChosen.prototype.results_update_field = function() {
|
|
this.set_default_text();
|
|
if (!this.is_multiple) {
|
|
this.results_reset_cleanup();
|
|
}
|
|
this.result_clear_highlight();
|
|
this.results_build();
|
|
if (this.results_showing) {
|
|
return this.winnow_results();
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.reset_single_select_options = function() {
|
|
var result, _i, _len, _ref, _results;
|
|
_ref = this.results_data;
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
result = _ref[_i];
|
|
if (result.selected) {
|
|
_results.push(result.selected = false);
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
AbstractChosen.prototype.results_toggle = function() {
|
|
if (this.results_showing) {
|
|
return this.results_hide();
|
|
} else {
|
|
return this.results_show();
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.results_search = function(evt) {
|
|
if (this.results_showing) {
|
|
return this.winnow_results();
|
|
} else {
|
|
return this.results_show();
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.winnow_results = function() {
|
|
var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
|
|
this.no_results_clear();
|
|
results = 0;
|
|
searchText = this.get_search_text();
|
|
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
regexAnchor = this.search_contains ? "" : "^";
|
|
regex = new RegExp(regexAnchor + escapedSearchText, 'i');
|
|
zregex = new RegExp(escapedSearchText, 'i');
|
|
_ref = this.results_data;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
option = _ref[_i];
|
|
option.search_match = false;
|
|
results_group = null;
|
|
if (this.include_option_in_results(option)) {
|
|
if (option.group) {
|
|
option.group_match = false;
|
|
option.active_options = 0;
|
|
}
|
|
if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
|
|
results_group = this.results_data[option.group_array_index];
|
|
if (results_group.active_options === 0 && results_group.search_match) {
|
|
results += 1;
|
|
}
|
|
results_group.active_options += 1;
|
|
}
|
|
if (!(option.group && !this.group_search)) {
|
|
option.search_text = option.group ? option.label : option.html;
|
|
option.search_match = this.search_string_match(option.search_text, regex);
|
|
if (option.search_match && !option.group) {
|
|
results += 1;
|
|
}
|
|
if (option.search_match) {
|
|
if (searchText.length) {
|
|
startpos = option.search_text.search(zregex);
|
|
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
|
|
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
|
|
}
|
|
if (results_group != null) {
|
|
results_group.group_match = true;
|
|
}
|
|
} else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
|
|
option.search_match = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.result_clear_highlight();
|
|
if (results < 1 && searchText.length) {
|
|
this.update_results_content("");
|
|
return this.no_results(searchText);
|
|
} else {
|
|
this.update_results_content(this.results_option_build());
|
|
return this.winnow_results_set_highlight();
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.search_string_match = function(search_string, regex) {
|
|
var part, parts, _i, _len;
|
|
if (regex.test(search_string)) {
|
|
return true;
|
|
} else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
|
|
parts = search_string.replace(/\[|\]/g, "").split(" ");
|
|
if (parts.length) {
|
|
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
|
part = parts[_i];
|
|
if (regex.test(part)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.choices_count = function() {
|
|
var option, _i, _len, _ref;
|
|
if (this.selected_option_count != null) {
|
|
return this.selected_option_count;
|
|
}
|
|
this.selected_option_count = 0;
|
|
_ref = this.form_field.options;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
option = _ref[_i];
|
|
if (option.selected) {
|
|
this.selected_option_count += 1;
|
|
}
|
|
}
|
|
return this.selected_option_count;
|
|
};
|
|
|
|
AbstractChosen.prototype.choices_click = function(evt) {
|
|
evt.preventDefault();
|
|
if (!(this.results_showing || this.is_disabled)) {
|
|
return this.results_show();
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.keyup_checker = function(evt) {
|
|
var stroke, _ref;
|
|
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
|
this.search_field_scale();
|
|
switch (stroke) {
|
|
case 8:
|
|
if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
|
|
return this.keydown_backstroke();
|
|
} else if (!this.pending_backstroke) {
|
|
this.result_clear_highlight();
|
|
return this.results_search();
|
|
}
|
|
break;
|
|
case 13:
|
|
evt.preventDefault();
|
|
if (this.results_showing) {
|
|
return this.result_select(evt);
|
|
}
|
|
break;
|
|
case 27:
|
|
if (this.results_showing) {
|
|
this.results_hide();
|
|
}
|
|
return true;
|
|
case 9:
|
|
case 38:
|
|
case 40:
|
|
case 16:
|
|
case 91:
|
|
case 17:
|
|
break;
|
|
default:
|
|
return this.results_search();
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.clipboard_event_checker = function(evt) {
|
|
var _this = this;
|
|
return setTimeout((function() {
|
|
return _this.results_search();
|
|
}), 50);
|
|
};
|
|
|
|
AbstractChosen.prototype.container_width = function() {
|
|
if (this.options.width != null) {
|
|
return this.options.width;
|
|
} else {
|
|
return "" + this.form_field.offsetWidth + "px";
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.include_option_in_results = function(option) {
|
|
if (this.is_multiple && (!this.display_selected_options && option.selected)) {
|
|
return false;
|
|
}
|
|
if (!this.display_disabled_options && option.disabled) {
|
|
return false;
|
|
}
|
|
if (option.empty) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
AbstractChosen.prototype.search_results_touchstart = function(evt) {
|
|
this.touch_started = true;
|
|
return this.search_results_mouseover(evt);
|
|
};
|
|
|
|
AbstractChosen.prototype.search_results_touchmove = function(evt) {
|
|
this.touch_started = false;
|
|
return this.search_results_mouseout(evt);
|
|
};
|
|
|
|
AbstractChosen.prototype.search_results_touchend = function(evt) {
|
|
if (this.touch_started) {
|
|
return this.search_results_mouseup(evt);
|
|
}
|
|
};
|
|
|
|
AbstractChosen.prototype.outerHTML = function(element) {
|
|
var tmp;
|
|
if (element.outerHTML) {
|
|
return element.outerHTML;
|
|
}
|
|
tmp = document.createElement("div");
|
|
tmp.appendChild(element);
|
|
return tmp.innerHTML;
|
|
};
|
|
|
|
AbstractChosen.browser_is_supported = function() {
|
|
if (window.navigator.appName === "Microsoft Internet Explorer") {
|
|
return document.documentMode >= 8;
|
|
}
|
|
if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
|
|
return false;
|
|
}
|
|
if (/Android/i.test(window.navigator.userAgent)) {
|
|
if (/Mobile/i.test(window.navigator.userAgent)) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
AbstractChosen.default_multiple_text = "Select Some Options";
|
|
|
|
AbstractChosen.default_single_text = "Select an Option";
|
|
|
|
AbstractChosen.default_no_result_text = "No results match";
|
|
|
|
return AbstractChosen;
|
|
|
|
})();
|
|
|
|
$ = jQuery;
|
|
|
|
$.fn.extend({
|
|
chosen: function(options) {
|
|
if (!AbstractChosen.browser_is_supported()) {
|
|
return this;
|
|
}
|
|
return this.each(function(input_field) {
|
|
var $this, chosen;
|
|
$this = $(this);
|
|
chosen = $this.data('chosen');
|
|
if (options === 'destroy' && chosen) {
|
|
chosen.destroy();
|
|
} else if (!chosen) {
|
|
$this.data('chosen', new Chosen(this, options));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
Chosen = (function(_super) {
|
|
__extends(Chosen, _super);
|
|
|
|
function Chosen() {
|
|
_ref = Chosen.__super__.constructor.apply(this, arguments);
|
|
return _ref;
|
|
}
|
|
|
|
Chosen.prototype.setup = function() {
|
|
this.form_field_jq = $(this.form_field);
|
|
this.current_selectedIndex = this.form_field.selectedIndex;
|
|
return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
|
|
};
|
|
|
|
Chosen.prototype.set_up_html = function() {
|
|
var container_classes, container_props;
|
|
container_classes = ["chosen-container"];
|
|
container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
|
|
if (this.inherit_select_classes && this.form_field.className) {
|
|
container_classes.push(this.form_field.className);
|
|
}
|
|
if (this.is_rtl) {
|
|
container_classes.push("chosen-rtl");
|
|
}
|
|
container_props = {
|
|
'class': container_classes.join(' '),
|
|
'style': "width: " + (this.container_width()) + ";",
|
|
'title': this.form_field.title
|
|
};
|
|
if (this.form_field.id.length) {
|
|
container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
|
|
}
|
|
this.container = $("<div />", container_props);
|
|
if (this.is_multiple) {
|
|
this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');
|
|
} else {
|
|
this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
|
|
}
|
|
this.form_field_jq.hide().after(this.container);
|
|
this.dropdown = this.container.find('div.chosen-drop').first();
|
|
this.search_field = this.container.find('input').first();
|
|
this.search_results = this.container.find('ul.chosen-results').first();
|
|
this.search_field_scale();
|
|
this.search_no_results = this.container.find('li.no-results').first();
|
|
if (this.is_multiple) {
|
|
this.search_choices = this.container.find('ul.chosen-choices').first();
|
|
this.search_container = this.container.find('li.search-field').first();
|
|
} else {
|
|
this.search_container = this.container.find('div.chosen-search').first();
|
|
this.selected_item = this.container.find('.chosen-single').first();
|
|
}
|
|
this.results_build();
|
|
this.set_tab_index();
|
|
this.set_label_behavior();
|
|
return this.form_field_jq.trigger("chosen:ready", {
|
|
chosen: this
|
|
});
|
|
};
|
|
|
|
Chosen.prototype.register_observers = function() {
|
|
var _this = this;
|
|
this.container.bind('mousedown.chosen', function(evt) {
|
|
_this.container_mousedown(evt);
|
|
});
|
|
this.container.bind('mouseup.chosen', function(evt) {
|
|
_this.container_mouseup(evt);
|
|
});
|
|
this.container.bind('mouseenter.chosen', function(evt) {
|
|
_this.mouse_enter(evt);
|
|
});
|
|
this.container.bind('mouseleave.chosen', function(evt) {
|
|
_this.mouse_leave(evt);
|
|
});
|
|
this.search_results.bind('mouseup.chosen', function(evt) {
|
|
_this.search_results_mouseup(evt);
|
|
});
|
|
this.search_results.bind('mouseover.chosen', function(evt) {
|
|
_this.search_results_mouseover(evt);
|
|
});
|
|
this.search_results.bind('mouseout.chosen', function(evt) {
|
|
_this.search_results_mouseout(evt);
|
|
});
|
|
this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
|
|
_this.search_results_mousewheel(evt);
|
|
});
|
|
this.search_results.bind('touchstart.chosen', function(evt) {
|
|
_this.search_results_touchstart(evt);
|
|
});
|
|
this.search_results.bind('touchmove.chosen', function(evt) {
|
|
_this.search_results_touchmove(evt);
|
|
});
|
|
this.search_results.bind('touchend.chosen', function(evt) {
|
|
_this.search_results_touchend(evt);
|
|
});
|
|
this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
|
|
_this.results_update_field(evt);
|
|
});
|
|
this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
|
|
_this.activate_field(evt);
|
|
});
|
|
this.form_field_jq.bind("chosen:open.chosen", function(evt) {
|
|
_this.container_mousedown(evt);
|
|
});
|
|
this.form_field_jq.bind("chosen:close.chosen", function(evt) {
|
|
_this.input_blur(evt);
|
|
});
|
|
this.search_field.bind('blur.chosen', function(evt) {
|
|
_this.input_blur(evt);
|
|
});
|
|
this.search_field.bind('keyup.chosen', function(evt) {
|
|
_this.keyup_checker(evt);
|
|
});
|
|
this.search_field.bind('keydown.chosen', function(evt) {
|
|
_this.keydown_checker(evt);
|
|
});
|
|
this.search_field.bind('focus.chosen', function(evt) {
|
|
_this.input_focus(evt);
|
|
});
|
|
this.search_field.bind('cut.chosen', function(evt) {
|
|
_this.clipboard_event_checker(evt);
|
|
});
|
|
this.search_field.bind('paste.chosen', function(evt) {
|
|
_this.clipboard_event_checker(evt);
|
|
});
|
|
if (this.is_multiple) {
|
|
return this.search_choices.bind('click.chosen', function(evt) {
|
|
_this.choices_click(evt);
|
|
});
|
|
} else {
|
|
return this.container.bind('click.chosen', function(evt) {
|
|
evt.preventDefault();
|
|
});
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.destroy = function() {
|
|
$(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
|
|
if (this.search_field[0].tabIndex) {
|
|
this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
|
|
}
|
|
this.container.remove();
|
|
this.form_field_jq.removeData('chosen');
|
|
return this.form_field_jq.show();
|
|
};
|
|
|
|
Chosen.prototype.search_field_disabled = function() {
|
|
this.is_disabled = this.form_field_jq[0].disabled;
|
|
if (this.is_disabled) {
|
|
this.container.addClass('chosen-disabled');
|
|
this.search_field[0].disabled = true;
|
|
if (!this.is_multiple) {
|
|
this.selected_item.unbind("focus.chosen", this.activate_action);
|
|
}
|
|
return this.close_field();
|
|
} else {
|
|
this.container.removeClass('chosen-disabled');
|
|
this.search_field[0].disabled = false;
|
|
if (!this.is_multiple) {
|
|
return this.selected_item.bind("focus.chosen", this.activate_action);
|
|
}
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.container_mousedown = function(evt) {
|
|
if (!this.is_disabled) {
|
|
if (evt && evt.type === "mousedown" && !this.results_showing) {
|
|
evt.preventDefault();
|
|
}
|
|
if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
|
|
if (!this.active_field) {
|
|
if (this.is_multiple) {
|
|
this.search_field.val("");
|
|
}
|
|
$(this.container[0].ownerDocument).bind('click.chosen', this.click_test_action);
|
|
this.results_show();
|
|
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
|
|
evt.preventDefault();
|
|
this.results_toggle();
|
|
}
|
|
return this.activate_field();
|
|
}
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.container_mouseup = function(evt) {
|
|
if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
|
|
return this.results_reset(evt);
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.search_results_mousewheel = function(evt) {
|
|
var delta;
|
|
if (evt.originalEvent) {
|
|
delta = -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
|
|
}
|
|
if (delta != null) {
|
|
evt.preventDefault();
|
|
if (evt.type === 'DOMMouseScroll') {
|
|
delta = delta * 40;
|
|
}
|
|
return this.search_results.scrollTop(delta + this.search_results.scrollTop());
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.blur_test = function(evt) {
|
|
if (!this.active_field && this.container.hasClass("chosen-container-active")) {
|
|
return this.close_field();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.close_field = function() {
|
|
$(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
|
|
this.active_field = false;
|
|
this.results_hide();
|
|
this.container.removeClass("chosen-container-active");
|
|
this.clear_backstroke();
|
|
this.show_search_field_default();
|
|
return this.search_field_scale();
|
|
};
|
|
|
|
Chosen.prototype.activate_field = function() {
|
|
this.container.addClass("chosen-container-active");
|
|
this.active_field = true;
|
|
this.search_field.val(this.search_field.val());
|
|
return this.search_field.focus();
|
|
};
|
|
|
|
Chosen.prototype.test_active_click = function(evt) {
|
|
var active_container;
|
|
active_container = $(evt.target).closest('.chosen-container');
|
|
if (active_container.length && this.container[0] === active_container[0]) {
|
|
return this.active_field = true;
|
|
} else {
|
|
return this.close_field();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.results_build = function() {
|
|
this.parsing = true;
|
|
this.selected_option_count = null;
|
|
this.results_data = SelectParser.select_to_array(this.form_field);
|
|
if (this.is_multiple) {
|
|
this.search_choices.find("li.search-choice").remove();
|
|
} else if (!this.is_multiple) {
|
|
this.single_set_selected_text();
|
|
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
|
|
this.search_field[0].readOnly = true;
|
|
this.container.addClass("chosen-container-single-nosearch");
|
|
} else {
|
|
this.search_field[0].readOnly = false;
|
|
this.container.removeClass("chosen-container-single-nosearch");
|
|
}
|
|
}
|
|
this.update_results_content(this.results_option_build({
|
|
first: true
|
|
}));
|
|
this.search_field_disabled();
|
|
this.show_search_field_default();
|
|
this.search_field_scale();
|
|
return this.parsing = false;
|
|
};
|
|
|
|
Chosen.prototype.result_do_highlight = function(el) {
|
|
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
|
|
if (el.length) {
|
|
this.result_clear_highlight();
|
|
this.result_highlight = el;
|
|
this.result_highlight.addClass("highlighted");
|
|
maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
|
|
visible_top = this.search_results.scrollTop();
|
|
visible_bottom = maxHeight + visible_top;
|
|
high_top = this.result_highlight.position().top + this.search_results.scrollTop();
|
|
high_bottom = high_top + this.result_highlight.outerHeight();
|
|
if (high_bottom >= visible_bottom) {
|
|
return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
|
|
} else if (high_top < visible_top) {
|
|
return this.search_results.scrollTop(high_top);
|
|
}
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.result_clear_highlight = function() {
|
|
if (this.result_highlight) {
|
|
this.result_highlight.removeClass("highlighted");
|
|
}
|
|
return this.result_highlight = null;
|
|
};
|
|
|
|
Chosen.prototype.results_show = function() {
|
|
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
|
|
this.form_field_jq.trigger("chosen:maxselected", {
|
|
chosen: this
|
|
});
|
|
return false;
|
|
}
|
|
this.container.addClass("chosen-with-drop");
|
|
this.results_showing = true;
|
|
this.search_field.focus();
|
|
this.search_field.val(this.search_field.val());
|
|
this.winnow_results();
|
|
return this.form_field_jq.trigger("chosen:showing_dropdown", {
|
|
chosen: this
|
|
});
|
|
};
|
|
|
|
Chosen.prototype.update_results_content = function(content) {
|
|
return this.search_results.html(content);
|
|
};
|
|
|
|
Chosen.prototype.results_hide = function() {
|
|
if (this.results_showing) {
|
|
this.result_clear_highlight();
|
|
this.container.removeClass("chosen-with-drop");
|
|
this.form_field_jq.trigger("chosen:hiding_dropdown", {
|
|
chosen: this
|
|
});
|
|
}
|
|
return this.results_showing = false;
|
|
};
|
|
|
|
Chosen.prototype.set_tab_index = function(el) {
|
|
var ti;
|
|
if (this.form_field.tabIndex) {
|
|
ti = this.form_field.tabIndex;
|
|
this.form_field.tabIndex = -1;
|
|
return this.search_field[0].tabIndex = ti;
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.set_label_behavior = function() {
|
|
var _this = this;
|
|
this.form_field_label = this.form_field_jq.parents("label");
|
|
if (!this.form_field_label.length && this.form_field.id.length) {
|
|
this.form_field_label = $("label[for='" + this.form_field.id + "']");
|
|
}
|
|
if (this.form_field_label.length > 0) {
|
|
return this.form_field_label.bind('click.chosen', function(evt) {
|
|
if (_this.is_multiple) {
|
|
return _this.container_mousedown(evt);
|
|
} else {
|
|
return _this.activate_field();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.show_search_field_default = function() {
|
|
if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
|
|
this.search_field.val(this.default_text);
|
|
return this.search_field.addClass("default");
|
|
} else {
|
|
this.search_field.val("");
|
|
return this.search_field.removeClass("default");
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.search_results_mouseup = function(evt) {
|
|
var target;
|
|
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
|
if (target.length) {
|
|
this.result_highlight = target;
|
|
this.result_select(evt);
|
|
return this.search_field.focus();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.search_results_mouseover = function(evt) {
|
|
var target;
|
|
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
|
if (target) {
|
|
return this.result_do_highlight(target);
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.search_results_mouseout = function(evt) {
|
|
if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
|
|
return this.result_clear_highlight();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.choice_build = function(item) {
|
|
var choice, close_link,
|
|
_this = this;
|
|
choice = $('<li />', {
|
|
"class": "search-choice"
|
|
}).html("<span>" + item.html + "</span>");
|
|
if (item.disabled) {
|
|
choice.addClass('search-choice-disabled');
|
|
} else {
|
|
close_link = $('<a />', {
|
|
"class": 'search-choice-close',
|
|
'data-option-array-index': item.array_index
|
|
});
|
|
close_link.bind('click.chosen', function(evt) {
|
|
return _this.choice_destroy_link_click(evt);
|
|
});
|
|
choice.append(close_link);
|
|
}
|
|
return this.search_container.before(choice);
|
|
};
|
|
|
|
Chosen.prototype.choice_destroy_link_click = function(evt) {
|
|
evt.preventDefault();
|
|
evt.stopPropagation();
|
|
if (!this.is_disabled) {
|
|
return this.choice_destroy($(evt.target));
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.choice_destroy = function(link) {
|
|
if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
|
|
this.show_search_field_default();
|
|
if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
|
|
this.results_hide();
|
|
}
|
|
link.parents('li').first().remove();
|
|
return this.search_field_scale();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.results_reset = function() {
|
|
this.reset_single_select_options();
|
|
this.form_field.options[0].selected = true;
|
|
this.single_set_selected_text();
|
|
this.show_search_field_default();
|
|
this.results_reset_cleanup();
|
|
this.form_field_jq.trigger("change");
|
|
if (this.active_field) {
|
|
return this.results_hide();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.results_reset_cleanup = function() {
|
|
this.current_selectedIndex = this.form_field.selectedIndex;
|
|
return this.selected_item.find("abbr").remove();
|
|
};
|
|
|
|
Chosen.prototype.result_select = function(evt) {
|
|
var high, item;
|
|
if (this.result_highlight) {
|
|
high = this.result_highlight;
|
|
this.result_clear_highlight();
|
|
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
|
|
this.form_field_jq.trigger("chosen:maxselected", {
|
|
chosen: this
|
|
});
|
|
return false;
|
|
}
|
|
if (this.is_multiple) {
|
|
high.removeClass("active-result");
|
|
} else {
|
|
this.reset_single_select_options();
|
|
}
|
|
item = this.results_data[high[0].getAttribute("data-option-array-index")];
|
|
item.selected = true;
|
|
this.form_field.options[item.options_index].selected = true;
|
|
this.selected_option_count = null;
|
|
if (this.is_multiple) {
|
|
this.choice_build(item);
|
|
} else {
|
|
this.single_set_selected_text(item.text);
|
|
}
|
|
if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
|
|
this.results_hide();
|
|
}
|
|
this.search_field.val("");
|
|
if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
|
|
this.form_field_jq.trigger("change", {
|
|
'selected': this.form_field.options[item.options_index].value
|
|
});
|
|
}
|
|
this.current_selectedIndex = this.form_field.selectedIndex;
|
|
return this.search_field_scale();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.single_set_selected_text = function(text) {
|
|
if (text == null) {
|
|
text = this.default_text;
|
|
}
|
|
if (text === this.default_text) {
|
|
this.selected_item.addClass("chosen-default");
|
|
} else {
|
|
this.single_deselect_control_build();
|
|
this.selected_item.removeClass("chosen-default");
|
|
}
|
|
return this.selected_item.find("span").text(text);
|
|
};
|
|
|
|
Chosen.prototype.result_deselect = function(pos) {
|
|
var result_data;
|
|
result_data = this.results_data[pos];
|
|
if (!this.form_field.options[result_data.options_index].disabled) {
|
|
result_data.selected = false;
|
|
this.form_field.options[result_data.options_index].selected = false;
|
|
this.selected_option_count = null;
|
|
this.result_clear_highlight();
|
|
if (this.results_showing) {
|
|
this.winnow_results();
|
|
}
|
|
this.form_field_jq.trigger("change", {
|
|
deselected: this.form_field.options[result_data.options_index].value
|
|
});
|
|
this.search_field_scale();
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.single_deselect_control_build = function() {
|
|
if (!this.allow_single_deselect) {
|
|
return;
|
|
}
|
|
if (!this.selected_item.find("abbr").length) {
|
|
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
|
|
}
|
|
return this.selected_item.addClass("chosen-single-with-deselect");
|
|
};
|
|
|
|
Chosen.prototype.get_search_text = function() {
|
|
if (this.search_field.val() === this.default_text) {
|
|
return "";
|
|
} else {
|
|
return $('<div/>').text($.trim(this.search_field.val())).html();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.winnow_results_set_highlight = function() {
|
|
var do_high, selected_results;
|
|
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
|
|
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
|
|
if (do_high != null) {
|
|
return this.result_do_highlight(do_high);
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.no_results = function(terms) {
|
|
var no_results_html;
|
|
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
|
|
no_results_html.find("span").first().html(terms);
|
|
this.search_results.append(no_results_html);
|
|
return this.form_field_jq.trigger("chosen:no_results", {
|
|
chosen: this
|
|
});
|
|
};
|
|
|
|
Chosen.prototype.no_results_clear = function() {
|
|
return this.search_results.find(".no-results").remove();
|
|
};
|
|
|
|
Chosen.prototype.keydown_arrow = function() {
|
|
var next_sib;
|
|
if (this.results_showing && this.result_highlight) {
|
|
next_sib = this.result_highlight.nextAll("li.active-result").first();
|
|
if (next_sib) {
|
|
return this.result_do_highlight(next_sib);
|
|
}
|
|
} else {
|
|
return this.results_show();
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.keyup_arrow = function() {
|
|
var prev_sibs;
|
|
if (!this.results_showing && !this.is_multiple) {
|
|
return this.results_show();
|
|
} else if (this.result_highlight) {
|
|
prev_sibs = this.result_highlight.prevAll("li.active-result");
|
|
if (prev_sibs.length) {
|
|
return this.result_do_highlight(prev_sibs.first());
|
|
} else {
|
|
if (this.choices_count() > 0) {
|
|
this.results_hide();
|
|
}
|
|
return this.result_clear_highlight();
|
|
}
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.keydown_backstroke = function() {
|
|
var next_available_destroy;
|
|
if (this.pending_backstroke) {
|
|
this.choice_destroy(this.pending_backstroke.find("a").first());
|
|
return this.clear_backstroke();
|
|
} else {
|
|
next_available_destroy = this.search_container.siblings("li.search-choice").last();
|
|
if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
|
|
this.pending_backstroke = next_available_destroy;
|
|
if (this.single_backstroke_delete) {
|
|
return this.keydown_backstroke();
|
|
} else {
|
|
return this.pending_backstroke.addClass("search-choice-focus");
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.clear_backstroke = function() {
|
|
if (this.pending_backstroke) {
|
|
this.pending_backstroke.removeClass("search-choice-focus");
|
|
}
|
|
return this.pending_backstroke = null;
|
|
};
|
|
|
|
Chosen.prototype.keydown_checker = function(evt) {
|
|
var stroke, _ref1;
|
|
stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
|
|
this.search_field_scale();
|
|
if (stroke !== 8 && this.pending_backstroke) {
|
|
this.clear_backstroke();
|
|
}
|
|
switch (stroke) {
|
|
case 8:
|
|
this.backstroke_length = this.search_field.val().length;
|
|
break;
|
|
case 9:
|
|
if (this.results_showing && !this.is_multiple) {
|
|
this.result_select(evt);
|
|
}
|
|
this.mouse_on_container = false;
|
|
break;
|
|
case 13:
|
|
evt.preventDefault();
|
|
break;
|
|
case 38:
|
|
evt.preventDefault();
|
|
this.keyup_arrow();
|
|
break;
|
|
case 40:
|
|
evt.preventDefault();
|
|
this.keydown_arrow();
|
|
break;
|
|
}
|
|
};
|
|
|
|
Chosen.prototype.search_field_scale = function() {
|
|
var div, f_width, h, style, style_block, styles, w, _i, _len;
|
|
if (this.is_multiple) {
|
|
h = 0;
|
|
w = 0;
|
|
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
|
|
styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
|
|
for (_i = 0, _len = styles.length; _i < _len; _i++) {
|
|
style = styles[_i];
|
|
style_block += style + ":" + this.search_field.css(style) + ";";
|
|
}
|
|
div = $('<div />', {
|
|
'style': style_block
|
|
});
|
|
div.text(this.search_field.val());
|
|
$('body').append(div);
|
|
w = div.width() + 25;
|
|
div.remove();
|
|
f_width = this.container.outerWidth();
|
|
if (w > f_width - 10) {
|
|
w = f_width - 10;
|
|
}
|
|
return this.search_field.css({
|
|
'width': w + 'px'
|
|
});
|
|
}
|
|
};
|
|
|
|
return Chosen;
|
|
|
|
})(AbstractChosen);
|
|
|
|
}).call(this);
|
|
|
|
/*!
|
|
* typeahead.js 0.11.0-templating
|
|
* https://github.com/twitter/typeahead.js
|
|
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
|
|
*/
|
|
|
|
(function(root, factory) {
|
|
if (typeof define === "function" && define.amd) {
|
|
define("bloodhound", [ "jquery" ], function(jquery) {
|
|
return root["Bloodhound"] = factory(jquery);
|
|
});
|
|
} else if (typeof exports === "object") {
|
|
module.exports = factory(require("jquery"));
|
|
} else {
|
|
root["Bloodhound"] = factory(jQuery);
|
|
}
|
|
})(this, function() {
|
|
var _ = function() {
|
|
"use strict";
|
|
return {
|
|
isMsie: function() {
|
|
return /(msie|trident)/i.test(navigator.userAgent) ? navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2] : false;
|
|
},
|
|
isBlankString: function(str) {
|
|
return !str || /^\s*$/.test(str);
|
|
},
|
|
escapeRegExChars: function(str) {
|
|
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
},
|
|
isString: function(obj) {
|
|
return typeof obj === "string";
|
|
},
|
|
isNumber: function(obj) {
|
|
return typeof obj === "number";
|
|
},
|
|
isArray: $.isArray,
|
|
isFunction: $.isFunction,
|
|
isObject: $.isPlainObject,
|
|
isUndefined: function(obj) {
|
|
return typeof obj === "undefined";
|
|
},
|
|
isElement: function(obj) {
|
|
return !!(obj && obj.nodeType === 1);
|
|
},
|
|
isJQuery: function(obj) {
|
|
return obj instanceof $;
|
|
},
|
|
toStr: function toStr(s) {
|
|
return _.isUndefined(s) || s === null ? "" : s + "";
|
|
},
|
|
bind: $.proxy,
|
|
each: function(collection, cb) {
|
|
$.each(collection, reverseArgs);
|
|
function reverseArgs(index, value) {
|
|
return cb(value, index);
|
|
}
|
|
},
|
|
map: $.map,
|
|
filter: $.grep,
|
|
every: function(obj, test) {
|
|
var result = true;
|
|
if (!obj) {
|
|
return result;
|
|
}
|
|
$.each(obj, function(key, val) {
|
|
if (!(result = test.call(null, val, key, obj))) {
|
|
return false;
|
|
}
|
|
});
|
|
return !!result;
|
|
},
|
|
some: function(obj, test) {
|
|
var result = false;
|
|
if (!obj) {
|
|
return result;
|
|
}
|
|
$.each(obj, function(key, val) {
|
|
if (result = test.call(null, val, key, obj)) {
|
|
return false;
|
|
}
|
|
});
|
|
return !!result;
|
|
},
|
|
mixin: $.extend,
|
|
identity: function(x) {
|
|
return x;
|
|
},
|
|
clone: function(obj) {
|
|
return $.extend(true, {}, obj);
|
|
},
|
|
getIdGenerator: function() {
|
|
var counter = 0;
|
|
return function() {
|
|
return counter++;
|
|
};
|
|
},
|
|
templatify: function templatify(obj) {
|
|
return $.isFunction(obj) ? obj : template;
|
|
function template() {
|
|
return String(obj);
|
|
}
|
|
},
|
|
defer: function(fn) {
|
|
setTimeout(fn, 0);
|
|
},
|
|
debounce: function(func, wait, immediate) {
|
|
var timeout, result;
|
|
return function() {
|
|
var context = this, args = arguments, later, callNow;
|
|
later = function() {
|
|
timeout = null;
|
|
if (!immediate) {
|
|
result = func.apply(context, args);
|
|
}
|
|
};
|
|
callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
if (callNow) {
|
|
result = func.apply(context, args);
|
|
}
|
|
return result;
|
|
};
|
|
},
|
|
throttle: function(func, wait) {
|
|
var context, args, timeout, result, previous, later;
|
|
previous = 0;
|
|
later = function() {
|
|
previous = new Date();
|
|
timeout = null;
|
|
result = func.apply(context, args);
|
|
};
|
|
return function() {
|
|
var now = new Date(), remaining = wait - (now - previous);
|
|
context = this;
|
|
args = arguments;
|
|
if (remaining <= 0) {
|
|
clearTimeout(timeout);
|
|
timeout = null;
|
|
previous = now;
|
|
result = func.apply(context, args);
|
|
} else if (!timeout) {
|
|
timeout = setTimeout(later, remaining);
|
|
}
|
|
return result;
|
|
};
|
|
},
|
|
stringify: function(val) {
|
|
return _.isString(val) ? val : JSON.stringify(val);
|
|
},
|
|
noop: function() {}
|
|
};
|
|
}();
|
|
var VERSION = "0.11.0-templating";
|
|
var tokenizers = function() {
|
|
"use strict";
|
|
return {
|
|
nonword: nonword,
|
|
whitespace: whitespace,
|
|
obj: {
|
|
nonword: getObjTokenizer(nonword),
|
|
whitespace: getObjTokenizer(whitespace)
|
|
}
|
|
};
|
|
function whitespace(str) {
|
|
str = _.toStr(str);
|
|
return str ? str.split(/\s+/) : [];
|
|
}
|
|
function nonword(str) {
|
|
str = _.toStr(str);
|
|
return str ? str.split(/\W+/) : [];
|
|
}
|
|
function getObjTokenizer(tokenizer) {
|
|
return function setKey() {
|
|
var args = [].slice.call(arguments, 0);
|
|
return function tokenize(o) {
|
|
var tokens = [];
|
|
_.each(args, function(k) {
|
|
tokens = tokens.concat(tokenizer(_.toStr(o[k])));
|
|
});
|
|
return tokens;
|
|
};
|
|
};
|
|
}
|
|
}();
|
|
var LruCache = function() {
|
|
"use strict";
|
|
function LruCache(maxSize) {
|
|
this.maxSize = _.isNumber(maxSize) ? maxSize : 100;
|
|
this.reset();
|
|
if (this.maxSize <= 0) {
|
|
this.set = this.get = $.noop;
|
|
}
|
|
}
|
|
_.mixin(LruCache.prototype, {
|
|
set: function set(key, val) {
|
|
var tailItem = this.list.tail, node;
|
|
if (this.size >= this.maxSize) {
|
|
this.list.remove(tailItem);
|
|
delete this.hash[tailItem.key];
|
|
this.size--;
|
|
}
|
|
if (node = this.hash[key]) {
|
|
node.val = val;
|
|
this.list.moveToFront(node);
|
|
} else {
|
|
node = new Node(key, val);
|
|
this.list.add(node);
|
|
this.hash[key] = node;
|
|
this.size++;
|
|
}
|
|
},
|
|
get: function get(key) {
|
|
var node = this.hash[key];
|
|
if (node) {
|
|
this.list.moveToFront(node);
|
|
return node.val;
|
|
}
|
|
},
|
|
reset: function reset() {
|
|
this.size = 0;
|
|
this.hash = {};
|
|
this.list = new List();
|
|
}
|
|
});
|
|
function List() {
|
|
this.head = this.tail = null;
|
|
}
|
|
_.mixin(List.prototype, {
|
|
add: function add(node) {
|
|
if (this.head) {
|
|
node.next = this.head;
|
|
this.head.prev = node;
|
|
}
|
|
this.head = node;
|
|
this.tail = this.tail || node;
|
|
},
|
|
remove: function remove(node) {
|
|
node.prev ? node.prev.next = node.next : this.head = node.next;
|
|
node.next ? node.next.prev = node.prev : this.tail = node.prev;
|
|
},
|
|
moveToFront: function(node) {
|
|
this.remove(node);
|
|
this.add(node);
|
|
}
|
|
});
|
|
function Node(key, val) {
|
|
this.key = key;
|
|
this.val = val;
|
|
this.prev = this.next = null;
|
|
}
|
|
return LruCache;
|
|
}();
|
|
var PersistentStorage = function() {
|
|
"use strict";
|
|
var LOCAL_STORAGE;
|
|
try {
|
|
LOCAL_STORAGE = window.localStorage;
|
|
LOCAL_STORAGE.setItem("~~~", "!");
|
|
LOCAL_STORAGE.removeItem("~~~");
|
|
} catch (err) {
|
|
LOCAL_STORAGE = null;
|
|
}
|
|
function PersistentStorage(namespace, override) {
|
|
this.prefix = [ "__", namespace, "__" ].join("");
|
|
this.ttlKey = "__ttl__";
|
|
this.keyMatcher = new RegExp("^" + _.escapeRegExChars(this.prefix));
|
|
this.ls = override || LOCAL_STORAGE;
|
|
if (!this.ls || !window.JSON) {
|
|
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
|
|
}
|
|
}
|
|
_.mixin(PersistentStorage.prototype, {
|
|
_prefix: function(key) {
|
|
return this.prefix + key;
|
|
},
|
|
_ttlKey: function(key) {
|
|
return this._prefix(key) + this.ttlKey;
|
|
},
|
|
get: function(key) {
|
|
if (this.isExpired(key)) {
|
|
this.remove(key);
|
|
}
|
|
return decode(this.ls.getItem(this._prefix(key)));
|
|
},
|
|
set: function(key, val, ttl) {
|
|
if (_.isNumber(ttl)) {
|
|
this.ls.setItem(this._ttlKey(key), encode(now() + ttl));
|
|
} else {
|
|
this.ls.removeItem(this._ttlKey(key));
|
|
}
|
|
return this.ls.setItem(this._prefix(key), encode(val));
|
|
},
|
|
remove: function(key) {
|
|
this.ls.removeItem(this._ttlKey(key));
|
|
this.ls.removeItem(this._prefix(key));
|
|
return this;
|
|
},
|
|
clear: function() {
|
|
var i, key, keys = [], len = this.ls.length;
|
|
for (i = 0; i < len; i++) {
|
|
if ((key = this.ls.key(i)).match(this.keyMatcher)) {
|
|
keys.push(key.replace(this.keyMatcher, ""));
|
|
}
|
|
}
|
|
for (i = keys.length; i--; ) {
|
|
this.remove(keys[i]);
|
|
}
|
|
return this;
|
|
},
|
|
isExpired: function(key) {
|
|
var ttl = decode(this.ls.getItem(this._ttlKey(key)));
|
|
return _.isNumber(ttl) && now() > ttl ? true : false;
|
|
}
|
|
});
|
|
return PersistentStorage;
|
|
function now() {
|
|
return new Date().getTime();
|
|
}
|
|
function encode(val) {
|
|
return JSON.stringify(_.isUndefined(val) ? null : val);
|
|
}
|
|
function decode(val) {
|
|
return $.parseJSON(val);
|
|
}
|
|
}();
|
|
var Transport = function() {
|
|
"use strict";
|
|
var pendingRequestsCount = 0, pendingRequests = {}, maxPendingRequests = 6, sharedCache = new LruCache(10);
|
|
function Transport(o) {
|
|
o = o || {};
|
|
this.cancelled = false;
|
|
this.lastReq = null;
|
|
this._send = o.transport;
|
|
this._get = o.limiter ? o.limiter(this._get) : this._get;
|
|
this._cache = o.cache === false ? new LruCache(0) : sharedCache;
|
|
}
|
|
Transport.setMaxPendingRequests = function setMaxPendingRequests(num) {
|
|
maxPendingRequests = num;
|
|
};
|
|
Transport.resetCache = function resetCache() {
|
|
sharedCache.reset();
|
|
};
|
|
_.mixin(Transport.prototype, {
|
|
_fingerprint: function fingerprint(o) {
|
|
o = o || {};
|
|
return o.url + o.type + $.param(o.data || {});
|
|
},
|
|
_get: function(o, cb) {
|
|
var that = this, fingerprint, jqXhr;
|
|
fingerprint = this._fingerprint(o);
|
|
if (this.cancelled || fingerprint !== this.lastReq) {
|
|
return;
|
|
}
|
|
if (jqXhr = pendingRequests[fingerprint]) {
|
|
jqXhr.done(done).fail(fail);
|
|
} else if (pendingRequestsCount < maxPendingRequests) {
|
|
pendingRequestsCount++;
|
|
pendingRequests[fingerprint] = this._send(o).done(done).fail(fail).always(always);
|
|
} else {
|
|
this.onDeckRequestArgs = [].slice.call(arguments, 0);
|
|
}
|
|
function done(resp) {
|
|
cb(null, resp);
|
|
that._cache.set(fingerprint, resp);
|
|
}
|
|
function fail() {
|
|
cb(true);
|
|
}
|
|
function always() {
|
|
pendingRequestsCount--;
|
|
delete pendingRequests[fingerprint];
|
|
if (that.onDeckRequestArgs) {
|
|
that._get.apply(that, that.onDeckRequestArgs);
|
|
that.onDeckRequestArgs = null;
|
|
}
|
|
}
|
|
},
|
|
get: function(o, cb) {
|
|
var resp, fingerprint;
|
|
cb = cb || $.noop;
|
|
o = _.isString(o) ? {
|
|
url: o
|
|
} : o || {};
|
|
fingerprint = this._fingerprint(o);
|
|
this.cancelled = false;
|
|
this.lastReq = fingerprint;
|
|
if (resp = this._cache.get(fingerprint)) {
|
|
cb(null, resp);
|
|
} else {
|
|
this._get(o, cb);
|
|
}
|
|
},
|
|
cancel: function() {
|
|
this.cancelled = true;
|
|
}
|
|
});
|
|
return Transport;
|
|
}();
|
|
var SearchIndex = window.SearchIndex = function() {
|
|
"use strict";
|
|
var CHILDREN = "c", IDS = "i";
|
|
function SearchIndex(o) {
|
|
o = o || {};
|
|
if (!o.datumTokenizer || !o.queryTokenizer) {
|
|
$.error("datumTokenizer and queryTokenizer are both required");
|
|
}
|
|
this.identify = o.identify || _.stringify;
|
|
this.datumTokenizer = o.datumTokenizer;
|
|
this.queryTokenizer = o.queryTokenizer;
|
|
this.reset();
|
|
}
|
|
_.mixin(SearchIndex.prototype, {
|
|
bootstrap: function bootstrap(o) {
|
|
this.datums = o.datums;
|
|
this.trie = o.trie;
|
|
},
|
|
add: function(data) {
|
|
var that = this;
|
|
data = _.isArray(data) ? data : [ data ];
|
|
_.each(data, function(datum) {
|
|
var id, tokens;
|
|
that.datums[id = that.identify(datum)] = datum;
|
|
tokens = normalizeTokens(that.datumTokenizer(datum));
|
|
_.each(tokens, function(token) {
|
|
var node, chars, ch;
|
|
node = that.trie;
|
|
chars = token.split("");
|
|
while (ch = chars.shift()) {
|
|
node = node[CHILDREN][ch] || (node[CHILDREN][ch] = newNode());
|
|
node[IDS].push(id);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
get: function get(ids) {
|
|
var that = this;
|
|
return _.map(ids, function(id) {
|
|
return that.datums[id];
|
|
});
|
|
},
|
|
search: function search(query) {
|
|
var that = this, tokens, matches;
|
|
tokens = normalizeTokens(this.queryTokenizer(query));
|
|
_.each(tokens, function(token) {
|
|
var node, chars, ch, ids;
|
|
if (matches && matches.length === 0) {
|
|
return false;
|
|
}
|
|
node = that.trie;
|
|
chars = token.split("");
|
|
while (node && (ch = chars.shift())) {
|
|
node = node[CHILDREN][ch];
|
|
}
|
|
if (node && chars.length === 0) {
|
|
ids = node[IDS].slice(0);
|
|
matches = matches ? getIntersection(matches, ids) : ids;
|
|
} else {
|
|
matches = [];
|
|
return false;
|
|
}
|
|
});
|
|
return matches ? _.map(unique(matches), function(id) {
|
|
return that.datums[id];
|
|
}) : [];
|
|
},
|
|
all: function all() {
|
|
var values = [];
|
|
for (var key in this.datums) {
|
|
values.push(this.datums[key]);
|
|
}
|
|
return values;
|
|
},
|
|
reset: function reset() {
|
|
this.datums = {};
|
|
this.trie = newNode();
|
|
},
|
|
serialize: function serialize() {
|
|
return {
|
|
datums: this.datums,
|
|
trie: this.trie
|
|
};
|
|
}
|
|
});
|
|
return SearchIndex;
|
|
function normalizeTokens(tokens) {
|
|
tokens = _.filter(tokens, function(token) {
|
|
return !!token;
|
|
});
|
|
tokens = _.map(tokens, function(token) {
|
|
return token.toLowerCase();
|
|
});
|
|
return tokens;
|
|
}
|
|
function newNode() {
|
|
var node = {};
|
|
node[IDS] = [];
|
|
node[CHILDREN] = {};
|
|
return node;
|
|
}
|
|
function unique(array) {
|
|
var seen = {}, uniques = [];
|
|
for (var i = 0, len = array.length; i < len; i++) {
|
|
if (!seen[array[i]]) {
|
|
seen[array[i]] = true;
|
|
uniques.push(array[i]);
|
|
}
|
|
}
|
|
return uniques;
|
|
}
|
|
function getIntersection(arrayA, arrayB) {
|
|
var ai = 0, bi = 0, intersection = [];
|
|
arrayA = arrayA.sort(compare);
|
|
arrayB = arrayB.sort(compare);
|
|
var lenArrayA = arrayA.length, lenArrayB = arrayB.length;
|
|
while (ai < lenArrayA && bi < lenArrayB) {
|
|
if (arrayA[ai] < arrayB[bi]) {
|
|
ai++;
|
|
} else if (arrayA[ai] > arrayB[bi]) {
|
|
bi++;
|
|
} else {
|
|
intersection.push(arrayA[ai]);
|
|
ai++;
|
|
bi++;
|
|
}
|
|
}
|
|
return intersection;
|
|
function compare(a, b) {
|
|
return a - b;
|
|
}
|
|
}
|
|
}();
|
|
var Prefetch = function() {
|
|
"use strict";
|
|
var keys;
|
|
keys = {
|
|
data: "data",
|
|
protocol: "protocol",
|
|
thumbprint: "thumbprint"
|
|
};
|
|
function Prefetch(o) {
|
|
this.url = o.url;
|
|
this.ttl = o.ttl;
|
|
this.cache = o.cache;
|
|
this.transform = o.transform;
|
|
this.transport = o.transport;
|
|
this.thumbprint = o.thumbprint;
|
|
this.storage = new PersistentStorage(o.cacheKey);
|
|
}
|
|
_.mixin(Prefetch.prototype, {
|
|
_settings: function settings() {
|
|
return {
|
|
url: this.url,
|
|
type: "GET",
|
|
dataType: "json"
|
|
};
|
|
},
|
|
store: function store(data) {
|
|
if (!this.cache) {
|
|
return;
|
|
}
|
|
this.storage.set(keys.data, data, this.ttl);
|
|
this.storage.set(keys.protocol, location.protocol, this.ttl);
|
|
this.storage.set(keys.thumbprint, this.thumbprint, this.ttl);
|
|
},
|
|
fromCache: function fromCache() {
|
|
var stored = {}, isExpired;
|
|
if (!this.cache) {
|
|
return null;
|
|
}
|
|
stored.data = this.storage.get(keys.data);
|
|
stored.protocol = this.storage.get(keys.protocol);
|
|
stored.thumbprint = this.storage.get(keys.thumbprint);
|
|
isExpired = stored.thumbprint !== this.thumbprint || stored.protocol !== location.protocol;
|
|
return stored.data && !isExpired ? stored.data : null;
|
|
},
|
|
fromNetwork: function(cb) {
|
|
var that = this;
|
|
if (!cb) {
|
|
return;
|
|
}
|
|
this.transport(this._settings()).fail(onError).done(onResponse);
|
|
function onError() {
|
|
cb(true);
|
|
}
|
|
function onResponse(resp) {
|
|
cb(null, that.transform(resp));
|
|
}
|
|
},
|
|
clear: function clear() {
|
|
this.storage.clear();
|
|
return this;
|
|
}
|
|
});
|
|
return Prefetch;
|
|
}();
|
|
var Remote = function() {
|
|
"use strict";
|
|
function Remote(o) {
|
|
this.url = o.url;
|
|
this.prepare = o.prepare;
|
|
this.transform = o.transform;
|
|
this.transport = new Transport({
|
|
cache: o.cache,
|
|
limiter: o.limiter,
|
|
transport: o.transport
|
|
});
|
|
}
|
|
_.mixin(Remote.prototype, {
|
|
_settings: function settings() {
|
|
return {
|
|
url: this.url,
|
|
type: "GET",
|
|
dataType: "json"
|
|
};
|
|
},
|
|
get: function get(query, cb) {
|
|
var that = this, settings;
|
|
if (!cb) {
|
|
return;
|
|
}
|
|
query = query || "";
|
|
settings = this.prepare(query, this._settings());
|
|
return this.transport.get(settings, onResponse);
|
|
function onResponse(err, resp) {
|
|
err ? cb([]) : cb(that.transform(resp));
|
|
}
|
|
},
|
|
cancelLastRequest: function cancelLastRequest() {
|
|
this.transport.cancel();
|
|
}
|
|
});
|
|
return Remote;
|
|
}();
|
|
var oParser = function() {
|
|
"use strict";
|
|
return function parse(o) {
|
|
var defaults, sorter;
|
|
defaults = {
|
|
initialize: true,
|
|
identify: _.stringify,
|
|
datumTokenizer: null,
|
|
queryTokenizer: null,
|
|
sufficient: 5,
|
|
sorter: null,
|
|
local: [],
|
|
prefetch: null,
|
|
remote: null
|
|
};
|
|
o = _.mixin(defaults, o || {});
|
|
!o.datumTokenizer && $.error("datumTokenizer is required");
|
|
!o.queryTokenizer && $.error("queryTokenizer is required");
|
|
sorter = o.sorter;
|
|
o.sorter = sorter ? function(x) {
|
|
return x.sort(sorter);
|
|
} : _.identity;
|
|
o.local = _.isFunction(o.local) ? o.local() : o.local;
|
|
o.prefetch = parsePrefetch(o.prefetch);
|
|
o.remote = parseRemote(o.remote);
|
|
return o;
|
|
};
|
|
function parsePrefetch(o) {
|
|
var defaults;
|
|
if (!o) {
|
|
return null;
|
|
}
|
|
defaults = {
|
|
url: null,
|
|
ttl: 24 * 60 * 60 * 1e3,
|
|
cache: true,
|
|
cacheKey: null,
|
|
thumbprint: "",
|
|
transform: _.identity,
|
|
transport: null
|
|
};
|
|
o = _.isString(o) ? {
|
|
url: o
|
|
} : o;
|
|
o = _.mixin(defaults, o);
|
|
!o.url && $.error("prefetch requires url to be set");
|
|
o.transform = o.filter || o.transform;
|
|
o.cacheKey = o.cacheKey || o.url;
|
|
o.thumbprint = VERSION + o.thumbprint;
|
|
o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax;
|
|
return o;
|
|
}
|
|
function parseRemote(o) {
|
|
var defaults;
|
|
if (!o) {
|
|
return;
|
|
}
|
|
defaults = {
|
|
url: null,
|
|
cache: true,
|
|
prepare: null,
|
|
replace: null,
|
|
wildcard: null,
|
|
limiter: null,
|
|
rateLimitBy: "debounce",
|
|
rateLimitWait: 300,
|
|
transform: _.identity,
|
|
transport: null
|
|
};
|
|
o = _.isString(o) ? {
|
|
url: o
|
|
} : o;
|
|
o = _.mixin(defaults, o);
|
|
!o.url && $.error("remote requires url to be set");
|
|
o.transform = o.filter || o.transform;
|
|
o.prepare = toPrepare(o);
|
|
o.limiter = toLimiter(o);
|
|
o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax;
|
|
delete o.replace;
|
|
delete o.wildcard;
|
|
delete o.rateLimitBy;
|
|
delete o.rateLimitWait;
|
|
return o;
|
|
}
|
|
function toPrepare(o) {
|
|
var prepare, replace, wildcard;
|
|
prepare = o.prepare;
|
|
replace = o.replace;
|
|
wildcard = o.wildcard;
|
|
if (prepare) {
|
|
return prepare;
|
|
}
|
|
if (replace) {
|
|
prepare = prepareByReplace;
|
|
} else if (o.wildcard) {
|
|
prepare = prepareByWildcard;
|
|
} else {
|
|
prepare = idenityPrepare;
|
|
}
|
|
return prepare;
|
|
function prepareByReplace(query, settings) {
|
|
settings.url = replace(settings.url, query);
|
|
return settings;
|
|
}
|
|
function prepareByWildcard(query, settings) {
|
|
settings.url = settings.url.replace(wildcard, encodeURIComponent(query));
|
|
return settings;
|
|
}
|
|
function idenityPrepare(query, settings) {
|
|
return settings;
|
|
}
|
|
}
|
|
function toLimiter(o) {
|
|
var limiter, method, wait;
|
|
limiter = o.limiter;
|
|
method = o.rateLimitBy;
|
|
wait = o.rateLimitWait;
|
|
if (!limiter) {
|
|
limiter = /^throttle$/i.test(method) ? throttle(wait) : debounce(wait);
|
|
}
|
|
return limiter;
|
|
function debounce(wait) {
|
|
return function debounce(fn) {
|
|
return _.debounce(fn, wait);
|
|
};
|
|
}
|
|
function throttle(wait) {
|
|
return function throttle(fn) {
|
|
return _.throttle(fn, wait);
|
|
};
|
|
}
|
|
}
|
|
function callbackToDeferred(fn) {
|
|
return function wrapper(o) {
|
|
var deferred = $.Deferred();
|
|
fn(o, onSuccess, onError);
|
|
return deferred;
|
|
function onSuccess(resp) {
|
|
_.defer(function() {
|
|
deferred.resolve(resp);
|
|
});
|
|
}
|
|
function onError(err) {
|
|
_.defer(function() {
|
|
deferred.reject(err);
|
|
});
|
|
}
|
|
};
|
|
}
|
|
}();
|
|
var Bloodhound = function() {
|
|
"use strict";
|
|
var old;
|
|
old = window && window.Bloodhound;
|
|
function Bloodhound(o) {
|
|
o = oParser(o);
|
|
this.sorter = o.sorter;
|
|
this.identify = o.identify;
|
|
this.sufficient = o.sufficient;
|
|
this.local = o.local;
|
|
this.remote = o.remote ? new Remote(o.remote) : null;
|
|
this.prefetch = o.prefetch ? new Prefetch(o.prefetch) : null;
|
|
this.index = new SearchIndex({
|
|
identify: this.identify,
|
|
datumTokenizer: o.datumTokenizer,
|
|
queryTokenizer: o.queryTokenizer
|
|
});
|
|
o.initialize !== false && this.initialize();
|
|
}
|
|
Bloodhound.noConflict = function noConflict() {
|
|
window && (window.Bloodhound = old);
|
|
return Bloodhound;
|
|
};
|
|
Bloodhound.tokenizers = tokenizers;
|
|
_.mixin(Bloodhound.prototype, {
|
|
__ttAdapter: function ttAdapter() {
|
|
var that = this;
|
|
return this.remote ? withAsync : withoutAsync;
|
|
function withAsync(query, sync, async) {
|
|
return that.search(query, sync, async);
|
|
}
|
|
function withoutAsync(query, sync) {
|
|
return that.search(query, sync);
|
|
}
|
|
},
|
|
_loadPrefetch: function loadPrefetch() {
|
|
var that = this, deferred, serialized;
|
|
deferred = $.Deferred();
|
|
if (!this.prefetch) {
|
|
deferred.resolve();
|
|
} else if (serialized = this.prefetch.fromCache()) {
|
|
this.index.bootstrap(serialized);
|
|
deferred.resolve();
|
|
} else {
|
|
this.prefetch.fromNetwork(done);
|
|
}
|
|
return deferred.promise();
|
|
function done(err, data) {
|
|
if (err) {
|
|
return deferred.reject();
|
|
}
|
|
that.add(data);
|
|
that.prefetch.store(that.index.serialize());
|
|
deferred.resolve();
|
|
}
|
|
},
|
|
_initialize: function initialize() {
|
|
var that = this, deferred;
|
|
this.clear();
|
|
(this.initPromise = this._loadPrefetch()).done(addLocalToIndex);
|
|
return this.initPromise;
|
|
function addLocalToIndex() {
|
|
that.add(that.local);
|
|
}
|
|
},
|
|
initialize: function initialize(force) {
|
|
return !this.initPromise || force ? this._initialize() : this.initPromise;
|
|
},
|
|
add: function add(data) {
|
|
this.index.add(data);
|
|
return this;
|
|
},
|
|
get: function get(ids) {
|
|
ids = _.isArray(ids) ? ids : [].slice.call(arguments);
|
|
return this.index.get(ids);
|
|
},
|
|
search: function search(query, sync, async) {
|
|
var that = this, local;
|
|
local = this.sorter(this.index.search(query));
|
|
sync(this.remote ? local.slice() : local);
|
|
if (this.remote && local.length < this.sufficient) {
|
|
this.remote.get(query, processRemote);
|
|
} else if (this.remote) {
|
|
this.remote.cancelLastRequest();
|
|
}
|
|
return this;
|
|
function processRemote(remote) {
|
|
var nonDuplicates = [];
|
|
_.each(remote, function(r) {
|
|
!_.some(local, function(l) {
|
|
return that.identify(r) === that.identify(l);
|
|
}) && nonDuplicates.push(r);
|
|
});
|
|
async && async(nonDuplicates);
|
|
}
|
|
},
|
|
all: function all() {
|
|
return this.index.all();
|
|
},
|
|
clear: function clear() {
|
|
this.index.reset();
|
|
return this;
|
|
},
|
|
clearPrefetchCache: function clearPrefetchCache() {
|
|
this.prefetch && this.prefetch.clear();
|
|
return this;
|
|
},
|
|
clearRemoteCache: function clearRemoteCache() {
|
|
Transport.resetCache();
|
|
return this;
|
|
},
|
|
ttAdapter: function ttAdapter() {
|
|
return this.__ttAdapter();
|
|
}
|
|
});
|
|
return Bloodhound;
|
|
}();
|
|
return Bloodhound;
|
|
});
|
|
|
|
(function(root, factory) {
|
|
if (typeof define === "function" && define.amd) {
|
|
define("typeahead.js", [ "jquery" ], function(jquery) {
|
|
return factory(jquery);
|
|
});
|
|
} else if (typeof exports === "object") {
|
|
module.exports = factory(require("jquery"));
|
|
} else {
|
|
factory(jQuery);
|
|
}
|
|
})(this, function() {
|
|
var _ = function() {
|
|
"use strict";
|
|
return {
|
|
isMsie: function() {
|
|
return /(msie|trident)/i.test(navigator.userAgent) ? navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2] : false;
|
|
},
|
|
isBlankString: function(str) {
|
|
return !str || /^\s*$/.test(str);
|
|
},
|
|
escapeRegExChars: function(str) {
|
|
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
},
|
|
isString: function(obj) {
|
|
return typeof obj === "string";
|
|
},
|
|
isNumber: function(obj) {
|
|
return typeof obj === "number";
|
|
},
|
|
isArray: $.isArray,
|
|
isFunction: $.isFunction,
|
|
isObject: $.isPlainObject,
|
|
isUndefined: function(obj) {
|
|
return typeof obj === "undefined";
|
|
},
|
|
isElement: function(obj) {
|
|
return !!(obj && obj.nodeType === 1);
|
|
},
|
|
isJQuery: function(obj) {
|
|
return obj instanceof $;
|
|
},
|
|
toStr: function toStr(s) {
|
|
return _.isUndefined(s) || s === null ? "" : s + "";
|
|
},
|
|
bind: $.proxy,
|
|
each: function(collection, cb) {
|
|
$.each(collection, reverseArgs);
|
|
function reverseArgs(index, value) {
|
|
return cb(value, index);
|
|
}
|
|
},
|
|
map: $.map,
|
|
filter: $.grep,
|
|
every: function(obj, test) {
|
|
var result = true;
|
|
if (!obj) {
|
|
return result;
|
|
}
|
|
$.each(obj, function(key, val) {
|
|
if (!(result = test.call(null, val, key, obj))) {
|
|
return false;
|
|
}
|
|
});
|
|
return !!result;
|
|
},
|
|
some: function(obj, test) {
|
|
var result = false;
|
|
if (!obj) {
|
|
return result;
|
|
}
|
|
$.each(obj, function(key, val) {
|
|
if (result = test.call(null, val, key, obj)) {
|
|
return false;
|
|
}
|
|
});
|
|
return !!result;
|
|
},
|
|
mixin: $.extend,
|
|
identity: function(x) {
|
|
return x;
|
|
},
|
|
clone: function(obj) {
|
|
return $.extend(true, {}, obj);
|
|
},
|
|
getIdGenerator: function() {
|
|
var counter = 0;
|
|
return function() {
|
|
return counter++;
|
|
};
|
|
},
|
|
templatify: function templatify(obj) {
|
|
return $.isFunction(obj) ? obj : template;
|
|
function template() {
|
|
return String(obj);
|
|
}
|
|
},
|
|
defer: function(fn) {
|
|
setTimeout(fn, 0);
|
|
},
|
|
debounce: function(func, wait, immediate) {
|
|
var timeout, result;
|
|
return function() {
|
|
var context = this, args = arguments, later, callNow;
|
|
later = function() {
|
|
timeout = null;
|
|
if (!immediate) {
|
|
result = func.apply(context, args);
|
|
}
|
|
};
|
|
callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
if (callNow) {
|
|
result = func.apply(context, args);
|
|
}
|
|
return result;
|
|
};
|
|
},
|
|
throttle: function(func, wait) {
|
|
var context, args, timeout, result, previous, later;
|
|
previous = 0;
|
|
later = function() {
|
|
previous = new Date();
|
|
timeout = null;
|
|
result = func.apply(context, args);
|
|
};
|
|
return function() {
|
|
var now = new Date(), remaining = wait - (now - previous);
|
|
context = this;
|
|
args = arguments;
|
|
if (remaining <= 0) {
|
|
clearTimeout(timeout);
|
|
timeout = null;
|
|
previous = now;
|
|
result = func.apply(context, args);
|
|
} else if (!timeout) {
|
|
timeout = setTimeout(later, remaining);
|
|
}
|
|
return result;
|
|
};
|
|
},
|
|
stringify: function(val) {
|
|
return _.isString(val) ? val : JSON.stringify(val);
|
|
},
|
|
noop: function() {}
|
|
};
|
|
}();
|
|
var WWW = function() {
|
|
"use strict";
|
|
var defaultClassNames = {
|
|
wrapper: "twitter-typeahead",
|
|
input: "tt-input",
|
|
hint: "tt-hint",
|
|
menu: "tt-menu",
|
|
dataset: "tt-dataset",
|
|
suggestion: "tt-suggestion",
|
|
selectable: "tt-selectable",
|
|
empty: "tt-empty",
|
|
open: "tt-open",
|
|
cursor: "tt-cursor",
|
|
highlight: "tt-highlight"
|
|
};
|
|
var defaultTemplates = {
|
|
wrapper: "<span></span>",
|
|
menu: "<div></div>",
|
|
dataset: "<div></div>"
|
|
};
|
|
return build;
|
|
function build(o) {
|
|
o = o || {};
|
|
var www, classes, templates;
|
|
classes = _.mixin({}, defaultClassNames, o.classNames);
|
|
templates = _.mixin({}, defaultTemplates, o.templates);
|
|
www = {
|
|
css: buildCss(),
|
|
classes: classes,
|
|
html: {
|
|
wrapper: function() {
|
|
return $(templates.wrapper).addClass(classes.wrapper);
|
|
},
|
|
menu: function() {
|
|
return $(templates.menu).addClass(classes.menu);
|
|
},
|
|
dataset: function() {
|
|
return $(templates.dataset).addClass(classes.dataset);
|
|
}
|
|
},
|
|
selectors: buildSelectors(classes)
|
|
};
|
|
return {
|
|
css: www.css,
|
|
html: www.html,
|
|
classes: www.classes,
|
|
selectors: www.selectors,
|
|
mixin: function(o) {
|
|
_.mixin(o, www);
|
|
}
|
|
};
|
|
}
|
|
function buildSelectors(classes) {
|
|
var selectors = {};
|
|
_.each(classes, function(v, k) {
|
|
selectors[k] = "." + v;
|
|
});
|
|
return selectors;
|
|
}
|
|
function buildCss() {
|
|
var css = {
|
|
wrapper: {
|
|
position: "relative",
|
|
display: "inline-block"
|
|
},
|
|
hint: {
|
|
position: "absolute",
|
|
top: "0",
|
|
left: "0",
|
|
borderColor: "transparent",
|
|
boxShadow: "none",
|
|
opacity: "1"
|
|
},
|
|
input: {
|
|
position: "relative",
|
|
verticalAlign: "top",
|
|
backgroundColor: "transparent"
|
|
},
|
|
inputWithNoHint: {
|
|
position: "relative",
|
|
verticalAlign: "top"
|
|
},
|
|
menu: {
|
|
position: "absolute",
|
|
top: "100%",
|
|
left: "0",
|
|
zIndex: "100",
|
|
display: "none"
|
|
},
|
|
ltr: {
|
|
left: "0",
|
|
right: "auto"
|
|
},
|
|
rtl: {
|
|
left: "auto",
|
|
right: " 0"
|
|
}
|
|
};
|
|
if (_.isMsie()) {
|
|
_.mixin(css.input, {
|
|
backgroundImage: "url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"
|
|
});
|
|
}
|
|
if (_.isMsie() && _.isMsie() <= 7) {
|
|
_.mixin(css.input, {
|
|
marginTop: "-1px"
|
|
});
|
|
}
|
|
return css;
|
|
}
|
|
}();
|
|
var EventBus = function() {
|
|
"use strict";
|
|
var namespace, deprecationMap;
|
|
namespace = "typeahead:";
|
|
deprecationMap = {
|
|
render: "rendered",
|
|
cursorchange: "cursorchanged",
|
|
select: "selected",
|
|
autocomplete: "autocompleted"
|
|
};
|
|
function EventBus(o) {
|
|
if (!o || !o.el) {
|
|
$.error("EventBus initialized without el");
|
|
}
|
|
this.$el = $(o.el);
|
|
}
|
|
_.mixin(EventBus.prototype, {
|
|
_trigger: function(type, args) {
|
|
var $e;
|
|
$e = $.Event(namespace + type);
|
|
(args = args || []).unshift($e);
|
|
this.$el.trigger.apply(this.$el, args);
|
|
return $e;
|
|
},
|
|
before: function(type) {
|
|
var args, $e;
|
|
args = [].slice.call(arguments, 1);
|
|
$e = this._trigger("before" + type, args);
|
|
return $e.isDefaultPrevented();
|
|
},
|
|
trigger: function(type) {
|
|
var deprecatedType;
|
|
this._trigger(type, [].slice.call(arguments, 1));
|
|
if (deprecatedType = deprecationMap[type]) {
|
|
this._trigger(deprecatedType, [].slice.call(arguments, 1));
|
|
}
|
|
}
|
|
});
|
|
return EventBus;
|
|
}();
|
|
var EventEmitter = function() {
|
|
"use strict";
|
|
var splitter = /\s+/, nextTick = getNextTick();
|
|
return {
|
|
onSync: onSync,
|
|
onAsync: onAsync,
|
|
off: off,
|
|
trigger: trigger
|
|
};
|
|
function on(method, types, cb, context) {
|
|
var type;
|
|
if (!cb) {
|
|
return this;
|
|
}
|
|
types = types.split(splitter);
|
|
cb = context ? bindContext(cb, context) : cb;
|
|
this._callbacks = this._callbacks || {};
|
|
while (type = types.shift()) {
|
|
this._callbacks[type] = this._callbacks[type] || {
|
|
sync: [],
|
|
async: []
|
|
};
|
|
this._callbacks[type][method].push(cb);
|
|
}
|
|
return this;
|
|
}
|
|
function onAsync(types, cb, context) {
|
|
return on.call(this, "async", types, cb, context);
|
|
}
|
|
function onSync(types, cb, context) {
|
|
return on.call(this, "sync", types, cb, context);
|
|
}
|
|
function off(types) {
|
|
var type;
|
|
if (!this._callbacks) {
|
|
return this;
|
|
}
|
|
types = types.split(splitter);
|
|
while (type = types.shift()) {
|
|
delete this._callbacks[type];
|
|
}
|
|
return this;
|
|
}
|
|
function trigger(types) {
|
|
var type, callbacks, args, syncFlush, asyncFlush;
|
|
if (!this._callbacks) {
|
|
return this;
|
|
}
|
|
types = types.split(splitter);
|
|
args = [].slice.call(arguments, 1);
|
|
while ((type = types.shift()) && (callbacks = this._callbacks[type])) {
|
|
syncFlush = getFlush(callbacks.sync, this, [ type ].concat(args));
|
|
asyncFlush = getFlush(callbacks.async, this, [ type ].concat(args));
|
|
syncFlush() && nextTick(asyncFlush);
|
|
}
|
|
return this;
|
|
}
|
|
function getFlush(callbacks, context, args) {
|
|
return flush;
|
|
function flush() {
|
|
var cancelled;
|
|
for (var i = 0, len = callbacks.length; !cancelled && i < len; i += 1) {
|
|
cancelled = callbacks[i].apply(context, args) === false;
|
|
}
|
|
return !cancelled;
|
|
}
|
|
}
|
|
function getNextTick() {
|
|
var nextTickFn;
|
|
if (window.setImmediate) {
|
|
nextTickFn = function nextTickSetImmediate(fn) {
|
|
setImmediate(function() {
|
|
fn();
|
|
});
|
|
};
|
|
} else {
|
|
nextTickFn = function nextTickSetTimeout(fn) {
|
|
setTimeout(function() {
|
|
fn();
|
|
}, 0);
|
|
};
|
|
}
|
|
return nextTickFn;
|
|
}
|
|
function bindContext(fn, context) {
|
|
return fn.bind ? fn.bind(context) : function() {
|
|
fn.apply(context, [].slice.call(arguments, 0));
|
|
};
|
|
}
|
|
}();
|
|
var highlight = function(doc) {
|
|
"use strict";
|
|
var defaults = {
|
|
node: null,
|
|
pattern: null,
|
|
tagName: "strong",
|
|
className: null,
|
|
wordsOnly: false,
|
|
caseSensitive: false
|
|
};
|
|
return function hightlight(o) {
|
|
var regex;
|
|
o = _.mixin({}, defaults, o);
|
|
if (!o.node || !o.pattern) {
|
|
return;
|
|
}
|
|
o.pattern = _.isArray(o.pattern) ? o.pattern : [ o.pattern ];
|
|
regex = getRegex(o.pattern, o.caseSensitive, o.wordsOnly);
|
|
traverse(o.node, hightlightTextNode);
|
|
function hightlightTextNode(textNode) {
|
|
var match, patternNode, wrapperNode;
|
|
if (match = regex.exec(textNode.data)) {
|
|
wrapperNode = doc.createElement(o.tagName);
|
|
o.className && (wrapperNode.className = o.className);
|
|
patternNode = textNode.splitText(match.index);
|
|
patternNode.splitText(match[0].length);
|
|
wrapperNode.appendChild(patternNode.cloneNode(true));
|
|
textNode.parentNode.replaceChild(wrapperNode, patternNode);
|
|
}
|
|
return !!match;
|
|
}
|
|
function traverse(el, hightlightTextNode) {
|
|
var childNode, TEXT_NODE_TYPE = 3;
|
|
for (var i = 0; i < el.childNodes.length; i++) {
|
|
childNode = el.childNodes[i];
|
|
if (childNode.nodeType === TEXT_NODE_TYPE) {
|
|
i += hightlightTextNode(childNode) ? 1 : 0;
|
|
} else {
|
|
traverse(childNode, hightlightTextNode);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
function getRegex(patterns, caseSensitive, wordsOnly) {
|
|
var escapedPatterns = [], regexStr;
|
|
for (var i = 0, len = patterns.length; i < len; i++) {
|
|
escapedPatterns.push(_.escapeRegExChars(patterns[i]));
|
|
}
|
|
regexStr = wordsOnly ? "\\b(" + escapedPatterns.join("|") + ")\\b" : "(" + escapedPatterns.join("|") + ")";
|
|
return caseSensitive ? new RegExp(regexStr) : new RegExp(regexStr, "i");
|
|
}
|
|
}(window.document);
|
|
var Input = function() {
|
|
"use strict";
|
|
var specialKeyCodeMap;
|
|
specialKeyCodeMap = {
|
|
9: "tab",
|
|
27: "esc",
|
|
37: "left",
|
|
39: "right",
|
|
13: "enter",
|
|
38: "up",
|
|
40: "down"
|
|
};
|
|
function Input(o, www) {
|
|
o = o || {};
|
|
if (!o.input) {
|
|
$.error("input is missing");
|
|
}
|
|
www.mixin(this);
|
|
this.$hint = $(o.hint);
|
|
this.$input = $(o.input);
|
|
this.query = this.$input.val();
|
|
this.queryWhenFocused = this.hasFocus() ? this.query : null;
|
|
this.$overflowHelper = buildOverflowHelper(this.$input);
|
|
this._checkLanguageDirection();
|
|
if (this.$hint.length === 0) {
|
|
this.setHint = this.getHint = this.clearHint = this.clearHintIfInvalid = _.noop;
|
|
}
|
|
}
|
|
Input.normalizeQuery = function(str) {
|
|
return (str || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
|
|
};
|
|
_.mixin(Input.prototype, EventEmitter, {
|
|
_onBlur: function onBlur() {
|
|
this.resetInputValue();
|
|
this.trigger("blurred");
|
|
},
|
|
_onFocus: function onFocus() {
|
|
this.queryWhenFocused = this.query;
|
|
this.trigger("focused");
|
|
},
|
|
_onKeydown: function onKeydown($e) {
|
|
var keyName = specialKeyCodeMap[$e.which || $e.keyCode];
|
|
this._managePreventDefault(keyName, $e);
|
|
if (keyName && this._shouldTrigger(keyName, $e)) {
|
|
this.trigger(keyName + "Keyed", $e);
|
|
}
|
|
},
|
|
_onInput: function onInput() {
|
|
this._setQuery(this.getInputValue());
|
|
this.clearHintIfInvalid();
|
|
this._checkLanguageDirection();
|
|
},
|
|
_managePreventDefault: function managePreventDefault(keyName, $e) {
|
|
var preventDefault;
|
|
switch (keyName) {
|
|
case "up":
|
|
case "down":
|
|
preventDefault = !withModifier($e);
|
|
break;
|
|
|
|
default:
|
|
preventDefault = false;
|
|
}
|
|
preventDefault && $e.preventDefault();
|
|
},
|
|
_shouldTrigger: function shouldTrigger(keyName, $e) {
|
|
var trigger;
|
|
switch (keyName) {
|
|
case "tab":
|
|
trigger = !withModifier($e);
|
|
break;
|
|
|
|
default:
|
|
trigger = true;
|
|
}
|
|
return trigger;
|
|
},
|
|
_checkLanguageDirection: function checkLanguageDirection() {
|
|
var dir = (this.$input.css("direction") || "ltr").toLowerCase();
|
|
if (this.dir !== dir) {
|
|
this.dir = dir;
|
|
this.$hint.attr("dir", dir);
|
|
this.trigger("langDirChanged", dir);
|
|
}
|
|
},
|
|
_setQuery: function setQuery(val, silent) {
|
|
var areEquivalent, hasDifferentWhitespace;
|
|
areEquivalent = areQueriesEquivalent(val, this.query);
|
|
hasDifferentWhitespace = areEquivalent ? this.query.length !== val.length : false;
|
|
this.query = val;
|
|
if (!silent && !areEquivalent) {
|
|
this.trigger("queryChanged", this.query);
|
|
} else if (!silent && hasDifferentWhitespace) {
|
|
this.trigger("whitespaceChanged", this.query);
|
|
}
|
|
},
|
|
bind: function() {
|
|
var that = this, onBlur, onFocus, onKeydown, onInput;
|
|
onBlur = _.bind(this._onBlur, this);
|
|
onFocus = _.bind(this._onFocus, this);
|
|
onKeydown = _.bind(this._onKeydown, this);
|
|
onInput = _.bind(this._onInput, this);
|
|
this.$input.on("blur.tt", onBlur).on("focus.tt", onFocus).on("keydown.tt", onKeydown);
|
|
if (!_.isMsie() || _.isMsie() > 9) {
|
|
this.$input.on("input.tt", onInput);
|
|
} else {
|
|
this.$input.on("keydown.tt keypress.tt cut.tt paste.tt", function($e) {
|
|
if (specialKeyCodeMap[$e.which || $e.keyCode]) {
|
|
return;
|
|
}
|
|
_.defer(_.bind(that._onInput, that, $e));
|
|
});
|
|
}
|
|
return this;
|
|
},
|
|
focus: function focus() {
|
|
this.$input.focus();
|
|
},
|
|
blur: function blur() {
|
|
this.$input.blur();
|
|
},
|
|
getLangDir: function getLangDir() {
|
|
return this.dir;
|
|
},
|
|
getQuery: function getQuery() {
|
|
return this.query || "";
|
|
},
|
|
setQuery: function setQuery(val, silent) {
|
|
this.setInputValue(val);
|
|
this._setQuery(val, silent);
|
|
},
|
|
hasQueryChangedSinceLastFocus: function hasQueryChangedSinceLastFocus() {
|
|
return this.query !== this.queryWhenFocused;
|
|
},
|
|
getInputValue: function getInputValue() {
|
|
return this.$input.val();
|
|
},
|
|
setInputValue: function setInputValue(value) {
|
|
this.$input.val(value);
|
|
this.clearHintIfInvalid();
|
|
this._checkLanguageDirection();
|
|
},
|
|
resetInputValue: function resetInputValue() {
|
|
this.setInputValue(this.query);
|
|
},
|
|
getHint: function getHint() {
|
|
return this.$hint.val();
|
|
},
|
|
setHint: function setHint(value) {
|
|
this.$hint.val(value);
|
|
},
|
|
clearHint: function clearHint() {
|
|
this.setHint("");
|
|
},
|
|
clearHintIfInvalid: function clearHintIfInvalid() {
|
|
var val, hint, valIsPrefixOfHint, isValid;
|
|
val = this.getInputValue();
|
|
hint = this.getHint();
|
|
valIsPrefixOfHint = val !== hint && hint.indexOf(val) === 0;
|
|
isValid = val !== "" && valIsPrefixOfHint && !this.hasOverflow();
|
|
!isValid && this.clearHint();
|
|
},
|
|
hasFocus: function hasFocus() {
|
|
return this.$input.is(":focus");
|
|
},
|
|
hasOverflow: function hasOverflow() {
|
|
var constraint = this.$input.width() - 2;
|
|
this.$overflowHelper.text(this.getInputValue());
|
|
return this.$overflowHelper.width() >= constraint;
|
|
},
|
|
isCursorAtEnd: function() {
|
|
var valueLength, selectionStart, range;
|
|
valueLength = this.$input.val().length;
|
|
selectionStart = this.$input[0].selectionStart;
|
|
if (_.isNumber(selectionStart)) {
|
|
return selectionStart === valueLength;
|
|
} else if (document.selection) {
|
|
range = document.selection.createRange();
|
|
range.moveStart("character", -valueLength);
|
|
return valueLength === range.text.length;
|
|
}
|
|
return true;
|
|
},
|
|
destroy: function destroy() {
|
|
this.$hint.off(".tt");
|
|
this.$input.off(".tt");
|
|
this.$overflowHelper.remove();
|
|
this.$hint = this.$input = this.$overflowHelper = null;
|
|
}
|
|
});
|
|
return Input;
|
|
function buildOverflowHelper($input) {
|
|
return $('<pre aria-hidden="true"></pre>').css({
|
|
position: "absolute",
|
|
visibility: "hidden",
|
|
whiteSpace: "pre",
|
|
fontFamily: $input.css("font-family"),
|
|
fontSize: $input.css("font-size"),
|
|
fontStyle: $input.css("font-style"),
|
|
fontVariant: $input.css("font-variant"),
|
|
fontWeight: $input.css("font-weight"),
|
|
wordSpacing: $input.css("word-spacing"),
|
|
letterSpacing: $input.css("letter-spacing"),
|
|
textIndent: $input.css("text-indent"),
|
|
textRendering: $input.css("text-rendering"),
|
|
textTransform: $input.css("text-transform")
|
|
}).insertAfter($input);
|
|
}
|
|
function areQueriesEquivalent(a, b) {
|
|
return Input.normalizeQuery(a) === Input.normalizeQuery(b);
|
|
}
|
|
function withModifier($e) {
|
|
return $e.altKey || $e.ctrlKey || $e.metaKey || $e.shiftKey;
|
|
}
|
|
}();
|
|
var Dataset = function() {
|
|
"use strict";
|
|
var keys, nameGenerator;
|
|
keys = {
|
|
val: "tt-selectable-display",
|
|
obj: "tt-selectable-object"
|
|
};
|
|
nameGenerator = _.getIdGenerator();
|
|
function Dataset(o, www) {
|
|
o = o || {};
|
|
o.templates = o.templates || {};
|
|
o.templates.notFound = o.templates.notFound || o.templates.empty;
|
|
if (!o.source) {
|
|
$.error("missing source");
|
|
}
|
|
if (!o.node) {
|
|
$.error("missing node");
|
|
}
|
|
if (o.name && !isValidName(o.name)) {
|
|
$.error("invalid dataset name: " + o.name);
|
|
}
|
|
www.mixin(this);
|
|
this.highlight = !!o.highlight;
|
|
this.name = o.name || nameGenerator();
|
|
this.limit = o.limit || 5;
|
|
this.displayFn = getDisplayFn(o.display || o.displayKey);
|
|
this.templates = getTemplates(o.templates, this.displayFn);
|
|
this.source = o.source.__ttAdapter ? o.source.__ttAdapter() : o.source;
|
|
this.async = _.isUndefined(o.async) ? this.source.length > 2 : !!o.async;
|
|
this._resetLastSuggestion();
|
|
this.$el = $(o.node).addClass(this.classes.dataset).addClass(this.classes.dataset + "-" + this.name);
|
|
}
|
|
Dataset.extractData = function extractData(el) {
|
|
var $el = $(el);
|
|
if ($el.data(keys.obj)) {
|
|
return {
|
|
val: $el.data(keys.val) || "",
|
|
obj: $el.data(keys.obj) || null
|
|
};
|
|
}
|
|
return null;
|
|
};
|
|
_.mixin(Dataset.prototype, EventEmitter, {
|
|
_overwrite: function overwrite(query, suggestions) {
|
|
suggestions = suggestions || [];
|
|
if (suggestions.length) {
|
|
this._renderSuggestions(query, suggestions);
|
|
} else if (this.async && this.templates.pending) {
|
|
this._renderPending(query);
|
|
} else if (!this.async && this.templates.notFound) {
|
|
this._renderNotFound(query);
|
|
} else {
|
|
this._empty();
|
|
}
|
|
this.trigger("rendered", this.name, suggestions, false);
|
|
},
|
|
_append: function append(query, suggestions) {
|
|
suggestions = suggestions || [];
|
|
if (suggestions.length && this.$lastSuggestion.length) {
|
|
this._appendSuggestions(query, suggestions);
|
|
} else if (suggestions.length) {
|
|
this._renderSuggestions(query, suggestions);
|
|
} else if (!this.$lastSuggestion.length && this.templates.notFound) {
|
|
this._renderNotFound(query);
|
|
}
|
|
this.trigger("rendered", this.name, suggestions, true);
|
|
},
|
|
_renderSuggestions: function renderSuggestions(query, suggestions) {
|
|
var $fragment;
|
|
$fragment = this._getSuggestionsFragment(query, suggestions);
|
|
this.$lastSuggestion = $fragment.children().last();
|
|
this.$el.html($fragment).prepend(this._getHeader(query, suggestions)).append(this._getFooter(query, suggestions));
|
|
},
|
|
_appendSuggestions: function appendSuggestions(query, suggestions) {
|
|
var $fragment, $lastSuggestion;
|
|
$fragment = this._getSuggestionsFragment(query, suggestions);
|
|
$lastSuggestion = $fragment.children().last();
|
|
this.$lastSuggestion.after($fragment);
|
|
this.$lastSuggestion = $lastSuggestion;
|
|
},
|
|
_renderPending: function renderPending(query) {
|
|
var template = this.templates.pending;
|
|
this._resetLastSuggestion();
|
|
template && this.$el.html(template({
|
|
query: query,
|
|
dataset: this.name
|
|
}));
|
|
},
|
|
_renderNotFound: function renderNotFound(query) {
|
|
var template = this.templates.notFound;
|
|
this._resetLastSuggestion();
|
|
template && this.$el.html(template({
|
|
query: query,
|
|
dataset: this.name
|
|
}));
|
|
},
|
|
_empty: function empty() {
|
|
this.$el.empty();
|
|
this._resetLastSuggestion();
|
|
},
|
|
_getSuggestionsFragment: function getSuggestionsFragment(query, suggestions) {
|
|
var that = this, fragment;
|
|
fragment = document.createDocumentFragment();
|
|
_.each(suggestions, function getSuggestionNode(suggestion) {
|
|
var $el, context;
|
|
context = that._injectQuery(query, suggestion);
|
|
$el = $(that.templates.suggestion(context)).data(keys.obj, suggestion).data(keys.val, that.displayFn(suggestion)).addClass(that.classes.suggestion + " " + that.classes.selectable);
|
|
fragment.appendChild($el[0]);
|
|
});
|
|
this.highlight && highlight({
|
|
className: this.classes.highlight,
|
|
node: fragment,
|
|
pattern: query
|
|
});
|
|
return $(fragment);
|
|
},
|
|
_getFooter: function getFooter(query, suggestions) {
|
|
return this.templates.footer ? this.templates.footer({
|
|
query: query,
|
|
suggestions: suggestions,
|
|
dataset: this.name
|
|
}) : null;
|
|
},
|
|
_getHeader: function getHeader(query, suggestions) {
|
|
return this.templates.header ? this.templates.header({
|
|
query: query,
|
|
suggestions: suggestions,
|
|
dataset: this.name
|
|
}) : null;
|
|
},
|
|
_resetLastSuggestion: function resetLastSuggestion() {
|
|
this.$lastSuggestion = $();
|
|
},
|
|
_injectQuery: function injectQuery(query, obj) {
|
|
return _.isObject(obj) ? _.mixin({
|
|
_query: query
|
|
}, obj) : obj;
|
|
},
|
|
update: function update(query) {
|
|
var that = this, canceled = false, syncCalled = false, rendered = 0;
|
|
this.cancel();
|
|
this.cancel = function cancel() {
|
|
canceled = true;
|
|
that.cancel = $.noop;
|
|
that.async && that.trigger("asyncCanceled", query);
|
|
};
|
|
this.source(query, sync, async);
|
|
!syncCalled && sync([]);
|
|
function sync(suggestions) {
|
|
if (syncCalled) {
|
|
return;
|
|
}
|
|
syncCalled = true;
|
|
suggestions = (suggestions || []).slice(0, that.limit);
|
|
rendered = suggestions.length;
|
|
that._overwrite(query, suggestions);
|
|
if (rendered < that.limit && that.async) {
|
|
that.trigger("asyncRequested", query);
|
|
}
|
|
}
|
|
function async(suggestions) {
|
|
suggestions = suggestions || [];
|
|
if (!canceled && rendered < that.limit) {
|
|
that.cancel = $.noop;
|
|
rendered += suggestions.length;
|
|
that._append(query, suggestions.slice(0, that.limit - rendered));
|
|
that.async && that.trigger("asyncReceived", query);
|
|
}
|
|
}
|
|
},
|
|
cancel: $.noop,
|
|
clear: function clear() {
|
|
this._empty();
|
|
this.cancel();
|
|
this.trigger("cleared");
|
|
},
|
|
isEmpty: function isEmpty() {
|
|
return this.$el.is(":empty");
|
|
},
|
|
destroy: function destroy() {
|
|
this.$el = null;
|
|
}
|
|
});
|
|
return Dataset;
|
|
function getDisplayFn(display) {
|
|
display = display || _.stringify;
|
|
return _.isFunction(display) ? display : displayFn;
|
|
function displayFn(obj) {
|
|
return obj[display];
|
|
}
|
|
}
|
|
function getTemplates(templates, displayFn) {
|
|
return {
|
|
notFound: templates.notFound && _.templatify(templates.notFound),
|
|
pending: templates.pending && _.templatify(templates.pending),
|
|
header: templates.header && _.templatify(templates.header),
|
|
footer: templates.footer && _.templatify(templates.footer),
|
|
suggestion: templates.suggestion || suggestionTemplate
|
|
};
|
|
function suggestionTemplate(context) {
|
|
return "<div><p>" + displayFn(context) + "</p></div>";
|
|
}
|
|
}
|
|
function isValidName(str) {
|
|
return /^[_a-zA-Z0-9-]+$/.test(str);
|
|
}
|
|
}();
|
|
var Menu = function() {
|
|
"use strict";
|
|
function Menu(o, www) {
|
|
var that = this;
|
|
o = o || {};
|
|
if (!o.node) {
|
|
$.error("node is required");
|
|
}
|
|
www.mixin(this);
|
|
this.$node = $(o.node);
|
|
this.query = null;
|
|
this.datasets = _.map(o.datasets, initializeDataset);
|
|
function initializeDataset(oDataset) {
|
|
var node = that.$node.find(oDataset.node).first();
|
|
oDataset.node = node.length ? node : $(oDataset.templates.dataset).appendTo(that.$node);
|
|
return new Dataset(oDataset, www);
|
|
}
|
|
}
|
|
_.mixin(Menu.prototype, EventEmitter, {
|
|
_onSelectableClick: function onSelectableClick($e) {
|
|
this.trigger("selectableClicked", $($e.currentTarget));
|
|
},
|
|
_onRendered: function onRendered(type, dataset, suggestions, async) {
|
|
this.$node.toggleClass(this.classes.empty, this._allDatasetsEmpty());
|
|
this.trigger("datasetRendered", dataset, suggestions, async);
|
|
},
|
|
_onCleared: function onCleared() {
|
|
this.$node.toggleClass(this.classes.empty, this._allDatasetsEmpty());
|
|
this.trigger("datasetCleared");
|
|
},
|
|
_propagate: function propagate() {
|
|
this.trigger.apply(this, arguments);
|
|
},
|
|
_allDatasetsEmpty: function allDatasetsEmpty() {
|
|
return _.every(this.datasets, isDatasetEmpty);
|
|
function isDatasetEmpty(dataset) {
|
|
return dataset.isEmpty();
|
|
}
|
|
},
|
|
_getSelectables: function getSelectables() {
|
|
return this.$node.find(this.selectors.selectable);
|
|
},
|
|
_removeCursor: function _removeCursor() {
|
|
var $selectable = this.getActiveSelectable();
|
|
$selectable && $selectable.removeClass(this.classes.cursor);
|
|
},
|
|
_ensureVisible: function ensureVisible($el) {
|
|
var elTop, elBottom, nodeScrollTop, nodeHeight;
|
|
elTop = $el.position().top;
|
|
elBottom = elTop + $el.outerHeight(true);
|
|
nodeScrollTop = this.$node.scrollTop();
|
|
nodeHeight = this.$node.height() + parseInt(this.$node.css("paddingTop"), 10) + parseInt(this.$node.css("paddingBottom"), 10);
|
|
if (elTop < 0) {
|
|
this.$node.scrollTop(nodeScrollTop + elTop);
|
|
} else if (nodeHeight < elBottom) {
|
|
this.$node.scrollTop(nodeScrollTop + (elBottom - nodeHeight));
|
|
}
|
|
},
|
|
bind: function() {
|
|
var that = this, onSelectableClick;
|
|
onSelectableClick = _.bind(this._onSelectableClick, this);
|
|
this.$node.on("click.tt", this.selectors.selectable, onSelectableClick);
|
|
_.each(this.datasets, function(dataset) {
|
|
dataset.onSync("asyncRequested", that._propagate, that).onSync("asyncCanceled", that._propagate, that).onSync("asyncReceived", that._propagate, that).onSync("rendered", that._onRendered, that).onSync("cleared", that._onCleared, that);
|
|
});
|
|
return this;
|
|
},
|
|
isOpen: function isOpen() {
|
|
return this.$node.hasClass(this.classes.open);
|
|
},
|
|
open: function open() {
|
|
this.$node.addClass(this.classes.open);
|
|
},
|
|
close: function close() {
|
|
this.$node.removeClass(this.classes.open);
|
|
this._removeCursor();
|
|
},
|
|
setLanguageDirection: function setLanguageDirection(dir) {
|
|
this.$node.attr("dir", dir);
|
|
},
|
|
selectableRelativeToCursor: function selectableRelativeToCursor(delta) {
|
|
var $selectables, $oldCursor, oldIndex, newIndex;
|
|
$oldCursor = this.getActiveSelectable();
|
|
$selectables = this._getSelectables();
|
|
oldIndex = $oldCursor ? $selectables.index($oldCursor) : -1;
|
|
newIndex = oldIndex + delta;
|
|
newIndex = (newIndex + 1) % ($selectables.length + 1) - 1;
|
|
newIndex = newIndex < -1 ? $selectables.length - 1 : newIndex;
|
|
return newIndex === -1 ? null : $selectables.eq(newIndex);
|
|
},
|
|
setCursor: function setCursor($selectable) {
|
|
this._removeCursor();
|
|
if ($selectable = $selectable && $selectable.first()) {
|
|
$selectable.addClass(this.classes.cursor);
|
|
this._ensureVisible($selectable);
|
|
}
|
|
},
|
|
getSelectableData: function getSelectableData($el) {
|
|
return $el && $el.length ? Dataset.extractData($el) : null;
|
|
},
|
|
getActiveSelectable: function getActiveSelectable() {
|
|
var $selectable = this._getSelectables().filter(this.selectors.cursor).first();
|
|
return $selectable.length ? $selectable : null;
|
|
},
|
|
getTopSelectable: function getTopSelectable() {
|
|
var $selectable = this._getSelectables().first();
|
|
return $selectable.length ? $selectable : null;
|
|
},
|
|
update: function update(query) {
|
|
var isValidUpdate = query !== this.query;
|
|
if (isValidUpdate) {
|
|
this.query = query;
|
|
_.each(this.datasets, updateDataset);
|
|
}
|
|
return isValidUpdate;
|
|
function updateDataset(dataset) {
|
|
dataset.update(query);
|
|
}
|
|
},
|
|
empty: function empty() {
|
|
_.each(this.datasets, clearDataset);
|
|
this.query = null;
|
|
this.$node.addClass(this.classes.empty);
|
|
function clearDataset(dataset) {
|
|
dataset.clear();
|
|
}
|
|
},
|
|
destroy: function destroy() {
|
|
this.$node.off(".tt");
|
|
this.$node = null;
|
|
_.each(this.datasets, destroyDataset);
|
|
function destroyDataset(dataset) {
|
|
dataset.destroy();
|
|
}
|
|
}
|
|
});
|
|
return Menu;
|
|
}();
|
|
var DefaultMenu = function() {
|
|
"use strict";
|
|
var s = Menu.prototype;
|
|
function DefaultMenu() {
|
|
Menu.apply(this, [].slice.call(arguments, 0));
|
|
}
|
|
_.mixin(DefaultMenu.prototype, Menu.prototype, {
|
|
open: function open() {
|
|
!this._allDatasetsEmpty() && this._show();
|
|
return s.open.apply(this, [].slice.call(arguments, 0));
|
|
},
|
|
close: function close() {
|
|
this._hide();
|
|
return s.close.apply(this, [].slice.call(arguments, 0));
|
|
},
|
|
_onRendered: function onRendered() {
|
|
if (this._allDatasetsEmpty()) {
|
|
this._hide();
|
|
} else {
|
|
this.isOpen() && this._show();
|
|
}
|
|
return s._onRendered.apply(this, [].slice.call(arguments, 0));
|
|
},
|
|
_onCleared: function onCleared() {
|
|
if (this._allDatasetsEmpty()) {
|
|
this._hide();
|
|
} else {
|
|
this.isOpen() && this._show();
|
|
}
|
|
return s._onCleared.apply(this, [].slice.call(arguments, 0));
|
|
},
|
|
setLanguageDirection: function setLanguageDirection(dir) {
|
|
this.$node.css(dir === "ltr" ? this.css.ltr : this.css.rtl);
|
|
return s.setLanguageDirection.apply(this, [].slice.call(arguments, 0));
|
|
},
|
|
_hide: function hide() {
|
|
this.$node.hide();
|
|
},
|
|
_show: function show() {
|
|
this.$node.css("display", "block");
|
|
}
|
|
});
|
|
return DefaultMenu;
|
|
}();
|
|
var Typeahead = function() {
|
|
"use strict";
|
|
function Typeahead(o, www) {
|
|
var onFocused, onBlurred, onEnterKeyed, onTabKeyed, onEscKeyed, onUpKeyed, onDownKeyed, onLeftKeyed, onRightKeyed, onQueryChanged, onWhitespaceChanged;
|
|
o = o || {};
|
|
if (!o.input) {
|
|
$.error("missing input");
|
|
}
|
|
if (!o.menu) {
|
|
$.error("missing menu");
|
|
}
|
|
if (!o.eventBus) {
|
|
$.error("missing event bus");
|
|
}
|
|
www.mixin(this);
|
|
this.eventBus = o.eventBus;
|
|
this.minLength = _.isNumber(o.minLength) ? o.minLength : 1;
|
|
this.input = o.input;
|
|
this.menu = o.menu;
|
|
this.enabled = true;
|
|
this.active = false;
|
|
this.input.hasFocus() && this.activate();
|
|
this.dir = this.input.getLangDir();
|
|
this._hacks();
|
|
this.menu.bind().onSync("selectableClicked", this._onSelectableClicked, this).onSync("asyncRequested", this._onAsyncRequested, this).onSync("asyncCanceled", this._onAsyncCanceled, this).onSync("asyncReceived", this._onAsyncReceived, this).onSync("datasetRendered", this._onDatasetRendered, this).onSync("datasetCleared", this._onDatasetCleared, this);
|
|
onFocused = c(this, "activate", "open", "_onFocused");
|
|
onBlurred = c(this, "deactivate", "_onBlurred");
|
|
onEnterKeyed = c(this, "isActive", "isOpen", "_onEnterKeyed");
|
|
onTabKeyed = c(this, "isActive", "isOpen", "_onTabKeyed");
|
|
onEscKeyed = c(this, "isActive", "_onEscKeyed");
|
|
onUpKeyed = c(this, "isActive", "open", "_onUpKeyed");
|
|
onDownKeyed = c(this, "isActive", "open", "_onDownKeyed");
|
|
onLeftKeyed = c(this, "isActive", "isOpen", "_onLeftKeyed");
|
|
onRightKeyed = c(this, "isActive", "isOpen", "_onRightKeyed");
|
|
onQueryChanged = c(this, "_openIfActive", "_onQueryChanged");
|
|
onWhitespaceChanged = c(this, "_openIfActive", "_onWhitespaceChanged");
|
|
this.input.bind().onSync("focused", onFocused, this).onSync("blurred", onBlurred, this).onSync("enterKeyed", onEnterKeyed, this).onSync("tabKeyed", onTabKeyed, this).onSync("escKeyed", onEscKeyed, this).onSync("upKeyed", onUpKeyed, this).onSync("downKeyed", onDownKeyed, this).onSync("leftKeyed", onLeftKeyed, this).onSync("rightKeyed", onRightKeyed, this).onSync("queryChanged", onQueryChanged, this).onSync("whitespaceChanged", onWhitespaceChanged, this).onSync("langDirChanged", this._onLangDirChanged, this);
|
|
}
|
|
_.mixin(Typeahead.prototype, {
|
|
_hacks: function hacks() {
|
|
var $input, $menu;
|
|
$input = this.input.$input || $("<div>");
|
|
$menu = this.menu.$node || $("<div>");
|
|
$input.on("blur.tt", function($e) {
|
|
var active, isActive, hasActive;
|
|
active = document.activeElement;
|
|
isActive = $menu.is(active);
|
|
hasActive = $menu.has(active).length > 0;
|
|
if (_.isMsie() && (isActive || hasActive)) {
|
|
$e.preventDefault();
|
|
$e.stopImmediatePropagation();
|
|
_.defer(function() {
|
|
$input.focus();
|
|
});
|
|
}
|
|
});
|
|
$menu.on("mousedown.tt", function($e) {
|
|
$e.preventDefault();
|
|
});
|
|
},
|
|
_onSelectableClicked: function onSelectableClicked(type, $el) {
|
|
this.select($el);
|
|
},
|
|
_onDatasetCleared: function onDatasetCleared() {
|
|
this._updateHint();
|
|
},
|
|
_onDatasetRendered: function onDatasetRendered(type, dataset, suggestions, async) {
|
|
this._updateHint();
|
|
this.eventBus.trigger("render", suggestions, async, dataset);
|
|
},
|
|
_onAsyncRequested: function onAsyncRequested(type, dataset, query) {
|
|
this.eventBus.trigger("asyncrequest", query, dataset);
|
|
},
|
|
_onAsyncCanceled: function onAsyncCanceled(type, dataset, query) {
|
|
this.eventBus.trigger("asynccancel", query, dataset);
|
|
},
|
|
_onAsyncReceived: function onAsyncReceived(type, dataset, query) {
|
|
this.eventBus.trigger("asyncreceive", query, dataset);
|
|
},
|
|
_onFocused: function onFocused() {
|
|
this._minLengthMet() && this.menu.update(this.input.getQuery());
|
|
},
|
|
_onBlurred: function onBlurred() {
|
|
if (this.input.hasQueryChangedSinceLastFocus()) {
|
|
this.eventBus.trigger("change", this.input.getQuery());
|
|
}
|
|
},
|
|
_onEnterKeyed: function onEnterKeyed(type, $e) {
|
|
var $selectable;
|
|
if ($selectable = this.menu.getActiveSelectable()) {
|
|
this.select($selectable) && $e.preventDefault();
|
|
}
|
|
},
|
|
_onTabKeyed: function onTabKeyed(type, $e) {
|
|
var $selectable;
|
|
if ($selectable = this.menu.getActiveSelectable()) {
|
|
this.select($selectable) && $e.preventDefault();
|
|
} else if ($selectable = this.menu.getTopSelectable()) {
|
|
this.autocomplete($selectable) && $e.preventDefault();
|
|
}
|
|
},
|
|
_onEscKeyed: function onEscKeyed() {
|
|
this.close();
|
|
},
|
|
_onUpKeyed: function onUpKeyed() {
|
|
this.moveCursor(-1);
|
|
},
|
|
_onDownKeyed: function onDownKeyed() {
|
|
this.moveCursor(+1);
|
|
},
|
|
_onLeftKeyed: function onLeftKeyed() {
|
|
if (this.dir === "rtl" && this.input.isCursorAtEnd()) {
|
|
this.autocomplete(this.menu.getTopSelectable());
|
|
}
|
|
},
|
|
_onRightKeyed: function onRightKeyed() {
|
|
if (this.dir === "ltr" && this.input.isCursorAtEnd()) {
|
|
this.autocomplete(this.menu.getTopSelectable());
|
|
}
|
|
},
|
|
_onQueryChanged: function onQueryChanged(e, query) {
|
|
this._minLengthMet(query) ? this.menu.update(query) : this.menu.empty();
|
|
},
|
|
_onWhitespaceChanged: function onWhitespaceChanged() {
|
|
this._updateHint();
|
|
},
|
|
_onLangDirChanged: function onLangDirChanged(e, dir) {
|
|
if (this.dir !== dir) {
|
|
this.dir = dir;
|
|
this.menu.setLanguageDirection(dir);
|
|
}
|
|
},
|
|
_openIfActive: function openIfActive() {
|
|
this.isActive() && this.open();
|
|
},
|
|
_minLengthMet: function minLengthMet(query) {
|
|
query = _.isString(query) ? query : this.input.getQuery() || "";
|
|
return query.length >= this.minLength;
|
|
},
|
|
_updateHint: function updateHint() {
|
|
var $selectable, data, val, query, escapedQuery, frontMatchRegEx, match;
|
|
$selectable = this.menu.getTopSelectable();
|
|
data = this.menu.getSelectableData($selectable);
|
|
val = this.input.getInputValue();
|
|
if (data && !_.isBlankString(val) && !this.input.hasOverflow()) {
|
|
query = Input.normalizeQuery(val);
|
|
escapedQuery = _.escapeRegExChars(query);
|
|
frontMatchRegEx = new RegExp("^(?:" + escapedQuery + ")(.+$)", "i");
|
|
match = frontMatchRegEx.exec(data.val);
|
|
match && this.input.setHint(val + match[1]);
|
|
} else {
|
|
this.input.clearHint();
|
|
}
|
|
},
|
|
isEnabled: function isEnabled() {
|
|
return this.enabled;
|
|
},
|
|
enable: function enable() {
|
|
this.enabled = true;
|
|
},
|
|
disable: function disable() {
|
|
this.enabled = false;
|
|
},
|
|
isActive: function isActive() {
|
|
return this.active;
|
|
},
|
|
activate: function activate() {
|
|
if (this.isActive()) {
|
|
return true;
|
|
} else if (!this.isEnabled() || this.eventBus.before("active")) {
|
|
return false;
|
|
} else {
|
|
this.active = true;
|
|
this.eventBus.trigger("active");
|
|
return true;
|
|
}
|
|
},
|
|
deactivate: function deactivate() {
|
|
if (!this.isActive()) {
|
|
return true;
|
|
} else if (this.eventBus.before("idle")) {
|
|
return false;
|
|
} else {
|
|
this.active = false;
|
|
this.close();
|
|
this.eventBus.trigger("idle");
|
|
return true;
|
|
}
|
|
},
|
|
isOpen: function isOpen() {
|
|
return this.menu.isOpen();
|
|
},
|
|
open: function open() {
|
|
if (!this.isOpen() && !this.eventBus.before("open")) {
|
|
this.menu.open();
|
|
this._updateHint();
|
|
this.eventBus.trigger("open");
|
|
}
|
|
return this.isOpen();
|
|
},
|
|
close: function close() {
|
|
if (this.isOpen() && !this.eventBus.before("close")) {
|
|
this.menu.close();
|
|
this.input.clearHint();
|
|
this.input.resetInputValue();
|
|
this.eventBus.trigger("close");
|
|
}
|
|
return !this.isOpen();
|
|
},
|
|
setVal: function setVal(val) {
|
|
this.input.setQuery(_.toStr(val));
|
|
},
|
|
getVal: function getVal() {
|
|
return this.input.getQuery();
|
|
},
|
|
select: function select($selectable) {
|
|
var data = this.menu.getSelectableData($selectable);
|
|
if (data && !this.eventBus.before("select", data.obj)) {
|
|
this.input.setQuery(data.val, true);
|
|
this.close();
|
|
this.eventBus.trigger("select", data.obj);
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
autocomplete: function autocomplete($selectable) {
|
|
var query, data, isValid;
|
|
query = this.input.getQuery();
|
|
data = this.menu.getSelectableData($selectable);
|
|
isValid = data && query !== data.val;
|
|
if (isValid && !this.eventBus.before("autocomplete", data.obj)) {
|
|
this.input.setQuery(data.val);
|
|
this.eventBus.trigger("autocomplete", data.obj);
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
moveCursor: function moveCursor(delta) {
|
|
var query, $candidate, data, payload, cancelMove;
|
|
query = this.input.getQuery();
|
|
$candidate = this.menu.selectableRelativeToCursor(delta);
|
|
data = this.menu.getSelectableData($candidate);
|
|
payload = data ? data.obj : null;
|
|
cancelMove = this._minLengthMet() && this.menu.update(query);
|
|
if (!cancelMove && !this.eventBus.before("cursorchange", payload)) {
|
|
this.menu.setCursor($candidate);
|
|
if (data) {
|
|
this.input.setInputValue(data.val);
|
|
} else {
|
|
this.input.resetInputValue();
|
|
this._updateHint();
|
|
}
|
|
this.eventBus.trigger("cursorchange", payload);
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
destroy: function destroy() {
|
|
this.input.destroy();
|
|
this.menu.destroy();
|
|
}
|
|
});
|
|
return Typeahead;
|
|
function c(ctx) {
|
|
var methods = [].slice.call(arguments, 1);
|
|
return function() {
|
|
var args = [].slice.call(arguments);
|
|
_.each(methods, function(method) {
|
|
return ctx[method].apply(ctx, args);
|
|
});
|
|
};
|
|
}
|
|
}();
|
|
(function() {
|
|
"use strict";
|
|
var old, keys, methods;
|
|
old = $.fn.typeahead;
|
|
keys = {
|
|
www: "tt-www",
|
|
attrs: "tt-attrs",
|
|
typeahead: "tt-typeahead"
|
|
};
|
|
methods = {
|
|
initialize: function initialize(o, datasets) {
|
|
var www;
|
|
datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
|
|
o = o || {};
|
|
www = WWW(o);
|
|
return this.each(attach);
|
|
function attach() {
|
|
var $input, $wrapper, $hint, $menu, defaultHint, defaultMenu, eventBus, input, menu, typeahead, MenuConstructor;
|
|
_.each(datasets, function(d) {
|
|
d.highlight = !!o.highlight;
|
|
d.templates = _.mixin({
|
|
dataset: www.html.dataset()
|
|
}, d.templates);
|
|
});
|
|
$input = $(this);
|
|
$wrapper = www.html.wrapper();
|
|
$hint = $elOrNull(o.hint);
|
|
$menu = $elOrNull(o.menu);
|
|
defaultHint = o.hint !== false && !$hint;
|
|
defaultMenu = o.menu !== false && !$menu;
|
|
defaultHint && ($hint = buildHintFromInput($input, www));
|
|
defaultMenu && ($menu = www.html.menu().css(www.css.menu));
|
|
$hint && $hint.val("");
|
|
$input = prepInput($input, www);
|
|
if (defaultHint || defaultMenu) {
|
|
$wrapper.css(www.css.wrapper);
|
|
$input.css(defaultHint ? www.css.input : www.css.inputWithNoHint);
|
|
$input.wrap($wrapper).parent().prepend(defaultHint ? $hint : null).append(defaultMenu ? $menu : null);
|
|
}
|
|
MenuConstructor = defaultMenu ? DefaultMenu : Menu;
|
|
eventBus = new EventBus({
|
|
el: $input
|
|
});
|
|
input = new Input({
|
|
hint: $hint,
|
|
input: $input
|
|
}, www);
|
|
menu = new MenuConstructor({
|
|
node: $menu,
|
|
datasets: datasets
|
|
}, www);
|
|
typeahead = new Typeahead({
|
|
input: input,
|
|
menu: menu,
|
|
eventBus: eventBus,
|
|
minLength: o.minLength
|
|
}, www);
|
|
$input.data(keys.www, www);
|
|
$input.data(keys.typeahead, typeahead);
|
|
}
|
|
},
|
|
isEnabled: function isEnabled() {
|
|
var enabled;
|
|
ttEach(this.first(), function(t) {
|
|
enabled = t.isEnabled();
|
|
});
|
|
return enabled;
|
|
},
|
|
enable: function enable() {
|
|
ttEach(this, function(t) {
|
|
t.enable();
|
|
});
|
|
return this;
|
|
},
|
|
disable: function disable() {
|
|
ttEach(this, function(t) {
|
|
t.disable();
|
|
});
|
|
return this;
|
|
},
|
|
isActive: function isActive() {
|
|
var active;
|
|
ttEach(this.first(), function(t) {
|
|
active = t.isActive();
|
|
});
|
|
return active;
|
|
},
|
|
activate: function activate() {
|
|
ttEach(this, function(t) {
|
|
t.activate();
|
|
});
|
|
return this;
|
|
},
|
|
deactivate: function deactivate() {
|
|
ttEach(this, function(t) {
|
|
t.deactivate();
|
|
});
|
|
return this;
|
|
},
|
|
isOpen: function isOpen() {
|
|
var open;
|
|
ttEach(this.first(), function(t) {
|
|
open = t.isOpen();
|
|
});
|
|
return open;
|
|
},
|
|
open: function open() {
|
|
ttEach(this, function(t) {
|
|
t.open();
|
|
});
|
|
return this;
|
|
},
|
|
close: function close() {
|
|
ttEach(this, function(t) {
|
|
t.close();
|
|
});
|
|
return this;
|
|
},
|
|
select: function select(el) {
|
|
var success = false, $el = $(el);
|
|
ttEach(this.first(), function(t) {
|
|
success = t.select($el);
|
|
});
|
|
return success;
|
|
},
|
|
autocomplete: function autocomplete(el) {
|
|
var success = false, $el = $(el);
|
|
ttEach(this.first(), function(t) {
|
|
success = t.autocomplete($el);
|
|
});
|
|
return success;
|
|
},
|
|
moveCursor: function moveCursoe(delta) {
|
|
var success = false;
|
|
ttEach(this.first(), function(t) {
|
|
success = t.moveCursor(delta);
|
|
});
|
|
return success;
|
|
},
|
|
val: function val(newVal) {
|
|
var query;
|
|
if (!arguments.length) {
|
|
ttEach(this.first(), function(t) {
|
|
query = t.getVal();
|
|
});
|
|
return query;
|
|
} else {
|
|
ttEach(this, function(t) {
|
|
t.setVal(newVal);
|
|
});
|
|
return this;
|
|
}
|
|
},
|
|
destroy: function destroy() {
|
|
ttEach(this, function(typeahead, $input) {
|
|
revert($input);
|
|
typeahead.destroy();
|
|
});
|
|
return this;
|
|
}
|
|
};
|
|
$.fn.typeahead = function(method) {
|
|
if (methods[method]) {
|
|
return methods[method].apply(this, [].slice.call(arguments, 1));
|
|
} else {
|
|
return methods.initialize.apply(this, arguments);
|
|
}
|
|
};
|
|
$.fn.typeahead.noConflict = function noConflict() {
|
|
$.fn.typeahead = old;
|
|
return this;
|
|
};
|
|
function ttEach($els, fn) {
|
|
$els.each(function() {
|
|
var $input = $(this), typeahead;
|
|
(typeahead = $input.data(keys.typeahead)) && fn(typeahead, $input);
|
|
});
|
|
}
|
|
function buildHintFromInput($input, www) {
|
|
return $input.clone().addClass(www.classes.hint).removeData().css(www.css.hint).css(getBackgroundStyles($input)).prop("readonly", true).removeAttr("id name placeholder required").attr({
|
|
autocomplete: "off",
|
|
spellcheck: "false",
|
|
tabindex: -1
|
|
});
|
|
}
|
|
function prepInput($input, www) {
|
|
$input.data(keys.attrs, {
|
|
dir: $input.attr("dir"),
|
|
autocomplete: $input.attr("autocomplete"),
|
|
spellcheck: $input.attr("spellcheck"),
|
|
style: $input.attr("style")
|
|
});
|
|
$input.addClass(www.classes.input).attr({
|
|
autocomplete: "off",
|
|
spellcheck: false
|
|
});
|
|
try {
|
|
!$input.attr("dir") && $input.attr("dir", "auto");
|
|
} catch (e) {}
|
|
return $input;
|
|
}
|
|
function getBackgroundStyles($el) {
|
|
return {
|
|
backgroundAttachment: $el.css("background-attachment"),
|
|
backgroundClip: $el.css("background-clip"),
|
|
backgroundColor: $el.css("background-color"),
|
|
backgroundImage: $el.css("background-image"),
|
|
backgroundOrigin: $el.css("background-origin"),
|
|
backgroundPosition: $el.css("background-position"),
|
|
backgroundRepeat: $el.css("background-repeat"),
|
|
backgroundSize: $el.css("background-size")
|
|
};
|
|
}
|
|
function revert($input) {
|
|
var www, $wrapper;
|
|
www = $input.data(keys.www);
|
|
$wrapper = $input.parent().filter(www.selectors.wrapper);
|
|
_.each($input.data(keys.attrs), function(val, key) {
|
|
_.isUndefined(val) ? $input.removeAttr(key) : $input.attr(key, val);
|
|
});
|
|
$input.removeData(keys.typeahead).removeData(keys.www).removeData(keys.attr).removeClass(www.classes.input);
|
|
if ($wrapper.length) {
|
|
$input.detach().insertAfter($wrapper);
|
|
$wrapper.remove();
|
|
}
|
|
}
|
|
function $elOrNull(obj) {
|
|
var isValid, $el;
|
|
isValid = _.isJQuery(obj) || _.isElement(obj);
|
|
$el = isValid ? $(obj).first() : [];
|
|
return $el.length ? $el : null;
|
|
}
|
|
})();
|
|
});
|
|
/* ========================================================================
|
|
* Bootstrap: affix.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#affix
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// AFFIX CLASS DEFINITION
|
|
// ======================
|
|
|
|
var Affix = function (element, options) {
|
|
this.options = $.extend({}, Affix.DEFAULTS, options)
|
|
|
|
this.$target = $(this.options.target)
|
|
.on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
|
|
.on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
|
|
|
|
this.$element = $(element)
|
|
this.affixed = null
|
|
this.unpin = null
|
|
this.pinnedOffset = null
|
|
|
|
this.checkPosition()
|
|
}
|
|
|
|
Affix.VERSION = '3.3.7'
|
|
|
|
Affix.RESET = 'affix affix-top affix-bottom'
|
|
|
|
Affix.DEFAULTS = {
|
|
offset: 0,
|
|
target: window
|
|
}
|
|
|
|
Affix.prototype.getState = function (scrollHeight, height, offsetTop, offsetBottom) {
|
|
var scrollTop = this.$target.scrollTop()
|
|
var position = this.$element.offset()
|
|
var targetHeight = this.$target.height()
|
|
|
|
if (offsetTop != null && this.affixed == 'top') return scrollTop < offsetTop ? 'top' : false
|
|
|
|
if (this.affixed == 'bottom') {
|
|
if (offsetTop != null) return (scrollTop + this.unpin <= position.top) ? false : 'bottom'
|
|
return (scrollTop + targetHeight <= scrollHeight - offsetBottom) ? false : 'bottom'
|
|
}
|
|
|
|
var initializing = this.affixed == null
|
|
var colliderTop = initializing ? scrollTop : position.top
|
|
var colliderHeight = initializing ? targetHeight : height
|
|
|
|
if (offsetTop != null && scrollTop <= offsetTop) return 'top'
|
|
if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'
|
|
|
|
return false
|
|
}
|
|
|
|
Affix.prototype.getPinnedOffset = function () {
|
|
if (this.pinnedOffset) return this.pinnedOffset
|
|
this.$element.removeClass(Affix.RESET).addClass('affix')
|
|
var scrollTop = this.$target.scrollTop()
|
|
var position = this.$element.offset()
|
|
return (this.pinnedOffset = position.top - scrollTop)
|
|
}
|
|
|
|
Affix.prototype.checkPositionWithEventLoop = function () {
|
|
setTimeout($.proxy(this.checkPosition, this), 1)
|
|
}
|
|
|
|
Affix.prototype.checkPosition = function () {
|
|
if (!this.$element.is(':visible')) return
|
|
|
|
var height = this.$element.height()
|
|
var offset = this.options.offset
|
|
var offsetTop = offset.top
|
|
var offsetBottom = offset.bottom
|
|
var scrollHeight = Math.max($(document).height(), $(document.body).height())
|
|
|
|
if (typeof offset != 'object') offsetBottom = offsetTop = offset
|
|
if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element)
|
|
if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element)
|
|
|
|
var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
|
|
|
|
if (this.affixed != affix) {
|
|
if (this.unpin != null) this.$element.css('top', '')
|
|
|
|
var affixType = 'affix' + (affix ? '-' + affix : '')
|
|
var e = $.Event(affixType + '.bs.affix')
|
|
|
|
this.$element.trigger(e)
|
|
|
|
if (e.isDefaultPrevented()) return
|
|
|
|
this.affixed = affix
|
|
this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
|
|
|
|
this.$element
|
|
.removeClass(Affix.RESET)
|
|
.addClass(affixType)
|
|
.trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
|
|
}
|
|
|
|
if (affix == 'bottom') {
|
|
this.$element.offset({
|
|
top: scrollHeight - height - offsetBottom
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
// AFFIX PLUGIN DEFINITION
|
|
// =======================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.affix')
|
|
var options = typeof option == 'object' && option
|
|
|
|
if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.affix
|
|
|
|
$.fn.affix = Plugin
|
|
$.fn.affix.Constructor = Affix
|
|
|
|
|
|
// AFFIX NO CONFLICT
|
|
// =================
|
|
|
|
$.fn.affix.noConflict = function () {
|
|
$.fn.affix = old
|
|
return this
|
|
}
|
|
|
|
|
|
// AFFIX DATA-API
|
|
// ==============
|
|
|
|
$(window).on('load', function () {
|
|
$('[data-spy="affix"]').each(function () {
|
|
var $spy = $(this)
|
|
var data = $spy.data()
|
|
|
|
data.offset = data.offset || {}
|
|
|
|
if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom
|
|
if (data.offsetTop != null) data.offset.top = data.offsetTop
|
|
|
|
Plugin.call($spy, data)
|
|
})
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: alert.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#alerts
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// ALERT CLASS DEFINITION
|
|
// ======================
|
|
|
|
var dismiss = '[data-dismiss="alert"]'
|
|
var Alert = function (el) {
|
|
$(el).on('click', dismiss, this.close)
|
|
}
|
|
|
|
Alert.VERSION = '3.3.7'
|
|
|
|
Alert.TRANSITION_DURATION = 150
|
|
|
|
Alert.prototype.close = function (e) {
|
|
var $this = $(this)
|
|
var selector = $this.attr('data-target')
|
|
|
|
if (!selector) {
|
|
selector = $this.attr('href')
|
|
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
|
|
}
|
|
|
|
var $parent = $(selector === '#' ? [] : selector)
|
|
|
|
if (e) e.preventDefault()
|
|
|
|
if (!$parent.length) {
|
|
$parent = $this.closest('.alert')
|
|
}
|
|
|
|
$parent.trigger(e = $.Event('close.bs.alert'))
|
|
|
|
if (e.isDefaultPrevented()) return
|
|
|
|
$parent.removeClass('in')
|
|
|
|
function removeElement() {
|
|
// detach from parent, fire event then clean up data
|
|
$parent.detach().trigger('closed.bs.alert').remove()
|
|
}
|
|
|
|
$.support.transition && $parent.hasClass('fade') ?
|
|
$parent
|
|
.one('bsTransitionEnd', removeElement)
|
|
.emulateTransitionEnd(Alert.TRANSITION_DURATION) :
|
|
removeElement()
|
|
}
|
|
|
|
|
|
// ALERT PLUGIN DEFINITION
|
|
// =======================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.alert')
|
|
|
|
if (!data) $this.data('bs.alert', (data = new Alert(this)))
|
|
if (typeof option == 'string') data[option].call($this)
|
|
})
|
|
}
|
|
|
|
var old = $.fn.alert
|
|
|
|
$.fn.alert = Plugin
|
|
$.fn.alert.Constructor = Alert
|
|
|
|
|
|
// ALERT NO CONFLICT
|
|
// =================
|
|
|
|
$.fn.alert.noConflict = function () {
|
|
$.fn.alert = old
|
|
return this
|
|
}
|
|
|
|
|
|
// ALERT DATA-API
|
|
// ==============
|
|
|
|
$(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close)
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: button.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#buttons
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// BUTTON PUBLIC CLASS DEFINITION
|
|
// ==============================
|
|
|
|
var Button = function (element, options) {
|
|
this.$element = $(element)
|
|
this.options = $.extend({}, Button.DEFAULTS, options)
|
|
this.isLoading = false
|
|
}
|
|
|
|
Button.VERSION = '3.3.7'
|
|
|
|
Button.DEFAULTS = {
|
|
loadingText: 'loading...'
|
|
}
|
|
|
|
Button.prototype.setState = function (state) {
|
|
var d = 'disabled'
|
|
var $el = this.$element
|
|
var val = $el.is('input') ? 'val' : 'html'
|
|
var data = $el.data()
|
|
|
|
state += 'Text'
|
|
|
|
if (data.resetText == null) $el.data('resetText', $el[val]())
|
|
|
|
// push to event loop to allow forms to submit
|
|
setTimeout($.proxy(function () {
|
|
$el[val](data[state] == null ? this.options[state] : data[state])
|
|
|
|
if (state == 'loadingText') {
|
|
this.isLoading = true
|
|
$el.addClass(d).attr(d, d).prop(d, true)
|
|
} else if (this.isLoading) {
|
|
this.isLoading = false
|
|
$el.removeClass(d).removeAttr(d).prop(d, false)
|
|
}
|
|
}, this), 0)
|
|
}
|
|
|
|
Button.prototype.toggle = function () {
|
|
var changed = true
|
|
var $parent = this.$element.closest('[data-toggle="buttons"]')
|
|
|
|
if ($parent.length) {
|
|
var $input = this.$element.find('input')
|
|
if ($input.prop('type') == 'radio') {
|
|
if ($input.prop('checked')) changed = false
|
|
$parent.find('.active').removeClass('active')
|
|
this.$element.addClass('active')
|
|
} else if ($input.prop('type') == 'checkbox') {
|
|
if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false
|
|
this.$element.toggleClass('active')
|
|
}
|
|
$input.prop('checked', this.$element.hasClass('active'))
|
|
if (changed) $input.trigger('change')
|
|
} else {
|
|
this.$element.attr('aria-pressed', !this.$element.hasClass('active'))
|
|
this.$element.toggleClass('active')
|
|
}
|
|
}
|
|
|
|
|
|
// BUTTON PLUGIN DEFINITION
|
|
// ========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.button')
|
|
var options = typeof option == 'object' && option
|
|
|
|
if (!data) $this.data('bs.button', (data = new Button(this, options)))
|
|
|
|
if (option == 'toggle') data.toggle()
|
|
else if (option) data.setState(option)
|
|
})
|
|
}
|
|
|
|
var old = $.fn.button
|
|
|
|
$.fn.button = Plugin
|
|
$.fn.button.Constructor = Button
|
|
|
|
|
|
// BUTTON NO CONFLICT
|
|
// ==================
|
|
|
|
$.fn.button.noConflict = function () {
|
|
$.fn.button = old
|
|
return this
|
|
}
|
|
|
|
|
|
// BUTTON DATA-API
|
|
// ===============
|
|
|
|
$(document)
|
|
.on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
|
|
var $btn = $(e.target).closest('.btn')
|
|
Plugin.call($btn, 'toggle')
|
|
if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) {
|
|
// Prevent double click on radios, and the double selections (so cancellation) on checkboxes
|
|
e.preventDefault()
|
|
// The target component still receive the focus
|
|
if ($btn.is('input,button')) $btn.trigger('focus')
|
|
else $btn.find('input:visible,button:visible').first().trigger('focus')
|
|
}
|
|
})
|
|
.on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
|
|
$(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: carousel.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#carousel
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// CAROUSEL CLASS DEFINITION
|
|
// =========================
|
|
|
|
var Carousel = function (element, options) {
|
|
this.$element = $(element)
|
|
this.$indicators = this.$element.find('.carousel-indicators')
|
|
this.options = options
|
|
this.paused = null
|
|
this.sliding = null
|
|
this.interval = null
|
|
this.$active = null
|
|
this.$items = null
|
|
|
|
this.options.keyboard && this.$element.on('keydown.bs.carousel', $.proxy(this.keydown, this))
|
|
|
|
this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element
|
|
.on('mouseenter.bs.carousel', $.proxy(this.pause, this))
|
|
.on('mouseleave.bs.carousel', $.proxy(this.cycle, this))
|
|
}
|
|
|
|
Carousel.VERSION = '3.3.7'
|
|
|
|
Carousel.TRANSITION_DURATION = 600
|
|
|
|
Carousel.DEFAULTS = {
|
|
interval: 5000,
|
|
pause: 'hover',
|
|
wrap: true,
|
|
keyboard: true
|
|
}
|
|
|
|
Carousel.prototype.keydown = function (e) {
|
|
if (/input|textarea/i.test(e.target.tagName)) return
|
|
switch (e.which) {
|
|
case 37: this.prev(); break
|
|
case 39: this.next(); break
|
|
default: return
|
|
}
|
|
|
|
e.preventDefault()
|
|
}
|
|
|
|
Carousel.prototype.cycle = function (e) {
|
|
e || (this.paused = false)
|
|
|
|
this.interval && clearInterval(this.interval)
|
|
|
|
this.options.interval
|
|
&& !this.paused
|
|
&& (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
|
|
|
|
return this
|
|
}
|
|
|
|
Carousel.prototype.getItemIndex = function (item) {
|
|
this.$items = item.parent().children('.item')
|
|
return this.$items.index(item || this.$active)
|
|
}
|
|
|
|
Carousel.prototype.getItemForDirection = function (direction, active) {
|
|
var activeIndex = this.getItemIndex(active)
|
|
var willWrap = (direction == 'prev' && activeIndex === 0)
|
|
|| (direction == 'next' && activeIndex == (this.$items.length - 1))
|
|
if (willWrap && !this.options.wrap) return active
|
|
var delta = direction == 'prev' ? -1 : 1
|
|
var itemIndex = (activeIndex + delta) % this.$items.length
|
|
return this.$items.eq(itemIndex)
|
|
}
|
|
|
|
Carousel.prototype.to = function (pos) {
|
|
var that = this
|
|
var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active'))
|
|
|
|
if (pos > (this.$items.length - 1) || pos < 0) return
|
|
|
|
if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid"
|
|
if (activeIndex == pos) return this.pause().cycle()
|
|
|
|
return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos))
|
|
}
|
|
|
|
Carousel.prototype.pause = function (e) {
|
|
e || (this.paused = true)
|
|
|
|
if (this.$element.find('.next, .prev').length && $.support.transition) {
|
|
this.$element.trigger($.support.transition.end)
|
|
this.cycle(true)
|
|
}
|
|
|
|
this.interval = clearInterval(this.interval)
|
|
|
|
return this
|
|
}
|
|
|
|
Carousel.prototype.next = function () {
|
|
if (this.sliding) return
|
|
return this.slide('next')
|
|
}
|
|
|
|
Carousel.prototype.prev = function () {
|
|
if (this.sliding) return
|
|
return this.slide('prev')
|
|
}
|
|
|
|
Carousel.prototype.slide = function (type, next) {
|
|
var $active = this.$element.find('.item.active')
|
|
var $next = next || this.getItemForDirection(type, $active)
|
|
var isCycling = this.interval
|
|
var direction = type == 'next' ? 'left' : 'right'
|
|
var that = this
|
|
|
|
if ($next.hasClass('active')) return (this.sliding = false)
|
|
|
|
var relatedTarget = $next[0]
|
|
var slideEvent = $.Event('slide.bs.carousel', {
|
|
relatedTarget: relatedTarget,
|
|
direction: direction
|
|
})
|
|
this.$element.trigger(slideEvent)
|
|
if (slideEvent.isDefaultPrevented()) return
|
|
|
|
this.sliding = true
|
|
|
|
isCycling && this.pause()
|
|
|
|
if (this.$indicators.length) {
|
|
this.$indicators.find('.active').removeClass('active')
|
|
var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)])
|
|
$nextIndicator && $nextIndicator.addClass('active')
|
|
}
|
|
|
|
var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid"
|
|
if ($.support.transition && this.$element.hasClass('slide')) {
|
|
$next.addClass(type)
|
|
$next[0].offsetWidth // force reflow
|
|
$active.addClass(direction)
|
|
$next.addClass(direction)
|
|
$active
|
|
.one('bsTransitionEnd', function () {
|
|
$next.removeClass([type, direction].join(' ')).addClass('active')
|
|
$active.removeClass(['active', direction].join(' '))
|
|
that.sliding = false
|
|
setTimeout(function () {
|
|
that.$element.trigger(slidEvent)
|
|
}, 0)
|
|
})
|
|
.emulateTransitionEnd(Carousel.TRANSITION_DURATION)
|
|
} else {
|
|
$active.removeClass('active')
|
|
$next.addClass('active')
|
|
this.sliding = false
|
|
this.$element.trigger(slidEvent)
|
|
}
|
|
|
|
isCycling && this.cycle()
|
|
|
|
return this
|
|
}
|
|
|
|
|
|
// CAROUSEL PLUGIN DEFINITION
|
|
// ==========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.carousel')
|
|
var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
|
|
var action = typeof option == 'string' ? option : options.slide
|
|
|
|
if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
|
|
if (typeof option == 'number') data.to(option)
|
|
else if (action) data[action]()
|
|
else if (options.interval) data.pause().cycle()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.carousel
|
|
|
|
$.fn.carousel = Plugin
|
|
$.fn.carousel.Constructor = Carousel
|
|
|
|
|
|
// CAROUSEL NO CONFLICT
|
|
// ====================
|
|
|
|
$.fn.carousel.noConflict = function () {
|
|
$.fn.carousel = old
|
|
return this
|
|
}
|
|
|
|
|
|
// CAROUSEL DATA-API
|
|
// =================
|
|
|
|
var clickHandler = function (e) {
|
|
var href
|
|
var $this = $(this)
|
|
var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
|
|
if (!$target.hasClass('carousel')) return
|
|
var options = $.extend({}, $target.data(), $this.data())
|
|
var slideIndex = $this.attr('data-slide-to')
|
|
if (slideIndex) options.interval = false
|
|
|
|
Plugin.call($target, options)
|
|
|
|
if (slideIndex) {
|
|
$target.data('bs.carousel').to(slideIndex)
|
|
}
|
|
|
|
e.preventDefault()
|
|
}
|
|
|
|
$(document)
|
|
.on('click.bs.carousel.data-api', '[data-slide]', clickHandler)
|
|
.on('click.bs.carousel.data-api', '[data-slide-to]', clickHandler)
|
|
|
|
$(window).on('load', function () {
|
|
$('[data-ride="carousel"]').each(function () {
|
|
var $carousel = $(this)
|
|
Plugin.call($carousel, $carousel.data())
|
|
})
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: collapse.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#collapse
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
/* jshint latedef: false */
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// COLLAPSE PUBLIC CLASS DEFINITION
|
|
// ================================
|
|
|
|
var Collapse = function (element, options) {
|
|
this.$element = $(element)
|
|
this.options = $.extend({}, Collapse.DEFAULTS, options)
|
|
this.$trigger = $('[data-toggle="collapse"][href="#' + element.id + '"],' +
|
|
'[data-toggle="collapse"][data-target="#' + element.id + '"]')
|
|
this.transitioning = null
|
|
|
|
if (this.options.parent) {
|
|
this.$parent = this.getParent()
|
|
} else {
|
|
this.addAriaAndCollapsedClass(this.$element, this.$trigger)
|
|
}
|
|
|
|
if (this.options.toggle) this.toggle()
|
|
}
|
|
|
|
Collapse.VERSION = '3.3.7'
|
|
|
|
Collapse.TRANSITION_DURATION = 350
|
|
|
|
Collapse.DEFAULTS = {
|
|
toggle: true
|
|
}
|
|
|
|
Collapse.prototype.dimension = function () {
|
|
var hasWidth = this.$element.hasClass('width')
|
|
return hasWidth ? 'width' : 'height'
|
|
}
|
|
|
|
Collapse.prototype.show = function () {
|
|
if (this.transitioning || this.$element.hasClass('in')) return
|
|
|
|
var activesData
|
|
var actives = this.$parent && this.$parent.children('.panel').children('.in, .collapsing')
|
|
|
|
if (actives && actives.length) {
|
|
activesData = actives.data('bs.collapse')
|
|
if (activesData && activesData.transitioning) return
|
|
}
|
|
|
|
var startEvent = $.Event('show.bs.collapse')
|
|
this.$element.trigger(startEvent)
|
|
if (startEvent.isDefaultPrevented()) return
|
|
|
|
if (actives && actives.length) {
|
|
Plugin.call(actives, 'hide')
|
|
activesData || actives.data('bs.collapse', null)
|
|
}
|
|
|
|
var dimension = this.dimension()
|
|
|
|
this.$element
|
|
.removeClass('collapse')
|
|
.addClass('collapsing')[dimension](0)
|
|
.attr('aria-expanded', true)
|
|
|
|
this.$trigger
|
|
.removeClass('collapsed')
|
|
.attr('aria-expanded', true)
|
|
|
|
this.transitioning = 1
|
|
|
|
var complete = function () {
|
|
this.$element
|
|
.removeClass('collapsing')
|
|
.addClass('collapse in')[dimension]('')
|
|
this.transitioning = 0
|
|
this.$element
|
|
.trigger('shown.bs.collapse')
|
|
}
|
|
|
|
if (!$.support.transition) return complete.call(this)
|
|
|
|
var scrollSize = $.camelCase(['scroll', dimension].join('-'))
|
|
|
|
this.$element
|
|
.one('bsTransitionEnd', $.proxy(complete, this))
|
|
.emulateTransitionEnd(Collapse.TRANSITION_DURATION)[dimension](this.$element[0][scrollSize])
|
|
}
|
|
|
|
Collapse.prototype.hide = function () {
|
|
if (this.transitioning || !this.$element.hasClass('in')) return
|
|
|
|
var startEvent = $.Event('hide.bs.collapse')
|
|
this.$element.trigger(startEvent)
|
|
if (startEvent.isDefaultPrevented()) return
|
|
|
|
var dimension = this.dimension()
|
|
|
|
this.$element[dimension](this.$element[dimension]())[0].offsetHeight
|
|
|
|
this.$element
|
|
.addClass('collapsing')
|
|
.removeClass('collapse in')
|
|
.attr('aria-expanded', false)
|
|
|
|
this.$trigger
|
|
.addClass('collapsed')
|
|
.attr('aria-expanded', false)
|
|
|
|
this.transitioning = 1
|
|
|
|
var complete = function () {
|
|
this.transitioning = 0
|
|
this.$element
|
|
.removeClass('collapsing')
|
|
.addClass('collapse')
|
|
.trigger('hidden.bs.collapse')
|
|
}
|
|
|
|
if (!$.support.transition) return complete.call(this)
|
|
|
|
this.$element
|
|
[dimension](0)
|
|
.one('bsTransitionEnd', $.proxy(complete, this))
|
|
.emulateTransitionEnd(Collapse.TRANSITION_DURATION)
|
|
}
|
|
|
|
Collapse.prototype.toggle = function () {
|
|
this[this.$element.hasClass('in') ? 'hide' : 'show']()
|
|
}
|
|
|
|
Collapse.prototype.getParent = function () {
|
|
return $(this.options.parent)
|
|
.find('[data-toggle="collapse"][data-parent="' + this.options.parent + '"]')
|
|
.each($.proxy(function (i, element) {
|
|
var $element = $(element)
|
|
this.addAriaAndCollapsedClass(getTargetFromTrigger($element), $element)
|
|
}, this))
|
|
.end()
|
|
}
|
|
|
|
Collapse.prototype.addAriaAndCollapsedClass = function ($element, $trigger) {
|
|
var isOpen = $element.hasClass('in')
|
|
|
|
$element.attr('aria-expanded', isOpen)
|
|
$trigger
|
|
.toggleClass('collapsed', !isOpen)
|
|
.attr('aria-expanded', isOpen)
|
|
}
|
|
|
|
function getTargetFromTrigger($trigger) {
|
|
var href
|
|
var target = $trigger.attr('data-target')
|
|
|| (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
|
|
|
|
return $(target)
|
|
}
|
|
|
|
|
|
// COLLAPSE PLUGIN DEFINITION
|
|
// ==========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.collapse')
|
|
var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
|
|
|
|
if (!data && options.toggle && /show|hide/.test(option)) options.toggle = false
|
|
if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.collapse
|
|
|
|
$.fn.collapse = Plugin
|
|
$.fn.collapse.Constructor = Collapse
|
|
|
|
|
|
// COLLAPSE NO CONFLICT
|
|
// ====================
|
|
|
|
$.fn.collapse.noConflict = function () {
|
|
$.fn.collapse = old
|
|
return this
|
|
}
|
|
|
|
|
|
// COLLAPSE DATA-API
|
|
// =================
|
|
|
|
$(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) {
|
|
var $this = $(this)
|
|
|
|
if (!$this.attr('data-target')) e.preventDefault()
|
|
|
|
var $target = getTargetFromTrigger($this)
|
|
var data = $target.data('bs.collapse')
|
|
var option = data ? 'toggle' : $this.data()
|
|
|
|
Plugin.call($target, option)
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: dropdown.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#dropdowns
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// DROPDOWN CLASS DEFINITION
|
|
// =========================
|
|
|
|
var backdrop = '.dropdown-backdrop'
|
|
var toggle = '[data-toggle="dropdown"]'
|
|
var Dropdown = function (element) {
|
|
$(element).on('click.bs.dropdown', this.toggle)
|
|
}
|
|
|
|
Dropdown.VERSION = '3.3.7'
|
|
|
|
function getParent($this) {
|
|
var selector = $this.attr('data-target')
|
|
|
|
if (!selector) {
|
|
selector = $this.attr('href')
|
|
selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
|
|
}
|
|
|
|
var $parent = selector && $(selector)
|
|
|
|
return $parent && $parent.length ? $parent : $this.parent()
|
|
}
|
|
|
|
function clearMenus(e) {
|
|
if (e && e.which === 3) return
|
|
$(backdrop).remove()
|
|
$(toggle).each(function () {
|
|
var $this = $(this)
|
|
var $parent = getParent($this)
|
|
var relatedTarget = { relatedTarget: this }
|
|
|
|
if (!$parent.hasClass('open')) return
|
|
|
|
if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return
|
|
|
|
$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
|
|
|
|
if (e.isDefaultPrevented()) return
|
|
|
|
$this.attr('aria-expanded', 'false')
|
|
$parent.removeClass('open').trigger($.Event('hidden.bs.dropdown', relatedTarget))
|
|
})
|
|
}
|
|
|
|
Dropdown.prototype.toggle = function (e) {
|
|
var $this = $(this)
|
|
|
|
if ($this.is('.disabled, :disabled')) return
|
|
|
|
var $parent = getParent($this)
|
|
var isActive = $parent.hasClass('open')
|
|
|
|
clearMenus()
|
|
|
|
if (!isActive) {
|
|
if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
|
|
// if mobile we use a backdrop because click events don't delegate
|
|
$(document.createElement('div'))
|
|
.addClass('dropdown-backdrop')
|
|
.insertAfter($(this))
|
|
.on('click', clearMenus)
|
|
}
|
|
|
|
var relatedTarget = { relatedTarget: this }
|
|
$parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget))
|
|
|
|
if (e.isDefaultPrevented()) return
|
|
|
|
$this
|
|
.trigger('focus')
|
|
.attr('aria-expanded', 'true')
|
|
|
|
$parent
|
|
.toggleClass('open')
|
|
.trigger($.Event('shown.bs.dropdown', relatedTarget))
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
Dropdown.prototype.keydown = function (e) {
|
|
if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return
|
|
|
|
var $this = $(this)
|
|
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
|
|
if ($this.is('.disabled, :disabled')) return
|
|
|
|
var $parent = getParent($this)
|
|
var isActive = $parent.hasClass('open')
|
|
|
|
if (!isActive && e.which != 27 || isActive && e.which == 27) {
|
|
if (e.which == 27) $parent.find(toggle).trigger('focus')
|
|
return $this.trigger('click')
|
|
}
|
|
|
|
var desc = ' li:not(.disabled):visible a'
|
|
var $items = $parent.find('.dropdown-menu' + desc)
|
|
|
|
if (!$items.length) return
|
|
|
|
var index = $items.index(e.target)
|
|
|
|
if (e.which == 38 && index > 0) index-- // up
|
|
if (e.which == 40 && index < $items.length - 1) index++ // down
|
|
if (!~index) index = 0
|
|
|
|
$items.eq(index).trigger('focus')
|
|
}
|
|
|
|
|
|
// DROPDOWN PLUGIN DEFINITION
|
|
// ==========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.dropdown')
|
|
|
|
if (!data) $this.data('bs.dropdown', (data = new Dropdown(this)))
|
|
if (typeof option == 'string') data[option].call($this)
|
|
})
|
|
}
|
|
|
|
var old = $.fn.dropdown
|
|
|
|
$.fn.dropdown = Plugin
|
|
$.fn.dropdown.Constructor = Dropdown
|
|
|
|
|
|
// DROPDOWN NO CONFLICT
|
|
// ====================
|
|
|
|
$.fn.dropdown.noConflict = function () {
|
|
$.fn.dropdown = old
|
|
return this
|
|
}
|
|
|
|
|
|
// APPLY TO STANDARD DROPDOWN ELEMENTS
|
|
// ===================================
|
|
|
|
$(document)
|
|
.on('click.bs.dropdown.data-api', clearMenus)
|
|
.on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
|
|
.on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle)
|
|
.on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown)
|
|
.on('keydown.bs.dropdown.data-api', '.dropdown-menu', Dropdown.prototype.keydown)
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: modal.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#modals
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// MODAL CLASS DEFINITION
|
|
// ======================
|
|
|
|
var Modal = function (element, options) {
|
|
this.options = options
|
|
this.$body = $(document.body)
|
|
this.$element = $(element)
|
|
this.$dialog = this.$element.find('.modal-dialog')
|
|
this.$backdrop = null
|
|
this.isShown = null
|
|
this.originalBodyPad = null
|
|
this.scrollbarWidth = 0
|
|
this.ignoreBackdropClick = false
|
|
|
|
if (this.options.remote) {
|
|
this.$element
|
|
.find('.modal-content')
|
|
.load(this.options.remote, $.proxy(function () {
|
|
this.$element.trigger('loaded.bs.modal')
|
|
}, this))
|
|
}
|
|
}
|
|
|
|
Modal.VERSION = '3.3.7'
|
|
|
|
Modal.TRANSITION_DURATION = 300
|
|
Modal.BACKDROP_TRANSITION_DURATION = 150
|
|
|
|
Modal.DEFAULTS = {
|
|
backdrop: true,
|
|
keyboard: true,
|
|
show: true
|
|
}
|
|
|
|
Modal.prototype.toggle = function (_relatedTarget) {
|
|
return this.isShown ? this.hide() : this.show(_relatedTarget)
|
|
}
|
|
|
|
Modal.prototype.show = function (_relatedTarget) {
|
|
var that = this
|
|
var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget })
|
|
|
|
this.$element.trigger(e)
|
|
|
|
if (this.isShown || e.isDefaultPrevented()) return
|
|
|
|
this.isShown = true
|
|
|
|
this.checkScrollbar()
|
|
this.setScrollbar()
|
|
this.$body.addClass('modal-open')
|
|
|
|
this.escape()
|
|
this.resize()
|
|
|
|
this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
|
|
|
|
this.$dialog.on('mousedown.dismiss.bs.modal', function () {
|
|
that.$element.one('mouseup.dismiss.bs.modal', function (e) {
|
|
if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true
|
|
})
|
|
})
|
|
|
|
this.backdrop(function () {
|
|
var transition = $.support.transition && that.$element.hasClass('fade')
|
|
|
|
if (!that.$element.parent().length) {
|
|
that.$element.appendTo(that.$body) // don't move modals dom position
|
|
}
|
|
|
|
that.$element
|
|
.show()
|
|
.scrollTop(0)
|
|
|
|
that.adjustDialog()
|
|
|
|
if (transition) {
|
|
that.$element[0].offsetWidth // force reflow
|
|
}
|
|
|
|
that.$element.addClass('in')
|
|
|
|
that.enforceFocus()
|
|
|
|
var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
|
|
|
|
transition ?
|
|
that.$dialog // wait for modal to slide in
|
|
.one('bsTransitionEnd', function () {
|
|
that.$element.trigger('focus').trigger(e)
|
|
})
|
|
.emulateTransitionEnd(Modal.TRANSITION_DURATION) :
|
|
that.$element.trigger('focus').trigger(e)
|
|
})
|
|
}
|
|
|
|
Modal.prototype.hide = function (e) {
|
|
if (e) e.preventDefault()
|
|
|
|
e = $.Event('hide.bs.modal')
|
|
|
|
this.$element.trigger(e)
|
|
|
|
if (!this.isShown || e.isDefaultPrevented()) return
|
|
|
|
this.isShown = false
|
|
|
|
this.escape()
|
|
this.resize()
|
|
|
|
$(document).off('focusin.bs.modal')
|
|
|
|
this.$element
|
|
.removeClass('in')
|
|
.off('click.dismiss.bs.modal')
|
|
.off('mouseup.dismiss.bs.modal')
|
|
|
|
this.$dialog.off('mousedown.dismiss.bs.modal')
|
|
|
|
$.support.transition && this.$element.hasClass('fade') ?
|
|
this.$element
|
|
.one('bsTransitionEnd', $.proxy(this.hideModal, this))
|
|
.emulateTransitionEnd(Modal.TRANSITION_DURATION) :
|
|
this.hideModal()
|
|
}
|
|
|
|
Modal.prototype.enforceFocus = function () {
|
|
$(document)
|
|
.off('focusin.bs.modal') // guard against infinite focus loop
|
|
.on('focusin.bs.modal', $.proxy(function (e) {
|
|
if (document !== e.target &&
|
|
this.$element[0] !== e.target &&
|
|
!this.$element.has(e.target).length) {
|
|
this.$element.trigger('focus')
|
|
}
|
|
}, this))
|
|
}
|
|
|
|
Modal.prototype.escape = function () {
|
|
if (this.isShown && this.options.keyboard) {
|
|
this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) {
|
|
e.which == 27 && this.hide()
|
|
}, this))
|
|
} else if (!this.isShown) {
|
|
this.$element.off('keydown.dismiss.bs.modal')
|
|
}
|
|
}
|
|
|
|
Modal.prototype.resize = function () {
|
|
if (this.isShown) {
|
|
$(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this))
|
|
} else {
|
|
$(window).off('resize.bs.modal')
|
|
}
|
|
}
|
|
|
|
Modal.prototype.hideModal = function () {
|
|
var that = this
|
|
this.$element.hide()
|
|
this.backdrop(function () {
|
|
that.$body.removeClass('modal-open')
|
|
that.resetAdjustments()
|
|
that.resetScrollbar()
|
|
that.$element.trigger('hidden.bs.modal')
|
|
})
|
|
}
|
|
|
|
Modal.prototype.removeBackdrop = function () {
|
|
this.$backdrop && this.$backdrop.remove()
|
|
this.$backdrop = null
|
|
}
|
|
|
|
Modal.prototype.backdrop = function (callback) {
|
|
var that = this
|
|
var animate = this.$element.hasClass('fade') ? 'fade' : ''
|
|
|
|
if (this.isShown && this.options.backdrop) {
|
|
var doAnimate = $.support.transition && animate
|
|
|
|
this.$backdrop = $(document.createElement('div'))
|
|
.addClass('modal-backdrop ' + animate)
|
|
.appendTo(this.$body)
|
|
|
|
this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
|
|
if (this.ignoreBackdropClick) {
|
|
this.ignoreBackdropClick = false
|
|
return
|
|
}
|
|
if (e.target !== e.currentTarget) return
|
|
this.options.backdrop == 'static'
|
|
? this.$element[0].focus()
|
|
: this.hide()
|
|
}, this))
|
|
|
|
if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
|
|
|
|
this.$backdrop.addClass('in')
|
|
|
|
if (!callback) return
|
|
|
|
doAnimate ?
|
|
this.$backdrop
|
|
.one('bsTransitionEnd', callback)
|
|
.emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
|
|
callback()
|
|
|
|
} else if (!this.isShown && this.$backdrop) {
|
|
this.$backdrop.removeClass('in')
|
|
|
|
var callbackRemove = function () {
|
|
that.removeBackdrop()
|
|
callback && callback()
|
|
}
|
|
$.support.transition && this.$element.hasClass('fade') ?
|
|
this.$backdrop
|
|
.one('bsTransitionEnd', callbackRemove)
|
|
.emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
|
|
callbackRemove()
|
|
|
|
} else if (callback) {
|
|
callback()
|
|
}
|
|
}
|
|
|
|
// these following methods are used to handle overflowing modals
|
|
|
|
Modal.prototype.handleUpdate = function () {
|
|
this.adjustDialog()
|
|
}
|
|
|
|
Modal.prototype.adjustDialog = function () {
|
|
var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight
|
|
|
|
this.$element.css({
|
|
paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '',
|
|
paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
|
|
})
|
|
}
|
|
|
|
Modal.prototype.resetAdjustments = function () {
|
|
this.$element.css({
|
|
paddingLeft: '',
|
|
paddingRight: ''
|
|
})
|
|
}
|
|
|
|
Modal.prototype.checkScrollbar = function () {
|
|
var fullWindowWidth = window.innerWidth
|
|
if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
|
|
var documentElementRect = document.documentElement.getBoundingClientRect()
|
|
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left)
|
|
}
|
|
this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth
|
|
this.scrollbarWidth = this.measureScrollbar()
|
|
}
|
|
|
|
Modal.prototype.setScrollbar = function () {
|
|
var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
|
|
this.originalBodyPad = document.body.style.paddingRight || ''
|
|
if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
|
|
}
|
|
|
|
Modal.prototype.resetScrollbar = function () {
|
|
this.$body.css('padding-right', this.originalBodyPad)
|
|
}
|
|
|
|
Modal.prototype.measureScrollbar = function () { // thx walsh
|
|
var scrollDiv = document.createElement('div')
|
|
scrollDiv.className = 'modal-scrollbar-measure'
|
|
this.$body.append(scrollDiv)
|
|
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
|
|
this.$body[0].removeChild(scrollDiv)
|
|
return scrollbarWidth
|
|
}
|
|
|
|
|
|
// MODAL PLUGIN DEFINITION
|
|
// =======================
|
|
|
|
function Plugin(option, _relatedTarget) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.modal')
|
|
var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)
|
|
|
|
if (!data) $this.data('bs.modal', (data = new Modal(this, options)))
|
|
if (typeof option == 'string') data[option](_relatedTarget)
|
|
else if (options.show) data.show(_relatedTarget)
|
|
})
|
|
}
|
|
|
|
var old = $.fn.modal
|
|
|
|
$.fn.modal = Plugin
|
|
$.fn.modal.Constructor = Modal
|
|
|
|
|
|
// MODAL NO CONFLICT
|
|
// =================
|
|
|
|
$.fn.modal.noConflict = function () {
|
|
$.fn.modal = old
|
|
return this
|
|
}
|
|
|
|
|
|
// MODAL DATA-API
|
|
// ==============
|
|
|
|
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
|
|
var $this = $(this)
|
|
var href = $this.attr('href')
|
|
var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
|
|
var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
|
|
|
|
if ($this.is('a')) e.preventDefault()
|
|
|
|
$target.one('show.bs.modal', function (showEvent) {
|
|
if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
|
|
$target.one('hidden.bs.modal', function () {
|
|
$this.is(':visible') && $this.trigger('focus')
|
|
})
|
|
})
|
|
Plugin.call($target, option, this)
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: tooltip.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#tooltip
|
|
* Inspired by the original jQuery.tipsy by Jason Frame
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// TOOLTIP PUBLIC CLASS DEFINITION
|
|
// ===============================
|
|
|
|
var Tooltip = function (element, options) {
|
|
this.type = null
|
|
this.options = null
|
|
this.enabled = null
|
|
this.timeout = null
|
|
this.hoverState = null
|
|
this.$element = null
|
|
this.inState = null
|
|
|
|
this.init('tooltip', element, options)
|
|
}
|
|
|
|
Tooltip.VERSION = '3.3.7'
|
|
|
|
Tooltip.TRANSITION_DURATION = 150
|
|
|
|
Tooltip.DEFAULTS = {
|
|
animation: true,
|
|
placement: 'top',
|
|
selector: false,
|
|
template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
|
|
trigger: 'hover focus',
|
|
title: '',
|
|
delay: 0,
|
|
html: false,
|
|
container: false,
|
|
viewport: {
|
|
selector: 'body',
|
|
padding: 0
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.init = function (type, element, options) {
|
|
this.enabled = true
|
|
this.type = type
|
|
this.$element = $(element)
|
|
this.options = this.getOptions(options)
|
|
this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport))
|
|
this.inState = { click: false, hover: false, focus: false }
|
|
|
|
if (this.$element[0] instanceof document.constructor && !this.options.selector) {
|
|
throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!')
|
|
}
|
|
|
|
var triggers = this.options.trigger.split(' ')
|
|
|
|
for (var i = triggers.length; i--;) {
|
|
var trigger = triggers[i]
|
|
|
|
if (trigger == 'click') {
|
|
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
|
|
} else if (trigger != 'manual') {
|
|
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
|
|
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
|
|
|
|
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
|
|
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
|
|
}
|
|
}
|
|
|
|
this.options.selector ?
|
|
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
|
|
this.fixTitle()
|
|
}
|
|
|
|
Tooltip.prototype.getDefaults = function () {
|
|
return Tooltip.DEFAULTS
|
|
}
|
|
|
|
Tooltip.prototype.getOptions = function (options) {
|
|
options = $.extend({}, this.getDefaults(), this.$element.data(), options)
|
|
|
|
if (options.delay && typeof options.delay == 'number') {
|
|
options.delay = {
|
|
show: options.delay,
|
|
hide: options.delay
|
|
}
|
|
}
|
|
|
|
return options
|
|
}
|
|
|
|
Tooltip.prototype.getDelegateOptions = function () {
|
|
var options = {}
|
|
var defaults = this.getDefaults()
|
|
|
|
this._options && $.each(this._options, function (key, value) {
|
|
if (defaults[key] != value) options[key] = value
|
|
})
|
|
|
|
return options
|
|
}
|
|
|
|
Tooltip.prototype.enter = function (obj) {
|
|
var self = obj instanceof this.constructor ?
|
|
obj : $(obj.currentTarget).data('bs.' + this.type)
|
|
|
|
if (!self) {
|
|
self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
|
|
$(obj.currentTarget).data('bs.' + this.type, self)
|
|
}
|
|
|
|
if (obj instanceof $.Event) {
|
|
self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true
|
|
}
|
|
|
|
if (self.tip().hasClass('in') || self.hoverState == 'in') {
|
|
self.hoverState = 'in'
|
|
return
|
|
}
|
|
|
|
clearTimeout(self.timeout)
|
|
|
|
self.hoverState = 'in'
|
|
|
|
if (!self.options.delay || !self.options.delay.show) return self.show()
|
|
|
|
self.timeout = setTimeout(function () {
|
|
if (self.hoverState == 'in') self.show()
|
|
}, self.options.delay.show)
|
|
}
|
|
|
|
Tooltip.prototype.isInStateTrue = function () {
|
|
for (var key in this.inState) {
|
|
if (this.inState[key]) return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
Tooltip.prototype.leave = function (obj) {
|
|
var self = obj instanceof this.constructor ?
|
|
obj : $(obj.currentTarget).data('bs.' + this.type)
|
|
|
|
if (!self) {
|
|
self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
|
|
$(obj.currentTarget).data('bs.' + this.type, self)
|
|
}
|
|
|
|
if (obj instanceof $.Event) {
|
|
self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false
|
|
}
|
|
|
|
if (self.isInStateTrue()) return
|
|
|
|
clearTimeout(self.timeout)
|
|
|
|
self.hoverState = 'out'
|
|
|
|
if (!self.options.delay || !self.options.delay.hide) return self.hide()
|
|
|
|
self.timeout = setTimeout(function () {
|
|
if (self.hoverState == 'out') self.hide()
|
|
}, self.options.delay.hide)
|
|
}
|
|
|
|
Tooltip.prototype.show = function () {
|
|
var e = $.Event('show.bs.' + this.type)
|
|
|
|
if (this.hasContent() && this.enabled) {
|
|
this.$element.trigger(e)
|
|
|
|
var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0])
|
|
if (e.isDefaultPrevented() || !inDom) return
|
|
var that = this
|
|
|
|
var $tip = this.tip()
|
|
|
|
var tipId = this.getUID(this.type)
|
|
|
|
this.setContent()
|
|
$tip.attr('id', tipId)
|
|
this.$element.attr('aria-describedby', tipId)
|
|
|
|
if (this.options.animation) $tip.addClass('fade')
|
|
|
|
var placement = typeof this.options.placement == 'function' ?
|
|
this.options.placement.call(this, $tip[0], this.$element[0]) :
|
|
this.options.placement
|
|
|
|
var autoToken = /\s?auto?\s?/i
|
|
var autoPlace = autoToken.test(placement)
|
|
if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
|
|
|
|
$tip
|
|
.detach()
|
|
.css({ top: 0, left: 0, display: 'block' })
|
|
.addClass(placement)
|
|
.data('bs.' + this.type, this)
|
|
|
|
this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
|
|
this.$element.trigger('inserted.bs.' + this.type)
|
|
|
|
var pos = this.getPosition()
|
|
var actualWidth = $tip[0].offsetWidth
|
|
var actualHeight = $tip[0].offsetHeight
|
|
|
|
if (autoPlace) {
|
|
var orgPlacement = placement
|
|
var viewportDim = this.getPosition(this.$viewport)
|
|
|
|
placement = placement == 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' :
|
|
placement == 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' :
|
|
placement == 'right' && pos.right + actualWidth > viewportDim.width ? 'left' :
|
|
placement == 'left' && pos.left - actualWidth < viewportDim.left ? 'right' :
|
|
placement
|
|
|
|
$tip
|
|
.removeClass(orgPlacement)
|
|
.addClass(placement)
|
|
}
|
|
|
|
var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
|
|
|
|
this.applyPlacement(calculatedOffset, placement)
|
|
|
|
var complete = function () {
|
|
var prevHoverState = that.hoverState
|
|
that.$element.trigger('shown.bs.' + that.type)
|
|
that.hoverState = null
|
|
|
|
if (prevHoverState == 'out') that.leave(that)
|
|
}
|
|
|
|
$.support.transition && this.$tip.hasClass('fade') ?
|
|
$tip
|
|
.one('bsTransitionEnd', complete)
|
|
.emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
|
|
complete()
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.applyPlacement = function (offset, placement) {
|
|
var $tip = this.tip()
|
|
var width = $tip[0].offsetWidth
|
|
var height = $tip[0].offsetHeight
|
|
|
|
// manually read margins because getBoundingClientRect includes difference
|
|
var marginTop = parseInt($tip.css('margin-top'), 10)
|
|
var marginLeft = parseInt($tip.css('margin-left'), 10)
|
|
|
|
// we must check for NaN for ie 8/9
|
|
if (isNaN(marginTop)) marginTop = 0
|
|
if (isNaN(marginLeft)) marginLeft = 0
|
|
|
|
offset.top += marginTop
|
|
offset.left += marginLeft
|
|
|
|
// $.fn.offset doesn't round pixel values
|
|
// so we use setOffset directly with our own function B-0
|
|
$.offset.setOffset($tip[0], $.extend({
|
|
using: function (props) {
|
|
$tip.css({
|
|
top: Math.round(props.top),
|
|
left: Math.round(props.left)
|
|
})
|
|
}
|
|
}, offset), 0)
|
|
|
|
$tip.addClass('in')
|
|
|
|
// check to see if placing tip in new offset caused the tip to resize itself
|
|
var actualWidth = $tip[0].offsetWidth
|
|
var actualHeight = $tip[0].offsetHeight
|
|
|
|
if (placement == 'top' && actualHeight != height) {
|
|
offset.top = offset.top + height - actualHeight
|
|
}
|
|
|
|
var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
|
|
|
|
if (delta.left) offset.left += delta.left
|
|
else offset.top += delta.top
|
|
|
|
var isVertical = /top|bottom/.test(placement)
|
|
var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
|
|
var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'
|
|
|
|
$tip.offset(offset)
|
|
this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical)
|
|
}
|
|
|
|
Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) {
|
|
this.arrow()
|
|
.css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%')
|
|
.css(isVertical ? 'top' : 'left', '')
|
|
}
|
|
|
|
Tooltip.prototype.setContent = function () {
|
|
var $tip = this.tip()
|
|
var title = this.getTitle()
|
|
|
|
$tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
|
|
$tip.removeClass('fade in top bottom left right')
|
|
}
|
|
|
|
Tooltip.prototype.hide = function (callback) {
|
|
var that = this
|
|
var $tip = $(this.$tip)
|
|
var e = $.Event('hide.bs.' + this.type)
|
|
|
|
function complete() {
|
|
if (that.hoverState != 'in') $tip.detach()
|
|
if (that.$element) { // TODO: Check whether guarding this code with this `if` is really necessary.
|
|
that.$element
|
|
.removeAttr('aria-describedby')
|
|
.trigger('hidden.bs.' + that.type)
|
|
}
|
|
callback && callback()
|
|
}
|
|
|
|
this.$element.trigger(e)
|
|
|
|
if (e.isDefaultPrevented()) return
|
|
|
|
$tip.removeClass('in')
|
|
|
|
$.support.transition && $tip.hasClass('fade') ?
|
|
$tip
|
|
.one('bsTransitionEnd', complete)
|
|
.emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
|
|
complete()
|
|
|
|
this.hoverState = null
|
|
|
|
return this
|
|
}
|
|
|
|
Tooltip.prototype.fixTitle = function () {
|
|
var $e = this.$element
|
|
if ($e.attr('title') || typeof $e.attr('data-original-title') != 'string') {
|
|
$e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.hasContent = function () {
|
|
return this.getTitle()
|
|
}
|
|
|
|
Tooltip.prototype.getPosition = function ($element) {
|
|
$element = $element || this.$element
|
|
|
|
var el = $element[0]
|
|
var isBody = el.tagName == 'BODY'
|
|
|
|
var elRect = el.getBoundingClientRect()
|
|
if (elRect.width == null) {
|
|
// width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093
|
|
elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top })
|
|
}
|
|
var isSvg = window.SVGElement && el instanceof window.SVGElement
|
|
// Avoid using $.offset() on SVGs since it gives incorrect results in jQuery 3.
|
|
// See https://github.com/twbs/bootstrap/issues/20280
|
|
var elOffset = isBody ? { top: 0, left: 0 } : (isSvg ? null : $element.offset())
|
|
var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() }
|
|
var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null
|
|
|
|
return $.extend({}, elRect, scroll, outerDims, elOffset)
|
|
}
|
|
|
|
Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
|
|
return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } :
|
|
placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
|
|
placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
|
|
/* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
|
|
|
|
}
|
|
|
|
Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) {
|
|
var delta = { top: 0, left: 0 }
|
|
if (!this.$viewport) return delta
|
|
|
|
var viewportPadding = this.options.viewport && this.options.viewport.padding || 0
|
|
var viewportDimensions = this.getPosition(this.$viewport)
|
|
|
|
if (/right|left/.test(placement)) {
|
|
var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll
|
|
var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight
|
|
if (topEdgeOffset < viewportDimensions.top) { // top overflow
|
|
delta.top = viewportDimensions.top - topEdgeOffset
|
|
} else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
|
|
delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset
|
|
}
|
|
} else {
|
|
var leftEdgeOffset = pos.left - viewportPadding
|
|
var rightEdgeOffset = pos.left + viewportPadding + actualWidth
|
|
if (leftEdgeOffset < viewportDimensions.left) { // left overflow
|
|
delta.left = viewportDimensions.left - leftEdgeOffset
|
|
} else if (rightEdgeOffset > viewportDimensions.right) { // right overflow
|
|
delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
|
|
}
|
|
}
|
|
|
|
return delta
|
|
}
|
|
|
|
Tooltip.prototype.getTitle = function () {
|
|
var title
|
|
var $e = this.$element
|
|
var o = this.options
|
|
|
|
title = $e.attr('data-original-title')
|
|
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
|
|
|
|
return title
|
|
}
|
|
|
|
Tooltip.prototype.getUID = function (prefix) {
|
|
do prefix += ~~(Math.random() * 1000000)
|
|
while (document.getElementById(prefix))
|
|
return prefix
|
|
}
|
|
|
|
Tooltip.prototype.tip = function () {
|
|
if (!this.$tip) {
|
|
this.$tip = $(this.options.template)
|
|
if (this.$tip.length != 1) {
|
|
throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!')
|
|
}
|
|
}
|
|
return this.$tip
|
|
}
|
|
|
|
Tooltip.prototype.arrow = function () {
|
|
return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow'))
|
|
}
|
|
|
|
Tooltip.prototype.enable = function () {
|
|
this.enabled = true
|
|
}
|
|
|
|
Tooltip.prototype.disable = function () {
|
|
this.enabled = false
|
|
}
|
|
|
|
Tooltip.prototype.toggleEnabled = function () {
|
|
this.enabled = !this.enabled
|
|
}
|
|
|
|
Tooltip.prototype.toggle = function (e) {
|
|
var self = this
|
|
if (e) {
|
|
self = $(e.currentTarget).data('bs.' + this.type)
|
|
if (!self) {
|
|
self = new this.constructor(e.currentTarget, this.getDelegateOptions())
|
|
$(e.currentTarget).data('bs.' + this.type, self)
|
|
}
|
|
}
|
|
|
|
if (e) {
|
|
self.inState.click = !self.inState.click
|
|
if (self.isInStateTrue()) self.enter(self)
|
|
else self.leave(self)
|
|
} else {
|
|
self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.destroy = function () {
|
|
var that = this
|
|
clearTimeout(this.timeout)
|
|
this.hide(function () {
|
|
that.$element.off('.' + that.type).removeData('bs.' + that.type)
|
|
if (that.$tip) {
|
|
that.$tip.detach()
|
|
}
|
|
that.$tip = null
|
|
that.$arrow = null
|
|
that.$viewport = null
|
|
that.$element = null
|
|
})
|
|
}
|
|
|
|
|
|
// TOOLTIP PLUGIN DEFINITION
|
|
// =========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.tooltip')
|
|
var options = typeof option == 'object' && option
|
|
|
|
if (!data && /destroy|hide/.test(option)) return
|
|
if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.tooltip
|
|
|
|
$.fn.tooltip = Plugin
|
|
$.fn.tooltip.Constructor = Tooltip
|
|
|
|
|
|
// TOOLTIP NO CONFLICT
|
|
// ===================
|
|
|
|
$.fn.tooltip.noConflict = function () {
|
|
$.fn.tooltip = old
|
|
return this
|
|
}
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: popover.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#popovers
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// POPOVER PUBLIC CLASS DEFINITION
|
|
// ===============================
|
|
|
|
var Popover = function (element, options) {
|
|
this.init('popover', element, options)
|
|
}
|
|
|
|
if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
|
|
|
|
Popover.VERSION = '3.3.7'
|
|
|
|
Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, {
|
|
placement: 'right',
|
|
trigger: 'click',
|
|
content: '',
|
|
template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
|
|
})
|
|
|
|
|
|
// NOTE: POPOVER EXTENDS tooltip.js
|
|
// ================================
|
|
|
|
Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
|
|
|
|
Popover.prototype.constructor = Popover
|
|
|
|
Popover.prototype.getDefaults = function () {
|
|
return Popover.DEFAULTS
|
|
}
|
|
|
|
Popover.prototype.setContent = function () {
|
|
var $tip = this.tip()
|
|
var title = this.getTitle()
|
|
var content = this.getContent()
|
|
|
|
$tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
|
|
$tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events
|
|
this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
|
|
](content)
|
|
|
|
$tip.removeClass('fade top bottom left right in')
|
|
|
|
// IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
|
|
// this manually by checking the contents.
|
|
if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
|
|
}
|
|
|
|
Popover.prototype.hasContent = function () {
|
|
return this.getTitle() || this.getContent()
|
|
}
|
|
|
|
Popover.prototype.getContent = function () {
|
|
var $e = this.$element
|
|
var o = this.options
|
|
|
|
return $e.attr('data-content')
|
|
|| (typeof o.content == 'function' ?
|
|
o.content.call($e[0]) :
|
|
o.content)
|
|
}
|
|
|
|
Popover.prototype.arrow = function () {
|
|
return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
|
|
}
|
|
|
|
|
|
// POPOVER PLUGIN DEFINITION
|
|
// =========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.popover')
|
|
var options = typeof option == 'object' && option
|
|
|
|
if (!data && /destroy|hide/.test(option)) return
|
|
if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.popover
|
|
|
|
$.fn.popover = Plugin
|
|
$.fn.popover.Constructor = Popover
|
|
|
|
|
|
// POPOVER NO CONFLICT
|
|
// ===================
|
|
|
|
$.fn.popover.noConflict = function () {
|
|
$.fn.popover = old
|
|
return this
|
|
}
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: scrollspy.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#scrollspy
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// SCROLLSPY CLASS DEFINITION
|
|
// ==========================
|
|
|
|
function ScrollSpy(element, options) {
|
|
this.$body = $(document.body)
|
|
this.$scrollElement = $(element).is(document.body) ? $(window) : $(element)
|
|
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
|
this.selector = (this.options.target || '') + ' .nav li > a'
|
|
this.offsets = []
|
|
this.targets = []
|
|
this.activeTarget = null
|
|
this.scrollHeight = 0
|
|
|
|
this.$scrollElement.on('scroll.bs.scrollspy', $.proxy(this.process, this))
|
|
this.refresh()
|
|
this.process()
|
|
}
|
|
|
|
ScrollSpy.VERSION = '3.3.7'
|
|
|
|
ScrollSpy.DEFAULTS = {
|
|
offset: 10
|
|
}
|
|
|
|
ScrollSpy.prototype.getScrollHeight = function () {
|
|
return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight)
|
|
}
|
|
|
|
ScrollSpy.prototype.refresh = function () {
|
|
var that = this
|
|
var offsetMethod = 'offset'
|
|
var offsetBase = 0
|
|
|
|
this.offsets = []
|
|
this.targets = []
|
|
this.scrollHeight = this.getScrollHeight()
|
|
|
|
if (!$.isWindow(this.$scrollElement[0])) {
|
|
offsetMethod = 'position'
|
|
offsetBase = this.$scrollElement.scrollTop()
|
|
}
|
|
|
|
this.$body
|
|
.find(this.selector)
|
|
.map(function () {
|
|
var $el = $(this)
|
|
var href = $el.data('target') || $el.attr('href')
|
|
var $href = /^#./.test(href) && $(href)
|
|
|
|
return ($href
|
|
&& $href.length
|
|
&& $href.is(':visible')
|
|
&& [[$href[offsetMethod]().top + offsetBase, href]]) || null
|
|
})
|
|
.sort(function (a, b) { return a[0] - b[0] })
|
|
.each(function () {
|
|
that.offsets.push(this[0])
|
|
that.targets.push(this[1])
|
|
})
|
|
}
|
|
|
|
ScrollSpy.prototype.process = function () {
|
|
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
|
|
var scrollHeight = this.getScrollHeight()
|
|
var maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height()
|
|
var offsets = this.offsets
|
|
var targets = this.targets
|
|
var activeTarget = this.activeTarget
|
|
var i
|
|
|
|
if (this.scrollHeight != scrollHeight) {
|
|
this.refresh()
|
|
}
|
|
|
|
if (scrollTop >= maxScroll) {
|
|
return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
|
|
}
|
|
|
|
if (activeTarget && scrollTop < offsets[0]) {
|
|
this.activeTarget = null
|
|
return this.clear()
|
|
}
|
|
|
|
for (i = offsets.length; i--;) {
|
|
activeTarget != targets[i]
|
|
&& scrollTop >= offsets[i]
|
|
&& (offsets[i + 1] === undefined || scrollTop < offsets[i + 1])
|
|
&& this.activate(targets[i])
|
|
}
|
|
}
|
|
|
|
ScrollSpy.prototype.activate = function (target) {
|
|
this.activeTarget = target
|
|
|
|
this.clear()
|
|
|
|
var selector = this.selector +
|
|
'[data-target="' + target + '"],' +
|
|
this.selector + '[href="' + target + '"]'
|
|
|
|
var active = $(selector)
|
|
.parents('li')
|
|
.addClass('active')
|
|
|
|
if (active.parent('.dropdown-menu').length) {
|
|
active = active
|
|
.closest('li.dropdown')
|
|
.addClass('active')
|
|
}
|
|
|
|
active.trigger('activate.bs.scrollspy')
|
|
}
|
|
|
|
ScrollSpy.prototype.clear = function () {
|
|
$(this.selector)
|
|
.parentsUntil(this.options.target, '.active')
|
|
.removeClass('active')
|
|
}
|
|
|
|
|
|
// SCROLLSPY PLUGIN DEFINITION
|
|
// ===========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.scrollspy')
|
|
var options = typeof option == 'object' && option
|
|
|
|
if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.scrollspy
|
|
|
|
$.fn.scrollspy = Plugin
|
|
$.fn.scrollspy.Constructor = ScrollSpy
|
|
|
|
|
|
// SCROLLSPY NO CONFLICT
|
|
// =====================
|
|
|
|
$.fn.scrollspy.noConflict = function () {
|
|
$.fn.scrollspy = old
|
|
return this
|
|
}
|
|
|
|
|
|
// SCROLLSPY DATA-API
|
|
// ==================
|
|
|
|
$(window).on('load.bs.scrollspy.data-api', function () {
|
|
$('[data-spy="scroll"]').each(function () {
|
|
var $spy = $(this)
|
|
Plugin.call($spy, $spy.data())
|
|
})
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: tab.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#tabs
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// TAB CLASS DEFINITION
|
|
// ====================
|
|
|
|
var Tab = function (element) {
|
|
// jscs:disable requireDollarBeforejQueryAssignment
|
|
this.element = $(element)
|
|
// jscs:enable requireDollarBeforejQueryAssignment
|
|
}
|
|
|
|
Tab.VERSION = '3.3.7'
|
|
|
|
Tab.TRANSITION_DURATION = 150
|
|
|
|
Tab.prototype.show = function () {
|
|
var $this = this.element
|
|
var $ul = $this.closest('ul:not(.dropdown-menu)')
|
|
var selector = $this.data('target')
|
|
|
|
if (!selector) {
|
|
selector = $this.attr('href')
|
|
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
|
|
}
|
|
|
|
if ($this.parent('li').hasClass('active')) return
|
|
|
|
var $previous = $ul.find('.active:last a')
|
|
var hideEvent = $.Event('hide.bs.tab', {
|
|
relatedTarget: $this[0]
|
|
})
|
|
var showEvent = $.Event('show.bs.tab', {
|
|
relatedTarget: $previous[0]
|
|
})
|
|
|
|
$previous.trigger(hideEvent)
|
|
$this.trigger(showEvent)
|
|
|
|
if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
|
|
|
|
var $target = $(selector)
|
|
|
|
this.activate($this.closest('li'), $ul)
|
|
this.activate($target, $target.parent(), function () {
|
|
$previous.trigger({
|
|
type: 'hidden.bs.tab',
|
|
relatedTarget: $this[0]
|
|
})
|
|
$this.trigger({
|
|
type: 'shown.bs.tab',
|
|
relatedTarget: $previous[0]
|
|
})
|
|
})
|
|
}
|
|
|
|
Tab.prototype.activate = function (element, container, callback) {
|
|
var $active = container.find('> .active')
|
|
var transition = callback
|
|
&& $.support.transition
|
|
&& ($active.length && $active.hasClass('fade') || !!container.find('> .fade').length)
|
|
|
|
function next() {
|
|
$active
|
|
.removeClass('active')
|
|
.find('> .dropdown-menu > .active')
|
|
.removeClass('active')
|
|
.end()
|
|
.find('[data-toggle="tab"]')
|
|
.attr('aria-expanded', false)
|
|
|
|
element
|
|
.addClass('active')
|
|
.find('[data-toggle="tab"]')
|
|
.attr('aria-expanded', true)
|
|
|
|
if (transition) {
|
|
element[0].offsetWidth // reflow for transition
|
|
element.addClass('in')
|
|
} else {
|
|
element.removeClass('fade')
|
|
}
|
|
|
|
if (element.parent('.dropdown-menu').length) {
|
|
element
|
|
.closest('li.dropdown')
|
|
.addClass('active')
|
|
.end()
|
|
.find('[data-toggle="tab"]')
|
|
.attr('aria-expanded', true)
|
|
}
|
|
|
|
callback && callback()
|
|
}
|
|
|
|
$active.length && transition ?
|
|
$active
|
|
.one('bsTransitionEnd', next)
|
|
.emulateTransitionEnd(Tab.TRANSITION_DURATION) :
|
|
next()
|
|
|
|
$active.removeClass('in')
|
|
}
|
|
|
|
|
|
// TAB PLUGIN DEFINITION
|
|
// =====================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.tab')
|
|
|
|
if (!data) $this.data('bs.tab', (data = new Tab(this)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.tab
|
|
|
|
$.fn.tab = Plugin
|
|
$.fn.tab.Constructor = Tab
|
|
|
|
|
|
// TAB NO CONFLICT
|
|
// ===============
|
|
|
|
$.fn.tab.noConflict = function () {
|
|
$.fn.tab = old
|
|
return this
|
|
}
|
|
|
|
|
|
// TAB DATA-API
|
|
// ============
|
|
|
|
var clickHandler = function (e) {
|
|
e.preventDefault()
|
|
Plugin.call($(this), 'show')
|
|
}
|
|
|
|
$(document)
|
|
.on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler)
|
|
.on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler)
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: transition.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#transitions
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
|
|
// ============================================================
|
|
|
|
function transitionEnd() {
|
|
var el = document.createElement('bootstrap')
|
|
|
|
var transEndEventNames = {
|
|
WebkitTransition : 'webkitTransitionEnd',
|
|
MozTransition : 'transitionend',
|
|
OTransition : 'oTransitionEnd otransitionend',
|
|
transition : 'transitionend'
|
|
}
|
|
|
|
for (var name in transEndEventNames) {
|
|
if (el.style[name] !== undefined) {
|
|
return { end: transEndEventNames[name] }
|
|
}
|
|
}
|
|
|
|
return false // explicit for ie8 ( ._.)
|
|
}
|
|
|
|
// http://blog.alexmaccaw.com/css-transitions
|
|
$.fn.emulateTransitionEnd = function (duration) {
|
|
var called = false
|
|
var $el = this
|
|
$(this).one('bsTransitionEnd', function () { called = true })
|
|
var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
|
|
setTimeout(callback, duration)
|
|
return this
|
|
}
|
|
|
|
$(function () {
|
|
$.support.transition = transitionEnd()
|
|
|
|
if (!$.support.transition) return
|
|
|
|
$.event.special.bsTransitionEnd = {
|
|
bindType: $.support.transition.end,
|
|
delegateType: $.support.transition.end,
|
|
handle: function (e) {
|
|
if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments)
|
|
}
|
|
}
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Extends Bootstrap v3.1.1
|
|
|
|
* Copyright (c) <2014> eBay Software Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of eBay or any of its subsidiaries or affiliates nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* ======================================================================== */
|
|
|
|
|
|
(function($) {
|
|
"use strict";
|
|
|
|
// GENERAL UTILITY FUNCTIONS
|
|
// ===============================
|
|
|
|
var uniqueId = function(prefix) {
|
|
return (prefix || 'ui-id') + '-' + Math.floor((Math.random()*1000)+1)
|
|
}
|
|
|
|
|
|
var removeMultiValAttributes = function (el, attr, val) {
|
|
var describedby = (el.attr( attr ) || "").split( /\s+/ )
|
|
, index = $.inArray(val, describedby)
|
|
if ( index !== -1 ) {
|
|
describedby.splice( index, 1 )
|
|
}
|
|
describedby = $.trim( describedby.join( " " ) )
|
|
if (describedby ) {
|
|
el.attr( attr, describedby )
|
|
} else {
|
|
el.removeAttr( attr )
|
|
}
|
|
}
|
|
// Alert Extension
|
|
// ===============================
|
|
|
|
$('.alert').attr('role', 'alert')
|
|
$('.close').removeAttr('aria-hidden').wrapInner('<span aria-hidden="true"></span>').append('<span class="sr-only">Close</span>')
|
|
|
|
// TOOLTIP Extension
|
|
// ===============================
|
|
|
|
var showTooltip = $.fn.tooltip.Constructor.prototype.show
|
|
, hideTooltip = $.fn.tooltip.Constructor.prototype.hide
|
|
|
|
$.fn.tooltip.Constructor.prototype.show = function () {
|
|
showTooltip.apply(this, arguments)
|
|
var $tip = this.tip()
|
|
, tooltipID = $tip.attr('id') || uniqueId('ui-tooltip')
|
|
$tip.attr({'role':'tooltip','id' : tooltipID})
|
|
this.$element.attr('aria-describedby', tooltipID)
|
|
}
|
|
|
|
$.fn.tooltip.Constructor.prototype.hide = function () {
|
|
hideTooltip.apply(this, arguments)
|
|
removeMultiValAttributes(this.$element, 'aria-describedby', this.tip().attr('id'))
|
|
return this
|
|
}
|
|
// Popover Extension
|
|
// ===============================
|
|
|
|
var showPopover = $.fn.popover.Constructor.prototype.setContent
|
|
, hidePopover = $.fn.popover.Constructor.prototype.hide
|
|
|
|
$.fn.popover.Constructor.prototype.setContent = function(){
|
|
showPopover.apply(this, arguments)
|
|
var $tip = this.tip()
|
|
, tooltipID = $tip.attr('id') || uniqueId('ui-tooltip')
|
|
$tip.attr({'role':'alert','id' : tooltipID})
|
|
this.$element.attr('aria-describedby', tooltipID)
|
|
this.$element.focus()
|
|
}
|
|
$.fn.popover.Constructor.prototype.hide = function(){
|
|
hidePopover.apply(this, arguments)
|
|
removeMultiValAttributes(this.$element, 'aria-describedby', this.tip().attr('id'))
|
|
return this
|
|
}
|
|
|
|
// Modal Extension
|
|
// ===============================
|
|
|
|
$('.modal-dialog').attr( {'role' : 'document'})
|
|
var modalhide = $.fn.modal.Constructor.prototype.hide
|
|
$.fn.modal.Constructor.prototype.hide = function(){
|
|
var modalOpener = this.$element.parent().find('[data-target="#' + this.$element.attr('id') + '"]')
|
|
modalhide.apply(this, arguments)
|
|
modalOpener.focus()
|
|
}
|
|
// DROPDOWN Extension
|
|
// ===============================
|
|
|
|
var toggle = '[data-toggle=dropdown]'
|
|
, $par
|
|
, firstItem
|
|
, focusDelay = 200
|
|
, menus = $(toggle).parent().find('ul').attr('role','menu')
|
|
, lis = menus.find('li').attr('role','presentation')
|
|
|
|
lis.find('a').attr({'role':'menuitem', 'tabIndex':'-1'})
|
|
$(toggle).attr({ 'aria-haspopup':'true', 'aria-expanded': 'false'})
|
|
|
|
$(toggle).parent().on('shown.bs.dropdown',function(e){
|
|
$par = $(this)
|
|
var $toggle = $par.find(toggle)
|
|
$toggle.attr('aria-expanded','true')
|
|
|
|
// setTimeout(function(){
|
|
// firstItem = $('.dropdown-menu [role=menuitem]:visible', $par)[0]
|
|
// try{ firstItem.focus()} catch(ex) {}
|
|
// }, focusDelay)
|
|
})
|
|
|
|
$(toggle).parent().on('hidden.bs.dropdown',function(e){
|
|
$par = $(this)
|
|
var $toggle = $par.find(toggle)
|
|
$toggle.attr('aria-expanded','false')
|
|
})
|
|
|
|
//Adding Space Key Behaviour, opens on spacebar
|
|
$.fn.dropdown.Constructor.prototype.keydown = function (e) {
|
|
var $par
|
|
, firstItem
|
|
if (!/(32)/.test(e.keyCode)) return
|
|
$par = $(this).parent()
|
|
$(this).trigger ("click")
|
|
e.preventDefault() && e.stopPropagation()
|
|
}
|
|
|
|
// $(document)
|
|
// .on('focusout.dropdown.data-api', '.dropdown-menu', function(e){
|
|
// var $this = $(this)
|
|
// , that = this
|
|
// setTimeout(function() {
|
|
// if(!$.contains(that, document.activeElement)){
|
|
// $this.parent().removeClass('open')
|
|
// $this.parent().find('[data-toggle=dropdown]').attr('aria-expanded','false')
|
|
// }
|
|
// }, 150)
|
|
// })
|
|
// .on('keydown.bs.dropdown.data-api', toggle + ', [role=menu]' , $.fn.dropdown.Constructor.prototype.keydown)
|
|
// Tab Extension
|
|
// ===============================
|
|
|
|
var $tablist = $('.nav-tabs, .nav-pills')
|
|
, $lis = $tablist.children('li')
|
|
, $tabs = $tablist.find('[data-toggle="tab"], [data-toggle="pill"]')
|
|
|
|
$tablist.attr('role', 'tablist')
|
|
$lis.attr('role', 'presentation')
|
|
$tabs.attr('role', 'tab')
|
|
|
|
$tabs.each(function( index ) {
|
|
var tabpanel = $($(this).attr('href'))
|
|
, tab = $(this)
|
|
, tabid = tab.attr('id') || uniqueId('ui-tab')
|
|
|
|
tab.attr('id', tabid)
|
|
|
|
if(tab.parent().hasClass('active')){
|
|
tab.attr( { 'tabIndex' : '0', 'aria-selected' : 'true', 'aria-controls': tab.attr('href').substr(1) } )
|
|
tabpanel.attr({ 'role' : 'tabpanel', 'aria-hidden' : 'false', 'aria-labelledby': tabid })
|
|
}else{
|
|
tab.attr( { 'tabIndex' : '-1', 'aria-selected' : 'false', 'aria-controls': tab.attr('href').substr(1) } )
|
|
tabpanel.attr( { 'role' : 'tabpanel', 'aria-hidden' : 'true', 'aria-labelledby': tabid } )
|
|
}
|
|
})
|
|
|
|
$.fn.tab.Constructor.prototype.keydown = function (e) {
|
|
var $this = $(this)
|
|
, $items
|
|
, $ul = $this.closest('ul[role=tablist] ')
|
|
, index
|
|
, k = e.which || e.keyCode
|
|
|
|
$this = $(this)
|
|
if (!/(37|38|39|40)/.test(k)) return
|
|
|
|
$items = $ul.find('[role=tab]:visible')
|
|
index = $items.index($items.filter(':focus'))
|
|
|
|
if (k == 38 || k == 37) index-- // up & left
|
|
if (k == 39 || k == 40) index++ // down & right
|
|
|
|
|
|
if(index < 0) index = $items.length -1
|
|
if(index == $items.length) index = 0
|
|
|
|
var nextTab = $items.eq(index)
|
|
if(nextTab.attr('role') ==='tab'){
|
|
|
|
nextTab//.tab('show') //Comment this line for dynamically loaded tabPabels, to save Ajax requests on arrow key navigation
|
|
.focus()
|
|
}
|
|
// nextTab.focus()
|
|
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
}
|
|
|
|
$(document).on('keydown.tab.data-api','[data-toggle="tab"], [data-toggle="pill"]' , $.fn.tab.Constructor.prototype.keydown)
|
|
|
|
var tabactivate = $.fn.tab.Constructor.prototype.activate;
|
|
$.fn.tab.Constructor.prototype.activate = function (element, container, callback) {
|
|
var $active = container.find('> .active')
|
|
$active.find('[data-toggle=tab], [data-toggle=pill]').attr({ 'tabIndex' : '-1','aria-selected' : false })
|
|
$active.filter('.tab-pane').attr({ 'aria-hidden': true })
|
|
|
|
tabactivate.apply(this, arguments)
|
|
|
|
element.addClass('active')
|
|
element.find('[data-toggle=tab], [data-toggle=pill]').attr({ 'tabIndex' : '0','aria-selected' : true })
|
|
element.filter('.tab-pane').attr({ 'aria-hidden': false })
|
|
}
|
|
|
|
|
|
// Collapse Extension
|
|
// ===============================
|
|
|
|
var $colltabs = $('[data-toggle="collapse"]')
|
|
$colltabs.attr({ 'role':'tab', 'aria-selected':'false', 'aria-expanded':'false' })
|
|
$colltabs.each(function( index ) {
|
|
var colltab = $(this)
|
|
, collpanel = (colltab.attr('data-target')) ? $(colltab.attr('data-target')) : $(colltab.attr('href'))
|
|
, parent = colltab.attr('data-parent')
|
|
, collparent = parent && $(parent)
|
|
, collid = colltab.attr('id') || uniqueId('ui-collapse')
|
|
|
|
$(collparent).find('div:not(.collapse,.panel-body), h4').attr('role','presentation')
|
|
|
|
colltab.attr('id', collid)
|
|
if(collparent){
|
|
collparent.attr({ 'role' : 'tablist', 'aria-multiselectable' : 'true' })
|
|
if(collpanel.hasClass('in')){
|
|
colltab.attr({ 'aria-controls': colltab.attr('href').substr(1), 'aria-selected':'true', 'aria-expanded':'true', 'tabindex':'0' })
|
|
collpanel.attr({ 'role':'tabpanel', 'tabindex':'0', 'aria-labelledby':collid, 'aria-hidden':'false' })
|
|
}else{
|
|
colltab.attr({'aria-controls' : colltab.attr('href').substr(1), 'tabindex':'-1' })
|
|
collpanel.attr({ 'role':'tabpanel', 'tabindex':'-1', 'aria-labelledby':collid, 'aria-hidden':'true' })
|
|
}
|
|
}
|
|
})
|
|
|
|
var collToggle = $.fn.collapse.Constructor.prototype.toggle
|
|
$.fn.collapse.Constructor.prototype.toggle = function(){
|
|
var prevTab = this.$parent && this.$parent.find('[aria-expanded="true"]') , href
|
|
|
|
if(prevTab){
|
|
var prevPanel = prevTab.attr('data-target') || (href = prevTab.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')
|
|
, $prevPanel = $(prevPanel)
|
|
, $curPanel = this.$element
|
|
, par = this.$parent
|
|
, curTab
|
|
|
|
if (this.$parent) curTab = this.$parent.find('[data-toggle=collapse][href="#' + this.$element.attr('id') + '"]')
|
|
|
|
collToggle.apply(this, arguments)
|
|
|
|
if ($.support.transition) {
|
|
this.$element.one($.support.transition.end, function(){
|
|
|
|
prevTab.attr({ 'aria-selected':'false','aria-expanded':'false', 'tabIndex':'-1' })
|
|
$prevPanel.attr({ 'aria-hidden' : 'true','tabIndex' : '-1'})
|
|
|
|
curTab.attr({ 'aria-selected':'true','aria-expanded':'true', 'tabIndex':'0' })
|
|
|
|
if($curPanel.hasClass('in')){
|
|
$curPanel.attr({ 'aria-hidden' : 'false','tabIndex' : '0' })
|
|
}else{
|
|
curTab.attr({ 'aria-selected':'false','aria-expanded':'false'})
|
|
$curPanel.attr({ 'aria-hidden' : 'true','tabIndex' : '-1' })
|
|
}
|
|
})
|
|
}
|
|
}else{
|
|
collToggle.apply(this, arguments)
|
|
}
|
|
}
|
|
|
|
$.fn.collapse.Constructor.prototype.keydown = function (e) {
|
|
var $this = $(this)
|
|
, $items
|
|
, $tablist = $this.closest('div[role=tablist] ')
|
|
, index
|
|
, k = e.which || e.keyCode
|
|
|
|
$this = $(this)
|
|
if (!/(32|37|38|39|40)/.test(k)) return
|
|
if(k==32) $this.click()
|
|
|
|
$items = $tablist.find('[role=tab]')
|
|
index = $items.index($items.filter(':focus'))
|
|
|
|
if (k == 38 || k == 37) index-- // up & left
|
|
if (k == 39 || k == 40) index++ // down & right
|
|
if(index < 0) index = $items.length -1
|
|
if(index == $items.length) index = 0
|
|
|
|
$items.eq(index).focus()
|
|
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
|
|
}
|
|
|
|
$(document).on('keydown.collapse.data-api','[data-toggle="collapse"]' , $.fn.collapse.Constructor.prototype.keydown)
|
|
|
|
// Carousel Extension
|
|
// ===============================
|
|
|
|
$('.carousel').each(function (index) {
|
|
var $this = $(this)
|
|
, prev = $this.find('[data-slide="prev"]')
|
|
, next = $this.find('[data-slide="next"]')
|
|
, $options = $this.find('.item')
|
|
, $listbox = $options.parent()
|
|
|
|
$this.attr( { 'data-interval' : 'false', 'data-wrap' : 'false' } )
|
|
$listbox.attr('role', 'listbox')
|
|
$options.attr('role', 'option')
|
|
|
|
var spanPrev = document.createElement('span')
|
|
spanPrev.setAttribute('class', 'sr-only')
|
|
spanPrev.innerHTML='Previous'
|
|
|
|
var spanNext = document.createElement('span')
|
|
spanNext.setAttribute('class', 'sr-only')
|
|
spanNext.innerHTML='Next'
|
|
|
|
prev.attr('role', 'button')
|
|
next.attr('role', 'button')
|
|
|
|
prev.append(spanPrev)
|
|
next.append(spanNext)
|
|
|
|
$options.each(function () {
|
|
var item = $(this)
|
|
if(item.hasClass('active')){
|
|
item.attr({ 'aria-selected': 'true', 'tabindex' : '0' })
|
|
}else{
|
|
item.attr({ 'aria-selected': 'false', 'tabindex' : '-1' })
|
|
}
|
|
})
|
|
})
|
|
|
|
var slideCarousel = $.fn.carousel.Constructor.prototype.slide
|
|
$.fn.carousel.Constructor.prototype.slide = function (type, next) {
|
|
var $active = this.$element.find('.item.active')
|
|
, $next = next || $active[type]()
|
|
|
|
slideCarousel.apply(this, arguments)
|
|
|
|
$active
|
|
.one($.support.transition.end, function () {
|
|
$active.attr({'aria-selected':false, 'tabIndex': '-1'})
|
|
$next.attr({'aria-selected':true, 'tabIndex': '0'})
|
|
//.focus()
|
|
})
|
|
}
|
|
|
|
$.fn.carousel.Constructor.prototype.keydown = function (e) {
|
|
var $this = $(this)
|
|
, $ul = $this.closest('div[role=listbox]')
|
|
, $items = $ul.find('[role=option]')
|
|
, $parent = $ul.parent()
|
|
, k = e.which || e.keyCode
|
|
, index
|
|
, i
|
|
|
|
if (!/(37|38|39|40)/.test(k)) return
|
|
|
|
index = $items.index($items.filter('.active'))
|
|
if (k == 37 || k == 38) { // Up
|
|
$parent.carousel('prev')
|
|
index--
|
|
if(index < 0) index = $items.length -1
|
|
else $this.prev().focus()
|
|
|
|
}
|
|
if (k == 39 || k == 40) { // Down
|
|
$parent.carousel('next')
|
|
index++
|
|
if(index == $items.length) index = 0
|
|
else {
|
|
$this.one($.support.transition.end, function () {
|
|
$this.next().focus()
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
}
|
|
$(document).on('keydown.carousel.data-api', 'div[role=option]', $.fn.carousel.Constructor.prototype.keydown)
|
|
|
|
})(jQuery);
|
|
(function(factory) {
|
|
if (typeof define === 'function' && define.amd) {
|
|
define(['jquery'], factory);
|
|
} else if (typeof module === 'object' && typeof module.exports === 'object') {
|
|
module.exports = factory(require('jquery'));
|
|
} else {
|
|
factory(jQuery);
|
|
}
|
|
}(function(jQuery) {
|
|
|
|
/*! TableSorter (FORK) v2.29.0 *//*
|
|
* Client-side table sorting with ease!
|
|
* @requires jQuery v1.2.6+
|
|
*
|
|
* Copyright (c) 2007 Christian Bach
|
|
* fork maintained by Rob Garrison
|
|
*
|
|
* Examples and original docs at: http://tablesorter.com
|
|
* Dual licensed under the MIT and GPL licenses:
|
|
* http://www.opensource.org/licenses/mit-license.php
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
*
|
|
* @type jQuery
|
|
* @name tablesorter (FORK)
|
|
* @cat Plugins/Tablesorter
|
|
* @author Christian Bach - christian.bach@polyester.se
|
|
* @contributor Rob Garrison - https://github.com/Mottie/tablesorter
|
|
* @docs (fork) - https://mottie.github.io/tablesorter/docs/
|
|
*/
|
|
/*jshint browser:true, jquery:true, unused:false, expr: true */
|
|
;( function( $ ) {
|
|
'use strict';
|
|
var ts = $.tablesorter = {
|
|
|
|
version : '2.29.0',
|
|
|
|
parsers : [],
|
|
widgets : [],
|
|
defaults : {
|
|
|
|
// *** appearance
|
|
theme : 'default', // adds tablesorter-{theme} to the table for styling
|
|
widthFixed : false, // adds colgroup to fix widths of columns
|
|
showProcessing : false, // show an indeterminate timer icon in the header when the table is sorted or filtered.
|
|
|
|
headerTemplate : '{content}',// header layout template (HTML ok); {content} = innerHTML, {icon} = <i/> // class from cssIcon
|
|
onRenderTemplate : null, // function( index, template ){ return template; }, // template is a string
|
|
onRenderHeader : null, // function( index ){}, // nothing to return
|
|
|
|
// *** functionality
|
|
cancelSelection : true, // prevent text selection in the header
|
|
tabIndex : true, // add tabindex to header for keyboard accessibility
|
|
dateFormat : 'mmddyyyy', // other options: 'ddmmyyy' or 'yyyymmdd'
|
|
sortMultiSortKey : 'shiftKey', // key used to select additional columns
|
|
sortResetKey : 'ctrlKey', // key used to remove sorting on a column
|
|
usNumberFormat : true, // false for German '1.234.567,89' or French '1 234 567,89'
|
|
delayInit : false, // if false, the parsed table contents will not update until the first sort
|
|
serverSideSorting: false, // if true, server-side sorting should be performed because client-side sorting will be disabled, but the ui and events will still be used.
|
|
resort : true, // default setting to trigger a resort after an 'update', 'addRows', 'updateCell', etc has completed
|
|
|
|
// *** sort options
|
|
headers : {}, // set sorter, string, empty, locked order, sortInitialOrder, filter, etc.
|
|
ignoreCase : true, // ignore case while sorting
|
|
sortForce : null, // column(s) first sorted; always applied
|
|
sortList : [], // Initial sort order; applied initially; updated when manually sorted
|
|
sortAppend : null, // column(s) sorted last; always applied
|
|
sortStable : false, // when sorting two rows with exactly the same content, the original sort order is maintained
|
|
|
|
sortInitialOrder : 'asc', // sort direction on first click
|
|
sortLocaleCompare: false, // replace equivalent character (accented characters)
|
|
sortReset : false, // third click on the header will reset column to default - unsorted
|
|
sortRestart : false, // restart sort to 'sortInitialOrder' when clicking on previously unsorted columns
|
|
|
|
emptyTo : 'bottom', // sort empty cell to bottom, top, none, zero, emptyMax, emptyMin
|
|
stringTo : 'max', // sort strings in numerical column as max, min, top, bottom, zero
|
|
duplicateSpan : true, // colspan cells in the tbody will have duplicated content in the cache for each spanned column
|
|
textExtraction : 'basic', // text extraction method/function - function( node, table, cellIndex ){}
|
|
textAttribute : 'data-text',// data-attribute that contains alternate cell text (used in default textExtraction function)
|
|
textSorter : null, // choose overall or specific column sorter function( a, b, direction, table, columnIndex ) [alt: ts.sortText]
|
|
numberSorter : null, // choose overall numeric sorter function( a, b, direction, maxColumnValue )
|
|
|
|
// *** widget options
|
|
initWidgets : true, // apply widgets on tablesorter initialization
|
|
widgetClass : 'widget-{name}', // table class name template to match to include a widget
|
|
widgets : [], // method to add widgets, e.g. widgets: ['zebra']
|
|
widgetOptions : {
|
|
zebra : [ 'even', 'odd' ] // zebra widget alternating row class names
|
|
},
|
|
|
|
// *** callbacks
|
|
initialized : null, // function( table ){},
|
|
|
|
// *** extra css class names
|
|
tableClass : '',
|
|
cssAsc : '',
|
|
cssDesc : '',
|
|
cssNone : '',
|
|
cssHeader : '',
|
|
cssHeaderRow : '',
|
|
cssProcessing : '', // processing icon applied to header during sort/filter
|
|
|
|
cssChildRow : 'tablesorter-childRow', // class name indiciating that a row is to be attached to its parent
|
|
cssInfoBlock : 'tablesorter-infoOnly', // don't sort tbody with this class name (only one class name allowed here!)
|
|
cssNoSort : 'tablesorter-noSort', // class name added to element inside header; clicking on it won't cause a sort
|
|
cssIgnoreRow : 'tablesorter-ignoreRow',// header row to ignore; cells within this row will not be added to c.$headers
|
|
|
|
cssIcon : 'tablesorter-icon', // if this class does not exist, the {icon} will not be added from the headerTemplate
|
|
cssIconNone : '', // class name added to the icon when there is no column sort
|
|
cssIconAsc : '', // class name added to the icon when the column has an ascending sort
|
|
cssIconDesc : '', // class name added to the icon when the column has a descending sort
|
|
cssIconDisabled : '', // class name added to the icon when the column has a disabled sort
|
|
|
|
// *** events
|
|
pointerClick : 'click',
|
|
pointerDown : 'mousedown',
|
|
pointerUp : 'mouseup',
|
|
|
|
// *** selectors
|
|
selectorHeaders : '> thead th, > thead td',
|
|
selectorSort : 'th, td', // jQuery selector of content within selectorHeaders that is clickable to trigger a sort
|
|
selectorRemove : '.remove-me',
|
|
|
|
// *** advanced
|
|
debug : false,
|
|
|
|
// *** Internal variables
|
|
headerList: [],
|
|
empties: {},
|
|
strings: {},
|
|
parsers: [],
|
|
|
|
// *** parser options for validator; values must be falsy!
|
|
globalize: 0,
|
|
imgAttr: 0
|
|
|
|
// removed: widgetZebra: { css: ['even', 'odd'] }
|
|
|
|
},
|
|
|
|
// internal css classes - these will ALWAYS be added to
|
|
// the table and MUST only contain one class name - fixes #381
|
|
css : {
|
|
table : 'tablesorter',
|
|
cssHasChild: 'tablesorter-hasChildRow',
|
|
childRow : 'tablesorter-childRow',
|
|
colgroup : 'tablesorter-colgroup',
|
|
header : 'tablesorter-header',
|
|
headerRow : 'tablesorter-headerRow',
|
|
headerIn : 'tablesorter-header-inner',
|
|
icon : 'tablesorter-icon',
|
|
processing : 'tablesorter-processing',
|
|
sortAsc : 'tablesorter-headerAsc',
|
|
sortDesc : 'tablesorter-headerDesc',
|
|
sortNone : 'tablesorter-headerUnSorted'
|
|
},
|
|
|
|
// labels applied to sortable headers for accessibility (aria) support
|
|
language : {
|
|
sortAsc : 'Ascending sort applied, ',
|
|
sortDesc : 'Descending sort applied, ',
|
|
sortNone : 'No sort applied, ',
|
|
sortDisabled : 'sorting is disabled',
|
|
nextAsc : 'activate to apply an ascending sort',
|
|
nextDesc : 'activate to apply a descending sort',
|
|
nextNone : 'activate to remove the sort'
|
|
},
|
|
|
|
regex : {
|
|
templateContent : /\{content\}/g,
|
|
templateIcon : /\{icon\}/g,
|
|
templateName : /\{name\}/i,
|
|
spaces : /\s+/g,
|
|
nonWord : /\W/g,
|
|
formElements : /(input|select|button|textarea)/i,
|
|
|
|
// *** sort functions ***
|
|
// regex used in natural sort
|
|
// chunk/tokenize numbers & letters
|
|
chunk : /(^([+\-]?(?:\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi,
|
|
// replace chunks @ ends
|
|
chunks : /(^\\0|\\0$)/,
|
|
hex : /^0x[0-9a-f]+$/i,
|
|
|
|
// *** formatFloat ***
|
|
comma : /,/g,
|
|
digitNonUS : /[\s|\.]/g,
|
|
digitNegativeTest : /^\s*\([.\d]+\)/,
|
|
digitNegativeReplace : /^\s*\(([.\d]+)\)/,
|
|
|
|
// *** isDigit ***
|
|
digitTest : /^[\-+(]?\d+[)]?$/,
|
|
digitReplace : /[,.'"\s]/g
|
|
|
|
},
|
|
|
|
// digit sort, text location
|
|
string : {
|
|
max : 1,
|
|
min : -1,
|
|
emptymin : 1,
|
|
emptymax : -1,
|
|
zero : 0,
|
|
none : 0,
|
|
'null' : 0,
|
|
top : true,
|
|
bottom : false
|
|
},
|
|
|
|
keyCodes : {
|
|
enter : 13
|
|
},
|
|
|
|
// placeholder date parser data (globalize)
|
|
dates : {},
|
|
|
|
// These methods can be applied on table.config instance
|
|
instanceMethods : {},
|
|
|
|
/*
|
|
▄█████ ██████ ██████ ██ ██ █████▄
|
|
▀█▄ ██▄▄ ██ ██ ██ ██▄▄██
|
|
▀█▄ ██▀▀ ██ ██ ██ ██▀▀▀
|
|
█████▀ ██████ ██ ▀████▀ ██
|
|
*/
|
|
|
|
setup : function( table, c ) {
|
|
// if no thead or tbody, or tablesorter is already present, quit
|
|
if ( !table || !table.tHead || table.tBodies.length === 0 || table.hasInitialized === true ) {
|
|
if ( c.debug ) {
|
|
if ( table.hasInitialized ) {
|
|
console.warn( 'Stopping initialization. Tablesorter has already been initialized' );
|
|
} else {
|
|
console.error( 'Stopping initialization! No table, thead or tbody', table );
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
var tmp = '',
|
|
$table = $( table ),
|
|
meta = $.metadata;
|
|
// initialization flag
|
|
table.hasInitialized = false;
|
|
// table is being processed flag
|
|
table.isProcessing = true;
|
|
// make sure to store the config object
|
|
table.config = c;
|
|
// save the settings where they read
|
|
$.data( table, 'tablesorter', c );
|
|
if ( c.debug ) {
|
|
console[ console.group ? 'group' : 'log' ]( 'Initializing tablesorter v' + ts.version );
|
|
$.data( table, 'startoveralltimer', new Date() );
|
|
}
|
|
|
|
// removing this in version 3 (only supports jQuery 1.7+)
|
|
c.supportsDataObject = ( function( version ) {
|
|
version[ 0 ] = parseInt( version[ 0 ], 10 );
|
|
return ( version[ 0 ] > 1 ) || ( version[ 0 ] === 1 && parseInt( version[ 1 ], 10 ) >= 4 );
|
|
})( $.fn.jquery.split( '.' ) );
|
|
// ensure case insensitivity
|
|
c.emptyTo = c.emptyTo.toLowerCase();
|
|
c.stringTo = c.stringTo.toLowerCase();
|
|
c.last = { sortList : [], clickedIndex : -1 };
|
|
// add table theme class only if there isn't already one there
|
|
if ( !/tablesorter\-/.test( $table.attr( 'class' ) ) ) {
|
|
tmp = ( c.theme !== '' ? ' tablesorter-' + c.theme : '' );
|
|
}
|
|
|
|
// give the table a unique id, which will be used in namespace binding
|
|
if ( !c.namespace ) {
|
|
c.namespace = '.tablesorter' + Math.random().toString( 16 ).slice( 2 );
|
|
} else {
|
|
// make sure namespace starts with a period & doesn't have weird characters
|
|
c.namespace = '.' + c.namespace.replace( ts.regex.nonWord, '' );
|
|
}
|
|
|
|
c.table = table;
|
|
c.$table = $table
|
|
// add namespace to table to allow bindings on extra elements to target
|
|
// the parent table (e.g. parser-input-select)
|
|
.addClass( ts.css.table + ' ' + c.tableClass + tmp + ' ' + c.namespace.slice(1) )
|
|
.attr( 'role', 'grid' );
|
|
c.$headers = $table.find( c.selectorHeaders );
|
|
|
|
c.$table.children().children( 'tr' ).attr( 'role', 'row' );
|
|
c.$tbodies = $table.children( 'tbody:not(.' + c.cssInfoBlock + ')' ).attr({
|
|
'aria-live' : 'polite',
|
|
'aria-relevant' : 'all'
|
|
});
|
|
if ( c.$table.children( 'caption' ).length ) {
|
|
tmp = c.$table.children( 'caption' )[ 0 ];
|
|
if ( !tmp.id ) { tmp.id = c.namespace.slice( 1 ) + 'caption'; }
|
|
c.$table.attr( 'aria-labelledby', tmp.id );
|
|
}
|
|
c.widgetInit = {}; // keep a list of initialized widgets
|
|
// change textExtraction via data-attribute
|
|
c.textExtraction = c.$table.attr( 'data-text-extraction' ) || c.textExtraction || 'basic';
|
|
// build headers
|
|
ts.buildHeaders( c );
|
|
// fixate columns if the users supplies the fixedWidth option
|
|
// do this after theme has been applied
|
|
ts.fixColumnWidth( table );
|
|
// add widgets from class name
|
|
ts.addWidgetFromClass( table );
|
|
// add widget options before parsing (e.g. grouping widget has parser settings)
|
|
ts.applyWidgetOptions( table );
|
|
// try to auto detect column type, and store in tables config
|
|
ts.setupParsers( c );
|
|
// start total row count at zero
|
|
c.totalRows = 0;
|
|
ts.validateOptions( c );
|
|
// build the cache for the tbody cells
|
|
// delayInit will delay building the cache until the user starts a sort
|
|
if ( !c.delayInit ) { ts.buildCache( c ); }
|
|
// bind all header events and methods
|
|
ts.bindEvents( table, c.$headers, true );
|
|
ts.bindMethods( c );
|
|
// get sort list from jQuery data or metadata
|
|
// in jQuery < 1.4, an error occurs when calling $table.data()
|
|
if ( c.supportsDataObject && typeof $table.data().sortlist !== 'undefined' ) {
|
|
c.sortList = $table.data().sortlist;
|
|
} else if ( meta && ( $table.metadata() && $table.metadata().sortlist ) ) {
|
|
c.sortList = $table.metadata().sortlist;
|
|
}
|
|
// apply widget init code
|
|
ts.applyWidget( table, true );
|
|
// if user has supplied a sort list to constructor
|
|
if ( c.sortList.length > 0 ) {
|
|
ts.sortOn( c, c.sortList, {}, !c.initWidgets );
|
|
} else {
|
|
ts.setHeadersCss( c );
|
|
if ( c.initWidgets ) {
|
|
// apply widget format
|
|
ts.applyWidget( table, false );
|
|
}
|
|
}
|
|
|
|
// show processesing icon
|
|
if ( c.showProcessing ) {
|
|
$table
|
|
.unbind( 'sortBegin' + c.namespace + ' sortEnd' + c.namespace )
|
|
.bind( 'sortBegin' + c.namespace + ' sortEnd' + c.namespace, function( e ) {
|
|
clearTimeout( c.timerProcessing );
|
|
ts.isProcessing( table );
|
|
if ( e.type === 'sortBegin' ) {
|
|
c.timerProcessing = setTimeout( function() {
|
|
ts.isProcessing( table, true );
|
|
}, 500 );
|
|
}
|
|
});
|
|
}
|
|
|
|
// initialized
|
|
table.hasInitialized = true;
|
|
table.isProcessing = false;
|
|
if ( c.debug ) {
|
|
console.log( 'Overall initialization time:' + ts.benchmark( $.data( table, 'startoveralltimer' ) ) );
|
|
if ( c.debug && console.groupEnd ) { console.groupEnd(); }
|
|
}
|
|
$table.triggerHandler( 'tablesorter-initialized', table );
|
|
if ( typeof c.initialized === 'function' ) {
|
|
c.initialized( table );
|
|
}
|
|
},
|
|
|
|
bindMethods : function( c ) {
|
|
var $table = c.$table,
|
|
namespace = c.namespace,
|
|
events = ( 'sortReset update updateRows updateAll updateHeaders addRows updateCell updateComplete ' +
|
|
'sorton appendCache updateCache applyWidgetId applyWidgets refreshWidgets destroy mouseup ' +
|
|
'mouseleave ' ).split( ' ' )
|
|
.join( namespace + ' ' );
|
|
// apply easy methods that trigger bound events
|
|
$table
|
|
.unbind( events.replace( ts.regex.spaces, ' ' ) )
|
|
.bind( 'sortReset' + namespace, function( e, callback ) {
|
|
e.stopPropagation();
|
|
// using this.config to ensure functions are getting a non-cached version of the config
|
|
ts.sortReset( this.config, function( table ) {
|
|
if (table.isApplyingWidgets) {
|
|
// multiple triggers in a row... filterReset, then sortReset - see #1361
|
|
// wait to update widgets
|
|
setTimeout( function() {
|
|
ts.applyWidget( table, '', callback );
|
|
}, 100 );
|
|
} else {
|
|
ts.applyWidget( table, '', callback );
|
|
}
|
|
});
|
|
})
|
|
.bind( 'updateAll' + namespace, function( e, resort, callback ) {
|
|
e.stopPropagation();
|
|
ts.updateAll( this.config, resort, callback );
|
|
})
|
|
.bind( 'update' + namespace + ' updateRows' + namespace, function( e, resort, callback ) {
|
|
e.stopPropagation();
|
|
ts.update( this.config, resort, callback );
|
|
})
|
|
.bind( 'updateHeaders' + namespace, function( e, callback ) {
|
|
e.stopPropagation();
|
|
ts.updateHeaders( this.config, callback );
|
|
})
|
|
.bind( 'updateCell' + namespace, function( e, cell, resort, callback ) {
|
|
e.stopPropagation();
|
|
ts.updateCell( this.config, cell, resort, callback );
|
|
})
|
|
.bind( 'addRows' + namespace, function( e, $row, resort, callback ) {
|
|
e.stopPropagation();
|
|
ts.addRows( this.config, $row, resort, callback );
|
|
})
|
|
.bind( 'updateComplete' + namespace, function() {
|
|
this.isUpdating = false;
|
|
})
|
|
.bind( 'sorton' + namespace, function( e, list, callback, init ) {
|
|
e.stopPropagation();
|
|
ts.sortOn( this.config, list, callback, init );
|
|
})
|
|
.bind( 'appendCache' + namespace, function( e, callback, init ) {
|
|
e.stopPropagation();
|
|
ts.appendCache( this.config, init );
|
|
if ( $.isFunction( callback ) ) {
|
|
callback( this );
|
|
}
|
|
})
|
|
// $tbodies variable is used by the tbody sorting widget
|
|
.bind( 'updateCache' + namespace, function( e, callback, $tbodies ) {
|
|
e.stopPropagation();
|
|
ts.updateCache( this.config, callback, $tbodies );
|
|
})
|
|
.bind( 'applyWidgetId' + namespace, function( e, id ) {
|
|
e.stopPropagation();
|
|
ts.applyWidgetId( this, id );
|
|
})
|
|
.bind( 'applyWidgets' + namespace, function( e, callback ) {
|
|
e.stopPropagation();
|
|
// apply widgets (false = not initializing)
|
|
ts.applyWidget( this, false, callback );
|
|
})
|
|
.bind( 'refreshWidgets' + namespace, function( e, all, dontapply ) {
|
|
e.stopPropagation();
|
|
ts.refreshWidgets( this, all, dontapply );
|
|
})
|
|
.bind( 'removeWidget' + namespace, function( e, name, refreshing ) {
|
|
e.stopPropagation();
|
|
ts.removeWidget( this, name, refreshing );
|
|
})
|
|
.bind( 'destroy' + namespace, function( e, removeClasses, callback ) {
|
|
e.stopPropagation();
|
|
ts.destroy( this, removeClasses, callback );
|
|
})
|
|
.bind( 'resetToLoadState' + namespace, function( e ) {
|
|
e.stopPropagation();
|
|
// remove all widgets
|
|
ts.removeWidget( this, true, false );
|
|
var tmp = $.extend( true, {}, c.originalSettings );
|
|
// restore original settings; this clears out current settings, but does not clear
|
|
// values saved to storage.
|
|
c = $.extend( true, {}, ts.defaults, tmp );
|
|
c.originalSettings = tmp;
|
|
this.hasInitialized = false;
|
|
// setup the entire table again
|
|
ts.setup( this, c );
|
|
});
|
|
},
|
|
|
|
bindEvents : function( table, $headers, core ) {
|
|
table = $( table )[ 0 ];
|
|
var tmp,
|
|
c = table.config,
|
|
namespace = c.namespace,
|
|
downTarget = null;
|
|
if ( core !== true ) {
|
|
$headers.addClass( namespace.slice( 1 ) + '_extra_headers' );
|
|
tmp = ts.getClosest( $headers, 'table' );
|
|
if ( tmp.length && tmp[ 0 ].nodeName === 'TABLE' && tmp[ 0 ] !== table ) {
|
|
$( tmp[ 0 ] ).addClass( namespace.slice( 1 ) + '_extra_table' );
|
|
}
|
|
}
|
|
tmp = ( c.pointerDown + ' ' + c.pointerUp + ' ' + c.pointerClick + ' sort keyup ' )
|
|
.replace( ts.regex.spaces, ' ' )
|
|
.split( ' ' )
|
|
.join( namespace + ' ' );
|
|
// apply event handling to headers and/or additional headers (stickyheaders, scroller, etc)
|
|
$headers
|
|
// http://stackoverflow.com/questions/5312849/jquery-find-self;
|
|
.find( c.selectorSort )
|
|
.add( $headers.filter( c.selectorSort ) )
|
|
.unbind( tmp )
|
|
.bind( tmp, function( e, external ) {
|
|
var $cell, cell, temp,
|
|
$target = $( e.target ),
|
|
// wrap event type in spaces, so the match doesn't trigger on inner words
|
|
type = ' ' + e.type + ' ';
|
|
// only recognize left clicks
|
|
if ( ( ( e.which || e.button ) !== 1 && !type.match( ' ' + c.pointerClick + ' | sort | keyup ' ) ) ||
|
|
// allow pressing enter
|
|
( type === ' keyup ' && e.which !== ts.keyCodes.enter ) ||
|
|
// allow triggering a click event (e.which is undefined) & ignore physical clicks
|
|
( type.match( ' ' + c.pointerClick + ' ' ) && typeof e.which !== 'undefined' ) ) {
|
|
return;
|
|
}
|
|
// ignore mouseup if mousedown wasn't on the same target
|
|
if ( type.match( ' ' + c.pointerUp + ' ' ) && downTarget !== e.target && external !== true ) {
|
|
return;
|
|
}
|
|
// set target on mousedown
|
|
if ( type.match( ' ' + c.pointerDown + ' ' ) ) {
|
|
downTarget = e.target;
|
|
// preventDefault needed or jQuery v1.3.2 and older throws an
|
|
// "Uncaught TypeError: handler.apply is not a function" error
|
|
temp = $target.jquery.split( '.' );
|
|
if ( temp[ 0 ] === '1' && temp[ 1 ] < 4 ) { e.preventDefault(); }
|
|
return;
|
|
}
|
|
downTarget = null;
|
|
// prevent sort being triggered on form elements
|
|
if ( ts.regex.formElements.test( e.target.nodeName ) ||
|
|
// nosort class name, or elements within a nosort container
|
|
$target.hasClass( c.cssNoSort ) || $target.parents( '.' + c.cssNoSort ).length > 0 ||
|
|
// elements within a button
|
|
$target.parents( 'button' ).length > 0 ) {
|
|
return !c.cancelSelection;
|
|
}
|
|
if ( c.delayInit && ts.isEmptyObject( c.cache ) ) {
|
|
ts.buildCache( c );
|
|
}
|
|
// jQuery v1.2.6 doesn't have closest()
|
|
$cell = ts.getHeaderCell( $( this ) );
|
|
// reference original table headers and find the same cell
|
|
// don't use $headers or IE8 throws an error - see #987
|
|
temp = $headers.index( $cell );
|
|
c.last.clickedIndex = ( temp < 0 ) ? $cell.attr( 'data-column' ) : temp;
|
|
// use column index if $headers is undefined
|
|
cell = c.$headers[ c.last.clickedIndex ];
|
|
if ( cell && !cell.sortDisabled ) {
|
|
ts.initSort( c, cell, e );
|
|
}
|
|
});
|
|
if ( c.cancelSelection ) {
|
|
// cancel selection
|
|
$headers
|
|
.attr( 'unselectable', 'on' )
|
|
.bind( 'selectstart', false )
|
|
.css({
|
|
'user-select' : 'none',
|
|
'MozUserSelect' : 'none' // not needed for jQuery 1.8+
|
|
});
|
|
}
|
|
},
|
|
|
|
buildHeaders : function( c ) {
|
|
var $temp, icon, timer, indx;
|
|
c.headerList = [];
|
|
c.headerContent = [];
|
|
c.sortVars = [];
|
|
if ( c.debug ) {
|
|
timer = new Date();
|
|
}
|
|
// children tr in tfoot - see issue #196 & #547
|
|
// don't pass table.config to computeColumnIndex here - widgets (math) pass it to "quickly" index tbody cells
|
|
c.columns = ts.computeColumnIndex( c.$table.children( 'thead, tfoot' ).children( 'tr' ) );
|
|
// add icon if cssIcon option exists
|
|
icon = c.cssIcon ?
|
|
'<i class="' + ( c.cssIcon === ts.css.icon ? ts.css.icon : c.cssIcon + ' ' + ts.css.icon ) + '"></i>' :
|
|
'';
|
|
// redefine c.$headers here in case of an updateAll that replaces or adds an entire header cell - see #683
|
|
c.$headers = $( $.map( c.$table.find( c.selectorHeaders ), function( elem, index ) {
|
|
var configHeaders, header, column, template, tmp, $th,
|
|
$elem = $( elem );
|
|
// ignore cell (don't add it to c.$headers) if row has ignoreRow class
|
|
if ( $elem.parent().hasClass( c.cssIgnoreRow ) ) { return; }
|
|
// make sure to get header cell & not column indexed cell
|
|
configHeaders = ts.getColumnData( c.table, c.headers, index, true );
|
|
// save original header content
|
|
c.headerContent[ index ] = $elem.html();
|
|
// if headerTemplate is empty, don't reformat the header cell
|
|
if ( c.headerTemplate !== '' && !$elem.find( '.' + ts.css.headerIn ).length ) {
|
|
// set up header template
|
|
template = c.headerTemplate
|
|
.replace( ts.regex.templateContent, $elem.html() )
|
|
.replace( ts.regex.templateIcon, $elem.find( '.' + ts.css.icon ).length ? '' : icon );
|
|
if ( c.onRenderTemplate ) {
|
|
header = c.onRenderTemplate.apply( $elem, [ index, template ] );
|
|
// only change t if something is returned
|
|
if ( header && typeof header === 'string' ) {
|
|
template = header;
|
|
}
|
|
}
|
|
$elem.html( '<div class="' + ts.css.headerIn + '">' + template + '</div>' ); // faster than wrapInner
|
|
}
|
|
if ( c.onRenderHeader ) {
|
|
c.onRenderHeader.apply( $elem, [ index, c, c.$table ] );
|
|
}
|
|
// data-column stored on th or td only
|
|
$th = ts.getHeaderCell( $elem );
|
|
column = parseInt( $th.attr( 'data-column' ), 10 );
|
|
elem.column = column;
|
|
tmp = ts.getOrder( ts.getData( $elem, configHeaders, 'sortInitialOrder' ) || c.sortInitialOrder );
|
|
// this may get updated numerous times if there are multiple rows
|
|
c.sortVars[ column ] = {
|
|
count : -1, // set to -1 because clicking on the header automatically adds one
|
|
order: tmp ?
|
|
( c.sortReset ? [ 1, 0, 2 ] : [ 1, 0 ] ) : // desc, asc, unsorted
|
|
( c.sortReset ? [ 0, 1, 2 ] : [ 0, 1 ] ), // asc, desc, unsorted
|
|
lockedOrder : false
|
|
};
|
|
tmp = ts.getData( $elem, configHeaders, 'lockedOrder' ) || false;
|
|
if ( typeof tmp !== 'undefined' && tmp !== false ) {
|
|
c.sortVars[ column ].lockedOrder = true;
|
|
c.sortVars[ column ].order = ts.getOrder( tmp ) ? [ 1, 1 ] : [ 0, 0 ];
|
|
}
|
|
// add cell to headerList
|
|
c.headerList[ index ] = elem;
|
|
$elem.addClass( ts.css.header + ' ' + c.cssHeader );
|
|
// add to parent in case there are multiple rows
|
|
ts.getClosest( $elem, 'tr' )
|
|
.addClass( ts.css.headerRow + ' ' + c.cssHeaderRow )
|
|
.attr( 'role', 'row' );
|
|
// allow keyboard cursor to focus on element
|
|
if ( c.tabIndex ) {
|
|
$elem.attr( 'tabindex', 0 );
|
|
}
|
|
return elem;
|
|
}) );
|
|
// cache headers per column
|
|
c.$headerIndexed = [];
|
|
for ( indx = 0; indx < c.columns; indx++ ) {
|
|
// colspan in header making a column undefined
|
|
if ( ts.isEmptyObject( c.sortVars[ indx ] ) ) {
|
|
c.sortVars[ indx ] = {};
|
|
}
|
|
$temp = c.$headers.filter( '[data-column="' + indx + '"]' );
|
|
// target sortable column cells, unless there are none, then use non-sortable cells
|
|
// .last() added in jQuery 1.4; use .filter(':last') to maintain compatibility with jQuery v1.2.6
|
|
c.$headerIndexed[ indx ] = $temp.length ?
|
|
$temp.not( '.sorter-false' ).length ?
|
|
$temp.not( '.sorter-false' ).filter( ':last' ) :
|
|
$temp.filter( ':last' ) :
|
|
$();
|
|
}
|
|
c.$table.find( c.selectorHeaders ).attr({
|
|
scope: 'col',
|
|
role : 'columnheader'
|
|
});
|
|
// enable/disable sorting
|
|
ts.updateHeader( c );
|
|
if ( c.debug ) {
|
|
console.log( 'Built headers:' + ts.benchmark( timer ) );
|
|
console.log( c.$headers );
|
|
}
|
|
},
|
|
|
|
// Use it to add a set of methods to table.config which will be available for all tables.
|
|
// This should be done before table initialization
|
|
addInstanceMethods : function( methods ) {
|
|
$.extend( ts.instanceMethods, methods );
|
|
},
|
|
|
|
/*
|
|
█████▄ ▄████▄ █████▄ ▄█████ ██████ █████▄ ▄█████
|
|
██▄▄██ ██▄▄██ ██▄▄██ ▀█▄ ██▄▄ ██▄▄██ ▀█▄
|
|
██▀▀▀ ██▀▀██ ██▀██ ▀█▄ ██▀▀ ██▀██ ▀█▄
|
|
██ ██ ██ ██ ██ █████▀ ██████ ██ ██ █████▀
|
|
*/
|
|
setupParsers : function( c, $tbodies ) {
|
|
var rows, list, span, max, colIndex, indx, header, configHeaders,
|
|
noParser, parser, extractor, time, tbody, len,
|
|
table = c.table,
|
|
tbodyIndex = 0,
|
|
debug = {};
|
|
// update table bodies in case we start with an empty table
|
|
c.$tbodies = c.$table.children( 'tbody:not(.' + c.cssInfoBlock + ')' );
|
|
tbody = typeof $tbodies === 'undefined' ? c.$tbodies : $tbodies;
|
|
len = tbody.length;
|
|
if ( len === 0 ) {
|
|
return c.debug ? console.warn( 'Warning: *Empty table!* Not building a parser cache' ) : '';
|
|
} else if ( c.debug ) {
|
|
time = new Date();
|
|
console[ console.group ? 'group' : 'log' ]( 'Detecting parsers for each column' );
|
|
}
|
|
list = {
|
|
extractors: [],
|
|
parsers: []
|
|
};
|
|
while ( tbodyIndex < len ) {
|
|
rows = tbody[ tbodyIndex ].rows;
|
|
if ( rows.length ) {
|
|
colIndex = 0;
|
|
max = c.columns;
|
|
for ( indx = 0; indx < max; indx++ ) {
|
|
header = c.$headerIndexed[ colIndex ];
|
|
if ( header && header.length ) {
|
|
// get column indexed table cell; adding true parameter fixes #1362 but
|
|
// it would break backwards compatibility...
|
|
configHeaders = ts.getColumnData( table, c.headers, colIndex ); // , true );
|
|
// get column parser/extractor
|
|
extractor = ts.getParserById( ts.getData( header, configHeaders, 'extractor' ) );
|
|
parser = ts.getParserById( ts.getData( header, configHeaders, 'sorter' ) );
|
|
noParser = ts.getData( header, configHeaders, 'parser' ) === 'false';
|
|
// empty cells behaviour - keeping emptyToBottom for backwards compatibility
|
|
c.empties[colIndex] = (
|
|
ts.getData( header, configHeaders, 'empty' ) ||
|
|
c.emptyTo || ( c.emptyToBottom ? 'bottom' : 'top' ) ).toLowerCase();
|
|
// text strings behaviour in numerical sorts
|
|
c.strings[colIndex] = (
|
|
ts.getData( header, configHeaders, 'string' ) ||
|
|
c.stringTo ||
|
|
'max' ).toLowerCase();
|
|
if ( noParser ) {
|
|
parser = ts.getParserById( 'no-parser' );
|
|
}
|
|
if ( !extractor ) {
|
|
// For now, maybe detect someday
|
|
extractor = false;
|
|
}
|
|
if ( !parser ) {
|
|
parser = ts.detectParserForColumn( c, rows, -1, colIndex );
|
|
}
|
|
if ( c.debug ) {
|
|
debug[ '(' + colIndex + ') ' + header.text() ] = {
|
|
parser : parser.id,
|
|
extractor : extractor ? extractor.id : 'none',
|
|
string : c.strings[ colIndex ],
|
|
empty : c.empties[ colIndex ]
|
|
};
|
|
}
|
|
list.parsers[ colIndex ] = parser;
|
|
list.extractors[ colIndex ] = extractor;
|
|
span = header[ 0 ].colSpan - 1;
|
|
if ( span > 0 ) {
|
|
colIndex += span;
|
|
max += span;
|
|
while ( span + 1 > 0 ) {
|
|
// set colspan columns to use the same parsers & extractors
|
|
list.parsers[ colIndex - span ] = parser;
|
|
list.extractors[ colIndex - span ] = extractor;
|
|
span--;
|
|
}
|
|
}
|
|
}
|
|
colIndex++;
|
|
}
|
|
}
|
|
tbodyIndex += ( list.parsers.length ) ? len : 1;
|
|
}
|
|
if ( c.debug ) {
|
|
if ( !ts.isEmptyObject( debug ) ) {
|
|
console[ console.table ? 'table' : 'log' ]( debug );
|
|
} else {
|
|
console.warn( ' No parsers detected!' );
|
|
}
|
|
console.log( 'Completed detecting parsers' + ts.benchmark( time ) );
|
|
if ( console.groupEnd ) { console.groupEnd(); }
|
|
}
|
|
c.parsers = list.parsers;
|
|
c.extractors = list.extractors;
|
|
},
|
|
|
|
addParser : function( parser ) {
|
|
var indx,
|
|
len = ts.parsers.length,
|
|
add = true;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
if ( ts.parsers[ indx ].id.toLowerCase() === parser.id.toLowerCase() ) {
|
|
add = false;
|
|
}
|
|
}
|
|
if ( add ) {
|
|
ts.parsers[ ts.parsers.length ] = parser;
|
|
}
|
|
},
|
|
|
|
getParserById : function( name ) {
|
|
/*jshint eqeqeq:false */
|
|
if ( name == 'false' ) { return false; }
|
|
var indx,
|
|
len = ts.parsers.length;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
if ( ts.parsers[ indx ].id.toLowerCase() === ( name.toString() ).toLowerCase() ) {
|
|
return ts.parsers[ indx ];
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
|
|
detectParserForColumn : function( c, rows, rowIndex, cellIndex ) {
|
|
var cur, $node, row,
|
|
indx = ts.parsers.length,
|
|
node = false,
|
|
nodeValue = '',
|
|
keepLooking = true;
|
|
while ( nodeValue === '' && keepLooking ) {
|
|
rowIndex++;
|
|
row = rows[ rowIndex ];
|
|
// stop looking after 50 empty rows
|
|
if ( row && rowIndex < 50 ) {
|
|
if ( row.className.indexOf( ts.cssIgnoreRow ) < 0 ) {
|
|
node = rows[ rowIndex ].cells[ cellIndex ];
|
|
nodeValue = ts.getElementText( c, node, cellIndex );
|
|
$node = $( node );
|
|
if ( c.debug ) {
|
|
console.log( 'Checking if value was empty on row ' + rowIndex + ', column: ' +
|
|
cellIndex + ': "' + nodeValue + '"' );
|
|
}
|
|
}
|
|
} else {
|
|
keepLooking = false;
|
|
}
|
|
}
|
|
while ( --indx >= 0 ) {
|
|
cur = ts.parsers[ indx ];
|
|
// ignore the default text parser because it will always be true
|
|
if ( cur && cur.id !== 'text' && cur.is && cur.is( nodeValue, c.table, node, $node ) ) {
|
|
return cur;
|
|
}
|
|
}
|
|
// nothing found, return the generic parser (text)
|
|
return ts.getParserById( 'text' );
|
|
},
|
|
|
|
getElementText : function( c, node, cellIndex ) {
|
|
if ( !node ) { return ''; }
|
|
var tmp,
|
|
extract = c.textExtraction || '',
|
|
// node could be a jquery object
|
|
// http://jsperf.com/jquery-vs-instanceof-jquery/2
|
|
$node = node.jquery ? node : $( node );
|
|
if ( typeof extract === 'string' ) {
|
|
// check data-attribute first when set to 'basic'; don't use node.innerText - it's really slow!
|
|
// http://www.kellegous.com/j/2013/02/27/innertext-vs-textcontent/
|
|
if ( extract === 'basic' && typeof ( tmp = $node.attr( c.textAttribute ) ) !== 'undefined' ) {
|
|
return $.trim( tmp );
|
|
}
|
|
return $.trim( node.textContent || $node.text() );
|
|
} else {
|
|
if ( typeof extract === 'function' ) {
|
|
return $.trim( extract( $node[ 0 ], c.table, cellIndex ) );
|
|
} else if ( typeof ( tmp = ts.getColumnData( c.table, extract, cellIndex ) ) === 'function' ) {
|
|
return $.trim( tmp( $node[ 0 ], c.table, cellIndex ) );
|
|
}
|
|
}
|
|
// fallback
|
|
return $.trim( $node[ 0 ].textContent || $node.text() );
|
|
},
|
|
|
|
// centralized function to extract/parse cell contents
|
|
getParsedText : function( c, cell, colIndex, txt ) {
|
|
if ( typeof txt === 'undefined' ) {
|
|
txt = ts.getElementText( c, cell, colIndex );
|
|
}
|
|
// if no parser, make sure to return the txt
|
|
var val = '' + txt,
|
|
parser = c.parsers[ colIndex ],
|
|
extractor = c.extractors[ colIndex ];
|
|
if ( parser ) {
|
|
// do extract before parsing, if there is one
|
|
if ( extractor && typeof extractor.format === 'function' ) {
|
|
txt = extractor.format( txt, c.table, cell, colIndex );
|
|
}
|
|
// allow parsing if the string is empty, previously parsing would change it to zero,
|
|
// in case the parser needs to extract data from the table cell attributes
|
|
val = parser.id === 'no-parser' ? '' :
|
|
// make sure txt is a string (extractor may have converted it)
|
|
parser.format( '' + txt, c.table, cell, colIndex );
|
|
if ( c.ignoreCase && typeof val === 'string' ) {
|
|
val = val.toLowerCase();
|
|
}
|
|
}
|
|
return val;
|
|
},
|
|
|
|
/*
|
|
▄████▄ ▄████▄ ▄████▄ ██ ██ ██████
|
|
██ ▀▀ ██▄▄██ ██ ▀▀ ██▄▄██ ██▄▄
|
|
██ ▄▄ ██▀▀██ ██ ▄▄ ██▀▀██ ██▀▀
|
|
▀████▀ ██ ██ ▀████▀ ██ ██ ██████
|
|
*/
|
|
buildCache : function( c, callback, $tbodies ) {
|
|
var cache, val, txt, rowIndex, colIndex, tbodyIndex, $tbody, $row,
|
|
cols, $cells, cell, cacheTime, totalRows, rowData, prevRowData,
|
|
colMax, span, cacheIndex, hasParser, max, len, index,
|
|
table = c.table,
|
|
parsers = c.parsers;
|
|
// update tbody variable
|
|
c.$tbodies = c.$table.children( 'tbody:not(.' + c.cssInfoBlock + ')' );
|
|
$tbody = typeof $tbodies === 'undefined' ? c.$tbodies : $tbodies,
|
|
c.cache = {};
|
|
c.totalRows = 0;
|
|
// if no parsers found, return - it's an empty table.
|
|
if ( !parsers ) {
|
|
return c.debug ? console.warn( 'Warning: *Empty table!* Not building a cache' ) : '';
|
|
}
|
|
if ( c.debug ) {
|
|
cacheTime = new Date();
|
|
}
|
|
// processing icon
|
|
if ( c.showProcessing ) {
|
|
ts.isProcessing( table, true );
|
|
}
|
|
for ( tbodyIndex = 0; tbodyIndex < $tbody.length; tbodyIndex++ ) {
|
|
colMax = []; // column max value per tbody
|
|
cache = c.cache[ tbodyIndex ] = {
|
|
normalized: [] // array of normalized row data; last entry contains 'rowData' above
|
|
// colMax: # // added at the end
|
|
};
|
|
|
|
totalRows = ( $tbody[ tbodyIndex ] && $tbody[ tbodyIndex ].rows.length ) || 0;
|
|
for ( rowIndex = 0; rowIndex < totalRows; ++rowIndex ) {
|
|
rowData = {
|
|
// order: original row order #
|
|
// $row : jQuery Object[]
|
|
child: [], // child row text (filter widget)
|
|
raw: [] // original row text
|
|
};
|
|
/** Add the table data to main data array */
|
|
$row = $( $tbody[ tbodyIndex ].rows[ rowIndex ] );
|
|
cols = [];
|
|
// ignore "remove-me" rows
|
|
if ( $row.hasClass( c.selectorRemove.slice(1) ) ) {
|
|
continue;
|
|
}
|
|
// if this is a child row, add it to the last row's children and continue to the next row
|
|
// ignore child row class, if it is the first row
|
|
if ( $row.hasClass( c.cssChildRow ) && rowIndex !== 0 ) {
|
|
len = cache.normalized.length - 1;
|
|
prevRowData = cache.normalized[ len ][ c.columns ];
|
|
prevRowData.$row = prevRowData.$row.add( $row );
|
|
// add 'hasChild' class name to parent row
|
|
if ( !$row.prev().hasClass( c.cssChildRow ) ) {
|
|
$row.prev().addClass( ts.css.cssHasChild );
|
|
}
|
|
// save child row content (un-parsed!)
|
|
$cells = $row.children( 'th, td' );
|
|
len = prevRowData.child.length;
|
|
prevRowData.child[ len ] = [];
|
|
// child row content does not account for colspans/rowspans; so indexing may be off
|
|
cacheIndex = 0;
|
|
max = c.columns;
|
|
for ( colIndex = 0; colIndex < max; colIndex++ ) {
|
|
cell = $cells[ colIndex ];
|
|
if ( cell ) {
|
|
prevRowData.child[ len ][ colIndex ] = ts.getParsedText( c, cell, colIndex );
|
|
span = $cells[ colIndex ].colSpan - 1;
|
|
if ( span > 0 ) {
|
|
cacheIndex += span;
|
|
max += span;
|
|
}
|
|
}
|
|
cacheIndex++;
|
|
}
|
|
// go to the next for loop
|
|
continue;
|
|
}
|
|
rowData.$row = $row;
|
|
rowData.order = rowIndex; // add original row position to rowCache
|
|
cacheIndex = 0;
|
|
max = c.columns;
|
|
for ( colIndex = 0; colIndex < max; ++colIndex ) {
|
|
cell = $row[ 0 ].cells[ colIndex ];
|
|
if ( cell && cacheIndex < c.columns ) {
|
|
hasParser = typeof parsers[ cacheIndex ] !== 'undefined';
|
|
if ( !hasParser && c.debug ) {
|
|
console.warn( 'No parser found for row: ' + rowIndex + ', column: ' + colIndex +
|
|
'; cell containing: "' + $(cell).text() + '"; does it have a header?' );
|
|
}
|
|
val = ts.getElementText( c, cell, cacheIndex );
|
|
rowData.raw[ cacheIndex ] = val; // save original row text
|
|
// save raw column text even if there is no parser set
|
|
txt = ts.getParsedText( c, cell, cacheIndex, val );
|
|
cols[ cacheIndex ] = txt;
|
|
if ( hasParser && ( parsers[ cacheIndex ].type || '' ).toLowerCase() === 'numeric' ) {
|
|
// determine column max value (ignore sign)
|
|
colMax[ cacheIndex ] = Math.max( Math.abs( txt ) || 0, colMax[ cacheIndex ] || 0 );
|
|
}
|
|
// allow colSpan in tbody
|
|
span = cell.colSpan - 1;
|
|
if ( span > 0 ) {
|
|
index = 0;
|
|
while ( index <= span ) {
|
|
// duplicate text (or not) to spanned columns
|
|
// instead of setting duplicate span to empty string, use textExtraction to try to get a value
|
|
// see http://stackoverflow.com/q/36449711/145346
|
|
txt = c.duplicateSpan || index === 0 ?
|
|
val :
|
|
typeof c.textExtraction !== 'string' ?
|
|
ts.getElementText( c, cell, cacheIndex + index ) || '' :
|
|
'';
|
|
rowData.raw[ cacheIndex + index ] = txt;
|
|
cols[ cacheIndex + index ] = txt;
|
|
index++;
|
|
}
|
|
cacheIndex += span;
|
|
max += span;
|
|
}
|
|
}
|
|
cacheIndex++;
|
|
}
|
|
// ensure rowData is always in the same location (after the last column)
|
|
cols[ c.columns ] = rowData;
|
|
cache.normalized[ cache.normalized.length ] = cols;
|
|
}
|
|
cache.colMax = colMax;
|
|
// total up rows, not including child rows
|
|
c.totalRows += cache.normalized.length;
|
|
|
|
}
|
|
if ( c.showProcessing ) {
|
|
ts.isProcessing( table ); // remove processing icon
|
|
}
|
|
if ( c.debug ) {
|
|
len = Math.min( 5, c.cache[ 0 ].normalized.length );
|
|
console[ console.group ? 'group' : 'log' ]( 'Building cache for ' + c.totalRows +
|
|
' rows (showing ' + len + ' rows in log) and ' + c.columns + ' columns' +
|
|
ts.benchmark( cacheTime ) );
|
|
val = {};
|
|
for ( colIndex = 0; colIndex < c.columns; colIndex++ ) {
|
|
for ( cacheIndex = 0; cacheIndex < len; cacheIndex++ ) {
|
|
if ( !val[ 'row: ' + cacheIndex ] ) {
|
|
val[ 'row: ' + cacheIndex ] = {};
|
|
}
|
|
val[ 'row: ' + cacheIndex ][ c.$headerIndexed[ colIndex ].text() ] =
|
|
c.cache[ 0 ].normalized[ cacheIndex ][ colIndex ];
|
|
}
|
|
}
|
|
console[ console.table ? 'table' : 'log' ]( val );
|
|
if ( console.groupEnd ) { console.groupEnd(); }
|
|
}
|
|
if ( $.isFunction( callback ) ) {
|
|
callback( table );
|
|
}
|
|
},
|
|
|
|
getColumnText : function( table, column, callback, rowFilter ) {
|
|
table = $( table )[0];
|
|
var tbodyIndex, rowIndex, cache, row, tbodyLen, rowLen, raw, parsed, $cell, result,
|
|
hasCallback = typeof callback === 'function',
|
|
allColumns = column === 'all',
|
|
data = { raw : [], parsed: [], $cell: [] },
|
|
c = table.config;
|
|
if ( ts.isEmptyObject( c ) ) {
|
|
if ( c.debug ) {
|
|
console.warn( 'No cache found - aborting getColumnText function!' );
|
|
}
|
|
} else {
|
|
tbodyLen = c.$tbodies.length;
|
|
for ( tbodyIndex = 0; tbodyIndex < tbodyLen; tbodyIndex++ ) {
|
|
cache = c.cache[ tbodyIndex ].normalized;
|
|
rowLen = cache.length;
|
|
for ( rowIndex = 0; rowIndex < rowLen; rowIndex++ ) {
|
|
row = cache[ rowIndex ];
|
|
if ( rowFilter && !row[ c.columns ].$row.is( rowFilter ) ) {
|
|
continue;
|
|
}
|
|
result = true;
|
|
parsed = ( allColumns ) ? row.slice( 0, c.columns ) : row[ column ];
|
|
row = row[ c.columns ];
|
|
raw = ( allColumns ) ? row.raw : row.raw[ column ];
|
|
$cell = ( allColumns ) ? row.$row.children() : row.$row.children().eq( column );
|
|
if ( hasCallback ) {
|
|
result = callback({
|
|
tbodyIndex : tbodyIndex,
|
|
rowIndex : rowIndex,
|
|
parsed : parsed,
|
|
raw : raw,
|
|
$row : row.$row,
|
|
$cell : $cell
|
|
});
|
|
}
|
|
if ( result !== false ) {
|
|
data.parsed[ data.parsed.length ] = parsed;
|
|
data.raw[ data.raw.length ] = raw;
|
|
data.$cell[ data.$cell.length ] = $cell;
|
|
}
|
|
}
|
|
}
|
|
// return everything
|
|
return data;
|
|
}
|
|
},
|
|
|
|
/*
|
|
██ ██ █████▄ █████▄ ▄████▄ ██████ ██████
|
|
██ ██ ██▄▄██ ██ ██ ██▄▄██ ██ ██▄▄
|
|
██ ██ ██▀▀▀ ██ ██ ██▀▀██ ██ ██▀▀
|
|
▀████▀ ██ █████▀ ██ ██ ██ ██████
|
|
*/
|
|
setHeadersCss : function( c ) {
|
|
var indx, column,
|
|
list = c.sortList,
|
|
len = list.length,
|
|
none = ts.css.sortNone + ' ' + c.cssNone,
|
|
css = [ ts.css.sortAsc + ' ' + c.cssAsc, ts.css.sortDesc + ' ' + c.cssDesc ],
|
|
cssIcon = [ c.cssIconAsc, c.cssIconDesc, c.cssIconNone ],
|
|
aria = [ 'ascending', 'descending' ],
|
|
// find the footer
|
|
$extras = c.$table
|
|
.find( 'tfoot tr' )
|
|
.children( 'td, th' )
|
|
.add( $( c.namespace + '_extra_headers' ) )
|
|
.removeClass( css.join( ' ' ) ),
|
|
// remove all header information
|
|
$sorted = c.$headers
|
|
.add( $( 'thead ' + c.namespace + '_extra_headers' ) )
|
|
.removeClass( css.join( ' ' ) )
|
|
.addClass( none )
|
|
.attr( 'aria-sort', 'none' )
|
|
.find( '.' + ts.css.icon )
|
|
.removeClass( cssIcon.join( ' ' ) )
|
|
.end();
|
|
// add css none to all sortable headers
|
|
$sorted
|
|
.not( '.sorter-false' )
|
|
.find( '.' + ts.css.icon )
|
|
.addClass( cssIcon[ 2 ] );
|
|
// add disabled css icon class
|
|
if ( c.cssIconDisabled ) {
|
|
$sorted
|
|
.filter( '.sorter-false' )
|
|
.find( '.' + ts.css.icon )
|
|
.addClass( c.cssIconDisabled );
|
|
}
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
// direction = 2 means reset!
|
|
if ( list[ indx ][ 1 ] !== 2 ) {
|
|
// multicolumn sorting updating - see #1005
|
|
// .not(function(){}) needs jQuery 1.4
|
|
// filter(function(i, el){}) <- el is undefined in jQuery v1.2.6
|
|
$sorted = c.$headers.filter( function( i ) {
|
|
// only include headers that are in the sortList (this includes colspans)
|
|
var include = true,
|
|
$el = c.$headers.eq( i ),
|
|
col = parseInt( $el.attr( 'data-column' ), 10 ),
|
|
end = col + c.$headers[ i ].colSpan;
|
|
for ( ; col < end; col++ ) {
|
|
include = include ? include || ts.isValueInArray( col, c.sortList ) > -1 : false;
|
|
}
|
|
return include;
|
|
});
|
|
|
|
// choose the :last in case there are nested columns
|
|
$sorted = $sorted
|
|
.not( '.sorter-false' )
|
|
.filter( '[data-column="' + list[ indx ][ 0 ] + '"]' + ( len === 1 ? ':last' : '' ) );
|
|
if ( $sorted.length ) {
|
|
for ( column = 0; column < $sorted.length; column++ ) {
|
|
if ( !$sorted[ column ].sortDisabled ) {
|
|
$sorted
|
|
.eq( column )
|
|
.removeClass( none )
|
|
.addClass( css[ list[ indx ][ 1 ] ] )
|
|
.attr( 'aria-sort', aria[ list[ indx ][ 1 ] ] )
|
|
.find( '.' + ts.css.icon )
|
|
.removeClass( cssIcon[ 2 ] )
|
|
.addClass( cssIcon[ list[ indx ][ 1 ] ] );
|
|
}
|
|
}
|
|
// add sorted class to footer & extra headers, if they exist
|
|
if ( $extras.length ) {
|
|
$extras
|
|
.filter( '[data-column="' + list[ indx ][ 0 ] + '"]' )
|
|
.removeClass( none )
|
|
.addClass( css[ list[ indx ][ 1 ] ] );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// add verbose aria labels
|
|
len = c.$headers.length;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
ts.setColumnAriaLabel( c, c.$headers.eq( indx ) );
|
|
}
|
|
},
|
|
|
|
// This function does NOT return closest if the $el matches the selector
|
|
getClosest : function( $el, selector ) {
|
|
return $.fn.closest ?
|
|
$el.closest( selector ) :
|
|
$el.parents( selector ).filter( ':first' );
|
|
},
|
|
|
|
getHeaderCell : function( $el ) {
|
|
// jQuery v1.2.6 doesn't have closest()
|
|
if ( $.fn.closest ) {
|
|
return $el.closest( 'th, td' );
|
|
}
|
|
return /TH|TD/.test( $el[0].nodeName ) ?
|
|
$el :
|
|
$el.parents( 'th, td' ).filter( ':first' );
|
|
},
|
|
|
|
// nextSort (optional), lets you disable next sort text
|
|
setColumnAriaLabel : function( c, $header, nextSort ) {
|
|
if ( $header.length ) {
|
|
var $th = ts.getHeaderCell( $header ),
|
|
// data-column always stored on the th/td
|
|
column = parseInt( $th.attr( 'data-column' ), 10 ),
|
|
vars = c.sortVars[ column ],
|
|
tmp = $header.hasClass( ts.css.sortAsc ) ?
|
|
'sortAsc' :
|
|
$header.hasClass( ts.css.sortDesc ) ? 'sortDesc' : 'sortNone',
|
|
txt = $.trim( $header.text() ) + ': ' + ts.language[ tmp ];
|
|
if ( $header.hasClass( 'sorter-false' ) || nextSort === false ) {
|
|
txt += ts.language.sortDisabled;
|
|
} else {
|
|
tmp = ( vars.count + 1 ) % vars.order.length;
|
|
nextSort = vars.order[ tmp ];
|
|
// if nextSort
|
|
txt += ts.language[ nextSort === 0 ? 'nextAsc' : nextSort === 1 ? 'nextDesc' : 'nextNone' ];
|
|
}
|
|
$header.attr( 'aria-label', txt );
|
|
}
|
|
},
|
|
|
|
updateHeader : function( c ) {
|
|
var index, isDisabled, $header, col,
|
|
table = c.table,
|
|
len = c.$headers.length;
|
|
for ( index = 0; index < len; index++ ) {
|
|
$header = c.$headers.eq( index );
|
|
col = ts.getColumnData( table, c.headers, index, true );
|
|
// add 'sorter-false' class if 'parser-false' is set
|
|
isDisabled = ts.getData( $header, col, 'sorter' ) === 'false' || ts.getData( $header, col, 'parser' ) === 'false';
|
|
ts.setColumnSort( c, $header, isDisabled );
|
|
}
|
|
},
|
|
|
|
setColumnSort : function( c, $header, isDisabled ) {
|
|
var id = c.table.id;
|
|
$header[ 0 ].sortDisabled = isDisabled;
|
|
$header[ isDisabled ? 'addClass' : 'removeClass' ]( 'sorter-false' )
|
|
.attr( 'aria-disabled', '' + isDisabled );
|
|
// disable tab index on disabled cells
|
|
if ( c.tabIndex ) {
|
|
if ( isDisabled ) {
|
|
$header.removeAttr( 'tabindex' );
|
|
} else {
|
|
$header.attr( 'tabindex', '0' );
|
|
}
|
|
}
|
|
// aria-controls - requires table ID
|
|
if ( id ) {
|
|
if ( isDisabled ) {
|
|
$header.removeAttr( 'aria-controls' );
|
|
} else {
|
|
$header.attr( 'aria-controls', id );
|
|
}
|
|
}
|
|
},
|
|
|
|
updateHeaderSortCount : function( c, list ) {
|
|
var col, dir, group, indx, primary, temp, val, order,
|
|
sortList = list || c.sortList,
|
|
len = sortList.length;
|
|
c.sortList = [];
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
val = sortList[ indx ];
|
|
// ensure all sortList values are numeric - fixes #127
|
|
col = parseInt( val[ 0 ], 10 );
|
|
// prevents error if sorton array is wrong
|
|
if ( col < c.columns ) {
|
|
|
|
// set order if not already defined - due to colspan header without associated header cell
|
|
// adding this check prevents a javascript error
|
|
if ( !c.sortVars[ col ].order ) {
|
|
if ( ts.getOrder( c.sortInitialOrder ) ) {
|
|
order = c.sortReset ? [ 1, 0, 2 ] : [ 1, 0 ];
|
|
} else {
|
|
order = c.sortReset ? [ 0, 1, 2 ] : [ 0, 1 ];
|
|
}
|
|
c.sortVars[ col ].order = order;
|
|
c.sortVars[ col ].count = 0;
|
|
}
|
|
|
|
order = c.sortVars[ col ].order;
|
|
dir = ( '' + val[ 1 ] ).match( /^(1|d|s|o|n)/ );
|
|
dir = dir ? dir[ 0 ] : '';
|
|
// 0/(a)sc (default), 1/(d)esc, (s)ame, (o)pposite, (n)ext
|
|
switch ( dir ) {
|
|
case '1' : case 'd' : // descending
|
|
dir = 1;
|
|
break;
|
|
case 's' : // same direction (as primary column)
|
|
// if primary sort is set to 's', make it ascending
|
|
dir = primary || 0;
|
|
break;
|
|
case 'o' :
|
|
temp = order[ ( primary || 0 ) % order.length ];
|
|
// opposite of primary column; but resets if primary resets
|
|
dir = temp === 0 ? 1 : temp === 1 ? 0 : 2;
|
|
break;
|
|
case 'n' :
|
|
dir = order[ ( ++c.sortVars[ col ].count ) % order.length ];
|
|
break;
|
|
default : // ascending
|
|
dir = 0;
|
|
break;
|
|
}
|
|
primary = indx === 0 ? dir : primary;
|
|
group = [ col, parseInt( dir, 10 ) || 0 ];
|
|
c.sortList[ c.sortList.length ] = group;
|
|
dir = $.inArray( group[ 1 ], order ); // fixes issue #167
|
|
c.sortVars[ col ].count = dir >= 0 ? dir : group[ 1 ] % order.length;
|
|
}
|
|
}
|
|
},
|
|
|
|
updateAll : function( c, resort, callback ) {
|
|
var table = c.table;
|
|
table.isUpdating = true;
|
|
ts.refreshWidgets( table, true, true );
|
|
ts.buildHeaders( c );
|
|
ts.bindEvents( table, c.$headers, true );
|
|
ts.bindMethods( c );
|
|
ts.commonUpdate( c, resort, callback );
|
|
},
|
|
|
|
update : function( c, resort, callback ) {
|
|
var table = c.table;
|
|
table.isUpdating = true;
|
|
// update sorting (if enabled/disabled)
|
|
ts.updateHeader( c );
|
|
ts.commonUpdate( c, resort, callback );
|
|
},
|
|
|
|
// simple header update - see #989
|
|
updateHeaders : function( c, callback ) {
|
|
c.table.isUpdating = true;
|
|
ts.buildHeaders( c );
|
|
ts.bindEvents( c.table, c.$headers, true );
|
|
ts.resortComplete( c, callback );
|
|
},
|
|
|
|
updateCell : function( c, cell, resort, callback ) {
|
|
// updateCell for child rows is a mess - we'll ignore them for now
|
|
// eventually I'll break out the "update" row cache code to make everything consistent
|
|
if ( $( cell ).closest( 'tr' ).hasClass( c.cssChildRow ) ) {
|
|
console.warn('Tablesorter Warning! "updateCell" for child row content has been disabled, use "update" instead');
|
|
return;
|
|
}
|
|
if ( ts.isEmptyObject( c.cache ) ) {
|
|
// empty table, do an update instead - fixes #1099
|
|
ts.updateHeader( c );
|
|
ts.commonUpdate( c, resort, callback );
|
|
return;
|
|
}
|
|
c.table.isUpdating = true;
|
|
c.$table.find( c.selectorRemove ).remove();
|
|
// get position from the dom
|
|
var tmp, indx, row, icell, cache, len,
|
|
$tbodies = c.$tbodies,
|
|
$cell = $( cell ),
|
|
// update cache - format: function( s, table, cell, cellIndex )
|
|
// no closest in jQuery v1.2.6
|
|
tbodyIndex = $tbodies.index( ts.getClosest( $cell, 'tbody' ) ),
|
|
tbcache = c.cache[ tbodyIndex ],
|
|
$row = ts.getClosest( $cell, 'tr' );
|
|
cell = $cell[ 0 ]; // in case cell is a jQuery object
|
|
// tbody may not exist if update is initialized while tbody is removed for processing
|
|
if ( $tbodies.length && tbodyIndex >= 0 ) {
|
|
row = $tbodies.eq( tbodyIndex ).find( 'tr' ).not( '.' + c.cssChildRow ).index( $row );
|
|
cache = tbcache.normalized[ row ];
|
|
len = $row[ 0 ].cells.length;
|
|
if ( len !== c.columns ) {
|
|
// colspan in here somewhere!
|
|
icell = 0;
|
|
tmp = false;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
if ( !tmp && $row[ 0 ].cells[ indx ] !== cell ) {
|
|
icell += $row[ 0 ].cells[ indx ].colSpan;
|
|
} else {
|
|
tmp = true;
|
|
}
|
|
}
|
|
} else {
|
|
icell = $cell.index();
|
|
}
|
|
tmp = ts.getElementText( c, cell, icell ); // raw
|
|
cache[ c.columns ].raw[ icell ] = tmp;
|
|
tmp = ts.getParsedText( c, cell, icell, tmp );
|
|
cache[ icell ] = tmp; // parsed
|
|
if ( ( c.parsers[ icell ].type || '' ).toLowerCase() === 'numeric' ) {
|
|
// update column max value (ignore sign)
|
|
tbcache.colMax[ icell ] = Math.max( Math.abs( tmp ) || 0, tbcache.colMax[ icell ] || 0 );
|
|
}
|
|
tmp = resort !== 'undefined' ? resort : c.resort;
|
|
if ( tmp !== false ) {
|
|
// widgets will be reapplied
|
|
ts.checkResort( c, tmp, callback );
|
|
} else {
|
|
// don't reapply widgets is resort is false, just in case it causes
|
|
// problems with element focus
|
|
ts.resortComplete( c, callback );
|
|
}
|
|
} else {
|
|
if ( c.debug ) {
|
|
console.error( 'updateCell aborted, tbody missing or not within the indicated table' );
|
|
}
|
|
c.table.isUpdating = false;
|
|
}
|
|
},
|
|
|
|
addRows : function( c, $row, resort, callback ) {
|
|
var txt, val, tbodyIndex, rowIndex, rows, cellIndex, len, order,
|
|
cacheIndex, rowData, cells, cell, span,
|
|
// allow passing a row string if only one non-info tbody exists in the table
|
|
valid = typeof $row === 'string' && c.$tbodies.length === 1 && /<tr/.test( $row || '' ),
|
|
table = c.table;
|
|
if ( valid ) {
|
|
$row = $( $row );
|
|
c.$tbodies.append( $row );
|
|
} else if (
|
|
!$row ||
|
|
// row is a jQuery object?
|
|
!( $row instanceof jQuery ) ||
|
|
// row contained in the table?
|
|
( ts.getClosest( $row, 'table' )[ 0 ] !== c.table )
|
|
) {
|
|
if ( c.debug ) {
|
|
console.error( 'addRows method requires (1) a jQuery selector reference to rows that have already ' +
|
|
'been added to the table, or (2) row HTML string to be added to a table with only one tbody' );
|
|
}
|
|
return false;
|
|
}
|
|
table.isUpdating = true;
|
|
if ( ts.isEmptyObject( c.cache ) ) {
|
|
// empty table, do an update instead - fixes #450
|
|
ts.updateHeader( c );
|
|
ts.commonUpdate( c, resort, callback );
|
|
} else {
|
|
rows = $row.filter( 'tr' ).attr( 'role', 'row' ).length;
|
|
tbodyIndex = c.$tbodies.index( $row.parents( 'tbody' ).filter( ':first' ) );
|
|
// fixes adding rows to an empty table - see issue #179
|
|
if ( !( c.parsers && c.parsers.length ) ) {
|
|
ts.setupParsers( c );
|
|
}
|
|
// add each row
|
|
for ( rowIndex = 0; rowIndex < rows; rowIndex++ ) {
|
|
cacheIndex = 0;
|
|
len = $row[ rowIndex ].cells.length;
|
|
order = c.cache[ tbodyIndex ].normalized.length;
|
|
cells = [];
|
|
rowData = {
|
|
child : [],
|
|
raw : [],
|
|
$row : $row.eq( rowIndex ),
|
|
order : order
|
|
};
|
|
// add each cell
|
|
for ( cellIndex = 0; cellIndex < len; cellIndex++ ) {
|
|
cell = $row[ rowIndex ].cells[ cellIndex ];
|
|
txt = ts.getElementText( c, cell, cacheIndex );
|
|
rowData.raw[ cacheIndex ] = txt;
|
|
val = ts.getParsedText( c, cell, cacheIndex, txt );
|
|
cells[ cacheIndex ] = val;
|
|
if ( ( c.parsers[ cacheIndex ].type || '' ).toLowerCase() === 'numeric' ) {
|
|
// update column max value (ignore sign)
|
|
c.cache[ tbodyIndex ].colMax[ cacheIndex ] =
|
|
Math.max( Math.abs( val ) || 0, c.cache[ tbodyIndex ].colMax[ cacheIndex ] || 0 );
|
|
}
|
|
span = cell.colSpan - 1;
|
|
if ( span > 0 ) {
|
|
cacheIndex += span;
|
|
}
|
|
cacheIndex++;
|
|
}
|
|
// add the row data to the end
|
|
cells[ c.columns ] = rowData;
|
|
// update cache
|
|
c.cache[ tbodyIndex ].normalized[ order ] = cells;
|
|
}
|
|
// resort using current settings
|
|
ts.checkResort( c, resort, callback );
|
|
}
|
|
},
|
|
|
|
updateCache : function( c, callback, $tbodies ) {
|
|
// rebuild parsers
|
|
if ( !( c.parsers && c.parsers.length ) ) {
|
|
ts.setupParsers( c, $tbodies );
|
|
}
|
|
// rebuild the cache map
|
|
ts.buildCache( c, callback, $tbodies );
|
|
},
|
|
|
|
// init flag (true) used by pager plugin to prevent widget application
|
|
// renamed from appendToTable
|
|
appendCache : function( c, init ) {
|
|
var parsed, totalRows, $tbody, $curTbody, rowIndex, tbodyIndex, appendTime,
|
|
table = c.table,
|
|
wo = c.widgetOptions,
|
|
$tbodies = c.$tbodies,
|
|
rows = [],
|
|
cache = c.cache;
|
|
// empty table - fixes #206/#346
|
|
if ( ts.isEmptyObject( cache ) ) {
|
|
// run pager appender in case the table was just emptied
|
|
return c.appender ? c.appender( table, rows ) :
|
|
table.isUpdating ? c.$table.triggerHandler( 'updateComplete', table ) : ''; // Fixes #532
|
|
}
|
|
if ( c.debug ) {
|
|
appendTime = new Date();
|
|
}
|
|
for ( tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
|
|
$tbody = $tbodies.eq( tbodyIndex );
|
|
if ( $tbody.length ) {
|
|
// detach tbody for manipulation
|
|
$curTbody = ts.processTbody( table, $tbody, true );
|
|
parsed = cache[ tbodyIndex ].normalized;
|
|
totalRows = parsed.length;
|
|
for ( rowIndex = 0; rowIndex < totalRows; rowIndex++ ) {
|
|
rows[rows.length] = parsed[ rowIndex ][ c.columns ].$row;
|
|
// removeRows used by the pager plugin; don't render if using ajax - fixes #411
|
|
if ( !c.appender || ( c.pager && ( !c.pager.removeRows || !wo.pager_removeRows ) && !c.pager.ajax ) ) {
|
|
$curTbody.append( parsed[ rowIndex ][ c.columns ].$row );
|
|
}
|
|
}
|
|
// restore tbody
|
|
ts.processTbody( table, $curTbody, false );
|
|
}
|
|
}
|
|
if ( c.appender ) {
|
|
c.appender( table, rows );
|
|
}
|
|
if ( c.debug ) {
|
|
console.log( 'Rebuilt table' + ts.benchmark( appendTime ) );
|
|
}
|
|
// apply table widgets; but not before ajax completes
|
|
if ( !init && !c.appender ) {
|
|
ts.applyWidget( table );
|
|
}
|
|
if ( table.isUpdating ) {
|
|
c.$table.triggerHandler( 'updateComplete', table );
|
|
}
|
|
},
|
|
|
|
commonUpdate : function( c, resort, callback ) {
|
|
// remove rows/elements before update
|
|
c.$table.find( c.selectorRemove ).remove();
|
|
// rebuild parsers
|
|
ts.setupParsers( c );
|
|
// rebuild the cache map
|
|
ts.buildCache( c );
|
|
ts.checkResort( c, resort, callback );
|
|
},
|
|
|
|
/*
|
|
▄█████ ▄████▄ █████▄ ██████ ██ █████▄ ▄████▄
|
|
▀█▄ ██ ██ ██▄▄██ ██ ██ ██ ██ ██ ▄▄▄
|
|
▀█▄ ██ ██ ██▀██ ██ ██ ██ ██ ██ ▀██
|
|
█████▀ ▀████▀ ██ ██ ██ ██ ██ ██ ▀████▀
|
|
*/
|
|
initSort : function( c, cell, event ) {
|
|
if ( c.table.isUpdating ) {
|
|
// let any updates complete before initializing a sort
|
|
return setTimeout( function(){
|
|
ts.initSort( c, cell, event );
|
|
}, 50 );
|
|
}
|
|
|
|
var arry, indx, headerIndx, dir, temp, tmp, $header,
|
|
notMultiSort = !event[ c.sortMultiSortKey ],
|
|
table = c.table,
|
|
len = c.$headers.length,
|
|
// get current column index; *always* stored on th/td
|
|
$th = ts.getHeaderCell( $( cell ) ),
|
|
col = parseInt( $th.attr( 'data-column' ), 10 ),
|
|
order = c.sortVars[ col ].order;
|
|
// Only call sortStart if sorting is enabled
|
|
c.$table.triggerHandler( 'sortStart', table );
|
|
// get current column sort order
|
|
tmp = ( c.sortVars[ col ].count + 1 ) % order.length;
|
|
c.sortVars[ col ].count = event[ c.sortResetKey ] ? 2 : tmp;
|
|
// reset all sorts on non-current column - issue #30
|
|
if ( c.sortRestart ) {
|
|
for ( headerIndx = 0; headerIndx < len; headerIndx++ ) {
|
|
$header = c.$headers.eq( headerIndx );
|
|
tmp = parseInt( $header.attr( 'data-column' ), 10 );
|
|
// only reset counts on columns that weren't just clicked on and if not included in a multisort
|
|
if ( col !== tmp && ( notMultiSort || $header.hasClass( ts.css.sortNone ) ) ) {
|
|
c.sortVars[ tmp ].count = -1;
|
|
}
|
|
}
|
|
}
|
|
// user only wants to sort on one column
|
|
if ( notMultiSort ) {
|
|
// flush the sort list
|
|
c.sortList = [];
|
|
c.last.sortList = [];
|
|
if ( c.sortForce !== null ) {
|
|
arry = c.sortForce;
|
|
for ( indx = 0; indx < arry.length; indx++ ) {
|
|
if ( arry[ indx ][ 0 ] !== col ) {
|
|
c.sortList[ c.sortList.length ] = arry[ indx ];
|
|
}
|
|
}
|
|
}
|
|
// add column to sort list
|
|
dir = order[ c.sortVars[ col ].count ];
|
|
if ( dir < 2 ) {
|
|
c.sortList[ c.sortList.length ] = [ col, dir ];
|
|
// add other columns if header spans across multiple
|
|
if ( cell.colSpan > 1 ) {
|
|
for ( indx = 1; indx < cell.colSpan; indx++ ) {
|
|
c.sortList[ c.sortList.length ] = [ col + indx, dir ];
|
|
// update count on columns in colSpan
|
|
c.sortVars[ col + indx ].count = $.inArray( dir, order );
|
|
}
|
|
}
|
|
}
|
|
// multi column sorting
|
|
} else {
|
|
// get rid of the sortAppend before adding more - fixes issue #115 & #523
|
|
c.sortList = $.extend( [], c.last.sortList );
|
|
|
|
// the user has clicked on an already sorted column
|
|
if ( ts.isValueInArray( col, c.sortList ) >= 0 ) {
|
|
// reverse the sorting direction
|
|
for ( indx = 0; indx < c.sortList.length; indx++ ) {
|
|
tmp = c.sortList[ indx ];
|
|
if ( tmp[ 0 ] === col ) {
|
|
// order.count seems to be incorrect when compared to cell.count
|
|
tmp[ 1 ] = order[ c.sortVars[ col ].count ];
|
|
if ( tmp[1] === 2 ) {
|
|
c.sortList.splice( indx, 1 );
|
|
c.sortVars[ col ].count = -1;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
// add column to sort list array
|
|
dir = order[ c.sortVars[ col ].count ];
|
|
if ( dir < 2 ) {
|
|
c.sortList[ c.sortList.length ] = [ col, dir ];
|
|
// add other columns if header spans across multiple
|
|
if ( cell.colSpan > 1 ) {
|
|
for ( indx = 1; indx < cell.colSpan; indx++ ) {
|
|
c.sortList[ c.sortList.length ] = [ col + indx, dir ];
|
|
// update count on columns in colSpan
|
|
c.sortVars[ col + indx ].count = $.inArray( dir, order );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// save sort before applying sortAppend
|
|
c.last.sortList = $.extend( [], c.sortList );
|
|
if ( c.sortList.length && c.sortAppend ) {
|
|
arry = $.isArray( c.sortAppend ) ? c.sortAppend : c.sortAppend[ c.sortList[ 0 ][ 0 ] ];
|
|
if ( !ts.isEmptyObject( arry ) ) {
|
|
for ( indx = 0; indx < arry.length; indx++ ) {
|
|
if ( arry[ indx ][ 0 ] !== col && ts.isValueInArray( arry[ indx ][ 0 ], c.sortList ) < 0 ) {
|
|
dir = arry[ indx ][ 1 ];
|
|
temp = ( '' + dir ).match( /^(a|d|s|o|n)/ );
|
|
if ( temp ) {
|
|
tmp = c.sortList[ 0 ][ 1 ];
|
|
switch ( temp[ 0 ] ) {
|
|
case 'd' :
|
|
dir = 1;
|
|
break;
|
|
case 's' :
|
|
dir = tmp;
|
|
break;
|
|
case 'o' :
|
|
dir = tmp === 0 ? 1 : 0;
|
|
break;
|
|
case 'n' :
|
|
dir = ( tmp + 1 ) % order.length;
|
|
break;
|
|
default:
|
|
dir = 0;
|
|
break;
|
|
}
|
|
}
|
|
c.sortList[ c.sortList.length ] = [ arry[ indx ][ 0 ], dir ];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// sortBegin event triggered immediately before the sort
|
|
c.$table.triggerHandler( 'sortBegin', table );
|
|
// setTimeout needed so the processing icon shows up
|
|
setTimeout( function() {
|
|
// set css for headers
|
|
ts.setHeadersCss( c );
|
|
ts.multisort( c );
|
|
ts.appendCache( c );
|
|
c.$table.triggerHandler( 'sortBeforeEnd', table );
|
|
c.$table.triggerHandler( 'sortEnd', table );
|
|
}, 1 );
|
|
},
|
|
|
|
// sort multiple columns
|
|
multisort : function( c ) { /*jshint loopfunc:true */
|
|
var tbodyIndex, sortTime, colMax, rows, tmp,
|
|
table = c.table,
|
|
sorter = [],
|
|
dir = 0,
|
|
textSorter = c.textSorter || '',
|
|
sortList = c.sortList,
|
|
sortLen = sortList.length,
|
|
len = c.$tbodies.length;
|
|
if ( c.serverSideSorting || ts.isEmptyObject( c.cache ) ) {
|
|
// empty table - fixes #206/#346
|
|
return;
|
|
}
|
|
if ( c.debug ) { sortTime = new Date(); }
|
|
// cache textSorter to optimize speed
|
|
if ( typeof textSorter === 'object' ) {
|
|
colMax = c.columns;
|
|
while ( colMax-- ) {
|
|
tmp = ts.getColumnData( table, textSorter, colMax );
|
|
if ( typeof tmp === 'function' ) {
|
|
sorter[ colMax ] = tmp;
|
|
}
|
|
}
|
|
}
|
|
for ( tbodyIndex = 0; tbodyIndex < len; tbodyIndex++ ) {
|
|
colMax = c.cache[ tbodyIndex ].colMax;
|
|
rows = c.cache[ tbodyIndex ].normalized;
|
|
|
|
rows.sort( function( a, b ) {
|
|
var sortIndex, num, col, order, sort, x, y;
|
|
// rows is undefined here in IE, so don't use it!
|
|
for ( sortIndex = 0; sortIndex < sortLen; sortIndex++ ) {
|
|
col = sortList[ sortIndex ][ 0 ];
|
|
order = sortList[ sortIndex ][ 1 ];
|
|
// sort direction, true = asc, false = desc
|
|
dir = order === 0;
|
|
|
|
if ( c.sortStable && a[ col ] === b[ col ] && sortLen === 1 ) {
|
|
return a[ c.columns ].order - b[ c.columns ].order;
|
|
}
|
|
|
|
// fallback to natural sort since it is more robust
|
|
num = /n/i.test( ts.getSortType( c.parsers, col ) );
|
|
if ( num && c.strings[ col ] ) {
|
|
// sort strings in numerical columns
|
|
if ( typeof ( ts.string[ c.strings[ col ] ] ) === 'boolean' ) {
|
|
num = ( dir ? 1 : -1 ) * ( ts.string[ c.strings[ col ] ] ? -1 : 1 );
|
|
} else {
|
|
num = ( c.strings[ col ] ) ? ts.string[ c.strings[ col ] ] || 0 : 0;
|
|
}
|
|
// fall back to built-in numeric sort
|
|
// var sort = $.tablesorter['sort' + s]( a[col], b[col], dir, colMax[col], table );
|
|
sort = c.numberSorter ? c.numberSorter( a[ col ], b[ col ], dir, colMax[ col ], table ) :
|
|
ts[ 'sortNumeric' + ( dir ? 'Asc' : 'Desc' ) ]( a[ col ], b[ col ], num, colMax[ col ], col, c );
|
|
} else {
|
|
// set a & b depending on sort direction
|
|
x = dir ? a : b;
|
|
y = dir ? b : a;
|
|
// text sort function
|
|
if ( typeof textSorter === 'function' ) {
|
|
// custom OVERALL text sorter
|
|
sort = textSorter( x[ col ], y[ col ], dir, col, table );
|
|
} else if ( typeof sorter[ col ] === 'function' ) {
|
|
// custom text sorter for a SPECIFIC COLUMN
|
|
sort = sorter[ col ]( x[ col ], y[ col ], dir, col, table );
|
|
} else {
|
|
// fall back to natural sort
|
|
sort = ts[ 'sortNatural' + ( dir ? 'Asc' : 'Desc' ) ]( a[ col ], b[ col ], col, c );
|
|
}
|
|
}
|
|
if ( sort ) { return sort; }
|
|
}
|
|
return a[ c.columns ].order - b[ c.columns ].order;
|
|
});
|
|
}
|
|
if ( c.debug ) {
|
|
console.log( 'Applying sort ' + sortList.toString() + ts.benchmark( sortTime ) );
|
|
}
|
|
},
|
|
|
|
resortComplete : function( c, callback ) {
|
|
if ( c.table.isUpdating ) {
|
|
c.$table.triggerHandler( 'updateComplete', c.table );
|
|
}
|
|
if ( $.isFunction( callback ) ) {
|
|
callback( c.table );
|
|
}
|
|
},
|
|
|
|
checkResort : function( c, resort, callback ) {
|
|
var sortList = $.isArray( resort ) ? resort : c.sortList,
|
|
// if no resort parameter is passed, fallback to config.resort (true by default)
|
|
resrt = typeof resort === 'undefined' ? c.resort : resort;
|
|
// don't try to resort if the table is still processing
|
|
// this will catch spamming of the updateCell method
|
|
if ( resrt !== false && !c.serverSideSorting && !c.table.isProcessing ) {
|
|
if ( sortList.length ) {
|
|
ts.sortOn( c, sortList, function() {
|
|
ts.resortComplete( c, callback );
|
|
}, true );
|
|
} else {
|
|
ts.sortReset( c, function() {
|
|
ts.resortComplete( c, callback );
|
|
ts.applyWidget( c.table, false );
|
|
} );
|
|
}
|
|
} else {
|
|
ts.resortComplete( c, callback );
|
|
ts.applyWidget( c.table, false );
|
|
}
|
|
},
|
|
|
|
sortOn : function( c, list, callback, init ) {
|
|
var table = c.table;
|
|
c.$table.triggerHandler( 'sortStart', table );
|
|
// update header count index
|
|
ts.updateHeaderSortCount( c, list );
|
|
// set css for headers
|
|
ts.setHeadersCss( c );
|
|
// fixes #346
|
|
if ( c.delayInit && ts.isEmptyObject( c.cache ) ) {
|
|
ts.buildCache( c );
|
|
}
|
|
c.$table.triggerHandler( 'sortBegin', table );
|
|
// sort the table and append it to the dom
|
|
ts.multisort( c );
|
|
ts.appendCache( c, init );
|
|
c.$table.triggerHandler( 'sortBeforeEnd', table );
|
|
c.$table.triggerHandler( 'sortEnd', table );
|
|
ts.applyWidget( table );
|
|
if ( $.isFunction( callback ) ) {
|
|
callback( table );
|
|
}
|
|
},
|
|
|
|
sortReset : function( c, callback ) {
|
|
c.sortList = [];
|
|
ts.setHeadersCss( c );
|
|
ts.multisort( c );
|
|
ts.appendCache( c );
|
|
var indx;
|
|
for (indx = 0; indx < c.columns; indx++) {
|
|
c.sortVars[ indx ].count = -1;
|
|
}
|
|
if ( $.isFunction( callback ) ) {
|
|
callback( c.table );
|
|
}
|
|
},
|
|
|
|
getSortType : function( parsers, column ) {
|
|
return ( parsers && parsers[ column ] ) ? parsers[ column ].type || '' : '';
|
|
},
|
|
|
|
getOrder : function( val ) {
|
|
// look for 'd' in 'desc' order; return true
|
|
return ( /^d/i.test( val ) || val === 1 );
|
|
},
|
|
|
|
// Natural sort - https://github.com/overset/javascript-natural-sort (date sorting removed)
|
|
sortNatural : function( a, b ) {
|
|
if ( a === b ) { return 0; }
|
|
a = a.toString();
|
|
b = b.toString();
|
|
var aNum, bNum, aFloat, bFloat, indx, max,
|
|
regex = ts.regex;
|
|
// first try and sort Hex codes
|
|
if ( regex.hex.test( b ) ) {
|
|
aNum = parseInt( ( a || '' ).match( regex.hex ), 16 );
|
|
bNum = parseInt( ( b || '' ).match( regex.hex ), 16 );
|
|
if ( aNum < bNum ) { return -1; }
|
|
if ( aNum > bNum ) { return 1; }
|
|
}
|
|
// chunk/tokenize
|
|
aNum = ( a || '' ).replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
|
|
bNum = ( b || '' ).replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
|
|
max = Math.max( aNum.length, bNum.length );
|
|
// natural sorting through split numeric strings and default strings
|
|
for ( indx = 0; indx < max; indx++ ) {
|
|
// find floats not starting with '0', string or 0 if not defined
|
|
aFloat = isNaN( aNum[ indx ] ) ? aNum[ indx ] || 0 : parseFloat( aNum[ indx ] ) || 0;
|
|
bFloat = isNaN( bNum[ indx ] ) ? bNum[ indx ] || 0 : parseFloat( bNum[ indx ] ) || 0;
|
|
// handle numeric vs string comparison - number < string - (Kyle Adams)
|
|
if ( isNaN( aFloat ) !== isNaN( bFloat ) ) { return isNaN( aFloat ) ? 1 : -1; }
|
|
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
|
|
if ( typeof aFloat !== typeof bFloat ) {
|
|
aFloat += '';
|
|
bFloat += '';
|
|
}
|
|
if ( aFloat < bFloat ) { return -1; }
|
|
if ( aFloat > bFloat ) { return 1; }
|
|
}
|
|
return 0;
|
|
},
|
|
|
|
sortNaturalAsc : function( a, b, col, c ) {
|
|
if ( a === b ) { return 0; }
|
|
var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
|
|
if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : -empty || -1; }
|
|
if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : empty || 1; }
|
|
return ts.sortNatural( a, b );
|
|
},
|
|
|
|
sortNaturalDesc : function( a, b, col, c ) {
|
|
if ( a === b ) { return 0; }
|
|
var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
|
|
if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : empty || 1; }
|
|
if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : -empty || -1; }
|
|
return ts.sortNatural( b, a );
|
|
},
|
|
|
|
// basic alphabetical sort
|
|
sortText : function( a, b ) {
|
|
return a > b ? 1 : ( a < b ? -1 : 0 );
|
|
},
|
|
|
|
// return text string value by adding up ascii value
|
|
// so the text is somewhat sorted when using a digital sort
|
|
// this is NOT an alphanumeric sort
|
|
getTextValue : function( val, num, max ) {
|
|
if ( max ) {
|
|
// make sure the text value is greater than the max numerical value (max)
|
|
var indx,
|
|
len = val ? val.length : 0,
|
|
n = max + num;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
n += val.charCodeAt( indx );
|
|
}
|
|
return num * n;
|
|
}
|
|
return 0;
|
|
},
|
|
|
|
sortNumericAsc : function( a, b, num, max, col, c ) {
|
|
if ( a === b ) { return 0; }
|
|
var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
|
|
if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : -empty || -1; }
|
|
if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : empty || 1; }
|
|
if ( isNaN( a ) ) { a = ts.getTextValue( a, num, max ); }
|
|
if ( isNaN( b ) ) { b = ts.getTextValue( b, num, max ); }
|
|
return a - b;
|
|
},
|
|
|
|
sortNumericDesc : function( a, b, num, max, col, c ) {
|
|
if ( a === b ) { return 0; }
|
|
var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
|
|
if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : empty || 1; }
|
|
if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : -empty || -1; }
|
|
if ( isNaN( a ) ) { a = ts.getTextValue( a, num, max ); }
|
|
if ( isNaN( b ) ) { b = ts.getTextValue( b, num, max ); }
|
|
return b - a;
|
|
},
|
|
|
|
sortNumeric : function( a, b ) {
|
|
return a - b;
|
|
},
|
|
|
|
/*
|
|
██ ██ ██ ██ █████▄ ▄████▄ ██████ ██████ ▄█████
|
|
██ ██ ██ ██ ██ ██ ██ ▄▄▄ ██▄▄ ██ ▀█▄
|
|
██ ██ ██ ██ ██ ██ ██ ▀██ ██▀▀ ██ ▀█▄
|
|
███████▀ ██ █████▀ ▀████▀ ██████ ██ █████▀
|
|
*/
|
|
addWidget : function( widget ) {
|
|
if ( widget.id && !ts.isEmptyObject( ts.getWidgetById( widget.id ) ) ) {
|
|
console.warn( '"' + widget.id + '" widget was loaded more than once!' );
|
|
}
|
|
ts.widgets[ ts.widgets.length ] = widget;
|
|
},
|
|
|
|
hasWidget : function( $table, name ) {
|
|
$table = $( $table );
|
|
return $table.length && $table[ 0 ].config && $table[ 0 ].config.widgetInit[ name ] || false;
|
|
},
|
|
|
|
getWidgetById : function( name ) {
|
|
var indx, widget,
|
|
len = ts.widgets.length;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
widget = ts.widgets[ indx ];
|
|
if ( widget && widget.id && widget.id.toLowerCase() === name.toLowerCase() ) {
|
|
return widget;
|
|
}
|
|
}
|
|
},
|
|
|
|
applyWidgetOptions : function( table ) {
|
|
var indx, widget, wo,
|
|
c = table.config,
|
|
len = c.widgets.length;
|
|
if ( len ) {
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
widget = ts.getWidgetById( c.widgets[ indx ] );
|
|
if ( widget && widget.options ) {
|
|
wo = $.extend( true, {}, widget.options );
|
|
c.widgetOptions = $.extend( true, wo, c.widgetOptions );
|
|
// add widgetOptions to defaults for option validator
|
|
$.extend( true, ts.defaults.widgetOptions, widget.options );
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
addWidgetFromClass : function( table ) {
|
|
var len, indx,
|
|
c = table.config,
|
|
// look for widgets to apply from table class
|
|
// don't match from 'ui-widget-content'; use \S instead of \w to include widgets
|
|
// with dashes in the name, e.g. "widget-test-2" extracts out "test-2"
|
|
regex = '^' + c.widgetClass.replace( ts.regex.templateName, '(\\S+)+' ) + '$',
|
|
widgetClass = new RegExp( regex, 'g' ),
|
|
// split up table class (widget id's can include dashes) - stop using match
|
|
// otherwise only one widget gets extracted, see #1109
|
|
widgets = ( table.className || '' ).split( ts.regex.spaces );
|
|
if ( widgets.length ) {
|
|
len = widgets.length;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
if ( widgets[ indx ].match( widgetClass ) ) {
|
|
c.widgets[ c.widgets.length ] = widgets[ indx ].replace( widgetClass, '$1' );
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
applyWidgetId : function( table, id, init ) {
|
|
table = $(table)[0];
|
|
var applied, time, name,
|
|
c = table.config,
|
|
wo = c.widgetOptions,
|
|
widget = ts.getWidgetById( id );
|
|
if ( widget ) {
|
|
name = widget.id;
|
|
applied = false;
|
|
// add widget name to option list so it gets reapplied after sorting, filtering, etc
|
|
if ( $.inArray( name, c.widgets ) < 0 ) {
|
|
c.widgets[ c.widgets.length ] = name;
|
|
}
|
|
if ( c.debug ) { time = new Date(); }
|
|
|
|
if ( init || !( c.widgetInit[ name ] ) ) {
|
|
// set init flag first to prevent calling init more than once (e.g. pager)
|
|
c.widgetInit[ name ] = true;
|
|
if ( table.hasInitialized ) {
|
|
// don't reapply widget options on tablesorter init
|
|
ts.applyWidgetOptions( table );
|
|
}
|
|
if ( typeof widget.init === 'function' ) {
|
|
applied = true;
|
|
if ( c.debug ) {
|
|
console[ console.group ? 'group' : 'log' ]( 'Initializing ' + name + ' widget' );
|
|
}
|
|
widget.init( table, widget, c, wo );
|
|
}
|
|
}
|
|
if ( !init && typeof widget.format === 'function' ) {
|
|
applied = true;
|
|
if ( c.debug ) {
|
|
console[ console.group ? 'group' : 'log' ]( 'Updating ' + name + ' widget' );
|
|
}
|
|
widget.format( table, c, wo, false );
|
|
}
|
|
if ( c.debug ) {
|
|
if ( applied ) {
|
|
console.log( 'Completed ' + ( init ? 'initializing ' : 'applying ' ) + name + ' widget' + ts.benchmark( time ) );
|
|
if ( console.groupEnd ) { console.groupEnd(); }
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
applyWidget : function( table, init, callback ) {
|
|
table = $( table )[ 0 ]; // in case this is called externally
|
|
var indx, len, names, widget, time,
|
|
c = table.config,
|
|
widgets = [];
|
|
// prevent numerous consecutive widget applications
|
|
if ( init !== false && table.hasInitialized && ( table.isApplyingWidgets || table.isUpdating ) ) {
|
|
return;
|
|
}
|
|
if ( c.debug ) { time = new Date(); }
|
|
ts.addWidgetFromClass( table );
|
|
// prevent "tablesorter-ready" from firing multiple times in a row
|
|
clearTimeout( c.timerReady );
|
|
if ( c.widgets.length ) {
|
|
table.isApplyingWidgets = true;
|
|
// ensure unique widget ids
|
|
c.widgets = $.grep( c.widgets, function( val, index ) {
|
|
return $.inArray( val, c.widgets ) === index;
|
|
});
|
|
names = c.widgets || [];
|
|
len = names.length;
|
|
// build widget array & add priority as needed
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
widget = ts.getWidgetById( names[ indx ] );
|
|
if ( widget && widget.id ) {
|
|
// set priority to 10 if not defined
|
|
if ( !widget.priority ) { widget.priority = 10; }
|
|
widgets[ indx ] = widget;
|
|
} else if ( c.debug ) {
|
|
console.warn( '"' + names[ indx ] + '" was enabled, but the widget code has not been loaded!' );
|
|
}
|
|
}
|
|
// sort widgets by priority
|
|
widgets.sort( function( a, b ) {
|
|
return a.priority < b.priority ? -1 : a.priority === b.priority ? 0 : 1;
|
|
});
|
|
// add/update selected widgets
|
|
len = widgets.length;
|
|
if ( c.debug ) {
|
|
console[ console.group ? 'group' : 'log' ]( 'Start ' + ( init ? 'initializing' : 'applying' ) + ' widgets' );
|
|
}
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
widget = widgets[ indx ];
|
|
if ( widget && widget.id ) {
|
|
ts.applyWidgetId( table, widget.id, init );
|
|
}
|
|
}
|
|
if ( c.debug && console.groupEnd ) { console.groupEnd(); }
|
|
}
|
|
c.timerReady = setTimeout( function() {
|
|
table.isApplyingWidgets = false;
|
|
$.data( table, 'lastWidgetApplication', new Date() );
|
|
c.$table.triggerHandler( 'tablesorter-ready' );
|
|
// callback executed on init only
|
|
if ( !init && typeof callback === 'function' ) {
|
|
callback( table );
|
|
}
|
|
if ( c.debug ) {
|
|
widget = c.widgets.length;
|
|
console.log( 'Completed ' +
|
|
( init === true ? 'initializing ' : 'applying ' ) + widget +
|
|
' widget' + ( widget !== 1 ? 's' : '' ) + ts.benchmark( time ) );
|
|
}
|
|
}, 10 );
|
|
},
|
|
|
|
removeWidget : function( table, name, refreshing ) {
|
|
table = $( table )[ 0 ];
|
|
var index, widget, indx, len,
|
|
c = table.config;
|
|
// if name === true, add all widgets from $.tablesorter.widgets
|
|
if ( name === true ) {
|
|
name = [];
|
|
len = ts.widgets.length;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
widget = ts.widgets[ indx ];
|
|
if ( widget && widget.id ) {
|
|
name[ name.length ] = widget.id;
|
|
}
|
|
}
|
|
} else {
|
|
// name can be either an array of widgets names,
|
|
// or a space/comma separated list of widget names
|
|
name = ( $.isArray( name ) ? name.join( ',' ) : name || '' ).toLowerCase().split( /[\s,]+/ );
|
|
}
|
|
len = name.length;
|
|
for ( index = 0; index < len; index++ ) {
|
|
widget = ts.getWidgetById( name[ index ] );
|
|
indx = $.inArray( name[ index ], c.widgets );
|
|
// don't remove the widget from config.widget if refreshing
|
|
if ( indx >= 0 && refreshing !== true ) {
|
|
c.widgets.splice( indx, 1 );
|
|
}
|
|
if ( widget && widget.remove ) {
|
|
if ( c.debug ) {
|
|
console.log( ( refreshing ? 'Refreshing' : 'Removing' ) + ' "' + name[ index ] + '" widget' );
|
|
}
|
|
widget.remove( table, c, c.widgetOptions, refreshing );
|
|
c.widgetInit[ name[ index ] ] = false;
|
|
}
|
|
}
|
|
c.$table.triggerHandler( 'widgetRemoveEnd', table );
|
|
},
|
|
|
|
refreshWidgets : function( table, doAll, dontapply ) {
|
|
table = $( table )[ 0 ]; // see issue #243
|
|
var indx, widget,
|
|
c = table.config,
|
|
curWidgets = c.widgets,
|
|
widgets = ts.widgets,
|
|
len = widgets.length,
|
|
list = [],
|
|
callback = function( table ) {
|
|
$( table ).triggerHandler( 'refreshComplete' );
|
|
};
|
|
// remove widgets not defined in config.widgets, unless doAll is true
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
widget = widgets[ indx ];
|
|
if ( widget && widget.id && ( doAll || $.inArray( widget.id, curWidgets ) < 0 ) ) {
|
|
list[ list.length ] = widget.id;
|
|
}
|
|
}
|
|
ts.removeWidget( table, list.join( ',' ), true );
|
|
if ( dontapply !== true ) {
|
|
// call widget init if
|
|
ts.applyWidget( table, doAll || false, callback );
|
|
if ( doAll ) {
|
|
// apply widget format
|
|
ts.applyWidget( table, false, callback );
|
|
}
|
|
} else {
|
|
callback( table );
|
|
}
|
|
},
|
|
|
|
/*
|
|
██ ██ ██████ ██ ██ ██ ██████ ██ ██████ ▄█████
|
|
██ ██ ██ ██ ██ ██ ██ ██ ██▄▄ ▀█▄
|
|
██ ██ ██ ██ ██ ██ ██ ██ ██▀▀ ▀█▄
|
|
▀████▀ ██ ██ ██████ ██ ██ ██ ██████ █████▀
|
|
*/
|
|
benchmark : function( diff ) {
|
|
return ( ' (' + ( new Date().getTime() - diff.getTime() ) + ' ms)' );
|
|
},
|
|
// deprecated ts.log
|
|
log : function() {
|
|
console.log( arguments );
|
|
},
|
|
|
|
// $.isEmptyObject from jQuery v1.4
|
|
isEmptyObject : function( obj ) {
|
|
/*jshint forin: false */
|
|
for ( var name in obj ) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
isValueInArray : function( column, arry ) {
|
|
var indx,
|
|
len = arry && arry.length || 0;
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
if ( arry[ indx ][ 0 ] === column ) {
|
|
return indx;
|
|
}
|
|
}
|
|
return -1;
|
|
},
|
|
|
|
formatFloat : function( str, table ) {
|
|
if ( typeof str !== 'string' || str === '' ) { return str; }
|
|
// allow using formatFloat without a table; defaults to US number format
|
|
var num,
|
|
usFormat = table && table.config ? table.config.usNumberFormat !== false :
|
|
typeof table !== 'undefined' ? table : true;
|
|
if ( usFormat ) {
|
|
// US Format - 1,234,567.89 -> 1234567.89
|
|
str = str.replace( ts.regex.comma, '' );
|
|
} else {
|
|
// German Format = 1.234.567,89 -> 1234567.89
|
|
// French Format = 1 234 567,89 -> 1234567.89
|
|
str = str.replace( ts.regex.digitNonUS, '' ).replace( ts.regex.comma, '.' );
|
|
}
|
|
if ( ts.regex.digitNegativeTest.test( str ) ) {
|
|
// make (#) into a negative number -> (10) = -10
|
|
str = str.replace( ts.regex.digitNegativeReplace, '-$1' );
|
|
}
|
|
num = parseFloat( str );
|
|
// return the text instead of zero
|
|
return isNaN( num ) ? $.trim( str ) : num;
|
|
},
|
|
|
|
isDigit : function( str ) {
|
|
// replace all unwanted chars and match
|
|
return isNaN( str ) ?
|
|
ts.regex.digitTest.test( str.toString().replace( ts.regex.digitReplace, '' ) ) :
|
|
str !== '';
|
|
},
|
|
|
|
// computeTableHeaderCellIndexes from:
|
|
// http://www.javascripttoolbox.com/lib/table/examples.php
|
|
// http://www.javascripttoolbox.com/temp/table_cellindex.html
|
|
computeColumnIndex : function( $rows, c ) {
|
|
var i, j, k, l, cell, cells, rowIndex, rowSpan, colSpan, firstAvailCol,
|
|
// total columns has been calculated, use it to set the matrixrow
|
|
columns = c && c.columns || 0,
|
|
matrix = [],
|
|
matrixrow = new Array( columns );
|
|
for ( i = 0; i < $rows.length; i++ ) {
|
|
cells = $rows[ i ].cells;
|
|
for ( j = 0; j < cells.length; j++ ) {
|
|
cell = cells[ j ];
|
|
rowIndex = i;
|
|
rowSpan = cell.rowSpan || 1;
|
|
colSpan = cell.colSpan || 1;
|
|
if ( typeof matrix[ rowIndex ] === 'undefined' ) {
|
|
matrix[ rowIndex ] = [];
|
|
}
|
|
// Find first available column in the first row
|
|
for ( k = 0; k < matrix[ rowIndex ].length + 1; k++ ) {
|
|
if ( typeof matrix[ rowIndex ][ k ] === 'undefined' ) {
|
|
firstAvailCol = k;
|
|
break;
|
|
}
|
|
}
|
|
// jscs:disable disallowEmptyBlocks
|
|
if ( columns && cell.cellIndex === firstAvailCol ) {
|
|
// don't to anything
|
|
} else if ( cell.setAttribute ) {
|
|
// jscs:enable disallowEmptyBlocks
|
|
// add data-column (setAttribute = IE8+)
|
|
cell.setAttribute( 'data-column', firstAvailCol );
|
|
} else {
|
|
// remove once we drop support for IE7 - 1/12/2016
|
|
$( cell ).attr( 'data-column', firstAvailCol );
|
|
}
|
|
for ( k = rowIndex; k < rowIndex + rowSpan; k++ ) {
|
|
if ( typeof matrix[ k ] === 'undefined' ) {
|
|
matrix[ k ] = [];
|
|
}
|
|
matrixrow = matrix[ k ];
|
|
for ( l = firstAvailCol; l < firstAvailCol + colSpan; l++ ) {
|
|
matrixrow[ l ] = 'x';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ts.checkColumnCount($rows, matrix, matrixrow.length);
|
|
return matrixrow.length;
|
|
},
|
|
|
|
checkColumnCount : function($rows, matrix, columns) {
|
|
// this DOES NOT report any tbody column issues, except for the math and
|
|
// and column selector widgets
|
|
var i, len,
|
|
valid = true,
|
|
cells = [];
|
|
for ( i = 0; i < matrix.length; i++ ) {
|
|
// some matrix entries are undefined when testing the footer because
|
|
// it is using the rowIndex property
|
|
if ( matrix[i] ) {
|
|
len = matrix[i].length;
|
|
if ( matrix[i].length !== columns ) {
|
|
valid = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ( !valid ) {
|
|
$rows.each( function( indx, el ) {
|
|
var cell = el.parentElement.nodeName;
|
|
if ( cells.indexOf( cell ) < 0 ) {
|
|
cells.push( cell );
|
|
}
|
|
});
|
|
console.error(
|
|
'Invalid or incorrect number of columns in the ' +
|
|
cells.join( ' or ' ) + '; expected ' + columns +
|
|
', but found ' + len + ' columns'
|
|
);
|
|
}
|
|
},
|
|
|
|
// automatically add a colgroup with col elements set to a percentage width
|
|
fixColumnWidth : function( table ) {
|
|
table = $( table )[ 0 ];
|
|
var overallWidth, percent, $tbodies, len, index,
|
|
c = table.config,
|
|
$colgroup = c.$table.children( 'colgroup' );
|
|
// remove plugin-added colgroup, in case we need to refresh the widths
|
|
if ( $colgroup.length && $colgroup.hasClass( ts.css.colgroup ) ) {
|
|
$colgroup.remove();
|
|
}
|
|
if ( c.widthFixed && c.$table.children( 'colgroup' ).length === 0 ) {
|
|
$colgroup = $( '<colgroup class="' + ts.css.colgroup + '">' );
|
|
overallWidth = c.$table.width();
|
|
// only add col for visible columns - fixes #371
|
|
$tbodies = c.$tbodies.find( 'tr:first' ).children( ':visible' );
|
|
len = $tbodies.length;
|
|
for ( index = 0; index < len; index++ ) {
|
|
percent = parseInt( ( $tbodies.eq( index ).width() / overallWidth ) * 1000, 10 ) / 10 + '%';
|
|
$colgroup.append( $( '<col>' ).css( 'width', percent ) );
|
|
}
|
|
c.$table.prepend( $colgroup );
|
|
}
|
|
},
|
|
|
|
// get sorter, string, empty, etc options for each column from
|
|
// jQuery data, metadata, header option or header class name ('sorter-false')
|
|
// priority = jQuery data > meta > headers option > header class name
|
|
getData : function( header, configHeader, key ) {
|
|
var meta, cl4ss,
|
|
val = '',
|
|
$header = $( header );
|
|
if ( !$header.length ) { return ''; }
|
|
meta = $.metadata ? $header.metadata() : false;
|
|
cl4ss = ' ' + ( $header.attr( 'class' ) || '' );
|
|
if ( typeof $header.data( key ) !== 'undefined' ||
|
|
typeof $header.data( key.toLowerCase() ) !== 'undefined' ) {
|
|
// 'data-lockedOrder' is assigned to 'lockedorder'; but 'data-locked-order' is assigned to 'lockedOrder'
|
|
// 'data-sort-initial-order' is assigned to 'sortInitialOrder'
|
|
val += $header.data( key ) || $header.data( key.toLowerCase() );
|
|
} else if ( meta && typeof meta[ key ] !== 'undefined' ) {
|
|
val += meta[ key ];
|
|
} else if ( configHeader && typeof configHeader[ key ] !== 'undefined' ) {
|
|
val += configHeader[ key ];
|
|
} else if ( cl4ss !== ' ' && cl4ss.match( ' ' + key + '-' ) ) {
|
|
// include sorter class name 'sorter-text', etc; now works with 'sorter-my-custom-parser'
|
|
val = cl4ss.match( new RegExp( '\\s' + key + '-([\\w-]+)' ) )[ 1 ] || '';
|
|
}
|
|
return $.trim( val );
|
|
},
|
|
|
|
getColumnData : function( table, obj, indx, getCell, $headers ) {
|
|
if ( typeof obj !== 'object' || obj === null ) {
|
|
return obj;
|
|
}
|
|
table = $( table )[ 0 ];
|
|
var $header, key,
|
|
c = table.config,
|
|
$cells = ( $headers || c.$headers ),
|
|
// c.$headerIndexed is not defined initially
|
|
$cell = c.$headerIndexed && c.$headerIndexed[ indx ] ||
|
|
$cells.filter( '[data-column="' + indx + '"]:last' );
|
|
if ( typeof obj[ indx ] !== 'undefined' ) {
|
|
return getCell ? obj[ indx ] : obj[ $cells.index( $cell ) ];
|
|
}
|
|
for ( key in obj ) {
|
|
if ( typeof key === 'string' ) {
|
|
$header = $cell
|
|
// header cell with class/id
|
|
.filter( key )
|
|
// find elements within the header cell with cell/id
|
|
.add( $cell.find( key ) );
|
|
if ( $header.length ) {
|
|
return obj[ key ];
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
},
|
|
|
|
// *** Process table ***
|
|
// add processing indicator
|
|
isProcessing : function( $table, toggle, $headers ) {
|
|
$table = $( $table );
|
|
var c = $table[ 0 ].config,
|
|
// default to all headers
|
|
$header = $headers || $table.find( '.' + ts.css.header );
|
|
if ( toggle ) {
|
|
// don't use sortList if custom $headers used
|
|
if ( typeof $headers !== 'undefined' && c.sortList.length > 0 ) {
|
|
// get headers from the sortList
|
|
$header = $header.filter( function() {
|
|
// get data-column from attr to keep compatibility with jQuery 1.2.6
|
|
return this.sortDisabled ?
|
|
false :
|
|
ts.isValueInArray( parseFloat( $( this ).attr( 'data-column' ) ), c.sortList ) >= 0;
|
|
});
|
|
}
|
|
$table.add( $header ).addClass( ts.css.processing + ' ' + c.cssProcessing );
|
|
} else {
|
|
$table.add( $header ).removeClass( ts.css.processing + ' ' + c.cssProcessing );
|
|
}
|
|
},
|
|
|
|
// detach tbody but save the position
|
|
// don't use tbody because there are portions that look for a tbody index (updateCell)
|
|
processTbody : function( table, $tb, getIt ) {
|
|
table = $( table )[ 0 ];
|
|
if ( getIt ) {
|
|
table.isProcessing = true;
|
|
$tb.before( '<colgroup class="tablesorter-savemyplace"/>' );
|
|
return $.fn.detach ? $tb.detach() : $tb.remove();
|
|
}
|
|
var holdr = $( table ).find( 'colgroup.tablesorter-savemyplace' );
|
|
$tb.insertAfter( holdr );
|
|
holdr.remove();
|
|
table.isProcessing = false;
|
|
},
|
|
|
|
clearTableBody : function( table ) {
|
|
$( table )[ 0 ].config.$tbodies.children().detach();
|
|
},
|
|
|
|
// used when replacing accented characters during sorting
|
|
characterEquivalents : {
|
|
'a' : '\u00e1\u00e0\u00e2\u00e3\u00e4\u0105\u00e5', // áàâãäąå
|
|
'A' : '\u00c1\u00c0\u00c2\u00c3\u00c4\u0104\u00c5', // ÁÀÂÃÄĄÅ
|
|
'c' : '\u00e7\u0107\u010d', // çćč
|
|
'C' : '\u00c7\u0106\u010c', // ÇĆČ
|
|
'e' : '\u00e9\u00e8\u00ea\u00eb\u011b\u0119', // éèêëěę
|
|
'E' : '\u00c9\u00c8\u00ca\u00cb\u011a\u0118', // ÉÈÊËĚĘ
|
|
'i' : '\u00ed\u00ec\u0130\u00ee\u00ef\u0131', // íìİîïı
|
|
'I' : '\u00cd\u00cc\u0130\u00ce\u00cf', // ÍÌİÎÏ
|
|
'o' : '\u00f3\u00f2\u00f4\u00f5\u00f6\u014d', // óòôõöō
|
|
'O' : '\u00d3\u00d2\u00d4\u00d5\u00d6\u014c', // ÓÒÔÕÖŌ
|
|
'ss': '\u00df', // ß (s sharp)
|
|
'SS': '\u1e9e', // ẞ (Capital sharp s)
|
|
'u' : '\u00fa\u00f9\u00fb\u00fc\u016f', // úùûüů
|
|
'U' : '\u00da\u00d9\u00db\u00dc\u016e' // ÚÙÛÜŮ
|
|
},
|
|
|
|
replaceAccents : function( str ) {
|
|
var chr,
|
|
acc = '[',
|
|
eq = ts.characterEquivalents;
|
|
if ( !ts.characterRegex ) {
|
|
ts.characterRegexArray = {};
|
|
for ( chr in eq ) {
|
|
if ( typeof chr === 'string' ) {
|
|
acc += eq[ chr ];
|
|
ts.characterRegexArray[ chr ] = new RegExp( '[' + eq[ chr ] + ']', 'g' );
|
|
}
|
|
}
|
|
ts.characterRegex = new RegExp( acc + ']' );
|
|
}
|
|
if ( ts.characterRegex.test( str ) ) {
|
|
for ( chr in eq ) {
|
|
if ( typeof chr === 'string' ) {
|
|
str = str.replace( ts.characterRegexArray[ chr ], chr );
|
|
}
|
|
}
|
|
}
|
|
return str;
|
|
},
|
|
|
|
validateOptions : function( c ) {
|
|
var setting, setting2, typ, timer,
|
|
// ignore options containing an array
|
|
ignore = 'headers sortForce sortList sortAppend widgets'.split( ' ' ),
|
|
orig = c.originalSettings;
|
|
if ( orig ) {
|
|
if ( c.debug ) {
|
|
timer = new Date();
|
|
}
|
|
for ( setting in orig ) {
|
|
typ = typeof ts.defaults[setting];
|
|
if ( typ === 'undefined' ) {
|
|
console.warn( 'Tablesorter Warning! "table.config.' + setting + '" option not recognized' );
|
|
} else if ( typ === 'object' ) {
|
|
for ( setting2 in orig[setting] ) {
|
|
typ = ts.defaults[setting] && typeof ts.defaults[setting][setting2];
|
|
if ( $.inArray( setting, ignore ) < 0 && typ === 'undefined' ) {
|
|
console.warn( 'Tablesorter Warning! "table.config.' + setting + '.' + setting2 + '" option not recognized' );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ( c.debug ) {
|
|
console.log( 'validate options time:' + ts.benchmark( timer ) );
|
|
}
|
|
}
|
|
},
|
|
|
|
// restore headers
|
|
restoreHeaders : function( table ) {
|
|
var index, $cell,
|
|
c = $( table )[ 0 ].config,
|
|
$headers = c.$table.find( c.selectorHeaders ),
|
|
len = $headers.length;
|
|
// don't use c.$headers here in case header cells were swapped
|
|
for ( index = 0; index < len; index++ ) {
|
|
$cell = $headers.eq( index );
|
|
// only restore header cells if it is wrapped
|
|
// because this is also used by the updateAll method
|
|
if ( $cell.find( '.' + ts.css.headerIn ).length ) {
|
|
$cell.html( c.headerContent[ index ] );
|
|
}
|
|
}
|
|
},
|
|
|
|
destroy : function( table, removeClasses, callback ) {
|
|
table = $( table )[ 0 ];
|
|
if ( !table.hasInitialized ) { return; }
|
|
// remove all widgets
|
|
ts.removeWidget( table, true, false );
|
|
var events,
|
|
$t = $( table ),
|
|
c = table.config,
|
|
debug = c.debug,
|
|
$h = $t.find( 'thead:first' ),
|
|
$r = $h.find( 'tr.' + ts.css.headerRow ).removeClass( ts.css.headerRow + ' ' + c.cssHeaderRow ),
|
|
$f = $t.find( 'tfoot:first > tr' ).children( 'th, td' );
|
|
if ( removeClasses === false && $.inArray( 'uitheme', c.widgets ) >= 0 ) {
|
|
// reapply uitheme classes, in case we want to maintain appearance
|
|
$t.triggerHandler( 'applyWidgetId', [ 'uitheme' ] );
|
|
$t.triggerHandler( 'applyWidgetId', [ 'zebra' ] );
|
|
}
|
|
// remove widget added rows, just in case
|
|
$h.find( 'tr' ).not( $r ).remove();
|
|
// disable tablesorter - not using .unbind( namespace ) because namespacing was
|
|
// added in jQuery v1.4.3 - see http://api.jquery.com/event.namespace/
|
|
events = 'sortReset update updateRows updateAll updateHeaders updateCell addRows updateComplete sorton ' +
|
|
'appendCache updateCache applyWidgetId applyWidgets refreshWidgets removeWidget destroy mouseup mouseleave ' +
|
|
'keypress sortBegin sortEnd resetToLoadState '.split( ' ' )
|
|
.join( c.namespace + ' ' );
|
|
$t
|
|
.removeData( 'tablesorter' )
|
|
.unbind( events.replace( ts.regex.spaces, ' ' ) );
|
|
c.$headers
|
|
.add( $f )
|
|
.removeClass( [ ts.css.header, c.cssHeader, c.cssAsc, c.cssDesc, ts.css.sortAsc, ts.css.sortDesc, ts.css.sortNone ].join( ' ' ) )
|
|
.removeAttr( 'data-column' )
|
|
.removeAttr( 'aria-label' )
|
|
.attr( 'aria-disabled', 'true' );
|
|
$r
|
|
.find( c.selectorSort )
|
|
.unbind( ( 'mousedown mouseup keypress '.split( ' ' ).join( c.namespace + ' ' ) ).replace( ts.regex.spaces, ' ' ) );
|
|
ts.restoreHeaders( table );
|
|
$t.toggleClass( ts.css.table + ' ' + c.tableClass + ' tablesorter-' + c.theme, removeClasses === false );
|
|
$t.removeClass(c.namespace.slice(1));
|
|
// clear flag in case the plugin is initialized again
|
|
table.hasInitialized = false;
|
|
delete table.config.cache;
|
|
if ( typeof callback === 'function' ) {
|
|
callback( table );
|
|
}
|
|
if ( debug ) {
|
|
console.log( 'tablesorter has been removed' );
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
$.fn.tablesorter = function( settings ) {
|
|
return this.each( function() {
|
|
var table = this,
|
|
// merge & extend config options
|
|
c = $.extend( true, {}, ts.defaults, settings, ts.instanceMethods );
|
|
// save initial settings
|
|
c.originalSettings = settings;
|
|
// create a table from data (build table widget)
|
|
if ( !table.hasInitialized && ts.buildTable && this.nodeName !== 'TABLE' ) {
|
|
// return the table (in case the original target is the table's container)
|
|
ts.buildTable( table, c );
|
|
} else {
|
|
ts.setup( table, c );
|
|
}
|
|
});
|
|
};
|
|
|
|
// set up debug logs
|
|
if ( !( window.console && window.console.log ) ) {
|
|
// access $.tablesorter.logs for browsers that don't have a console...
|
|
ts.logs = [];
|
|
/*jshint -W020 */
|
|
console = {};
|
|
console.log = console.warn = console.error = console.table = function() {
|
|
var arg = arguments.length > 1 ? arguments : arguments[0];
|
|
ts.logs[ ts.logs.length ] = { date: Date.now(), log: arg };
|
|
};
|
|
}
|
|
|
|
// add default parsers
|
|
ts.addParser({
|
|
id : 'no-parser',
|
|
is : function() {
|
|
return false;
|
|
},
|
|
format : function() {
|
|
return '';
|
|
},
|
|
type : 'text'
|
|
});
|
|
|
|
ts.addParser({
|
|
id : 'text',
|
|
is : function() {
|
|
return true;
|
|
},
|
|
format : function( str, table ) {
|
|
var c = table.config;
|
|
if ( str ) {
|
|
str = $.trim( c.ignoreCase ? str.toLocaleLowerCase() : str );
|
|
str = c.sortLocaleCompare ? ts.replaceAccents( str ) : str;
|
|
}
|
|
return str;
|
|
},
|
|
type : 'text'
|
|
});
|
|
|
|
ts.regex.nondigit = /[^\w,. \-()]/g;
|
|
ts.addParser({
|
|
id : 'digit',
|
|
is : function( str ) {
|
|
return ts.isDigit( str );
|
|
},
|
|
format : function( str, table ) {
|
|
var num = ts.formatFloat( ( str || '' ).replace( ts.regex.nondigit, '' ), table );
|
|
return str && typeof num === 'number' ? num :
|
|
str ? $.trim( str && table.config.ignoreCase ? str.toLocaleLowerCase() : str ) : str;
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
ts.regex.currencyReplace = /[+\-,. ]/g;
|
|
ts.regex.currencyTest = /^\(?\d+[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]|[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]\d+\)?$/;
|
|
ts.addParser({
|
|
id : 'currency',
|
|
is : function( str ) {
|
|
str = ( str || '' ).replace( ts.regex.currencyReplace, '' );
|
|
// test for £$€¤¥¢
|
|
return ts.regex.currencyTest.test( str );
|
|
},
|
|
format : function( str, table ) {
|
|
var num = ts.formatFloat( ( str || '' ).replace( ts.regex.nondigit, '' ), table );
|
|
return str && typeof num === 'number' ? num :
|
|
str ? $.trim( str && table.config.ignoreCase ? str.toLocaleLowerCase() : str ) : str;
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
// too many protocols to add them all https://en.wikipedia.org/wiki/URI_scheme
|
|
// now, this regex can be updated before initialization
|
|
ts.regex.urlProtocolTest = /^(https?|ftp|file):\/\//;
|
|
ts.regex.urlProtocolReplace = /(https?|ftp|file):\/\/(www\.)?/;
|
|
ts.addParser({
|
|
id : 'url',
|
|
is : function( str ) {
|
|
return ts.regex.urlProtocolTest.test( str );
|
|
},
|
|
format : function( str ) {
|
|
return str ? $.trim( str.replace( ts.regex.urlProtocolReplace, '' ) ) : str;
|
|
},
|
|
type : 'text'
|
|
});
|
|
|
|
ts.regex.dash = /-/g;
|
|
ts.regex.isoDate = /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/;
|
|
ts.addParser({
|
|
id : 'isoDate',
|
|
is : function( str ) {
|
|
return ts.regex.isoDate.test( str );
|
|
},
|
|
format : function( str, table ) {
|
|
var date = str ? new Date( str.replace( ts.regex.dash, '/' ) ) : str;
|
|
return date instanceof Date && isFinite( date ) ? date.getTime() : str;
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
ts.regex.percent = /%/g;
|
|
ts.regex.percentTest = /(\d\s*?%|%\s*?\d)/;
|
|
ts.addParser({
|
|
id : 'percent',
|
|
is : function( str ) {
|
|
return ts.regex.percentTest.test( str ) && str.length < 15;
|
|
},
|
|
format : function( str, table ) {
|
|
return str ? ts.formatFloat( str.replace( ts.regex.percent, '' ), table ) : str;
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
// added image parser to core v2.17.9
|
|
ts.addParser({
|
|
id : 'image',
|
|
is : function( str, table, node, $node ) {
|
|
return $node.find( 'img' ).length > 0;
|
|
},
|
|
format : function( str, table, cell ) {
|
|
return $( cell ).find( 'img' ).attr( table.config.imgAttr || 'alt' ) || str;
|
|
},
|
|
parsed : true, // filter widget flag
|
|
type : 'text'
|
|
});
|
|
|
|
ts.regex.dateReplace = /(\S)([AP]M)$/i; // used by usLongDate & time parser
|
|
ts.regex.usLongDateTest1 = /^[A-Z]{3,10}\.?\s+\d{1,2},?\s+(\d{4})(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?$/i;
|
|
ts.regex.usLongDateTest2 = /^\d{1,2}\s+[A-Z]{3,10}\s+\d{4}/i;
|
|
ts.addParser({
|
|
id : 'usLongDate',
|
|
is : function( str ) {
|
|
// two digit years are not allowed cross-browser
|
|
// Jan 01, 2013 12:34:56 PM or 01 Jan 2013
|
|
return ts.regex.usLongDateTest1.test( str ) || ts.regex.usLongDateTest2.test( str );
|
|
},
|
|
format : function( str, table ) {
|
|
var date = str ? new Date( str.replace( ts.regex.dateReplace, '$1 $2' ) ) : str;
|
|
return date instanceof Date && isFinite( date ) ? date.getTime() : str;
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
// testing for ##-##-#### or ####-##-##, so it's not perfect; time can be included
|
|
ts.regex.shortDateTest = /(^\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4})|(^\d{4}[\/\s]\d{1,2}[\/\s]\d{1,2})/;
|
|
// escaped "-" because JSHint in Firefox was showing it as an error
|
|
ts.regex.shortDateReplace = /[\-.,]/g;
|
|
// XXY covers MDY & DMY formats
|
|
ts.regex.shortDateXXY = /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/;
|
|
ts.regex.shortDateYMD = /(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/;
|
|
ts.convertFormat = function( dateString, format ) {
|
|
dateString = ( dateString || '' )
|
|
.replace( ts.regex.spaces, ' ' )
|
|
.replace( ts.regex.shortDateReplace, '/' );
|
|
if ( format === 'mmddyyyy' ) {
|
|
dateString = dateString.replace( ts.regex.shortDateXXY, '$3/$1/$2' );
|
|
} else if ( format === 'ddmmyyyy' ) {
|
|
dateString = dateString.replace( ts.regex.shortDateXXY, '$3/$2/$1' );
|
|
} else if ( format === 'yyyymmdd' ) {
|
|
dateString = dateString.replace( ts.regex.shortDateYMD, '$1/$2/$3' );
|
|
}
|
|
var date = new Date( dateString );
|
|
return date instanceof Date && isFinite( date ) ? date.getTime() : '';
|
|
};
|
|
|
|
ts.addParser({
|
|
id : 'shortDate', // 'mmddyyyy', 'ddmmyyyy' or 'yyyymmdd'
|
|
is : function( str ) {
|
|
str = ( str || '' ).replace( ts.regex.spaces, ' ' ).replace( ts.regex.shortDateReplace, '/' );
|
|
return ts.regex.shortDateTest.test( str );
|
|
},
|
|
format : function( str, table, cell, cellIndex ) {
|
|
if ( str ) {
|
|
var c = table.config,
|
|
$header = c.$headerIndexed[ cellIndex ],
|
|
format = $header.length && $header.data( 'dateFormat' ) ||
|
|
ts.getData( $header, ts.getColumnData( table, c.headers, cellIndex ), 'dateFormat' ) ||
|
|
c.dateFormat;
|
|
// save format because getData can be slow...
|
|
if ( $header.length ) {
|
|
$header.data( 'dateFormat', format );
|
|
}
|
|
return ts.convertFormat( str, format ) || str;
|
|
}
|
|
return str;
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
// match 24 hour time & 12 hours time + am/pm - see http://regexr.com/3c3tk
|
|
ts.regex.timeTest = /^(0?[1-9]|1[0-2]):([0-5]\d)(\s[AP]M)$|^((?:[01]\d|[2][0-4]):[0-5]\d)$/i;
|
|
ts.regex.timeMatch = /(0?[1-9]|1[0-2]):([0-5]\d)(\s[AP]M)|((?:[01]\d|[2][0-4]):[0-5]\d)/i;
|
|
ts.addParser({
|
|
id : 'time',
|
|
is : function( str ) {
|
|
return ts.regex.timeTest.test( str );
|
|
},
|
|
format : function( str, table ) {
|
|
// isolate time... ignore month, day and year
|
|
var temp,
|
|
timePart = ( str || '' ).match( ts.regex.timeMatch ),
|
|
orig = new Date( str ),
|
|
// no time component? default to 00:00 by leaving it out, but only if str is defined
|
|
time = str && ( timePart !== null ? timePart[ 0 ] : '00:00 AM' ),
|
|
date = time ? new Date( '2000/01/01 ' + time.replace( ts.regex.dateReplace, '$1 $2' ) ) : time;
|
|
if ( date instanceof Date && isFinite( date ) ) {
|
|
temp = orig instanceof Date && isFinite( orig ) ? orig.getTime() : 0;
|
|
// if original string was a valid date, add it to the decimal so the column sorts in some kind of order
|
|
// luckily new Date() ignores the decimals
|
|
return temp ? parseFloat( date.getTime() + '.' + orig.getTime() ) : date.getTime();
|
|
}
|
|
return str;
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
ts.addParser({
|
|
id : 'metadata',
|
|
is : function() {
|
|
return false;
|
|
},
|
|
format : function( str, table, cell ) {
|
|
var c = table.config,
|
|
p = ( !c.parserMetadataName ) ? 'sortValue' : c.parserMetadataName;
|
|
return $( cell ).metadata()[ p ];
|
|
},
|
|
type : 'numeric'
|
|
});
|
|
|
|
/*
|
|
██████ ██████ █████▄ █████▄ ▄████▄
|
|
▄█▀ ██▄▄ ██▄▄██ ██▄▄██ ██▄▄██
|
|
▄█▀ ██▀▀ ██▀▀██ ██▀▀█ ██▀▀██
|
|
██████ ██████ █████▀ ██ ██ ██ ██
|
|
*/
|
|
// add default widgets
|
|
ts.addWidget({
|
|
id : 'zebra',
|
|
priority : 90,
|
|
format : function( table, c, wo ) {
|
|
var $visibleRows, $row, count, isEven, tbodyIndex, rowIndex, len,
|
|
child = new RegExp( c.cssChildRow, 'i' ),
|
|
$tbodies = c.$tbodies.add( $( c.namespace + '_extra_table' ).children( 'tbody:not(.' + c.cssInfoBlock + ')' ) );
|
|
for ( tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
|
|
// loop through the visible rows
|
|
count = 0;
|
|
$visibleRows = $tbodies.eq( tbodyIndex ).children( 'tr:visible' ).not( c.selectorRemove );
|
|
len = $visibleRows.length;
|
|
for ( rowIndex = 0; rowIndex < len; rowIndex++ ) {
|
|
$row = $visibleRows.eq( rowIndex );
|
|
// style child rows the same way the parent row was styled
|
|
if ( !child.test( $row[ 0 ].className ) ) { count++; }
|
|
isEven = ( count % 2 === 0 );
|
|
$row
|
|
.removeClass( wo.zebra[ isEven ? 1 : 0 ] )
|
|
.addClass( wo.zebra[ isEven ? 0 : 1 ] );
|
|
}
|
|
}
|
|
},
|
|
remove : function( table, c, wo, refreshing ) {
|
|
if ( refreshing ) { return; }
|
|
var tbodyIndex, $tbody,
|
|
$tbodies = c.$tbodies,
|
|
toRemove = ( wo.zebra || [ 'even', 'odd' ] ).join( ' ' );
|
|
for ( tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ){
|
|
$tbody = ts.processTbody( table, $tbodies.eq( tbodyIndex ), true ); // remove tbody
|
|
$tbody.children().removeClass( toRemove );
|
|
ts.processTbody( table, $tbody, false ); // restore tbody
|
|
}
|
|
}
|
|
});
|
|
|
|
})( jQuery );
|
|
|
|
return jQuery.tablesorter;
|
|
}));
|
|
|
|
/**
|
|
* A simple jQuery plugin for creating animated drilldown menus.
|
|
*
|
|
* @name jQuery Drilldown
|
|
* @version 1.1.1
|
|
* @requires jQuery v1.7+
|
|
* @author Aleksandras Nelkinas
|
|
* @license [MIT]{@link http://opensource.org/licenses/mit-license.php}
|
|
*
|
|
* Copyright (c) 2015 Aleksandras Nelkinas
|
|
*/
|
|
|
|
;(function (factory) {
|
|
if (typeof define === 'function' && define.amd) {
|
|
// AMD
|
|
define(['jquery'], factory);
|
|
} else if (typeof exports === 'object') {
|
|
// Node/CommonJS
|
|
module.exports = factory(require('jquery'));
|
|
} else {
|
|
// Browser globals
|
|
factory(jQuery);
|
|
}
|
|
}(function ($, undefined) {
|
|
|
|
'use strict';
|
|
|
|
var PLUGIN_NAME = 'drilldown';
|
|
var TRACK_PARENT_ATTR = 'data-next-parent';
|
|
|
|
var defaults = {
|
|
event: 'click',
|
|
selector: 'a',
|
|
speed: 100,
|
|
cssClass: {
|
|
container: PLUGIN_NAME + '-container',
|
|
root: PLUGIN_NAME + '-root',
|
|
sub: PLUGIN_NAME + '-sub',
|
|
back: PLUGIN_NAME + '-back'
|
|
}
|
|
};
|
|
|
|
var Plugin = (function () {
|
|
|
|
function Plugin(element, options) {
|
|
var inst = this;
|
|
|
|
this._name = PLUGIN_NAME;
|
|
this._defaults = defaults;
|
|
|
|
this.element = element;
|
|
this.$element = $(element);
|
|
|
|
this.options = $.extend({}, defaults, options);
|
|
|
|
this._history = [];
|
|
this._css = {
|
|
float: 'left',
|
|
width: null
|
|
};
|
|
|
|
this.$container = this.$element.find('.' + this.options.cssClass.container);
|
|
|
|
this.$element.on(this.options.event + '.' + PLUGIN_NAME, this.options.selector, function (e) {
|
|
handleAction.call(inst, e, $(this));
|
|
});
|
|
}
|
|
|
|
Plugin.prototype = {
|
|
|
|
/**
|
|
* Destroys plugin instance.
|
|
*/
|
|
destroy: function () {
|
|
this.reset();
|
|
|
|
this.$element.off(this.options.event + '.' + PLUGIN_NAME, this.options.selector);
|
|
},
|
|
|
|
/**
|
|
* Resets drilldown to its initial state.
|
|
*/
|
|
reset: function () {
|
|
var iter;
|
|
|
|
for (iter = this._history.length; iter > 0; iter--) {
|
|
up.call(this, { speed: 0 });
|
|
}
|
|
|
|
this._history = [];
|
|
this._css = {
|
|
float: 'left',
|
|
width: null
|
|
};
|
|
}
|
|
|
|
};
|
|
|
|
/**
|
|
* Handles user action and decides whether or not and where to drill.
|
|
*
|
|
* @param {jQuery.Event} e
|
|
* @param {jQuery} $trigger
|
|
* @private
|
|
*/
|
|
function handleAction(e, $trigger) {
|
|
var $next = $trigger.nextAll('.' + this.options.cssClass.sub);
|
|
var preventDefault = true;
|
|
|
|
if ($next.length) {
|
|
down.call(this, $next);
|
|
} else if ($trigger.closest('.' + this.options.cssClass.back).length) {
|
|
up.call(this);
|
|
} else {
|
|
preventDefault = false;
|
|
}
|
|
|
|
if (preventDefault && $trigger.prop('tagName') === 'A') {
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Drills down (deeper).
|
|
*
|
|
* @param {jQuery} $next
|
|
* @param {Object} opts
|
|
* @private
|
|
*/
|
|
function down($next, opts) {
|
|
var speed = (opts && opts.speed !== undefined) ? opts.speed : this.options.speed;
|
|
|
|
if (!$next.length) {
|
|
return;
|
|
}
|
|
|
|
this._css.width = this.$element.outerWidth();
|
|
this.$container.width(this._css.width * 2);
|
|
|
|
// Track parent of the opened node
|
|
$next.parent().attr(TRACK_PARENT_ATTR, true);
|
|
|
|
$next = $next
|
|
.removeClass(this.options.cssClass.sub)
|
|
.addClass(this.options.cssClass.root);
|
|
|
|
this.$container.append($next);
|
|
|
|
animateDrilling.call(this, { marginLeft: -1 * this._css.width, speed: speed }, function () {
|
|
var $current = $next.prev();
|
|
|
|
this._history.push($current.detach());
|
|
|
|
restoreState.call(this, $next);
|
|
}.bind(this));
|
|
}
|
|
|
|
/**
|
|
* Drills up (back).
|
|
*
|
|
* @private
|
|
*/
|
|
function up(opts) {
|
|
var speed = (opts && opts.speed !== undefined) ? opts.speed : this.options.speed;
|
|
var $next = this._history.pop();
|
|
|
|
this._css.width = this.$element.outerWidth();
|
|
this.$container.width(this._css.width * 2);
|
|
|
|
this.$container.prepend($next);
|
|
|
|
animateDrilling.call(this, { marginLeft: 0, speed: speed }, function () {
|
|
var $current = $next.next();
|
|
|
|
$current
|
|
.addClass(this.options.cssClass.sub)
|
|
.removeClass(this.options.cssClass.root);
|
|
|
|
// Restore the node at its initial position in the DOM
|
|
this.$container.find('[' + TRACK_PARENT_ATTR + ']').last()
|
|
.removeAttr(TRACK_PARENT_ATTR)
|
|
.append($current);
|
|
|
|
restoreState.call(this, $next);
|
|
}.bind(this));
|
|
}
|
|
|
|
/**
|
|
* Animates drilling process.
|
|
*
|
|
* @param {Object} opts
|
|
* @param {Function} callback
|
|
* @private
|
|
*/
|
|
function animateDrilling(opts, callback) {
|
|
var $menus = this.$container.children('.' + this.options.cssClass.root);
|
|
|
|
$menus.css(this._css);
|
|
|
|
$menus.first().animate({ marginLeft: opts.marginLeft }, opts.speed, callback);
|
|
}
|
|
|
|
/**
|
|
* Restores initial menu's state.
|
|
*
|
|
* @param {jQuery} $menu
|
|
* @private
|
|
*/
|
|
function restoreState($menu) {
|
|
$menu.css({
|
|
float: '',
|
|
width: '',
|
|
marginLeft: ''
|
|
});
|
|
|
|
this.$container.css('width', '');
|
|
}
|
|
|
|
return Plugin;
|
|
|
|
})();
|
|
|
|
$.fn[PLUGIN_NAME] = function (options) {
|
|
return this.each(function () {
|
|
var inst = $.data(this, PLUGIN_NAME);
|
|
var method = options;
|
|
|
|
if (!inst) {
|
|
$.data(this, PLUGIN_NAME, new Plugin(this, options));
|
|
} else if (typeof method === 'string') {
|
|
if (method === 'destroy') {
|
|
$.removeData(this, PLUGIN_NAME);
|
|
}
|
|
if (typeof inst[method] === 'function') {
|
|
inst[method]();
|
|
}
|
|
}
|
|
});
|
|
};
|
|
|
|
}));
|
|
|
|
/*
|
|
* Copyright (c) 2013 Shane Carr
|
|
*
|
|
* https://github.com/vote539/placeholdr
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
(function($, ns, placeholderAttribute, origValFn){
|
|
// Utility functions
|
|
var putPlaceholder = function(){
|
|
var $this = $(this);
|
|
if (!$this[origValFn]()) {
|
|
$this.addClass(ns);
|
|
if ($this.attr("type") === "password") {
|
|
$this.attr("type", "text");
|
|
$this.data(ns+"-pwd", true);
|
|
}
|
|
$this[origValFn]($this.attr(placeholderAttribute));
|
|
}
|
|
};
|
|
var clearPlaceholder = function(){
|
|
var $this = $(this);
|
|
$this.removeClass(ns);
|
|
if ($this.data(ns+"-pwd")) {
|
|
$this.attr("type", "password");
|
|
}
|
|
if ($this[origValFn]() === $this.attr(placeholderAttribute)){
|
|
$this[origValFn]("");
|
|
}
|
|
};
|
|
var clearPlaceholdersInForm = function(){
|
|
$(this).find("["+placeholderAttribute+"]").each(function() {
|
|
if ($(this).data(ns)) clearPlaceholder.call(this);
|
|
});
|
|
};
|
|
|
|
$.fn.placeholdr = function(){
|
|
// Don't evaluate the polyfill if the browser supports placeholders
|
|
if (placeholderAttribute in document.createElement("input")) return this;
|
|
|
|
// Find and iterate through all inputs that have a placeholder attribute
|
|
$(this).find("["+placeholderAttribute+"]").each(function(){
|
|
var $this = $(this);
|
|
|
|
// leave now if we've polyfilled this element before
|
|
if ($this.data(ns)) return;
|
|
$this.data(ns, true);
|
|
|
|
// put the placeholder into the value
|
|
putPlaceholder.call(this);
|
|
|
|
// handle focus and blur events
|
|
$this.focus(clearPlaceholder);
|
|
$this.blur(putPlaceholder);
|
|
});
|
|
|
|
// Find and iterate through all form elements in order to prevent
|
|
// placeholders from being submitted in forms.
|
|
$(this).find("form").each(function(){
|
|
var $this = $(this);
|
|
|
|
// leave now if we've polyfilled this element before
|
|
if ($this.data(ns)) return;
|
|
$this.data(ns, true);
|
|
|
|
$this.submit(clearPlaceholdersInForm);
|
|
});
|
|
|
|
return this;
|
|
};
|
|
|
|
// Overwrite the existing jQuery val() function
|
|
$.fn[origValFn] = $.fn.val;
|
|
$.fn.val = function(txt){
|
|
var $this = $(this);
|
|
if ($.type(txt) === "undefined"
|
|
&& $this.data(ns)
|
|
&& $this[origValFn]() === $this.attr(placeholderAttribute)
|
|
){
|
|
return "";
|
|
}
|
|
var isstr = $.type(txt) === "string";
|
|
if (isstr) {
|
|
clearPlaceholder.call(this);
|
|
}
|
|
var ret = $.fn[origValFn].apply(this, arguments);
|
|
if (isstr && !txt) {
|
|
putPlaceholder.call(this);
|
|
}
|
|
return ret;
|
|
};
|
|
|
|
// Evaluate the script on page ready
|
|
$(function(){
|
|
$(document).placeholdr();
|
|
});
|
|
|
|
// Add default CSS rule
|
|
document.write("<style>.placeholdr{color:#AAA;}</style>");
|
|
})(jQuery, "placeholdr", "placeholder", "placeholdrVal");
|
|
|
|
!function(t){"use strict";"function"==typeof define&&define.amd?define(["./blueimp-helper"],t):(window.blueimp=window.blueimp||{},window.blueimp.Gallery=t(window.blueimp.helper||window.jQuery))}(function(t){"use strict";function e(t,i){return void 0===document.body.style.maxHeight?null:this&&this.options===e.prototype.options?void(t&&t.length?(this.list=t,this.num=t.length,this.initOptions(i),this.initialize()):this.console.log("blueimp Gallery: No or empty list provided as first argument.",t)):new e(t,i)}return t.extend(e.prototype,{options:{container:"#blueimp-gallery",slidesContainer:"div",titleElement:"h3",displayClass:"blueimp-gallery-display",controlsClass:"blueimp-gallery-controls",singleClass:"blueimp-gallery-single",leftEdgeClass:"blueimp-gallery-left",rightEdgeClass:"blueimp-gallery-right",playingClass:"blueimp-gallery-playing",slideClass:"slide",slideLoadingClass:"slide-loading",slideErrorClass:"slide-error",slideContentClass:"slide-content",toggleClass:"toggle",prevClass:"prev",nextClass:"next",closeClass:"close",playPauseClass:"play-pause",typeProperty:"type",titleProperty:"title",urlProperty:"href",srcsetProperty:"urlset",displayTransition:!0,clearSlides:!0,stretchImages:!1,toggleControlsOnReturn:!0,toggleControlsOnSlideClick:!0,toggleSlideshowOnSpace:!0,enableKeyboardNavigation:!0,closeOnEscape:!0,closeOnSlideClick:!0,closeOnSwipeUpOrDown:!0,emulateTouchEvents:!0,stopTouchEventsPropagation:!1,hidePageScrollbars:!0,disableScroll:!0,carousel:!1,continuous:!0,unloadElements:!0,startSlideshow:!1,slideshowInterval:5e3,index:0,preloadRange:2,transitionSpeed:400,slideshowTransitionSpeed:void 0,event:void 0,onopen:void 0,onopened:void 0,onslide:void 0,onslideend:void 0,onslidecomplete:void 0,onclose:void 0,onclosed:void 0},carouselOptions:{hidePageScrollbars:!1,toggleControlsOnReturn:!1,toggleSlideshowOnSpace:!1,enableKeyboardNavigation:!1,closeOnEscape:!1,closeOnSlideClick:!1,closeOnSwipeUpOrDown:!1,disableScroll:!1,startSlideshow:!0},console:window.console&&"function"==typeof window.console.log?window.console:{log:function(){}},support:function(e){function i(){var t,i,s=n.transition;document.body.appendChild(e),s&&(t=s.name.slice(0,-9)+"ransform",void 0!==e.style[t]&&(e.style[t]="translateZ(0)",i=window.getComputedStyle(e).getPropertyValue(s.prefix+"transform"),n.transform={prefix:s.prefix,name:t,translate:!0,translateZ:!!i&&"none"!==i})),void 0!==e.style.backgroundSize&&(n.backgroundSize={},e.style.backgroundSize="contain",n.backgroundSize.contain="contain"===window.getComputedStyle(e).getPropertyValue("background-size"),e.style.backgroundSize="cover",n.backgroundSize.cover="cover"===window.getComputedStyle(e).getPropertyValue("background-size")),document.body.removeChild(e)}var s,n={touch:void 0!==window.ontouchstart||window.DocumentTouch&&document instanceof DocumentTouch},o={webkitTransition:{end:"webkitTransitionEnd",prefix:"-webkit-"},MozTransition:{end:"transitionend",prefix:"-moz-"},OTransition:{end:"otransitionend",prefix:"-o-"},transition:{end:"transitionend",prefix:""}};for(s in o)if(o.hasOwnProperty(s)&&void 0!==e.style[s]){n.transition=o[s],n.transition.name=s;break}return document.body?i():t(document).on("DOMContentLoaded",i),n}(document.createElement("div")),requestAnimationFrame:window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,cancelAnimationFrame:window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame,initialize:function(){if(this.initStartIndex(),!1===this.initWidget())return!1;this.initEventListeners(),this.onslide(this.index),this.ontransitionend(),this.options.startSlideshow&&this.play()},slide:function(t,e){window.clearTimeout(this.timeout);var i,s,n,o=this.index;if(o!==t&&1!==this.num){if(e||(e=this.options.transitionSpeed),this.support.transform){for(this.options.continuous||(t=this.circle(t)),i=Math.abs(o-t)/(o-t),this.options.continuous&&(s=i,(i=-this.positions[this.circle(t)]/this.slideWidth)!==s&&(t=-i*this.num+t)),n=Math.abs(o-t)-1;n;)n-=1,this.move(this.circle((t>o?t:o)-n-1),this.slideWidth*i,0);t=this.circle(t),this.move(o,this.slideWidth*i,e),this.move(t,0,e),this.options.continuous&&this.move(this.circle(t-i),-this.slideWidth*i,0)}else t=this.circle(t),this.animate(o*-this.slideWidth,t*-this.slideWidth,e);this.onslide(t)}},getIndex:function(){return this.index},getNumber:function(){return this.num},prev:function(){(this.options.continuous||this.index)&&this.slide(this.index-1)},next:function(){(this.options.continuous||this.index<this.num-1)&&this.slide(this.index+1)},play:function(t){var e=this;window.clearTimeout(this.timeout),this.interval=t||this.options.slideshowInterval,this.elements[this.index]>1&&(this.timeout=this.setTimeout(!this.requestAnimationFrame&&this.slide||function(t,i){e.animationFrameId=e.requestAnimationFrame.call(window,function(){e.slide(t,i)})},[this.index+1,this.options.slideshowTransitionSpeed],this.interval)),this.container.addClass(this.options.playingClass)},pause:function(){window.clearTimeout(this.timeout),this.interval=null,this.cancelAnimationFrame&&(this.cancelAnimationFrame.call(window,this.animationFrameId),this.animationFrameId=null),this.container.removeClass(this.options.playingClass)},add:function(t){var e;for(t.concat||(t=Array.prototype.slice.call(t)),this.list.concat||(this.list=Array.prototype.slice.call(this.list)),this.list=this.list.concat(t),this.num=this.list.length,this.num>2&&null===this.options.continuous&&(this.options.continuous=!0,this.container.removeClass(this.options.leftEdgeClass)),this.container.removeClass(this.options.rightEdgeClass).removeClass(this.options.singleClass),e=this.num-t.length;e<this.num;e+=1)this.addSlide(e),this.positionSlide(e);this.positions.length=this.num,this.initSlides(!0)},resetSlides:function(){this.slidesContainer.empty(),this.unloadAllSlides(),this.slides=[]},handleClose:function(){var t=this.options;this.destroyEventListeners(),this.pause(),this.container[0].style.display="none",this.container.removeClass(t.displayClass).removeClass(t.singleClass).removeClass(t.leftEdgeClass).removeClass(t.rightEdgeClass),t.hidePageScrollbars&&(document.body.style.overflow=this.bodyOverflowStyle),this.options.clearSlides&&this.resetSlides(),this.options.onclosed&&this.options.onclosed.call(this)},close:function(){function t(i){i.target===e.container[0]&&(e.container.off(e.support.transition.end,t),e.handleClose())}var e=this;this.options.onclose&&this.options.onclose.call(this),this.support.transition&&this.options.displayTransition?(this.container.on(this.support.transition.end,t),this.container.removeClass(this.options.displayClass)):this.handleClose()},circle:function(t){return(this.num+t%this.num)%this.num},move:function(t,e,i){this.translateX(t,e,i),this.positions[t]=e},translate:function(t,e,i,s){var n=this.slides[t].style,o=this.support.transition,a=this.support.transform;n[o.name+"Duration"]=s+"ms",n[a.name]="translate("+e+"px, "+i+"px)"+(a.translateZ?" translateZ(0)":"")},translateX:function(t,e,i){this.translate(t,e,0,i)},translateY:function(t,e,i){this.translate(t,0,e,i)},animate:function(t,e,i){if(i)var s=this,n=(new Date).getTime(),o=window.setInterval(function(){var a=(new Date).getTime()-n;if(a>i)return s.slidesContainer[0].style.left=e+"px",s.ontransitionend(),void window.clearInterval(o);s.slidesContainer[0].style.left=(e-t)*(Math.floor(a/i*100)/100)+t+"px"},4);else this.slidesContainer[0].style.left=e+"px"},preventDefault:function(t){t.preventDefault?t.preventDefault():t.returnValue=!1},stopPropagation:function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},onresize:function(){this.initSlides(!0)},onmousedown:function(t){t.which&&1===t.which&&"VIDEO"!==t.target.nodeName&&(t.preventDefault(),(t.originalEvent||t).touches=[{pageX:t.pageX,pageY:t.pageY}],this.ontouchstart(t))},onmousemove:function(t){this.touchStart&&((t.originalEvent||t).touches=[{pageX:t.pageX,pageY:t.pageY}],this.ontouchmove(t))},onmouseup:function(t){this.touchStart&&(this.ontouchend(t),delete this.touchStart)},onmouseout:function(e){if(this.touchStart){var i=e.target,s=e.relatedTarget;s&&(s===i||t.contains(i,s))||this.onmouseup(e)}},ontouchstart:function(t){this.options.stopTouchEventsPropagation&&this.stopPropagation(t);var e=(t.originalEvent||t).touches[0];this.touchStart={x:e.pageX,y:e.pageY,time:Date.now()},this.isScrolling=void 0,this.touchDelta={}},ontouchmove:function(t){this.options.stopTouchEventsPropagation&&this.stopPropagation(t);var e,i,s=(t.originalEvent||t).touches[0],n=(t.originalEvent||t).scale,o=this.index;if(!(s.length>1||n&&1!==n))if(this.options.disableScroll&&t.preventDefault(),this.touchDelta={x:s.pageX-this.touchStart.x,y:s.pageY-this.touchStart.y},e=this.touchDelta.x,void 0===this.isScrolling&&(this.isScrolling=this.isScrolling||Math.abs(e)<Math.abs(this.touchDelta.y)),this.isScrolling)this.translateY(o,this.touchDelta.y+this.positions[o],0);else for(t.preventDefault(),window.clearTimeout(this.timeout),this.options.continuous?i=[this.circle(o+1),o,this.circle(o-1)]:(this.touchDelta.x=e/=!o&&e>0||o===this.num-1&&e<0?Math.abs(e)/this.slideWidth+1:1,i=[o],o&&i.push(o-1),o<this.num-1&&i.unshift(o+1));i.length;)o=i.pop(),this.translateX(o,e+this.positions[o],0)},ontouchend:function(t){this.options.stopTouchEventsPropagation&&this.stopPropagation(t);var e,i,s,n,o,a=this.index,l=this.options.transitionSpeed,r=this.slideWidth,h=Number(Date.now()-this.touchStart.time)<250,d=h&&Math.abs(this.touchDelta.x)>20||Math.abs(this.touchDelta.x)>r/2,c=!a&&this.touchDelta.x>0||a===this.num-1&&this.touchDelta.x<0,u=!d&&this.options.closeOnSwipeUpOrDown&&(h&&Math.abs(this.touchDelta.y)>20||Math.abs(this.touchDelta.y)>this.slideHeight/2);this.options.continuous&&(c=!1),e=this.touchDelta.x<0?-1:1,this.isScrolling?u?this.close():this.translateY(a,0,l):d&&!c?(i=a+e,s=a-e,n=r*e,o=-r*e,this.options.continuous?(this.move(this.circle(i),n,0),this.move(this.circle(a-2*e),o,0)):i>=0&&i<this.num&&this.move(i,n,0),this.move(a,this.positions[a]+n,l),this.move(this.circle(s),this.positions[this.circle(s)]+n,l),a=this.circle(s),this.onslide(a)):this.options.continuous?(this.move(this.circle(a-1),-r,l),this.move(a,0,l),this.move(this.circle(a+1),r,l)):(a&&this.move(a-1,-r,l),this.move(a,0,l),a<this.num-1&&this.move(a+1,r,l))},ontouchcancel:function(t){this.touchStart&&(this.ontouchend(t),delete this.touchStart)},ontransitionend:function(t){var e=this.slides[this.index];t&&e!==t.target||(this.interval&&this.play(),this.setTimeout(this.options.onslideend,[this.index,e]))},oncomplete:function(e){var i,s=e.target||e.srcElement,n=s&&s.parentNode;s&&n&&(i=this.getNodeIndex(n),t(n).removeClass(this.options.slideLoadingClass),"error"===e.type?(t(n).addClass(this.options.slideErrorClass),this.elements[i]=3):this.elements[i]=2,s.clientHeight>this.container[0].clientHeight&&(s.style.maxHeight=this.container[0].clientHeight),this.interval&&this.slides[this.index]===n&&this.play(),this.setTimeout(this.options.onslidecomplete,[i,n]))},onload:function(t){this.oncomplete(t)},onerror:function(t){this.oncomplete(t)},onkeydown:function(t){switch(t.which||t.keyCode){case 13:this.options.toggleControlsOnReturn&&(this.preventDefault(t),this.toggleControls());break;case 27:this.options.closeOnEscape&&(this.close(),t.stopImmediatePropagation());break;case 32:this.options.toggleSlideshowOnSpace&&(this.preventDefault(t),this.toggleSlideshow());break;case 37:this.options.enableKeyboardNavigation&&(this.preventDefault(t),this.prev());break;case 39:this.options.enableKeyboardNavigation&&(this.preventDefault(t),this.next())}},handleClick:function(e){function i(e){return t(n).hasClass(e)||t(o).hasClass(e)}var s=this.options,n=e.target||e.srcElement,o=n.parentNode;i(s.toggleClass)?(this.preventDefault(e),this.toggleControls()):i(s.prevClass)?(this.preventDefault(e),this.prev()):i(s.nextClass)?(this.preventDefault(e),this.next()):i(s.closeClass)?(this.preventDefault(e),this.close()):i(s.playPauseClass)?(this.preventDefault(e),this.toggleSlideshow()):o===this.slidesContainer[0]?s.closeOnSlideClick?(this.preventDefault(e),this.close()):s.toggleControlsOnSlideClick&&(this.preventDefault(e),this.toggleControls()):o.parentNode&&o.parentNode===this.slidesContainer[0]&&s.toggleControlsOnSlideClick&&(this.preventDefault(e),this.toggleControls())},onclick:function(t){if(!(this.options.emulateTouchEvents&&this.touchDelta&&(Math.abs(this.touchDelta.x)>20||Math.abs(this.touchDelta.y)>20)))return this.handleClick(t);delete this.touchDelta},updateEdgeClasses:function(t){t?this.container.removeClass(this.options.leftEdgeClass):this.container.addClass(this.options.leftEdgeClass),t===this.num-1?this.container.addClass(this.options.rightEdgeClass):this.container.removeClass(this.options.rightEdgeClass)},handleSlide:function(t){this.options.continuous||this.updateEdgeClasses(t),this.loadElements(t),this.options.unloadElements&&this.unloadElements(t),this.setTitle(t)},onslide:function(t){this.index=t,this.handleSlide(t),this.setTimeout(this.options.onslide,[t,this.slides[t]])},setTitle:function(t){var e=this.slides[t].firstChild,i=e.title||e.alt,s=this.titleElement;s.length&&(this.titleElement.empty(),i&&s[0].appendChild(document.createTextNode(i)))},setTimeout:function(t,e,i){var s=this;return t&&window.setTimeout(function(){t.apply(s,e||[])},i||0)},imageFactory:function(e,i){function s(e){if(!n){if(e={type:e.type,target:o},!o.parentNode)return l.setTimeout(s,[e]);n=!0,t(r).off("load error",s),d&&"load"===e.type&&(o.style.background='url("'+h+'") center no-repeat',o.style.backgroundSize=d),i(e)}}var n,o,a,l=this,r=this.imagePrototype.cloneNode(!1),h=e,d=this.options.stretchImages;return"string"!=typeof h&&(h=this.getItemProperty(e,this.options.urlProperty),a=this.getItemProperty(e,this.options.titleProperty)),!0===d&&(d="contain"),(d=this.support.backgroundSize&&this.support.backgroundSize[d]&&d)?o=this.elementPrototype.cloneNode(!1):(o=r,r.draggable=!1),a&&(o.title=a),t(r).on("load error",s),r.src=h,o},createElement:function(e,i){var s=e&&this.getItemProperty(e,this.options.typeProperty),n=s&&this[s.split("/")[0]+"Factory"]||this.imageFactory,o=e&&n.call(this,e,i),a=this.getItemProperty(e,this.options.srcsetProperty);return o||(o=this.elementPrototype.cloneNode(!1),this.setTimeout(i,[{type:"error",target:o}])),a&&o.setAttribute("srcset",a),t(o).addClass(this.options.slideContentClass),o},loadElement:function(e){this.elements[e]||(this.slides[e].firstChild?this.elements[e]=t(this.slides[e]).hasClass(this.options.slideErrorClass)?3:2:(this.elements[e]=1,t(this.slides[e]).addClass(this.options.slideLoadingClass),this.slides[e].appendChild(this.createElement(this.list[e],this.proxyListener))))},loadElements:function(t){var e,i=Math.min(this.num,2*this.options.preloadRange+1),s=t;for(e=0;e<i;e+=1)s+=e*(e%2==0?-1:1),s=this.circle(s),this.loadElement(s)},unloadElements:function(t){var e,i;for(e in this.elements)this.elements.hasOwnProperty(e)&&(i=Math.abs(t-e))>this.options.preloadRange&&i+this.options.preloadRange<this.num&&(this.unloadSlide(e),delete this.elements[e])},addSlide:function(t){var e=this.slidePrototype.cloneNode(!1);e.setAttribute("data-index",t),this.slidesContainer[0].appendChild(e),this.slides.push(e)},positionSlide:function(t){var e=this.slides[t];e.style.width=this.slideWidth+"px",this.support.transform&&(e.style.left=t*-this.slideWidth+"px",this.move(t,this.index>t?-this.slideWidth:this.index<t?this.slideWidth:0,0))},initSlides:function(e){var i,s;for(e||(this.positions=[],this.positions.length=this.num,this.elements={},this.imagePrototype=document.createElement("img"),this.elementPrototype=document.createElement("div"),this.slidePrototype=document.createElement("div"),t(this.slidePrototype).addClass(this.options.slideClass),this.slides=this.slidesContainer[0].children,i=this.options.clearSlides||this.slides.length!==this.num),this.slideWidth=this.container[0].offsetWidth,this.slideHeight=this.container[0].offsetHeight,this.slidesContainer[0].style.width=this.num*this.slideWidth+"px",i&&this.resetSlides(),s=0;s<this.num;s+=1)i&&this.addSlide(s),this.positionSlide(s);this.options.continuous&&this.support.transform&&(this.move(this.circle(this.index-1),-this.slideWidth,0),this.move(this.circle(this.index+1),this.slideWidth,0)),this.support.transform||(this.slidesContainer[0].style.left=this.index*-this.slideWidth+"px")},unloadSlide:function(t){var e,i;null!==(i=(e=this.slides[t]).firstChild)&&e.removeChild(i)},unloadAllSlides:function(){var t,e;for(t=0,e=this.slides.length;t<e;t++)this.unloadSlide(t)},toggleControls:function(){var t=this.options.controlsClass;this.container.hasClass(t)?this.container.removeClass(t):this.container.addClass(t)},toggleSlideshow:function(){this.interval?this.pause():this.play()},getNodeIndex:function(t){return parseInt(t.getAttribute("data-index"),10)},getNestedProperty:function(t,e){return e.replace(/\[(?:'([^']+)'|"([^"]+)"|(\d+))\]|(?:(?:^|\.)([^\.\[]+))/g,function(e,i,s,n,o){var a=o||i||s||n&&parseInt(n,10);e&&t&&(t=t[a])}),t},getDataProperty:function(e,i){var s,n;if(e.dataset?(s=i.replace(/-([a-z])/g,function(t,e){return e.toUpperCase()}),n=e.dataset[s]):e.getAttribute&&(n=e.getAttribute("data-"+i.replace(/([A-Z])/g,"-$1").toLowerCase())),"string"==typeof n){if(/^(true|false|null|-?\d+(\.\d+)?|\{[\s\S]*\}|\[[\s\S]*\])$/.test(n))try{return t.parseJSON(n)}catch(t){}return n}},getItemProperty:function(t,e){var i=this.getDataProperty(t,e);return void 0===i&&(i=t[e]),void 0===i&&(i=this.getNestedProperty(t,e)),i},initStartIndex:function(){var t,e=this.options.index,i=this.options.urlProperty;if(e&&"number"!=typeof e)for(t=0;t<this.num;t+=1)if(this.list[t]===e||this.getItemProperty(this.list[t],i)===this.getItemProperty(e,i)){e=t;break}this.index=this.circle(parseInt(e,10)||0)},initEventListeners:function(){function e(t){var e=i.support.transition&&i.support.transition.end===t.type?"transitionend":t.type;i["on"+e](t)}var i=this,s=this.slidesContainer;t(window).on("resize",e),t(document.body).on("keydown",e),this.container.on("click",e),this.support.touch?s.on("touchstart touchmove touchend touchcancel",e):this.options.emulateTouchEvents&&this.support.transition&&s.on("mousedown mousemove mouseup mouseout",e),this.support.transition&&s.on(this.support.transition.end,e),this.proxyListener=e},destroyEventListeners:function(){var e=this.slidesContainer,i=this.proxyListener;t(window).off("resize",i),t(document.body).off("keydown",i),this.container.off("click",i),this.support.touch?e.off("touchstart touchmove touchend touchcancel",i):this.options.emulateTouchEvents&&this.support.transition&&e.off("mousedown mousemove mouseup mouseout",i),this.support.transition&&e.off(this.support.transition.end,i)},handleOpen:function(){this.options.onopened&&this.options.onopened.call(this)},initWidget:function(){function e(t){t.target===i.container[0]&&(i.container.off(i.support.transition.end,e),i.handleOpen())}var i=this;return this.container=t(this.options.container),this.container.length?(this.slidesContainer=this.container.find(this.options.slidesContainer).first(),this.slidesContainer.length?(this.titleElement=this.container.find(this.options.titleElement).first(),1===this.num&&this.container.addClass(this.options.singleClass),this.options.onopen&&this.options.onopen.call(this),this.support.transition&&this.options.displayTransition?this.container.on(this.support.transition.end,e):this.handleOpen(),this.options.hidePageScrollbars&&(this.bodyOverflowStyle=document.body.style.overflow,document.body.style.overflow="hidden"),this.container[0].style.display="block",this.initSlides(),void this.container.addClass(this.options.displayClass)):(this.console.log("blueimp Gallery: Slides container not found.",this.options.slidesContainer),!1)):(this.console.log("blueimp Gallery: Widget container not found.",this.options.container),!1)},initOptions:function(e){this.options=t.extend({},this.options),(e&&e.carousel||this.options.carousel&&(!e||!1!==e.carousel))&&t.extend(this.options,this.carouselOptions),t.extend(this.options,e),this.num<3&&(this.options.continuous=!!this.options.continuous&&null),this.support.transition||(this.options.emulateTouchEvents=!1),this.options.event&&this.preventDefault(this.options.event)}}),e}),function(t){"use strict";"function"==typeof define&&define.amd?define(["./blueimp-helper","./blueimp-gallery"],t):t(window.blueimp.helper||window.jQuery,window.blueimp.Gallery)}(function(t,e){"use strict";t.extend(e.prototype.options,{fullScreen:!1});var i=e.prototype.initialize,s=e.prototype.close;return t.extend(e.prototype,{getFullScreenElement:function(){return document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement},requestFullScreen:function(t){t.requestFullscreen?t.requestFullscreen():t.webkitRequestFullscreen?t.webkitRequestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.msRequestFullscreen&&t.msRequestFullscreen()},exitFullScreen:function(){document.exitFullscreen?document.exitFullscreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.msExitFullscreen&&document.msExitFullscreen()},initialize:function(){i.call(this),this.options.fullScreen&&!this.getFullScreenElement()&&this.requestFullScreen(this.container[0])},close:function(){this.getFullScreenElement()===this.container[0]&&this.exitFullScreen(),s.call(this)}}),e}),function(t){"use strict";"function"==typeof define&&define.amd?define(["./blueimp-helper","./blueimp-gallery"],t):t(window.blueimp.helper||window.jQuery,window.blueimp.Gallery)}(function(t,e){"use strict";t.extend(e.prototype.options,{indicatorContainer:"ol",activeIndicatorClass:"active",thumbnailProperty:"thumbnail",thumbnailIndicators:!0});var i=e.prototype.initSlides,s=e.prototype.addSlide,n=e.prototype.resetSlides,o=e.prototype.handleClick,a=e.prototype.handleSlide,l=e.prototype.handleClose;return t.extend(e.prototype,{createIndicator:function(e){var i,s,n=this.indicatorPrototype.cloneNode(!1),o=this.getItemProperty(e,this.options.titleProperty),a=this.options.thumbnailProperty;return this.options.thumbnailIndicators&&(a&&(i=this.getItemProperty(e,a)),void 0===i&&(s=e.getElementsByTagName&&t(e).find("img")[0])&&(i=s.src),i&&(n.style.backgroundImage='url("'+i+'")')),o&&(n.title=o),n},addIndicator:function(t){if(this.indicatorContainer.length){var e=this.createIndicator(this.list[t]);e.setAttribute("data-index",t),this.indicatorContainer[0].appendChild(e),this.indicators.push(e)}},setActiveIndicator:function(e){this.indicators&&(this.activeIndicator&&this.activeIndicator.removeClass(this.options.activeIndicatorClass),this.activeIndicator=t(this.indicators[e]),this.activeIndicator.addClass(this.options.activeIndicatorClass))},initSlides:function(t){t||(this.indicatorContainer=this.container.find(this.options.indicatorContainer),this.indicatorContainer.length&&(this.indicatorPrototype=document.createElement("li"),this.indicators=this.indicatorContainer[0].children)),i.call(this,t)},addSlide:function(t){s.call(this,t),this.addIndicator(t)},resetSlides:function(){n.call(this),this.indicatorContainer.empty(),this.indicators=[]},handleClick:function(t){var e=t.target||t.srcElement,i=e.parentNode;if(i===this.indicatorContainer[0])this.preventDefault(t),this.slide(this.getNodeIndex(e));else{if(i.parentNode!==this.indicatorContainer[0])return o.call(this,t);this.preventDefault(t),this.slide(this.getNodeIndex(i))}},handleSlide:function(t){a.call(this,t),this.setActiveIndicator(t)},handleClose:function(){this.activeIndicator&&this.activeIndicator.removeClass(this.options.activeIndicatorClass),l.call(this)}}),e}),function(t){"use strict";"function"==typeof define&&define.amd?define(["./blueimp-helper","./blueimp-gallery"],t):t(window.blueimp.helper||window.jQuery,window.blueimp.Gallery)}(function(t,e){"use strict";t.extend(e.prototype.options,{videoContentClass:"video-content",videoLoadingClass:"video-loading",videoPlayingClass:"video-playing",videoPosterProperty:"poster",videoSourcesProperty:"sources"});var i=e.prototype.handleSlide;return t.extend(e.prototype,{handleSlide:function(t){i.call(this,t),this.playingVideo&&this.playingVideo.pause()},videoFactory:function(e,i,s){var n,o,a,l,r,h=this,d=this.options,c=this.elementPrototype.cloneNode(!1),u=t(c),p=[{type:"error",target:c}],m=s||document.createElement("video"),y=this.getItemProperty(e,d.urlProperty),f=this.getItemProperty(e,d.typeProperty),g=this.getItemProperty(e,d.titleProperty),v=this.getItemProperty(e,d.videoPosterProperty),C=this.getItemProperty(e,d.videoSourcesProperty);if(u.addClass(d.videoContentClass),g&&(c.title=g),m.canPlayType)if(y&&f&&m.canPlayType(f))m.src=y;else if(C)for(;C.length;)if(o=C.shift(),y=this.getItemProperty(o,d.urlProperty),f=this.getItemProperty(o,d.typeProperty),y&&f&&m.canPlayType(f)){m.src=y;break}return v&&(m.poster=v,n=this.imagePrototype.cloneNode(!1),t(n).addClass(d.toggleClass),n.src=v,n.draggable=!1,c.appendChild(n)),(a=document.createElement("a")).setAttribute("target","_blank"),s||a.setAttribute("download",g),a.href=y,m.src&&(m.controls=!0,(s||t(m)).on("error",function(){h.setTimeout(i,p)}).on("pause",function(){m.seeking||(l=!1,u.removeClass(h.options.videoLoadingClass).removeClass(h.options.videoPlayingClass),r&&h.container.addClass(h.options.controlsClass),delete h.playingVideo,h.interval&&h.play())}).on("playing",function(){l=!1,u.removeClass(h.options.videoLoadingClass).addClass(h.options.videoPlayingClass),h.container.hasClass(h.options.controlsClass)?(r=!0,h.container.removeClass(h.options.controlsClass)):r=!1}).on("play",function(){window.clearTimeout(h.timeout),l=!0,u.addClass(h.options.videoLoadingClass),h.playingVideo=m}),t(a).on("click",function(t){h.preventDefault(t),l?m.pause():m.play()}),c.appendChild(s&&s.element||m)),c.appendChild(a),this.setTimeout(i,[{type:"load",target:c}]),c}}),e}),function(t){"use strict";"function"==typeof define&&define.amd?define(["./blueimp-helper","./blueimp-gallery-video"],t):t(window.blueimp.helper||window.jQuery,window.blueimp.Gallery)}(function(t,e){"use strict";if(!window.postMessage)return e;t.extend(e.prototype.options,{vimeoVideoIdProperty:"vimeo",vimeoPlayerUrl:"//player.vimeo.com/video/VIDEO_ID?api=1&player_id=PLAYER_ID",vimeoPlayerIdPrefix:"vimeo-player-",vimeoClickToPlay:!0});var i=e.prototype.textFactory||e.prototype.imageFactory,s=function(t,e,i,s){this.url=t,this.videoId=e,this.playerId=i,this.clickToPlay=s,this.element=document.createElement("div"),this.listeners={}},n=0;return t.extend(s.prototype,{canPlayType:function(){return!0},on:function(t,e){return this.listeners[t]=e,this},loadAPI:function(){function e(){!s&&n.playOnReady&&n.play(),s=!0}for(var i,s,n=this,o="//f.vimeocdn.com/js/froogaloop2.min.js",a=document.getElementsByTagName("script"),l=a.length;l;)if(l-=1,a[l].src===o){i=a[l];break}i||((i=document.createElement("script")).src=o),t(i).on("load",e),a[0].parentNode.insertBefore(i,a[0]),/loaded|complete/.test(i.readyState)&&e()},onReady:function(){var t=this;this.ready=!0,this.player.addEvent("play",function(){t.hasPlayed=!0,t.onPlaying()}),this.player.addEvent("pause",function(){t.onPause()}),this.player.addEvent("finish",function(){t.onPause()}),this.playOnReady&&this.play()},onPlaying:function(){this.playStatus<2&&(this.listeners.playing(),this.playStatus=2)},onPause:function(){this.listeners.pause(),delete this.playStatus},insertIframe:function(){var t=document.createElement("iframe");t.src=this.url.replace("VIDEO_ID",this.videoId).replace("PLAYER_ID",this.playerId),t.id=this.playerId,this.element.parentNode.replaceChild(t,this.element),this.element=t},play:function(){var t=this;this.playStatus||(this.listeners.play(),this.playStatus=1),this.ready?!this.hasPlayed&&(this.clickToPlay||window.navigator&&/iP(hone|od|ad)/.test(window.navigator.platform))?this.onPlaying():this.player.api("play"):(this.playOnReady=!0,window.$f?this.player||(this.insertIframe(),this.player=$f(this.element),this.player.addEvent("ready",function(){t.onReady()})):this.loadAPI())},pause:function(){this.ready?this.player.api("pause"):this.playStatus&&(delete this.playOnReady,this.listeners.pause(),delete this.playStatus)}}),t.extend(e.prototype,{VimeoPlayer:s,textFactory:function(t,e){var o=this.options,a=this.getItemProperty(t,o.vimeoVideoIdProperty);return a?(void 0===this.getItemProperty(t,o.urlProperty)&&(t[o.urlProperty]="//vimeo.com/"+a),n+=1,this.videoFactory(t,e,new s(o.vimeoPlayerUrl,a,o.vimeoPlayerIdPrefix+n,o.vimeoClickToPlay))):i.call(this,t,e)}}),e}),function(t){"use strict";"function"==typeof define&&define.amd?define(["./blueimp-helper","./blueimp-gallery-video"],t):t(window.blueimp.helper||window.jQuery,window.blueimp.Gallery)}(function(t,e){"use strict";if(!window.postMessage)return e;t.extend(e.prototype.options,{youTubeVideoIdProperty:"youtube",youTubePlayerVars:{wmode:"transparent"},youTubeClickToPlay:!0});var i=e.prototype.textFactory||e.prototype.imageFactory,s=function(t,e,i){this.videoId=t,this.playerVars=e,this.clickToPlay=i,this.element=document.createElement("div"),this.listeners={}};return t.extend(s.prototype,{canPlayType:function(){return!0},on:function(t,e){return this.listeners[t]=e,this},loadAPI:function(){var t,e=this,i=window.onYouTubeIframeAPIReady,s="//www.youtube.com/iframe_api",n=document.getElementsByTagName("script"),o=n.length;for(window.onYouTubeIframeAPIReady=function(){i&&i.apply(this),e.playOnReady&&e.play()};o;)if(o-=1,n[o].src===s)return;(t=document.createElement("script")).src=s,n[0].parentNode.insertBefore(t,n[0])},onReady:function(){this.ready=!0,this.playOnReady&&this.play()},onPlaying:function(){this.playStatus<2&&(this.listeners.playing(),this.playStatus=2)},onPause:function(){e.prototype.setTimeout.call(this,this.checkSeek,null,2e3)},checkSeek:function(){this.stateChange!==YT.PlayerState.PAUSED&&this.stateChange!==YT.PlayerState.ENDED||(this.listeners.pause(),delete this.playStatus)},onStateChange:function(t){switch(t.data){case YT.PlayerState.PLAYING:this.hasPlayed=!0,this.onPlaying();break;case YT.PlayerState.PAUSED:case YT.PlayerState.ENDED:this.onPause()}this.stateChange=t.data},onError:function(t){this.listeners.error(t)},play:function(){var t=this;this.playStatus||(this.listeners.play(),this.playStatus=1),this.ready?!this.hasPlayed&&(this.clickToPlay||window.navigator&&/iP(hone|od|ad)/.test(window.navigator.platform))?this.onPlaying():this.player.playVideo():(this.playOnReady=!0,window.YT&&YT.Player?this.player||(this.player=new YT.Player(this.element,{videoId:this.videoId,playerVars:this.playerVars,events:{onReady:function(){t.onReady()},onStateChange:function(e){t.onStateChange(e)},onError:function(e){t.onError(e)}}})):this.loadAPI())},pause:function(){this.ready?this.player.pauseVideo():this.playStatus&&(delete this.playOnReady,this.listeners.pause(),delete this.playStatus)}}),t.extend(e.prototype,{YouTubePlayer:s,textFactory:function(t,e){var n=this.options,o=this.getItemProperty(t,n.youTubeVideoIdProperty);return o?(void 0===this.getItemProperty(t,n.urlProperty)&&(t[n.urlProperty]="//www.youtube.com/watch?v="+o),void 0===this.getItemProperty(t,n.videoPosterProperty)&&(t[n.videoPosterProperty]="//img.youtube.com/vi/"+o+"/maxresdefault.jpg"),this.videoFactory(t,e,new s(o,n.youTubePlayerVars,n.youTubeClickToPlay))):i.call(this,t,e)}}),e}),function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery","./blueimp-gallery"],t):t(window.jQuery,window.blueimp.Gallery)}(function(t,e){"use strict";t(document).on("click","[data-gallery]",function(i){var s=t(this).data("gallery"),n=t(s),o=n.length&&n||t(e.prototype.options.container),a={onopen:function(){o.data("gallery",this).trigger("open")},onopened:function(){o.trigger("opened")},onslide:function(){o.trigger("slide",arguments)},onslideend:function(){o.trigger("slideend",arguments)},onslidecomplete:function(){o.trigger("slidecomplete",arguments)},onclose:function(){o.trigger("close")},onclosed:function(){o.trigger("closed").removeData("gallery")}},l=t.extend(o.data(),{container:o[0],index:this,event:i},a),r=t('[data-gallery="'+s+'"]');return l.filter&&(r=r.filter(l.filter)),new e(r,l)})});
|
|
//# sourceMappingURL=jquery.blueimp-gallery.min.js.map
|
|
!function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery","./blueimp-gallery"],t):t(window.jQuery,window.blueimp.Gallery)}(function(t,o){"use strict";t.extend(o.prototype.options,{useBootstrapModal:!0});var e=o.prototype.close,n=o.prototype.imageFactory,i=o.prototype.videoFactory,r=o.prototype.textFactory;t.extend(o.prototype,{modalFactory:function(t,o,e,n){if(!this.options.useBootstrapModal||e)return n.call(this,t,o,e);var i=this,r=this.container.children(".modal"),a=r.clone().show().on("click",function(t){(t.target===a[0]||t.target===a.children()[0])&&(t.preventDefault(),t.stopPropagation(),i.close())}),c=n.call(this,t,function(t){o({type:t.type,target:a[0]}),a.addClass("in")},e);return a.find(".modal-title").text(c.title||String.fromCharCode(160)),a.find(".modal-body").append(c),a[0]},imageFactory:function(t,o,e){return this.modalFactory(t,o,e,n)},videoFactory:function(t,o,e){return this.modalFactory(t,o,e,i)},textFactory:function(t,o,e){return this.modalFactory(t,o,e,r)},close:function(){this.container.find(".modal").removeClass("in"),e.call(this)}})});
|
|
//# sourceMappingURL=bootstrap-image-gallery.min.js.map
|
|
//! moment.js
|
|
//! version : 2.19.2
|
|
//! authors : Tim Wood, Iskren Chernev, Moment.js contributors
|
|
//! license : MIT
|
|
//! momentjs.com
|
|
|
|
;(function (global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
global.moment = factory()
|
|
}(this, (function () { 'use strict';
|
|
|
|
var hookCallback;
|
|
|
|
function hooks () {
|
|
return hookCallback.apply(null, arguments);
|
|
}
|
|
|
|
// This is done to register the method called with moment()
|
|
// without creating circular dependencies.
|
|
function setHookCallback (callback) {
|
|
hookCallback = callback;
|
|
}
|
|
|
|
function isArray(input) {
|
|
return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
|
|
}
|
|
|
|
function isObject(input) {
|
|
// IE8 will treat undefined and null as object if it wasn't for
|
|
// input != null
|
|
return input != null && Object.prototype.toString.call(input) === '[object Object]';
|
|
}
|
|
|
|
function isObjectEmpty(obj) {
|
|
if (Object.getOwnPropertyNames) {
|
|
return (Object.getOwnPropertyNames(obj).length === 0);
|
|
} else {
|
|
var k;
|
|
for (k in obj) {
|
|
if (obj.hasOwnProperty(k)) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function isUndefined(input) {
|
|
return input === void 0;
|
|
}
|
|
|
|
function isNumber(input) {
|
|
return typeof input === 'number' || Object.prototype.toString.call(input) === '[object Number]';
|
|
}
|
|
|
|
function isDate(input) {
|
|
return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
|
|
}
|
|
|
|
function map(arr, fn) {
|
|
var res = [], i;
|
|
for (i = 0; i < arr.length; ++i) {
|
|
res.push(fn(arr[i], i));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
function hasOwnProp(a, b) {
|
|
return Object.prototype.hasOwnProperty.call(a, b);
|
|
}
|
|
|
|
function extend(a, b) {
|
|
for (var i in b) {
|
|
if (hasOwnProp(b, i)) {
|
|
a[i] = b[i];
|
|
}
|
|
}
|
|
|
|
if (hasOwnProp(b, 'toString')) {
|
|
a.toString = b.toString;
|
|
}
|
|
|
|
if (hasOwnProp(b, 'valueOf')) {
|
|
a.valueOf = b.valueOf;
|
|
}
|
|
|
|
return a;
|
|
}
|
|
|
|
function createUTC (input, format, locale, strict) {
|
|
return createLocalOrUTC(input, format, locale, strict, true).utc();
|
|
}
|
|
|
|
function defaultParsingFlags() {
|
|
// We need to deep clone this object.
|
|
return {
|
|
empty : false,
|
|
unusedTokens : [],
|
|
unusedInput : [],
|
|
overflow : -2,
|
|
charsLeftOver : 0,
|
|
nullInput : false,
|
|
invalidMonth : null,
|
|
invalidFormat : false,
|
|
userInvalidated : false,
|
|
iso : false,
|
|
parsedDateParts : [],
|
|
meridiem : null,
|
|
rfc2822 : false,
|
|
weekdayMismatch : false
|
|
};
|
|
}
|
|
|
|
function getParsingFlags(m) {
|
|
if (m._pf == null) {
|
|
m._pf = defaultParsingFlags();
|
|
}
|
|
return m._pf;
|
|
}
|
|
|
|
var some;
|
|
if (Array.prototype.some) {
|
|
some = Array.prototype.some;
|
|
} else {
|
|
some = function (fun) {
|
|
var t = Object(this);
|
|
var len = t.length >>> 0;
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
if (i in t && fun.call(this, t[i], i, t)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
};
|
|
}
|
|
|
|
function isValid(m) {
|
|
if (m._isValid == null) {
|
|
var flags = getParsingFlags(m);
|
|
var parsedParts = some.call(flags.parsedDateParts, function (i) {
|
|
return i != null;
|
|
});
|
|
var isNowValid = !isNaN(m._d.getTime()) &&
|
|
flags.overflow < 0 &&
|
|
!flags.empty &&
|
|
!flags.invalidMonth &&
|
|
!flags.invalidWeekday &&
|
|
!flags.weekdayMismatch &&
|
|
!flags.nullInput &&
|
|
!flags.invalidFormat &&
|
|
!flags.userInvalidated &&
|
|
(!flags.meridiem || (flags.meridiem && parsedParts));
|
|
|
|
if (m._strict) {
|
|
isNowValid = isNowValid &&
|
|
flags.charsLeftOver === 0 &&
|
|
flags.unusedTokens.length === 0 &&
|
|
flags.bigHour === undefined;
|
|
}
|
|
|
|
if (Object.isFrozen == null || !Object.isFrozen(m)) {
|
|
m._isValid = isNowValid;
|
|
}
|
|
else {
|
|
return isNowValid;
|
|
}
|
|
}
|
|
return m._isValid;
|
|
}
|
|
|
|
function createInvalid (flags) {
|
|
var m = createUTC(NaN);
|
|
if (flags != null) {
|
|
extend(getParsingFlags(m), flags);
|
|
}
|
|
else {
|
|
getParsingFlags(m).userInvalidated = true;
|
|
}
|
|
|
|
return m;
|
|
}
|
|
|
|
// Plugins that add properties should also add the key here (null value),
|
|
// so we can properly clone ourselves.
|
|
var momentProperties = hooks.momentProperties = [];
|
|
|
|
function copyConfig(to, from) {
|
|
var i, prop, val;
|
|
|
|
if (!isUndefined(from._isAMomentObject)) {
|
|
to._isAMomentObject = from._isAMomentObject;
|
|
}
|
|
if (!isUndefined(from._i)) {
|
|
to._i = from._i;
|
|
}
|
|
if (!isUndefined(from._f)) {
|
|
to._f = from._f;
|
|
}
|
|
if (!isUndefined(from._l)) {
|
|
to._l = from._l;
|
|
}
|
|
if (!isUndefined(from._strict)) {
|
|
to._strict = from._strict;
|
|
}
|
|
if (!isUndefined(from._tzm)) {
|
|
to._tzm = from._tzm;
|
|
}
|
|
if (!isUndefined(from._isUTC)) {
|
|
to._isUTC = from._isUTC;
|
|
}
|
|
if (!isUndefined(from._offset)) {
|
|
to._offset = from._offset;
|
|
}
|
|
if (!isUndefined(from._pf)) {
|
|
to._pf = getParsingFlags(from);
|
|
}
|
|
if (!isUndefined(from._locale)) {
|
|
to._locale = from._locale;
|
|
}
|
|
|
|
if (momentProperties.length > 0) {
|
|
for (i = 0; i < momentProperties.length; i++) {
|
|
prop = momentProperties[i];
|
|
val = from[prop];
|
|
if (!isUndefined(val)) {
|
|
to[prop] = val;
|
|
}
|
|
}
|
|
}
|
|
|
|
return to;
|
|
}
|
|
|
|
var updateInProgress = false;
|
|
|
|
// Moment prototype object
|
|
function Moment(config) {
|
|
copyConfig(this, config);
|
|
this._d = new Date(config._d != null ? config._d.getTime() : NaN);
|
|
if (!this.isValid()) {
|
|
this._d = new Date(NaN);
|
|
}
|
|
// Prevent infinite loop in case updateOffset creates new moment
|
|
// objects.
|
|
if (updateInProgress === false) {
|
|
updateInProgress = true;
|
|
hooks.updateOffset(this);
|
|
updateInProgress = false;
|
|
}
|
|
}
|
|
|
|
function isMoment (obj) {
|
|
return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
|
|
}
|
|
|
|
function absFloor (number) {
|
|
if (number < 0) {
|
|
// -0 -> 0
|
|
return Math.ceil(number) || 0;
|
|
} else {
|
|
return Math.floor(number);
|
|
}
|
|
}
|
|
|
|
function toInt(argumentForCoercion) {
|
|
var coercedNumber = +argumentForCoercion,
|
|
value = 0;
|
|
|
|
if (coercedNumber !== 0 && isFinite(coercedNumber)) {
|
|
value = absFloor(coercedNumber);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
// compare two arrays, return the number of differences
|
|
function compareArrays(array1, array2, dontConvert) {
|
|
var len = Math.min(array1.length, array2.length),
|
|
lengthDiff = Math.abs(array1.length - array2.length),
|
|
diffs = 0,
|
|
i;
|
|
for (i = 0; i < len; i++) {
|
|
if ((dontConvert && array1[i] !== array2[i]) ||
|
|
(!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
|
|
diffs++;
|
|
}
|
|
}
|
|
return diffs + lengthDiff;
|
|
}
|
|
|
|
function warn(msg) {
|
|
if (hooks.suppressDeprecationWarnings === false &&
|
|
(typeof console !== 'undefined') && console.warn) {
|
|
console.warn('Deprecation warning: ' + msg);
|
|
}
|
|
}
|
|
|
|
function deprecate(msg, fn) {
|
|
var firstTime = true;
|
|
|
|
return extend(function () {
|
|
if (hooks.deprecationHandler != null) {
|
|
hooks.deprecationHandler(null, msg);
|
|
}
|
|
if (firstTime) {
|
|
var args = [];
|
|
var arg;
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
arg = '';
|
|
if (typeof arguments[i] === 'object') {
|
|
arg += '\n[' + i + '] ';
|
|
for (var key in arguments[0]) {
|
|
arg += key + ': ' + arguments[0][key] + ', ';
|
|
}
|
|
arg = arg.slice(0, -2); // Remove trailing comma and space
|
|
} else {
|
|
arg = arguments[i];
|
|
}
|
|
args.push(arg);
|
|
}
|
|
warn(msg + '\nArguments: ' + Array.prototype.slice.call(args).join('') + '\n' + (new Error()).stack);
|
|
firstTime = false;
|
|
}
|
|
return fn.apply(this, arguments);
|
|
}, fn);
|
|
}
|
|
|
|
var deprecations = {};
|
|
|
|
function deprecateSimple(name, msg) {
|
|
if (hooks.deprecationHandler != null) {
|
|
hooks.deprecationHandler(name, msg);
|
|
}
|
|
if (!deprecations[name]) {
|
|
warn(msg);
|
|
deprecations[name] = true;
|
|
}
|
|
}
|
|
|
|
hooks.suppressDeprecationWarnings = false;
|
|
hooks.deprecationHandler = null;
|
|
|
|
function isFunction(input) {
|
|
return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
|
|
}
|
|
|
|
function set (config) {
|
|
var prop, i;
|
|
for (i in config) {
|
|
prop = config[i];
|
|
if (isFunction(prop)) {
|
|
this[i] = prop;
|
|
} else {
|
|
this['_' + i] = prop;
|
|
}
|
|
}
|
|
this._config = config;
|
|
// Lenient ordinal parsing accepts just a number in addition to
|
|
// number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
|
|
// TODO: Remove "ordinalParse" fallback in next major release.
|
|
this._dayOfMonthOrdinalParseLenient = new RegExp(
|
|
(this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
|
|
'|' + (/\d{1,2}/).source);
|
|
}
|
|
|
|
function mergeConfigs(parentConfig, childConfig) {
|
|
var res = extend({}, parentConfig), prop;
|
|
for (prop in childConfig) {
|
|
if (hasOwnProp(childConfig, prop)) {
|
|
if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
|
|
res[prop] = {};
|
|
extend(res[prop], parentConfig[prop]);
|
|
extend(res[prop], childConfig[prop]);
|
|
} else if (childConfig[prop] != null) {
|
|
res[prop] = childConfig[prop];
|
|
} else {
|
|
delete res[prop];
|
|
}
|
|
}
|
|
}
|
|
for (prop in parentConfig) {
|
|
if (hasOwnProp(parentConfig, prop) &&
|
|
!hasOwnProp(childConfig, prop) &&
|
|
isObject(parentConfig[prop])) {
|
|
// make sure changes to properties don't modify parent config
|
|
res[prop] = extend({}, res[prop]);
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
function Locale(config) {
|
|
if (config != null) {
|
|
this.set(config);
|
|
}
|
|
}
|
|
|
|
var keys;
|
|
|
|
if (Object.keys) {
|
|
keys = Object.keys;
|
|
} else {
|
|
keys = function (obj) {
|
|
var i, res = [];
|
|
for (i in obj) {
|
|
if (hasOwnProp(obj, i)) {
|
|
res.push(i);
|
|
}
|
|
}
|
|
return res;
|
|
};
|
|
}
|
|
|
|
var defaultCalendar = {
|
|
sameDay : '[Today at] LT',
|
|
nextDay : '[Tomorrow at] LT',
|
|
nextWeek : 'dddd [at] LT',
|
|
lastDay : '[Yesterday at] LT',
|
|
lastWeek : '[Last] dddd [at] LT',
|
|
sameElse : 'L'
|
|
};
|
|
|
|
function calendar (key, mom, now) {
|
|
var output = this._calendar[key] || this._calendar['sameElse'];
|
|
return isFunction(output) ? output.call(mom, now) : output;
|
|
}
|
|
|
|
var defaultLongDateFormat = {
|
|
LTS : 'h:mm:ss A',
|
|
LT : 'h:mm A',
|
|
L : 'MM/DD/YYYY',
|
|
LL : 'MMMM D, YYYY',
|
|
LLL : 'MMMM D, YYYY h:mm A',
|
|
LLLL : 'dddd, MMMM D, YYYY h:mm A'
|
|
};
|
|
|
|
function longDateFormat (key) {
|
|
var format = this._longDateFormat[key],
|
|
formatUpper = this._longDateFormat[key.toUpperCase()];
|
|
|
|
if (format || !formatUpper) {
|
|
return format;
|
|
}
|
|
|
|
this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
|
|
return val.slice(1);
|
|
});
|
|
|
|
return this._longDateFormat[key];
|
|
}
|
|
|
|
var defaultInvalidDate = 'Invalid date';
|
|
|
|
function invalidDate () {
|
|
return this._invalidDate;
|
|
}
|
|
|
|
var defaultOrdinal = '%d';
|
|
var defaultDayOfMonthOrdinalParse = /\d{1,2}/;
|
|
|
|
function ordinal (number) {
|
|
return this._ordinal.replace('%d', number);
|
|
}
|
|
|
|
var defaultRelativeTime = {
|
|
future : 'in %s',
|
|
past : '%s ago',
|
|
s : 'a few seconds',
|
|
ss : '%d seconds',
|
|
m : 'a minute',
|
|
mm : '%d minutes',
|
|
h : 'an hour',
|
|
hh : '%d hours',
|
|
d : 'a day',
|
|
dd : '%d days',
|
|
M : 'a month',
|
|
MM : '%d months',
|
|
y : 'a year',
|
|
yy : '%d years'
|
|
};
|
|
|
|
function relativeTime (number, withoutSuffix, string, isFuture) {
|
|
var output = this._relativeTime[string];
|
|
return (isFunction(output)) ?
|
|
output(number, withoutSuffix, string, isFuture) :
|
|
output.replace(/%d/i, number);
|
|
}
|
|
|
|
function pastFuture (diff, output) {
|
|
var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
|
|
return isFunction(format) ? format(output) : format.replace(/%s/i, output);
|
|
}
|
|
|
|
var aliases = {};
|
|
|
|
function addUnitAlias (unit, shorthand) {
|
|
var lowerCase = unit.toLowerCase();
|
|
aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
|
|
}
|
|
|
|
function normalizeUnits(units) {
|
|
return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
|
|
}
|
|
|
|
function normalizeObjectUnits(inputObject) {
|
|
var normalizedInput = {},
|
|
normalizedProp,
|
|
prop;
|
|
|
|
for (prop in inputObject) {
|
|
if (hasOwnProp(inputObject, prop)) {
|
|
normalizedProp = normalizeUnits(prop);
|
|
if (normalizedProp) {
|
|
normalizedInput[normalizedProp] = inputObject[prop];
|
|
}
|
|
}
|
|
}
|
|
|
|
return normalizedInput;
|
|
}
|
|
|
|
var priorities = {};
|
|
|
|
function addUnitPriority(unit, priority) {
|
|
priorities[unit] = priority;
|
|
}
|
|
|
|
function getPrioritizedUnits(unitsObj) {
|
|
var units = [];
|
|
for (var u in unitsObj) {
|
|
units.push({unit: u, priority: priorities[u]});
|
|
}
|
|
units.sort(function (a, b) {
|
|
return a.priority - b.priority;
|
|
});
|
|
return units;
|
|
}
|
|
|
|
function zeroFill(number, targetLength, forceSign) {
|
|
var absNumber = '' + Math.abs(number),
|
|
zerosToFill = targetLength - absNumber.length,
|
|
sign = number >= 0;
|
|
return (sign ? (forceSign ? '+' : '') : '-') +
|
|
Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
|
|
}
|
|
|
|
var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
|
|
|
|
var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
|
|
|
|
var formatFunctions = {};
|
|
|
|
var formatTokenFunctions = {};
|
|
|
|
// token: 'M'
|
|
// padded: ['MM', 2]
|
|
// ordinal: 'Mo'
|
|
// callback: function () { this.month() + 1 }
|
|
function addFormatToken (token, padded, ordinal, callback) {
|
|
var func = callback;
|
|
if (typeof callback === 'string') {
|
|
func = function () {
|
|
return this[callback]();
|
|
};
|
|
}
|
|
if (token) {
|
|
formatTokenFunctions[token] = func;
|
|
}
|
|
if (padded) {
|
|
formatTokenFunctions[padded[0]] = function () {
|
|
return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
|
|
};
|
|
}
|
|
if (ordinal) {
|
|
formatTokenFunctions[ordinal] = function () {
|
|
return this.localeData().ordinal(func.apply(this, arguments), token);
|
|
};
|
|
}
|
|
}
|
|
|
|
function removeFormattingTokens(input) {
|
|
if (input.match(/\[[\s\S]/)) {
|
|
return input.replace(/^\[|\]$/g, '');
|
|
}
|
|
return input.replace(/\\/g, '');
|
|
}
|
|
|
|
function makeFormatFunction(format) {
|
|
var array = format.match(formattingTokens), i, length;
|
|
|
|
for (i = 0, length = array.length; i < length; i++) {
|
|
if (formatTokenFunctions[array[i]]) {
|
|
array[i] = formatTokenFunctions[array[i]];
|
|
} else {
|
|
array[i] = removeFormattingTokens(array[i]);
|
|
}
|
|
}
|
|
|
|
return function (mom) {
|
|
var output = '', i;
|
|
for (i = 0; i < length; i++) {
|
|
output += isFunction(array[i]) ? array[i].call(mom, format) : array[i];
|
|
}
|
|
return output;
|
|
};
|
|
}
|
|
|
|
// format date using native date object
|
|
function formatMoment(m, format) {
|
|
if (!m.isValid()) {
|
|
return m.localeData().invalidDate();
|
|
}
|
|
|
|
format = expandFormat(format, m.localeData());
|
|
formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
|
|
|
|
return formatFunctions[format](m);
|
|
}
|
|
|
|
function expandFormat(format, locale) {
|
|
var i = 5;
|
|
|
|
function replaceLongDateFormatTokens(input) {
|
|
return locale.longDateFormat(input) || input;
|
|
}
|
|
|
|
localFormattingTokens.lastIndex = 0;
|
|
while (i >= 0 && localFormattingTokens.test(format)) {
|
|
format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
|
|
localFormattingTokens.lastIndex = 0;
|
|
i -= 1;
|
|
}
|
|
|
|
return format;
|
|
}
|
|
|
|
var match1 = /\d/; // 0 - 9
|
|
var match2 = /\d\d/; // 00 - 99
|
|
var match3 = /\d{3}/; // 000 - 999
|
|
var match4 = /\d{4}/; // 0000 - 9999
|
|
var match6 = /[+-]?\d{6}/; // -999999 - 999999
|
|
var match1to2 = /\d\d?/; // 0 - 99
|
|
var match3to4 = /\d\d\d\d?/; // 999 - 9999
|
|
var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
|
|
var match1to3 = /\d{1,3}/; // 0 - 999
|
|
var match1to4 = /\d{1,4}/; // 0 - 9999
|
|
var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
|
|
|
|
var matchUnsigned = /\d+/; // 0 - inf
|
|
var matchSigned = /[+-]?\d+/; // -inf - inf
|
|
|
|
var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
|
|
var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
|
|
|
|
var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
|
|
|
|
// any word (or two) characters or numbers including two/three word month in arabic.
|
|
// includes scottish gaelic two word and hyphenated months
|
|
var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
|
|
|
|
|
|
var regexes = {};
|
|
|
|
function addRegexToken (token, regex, strictRegex) {
|
|
regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
|
|
return (isStrict && strictRegex) ? strictRegex : regex;
|
|
};
|
|
}
|
|
|
|
function getParseRegexForToken (token, config) {
|
|
if (!hasOwnProp(regexes, token)) {
|
|
return new RegExp(unescapeFormat(token));
|
|
}
|
|
|
|
return regexes[token](config._strict, config._locale);
|
|
}
|
|
|
|
// Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
|
|
function unescapeFormat(s) {
|
|
return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
|
|
return p1 || p2 || p3 || p4;
|
|
}));
|
|
}
|
|
|
|
function regexEscape(s) {
|
|
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
}
|
|
|
|
var tokens = {};
|
|
|
|
function addParseToken (token, callback) {
|
|
var i, func = callback;
|
|
if (typeof token === 'string') {
|
|
token = [token];
|
|
}
|
|
if (isNumber(callback)) {
|
|
func = function (input, array) {
|
|
array[callback] = toInt(input);
|
|
};
|
|
}
|
|
for (i = 0; i < token.length; i++) {
|
|
tokens[token[i]] = func;
|
|
}
|
|
}
|
|
|
|
function addWeekParseToken (token, callback) {
|
|
addParseToken(token, function (input, array, config, token) {
|
|
config._w = config._w || {};
|
|
callback(input, config._w, config, token);
|
|
});
|
|
}
|
|
|
|
function addTimeToArrayFromToken(token, input, config) {
|
|
if (input != null && hasOwnProp(tokens, token)) {
|
|
tokens[token](input, config._a, config, token);
|
|
}
|
|
}
|
|
|
|
var YEAR = 0;
|
|
var MONTH = 1;
|
|
var DATE = 2;
|
|
var HOUR = 3;
|
|
var MINUTE = 4;
|
|
var SECOND = 5;
|
|
var MILLISECOND = 6;
|
|
var WEEK = 7;
|
|
var WEEKDAY = 8;
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('Y', 0, 0, function () {
|
|
var y = this.year();
|
|
return y <= 9999 ? '' + y : '+' + y;
|
|
});
|
|
|
|
addFormatToken(0, ['YY', 2], 0, function () {
|
|
return this.year() % 100;
|
|
});
|
|
|
|
addFormatToken(0, ['YYYY', 4], 0, 'year');
|
|
addFormatToken(0, ['YYYYY', 5], 0, 'year');
|
|
addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('year', 'y');
|
|
|
|
// PRIORITIES
|
|
|
|
addUnitPriority('year', 1);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('Y', matchSigned);
|
|
addRegexToken('YY', match1to2, match2);
|
|
addRegexToken('YYYY', match1to4, match4);
|
|
addRegexToken('YYYYY', match1to6, match6);
|
|
addRegexToken('YYYYYY', match1to6, match6);
|
|
|
|
addParseToken(['YYYYY', 'YYYYYY'], YEAR);
|
|
addParseToken('YYYY', function (input, array) {
|
|
array[YEAR] = input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
|
|
});
|
|
addParseToken('YY', function (input, array) {
|
|
array[YEAR] = hooks.parseTwoDigitYear(input);
|
|
});
|
|
addParseToken('Y', function (input, array) {
|
|
array[YEAR] = parseInt(input, 10);
|
|
});
|
|
|
|
// HELPERS
|
|
|
|
function daysInYear(year) {
|
|
return isLeapYear(year) ? 366 : 365;
|
|
}
|
|
|
|
function isLeapYear(year) {
|
|
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
}
|
|
|
|
// HOOKS
|
|
|
|
hooks.parseTwoDigitYear = function (input) {
|
|
return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
|
|
};
|
|
|
|
// MOMENTS
|
|
|
|
var getSetYear = makeGetSet('FullYear', true);
|
|
|
|
function getIsLeapYear () {
|
|
return isLeapYear(this.year());
|
|
}
|
|
|
|
function makeGetSet (unit, keepTime) {
|
|
return function (value) {
|
|
if (value != null) {
|
|
set$1(this, unit, value);
|
|
hooks.updateOffset(this, keepTime);
|
|
return this;
|
|
} else {
|
|
return get(this, unit);
|
|
}
|
|
};
|
|
}
|
|
|
|
function get (mom, unit) {
|
|
return mom.isValid() ?
|
|
mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
|
|
}
|
|
|
|
function set$1 (mom, unit, value) {
|
|
if (mom.isValid() && !isNaN(value)) {
|
|
if (unit === 'FullYear' && isLeapYear(mom.year()) && mom.month() === 1 && mom.date() === 29) {
|
|
mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value, mom.month(), daysInMonth(value, mom.month()));
|
|
}
|
|
else {
|
|
mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
|
|
}
|
|
}
|
|
}
|
|
|
|
// MOMENTS
|
|
|
|
function stringGet (units) {
|
|
units = normalizeUnits(units);
|
|
if (isFunction(this[units])) {
|
|
return this[units]();
|
|
}
|
|
return this;
|
|
}
|
|
|
|
|
|
function stringSet (units, value) {
|
|
if (typeof units === 'object') {
|
|
units = normalizeObjectUnits(units);
|
|
var prioritized = getPrioritizedUnits(units);
|
|
for (var i = 0; i < prioritized.length; i++) {
|
|
this[prioritized[i].unit](units[prioritized[i].unit]);
|
|
}
|
|
} else {
|
|
units = normalizeUnits(units);
|
|
if (isFunction(this[units])) {
|
|
return this[units](value);
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
|
|
function mod(n, x) {
|
|
return ((n % x) + x) % x;
|
|
}
|
|
|
|
var indexOf;
|
|
|
|
if (Array.prototype.indexOf) {
|
|
indexOf = Array.prototype.indexOf;
|
|
} else {
|
|
indexOf = function (o) {
|
|
// I know
|
|
var i;
|
|
for (i = 0; i < this.length; ++i) {
|
|
if (this[i] === o) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
};
|
|
}
|
|
|
|
function daysInMonth(year, month) {
|
|
if (isNaN(year) || isNaN(month)) {
|
|
return NaN;
|
|
}
|
|
var modMonth = mod(month, 12);
|
|
year += (month - modMonth) / 12;
|
|
return modMonth === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - modMonth % 7 % 2);
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('M', ['MM', 2], 'Mo', function () {
|
|
return this.month() + 1;
|
|
});
|
|
|
|
addFormatToken('MMM', 0, 0, function (format) {
|
|
return this.localeData().monthsShort(this, format);
|
|
});
|
|
|
|
addFormatToken('MMMM', 0, 0, function (format) {
|
|
return this.localeData().months(this, format);
|
|
});
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('month', 'M');
|
|
|
|
// PRIORITY
|
|
|
|
addUnitPriority('month', 8);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('M', match1to2);
|
|
addRegexToken('MM', match1to2, match2);
|
|
addRegexToken('MMM', function (isStrict, locale) {
|
|
return locale.monthsShortRegex(isStrict);
|
|
});
|
|
addRegexToken('MMMM', function (isStrict, locale) {
|
|
return locale.monthsRegex(isStrict);
|
|
});
|
|
|
|
addParseToken(['M', 'MM'], function (input, array) {
|
|
array[MONTH] = toInt(input) - 1;
|
|
});
|
|
|
|
addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
|
|
var month = config._locale.monthsParse(input, token, config._strict);
|
|
// if we didn't find a month name, mark the date as invalid.
|
|
if (month != null) {
|
|
array[MONTH] = month;
|
|
} else {
|
|
getParsingFlags(config).invalidMonth = input;
|
|
}
|
|
});
|
|
|
|
// LOCALES
|
|
|
|
var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
|
|
var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
|
|
function localeMonths (m, format) {
|
|
if (!m) {
|
|
return isArray(this._months) ? this._months :
|
|
this._months['standalone'];
|
|
}
|
|
return isArray(this._months) ? this._months[m.month()] :
|
|
this._months[(this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'][m.month()];
|
|
}
|
|
|
|
var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
|
|
function localeMonthsShort (m, format) {
|
|
if (!m) {
|
|
return isArray(this._monthsShort) ? this._monthsShort :
|
|
this._monthsShort['standalone'];
|
|
}
|
|
return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
|
|
this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
|
|
}
|
|
|
|
function handleStrictParse(monthName, format, strict) {
|
|
var i, ii, mom, llc = monthName.toLocaleLowerCase();
|
|
if (!this._monthsParse) {
|
|
// this is not used
|
|
this._monthsParse = [];
|
|
this._longMonthsParse = [];
|
|
this._shortMonthsParse = [];
|
|
for (i = 0; i < 12; ++i) {
|
|
mom = createUTC([2000, i]);
|
|
this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
|
|
this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
|
|
}
|
|
}
|
|
|
|
if (strict) {
|
|
if (format === 'MMM') {
|
|
ii = indexOf.call(this._shortMonthsParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
} else {
|
|
ii = indexOf.call(this._longMonthsParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
}
|
|
} else {
|
|
if (format === 'MMM') {
|
|
ii = indexOf.call(this._shortMonthsParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._longMonthsParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
} else {
|
|
ii = indexOf.call(this._longMonthsParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._shortMonthsParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
}
|
|
}
|
|
}
|
|
|
|
function localeMonthsParse (monthName, format, strict) {
|
|
var i, mom, regex;
|
|
|
|
if (this._monthsParseExact) {
|
|
return handleStrictParse.call(this, monthName, format, strict);
|
|
}
|
|
|
|
if (!this._monthsParse) {
|
|
this._monthsParse = [];
|
|
this._longMonthsParse = [];
|
|
this._shortMonthsParse = [];
|
|
}
|
|
|
|
// TODO: add sorting
|
|
// Sorting makes sure if one month (or abbr) is a prefix of another
|
|
// see sorting in computeMonthsParse
|
|
for (i = 0; i < 12; i++) {
|
|
// make the regex if we don't have it already
|
|
mom = createUTC([2000, i]);
|
|
if (strict && !this._longMonthsParse[i]) {
|
|
this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
|
|
this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
|
|
}
|
|
if (!strict && !this._monthsParse[i]) {
|
|
regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
|
|
this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
|
|
}
|
|
// test the regex
|
|
if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
|
|
return i;
|
|
} else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
|
|
return i;
|
|
} else if (!strict && this._monthsParse[i].test(monthName)) {
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
// MOMENTS
|
|
|
|
function setMonth (mom, value) {
|
|
var dayOfMonth;
|
|
|
|
if (!mom.isValid()) {
|
|
// No op
|
|
return mom;
|
|
}
|
|
|
|
if (typeof value === 'string') {
|
|
if (/^\d+$/.test(value)) {
|
|
value = toInt(value);
|
|
} else {
|
|
value = mom.localeData().monthsParse(value);
|
|
// TODO: Another silent failure?
|
|
if (!isNumber(value)) {
|
|
return mom;
|
|
}
|
|
}
|
|
}
|
|
|
|
dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
|
|
mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
|
|
return mom;
|
|
}
|
|
|
|
function getSetMonth (value) {
|
|
if (value != null) {
|
|
setMonth(this, value);
|
|
hooks.updateOffset(this, true);
|
|
return this;
|
|
} else {
|
|
return get(this, 'Month');
|
|
}
|
|
}
|
|
|
|
function getDaysInMonth () {
|
|
return daysInMonth(this.year(), this.month());
|
|
}
|
|
|
|
var defaultMonthsShortRegex = matchWord;
|
|
function monthsShortRegex (isStrict) {
|
|
if (this._monthsParseExact) {
|
|
if (!hasOwnProp(this, '_monthsRegex')) {
|
|
computeMonthsParse.call(this);
|
|
}
|
|
if (isStrict) {
|
|
return this._monthsShortStrictRegex;
|
|
} else {
|
|
return this._monthsShortRegex;
|
|
}
|
|
} else {
|
|
if (!hasOwnProp(this, '_monthsShortRegex')) {
|
|
this._monthsShortRegex = defaultMonthsShortRegex;
|
|
}
|
|
return this._monthsShortStrictRegex && isStrict ?
|
|
this._monthsShortStrictRegex : this._monthsShortRegex;
|
|
}
|
|
}
|
|
|
|
var defaultMonthsRegex = matchWord;
|
|
function monthsRegex (isStrict) {
|
|
if (this._monthsParseExact) {
|
|
if (!hasOwnProp(this, '_monthsRegex')) {
|
|
computeMonthsParse.call(this);
|
|
}
|
|
if (isStrict) {
|
|
return this._monthsStrictRegex;
|
|
} else {
|
|
return this._monthsRegex;
|
|
}
|
|
} else {
|
|
if (!hasOwnProp(this, '_monthsRegex')) {
|
|
this._monthsRegex = defaultMonthsRegex;
|
|
}
|
|
return this._monthsStrictRegex && isStrict ?
|
|
this._monthsStrictRegex : this._monthsRegex;
|
|
}
|
|
}
|
|
|
|
function computeMonthsParse () {
|
|
function cmpLenRev(a, b) {
|
|
return b.length - a.length;
|
|
}
|
|
|
|
var shortPieces = [], longPieces = [], mixedPieces = [],
|
|
i, mom;
|
|
for (i = 0; i < 12; i++) {
|
|
// make the regex if we don't have it already
|
|
mom = createUTC([2000, i]);
|
|
shortPieces.push(this.monthsShort(mom, ''));
|
|
longPieces.push(this.months(mom, ''));
|
|
mixedPieces.push(this.months(mom, ''));
|
|
mixedPieces.push(this.monthsShort(mom, ''));
|
|
}
|
|
// Sorting makes sure if one month (or abbr) is a prefix of another it
|
|
// will match the longer piece.
|
|
shortPieces.sort(cmpLenRev);
|
|
longPieces.sort(cmpLenRev);
|
|
mixedPieces.sort(cmpLenRev);
|
|
for (i = 0; i < 12; i++) {
|
|
shortPieces[i] = regexEscape(shortPieces[i]);
|
|
longPieces[i] = regexEscape(longPieces[i]);
|
|
}
|
|
for (i = 0; i < 24; i++) {
|
|
mixedPieces[i] = regexEscape(mixedPieces[i]);
|
|
}
|
|
|
|
this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
|
|
this._monthsShortRegex = this._monthsRegex;
|
|
this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
|
|
this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
|
|
}
|
|
|
|
function createDate (y, m, d, h, M, s, ms) {
|
|
// can't just apply() to create a date:
|
|
// https://stackoverflow.com/q/181348
|
|
var date = new Date(y, m, d, h, M, s, ms);
|
|
|
|
// the date constructor remaps years 0-99 to 1900-1999
|
|
if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
|
|
date.setFullYear(y);
|
|
}
|
|
return date;
|
|
}
|
|
|
|
function createUTCDate (y) {
|
|
var date = new Date(Date.UTC.apply(null, arguments));
|
|
|
|
// the Date.UTC function remaps years 0-99 to 1900-1999
|
|
if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
|
|
date.setUTCFullYear(y);
|
|
}
|
|
return date;
|
|
}
|
|
|
|
// start-of-first-week - start-of-year
|
|
function firstWeekOffset(year, dow, doy) {
|
|
var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
|
|
fwd = 7 + dow - doy,
|
|
// first-week day local weekday -- which local weekday is fwd
|
|
fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
|
|
|
|
return -fwdlw + fwd - 1;
|
|
}
|
|
|
|
// https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
|
|
function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
|
|
var localWeekday = (7 + weekday - dow) % 7,
|
|
weekOffset = firstWeekOffset(year, dow, doy),
|
|
dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
|
|
resYear, resDayOfYear;
|
|
|
|
if (dayOfYear <= 0) {
|
|
resYear = year - 1;
|
|
resDayOfYear = daysInYear(resYear) + dayOfYear;
|
|
} else if (dayOfYear > daysInYear(year)) {
|
|
resYear = year + 1;
|
|
resDayOfYear = dayOfYear - daysInYear(year);
|
|
} else {
|
|
resYear = year;
|
|
resDayOfYear = dayOfYear;
|
|
}
|
|
|
|
return {
|
|
year: resYear,
|
|
dayOfYear: resDayOfYear
|
|
};
|
|
}
|
|
|
|
function weekOfYear(mom, dow, doy) {
|
|
var weekOffset = firstWeekOffset(mom.year(), dow, doy),
|
|
week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
|
|
resWeek, resYear;
|
|
|
|
if (week < 1) {
|
|
resYear = mom.year() - 1;
|
|
resWeek = week + weeksInYear(resYear, dow, doy);
|
|
} else if (week > weeksInYear(mom.year(), dow, doy)) {
|
|
resWeek = week - weeksInYear(mom.year(), dow, doy);
|
|
resYear = mom.year() + 1;
|
|
} else {
|
|
resYear = mom.year();
|
|
resWeek = week;
|
|
}
|
|
|
|
return {
|
|
week: resWeek,
|
|
year: resYear
|
|
};
|
|
}
|
|
|
|
function weeksInYear(year, dow, doy) {
|
|
var weekOffset = firstWeekOffset(year, dow, doy),
|
|
weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
|
|
return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('w', ['ww', 2], 'wo', 'week');
|
|
addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('week', 'w');
|
|
addUnitAlias('isoWeek', 'W');
|
|
|
|
// PRIORITIES
|
|
|
|
addUnitPriority('week', 5);
|
|
addUnitPriority('isoWeek', 5);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('w', match1to2);
|
|
addRegexToken('ww', match1to2, match2);
|
|
addRegexToken('W', match1to2);
|
|
addRegexToken('WW', match1to2, match2);
|
|
|
|
addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
|
|
week[token.substr(0, 1)] = toInt(input);
|
|
});
|
|
|
|
// HELPERS
|
|
|
|
// LOCALES
|
|
|
|
function localeWeek (mom) {
|
|
return weekOfYear(mom, this._week.dow, this._week.doy).week;
|
|
}
|
|
|
|
var defaultLocaleWeek = {
|
|
dow : 0, // Sunday is the first day of the week.
|
|
doy : 6 // The week that contains Jan 1st is the first week of the year.
|
|
};
|
|
|
|
function localeFirstDayOfWeek () {
|
|
return this._week.dow;
|
|
}
|
|
|
|
function localeFirstDayOfYear () {
|
|
return this._week.doy;
|
|
}
|
|
|
|
// MOMENTS
|
|
|
|
function getSetWeek (input) {
|
|
var week = this.localeData().week(this);
|
|
return input == null ? week : this.add((input - week) * 7, 'd');
|
|
}
|
|
|
|
function getSetISOWeek (input) {
|
|
var week = weekOfYear(this, 1, 4).week;
|
|
return input == null ? week : this.add((input - week) * 7, 'd');
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('d', 0, 'do', 'day');
|
|
|
|
addFormatToken('dd', 0, 0, function (format) {
|
|
return this.localeData().weekdaysMin(this, format);
|
|
});
|
|
|
|
addFormatToken('ddd', 0, 0, function (format) {
|
|
return this.localeData().weekdaysShort(this, format);
|
|
});
|
|
|
|
addFormatToken('dddd', 0, 0, function (format) {
|
|
return this.localeData().weekdays(this, format);
|
|
});
|
|
|
|
addFormatToken('e', 0, 0, 'weekday');
|
|
addFormatToken('E', 0, 0, 'isoWeekday');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('day', 'd');
|
|
addUnitAlias('weekday', 'e');
|
|
addUnitAlias('isoWeekday', 'E');
|
|
|
|
// PRIORITY
|
|
addUnitPriority('day', 11);
|
|
addUnitPriority('weekday', 11);
|
|
addUnitPriority('isoWeekday', 11);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('d', match1to2);
|
|
addRegexToken('e', match1to2);
|
|
addRegexToken('E', match1to2);
|
|
addRegexToken('dd', function (isStrict, locale) {
|
|
return locale.weekdaysMinRegex(isStrict);
|
|
});
|
|
addRegexToken('ddd', function (isStrict, locale) {
|
|
return locale.weekdaysShortRegex(isStrict);
|
|
});
|
|
addRegexToken('dddd', function (isStrict, locale) {
|
|
return locale.weekdaysRegex(isStrict);
|
|
});
|
|
|
|
addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
|
|
var weekday = config._locale.weekdaysParse(input, token, config._strict);
|
|
// if we didn't get a weekday name, mark the date as invalid
|
|
if (weekday != null) {
|
|
week.d = weekday;
|
|
} else {
|
|
getParsingFlags(config).invalidWeekday = input;
|
|
}
|
|
});
|
|
|
|
addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
|
|
week[token] = toInt(input);
|
|
});
|
|
|
|
// HELPERS
|
|
|
|
function parseWeekday(input, locale) {
|
|
if (typeof input !== 'string') {
|
|
return input;
|
|
}
|
|
|
|
if (!isNaN(input)) {
|
|
return parseInt(input, 10);
|
|
}
|
|
|
|
input = locale.weekdaysParse(input);
|
|
if (typeof input === 'number') {
|
|
return input;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function parseIsoWeekday(input, locale) {
|
|
if (typeof input === 'string') {
|
|
return locale.weekdaysParse(input) % 7 || 7;
|
|
}
|
|
return isNaN(input) ? null : input;
|
|
}
|
|
|
|
// LOCALES
|
|
|
|
var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
|
|
function localeWeekdays (m, format) {
|
|
if (!m) {
|
|
return isArray(this._weekdays) ? this._weekdays :
|
|
this._weekdays['standalone'];
|
|
}
|
|
return isArray(this._weekdays) ? this._weekdays[m.day()] :
|
|
this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
|
|
}
|
|
|
|
var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
|
|
function localeWeekdaysShort (m) {
|
|
return (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
|
|
}
|
|
|
|
var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
|
|
function localeWeekdaysMin (m) {
|
|
return (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
|
|
}
|
|
|
|
function handleStrictParse$1(weekdayName, format, strict) {
|
|
var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
|
|
if (!this._weekdaysParse) {
|
|
this._weekdaysParse = [];
|
|
this._shortWeekdaysParse = [];
|
|
this._minWeekdaysParse = [];
|
|
|
|
for (i = 0; i < 7; ++i) {
|
|
mom = createUTC([2000, 1]).day(i);
|
|
this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
|
|
this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
|
|
this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
|
|
}
|
|
}
|
|
|
|
if (strict) {
|
|
if (format === 'dddd') {
|
|
ii = indexOf.call(this._weekdaysParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
} else if (format === 'ddd') {
|
|
ii = indexOf.call(this._shortWeekdaysParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
} else {
|
|
ii = indexOf.call(this._minWeekdaysParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
}
|
|
} else {
|
|
if (format === 'dddd') {
|
|
ii = indexOf.call(this._weekdaysParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._shortWeekdaysParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._minWeekdaysParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
} else if (format === 'ddd') {
|
|
ii = indexOf.call(this._shortWeekdaysParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._weekdaysParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._minWeekdaysParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
} else {
|
|
ii = indexOf.call(this._minWeekdaysParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._weekdaysParse, llc);
|
|
if (ii !== -1) {
|
|
return ii;
|
|
}
|
|
ii = indexOf.call(this._shortWeekdaysParse, llc);
|
|
return ii !== -1 ? ii : null;
|
|
}
|
|
}
|
|
}
|
|
|
|
function localeWeekdaysParse (weekdayName, format, strict) {
|
|
var i, mom, regex;
|
|
|
|
if (this._weekdaysParseExact) {
|
|
return handleStrictParse$1.call(this, weekdayName, format, strict);
|
|
}
|
|
|
|
if (!this._weekdaysParse) {
|
|
this._weekdaysParse = [];
|
|
this._minWeekdaysParse = [];
|
|
this._shortWeekdaysParse = [];
|
|
this._fullWeekdaysParse = [];
|
|
}
|
|
|
|
for (i = 0; i < 7; i++) {
|
|
// make the regex if we don't have it already
|
|
|
|
mom = createUTC([2000, 1]).day(i);
|
|
if (strict && !this._fullWeekdaysParse[i]) {
|
|
this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
|
|
this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
|
|
this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
|
|
}
|
|
if (!this._weekdaysParse[i]) {
|
|
regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
|
|
this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
|
|
}
|
|
// test the regex
|
|
if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
|
|
return i;
|
|
} else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
|
|
return i;
|
|
} else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
|
|
return i;
|
|
} else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
// MOMENTS
|
|
|
|
function getSetDayOfWeek (input) {
|
|
if (!this.isValid()) {
|
|
return input != null ? this : NaN;
|
|
}
|
|
var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
|
|
if (input != null) {
|
|
input = parseWeekday(input, this.localeData());
|
|
return this.add(input - day, 'd');
|
|
} else {
|
|
return day;
|
|
}
|
|
}
|
|
|
|
function getSetLocaleDayOfWeek (input) {
|
|
if (!this.isValid()) {
|
|
return input != null ? this : NaN;
|
|
}
|
|
var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
|
|
return input == null ? weekday : this.add(input - weekday, 'd');
|
|
}
|
|
|
|
function getSetISODayOfWeek (input) {
|
|
if (!this.isValid()) {
|
|
return input != null ? this : NaN;
|
|
}
|
|
|
|
// behaves the same as moment#day except
|
|
// as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
|
|
// as a setter, sunday should belong to the previous week.
|
|
|
|
if (input != null) {
|
|
var weekday = parseIsoWeekday(input, this.localeData());
|
|
return this.day(this.day() % 7 ? weekday : weekday - 7);
|
|
} else {
|
|
return this.day() || 7;
|
|
}
|
|
}
|
|
|
|
var defaultWeekdaysRegex = matchWord;
|
|
function weekdaysRegex (isStrict) {
|
|
if (this._weekdaysParseExact) {
|
|
if (!hasOwnProp(this, '_weekdaysRegex')) {
|
|
computeWeekdaysParse.call(this);
|
|
}
|
|
if (isStrict) {
|
|
return this._weekdaysStrictRegex;
|
|
} else {
|
|
return this._weekdaysRegex;
|
|
}
|
|
} else {
|
|
if (!hasOwnProp(this, '_weekdaysRegex')) {
|
|
this._weekdaysRegex = defaultWeekdaysRegex;
|
|
}
|
|
return this._weekdaysStrictRegex && isStrict ?
|
|
this._weekdaysStrictRegex : this._weekdaysRegex;
|
|
}
|
|
}
|
|
|
|
var defaultWeekdaysShortRegex = matchWord;
|
|
function weekdaysShortRegex (isStrict) {
|
|
if (this._weekdaysParseExact) {
|
|
if (!hasOwnProp(this, '_weekdaysRegex')) {
|
|
computeWeekdaysParse.call(this);
|
|
}
|
|
if (isStrict) {
|
|
return this._weekdaysShortStrictRegex;
|
|
} else {
|
|
return this._weekdaysShortRegex;
|
|
}
|
|
} else {
|
|
if (!hasOwnProp(this, '_weekdaysShortRegex')) {
|
|
this._weekdaysShortRegex = defaultWeekdaysShortRegex;
|
|
}
|
|
return this._weekdaysShortStrictRegex && isStrict ?
|
|
this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
|
|
}
|
|
}
|
|
|
|
var defaultWeekdaysMinRegex = matchWord;
|
|
function weekdaysMinRegex (isStrict) {
|
|
if (this._weekdaysParseExact) {
|
|
if (!hasOwnProp(this, '_weekdaysRegex')) {
|
|
computeWeekdaysParse.call(this);
|
|
}
|
|
if (isStrict) {
|
|
return this._weekdaysMinStrictRegex;
|
|
} else {
|
|
return this._weekdaysMinRegex;
|
|
}
|
|
} else {
|
|
if (!hasOwnProp(this, '_weekdaysMinRegex')) {
|
|
this._weekdaysMinRegex = defaultWeekdaysMinRegex;
|
|
}
|
|
return this._weekdaysMinStrictRegex && isStrict ?
|
|
this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
|
|
}
|
|
}
|
|
|
|
|
|
function computeWeekdaysParse () {
|
|
function cmpLenRev(a, b) {
|
|
return b.length - a.length;
|
|
}
|
|
|
|
var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
|
|
i, mom, minp, shortp, longp;
|
|
for (i = 0; i < 7; i++) {
|
|
// make the regex if we don't have it already
|
|
mom = createUTC([2000, 1]).day(i);
|
|
minp = this.weekdaysMin(mom, '');
|
|
shortp = this.weekdaysShort(mom, '');
|
|
longp = this.weekdays(mom, '');
|
|
minPieces.push(minp);
|
|
shortPieces.push(shortp);
|
|
longPieces.push(longp);
|
|
mixedPieces.push(minp);
|
|
mixedPieces.push(shortp);
|
|
mixedPieces.push(longp);
|
|
}
|
|
// Sorting makes sure if one weekday (or abbr) is a prefix of another it
|
|
// will match the longer piece.
|
|
minPieces.sort(cmpLenRev);
|
|
shortPieces.sort(cmpLenRev);
|
|
longPieces.sort(cmpLenRev);
|
|
mixedPieces.sort(cmpLenRev);
|
|
for (i = 0; i < 7; i++) {
|
|
shortPieces[i] = regexEscape(shortPieces[i]);
|
|
longPieces[i] = regexEscape(longPieces[i]);
|
|
mixedPieces[i] = regexEscape(mixedPieces[i]);
|
|
}
|
|
|
|
this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
|
|
this._weekdaysShortRegex = this._weekdaysRegex;
|
|
this._weekdaysMinRegex = this._weekdaysRegex;
|
|
|
|
this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
|
|
this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
|
|
this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
function hFormat() {
|
|
return this.hours() % 12 || 12;
|
|
}
|
|
|
|
function kFormat() {
|
|
return this.hours() || 24;
|
|
}
|
|
|
|
addFormatToken('H', ['HH', 2], 0, 'hour');
|
|
addFormatToken('h', ['hh', 2], 0, hFormat);
|
|
addFormatToken('k', ['kk', 2], 0, kFormat);
|
|
|
|
addFormatToken('hmm', 0, 0, function () {
|
|
return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
|
|
});
|
|
|
|
addFormatToken('hmmss', 0, 0, function () {
|
|
return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
|
|
zeroFill(this.seconds(), 2);
|
|
});
|
|
|
|
addFormatToken('Hmm', 0, 0, function () {
|
|
return '' + this.hours() + zeroFill(this.minutes(), 2);
|
|
});
|
|
|
|
addFormatToken('Hmmss', 0, 0, function () {
|
|
return '' + this.hours() + zeroFill(this.minutes(), 2) +
|
|
zeroFill(this.seconds(), 2);
|
|
});
|
|
|
|
function meridiem (token, lowercase) {
|
|
addFormatToken(token, 0, 0, function () {
|
|
return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
|
|
});
|
|
}
|
|
|
|
meridiem('a', true);
|
|
meridiem('A', false);
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('hour', 'h');
|
|
|
|
// PRIORITY
|
|
addUnitPriority('hour', 13);
|
|
|
|
// PARSING
|
|
|
|
function matchMeridiem (isStrict, locale) {
|
|
return locale._meridiemParse;
|
|
}
|
|
|
|
addRegexToken('a', matchMeridiem);
|
|
addRegexToken('A', matchMeridiem);
|
|
addRegexToken('H', match1to2);
|
|
addRegexToken('h', match1to2);
|
|
addRegexToken('k', match1to2);
|
|
addRegexToken('HH', match1to2, match2);
|
|
addRegexToken('hh', match1to2, match2);
|
|
addRegexToken('kk', match1to2, match2);
|
|
|
|
addRegexToken('hmm', match3to4);
|
|
addRegexToken('hmmss', match5to6);
|
|
addRegexToken('Hmm', match3to4);
|
|
addRegexToken('Hmmss', match5to6);
|
|
|
|
addParseToken(['H', 'HH'], HOUR);
|
|
addParseToken(['k', 'kk'], function (input, array, config) {
|
|
var kInput = toInt(input);
|
|
array[HOUR] = kInput === 24 ? 0 : kInput;
|
|
});
|
|
addParseToken(['a', 'A'], function (input, array, config) {
|
|
config._isPm = config._locale.isPM(input);
|
|
config._meridiem = input;
|
|
});
|
|
addParseToken(['h', 'hh'], function (input, array, config) {
|
|
array[HOUR] = toInt(input);
|
|
getParsingFlags(config).bigHour = true;
|
|
});
|
|
addParseToken('hmm', function (input, array, config) {
|
|
var pos = input.length - 2;
|
|
array[HOUR] = toInt(input.substr(0, pos));
|
|
array[MINUTE] = toInt(input.substr(pos));
|
|
getParsingFlags(config).bigHour = true;
|
|
});
|
|
addParseToken('hmmss', function (input, array, config) {
|
|
var pos1 = input.length - 4;
|
|
var pos2 = input.length - 2;
|
|
array[HOUR] = toInt(input.substr(0, pos1));
|
|
array[MINUTE] = toInt(input.substr(pos1, 2));
|
|
array[SECOND] = toInt(input.substr(pos2));
|
|
getParsingFlags(config).bigHour = true;
|
|
});
|
|
addParseToken('Hmm', function (input, array, config) {
|
|
var pos = input.length - 2;
|
|
array[HOUR] = toInt(input.substr(0, pos));
|
|
array[MINUTE] = toInt(input.substr(pos));
|
|
});
|
|
addParseToken('Hmmss', function (input, array, config) {
|
|
var pos1 = input.length - 4;
|
|
var pos2 = input.length - 2;
|
|
array[HOUR] = toInt(input.substr(0, pos1));
|
|
array[MINUTE] = toInt(input.substr(pos1, 2));
|
|
array[SECOND] = toInt(input.substr(pos2));
|
|
});
|
|
|
|
// LOCALES
|
|
|
|
function localeIsPM (input) {
|
|
// IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
|
|
// Using charAt should be more compatible.
|
|
return ((input + '').toLowerCase().charAt(0) === 'p');
|
|
}
|
|
|
|
var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
|
|
function localeMeridiem (hours, minutes, isLower) {
|
|
if (hours > 11) {
|
|
return isLower ? 'pm' : 'PM';
|
|
} else {
|
|
return isLower ? 'am' : 'AM';
|
|
}
|
|
}
|
|
|
|
|
|
// MOMENTS
|
|
|
|
// Setting the hour should keep the time, because the user explicitly
|
|
// specified which hour he wants. So trying to maintain the same hour (in
|
|
// a new timezone) makes sense. Adding/subtracting hours does not follow
|
|
// this rule.
|
|
var getSetHour = makeGetSet('Hours', true);
|
|
|
|
// months
|
|
// week
|
|
// weekdays
|
|
// meridiem
|
|
var baseConfig = {
|
|
calendar: defaultCalendar,
|
|
longDateFormat: defaultLongDateFormat,
|
|
invalidDate: defaultInvalidDate,
|
|
ordinal: defaultOrdinal,
|
|
dayOfMonthOrdinalParse: defaultDayOfMonthOrdinalParse,
|
|
relativeTime: defaultRelativeTime,
|
|
|
|
months: defaultLocaleMonths,
|
|
monthsShort: defaultLocaleMonthsShort,
|
|
|
|
week: defaultLocaleWeek,
|
|
|
|
weekdays: defaultLocaleWeekdays,
|
|
weekdaysMin: defaultLocaleWeekdaysMin,
|
|
weekdaysShort: defaultLocaleWeekdaysShort,
|
|
|
|
meridiemParse: defaultLocaleMeridiemParse
|
|
};
|
|
|
|
// internal storage for locale config files
|
|
var locales = {};
|
|
var localeFamilies = {};
|
|
var globalLocale;
|
|
|
|
function normalizeLocale(key) {
|
|
return key ? key.toLowerCase().replace('_', '-') : key;
|
|
}
|
|
|
|
// pick the locale from the array
|
|
// try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
|
|
// substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
|
|
function chooseLocale(names) {
|
|
var i = 0, j, next, locale, split;
|
|
|
|
while (i < names.length) {
|
|
split = normalizeLocale(names[i]).split('-');
|
|
j = split.length;
|
|
next = normalizeLocale(names[i + 1]);
|
|
next = next ? next.split('-') : null;
|
|
while (j > 0) {
|
|
locale = loadLocale(split.slice(0, j).join('-'));
|
|
if (locale) {
|
|
return locale;
|
|
}
|
|
if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
|
|
//the next array item is better than a shallower substring of this one
|
|
break;
|
|
}
|
|
j--;
|
|
}
|
|
i++;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function loadLocale(name) {
|
|
var oldLocale = null;
|
|
// TODO: Find a better way to register and load all the locales in Node
|
|
if (!locales[name] && (typeof module !== 'undefined') &&
|
|
module && module.exports) {
|
|
try {
|
|
oldLocale = globalLocale._abbr;
|
|
var aliasedRequire = require;
|
|
aliasedRequire('./locale/' + name);
|
|
getSetGlobalLocale(oldLocale);
|
|
} catch (e) {}
|
|
}
|
|
return locales[name];
|
|
}
|
|
|
|
// This function will load locale and then set the global locale. If
|
|
// no arguments are passed in, it will simply return the current global
|
|
// locale key.
|
|
function getSetGlobalLocale (key, values) {
|
|
var data;
|
|
if (key) {
|
|
if (isUndefined(values)) {
|
|
data = getLocale(key);
|
|
}
|
|
else {
|
|
data = defineLocale(key, values);
|
|
}
|
|
|
|
if (data) {
|
|
// moment.duration._locale = moment._locale = data;
|
|
globalLocale = data;
|
|
}
|
|
}
|
|
|
|
return globalLocale._abbr;
|
|
}
|
|
|
|
function defineLocale (name, config) {
|
|
if (config !== null) {
|
|
var parentConfig = baseConfig;
|
|
config.abbr = name;
|
|
if (locales[name] != null) {
|
|
deprecateSimple('defineLocaleOverride',
|
|
'use moment.updateLocale(localeName, config) to change ' +
|
|
'an existing locale. moment.defineLocale(localeName, ' +
|
|
'config) should only be used for creating a new locale ' +
|
|
'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
|
|
parentConfig = locales[name]._config;
|
|
} else if (config.parentLocale != null) {
|
|
if (locales[config.parentLocale] != null) {
|
|
parentConfig = locales[config.parentLocale]._config;
|
|
} else {
|
|
if (!localeFamilies[config.parentLocale]) {
|
|
localeFamilies[config.parentLocale] = [];
|
|
}
|
|
localeFamilies[config.parentLocale].push({
|
|
name: name,
|
|
config: config
|
|
});
|
|
return null;
|
|
}
|
|
}
|
|
locales[name] = new Locale(mergeConfigs(parentConfig, config));
|
|
|
|
if (localeFamilies[name]) {
|
|
localeFamilies[name].forEach(function (x) {
|
|
defineLocale(x.name, x.config);
|
|
});
|
|
}
|
|
|
|
// backwards compat for now: also set the locale
|
|
// make sure we set the locale AFTER all child locales have been
|
|
// created, so we won't end up with the child locale set.
|
|
getSetGlobalLocale(name);
|
|
|
|
|
|
return locales[name];
|
|
} else {
|
|
// useful for testing
|
|
delete locales[name];
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function updateLocale(name, config) {
|
|
if (config != null) {
|
|
var locale, tmpLocale, parentConfig = baseConfig;
|
|
// MERGE
|
|
tmpLocale = loadLocale(name);
|
|
if (tmpLocale != null) {
|
|
parentConfig = tmpLocale._config;
|
|
}
|
|
config = mergeConfigs(parentConfig, config);
|
|
locale = new Locale(config);
|
|
locale.parentLocale = locales[name];
|
|
locales[name] = locale;
|
|
|
|
// backwards compat for now: also set the locale
|
|
getSetGlobalLocale(name);
|
|
} else {
|
|
// pass null for config to unupdate, useful for tests
|
|
if (locales[name] != null) {
|
|
if (locales[name].parentLocale != null) {
|
|
locales[name] = locales[name].parentLocale;
|
|
} else if (locales[name] != null) {
|
|
delete locales[name];
|
|
}
|
|
}
|
|
}
|
|
return locales[name];
|
|
}
|
|
|
|
// returns locale data
|
|
function getLocale (key) {
|
|
var locale;
|
|
|
|
if (key && key._locale && key._locale._abbr) {
|
|
key = key._locale._abbr;
|
|
}
|
|
|
|
if (!key) {
|
|
return globalLocale;
|
|
}
|
|
|
|
if (!isArray(key)) {
|
|
//short-circuit everything else
|
|
locale = loadLocale(key);
|
|
if (locale) {
|
|
return locale;
|
|
}
|
|
key = [key];
|
|
}
|
|
|
|
return chooseLocale(key);
|
|
}
|
|
|
|
function listLocales() {
|
|
return keys(locales);
|
|
}
|
|
|
|
function checkOverflow (m) {
|
|
var overflow;
|
|
var a = m._a;
|
|
|
|
if (a && getParsingFlags(m).overflow === -2) {
|
|
overflow =
|
|
a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
|
|
a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
|
|
a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
|
|
a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
|
|
a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
|
|
a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
|
|
-1;
|
|
|
|
if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
|
|
overflow = DATE;
|
|
}
|
|
if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
|
|
overflow = WEEK;
|
|
}
|
|
if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
|
|
overflow = WEEKDAY;
|
|
}
|
|
|
|
getParsingFlags(m).overflow = overflow;
|
|
}
|
|
|
|
return m;
|
|
}
|
|
|
|
// Pick the first defined of two or three arguments.
|
|
function defaults(a, b, c) {
|
|
if (a != null) {
|
|
return a;
|
|
}
|
|
if (b != null) {
|
|
return b;
|
|
}
|
|
return c;
|
|
}
|
|
|
|
function currentDateArray(config) {
|
|
// hooks is actually the exported moment object
|
|
var nowValue = new Date(hooks.now());
|
|
if (config._useUTC) {
|
|
return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
|
|
}
|
|
return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
|
|
}
|
|
|
|
// convert an array to a date.
|
|
// the array should mirror the parameters below
|
|
// note: all values past the year are optional and will default to the lowest possible value.
|
|
// [year, month, day , hour, minute, second, millisecond]
|
|
function configFromArray (config) {
|
|
var i, date, input = [], currentDate, yearToUse;
|
|
|
|
if (config._d) {
|
|
return;
|
|
}
|
|
|
|
currentDate = currentDateArray(config);
|
|
|
|
//compute day of the year from weeks and weekdays
|
|
if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
|
|
dayOfYearFromWeekInfo(config);
|
|
}
|
|
|
|
//if the day of the year is set, figure out what it is
|
|
if (config._dayOfYear != null) {
|
|
yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
|
|
|
|
if (config._dayOfYear > daysInYear(yearToUse) || config._dayOfYear === 0) {
|
|
getParsingFlags(config)._overflowDayOfYear = true;
|
|
}
|
|
|
|
date = createUTCDate(yearToUse, 0, config._dayOfYear);
|
|
config._a[MONTH] = date.getUTCMonth();
|
|
config._a[DATE] = date.getUTCDate();
|
|
}
|
|
|
|
// Default to current date.
|
|
// * if no year, month, day of month are given, default to today
|
|
// * if day of month is given, default month and year
|
|
// * if month is given, default only year
|
|
// * if year is given, don't default anything
|
|
for (i = 0; i < 3 && config._a[i] == null; ++i) {
|
|
config._a[i] = input[i] = currentDate[i];
|
|
}
|
|
|
|
// Zero out whatever was not defaulted, including time
|
|
for (; i < 7; i++) {
|
|
config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
|
|
}
|
|
|
|
// Check for 24:00:00.000
|
|
if (config._a[HOUR] === 24 &&
|
|
config._a[MINUTE] === 0 &&
|
|
config._a[SECOND] === 0 &&
|
|
config._a[MILLISECOND] === 0) {
|
|
config._nextDay = true;
|
|
config._a[HOUR] = 0;
|
|
}
|
|
|
|
config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
|
|
// Apply timezone offset from input. The actual utcOffset can be changed
|
|
// with parseZone.
|
|
if (config._tzm != null) {
|
|
config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
|
|
}
|
|
|
|
if (config._nextDay) {
|
|
config._a[HOUR] = 24;
|
|
}
|
|
|
|
// check for mismatching day of week
|
|
if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== config._d.getDay()) {
|
|
getParsingFlags(config).weekdayMismatch = true;
|
|
}
|
|
}
|
|
|
|
function dayOfYearFromWeekInfo(config) {
|
|
var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
|
|
|
|
w = config._w;
|
|
if (w.GG != null || w.W != null || w.E != null) {
|
|
dow = 1;
|
|
doy = 4;
|
|
|
|
// TODO: We need to take the current isoWeekYear, but that depends on
|
|
// how we interpret now (local, utc, fixed offset). So create
|
|
// a now version of current config (take local/utc/offset flags, and
|
|
// create now).
|
|
weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(createLocal(), 1, 4).year);
|
|
week = defaults(w.W, 1);
|
|
weekday = defaults(w.E, 1);
|
|
if (weekday < 1 || weekday > 7) {
|
|
weekdayOverflow = true;
|
|
}
|
|
} else {
|
|
dow = config._locale._week.dow;
|
|
doy = config._locale._week.doy;
|
|
|
|
var curWeek = weekOfYear(createLocal(), dow, doy);
|
|
|
|
weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
|
|
|
|
// Default to current week.
|
|
week = defaults(w.w, curWeek.week);
|
|
|
|
if (w.d != null) {
|
|
// weekday -- low day numbers are considered next week
|
|
weekday = w.d;
|
|
if (weekday < 0 || weekday > 6) {
|
|
weekdayOverflow = true;
|
|
}
|
|
} else if (w.e != null) {
|
|
// local weekday -- counting starts from begining of week
|
|
weekday = w.e + dow;
|
|
if (w.e < 0 || w.e > 6) {
|
|
weekdayOverflow = true;
|
|
}
|
|
} else {
|
|
// default to begining of week
|
|
weekday = dow;
|
|
}
|
|
}
|
|
if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
|
|
getParsingFlags(config)._overflowWeeks = true;
|
|
} else if (weekdayOverflow != null) {
|
|
getParsingFlags(config)._overflowWeekday = true;
|
|
} else {
|
|
temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
|
|
config._a[YEAR] = temp.year;
|
|
config._dayOfYear = temp.dayOfYear;
|
|
}
|
|
}
|
|
|
|
// iso 8601 regex
|
|
// 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
|
|
var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
|
|
var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
|
|
|
|
var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
|
|
|
|
var isoDates = [
|
|
['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
|
|
['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
|
|
['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
|
|
['GGGG-[W]WW', /\d{4}-W\d\d/, false],
|
|
['YYYY-DDD', /\d{4}-\d{3}/],
|
|
['YYYY-MM', /\d{4}-\d\d/, false],
|
|
['YYYYYYMMDD', /[+-]\d{10}/],
|
|
['YYYYMMDD', /\d{8}/],
|
|
// YYYYMM is NOT allowed by the standard
|
|
['GGGG[W]WWE', /\d{4}W\d{3}/],
|
|
['GGGG[W]WW', /\d{4}W\d{2}/, false],
|
|
['YYYYDDD', /\d{7}/]
|
|
];
|
|
|
|
// iso time formats and regexes
|
|
var isoTimes = [
|
|
['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
|
|
['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
|
|
['HH:mm:ss', /\d\d:\d\d:\d\d/],
|
|
['HH:mm', /\d\d:\d\d/],
|
|
['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
|
|
['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
|
|
['HHmmss', /\d\d\d\d\d\d/],
|
|
['HHmm', /\d\d\d\d/],
|
|
['HH', /\d\d/]
|
|
];
|
|
|
|
var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
|
|
|
|
// date from iso format
|
|
function configFromISO(config) {
|
|
var i, l,
|
|
string = config._i,
|
|
match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
|
|
allowTime, dateFormat, timeFormat, tzFormat;
|
|
|
|
if (match) {
|
|
getParsingFlags(config).iso = true;
|
|
|
|
for (i = 0, l = isoDates.length; i < l; i++) {
|
|
if (isoDates[i][1].exec(match[1])) {
|
|
dateFormat = isoDates[i][0];
|
|
allowTime = isoDates[i][2] !== false;
|
|
break;
|
|
}
|
|
}
|
|
if (dateFormat == null) {
|
|
config._isValid = false;
|
|
return;
|
|
}
|
|
if (match[3]) {
|
|
for (i = 0, l = isoTimes.length; i < l; i++) {
|
|
if (isoTimes[i][1].exec(match[3])) {
|
|
// match[2] should be 'T' or space
|
|
timeFormat = (match[2] || ' ') + isoTimes[i][0];
|
|
break;
|
|
}
|
|
}
|
|
if (timeFormat == null) {
|
|
config._isValid = false;
|
|
return;
|
|
}
|
|
}
|
|
if (!allowTime && timeFormat != null) {
|
|
config._isValid = false;
|
|
return;
|
|
}
|
|
if (match[4]) {
|
|
if (tzRegex.exec(match[4])) {
|
|
tzFormat = 'Z';
|
|
} else {
|
|
config._isValid = false;
|
|
return;
|
|
}
|
|
}
|
|
config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
|
|
configFromStringAndFormat(config);
|
|
} else {
|
|
config._isValid = false;
|
|
}
|
|
}
|
|
|
|
// RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
|
|
var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/;
|
|
|
|
function extractFromRFC2822Strings(yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
|
|
var result = [
|
|
untruncateYear(yearStr),
|
|
defaultLocaleMonthsShort.indexOf(monthStr),
|
|
parseInt(dayStr, 10),
|
|
parseInt(hourStr, 10),
|
|
parseInt(minuteStr, 10)
|
|
];
|
|
|
|
if (secondStr) {
|
|
result.push(parseInt(secondStr, 10));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
function untruncateYear(yearStr) {
|
|
var year = parseInt(yearStr, 10);
|
|
if (year <= 49) {
|
|
return 2000 + year;
|
|
} else if (year <= 999) {
|
|
return 1900 + year;
|
|
}
|
|
return year;
|
|
}
|
|
|
|
function preprocessRFC2822(s) {
|
|
// Remove comments and folding whitespace and replace multiple-spaces with a single space
|
|
return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim();
|
|
}
|
|
|
|
function checkWeekday(weekdayStr, parsedInput, config) {
|
|
if (weekdayStr) {
|
|
// TODO: Replace the vanilla JS Date object with an indepentent day-of-week check.
|
|
var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
|
|
weekdayActual = new Date(parsedInput[0], parsedInput[1], parsedInput[2]).getDay();
|
|
if (weekdayProvided !== weekdayActual) {
|
|
getParsingFlags(config).weekdayMismatch = true;
|
|
config._isValid = false;
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
var obsOffsets = {
|
|
UT: 0,
|
|
GMT: 0,
|
|
EDT: -4 * 60,
|
|
EST: -5 * 60,
|
|
CDT: -5 * 60,
|
|
CST: -6 * 60,
|
|
MDT: -6 * 60,
|
|
MST: -7 * 60,
|
|
PDT: -7 * 60,
|
|
PST: -8 * 60
|
|
};
|
|
|
|
function calculateOffset(obsOffset, militaryOffset, numOffset) {
|
|
if (obsOffset) {
|
|
return obsOffsets[obsOffset];
|
|
} else if (militaryOffset) {
|
|
// the only allowed military tz is Z
|
|
return 0;
|
|
} else {
|
|
var hm = parseInt(numOffset, 10);
|
|
var m = hm % 100, h = (hm - m) / 100;
|
|
return h * 60 + m;
|
|
}
|
|
}
|
|
|
|
// date and time from ref 2822 format
|
|
function configFromRFC2822(config) {
|
|
var match = rfc2822.exec(preprocessRFC2822(config._i));
|
|
if (match) {
|
|
var parsedArray = extractFromRFC2822Strings(match[4], match[3], match[2], match[5], match[6], match[7]);
|
|
if (!checkWeekday(match[1], parsedArray, config)) {
|
|
return;
|
|
}
|
|
|
|
config._a = parsedArray;
|
|
config._tzm = calculateOffset(match[8], match[9], match[10]);
|
|
|
|
config._d = createUTCDate.apply(null, config._a);
|
|
config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
|
|
|
|
getParsingFlags(config).rfc2822 = true;
|
|
} else {
|
|
config._isValid = false;
|
|
}
|
|
}
|
|
|
|
// date from iso format or fallback
|
|
function configFromString(config) {
|
|
var matched = aspNetJsonRegex.exec(config._i);
|
|
|
|
if (matched !== null) {
|
|
config._d = new Date(+matched[1]);
|
|
return;
|
|
}
|
|
|
|
configFromISO(config);
|
|
if (config._isValid === false) {
|
|
delete config._isValid;
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
configFromRFC2822(config);
|
|
if (config._isValid === false) {
|
|
delete config._isValid;
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
// Final attempt, use Input Fallback
|
|
hooks.createFromInputFallback(config);
|
|
}
|
|
|
|
hooks.createFromInputFallback = deprecate(
|
|
'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
|
|
'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
|
|
'discouraged and will be removed in an upcoming major release. Please refer to ' +
|
|
'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
|
|
function (config) {
|
|
config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
|
|
}
|
|
);
|
|
|
|
// constant that refers to the ISO standard
|
|
hooks.ISO_8601 = function () {};
|
|
|
|
// constant that refers to the RFC 2822 form
|
|
hooks.RFC_2822 = function () {};
|
|
|
|
// date from string and format string
|
|
function configFromStringAndFormat(config) {
|
|
// TODO: Move this to another part of the creation flow to prevent circular deps
|
|
if (config._f === hooks.ISO_8601) {
|
|
configFromISO(config);
|
|
return;
|
|
}
|
|
if (config._f === hooks.RFC_2822) {
|
|
configFromRFC2822(config);
|
|
return;
|
|
}
|
|
config._a = [];
|
|
getParsingFlags(config).empty = true;
|
|
|
|
// This array is used to make a Date, either with `new Date` or `Date.UTC`
|
|
var string = '' + config._i,
|
|
i, parsedInput, tokens, token, skipped,
|
|
stringLength = string.length,
|
|
totalParsedInputLength = 0;
|
|
|
|
tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
|
|
|
|
for (i = 0; i < tokens.length; i++) {
|
|
token = tokens[i];
|
|
parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
|
|
// console.log('token', token, 'parsedInput', parsedInput,
|
|
// 'regex', getParseRegexForToken(token, config));
|
|
if (parsedInput) {
|
|
skipped = string.substr(0, string.indexOf(parsedInput));
|
|
if (skipped.length > 0) {
|
|
getParsingFlags(config).unusedInput.push(skipped);
|
|
}
|
|
string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
|
|
totalParsedInputLength += parsedInput.length;
|
|
}
|
|
// don't parse if it's not a known token
|
|
if (formatTokenFunctions[token]) {
|
|
if (parsedInput) {
|
|
getParsingFlags(config).empty = false;
|
|
}
|
|
else {
|
|
getParsingFlags(config).unusedTokens.push(token);
|
|
}
|
|
addTimeToArrayFromToken(token, parsedInput, config);
|
|
}
|
|
else if (config._strict && !parsedInput) {
|
|
getParsingFlags(config).unusedTokens.push(token);
|
|
}
|
|
}
|
|
|
|
// add remaining unparsed input length to the string
|
|
getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
|
|
if (string.length > 0) {
|
|
getParsingFlags(config).unusedInput.push(string);
|
|
}
|
|
|
|
// clear _12h flag if hour is <= 12
|
|
if (config._a[HOUR] <= 12 &&
|
|
getParsingFlags(config).bigHour === true &&
|
|
config._a[HOUR] > 0) {
|
|
getParsingFlags(config).bigHour = undefined;
|
|
}
|
|
|
|
getParsingFlags(config).parsedDateParts = config._a.slice(0);
|
|
getParsingFlags(config).meridiem = config._meridiem;
|
|
// handle meridiem
|
|
config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
|
|
|
|
configFromArray(config);
|
|
checkOverflow(config);
|
|
}
|
|
|
|
|
|
function meridiemFixWrap (locale, hour, meridiem) {
|
|
var isPm;
|
|
|
|
if (meridiem == null) {
|
|
// nothing to do
|
|
return hour;
|
|
}
|
|
if (locale.meridiemHour != null) {
|
|
return locale.meridiemHour(hour, meridiem);
|
|
} else if (locale.isPM != null) {
|
|
// Fallback
|
|
isPm = locale.isPM(meridiem);
|
|
if (isPm && hour < 12) {
|
|
hour += 12;
|
|
}
|
|
if (!isPm && hour === 12) {
|
|
hour = 0;
|
|
}
|
|
return hour;
|
|
} else {
|
|
// this is not supposed to happen
|
|
return hour;
|
|
}
|
|
}
|
|
|
|
// date from string and array of format strings
|
|
function configFromStringAndArray(config) {
|
|
var tempConfig,
|
|
bestMoment,
|
|
|
|
scoreToBeat,
|
|
i,
|
|
currentScore;
|
|
|
|
if (config._f.length === 0) {
|
|
getParsingFlags(config).invalidFormat = true;
|
|
config._d = new Date(NaN);
|
|
return;
|
|
}
|
|
|
|
for (i = 0; i < config._f.length; i++) {
|
|
currentScore = 0;
|
|
tempConfig = copyConfig({}, config);
|
|
if (config._useUTC != null) {
|
|
tempConfig._useUTC = config._useUTC;
|
|
}
|
|
tempConfig._f = config._f[i];
|
|
configFromStringAndFormat(tempConfig);
|
|
|
|
if (!isValid(tempConfig)) {
|
|
continue;
|
|
}
|
|
|
|
// if there is any input that was not parsed add a penalty for that format
|
|
currentScore += getParsingFlags(tempConfig).charsLeftOver;
|
|
|
|
//or tokens
|
|
currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
|
|
|
|
getParsingFlags(tempConfig).score = currentScore;
|
|
|
|
if (scoreToBeat == null || currentScore < scoreToBeat) {
|
|
scoreToBeat = currentScore;
|
|
bestMoment = tempConfig;
|
|
}
|
|
}
|
|
|
|
extend(config, bestMoment || tempConfig);
|
|
}
|
|
|
|
function configFromObject(config) {
|
|
if (config._d) {
|
|
return;
|
|
}
|
|
|
|
var i = normalizeObjectUnits(config._i);
|
|
config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
|
|
return obj && parseInt(obj, 10);
|
|
});
|
|
|
|
configFromArray(config);
|
|
}
|
|
|
|
function createFromConfig (config) {
|
|
var res = new Moment(checkOverflow(prepareConfig(config)));
|
|
if (res._nextDay) {
|
|
// Adding is smart enough around DST
|
|
res.add(1, 'd');
|
|
res._nextDay = undefined;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
function prepareConfig (config) {
|
|
var input = config._i,
|
|
format = config._f;
|
|
|
|
config._locale = config._locale || getLocale(config._l);
|
|
|
|
if (input === null || (format === undefined && input === '')) {
|
|
return createInvalid({nullInput: true});
|
|
}
|
|
|
|
if (typeof input === 'string') {
|
|
config._i = input = config._locale.preparse(input);
|
|
}
|
|
|
|
if (isMoment(input)) {
|
|
return new Moment(checkOverflow(input));
|
|
} else if (isDate(input)) {
|
|
config._d = input;
|
|
} else if (isArray(format)) {
|
|
configFromStringAndArray(config);
|
|
} else if (format) {
|
|
configFromStringAndFormat(config);
|
|
} else {
|
|
configFromInput(config);
|
|
}
|
|
|
|
if (!isValid(config)) {
|
|
config._d = null;
|
|
}
|
|
|
|
return config;
|
|
}
|
|
|
|
function configFromInput(config) {
|
|
var input = config._i;
|
|
if (isUndefined(input)) {
|
|
config._d = new Date(hooks.now());
|
|
} else if (isDate(input)) {
|
|
config._d = new Date(input.valueOf());
|
|
} else if (typeof input === 'string') {
|
|
configFromString(config);
|
|
} else if (isArray(input)) {
|
|
config._a = map(input.slice(0), function (obj) {
|
|
return parseInt(obj, 10);
|
|
});
|
|
configFromArray(config);
|
|
} else if (isObject(input)) {
|
|
configFromObject(config);
|
|
} else if (isNumber(input)) {
|
|
// from milliseconds
|
|
config._d = new Date(input);
|
|
} else {
|
|
hooks.createFromInputFallback(config);
|
|
}
|
|
}
|
|
|
|
function createLocalOrUTC (input, format, locale, strict, isUTC) {
|
|
var c = {};
|
|
|
|
if (locale === true || locale === false) {
|
|
strict = locale;
|
|
locale = undefined;
|
|
}
|
|
|
|
if ((isObject(input) && isObjectEmpty(input)) ||
|
|
(isArray(input) && input.length === 0)) {
|
|
input = undefined;
|
|
}
|
|
// object construction must be done this way.
|
|
// https://github.com/moment/moment/issues/1423
|
|
c._isAMomentObject = true;
|
|
c._useUTC = c._isUTC = isUTC;
|
|
c._l = locale;
|
|
c._i = input;
|
|
c._f = format;
|
|
c._strict = strict;
|
|
|
|
return createFromConfig(c);
|
|
}
|
|
|
|
function createLocal (input, format, locale, strict) {
|
|
return createLocalOrUTC(input, format, locale, strict, false);
|
|
}
|
|
|
|
var prototypeMin = deprecate(
|
|
'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
|
|
function () {
|
|
var other = createLocal.apply(null, arguments);
|
|
if (this.isValid() && other.isValid()) {
|
|
return other < this ? this : other;
|
|
} else {
|
|
return createInvalid();
|
|
}
|
|
}
|
|
);
|
|
|
|
var prototypeMax = deprecate(
|
|
'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
|
|
function () {
|
|
var other = createLocal.apply(null, arguments);
|
|
if (this.isValid() && other.isValid()) {
|
|
return other > this ? this : other;
|
|
} else {
|
|
return createInvalid();
|
|
}
|
|
}
|
|
);
|
|
|
|
// Pick a moment m from moments so that m[fn](other) is true for all
|
|
// other. This relies on the function fn to be transitive.
|
|
//
|
|
// moments should either be an array of moment objects or an array, whose
|
|
// first element is an array of moment objects.
|
|
function pickBy(fn, moments) {
|
|
var res, i;
|
|
if (moments.length === 1 && isArray(moments[0])) {
|
|
moments = moments[0];
|
|
}
|
|
if (!moments.length) {
|
|
return createLocal();
|
|
}
|
|
res = moments[0];
|
|
for (i = 1; i < moments.length; ++i) {
|
|
if (!moments[i].isValid() || moments[i][fn](res)) {
|
|
res = moments[i];
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
// TODO: Use [].sort instead?
|
|
function min () {
|
|
var args = [].slice.call(arguments, 0);
|
|
|
|
return pickBy('isBefore', args);
|
|
}
|
|
|
|
function max () {
|
|
var args = [].slice.call(arguments, 0);
|
|
|
|
return pickBy('isAfter', args);
|
|
}
|
|
|
|
var now = function () {
|
|
return Date.now ? Date.now() : +(new Date());
|
|
};
|
|
|
|
var ordering = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
|
|
|
|
function isDurationValid(m) {
|
|
for (var key in m) {
|
|
if (!(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
var unitHasDecimal = false;
|
|
for (var i = 0; i < ordering.length; ++i) {
|
|
if (m[ordering[i]]) {
|
|
if (unitHasDecimal) {
|
|
return false; // only allow non-integers for smallest unit
|
|
}
|
|
if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
|
|
unitHasDecimal = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function isValid$1() {
|
|
return this._isValid;
|
|
}
|
|
|
|
function createInvalid$1() {
|
|
return createDuration(NaN);
|
|
}
|
|
|
|
function Duration (duration) {
|
|
var normalizedInput = normalizeObjectUnits(duration),
|
|
years = normalizedInput.year || 0,
|
|
quarters = normalizedInput.quarter || 0,
|
|
months = normalizedInput.month || 0,
|
|
weeks = normalizedInput.week || 0,
|
|
days = normalizedInput.day || 0,
|
|
hours = normalizedInput.hour || 0,
|
|
minutes = normalizedInput.minute || 0,
|
|
seconds = normalizedInput.second || 0,
|
|
milliseconds = normalizedInput.millisecond || 0;
|
|
|
|
this._isValid = isDurationValid(normalizedInput);
|
|
|
|
// representation for dateAddRemove
|
|
this._milliseconds = +milliseconds +
|
|
seconds * 1e3 + // 1000
|
|
minutes * 6e4 + // 1000 * 60
|
|
hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
|
|
// Because of dateAddRemove treats 24 hours as different from a
|
|
// day when working around DST, we need to store them separately
|
|
this._days = +days +
|
|
weeks * 7;
|
|
// It is impossible to translate months into days without knowing
|
|
// which months you are are talking about, so we have to store
|
|
// it separately.
|
|
this._months = +months +
|
|
quarters * 3 +
|
|
years * 12;
|
|
|
|
this._data = {};
|
|
|
|
this._locale = getLocale();
|
|
|
|
this._bubble();
|
|
}
|
|
|
|
function isDuration (obj) {
|
|
return obj instanceof Duration;
|
|
}
|
|
|
|
function absRound (number) {
|
|
if (number < 0) {
|
|
return Math.round(-1 * number) * -1;
|
|
} else {
|
|
return Math.round(number);
|
|
}
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
function offset (token, separator) {
|
|
addFormatToken(token, 0, 0, function () {
|
|
var offset = this.utcOffset();
|
|
var sign = '+';
|
|
if (offset < 0) {
|
|
offset = -offset;
|
|
sign = '-';
|
|
}
|
|
return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
|
|
});
|
|
}
|
|
|
|
offset('Z', ':');
|
|
offset('ZZ', '');
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('Z', matchShortOffset);
|
|
addRegexToken('ZZ', matchShortOffset);
|
|
addParseToken(['Z', 'ZZ'], function (input, array, config) {
|
|
config._useUTC = true;
|
|
config._tzm = offsetFromString(matchShortOffset, input);
|
|
});
|
|
|
|
// HELPERS
|
|
|
|
// timezone chunker
|
|
// '+10:00' > ['10', '00']
|
|
// '-1530' > ['-15', '30']
|
|
var chunkOffset = /([\+\-]|\d\d)/gi;
|
|
|
|
function offsetFromString(matcher, string) {
|
|
var matches = (string || '').match(matcher);
|
|
|
|
if (matches === null) {
|
|
return null;
|
|
}
|
|
|
|
var chunk = matches[matches.length - 1] || [];
|
|
var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
|
|
var minutes = +(parts[1] * 60) + toInt(parts[2]);
|
|
|
|
return minutes === 0 ?
|
|
0 :
|
|
parts[0] === '+' ? minutes : -minutes;
|
|
}
|
|
|
|
// Return a moment from input, that is local/utc/zone equivalent to model.
|
|
function cloneWithOffset(input, model) {
|
|
var res, diff;
|
|
if (model._isUTC) {
|
|
res = model.clone();
|
|
diff = (isMoment(input) || isDate(input) ? input.valueOf() : createLocal(input).valueOf()) - res.valueOf();
|
|
// Use low-level api, because this fn is low-level api.
|
|
res._d.setTime(res._d.valueOf() + diff);
|
|
hooks.updateOffset(res, false);
|
|
return res;
|
|
} else {
|
|
return createLocal(input).local();
|
|
}
|
|
}
|
|
|
|
function getDateOffset (m) {
|
|
// On Firefox.24 Date#getTimezoneOffset returns a floating point.
|
|
// https://github.com/moment/moment/pull/1871
|
|
return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
|
|
}
|
|
|
|
// HOOKS
|
|
|
|
// This function will be called whenever a moment is mutated.
|
|
// It is intended to keep the offset in sync with the timezone.
|
|
hooks.updateOffset = function () {};
|
|
|
|
// MOMENTS
|
|
|
|
// keepLocalTime = true means only change the timezone, without
|
|
// affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
|
|
// 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
|
|
// +0200, so we adjust the time as needed, to be valid.
|
|
//
|
|
// Keeping the time actually adds/subtracts (one hour)
|
|
// from the actual represented time. That is why we call updateOffset
|
|
// a second time. In case it wants us to change the offset again
|
|
// _changeInProgress == true case, then we have to adjust, because
|
|
// there is no such time in the given timezone.
|
|
function getSetOffset (input, keepLocalTime, keepMinutes) {
|
|
var offset = this._offset || 0,
|
|
localAdjust;
|
|
if (!this.isValid()) {
|
|
return input != null ? this : NaN;
|
|
}
|
|
if (input != null) {
|
|
if (typeof input === 'string') {
|
|
input = offsetFromString(matchShortOffset, input);
|
|
if (input === null) {
|
|
return this;
|
|
}
|
|
} else if (Math.abs(input) < 16 && !keepMinutes) {
|
|
input = input * 60;
|
|
}
|
|
if (!this._isUTC && keepLocalTime) {
|
|
localAdjust = getDateOffset(this);
|
|
}
|
|
this._offset = input;
|
|
this._isUTC = true;
|
|
if (localAdjust != null) {
|
|
this.add(localAdjust, 'm');
|
|
}
|
|
if (offset !== input) {
|
|
if (!keepLocalTime || this._changeInProgress) {
|
|
addSubtract(this, createDuration(input - offset, 'm'), 1, false);
|
|
} else if (!this._changeInProgress) {
|
|
this._changeInProgress = true;
|
|
hooks.updateOffset(this, true);
|
|
this._changeInProgress = null;
|
|
}
|
|
}
|
|
return this;
|
|
} else {
|
|
return this._isUTC ? offset : getDateOffset(this);
|
|
}
|
|
}
|
|
|
|
function getSetZone (input, keepLocalTime) {
|
|
if (input != null) {
|
|
if (typeof input !== 'string') {
|
|
input = -input;
|
|
}
|
|
|
|
this.utcOffset(input, keepLocalTime);
|
|
|
|
return this;
|
|
} else {
|
|
return -this.utcOffset();
|
|
}
|
|
}
|
|
|
|
function setOffsetToUTC (keepLocalTime) {
|
|
return this.utcOffset(0, keepLocalTime);
|
|
}
|
|
|
|
function setOffsetToLocal (keepLocalTime) {
|
|
if (this._isUTC) {
|
|
this.utcOffset(0, keepLocalTime);
|
|
this._isUTC = false;
|
|
|
|
if (keepLocalTime) {
|
|
this.subtract(getDateOffset(this), 'm');
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
|
|
function setOffsetToParsedOffset () {
|
|
if (this._tzm != null) {
|
|
this.utcOffset(this._tzm, false, true);
|
|
} else if (typeof this._i === 'string') {
|
|
var tZone = offsetFromString(matchOffset, this._i);
|
|
if (tZone != null) {
|
|
this.utcOffset(tZone);
|
|
}
|
|
else {
|
|
this.utcOffset(0, true);
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
|
|
function hasAlignedHourOffset (input) {
|
|
if (!this.isValid()) {
|
|
return false;
|
|
}
|
|
input = input ? createLocal(input).utcOffset() : 0;
|
|
|
|
return (this.utcOffset() - input) % 60 === 0;
|
|
}
|
|
|
|
function isDaylightSavingTime () {
|
|
return (
|
|
this.utcOffset() > this.clone().month(0).utcOffset() ||
|
|
this.utcOffset() > this.clone().month(5).utcOffset()
|
|
);
|
|
}
|
|
|
|
function isDaylightSavingTimeShifted () {
|
|
if (!isUndefined(this._isDSTShifted)) {
|
|
return this._isDSTShifted;
|
|
}
|
|
|
|
var c = {};
|
|
|
|
copyConfig(c, this);
|
|
c = prepareConfig(c);
|
|
|
|
if (c._a) {
|
|
var other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
|
|
this._isDSTShifted = this.isValid() &&
|
|
compareArrays(c._a, other.toArray()) > 0;
|
|
} else {
|
|
this._isDSTShifted = false;
|
|
}
|
|
|
|
return this._isDSTShifted;
|
|
}
|
|
|
|
function isLocal () {
|
|
return this.isValid() ? !this._isUTC : false;
|
|
}
|
|
|
|
function isUtcOffset () {
|
|
return this.isValid() ? this._isUTC : false;
|
|
}
|
|
|
|
function isUtc () {
|
|
return this.isValid() ? this._isUTC && this._offset === 0 : false;
|
|
}
|
|
|
|
// ASP.NET json date format regex
|
|
var aspNetRegex = /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
|
|
|
|
// from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
|
|
// somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
|
|
// and further modified to allow for strings containing both week and day
|
|
var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
|
|
|
|
function createDuration (input, key) {
|
|
var duration = input,
|
|
// matching against regexp is expensive, do it on demand
|
|
match = null,
|
|
sign,
|
|
ret,
|
|
diffRes;
|
|
|
|
if (isDuration(input)) {
|
|
duration = {
|
|
ms : input._milliseconds,
|
|
d : input._days,
|
|
M : input._months
|
|
};
|
|
} else if (isNumber(input)) {
|
|
duration = {};
|
|
if (key) {
|
|
duration[key] = input;
|
|
} else {
|
|
duration.milliseconds = input;
|
|
}
|
|
} else if (!!(match = aspNetRegex.exec(input))) {
|
|
sign = (match[1] === '-') ? -1 : 1;
|
|
duration = {
|
|
y : 0,
|
|
d : toInt(match[DATE]) * sign,
|
|
h : toInt(match[HOUR]) * sign,
|
|
m : toInt(match[MINUTE]) * sign,
|
|
s : toInt(match[SECOND]) * sign,
|
|
ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
|
|
};
|
|
} else if (!!(match = isoRegex.exec(input))) {
|
|
sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
|
|
duration = {
|
|
y : parseIso(match[2], sign),
|
|
M : parseIso(match[3], sign),
|
|
w : parseIso(match[4], sign),
|
|
d : parseIso(match[5], sign),
|
|
h : parseIso(match[6], sign),
|
|
m : parseIso(match[7], sign),
|
|
s : parseIso(match[8], sign)
|
|
};
|
|
} else if (duration == null) {// checks for null or undefined
|
|
duration = {};
|
|
} else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
|
|
diffRes = momentsDifference(createLocal(duration.from), createLocal(duration.to));
|
|
|
|
duration = {};
|
|
duration.ms = diffRes.milliseconds;
|
|
duration.M = diffRes.months;
|
|
}
|
|
|
|
ret = new Duration(duration);
|
|
|
|
if (isDuration(input) && hasOwnProp(input, '_locale')) {
|
|
ret._locale = input._locale;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
createDuration.fn = Duration.prototype;
|
|
createDuration.invalid = createInvalid$1;
|
|
|
|
function parseIso (inp, sign) {
|
|
// We'd normally use ~~inp for this, but unfortunately it also
|
|
// converts floats to ints.
|
|
// inp may be undefined, so careful calling replace on it.
|
|
var res = inp && parseFloat(inp.replace(',', '.'));
|
|
// apply sign while we're at it
|
|
return (isNaN(res) ? 0 : res) * sign;
|
|
}
|
|
|
|
function positiveMomentsDifference(base, other) {
|
|
var res = {milliseconds: 0, months: 0};
|
|
|
|
res.months = other.month() - base.month() +
|
|
(other.year() - base.year()) * 12;
|
|
if (base.clone().add(res.months, 'M').isAfter(other)) {
|
|
--res.months;
|
|
}
|
|
|
|
res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
|
|
|
|
return res;
|
|
}
|
|
|
|
function momentsDifference(base, other) {
|
|
var res;
|
|
if (!(base.isValid() && other.isValid())) {
|
|
return {milliseconds: 0, months: 0};
|
|
}
|
|
|
|
other = cloneWithOffset(other, base);
|
|
if (base.isBefore(other)) {
|
|
res = positiveMomentsDifference(base, other);
|
|
} else {
|
|
res = positiveMomentsDifference(other, base);
|
|
res.milliseconds = -res.milliseconds;
|
|
res.months = -res.months;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
// TODO: remove 'name' arg after deprecation is removed
|
|
function createAdder(direction, name) {
|
|
return function (val, period) {
|
|
var dur, tmp;
|
|
//invert the arguments, but complain about it
|
|
if (period !== null && !isNaN(+period)) {
|
|
deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period). ' +
|
|
'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
|
|
tmp = val; val = period; period = tmp;
|
|
}
|
|
|
|
val = typeof val === 'string' ? +val : val;
|
|
dur = createDuration(val, period);
|
|
addSubtract(this, dur, direction);
|
|
return this;
|
|
};
|
|
}
|
|
|
|
function addSubtract (mom, duration, isAdding, updateOffset) {
|
|
var milliseconds = duration._milliseconds,
|
|
days = absRound(duration._days),
|
|
months = absRound(duration._months);
|
|
|
|
if (!mom.isValid()) {
|
|
// No op
|
|
return;
|
|
}
|
|
|
|
updateOffset = updateOffset == null ? true : updateOffset;
|
|
|
|
if (months) {
|
|
setMonth(mom, get(mom, 'Month') + months * isAdding);
|
|
}
|
|
if (days) {
|
|
set$1(mom, 'Date', get(mom, 'Date') + days * isAdding);
|
|
}
|
|
if (milliseconds) {
|
|
mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
|
|
}
|
|
if (updateOffset) {
|
|
hooks.updateOffset(mom, days || months);
|
|
}
|
|
}
|
|
|
|
var add = createAdder(1, 'add');
|
|
var subtract = createAdder(-1, 'subtract');
|
|
|
|
function getCalendarFormat(myMoment, now) {
|
|
var diff = myMoment.diff(now, 'days', true);
|
|
return diff < -6 ? 'sameElse' :
|
|
diff < -1 ? 'lastWeek' :
|
|
diff < 0 ? 'lastDay' :
|
|
diff < 1 ? 'sameDay' :
|
|
diff < 2 ? 'nextDay' :
|
|
diff < 7 ? 'nextWeek' : 'sameElse';
|
|
}
|
|
|
|
function calendar$1 (time, formats) {
|
|
// We want to compare the start of today, vs this.
|
|
// Getting start-of-today depends on whether we're local/utc/offset or not.
|
|
var now = time || createLocal(),
|
|
sod = cloneWithOffset(now, this).startOf('day'),
|
|
format = hooks.calendarFormat(this, sod) || 'sameElse';
|
|
|
|
var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
|
|
|
|
return this.format(output || this.localeData().calendar(format, this, createLocal(now)));
|
|
}
|
|
|
|
function clone () {
|
|
return new Moment(this);
|
|
}
|
|
|
|
function isAfter (input, units) {
|
|
var localInput = isMoment(input) ? input : createLocal(input);
|
|
if (!(this.isValid() && localInput.isValid())) {
|
|
return false;
|
|
}
|
|
units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
|
|
if (units === 'millisecond') {
|
|
return this.valueOf() > localInput.valueOf();
|
|
} else {
|
|
return localInput.valueOf() < this.clone().startOf(units).valueOf();
|
|
}
|
|
}
|
|
|
|
function isBefore (input, units) {
|
|
var localInput = isMoment(input) ? input : createLocal(input);
|
|
if (!(this.isValid() && localInput.isValid())) {
|
|
return false;
|
|
}
|
|
units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
|
|
if (units === 'millisecond') {
|
|
return this.valueOf() < localInput.valueOf();
|
|
} else {
|
|
return this.clone().endOf(units).valueOf() < localInput.valueOf();
|
|
}
|
|
}
|
|
|
|
function isBetween (from, to, units, inclusivity) {
|
|
inclusivity = inclusivity || '()';
|
|
return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
|
|
(inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
|
|
}
|
|
|
|
function isSame (input, units) {
|
|
var localInput = isMoment(input) ? input : createLocal(input),
|
|
inputMs;
|
|
if (!(this.isValid() && localInput.isValid())) {
|
|
return false;
|
|
}
|
|
units = normalizeUnits(units || 'millisecond');
|
|
if (units === 'millisecond') {
|
|
return this.valueOf() === localInput.valueOf();
|
|
} else {
|
|
inputMs = localInput.valueOf();
|
|
return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
|
|
}
|
|
}
|
|
|
|
function isSameOrAfter (input, units) {
|
|
return this.isSame(input, units) || this.isAfter(input,units);
|
|
}
|
|
|
|
function isSameOrBefore (input, units) {
|
|
return this.isSame(input, units) || this.isBefore(input,units);
|
|
}
|
|
|
|
function diff (input, units, asFloat) {
|
|
var that,
|
|
zoneDelta,
|
|
delta, output;
|
|
|
|
if (!this.isValid()) {
|
|
return NaN;
|
|
}
|
|
|
|
that = cloneWithOffset(input, this);
|
|
|
|
if (!that.isValid()) {
|
|
return NaN;
|
|
}
|
|
|
|
zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
|
|
|
|
units = normalizeUnits(units);
|
|
|
|
switch (units) {
|
|
case 'year': output = monthDiff(this, that) / 12; break;
|
|
case 'month': output = monthDiff(this, that); break;
|
|
case 'quarter': output = monthDiff(this, that) / 3; break;
|
|
case 'second': output = (this - that) / 1e3; break; // 1000
|
|
case 'minute': output = (this - that) / 6e4; break; // 1000 * 60
|
|
case 'hour': output = (this - that) / 36e5; break; // 1000 * 60 * 60
|
|
case 'day': output = (this - that - zoneDelta) / 864e5; break; // 1000 * 60 * 60 * 24, negate dst
|
|
case 'week': output = (this - that - zoneDelta) / 6048e5; break; // 1000 * 60 * 60 * 24 * 7, negate dst
|
|
default: output = this - that;
|
|
}
|
|
|
|
return asFloat ? output : absFloor(output);
|
|
}
|
|
|
|
function monthDiff (a, b) {
|
|
// difference in months
|
|
var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
|
|
// b is in (anchor - 1 month, anchor + 1 month)
|
|
anchor = a.clone().add(wholeMonthDiff, 'months'),
|
|
anchor2, adjust;
|
|
|
|
if (b - anchor < 0) {
|
|
anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
|
|
// linear across the month
|
|
adjust = (b - anchor) / (anchor - anchor2);
|
|
} else {
|
|
anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
|
|
// linear across the month
|
|
adjust = (b - anchor) / (anchor2 - anchor);
|
|
}
|
|
|
|
//check for negative zero, return zero if negative zero
|
|
return -(wholeMonthDiff + adjust) || 0;
|
|
}
|
|
|
|
hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
|
|
hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
|
|
|
|
function toString () {
|
|
return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
|
|
}
|
|
|
|
function toISOString() {
|
|
if (!this.isValid()) {
|
|
return null;
|
|
}
|
|
var m = this.clone().utc();
|
|
if (m.year() < 0 || m.year() > 9999) {
|
|
return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
|
|
}
|
|
if (isFunction(Date.prototype.toISOString)) {
|
|
// native implementation is ~50x faster, use it when we can
|
|
return this.toDate().toISOString();
|
|
}
|
|
return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
|
|
}
|
|
|
|
/**
|
|
* Return a human readable representation of a moment that can
|
|
* also be evaluated to get a new moment which is the same
|
|
*
|
|
* @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
|
|
*/
|
|
function inspect () {
|
|
if (!this.isValid()) {
|
|
return 'moment.invalid(/* ' + this._i + ' */)';
|
|
}
|
|
var func = 'moment';
|
|
var zone = '';
|
|
if (!this.isLocal()) {
|
|
func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
|
|
zone = 'Z';
|
|
}
|
|
var prefix = '[' + func + '("]';
|
|
var year = (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
|
|
var datetime = '-MM-DD[T]HH:mm:ss.SSS';
|
|
var suffix = zone + '[")]';
|
|
|
|
return this.format(prefix + year + datetime + suffix);
|
|
}
|
|
|
|
function format (inputString) {
|
|
if (!inputString) {
|
|
inputString = this.isUtc() ? hooks.defaultFormatUtc : hooks.defaultFormat;
|
|
}
|
|
var output = formatMoment(this, inputString);
|
|
return this.localeData().postformat(output);
|
|
}
|
|
|
|
function from (time, withoutSuffix) {
|
|
if (this.isValid() &&
|
|
((isMoment(time) && time.isValid()) ||
|
|
createLocal(time).isValid())) {
|
|
return createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
|
|
} else {
|
|
return this.localeData().invalidDate();
|
|
}
|
|
}
|
|
|
|
function fromNow (withoutSuffix) {
|
|
return this.from(createLocal(), withoutSuffix);
|
|
}
|
|
|
|
function to (time, withoutSuffix) {
|
|
if (this.isValid() &&
|
|
((isMoment(time) && time.isValid()) ||
|
|
createLocal(time).isValid())) {
|
|
return createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
|
|
} else {
|
|
return this.localeData().invalidDate();
|
|
}
|
|
}
|
|
|
|
function toNow (withoutSuffix) {
|
|
return this.to(createLocal(), withoutSuffix);
|
|
}
|
|
|
|
// If passed a locale key, it will set the locale for this
|
|
// instance. Otherwise, it will return the locale configuration
|
|
// variables for this instance.
|
|
function locale (key) {
|
|
var newLocaleData;
|
|
|
|
if (key === undefined) {
|
|
return this._locale._abbr;
|
|
} else {
|
|
newLocaleData = getLocale(key);
|
|
if (newLocaleData != null) {
|
|
this._locale = newLocaleData;
|
|
}
|
|
return this;
|
|
}
|
|
}
|
|
|
|
var lang = deprecate(
|
|
'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
|
|
function (key) {
|
|
if (key === undefined) {
|
|
return this.localeData();
|
|
} else {
|
|
return this.locale(key);
|
|
}
|
|
}
|
|
);
|
|
|
|
function localeData () {
|
|
return this._locale;
|
|
}
|
|
|
|
function startOf (units) {
|
|
units = normalizeUnits(units);
|
|
// the following switch intentionally omits break keywords
|
|
// to utilize falling through the cases.
|
|
switch (units) {
|
|
case 'year':
|
|
this.month(0);
|
|
/* falls through */
|
|
case 'quarter':
|
|
case 'month':
|
|
this.date(1);
|
|
/* falls through */
|
|
case 'week':
|
|
case 'isoWeek':
|
|
case 'day':
|
|
case 'date':
|
|
this.hours(0);
|
|
/* falls through */
|
|
case 'hour':
|
|
this.minutes(0);
|
|
/* falls through */
|
|
case 'minute':
|
|
this.seconds(0);
|
|
/* falls through */
|
|
case 'second':
|
|
this.milliseconds(0);
|
|
}
|
|
|
|
// weeks are a special case
|
|
if (units === 'week') {
|
|
this.weekday(0);
|
|
}
|
|
if (units === 'isoWeek') {
|
|
this.isoWeekday(1);
|
|
}
|
|
|
|
// quarters are also special
|
|
if (units === 'quarter') {
|
|
this.month(Math.floor(this.month() / 3) * 3);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
function endOf (units) {
|
|
units = normalizeUnits(units);
|
|
if (units === undefined || units === 'millisecond') {
|
|
return this;
|
|
}
|
|
|
|
// 'date' is an alias for 'day', so it should be considered as such.
|
|
if (units === 'date') {
|
|
units = 'day';
|
|
}
|
|
|
|
return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
|
|
}
|
|
|
|
function valueOf () {
|
|
return this._d.valueOf() - ((this._offset || 0) * 60000);
|
|
}
|
|
|
|
function unix () {
|
|
return Math.floor(this.valueOf() / 1000);
|
|
}
|
|
|
|
function toDate () {
|
|
return new Date(this.valueOf());
|
|
}
|
|
|
|
function toArray () {
|
|
var m = this;
|
|
return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
|
|
}
|
|
|
|
function toObject () {
|
|
var m = this;
|
|
return {
|
|
years: m.year(),
|
|
months: m.month(),
|
|
date: m.date(),
|
|
hours: m.hours(),
|
|
minutes: m.minutes(),
|
|
seconds: m.seconds(),
|
|
milliseconds: m.milliseconds()
|
|
};
|
|
}
|
|
|
|
function toJSON () {
|
|
// new Date(NaN).toJSON() === null
|
|
return this.isValid() ? this.toISOString() : null;
|
|
}
|
|
|
|
function isValid$2 () {
|
|
return isValid(this);
|
|
}
|
|
|
|
function parsingFlags () {
|
|
return extend({}, getParsingFlags(this));
|
|
}
|
|
|
|
function invalidAt () {
|
|
return getParsingFlags(this).overflow;
|
|
}
|
|
|
|
function creationData() {
|
|
return {
|
|
input: this._i,
|
|
format: this._f,
|
|
locale: this._locale,
|
|
isUTC: this._isUTC,
|
|
strict: this._strict
|
|
};
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken(0, ['gg', 2], 0, function () {
|
|
return this.weekYear() % 100;
|
|
});
|
|
|
|
addFormatToken(0, ['GG', 2], 0, function () {
|
|
return this.isoWeekYear() % 100;
|
|
});
|
|
|
|
function addWeekYearFormatToken (token, getter) {
|
|
addFormatToken(0, [token, token.length], 0, getter);
|
|
}
|
|
|
|
addWeekYearFormatToken('gggg', 'weekYear');
|
|
addWeekYearFormatToken('ggggg', 'weekYear');
|
|
addWeekYearFormatToken('GGGG', 'isoWeekYear');
|
|
addWeekYearFormatToken('GGGGG', 'isoWeekYear');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('weekYear', 'gg');
|
|
addUnitAlias('isoWeekYear', 'GG');
|
|
|
|
// PRIORITY
|
|
|
|
addUnitPriority('weekYear', 1);
|
|
addUnitPriority('isoWeekYear', 1);
|
|
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('G', matchSigned);
|
|
addRegexToken('g', matchSigned);
|
|
addRegexToken('GG', match1to2, match2);
|
|
addRegexToken('gg', match1to2, match2);
|
|
addRegexToken('GGGG', match1to4, match4);
|
|
addRegexToken('gggg', match1to4, match4);
|
|
addRegexToken('GGGGG', match1to6, match6);
|
|
addRegexToken('ggggg', match1to6, match6);
|
|
|
|
addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
|
|
week[token.substr(0, 2)] = toInt(input);
|
|
});
|
|
|
|
addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
|
|
week[token] = hooks.parseTwoDigitYear(input);
|
|
});
|
|
|
|
// MOMENTS
|
|
|
|
function getSetWeekYear (input) {
|
|
return getSetWeekYearHelper.call(this,
|
|
input,
|
|
this.week(),
|
|
this.weekday(),
|
|
this.localeData()._week.dow,
|
|
this.localeData()._week.doy);
|
|
}
|
|
|
|
function getSetISOWeekYear (input) {
|
|
return getSetWeekYearHelper.call(this,
|
|
input, this.isoWeek(), this.isoWeekday(), 1, 4);
|
|
}
|
|
|
|
function getISOWeeksInYear () {
|
|
return weeksInYear(this.year(), 1, 4);
|
|
}
|
|
|
|
function getWeeksInYear () {
|
|
var weekInfo = this.localeData()._week;
|
|
return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
|
|
}
|
|
|
|
function getSetWeekYearHelper(input, week, weekday, dow, doy) {
|
|
var weeksTarget;
|
|
if (input == null) {
|
|
return weekOfYear(this, dow, doy).year;
|
|
} else {
|
|
weeksTarget = weeksInYear(input, dow, doy);
|
|
if (week > weeksTarget) {
|
|
week = weeksTarget;
|
|
}
|
|
return setWeekAll.call(this, input, week, weekday, dow, doy);
|
|
}
|
|
}
|
|
|
|
function setWeekAll(weekYear, week, weekday, dow, doy) {
|
|
var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
|
|
date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
|
|
|
|
this.year(date.getUTCFullYear());
|
|
this.month(date.getUTCMonth());
|
|
this.date(date.getUTCDate());
|
|
return this;
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('Q', 0, 'Qo', 'quarter');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('quarter', 'Q');
|
|
|
|
// PRIORITY
|
|
|
|
addUnitPriority('quarter', 7);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('Q', match1);
|
|
addParseToken('Q', function (input, array) {
|
|
array[MONTH] = (toInt(input) - 1) * 3;
|
|
});
|
|
|
|
// MOMENTS
|
|
|
|
function getSetQuarter (input) {
|
|
return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('D', ['DD', 2], 'Do', 'date');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('date', 'D');
|
|
|
|
// PRIOROITY
|
|
addUnitPriority('date', 9);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('D', match1to2);
|
|
addRegexToken('DD', match1to2, match2);
|
|
addRegexToken('Do', function (isStrict, locale) {
|
|
// TODO: Remove "ordinalParse" fallback in next major release.
|
|
return isStrict ?
|
|
(locale._dayOfMonthOrdinalParse || locale._ordinalParse) :
|
|
locale._dayOfMonthOrdinalParseLenient;
|
|
});
|
|
|
|
addParseToken(['D', 'DD'], DATE);
|
|
addParseToken('Do', function (input, array) {
|
|
array[DATE] = toInt(input.match(match1to2)[0], 10);
|
|
});
|
|
|
|
// MOMENTS
|
|
|
|
var getSetDayOfMonth = makeGetSet('Date', true);
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('dayOfYear', 'DDD');
|
|
|
|
// PRIORITY
|
|
addUnitPriority('dayOfYear', 4);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('DDD', match1to3);
|
|
addRegexToken('DDDD', match3);
|
|
addParseToken(['DDD', 'DDDD'], function (input, array, config) {
|
|
config._dayOfYear = toInt(input);
|
|
});
|
|
|
|
// HELPERS
|
|
|
|
// MOMENTS
|
|
|
|
function getSetDayOfYear (input) {
|
|
var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
|
|
return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
|
|
}
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('m', ['mm', 2], 0, 'minute');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('minute', 'm');
|
|
|
|
// PRIORITY
|
|
|
|
addUnitPriority('minute', 14);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('m', match1to2);
|
|
addRegexToken('mm', match1to2, match2);
|
|
addParseToken(['m', 'mm'], MINUTE);
|
|
|
|
// MOMENTS
|
|
|
|
var getSetMinute = makeGetSet('Minutes', false);
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('s', ['ss', 2], 0, 'second');
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('second', 's');
|
|
|
|
// PRIORITY
|
|
|
|
addUnitPriority('second', 15);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('s', match1to2);
|
|
addRegexToken('ss', match1to2, match2);
|
|
addParseToken(['s', 'ss'], SECOND);
|
|
|
|
// MOMENTS
|
|
|
|
var getSetSecond = makeGetSet('Seconds', false);
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('S', 0, 0, function () {
|
|
return ~~(this.millisecond() / 100);
|
|
});
|
|
|
|
addFormatToken(0, ['SS', 2], 0, function () {
|
|
return ~~(this.millisecond() / 10);
|
|
});
|
|
|
|
addFormatToken(0, ['SSS', 3], 0, 'millisecond');
|
|
addFormatToken(0, ['SSSS', 4], 0, function () {
|
|
return this.millisecond() * 10;
|
|
});
|
|
addFormatToken(0, ['SSSSS', 5], 0, function () {
|
|
return this.millisecond() * 100;
|
|
});
|
|
addFormatToken(0, ['SSSSSS', 6], 0, function () {
|
|
return this.millisecond() * 1000;
|
|
});
|
|
addFormatToken(0, ['SSSSSSS', 7], 0, function () {
|
|
return this.millisecond() * 10000;
|
|
});
|
|
addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
|
|
return this.millisecond() * 100000;
|
|
});
|
|
addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
|
|
return this.millisecond() * 1000000;
|
|
});
|
|
|
|
|
|
// ALIASES
|
|
|
|
addUnitAlias('millisecond', 'ms');
|
|
|
|
// PRIORITY
|
|
|
|
addUnitPriority('millisecond', 16);
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('S', match1to3, match1);
|
|
addRegexToken('SS', match1to3, match2);
|
|
addRegexToken('SSS', match1to3, match3);
|
|
|
|
var token;
|
|
for (token = 'SSSS'; token.length <= 9; token += 'S') {
|
|
addRegexToken(token, matchUnsigned);
|
|
}
|
|
|
|
function parseMs(input, array) {
|
|
array[MILLISECOND] = toInt(('0.' + input) * 1000);
|
|
}
|
|
|
|
for (token = 'S'; token.length <= 9; token += 'S') {
|
|
addParseToken(token, parseMs);
|
|
}
|
|
// MOMENTS
|
|
|
|
var getSetMillisecond = makeGetSet('Milliseconds', false);
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('z', 0, 0, 'zoneAbbr');
|
|
addFormatToken('zz', 0, 0, 'zoneName');
|
|
|
|
// MOMENTS
|
|
|
|
function getZoneAbbr () {
|
|
return this._isUTC ? 'UTC' : '';
|
|
}
|
|
|
|
function getZoneName () {
|
|
return this._isUTC ? 'Coordinated Universal Time' : '';
|
|
}
|
|
|
|
var proto = Moment.prototype;
|
|
|
|
proto.add = add;
|
|
proto.calendar = calendar$1;
|
|
proto.clone = clone;
|
|
proto.diff = diff;
|
|
proto.endOf = endOf;
|
|
proto.format = format;
|
|
proto.from = from;
|
|
proto.fromNow = fromNow;
|
|
proto.to = to;
|
|
proto.toNow = toNow;
|
|
proto.get = stringGet;
|
|
proto.invalidAt = invalidAt;
|
|
proto.isAfter = isAfter;
|
|
proto.isBefore = isBefore;
|
|
proto.isBetween = isBetween;
|
|
proto.isSame = isSame;
|
|
proto.isSameOrAfter = isSameOrAfter;
|
|
proto.isSameOrBefore = isSameOrBefore;
|
|
proto.isValid = isValid$2;
|
|
proto.lang = lang;
|
|
proto.locale = locale;
|
|
proto.localeData = localeData;
|
|
proto.max = prototypeMax;
|
|
proto.min = prototypeMin;
|
|
proto.parsingFlags = parsingFlags;
|
|
proto.set = stringSet;
|
|
proto.startOf = startOf;
|
|
proto.subtract = subtract;
|
|
proto.toArray = toArray;
|
|
proto.toObject = toObject;
|
|
proto.toDate = toDate;
|
|
proto.toISOString = toISOString;
|
|
proto.inspect = inspect;
|
|
proto.toJSON = toJSON;
|
|
proto.toString = toString;
|
|
proto.unix = unix;
|
|
proto.valueOf = valueOf;
|
|
proto.creationData = creationData;
|
|
|
|
// Year
|
|
proto.year = getSetYear;
|
|
proto.isLeapYear = getIsLeapYear;
|
|
|
|
// Week Year
|
|
proto.weekYear = getSetWeekYear;
|
|
proto.isoWeekYear = getSetISOWeekYear;
|
|
|
|
// Quarter
|
|
proto.quarter = proto.quarters = getSetQuarter;
|
|
|
|
// Month
|
|
proto.month = getSetMonth;
|
|
proto.daysInMonth = getDaysInMonth;
|
|
|
|
// Week
|
|
proto.week = proto.weeks = getSetWeek;
|
|
proto.isoWeek = proto.isoWeeks = getSetISOWeek;
|
|
proto.weeksInYear = getWeeksInYear;
|
|
proto.isoWeeksInYear = getISOWeeksInYear;
|
|
|
|
// Day
|
|
proto.date = getSetDayOfMonth;
|
|
proto.day = proto.days = getSetDayOfWeek;
|
|
proto.weekday = getSetLocaleDayOfWeek;
|
|
proto.isoWeekday = getSetISODayOfWeek;
|
|
proto.dayOfYear = getSetDayOfYear;
|
|
|
|
// Hour
|
|
proto.hour = proto.hours = getSetHour;
|
|
|
|
// Minute
|
|
proto.minute = proto.minutes = getSetMinute;
|
|
|
|
// Second
|
|
proto.second = proto.seconds = getSetSecond;
|
|
|
|
// Millisecond
|
|
proto.millisecond = proto.milliseconds = getSetMillisecond;
|
|
|
|
// Offset
|
|
proto.utcOffset = getSetOffset;
|
|
proto.utc = setOffsetToUTC;
|
|
proto.local = setOffsetToLocal;
|
|
proto.parseZone = setOffsetToParsedOffset;
|
|
proto.hasAlignedHourOffset = hasAlignedHourOffset;
|
|
proto.isDST = isDaylightSavingTime;
|
|
proto.isLocal = isLocal;
|
|
proto.isUtcOffset = isUtcOffset;
|
|
proto.isUtc = isUtc;
|
|
proto.isUTC = isUtc;
|
|
|
|
// Timezone
|
|
proto.zoneAbbr = getZoneAbbr;
|
|
proto.zoneName = getZoneName;
|
|
|
|
// Deprecations
|
|
proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
|
|
proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
|
|
proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
|
|
proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone);
|
|
proto.isDSTShifted = deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted);
|
|
|
|
function createUnix (input) {
|
|
return createLocal(input * 1000);
|
|
}
|
|
|
|
function createInZone () {
|
|
return createLocal.apply(null, arguments).parseZone();
|
|
}
|
|
|
|
function preParsePostFormat (string) {
|
|
return string;
|
|
}
|
|
|
|
var proto$1 = Locale.prototype;
|
|
|
|
proto$1.calendar = calendar;
|
|
proto$1.longDateFormat = longDateFormat;
|
|
proto$1.invalidDate = invalidDate;
|
|
proto$1.ordinal = ordinal;
|
|
proto$1.preparse = preParsePostFormat;
|
|
proto$1.postformat = preParsePostFormat;
|
|
proto$1.relativeTime = relativeTime;
|
|
proto$1.pastFuture = pastFuture;
|
|
proto$1.set = set;
|
|
|
|
// Month
|
|
proto$1.months = localeMonths;
|
|
proto$1.monthsShort = localeMonthsShort;
|
|
proto$1.monthsParse = localeMonthsParse;
|
|
proto$1.monthsRegex = monthsRegex;
|
|
proto$1.monthsShortRegex = monthsShortRegex;
|
|
|
|
// Week
|
|
proto$1.week = localeWeek;
|
|
proto$1.firstDayOfYear = localeFirstDayOfYear;
|
|
proto$1.firstDayOfWeek = localeFirstDayOfWeek;
|
|
|
|
// Day of Week
|
|
proto$1.weekdays = localeWeekdays;
|
|
proto$1.weekdaysMin = localeWeekdaysMin;
|
|
proto$1.weekdaysShort = localeWeekdaysShort;
|
|
proto$1.weekdaysParse = localeWeekdaysParse;
|
|
|
|
proto$1.weekdaysRegex = weekdaysRegex;
|
|
proto$1.weekdaysShortRegex = weekdaysShortRegex;
|
|
proto$1.weekdaysMinRegex = weekdaysMinRegex;
|
|
|
|
// Hours
|
|
proto$1.isPM = localeIsPM;
|
|
proto$1.meridiem = localeMeridiem;
|
|
|
|
function get$1 (format, index, field, setter) {
|
|
var locale = getLocale();
|
|
var utc = createUTC().set(setter, index);
|
|
return locale[field](utc, format);
|
|
}
|
|
|
|
function listMonthsImpl (format, index, field) {
|
|
if (isNumber(format)) {
|
|
index = format;
|
|
format = undefined;
|
|
}
|
|
|
|
format = format || '';
|
|
|
|
if (index != null) {
|
|
return get$1(format, index, field, 'month');
|
|
}
|
|
|
|
var i;
|
|
var out = [];
|
|
for (i = 0; i < 12; i++) {
|
|
out[i] = get$1(format, i, field, 'month');
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// ()
|
|
// (5)
|
|
// (fmt, 5)
|
|
// (fmt)
|
|
// (true)
|
|
// (true, 5)
|
|
// (true, fmt, 5)
|
|
// (true, fmt)
|
|
function listWeekdaysImpl (localeSorted, format, index, field) {
|
|
if (typeof localeSorted === 'boolean') {
|
|
if (isNumber(format)) {
|
|
index = format;
|
|
format = undefined;
|
|
}
|
|
|
|
format = format || '';
|
|
} else {
|
|
format = localeSorted;
|
|
index = format;
|
|
localeSorted = false;
|
|
|
|
if (isNumber(format)) {
|
|
index = format;
|
|
format = undefined;
|
|
}
|
|
|
|
format = format || '';
|
|
}
|
|
|
|
var locale = getLocale(),
|
|
shift = localeSorted ? locale._week.dow : 0;
|
|
|
|
if (index != null) {
|
|
return get$1(format, (index + shift) % 7, field, 'day');
|
|
}
|
|
|
|
var i;
|
|
var out = [];
|
|
for (i = 0; i < 7; i++) {
|
|
out[i] = get$1(format, (i + shift) % 7, field, 'day');
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function listMonths (format, index) {
|
|
return listMonthsImpl(format, index, 'months');
|
|
}
|
|
|
|
function listMonthsShort (format, index) {
|
|
return listMonthsImpl(format, index, 'monthsShort');
|
|
}
|
|
|
|
function listWeekdays (localeSorted, format, index) {
|
|
return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
|
|
}
|
|
|
|
function listWeekdaysShort (localeSorted, format, index) {
|
|
return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
|
|
}
|
|
|
|
function listWeekdaysMin (localeSorted, format, index) {
|
|
return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
|
|
}
|
|
|
|
getSetGlobalLocale('en', {
|
|
dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
|
|
ordinal : function (number) {
|
|
var b = number % 10,
|
|
output = (toInt(number % 100 / 10) === 1) ? 'th' :
|
|
(b === 1) ? 'st' :
|
|
(b === 2) ? 'nd' :
|
|
(b === 3) ? 'rd' : 'th';
|
|
return number + output;
|
|
}
|
|
});
|
|
|
|
// Side effect imports
|
|
hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale);
|
|
hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale);
|
|
|
|
var mathAbs = Math.abs;
|
|
|
|
function abs () {
|
|
var data = this._data;
|
|
|
|
this._milliseconds = mathAbs(this._milliseconds);
|
|
this._days = mathAbs(this._days);
|
|
this._months = mathAbs(this._months);
|
|
|
|
data.milliseconds = mathAbs(data.milliseconds);
|
|
data.seconds = mathAbs(data.seconds);
|
|
data.minutes = mathAbs(data.minutes);
|
|
data.hours = mathAbs(data.hours);
|
|
data.months = mathAbs(data.months);
|
|
data.years = mathAbs(data.years);
|
|
|
|
return this;
|
|
}
|
|
|
|
function addSubtract$1 (duration, input, value, direction) {
|
|
var other = createDuration(input, value);
|
|
|
|
duration._milliseconds += direction * other._milliseconds;
|
|
duration._days += direction * other._days;
|
|
duration._months += direction * other._months;
|
|
|
|
return duration._bubble();
|
|
}
|
|
|
|
// supports only 2.0-style add(1, 's') or add(duration)
|
|
function add$1 (input, value) {
|
|
return addSubtract$1(this, input, value, 1);
|
|
}
|
|
|
|
// supports only 2.0-style subtract(1, 's') or subtract(duration)
|
|
function subtract$1 (input, value) {
|
|
return addSubtract$1(this, input, value, -1);
|
|
}
|
|
|
|
function absCeil (number) {
|
|
if (number < 0) {
|
|
return Math.floor(number);
|
|
} else {
|
|
return Math.ceil(number);
|
|
}
|
|
}
|
|
|
|
function bubble () {
|
|
var milliseconds = this._milliseconds;
|
|
var days = this._days;
|
|
var months = this._months;
|
|
var data = this._data;
|
|
var seconds, minutes, hours, years, monthsFromDays;
|
|
|
|
// if we have a mix of positive and negative values, bubble down first
|
|
// check: https://github.com/moment/moment/issues/2166
|
|
if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
|
|
(milliseconds <= 0 && days <= 0 && months <= 0))) {
|
|
milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
|
|
days = 0;
|
|
months = 0;
|
|
}
|
|
|
|
// The following code bubbles up values, see the tests for
|
|
// examples of what that means.
|
|
data.milliseconds = milliseconds % 1000;
|
|
|
|
seconds = absFloor(milliseconds / 1000);
|
|
data.seconds = seconds % 60;
|
|
|
|
minutes = absFloor(seconds / 60);
|
|
data.minutes = minutes % 60;
|
|
|
|
hours = absFloor(minutes / 60);
|
|
data.hours = hours % 24;
|
|
|
|
days += absFloor(hours / 24);
|
|
|
|
// convert days to months
|
|
monthsFromDays = absFloor(daysToMonths(days));
|
|
months += monthsFromDays;
|
|
days -= absCeil(monthsToDays(monthsFromDays));
|
|
|
|
// 12 months -> 1 year
|
|
years = absFloor(months / 12);
|
|
months %= 12;
|
|
|
|
data.days = days;
|
|
data.months = months;
|
|
data.years = years;
|
|
|
|
return this;
|
|
}
|
|
|
|
function daysToMonths (days) {
|
|
// 400 years have 146097 days (taking into account leap year rules)
|
|
// 400 years have 12 months === 4800
|
|
return days * 4800 / 146097;
|
|
}
|
|
|
|
function monthsToDays (months) {
|
|
// the reverse of daysToMonths
|
|
return months * 146097 / 4800;
|
|
}
|
|
|
|
function as (units) {
|
|
if (!this.isValid()) {
|
|
return NaN;
|
|
}
|
|
var days;
|
|
var months;
|
|
var milliseconds = this._milliseconds;
|
|
|
|
units = normalizeUnits(units);
|
|
|
|
if (units === 'month' || units === 'year') {
|
|
days = this._days + milliseconds / 864e5;
|
|
months = this._months + daysToMonths(days);
|
|
return units === 'month' ? months : months / 12;
|
|
} else {
|
|
// handle milliseconds separately because of floating point math errors (issue #1867)
|
|
days = this._days + Math.round(monthsToDays(this._months));
|
|
switch (units) {
|
|
case 'week' : return days / 7 + milliseconds / 6048e5;
|
|
case 'day' : return days + milliseconds / 864e5;
|
|
case 'hour' : return days * 24 + milliseconds / 36e5;
|
|
case 'minute' : return days * 1440 + milliseconds / 6e4;
|
|
case 'second' : return days * 86400 + milliseconds / 1000;
|
|
// Math.floor prevents floating point math errors here
|
|
case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
|
|
default: throw new Error('Unknown unit ' + units);
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: Use this.as('ms')?
|
|
function valueOf$1 () {
|
|
if (!this.isValid()) {
|
|
return NaN;
|
|
}
|
|
return (
|
|
this._milliseconds +
|
|
this._days * 864e5 +
|
|
(this._months % 12) * 2592e6 +
|
|
toInt(this._months / 12) * 31536e6
|
|
);
|
|
}
|
|
|
|
function makeAs (alias) {
|
|
return function () {
|
|
return this.as(alias);
|
|
};
|
|
}
|
|
|
|
var asMilliseconds = makeAs('ms');
|
|
var asSeconds = makeAs('s');
|
|
var asMinutes = makeAs('m');
|
|
var asHours = makeAs('h');
|
|
var asDays = makeAs('d');
|
|
var asWeeks = makeAs('w');
|
|
var asMonths = makeAs('M');
|
|
var asYears = makeAs('y');
|
|
|
|
function clone$1 () {
|
|
return createDuration(this);
|
|
}
|
|
|
|
function get$2 (units) {
|
|
units = normalizeUnits(units);
|
|
return this.isValid() ? this[units + 's']() : NaN;
|
|
}
|
|
|
|
function makeGetter(name) {
|
|
return function () {
|
|
return this.isValid() ? this._data[name] : NaN;
|
|
};
|
|
}
|
|
|
|
var milliseconds = makeGetter('milliseconds');
|
|
var seconds = makeGetter('seconds');
|
|
var minutes = makeGetter('minutes');
|
|
var hours = makeGetter('hours');
|
|
var days = makeGetter('days');
|
|
var months = makeGetter('months');
|
|
var years = makeGetter('years');
|
|
|
|
function weeks () {
|
|
return absFloor(this.days() / 7);
|
|
}
|
|
|
|
var round = Math.round;
|
|
var thresholds = {
|
|
ss: 44, // a few seconds to seconds
|
|
s : 45, // seconds to minute
|
|
m : 45, // minutes to hour
|
|
h : 22, // hours to day
|
|
d : 26, // days to month
|
|
M : 11 // months to year
|
|
};
|
|
|
|
// helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
|
|
function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
|
|
return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
|
|
}
|
|
|
|
function relativeTime$1 (posNegDuration, withoutSuffix, locale) {
|
|
var duration = createDuration(posNegDuration).abs();
|
|
var seconds = round(duration.as('s'));
|
|
var minutes = round(duration.as('m'));
|
|
var hours = round(duration.as('h'));
|
|
var days = round(duration.as('d'));
|
|
var months = round(duration.as('M'));
|
|
var years = round(duration.as('y'));
|
|
|
|
var a = seconds <= thresholds.ss && ['s', seconds] ||
|
|
seconds < thresholds.s && ['ss', seconds] ||
|
|
minutes <= 1 && ['m'] ||
|
|
minutes < thresholds.m && ['mm', minutes] ||
|
|
hours <= 1 && ['h'] ||
|
|
hours < thresholds.h && ['hh', hours] ||
|
|
days <= 1 && ['d'] ||
|
|
days < thresholds.d && ['dd', days] ||
|
|
months <= 1 && ['M'] ||
|
|
months < thresholds.M && ['MM', months] ||
|
|
years <= 1 && ['y'] || ['yy', years];
|
|
|
|
a[2] = withoutSuffix;
|
|
a[3] = +posNegDuration > 0;
|
|
a[4] = locale;
|
|
return substituteTimeAgo.apply(null, a);
|
|
}
|
|
|
|
// This function allows you to set the rounding function for relative time strings
|
|
function getSetRelativeTimeRounding (roundingFunction) {
|
|
if (roundingFunction === undefined) {
|
|
return round;
|
|
}
|
|
if (typeof(roundingFunction) === 'function') {
|
|
round = roundingFunction;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// This function allows you to set a threshold for relative time strings
|
|
function getSetRelativeTimeThreshold (threshold, limit) {
|
|
if (thresholds[threshold] === undefined) {
|
|
return false;
|
|
}
|
|
if (limit === undefined) {
|
|
return thresholds[threshold];
|
|
}
|
|
thresholds[threshold] = limit;
|
|
if (threshold === 's') {
|
|
thresholds.ss = limit - 1;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function humanize (withSuffix) {
|
|
if (!this.isValid()) {
|
|
return this.localeData().invalidDate();
|
|
}
|
|
|
|
var locale = this.localeData();
|
|
var output = relativeTime$1(this, !withSuffix, locale);
|
|
|
|
if (withSuffix) {
|
|
output = locale.pastFuture(+this, output);
|
|
}
|
|
|
|
return locale.postformat(output);
|
|
}
|
|
|
|
var abs$1 = Math.abs;
|
|
|
|
function sign(x) {
|
|
return ((x > 0) - (x < 0)) || +x;
|
|
}
|
|
|
|
function toISOString$1() {
|
|
// for ISO strings we do not use the normal bubbling rules:
|
|
// * milliseconds bubble up until they become hours
|
|
// * days do not bubble at all
|
|
// * months bubble up until they become years
|
|
// This is because there is no context-free conversion between hours and days
|
|
// (think of clock changes)
|
|
// and also not between days and months (28-31 days per month)
|
|
if (!this.isValid()) {
|
|
return this.localeData().invalidDate();
|
|
}
|
|
|
|
var seconds = abs$1(this._milliseconds) / 1000;
|
|
var days = abs$1(this._days);
|
|
var months = abs$1(this._months);
|
|
var minutes, hours, years;
|
|
|
|
// 3600 seconds -> 60 minutes -> 1 hour
|
|
minutes = absFloor(seconds / 60);
|
|
hours = absFloor(minutes / 60);
|
|
seconds %= 60;
|
|
minutes %= 60;
|
|
|
|
// 12 months -> 1 year
|
|
years = absFloor(months / 12);
|
|
months %= 12;
|
|
|
|
|
|
// inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
|
|
var Y = years;
|
|
var M = months;
|
|
var D = days;
|
|
var h = hours;
|
|
var m = minutes;
|
|
var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
|
|
var total = this.asSeconds();
|
|
|
|
if (!total) {
|
|
// this is the same as C#'s (Noda) and python (isodate)...
|
|
// but not other JS (goog.date)
|
|
return 'P0D';
|
|
}
|
|
|
|
var totalSign = total < 0 ? '-' : '';
|
|
var ymSign = sign(this._months) !== sign(total) ? '-' : '';
|
|
var daysSign = sign(this._days) !== sign(total) ? '-' : '';
|
|
var hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
|
|
|
|
return totalSign + 'P' +
|
|
(Y ? ymSign + Y + 'Y' : '') +
|
|
(M ? ymSign + M + 'M' : '') +
|
|
(D ? daysSign + D + 'D' : '') +
|
|
((h || m || s) ? 'T' : '') +
|
|
(h ? hmsSign + h + 'H' : '') +
|
|
(m ? hmsSign + m + 'M' : '') +
|
|
(s ? hmsSign + s + 'S' : '');
|
|
}
|
|
|
|
var proto$2 = Duration.prototype;
|
|
|
|
proto$2.isValid = isValid$1;
|
|
proto$2.abs = abs;
|
|
proto$2.add = add$1;
|
|
proto$2.subtract = subtract$1;
|
|
proto$2.as = as;
|
|
proto$2.asMilliseconds = asMilliseconds;
|
|
proto$2.asSeconds = asSeconds;
|
|
proto$2.asMinutes = asMinutes;
|
|
proto$2.asHours = asHours;
|
|
proto$2.asDays = asDays;
|
|
proto$2.asWeeks = asWeeks;
|
|
proto$2.asMonths = asMonths;
|
|
proto$2.asYears = asYears;
|
|
proto$2.valueOf = valueOf$1;
|
|
proto$2._bubble = bubble;
|
|
proto$2.clone = clone$1;
|
|
proto$2.get = get$2;
|
|
proto$2.milliseconds = milliseconds;
|
|
proto$2.seconds = seconds;
|
|
proto$2.minutes = minutes;
|
|
proto$2.hours = hours;
|
|
proto$2.days = days;
|
|
proto$2.weeks = weeks;
|
|
proto$2.months = months;
|
|
proto$2.years = years;
|
|
proto$2.humanize = humanize;
|
|
proto$2.toISOString = toISOString$1;
|
|
proto$2.toString = toISOString$1;
|
|
proto$2.toJSON = toISOString$1;
|
|
proto$2.locale = locale;
|
|
proto$2.localeData = localeData;
|
|
|
|
// Deprecations
|
|
proto$2.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString$1);
|
|
proto$2.lang = lang;
|
|
|
|
// Side effect imports
|
|
|
|
// FORMATTING
|
|
|
|
addFormatToken('X', 0, 0, 'unix');
|
|
addFormatToken('x', 0, 0, 'valueOf');
|
|
|
|
// PARSING
|
|
|
|
addRegexToken('x', matchSigned);
|
|
addRegexToken('X', matchTimestamp);
|
|
addParseToken('X', function (input, array, config) {
|
|
config._d = new Date(parseFloat(input, 10) * 1000);
|
|
});
|
|
addParseToken('x', function (input, array, config) {
|
|
config._d = new Date(toInt(input));
|
|
});
|
|
|
|
// Side effect imports
|
|
|
|
|
|
hooks.version = '2.19.2';
|
|
|
|
setHookCallback(createLocal);
|
|
|
|
hooks.fn = proto;
|
|
hooks.min = min;
|
|
hooks.max = max;
|
|
hooks.now = now;
|
|
hooks.utc = createUTC;
|
|
hooks.unix = createUnix;
|
|
hooks.months = listMonths;
|
|
hooks.isDate = isDate;
|
|
hooks.locale = getSetGlobalLocale;
|
|
hooks.invalid = createInvalid;
|
|
hooks.duration = createDuration;
|
|
hooks.isMoment = isMoment;
|
|
hooks.weekdays = listWeekdays;
|
|
hooks.parseZone = createInZone;
|
|
hooks.localeData = getLocale;
|
|
hooks.isDuration = isDuration;
|
|
hooks.monthsShort = listMonthsShort;
|
|
hooks.weekdaysMin = listWeekdaysMin;
|
|
hooks.defineLocale = defineLocale;
|
|
hooks.updateLocale = updateLocale;
|
|
hooks.locales = listLocales;
|
|
hooks.weekdaysShort = listWeekdaysShort;
|
|
hooks.normalizeUnits = normalizeUnits;
|
|
hooks.relativeTimeRounding = getSetRelativeTimeRounding;
|
|
hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
|
|
hooks.calendarFormat = getCalendarFormat;
|
|
hooks.prototype = proto;
|
|
|
|
return hooks;
|
|
|
|
})));
|
|
|
|
/*!
|
|
* Pikaday
|
|
*
|
|
* Copyright © 2014 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
|
|
*/
|
|
|
|
(function (root, factory)
|
|
{
|
|
'use strict';
|
|
|
|
var moment;
|
|
if (typeof exports === 'object') {
|
|
// CommonJS module
|
|
// Load moment.js as an optional dependency
|
|
try { moment = require('moment'); } catch (e) {}
|
|
module.exports = factory(moment);
|
|
} else if (typeof define === 'function' && define.amd) {
|
|
// AMD. Register as an anonymous module.
|
|
define(function (req)
|
|
{
|
|
// Load moment.js as an optional dependency
|
|
var id = 'moment';
|
|
try { moment = req(id); } catch (e) {}
|
|
return factory(moment);
|
|
});
|
|
} else {
|
|
root.Pikaday = factory(root.moment);
|
|
}
|
|
}(this, function (moment)
|
|
{
|
|
'use strict';
|
|
|
|
/**
|
|
* feature detection and helper functions
|
|
*/
|
|
var hasMoment = typeof moment === 'function',
|
|
|
|
hasEventListeners = !!window.addEventListener,
|
|
|
|
document = window.document,
|
|
|
|
sto = window.setTimeout,
|
|
|
|
addEvent = function(el, e, callback, capture)
|
|
{
|
|
if (hasEventListeners) {
|
|
el.addEventListener(e, callback, !!capture);
|
|
} else {
|
|
el.attachEvent('on' + e, callback);
|
|
}
|
|
},
|
|
|
|
removeEvent = function(el, e, callback, capture)
|
|
{
|
|
if (hasEventListeners) {
|
|
el.removeEventListener(e, callback, !!capture);
|
|
} else {
|
|
el.detachEvent('on' + e, callback);
|
|
}
|
|
},
|
|
|
|
trim = function(str)
|
|
{
|
|
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g,'');
|
|
},
|
|
|
|
hasClass = function(el, cn)
|
|
{
|
|
return (' ' + el.className + ' ').indexOf(' ' + cn + ' ') !== -1;
|
|
},
|
|
|
|
addClass = function(el, cn)
|
|
{
|
|
if (!hasClass(el, cn)) {
|
|
el.className = (el.className === '') ? cn : el.className + ' ' + cn;
|
|
}
|
|
},
|
|
|
|
removeClass = function(el, cn)
|
|
{
|
|
el.className = trim((' ' + el.className + ' ').replace(' ' + cn + ' ', ' '));
|
|
},
|
|
|
|
isArray = function(obj)
|
|
{
|
|
return (/Array/).test(Object.prototype.toString.call(obj));
|
|
},
|
|
|
|
isDate = function(obj)
|
|
{
|
|
return (/Date/).test(Object.prototype.toString.call(obj)) && !isNaN(obj.getTime());
|
|
},
|
|
|
|
isWeekend = function(date)
|
|
{
|
|
var day = date.getDay();
|
|
return day === 0 || day === 6;
|
|
},
|
|
|
|
isLeapYear = function(year)
|
|
{
|
|
// solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
|
|
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
},
|
|
|
|
getDaysInMonth = function(year, month)
|
|
{
|
|
return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
|
|
},
|
|
|
|
setToStartOfDay = function(date)
|
|
{
|
|
if (isDate(date)) date.setHours(0,0,0,0);
|
|
},
|
|
|
|
compareDates = function(a,b)
|
|
{
|
|
// weak date comparison (use setToStartOfDay(date) to ensure correct result)
|
|
return a.getTime() === b.getTime();
|
|
},
|
|
|
|
extend = function(to, from, overwrite)
|
|
{
|
|
var prop, hasProp;
|
|
for (prop in from) {
|
|
hasProp = to[prop] !== undefined;
|
|
if (hasProp && typeof from[prop] === 'object' && from[prop] !== null && from[prop].nodeName === undefined) {
|
|
if (isDate(from[prop])) {
|
|
if (overwrite) {
|
|
to[prop] = new Date(from[prop].getTime());
|
|
}
|
|
}
|
|
else if (isArray(from[prop])) {
|
|
if (overwrite) {
|
|
to[prop] = from[prop].slice(0);
|
|
}
|
|
} else {
|
|
to[prop] = extend({}, from[prop], overwrite);
|
|
}
|
|
} else if (overwrite || !hasProp) {
|
|
to[prop] = from[prop];
|
|
}
|
|
}
|
|
return to;
|
|
},
|
|
|
|
fireEvent = function(el, eventName, data)
|
|
{
|
|
var ev;
|
|
|
|
if (document.createEvent) {
|
|
ev = document.createEvent('HTMLEvents');
|
|
ev.initEvent(eventName, true, false);
|
|
ev = extend(ev, data);
|
|
el.dispatchEvent(ev);
|
|
} else if (document.createEventObject) {
|
|
ev = document.createEventObject();
|
|
ev = extend(ev, data);
|
|
el.fireEvent('on' + eventName, ev);
|
|
}
|
|
},
|
|
|
|
adjustCalendar = function(calendar) {
|
|
if (calendar.month < 0) {
|
|
calendar.year -= Math.ceil(Math.abs(calendar.month)/12);
|
|
calendar.month += 12;
|
|
}
|
|
if (calendar.month > 11) {
|
|
calendar.year += Math.floor(Math.abs(calendar.month)/12);
|
|
calendar.month -= 12;
|
|
}
|
|
return calendar;
|
|
},
|
|
|
|
/**
|
|
* defaults and localisation
|
|
*/
|
|
defaults = {
|
|
|
|
// bind the picker to a form field
|
|
field: null,
|
|
|
|
// automatically show/hide the picker on `field` focus (default `true` if `field` is set)
|
|
bound: undefined,
|
|
|
|
// position of the datepicker, relative to the field (default to bottom & left)
|
|
// ('bottom' & 'left' keywords are not used, 'top' & 'right' are modifier on the bottom/left position)
|
|
position: 'bottom left',
|
|
|
|
// automatically fit in the viewport even if it means repositioning from the position option
|
|
reposition: true,
|
|
|
|
// the default output format for `.toString()` and `field` value
|
|
format: 'YYYY-MM-DD',
|
|
|
|
// the toString function which gets passed a current date object and format
|
|
// and returns a string
|
|
toString: null,
|
|
|
|
// used to create date object from current input string
|
|
parse: null,
|
|
|
|
// the initial date to view when first opened
|
|
defaultDate: null,
|
|
|
|
// make the `defaultDate` the initial selected value
|
|
setDefaultDate: false,
|
|
|
|
// first day of week (0: Sunday, 1: Monday etc)
|
|
firstDay: 0,
|
|
|
|
// the default flag for moment's strict date parsing
|
|
formatStrict: false,
|
|
|
|
// the minimum/earliest date that can be selected
|
|
minDate: null,
|
|
// the maximum/latest date that can be selected
|
|
maxDate: null,
|
|
|
|
// number of years either side, or array of upper/lower range
|
|
yearRange: 10,
|
|
|
|
// show week numbers at head of row
|
|
showWeekNumber: false,
|
|
|
|
// Week picker mode
|
|
pickWholeWeek: false,
|
|
|
|
// used internally (don't config outside)
|
|
minYear: 0,
|
|
maxYear: 9999,
|
|
minMonth: undefined,
|
|
maxMonth: undefined,
|
|
|
|
startRange: null,
|
|
endRange: null,
|
|
|
|
isRTL: false,
|
|
|
|
// Additional text to append to the year in the calendar title
|
|
yearSuffix: '',
|
|
|
|
// Render the month after year in the calendar title
|
|
showMonthAfterYear: false,
|
|
|
|
// Render days of the calendar grid that fall in the next or previous month
|
|
showDaysInNextAndPreviousMonths: false,
|
|
|
|
// Allows user to select days that fall in the next or previous month
|
|
enableSelectionDaysInNextAndPreviousMonths: false,
|
|
|
|
// how many months are visible
|
|
numberOfMonths: 1,
|
|
|
|
// when numberOfMonths is used, this will help you to choose where the main calendar will be (default `left`, can be set to `right`)
|
|
// only used for the first display or when a selected date is not visible
|
|
mainCalendar: 'left',
|
|
|
|
// Specify a DOM element to render the calendar in
|
|
container: undefined,
|
|
|
|
// Blur field when date is selected
|
|
blurFieldOnSelect : true,
|
|
|
|
// internationalization
|
|
i18n: {
|
|
previousMonth : 'Previous Month',
|
|
nextMonth : 'Next Month',
|
|
months : ['January','February','March','April','May','June','July','August','September','October','November','December'],
|
|
weekdays : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
|
|
weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
|
|
},
|
|
|
|
// Theme Classname
|
|
theme: null,
|
|
|
|
// events array
|
|
events: [],
|
|
|
|
// callback function
|
|
onSelect: null,
|
|
onOpen: null,
|
|
onClose: null,
|
|
onDraw: null
|
|
},
|
|
|
|
|
|
/**
|
|
* templating functions to abstract HTML rendering
|
|
*/
|
|
renderDayName = function(opts, day, abbr)
|
|
{
|
|
day += opts.firstDay;
|
|
while (day >= 7) {
|
|
day -= 7;
|
|
}
|
|
return abbr ? opts.i18n.weekdaysShort[day] : opts.i18n.weekdays[day];
|
|
},
|
|
|
|
renderDay = function(opts)
|
|
{
|
|
var arr = [];
|
|
var ariaSelected = 'false';
|
|
if (opts.isEmpty) {
|
|
if (opts.showDaysInNextAndPreviousMonths) {
|
|
arr.push('is-outside-current-month');
|
|
|
|
if(!opts.enableSelectionDaysInNextAndPreviousMonths) {
|
|
arr.push('is-selection-disabled');
|
|
}
|
|
|
|
} else {
|
|
return '<td class="is-empty"></td>';
|
|
}
|
|
}
|
|
if (opts.isDisabled) {
|
|
arr.push('is-disabled');
|
|
}
|
|
if (opts.isToday) {
|
|
arr.push('is-today');
|
|
}
|
|
if (opts.isSelected) {
|
|
arr.push('is-selected');
|
|
ariaSelected = 'true';
|
|
}
|
|
if (opts.hasEvent) {
|
|
arr.push('has-event');
|
|
}
|
|
if (opts.isInRange) {
|
|
arr.push('is-inrange');
|
|
}
|
|
if (opts.isStartRange) {
|
|
arr.push('is-startrange');
|
|
}
|
|
if (opts.isEndRange) {
|
|
arr.push('is-endrange');
|
|
}
|
|
return '<td data-day="' + opts.day + '" class="' + arr.join(' ') + '" aria-selected="' + ariaSelected + '">' +
|
|
'<button class="pika-button pika-day" type="button" ' +
|
|
'data-pika-year="' + opts.year + '" data-pika-month="' + opts.month + '" data-pika-day="' + opts.day + '">' +
|
|
opts.day +
|
|
'</button>' +
|
|
'</td>';
|
|
},
|
|
|
|
renderWeek = function (d, m, y) {
|
|
// Lifted from http://javascript.about.com/library/blweekyear.htm, lightly modified.
|
|
var onejan = new Date(y, 0, 1),
|
|
weekNum = Math.ceil((((new Date(y, m, d) - onejan) / 86400000) + onejan.getDay()+1)/7);
|
|
return '<td class="pika-week">' + weekNum + '</td>';
|
|
},
|
|
|
|
renderRow = function(days, isRTL, pickWholeWeek, isRowSelected)
|
|
{
|
|
return '<tr class="pika-row' + (pickWholeWeek ? ' pick-whole-week' : '') + (isRowSelected ? ' is-selected' : '') + '">' + (isRTL ? days.reverse() : days).join('') + '</tr>';
|
|
},
|
|
|
|
renderBody = function(rows)
|
|
{
|
|
return '<tbody>' + rows.join('') + '</tbody>';
|
|
},
|
|
|
|
renderHead = function(opts)
|
|
{
|
|
var i, arr = [];
|
|
if (opts.showWeekNumber) {
|
|
arr.push('<th></th>');
|
|
}
|
|
for (i = 0; i < 7; i++) {
|
|
arr.push('<th scope="col"><abbr title="' + renderDayName(opts, i) + '">' + renderDayName(opts, i, true) + '</abbr></th>');
|
|
}
|
|
return '<thead><tr>' + (opts.isRTL ? arr.reverse() : arr).join('') + '</tr></thead>';
|
|
},
|
|
|
|
renderTitle = function(instance, c, year, month, refYear, randId)
|
|
{
|
|
var i, j, arr,
|
|
opts = instance._o,
|
|
isMinYear = year === opts.minYear,
|
|
isMaxYear = year === opts.maxYear,
|
|
html = '<div id="' + randId + '" class="pika-title" role="heading" aria-live="assertive">',
|
|
monthHtml,
|
|
yearHtml,
|
|
prev = true,
|
|
next = true;
|
|
|
|
for (arr = [], i = 0; i < 12; i++) {
|
|
arr.push('<option value="' + (year === refYear ? i - c : 12 + i - c) + '"' +
|
|
(i === month ? ' selected="selected"': '') +
|
|
((isMinYear && i < opts.minMonth) || (isMaxYear && i > opts.maxMonth) ? 'disabled="disabled"' : '') + '>' +
|
|
opts.i18n.months[i] + '</option>');
|
|
}
|
|
|
|
monthHtml = '<div class="pika-label">' + opts.i18n.months[month] + '<select class="pika-select pika-select-month" tabindex="-1">' + arr.join('') + '</select></div>';
|
|
|
|
if (isArray(opts.yearRange)) {
|
|
i = opts.yearRange[0];
|
|
j = opts.yearRange[1] + 1;
|
|
} else {
|
|
i = year - opts.yearRange;
|
|
j = 1 + year + opts.yearRange;
|
|
}
|
|
|
|
for (arr = []; i < j && i <= opts.maxYear; i++) {
|
|
if (i >= opts.minYear) {
|
|
arr.push('<option value="' + i + '"' + (i === year ? ' selected="selected"': '') + '>' + (i) + '</option>');
|
|
}
|
|
}
|
|
yearHtml = '<div class="pika-label">' + year + opts.yearSuffix + '<select class="pika-select pika-select-year" tabindex="-1">' + arr.join('') + '</select></div>';
|
|
|
|
if (opts.showMonthAfterYear) {
|
|
html += yearHtml + monthHtml;
|
|
} else {
|
|
html += monthHtml + yearHtml;
|
|
}
|
|
|
|
if (isMinYear && (month === 0 || opts.minMonth >= month)) {
|
|
prev = false;
|
|
}
|
|
|
|
if (isMaxYear && (month === 11 || opts.maxMonth <= month)) {
|
|
next = false;
|
|
}
|
|
|
|
if (c === 0) {
|
|
html += '<button class="pika-prev' + (prev ? '' : ' is-disabled') + '" type="button">' + opts.i18n.previousMonth + '</button>';
|
|
}
|
|
if (c === (instance._o.numberOfMonths - 1) ) {
|
|
html += '<button class="pika-next' + (next ? '' : ' is-disabled') + '" type="button">' + opts.i18n.nextMonth + '</button>';
|
|
}
|
|
|
|
return html += '</div>';
|
|
},
|
|
|
|
renderTable = function(opts, data, randId)
|
|
{
|
|
return '<table cellpadding="0" cellspacing="0" class="pika-table" role="grid" aria-labelledby="' + randId + '">' + renderHead(opts) + renderBody(data) + '</table>';
|
|
},
|
|
|
|
|
|
/**
|
|
* Pikaday constructor
|
|
*/
|
|
Pikaday = function(options)
|
|
{
|
|
var self = this,
|
|
opts = self.config(options);
|
|
|
|
self._onMouseDown = function(e)
|
|
{
|
|
if (!self._v) {
|
|
return;
|
|
}
|
|
e = e || window.event;
|
|
var target = e.target || e.srcElement;
|
|
if (!target) {
|
|
return;
|
|
}
|
|
|
|
if (!hasClass(target, 'is-disabled')) {
|
|
if (hasClass(target, 'pika-button') && !hasClass(target, 'is-empty') && !hasClass(target.parentNode, 'is-disabled')) {
|
|
self.setDate(new Date(target.getAttribute('data-pika-year'), target.getAttribute('data-pika-month'), target.getAttribute('data-pika-day')));
|
|
if (opts.bound) {
|
|
sto(function() {
|
|
self.hide();
|
|
if (opts.blurFieldOnSelect && opts.field) {
|
|
opts.field.blur();
|
|
}
|
|
}, 100);
|
|
}
|
|
}
|
|
else if (hasClass(target, 'pika-prev')) {
|
|
self.prevMonth();
|
|
}
|
|
else if (hasClass(target, 'pika-next')) {
|
|
self.nextMonth();
|
|
}
|
|
}
|
|
if (!hasClass(target, 'pika-select')) {
|
|
// if this is touch event prevent mouse events emulation
|
|
if (e.preventDefault) {
|
|
e.preventDefault();
|
|
} else {
|
|
e.returnValue = false;
|
|
return false;
|
|
}
|
|
} else {
|
|
self._c = true;
|
|
}
|
|
};
|
|
|
|
self._onChange = function(e)
|
|
{
|
|
e = e || window.event;
|
|
var target = e.target || e.srcElement;
|
|
if (!target) {
|
|
return;
|
|
}
|
|
if (hasClass(target, 'pika-select-month')) {
|
|
self.gotoMonth(target.value);
|
|
}
|
|
else if (hasClass(target, 'pika-select-year')) {
|
|
self.gotoYear(target.value);
|
|
}
|
|
};
|
|
|
|
self._onKeyChange = function(e)
|
|
{
|
|
e = e || window.event;
|
|
|
|
if (self.isVisible()) {
|
|
|
|
switch(e.keyCode){
|
|
case 13:
|
|
case 27:
|
|
if (opts.field) {
|
|
opts.field.blur();
|
|
}
|
|
break;
|
|
case 37:
|
|
e.preventDefault();
|
|
self.adjustDate('subtract', 1);
|
|
break;
|
|
case 38:
|
|
self.adjustDate('subtract', 7);
|
|
break;
|
|
case 39:
|
|
self.adjustDate('add', 1);
|
|
break;
|
|
case 40:
|
|
self.adjustDate('add', 7);
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
|
|
self._onInputChange = function(e)
|
|
{
|
|
var date;
|
|
|
|
if (e.firedBy === self) {
|
|
return;
|
|
}
|
|
if (opts.parse) {
|
|
date = opts.parse(opts.field.value, opts.format);
|
|
} else if (hasMoment) {
|
|
date = moment(opts.field.value, opts.format, opts.formatStrict);
|
|
date = (date && date.isValid()) ? date.toDate() : null;
|
|
}
|
|
else {
|
|
date = new Date(Date.parse(opts.field.value));
|
|
}
|
|
if (isDate(date)) {
|
|
self.setDate(date);
|
|
}
|
|
if (!self._v) {
|
|
self.show();
|
|
}
|
|
};
|
|
|
|
self._onInputFocus = function()
|
|
{
|
|
self.show();
|
|
};
|
|
|
|
self._onInputClick = function()
|
|
{
|
|
self.show();
|
|
};
|
|
|
|
self._onInputBlur = function()
|
|
{
|
|
// IE allows pika div to gain focus; catch blur the input field
|
|
var pEl = document.activeElement;
|
|
do {
|
|
if (hasClass(pEl, 'pika-single')) {
|
|
return;
|
|
}
|
|
}
|
|
while ((pEl = pEl.parentNode));
|
|
|
|
if (!self._c) {
|
|
self._b = sto(function() {
|
|
self.hide();
|
|
}, 50);
|
|
}
|
|
self._c = false;
|
|
};
|
|
|
|
self._onClick = function(e)
|
|
{
|
|
e = e || window.event;
|
|
var target = e.target || e.srcElement,
|
|
pEl = target;
|
|
if (!target) {
|
|
return;
|
|
}
|
|
if (!hasEventListeners && hasClass(target, 'pika-select')) {
|
|
if (!target.onchange) {
|
|
target.setAttribute('onchange', 'return;');
|
|
addEvent(target, 'change', self._onChange);
|
|
}
|
|
}
|
|
do {
|
|
if (hasClass(pEl, 'pika-single') || pEl === opts.trigger) {
|
|
return;
|
|
}
|
|
}
|
|
while ((pEl = pEl.parentNode));
|
|
if (self._v && target !== opts.trigger && pEl !== opts.trigger) {
|
|
self.hide();
|
|
}
|
|
};
|
|
|
|
self.el = document.createElement('div');
|
|
self.el.className = 'pika-single' + (opts.isRTL ? ' is-rtl' : '') + (opts.theme ? ' ' + opts.theme : '');
|
|
|
|
addEvent(self.el, 'mousedown', self._onMouseDown, true);
|
|
addEvent(self.el, 'touchend', self._onMouseDown, true);
|
|
addEvent(self.el, 'change', self._onChange);
|
|
addEvent(document, 'keydown', self._onKeyChange);
|
|
|
|
if (opts.field) {
|
|
if (opts.container) {
|
|
opts.container.appendChild(self.el);
|
|
} else if (opts.bound) {
|
|
document.body.appendChild(self.el);
|
|
} else {
|
|
opts.field.parentNode.insertBefore(self.el, opts.field.nextSibling);
|
|
}
|
|
addEvent(opts.field, 'change', self._onInputChange);
|
|
|
|
if (!opts.defaultDate) {
|
|
if (hasMoment && opts.field.value) {
|
|
opts.defaultDate = moment(opts.field.value, opts.format).toDate();
|
|
} else {
|
|
opts.defaultDate = new Date(Date.parse(opts.field.value));
|
|
}
|
|
opts.setDefaultDate = true;
|
|
}
|
|
}
|
|
|
|
var defDate = opts.defaultDate;
|
|
|
|
if (isDate(defDate)) {
|
|
if (opts.setDefaultDate) {
|
|
self.setDate(defDate, true);
|
|
} else {
|
|
self.gotoDate(defDate);
|
|
}
|
|
} else {
|
|
self.gotoDate(new Date());
|
|
}
|
|
|
|
if (opts.bound) {
|
|
this.hide();
|
|
self.el.className += ' is-bound';
|
|
addEvent(opts.trigger, 'click', self._onInputClick);
|
|
addEvent(opts.trigger, 'focus', self._onInputFocus);
|
|
addEvent(opts.trigger, 'blur', self._onInputBlur);
|
|
} else {
|
|
this.show();
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* public Pikaday API
|
|
*/
|
|
Pikaday.prototype = {
|
|
|
|
|
|
/**
|
|
* configure functionality
|
|
*/
|
|
config: function(options)
|
|
{
|
|
if (!this._o) {
|
|
this._o = extend({}, defaults, true);
|
|
}
|
|
|
|
var opts = extend(this._o, options, true);
|
|
|
|
opts.isRTL = !!opts.isRTL;
|
|
|
|
opts.field = (opts.field && opts.field.nodeName) ? opts.field : null;
|
|
|
|
opts.theme = (typeof opts.theme) === 'string' && opts.theme ? opts.theme : null;
|
|
|
|
opts.bound = !!(opts.bound !== undefined ? opts.field && opts.bound : opts.field);
|
|
|
|
opts.trigger = (opts.trigger && opts.trigger.nodeName) ? opts.trigger : opts.field;
|
|
|
|
opts.disableWeekends = !!opts.disableWeekends;
|
|
|
|
opts.disableDayFn = (typeof opts.disableDayFn) === 'function' ? opts.disableDayFn : null;
|
|
|
|
var nom = parseInt(opts.numberOfMonths, 10) || 1;
|
|
opts.numberOfMonths = nom > 4 ? 4 : nom;
|
|
|
|
if (!isDate(opts.minDate)) {
|
|
opts.minDate = false;
|
|
}
|
|
if (!isDate(opts.maxDate)) {
|
|
opts.maxDate = false;
|
|
}
|
|
if ((opts.minDate && opts.maxDate) && opts.maxDate < opts.minDate) {
|
|
opts.maxDate = opts.minDate = false;
|
|
}
|
|
if (opts.minDate) {
|
|
this.setMinDate(opts.minDate);
|
|
}
|
|
if (opts.maxDate) {
|
|
this.setMaxDate(opts.maxDate);
|
|
}
|
|
|
|
if (isArray(opts.yearRange)) {
|
|
var fallback = new Date().getFullYear() - 10;
|
|
opts.yearRange[0] = parseInt(opts.yearRange[0], 10) || fallback;
|
|
opts.yearRange[1] = parseInt(opts.yearRange[1], 10) || fallback;
|
|
} else {
|
|
opts.yearRange = Math.abs(parseInt(opts.yearRange, 10)) || defaults.yearRange;
|
|
if (opts.yearRange > 100) {
|
|
opts.yearRange = 100;
|
|
}
|
|
}
|
|
|
|
return opts;
|
|
},
|
|
|
|
/**
|
|
* return a formatted string of the current selection (using Moment.js if available)
|
|
*/
|
|
toString: function(format)
|
|
{
|
|
format = format || this._o.format;
|
|
if (!isDate(this._d)) {
|
|
return '';
|
|
}
|
|
if (this._o.toString) {
|
|
return this._o.toString(this._d, format);
|
|
}
|
|
if (hasMoment) {
|
|
return moment(this._d).format(format);
|
|
}
|
|
return this._d.toDateString();
|
|
},
|
|
|
|
/**
|
|
* return a Moment.js object of the current selection (if available)
|
|
*/
|
|
getMoment: function()
|
|
{
|
|
return hasMoment ? moment(this._d) : null;
|
|
},
|
|
|
|
/**
|
|
* set the current selection from a Moment.js object (if available)
|
|
*/
|
|
setMoment: function(date, preventOnSelect)
|
|
{
|
|
if (hasMoment && moment.isMoment(date)) {
|
|
this.setDate(date.toDate(), preventOnSelect);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* return a Date object of the current selection
|
|
*/
|
|
getDate: function()
|
|
{
|
|
return isDate(this._d) ? new Date(this._d.getTime()) : null;
|
|
},
|
|
|
|
/**
|
|
* set the current selection
|
|
*/
|
|
setDate: function(date, preventOnSelect)
|
|
{
|
|
if (!date) {
|
|
this._d = null;
|
|
|
|
if (this._o.field) {
|
|
this._o.field.value = '';
|
|
fireEvent(this._o.field, 'change', { firedBy: this });
|
|
}
|
|
|
|
return this.draw();
|
|
}
|
|
if (typeof date === 'string') {
|
|
date = new Date(Date.parse(date));
|
|
}
|
|
if (!isDate(date)) {
|
|
return;
|
|
}
|
|
|
|
var min = this._o.minDate,
|
|
max = this._o.maxDate;
|
|
|
|
if (isDate(min) && date < min) {
|
|
date = min;
|
|
} else if (isDate(max) && date > max) {
|
|
date = max;
|
|
}
|
|
|
|
this._d = new Date(date.getTime());
|
|
setToStartOfDay(this._d);
|
|
this.gotoDate(this._d);
|
|
|
|
if (this._o.field) {
|
|
this._o.field.value = this.toString();
|
|
fireEvent(this._o.field, 'change', { firedBy: this });
|
|
}
|
|
if (!preventOnSelect && typeof this._o.onSelect === 'function') {
|
|
this._o.onSelect.call(this, this.getDate());
|
|
}
|
|
},
|
|
|
|
/**
|
|
* change view to a specific date
|
|
*/
|
|
gotoDate: function(date)
|
|
{
|
|
var newCalendar = true;
|
|
|
|
if (!isDate(date)) {
|
|
return;
|
|
}
|
|
|
|
if (this.calendars) {
|
|
var firstVisibleDate = new Date(this.calendars[0].year, this.calendars[0].month, 1),
|
|
lastVisibleDate = new Date(this.calendars[this.calendars.length-1].year, this.calendars[this.calendars.length-1].month, 1),
|
|
visibleDate = date.getTime();
|
|
// get the end of the month
|
|
lastVisibleDate.setMonth(lastVisibleDate.getMonth()+1);
|
|
lastVisibleDate.setDate(lastVisibleDate.getDate()-1);
|
|
newCalendar = (visibleDate < firstVisibleDate.getTime() || lastVisibleDate.getTime() < visibleDate);
|
|
}
|
|
|
|
if (newCalendar) {
|
|
this.calendars = [{
|
|
month: date.getMonth(),
|
|
year: date.getFullYear()
|
|
}];
|
|
if (this._o.mainCalendar === 'right') {
|
|
this.calendars[0].month += 1 - this._o.numberOfMonths;
|
|
}
|
|
}
|
|
|
|
this.adjustCalendars();
|
|
},
|
|
|
|
adjustDate: function(sign, days) {
|
|
|
|
var day = this.getDate() || new Date();
|
|
var difference = parseInt(days)*24*60*60*1000;
|
|
|
|
var newDay;
|
|
|
|
if (sign === 'add') {
|
|
newDay = new Date(day.valueOf() + difference);
|
|
} else if (sign === 'subtract') {
|
|
newDay = new Date(day.valueOf() - difference);
|
|
}
|
|
|
|
this.setDate(newDay);
|
|
},
|
|
|
|
adjustCalendars: function() {
|
|
this.calendars[0] = adjustCalendar(this.calendars[0]);
|
|
for (var c = 1; c < this._o.numberOfMonths; c++) {
|
|
this.calendars[c] = adjustCalendar({
|
|
month: this.calendars[0].month + c,
|
|
year: this.calendars[0].year
|
|
});
|
|
}
|
|
this.draw();
|
|
},
|
|
|
|
gotoToday: function()
|
|
{
|
|
this.gotoDate(new Date());
|
|
},
|
|
|
|
/**
|
|
* change view to a specific month (zero-index, e.g. 0: January)
|
|
*/
|
|
gotoMonth: function(month)
|
|
{
|
|
if (!isNaN(month)) {
|
|
this.calendars[0].month = parseInt(month, 10);
|
|
this.adjustCalendars();
|
|
}
|
|
},
|
|
|
|
nextMonth: function()
|
|
{
|
|
this.calendars[0].month++;
|
|
this.adjustCalendars();
|
|
},
|
|
|
|
prevMonth: function()
|
|
{
|
|
this.calendars[0].month--;
|
|
this.adjustCalendars();
|
|
},
|
|
|
|
/**
|
|
* change view to a specific full year (e.g. "2012")
|
|
*/
|
|
gotoYear: function(year)
|
|
{
|
|
if (!isNaN(year)) {
|
|
this.calendars[0].year = parseInt(year, 10);
|
|
this.adjustCalendars();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* change the minDate
|
|
*/
|
|
setMinDate: function(value)
|
|
{
|
|
if(value instanceof Date) {
|
|
setToStartOfDay(value);
|
|
this._o.minDate = value;
|
|
this._o.minYear = value.getFullYear();
|
|
this._o.minMonth = value.getMonth();
|
|
} else {
|
|
this._o.minDate = defaults.minDate;
|
|
this._o.minYear = defaults.minYear;
|
|
this._o.minMonth = defaults.minMonth;
|
|
this._o.startRange = defaults.startRange;
|
|
}
|
|
|
|
this.draw();
|
|
},
|
|
|
|
/**
|
|
* change the maxDate
|
|
*/
|
|
setMaxDate: function(value)
|
|
{
|
|
if(value instanceof Date) {
|
|
setToStartOfDay(value);
|
|
this._o.maxDate = value;
|
|
this._o.maxYear = value.getFullYear();
|
|
this._o.maxMonth = value.getMonth();
|
|
} else {
|
|
this._o.maxDate = defaults.maxDate;
|
|
this._o.maxYear = defaults.maxYear;
|
|
this._o.maxMonth = defaults.maxMonth;
|
|
this._o.endRange = defaults.endRange;
|
|
}
|
|
|
|
this.draw();
|
|
},
|
|
|
|
setStartRange: function(value)
|
|
{
|
|
this._o.startRange = value;
|
|
},
|
|
|
|
setEndRange: function(value)
|
|
{
|
|
this._o.endRange = value;
|
|
},
|
|
|
|
/**
|
|
* refresh the HTML
|
|
*/
|
|
draw: function(force)
|
|
{
|
|
if (!this._v && !force) {
|
|
return;
|
|
}
|
|
var opts = this._o,
|
|
minYear = opts.minYear,
|
|
maxYear = opts.maxYear,
|
|
minMonth = opts.minMonth,
|
|
maxMonth = opts.maxMonth,
|
|
html = '',
|
|
randId;
|
|
|
|
if (this._y <= minYear) {
|
|
this._y = minYear;
|
|
if (!isNaN(minMonth) && this._m < minMonth) {
|
|
this._m = minMonth;
|
|
}
|
|
}
|
|
if (this._y >= maxYear) {
|
|
this._y = maxYear;
|
|
if (!isNaN(maxMonth) && this._m > maxMonth) {
|
|
this._m = maxMonth;
|
|
}
|
|
}
|
|
|
|
randId = 'pika-title-' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 2);
|
|
|
|
for (var c = 0; c < opts.numberOfMonths; c++) {
|
|
html += '<div class="pika-lendar">' + renderTitle(this, c, this.calendars[c].year, this.calendars[c].month, this.calendars[0].year, randId) + this.render(this.calendars[c].year, this.calendars[c].month, randId) + '</div>';
|
|
}
|
|
|
|
this.el.innerHTML = html;
|
|
|
|
if (opts.bound) {
|
|
if(opts.field.type !== 'hidden') {
|
|
sto(function() {
|
|
opts.trigger.focus();
|
|
}, 1);
|
|
}
|
|
}
|
|
|
|
if (typeof this._o.onDraw === 'function') {
|
|
this._o.onDraw(this);
|
|
}
|
|
|
|
if (opts.bound) {
|
|
// let the screen reader user know to use arrow keys
|
|
opts.field.setAttribute('aria-label', 'Use the arrow keys to pick a date');
|
|
}
|
|
},
|
|
|
|
adjustPosition: function()
|
|
{
|
|
var field, pEl, width, height, viewportWidth, viewportHeight, scrollTop, left, top, clientRect;
|
|
|
|
if (this._o.container) return;
|
|
|
|
this.el.style.position = 'absolute';
|
|
|
|
field = this._o.trigger;
|
|
pEl = field;
|
|
width = this.el.offsetWidth;
|
|
height = this.el.offsetHeight;
|
|
viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
|
|
|
|
if (typeof field.getBoundingClientRect === 'function') {
|
|
clientRect = field.getBoundingClientRect();
|
|
left = clientRect.left + window.pageXOffset;
|
|
top = clientRect.bottom + window.pageYOffset;
|
|
} else {
|
|
left = pEl.offsetLeft;
|
|
top = pEl.offsetTop + pEl.offsetHeight;
|
|
while((pEl = pEl.offsetParent)) {
|
|
left += pEl.offsetLeft;
|
|
top += pEl.offsetTop;
|
|
}
|
|
}
|
|
|
|
// default position is bottom & left
|
|
if ((this._o.reposition && left + width > viewportWidth) ||
|
|
(
|
|
this._o.position.indexOf('right') > -1 &&
|
|
left - width + field.offsetWidth > 0
|
|
)
|
|
) {
|
|
left = left - width + field.offsetWidth;
|
|
}
|
|
if ((this._o.reposition && top + height > viewportHeight + scrollTop) ||
|
|
(
|
|
this._o.position.indexOf('top') > -1 &&
|
|
top - height - field.offsetHeight > 0
|
|
)
|
|
) {
|
|
top = top - height - field.offsetHeight;
|
|
}
|
|
|
|
this.el.style.left = left + 'px';
|
|
this.el.style.top = top + 'px';
|
|
},
|
|
|
|
/**
|
|
* render HTML for a particular month
|
|
*/
|
|
render: function(year, month, randId)
|
|
{
|
|
var opts = this._o,
|
|
now = new Date(),
|
|
days = getDaysInMonth(year, month),
|
|
before = new Date(year, month, 1).getDay(),
|
|
data = [],
|
|
row = [];
|
|
setToStartOfDay(now);
|
|
if (opts.firstDay > 0) {
|
|
before -= opts.firstDay;
|
|
if (before < 0) {
|
|
before += 7;
|
|
}
|
|
}
|
|
var previousMonth = month === 0 ? 11 : month - 1,
|
|
nextMonth = month === 11 ? 0 : month + 1,
|
|
yearOfPreviousMonth = month === 0 ? year - 1 : year,
|
|
yearOfNextMonth = month === 11 ? year + 1 : year,
|
|
daysInPreviousMonth = getDaysInMonth(yearOfPreviousMonth, previousMonth);
|
|
var cells = days + before,
|
|
after = cells;
|
|
while(after > 7) {
|
|
after -= 7;
|
|
}
|
|
cells += 7 - after;
|
|
var isWeekSelected = false;
|
|
for (var i = 0, r = 0; i < cells; i++)
|
|
{
|
|
var day = new Date(year, month, 1 + (i - before)),
|
|
isSelected = isDate(this._d) ? compareDates(day, this._d) : false,
|
|
isToday = compareDates(day, now),
|
|
hasEvent = opts.events.indexOf(day.toDateString()) !== -1 ? true : false,
|
|
isEmpty = i < before || i >= (days + before),
|
|
dayNumber = 1 + (i - before),
|
|
monthNumber = month,
|
|
yearNumber = year,
|
|
isStartRange = opts.startRange && compareDates(opts.startRange, day),
|
|
isEndRange = opts.endRange && compareDates(opts.endRange, day),
|
|
isInRange = opts.startRange && opts.endRange && opts.startRange < day && day < opts.endRange,
|
|
isDisabled = (opts.minDate && day < opts.minDate) ||
|
|
(opts.maxDate && day > opts.maxDate) ||
|
|
(opts.disableWeekends && isWeekend(day)) ||
|
|
(opts.disableDayFn && opts.disableDayFn(day));
|
|
|
|
if (isEmpty) {
|
|
if (i < before) {
|
|
dayNumber = daysInPreviousMonth + dayNumber;
|
|
monthNumber = previousMonth;
|
|
yearNumber = yearOfPreviousMonth;
|
|
} else {
|
|
dayNumber = dayNumber - days;
|
|
monthNumber = nextMonth;
|
|
yearNumber = yearOfNextMonth;
|
|
}
|
|
}
|
|
|
|
var dayConfig = {
|
|
day: dayNumber,
|
|
month: monthNumber,
|
|
year: yearNumber,
|
|
hasEvent: hasEvent,
|
|
isSelected: isSelected,
|
|
isToday: isToday,
|
|
isDisabled: isDisabled,
|
|
isEmpty: isEmpty,
|
|
isStartRange: isStartRange,
|
|
isEndRange: isEndRange,
|
|
isInRange: isInRange,
|
|
showDaysInNextAndPreviousMonths: opts.showDaysInNextAndPreviousMonths,
|
|
enableSelectionDaysInNextAndPreviousMonths: opts.enableSelectionDaysInNextAndPreviousMonths
|
|
};
|
|
|
|
if (opts.pickWholeWeek && isSelected) {
|
|
isWeekSelected = true;
|
|
}
|
|
|
|
row.push(renderDay(dayConfig));
|
|
|
|
if (++r === 7) {
|
|
if (opts.showWeekNumber) {
|
|
row.unshift(renderWeek(i - before, month, year));
|
|
}
|
|
data.push(renderRow(row, opts.isRTL, opts.pickWholeWeek, isWeekSelected));
|
|
row = [];
|
|
r = 0;
|
|
isWeekSelected = false;
|
|
}
|
|
}
|
|
return renderTable(opts, data, randId);
|
|
},
|
|
|
|
isVisible: function()
|
|
{
|
|
return this._v;
|
|
},
|
|
|
|
show: function()
|
|
{
|
|
if (!this.isVisible()) {
|
|
this._v = true;
|
|
this.draw();
|
|
removeClass(this.el, 'is-hidden');
|
|
if (this._o.bound) {
|
|
addEvent(document, 'click', this._onClick);
|
|
this.adjustPosition();
|
|
}
|
|
if (typeof this._o.onOpen === 'function') {
|
|
this._o.onOpen.call(this);
|
|
}
|
|
}
|
|
},
|
|
|
|
hide: function()
|
|
{
|
|
var v = this._v;
|
|
if (v !== false) {
|
|
if (this._o.bound) {
|
|
removeEvent(document, 'click', this._onClick);
|
|
}
|
|
this.el.style.position = 'static'; // reset
|
|
this.el.style.left = 'auto';
|
|
this.el.style.top = 'auto';
|
|
addClass(this.el, 'is-hidden');
|
|
this._v = false;
|
|
if (v !== undefined && typeof this._o.onClose === 'function') {
|
|
this._o.onClose.call(this);
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* GAME OVER
|
|
*/
|
|
destroy: function()
|
|
{
|
|
this.hide();
|
|
removeEvent(this.el, 'mousedown', this._onMouseDown, true);
|
|
removeEvent(this.el, 'touchend', this._onMouseDown, true);
|
|
removeEvent(this.el, 'change', this._onChange);
|
|
removeEvent(document, 'keydown', this._onKeyChange);
|
|
if (this._o.field) {
|
|
removeEvent(this._o.field, 'change', this._onInputChange);
|
|
if (this._o.bound) {
|
|
removeEvent(this._o.trigger, 'click', this._onInputClick);
|
|
removeEvent(this._o.trigger, 'focus', this._onInputFocus);
|
|
removeEvent(this._o.trigger, 'blur', this._onInputBlur);
|
|
}
|
|
}
|
|
if (this.el.parentNode) {
|
|
this.el.parentNode.removeChild(this.el);
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
return Pikaday;
|
|
|
|
}));
|