{I" class:ETI"BundledAsset;�FI"logical_path;�TI"application.js;�TI" pathname;�TI"0$root/app/assets/javascripts/application.js;�FI"content_type;�TI"application/javascript;�TI" mtime;�Tl+g<RI"length;�Tis� I"digest;�TI"%ff3eca8982e1c36114f3de6ac9fd3c84;�FI"source;�TI"s� /*! * jQuery JavaScript Library v1.10.2 * http://jquery.com/ * * Includes Sizzle.js * http://sizzlejs.com/ * * Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors * Released under the MIT license * http://jquery.org/license * * Date: 2013-07-03T13:48Z */ (function( window, undefined ) { // Can't do this because several apps including ASP.NET trace // the stack via arguments.caller.callee and Firefox dies if // you try to trace through "use strict" call chains. (#13335) // Support: Firefox 18+ //"use strict"; var // The deferred used on DOM ready readyList, // A central reference to the root jQuery(document) rootjQuery, // Support: IE<10 // For `typeof xmlNode.method` instead of `xmlNode.method !== undefined` core_strundefined = typeof undefined, // Use the correct document accordingly with window argument (sandbox) location = window.location, document = window.document, docElem = document.documentElement, // Map over jQuery in case of overwrite _jQuery = window.jQuery, // Map over the $ in case of overwrite _$ = window.$, // [[Class]] -> type pairs class2type = {}, // List of deleted data cache ids, so we can reuse them core_deletedIds = [], core_version = "1.10.2", // Save a reference to some core methods core_concat = core_deletedIds.concat, core_push = core_deletedIds.push, core_slice = core_deletedIds.slice, core_indexOf = core_deletedIds.indexOf, core_toString = class2type.toString, core_hasOwn = class2type.hasOwnProperty, core_trim = core_version.trim, // Define a local copy of jQuery jQuery = function( selector, context ) { // The jQuery object is actually just the init constructor 'enhanced' return new jQuery.fn.init( selector, context, rootjQuery ); }, // Used for matching numbers core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source, // Used for splitting on whitespace core_rnotwhite = /\S+/g, // Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE) rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, // 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-]*))$/, // Match a standalone tag rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, // JSON RegExp rvalidchars = /^[\],:{}\s]*$/, rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g, rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g, rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/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(); }, // The ready event handler completed = function( event ) { // readyState === "complete" is good enough for us to call the dom ready in oldIE if ( document.addEventListener || event.type === "load" || document.readyState === "complete" ) { detach(); jQuery.ready(); } }, // Clean-up method for dom ready events detach = function() { if ( document.addEventListener ) { document.removeEventListener( "DOMContentLoaded", completed, false ); window.removeEventListener( "load", completed, false ); } else { document.detachEvent( "onreadystatechange", completed ); window.detachEvent( "onload", completed ); } }; jQuery.fn = jQuery.prototype = { // The current version of jQuery being used jquery: core_version, constructor: jQuery, init: function( selector, context, rootjQuery ) { var match, elem; // HANDLE: $(""), $(null), $(undefined), $(false) if ( !selector ) { return this; } // 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 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 || rootjQuery ).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 rootjQuery.ready( selector ); } if ( selector.selector !== undefined ) { this.selector = selector.selector; this.context = selector.context; } return jQuery.makeArray( selector, this ); }, // Start with an empty selector selector: "", // The default length of a jQuery object is 0 length: 0, toArray: function() { return core_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 a 'clean' array this.toArray() : // Return just the object ( num < 0 ? this[ this.length + num ] : this[ num ] ); }, // 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. // (You can seed the arguments with an array of args, but this is // only used internally.) each: function( callback, args ) { return jQuery.each( this, callback, args ); }, ready: function( fn ) { // Add the callback jQuery.ready.promise().done( fn ); return this; }, slice: function() { return this.pushStack( core_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] ] : [] ); }, map: function( callback ) { return this.pushStack( jQuery.map(this, function( elem, i ) { return callback.call( elem, i, elem ); })); }, end: function() { return this.prevObject || this.constructor(null); }, // For internal use only. // Behaves like an Array's method, not like a jQuery method. push: core_push, sort: [].sort, splice: [].splice }; // Give the init function the jQuery prototype for later instantiation jQuery.fn.init.prototype = jQuery.fn; 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; target = arguments[1] || {}; // skip the boolean and the target i = 2; } // 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 ( length === i ) { 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 // Non-digits removed to match rinlinejQuery expando: "jQuery" + ( core_version + Math.random() ).replace( /\D/g, "" ), noConflict: function( deep ) { if ( window.$ === jQuery ) { window.$ = _$; } if ( deep && window.jQuery === jQuery ) { window.jQuery = _jQuery; } return jQuery; }, // 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; } // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). if ( !document.body ) { return setTimeout( jQuery.ready ); } // 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.trigger ) { jQuery( document ).trigger("ready").off("ready"); } }, // 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 ) { return !isNaN( parseFloat(obj) ) && isFinite( obj ); }, type: function( obj ) { if ( obj == null ) { return String( obj ); } return typeof obj === "object" || typeof obj === "function" ? class2type[ core_toString.call(obj) ] || "object" : typeof obj; }, 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 && !core_hasOwn.call(obj, "constructor") && !core_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 ( jQuery.support.ownLast ) { for ( key in obj ) { return core_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 || core_hasOwn.call( obj, key ); }, isEmptyObject: function( obj ) { var name; for ( name in obj ) { return false; } return true; }, error: function( msg ) { throw new Error( msg ); }, // 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 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 = jQuery.buildFragment( [ data ], context, scripts ); if ( scripts ) { jQuery( scripts ).remove(); } return jQuery.merge( [], parsed.childNodes ); }, parseJSON: function( data ) { // Attempt to parse using the native JSON parser first if ( window.JSON && window.JSON.parse ) { return window.JSON.parse( data ); } if ( data === null ) { return data; } if ( typeof data === "string" ) { // Make sure leading/trailing whitespace is removed (IE can't handle it) data = jQuery.trim( data ); if ( data ) { // Make sure the incoming data is actual JSON // Logic borrowed from http://json.org/json2.js if ( rvalidchars.test( data.replace( rvalidescape, "@" ) .replace( rvalidtokens, "]" ) .replace( rvalidbraces, "")) ) { return ( new Function( "return " + data ) )(); } } } jQuery.error( "Invalid JSON: " + data ); }, // Cross-browser xml parsing parseXML: function( data ) { var xml, tmp; if ( !data || typeof data !== "string" ) { return null; } try { if ( window.DOMParser ) { // Standard tmp = new DOMParser(); xml = tmp.parseFromString( data , "text/xml" ); } else { // IE xml = new 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; }, noop: function() {}, // Evaluates a script in a global context // 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 ); } )( 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(); }, // args is for internal usage only each: function( obj, callback, args ) { var value, i = 0, length = obj.length, isArray = isArraylike( obj ); if ( args ) { if ( isArray ) { for ( ; i < length; i++ ) { value = callback.apply( obj[ i ], args ); if ( value === false ) { break; } } } else { for ( i in obj ) { value = callback.apply( obj[ i ], args ); if ( value === false ) { break; } } } // A special, fast, case for the most common use of each } else { if ( isArray ) { for ( ; i < length; i++ ) { value = callback.call( obj[ i ], i, obj[ i ] ); if ( value === false ) { break; } } } else { for ( i in obj ) { value = callback.call( obj[ i ], i, obj[ i ] ); if ( value === false ) { break; } } } } return obj; }, // Use native String.trim function wherever possible trim: core_trim && !core_trim.call("\uFEFF\xA0") ? function( text ) { return text == null ? "" : core_trim.call( text ); } : // Otherwise use our own trimming functionality 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 { core_push.call( ret, arr ); } } return ret; }, inArray: function( elem, arr, i ) { var len; if ( arr ) { if ( core_indexOf ) { return core_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 l = second.length, i = first.length, j = 0; if ( typeof l === "number" ) { for ( ; j < l; j++ ) { first[ i++ ] = second[ j ]; } } else { while ( second[j] !== undefined ) { first[ i++ ] = second[ j++ ]; } } first.length = i; return first; }, grep: function( elems, callback, inv ) { var retVal, ret = [], i = 0, length = elems.length; inv = !!inv; // Go through the array, only saving the items // that pass the validator function for ( ; i < length; i++ ) { retVal = !!callback( elems[ i ], i ); if ( inv !== retVal ) { ret.push( elems[ i ] ); } } return ret; }, // arg is for internal usage only map: function( elems, callback, arg ) { var value, i = 0, length = elems.length, isArray = isArraylike( elems ), ret = []; // Go through the array, translating each of the items to their if ( isArray ) { for ( ; i < length; i++ ) { value = callback( elems[ i ], i, arg ); if ( value != null ) { ret[ ret.length ] = value; } } // Go through every key on the object, } else { for ( i in elems ) { value = callback( elems[ i ], i, arg ); if ( value != null ) { ret[ ret.length ] = value; } } } // Flatten any nested arrays return core_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 = core_slice.call( arguments, 2 ); proxy = function() { return fn.apply( context || this, args.concat( core_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; }, // Multifunctional method to get and set values of a collection // The value/s can optionally be executed if it's a function 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 ) { jQuery.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; }, now: function() { return ( new Date() ).getTime(); }, // A method for quickly swapping in/out CSS properties to get correct calculations. // Note: this method belongs to the css module but it's needed here for the support module. // If support gets modularized, this method should be moved back to the css module. 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; } }); jQuery.ready.promise = function( obj ) { if ( !readyList ) { readyList = jQuery.Deferred(); // Catch cases where $(document).ready() is called after the browser event has already occurred. // we once tried to use readyState "interactive" here, but it caused issues like the one // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15 if ( document.readyState === "complete" ) { // Handle it asynchronously to allow scripts the opportunity to delay ready setTimeout( jQuery.ready ); // Standards-based browsers support DOMContentLoaded } else if ( document.addEventListener ) { // Use the handy event callback document.addEventListener( "DOMContentLoaded", completed, false ); // A fallback to window.onload, that will always work window.addEventListener( "load", completed, false ); // 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 setTimeout( doScrollCheck, 50 ); } // detach all dom ready events detach(); // and execute any waiting functions jQuery.ready(); } })(); } } } return readyList.promise( obj ); }; // Populate the class2type map jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); }); function isArraylike( obj ) { var length = obj.length, type = jQuery.type( obj ); if ( jQuery.isWindow( obj ) ) { return false; } if ( obj.nodeType === 1 && length ) { return true; } return type === "array" || type !== "function" && ( length === 0 || typeof length === "number" && length > 0 && ( length - 1 ) in obj ); } // All jQuery objects should point back to these rootjQuery = jQuery(document); /*! * Sizzle CSS Selector Engine v1.10.2 * http://sizzlejs.com/ * * Copyright 2013 jQuery Foundation, Inc. and other contributors * Released under the MIT license * http://jquery.org/license * * Date: 2013-07-03 */ (function( window, undefined ) { var i, support, cachedruns, Expr, getText, isXML, compile, outermostContext, sortInput, // Local document vars setDocument, document, docElem, documentIsHTML, rbuggyQSA, rbuggyMatches, matches, contains, // Instance-specific data expando = "sizzle" + -(new Date()), preferredDoc = window.document, dirruns = 0, done = 0, classCache = createCache(), tokenCache = createCache(), compilerCache = createCache(), hasDuplicate = false, sortOrder = function( a, b ) { if ( a === b ) { hasDuplicate = true; return 0; } return 0; }, // General-purpose constants strundefined = typeof undefined, 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 if we can't use a native one indexOf = arr.indexOf || function( elem ) { var i = 0, len = this.length; for ( ; i < len; i++ ) { if ( this[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 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace whitespace = "[\\x20\\t\\r\\n\\f]", // http://www.w3.org/TR/css3-syntax/#characters characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+", // Loosely modeled on CSS identifier characters // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier identifier = characterEncoding.replace( "w", "w#" ), // Acceptable operators http://www.w3.org/TR/selectors/#attribute-selectors attributes = "\\[" + whitespace + "*(" + characterEncoding + ")" + whitespace + "*(?:([*^$|!~]?=)" + whitespace + "*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|(" + identifier + ")|)|)" + whitespace + "*\\]", // Prefer arguments quoted, // then not containing pseudos/brackets, // then attribute selectors/non-parenthetical expressions, // then anything else // These preferences are here to reduce the number of selectors // needing tokenize in the PSEUDO preFilter pseudos = ":(" + characterEncoding + ")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\\)|)", // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ), rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ), rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ), rsibling = new RegExp( whitespace + "*[+~]" ), rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*)" + whitespace + "*\\]", "g" ), rpseudo = new RegExp( pseudos ), ridentifier = new RegExp( "^" + identifier + "$" ), matchExpr = { "ID": new RegExp( "^#(" + characterEncoding + ")" ), "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ), "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ), "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" ) }, rnative = /^[^{]+\{\s*\[native \w/, // Easily-parseable/retrievable ID or TAG or CLASS selectors rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, rinputs = /^(?:input|select|textarea|button)$/i, rheader = /^h\d$/i, 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 // Workaround erroneous numeric interpretation of +"0x" return high !== high || escapedWhitespace ? escaped : // BMP codepoint high < 0 ? String.fromCharCode( high + 0x10000 ) : // Supplemental Plane codepoint (surrogate pair) String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 ); }; // 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 match, elem, m, nodeType, // QSA vars i, groups, old, nid, newContext, newSelector; if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) { setDocument( context ); } context = context || document; results = results || []; if ( !selector || typeof selector !== "string" ) { return results; } if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) { return []; } if ( documentIsHTML && !seed ) { // Shortcuts if ( (match = rquickExpr.exec( selector )) ) { // Speed-up: Sizzle("#ID") if ( (m = match[1]) ) { if ( nodeType === 9 ) { elem = context.getElementById( m ); // 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, Opera, and Webkit return items // by name instead of ID if ( elem.id === m ) { results.push( elem ); return results; } } else { return results; } } else { // Context is not a document if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) && contains( context, elem ) && elem.id === m ) { results.push( elem ); return results; } } // Speed-up: Sizzle("TAG") } else if ( match[2] ) { push.apply( results, context.getElementsByTagName( selector ) ); return results; // Speed-up: Sizzle(".CLASS") } else if ( (m = match[3]) && support.getElementsByClassName && context.getElementsByClassName ) { push.apply( results, context.getElementsByClassName( m ) ); return results; } } // QSA path if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) { nid = old = expando; newContext = context; newSelector = nodeType === 9 && selector; // qSA works strangely on Element-rooted queries // We can work around this by specifying an extra ID on the root // and working up from there (Thanks to Andrew Dupont for the technique) // IE 8 doesn't work on object elements if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { groups = tokenize( selector ); if ( (old = context.getAttribute("id")) ) { nid = old.replace( rescape, "\\$&" ); } else { context.setAttribute( "id", nid ); } nid = "[id='" + nid + "'] "; i = groups.length; while ( i-- ) { groups[i] = nid + toSelector( groups[i] ); } newContext = rsibling.test( selector ) && context.parentNode || context; newSelector = groups.join(","); } if ( newSelector ) { try { push.apply( results, newContext.querySelectorAll( newSelector ) ); return results; } catch(qsaError) { } finally { if ( !old ) { 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 = attrs.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]); } } }); }); } /** * Detect xml * @param {Element|Object} elem An element or a document */ 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; }; // Expose support vars for convenience support = Sizzle.support = {}; /** * 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 doc = node ? node.ownerDocument || node : preferredDoc, parent = doc.defaultView; // If no document and documentElement is available, return if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) { return document; } // Set our document document = doc; docElem = doc.documentElement; // Support tests documentIsHTML = !isXML( doc ); // Support: IE>8 // If iframe document is assigned to "document" variable and if iframe has been reloaded, // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936 // IE6-8 do not support the defaultView property so parent will be undefined if ( parent && parent.attachEvent && parent !== parent.top ) { parent.attachEvent( "onbeforeunload", function() { setDocument(); }); } /* 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( doc.createComment("") ); return !div.getElementsByTagName("*").length; }); // Check if getElementsByClassName can be trusted support.getElementsByClassName = assert(function( div ) { div.innerHTML = "<div class='a'></div><div class='a i'></div>"; // Support: Safari<4 // Catch class over-caching div.firstChild.className = "i"; // Support: Opera<10 // Catch gEBCN failure to find non-leading classes return div.getElementsByClassName("i").length === 2; }); // 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 !doc.getElementsByName || !doc.getElementsByName( expando ).length; }); // ID find and filter if ( support.getById ) { Expr.find["ID"] = function( id, context ) { if ( typeof context.getElementById !== strundefined && documentIsHTML ) { var m = context.getElementById( id ); // Check parentNode to catch when Blackberry 4.6 returns // nodes that are no longer in the document #6963 return m && m.parentNode ? [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 !== strundefined && elem.getAttributeNode("id"); return node && node.value === attrId; }; }; } // Tag Expr.find["TAG"] = support.getElementsByTagName ? function( tag, context ) { if ( typeof context.getElementsByTagName !== strundefined ) { return context.getElementsByTagName( tag ); } } : function( tag, context ) { var elem, tmp = [], i = 0, 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 !== strundefined && 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( doc.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 div.innerHTML = "<select><option selected=''></option></select>"; // Support: IE8 // Boolean attributes and "value" are not treated correctly if ( !div.querySelectorAll("[selected]").length ) { rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" ); } // 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"); } }); assert(function( div ) { // Support: Opera 10-12/IE8 // ^= $= *= and empty values // Should not select anything // Support: Windows 8 Native Apps // The type attribute is restricted during .innerHTML assignment var input = doc.createElement("input"); input.setAttribute( "type", "hidden" ); div.appendChild( input ).setAttribute( "t", "" ); if ( div.querySelectorAll("[t^='']").length ) { rbuggyQSA.push( "[*^$]=" + 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.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 ---------------------------------------------------------------------- */ // Element contains another // Purposefully does not implement inclusive descendent // As in, an element does not contain itself contains = rnative.test( docElem.contains ) || docElem.compareDocumentPosition ? 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 = docElem.compareDocumentPosition ? function( a, b ) { // Flag for duplicate removal if ( a === b ) { hasDuplicate = true; return 0; } var compare = b.compareDocumentPosition && a.compareDocumentPosition && a.compareDocumentPosition( b ); if ( compare ) { // Disconnected nodes if ( compare & 1 || (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) { // Choose the first element that is related to our preferred document if ( a === doc || contains(preferredDoc, a) ) { return -1; } if ( b === doc || contains(preferredDoc, b) ) { return 1; } // Maintain original order return sortInput ? ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) : 0; } return compare & 4 ? -1 : 1; } // Not directly comparable, sort on existence of method return a.compareDocumentPosition ? -1 : 1; } : function( a, b ) { var cur, i = 0, aup = a.parentNode, bup = b.parentNode, ap = [ a ], bp = [ b ]; // Exit early if the nodes are identical if ( a === b ) { hasDuplicate = true; return 0; // Parentless nodes are either documents or disconnected } else if ( !aup || !bup ) { return a === doc ? -1 : b === doc ? 1 : aup ? -1 : bup ? 1 : sortInput ? ( indexOf.call( sortInput, a ) - indexOf.call( 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 doc; }; 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 && ( !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 ? support.attributes || !documentIsHTML ? elem.getAttribute( name ) : (val = elem.getAttributeNode(name)) && val.specified ? val.value : null : val; }; 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 ); } } 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 for ( ; (node = elem[i]); 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 (see #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[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[5] && match[2]; if ( matchExpr["CHILD"].test( match[0] ) ) { return null; } // Accept quoted arguments as-is if ( match[3] && match[4] !== undefined ) { match[2] = match[4]; // 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 !== strundefined && 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 + " " ).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, outerCache, node, diff, nodeIndex, start, dir = simple !== forward ? "nextSibling" : "previousSibling", parent = elem.parentNode, name = ofType && elem.nodeName.toLowerCase(), useCache = !xml && !ofType; 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 outerCache = parent[ expando ] || (parent[ expando ] = {}); cache = outerCache[ type ] || []; nodeIndex = cache[0] === dirruns && cache[1]; diff = cache[0] === dirruns && 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 ) { outerCache[ type ] = [ dirruns, nodeIndex, diff ]; break; } } // Use previously-cached element index if available } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) { diff = cache[1]; // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...) } else { // 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 ) { (node[ expando ] || (node[ expando ] = {}))[ 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.call( 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 ); return !results.pop(); }; }), "has": markFunction(function( selector ) { return function( elem ) { return Sizzle( selector, elem ).length > 0; }; }), "contains": markFunction(function( text ) { 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 only affected by element nodes and content nodes(including text(3), cdata(4)), // not comment, processing instructions, or others // Thanks to Diego Perini for the nodeName shortcut // Greater than "@" means alpha characters (specifically not starting with "#" or "?") for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { if ( elem.nodeName > "@" || elem.nodeType === 3 || elem.nodeType === 4 ) { 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; // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) // use getAttribute instead to test this case return elem.nodeName.toLowerCase() === "input" && elem.type === "text" && ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === elem.type ); }, // 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(); function tokenize( 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 data, cache, outerCache, dirkey = dirruns + " " + doneName; // We can't set arbitrary data on XML nodes, so they don't benefit from dir 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 ] = {}); if ( (cache = outerCache[ dir ]) && cache[0] === dirkey ) { if ( (data = cache[1]) === true || data === cachedruns ) { return data === true; } } else { cache = outerCache[ dir ] = [ dirkey ]; cache[1] = matcher( elem, context, xml ) || cachedruns; if ( cache[1] === true ) { 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 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.call( 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.call( checkContext, elem ) > -1; }, implicitRelative, true ), matchers = [ function( elem, context, xml ) { return ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( (checkContext = context).nodeType ? matchContext( elem, context, xml ) : matchAnyContext( elem, context, xml ) ); } ]; 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 ) { // A counter to specify which element is currently being matched var matcherCachedRuns = 0, bySet = setMatchers.length > 0, byElement = elementMatchers.length > 0, superMatcher = function( seed, context, xml, results, expandContext ) { var elem, j, matcher, setMatched = [], matchedCount = 0, i = "0", unmatched = seed && [], outermost = expandContext != null, contextBackup = outermostContext, // We must always have either seed elements or context elems = seed || byElement && Expr.find["TAG"]( "*", expandContext && context.parentNode || context ), // Use integer dirruns iff this is the outermost matcher dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1); if ( outermost ) { outermostContext = context !== document && context; cachedruns = matcherCachedRuns; } // Add elements passing elementMatchers directly to results // Keep `i` a string if there are no elements so `matchedCount` will be "00" below for ( ; (elem = elems[i]) != null; i++ ) { if ( byElement && elem ) { j = 0; while ( (matcher = elementMatchers[j++]) ) { if ( matcher( elem, context, xml ) ) { results.push( elem ); break; } } if ( outermost ) { dirruns = dirrunsUnique; cachedruns = ++matcherCachedRuns; } } // 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 ); } } } // Apply set filters to unmatched elements matchedCount += i; 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, group /* 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 ( !group ) { group = tokenize( selector ); } i = group.length; while ( i-- ) { cached = matcherFromTokens( group[i] ); if ( cached[ expando ] ) { setMatchers.push( cached ); } else { elementMatchers.push( cached ); } } // Cache the compiled function cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) ); } return cached; }; function multipleContexts( selector, contexts, results ) { var i = 0, len = contexts.length; for ( ; i < len; i++ ) { Sizzle( selector, contexts[i], results ); } return results; } function select( selector, context, results, seed ) { var i, tokens, token, type, find, match = tokenize( selector ); if ( !seed ) { // Try to minimize operations if there is only one group if ( match.length === 1 ) { // Take a shortcut and set the context if the root 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; } 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 ) && 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 // Provide `match` to avoid retokenization if we modified the selector above compile( selector, match )( seed, context, !documentIsHTML, results, rsibling.test( selector ) ); return results; } // One-time assignments // Sort stability support.sortStable = expando.split("").sort( sortOrder ).join("") === expando; // Support: Chrome<14 // 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 (val = elem.getAttributeNode( name )) && val.specified ? val.value : elem[ name ] === true ? name.toLowerCase() : null; } }); } jQuery.find = Sizzle; jQuery.expr = Sizzle.selectors; jQuery.expr[":"] = jQuery.expr.pseudos; jQuery.unique = Sizzle.uniqueSort; jQuery.text = Sizzle.getText; jQuery.isXMLDoc = Sizzle.isXML; jQuery.contains = Sizzle.contains; })( window ); // String to Object options format cache var optionsCache = {}; // Convert String-formatted options into Object-formatted ones and store in cache function createOptions( options ) { var object = optionsCache[ options ] = {}; jQuery.each( options.match( core_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" ? ( optionsCache[ options ] || 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, // End of the loop when firing firingLength, // Index of currently firing callback (modified by remove if needed) firingIndex, // First callback to fire (used internally by add and fireWith) firingStart, // Actual callback list list = [], // Stack of fire calls for repeatable lists stack = !options.once && [], // Fire callbacks fire = function( data ) { memory = options.memory && data; fired = true; firingIndex = firingStart || 0; firingStart = 0; firingLength = list.length; firing = true; for ( ; list && firingIndex < firingLength; firingIndex++ ) { if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) { memory = false; // To prevent further calls using add break; } } firing = false; if ( list ) { if ( stack ) { if ( stack.length ) { fire( stack.shift() ); } } else if ( memory ) { list = []; } else { self.disable(); } } }, // Actual Callbacks object self = { // Add a callback or a collection of callbacks to the list add: function() { if ( list ) { // First, we save the current length var start = list.length; (function add( args ) { jQuery.each( args, function( _, arg ) { var type = jQuery.type( arg ); if ( type === "function" ) { if ( !options.unique || !self.has( arg ) ) { list.push( arg ); } } else if ( arg && arg.length && type !== "string" ) { // Inspect recursively add( arg ); } }); })( arguments ); // Do we need to add the callbacks to the // current firing batch? if ( firing ) { firingLength = list.length; // With memory, if we're not firing then // we should call right away } else if ( memory ) { firingStart = start; fire( memory ); } } return this; }, // Remove a callback from the list remove: function() { if ( list ) { jQuery.each( arguments, function( _, arg ) { var index; while( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { list.splice( index, 1 ); // Handle firing indexes if ( firing ) { if ( index <= firingLength ) { firingLength--; } 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 && list.length ); }, // Remove all callbacks from the list empty: function() { list = []; firingLength = 0; return this; }, // Have the list do nothing anymore disable: function() { list = stack = memory = undefined; return this; }, // Is it disabled? disabled: function() { return !list; }, // Lock the list in its current state lock: function() { stack = undefined; if ( !memory ) { self.disable(); } return this; }, // Is it locked? locked: function() { return !stack; }, // Call all callbacks with the given context and arguments fireWith: function( context, args ) { if ( list && ( !fired || stack ) ) { args = args || []; args = [ context, args.slice ? args.slice() : args ]; if ( firing ) { stack.push( args ); } else { fire( args ); } } 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 action = tuple[ 0 ], 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() .done( newDefer.resolve ) .fail( newDefer.reject ) .progress( newDefer.notify ); } else { newDefer[ action + "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 = core_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 ? core_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() .done( updateFunc( i, resolveContexts, resolveValues ) ) .fail( deferred.reject ) .progress( updateFunc( i, progressContexts, progressValues ) ); } else { --remaining; } } } // if we're not waiting on anything, resolve the master if ( !remaining ) { deferred.resolveWith( resolveContexts, resolveValues ); } return deferred.promise(); } }); jQuery.support = (function( support ) { var all, a, input, select, fragment, opt, eventName, isSupported, i, div = document.createElement("div"); // Setup div.setAttribute( "className", "t" ); div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>"; // Finish early in limited (non-browser) environments all = div.getElementsByTagName("*") || []; a = div.getElementsByTagName("a")[ 0 ]; if ( !a || !a.style || !all.length ) { return support; } // First batch of tests select = document.createElement("select"); opt = select.appendChild( document.createElement("option") ); input = div.getElementsByTagName("input")[ 0 ]; a.style.cssText = "top:1px;float:left;opacity:.5"; // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) support.getSetAttribute = div.className !== "t"; // 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; // 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"; // Make sure that element opacity exists // (IE uses filter instead) // Use a regex to work around a WebKit issue. See #5145 support.opacity = /^0.5/.test( a.style.opacity ); // Verify style float existence // (IE uses styleFloat instead of cssFloat) support.cssFloat = !!a.style.cssFloat; // 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; // 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>"; // Will be defined later support.inlineBlockNeedsLayout = false; support.shrinkWrapBlocks = false; support.pixelPosition = false; support.deleteExpando = true; support.noCloneEvent = true; support.reliableMarginRight = true; support.boxSizingReliable = true; // Make sure checked status is properly cloned input.checked = true; support.noCloneChecked = input.cloneNode( true ).checked; // 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: IE<9 try { delete div.test; } catch( e ) { support.deleteExpando = false; } // 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"; // #11217 - WebKit loses check when the name is after the checked attribute input.setAttribute( "checked", "t" ); input.setAttribute( "name", "t" ); fragment = document.createDocumentFragment(); fragment.appendChild( input ); // Check if a disconnected checkbox will retain its checked // value of true after appended to the DOM (IE6/7) support.appendChecked = input.checked; // WebKit doesn't clone checked state correctly in fragments support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked; // Support: IE<9 // Opera does not clone events (and typeof div.attachEvent === undefined). // IE9-10 clones events bound via attachEvent, but they don't trigger with .click() if ( div.attachEvent ) { div.attachEvent( "onclick", function() { support.noCloneEvent = false; }); div.cloneNode( true ).click(); } // Support: IE<9 (lack submit/change bubble), Firefox 17+ (lack focusin event) // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP) for ( i in { submit: true, change: true, focusin: true }) { div.setAttribute( eventName = "on" + i, "t" ); support[ i + "Bubbles" ] = eventName in window || div.attributes[ eventName ].expando === false; } div.style.backgroundClip = "content-box"; div.cloneNode( true ).style.backgroundClip = ""; support.clearCloneStyle = div.style.backgroundClip === "content-box"; // Support: IE<9 // Iteration over object's inherited properties before its own. for ( i in jQuery( support ) ) { break; } support.ownLast = i !== "0"; // Run tests that need a body at doc ready jQuery(function() { var container, marginDiv, tds, divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;", body = document.getElementsByTagName("body")[0]; if ( !body ) { // Return for frameset docs that don't have a body return; } container = document.createElement("div"); container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; body.appendChild( container ).appendChild( div ); // Support: IE8 // 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.innerHTML = "<table><tr><td></td><td>t</td></tr></table>"; tds = div.getElementsByTagName("td"); tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none"; isSupported = ( tds[ 0 ].offsetHeight === 0 ); tds[ 0 ].style.display = ""; tds[ 1 ].style.display = "none"; // Support: IE8 // Check if empty table cells still have offsetWidth/Height support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 ); // Check box-sizing and margin behavior. div.innerHTML = ""; div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;"; // Workaround failing boxSizing test due to offsetWidth returning wrong value // with some non-1 values of body zoom, ticket #13543 jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() { support.boxSizing = div.offsetWidth === 4; }); // Use window.getComputedStyle because jsdom on node.js will break without it. if ( window.getComputedStyle ) { support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%"; support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; // Check if div with explicit width and no margin-right incorrectly // gets computed margin-right based on width of container. (#3333) // Fails in WebKit before Feb 2011 nightlies // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right marginDiv = div.appendChild( document.createElement("div") ); marginDiv.style.cssText = div.style.cssText = divReset; marginDiv.style.marginRight = marginDiv.style.width = "0"; div.style.width = "1px"; support.reliableMarginRight = !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight ); } if ( typeof div.style.zoom !== core_strundefined ) { // 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.innerHTML = ""; div.style.cssText = divReset + "width:1px;padding:1px;display:inline;zoom:1"; support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 ); // Support: IE6 // Check if elements with layout shrink-wrap their children div.style.display = "block"; div.innerHTML = "<div></div>"; div.firstChild.style.width = "5px"; support.shrinkWrapBlocks = ( div.offsetWidth !== 3 ); if ( support.inlineBlockNeedsLayout ) { // 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 ); // Null elements to avoid leaks in IE container = div = tds = marginDiv = null; }); // Null elements to avoid leaks in IE all = select = fragment = opt = a = input = null; return support; })({}); var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, rmultiDash = /([A-Z])/g; function internalData( elem, name, data, pvt /* Internal Use Only */ ){ if ( !jQuery.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 ] = core_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 ( !jQuery.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 ( jQuery.support.deleteExpando || cache != cache.window ) { /* jshint eqeqeq: true */ delete cache[ id ]; // When all else fails, null } else { cache[ id ] = null; } } jQuery.extend({ cache: {}, // The following elements throw uncatchable exceptions if you // attempt to add expando properties to them. noData: { "applet": true, "embed": true, // Ban all objects except for Flash (which 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 ); }, // A method for determining if a DOM node can handle the data expando acceptData: function( elem ) { // Do not set data on non-element because it will not be cleared (#8335). if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) { return false; } var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ]; // nodes accept data unless otherwise specified; rejection can be conditional return !noData || noData !== true && elem.getAttribute("classid") === noData; } }); jQuery.fn.extend({ data: function( key, value ) { var attrs, name, data = null, i = 0, elem = this[0]; // 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" ) ) { attrs = elem.attributes; for ( ; i < attrs.length; 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 ) ) : null; }, removeData: function( key ) { return this.each(function() { jQuery.removeData( this, key ); }); } }); 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; } 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 ); }); }, // Based off of the plugin by Clint Helfers, with permission. // http://blindsignals.com/index.php/2009/07/jquery-delay/ 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 = setTimeout( next, time ); hooks.stop = function() { clearTimeout( timeout ); }; }); }, 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 ); } }); var nodeHook, boolHook, rclass = /[\t\r\n\f]/g, rreturn = /\r/g, rfocusable = /^(?:input|select|textarea|button|object)$/i, rclickable = /^(?:a|area)$/i, ruseDefault = /^(?:checked|selected)$/i, getSetAttribute = jQuery.support.getSetAttribute, getSetInput = jQuery.support.input; jQuery.fn.extend({ attr: function( name, value ) { return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 ); }, removeAttr: function( name ) { return this.each(function() { jQuery.removeAttr( this, name ); }); }, prop: function( name, value ) { return jQuery.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 ) {} }); }, addClass: function( value ) { var classes, elem, cur, clazz, j, i = 0, len = this.length, proceed = typeof value === "string" && value; if ( jQuery.isFunction( value ) ) { return this.each(function( j ) { jQuery( this ).addClass( value.call( this, j, this.className ) ); }); } if ( proceed ) { // The disjunction here is for better compressibility (see removeClass) classes = ( value || "" ).match( core_rnotwhite ) || []; for ( ; i < len; i++ ) { elem = this[ i ]; cur = elem.nodeType === 1 && ( elem.className ? ( " " + elem.className + " " ).replace( rclass, " " ) : " " ); if ( cur ) { j = 0; while ( (clazz = classes[j++]) ) { if ( cur.indexOf( " " + clazz + " " ) < 0 ) { cur += clazz + " "; } } elem.className = jQuery.trim( cur ); } } } return this; }, removeClass: function( value ) { var classes, elem, cur, clazz, j, i = 0, len = this.length, proceed = arguments.length === 0 || typeof value === "string" && value; if ( jQuery.isFunction( value ) ) { return this.each(function( j ) { jQuery( this ).removeClass( value.call( this, j, this.className ) ); }); } if ( proceed ) { classes = ( value || "" ).match( core_rnotwhite ) || []; for ( ; i < len; i++ ) { elem = this[ i ]; // This expression is here for better compressibility (see addClass) cur = elem.nodeType === 1 && ( elem.className ? ( " " + elem.className + " " ).replace( rclass, " " ) : "" ); if ( cur ) { j = 0; while ( (clazz = classes[j++]) ) { // Remove *all* instances while ( cur.indexOf( " " + clazz + " " ) >= 0 ) { cur = cur.replace( " " + clazz + " ", " " ); } } elem.className = value ? jQuery.trim( cur ) : ""; } } } 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, this.className, stateVal), stateVal ); }); } return this.each(function() { if ( type === "string" ) { // toggle individual class names var className, i = 0, self = jQuery( this ), classNames = value.match( core_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 ( type === core_strundefined || type === "boolean" ) { if ( this.className ) { // store className if set jQuery._data( this, "__className__", this.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. this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || ""; } }); }, hasClass: function( selector ) { var className = " " + selector + " ", i = 0, l = this.length; for ( ; i < l; i++ ) { if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) { return true; } } return false; }, val: function( value ) { var ret, hooks, 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 ) { // Use proper attribute retrieval(#6932, #12072) var val = jQuery.find.attr( elem, "value" ); return val != null ? val : elem.text; } }, 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 ( jQuery.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 ( (option.selected = jQuery.inArray( jQuery(option).val(), values ) >= 0) ) { optionSet = true; } } // force browsers to behave consistently when non-matching value is set if ( !optionSet ) { elem.selectedIndex = -1; } return values; } } }, attr: function( elem, name, value ) { var hooks, ret, nType = elem.nodeType; // don't get/set attributes on text, comment and attribute nodes if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { return; } // Fallback to prop when attributes are not supported if ( typeof elem.getAttribute === core_strundefined ) { 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 ); } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { return ret; } else { elem.setAttribute( name, value + "" ); return value; } } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { return ret; } else { ret = jQuery.find.attr( elem, name ); // Non-existent attributes return null, we normalize to undefined return ret == null ? undefined : ret; } }, removeAttr: function( elem, value ) { var name, propName, i = 0, attrNames = value && value.match( core_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 ); } } }, attrHooks: { type: { set: function( elem, value ) { if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) { // Setting the type on a radio button after the value resets the value in IE6-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; } } } }, propFix: { "for": "htmlFor", "class": "className" }, prop: function( elem, name, value ) { var ret, hooks, notxml, nType = elem.nodeType; // don't get/set properties on text, comment and attribute nodes if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { return; } notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); if ( notxml ) { // Fix name and attach hooks name = jQuery.propFix[ name ] || name; hooks = jQuery.propHooks[ name ]; } if ( value !== undefined ) { return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ? ret : ( elem[ name ] = value ); } else { return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ? ret : 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; } } } }); // 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 ); // Use defaultChecked and defaultSelected for oldIE } else { 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 = jQuery.expr.attrHandle[ name ] || jQuery.find.attr; jQuery.expr.attrHandle[ name ] = getSetInput && getSetAttribute || !ruseDefault.test( name ) ? function( elem, name, isXML ) { var fn = jQuery.expr.attrHandle[ name ], ret = isXML ? undefined : /* jshint eqeqeq: false */ (jQuery.expr.attrHandle[ name ] = undefined) != getter( elem, name, isXML ) ? name.toLowerCase() : null; jQuery.expr.attrHandle[ name ] = fn; return ret; } : function( elem, name, isXML ) { return isXML ? undefined : 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) return name === "value" || value === elem.getAttribute( name ) ? value : undefined; } }; jQuery.expr.attrHandle.id = jQuery.expr.attrHandle.name = jQuery.expr.attrHandle.coords = // Some attributes are constructed with empty-string values when not defined function( elem, name, isXML ) { var ret; return isXML ? undefined : (ret = elem.getAttributeNode( name )) && ret.value !== "" ? ret.value : null; }; jQuery.valHooks.button = { get: function( elem, name ) { var ret = elem.getAttributeNode( name ); return ret && ret.specified ? ret.value : undefined; }, 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; } } }; }); } // Some attributes require a special call on IE // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx if ( !jQuery.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 ); } }; }); } if ( !jQuery.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 senstitivity in URL's, like in "background" return elem.style.cssText || undefined; }, set: function( elem, value ) { return ( elem.style.cssText = value + "" ); } }; } // Safari mis-reports the default selected property of an option // Accessing the parent's selectedIndex property fixes it if ( !jQuery.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; } }; } jQuery.each([ "tabIndex", "readOnly", "maxLength", "cellSpacing", "cellPadding", "rowSpan", "colSpan", "useMap", "frameBorder", "contentEditable" ], function() { jQuery.propFix[ this.toLowerCase() ] = this; }); // IE6/7 call enctype encoding if ( !jQuery.support.enctype ) { jQuery.propFix.enctype = "encoding"; } // 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 ) >= 0 ); } } }; if ( !jQuery.support.checkOn ) { jQuery.valHooks[ this ].get = function( elem ) { // Support: Webkit // "" is returned instead of "on" if a value isn't specified return elem.getAttribute("value") === null ? "on" : elem.value; }; } }); var rformElems = /^(?:input|select|textarea)$/i, rkeyEvent = /^key/, rmouseEvent = /^(?:mouse|contextmenu)|click/, rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, rtypenamespace = /^([^.]*)(?:\.(.+)|)$/; function returnTrue() { return true; } function returnFalse() { return false; } function safeActiveElement() { try { return document.activeElement; } catch ( err ) { } } /* * 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 !== core_strundefined && (!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( core_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( core_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 = core_hasOwn.call( event, "type" ) ? event.type : event, namespaces = core_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(".") >= 0 ) { // 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.namespace_re = 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 && jQuery.acceptData( cur ) && handle.apply && handle.apply( cur, data ) === 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) && jQuery.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, ret, handleObj, matched, j, handlerQueue = [], args = core_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.namespace_re || event.namespace_re.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 sel, handleObj, matches, i, handlerQueue = [], delegateCount = handlers.delegateCount, cur = event.target; // Find delegate handlers // Black-hole SVG <use> instance trees (#13180) // Avoid non-left-click bubbling in Firefox (#3861) if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) { /* 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 ) >= 0 : 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: Chrome 23+, Safari? // 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 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 ) { // Even when returnValue equals to undefined Firefox will still show alert if ( event.result !== undefined ) { event.originalEvent.returnValue = event.result; } } } }, simulate: function( type, elem, event, bubble ) { // Piggyback on a donor event to simulate a different one. // Fake originalEvent to avoid donor's stopPropagation, but if the // simulated event prevents default then we do the same on the donor. var e = jQuery.extend( new jQuery.Event(), event, { type: type, isSimulated: true, originalEvent: {} } ); if ( bubble ) { jQuery.event.trigger( e, null, elem ); } else { jQuery.event.dispatch.call( elem, e ); } if ( e.isDefaultPrevented() ) { event.preventDefault(); } } }; jQuery.removeEvent = document.removeEventListener ? function( elem, type, handle ) { if ( elem.removeEventListener ) { elem.removeEventListener( type, handle, false ); } } : 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 ] === core_strundefined ) { 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.returnValue === false || src.getPreventDefault && src.getPreventDefault() ) ? 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 = { 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 ) { 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() { this.isImmediatePropagationStopped = returnTrue; this.stopPropagation(); } }; // Create mouseenter/leave events using mouseover/out and event-time checks jQuery.each({ mouseenter: "mouseover", mouseleave: "mouseout" }, 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 mousenter/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 ( !jQuery.support.submitBubbles ) { 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" ) ? elem.form : undefined; if ( form && !jQuery._data( form, "submitBubbles" ) ) { jQuery.event.add( form, "submit._submit", function( event ) { event._submit_bubble = true; }); jQuery._data( form, "submitBubbles", 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._submit_bubble ) { delete event._submit_bubble; if ( this.parentNode && !event.isTrigger ) { jQuery.event.simulate( "submit", this.parentNode, event, true ); } } }, 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 ( !jQuery.support.changeBubbles ) { 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._just_changed = true; } }); jQuery.event.add( this, "click._change", function( event ) { if ( this._just_changed && !event.isTrigger ) { this._just_changed = false; } // Allow triggered, simulated change events (#11500) jQuery.event.simulate( "change", this, event, true ); }); } 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, "changeBubbles" ) ) { jQuery.event.add( elem, "change._change", function( event ) { if ( this.parentNode && !event.isSimulated && !event.isTrigger ) { jQuery.event.simulate( "change", this.parentNode, event, true ); } }); jQuery._data( elem, "changeBubbles", 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 ); } }; } // Create "bubbling" focus and blur events if ( !jQuery.support.focusinBubbles ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { // Attach a single capturing handler while someone wants focusin/focusout var attaches = 0, handler = function( event ) { jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true ); }; jQuery.event.special[ fix ] = { setup: function() { if ( attaches++ === 0 ) { document.addEventListener( orig, handler, true ); } }, teardown: function() { if ( --attaches === 0 ) { document.removeEventListener( orig, handler, true ); } } }; }); } jQuery.fn.extend({ on: function( types, selector, data, fn, /*INTERNAL*/ one ) { var type, origFn; // 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 ) { this.on( type, selector, data, types[ type ], one ); } return this; } 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 this; } 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 this.each( function() { jQuery.event.add( this, types, fn, data, selector ); }); }, one: function( types, selector, data, fn ) { return this.on( 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 isSimple = /^.[^:#\[\.,]*$/, rparentsprev = /^(?:parents|prev(?:Until|All))/, rneedsContext = jQuery.expr.match.needsContext, // 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({ 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; }, 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; } } }); }, not: function( selector ) { return this.pushStack( winnow(this, selector || [], true) ); }, filter: function( selector ) { return this.pushStack( winnow(this, selector || [], false) ); }, 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; }, closest: function( selectors, context ) { var cur, i = 0, l = this.length, ret = [], 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)) ) { cur = ret.push( cur ); break; } } } return this.pushStack( ret.length > 1 ? jQuery.unique( ret ) : ret ); }, // 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 ) { var set = typeof selector === "string" ? jQuery( selector, context ) : jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ), all = jQuery.merge( this.get(), set ); return this.pushStack( jQuery.unique(all) ); }, 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 jQuery.dir( elem, "parentNode" ); }, parentsUntil: function( elem, i, until ) { return jQuery.dir( elem, "parentNode", until ); }, next: function( elem ) { return sibling( elem, "nextSibling" ); }, prev: function( elem ) { return sibling( elem, "previousSibling" ); }, nextAll: function( elem ) { return jQuery.dir( elem, "nextSibling" ); }, prevAll: function( elem ) { return jQuery.dir( elem, "previousSibling" ); }, nextUntil: function( elem, i, until ) { return jQuery.dir( elem, "nextSibling", until ); }, prevUntil: function( elem, i, until ) { return jQuery.dir( elem, "previousSibling", until ); }, siblings: function( elem ) { return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem ); }, children: function( elem ) { return jQuery.sibling( 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.unique( ret ); } // Reverse order for parents* and prev-derivatives if ( rparentsprev.test( name ) ) { ret = ret.reverse(); } } return this.pushStack( ret ); }; }); jQuery.extend({ 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; })); }, dir: function( elem, dir, until ) { var matched = [], cur = elem[ dir ]; while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) { if ( cur.nodeType === 1 ) { matched.push( cur ); } cur = cur[dir]; } return matched; }, sibling: function( n, elem ) { var r = []; for ( ; n; n = n.nextSibling ) { if ( n.nodeType === 1 && n !== elem ) { r.push( n ); } } return r; } }); // 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 ( isSimple.test( qualifier ) ) { return jQuery.filter( qualifier, elements, not ); } qualifier = jQuery.filter( qualifier, elements ); } return jQuery.grep( elements, function( elem ) { return ( jQuery.inArray( elem, qualifier ) >= 0 ) !== not; }); } function createSafeFragment( document ) { var list = nodeNames.split( "|" ), safeFrag = document.createDocumentFragment(); if ( safeFrag.createElement ) { while ( list.length ) { safeFrag.createElement( list.pop() ); } } return safeFrag; } var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"), rleadingWhitespace = /^\s+/, rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, rtbody = /<tbody/i, rhtml = /<|&#?\w+;/, rnoInnerhtml = /<(?:script|style|link)/i, manipulation_rcheckableType = /^(?:checkbox|radio)$/i, // checked="checked" or checked rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, rscriptType = /^$|\/(?:java|ecma)script/i, rscriptTypeMasked = /^true\/(.*)/, rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g, // We have to close these tags to support XHTML (#13200) wrapMap = { option: [ 1, "<select multiple='multiple'>", "</select>" ], legend: [ 1, "<fieldset>", "</fieldset>" ], area: [ 1, "<map>", "</map>" ], 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: jQuery.support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X<div>", "</div>" ] }, safeFragment = createSafeFragment( document ), fragmentDiv = safeFragment.appendChild( document.createElement("div") ); wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; wrapMap.th = wrapMap.td; jQuery.fn.extend({ text: function( value ) { return jQuery.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 this.domManip( arguments, function( elem ) { if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { var target = manipulationTarget( this, elem ); target.appendChild( elem ); } }); }, prepend: function() { return this.domManip( 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 this.domManip( arguments, function( elem ) { if ( this.parentNode ) { this.parentNode.insertBefore( elem, this ); } }); }, after: function() { return this.domManip( arguments, function( elem ) { if ( this.parentNode ) { this.parentNode.insertBefore( elem, this.nextSibling ); } }); }, // keepData is for internal use only--do not document remove: function( selector, keepData ) { var elem, elems = selector ? jQuery.filter( selector, this ) : this, i = 0; for ( ; (elem = elems[i]) != null; i++ ) { if ( !keepData && elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem ) ); } if ( elem.parentNode ) { if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) { setGlobalEval( getAll( elem, "script" ) ); } elem.parentNode.removeChild( elem ); } } return this; }, 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 jQuery.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 ) && ( jQuery.support.htmlSerialize || !rnoshimcache.test( value ) ) && ( jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value ) ) && !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[1].toLowerCase() ] ) { value = value.replace( rxhtmlTag, "<$1></$2>" ); 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 // Snapshot the DOM in case .domManip sweeps something relevant into its fragment args = jQuery.map( this, function( elem ) { return [ elem.nextSibling, elem.parentNode ]; }), i = 0; // Make the changes, replacing each context element with the new content this.domManip( arguments, function( elem ) { var next = args[ i++ ], parent = args[ i++ ]; if ( parent ) { // Don't use the snapshot next if it has moved (#13810) if ( next && next.parentNode !== parent ) { next = this.nextSibling; } jQuery( this ).remove(); parent.insertBefore( elem, next ); } // Allow new content to include elements from the context set }, true ); // Force removal if there was no new content (e.g., from empty arguments) return i ? this : this.remove(); }, detach: function( selector ) { return this.remove( selector, true ); }, domManip: function( args, callback, allowIntersection ) { // Flatten any nested arrays args = core_concat.apply( [], args ); var first, node, hasScripts, scripts, doc, fragment, i = 0, l = this.length, set = this, 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" || jQuery.support.checkClone || !rchecked.test( value ) ) ) { return this.each(function( index ) { var self = set.eq( index ); if ( isFunction ) { args[0] = value.call( this, index, self.html() ); } self.domManip( args, callback, allowIntersection ); }); } if ( l ) { fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, !allowIntersection && this ); first = fragment.firstChild; if ( fragment.childNodes.length === 1 ) { fragment = first; } if ( first ) { 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 ) { jQuery.merge( scripts, getAll( node, "script" ) ); } } callback.call( this[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 ) { // Hope ajax is available... jQuery._evalUrl( node.src ); } else { jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) ); } } } } // Fix #11809: Avoid leaking memory fragment = first = null; } } return this; } }); // Support: IE<8 // Manipulating tables requires a tbody function manipulationTarget( elem, content ) { return jQuery.nodeName( elem, "table" ) && jQuery.nodeName( content.nodeType === 1 ? 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; } // 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" ) ); } } 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 ( !jQuery.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 ( jQuery.support.html5Clone && ( src.innerHTML && !jQuery.trim(dest.innerHTML) ) ) { dest.innerHTML = src.innerHTML; } } else if ( nodeName === "input" && manipulation_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; } } 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() core_push.apply( ret, elems.get() ); } return this.pushStack( ret ); }; }); function getAll( context, tag ) { var elems, elem, i = 0, found = typeof context.getElementsByTagName !== core_strundefined ? context.getElementsByTagName( tag || "*" ) : typeof context.querySelectorAll !== core_strundefined ? 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; } // Used in buildFragment, fixes the defaultChecked property function fixDefaultChecked( elem ) { if ( manipulation_rcheckableType.test( elem.type ) ) { elem.defaultChecked = elem.checked; } } jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { var destElements, node, clone, i, srcElements, inPage = jQuery.contains( elem.ownerDocument, elem ); if ( jQuery.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 ( (!jQuery.support.noCloneEvent || !jQuery.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; }, buildFragment: function( elems, context, scripts, selection ) { 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] + elem.replace( rxhtmlTag, "<$1></$2>" ) + 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 ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) { nodes.push( context.createTextNode( rleadingWhitespace.exec( elem )[0] ) ); } // Remove IE's autoinserted <tbody> from table fragments if ( !jQuery.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 ( !jQuery.support.appendChecked ) { jQuery.grep( getAll( nodes, "input" ), fixDefaultChecked ); } i = 0; while ( (elem = nodes[ i++ ]) ) { // #4087 - If origin and destination elements are the same, and this is // that element, do not do anything if ( selection && jQuery.inArray( elem, selection ) !== -1 ) { 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; }, cleanData: function( elems, /* internal */ acceptData ) { var elem, type, id, data, i = 0, internalKey = jQuery.expando, cache = jQuery.cache, deleteExpando = jQuery.support.deleteExpando, special = jQuery.event.special; for ( ; (elem = elems[i]) != null; i++ ) { if ( acceptData || jQuery.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 ]; // IE does not allow us to delete expando properties from nodes, // nor does it have a removeAttribute function on Document nodes; // we must handle all of these cases if ( deleteExpando ) { delete elem[ internalKey ]; } else if ( typeof elem.removeAttribute !== core_strundefined ) { elem.removeAttribute( internalKey ); } else { elem[ internalKey ] = null; } core_deletedIds.push( id ); } } } } }, _evalUrl: function( url ) { return jQuery.ajax({ url: url, type: "GET", dataType: "script", 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(); } }); var iframe, getStyles, curCSS, ralpha = /alpha\([^)]*\)/i, ropacity = /opacity\s*=\s*([^)]*)/, rposition = /^(top|right|bottom|left)$/, // 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]).+)/, rmargin = /^margin/, rnumsplit = new RegExp( "^(" + core_pnum + ")(.*)$", "i" ), rnumnonpx = new RegExp( "^(" + core_pnum + ")(?!px)[a-z%]+$", "i" ), rrelNum = new RegExp( "^([+-])=(" + core_pnum + ")", "i" ), elemdisplay = { BODY: "block" }, cssShow = { position: "absolute", visibility: "hidden", display: "block" }, cssNormalTransform = { letterSpacing: 0, fontWeight: 400 }, cssExpand = [ "Top", "Right", "Bottom", "Left" ], cssPrefixes = [ "Webkit", "O", "Moz", "ms" ]; // return a css property mapped to a potentially vendor prefixed property function vendorPropName( style, name ) { // shortcut for names that are not vendor prefixed if ( name in style ) { return name; } // check for vendor prefixed names var capName = name.charAt(0).toUpperCase() + name.slice(1), origName = name, i = cssPrefixes.length; while ( i-- ) { name = cssPrefixes[ i ] + capName; if ( name in style ) { return name; } } return origName; } function isHidden( 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 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", css_defaultDisplay(elem.nodeName) ); } } else { if ( !values[ index ] ) { 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; } jQuery.fn.extend({ css: function( name, value ) { return jQuery.access( this, function( elem, name, value ) { var len, styles, 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(); } }); } }); 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: { "columnCount": true, "fillOpacity": 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": jQuery.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( style, 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 relative number strings (+= or -=) to relative numbers. #7345 if ( type === "string" && (ret = rrelNum.exec( value )) ) { value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) ); // Fixes bug #9237 type = "number"; } // Make sure that NaN and null values aren't set. See: #7116 if ( value == null || type === "number" && isNaN( value ) ) { return; } // If a number was passed in, add 'px' to the (except for certain CSS properties) if ( type === "number" && !jQuery.cssNumber[ origName ] ) { value += "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 ( !jQuery.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 ) { // Wrapped to prevent IE from throwing errors when 'invalid' values are provided // Fixes bug #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( elem.style, 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 || jQuery.isNumeric( num ) ? num || 0 : val; } return val; } }); // NOTE: we've included the "window" in window.getComputedStyle // because jsdom on node.js will break without it. if ( window.getComputedStyle ) { getStyles = function( elem ) { return window.getComputedStyle( elem, null ); }; curCSS = function( elem, name, _computed ) { var width, minWidth, maxWidth, computed = _computed || getStyles( elem ), // getPropertyValue is only needed for .css('filter') in IE9, see #12537 ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined, style = elem.style; if ( computed ) { if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) { ret = jQuery.style( elem, name ); } // 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 ( 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; } } return ret; }; } else if ( document.documentElement.currentStyle ) { getStyles = function( elem ) { return elem.currentStyle; }; curCSS = function( elem, name, _computed ) { var left, rs, rsLeft, computed = _computed || getStyles( elem ), ret = computed ? computed[ name ] : undefined, style = elem.style; // 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; } } return ret === "" ? "auto" : ret; }; } 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 = jQuery.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 && ( jQuery.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"; } // Try to determine the default display value of an element function css_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'/>") .css( "cssText", "display:block !important" ) ).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; doc.write("<!doctype html><html><body>"); doc.close(); display = actualDisplay( nodeName, doc ); iframe.detach(); } // Store the correct default display elemdisplay[ nodeName ] = display; } return display; } // Called ONLY from within css_defaultDisplay function actualDisplay( name, doc ) { var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ), display = jQuery.css( elem[0], "display" ); elem.remove(); return display; } 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 elem.offsetWidth === 0 && rdisplayswap.test( jQuery.css( elem, "display" ) ) ? jQuery.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, jQuery.support.boxSizing && jQuery.css( elem, "boxSizing", false, styles ) === "border-box", styles ) : 0 ); } }; }); if ( !jQuery.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; } }; } // These hooks cannot be added until DOM ready because the support test // for it is not run until after DOM ready jQuery(function() { if ( !jQuery.support.reliableMarginRight ) { jQuery.cssHooks.marginRight = { get: function( elem, computed ) { if ( computed ) { // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right // Work around by temporarily setting element display to inline-block return jQuery.swap( elem, { "display": "inline-block" }, curCSS, [ elem, "marginRight" ] ); } } }; } // 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 if ( !jQuery.support.pixelPosition && jQuery.fn.position ) { jQuery.each( [ "top", "left" ], function( i, prop ) { jQuery.cssHooks[ prop ] = { get: 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; } } }; }); } }); if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.hidden = function( elem ) { // Support: Opera <= 12.12 // Opera reports offsetWidths and offsetHeights less than zero on some elements return elem.offsetWidth <= 0 && elem.offsetHeight <= 0 || (!jQuery.support.reliableHiddenOffsets && ((elem.style && elem.style.display) || jQuery.css( elem, "display" )) === "none"); }; jQuery.expr.filters.visible = function( elem ) { return !jQuery.expr.filters.hidden( elem ); }; } // 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; } }); var r20 = /%20/g, rbracket = /\[\]$/, rCRLF = /\r?\n/g, rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i, rsubmittable = /^(?:input|select|textarea|keygen)/i; 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 || !manipulation_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(); } }); //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, "+" ); }; 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" ? 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 ); } } 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 ); }, 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 ); } }); var // Document location ajaxLocParts, ajaxLocation, ajax_nonce = jQuery.now(), ajax_rquery = /\?/, rhash = /#.*$/, rts = /([?&])_=[^&]*/, rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL // #7653, #8125, #8152: local protocol detection rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/, rnoContent = /^(?:GET|HEAD)$/, rprotocol = /^\/\//, rurl = /^([\w.+-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/, // Keep a copy of the old load method _load = jQuery.fn.load, /* 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("*"); // #8138, IE may throw an exception when accessing // a field from window.location if document.domain has been set try { ajaxLocation = location.href; } catch( e ) { // Use the href attribute of an A element // since IE will modify it given document.location ajaxLocation = document.createElement( "a" ); ajaxLocation.href = ""; ajaxLocation = ajaxLocation.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( core_rnotwhite ) || []; if ( jQuery.isFunction( func ) ) { // For each dataType in the dataTypeExpression while ( (dataType = dataTypes[i++]) ) { // Prepend if requested if ( dataType[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; } jQuery.fn.load = function( url, params, callback ) { if ( typeof url !== "string" && _load ) { return _load.apply( this, arguments ); } var selector, response, type, self = this, off = url.indexOf(" "); if ( off >= 0 ) { selector = 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 type: type, 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 ); }).complete( callback && function( jqXHR, status ) { self.each( callback, 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.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: /xml/, html: /html/, json: /json/ }, 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( core_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 fireGlobals = 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 += ( ajax_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_=" + ajax_nonce++ ) : // Otherwise add one to the end cacheURL + ( ajax_rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ajax_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 ] ); } // Timeout if ( s.async && s.timeout > 0 ) { timeoutTimer = 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 ) { 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; } return jQuery.ajax({ url: url, type: method, dataType: type, data: data, success: callback }); }; }); /* 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" ] ) { 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 }; } // Install script dataType jQuery.ajaxSetup({ accepts: { script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" }, contents: { script: /(?:java|ecma)script/ }, 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 + "_" + ( ajax_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") && 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 += ( ajax_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() { // Restore preexisting value 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"; } }); var xhrCallbacks, xhrSupported, xhrId = 0, // #5280: Internet Explorer will keep connections alive if we don't abort on unload xhrOnUnloadAbort = window.ActiveXObject && function() { // Abort all pending requests var key; for ( key in xhrCallbacks ) { xhrCallbacks[ key ]( 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 ) {} } // Create the request object // (This is still attached to ajaxSettings for backward compatibility) jQuery.ajaxSettings.xhr = window.ActiveXObject ? /* Microsoft failed to properly * implement the XMLHttpRequest in IE7 (can't request local files), * so we use the ActiveXObject when it is available * Additionally XMLHttpRequest can be disabled in IE7/IE8 so * we need a fallback. */ function() { return !this.isLocal && createStandardXHR() || createActiveXHR(); } : // For all other browsers, use the standard XMLHttpRequest object createStandardXHR; // Determine support properties xhrSupported = jQuery.ajaxSettings.xhr(); jQuery.support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported ); xhrSupported = jQuery.support.ajax = !!xhrSupported; // Create transport if the browser can provide an xhr if ( xhrSupported ) { jQuery.ajaxTransport(function( s ) { // Cross domain only allowed if supported through XMLHttpRequest if ( !s.crossDomain || jQuery.support.cors ) { var callback; return { send: function( headers, complete ) { // Get a new xhr var handle, i, xhr = s.xhr(); // Open the socket // Passing null username, generates a login popup on Opera (#2865) if ( s.username ) { xhr.open( s.type, s.url, s.async, s.username, s.password ); } else { xhr.open( s.type, s.url, s.async ); } // Apply custom fields if provided if ( s.xhrFields ) { for ( i in s.xhrFields ) { xhr[ i ] = s.xhrFields[ i ]; } } // Override mime type if needed if ( s.mimeType && xhr.overrideMimeType ) { xhr.overrideMimeType( s.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 ( !s.crossDomain && !headers["X-Requested-With"] ) { headers["X-Requested-With"] = "XMLHttpRequest"; } // Need an extra try/catch for cross domain requests in Firefox 3 try { for ( i in headers ) { xhr.setRequestHeader( i, headers[ i ] ); } } catch( err ) {} // Do send the request // This may raise an exception which is actually // handled in jQuery.ajax (so no try/catch here) xhr.send( ( s.hasContent && s.data ) || null ); // Listener callback = function( _, isAbort ) { var status, responseHeaders, statusText, responses; // Firefox throws exceptions when accessing properties // of an xhr when a network error occurred // http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE) try { // Was never called and is aborted or complete if ( callback && ( isAbort || xhr.readyState === 4 ) ) { // Only called once callback = undefined; // Do not keep as active anymore if ( handle ) { xhr.onreadystatechange = jQuery.noop; if ( xhrOnUnloadAbort ) { delete xhrCallbacks[ handle ]; } } // If it's an abort if ( isAbort ) { // Abort it manually if needed if ( xhr.readyState !== 4 ) { xhr.abort(); } } else { responses = {}; status = xhr.status; responseHeaders = xhr.getAllResponseHeaders(); // When requesting binary data, IE6-9 will throw an exception // on any attempt to access responseText (#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 && s.isLocal && !s.crossDomain ) { status = responses.text ? 200 : 404; // IE - #1450: sometimes returns 1223 when it should be 204 } else if ( status === 1223 ) { status = 204; } } } } catch( firefoxAccessException ) { if ( !isAbort ) { complete( -1, firefoxAccessException ); } } // Call complete if needed if ( responses ) { complete( status, statusText, responses, responseHeaders ); } }; if ( !s.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 setTimeout( callback ); } else { handle = ++xhrId; if ( xhrOnUnloadAbort ) { // Create the active xhrs callbacks list if needed // and attach the unload handler if ( !xhrCallbacks ) { xhrCallbacks = {}; jQuery( window ).unload( xhrOnUnloadAbort ); } // Add to list of active xhrs callbacks xhrCallbacks[ handle ] = callback; } xhr.onreadystatechange = callback; } }, abort: function() { if ( callback ) { callback( undefined, true ); } } }; } }); } var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, rfxnum = new RegExp( "^(?:([+-])=|)(" + core_pnum + ")([a-z%]*)$", "i" ), rrun = /queueHooks$/, animationPrefilters = [ defaultPrefilter ], tweeners = { "*": [function( prop, value ) { var tween = this.createTween( prop, value ), target = tween.cur(), parts = rfxnum.exec( value ), unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ), // Starting value computation is required for potential unit mismatches start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) && rfxnum.exec( jQuery.css( tween.elem, prop ) ), scale = 1, maxIterations = 20; if ( start && start[ 3 ] !== unit ) { // Trust units reported by jQuery.css unit = unit || start[ 3 ]; // Make sure we update the tween properties later on parts = parts || []; // Iteratively approximate from a nonzero starting point start = +target || 1; do { // If previous iteration zeroed out, double until we get *something* // Use a string for doubling factor so we don't accidentally see scale as unchanged below scale = scale || ".5"; // Adjust and apply start = start / scale; jQuery.style( tween.elem, prop, start + unit ); // Update scale, tolerating zero or NaN from tween.cur() // And breaking the loop if scale is unchanged or perfect, or if we've just had enough } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations ); } // Update tween properties if ( parts ) { start = tween.start = +start || +target || 0; tween.unit = unit; // If a +=/-= token was provided, we're doing a relative animation tween.end = parts[ 1 ] ? start + ( parts[ 1 ] + 1 ) * parts[ 2 ] : +parts[ 2 ]; } return tween; }] }; // Animations created synchronously will run synchronously function createFxNow() { setTimeout(function() { fxNow = undefined; }); return ( fxNow = jQuery.now() ); } function createTween( value, prop, animation ) { var tween, collection = ( tweeners[ prop ] || [] ).concat( 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 Animation( elem, properties, options ) { var result, stopped, index = 0, length = animationPrefilters.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 ), // 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: {} }, 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.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 = animationPrefilters[ index ].call( animation, elem, props, animation.opts ); if ( 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 ); } 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; } } } jQuery.Animation = jQuery.extend( Animation, { tweener: function( props, callback ) { if ( jQuery.isFunction( props ) ) { callback = props; props = [ "*" ]; } else { props = props.split(" "); } var prop, index = 0, length = props.length; for ( ; index < length ; index++ ) { prop = props[ index ]; tweeners[ prop ] = tweeners[ prop ] || []; tweeners[ prop ].unshift( callback ); } }, prefilter: function( callback, prepend ) { if ( prepend ) { animationPrefilters.unshift( callback ); } else { animationPrefilters.push( callback ); } } }); function defaultPrefilter( elem, props, opts ) { /* jshint validthis: true */ var prop, value, toggle, tween, hooks, oldfire, 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 if ( jQuery.css( elem, "display" ) === "inline" && jQuery.css( elem, "float" ) === "none" ) { // inline-level elements accept inline-block; // block-level elements need to be inline with layout if ( !jQuery.support.inlineBlockNeedsLayout || css_defaultDisplay( elem.nodeName ) === "inline" ) { style.display = "inline-block"; } else { style.zoom = 1; } } } if ( opts.overflow ) { style.overflow = "hidden"; if ( !jQuery.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" ) ) { continue; } orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop ); } } 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; } } } } } 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 || "swing"; 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; if ( tween.elem[ tween.prop ] != null && (!tween.elem.style || 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.style && ( 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.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 ); }; }); 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; }); } }); // 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; } // 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.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.easing = { linear: function( p ) { return p; }, swing: function( p ) { return 0.5 - Math.cos( p*Math.PI ) / 2; } }; jQuery.timers = []; jQuery.fx = Tween.prototype.init; 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 ) { if ( timer() && jQuery.timers.push( timer ) ) { jQuery.fx.start(); } }; jQuery.fx.interval = 13; jQuery.fx.start = function() { if ( !timerId ) { timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval ); } }; jQuery.fx.stop = function() { clearInterval( timerId ); timerId = null; }; jQuery.fx.speeds = { slow: 600, fast: 200, // Default speed _default: 400 }; // Back Compat <1.8 extension point jQuery.fx.step = {}; if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.animated = function( elem ) { return jQuery.grep(jQuery.timers, function( fn ) { return elem === fn.elem; }).length; }; } jQuery.fn.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 !== core_strundefined ) { 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 ) }; }; jQuery.offset = { setOffset: function( elem, options, i ) { var position = jQuery.css( elem, "position" ); // set position first, in-case top/left are set even on static elem if ( position === "static" ) { elem.style.position = "relative"; } var curElem = jQuery( elem ), curOffset = curElem.offset(), curCSSTop = jQuery.css( elem, "top" ), curCSSLeft = jQuery.css( elem, "left" ), calculatePosition = ( position === "absolute" || position === "fixed" ) && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1, props = {}, curPosition = {}, curTop, curLeft; // 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 ) ) { options = options.call( elem, i, 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({ 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 it's 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 || docElem; while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) { offsetParent = offsetParent.offsetParent; } return offsetParent || docElem; }); } }); // 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 jQuery.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 ); }; }); function getWindow( elem ) { return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 ? elem.defaultView || elem.parentWindow : false; } // 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 jQuery.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 ); }; }); }); // Limit scope pollution from any deprecated API // (function() { // The number of elements contained in the matched element set jQuery.fn.size = function() { return this.length; }; jQuery.fn.andSelf = jQuery.fn.addBack; // })(); if ( typeof module === "object" && module && typeof module.exports === "object" ) { // Expose jQuery as module.exports in loaders that implement the Node // module pattern (including browserify). Do not create the global, since // the user will be storing it themselves locally, and globals are frowned // upon in the Node module world. module.exports = jQuery; } else { // Otherwise expose jQuery to the global object as usual window.jQuery = window.$ = jQuery; // 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. if ( typeof define === "function" && define.amd ) { define( "jquery", [], function () { return jQuery; } ); } } })( window ); (function($, undefined) { /** * Unobtrusive scripting adapter for jQuery * https://github.com/rails/jquery-ujs * * Requires jQuery 1.7.0 or later. * * Released under the MIT license * */ // Cut down on the number of issues from people inadvertently including jquery_ujs twice // by detecting and raising an error when it happens. if ( $.rails !== undefined ) { $.error('jquery-ujs has already been loaded!'); } // Shorthand to make it a little easier to call public rails functions from within rails.js var rails; var $document = $(document); $.rails = rails = { // Link elements bound by jquery-ujs linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]', // Button elements boud jquery-ujs buttonClickSelector: 'button[data-remote]', // Select elements bound by jquery-ujs inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]', // Form elements bound by jquery-ujs formSubmitSelector: 'form', // Form input elements bound by jquery-ujs formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])', // Form input elements disabled during form submission disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]', // Form input elements re-enabled after form submission enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled', // Form required input elements requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])', // Form file input elements fileInputSelector: 'input[type=file]', // Link onClick disable selector with possible reenable after remote submission linkDisableSelector: 'a[data-disable-with]', // Make sure that every Ajax request sends the CSRF token CSRFProtection: function(xhr) { var token = $('meta[name="csrf-token"]').attr('content'); if (token) xhr.setRequestHeader('X-CSRF-Token', token); }, // Triggers an event on an element and returns false if the event result is false fire: function(obj, name, data) { var event = $.Event(name); obj.trigger(event, data); return event.result !== false; }, // Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm confirm: function(message) { return confirm(message); }, // Default ajax function, may be overridden with custom function in $.rails.ajax ajax: function(options) { return $.ajax(options); }, // Default way to get an element's href. May be overridden at $.rails.href. href: function(element) { return element.attr('href'); }, // Submits "remote" forms and links with ajax handleRemote: function(element) { var method, url, data, elCrossDomain, crossDomain, withCredentials, dataType, options; if (rails.fire(element, 'ajax:before')) { elCrossDomain = element.data('cross-domain'); crossDomain = elCrossDomain === undefined ? null : elCrossDomain; withCredentials = element.data('with-credentials') || null; dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType); if (element.is('form')) { method = element.attr('method'); url = element.attr('action'); data = element.serializeArray(); // memoized value from clicked submit button var button = element.data('ujs:submit-button'); if (button) { data.push(button); element.data('ujs:submit-button', null); } } else if (element.is(rails.inputChangeSelector)) { method = element.data('method'); url = element.data('url'); data = element.serialize(); if (element.data('params')) data = data + "&" + element.data('params'); } else if (element.is(rails.buttonClickSelector)) { method = element.data('method') || 'get'; url = element.data('url'); data = element.serialize(); if (element.data('params')) data = data + "&" + element.data('params'); } else { method = element.data('method'); url = rails.href(element); data = element.data('params') || null; } options = { type: method || 'GET', data: data, dataType: dataType, // stopping the "ajax:beforeSend" event will cancel the ajax request beforeSend: function(xhr, settings) { if (settings.dataType === undefined) { xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script); } return rails.fire(element, 'ajax:beforeSend', [xhr, settings]); }, success: function(data, status, xhr) { element.trigger('ajax:success', [data, status, xhr]); }, complete: function(xhr, status) { element.trigger('ajax:complete', [xhr, status]); }, error: function(xhr, status, error) { element.trigger('ajax:error', [xhr, status, error]); }, crossDomain: crossDomain }; // There is no withCredentials for IE6-8 when // "Enable native XMLHTTP support" is disabled if (withCredentials) { options.xhrFields = { withCredentials: withCredentials }; } // Only pass url to `ajax` options if not blank if (url) { options.url = url; } var jqxhr = rails.ajax(options); element.trigger('ajax:send', jqxhr); return jqxhr; } else { return false; } }, // Handles "data-method" on links such as: // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a> handleMethod: function(link) { var href = rails.href(link), method = link.data('method'), target = link.attr('target'), csrf_token = $('meta[name=csrf-token]').attr('content'), csrf_param = $('meta[name=csrf-param]').attr('content'), form = $('<form method="post" action="' + href + '"></form>'), metadata_input = '<input name="_method" value="' + method + '" type="hidden" />'; if (csrf_param !== undefined && csrf_token !== undefined) { metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />'; } if (target) { form.attr('target', target); } form.hide().append(metadata_input).appendTo('body'); form.submit(); }, /* Disables form elements: - Caches element value in 'ujs:enable-with' data store - Replaces element text with value of 'data-disable-with' attribute - Sets disabled property to true */ disableFormElements: function(form) { form.find(rails.disableSelector).each(function() { var element = $(this), method = element.is('button') ? 'html' : 'val'; element.data('ujs:enable-with', element[method]()); element[method](element.data('disable-with')); element.prop('disabled', true); }); }, /* Re-enables disabled form elements: - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) - Sets disabled property to false */ enableFormElements: function(form) { form.find(rails.enableSelector).each(function() { var element = $(this), method = element.is('button') ? 'html' : 'val'; if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); element.prop('disabled', false); }); }, /* For 'data-confirm' attribute: - Fires `confirm` event - Shows the confirmation dialog - Fires the `confirm:complete` event Returns `true` if no function stops the chain and user chose yes; `false` otherwise. Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog. Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog. */ allowAction: function(element) { var message = element.data('confirm'), answer = false, callback; if (!message) { return true; } if (rails.fire(element, 'confirm')) { answer = rails.confirm(message); callback = rails.fire(element, 'confirm:complete', [answer]); } return answer && callback; }, // Helper function which checks for blank inputs in a form that match the specified CSS selector blankInputs: function(form, specifiedSelector, nonBlank) { var inputs = $(), input, valueToCheck, selector = specifiedSelector || 'input,textarea', allInputs = form.find(selector); allInputs.each(function() { input = $(this); valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val(); // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey if (!valueToCheck === !nonBlank) { // Don't count unchecked required radio if other radio with same name is checked if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) { return true; // Skip to next input } inputs = inputs.add(input); } }); return inputs.length ? inputs : false; }, // Helper function which checks for non-blank inputs in a form that match the specified CSS selector nonBlankInputs: function(form, specifiedSelector) { return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank }, // Helper function, needed to provide consistent behavior in IE stopEverything: function(e) { $(e.target).trigger('ujs:everythingStopped'); e.stopImmediatePropagation(); return false; }, // replace element's html with the 'data-disable-with' after storing original html // and prevent clicking on it disableElement: function(element) { element.data('ujs:enable-with', element.html()); // store enabled state element.html(element.data('disable-with')); // set to disabled state element.bind('click.railsDisable', function(e) { // prevent further clicking return rails.stopEverything(e); }); }, // restore element to its original state which was disabled by 'disableElement' above enableElement: function(element) { if (element.data('ujs:enable-with') !== undefined) { element.html(element.data('ujs:enable-with')); // set to old enabled state element.removeData('ujs:enable-with'); // clean up cache } element.unbind('click.railsDisable'); // enable element } }; if (rails.fire($document, 'rails:attachBindings')) { $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }}); $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() { rails.enableElement($(this)); }); $document.delegate(rails.linkClickSelector, 'click.rails', function(e) { var link = $(this), method = link.data('method'), data = link.data('params'); if (!rails.allowAction(link)) return rails.stopEverything(e); if (link.is(rails.linkDisableSelector)) rails.disableElement(link); if (link.data('remote') !== undefined) { if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; } var handleRemote = rails.handleRemote(link); // response from rails.handleRemote() will either be false or a deferred object promise. if (handleRemote === false) { rails.enableElement(link); } else { handleRemote.error( function() { rails.enableElement(link); } ); } return false; } else if (link.data('method')) { rails.handleMethod(link); return false; } }); $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) { var button = $(this); if (!rails.allowAction(button)) return rails.stopEverything(e); rails.handleRemote(button); return false; }); $document.delegate(rails.inputChangeSelector, 'change.rails', function(e) { var link = $(this); if (!rails.allowAction(link)) return rails.stopEverything(e); rails.handleRemote(link); return false; }); $document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) { var form = $(this), remote = form.data('remote') !== undefined, blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector), nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector); if (!rails.allowAction(form)) return rails.stopEverything(e); // skip other logic when required values are missing or file upload is present if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) { return rails.stopEverything(e); } if (remote) { if (nonBlankFileInputs) { // slight timeout so that the submit button gets properly serialized // (make it easy for event handler to serialize form without disabled values) setTimeout(function(){ rails.disableFormElements(form); }, 13); var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); // re-enable form elements if event bindings return false (canceling normal form submission) if (!aborted) { setTimeout(function(){ rails.enableFormElements(form); }, 13); } return aborted; } rails.handleRemote(form); return false; } else { // slight timeout so that the submit button gets properly serialized setTimeout(function(){ rails.disableFormElements(form); }, 13); } }); $document.delegate(rails.formInputClickSelector, 'click.rails', function(event) { var button = $(this); if (!rails.allowAction(button)) return rails.stopEverything(event); // register the pressed submit button var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null; button.closest('form').data('ujs:submit-button', data); }); $document.delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) { if (this == event.target) rails.disableFormElements($(this)); }); $document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) { if (this == event.target) rails.enableFormElements($(this)); }); $(function(){ // making sure that all forms have actual up-to-date token(cached forms contain old one) var csrf_token = $('meta[name=csrf-token]').attr('content'); var csrf_param = $('meta[name=csrf-param]').attr('content'); $('form input[name="' + csrf_param + '"]').val(csrf_token); }); } })( jQuery ); /*! * jQuery Migrate - v1.2.1 - 2013-05-08 * https://github.com/jquery/jquery-migrate * Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors; Licensed MIT */ (function( jQuery, window, undefined ) { // See http://bugs.jquery.com/ticket/13335 // "use strict"; var warnedAbout = {}; // List of warnings already given; public read only jQuery.migrateWarnings = []; // Set to true to prevent console output; migrateWarnings still maintained // jQuery.migrateMute = false; // Show a message on the console so devs know we're active if ( !jQuery.migrateMute && window.console && window.console.log ) { window.console.log("JQMIGRATE: Logging is active"); } // Set to false to disable traces that appear with warnings if ( jQuery.migrateTrace === undefined ) { jQuery.migrateTrace = true; } // Forget any warnings we've already given; public jQuery.migrateReset = function() { warnedAbout = {}; jQuery.migrateWarnings.length = 0; }; function migrateWarn( msg) { var console = window.console; if ( !warnedAbout[ msg ] ) { warnedAbout[ msg ] = true; jQuery.migrateWarnings.push( msg ); if ( console && console.warn && !jQuery.migrateMute ) { console.warn( "JQMIGRATE: " + msg ); if ( jQuery.migrateTrace && console.trace ) { console.trace(); } } } } function migrateWarnProp( obj, prop, value, msg ) { if ( Object.defineProperty ) { // On ES5 browsers (non-oldIE), warn if the code tries to get prop; // allow property to be overwritten in case some other plugin wants it try { Object.defineProperty( obj, prop, { configurable: true, enumerable: true, get: function() { migrateWarn( msg ); return value; }, set: function( newValue ) { migrateWarn( msg ); value = newValue; } }); return; } catch( err ) { // IE8 is a dope about Object.defineProperty, can't warn there } } // Non-ES5 (or broken) browser; just set the property jQuery._definePropertyBroken = true; obj[ prop ] = value; } if ( document.compatMode === "BackCompat" ) { // jQuery has never supported or tested Quirks Mode migrateWarn( "jQuery is not compatible with Quirks Mode" ); } var attrFn = jQuery( "<input/>", { size: 1 } ).attr("size") && jQuery.attrFn, oldAttr = jQuery.attr, valueAttrGet = jQuery.attrHooks.value && jQuery.attrHooks.value.get || function() { return null; }, valueAttrSet = jQuery.attrHooks.value && jQuery.attrHooks.value.set || function() { return undefined; }, rnoType = /^(?:input|button)$/i, rnoAttrNodeType = /^[238]$/, rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i, ruseDefault = /^(?:checked|selected)$/i; // jQuery.attrFn migrateWarnProp( jQuery, "attrFn", attrFn || {}, "jQuery.attrFn is deprecated" ); jQuery.attr = function( elem, name, value, pass ) { var lowerName = name.toLowerCase(), nType = elem && elem.nodeType; if ( pass ) { // Since pass is used internally, we only warn for new jQuery // versions where there isn't a pass arg in the formal params if ( oldAttr.length < 4 ) { migrateWarn("jQuery.fn.attr( props, pass ) is deprecated"); } if ( elem && !rnoAttrNodeType.test( nType ) && (attrFn ? name in attrFn : jQuery.isFunction(jQuery.fn[name])) ) { return jQuery( elem )[ name ]( value ); } } // Warn if user tries to set `type`, since it breaks on IE 6/7/8; by checking // for disconnected elements we don't warn on $( "<button>", { type: "button" } ). if ( name === "type" && value !== undefined && rnoType.test( elem.nodeName ) && elem.parentNode ) { migrateWarn("Can't change the 'type' of an input or button in IE 6/7/8"); } // Restore boolHook for boolean property/attribute synchronization if ( !jQuery.attrHooks[ lowerName ] && rboolean.test( lowerName ) ) { jQuery.attrHooks[ lowerName ] = { get: function( elem, name ) { // Align boolean attributes with corresponding properties // Fall back to attribute presence where some booleans are not supported var attrNode, property = jQuery.prop( elem, name ); return property === true || typeof property !== "boolean" && ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ? name.toLowerCase() : undefined; }, set: function( elem, value, name ) { var propName; if ( value === false ) { // Remove boolean attributes when set to false jQuery.removeAttr( elem, name ); } else { // value is true since we know at this point it's type boolean and not false // Set boolean attributes to the same name and set the DOM property propName = jQuery.propFix[ name ] || name; if ( propName in elem ) { // Only set the IDL specifically if it already exists on the element elem[ propName ] = true; } elem.setAttribute( name, name.toLowerCase() ); } return name; } }; // Warn only for attributes that can remain distinct from their properties post-1.9 if ( ruseDefault.test( lowerName ) ) { migrateWarn( "jQuery.fn.attr('" + lowerName + "') may use property instead of attribute" ); } } return oldAttr.call( jQuery, elem, name, value ); }; // attrHooks: value jQuery.attrHooks.value = { get: function( elem, name ) { var nodeName = ( elem.nodeName || "" ).toLowerCase(); if ( nodeName === "button" ) { return valueAttrGet.apply( this, arguments ); } if ( nodeName !== "input" && nodeName !== "option" ) { migrateWarn("jQuery.fn.attr('value') no longer gets properties"); } return name in elem ? elem.value : null; }, set: function( elem, value ) { var nodeName = ( elem.nodeName || "" ).toLowerCase(); if ( nodeName === "button" ) { return valueAttrSet.apply( this, arguments ); } if ( nodeName !== "input" && nodeName !== "option" ) { migrateWarn("jQuery.fn.attr('value', val) no longer sets properties"); } // Does not return so that setAttribute is also used elem.value = value; } }; var matched, browser, oldInit = jQuery.fn.init, oldParseJSON = jQuery.parseJSON, // Note: XSS check is done below after string is trimmed rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/; // $(html) "looks like html" rule change jQuery.fn.init = function( selector, context, rootjQuery ) { var match; if ( selector && typeof selector === "string" && !jQuery.isPlainObject( context ) && (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) { // This is an HTML string according to the "old" rules; is it still? if ( selector.charAt( 0 ) !== "<" ) { migrateWarn("$(html) HTML strings must start with '<' character"); } if ( match[ 3 ] ) { migrateWarn("$(html) HTML text after last tag is ignored"); } // Consistently reject any HTML-like string starting with a hash (#9521) // Note that this may break jQuery 1.6.x code that otherwise would work. if ( match[ 0 ].charAt( 0 ) === "#" ) { migrateWarn("HTML string cannot start with a '#' character"); jQuery.error("JQMIGRATE: Invalid selector string (XSS)"); } // Now process using loose rules; let pre-1.8 play too if ( context && context.context ) { // jQuery object as context; parseHTML expects a DOM object context = context.context; } if ( jQuery.parseHTML ) { return oldInit.call( this, jQuery.parseHTML( match[ 2 ], context, true ), context, rootjQuery ); } } return oldInit.apply( this, arguments ); }; jQuery.fn.init.prototype = jQuery.fn; // Let $.parseJSON(falsy_value) return null jQuery.parseJSON = function( json ) { if ( !json && json !== null ) { migrateWarn("jQuery.parseJSON requires a valid JSON string"); return null; } return oldParseJSON.apply( this, arguments ); }; jQuery.uaMatch = function( ua ) { ua = ua.toLowerCase(); var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+)/.exec( ua ) || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || /(msie) ([\w.]+)/.exec( ua ) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || []; return { browser: match[ 1 ] || "", version: match[ 2 ] || "0" }; }; // Don't clobber any existing jQuery.browser in case it's different if ( !jQuery.browser ) { matched = jQuery.uaMatch( navigator.userAgent ); browser = {}; if ( matched.browser ) { browser[ matched.browser ] = true; browser.version = matched.version; } // Chrome is Webkit, but Webkit is also Safari. if ( browser.chrome ) { browser.webkit = true; } else if ( browser.webkit ) { browser.safari = true; } jQuery.browser = browser; } // Warn if the code tries to get jQuery.browser migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" ); jQuery.sub = function() { function jQuerySub( selector, context ) { return new jQuerySub.fn.init( selector, context ); } jQuery.extend( true, jQuerySub, this ); jQuerySub.superclass = this; jQuerySub.fn = jQuerySub.prototype = this(); jQuerySub.fn.constructor = jQuerySub; jQuerySub.sub = this.sub; jQuerySub.fn.init = function init( selector, context ) { if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) { context = jQuerySub( context ); } return jQuery.fn.init.call( this, selector, context, rootjQuerySub ); }; jQuerySub.fn.init.prototype = jQuerySub.fn; var rootjQuerySub = jQuerySub(document); migrateWarn( "jQuery.sub() is deprecated" ); return jQuerySub; }; // Ensure that $.ajax gets the new parseJSON defined in core.js jQuery.ajaxSetup({ converters: { "text json": jQuery.parseJSON } }); var oldFnData = jQuery.fn.data; jQuery.fn.data = function( name ) { var ret, evt, elem = this[0]; // Handles 1.7 which has this behavior and 1.8 which doesn't if ( elem && name === "events" && arguments.length === 1 ) { ret = jQuery.data( elem, name ); evt = jQuery._data( elem, name ); if ( ( ret === undefined || ret === evt ) && evt !== undefined ) { migrateWarn("Use of jQuery.fn.data('events') is deprecated"); return evt; } } return oldFnData.apply( this, arguments ); }; var rscriptType = /\/(java|ecma)script/i, oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack; jQuery.fn.andSelf = function() { migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()"); return oldSelf.apply( this, arguments ); }; // Since jQuery.clean is used internally on older versions, we only shim if it's missing if ( !jQuery.clean ) { jQuery.clean = function( elems, context, fragment, scripts ) { // Set context per 1.8 logic context = context || document; context = !context.nodeType && context[0] || context; context = context.ownerDocument || context; migrateWarn("jQuery.clean() is deprecated"); var i, elem, handleScript, jsTags, ret = []; jQuery.merge( ret, jQuery.buildFragment( elems, context ).childNodes ); // Complex logic lifted directly from jQuery 1.8 if ( fragment ) { // Special handling of each script element handleScript = function( elem ) { // Check if we consider it executable if ( !elem.type || rscriptType.test( elem.type ) ) { // Detach the script and store it in the scripts array (if provided) or the fragment // Return truthy to indicate that it has been handled return scripts ? scripts.push( elem.parentNode ? elem.parentNode.removeChild( elem ) : elem ) : fragment.appendChild( elem ); } }; for ( i = 0; (elem = ret[i]) != null; i++ ) { // Check if we're done after handling an executable script if ( !( jQuery.nodeName( elem, "script" ) && handleScript( elem ) ) ) { // Append to fragment and handle embedded scripts fragment.appendChild( elem ); if ( typeof elem.getElementsByTagName !== "undefined" ) { // handleScript alters the DOM, so use jQuery.merge to ensure snapshot iteration jsTags = jQuery.grep( jQuery.merge( [], elem.getElementsByTagName("script") ), handleScript ); // Splice the scripts into ret after their former ancestor and advance our index beyond them ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) ); i += jsTags.length; } } } } return ret; }; } var eventAdd = jQuery.event.add, eventRemove = jQuery.event.remove, eventTrigger = jQuery.event.trigger, oldToggle = jQuery.fn.toggle, oldLive = jQuery.fn.live, oldDie = jQuery.fn.die, ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess", rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ), rhoverHack = /(?:^|\s)hover(\.\S+|)\b/, hoverHack = function( events ) { if ( typeof( events ) !== "string" || jQuery.event.special.hover ) { return events; } if ( rhoverHack.test( events ) ) { migrateWarn("'hover' pseudo-event is deprecated, use 'mouseenter mouseleave'"); } return events && events.replace( rhoverHack, "mouseenter$1 mouseleave$1" ); }; // Event props removed in 1.9, put them back if needed; no practical way to warn them if ( jQuery.event.props && jQuery.event.props[ 0 ] !== "attrChange" ) { jQuery.event.props.unshift( "attrChange", "attrName", "relatedNode", "srcElement" ); } // Undocumented jQuery.event.handle was "deprecated" in jQuery 1.7 if ( jQuery.event.dispatch ) { migrateWarnProp( jQuery.event, "handle", jQuery.event.dispatch, "jQuery.event.handle is undocumented and deprecated" ); } // Support for 'hover' pseudo-event and ajax event warnings jQuery.event.add = function( elem, types, handler, data, selector ){ if ( elem !== document && rajaxEvent.test( types ) ) { migrateWarn( "AJAX events should be attached to document: " + types ); } eventAdd.call( this, elem, hoverHack( types || "" ), handler, data, selector ); }; jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){ eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes ); }; jQuery.fn.error = function() { var args = Array.prototype.slice.call( arguments, 0); migrateWarn("jQuery.fn.error() is deprecated"); args.splice( 0, 0, "error" ); if ( arguments.length ) { return this.bind.apply( this, args ); } // error event should not bubble to window, although it does pre-1.7 this.triggerHandler.apply( this, args ); return this; }; jQuery.fn.toggle = function( fn, fn2 ) { // Don't mess with animation or css toggles if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) { return oldToggle.apply( this, arguments ); } migrateWarn("jQuery.fn.toggle(handler, handler...) is deprecated"); // Save reference to arguments for access in closure var args = arguments, guid = fn.guid || jQuery.guid++, i = 0, toggler = function( event ) { // Figure out which function to execute var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i; jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 ); // Make sure that clicks stop event.preventDefault(); // and execute the function return args[ lastToggle ].apply( this, arguments ) || false; }; // link all the functions, so any of them can unbind this click handler toggler.guid = guid; while ( i < args.length ) { args[ i++ ].guid = guid; } return this.click( toggler ); }; jQuery.fn.live = function( types, data, fn ) { migrateWarn("jQuery.fn.live() is deprecated"); if ( oldLive ) { return oldLive.apply( this, arguments ); } jQuery( this.context ).on( types, this.selector, data, fn ); return this; }; jQuery.fn.die = function( types, fn ) { migrateWarn("jQuery.fn.die() is deprecated"); if ( oldDie ) { return oldDie.apply( this, arguments ); } jQuery( this.context ).off( types, this.selector || "**", fn ); return this; }; // Turn global events into document-triggered events jQuery.event.trigger = function( event, data, elem, onlyHandlers ){ if ( !elem && !rajaxEvent.test( event ) ) { migrateWarn( "Global events are undocumented and deprecated" ); } return eventTrigger.call( this, event, data, elem || document, onlyHandlers ); }; jQuery.each( ajaxEvents.split("|"), function( _, name ) { jQuery.event.special[ name ] = { setup: function() { var elem = this; // The document needs no shimming; must be !== for oldIE if ( elem !== document ) { jQuery.event.add( document, name + "." + jQuery.guid, function() { jQuery.event.trigger( name, null, elem, true ); }); jQuery._data( this, name, jQuery.guid++ ); } return false; }, teardown: function() { if ( this !== document ) { jQuery.event.remove( document, name + "." + jQuery._data( this, name ) ); } return false; } }; } ); })( jQuery, window ); /*! * Mercury Editor is a CoffeeScript and jQuery based WYSIWYG editor. Documentation and other useful information can be * found at https://github.com/jejacks0n/mercury * * Minimum jQuery requirements are 1.7 * * You can include the Rails jQuery ujs script here to get some nicer behaviors in modals, panels and lightviews when * using :remote => true within the contents rendered in them. * require jquery_ujs * * Add any requires for the support libraries that integrate nicely with Mercury Editor. * require mercury/support/history * * Require Mercury Editor itself. * * Require any localizations you wish to support * Example: es.locale, or fr.locale -- regional dialects are in each language file so never en_US for instance. * Make sure you enable the localization feature in the configuration. * require mercury/locales/swedish_chef.locale * * Add all requires for plugins that extend or change the behavior of Mercury Editor. * require mercury/plugins/save_as_xml/plugin.js * * Require any files you want to use that either extend, or change the default Mercury behavior. * require mercury_overrides */ window.Mercury = { // # Mercury Configuration config: { // ## Toolbars // // This is where you can customize the toolbars by adding or removing buttons, or changing them and their // behaviors. Any top level object put here will create a new toolbar. Buttons are simply nested inside the // toolbars, along with button groups. // // Some toolbars are custom (the snippets toolbar for instance), and to denote that use _custom: true. You can then // build the toolbar yourself with it's own behavior. // // Buttons can be grouped, and a button group is simply a way to wrap buttons for styling -- they can also handle // enabling or disabling all the buttons within it by using a context. The table button group is a good example of // this. // // It's important to note that each of the button names (keys), in each toolbar object must be unique, regardless of // if it's in a button group, or nested, etc. This is because styling is applied to them by name, and because their // name is used in the event that's fired when you click on them. // // Button format: `[label, description, {type: action, type: action, etc}]` // // ### The available button types are: // // - toggle: toggles on or off when clicked, otherwise behaves like a button // - modal: opens a modal window, expects the action to be one of: // 1. a string url // 2. a function that returns a string url // - lightview: opens a lightview window (like modal, but different UI), expects the action to be one of: // 1. a string url // 2. a function that returns a string url // - panel: opens a panel dialog, expects the action to be one of: // 1. a string url // 2. a function that returns a string url // - palette: opens a palette window, expects the action to be one of: // 1. a string url // 2. a function that returns a string url // - select: opens a pulldown style window, expects the action to be one of: // 1. a string url // 2. a function that returns a string url // - context: calls a callback function, expects the action to be: // 1. a function that returns a boolean to highlight the button // note: if a function isn't provided, the key will be passed to the contextHandler, in which case a default // context will be used (for more info read the Contexts section below) // - mode: toggle a given mode in the editor, expects the action to be: // 1. a string, denoting the name of the mode // note: it's assumed that when a specific mode is turned on, all other modes will be turned off, which happens // automatically, thus putting the editor into a specific "state" // - regions: allows buttons to be enabled/disabled based on what region type has focus, expects: // 1. an array of region types (eg. ['full', 'markdown']) // - preload: allows some dialog views to be loaded when the button is created instead of on first open, expects: // 1. a boolean true / false // note: this is only used by panels, selects, and palettes // // Separators are any "button" that's not an array, and are expected to be a string. You can use two different // separator styles: line ('-'), and spacer (' '). // // ### Adding Contexts // // Contexts are used callback functions used for highlighting and disabling/enabling buttons and buttongroups. When // the cursor enters an element within an html region for instance we want to disable or highlight buttons based on // the properties of the given node. You can see examples of contexts in, and add your own to: // `Mercury.Toolbar.Button.contexts` and `Mercury.Toolbar.ButtonGroup.contexts` toolbars: { primary: { save: ['Save', 'Save this page'], preview: ['Preview', 'Preview this page', { toggle: true, mode: true }], sep1: ' ', undoredo: { undo: ['Undo', 'Undo your last action'], redo: ['Redo', 'Redo your last action'], sep: ' ' }, insertLink: ['Link', 'Insert Link', { modal: '/mercury/modals/link.html', regions: ['full', 'markdown'] }], insertMedia: ['Media', 'Insert Media (images and videos)', { modal: '/mercury/modals/media.html', regions: ['full', 'markdown'] }], insertTable: ['Table', 'Insert Table', { modal: '/mercury/modals/table.html', regions: ['full', 'markdown'] }], insertCharacter: ['Character', 'Special Characters', { modal: '/mercury/modals/character.html', regions: ['full', 'markdown'] }], snippetPanel: ['Snippet', 'Snippet Panel', { panel: '/mercury/panels/snippets.html' }], sep2: ' ', historyPanel: ['History', 'Page Version History', { panel: '/mercury/panels/history.html' }], sep3: ' ', notesPanel: ['Notes', 'Page Notes', { panel: '/mercury/panels/notes.html' }] }, editable: { _regions: ['full', 'markdown'], predefined: { style: ['Style', null, { select: '/mercury/selects/style.html', preload: true }], sep1: ' ', formatblock: ['Block Format', null, { select: '/mercury/selects/formatblock.html', preload: true }], sep2: '-' }, colors: { backColor: ['Background Color', null, { palette: '/mercury/palettes/backcolor.html', context: true, preload: true, regions: ['full'] }], sep1: ' ', foreColor: ['Text Color', null, { palette: '/mercury/palettes/forecolor.html', context: true, preload: true, regions: ['full'] }], sep2: '-' }, decoration: { bold: ['Bold', null, { context: true }], italic: ['Italicize', null, { context: true }], overline: ['Overline', null, { context: true, regions: ['full'] }], strikethrough: ['Strikethrough', null, { context: true, regions: ['full'] }], underline: ['Underline', null, { context: true, regions: ['full'] }], sep: '-' }, script: { subscript: ['Subscript', null, { context: true }], superscript: ['Superscript', null, { context: true }], sep: '-' }, justify: { justifyLeft: ['Align Left', null, { context: true, regions: ['full'] }], justifyCenter: ['Center', null, { context: true, regions: ['full'] }], justifyRight: ['Align Right', null, { context: true, regions: ['full'] }], justifyFull: ['Justify Full', null, { context: true, regions: ['full'] }], sep: '-' }, list: { insertUnorderedList: ['Unordered List', null, { context: true }], insertOrderedList: ['Numbered List', null, { context: true }], sep: '-' }, indent: { outdent: ['Decrease Indentation'], indent: ['Increase Indentation'], sep: '-' }, table: { _context: true, insertRowBefore: ['Insert Table Row', 'Insert a table row before the cursor', { regions: ['full'] }], insertRowAfter: ['Insert Table Row', 'Insert a table row after the cursor', { regions: ['full'] }], deleteRow: ['Delete Table Row', 'Delete this table row', { regions: ['full'] }], insertColumnBefore: ['Insert Table Column', 'Insert a table column before the cursor', { regions: ['full'] }], insertColumnAfter: ['Insert Table Column', 'Insert a table column after the cursor', { regions: ['full'] }], deleteColumn: ['Delete Table Column', 'Delete this table column', { regions: ['full'] }], sep1: ' ', increaseColspan: ['Increase Cell Columns', 'Increase the cells colspan'], decreaseColspan: ['Decrease Cell Columns', 'Decrease the cells colspan and add a new cell'], increaseRowspan: ['Increase Cell Rows', 'Increase the cells rowspan'], decreaseRowspan: ['Decrease Cell Rows', 'Decrease the cells rowspan and add a new cell'], sep2: '-' }, rules: { horizontalRule: ['Horizontal Rule', 'Insert a horizontal rule'], sep1: '-' }, formatting: { removeFormatting: ['Remove Formatting', 'Remove formatting for the selection', { regions: ['full'] }], sep2: ' ' }, editors: { htmlEditor: ['Edit HTML', 'Edit the HTML content', { regions: ['full'] }] } }, snippets: { _custom: true, actions: { editSnippet: ['Edit Snippet Settings'], sep1: ' ', removeSnippet: ['Remove Snippet'] } } }, // ## Region Options // // You can customize some aspects of how regions are found, identified, and saved. // // attribute: Mercury identifies editable regions by a data-mercury attribute. This attribute has to be added in // your HTML in advance, and is the only real code/naming exposed in the implementation of Mercury. To allow this // to be as configurable as possible, you can set the name of this attribute. If you change this, you should adjust // the injected styles as well. // // identifier: This is used as a unique identifier for any given region (and thus should be unique to the page). // By default this is the id attribute but can be changed to a data attribute should you want to use something // custom instead. // // dataAttributes: The dataAttributes is an array of data attributes that will be serialized and returned to the // server upon saving. These attributes, when applied to a Mercury region element, will be automatically serialized // and submitted with the AJAX request sent when a page is saved. These are expected to be HTML5 data attributes, // and 'data-' will automatically be prepended to each item in this directive. (ex. ['scope', 'version']) // // determineType: This function is called after checking the data-type attribute for the correct field type. Use // it if you want to dynamically set the type based on inspection of the region. regions: { attribute: 'data-mercury', identifier: 'id', dataAttributes: [] // determineType: function(region){}, }, // ## Snippet Options / Preview // // When a user drags a snippet onto the page they'll be prompted to enter options for the given snippet. The server // is expected to respond with a form. Once the user submits this form, an Ajax request is sent to the server with // the options provided; this preview request is expected to respond with the rendered markup for the snippet. // // method: The HTTP method used when submitting both the options and the preview. We use POST by default because a // snippet options form may contain large text inputs and we don't want that to be truncated when sent to the // server. // // optionsUrl: The url that the options form will be loaded from. // // previewUrl: The url that the options will be submitted to, and will return the rendered snippet markup. // // **Note:** `:name` will be replaced with the snippet name in the urls (eg. /mercury/snippets/example/options.html) snippets: { method: 'POST', optionsUrl: '/mercury/snippets/:name/options.html', previewUrl: '/mercury/snippets/:name/preview.html' }, // ## Image Uploading // // If you drag images from your desktop into regions that support it, it will be uploaded to the server and inserted // into the region. You can disable or enable this feature, the accepted mime-types, file size restrictions, and // other things related to uploading. // // **Note:** Image uploading is only supported in some region types, and some browsers. // // enabled: You can set this to true, or false if you want to disable the feature entirely. // // allowedMimeTypes: You can restrict the types of files that can be uploaded by providing a list of allowed mime // types. // // maxFileSize: You can restrict large files by setting the maxFileSize (in bytes). // // inputName: When uploading, a form is generated and submitted to the server via Ajax. If your server would prefer // a different name for how the image comes through, you can change the inputName. // // url: The url that the image upload will be submitted to. // // handler: You can use false to let Mercury handle it for you, or you can provide a handler function that can // modify the response from the server. This can be useful if your server doesn't respond the way Mercury expects. // The handler function should take the response from the server and return an object that matches: // `{image: {url: '[your provided url]'}` uploading: { enabled: true, allowedMimeTypes: ['image/jpeg', 'image/gif', 'image/png'], maxFileSize: 1235242880, inputName: 'image[image]', url: '/mercury/images', handler: false }, // ## Localization / I18n // // Include the .locale files you want to support when loading Mercury. The files are always named by the language, // and not the regional dialect (eg. en.locale.js) because the regional dialects are nested within the primary // locale files. // // The client locale will be used first, and if no proper locale file is found for their language then the fallback // preferredLocale configuration will be used. If one isn't provided, and the client locale isn't included, the // strings will remain untranslated. // // enabled: Set to false to disable, true to enable. // // preferredLocale: If a client doesn't support the locales you've included, this is used as a fallback. localization: { enabled: false, preferredLocale: 'swedish_chef-BORK' }, // ## Behaviors // // Behaviors are used to change the default behaviors of a given region type when a given button is clicked. For // example, you may prefer to add HR tags using an HR wrapped within a div with a classname (for styling). You // can add your own complex behaviors here and they'll be shared across all regions. // // If you want to add behaviors to specific region types, you can mix them into the actions property of any region // type. // // Mercury.Regions.Full.actions.htmlEditor = function() {} // // You can see how the behavior matches up directly with the button names. It's also important to note that the // callback functions are executed within the scope of the given region, so you have access to all it's methods. behaviors: { //foreColor: function(selection, options) { selection.wrap('<span style="color:' + options.value.toHex() + '">', true) }, htmlEditor: function() { Mercury.modal('/mercury/modals/htmleditor.html', { title: 'HTML Editor', fullHeight: true, handler: 'htmlEditor' }); } }, // ## Global Behaviors // // Global behaviors are much like behaviors, but are more "global". Things like save, exit, etc. can be included // here. They'll only be called once, and execute within the scope of whatever editor is instantiated (eg. // PageEditor). // // An example of changing how saving works: // // save: function() { // var data = top.JSON.stringify(this.serialize(), null, ' '); // var content = '<textarea style="width:500px;height:200px" wrap="off">' + data + '</textarea>'; // Mercury.modal(null, {title: 'Saving', closeButton: true, content: content}) // } // // This is a nice way to add functionality, when the behaviors aren't region specific. These can be triggered by a // button, or manually with `Mercury.trigger('action', {action: 'barrelRoll'})` globalBehaviors: { exit: function() { window.location.href = this.iframeSrc() }, barrelRoll: function() { $('body').css({webkitTransform: 'rotate(360deg)'}) } }, // ## Ajax and CSRF Headers // // Some server frameworks require that you provide a specific header for Ajax requests. The values for these CSRF // tokens are typically stored in the rendered DOM. By default, Mercury will look for the Rails specific meta tag, // and provide the X-CSRF-Token header on Ajax requests, but you can modify this configuration if the system you're // using doesn't follow the same standard. csrfSelector: 'meta[name="csrf-token"]', csrfHeader: 'X-CSRF-Token', // ## Editor URLs // // When loading a given page, you may want to tweak this regex. It's to allow the url to differ from the page // you're editing, and the url at which you access it. editorUrlRegEx: /([http|https]:\/\/.[^\/]*)\/editor\/?(.*)/i, // ## Hijacking Links & Forms // // Mercury will hijack links and forms that don't have a target set, or the target is set to _self and will set it // to _parent. This is because the target must be set properly for Mercury to not get in the way of some // functionality, like proper page loads on form submissions etc. Mercury doesn't do this to links or forms that // are within editable regions because it doesn't want to impact the html that's saved. With that being explained, // you can add classes to links or forms that you don't want this behavior added to. Let's say you have links that // open a lightbox style window, and you don't want the targets of these to be set to _parent. You can add classes // to this array, and they will be ignored when the hijacking is applied. nonHijackableClasses: [], // ## Pasting & Sanitizing // // When pasting content into Mercury it may sometimes contain HTML tags and attributes. This markup is used to // style the content and makes the pasted content look (and behave) the same as the original content. This can be a // desired feature or an annoyance, so you can enable various sanitizing methods to clean the content when it's // pasted. // // sanitize: Can be any of the following: // - false: no sanitizing is done, the content is pasted the exact same as it was copied by the user // - 'whitelist': content is cleaned using the settings specified in the tag white list (described below) // - 'text': all html is stripped before pasting, leaving only the raw text // // whitelist: The white list allows you to specify tags and attributes that are allowed when pasting content. Each // item in this object should contain the allowed tag, and an array of attributes that are allowed on that tag. If // the allowed attributes array is empty, all attributes will be removed. If a tag is not present in this list, it // will be removed, but without removing any of the text or tags inside it. // // **Note:** Content is *always* sanitized if looks like it's from MS Word or similar editors regardless of this // configuration. pasting: { sanitize: 'whitelist', whitelist: { h1: [], h2: [], h3: [], h4: [], h5: [], h6: [], table: [], thead: [], tbody: [], tfoot: [], tr: [], th: ['colspan', 'rowspan'], td: ['colspan', 'rowspan'], div: ['class'], span: ['class'], ul: [], ol: [], li: [], b: [], strong: [], i: [], em: [], u: [], strike: [], br: [], p: [], hr: [], a: ['href', 'target', 'title', 'name'], img: ['src', 'title', 'alt'] } }, // ## Injected Styles // // Mercury tries to stay as much out of your code as possible, but because regions appear within your document we // need to include a few styles to indicate regions, as well as the different states of them (eg. focused). These // styles are injected into your document, and as simple as they might be, you may want to change them. injectedStyles: '' + '[data-mercury] { min-height: 10px; outline: 1px dotted #09F } ' + '[data-mercury]:focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }' + '[data-mercury].focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }' + '[data-mercury]:after { content: "."; display: block; visibility: hidden; clear: both; height: 0; overflow: hidden; }' + '[data-mercury] table { border: 1px dotted red; min-width: 6px; }' + '[data-mercury] th { border: 1px dotted red; min-width: 6px; }' + '[data-mercury] td { border: 1px dotted red; min-width: 6px; }' + '[data-mercury] .mercury-textarea { border: 0; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; resize: none; }' + '[data-mercury] .mercury-textarea:focus { outline: none; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; }' }, // ## Silent Mode // // Turning silent mode on will disable asking about unsaved changes before leaving the page. silent: false, // ## Debug Mode // // Turning debug mode on will log events and other various things (using console.debug if available). debug: false }; // $(window).on('mercury:ready', function() { // var link = $('.admin_edit_link'); // if(Mercury.saveUrl !== null) { // Mercury.saveUrl = link.attr('data-save-url'); // } // link.hide(Mercury.saveUrl); // }); // $(window).on('mercury:saved', function() { // window.location = window.location.href.replace(/\/editor\//i, '/'); // }); $(window).on('mercury:ready', function() { var link = $('.admin_edit_link'); if(Mercury.saveUrl !== null) { Mercury.saveUrl = link.attr('data-save-url'); } link.hide(Mercury.saveUrl); }); $(window).on('mercury:saved', function() { window.location = window.location.href.replace(/\/editor\//i, '/'); }); /*! * jQuery UI 1.8.13 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * * http://docs.jquery.com/UI */ (function(c,j){function k(a,b){var d=a.nodeName.toLowerCase();if("area"===d){b=a.parentNode;d=b.name;if(!a.href||!d||b.nodeName.toLowerCase()!=="map")return false;a=c("img[usemap=#"+d+"]")[0];return!!a&&l(a)}return(/input|select|textarea|button|object/.test(d)?!a.disabled:"a"==d?a.href||b:b)&&l(a)}function l(a){return!c(a).parents().andSelf().filter(function(){return c.curCSS(this,"visibility")==="hidden"||c.expr.filters.hidden(this)}).length}c.ui=c.ui||{};if(!c.ui.version){c.extend(c.ui,{version:"1.8.13", keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});c.fn.extend({_focus:c.fn.focus,focus:function(a,b){return typeof a==="number"?this.each(function(){var d=this;setTimeout(function(){c(d).focus(); b&&b.call(d)},a)}):this._focus.apply(this,arguments)},scrollParent:function(){var a;a=c.browser.msie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(c.curCSS(this,"position",1))&&/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this, "overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0);return/fixed/.test(this.css("position"))||!a.length?c(document):a},zIndex:function(a){if(a!==j)return this.css("zIndex",a);if(this.length){a=c(this[0]);for(var b;a.length&&a[0]!==document;){b=a.css("position");if(b==="absolute"||b==="relative"||b==="fixed"){b=parseInt(a.css("zIndex"),10);if(!isNaN(b)&&b!==0)return b}a=a.parent()}}return 0},disableSelection:function(){return this.bind((c.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection", function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});c.each(["Width","Height"],function(a,b){function d(f,g,m,n){c.each(e,function(){g-=parseFloat(c.curCSS(f,"padding"+this,true))||0;if(m)g-=parseFloat(c.curCSS(f,"border"+this+"Width",true))||0;if(n)g-=parseFloat(c.curCSS(f,"margin"+this,true))||0});return g}var e=b==="Width"?["Left","Right"]:["Top","Bottom"],h=b.toLowerCase(),i={innerWidth:c.fn.innerWidth,innerHeight:c.fn.innerHeight,outerWidth:c.fn.outerWidth, outerHeight:c.fn.outerHeight};c.fn["inner"+b]=function(f){if(f===j)return i["inner"+b].call(this);return this.each(function(){c(this).css(h,d(this,f)+"px")})};c.fn["outer"+b]=function(f,g){if(typeof f!=="number")return i["outer"+b].call(this,f);return this.each(function(){c(this).css(h,d(this,f,true,g)+"px")})}});c.extend(c.expr[":"],{data:function(a,b,d){return!!c.data(a,d[3])},focusable:function(a){return k(a,!isNaN(c.attr(a,"tabindex")))},tabbable:function(a){var b=c.attr(a,"tabindex"),d=isNaN(b); return(d||b>=0)&&k(a,!d)}});c(function(){var a=document.body,b=a.appendChild(b=document.createElement("div"));c.extend(b.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});c.support.minHeight=b.offsetHeight===100;c.support.selectstart="onselectstart"in b;a.removeChild(b).style.display="none"});c.extend(c.ui,{plugin:{add:function(a,b,d){a=c.ui[a].prototype;for(var e in d){a.plugins[e]=a.plugins[e]||[];a.plugins[e].push([b,d[e]])}},call:function(a,b,d){if((b=a.plugins[b])&&a.element[0].parentNode)for(var e= 0;e<b.length;e++)a.options[b[e][0]]&&b[e][1].apply(a.element,d)}},contains:function(a,b){return document.compareDocumentPosition?a.compareDocumentPosition(b)&16:a!==b&&a.contains(b)},hasScroll:function(a,b){if(c(a).css("overflow")==="hidden")return false;b=b&&b==="left"?"scrollLeft":"scrollTop";var d=false;if(a[b]>0)return true;a[b]=1;d=a[b]>0;a[b]=0;return d},isOverAxis:function(a,b,d){return a>b&&a<b+d},isOver:function(a,b,d,e,h,i){return c.ui.isOverAxis(a,d,h)&&c.ui.isOverAxis(b,e,i)}})}})(jQuery); ;/*! * jQuery UI Widget 1.8.13 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * * http://docs.jquery.com/UI/Widget */ (function(b,j){if(b.cleanData){var k=b.cleanData;b.cleanData=function(a){for(var c=0,d;(d=a[c])!=null;c++)b(d).triggerHandler("remove");k(a)}}else{var l=b.fn.remove;b.fn.remove=function(a,c){return this.each(function(){if(!c)if(!a||b.filter(a,[this]).length)b("*",this).add([this]).each(function(){b(this).triggerHandler("remove")});return l.call(b(this),a,c)})}}b.widget=function(a,c,d){var e=a.split(".")[0],f;a=a.split(".")[1];f=e+"-"+a;if(!d){d=c;c=b.Widget}b.expr[":"][f]=function(h){return!!b.data(h, a)};b[e]=b[e]||{};b[e][a]=function(h,g){arguments.length&&this._createWidget(h,g)};c=new c;c.options=b.extend(true,{},c.options);b[e][a].prototype=b.extend(true,c,{namespace:e,widgetName:a,widgetEventPrefix:b[e][a].prototype.widgetEventPrefix||a,widgetBaseClass:f},d);b.widget.bridge(a,b[e][a])};b.widget.bridge=function(a,c){b.fn[a]=function(d){var e=typeof d==="string",f=Array.prototype.slice.call(arguments,1),h=this;d=!e&&f.length?b.extend.apply(null,[true,d].concat(f)):d;if(e&&d.charAt(0)==="_")return h; e?this.each(function(){var g=b.data(this,a),i=g&&b.isFunction(g[d])?g[d].apply(g,f):g;if(i!==g&&i!==j){h=i;return false}}):this.each(function(){var g=b.data(this,a);g?g.option(d||{})._init():b.data(this,a,new c(d,this))});return h}};b.Widget=function(a,c){arguments.length&&this._createWidget(a,c)};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(a,c){b.data(c,this.widgetName,this);this.element=b(c);this.options=b.extend(true,{},this.options, this._getCreateOptions(),a);var d=this;this.element.bind("remove."+this.widgetName,function(){d.destroy()});this._create();this._trigger("create");this._init()},_getCreateOptions:function(){return b.metadata&&b.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")}, widget:function(){return this.element},option:function(a,c){var d=a;if(arguments.length===0)return b.extend({},this.options);if(typeof a==="string"){if(c===j)return this.options[a];d={};d[a]=c}this._setOptions(d);return this},_setOptions:function(a){var c=this;b.each(a,function(d,e){c._setOption(d,e)});return this},_setOption:function(a,c){this.options[a]=c;if(a==="disabled")this.widget()[c?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",c);return this}, enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(a,c,d){var e=this.options[a];c=b.Event(c);c.type=(a===this.widgetEventPrefix?a:this.widgetEventPrefix+a).toLowerCase();d=d||{};if(c.originalEvent){a=b.event.props.length;for(var f;a;){f=b.event.props[--a];c[f]=c.originalEvent[f]}}this.element.trigger(c,d);return!(b.isFunction(e)&&e.call(this.element[0],c,d)===false||c.isDefaultPrevented())}}})(jQuery); ; /*! * jQuery UI Mouse 1.8.13 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * * http://docs.jquery.com/UI/Mouse * * Depends: * jquery.ui.widget.js */ (function( $, undefined ) { var mouseHandled = false; $(document).mousedown(function(e) { mouseHandled = false; }); $.widget("ui.mouse", { options: { cancel: ':input,option', distance: 1, delay: 0 }, _mouseInit: function() { var self = this; this.element .bind('mousedown.'+this.widgetName, function(event) { return self._mouseDown(event); }) .bind('click.'+this.widgetName, function(event) { if (true === $.data(event.target, self.widgetName + '.preventClickEvent')) { $.removeData(event.target, self.widgetName + '.preventClickEvent'); event.stopImmediatePropagation(); return false; } }); this.started = false; }, // TODO: make sure destroying one instance of mouse doesn't mess with // other instances of mouse _mouseDestroy: function() { this.element.unbind('.'+this.widgetName); }, _mouseDown: function(event) { // don't let more than one widget handle mouseStart $(this.document || document).mousedown(function(e) { mouseHandled = false; }); if(mouseHandled) {return}; // we may have missed mouseup (out of window) (this._mouseStarted && this._mouseUp(event)); this._mouseDownEvent = event; var self = this, btnIsLeft = (event.which == 1), elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false); if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) { return true; } this.mouseDelayMet = !this.options.delay; if (!this.mouseDelayMet) { this._mouseDelayTimer = setTimeout(function() { self.mouseDelayMet = true; }, this.options.delay); } if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { this._mouseStarted = (this._mouseStart(event) !== false); if (!this._mouseStarted) { event.preventDefault(); return true; } } // Click event may never have fired (Gecko & Opera) if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) { $.removeData(event.target, this.widgetName + '.preventClickEvent'); } // these delegates are required to keep context this._mouseMoveDelegate = function(event) { return self._mouseMove(event); }; this._mouseUpDelegate = function(event) { return self._mouseUp(event); }; $(this.document || document) .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate) .bind('mouseup.'+this.widgetName, this._mouseUpDelegate); event.preventDefault(); mouseHandled = true; return true; }, _mouseMove: function(event) { // IE mouseup check - mouseup happened when mouse was out of window if ($.browser.msie && !((this.document || document).documentMode >= 9) && !event.button) { return this._mouseUp(event); } if (this._mouseStarted) { this._mouseDrag(event); return event.preventDefault(); } if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { this._mouseStarted = (this._mouseStart(this._mouseDownEvent, event) !== false); (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event)); } return !this._mouseStarted; }, _mouseUp: function(event) { $(this.document || document) .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate) .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate); if (this._mouseStarted) { this._mouseStarted = false; if (event.target == this._mouseDownEvent.target) { $.data(event.target, this.widgetName + '.preventClickEvent', true); } this._mouseStop(event); } return false; }, _mouseDistanceMet: function(event) { return (Math.max( Math.abs(this._mouseDownEvent.pageX - event.pageX), Math.abs(this._mouseDownEvent.pageY - event.pageY) ) >= this.options.distance ); }, _mouseDelayMet: function(event) { return this.mouseDelayMet; }, // These are placeholder methods, to be overriden by extending plugin _mouseStart: function(event) {}, _mouseDrag: function(event) {}, _mouseStop: function(event) {}, _mouseCapture: function(event) { return true; } }); })(jQuery); /* * jQuery UI Draggable 1.8.13 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * * http://docs.jquery.com/UI/Draggables * * Depends: * jquery.ui.core.js * jquery.ui.mouse.js * jquery.ui.widget.js */ (function(d){d.widget("ui.draggable",d.ui.mouse,{widgetEventPrefix:"drag",options:{addClasses:true,appendTo:"parent",axis:false,connectToSortable:false,containment:false,cursor:"auto",cursorAt:false,grid:false,handle:false,helper:"original",iframeFix:false,opacity:false,refreshPositions:false,revert:false,revertDuration:500,scope:"default",scroll:true,scrollSensitivity:20,scrollSpeed:20,snap:false,snapMode:"both",snapTolerance:20,stack:false,zIndex:false},_create:function(){if(this.options.helper== "original"&&!/^(?:r|a|f)/.test(this.element.css("position")))this.element[0].style.position="relative";this.options.addClasses&&this.element.addClass("ui-draggable");this.options.disabled&&this.element.addClass("ui-draggable-disabled");this._mouseInit()},destroy:function(){if(this.element.data("draggable")){this.element.removeData("draggable").unbind(".draggable").removeClass("ui-draggable ui-draggable-dragging ui-draggable-disabled");this._mouseDestroy();return this}},_mouseCapture:function(a){var b= this.options;if(this.helper||b.disabled||d(a.target).is(".ui-resizable-handle"))return false;this.handle=this._getHandle(a);if(!this.handle)return false;d(b.iframeFix===true?"iframe":b.iframeFix).each(function(){d('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>').css({width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1E3}).css(d(this).offset()).appendTo("body")});return true},_mouseStart:function(a){var b=this.options;this.helper= this._createHelper(a);this._cacheHelperProportions();if(d.ui.ddmanager)d.ui.ddmanager.current=this;this._cacheMargins();this.cssPosition=this.helper.css("position");this.scrollParent=this.helper.scrollParent();this.offset=this.positionAbs=this.element.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};d.extend(this.offset,{click:{left:a.pageX-this.offset.left,top:a.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}); this.originalPosition=this.position=this._generatePosition(a);this.originalPageX=a.pageX;this.originalPageY=a.pageY;b.cursorAt&&this._adjustOffsetFromHelper(b.cursorAt);b.containment&&this._setContainment();if(this._trigger("start",a)===false){this._clear();return false}this._cacheHelperProportions();d.ui.ddmanager&&!b.dropBehaviour&&d.ui.ddmanager.prepareOffsets(this,a);this.helper.addClass("ui-draggable-dragging");this._mouseDrag(a,true);return true},_mouseDrag:function(a,b){this.position=this._generatePosition(a); this.positionAbs=this._convertPositionTo("absolute");if(!b){b=this._uiHash();if(this._trigger("drag",a,b)===false){this._mouseUp({});return false}this.position=b.position}if(!this.options.axis||this.options.axis!="y")this.helper[0].style.left=this.position.left+"px";if(!this.options.axis||this.options.axis!="x")this.helper[0].style.top=this.position.top+"px";d.ui.ddmanager&&d.ui.ddmanager.drag(this,a);return false},_mouseStop:function(a){var b=false;if(d.ui.ddmanager&&!this.options.dropBehaviour)b= d.ui.ddmanager.drop(this,a);if(this.dropped){b=this.dropped;this.dropped=false}if((!this.element[0]||!this.element[0].parentNode)&&this.options.helper=="original")return false;if(this.options.revert=="invalid"&&!b||this.options.revert=="valid"&&b||this.options.revert===true||d.isFunction(this.options.revert)&&this.options.revert.call(this.element,b)){var c=this;d(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){c._trigger("stop",a)!==false&&c._clear()})}else this._trigger("stop", a)!==false&&this._clear();return false},_mouseUp:function(a){this.options.iframeFix===true&&d("div.ui-draggable-iframeFix").each(function(){this.parentNode.removeChild(this)});return d.ui.mouse.prototype._mouseUp.call(this,a)},cancel:function(){this.helper.is(".ui-draggable-dragging")?this._mouseUp({}):this._clear();return this},_getHandle:function(a){var b=!this.options.handle||!d(this.options.handle,this.element).length?true:false;d(this.options.handle,this.element).find("*").andSelf().each(function(){if(this== a.target)b=true});return b},_createHelper:function(a){var b=this.options;a=d.isFunction(b.helper)?d(b.helper.apply(this.element[0],[a])):b.helper=="clone"?this.element.clone().removeAttr("id"):this.element;a.parents("body").length||a.appendTo(b.appendTo=="parent"?this.element[0].parentNode:b.appendTo);a[0]!=this.element[0]&&!/(fixed|absolute)/.test(a.css("position"))&&a.css("position","absolute");return a},_adjustOffsetFromHelper:function(a){if(typeof a=="string")a=a.split(" ");if(d.isArray(a))a= {left:+a[0],top:+a[1]||0};if("left"in a)this.offset.click.left=a.left+this.margins.left;if("right"in a)this.offset.click.left=this.helperProportions.width-a.right+this.margins.left;if("top"in a)this.offset.click.top=a.top+this.margins.top;if("bottom"in a)this.offset.click.top=this.helperProportions.height-a.bottom+this.margins.top},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var a=this.offsetParent.offset();if(this.cssPosition=="absolute"&&this.scrollParent[0]!=document&& d.ui.contains(this.scrollParent[0],this.offsetParent[0])){a.left+=this.scrollParent.scrollLeft();a.top+=this.scrollParent.scrollTop()}if(this.offsetParent[0]==document.body||this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()=="html"&&d.browser.msie)a={top:0,left:0};return{top:a.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:a.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition=="relative"){var a= this.element.position();return{top:a.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:a.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}else return{top:0,left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.element.css("marginLeft"),10)||0,top:parseInt(this.element.css("marginTop"),10)||0,right:parseInt(this.element.css("marginRight"),10)||0,bottom:parseInt(this.element.css("marginBottom"),10)||0}},_cacheHelperProportions:function(){this.helperProportions= {width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var a=this.options;if(a.containment=="parent")a.containment=this.helper[0].parentNode;if(a.containment=="document"||a.containment=="window")this.containment=[(a.containment=="document"?0:d(window).scrollLeft())-this.offset.relative.left-this.offset.parent.left,(a.containment=="document"?0:d(window).scrollTop())-this.offset.relative.top-this.offset.parent.top,(a.containment=="document"?0:d(window).scrollLeft())+ d(a.containment=="document"?document:window).width()-this.helperProportions.width-this.margins.left,(a.containment=="document"?0:d(window).scrollTop())+(d(a.containment=="document"?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top];if(!/^(document|window|parent)$/.test(a.containment)&&a.containment.constructor!=Array){a=d(a.containment);var b=a[0];if(b){a.offset();var c=d(b).css("overflow")!="hidden";this.containment=[(parseInt(d(b).css("borderLeftWidth"), 10)||0)+(parseInt(d(b).css("paddingLeft"),10)||0),(parseInt(d(b).css("borderTopWidth"),10)||0)+(parseInt(d(b).css("paddingTop"),10)||0),(c?Math.max(b.scrollWidth,b.offsetWidth):b.offsetWidth)-(parseInt(d(b).css("borderLeftWidth"),10)||0)-(parseInt(d(b).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left-this.margins.right,(c?Math.max(b.scrollHeight,b.offsetHeight):b.offsetHeight)-(parseInt(d(b).css("borderTopWidth"),10)||0)-(parseInt(d(b).css("paddingBottom"),10)||0)-this.helperProportions.height- this.margins.top-this.margins.bottom];this.relative_container=a}}else if(a.containment.constructor==Array)this.containment=a.containment},_convertPositionTo:function(a,b){if(!b)b=this.position;a=a=="absolute"?1:-1;var c=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,f=/(html|body)/i.test(c[0].tagName);return{top:b.top+this.offset.relative.top*a+this.offset.parent.top*a-(d.browser.safari&& d.browser.version<526&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollTop():f?0:c.scrollTop())*a),left:b.left+this.offset.relative.left*a+this.offset.parent.left*a-(d.browser.safari&&d.browser.version<526&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():f?0:c.scrollLeft())*a)}},_generatePosition:function(a){var b=this.options,c=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0], this.offsetParent[0]))?this.offsetParent:this.scrollParent,f=/(html|body)/i.test(c[0].tagName),e=a.pageX,h=a.pageY;if(this.originalPosition){var g;if(this.containment){if(this.relative_container){g=this.relative_container.offset();g=[this.containment[0]+g.left,this.containment[1]+g.top,this.containment[2]+g.left,this.containment[3]+g.top]}else g=this.containment;if(a.pageX-this.offset.click.left<g[0])e=g[0]+this.offset.click.left;if(a.pageY-this.offset.click.top<g[1])h=g[1]+this.offset.click.top; if(a.pageX-this.offset.click.left>g[2])e=g[2]+this.offset.click.left;if(a.pageY-this.offset.click.top>g[3])h=g[3]+this.offset.click.top}if(b.grid){h=this.originalPageY+Math.round((h-this.originalPageY)/b.grid[1])*b.grid[1];h=g?!(h-this.offset.click.top<g[1]||h-this.offset.click.top>g[3])?h:!(h-this.offset.click.top<g[1])?h-b.grid[1]:h+b.grid[1]:h;e=this.originalPageX+Math.round((e-this.originalPageX)/b.grid[0])*b.grid[0];e=g?!(e-this.offset.click.left<g[0]||e-this.offset.click.left>g[2])?e:!(e-this.offset.click.left< g[0])?e-b.grid[0]:e+b.grid[0]:e}}return{top:h-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+(d.browser.safari&&d.browser.version<526&&this.cssPosition=="fixed"?0:this.cssPosition=="fixed"?-this.scrollParent.scrollTop():f?0:c.scrollTop()),left:e-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+(d.browser.safari&&d.browser.version<526&&this.cssPosition=="fixed"?0:this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():f?0:c.scrollLeft())}},_clear:function(){this.helper.removeClass("ui-draggable-dragging"); this.helper[0]!=this.element[0]&&!this.cancelHelperRemoval&&this.helper.remove();this.helper=null;this.cancelHelperRemoval=false},_trigger:function(a,b,c){c=c||this._uiHash();d.ui.plugin.call(this,a,[b,c]);if(a=="drag")this.positionAbs=this._convertPositionTo("absolute");return d.Widget.prototype._trigger.call(this,a,b,c)},plugins:{},_uiHash:function(){return{helper:this.helper,position:this.position,originalPosition:this.originalPosition,offset:this.positionAbs}}});d.extend(d.ui.draggable,{version:"1.8.13"}); d.ui.plugin.add("draggable","connectToSortable",{start:function(a,b){var c=d(this).data("draggable"),f=c.options,e=d.extend({},b,{item:c.element});c.sortables=[];d(f.connectToSortable).each(function(){var h=d.data(this,"sortable");if(h&&!h.options.disabled){c.sortables.push({instance:h,shouldRevert:h.options.revert});h.refreshPositions();h._trigger("activate",a,e)}})},stop:function(a,b){var c=d(this).data("draggable"),f=d.extend({},b,{item:c.element});d.each(c.sortables,function(){if(this.instance.isOver){this.instance.isOver= 0;c.cancelHelperRemoval=true;this.instance.cancelHelperRemoval=false;if(this.shouldRevert)this.instance.options.revert=true;this.instance._mouseStop(a);this.instance.options.helper=this.instance.options._helper;c.options.helper=="original"&&this.instance.currentItem.css({top:"auto",left:"auto"})}else{this.instance.cancelHelperRemoval=false;this.instance._trigger("deactivate",a,f)}})},drag:function(a,b){var c=d(this).data("draggable"),f=this;d.each(c.sortables,function(){this.instance.positionAbs= c.positionAbs;this.instance.helperProportions=c.helperProportions;this.instance.offset.click=c.offset.click;if(this.instance._intersectsWith(this.instance.containerCache)){if(!this.instance.isOver){this.instance.isOver=1;this.instance.currentItem=d(f).clone().removeAttr("id").appendTo(this.instance.element).data("sortable-item",true);this.instance.options._helper=this.instance.options.helper;this.instance.options.helper=function(){return b.helper[0]};a.target=this.instance.currentItem[0];this.instance._mouseCapture(a, true);this.instance._mouseStart(a,true,true);this.instance.offset.click.top=c.offset.click.top;this.instance.offset.click.left=c.offset.click.left;this.instance.offset.parent.left-=c.offset.parent.left-this.instance.offset.parent.left;this.instance.offset.parent.top-=c.offset.parent.top-this.instance.offset.parent.top;c._trigger("toSortable",a);c.dropped=this.instance.element;c.currentItem=c.element;this.instance.fromOutside=c}this.instance.currentItem&&this.instance._mouseDrag(a)}else if(this.instance.isOver){this.instance.isOver= 0;this.instance.cancelHelperRemoval=true;this.instance.options.revert=false;this.instance._trigger("out",a,this.instance._uiHash(this.instance));this.instance._mouseStop(a,true);this.instance.options.helper=this.instance.options._helper;this.instance.currentItem.remove();this.instance.placeholder&&this.instance.placeholder.remove();c._trigger("fromSortable",a);c.dropped=false}})}});d.ui.plugin.add("draggable","cursor",{start:function(){var a=d("body"),b=d(this).data("draggable").options;if(a.css("cursor"))b._cursor= a.css("cursor");a.css("cursor",b.cursor)},stop:function(){var a=d(this).data("draggable").options;a._cursor&&d("body").css("cursor",a._cursor)}});d.ui.plugin.add("draggable","opacity",{start:function(a,b){a=d(b.helper);b=d(this).data("draggable").options;if(a.css("opacity"))b._opacity=a.css("opacity");a.css("opacity",b.opacity)},stop:function(a,b){a=d(this).data("draggable").options;a._opacity&&d(b.helper).css("opacity",a._opacity)}});d.ui.plugin.add("draggable","scroll",{start:function(){var a=d(this).data("draggable"); if(a.scrollParent[0]!=document&&a.scrollParent[0].tagName!="HTML")a.overflowOffset=a.scrollParent.offset()},drag:function(a){var b=d(this).data("draggable"),c=b.options,f=false;if(b.scrollParent[0]!=document&&b.scrollParent[0].tagName!="HTML"){if(!c.axis||c.axis!="x")if(b.overflowOffset.top+b.scrollParent[0].offsetHeight-a.pageY<c.scrollSensitivity)b.scrollParent[0].scrollTop=f=b.scrollParent[0].scrollTop+c.scrollSpeed;else if(a.pageY-b.overflowOffset.top<c.scrollSensitivity)b.scrollParent[0].scrollTop= f=b.scrollParent[0].scrollTop-c.scrollSpeed;if(!c.axis||c.axis!="y")if(b.overflowOffset.left+b.scrollParent[0].offsetWidth-a.pageX<c.scrollSensitivity)b.scrollParent[0].scrollLeft=f=b.scrollParent[0].scrollLeft+c.scrollSpeed;else if(a.pageX-b.overflowOffset.left<c.scrollSensitivity)b.scrollParent[0].scrollLeft=f=b.scrollParent[0].scrollLeft-c.scrollSpeed}else{if(!c.axis||c.axis!="x")if(a.pageY-d(document).scrollTop()<c.scrollSensitivity)f=d(document).scrollTop(d(document).scrollTop()-c.scrollSpeed); else if(d(window).height()-(a.pageY-d(document).scrollTop())<c.scrollSensitivity)f=d(document).scrollTop(d(document).scrollTop()+c.scrollSpeed);if(!c.axis||c.axis!="y")if(a.pageX-d(document).scrollLeft()<c.scrollSensitivity)f=d(document).scrollLeft(d(document).scrollLeft()-c.scrollSpeed);else if(d(window).width()-(a.pageX-d(document).scrollLeft())<c.scrollSensitivity)f=d(document).scrollLeft(d(document).scrollLeft()+c.scrollSpeed)}f!==false&&d.ui.ddmanager&&!c.dropBehaviour&&d.ui.ddmanager.prepareOffsets(b, a)}});d.ui.plugin.add("draggable","snap",{start:function(){var a=d(this).data("draggable"),b=a.options;a.snapElements=[];d(b.snap.constructor!=String?b.snap.items||":data(draggable)":b.snap).each(function(){var c=d(this),f=c.offset();this!=a.element[0]&&a.snapElements.push({item:this,width:c.outerWidth(),height:c.outerHeight(),top:f.top,left:f.left})})},drag:function(a,b){for(var c=d(this).data("draggable"),f=c.options,e=f.snapTolerance,h=b.offset.left,g=h+c.helperProportions.width,n=b.offset.top, o=n+c.helperProportions.height,i=c.snapElements.length-1;i>=0;i--){var j=c.snapElements[i].left,l=j+c.snapElements[i].width,k=c.snapElements[i].top,m=k+c.snapElements[i].height;if(j-e<h&&h<l+e&&k-e<n&&n<m+e||j-e<h&&h<l+e&&k-e<o&&o<m+e||j-e<g&&g<l+e&&k-e<n&&n<m+e||j-e<g&&g<l+e&&k-e<o&&o<m+e){if(f.snapMode!="inner"){var p=Math.abs(k-o)<=e,q=Math.abs(m-n)<=e,r=Math.abs(j-g)<=e,s=Math.abs(l-h)<=e;if(p)b.position.top=c._convertPositionTo("relative",{top:k-c.helperProportions.height,left:0}).top-c.margins.top; if(q)b.position.top=c._convertPositionTo("relative",{top:m,left:0}).top-c.margins.top;if(r)b.position.left=c._convertPositionTo("relative",{top:0,left:j-c.helperProportions.width}).left-c.margins.left;if(s)b.position.left=c._convertPositionTo("relative",{top:0,left:l}).left-c.margins.left}var t=p||q||r||s;if(f.snapMode!="outer"){p=Math.abs(k-n)<=e;q=Math.abs(m-o)<=e;r=Math.abs(j-h)<=e;s=Math.abs(l-g)<=e;if(p)b.position.top=c._convertPositionTo("relative",{top:k,left:0}).top-c.margins.top;if(q)b.position.top= c._convertPositionTo("relative",{top:m-c.helperProportions.height,left:0}).top-c.margins.top;if(r)b.position.left=c._convertPositionTo("relative",{top:0,left:j}).left-c.margins.left;if(s)b.position.left=c._convertPositionTo("relative",{top:0,left:l-c.helperProportions.width}).left-c.margins.left}if(!c.snapElements[i].snapping&&(p||q||r||s||t))c.options.snap.snap&&c.options.snap.snap.call(c.element,a,d.extend(c._uiHash(),{snapItem:c.snapElements[i].item}));c.snapElements[i].snapping=p||q||r||s||t}else{c.snapElements[i].snapping&& c.options.snap.release&&c.options.snap.release.call(c.element,a,d.extend(c._uiHash(),{snapItem:c.snapElements[i].item}));c.snapElements[i].snapping=false}}}});d.ui.plugin.add("draggable","stack",{start:function(){var a=d(this).data("draggable").options;a=d.makeArray(d(a.stack)).sort(function(c,f){return(parseInt(d(c).css("zIndex"),10)||0)-(parseInt(d(f).css("zIndex"),10)||0)});if(a.length){var b=parseInt(a[0].style.zIndex)||0;d(a).each(function(c){this.style.zIndex=b+c});this[0].style.zIndex=b+a.length}}}); d.ui.plugin.add("draggable","zIndex",{start:function(a,b){a=d(b.helper);b=d(this).data("draggable").options;if(a.css("zIndex"))b._zIndex=a.css("zIndex");a.css("zIndex",b.zIndex)},stop:function(a,b){a=d(this).data("draggable").options;a._zIndex&&d(b.helper).css("zIndex",a._zIndex)}})})(jQuery); ; /* * jQuery UI Sortable 1.8.13 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * * http://docs.jquery.com/UI/Sortables * * Depends: * jquery.ui.core.js * jquery.ui.mouse.js * jquery.ui.widget.js */ (function( $, undefined ) { $.widget("ui.sortable", $.ui.mouse, { widgetEventPrefix: "sort", options: { appendTo: "parent", axis: false, connectWith: false, containment: false, cursor: 'auto', cursorAt: false, dropOnEmpty: true, forcePlaceholderSize: false, forceHelperSize: false, grid: false, handle: false, helper: "original", items: '> *', opacity: false, placeholder: false, revert: false, scroll: true, scrollSensitivity: 20, scrollSpeed: 20, scope: "default", tolerance: "intersect", zIndex: 1000 }, _create: function() { var o = this.options; this.document = o.document; this.containerCache = {}; this.element.addClass("ui-sortable"); //Get the items this.refresh(); //Let's determine if the items are being displayed horizontally this.floating = this.items.length ? o.axis === 'x' || (/left|right/).test(this.items[0].item.css('float')) || (/inline|table-cell/).test(this.items[0].item.css('display')) : false; //Let's determine the parent's offset this.offset = this.element.offset(); //Initialize mouse events for interaction this._mouseInit(); }, destroy: function() { this.element .removeClass("ui-sortable ui-sortable-disabled") .removeData("sortable") .unbind(".sortable"); this._mouseDestroy(); for ( var i = this.items.length - 1; i >= 0; i-- ) this.items[i].item.removeData("sortable-item"); return this; }, _setOption: function(key, value){ if ( key === "disabled" ) { this.options[ key ] = value; this.widget() [ value ? "addClass" : "removeClass"]( "ui-sortable-disabled" ); } else { // Don't call widget base _setOption for disable as it adds ui-state-disabled class $.Widget.prototype._setOption.apply(this, arguments); } }, _mouseCapture: function(event, overrideHandle) { if (this.reverting) { return false; } if(this.options.disabled || this.options.type == 'static') return false; //We have to refresh the items data once first this._refreshItems(event); //Find out if the clicked node (or one of its parents) is a actual item in this.items var currentItem = null, self = this, nodes = $(event.target).parents().each(function() { if($.data(this, 'sortable-item') == self) { currentItem = $(this); return false; } }); if($.data(event.target, 'sortable-item') == self) currentItem = $(event.target); if(!currentItem) return false; if(this.options.handle && !overrideHandle) { var validHandle = false; $(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; }); if(!validHandle) return false; } this.currentItem = currentItem; this._removeCurrentsFromItems(); return true; }, _mouseStart: function(event, overrideHandle, noActivation) { var o = this.options, self = this; this.currentContainer = this; //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture this.refreshPositions(); //Create and append the visible helper this.helper = this._createHelper(event); //Cache the helper size this._cacheHelperProportions(); /* * - Position generation - * This block generates everything position related - it's the core of draggables. */ //Cache the margins of the original element this._cacheMargins(); //Get the next scrolling parent this.scrollParent = this.helper.scrollParent(); //The element's absolute position on the page minus margins this.offset = this.currentItem.offset(); this.offset = { top: this.offset.top - this.margins.top, left: this.offset.left - this.margins.left }; // Only after we got the offset, we can change the helper's position to absolute // TODO: Still need to figure out a way to make relative sorting possible this.helper.css("position", "absolute"); this.cssPosition = this.helper.css("position"); $.extend(this.offset, { click: { //Where the click happened, relative to the element left: event.pageX - this.offset.left, top: event.pageY - this.offset.top }, parent: this._getParentOffset(), relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper }); //Generate the original position this.originalPosition = this._generatePosition(event); this.originalPageX = event.pageX; this.originalPageY = event.pageY; //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); //Cache the former DOM position this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; //If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way if(this.helper[0] != this.currentItem[0]) { this.currentItem.hide(); } //Create the placeholder this._createPlaceholder(); //Set a containment if given in the options if(o.containment) this._setContainment(); if(o.cursor) { // cursor option if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor"); $('body').css("cursor", o.cursor); } if(o.opacity) { // opacity option if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity"); this.helper.css("opacity", o.opacity); } if(o.zIndex) { // zIndex option if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex"); this.helper.css("zIndex", o.zIndex); } //Prepare scrolling if(this.scrollParent[0] != (this.document || document) && this.scrollParent[0].tagName != 'HTML') this.overflowOffset = this.scrollParent.offset(); //Call callbacks this._trigger("start", event, this._uiHash()); //Recache the helper size if(!this._preserveHelperProportions) this._cacheHelperProportions(); //Post 'activate' events to possible containers if(!noActivation) { for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, self._uiHash(this)); } } //Prepare possible droppables if($.ui.ddmanager) $.ui.ddmanager.current = this; if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, event); this.dragging = true; this.helper.addClass("ui-sortable-helper"); this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position return true; }, _mouseDrag: function(event) { //Compute the helpers position this.position = this._generatePosition(event); this.positionAbs = this._convertPositionTo("absolute"); if (!this.lastPositionAbs) { this.lastPositionAbs = this.positionAbs; } //Do scrolling if(this.options.scroll) { var o = this.options, scrolled = false; if(this.scrollParent[0] != (this.document || document) && this.scrollParent[0].tagName != 'HTML') { if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed; else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed; if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed; else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed; } else { if(event.pageY - $((this.document || document)).scrollTop() < o.scrollSensitivity) scrolled = $((this.document || document)).scrollTop($((this.document || document)).scrollTop() - o.scrollSpeed); else if($(window).height() - (event.pageY - $((this.document || document)).scrollTop()) < o.scrollSensitivity) scrolled = $((this.document || document)).scrollTop($((this.document || document)).scrollTop() + o.scrollSpeed); if(event.pageX - $((this.document || document)).scrollLeft() < o.scrollSensitivity) scrolled = $((this.document || document)).scrollLeft($((this.document || document)).scrollLeft() - o.scrollSpeed); else if($(window).width() - (event.pageX - $((this.document || document)).scrollLeft()) < o.scrollSensitivity) scrolled = $((this.document || document)).scrollLeft($((this.document || document)).scrollLeft() + o.scrollSpeed); } if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, event); } //Regenerate the absolute position used for position checks this.positionAbs = this._convertPositionTo("absolute"); //Set the helper position if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; //Rearrange for (var i = this.items.length - 1; i >= 0; i--) { //Cache variables and intersection, continue if no intersection var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item); if (!intersection) continue; if(itemElement != this.currentItem[0] //cannot intersect with itself && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before && !$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked && (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true) //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container ) { this.direction = intersection == 1 ? "down" : "up"; if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) { this._rearrange(event, item); } else { break; } this._trigger("change", event, this._uiHash()); break; } } //Post events to containers this._contactContainers(event); //Interconnect with droppables if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); //Call callbacks this._trigger('sort', event, this._uiHash()); this.lastPositionAbs = this.positionAbs; return false; }, _mouseStop: function(event, noPropagation) { if(!event) return; //If we are using droppables, inform the manager about the drop if ($.ui.ddmanager && !this.options.dropBehaviour) $.ui.ddmanager.drop(this, event); if(this.options.revert) { var self = this; var cur = self.placeholder.offset(); self.reverting = true; $(this.helper).animate({ left: cur.left - this.offset.parent.left - self.margins.left + (this.offsetParent[0] == (this.document || document).body ? 0 : this.offsetParent[0].scrollLeft), top: cur.top - this.offset.parent.top - self.margins.top + (this.offsetParent[0] == (this.document || document).body ? 0 : this.offsetParent[0].scrollTop) }, parseInt(this.options.revert, 10) || 500, function() { self._clear(event); }); } else { this._clear(event, noPropagation); } return false; }, cancel: function() { var self = this; if(this.dragging) { this._mouseUp({ target: null }); if(this.options.helper == "original") this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"); else this.currentItem.show(); //Post deactivating events to containers for (var i = this.containers.length - 1; i >= 0; i--){ this.containers[i]._trigger("deactivate", null, self._uiHash(this)); if(this.containers[i].containerCache.over) { this.containers[i]._trigger("out", null, self._uiHash(this)); this.containers[i].containerCache.over = 0; } } } if (this.placeholder) { //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]); if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove(); $.extend(this, { helper: null, dragging: false, reverting: false, _noFinalSort: null }); if(this.domPosition.prev) { $(this.domPosition.prev).after(this.currentItem); } else { $(this.domPosition.parent).prepend(this.currentItem); } } return this; }, serialize: function(o) { var items = this._getItemsAsjQuery(o && o.connected); var str = []; o = o || {}; $(items).each(function() { var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/)); if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2])); }); if(!str.length && o.key) { str.push(o.key + '='); } return str.join('&'); }, toArray: function(o) { var items = this._getItemsAsjQuery(o && o.connected); var ret = []; o = o || {}; items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); }); return ret; }, /* Be careful with the following core functions */ _intersectsWith: function(item) { var x1 = this.positionAbs.left, x2 = x1 + this.helperProportions.width, y1 = this.positionAbs.top, y2 = y1 + this.helperProportions.height; var l = item.left, r = l + item.width, t = item.top, b = t + item.height; var dyClick = this.offset.click.top, dxClick = this.offset.click.left; var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; if( this.options.tolerance == "pointer" || this.options.forcePointerForContainers || (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height']) ) { return isOverElement; } else { return (l < x1 + (this.helperProportions.width / 2) // Right Half && x2 - (this.helperProportions.width / 2) < r // Left Half && t < y1 + (this.helperProportions.height / 2) // Bottom Half && y2 - (this.helperProportions.height / 2) < b ); // Top Half } }, _intersectsWithPointer: function(item) { var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height), isOverElementWidth = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width), isOverElement = isOverElementHeight && isOverElementWidth, verticalDirection = this._getDragVerticalDirection(), horizontalDirection = this._getDragHorizontalDirection(); if (!isOverElement) return false; return this.floating ? ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 ) : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) ); }, _intersectsWithSides: function(item) { var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), verticalDirection = this._getDragVerticalDirection(), horizontalDirection = this._getDragHorizontalDirection(); if (this.floating && horizontalDirection) { return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf)); } else { return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf)); } }, _getDragVerticalDirection: function() { var delta = this.positionAbs.top - this.lastPositionAbs.top; return delta != 0 && (delta > 0 ? "down" : "up"); }, _getDragHorizontalDirection: function() { var delta = this.positionAbs.left - this.lastPositionAbs.left; return delta != 0 && (delta > 0 ? "right" : "left"); }, refresh: function(event) { this._refreshItems(event); this.refreshPositions(); return this; }, _connectWith: function() { var options = this.options; return options.connectWith.constructor == String ? [options.connectWith] : options.connectWith; }, _getItemsAsjQuery: function(connected) { var self = this; var items = []; var queries = []; var connectWith = this._connectWith(); if(connectWith && connected) { for (var i = connectWith.length - 1; i >= 0; i--){ var cur = $(connectWith[i]); for (var j = cur.length - 1; j >= 0; j--){ var inst = $.data(cur[j], 'sortable'); if(inst && inst != this && !inst.options.disabled) { queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]); } }; }; } queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), this]); for (var i = queries.length - 1; i >= 0; i--){ queries[i][0].each(function() { items.push(this); }); }; return $(items); }, _removeCurrentsFromItems: function() { var list = this.currentItem.find(":data(sortable-item)"); for (var i=0; i < this.items.length; i++) { for (var j=0; j < list.length; j++) { if(list[j] == this.items[i].item[0]) this.items.splice(i,1); }; }; }, _refreshItems: function(event) { this.items = []; this.containers = [this]; var items = this.items; var self = this; var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]]; var connectWith = this._connectWith(); if(connectWith) { for (var i = connectWith.length - 1; i >= 0; i--){ var cur = $(connectWith[i]); for (var j = cur.length - 1; j >= 0; j--){ var inst = $.data(cur[j], 'sortable'); if(inst && inst != this && !inst.options.disabled) { queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]); this.containers.push(inst); } }; }; } for (var i = queries.length - 1; i >= 0; i--) { var targetData = queries[i][1]; var _queries = queries[i][0]; for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) { var item = $(_queries[j]); item.data('sortable-item', targetData); // Data for target checking (mouse manager) items.push({ item: item, instance: targetData, width: 0, height: 0, left: 0, top: 0 }); }; }; }, refreshPositions: function(fast) { //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change if(this.offsetParent && this.helper) { this.offset.parent = this._getParentOffset(); } for (var i = this.items.length - 1; i >= 0; i--){ var item = this.items[i]; //We ignore calculating positions of all connected containers when we're not over them if(item.instance != this.currentContainer && this.currentContainer && item.item[0] != this.currentItem[0]) continue; var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item; if (!fast) { item.width = t.outerWidth(); item.height = t.outerHeight(); } var p = t.offset(); item.left = p.left; item.top = p.top; }; if(this.options.custom && this.options.custom.refreshContainers) { this.options.custom.refreshContainers.call(this); } else { for (var i = this.containers.length - 1; i >= 0; i--){ var p = this.containers[i].element.offset(); this.containers[i].containerCache.left = p.left; this.containers[i].containerCache.top = p.top; this.containers[i].containerCache.width = this.containers[i].element.outerWidth(); this.containers[i].containerCache.height = this.containers[i].element.outerHeight(); }; } return this; }, _createPlaceholder: function(that) { var self = that || this, o = self.options; if(!o.placeholder || o.placeholder.constructor == String) { var className = o.placeholder; o.placeholder = { element: function() { var el = $((this.document || document).createElement(self.currentItem[0].nodeName)) .addClass(className || self.currentItem[0].className+" ui-sortable-placeholder") .removeClass("ui-sortable-helper")[0]; if(!className) el.style.visibility = "hidden"; return el; }, update: function(container, p) { // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified if(className && !o.forcePlaceholderSize) return; //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item if(!p.height()) { p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10)); }; if(!p.width()) { p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10)); }; } }; } //Create the placeholder self.placeholder = $(o.placeholder.element.call(self.element, self.currentItem)); //Append it after the actual current item self.currentItem.after(self.placeholder); //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317) o.placeholder.update(self, self.placeholder); }, _contactContainers: function(event) { // get innermost container that intersects with item var innermostContainer = null, innermostIndex = null; for (var i = this.containers.length - 1; i >= 0; i--){ // never consider a container that's located within the item itself if($.ui.contains(this.currentItem[0], this.containers[i].element[0])) continue; if(this._intersectsWith(this.containers[i].containerCache)) { // if we've already found a container and it's more "inner" than this, then continue if(innermostContainer && $.ui.contains(this.containers[i].element[0], innermostContainer.element[0])) continue; innermostContainer = this.containers[i]; innermostIndex = i; } else { // container doesn't intersect. trigger "out" event if necessary if(this.containers[i].containerCache.over) { this.containers[i]._trigger("out", event, this._uiHash(this)); this.containers[i].containerCache.over = 0; } } } // if no intersecting containers found, return if(!innermostContainer) return; // move the item into the container if it's not there already if(this.containers.length === 1) { this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); this.containers[innermostIndex].containerCache.over = 1; } else if(this.currentContainer != this.containers[innermostIndex]) { //When entering a new container, we will find the item with the least distance and append our item near it var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top']; for (var j = this.items.length - 1; j >= 0; j--) { if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue; var cur = this.items[j][this.containers[innermostIndex].floating ? 'left' : 'top']; if(Math.abs(cur - base) < dist) { dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; } } if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled return; this.currentContainer = this.containers[innermostIndex]; itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true); this._trigger("change", event, this._uiHash()); this.containers[innermostIndex]._trigger("change", event, this._uiHash(this)); //Update the placeholder this.options.placeholder.update(this.currentContainer, this.placeholder); this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); this.containers[innermostIndex].containerCache.over = 1; } }, _createHelper: function(event) { var o = this.options; var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem); if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already $(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]); if(helper[0] == this.currentItem[0]) this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") }; if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width()); if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height()); return helper; }, _adjustOffsetFromHelper: function(obj) { if (typeof obj == 'string') { obj = obj.split(' '); } if ($.isArray(obj)) { obj = {left: +obj[0], top: +obj[1] || 0}; } if ('left' in obj) { this.offset.click.left = obj.left + this.margins.left; } if ('right' in obj) { this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left; } if ('top' in obj) { this.offset.click.top = obj.top + this.margins.top; } if ('bottom' in obj) { this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top; } }, _getParentOffset: function() { //Get the offsetParent and cache its position this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); // This is a special case where we need to modify a offset calculated on start, since the following happened: // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag if(this.cssPosition == 'absolute' && this.scrollParent[0] != (this.document || document) && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) { po.left += this.scrollParent.scrollLeft(); po.top += this.scrollParent.scrollTop(); } if((this.offsetParent[0] == (this.document || document).body) //This needs to be actually done for all browsers, since pageX/pageY includes this information || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix po = { top: 0, left: 0 }; return { top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0), left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) }; }, _getRelativeOffset: function() { if(this.cssPosition == "relative") { var p = this.currentItem.position(); return { top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(), left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft() }; } else { return { top: 0, left: 0 }; } }, _cacheMargins: function() { this.margins = { left: (parseInt(this.currentItem.css("marginLeft"),10) || 0), top: (parseInt(this.currentItem.css("marginTop"),10) || 0) }; }, _cacheHelperProportions: function() { this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() }; }, _setContainment: function() { var o = this.options; if(o.containment == 'parent') o.containment = this.helper[0].parentNode; if(o.containment == 'document' || o.containment == 'window') this.containment = [ 0 - this.offset.relative.left - this.offset.parent.left, 0 - this.offset.relative.top - this.offset.parent.top, $(o.containment == 'document' ? (this.document || document) : window).width() - this.helperProportions.width - this.margins.left, ($(o.containment == 'document' ? (this.document || document) : window).height() || (this.document || document).body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top ]; if(!(/^(document|window|parent)$/).test(o.containment)) { var ce = $(o.containment)[0]; var co = $(o.containment).offset(); var over = ($(ce).css("overflow") != 'hidden'); this.containment = [ co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left, co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top, co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left, co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top ]; } }, _convertPositionTo: function(d, pos) { if(!pos) pos = this.position; var mod = d == "absolute" ? 1 : -1; var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != (this.document || document) && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); return { top: ( pos.top // The absolute mouse position + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border) - ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod) ), left: ( pos.left // The absolute mouse position + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border) - ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod) ) }; }, _generatePosition: function(event) { var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != (this.document || document) && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); // This is another very weird special case that only happens for relative elements: // 1. If the css position is relative // 2. and the scroll parent is the document or similar to the offset parent // we have to refresh the relative offset during the scroll so there are no jumps if(this.cssPosition == 'relative' && !(this.scrollParent[0] != (this.document || document) && this.scrollParent[0] != this.offsetParent[0])) { this.offset.relative = this._getRelativeOffset(); } var pageX = event.pageX; var pageY = event.pageY; /* * - Position constraining - * Constrain the position to a mix of grid, containment. */ if(this.originalPosition) { //If we are not dragging yet, we won't check for options if(this.containment) { if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left; if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top; if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left; if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top; } if(o.grid) { var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1]; pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0]; pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; } } return { top: ( pageY // The absolute mouse position - this.offset.click.top // Click offset (relative to the element) - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent - this.offset.parent.top // The offsetParent's offset without borders (offset + border) + ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )) ), left: ( pageX // The absolute mouse position - this.offset.click.left // Click offset (relative to the element) - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent - this.offset.parent.left // The offsetParent's offset without borders (offset + border) + ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )) ) }; }, _rearrange: function(event, i, a, hardRefresh) { a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction == 'down' ? i.item[0] : i.item[0].nextSibling)); //Various things done here to improve the performance: // 1. we create a setTimeout, that calls refreshPositions // 2. on the instance, we have a counter variable, that get's higher after every append // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same // 4. this lets only the last addition to the timeout stack through this.counter = this.counter ? ++this.counter : 1; var self = this, counter = this.counter; window.setTimeout(function() { if(counter == self.counter) self.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove },0); }, _clear: function(event, noPropagation) { this.reverting = false; // We delay all events that have to be triggered to after the point where the placeholder has been removed and // everything else normalized again var delayedTriggers = [], self = this; // We first have to update the dom position of the actual currentItem // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088) if(!this._noFinalSort && this.currentItem[0].parentNode) this.placeholder.before(this.currentItem); this._noFinalSort = null; if(this.helper[0] == this.currentItem[0]) { for(var i in this._storedCSS) { if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = ''; } this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"); } else { this.currentItem.show(); } if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); }); if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element if(!noPropagation) delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); }); for (var i = this.containers.length - 1; i >= 0; i--){ if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) { delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.containers[i])); delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.containers[i])); } }; }; //Post events to containers for (var i = this.containers.length - 1; i >= 0; i--){ if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i])); if(this.containers[i].containerCache.over) { delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i])); this.containers[i].containerCache.over = 0; } } //Do what was originally in plugins if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset opacity if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index this.dragging = false; if(this.cancelHelperRemoval) { if(!noPropagation) { this._trigger("beforeStop", event, this._uiHash()); for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events this._trigger("stop", event, this._uiHash()); } return false; } if(!noPropagation) this._trigger("beforeStop", event, this._uiHash()); //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! this.placeholder[0].parentNode.removeChild(this.placeholder[0]); if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null; if(!noPropagation) { for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events this._trigger("stop", event, this._uiHash()); } this.fromOutside = false; return true; }, _trigger: function() { if ($.Widget.prototype._trigger.apply(this, arguments) === false) { this.cancel(); } }, _uiHash: function(inst) { var self = inst || this; return { helper: self.helper, placeholder: self.placeholder || $([]), position: self.position, originalPosition: self.originalPosition, offset: self.positionAbs, item: self.currentItem, sender: inst ? inst.element : null }; } }); $.extend($.ui.sortable, { version: "1.8.13" }); })(jQuery); /* * jQuery serializeObject Plugin: https://github.com/fojas/jQuery-serializeObject * */ !function($){ $.serializeObject = function(obj){ var o={},lookup=o,a = obj; $.each(a,function(){ var named = this.name.replace(/\[([^\]]+)?\]/g,',$1').split(','), cap = named.length - 1, i = 0; for(;i<cap;i++) { // move down the tree - create objects or array if necessary if(lookup.push){ // this is an array, add values instead of setting them // push an object if this is an empty array or we are about to overwrite a value if( !lookup[lookup.length -1] // this is an empty array || lookup[lookup.length -1].constructor !== Object //current value is not a hash || lookup[lookup.length -1][named[i+1]] !== undefined //current item is already set ){ lookup.push({}); } lookup = lookup[lookup.length -1]; } else { lookup = lookup[named[i]] = lookup[named[i]] || (named[i+1]==""?[]:{}); } } if(lookup.push){ lookup.push(this.value); }else{ lookup[named[cap]]=this.value; } lookup = o; }); return o; }; $.deserializeObject = function deserializeObject(json,arr,prefix){ var i,j,thisPrefix,objType; arr = arr || []; if(Object.prototype.toString.call(json) ==='[object Object]'){ for(i in json){ thisPrefix = prefix ? [prefix,'[',i,']'].join('') : i; if(json.hasOwnProperty(i)){ objType = Object.prototype.toString.call(json[i]) if(objType === '[object Array]'){ for(j = 0,jsonLen = json[i].length;j<jsonLen;j++){ deserializeObject(json[i][j],arr,thisPrefix+'[]'); } }else if(objType === '[object Object]'){ deserializeObject(json[i],arr,thisPrefix); }else { arr.push({ name : thisPrefix, value : json[i] }); } } } } else { arr.push({ name : prefix, value : json }); } return arr; } var check = function(){ // older versions of jQuery do not have prop var propExists = !!$.fn.prop; return function(obj,checked){ if(propExists) obj.prop('checked',checked); else obj.attr('checked', (checked ? 'checked' : null )); }; }(); $.applySerializedArray = function(form,obj){ var $form = $(form).find('input,select,textarea'), el; check($form.filter(':checked'),false) for(var i = obj.length;i--;){ el = $form.filter("[name='"+obj[i].name+"']"); if(el.filter(':checkbox').length){ if(el.val() == obj[i].value) check(el.filter(':checkbox'),true); }else if(el.filter(':radio').length){ check(el.filter("[value='"+obj[i].value+"']"),true) } else { el.val(obj[i].value); } } }; $.applySerializedObject = function(form, obj){ $.applySerializedArray(form,$.deserializeObject(obj)); }; $.fn.serializeObject = $.fn.serializeObject || function(){ return $.serializeObject(this.serializeArray()); }; $.fn.applySerializedObject = function(obj){ $.applySerializedObject(this,obj); return this; }; $.fn.applySerializedArray = function(obj){ $.applySerializedArray(this,obj); return this; }; }(jQuery); /* * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ * * Uses the built in easing capabilities added In jQuery 1.1 to offer multiple easing options * * TERMS OF USE - jQuery Easing * * Open source under the BSD License. * * Copyright © 2008 George McGinley Smith * 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 the author nor the names of 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 OWNER 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. */ jQuery.extend(jQuery.easing, { easeInSine: function (x, t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b }, easeOutSine: function (x, t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b }, easeInOutSine: function (x, t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b } }); /* * jQuery JSON Plugin version: 2.1 (2009-08-14) * * This document is licensed as free software under the terms of the MIT License: * http://www.opensource.org/licenses/mit-license.php * * Brantley Harris wrote this plugin. It is based somewhat on the JSON.org website's http://www.json.org/json2.js, * which proclaims: "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that I uphold. * * It is also influenced heavily by MochiKit's serializeJSON, which is copyrighted 2005 by Bob Ippolito. */ (function($) { $.toJSON = function(o) { if (typeof(JSON) == 'object' && JSON.stringify) return JSON.stringify(o); var type = typeof(o); if (o === null) return "null"; if (type == "undefined") return undefined; if (type == "number" || type == "boolean") return o + ""; if (type == "string") return $.quoteString(o); if (type == 'object') { if (typeof(o.toJSON) == "function") return $.toJSON(o.toJSON()); if (o.constructor === Date) { var year = o.getUTCFullYear(); var month = o.getUTCMonth() + 1; if (month < 10) month = '0' + month; var day = o.getUTCDate(); if (day < 10) day = '0' + day; var hours = o.getUTCHours(); if (hours < 10) hours = '0' + hours; var minutes = o.getUTCMinutes(); if (minutes < 10) minutes = '0' + minutes; var seconds = o.getUTCSeconds(); if (seconds < 10) seconds = '0' + seconds; var milli = o.getUTCMilliseconds(); if (milli < 100) milli = '0' + milli; if (milli < 10) milli = '0' + milli; return '"' + year + '-' + month + '-' + day + 'T' + hours + ':' + minutes + ':' + seconds + '.' + milli + 'Z"'; } if (o.constructor === Array) { var ret = []; for (var i = 0; i < o.length; i++) ret.push($.toJSON(o[i]) || "null"); return "[" + ret.join(",") + "]"; } var pairs = []; for (var k in o) { var name; type = typeof(k); if (type == "number") name = '"' + k + '"'; else if (type == "string") name = $.quoteString(k); else continue; //skip non-string or number keys if (typeof o[k] == "function") continue; //skip pairs where the value is a function. var val = $.toJSON(o[k]); pairs.push(name + ":" + val); } return "{" + pairs.join(", ") + "}"; } }; $.quoteString = function(string) { if (string.match(_escapeable)) { return '"' + string.replace(_escapeable, function (a) { var c = _meta[a]; if (typeof c === 'string') return c; c = a.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }) + '"'; } return '"' + string + '"'; }; var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g; var _meta = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'}; })(jQuery); /* * jQuery Localizer Plugin * * Copyright (c) 2011 Sagi Mann (with a basic reworking by Jeremy Jackson) * All rights reserved. * * Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this * paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials * related to such distribution and use acknowledge that the software was developed by the <organization>. The name of * the University may not be used to endorse or promote products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ (function($) { $.fn.localize = function(locale) { this.find('*').contents().each(function() { var translated = false; var source = ''; if (typeof(this.data) == 'string') { source = $.trim(this.data); if (source && (translated = (locale.sub[source] || locale.top[source]))) { this.data = translated; } } if (this.nodeName == 'IMG' && this.attributes['src']) { source = this.attributes['src'].nodeValue; if (source && (translated = (locale.sub[source] || locale.top[source]))) { $(this).attr('src', translated); } } if (this.nodeName == "A" && this.attributes['href']) { source = $.trim(this.attributes['href'].nodeValue); if (source && (translated = (locale.sub[source] || locale.top[source]))) { $(this).attr('href', translated); } } if (this.nodeName == "INPUT" && this.attributes['type']) { if (this.attributes['value'] && ['submit', 'reset', 'button'].indexOf(this.attributes['type'].nodeValue.toLowerCase()) > -1) { source = $.trim(this.attributes['value'].nodeValue); if (source && (translated = (locale.sub[source] || locale.top[source]))) { $(this).attr('value', translated); } } } return this; }); }; })(jQuery); /* HTML Clean for jQuery Anthony Johnston http://www.antix.co.uk version 1.2.3 $Revision: 51 $ requires jQuery http://jquery.com Use and distibution http://www.opensource.org/licenses/bsd-license.php 2010-04-02 allowedTags/removeTags added (white/black list) thanks to David Wartian (Dwartian) 2010-06-30 replaceStyles added for replacement of bold, italic, super and sub styles on a tag 2010-07-01 notRenderedTags added, where tags are to be removed but their contents are kept */ (function ($) { $.fn.htmlClean = function (options) { // iterate and html clean each matched element return this.each(function () { if (this.value) { this.value = $.htmlClean(this.value, options); } else { this.innerHTML = $.htmlClean(this.innerHTML, options); } }); }; // clean the passed html $.htmlClean = function (html, options) { options = $.extend({}, $.htmlClean.defaults, options); var tagsRE = /<(\/)?(\w+:)?([\w]+)([^>]*)>/gi; var attrsRE = /(\w+)=(".*?"|'.*?'|[^\s>]*)/gi; var tagMatch; var root = new Element(); var stack = [root]; var container = root; if (options.bodyOnly) { // check for body tag if (tagMatch = /<body[^>]*>((\n|.)*)<\/body>/i.exec(html)) { html = tagMatch[1]; } } html = html.concat("<xxx>"); // ensure last element/text is found var lastIndex; while (tagMatch = tagsRE.exec(html)) { var tag = new Tag(tagMatch[3], tagMatch[1], tagMatch[4], options); // add the text var text = html.substring(lastIndex, tagMatch.index); if (text.length > 0) { var child = container.children[container.children.length - 1]; if (container.children.length > 0 && isText(child = container.children[container.children.length - 1])) { // merge text container.children[container.children.length - 1] = child.concat(text); } else { container.children.push(text); } } lastIndex = tagsRE.lastIndex; if (tag.isClosing) { // find matching container if (pop(stack, [tag.name])) { stack.pop(); container = stack[stack.length - 1]; } } else { // create a new element var element = new Element(tag); // add attributes var attrMatch; while (attrMatch = attrsRE.exec(tag.rawAttributes)) { // check style attribute and do replacements if (attrMatch[1].toLowerCase() == "style" && options.replaceStyles) { var renderParent = !tag.isInline; for (var i = 0; i < options.replaceStyles.length; i++) { if (options.replaceStyles[i][0].test(attrMatch[2])) { if (!renderParent) { tag.render = false; renderParent = true; } container.children.push(element); // assumes not replaced stack.push(element); container = element; // assumes replacement is a container // create new tag and element tag = new Tag(options.replaceStyles[i][1], "", "", options); element = new Element(tag); } } } if (tag.allowedAttributes != null && (tag.allowedAttributes.length == 0 || $.inArray(attrMatch[1], tag.allowedAttributes) > -1)) { element.attributes.push(new Attribute(attrMatch[1], attrMatch[2])); } } // add required empty ones $.each(tag.requiredAttributes, function () { var name = this.toString(); if (!element.hasAttribute(name)) element.attributes.push(new Attribute(name, "")); }); // check for replacements for (var repIndex = 0; repIndex < options.replace.length; repIndex++) { for (var tagIndex = 0; tagIndex < options.replace[repIndex][0].length; tagIndex++) { var byName = typeof (options.replace[repIndex][0][tagIndex]) == "string"; if ((byName && options.replace[repIndex][0][tagIndex] == tag.name) || (!byName && options.replace[repIndex][0][tagIndex].test(tagMatch))) { // don't render this tag tag.render = false; container.children.push(element); stack.push(element); container = element; // render new tag, keep attributes tag = new Tag(options.replace[repIndex][1], tagMatch[1], tagMatch[4], options); element = new Element(tag); element.attributes = container.attributes; repIndex = options.replace.length; // break out of both loops break; } } } // check container rules var add = true; if (!container.isRoot) { if (container.tag.isInline && !tag.isInline) { add = false; } else if (container.tag.disallowNest && tag.disallowNest && !tag.requiredParent) { add = false; } else if (tag.requiredParent) { if (add = pop(stack, tag.requiredParent)) { container = stack[stack.length - 1]; } } } if (add) { container.children.push(element); if (tag.toProtect) { // skip to closing tag var tagMatch2 = null; while (tagMatch2 = tagsRE.exec(html)) { var tag2 = new Tag(tagMatch2[3], tagMatch2[1], tagMatch2[4], options); if (tag2.isClosing && tag2.name == tag.name) { element.children.push(RegExp.leftContext.substring(lastIndex)); lastIndex = tagsRE.lastIndex; break; } } } else { // set as current container element if (!tag.isSelfClosing && !tag.isNonClosing) { stack.push(element); container = element; } } } } } // render doc return render(root, options).join(""); }; // defaults $.htmlClean.defaults = { // only clean the body tagbody bodyOnly: true, // only allow tags in this array, (white list), contents still rendered allowedTags: [], // remove tags in this array, (black list), contents still rendered removeTags: ["basefont", "center", "dir", "font", "frame", "frameset", "iframe", "isindex", "menu", "noframes", "s", "strike", "u"], // array of attribute names to remove on all elements in addition to those not in tagAttributes e.g ["width", "height"] removeAttrs: [], // array of [className], [optional array of allowed on elements] e.g. [["class"], ["anotherClass", ["p", "dl"]]] allowedClasses: [], // tags not rendered, contents remain notRenderedTags: [], // format the result format: false, // format indent to start on formatIndent: 0, // tags to replace, and what to replace with, tag name or regex to match the tag and attributes replace: [ [ ["b", "big"], "strong" ], [ ["i"], "em" ] ], // styles to replace with tags, multiple style matches supported, inline tags are replaced by the first match blocks are retained replaceStyles: [ [/font-weight:\s*bold/i, "strong"], [/font-style:\s*italic/i, "em"], [/vertical-align:\s*super/i, "sup"], [/vertical-align:\s*sub/i, "sub"] ] }; function applyFormat(element, options, output, indent) { if (!element.tag.isInline && output.length > 0) { output.push("\n"); for (var i = 0; i < indent; i++) output.push("\t"); } } function render(element, options) { var output = [], empty = element.attributes.length == 0, indent = 0, outputChildren = null; // don't render if not in allowedTags or in removeTags var renderTag = element.tag.render && (options.allowedTags.length == 0 || $.inArray(element.tag.name, options.allowedTags) > -1) && (options.removeTags.length == 0 || $.inArray(element.tag.name, options.removeTags) == -1); if (!element.isRoot && renderTag) { // render opening tag output.push("<"); output.push(element.tag.name); $.each(element.attributes, function () { if ($.inArray(this.name, options.removeAttrs) == -1) { var m = new RegExp(/^(['"]?)(.*?)['"]?$/).exec(this.value); var value = m[2]; var valueQuote = m[1] || "'"; // check for classes allowed if (this.name == "class") { value = $.grep(value.split(" "), function (c) { return $.grep(options.allowedClasses, function (a) { return a[0] == c && (a.length == 1 || $.inArray(element.tag.name, a[1]) > -1); }).length > 0; }) .join(" "); valueQuote = "'"; } if (value != null && (value.length > 0 || $.inArray(this.name, element.tag.requiredAttributes) > -1)) { output.push(" "); output.push(this.name); output.push("="); output.push(valueQuote); output.push(value); output.push(valueQuote); } } }); } if (element.tag.isSelfClosing) { // self closing if (renderTag) output.push(" />"); empty = false; } else if (element.tag.isNonClosing) { empty = false; } else { if (!element.isRoot && renderTag) { // close output.push(">"); } indent = options.formatIndent++; // render children if (element.tag.toProtect) { outputChildren = $.htmlClean.trim(element.children.join("")).replace(/<br>/ig, "\n"); output.push(outputChildren); empty = outputChildren.length == 0; options.formatIndent--; } else { outputChildren = []; for (var i = 0; i < element.children.length; i++) { var child = element.children[i]; var text = $.htmlClean.trim(textClean(isText(child) ? child : child.childrenToString())); if (isInline(child)) { if (i > 0 && text.length > 0 && (startsWithWhitespace(child) || endsWithWhitespace(element.children[i - 1]))) { outputChildren.push(" "); } } if (isText(child)) { if (text.length > 0) { outputChildren.push(text); } } else { // don't allow a break to be the last child if (i != element.children.length - 1 || child.tag.name != "br") { if (options.format) applyFormat(child, options, outputChildren, indent); outputChildren = outputChildren.concat(render(child, options)); } } } options.formatIndent--; if (outputChildren.length > 0) { if (options.format && outputChildren[0] != "\n") applyFormat(element, options, output, indent); output = output.concat(outputChildren); empty = false; } } if (!element.isRoot && renderTag) { // render the closing tag if (options.format) applyFormat(element, options, output, indent - 1); output.push("</"); output.push(element.tag.name); output.push(">"); } } // check for empty tags if (!element.tag.allowEmpty && empty) { return []; } return output; } // find a matching tag, and pop to it, if not do nothing function pop(stack, tagNameArray, index) { index = index || 1; if ($.inArray(stack[stack.length - index].tag.name, tagNameArray) > -1) { return true; } else if (stack.length - (index + 1) > 0 && pop(stack, tagNameArray, index + 1)) { stack.pop(); return true; } return false; } // Element Object function Element(tag) { if (tag) { this.tag = tag; this.isRoot = false; } else { this.tag = new Tag("root"); this.isRoot = true; } this.attributes = []; this.children = []; this.hasAttribute = function (name) { for (var i = 0; i < this.attributes.length; i++) { if (this.attributes[i].name == name) return true; } return false; }; this.childrenToString = function () { return this.children.join(""); }; return this; } // Attribute Object function Attribute(name, value) { this.name = name; this.value = value; return this; } // Tag object function Tag(name, close, rawAttributes, options) { this.name = name.toLowerCase(); this.isSelfClosing = $.inArray(this.name, tagSelfClosing) > -1; this.isNonClosing = $.inArray(this.name, tagNonClosing) > -1; this.isClosing = (close != undefined && close.length > 0); this.isInline = $.inArray(this.name, tagInline) > -1; this.disallowNest = $.inArray(this.name, tagDisallowNest) > -1; this.requiredParent = tagRequiredParent[$.inArray(this.name, tagRequiredParent) + 1]; this.allowEmpty = $.inArray(this.name, tagAllowEmpty) > -1; this.toProtect = $.inArray(this.name, tagProtect) > -1; this.rawAttributes = rawAttributes; this.allowedAttributes = tagAttributes[$.inArray(this.name, tagAttributes) + 1]; this.requiredAttributes = tagAttributesRequired[$.inArray(this.name, tagAttributesRequired) + 1]; this.render = options && $.inArray(this.name, options.notRenderedTags) == -1; return this; } function startsWithWhitespace(item) { while (isElement(item) && item.children.length > 0) { item = item.children[0] } return isText(item) && item.length > 0 && $.htmlClean.isWhitespace(item.charAt(0)); } function endsWithWhitespace(item) { while (isElement(item) && item.children.length > 0) { item = item.children[item.children.length - 1] } return isText(item) && item.length > 0 && $.htmlClean.isWhitespace(item.charAt(item.length - 1)); } function isText(item) { return item.constructor == String; } function isInline(item) { return isText(item) || item.tag.isInline; } function isElement(item) { return item.constructor == Element; } function textClean(text) { return text.replace(/ |\n/g, " ").replace(/\s\s+/g, " "); } // trim off white space, doesn't use regex $.htmlClean.trim = function (text) { return $.htmlClean.trimStart($.htmlClean.trimEnd(text)); }; $.htmlClean.trimStart = function (text) { return text.substring($.htmlClean.trimStartIndex(text)); }; $.htmlClean.trimStartIndex = function (text) { for (var start = 0; start < text.length - 1 && $.htmlClean.isWhitespace(text.charAt(start)); start++); return start; }; $.htmlClean.trimEnd = function (text) { return text.substring(0, $.htmlClean.trimEndIndex(text)); }; $.htmlClean.trimEndIndex = function (text) { for (var end = text.length - 1; end >= 0 && $.htmlClean.isWhitespace(text.charAt(end)); end--); return end + 1; }; // checks a char is white space or not $.htmlClean.isWhitespace = function (c) { return $.inArray(c, whitespace) != -1; }; // tags which are inline var tagInline = [ "a", "abbr", "acronym", "address", "b", "big", "br", "button", "caption", "cite", "code", "del", "em", "font", "hr", "i", "input", "img", "ins", "label", "legend", "map", "q", "samp", "select", "small", "span", "strong", "sub", "sup", "tt", "var"]; var tagDisallowNest = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "th", "td"]; var tagAllowEmpty = ["th", "td"]; var tagRequiredParent = [ null, "li", ["ul", "ol"], "dt", ["dl"], "dd", ["dl"], "td", ["tr"], "th", ["tr"], "tr", ["table", "thead", "tbody", "tfoot"], "thead", ["table"], "tbody", ["table"], "tfoot", ["table"] ]; var tagProtect = ["script", "style", "pre", "code"]; // tags which self close e.g. <br /> var tagSelfClosing = ["br", "hr", "img", "link", "meta"]; // tags which do not close var tagNonClosing = ["!doctype", "?xml"]; // attributes allowed on tags var tagAttributes = [ ["class"], // default, for all tags not mentioned "?xml", [], "!doctype", [], "a", ["accesskey", "class", "href", "name", "title", "rel", "rev", "type", "tabindex"], "abbr", ["class", "title"], "acronym", ["class", "title"], "blockquote", ["cite", "class"], "button", ["class", "disabled", "name", "type", "value"], "del", ["cite", "class", "datetime"], "form", ["accept", "action", "class", "enctype", "method", "name"], "input", ["accept", "accesskey", "alt", "checked", "class", "disabled", "ismap", "maxlength", "name", "size", "readonly", "src", "tabindex", "type", "usemap", "value"], "img", ["alt", "class", "height", "src", "width"], "ins", ["cite", "class", "datetime"], "label", ["accesskey", "class", "for"], "legend", ["accesskey", "class"], "link", ["href", "rel", "type"], "meta", ["content", "http-equiv", "name", "scheme"], "map", ["name"], "optgroup", ["class", "disabled", "label"], "option", ["class", "disabled", "label", "selected", "value"], "q", ["class", "cite"], "td", ["colspan", "rowspan"], "th", ["colspan", "rowspan"], "script", ["src", "type"], "select", ["class", "disabled", "multiple", "name", "size", "tabindex"], "style", ["type"], "table", ["class", "summary"], "textarea", ["accesskey", "class", "cols", "disabled", "name", "readonly", "rows", "tabindex"] ]; var tagAttributesRequired = [[], "img", ["alt"]]; // white space chars var whitespace = [" ", " ", "\t", "\n", "\r", "\f"]; })(jQuery); /* * LiquidMetal, version: 0.1 (2009-02-05) * * A mimetic poly-alloy of Quicksilver's scoring algorithm, essentially * LiquidMetal. * * For usage and examples, visit: * http://github.com/rmm5t/liquidmetal * * Licensed under the MIT: * http://www.opensource.org/licenses/mit-license.php * * Copyright (c) 2009, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org) */ var LiquidMetal = function() { var SCORE_NO_MATCH = 0.0; var SCORE_MATCH = 1.0; var SCORE_TRAILING = 0.8; var SCORE_TRAILING_BUT_STARTED = 0.9; var SCORE_BUFFER = 0.85; return { score: function(string, abbreviation) { // Short circuits if (abbreviation.length == 0) return SCORE_TRAILING; if (abbreviation.length > string.length) return SCORE_NO_MATCH; var scores = this.buildScoreArray(string, abbreviation); var sum = 0.0; for (var i =0; i < scores.length; i++) { sum += scores[i]; } return (sum / scores.length); }, buildScoreArray: function(string, abbreviation) { var scores = new Array(string.length); var lower = string.toLowerCase(); var chars = abbreviation.toLowerCase().split(""); var lastIndex = -1; var started = false; for (var i =0; i < chars.length; i++) { var c = chars[i]; var index = lower.indexOf(c, lastIndex+1); if (index < 0) return fillArray(scores, SCORE_NO_MATCH); if (index == 0) started = true; if (isNewWord(string, index)) { scores[index-1] = 1; fillArray(scores, SCORE_BUFFER, lastIndex+1, index-1); } else if (isUpperCase(string, index)) { fillArray(scores, SCORE_BUFFER, lastIndex+1, index); } else { fillArray(scores, SCORE_NO_MATCH, lastIndex+1, index); } scores[index] = SCORE_MATCH; lastIndex = index; } var trailingScore = started ? SCORE_TRAILING_BUT_STARTED : SCORE_TRAILING; fillArray(scores, trailingScore, lastIndex+1); return scores; } }; function isUpperCase(string, index) { var c = string.charAt(index); return ("A" <= c && c <= "Z"); } function isNewWord(string, index) { var c = string.charAt(index-1); return (c == " " || c == "\t"); } function fillArray(array, value, from, to) { from = Math.max(from || 0, 0); to = Math.min(to || array.length, array.length); for (var i = from; i < to; i++) { array[i] = value; } return array; } }(); // // showdown.js -- A javascript port of Markdown. // // Copyright (c) 2007 John Fraser. // // Original Markdown Copyright (c) 2004-2005 John Gruber // <http://daringfireball.net/projects/markdown/> // // Redistributable under a BSD-style open source license. // See license.txt for more information. // // The full source distribution is at: // // A A L // T C A // T K B // // <http://www.attacklab.net/> // // // Wherever possible, Showdown is a straight, line-by-line port // of the Perl version of Markdown. // // This is not a normal parser design; it's basically just a // series of string substitutions. It's hard to read and // maintain this way, but keeping Showdown close to the original // design makes it easier to port new features. // // More importantly, Showdown behaves like markdown.pl in most // edge cases. So web applications can do client-side preview // in Javascript, and then build identical HTML on the server. // // This port needs the new RegExp functionality of ECMA 262, // 3rd Edition (i.e. Javascript 1.5). Most modern web browsers // should do fine. Even with the new regular expression features, // We do a lot of work to emulate Perl's regex functionality. // The tricky changes in this file mostly have the "attacklab:" // label. Major or self-explanatory changes don't. // // Smart diff tools like Araxis Merge will be able to match up // this file with markdown.pl in a useful way. A little tweaking // helps: in a copy of markdown.pl, replace "#" with "//" and // replace "$text" with "text". Be sure to ignore whitespace // and line endings. // // // Showdown usage: // // var text = "Markdown *rocks*."; // // var converter = new Showdown.converter(); // var html = converter.makeHtml(text); // // alert(html); // // Note: move the sample code to the bottom of this // file before uncommenting it. // // ************************************************** // GitHub Flavored Markdown modifications by Tekkub // http://github.github.com/github-flavored-markdown/ // // Modifications are tagged with "GFM" // ************************************************** // // Showdown namespace // var Showdown = {}; // // converter // // Wraps all "globals" so that the only thing // exposed is makeHtml(). // Showdown.converter = function() { // Global hashes, used by various utility routines var g_urls; var g_titles; var g_html_blocks; // Used to track when we're inside an ordered or unordered list // (see _ProcessListItems() for details): var g_list_level = 0; // Main function. The order in which other subs are called here is // essential. Link and image substitutions need to happen before // _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the <a> // and <img> tags get encoded. this.makeHtml = function(text) { // Clear the global hashes. If we don't clear these, you get conflicts // from other articles when generating a page which contains more than // one article (e.g. an index page that shows the N most recent // articles): g_urls = new Array(); g_titles = new Array(); g_html_blocks = new Array(); // attacklab: Replace ~ with ~T // This lets us use tilde as an escape char to avoid md5 hashes // The choice of character is arbitray; anything that isn't // magic in Markdown will work. text = text.replace(/~/g, "~T"); // attacklab: Replace $ with ~D // RegExp interprets $ as a special character // when it's in a replacement string text = text.replace(/\$/g, "~D"); // Standardize line endings text = text.replace(/\r\n/g, "\n"); // DOS to Unix text = text.replace(/\r/g, "\n"); // Mac to Unix // Make sure text begins and ends with a couple of newlines: text = "\n\n" + text + "\n\n"; // Convert all tabs to spaces. text = _Detab(text); // Strip any lines consisting only of spaces and tabs. // This makes subsequent regexen easier to write, because we can // match consecutive blank lines with /\n+/ instead of something // contorted like /[ \t]*\n+/ . text = text.replace(/^[ \t]+$/mg, ""); // Turn block-level HTML blocks into hash entries text = _HashHTMLBlocks(text); // Strip link definitions, store in hashes. text = _StripLinkDefinitions(text); text = _RunBlockGamut(text); text = _UnescapeSpecialChars(text); // attacklab: Restore dollar signs text = text.replace(/~D/g, "$$"); // attacklab: Restore tildes text = text.replace(/~T/g, "~"); // ** GFM ** Auto-link URLs and emails text = text.replace(/https?\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!]/g, function(wholeMatch, matchIndex) { var left = text.slice(0, matchIndex), right = text.slice(matchIndex); if (left.match(/<[^>]+$/) && right.match(/^[^>]*>/)) { return wholeMatch } var href = wholeMatch.replace(/^http:\/\/github.com\//, "https://github.com/"); return "<a href='" + href + "'>" + wholeMatch + "</a>"; }); text = text.replace(/[a-z0-9_\-+=.]+@[a-z0-9\-]+(\.[a-z0-9-]+)+/ig, function(wholeMatch) { return "<a href='mailto:" + wholeMatch + "'>" + wholeMatch + "</a>"; }); // ** GFM ** Auto-link sha1 if GitHub.nameWithOwner is defined text = text.replace(/[a-f0-9]{40}/ig, function(wholeMatch, matchIndex) { if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") { return wholeMatch; } var left = text.slice(0, matchIndex), right = text.slice(matchIndex); if (left.match(/@$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) { return wholeMatch; } return "<a href='http://github.com/" + GitHub.nameWithOwner + "/commit/" + wholeMatch + "'>" + wholeMatch.substring(0, 7) + "</a>"; }); // ** GFM ** Auto-link user@sha1 if GitHub.nameWithOwner is defined text = text.replace(/([a-z0-9_\-+=.]+)@([a-f0-9]{40})/ig, function(wholeMatch, username, sha, matchIndex) { if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") { return wholeMatch; } GitHub.repoName = GitHub.repoName || _GetRepoName(); var left = text.slice(0, matchIndex), right = text.slice(matchIndex); if (left.match(/\/$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) { return wholeMatch; } return "<a href='http://github.com/" + username + "/" + GitHub.repoName + "/commit/" + sha + "'>" + username + "@" + sha.substring(0, 7) + "</a>"; }); // ** GFM ** Auto-link user/repo@sha1 text = text.replace(/([a-z0-9_\-+=.]+\/[a-z0-9_\-+=.]+)@([a-f0-9]{40})/ig, function(wholeMatch, repo, sha) { return "<a href='http://github.com/" + repo + "/commit/" + sha + "'>" + repo + "@" + sha.substring(0, 7) + "</a>"; }); // ** GFM ** Auto-link #issue if GitHub.nameWithOwner is defined text = text.replace(/#([0-9]+)/ig, function(wholeMatch, issue, matchIndex) { if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") { return wholeMatch; } var left = text.slice(0, matchIndex), right = text.slice(matchIndex); if (left == "" || left.match(/[a-z0-9_\-+=.]$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) { return wholeMatch; } return "<a href='http://github.com/" + GitHub.nameWithOwner + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>"; }); // ** GFM ** Auto-link user#issue if GitHub.nameWithOwner is defined text = text.replace(/([a-z0-9_\-+=.]+)#([0-9]+)/ig, function(wholeMatch, username, issue, matchIndex) { if (typeof(GitHub) == "undefined" || typeof(GitHub.nameWithOwner) == "undefined") { return wholeMatch; } GitHub.repoName = GitHub.repoName || _GetRepoName(); var left = text.slice(0, matchIndex), right = text.slice(matchIndex); if (left.match(/\/$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) { return wholeMatch; } return "<a href='http://github.com/" + username + "/" + GitHub.repoName + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>"; }); // ** GFM ** Auto-link user/repo#issue text = text.replace(/([a-z0-9_\-+=.]+\/[a-z0-9_\-+=.]+)#([0-9]+)/ig, function(wholeMatch, repo, issue) { return "<a href='http://github.com/" + repo + "/issues/#issue/" + issue + "'>" + wholeMatch + "</a>"; }); return text; }; var _GetRepoName = function() { return GitHub.nameWithOwner.match(/^.+\/(.+)$/)[1] }; // // Strips link definitions from text, stores the URLs and titles in // hash references. // var _StripLinkDefinitions = function(text) { // Link defs are in the form: ^[id]: url "optional title" /* var text = text.replace(/ ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1 [ \t]* \n? // maybe *one* newline [ \t]* <?(\S+?)>? // url = $2 [ \t]* \n? // maybe one newline [ \t]* (?: (\n*) // any lines skipped = $3 attacklab: lookbehind removed ["(] (.+?) // title = $4 [")] [ \t]* )? // title is optional (?:\n+|$) /gm, function(){...}); */ var text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|\Z)/gm, function (wholeMatch, m1, m2, m3, m4) { m1 = m1.toLowerCase(); g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive if (m3) { // Oops, found blank lines, so it's not a title. // Put back the parenthetical statement we stole. return m3 + m4; } else if (m4) { g_titles[m1] = m4.replace(/"/g, """); } // Completely remove the definition from the text return ""; }); return text; }; var _HashHTMLBlocks = function(text) { // attacklab: Double up blank lines to reduce lookaround text = text.replace(/\n/g, "\n\n"); // Hashify HTML blocks: // We only want to do this for block-level HTML tags, such as headers, // lists, and tables. That's because we still want to wrap <p>s around // "paragraphs" that are wrapped in non-block-level tags, such as anchors, // phrase emphasis, and spans. The list of tags we're looking for is // hard-coded: var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del"; var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math"; // First, look for nested blocks, e.g.: // <div> // <div> // tags for inner block must be indented. // </div> // </div> // // The outermost tags must start at the left margin for this to match, and // the inner nested divs must be indented. // We need to do this before the next, more liberal match, because the next // match will start at the first `<div>` and stop at the first `</div>`. // attacklab: This regex can be expensive when it fails. /* var text = text.replace(/ ( // save in $1 ^ // start of line (with /m) <($block_tags_a) // start tag = $2 \b // word break // attacklab: hack around khtml/pcre bug... [^\r]*?\n // any number of lines, minimally matching </\2> // the matching end tag [ \t]* // trailing spaces/tabs (?=\n+) // followed by a newline ) // attacklab: there are sentinel newlines at end of document /gm,function(){...}}; */ text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm, hashElement); // // Now match more liberally, simply from `\n<tag>` to `</tag>\n` // /* var text = text.replace(/ ( // save in $1 ^ // start of line (with /m) <($block_tags_b) // start tag = $2 \b // word break // attacklab: hack around khtml/pcre bug... [^\r]*? // any number of lines, minimally matching .*</\2> // the matching end tag [ \t]* // trailing spaces/tabs (?=\n+) // followed by a newline ) // attacklab: there are sentinel newlines at end of document /gm,function(){...}}; */ text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm, hashElement); // Special case just for <hr />. It was easier to make a special case than // to make the other regex more complicated. /* text = text.replace(/ ( // save in $1 \n\n // Starting after a blank line [ ]{0,3} (<(hr) // start tag = $2 \b // word break ([^<>])*? // \/?>) // the matching end tag [ \t]* (?=\n{2,}) // followed by a blank line ) /g,hashElement); */ text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g, hashElement); // Special case for standalone HTML comments: /* text = text.replace(/ ( // save in $1 \n\n // Starting after a blank line [ ]{0,3} // attacklab: g_tab_width - 1 <! (--[^\r]*?--\s*)+ > [ \t]* (?=\n{2,}) // followed by a blank line ) /g,hashElement); */ text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g, hashElement); // PHP and ASP-style processor instructions (<?...?> and <%...%>) /* text = text.replace(/ (?: \n\n // Starting after a blank line ) ( // save in $1 [ ]{0,3} // attacklab: g_tab_width - 1 (?: <([?%]) // $2 [^\r]*? \2> ) [ \t]* (?=\n{2,}) // followed by a blank line ) /g,hashElement); */ text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g, hashElement); // attacklab: Undo double lines (see comment at top of this function) text = text.replace(/\n\n/g, "\n"); return text; }; var hashElement = function(wholeMatch, m1) { var blockText = m1; // Undo double lines blockText = blockText.replace(/\n\n/g, "\n"); blockText = blockText.replace(/^\n/, ""); // strip trailing blank lines blockText = blockText.replace(/\n+$/g, ""); // Replace the element text with a marker ("~KxK" where x is its key) blockText = "\n\n~K" + (g_html_blocks.push(blockText) - 1) + "K\n\n"; return blockText; }; // // These are all the transformations that form block-level // tags like paragraphs, headers, and list items. // var _RunBlockGamut = function(text) { text = _DoHeaders(text); // Do Horizontal Rules: var key = hashBlock("<hr />"); text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, key); text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm, key); text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm, key); text = _DoLists(text); text = _DoCodeBlocks(text); text = _DoBlockQuotes(text); // We already ran _HashHTMLBlocks() before, in Markdown(), but that // was to escape raw HTML in the original Markdown source. This time, // we're escaping the markup we've just created, so that we don't wrap // <p> tags around block-level tags. text = _HashHTMLBlocks(text); text = _FormParagraphs(text); return text; }; // // These are all the transformations that occur *within* block-level // tags like paragraphs, headers, and list items. // var _RunSpanGamut = function(text) { text = _DoCodeSpans(text); text = _EscapeSpecialCharsWithinTagAttributes(text); text = _EncodeBackslashEscapes(text); // Process anchor and image tags. Images must come first, // because ![foo][f] looks like an anchor. text = _DoImages(text); text = _DoAnchors(text); // Make links out of things like `<http://example.com/>` // Must come after _DoAnchors(), because you can use < and > // delimiters in inline links like [this](<url>). text = _DoAutoLinks(text); text = _EncodeAmpsAndAngles(text); text = _DoItalicsAndBold(text); // Do hard breaks: text = text.replace(/ +\n/g, " <br />\n"); return text; }; // // Within tags -- meaning between < and > -- encode [\ ` * _] so they // don't conflict with their use in Markdown for code, italics and strong. // var _EscapeSpecialCharsWithinTagAttributes = function(text) { // Build a regex to find HTML tags and comments. See Friedl's // "Mastering Regular Expressions", 2nd Ed., pp. 200-201. var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi; text = text.replace(regex, function(wholeMatch) { var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, "$1`"); tag = escapeCharacters(tag, "\\`*_"); return tag; }); return text; }; // // Turn Markdown link shortcuts into XHTML <a> tags. // var _DoAnchors = function(text) { // // First, handle reference-style links: [link text] [id] // /* text = text.replace(/ ( // wrap whole match in $1 \[ ( (?: \[[^\]]*\] // allow brackets nested one level | [^\[] // or anything else )* ) \] [ ]? // one optional space (?:\n[ ]*)? // one optional newline followed by spaces \[ (.*?) // id = $3 \] )()()()() // pad remaining backreferences /g,_DoAnchors_callback); */ text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, writeAnchorTag); // // Next, inline-style links: [link text](url "optional title") // /* text = text.replace(/ ( // wrap whole match in $1 \[ ( (?: \[[^\]]*\] // allow brackets nested one level | [^\[\]] // or anything else ) ) \] \( // literal paren [ \t]* () // no id, so leave $3 empty <?(.*?)>? // href = $4 [ \t]* ( // $5 (['"]) // quote char = $6 (.*?) // Title = $7 \6 // matching quote [ \t]* // ignore any spaces/tabs between closing quote and ) )? // title is optional \) ) /g,writeAnchorTag); */ text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, writeAnchorTag); // // Last, handle reference-style shortcuts: [link text] // These must come last in case you've also got [link test][1] // or [link test](/foo) // /* text = text.replace(/ ( // wrap whole match in $1 \[ ([^\[\]]+) // link text = $2; can't contain '[' or ']' \] )()()()()() // pad rest of backreferences /g, writeAnchorTag); */ text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag); return text; }; var writeAnchorTag = function(wholeMatch, m1, m2, m3, m4, m5, m6, m7) { if (m7 == undefined) m7 = ""; var whole_match = m1; var link_text = m2; var link_id = m3.toLowerCase(); var url = m4; var title = m7; if (url == "") { if (link_id == "") { // lower-case and turn embedded newlines into spaces link_id = link_text.toLowerCase().replace(/ ?\n/g, " "); } url = "#" + link_id; if (g_urls[link_id] != undefined) { url = g_urls[link_id]; if (g_titles[link_id] != undefined) { title = g_titles[link_id]; } } else { if (whole_match.search(/\(\s*\)$/m) > -1) { // Special case for explicit empty url url = ""; } else { return whole_match; } } } url = escapeCharacters(url, "*_"); var result = "<a href=\"" + url + "\""; if (title != "") { title = title.replace(/"/g, """); title = escapeCharacters(title, "*_"); result += " title=\"" + title + "\""; } result += ">" + link_text + "</a>"; return result; }; // // Turn Markdown image shortcuts into <img> tags. // var _DoImages = function(text) { // // First, handle reference-style labeled images: ![alt text][id] // /* text = text.replace(/ ( // wrap whole match in $1 !\[ (.*?) // alt text = $2 \] [ ]? // one optional space (?:\n[ ]*)? // one optional newline followed by spaces \[ (.*?) // id = $3 \] )()()()() // pad rest of backreferences /g,writeImageTag); */ text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, writeImageTag); // // Next, handle inline images:  // Don't forget: encode * and _ /* text = text.replace(/ ( // wrap whole match in $1 !\[ (.*?) // alt text = $2 \] \s? // One optional whitespace character \( // literal paren [ \t]* () // no id, so leave $3 empty <?(\S+?)>? // src url = $4 [ \t]* ( // $5 (['"]) // quote char = $6 (.*?) // title = $7 \6 // matching quote [ \t]* )? // title is optional \) ) /g,writeImageTag); */ text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, writeImageTag); return text; }; var writeImageTag = function(wholeMatch, m1, m2, m3, m4, m5, m6, m7) { var whole_match = m1; var alt_text = m2; var link_id = m3.toLowerCase(); var url = m4; var title = m7; if (!title) title = ""; if (url == "") { if (link_id == "") { // lower-case and turn embedded newlines into spaces link_id = alt_text.toLowerCase().replace(/ ?\n/g, " "); } url = "#" + link_id; if (g_urls[link_id] != undefined) { url = g_urls[link_id]; if (g_titles[link_id] != undefined) { title = g_titles[link_id]; } } else { return whole_match; } } alt_text = alt_text.replace(/"/g, """); url = escapeCharacters(url, "*_"); var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\""; // attacklab: Markdown.pl adds empty title attributes to images. // Replicate this bug. //if (title != "") { title = title.replace(/"/g, """); title = escapeCharacters(title, "*_"); result += " title=\"" + title + "\""; //} result += " />"; return result; }; var _DoHeaders = function(text) { // Setext-style headers: // Header 1 // ======== // // Header 2 // -------- // text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm, function(wholeMatch, m1) { return hashBlock("<h1>" + _RunSpanGamut(m1) + "</h1>"); }); text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm, function(matchFound, m1) { return hashBlock("<h2>" + _RunSpanGamut(m1) + "</h2>"); }); // atx-style headers: // # Header 1 // ## Header 2 // ## Header 2 with closing hashes ## // ... // ###### Header 6 // /* text = text.replace(/ ^(\#{1,6}) // $1 = string of #'s [ \t]* (.+?) // $2 = Header text [ \t]* \#* // optional closing #'s (not counted) \n+ /gm, function() {...}); */ text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm, function(wholeMatch, m1, m2) { var h_level = m1.length; return hashBlock("<h" + h_level + ">" + _RunSpanGamut(m2) + "</h" + h_level + ">"); }); return text; }; // This declaration keeps Dojo compressor from outputting garbage: var _ProcessListItems; // // Form HTML ordered (numbered) and unordered (bulleted) lists. // var _DoLists = function(text) { // attacklab: add sentinel to hack around khtml/safari bug: // http://bugs.webkit.org/show_bug.cgi?id=11231 text += "~0"; // Re-usable pattern to match any entirel ul or ol list: /* var whole_list = / ( // $1 = whole list ( // $2 [ ]{0,3} // attacklab: g_tab_width - 1 ([*+-]|\d+[.]) // $3 = first list item marker [ \t]+ ) [^\r]+? ( // $4 ~0 // sentinel for workaround; should be $ | \n{2,} (?=\S) (?! // Negative lookahead for another list item marker [ \t]* (?:[*+-]|\d+[.])[ \t]+ ) ) )/g */ var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm; if (g_list_level) { text = text.replace(whole_list, function(wholeMatch, m1, m2) { var list = m1; var list_type = (m2.search(/[*+-]/g) > -1) ? "ul" : "ol"; // Turn double returns into triple returns, so that we can make a // paragraph for the last item in a list, if necessary: list = list.replace(/\n{2,}/g, "\n\n\n"); var result = _ProcessListItems(list); // Trim any trailing whitespace, to put the closing `</$list_type>` // up on the preceding line, to get it past the current stupid // HTML block parser. This is a hack to work around the terrible // hack that is the HTML block parser. result = result.replace(/\s+$/, ""); result = "<" + list_type + ">" + result + "</" + list_type + ">\n"; return result; }); } else { whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g; text = text.replace(whole_list, function(wholeMatch, m1, m2, m3) { var runup = m1; var list = m2; var list_type = (m3.search(/[*+-]/g) > -1) ? "ul" : "ol"; // Turn double returns into triple returns, so that we can make a // paragraph for the last item in a list, if necessary: var list = list.replace(/\n{2,}/g, "\n\n\n"); var result = _ProcessListItems(list); result = runup + "<" + list_type + ">\n" + result + "</" + list_type + ">\n"; return result; }); } // attacklab: strip sentinel text = text.replace(/~0/, ""); return text; }; // // Process the contents of a single ordered or unordered list, splitting it // into individual list items. // _ProcessListItems = function(list_str) { // The $g_list_level global keeps track of when we're inside a list. // Each time we enter a list, we increment it; when we leave a list, // we decrement. If it's zero, we're not in a list anymore. // // We do this because when we're not inside a list, we want to treat // something like this: // // I recommend upgrading to version // 8. Oops, now this line is treated // as a sub-list. // // As a single paragraph, despite the fact that the second line starts // with a digit-period-space sequence. // // Whereas when we're inside a list (or sub-list), that line will be // treated as the start of a sub-list. What a kludge, huh? This is // an aspect of Markdown's syntax that's hard to parse perfectly // without resorting to mind-reading. Perhaps the solution is to // change the syntax rules such that sub-lists must start with a // starting cardinal number; e.g. "1." or "a.". g_list_level++; // trim trailing blank lines: list_str = list_str.replace(/\n{2,}$/, "\n"); // attacklab: add sentinel to emulate \z list_str += "~0"; /* list_str = list_str.replace(/ (\n)? // leading line = $1 (^[ \t]*) // leading whitespace = $2 ([*+-]|\d+[.]) [ \t]+ // list marker = $3 ([^\r]+? // list item text = $4 (\n{1,2})) (?= \n* (~0 | \2 ([*+-]|\d+[.]) [ \t]+)) /gm, function(){...}); */ list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm, function(wholeMatch, m1, m2, m3, m4) { var item = m4; var leading_line = m1; var leading_space = m2; if (leading_line || (item.search(/\n{2,}/) > -1)) { item = _RunBlockGamut(_Outdent(item)); } else { // Recursion for sub-lists: item = _DoLists(_Outdent(item)); item = item.replace(/\n$/, ""); // chomp(item) item = _RunSpanGamut(item); } return "<li>" + item + "</li>\n"; } ); // attacklab: strip sentinel list_str = list_str.replace(/~0/g, ""); g_list_level--; return list_str; }; // // Process Markdown `<pre><code>` blocks. // var _DoCodeBlocks = function(text) { /* text = text.replace(text, /(?:\n\n|^) ( // $1 = the code block -- one or more lines, starting with a space/tab (?: (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width .*\n+ )+ ) (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width /g,function(){...}); */ // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug text += "~0"; text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g, function(wholeMatch, m1, m2) { var codeblock = m1; var nextChar = m2; codeblock = _EncodeCode(_Outdent(codeblock)); codeblock = _Detab(codeblock); codeblock = codeblock.replace(/^\n+/g, ""); // trim leading newlines codeblock = codeblock.replace(/\n+$/g, ""); // trim trailing whitespace codeblock = "<pre><code>" + codeblock + "\n</code></pre>"; return hashBlock(codeblock) + nextChar; }); // attacklab: strip sentinel text = text.replace(/~0/, ""); return text; }; var hashBlock = function(text) { text = text.replace(/(^\n+|\n+$)/g, ""); return "\n\n~K" + (g_html_blocks.push(text) - 1) + "K\n\n"; }; // // * Backtick quotes are used for <code></code> spans. // // * You can use multiple backticks as the delimiters if you want to // include literal backticks in the code span. So, this input: // // Just type ``foo `bar` baz`` at the prompt. // // Will translate to: // // <p>Just type <code>foo `bar` baz</code> at the prompt.</p> // // There's no arbitrary limit to the number of backticks you // can use as delimters. If you need three consecutive backticks // in your code, use four for delimiters, etc. // // * You can use spaces to get literal backticks at the edges: // // ... type `` `bar` `` ... // // Turns to: // // ... type <code>`bar`</code> ... // var _DoCodeSpans = function(text) { /* text = text.replace(/ (^|[^\\]) // Character before opening ` can't be a backslash (`+) // $2 = Opening run of ` ( // $3 = The code block [^\r]*? [^`] // attacklab: work around lack of lookbehind ) \2 // Matching closer (?!`) /gm, function(){...}); */ text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm, function(wholeMatch, m1, m2, m3, m4) { var c = m3; c = c.replace(/^([ \t]*)/g, ""); // leading whitespace c = c.replace(/[ \t]*$/g, ""); // trailing whitespace c = _EncodeCode(c); return m1 + "<code>" + c + "</code>"; }); return text; }; // // Encode/escape certain characters inside Markdown code runs. // The point is that in code, these characters are literals, // and lose their special Markdown meanings. // var _EncodeCode = function(text) { // Encode all ampersands; HTML entities are not // entities within a Markdown code span. text = text.replace(/&/g, "&"); // Do the angle bracket song and dance: text = text.replace(/</g, "<"); text = text.replace(/>/g, ">"); // Now, escape characters that are magic in Markdown: text = escapeCharacters(text, "\*_{}[]\\", false); return text; }; var _DoItalicsAndBold = function(text) { // <strong> must go first: text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, "<strong>$2</strong>"); text = text.replace(/(\w)_(\w)/g, "$1~E95E$2"); // ** GFM ** "~E95E" == escaped "_" text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, "<em>$2</em>"); return text; }; var _DoBlockQuotes = function(text) { /* text = text.replace(/ ( // Wrap whole match in $1 ( ^[ \t]*>[ \t]? // '>' at the start of a line .+\n // rest of the first line (.+\n)* // subsequent consecutive lines \n* // blanks )+ ) /gm, function(){...}); */ text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm, function(wholeMatch, m1) { var bq = m1; // attacklab: hack around Konqueror 3.5.4 bug: // "----------bug".replace(/^-/g,"") == "bug" bq = bq.replace(/^[ \t]*>[ \t]?/gm, "~0"); // trim one level of quoting // attacklab: clean up hack bq = bq.replace(/~0/g, ""); bq = bq.replace(/^[ \t]+$/gm, ""); // trim whitespace-only lines bq = _RunBlockGamut(bq); // recurse bq = bq.replace(/(^|\n)/g, "$1 "); // These leading spaces screw with <pre> content, so we need to fix that: bq = bq.replace( /(\s*<pre>[^\r]+?<\/pre>)/gm, function(wholeMatch, m1) { var pre = m1; // attacklab: hack around Konqueror 3.5.4 bug: pre = pre.replace(/^ /mg, "~0"); pre = pre.replace(/~0/g, ""); return pre; }); return hashBlock("<blockquote>\n" + bq + "\n</blockquote>"); }); return text; }; // // Params: // $text - string to process with html <p> tags // var _FormParagraphs = function(text) { // Strip leading and trailing lines: text = text.replace(/^\n+/g, ""); text = text.replace(/\n+$/g, ""); var grafs = text.split(/\n{2,}/g); var grafsOut = new Array(); // // Wrap <p> tags. // var end = grafs.length; for (var i = 0; i < end; i++) { var str = grafs[i]; // if this is an HTML marker, copy it if (str.search(/~K(\d+)K/g) >= 0) { grafsOut.push(str); } else if (str.search(/\S/) >= 0) { str = _RunSpanGamut(str); str = str.replace(/\n/g, "<br />"); // ** GFM ** str = str.replace(/^([ \t]*)/g, "<p>"); str += "</p>"; grafsOut.push(str); } } // // Unhashify HTML blocks // end = grafsOut.length; for (var i = 0; i < end; i++) { // if this is a marker for an html block... while (grafsOut[i].search(/~K(\d+)K/) >= 0) { var blockText = g_html_blocks[RegExp.$1]; blockText = blockText.replace(/\$/g, "$$$$"); // Escape any dollar signs grafsOut[i] = grafsOut[i].replace(/~K\d+K/, blockText); } } return grafsOut.join("\n\n"); }; // Smart processing for ampersands and angle brackets that need to be encoded. var _EncodeAmpsAndAngles = function(text) { // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: // http://bumppo.net/projects/amputator/ text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, "&"); // Encode naked <'s text = text.replace(/<(?![a-z\/?\$!])/gi, "<"); return text; }; // // Parameter: String. // Returns: The string, with after processing the following backslash // escape sequences. // var _EncodeBackslashEscapes = function(text) { // attacklab: The polite way to do this is with the new // escapeCharacters() function: // // text = escapeCharacters(text,"\\",true); // text = escapeCharacters(text,"`*_{}[]()>#+-.!",true); // // ...but we're sidestepping its use of the (slow) RegExp constructor // as an optimization for Firefox. This function gets called a LOT. text = text.replace(/\\(\\)/g, escapeCharacters_callback); text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, escapeCharacters_callback); return text; }; var _DoAutoLinks = function(text) { text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi, "<a href=\"$1\">$1</a>"); // Email addresses: <address@domain.foo> /* text = text.replace(/ < (?:mailto:)? ( [-.\w]+ \@ [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+ ) > /gi, _DoAutoLinks_callback()); */ text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi, function(wholeMatch, m1) { return _EncodeEmailAddress(_UnescapeSpecialChars(m1)); }); return text; }; // // Input: an email address, e.g. "foo@example.com" // // Output: the email address as a mailto link, with each character // of the address encoded as either a decimal or hex entity, in // the hopes of foiling most address harvesting spam bots. E.g.: // // <a href="mailto:foo@e // xample.com">foo // @example.com</a> // // Based on a filter by Matthew Wickline, posted to the BBEdit-Talk // mailing list: <http://tinyurl.com/yu7ue> // var _EncodeEmailAddress = function(addr) { // attacklab: why can't javascript speak hex? function char2hex(ch) { var hexDigits = '0123456789ABCDEF'; var dec = ch.charCodeAt(0); return(hexDigits.charAt(dec >> 4) + hexDigits.charAt(dec & 15)); } var encode = [ function(ch) { return "&#" + ch.charCodeAt(0) + ";" }, function(ch) { return "&#x" + char2hex(ch) + ";" }, function(ch) { return ch } ]; addr = "mailto:" + addr; addr = addr.replace(/./g, function(ch) { if (ch == "@") { // this *must* be encoded. I insist. ch = encode[Math.floor(Math.random() * 2)](ch); } else if (ch != ":") { // leave ':' alone (to spot mailto: later) var r = Math.random(); // roughly 10% raw, 45% hex, 45% dec ch = (r > .9 ? encode[2](ch) : r > .45 ? encode[1](ch) : encode[0](ch)); } return ch; }); addr = "<a href=\"" + addr + "\">" + addr + "</a>"; addr = addr.replace(/">.+:/g, "\">"); // strip the mailto: from the visible part return addr; }; // // Swap back in all the special characters we've hidden. // var _UnescapeSpecialChars = function(text) { text = text.replace(/~E(\d+)E/g, function(wholeMatch, m1) { var charCodeToReplace = parseInt(m1); return String.fromCharCode(charCodeToReplace); }); return text; }; // // Remove one level of line-leading tabs or spaces // var _Outdent = function(text) { // attacklab: hack around Konqueror 3.5.4 bug: // "----------bug".replace(/^-/g,"") == "bug" text = text.replace(/^(\t|[ ]{1,4})/gm, "~0"); // attacklab: g_tab_width // attacklab: clean up hack text = text.replace(/~0/g, ""); return text; }; // attacklab: Detab's completely rewritten for speed. // In perl we could fix it by anchoring the regexp with \G. // In javascript we're less fortunate. var _Detab = function(text) { // expand first n-1 tabs text = text.replace(/\t(?=\t)/g, " "); // attacklab: g_tab_width // replace the nth with two sentinels text = text.replace(/\t/g, "~A~B"); // use the sentinel to anchor our regex so it doesn't explode text = text.replace(/~B(.+?)~A/g, function(wholeMatch, m1, m2) { var leadingText = m1; var numSpaces = 4 - leadingText.length % 4; // attacklab: g_tab_width // there *must* be a better way to do this: for (var i = 0; i < numSpaces; i++) leadingText += " "; return leadingText; }); // clean up sentinels text = text.replace(/~A/g, " "); // attacklab: g_tab_width text = text.replace(/~B/g, ""); return text; }; // attacklab: Utility functions var escapeCharacters = function(text, charsToEscape, afterBackslash) { // First we have to escape the escape characters so that // we can build a character class out of them var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g, "\\$1") + "])"; if (afterBackslash) { regexString = "\\\\" + regexString; } var regex = new RegExp(regexString, "g"); text = text.replace(regex, escapeCharacters_callback); return text; }; var escapeCharacters_callback = function(wholeMatch, m1) { var charCodeToEscape = m1.charCodeAt(0); return "~E" + charCodeToEscape + "E"; }; }; (function() { var __slice = [].slice; this.Mercury || (this.Mercury = {}); jQuery.extend(this.Mercury, { version: '0.9.0', Regions: Mercury.Regions || {}, modalHandlers: Mercury.modalHandlers || {}, lightviewHandlers: Mercury.lightviewHandlers || {}, dialogHandlers: Mercury.dialogHandlers || {}, preloadedViews: Mercury.preloadedViews || {}, ajaxHeaders: function() { var headers; headers = {}; headers[Mercury.config.csrfHeader] = Mercury.csrfToken; return headers; }, on: function(eventName, callback) { return jQuery(window).on("mercury:" + eventName, callback); }, off: function(eventName, callback) { return jQuery(window).off("mercury:" + eventName, callback); }, one: function(eventName, callback) { return jQuery(window).one("mercury:" + eventName, callback); }, trigger: function(eventName, options) { Mercury.log(eventName, options); return jQuery(window).trigger("mercury:" + eventName, options); }, notify: function() { var args; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return window.alert(Mercury.I18n.apply(this, args)); }, warn: function(message, severity) { var e1, e2; if (severity == null) { severity = 0; } if (console) { try { return console.warn(message); } catch (_error) { e1 = _error; if (severity >= 1) { try { return console.debug(message); } catch (_error) { e2 = _error; } } } } else if (severity >= 1) { return Mercury.notify(message); } }, deprecated: function(message) { if (console && console.trace) { message = "" + message + " -- " + (console.trace()); } return Mercury.warn("deprecated: " + message, 1); }, log: function() { var e; if (Mercury.debug && console) { if (arguments[0] === 'hide:toolbar' || arguments[0] === 'show:toolbar') { return; } try { return console.debug(arguments); } catch (_error) { e = _error; } } }, locale: function() { var locale, subLocale, topLocale; if (Mercury.determinedLocale) { return Mercury.determinedLocale; } if (Mercury.config.localization.enabled) { debugger; locale = []; if (navigator.language && (locale = navigator.language.toString().split('-')).length) { topLocale = Mercury.I18n[locale[0]] || {}; subLocale = locale.length > 1 ? topLocale["_" + (locale[1].toUpperCase()) + "_"] : void 0; } if (!Mercury.I18n[locale[0]]) { locale = Mercury.config.localization.preferredLocale.split('-'); topLocale = Mercury.I18n[locale[0]] || {}; subLocale = locale.length > 1 ? topLocale["_" + (locale[1].toUpperCase()) + "_"] : void 0; } } return Mercury.determinedLocale = { top: topLocale || {}, sub: subLocale || {} }; }, I18n: function() { var args, locale, sourceString, translation; sourceString = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; locale = Mercury.locale(); translation = (locale.sub[sourceString] || locale.top[sourceString] || sourceString || '').toString(); if (args.length) { return translation.printf.apply(translation, args); } else { return translation; } } }); }).call(this); (function() { String.prototype.titleize = function() { return this[0].toUpperCase() + this.slice(1); }; String.prototype.toHex = function() { if (this[0] === '#') { return this; } return this.replace(/rgb(a)?\(([0-9|%]+)[\s|,]?\s?([0-9|%]+)[\s|,]?\s?([0-9|%]+)[\s|,]?\s?([0-9|.|%]+\s?)?\)/gi, function(x, alpha, r, g, b, a) { return "#" + (parseInt(r).toHex()) + (parseInt(g).toHex()) + (parseInt(b).toHex()); }); }; String.prototype.regExpEscape = function() { var escaped, specials; specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; escaped = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); return this.replace(escaped, '\\$1'); }; String.prototype.printf = function() { var arg, chunk, chunks, index, offset, p, re, result, _i, _len; chunks = this.split('%'); result = chunks[0]; re = /^([sdf])([\s\S%]*)$/; offset = 0; for (index = _i = 0, _len = chunks.length; _i < _len; index = ++_i) { chunk = chunks[index]; p = re.exec(chunk); if (index === 0 || !p || arguments[index] === null) { if (index > 1) { offset += 2; result += "%" + chunk; } continue; } arg = arguments[(index - 1) - offset]; switch (p[1]) { case 's': result += arg; break; case 'd': case 'i': result += parseInt(arg.toString(), 10); break; case 'f': result += parseFloat(arg); } result += p[2]; } return result; }; Number.prototype.toHex = function() { var result; result = this.toString(16).toUpperCase(); if (result[1]) { return result; } else { return "0" + result; } }; Number.prototype.toBytes = function() { var bytes, i; bytes = parseInt(this); i = 0; while (1023 < bytes) { bytes /= 1024; i += 1; } if (i) { return "" + (bytes.toFixed(2)) + ['', ' kb', ' Mb', ' Gb', ' Tb', ' Pb', ' Eb'][i]; } else { return "" + bytes + " bytes"; } }; }).call(this); (function() { this.Mercury.PageEditor = (function() { function PageEditor(saveUrl, options) { var token; this.saveUrl = saveUrl != null ? saveUrl : null; this.options = options != null ? options : {}; if (window.mercuryInstance) { throw Mercury.I18n('Mercury.PageEditor can only be instantiated once.'); } if (!(this.options.visible === false || this.options.visible === 'false')) { this.options.visible = true; } this.visible = this.options.visible; if (!(this.options.saveDataType === false || this.options.saveDataType)) { this.options.saveDataType = 'json'; } window.mercuryInstance = this; this.regions = []; this.initializeInterface(); if (token = jQuery(Mercury.config.csrfSelector).attr('content')) { Mercury.csrfToken = token; } } PageEditor.prototype.initializeInterface = function() { var _ref, _ref1, _this = this; this.focusableElement = jQuery('<input>', { "class": 'mercury-focusable', type: 'text' }).appendTo((_ref = this.options.appendTo) != null ? _ref : 'body'); this.iframe = jQuery('<iframe>', { id: 'mercury_iframe', name: 'mercury_iframe', "class": 'mercury-iframe', frameborder: '0', src: 'about:blank' }); this.iframe.appendTo((_ref1 = jQuery(this.options.appendTo).get(0)) != null ? _ref1 : 'body'); this.toolbar = new Mercury.Toolbar(jQuery.extend(true, {}, this.options, this.options.toolbarOptions)); this.statusbar = new Mercury.Statusbar(jQuery.extend(true, {}, this.options, this.options.statusbarOptions)); this.resize(); this.iframe.one('load', function() { return _this.bindEvents(); }); this.iframe.on('load', function() { return _this.initializeFrame(); }); return this.loadIframeSrc(null); }; PageEditor.prototype.initializeFrame = function() { var error, iframeWindow; try { if (this.iframe.data('loaded')) { return; } this.iframe.data('loaded', true); this.document = jQuery(this.iframe.get(0).contentWindow.document); jQuery("<style mercury-styles=\"true\">").html(Mercury.config.injectedStyles).appendTo(this.document.find('head')); iframeWindow = this.iframe.get(0).contentWindow; jQuery.globalEval = function(data) { if (data && /\S/.test(data)) { return (iframeWindow.execScript || function(data) { return iframeWindow["eval"].call(iframeWindow, data); })(data); } }; iframeWindow.Mercury = Mercury; if (window.History && History.Adapter) { iframeWindow.History = History; } this.bindDocumentEvents(); this.resize(); this.initializeRegions(); this.finalizeInterface(); Mercury.trigger('ready'); if (iframeWindow.jQuery) { iframeWindow.jQuery(iframeWindow).trigger('mercury:ready'); } if (iframeWindow.Event && iframeWindow.Event.fire) { iframeWindow.Event.fire(iframeWindow, 'mercury:ready'); } if (iframeWindow.onMercuryReady) { iframeWindow.onMercuryReady(); } return this.iframe.css({ visibility: 'visible' }); } catch (_error) { error = _error; return Mercury.notify('Mercury.PageEditor failed to load: %s\n\nPlease try refreshing.', error); } }; PageEditor.prototype.initializeRegions = function() { var region, _i, _j, _len, _len1, _ref, _ref1, _results; this.regions = []; _ref = jQuery("[" + Mercury.config.regions.attribute + "]", this.document); for (_i = 0, _len = _ref.length; _i < _len; _i++) { region = _ref[_i]; this.buildRegion(jQuery(region)); } if (!this.visible) { return; } _ref1 = this.regions; _results = []; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { region = _ref1[_j]; if (region.focus) { region.focus(); break; } else { _results.push(void 0); } } return _results; }; PageEditor.prototype.buildRegion = function(region) { var type, _base; if (region.data('region')) { region = region.data('region'); } else { type = (region.attr(Mercury.config.regions.attribute) || (typeof (_base = Mercury.config.regions).determineType === "function" ? _base.determineType(region) : void 0) || 'unknown').titleize(); if (type === 'Unknown' || !Mercury.Regions[type]) { throw Mercury.I18n('Region type is malformed, no data-type provided, or "%s" is unknown for the "%s" region.', type, region.attr('id') || 'unknown'); } if (!Mercury.Regions[type].supported) { Mercury.notify('Mercury.Regions.%s is unsupported in this client. Supported browsers are %s.', type, Mercury.Regions[type].supportedText); return false; } region = new Mercury.Regions[type](region, this.iframe.get(0).contentWindow); if (this.previewing) { region.togglePreview(); } } return this.regions.push(region); }; PageEditor.prototype.finalizeInterface = function() { var _ref; this.santizerElement = jQuery('<div>', { id: 'mercury_sanitizer', contenteditable: 'true', style: 'position:fixed;width:100px;height:100px;min-width:0;top:0;left:-100px;opacity:0;overflow:hidden' }); this.santizerElement.appendTo((_ref = this.options.appendTo) != null ? _ref : this.document.find('body')); if (this.snippetToolbar) { this.snippetToolbar.release(); } this.snippetToolbar = new Mercury.SnippetToolbar(this.document); this.hijackLinksAndForms(); if (!this.visible) { return Mercury.trigger('mode', { mode: 'preview' }); } }; PageEditor.prototype.bindDocumentEvents = function() { var _this = this; this.document.on('mousedown', function(event) { Mercury.trigger('hide:dialogs'); if (Mercury.region) { if (jQuery(event.target).closest("[" + Mercury.config.regions.attribute + "]").get(0) !== Mercury.region.element.get(0)) { return Mercury.trigger('unfocus:regions'); } } }); return jQuery(this.document).bind('keydown', function(event) { if (!(event.ctrlKey || event.metaKey)) { return; } if (event.keyCode === 83) { Mercury.trigger('action', { action: 'save' }); return event.preventDefault(); } }); }; PageEditor.prototype.bindEvents = function() { var _this = this; Mercury.on('initialize:frame', function() { return setTimeout(_this.initializeFrame, 100); }); Mercury.on('focus:frame', function() { return _this.iframe.focus(); }); Mercury.on('focus:window', function() { return setTimeout((function() { return _this.focusableElement.focus(); }), 10); }); Mercury.on('toggle:interface', function() { return _this.toggleInterface(); }); Mercury.on('reinitialize', function() { return _this.initializeRegions(); }); Mercury.on('mode', function(event, options) { if (options.mode === 'preview') { return _this.previewing = !_this.previewing; } }); Mercury.on('action', function(event, options) { var action; action = Mercury.config.globalBehaviors[options.action] || _this[options.action]; if (typeof action !== 'function') { return; } event.preventDefault(); return action.call(_this, options); }); jQuery(window).on('resize', function() { return _this.resize(); }); jQuery(window).bind('keydown', function(event) { if (!(event.ctrlKey || event.metaKey)) { return; } if (event.keyCode === 83) { Mercury.trigger('action', { action: 'save' }); return event.preventDefault(); } }); return window.onbeforeunload = this.beforeUnload; }; PageEditor.prototype.toggleInterface = function() { var _this = this; if (this.visible) { this.visible = false; this.toolbar.hide(); this.statusbar.hide(); if (!this.previewing) { Mercury.trigger('mode', { mode: 'preview' }); } this.previewing = true; return this.resize(); } else { this.visible = true; this.iframe.animate({ top: this.toolbar.height(true) }, 200, 'easeInOutSine', function() { return _this.resize(); }); this.toolbar.show(); this.statusbar.show(); Mercury.trigger('mode', { mode: 'preview' }); return this.previewing = false; } }; PageEditor.prototype.resize = function() { var height, toolbarHeight, width; width = jQuery(window).width(); height = this.statusbar.top(); toolbarHeight = this.toolbar.top() + this.toolbar.height(); Mercury.displayRect = { top: toolbarHeight, left: 0, width: width, height: height - toolbarHeight, fullHeight: height }; this.iframe.css({ top: toolbarHeight, left: 0, height: height - toolbarHeight }); return Mercury.trigger('resize'); }; PageEditor.prototype.iframeSrc = function(url, params) { var _base; if (url == null) { url = null; } if (params == null) { params = false; } url = (url != null ? url : window.location.href).replace((_base = Mercury.config).editorUrlRegEx != null ? (_base = Mercury.config).editorUrlRegEx : _base.editorUrlRegEx = /([http|https]:\/\/.[^\/]*)\/editor\/?(.*)/i, "$1/$2"); url = url.replace(/[\?|\&]mercury_frame=true/gi, '').replace(/\&_=\d+/gi, '').replace(/#$/, ''); if (params) { return "" + url + (url.indexOf('?') > -1 ? '&' : '?') + "mercury_frame=true&_=" + (new Date().getTime()); } else { return url; } }; PageEditor.prototype.loadIframeSrc = function(url) { if (this.document) { this.document.off(); } this.iframe.data('loaded', false); return this.iframe.get(0).contentWindow.document.location.href = this.iframeSrc(url, true); }; PageEditor.prototype.hijackLinksAndForms = function() { var classname, element, ignored, _i, _j, _len, _len1, _ref, _ref1, _results; _ref = jQuery('a, form', this.document); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { element = _ref[_i]; ignored = false; _ref1 = Mercury.config.nonHijackableClasses || []; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { classname = _ref1[_j]; if (jQuery(element).hasClass(classname)) { ignored = true; continue; } } if (!ignored && (element.target === '' || element.target === '_self') && !jQuery(element).closest("[" + Mercury.config.regions.attribute + "]").length) { _results.push(jQuery(element).attr('target', '_parent')); } else { _results.push(void 0); } } return _results; }; PageEditor.prototype.beforeUnload = function() { if (Mercury.changes && !Mercury.silent) { return Mercury.I18n('You have unsaved changes. Are you sure you want to leave without saving them first?'); } return null; }; PageEditor.prototype.getRegionByName = function(id) { var region, _i, _len, _ref; _ref = this.regions; for (_i = 0, _len = _ref.length; _i < _len; _i++) { region = _ref[_i]; if (region.name === id) { return region; } } return null; }; PageEditor.prototype.save = function(callback) { var data, method, options, url, _ref, _ref1, _this = this; url = (_ref = (_ref1 = this.saveUrl) != null ? _ref1 : Mercury.saveUrl) != null ? _ref : this.iframeSrc(); data = this.serialize(); data = { content: data }; if (this.options.saveMethod === 'POST') { method = 'POST'; } else { method = 'PUT'; data['_method'] = method; } Mercury.log('saving', data); options = { headers: Mercury.ajaxHeaders(), type: method, dataType: this.options.saveDataType, data: data, success: function(response) { Mercury.changes = false; Mercury.trigger('saved', response); if (typeof callback === 'function') { return callback(); } }, error: function(response) { Mercury.trigger('save_failed', response); return Mercury.notify('Mercury was unable to save to the url: %s', url); } }; if (this.options.saveStyle !== 'form') { options['data'] = jQuery.toJSON(data); options['contentType'] = 'application/json'; } return jQuery.ajax(url, options); }; PageEditor.prototype.serialize = function() { var region, serialized, _i, _len, _ref; serialized = {}; _ref = this.regions; for (_i = 0, _len = _ref.length; _i < _len; _i++) { region = _ref[_i]; serialized[region.name] = region.serialize(); } return serialized; }; return PageEditor; })(); }).call(this); (function() { this.Mercury.HistoryBuffer = (function() { function HistoryBuffer(maxLength) { this.maxLength = maxLength != null ? maxLength : 200; this.index = 0; this.stack = []; this.markerRegExp = /<em class="mercury-marker"><\/em>/g; } HistoryBuffer.prototype.push = function(item) { if (jQuery.type(item) === 'string') { if (this.stack[this.index] && this.stack[this.index].replace(this.markerRegExp, '') === item.replace(this.markerRegExp, '')) { return; } } else if (jQuery.type(item) === 'object' && item.html) { if (this.stack[this.index] && this.stack[this.index].html === item.html) { return; } } this.stack = this.stack.slice(0, this.index + 1); this.stack.push(item); if (this.stack.length > this.maxLength) { this.stack.shift(); } return this.index = this.stack.length - 1; }; HistoryBuffer.prototype.undo = function() { if (this.index < 1) { return null; } this.index -= 1; return this.stack[this.index]; }; HistoryBuffer.prototype.redo = function() { if (this.index >= this.stack.length - 1) { return null; } this.index += 1; return this.stack[this.index]; }; return HistoryBuffer; })(); }).call(this); (function() { this.Mercury.tableEditor = function(table, cell, cellContent) { Mercury.tableEditor.load(table, cell, cellContent); return Mercury.tableEditor; }; jQuery.extend(Mercury.tableEditor, { load: function(table, cell, cellContent) { this.table = table; this.cell = cell; this.cellContent = cellContent != null ? cellContent : ''; this.row = this.cell.parent('tr'); this.columnCount = this.getColumnCount(); return this.rowCount = this.getRowCount(); }, addColumnBefore: function() { return this.addColumn('before'); }, addColumnAfter: function() { return this.addColumn('after'); }, addColumn: function(position) { var i, intersecting, matchOptions, matching, newCell, row, rowSpan, sig, _i, _len, _ref, _results; if (position == null) { position = 'after'; } sig = this.cellSignatureFor(this.cell); _ref = this.table.find('tr'); _results = []; for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { row = _ref[i]; rowSpan = 1; matchOptions = position === 'after' ? { right: sig.right } : { left: sig.left }; if (matching = this.findCellByOptionsFor(row, matchOptions)) { newCell = jQuery("<" + (matching.cell.get(0).tagName) + ">").html(this.cellContent); this.setRowspanFor(newCell, matching.height); if (position === 'before') { matching.cell.before(newCell); } else { matching.cell.after(newCell); } _results.push(i += matching.height - 1); } else if (intersecting = this.findCellByIntersectionFor(row, sig)) { _results.push(this.setColspanFor(intersecting.cell, intersecting.width + 1)); } else { _results.push(void 0); } } return _results; }, removeColumn: function() { var adjusting, cell, i, intersecting, matching, removing, row, sig, _i, _j, _k, _len, _len1, _len2, _ref, _results; sig = this.cellSignatureFor(this.cell); if (sig.width > 1) { return; } removing = []; adjusting = []; _ref = this.table.find('tr'); for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { row = _ref[i]; if (matching = this.findCellByOptionsFor(row, { left: sig.left, width: sig.width })) { removing.push(matching.cell); i += matching.height - 1; } else if (intersecting = this.findCellByIntersectionFor(row, sig)) { adjusting.push(intersecting.cell); } } for (_j = 0, _len1 = removing.length; _j < _len1; _j++) { cell = removing[_j]; jQuery(cell).remove(); } _results = []; for (_k = 0, _len2 = adjusting.length; _k < _len2; _k++) { cell = adjusting[_k]; _results.push(this.setColspanFor(cell, this.colspanFor(cell) - 1)); } return _results; }, addRowBefore: function() { return this.addRow('before'); }, addRowAfter: function() { return this.addRow('after'); }, addRow: function(position) { var cell, cellCount, colspan, newCell, newRow, previousRow, rowCount, rowspan, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; if (position == null) { position = 'after'; } newRow = jQuery('<tr>'); if ((rowspan = this.rowspanFor(this.cell)) > 1 && position === 'after') { this.row = jQuery(this.row.nextAll('tr')[rowspan - 2]); } cellCount = 0; _ref = this.row.find('th, td'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { cell = _ref[_i]; colspan = this.colspanFor(cell); newCell = jQuery("<" + cell.tagName + ">").html(this.cellContent); this.setColspanFor(newCell, colspan); cellCount += colspan; if ((rowspan = this.rowspanFor(cell)) > 1 && position === 'after') { this.setRowspanFor(cell, rowspan + 1); continue; } newRow.append(newCell); } if (cellCount < this.columnCount) { rowCount = 0; _ref1 = this.row.prevAll('tr'); for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { previousRow = _ref1[_j]; rowCount += 1; _ref2 = jQuery(previousRow).find('td[rowspan], th[rowspan]'); for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { cell = _ref2[_k]; rowspan = this.rowspanFor(cell); if (rowspan - 1 >= rowCount && position === 'before') { this.setRowspanFor(cell, rowspan + 1); } else if (rowspan - 1 >= rowCount && position === 'after') { if (rowspan - 1 === rowCount) { newCell = jQuery("<" + cell.tagName + ">").html(this.cellContent); this.setColspanFor(newCell, this.colspanFor(cell)); newRow.append(newCell); } else { this.setRowspanFor(cell, rowspan + 1); } } } } } if (position === 'before') { return this.row.before(newRow); } else { return this.row.after(newRow); } }, removeRow: function() { var aboveRow, cell, i, match, minRowspan, prevRowspan, rowsAbove, rowspan, rowspansMatch, sig, _i, _j, _k, _l, _len, _len1, _len2, _len3, _m, _ref, _ref1, _ref2, _ref3, _ref4; rowspansMatch = true; prevRowspan = 0; minRowspan = 0; _ref = this.row.find('td, th'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { cell = _ref[_i]; rowspan = this.rowspanFor(cell); if (prevRowspan && rowspan !== prevRowspan) { rowspansMatch = false; } if (rowspan < minRowspan || !minRowspan) { minRowspan = rowspan; } prevRowspan = rowspan; } if (!rowspansMatch && this.rowspanFor(this.cell) > minRowspan) { return; } if (minRowspan > 1) { for (i = _j = 0, _ref1 = minRowspan - 2; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) { jQuery(this.row.nextAll('tr')[i]).remove(); } } _ref2 = this.row.find('td[rowspan], th[rowspan]'); for (_k = 0, _len1 = _ref2.length; _k < _len1; _k++) { cell = _ref2[_k]; sig = this.cellSignatureFor(cell); if (sig.height === minRowspan) { continue; } if (match = this.findCellByOptionsFor(this.row.nextAll('tr')[minRowspan - 1], { left: sig.left, forceAdjacent: true })) { this.setRowspanFor(cell, this.rowspanFor(cell) - this.rowspanFor(this.cell)); if (match.direction === 'before') { match.cell.before(jQuery(cell).clone()); } else { match.cell.after(jQuery(cell).clone()); } } } if (this.columnsFor(this.row.find('td, th')) < this.columnCount) { rowsAbove = 0; _ref3 = this.row.prevAll('tr'); for (_l = 0, _len2 = _ref3.length; _l < _len2; _l++) { aboveRow = _ref3[_l]; rowsAbove += 1; _ref4 = jQuery(aboveRow).find('td[rowspan], th[rowspan]'); for (_m = 0, _len3 = _ref4.length; _m < _len3; _m++) { cell = _ref4[_m]; rowspan = this.rowspanFor(cell); if (rowspan > rowsAbove) { this.setRowspanFor(cell, rowspan - this.rowspanFor(this.cell)); } } } } return this.row.remove(); }, increaseColspan: function() { var cell; cell = this.cell.next('td, th'); if (!cell.length) { return; } if (this.rowspanFor(cell) !== this.rowspanFor(this.cell)) { return; } if (this.cellIndexFor(cell) > this.cellIndexFor(this.cell) + this.colspanFor(this.cell)) { return; } this.setColspanFor(this.cell, this.colspanFor(this.cell) + this.colspanFor(cell)); return cell.remove(); }, decreaseColspan: function() { var newCell; if (this.colspanFor(this.cell) === 1) { return; } this.setColspanFor(this.cell, this.colspanFor(this.cell) - 1); newCell = jQuery("<" + (this.cell.get(0).tagName) + ">").html(this.cellContent); this.setRowspanFor(newCell, this.rowspanFor(this.cell)); return this.cell.after(newCell); }, increaseRowspan: function() { var match, nextRow, sig; sig = this.cellSignatureFor(this.cell); nextRow = this.row.nextAll('tr')[sig.height - 1]; if (nextRow && (match = this.findCellByOptionsFor(nextRow, { left: sig.left, width: sig.width }))) { this.setRowspanFor(this.cell, sig.height + match.height); return match.cell.remove(); } }, decreaseRowspan: function() { var match, newCell, nextRow, sig; sig = this.cellSignatureFor(this.cell); if (sig.height === 1) { return; } nextRow = this.row.nextAll('tr')[sig.height - 2]; if (match = this.findCellByOptionsFor(nextRow, { left: sig.left, forceAdjacent: true })) { newCell = jQuery("<" + (this.cell.get(0).tagName) + ">").html(this.cellContent); this.setColspanFor(newCell, this.colspanFor(this.cell)); this.setRowspanFor(this.cell, sig.height - 1); if (match.direction === 'before') { return match.cell.before(newCell); } else { return match.cell.after(newCell); } } }, getColumnCount: function() { return this.columnsFor(this.table.find('thead tr:first-child, tbody tr:first-child, tfoot tr:first-child').first().find('td, th')); }, getRowCount: function() { return this.table.find('tr').length; }, cellIndexFor: function(cell) { var aboveCell, aboveRow, columns, index, row, rowsAbove, _i, _j, _len, _len1, _ref, _ref1; cell = jQuery(cell); row = cell.parent('tr'); columns = this.columnsFor(row.find('td, th')); index = this.columnsFor(cell.prevAll('td, th')); if (columns < this.columnCount) { rowsAbove = 0; _ref = row.prevAll('tr'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { aboveRow = _ref[_i]; rowsAbove += 1; _ref1 = jQuery(aboveRow).find('td[rowspan], th[rowspan]'); for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { aboveCell = _ref1[_j]; if (this.rowspanFor(aboveCell) > rowsAbove && this.cellIndexFor(aboveCell) <= index) { index += this.colspanFor(aboveCell); } } } } return index; }, cellSignatureFor: function(cell) { var sig; sig = { cell: jQuery(cell) }; sig.left = this.cellIndexFor(cell); sig.width = this.colspanFor(cell); sig.height = this.rowspanFor(cell); sig.right = sig.left + sig.width; return sig; }, findCellByOptionsFor: function(row, options) { var cell, prev, sig, _i, _len, _ref; _ref = jQuery(row).find('td, th'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { cell = _ref[_i]; sig = this.cellSignatureFor(cell); if (typeof options.right !== 'undefined') { if (sig.right === options.right) { return sig; } } if (typeof options.left !== 'undefined') { if (options.width) { if (sig.left === options.left && sig.width === options.width) { return sig; } } else if (!options.forceAdjacent) { if (sig.left === options.left) { return sig; } } else if (options.forceAdjacent) { if (sig.left > options.left) { prev = jQuery(cell).prev('td, th'); if (prev.length) { sig = this.cellSignatureFor(prev); sig.direction = 'after'; } else { sig.direction = 'before'; } return sig; } } } } if (options.forceAdjacent) { sig.direction = 'after'; return sig; } return null; }, findCellByIntersectionFor: function(row, signature) { var cell, sig, _i, _len, _ref; _ref = jQuery(row).find('td, th'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { cell = _ref[_i]; sig = this.cellSignatureFor(cell); if (sig.right - signature.left >= 0 && sig.right > signature.left) { return sig; } } return null; }, columnsFor: function(cells) { var cell, count, _i, _len; count = 0; for (_i = 0, _len = cells.length; _i < _len; _i++) { cell = cells[_i]; count += this.colspanFor(cell); } return count; }, colspanFor: function(cell) { return parseInt(jQuery(cell).attr('colspan')) || 1; }, rowspanFor: function(cell) { return parseInt(jQuery(cell).attr('rowspan')) || 1; }, setColspanFor: function(cell, value) { return jQuery(cell).attr('colspan', value > 1 ? value : null); }, setRowspanFor: function(cell, value) { return jQuery(cell).attr('rowspan', value > 1 ? value : null); } }); }).call(this); (function() { this.Mercury.Dialog = (function() { function Dialog(url, name, options) { this.url = url; this.name = name; this.options = options != null ? options : {}; this.button = this.options["for"]; this.build(); this.bindEvents(); this.preload(); } Dialog.prototype.build = function() { var _ref; this.element = jQuery('<div>', { "class": "mercury-dialog mercury-" + this.name + "-dialog loading", style: 'display:none' }); return this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); }; Dialog.prototype.bindEvents = function() { return this.element.on('mousedown', function(event) { return event.stopPropagation(); }); }; Dialog.prototype.preload = function() { if (this.options.preload) { return this.load(); } }; Dialog.prototype.toggle = function() { if (this.visible) { return this.hide(); } else { return this.show(); } }; Dialog.prototype.resize = function() { return this.show(); }; Dialog.prototype.show = function() { Mercury.trigger('hide:dialogs', this); this.visible = true; if (this.loaded) { this.element.css({ width: 'auto', height: 'auto' }); this.position(this.visible); } else { this.position(); } return this.appear(); }; Dialog.prototype.position = function(keepVisible) {}; Dialog.prototype.appear = function() { var _this = this; this.element.css({ display: 'block', opacity: 0 }); return this.element.animate({ opacity: 0.95 }, 200, 'easeInOutSine', function() { if (!_this.loaded) { return _this.load(function() { return _this.resize(); }); } }); }; Dialog.prototype.hide = function() { this.element.hide(); return this.visible = false; }; Dialog.prototype.load = function(callback) { var _this = this; if (!this.url) { return; } if (Mercury.preloadedViews[this.url]) { this.loadContent(Mercury.preloadedViews[this.url]); if (Mercury.dialogHandlers[this.name]) { Mercury.dialogHandlers[this.name].call(this); } if (callback) { return callback(); } } else { return jQuery.ajax(this.url, { success: function(data) { _this.loadContent(data); if (Mercury.dialogHandlers[_this.name]) { Mercury.dialogHandlers[_this.name].call(_this); } if (callback) { return callback(); } }, error: function() { _this.hide(); if (_this.button) { _this.button.removeClass('pressed'); } return Mercury.notify('Mercury was unable to load %s for the "%s" dialog.', _this.url, _this.name); } }); } }; Dialog.prototype.loadContent = function(data) { this.loaded = true; this.element.removeClass('loading'); this.element.html(data); if (Mercury.config.localization.enabled) { return this.element.localize(Mercury.locale()); } }; return Dialog; })(); }).call(this); (function() { var __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; }; this.Mercury.Palette = (function(_super) { __extends(Palette, _super); function Palette(url, name, options) { this.url = url; this.name = name; this.options = options != null ? options : {}; Palette.__super__.constructor.apply(this, arguments); } Palette.prototype.build = function() { var _ref; this.element = jQuery('<div>', { "class": "mercury-palette mercury-" + this.name + "-palette loading", style: 'display:none' }); return this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); }; Palette.prototype.bindEvents = function() { var _this = this; Mercury.on('hide:dialogs', function(event, dialog) { if (dialog !== _this) { return _this.hide(); } }); return Palette.__super__.bindEvents.apply(this, arguments); }; Palette.prototype.position = function(keepVisible) { var position, width; this.element.css({ top: 0, left: 0, display: 'block', visibility: 'hidden' }); position = this.button.position(); width = this.element.width(); if (position.left + width > jQuery(window).width()) { position.left = position.left - width + this.button.width(); } return this.element.css({ top: position.top + this.button.height(), left: position.left, display: keepVisible ? 'block' : 'none', visibility: 'visible' }); }; return Palette; })(Mercury.Dialog); }).call(this); (function() { var __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; }; this.Mercury.Select = (function(_super) { __extends(Select, _super); function Select(url, name, options) { this.url = url; this.name = name; this.options = options != null ? options : {}; Select.__super__.constructor.apply(this, arguments); } Select.prototype.build = function() { var _ref; this.element = jQuery('<div>', { "class": "mercury-select mercury-" + this.name + "-select loading", style: 'display:none' }); return this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); }; Select.prototype.bindEvents = function() { var _this = this; Mercury.on('hide:dialogs', function(event, dialog) { if (dialog !== _this) { return _this.hide(); } }); this.element.on('mousedown', function(event) { return event.preventDefault(); }); return Select.__super__.bindEvents.apply(this, arguments); }; Select.prototype.position = function(keepVisible) { var documentHeight, elementHeight, elementWidth, height, left, position, top; this.element.css({ top: 0, left: 0, display: 'block', visibility: 'hidden' }); position = this.button.position(); elementWidth = this.element.width(); elementHeight = this.element.height(); documentHeight = jQuery(document).height(); top = position.top + (this.button.height() / 2) - (elementHeight / 2); if (top < position.top - 100) { top = position.top - 100; } if (top < 20) { top = 20; } height = this.loaded ? 'auto' : elementHeight; if (top + elementHeight >= documentHeight - 20) { height = documentHeight - top - 20; } left = position.left; if (left + elementWidth > jQuery(window).width()) { left = left - elementWidth + this.button.width(); } return this.element.css({ top: top, left: left, height: height, display: keepVisible ? 'block' : 'none', visibility: 'visible' }); }; return Select; })(Mercury.Dialog); }).call(this); (function() { var __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; }; this.Mercury.Panel = (function(_super) { __extends(Panel, _super); function Panel(url, name, options) { this.url = url; this.name = name; this.options = options != null ? options : {}; Panel.__super__.constructor.apply(this, arguments); } Panel.prototype.build = function() { var _ref; this.element = jQuery('<div>', { "class": 'mercury-panel loading', style: 'display:none;' }); this.titleElement = jQuery("<h1><span>" + (Mercury.I18n(this.options.title)) + "</span></h1>").appendTo(this.element); this.paneElement = jQuery('<div>', { "class": 'mercury-panel-pane' }).appendTo(this.element); if (this.options.closeButton) { jQuery('<a/>', { "class": 'mercury-panel-close' }).appendTo(this.titleElement).css({ opacity: 0 }); } return this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); }; Panel.prototype.bindEvents = function() { var _this = this; Mercury.on('resize', function() { return _this.position(_this.visible); }); Mercury.on('hide:panels', function(event, panel) { if (panel === _this) { return; } _this.button.removeClass('pressed'); return _this.hide(); }); this.titleElement.find('.mercury-panel-close').on('click', function(event) { event.preventDefault(); return Mercury.trigger('hide:panels'); }); this.element.on('mousedown', function(event) { return event.stopPropagation(); }); this.element.on('ajax:beforeSend', function(event, xhr, options) { return options.success = function(content) { _this.loadContent(content); return _this.resize(); }; }); return Panel.__super__.bindEvents.apply(this, arguments); }; Panel.prototype.show = function() { Mercury.trigger('hide:panels', this); return Panel.__super__.show.apply(this, arguments); }; Panel.prototype.resize = function() { var position, postWidth, preWidth, _this = this; this.titleElement.find('.mercury-panel-close').css({ opacity: 0 }); this.paneElement.css({ display: 'none' }); preWidth = this.element.width(); this.paneElement.css({ visibility: 'hidden', width: 'auto', display: 'block' }); postWidth = this.element.width(); this.paneElement.css({ visibility: 'visible', display: 'none' }); position = this.element.offset(); this.element.animate({ left: position.left - (postWidth - preWidth), width: postWidth }, 200, 'easeInOutSine', function() { _this.titleElement.find('.mercury-panel-close').animate({ opacity: 1 }, 100); _this.paneElement.css({ display: 'block', width: postWidth }); jQuery(_this.paneElement.find('.focusable').get(0)).focus(); return _this.makeDraggable(); }); if (!this.visible) { return this.hide(); } }; Panel.prototype.position = function(keepVisible) { var elementWidth, height, left, offset, paneHeight; this.element.css({ display: 'block', visibility: 'hidden' }); offset = this.element.offset(); elementWidth = this.element.width(); height = Mercury.displayRect.height - 16; paneHeight = height - this.titleElement.outerHeight(); this.paneElement.css({ height: paneHeight, overflowY: paneHeight < 30 ? 'hidden' : 'auto' }); if (!this.moved) { left = Mercury.displayRect.width - elementWidth - 20; } if (left <= 8) { left = 8; } if (this.pinned || elementWidth + offset.left > Mercury.displayRect.width - 20) { left = Mercury.displayRect.width - elementWidth - 20; } this.element.css({ top: Mercury.displayRect.top + 8, left: left, height: height, display: keepVisible ? 'block' : 'none', visibility: 'visible' }); this.makeDraggable(); if (!keepVisible) { return this.element.hide(); } }; Panel.prototype.loadContent = function(data) { this.loaded = true; this.element.removeClass('loading'); this.paneElement.css({ visibility: 'hidden' }); this.paneElement.html(data); if (Mercury.config.localization.enabled) { return this.paneElement.localize(Mercury.locale()); } }; Panel.prototype.makeDraggable = function() { var elementWidth, _this = this; elementWidth = this.element.width(); return this.element.draggable({ handle: 'h1 span', axis: 'x', opacity: 0.70, scroll: false, addClasses: false, iframeFix: true, containment: [8, 0, Mercury.displayRect.width - elementWidth - 20, 0], stop: function() { var left; left = _this.element.offset().left; _this.moved = true; _this.pinned = left > Mercury.displayRect.width - elementWidth - 30 ? true : false; return true; } }); }; return Panel; })(Mercury.Dialog); }).call(this); (function() { var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; this.Mercury.modal = function(url, options) { var instance; if (options == null) { options = {}; } instance = new Mercury.Modal(url, options); instance.show(); return instance; }; this.Mercury.Modal = (function() { function Modal(url, options) { this.url = url; this.options = options != null ? options : {}; this.hide = __bind(this.hide, this); } Modal.prototype.show = function(url, options) { var _base, _this = this; if (url == null) { url = null; } if (options == null) { options = null; } this.url = url || this.url; this.options = options || this.options; (_base = this.options).minWidth || (_base.minWidth = 400); if (this.options.ujsHandling !== false) { this.options.ujsHandling = true; } Mercury.trigger('focus:window'); this.initializeModal(); if (this.visible) { this.update(); } else { this.appear(); } if (this.options.content) { return setTimeout((function() { return _this.loadContent(_this.options.content); }), 500); } }; Modal.prototype.initializeModal = function() { if (this.initialized) { return; } this.build(); this.bindEvents(); return this.initialized = true; }; Modal.prototype.build = function() { var _ref, _ref1; this.element = jQuery('.mercury-modal'); this.overlay = jQuery('.mercury-modal-overlay'); if (!(this.element.get(0) && this.overlay.get(0))) { this.element = jQuery('<div>', { "class": 'mercury-modal loading' }); this.element.html('<h1 class="mercury-modal-title"><span></span><a>×</a></h1>'); this.element.append('<div class="mercury-modal-content-container"><div class="mercury-modal-content"></div></div>'); this.overlay = jQuery('<div>', { "class": 'mercury-modal-overlay' }); this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); this.overlay.appendTo((_ref1 = jQuery(this.options.appendTo).get(0)) != null ? _ref1 : 'body'); } this.titleElement = this.element.find('.mercury-modal-title'); this.contentContainerElement = this.element.find('.mercury-modal-content-container'); return this.contentElement = this.element.find('.mercury-modal-content'); }; Modal.prototype.bindEvents = function() { var _this = this; Mercury.on('refresh', function() { return _this.resize(true); }); Mercury.on('resize', function() { return _this.position(); }); this.overlay.on('click', function() { if (_this.options.allowHideUsingOverlay) { return _this.hide(); } }); this.titleElement.find('a').on('click', function() { return _this.hide(); }); if (this.options.ujsHandling) { this.element.on('ajax:beforeSend', function(event, xhr, options) { return options.success = function(content) { return _this.loadContent(content); }; }); } return jQuery(document).on('keydown', function(event) { if (event.keyCode === 27 && _this.visible) { return _this.hide(); } }); }; Modal.prototype.appear = function() { var _this = this; this.showing = true; this.position(); this.overlay.show(); return this.overlay.animate({ opacity: 1 }, 200, 'easeInOutSine', function() { _this.element.css({ top: -_this.element.height() }); _this.setTitle(); _this.element.show(); return _this.element.animate({ top: 0 }, 200, 'easeInOutSine', function() { _this.visible = true; _this.showing = false; return _this.load(); }); }); }; Modal.prototype.resize = function(keepVisible) { var height, titleHeight, visibility, width, _this = this; visibility = keepVisible ? 'visible' : 'hidden'; titleHeight = this.titleElement.outerHeight(); width = this.contentElement.outerWidth(); if (this.contentPane) { this.contentPane.css({ height: 'auto' }); } this.contentElement.css({ height: 'auto', visibility: visibility, display: 'block' }); height = this.contentElement.outerHeight() + titleHeight; if (width < this.options.minWidth) { width = this.options.minWidth; } if (height > Mercury.displayRect.fullHeight || this.options.fullHeight) { height = Mercury.displayRect.fullHeight; } return this.element.stop().animate({ left: (Mercury.displayRect.width - width) / 2, width: width, height: height }, 200, 'easeInOutSine', function() { var controlHeight; _this.contentElement.css({ visibility: 'visible', display: 'block' }); if (_this.contentPane.length) { _this.contentElement.css({ height: height - titleHeight, overflow: 'visible' }); controlHeight = _this.contentControl.length ? _this.contentControl.outerHeight() + 10 : 0; _this.contentPane.css({ height: height - titleHeight - controlHeight - 20 }); return _this.contentPane.find('.mercury-display-pane').css({ width: width - 20 }); } else { return _this.contentElement.css({ height: height - titleHeight, overflow: 'auto' }); } }); }; Modal.prototype.position = function() { var controlHeight, height, titleHeight, viewportWidth, width; viewportWidth = Mercury.displayRect.width; if (this.contentPane) { this.contentPane.css({ height: 'auto' }); } this.contentElement.css({ height: 'auto' }); this.element.css({ width: 'auto', height: 'auto', display: 'block', visibility: 'hidden' }); width = this.element.width(); height = this.element.height(); if (width < this.options.minWidth) { width = this.options.minWidth; } if (height > Mercury.displayRect.fullHeight || this.options.fullHeight) { height = Mercury.displayRect.fullHeight; } titleHeight = this.titleElement.outerHeight(); if (this.contentPane && this.contentPane.length) { this.contentElement.css({ height: height - titleHeight, overflow: 'visible' }); controlHeight = this.contentControl.length ? this.contentControl.outerHeight() + 10 : 0; this.contentPane.css({ height: height - titleHeight - controlHeight - 20 }); this.contentPane.find('.mercury-display-pane').css({ width: width - 20 }); } else { this.contentElement.css({ height: height - titleHeight, overflow: 'auto' }); } return this.element.css({ left: (viewportWidth - width) / 2, width: width, height: height, display: this.visible ? 'block' : 'none', visibility: 'visible' }); }; Modal.prototype.update = function() { this.reset(); this.resize(); return this.load(); }; Modal.prototype.load = function() { var _this = this; this.setTitle(); if (!this.url) { return; } this.element.addClass('loading'); if (Mercury.preloadedViews[this.url]) { return setTimeout((function() { return _this.loadContent(Mercury.preloadedViews[_this.url]); }), 10); } else { return jQuery.ajax(this.url, { headers: Mercury.ajaxHeaders(), type: this.options.loadType || 'GET', data: this.options.loadData, success: function(data) { return _this.loadContent(data); }, error: function() { _this.hide(); return Mercury.notify("Mercury was unable to load %s for the modal.", _this.url); } }); } }; Modal.prototype.loadContent = function(data, options) { if (options == null) { options = null; } this.initializeModal(); this.options = options || this.options; this.setTitle(); this.loaded = true; this.element.removeClass('loading'); this.contentElement.html(data); this.contentElement.css({ display: 'none', visibility: 'hidden' }); this.contentPane = this.element.find('.mercury-display-pane-container'); this.contentControl = this.element.find('.mercury-display-controls'); if (this.options.afterLoad) { this.options.afterLoad.call(this); } if (this.options.handler) { if (Mercury.modalHandlers[this.options.handler]) { if (typeof Mercury.modalHandlers[this.options.handler] === 'function') { Mercury.modalHandlers[this.options.handler].call(this); } else { jQuery.extend(this, Mercury.modalHandlers[this.options.handler]); this.initialize(); } } else if (Mercury.lightviewHandlers[this.options.handler]) { if (typeof Mercury.lightviewHandlers[this.options.handler] === 'function') { Mercury.lightviewHandlers[this.options.handler].call(this); } else { jQuery.extend(this, Mercury.lightviewHandlers[this.options.handler]); this.initialize(); } } } if (Mercury.config.localization.enabled) { this.element.localize(Mercury.locale()); } this.element.find('.modal-close').on('click', this.hide); return this.resize(); }; Modal.prototype.setTitle = function() { var closeButton; this.titleElement.find('span').html(Mercury.I18n(this.options.title)); closeButton = this.titleElement.find('a'); if (this.options.closeButton === false) { return closeButton.hide(); } else { return closeButton.show(); } }; Modal.prototype.serializeForm = function() { return this.element.find('form').serializeObject() || {}; }; Modal.prototype.reset = function() { this.titleElement.find('span').html(''); return this.contentElement.html(''); }; Modal.prototype.hide = function() { if (this.showing) { return; } this.options = {}; Mercury.trigger('focus:frame'); this.element.hide(); this.overlay.hide(); this.reset(); return this.visible = false; }; return Modal; })(); }).call(this); (function() { var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; this.Mercury.lightview = function(url, options) { var _base; if (options == null) { options = {}; } (_base = Mercury.lightview).instance || (_base.instance = new Mercury.Lightview(url, options)); Mercury.lightview.instance.show(url, options); return Mercury.lightview.instance; }; this.Mercury.Lightview = (function() { function Lightview(url, options) { this.url = url; this.options = options != null ? options : {}; this.hide = __bind(this.hide, this); } Lightview.prototype.show = function(url, options) { var _this = this; this.url = url || this.url; this.options = options || this.options; if (this.options.ujsHandling !== false) { this.options.ujsHandling = true; } Mercury.trigger('focus:window'); this.initializeLightview(); if (this.visible) { this.update(); } else { this.appear(); } if (this.options.content) { return setTimeout((function() { return _this.loadContent(_this.options.content); }), 500); } }; Lightview.prototype.initializeLightview = function() { if (this.initialized) { return; } this.build(); this.bindEvents(); return this.initialized = true; }; Lightview.prototype.build = function() { var _ref, _ref1; this.element = jQuery('<div>', { "class": 'mercury-lightview loading' }); this.element.html('<h1 class="mercury-lightview-title"><span></span></h1>'); this.element.append('<div class="mercury-lightview-content"></div>'); this.overlay = jQuery('<div>', { "class": 'mercury-lightview-overlay' }); this.titleElement = this.element.find('.mercury-lightview-title'); if (this.options.closeButton) { this.titleElement.append('<a class="mercury-lightview-close"></a>'); } this.contentElement = this.element.find('.mercury-lightview-content'); this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); return this.overlay.appendTo((_ref1 = jQuery(this.options.appendTo).get(0)) != null ? _ref1 : 'body'); }; Lightview.prototype.bindEvents = function() { var _this = this; Mercury.on('refresh', function() { return _this.resize(true); }); Mercury.on('resize', function() { if (_this.visible) { return _this.position(); } }); this.overlay.on('click', function() { if (!_this.options.closeButton) { return _this.hide(); } }); this.titleElement.find('.mercury-lightview-close').on('click', function() { return _this.hide(); }); if (this.options.ujsHandling) { this.element.on('ajax:beforeSend', function(event, xhr, options) { return options.success = function(content) { return _this.loadContent(content); }; }); } return jQuery(document).on('keydown', function(event) { if (event.keyCode === 27 && _this.visible) { return _this.hide(); } }); }; Lightview.prototype.appear = function() { var _this = this; this.showing = true; this.position(); this.overlay.show().css({ opacity: 0 }); return this.overlay.animate({ opacity: 1 }, 200, 'easeInOutSine', function() { _this.setTitle(); _this.element.show().css({ opacity: 0 }); return _this.element.stop().animate({ opacity: 1 }, 200, 'easeInOutSine', function() { _this.visible = true; _this.showing = false; return _this.load(); }); }); }; Lightview.prototype.resize = function(keepVisible) { var height, titleHeight, viewportHeight, viewportWidth, visibility, width, _this = this; visibility = keepVisible ? 'visible' : 'hidden'; viewportWidth = Mercury.displayRect.width; viewportHeight = Mercury.displayRect.fullHeight; titleHeight = this.titleElement.outerHeight(); width = this.contentElement.outerWidth(); if (width > viewportWidth - 40 || this.options.fullSize) { width = viewportWidth - 40; } if (this.contentPane) { this.contentPane.css({ height: 'auto' }); } this.contentElement.css({ height: 'auto', visibility: visibility, display: 'block' }); height = this.contentElement.outerHeight() + titleHeight; if (height > viewportHeight - 20 || this.options.fullSize) { height = viewportHeight - 20; } if (width < 300) { width = 300; } if (height < 150) { height = 150; } return this.element.stop().animate({ top: ((viewportHeight - height) / 2) + 10, left: (Mercury.displayRect.width - width) / 2, width: width, height: height }, 200, 'easeInOutSine', function() { var controlHeight; _this.contentElement.css({ visibility: 'visible', display: 'block' }); if (_this.contentPane.length) { _this.contentElement.css({ height: height - titleHeight, overflow: 'visible' }); controlHeight = _this.contentControl.length ? _this.contentControl.outerHeight() : 0; _this.contentPane.css({ height: height - titleHeight - controlHeight - 40 }); return _this.contentPane.find('.mercury-display-pane').css({ width: width - 40 }); } else { return _this.contentElement.css({ height: height - titleHeight - 30, overflow: 'auto' }); } }); }; Lightview.prototype.position = function() { var controlHeight, height, titleHeight, viewportHeight, viewportWidth, width; viewportWidth = Mercury.displayRect.width; viewportHeight = Mercury.displayRect.fullHeight; if (this.contentPane) { this.contentPane.css({ height: 'auto' }); } this.contentElement.css({ height: 'auto' }); this.element.css({ width: 'auto', height: 'auto', display: 'block', visibility: 'hidden' }); width = this.contentElement.width() + 40; height = this.contentElement.height() + this.titleElement.outerHeight() + 30; if (width > viewportWidth - 40 || this.options.fullSize) { width = viewportWidth - 40; } if (height > viewportHeight - 20 || this.options.fullSize) { height = viewportHeight - 20; } if (width < 300) { width = 300; } if (height < 150) { height = 150; } titleHeight = this.titleElement.outerHeight(); if (this.contentPane && this.contentPane.length) { this.contentElement.css({ height: height - titleHeight, overflow: 'visible' }); controlHeight = this.contentControl.length ? this.contentControl.outerHeight() : 0; this.contentPane.css({ height: height - titleHeight - controlHeight - 40 }); this.contentPane.find('.mercury-display-pane').css({ width: width - 40 }); } else { this.contentElement.css({ height: height - titleHeight - 30, overflow: 'auto' }); } return this.element.css({ top: ((viewportHeight - height) / 2) + 10, left: (viewportWidth - width) / 2, width: width, height: height, display: this.visible ? 'block' : 'none', visibility: 'visible' }); }; Lightview.prototype.update = function() { this.reset(); this.resize(); return this.load(); }; Lightview.prototype.load = function() { var _this = this; this.setTitle(); if (!this.url) { return; } this.element.addClass('loading'); if (Mercury.preloadedViews[this.url]) { return setTimeout((function() { return _this.loadContent(Mercury.preloadedViews[_this.url]); }), 10); } else { return jQuery.ajax(this.url, { headers: Mercury.ajaxHeaders(), type: this.options.loadType || 'GET', data: this.options.loadData, success: function(data) { return _this.loadContent(data); }, error: function() { _this.hide(); return Mercury.notify('Mercury was unable to load %s for the lightview.', _this.url); } }); } }; Lightview.prototype.loadContent = function(data, options) { if (options == null) { options = null; } this.initializeLightview(); this.options = options || this.options; this.setTitle(); this.loaded = true; this.element.removeClass('loading'); this.contentElement.html(data); this.contentElement.css({ display: 'none', visibility: 'hidden' }); this.contentPane = this.element.find('.mercury-display-pane-container'); this.contentControl = this.element.find('.mercury-display-controls'); if (this.options.afterLoad) { this.options.afterLoad.call(this); } if (this.options.handler) { if (Mercury.modalHandlers[this.options.handler]) { if (typeof Mercury.modalHandlers[this.options.handler] === 'function') { Mercury.modalHandlers[this.options.handler].call(this); } else { jQuery.extend(this, Mercury.modalHandlers[this.options.handler]); this.initialize(); } } else if (Mercury.lightviewHandlers[this.options.handler]) { if (typeof Mercury.lightviewHandlers[this.options.handler] === 'function') { Mercury.lightviewHandlers[this.options.handler].call(this); } else { jQuery.extend(this, Mercury.lightviewHandlers[this.options.handler]); this.initialize(); } } } if (Mercury.config.localization.enabled) { this.element.localize(Mercury.locale()); } this.element.find('.lightview-close').on('click', this.hide); return this.resize(); }; Lightview.prototype.setTitle = function() { return this.titleElement.find('span').html(Mercury.I18n(this.options.title)); }; Lightview.prototype.serializeForm = function() { return this.element.find('form').serializeObject() || {}; }; Lightview.prototype.reset = function() { this.titleElement.find('span').html(''); return this.contentElement.html(''); }; Lightview.prototype.hide = function() { if (this.showing) { return; } this.options = {}; Mercury.trigger('focus:frame'); this.element.hide(); this.overlay.hide(); this.reset(); return this.visible = false; }; return Lightview; })(); }).call(this); (function() { this.Mercury.Statusbar = (function() { function Statusbar(options) { this.options = options != null ? options : {}; this.visible = this.options.visible; this.build(); this.bindEvents(); } Statusbar.prototype.build = function() { var _ref; this.element = jQuery('<div>', { "class": 'mercury-statusbar' }); this.aboutElement = jQuery('<a>', { "class": "mercury-statusbar-about" }).appendTo(this.element).html("Mercury Editor v" + Mercury.version); this.pathElement = jQuery('<div>', { "class": 'mercury-statusbar-path' }).appendTo(this.element); if (!this.visible) { this.element.css({ visibility: 'hidden' }); } return this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); }; Statusbar.prototype.bindEvents = function() { var _this = this; Mercury.on('region:update', function(event, options) { if (options.region && jQuery.type(options.region.path) === 'function') { return _this.setPath(options.region.path()); } }); return this.aboutElement.on('click', function() { return Mercury.lightview('/mercury/lightviews/about.html', { title: "Mercury Editor v" + Mercury.version }); }); }; Statusbar.prototype.height = function() { return this.element.outerHeight(); }; Statusbar.prototype.top = function() { var currentTop, top; top = this.element.offset().top; currentTop = parseInt(this.element.css('bottom')) < 0 ? top - this.element.outerHeight() : top; if (this.visible) { return currentTop; } else { return top + this.element.outerHeight(); } }; Statusbar.prototype.setPath = function(elements) { var element, path, _i, _len; path = []; for (_i = 0, _len = elements.length; _i < _len; _i++) { element = elements[_i]; path.push("<a>" + (element.tagName.toLowerCase()) + "</a>"); } return this.pathElement.html("<span><strong>" + (Mercury.I18n('Path:')) + " </strong>" + (path.reverse().join(' » ')) + "</span>"); }; Statusbar.prototype.show = function() { this.visible = true; this.element.css({ opacity: 0, visibility: 'visible' }); return this.element.animate({ opacity: 1 }, 200, 'easeInOutSine'); }; Statusbar.prototype.hide = function() { this.visible = false; return this.element.css({ visibility: 'hidden' }); }; return Statusbar; })(); }).call(this); (function() { var __hasProp = {}.hasOwnProperty; this.Mercury.Toolbar = (function() { function Toolbar(options) { this.options = options != null ? options : {}; this.visible = this.options.visible; this.build(); this.bindEvents(); } Toolbar.prototype.build = function() { var button, buttonName, buttons, container, expander, options, toolbar, toolbarName, _ref, _ref1; this.element = jQuery('<div>', { "class": 'mercury-toolbar-container', style: 'width:10000px' }); this.element.css({ width: '100%' }); this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); _ref1 = Mercury.config.toolbars; for (toolbarName in _ref1) { if (!__hasProp.call(_ref1, toolbarName)) continue; buttons = _ref1[toolbarName]; if (buttons._custom) { continue; } toolbar = jQuery('<div>', { "class": "mercury-toolbar mercury-" + toolbarName + "-toolbar" }).appendTo(this.element); if (buttons._regions) { toolbar.attr('data-regions', buttons._regions); } container = jQuery('<div>', { "class": 'mercury-toolbar-button-container' }).appendTo(toolbar); for (buttonName in buttons) { if (!__hasProp.call(buttons, buttonName)) continue; options = buttons[buttonName]; if (buttonName === '_regions') { continue; } button = this.buildButton(buttonName, options); if (button) { button.appendTo(container); } } if (container.css('white-space') === 'nowrap') { expander = new Mercury.Toolbar.Expander(toolbarName, { appendTo: toolbar, "for": container }); expander.appendTo(this.element); } if (Mercury.config.toolbars['primary'] && toolbarName !== 'primary') { toolbar.addClass('disabled'); } } if (!this.visible) { return this.element.css({ display: 'none' }); } }; Toolbar.prototype.buildButton = function(name, options) { var action, button, group, handled, opts, summary, title; if (name[0] === '_') { return false; } switch (jQuery.type(options)) { case 'array': title = options[0], summary = options[1], handled = options[2]; return new Mercury.Toolbar.Button(name, title, summary, handled, { appendDialogsTo: this.element }); case 'object': group = new Mercury.Toolbar.ButtonGroup(name, options); for (action in options) { if (!__hasProp.call(options, action)) continue; opts = options[action]; button = this.buildButton(action, opts); if (button) { button.appendTo(group); } } return group; case 'string': return jQuery('<hr>', { "class": "mercury-" + (options === '-' ? 'line-separator' : 'separator') }); default: throw Mercury.I18n('Unknown button structure -- please provide an array, object, or string for "%s".', name); } }; Toolbar.prototype.bindEvents = function() { var _this = this; Mercury.on('region:focused', function(event, options) { var regions, toolbar, _i, _len, _ref, _results; _ref = _this.element.find(".mercury-toolbar"); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { toolbar = _ref[_i]; toolbar = jQuery(toolbar); if (regions = toolbar.data('regions')) { if (regions.split(',').indexOf(options.region.type()) > -1) { _results.push(toolbar.removeClass('disabled')); } else { _results.push(void 0); } } else { _results.push(void 0); } } return _results; }); Mercury.on('region:blurred', function(event, options) { var regions, toolbar, _i, _len, _ref, _results; _ref = _this.element.find(".mercury-toolbar"); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { toolbar = _ref[_i]; toolbar = jQuery(toolbar); if (regions = toolbar.data('regions')) { if (regions.split(',').indexOf(options.region.type()) > -1) { _results.push(toolbar.addClass('disabled')); } else { _results.push(void 0); } } else { _results.push(void 0); } } return _results; }); this.element.on('click', function() { return Mercury.trigger('hide:dialogs'); }); return this.element.on('mousedown', function(event) { return event.preventDefault(); }); }; Toolbar.prototype.height = function(force) { if (force == null) { force = false; } if (this.visible || force) { return this.element.outerHeight(); } else { return 0; } }; Toolbar.prototype.top = function() { if (this.visible) { return this.element.offset().top; } else { return 0; } }; Toolbar.prototype.show = function() { this.visible = true; this.element.css({ top: -this.element.outerHeight(), display: 'block' }); return this.element.animate({ top: 0 }, 200, 'easeInOutSine'); }; Toolbar.prototype.hide = function() { this.visible = false; return this.element.hide(); }; return Toolbar; })(); }).call(this); (function() { var __hasProp = {}.hasOwnProperty; this.Mercury.Toolbar.Button = (function() { function Button(name, title, summary, types, options) { this.name = name; this.title = title; this.summary = summary != null ? summary : null; this.types = types != null ? types : {}; this.options = options != null ? options : {}; if (this.title) { this.title = Mercury.I18n(this.title); } if (this.summary) { this.summary = Mercury.I18n(this.summary); } this.build(); this.bindEvents(); return this.element; } Button.prototype.build = function() { var mixed, result, type, _ref, _ref1, _results; this.element = jQuery('<div>', { title: (_ref = this.summary) != null ? _ref : this.title, "class": "mercury-button mercury-" + this.name + "-button" }).html("<em>" + this.title + "</em>"); this.element.data('expander', "<div class=\"mercury-expander-button\" data-button=\"" + this.name + "\"><em></em><span>" + this.title + "</span></div>"); this.handled = {}; _ref1 = this.types; _results = []; for (type in _ref1) { if (!__hasProp.call(_ref1, type)) continue; mixed = _ref1[type]; switch (type) { case 'preload': _results.push(true); break; case 'regions': this.element.addClass('disabled'); _results.push(this.handled[type] = jQuery.isFunction(mixed) ? mixed.call(this, this.name) : mixed); break; case 'toggle': _results.push(this.handled[type] = true); break; case 'mode': _results.push(this.handled[type] = mixed === true ? this.name : mixed); break; case 'context': _results.push(this.handled[type] = jQuery.isFunction(mixed) ? mixed : Mercury.Toolbar.Button.contexts[this.name]); break; case 'palette': this.element.addClass("mercury-button-palette"); result = jQuery.isFunction(mixed) ? mixed.call(this, this.name) : mixed; _results.push(this.handled[type] = typeof result === 'string' ? new Mercury.Palette(result, this.name, this.defaultDialogOptions()) : result); break; case 'select': this.element.addClass("mercury-button-select").find('em').html(this.title); result = jQuery.isFunction(mixed) ? mixed.call(this, this.name) : mixed; _results.push(this.handled[type] = typeof result === 'string' ? new Mercury.Select(result, this.name, this.defaultDialogOptions()) : result); break; case 'panel': this.element.addClass('mercury-button-panel'); this.handled['toggle'] = true; result = jQuery.isFunction(mixed) ? mixed.call(this, this.name) : mixed; _results.push(this.handled[type] = typeof result === 'string' ? new Mercury.Panel(result, this.name, this.defaultDialogOptions()) : result); break; case 'modal': _results.push(this.handled[type] = jQuery.isFunction(mixed) ? mixed.call(this, this.name) : mixed); break; case 'lightview': _results.push(this.handled[type] = jQuery.isFunction(mixed) ? mixed.call(this, this.name) : mixed); break; default: throw Mercury.I18n('Unknown button type \"%s\" used for the \"%s\" button.', type, this.name); } } return _results; }; Button.prototype.bindEvents = function() { var _this = this; Mercury.on('button', function(event, options) { if (options.action === _this.name) { return _this.element.click(); } }); Mercury.on('mode', function(event, options) { if (_this.handled.mode === options.mode && _this.handled.toggle) { return _this.togglePressed(); } }); Mercury.on('region:update', function(event, options) { var element; if (_this.handled.context && options.region && jQuery.type(options.region.currentElement) === 'function') { element = options.region.currentElement(); if (element.length && _this.handled.context.call(_this, element, options.region.element)) { return _this.element.addClass('active'); } else { return _this.element.removeClass('active'); } } else { return _this.element.removeClass('active'); } }); Mercury.on('region:focused', function(event, options) { if (_this.handled.regions && options.region && options.region.type()) { if (_this.handled.regions.indexOf(options.region.type()) > -1) { return _this.element.removeClass('disabled'); } else { return _this.element.addClass('disabled'); } } }); Mercury.on('region:blurred', function() { if (_this.handled.regions) { return _this.element.addClass('disabled'); } }); this.element.on('mousedown', function() { return _this.element.addClass('active'); }); this.element.on('mouseup', function() { return _this.element.removeClass('active'); }); return this.element.on('click', function(event) { if (_this.element.closest('.disabled').length) { return; } return _this.handleClick(event); }); }; Button.prototype.handleClick = function(event) { var handled, mixed, type, _ref; handled = false; _ref = this.handled; for (type in _ref) { if (!__hasProp.call(_ref, type)) continue; mixed = _ref[type]; switch (type) { case 'toggle': if (!this.handled.mode) { this.togglePressed(); } break; case 'mode': handled = true; Mercury.trigger('mode', { mode: mixed }); break; case 'modal': handled = this.handleModal(event); break; case 'lightview': handled = this.handleLightview(event); break; case 'palette': case 'select': case 'panel': handled = this.handleDialog(event, type); } } if (!handled) { Mercury.trigger('action', { action: this.name }); } if (this.options['regions'] && this.options['regions'].length) { return Mercury.trigger('focus:frame'); } }; Button.prototype.handleModal = function(event) { Mercury.modal(this.handled.modal, { title: this.summary || this.title, handler: this.name }); return true; }; Button.prototype.handleLightview = function(event) { Mercury.lightview(this.handled.lightview, { title: this.summary || this.title, handler: this.name, closeButton: true }); return true; }; Button.prototype.handleDialog = function(event, type) { event.stopPropagation(); this.handled[type].toggle(); return true; }; Button.prototype.defaultDialogOptions = function() { return { title: this.summary || this.title, preload: this.types.preload, appendTo: this.options.appendDialogsTo || 'body', closeButton: true, "for": this.element }; }; Button.prototype.togglePressed = function() { return this.element.toggleClass('pressed'); }; return Button; })(); this.Mercury.Toolbar.Button.contexts = { backColor: function(node) { return this.element.css('background-color', node.css('background-color')); }, foreColor: function(node) { return this.element.css('background-color', node.css('color')); }, bold: function(node) { var weight; weight = node.css('font-weight'); return weight === 'bold' || weight > 400; }, italic: function(node) { return node.css('font-style') === 'italic'; }, overline: function(node) { var parent, _i, _len, _ref; if (node.css('text-decoration') === 'overline') { return true; } _ref = node.parentsUntil(this.element); for (_i = 0, _len = _ref.length; _i < _len; _i++) { parent = _ref[_i]; if (jQuery(parent).css('text-decoration') === 'overline') { return true; } } return false; }, strikethrough: function(node, region) { return node.css('text-decoration') === 'line-through' || !!node.closest('strike', region).length; }, underline: function(node, region) { return node.css('text-decoration') === 'underline' || !!node.closest('u', region).length; }, subscript: function(node, region) { return !!node.closest('sub', region).length; }, superscript: function(node, region) { return !!node.closest('sup', region).length; }, justifyLeft: function(node) { return node.css('text-align').indexOf('left') > -1; }, justifyCenter: function(node) { return node.css('text-align').indexOf('center') > -1; }, justifyRight: function(node) { return node.css('text-align').indexOf('right') > -1; }, justifyFull: function(node) { return node.css('text-align').indexOf('justify') > -1; }, insertOrderedList: function(node, region) { return !!node.closest('ol', region.element).length; }, insertUnorderedList: function(node, region) { return !!node.closest('ul', region.element).length; } }; }).call(this); (function() { this.Mercury.Toolbar.ButtonGroup = (function() { function ButtonGroup(name, options) { this.name = name; this.options = options != null ? options : {}; this.build(); this.bindEvents(); this.regions = this.options._regions; return this.element; } ButtonGroup.prototype.build = function() { this.element = jQuery('<div>', { "class": "mercury-button-group mercury-" + this.name + "-group" }); if (this.options._context || this.options._regions) { return this.element.addClass('disabled'); } }; ButtonGroup.prototype.bindEvents = function() { var _this = this; Mercury.on('region:update', function(event, options) { var context, element; context = Mercury.Toolbar.ButtonGroup.contexts[_this.name]; if (context) { if (options.region && jQuery.type(options.region.currentElement) === 'function') { element = options.region.currentElement(); if (element.length && context.call(_this, element, options.region.element)) { return _this.element.removeClass('disabled'); } else { return _this.element.addClass('disabled'); } } } }); Mercury.on('region:focused', function(event, options) { if (_this.regions && options.region && options.region.type()) { if (_this.regions.indexOf(options.region.type()) > -1) { if (!_this.options._context) { return _this.element.removeClass('disabled'); } } else { return _this.element.addClass('disabled'); } } }); return Mercury.on('region:blurred', function(event, options) { if (_this.options.regions) { return _this.element.addClass('disabled'); } }); }; return ButtonGroup; })(); this.Mercury.Toolbar.ButtonGroup.contexts = { table: function(node, region) { return !!node.closest('table', region).length; } }; }).call(this); (function() { var __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; }; this.Mercury.Toolbar.Expander = (function(_super) { __extends(Expander, _super); function Expander(name, options) { this.name = name; this.options = options; this.container = this.options["for"]; Expander.__super__.constructor.call(this, null, this.name, this.options); return this.element; } Expander.prototype.build = function() { var _ref; this.container.css({ whiteSpace: 'normal', visibility: 'hidden', display: 'block' }); this.container.css({ visibility: 'visible' }); this.trigger = jQuery('<div>', { "class": 'mercury-toolbar-expander' }).appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); this.element = jQuery('<div>', { "class": "mercury-palette mercury-expander mercury-" + this.name + "-expander", style: 'display:none' }); return this.windowResize(); }; Expander.prototype.bindEvents = function() { var _this = this; Mercury.on('hide:dialogs', function(event, dialog) { if (dialog !== _this) { return _this.hide(); } }); Mercury.on('resize', function() { return _this.windowResize(); }); Expander.__super__.bindEvents.apply(this, arguments); this.trigger.click(function(event) { var button, hiddenButtons, _i, _len, _ref; event.stopPropagation(); hiddenButtons = []; _ref = _this.container.find('.mercury-button'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { button = _ref[_i]; button = jQuery(button); if (button.position().top > 5) { hiddenButtons.push(button.data('expander')); } } _this.loadContent(hiddenButtons.join('')); return _this.toggle(); }); return this.element.click(function(event) { var button, buttonName; buttonName = jQuery(event.target).closest('[data-button]').data('button'); button = _this.container.find(".mercury-" + buttonName + "-button"); return button.click(); }); }; Expander.prototype.windowResize = function() { if (jQuery(window).width() === this.container.outerWidth()) { this.trigger.show(); } else { this.trigger.hide(); } return this.hide(); }; Expander.prototype.position = function(keepVisible) { var position, width; this.element.css({ top: 0, left: 0, display: 'block', visibility: 'hidden' }); position = this.trigger.position(); width = this.element.width(); if (position.left + width > jQuery(window).width()) { position.left = position.left - width + this.trigger.width(); } return this.element.css({ top: position.top + this.trigger.height(), left: position.left, display: keepVisible ? 'block' : 'none', visibility: 'visible' }); }; return Expander; })(Mercury.Palette); }).call(this); (function() { this.Mercury.tooltip = function(forElement, content, options) { if (options == null) { options = {}; } Mercury.tooltip.show(forElement, content, options); return Mercury.tooltip; }; jQuery.extend(Mercury.tooltip, { show: function(forElement, content, options) { this.forElement = forElement; this.content = content; this.options = options != null ? options : {}; this.document = this.forElement.get(0).ownerDocument; this.initialize(); if (this.visible) { return this.update(); } else { return this.appear(); } }, initialize: function() { if (this.initialized) { return; } this.build(); this.bindEvents(); return this.initialized = true; }, build: function() { var _ref; this.element = jQuery('<div>', { "class": 'mercury-tooltip' }); return this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); }, bindEvents: function() { var parent, _i, _len, _ref, _this = this; Mercury.on('resize', function() { if (_this.visible) { return _this.position(); } }); this.element.on('mousedown', function(event) { event.preventDefault(); return event.stopPropagation(); }); _ref = this.forElement.parentsUntil(jQuery('body', this.document)); for (_i = 0, _len = _ref.length; _i < _len; _i++) { parent = _ref[_i]; if (!(parent.scrollHeight > parent.clientHeight)) { continue; } jQuery(parent).on('scroll', function() { if (_this.visible) { return _this.position(); } }); } return jQuery(this.document).on('scroll', function() { if (_this.visible) { return _this.position(); } }); }, appear: function() { var _this = this; this.update(); this.element.show(); return this.element.animate({ opacity: 1 }, 200, 'easeInOutSine', function() { return _this.visible = true; }); }, update: function() { this.element.html(this.content); return this.position(); }, position: function() { var left, offset, top, width; offset = this.forElement.offset(); width = this.element.width(); top = offset.top + (Mercury.displayRect.top - jQuery(this.document).scrollTop()) + this.forElement.outerHeight(); left = offset.left - jQuery(this.document).scrollLeft(); if ((left + width + 25) > Mercury.displayRect.width) { left = left - (left + width + 25) - Mercury.displayRect.width; } left = left <= 0 ? 0 : left; return this.element.css({ top: top, left: left }); }, hide: function() { if (!this.initialized) { return; } this.element.hide(); return this.visible = false; } }); }).call(this); (function() { var __hasProp = {}.hasOwnProperty; this.Mercury.Snippet = (function() { Snippet.all = []; Snippet.displayOptionsFor = function(name, options, displayOptions) { var snippet; if (options == null) { options = {}; } if (displayOptions == null) { displayOptions = true; } if (displayOptions) { Mercury.modal(this.optionsUrl(name), jQuery.extend({ title: 'Snippet Options', handler: 'insertSnippet', snippetName: name, loadType: Mercury.config.snippets.method }, options)); } else { snippet = Mercury.Snippet.create(name); Mercury.trigger('action', { action: 'insertSnippet', value: snippet }); } return Mercury.snippet = null; }; Snippet.optionsUrl = function(name) { var url; url = Mercury.config.snippets.optionsUrl; if (typeof url === 'function') { url = url(); } return url.replace(':name', name); }; Snippet.previewUrl = function(name) { var url; url = Mercury.config.snippets.previewUrl; if (typeof url === 'function') { url = url(); } return url.replace(':name', name); }; Snippet.create = function(name, options) { var instance; instance = new Mercury.Snippet(name, this.uniqueId(), options); this.all.push(instance); return instance; }; Snippet.uniqueId = function() { var i, identities, identity, snippet, _ref; _ref = [0, "snippet_0"], i = _ref[0], identity = _ref[1]; identities = (function() { var _i, _len, _ref1, _results; _ref1 = this.all; _results = []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { snippet = _ref1[_i]; _results.push(snippet.identity); } return _results; }).call(this); while (identities.indexOf(identity) !== -1) { i += 1; identity = "snippet_" + i; } return identity; }; Snippet.find = function(identity) { var snippet, _i, _len, _ref; _ref = this.all; for (_i = 0, _len = _ref.length; _i < _len; _i++) { snippet = _ref[_i]; if (snippet.identity === identity) { return snippet; } } return null; }; Snippet.load = function(snippets) { var details, identity, instance, _results; _results = []; for (identity in snippets) { if (!__hasProp.call(snippets, identity)) continue; details = snippets[identity]; instance = new Mercury.Snippet(details.name, identity, details); _results.push(this.all.push(instance)); } return _results; }; Snippet.clearAll = function() { delete this.all; return this.all = []; }; function Snippet(name, identity, options) { this.name = name; this.identity = identity; if (options == null) { options = {}; } this.version = 0; this.data = ''; this.wrapperTag = 'div'; this.wrapperClass = ''; this.history = new Mercury.HistoryBuffer(); this.setOptions(options); } Snippet.prototype.getHTML = function(context, callback) { var element, elementClass; if (callback == null) { callback = null; } elementClass = "" + this.name + "-snippet"; if (this.wrapperClass) { elementClass += " " + this.wrapperClass; } element = jQuery("<" + this.wrapperTag + ">", { "class": elementClass, contenteditable: "false", 'data-snippet': this.identity, 'data-version': this.version }, context); element.html("[" + this.identity + "]"); this.loadPreview(element, callback); return element; }; Snippet.prototype.getText = function(callback) { return "[--" + this.identity + "--]"; }; Snippet.prototype.loadPreview = function(element, callback) { var _this = this; if (callback == null) { callback = null; } return jQuery.ajax(Snippet.previewUrl(this.name), { headers: Mercury.ajaxHeaders(), type: Mercury.config.snippets.method, data: this.options, success: function(data) { _this.data = data; element.html(data); if (callback) { return callback(); } }, error: function() { return Mercury.notify('Error loading the preview for the \"%s\" snippet.', _this.name); } }); }; Snippet.prototype.displayOptions = function() { Mercury.snippet = this; return Mercury.modal(Snippet.optionsUrl(this.name), { title: 'Snippet Options', handler: 'insertSnippet', loadType: Mercury.config.snippets.method, loadData: this.options }); }; Snippet.prototype.setOptions = function(options) { this.options = options; delete this.options['authenticity_token']; delete this.options['utf8']; if (this.options.wrapperTag) { this.wrapperTag = this.options.wrapperTag; } if (this.options.wrapperClass) { this.wrapperClass = this.options.wrapperClass; } this.version += 1; return this.history.push(this.options); }; Snippet.prototype.setVersion = function(version) { if (version == null) { version = null; } version = parseInt(version); if (version && this.history.stack[version - 1]) { this.version = version; this.options = this.history.stack[version - 1]; return true; } return false; }; Snippet.prototype.serialize = function() { return $.extend({ name: this.name }, this.options); }; return Snippet; })(); }).call(this); (function() { var __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; }; this.Mercury.SnippetToolbar = (function(_super) { __extends(SnippetToolbar, _super); function SnippetToolbar(document, options) { this.document = document; this.options = options != null ? options : {}; this._boundEvents = []; SnippetToolbar.__super__.constructor.call(this, this.options); } SnippetToolbar.prototype.build = function() { var button, buttonName, options, _ref, _ref1, _results; this.element = jQuery('<div>', { "class": 'mercury-toolbar mercury-snippet-toolbar', style: 'display:none' }); this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); _ref1 = Mercury.config.toolbars.snippets; _results = []; for (buttonName in _ref1) { if (!__hasProp.call(_ref1, buttonName)) continue; options = _ref1[buttonName]; button = this.buildButton(buttonName, options); if (button) { _results.push(button.appendTo(this.element)); } else { _results.push(void 0); } } return _results; }; SnippetToolbar.prototype.bindEvents = function() { var _this = this; this.bindReleasableEvent(Mercury, 'show:toolbar', function(event, options) { if (!options.snippet) { return; } options.snippet.mouseout(function() { return _this.hide(); }); return _this.show(options.snippet); }); this.bindReleasableEvent(Mercury, 'hide:toolbar', function(event, options) { if (!(options.type && options.type === 'snippet')) { return; } return _this.hide(options.immediately); }); this.bindReleasableEvent(jQuery(this.document), 'scroll', function() { if (_this.visible) { return _this.position(); } }); this.element.mousemove(function() { return clearTimeout(_this.hideTimeout); }); return this.element.mouseout(function() { return _this.hide(); }); }; SnippetToolbar.prototype.bindReleasableEvent = function(target, eventName, handler) { target.on(eventName, handler); return this._boundEvents.push([target, eventName, handler]); }; SnippetToolbar.prototype.show = function(snippet) { this.snippet = snippet; Mercury.tooltip.hide(); this.position(); return this.appear(); }; SnippetToolbar.prototype.position = function() { var left, offset, top; offset = this.snippet.offset(); top = offset.top + Mercury.displayRect.top - jQuery(this.document).scrollTop() - this.height() + 10; left = offset.left - jQuery(this.document).scrollLeft(); return this.element.css({ top: top, left: left }); }; SnippetToolbar.prototype.appear = function() { clearTimeout(this.hideTimeout); if (this.visible) { return; } this.visible = true; this.element.css({ display: 'block', opacity: 0 }); return this.element.stop().animate({ opacity: 1 }, 200, 'easeInOutSine'); }; SnippetToolbar.prototype.hide = function(immediately) { var _this = this; if (immediately == null) { immediately = false; } clearTimeout(this.hideTimeout); if (immediately) { this.element.hide(); return this.visible = false; } else { return this.hideTimeout = setTimeout(function() { _this.element.stop().animate({ opacity: 0 }, 300, 'easeInOutSine', function() { return _this.element.hide(); }); return _this.visible = false; }, 500); } }; SnippetToolbar.prototype.release = function() { var eventName, handler, target, _i, _len, _ref, _ref1; this.element.off(); this.element.remove(); _ref = this._boundEvents; for (_i = 0, _len = _ref.length; _i < _len; _i++) { _ref1 = _ref[_i], target = _ref1[0], eventName = _ref1[1], handler = _ref1[2]; target.off(eventName, handler); } return this._boundEvents = []; }; return SnippetToolbar; })(Mercury.Toolbar); }).call(this); (function() { this.Mercury.Region = (function() { function Region(element, window, options) { this.element = element; this.window = window; this.options = options != null ? options : {}; Mercury.log("building " + (this.type()), this.element, this.options); this.document = this.window.document; this.name = this.element.attr(Mercury.config.regions.identifier); this.history = new Mercury.HistoryBuffer(); this.build(); this.bindEvents(); this.pushHistory(); this.element.data('region', this); } Region.prototype.type = function() { return 'unknown'; }; Region.prototype.build = function() {}; Region.prototype.focus = function() {}; Region.prototype.bindEvents = function() { var _this = this; Mercury.on('mode', function(event, options) { if (options.mode === 'preview') { return _this.togglePreview(); } }); Mercury.on('focus:frame', function() { if (_this.previewing || Mercury.region !== _this) { return; } return _this.focus(); }); Mercury.on('action', function(event, options) { if (_this.previewing || Mercury.region !== _this || event.isDefaultPrevented()) { return; } if (options.action) { return _this.execCommand(options.action, options); } }); this.element.on('mousemove', function(event) { var snippet; if (_this.previewing || Mercury.region !== _this) { return; } snippet = jQuery(event.target).closest('[data-snippet]'); if (snippet.length) { _this.snippet = snippet; if (_this.snippet.data('snippet')) { return Mercury.trigger('show:toolbar', { type: 'snippet', snippet: _this.snippet }); } } }); return this.element.on('mouseout', function() { if (_this.previewing) { return; } return Mercury.trigger('hide:toolbar', { type: 'snippet', immediately: false }); }); }; Region.prototype.content = function(value, filterSnippets) { var container, snippet, _i, _len, _ref; if (value == null) { value = null; } if (filterSnippets == null) { filterSnippets = false; } if (value !== null) { return this.element.html(value); } else { container = document.createElement('div'); container.innerHTML = this.element.html().replace(/^\s+|\s+$/g, ''); container = $(container); if (filterSnippets) { _ref = container.find('[data-snippet]'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { snippet = _ref[_i]; snippet = jQuery(snippet); snippet.attr({ contenteditable: null, 'data-version': null }); snippet.html("[" + (snippet.data('snippet')) + "]"); } } return container.html(); } }; Region.prototype.togglePreview = function() { if (this.previewing) { this.previewing = false; this.element.attr(Mercury.config.regions.attribute, this.type()); if (Mercury.region === this) { return this.focus(); } } else { this.previewing = true; this.element.removeAttr(Mercury.config.regions.attribute); return Mercury.trigger('region:blurred', { region: this }); } }; Region.prototype.execCommand = function(action, options) { if (options == null) { options = {}; } this.focus(); if (action !== 'redo') { this.pushHistory(); } Mercury.log('execCommand', action, options.value); return Mercury.changes = true; }; Region.prototype.pushHistory = function() { return this.history.push(this.content()); }; Region.prototype.snippets = function() { var element, snippet, snippets, _i, _len, _ref; snippets = {}; _ref = this.element.find('[data-snippet]'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { element = _ref[_i]; snippet = Mercury.Snippet.find(jQuery(element).data('snippet')); if (!snippet) { continue; } snippets[snippet.identity] = snippet.serialize(); } return snippets; }; Region.prototype.dataAttributes = function() { var attr, data, _i, _len, _ref; data = {}; _ref = Mercury.config.regions.dataAttributes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { attr = _ref[_i]; data[attr] = (this.container || this.element).attr('data-' + attr); } return data; }; Region.prototype.serialize = function() { return { type: this.type(), data: this.dataAttributes(), value: this.content(null, true), snippets: this.snippets() }; }; return Region; })(); }).call(this); (function() { var __hasProp = {}.hasOwnProperty; this.Mercury.uploader = function(file, options) { if (Mercury.config.uploading.enabled) { Mercury.uploader.show(file, options); } return Mercury.uploader; }; jQuery.extend(Mercury.uploader, { show: function(file, options) { this.options = options != null ? options : {}; this.file = new Mercury.uploader.File(file); if (this.file.errors) { alert("Error: " + this.file.errors); return; } if (!this.supported()) { return; } Mercury.trigger('focus:window'); this.initialize(); return this.appear(); }, initialize: function() { if (this.initialized) { return; } this.build(); this.bindEvents(); return this.initialized = true; }, supported: function() { var xhr; xhr = new XMLHttpRequest; if (window.Uint8Array && window.ArrayBuffer && !XMLHttpRequest.prototype.sendAsBinary) { XMLHttpRequest.prototype.sendAsBinary = function(datastr) { var data, index, ui8a, _i, _len; ui8a = new Uint8Array(datastr.length); for (index = _i = 0, _len = datastr.length; _i < _len; index = ++_i) { data = datastr[index]; ui8a[index] = datastr.charCodeAt(index) & 0xff; } return this.send(ui8a.buffer); }; } return !!(xhr.upload && xhr.sendAsBinary && (Mercury.uploader.fileReaderSupported() || Mercury.uploader.formDataSupported())); }, fileReaderSupported: function() { return !!window.FileReader; }, formDataSupported: function() { return !!window.FormData; }, build: function() { var _ref, _ref1; this.element = jQuery('<div>', { "class": 'mercury-uploader', style: 'display:none' }); this.element.append('<div class="mercury-uploader-preview"><b><img/></b></div>'); this.element.append('<div class="mercury-uploader-details"></div>'); this.element.append('<div class="mercury-uploader-progress"><span></span><div class="mercury-uploader-indicator"><div><b>0%</b></div></div></div>'); this.updateStatus('Processing...'); this.overlay = jQuery('<div>', { "class": 'mercury-uploader-overlay', style: 'display:none' }); this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body'); return this.overlay.appendTo((_ref1 = jQuery(this.options.appendTo).get(0)) != null ? _ref1 : 'body'); }, bindEvents: function() { var _this = this; return Mercury.on('resize', function() { return _this.position(); }); }, appear: function() { var _this = this; this.fillDisplay(); this.position(); this.overlay.show(); return this.overlay.animate({ opacity: 1 }, 200, 'easeInOutSine', function() { _this.element.show(); return _this.element.animate({ opacity: 1 }, 200, 'easeInOutSine', function() { _this.visible = true; return _this.loadImage(); }); }); }, position: function() { var height, width; width = this.element.outerWidth(); height = this.element.outerHeight(); return this.element.css({ top: (Mercury.displayRect.height - height) / 2, left: (Mercury.displayRect.width - width) / 2 }); }, fillDisplay: function() { var details; details = [Mercury.I18n('Name: %s', this.file.name), Mercury.I18n('Size: %s', this.file.readableSize), Mercury.I18n('Type: %s', this.file.type)]; return this.element.find('.mercury-uploader-details').html(details.join('<br/>')); }, loadImage: function() { var _this = this; if (Mercury.uploader.fileReaderSupported()) { return this.file.readAsDataURL(function(result) { _this.element.find('.mercury-uploader-preview b').html(jQuery('<img>', { src: result })); return _this.upload(); }); } else { return this.upload(); } }, upload: function() { var formData, xhr, _this = this; xhr = new XMLHttpRequest; jQuery.each(['onloadstart', 'onprogress', 'onload', 'onabort', 'onerror'], function(index, eventName) { return xhr.upload[eventName] = function(event) { return _this.uploaderEvents[eventName].call(_this, event); }; }); xhr.onload = function(event) { var error, response, src; if (event.currentTarget.status >= 400) { _this.updateStatus('Error: Unable to upload the file'); Mercury.notify('Unable to process response: %s', event.currentTarget.status); return _this.hide(); } else { try { response = Mercury.config.uploading.handler ? Mercury.config.uploading.handler(event.target.responseText) : jQuery.parseJSON(event.target.responseText); src = response.url || response.image.url; if (!src) { throw 'Malformed response from server.'; } Mercury.trigger('action', { action: 'insertImage', value: { src: src } }); return _this.hide(); } catch (_error) { error = _error; _this.updateStatus('Error: Unable to upload the file'); Mercury.notify('Unable to process response: %s', error); return _this.hide(); } } }; xhr.open('post', Mercury.config.uploading.url, true); xhr.setRequestHeader('Accept', 'application/json, text/javascript, text/html, application/xml, text/xml, */*'); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.setRequestHeader(Mercury.config.csrfHeader, Mercury.csrfToken); if (Mercury.uploader.fileReaderSupported()) { return this.file.readAsBinaryString(function(result) { var multipart; multipart = new Mercury.uploader.MultiPartPost(Mercury.config.uploading.inputName, _this.file, result); _this.file.updateSize(multipart.delta); xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + multipart.boundary); return xhr.sendAsBinary(multipart.body); }); } else { formData = new FormData(); formData.append(Mercury.config.uploading.inputName, this.file.file, this.file.file.name); return xhr.send(formData); } }, updateStatus: function(message, loaded) { var percent; this.element.find('.mercury-uploader-progress span').html(Mercury.I18n(message).toString()); if (loaded) { percent = Math.floor(loaded * 100 / this.file.size) + '%'; this.element.find('.mercury-uploader-indicator div').css({ width: percent }); return this.element.find('.mercury-uploader-indicator b').html(percent).show(); } }, hide: function(delay) { var _this = this; if (delay == null) { delay = 0; } return setTimeout(function() { return _this.element.animate({ opacity: 0 }, 200, 'easeInOutSine', function() { return _this.overlay.animate({ opacity: 0 }, 200, 'easeInOutSine', function() { _this.overlay.hide(); _this.element.hide(); _this.reset(); _this.visible = false; return Mercury.trigger('focus:frame'); }); }); }, delay * 1000); }, reset: function() { this.element.find('.mercury-uploader-preview b').html(''); this.element.find('.mercury-uploader-indicator div').css({ width: 0 }); this.element.find('.mercury-uploader-indicator b').html('0%').hide(); return this.updateStatus('Processing...'); }, uploaderEvents: { onloadstart: function() { return this.updateStatus('Uploading...'); }, onprogress: function(event) { return this.updateStatus('Uploading...', event.loaded); }, onabort: function() { this.updateStatus('Aborted'); return this.hide(1); }, onload: function() { return this.updateStatus('Successfully uploaded...', this.file.size); }, onerror: function() { this.updateStatus('Error: Unable to upload the file'); return this.hide(3); } } }); Mercury.uploader.File = (function() { function File(file) { var errors; this.file = file; this.fullSize = this.size = this.file.size || this.file.fileSize; this.readableSize = this.size.toBytes(); this.name = this.file.name || this.file.fileName; this.type = this.file.type || this.file.fileType; errors = []; if (this.size >= Mercury.config.uploading.maxFileSize) { errors.push(Mercury.I18n('Too large')); } if (!(Mercury.config.uploading.allowedMimeTypes.indexOf(this.type) > -1)) { errors.push(Mercury.I18n('Unsupported format')); } if (errors.length) { this.errors = errors.join(' / '); } } File.prototype.readAsDataURL = function(callback) { var reader, _this = this; if (callback == null) { callback = null; } reader = new FileReader(); reader.readAsDataURL(this.file); return reader.onload = function() { if (callback) { return callback(reader.result); } }; }; File.prototype.readAsBinaryString = function(callback) { var reader, _this = this; if (callback == null) { callback = null; } reader = new FileReader(); reader.readAsBinaryString(this.file); return reader.onload = function() { if (callback) { return callback(reader.result); } }; }; File.prototype.updateSize = function(delta) { return this.fullSize = this.size + delta; }; return File; })(); Mercury.uploader.MultiPartPost = (function() { function MultiPartPost(inputName, file, contents, formInputs) { this.inputName = inputName; this.file = file; this.contents = contents; this.formInputs = formInputs != null ? formInputs : {}; this.boundary = 'Boundaryx20072377098235644401115438165x'; this.body = ''; this.buildBody(); this.delta = this.body.length - this.file.size; } MultiPartPost.prototype.buildBody = function() { var boundary, name, value, _ref; boundary = '--' + this.boundary; _ref = this.formInputs; for (name in _ref) { if (!__hasProp.call(_ref, name)) continue; value = _ref[name]; this.body += "" + boundary + "\r\nContent-Disposition: form-data; name=\"" + name + "\"\r\n\r\n" + (unescape(encodeURIComponent(value))) + "\r\n"; } return this.body += "" + boundary + "\r\nContent-Disposition: form-data; name=\"" + this.inputName + "\"; filename=\"" + this.file.name + "\"\r\nContent-Type: " + this.file.type + "\r\nContent-Transfer-Encoding: binary\r\n\r\n" + this.contents + "\r\n" + boundary + "--"; }; return MultiPartPost; })(); }).call(this); (function() { var __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; }, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; this.Mercury.Regions.Full = (function(_super) { var type; __extends(Full, _super); Full.supported = document.designMode && !jQuery.browser.konqueror && (!jQuery.browser.msie || (jQuery.browser.msie && parseFloat(jQuery.browser.version, 10) >= 10)); Full.supportedText = "Chrome 10+, Firefox 4+, Safari 5+, Opera 11.64+"; type = 'full'; Full.prototype.type = function() { return type; }; function Full(element, window, options) { this.element = element; this.window = window; this.options = options != null ? options : {}; Full.__super__.constructor.apply(this, arguments); } Full.prototype.build = function() { var e, element, _i, _len, _ref; if (jQuery.browser.mozilla && this.content() === '') { this.content(' '); } this.element.data({ originalOverflow: this.element.css('overflow') }); this.element.css({ overflow: 'auto' }); this.specialContainer = jQuery.browser.mozilla && this.element.get(0).tagName !== 'DIV'; this.element.get(0).contentEditable = true; _ref = this.element.find('[data-snippet]'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { element = _ref[_i]; element.contentEditable = false; jQuery(element).attr('data-version', '1'); } if (!this.document.mercuryEditing) { this.document.mercuryEditing = true; try { this.document.execCommand('styleWithCSS', false, false); this.document.execCommand('insertBROnReturn', false, true); this.document.execCommand('enableInlineTableEditing', false, false); return this.document.execCommand('enableObjectResizing', false, false); } catch (_error) { e = _error; } } }; Full.prototype.bindEvents = function() { var _this = this; Full.__super__.bindEvents.apply(this, arguments); Mercury.on('region:update', function() { var anchor, currentElement, table; if (_this.previewing || Mercury.region !== _this) { return; } setTimeout((function() { return _this.selection().forceSelection(_this.element.get(0)); }), 1); currentElement = _this.currentElement(); if (currentElement.length) { table = currentElement.closest('table', _this.element); if (table.length) { Mercury.tableEditor(table, currentElement.closest('tr, td'), '<br/>'); } anchor = currentElement.closest('a', _this.element); if (anchor.length && anchor.attr('href')) { return Mercury.tooltip(anchor, "<a href=\"" + (anchor.attr('href')) + "\" target=\"_blank\">" + (anchor.attr('href')) + "</a>", { position: 'below' }); } else { return Mercury.tooltip.hide(); } } }); this.element.on('dragenter', function(event) { if (_this.previewing) { return; } if (!Mercury.snippet) { event.preventDefault(); } return event.originalEvent.dataTransfer.dropEffect = 'copy'; }); this.element.on('dragover', function(event) { if (_this.previewing) { return; } if (!Mercury.snippet) { event.preventDefault(); } return event.originalEvent.dataTransfer.dropEffect = 'copy'; }); this.element.on('drop', function(event) { if (_this.previewing) { return; } clearTimeout(_this.dropTimeout); _this.dropTimeout = setTimeout((function() { return _this.element.trigger('possible:drop'); }), 1); if (!event.originalEvent.dataTransfer.files.length) { return; } event.preventDefault(); _this.focus(); return Mercury.uploader(event.originalEvent.dataTransfer.files[0]); }); this.element.on('possible:drop', function() { if (_this.previewing) { return; } if (Mercury.snippet) { _this.focus(); Mercury.Snippet.displayOptionsFor(Mercury.snippet.name, {}, Mercury.snippet.hasOptions); return _this.document.execCommand('undo', false, null); } }); this.element.on('paste', function(event) { if (_this.previewing || Mercury.region !== _this) { return; } if (_this.specialContainer) { event.preventDefault(); return; } if (_this.pasting) { return; } Mercury.changes = true; return _this.handlePaste(event.originalEvent); }); this.element.on('focus', function() { if (_this.previewing) { return; } Mercury.region = _this; setTimeout((function() { return _this.selection().forceSelection(_this.element.get(0)); }), 1); return Mercury.trigger('region:focused', { region: _this }); }); this.element.on('blur', function() { if (_this.previewing) { return; } Mercury.trigger('region:blurred', { region: _this }); return Mercury.tooltip.hide(); }); this.element.on('click', function(event) { if (_this.previewing) { return jQuery(event.target).closest('a').attr('target', '_parent'); } }); this.element.on('dblclick', function(event) { var image; if (_this.previewing) { return; } image = jQuery(event.target).closest('img', _this.element); if (image.length) { _this.selection().selectNode(image.get(0), true); return Mercury.trigger('button', { action: 'insertMedia' }); } }); this.element.on('mouseup', function() { if (_this.previewing) { return; } _this.pushHistory(); return Mercury.trigger('region:update', { region: _this }); }); this.element.on('keydown', function(event) { var container; if (_this.previewing) { return; } switch (event.keyCode) { case 90: if (!event.metaKey) { return; } event.preventDefault(); if (event.shiftKey) { _this.execCommand('redo'); } else { _this.execCommand('undo'); } return; case 13: if (jQuery.browser.webkit && _this.selection().commonAncestor().closest('li, ul, ol', _this.element).length === 0) { event.preventDefault(); _this.document.execCommand('insertParagraph', false, null); } else if (_this.specialContainer || jQuery.browser.opera) { event.preventDefault(); _this.document.execCommand('insertHTML', false, '<br/>'); } break; case 9: event.preventDefault(); container = _this.selection().commonAncestor(); if (container.closest('li', _this.element).length) { if (!event.shiftKey) { _this.execCommand('indent'); } else if (container.parents('ul, ol').length > 1) { _this.execCommand('outdent'); } } else { _this.execCommand('insertHTML', { value: ' ' }); } } if (event.metaKey) { switch (event.keyCode) { case 66: _this.execCommand('bold'); event.preventDefault(); break; case 73: _this.execCommand('italic'); event.preventDefault(); break; case 85: _this.execCommand('underline'); event.preventDefault(); } } return _this.pushHistory(event.keyCode); }); return this.element.on('keyup', function() { if (_this.previewing) { return; } Mercury.trigger('region:update', { region: _this }); return Mercury.changes = true; }); }; Full.prototype.focus = function() { var e, _this = this; if (Mercury.region !== this) { setTimeout((function() { return _this.element.focus(); }), 10); try { this.selection().selection.collapseToStart(); } catch (_error) { e = _error; } } else { setTimeout((function() { return _this.element.focus(); }), 10); } Mercury.trigger('region:focused', { region: this }); return Mercury.trigger('region:update', { region: this }); }; Full.prototype.content = function(value, filterSnippets, includeMarker) { var container, content, element, error, index, selection, snippet, version, _i, _j, _len, _len1, _ref, _ref1; if (value == null) { value = null; } if (filterSnippets == null) { filterSnippets = true; } if (includeMarker == null) { includeMarker = false; } if (value !== null) { container = jQuery('<div>').appendTo(this.document.createDocumentFragment()); container.html(value); _ref = container.find('[data-snippet]'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { element = _ref[_i]; element.contentEditable = false; element = jQuery(element); if (snippet = Mercury.Snippet.find(element.data('snippet'))) { if (element.data('version')) { snippet.setVersion(element.data('version')); } else { try { version = parseInt(element.html().match(/\/(\d+)\]/)[1]); if (version) { snippet.setVersion(version); element.attr({ 'data-version': version }); element.html(snippet.data); } } catch (_error) { error = _error; } } } } this.element.html(container.html()); return this.selection().selectMarker(this.element); } else { this.element.find('meta').remove(); if (includeMarker) { selection = this.selection(); selection.placeMarker(); } container = jQuery('<div>').appendTo(this.document.createDocumentFragment()); container.html(this.element.html().replace(/^\s+|\s+$/g, '')); if (filterSnippets) { _ref1 = container.find('[data-snippet]'); for (index = _j = 0, _len1 = _ref1.length; _j < _len1; index = ++_j) { element = _ref1[index]; element = jQuery(element); if (snippet = Mercury.Snippet.find(element.data("snippet"))) { snippet.data = element.html(); } element.html("[" + (element.data("snippet")) + "/" + (element.data("version")) + "]"); element.attr({ contenteditable: null, 'data-version': null }); } } content = container.html(); if (includeMarker) { selection.removeMarker(); } return content; } }; Full.prototype.togglePreview = function() { if (this.previewing) { this.element.get(0).contentEditable = true; this.element.css({ overflow: 'auto' }); } else { this.content(this.content()); this.element.get(0).contentEditable = false; this.element.css({ overflow: this.element.data('originalOverflow') }); this.element.blur(); } return Full.__super__.togglePreview.apply(this, arguments); }; Full.prototype.execCommand = function(action, options) { var error, handler, sibling; if (options == null) { options = {}; } Full.__super__.execCommand.apply(this, arguments); if (handler = Mercury.config.behaviors[action] || Mercury.Regions.Full.actions[action]) { handler.call(this, this.selection(), options); } else { if (action === 'indent') { sibling = this.element.get(0).previousSibling; } if (action === 'insertHTML' && options.value && options.value.get) { options.value = jQuery('<div>').html(options.value).html(); } try { this.document.execCommand(action, false, options.value); } catch (_error) { error = _error; if (action === 'indent' && this.element.prev() !== sibling) { this.element.prev().remove(); } } } return this.element.find('img').one('error', function() { return jQuery(this).attr({ src: '/assets/mercury/missing-image.png', title: 'Image not found' }); }); }; Full.prototype.pushHistory = function(keyCode) { var keyCodes, knownKeyCode, waitTime, _this = this; keyCodes = [13, 46, 8]; waitTime = 2.5; if (keyCode) { knownKeyCode = keyCodes.indexOf(keyCode); } clearTimeout(this.historyTimeout); if (knownKeyCode >= 0 && knownKeyCode !== this.lastKnownKeyCode) { this.history.push(this.content(null, false, true)); } else if (keyCode) { this.historyTimeout = setTimeout((function() { return _this.history.push(_this.content(null, false, true)); }), waitTime * 1000); } else { this.history.push(this.content(null, false, true)); } return this.lastKnownKeyCode = knownKeyCode; }; Full.prototype.selection = function() { return new Mercury.Regions.Full.Selection(this.window.getSelection(), this.document); }; Full.prototype.path = function() { var container; container = this.selection().commonAncestor(); if (!container) { return []; } if (container.get(0) === this.element.get(0)) { return []; } else { return container.parentsUntil(this.element); } }; Full.prototype.currentElement = function() { var element, selection; element = []; selection = this.selection(); if (selection.range) { element = selection.commonAncestor(); if (element.get(0).nodeType === 3) { element = element.parent(); } } return element; }; Full.prototype.handlePaste = function(event) { var sanitizer, selection, _this = this; if (Mercury.config.pasting.sanitize === 'text' && event.clipboardData) { this.execCommand('insertHTML', { value: event.clipboardData.getData('text/plain') }); event.preventDefault(); } else { selection = this.selection(); selection.placeMarker(); sanitizer = jQuery('#mercury_sanitizer', this.document).focus(); return setTimeout(function() { var content; content = _this.sanitize(sanitizer); selection.selectMarker(_this.element); selection.removeMarker(); _this.element.focus(); return _this.execCommand('insertHTML', { value: content }); }, 1); } }; Full.prototype.sanitize = function(sanitizer) { var allowed, allowedAttributes, allowedTag, attr, content, element, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3; sanitizer.find("[" + Mercury.config.regions.attribute + "]").remove(); sanitizer.find('[src*="webkit-fake-url://"]').remove(); if (Mercury.config.pasting.sanitize) { switch (Mercury.config.pasting.sanitize) { case 'blacklist': sanitizer.find('[style]').removeAttr('style'); sanitizer.find('[class="Apple-style-span"]').removeClass('Apple-style-span'); content = sanitizer.html(); break; case 'whitelist': _ref = sanitizer.find('*'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { element = _ref[_i]; allowed = false; _ref1 = Mercury.config.pasting.whitelist; for (allowedTag in _ref1) { allowedAttributes = _ref1[allowedTag]; if (element.tagName.toLowerCase() === allowedTag.toLowerCase()) { allowed = true; _ref2 = jQuery(element.attributes); for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { attr = _ref2[_j]; if (_ref3 = attr.name, __indexOf.call(allowedAttributes, _ref3) < 0) { jQuery(element).removeAttr(attr.name); } } break; } } if (!allowed) { jQuery(element).replaceWith(jQuery(element).contents()); } } content = sanitizer.html(); break; default: content = sanitizer.text(); } } else { content = sanitizer.html(); if (content.indexOf('<!--StartFragment-->') > -1 || content.indexOf('="mso-') > -1 || content.indexOf('<o:') > -1 || content.indexOf('="Mso') > -1) { content = sanitizer.text(); } } sanitizer.html(''); return content; }; Full.actions = { insertRowBefore: function() { return Mercury.tableEditor.addRow('before'); }, insertRowAfter: function() { return Mercury.tableEditor.addRow('after'); }, insertColumnBefore: function() { return Mercury.tableEditor.addColumn('before'); }, insertColumnAfter: function() { return Mercury.tableEditor.addColumn('after'); }, deleteColumn: function() { return Mercury.tableEditor.removeColumn(); }, deleteRow: function() { return Mercury.tableEditor.removeRow(); }, increaseColspan: function() { return Mercury.tableEditor.increaseColspan(); }, decreaseColspan: function() { return Mercury.tableEditor.decreaseColspan(); }, increaseRowspan: function() { return Mercury.tableEditor.increaseRowspan(); }, decreaseRowspan: function() { return Mercury.tableEditor.decreaseRowspan(); }, undo: function() { return this.content(this.history.undo()); }, redo: function() { return this.content(this.history.redo()); }, horizontalRule: function() { return this.execCommand('insertHTML', { value: '<hr/>' }); }, removeFormatting: function(selection) { return selection.insertTextNode(selection.textContent()); }, backColor: function(selection, options) { return selection.wrap("<span style=\"background-color:" + (options.value.toHex()) + "\">", true); }, overline: function(selection) { return selection.wrap('<span style="text-decoration:overline">', true); }, style: function(selection, options) { return selection.wrap("<span class=\"" + options.value + "\">", true); }, replaceHTML: function(selection, options) { return this.content(options.value); }, insertImage: function(selection, options) { return this.execCommand('insertHTML', { value: jQuery('<img/>', options.value) }); }, insertTable: function(selection, options) { return this.execCommand('insertHTML', { value: options.value }); }, insertLink: function(selection, options) { var anchor; anchor = jQuery("<" + options.value.tagName + ">", this.document).attr(options.value.attrs).html(options.value.content); return selection.insertNode(anchor); }, replaceLink: function(selection, options) { var anchor, html; anchor = jQuery("<" + options.value.tagName + ">", this.document).attr(options.value.attrs).html(options.value.content); selection.selectNode(options.node); html = jQuery('<div>').html(selection.content()).find('a').html(); return selection.replace(jQuery(anchor, selection.context).html(html)); }, insertSnippet: function(selection, options) { var existing, snippet; snippet = options.value; if ((existing = this.element.find("[data-snippet=" + snippet.identity + "]")).length) { selection.selectNode(existing.get(0)); } return selection.insertNode(snippet.getHTML(this.document)); }, editSnippet: function() { var snippet; if (!this.snippet) { return; } snippet = Mercury.Snippet.find(this.snippet.data('snippet')); return snippet.displayOptions(); }, removeSnippet: function() { if (this.snippet) { this.snippet.remove(); } return Mercury.trigger('hide:toolbar', { type: 'snippet', immediately: true }); } }; return Full; })(Mercury.Region); Mercury.Regions.Full.Selection = (function() { function Selection(selection, context) { this.selection = selection; this.context = context; if (!(this.selection.rangeCount >= 1)) { return; } this.range = this.selection.getRangeAt(0); this.fragment = this.range.cloneContents(); this.clone = this.range.cloneRange(); this.collapsed = this.selection.isCollapsed; } Selection.prototype.commonAncestor = function(onlyTag) { var ancestor; if (onlyTag == null) { onlyTag = false; } if (!this.range) { return null; } ancestor = this.range.commonAncestorContainer; if (ancestor.nodeType === 3 && onlyTag) { ancestor = ancestor.parentNode; } return jQuery(ancestor); }; Selection.prototype.wrap = function(element, replace) { if (replace == null) { replace = false; } element = jQuery(element, this.context).html(this.fragment); if (replace) { this.replace(element); } return element; }; Selection.prototype.textContent = function() { return this.content().textContent; }; Selection.prototype.htmlContent = function() { var content; content = this.content(); return jQuery('<div>').html(content).html(); return null; }; Selection.prototype.content = function() { return this.range.cloneContents(); }; Selection.prototype.is = function(elementType) { var content; content = this.content(); if (jQuery(content).length === 1 && jQuery(content.firstChild).is(elementType)) { return jQuery(content.firstChild); } return false; }; Selection.prototype.forceSelection = function(element) { var lastChild, range; if (!jQuery.browser.webkit) { return; } range = this.context.createRange(); if (this.range) { if (this.commonAncestor(true).closest('[data-snippet]').length) { lastChild = this.context.createTextNode("\x00"); element.appendChild(lastChild); } } else { if (element.lastChild && element.lastChild.nodeType === 3 && element.lastChild.textContent.replace(/^[\s+|\n+]|[\s+|\n+]$/, '') === '') { lastChild = element.lastChild; element.lastChild.textContent = "\x00"; } else { lastChild = this.context.createTextNode("\x00"); element.appendChild(lastChild); } } if (lastChild) { range.setStartBefore(lastChild); range.setEndBefore(lastChild); return this.selection.addRange(range); } }; Selection.prototype.selectMarker = function(context) { var markers, range; markers = context.find('em.mercury-marker'); if (!markers.length) { return; } range = this.context.createRange(); range.setStartBefore(markers.get(0)); if (markers.length >= 2) { range.setEndBefore(markers.get(1)); } markers.remove(); this.selection.removeAllRanges(); return this.selection.addRange(range); }; Selection.prototype.placeMarker = function() { var rangeEnd, rangeStart; if (!this.range) { return; } this.startMarker = jQuery('<em class="mercury-marker"/>', this.context).get(0); this.endMarker = jQuery('<em class="mercury-marker"/>', this.context).get(0); rangeEnd = this.range.cloneRange(); rangeEnd.collapse(false); rangeEnd.insertNode(this.endMarker); if (!this.range.collapsed) { rangeStart = this.range.cloneRange(); rangeStart.collapse(true); rangeStart.insertNode(this.startMarker); } this.selection.removeAllRanges(); return this.selection.addRange(this.range); }; Selection.prototype.removeMarker = function() { jQuery(this.startMarker).remove(); return jQuery(this.endMarker).remove(); }; Selection.prototype.insertTextNode = function(string) { var node; node = this.context.createTextNode(string); this.range.extractContents(); this.range.insertNode(node); this.range.selectNodeContents(node); return this.selection.addRange(this.range); }; Selection.prototype.insertNode = function(element) { if (element.get) { element = element.get(0); } if (jQuery.type(element) === 'string') { element = jQuery(element, this.context).get(0); } this.range.deleteContents(); this.range.insertNode(element); this.range.selectNodeContents(element); return this.selection.addRange(this.range); }; Selection.prototype.selectNode = function(node, removeExisting) { if (removeExisting == null) { removeExisting = false; } this.range.selectNode(node); if (removeExisting) { this.selection.removeAllRanges(); } return this.selection.addRange(this.range); }; Selection.prototype.replace = function(element, collapse) { if (element.get) { element = element.get(0); } if (jQuery.type(element) === 'string') { element = jQuery(element, this.context).get(0); } this.range.deleteContents(); this.range.insertNode(element); this.range.selectNodeContents(element); this.selection.addRange(this.range); if (collapse) { return this.range.collapse(false); } }; return Selection; })(); }).call(this); (function() { var __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; }; this.Mercury.Regions.Image = (function(_super) { var type; __extends(Image, _super); Image.supported = document.getElementById; Image.supportedText = "Chrome 10+, Firefox 4+, IE 7+, Safari 5+, Opera 8+"; type = 'image'; Image.prototype.type = function() { return type; }; function Image(element, window, options) { this.element = element; this.window = window; this.options = options != null ? options : {}; Image.__super__.constructor.apply(this, arguments); } Image.prototype.bindEvents = function() { var _this = this; Mercury.on('mode', function(event, options) { if (options.mode === 'preview') { return _this.togglePreview(); } }); Mercury.on('focus:frame', function() { if (_this.previewing || Mercury.region !== _this) { return; } return _this.focus(); }); Mercury.on('action', function(event, options) { if (_this.previewing || Mercury.region !== _this) { return; } if (options.action) { return _this.execCommand(options.action, options); } }); this.element.on('dragenter', function(event) { if (_this.previewing) { return; } event.preventDefault(); return event.originalEvent.dataTransfer.dropEffect = 'copy'; }); this.element.on('dragover', function(event) { if (_this.previewing) { return; } event.preventDefault(); return event.originalEvent.dataTransfer.dropEffect = 'copy'; }); this.element.on('drop', function(event) { if (_this.previewing) { return; } if (event.originalEvent.dataTransfer.files.length) { event.preventDefault(); _this.focus(); return Mercury.uploader(event.originalEvent.dataTransfer.files[0]); } }); return this.element.on('focus', function() { return _this.focus(); }); }; Image.prototype.togglePreview = function() { if (this.previewing) { this.previewing = false; this.element.attr(Mercury.config.regions.attribute, type); return this.build(); } else { this.previewing = true; this.element.removeAttr(Mercury.config.regions.attribute); return Mercury.trigger('region:blurred', { region: this }); } }; Image.prototype.focus = function() { if (this.previewing) { return; } Mercury.region = this; Mercury.trigger('region:focused', { region: this }); return Mercury.trigger('region:update', { region: this }); }; Image.prototype.execCommand = function(action, options) { var handler; if (options == null) { options = {}; } Image.__super__.execCommand.apply(this, arguments); if (handler = Mercury.Regions.Image.actions[action]) { return handler.call(this, options); } }; Image.prototype.pushHistory = function() { return this.history.push({ src: this.element.attr('src') }); }; Image.prototype.updateSrc = function(src) { return this.element.attr('src', src); }; Image.prototype.serialize = function() { return { type: type, data: this.dataAttributes(), attributes: { src: this.element.attr('src') } }; }; Image.actions = { undo: function() { var prev; if (prev = this.history.undo()) { return this.updateSrc(prev.src); } }, redo: function() { var next; if (next = this.history.redo()) { return this.updateSrc(next.src); } }, insertImage: function(options) { return this.updateSrc(options.value.src); } }; return Image; })(Mercury.Region); }).call(this); (function() { var __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; }; this.Mercury.Regions.Markdown = (function(_super) { var type; __extends(Markdown, _super); Markdown.supported = document.getElementById; Markdown.supportedText = "Chrome 10+, Firefox 4+, IE 7+, Safari 5+, Opera 8+"; type = 'markdown'; Markdown.prototype.type = function() { return type; }; function Markdown(element, window, options) { this.element = element; this.window = window; this.options = options != null ? options : {}; Markdown.__super__.constructor.apply(this, arguments); this.converter = new Showdown.converter(); } Markdown.prototype.build = function() { var height, value, width; width = '100%'; height = this.element.height(); value = this.element.html().replace(/^\s+|\s+$/g, '').replace('>', '>'); this.textarea = jQuery('<textarea>', this.document).val(value).addClass('mercury-textarea'); this.textarea.css({ border: 0, background: 'transparent', display: 'block', 'overflow-y': 'hidden', width: width, height: height, fontFamily: '"Courier New", Courier, monospace' }); this.element.empty().append(this.textarea); this.previewElement = jQuery('<div>', this.document); this.element.append(this.previewElement); this.container = this.element; this.container.data('region', this); this.element = this.textarea; return this.resize(); }; Markdown.prototype.dataAttributes = function() { var attr, data, _i, _len, _ref; data = {}; _ref = Mercury.config.regions.dataAttributes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { attr = _ref[_i]; data[attr] = this.container.attr('data-' + attr); } return data; }; Markdown.prototype.bindEvents = function() { var _this = this; Mercury.on('mode', function(event, options) { if (options.mode === 'preview') { return _this.togglePreview(); } }); Mercury.on('focus:frame', function() { if (!_this.previewing && Mercury.region === _this) { return _this.focus(); } }); Mercury.on('action', function(event, options) { if (_this.previewing || Mercury.region !== _this) { return; } if (options.action) { return _this.execCommand(options.action, options); } }); Mercury.on('unfocus:regions', function() { if (_this.previewing || Mercury.region !== _this) { return; } _this.element.blur(); _this.container.removeClass('focus'); return Mercury.trigger('region:blurred', { region: _this }); }); this.element.on('dragenter', function(event) { if (_this.previewing) { return; } event.preventDefault(); return event.originalEvent.dataTransfer.dropEffect = 'copy'; }); this.element.on('dragover', function(event) { if (_this.previewing) { return; } event.preventDefault(); return event.originalEvent.dataTransfer.dropEffect = 'copy'; }); this.element.on('drop', function(event) { if (_this.previewing) { return; } if (Mercury.snippet) { event.preventDefault(); _this.focus(); Mercury.Snippet.displayOptionsFor(Mercury.snippet.name, {}, Mercury.snippet.hasOptions); } if (event.originalEvent.dataTransfer.files.length) { event.preventDefault(); _this.focus(); return Mercury.uploader(event.originalEvent.dataTransfer.files[0]); } }); this.element.on('focus', function() { if (_this.previewing) { return; } Mercury.region = _this; _this.container.addClass('focus'); return Mercury.trigger('region:focused', { region: _this }); }); this.element.on('keydown', function(event) { var end, lineText, number, selection, start, text; if (_this.previewing) { return; } _this.resize(); switch (event.keyCode) { case 90: if (!event.metaKey) { return; } event.preventDefault(); if (event.shiftKey) { _this.execCommand('redo'); } else { _this.execCommand('undo'); } return; case 13: selection = _this.selection(); text = _this.element.val(); start = text.lastIndexOf('\n', selection.start); end = text.indexOf('\n', selection.end); if (end < start) { end = text.length; } if (text[start] === '\n') { start = text.lastIndexOf('\n', selection.start - 1); } if (text[start + 1] === '-') { selection.replace('\n- ', false, true); event.preventDefault(); } if (/\d/.test(text[start + 1])) { lineText = text.substring(start, end); if (/(\d+)\./.test(lineText)) { number = parseInt(RegExp.$1); selection.replace("\n" + (number += 1) + ". ", false, true); event.preventDefault(); } } break; case 9: event.preventDefault(); _this.execCommand('insertHTML', { value: ' ' }); } if (event.metaKey) { switch (event.keyCode) { case 66: _this.execCommand('bold'); event.preventDefault(); break; case 73: _this.execCommand('italic'); event.preventDefault(); break; case 85: _this.execCommand('underline'); event.preventDefault(); } } return _this.pushHistory(event.keyCode); }); this.element.on('keyup', function() { if (_this.previewing) { return; } Mercury.changes = true; _this.resize(); return Mercury.trigger('region:update', { region: _this }); }); this.element.on('mouseup', function() { if (_this.previewing) { return; } _this.focus(); return Mercury.trigger('region:focused', { region: _this }); }); return this.previewElement.on('click', function(event) { if (_this.previewing) { return $(event.target).closest('a').attr('target', '_parent'); } }); }; Markdown.prototype.focus = function() { return this.element.focus(); }; Markdown.prototype.content = function(value, filterSnippets) { if (value == null) { value = null; } if (filterSnippets == null) { filterSnippets = true; } if (value !== null) { if (jQuery.type(value) === 'string') { return this.element.val(value); } else { this.element.val(value.html); return this.selection().select(value.selection.start, value.selection.end); } } else { return this.element.val(); } }; Markdown.prototype.contentAndSelection = function() { return { html: this.content(null, false), selection: this.selection().serialize() }; }; Markdown.prototype.togglePreview = function() { var value; if (this.previewing) { this.previewing = false; this.container.attr(Mercury.config.regions.attribute, type); this.previewElement.hide(); this.element.show(); if (Mercury.region === this) { return this.focus(); } } else { this.previewing = true; this.container.removeAttr(Mercury.config.regions.attribute); value = this.converter.makeHtml(this.element.val()); this.previewElement.html(value); this.previewElement.show(); this.element.hide(); return Mercury.trigger('region:blurred', { region: this }); } }; Markdown.prototype.execCommand = function(action, options) { var handler; if (options == null) { options = {}; } Markdown.__super__.execCommand.apply(this, arguments); if (handler = Mercury.Regions.Markdown.actions[action]) { handler.call(this, this.selection(), options); } return this.resize(); }; Markdown.prototype.pushHistory = function(keyCode) { var keyCodes, knownKeyCode, waitTime, _this = this; keyCodes = [13, 46, 8]; waitTime = 2.5; if (keyCode) { knownKeyCode = keyCodes.indexOf(keyCode); } clearTimeout(this.historyTimeout); if (knownKeyCode >= 0 && knownKeyCode !== this.lastKnownKeyCode) { this.history.push(this.contentAndSelection()); } else if (keyCode) { this.historyTimeout = setTimeout((function() { return _this.history.push(_this.contentAndSelection()); }), waitTime * 1000); } else { this.history.push(this.contentAndSelection()); } return this.lastKnownKeyCode = knownKeyCode; }; Markdown.prototype.selection = function() { return new Mercury.Regions.Markdown.Selection(this.element); }; Markdown.prototype.resize = function() { this.element.css({ height: this.element.get(0).scrollHeight - 100 }); return this.element.css({ height: this.element.get(0).scrollHeight }); }; Markdown.prototype.snippets = function() {}; Markdown.actions = { undo: function() { return this.content(this.history.undo()); }, redo: function() { return this.content(this.history.redo()); }, insertHTML: function(selection, options) { var element; if (options.value.get && (element = options.value.get(0))) { options.value = jQuery('<div>').html(element).html(); } return selection.replace(options.value, false, true); }, insertImage: function(selection, options) { return selection.replace(' + ')', true); }, insertTable: function(selection, options) { return selection.replace(options.value.replace(/<br>|<br\/>/ig, ''), false, true); }, insertLink: function(selection, options) { return selection.replace("[" + options.value.content + "](" + options.value.attrs.href + " 'optional title')", true); }, insertUnorderedList: function(selection) { return selection.addList('unordered'); }, insertOrderedList: function(selection) { return selection.addList('ordered'); }, style: function(selection, options) { return selection.wrap("<span class=\"" + options.value + "\">", '</span>'); }, formatblock: function(selection, options) { var wrapper, wrapperName, wrappers; wrappers = { h1: ['# ', ' #'], h2: ['## ', ' ##'], h3: ['### ', ' ###'], h4: ['#### ', ' ####'], h5: ['##### ', ' #####'], h6: ['###### ', ' ######'], pre: [' ', ''], blockquote: ['> ', ''], p: ['\n', '\n'] }; for (wrapperName in wrappers) { wrapper = wrappers[wrapperName]; selection.unWrapLine("" + wrapper[0], "" + wrapper[1]); } if (options.value === 'blockquote') { Mercury.Regions.Markdown.actions.indent.call(this, selection, options); return; } return selection.wrapLine("" + wrappers[options.value][0], "" + wrappers[options.value][1]); }, bold: function(selection) { return selection.wrap('**', '**'); }, italic: function(selection) { return selection.wrap('_', '_'); }, subscript: function(selection) { return selection.wrap('<sub>', '</sub>'); }, superscript: function(selection) { return selection.wrap('<sup>', '</sup>'); }, indent: function(selection) { return selection.wrapLine('> ', '', false, true); }, outdent: function(selection) { return selection.unWrapLine('> ', '', false, true); }, horizontalRule: function(selection) { return selection.replace('\n- - -\n'); }, insertSnippet: function(selection, options) { var snippet; snippet = options.value; return selection.replace(snippet.getText()); } }; return Markdown; })(Mercury.Region); Mercury.Regions.Markdown.Selection = (function() { function Selection(element) { this.element = element; this.el = this.element.get(0); this.getDetails(); } Selection.prototype.serialize = function() { return { start: this.start, end: this.end }; }; Selection.prototype.getDetails = function() { this.length = this.el.selectionEnd - this.el.selectionStart; this.start = this.el.selectionStart; this.end = this.el.selectionEnd; return this.text = this.element.val().substr(this.start, this.length); }; Selection.prototype.replace = function(text, select, placeCursor) { var changed, savedVal, val; if (select == null) { select = false; } if (placeCursor == null) { placeCursor = false; } this.getDetails(); val = this.element.val(); savedVal = this.element.val(); this.element.val(val.substr(0, this.start) + text + val.substr(this.end, val.length)); changed = this.element.val() !== savedVal; if (select) { this.select(this.start, this.start + text.length); } if (placeCursor) { this.select(this.start + text.length, this.start + text.length); } return changed; }; Selection.prototype.select = function(start, end) { this.start = start; this.end = end; this.element.focus(); this.el.selectionStart = this.start; this.el.selectionEnd = this.end; return this.getDetails(); }; Selection.prototype.wrap = function(left, right) { this.getDetails(); this.deselectNewLines(); this.replace(left + this.text + right, this.text !== ''); if (this.text === '') { return this.select(this.start + left.length, this.start + left.length); } }; Selection.prototype.wrapLine = function(left, right, selectAfter, reselect) { var end, savedSelection, start, text; if (selectAfter == null) { selectAfter = true; } if (reselect == null) { reselect = false; } this.getDetails(); savedSelection = this.serialize(); text = this.element.val(); start = text.lastIndexOf('\n', this.start); end = text.indexOf('\n', this.end); if (end < start) { end = text.length; } if (text[start] === '\n') { start = text.lastIndexOf('\n', this.start - 1); } this.select(start + 1, end); this.replace(left + this.text + right, selectAfter); if (reselect) { return this.select(savedSelection.start + left.length, savedSelection.end + left.length); } }; Selection.prototype.unWrapLine = function(left, right, selectAfter, reselect) { var changed, end, leftRegExp, rightRegExp, savedSelection, start, text; if (selectAfter == null) { selectAfter = true; } if (reselect == null) { reselect = false; } this.getDetails(); savedSelection = this.serialize(); text = this.element.val(); start = text.lastIndexOf('\n', this.start); end = text.indexOf('\n', this.end); if (end < start) { end = text.length; } if (text[start] === '\n') { start = text.lastIndexOf('\n', this.start - 1); } this.select(start + 1, end); window.something = this.text; leftRegExp = new RegExp("^" + (left.regExpEscape())); rightRegExp = new RegExp("" + (right.regExpEscape()) + "$"); changed = this.replace(this.text.replace(leftRegExp, '').replace(rightRegExp, ''), selectAfter); if (reselect && changed) { return this.select(savedSelection.start - left.length, savedSelection.end - left.length); } }; Selection.prototype.addList = function(type) { var end, index, line, lines, start, text; text = this.element.val(); start = text.lastIndexOf('\n', this.start); end = text.indexOf('\n', this.end); if (end < start) { end = text.length; } if (text[start] === '\n') { start = text.lastIndexOf('\n', this.start - 1); } this.select(start + 1, end); lines = this.text.split('\n'); if (type === 'unordered') { return this.replace("- " + lines.join("\n- "), true); } else { return this.replace(((function() { var _i, _len, _results; _results = []; for (index = _i = 0, _len = lines.length; _i < _len; index = ++_i) { line = lines[index]; _results.push("" + (index + 1) + ". " + line); } return _results; })()).join('\n'), true); } }; Selection.prototype.deselectNewLines = function() { var length, text; text = this.text; length = text.replace(/\n+$/g, '').length; return this.select(this.start, this.start + length); }; Selection.prototype.placeMarker = function() { return this.wrap('[mercury-marker]', '[mercury-marker]'); }; Selection.prototype.removeMarker = function() { var end, start, val; val = this.element.val(); start = val.indexOf('[mercury-marker]'); if (!(start > -1)) { return; } end = val.indexOf('[mercury-marker]', start + 1) - '[mercury-marker]'.length; this.element.val(this.element.val().replace(/\[mercury-marker\]/g, '')); return this.select(start, end); }; Selection.prototype.textContent = function() { return this.text; }; return Selection; })(); }).call(this); (function() { var __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; }; this.Mercury.Regions.Simple = (function(_super) { var type; __extends(Simple, _super); Simple.supported = document.getElementById; Simple.supportedText = "Chrome 10+, Firefox 4+, IE 7+, Safari 5+, Opera 8+"; type = 'simple'; Simple.prototype.type = function() { return type; }; function Simple(element, window, options) { this.element = element; this.window = window; this.options = options != null ? options : {}; Mercury.log("building " + type, this.element, this.options); Simple.__super__.constructor.apply(this, arguments); } Simple.prototype.build = function() { var height, value, width; if (this.element.css('display') === 'block') { width = '100%'; height = this.element.height(); } else { width = this.element.width(); height = this.element.height(); } value = this.element.text(); this.textarea = jQuery('<textarea>', this.document).val(value).addClass('mercury-textarea'); this.textarea.css({ border: 0, background: 'transparent', 'overflow-y': 'hidden', width: width, height: height, fontFamily: 'inherit', fontSize: 'inherit', fontWeight: 'inherit', fontStyle: 'inherit', color: 'inherit', 'min-height': 0, padding: '0', margin: 0, 'border-radius': 0, display: 'inherit', lineHeight: 'inherit', textAlign: 'inherit' }); this.element.empty().append(this.textarea); this.container = this.element; this.container.data('region', this); this.element = this.textarea; return this.resize(); }; Simple.prototype.bindEvents = function() { var _this = this; Mercury.on('mode', function(event, options) { if (options.mode === 'preview') { return _this.togglePreview(); } }); Mercury.on('focus:frame', function() { if (!_this.previewing && Mercury.region === _this) { return _this.focus(); } }); Mercury.on('action', function(event, options) { if (_this.previewing || Mercury.region !== _this) { return; } if (options.action) { return _this.execCommand(options.action, options); } }); Mercury.on('unfocus:regions', function() { if (_this.previewing || Mercury.region !== _this) { return; } _this.element.blur(); _this.container.removeClass('focus'); return Mercury.trigger('region:blurred', { region: _this }); }); return this.bindElementEvents(); }; Simple.prototype.bindElementEvents = function() { var _this = this; this.element.on('focus', function() { if (_this.previewing) { return; } Mercury.region = _this; _this.container.addClass('focus'); return Mercury.trigger('region:focused', { region: _this }); }); this.element.on('keydown', function(event) { var end, lineText, number, selection, start, text; if (_this.previewing) { return; } _this.resize(); switch (event.keyCode) { case 90: if (!event.metaKey) { return; } event.preventDefault(); if (event.shiftKey) { _this.execCommand('redo'); } else { _this.execCommand('undo'); } return; case 13: selection = _this.selection(); text = _this.element.val(); start = text.lastIndexOf('\n', selection.start); end = text.indexOf('\n', selection.end); if (end < start) { end = text.length; } if (text[start] === '\n') { start = text.lastIndexOf('\n', selection.start - 1); } if (text[start + 1] === '-') { selection.replace('\n- ', false, true); } if (/\d/.test(text[start + 1])) { lineText = text.substring(start, end); if (/(\d+)\./.test(lineText)) { number = parseInt(RegExp.$1); selection.replace("\n" + (number += 1) + ". ", false, true); } } event.preventDefault(); break; case 9: event.preventDefault(); _this.execCommand('insertHTML', { value: ' ' }); } return _this.pushHistory(event.keyCode); }); this.element.on('keyup', function() { if (_this.previewing) { return; } Mercury.changes = true; _this.resize(); return Mercury.trigger('region:update', { region: _this }); }); this.element.on('mouseup', function() { if (_this.previewing) { return; } _this.focus(); return Mercury.trigger('region:focused', { region: _this }); }); return this.element.on('paste', function(event) { if (_this.previewing || Mercury.region !== _this) { return; } if (_this.specialContainer) { event.preventDefault(); return; } if (_this.pasting) { return; } Mercury.changes = true; return _this.handlePaste(event.originalEvent); }); }; Simple.prototype.handlePaste = function(event) { this.execCommand('insertHTML', { value: event.clipboardData.getData('text/plain').replace(/\n/g, ' ') }); event.preventDefault(); }; Simple.prototype.path = function() { return [this.container.get(0)]; }; Simple.prototype.focus = function() { return this.element.focus(); }; Simple.prototype.content = function(value, filterSnippets) { if (value == null) { value = null; } if (filterSnippets == null) { filterSnippets = true; } if (value !== null) { if (jQuery.type(value) === 'string') { return this.element.val(value); } else { this.element.val(value.html); return this.selection().select(value.selection.start, value.selection.end); } } else { return this.element.val(); } }; Simple.prototype.contentAndSelection = function() { return { html: this.content(null, false), selection: this.selection().serialize() }; }; Simple.prototype.togglePreview = function() { var value; if (this.previewing) { this.previewing = false; this.element = this.container; this.container.attr(Mercury.config.regions.attribute, type); this.build(); this.bindElementEvents(); if (Mercury.region === this) { return this.focus(); } } else { this.previewing = true; value = jQuery('<div></div>').text(this.element.val()).html(); this.container.removeAttr(Mercury.config.regions.attribute); this.container.html(value); return Mercury.trigger('region:blurred', { region: this }); } }; Simple.prototype.execCommand = function(action, options) { var handler; if (options == null) { options = {}; } Simple.__super__.execCommand.apply(this, arguments); if (handler = Mercury.Regions.Simple.actions[action]) { handler.call(this, this.selection(), options); } return this.resize(); }; Simple.prototype.pushHistory = function(keyCode) { var keyCodes, knownKeyCode, waitTime, _this = this; keyCodes = [13, 46, 8]; waitTime = 2.5; if (keyCode) { knownKeyCode = keyCodes.indexOf(keyCode); } clearTimeout(this.historyTimeout); if (knownKeyCode >= 0 && knownKeyCode !== this.lastKnownKeyCode) { this.history.push(this.contentAndSelection()); } else if (keyCode) { this.historyTimeout = setTimeout((function() { return _this.history.push(_this.contentAndSelection()); }), waitTime * 1000); } else { this.history.push(this.contentAndSelection()); } return this.lastKnownKeyCode = knownKeyCode; }; Simple.prototype.selection = function() { return new Mercury.Regions.Simple.Selection(this.element); }; Simple.prototype.resize = function() { this.element.css({ height: this.element.get(0).scrollHeight - 100 }); return this.element.css({ height: this.element.get(0).scrollHeight }); }; Simple.prototype.snippets = function() {}; Simple.actions = { undo: function() { return this.content(this.history.undo()); }, redo: function() { return this.content(this.history.redo()); }, insertHTML: function(selection, options) { var element; if (options.value.get && (element = options.value.get(0))) { options.value = jQuery('<div>').html(element).html(); } return selection.replace(options.value, false, true); } }; return Simple; })(Mercury.Region); Mercury.Regions.Simple.Selection = (function() { function Selection(element) { this.element = element; this.el = this.element.get(0); this.getDetails(); } Selection.prototype.serialize = function() { return { start: this.start, end: this.end }; }; Selection.prototype.getDetails = function() { this.length = this.el.selectionEnd - this.el.selectionStart; this.start = this.el.selectionStart; this.end = this.el.selectionEnd; return this.text = this.element.val().substr(this.start, this.length); }; Selection.prototype.replace = function(text, select, placeCursor) { var changed, savedVal, val; if (select == null) { select = false; } if (placeCursor == null) { placeCursor = false; } this.getDetails(); val = this.element.val(); savedVal = this.element.val(); this.element.val(val.substr(0, this.start) + text + val.substr(this.end, val.length)); changed = this.element.val() !== savedVal; if (select) { this.select(this.start, this.start + text.length); } if (placeCursor) { this.select(this.start + text.length, this.start + text.length); } return changed; }; Selection.prototype.select = function(start, end) { this.start = start; this.end = end; this.element.focus(); this.el.selectionStart = this.start; this.el.selectionEnd = this.end; return this.getDetails(); }; Selection.prototype.wrap = function(left, right) { this.getDetails(); this.deselectNewLines(); this.replace(left + this.text + right, this.text !== ''); if (this.text === '') { return this.select(this.start + left.length, this.start + left.length); } }; Selection.prototype.deselectNewLines = function() { var length, text; text = this.text; length = text.replace(/\n+$/g, '').length; return this.select(this.start, this.start + length); }; Selection.prototype.placeMarker = function() { return this.wrap('[mercury-marker]', '[mercury-marker]'); }; Selection.prototype.removeMarker = function() { var end, start, val; val = this.element.val(); start = val.indexOf('[mercury-marker]'); if (!(start > -1)) { return; } end = val.indexOf('[mercury-marker]', start + 1) - '[mercury-marker]'.length; this.element.val(this.element.val().replace(/\[mercury-marker\]/g, '')); return this.select(start, end); }; Selection.prototype.textContent = function() { return this.text; }; return Selection; })(); }).call(this); (function() { var __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; }; this.Mercury.Regions.Snippets = (function(_super) { var type; __extends(Snippets, _super); Snippets.supported = document.getElementById; Snippets.supportedText = "Chrome 10+, Firefox 4+, IE 7+, Safari 5+, Opera 8+"; type = 'snippets'; Snippets.prototype.type = function() { return type; }; function Snippets(element, window, options) { this.element = element; this.window = window; this.options = options != null ? options : {}; Mercury.log("building " + type, this.element, this.options); Snippets.__super__.constructor.apply(this, arguments); this.makeSortable(); } Snippets.prototype.build = function() { var snippet, _i, _len, _ref; _ref = this.element.find('[data-snippet]'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { snippet = _ref[_i]; jQuery(snippet).attr('data-version', 0); } if (this.element.css('minHeight') === '0px') { return this.element.css({ minHeight: 20 }); } }; Snippets.prototype.bindEvents = function() { var _this = this; Snippets.__super__.bindEvents.apply(this, arguments); Mercury.on('unfocus:regions', function(event) { if (_this.previewing) { return; } if (Mercury.region === _this) { _this.element.removeClass('focus'); _this.element.sortable('destroy'); return Mercury.trigger('region:blurred', { region: _this }); } }); Mercury.on('focus:window', function(event) { if (_this.previewing) { return; } if (Mercury.region === _this) { _this.element.removeClass('focus'); _this.element.sortable('destroy'); return Mercury.trigger('region:blurred', { region: _this }); } }); this.element.on('mouseup', function() { if (_this.previewing) { return; } _this.focus(); return Mercury.trigger('region:focused', { region: _this }); }); this.element.on('dragover', function(event) { if (_this.previewing) { return; } event.preventDefault(); return event.originalEvent.dataTransfer.dropEffect = 'copy'; }); this.element.on('drop', function(event) { if (_this.previewing || !Mercury.snippet) { return; } _this.focus(); event.preventDefault(); return Mercury.Snippet.displayOptionsFor(Mercury.snippet.name, {}, Mercury.snippet.hasOptions); }); jQuery(this.document).on('keydown', function(event) { if (_this.previewing || Mercury.region !== _this) { return; } switch (event.keyCode) { case 90: if (!event.metaKey) { return; } event.preventDefault(); if (event.shiftKey) { return _this.execCommand('redo'); } else { return _this.execCommand('undo'); } } }); return jQuery(this.document).on('keyup', function() { if (_this.previewing || Mercury.region !== _this) { return; } return Mercury.changes = true; }); }; Snippets.prototype.focus = function() { Mercury.region = this; this.makeSortable(); return this.element.addClass('focus'); }; Snippets.prototype.togglePreview = function() { if (this.previewing) { this.makeSortable(); } else { this.element.sortable('destroy'); this.element.removeClass('focus'); } return Snippets.__super__.togglePreview.apply(this, arguments); }; Snippets.prototype.execCommand = function(action, options) { var handler; if (options == null) { options = {}; } Snippets.__super__.execCommand.apply(this, arguments); if (handler = Mercury.Regions.Snippets.actions[action]) { return handler.call(this, options); } }; Snippets.prototype.makeSortable = function() { var _this = this; return this.element.sortable('destroy').sortable({ document: this.document, scroll: false, containment: 'parent', items: '[data-snippet]', opacity: 0.4, revert: 100, tolerance: 'pointer', beforeStop: function() { Mercury.trigger('hide:toolbar', { type: 'snippet', immediately: true }); return true; }, stop: function() { setTimeout((function() { return _this.pushHistory(); }), 100); return true; } }); }; Snippets.actions = { undo: function() { return this.content(this.history.undo()); }, redo: function() { return this.content(this.history.redo()); }, insertSnippet: function(options) { var existing, snippet, _this = this; snippet = options.value; if ((existing = this.element.find("[data-snippet=" + snippet.identity + "]")).length) { return existing.replaceWith(snippet.getHTML(this.document, function() { return _this.pushHistory(); })); } else { return this.element.append(snippet.getHTML(this.document, function() { return _this.pushHistory(); })); } }, editSnippet: function() { var snippet; if (!this.snippet) { return; } snippet = Mercury.Snippet.find(this.snippet.data('snippet')); return snippet.displayOptions(); }, removeSnippet: function() { if (this.snippet) { this.snippet.remove(); } return Mercury.trigger('hide:toolbar', { type: 'snippet', immediately: true }); } }; return Snippets; })(Mercury.Region); }).call(this); (function() { this.Mercury.dialogHandlers.backColor = function() { var _this = this; return this.element.find('.picker, .last-picked').on('click', function(event) { var color; color = jQuery(event.target).css('background-color'); _this.element.find('.last-picked').css({ background: color }); _this.button.css({ backgroundColor: color }); return Mercury.trigger('action', { action: 'backColor', value: color }); }); }; }).call(this); (function() { this.Mercury.dialogHandlers.foreColor = function() { var _this = this; return this.element.find('.picker, .last-picked').on('click', function(event) { var color; color = jQuery(event.target).css('background-color').toHex(); _this.element.find('.last-picked').css({ background: color }); _this.button.css({ backgroundColor: color }); return Mercury.trigger('action', { action: 'foreColor', value: color }); }); }; }).call(this); (function() { this.Mercury.dialogHandlers.formatblock = function() { var _this = this; return this.element.find('[data-tag]').on('click', function(event) { var tag; tag = jQuery(event.target).data('tag'); return Mercury.trigger('action', { action: 'formatblock', value: tag }); }); }; }).call(this); (function() { this.Mercury.dialogHandlers.snippetPanel = function() { var _this = this; this.element.find('input.filter').on('keyup', function() { var snippet, value, _i, _len, _ref, _results; value = _this.element.find('input.filter').val(); _ref = _this.element.find('li[data-filter]'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { snippet = _ref[_i]; if (LiquidMetal.score(jQuery(snippet).data('filter'), value) === 0) { _results.push(jQuery(snippet).hide()); } else { _results.push(jQuery(snippet).show()); } } return _results; }); return this.element.find('img[data-snippet]').on('dragstart', function() { return Mercury.snippet = { name: jQuery(this).data('snippet'), hasOptions: !(jQuery(this).data('options') === false) }; }); }; }).call(this); (function() { this.Mercury.dialogHandlers.style = function() { var _this = this; return this.element.find('[data-class]').on('click', function(event) { var className; className = jQuery(event.target).data('class'); return Mercury.trigger('action', { action: 'style', value: className }); }); }; }).call(this); (function() { this.Mercury.modalHandlers.htmlEditor = function() { var content, _this = this; content = Mercury.region.content(null, true, false); this.element.find('textarea').val(content); return this.element.find('form').on('submit', function(event) { var value; event.preventDefault(); value = _this.element.find('textarea').val(); Mercury.trigger('action', { action: 'replaceHTML', value: value }); return _this.hide(); }); }; }).call(this); (function() { this.Mercury.modalHandlers.insertCharacter = function() { var _this = this; return this.element.find('.character').on('click', function(event) { Mercury.trigger('action', { action: 'insertHTML', value: "&" + (jQuery(event.target).attr('data-entity')) + ";" }); return _this.hide(); }); }; }).call(this); (function() { this.Mercury.modalHandlers.insertLink = { initialize: function() { var _this = this; this.editing = false; this.content = null; this.element.find('.control-label input').on('click', this.onLabelChecked); this.element.find('.controls .optional, .controls .required').on('focus', this.onInputFocused); this.element.find('#link_target').on('change', function() { return _this.onChangeTarget(); }); this.initializeForm(); return this.element.find('form').on('submit', function(event) { event.preventDefault(); _this.validateForm(); if (!_this.valid) { _this.resize(); return; } _this.submitForm(); return _this.hide(); }); }, initializeForm: function() { var a, bookmarkSelect, href, img, newBookmarkInput, selection; this.fillExistingBookmarks(); if (!(Mercury.region && Mercury.region.selection)) { return; } selection = Mercury.region.selection(); if (selection.textContent) { this.element.find('#link_text').val(selection.textContent()); } if (selection && selection.commonAncestor) { a = selection.commonAncestor(true).closest('a'); } if (selection.htmlContent) { img = /<img/.test(selection.htmlContent()); } if (!(img || a && a.length)) { return false; } this.element.find('#link_text_container').hide(); if (img) { this.content = selection.htmlContent(); } if (!(a && a.length)) { return false; } this.editing = a; if (a.attr('href') && a.attr('href').indexOf('#') === 0) { bookmarkSelect = this.element.find('#link_existing_bookmark'); bookmarkSelect.val(a.attr('href').replace(/[^#]*#/, '')); bookmarkSelect.closest('.control-group').find('input[type=radio]').prop('checked', true); } else { this.element.find('#link_external_url').val(a.attr('href')); } if (a.attr('name')) { newBookmarkInput = this.element.find('#link_new_bookmark'); newBookmarkInput.val(a.attr('name')); newBookmarkInput.closest('.control-group').find('input[type=radio]').prop('checked', true); } if (a.attr('target')) { this.element.find('#link_target').val(a.attr('target')); } if (a.attr('href') && a.attr('href').indexOf('javascript:void') === 0) { href = a.attr('href'); this.element.find('#link_external_url').val(href.match(/window.open\('([^']+)',/)[1]); this.element.find('#link_target').val('popup'); this.element.find('#link_popup_width').val(href.match(/width=(\d+),/)[1]); this.element.find('#link_popup_height').val(href.match(/height=(\d+),/)[1]); return this.element.find('#popup_options').show(); } }, fillExistingBookmarks: function() { var bookmarkSelect, tag, _i, _len, _ref, _results; bookmarkSelect = this.element.find('#link_existing_bookmark'); _ref = jQuery('a[name]', window.mercuryInstance.document); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { tag = _ref[_i]; _results.push(bookmarkSelect.append(jQuery('<option>', { value: jQuery(tag).attr('name') }).text(jQuery(tag).text()))); } return _results; }, onLabelChecked: function() { var forInput; forInput = jQuery(this).closest('.control-label').attr('for'); return jQuery(this).closest('.control-group').find("#" + forInput).focus(); }, onInputFocused: function() { return jQuery(this).closest('.control-group').find('input[type=radio]').prop('checked', true); }, onChangeTarget: function() { this.element.find(".link-target-options").hide(); this.element.find("#" + (this.element.find('#link_target').val()) + "_options").show(); return this.resize(true); }, addInputError: function(input, message) { input.after('<span class="help-inline error-message">' + Mercury.I18n(message) + '</span>').closest('.control-group').addClass('error'); return this.valid = false; }, clearInputErrors: function() { this.element.find('.control-group.error').removeClass('error').find('.error-message').remove(); return this.valid = true; }, validateForm: function() { var el, type; this.clearInputErrors(); type = this.element.find('input[name=link_type]:checked').val(); el = this.element.find("#link_" + type); if (!el.val()) { this.addInputError(el, "can't be blank"); } if (!this.editing && !this.content) { el = this.element.find('#link_text'); if (!el.val()) { return this.addInputError(el, "can't be blank"); } } }, submitForm: function() { var args, attrs, content, target, type, value; content = this.element.find('#link_text').val(); target = this.element.find('#link_target').val(); type = this.element.find('input[name=link_type]:checked').val(); switch (type) { case 'existing_bookmark': attrs = { href: "#" + (this.element.find('#link_existing_bookmark').val()) }; break; case 'new_bookmark': attrs = { name: "" + (this.element.find('#link_new_bookmark').val()) }; break; default: attrs = { href: this.element.find("#link_" + type).val() }; } switch (target) { case 'popup': args = { width: parseInt(this.element.find('#link_popup_width').val()) || 500, height: parseInt(this.element.find('#link_popup_height').val()) || 500, menubar: 'no', toolbar: 'no' }; attrs['href'] = "javascript:void(window.open('" + attrs['href'] + "', 'popup_window', '" + (jQuery.param(args).replace(/&/g, ',')) + "'))"; break; default: if (target) { attrs['target'] = target; } } value = { tagName: 'a', attrs: attrs, content: this.content || content }; if (this.editing) { return Mercury.trigger('action', { action: 'replaceLink', value: value, node: this.editing.get(0) }); } else { return Mercury.trigger('action', { action: 'insertLink', value: value }); } } }; }).call(this); (function() { this.Mercury.modalHandlers.insertMedia = { initialize: function() { var _this = this; this.element.find('.control-label input').on('click', this.onLabelChecked); this.element.find('.controls .optional, .controls .required').on('focus', function(event) { return _this.onInputFocused($(event.target)); }); this.focus('#media_image_url'); this.initializeForm(); return this.element.find('form').on('submit', function(event) { event.preventDefault(); _this.validateForm(); if (!_this.valid) { _this.resize(); return; } _this.submitForm(); return _this.hide(); }); }, initializeForm: function() { var iframe, image, selection, src; if (!(Mercury.region && Mercury.region.selection)) { return; } selection = Mercury.region.selection(); if (image = typeof selection.is === "function" ? selection.is('img') : void 0) { this.element.find('#media_image_url').val(image.attr('src')); this.element.find('#media_image_alignment').val(image.attr('align')); this.element.find('#media_image_float').val(image.attr('style') != null ? image.css('float') : ''); this.focus('#media_image_url'); } if (iframe = typeof selection.is === "function" ? selection.is('iframe') : void 0) { src = iframe.attr('src'); if (/^https?:\/\/www.youtube.com\//i.test(src)) { this.element.find('#media_youtube_url').val("" + (src.match(/^https?/)[0]) + "://youtu.be/" + (src.match(/\/embed\/(\w+)/)[1])); this.element.find('#media_youtube_width').val(iframe.width()); this.element.find('#media_youtube_height').val(iframe.height()); return this.focus('#media_youtube_url'); } else if (/^https?:\/\/player.vimeo.com\//i.test(src)) { this.element.find('#media_vimeo_url').val("" + (src.match(/^https?/)[0]) + "://vimeo.com/" + (src.match(/\/video\/(\w+)/)[1])); this.element.find('#media_vimeo_width').val(iframe.width()); this.element.find('#media_vimeo_height').val(iframe.height()); return this.focus('#media_vimeo_url'); } } }, focus: function(selector) { var _this = this; return setTimeout((function() { return _this.element.find(selector).focus(); }), 300); }, onLabelChecked: function() { var forInput; forInput = jQuery(this).closest('.control-label').attr('for'); return jQuery(this).closest('.control-group').find("#" + forInput).focus(); }, onInputFocused: function(input) { input.closest('.control-group').find('input[type=radio]').prop('checked', true); if (input.closest('.media-options').length) { return; } this.element.find(".media-options").hide(); this.element.find("#" + (input.attr('id').replace('media_', '')) + "_options").show(); return this.resize(true); }, addInputError: function(input, message) { input.after('<span class="help-inline error-message">' + Mercury.I18n(message) + '</span>').closest('.control-group').addClass('error'); return this.valid = false; }, clearInputErrors: function() { this.element.find('.control-group.error').removeClass('error').find('.error-message').remove(); return this.valid = true; }, validateForm: function() { var el, type, url; this.clearInputErrors(); type = this.element.find('input[name=media_type]:checked').val(); el = this.element.find("#media_" + type); switch (type) { case 'youtube_url': url = this.element.find('#media_youtube_url').val(); if (!/^https?:\/\/youtu.be\//.test(url)) { return this.addInputError(el, "is invalid"); } break; case 'vimeo_url': url = this.element.find('#media_vimeo_url').val(); if (!/^https?:\/\/vimeo.com\//.test(url)) { return this.addInputError(el, "is invalid"); } break; default: if (!el.val()) { return this.addInputError(el, "can't be blank"); } } }, submitForm: function() { var alignment, attrs, code, float, protocol, type, url, value; type = this.element.find('input[name=media_type]:checked').val(); switch (type) { case 'image_url': attrs = { src: this.element.find('#media_image_url').val() }; if (alignment = this.element.find('#media_image_alignment').val()) { attrs['align'] = alignment; } if (float = this.element.find('#media_image_float').val()) { attrs['style'] = 'float: ' + float + ';'; } return Mercury.trigger('action', { action: 'insertImage', value: attrs }); case 'youtube_url': url = this.element.find('#media_youtube_url').val(); code = url.replace(/https?:\/\/youtu.be\//, ''); protocol = 'http'; if (/^https:/.test(url)) { protocol = 'https'; } value = jQuery('<iframe>', { width: parseInt(this.element.find('#media_youtube_width').val(), 10) || 560, height: parseInt(this.element.find('#media_youtube_height').val(), 10) || 349, src: "" + protocol + "://www.youtube.com/embed/" + code + "?wmode=transparent", frameborder: 0, allowfullscreen: 'true' }); return Mercury.trigger('action', { action: 'insertHTML', value: value }); case 'vimeo_url': url = this.element.find('#media_vimeo_url').val(); code = url.replace(/^https?:\/\/vimeo.com\//, ''); protocol = 'http'; if (/^https:/.test(url)) { protocol = 'https'; } value = jQuery('<iframe>', { width: parseInt(this.element.find('#media_vimeo_width').val(), 10) || 400, height: parseInt(this.element.find('#media_vimeo_height').val(), 10) || 225, src: "" + protocol + "://player.vimeo.com/video/" + code + "?title=1&byline=1&portrait=0&color=ffffff", frameborder: 0 }); return Mercury.trigger('action', { action: 'insertHTML', value: value }); } } }; }).call(this); (function() { this.Mercury.modalHandlers.insertSnippet = function() { var _this = this; return this.element.find('form').on('submit', function(event) { var serializedForm, snippet; event.preventDefault(); serializedForm = _this.element.find('form').serializeObject(); if (Mercury.snippet) { snippet = Mercury.snippet; snippet.setOptions(serializedForm); Mercury.snippet = null; } else { snippet = Mercury.Snippet.create(_this.options.snippetName, serializedForm); } Mercury.trigger('action', { action: 'insertSnippet', value: snippet }); return _this.hide(); }); }; }).call(this); (function() { this.Mercury.modalHandlers.insertTable = { initialize: function() { var _this = this; this.table = this.element.find('#table_display table'); this.table.on('click', function(event) { return _this.onCellClick($(event.target)); }); this.element.find('#table_alignment').on('change', function() { return _this.setTableAlignment(); }); this.element.find('#table_border').on('keyup', function() { return _this.setTableBorder(); }); this.element.find('#table_spacing').on('keyup', function() { return _this.setTableCellSpacing(); }); this.element.find('[data-action]').on('click', function(event) { event.preventDefault(); return _this.onActionClick(jQuery(event.target).data('action')); }); this.selectFirstCell(); return this.element.find('form').on('submit', function(event) { event.preventDefault(); _this.submitForm(); return _this.hide(); }); }, selectFirstCell: function() { var firstCell; firstCell = this.table.find('td, th').first(); firstCell.addClass('selected'); return Mercury.tableEditor(this.table, firstCell, ' '); }, onCellClick: function(cell) { this.cell = cell; this.table = this.cell.closest('table'); this.table.find('.selected').removeAttr('class'); this.cell.addClass('selected'); return Mercury.tableEditor(this.table, this.cell, ' '); }, onActionClick: function(action) { if (!action) { return; } return Mercury.tableEditor[action](); }, setTableAlignment: function() { return this.table.attr({ align: this.element.find('#table_alignment').val() }); }, setTableBorder: function() { var border; border = parseInt(this.element.find('#table_border').val(), 10); if (isNaN(border)) { return this.table.removeAttr('border'); } else { return this.table.attr({ border: border }); } }, setTableCellSpacing: function() { var cellspacing; cellspacing = parseInt(this.element.find('#table_spacing').val(), 10); if (isNaN(cellspacing)) { return this.table.removeAttr('cellspacing'); } else { return this.table.attr({ cellspacing: cellspacing }); } }, submitForm: function() { var html, value; this.table.find('.selected').removeAttr('class'); this.table.find('td, th').html('<br/>'); html = jQuery('<div>').html(this.table).html(); value = html.replace(/^\s+|\n/gm, '').replace(/(<\/.*?>|<table.*?>|<tbody>|<tr>)/g, '$1\n'); return Mercury.trigger('action', { action: 'insertTable', value: value }); } }; }).call(this); (function() { if (Mercury.onload) { Mercury.onload(); } jQuery(window).trigger('mercury:loaded'); }).call(this); // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. // // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details // about supported directives. // ; ;�TI"required_assets_digest;�TI"%8e6bbbaeb7e796106aba825d9ae79790;�FI" _version;�TI"%2cf3622cbba861b85d33ffabfa420c13;�F