|
/** |
|
* NOTE: This was generated using `bbb debug` |
|
**/ |
|
/** |
|
* almond 0.2.0 Copyright (c) 2011, The Dojo Foundation All Rights Reserved. |
|
* Available via the MIT or new BSD license. |
|
* see: http://github.com/jrburke/almond for details |
|
*/ |
|
//Going sloppy to avoid 'use strict' string cost, but strict practices should |
|
//be followed. |
|
/*jslint sloppy: true */ |
|
/*global setTimeout: false */ |
|
|
|
var requirejs, require, define; |
|
(function (undef) { |
|
var main, req, makeMap, handlers, |
|
defined = {}, |
|
waiting = {}, |
|
config = {}, |
|
defining = {}, |
|
aps = [].slice; |
|
|
|
/** |
|
* Given a relative module name, like ./something, normalize it to |
|
* a real name that can be mapped to a path. |
|
* @param {String} name the relative name |
|
* @param {String} baseName a real name that the name arg is relative |
|
* to. |
|
* @returns {String} normalized name |
|
*/ |
|
function normalize(name, baseName) { |
|
var nameParts, nameSegment, mapValue, foundMap, |
|
foundI, foundStarMap, starI, i, j, part, |
|
baseParts = baseName && baseName.split("/"), |
|
map = config.map, |
|
starMap = (map && map['*']) || {}; |
|
|
|
//Adjust any relative paths. |
|
if (name && name.charAt(0) === ".") { |
|
//If have a base name, try to normalize against it, |
|
//otherwise, assume it is a top-level require that will |
|
//be relative to baseUrl in the end. |
|
if (baseName) { |
|
//Convert baseName to array, and lop off the last part, |
|
//so that . matches that "directory" and not name of the baseName's |
|
//module. For instance, baseName of "one/two/three", maps to |
|
//"one/two/three.js", but we want the directory, "one/two" for |
|
//this normalization. |
|
baseParts = baseParts.slice(0, baseParts.length - 1); |
|
|
|
name = baseParts.concat(name.split("/")); |
|
|
|
//start trimDots |
|
for (i = 0; i < name.length; i += 1) { |
|
part = name[i]; |
|
if (part === ".") { |
|
name.splice(i, 1); |
|
i -= 1; |
|
} else if (part === "..") { |
|
if (i === 1 && (name[2] === '..' || name[0] === '..')) { |
|
//End of the line. Keep at least one non-dot |
|
//path segment at the front so it can be mapped |
|
//correctly to disk. Otherwise, there is likely |
|
//no path mapping for a path starting with '..'. |
|
//This can still fail, but catches the most reasonable |
|
//uses of .. |
|
break; |
|
} else if (i > 0) { |
|
name.splice(i - 1, 2); |
|
i -= 2; |
|
} |
|
} |
|
} |
|
//end trimDots |
|
|
|
name = name.join("/"); |
|
} |
|
} |
|
|
|
//Apply map config if available. |
|
if ((baseParts || starMap) && map) { |
|
nameParts = name.split('/'); |
|
|
|
for (i = nameParts.length; i > 0; i -= 1) { |
|
nameSegment = nameParts.slice(0, i).join("/"); |
|
|
|
if (baseParts) { |
|
//Find the longest baseName segment match in the config. |
|
//So, do joins on the biggest to smallest lengths of baseParts. |
|
for (j = baseParts.length; j > 0; j -= 1) { |
|
mapValue = map[baseParts.slice(0, j).join('/')]; |
|
|
|
//baseName segment has config, find if it has one for |
|
//this name. |
|
if (mapValue) { |
|
mapValue = mapValue[nameSegment]; |
|
if (mapValue) { |
|
//Match, update name to the new value. |
|
foundMap = mapValue; |
|
foundI = i; |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
|
|
if (foundMap) { |
|
break; |
|
} |
|
|
|
//Check for a star map match, but just hold on to it, |
|
//if there is a shorter segment match later in a matching |
|
//config, then favor over this star map. |
|
if (!foundStarMap && starMap && starMap[nameSegment]) { |
|
foundStarMap = starMap[nameSegment]; |
|
starI = i; |
|
} |
|
} |
|
|
|
if (!foundMap && foundStarMap) { |
|
foundMap = foundStarMap; |
|
foundI = starI; |
|
} |
|
|
|
if (foundMap) { |
|
nameParts.splice(0, foundI, foundMap); |
|
name = nameParts.join('/'); |
|
} |
|
} |
|
|
|
return name; |
|
} |
|
|
|
function makeRequire(relName, forceSync) { |
|
return function () { |
|
//A version of a require function that passes a moduleName |
|
//value for items that may need to |
|
//look up paths relative to the moduleName |
|
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync])); |
|
}; |
|
} |
|
|
|
function makeNormalize(relName) { |
|
return function (name) { |
|
return normalize(name, relName); |
|
}; |
|
} |
|
|
|
function makeLoad(depName) { |
|
return function (value) { |
|
defined[depName] = value; |
|
}; |
|
} |
|
|
|
function callDep(name) { |
|
if (waiting.hasOwnProperty(name)) { |
|
var args = waiting[name]; |
|
delete waiting[name]; |
|
defining[name] = true; |
|
main.apply(undef, args); |
|
} |
|
|
|
if (!defined.hasOwnProperty(name) && !defining.hasOwnProperty(name)) { |
|
throw new Error('No ' + name); |
|
} |
|
return defined[name]; |
|
} |
|
|
|
//Turns a plugin!resource to [plugin, resource] |
|
//with the plugin being undefined if the name |
|
//did not have a plugin prefix. |
|
function splitPrefix(name) { |
|
var prefix, |
|
index = name ? name.indexOf('!') : -1; |
|
if (index > -1) { |
|
prefix = name.substring(0, index); |
|
name = name.substring(index + 1, name.length); |
|
} |
|
return [prefix, name]; |
|
} |
|
|
|
/** |
|
* Makes a name map, normalizing the name, and using a plugin |
|
* for normalization if necessary. Grabs a ref to plugin |
|
* too, as an optimization. |
|
*/ |
|
makeMap = function (name, relName) { |
|
var plugin, |
|
parts = splitPrefix(name), |
|
prefix = parts[0]; |
|
|
|
name = parts[1]; |
|
|
|
if (prefix) { |
|
prefix = normalize(prefix, relName); |
|
plugin = callDep(prefix); |
|
} |
|
|
|
//Normalize according |
|
if (prefix) { |
|
if (plugin && plugin.normalize) { |
|
name = plugin.normalize(name, makeNormalize(relName)); |
|
} else { |
|
name = normalize(name, relName); |
|
} |
|
} else { |
|
name = normalize(name, relName); |
|
parts = splitPrefix(name); |
|
prefix = parts[0]; |
|
name = parts[1]; |
|
if (prefix) { |
|
plugin = callDep(prefix); |
|
} |
|
} |
|
|
|
//Using ridiculous property names for space reasons |
|
return { |
|
f: prefix ? prefix + '!' + name : name, //fullName |
|
n: name, |
|
pr: prefix, |
|
p: plugin |
|
}; |
|
}; |
|
|
|
function makeConfig(name) { |
|
return function () { |
|
return (config && config.config && config.config[name]) || {}; |
|
}; |
|
} |
|
|
|
handlers = { |
|
require: function (name) { |
|
return makeRequire(name); |
|
}, |
|
exports: function (name) { |
|
var e = defined[name]; |
|
if (typeof e !== 'undefined') { |
|
return e; |
|
} else { |
|
return (defined[name] = {}); |
|
} |
|
}, |
|
module: function (name) { |
|
return { |
|
id: name, |
|
uri: '', |
|
exports: defined[name], |
|
config: makeConfig(name) |
|
}; |
|
} |
|
}; |
|
|
|
main = function (name, deps, callback, relName) { |
|
var cjsModule, depName, ret, map, i, |
|
args = [], |
|
usingExports; |
|
|
|
//Use name if no relName |
|
relName = relName || name; |
|
|
|
//Call the callback to define the module, if necessary. |
|
if (typeof callback === 'function') { |
|
|
|
//Pull out the defined dependencies and pass the ordered |
|
//values to the callback. |
|
//Default to [require, exports, module] if no deps |
|
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; |
|
for (i = 0; i < deps.length; i += 1) { |
|
map = makeMap(deps[i], relName); |
|
depName = map.f; |
|
|
|
//Fast path CommonJS standard dependencies. |
|
if (depName === "require") { |
|
args[i] = handlers.require(name); |
|
} else if (depName === "exports") { |
|
//CommonJS module spec 1.1 |
|
args[i] = handlers.exports(name); |
|
usingExports = true; |
|
} else if (depName === "module") { |
|
//CommonJS module spec 1.1 |
|
cjsModule = args[i] = handlers.module(name); |
|
} else if (defined.hasOwnProperty(depName) || |
|
waiting.hasOwnProperty(depName) || |
|
defining.hasOwnProperty(depName)) { |
|
args[i] = callDep(depName); |
|
} else if (map.p) { |
|
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {}); |
|
args[i] = defined[depName]; |
|
} else { |
|
throw new Error(name + ' missing ' + depName); |
|
} |
|
} |
|
|
|
ret = callback.apply(defined[name], args); |
|
|
|
if (name) { |
|
//If setting exports via "module" is in play, |
|
//favor that over return value and exports. After that, |
|
//favor a non-undefined return value over exports use. |
|
if (cjsModule && cjsModule.exports !== undef && |
|
cjsModule.exports !== defined[name]) { |
|
defined[name] = cjsModule.exports; |
|
} else if (ret !== undef || !usingExports) { |
|
//Use the return value from the function. |
|
defined[name] = ret; |
|
} |
|
} |
|
} else if (name) { |
|
//May just be an object definition for the module. Only |
|
//worry about defining if have a module name. |
|
defined[name] = callback; |
|
} |
|
}; |
|
|
|
requirejs = require = req = function (deps, callback, relName, forceSync, alt) { |
|
if (typeof deps === "string") { |
|
if (handlers[deps]) { |
|
//callback in this case is really relName |
|
return handlers[deps](callback); |
|
} |
|
//Just return the module wanted. In this scenario, the |
|
//deps arg is the module name, and second arg (if passed) |
|
//is just the relName. |
|
//Normalize module name, if it contains . or .. |
|
return callDep(makeMap(deps, callback).f); |
|
} else if (!deps.splice) { |
|
//deps is a config object, not an array. |
|
config = deps; |
|
if (callback.splice) { |
|
//callback is an array, which means it is a dependency list. |
|
//Adjust args if there are dependencies |
|
deps = callback; |
|
callback = relName; |
|
relName = null; |
|
} else { |
|
deps = undef; |
|
} |
|
} |
|
|
|
//Support require(['a']) |
|
callback = callback || function () {}; |
|
|
|
//If relName is a function, it is an errback handler, |
|
//so remove it. |
|
if (typeof relName === 'function') { |
|
relName = forceSync; |
|
forceSync = alt; |
|
} |
|
|
|
//Simulate async callback; |
|
if (forceSync) { |
|
main(undef, deps, callback, relName); |
|
} else { |
|
setTimeout(function () { |
|
main(undef, deps, callback, relName); |
|
}, 15); |
|
} |
|
|
|
return req; |
|
}; |
|
|
|
/** |
|
* Just drops the config on the floor, but returns req in case |
|
* the config return value is used. |
|
*/ |
|
req.config = function (cfg) { |
|
config = cfg; |
|
return req; |
|
}; |
|
|
|
define = function (name, deps, callback) { |
|
|
|
//This module may not have dependencies |
|
if (!deps.splice) { |
|
//deps is not an array, so probably means |
|
//an object literal or factory function for |
|
//the value. Adjust args. |
|
callback = deps; |
|
deps = []; |
|
} |
|
|
|
waiting[name] = [name, deps, callback]; |
|
}; |
|
|
|
define.amd = { |
|
jQuery: true |
|
}; |
|
}()); |
|
;this["JST"] = this["JST"] || {}; |
|
|
|
this["JST"]["app/templates/testing.html"] = function(obj){ |
|
var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')}; |
|
with(obj||{}){ |
|
__p+=''; |
|
} |
|
return __p; |
|
};; |
|
var jam = { |
|
"packages": [ |
|
{ |
|
"name": "backbone", |
|
"location": "../vendor/jam/backbone", |
|
"main": "backbone.js" |
|
}, |
|
{ |
|
"name": "backbone.layoutmanager", |
|
"location": "../vendor/jam/backbone.layoutmanager", |
|
"main": "backbone.layoutmanager.js" |
|
}, |
|
{ |
|
"name": "jquery", |
|
"location": "../vendor/jam/jquery", |
|
"main": "jquery.js" |
|
}, |
|
{ |
|
"name": "lodash", |
|
"location": "../vendor/jam/lodash", |
|
"main": "./lodash.js" |
|
} |
|
], |
|
"version": "0.2.11", |
|
"shim": { |
|
"backbone": { |
|
"deps": [ |
|
"jquery", |
|
"lodash" |
|
], |
|
"exports": "Backbone" |
|
}, |
|
"backbone.layoutmanager": { |
|
"deps": [ |
|
"jquery", |
|
"backbone", |
|
"lodash" |
|
], |
|
"exports": "Backbone.LayoutManager" |
|
} |
|
} |
|
}; |
|
|
|
if (typeof require !== "undefined" && require.config) { |
|
require.config({packages: jam.packages, shim: jam.shim}); |
|
} |
|
else { |
|
var require = {packages: jam.packages, shim: jam.shim}; |
|
} |
|
|
|
if (typeof exports !== "undefined" && typeof module !== "undefined") { |
|
module.exports = jam; |
|
}; |
|
define("../vendor/jam/require.config", function(){}); |
|
|
|
/*! jQuery v1.8.3 jquery.com | jquery.org/license */ |
|
(function(e,t){function _(e){var t=M[e]={};return v.each(e.split(y),function(e,n){t[n]=!0}),t}function H(e,n,r){if(r===t&&e.nodeType===1){var i="data-"+n.replace(P,"-$1").toLowerCase();r=e.getAttribute(i);if(typeof r=="string"){try{r=r==="true"?!0:r==="false"?!1:r==="null"?null:+r+""===r?+r:D.test(r)?v.parseJSON(r):r}catch(s){}v.data(e,n,r)}else r=t}return r}function B(e){var t;for(t in e){if(t==="data"&&v.isEmptyObject(e[t]))continue;if(t!=="toJSON")return!1}return!0}function et(){return!1}function tt(){return!0}function ut(e){return!e||!e.parentNode||e.parentNode.nodeType===11}function at(e,t){do e=e[t];while(e&&e.nodeType!==1);return e}function ft(e,t,n){t=t||0;if(v.isFunction(t))return v.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return v.grep(e,function(e,r){return e===t===n});if(typeof t=="string"){var r=v.grep(e,function(e){return e.nodeType===1});if(it.test(t))return v.filter(t,r,!n);t=v.filter(t,r)}return v.grep(e,function(e,r){return v.inArray(e,t)>=0===n})}function lt(e){var t=ct.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}function Lt(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function At(e,t){if(t.nodeType!==1||!v.hasData(e))return;var n,r,i,s=v._data(e),o=v._data(t,s),u=s.events;if(u){delete o.handle,o.events={};for(n in u)for(r=0,i=u[n].length;r<i;r++)v.event.add(t,n,u[n][r])}o.data&&(o.data=v.extend({},o.data))}function Ot(e,t){var n;if(t.nodeType!==1)return;t.clearAttributes&&t.clearAttributes(),t.mergeAttributes&&t.mergeAttributes(e),n=t.nodeName.toLowerCase(),n==="object"?(t.parentNode&&(t.outerHTML=e.outerHTML),v.support.html5Clone&&e.innerHTML&&!v.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):n==="input"&&Et.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):n==="option"?t.selected=e.defaultSelected:n==="input"||n==="textarea"?t.defaultValue=e.defaultValue:n==="script"&&t.text!==e.text&&(t.text=e.text),t.removeAttribute(v.expando)}function Mt(e){return typeof e.getElementsByTagName!="undefined"?e.getElementsByTagName("*"):typeof e.querySelectorAll!="undefined"?e.querySelectorAll("*"):[]}function _t(e){Et.test(e.type)&&(e.defaultChecked=e.checked)}function Qt(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Jt.length;while(i--){t=Jt[i]+n;if(t in e)return t}return r}function Gt(e,t){return e=t||e,v.css(e,"display")==="none"||!v.contains(e.ownerDocument,e)}function Yt(e,t){var n,r,i=[],s=0,o=e.length;for(;s<o;s++){n=e[s];if(!n.style)continue;i[s]=v._data(n,"olddisplay"),t?(!i[s]&&n.style.display==="none"&&(n.style.display=""),n.style.display===""&&Gt(n)&&(i[s]=v._data(n,"olddisplay",nn(n.nodeName)))):(r=Dt(n,"display"),!i[s]&&r!=="none"&&v._data(n,"olddisplay",r))}for(s=0;s<o;s++){n=e[s];if(!n.style)continue;if(!t||n.style.display==="none"||n.style.display==="")n.style.display=t?i[s]||"":"none"}return e}function Zt(e,t,n){var r=Rt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function en(e,t,n,r){var i=n===(r?"border":"content")?4:t==="width"?1:0,s=0;for(;i<4;i+=2)n==="margin"&&(s+=v.css(e,n+$t[i],!0)),r?(n==="content"&&(s-=parseFloat(Dt(e,"padding"+$t[i]))||0),n!=="margin"&&(s-=parseFloat(Dt(e,"border"+$t[i]+"Width"))||0)):(s+=parseFloat(Dt(e,"padding"+$t[i]))||0,n!=="padding"&&(s+=parseFloat(Dt(e,"border"+$t[i]+"Width"))||0));return s}function tn(e,t,n){var r=t==="width"?e.offsetWidth:e.offsetHeight,i=!0,s=v.support.boxSizing&&v.css(e,"boxSizing")==="border-box";if(r<=0||r==null){r=Dt(e,t);if(r<0||r==null)r=e.style[t];if(Ut.test(r))return r;i=s&&(v.support.boxSizingReliable||r===e.style[t]),r=parseFloat(r)||0}return r+en(e,t,n||(s?"border":"content"),i)+"px"}function nn(e){if(Wt[e])return Wt[e];var t=v("<"+e+">").appendTo(i.body),n=t.css("display");t.remove();if(n==="none"||n===""){Pt=i.body.appendChild(Pt||v.extend(i.createElement("iframe"),{frameBorder:0,width:0,height:0}));if(!Ht||!Pt.createElement)Ht=(Pt.contentWindow||Pt.contentDocument).document,Ht.write("<!doctype html><html><body>"),Ht.close();t=Ht.body.appendChild(Ht.createElement(e)),n=Dt(t,"display"),i.body.removeChild(Pt)}return Wt[e]=n,n}function fn(e,t,n,r){var i;if(v.isArray(t))v.each(t,function(t,i){n||sn.test(e)?r(e,i):fn(e+"["+(typeof i=="object"?t:"")+"]",i,n,r)});else if(!n&&v.type(t)==="object")for(i in t)fn(e+"["+i+"]",t[i],n,r);else r(e,t)}function Cn(e){return function(t,n){typeof t!="string"&&(n=t,t="*");var r,i,s,o=t.toLowerCase().split(y),u=0,a=o.length;if(v.isFunction(n))for(;u<a;u++)r=o[u],s=/^\+/.test(r),s&&(r=r.substr(1)||"*"),i=e[r]=e[r]||[],i[s?"unshift":"push"](n)}}function kn(e,n,r,i,s,o){s=s||n.dataTypes[0],o=o||{},o[s]=!0;var u,a=e[s],f=0,l=a?a.length:0,c=e===Sn;for(;f<l&&(c||!u);f++)u=a[f](n,r,i),typeof u=="string"&&(!c||o[u]?u=t:(n.dataTypes.unshift(u),u=kn(e,n,r,i,u,o)));return(c||!u)&&!o["*"]&&(u=kn(e,n,r,i,"*",o)),u}function Ln(e,n){var r,i,s=v.ajaxSettings.flatOptions||{};for(r in n)n[r]!==t&&((s[r]?e:i||(i={}))[r]=n[r]);i&&v.extend(!0,e,i)}function An(e,n,r){var i,s,o,u,a=e.contents,f=e.dataTypes,l=e.responseFields;for(s in l)s in r&&(n[l[s]]=r[s]);while(f[0]==="*")f.shift(),i===t&&(i=e.mimeType||n.getResponseHeader("content-type"));if(i)for(s in a)if(a[s]&&a[s].test(i)){f.unshift(s);break}if(f[0]in r)o=f[0];else{for(s in r){if(!f[0]||e.converters[s+" "+f[0]]){o=s;break}u||(u=s)}o=o||u}if(o)return o!==f[0]&&f.unshift(o),r[o]}function On(e,t){var n,r,i,s,o=e.dataTypes.slice(),u=o[0],a={},f=0;e.dataFilter&&(t=e.dataFilter(t,e.dataType));if(o[1])for(n in e.converters)a[n.toLowerCase()]=e.converters[n];for(;i=o[++f];)if(i!=="*"){if(u!=="*"&&u!==i){n=a[u+" "+i]||a["* "+i];if(!n)for(r in a){s=r.split(" ");if(s[1]===i){n=a[u+" "+s[0]]||a["* "+s[0]];if(n){n===!0?n=a[r]:a[r]!==!0&&(i=s[0],o.splice(f--,0,i));break}}}if(n!==!0)if(n&&e["throws"])t=n(t);else try{t=n(t)}catch(l){return{state:"parsererror",error:n?l:"No conversion from "+u+" to "+i}}}u=i}return{state:"success",data:t}}function Fn(){try{return new e.XMLHttpRequest}catch(t){}}function In(){try{return new e.ActiveXObject("Microsoft.XMLHTTP")}catch(t){}}function $n(){return setTimeout(function(){qn=t},0),qn=v.now()}function Jn(e,t){v.each(t,function(t,n){var r=(Vn[t]||[]).concat(Vn["*"]),i=0,s=r.length;for(;i<s;i++)if(r[i].call(e,t,n))return})}function Kn(e,t,n){var r,i=0,s=0,o=Xn.length,u=v.Deferred().always(function(){delete a.elem}),a=function(){var t=qn||$n(),n=Math.max(0,f.startTime+f.duration-t),r=n/f.duration||0,i=1-r,s=0,o=f.tweens.length;for(;s<o;s++)f.tweens[s].run(i);return u.notifyWith(e,[f,i,n]),i<1&&o?n:(u.resolveWith(e,[f]),!1)},f=u.promise({elem:e,props:v.extend({},t),opts:v.extend(!0,{specialEasing:{}},n),originalProperties:t,originalOptions:n,startTime:qn||$n(),duration:n.duration,tweens:[],createTween:function(t,n,r){var i=v.Tween(e,f.opts,t,n,f.opts.specialEasing[t]||f.opts.easing);return f.tweens.push(i),i},stop:function(t){var n=0,r=t?f.tweens.length:0;for(;n<r;n++)f.tweens[n].run(1);return t?u.resolveWith(e,[f,t]):u.rejectWith(e,[f,t]),this}}),l=f.props;Qn(l,f.opts.specialEasing);for(;i<o;i++){r=Xn[i].call(f,e,l,f.opts);if(r)return r}return Jn(f,l),v.isFunction(f.opts.start)&&f.opts.start.call(e,f),v.fx.timer(v.extend(a,{anim:f,queue:f.opts.queue,elem:e})),f.progress(f.opts.progress).done(f.opts.done,f.opts.complete).fail(f.opts.fail).always(f.opts.always)}function Qn(e,t){var n,r,i,s,o;for(n in e){r=v.camelCase(n),i=t[r],s=e[n],v.isArray(s)&&(i=s[1],s=e[n]=s[0]),n!==r&&(e[r]=s,delete e[n]),o=v.cssHooks[r];if(o&&"expand"in o){s=o.expand(s),delete e[r];for(n in s)n in e||(e[n]=s[n],t[n]=i)}else t[r]=i}}function Gn(e,t,n){var r,i,s,o,u,a,f,l,c,h=this,p=e.style,d={},m=[],g=e.nodeType&&Gt(e);n.queue||(l=v._queueHooks(e,"fx"),l.unqueued==null&&(l.unqueued=0,c=l.empty.fire,l.empty.fire=function(){l.unqueued||c()}),l.unqueued++,h.always(function(){h.always(function(){l.unqueued--,v.queue(e,"fx").length||l.empty.fire()})})),e.nodeType===1&&("height"in t||"width"in t)&&(n.overflow=[p.overflow,p.overflowX,p.overflowY],v.css(e,"display")==="inline"&&v.css(e,"float")==="none"&&(!v.support.inlineBlockNeedsLayout||nn(e.nodeName)==="inline"?p.display="inline-block":p.zoom=1)),n.overflow&&(p.overflow="hidden",v.support.shrinkWrapBlocks||h.done(function(){p.overflow=n.overflow[0],p.overflowX=n.overflow[1],p.overflowY=n.overflow[2]}));for(r in t){s=t[r];if(Un.exec(s)){delete t[r],a=a||s==="toggle";if(s===(g?"hide":"show"))continue;m.push(r)}}o=m.length;if(o){u=v._data(e,"fxshow")||v._data(e,"fxshow",{}),"hidden"in u&&(g=u.hidden),a&&(u.hidden=!g),g?v(e).show():h.done(function(){v(e).hide()}),h.done(function(){var t;v.removeData(e,"fxshow",!0);for(t in d)v.style(e,t,d[t])});for(r=0;r<o;r++)i=m[r],f=h.createTween(i,g?u[i]:0),d[i]=u[i]||v.style(e,i),i in u||(u[i]=f.start,g&&(f.end=f.start,f.start=i==="width"||i==="height"?1:0))}}function Yn(e,t,n,r,i){return new Yn.prototype.init(e,t,n,r,i)}function Zn(e,t){var n,r={height:e},i=0;t=t?1:0;for(;i<4;i+=2-t)n=$t[i],r["margin"+n]=r["padding"+n]=e;return t&&(r.opacity=r.width=e),r}function tr(e){return v.isWindow(e)?e:e.nodeType===9?e.defaultView||e.parentWindow:!1}var n,r,i=e.document,s=e.location,o=e.navigator,u=e.jQuery,a=e.$,f=Array.prototype.push,l=Array.prototype.slice,c=Array.prototype.indexOf,h=Object.prototype.toString,p=Object.prototype.hasOwnProperty,d=String.prototype.trim,v=function(e,t){return new v.fn.init(e,t,n)},m=/[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source,g=/\S/,y=/\s+/,b=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,w=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,E=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,S=/^[\],:{}\s]*$/,x=/(?:^|:|,)(?:\s*\[)+/g,T=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,N=/"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g,C=/^-ms-/,k=/-([\da-z])/gi,L=function(e,t){return(t+"").toUpperCase()},A=function(){i.addEventListener?(i.removeEventListener("DOMContentLoaded",A,!1),v.ready()):i.readyState==="complete"&&(i.detachEvent("onreadystatechange",A),v.ready())},O={};v.fn=v.prototype={constructor:v,init:function(e,n,r){var s,o,u,a;if(!e)return this;if(e.nodeType)return this.context=this[0]=e,this.length=1,this;if(typeof e=="string"){e.charAt(0)==="<"&&e.charAt(e.length-1)===">"&&e.length>=3?s=[null,e,null]:s=w.exec(e);if(s&&(s[1]||!n)){if(s[1])return n=n instanceof v?n[0]:n,a=n&&n.nodeType?n.ownerDocument||n:i,e=v.parseHTML(s[1],a,!0),E.test(s[1])&&v.isPlainObject(n)&&this.attr.call(e,n,!0),v.merge(this,e);o=i.getElementById(s[2]);if(o&&o.parentNode){if(o.id!==s[2])return r.find(e);this.length=1,this[0]=o}return this.context=i,this.selector=e,this}return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e)}return v.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),v.makeArray(e,this))},selector:"",jquery:"1.8.3",length:0,size:function(){return this.length},toArray:function(){return l.call(this)},get:function(e){return e==null?this.toArray():e<0?this[this.length+e]:this[e]},pushStack:function(e,t,n){var r=v.merge(this.constructor(),e);return r.prevObject=this,r.context=this.context,t==="find"?r.selector=this.selector+(this.selector?" ":"")+n:t&&(r.selector=this.selector+"."+t+"("+n+")"),r},each:function(e,t){return v.each(this,e,t)},ready:function(e){return v.ready.promise().done(e),this},eq:function(e){return e=+e,e===-1?this.slice(e):this.slice(e,e+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(l.apply(this,arguments),"slice",l.call(arguments).join(","))},map:function(e){return this.pushStack(v.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:[].sort,splice:[].splice},v.fn.init.prototype=v.fn,v.extend=v.fn.extend=function(){var e,n,r,i,s,o,u=arguments[0]||{},a=1,f=arguments.length,l=!1;typeof u=="boolean"&&(l=u,u=arguments[1]||{},a=2),typeof u!="object"&&!v.isFunction(u)&&(u={}),f===a&&(u=this,--a);for(;a<f;a++)if((e=arguments[a])!=null)for(n in e){r=u[n],i=e[n];if(u===i)continue;l&&i&&(v.isPlainObject(i)||(s=v.isArray(i)))?(s?(s=!1,o=r&&v.isArray(r)?r:[]):o=r&&v.isPlainObject(r)?r:{},u[n]=v.extend(l,o,i)):i!==t&&(u[n]=i)}return u},v.extend({noConflict:function(t){return e.$===v&&(e.$=a),t&&e.jQuery===v&&(e.jQuery=u),v},isReady:!1,readyWait:1,holdReady:function(e){e?v.readyWait++:v.ready(!0)},ready:function(e){if(e===!0?--v.readyWait:v.isReady)return;if(!i.body)return setTimeout(v.ready,1);v.isReady=!0;if(e!==!0&&--v.readyWait>0)return;r.resolveWith(i,[v]),v.fn.trigger&&v(i).trigger("ready").off("ready")},isFunction:function(e){return v.type(e)==="function"},isArray:Array.isArray||function(e){return v.type(e)==="array"},isWindow:function(e){return e!=null&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return e==null?String(e):O[h.call(e)]||"object"},isPlainObject:function(e){if(!e||v.type(e)!=="object"||e.nodeType||v.isWindow(e))return!1;try{if(e.constructor&&!p.call(e,"constructor")&&!p.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(n){return!1}var r;for(r in e);return r===t||p.call(e,r)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw new Error(e)},parseHTML:function(e,t,n){var r;return!e||typeof e!="string"?null:(typeof t=="boolean"&&(n=t,t=0),t=t||i,(r=E.exec(e))?[t.createElement(r[1])]:(r=v.buildFragment([e],t,n?null:[]),v.merge([],(r.cacheable?v.clone(r.fragment):r.fragment).childNodes)))},parseJSON:function(t){if(!t||typeof t!="string")return null;t=v.trim(t);if(e.JSON&&e.JSON.parse)return e.JSON.parse(t);if(S.test(t.replace(T,"@").replace(N,"]").replace(x,"")))return(new Function("return "+t))();v.error("Invalid JSON: "+t)},parseXML:function(n){var r,i;if(!n||typeof n!="string")return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(s){r=t}return(!r||!r.documentElement||r.getElementsByTagName("parsererror").length)&&v.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&g.test(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(C,"ms-").replace(k,L)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,n,r){var i,s=0,o=e.length,u=o===t||v.isFunction(e);if(r){if(u){for(i in e)if(n.apply(e[i],r)===!1)break}else for(;s<o;)if(n.apply(e[s++],r)===!1)break}else if(u){for(i in e)if(n.call(e[i],i,e[i])===!1)break}else for(;s<o;)if(n.call(e[s],s,e[s++])===!1)break;return e},trim:d&&!d.call("\ufeff\u00a0")?function(e){return e==null?"":d.call(e)}:function(e){return e==null?"":(e+"").replace(b,"")},makeArray:function(e,t){var n,r=t||[];return e!=null&&(n=v.type(e),e.length==null||n==="string"||n==="function"||n==="regexp"||v.isWindow(e)?f.call(r,e):v.merge(r,e)),r},inArray:function(e,t,n){var r;if(t){if(c)return c.call(t,e,n);r=t.length,n=n?n<0?Math.max(0,r+n):n:0;for(;n<r;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,s=0;if(typeof r=="number")for(;s<r;s++)e[i++]=n[s];else while(n[s]!==t)e[i++]=n[s++];return e.length=i,e},grep:function(e,t,n){var r,i=[],s=0,o=e.length;n=!!n;for(;s<o;s++)r=!!t(e[s],s),n!==r&&i.push(e[s]);return i},map:function(e,n,r){var i,s,o=[],u=0,a=e.length,f=e instanceof v||a!==t&&typeof a=="number"&&(a>0&&e[0]&&e[a-1]||a===0||v.isArray(e));if(f)for(;u<a;u++)i=n(e[u],u,r),i!=null&&(o[o.length]=i);else for(s in e)i=n(e[s],s,r),i!=null&&(o[o.length]=i);return o.concat.apply([],o)},guid:1,proxy:function(e,n){var r,i,s;return typeof n=="string"&&(r=e[n],n=e,e=r),v.isFunction(e)?(i=l.call(arguments,2),s=function(){return e.apply(n,i.concat(l.call(arguments)))},s.guid=e.guid=e.guid||v.guid++,s):t},access:function(e,n,r,i,s,o,u){var a,f=r==null,l=0,c=e.length;if(r&&typeof r=="object"){for(l in r)v.access(e,n,l,r[l],1,o,i);s=1}else if(i!==t){a=u===t&&v.isFunction(i),f&&(a?(a=n,n=function(e,t,n){return a.call(v(e),n)}):(n.call(e,i),n=null));if(n)for(;l<c;l++)n(e[l],r,a?i.call(e[l],l,n(e[l],r)):i,u);s=1}return s?e:f?n.call(e):c?n(e[0],r):o},now:function(){return(new Date).getTime()}}),v.ready.promise=function(t){if(!r){r=v.Deferred();if(i.readyState==="complete")setTimeout(v.ready,1);else if(i.addEventListener)i.addEventListener("DOMContentLoaded",A,!1),e.addEventListener("load",v.ready,!1);else{i.attachEvent("onreadystatechange",A),e.attachEvent("onload",v.ready);var n=!1;try{n=e.frameElement==null&&i.documentElement}catch(s){}n&&n.doScroll&&function o(){if(!v.isReady){try{n.doScroll("left")}catch(e){return setTimeout(o,50)}v.ready()}}()}}return r.promise(t)},v.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(e,t){O["[object "+t+"]"]=t.toLowerCase()}),n=v(i);var M={};v.Callbacks=function(e){e=typeof e=="string"?M[e]||_(e):v.extend({},e);var n,r,i,s,o,u,a=[],f=!e.once&&[],l=function(t){n=e.memory&&t,r=!0,u=s||0,s=0,o=a.length,i=!0;for(;a&&u<o;u++)if(a[u].apply(t[0],t[1])===!1&&e.stopOnFalse){n=!1;break}i=!1,a&&(f?f.length&&l(f.shift()):n?a=[]:c.disable())},c={add:function(){if(a){var t=a.length;(function r(t){v.each(t,function(t,n){var i=v.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this},remove:function(){return a&&v.each(arguments,function(e,t){var n;while((n=v.inArray(t,a,n))>-1)a.splice(n,1),i&&(n<=o&&o--,n<=u&&u--)}),this},has:function(e){return v.inArray(e,a)>-1},empty:function(){return a=[],this},disable:function(){return a=f=n=t,this},disabled:function(){return!a},lock:function(){return f=t,n||c.disable(),this},locked:function(){return!f},fireWith:function(e,t){return t=t||[],t=[e,t.slice?t.slice():t],a&&(!r||f)&&(i?f.push(t):l(t)),this},fire:function(){return c.fireWith(this,arguments),this},fired:function(){return!!r}};return c},v.extend({Deferred:function(e){var t=[["resolve","done",v.Callbacks("once memory"),"resolved"],["reject","fail",v.Callbacks("once memory"),"rejected"],["notify","progress",v.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return v.Deferred(function(n){v.each(t,function(t,r){var s=r[0],o=e[t];i[r[1]](v.isFunction(o)?function(){var e=o.apply(this,arguments);e&&v.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[s+"With"](this===i?n:this,[e])}:n[s])}),e=null}).promise()},promise:function(e){return e!=null?v.extend(e,r):r}},i={};return r.pipe=r.then,v.each(t,function(e,s){var o=s[2],u=s[3];r[s[1]]=o.add,u&&o.add(function(){n=u},t[e^1][2].disable,t[2][2].lock),i[s[0]]=o.fire,i[s[0]+"With"]=o.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=l.call(arguments),r=n.length,i=r!==1||e&&v.isFunction(e.promise)?r:0,s=i===1?e:v.Deferred(),o=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?l.call(arguments):r,n===u?s.notifyWith(t,n):--i||s.resolveWith(t,n)}},u,a,f;if(r>1){u=new Array(r),a=new Array(r),f=new Array(r);for(;t<r;t++)n[t]&&v.isFunction(n[t].promise)?n[t].promise().done(o(t,f,n)).fail(s.reject).progress(o(t,a,u)):--i}return i||s.resolveWith(f,n),s.promise()}}),v.support=function(){var t,n,r,s,o,u,a,f,l,c,h,p=i.createElement("div");p.setAttribute("className","t"),p.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",n=p.getElementsByTagName("*"),r=p.getElementsByTagName("a")[0];if(!n||!r||!n.length)return{};s=i.createElement("select"),o=s.appendChild(i.createElement("option")),u=p.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t={leadingWhitespace:p.firstChild.nodeType===3,tbody:!p.getElementsByTagName("tbody").length,htmlSerialize:!!p.getElementsByTagName("link").length,style:/top/.test(r.getAttribute("style")),hrefNormalized:r.getAttribute("href")==="/a",opacity:/^0.5/.test(r.style.opacity),cssFloat:!!r.style.cssFloat,checkOn:u.value==="on",optSelected:o.selected,getSetAttribute:p.className!=="t",enctype:!!i.createElement("form").enctype,html5Clone:i.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>",boxModel:i.compatMode==="CSS1Compat",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,boxSizingReliable:!0,pixelPosition:!1},u.checked=!0,t.noCloneChecked=u.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!o.disabled;try{delete p.test}catch(d){t.deleteExpando=!1}!p.addEventListener&&p.attachEvent&&p.fireEvent&&(p.attachEvent("onclick",h=function(){t.noCloneEvent=!1}),p.cloneNode(!0).fireEvent("onclick"),p.detachEvent("onclick",h)),u=i.createElement("input"),u.value="t",u.setAttribute("type","radio"),t.radioValue=u.value==="t",u.setAttribute("checked","checked"),u.setAttribute("name","t"),p.appendChild(u),a=i.createDocumentFragment(),a.appendChild(p.lastChild),t.checkClone=a.cloneNode(!0).cloneNode(!0).lastChild.checked,t.appendChecked=u.checked,a.removeChild(u),a.appendChild(p);if(p.attachEvent)for(l in{submit:!0,change:!0,focusin:!0})f="on"+l,c=f in p,c||(p.setAttribute(f,"return;"),c=typeof p[f]=="function"),t[l+"Bubbles"]=c;return v(function(){var n,r,s,o,u="padding:0;margin:0;border:0;display:block;overflow:hidden;",a=i.getElementsByTagName("body")[0];if(!a)return;n=i.createElement("div"),n.style.cssText="visibility:hidden;border:0;width:0;height:0;position:static;top:0;margin-top:1px",a.insertBefore(n,a.firstChild),r=i.createElement("div"),n.appendChild(r),r.innerHTML="<table><tr><td></td><td>t</td></tr></table>",s=r.getElementsByTagName("td"),s[0].style.cssText="padding:0;margin:0;border:0;display:none",c=s[0].offsetHeight===0,s[0].style.display="",s[1].style.display="none",t.reliableHiddenOffsets=c&&s[0].offsetHeight===0,r.innerHTML="",r.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%;",t.boxSizing=r.offsetWidth===4,t.doesNotIncludeMarginInBodyOffset=a.offsetTop!==1,e.getComputedStyle&&(t.pixelPosition=(e.getComputedStyle(r,null)||{}).top!=="1%",t.boxSizingReliable=(e.getComputedStyle(r,null)||{width:"4px"}).width==="4px",o=i.createElement("div"),o.style.cssText=r.style.cssText=u,o.style.marginRight=o.style.width="0",r.style.width="1px",r.appendChild(o),t.reliableMarginRight=!parseFloat((e.getComputedStyle(o,null)||{}).marginRight)),typeof r.style.zoom!="undefined"&&(r.innerHTML="",r.style.cssText=u+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=r.offsetWidth===3,r.style.display="block",r.style.overflow="visible",r.innerHTML="<div></div>",r.firstChild.style.width="5px",t.shrinkWrapBlocks=r.offsetWidth!==3,n.style.zoom=1),a.removeChild(n),n=r=s=o=null}),a.removeChild(p),n=r=s=o=u=a=p=null,t}();var D=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,P=/([A-Z])/g;v.extend({cache:{},deletedIds:[],uuid:0,expando:"jQuery"+(v.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(e){return e=e.nodeType?v.cache[e[v.expando]]:e[v.expando],!!e&&!B(e)},data:function(e,n,r,i){if(!v.acceptData(e))return;var s,o,u=v.expando,a=typeof n=="string",f=e.nodeType,l=f?v.cache:e,c=f?e[u]:e[u]&&u;if((!c||!l[c]||!i&&!l[c].data)&&a&&r===t)return;c||(f?e[u]=c=v.deletedIds.pop()||v.guid++:c=u),l[c]||(l[c]={},f||(l[c].toJSON=v.noop));if(typeof n=="object"||typeof n=="function")i?l[c]=v.extend(l[c],n):l[c].data=v.extend(l[c].data,n);return s=l[c],i||(s.data||(s.data={}),s=s.data),r!==t&&(s[v.camelCase(n)]=r),a?(o=s[n],o==null&&(o=s[v.camelCase(n)])):o=s,o},removeData:function(e,t,n){if(!v.acceptData(e))return;var r,i,s,o=e.nodeType,u=o?v.cache:e,a=o?e[v.expando]:v.expando;if(!u[a])return;if(t){r=n?u[a]:u[a].data;if(r){v.isArray(t)||(t in r?t=[t]:(t=v.camelCase(t),t in r?t=[t]:t=t.split(" ")));for(i=0,s=t.length;i<s;i++)delete r[t[i]];if(!(n?B:v.isEmptyObject)(r))return}}if(!n){delete u[a].data;if(!B(u[a]))return}o?v.cleanData([e],!0):v.support.deleteExpando||u!=u.window?delete u[a]:u[a]=null},_data:function(e,t,n){return v.data(e,t,n,!0)},acceptData:function(e){var t=e.nodeName&&v.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),v.fn.extend({data:function(e,n){var r,i,s,o,u,a=this[0],f=0,l=null;if(e===t){if(this.length){l=v.data(a);if(a.nodeType===1&&!v._data(a,"parsedAttrs")){s=a.attributes;for(u=s.length;f<u;f++)o=s[f].name,o.indexOf("data-")||(o=v.camelCase(o.substring(5)),H(a,o,l[o]));v._data(a,"parsedAttrs",!0)}}return l}return typeof e=="object"?this.each(function(){v.data(this,e)}):(r=e.split(".",2),r[1]=r[1]?"."+r[1]:"",i=r[1]+"!",v.access(this,function(n){if(n===t)return l=this.triggerHandler("getData"+i,[r[0]]),l===t&&a&&(l=v.data(a,e),l=H(a,e,l)),l===t&&r[1]?this.data(r[0]):l;r[1]=n,this.each(function(){var t=v(this);t.triggerHandler("setData"+i,r),v.data(this,e,n),t.triggerHandler("changeData"+i,r)})},null,n,arguments.length>1,null,!1))},removeData:function(e){return this.each(function(){v.removeData(this,e)})}}),v.extend({queue:function(e,t,n){var r;if(e)return t=(t||"fx")+"queue",r=v._data(e,t),n&&(!r||v.isArray(n)?r=v._data(e,t,v.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||"fx";var n=v.queue(e,t),r=n.length,i=n.shift(),s=v._queueHooks(e,t),o=function(){v.dequeue(e,t)};i==="inprogress"&&(i=n.shift(),r--),i&&(t==="fx"&&n.unshift("inprogress"),delete s.stop,i.call(e,o,s)),!r&&s&&s.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return v._data(e,n)||v._data(e,n,{empty:v.Callbacks("once memory").add(function(){v.removeData(e,t+"queue",!0),v.removeData(e,n,!0)})})}}),v.fn.extend({queue:function(e,n){var r=2;return typeof e!="string"&&(n=e,e="fx",r--),arguments.length<r?v.queue(this[0],e):n===t?this:this.each(function(){var t=v.queue(this,e,n);v._queueHooks(this,e),e==="fx"&&t[0]!=="inprogress"&&v.dequeue(this,e)})},dequeue:function(e){return this.each(function(){v.dequeue(this,e)})},delay:function(e,t){return e=v.fx?v.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,s=v.Deferred(),o=this,u=this.length,a=function(){--i||s.resolveWith(o,[o])};typeof e!="string"&&(n=e,e=t),e=e||"fx";while(u--)r=v._data(o[u],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(a));return a(),s.promise(n)}});var j,F,I,q=/[\t\r\n]/g,R=/\r/g,U=/^(?:button|input)$/i,z=/^(?:button|input|object|select|textarea)$/i,W=/^a(?:rea|)$/i,X=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,V=v.support.getSetAttribute;v.fn.extend({attr:function(e,t){return v.access(this,v.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){v.removeAttr(this,e)})},prop:function(e,t){return v.access(this,v.prop,e,t,arguments.length>1)},removeProp:function(e){return e=v.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,s,o,u;if(v.isFunction(e))return this.each(function(t){v(this).addClass(e.call(this,t,this.className))});if(e&&typeof e=="string"){t=e.split(y);for(n=0,r=this.length;n<r;n++){i=this[n];if(i.nodeType===1)if(!i.className&&t.length===1)i.className=e;else{s=" "+i.className+" ";for(o=0,u=t.length;o<u;o++)s.indexOf(" "+t[o]+" ")<0&&(s+=t[o]+" ");i.className=v.trim(s)}}}return this},removeClass:function(e){var n,r,i,s,o,u,a;if(v.isFunction(e))return this.each(function(t){v(this).removeClass(e.call(this,t,this.className))});if(e&&typeof e=="string"||e===t){n=(e||"").split(y);for(u=0,a=this.length;u<a;u++){i=this[u];if(i.nodeType===1&&i.className){r=(" "+i.className+" ").replace(q," ");for(s=0,o=n.length;s<o;s++)while(r.indexOf(" "+n[s]+" ")>=0)r=r.replace(" "+n[s]+" "," ");i.className=e?v.trim(r):""}}}return this},toggleClass:function(e,t){var n=typeof e,r=typeof t=="boolean";return v.isFunction(e)?this.each(function(n){v(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if(n==="string"){var i,s=0,o=v(this),u=t,a=e.split(y);while(i=a[s++])u=r?u:!o.hasClass(i),o[u?"addClass":"removeClass"](i)}else if(n==="undefined"||n==="boolean")this.className&&v._data(this,"__className__",this.className),this.className=this.className||e===!1?"":v._data(this,"__className__")||""})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;n<r;n++)if(this[n].nodeType===1&&(" "+this[n].className+" ").replace(q," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,s=this[0];if(!arguments.length){if(s)return n=v.valHooks[s.type]||v.valHooks[s.nodeName.toLowerCase()],n&&"get"in n&&(r=n.get(s,"value"))!==t?r:(r=s.value,typeof r=="string"?r.replace(R,""):r==null?"":r);return}return i=v.isFunction(e),this.each(function(r){var s,o=v(this);if(this.nodeType!==1)return;i?s=e.call(this,r,o.val()):s=e,s==null?s="":typeof s=="number"?s+="":v.isArray(s)&&(s=v.map(s,function(e){return e==null?"":e+""})),n=v.valHooks[this.type]||v.valHooks[this.nodeName.toLowerCase()];if(!n||!("set"in n)||n.set(this,s,"value")===t)this.value=s})}}),v.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,s=e.type==="select-one"||i<0,o=s?null:[],u=s?i+1:r.length,a=i<0?u:s?i:0;for(;a<u;a++){n=r[a];if((n.selected||a===i)&&(v.support.optDisabled?!n.disabled:n.getAttribute("disabled")===null)&&(!n.parentNode.disabled||!v.nodeName(n.parentNode,"optgroup"))){t=v(n).val();if(s)return t;o.push(t)}}return o},set:function(e,t){var n=v.makeArray(t);return v(e).find("option").each(function(){this.selected=v.inArray(v(this).val(),n)>=0}),n.length||(e.selectedIndex=-1),n}}},attrFn:{},attr:function(e,n,r,i){var s,o,u,a=e.nodeType;if(!e||a===3||a===8||a===2)return;if(i&&v.isFunction(v.fn[n]))return v(e)[n](r);if(typeof e.getAttribute=="undefined")return v.prop(e,n,r);u=a!==1||!v.isXMLDoc(e),u&&(n=n.toLowerCase(),o=v.attrHooks[n]||(X.test(n)?F:j));if(r!==t){if(r===null){v.removeAttr(e,n);return}return o&&"set"in o&&u&&(s=o.set(e,r,n))!==t?s:(e.setAttribute(n,r+""),r)}return o&&"get"in o&&u&&(s=o.get(e,n))!==null?s:(s=e.getAttribute(n),s===null?t:s)},removeAttr:function(e,t){var n,r,i,s,o=0;if(t&&e.nodeType===1){r=t.split(y);for(;o<r.length;o++)i=r[o],i&&(n=v.propFix[i]||i,s=X.test(i),s||v.attr(e,i,""),e.removeAttribute(V?i:n),s&&n in e&&(e[n]=!1))}},attrHooks:{type:{set:function(e,t){if(U.test(e.nodeName)&&e.parentNode)v.error("type property can't be changed");else if(!v.support.radioValue&&t==="radio"&&v.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}},value:{get:function(e,t){return j&&v.nodeName(e,"button")?j.get(e,t):t in e?e.value:null},set:function(e,t,n){if(j&&v.nodeName(e,"button"))return j.set(e,t,n);e.value=t}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(e,n,r){var i,s,o,u=e.nodeType;if(!e||u===3||u===8||u===2)return;return o=u!==1||!v.isXMLDoc(e),o&&(n=v.propFix[n]||n,s=v.propHooks[n]),r!==t?s&&"set"in s&&(i=s.set(e,r,n))!==t?i:e[n]=r:s&&"get"in s&&(i=s.get(e,n))!==null?i:e[n]},propHooks:{tabIndex:{get:function(e){var n=e.getAttributeNode("tabindex");return n&&n.specified?parseInt(n.value,10):z.test(e.nodeName)||W.test(e.nodeName)&&e.href?0:t}}}}),F={get:function(e,n){var r,i=v.prop(e,n);return i===!0||typeof i!="boolean"&&(r=e.getAttributeNode(n))&&r.nodeValue!==!1?n.toLowerCase():t},set:function(e,t,n){var r;return t===!1?v.removeAttr(e,n):(r=v.propFix[n]||n,r in e&&(e[r]=!0),e.setAttribute(n,n.toLowerCase())),n}},V||(I={name:!0,id:!0,coords:!0},j=v.valHooks.button={get:function(e,n){var r;return r=e.getAttributeNode(n),r&&(I[n]?r.value!=="":r.specified)?r.value:t},set:function(e,t,n){var r=e.getAttributeNode(n);return r||(r=i.createAttribute(n),e.setAttributeNode(r)),r.value=t+""}},v.each(["width","height"],function(e,t){v.attrHooks[t]=v.extend(v.attrHooks[t],{set:function(e,n){if(n==="")return e.setAttribute(t,"auto"),n}})}),v.attrHooks.contenteditable={get:j.get,set:function(e,t,n){t===""&&(t="false"),j.set(e,t,n)}}),v.support.hrefNormalized||v.each(["href","src","width","height"],function(e,n){v.attrHooks[n]=v.extend(v.attrHooks[n],{get:function(e){var r=e.getAttribute(n,2);return r===null?t:r}})}),v.support.style||(v.attrHooks.style={get:function(e){return e.style.cssText.toLowerCase()||t},set:function(e,t){return e.style.cssText=t+""}}),v.support.optSelected||(v.propHooks.selected=v.extend(v.propHooks.selected,{get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}})),v.support.enctype||(v.propFix.enctype="encoding"),v.support.checkOn||v.each(["radio","checkbox"],function(){v.valHooks[this]={get:function(e){return e.getAttribute("value")===null?"on":e.value}}}),v.each(["radio","checkbox"],function(){v.valHooks[this]=v.extend(v.valHooks[this],{set:function(e,t){if(v.isArray(t))return e.checked=v.inArray(v(e).val(),t)>=0}})});var $=/^(?:textarea|input|select)$/i,J=/^([^\.]*|)(?:\.(.+)|)$/,K=/(?:^|\s)hover(\.\S+|)\b/,Q=/^key/,G=/^(?:mouse|contextmenu)|click/,Y=/^(?:focusinfocus|focusoutblur)$/,Z=function(e){return v.event.special.hover?e:e.replace(K,"mouseenter$1 mouseleave$1")};v.event={add:function(e,n,r,i,s){var o,u,a,f,l,c,h,p,d,m,g;if(e.nodeType===3||e.nodeType===8||!n||!r||!(o=v._data(e)))return;r.handler&&(d=r,r=d.handler,s=d.selector),r.guid||(r.guid=v.guid++),a=o.events,a||(o.events=a={}),u=o.handle,u||(o.handle=u=function(e){return typeof v=="undefined"||!!e&&v.event.triggered===e.type?t:v.event.dispatch.apply(u.elem,arguments)},u.elem=e),n=v.trim(Z(n)).split(" ");for(f=0;f<n.length;f++){l=J.exec(n[f])||[],c=l[1],h=(l[2]||"").split(".").sort(),g=v.event.special[c]||{},c=(s?g.delegateType:g.bindType)||c,g=v.event.special[c]||{},p=v.extend({type:c,origType:l[1],data:i,handler:r,guid:r.guid,selector:s,needsContext:s&&v.expr.match.needsContext.test(s),namespace:h.join(".")},d),m=a[c];if(!m){m=a[c]=[],m.delegateCount=0;if(!g.setup||g.setup.call(e,i,h,u)===!1)e.addEventListener?e.addEventListener(c,u,!1):e.attachEvent&&e.attachEvent("on"+c,u)}g.add&&(g.add.call(e,p),p.handler.guid||(p.handler.guid=r.guid)),s?m.splice(m.delegateCount++,0,p):m.push(p),v.event.global[c]=!0}e=null},global:{},remove:function(e,t,n,r,i){var s,o,u,a,f,l,c,h,p,d,m,g=v.hasData(e)&&v._data(e);if(!g||!(h=g.events))return;t=v.trim(Z(t||"")).split(" ");for(s=0;s<t.length;s++){o=J.exec(t[s])||[],u=a=o[1],f=o[2];if(!u){for(u in h)v.event.remove(e,u+t[s],n,r,!0);continue}p=v.event.special[u]||{},u=(r?p.delegateType:p.bindType)||u,d=h[u]||[],l=d.length,f=f?new RegExp("(^|\\.)"+f.split(".").sort().join("\\.(?:.*\\.|)")+"(\\.|$)"):null;for(c=0;c<d.length;c++)m=d[c],(i||a===m.origType)&&(!n||n.guid===m.guid)&&(!f||f.test(m.namespace))&&(!r||r===m.selector||r==="**"&&m.selector)&&(d.splice(c--,1),m.selector&&d.delegateCount--,p.remove&&p.remove.call(e,m));d.length===0&&l!==d.length&&((!p.teardown||p.teardown.call(e,f,g.handle)===!1)&&v.removeEvent(e,u,g.handle),delete h[u])}v.isEmptyObject(h)&&(delete g.handle,v.removeData(e,"events",!0))},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(n,r,s,o){if(!s||s.nodeType!==3&&s.nodeType!==8){var u,a,f,l,c,h,p,d,m,g,y=n.type||n,b=[];if(Y.test(y+v.event.triggered))return;y.indexOf("!")>=0&&(y=y.slice(0,-1),a=!0),y.indexOf(".")>=0&&(b=y.split("."),y=b.shift(),b.sort());if((!s||v.event.customEvent[y])&&!v.event.global[y])return;n=typeof n=="object"?n[v.expando]?n:new v.Event(y,n):new v.Event(y),n.type=y,n.isTrigger=!0,n.exclusive=a,n.namespace=b.join("."),n.namespace_re=n.namespace?new RegExp("(^|\\.)"+b.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,h=y.indexOf(":")<0?"on"+y:"";if(!s){u=v.cache;for(f in u)u[f].events&&u[f].events[y]&&v.event.trigger(n,r,u[f].handle.elem,!0);return}n.result=t,n.target||(n.target=s),r=r!=null?v.makeArray(r):[],r.unshift(n),p=v.event.special[y]||{};if(p.trigger&&p.trigger.apply(s,r)===!1)return;m=[[s,p.bindType||y]];if(!o&&!p.noBubble&&!v.isWindow(s)){g=p.delegateType||y,l=Y.test(g+y)?s:s.parentNode;for(c=s;l;l=l.parentNode)m.push([l,g]),c=l;c===(s.ownerDocument||i)&&m.push([c.defaultView||c.parentWindow||e,g])}for(f=0;f<m.length&&!n.isPropagationStopped();f++)l=m[f][0],n.type=m[f][1],d=(v._data(l,"events")||{})[n.type]&&v._data(l,"handle"),d&&d.apply(l,r),d=h&&l[h],d&&v.acceptData(l)&&d.apply&&d.apply(l,r)===!1&&n.preventDefault();return n.type=y,!o&&!n.isDefaultPrevented()&&(!p._default||p._default.apply(s.ownerDocument,r)===!1)&&(y!=="click"||!v.nodeName(s,"a"))&&v.acceptData(s)&&h&&s[y]&&(y!=="focus"&&y!=="blur"||n.target.offsetWidth!==0)&&!v.isWindow(s)&&(c=s[h],c&&(s[h]=null),v.event.triggered=y,s[y](),v.event.triggered=t,c&&(s[h]=c)),n.result}return},dispatch:function(n){n=v.event.fix(n||e.event);var r,i,s,o,u,a,f,c,h,p,d=(v._data(this,"events")||{})[n.type]||[],m=d.delegateCount,g=l.call(arguments),y=!n.exclusive&&!n.namespace,b=v.event.special[n.type]||{},w=[];g[0]=n,n.delegateTarget=this;if(b.preDispatch&&b.preDispatch.call(this,n)===!1)return;if(m&&(!n.button||n.type!=="click"))for(s=n.target;s!=this;s=s.parentNode||this)if(s.disabled!==!0||n.type!=="click"){u={},f=[];for(r=0;r<m;r++)c=d[r],h=c.selector,u[h]===t&&(u[h]=c.needsContext?v(h,this).index(s)>=0:v.find(h,this,null,[s]).length),u[h]&&f.push(c);f.length&&w.push({elem:s,matches:f})}d.length>m&&w.push({elem:this,matches:d.slice(m)});for(r=0;r<w.length&&!n.isPropagationStopped();r++){a=w[r],n.currentTarget=a.elem;for(i=0;i<a.matches.length&&!n.isImmediatePropagationStopped();i++){c=a.matches[i];if(y||!n.namespace&&!c.namespace||n.namespace_re&&n.namespace_re.test(c.namespace))n.data=c.data,n.handleObj=c,o=((v.event.special[c.origType]||{}).handle||c.handler).apply(a.elem,g),o!==t&&(n.result=o,o===!1&&(n.preventDefault(),n.stopPropagation()))}}return b.postDispatch&&b.postDispatch.call(this,n),n.result},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return e.which==null&&(e.which=t.charCode!=null?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,s,o,u=n.button,a=n.fromElement;return e.pageX==null&&n.clientX!=null&&(r=e.target.ownerDocument||i,s=r.documentElement,o=r.body,e.pageX=n.clientX+(s&&s.scrollLeft||o&&o.scrollLeft||0)-(s&&s.clientLeft||o&&o.clientLeft||0),e.pageY=n.clientY+(s&&s.scrollTop||o&&o.scrollTop||0)-(s&&s.clientTop||o&&o.clientTop||0)),!e.relatedTarget&&a&&(e.relatedTarget=a===e.target?n.toElement:a),!e.which&&u!==t&&(e.which=u&1?1:u&2?3:u&4?2:0),e}},fix:function(e){if(e[v.expando])return e;var t,n,r=e,s=v.event.fixHooks[e.type]||{},o=s.props?this.props.concat(s.props):this.props;e=v.Event(r);for(t=o.length;t;)n=o[--t],e[n]=r[n];return e.target||(e.target=r.srcElement||i),e.target.nodeType===3&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,r):e},special:{load:{noBubble:!0},focus:{delegateType:"focusin"},blur:{delegateType:"focusout"},beforeunload:{setup:function(e,t,n){v.isWindow(this)&&(this.onbeforeunload=n)},teardown:function(e,t){this.onbeforeunload===t&&(this.onbeforeunload=null)}}},simulate:function(e,t,n,r){var i=v.extend(new v.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?v.event.trigger(i,null,t):v.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},v.event.handle=v.event.dispatch,v.removeEvent=i.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]=="undefined"&&(e[r]=null),e.detachEvent(r,n))},v.Event=function(e,t){if(!(this instanceof v.Event))return new v.Event(e,t);e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?tt:et):this.type=e,t&&v.extend(this,t),this.timeStamp=e&&e.timeStamp||v.now(),this[v.expando]=!0},v.Event.prototype={preventDefault:function(){this.isDefaultPrevented=tt;var e=this.originalEvent;if(!e)return;e.preventDefault?e.preventDefault():e.returnValue=!1},stopPropagation:function(){this.isPropagationStopped=tt;var e=this.originalEvent;if(!e)return;e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=tt,this.stopPropagation()},isDefaultPrevented:et,isPropagationStopped:et,isImmediatePropagationStopped:et},v.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){v.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,s=e.handleObj,o=s.selector;if(!i||i!==r&&!v.contains(r,i))e.type=s.origType,n=s.handler.apply(this,arguments),e.type=t;return n}}}),v.support.submitBubbles||(v.event.special.submit={setup:function(){if(v.nodeName(this,"form"))return!1;v.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=v.nodeName(n,"input")||v.nodeName(n,"button")?n.form:t;r&&!v._data(r,"_submit_attached")&&(v.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),v._data(r,"_submit_attached",!0))})},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&v.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){if(v.nodeName(this,"form"))return!1;v.event.remove(this,"._submit")}}),v.support.changeBubbles||(v.event.special.change={setup:function(){if($.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")v.event.add(this,"propertychange._change",function(e){e.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),v.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),v.event.simulate("change",this,e,!0)});return!1}v.event.add(this,"beforeactivate._change",function(e){var t=e.target;$.test(t.nodeName)&&!v._data(t,"_change_attached")&&(v.event.add(t,"change._change",function(e){this.parentNode&&!e.isSimulated&&!e.isTrigger&&v.event.simulate("change",this.parentNode,e,!0)}),v._data(t,"_change_attached",!0))})},handle:function(e){var t=e.target;if(this!==t||e.isSimulated||e.isTrigger||t.type!=="radio"&&t.type!=="checkbox")return e.handleObj.handler.apply(this,arguments)},teardown:function(){return v.event.remove(this,"._change"),!$.test(this.nodeName)}}),v.support.focusinBubbles||v.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){v.event.simulate(t,e.target,v.event.fix(e),!0)};v.event.special[t]={setup:function(){n++===0&&i.addEventListener(e,r,!0)},teardown:function(){--n===0&&i.removeEventListener(e,r,!0)}}}),v.fn.extend({on:function(e,n,r,i,s){var o,u;if(typeof e=="object"){typeof n!="string"&&(r=r||n,n=t);for(u in e)this.on(u,n,r,e[u],s);return this}r==null&&i==null?(i=n,r=n=t):i==null&&(typeof n=="string"?(i=r,r=t):(i=r,r=n,n=t));if(i===!1)i=et;else if(!i)return this;return s===1&&(o=i,i=function(e){return v().off(e),o.apply(this,arguments)},i.guid=o.guid||(o.guid=v.guid++)),this.each(function(){v.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,s;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,v(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if(typeof e=="object"){for(s in e)this.off(s,n,e[s]);return this}if(n===!1||typeof n=="function")r=n,n=t;return r===!1&&(r=et),this.each(function(){v.event.remove(this,e,r,n)})},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},live:function(e,t,n){return v(this.context).on(e,this.selector,t,n),this},die:function(e,t){return v(this.context).off(e,this.selector||"**",t),this},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return arguments.length===1?this.off(e,"**"):this.off(t,e||"**",n)},trigger:function(e,t){return this.each(function(){v.event.trigger(e,t,this)})},triggerHandler:function(e,t){if(this[0])return v.event.trigger(e,t,this[0],!0)},toggle:function(e){var t=arguments,n=e.guid||v.guid++,r=0,i=function(n){var i=(v._data(this,"lastToggle"+e.guid)||0)%r;return v._data(this,"lastToggle"+e.guid,i+1),n.preventDefault(),t[i].apply(this,arguments)||!1};i.guid=n;while(r<t.length)t[r++].guid=n;return this.click(i)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),v.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(e,t){v.fn[t]=function(e,n){return n==null&&(n=e,e=null),arguments.length>0?this.on(t,null,e,n):this.trigger(t)},Q.test(t)&&(v.event.fixHooks[t]=v.event.keyHooks),G.test(t)&&(v.event.fixHooks[t]=v.event.mouseHooks)}),function(e,t){function nt(e,t,n,r){n=n||[],t=t||g;var i,s,a,f,l=t.nodeType;if(!e||typeof e!="string")return n;if(l!==1&&l!==9)return[];a=o(t);if(!a&&!r)if(i=R.exec(e))if(f=i[1]){if(l===9){s=t.getElementById(f);if(!s||!s.parentNode)return n;if(s.id===f)return n.push(s),n}else if(t.ownerDocument&&(s=t.ownerDocument.getElementById(f))&&u(t,s)&&s.id===f)return n.push(s),n}else{if(i[2])return S.apply(n,x.call(t.getElementsByTagName(e),0)),n;if((f=i[3])&&Z&&t.getElementsByClassName)return S.apply(n,x.call(t.getElementsByClassName(f),0)),n}return vt(e.replace(j,"$1"),t,n,r,a)}function rt(e){return function(t){var n=t.nodeName.toLowerCase();return n==="input"&&t.type===e}}function it(e){return function(t){var n=t.nodeName.toLowerCase();return(n==="input"||n==="button")&&t.type===e}}function st(e){return N(function(t){return t=+t,N(function(n,r){var i,s=e([],n.length,t),o=s.length;while(o--)n[i=s[o]]&&(n[i]=!(r[i]=n[i]))})})}function ot(e,t,n){if(e===t)return n;var r=e.nextSibling;while(r){if(r===t)return-1;r=r.nextSibling}return 1}function ut(e,t){var n,r,s,o,u,a,f,l=L[d][e+" "];if(l)return t?0:l.slice(0);u=e,a=[],f=i.preFilter;while(u){if(!n||(r=F.exec(u)))r&&(u=u.slice(r[0].length)||u),a.push(s=[]);n=!1;if(r=I.exec(u))s.push(n=new m(r.shift())),u=u.slice(n.length),n.type=r[0].replace(j," ");for(o in i.filter)(r=J[o].exec(u))&&(!f[o]||(r=f[o](r)))&&(s.push(n=new m(r.shift())),u=u.slice(n.length),n.type=o,n.matches=r);if(!n)break}return t?u.length:u?nt.error(e):L(e,a).slice(0)}function at(e,t,r){var i=t.dir,s=r&&t.dir==="parentNode",o=w++;return t.first?function(t,n,r){while(t=t[i])if(s||t.nodeType===1)return e(t,n,r)}:function(t,r,u){if(!u){var a,f=b+" "+o+" ",l=f+n;while(t=t[i])if(s||t.nodeType===1){if((a=t[d])===l)return t.sizset;if(typeof a=="string"&&a.indexOf(f)===0){if(t.sizset)return t}else{t[d]=l;if(e(t,r,u))return t.sizset=!0,t;t.sizset=!1}}}else while(t=t[i])if(s||t.nodeType===1)if(e(t,r,u))return t}}function ft(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function lt(e,t,n,r,i){var s,o=[],u=0,a=e.length,f=t!=null;for(;u<a;u++)if(s=e[u])if(!n||n(s,r,i))o.push(s),f&&t.push(u);return o}function ct(e,t,n,r,i,s){return r&&!r[d]&&(r=ct(r)),i&&!i[d]&&(i=ct(i,s)),N(function(s,o,u,a){var f,l,c,h=[],p=[],d=o.length,v=s||dt(t||"*",u.nodeType?[u]:u,[]),m=e&&(s||!t)?lt(v,h,e,u,a):v,g=n?i||(s?e:d||r)?[]:o:m;n&&n(m,g,u,a);if(r){f=lt(g,p),r(f,[],u,a),l=f.length;while(l--)if(c=f[l])g[p[l]]=!(m[p[l]]=c)}if(s){if(i||e){if(i){f=[],l=g.length;while(l--)(c=g[l])&&f.push(m[l]=c);i(null,g=[],f,a)}l=g.length;while(l--)(c=g[l])&&(f=i?T.call(s,c):h[l])>-1&&(s[f]=!(o[f]=c))}}else g=lt(g===o?g.splice(d,g.length):g),i?i(null,o,g,a):S.apply(o,g)})}function ht(e){var t,n,r,s=e.length,o=i.relative[e[0].type],u=o||i.relative[" "],a=o?1:0,f=at(function(e){return e===t},u,!0),l=at(function(e){return T.call(t,e)>-1},u,!0),h=[function(e,n,r){return!o&&(r||n!==c)||((t=n).nodeType?f(e,n,r):l(e,n,r))}];for(;a<s;a++)if(n=i.relative[e[a].type])h=[at(ft(h),n)];else{n=i.filter[e[a].type].apply(null,e[a].matches);if(n[d]){r=++a;for(;r<s;r++)if(i.relative[e[r].type])break;return ct(a>1&&ft(h),a>1&&e.slice(0,a-1).join("").replace(j,"$1"),n,a<r&&ht(e.slice(a,r)),r<s&&ht(e=e.slice(r)),r<s&&e.join(""))}h.push(n)}return ft(h)}function pt(e,t){var r=t.length>0,s=e.length>0,o=function(u,a,f,l,h){var p,d,v,m=[],y=0,w="0",x=u&&[],T=h!=null,N=c,C=u||s&&i.find.TAG("*",h&&a.parentNode||a),k=b+=N==null?1:Math.E;T&&(c=a!==g&&a,n=o.el);for(;(p=C[w])!=null;w++){if(s&&p){for(d=0;v=e[d];d++)if(v(p,a,f)){l.push(p);break}T&&(b=k,n=++o.el)}r&&((p=!v&&p)&&y--,u&&x.push(p))}y+=w;if(r&&w!==y){for(d=0;v=t[d];d++)v(x,m,a,f);if(u){if(y>0)while(w--)!x[w]&&!m[w]&&(m[w]=E.call(l));m=lt(m)}S.apply(l,m),T&&!u&&m.length>0&&y+t.length>1&&nt.uniqueSort(l)}return T&&(b=k,c=N),x};return o.el=0,r?N(o):o}function dt(e,t,n){var r=0,i=t.length;for(;r<i;r++)nt(e,t[r],n);return n}function vt(e,t,n,r,s){var o,u,f,l,c,h=ut(e),p=h.length;if(!r&&h.length===1){u=h[0]=h[0].slice(0);if(u.length>2&&(f=u[0]).type==="ID"&&t.nodeType===9&&!s&&i.relative[u[1].type]){t=i.find.ID(f.matches[0].replace($,""),t,s)[0];if(!t)return n;e=e.slice(u.shift().length)}for(o=J.POS.test(e)?-1:u.length-1;o>=0;o--){f=u[o];if(i.relative[l=f.type])break;if(c=i.find[l])if(r=c(f.matches[0].replace($,""),z.test(u[0].type)&&t.parentNode||t,s)){u.splice(o,1),e=r.length&&u.join("");if(!e)return S.apply(n,x.call(r,0)),n;break}}}return a(e,h)(r,t,s,n,z.test(e)),n}function mt(){}var n,r,i,s,o,u,a,f,l,c,h=!0,p="undefined",d=("sizcache"+Math.random()).replace(".",""),m=String,g=e.document,y=g.documentElement,b=0,w=0,E=[].pop,S=[].push,x=[].slice,T=[].indexOf||function(e){var t=0,n=this.length;for(;t<n;t++)if(this[t]===e)return t;return-1},N=function(e,t){return e[d]=t==null||t,e},C=function(){var e={},t=[];return N(function(n,r){return t.push(n)>i.cacheLength&&delete e[t.shift()],e[n+" "]=r},e)},k=C(),L=C(),A=C(),O="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[-\\w]|[^\\x00-\\xa0])+",_=M.replace("w","w#"),D="([*^$|!~]?=)",P="\\["+O+"*("+M+")"+O+"*(?:"+D+O+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+_+")|)|)"+O+"*\\]",H=":("+M+")(?:\\((?:(['\"])((?:\\\\.|[^\\\\])*?)\\2|([^()[\\]]*|(?:(?:"+P+")|[^:]|\\\\.)*|.*))\\)|)",B=":(even|odd|eq|gt|lt|nth|first|last)(?:\\("+O+"*((?:-\\d)?\\d*)"+O+"*\\)|)(?=[^-]|$)",j=new RegExp("^"+O+"+|((?:^|[^\\\\])(?:\\\\.)*)"+O+"+$","g"),F=new RegExp("^"+O+"*,"+O+"*"),I=new RegExp("^"+O+"*([\\x20\\t\\r\\n\\f>+~])"+O+"*"),q=new RegExp(H),R=/^(?:#([\w\-]+)|(\w+)|\.([\w\-]+))$/,U=/^:not/,z=/[\x20\t\r\n\f]*[+~]/,W=/:not\($/,X=/h\d/i,V=/input|select|textarea|button/i,$=/\\(?!\\)/g,J={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),NAME:new RegExp("^\\[name=['\"]?("+M+")['\"]?\\]"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+H),POS:new RegExp(B,"i"),CHILD:new RegExp("^:(only|nth|first|last)-child(?:\\("+O+"*(even|odd|(([+-]|)(\\d*)n|)"+O+"*(?:([+-]|)"+O+"*(\\d+)|))"+O+"*\\)|)","i"),needsContext:new RegExp("^"+O+"*[>+~]|"+B,"i")},K=function(e){var t=g.createElement("div");try{return e(t)}catch(n){return!1}finally{t=null}},Q=K(function(e){return e.appendChild(g.createComment("")),!e.getElementsByTagName("*").length}),G=K(function(e){return e.innerHTML="<a href='#'></a>",e.firstChild&&typeof e.firstChild.getAttribute!==p&&e.firstChild.getAttribute("href")==="#"}),Y=K(function(e){e.innerHTML="<select></select>";var t=typeof e.lastChild.getAttribute("multiple");return t!=="boolean"&&t!=="string"}),Z=K(function(e){return e.innerHTML="<div class='hidden e'></div><div class='hidden'></div>",!e.getElementsByClassName||!e.getElementsByClassName("e").length?!1:(e.lastChild.className="e",e.getElementsByClassName("e").length===2)}),et=K(function(e){e.id=d+0,e.innerHTML="<a name='"+d+"'></a><div name='"+d+"'></div>",y.insertBefore(e,y.firstChild);var t=g.getElementsByName&&g.getElementsByName(d).length===2+g.getElementsByName(d+0).length;return r=!g.getElementById(d),y.removeChild(e),t});try{x.call(y.childNodes,0)[0].nodeType}catch(tt){x=function(e){var t,n=[];for(;t=this[e];e++)n.push(t);return n}}nt.matches=function(e,t){return nt(e,null,null,t)},nt.matchesSelector=function(e,t){return nt(t,null,null,[e]).length>0},s=nt.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(i===1||i===9||i===11){if(typeof e.textContent=="string")return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=s(e)}else if(i===3||i===4)return e.nodeValue}else for(;t=e[r];r++)n+=s(t);return n},o=nt.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?t.nodeName!=="HTML":!1},u=nt.contains=y.contains?function(e,t){var n=e.nodeType===9?e.documentElement:e,r=t&&t.parentNode;return e===r||!!(r&&r.nodeType===1&&n.contains&&n.contains(r))}:y.compareDocumentPosition?function(e,t){return t&&!!(e.compareDocumentPosition(t)&16)}:function(e,t){while(t=t.parentNode)if(t===e)return!0;return!1},nt.attr=function(e,t){var n,r=o(e);return r||(t=t.toLowerCase()),(n=i.attrHandle[t])?n(e):r||Y?e.getAttribute(t):(n=e.getAttributeNode(t),n?typeof e[t]=="boolean"?e[t]?t:null:n.specified?n.value:null:null)},i=nt.selectors={cacheLength:50,createPseudo:N,match:J,attrHandle:G?{}:{href:function(e){return e.getAttribute("href",2)},type:function(e){return e.getAttribute("type")}},find:{ID:r?function(e,t,n){if(typeof t.getElementById!==p&&!n){var r=t.getElementById(e);return r&&r.parentNode?[r]:[]}}:function(e,n,r){if(typeof n.getElementById!==p&&!r){var i=n.getElementById(e);return i?i.id===e||typeof i.getAttributeNode!==p&&i.getAttributeNode("id").value===e?[i]:t:[]}},TAG:Q?function(e,t){if(typeof t.getElementsByTagName!==p)return t.getElementsByTagName(e)}:function(e,t){var n=t.getElementsByTagName(e);if(e==="*"){var r,i=[],s=0;for(;r=n[s];s++)r.nodeType===1&&i.push(r);return i}return n},NAME:et&&function(e,t){if(typeof t.getElementsByName!==p)return t.getElementsByName(name)},CLASS:Z&&function(e,t,n){if(typeof t.getElementsByClassName!==p&&!n)return t.getElementsByClassName(e)}},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace($,""),e[3]=(e[4]||e[5]||"").replace($,""),e[2]==="~="&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),e[1]==="nth"?(e[2]||nt.error(e[0]),e[3]=+(e[3]?e[4]+(e[5]||1):2*(e[2]==="even"||e[2]==="odd")),e[4]=+(e[6]+e[7]||e[2]==="odd")):e[2]&&nt.error(e[0]),e},PSEUDO:function(e){var t,n;if(J.CHILD.test(e[0]))return null;if(e[3])e[2]=e[3];else if(t=e[4])q.test(t)&&(n=ut(t,!0))&&(n=t.indexOf(")",t.length-n)-t.length)&&(t=t.slice(0,n),e[0]=e[0].slice(0,n)),e[2]=t;return e.slice(0,3)}},filter:{ID:r?function(e){return e=e.replace($,""),function(t){return t.getAttribute("id")===e}}:function(e){return e=e.replace($,""),function(t){var n=typeof t.getAttributeNode!==p&&t.getAttributeNode("id");return n&&n.value===e}},TAG:function(e){return e==="*"?function(){return!0}:(e=e.replace($,"").toLowerCase(),function(t){return t.nodeName&&t.nodeName.toLowerCase()===e})},CLASS:function(e){var t=k[d][e+" "];return t||(t=new RegExp("(^|"+O+")"+e+"("+O+"|$)"))&&k(e,function(e){return t.test(e.className||typeof e.getAttribute!==p&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r,i){var s=nt.attr(r,e);return s==null?t==="!=":t?(s+="",t==="="?s===n:t==="!="?s!==n:t==="^="?n&&s.indexOf(n)===0:t==="*="?n&&s.indexOf(n)>-1:t==="$="?n&&s.substr(s.length-n.length)===n:t==="~="?(" "+s+" ").indexOf(n)>-1:t==="|="?s===n||s.substr(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r){return e==="nth"?function(e){var t,i,s=e.parentNode;if(n===1&&r===0)return!0;if(s){i=0;for(t=s.firstChild;t;t=t.nextSibling)if(t.nodeType===1){i++;if(e===t)break}}return i-=r,i===n||i%n===0&&i/n>=0}:function(t){var n=t;switch(e){case"only":case"first":while(n=n.previousSibling)if(n.nodeType===1)return!1;if(e==="first")return!0;n=t;case"last":while(n=n.nextSibling)if(n.nodeType===1)return!1;return!0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||nt.error("unsupported pseudo: "+e);return r[d]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?N(function(e,n){var i,s=r(e,t),o=s.length;while(o--)i=T.call(e,s[o]),e[i]=!(n[i]=s[o])}):function(e){return r(e,0,n)}):r}},pseudos:{not:N(function(e){var t=[],n=[],r=a(e.replace(j,"$1"));return r[d]?N(function(e,t,n,i){var s,o=r(e,null,i,[]),u=e.length;while(u--)if(s=o[u])e[u]=!(t[u]=s)}):function(e,i,s){return t[0]=e,r(t,null,s,n),!n.pop()}}),has:N(function(e){return function(t){return nt(e,t).length>0}}),contains:N(function(e){return function(t){return(t.textContent||t.innerText||s(t)).indexOf(e)>-1}}),enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return t==="input"&&!!e.checked||t==="option"&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},parent:function(e){return!i.pseudos.empty(e)},empty:function(e){var t;e=e.firstChild;while(e){if(e.nodeName>"@"||(t=e.nodeType)===3||t===4)return!1;e=e.nextSibling}return!0},header:function(e){return X.test(e.nodeName)},text:function(e){var t,n;return e.nodeName.toLowerCase()==="input"&&(t=e.type)==="text"&&((n=e.getAttribute("type"))==null||n.toLowerCase()===t)},radio:rt("radio"),checkbox:rt("checkbox"),file:rt("file"),password:rt("password"),image:rt("image"),submit:it("submit"),reset:it("reset"),button:function(e){var t=e.nodeName.toLowerCase();return t==="input"&&e.type==="button"||t==="button"},input:function(e){return V.test(e.nodeName)},focus:function(e){var t=e.ownerDocument;return e===t.activeElement&&(!t.hasFocus||t.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},active:function(e){return e===e.ownerDocument.activeElement},first:st(function(){return[0]}),last:st(function(e,t){return[t-1]}),eq:st(function(e,t,n){return[n<0?n+t:n]}),even:st(function(e,t){for(var n=0;n<t;n+=2)e.push(n);return e}),odd:st(function(e,t){for(var n=1;n<t;n+=2)e.push(n);return e}),lt:st(function(e,t,n){for(var r=n<0?n+t:n;--r>=0;)e.push(r);return e}),gt:st(function(e,t,n){for(var r=n<0?n+t:n;++r<t;)e.push(r);return e})}},f=y.compareDocumentPosition?function(e,t){return e===t?(l=!0,0):(!e.compareDocumentPosition||!t.compareDocumentPosition?e.compareDocumentPosition:e.compareDocumentPosition(t)&4)?-1:1}:function(e,t){if(e===t)return l=!0,0;if(e.sourceIndex&&t.sourceIndex)return e.sourceIndex-t.sourceIndex;var n,r,i=[],s=[],o=e.parentNode,u=t.parentNode,a=o;if(o===u)return ot(e,t);if(!o)return-1;if(!u)return 1;while(a)i.unshift(a),a=a.parentNode;a=u;while(a)s.unshift(a),a=a.parentNode;n=i.length,r=s.length;for(var f=0;f<n&&f<r;f++)if(i[f]!==s[f])return ot(i[f],s[f]);return f===n?ot(e,s[f],-1):ot(i[f],t,1)},[0,0].sort(f),h=!l,nt.uniqueSort=function(e){var t,n=[],r=1,i=0;l=h,e.sort(f);if(l){for(;t=e[r];r++)t===e[r-1]&&(i=n.push(r));while(i--)e.splice(n[i],1)}return e},nt.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},a=nt.compile=function(e,t){var n,r=[],i=[],s=A[d][e+" "];if(!s){t||(t=ut(e)),n=t.length;while(n--)s=ht(t[n]),s[d]?r.push(s):i.push(s);s=A(e,pt(i,r))}return s},g.querySelectorAll&&function(){var e,t=vt,n=/'|\\/g,r=/\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g,i=[":focus"],s=[":active"],u=y.matchesSelector||y.mozMatchesSelector||y.webkitMatchesSelector||y.oMatchesSelector||y.msMatchesSelector;K(function(e){e.innerHTML="<select><option selected=''></option></select>",e.querySelectorAll("[selected]").length||i.push("\\["+O+"*(?:checked|disabled|ismap|multiple|readonly|selected|value)"),e.querySelectorAll(":checked").length||i.push(":checked")}),K(function(e){e.innerHTML="<p test=''></p>",e.querySelectorAll("[test^='']").length&&i.push("[*^$]="+O+"*(?:\"\"|'')"),e.innerHTML="<input type='hidden'/>",e.querySelectorAll(":enabled").length||i.push(":enabled",":disabled")}),i=new RegExp(i.join("|")),vt=function(e,r,s,o,u){if(!o&&!u&&!i.test(e)){var a,f,l=!0,c=d,h=r,p=r.nodeType===9&&e;if(r.nodeType===1&&r.nodeName.toLowerCase()!=="object"){a=ut(e),(l=r.getAttribute("id"))?c=l.replace(n,"\\$&"):r.setAttribute("id",c),c="[id='"+c+"'] ",f=a.length;while(f--)a[f]=c+a[f].join("");h=z.test(e)&&r.parentNode||r,p=a.join(",")}if(p)try{return S.apply(s,x.call(h.querySelectorAll(p),0)),s}catch(v){}finally{l||r.removeAttribute("id")}}return t(e,r,s,o,u)},u&&(K(function(t){e=u.call(t,"div");try{u.call(t,"[test!='']:sizzle"),s.push("!=",H)}catch(n){}}),s=new RegExp(s.join("|")),nt.matchesSelector=function(t,n){n=n.replace(r,"='$1']");if(!o(t)&&!s.test(n)&&!i.test(n))try{var a=u.call(t,n);if(a||e||t.document&&t.document.nodeType!==11)return a}catch(f){}return nt(n,null,null,[t]).length>0})}(),i.pseudos.nth=i.pseudos.eq,i.filters=mt.prototype=i.pseudos,i.setFilters=new mt,nt.attr=v.attr,v.find=nt,v.expr=nt.selectors,v.expr[":"]=v.expr.pseudos,v.unique=nt.uniqueSort,v.text=nt.getText,v.isXMLDoc=nt.isXML,v.contains=nt.contains}(e);var nt=/Until$/,rt=/^(?:parents|prev(?:Until|All))/,it=/^.[^:#\[\.,]*$/,st=v.expr.match.needsContext,ot={children:!0,contents:!0,next:!0,prev:!0};v.fn.extend({find:function(e){var t,n,r,i,s,o,u=this;if(typeof e!="string")return v(e).filter(function(){for(t=0,n=u.length;t<n;t++)if(v.contains(u[t],this))return!0});o=this.pushStack("","find",e);for(t=0,n=this.length;t<n;t++){r=o.length,v.find(e,this[t],o);if(t>0)for(i=r;i<o.length;i++)for(s=0;s<r;s++)if(o[s]===o[i]){o.splice(i--,1);break}}return o},has:function(e){var t,n=v(e,this),r=n.length;return this.filter(function(){for(t=0;t<r;t++)if(v.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e,!1),"not",e)},filter:function(e){return this.pushStack(ft(this,e,!0),"filter",e)},is:function(e){return!!e&&(typeof e=="string"?st.test(e)?v(e,this.context).index(this[0])>=0:v.filter(e,this).length>0:this.filter(e).length>0)},closest:function(e,t){var n,r=0,i=this.length,s=[],o=st.test(e)||typeof e!="string"?v(e,t||this.context):0;for(;r<i;r++){n=this[r];while(n&&n.ownerDocument&&n!==t&&n.nodeType!==11){if(o?o.index(n)>-1:v.find.matchesSelector(n,e)){s.push(n);break}n=n.parentNode}}return s=s.length>1?v.unique(s):s,this.pushStack(s,"closest",e)},index:function(e){return e?typeof e=="string"?v.inArray(this[0],v(e)):v.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.prevAll().length:-1},add:function(e,t){var n=typeof e=="string"?v(e,t):v.makeArray(e&&e.nodeType?[e]:e),r=v.merge(this.get(),n);return this.pushStack(ut(n[0])||ut(r[0])?r:v.unique(r))},addBack:function(e){return this.add(e==null?this.prevObject:this.prevObject.filter(e))}}),v.fn.andSelf=v.fn.addBack,v.each({parent:function(e){var t=e.parentNode;return t&&t.nodeType!==11?t:null},parents:function(e){return v.dir(e,"parentNode")},parentsUntil:function(e,t,n){return v.dir(e,"parentNode",n)},next:function(e){return at(e,"nextSibling")},prev:function(e){return at(e,"previousSibling")},nextAll:function(e){return v.dir(e,"nextSibling")},prevAll:function(e){return v.dir(e,"previousSibling")},nextUntil:function(e,t,n){return v.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return v.dir(e,"previousSibling",n)},siblings:function(e){return v.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return v.sibling(e.firstChild)},contents:function(e){return v.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:v.merge([],e.childNodes)}},function(e,t){v.fn[e]=function(n,r){var i=v.map(this,t,n);return nt.test(e)||(r=n),r&&typeof r=="string"&&(i=v.filter(r,i)),i=this.length>1&&!ot[e]?v.unique(i):i,this.length>1&&rt.test(e)&&(i=i.reverse()),this.pushStack(i,e,l.call(arguments).join(","))}}),v.extend({filter:function(e,t,n){return n&&(e=":not("+e+")"),t.length===1?v.find.matchesSelector(t[0],e)?[t[0]]:[]:v.find.matches(e,t)},dir:function(e,n,r){var i=[],s=e[n];while(s&&s.nodeType!==9&&(r===t||s.nodeType!==1||!v(s).is(r)))s.nodeType===1&&i.push(s),s=s[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)e.nodeType===1&&e!==t&&n.push(e);return n}});var ct="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",ht=/ jQuery\d+="(?:null|\d+)"/g,pt=/^\s+/,dt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,vt=/<([\w:]+)/,mt=/<tbody/i,gt=/<|&#?\w+;/,yt=/<(?:script|style|link)/i,bt=/<(?:script|object|embed|option|style)/i,wt=new RegExp("<(?:"+ct+")[\\s/>]","i"),Et=/^(?:checkbox|radio)$/,St=/checked\s*(?:[^=]|=\s*.checked.)/i,xt=/\/(java|ecma)script/i,Tt=/^\s*<!(?:\[CDATA\[|\-\-)|[\]\-]{2}>\s*$/g,Nt={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},Ct=lt(i),kt=Ct.appendChild(i.createElement("div"));Nt.optgroup=Nt.option,Nt.tbody=Nt.tfoot=Nt.colgroup=Nt.caption=Nt.thead,Nt.th=Nt.td,v.support.htmlSerialize||(Nt._default=[1,"X<div>","</div>"]),v.fn.extend({text:function(e){return v.access(this,function(e){return e===t?v.text(this):this.empty().append((this[0]&&this[0].ownerDocument||i).createTextNode(e))},null,e,arguments.length)},wrapAll:function(e){if(v.isFunction(e))return this.each(function(t){v(this).wrapAll(e.call(this,t))});if(this[0]){var t=v(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&e.firstChild.nodeType===1)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return v.isFunction(e)?this.each(function(t){v(this).wrapInner(e.call(this,t))}):this.each(function(){var t=v(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=v.isFunction(e);return this.each(function(n){v(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){v.nodeName(this,"body")||v(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(e){(this.nodeType===1||this.nodeType===11)&&this.appendChild(e)})},prepend:function(){return this.domManip(arguments,!0,function(e){(this.nodeType===1||this.nodeType===11)&&this.insertBefore(e,this.firstChild)})},before:function(){if(!ut(this[0]))return this.domManip(arguments,!1,function(e){this.parentNode.insertBefore(e,this)});if(arguments.length){var e=v.clean(arguments);return this.pushStack(v.merge(e,this),"before",this.selector)}},after:function(){if(!ut(this[0]))return this.domManip(arguments,!1,function(e){this.parentNode.insertBefore(e,this.nextSibling)});if(arguments.length){var e=v.clean(arguments);return this.pushStack(v.merge(this,e),"after",this.selector)}},remove:function(e,t){var n,r=0;for(;(n=this[r])!=null;r++)if(!e||v.filter(e,[n]).length)!t&&n.nodeType===1&&(v.cleanData(n.getElementsByTagName("*")),v.cleanData([n])),n.parentNode&&n.parentNode.removeChild(n);return this},empty:function(){var e,t=0;for(;(e=this[t])!=null;t++){e.nodeType===1&&v.cleanData(e.getElementsByTagName("*"));while(e.firstChild)e.removeChild(e.firstChild)}return this},clone:function(e,t){return e=e==null?!1:e,t=t==null?e:t,this.map(function(){return v.clone(this,e,t)})},html:function(e){return v.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return n.nodeType===1?n.innerHTML.replace(ht,""):t;if(typeof e=="string"&&!yt.test(e)&&(v.support.htmlSerialize||!wt.test(e))&&(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace(dt,"<$1></$2>");try{for(;r<i;r++)n=this[r]||{},n.nodeType===1&&(v.cleanData(n.getElementsByTagName("*")),n.innerHTML=e);n=0}catch(s){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(e){return ut(this[0])?this.length?this.pushStack(v(v.isFunction(e)?e():e),"replaceWith",e):this:v.isFunction(e)?this.each(function(t){var n=v(this),r=n.html();n.replaceWith(e.call(this,t,r))}):(typeof e!="string"&&(e=v(e).detach()),this.each(function(){var t=this.nextSibling,n=this.parentNode;v(this).remove(),t?v(t).before(e):v(n).append(e)}))},detach:function(e){return this.remove(e,!0)},domManip:function(e,n,r){e=[].concat.apply([],e);var i,s,o,u,a=0,f=e[0],l=[],c=this.length;if(!v.support.checkClone&&c>1&&typeof f=="string"&&St.test(f))return this.each(function(){v(this).domManip(e,n,r)});if(v.isFunction(f))return this.each(function(i){var s=v(this);e[0]=f.call(this,i,n?s.html():t),s.domManip(e,n,r)});if(this[0]){i=v.buildFragment(e,this,l),o=i.fragment,s=o.firstChild,o.childNodes.length===1&&(o=s);if(s){n=n&&v.nodeName(s,"tr");for(u=i.cacheable||c-1;a<c;a++)r.call(n&&v.nodeName(this[a],"table")?Lt(this[a],"tbody"):this[a],a===u?o:v.clone(o,!0,!0))}o=s=null,l.length&&v.each(l,function(e,t){t.src?v.ajax?v.ajax({url:t.src,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0}):v.error("no ajax"):v.globalEval((t.text||t.textContent||t.innerHTML||"").replace(Tt,"")),t.parentNode&&t.parentNode.removeChild(t)})}return this}}),v.buildFragment=function(e,n,r){var s,o,u,a=e[0];return n=n||i,n=!n.nodeType&&n[0]||n,n=n.ownerDocument||n,e.length===1&&typeof a=="string"&&a.length<512&&n===i&&a.charAt(0)==="<"&&!bt.test(a)&&(v.support.checkClone||!St.test(a))&&(v.support.html5Clone||!wt.test(a))&&(o=!0,s=v.fragments[a],u=s!==t),s||(s=n.createDocumentFragment(),v.clean(e,n,s,r),o&&(v.fragments[a]=u&&s)),{fragment:s,cacheable:o}},v.fragments={},v.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){v.fn[e]=function(n){var r,i=0,s=[],o=v(n),u=o.length,a=this.length===1&&this[0].parentNode;if((a==null||a&&a.nodeType===11&&a.childNodes.length===1)&&u===1)return o[t](this[0]),this;for(;i<u;i++)r=(i>0?this.clone(!0):this).get(),v(o[i])[t](r),s=s.concat(r);return this.pushStack(s,e,o.selector)}}),v.extend({clone:function(e,t,n){var r,i,s,o;v.support.html5Clone||v.isXMLDoc(e)||!wt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(kt.innerHTML=e.outerHTML,kt.removeChild(o=kt.firstChild));if((!v.support.noCloneEvent||!v.support.noCloneChecked)&&(e.nodeType===1||e.nodeType===11)&&!v.isXMLDoc(e)){Ot(e,o),r=Mt(e),i=Mt(o);for(s=0;r[s];++s)i[s]&&Ot(r[s],i[s])}if(t){At(e,o);if(n){r=Mt(e),i=Mt(o);for(s=0;r[s];++s)At(r[s],i[s])}}return r=i=null,o},clean:function(e,t,n,r){var s,o,u,a,f,l,c,h,p,d,m,g,y=t===i&&Ct,b=[];if(!t||typeof t.createDocumentFragment=="undefined")t=i;for(s=0;(u=e[s])!=null;s++){typeof u=="number"&&(u+="");if(!u)continue;if(typeof u=="string")if(!gt.test(u))u=t.createTextNode(u);else{y=y||lt(t),c=t.createElement("div"),y.appendChild(c),u=u.replace(dt,"<$1></$2>"),a=(vt.exec(u)||["",""])[1].toLowerCase(),f=Nt[a]||Nt._default,l=f[0],c.innerHTML=f[1]+u+f[2];while(l--)c=c.lastChild;if(!v.support.tbody){h=mt.test(u),p=a==="table"&&!h?c.firstChild&&c.firstChild.childNodes:f[1]==="<table>"&&!h?c.childNodes:[];for(o=p.length-1;o>=0;--o)v.nodeName(p[o],"tbody")&&!p[o].childNodes.length&&p[o].parentNode.removeChild(p[o])}!v.support.leadingWhitespace&&pt.test(u)&&c.insertBefore(t.createTextNode(pt.exec(u)[0]),c.firstChild),u=c.childNodes,c.parentNode.removeChild(c)}u.nodeType?b.push(u):v.merge(b,u)}c&&(u=c=y=null);if(!v.support.appendChecked)for(s=0;(u=b[s])!=null;s++)v.nodeName(u,"input")?_t(u):typeof u.getElementsByTagName!="undefined"&&v.grep(u.getElementsByTagName("input"),_t);if(n){m=function(e){if(!e.type||xt.test(e.type))return r?r.push(e.parentNode?e.parentNode.removeChild(e):e):n.appendChild(e)};for(s=0;(u=b[s])!=null;s++)if(!v.nodeName(u,"script")||!m(u))n.appendChild(u),typeof u.getElementsByTagName!="undefined"&&(g=v.grep(v.merge([],u.getElementsByTagName("script")),m),b.splice.apply(b,[s+1,0].concat(g)),s+=g.length)}return b},cleanData:function(e,t){var n,r,i,s,o=0,u=v.expando,a=v.cache,f=v.support.deleteExpando,l=v.event.special;for(;(i=e[o])!=null;o++)if(t||v.acceptData(i)){r=i[u],n=r&&a[r];if(n){if(n.events)for(s in n.events)l[s]?v.event.remove(i,s):v.removeEvent(i,s,n.handle);a[r]&&(delete a[r],f?delete i[u]:i.removeAttribute?i.removeAttribute(u):i[u]=null,v.deletedIds.push(r))}}}}),function(){var e,t;v.uaMatch=function(e){e=e.toLowerCase();var t=/(chrome)[ \/]([\w.]+)/.exec(e)||/(webkit)[ \/]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[];return{browser:t[1]||"",version:t[2]||"0"}},e=v.uaMatch(o.userAgent),t={},e.browser&&(t[e.browser]=!0,t.version=e.version),t.chrome?t.webkit=!0:t.webkit&&(t.safari=!0),v.browser=t,v.sub=function(){function e(t,n){return new e.fn.init(t,n)}v.extend(!0,e,this),e.superclass=this,e.fn=e.prototype=this(),e.fn.constructor=e,e.sub=this.sub,e.fn.init=function(r,i){return i&&i instanceof v&&!(i instanceof e)&&(i=e(i)),v.fn.init.call(this,r,i,t)},e.fn.init.prototype=e.fn;var t=e(i);return e}}();var Dt,Pt,Ht,Bt=/alpha\([^)]*\)/i,jt=/opacity=([^)]*)/,Ft=/^(top|right|bottom|left)$/,It=/^(none|table(?!-c[ea]).+)/,qt=/^margin/,Rt=new RegExp("^("+m+")(.*)$","i"),Ut=new RegExp("^("+m+")(?!px)[a-z%]+$","i"),zt=new RegExp("^([-+])=("+m+")","i"),Wt={BODY:"block"},Xt={position:"absolute",visibility:"hidden",display:"block"},Vt={letterSpacing:0,fontWeight:400},$t=["Top","Right","Bottom","Left"],Jt=["Webkit","O","Moz","ms"],Kt=v.fn.toggle;v.fn.extend({css:function(e,n){return v.access(this,function(e,n,r){return r!==t?v.style(e,n,r):v.css(e,n)},e,n,arguments.length>1)},show:function(){return Yt(this,!0)},hide:function(){return Yt(this)},toggle:function(e,t){var n=typeof e=="boolean";return v.isFunction(e)&&v.isFunction(t)?Kt.apply(this,arguments):this.each(function(){(n?e:Gt(this))?v(this).show():v(this).hide()})}}),v.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Dt(e,"opacity");return n===""?"1":n}}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":v.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(!e||e.nodeType===3||e.nodeType===8||!e.style)return;var s,o,u,a=v.camelCase(n),f=e.style;n=v.cssProps[a]||(v.cssProps[a]=Qt(f,a)),u=v.cssHooks[n]||v.cssHooks[a];if(r===t)return u&&"get"in u&&(s=u.get(e,!1,i))!==t?s:f[n];o=typeof r,o==="string"&&(s=zt.exec(r))&&(r=(s[1]+1)*s[2]+parseFloat(v.css(e,n)),o="number");if(r==null||o==="number"&&isNaN(r))return;o==="number"&&!v.cssNumber[a]&&(r+="px");if(!u||!("set"in u)||(r=u.set(e,r,i))!==t)try{f[n]=r}catch(l){}},css:function(e,n,r,i){var s,o,u,a=v.camelCase(n);return n=v.cssProps[a]||(v.cssProps[a]=Qt(e.style,a)),u=v.cssHooks[n]||v.cssHooks[a],u&&"get"in u&&(s=u.get(e,!0,i)),s===t&&(s=Dt(e,n)),s==="normal"&&n in Vt&&(s=Vt[n]),r||i!==t?(o=parseFloat(s),r||v.isNumeric(o)?o||0:s):s},swap:function(e,t,n){var r,i,s={};for(i in t)s[i]=e.style[i],e.style[i]=t[i];r=n.call(e);for(i in t)e.style[i]=s[i];return r}}),e.getComputedStyle?Dt=function(t,n){var r,i,s,o,u=e.getComputedStyle(t,null),a=t.style;return u&&(r=u.getPropertyValue(n)||u[n],r===""&&!v.contains(t.ownerDocument,t)&&(r=v.style(t,n)),Ut.test(r)&&qt.test(n)&&(i=a.width,s=a.minWidth,o=a.maxWidth,a.minWidth=a.maxWidth=a.width=r,r=u.width,a.width=i,a.minWidth=s,a.maxWidth=o)),r}:i.documentElement.currentStyle&&(Dt=function(e,t){var n,r,i=e.currentStyle&&e.currentStyle[t],s=e.style;return i==null&&s&&s[t]&&(i=s[t]),Ut.test(i)&&!Ft.test(t)&&(n=s.left,r=e.runtimeStyle&&e.runtimeStyle.left,r&&(e.runtimeStyle.left=e.currentStyle.left),s.left=t==="fontSize"?"1em":i,i=s.pixelLeft+"px",s.left=n,r&&(e.runtimeStyle.left=r)),i===""?"auto":i}),v.each(["height","width"],function(e,t){v.cssHooks[t]={get:function(e,n,r){if(n)return e.offsetWidth===0&&It.test(Dt(e,"display"))?v.swap(e,Xt,function(){return tn(e,t,r)}):tn(e,t,r)},set:function(e,n,r){return Zt(e,n,r?en(e,t,r,v.support.boxSizing&&v.css(e,"boxSizing")==="border-box"):0)}}}),v.support.opacity||(v.cssHooks.opacity={get:function(e,t){return jt.test((t&&e.currentStyle?e.currentStyle.filter:e.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":t?"1":""},set:function(e,t){var n=e.style,r=e.currentStyle,i=v.isNumeric(t)?"alpha(opacity="+t*100+")":"",s=r&&r.filter||n.filter||"";n.zoom=1;if(t>=1&&v.trim(s.replace(Bt,""))===""&&n.removeAttribute){n.removeAttribute("filter");if(r&&!r.filter)return}n.filter=Bt.test(s)?s.replace(Bt,i):s+" "+i}}),v(function(){v.support.reliableMarginRight||(v.cssHooks.marginRight={get:function(e,t){return v.swap(e,{display:"inline-block"},function(){if(t)return Dt(e,"marginRight")})}}),!v.support.pixelPosition&&v.fn.position&&v.each(["top","left"],function(e,t){v.cssHooks[t]={get:function(e,n){if(n){var r=Dt(e,t);return Ut.test(r)?v(e).position()[t]+"px":r}}}})}),v.expr&&v.expr.filters&&(v.expr.filters.hidden=function(e){return e.offsetWidth===0&&e.offsetHeight===0||!v.support.reliableHiddenOffsets&&(e.style&&e.style.display||Dt(e,"display"))==="none"},v.expr.filters.visible=function(e){return!v.expr.filters.hidden(e)}),v.each({margin:"",padding:"",border:"Width"},function(e,t){v.cssHooks[e+t]={expand:function(n){var r,i=typeof n=="string"?n.split(" "):[n],s={};for(r=0;r<4;r++)s[e+$t[r]+t]=i[r]||i[r-2]||i[0];return s}},qt.test(e)||(v.cssHooks[e+t].set=Zt)});var rn=/%20/g,sn=/\[\]$/,on=/\r?\n/g,un=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,an=/^(?:select|textarea)/i;v.fn.extend({serialize:function(){return v.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?v.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||an.test(this.nodeName)||un.test(this.type))}).map(function(e,t){var n=v(this).val();return n==null?null:v.isArray(n)?v.map(n,function(e,n){return{name:t.name,value:e.replace(on,"\r\n")}}):{name:t.name,value:n.replace(on,"\r\n")}}).get()}}),v.param=function(e,n){var r,i=[],s=function(e,t){t=v.isFunction(t)?t():t==null?"":t,i[i.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};n===t&&(n=v.ajaxSettings&&v.ajaxSettings.traditional);if(v.isArray(e)||e.jquery&&!v.isPlainObject(e))v.each(e,function(){s(this.name,this.value)});else for(r in e)fn(r,e[r],n,s);return i.join("&").replace(rn,"+")};var ln,cn,hn=/#.*$/,pn=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,dn=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,vn=/^(?:GET|HEAD)$/,mn=/^\/\//,gn=/\?/,yn=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bn=/([?&])_=[^&]*/,wn=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,En=v.fn.load,Sn={},xn={},Tn=["*/"]+["*"];try{cn=s.href}catch(Nn){cn=i.createElement("a"),cn.href="",cn=cn.href}ln=wn.exec(cn.toLowerCase())||[],v.fn.load=function(e,n,r){if(typeof e!="string"&&En)return En.apply(this,arguments);if(!this.length)return this;var i,s,o,u=this,a=e.indexOf(" ");return a>=0&&(i=e.slice(a,e.length),e=e.slice(0,a)),v.isFunction(n)?(r=n,n=t):n&&typeof n=="object"&&(s="POST"),v.ajax({url:e,type:s,dataType:"html",data:n,complete:function(e,t){r&&u.each(r,o||[e.responseText,t,e])}}).done(function(e){o=arguments,u.html(i?v("<div>").append(e.replace(yn,"")).find(i):e)}),this},v.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(e,t){v.fn[t]=function(e){return this.on(t,e)}}),v.each(["get","post"],function(e,n){v[n]=function(e,r,i,s){return v.isFunction(r)&&(s=s||i,i=r,r=t),v.ajax({type:n,url:e,data:r,success:i,dataType:s})}}),v.extend({getScript:function(e,n){return v.get(e,t,n,"script")},getJSON:function(e,t,n){return v.get(e,t,n,"json")},ajaxSetup:function(e,t){return t?Ln(e,v.ajaxSettings):(t=e,e=v.ajaxSettings),Ln(e,t),e},ajaxSettings:{url:cn,isLocal:dn.test(ln[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded; charset=UTF-8",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":Tn},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":e.String,"text html":!0,"text json":v.parseJSON,"text xml":v.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:Cn(Sn),ajaxTransport:Cn(xn),ajax:function(e,n){function T(e,n,s,a){var l,y,b,w,S,T=n;if(E===2)return;E=2,u&&clearTimeout(u),o=t,i=a||"",x.readyState=e>0?4:0,s&&(w=An(c,x,s));if(e>=200&&e<300||e===304)c.ifModified&&(S=x.getResponseHeader("Last-Modified"),S&&(v.lastModified[r]=S),S=x.getResponseHeader("Etag"),S&&(v.etag[r]=S)),e===304?(T="notmodified",l=!0):(l=On(c,w),T=l.state,y=l.data,b=l.error,l=!b);else{b=T;if(!T||e)T="error",e<0&&(e=0)}x.status=e,x.statusText=(n||T)+"",l?d.resolveWith(h,[y,T,x]):d.rejectWith(h,[x,T,b]),x.statusCode(g),g=t,f&&p.trigger("ajax"+(l?"Success":"Error"),[x,c,l?y:b]),m.fireWith(h,[x,T]),f&&(p.trigger("ajaxComplete",[x,c]),--v.active||v.event.trigger("ajaxStop"))}typeof e=="object"&&(n=e,e=t),n=n||{};var r,i,s,o,u,a,f,l,c=v.ajaxSetup({},n),h=c.context||c,p=h!==c&&(h.nodeType||h instanceof v)?v(h):v.event,d=v.Deferred(),m=v.Callbacks("once memory"),g=c.statusCode||{},b={},w={},E=0,S="canceled",x={readyState:0,setRequestHeader:function(e,t){if(!E){var n=e.toLowerCase();e=w[n]=w[n]||e,b[e]=t}return this},getAllResponseHeaders:function(){return E===2?i:null},getResponseHeader:function(e){var n;if(E===2){if(!s){s={};while(n=pn.exec(i))s[n[1].toLowerCase()]=n[2]}n=s[e.toLowerCase()]}return n===t?null:n},overrideMimeType:function(e){return E||(c.mimeType=e),this},abort:function(e){return e=e||S,o&&o.abort(e),T(0,e),this}};d.promise(x),x.success=x.done,x.error=x.fail,x.complete=m.add,x.statusCode=function(e){if(e){var t;if(E<2)for(t in e)g[t]=[g[t],e[t]];else t=e[x.status],x.always(t)}return this},c.url=((e||c.url)+"").replace(hn,"").replace(mn,ln[1]+"//"),c.dataTypes=v.trim(c.dataType||"*").toLowerCase().split(y),c.crossDomain==null&&(a=wn.exec(c.url.toLowerCase()),c.crossDomain=!(!a||a[1]===ln[1]&&a[2]===ln[2]&&(a[3]||(a[1]==="http:"?80:443))==(ln[3]||(ln[1]==="http:"?80:443)))),c.data&&c.processData&&typeof c.data!="string"&&(c.data=v.param(c.data,c.traditional)),kn(Sn,c,n,x);if(E===2)return x;f=c.global,c.type=c.type.toUpperCase(),c.hasContent=!vn.test(c.type),f&&v.active++===0&&v.event.trigger("ajaxStart");if(!c.hasContent){c.data&&(c.url+=(gn.test(c.url)?"&":"?")+c.data,delete c.data),r=c.url;if(c.cache===!1){var N=v.now(),C=c.url.replace(bn,"$1_="+N);c.url=C+(C===c.url?(gn.test(c.url)?"&":"?")+"_="+N:"")}}(c.data&&c.hasContent&&c.contentType!==!1||n.contentType)&&x.setRequestHeader("Content-Type",c.contentType),c.ifModified&&(r=r||c.url,v.lastModified[r]&&x.setRequestHeader("If-Modified-Since",v.lastModified[r]),v.etag[r]&&x.setRequestHeader("If-None-Match",v.etag[r])),x.setRequestHeader("Accept",c.dataTypes[0]&&c.accepts[c.dataTypes[0]]?c.accepts[c.dataTypes[0]]+(c.dataTypes[0]!=="*"?", "+Tn+"; q=0.01":""):c.accepts["*"]);for(l in c.headers)x.setRequestHeader(l,c.headers[l]);if(!c.beforeSend||c.beforeSend.call(h,x,c)!==!1&&E!==2){S="abort";for(l in{success:1,error:1,complete:1})x[l](c[l]);o=kn(xn,c,n,x);if(!o)T(-1,"No Transport");else{x.readyState=1,f&&p.trigger("ajaxSend",[x,c]),c.async&&c.timeout>0&&(u=setTimeout(function(){x.abort("timeout")},c.timeout));try{E=1,o.send(b,T)}catch(k){if(!(E<2))throw k;T(-1,k)}}return x}return x.abort()},active:0,lastModified:{},etag:{}});var Mn=[],_n=/\?/,Dn=/(=)\?(?=&|$)|\?\?/,Pn=v.now();v.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Mn.pop()||v.expando+"_"+Pn++;return this[e]=!0,e}}),v.ajaxPrefilter("json jsonp",function(n,r,i){var s,o,u,a=n.data,f=n.url,l=n.jsonp!==!1,c=l&&Dn.test(f),h=l&&!c&&typeof a=="string"&&!(n.contentType||"").indexOf("application/x-www-form-urlencoded")&&Dn.test(a);if(n.dataTypes[0]==="jsonp"||c||h)return s=n.jsonpCallback=v.isFunction(n.jsonpCallback)?n.jsonpCallback():n.jsonpCallback,o=e[s],c?n.url=f.replace(Dn,"$1"+s):h?n.data=a.replace(Dn,"$1"+s):l&&(n.url+=(_n.test(f)?"&":"?")+n.jsonp+"="+s),n.converters["script json"]=function(){return u||v.error(s+" was not called"),u[0]},n.dataTypes[0]="json",e[s]=function(){u=arguments},i.always(function(){e[s]=o,n[s]&&(n.jsonpCallback=r.jsonpCallback,Mn.push(s)),u&&v.isFunction(o)&&o(u[0]),u=o=t}),"script"}),v.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(e){return v.globalEval(e),e}}}),v.ajaxPrefilter("script",function(e){e.cache===t&&(e.cache=!1),e.crossDomain&&(e.type="GET",e.global=!1)}),v.ajaxTransport("script",function(e){if(e.crossDomain){var n,r=i.head||i.getElementsByTagName("head")[0]||i.documentElement;return{send:function(s,o){n=i.createElement("script"),n.async="async",e.scriptCharset&&(n.charset=e.scriptCharset),n.src=e.url,n.onload=n.onreadystatechange=function(e,i){if(i||!n.readyState||/loaded|complete/.test(n.readyState))n.onload=n.onreadystatechange=null,r&&n.parentNode&&r.removeChild(n),n=t,i||o(200,"success")},r.insertBefore(n,r.firstChild)},abort:function(){n&&n.onload(0,1)}}}});var Hn,Bn=e.ActiveXObject?function(){for(var e in Hn)Hn[e](0,1)}:!1,jn=0;v.ajaxSettings.xhr=e.ActiveXObject?function(){return!this.isLocal&&Fn()||In()}:Fn,function(e){v.extend(v.support,{ajax:!!e,cors:!!e&&"withCredentials"in e})}(v.ajaxSettings.xhr()),v.support.ajax&&v.ajaxTransport(function(n){if(!n.crossDomain||v.support.cors){var r;return{send:function(i,s){var o,u,a=n.xhr();n.username?a.open(n.type,n.url,n.async,n.username,n.password):a.open(n.type,n.url,n.async);if(n.xhrFields)for(u in n.xhrFields)a[u]=n.xhrFields[u];n.mimeType&&a.overrideMimeType&&a.overrideMimeType(n.mimeType),!n.crossDomain&&!i["X-Requested-With"]&&(i["X-Requested-With"]="XMLHttpRequest");try{for(u in i)a.setRequestHeader(u,i[u])}catch(f){}a.send(n.hasContent&&n.data||null),r=function(e,i){var u,f,l,c,h;try{if(r&&(i||a.readyState===4)){r=t,o&&(a.onreadystatechange=v.noop,Bn&&delete Hn[o]);if(i)a.readyState!==4&&a.abort();else{u=a.status,l=a.getAllResponseHeaders(),c={},h=a.responseXML,h&&h.documentElement&&(c.xml=h);try{c.text=a.responseText}catch(p){}try{f=a.statusText}catch(p){f=""}!u&&n.isLocal&&!n.crossDomain?u=c.text?200:404:u===1223&&(u=204)}}}catch(d){i||s(-1,d)}c&&s(u,f,c,l)},n.async?a.readyState===4?setTimeout(r,0):(o=++jn,Bn&&(Hn||(Hn={},v(e).unload(Bn)),Hn[o]=r),a.onreadystatechange=r):r()},abort:function(){r&&r(0,1)}}}});var qn,Rn,Un=/^(?:toggle|show|hide)$/,zn=new RegExp("^(?:([-+])=|)("+m+")([a-z%]*)$","i"),Wn=/queueHooks$/,Xn=[Gn],Vn={"*":[function(e,t){var n,r,i=this.createTween(e,t),s=zn.exec(t),o=i.cur(),u=+o||0,a=1,f=20;if(s){n=+s[2],r=s[3]||(v.cssNumber[e]?"":"px");if(r!=="px"&&u){u=v.css(i.elem,e,!0)||n||1;do a=a||".5",u/=a,v.style(i.elem,e,u+r);while(a!==(a=i.cur()/o)&&a!==1&&--f)}i.unit=r,i.start=u,i.end=s[1]?u+(s[1]+1)*n:n}return i}]};v.Animation=v.extend(Kn,{tweener:function(e,t){v.isFunction(e)?(t=e,e=["*"]):e=e.split(" ");var n,r=0,i=e.length;for(;r<i;r++)n=e[r],Vn[n]=Vn[n]||[],Vn[n].unshift(t)},prefilter:function(e,t){t?Xn.unshift(e):Xn.push(e)}}),v.Tween=Yn,Yn.prototype={constructor:Yn,init:function(e,t,n,r,i,s){this.elem=e,this.prop=n,this.easing=i||"swing",this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=s||(v.cssNumber[n]?"":"px")},cur:function(){var e=Yn.propHooks[this.prop];return e&&e.get?e.get(this):Yn.propHooks._default.get(this)},run:function(e){var t,n=Yn.propHooks[this.prop];return this.options.duration?this.pos=t=v.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):this.pos=t=e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):Yn.propHooks._default.set(this),this}},Yn.prototype.init.prototype=Yn.prototype,Yn.propHooks={_default:{get:function(e){var t;return e.elem[e.prop]==null||!!e.elem.style&&e.elem.style[e.prop]!=null?(t=v.css(e.elem,e.prop,!1,""),!t||t==="auto"?0:t):e.elem[e.prop]},set:function(e){v.fx.step[e.prop]?v.fx.step[e.prop](e):e.elem.style&&(e.elem.style[v.cssProps[e.prop]]!=null||v.cssHooks[e.prop])?v.style(e.elem,e.prop,e.now+e.unit):e.elem[e.prop]=e.now}}},Yn.propHooks.scrollTop=Yn.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},v.each(["toggle","show","hide"],function(e,t){var n=v.fn[t];v.fn[t]=function(r,i,s){return r==null||typeof r=="boolean"||!e&&v.isFunction(r)&&v.isFunction(i)?n.apply(this,arguments):this.animate(Zn(t,!0),r,i,s)}}),v.fn.extend({fadeTo:function(e,t,n,r){return this.filter(Gt).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(e,t,n,r){var i=v.isEmptyObject(e),s=v.speed(t,n,r),o=function(){var t=Kn(this,v.extend({},e),s);i&&t.stop(!0)};return i||s.queue===!1?this.each(o):this.queue(s.queue,o)},stop:function(e,n,r){var i=function(e){var t=e.stop;delete e.stop,t(r)};return typeof e!="string"&&(r=n,n=e,e=t),n&&e!==!1&&this.queue(e||"fx",[]),this.each(function(){var t=!0,n=e!=null&&e+"queueHooks",s=v.timers,o=v._data(this);if(n)o[n]&&o[n].stop&&i(o[n]);else for(n in o)o[n]&&o[n].stop&&Wn.test(n)&&i(o[n]);for(n=s.length;n--;)s[n].elem===this&&(e==null||s[n].queue===e)&&(s[n].anim.stop(r),t=!1,s.splice(n,1));(t||!r)&&v.dequeue(this,e)})}}),v.each({slideDown:Zn("show"),slideUp:Zn("hide"),slideToggle:Zn("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,t){v.fn[e]=function(e,n,r){return this.animate(t,e,n,r)}}),v.speed=function(e,t,n){var r=e&&typeof e=="object"?v.extend({},e):{complete:n||!n&&t||v.isFunction(e)&&e,duration:e,easing:n&&t||t&&!v.isFunction(t)&&t};r.duration=v.fx.off?0:typeof r.duration=="number"?r.duration:r.duration in v.fx.speeds?v.fx.speeds[r.duration]:v.fx.speeds._default;if(r.queue==null||r.queue===!0)r.queue="fx";return r.old=r.complete,r.complete=function(){v.isFunction(r.old)&&r.old.call(this),r.queue&&v.dequeue(this,r.queue)},r},v.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2}},v.timers=[],v.fx=Yn.prototype.init,v.fx.tick=function(){var e,n=v.timers,r=0;qn=v.now();for(;r<n.length;r++)e=n[r],!e()&&n[r]===e&&n.splice(r--,1);n.length||v.fx.stop(),qn=t},v.fx.timer=function(e){e()&&v.timers.push(e)&&!Rn&&(Rn=setInterval(v.fx.tick,v.fx.interval))},v.fx.interval=13,v.fx.stop=function(){clearInterval(Rn),Rn=null},v.fx.speeds={slow:600,fast:200,_default:400},v.fx.step={},v.expr&&v.expr.filters&&(v.expr.filters.animated=function(e){return v.grep(v.timers,function(t){return e===t.elem}).length});var er=/^(?:body|html)$/i;v.fn.offset=function(e){if(arguments.length)return e===t?this:this.each(function(t){v.offset.setOffset(this,e,t)});var n,r,i,s,o,u,a,f={top:0,left:0},l=this[0],c=l&&l.ownerDocument;if(!c)return;return(r=c.body)===l?v.offset.bodyOffset(l):(n=c.documentElement,v.contains(n,l)?(typeof l.getBoundingClientRect!="undefined"&&(f=l.getBoundingClientRect()),i=tr(c),s=n.clientTop||r.clientTop||0,o=n.clientLeft||r.clientLeft||0,u=i.pageYOffset||n.scrollTop,a=i.pageXOffset||n.scrollLeft,{top:f.top+u-s,left:f.left+a-o}):f)},v.offset={bodyOffset:function(e){var t=e.offsetTop,n=e.offsetLeft;return v.support.doesNotIncludeMarginInBodyOffset&&(t+=parseFloat(v.css(e,"marginTop"))||0,n+=parseFloat(v.css(e,"marginLeft"))||0),{top:t,left:n}},setOffset:function(e,t,n){var r=v.css(e,"position");r==="static"&&(e.style.position="relative");var i=v(e),s=i.offset(),o=v.css(e,"top"),u=v.css(e,"left"),a=(r==="absolute"||r==="fixed")&&v.inArray("auto",[o,u])>-1,f={},l={},c,h;a?(l=i.position(),c=l.top,h=l.left):(c=parseFloat(o)||0,h=parseFloat(u)||0),v.isFunction(t)&&(t=t.call(e,n,s)),t.top!=null&&(f.top=t.top-s.top+c),t.left!=null&&(f.left=t.left-s.left+h),"using"in t?t.using.call(e,f):i.css(f)}},v.fn.extend({position:function(){if(!this[0])return;var e=this[0],t=this.offsetParent(),n=this.offset(),r=er.test(t[0].nodeName)?{top:0,left:0}:t.offset();return n.top-=parseFloat(v.css(e,"marginTop"))||0,n.left-=parseFloat(v.css(e,"marginLeft"))||0,r.top+=parseFloat(v.css(t[0],"borderTopWidth"))||0,r.left+=parseFloat(v.css(t[0],"borderLeftWidth"))||0,{top:n.top-r.top,left:n.left-r.left}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||i.body;while(e&&!er.test(e.nodeName)&&v.css(e,"position")==="static")e=e.offsetParent;return e||i.body})}}),v.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,n){var r=/Y/.test(n);v.fn[e]=function(i){return v.access(this,function(e,i,s){var o=tr(e);if(s===t)return o?n in o?o[n]:o.document.documentElement[i]:e[i];o?o.scrollTo(r?v(o).scrollLeft():s,r?s:v(o).scrollTop()):e[i]=s},e,i,arguments.length,null)}}),v.each({Height:"height",Width:"width"},function(e,n){v.each({padding:"inner"+e,content:n,"":"outer"+e},function(r,i){v.fn[i]=function(i,s){var o=arguments.length&&(r||typeof i!="boolean"),u=r||(i===!0||s===!0?"margin":"border");return v.access(this,function(n,r,i){var s;return v.isWindow(n)?n.document.documentElement["client"+e]:n.nodeType===9?(s=n.documentElement,Math.max(n.body["scroll"+e],s["scroll"+e],n.body["offset"+e],s["offset"+e],s["client"+e])):i===t?v.css(n,r,i,u):v.style(n,r,i,u)},n,o?i:t,o,null)}})}),e.jQuery=e.$=v,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return v})})(window); |
|
define('jquery', ['jquery/jquery'], function (main) { return main; }); |
|
|
|
define("jquery/jquery", function(){}); |
|
|
|
/*! |
|
* Lo-Dash v0.9.2 <http://lodash.com> |
|
* (c) 2012 John-David Dalton <http://allyoucanleet.com/> |
|
* Based on Underscore.js 1.4.2 <http://underscorejs.org> |
|
* (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. |
|
* Available under MIT license <http://lodash.com/license> |
|
*/ |
|
;(function(window, undefined) { |
|
|
|
/** Detect free variable `exports` */ |
|
var freeExports = typeof exports == 'object' && exports; |
|
|
|
/** Detect free variable `global` and use it as `window` */ |
|
var freeGlobal = typeof global == 'object' && global; |
|
if (freeGlobal.global === freeGlobal) { |
|
window = freeGlobal; |
|
} |
|
|
|
/** Used for array and object method references */ |
|
var arrayRef = [], |
|
// avoid a Closure Compiler bug by creatively creating an object |
|
objectRef = new function(){}; |
|
|
|
/** Used to generate unique IDs */ |
|
var idCounter = 0; |
|
|
|
/** Used internally to indicate various things */ |
|
var indicatorObject = objectRef; |
|
|
|
/** Used by `cachedContains` as the default size when optimizations are enabled for large arrays */ |
|
var largeArraySize = 30; |
|
|
|
/** Used to restore the original `_` reference in `noConflict` */ |
|
var oldDash = window._; |
|
|
|
/** Used to detect template delimiter values that require a with-statement */ |
|
var reComplexDelimiter = /[-?+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/; |
|
|
|
/** Used to match HTML entities */ |
|
var reEscapedHtml = /&(?:amp|lt|gt|quot|#x27);/g; |
|
|
|
/** Used to match empty string literals in compiled template source */ |
|
var reEmptyStringLeading = /\b__p \+= '';/g, |
|
reEmptyStringMiddle = /\b(__p \+=) '' \+/g, |
|
reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; |
|
|
|
/** Used to match regexp flags from their coerced string values */ |
|
var reFlags = /\w*$/; |
|
|
|
/** Used to insert the data object variable into compiled template source */ |
|
var reInsertVariable = /(?:__e|__t = )\(\s*(?![\d\s"']|this\.)/g; |
|
|
|
/** Used to detect if a method is native */ |
|
var reNative = RegExp('^' + |
|
(objectRef.valueOf + '') |
|
.replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&') |
|
.replace(/valueOf|for [^\]]+/g, '.+?') + '$' |
|
); |
|
|
|
/** |
|
* Used to match ES6 template delimiters |
|
* http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.8.6 |
|
*/ |
|
var reEsTemplate = /\$\{((?:(?=\\?)\\?[\s\S])*?)}/g; |
|
|
|
/** Used to match "interpolate" template delimiters */ |
|
var reInterpolate = /<%=([\s\S]+?)%>/g; |
|
|
|
/** Used to ensure capturing order of template delimiters */ |
|
var reNoMatch = /($^)/; |
|
|
|
/** Used to match HTML characters */ |
|
var reUnescapedHtml = /[&<>"']/g; |
|
|
|
/** Used to match unescaped characters in compiled string literals */ |
|
var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g; |
|
|
|
/** Used to fix the JScript [[DontEnum]] bug */ |
|
var shadowed = [ |
|
'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', |
|
'toLocaleString', 'toString', 'valueOf' |
|
]; |
|
|
|
/** Used to make template sourceURLs easier to identify */ |
|
var templateCounter = 0; |
|
|
|
/** Native method shortcuts */ |
|
var ceil = Math.ceil, |
|
concat = arrayRef.concat, |
|
floor = Math.floor, |
|
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf, |
|
hasOwnProperty = objectRef.hasOwnProperty, |
|
push = arrayRef.push, |
|
propertyIsEnumerable = objectRef.propertyIsEnumerable, |
|
slice = arrayRef.slice, |
|
toString = objectRef.toString; |
|
|
|
/* Native method shortcuts for methods with the same name as other `lodash` methods */ |
|
var nativeBind = reNative.test(nativeBind = slice.bind) && nativeBind, |
|
nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, |
|
nativeIsFinite = window.isFinite, |
|
nativeIsNaN = window.isNaN, |
|
nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys, |
|
nativeMax = Math.max, |
|
nativeMin = Math.min, |
|
nativeRandom = Math.random; |
|
|
|
/** `Object#toString` result shortcuts */ |
|
var argsClass = '[object Arguments]', |
|
arrayClass = '[object Array]', |
|
boolClass = '[object Boolean]', |
|
dateClass = '[object Date]', |
|
funcClass = '[object Function]', |
|
numberClass = '[object Number]', |
|
objectClass = '[object Object]', |
|
regexpClass = '[object RegExp]', |
|
stringClass = '[object String]'; |
|
|
|
/** |
|
* Detect the JScript [[DontEnum]] bug: |
|
* |
|
* In IE < 9 an objects own properties, shadowing non-enumerable ones, are |
|
* made non-enumerable as well. |
|
*/ |
|
var hasDontEnumBug; |
|
|
|
/** Detect if own properties are iterated after inherited properties (IE < 9) */ |
|
var iteratesOwnLast; |
|
|
|
/** |
|
* Detect if `Array#shift` and `Array#splice` augment array-like objects |
|
* incorrectly: |
|
* |
|
* Firefox < 10, IE compatibility mode, and IE < 9 have buggy Array `shift()` |
|
* and `splice()` functions that fail to remove the last element, `value[0]`, |
|
* of array-like objects even though the `length` property is set to `0`. |
|
* The `shift()` method is buggy in IE 8 compatibility mode, while `splice()` |
|
* is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9. |
|
*/ |
|
var hasObjectSpliceBug = (hasObjectSpliceBug = { '0': 1, 'length': 1 }, |
|
arrayRef.splice.call(hasObjectSpliceBug, 0, 1), hasObjectSpliceBug[0]); |
|
|
|
/** Detect if an `arguments` object's indexes are non-enumerable (IE < 9) */ |
|
var noArgsEnum = true; |
|
|
|
(function() { |
|
var props = []; |
|
function ctor() { this.x = 1; } |
|
ctor.prototype = { 'valueOf': 1, 'y': 1 }; |
|
for (var prop in new ctor) { props.push(prop); } |
|
for (prop in arguments) { noArgsEnum = !prop; } |
|
|
|
hasDontEnumBug = !/valueOf/.test(props); |
|
iteratesOwnLast = props[0] != 'x'; |
|
}(1)); |
|
|
|
/** Detect if an `arguments` object's [[Class]] is unresolvable (Firefox < 4, IE < 9) */ |
|
var noArgsClass = !isArguments(arguments); |
|
|
|
/** Detect if `Array#slice` cannot be used to convert strings to arrays (Opera < 10.52) */ |
|
var noArraySliceOnStrings = slice.call('x')[0] != 'x'; |
|
|
|
/** |
|
* Detect lack of support for accessing string characters by index: |
|
* |
|
* IE < 8 can't access characters by index and IE 8 can only access |
|
* characters by index on string literals. |
|
*/ |
|
var noCharByIndex = ('x'[0] + Object('x')[0]) != 'xx'; |
|
|
|
/** |
|
* Detect if a node's [[Class]] is unresolvable (IE < 9) |
|
* and that the JS engine won't error when attempting to coerce an object to |
|
* a string without a `toString` property value of `typeof` "function". |
|
*/ |
|
try { |
|
var noNodeClass = ({ 'toString': 0 } + '', toString.call(window.document || 0) == objectClass); |
|
} catch(e) { } |
|
|
|
/* Detect if `Function#bind` exists and is inferred to be fast (all but V8) */ |
|
var isBindFast = nativeBind && /\n|Opera/.test(nativeBind + toString.call(window.opera)); |
|
|
|
/* Detect if `Object.keys` exists and is inferred to be fast (IE, Opera, V8) */ |
|
var isKeysFast = nativeKeys && /^.+$|true/.test(nativeKeys + !!window.attachEvent); |
|
|
|
/** |
|
* Detect if sourceURL syntax is usable without erroring: |
|
* |
|
* The JS engine in Adobe products, like InDesign, will throw a syntax error |
|
* when it encounters a single line comment beginning with the `@` symbol. |
|
* |
|
* The JS engine in Narwhal will generate the function `function anonymous(){//}` |
|
* and throw a syntax error. |
|
* |
|
* Avoid comments beginning `@` symbols in IE because they are part of its |
|
* non-standard conditional compilation support. |
|
* http://msdn.microsoft.com/en-us/library/121hztk3(v=vs.94).aspx |
|
*/ |
|
try { |
|
var useSourceURL = (Function('//@')(), !window.attachEvent); |
|
} catch(e) { } |
|
|
|
/** Used to identify object classifications that `_.clone` supports */ |
|
var cloneableClasses = {}; |
|
cloneableClasses[argsClass] = cloneableClasses[funcClass] = false; |
|
cloneableClasses[arrayClass] = cloneableClasses[boolClass] = cloneableClasses[dateClass] = |
|
cloneableClasses[numberClass] = cloneableClasses[objectClass] = cloneableClasses[regexpClass] = |
|
cloneableClasses[stringClass] = true; |
|
|
|
/** Used to determine if values are of the language type Object */ |
|
var objectTypes = { |
|
'boolean': false, |
|
'function': true, |
|
'object': true, |
|
'number': false, |
|
'string': false, |
|
'undefined': false |
|
}; |
|
|
|
/** Used to escape characters for inclusion in compiled string literals */ |
|
var stringEscapes = { |
|
'\\': '\\', |
|
"'": "'", |
|
'\n': 'n', |
|
'\r': 'r', |
|
'\t': 't', |
|
'\u2028': 'u2028', |
|
'\u2029': 'u2029' |
|
}; |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* The `lodash` function. |
|
* |
|
* @name _ |
|
* @constructor |
|
* @category Chaining |
|
* @param {Mixed} value The value to wrap in a `lodash` instance. |
|
* @returns {Object} Returns a `lodash` instance. |
|
*/ |
|
function lodash(value) { |
|
// exit early if already wrapped |
|
if (value && value.__wrapped__) { |
|
return value; |
|
} |
|
// allow invoking `lodash` without the `new` operator |
|
if (!(this instanceof lodash)) { |
|
return new lodash(value); |
|
} |
|
this.__wrapped__ = value; |
|
} |
|
|
|
/** |
|
* By default, the template delimiters used by Lo-Dash are similar to those in |
|
* embedded Ruby (ERB). Change the following template settings to use alternative |
|
* delimiters. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type Object |
|
*/ |
|
lodash.templateSettings = { |
|
|
|
/** |
|
* Used to detect `data` property values to be HTML-escaped. |
|
* |
|
* @static |
|
* @memberOf _.templateSettings |
|
* @type RegExp |
|
*/ |
|
'escape': /<%-([\s\S]+?)%>/g, |
|
|
|
/** |
|
* Used to detect code to be evaluated. |
|
* |
|
* @static |
|
* @memberOf _.templateSettings |
|
* @type RegExp |
|
*/ |
|
'evaluate': /<%([\s\S]+?)%>/g, |
|
|
|
/** |
|
* Used to detect `data` property values to inject. |
|
* |
|
* @static |
|
* @memberOf _.templateSettings |
|
* @type RegExp |
|
*/ |
|
'interpolate': reInterpolate, |
|
|
|
/** |
|
* Used to reference the data object in the template text. |
|
* |
|
* @static |
|
* @memberOf _.templateSettings |
|
* @type String |
|
*/ |
|
'variable': '' |
|
}; |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* The template used to create iterator functions. |
|
* |
|
* @private |
|
* @param {Obect} data The data object used to populate the text. |
|
* @returns {String} Returns the interpolated text. |
|
*/ |
|
var iteratorTemplate = template( |
|
// conditional strict mode |
|
'<% if (obj.useStrict) { %>\'use strict\';\n<% } %>' + |
|
|
|
// the `iteratee` may be reassigned by the `top` snippet |
|
'var index, value, iteratee = <%= firstArg %>, ' + |
|
// assign the `result` variable an initial value |
|
'result = <%= firstArg %>;\n' + |
|
// exit early if the first argument is falsey |
|
'if (!<%= firstArg %>) return result;\n' + |
|
// add code before the iteration branches |
|
'<%= top %>;\n' + |
|
|
|
// array-like iteration: |
|
'<% if (arrayLoop) { %>' + |
|
'var length = iteratee.length; index = -1;\n' + |
|
'if (typeof length == \'number\') {' + |
|
|
|
// add support for accessing string characters by index if needed |
|
' <% if (noCharByIndex) { %>\n' + |
|
' if (isString(iteratee)) {\n' + |
|
' iteratee = iteratee.split(\'\')\n' + |
|
' }' + |
|
' <% } %>\n' + |
|
|
|
// iterate over the array-like value |
|
' while (++index < length) {\n' + |
|
' value = iteratee[index];\n' + |
|
' <%= arrayLoop %>\n' + |
|
' }\n' + |
|
'}\n' + |
|
'else {' + |
|
|
|
// object iteration: |
|
// add support for iterating over `arguments` objects if needed |
|
' <% } else if (noArgsEnum) { %>\n' + |
|
' var length = iteratee.length; index = -1;\n' + |
|
' if (length && isArguments(iteratee)) {\n' + |
|
' while (++index < length) {\n' + |
|
' value = iteratee[index += \'\'];\n' + |
|
' <%= objectLoop %>\n' + |
|
' }\n' + |
|
' } else {' + |
|
' <% } %>' + |
|
|
|
// Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1 |
|
// (if the prototype or a property on the prototype has been set) |
|
// incorrectly sets a function's `prototype` property [[Enumerable]] |
|
// value to `true`. Because of this Lo-Dash standardizes on skipping |
|
// the the `prototype` property of functions regardless of its |
|
// [[Enumerable]] value. |
|
' <% if (!hasDontEnumBug) { %>\n' + |
|
' var skipProto = typeof iteratee == \'function\' && \n' + |
|
' propertyIsEnumerable.call(iteratee, \'prototype\');\n' + |
|
' <% } %>' + |
|
|
|
// iterate own properties using `Object.keys` if it's fast |
|
' <% if (isKeysFast && useHas) { %>\n' + |
|
' var ownIndex = -1,\n' + |
|
' ownProps = objectTypes[typeof iteratee] ? nativeKeys(iteratee) : [],\n' + |
|
' length = ownProps.length;\n\n' + |
|
' while (++ownIndex < length) {\n' + |
|
' index = ownProps[ownIndex];\n' + |
|
' <% if (!hasDontEnumBug) { %>if (!(skipProto && index == \'prototype\')) {\n <% } %>' + |
|
' value = iteratee[index];\n' + |
|
' <%= objectLoop %>\n' + |
|
' <% if (!hasDontEnumBug) { %>}\n<% } %>' + |
|
' }' + |
|
|
|
// else using a for-in loop |
|
' <% } else { %>\n' + |
|
' for (index in iteratee) {<%' + |
|
' if (!hasDontEnumBug || useHas) { %>\n if (<%' + |
|
' if (!hasDontEnumBug) { %>!(skipProto && index == \'prototype\')<% }' + |
|
' if (!hasDontEnumBug && useHas) { %> && <% }' + |
|
' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' + |
|
' %>) {' + |
|
' <% } %>\n' + |
|
' value = iteratee[index];\n' + |
|
' <%= objectLoop %>;' + |
|
' <% if (!hasDontEnumBug || useHas) { %>\n }<% } %>\n' + |
|
' }' + |
|
' <% } %>' + |
|
|
|
// Because IE < 9 can't set the `[[Enumerable]]` attribute of an |
|
// existing property and the `constructor` property of a prototype |
|
// defaults to non-enumerable, Lo-Dash skips the `constructor` |
|
// property when it infers it's iterating over a `prototype` object. |
|
' <% if (hasDontEnumBug) { %>\n\n' + |
|
' var ctor = iteratee.constructor;\n' + |
|
' <% for (var k = 0; k < 7; k++) { %>\n' + |
|
' index = \'<%= shadowed[k] %>\';\n' + |
|
' if (<%' + |
|
' if (shadowed[k] == \'constructor\') {' + |
|
' %>!(ctor && ctor.prototype === iteratee) && <%' + |
|
' } %>hasOwnProperty.call(iteratee, index)) {\n' + |
|
' value = iteratee[index];\n' + |
|
' <%= objectLoop %>\n' + |
|
' }' + |
|
' <% } %>' + |
|
' <% } %>' + |
|
' <% if (arrayLoop || noArgsEnum) { %>\n}<% } %>\n' + |
|
|
|
// add code to the bottom of the iteration function |
|
'<%= bottom %>;\n' + |
|
// finally, return the `result` |
|
'return result' |
|
); |
|
|
|
/** |
|
* Reusable iterator options shared by `forEach`, `forIn`, and `forOwn`. |
|
*/ |
|
var forEachIteratorOptions = { |
|
'args': 'collection, callback, thisArg', |
|
'top': 'callback = createCallback(callback, thisArg)', |
|
'arrayLoop': 'if (callback(value, index, collection) === false) return result', |
|
'objectLoop': 'if (callback(value, index, collection) === false) return result' |
|
}; |
|
|
|
/** Reusable iterator options for `defaults`, and `extend` */ |
|
var extendIteratorOptions = { |
|
'useHas': false, |
|
'args': 'object', |
|
'top': |
|
'for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) {\n' + |
|
' if (iteratee = arguments[argsIndex]) {', |
|
'objectLoop': 'result[index] = value', |
|
'bottom': ' }\n}' |
|
}; |
|
|
|
/** Reusable iterator options for `forIn` and `forOwn` */ |
|
var forOwnIteratorOptions = { |
|
'arrayLoop': null |
|
}; |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Creates a function optimized to search large arrays for a given `value`, |
|
* starting at `fromIndex`, using strict equality for comparisons, i.e. `===`. |
|
* |
|
* @private |
|
* @param {Array} array The array to search. |
|
* @param {Mixed} value The value to search for. |
|
* @param {Number} [fromIndex=0] The index to search from. |
|
* @param {Number} [largeSize=30] The length at which an array is considered large. |
|
* @returns {Boolean} Returns `true` if `value` is found, else `false`. |
|
*/ |
|
function cachedContains(array, fromIndex, largeSize) { |
|
fromIndex || (fromIndex = 0); |
|
|
|
var length = array.length, |
|
isLarge = (length - fromIndex) >= (largeSize || largeArraySize); |
|
|
|
if (isLarge) { |
|
var cache = {}, |
|
index = fromIndex - 1; |
|
|
|
while (++index < length) { |
|
// manually coerce `value` to a string because `hasOwnProperty`, in some |
|
// older versions of Firefox, coerces objects incorrectly |
|
var key = array[index] + ''; |
|
(hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = [])).push(array[index]); |
|
} |
|
} |
|
return function(value) { |
|
if (isLarge) { |
|
var key = value + ''; |
|
return hasOwnProperty.call(cache, key) && indexOf(cache[key], value) > -1; |
|
} |
|
return indexOf(array, value, fromIndex) > -1; |
|
} |
|
} |
|
|
|
/** |
|
* Used by `_.max` and `_.min` as the default `callback` when a given |
|
* `collection` is a string value. |
|
* |
|
* @private |
|
* @param {String} value The character to inspect. |
|
* @returns {Number} Returns the code unit of given character. |
|
*/ |
|
function charAtCallback(value) { |
|
return value.charCodeAt(0); |
|
} |
|
|
|
/** |
|
* Used by `sortBy` to compare transformed `collection` values, stable sorting |
|
* them in ascending order. |
|
* |
|
* @private |
|
* @param {Object} a The object to compare to `b`. |
|
* @param {Object} b The object to compare to `a`. |
|
* @returns {Number} Returns the sort order indicator of `1` or `-1`. |
|
*/ |
|
function compareAscending(a, b) { |
|
var ai = a.index, |
|
bi = b.index; |
|
|
|
a = a.criteria; |
|
b = b.criteria; |
|
|
|
// ensure a stable sort in V8 and other engines |
|
// http://code.google.com/p/v8/issues/detail?id=90 |
|
if (a !== b) { |
|
if (a > b || a === undefined) { |
|
return 1; |
|
} |
|
if (a < b || b === undefined) { |
|
return -1; |
|
} |
|
} |
|
return ai < bi ? -1 : 1; |
|
} |
|
|
|
/** |
|
* Creates a function that, when called, invokes `func` with the `this` |
|
* binding of `thisArg` and prepends any `partailArgs` to the arguments passed |
|
* to the bound function. |
|
* |
|
* @private |
|
* @param {Function|String} func The function to bind or the method name. |
|
* @param {Mixed} [thisArg] The `this` binding of `func`. |
|
* @param {Array} partialArgs An array of arguments to be partially applied. |
|
* @returns {Function} Returns the new bound function. |
|
*/ |
|
function createBound(func, thisArg, partialArgs) { |
|
var isFunc = isFunction(func), |
|
isPartial = !partialArgs, |
|
methodName = func; |
|
|
|
// juggle arguments |
|
if (isPartial) { |
|
partialArgs = thisArg; |
|
} |
|
|
|
function bound() { |
|
// `Function#bind` spec |
|
// http://es5.github.com/#x15.3.4.5 |
|
var args = arguments, |
|
thisBinding = isPartial ? this : thisArg; |
|
|
|
if (!isFunc) { |
|
func = thisArg[methodName]; |
|
} |
|
if (partialArgs.length) { |
|
args = args.length |
|
? partialArgs.concat(slice.call(args)) |
|
: partialArgs; |
|
} |
|
if (this instanceof bound) { |
|
// get `func` instance if `bound` is invoked in a `new` expression |
|
noop.prototype = func.prototype; |
|
thisBinding = new noop; |
|
|
|
// mimic the constructor's `return` behavior |
|
// http://es5.github.com/#x13.2.2 |
|
var result = func.apply(thisBinding, args); |
|
return isObject(result) |
|
? result |
|
: thisBinding |
|
} |
|
return func.apply(thisBinding, args); |
|
} |
|
return bound; |
|
} |
|
|
|
/** |
|
* Produces an iteration callback bound to an optional `thisArg`. If `func` is |
|
* a property name, the callback will return the property value for a given element. |
|
* |
|
* @private |
|
* @param {Function|String} [func=identity|property] The function called per |
|
* iteration or property name to query. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Function} Returns a callback function. |
|
*/ |
|
function createCallback(func, thisArg) { |
|
if (!func) { |
|
return identity; |
|
} |
|
if (typeof func != 'function') { |
|
return function(object) { |
|
return object[func]; |
|
}; |
|
} |
|
if (thisArg !== undefined) { |
|
return function(value, index, object) { |
|
return func.call(thisArg, value, index, object); |
|
}; |
|
} |
|
return func; |
|
} |
|
|
|
/** |
|
* Creates compiled iteration functions. |
|
* |
|
* @private |
|
* @param {Object} [options1, options2, ...] The compile options object(s). |
|
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop. |
|
* args - A string of comma separated arguments the iteration function will accept. |
|
* top - A string of code to execute before the iteration branches. |
|
* arrayLoop - A string of code to execute in the array loop. |
|
* objectLoop - A string of code to execute in the object loop. |
|
* bottom - A string of code to execute after the iteration branches. |
|
* |
|
* @returns {Function} Returns the compiled function. |
|
*/ |
|
function createIterator() { |
|
var data = { |
|
'arrayLoop': '', |
|
'bottom': '', |
|
'hasDontEnumBug': hasDontEnumBug, |
|
'isKeysFast': isKeysFast, |
|
'objectLoop': '', |
|
'noArgsEnum': noArgsEnum, |
|
'noCharByIndex': noCharByIndex, |
|
'shadowed': shadowed, |
|
'top': '', |
|
'useHas': true |
|
}; |
|
|
|
// merge options into a template data object |
|
for (var object, index = 0; object = arguments[index]; index++) { |
|
for (var key in object) { |
|
data[key] = object[key]; |
|
} |
|
} |
|
var args = data.args; |
|
data.firstArg = /^[^,]+/.exec(args)[0]; |
|
|
|
// create the function factory |
|
var factory = Function( |
|
'createCallback, hasOwnProperty, isArguments, isString, objectTypes, ' + |
|
'nativeKeys, propertyIsEnumerable', |
|
'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}' |
|
); |
|
// return the compiled function |
|
return factory( |
|
createCallback, hasOwnProperty, isArguments, isString, objectTypes, |
|
nativeKeys, propertyIsEnumerable |
|
); |
|
} |
|
|
|
/** |
|
* Used by `template` to escape characters for inclusion in compiled |
|
* string literals. |
|
* |
|
* @private |
|
* @param {String} match The matched character to escape. |
|
* @returns {String} Returns the escaped character. |
|
*/ |
|
function escapeStringChar(match) { |
|
return '\\' + stringEscapes[match]; |
|
} |
|
|
|
/** |
|
* Used by `escape` to convert characters to HTML entities. |
|
* |
|
* @private |
|
* @param {String} match The matched character to escape. |
|
* @returns {String} Returns the escaped character. |
|
*/ |
|
function escapeHtmlChar(match) { |
|
return htmlEscapes[match]; |
|
} |
|
|
|
/** |
|
* A no-operation function. |
|
* |
|
* @private |
|
*/ |
|
function noop() { |
|
// no operation performed |
|
} |
|
|
|
/** |
|
* Used by `unescape` to convert HTML entities to characters. |
|
* |
|
* @private |
|
* @param {String} match The matched character to unescape. |
|
* @returns {String} Returns the unescaped character. |
|
*/ |
|
function unescapeHtmlChar(match) { |
|
return htmlUnescapes[match]; |
|
} |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Checks if `value` is an `arguments` object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is an `arguments` object, else `false`. |
|
* @example |
|
* |
|
* (function() { return _.isArguments(arguments); })(1, 2, 3); |
|
* // => true |
|
* |
|
* _.isArguments([1, 2, 3]); |
|
* // => false |
|
*/ |
|
function isArguments(value) { |
|
return toString.call(value) == argsClass; |
|
} |
|
// fallback for browsers that can't detect `arguments` objects by [[Class]] |
|
if (noArgsClass) { |
|
isArguments = function(value) { |
|
return value ? hasOwnProperty.call(value, 'callee') : false; |
|
}; |
|
} |
|
|
|
/** |
|
* Iterates over `object`'s own and inherited enumerable properties, executing |
|
* the `callback` for each property. The `callback` is bound to `thisArg` and |
|
* invoked with three arguments; (value, key, object). Callbacks may exit iteration |
|
* early by explicitly returning `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} callback The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function Dog(name) { |
|
* this.name = name; |
|
* } |
|
* |
|
* Dog.prototype.bark = function() { |
|
* alert('Woof, woof!'); |
|
* }; |
|
* |
|
* _.forIn(new Dog('Dagny'), function(value, key) { |
|
* alert(key); |
|
* }); |
|
* // => alerts 'name' and 'bark' (order is not guaranteed) |
|
*/ |
|
var forIn = createIterator(forEachIteratorOptions, forOwnIteratorOptions, { |
|
'useHas': false |
|
}); |
|
|
|
/** |
|
* Iterates over `object`'s own enumerable properties, executing the `callback` |
|
* for each property. The `callback` is bound to `thisArg` and invoked with three |
|
* arguments; (value, key, object). Callbacks may exit iteration early by explicitly |
|
* returning `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} callback The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { |
|
* alert(key); |
|
* }); |
|
* // => alerts '0', '1', and 'length' (order is not guaranteed) |
|
*/ |
|
var forOwn = createIterator(forEachIteratorOptions, forOwnIteratorOptions); |
|
|
|
/** |
|
* A fallback implementation of `isPlainObject` that checks if a given `value` |
|
* is an object created by the `Object` constructor, assuming objects created |
|
* by the `Object` constructor have no inherited enumerable properties and that |
|
* there are no `Object.prototype` extensions. |
|
* |
|
* @private |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. |
|
*/ |
|
function shimIsPlainObject(value) { |
|
// avoid non-objects and false positives for `arguments` objects |
|
var result = false; |
|
if (!(value && typeof value == 'object') || isArguments(value)) { |
|
return result; |
|
} |
|
// IE < 9 presents DOM nodes as `Object` objects except they have `toString` |
|
// methods that are `typeof` "string" and still can coerce nodes to strings. |
|
// Also check that the constructor is `Object` (i.e. `Object instanceof Object`) |
|
var ctor = value.constructor; |
|
if ((!noNodeClass || !(typeof value.toString != 'function' && typeof (value + '') == 'string')) && |
|
(!isFunction(ctor) || ctor instanceof ctor)) { |
|
// IE < 9 iterates inherited properties before own properties. If the first |
|
// iterated property is an object's own property then there are no inherited |
|
// enumerable properties. |
|
if (iteratesOwnLast) { |
|
forIn(value, function(value, key, object) { |
|
result = !hasOwnProperty.call(object, key); |
|
return false; |
|
}); |
|
return result === false; |
|
} |
|
// In most environments an object's own properties are iterated before |
|
// its inherited properties. If the last iterated property is an object's |
|
// own property then there are no inherited enumerable properties. |
|
forIn(value, function(value, key) { |
|
result = key; |
|
}); |
|
return result === false || hasOwnProperty.call(value, result); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* A fallback implementation of `Object.keys` that produces an array of the |
|
* given object's own enumerable property names. |
|
* |
|
* @private |
|
* @param {Object} object The object to inspect. |
|
* @returns {Array} Returns a new array of property names. |
|
*/ |
|
function shimKeys(object) { |
|
var result = []; |
|
forOwn(object, function(value, key) { |
|
result.push(key); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Used to convert characters to HTML entities: |
|
* |
|
* Though the `>` character is escaped for symmetry, characters like `>` and `/` |
|
* don't require escaping in HTML and have no special meaning unless they're part |
|
* of a tag or an unquoted attribute value. |
|
* http://mathiasbynens.be/notes/ambiguous-ampersands (under "semi-related fun fact") |
|
*/ |
|
var htmlEscapes = { |
|
'&': '&', |
|
'<': '<', |
|
'>': '>', |
|
'"': '"', |
|
"'": ''' |
|
}; |
|
|
|
/** Used to convert HTML entities to characters */ |
|
var htmlUnescapes = invert(htmlEscapes); |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Creates a clone of `value`. If `deep` is `true`, all nested objects will |
|
* also be cloned otherwise they will be assigned by reference. Functions, DOM |
|
* nodes, `arguments` objects, and objects created by constructors other than |
|
* `Object` are **not** cloned. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to clone. |
|
* @param {Boolean} deep A flag to indicate a deep clone. |
|
* @param- {Object} [guard] Internally used to allow this method to work with |
|
* others like `_.map` without using their callback `index` argument for `deep`. |
|
* @param- {Array} [stackA=[]] Internally used to track traversed source objects. |
|
* @param- {Array} [stackB=[]] Internally used to associate clones with their |
|
* source counterparts. |
|
* @returns {Mixed} Returns the cloned `value`. |
|
* @example |
|
* |
|
* var stooges = [ |
|
* { 'name': 'moe', 'age': 40 }, |
|
* { 'name': 'larry', 'age': 50 }, |
|
* { 'name': 'curly', 'age': 60 } |
|
* ]; |
|
* |
|
* _.clone({ 'name': 'moe' }); |
|
* // => { 'name': 'moe' } |
|
* |
|
* var shallow = _.clone(stooges); |
|
* shallow[0] === stooges[0]; |
|
* // => true |
|
* |
|
* var deep = _.clone(stooges, true); |
|
* shallow[0] === stooges[0]; |
|
* // => false |
|
*/ |
|
function clone(value, deep, guard, stackA, stackB) { |
|
if (value == null) { |
|
return value; |
|
} |
|
if (guard) { |
|
deep = false; |
|
} |
|
// inspect [[Class]] |
|
var isObj = isObject(value); |
|
if (isObj) { |
|
// don't clone `arguments` objects, functions, or non-object Objects |
|
var className = toString.call(value); |
|
if (!cloneableClasses[className] || (noArgsClass && isArguments(value))) { |
|
return value; |
|
} |
|
var isArr = className == arrayClass; |
|
isObj = isArr || (className == objectClass ? isPlainObject(value) : isObj); |
|
} |
|
// shallow clone |
|
if (!isObj || !deep) { |
|
// don't clone functions |
|
return isObj |
|
? (isArr ? slice.call(value) : extend({}, value)) |
|
: value; |
|
} |
|
|
|
var ctor = value.constructor; |
|
switch (className) { |
|
case boolClass: |
|
case dateClass: |
|
return new ctor(+value); |
|
|
|
case numberClass: |
|
case stringClass: |
|
return new ctor(value); |
|
|
|
case regexpClass: |
|
return ctor(value.source, reFlags.exec(value)); |
|
} |
|
// check for circular references and return corresponding clone |
|
stackA || (stackA = []); |
|
stackB || (stackB = []); |
|
|
|
var length = stackA.length; |
|
while (length--) { |
|
if (stackA[length] == value) { |
|
return stackB[length]; |
|
} |
|
} |
|
// init cloned object |
|
var result = isArr ? ctor(value.length) : {}; |
|
|
|
// add the source value to the stack of traversed objects |
|
// and associate it with its clone |
|
stackA.push(value); |
|
stackB.push(result); |
|
|
|
// recursively populate clone (susceptible to call stack limits) |
|
(isArr ? forEach : forOwn)(value, function(objValue, key) { |
|
result[key] = clone(objValue, deep, null, stackA, stackB); |
|
}); |
|
|
|
return result; |
|
} |
|
|
|
/** |
|
* Assigns enumerable properties of the default object(s) to the `destination` |
|
* object for all `destination` properties that resolve to `null`/`undefined`. |
|
* Once a property is set, additional defaults of the same property will be |
|
* ignored. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The destination object. |
|
* @param {Object} [default1, default2, ...] The default objects. |
|
* @returns {Object} Returns the destination object. |
|
* @example |
|
* |
|
* var iceCream = { 'flavor': 'chocolate' }; |
|
* _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); |
|
* // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } |
|
*/ |
|
var defaults = createIterator(extendIteratorOptions, { |
|
'objectLoop': 'if (result[index] == null) ' + extendIteratorOptions.objectLoop |
|
}); |
|
|
|
/** |
|
* Assigns enumerable properties of the source object(s) to the `destination` |
|
* object. Subsequent sources will overwrite propery assignments of previous |
|
* sources. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The destination object. |
|
* @param {Object} [source1, source2, ...] The source objects. |
|
* @returns {Object} Returns the destination object. |
|
* @example |
|
* |
|
* _.extend({ 'name': 'moe' }, { 'age': 40 }); |
|
* // => { 'name': 'moe', 'age': 40 } |
|
*/ |
|
var extend = createIterator(extendIteratorOptions); |
|
|
|
/** |
|
* Creates a sorted array of all enumerable properties, own and inherited, |
|
* of `object` that have function values. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias methods |
|
* @category Objects |
|
* @param {Object} object The object to inspect. |
|
* @returns {Array} Returns a new array of property names that have function values. |
|
* @example |
|
* |
|
* _.functions(_); |
|
* // => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] |
|
*/ |
|
function functions(object) { |
|
var result = []; |
|
forIn(object, function(value, key) { |
|
if (isFunction(value)) { |
|
result.push(key); |
|
} |
|
}); |
|
return result.sort(); |
|
} |
|
|
|
/** |
|
* Checks if the specified object `property` exists and is a direct property, |
|
* instead of an inherited property. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The object to check. |
|
* @param {String} property The property to check for. |
|
* @returns {Boolean} Returns `true` if key is a direct property, else `false`. |
|
* @example |
|
* |
|
* _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); |
|
* // => true |
|
*/ |
|
function has(object, property) { |
|
return object ? hasOwnProperty.call(object, property) : false; |
|
} |
|
|
|
/** |
|
* Creates an object composed of the inverted keys and values of the given `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The object to invert. |
|
* @returns {Object} Returns the created inverted object. |
|
* @example |
|
* |
|
* _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); |
|
* // => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) |
|
*/ |
|
function invert(object) { |
|
var result = {}; |
|
forOwn(object, function(value, key) { |
|
result[value] = key; |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Checks if `value` is an array. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is an array, else `false`. |
|
* @example |
|
* |
|
* (function() { return _.isArray(arguments); })(); |
|
* // => false |
|
* |
|
* _.isArray([1, 2, 3]); |
|
* // => true |
|
*/ |
|
var isArray = nativeIsArray || function(value) { |
|
return toString.call(value) == arrayClass; |
|
}; |
|
|
|
/** |
|
* Checks if `value` is a boolean (`true` or `false`) value. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a boolean value, else `false`. |
|
* @example |
|
* |
|
* _.isBoolean(null); |
|
* // => false |
|
*/ |
|
function isBoolean(value) { |
|
return value === true || value === false || toString.call(value) == boolClass; |
|
} |
|
|
|
/** |
|
* Checks if `value` is a date. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a date, else `false`. |
|
* @example |
|
* |
|
* _.isDate(new Date); |
|
* // => true |
|
*/ |
|
function isDate(value) { |
|
return toString.call(value) == dateClass; |
|
} |
|
|
|
/** |
|
* Checks if `value` is a DOM element. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a DOM element, else `false`. |
|
* @example |
|
* |
|
* _.isElement(document.body); |
|
* // => true |
|
*/ |
|
function isElement(value) { |
|
return value ? value.nodeType === 1 : false; |
|
} |
|
|
|
/** |
|
* Checks if `value` is empty. Arrays, strings, or `arguments` objects with a |
|
* length of `0` and objects with no own enumerable properties are considered |
|
* "empty". |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Array|Object|String} value The value to inspect. |
|
* @returns {Boolean} Returns `true` if the `value` is empty, else `false`. |
|
* @example |
|
* |
|
* _.isEmpty([1, 2, 3]); |
|
* // => false |
|
* |
|
* _.isEmpty({}); |
|
* // => true |
|
* |
|
* _.isEmpty(''); |
|
* // => true |
|
*/ |
|
function isEmpty(value) { |
|
var result = true; |
|
if (!value) { |
|
return result; |
|
} |
|
var className = toString.call(value), |
|
length = value.length; |
|
|
|
if ((className == arrayClass || className == stringClass || |
|
className == argsClass || (noArgsClass && isArguments(value))) || |
|
(className == objectClass && typeof length == 'number' && isFunction(value.splice))) { |
|
return !length; |
|
} |
|
forOwn(value, function() { |
|
return (result = false); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Performs a deep comparison between two values to determine if they are |
|
* equivalent to each other. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} a The value to compare. |
|
* @param {Mixed} b The other value to compare. |
|
* @param- {Object} [stackA=[]] Internally used track traversed `a` objects. |
|
* @param- {Object} [stackB=[]] Internally used track traversed `b` objects. |
|
* @returns {Boolean} Returns `true` if the values are equvalent, else `false`. |
|
* @example |
|
* |
|
* var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; |
|
* var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; |
|
* |
|
* moe == clone; |
|
* // => false |
|
* |
|
* _.isEqual(moe, clone); |
|
* // => true |
|
*/ |
|
function isEqual(a, b, stackA, stackB) { |
|
// exit early for identical values |
|
if (a === b) { |
|
// treat `+0` vs. `-0` as not equal |
|
return a !== 0 || (1 / a == 1 / b); |
|
} |
|
// a strict comparison is necessary because `null == undefined` |
|
if (a == null || b == null) { |
|
return a === b; |
|
} |
|
// compare [[Class]] names |
|
var className = toString.call(a); |
|
if (className != toString.call(b)) { |
|
return false; |
|
} |
|
switch (className) { |
|
case boolClass: |
|
case dateClass: |
|
// coerce dates and booleans to numbers, dates to milliseconds and booleans |
|
// to `1` or `0`, treating invalid dates coerced to `NaN` as not equal |
|
return +a == +b; |
|
|
|
case numberClass: |
|
// treat `NaN` vs. `NaN` as equal |
|
return a != +a |
|
? b != +b |
|
// but treat `+0` vs. `-0` as not equal |
|
: (a == 0 ? (1 / a == 1 / b) : a == +b); |
|
|
|
case regexpClass: |
|
case stringClass: |
|
// coerce regexes to strings (http://es5.github.com/#x15.10.6.4) |
|
// treat string primitives and their corresponding object instances as equal |
|
return a == b + ''; |
|
} |
|
// exit early, in older browsers, if `a` is array-like but not `b` |
|
var isArr = className == arrayClass || className == argsClass; |
|
if (noArgsClass && !isArr && (isArr = isArguments(a)) && !isArguments(b)) { |
|
return false; |
|
} |
|
if (!isArr) { |
|
// unwrap any `lodash` wrapped values |
|
if (a.__wrapped__ || b.__wrapped__) { |
|
return isEqual(a.__wrapped__ || a, b.__wrapped__ || b); |
|
} |
|
// exit for functions and DOM nodes |
|
if (className != objectClass || (noNodeClass && ( |
|
(typeof a.toString != 'function' && typeof (a + '') == 'string') || |
|
(typeof b.toString != 'function' && typeof (b + '') == 'string')))) { |
|
return false; |
|
} |
|
var ctorA = a.constructor, |
|
ctorB = b.constructor; |
|
|
|
// non `Object` object instances with different constructors are not equal |
|
if (ctorA != ctorB && !( |
|
isFunction(ctorA) && ctorA instanceof ctorA && |
|
isFunction(ctorB) && ctorB instanceof ctorB |
|
)) { |
|
return false; |
|
} |
|
} |
|
// assume cyclic structures are equal |
|
// the algorithm for detecting cyclic structures is adapted from ES 5.1 |
|
// section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3) |
|
stackA || (stackA = []); |
|
stackB || (stackB = []); |
|
|
|
var length = stackA.length; |
|
while (length--) { |
|
if (stackA[length] == a) { |
|
return stackB[length] == b; |
|
} |
|
} |
|
|
|
var index = -1, |
|
result = true, |
|
size = 0; |
|
|
|
// add `a` and `b` to the stack of traversed objects |
|
stackA.push(a); |
|
stackB.push(b); |
|
|
|
// recursively compare objects and arrays (susceptible to call stack limits) |
|
if (isArr) { |
|
// compare lengths to determine if a deep comparison is necessary |
|
size = a.length; |
|
result = size == b.length; |
|
|
|
if (result) { |
|
// deep compare the contents, ignoring non-numeric properties |
|
while (size--) { |
|
if (!(result = isEqual(a[size], b[size], stackA, stackB))) { |
|
break; |
|
} |
|
} |
|
} |
|
return result; |
|
} |
|
// deep compare objects |
|
for (var key in a) { |
|
if (hasOwnProperty.call(a, key)) { |
|
// count the number of properties. |
|
size++; |
|
// deep compare each property value. |
|
if (!(hasOwnProperty.call(b, key) && isEqual(a[key], b[key], stackA, stackB))) { |
|
return false; |
|
} |
|
} |
|
} |
|
// ensure both objects have the same number of properties |
|
for (key in b) { |
|
// The JS engine in Adobe products, like InDesign, has a bug that causes |
|
// `!size--` to throw an error so it must be wrapped in parentheses. |
|
// https://github.com/documentcloud/underscore/issues/355 |
|
if (hasOwnProperty.call(b, key) && !(size--)) { |
|
// `size` will be `-1` if `b` has more properties than `a` |
|
return false; |
|
} |
|
} |
|
// handle JScript [[DontEnum]] bug |
|
if (hasDontEnumBug) { |
|
while (++index < 7) { |
|
key = shadowed[index]; |
|
if (hasOwnProperty.call(a, key) && |
|
!(hasOwnProperty.call(b, key) && isEqual(a[key], b[key], stackA, stackB))) { |
|
return false; |
|
} |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
/** |
|
* Checks if `value` is, or can be coerced to, a finite number. |
|
* |
|
* Note: This is not the same as native `isFinite`, which will return true for |
|
* booleans and empty strings. See http://es5.github.com/#x15.1.2.5. |
|
* |
|
* @deprecated |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a finite number, else `false`. |
|
* @example |
|
* |
|
* _.isFinite(-101); |
|
* // => true |
|
* |
|
* _.isFinite('10'); |
|
* // => true |
|
* |
|
* _.isFinite(true); |
|
* // => false |
|
* |
|
* _.isFinite(''); |
|
* // => false |
|
* |
|
* _.isFinite(Infinity); |
|
* // => false |
|
*/ |
|
function isFinite(value) { |
|
return nativeIsFinite(value) && !nativeIsNaN(parseFloat(value)); |
|
} |
|
|
|
/** |
|
* Checks if `value` is a function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a function, else `false`. |
|
* @example |
|
* |
|
* _.isFunction(_); |
|
* // => true |
|
*/ |
|
function isFunction(value) { |
|
return typeof value == 'function'; |
|
} |
|
// fallback for older versions of Chrome and Safari |
|
if (isFunction(/x/)) { |
|
isFunction = function(value) { |
|
return toString.call(value) == funcClass; |
|
}; |
|
} |
|
|
|
/** |
|
* Checks if `value` is the language type of Object. |
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is an object, else `false`. |
|
* @example |
|
* |
|
* _.isObject({}); |
|
* // => true |
|
* |
|
* _.isObject([1, 2, 3]); |
|
* // => true |
|
* |
|
* _.isObject(1); |
|
* // => false |
|
*/ |
|
function isObject(value) { |
|
// check if the value is the ECMAScript language type of Object |
|
// http://es5.github.com/#x8 |
|
// and avoid a V8 bug |
|
// http://code.google.com/p/v8/issues/detail?id=2291 |
|
return value ? objectTypes[typeof value] : false; |
|
} |
|
|
|
/** |
|
* Checks if `value` is `NaN`. |
|
* |
|
* Note: This is not the same as native `isNaN`, which will return true for |
|
* `undefined` and other values. See http://es5.github.com/#x15.1.2.4. |
|
* |
|
* @deprecated |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is `NaN`, else `false`. |
|
* @example |
|
* |
|
* _.isNaN(NaN); |
|
* // => true |
|
* |
|
* _.isNaN(new Number(NaN)); |
|
* // => true |
|
* |
|
* isNaN(undefined); |
|
* // => true |
|
* |
|
* _.isNaN(undefined); |
|
* // => false |
|
*/ |
|
function isNaN(value) { |
|
// `NaN` as a primitive is the only value that is not equal to itself |
|
// (perform the [[Class]] check first to avoid errors with some host objects in IE) |
|
return toString.call(value) == numberClass && value != +value |
|
} |
|
|
|
/** |
|
* Checks if `value` is `null`. |
|
* |
|
* @deprecated |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is `null`, else `false`. |
|
* @example |
|
* |
|
* _.isNull(null); |
|
* // => true |
|
* |
|
* _.isNull(undefined); |
|
* // => false |
|
*/ |
|
function isNull(value) { |
|
return value === null; |
|
} |
|
|
|
/** |
|
* Checks if `value` is a number. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a number, else `false`. |
|
* @example |
|
* |
|
* _.isNumber(8.4 * 5); |
|
* // => true |
|
*/ |
|
function isNumber(value) { |
|
return toString.call(value) == numberClass; |
|
} |
|
|
|
/** |
|
* Checks if a given `value` is an object created by the `Object` constructor. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if `value` is a plain object, else `false`. |
|
* @example |
|
* |
|
* function Stooge(name, age) { |
|
* this.name = name; |
|
* this.age = age; |
|
* } |
|
* |
|
* _.isPlainObject(new Stooge('moe', 40)); |
|
* // => false |
|
* |
|
* _.isPlainObject([1, 2, 3]); |
|
* // => false |
|
* |
|
* _.isPlainObject({ 'name': 'moe', 'age': 40 }); |
|
* // => true |
|
*/ |
|
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) { |
|
if (!(value && typeof value == 'object')) { |
|
return false; |
|
} |
|
var valueOf = value.valueOf, |
|
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); |
|
|
|
return objProto |
|
? value == objProto || (getPrototypeOf(value) == objProto && !isArguments(value)) |
|
: shimIsPlainObject(value); |
|
}; |
|
|
|
/** |
|
* Checks if `value` is a regular expression. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a regular expression, else `false`. |
|
* @example |
|
* |
|
* _.isRegExp(/moe/); |
|
* // => true |
|
*/ |
|
function isRegExp(value) { |
|
return toString.call(value) == regexpClass; |
|
} |
|
|
|
/** |
|
* Checks if `value` is a string. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is a string, else `false`. |
|
* @example |
|
* |
|
* _.isString('moe'); |
|
* // => true |
|
*/ |
|
function isString(value) { |
|
return toString.call(value) == stringClass; |
|
} |
|
|
|
/** |
|
* Checks if `value` is `undefined`. |
|
* |
|
* @deprecated |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Mixed} value The value to check. |
|
* @returns {Boolean} Returns `true` if the `value` is `undefined`, else `false`. |
|
* @example |
|
* |
|
* _.isUndefined(void 0); |
|
* // => true |
|
*/ |
|
function isUndefined(value) { |
|
return value === undefined; |
|
} |
|
|
|
/** |
|
* Creates an array composed of the own enumerable property names of `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The object to inspect. |
|
* @returns {Array} Returns a new array of property names. |
|
* @example |
|
* |
|
* _.keys({ 'one': 1, 'two': 2, 'three': 3 }); |
|
* // => ['one', 'two', 'three'] (order is not guaranteed) |
|
*/ |
|
var keys = !nativeKeys ? shimKeys : function(object) { |
|
// avoid iterating over the `prototype` property |
|
return typeof object == 'function' && propertyIsEnumerable.call(object, 'prototype') |
|
? shimKeys(object) |
|
: (isObject(object) ? nativeKeys(object) : []); |
|
}; |
|
|
|
/** |
|
* Merges enumerable properties of the source object(s) into the `destination` |
|
* object. Subsequent sources will overwrite propery assignments of previous |
|
* sources. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The destination object. |
|
* @param {Object} [source1, source2, ...] The source objects. |
|
* @param- {Object} [indicator] Internally used to indicate that the `stack` |
|
* argument is an array of traversed objects instead of another source object. |
|
* @param- {Array} [stackA=[]] Internally used to track traversed source objects. |
|
* @param- {Array} [stackB=[]] Internally used to associate values with their |
|
* source counterparts. |
|
* @returns {Object} Returns the destination object. |
|
* @example |
|
* |
|
* var stooges = [ |
|
* { 'name': 'moe' }, |
|
* { 'name': 'larry' } |
|
* ]; |
|
* |
|
* var ages = [ |
|
* { 'age': 40 }, |
|
* { 'age': 50 } |
|
* ]; |
|
* |
|
* _.merge(stooges, ages); |
|
* // => [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] |
|
*/ |
|
function merge(object, source, indicator) { |
|
var args = arguments, |
|
index = 0, |
|
length = 2, |
|
stackA = args[3], |
|
stackB = args[4]; |
|
|
|
if (indicator !== objectRef) { |
|
stackA = []; |
|
stackB = []; |
|
length = args.length; |
|
} |
|
while (++index < length) { |
|
forOwn(args[index], function(source, key) { |
|
var found, isArr, value; |
|
if (source && ((isArr = isArray(source)) || isPlainObject(source))) { |
|
// avoid merging previously merged cyclic sources |
|
var stackLength = stackA.length; |
|
while (stackLength--) { |
|
found = stackA[stackLength] == source; |
|
if (found) { |
|
break; |
|
} |
|
} |
|
if (found) { |
|
object[key] = stackB[stackLength]; |
|
} |
|
else { |
|
// add `source` and associated `value` to the stack of traversed objects |
|
stackA.push(source); |
|
stackB.push(value = (value = object[key], isArr) |
|
? (isArray(value) ? value : []) |
|
: (isPlainObject(value) ? value : {}) |
|
); |
|
// recursively merge objects and arrays (susceptible to call stack limits) |
|
object[key] = merge(value, source, objectRef, stackA, stackB); |
|
} |
|
} else if (source != null) { |
|
object[key] = source; |
|
} |
|
}); |
|
} |
|
return object; |
|
} |
|
|
|
/** |
|
* Creates a shallow clone of `object` excluding the specified properties. |
|
* Property names may be specified as individual arguments or as arrays of |
|
* property names. If `callback` is passed, it will be executed for each property |
|
* in the `object`, omitting the properties `callback` returns truthy for. The |
|
* `callback` is bound to `thisArg` and invoked with three arguments; (value, key, object). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The source object. |
|
* @param {Function|String} callback|[prop1, prop2, ...] The properties to omit |
|
* or the function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Object} Returns an object without the omitted properties. |
|
* @example |
|
* |
|
* _.omit({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); |
|
* // => { 'name': 'moe', 'age': 40 } |
|
* |
|
* _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) { |
|
* return key.charAt(0) == '_'; |
|
* }); |
|
* // => { 'name': 'moe' } |
|
*/ |
|
function omit(object, callback, thisArg) { |
|
var isFunc = typeof callback == 'function', |
|
result = {}; |
|
|
|
if (isFunc) { |
|
callback = createCallback(callback, thisArg); |
|
} else { |
|
var props = concat.apply(arrayRef, arguments); |
|
} |
|
forIn(object, function(value, key, object) { |
|
if (isFunc |
|
? !callback(value, key, object) |
|
: indexOf(props, key, 1) < 0 |
|
) { |
|
result[key] = value; |
|
} |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a two dimensional array of the given object's key-value pairs, |
|
* i.e. `[[key1, value1], [key2, value2]]`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The object to inspect. |
|
* @returns {Array} Returns new array of key-value pairs. |
|
* @example |
|
* |
|
* _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); |
|
* // => [['moe', 30], ['larry', 40], ['curly', 50]] (order is not guaranteed) |
|
*/ |
|
function pairs(object) { |
|
var result = []; |
|
forOwn(object, function(value, key) { |
|
result.push([key, value]); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a shallow clone of `object` composed of the specified properties. |
|
* Property names may be specified as individual arguments or as arrays of |
|
* property names. If `callback` is passed, it will be executed for each property |
|
* in the `object`, picking the properties `callback` returns truthy for. The |
|
* `callback` is bound to `thisArg` and invoked with three arguments; (value, key, object). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The source object. |
|
* @param {Function|String} callback|[prop1, prop2, ...] The properties to pick |
|
* or the function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Object} Returns an object composed of the picked properties. |
|
* @example |
|
* |
|
* _.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); |
|
* // => { 'name': 'moe', 'age': 40 } |
|
* |
|
* _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) { |
|
* return key.charAt(0) != '_'; |
|
* }); |
|
* // => { 'name': 'moe' } |
|
*/ |
|
function pick(object, callback, thisArg) { |
|
var result = {}; |
|
if (typeof callback != 'function') { |
|
var index = 0, |
|
props = concat.apply(arrayRef, arguments), |
|
length = props.length; |
|
|
|
while (++index < length) { |
|
var key = props[index]; |
|
if (key in object) { |
|
result[key] = object[key]; |
|
} |
|
} |
|
} else { |
|
callback = createCallback(callback, thisArg); |
|
forIn(object, function(value, key, object) { |
|
if (callback(value, key, object)) { |
|
result[key] = value; |
|
} |
|
}); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an array composed of the own enumerable property values of `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Objects |
|
* @param {Object} object The object to inspect. |
|
* @returns {Array} Returns a new array of property values. |
|
* @example |
|
* |
|
* _.values({ 'one': 1, 'two': 2, 'three': 3 }); |
|
* // => [1, 2, 3] |
|
*/ |
|
function values(object) { |
|
var result = []; |
|
forOwn(object, function(value) { |
|
result.push(value); |
|
}); |
|
return result; |
|
} |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Checks if a given `target` element is present in a `collection` using strict |
|
* equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used |
|
* as the offset from the end of the collection. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias include |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Mixed} target The value to check for. |
|
* @param {Number} [fromIndex=0] The index to search from. |
|
* @returns {Boolean} Returns `true` if the `target` element is found, else `false`. |
|
* @example |
|
* |
|
* _.contains([1, 2, 3], 1); |
|
* // => true |
|
* |
|
* _.contains([1, 2, 3], 1, 2); |
|
* // => false |
|
* |
|
* _.contains({ 'name': 'moe', 'age': 40 }, 'moe'); |
|
* // => true |
|
* |
|
* _.contains('curly', 'ur'); |
|
* // => true |
|
*/ |
|
function contains(collection, target, fromIndex) { |
|
var index = -1, |
|
length = collection ? collection.length : 0; |
|
|
|
fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) || 0; |
|
if (typeof length == 'number') { |
|
return (isString(collection) |
|
? collection.indexOf(target, fromIndex) |
|
: indexOf(collection, target, fromIndex) |
|
) > -1; |
|
} |
|
return some(collection, function(value) { |
|
return ++index >= fromIndex && value === target; |
|
}); |
|
} |
|
|
|
/** |
|
* Creates an object composed of keys returned from running each element of |
|
* `collection` through a `callback`. The corresponding value of each key is |
|
* the number of times the key was returned by `callback`. The `callback` is |
|
* bound to `thisArg` and invoked with three arguments; (value, index|key, collection). |
|
* The `callback` argument may also be the name of a property to count by (e.g. 'length'). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function|String} callback|property The function called per iteration |
|
* or property name to count by. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Object} Returns the composed aggregate object. |
|
* @example |
|
* |
|
* _.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); |
|
* // => { '4': 1, '6': 2 } |
|
* |
|
* _.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); |
|
* // => { '4': 1, '6': 2 } |
|
* |
|
* _.countBy(['one', 'two', 'three'], 'length'); |
|
* // => { '3': 2, '5': 1 } |
|
*/ |
|
function countBy(collection, callback, thisArg) { |
|
var result = {}; |
|
callback = createCallback(callback, thisArg); |
|
forEach(collection, function(value, key, collection) { |
|
key = callback(value, key, collection); |
|
(hasOwnProperty.call(result, key) ? result[key]++ : result[key] = 1); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Checks if the `callback` returns a truthy value for **all** elements of a |
|
* `collection`. The `callback` is bound to `thisArg` and invoked with three |
|
* arguments; (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias all |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} [callback=identity] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Boolean} Returns `true` if all elements pass the callback check, |
|
* else `false`. |
|
* @example |
|
* |
|
* _.every([true, 1, null, 'yes'], Boolean); |
|
* // => false |
|
*/ |
|
function every(collection, callback, thisArg) { |
|
var result = true; |
|
callback = createCallback(callback, thisArg); |
|
|
|
if (isArray(collection)) { |
|
var index = -1, |
|
length = collection.length; |
|
|
|
while (++index < length) { |
|
if (!(result = !!callback(collection[index], index, collection))) { |
|
break; |
|
} |
|
} |
|
} else { |
|
forEach(collection, function(value, index, collection) { |
|
return (result = !!callback(value, index, collection)); |
|
}); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Examines each element in a `collection`, returning an array of all elements |
|
* the `callback` returns truthy for. The `callback` is bound to `thisArg` and |
|
* invoked with three arguments; (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias select |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} [callback=identity] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Array} Returns a new array of elements that passed the callback check. |
|
* @example |
|
* |
|
* var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); |
|
* // => [2, 4, 6] |
|
*/ |
|
function filter(collection, callback, thisArg) { |
|
var result = []; |
|
callback = createCallback(callback, thisArg); |
|
forEach(collection, function(value, index, collection) { |
|
if (callback(value, index, collection)) { |
|
result.push(value); |
|
} |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Examines each element in a `collection`, returning the first one the `callback` |
|
* returns truthy for. The function returns as soon as it finds an acceptable |
|
* element, and does not iterate over the entire `collection`. The `callback` is |
|
* bound to `thisArg` and invoked with three arguments; (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias detect |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} callback The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Mixed} Returns the element that passed the callback check, |
|
* else `undefined`. |
|
* @example |
|
* |
|
* var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); |
|
* // => 2 |
|
*/ |
|
function find(collection, callback, thisArg) { |
|
var result; |
|
callback = createCallback(callback, thisArg); |
|
forEach(collection, function(value, index, collection) { |
|
if (callback(value, index, collection)) { |
|
result = value; |
|
return false; |
|
} |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Iterates over a `collection`, executing the `callback` for each element in |
|
* the `collection`. The `callback` is bound to `thisArg` and invoked with three |
|
* arguments; (value, index|key, collection). Callbacks may exit iteration early |
|
* by explicitly returning `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias each |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} callback The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Array|Object|String} Returns `collection`. |
|
* @example |
|
* |
|
* _([1, 2, 3]).forEach(alert).join(','); |
|
* // => alerts each number and returns '1,2,3' |
|
* |
|
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); |
|
* // => alerts each number (order is not guaranteed) |
|
*/ |
|
var forEach = createIterator(forEachIteratorOptions); |
|
|
|
/** |
|
* Creates an object composed of keys returned from running each element of |
|
* `collection` through a `callback`. The corresponding value of each key is an |
|
* array of elements passed to `callback` that returned the key. The `callback` |
|
* is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). |
|
* The `callback` argument may also be the name of a property to group by (e.g. 'length'). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function|String} callback|property The function called per iteration |
|
* or property name to group by. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Object} Returns the composed aggregate object. |
|
* @example |
|
* |
|
* _.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); |
|
* // => { '4': [4.2], '6': [6.1, 6.4] } |
|
* |
|
* _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); |
|
* // => { '4': [4.2], '6': [6.1, 6.4] } |
|
* |
|
* _.groupBy(['one', 'two', 'three'], 'length'); |
|
* // => { '3': ['one', 'two'], '5': ['three'] } |
|
*/ |
|
function groupBy(collection, callback, thisArg) { |
|
var result = {}; |
|
callback = createCallback(callback, thisArg); |
|
forEach(collection, function(value, key, collection) { |
|
key = callback(value, key, collection); |
|
(hasOwnProperty.call(result, key) ? result[key] : result[key] = []).push(value); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Invokes the method named by `methodName` on each element in the `collection`, |
|
* returning an array of the results of each invoked method. Additional arguments |
|
* will be passed to each invoked method. If `methodName` is a function it will |
|
* be invoked for, and `this` bound to, each element in the `collection`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function|String} methodName The name of the method to invoke or |
|
* the function invoked per iteration. |
|
* @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with. |
|
* @returns {Array} Returns a new array of the results of each invoked method. |
|
* @example |
|
* |
|
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); |
|
* // => [[1, 5, 7], [1, 2, 3]] |
|
* |
|
* _.invoke([123, 456], String.prototype.split, ''); |
|
* // => [['1', '2', '3'], ['4', '5', '6']] |
|
*/ |
|
function invoke(collection, methodName) { |
|
var args = slice.call(arguments, 2), |
|
isFunc = typeof methodName == 'function', |
|
result = []; |
|
|
|
forEach(collection, function(value) { |
|
result.push((isFunc ? methodName : value[methodName]).apply(value, args)); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an array of values by running each element in the `collection` |
|
* through a `callback`. The `callback` is bound to `thisArg` and invoked with |
|
* three arguments; (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias collect |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} [callback=identity] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Array} Returns a new array of the results of each `callback` execution. |
|
* @example |
|
* |
|
* _.map([1, 2, 3], function(num) { return num * 3; }); |
|
* // => [3, 6, 9] |
|
* |
|
* _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); |
|
* // => [3, 6, 9] (order is not guaranteed) |
|
*/ |
|
function map(collection, callback, thisArg) { |
|
var index = -1, |
|
length = collection ? collection.length : 0, |
|
result = Array(typeof length == 'number' ? length : 0); |
|
|
|
callback = createCallback(callback, thisArg); |
|
if (isArray(collection)) { |
|
while (++index < length) { |
|
result[index] = callback(collection[index], index, collection); |
|
} |
|
} else { |
|
forEach(collection, function(value, key, collection) { |
|
result[++index] = callback(value, key, collection); |
|
}); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Retrieves the maximum value of an `array`. If `callback` is passed, |
|
* it will be executed for each value in the `array` to generate the |
|
* criterion by which the value is ranked. The `callback` is bound to |
|
* `thisArg` and invoked with three arguments; (value, index, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} [callback] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Mixed} Returns the maximum value. |
|
* @example |
|
* |
|
* var stooges = [ |
|
* { 'name': 'moe', 'age': 40 }, |
|
* { 'name': 'larry', 'age': 50 }, |
|
* { 'name': 'curly', 'age': 60 } |
|
* ]; |
|
* |
|
* _.max(stooges, function(stooge) { return stooge.age; }); |
|
* // => { 'name': 'curly', 'age': 60 }; |
|
*/ |
|
function max(collection, callback, thisArg) { |
|
var computed = -Infinity, |
|
index = -1, |
|
length = collection ? collection.length : 0, |
|
result = computed; |
|
|
|
if (callback || !isArray(collection)) { |
|
callback = !callback && isString(collection) |
|
? charAtCallback |
|
: createCallback(callback, thisArg); |
|
|
|
forEach(collection, function(value, index, collection) { |
|
var current = callback(value, index, collection); |
|
if (current > computed) { |
|
computed = current; |
|
result = value; |
|
} |
|
}); |
|
} else { |
|
while (++index < length) { |
|
if (collection[index] > result) { |
|
result = collection[index]; |
|
} |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Retrieves the minimum value of an `array`. If `callback` is passed, |
|
* it will be executed for each value in the `array` to generate the |
|
* criterion by which the value is ranked. The `callback` is bound to `thisArg` |
|
* and invoked with three arguments; (value, index, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} [callback] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Mixed} Returns the minimum value. |
|
* @example |
|
* |
|
* _.min([10, 5, 100, 2, 1000]); |
|
* // => 2 |
|
*/ |
|
function min(collection, callback, thisArg) { |
|
var computed = Infinity, |
|
index = -1, |
|
length = collection ? collection.length : 0, |
|
result = computed; |
|
|
|
if (callback || !isArray(collection)) { |
|
callback = !callback && isString(collection) |
|
? charAtCallback |
|
: createCallback(callback, thisArg); |
|
|
|
forEach(collection, function(value, index, collection) { |
|
var current = callback(value, index, collection); |
|
if (current < computed) { |
|
computed = current; |
|
result = value; |
|
} |
|
}); |
|
} else { |
|
while (++index < length) { |
|
if (collection[index] < result) { |
|
result = collection[index]; |
|
} |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Retrieves the value of a specified property from all elements in |
|
* the `collection`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {String} property The property to pluck. |
|
* @returns {Array} Returns a new array of property values. |
|
* @example |
|
* |
|
* var stooges = [ |
|
* { 'name': 'moe', 'age': 40 }, |
|
* { 'name': 'larry', 'age': 50 }, |
|
* { 'name': 'curly', 'age': 60 } |
|
* ]; |
|
* |
|
* _.pluck(stooges, 'name'); |
|
* // => ['moe', 'larry', 'curly'] |
|
*/ |
|
function pluck(collection, property) { |
|
var result = []; |
|
forEach(collection, function(value) { |
|
result.push(value[property]); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Boils down a `collection` to a single value. The initial state of the |
|
* reduction is `accumulator` and each successive step of it should be returned |
|
* by the `callback`. The `callback` is bound to `thisArg` and invoked with 4 |
|
* arguments; for arrays they are (accumulator, value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias foldl, inject |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} callback The function called per iteration. |
|
* @param {Mixed} [accumulator] Initial value of the accumulator. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Mixed} Returns the accumulated value. |
|
* @example |
|
* |
|
* var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); |
|
* // => 6 |
|
*/ |
|
function reduce(collection, callback, accumulator, thisArg) { |
|
var noaccum = arguments.length < 3; |
|
callback = createCallback(callback, thisArg); |
|
forEach(collection, function(value, index, collection) { |
|
accumulator = noaccum |
|
? (noaccum = false, value) |
|
: callback(accumulator, value, index, collection) |
|
}); |
|
return accumulator; |
|
} |
|
|
|
/** |
|
* The right-associative version of `_.reduce`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias foldr |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} callback The function called per iteration. |
|
* @param {Mixed} [accumulator] Initial value of the accumulator. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Mixed} Returns the accumulated value. |
|
* @example |
|
* |
|
* var list = [[0, 1], [2, 3], [4, 5]]; |
|
* var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); |
|
* // => [4, 5, 2, 3, 0, 1] |
|
*/ |
|
function reduceRight(collection, callback, accumulator, thisArg) { |
|
var iteratee = collection, |
|
length = collection ? collection.length : 0, |
|
noaccum = arguments.length < 3; |
|
|
|
if (typeof length != 'number') { |
|
var props = keys(collection); |
|
length = props.length; |
|
} else if (noCharByIndex && isString(collection)) { |
|
iteratee = collection.split(''); |
|
} |
|
forEach(collection, function(value, index, collection) { |
|
index = props ? props[--length] : --length; |
|
accumulator = noaccum |
|
? (noaccum = false, iteratee[index]) |
|
: callback.call(thisArg, accumulator, iteratee[index], index, collection); |
|
}); |
|
return accumulator; |
|
} |
|
|
|
/** |
|
* The opposite of `_.filter`, this method returns the values of a |
|
* `collection` that `callback` does **not** return truthy for. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} [callback=identity] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Array} Returns a new array of elements that did **not** pass the |
|
* callback check. |
|
* @example |
|
* |
|
* var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); |
|
* // => [1, 3, 5] |
|
*/ |
|
function reject(collection, callback, thisArg) { |
|
callback = createCallback(callback, thisArg); |
|
return filter(collection, function(value, index, collection) { |
|
return !callback(value, index, collection); |
|
}); |
|
} |
|
|
|
/** |
|
* Creates an array of shuffled `array` values, using a version of the |
|
* Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to shuffle. |
|
* @returns {Array} Returns a new shuffled collection. |
|
* @example |
|
* |
|
* _.shuffle([1, 2, 3, 4, 5, 6]); |
|
* // => [4, 1, 6, 3, 5, 2] |
|
*/ |
|
function shuffle(collection) { |
|
var index = -1, |
|
result = Array(collection ? collection.length : 0); |
|
|
|
forEach(collection, function(value) { |
|
var rand = floor(nativeRandom() * (++index + 1)); |
|
result[index] = result[rand]; |
|
result[rand] = value; |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the size of the `collection` by returning `collection.length` for arrays |
|
* and array-like objects or the number of own enumerable properties for objects. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to inspect. |
|
* @returns {Number} Returns `collection.length` or number of own enumerable properties. |
|
* @example |
|
* |
|
* _.size([1, 2]); |
|
* // => 2 |
|
* |
|
* _.size({ 'one': 1, 'two': 2, 'three': 3 }); |
|
* // => 3 |
|
* |
|
* _.size('curly'); |
|
* // => 5 |
|
*/ |
|
function size(collection) { |
|
var length = collection ? collection.length : 0; |
|
return typeof length == 'number' ? length : keys(collection).length; |
|
} |
|
|
|
/** |
|
* Checks if the `callback` returns a truthy value for **any** element of a |
|
* `collection`. The function returns as soon as it finds passing value, and |
|
* does not iterate over the entire `collection`. The `callback` is bound to |
|
* `thisArg` and invoked with three arguments; (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias any |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function} [callback=identity] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Boolean} Returns `true` if any element passes the callback check, |
|
* else `false`. |
|
* @example |
|
* |
|
* _.some([null, 0, 'yes', false]); |
|
* // => true |
|
*/ |
|
function some(collection, callback, thisArg) { |
|
var result; |
|
callback = createCallback(callback, thisArg); |
|
|
|
if (isArray(collection)) { |
|
var index = -1, |
|
length = collection.length; |
|
|
|
while (++index < length) { |
|
if (result = callback(collection[index], index, collection)) { |
|
break; |
|
} |
|
} |
|
} else { |
|
forEach(collection, function(value, index, collection) { |
|
return !(result = callback(value, index, collection)); |
|
}); |
|
} |
|
return !!result; |
|
} |
|
|
|
/** |
|
* Creates an array, stable sorted in ascending order by the results of |
|
* running each element of `collection` through a `callback`. The `callback` |
|
* is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). |
|
* The `callback` argument may also be the name of a property to sort by (e.g. 'length'). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Function|String} callback|property The function called per iteration |
|
* or property name to sort by. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Array} Returns a new array of sorted elements. |
|
* @example |
|
* |
|
* _.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); |
|
* // => [3, 1, 2] |
|
* |
|
* _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); |
|
* // => [3, 1, 2] |
|
* |
|
* _.sortBy(['larry', 'brendan', 'moe'], 'length'); |
|
* // => ['moe', 'larry', 'brendan'] |
|
*/ |
|
function sortBy(collection, callback, thisArg) { |
|
var result = []; |
|
callback = createCallback(callback, thisArg); |
|
forEach(collection, function(value, index, collection) { |
|
result.push({ |
|
'criteria': callback(value, index, collection), |
|
'index': index, |
|
'value': value |
|
}); |
|
}); |
|
|
|
var length = result.length; |
|
result.sort(compareAscending); |
|
while (length--) { |
|
result[length] = result[length].value; |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Converts the `collection`, to an array. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to convert. |
|
* @returns {Array} Returns the new converted array. |
|
* @example |
|
* |
|
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); |
|
* // => [2, 3, 4] |
|
*/ |
|
function toArray(collection) { |
|
if (collection && typeof collection.length == 'number') { |
|
return (noArraySliceOnStrings ? isString(collection) : typeof collection == 'string') |
|
? collection.split('') |
|
: slice.call(collection); |
|
} |
|
return values(collection); |
|
} |
|
|
|
/** |
|
* Examines each element in a `collection`, returning an array of all elements |
|
* that contain the given `properties`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collections |
|
* @param {Array|Object|String} collection The collection to iterate over. |
|
* @param {Object} properties The object of property values to filter by. |
|
* @returns {Array} Returns a new array of elements that contain the given `properties`. |
|
* @example |
|
* |
|
* var stooges = [ |
|
* { 'name': 'moe', 'age': 40 }, |
|
* { 'name': 'larry', 'age': 50 }, |
|
* { 'name': 'curly', 'age': 60 } |
|
* ]; |
|
* |
|
* _.where(stooges, { 'age': 40 }); |
|
* // => [{ 'name': 'moe', 'age': 40 }] |
|
*/ |
|
function where(collection, properties) { |
|
var props = []; |
|
forIn(properties, function(value, prop) { |
|
props.push(prop); |
|
}); |
|
return filter(collection, function(object) { |
|
var length = props.length; |
|
while (length--) { |
|
var result = object[props[length]] === properties[props[length]]; |
|
if (!result) { |
|
break; |
|
} |
|
} |
|
return !!result; |
|
}); |
|
} |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Creates an array with all falsey values of `array` removed. The values |
|
* `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to compact. |
|
* @returns {Array} Returns a new filtered array. |
|
* @example |
|
* |
|
* _.compact([0, 1, false, 2, '', 3]); |
|
* // => [1, 2, 3] |
|
*/ |
|
function compact(array) { |
|
var index = -1, |
|
length = array ? array.length : 0, |
|
result = []; |
|
|
|
while (++index < length) { |
|
var value = array[index]; |
|
if (value) { |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an array of `array` elements not present in the other arrays |
|
* using strict equality for comparisons, i.e. `===`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to process. |
|
* @param {Array} [array1, array2, ...] Arrays to check. |
|
* @returns {Array} Returns a new array of `array` elements not present in the |
|
* other arrays. |
|
* @example |
|
* |
|
* _.difference([1, 2, 3, 4, 5], [5, 2, 10]); |
|
* // => [1, 3, 4] |
|
*/ |
|
function difference(array) { |
|
var index = -1, |
|
length = array ? array.length : 0, |
|
flattened = concat.apply(arrayRef, arguments), |
|
contains = cachedContains(flattened, length), |
|
result = []; |
|
|
|
while (++index < length) { |
|
var value = array[index]; |
|
if (!contains(value)) { |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the first element of the `array`. Pass `n` to return the first `n` |
|
* elements of the `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias head, take |
|
* @category Arrays |
|
* @param {Array} array The array to query. |
|
* @param {Number} [n] The number of elements to return. |
|
* @param- {Object} [guard] Internally used to allow this method to work with |
|
* others like `_.map` without using their callback `index` argument for `n`. |
|
* @returns {Mixed} Returns the first element or an array of the first `n` |
|
* elements of `array`. |
|
* @example |
|
* |
|
* _.first([5, 4, 3, 2, 1]); |
|
* // => 5 |
|
*/ |
|
function first(array, n, guard) { |
|
if (array) { |
|
return (n == null || guard) ? array[0] : slice.call(array, 0, n); |
|
} |
|
} |
|
|
|
/** |
|
* Flattens a nested array (the nesting can be to any depth). If `shallow` is |
|
* truthy, `array` will only be flattened a single level. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to compact. |
|
* @param {Boolean} shallow A flag to indicate only flattening a single level. |
|
* @returns {Array} Returns a new flattened array. |
|
* @example |
|
* |
|
* _.flatten([1, [2], [3, [[4]]]]); |
|
* // => [1, 2, 3, 4]; |
|
* |
|
* _.flatten([1, [2], [3, [[4]]]], true); |
|
* // => [1, 2, 3, [[4]]]; |
|
*/ |
|
function flatten(array, shallow) { |
|
var index = -1, |
|
length = array ? array.length : 0, |
|
result = []; |
|
|
|
while (++index < length) { |
|
var value = array[index]; |
|
|
|
// recursively flatten arrays (susceptible to call stack limits) |
|
if (isArray(value)) { |
|
push.apply(result, shallow ? value : flatten(value)); |
|
} else { |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the index at which the first occurrence of `value` is found using |
|
* strict equality for comparisons, i.e. `===`. If the `array` is already |
|
* sorted, passing `true` for `fromIndex` will run a faster binary search. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to search. |
|
* @param {Mixed} value The value to search for. |
|
* @param {Boolean|Number} [fromIndex=0] The index to search from or `true` to |
|
* perform a binary search on a sorted `array`. |
|
* @returns {Number} Returns the index of the matched value or `-1`. |
|
* @example |
|
* |
|
* _.indexOf([1, 2, 3, 1, 2, 3], 2); |
|
* // => 1 |
|
* |
|
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); |
|
* // => 4 |
|
* |
|
* _.indexOf([1, 1, 2, 2, 3, 3], 2, true); |
|
* // => 2 |
|
*/ |
|
function indexOf(array, value, fromIndex) { |
|
var index = -1, |
|
length = array ? array.length : 0; |
|
|
|
if (typeof fromIndex == 'number') { |
|
index = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex || 0) - 1; |
|
} else if (fromIndex) { |
|
index = sortedIndex(array, value); |
|
return array[index] === value ? index : -1; |
|
} |
|
while (++index < length) { |
|
if (array[index] === value) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** |
|
* Gets all but the last element of `array`. Pass `n` to exclude the last `n` |
|
* elements from the result. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to query. |
|
* @param {Number} [n=1] The number of elements to exclude. |
|
* @param- {Object} [guard] Internally used to allow this method to work with |
|
* others like `_.map` without using their callback `index` argument for `n`. |
|
* @returns {Array} Returns all but the last element or `n` elements of `array`. |
|
* @example |
|
* |
|
* _.initial([3, 2, 1]); |
|
* // => [3, 2] |
|
*/ |
|
function initial(array, n, guard) { |
|
return array |
|
? slice.call(array, 0, -((n == null || guard) ? 1 : n)) |
|
: []; |
|
} |
|
|
|
/** |
|
* Computes the intersection of all the passed-in arrays using strict equality |
|
* for comparisons, i.e. `===`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} [array1, array2, ...] Arrays to process. |
|
* @returns {Array} Returns a new array of unique elements, in order, that are |
|
* present in **all** of the arrays. |
|
* @example |
|
* |
|
* _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); |
|
* // => [1, 2] |
|
*/ |
|
function intersection(array) { |
|
var args = arguments, |
|
argsLength = args.length, |
|
cache = {}, |
|
result = []; |
|
|
|
forEach(array, function(value) { |
|
if (indexOf(result, value) < 0) { |
|
var length = argsLength; |
|
while (--length) { |
|
if (!(cache[length] || (cache[length] = cachedContains(args[length])))(value)) { |
|
return; |
|
} |
|
} |
|
result.push(value); |
|
} |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the last element of the `array`. Pass `n` to return the last `n` |
|
* elements of the `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to query. |
|
* @param {Number} [n] The number of elements to return. |
|
* @param- {Object} [guard] Internally used to allow this method to work with |
|
* others like `_.map` without using their callback `index` argument for `n`. |
|
* @returns {Mixed} Returns the last element or an array of the last `n` |
|
* elements of `array`. |
|
* @example |
|
* |
|
* _.last([3, 2, 1]); |
|
* // => 1 |
|
*/ |
|
function last(array, n, guard) { |
|
if (array) { |
|
var length = array.length; |
|
return (n == null || guard) ? array[length - 1] : slice.call(array, -n || length); |
|
} |
|
} |
|
|
|
/** |
|
* Gets the index at which the last occurrence of `value` is found using strict |
|
* equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used |
|
* as the offset from the end of the collection. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to search. |
|
* @param {Mixed} value The value to search for. |
|
* @param {Number} [fromIndex=array.length-1] The index to search from. |
|
* @returns {Number} Returns the index of the matched value or `-1`. |
|
* @example |
|
* |
|
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); |
|
* // => 4 |
|
* |
|
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); |
|
* // => 1 |
|
*/ |
|
function lastIndexOf(array, value, fromIndex) { |
|
var index = array ? array.length : 0; |
|
if (typeof fromIndex == 'number') { |
|
index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1; |
|
} |
|
while (index--) { |
|
if (array[index] === value) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** |
|
* Creates an object composed from arrays of `keys` and `values`. Pass either |
|
* a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or |
|
* two arrays, one of `keys` and one of corresponding `values`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} keys The array of keys. |
|
* @param {Array} [values=[]] The array of values. |
|
* @returns {Object} Returns an object composed of the given keys and |
|
* corresponding values. |
|
* @example |
|
* |
|
* _.object(['moe', 'larry', 'curly'], [30, 40, 50]); |
|
* // => { 'moe': 30, 'larry': 40, 'curly': 50 } |
|
*/ |
|
function object(keys, values) { |
|
var index = -1, |
|
length = keys ? keys.length : 0, |
|
result = {}; |
|
|
|
while (++index < length) { |
|
var key = keys[index]; |
|
if (values) { |
|
result[key] = values[index]; |
|
} else { |
|
result[key[0]] = key[1]; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an array of numbers (positive and/or negative) progressing from |
|
* `start` up to but not including `stop`. This method is a port of Python's |
|
* `range()` function. See http://docs.python.org/library/functions.html#range. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Number} [start=0] The start of the range. |
|
* @param {Number} end The end of the range. |
|
* @param {Number} [step=1] The value to increment or descrement by. |
|
* @returns {Array} Returns a new range array. |
|
* @example |
|
* |
|
* _.range(10); |
|
* // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|
* |
|
* _.range(1, 11); |
|
* // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
|
* |
|
* _.range(0, 30, 5); |
|
* // => [0, 5, 10, 15, 20, 25] |
|
* |
|
* _.range(0, -10, -1); |
|
* // => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] |
|
* |
|
* _.range(0); |
|
* // => [] |
|
*/ |
|
function range(start, end, step) { |
|
start = +start || 0; |
|
step = +step || 1; |
|
|
|
if (end == null) { |
|
end = start; |
|
start = 0; |
|
} |
|
// use `Array(length)` so V8 will avoid the slower "dictionary" mode |
|
// http://www.youtube.com/watch?v=XAqIpGU8ZZk#t=16m27s |
|
var index = -1, |
|
length = nativeMax(0, ceil((end - start) / step)), |
|
result = Array(length); |
|
|
|
while (++index < length) { |
|
result[index] = start; |
|
start += step; |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The opposite of `_.initial`, this method gets all but the first value of |
|
* `array`. Pass `n` to exclude the first `n` values from the result. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias drop, tail |
|
* @category Arrays |
|
* @param {Array} array The array to query. |
|
* @param {Number} [n=1] The number of elements to exclude. |
|
* @param- {Object} [guard] Internally used to allow this method to work with |
|
* others like `_.map` without using their callback `index` argument for `n`. |
|
* @returns {Array} Returns all but the first value or `n` values of `array`. |
|
* @example |
|
* |
|
* _.rest([3, 2, 1]); |
|
* // => [2, 1] |
|
*/ |
|
function rest(array, n, guard) { |
|
return array |
|
? slice.call(array, (n == null || guard) ? 1 : n) |
|
: []; |
|
} |
|
|
|
/** |
|
* Uses a binary search to determine the smallest index at which the `value` |
|
* should be inserted into `array` in order to maintain the sort order of the |
|
* sorted `array`. If `callback` is passed, it will be executed for `value` and |
|
* each element in `array` to compute their sort ranking. The `callback` is |
|
* bound to `thisArg` and invoked with one argument; (value). The `callback` |
|
* argument may also be the name of a property to order by. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to iterate over. |
|
* @param {Mixed} value The value to evaluate. |
|
* @param {Function|String} [callback=identity|property] The function called |
|
* per iteration or property name to order by. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Number} Returns the index at which the value should be inserted |
|
* into `array`. |
|
* @example |
|
* |
|
* _.sortedIndex([20, 30, 50], 40); |
|
* // => 2 |
|
* |
|
* _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); |
|
* // => 2 |
|
* |
|
* var dict = { |
|
* 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } |
|
* }; |
|
* |
|
* _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { |
|
* return dict.wordToNumber[word]; |
|
* }); |
|
* // => 2 |
|
* |
|
* _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { |
|
* return this.wordToNumber[word]; |
|
* }, dict); |
|
* // => 2 |
|
*/ |
|
function sortedIndex(array, value, callback, thisArg) { |
|
var low = 0, |
|
high = array ? array.length : low; |
|
|
|
// explicitly reference `identity` for better engine inlining |
|
callback = callback ? createCallback(callback, thisArg) : identity; |
|
value = callback(value); |
|
while (low < high) { |
|
var mid = (low + high) >>> 1; |
|
callback(array[mid]) < value |
|
? low = mid + 1 |
|
: high = mid; |
|
} |
|
return low; |
|
} |
|
|
|
/** |
|
* Computes the union of the passed-in arrays using strict equality for |
|
* comparisons, i.e. `===`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} [array1, array2, ...] Arrays to process. |
|
* @returns {Array} Returns a new array of unique values, in order, that are |
|
* present in one or more of the arrays. |
|
* @example |
|
* |
|
* _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); |
|
* // => [1, 2, 3, 101, 10] |
|
*/ |
|
function union() { |
|
return uniq(concat.apply(arrayRef, arguments)); |
|
} |
|
|
|
/** |
|
* Creates a duplicate-value-free version of the `array` using strict equality |
|
* for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` |
|
* for `isSorted` will run a faster algorithm. If `callback` is passed, each |
|
* element of `array` is passed through a callback` before uniqueness is computed. |
|
* The `callback` is bound to `thisArg` and invoked with three arguments; (value, index, array). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias unique |
|
* @category Arrays |
|
* @param {Array} array The array to process. |
|
* @param {Boolean} [isSorted=false] A flag to indicate that the `array` is already sorted. |
|
* @param {Function} [callback=identity] The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Array} Returns a duplicate-value-free array. |
|
* @example |
|
* |
|
* _.uniq([1, 2, 1, 3, 1]); |
|
* // => [1, 2, 3] |
|
* |
|
* _.uniq([1, 1, 2, 2, 3], true); |
|
* // => [1, 2, 3] |
|
* |
|
* _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return Math.floor(num); }); |
|
* // => [1, 2, 3] |
|
* |
|
* _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); |
|
* // => [1, 2, 3] |
|
*/ |
|
function uniq(array, isSorted, callback, thisArg) { |
|
var index = -1, |
|
length = array ? array.length : 0, |
|
result = [], |
|
seen = result; |
|
|
|
// juggle arguments |
|
if (typeof isSorted == 'function') { |
|
thisArg = callback; |
|
callback = isSorted; |
|
isSorted = false; |
|
} |
|
// init value cache for large arrays |
|
var isLarge = !isSorted && length > 74; |
|
if (isLarge) { |
|
var cache = {}; |
|
} |
|
if (callback) { |
|
seen = []; |
|
callback = createCallback(callback, thisArg); |
|
} |
|
while (++index < length) { |
|
var value = array[index], |
|
computed = callback ? callback(value, index, array) : value; |
|
|
|
if (isLarge) { |
|
// manually coerce `computed` to a string because `hasOwnProperty`, in |
|
// some older versions of Firefox, coerces objects incorrectly |
|
seen = hasOwnProperty.call(cache, computed + '') ? cache[computed] : (cache[computed] = []); |
|
} |
|
if (isSorted |
|
? !index || seen[seen.length - 1] !== computed |
|
: indexOf(seen, computed) < 0 |
|
) { |
|
if (callback || isLarge) { |
|
seen.push(computed); |
|
} |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an array with all occurrences of the passed values removed using |
|
* strict equality for comparisons, i.e. `===`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} array The array to filter. |
|
* @param {Mixed} [value1, value2, ...] Values to remove. |
|
* @returns {Array} Returns a new filtered array. |
|
* @example |
|
* |
|
* _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); |
|
* // => [2, 3, 4] |
|
*/ |
|
function without(array) { |
|
var index = -1, |
|
length = array ? array.length : 0, |
|
contains = cachedContains(arguments, 1, 20), |
|
result = []; |
|
|
|
while (++index < length) { |
|
var value = array[index]; |
|
if (!contains(value)) { |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Groups the elements of each array at their corresponding indexes. Useful for |
|
* separate data sources that are coordinated through matching array indexes. |
|
* For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix |
|
* in a similar fashion. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Arrays |
|
* @param {Array} [array1, array2, ...] Arrays to process. |
|
* @returns {Array} Returns a new array of grouped elements. |
|
* @example |
|
* |
|
* _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); |
|
* // => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] |
|
*/ |
|
function zip(array) { |
|
var index = -1, |
|
length = array ? max(pluck(arguments, 'length')) : 0, |
|
result = Array(length); |
|
|
|
while (++index < length) { |
|
result[index] = pluck(arguments, index); |
|
} |
|
return result; |
|
} |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Creates a function that is restricted to executing `func` only after it is |
|
* called `n` times. The `func` is executed with the `this` binding of the |
|
* created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Number} n The number of times the function must be called before |
|
* it is executed. |
|
* @param {Function} func The function to restrict. |
|
* @returns {Function} Returns the new restricted function. |
|
* @example |
|
* |
|
* var renderNotes = _.after(notes.length, render); |
|
* _.forEach(notes, function(note) { |
|
* note.asyncSave({ 'success': renderNotes }); |
|
* }); |
|
* // `renderNotes` is run once, after all notes have saved |
|
*/ |
|
function after(n, func) { |
|
if (n < 1) { |
|
return func(); |
|
} |
|
return function() { |
|
if (--n < 1) { |
|
return func.apply(this, arguments); |
|
} |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that, when called, invokes `func` with the `this` |
|
* binding of `thisArg` and prepends any additional `bind` arguments to those |
|
* passed to the bound function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to bind. |
|
* @param {Mixed} [thisArg] The `this` binding of `func`. |
|
* @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied. |
|
* @returns {Function} Returns the new bound function. |
|
* @example |
|
* |
|
* var func = function(greeting) { |
|
* return greeting + ' ' + this.name; |
|
* }; |
|
* |
|
* func = _.bind(func, { 'name': 'moe' }, 'hi'); |
|
* func(); |
|
* // => 'hi moe' |
|
*/ |
|
function bind(func, thisArg) { |
|
// use `Function#bind` if it exists and is fast |
|
// (in V8 `Function#bind` is slower except when partially applied) |
|
return isBindFast || (nativeBind && arguments.length > 2) |
|
? nativeBind.call.apply(nativeBind, arguments) |
|
: createBound(func, thisArg, slice.call(arguments, 2)); |
|
} |
|
|
|
/** |
|
* Binds methods on `object` to `object`, overwriting the existing method. |
|
* If no method names are provided, all the function properties of `object` |
|
* will be bound. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Object} object The object to bind and assign the bound methods to. |
|
* @param {String} [methodName1, methodName2, ...] Method names on the object to bind. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* var buttonView = { |
|
* 'label': 'lodash', |
|
* 'onClick': function() { alert('clicked: ' + this.label); } |
|
* }; |
|
* |
|
* _.bindAll(buttonView); |
|
* jQuery('#lodash_button').on('click', buttonView.onClick); |
|
* // => When the button is clicked, `this.label` will have the correct value |
|
*/ |
|
function bindAll(object) { |
|
var funcs = arguments, |
|
index = funcs.length > 1 ? 0 : (funcs = functions(object), -1), |
|
length = funcs.length; |
|
|
|
while (++index < length) { |
|
var key = funcs[index]; |
|
object[key] = bind(object[key], object); |
|
} |
|
return object; |
|
} |
|
|
|
/** |
|
* Creates a function that is the composition of the passed functions, |
|
* where each function consumes the return value of the function that follows. |
|
* In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. |
|
* Each function is executed with the `this` binding of the composed function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} [func1, func2, ...] Functions to compose. |
|
* @returns {Function} Returns the new composed function. |
|
* @example |
|
* |
|
* var greet = function(name) { return 'hi: ' + name; }; |
|
* var exclaim = function(statement) { return statement + '!'; }; |
|
* var welcome = _.compose(exclaim, greet); |
|
* welcome('moe'); |
|
* // => 'hi: moe!' |
|
*/ |
|
function compose() { |
|
var funcs = arguments; |
|
return function() { |
|
var args = arguments, |
|
length = funcs.length; |
|
|
|
while (length--) { |
|
args = [funcs[length].apply(this, args)]; |
|
} |
|
return args[0]; |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that will delay the execution of `func` until after |
|
* `wait` milliseconds have elapsed since the last time it was invoked. Pass |
|
* `true` for `immediate` to cause debounce to invoke `func` on the leading, |
|
* instead of the trailing, edge of the `wait` timeout. Subsequent calls to |
|
* the debounced function will return the result of the last `func` call. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to debounce. |
|
* @param {Number} wait The number of milliseconds to delay. |
|
* @param {Boolean} immediate A flag to indicate execution is on the leading |
|
* edge of the timeout. |
|
* @returns {Function} Returns the new debounced function. |
|
* @example |
|
* |
|
* var lazyLayout = _.debounce(calculateLayout, 300); |
|
* jQuery(window).on('resize', lazyLayout); |
|
*/ |
|
function debounce(func, wait, immediate) { |
|
var args, |
|
result, |
|
thisArg, |
|
timeoutId; |
|
|
|
function delayed() { |
|
timeoutId = null; |
|
if (!immediate) { |
|
result = func.apply(thisArg, args); |
|
} |
|
} |
|
return function() { |
|
var isImmediate = immediate && !timeoutId; |
|
args = arguments; |
|
thisArg = this; |
|
|
|
clearTimeout(timeoutId); |
|
timeoutId = setTimeout(delayed, wait); |
|
|
|
if (isImmediate) { |
|
result = func.apply(thisArg, args); |
|
} |
|
return result; |
|
}; |
|
} |
|
|
|
/** |
|
* Executes the `func` function after `wait` milliseconds. Additional arguments |
|
* will be passed to `func` when it is invoked. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to delay. |
|
* @param {Number} wait The number of milliseconds to delay execution. |
|
* @param {Mixed} [arg1, arg2, ...] Arguments to invoke the function with. |
|
* @returns {Number} Returns the `setTimeout` timeout id. |
|
* @example |
|
* |
|
* var log = _.bind(console.log, console); |
|
* _.delay(log, 1000, 'logged later'); |
|
* // => 'logged later' (Appears after one second.) |
|
*/ |
|
function delay(func, wait) { |
|
var args = slice.call(arguments, 2); |
|
return setTimeout(function() { func.apply(undefined, args); }, wait); |
|
} |
|
|
|
/** |
|
* Defers executing the `func` function until the current call stack has cleared. |
|
* Additional arguments will be passed to `func` when it is invoked. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to defer. |
|
* @param {Mixed} [arg1, arg2, ...] Arguments to invoke the function with. |
|
* @returns {Number} Returns the `setTimeout` timeout id. |
|
* @example |
|
* |
|
* _.defer(function() { alert('deferred'); }); |
|
* // returns from the function before `alert` is called |
|
*/ |
|
function defer(func) { |
|
var args = slice.call(arguments, 1); |
|
return setTimeout(function() { func.apply(undefined, args); }, 1); |
|
} |
|
|
|
/** |
|
* Creates a function that, when called, invokes `object[methodName]` and |
|
* prepends any additional `lateBind` arguments to those passed to the bound |
|
* function. This method differs from `_.bind` by allowing bound functions to |
|
* reference methods that will be redefined or don't yet exist. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Object} object The object the method belongs to. |
|
* @param {String} methodName The method name. |
|
* @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied. |
|
* @returns {Function} Returns the new bound function. |
|
* @example |
|
* |
|
* var object = { |
|
* 'name': 'moe', |
|
* 'greet': function(greeting) { |
|
* return greeting + ' ' + this.name; |
|
* } |
|
* }; |
|
* |
|
* var func = _.lateBind(object, 'greet', 'hi'); |
|
* func(); |
|
* // => 'hi moe' |
|
* |
|
* object.greet = function(greeting) { |
|
* return greeting + ', ' + this.name + '!'; |
|
* }; |
|
* |
|
* func(); |
|
* // => 'hi, moe!' |
|
*/ |
|
function lateBind(object, methodName) { |
|
return createBound(methodName, object, slice.call(arguments, 2)); |
|
} |
|
|
|
/** |
|
* Creates a function that memoizes the result of `func`. If `resolver` is |
|
* passed, it will be used to determine the cache key for storing the result |
|
* based on the arguments passed to the memoized function. By default, the first |
|
* argument passed to the memoized function is used as the cache key. The `func` |
|
* is executed with the `this` binding of the memoized function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to have its output memoized. |
|
* @param {Function} [resolver] A function used to resolve the cache key. |
|
* @returns {Function} Returns the new memoizing function. |
|
* @example |
|
* |
|
* var fibonacci = _.memoize(function(n) { |
|
* return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); |
|
* }); |
|
*/ |
|
function memoize(func, resolver) { |
|
var cache = {}; |
|
return function() { |
|
var key = resolver ? resolver.apply(this, arguments) : arguments[0]; |
|
return hasOwnProperty.call(cache, key) |
|
? cache[key] |
|
: (cache[key] = func.apply(this, arguments)); |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that is restricted to execute `func` once. Repeat calls to |
|
* the function will return the value of the first call. The `func` is executed |
|
* with the `this` binding of the created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to restrict. |
|
* @returns {Function} Returns the new restricted function. |
|
* @example |
|
* |
|
* var initialize = _.once(createApplication); |
|
* initialize(); |
|
* initialize(); |
|
* // Application is only created once. |
|
*/ |
|
function once(func) { |
|
var result, |
|
ran = false; |
|
|
|
return function() { |
|
if (ran) { |
|
return result; |
|
} |
|
ran = true; |
|
result = func.apply(this, arguments); |
|
|
|
// clear the `func` variable so the function may be garbage collected |
|
func = null; |
|
return result; |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that, when called, invokes `func` with any additional |
|
* `partial` arguments prepended to those passed to the new function. This |
|
* method is similar to `bind`, except it does **not** alter the `this` binding. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to partially apply arguments to. |
|
* @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied. |
|
* @returns {Function} Returns the new partially applied function. |
|
* @example |
|
* |
|
* var greet = function(greeting, name) { return greeting + ': ' + name; }; |
|
* var hi = _.partial(greet, 'hi'); |
|
* hi('moe'); |
|
* // => 'hi: moe' |
|
*/ |
|
function partial(func) { |
|
return createBound(func, slice.call(arguments, 1)); |
|
} |
|
|
|
/** |
|
* Creates a function that, when executed, will only call the `func` |
|
* function at most once per every `wait` milliseconds. If the throttled |
|
* function is invoked more than once during the `wait` timeout, `func` will |
|
* also be called on the trailing edge of the timeout. Subsequent calls to the |
|
* throttled function will return the result of the last `func` call. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Function} func The function to throttle. |
|
* @param {Number} wait The number of milliseconds to throttle executions to. |
|
* @returns {Function} Returns the new throttled function. |
|
* @example |
|
* |
|
* var throttled = _.throttle(updatePosition, 100); |
|
* jQuery(window).on('scroll', throttled); |
|
*/ |
|
function throttle(func, wait) { |
|
var args, |
|
result, |
|
thisArg, |
|
timeoutId, |
|
lastCalled = 0; |
|
|
|
function trailingCall() { |
|
lastCalled = new Date; |
|
timeoutId = null; |
|
result = func.apply(thisArg, args); |
|
} |
|
return function() { |
|
var now = new Date, |
|
remaining = wait - (now - lastCalled); |
|
|
|
args = arguments; |
|
thisArg = this; |
|
|
|
if (remaining <= 0) { |
|
clearTimeout(timeoutId); |
|
lastCalled = now; |
|
result = func.apply(thisArg, args); |
|
} |
|
else if (!timeoutId) { |
|
timeoutId = setTimeout(trailingCall, remaining); |
|
} |
|
return result; |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that passes `value` to the `wrapper` function as its |
|
* first argument. Additional arguments passed to the function are appended |
|
* to those passed to the `wrapper` function. The `wrapper` is executed with |
|
* the `this` binding of the created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Functions |
|
* @param {Mixed} value The value to wrap. |
|
* @param {Function} wrapper The wrapper function. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var hello = function(name) { return 'hello ' + name; }; |
|
* hello = _.wrap(hello, function(func) { |
|
* return 'before, ' + func('moe') + ', after'; |
|
* }); |
|
* hello(); |
|
* // => 'before, hello moe, after' |
|
*/ |
|
function wrap(value, wrapper) { |
|
return function() { |
|
var args = [value]; |
|
push.apply(args, arguments); |
|
return wrapper.apply(this, args); |
|
}; |
|
} |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their |
|
* corresponding HTML entities. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {String} string The string to escape. |
|
* @returns {String} Returns the escaped string. |
|
* @example |
|
* |
|
* _.escape('Moe, Larry & Curly'); |
|
* // => "Moe, Larry & Curly" |
|
*/ |
|
function escape(string) { |
|
return string == null ? '' : (string + '').replace(reUnescapedHtml, escapeHtmlChar); |
|
} |
|
|
|
/** |
|
* This function returns the first argument passed to it. |
|
* |
|
* Note: It is used throughout Lo-Dash as a default callback. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {Mixed} value Any value. |
|
* @returns {Mixed} Returns `value`. |
|
* @example |
|
* |
|
* var moe = { 'name': 'moe' }; |
|
* moe === _.identity(moe); |
|
* // => true |
|
*/ |
|
function identity(value) { |
|
return value; |
|
} |
|
|
|
/** |
|
* Adds functions properties of `object` to the `lodash` function and chainable |
|
* wrapper. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {Object} object The object of function properties to add to `lodash`. |
|
* @example |
|
* |
|
* _.mixin({ |
|
* 'capitalize': function(string) { |
|
* return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); |
|
* } |
|
* }); |
|
* |
|
* _.capitalize('larry'); |
|
* // => 'Larry' |
|
* |
|
* _('curly').capitalize(); |
|
* // => 'Curly' |
|
*/ |
|
function mixin(object) { |
|
forEach(functions(object), function(methodName) { |
|
var func = lodash[methodName] = object[methodName]; |
|
|
|
lodash.prototype[methodName] = function() { |
|
var args = [this.__wrapped__]; |
|
push.apply(args, arguments); |
|
|
|
var result = func.apply(lodash, args); |
|
if (this.__chain__) { |
|
result = new lodash(result); |
|
result.__chain__ = true; |
|
} |
|
return result; |
|
}; |
|
}); |
|
} |
|
|
|
/** |
|
* Reverts the '_' variable to its previous value and returns a reference to |
|
* the `lodash` function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @returns {Function} Returns the `lodash` function. |
|
* @example |
|
* |
|
* var lodash = _.noConflict(); |
|
*/ |
|
function noConflict() { |
|
window._ = oldDash; |
|
return this; |
|
} |
|
|
|
/** |
|
* Produces a random number between `min` and `max` (inclusive). If only one |
|
* argument is passed, a number between `0` and the given number will be returned. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {Number} [min=0] The minimum possible value. |
|
* @param {Number} [max=1] The maximum possible value. |
|
* @returns {Number} Returns a random number. |
|
* @example |
|
* |
|
* _.random(0, 5); |
|
* // => a number between 1 and 5 |
|
* |
|
* _.random(5); |
|
* // => also a number between 1 and 5 |
|
*/ |
|
function random(min, max) { |
|
if (min == null && max == null) { |
|
max = 1; |
|
} |
|
min = +min || 0; |
|
if (max == null) { |
|
max = min; |
|
min = 0; |
|
} |
|
return min + floor(nativeRandom() * ((+max || 0) - min + 1)); |
|
} |
|
|
|
/** |
|
* Resolves the value of `property` on `object`. If `property` is a function |
|
* it will be invoked and its result returned, else the property value is |
|
* returned. If `object` is falsey, then `null` is returned. |
|
* |
|
* @deprecated |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {Object} object The object to inspect. |
|
* @param {String} property The property to get the value of. |
|
* @returns {Mixed} Returns the resolved value. |
|
* @example |
|
* |
|
* var object = { |
|
* 'cheese': 'crumpets', |
|
* 'stuff': function() { |
|
* return 'nonsense'; |
|
* } |
|
* }; |
|
* |
|
* _.result(object, 'cheese'); |
|
* // => 'crumpets' |
|
* |
|
* _.result(object, 'stuff'); |
|
* // => 'nonsense' |
|
*/ |
|
function result(object, property) { |
|
// based on Backbone's private `getValue` function |
|
// https://github.com/documentcloud/backbone/blob/0.9.2/backbone.js#L1419-1424 |
|
var value = object ? object[property] : null; |
|
return isFunction(value) ? object[property]() : value; |
|
} |
|
|
|
/** |
|
* A micro-templating method that handles arbitrary delimiters, preserves |
|
* whitespace, and correctly escapes quotes within interpolated code. |
|
* |
|
* Note: In the development build `_.template` utilizes sourceURLs for easier |
|
* debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl |
|
* |
|
* Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` |
|
* build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. |
|
* See http://developer.chrome.com/trunk/extensions/sandboxingEval.html |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {String} text The template text. |
|
* @param {Obect} data The data object used to populate the text. |
|
* @param {Object} options The options object. |
|
* escape - The "escape" delimiter regexp. |
|
* evaluate - The "evaluate" delimiter regexp. |
|
* interpolate - The "interpolate" delimiter regexp. |
|
* sourceURL - The sourceURL of the template's compiled source. |
|
* variable - The data object variable name. |
|
* |
|
* @returns {Function|String} Returns a compiled function when no `data` object |
|
* is given, else it returns the interpolated text. |
|
* @example |
|
* |
|
* // using a compiled template |
|
* var compiled = _.template('hello <%= name %>'); |
|
* compiled({ 'name': 'moe' }); |
|
* // => 'hello moe' |
|
* |
|
* var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>'; |
|
* _.template(list, { 'people': ['moe', 'larry', 'curly'] }); |
|
* // => '<li>moe</li><li>larry</li><li>curly</li>' |
|
* |
|
* // using the "escape" delimiter to escape HTML in data property values |
|
* _.template('<b><%- value %></b>', { 'value': '<script>' }); |
|
* // => '<b><script></b>' |
|
* |
|
* // using the ES6 delimiter as an alternative to the default "interpolate" delimiter |
|
* _.template('hello ${ name }', { 'name': 'curly' }); |
|
* // => 'hello curly' |
|
* |
|
* // using the internal `print` function in "evaluate" delimiters |
|
* _.template('<% print("hello " + epithet); %>!', { 'epithet': 'stooge' }); |
|
* // => 'hello stooge!' |
|
* |
|
* // using custom template delimiters |
|
* _.templateSettings = { |
|
* 'interpolate': /{{([\s\S]+?)}}/g |
|
* }; |
|
* |
|
* _.template('hello {{ name }}!', { 'name': 'mustache' }); |
|
* // => 'hello mustache!' |
|
* |
|
* // using the `sourceURL` option to specify a custom sourceURL for the template |
|
* var compiled = _.template('hello <%= name %>', null, { 'sourceURL': '/basic/greeting.jst' }); |
|
* compiled(data); |
|
* // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector |
|
* |
|
* // using the `variable` option to ensure a with-statement isn't used in the compiled template |
|
* var compiled = _.template('hello <%= data.name %>!', null, { 'variable': 'data' }); |
|
* compiled.source; |
|
* // => function(data) { |
|
* var __t, __p = '', __e = _.escape; |
|
* __p += 'hello ' + ((__t = ( data.name )) == null ? '' : __t) + '!'; |
|
* return __p; |
|
* } |
|
* |
|
* // using the `source` property to inline compiled templates for meaningful |
|
* // line numbers in error messages and a stack trace |
|
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\ |
|
* var JST = {\ |
|
* "main": ' + _.template(mainText).source + '\ |
|
* };\ |
|
* '); |
|
*/ |
|
function template(text, data, options) { |
|
// based on John Resig's `tmpl` implementation |
|
// http://ejohn.org/blog/javascript-micro-templating/ |
|
// and Laura Doktorova's doT.js |
|
// https://github.com/olado/doT |
|
text || (text = ''); |
|
options || (options = {}); |
|
|
|
var isEvaluating, |
|
result, |
|
settings = lodash.templateSettings, |
|
index = 0, |
|
interpolate = options.interpolate || settings.interpolate || reNoMatch, |
|
source = "__p += '", |
|
variable = options.variable || settings.variable, |
|
hasVariable = variable; |
|
|
|
// compile regexp to match each delimiter |
|
var reDelimiters = RegExp( |
|
(options.escape || settings.escape || reNoMatch).source + '|' + |
|
interpolate.source + '|' + |
|
(interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + |
|
(options.evaluate || settings.evaluate || reNoMatch).source + '|$' |
|
, 'g'); |
|
|
|
text.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { |
|
interpolateValue || (interpolateValue = esTemplateValue); |
|
|
|
// escape characters that cannot be included in string literals |
|
source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar); |
|
|
|
// replace delimiters with snippets |
|
source += |
|
escapeValue ? "' +\n__e(" + escapeValue + ") +\n'" : |
|
evaluateValue ? "';\n" + evaluateValue + ";\n__p += '" : |
|
interpolateValue ? "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'" : ''; |
|
|
|
isEvaluating || (isEvaluating = evaluateValue || reComplexDelimiter.test(escapeValue || interpolateValue)); |
|
index = offset + match.length; |
|
}); |
|
|
|
source += "';\n"; |
|
|
|
// if `variable` is not specified and the template contains "evaluate" |
|
// delimiters, wrap a with-statement around the generated code to add the |
|
// data object to the top of the scope chain |
|
if (!hasVariable) { |
|
variable = 'obj'; |
|
if (isEvaluating) { |
|
source = 'with (' + variable + ') {\n' + source + '\n}\n'; |
|
} |
|
else { |
|
// avoid a with-statement by prepending data object references to property names |
|
var reDoubleVariable = RegExp('(\\(\\s*)' + variable + '\\.' + variable + '\\b', 'g'); |
|
source = source |
|
.replace(reInsertVariable, '$&' + variable + '.') |
|
.replace(reDoubleVariable, '$1__d'); |
|
} |
|
} |
|
|
|
// cleanup code by stripping empty strings |
|
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) |
|
.replace(reEmptyStringMiddle, '$1') |
|
.replace(reEmptyStringTrailing, '$1;'); |
|
|
|
// frame code as the function body |
|
source = 'function(' + variable + ') {\n' + |
|
(hasVariable ? '' : variable + ' || (' + variable + ' = {});\n') + |
|
'var __t, __p = \'\', __e = _.escape' + |
|
(isEvaluating |
|
? ', __j = Array.prototype.join;\n' + |
|
'function print() { __p += __j.call(arguments, \'\') }\n' |
|
: (hasVariable ? '' : ', __d = ' + variable + '.' + variable + ' || ' + variable) + ';\n' |
|
) + |
|
source + |
|
'return __p\n}'; |
|
|
|
// use a sourceURL for easier debugging |
|
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl |
|
var sourceURL = useSourceURL |
|
? '\n//@ sourceURL=' + (options.sourceURL || '/lodash/template/source[' + (templateCounter++) + ']') |
|
: ''; |
|
|
|
try { |
|
result = Function('_', 'return ' + source + sourceURL)(lodash); |
|
} catch(e) { |
|
e.source = source; |
|
throw e; |
|
} |
|
|
|
if (data) { |
|
return result(data); |
|
} |
|
// provide the compiled function's source via its `toString` method, in |
|
// supported environments, or the `source` property as a convenience for |
|
// inlining compiled templates during the build process |
|
result.source = source; |
|
return result; |
|
} |
|
|
|
/** |
|
* Executes the `callback` function `n` times, returning an array of the results |
|
* of each `callback` execution. The `callback` is bound to `thisArg` and invoked |
|
* with one argument; (index). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {Number} n The number of times to execute the callback. |
|
* @param {Function} callback The function called per iteration. |
|
* @param {Mixed} [thisArg] The `this` binding of `callback`. |
|
* @returns {Array} Returns a new array of the results of each `callback` execution. |
|
* @example |
|
* |
|
* var diceRolls = _.times(3, _.partial(_.random, 1, 6)); |
|
* // => [3, 6, 4] |
|
* |
|
* _.times(3, function(n) { mage.castSpell(n); }); |
|
* // => calls `mage.castSpell(n)` three times, passing `n` of `0`, `1`, and `2` respectively |
|
* |
|
* _.times(3, function(n) { this.cast(n); }, mage); |
|
* // => also calls `mage.castSpell(n)` three times |
|
*/ |
|
function times(n, callback, thisArg) { |
|
n = +n || 0; |
|
var index = -1, |
|
result = Array(n); |
|
|
|
while (++index < n) { |
|
result[index] = callback.call(thisArg, index); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The opposite of `_.escape`, this method converts the HTML entities |
|
* `&`, `<`, `>`, `"`, and `'` in `string` to their |
|
* corresponding characters. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {String} string The string to unescape. |
|
* @returns {String} Returns the unescaped string. |
|
* @example |
|
* |
|
* _.unescape('Moe, Larry & Curly'); |
|
* // => "Moe, Larry & Curly" |
|
*/ |
|
function unescape(string) { |
|
return string == null ? '' : (string + '').replace(reEscapedHtml, unescapeHtmlChar); |
|
} |
|
|
|
/** |
|
* Generates a unique id. If `prefix` is passed, the id will be appended to it. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utilities |
|
* @param {String} [prefix] The value to prefix the id with. |
|
* @returns {Number|String} Returns a numeric id if no prefix is passed, else |
|
* a string id may be returned. |
|
* @example |
|
* |
|
* _.uniqueId('contact_'); |
|
* // => 'contact_104' |
|
*/ |
|
function uniqueId(prefix) { |
|
var id = idCounter++; |
|
return prefix ? prefix + id : id; |
|
} |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* Wraps the value in a `lodash` wrapper object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Chaining |
|
* @param {Mixed} value The value to wrap. |
|
* @returns {Object} Returns the wrapper object. |
|
* @example |
|
* |
|
* var stooges = [ |
|
* { 'name': 'moe', 'age': 40 }, |
|
* { 'name': 'larry', 'age': 50 }, |
|
* { 'name': 'curly', 'age': 60 } |
|
* ]; |
|
* |
|
* var youngest = _.chain(stooges) |
|
* .sortBy(function(stooge) { return stooge.age; }) |
|
* .map(function(stooge) { return stooge.name + ' is ' + stooge.age; }) |
|
* .first() |
|
* .value(); |
|
* // => 'moe is 40' |
|
*/ |
|
function chain(value) { |
|
value = new lodash(value); |
|
value.__chain__ = true; |
|
return value; |
|
} |
|
|
|
/** |
|
* Invokes `interceptor` with the `value` as the first argument, and then |
|
* returns `value`. The purpose of this method is to "tap into" a method chain, |
|
* in order to perform operations on intermediate results within the chain. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Chaining |
|
* @param {Mixed} value The value to pass to `interceptor`. |
|
* @param {Function} interceptor The function to invoke. |
|
* @returns {Mixed} Returns `value`. |
|
* @example |
|
* |
|
* _.chain([1, 2, 3, 200]) |
|
* .filter(function(num) { return num % 2 == 0; }) |
|
* .tap(alert) |
|
* .map(function(num) { return num * num }) |
|
* .value(); |
|
* // => // [2, 200] (alerted) |
|
* // => [4, 40000] |
|
*/ |
|
function tap(value, interceptor) { |
|
interceptor(value); |
|
return value; |
|
} |
|
|
|
/** |
|
* Enables method chaining on the wrapper object. |
|
* |
|
* @name chain |
|
* @deprecated |
|
* @memberOf _ |
|
* @category Chaining |
|
* @returns {Mixed} Returns the wrapper object. |
|
* @example |
|
* |
|
* _([1, 2, 3]).value(); |
|
* // => [1, 2, 3] |
|
*/ |
|
function wrapperChain() { |
|
this.__chain__ = true; |
|
return this; |
|
} |
|
|
|
/** |
|
* Extracts the wrapped value. |
|
* |
|
* @name value |
|
* @memberOf _ |
|
* @category Chaining |
|
* @returns {Mixed} Returns the wrapped value. |
|
* @example |
|
* |
|
* _([1, 2, 3]).value(); |
|
* // => [1, 2, 3] |
|
*/ |
|
function wrapperValue() { |
|
return this.__wrapped__; |
|
} |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
/** |
|
* The semantic version number. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type String |
|
*/ |
|
lodash.VERSION = '0.9.2'; |
|
|
|
// assign static methods |
|
lodash.after = after; |
|
lodash.bind = bind; |
|
lodash.bindAll = bindAll; |
|
lodash.chain = chain; |
|
lodash.clone = clone; |
|
lodash.compact = compact; |
|
lodash.compose = compose; |
|
lodash.contains = contains; |
|
lodash.countBy = countBy; |
|
lodash.debounce = debounce; |
|
lodash.defaults = defaults; |
|
lodash.defer = defer; |
|
lodash.delay = delay; |
|
lodash.difference = difference; |
|
lodash.escape = escape; |
|
lodash.every = every; |
|
lodash.extend = extend; |
|
lodash.filter = filter; |
|
lodash.find = find; |
|
lodash.first = first; |
|
lodash.flatten = flatten; |
|
lodash.forEach = forEach; |
|
lodash.forIn = forIn; |
|
lodash.forOwn = forOwn; |
|
lodash.functions = functions; |
|
lodash.groupBy = groupBy; |
|
lodash.has = has; |
|
lodash.identity = identity; |
|
lodash.indexOf = indexOf; |
|
lodash.initial = initial; |
|
lodash.intersection = intersection; |
|
lodash.invert = invert; |
|
lodash.invoke = invoke; |
|
lodash.isArguments = isArguments; |
|
lodash.isArray = isArray; |
|
lodash.isBoolean = isBoolean; |
|
lodash.isDate = isDate; |
|
lodash.isElement = isElement; |
|
lodash.isEmpty = isEmpty; |
|
lodash.isEqual = isEqual; |
|
lodash.isFinite = isFinite; |
|
lodash.isFunction = isFunction; |
|
lodash.isNaN = isNaN; |
|
lodash.isNull = isNull; |
|
lodash.isNumber = isNumber; |
|
lodash.isObject = isObject; |
|
lodash.isPlainObject = isPlainObject; |
|
lodash.isRegExp = isRegExp; |
|
lodash.isString = isString; |
|
lodash.isUndefined = isUndefined; |
|
lodash.keys = keys; |
|
lodash.last = last; |
|
lodash.lastIndexOf = lastIndexOf; |
|
lodash.lateBind = lateBind; |
|
lodash.map = map; |
|
lodash.max = max; |
|
lodash.memoize = memoize; |
|
lodash.merge = merge; |
|
lodash.min = min; |
|
lodash.mixin = mixin; |
|
lodash.noConflict = noConflict; |
|
lodash.object = object; |
|
lodash.omit = omit; |
|
lodash.once = once; |
|
lodash.pairs = pairs; |
|
lodash.partial = partial; |
|
lodash.pick = pick; |
|
lodash.pluck = pluck; |
|
lodash.random = random; |
|
lodash.range = range; |
|
lodash.reduce = reduce; |
|
lodash.reduceRight = reduceRight; |
|
lodash.reject = reject; |
|
lodash.rest = rest; |
|
lodash.result = result; |
|
lodash.shuffle = shuffle; |
|
lodash.size = size; |
|
lodash.some = some; |
|
lodash.sortBy = sortBy; |
|
lodash.sortedIndex = sortedIndex; |
|
lodash.tap = tap; |
|
lodash.template = template; |
|
lodash.throttle = throttle; |
|
lodash.times = times; |
|
lodash.toArray = toArray; |
|
lodash.unescape = unescape; |
|
lodash.union = union; |
|
lodash.uniq = uniq; |
|
lodash.uniqueId = uniqueId; |
|
lodash.values = values; |
|
lodash.where = where; |
|
lodash.without = without; |
|
lodash.wrap = wrap; |
|
lodash.zip = zip; |
|
|
|
// assign aliases |
|
lodash.all = every; |
|
lodash.any = some; |
|
lodash.collect = map; |
|
lodash.detect = find; |
|
lodash.drop = rest; |
|
lodash.each = forEach; |
|
lodash.foldl = reduce; |
|
lodash.foldr = reduceRight; |
|
lodash.head = first; |
|
lodash.include = contains; |
|
lodash.inject = reduce; |
|
lodash.methods = functions; |
|
lodash.select = filter; |
|
lodash.tail = rest; |
|
lodash.take = first; |
|
lodash.unique = uniq; |
|
|
|
// add pseudo private property to be used and removed during the build process |
|
lodash._iteratorTemplate = iteratorTemplate; |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
// add all static functions to `lodash.prototype` |
|
mixin(lodash); |
|
|
|
// add `lodash.prototype.chain` after calling `mixin()` to avoid overwriting |
|
// it with the wrapped `lodash.chain` |
|
lodash.prototype.chain = wrapperChain; |
|
lodash.prototype.value = wrapperValue; |
|
|
|
// add all mutator Array functions to the wrapper. |
|
forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { |
|
var func = arrayRef[methodName]; |
|
|
|
lodash.prototype[methodName] = function() { |
|
var value = this.__wrapped__; |
|
func.apply(value, arguments); |
|
|
|
// avoid array-like object bugs with `Array#shift` and `Array#splice` in |
|
// Firefox < 10 and IE < 9 |
|
if (hasObjectSpliceBug && value.length === 0) { |
|
delete value[0]; |
|
} |
|
if (this.__chain__) { |
|
value = new lodash(value); |
|
value.__chain__ = true; |
|
} |
|
return value; |
|
}; |
|
}); |
|
|
|
// add all accessor Array functions to the wrapper. |
|
forEach(['concat', 'join', 'slice'], function(methodName) { |
|
var func = arrayRef[methodName]; |
|
|
|
lodash.prototype[methodName] = function() { |
|
var value = this.__wrapped__, |
|
result = func.apply(value, arguments); |
|
|
|
if (this.__chain__) { |
|
result = new lodash(result); |
|
result.__chain__ = true; |
|
} |
|
return result; |
|
}; |
|
}); |
|
|
|
/*--------------------------------------------------------------------------*/ |
|
|
|
// expose Lo-Dash |
|
// some AMD build optimizers, like r.js, check for specific condition patterns like the following: |
|
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { |
|
// Expose Lo-Dash to the global object even when an AMD loader is present in |
|
// case Lo-Dash was injected by a third-party script and not intended to be |
|
// loaded as a module. The global assignment can be reverted in the Lo-Dash |
|
// module via its `noConflict()` method. |
|
window._ = lodash; |
|
|
|
// define as an anonymous module so, through path mapping, it can be |
|
// referenced as the "underscore" module |
|
define('lodash/lodash',[],function() { |
|
return lodash; |
|
}); |
|
} |
|
// check for `exports` after `define` in case a build optimizer adds an `exports` object |
|
else if (freeExports) { |
|
// in Node.js or RingoJS v0.8.0+ |
|
if (typeof module == 'object' && module && module.exports == freeExports) { |
|
(module.exports = lodash)._ = lodash; |
|
} |
|
// in Narwhal or RingoJS v0.7.0- |
|
else { |
|
freeExports._ = lodash; |
|
} |
|
} |
|
else { |
|
// in a browser or Rhino |
|
window._ = lodash; |
|
} |
|
}(this)); |
|
|
|
define('lodash', ['lodash/lodash'], function (main) { return main; }); |
|
|
|
// Backbone.js 0.9.2 |
|
|
|
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. |
|
// Backbone may be freely distributed under the MIT license. |
|
// For all details and documentation: |
|
// http://backbonejs.org |
|
|
|
(function(){ |
|
|
|
// Initial Setup |
|
// ------------- |
|
|
|
// Save a reference to the global object (`window` in the browser, `global` |
|
// on the server). |
|
var root = this; |
|
|
|
// Save the previous value of the `Backbone` variable, so that it can be |
|
// restored later on, if `noConflict` is used. |
|
var previousBackbone = root.Backbone; |
|
|
|
// Create a local reference to array methods. |
|
var ArrayProto = Array.prototype; |
|
var push = ArrayProto.push; |
|
var slice = ArrayProto.slice; |
|
var splice = ArrayProto.splice; |
|
|
|
// The top-level namespace. All public Backbone classes and modules will |
|
// be attached to this. Exported for both CommonJS and the browser. |
|
var Backbone; |
|
if (typeof exports !== 'undefined') { |
|
Backbone = exports; |
|
} else { |
|
Backbone = root.Backbone = {}; |
|
} |
|
|
|
// Current version of the library. Keep in sync with `package.json`. |
|
Backbone.VERSION = '0.9.2'; |
|
|
|
// Require Underscore, if we're on the server, and it's not already present. |
|
var _ = root._; |
|
if (!_ && (typeof require !== 'undefined')) _ = require('underscore'); |
|
|
|
// For Backbone's purposes, jQuery, Zepto, or Ender owns the `$` variable. |
|
Backbone.$ = root.jQuery || root.Zepto || root.ender; |
|
|
|
// Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable |
|
// to its previous owner. Returns a reference to this Backbone object. |
|
Backbone.noConflict = function() { |
|
root.Backbone = previousBackbone; |
|
return this; |
|
}; |
|
|
|
// Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option |
|
// will fake `"PUT"` and `"DELETE"` requests via the `_method` parameter and |
|
// set a `X-Http-Method-Override` header. |
|
Backbone.emulateHTTP = false; |
|
|
|
// Turn on `emulateJSON` to support legacy servers that can't deal with direct |
|
// `application/json` requests ... will encode the body as |
|
// `application/x-www-form-urlencoded` instead and will send the model in a |
|
// form param named `model`. |
|
Backbone.emulateJSON = false; |
|
|
|
// Backbone.Events |
|
// ----------------- |
|
|
|
// Regular expression used to split event strings |
|
var eventSplitter = /\s+/; |
|
|
|
// A module that can be mixed in to *any object* in order to provide it with |
|
// custom events. You may bind with `on` or remove with `off` callback functions |
|
// to an event; `trigger`-ing an event fires all callbacks in succession. |
|
// |
|
// var object = {}; |
|
// _.extend(object, Backbone.Events); |
|
// object.on('expand', function(){ alert('expanded'); }); |
|
// object.trigger('expand'); |
|
// |
|
var Events = Backbone.Events = { |
|
|
|
// Bind one or more space separated events, `events`, to a `callback` |
|
// function. Passing `"all"` will bind the callback to all events fired. |
|
on: function(events, callback, context) { |
|
var calls, event, list; |
|
if (!callback) return this; |
|
|
|
events = events.split(eventSplitter); |
|
calls = this._callbacks || (this._callbacks = {}); |
|
|
|
while (event = events.shift()) { |
|
list = calls[event] || (calls[event] = []); |
|
list.push(callback, context); |
|
} |
|
|
|
return this; |
|
}, |
|
|
|
// Remove one or many callbacks. If `context` is null, removes all callbacks |
|
// with that function. If `callback` is null, removes all callbacks for the |
|
// event. If `events` is null, removes all bound callbacks for all events. |
|
off: function(events, callback, context) { |
|
var event, calls, list, i; |
|
|
|
// No events, or removing *all* events. |
|
if (!(calls = this._callbacks)) return this; |
|
if (!(events || callback || context)) { |
|
delete this._callbacks; |
|
return this; |
|
} |
|
|
|
events = events ? events.split(eventSplitter) : _.keys(calls); |
|
|
|
// Loop through the callback list, splicing where appropriate. |
|
while (event = events.shift()) { |
|
if (!(list = calls[event]) || !(callback || context)) { |
|
delete calls[event]; |
|
continue; |
|
} |
|
|
|
for (i = list.length - 2; i >= 0; i -= 2) { |
|
if (!(callback && list[i] !== callback || context && list[i + 1] !== context)) { |
|
list.splice(i, 2); |
|
} |
|
} |
|
} |
|
|
|
return this; |
|
}, |
|
|
|
// Trigger one or many events, firing all bound callbacks. Callbacks are |
|
// passed the same arguments as `trigger` is, apart from the event name |
|
// (unless you're listening on `"all"`, which will cause your callback to |
|
// receive the true name of the event as the first argument). |
|
trigger: function(events) { |
|
var event, calls, list, i, length, args, all, rest; |
|
if (!(calls = this._callbacks)) return this; |
|
|
|
rest = []; |
|
events = events.split(eventSplitter); |
|
|
|
// Fill up `rest` with the callback arguments. Since we're only copying |
|
// the tail of `arguments`, a loop is much faster than Array#slice. |
|
for (i = 1, length = arguments.length; i < length; i++) { |
|
rest[i - 1] = arguments[i]; |
|
} |
|
|
|
// For each event, walk through the list of callbacks twice, first to |
|
// trigger the event, then to trigger any `"all"` callbacks. |
|
while (event = events.shift()) { |
|
// Copy callback lists to prevent modification. |
|
if (all = calls.all) all = all.slice(); |
|
if (list = calls[event]) list = list.slice(); |
|
|
|
// Execute event callbacks. |
|
if (list) { |
|
for (i = 0, length = list.length; i < length; i += 2) { |
|
list[i].apply(list[i + 1] || this, rest); |
|
} |
|
} |
|
|
|
// Execute "all" callbacks. |
|
if (all) { |
|
args = [event].concat(rest); |
|
for (i = 0, length = all.length; i < length; i += 2) { |
|
all[i].apply(all[i + 1] || this, args); |
|
} |
|
} |
|
} |
|
|
|
return this; |
|
} |
|
|
|
}; |
|
|
|
// Aliases for backwards compatibility. |
|
Events.bind = Events.on; |
|
Events.unbind = Events.off; |
|
|
|
// Backbone.Model |
|
// -------------- |
|
|
|
// Create a new model, with defined attributes. A client id (`cid`) |
|
// is automatically generated and assigned for you. |
|
var Model = Backbone.Model = function(attributes, options) { |
|
var defaults; |
|
var attrs = attributes || {}; |
|
if (options && options.collection) this.collection = options.collection; |
|
if (options && options.parse) attributes = this.parse(attributes); |
|
if (defaults = _.result(this, 'defaults')) { |
|
attrs = _.extend({}, defaults, attrs); |
|
} |
|
this.attributes = {}; |
|
this._escapedAttributes = {}; |
|
this.cid = _.uniqueId('c'); |
|
this.changed = {}; |
|
this._changes = {}; |
|
this._pending = {}; |
|
this.set(attrs, {silent: true}); |
|
// Reset change tracking. |
|
this.changed = {}; |
|
this._changes = {}; |
|
this._pending = {}; |
|
this._previousAttributes = _.clone(this.attributes); |
|
this.initialize.apply(this, arguments); |
|
}; |
|
|
|
// Attach all inheritable methods to the Model prototype. |
|
_.extend(Model.prototype, Events, { |
|
|
|
// A hash of attributes whose current and previous value differ. |
|
changed: null, |
|
|
|
// A hash of attributes that have changed since the last time `change` |
|
// was called. |
|
_changes: null, |
|
|
|
// A hash of attributes that have changed since the last `change` event |
|
// began. |
|
_pending: null, |
|
|
|
// A hash of attributes with the current model state to determine if |
|
// a `change` should be recorded within a nested `change` block. |
|
_changing : null, |
|
|
|
// The default name for the JSON `id` attribute is `"id"`. MongoDB and |
|
// CouchDB users may want to set this to `"_id"`. |
|
idAttribute: 'id', |
|
|
|
// Initialize is an empty function by default. Override it with your own |
|
// initialization logic. |
|
initialize: function(){}, |
|
|
|
// Return a copy of the model's `attributes` object. |
|
toJSON: function(options) { |
|
return _.clone(this.attributes); |
|
}, |
|
|
|
// Proxy `Backbone.sync` by default. |
|
sync: function() { |
|
return Backbone.sync.apply(this, arguments); |
|
}, |
|
|
|
// Get the value of an attribute. |
|
get: function(attr) { |
|
return this.attributes[attr]; |
|
}, |
|
|
|
// Get the HTML-escaped value of an attribute. |
|
escape: function(attr) { |
|
var html; |
|
if (html = this._escapedAttributes[attr]) return html; |
|
var val = this.get(attr); |
|
return this._escapedAttributes[attr] = _.escape(val == null ? '' : '' + val); |
|
}, |
|
|
|
// Returns `true` if the attribute contains a value that is not null |
|
// or undefined. |
|
has: function(attr) { |
|
return this.get(attr) != null; |
|
}, |
|
|
|
// Set a hash of model attributes on the object, firing `"change"` unless |
|
// you choose to silence it. |
|
set: function(attrs, options) { |
|
var attr, key, val; |
|
if (attrs == null) return this; |
|
|
|
// Handle both `"key", value` and `{key: value}` -style arguments. |
|
if (!_.isObject(attrs)) { |
|
key = attrs; |
|
(attrs = {})[key] = options; |
|
options = arguments[2]; |
|
} |
|
|
|
// Extract attributes and options. |
|
var silent = options && options.silent; |
|
var unset = options && options.unset; |
|
if (attrs instanceof Model) attrs = attrs.attributes; |
|
if (unset) for (attr in attrs) attrs[attr] = void 0; |
|
|
|
// Run validation. |
|
if (!this._validate(attrs, options)) return false; |
|
|
|
// Check for changes of `id`. |
|
if (this.idAttribute in attrs) this.id = attrs[this.idAttribute]; |
|
|
|
var changing = this._changing; |
|
var now = this.attributes; |
|
var escaped = this._escapedAttributes; |
|
var prev = this._previousAttributes || {}; |
|
|
|
// For each `set` attribute... |
|
for (attr in attrs) { |
|
val = attrs[attr]; |
|
|
|
// If the new and current value differ, record the change. |
|
if (!_.isEqual(now[attr], val) || (unset && _.has(now, attr))) { |
|
delete escaped[attr]; |
|
this._changes[attr] = true; |
|
} |
|
|
|
// Update or delete the current value. |
|
unset ? delete now[attr] : now[attr] = val; |
|
|
|
// If the new and previous value differ, record the change. If not, |
|
// then remove changes for this attribute. |
|
if (!_.isEqual(prev[attr], val) || (_.has(now, attr) !== _.has(prev, attr))) { |
|
this.changed[attr] = val; |
|
if (!silent) this._pending[attr] = true; |
|
} else { |
|
delete this.changed[attr]; |
|
delete this._pending[attr]; |
|
if (!changing) delete this._changes[attr]; |
|
} |
|
|
|
if (changing && _.isEqual(now[attr], changing[attr])) delete this._changes[attr]; |
|
} |
|
|
|
// Fire the `"change"` events. |
|
if (!silent) this.change(options); |
|
return this; |
|
}, |
|
|
|
// Remove an attribute from the model, firing `"change"` unless you choose |
|
// to silence it. `unset` is a noop if the attribute doesn't exist. |
|
unset: function(attr, options) { |
|
options = _.extend({}, options, {unset: true}); |
|
return this.set(attr, null, options); |
|
}, |
|
|
|
// Clear all attributes on the model, firing `"change"` unless you choose |
|
// to silence it. |
|
clear: function(options) { |
|
options = _.extend({}, options, {unset: true}); |
|
return this.set(_.clone(this.attributes), options); |
|
}, |
|
|
|
// Fetch the model from the server. If the server's representation of the |
|
// model differs from its current attributes, they will be overriden, |
|
// triggering a `"change"` event. |
|
fetch: function(options) { |
|
options = options ? _.clone(options) : {}; |
|
var model = this; |
|
var success = options.success; |
|
options.success = function(resp, status, xhr) { |
|
if (!model.set(model.parse(resp, xhr), options)) return false; |
|
if (success) success(model, resp, options); |
|
}; |
|
return this.sync('read', this, options); |
|
}, |
|
|
|
// Set a hash of model attributes, and sync the model to the server. |
|
// If the server returns an attributes hash that differs, the model's |
|
// state will be `set` again. |
|
save: function(attrs, options) { |
|
var key, current, done; |
|
|
|
// Handle both `"key", value` and `{key: value}` -style arguments. |
|
if (attrs != null && !_.isObject(attrs)) { |
|
key = attrs; |
|
(attrs = {})[key] = options; |
|
options = arguments[2]; |
|
} |
|
options = options ? _.clone(options) : {}; |
|
|
|
// If we're "wait"-ing to set changed attributes, validate early. |
|
if (options.wait) { |
|
if (!this._validate(attrs, options)) return false; |
|
current = _.clone(this.attributes); |
|
} |
|
|
|
// Regular saves `set` attributes before persisting to the server. |
|
var silentOptions = _.extend({}, options, {silent: true}); |
|
if (attrs && !this.set(attrs, options.wait ? silentOptions : options)) { |
|
return false; |
|
} |
|
|
|
// Do not persist invalid models. |
|
if (!attrs && !this._validate(null, options)) return false; |
|
|
|
// After a successful server-side save, the client is (optionally) |
|
// updated with the server-side state. |
|
var model = this; |
|
var success = options.success; |
|
options.success = function(resp, status, xhr) { |
|
done = true; |
|
var serverAttrs = model.parse(resp, xhr); |
|
if (options.wait) serverAttrs = _.extend(attrs || {}, serverAttrs); |
|
if (!model.set(serverAttrs, options)) return false; |
|
if (success) success(model, resp, options); |
|
}; |
|
|
|
// Finish configuring and sending the Ajax request. |
|
var xhr = this.sync(this.isNew() ? 'create' : 'update', this, options); |
|
|
|
// When using `wait`, reset attributes to original values unless |
|
// `success` has been called already. |
|
if (!done && options.wait) { |
|
this.clear(silentOptions); |
|
this.set(current, silentOptions); |
|
} |
|
|
|
return xhr; |
|
}, |
|
|
|
// Destroy this model on the server if it was already persisted. |
|
// Optimistically removes the model from its collection, if it has one. |
|
// If `wait: true` is passed, waits for the server to respond before removal. |
|
destroy: function(options) { |
|
options = options ? _.clone(options) : {}; |
|
var model = this; |
|
var success = options.success; |
|
|
|
var destroy = function() { |
|
model.trigger('destroy', model, model.collection, options); |
|
}; |
|
|
|
options.success = function(resp) { |
|
if (options.wait || model.isNew()) destroy(); |
|
if (success) success(model, resp, options); |
|
}; |
|
|
|
if (this.isNew()) { |
|
options.success(); |
|
return false; |
|
} |
|
|
|
var xhr = this.sync('delete', this, options); |
|
if (!options.wait) destroy(); |
|
return xhr; |
|
}, |
|
|
|
// Default URL for the model's representation on the server -- if you're |
|
// using Backbone's restful methods, override this to change the endpoint |
|
// that will be called. |
|
url: function() { |
|
var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url') || urlError(); |
|
if (this.isNew()) return base; |
|
return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id); |
|
}, |
|
|
|
// **parse** converts a response into the hash of attributes to be `set` on |
|
// the model. The default implementation is just to pass the response along. |
|
parse: function(resp, xhr) { |
|
return resp; |
|
}, |
|
|
|
// Create a new model with identical attributes to this one. |
|
clone: function() { |
|
return new this.constructor(this.attributes); |
|
}, |
|
|
|
// A model is new if it has never been saved to the server, and lacks an id. |
|
isNew: function() { |
|
return this.id == null; |
|
}, |
|
|
|
// Call this method to manually fire a `"change"` event for this model and |
|
// a `"change:attribute"` event for each changed attribute. |
|
// Calling this will cause all objects observing the model to update. |
|
change: function(options) { |
|
var changing = this._changing; |
|
var current = this._changing = {}; |
|
|
|
// Silent changes become pending changes. |
|
for (var attr in this._changes) this._pending[attr] = true; |
|
|
|
// Trigger 'change:attr' for any new or silent changes. |
|
var changes = this._changes; |
|
this._changes = {}; |
|
|
|
// Set the correct state for this._changing values |
|
var triggers = []; |
|
for (var attr in changes) { |
|
current[attr] = this.get(attr); |
|
triggers.push(attr); |
|
} |
|
|
|
for (var i=0, l=triggers.length; i < l; i++) { |
|
this.trigger('change:' + triggers[i], this, current[triggers[i]], options); |
|
} |
|
if (changing) return this; |
|
|
|
// Continue firing `"change"` events while there are pending changes. |
|
while (!_.isEmpty(this._pending)) { |
|
this._pending = {}; |
|
this.trigger('change', this, options); |
|
// Pending and silent changes still remain. |
|
for (var attr in this.changed) { |
|
if (this._pending[attr] || this._changes[attr]) continue; |
|
delete this.changed[attr]; |
|
} |
|
this._previousAttributes = _.clone(this.attributes); |
|
} |
|
|
|
this._changing = null; |
|
return this; |
|
}, |
|
|
|
// Determine if the model has changed since the last `"change"` event. |
|
// If you specify an attribute name, determine if that attribute has changed. |
|
hasChanged: function(attr) { |
|
if (attr == null) return !_.isEmpty(this.changed); |
|
return _.has(this.changed, attr); |
|
}, |
|
|
|
// Return an object containing all the attributes that have changed, or |
|
// false if there are no changed attributes. Useful for determining what |
|
// parts of a view need to be updated and/or what attributes need to be |
|
// persisted to the server. Unset attributes will be set to undefined. |
|
// You can also pass an attributes object to diff against the model, |
|
// determining if there *would be* a change. |
|
changedAttributes: function(diff) { |
|
if (!diff) return this.hasChanged() ? _.clone(this.changed) : false; |
|
var val, changed = false, old = this._previousAttributes; |
|
for (var attr in diff) { |
|
if (_.isEqual(old[attr], (val = diff[attr]))) continue; |
|
(changed || (changed = {}))[attr] = val; |
|
} |
|
return changed; |
|
}, |
|
|
|
// Get the previous value of an attribute, recorded at the time the last |
|
// `"change"` event was fired. |
|
previous: function(attr) { |
|
if (attr == null || !this._previousAttributes) return null; |
|
return this._previousAttributes[attr]; |
|
}, |
|
|
|
// Get all of the attributes of the model at the time of the previous |
|
// `"change"` event. |
|
previousAttributes: function() { |
|
return _.clone(this._previousAttributes); |
|
}, |
|
|
|
// Check if the model is currently in a valid state. It's only possible to |
|
// get into an *invalid* state if you're using silent changes. |
|
isValid: function(options) { |
|
return !this.validate || !this.validate(this.attributes, options); |
|
}, |
|
|
|
// Run validation against the next complete set of model attributes, |
|
// returning `true` if all is well. If a specific `error` callback has |
|
// been passed, call that instead of firing the general `"error"` event. |
|
_validate: function(attrs, options) { |
|
if (options && options.silent || !this.validate) return true; |
|
attrs = _.extend({}, this.attributes, attrs); |
|
var error = this.validate(attrs, options); |
|
if (!error) return true; |
|
if (options && options.error) options.error(this, error, options); |
|
this.trigger('error', this, error, options); |
|
return false; |
|
} |
|
|
|
}); |
|
|
|
// Backbone.Collection |
|
// ------------------- |
|
|
|
// Provides a standard collection class for our sets of models, ordered |
|
// or unordered. If a `comparator` is specified, the Collection will maintain |
|
// its models in sort order, as they're added and removed. |
|
var Collection = Backbone.Collection = function(models, options) { |
|
options || (options = {}); |
|
if (options.model) this.model = options.model; |
|
if (options.comparator !== void 0) this.comparator = options.comparator; |
|
this._reset(); |
|
this.initialize.apply(this, arguments); |
|
if (models) { |
|
if (options.parse) models = this.parse(models); |
|
this.reset(models, {silent: true, parse: options.parse}); |
|
} |
|
}; |
|
|
|
// Define the Collection's inheritable methods. |
|
_.extend(Collection.prototype, Events, { |
|
|
|
// The default model for a collection is just a **Backbone.Model**. |
|
// This should be overridden in most cases. |
|
model: Model, |
|
|
|
// Initialize is an empty function by default. Override it with your own |
|
// initialization logic. |
|
initialize: function(){}, |
|
|
|
// The JSON representation of a Collection is an array of the |
|
// models' attributes. |
|
toJSON: function(options) { |
|
return this.map(function(model){ return model.toJSON(options); }); |
|
}, |
|
|
|
// Proxy `Backbone.sync` by default. |
|
sync: function() { |
|
return Backbone.sync.apply(this, arguments); |
|
}, |
|
|
|
// Add a model, or list of models to the set. Pass **silent** to avoid |
|
// firing the `add` event for every new model. |
|
add: function(models, options) { |
|
var i, args, length, model, existing; |
|
var at = options && options.at; |
|
models = _.isArray(models) ? models.slice() : [models]; |
|
|
|
// Begin by turning bare objects into model references, and preventing |
|
// invalid models from being added. |
|
for (i = 0, length = models.length; i < length; i++) { |
|
if (models[i] = this._prepareModel(models[i], options)) continue; |
|
throw new Error("Can't add an invalid model to a collection"); |
|
} |
|
|
|
for (i = models.length - 1; i >= 0; i--) { |
|
model = models[i]; |
|
existing = model.id != null && this._byId[model.id]; |
|
|
|
// If a duplicate is found, splice it out and optionally merge it into |
|
// the existing model. |
|
if (existing || this._byCid[model.cid]) { |
|
if (options && options.merge && existing) { |
|
existing.set(model, options); |
|
} |
|
models.splice(i, 1); |
|
continue; |
|
} |
|
|
|
// Listen to added models' events, and index models for lookup by |
|
// `id` and by `cid`. |
|
model.on('all', this._onModelEvent, this); |
|
this._byCid[model.cid] = model; |
|
if (model.id != null) this._byId[model.id] = model; |
|
} |
|
|
|
// Update `length` and splice in new models. |
|
this.length += models.length; |
|
args = [at != null ? at : this.models.length, 0]; |
|
push.apply(args, models); |
|
splice.apply(this.models, args); |
|
|
|
// Sort the collection if appropriate. |
|
if (this.comparator && at == null) this.sort({silent: true}); |
|
|
|
if (options && options.silent) return this; |
|
|
|
// Trigger `add` events. |
|
while (model = models.shift()) { |
|
model.trigger('add', model, this, options); |
|
} |
|
|
|
return this; |
|
}, |
|
|
|
// Remove a model, or a list of models from the set. Pass silent to avoid |
|
// firing the `remove` event for every model removed. |
|
remove: function(models, options) { |
|
var i, l, index, model; |
|
options || (options = {}); |
|
models = _.isArray(models) ? models.slice() : [models]; |
|
for (i = 0, l = models.length; i < l; i++) { |
|
model = this.getByCid(models[i]) || this.get(models[i]); |
|
if (!model) continue; |
|
delete this._byId[model.id]; |
|
delete this._byCid[model.cid]; |
|
index = this.indexOf(model); |
|
this.models.splice(index, 1); |
|
this.length--; |
|
if (!options.silent) { |
|
options.index = index; |
|
model.trigger('remove', model, this, options); |
|
} |
|
this._removeReference(model); |
|
} |
|
return this; |
|
}, |
|
|
|
// Add a model to the end of the collection. |
|
push: function(model, options) { |
|
model = this._prepareModel(model, options); |
|
this.add(model, options); |
|
return model; |
|
}, |
|
|
|
// Remove a model from the end of the collection. |
|
pop: function(options) { |
|
var model = this.at(this.length - 1); |
|
this.remove(model, options); |
|
return model; |
|
}, |
|
|
|
// Add a model to the beginning of the collection. |
|
unshift: function(model, options) { |
|
model = this._prepareModel(model, options); |
|
this.add(model, _.extend({at: 0}, options)); |
|
return model; |
|
}, |
|
|
|
// Remove a model from the beginning of the collection. |
|
shift: function(options) { |
|
var model = this.at(0); |
|
this.remove(model, options); |
|
return model; |
|
}, |
|
|
|
// Slice out a sub-array of models from the collection. |
|
slice: function(begin, end) { |
|
return this.models.slice(begin, end); |
|
}, |
|
|
|
// Get a model from the set by id. |
|
get: function(id) { |
|
if (id == null) return void 0; |
|
return this._byId[id.id != null ? id.id : id]; |
|
}, |
|
|
|
// Get a model from the set by client id. |
|
getByCid: function(cid) { |
|
return cid && this._byCid[cid.cid || cid]; |
|
}, |
|
|
|
// Get the model at the given index. |
|
at: function(index) { |
|
return this.models[index]; |
|
}, |
|
|
|
// Return models with matching attributes. Useful for simple cases of `filter`. |
|
where: function(attrs) { |
|
if (_.isEmpty(attrs)) return []; |
|
return this.filter(function(model) { |
|
for (var key in attrs) { |
|
if (attrs[key] !== model.get(key)) return false; |
|
} |
|
return true; |
|
}); |
|
}, |
|
|
|
// Force the collection to re-sort itself. You don't need to call this under |
|
// normal circumstances, as the set will maintain sort order as each item |
|
// is added. |
|
sort: function(options) { |
|
if (!this.comparator) { |
|
throw new Error('Cannot sort a set without a comparator'); |
|
} |
|
|
|
if (_.isString(this.comparator) || this.comparator.length === 1) { |
|
this.models = this.sortBy(this.comparator, this); |
|
} else { |
|
this.models.sort(_.bind(this.comparator, this)); |
|
} |
|
|
|
if (!options || !options.silent) this.trigger('reset', this, options); |
|
return this; |
|
}, |
|
|
|
// Pluck an attribute from each model in the collection. |
|
pluck: function(attr) { |
|
return _.invoke(this.models, 'get', attr); |
|
}, |
|
|
|
// When you have more items than you want to add or remove individually, |
|
// you can reset the entire set with a new list of models, without firing |
|
// any `add` or `remove` events. Fires `reset` when finished. |
|
reset: function(models, options) { |
|
for (var i = 0, l = this.models.length; i < l; i++) { |
|
this._removeReference(this.models[i]); |
|
} |
|
this._reset(); |
|
if (models) this.add(models, _.extend({silent: true}, options)); |
|
if (!options || !options.silent) this.trigger('reset', this, options); |
|
return this; |
|
}, |
|
|
|
// Fetch the default set of models for this collection, resetting the |
|
// collection when they arrive. If `add: true` is passed, appends the |
|
// models to the collection instead of resetting. |
|
fetch: function(options) { |
|
options = options ? _.clone(options) : {}; |
|
if (options.parse === void 0) options.parse = true; |
|
var collection = this; |
|
var success = options.success; |
|
options.success = function(resp, status, xhr) { |
|
collection[options.add ? 'add' : 'reset'](collection.parse(resp, xhr), options); |
|
if (success) success(collection, resp, options); |
|
}; |
|
return this.sync('read', this, options); |
|
}, |
|
|
|
// Create a new instance of a model in this collection. Add the model to the |
|
// collection immediately, unless `wait: true` is passed, in which case we |
|
// wait for the server to agree. |
|
create: function(model, options) { |
|
var collection = this; |
|
options = options ? _.clone(options) : {}; |
|
model = this._prepareModel(model, options); |
|
if (!model) return false; |
|
if (!options.wait) collection.add(model, options); |
|
var success = options.success; |
|
options.success = function(model, resp, options) { |
|
if (options.wait) collection.add(model, options); |
|
if (success) success(model, resp, options); |
|
}; |
|
model.save(null, options); |
|
return model; |
|
}, |
|
|
|
// **parse** converts a response into a list of models to be added to the |
|
// collection. The default implementation is just to pass it through. |
|
parse: function(resp, xhr) { |
|
return resp; |
|
}, |
|
|
|
// Create a new collection with an identical list of models as this one. |
|
clone: function() { |
|
return new this.constructor(this.models); |
|
}, |
|
|
|
// Proxy to _'s chain. Can't be proxied the same way the rest of the |
|
// underscore methods are proxied because it relies on the underscore |
|
// constructor. |
|
chain: function() { |
|
return _(this.models).chain(); |
|
}, |
|
|
|
// Reset all internal state. Called when the collection is reset. |
|
_reset: function(options) { |
|
this.length = 0; |
|
this.models = []; |
|
this._byId = {}; |
|
this._byCid = {}; |
|
}, |
|
|
|
// Prepare a model or hash of attributes to be added to this collection. |
|
_prepareModel: function(attrs, options) { |
|
if (attrs instanceof Model) { |
|
if (!attrs.collection) attrs.collection = this; |
|
return attrs; |
|
} |
|
options || (options = {}); |
|
options.collection = this; |
|
var model = new this.model(attrs, options); |
|
if (!model._validate(model.attributes, options)) return false; |
|
return model; |
|
}, |
|
|
|
// Internal method to remove a model's ties to a collection. |
|
_removeReference: function(model) { |
|
if (this === model.collection) delete model.collection; |
|
model.off('all', this._onModelEvent, this); |
|
}, |
|
|
|
// Internal method called every time a model in the set fires an event. |
|
// Sets need to update their indexes when models change ids. All other |
|
// events simply proxy through. "add" and "remove" events that originate |
|
// in other collections are ignored. |
|
_onModelEvent: function(event, model, collection, options) { |
|
if ((event === 'add' || event === 'remove') && collection !== this) return; |
|
if (event === 'destroy') this.remove(model, options); |
|
if (model && event === 'change:' + model.idAttribute) { |
|
delete this._byId[model.previous(model.idAttribute)]; |
|
if (model.id != null) this._byId[model.id] = model; |
|
} |
|
this.trigger.apply(this, arguments); |
|
} |
|
|
|
}); |
|
|
|
// Underscore methods that we want to implement on the Collection. |
|
var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl', |
|
'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select', |
|
'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke', |
|
'max', 'min', 'sortedIndex', 'toArray', 'size', 'first', 'head', 'take', |
|
'initial', 'rest', 'tail', 'last', 'without', 'indexOf', 'shuffle', |
|
'lastIndexOf', 'isEmpty']; |
|
|
|
// Mix in each Underscore method as a proxy to `Collection#models`. |
|
_.each(methods, function(method) { |
|
Collection.prototype[method] = function() { |
|
var args = slice.call(arguments); |
|
args.unshift(this.models); |
|
return _[method].apply(_, args); |
|
}; |
|
}); |
|
|
|
// Underscore methods that take a property name as an argument. |
|
var attributeMethods = ['groupBy', 'countBy', 'sortBy']; |
|
|
|
// Use attributes instead of properties. |
|
_.each(attributeMethods, function(method) { |
|
Collection.prototype[method] = function(value, context) { |
|
var iterator = _.isFunction(value) ? value : function(model) { |
|
return model.get(value); |
|
}; |
|
return _[method](this.models, iterator, context); |
|
}; |
|
}); |
|
|
|
// Backbone.Router |
|
// ------------------- |
|
|
|
// Routers map faux-URLs to actions, and fire events when routes are |
|
// matched. Creating a new one sets its `routes` hash, if not set statically. |
|
var Router = Backbone.Router = function(options) { |
|
options || (options = {}); |
|
if (options.routes) this.routes = options.routes; |
|
this._bindRoutes(); |
|
this.initialize.apply(this, arguments); |
|
}; |
|
|
|
// Cached regular expressions for matching named param parts and splatted |
|
// parts of route strings. |
|
var optionalParam = /\((.*?)\)/g; |
|
var namedParam = /:\w+/g; |
|
var splatParam = /\*\w+/g; |
|
var escapeRegExp = /[-{}[\]+?.,\\^$|#\s]/g; |
|
|
|
// Set up all inheritable **Backbone.Router** properties and methods. |
|
_.extend(Router.prototype, Events, { |
|
|
|
// Initialize is an empty function by default. Override it with your own |
|
// initialization logic. |
|
initialize: function(){}, |
|
|
|
// Manually bind a single named route to a callback. For example: |
|
// |
|
// this.route('search/:query/p:num', 'search', function(query, num) { |
|
// ... |
|
// }); |
|
// |
|
route: function(route, name, callback) { |
|
if (!_.isRegExp(route)) route = this._routeToRegExp(route); |
|
if (!callback) callback = this[name]; |
|
Backbone.history.route(route, _.bind(function(fragment) { |
|
var args = this._extractParameters(route, fragment); |
|
callback && callback.apply(this, args); |
|
this.trigger.apply(this, ['route:' + name].concat(args)); |
|
Backbone.history.trigger('route', this, name, args); |
|
}, this)); |
|
return this; |
|
}, |
|
|
|
// Simple proxy to `Backbone.history` to save a fragment into the history. |
|
navigate: function(fragment, options) { |
|
Backbone.history.navigate(fragment, options); |
|
return this; |
|
}, |
|
|
|
// Bind all defined routes to `Backbone.history`. We have to reverse the |
|
// order of the routes here to support behavior where the most general |
|
// routes can be defined at the bottom of the route map. |
|
_bindRoutes: function() { |
|
if (!this.routes) return; |
|
var routes = []; |
|
for (var route in this.routes) { |
|
routes.unshift([route, this.routes[route]]); |
|
} |
|
for (var i = 0, l = routes.length; i < l; i++) { |
|
this.route(routes[i][0], routes[i][1], this[routes[i][1]]); |
|
} |
|
}, |
|
|
|
// Convert a route string into a regular expression, suitable for matching |
|
// against the current location hash. |
|
_routeToRegExp: function(route) { |
|
route = route.replace(escapeRegExp, '\\$&') |
|
.replace(optionalParam, '(?:$1)?') |
|
.replace(namedParam, '([^\/]+)') |
|
.replace(splatParam, '(.*?)'); |
|
return new RegExp('^' + route + '$'); |
|
}, |
|
|
|
// Given a route, and a URL fragment that it matches, return the array of |
|
// extracted parameters. |
|
_extractParameters: function(route, fragment) { |
|
return route.exec(fragment).slice(1); |
|
} |
|
|
|
}); |
|
|
|
// Backbone.History |
|
// ---------------- |
|
|
|
// Handles cross-browser history management, based on URL fragments. If the |
|
// browser does not support `onhashchange`, falls back to polling. |
|
var History = Backbone.History = function() { |
|
this.handlers = []; |
|
_.bindAll(this, 'checkUrl'); |
|
|
|
// #1653 - Ensure that `History` can be used outside of the browser. |
|
if (typeof window !== 'undefined') { |
|
this.location = window.location; |
|
this.history = window.history; |
|
} |
|
}; |
|
|
|
// Cached regex for cleaning leading hashes and slashes. |
|
var routeStripper = /^[#\/]/; |
|
|
|
// Cached regex for stripping leading and trailing slashes. |
|
var rootStripper = /^\/+|\/+$/g; |
|
|
|
// Cached regex for detecting MSIE. |
|
var isExplorer = /msie [\w.]+/; |
|
|
|
// Cached regex for removing a trailing slash. |
|
var trailingSlash = /\/$/; |
|
|
|
// Has the history handling already been started? |
|
History.started = false; |
|
|
|
// Set up all inheritable **Backbone.History** properties and methods. |
|
_.extend(History.prototype, Events, { |
|
|
|
// The default interval to poll for hash changes, if necessary, is |
|
// twenty times a second. |
|
interval: 50, |
|
|
|
// Gets the true hash value. Cannot use location.hash directly due to bug |
|
// in Firefox where location.hash will always be decoded. |
|
getHash: function(window) { |
|
var match = (window || this).location.href.match(/#(.*)$/); |
|
return match ? match[1] : ''; |
|
}, |
|
|
|
// Get the cross-browser normalized URL fragment, either from the URL, |
|
// the hash, or the override. |
|
getFragment: function(fragment, forcePushState) { |
|
if (fragment == null) { |
|
if (this._hasPushState || !this._wantsHashChange || forcePushState) { |
|
fragment = this.location.pathname; |
|
var root = this.root.replace(trailingSlash, ''); |
|
if (!fragment.indexOf(root)) fragment = fragment.substr(root.length); |
|
} else { |
|
fragment = this.getHash(); |
|
} |
|
} |
|
return decodeURIComponent(fragment.replace(routeStripper, '')); |
|
}, |
|
|
|
// Start the hash change handling, returning `true` if the current URL matches |
|
// an existing route, and `false` otherwise. |
|
start: function(options) { |
|
if (History.started) throw new Error("Backbone.history has already been started"); |
|
History.started = true; |
|
|
|
// Figure out the initial configuration. Do we need an iframe? |
|
// Is pushState desired ... is it available? |
|
this.options = _.extend({}, {root: '/'}, this.options, options); |
|
this.root = this.options.root; |
|
this._wantsHashChange = this.options.hashChange !== false; |
|
this._wantsPushState = !!this.options.pushState; |
|
this._hasPushState = !!(this.options.pushState && this.history && this.history.pushState); |
|
var fragment = this.getFragment(); |
|
var docMode = document.documentMode; |
|
var oldIE = (isExplorer.exec(navigator.userAgent.toLowerCase()) && (!docMode || docMode <= 7)); |
|
|
|
// Normalize root to always include a leading and trailing slash. |
|
this.root = ('/' + this.root + '/').replace(rootStripper, '/'); |
|
|
|
if (oldIE && this._wantsHashChange) { |
|
this.iframe = Backbone.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow; |
|
this.navigate(fragment); |
|
} |
|
|
|
// Depending on whether we're using pushState or hashes, and whether |
|
// 'onhashchange' is supported, determine how we check the URL state. |
|
if (this._hasPushState) { |
|
Backbone.$(window).bind('popstate', this.checkUrl); |
|
} else if (this._wantsHashChange && ('onhashchange' in window) && !oldIE) { |
|
Backbone.$(window).bind('hashchange', this.checkUrl); |
|
} else if (this._wantsHashChange) { |
|
this._checkUrlInterval = setInterval(this.checkUrl, this.interval); |
|
} |
|
|
|
// Determine if we need to change the base url, for a pushState link |
|
// opened by a non-pushState browser. |
|
this.fragment = fragment; |
|
var loc = this.location; |
|
var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root; |
|
|
|
// If we've started off with a route from a `pushState`-enabled browser, |
|
// but we're currently in a browser that doesn't support it... |
|
if (this._wantsHashChange && this._wantsPushState && !this._hasPushState && !atRoot) { |
|
this.fragment = this.getFragment(null, true); |
|
this.location.replace(this.root + this.location.search + '#' + this.fragment); |
|
// Return immediately as browser will do redirect to new url |
|
return true; |
|
|
|
// Or if we've started out with a hash-based route, but we're currently |
|
// in a browser where it could be `pushState`-based instead... |
|
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) { |
|
this.fragment = this.getHash().replace(routeStripper, ''); |
|
this.history.replaceState({}, document.title, this.root + this.fragment + loc.search); |
|
} |
|
|
|
if (!this.options.silent) return this.loadUrl(); |
|
}, |
|
|
|
// Disable Backbone.history, perhaps temporarily. Not useful in a real app, |
|
// but possibly useful for unit testing Routers. |
|
stop: function() { |
|
Backbone.$(window).unbind('popstate', this.checkUrl).unbind('hashchange', this.checkUrl); |
|
clearInterval(this._checkUrlInterval); |
|
History.started = false; |
|
}, |
|
|
|
// Add a route to be tested when the fragment changes. Routes added later |
|
// may override previous routes. |
|
route: function(route, callback) { |
|
this.handlers.unshift({route: route, callback: callback}); |
|
}, |
|
|
|
// Checks the current URL to see if it has changed, and if it has, |
|
// calls `loadUrl`, normalizing across the hidden iframe. |
|
checkUrl: function(e) { |
|
var current = this.getFragment(); |
|
if (current === this.fragment && this.iframe) { |
|
current = this.getFragment(this.getHash(this.iframe)); |
|
} |
|
if (current === this.fragment) return false; |
|
if (this.iframe) this.navigate(current); |
|
this.loadUrl() || this.loadUrl(this.getHash()); |
|
}, |
|
|
|
// Attempt to load the current URL fragment. If a route succeeds with a |
|
// match, returns `true`. If no defined routes matches the fragment, |
|
// returns `false`. |
|
loadUrl: function(fragmentOverride) { |
|
var fragment = this.fragment = this.getFragment(fragmentOverride); |
|
var matched = _.any(this.handlers, function(handler) { |
|
if (handler.route.test(fragment)) { |
|
handler.callback(fragment); |
|
return true; |
|
} |
|
}); |
|
return matched; |
|
}, |
|
|
|
// Save a fragment into the hash history, or replace the URL state if the |
|
// 'replace' option is passed. You are responsible for properly URL-encoding |
|
// the fragment in advance. |
|
// |
|
// The options object can contain `trigger: true` if you wish to have the |
|
// route callback be fired (not usually desirable), or `replace: true`, if |
|
// you wish to modify the current URL without adding an entry to the history. |
|
navigate: function(fragment, options) { |
|
if (!History.started) return false; |
|
if (!options || options === true) options = {trigger: options}; |
|
fragment = this.getFragment(fragment || ''); |
|
if (this.fragment === fragment) return; |
|
this.fragment = fragment; |
|
var url = this.root + fragment; |
|
|
|
// If pushState is available, we use it to set the fragment as a real URL. |
|
if (this._hasPushState) { |
|
this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url); |
|
|
|
// If hash changes haven't been explicitly disabled, update the hash |
|
// fragment to store history. |
|
} else if (this._wantsHashChange) { |
|
this._updateHash(this.location, fragment, options.replace); |
|
if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) { |
|
// Opening and closing the iframe tricks IE7 and earlier to push a |
|
// history entry on hash-tag change. When replace is true, we don't |
|
// want this. |
|
if(!options.replace) this.iframe.document.open().close(); |
|
this._updateHash(this.iframe.location, fragment, options.replace); |
|
} |
|
|
|
// If you've told us that you explicitly don't want fallback hashchange- |
|
// based history, then `navigate` becomes a page refresh. |
|
} else { |
|
return this.location.assign(url); |
|
} |
|
if (options.trigger) this.loadUrl(fragment); |
|
}, |
|
|
|
// Update the hash location, either replacing the current entry, or adding |
|
// a new one to the browser history. |
|
_updateHash: function(location, fragment, replace) { |
|
if (replace) { |
|
var href = location.href.replace(/(javascript:|#).*$/, ''); |
|
location.replace(href + '#' + fragment); |
|
} else { |
|
// #1649 - Some browsers require that `hash` contains a leading #. |
|
location.hash = '#' + fragment; |
|
} |
|
} |
|
|
|
}); |
|
|
|
// Create the default Backbone.history. |
|
Backbone.history = new History; |
|
|
|
// Backbone.View |
|
// ------------- |
|
|
|
// Creating a Backbone.View creates its initial element outside of the DOM, |
|
// if an existing element is not provided... |
|
var View = Backbone.View = function(options) { |
|
this.cid = _.uniqueId('view'); |
|
this._configure(options || {}); |
|
this._ensureElement(); |
|
this.initialize.apply(this, arguments); |
|
this.delegateEvents(); |
|
}; |
|
|
|
// Cached regex to split keys for `delegate`. |
|
var delegateEventSplitter = /^(\S+)\s*(.*)$/; |
|
|
|
// List of view options to be merged as properties. |
|
var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName']; |
|
|
|
// Set up all inheritable **Backbone.View** properties and methods. |
|
_.extend(View.prototype, Events, { |
|
|
|
// The default `tagName` of a View's element is `"div"`. |
|
tagName: 'div', |
|
|
|
// jQuery delegate for element lookup, scoped to DOM elements within the |
|
// current view. This should be prefered to global lookups where possible. |
|
$: function(selector) { |
|
return this.$el.find(selector); |
|
}, |
|
|
|
// Initialize is an empty function by default. Override it with your own |
|
// initialization logic. |
|
initialize: function(){}, |
|
|
|
// **render** is the core function that your view should override, in order |
|
// to populate its element (`this.el`), with the appropriate HTML. The |
|
// convention is for **render** to always return `this`. |
|
render: function() { |
|
return this; |
|
}, |
|
|
|
// Clean up references to this view in order to prevent latent effects and |
|
// memory leaks. |
|
dispose: function() { |
|
this.undelegateEvents(); |
|
if (this.model && this.model.off) this.model.off(null, null, this); |
|
if (this.collection && this.collection.off) this.collection.off(null, null, this); |
|
return this; |
|
}, |
|
|
|
// Remove this view from the DOM. Note that the view isn't present in the |
|
// DOM by default, so calling this method may be a no-op. |
|
remove: function() { |
|
this.dispose(); |
|
this.$el.remove(); |
|
return this; |
|
}, |
|
|
|
// For small amounts of DOM Elements, where a full-blown template isn't |
|
// needed, use **make** to manufacture elements, one at a time. |
|
// |
|
// var el = this.make('li', {'class': 'row'}, this.model.escape('title')); |
|
// |
|
make: function(tagName, attributes, content) { |
|
var el = document.createElement(tagName); |
|
if (attributes) Backbone.$(el).attr(attributes); |
|
if (content != null) Backbone.$(el).html(content); |
|
return el; |
|
}, |
|
|
|
// Change the view's element (`this.el` property), including event |
|
// re-delegation. |
|
setElement: function(element, delegate) { |
|
if (this.$el) this.undelegateEvents(); |
|
this.$el = element instanceof Backbone.$ ? element : Backbone.$(element); |
|
this.el = this.$el[0]; |
|
if (delegate !== false) this.delegateEvents(); |
|
return this; |
|
}, |
|
|
|
// Set callbacks, where `this.events` is a hash of |
|
// |
|
// *{"event selector": "callback"}* |
|
// |
|
// { |
|
// 'mousedown .title': 'edit', |
|
// 'click .button': 'save' |
|
// 'click .open': function(e) { ... } |
|
// } |
|
// |
|
// pairs. Callbacks will be bound to the view, with `this` set properly. |
|
// Uses event delegation for efficiency. |
|
// Omitting the selector binds the event to `this.el`. |
|
// This only works for delegate-able events: not `focus`, `blur`, and |
|
// not `change`, `submit`, and `reset` in Internet Explorer. |
|
delegateEvents: function(events) { |
|
if (!(events || (events = _.result(this, 'events')))) return; |
|
this.undelegateEvents(); |
|
for (var key in events) { |
|
var method = events[key]; |
|
if (!_.isFunction(method)) method = this[events[key]]; |
|
if (!method) throw new Error('Method "' + events[key] + '" does not exist'); |
|
var match = key.match(delegateEventSplitter); |
|
var eventName = match[1], selector = match[2]; |
|
method = _.bind(method, this); |
|
eventName += '.delegateEvents' + this.cid; |
|
if (selector === '') { |
|
this.$el.bind(eventName, method); |
|
} else { |
|
this.$el.delegate(selector, eventName, method); |
|
} |
|
} |
|
}, |
|
|
|
// Clears all callbacks previously bound to the view with `delegateEvents`. |
|
// You usually don't need to use this, but may wish to if you have multiple |
|
// Backbone views attached to the same DOM element. |
|
undelegateEvents: function() { |
|
this.$el.unbind('.delegateEvents' + this.cid); |
|
}, |
|
|
|
// Performs the initial configuration of a View with a set of options. |
|
// Keys with special meaning *(model, collection, id, className)*, are |
|
// attached directly to the view. |
|
_configure: function(options) { |
|
if (this.options) options = _.extend({}, this.options, options); |
|
for (var i = 0, l = viewOptions.length; i < l; i++) { |
|
var attr = viewOptions[i]; |
|
if (options[attr]) this[attr] = options[attr]; |
|
} |
|
this.options = options; |
|
}, |
|
|
|
// Ensure that the View has a DOM element to render into. |
|
// If `this.el` is a string, pass it through `$()`, take the first |
|
// matching element, and re-assign it to `el`. Otherwise, create |
|
// an element from the `id`, `className` and `tagName` properties. |
|
_ensureElement: function() { |
|
if (!this.el) { |
|
var attrs = _.extend({}, _.result(this, 'attributes')); |
|
if (this.id) attrs.id = _.result(this, 'id'); |
|
if (this.className) attrs['class'] = _.result(this, 'className'); |
|
this.setElement(this.make(_.result(this, 'tagName'), attrs), false); |
|
} else { |
|
this.setElement(_.result(this, 'el'), false); |
|
} |
|
} |
|
|
|
}); |
|
|
|
// Backbone.sync |
|
// ------------- |
|
|
|
// Map from CRUD to HTTP for our default `Backbone.sync` implementation. |
|
var methodMap = { |
|
'create': 'POST', |
|
'update': 'PUT', |
|
'delete': 'DELETE', |
|
'read': 'GET' |
|
}; |
|
|
|
// Override this function to change the manner in which Backbone persists |
|
// models to the server. You will be passed the type of request, and the |
|
// model in question. By default, makes a RESTful Ajax request |
|
// to the model's `url()`. Some possible customizations could be: |
|
// |
|
// * Use `setTimeout` to batch rapid-fire updates into a single request. |
|
// * Send up the models as XML instead of JSON. |
|
// * Persist models via WebSockets instead of Ajax. |
|
// |
|
// Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests |
|
// as `POST`, with a `_method` parameter containing the true HTTP method, |
|
// as well as all requests with the body as `application/x-www-form-urlencoded` |
|
// instead of `application/json` with the model in a param named `model`. |
|
// Useful when interfacing with server-side languages like **PHP** that make |
|
// it difficult to read the body of `PUT` requests. |
|
Backbone.sync = function(method, model, options) { |
|
var type = methodMap[method]; |
|
|
|
// Default options, unless specified. |
|
options || (options = {}); |
|
|
|
// Default JSON-request options. |
|
var params = {type: type, dataType: 'json'}; |
|
|
|
// Ensure that we have a URL. |
|
if (!options.url) { |
|
params.url = _.result(model, 'url') || urlError(); |
|
} |
|
|
|
// Ensure that we have the appropriate request data. |
|
if (!options.data && model && (method === 'create' || method === 'update')) { |
|
params.contentType = 'application/json'; |
|
params.data = JSON.stringify(model); |
|
} |
|
|
|
// For older servers, emulate JSON by encoding the request into an HTML-form. |
|
if (Backbone.emulateJSON) { |
|
params.contentType = 'application/x-www-form-urlencoded'; |
|
params.data = params.data ? {model: params.data} : {}; |
|
} |
|
|
|
// For older servers, emulate HTTP by mimicking the HTTP method with `_method` |
|
// And an `X-HTTP-Method-Override` header. |
|
if (Backbone.emulateHTTP) { |
|
if (type === 'PUT' || type === 'DELETE') { |
|
if (Backbone.emulateJSON) params.data._method = type; |
|
params.type = 'POST'; |
|
params.beforeSend = function(xhr) { |
|
xhr.setRequestHeader('X-HTTP-Method-Override', type); |
|
}; |
|
} |
|
} |
|
|
|
// Don't process data on a non-GET request. |
|
if (params.type !== 'GET' && !Backbone.emulateJSON) { |
|
params.processData = false; |
|
} |
|
|
|
var success = options.success; |
|
options.success = function(resp, status, xhr) { |
|
if (success) success(resp, status, xhr); |
|
model.trigger('sync', model, resp, options); |
|
}; |
|
|
|
var error = options.error; |
|
options.error = function(xhr, status, thrown) { |
|
if (error) error(model, xhr, options); |
|
model.trigger('error', model, xhr, options); |
|
}; |
|
|
|
// Make the request, allowing the user to override any Ajax options. |
|
return Backbone.ajax(_.extend(params, options)); |
|
}; |
|
|
|
// Set the default implementation of `Backbone.ajax` to proxy through to `$`. |
|
Backbone.ajax = function() { |
|
return Backbone.$.ajax.apply(Backbone.$, arguments); |
|
}; |
|
|
|
// Helpers |
|
// ------- |
|
|
|
// Helper function to correctly set up the prototype chain, for subclasses. |
|
// Similar to `goog.inherits`, but uses a hash of prototype properties and |
|
// class properties to be extended. |
|
var extend = function(protoProps, staticProps) { |
|
var parent = this; |
|
var child; |
|
|
|
// The constructor function for the new subclass is either defined by you |
|
// (the "constructor" property in your `extend` definition), or defaulted |
|
// by us to simply call the parent's constructor. |
|
if (protoProps && _.has(protoProps, 'constructor')) { |
|
child = protoProps.constructor; |
|
} else { |
|
child = function(){ parent.apply(this, arguments); }; |
|
} |
|
|
|
// Add static properties to the constructor function, if supplied. |
|
_.extend(child, parent, staticProps); |
|
|
|
// Set the prototype chain to inherit from `parent`, without calling |
|
// `parent`'s constructor function. |
|
var Surrogate = function(){ this.constructor = child; }; |
|
Surrogate.prototype = parent.prototype; |
|
child.prototype = new Surrogate; |
|
|
|
// Add prototype properties (instance properties) to the subclass, |
|
// if supplied. |
|
if (protoProps) _.extend(child.prototype, protoProps); |
|
|
|
// Set a convenience property in case the parent's prototype is needed |
|
// later. |
|
child.__super__ = parent.prototype; |
|
|
|
return child; |
|
}; |
|
|
|
// Set up inheritance for the model, collection, router, and view. |
|
Model.extend = Collection.extend = Router.extend = View.extend = extend; |
|
|
|
// Throw an error when a URL is needed, and none is supplied. |
|
var urlError = function() { |
|
throw new Error('A "url" property or function must be specified'); |
|
}; |
|
|
|
}).call(this); |
|
|
|
define('backbone', ['backbone/backbone'], function (main) { return main; }); |
|
|
|
define("backbone/backbone", function(){}); |
|
|
|
// Testing module |
|
define('modules/testing',[ |
|
// Application. |
|
"backbone" |
|
], |
|
|
|
// Map dependencies from above array. |
|
function (Backbone) { |
|
console.log(Backbone); |
|
}); |
|
|
|
/*! |
|
* backbone.layoutmanager.js v0.7.1 |
|
* Copyright 2012, Tim Branyen (@tbranyen) |
|
* backbone.layoutmanager.js may be freely distributed under the MIT license. |
|
*/ |
|
(function(window) { |
|
|
|
|
|
|
|
// Hoisted, referenced at the bottom of the source. This caches a list of all |
|
// LayoutManager options at definition time. |
|
var keys; |
|
|
|
// Localize global dependency references. |
|
var Backbone = window.Backbone; |
|
var _ = window._; |
|
var $ = window.$; |
|
|
|
// Maintain references to the two `Backbone.View` functions that are |
|
// overwritten so that they can be proxied. |
|
var _configure = Backbone.View.prototype._configure; |
|
var render = Backbone.View.prototype.render; |
|
|
|
// Cache these methods for performance. |
|
var aPush = Array.prototype.push; |
|
var aConcat = Array.prototype.concat; |
|
var aSplice = Array.prototype.splice; |
|
|
|
// LayoutManager is a wrapper around a `Backbone.View`. |
|
var LayoutManager = Backbone.View.extend({ |
|
// This named function allows for significantly easier debugging. |
|
constructor: function Layout(options) { |
|
// Options may not always be passed to the constructor, this ensures it is |
|
// always an object. |
|
options = options || {}; |
|
|
|
// Grant this View superpowers. |
|
LayoutManager.setupView(this, options); |
|
|
|
// Have Backbone set up the rest of this View. |
|
Backbone.View.call(this, options); |
|
}, |
|
|
|
// Shorthand to `setView` function with the `append` flag set. |
|
insertView: function(selector, view) { |
|
// If the `view` argument exists, then a selector was passed in. This code |
|
// path will forward the selector on to `setView`. |
|
if (view) { |
|
return this.setView(selector, view, true); |
|
} |
|
|
|
// If no `view` argument is defined, then assume the first argument is the |
|
// View, somewhat now confusingly named `selector`. |
|
return this.setView(selector, true); |
|
}, |
|
|
|
// Iterate over an object and ensure every value is wrapped in an array to |
|
// ensure they will be appended, then pass that object to `setViews`. |
|
insertViews: function(views) { |
|
// If an array of views was passed it should be inserted into the |
|
// root view. Much like calling insertView without a selector |
|
if (_.isArray(views)) { |
|
return this.setViews({'': views}); |
|
} |
|
|
|
_.each(views, function(view, selector) { |
|
views[selector] = _.isArray(view) ? view : [view]; |
|
}); |
|
|
|
return this.setViews(views); |
|
}, |
|
|
|
// Returns the View that matches the `getViews` filter function. |
|
getView: function(fn) { |
|
return this.getViews(fn).first().value(); |
|
}, |
|
|
|
// Provide a filter function to get a flattened array of all the subviews. |
|
// If the filter function is omitted it will return all subviews. If a |
|
// String is passed instead, it will return the Views for that selector. |
|
getViews: function(fn) { |
|
// Generate an array of all top level (no deeply nested) Views flattened. |
|
var views = _.chain(this.views).map(function(view) { |
|
return _.isArray(view) ? view : [view]; |
|
}, this).flatten().value(); |
|
|
|
// If the filter argument is a String, then return a chained Version of the |
|
// elements. |
|
if (typeof fn === "string") { |
|
return _.chain([this.views[fn]]).flatten(); |
|
} |
|
|
|
// If a filter function is provided, run it on all Views and return a |
|
// wrapped chain. Otherwise, simply return a wrapped chain of all Views. |
|
return _.chain(typeof fn === "function" ? _.filter(views, fn) : views); |
|
}, |
|
|
|
// This takes in a partial name and view instance and assigns them to |
|
// the internal collection of views. If a view is not a LayoutManager |
|
// instance, then mix in the LayoutManager prototype. This ensures |
|
// all Views can be used successfully. |
|
// |
|
// Must definitely wrap any render method passed in or defaults to a |
|
// typical render function `return layout(this).render()`. |
|
setView: function(name, view, append) { |
|
var manager, existing, options; |
|
// Parent view, the one you are setting a View on. |
|
var root = this; |
|
|
|
// If no name was passed, use an empty string and shift all arguments. |
|
if (typeof name !== "string") { |
|
append = view; |
|
view = name; |
|
name = ""; |
|
} |
|
|
|
// If the parent views object doesn't exist... create it. |
|
this.views = this.views || {}; |
|
|
|
// Shorthand the `__manager__` property. |
|
manager = view.__manager__; |
|
|
|
// Shorthand the View that potentially already exists. |
|
existing = this.views[name]; |
|
|
|
// If the View has not been properly set up, throw an Error message |
|
// indicating that the View needs `manage: true` set. |
|
if (!manager) { |
|
throw new Error("Please set `View#manage` property with selector '" + |
|
name + "' to `true`."); |
|
} |
|
|
|
// Assign options. |
|
options = view._options(); |
|
|
|
// Add reference to the parentView. |
|
manager.parent = root; |
|
|
|
// Add reference to the placement selector used. |
|
manager.selector = name; |
|
|
|
// Code path is less complex for Views that are not being appended. Simply |
|
// remove existing Views and bail out with the assignment. |
|
if (!append) { |
|
// If the View we are adding has already been rendered, simply inject it |
|
// into the parent. |
|
if (manager.hasRendered) { |
|
options.partial(root.el, manager.selector, view.el, manager.append); |
|
} |
|
|
|
// Ensure remove is called when swapping View's. |
|
if (existing) { |
|
// If the views are an array, iterate and remove each individually. |
|
_.each(aConcat.call([], existing), function(nestedView) { |
|
nestedView.remove(); |
|
}); |
|
} |
|
|
|
// Assign to main views object and return for chainability. |
|
return this.views[name] = view; |
|
} |
|
|
|
// Ensure this.views[name] is an array and push this View to the end. |
|
this.views[name] = aConcat.call([], existing || [], view); |
|
|
|
// Put the view into `append` mode. |
|
manager.append = true; |
|
|
|
return view; |
|
}, |
|
|
|
// Allows the setting of multiple views instead of a single view. |
|
setViews: function(views) { |
|
// Iterate over all the views and use the View's view method to assign. |
|
_.each(views, function(view, name) { |
|
// If the view is an array put all views into insert mode. |
|
if (_.isArray(view)) { |
|
return _.each(view, function(view) { |
|
this.insertView(name, view); |
|
}, this); |
|
} |
|
|
|
// Assign each view using the view function. |
|
this.setView(name, view); |
|
}, this); |
|
|
|
// Allow for chaining |
|
return this; |
|
}, |
|
|
|
// By default this should find all nested views and render them into |
|
// the this.el and call done once all of them have successfully been |
|
// resolved. |
|
// |
|
// This function returns a promise that can be chained to determine |
|
// once all subviews and main view have been rendered into the view.el. |
|
render: function() { |
|
var root = this; |
|
var options = root._options(); |
|
var manager = root.__manager__; |
|
var parent = manager.parent; |
|
var rentManager = parent && parent.__manager__; |
|
var def = options.deferred(); |
|
|
|
// Triggered once the render has succeeded. |
|
function resolve() { |
|
var next; |
|
|
|
// If there is a parent, attach. |
|
if (parent) { |
|
if (!options.contains(parent.el, root.el)) { |
|
options.partial(parent.el, manager.selector, root.el, |
|
manager.append); |
|
} |
|
} |
|
|
|
// Ensure events are always correctly bound after rendering. |
|
root.delegateEvents(); |
|
|
|
// Resolve the deferred. |
|
def.resolveWith(root, [root]); |
|
|
|
// Set this View as successfully rendered. |
|
manager.hasRendered = true; |
|
|
|
// Only process the queue if it exists. |
|
if (next = manager.queue.shift()) { |
|
// Ensure that the next render is only called after all other |
|
// `done` handlers have completed. This will prevent `render` |
|
// callbacks from firing out of order. |
|
next(); |
|
} else { |
|
// Once the queue is depleted, remove it, the render process has |
|
// completed. |
|
delete manager.queue; |
|
} |
|
|
|
// Reusable function for triggering the afterRender callback and event |
|
// and setting the hasRendered flag. |
|
function completeRender() { |
|
var afterRender = options.afterRender; |
|
|
|
if (afterRender) { |
|
afterRender.call(root, root); |
|
} |
|
|
|
// Always emit an afterRender event. |
|
root.trigger("afterRender", root); |
|
} |
|
|
|
// Special case for when a parent View that has not been rendered is |
|
// involved. |
|
if (rentManager && !rentManager.hasRendered) { |
|
// Wait until the parent View has finished rendering, which could be |
|
// asynchronous, and trigger afterRender on this View once it has |
|
// compeleted. |
|
return parent.on("afterRender", function() { |
|
// Wish we had `once` for this... |
|
parent.off("afterRender", null, this); |
|
|
|
// Trigger the afterRender and set hasRendered. |
|
completeRender(); |
|
}, root); |
|
} |
|
|
|
// This View and its parent have both rendered. |
|
completeRender(); |
|
} |
|
|
|
// Actually facilitate a render. |
|
function actuallyRender() { |
|
var options = root._options(); |
|
var manager = root.__manager__; |
|
var parent = manager.parent; |
|
var rentManager = parent && parent.__manager__; |
|
|
|
// The `_viewRender` method is broken out to abstract away from having |
|
// too much code in `processRender`. |
|
root._render(LayoutManager._viewRender, options).done(function() { |
|
// If there are no children to worry about, complete the render |
|
// instantly. |
|
if (!_.keys(root.views).length) { |
|
return resolve(); |
|
} |
|
|
|
// Create a list of promises to wait on until rendering is done. |
|
// Since this method will run on all children as well, its sufficient |
|
// for a full hierarchical. |
|
var promises = _.map(root.views, function(view) { |
|
var append = _.isArray(view); |
|
|
|
// If items are being inserted, they will be in a non-zero length |
|
// Array. |
|
if (append && view.length) { |
|
// Only need to wait for the first View to complete, the rest |
|
// will be synchronous, by virtue of having the template cached. |
|
return view[0].render().pipe(function() { |
|
// Map over all the View's to be inserted and call render on |
|
// them all. Once they have all resolved, resolve the other |
|
// deferred. |
|
return options.when(_.map(view.slice(1), function(insertView) { |
|
return insertView.render(); |
|
})); |
|
}); |
|
} |
|
|
|
// Only return the fetch deferred, resolve the main deferred after |
|
// the element has been attached to it's parent. |
|
return !append ? view.render() : view; |
|
}); |
|
|
|
// Once all nested Views have been rendered, resolve this View's |
|
// deferred. |
|
options.when(promises).done(function() { |
|
resolve(); |
|
}); |
|
}); |
|
} |
|
|
|
// Another render is currently happening if there is an existing queue, so |
|
// push a closure to render later into the queue. |
|
if (manager.queue) { |
|
aPush.call(manager.queue, function() { |
|
actuallyRender(); |
|
}); |
|
} else { |
|
manager.queue = []; |
|
|
|
// This the first `render`, preceeding the `queue` so render |
|
// immediately. |
|
actuallyRender(root, def); |
|
} |
|
|
|
// Add the View to the deferred so that `view.render().view.el` is |
|
// possible. |
|
def.view = root; |
|
|
|
// This is the promise that determines if the `render` function has |
|
// completed or not. |
|
return def; |
|
}, |
|
|
|
// Ensure the cleanup function is called whenever remove is called. |
|
remove: function() { |
|
// Force remove itself from its parent. |
|
LayoutManager._removeView(this, true); |
|
|
|
// Call the original remove function. |
|
return this._remove.apply(this, arguments); |
|
}, |
|
|
|
// Merge instance and global options. |
|
_options: function() { |
|
// Instance overrides take precedence, fallback to prototype options. |
|
return _.extend({}, this, LayoutManager.prototype.options, this.options); |
|
} |
|
}, |
|
{ |
|
// Clearable cache. |
|
_cache: {}, |
|
|
|
// Creates a deferred and returns a function to call when finished. |
|
_makeAsync: function(options, done) { |
|
var handler = options.deferred(); |
|
|
|
// Used to handle asynchronous renders. |
|
handler.async = function() { |
|
handler._isAsync = true; |
|
|
|
return done; |
|
}; |
|
|
|
return handler; |
|
}, |
|
|
|
// This gets passed to all _render methods. The `root` value here is passed |
|
// from the `manage(this).render()` line in the `_render` function |
|
_viewRender: function(root, options) { |
|
var url, contents, fetchAsync; |
|
var manager = root.__manager__; |
|
|
|
// This function is responsible for pairing the rendered template into |
|
// the DOM element. |
|
function applyTemplate(rendered) { |
|
// Actually put the rendered contents into the element. |
|
if (rendered) { |
|
options.html(root.el, rendered); |
|
} |
|
|
|
// Resolve only after fetch and render have succeeded. |
|
fetchAsync.resolveWith(root, [root]); |
|
} |
|
|
|
// Once the template is successfully fetched, use its contents to proceed. |
|
// Context argument is first, since it is bound for partial application |
|
// reasons. |
|
function done(context, contents) { |
|
// Store the rendered template someplace so it can be re-assignable. |
|
var rendered; |
|
// This allows the `render` method to be asynchronous as well as `fetch`. |
|
var renderAsync = LayoutManager._makeAsync(options, function(rendered) { |
|
applyTemplate(rendered); |
|
}); |
|
|
|
// Ensure the cache is up-to-date. |
|
LayoutManager.cache(url, contents); |
|
|
|
// Render the View into the el property. |
|
if (contents) { |
|
rendered = options.render.call(renderAsync, contents, context); |
|
} |
|
|
|
// If the function was synchronous, continue execution. |
|
if (!renderAsync._isAsync) { |
|
applyTemplate(rendered); |
|
} |
|
} |
|
|
|
return { |
|
// This `render` function is what gets called inside of the View render, |
|
// when `manage(this).render` is called. Returns a promise that can be |
|
// used to know when the element has been rendered into its parent. |
|
render: function() { |
|
var context; |
|
var data = options.data || options.serialize; |
|
var template = root.template || options.template; |
|
|
|
// If data is a function, immediately call it. |
|
if (_.isFunction(data)) { |
|
data = data.call(root); |
|
} |
|
|
|
// This allows for `var done = this.async()` and then `done(contents)`. |
|
fetchAsync = LayoutManager._makeAsync(options, function(contents) { |
|
done(data, contents); |
|
}); |
|
|
|
// Set the url to the prefix + the view's template property. |
|
if (typeof template === "string") { |
|
url = options.prefix + template; |
|
} |
|
|
|
// Check if contents are already cached and if they are, simply process |
|
// the template with the correct data. |
|
if (contents = LayoutManager.cache(url)) { |
|
done(data, contents, url); |
|
|
|
return fetchAsync; |
|
} |
|
|
|
// Fetch layout and template contents. |
|
if (typeof template === "string") { |
|
contents = options.fetch.call(fetchAsync, options.prefix + template); |
|
// If its not a string just pass the object/function/whatever. |
|
} else if (template != null) { |
|
contents = options.fetch.call(fetchAsync, template); |
|
} |
|
|
|
// If the function was synchronous, continue execution. |
|
if (!fetchAsync._isAsync) { |
|
done(data, contents); |
|
} |
|
|
|
return fetchAsync; |
|
} |
|
}; |
|
}, |
|
|
|
// Remove all nested Views. |
|
_removeViews: function(root, force) { |
|
// Shift arguments around. |
|
if (typeof root === "boolean") { |
|
force = root; |
|
root = this; |
|
} |
|
|
|
// Allow removeView to be called on instances. |
|
root = root || this; |
|
|
|
// Iterate over all of the nested View's and remove. |
|
root.getViews().each(function(view) { |
|
// Force doesn't care about if a View has rendered or not. |
|
if (view.__manager__.hasRendered || force) { |
|
LayoutManager._removeView(view, force); |
|
} |
|
}); |
|
}, |
|
|
|
// Remove a single nested View. |
|
_removeView: function(view, force) { |
|
var parentViews; |
|
// Shorthand the manager for easier access. |
|
var manager = view.__manager__; |
|
// Test for keep. |
|
var keep = typeof view.keep === "boolean" ? view.keep : view.options.keep; |
|
|
|
// Only remove views that do not have `keep` attribute set, unless the |
|
// View is in `append` mode and the force flag is set. |
|
if (!keep && (manager.append === true || force)) { |
|
// Clean out the events. |
|
LayoutManager.cleanViews(view); |
|
|
|
// Since we are removing this view, force subviews to remove |
|
view._removeViews(true); |
|
|
|
// Remove the View completely. |
|
view.$el.remove(); |
|
|
|
// Bail out early if no parent exists. |
|
if (!manager.parent) { return; } |
|
|
|
// Assign (if they exist) the sibling Views to a property. |
|
parentViews = manager.parent.views[manager.selector]; |
|
|
|
// If this is an array of items remove items that are not marked to |
|
// keep. |
|
if (_.isArray(parentViews)) { |
|
// Remove duplicate Views. |
|
return _.each(_.clone(parentViews), function(view, i) { |
|
// If the managers match, splice off this View. |
|
if (view && view.__manager__ === manager) { |
|
aSplice.call(parentViews, i, 1); |
|
} |
|
}); |
|
} |
|
|
|
// Otherwise delete the parent selector. |
|
delete manager.parent.views[manager.selector]; |
|
} |
|
}, |
|
|
|
// Accept either a single view or an array of views to clean of all DOM |
|
// events internal model and collection references and all Backbone.Events. |
|
cleanViews: function(views) { |
|
// Clear out all existing views. |
|
_.each(aConcat.call([], views), function(view) { |
|
// Remove all custom events attached to this View. |
|
view.unbind(); |
|
|
|
// Automatically unbind `model`. |
|
if (view.model instanceof Backbone.Model) { |
|
view.model.off(null, null, view); |
|
} |
|
|
|
// Automatically unbind `collection`. |
|
if (view.collection instanceof Backbone.Collection) { |
|
view.collection.off(null, null, view); |
|
} |
|
|
|
// If a custom cleanup method was provided on the view, call it after |
|
// the initial cleanup is done |
|
if (view.cleanup) { |
|
view.cleanup.call(view); |
|
} |
|
}); |
|
}, |
|
|
|
// Cache templates into LayoutManager._cache. |
|
cache: function(path, contents) { |
|
// If template path is found in the cache, return the contents. |
|
if (path in this._cache) { |
|
return this._cache[path]; |
|
// Ensure path and contents aren't undefined. |
|
} else if (path != null && contents != null) { |
|
return this._cache[path] = contents; |
|
} |
|
|
|
// If the template is not in the cache, return undefined. |
|
}, |
|
|
|
// This static method allows for global configuration of LayoutManager. |
|
configure: function(opts) { |
|
_.extend(LayoutManager.prototype.options, opts); |
|
|
|
// Allow LayoutManager to manage Backbone.View.prototype. |
|
if (opts.manage) { |
|
Backbone.View.prototype.manage = true; |
|
} |
|
}, |
|
|
|
// Configure a View to work with the LayoutManager plugin. |
|
setupView: function(view, options) { |
|
// If the View has already been setup, no need to do it again. |
|
if (view.__manager__) { |
|
return; |
|
} |
|
|
|
var views, declaredViews, viewOptions; |
|
var proto = Backbone.LayoutManager.prototype; |
|
var viewOverrides = _.pick(view, keys); |
|
|
|
// Ensure necessary properties are set. |
|
_.defaults(view, { |
|
// Ensure a view always has a views object. |
|
views: {}, |
|
|
|
// Internal state object used to store whether or not a View has been |
|
// taken over by layout manager and if it has been rendered into the DOM. |
|
__manager__: {}, |
|
|
|
// Add the ability to remove all Views. |
|
_removeViews: LayoutManager._removeViews, |
|
|
|
// Add the ability to remove itself. |
|
_removeView: LayoutManager._removeView |
|
|
|
// Mix in all LayoutManager prototype properties as well. |
|
}, LayoutManager.prototype); |
|
|
|
// Extend the options with the prototype and passed options. |
|
options = view.options = _.defaults(options || {}, view.options, |
|
proto.options); |
|
|
|
// Ensure view events are properly copied over. |
|
viewOptions = _.pick(options, aConcat.call(["events"], |
|
_.values(options.events))); |
|
|
|
// Merge the View options into the View. |
|
_.extend(view, viewOptions); |
|
|
|
// If the View still has the Backbone.View#render method, remove it. Don't |
|
// want it accidentally overriding the LM render. |
|
if (viewOverrides.render === LayoutManager.prototype.render || |
|
viewOverrides.render === Backbone.View.prototype.render) { |
|
delete viewOverrides.render; |
|
} |
|
|
|
// Pick out the specific properties that can be dynamically added at |
|
// runtime and ensure they are available on the view object. |
|
_.extend(options, viewOverrides); |
|
|
|
// By default the original Remove function is the Backbone.View one. |
|
view._remove = Backbone.View.prototype.remove; |
|
|
|
// Always use this render function when using LayoutManager. |
|
view._render = function(manage, options) { |
|
// Keep the view consistent between callbacks and deferreds. |
|
var view = this; |
|
// Shorthand the manager. |
|
var manager = view.__manager__; |
|
// Cache these properties. |
|
var beforeRender = options.beforeRender; |
|
|
|
// Ensure all nested Views are properly scrubbed if re-rendering. |
|
if (manager.hasRendered) { |
|
this._removeViews(); |
|
} |
|
|
|
// If a beforeRender function is defined, call it. |
|
if (beforeRender) { |
|
beforeRender.call(this, this); |
|
} |
|
|
|
// Always emit a beforeRender event. |
|
this.trigger("beforeRender", this); |
|
|
|
// Render! |
|
return manage(this, options).render(); |
|
}; |
|
|
|
// Ensure the render is always set correctly. |
|
view.render = LayoutManager.prototype.render; |
|
|
|
// If the user provided their own remove override, use that instead of the |
|
// default. |
|
if (view.remove !== proto.remove) { |
|
view._remove = view.remove; |
|
view.remove = proto.remove; |
|
} |
|
|
|
// Normalize views to exist on either instance or options, default to |
|
// options. |
|
views = options.views || view.views; |
|
|
|
// Set the internal views, only if selectors have been provided. |
|
if (_.keys(views).length) { |
|
// Keep original object declared containing Views. |
|
declaredViews = views; |
|
|
|
// Reset the property to avoid duplication or overwritting. |
|
view.views = {}; |
|
|
|
// Set the declared Views. |
|
view.setViews(declaredViews); |
|
} |
|
|
|
// If a template is passed use that instead. |
|
if (view.options.template) { |
|
view.options.template = options.template; |
|
// Ensure the template is mapped over. |
|
} else if (view.template) { |
|
options.template = view.template; |
|
|
|
// Remove it from the instance. |
|
delete view.template; |
|
} |
|
} |
|
}); |
|
|
|
// Convenience assignment to make creating Layout's slightly shorter. |
|
Backbone.Layout = Backbone.LayoutView = Backbone.LayoutManager = LayoutManager; |
|
// Tack on the version. |
|
LayoutManager.VERSION = "0.7.1"; |
|
|
|
// Override _configure to provide extra functionality that is necessary in |
|
// order for the render function reference to be bound during initialize. |
|
Backbone.View.prototype._configure = function() { |
|
// Run the original _configure. |
|
var retVal = _configure.apply(this, arguments); |
|
|
|
// If manage is set, do it! |
|
if (this.manage) { |
|
// Set up this View. |
|
LayoutManager.setupView(this); |
|
} |
|
|
|
// Act like nothing happened. |
|
return retVal; |
|
}; |
|
|
|
// Default configuration options; designed to be overriden. |
|
LayoutManager.prototype.options = { |
|
// Prefix template/layout paths. |
|
prefix: "", |
|
|
|
// Can be used to supply a different deferred implementation. |
|
deferred: function() { |
|
return $.Deferred(); |
|
}, |
|
|
|
// Fetch is passed a path and is expected to return template contents as a |
|
// function or string. |
|
fetch: function(path) { |
|
return _.template($(path).html()); |
|
}, |
|
|
|
// This is the most common way you will want to partially apply a view into |
|
// a layout. |
|
partial: function(root, name, el, append) { |
|
// If no selector is specified, assume the parent should be added to. |
|
var $root = name ? $(root).find(name) : $(root); |
|
|
|
// Use the append method if append argument is true. |
|
this[append ? "append" : "html"]($root, el); |
|
}, |
|
|
|
// Override this with a custom HTML method, passed a root element and an |
|
// element to replace the innerHTML with. |
|
html: function(root, el) { |
|
$(root).html(el); |
|
}, |
|
|
|
// Very similar to HTML except this one will appendChild. |
|
append: function(root, el) { |
|
$(root).append(el); |
|
}, |
|
|
|
// Return a deferred for when all promises resolve/reject. |
|
when: function(promises) { |
|
return $.when.apply(null, promises); |
|
}, |
|
|
|
// By default, render using underscore's templating. |
|
render: function(template, context) { |
|
return template(context); |
|
}, |
|
|
|
// A method to determine if a View contains another. |
|
contains: function(parent, child) { |
|
return $.contains(parent, child); |
|
} |
|
}; |
|
|
|
// Maintain a list of the keys at define time. |
|
keys = _.keys(LayoutManager.prototype.options); |
|
|
|
})(this); |
|
|
|
|
|
define('backbone.layoutmanager', ['backbone.layoutmanager/backbone.layoutmanager'], function (main) { return main; }); |
|
|
|
define("backbone.layoutmanager/backbone.layoutmanager", function(){}); |
|
|
|
define('app',[ |
|
"modules/testing", |
|
"backbone.layoutmanager" |
|
], function() { |
|
|
|
// Provide a global location to place configuration settings and module |
|
// creation. |
|
var app = { |
|
// The root path to run the application. |
|
root: "/" |
|
}; |
|
|
|
// Localize or create a new JavaScript Template object. |
|
var JST = window.JST = window.JST || {}; |
|
|
|
// Configure LayoutManager with Backbone Boilerplate defaults. |
|
Backbone.LayoutManager.configure({ |
|
// Allow LayoutManager to augment Backbone.View.prototype. |
|
manage: true, |
|
|
|
prefix: "app/templates/", |
|
|
|
fetch: function(path) { |
|
// Concatenate the file extension. |
|
path = path + ".html"; |
|
|
|
// If cached, use the compiled template. |
|
if (JST[path]) { |
|
return JST[path]; |
|
} |
|
|
|
// Put fetch into `async-mode`. |
|
var done = this.async(); |
|
|
|
// Seek out the template asynchronously. |
|
$.get(app.root + path, function(contents) { |
|
done(JST[path] = _.template(contents)); |
|
}); |
|
} |
|
}); |
|
|
|
// Mix Backbone.Events, modules, and layout management into the app object. |
|
return _.extend(app, { |
|
// Create a custom object with a nested Views object. |
|
module: function(additionalProps) { |
|
return _.extend({ Views: {} }, additionalProps); |
|
}, |
|
|
|
// Helper for using layouts. |
|
useLayout: function(name, options) { |
|
// Enable variable arity by allowing the first argument to be the options |
|
// object and omitting the name argument. |
|
if (_.isObject(name)) { |
|
options = name; |
|
} |
|
|
|
// Ensure options is an object. |
|
options = options || {}; |
|
|
|
// If a name property was specified use that as the template. |
|
if (_.isString(name)) { |
|
options.template = name; |
|
} |
|
|
|
// Create a new Layout with options. |
|
var layout = new Backbone.Layout(_.extend({ |
|
el: "#main" |
|
}, options)); |
|
|
|
// Cache the refererence. |
|
return this.layout = layout; |
|
} |
|
}, Backbone.Events); |
|
|
|
}); |
|
|
|
define('router',[ |
|
// Application. |
|
"app" |
|
], |
|
|
|
function(app) { |
|
|
|
// Defining the application router, you can attach sub routers here. |
|
var Router = Backbone.Router.extend({ |
|
routes: { |
|
"": "index" |
|
}, |
|
|
|
index: function() { |
|
|
|
} |
|
}); |
|
|
|
return Router; |
|
|
|
}); |
|
|
|
require([ |
|
// Application. |
|
"app", |
|
|
|
// Main Router. |
|
"router" |
|
], |
|
|
|
function(app, Router) { |
|
|
|
// Define your master router on the application namespace and trigger all |
|
// navigation from this instance. |
|
app.router = new Router(); |
|
|
|
// Trigger the initial route and enable HTML5 History API support, set the |
|
// root folder to '/' by default. Change in app.js. |
|
Backbone.history.start({ pushState: true, root: app.root }); |
|
|
|
// All navigation that is relative should be passed through the navigate |
|
// method, to be processed by the router. If the link has a `data-bypass` |
|
// attribute, bypass the delegation completely. |
|
$(document).on("click", "a[href]:not([data-bypass])", function(evt) { |
|
// Get the absolute anchor href. |
|
var href = { prop: $(this).prop("href"), attr: $(this).attr("href") }; |
|
// Get the absolute root. |
|
var root = location.protocol + "//" + location.host + app.root; |
|
|
|
// Ensure the root is part of the anchor href, meaning it's relative. |
|
if (href.prop.slice(0, root.length) === root) { |
|
// Stop the default event to ensure the link will not cause a page |
|
// refresh. |
|
evt.preventDefault(); |
|
|
|
// `Backbone.history.navigate` is sufficient for all Routers and will |
|
// trigger the correct events. The Router's internal `navigate` method |
|
// calls this anyways. The fragment is sliced from the root. |
|
Backbone.history.navigate(href.attr, true); |
|
} |
|
}); |
|
|
|
}); |
|
|
|
define("main", function(){}); |
|
|
|
// Set the require.js configuration for your application. |
|
require.config({ |
|
|
|
// Initialize the application with the main application file and the JamJS |
|
// generated configuration file. |
|
deps: ["../vendor/jam/require.config", "main"], |
|
|
|
paths: { |
|
// Put paths here. |
|
}, |
|
|
|
shim: { |
|
// Put shims here. |
|
} |
|
|
|
}); |
|
|
|
define("config", function(){}); |