PageRenderTime 143ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 2ms

/src/cs-example/public/assets/commits.js

https://github.com/coltonTB/ezel
JavaScript | 12528 lines | 8446 code | 1937 blank | 2145 comment | 2372 complexity | bae828dd958c7f774ab6b536b95f09be MD5 | raw file
Possible License(s): MIT
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. var $, Backbone, Commits, CommitsView, listTemplate, sd, _ref,
  3. __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  6. Backbone = require("backbone");
  7. $ = require('jquery');
  8. Backbone.$ = $;
  9. sd = require("sharify").data;
  10. Commits = require("../../collections/commits.coffee");
  11. listTemplate = function() {
  12. return require("./templates/list.jade").apply(null, arguments);
  13. };
  14. module.exports.CommitsView = CommitsView = (function(_super) {
  15. __extends(CommitsView, _super);
  16. function CommitsView() {
  17. this.render = __bind(this.render, this);
  18. _ref = CommitsView.__super__.constructor.apply(this, arguments);
  19. return _ref;
  20. }
  21. CommitsView.prototype.initialize = function() {
  22. return this.collection.on("sync", this.render);
  23. };
  24. CommitsView.prototype.render = function() {
  25. return this.$("#commits-list").html(listTemplate({
  26. commits: this.collection.models
  27. }));
  28. };
  29. CommitsView.prototype.events = {
  30. "change .search-input": "changeRepo"
  31. };
  32. CommitsView.prototype.changeRepo = function(e) {
  33. this.collection.repo = $(e.target).val();
  34. return this.collection.fetch();
  35. };
  36. return CommitsView;
  37. })(Backbone.View);
  38. module.exports.init = function() {
  39. return new CommitsView({
  40. el: $("body"),
  41. collection: new Commits(sd.COMMITS, {
  42. owner: "artsy",
  43. repo: "flare"
  44. })
  45. });
  46. };
  47. },{"../../collections/commits.coffee":4,"./templates/list.jade":2,"backbone":6,"jquery":10,"sharify":11}],2:[function(require,module,exports){
  48. var jade = require("jade/runtime");
  49. module.exports = function template(locals) {
  50. var buf = [];
  51. var jade_mixins = {};
  52. var jade_interp;
  53. ;var locals_for_with = (locals || {});(function (commits) {
  54. // iterate commits
  55. ;(function(){
  56. var $$obj = commits;
  57. if ('number' == typeof $$obj.length) {
  58. for (var $index = 0, $$l = $$obj.length; $index < $$l; $index++) {
  59. var commit = $$obj[$index];
  60. buf.push("<li>" + (jade.escape(null == (jade_interp = commit.get('commit').message) ? "" : jade_interp)) + "</li>");
  61. }
  62. } else {
  63. var $$l = 0;
  64. for (var $index in $$obj) {
  65. $$l++; var commit = $$obj[$index];
  66. buf.push("<li>" + (jade.escape(null == (jade_interp = commit.get('commit').message) ? "" : jade_interp)) + "</li>");
  67. }
  68. }
  69. }).call(this);
  70. }("commits" in locals_for_with?locals_for_with.commits:typeof commits!=="undefined"?commits:undefined));;return buf.join("");
  71. };
  72. },{"jade/runtime":9}],3:[function(require,module,exports){
  73. require('jquery')(require("../apps/commits/client.coffee").init);
  74. },{"../apps/commits/client.coffee":1,"jquery":10}],4:[function(require,module,exports){
  75. var Backbone, Commit, Commits, sd, _ref,
  76. __hasProp = {}.hasOwnProperty,
  77. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  78. Backbone = require("backbone");
  79. sd = require("sharify").data;
  80. Commit = require("../models/commit.coffee");
  81. module.exports = Commits = (function(_super) {
  82. __extends(Commits, _super);
  83. function Commits() {
  84. _ref = Commits.__super__.constructor.apply(this, arguments);
  85. return _ref;
  86. }
  87. Commits.prototype.model = Commit;
  88. Commits.prototype.url = function() {
  89. return "" + sd.API_URL + "/repos/" + this.owner + "/" + this.repo + "/commits";
  90. };
  91. Commits.prototype.initialize = function(models, options) {
  92. return this.owner = options.owner, this.repo = options.repo, options;
  93. };
  94. return Commits;
  95. })(Backbone.Collection);
  96. },{"../models/commit.coffee":5,"backbone":6,"sharify":11}],5:[function(require,module,exports){
  97. var Backbone, Commit, sd, _ref,
  98. __hasProp = {}.hasOwnProperty,
  99. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  100. Backbone = require("backbone");
  101. sd = require("sharify").data;
  102. module.exports = Commit = (function(_super) {
  103. __extends(Commit, _super);
  104. function Commit() {
  105. _ref = Commit.__super__.constructor.apply(this, arguments);
  106. return _ref;
  107. }
  108. Commit.prototype.url = function() {
  109. return "" + sd.API_URL + "/repos/" + this.collection.owner + "/" + this.collection.repo + "/" + (this.get('sha'));
  110. };
  111. return Commit;
  112. })(Backbone.Model);
  113. },{"backbone":6,"sharify":11}],6:[function(require,module,exports){
  114. // Backbone.js 1.1.2
  115. // (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  116. // Backbone may be freely distributed under the MIT license.
  117. // For all details and documentation:
  118. // http://backbonejs.org
  119. (function(root, factory) {
  120. // Set up Backbone appropriately for the environment. Start with AMD.
  121. if (typeof define === 'function' && define.amd) {
  122. define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
  123. // Export global even in AMD case in case this script is loaded with
  124. // others that may still expect a global Backbone.
  125. root.Backbone = factory(root, exports, _, $);
  126. });
  127. // Next for Node.js or CommonJS. jQuery may not be needed as a module.
  128. } else if (typeof exports !== 'undefined') {
  129. var _ = require('underscore');
  130. factory(root, exports, _);
  131. // Finally, as a browser global.
  132. } else {
  133. root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
  134. }
  135. }(this, function(root, Backbone, _, $) {
  136. // Initial Setup
  137. // -------------
  138. // Save the previous value of the `Backbone` variable, so that it can be
  139. // restored later on, if `noConflict` is used.
  140. var previousBackbone = root.Backbone;
  141. // Create local references to array methods we'll want to use later.
  142. var array = [];
  143. var push = array.push;
  144. var slice = array.slice;
  145. var splice = array.splice;
  146. // Current version of the library. Keep in sync with `package.json`.
  147. Backbone.VERSION = '1.1.2';
  148. // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
  149. // the `$` variable.
  150. Backbone.$ = $;
  151. // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
  152. // to its previous owner. Returns a reference to this Backbone object.
  153. Backbone.noConflict = function() {
  154. root.Backbone = previousBackbone;
  155. return this;
  156. };
  157. // Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option
  158. // will fake `"PATCH"`, `"PUT"` and `"DELETE"` requests via the `_method` parameter and
  159. // set a `X-Http-Method-Override` header.
  160. Backbone.emulateHTTP = false;
  161. // Turn on `emulateJSON` to support legacy servers that can't deal with direct
  162. // `application/json` requests ... will encode the body as
  163. // `application/x-www-form-urlencoded` instead and will send the model in a
  164. // form param named `model`.
  165. Backbone.emulateJSON = false;
  166. // Backbone.Events
  167. // ---------------
  168. // A module that can be mixed in to *any object* in order to provide it with
  169. // custom events. You may bind with `on` or remove with `off` callback
  170. // functions to an event; `trigger`-ing an event fires all callbacks in
  171. // succession.
  172. //
  173. // var object = {};
  174. // _.extend(object, Backbone.Events);
  175. // object.on('expand', function(){ alert('expanded'); });
  176. // object.trigger('expand');
  177. //
  178. var Events = Backbone.Events = {
  179. // Bind an event to a `callback` function. Passing `"all"` will bind
  180. // the callback to all events fired.
  181. on: function(name, callback, context) {
  182. if (!eventsApi(this, 'on', name, [callback, context]) || !callback) return this;
  183. this._events || (this._events = {});
  184. var events = this._events[name] || (this._events[name] = []);
  185. events.push({callback: callback, context: context, ctx: context || this});
  186. return this;
  187. },
  188. // Bind an event to only be triggered a single time. After the first time
  189. // the callback is invoked, it will be removed.
  190. once: function(name, callback, context) {
  191. if (!eventsApi(this, 'once', name, [callback, context]) || !callback) return this;
  192. var self = this;
  193. var once = _.once(function() {
  194. self.off(name, once);
  195. callback.apply(this, arguments);
  196. });
  197. once._callback = callback;
  198. return this.on(name, once, context);
  199. },
  200. // Remove one or many callbacks. If `context` is null, removes all
  201. // callbacks with that function. If `callback` is null, removes all
  202. // callbacks for the event. If `name` is null, removes all bound
  203. // callbacks for all events.
  204. off: function(name, callback, context) {
  205. if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this;
  206. // Remove all callbacks for all events.
  207. if (!name && !callback && !context) {
  208. this._events = void 0;
  209. return this;
  210. }
  211. var names = name ? [name] : _.keys(this._events);
  212. for (var i = 0, length = names.length; i < length; i++) {
  213. name = names[i];
  214. // Bail out if there are no events stored.
  215. var events = this._events[name];
  216. if (!events) continue;
  217. // Remove all callbacks for this event.
  218. if (!callback && !context) {
  219. delete this._events[name];
  220. continue;
  221. }
  222. // Find any remaining events.
  223. var remaining = [];
  224. for (var j = 0, k = events.length; j < k; j++) {
  225. var event = events[j];
  226. if (
  227. callback && callback !== event.callback &&
  228. callback !== event.callback._callback ||
  229. context && context !== event.context
  230. ) {
  231. remaining.push(event);
  232. }
  233. }
  234. // Replace events if there are any remaining. Otherwise, clean up.
  235. if (remaining.length) {
  236. this._events[name] = remaining;
  237. } else {
  238. delete this._events[name];
  239. }
  240. }
  241. return this;
  242. },
  243. // Trigger one or many events, firing all bound callbacks. Callbacks are
  244. // passed the same arguments as `trigger` is, apart from the event name
  245. // (unless you're listening on `"all"`, which will cause your callback to
  246. // receive the true name of the event as the first argument).
  247. trigger: function(name) {
  248. if (!this._events) return this;
  249. var args = slice.call(arguments, 1);
  250. if (!eventsApi(this, 'trigger', name, args)) return this;
  251. var events = this._events[name];
  252. var allEvents = this._events.all;
  253. if (events) triggerEvents(events, args);
  254. if (allEvents) triggerEvents(allEvents, arguments);
  255. return this;
  256. },
  257. // Tell this object to stop listening to either specific events ... or
  258. // to every object it's currently listening to.
  259. stopListening: function(obj, name, callback) {
  260. var listeningTo = this._listeningTo;
  261. if (!listeningTo) return this;
  262. var remove = !name && !callback;
  263. if (!callback && typeof name === 'object') callback = this;
  264. if (obj) (listeningTo = {})[obj._listenId] = obj;
  265. for (var id in listeningTo) {
  266. obj = listeningTo[id];
  267. obj.off(name, callback, this);
  268. if (remove || _.isEmpty(obj._events)) delete this._listeningTo[id];
  269. }
  270. return this;
  271. }
  272. };
  273. // Regular expression used to split event strings.
  274. var eventSplitter = /\s+/;
  275. // Implement fancy features of the Events API such as multiple event
  276. // names `"change blur"` and jQuery-style event maps `{change: action}`
  277. // in terms of the existing API.
  278. var eventsApi = function(obj, action, name, rest) {
  279. if (!name) return true;
  280. // Handle event maps.
  281. if (typeof name === 'object') {
  282. for (var key in name) {
  283. obj[action].apply(obj, [key, name[key]].concat(rest));
  284. }
  285. return false;
  286. }
  287. // Handle space separated event names.
  288. if (eventSplitter.test(name)) {
  289. var names = name.split(eventSplitter);
  290. for (var i = 0, length = names.length; i < length; i++) {
  291. obj[action].apply(obj, [names[i]].concat(rest));
  292. }
  293. return false;
  294. }
  295. return true;
  296. };
  297. // A difficult-to-believe, but optimized internal dispatch function for
  298. // triggering events. Tries to keep the usual cases speedy (most internal
  299. // Backbone events have 3 arguments).
  300. var triggerEvents = function(events, args) {
  301. var ev, i = -1, l = events.length, a1 = args[0], a2 = args[1], a3 = args[2];
  302. switch (args.length) {
  303. case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); return;
  304. case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return;
  305. case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return;
  306. case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return;
  307. default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return;
  308. }
  309. };
  310. var listenMethods = {listenTo: 'on', listenToOnce: 'once'};
  311. // Inversion-of-control versions of `on` and `once`. Tell *this* object to
  312. // listen to an event in another object ... keeping track of what it's
  313. // listening to.
  314. _.each(listenMethods, function(implementation, method) {
  315. Events[method] = function(obj, name, callback) {
  316. var listeningTo = this._listeningTo || (this._listeningTo = {});
  317. var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
  318. listeningTo[id] = obj;
  319. if (!callback && typeof name === 'object') callback = this;
  320. obj[implementation](name, callback, this);
  321. return this;
  322. };
  323. });
  324. // Aliases for backwards compatibility.
  325. Events.bind = Events.on;
  326. Events.unbind = Events.off;
  327. // Allow the `Backbone` object to serve as a global event bus, for folks who
  328. // want global "pubsub" in a convenient place.
  329. _.extend(Backbone, Events);
  330. // Backbone.Model
  331. // --------------
  332. // Backbone **Models** are the basic data object in the framework --
  333. // frequently representing a row in a table in a database on your server.
  334. // A discrete chunk of data and a bunch of useful, related methods for
  335. // performing computations and transformations on that data.
  336. // Create a new model with the specified attributes. A client id (`cid`)
  337. // is automatically generated and assigned for you.
  338. var Model = Backbone.Model = function(attributes, options) {
  339. var attrs = attributes || {};
  340. options || (options = {});
  341. this.cid = _.uniqueId('c');
  342. this.attributes = {};
  343. if (options.collection) this.collection = options.collection;
  344. if (options.parse) attrs = this.parse(attrs, options) || {};
  345. attrs = _.defaults({}, attrs, _.result(this, 'defaults'));
  346. this.set(attrs, options);
  347. this.changed = {};
  348. this.initialize.apply(this, arguments);
  349. };
  350. // Attach all inheritable methods to the Model prototype.
  351. _.extend(Model.prototype, Events, {
  352. // A hash of attributes whose current and previous value differ.
  353. changed: null,
  354. // The value returned during the last failed validation.
  355. validationError: null,
  356. // The default name for the JSON `id` attribute is `"id"`. MongoDB and
  357. // CouchDB users may want to set this to `"_id"`.
  358. idAttribute: 'id',
  359. // Initialize is an empty function by default. Override it with your own
  360. // initialization logic.
  361. initialize: function(){},
  362. // Return a copy of the model's `attributes` object.
  363. toJSON: function(options) {
  364. return _.clone(this.attributes);
  365. },
  366. // Proxy `Backbone.sync` by default -- but override this if you need
  367. // custom syncing semantics for *this* particular model.
  368. sync: function() {
  369. return Backbone.sync.apply(this, arguments);
  370. },
  371. // Get the value of an attribute.
  372. get: function(attr) {
  373. return this.attributes[attr];
  374. },
  375. // Get the HTML-escaped value of an attribute.
  376. escape: function(attr) {
  377. return _.escape(this.get(attr));
  378. },
  379. // Returns `true` if the attribute contains a value that is not null
  380. // or undefined.
  381. has: function(attr) {
  382. return this.get(attr) != null;
  383. },
  384. // Set a hash of model attributes on the object, firing `"change"`. This is
  385. // the core primitive operation of a model, updating the data and notifying
  386. // anyone who needs to know about the change in state. The heart of the beast.
  387. set: function(key, val, options) {
  388. var attr, attrs, unset, changes, silent, changing, prev, current;
  389. if (key == null) return this;
  390. // Handle both `"key", value` and `{key: value}` -style arguments.
  391. if (typeof key === 'object') {
  392. attrs = key;
  393. options = val;
  394. } else {
  395. (attrs = {})[key] = val;
  396. }
  397. options || (options = {});
  398. // Run validation.
  399. if (!this._validate(attrs, options)) return false;
  400. // Extract attributes and options.
  401. unset = options.unset;
  402. silent = options.silent;
  403. changes = [];
  404. changing = this._changing;
  405. this._changing = true;
  406. if (!changing) {
  407. this._previousAttributes = _.clone(this.attributes);
  408. this.changed = {};
  409. }
  410. current = this.attributes, prev = this._previousAttributes;
  411. // Check for changes of `id`.
  412. if (this.idAttribute in attrs) this.id = attrs[this.idAttribute];
  413. // For each `set` attribute, update or delete the current value.
  414. for (attr in attrs) {
  415. val = attrs[attr];
  416. if (!_.isEqual(current[attr], val)) changes.push(attr);
  417. if (!_.isEqual(prev[attr], val)) {
  418. this.changed[attr] = val;
  419. } else {
  420. delete this.changed[attr];
  421. }
  422. unset ? delete current[attr] : current[attr] = val;
  423. }
  424. // Trigger all relevant attribute changes.
  425. if (!silent) {
  426. if (changes.length) this._pending = options;
  427. for (var i = 0, length = changes.length; i < length; i++) {
  428. this.trigger('change:' + changes[i], this, current[changes[i]], options);
  429. }
  430. }
  431. // You might be wondering why there's a `while` loop here. Changes can
  432. // be recursively nested within `"change"` events.
  433. if (changing) return this;
  434. if (!silent) {
  435. while (this._pending) {
  436. options = this._pending;
  437. this._pending = false;
  438. this.trigger('change', this, options);
  439. }
  440. }
  441. this._pending = false;
  442. this._changing = false;
  443. return this;
  444. },
  445. // Remove an attribute from the model, firing `"change"`. `unset` is a noop
  446. // if the attribute doesn't exist.
  447. unset: function(attr, options) {
  448. return this.set(attr, void 0, _.extend({}, options, {unset: true}));
  449. },
  450. // Clear all attributes on the model, firing `"change"`.
  451. clear: function(options) {
  452. var attrs = {};
  453. for (var key in this.attributes) attrs[key] = void 0;
  454. return this.set(attrs, _.extend({}, options, {unset: true}));
  455. },
  456. // Determine if the model has changed since the last `"change"` event.
  457. // If you specify an attribute name, determine if that attribute has changed.
  458. hasChanged: function(attr) {
  459. if (attr == null) return !_.isEmpty(this.changed);
  460. return _.has(this.changed, attr);
  461. },
  462. // Return an object containing all the attributes that have changed, or
  463. // false if there are no changed attributes. Useful for determining what
  464. // parts of a view need to be updated and/or what attributes need to be
  465. // persisted to the server. Unset attributes will be set to undefined.
  466. // You can also pass an attributes object to diff against the model,
  467. // determining if there *would be* a change.
  468. changedAttributes: function(diff) {
  469. if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
  470. var val, changed = false;
  471. var old = this._changing ? this._previousAttributes : this.attributes;
  472. for (var attr in diff) {
  473. if (_.isEqual(old[attr], (val = diff[attr]))) continue;
  474. (changed || (changed = {}))[attr] = val;
  475. }
  476. return changed;
  477. },
  478. // Get the previous value of an attribute, recorded at the time the last
  479. // `"change"` event was fired.
  480. previous: function(attr) {
  481. if (attr == null || !this._previousAttributes) return null;
  482. return this._previousAttributes[attr];
  483. },
  484. // Get all of the attributes of the model at the time of the previous
  485. // `"change"` event.
  486. previousAttributes: function() {
  487. return _.clone(this._previousAttributes);
  488. },
  489. // Fetch the model from the server. If the server's representation of the
  490. // model differs from its current attributes, they will be overridden,
  491. // triggering a `"change"` event.
  492. fetch: function(options) {
  493. options = options ? _.clone(options) : {};
  494. if (options.parse === void 0) options.parse = true;
  495. var model = this;
  496. var success = options.success;
  497. options.success = function(resp) {
  498. if (!model.set(model.parse(resp, options), options)) return false;
  499. if (success) success(model, resp, options);
  500. model.trigger('sync', model, resp, options);
  501. };
  502. wrapError(this, options);
  503. return this.sync('read', this, options);
  504. },
  505. // Set a hash of model attributes, and sync the model to the server.
  506. // If the server returns an attributes hash that differs, the model's
  507. // state will be `set` again.
  508. save: function(key, val, options) {
  509. var attrs, method, xhr, attributes = this.attributes;
  510. // Handle both `"key", value` and `{key: value}` -style arguments.
  511. if (key == null || typeof key === 'object') {
  512. attrs = key;
  513. options = val;
  514. } else {
  515. (attrs = {})[key] = val;
  516. }
  517. options = _.extend({validate: true}, options);
  518. // If we're not waiting and attributes exist, save acts as
  519. // `set(attr).save(null, opts)` with validation. Otherwise, check if
  520. // the model will be valid when the attributes, if any, are set.
  521. if (attrs && !options.wait) {
  522. if (!this.set(attrs, options)) return false;
  523. } else {
  524. if (!this._validate(attrs, options)) return false;
  525. }
  526. // Set temporary attributes if `{wait: true}`.
  527. if (attrs && options.wait) {
  528. this.attributes = _.extend({}, attributes, attrs);
  529. }
  530. // After a successful server-side save, the client is (optionally)
  531. // updated with the server-side state.
  532. if (options.parse === void 0) options.parse = true;
  533. var model = this;
  534. var success = options.success;
  535. options.success = function(resp) {
  536. // Ensure attributes are restored during synchronous saves.
  537. model.attributes = attributes;
  538. var serverAttrs = model.parse(resp, options);
  539. if (options.wait) serverAttrs = _.extend(attrs || {}, serverAttrs);
  540. if (_.isObject(serverAttrs) && !model.set(serverAttrs, options)) {
  541. return false;
  542. }
  543. if (success) success(model, resp, options);
  544. model.trigger('sync', model, resp, options);
  545. };
  546. wrapError(this, options);
  547. method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
  548. if (method === 'patch') options.attrs = attrs;
  549. xhr = this.sync(method, this, options);
  550. // Restore attributes.
  551. if (attrs && options.wait) this.attributes = attributes;
  552. return xhr;
  553. },
  554. // Destroy this model on the server if it was already persisted.
  555. // Optimistically removes the model from its collection, if it has one.
  556. // If `wait: true` is passed, waits for the server to respond before removal.
  557. destroy: function(options) {
  558. options = options ? _.clone(options) : {};
  559. var model = this;
  560. var success = options.success;
  561. var destroy = function() {
  562. model.trigger('destroy', model, model.collection, options);
  563. };
  564. options.success = function(resp) {
  565. if (options.wait || model.isNew()) destroy();
  566. if (success) success(model, resp, options);
  567. if (!model.isNew()) model.trigger('sync', model, resp, options);
  568. };
  569. if (this.isNew()) {
  570. options.success();
  571. return false;
  572. }
  573. wrapError(this, options);
  574. var xhr = this.sync('delete', this, options);
  575. if (!options.wait) destroy();
  576. return xhr;
  577. },
  578. // Default URL for the model's representation on the server -- if you're
  579. // using Backbone's restful methods, override this to change the endpoint
  580. // that will be called.
  581. url: function() {
  582. var base =
  583. _.result(this, 'urlRoot') ||
  584. _.result(this.collection, 'url') ||
  585. urlError();
  586. if (this.isNew()) return base;
  587. return base.replace(/([^\/])$/, '$1/') + encodeURIComponent(this.id);
  588. },
  589. // **parse** converts a response into the hash of attributes to be `set` on
  590. // the model. The default implementation is just to pass the response along.
  591. parse: function(resp, options) {
  592. return resp;
  593. },
  594. // Create a new model with identical attributes to this one.
  595. clone: function() {
  596. return new this.constructor(this.attributes);
  597. },
  598. // A model is new if it has never been saved to the server, and lacks an id.
  599. isNew: function() {
  600. return !this.has(this.idAttribute);
  601. },
  602. // Check if the model is currently in a valid state.
  603. isValid: function(options) {
  604. return this._validate({}, _.extend(options || {}, { validate: true }));
  605. },
  606. // Run validation against the next complete set of model attributes,
  607. // returning `true` if all is well. Otherwise, fire an `"invalid"` event.
  608. _validate: function(attrs, options) {
  609. if (!options.validate || !this.validate) return true;
  610. attrs = _.extend({}, this.attributes, attrs);
  611. var error = this.validationError = this.validate(attrs, options) || null;
  612. if (!error) return true;
  613. this.trigger('invalid', this, error, _.extend(options, {validationError: error}));
  614. return false;
  615. }
  616. });
  617. // Underscore methods that we want to implement on the Model.
  618. var modelMethods = ['keys', 'values', 'pairs', 'invert', 'pick', 'omit'];
  619. // Mix in each Underscore method as a proxy to `Model#attributes`.
  620. _.each(modelMethods, function(method) {
  621. if (!_[method]) return;
  622. Model.prototype[method] = function() {
  623. var args = slice.call(arguments);
  624. args.unshift(this.attributes);
  625. return _[method].apply(_, args);
  626. };
  627. });
  628. // Backbone.Collection
  629. // -------------------
  630. // If models tend to represent a single row of data, a Backbone Collection is
  631. // more analagous to a table full of data ... or a small slice or page of that
  632. // table, or a collection of rows that belong together for a particular reason
  633. // -- all of the messages in this particular folder, all of the documents
  634. // belonging to this particular author, and so on. Collections maintain
  635. // indexes of their models, both in order, and for lookup by `id`.
  636. // Create a new **Collection**, perhaps to contain a specific type of `model`.
  637. // If a `comparator` is specified, the Collection will maintain
  638. // its models in sort order, as they're added and removed.
  639. var Collection = Backbone.Collection = function(models, options) {
  640. options || (options = {});
  641. if (options.model) this.model = options.model;
  642. if (options.comparator !== void 0) this.comparator = options.comparator;
  643. this._reset();
  644. this.initialize.apply(this, arguments);
  645. if (models) this.reset(models, _.extend({silent: true}, options));
  646. };
  647. // Default options for `Collection#set`.
  648. var setOptions = {add: true, remove: true, merge: true};
  649. var addOptions = {add: true, remove: false};
  650. // Define the Collection's inheritable methods.
  651. _.extend(Collection.prototype, Events, {
  652. // The default model for a collection is just a **Backbone.Model**.
  653. // This should be overridden in most cases.
  654. model: Model,
  655. // Initialize is an empty function by default. Override it with your own
  656. // initialization logic.
  657. initialize: function(){},
  658. // The JSON representation of a Collection is an array of the
  659. // models' attributes.
  660. toJSON: function(options) {
  661. return this.map(function(model){ return model.toJSON(options); });
  662. },
  663. // Proxy `Backbone.sync` by default.
  664. sync: function() {
  665. return Backbone.sync.apply(this, arguments);
  666. },
  667. // Add a model, or list of models to the set.
  668. add: function(models, options) {
  669. return this.set(models, _.extend({merge: false}, options, addOptions));
  670. },
  671. // Remove a model, or a list of models from the set.
  672. remove: function(models, options) {
  673. var singular = !_.isArray(models);
  674. models = singular ? [models] : _.clone(models);
  675. options || (options = {});
  676. for (var i = 0, length = models.length; i < length; i++) {
  677. var model = models[i] = this.get(models[i]);
  678. if (!model) continue;
  679. delete this._byId[model.id];
  680. delete this._byId[model.cid];
  681. var index = this.indexOf(model);
  682. this.models.splice(index, 1);
  683. this.length--;
  684. if (!options.silent) {
  685. options.index = index;
  686. model.trigger('remove', model, this, options);
  687. }
  688. this._removeReference(model, options);
  689. }
  690. return singular ? models[0] : models;
  691. },
  692. // Update a collection by `set`-ing a new list of models, adding new ones,
  693. // removing models that are no longer present, and merging models that
  694. // already exist in the collection, as necessary. Similar to **Model#set**,
  695. // the core operation for updating the data contained by the collection.
  696. set: function(models, options) {
  697. options = _.defaults({}, options, setOptions);
  698. if (options.parse) models = this.parse(models, options);
  699. var singular = !_.isArray(models);
  700. models = singular ? (models ? [models] : []) : models.slice();
  701. var id, model, attrs, existing, sort;
  702. var at = options.at;
  703. var sortable = this.comparator && (at == null) && options.sort !== false;
  704. var sortAttr = _.isString(this.comparator) ? this.comparator : null;
  705. var toAdd = [], toRemove = [], modelMap = {};
  706. var add = options.add, merge = options.merge, remove = options.remove;
  707. var order = !sortable && add && remove ? [] : false;
  708. // Turn bare objects into model references, and prevent invalid models
  709. // from being added.
  710. for (var i = 0, length = models.length; i < length; i++) {
  711. attrs = models[i] || {};
  712. if (attrs instanceof Model) {
  713. id = model = attrs;
  714. } else {
  715. id = attrs[this.model.prototype.idAttribute || 'id'];
  716. }
  717. // If a duplicate is found, prevent it from being added and
  718. // optionally merge it into the existing model.
  719. if (existing = this.get(id)) {
  720. if (remove) modelMap[existing.cid] = true;
  721. if (merge) {
  722. attrs = attrs === model ? model.attributes : attrs;
  723. if (options.parse) attrs = existing.parse(attrs, options);
  724. existing.set(attrs, options);
  725. if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true;
  726. }
  727. models[i] = existing;
  728. // If this is a new, valid model, push it to the `toAdd` list.
  729. } else if (add) {
  730. model = models[i] = this._prepareModel(attrs, options);
  731. if (!model) continue;
  732. toAdd.push(model);
  733. this._addReference(model, options);
  734. }
  735. // Do not add multiple models with the same `id`.
  736. model = existing || model;
  737. if (!model) continue;
  738. if (order && (model.isNew() || !modelMap[model.id])) order.push(model);
  739. modelMap[model.id] = true;
  740. }
  741. // Remove nonexistent models if appropriate.
  742. if (remove) {
  743. for (var i = 0, length = this.length; i < length; i++) {
  744. if (!modelMap[(model = this.models[i]).cid]) toRemove.push(model);
  745. }
  746. if (toRemove.length) this.remove(toRemove, options);
  747. }
  748. // See if sorting is needed, update `length` and splice in new models.
  749. if (toAdd.length || (order && order.length)) {
  750. if (sortable) sort = true;
  751. this.length += toAdd.length;
  752. if (at != null) {
  753. for (var i = 0, length = toAdd.length; i < length; i++) {
  754. this.models.splice(at + i, 0, toAdd[i]);
  755. }
  756. } else {
  757. if (order) this.models.length = 0;
  758. var orderedModels = order || toAdd;
  759. for (var i = 0, length = orderedModels.length; i < length; i++) {
  760. this.models.push(orderedModels[i]);
  761. }
  762. }
  763. }
  764. // Silently sort the collection if appropriate.
  765. if (sort) this.sort({silent: true});
  766. // Unless silenced, it's time to fire all appropriate add/sort events.
  767. if (!options.silent) {
  768. for (var i = 0, length = toAdd.length; i < length; i++) {
  769. (model = toAdd[i]).trigger('add', model, this, options);
  770. }
  771. if (sort || (order && order.length)) this.trigger('sort', this, options);
  772. }
  773. // Return the added (or merged) model (or models).
  774. return singular ? models[0] : models;
  775. },
  776. // When you have more items than you want to add or remove individually,
  777. // you can reset the entire set with a new list of models, without firing
  778. // any granular `add` or `remove` events. Fires `reset` when finished.
  779. // Useful for bulk operations and optimizations.
  780. reset: function(models, options) {
  781. options || (options = {});
  782. for (var i = 0, length = this.models.length; i < length; i++) {
  783. this._removeReference(this.models[i], options);
  784. }
  785. options.previousModels = this.models;
  786. this._reset();
  787. models = this.add(models, _.extend({silent: true}, options));
  788. if (!options.silent) this.trigger('reset', this, options);
  789. return models;
  790. },
  791. // Add a model to the end of the collection.
  792. push: function(model, options) {
  793. return this.add(model, _.extend({at: this.length}, options));
  794. },
  795. // Remove a model from the end of the collection.
  796. pop: function(options) {
  797. var model = this.at(this.length - 1);
  798. this.remove(model, options);
  799. return model;
  800. },
  801. // Add a model to the beginning of the collection.
  802. unshift: function(model, options) {
  803. return this.add(model, _.extend({at: 0}, options));
  804. },
  805. // Remove a model from the beginning of the collection.
  806. shift: function(options) {
  807. var model = this.at(0);
  808. this.remove(model, options);
  809. return model;
  810. },
  811. // Slice out a sub-array of models from the collection.
  812. slice: function() {
  813. return slice.apply(this.models, arguments);
  814. },
  815. // Get a model from the set by id.
  816. get: function(obj) {
  817. if (obj == null) return void 0;
  818. return this._byId[obj] || this._byId[obj.id] || this._byId[obj.cid];
  819. },
  820. // Get the model at the given index.
  821. at: function(index) {
  822. return this.models[index];
  823. },
  824. // Return models with matching attributes. Useful for simple cases of
  825. // `filter`.
  826. where: function(attrs, first) {
  827. if (_.isEmpty(attrs)) return first ? void 0 : [];
  828. return this[first ? 'find' : 'filter'](function(model) {
  829. for (var key in attrs) {
  830. if (attrs[key] !== model.get(key)) return false;
  831. }
  832. return true;
  833. });
  834. },
  835. // Return the first model with matching attributes. Useful for simple cases
  836. // of `find`.
  837. findWhere: function(attrs) {
  838. return this.where(attrs, true);
  839. },
  840. // Force the collection to re-sort itself. You don't need to call this under
  841. // normal circumstances, as the set will maintain sort order as each item
  842. // is added.
  843. sort: function(options) {
  844. if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
  845. options || (options = {});
  846. // Run sort based on type of `comparator`.
  847. if (_.isString(this.comparator) || this.comparator.length === 1) {
  848. this.models = this.sortBy(this.comparator, this);
  849. } else {
  850. this.models.sort(_.bind(this.comparator, this));
  851. }
  852. if (!options.silent) this.trigger('sort', this, options);
  853. return this;
  854. },
  855. // Pluck an attribute from each model in the collection.
  856. pluck: function(attr) {
  857. return _.invoke(this.models, 'get', attr);
  858. },
  859. // Fetch the default set of models for this collection, resetting the
  860. // collection when they arrive. If `reset: true` is passed, the response
  861. // data will be passed through the `reset` method instead of `set`.
  862. fetch: function(options) {
  863. options = options ? _.clone(options) : {};
  864. if (options.parse === void 0) options.parse = true;
  865. var success = options.success;
  866. var collection = this;
  867. options.success = function(resp) {
  868. var method = options.reset ? 'reset' : 'set';
  869. collection[method](resp, options);
  870. if (success) success(collection, resp, options);
  871. collection.trigger('sync', collection, resp, options);
  872. };
  873. wrapError(this, options);
  874. return this.sync('read', this, options);
  875. },
  876. // Create a new instance of a model in this collection. Add the model to the
  877. // collection immediately, unless `wait: true` is passed, in which case we
  878. // wait for the server to agree.
  879. create: function(model, options) {
  880. options = options ? _.clone(options) : {};
  881. if (!(model = this._prepareModel(model, options))) return false;
  882. if (!options.wait) this.add(model, options);
  883. var collection = this;
  884. var success = options.success;
  885. options.success = function(model, resp) {
  886. if (options.wait) collection.add(model, options);
  887. if (success) success(model, resp, options);
  888. };
  889. model.save(null, options);
  890. return model;
  891. },
  892. // **parse** converts a response into a list of models to be added to the
  893. // collection. The default implementation is just to pass it through.
  894. parse: function(resp, options) {
  895. return resp;
  896. },
  897. // Create a new collection with an identical list of models as this one.
  898. clone: function() {
  899. return new this.constructor(this.models);
  900. },
  901. // Private method to reset all internal state. Called when the collection
  902. // is first initialized or reset.
  903. _reset: function() {
  904. this.length = 0;
  905. this.models = [];
  906. this._byId = {};
  907. },
  908. // Prepare a hash of attributes (or other model) to be added to this
  909. // collection.
  910. _prepareModel: function(attrs, options) {
  911. if (attrs instanceof Model) return attrs;
  912. options = options ? _.clone(options) : {};
  913. options.collection = this;
  914. var model = new this.model(attrs, options);
  915. if (!model.validationError) return model;
  916. this.trigger('invalid', this, model.validationError, options);
  917. return false;
  918. },
  919. // Internal method to create a model's ties to a collection.
  920. _addReference: function(model, options) {
  921. this._byId[model.cid] = model;
  922. if (model.id != null) this._byId[model.id] = model;
  923. if (!model.collection) model.collection = this;
  924. model.on('all', this._onModelEvent, this);
  925. },
  926. // Internal method to sever a model's ties to a collection.
  927. _removeReference: function(model, options) {
  928. if (this === model.collection) delete model.collection;
  929. model.off('all', this._onModelEvent, this);
  930. },
  931. // Internal method called every time a model in the set fires an event.
  932. // Sets need to update their indexes when models change ids. All other
  933. // events simply proxy through. "add" and "remove" events that originate
  934. // in other collections are ignored.
  935. _onModelEvent: function(event, model, collection, options) {
  936. if ((event === 'add' || event === 'remove') && collection !== this) return;
  937. if (event === 'destroy') this.remove(model, options);
  938. if (model && event === 'change:' + model.idAttribute) {
  939. delete this._byId[model.previous(model.idAttribute)];
  940. if (model.id != null) this._byId[model.id] = model;
  941. }
  942. this.trigger.apply(this, arguments);
  943. }
  944. });
  945. // Underscore methods that we want to implement on the Collection.
  946. // 90% of the core usefulness of Backbone Collections is actually implemented
  947. // right here:
  948. var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
  949. 'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
  950. 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
  951. 'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
  952. 'tail', 'drop', 'last', 'without', 'difference', 'indexOf', 'shuffle',
  953. 'lastIndexOf', 'isEmpty', 'chain', 'sample', 'partition'];
  954. // Mix in each Underscore method as a proxy to `Collection#models`.
  955. _.each(methods, function(method) {
  956. if (!_[method]) return;
  957. Collection.prototype[method] = function() {
  958. var args = slice.call(arguments);
  959. args.unshift(this.models);
  960. return _[method].apply(_, args);
  961. };
  962. });
  963. // Underscore methods that take a property name as an argument.
  964. var attributeMethods = ['groupBy', 'countBy', 'sortBy', 'indexBy'];
  965. // Use attributes instead of properties.
  966. _.each(attributeMethods, function(method) {
  967. if (!_[method]) return;
  968. Collection.prototype[method] = function(value, context) {
  969. var iterator = _.isFunction(value) ? value : function(model) {
  970. return model.get(value);
  971. };
  972. return _[method](this.models, iterator, context);
  973. };
  974. });
  975. // Backbone.View
  976. // -------------
  977. // Backbone Views are almost more convention than they are actual code. A View
  978. // is simply a JavaScript object that represents a logical chunk of UI in the
  979. // DOM. This might be a single item, an entire list, a sidebar or panel, or
  980. // even the surrounding frame which wraps your whole app. Defining a chunk of
  981. // UI as a **View** allows you to define your DOM events declaratively, without
  982. // having to worry about render order ... and makes it easy for the view to
  983. // react to specific changes in the state of your models.
  984. // Creating a Backbone.View creates its initial element outside of the DOM,
  985. // if an existing element is not provided...
  986. var View = Backbone.View = function(options) {
  987. this.cid = _.uniqueId('view');
  988. options || (options = {});
  989. _.extend(this, _.pick(options, viewOptions));
  990. this._ensureElement();
  991. this.initialize.apply(this, arguments);
  992. this.delegateEvents();
  993. };
  994. // Cached regex to split keys for `delegate`.
  995. var delegateEventSplitter = /^(\S+)\s*(.*)$/;
  996. // List of view options to be merged as properties.
  997. var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
  998. // Set up all inheritable **Backbone.View** properties and methods.
  999. _.extend(View.prototype, Events, {
  1000. // The default `tagName` of a View's element is `"div"`.
  1001. tagName: 'div',
  1002. // jQuery delegate for element lookup, scoped to DOM elements within the
  1003. // current view. This should be preferred to global lookups where possible.
  1004. $: function(selector) {
  1005. return this.$el.find(selector);
  1006. },
  1007. // Initialize is an empty function by default. Override it with your own
  1008. // initialization logic.
  1009. initialize: function(){},
  1010. // **render** is the core function that your view should override, in order
  1011. // to populate its element (`this.el`), with the appropriate HTML. The
  1012. // convention is for **render** to always return `this`.
  1013. render: function() {
  1014. return this;
  1015. },
  1016. // Remove this view by taking the element out of the DOM, and removing any
  1017. // applicable Backbone.Events listeners.
  1018. remove: function() {
  1019. this.$el.remove();
  1020. this.stopListening();
  1021. return this;
  1022. },
  1023. // Change the view's element (`this.el` property), including event
  1024. // re-delegation.
  1025. setElement: function(element, delegate) {
  1026. if (this.$el) this.undelegateEvents();
  1027. this.$el = element instanceof Backbone.$ ? element : Backbone.$(element);
  1028. this.el = this.$el[0];
  1029. if (delegate !== false) this.delegateEvents();
  1030. return this;
  1031. },
  1032. // Set callbacks, where `this.events` is a hash of
  1033. //
  1034. // *{"event selector": "callback"}*
  1035. //
  1036. // {
  1037. // 'mousedown .title': 'edit',
  1038. // 'click .button': 'save',
  1039. // 'click .open': function(e) { ... }
  1040. // }
  1041. //
  1042. // pairs. Callbacks will be bound to the view, with `this` set properly.
  1043. // Uses event delegation for efficiency.
  1044. // Omitting the selector binds the event to `this.el`.
  1045. // This only works for delegate-able events: not `focus`, `blur`, and
  1046. // not `change`, `submit`, and `reset` in Internet Explorer.
  1047. delegateEvents: function(events) {
  1048. if (!(events || (events = _.result(this, 'events')))) return this;
  1049. this.undelegateEvents();
  1050. for (var key in events) {
  1051. var method = events[key];
  1052. if (!_.isFunction(method)) method = this[events[key]];
  1053. if (!method) continue;
  1054. var match = key.match(delegateEventSplitter);
  1055. var eventName = match[1], selector = match[2];
  1056. method = _.bind(method, this);
  1057. eventName += '.delegateEvents' + this.cid;
  1058. if (selector === '') {
  1059. this.$el.on(eventName, method);
  1060. } else {
  1061. this.$el.on(eventName, selector, method);
  1062. }
  1063. }
  1064. return this;
  1065. },
  1066. // Clears all callbacks previously bound to the view with `delegateEvents`.
  1067. // You usually don't need to use this, but may wish to if you have multiple
  1068. // Backbone views attached to the same DOM element.
  1069. undelegateEvents: function() {
  1070. this.$el.off('.delegateEvents' + this.cid);
  1071. return this;
  1072. },
  1073. // Ensure that the View has a DOM element to render into.
  1074. // If `this.el` is a string, pass it through `$()`, take the first
  1075. // matching element, and re-assign it to `el`. Otherwise, create
  1076. // an element from the `id`, `className` and `tagName` properties.
  1077. _ensureElement: function() {
  1078. if (!this.el) {
  1079. var attrs = _.extend({}, _.result(this, 'attributes'));
  1080. if (this.id) attrs.id = _.result(this, 'id');
  1081. if (this.className) attrs['class'] = _.result(this, 'className');
  1082. var $el = Backbone.$('<' + _.result(this, 'tagName') + '>').attr(attrs);
  1083. this.setElement($el, false);
  1084. } else {
  1085. this.setElement(_.result(this, 'el'), false);
  1086. }
  1087. }
  1088. });
  1089. // Backbone.sync
  1090. // -------------
  1091. // Override this function to change the manner in which Backbone persists
  1092. // models to the server. You will be passed the type of request, and the
  1093. // model in question. By default, makes a RESTful Ajax request
  1094. // to the model's `url()`. Some possible customizations could be:
  1095. //
  1096. // * Use `setTimeout` to batch rapid-fire updates into a single request.
  1097. // * Send up the models as XML instead of JSON.
  1098. // * Persist models via WebSockets instead of Ajax.
  1099. //
  1100. // Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests
  1101. // as `POST`, with a `_method` parameter containing the true HTTP method,
  1102. // as well as all requests with the body as `application/x-www-form-urlencoded`
  1103. // instead of `application/json` with the model in a param named `model`.
  1104. // Useful when interfacing with server-side languages like **PHP** that make
  1105. // it difficult to read the body of `PUT` requests.
  1106. Backbone.sync = function(method, model, options) {
  1107. var type = methodMap[method];
  1108. // Default options, unless specified.
  1109. _.defaults(options || (options = {}), {
  1110. emulateHTTP: Backbone.emulateHTTP,
  1111. emulateJSON: Backbone.emulateJSON
  1112. });
  1113. // Default JSON-request options.
  1114. var params = {type: type, dataType: 'json'};
  1115. // Ensure that we have a URL.
  1116. if (!options.url) {
  1117. params.url = _.result(model, 'url') || urlError();
  1118. }
  1119. // Ensure that we have the appropriate request data.
  1120. if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
  1121. params.contentType = 'application/json';
  1122. params.data = JSON.stringify(options.attrs || model.toJSON(options));
  1123. }
  1124. // For older servers, emulate JSON by encoding the request into an HTML-form.
  1125. if (options.emulateJSON) {
  1126. params.contentType = 'application/x-www-form-urlencoded';
  1127. params.data = params.data ? {model: params.data} : {};
  1128. }
  1129. // For older servers, emulate HTTP by mimicking the HTTP method with `_method`
  1130. // And an `X-HTTP-Method-Override` header.
  1131. if (options.emulateHTTP && (type === 'PUT' || type === 'DELETE' || type === 'PATCH')) {
  1132. params.type = 'POST';
  1133. if (options.emulateJSON) params.data._method = type;
  1134. var beforeSend = options.beforeSend;
  1135. options.beforeSend = function(xhr) {
  1136. xhr.setRequestHeader('X-HTTP-Method-Override', type);
  1137. if (beforeSend) return beforeSend.apply(this, arguments);
  1138. };
  1139. }
  1140. // Don't process data on a non-GET request.
  1141. if (params.type !== 'GET' && !options.emulateJSON) {
  1142. params.processData = false;
  1143. }
  1144. // If we're sending a `PATCH` request, and we're in an old Internet Explorer
  1145. // that still has ActiveX enabled by default, override jQuery to use that
  1146. // for XHR instead. Remove this line when jQuery supports `PATCH` on IE8.
  1147. if (params.type === 'PATCH' && noXhrPatch) {
  1148. params.xhr = function() {
  1149. return new ActiveXObject("Microsoft.XMLHTTP");
  1150. };
  1151. }
  1152. // Make the request, allowing the user to override any Ajax options.
  1153. var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
  1154. model.trigger('request', model, xhr, options);
  1155. return xhr;
  1156. };
  1157. var noXhrPatch =
  1158. typeof window !== 'undefined' && !!window.ActiveXObject &&
  1159. !(window.XMLHttpRequest && (new XMLHttpRequest).dispatchEvent);
  1160. // Map from CRUD to HTTP for our default `Backbone.sync` implementation.
  1161. var methodMap = {
  1162. 'create': 'POST',
  1163. 'update': 'PUT',
  1164. 'patch': 'PATCH',
  1165. 'delete': 'DELETE',
  1166. 'read': 'GET'
  1167. };
  1168. // Set the default implementation of `Backbone.ajax` to proxy through to `$`.
  1169. // Override this if you'd like to use a different library.
  1170. Backbone.ajax = function() {
  1171. return Backbone.$.ajax.apply(Backbone.$, arguments);
  1172. };
  1173. // Backbone.Router
  1174. // ---------------
  1175. // Routers map faux-URLs to actions, and fire events when routes are
  1176. // matched. Creating a new one sets its `routes` hash, if not set statically.
  1177. var Router = Backbone.Router = function(options) {
  1178. options || (options = {});
  1179. if (options.routes) this.routes = options.routes;
  1180. this._bindRoutes();
  1181. this.initialize.apply(this, arguments);
  1182. };
  1183. // Cached regular expressions for matching named param parts and splatted
  1184. // parts of route strings.
  1185. var optionalParam = /\((.*?)\)/g;
  1186. var namedParam = /(\(\?)?:\w+/g;
  1187. var splatParam = /\*\w+/g;
  1188. var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
  1189. // Set up all inheritable **Backbone.Router** properties and methods.
  1190. _.extend(Router.prototype, Events, {
  1191. // Initialize is an empty function by default. Override it with your own
  1192. // initialization logic.
  1193. initialize: function(){},
  1194. // Manually bind a single named route to a callback. For example:
  1195. //
  1196. // this.route('search/:query/p:num', 'search', function(query, num) {
  1197. // ...
  1198. // });
  1199. //
  1200. route: function(route, name, callback) {
  1201. if (!_.isRegExp(route)) route = this._routeToRegExp(route);
  1202. if (_.isFunction(name)) {
  1203. callback = name;
  1204. name = '';
  1205. }
  1206. if (!callback) callback = this[name];
  1207. var router = this;
  1208. Backbone.history.route(route, function(fragment) {
  1209. var args = router._extractParameters(route, fragment);
  1210. if (router.execute(callback, args) !== false) {
  1211. router.trigger.apply(router, ['route:' + name].concat(args));
  1212. router.trigger('route', name, args);
  1213. Backbone.history.trigger('route', router, name, args);
  1214. }
  1215. });
  1216. return this;
  1217. },
  1218. // Execute a route handler with the provided parameters. This is an
  1219. // excellent place to do pre-route setup or post-route cleanup.
  1220. execute: function(callback, args) {
  1221. if (callback) callback.apply(this, args);
  1222. },
  1223. // Simple proxy to `Backbone.history` to save a fragment into the history.
  1224. navigate: function(fragment, options) {
  1225. Backbone.history.navigate(fragment, options);
  1226. return this;
  1227. },
  1228. // Bind all defined routes to `Backbone.history`. We have to reverse the
  1229. // order of the routes here to support behavior where the most general
  1230. // routes can be defined at the bottom of the route map.
  1231. _bindRoutes: function() {
  1232. if (!this.routes) return;
  1233. this.routes = _.result(this, 'routes');
  1234. var route, routes = _.keys(this.routes);
  1235. while ((route = routes.pop()) != null) {
  1236. this.route(route, this.routes[route]);
  1237. }
  1238. },
  1239. // Convert a route string into a regular expression, suitable for matching
  1240. // against the current location hash.
  1241. _routeToRegExp: function(route) {
  1242. route = route.replace(escapeRegExp, '\\$&')
  1243. .replace(optionalParam, '(?:$1)?')
  1244. .replace(namedParam, function(match, optional) {
  1245. return optional ? match : '([^/?]+)';
  1246. })
  1247. .replace(splatParam, '([^?]*?)');
  1248. return new RegExp('^' + route + '(?:\\?([\\s\\S]*))?$');
  1249. },
  1250. // Given a route, and a URL fragment that it matches, return the array of
  1251. // extracted decoded parameters. Empty or unmatched parameters will be
  1252. // treated as `null` to normalize cross-browser behavior.
  1253. _extractParameters: function(route, fragment) {
  1254. var params = route.exec(fragment).slice(1);
  1255. return _.map(params, function(param, i) {
  1256. // Don't decode the search params.
  1257. if (i === params.length - 1) return param || null;
  1258. return param ? decodeURIComponent(param) : null;
  1259. });
  1260. }
  1261. });
  1262. // Backbone.History
  1263. // ----------------
  1264. // Handles cross-browser history management, based on either
  1265. // [pushState](http://diveintohtml5.info/history.html) and real URLs, or
  1266. // [onhashchange](https://developer.mozilla.org/en-US/docs/DOM/window.onhashchange)
  1267. // and URL fragments. If the browser supports neither (old IE, natch),
  1268. // falls back to polling.
  1269. var History = Backbone.History = function() {
  1270. this.handlers = [];
  1271. _.bindAll(this, 'checkUrl');
  1272. // Ensure that `History` can be used outside of the browser.
  1273. if (typeof window !== 'undefined') {
  1274. this.location = window.location;
  1275. this.history = window.history;
  1276. }
  1277. };
  1278. // Cached regex for stripping a leading hash/slash and trailing space.
  1279. var routeStripper = /^[#\/]|\s+$/g;
  1280. // Cached regex for stripping leading and trailing slashes.
  1281. var rootStripper = /^\/+|\/+$/g;
  1282. // Cached regex for removing a trailing slash.
  1283. var trailingSlash = /\/$/;
  1284. // Cached regex for stripping urls of hash.
  1285. var pathStripper = /#.*$/;
  1286. // Has the history handling already been started?
  1287. History.started = false;
  1288. // Set up all inheritable **Backbone.History** properties and methods.
  1289. _.extend(History.prototype, Events, {
  1290. // The default interval to poll for hash changes, if necessary, is
  1291. // twenty times a second.
  1292. interval: 50,
  1293. // Are we at the app root?
  1294. atRoot: function() {
  1295. return this.location.pathname.replace(/[^\/]$/, '$&/') === this.root;
  1296. },
  1297. // Gets the true hash value. Cannot use location.hash directly due to bug
  1298. // in Firefox where location.hash will always be decoded.
  1299. getHash: function(window) {
  1300. var match = (window || this).location.href.match(/#(.*)$/);
  1301. return match ? match[1] : '';
  1302. },
  1303. // Get the cross-browser normalized URL fragment, either from the URL,
  1304. // the hash, or the override.
  1305. getFragment: function(fragment, forcePushState) {
  1306. if (fragment == null) {
  1307. if (this._hasPushState || !this._wantsHashChange || forcePushState) {
  1308. fragment = decodeURI(this.location.pathname + this.location.search);
  1309. var root = this.root.replace(trailingSlash, '');
  1310. if (!fragment.indexOf(root)) fragment = fragment.slice(root.length);
  1311. } else {
  1312. fragment = this.getHash();
  1313. }
  1314. }
  1315. return fragment.replace(routeStripper, '');
  1316. },
  1317. // Start the hash change handling, returning `true` if the current URL matches
  1318. // an existing route, and `false` otherwise.
  1319. start: function(options) {
  1320. if (History.started) throw new Error("Backbone.history has already been started");
  1321. History.started = true;
  1322. // Figure out the initial configuration. Do we need an iframe?
  1323. // Is pushState desired ... is it available?
  1324. this.options = _.extend({root: '/'}, this.options, options);
  1325. this.root = this.options.root;
  1326. this._wantsHashChange = this.options.hashChange !== false;
  1327. this._hasHashChange = 'onhashchange' in window;
  1328. this._wantsPushState = !!this.options.pushState;
  1329. this._hasPushState = !!(this.options.pushState && this.history && this.history.pushState);
  1330. var fragment = this.getFragment();
  1331. // Add a cross-platform `addEventListener` shim for older browsers.
  1332. var addEventListener = window.addEventListener || function (eventName, listener) {
  1333. return attachEvent('on' + eventName, listener);
  1334. };
  1335. // Normalize root to always include a leading and trailing slash.
  1336. this.root = ('/' + this.root + '/').replace(rootStripper, '/');
  1337. // Proxy an iframe to handle location events if the browser doesn't
  1338. // support the `hashchange` event, HTML5 history, or the user wants
  1339. // `hashChange` but not `pushState`.
  1340. if (!this._hasHashChange && this._wantsHashChange && (!this._wantsPushState || !this._hasPushState)) {
  1341. var iframe = document.createElement('iframe');
  1342. iframe.src = 'javascript:0';
  1343. iframe.style.display = 'none';
  1344. iframe.tabIndex = -1;
  1345. var body = document.body;
  1346. // Using `appendChild` will throw on IE < 9 if the document is not ready.
  1347. this.iframe = body.insertBefore(iframe, body.firstChild).contentWindow;
  1348. this.navigate(fragment);
  1349. }
  1350. // Depending on whether we're using pushState or hashes, and whether
  1351. // 'onhashchange' is supported, determine how we check the URL state.
  1352. if (this._hasPushState) {
  1353. addEventListener('popstate', this.checkUrl, false);
  1354. } else if (this._wantsHashChange && this._hasHashChange && !this.iframe) {
  1355. addEventListener('hashchange', this.checkUrl, false);
  1356. } else if (this._wantsHashChange) {
  1357. this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
  1358. }
  1359. // Determine if we need to change the base url, for a pushState link
  1360. // opened by a non-pushState browser.
  1361. this.fragment = fragment;
  1362. var loc = this.location;
  1363. // Transition from hashChange to pushState or vice versa if both are
  1364. // requested.
  1365. if (this._wantsHashChange && this._wantsPushState) {
  1366. // If we've started off with a route from a `pushState`-enabled
  1367. // browser, but we're currently in a browser that doesn't support it...
  1368. if (!this._hasPushState && !this.atRoot()) {
  1369. this.fragment = this.getFragment(null, true);
  1370. this.location.replace(this.root + '#' + this.fragment);
  1371. // Return immediately as browser will do redirect to new url
  1372. return true;
  1373. // Or if we've started out with a hash-based route, but we're currently
  1374. // in a browser where it could be `pushState`-based instead...
  1375. } else if (this._hasPushState && this.atRoot() && loc.hash) {
  1376. this.fragment = this.getHash().replace(routeStripper, '');
  1377. this.history.replaceState({}, document.title, this.root + this.fragment);
  1378. }
  1379. }
  1380. if (!this.options.silent) return this.loadUrl();
  1381. },
  1382. // Disable Backbone.history, perhaps temporarily. Not useful in a real app,
  1383. // but possibly useful for unit testing Routers.
  1384. stop: function() {
  1385. // Add a cross-platform `removeEventListener` shim for older browsers.
  1386. var removeEventListener = window.removeEventListener || function (eventName, listener) {
  1387. return detachEvent('on' + eventName, listener);
  1388. };
  1389. if (this._hasPushState) {
  1390. removeEventListener('popstate', this.checkUrl, false);
  1391. } else if (this._wantsHashChange && this._hasHashChange && !this.iframe) {
  1392. removeEventListener('hashchange', this.checkUrl, false);
  1393. }
  1394. // Some environments will throw when clearing an undefined interval.
  1395. if (this._checkUrlInterval) clearInterval(this._checkUrlInterval);
  1396. History.started = false;
  1397. },
  1398. // Add a route to be tested when the fragment changes. Routes added later
  1399. // may override previous routes.
  1400. route: function(route, callback) {
  1401. this.handlers.unshift({route: route, callback: callback});
  1402. },
  1403. // Checks the current URL to see if it has changed, and if it has,
  1404. // calls `loadUrl`, normalizing across the hidden iframe.
  1405. checkUrl: function(e) {
  1406. var current = this.getFragment();
  1407. if (current === this.fragment && this.iframe) {
  1408. current = this.getFragment(this.getHash(this.iframe));
  1409. }
  1410. if (current === this.fragment) return false;
  1411. if (this.iframe) this.navigate(current);
  1412. this.loadUrl();
  1413. },
  1414. // Attempt to load the current URL fragment. If a route succeeds with a
  1415. // match, returns `true`. If no defined routes matches the fragment,
  1416. // returns `false`.
  1417. loadUrl: function(fragment) {
  1418. fragment = this.fragment = this.getFragment(fragment);
  1419. return _.any(this.handlers, function(handler) {
  1420. if (handler.route.test(fragment)) {
  1421. handler.callback(fragment);
  1422. return true;
  1423. }
  1424. });
  1425. },
  1426. // Save a fragment into the hash history, or replace the URL state if the
  1427. // 'replace' option is passed. You are responsible for properly URL-encoding
  1428. // the fragment in advance.
  1429. //
  1430. // The options object can contain `trigger: true` if you wish to have the
  1431. // route callback be fired (not usually desirable), or `replace: true`, if
  1432. // you wish to modify the current URL without adding an entry to the history.
  1433. navigate: function(fragment, options) {
  1434. if (!History.started) return false;
  1435. if (!options || options === true) options = {trigger: !!options};
  1436. var url = this.root + (fragment = this.getFragment(fragment || ''));
  1437. // Strip the hash for matching.
  1438. fragment = fragment.replace(pathStripper, '');
  1439. if (this.fragment === fragment) return;
  1440. this.fragment = fragment;
  1441. // Don't include a trailing slash on the root.
  1442. if (fragment === '' && url !== '/') url = url.slice(0, -1);
  1443. // If pushState is available, we use it to set the fragment as a real URL.
  1444. if (this._hasPushState) {
  1445. this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url);
  1446. // If hash changes haven't been explicitly disabled, update the hash
  1447. // fragment to store history.
  1448. } else if (this._wantsHashChange) {
  1449. this._updateHash(this.location, fragment, options.replace);
  1450. if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) {
  1451. // Opening and closing the iframe tricks IE7 and earlier to push a
  1452. // history entry on hash-tag change. When replace is true, we don't
  1453. // want this.
  1454. if(!options.replace) this.iframe.document.open().close();
  1455. this._updateHash(this.iframe.location, fragment, options.replace);
  1456. }
  1457. // If you've told us that you explicitly don't want fallback hashchange-
  1458. // based history, then `navigate` becomes a page refresh.
  1459. } else {
  1460. return this.location.assign(url);
  1461. }
  1462. if (options.trigger) return this.loadUrl(fragment);
  1463. },
  1464. // Update the hash location, either replacing the current entry, or adding
  1465. // a new one to the browser history.
  1466. _updateHash: function(location, fragment, replace) {
  1467. if (replace) {
  1468. var href = location.href.replace(/(javascript:|#).*$/, '');
  1469. location.replace(href + '#' + fragment);
  1470. } else {
  1471. // Some browsers require that `hash` contains a leading #.
  1472. location.hash = '#' + fragment;
  1473. }
  1474. }
  1475. });
  1476. // Create the default Backbone.history.
  1477. Backbone.history = new History;
  1478. // Helpers
  1479. // -------
  1480. // Helper function to correctly set up the prototype chain, for subclasses.
  1481. // Similar to `goog.inherits`, but uses a hash of prototype properties and
  1482. // class properties to be extended.
  1483. var extend = function(protoProps, staticProps) {
  1484. var parent = this;
  1485. var child;
  1486. // The constructor function for the new subclass is either defined by you
  1487. // (the "constructor" property in your `extend` definition), or defaulted
  1488. // by us to simply call the parent's constructor.
  1489. if (protoProps && _.has(protoProps, 'constructor')) {
  1490. child = protoProps.constructor;
  1491. } else {
  1492. child = function(){ return parent.apply(this, arguments); };
  1493. }
  1494. // Add static properties to the constructor function, if supplied.
  1495. _.extend(child, parent, staticProps);
  1496. // Set the prototype chain to inherit from `parent`, without calling
  1497. // `parent`'s constructor function.
  1498. var Surrogate = function(){ this.constructor = child; };
  1499. Surrogate.prototype = parent.prototype;
  1500. child.prototype = new Surrogate;
  1501. // Add prototype properties (instance properties) to the subclass,
  1502. // if supplied.
  1503. if (protoProps) _.extend(child.prototype, protoProps);
  1504. // Set a convenience property in case the parent's prototype is needed
  1505. // later.
  1506. child.__super__ = parent.prototype;
  1507. return child;
  1508. };
  1509. // Set up inheritance for the model, collection, router, view and history.
  1510. Model.extend = Collection.extend = Router.extend = View.extend = History.extend = extend;
  1511. // Throw an error when a URL is needed, and none is supplied.
  1512. var urlError = function() {
  1513. throw new Error('A "url" property or function must be specified');
  1514. };
  1515. // Wrap an optional error callback with a fallback error event.
  1516. var wrapError = function(model, options) {
  1517. var error = options.error;
  1518. options.error = function(resp) {
  1519. if (error) error(model, resp, options);
  1520. model.trigger('error', model, resp, options);
  1521. };
  1522. };
  1523. return Backbone;
  1524. }));
  1525. },{"underscore":7}],7:[function(require,module,exports){
  1526. // Underscore.js 1.6.0
  1527. // http://underscorejs.org
  1528. // (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1529. // Underscore may be freely distributed under the MIT license.
  1530. (function() {
  1531. // Baseline setup
  1532. // --------------
  1533. // Establish the root object, `window` in the browser, or `exports` on the server.
  1534. var root = this;
  1535. // Save the previous value of the `_` variable.
  1536. var previousUnderscore = root._;
  1537. // Establish the object that gets returned to break out of a loop iteration.
  1538. var breaker = {};
  1539. // Save bytes in the minified (but not gzipped) version:
  1540. var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  1541. // Create quick reference variables for speed access to core prototypes.
  1542. var
  1543. push = ArrayProto.push,
  1544. slice = ArrayProto.slice,
  1545. concat = ArrayProto.concat,
  1546. toString = ObjProto.toString,
  1547. hasOwnProperty = ObjProto.hasOwnProperty;
  1548. // All **ECMAScript 5** native function implementations that we hope to use
  1549. // are declared here.
  1550. var
  1551. nativeForEach = ArrayProto.forEach,
  1552. nativeMap = ArrayProto.map,
  1553. nativeReduce = ArrayProto.reduce,
  1554. nativeReduceRight = ArrayProto.reduceRight,
  1555. nativeFilter = ArrayProto.filter,
  1556. nativeEvery = ArrayProto.every,
  1557. nativeSome = ArrayProto.some,
  1558. nativeIndexOf = ArrayProto.indexOf,
  1559. nativeLastIndexOf = ArrayProto.lastIndexOf,
  1560. nativeIsArray = Array.isArray,
  1561. nativeKeys = Object.keys,
  1562. nativeBind = FuncProto.bind;
  1563. // Create a safe reference to the Underscore object for use below.
  1564. var _ = function(obj) {
  1565. if (obj instanceof _) return obj;
  1566. if (!(this instanceof _)) return new _(obj);
  1567. this._wrapped = obj;
  1568. };
  1569. // Export the Underscore object for **Node.js**, with
  1570. // backwards-compatibility for the old `require()` API. If we're in
  1571. // the browser, add `_` as a global object via a string identifier,
  1572. // for Closure Compiler "advanced" mode.
  1573. if (typeof exports !== 'undefined') {
  1574. if (typeof module !== 'undefined' && module.exports) {
  1575. exports = module.exports = _;
  1576. }
  1577. exports._ = _;
  1578. } else {
  1579. root._ = _;
  1580. }
  1581. // Current version.
  1582. _.VERSION = '1.6.0';
  1583. // Collection Functions
  1584. // --------------------
  1585. // The cornerstone, an `each` implementation, aka `forEach`.
  1586. // Handles objects with the built-in `forEach`, arrays, and raw objects.
  1587. // Delegates to **ECMAScript 5**'s native `forEach` if available.
  1588. var each = _.each = _.forEach = function(obj, iterator, context) {
  1589. if (obj == null) return obj;
  1590. if (nativeForEach && obj.forEach === nativeForEach) {
  1591. obj.forEach(iterator, context);
  1592. } else if (obj.length === +obj.length) {
  1593. for (var i = 0, length = obj.length; i < length; i++) {
  1594. if (iterator.call(context, obj[i], i, obj) === breaker) return;
  1595. }
  1596. } else {
  1597. var keys = _.keys(obj);
  1598. for (var i = 0, length = keys.length; i < length; i++) {
  1599. if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
  1600. }
  1601. }
  1602. return obj;
  1603. };
  1604. // Return the results of applying the iterator to each element.
  1605. // Delegates to **ECMAScript 5**'s native `map` if available.
  1606. _.map = _.collect = function(obj, iterator, context) {
  1607. var results = [];
  1608. if (obj == null) return results;
  1609. if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
  1610. each(obj, function(value, index, list) {
  1611. results.push(iterator.call(context, value, index, list));
  1612. });
  1613. return results;
  1614. };
  1615. var reduceError = 'Reduce of empty array with no initial value';
  1616. // **Reduce** builds up a single result from a list of values, aka `inject`,
  1617. // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
  1618. _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
  1619. var initial = arguments.length > 2;
  1620. if (obj == null) obj = [];
  1621. if (nativeReduce && obj.reduce === nativeReduce) {
  1622. if (context) iterator = _.bind(iterator, context);
  1623. return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
  1624. }
  1625. each(obj, function(value, index, list) {
  1626. if (!initial) {
  1627. memo = value;
  1628. initial = true;
  1629. } else {
  1630. memo = iterator.call(context, memo, value, index, list);
  1631. }
  1632. });
  1633. if (!initial) throw new TypeError(reduceError);
  1634. return memo;
  1635. };
  1636. // The right-associative version of reduce, also known as `foldr`.
  1637. // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
  1638. _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
  1639. var initial = arguments.length > 2;
  1640. if (obj == null) obj = [];
  1641. if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
  1642. if (context) iterator = _.bind(iterator, context);
  1643. return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
  1644. }
  1645. var length = obj.length;
  1646. if (length !== +length) {
  1647. var keys = _.keys(obj);
  1648. length = keys.length;
  1649. }
  1650. each(obj, function(value, index, list) {
  1651. index = keys ? keys[--length] : --length;
  1652. if (!initial) {
  1653. memo = obj[index];
  1654. initial = true;
  1655. } else {
  1656. memo = iterator.call(context, memo, obj[index], index, list);
  1657. }
  1658. });
  1659. if (!initial) throw new TypeError(reduceError);
  1660. return memo;
  1661. };
  1662. // Return the first value which passes a truth test. Aliased as `detect`.
  1663. _.find = _.detect = function(obj, predicate, context) {
  1664. var result;
  1665. any(obj, function(value, index, list) {
  1666. if (predicate.call(context, value, index, list)) {
  1667. result = value;
  1668. return true;
  1669. }
  1670. });
  1671. return result;
  1672. };
  1673. // Return all the elements that pass a truth test.
  1674. // Delegates to **ECMAScript 5**'s native `filter` if available.
  1675. // Aliased as `select`.
  1676. _.filter = _.select = function(obj, predicate, context) {
  1677. var results = [];
  1678. if (obj == null) return results;
  1679. if (nativeFilter && obj.filter === nativeFilter) return obj.filter(predicate, context);
  1680. each(obj, function(value, index, list) {
  1681. if (predicate.call(context, value, index, list)) results.push(value);
  1682. });
  1683. return results;
  1684. };
  1685. // Return all the elements for which a truth test fails.
  1686. _.reject = function(obj, predicate, context) {
  1687. return _.filter(obj, function(value, index, list) {
  1688. return !predicate.call(context, value, index, list);
  1689. }, context);
  1690. };
  1691. // Determine whether all of the elements match a truth test.
  1692. // Delegates to **ECMAScript 5**'s native `every` if available.
  1693. // Aliased as `all`.
  1694. _.every = _.all = function(obj, predicate, context) {
  1695. predicate || (predicate = _.identity);
  1696. var result = true;
  1697. if (obj == null) return result;
  1698. if (nativeEvery && obj.every === nativeEvery) return obj.every(predicate, context);
  1699. each(obj, function(value, index, list) {
  1700. if (!(result = result && predicate.call(context, value, index, list))) return breaker;
  1701. });
  1702. return !!result;
  1703. };
  1704. // Determine if at least one element in the object matches a truth test.
  1705. // Delegates to **ECMAScript 5**'s native `some` if available.
  1706. // Aliased as `any`.
  1707. var any = _.some = _.any = function(obj, predicate, context) {
  1708. predicate || (predicate = _.identity);
  1709. var result = false;
  1710. if (obj == null) return result;
  1711. if (nativeSome && obj.some === nativeSome) return obj.some(predicate, context);
  1712. each(obj, function(value, index, list) {
  1713. if (result || (result = predicate.call(context, value, index, list))) return breaker;
  1714. });
  1715. return !!result;
  1716. };
  1717. // Determine if the array or object contains a given value (using `===`).
  1718. // Aliased as `include`.
  1719. _.contains = _.include = function(obj, target) {
  1720. if (obj == null) return false;
  1721. if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
  1722. return any(obj, function(value) {
  1723. return value === target;
  1724. });
  1725. };
  1726. // Invoke a method (with arguments) on every item in a collection.
  1727. _.invoke = function(obj, method) {
  1728. var args = slice.call(arguments, 2);
  1729. var isFunc = _.isFunction(method);
  1730. return _.map(obj, function(value) {
  1731. return (isFunc ? method : value[method]).apply(value, args);
  1732. });
  1733. };
  1734. // Convenience version of a common use case of `map`: fetching a property.
  1735. _.pluck = function(obj, key) {
  1736. return _.map(obj, _.property(key));
  1737. };
  1738. // Convenience version of a common use case of `filter`: selecting only objects
  1739. // containing specific `key:value` pairs.
  1740. _.where = function(obj, attrs) {
  1741. return _.filter(obj, _.matches(attrs));
  1742. };
  1743. // Convenience version of a common use case of `find`: getting the first object
  1744. // containing specific `key:value` pairs.
  1745. _.findWhere = function(obj, attrs) {
  1746. return _.find(obj, _.matches(attrs));
  1747. };
  1748. // Return the maximum element or (element-based computation).
  1749. // Can't optimize arrays of integers longer than 65,535 elements.
  1750. // See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
  1751. _.max = function(obj, iterator, context) {
  1752. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  1753. return Math.max.apply(Math, obj);
  1754. }
  1755. var result = -Infinity, lastComputed = -Infinity;
  1756. each(obj, function(value, index, list) {
  1757. var computed = iterator ? iterator.call(context, value, index, list) : value;
  1758. if (computed > lastComputed) {
  1759. result = value;
  1760. lastComputed = computed;
  1761. }
  1762. });
  1763. return result;
  1764. };
  1765. // Return the minimum element (or element-based computation).
  1766. _.min = function(obj, iterator, context) {
  1767. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  1768. return Math.min.apply(Math, obj);
  1769. }
  1770. var result = Infinity, lastComputed = Infinity;
  1771. each(obj, function(value, index, list) {
  1772. var computed = iterator ? iterator.call(context, value, index, list) : value;
  1773. if (computed < lastComputed) {
  1774. result = value;
  1775. lastComputed = computed;
  1776. }
  1777. });
  1778. return result;
  1779. };
  1780. // Shuffle an array, using the modern version of the
  1781. // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
  1782. _.shuffle = function(obj) {
  1783. var rand;
  1784. var index = 0;
  1785. var shuffled = [];
  1786. each(obj, function(value) {
  1787. rand = _.random(index++);
  1788. shuffled[index - 1] = shuffled[rand];
  1789. shuffled[rand] = value;
  1790. });
  1791. return shuffled;
  1792. };
  1793. // Sample **n** random values from a collection.
  1794. // If **n** is not specified, returns a single random element.
  1795. // The internal `guard` argument allows it to work with `map`.
  1796. _.sample = function(obj, n, guard) {
  1797. if (n == null || guard) {
  1798. if (obj.length !== +obj.length) obj = _.values(obj);
  1799. return obj[_.random(obj.length - 1)];
  1800. }
  1801. return _.shuffle(obj).slice(0, Math.max(0, n));
  1802. };
  1803. // An internal function to generate lookup iterators.
  1804. var lookupIterator = function(value) {
  1805. if (value == null) return _.identity;
  1806. if (_.isFunction(value)) return value;
  1807. return _.property(value);
  1808. };
  1809. // Sort the object's values by a criterion produced by an iterator.
  1810. _.sortBy = function(obj, iterator, context) {
  1811. iterator = lookupIterator(iterator);
  1812. return _.pluck(_.map(obj, function(value, index, list) {
  1813. return {
  1814. value: value,
  1815. index: index,
  1816. criteria: iterator.call(context, value, index, list)
  1817. };
  1818. }).sort(function(left, right) {
  1819. var a = left.criteria;
  1820. var b = right.criteria;
  1821. if (a !== b) {
  1822. if (a > b || a === void 0) return 1;
  1823. if (a < b || b === void 0) return -1;
  1824. }
  1825. return left.index - right.index;
  1826. }), 'value');
  1827. };
  1828. // An internal function used for aggregate "group by" operations.
  1829. var group = function(behavior) {
  1830. return function(obj, iterator, context) {
  1831. var result = {};
  1832. iterator = lookupIterator(iterator);
  1833. each(obj, function(value, index) {
  1834. var key = iterator.call(context, value, index, obj);
  1835. behavior(result, key, value);
  1836. });
  1837. return result;
  1838. };
  1839. };
  1840. // Groups the object's values by a criterion. Pass either a string attribute
  1841. // to group by, or a function that returns the criterion.
  1842. _.groupBy = group(function(result, key, value) {
  1843. _.has(result, key) ? result[key].push(value) : result[key] = [value];
  1844. });
  1845. // Indexes the object's values by a criterion, similar to `groupBy`, but for
  1846. // when you know that your index values will be unique.
  1847. _.indexBy = group(function(result, key, value) {
  1848. result[key] = value;
  1849. });
  1850. // Counts instances of an object that group by a certain criterion. Pass
  1851. // either a string attribute to count by, or a function that returns the
  1852. // criterion.
  1853. _.countBy = group(function(result, key) {
  1854. _.has(result, key) ? result[key]++ : result[key] = 1;
  1855. });
  1856. // Use a comparator function to figure out the smallest index at which
  1857. // an object should be inserted so as to maintain order. Uses binary search.
  1858. _.sortedIndex = function(array, obj, iterator, context) {
  1859. iterator = lookupIterator(iterator);
  1860. var value = iterator.call(context, obj);
  1861. var low = 0, high = array.length;
  1862. while (low < high) {
  1863. var mid = (low + high) >>> 1;
  1864. iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
  1865. }
  1866. return low;
  1867. };
  1868. // Safely create a real, live array from anything iterable.
  1869. _.toArray = function(obj) {
  1870. if (!obj) return [];
  1871. if (_.isArray(obj)) return slice.call(obj);
  1872. if (obj.length === +obj.length) return _.map(obj, _.identity);
  1873. return _.values(obj);
  1874. };
  1875. // Return the number of elements in an object.
  1876. _.size = function(obj) {
  1877. if (obj == null) return 0;
  1878. return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
  1879. };
  1880. // Array Functions
  1881. // ---------------
  1882. // Get the first element of an array. Passing **n** will return the first N
  1883. // values in the array. Aliased as `head` and `take`. The **guard** check
  1884. // allows it to work with `_.map`.
  1885. _.first = _.head = _.take = function(array, n, guard) {
  1886. if (array == null) return void 0;
  1887. if ((n == null) || guard) return array[0];
  1888. if (n < 0) return [];
  1889. return slice.call(array, 0, n);
  1890. };
  1891. // Returns everything but the last entry of the array. Especially useful on
  1892. // the arguments object. Passing **n** will return all the values in
  1893. // the array, excluding the last N. The **guard** check allows it to work with
  1894. // `_.map`.
  1895. _.initial = function(array, n, guard) {
  1896. return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
  1897. };
  1898. // Get the last element of an array. Passing **n** will return the last N
  1899. // values in the array. The **guard** check allows it to work with `_.map`.
  1900. _.last = function(array, n, guard) {
  1901. if (array == null) return void 0;
  1902. if ((n == null) || guard) return array[array.length - 1];
  1903. return slice.call(array, Math.max(array.length - n, 0));
  1904. };
  1905. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  1906. // Especially useful on the arguments object. Passing an **n** will return
  1907. // the rest N values in the array. The **guard**
  1908. // check allows it to work with `_.map`.
  1909. _.rest = _.tail = _.drop = function(array, n, guard) {
  1910. return slice.call(array, (n == null) || guard ? 1 : n);
  1911. };
  1912. // Trim out all falsy values from an array.
  1913. _.compact = function(array) {
  1914. return _.filter(array, _.identity);
  1915. };
  1916. // Internal implementation of a recursive `flatten` function.
  1917. var flatten = function(input, shallow, output) {
  1918. if (shallow && _.every(input, _.isArray)) {
  1919. return concat.apply(output, input);
  1920. }
  1921. each(input, function(value) {
  1922. if (_.isArray(value) || _.isArguments(value)) {
  1923. shallow ? push.apply(output, value) : flatten(value, shallow, output);
  1924. } else {
  1925. output.push(value);
  1926. }
  1927. });
  1928. return output;
  1929. };
  1930. // Flatten out an array, either recursively (by default), or just one level.
  1931. _.flatten = function(array, shallow) {
  1932. return flatten(array, shallow, []);
  1933. };
  1934. // Return a version of the array that does not contain the specified value(s).
  1935. _.without = function(array) {
  1936. return _.difference(array, slice.call(arguments, 1));
  1937. };
  1938. // Split an array into two arrays: one whose elements all satisfy the given
  1939. // predicate, and one whose elements all do not satisfy the predicate.
  1940. _.partition = function(array, predicate) {
  1941. var pass = [], fail = [];
  1942. each(array, function(elem) {
  1943. (predicate(elem) ? pass : fail).push(elem);
  1944. });
  1945. return [pass, fail];
  1946. };
  1947. // Produce a duplicate-free version of the array. If the array has already
  1948. // been sorted, you have the option of using a faster algorithm.
  1949. // Aliased as `unique`.
  1950. _.uniq = _.unique = function(array, isSorted, iterator, context) {
  1951. if (_.isFunction(isSorted)) {
  1952. context = iterator;
  1953. iterator = isSorted;
  1954. isSorted = false;
  1955. }
  1956. var initial = iterator ? _.map(array, iterator, context) : array;
  1957. var results = [];
  1958. var seen = [];
  1959. each(initial, function(value, index) {
  1960. if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
  1961. seen.push(value);
  1962. results.push(array[index]);
  1963. }
  1964. });
  1965. return results;
  1966. };
  1967. // Produce an array that contains the union: each distinct element from all of
  1968. // the passed-in arrays.
  1969. _.union = function() {
  1970. return _.uniq(_.flatten(arguments, true));
  1971. };
  1972. // Produce an array that contains every item shared between all the
  1973. // passed-in arrays.
  1974. _.intersection = function(array) {
  1975. var rest = slice.call(arguments, 1);
  1976. return _.filter(_.uniq(array), function(item) {
  1977. return _.every(rest, function(other) {
  1978. return _.contains(other, item);
  1979. });
  1980. });
  1981. };
  1982. // Take the difference between one array and a number of other arrays.
  1983. // Only the elements present in just the first array will remain.
  1984. _.difference = function(array) {
  1985. var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
  1986. return _.filter(array, function(value){ return !_.contains(rest, value); });
  1987. };
  1988. // Zip together multiple lists into a single array -- elements that share
  1989. // an index go together.
  1990. _.zip = function() {
  1991. var length = _.max(_.pluck(arguments, 'length').concat(0));
  1992. var results = new Array(length);
  1993. for (var i = 0; i < length; i++) {
  1994. results[i] = _.pluck(arguments, '' + i);
  1995. }
  1996. return results;
  1997. };
  1998. // Converts lists into objects. Pass either a single array of `[key, value]`
  1999. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  2000. // the corresponding values.
  2001. _.object = function(list, values) {
  2002. if (list == null) return {};
  2003. var result = {};
  2004. for (var i = 0, length = list.length; i < length; i++) {
  2005. if (values) {
  2006. result[list[i]] = values[i];
  2007. } else {
  2008. result[list[i][0]] = list[i][1];
  2009. }
  2010. }
  2011. return result;
  2012. };
  2013. // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
  2014. // we need this function. Return the position of the first occurrence of an
  2015. // item in an array, or -1 if the item is not included in the array.
  2016. // Delegates to **ECMAScript 5**'s native `indexOf` if available.
  2017. // If the array is large and already in sort order, pass `true`
  2018. // for **isSorted** to use binary search.
  2019. _.indexOf = function(array, item, isSorted) {
  2020. if (array == null) return -1;
  2021. var i = 0, length = array.length;
  2022. if (isSorted) {
  2023. if (typeof isSorted == 'number') {
  2024. i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
  2025. } else {
  2026. i = _.sortedIndex(array, item);
  2027. return array[i] === item ? i : -1;
  2028. }
  2029. }
  2030. if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
  2031. for (; i < length; i++) if (array[i] === item) return i;
  2032. return -1;
  2033. };
  2034. // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
  2035. _.lastIndexOf = function(array, item, from) {
  2036. if (array == null) return -1;
  2037. var hasIndex = from != null;
  2038. if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
  2039. return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
  2040. }
  2041. var i = (hasIndex ? from : array.length);
  2042. while (i--) if (array[i] === item) return i;
  2043. return -1;
  2044. };
  2045. // Generate an integer Array containing an arithmetic progression. A port of
  2046. // the native Python `range()` function. See
  2047. // [the Python documentation](http://docs.python.org/library/functions.html#range).
  2048. _.range = function(start, stop, step) {
  2049. if (arguments.length <= 1) {
  2050. stop = start || 0;
  2051. start = 0;
  2052. }
  2053. step = arguments[2] || 1;
  2054. var length = Math.max(Math.ceil((stop - start) / step), 0);
  2055. var idx = 0;
  2056. var range = new Array(length);
  2057. while(idx < length) {
  2058. range[idx++] = start;
  2059. start += step;
  2060. }
  2061. return range;
  2062. };
  2063. // Function (ahem) Functions
  2064. // ------------------
  2065. // Reusable constructor function for prototype setting.
  2066. var ctor = function(){};
  2067. // Create a function bound to a given object (assigning `this`, and arguments,
  2068. // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  2069. // available.
  2070. _.bind = function(func, context) {
  2071. var args, bound;
  2072. if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  2073. if (!_.isFunction(func)) throw new TypeError;
  2074. args = slice.call(arguments, 2);
  2075. return bound = function() {
  2076. if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
  2077. ctor.prototype = func.prototype;
  2078. var self = new ctor;
  2079. ctor.prototype = null;
  2080. var result = func.apply(self, args.concat(slice.call(arguments)));
  2081. if (Object(result) === result) return result;
  2082. return self;
  2083. };
  2084. };
  2085. // Partially apply a function by creating a version that has had some of its
  2086. // arguments pre-filled, without changing its dynamic `this` context. _ acts
  2087. // as a placeholder, allowing any combination of arguments to be pre-filled.
  2088. _.partial = function(func) {
  2089. var boundArgs = slice.call(arguments, 1);
  2090. return function() {
  2091. var position = 0;
  2092. var args = boundArgs.slice();
  2093. for (var i = 0, length = args.length; i < length; i++) {
  2094. if (args[i] === _) args[i] = arguments[position++];
  2095. }
  2096. while (position < arguments.length) args.push(arguments[position++]);
  2097. return func.apply(this, args);
  2098. };
  2099. };
  2100. // Bind a number of an object's methods to that object. Remaining arguments
  2101. // are the method names to be bound. Useful for ensuring that all callbacks
  2102. // defined on an object belong to it.
  2103. _.bindAll = function(obj) {
  2104. var funcs = slice.call(arguments, 1);
  2105. if (funcs.length === 0) throw new Error('bindAll must be passed function names');
  2106. each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
  2107. return obj;
  2108. };
  2109. // Memoize an expensive function by storing its results.
  2110. _.memoize = function(func, hasher) {
  2111. var memo = {};
  2112. hasher || (hasher = _.identity);
  2113. return function() {
  2114. var key = hasher.apply(this, arguments);
  2115. return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
  2116. };
  2117. };
  2118. // Delays a function for the given number of milliseconds, and then calls
  2119. // it with the arguments supplied.
  2120. _.delay = function(func, wait) {
  2121. var args = slice.call(arguments, 2);
  2122. return setTimeout(function(){ return func.apply(null, args); }, wait);
  2123. };
  2124. // Defers a function, scheduling it to run after the current call stack has
  2125. // cleared.
  2126. _.defer = function(func) {
  2127. return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
  2128. };
  2129. // Returns a function, that, when invoked, will only be triggered at most once
  2130. // during a given window of time. Normally, the throttled function will run
  2131. // as much as it can, without ever going more than once per `wait` duration;
  2132. // but if you'd like to disable the execution on the leading edge, pass
  2133. // `{leading: false}`. To disable execution on the trailing edge, ditto.
  2134. _.throttle = function(func, wait, options) {
  2135. var context, args, result;
  2136. var timeout = null;
  2137. var previous = 0;
  2138. options || (options = {});
  2139. var later = function() {
  2140. previous = options.leading === false ? 0 : _.now();
  2141. timeout = null;
  2142. result = func.apply(context, args);
  2143. context = args = null;
  2144. };
  2145. return function() {
  2146. var now = _.now();
  2147. if (!previous && options.leading === false) previous = now;
  2148. var remaining = wait - (now - previous);
  2149. context = this;
  2150. args = arguments;
  2151. if (remaining <= 0) {
  2152. clearTimeout(timeout);
  2153. timeout = null;
  2154. previous = now;
  2155. result = func.apply(context, args);
  2156. context = args = null;
  2157. } else if (!timeout && options.trailing !== false) {
  2158. timeout = setTimeout(later, remaining);
  2159. }
  2160. return result;
  2161. };
  2162. };
  2163. // Returns a function, that, as long as it continues to be invoked, will not
  2164. // be triggered. The function will be called after it stops being called for
  2165. // N milliseconds. If `immediate` is passed, trigger the function on the
  2166. // leading edge, instead of the trailing.
  2167. _.debounce = function(func, wait, immediate) {
  2168. var timeout, args, context, timestamp, result;
  2169. var later = function() {
  2170. var last = _.now() - timestamp;
  2171. if (last < wait) {
  2172. timeout = setTimeout(later, wait - last);
  2173. } else {
  2174. timeout = null;
  2175. if (!immediate) {
  2176. result = func.apply(context, args);
  2177. context = args = null;
  2178. }
  2179. }
  2180. };
  2181. return function() {
  2182. context = this;
  2183. args = arguments;
  2184. timestamp = _.now();
  2185. var callNow = immediate && !timeout;
  2186. if (!timeout) {
  2187. timeout = setTimeout(later, wait);
  2188. }
  2189. if (callNow) {
  2190. result = func.apply(context, args);
  2191. context = args = null;
  2192. }
  2193. return result;
  2194. };
  2195. };
  2196. // Returns a function that will be executed at most one time, no matter how
  2197. // often you call it. Useful for lazy initialization.
  2198. _.once = function(func) {
  2199. var ran = false, memo;
  2200. return function() {
  2201. if (ran) return memo;
  2202. ran = true;
  2203. memo = func.apply(this, arguments);
  2204. func = null;
  2205. return memo;
  2206. };
  2207. };
  2208. // Returns the first function passed as an argument to the second,
  2209. // allowing you to adjust arguments, run code before and after, and
  2210. // conditionally execute the original function.
  2211. _.wrap = function(func, wrapper) {
  2212. return _.partial(wrapper, func);
  2213. };
  2214. // Returns a function that is the composition of a list of functions, each
  2215. // consuming the return value of the function that follows.
  2216. _.compose = function() {
  2217. var funcs = arguments;
  2218. return function() {
  2219. var args = arguments;
  2220. for (var i = funcs.length - 1; i >= 0; i--) {
  2221. args = [funcs[i].apply(this, args)];
  2222. }
  2223. return args[0];
  2224. };
  2225. };
  2226. // Returns a function that will only be executed after being called N times.
  2227. _.after = function(times, func) {
  2228. return function() {
  2229. if (--times < 1) {
  2230. return func.apply(this, arguments);
  2231. }
  2232. };
  2233. };
  2234. // Object Functions
  2235. // ----------------
  2236. // Retrieve the names of an object's properties.
  2237. // Delegates to **ECMAScript 5**'s native `Object.keys`
  2238. _.keys = function(obj) {
  2239. if (!_.isObject(obj)) return [];
  2240. if (nativeKeys) return nativeKeys(obj);
  2241. var keys = [];
  2242. for (var key in obj) if (_.has(obj, key)) keys.push(key);
  2243. return keys;
  2244. };
  2245. // Retrieve the values of an object's properties.
  2246. _.values = function(obj) {
  2247. var keys = _.keys(obj);
  2248. var length = keys.length;
  2249. var values = new Array(length);
  2250. for (var i = 0; i < length; i++) {
  2251. values[i] = obj[keys[i]];
  2252. }
  2253. return values;
  2254. };
  2255. // Convert an object into a list of `[key, value]` pairs.
  2256. _.pairs = function(obj) {
  2257. var keys = _.keys(obj);
  2258. var length = keys.length;
  2259. var pairs = new Array(length);
  2260. for (var i = 0; i < length; i++) {
  2261. pairs[i] = [keys[i], obj[keys[i]]];
  2262. }
  2263. return pairs;
  2264. };
  2265. // Invert the keys and values of an object. The values must be serializable.
  2266. _.invert = function(obj) {
  2267. var result = {};
  2268. var keys = _.keys(obj);
  2269. for (var i = 0, length = keys.length; i < length; i++) {
  2270. result[obj[keys[i]]] = keys[i];
  2271. }
  2272. return result;
  2273. };
  2274. // Return a sorted list of the function names available on the object.
  2275. // Aliased as `methods`
  2276. _.functions = _.methods = function(obj) {
  2277. var names = [];
  2278. for (var key in obj) {
  2279. if (_.isFunction(obj[key])) names.push(key);
  2280. }
  2281. return names.sort();
  2282. };
  2283. // Extend a given object with all the properties in passed-in object(s).
  2284. _.extend = function(obj) {
  2285. each(slice.call(arguments, 1), function(source) {
  2286. if (source) {
  2287. for (var prop in source) {
  2288. obj[prop] = source[prop];
  2289. }
  2290. }
  2291. });
  2292. return obj;
  2293. };
  2294. // Return a copy of the object only containing the whitelisted properties.
  2295. _.pick = function(obj) {
  2296. var copy = {};
  2297. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  2298. each(keys, function(key) {
  2299. if (key in obj) copy[key] = obj[key];
  2300. });
  2301. return copy;
  2302. };
  2303. // Return a copy of the object without the blacklisted properties.
  2304. _.omit = function(obj) {
  2305. var copy = {};
  2306. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  2307. for (var key in obj) {
  2308. if (!_.contains(keys, key)) copy[key] = obj[key];
  2309. }
  2310. return copy;
  2311. };
  2312. // Fill in a given object with default properties.
  2313. _.defaults = function(obj) {
  2314. each(slice.call(arguments, 1), function(source) {
  2315. if (source) {
  2316. for (var prop in source) {
  2317. if (obj[prop] === void 0) obj[prop] = source[prop];
  2318. }
  2319. }
  2320. });
  2321. return obj;
  2322. };
  2323. // Create a (shallow-cloned) duplicate of an object.
  2324. _.clone = function(obj) {
  2325. if (!_.isObject(obj)) return obj;
  2326. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  2327. };
  2328. // Invokes interceptor with the obj, and then returns obj.
  2329. // The primary purpose of this method is to "tap into" a method chain, in
  2330. // order to perform operations on intermediate results within the chain.
  2331. _.tap = function(obj, interceptor) {
  2332. interceptor(obj);
  2333. return obj;
  2334. };
  2335. // Internal recursive comparison function for `isEqual`.
  2336. var eq = function(a, b, aStack, bStack) {
  2337. // Identical objects are equal. `0 === -0`, but they aren't identical.
  2338. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
  2339. if (a === b) return a !== 0 || 1 / a == 1 / b;
  2340. // A strict comparison is necessary because `null == undefined`.
  2341. if (a == null || b == null) return a === b;
  2342. // Unwrap any wrapped objects.
  2343. if (a instanceof _) a = a._wrapped;
  2344. if (b instanceof _) b = b._wrapped;
  2345. // Compare `[[Class]]` names.
  2346. var className = toString.call(a);
  2347. if (className != toString.call(b)) return false;
  2348. switch (className) {
  2349. // Strings, numbers, dates, and booleans are compared by value.
  2350. case '[object String]':
  2351. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  2352. // equivalent to `new String("5")`.
  2353. return a == String(b);
  2354. case '[object Number]':
  2355. // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
  2356. // other numeric values.
  2357. return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
  2358. case '[object Date]':
  2359. case '[object Boolean]':
  2360. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  2361. // millisecond representations. Note that invalid dates with millisecond representations
  2362. // of `NaN` are not equivalent.
  2363. return +a == +b;
  2364. // RegExps are compared by their source patterns and flags.
  2365. case '[object RegExp]':
  2366. return a.source == b.source &&
  2367. a.global == b.global &&
  2368. a.multiline == b.multiline &&
  2369. a.ignoreCase == b.ignoreCase;
  2370. }
  2371. if (typeof a != 'object' || typeof b != 'object') return false;
  2372. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  2373. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  2374. var length = aStack.length;
  2375. while (length--) {
  2376. // Linear search. Performance is inversely proportional to the number of
  2377. // unique nested structures.
  2378. if (aStack[length] == a) return bStack[length] == b;
  2379. }
  2380. // Objects with different constructors are not equivalent, but `Object`s
  2381. // from different frames are.
  2382. var aCtor = a.constructor, bCtor = b.constructor;
  2383. if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
  2384. _.isFunction(bCtor) && (bCtor instanceof bCtor))
  2385. && ('constructor' in a && 'constructor' in b)) {
  2386. return false;
  2387. }
  2388. // Add the first object to the stack of traversed objects.
  2389. aStack.push(a);
  2390. bStack.push(b);
  2391. var size = 0, result = true;
  2392. // Recursively compare objects and arrays.
  2393. if (className == '[object Array]') {
  2394. // Compare array lengths to determine if a deep comparison is necessary.
  2395. size = a.length;
  2396. result = size == b.length;
  2397. if (result) {
  2398. // Deep compare the contents, ignoring non-numeric properties.
  2399. while (size--) {
  2400. if (!(result = eq(a[size], b[size], aStack, bStack))) break;
  2401. }
  2402. }
  2403. } else {
  2404. // Deep compare objects.
  2405. for (var key in a) {
  2406. if (_.has(a, key)) {
  2407. // Count the expected number of properties.
  2408. size++;
  2409. // Deep compare each member.
  2410. if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
  2411. }
  2412. }
  2413. // Ensure that both objects contain the same number of properties.
  2414. if (result) {
  2415. for (key in b) {
  2416. if (_.has(b, key) && !(size--)) break;
  2417. }
  2418. result = !size;
  2419. }
  2420. }
  2421. // Remove the first object from the stack of traversed objects.
  2422. aStack.pop();
  2423. bStack.pop();
  2424. return result;
  2425. };
  2426. // Perform a deep comparison to check if two objects are equal.
  2427. _.isEqual = function(a, b) {
  2428. return eq(a, b, [], []);
  2429. };
  2430. // Is a given array, string, or object empty?
  2431. // An "empty" object has no enumerable own-properties.
  2432. _.isEmpty = function(obj) {
  2433. if (obj == null) return true;
  2434. if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
  2435. for (var key in obj) if (_.has(obj, key)) return false;
  2436. return true;
  2437. };
  2438. // Is a given value a DOM element?
  2439. _.isElement = function(obj) {
  2440. return !!(obj && obj.nodeType === 1);
  2441. };
  2442. // Is a given value an array?
  2443. // Delegates to ECMA5's native Array.isArray
  2444. _.isArray = nativeIsArray || function(obj) {
  2445. return toString.call(obj) == '[object Array]';
  2446. };
  2447. // Is a given variable an object?
  2448. _.isObject = function(obj) {
  2449. return obj === Object(obj);
  2450. };
  2451. // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
  2452. each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
  2453. _['is' + name] = function(obj) {
  2454. return toString.call(obj) == '[object ' + name + ']';
  2455. };
  2456. });
  2457. // Define a fallback version of the method in browsers (ahem, IE), where
  2458. // there isn't any inspectable "Arguments" type.
  2459. if (!_.isArguments(arguments)) {
  2460. _.isArguments = function(obj) {
  2461. return !!(obj && _.has(obj, 'callee'));
  2462. };
  2463. }
  2464. // Optimize `isFunction` if appropriate.
  2465. if (typeof (/./) !== 'function') {
  2466. _.isFunction = function(obj) {
  2467. return typeof obj === 'function';
  2468. };
  2469. }
  2470. // Is a given object a finite number?
  2471. _.isFinite = function(obj) {
  2472. return isFinite(obj) && !isNaN(parseFloat(obj));
  2473. };
  2474. // Is the given value `NaN`? (NaN is the only number which does not equal itself).
  2475. _.isNaN = function(obj) {
  2476. return _.isNumber(obj) && obj != +obj;
  2477. };
  2478. // Is a given value a boolean?
  2479. _.isBoolean = function(obj) {
  2480. return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
  2481. };
  2482. // Is a given value equal to null?
  2483. _.isNull = function(obj) {
  2484. return obj === null;
  2485. };
  2486. // Is a given variable undefined?
  2487. _.isUndefined = function(obj) {
  2488. return obj === void 0;
  2489. };
  2490. // Shortcut function for checking if an object has a given property directly
  2491. // on itself (in other words, not on a prototype).
  2492. _.has = function(obj, key) {
  2493. return hasOwnProperty.call(obj, key);
  2494. };
  2495. // Utility Functions
  2496. // -----------------
  2497. // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  2498. // previous owner. Returns a reference to the Underscore object.
  2499. _.noConflict = function() {
  2500. root._ = previousUnderscore;
  2501. return this;
  2502. };
  2503. // Keep the identity function around for default iterators.
  2504. _.identity = function(value) {
  2505. return value;
  2506. };
  2507. _.constant = function(value) {
  2508. return function () {
  2509. return value;
  2510. };
  2511. };
  2512. _.property = function(key) {
  2513. return function(obj) {
  2514. return obj[key];
  2515. };
  2516. };
  2517. // Returns a predicate for checking whether an object has a given set of `key:value` pairs.
  2518. _.matches = function(attrs) {
  2519. return function(obj) {
  2520. if (obj === attrs) return true; //avoid comparing an object to itself.
  2521. for (var key in attrs) {
  2522. if (attrs[key] !== obj[key])
  2523. return false;
  2524. }
  2525. return true;
  2526. }
  2527. };
  2528. // Run a function **n** times.
  2529. _.times = function(n, iterator, context) {
  2530. var accum = Array(Math.max(0, n));
  2531. for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
  2532. return accum;
  2533. };
  2534. // Return a random integer between min and max (inclusive).
  2535. _.random = function(min, max) {
  2536. if (max == null) {
  2537. max = min;
  2538. min = 0;
  2539. }
  2540. return min + Math.floor(Math.random() * (max - min + 1));
  2541. };
  2542. // A (possibly faster) way to get the current timestamp as an integer.
  2543. _.now = Date.now || function() { return new Date().getTime(); };
  2544. // List of HTML entities for escaping.
  2545. var entityMap = {
  2546. escape: {
  2547. '&': '&amp;',
  2548. '<': '&lt;',
  2549. '>': '&gt;',
  2550. '"': '&quot;',
  2551. "'": '&#x27;'
  2552. }
  2553. };
  2554. entityMap.unescape = _.invert(entityMap.escape);
  2555. // Regexes containing the keys and values listed immediately above.
  2556. var entityRegexes = {
  2557. escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
  2558. unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
  2559. };
  2560. // Functions for escaping and unescaping strings to/from HTML interpolation.
  2561. _.each(['escape', 'unescape'], function(method) {
  2562. _[method] = function(string) {
  2563. if (string == null) return '';
  2564. return ('' + string).replace(entityRegexes[method], function(match) {
  2565. return entityMap[method][match];
  2566. });
  2567. };
  2568. });
  2569. // If the value of the named `property` is a function then invoke it with the
  2570. // `object` as context; otherwise, return it.
  2571. _.result = function(object, property) {
  2572. if (object == null) return void 0;
  2573. var value = object[property];
  2574. return _.isFunction(value) ? value.call(object) : value;
  2575. };
  2576. // Add your own custom functions to the Underscore object.
  2577. _.mixin = function(obj) {
  2578. each(_.functions(obj), function(name) {
  2579. var func = _[name] = obj[name];
  2580. _.prototype[name] = function() {
  2581. var args = [this._wrapped];
  2582. push.apply(args, arguments);
  2583. return result.call(this, func.apply(_, args));
  2584. };
  2585. });
  2586. };
  2587. // Generate a unique integer id (unique within the entire client session).
  2588. // Useful for temporary DOM ids.
  2589. var idCounter = 0;
  2590. _.uniqueId = function(prefix) {
  2591. var id = ++idCounter + '';
  2592. return prefix ? prefix + id : id;
  2593. };
  2594. // By default, Underscore uses ERB-style template delimiters, change the
  2595. // following template settings to use alternative delimiters.
  2596. _.templateSettings = {
  2597. evaluate : /<%([\s\S]+?)%>/g,
  2598. interpolate : /<%=([\s\S]+?)%>/g,
  2599. escape : /<%-([\s\S]+?)%>/g
  2600. };
  2601. // When customizing `templateSettings`, if you don't want to define an
  2602. // interpolation, evaluation or escaping regex, we need one that is
  2603. // guaranteed not to match.
  2604. var noMatch = /(.)^/;
  2605. // Certain characters need to be escaped so that they can be put into a
  2606. // string literal.
  2607. var escapes = {
  2608. "'": "'",
  2609. '\\': '\\',
  2610. '\r': 'r',
  2611. '\n': 'n',
  2612. '\t': 't',
  2613. '\u2028': 'u2028',
  2614. '\u2029': 'u2029'
  2615. };
  2616. var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
  2617. // JavaScript micro-templating, similar to John Resig's implementation.
  2618. // Underscore templating handles arbitrary delimiters, preserves whitespace,
  2619. // and correctly escapes quotes within interpolated code.
  2620. _.template = function(text, data, settings) {
  2621. var render;
  2622. settings = _.defaults({}, settings, _.templateSettings);
  2623. // Combine delimiters into one regular expression via alternation.
  2624. var matcher = new RegExp([
  2625. (settings.escape || noMatch).source,
  2626. (settings.interpolate || noMatch).source,
  2627. (settings.evaluate || noMatch).source
  2628. ].join('|') + '|$', 'g');
  2629. // Compile the template source, escaping string literals appropriately.
  2630. var index = 0;
  2631. var source = "__p+='";
  2632. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  2633. source += text.slice(index, offset)
  2634. .replace(escaper, function(match) { return '\\' + escapes[match]; });
  2635. if (escape) {
  2636. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  2637. }
  2638. if (interpolate) {
  2639. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  2640. }
  2641. if (evaluate) {
  2642. source += "';\n" + evaluate + "\n__p+='";
  2643. }
  2644. index = offset + match.length;
  2645. return match;
  2646. });
  2647. source += "';\n";
  2648. // If a variable is not specified, place data values in local scope.
  2649. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  2650. source = "var __t,__p='',__j=Array.prototype.join," +
  2651. "print=function(){__p+=__j.call(arguments,'');};\n" +
  2652. source + "return __p;\n";
  2653. try {
  2654. render = new Function(settings.variable || 'obj', '_', source);
  2655. } catch (e) {
  2656. e.source = source;
  2657. throw e;
  2658. }
  2659. if (data) return render(data, _);
  2660. var template = function(data) {
  2661. return render.call(this, data, _);
  2662. };
  2663. // Provide the compiled function source as a convenience for precompilation.
  2664. template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
  2665. return template;
  2666. };
  2667. // Add a "chain" function, which will delegate to the wrapper.
  2668. _.chain = function(obj) {
  2669. return _(obj).chain();
  2670. };
  2671. // OOP
  2672. // ---------------
  2673. // If Underscore is called as a function, it returns a wrapped object that
  2674. // can be used OO-style. This wrapper holds altered versions of all the
  2675. // underscore functions. Wrapped objects may be chained.
  2676. // Helper function to continue chaining intermediate results.
  2677. var result = function(obj) {
  2678. return this._chain ? _(obj).chain() : obj;
  2679. };
  2680. // Add all of the Underscore functions to the wrapper object.
  2681. _.mixin(_);
  2682. // Add all mutator Array functions to the wrapper.
  2683. each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  2684. var method = ArrayProto[name];
  2685. _.prototype[name] = function() {
  2686. var obj = this._wrapped;
  2687. method.apply(obj, arguments);
  2688. if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
  2689. return result.call(this, obj);
  2690. };
  2691. });
  2692. // Add all accessor Array functions to the wrapper.
  2693. each(['concat', 'join', 'slice'], function(name) {
  2694. var method = ArrayProto[name];
  2695. _.prototype[name] = function() {
  2696. return result.call(this, method.apply(this._wrapped, arguments));
  2697. };
  2698. });
  2699. _.extend(_.prototype, {
  2700. // Start chaining a wrapped Underscore object.
  2701. chain: function() {
  2702. this._chain = true;
  2703. return this;
  2704. },
  2705. // Extracts the result from a wrapped and chained object.
  2706. value: function() {
  2707. return this._wrapped;
  2708. }
  2709. });
  2710. // AMD registration happens at the end for compatibility with AMD loaders
  2711. // that may not enforce next-turn semantics on modules. Even though general
  2712. // practice for AMD registration is to be anonymous, underscore registers
  2713. // as a named module because, like jQuery, it is a base library that is
  2714. // popular enough to be bundled in a third party lib, but not be part of
  2715. // an AMD load request. Those cases could generate an error when an
  2716. // anonymous define() is called outside of a loader request.
  2717. if (typeof define === 'function' && define.amd) {
  2718. define('underscore', [], function() {
  2719. return _;
  2720. });
  2721. }
  2722. }).call(this);
  2723. },{}],8:[function(require,module,exports){
  2724. },{}],9:[function(require,module,exports){
  2725. (function (global){
  2726. !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.jade=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2727. 'use strict';
  2728. /**
  2729. * Merge two attribute objects giving precedence
  2730. * to values in object `b`. Classes are special-cased
  2731. * allowing for arrays and merging/joining appropriately
  2732. * resulting in a string.
  2733. *
  2734. * @param {Object} a
  2735. * @param {Object} b
  2736. * @return {Object} a
  2737. * @api private
  2738. */
  2739. exports.merge = function merge(a, b) {
  2740. if (arguments.length === 1) {
  2741. var attrs = a[0];
  2742. for (var i = 1; i < a.length; i++) {
  2743. attrs = merge(attrs, a[i]);
  2744. }
  2745. return attrs;
  2746. }
  2747. var ac = a['class'];
  2748. var bc = b['class'];
  2749. if (ac || bc) {
  2750. ac = ac || [];
  2751. bc = bc || [];
  2752. if (!Array.isArray(ac)) ac = [ac];
  2753. if (!Array.isArray(bc)) bc = [bc];
  2754. a['class'] = ac.concat(bc).filter(nulls);
  2755. }
  2756. for (var key in b) {
  2757. if (key != 'class') {
  2758. a[key] = b[key];
  2759. }
  2760. }
  2761. return a;
  2762. };
  2763. /**
  2764. * Filter null `val`s.
  2765. *
  2766. * @param {*} val
  2767. * @return {Boolean}
  2768. * @api private
  2769. */
  2770. function nulls(val) {
  2771. return val != null && val !== '';
  2772. }
  2773. /**
  2774. * join array as classes.
  2775. *
  2776. * @param {*} val
  2777. * @return {String}
  2778. */
  2779. exports.joinClasses = joinClasses;
  2780. function joinClasses(val) {
  2781. return Array.isArray(val) ? val.map(joinClasses).filter(nulls).join(' ') : val;
  2782. }
  2783. /**
  2784. * Render the given classes.
  2785. *
  2786. * @param {Array} classes
  2787. * @param {Array.<Boolean>} escaped
  2788. * @return {String}
  2789. */
  2790. exports.cls = function cls(classes, escaped) {
  2791. var buf = [];
  2792. for (var i = 0; i < classes.length; i++) {
  2793. if (escaped && escaped[i]) {
  2794. buf.push(exports.escape(joinClasses([classes[i]])));
  2795. } else {
  2796. buf.push(joinClasses(classes[i]));
  2797. }
  2798. }
  2799. var text = joinClasses(buf);
  2800. if (text.length) {
  2801. return ' class="' + text + '"';
  2802. } else {
  2803. return '';
  2804. }
  2805. };
  2806. /**
  2807. * Render the given attribute.
  2808. *
  2809. * @param {String} key
  2810. * @param {String} val
  2811. * @param {Boolean} escaped
  2812. * @param {Boolean} terse
  2813. * @return {String}
  2814. */
  2815. exports.attr = function attr(key, val, escaped, terse) {
  2816. if ('boolean' == typeof val || null == val) {
  2817. if (val) {
  2818. return ' ' + (terse ? key : key + '="' + key + '"');
  2819. } else {
  2820. return '';
  2821. }
  2822. } else if (0 == key.indexOf('data') && 'string' != typeof val) {
  2823. return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, '&apos;') + "'";
  2824. } else if (escaped) {
  2825. return ' ' + key + '="' + exports.escape(val) + '"';
  2826. } else {
  2827. return ' ' + key + '="' + val + '"';
  2828. }
  2829. };
  2830. /**
  2831. * Render the given attributes object.
  2832. *
  2833. * @param {Object} obj
  2834. * @param {Object} escaped
  2835. * @return {String}
  2836. */
  2837. exports.attrs = function attrs(obj, terse){
  2838. var buf = [];
  2839. var keys = Object.keys(obj);
  2840. if (keys.length) {
  2841. for (var i = 0; i < keys.length; ++i) {
  2842. var key = keys[i]
  2843. , val = obj[key];
  2844. if ('class' == key) {
  2845. if (val = joinClasses(val)) {
  2846. buf.push(' ' + key + '="' + val + '"');
  2847. }
  2848. } else {
  2849. buf.push(exports.attr(key, val, false, terse));
  2850. }
  2851. }
  2852. }
  2853. return buf.join('');
  2854. };
  2855. /**
  2856. * Escape the given string of `html`.
  2857. *
  2858. * @param {String} html
  2859. * @return {String}
  2860. * @api private
  2861. */
  2862. exports.escape = function escape(html){
  2863. var result = String(html)
  2864. .replace(/&/g, '&amp;')
  2865. .replace(/</g, '&lt;')
  2866. .replace(/>/g, '&gt;')
  2867. .replace(/"/g, '&quot;');
  2868. if (result === '' + html) return html;
  2869. else return result;
  2870. };
  2871. /**
  2872. * Re-throw the given `err` in context to the
  2873. * the jade in `filename` at the given `lineno`.
  2874. *
  2875. * @param {Error} err
  2876. * @param {String} filename
  2877. * @param {String} lineno
  2878. * @api private
  2879. */
  2880. exports.rethrow = function rethrow(err, filename, lineno, str){
  2881. if (!(err instanceof Error)) throw err;
  2882. if ((typeof window != 'undefined' || !filename) && !str) {
  2883. err.message += ' on line ' + lineno;
  2884. throw err;
  2885. }
  2886. try {
  2887. str = str || require('fs').readFileSync(filename, 'utf8')
  2888. } catch (ex) {
  2889. rethrow(err, null, lineno)
  2890. }
  2891. var context = 3
  2892. , lines = str.split('\n')
  2893. , start = Math.max(lineno - context, 0)
  2894. , end = Math.min(lines.length, lineno + context);
  2895. // Error context
  2896. var context = lines.slice(start, end).map(function(line, i){
  2897. var curr = i + start + 1;
  2898. return (curr == lineno ? ' > ' : ' ')
  2899. + curr
  2900. + '| '
  2901. + line;
  2902. }).join('\n');
  2903. // Alter exception message
  2904. err.path = filename;
  2905. err.message = (filename || 'Jade') + ':' + lineno
  2906. + '\n' + context + '\n\n' + err.message;
  2907. throw err;
  2908. };
  2909. },{"fs":2}],2:[function(require,module,exports){
  2910. },{}]},{},[1])
  2911. (1)
  2912. });
  2913. }).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2914. },{"fs":8}],10:[function(require,module,exports){
  2915. /*!
  2916. * jQuery JavaScript Library v2.1.0
  2917. * http://jquery.com/
  2918. *
  2919. * Includes Sizzle.js
  2920. * http://sizzlejs.com/
  2921. *
  2922. * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
  2923. * Released under the MIT license
  2924. * http://jquery.org/license
  2925. *
  2926. * Date: 2014-01-23T21:10Z
  2927. */
  2928. (function( global, factory ) {
  2929. if ( typeof module === "object" && typeof module.exports === "object" ) {
  2930. // For CommonJS and CommonJS-like environments where a proper window is present,
  2931. // execute the factory and get jQuery
  2932. // For environments that do not inherently posses a window with a document
  2933. // (such as Node.js), expose a jQuery-making factory as module.exports
  2934. // This accentuates the need for the creation of a real window
  2935. // e.g. var jQuery = require("jquery")(window);
  2936. // See ticket #14549 for more info
  2937. module.exports = global.document ?
  2938. factory( global, true ) :
  2939. function( w ) {
  2940. if ( !w.document ) {
  2941. throw new Error( "jQuery requires a window with a document" );
  2942. }
  2943. return factory( w );
  2944. };
  2945. } else {
  2946. factory( global );
  2947. }
  2948. // Pass this if window is not defined yet
  2949. }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
  2950. // Can't do this because several apps including ASP.NET trace
  2951. // the stack via arguments.caller.callee and Firefox dies if
  2952. // you try to trace through "use strict" call chains. (#13335)
  2953. // Support: Firefox 18+
  2954. //
  2955. var arr = [];
  2956. var slice = arr.slice;
  2957. var concat = arr.concat;
  2958. var push = arr.push;
  2959. var indexOf = arr.indexOf;
  2960. var class2type = {};
  2961. var toString = class2type.toString;
  2962. var hasOwn = class2type.hasOwnProperty;
  2963. var trim = "".trim;
  2964. var support = {};
  2965. var
  2966. // Use the correct document accordingly with window argument (sandbox)
  2967. document = window.document,
  2968. version = "2.1.0",
  2969. // Define a local copy of jQuery
  2970. jQuery = function( selector, context ) {
  2971. // The jQuery object is actually just the init constructor 'enhanced'
  2972. // Need init if jQuery is called (just allow error to be thrown if not included)
  2973. return new jQuery.fn.init( selector, context );
  2974. },
  2975. // Matches dashed string for camelizing
  2976. rmsPrefix = /^-ms-/,
  2977. rdashAlpha = /-([\da-z])/gi,
  2978. // Used by jQuery.camelCase as callback to replace()
  2979. fcamelCase = function( all, letter ) {
  2980. return letter.toUpperCase();
  2981. };
  2982. jQuery.fn = jQuery.prototype = {
  2983. // The current version of jQuery being used
  2984. jquery: version,
  2985. constructor: jQuery,
  2986. // Start with an empty selector
  2987. selector: "",
  2988. // The default length of a jQuery object is 0
  2989. length: 0,
  2990. toArray: function() {
  2991. return slice.call( this );
  2992. },
  2993. // Get the Nth element in the matched element set OR
  2994. // Get the whole matched element set as a clean array
  2995. get: function( num ) {
  2996. return num != null ?
  2997. // Return a 'clean' array
  2998. ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
  2999. // Return just the object
  3000. slice.call( this );
  3001. },
  3002. // Take an array of elements and push it onto the stack
  3003. // (returning the new matched element set)
  3004. pushStack: function( elems ) {
  3005. // Build a new jQuery matched element set
  3006. var ret = jQuery.merge( this.constructor(), elems );
  3007. // Add the old object onto the stack (as a reference)
  3008. ret.prevObject = this;
  3009. ret.context = this.context;
  3010. // Return the newly-formed element set
  3011. return ret;
  3012. },
  3013. // Execute a callback for every element in the matched set.
  3014. // (You can seed the arguments with an array of args, but this is
  3015. // only used internally.)
  3016. each: function( callback, args ) {
  3017. return jQuery.each( this, callback, args );
  3018. },
  3019. map: function( callback ) {
  3020. return this.pushStack( jQuery.map(this, function( elem, i ) {
  3021. return callback.call( elem, i, elem );
  3022. }));
  3023. },
  3024. slice: function() {
  3025. return this.pushStack( slice.apply( this, arguments ) );
  3026. },
  3027. first: function() {
  3028. return this.eq( 0 );
  3029. },
  3030. last: function() {
  3031. return this.eq( -1 );
  3032. },
  3033. eq: function( i ) {
  3034. var len = this.length,
  3035. j = +i + ( i < 0 ? len : 0 );
  3036. return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
  3037. },
  3038. end: function() {
  3039. return this.prevObject || this.constructor(null);
  3040. },
  3041. // For internal use only.
  3042. // Behaves like an Array's method, not like a jQuery method.
  3043. push: push,
  3044. sort: arr.sort,
  3045. splice: arr.splice
  3046. };
  3047. jQuery.extend = jQuery.fn.extend = function() {
  3048. var options, name, src, copy, copyIsArray, clone,
  3049. target = arguments[0] || {},
  3050. i = 1,
  3051. length = arguments.length,
  3052. deep = false;
  3053. // Handle a deep copy situation
  3054. if ( typeof target === "boolean" ) {
  3055. deep = target;
  3056. // skip the boolean and the target
  3057. target = arguments[ i ] || {};
  3058. i++;
  3059. }
  3060. // Handle case when target is a string or something (possible in deep copy)
  3061. if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
  3062. target = {};
  3063. }
  3064. // extend jQuery itself if only one argument is passed
  3065. if ( i === length ) {
  3066. target = this;
  3067. i--;
  3068. }
  3069. for ( ; i < length; i++ ) {
  3070. // Only deal with non-null/undefined values
  3071. if ( (options = arguments[ i ]) != null ) {
  3072. // Extend the base object
  3073. for ( name in options ) {
  3074. src = target[ name ];
  3075. copy = options[ name ];
  3076. // Prevent never-ending loop
  3077. if ( target === copy ) {
  3078. continue;
  3079. }
  3080. // Recurse if we're merging plain objects or arrays
  3081. if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
  3082. if ( copyIsArray ) {
  3083. copyIsArray = false;
  3084. clone = src && jQuery.isArray(src) ? src : [];
  3085. } else {
  3086. clone = src && jQuery.isPlainObject(src) ? src : {};
  3087. }
  3088. // Never move original objects, clone them
  3089. target[ name ] = jQuery.extend( deep, clone, copy );
  3090. // Don't bring in undefined values
  3091. } else if ( copy !== undefined ) {
  3092. target[ name ] = copy;
  3093. }
  3094. }
  3095. }
  3096. }
  3097. // Return the modified object
  3098. return target;
  3099. };
  3100. jQuery.extend({
  3101. // Unique for each copy of jQuery on the page
  3102. expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
  3103. // Assume jQuery is ready without the ready module
  3104. isReady: true,
  3105. error: function( msg ) {
  3106. throw new Error( msg );
  3107. },
  3108. noop: function() {},
  3109. // See test/unit/core.js for details concerning isFunction.
  3110. // Since version 1.3, DOM methods and functions like alert
  3111. // aren't supported. They return false on IE (#2968).
  3112. isFunction: function( obj ) {
  3113. return jQuery.type(obj) === "function";
  3114. },
  3115. isArray: Array.isArray,
  3116. isWindow: function( obj ) {
  3117. return obj != null && obj === obj.window;
  3118. },
  3119. isNumeric: function( obj ) {
  3120. // parseFloat NaNs numeric-cast false positives (null|true|false|"")
  3121. // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  3122. // subtraction forces infinities to NaN
  3123. return obj - parseFloat( obj ) >= 0;
  3124. },
  3125. isPlainObject: function( obj ) {
  3126. // Not plain objects:
  3127. // - Any object or value whose internal [[Class]] property is not "[object Object]"
  3128. // - DOM nodes
  3129. // - window
  3130. if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
  3131. return false;
  3132. }
  3133. // Support: Firefox <20
  3134. // The try/catch suppresses exceptions thrown when attempting to access
  3135. // the "constructor" property of certain host objects, ie. |window.location|
  3136. // https://bugzilla.mozilla.org/show_bug.cgi?id=814622
  3137. try {
  3138. if ( obj.constructor &&
  3139. !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
  3140. return false;
  3141. }
  3142. } catch ( e ) {
  3143. return false;
  3144. }
  3145. // If the function hasn't returned already, we're confident that
  3146. // |obj| is a plain object, created by {} or constructed with new Object
  3147. return true;
  3148. },
  3149. isEmptyObject: function( obj ) {
  3150. var name;
  3151. for ( name in obj ) {
  3152. return false;
  3153. }
  3154. return true;
  3155. },
  3156. type: function( obj ) {
  3157. if ( obj == null ) {
  3158. return obj + "";
  3159. }
  3160. // Support: Android < 4.0, iOS < 6 (functionish RegExp)
  3161. return typeof obj === "object" || typeof obj === "function" ?
  3162. class2type[ toString.call(obj) ] || "object" :
  3163. typeof obj;
  3164. },
  3165. // Evaluates a script in a global context
  3166. globalEval: function( code ) {
  3167. var script,
  3168. indirect = eval;
  3169. code = jQuery.trim( code );
  3170. if ( code ) {
  3171. // If the code includes a valid, prologue position
  3172. // strict mode pragma, execute code by injecting a
  3173. // script tag into the document.
  3174. if ( code.indexOf("use strict") === 1 ) {
  3175. script = document.createElement("script");
  3176. script.text = code;
  3177. document.head.appendChild( script ).parentNode.removeChild( script );
  3178. } else {
  3179. // Otherwise, avoid the DOM node creation, insertion
  3180. // and removal by using an indirect global eval
  3181. indirect( code );
  3182. }
  3183. }
  3184. },
  3185. // Convert dashed to camelCase; used by the css and data modules
  3186. // Microsoft forgot to hump their vendor prefix (#9572)
  3187. camelCase: function( string ) {
  3188. return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
  3189. },
  3190. nodeName: function( elem, name ) {
  3191. return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
  3192. },
  3193. // args is for internal usage only
  3194. each: function( obj, callback, args ) {
  3195. var value,
  3196. i = 0,
  3197. length = obj.length,
  3198. isArray = isArraylike( obj );
  3199. if ( args ) {
  3200. if ( isArray ) {
  3201. for ( ; i < length; i++ ) {
  3202. value = callback.apply( obj[ i ], args );
  3203. if ( value === false ) {
  3204. break;
  3205. }
  3206. }
  3207. } else {
  3208. for ( i in obj ) {
  3209. value = callback.apply( obj[ i ], args );
  3210. if ( value === false ) {
  3211. break;
  3212. }
  3213. }
  3214. }
  3215. // A special, fast, case for the most common use of each
  3216. } else {
  3217. if ( isArray ) {
  3218. for ( ; i < length; i++ ) {
  3219. value = callback.call( obj[ i ], i, obj[ i ] );
  3220. if ( value === false ) {
  3221. break;
  3222. }
  3223. }
  3224. } else {
  3225. for ( i in obj ) {
  3226. value = callback.call( obj[ i ], i, obj[ i ] );
  3227. if ( value === false ) {
  3228. break;
  3229. }
  3230. }
  3231. }
  3232. }
  3233. return obj;
  3234. },
  3235. trim: function( text ) {
  3236. return text == null ? "" : trim.call( text );
  3237. },
  3238. // results is for internal usage only
  3239. makeArray: function( arr, results ) {
  3240. var ret = results || [];
  3241. if ( arr != null ) {
  3242. if ( isArraylike( Object(arr) ) ) {
  3243. jQuery.merge( ret,
  3244. typeof arr === "string" ?
  3245. [ arr ] : arr
  3246. );
  3247. } else {
  3248. push.call( ret, arr );
  3249. }
  3250. }
  3251. return ret;
  3252. },
  3253. inArray: function( elem, arr, i ) {
  3254. return arr == null ? -1 : indexOf.call( arr, elem, i );
  3255. },
  3256. merge: function( first, second ) {
  3257. var len = +second.length,
  3258. j = 0,
  3259. i = first.length;
  3260. for ( ; j < len; j++ ) {
  3261. first[ i++ ] = second[ j ];
  3262. }
  3263. first.length = i;
  3264. return first;
  3265. },
  3266. grep: function( elems, callback, invert ) {
  3267. var callbackInverse,
  3268. matches = [],
  3269. i = 0,
  3270. length = elems.length,
  3271. callbackExpect = !invert;
  3272. // Go through the array, only saving the items
  3273. // that pass the validator function
  3274. for ( ; i < length; i++ ) {
  3275. callbackInverse = !callback( elems[ i ], i );
  3276. if ( callbackInverse !== callbackExpect ) {
  3277. matches.push( elems[ i ] );
  3278. }
  3279. }
  3280. return matches;
  3281. },
  3282. // arg is for internal usage only
  3283. map: function( elems, callback, arg ) {
  3284. var value,
  3285. i = 0,
  3286. length = elems.length,
  3287. isArray = isArraylike( elems ),
  3288. ret = [];
  3289. // Go through the array, translating each of the items to their new values
  3290. if ( isArray ) {
  3291. for ( ; i < length; i++ ) {
  3292. value = callback( elems[ i ], i, arg );
  3293. if ( value != null ) {
  3294. ret.push( value );
  3295. }
  3296. }
  3297. // Go through every key on the object,
  3298. } else {
  3299. for ( i in elems ) {
  3300. value = callback( elems[ i ], i, arg );
  3301. if ( value != null ) {
  3302. ret.push( value );
  3303. }
  3304. }
  3305. }
  3306. // Flatten any nested arrays
  3307. return concat.apply( [], ret );
  3308. },
  3309. // A global GUID counter for objects
  3310. guid: 1,
  3311. // Bind a function to a context, optionally partially applying any
  3312. // arguments.
  3313. proxy: function( fn, context ) {
  3314. var tmp, args, proxy;
  3315. if ( typeof context === "string" ) {
  3316. tmp = fn[ context ];
  3317. context = fn;
  3318. fn = tmp;
  3319. }
  3320. // Quick check to determine if target is callable, in the spec
  3321. // this throws a TypeError, but we will just return undefined.
  3322. if ( !jQuery.isFunction( fn ) ) {
  3323. return undefined;
  3324. }
  3325. // Simulated bind
  3326. args = slice.call( arguments, 2 );
  3327. proxy = function() {
  3328. return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
  3329. };
  3330. // Set the guid of unique handler to the same of original handler, so it can be removed
  3331. proxy.guid = fn.guid = fn.guid || jQuery.guid++;
  3332. return proxy;
  3333. },
  3334. now: Date.now,
  3335. // jQuery.support is not used in Core but other projects attach their
  3336. // properties to it so it needs to exist.
  3337. support: support
  3338. });
  3339. // Populate the class2type map
  3340. jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
  3341. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  3342. });
  3343. function isArraylike( obj ) {
  3344. var length = obj.length,
  3345. type = jQuery.type( obj );
  3346. if ( type === "function" || jQuery.isWindow( obj ) ) {
  3347. return false;
  3348. }
  3349. if ( obj.nodeType === 1 && length ) {
  3350. return true;
  3351. }
  3352. return type === "array" || length === 0 ||
  3353. typeof length === "number" && length > 0 && ( length - 1 ) in obj;
  3354. }
  3355. var Sizzle =
  3356. /*!
  3357. * Sizzle CSS Selector Engine v1.10.16
  3358. * http://sizzlejs.com/
  3359. *
  3360. * Copyright 2013 jQuery Foundation, Inc. and other contributors
  3361. * Released under the MIT license
  3362. * http://jquery.org/license
  3363. *
  3364. * Date: 2014-01-13
  3365. */
  3366. (function( window ) {
  3367. var i,
  3368. support,
  3369. Expr,
  3370. getText,
  3371. isXML,
  3372. compile,
  3373. outermostContext,
  3374. sortInput,
  3375. hasDuplicate,
  3376. // Local document vars
  3377. setDocument,
  3378. document,
  3379. docElem,
  3380. documentIsHTML,
  3381. rbuggyQSA,
  3382. rbuggyMatches,
  3383. matches,
  3384. contains,
  3385. // Instance-specific data
  3386. expando = "sizzle" + -(new Date()),
  3387. preferredDoc = window.document,
  3388. dirruns = 0,
  3389. done = 0,
  3390. classCache = createCache(),
  3391. tokenCache = createCache(),
  3392. compilerCache = createCache(),
  3393. sortOrder = function( a, b ) {
  3394. if ( a === b ) {
  3395. hasDuplicate = true;
  3396. }
  3397. return 0;
  3398. },
  3399. // General-purpose constants
  3400. strundefined = typeof undefined,
  3401. MAX_NEGATIVE = 1 << 31,
  3402. // Instance methods
  3403. hasOwn = ({}).hasOwnProperty,
  3404. arr = [],
  3405. pop = arr.pop,
  3406. push_native = arr.push,
  3407. push = arr.push,
  3408. slice = arr.slice,
  3409. // Use a stripped-down indexOf if we can't use a native one
  3410. indexOf = arr.indexOf || function( elem ) {
  3411. var i = 0,
  3412. len = this.length;
  3413. for ( ; i < len; i++ ) {
  3414. if ( this[i] === elem ) {
  3415. return i;
  3416. }
  3417. }
  3418. return -1;
  3419. },
  3420. booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
  3421. // Regular expressions
  3422. // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
  3423. whitespace = "[\\x20\\t\\r\\n\\f]",
  3424. // http://www.w3.org/TR/css3-syntax/#characters
  3425. characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
  3426. // Loosely modeled on CSS identifier characters
  3427. // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
  3428. // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
  3429. identifier = characterEncoding.replace( "w", "w#" ),
  3430. // Acceptable operators http://www.w3.org/TR/selectors/#attribute-selectors
  3431. attributes = "\\[" + whitespace + "*(" + characterEncoding + ")" + whitespace +
  3432. "*(?:([*^$|!~]?=)" + whitespace + "*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|(" + identifier + ")|)|)" + whitespace + "*\\]",
  3433. // Prefer arguments quoted,
  3434. // then not containing pseudos/brackets,
  3435. // then attribute selectors/non-parenthetical expressions,
  3436. // then anything else
  3437. // These preferences are here to reduce the number of selectors
  3438. // needing tokenize in the PSEUDO preFilter
  3439. pseudos = ":(" + characterEncoding + ")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\\)|)",
  3440. // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
  3441. rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
  3442. rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
  3443. rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
  3444. rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
  3445. rpseudo = new RegExp( pseudos ),
  3446. ridentifier = new RegExp( "^" + identifier + "$" ),
  3447. matchExpr = {
  3448. "ID": new RegExp( "^#(" + characterEncoding + ")" ),
  3449. "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
  3450. "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
  3451. "ATTR": new RegExp( "^" + attributes ),
  3452. "PSEUDO": new RegExp( "^" + pseudos ),
  3453. "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
  3454. "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
  3455. "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
  3456. "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
  3457. // For use in libraries implementing .is()
  3458. // We use this for POS matching in `select`
  3459. "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
  3460. whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
  3461. },
  3462. rinputs = /^(?:input|select|textarea|button)$/i,
  3463. rheader = /^h\d$/i,
  3464. rnative = /^[^{]+\{\s*\[native \w/,
  3465. // Easily-parseable/retrievable ID or TAG or CLASS selectors
  3466. rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
  3467. rsibling = /[+~]/,
  3468. rescape = /'|\\/g,
  3469. // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
  3470. runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
  3471. funescape = function( _, escaped, escapedWhitespace ) {
  3472. var high = "0x" + escaped - 0x10000;
  3473. // NaN means non-codepoint
  3474. // Support: Firefox
  3475. // Workaround erroneous numeric interpretation of +"0x"
  3476. return high !== high || escapedWhitespace ?
  3477. escaped :
  3478. high < 0 ?
  3479. // BMP codepoint
  3480. String.fromCharCode( high + 0x10000 ) :
  3481. // Supplemental Plane codepoint (surrogate pair)
  3482. String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
  3483. };
  3484. // Optimize for push.apply( _, NodeList )
  3485. try {
  3486. push.apply(
  3487. (arr = slice.call( preferredDoc.childNodes )),
  3488. preferredDoc.childNodes
  3489. );
  3490. // Support: Android<4.0
  3491. // Detect silently failing push.apply
  3492. arr[ preferredDoc.childNodes.length ].nodeType;
  3493. } catch ( e ) {
  3494. push = { apply: arr.length ?
  3495. // Leverage slice if possible
  3496. function( target, els ) {
  3497. push_native.apply( target, slice.call(els) );
  3498. } :
  3499. // Support: IE<9
  3500. // Otherwise append directly
  3501. function( target, els ) {
  3502. var j = target.length,
  3503. i = 0;
  3504. // Can't trust NodeList.length
  3505. while ( (target[j++] = els[i++]) ) {}
  3506. target.length = j - 1;
  3507. }
  3508. };
  3509. }
  3510. function Sizzle( selector, context, results, seed ) {
  3511. var match, elem, m, nodeType,
  3512. // QSA vars
  3513. i, groups, old, nid, newContext, newSelector;
  3514. if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
  3515. setDocument( context );
  3516. }
  3517. context = context || document;
  3518. results = results || [];
  3519. if ( !selector || typeof selector !== "string" ) {
  3520. return results;
  3521. }
  3522. if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) {
  3523. return [];
  3524. }
  3525. if ( documentIsHTML && !seed ) {
  3526. // Shortcuts
  3527. if ( (match = rquickExpr.exec( selector )) ) {
  3528. // Speed-up: Sizzle("#ID")
  3529. if ( (m = match[1]) ) {
  3530. if ( nodeType === 9 ) {
  3531. elem = context.getElementById( m );
  3532. // Check parentNode to catch when Blackberry 4.6 returns
  3533. // nodes that are no longer in the document (jQuery #6963)
  3534. if ( elem && elem.parentNode ) {
  3535. // Handle the case where IE, Opera, and Webkit return items
  3536. // by name instead of ID
  3537. if ( elem.id === m ) {
  3538. results.push( elem );
  3539. return results;
  3540. }
  3541. } else {
  3542. return results;
  3543. }
  3544. } else {
  3545. // Context is not a document
  3546. if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
  3547. contains( context, elem ) && elem.id === m ) {
  3548. results.push( elem );
  3549. return results;
  3550. }
  3551. }
  3552. // Speed-up: Sizzle("TAG")
  3553. } else if ( match[2] ) {
  3554. push.apply( results, context.getElementsByTagName( selector ) );
  3555. return results;
  3556. // Speed-up: Sizzle(".CLASS")
  3557. } else if ( (m = match[3]) && support.getElementsByClassName && context.getElementsByClassName ) {
  3558. push.apply( results, context.getElementsByClassName( m ) );
  3559. return results;
  3560. }
  3561. }
  3562. // QSA path
  3563. if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
  3564. nid = old = expando;
  3565. newContext = context;
  3566. newSelector = nodeType === 9 && selector;
  3567. // qSA works strangely on Element-rooted queries
  3568. // We can work around this by specifying an extra ID on the root
  3569. // and working up from there (Thanks to Andrew Dupont for the technique)
  3570. // IE 8 doesn't work on object elements
  3571. if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
  3572. groups = tokenize( selector );
  3573. if ( (old = context.getAttribute("id")) ) {
  3574. nid = old.replace( rescape, "\\$&" );
  3575. } else {
  3576. context.setAttribute( "id", nid );
  3577. }
  3578. nid = "[id='" + nid + "'] ";
  3579. i = groups.length;
  3580. while ( i-- ) {
  3581. groups[i] = nid + toSelector( groups[i] );
  3582. }
  3583. newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
  3584. newSelector = groups.join(",");
  3585. }
  3586. if ( newSelector ) {
  3587. try {
  3588. push.apply( results,
  3589. newContext.querySelectorAll( newSelector )
  3590. );
  3591. return results;
  3592. } catch(qsaError) {
  3593. } finally {
  3594. if ( !old ) {
  3595. context.removeAttribute("id");
  3596. }
  3597. }
  3598. }
  3599. }
  3600. }
  3601. // All others
  3602. return select( selector.replace( rtrim, "$1" ), context, results, seed );
  3603. }
  3604. /**
  3605. * Create key-value caches of limited size
  3606. * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
  3607. * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
  3608. * deleting the oldest entry
  3609. */
  3610. function createCache() {
  3611. var keys = [];
  3612. function cache( key, value ) {
  3613. // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
  3614. if ( keys.push( key + " " ) > Expr.cacheLength ) {
  3615. // Only keep the most recent entries
  3616. delete cache[ keys.shift() ];
  3617. }
  3618. return (cache[ key + " " ] = value);
  3619. }
  3620. return cache;
  3621. }
  3622. /**
  3623. * Mark a function for special use by Sizzle
  3624. * @param {Function} fn The function to mark
  3625. */
  3626. function markFunction( fn ) {
  3627. fn[ expando ] = true;
  3628. return fn;
  3629. }
  3630. /**
  3631. * Support testing using an element
  3632. * @param {Function} fn Passed the created div and expects a boolean result
  3633. */
  3634. function assert( fn ) {
  3635. var div = document.createElement("div");
  3636. try {
  3637. return !!fn( div );
  3638. } catch (e) {
  3639. return false;
  3640. } finally {
  3641. // Remove from its parent by default
  3642. if ( div.parentNode ) {
  3643. div.parentNode.removeChild( div );
  3644. }
  3645. // release memory in IE
  3646. div = null;
  3647. }
  3648. }
  3649. /**
  3650. * Adds the same handler for all of the specified attrs
  3651. * @param {String} attrs Pipe-separated list of attributes
  3652. * @param {Function} handler The method that will be applied
  3653. */
  3654. function addHandle( attrs, handler ) {
  3655. var arr = attrs.split("|"),
  3656. i = attrs.length;
  3657. while ( i-- ) {
  3658. Expr.attrHandle[ arr[i] ] = handler;
  3659. }
  3660. }
  3661. /**
  3662. * Checks document order of two siblings
  3663. * @param {Element} a
  3664. * @param {Element} b
  3665. * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
  3666. */
  3667. function siblingCheck( a, b ) {
  3668. var cur = b && a,
  3669. diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
  3670. ( ~b.sourceIndex || MAX_NEGATIVE ) -
  3671. ( ~a.sourceIndex || MAX_NEGATIVE );
  3672. // Use IE sourceIndex if available on both nodes
  3673. if ( diff ) {
  3674. return diff;
  3675. }
  3676. // Check if b follows a
  3677. if ( cur ) {
  3678. while ( (cur = cur.nextSibling) ) {
  3679. if ( cur === b ) {
  3680. return -1;
  3681. }
  3682. }
  3683. }
  3684. return a ? 1 : -1;
  3685. }
  3686. /**
  3687. * Returns a function to use in pseudos for input types
  3688. * @param {String} type
  3689. */
  3690. function createInputPseudo( type ) {
  3691. return function( elem ) {
  3692. var name = elem.nodeName.toLowerCase();
  3693. return name === "input" && elem.type === type;
  3694. };
  3695. }
  3696. /**
  3697. * Returns a function to use in pseudos for buttons
  3698. * @param {String} type
  3699. */
  3700. function createButtonPseudo( type ) {
  3701. return function( elem ) {
  3702. var name = elem.nodeName.toLowerCase();
  3703. return (name === "input" || name === "button") && elem.type === type;
  3704. };
  3705. }
  3706. /**
  3707. * Returns a function to use in pseudos for positionals
  3708. * @param {Function} fn
  3709. */
  3710. function createPositionalPseudo( fn ) {
  3711. return markFunction(function( argument ) {
  3712. argument = +argument;
  3713. return markFunction(function( seed, matches ) {
  3714. var j,
  3715. matchIndexes = fn( [], seed.length, argument ),
  3716. i = matchIndexes.length;
  3717. // Match elements found at the specified indexes
  3718. while ( i-- ) {
  3719. if ( seed[ (j = matchIndexes[i]) ] ) {
  3720. seed[j] = !(matches[j] = seed[j]);
  3721. }
  3722. }
  3723. });
  3724. });
  3725. }
  3726. /**
  3727. * Checks a node for validity as a Sizzle context
  3728. * @param {Element|Object=} context
  3729. * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
  3730. */
  3731. function testContext( context ) {
  3732. return context && typeof context.getElementsByTagName !== strundefined && context;
  3733. }
  3734. // Expose support vars for convenience
  3735. support = Sizzle.support = {};
  3736. /**
  3737. * Detects XML nodes
  3738. * @param {Element|Object} elem An element or a document
  3739. * @returns {Boolean} True iff elem is a non-HTML XML node
  3740. */
  3741. isXML = Sizzle.isXML = function( elem ) {
  3742. // documentElement is verified for cases where it doesn't yet exist
  3743. // (such as loading iframes in IE - #4833)
  3744. var documentElement = elem && (elem.ownerDocument || elem).documentElement;
  3745. return documentElement ? documentElement.nodeName !== "HTML" : false;
  3746. };
  3747. /**
  3748. * Sets document-related variables once based on the current document
  3749. * @param {Element|Object} [doc] An element or document object to use to set the document
  3750. * @returns {Object} Returns the current document
  3751. */
  3752. setDocument = Sizzle.setDocument = function( node ) {
  3753. var hasCompare,
  3754. doc = node ? node.ownerDocument || node : preferredDoc,
  3755. parent = doc.defaultView;
  3756. // If no document and documentElement is available, return
  3757. if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
  3758. return document;
  3759. }
  3760. // Set our document
  3761. document = doc;
  3762. docElem = doc.documentElement;
  3763. // Support tests
  3764. documentIsHTML = !isXML( doc );
  3765. // Support: IE>8
  3766. // If iframe document is assigned to "document" variable and if iframe has been reloaded,
  3767. // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
  3768. // IE6-8 do not support the defaultView property so parent will be undefined
  3769. if ( parent && parent !== parent.top ) {
  3770. // IE11 does not have attachEvent, so all must suffer
  3771. if ( parent.addEventListener ) {
  3772. parent.addEventListener( "unload", function() {
  3773. setDocument();
  3774. }, false );
  3775. } else if ( parent.attachEvent ) {
  3776. parent.attachEvent( "onunload", function() {
  3777. setDocument();
  3778. });
  3779. }
  3780. }
  3781. /* Attributes
  3782. ---------------------------------------------------------------------- */
  3783. // Support: IE<8
  3784. // Verify that getAttribute really returns attributes and not properties (excepting IE8 booleans)
  3785. support.attributes = assert(function( div ) {
  3786. div.className = "i";
  3787. return !div.getAttribute("className");
  3788. });
  3789. /* getElement(s)By*
  3790. ---------------------------------------------------------------------- */
  3791. // Check if getElementsByTagName("*") returns only elements
  3792. support.getElementsByTagName = assert(function( div ) {
  3793. div.appendChild( doc.createComment("") );
  3794. return !div.getElementsByTagName("*").length;
  3795. });
  3796. // Check if getElementsByClassName can be trusted
  3797. support.getElementsByClassName = rnative.test( doc.getElementsByClassName ) && assert(function( div ) {
  3798. div.innerHTML = "<div class='a'></div><div class='a i'></div>";
  3799. // Support: Safari<4
  3800. // Catch class over-caching
  3801. div.firstChild.className = "i";
  3802. // Support: Opera<10
  3803. // Catch gEBCN failure to find non-leading classes
  3804. return div.getElementsByClassName("i").length === 2;
  3805. });
  3806. // Support: IE<10
  3807. // Check if getElementById returns elements by name
  3808. // The broken getElementById methods don't pick up programatically-set names,
  3809. // so use a roundabout getElementsByName test
  3810. support.getById = assert(function( div ) {
  3811. docElem.appendChild( div ).id = expando;
  3812. return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
  3813. });
  3814. // ID find and filter
  3815. if ( support.getById ) {
  3816. Expr.find["ID"] = function( id, context ) {
  3817. if ( typeof context.getElementById !== strundefined && documentIsHTML ) {
  3818. var m = context.getElementById( id );
  3819. // Check parentNode to catch when Blackberry 4.6 returns
  3820. // nodes that are no longer in the document #6963
  3821. return m && m.parentNode ? [m] : [];
  3822. }
  3823. };
  3824. Expr.filter["ID"] = function( id ) {
  3825. var attrId = id.replace( runescape, funescape );
  3826. return function( elem ) {
  3827. return elem.getAttribute("id") === attrId;
  3828. };
  3829. };
  3830. } else {
  3831. // Support: IE6/7
  3832. // getElementById is not reliable as a find shortcut
  3833. delete Expr.find["ID"];
  3834. Expr.filter["ID"] = function( id ) {
  3835. var attrId = id.replace( runescape, funescape );
  3836. return function( elem ) {
  3837. var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode("id");
  3838. return node && node.value === attrId;
  3839. };
  3840. };
  3841. }
  3842. // Tag
  3843. Expr.find["TAG"] = support.getElementsByTagName ?
  3844. function( tag, context ) {
  3845. if ( typeof context.getElementsByTagName !== strundefined ) {
  3846. return context.getElementsByTagName( tag );
  3847. }
  3848. } :
  3849. function( tag, context ) {
  3850. var elem,
  3851. tmp = [],
  3852. i = 0,
  3853. results = context.getElementsByTagName( tag );
  3854. // Filter out possible comments
  3855. if ( tag === "*" ) {
  3856. while ( (elem = results[i++]) ) {
  3857. if ( elem.nodeType === 1 ) {
  3858. tmp.push( elem );
  3859. }
  3860. }
  3861. return tmp;
  3862. }
  3863. return results;
  3864. };
  3865. // Class
  3866. Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
  3867. if ( typeof context.getElementsByClassName !== strundefined && documentIsHTML ) {
  3868. return context.getElementsByClassName( className );
  3869. }
  3870. };
  3871. /* QSA/matchesSelector
  3872. ---------------------------------------------------------------------- */
  3873. // QSA and matchesSelector support
  3874. // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
  3875. rbuggyMatches = [];
  3876. // qSa(:focus) reports false when true (Chrome 21)
  3877. // We allow this because of a bug in IE8/9 that throws an error
  3878. // whenever `document.activeElement` is accessed on an iframe
  3879. // So, we allow :focus to pass through QSA all the time to avoid the IE error
  3880. // See http://bugs.jquery.com/ticket/13378
  3881. rbuggyQSA = [];
  3882. if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
  3883. // Build QSA regex
  3884. // Regex strategy adopted from Diego Perini
  3885. assert(function( div ) {
  3886. // Select is set to empty string on purpose
  3887. // This is to test IE's treatment of not explicitly
  3888. // setting a boolean content attribute,
  3889. // since its presence should be enough
  3890. // http://bugs.jquery.com/ticket/12359
  3891. div.innerHTML = "<select t=''><option selected=''></option></select>";
  3892. // Support: IE8, Opera 10-12
  3893. // Nothing should be selected when empty strings follow ^= or $= or *=
  3894. if ( div.querySelectorAll("[t^='']").length ) {
  3895. rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
  3896. }
  3897. // Support: IE8
  3898. // Boolean attributes and "value" are not treated correctly
  3899. if ( !div.querySelectorAll("[selected]").length ) {
  3900. rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
  3901. }
  3902. // Webkit/Opera - :checked should return selected option elements
  3903. // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  3904. // IE8 throws error here and will not see later tests
  3905. if ( !div.querySelectorAll(":checked").length ) {
  3906. rbuggyQSA.push(":checked");
  3907. }
  3908. });
  3909. assert(function( div ) {
  3910. // Support: Windows 8 Native Apps
  3911. // The type and name attributes are restricted during .innerHTML assignment
  3912. var input = doc.createElement("input");
  3913. input.setAttribute( "type", "hidden" );
  3914. div.appendChild( input ).setAttribute( "name", "D" );
  3915. // Support: IE8
  3916. // Enforce case-sensitivity of name attribute
  3917. if ( div.querySelectorAll("[name=d]").length ) {
  3918. rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
  3919. }
  3920. // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
  3921. // IE8 throws error here and will not see later tests
  3922. if ( !div.querySelectorAll(":enabled").length ) {
  3923. rbuggyQSA.push( ":enabled", ":disabled" );
  3924. }
  3925. // Opera 10-11 does not throw on post-comma invalid pseudos
  3926. div.querySelectorAll("*,:x");
  3927. rbuggyQSA.push(",.*:");
  3928. });
  3929. }
  3930. if ( (support.matchesSelector = rnative.test( (matches = docElem.webkitMatchesSelector ||
  3931. docElem.mozMatchesSelector ||
  3932. docElem.oMatchesSelector ||
  3933. docElem.msMatchesSelector) )) ) {
  3934. assert(function( div ) {
  3935. // Check to see if it's possible to do matchesSelector
  3936. // on a disconnected node (IE 9)
  3937. support.disconnectedMatch = matches.call( div, "div" );
  3938. // This should fail with an exception
  3939. // Gecko does not error, returns false instead
  3940. matches.call( div, "[s!='']:x" );
  3941. rbuggyMatches.push( "!=", pseudos );
  3942. });
  3943. }
  3944. rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
  3945. rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
  3946. /* Contains
  3947. ---------------------------------------------------------------------- */
  3948. hasCompare = rnative.test( docElem.compareDocumentPosition );
  3949. // Element contains another
  3950. // Purposefully does not implement inclusive descendent
  3951. // As in, an element does not contain itself
  3952. contains = hasCompare || rnative.test( docElem.contains ) ?
  3953. function( a, b ) {
  3954. var adown = a.nodeType === 9 ? a.documentElement : a,
  3955. bup = b && b.parentNode;
  3956. return a === bup || !!( bup && bup.nodeType === 1 && (
  3957. adown.contains ?
  3958. adown.contains( bup ) :
  3959. a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
  3960. ));
  3961. } :
  3962. function( a, b ) {
  3963. if ( b ) {
  3964. while ( (b = b.parentNode) ) {
  3965. if ( b === a ) {
  3966. return true;
  3967. }
  3968. }
  3969. }
  3970. return false;
  3971. };
  3972. /* Sorting
  3973. ---------------------------------------------------------------------- */
  3974. // Document order sorting
  3975. sortOrder = hasCompare ?
  3976. function( a, b ) {
  3977. // Flag for duplicate removal
  3978. if ( a === b ) {
  3979. hasDuplicate = true;
  3980. return 0;
  3981. }
  3982. // Sort on method existence if only one input has compareDocumentPosition
  3983. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  3984. if ( compare ) {
  3985. return compare;
  3986. }
  3987. // Calculate position if both inputs belong to the same document
  3988. compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
  3989. a.compareDocumentPosition( b ) :
  3990. // Otherwise we know they are disconnected
  3991. 1;
  3992. // Disconnected nodes
  3993. if ( compare & 1 ||
  3994. (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
  3995. // Choose the first element that is related to our preferred document
  3996. if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
  3997. return -1;
  3998. }
  3999. if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
  4000. return 1;
  4001. }
  4002. // Maintain original order
  4003. return sortInput ?
  4004. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  4005. 0;
  4006. }
  4007. return compare & 4 ? -1 : 1;
  4008. } :
  4009. function( a, b ) {
  4010. // Exit early if the nodes are identical
  4011. if ( a === b ) {
  4012. hasDuplicate = true;
  4013. return 0;
  4014. }
  4015. var cur,
  4016. i = 0,
  4017. aup = a.parentNode,
  4018. bup = b.parentNode,
  4019. ap = [ a ],
  4020. bp = [ b ];
  4021. // Parentless nodes are either documents or disconnected
  4022. if ( !aup || !bup ) {
  4023. return a === doc ? -1 :
  4024. b === doc ? 1 :
  4025. aup ? -1 :
  4026. bup ? 1 :
  4027. sortInput ?
  4028. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  4029. 0;
  4030. // If the nodes are siblings, we can do a quick check
  4031. } else if ( aup === bup ) {
  4032. return siblingCheck( a, b );
  4033. }
  4034. // Otherwise we need full lists of their ancestors for comparison
  4035. cur = a;
  4036. while ( (cur = cur.parentNode) ) {
  4037. ap.unshift( cur );
  4038. }
  4039. cur = b;
  4040. while ( (cur = cur.parentNode) ) {
  4041. bp.unshift( cur );
  4042. }
  4043. // Walk down the tree looking for a discrepancy
  4044. while ( ap[i] === bp[i] ) {
  4045. i++;
  4046. }
  4047. return i ?
  4048. // Do a sibling check if the nodes have a common ancestor
  4049. siblingCheck( ap[i], bp[i] ) :
  4050. // Otherwise nodes in our document sort first
  4051. ap[i] === preferredDoc ? -1 :
  4052. bp[i] === preferredDoc ? 1 :
  4053. 0;
  4054. };
  4055. return doc;
  4056. };
  4057. Sizzle.matches = function( expr, elements ) {
  4058. return Sizzle( expr, null, null, elements );
  4059. };
  4060. Sizzle.matchesSelector = function( elem, expr ) {
  4061. // Set document vars if needed
  4062. if ( ( elem.ownerDocument || elem ) !== document ) {
  4063. setDocument( elem );
  4064. }
  4065. // Make sure that attribute selectors are quoted
  4066. expr = expr.replace( rattributeQuotes, "='$1']" );
  4067. if ( support.matchesSelector && documentIsHTML &&
  4068. ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
  4069. ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
  4070. try {
  4071. var ret = matches.call( elem, expr );
  4072. // IE 9's matchesSelector returns false on disconnected nodes
  4073. if ( ret || support.disconnectedMatch ||
  4074. // As well, disconnected nodes are said to be in a document
  4075. // fragment in IE 9
  4076. elem.document && elem.document.nodeType !== 11 ) {
  4077. return ret;
  4078. }
  4079. } catch(e) {}
  4080. }
  4081. return Sizzle( expr, document, null, [elem] ).length > 0;
  4082. };
  4083. Sizzle.contains = function( context, elem ) {
  4084. // Set document vars if needed
  4085. if ( ( context.ownerDocument || context ) !== document ) {
  4086. setDocument( context );
  4087. }
  4088. return contains( context, elem );
  4089. };
  4090. Sizzle.attr = function( elem, name ) {
  4091. // Set document vars if needed
  4092. if ( ( elem.ownerDocument || elem ) !== document ) {
  4093. setDocument( elem );
  4094. }
  4095. var fn = Expr.attrHandle[ name.toLowerCase() ],
  4096. // Don't get fooled by Object.prototype properties (jQuery #13807)
  4097. val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
  4098. fn( elem, name, !documentIsHTML ) :
  4099. undefined;
  4100. return val !== undefined ?
  4101. val :
  4102. support.attributes || !documentIsHTML ?
  4103. elem.getAttribute( name ) :
  4104. (val = elem.getAttributeNode(name)) && val.specified ?
  4105. val.value :
  4106. null;
  4107. };
  4108. Sizzle.error = function( msg ) {
  4109. throw new Error( "Syntax error, unrecognized expression: " + msg );
  4110. };
  4111. /**
  4112. * Document sorting and removing duplicates
  4113. * @param {ArrayLike} results
  4114. */
  4115. Sizzle.uniqueSort = function( results ) {
  4116. var elem,
  4117. duplicates = [],
  4118. j = 0,
  4119. i = 0;
  4120. // Unless we *know* we can detect duplicates, assume their presence
  4121. hasDuplicate = !support.detectDuplicates;
  4122. sortInput = !support.sortStable && results.slice( 0 );
  4123. results.sort( sortOrder );
  4124. if ( hasDuplicate ) {
  4125. while ( (elem = results[i++]) ) {
  4126. if ( elem === results[ i ] ) {
  4127. j = duplicates.push( i );
  4128. }
  4129. }
  4130. while ( j-- ) {
  4131. results.splice( duplicates[ j ], 1 );
  4132. }
  4133. }
  4134. // Clear input after sorting to release objects
  4135. // See https://github.com/jquery/sizzle/pull/225
  4136. sortInput = null;
  4137. return results;
  4138. };
  4139. /**
  4140. * Utility function for retrieving the text value of an array of DOM nodes
  4141. * @param {Array|Element} elem
  4142. */
  4143. getText = Sizzle.getText = function( elem ) {
  4144. var node,
  4145. ret = "",
  4146. i = 0,
  4147. nodeType = elem.nodeType;
  4148. if ( !nodeType ) {
  4149. // If no nodeType, this is expected to be an array
  4150. while ( (node = elem[i++]) ) {
  4151. // Do not traverse comment nodes
  4152. ret += getText( node );
  4153. }
  4154. } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
  4155. // Use textContent for elements
  4156. // innerText usage removed for consistency of new lines (jQuery #11153)
  4157. if ( typeof elem.textContent === "string" ) {
  4158. return elem.textContent;
  4159. } else {
  4160. // Traverse its children
  4161. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  4162. ret += getText( elem );
  4163. }
  4164. }
  4165. } else if ( nodeType === 3 || nodeType === 4 ) {
  4166. return elem.nodeValue;
  4167. }
  4168. // Do not include comment or processing instruction nodes
  4169. return ret;
  4170. };
  4171. Expr = Sizzle.selectors = {
  4172. // Can be adjusted by the user
  4173. cacheLength: 50,
  4174. createPseudo: markFunction,
  4175. match: matchExpr,
  4176. attrHandle: {},
  4177. find: {},
  4178. relative: {
  4179. ">": { dir: "parentNode", first: true },
  4180. " ": { dir: "parentNode" },
  4181. "+": { dir: "previousSibling", first: true },
  4182. "~": { dir: "previousSibling" }
  4183. },
  4184. preFilter: {
  4185. "ATTR": function( match ) {
  4186. match[1] = match[1].replace( runescape, funescape );
  4187. // Move the given value to match[3] whether quoted or unquoted
  4188. match[3] = ( match[4] || match[5] || "" ).replace( runescape, funescape );
  4189. if ( match[2] === "~=" ) {
  4190. match[3] = " " + match[3] + " ";
  4191. }
  4192. return match.slice( 0, 4 );
  4193. },
  4194. "CHILD": function( match ) {
  4195. /* matches from matchExpr["CHILD"]
  4196. 1 type (only|nth|...)
  4197. 2 what (child|of-type)
  4198. 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
  4199. 4 xn-component of xn+y argument ([+-]?\d*n|)
  4200. 5 sign of xn-component
  4201. 6 x of xn-component
  4202. 7 sign of y-component
  4203. 8 y of y-component
  4204. */
  4205. match[1] = match[1].toLowerCase();
  4206. if ( match[1].slice( 0, 3 ) === "nth" ) {
  4207. // nth-* requires argument
  4208. if ( !match[3] ) {
  4209. Sizzle.error( match[0] );
  4210. }
  4211. // numeric x and y parameters for Expr.filter.CHILD
  4212. // remember that false/true cast respectively to 0/1
  4213. match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
  4214. match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
  4215. // other types prohibit arguments
  4216. } else if ( match[3] ) {
  4217. Sizzle.error( match[0] );
  4218. }
  4219. return match;
  4220. },
  4221. "PSEUDO": function( match ) {
  4222. var excess,
  4223. unquoted = !match[5] && match[2];
  4224. if ( matchExpr["CHILD"].test( match[0] ) ) {
  4225. return null;
  4226. }
  4227. // Accept quoted arguments as-is
  4228. if ( match[3] && match[4] !== undefined ) {
  4229. match[2] = match[4];
  4230. // Strip excess characters from unquoted arguments
  4231. } else if ( unquoted && rpseudo.test( unquoted ) &&
  4232. // Get excess from tokenize (recursively)
  4233. (excess = tokenize( unquoted, true )) &&
  4234. // advance to the next closing parenthesis
  4235. (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
  4236. // excess is a negative index
  4237. match[0] = match[0].slice( 0, excess );
  4238. match[2] = unquoted.slice( 0, excess );
  4239. }
  4240. // Return only captures needed by the pseudo filter method (type and argument)
  4241. return match.slice( 0, 3 );
  4242. }
  4243. },
  4244. filter: {
  4245. "TAG": function( nodeNameSelector ) {
  4246. var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
  4247. return nodeNameSelector === "*" ?
  4248. function() { return true; } :
  4249. function( elem ) {
  4250. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
  4251. };
  4252. },
  4253. "CLASS": function( className ) {
  4254. var pattern = classCache[ className + " " ];
  4255. return pattern ||
  4256. (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
  4257. classCache( className, function( elem ) {
  4258. return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute("class") || "" );
  4259. });
  4260. },
  4261. "ATTR": function( name, operator, check ) {
  4262. return function( elem ) {
  4263. var result = Sizzle.attr( elem, name );
  4264. if ( result == null ) {
  4265. return operator === "!=";
  4266. }
  4267. if ( !operator ) {
  4268. return true;
  4269. }
  4270. result += "";
  4271. return operator === "=" ? result === check :
  4272. operator === "!=" ? result !== check :
  4273. operator === "^=" ? check && result.indexOf( check ) === 0 :
  4274. operator === "*=" ? check && result.indexOf( check ) > -1 :
  4275. operator === "$=" ? check && result.slice( -check.length ) === check :
  4276. operator === "~=" ? ( " " + result + " " ).indexOf( check ) > -1 :
  4277. operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
  4278. false;
  4279. };
  4280. },
  4281. "CHILD": function( type, what, argument, first, last ) {
  4282. var simple = type.slice( 0, 3 ) !== "nth",
  4283. forward = type.slice( -4 ) !== "last",
  4284. ofType = what === "of-type";
  4285. return first === 1 && last === 0 ?
  4286. // Shortcut for :nth-*(n)
  4287. function( elem ) {
  4288. return !!elem.parentNode;
  4289. } :
  4290. function( elem, context, xml ) {
  4291. var cache, outerCache, node, diff, nodeIndex, start,
  4292. dir = simple !== forward ? "nextSibling" : "previousSibling",
  4293. parent = elem.parentNode,
  4294. name = ofType && elem.nodeName.toLowerCase(),
  4295. useCache = !xml && !ofType;
  4296. if ( parent ) {
  4297. // :(first|last|only)-(child|of-type)
  4298. if ( simple ) {
  4299. while ( dir ) {
  4300. node = elem;
  4301. while ( (node = node[ dir ]) ) {
  4302. if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
  4303. return false;
  4304. }
  4305. }
  4306. // Reverse direction for :only-* (if we haven't yet done so)
  4307. start = dir = type === "only" && !start && "nextSibling";
  4308. }
  4309. return true;
  4310. }
  4311. start = [ forward ? parent.firstChild : parent.lastChild ];
  4312. // non-xml :nth-child(...) stores cache data on `parent`
  4313. if ( forward && useCache ) {
  4314. // Seek `elem` from a previously-cached index
  4315. outerCache = parent[ expando ] || (parent[ expando ] = {});
  4316. cache = outerCache[ type ] || [];
  4317. nodeIndex = cache[0] === dirruns && cache[1];
  4318. diff = cache[0] === dirruns && cache[2];
  4319. node = nodeIndex && parent.childNodes[ nodeIndex ];
  4320. while ( (node = ++nodeIndex && node && node[ dir ] ||
  4321. // Fallback to seeking `elem` from the start
  4322. (diff = nodeIndex = 0) || start.pop()) ) {
  4323. // When found, cache indexes on `parent` and break
  4324. if ( node.nodeType === 1 && ++diff && node === elem ) {
  4325. outerCache[ type ] = [ dirruns, nodeIndex, diff ];
  4326. break;
  4327. }
  4328. }
  4329. // Use previously-cached element index if available
  4330. } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
  4331. diff = cache[1];
  4332. // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
  4333. } else {
  4334. // Use the same loop as above to seek `elem` from the start
  4335. while ( (node = ++nodeIndex && node && node[ dir ] ||
  4336. (diff = nodeIndex = 0) || start.pop()) ) {
  4337. if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
  4338. // Cache the index of each encountered element
  4339. if ( useCache ) {
  4340. (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
  4341. }
  4342. if ( node === elem ) {
  4343. break;
  4344. }
  4345. }
  4346. }
  4347. }
  4348. // Incorporate the offset, then check against cycle size
  4349. diff -= last;
  4350. return diff === first || ( diff % first === 0 && diff / first >= 0 );
  4351. }
  4352. };
  4353. },
  4354. "PSEUDO": function( pseudo, argument ) {
  4355. // pseudo-class names are case-insensitive
  4356. // http://www.w3.org/TR/selectors/#pseudo-classes
  4357. // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
  4358. // Remember that setFilters inherits from pseudos
  4359. var args,
  4360. fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
  4361. Sizzle.error( "unsupported pseudo: " + pseudo );
  4362. // The user may use createPseudo to indicate that
  4363. // arguments are needed to create the filter function
  4364. // just as Sizzle does
  4365. if ( fn[ expando ] ) {
  4366. return fn( argument );
  4367. }
  4368. // But maintain support for old signatures
  4369. if ( fn.length > 1 ) {
  4370. args = [ pseudo, pseudo, "", argument ];
  4371. return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
  4372. markFunction(function( seed, matches ) {
  4373. var idx,
  4374. matched = fn( seed, argument ),
  4375. i = matched.length;
  4376. while ( i-- ) {
  4377. idx = indexOf.call( seed, matched[i] );
  4378. seed[ idx ] = !( matches[ idx ] = matched[i] );
  4379. }
  4380. }) :
  4381. function( elem ) {
  4382. return fn( elem, 0, args );
  4383. };
  4384. }
  4385. return fn;
  4386. }
  4387. },
  4388. pseudos: {
  4389. // Potentially complex pseudos
  4390. "not": markFunction(function( selector ) {
  4391. // Trim the selector passed to compile
  4392. // to avoid treating leading and trailing
  4393. // spaces as combinators
  4394. var input = [],
  4395. results = [],
  4396. matcher = compile( selector.replace( rtrim, "$1" ) );
  4397. return matcher[ expando ] ?
  4398. markFunction(function( seed, matches, context, xml ) {
  4399. var elem,
  4400. unmatched = matcher( seed, null, xml, [] ),
  4401. i = seed.length;
  4402. // Match elements unmatched by `matcher`
  4403. while ( i-- ) {
  4404. if ( (elem = unmatched[i]) ) {
  4405. seed[i] = !(matches[i] = elem);
  4406. }
  4407. }
  4408. }) :
  4409. function( elem, context, xml ) {
  4410. input[0] = elem;
  4411. matcher( input, null, xml, results );
  4412. return !results.pop();
  4413. };
  4414. }),
  4415. "has": markFunction(function( selector ) {
  4416. return function( elem ) {
  4417. return Sizzle( selector, elem ).length > 0;
  4418. };
  4419. }),
  4420. "contains": markFunction(function( text ) {
  4421. return function( elem ) {
  4422. return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
  4423. };
  4424. }),
  4425. // "Whether an element is represented by a :lang() selector
  4426. // is based solely on the element's language value
  4427. // being equal to the identifier C,
  4428. // or beginning with the identifier C immediately followed by "-".
  4429. // The matching of C against the element's language value is performed case-insensitively.
  4430. // The identifier C does not have to be a valid language name."
  4431. // http://www.w3.org/TR/selectors/#lang-pseudo
  4432. "lang": markFunction( function( lang ) {
  4433. // lang value must be a valid identifier
  4434. if ( !ridentifier.test(lang || "") ) {
  4435. Sizzle.error( "unsupported lang: " + lang );
  4436. }
  4437. lang = lang.replace( runescape, funescape ).toLowerCase();
  4438. return function( elem ) {
  4439. var elemLang;
  4440. do {
  4441. if ( (elemLang = documentIsHTML ?
  4442. elem.lang :
  4443. elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
  4444. elemLang = elemLang.toLowerCase();
  4445. return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
  4446. }
  4447. } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
  4448. return false;
  4449. };
  4450. }),
  4451. // Miscellaneous
  4452. "target": function( elem ) {
  4453. var hash = window.location && window.location.hash;
  4454. return hash && hash.slice( 1 ) === elem.id;
  4455. },
  4456. "root": function( elem ) {
  4457. return elem === docElem;
  4458. },
  4459. "focus": function( elem ) {
  4460. return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
  4461. },
  4462. // Boolean properties
  4463. "enabled": function( elem ) {
  4464. return elem.disabled === false;
  4465. },
  4466. "disabled": function( elem ) {
  4467. return elem.disabled === true;
  4468. },
  4469. "checked": function( elem ) {
  4470. // In CSS3, :checked should return both checked and selected elements
  4471. // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  4472. var nodeName = elem.nodeName.toLowerCase();
  4473. return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
  4474. },
  4475. "selected": function( elem ) {
  4476. // Accessing this property makes selected-by-default
  4477. // options in Safari work properly
  4478. if ( elem.parentNode ) {
  4479. elem.parentNode.selectedIndex;
  4480. }
  4481. return elem.selected === true;
  4482. },
  4483. // Contents
  4484. "empty": function( elem ) {
  4485. // http://www.w3.org/TR/selectors/#empty-pseudo
  4486. // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
  4487. // but not by others (comment: 8; processing instruction: 7; etc.)
  4488. // nodeType < 6 works because attributes (2) do not appear as children
  4489. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  4490. if ( elem.nodeType < 6 ) {
  4491. return false;
  4492. }
  4493. }
  4494. return true;
  4495. },
  4496. "parent": function( elem ) {
  4497. return !Expr.pseudos["empty"]( elem );
  4498. },
  4499. // Element/input types
  4500. "header": function( elem ) {
  4501. return rheader.test( elem.nodeName );
  4502. },
  4503. "input": function( elem ) {
  4504. return rinputs.test( elem.nodeName );
  4505. },
  4506. "button": function( elem ) {
  4507. var name = elem.nodeName.toLowerCase();
  4508. return name === "input" && elem.type === "button" || name === "button";
  4509. },
  4510. "text": function( elem ) {
  4511. var attr;
  4512. return elem.nodeName.toLowerCase() === "input" &&
  4513. elem.type === "text" &&
  4514. // Support: IE<8
  4515. // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
  4516. ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
  4517. },
  4518. // Position-in-collection
  4519. "first": createPositionalPseudo(function() {
  4520. return [ 0 ];
  4521. }),
  4522. "last": createPositionalPseudo(function( matchIndexes, length ) {
  4523. return [ length - 1 ];
  4524. }),
  4525. "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
  4526. return [ argument < 0 ? argument + length : argument ];
  4527. }),
  4528. "even": createPositionalPseudo(function( matchIndexes, length ) {
  4529. var i = 0;
  4530. for ( ; i < length; i += 2 ) {
  4531. matchIndexes.push( i );
  4532. }
  4533. return matchIndexes;
  4534. }),
  4535. "odd": createPositionalPseudo(function( matchIndexes, length ) {
  4536. var i = 1;
  4537. for ( ; i < length; i += 2 ) {
  4538. matchIndexes.push( i );
  4539. }
  4540. return matchIndexes;
  4541. }),
  4542. "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
  4543. var i = argument < 0 ? argument + length : argument;
  4544. for ( ; --i >= 0; ) {
  4545. matchIndexes.push( i );
  4546. }
  4547. return matchIndexes;
  4548. }),
  4549. "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
  4550. var i = argument < 0 ? argument + length : argument;
  4551. for ( ; ++i < length; ) {
  4552. matchIndexes.push( i );
  4553. }
  4554. return matchIndexes;
  4555. })
  4556. }
  4557. };
  4558. Expr.pseudos["nth"] = Expr.pseudos["eq"];
  4559. // Add button/input type pseudos
  4560. for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
  4561. Expr.pseudos[ i ] = createInputPseudo( i );
  4562. }
  4563. for ( i in { submit: true, reset: true } ) {
  4564. Expr.pseudos[ i ] = createButtonPseudo( i );
  4565. }
  4566. // Easy API for creating new setFilters
  4567. function setFilters() {}
  4568. setFilters.prototype = Expr.filters = Expr.pseudos;
  4569. Expr.setFilters = new setFilters();
  4570. function tokenize( selector, parseOnly ) {
  4571. var matched, match, tokens, type,
  4572. soFar, groups, preFilters,
  4573. cached = tokenCache[ selector + " " ];
  4574. if ( cached ) {
  4575. return parseOnly ? 0 : cached.slice( 0 );
  4576. }
  4577. soFar = selector;
  4578. groups = [];
  4579. preFilters = Expr.preFilter;
  4580. while ( soFar ) {
  4581. // Comma and first run
  4582. if ( !matched || (match = rcomma.exec( soFar )) ) {
  4583. if ( match ) {
  4584. // Don't consume trailing commas as valid
  4585. soFar = soFar.slice( match[0].length ) || soFar;
  4586. }
  4587. groups.push( (tokens = []) );
  4588. }
  4589. matched = false;
  4590. // Combinators
  4591. if ( (match = rcombinators.exec( soFar )) ) {
  4592. matched = match.shift();
  4593. tokens.push({
  4594. value: matched,
  4595. // Cast descendant combinators to space
  4596. type: match[0].replace( rtrim, " " )
  4597. });
  4598. soFar = soFar.slice( matched.length );
  4599. }
  4600. // Filters
  4601. for ( type in Expr.filter ) {
  4602. if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
  4603. (match = preFilters[ type ]( match ))) ) {
  4604. matched = match.shift();
  4605. tokens.push({
  4606. value: matched,
  4607. type: type,
  4608. matches: match
  4609. });
  4610. soFar = soFar.slice( matched.length );
  4611. }
  4612. }
  4613. if ( !matched ) {
  4614. break;
  4615. }
  4616. }
  4617. // Return the length of the invalid excess
  4618. // if we're just parsing
  4619. // Otherwise, throw an error or return tokens
  4620. return parseOnly ?
  4621. soFar.length :
  4622. soFar ?
  4623. Sizzle.error( selector ) :
  4624. // Cache the tokens
  4625. tokenCache( selector, groups ).slice( 0 );
  4626. }
  4627. function toSelector( tokens ) {
  4628. var i = 0,
  4629. len = tokens.length,
  4630. selector = "";
  4631. for ( ; i < len; i++ ) {
  4632. selector += tokens[i].value;
  4633. }
  4634. return selector;
  4635. }
  4636. function addCombinator( matcher, combinator, base ) {
  4637. var dir = combinator.dir,
  4638. checkNonElements = base && dir === "parentNode",
  4639. doneName = done++;
  4640. return combinator.first ?
  4641. // Check against closest ancestor/preceding element
  4642. function( elem, context, xml ) {
  4643. while ( (elem = elem[ dir ]) ) {
  4644. if ( elem.nodeType === 1 || checkNonElements ) {
  4645. return matcher( elem, context, xml );
  4646. }
  4647. }
  4648. } :
  4649. // Check against all ancestor/preceding elements
  4650. function( elem, context, xml ) {
  4651. var oldCache, outerCache,
  4652. newCache = [ dirruns, doneName ];
  4653. // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
  4654. if ( xml ) {
  4655. while ( (elem = elem[ dir ]) ) {
  4656. if ( elem.nodeType === 1 || checkNonElements ) {
  4657. if ( matcher( elem, context, xml ) ) {
  4658. return true;
  4659. }
  4660. }
  4661. }
  4662. } else {
  4663. while ( (elem = elem[ dir ]) ) {
  4664. if ( elem.nodeType === 1 || checkNonElements ) {
  4665. outerCache = elem[ expando ] || (elem[ expando ] = {});
  4666. if ( (oldCache = outerCache[ dir ]) &&
  4667. oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
  4668. // Assign to newCache so results back-propagate to previous elements
  4669. return (newCache[ 2 ] = oldCache[ 2 ]);
  4670. } else {
  4671. // Reuse newcache so results back-propagate to previous elements
  4672. outerCache[ dir ] = newCache;
  4673. // A match means we're done; a fail means we have to keep checking
  4674. if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
  4675. return true;
  4676. }
  4677. }
  4678. }
  4679. }
  4680. }
  4681. };
  4682. }
  4683. function elementMatcher( matchers ) {
  4684. return matchers.length > 1 ?
  4685. function( elem, context, xml ) {
  4686. var i = matchers.length;
  4687. while ( i-- ) {
  4688. if ( !matchers[i]( elem, context, xml ) ) {
  4689. return false;
  4690. }
  4691. }
  4692. return true;
  4693. } :
  4694. matchers[0];
  4695. }
  4696. function condense( unmatched, map, filter, context, xml ) {
  4697. var elem,
  4698. newUnmatched = [],
  4699. i = 0,
  4700. len = unmatched.length,
  4701. mapped = map != null;
  4702. for ( ; i < len; i++ ) {
  4703. if ( (elem = unmatched[i]) ) {
  4704. if ( !filter || filter( elem, context, xml ) ) {
  4705. newUnmatched.push( elem );
  4706. if ( mapped ) {
  4707. map.push( i );
  4708. }
  4709. }
  4710. }
  4711. }
  4712. return newUnmatched;
  4713. }
  4714. function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
  4715. if ( postFilter && !postFilter[ expando ] ) {
  4716. postFilter = setMatcher( postFilter );
  4717. }
  4718. if ( postFinder && !postFinder[ expando ] ) {
  4719. postFinder = setMatcher( postFinder, postSelector );
  4720. }
  4721. return markFunction(function( seed, results, context, xml ) {
  4722. var temp, i, elem,
  4723. preMap = [],
  4724. postMap = [],
  4725. preexisting = results.length,
  4726. // Get initial elements from seed or context
  4727. elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
  4728. // Prefilter to get matcher input, preserving a map for seed-results synchronization
  4729. matcherIn = preFilter && ( seed || !selector ) ?
  4730. condense( elems, preMap, preFilter, context, xml ) :
  4731. elems,
  4732. matcherOut = matcher ?
  4733. // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
  4734. postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
  4735. // ...intermediate processing is necessary
  4736. [] :
  4737. // ...otherwise use results directly
  4738. results :
  4739. matcherIn;
  4740. // Find primary matches
  4741. if ( matcher ) {
  4742. matcher( matcherIn, matcherOut, context, xml );
  4743. }
  4744. // Apply postFilter
  4745. if ( postFilter ) {
  4746. temp = condense( matcherOut, postMap );
  4747. postFilter( temp, [], context, xml );
  4748. // Un-match failing elements by moving them back to matcherIn
  4749. i = temp.length;
  4750. while ( i-- ) {
  4751. if ( (elem = temp[i]) ) {
  4752. matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
  4753. }
  4754. }
  4755. }
  4756. if ( seed ) {
  4757. if ( postFinder || preFilter ) {
  4758. if ( postFinder ) {
  4759. // Get the final matcherOut by condensing this intermediate into postFinder contexts
  4760. temp = [];
  4761. i = matcherOut.length;
  4762. while ( i-- ) {
  4763. if ( (elem = matcherOut[i]) ) {
  4764. // Restore matcherIn since elem is not yet a final match
  4765. temp.push( (matcherIn[i] = elem) );
  4766. }
  4767. }
  4768. postFinder( null, (matcherOut = []), temp, xml );
  4769. }
  4770. // Move matched elements from seed to results to keep them synchronized
  4771. i = matcherOut.length;
  4772. while ( i-- ) {
  4773. if ( (elem = matcherOut[i]) &&
  4774. (temp = postFinder ? indexOf.call( seed, elem ) : preMap[i]) > -1 ) {
  4775. seed[temp] = !(results[temp] = elem);
  4776. }
  4777. }
  4778. }
  4779. // Add elements to results, through postFinder if defined
  4780. } else {
  4781. matcherOut = condense(
  4782. matcherOut === results ?
  4783. matcherOut.splice( preexisting, matcherOut.length ) :
  4784. matcherOut
  4785. );
  4786. if ( postFinder ) {
  4787. postFinder( null, results, matcherOut, xml );
  4788. } else {
  4789. push.apply( results, matcherOut );
  4790. }
  4791. }
  4792. });
  4793. }
  4794. function matcherFromTokens( tokens ) {
  4795. var checkContext, matcher, j,
  4796. len = tokens.length,
  4797. leadingRelative = Expr.relative[ tokens[0].type ],
  4798. implicitRelative = leadingRelative || Expr.relative[" "],
  4799. i = leadingRelative ? 1 : 0,
  4800. // The foundational matcher ensures that elements are reachable from top-level context(s)
  4801. matchContext = addCombinator( function( elem ) {
  4802. return elem === checkContext;
  4803. }, implicitRelative, true ),
  4804. matchAnyContext = addCombinator( function( elem ) {
  4805. return indexOf.call( checkContext, elem ) > -1;
  4806. }, implicitRelative, true ),
  4807. matchers = [ function( elem, context, xml ) {
  4808. return ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
  4809. (checkContext = context).nodeType ?
  4810. matchContext( elem, context, xml ) :
  4811. matchAnyContext( elem, context, xml ) );
  4812. } ];
  4813. for ( ; i < len; i++ ) {
  4814. if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
  4815. matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
  4816. } else {
  4817. matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
  4818. // Return special upon seeing a positional matcher
  4819. if ( matcher[ expando ] ) {
  4820. // Find the next relative operator (if any) for proper handling
  4821. j = ++i;
  4822. for ( ; j < len; j++ ) {
  4823. if ( Expr.relative[ tokens[j].type ] ) {
  4824. break;
  4825. }
  4826. }
  4827. return setMatcher(
  4828. i > 1 && elementMatcher( matchers ),
  4829. i > 1 && toSelector(
  4830. // If the preceding token was a descendant combinator, insert an implicit any-element `*`
  4831. tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
  4832. ).replace( rtrim, "$1" ),
  4833. matcher,
  4834. i < j && matcherFromTokens( tokens.slice( i, j ) ),
  4835. j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
  4836. j < len && toSelector( tokens )
  4837. );
  4838. }
  4839. matchers.push( matcher );
  4840. }
  4841. }
  4842. return elementMatcher( matchers );
  4843. }
  4844. function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
  4845. var bySet = setMatchers.length > 0,
  4846. byElement = elementMatchers.length > 0,
  4847. superMatcher = function( seed, context, xml, results, outermost ) {
  4848. var elem, j, matcher,
  4849. matchedCount = 0,
  4850. i = "0",
  4851. unmatched = seed && [],
  4852. setMatched = [],
  4853. contextBackup = outermostContext,
  4854. // We must always have either seed elements or outermost context
  4855. elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
  4856. // Use integer dirruns iff this is the outermost matcher
  4857. dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
  4858. len = elems.length;
  4859. if ( outermost ) {
  4860. outermostContext = context !== document && context;
  4861. }
  4862. // Add elements passing elementMatchers directly to results
  4863. // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
  4864. // Support: IE<9, Safari
  4865. // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
  4866. for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
  4867. if ( byElement && elem ) {
  4868. j = 0;
  4869. while ( (matcher = elementMatchers[j++]) ) {
  4870. if ( matcher( elem, context, xml ) ) {
  4871. results.push( elem );
  4872. break;
  4873. }
  4874. }
  4875. if ( outermost ) {
  4876. dirruns = dirrunsUnique;
  4877. }
  4878. }
  4879. // Track unmatched elements for set filters
  4880. if ( bySet ) {
  4881. // They will have gone through all possible matchers
  4882. if ( (elem = !matcher && elem) ) {
  4883. matchedCount--;
  4884. }
  4885. // Lengthen the array for every element, matched or not
  4886. if ( seed ) {
  4887. unmatched.push( elem );
  4888. }
  4889. }
  4890. }
  4891. // Apply set filters to unmatched elements
  4892. matchedCount += i;
  4893. if ( bySet && i !== matchedCount ) {
  4894. j = 0;
  4895. while ( (matcher = setMatchers[j++]) ) {
  4896. matcher( unmatched, setMatched, context, xml );
  4897. }
  4898. if ( seed ) {
  4899. // Reintegrate element matches to eliminate the need for sorting
  4900. if ( matchedCount > 0 ) {
  4901. while ( i-- ) {
  4902. if ( !(unmatched[i] || setMatched[i]) ) {
  4903. setMatched[i] = pop.call( results );
  4904. }
  4905. }
  4906. }
  4907. // Discard index placeholder values to get only actual matches
  4908. setMatched = condense( setMatched );
  4909. }
  4910. // Add matches to results
  4911. push.apply( results, setMatched );
  4912. // Seedless set matches succeeding multiple successful matchers stipulate sorting
  4913. if ( outermost && !seed && setMatched.length > 0 &&
  4914. ( matchedCount + setMatchers.length ) > 1 ) {
  4915. Sizzle.uniqueSort( results );
  4916. }
  4917. }
  4918. // Override manipulation of globals by nested matchers
  4919. if ( outermost ) {
  4920. dirruns = dirrunsUnique;
  4921. outermostContext = contextBackup;
  4922. }
  4923. return unmatched;
  4924. };
  4925. return bySet ?
  4926. markFunction( superMatcher ) :
  4927. superMatcher;
  4928. }
  4929. compile = Sizzle.compile = function( selector, group /* Internal Use Only */ ) {
  4930. var i,
  4931. setMatchers = [],
  4932. elementMatchers = [],
  4933. cached = compilerCache[ selector + " " ];
  4934. if ( !cached ) {
  4935. // Generate a function of recursive functions that can be used to check each element
  4936. if ( !group ) {
  4937. group = tokenize( selector );
  4938. }
  4939. i = group.length;
  4940. while ( i-- ) {
  4941. cached = matcherFromTokens( group[i] );
  4942. if ( cached[ expando ] ) {
  4943. setMatchers.push( cached );
  4944. } else {
  4945. elementMatchers.push( cached );
  4946. }
  4947. }
  4948. // Cache the compiled function
  4949. cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
  4950. }
  4951. return cached;
  4952. };
  4953. function multipleContexts( selector, contexts, results ) {
  4954. var i = 0,
  4955. len = contexts.length;
  4956. for ( ; i < len; i++ ) {
  4957. Sizzle( selector, contexts[i], results );
  4958. }
  4959. return results;
  4960. }
  4961. function select( selector, context, results, seed ) {
  4962. var i, tokens, token, type, find,
  4963. match = tokenize( selector );
  4964. if ( !seed ) {
  4965. // Try to minimize operations if there is only one group
  4966. if ( match.length === 1 ) {
  4967. // Take a shortcut and set the context if the root selector is an ID
  4968. tokens = match[0] = match[0].slice( 0 );
  4969. if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
  4970. support.getById && context.nodeType === 9 && documentIsHTML &&
  4971. Expr.relative[ tokens[1].type ] ) {
  4972. context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
  4973. if ( !context ) {
  4974. return results;
  4975. }
  4976. selector = selector.slice( tokens.shift().value.length );
  4977. }
  4978. // Fetch a seed set for right-to-left matching
  4979. i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
  4980. while ( i-- ) {
  4981. token = tokens[i];
  4982. // Abort if we hit a combinator
  4983. if ( Expr.relative[ (type = token.type) ] ) {
  4984. break;
  4985. }
  4986. if ( (find = Expr.find[ type ]) ) {
  4987. // Search, expanding context for leading sibling combinators
  4988. if ( (seed = find(
  4989. token.matches[0].replace( runescape, funescape ),
  4990. rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
  4991. )) ) {
  4992. // If seed is empty or no tokens remain, we can return early
  4993. tokens.splice( i, 1 );
  4994. selector = seed.length && toSelector( tokens );
  4995. if ( !selector ) {
  4996. push.apply( results, seed );
  4997. return results;
  4998. }
  4999. break;
  5000. }
  5001. }
  5002. }
  5003. }
  5004. }
  5005. // Compile and execute a filtering function
  5006. // Provide `match` to avoid retokenization if we modified the selector above
  5007. compile( selector, match )(
  5008. seed,
  5009. context,
  5010. !documentIsHTML,
  5011. results,
  5012. rsibling.test( selector ) && testContext( context.parentNode ) || context
  5013. );
  5014. return results;
  5015. }
  5016. // One-time assignments
  5017. // Sort stability
  5018. support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
  5019. // Support: Chrome<14
  5020. // Always assume duplicates if they aren't passed to the comparison function
  5021. support.detectDuplicates = !!hasDuplicate;
  5022. // Initialize against the default document
  5023. setDocument();
  5024. // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
  5025. // Detached nodes confoundingly follow *each other*
  5026. support.sortDetached = assert(function( div1 ) {
  5027. // Should return 1, but returns 4 (following)
  5028. return div1.compareDocumentPosition( document.createElement("div") ) & 1;
  5029. });
  5030. // Support: IE<8
  5031. // Prevent attribute/property "interpolation"
  5032. // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
  5033. if ( !assert(function( div ) {
  5034. div.innerHTML = "<a href='#'></a>";
  5035. return div.firstChild.getAttribute("href") === "#" ;
  5036. }) ) {
  5037. addHandle( "type|href|height|width", function( elem, name, isXML ) {
  5038. if ( !isXML ) {
  5039. return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
  5040. }
  5041. });
  5042. }
  5043. // Support: IE<9
  5044. // Use defaultValue in place of getAttribute("value")
  5045. if ( !support.attributes || !assert(function( div ) {
  5046. div.innerHTML = "<input/>";
  5047. div.firstChild.setAttribute( "value", "" );
  5048. return div.firstChild.getAttribute( "value" ) === "";
  5049. }) ) {
  5050. addHandle( "value", function( elem, name, isXML ) {
  5051. if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
  5052. return elem.defaultValue;
  5053. }
  5054. });
  5055. }
  5056. // Support: IE<9
  5057. // Use getAttributeNode to fetch booleans when getAttribute lies
  5058. if ( !assert(function( div ) {
  5059. return div.getAttribute("disabled") == null;
  5060. }) ) {
  5061. addHandle( booleans, function( elem, name, isXML ) {
  5062. var val;
  5063. if ( !isXML ) {
  5064. return elem[ name ] === true ? name.toLowerCase() :
  5065. (val = elem.getAttributeNode( name )) && val.specified ?
  5066. val.value :
  5067. null;
  5068. }
  5069. });
  5070. }
  5071. return Sizzle;
  5072. })( window );
  5073. jQuery.find = Sizzle;
  5074. jQuery.expr = Sizzle.selectors;
  5075. jQuery.expr[":"] = jQuery.expr.pseudos;
  5076. jQuery.unique = Sizzle.uniqueSort;
  5077. jQuery.text = Sizzle.getText;
  5078. jQuery.isXMLDoc = Sizzle.isXML;
  5079. jQuery.contains = Sizzle.contains;
  5080. var rneedsContext = jQuery.expr.match.needsContext;
  5081. var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
  5082. var risSimple = /^.[^:#\[\.,]*$/;
  5083. // Implement the identical functionality for filter and not
  5084. function winnow( elements, qualifier, not ) {
  5085. if ( jQuery.isFunction( qualifier ) ) {
  5086. return jQuery.grep( elements, function( elem, i ) {
  5087. /* jshint -W018 */
  5088. return !!qualifier.call( elem, i, elem ) !== not;
  5089. });
  5090. }
  5091. if ( qualifier.nodeType ) {
  5092. return jQuery.grep( elements, function( elem ) {
  5093. return ( elem === qualifier ) !== not;
  5094. });
  5095. }
  5096. if ( typeof qualifier === "string" ) {
  5097. if ( risSimple.test( qualifier ) ) {
  5098. return jQuery.filter( qualifier, elements, not );
  5099. }
  5100. qualifier = jQuery.filter( qualifier, elements );
  5101. }
  5102. return jQuery.grep( elements, function( elem ) {
  5103. return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
  5104. });
  5105. }
  5106. jQuery.filter = function( expr, elems, not ) {
  5107. var elem = elems[ 0 ];
  5108. if ( not ) {
  5109. expr = ":not(" + expr + ")";
  5110. }
  5111. return elems.length === 1 && elem.nodeType === 1 ?
  5112. jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
  5113. jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
  5114. return elem.nodeType === 1;
  5115. }));
  5116. };
  5117. jQuery.fn.extend({
  5118. find: function( selector ) {
  5119. var i,
  5120. len = this.length,
  5121. ret = [],
  5122. self = this;
  5123. if ( typeof selector !== "string" ) {
  5124. return this.pushStack( jQuery( selector ).filter(function() {
  5125. for ( i = 0; i < len; i++ ) {
  5126. if ( jQuery.contains( self[ i ], this ) ) {
  5127. return true;
  5128. }
  5129. }
  5130. }) );
  5131. }
  5132. for ( i = 0; i < len; i++ ) {
  5133. jQuery.find( selector, self[ i ], ret );
  5134. }
  5135. // Needed because $( selector, context ) becomes $( context ).find( selector )
  5136. ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
  5137. ret.selector = this.selector ? this.selector + " " + selector : selector;
  5138. return ret;
  5139. },
  5140. filter: function( selector ) {
  5141. return this.pushStack( winnow(this, selector || [], false) );
  5142. },
  5143. not: function( selector ) {
  5144. return this.pushStack( winnow(this, selector || [], true) );
  5145. },
  5146. is: function( selector ) {
  5147. return !!winnow(
  5148. this,
  5149. // If this is a positional/relative selector, check membership in the returned set
  5150. // so $("p:first").is("p:last") won't return true for a doc with two "p".
  5151. typeof selector === "string" && rneedsContext.test( selector ) ?
  5152. jQuery( selector ) :
  5153. selector || [],
  5154. false
  5155. ).length;
  5156. }
  5157. });
  5158. // Initialize a jQuery object
  5159. // A central reference to the root jQuery(document)
  5160. var rootjQuery,
  5161. // A simple way to check for HTML strings
  5162. // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
  5163. // Strict HTML recognition (#11290: must start with <)
  5164. rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
  5165. init = jQuery.fn.init = function( selector, context ) {
  5166. var match, elem;
  5167. // HANDLE: $(""), $(null), $(undefined), $(false)
  5168. if ( !selector ) {
  5169. return this;
  5170. }
  5171. // Handle HTML strings
  5172. if ( typeof selector === "string" ) {
  5173. if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
  5174. // Assume that strings that start and end with <> are HTML and skip the regex check
  5175. match = [ null, selector, null ];
  5176. } else {
  5177. match = rquickExpr.exec( selector );
  5178. }
  5179. // Match html or make sure no context is specified for #id
  5180. if ( match && (match[1] || !context) ) {
  5181. // HANDLE: $(html) -> $(array)
  5182. if ( match[1] ) {
  5183. context = context instanceof jQuery ? context[0] : context;
  5184. // scripts is true for back-compat
  5185. // Intentionally let the error be thrown if parseHTML is not present
  5186. jQuery.merge( this, jQuery.parseHTML(
  5187. match[1],
  5188. context && context.nodeType ? context.ownerDocument || context : document,
  5189. true
  5190. ) );
  5191. // HANDLE: $(html, props)
  5192. if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
  5193. for ( match in context ) {
  5194. // Properties of context are called as methods if possible
  5195. if ( jQuery.isFunction( this[ match ] ) ) {
  5196. this[ match ]( context[ match ] );
  5197. // ...and otherwise set as attributes
  5198. } else {
  5199. this.attr( match, context[ match ] );
  5200. }
  5201. }
  5202. }
  5203. return this;
  5204. // HANDLE: $(#id)
  5205. } else {
  5206. elem = document.getElementById( match[2] );
  5207. // Check parentNode to catch when Blackberry 4.6 returns
  5208. // nodes that are no longer in the document #6963
  5209. if ( elem && elem.parentNode ) {
  5210. // Inject the element directly into the jQuery object
  5211. this.length = 1;
  5212. this[0] = elem;
  5213. }
  5214. this.context = document;
  5215. this.selector = selector;
  5216. return this;
  5217. }
  5218. // HANDLE: $(expr, $(...))
  5219. } else if ( !context || context.jquery ) {
  5220. return ( context || rootjQuery ).find( selector );
  5221. // HANDLE: $(expr, context)
  5222. // (which is just equivalent to: $(context).find(expr)
  5223. } else {
  5224. return this.constructor( context ).find( selector );
  5225. }
  5226. // HANDLE: $(DOMElement)
  5227. } else if ( selector.nodeType ) {
  5228. this.context = this[0] = selector;
  5229. this.length = 1;
  5230. return this;
  5231. // HANDLE: $(function)
  5232. // Shortcut for document ready
  5233. } else if ( jQuery.isFunction( selector ) ) {
  5234. return typeof rootjQuery.ready !== "undefined" ?
  5235. rootjQuery.ready( selector ) :
  5236. // Execute immediately if ready is not present
  5237. selector( jQuery );
  5238. }
  5239. if ( selector.selector !== undefined ) {
  5240. this.selector = selector.selector;
  5241. this.context = selector.context;
  5242. }
  5243. return jQuery.makeArray( selector, this );
  5244. };
  5245. // Give the init function the jQuery prototype for later instantiation
  5246. init.prototype = jQuery.fn;
  5247. // Initialize central reference
  5248. rootjQuery = jQuery( document );
  5249. var rparentsprev = /^(?:parents|prev(?:Until|All))/,
  5250. // methods guaranteed to produce a unique set when starting from a unique set
  5251. guaranteedUnique = {
  5252. children: true,
  5253. contents: true,
  5254. next: true,
  5255. prev: true
  5256. };
  5257. jQuery.extend({
  5258. dir: function( elem, dir, until ) {
  5259. var matched = [],
  5260. truncate = until !== undefined;
  5261. while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
  5262. if ( elem.nodeType === 1 ) {
  5263. if ( truncate && jQuery( elem ).is( until ) ) {
  5264. break;
  5265. }
  5266. matched.push( elem );
  5267. }
  5268. }
  5269. return matched;
  5270. },
  5271. sibling: function( n, elem ) {
  5272. var matched = [];
  5273. for ( ; n; n = n.nextSibling ) {
  5274. if ( n.nodeType === 1 && n !== elem ) {
  5275. matched.push( n );
  5276. }
  5277. }
  5278. return matched;
  5279. }
  5280. });
  5281. jQuery.fn.extend({
  5282. has: function( target ) {
  5283. var targets = jQuery( target, this ),
  5284. l = targets.length;
  5285. return this.filter(function() {
  5286. var i = 0;
  5287. for ( ; i < l; i++ ) {
  5288. if ( jQuery.contains( this, targets[i] ) ) {
  5289. return true;
  5290. }
  5291. }
  5292. });
  5293. },
  5294. closest: function( selectors, context ) {
  5295. var cur,
  5296. i = 0,
  5297. l = this.length,
  5298. matched = [],
  5299. pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
  5300. jQuery( selectors, context || this.context ) :
  5301. 0;
  5302. for ( ; i < l; i++ ) {
  5303. for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
  5304. // Always skip document fragments
  5305. if ( cur.nodeType < 11 && (pos ?
  5306. pos.index(cur) > -1 :
  5307. // Don't pass non-elements to Sizzle
  5308. cur.nodeType === 1 &&
  5309. jQuery.find.matchesSelector(cur, selectors)) ) {
  5310. matched.push( cur );
  5311. break;
  5312. }
  5313. }
  5314. }
  5315. return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
  5316. },
  5317. // Determine the position of an element within
  5318. // the matched set of elements
  5319. index: function( elem ) {
  5320. // No argument, return index in parent
  5321. if ( !elem ) {
  5322. return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
  5323. }
  5324. // index in selector
  5325. if ( typeof elem === "string" ) {
  5326. return indexOf.call( jQuery( elem ), this[ 0 ] );
  5327. }
  5328. // Locate the position of the desired element
  5329. return indexOf.call( this,
  5330. // If it receives a jQuery object, the first element is used
  5331. elem.jquery ? elem[ 0 ] : elem
  5332. );
  5333. },
  5334. add: function( selector, context ) {
  5335. return this.pushStack(
  5336. jQuery.unique(
  5337. jQuery.merge( this.get(), jQuery( selector, context ) )
  5338. )
  5339. );
  5340. },
  5341. addBack: function( selector ) {
  5342. return this.add( selector == null ?
  5343. this.prevObject : this.prevObject.filter(selector)
  5344. );
  5345. }
  5346. });
  5347. function sibling( cur, dir ) {
  5348. while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
  5349. return cur;
  5350. }
  5351. jQuery.each({
  5352. parent: function( elem ) {
  5353. var parent = elem.parentNode;
  5354. return parent && parent.nodeType !== 11 ? parent : null;
  5355. },
  5356. parents: function( elem ) {
  5357. return jQuery.dir( elem, "parentNode" );
  5358. },
  5359. parentsUntil: function( elem, i, until ) {
  5360. return jQuery.dir( elem, "parentNode", until );
  5361. },
  5362. next: function( elem ) {
  5363. return sibling( elem, "nextSibling" );
  5364. },
  5365. prev: function( elem ) {
  5366. return sibling( elem, "previousSibling" );
  5367. },
  5368. nextAll: function( elem ) {
  5369. return jQuery.dir( elem, "nextSibling" );
  5370. },
  5371. prevAll: function( elem ) {
  5372. return jQuery.dir( elem, "previousSibling" );
  5373. },
  5374. nextUntil: function( elem, i, until ) {
  5375. return jQuery.dir( elem, "nextSibling", until );
  5376. },
  5377. prevUntil: function( elem, i, until ) {
  5378. return jQuery.dir( elem, "previousSibling", until );
  5379. },
  5380. siblings: function( elem ) {
  5381. return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
  5382. },
  5383. children: function( elem ) {
  5384. return jQuery.sibling( elem.firstChild );
  5385. },
  5386. contents: function( elem ) {
  5387. return elem.contentDocument || jQuery.merge( [], elem.childNodes );
  5388. }
  5389. }, function( name, fn ) {
  5390. jQuery.fn[ name ] = function( until, selector ) {
  5391. var matched = jQuery.map( this, fn, until );
  5392. if ( name.slice( -5 ) !== "Until" ) {
  5393. selector = until;
  5394. }
  5395. if ( selector && typeof selector === "string" ) {
  5396. matched = jQuery.filter( selector, matched );
  5397. }
  5398. if ( this.length > 1 ) {
  5399. // Remove duplicates
  5400. if ( !guaranteedUnique[ name ] ) {
  5401. jQuery.unique( matched );
  5402. }
  5403. // Reverse order for parents* and prev-derivatives
  5404. if ( rparentsprev.test( name ) ) {
  5405. matched.reverse();
  5406. }
  5407. }
  5408. return this.pushStack( matched );
  5409. };
  5410. });
  5411. var rnotwhite = (/\S+/g);
  5412. // String to Object options format cache
  5413. var optionsCache = {};
  5414. // Convert String-formatted options into Object-formatted ones and store in cache
  5415. function createOptions( options ) {
  5416. var object = optionsCache[ options ] = {};
  5417. jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
  5418. object[ flag ] = true;
  5419. });
  5420. return object;
  5421. }
  5422. /*
  5423. * Create a callback list using the following parameters:
  5424. *
  5425. * options: an optional list of space-separated options that will change how
  5426. * the callback list behaves or a more traditional option object
  5427. *
  5428. * By default a callback list will act like an event callback list and can be
  5429. * "fired" multiple times.
  5430. *
  5431. * Possible options:
  5432. *
  5433. * once: will ensure the callback list can only be fired once (like a Deferred)
  5434. *
  5435. * memory: will keep track of previous values and will call any callback added
  5436. * after the list has been fired right away with the latest "memorized"
  5437. * values (like a Deferred)
  5438. *
  5439. * unique: will ensure a callback can only be added once (no duplicate in the list)
  5440. *
  5441. * stopOnFalse: interrupt callings when a callback returns false
  5442. *
  5443. */
  5444. jQuery.Callbacks = function( options ) {
  5445. // Convert options from String-formatted to Object-formatted if needed
  5446. // (we check in cache first)
  5447. options = typeof options === "string" ?
  5448. ( optionsCache[ options ] || createOptions( options ) ) :
  5449. jQuery.extend( {}, options );
  5450. var // Last fire value (for non-forgettable lists)
  5451. memory,
  5452. // Flag to know if list was already fired
  5453. fired,
  5454. // Flag to know if list is currently firing
  5455. firing,
  5456. // First callback to fire (used internally by add and fireWith)
  5457. firingStart,
  5458. // End of the loop when firing
  5459. firingLength,
  5460. // Index of currently firing callback (modified by remove if needed)
  5461. firingIndex,
  5462. // Actual callback list
  5463. list = [],
  5464. // Stack of fire calls for repeatable lists
  5465. stack = !options.once && [],
  5466. // Fire callbacks
  5467. fire = function( data ) {
  5468. memory = options.memory && data;
  5469. fired = true;
  5470. firingIndex = firingStart || 0;
  5471. firingStart = 0;
  5472. firingLength = list.length;
  5473. firing = true;
  5474. for ( ; list && firingIndex < firingLength; firingIndex++ ) {
  5475. if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
  5476. memory = false; // To prevent further calls using add
  5477. break;
  5478. }
  5479. }
  5480. firing = false;
  5481. if ( list ) {
  5482. if ( stack ) {
  5483. if ( stack.length ) {
  5484. fire( stack.shift() );
  5485. }
  5486. } else if ( memory ) {
  5487. list = [];
  5488. } else {
  5489. self.disable();
  5490. }
  5491. }
  5492. },
  5493. // Actual Callbacks object
  5494. self = {
  5495. // Add a callback or a collection of callbacks to the list
  5496. add: function() {
  5497. if ( list ) {
  5498. // First, we save the current length
  5499. var start = list.length;
  5500. (function add( args ) {
  5501. jQuery.each( args, function( _, arg ) {
  5502. var type = jQuery.type( arg );
  5503. if ( type === "function" ) {
  5504. if ( !options.unique || !self.has( arg ) ) {
  5505. list.push( arg );
  5506. }
  5507. } else if ( arg && arg.length && type !== "string" ) {
  5508. // Inspect recursively
  5509. add( arg );
  5510. }
  5511. });
  5512. })( arguments );
  5513. // Do we need to add the callbacks to the
  5514. // current firing batch?
  5515. if ( firing ) {
  5516. firingLength = list.length;
  5517. // With memory, if we're not firing then
  5518. // we should call right away
  5519. } else if ( memory ) {
  5520. firingStart = start;
  5521. fire( memory );
  5522. }
  5523. }
  5524. return this;
  5525. },
  5526. // Remove a callback from the list
  5527. remove: function() {
  5528. if ( list ) {
  5529. jQuery.each( arguments, function( _, arg ) {
  5530. var index;
  5531. while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
  5532. list.splice( index, 1 );
  5533. // Handle firing indexes
  5534. if ( firing ) {
  5535. if ( index <= firingLength ) {
  5536. firingLength--;
  5537. }
  5538. if ( index <= firingIndex ) {
  5539. firingIndex--;
  5540. }
  5541. }
  5542. }
  5543. });
  5544. }
  5545. return this;
  5546. },
  5547. // Check if a given callback is in the list.
  5548. // If no argument is given, return whether or not list has callbacks attached.
  5549. has: function( fn ) {
  5550. return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
  5551. },
  5552. // Remove all callbacks from the list
  5553. empty: function() {
  5554. list = [];
  5555. firingLength = 0;
  5556. return this;
  5557. },
  5558. // Have the list do nothing anymore
  5559. disable: function() {
  5560. list = stack = memory = undefined;
  5561. return this;
  5562. },
  5563. // Is it disabled?
  5564. disabled: function() {
  5565. return !list;
  5566. },
  5567. // Lock the list in its current state
  5568. lock: function() {
  5569. stack = undefined;
  5570. if ( !memory ) {
  5571. self.disable();
  5572. }
  5573. return this;
  5574. },
  5575. // Is it locked?
  5576. locked: function() {
  5577. return !stack;
  5578. },
  5579. // Call all callbacks with the given context and arguments
  5580. fireWith: function( context, args ) {
  5581. if ( list && ( !fired || stack ) ) {
  5582. args = args || [];
  5583. args = [ context, args.slice ? args.slice() : args ];
  5584. if ( firing ) {
  5585. stack.push( args );
  5586. } else {
  5587. fire( args );
  5588. }
  5589. }
  5590. return this;
  5591. },
  5592. // Call all the callbacks with the given arguments
  5593. fire: function() {
  5594. self.fireWith( this, arguments );
  5595. return this;
  5596. },
  5597. // To know if the callbacks have already been called at least once
  5598. fired: function() {
  5599. return !!fired;
  5600. }
  5601. };
  5602. return self;
  5603. };
  5604. jQuery.extend({
  5605. Deferred: function( func ) {
  5606. var tuples = [
  5607. // action, add listener, listener list, final state
  5608. [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
  5609. [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
  5610. [ "notify", "progress", jQuery.Callbacks("memory") ]
  5611. ],
  5612. state = "pending",
  5613. promise = {
  5614. state: function() {
  5615. return state;
  5616. },
  5617. always: function() {
  5618. deferred.done( arguments ).fail( arguments );
  5619. return this;
  5620. },
  5621. then: function( /* fnDone, fnFail, fnProgress */ ) {
  5622. var fns = arguments;
  5623. return jQuery.Deferred(function( newDefer ) {
  5624. jQuery.each( tuples, function( i, tuple ) {
  5625. var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
  5626. // deferred[ done | fail | progress ] for forwarding actions to newDefer
  5627. deferred[ tuple[1] ](function() {
  5628. var returned = fn && fn.apply( this, arguments );
  5629. if ( returned && jQuery.isFunction( returned.promise ) ) {
  5630. returned.promise()
  5631. .done( newDefer.resolve )
  5632. .fail( newDefer.reject )
  5633. .progress( newDefer.notify );
  5634. } else {
  5635. newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
  5636. }
  5637. });
  5638. });
  5639. fns = null;
  5640. }).promise();
  5641. },
  5642. // Get a promise for this deferred
  5643. // If obj is provided, the promise aspect is added to the object
  5644. promise: function( obj ) {
  5645. return obj != null ? jQuery.extend( obj, promise ) : promise;
  5646. }
  5647. },
  5648. deferred = {};
  5649. // Keep pipe for back-compat
  5650. promise.pipe = promise.then;
  5651. // Add list-specific methods
  5652. jQuery.each( tuples, function( i, tuple ) {
  5653. var list = tuple[ 2 ],
  5654. stateString = tuple[ 3 ];
  5655. // promise[ done | fail | progress ] = list.add
  5656. promise[ tuple[1] ] = list.add;
  5657. // Handle state
  5658. if ( stateString ) {
  5659. list.add(function() {
  5660. // state = [ resolved | rejected ]
  5661. state = stateString;
  5662. // [ reject_list | resolve_list ].disable; progress_list.lock
  5663. }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
  5664. }
  5665. // deferred[ resolve | reject | notify ]
  5666. deferred[ tuple[0] ] = function() {
  5667. deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
  5668. return this;
  5669. };
  5670. deferred[ tuple[0] + "With" ] = list.fireWith;
  5671. });
  5672. // Make the deferred a promise
  5673. promise.promise( deferred );
  5674. // Call given func if any
  5675. if ( func ) {
  5676. func.call( deferred, deferred );
  5677. }
  5678. // All done!
  5679. return deferred;
  5680. },
  5681. // Deferred helper
  5682. when: function( subordinate /* , ..., subordinateN */ ) {
  5683. var i = 0,
  5684. resolveValues = slice.call( arguments ),
  5685. length = resolveValues.length,
  5686. // the count of uncompleted subordinates
  5687. remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
  5688. // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
  5689. deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
  5690. // Update function for both resolve and progress values
  5691. updateFunc = function( i, contexts, values ) {
  5692. return function( value ) {
  5693. contexts[ i ] = this;
  5694. values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
  5695. if ( values === progressValues ) {
  5696. deferred.notifyWith( contexts, values );
  5697. } else if ( !( --remaining ) ) {
  5698. deferred.resolveWith( contexts, values );
  5699. }
  5700. };
  5701. },
  5702. progressValues, progressContexts, resolveContexts;
  5703. // add listeners to Deferred subordinates; treat others as resolved
  5704. if ( length > 1 ) {
  5705. progressValues = new Array( length );
  5706. progressContexts = new Array( length );
  5707. resolveContexts = new Array( length );
  5708. for ( ; i < length; i++ ) {
  5709. if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
  5710. resolveValues[ i ].promise()
  5711. .done( updateFunc( i, resolveContexts, resolveValues ) )
  5712. .fail( deferred.reject )
  5713. .progress( updateFunc( i, progressContexts, progressValues ) );
  5714. } else {
  5715. --remaining;
  5716. }
  5717. }
  5718. }
  5719. // if we're not waiting on anything, resolve the master
  5720. if ( !remaining ) {
  5721. deferred.resolveWith( resolveContexts, resolveValues );
  5722. }
  5723. return deferred.promise();
  5724. }
  5725. });
  5726. // The deferred used on DOM ready
  5727. var readyList;
  5728. jQuery.fn.ready = function( fn ) {
  5729. // Add the callback
  5730. jQuery.ready.promise().done( fn );
  5731. return this;
  5732. };
  5733. jQuery.extend({
  5734. // Is the DOM ready to be used? Set to true once it occurs.
  5735. isReady: false,
  5736. // A counter to track how many items to wait for before
  5737. // the ready event fires. See #6781
  5738. readyWait: 1,
  5739. // Hold (or release) the ready event
  5740. holdReady: function( hold ) {
  5741. if ( hold ) {
  5742. jQuery.readyWait++;
  5743. } else {
  5744. jQuery.ready( true );
  5745. }
  5746. },
  5747. // Handle when the DOM is ready
  5748. ready: function( wait ) {
  5749. // Abort if there are pending holds or we're already ready
  5750. if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
  5751. return;
  5752. }
  5753. // Remember that the DOM is ready
  5754. jQuery.isReady = true;
  5755. // If a normal DOM Ready event fired, decrement, and wait if need be
  5756. if ( wait !== true && --jQuery.readyWait > 0 ) {
  5757. return;
  5758. }
  5759. // If there are functions bound, to execute
  5760. readyList.resolveWith( document, [ jQuery ] );
  5761. // Trigger any bound ready events
  5762. if ( jQuery.fn.trigger ) {
  5763. jQuery( document ).trigger("ready").off("ready");
  5764. }
  5765. }
  5766. });
  5767. /**
  5768. * The ready event handler and self cleanup method
  5769. */
  5770. function completed() {
  5771. document.removeEventListener( "DOMContentLoaded", completed, false );
  5772. window.removeEventListener( "load", completed, false );
  5773. jQuery.ready();
  5774. }
  5775. jQuery.ready.promise = function( obj ) {
  5776. if ( !readyList ) {
  5777. readyList = jQuery.Deferred();
  5778. // Catch cases where $(document).ready() is called after the browser event has already occurred.
  5779. // we once tried to use readyState "interactive" here, but it caused issues like the one
  5780. // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
  5781. if ( document.readyState === "complete" ) {
  5782. // Handle it asynchronously to allow scripts the opportunity to delay ready
  5783. setTimeout( jQuery.ready );
  5784. } else {
  5785. // Use the handy event callback
  5786. document.addEventListener( "DOMContentLoaded", completed, false );
  5787. // A fallback to window.onload, that will always work
  5788. window.addEventListener( "load", completed, false );
  5789. }
  5790. }
  5791. return readyList.promise( obj );
  5792. };
  5793. // Kick off the DOM ready check even if the user does not
  5794. jQuery.ready.promise();
  5795. // Multifunctional method to get and set values of a collection
  5796. // The value/s can optionally be executed if it's a function
  5797. var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
  5798. var i = 0,
  5799. len = elems.length,
  5800. bulk = key == null;
  5801. // Sets many values
  5802. if ( jQuery.type( key ) === "object" ) {
  5803. chainable = true;
  5804. for ( i in key ) {
  5805. jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
  5806. }
  5807. // Sets one value
  5808. } else if ( value !== undefined ) {
  5809. chainable = true;
  5810. if ( !jQuery.isFunction( value ) ) {
  5811. raw = true;
  5812. }
  5813. if ( bulk ) {
  5814. // Bulk operations run against the entire set
  5815. if ( raw ) {
  5816. fn.call( elems, value );
  5817. fn = null;
  5818. // ...except when executing function values
  5819. } else {
  5820. bulk = fn;
  5821. fn = function( elem, key, value ) {
  5822. return bulk.call( jQuery( elem ), value );
  5823. };
  5824. }
  5825. }
  5826. if ( fn ) {
  5827. for ( ; i < len; i++ ) {
  5828. fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
  5829. }
  5830. }
  5831. }
  5832. return chainable ?
  5833. elems :
  5834. // Gets
  5835. bulk ?
  5836. fn.call( elems ) :
  5837. len ? fn( elems[0], key ) : emptyGet;
  5838. };
  5839. /**
  5840. * Determines whether an object can have data
  5841. */
  5842. jQuery.acceptData = function( owner ) {
  5843. // Accepts only:
  5844. // - Node
  5845. // - Node.ELEMENT_NODE
  5846. // - Node.DOCUMENT_NODE
  5847. // - Object
  5848. // - Any
  5849. /* jshint -W018 */
  5850. return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
  5851. };
  5852. function Data() {
  5853. // Support: Android < 4,
  5854. // Old WebKit does not have Object.preventExtensions/freeze method,
  5855. // return new empty object instead with no [[set]] accessor
  5856. Object.defineProperty( this.cache = {}, 0, {
  5857. get: function() {
  5858. return {};
  5859. }
  5860. });
  5861. this.expando = jQuery.expando + Math.random();
  5862. }
  5863. Data.uid = 1;
  5864. Data.accepts = jQuery.acceptData;
  5865. Data.prototype = {
  5866. key: function( owner ) {
  5867. // We can accept data for non-element nodes in modern browsers,
  5868. // but we should not, see #8335.
  5869. // Always return the key for a frozen object.
  5870. if ( !Data.accepts( owner ) ) {
  5871. return 0;
  5872. }
  5873. var descriptor = {},
  5874. // Check if the owner object already has a cache key
  5875. unlock = owner[ this.expando ];
  5876. // If not, create one
  5877. if ( !unlock ) {
  5878. unlock = Data.uid++;
  5879. // Secure it in a non-enumerable, non-writable property
  5880. try {
  5881. descriptor[ this.expando ] = { value: unlock };
  5882. Object.defineProperties( owner, descriptor );
  5883. // Support: Android < 4
  5884. // Fallback to a less secure definition
  5885. } catch ( e ) {
  5886. descriptor[ this.expando ] = unlock;
  5887. jQuery.extend( owner, descriptor );
  5888. }
  5889. }
  5890. // Ensure the cache object
  5891. if ( !this.cache[ unlock ] ) {
  5892. this.cache[ unlock ] = {};
  5893. }
  5894. return unlock;
  5895. },
  5896. set: function( owner, data, value ) {
  5897. var prop,
  5898. // There may be an unlock assigned to this node,
  5899. // if there is no entry for this "owner", create one inline
  5900. // and set the unlock as though an owner entry had always existed
  5901. unlock = this.key( owner ),
  5902. cache = this.cache[ unlock ];
  5903. // Handle: [ owner, key, value ] args
  5904. if ( typeof data === "string" ) {
  5905. cache[ data ] = value;
  5906. // Handle: [ owner, { properties } ] args
  5907. } else {
  5908. // Fresh assignments by object are shallow copied
  5909. if ( jQuery.isEmptyObject( cache ) ) {
  5910. jQuery.extend( this.cache[ unlock ], data );
  5911. // Otherwise, copy the properties one-by-one to the cache object
  5912. } else {
  5913. for ( prop in data ) {
  5914. cache[ prop ] = data[ prop ];
  5915. }
  5916. }
  5917. }
  5918. return cache;
  5919. },
  5920. get: function( owner, key ) {
  5921. // Either a valid cache is found, or will be created.
  5922. // New caches will be created and the unlock returned,
  5923. // allowing direct access to the newly created
  5924. // empty data object. A valid owner object must be provided.
  5925. var cache = this.cache[ this.key( owner ) ];
  5926. return key === undefined ?
  5927. cache : cache[ key ];
  5928. },
  5929. access: function( owner, key, value ) {
  5930. var stored;
  5931. // In cases where either:
  5932. //
  5933. // 1. No key was specified
  5934. // 2. A string key was specified, but no value provided
  5935. //
  5936. // Take the "read" path and allow the get method to determine
  5937. // which value to return, respectively either:
  5938. //
  5939. // 1. The entire cache object
  5940. // 2. The data stored at the key
  5941. //
  5942. if ( key === undefined ||
  5943. ((key && typeof key === "string") && value === undefined) ) {
  5944. stored = this.get( owner, key );
  5945. return stored !== undefined ?
  5946. stored : this.get( owner, jQuery.camelCase(key) );
  5947. }
  5948. // [*]When the key is not a string, or both a key and value
  5949. // are specified, set or extend (existing objects) with either:
  5950. //
  5951. // 1. An object of properties
  5952. // 2. A key and value
  5953. //
  5954. this.set( owner, key, value );
  5955. // Since the "set" path can have two possible entry points
  5956. // return the expected data based on which path was taken[*]
  5957. return value !== undefined ? value : key;
  5958. },
  5959. remove: function( owner, key ) {
  5960. var i, name, camel,
  5961. unlock = this.key( owner ),
  5962. cache = this.cache[ unlock ];
  5963. if ( key === undefined ) {
  5964. this.cache[ unlock ] = {};
  5965. } else {
  5966. // Support array or space separated string of keys
  5967. if ( jQuery.isArray( key ) ) {
  5968. // If "name" is an array of keys...
  5969. // When data is initially created, via ("key", "val") signature,
  5970. // keys will be converted to camelCase.
  5971. // Since there is no way to tell _how_ a key was added, remove
  5972. // both plain key and camelCase key. #12786
  5973. // This will only penalize the array argument path.
  5974. name = key.concat( key.map( jQuery.camelCase ) );
  5975. } else {
  5976. camel = jQuery.camelCase( key );
  5977. // Try the string as a key before any manipulation
  5978. if ( key in cache ) {
  5979. name = [ key, camel ];
  5980. } else {
  5981. // If a key with the spaces exists, use it.
  5982. // Otherwise, create an array by matching non-whitespace
  5983. name = camel;
  5984. name = name in cache ?
  5985. [ name ] : ( name.match( rnotwhite ) || [] );
  5986. }
  5987. }
  5988. i = name.length;
  5989. while ( i-- ) {
  5990. delete cache[ name[ i ] ];
  5991. }
  5992. }
  5993. },
  5994. hasData: function( owner ) {
  5995. return !jQuery.isEmptyObject(
  5996. this.cache[ owner[ this.expando ] ] || {}
  5997. );
  5998. },
  5999. discard: function( owner ) {
  6000. if ( owner[ this.expando ] ) {
  6001. delete this.cache[ owner[ this.expando ] ];
  6002. }
  6003. }
  6004. };
  6005. var data_priv = new Data();
  6006. var data_user = new Data();
  6007. /*
  6008. Implementation Summary
  6009. 1. Enforce API surface and semantic compatibility with 1.9.x branch
  6010. 2. Improve the module's maintainability by reducing the storage
  6011. paths to a single mechanism.
  6012. 3. Use the same single mechanism to support "private" and "user" data.
  6013. 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
  6014. 5. Avoid exposing implementation details on user objects (eg. expando properties)
  6015. 6. Provide a clear path for implementation upgrade to WeakMap in 2014
  6016. */
  6017. var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
  6018. rmultiDash = /([A-Z])/g;
  6019. function dataAttr( elem, key, data ) {
  6020. var name;
  6021. // If nothing was found internally, try to fetch any
  6022. // data from the HTML5 data-* attribute
  6023. if ( data === undefined && elem.nodeType === 1 ) {
  6024. name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
  6025. data = elem.getAttribute( name );
  6026. if ( typeof data === "string" ) {
  6027. try {
  6028. data = data === "true" ? true :
  6029. data === "false" ? false :
  6030. data === "null" ? null :
  6031. // Only convert to a number if it doesn't change the string
  6032. +data + "" === data ? +data :
  6033. rbrace.test( data ) ? jQuery.parseJSON( data ) :
  6034. data;
  6035. } catch( e ) {}
  6036. // Make sure we set the data so it isn't changed later
  6037. data_user.set( elem, key, data );
  6038. } else {
  6039. data = undefined;
  6040. }
  6041. }
  6042. return data;
  6043. }
  6044. jQuery.extend({
  6045. hasData: function( elem ) {
  6046. return data_user.hasData( elem ) || data_priv.hasData( elem );
  6047. },
  6048. data: function( elem, name, data ) {
  6049. return data_user.access( elem, name, data );
  6050. },
  6051. removeData: function( elem, name ) {
  6052. data_user.remove( elem, name );
  6053. },
  6054. // TODO: Now that all calls to _data and _removeData have been replaced
  6055. // with direct calls to data_priv methods, these can be deprecated.
  6056. _data: function( elem, name, data ) {
  6057. return data_priv.access( elem, name, data );
  6058. },
  6059. _removeData: function( elem, name ) {
  6060. data_priv.remove( elem, name );
  6061. }
  6062. });
  6063. jQuery.fn.extend({
  6064. data: function( key, value ) {
  6065. var i, name, data,
  6066. elem = this[ 0 ],
  6067. attrs = elem && elem.attributes;
  6068. // Gets all values
  6069. if ( key === undefined ) {
  6070. if ( this.length ) {
  6071. data = data_user.get( elem );
  6072. if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
  6073. i = attrs.length;
  6074. while ( i-- ) {
  6075. name = attrs[ i ].name;
  6076. if ( name.indexOf( "data-" ) === 0 ) {
  6077. name = jQuery.camelCase( name.slice(5) );
  6078. dataAttr( elem, name, data[ name ] );
  6079. }
  6080. }
  6081. data_priv.set( elem, "hasDataAttrs", true );
  6082. }
  6083. }
  6084. return data;
  6085. }
  6086. // Sets multiple values
  6087. if ( typeof key === "object" ) {
  6088. return this.each(function() {
  6089. data_user.set( this, key );
  6090. });
  6091. }
  6092. return access( this, function( value ) {
  6093. var data,
  6094. camelKey = jQuery.camelCase( key );
  6095. // The calling jQuery object (element matches) is not empty
  6096. // (and therefore has an element appears at this[ 0 ]) and the
  6097. // `value` parameter was not undefined. An empty jQuery object
  6098. // will result in `undefined` for elem = this[ 0 ] which will
  6099. // throw an exception if an attempt to read a data cache is made.
  6100. if ( elem && value === undefined ) {
  6101. // Attempt to get data from the cache
  6102. // with the key as-is
  6103. data = data_user.get( elem, key );
  6104. if ( data !== undefined ) {
  6105. return data;
  6106. }
  6107. // Attempt to get data from the cache
  6108. // with the key camelized
  6109. data = data_user.get( elem, camelKey );
  6110. if ( data !== undefined ) {
  6111. return data;
  6112. }
  6113. // Attempt to "discover" the data in
  6114. // HTML5 custom data-* attrs
  6115. data = dataAttr( elem, camelKey, undefined );
  6116. if ( data !== undefined ) {
  6117. return data;
  6118. }
  6119. // We tried really hard, but the data doesn't exist.
  6120. return;
  6121. }
  6122. // Set the data...
  6123. this.each(function() {
  6124. // First, attempt to store a copy or reference of any
  6125. // data that might've been store with a camelCased key.
  6126. var data = data_user.get( this, camelKey );
  6127. // For HTML5 data-* attribute interop, we have to
  6128. // store property names with dashes in a camelCase form.
  6129. // This might not apply to all properties...*
  6130. data_user.set( this, camelKey, value );
  6131. // *... In the case of properties that might _actually_
  6132. // have dashes, we need to also store a copy of that
  6133. // unchanged property.
  6134. if ( key.indexOf("-") !== -1 && data !== undefined ) {
  6135. data_user.set( this, key, value );
  6136. }
  6137. });
  6138. }, null, value, arguments.length > 1, null, true );
  6139. },
  6140. removeData: function( key ) {
  6141. return this.each(function() {
  6142. data_user.remove( this, key );
  6143. });
  6144. }
  6145. });
  6146. jQuery.extend({
  6147. queue: function( elem, type, data ) {
  6148. var queue;
  6149. if ( elem ) {
  6150. type = ( type || "fx" ) + "queue";
  6151. queue = data_priv.get( elem, type );
  6152. // Speed up dequeue by getting out quickly if this is just a lookup
  6153. if ( data ) {
  6154. if ( !queue || jQuery.isArray( data ) ) {
  6155. queue = data_priv.access( elem, type, jQuery.makeArray(data) );
  6156. } else {
  6157. queue.push( data );
  6158. }
  6159. }
  6160. return queue || [];
  6161. }
  6162. },
  6163. dequeue: function( elem, type ) {
  6164. type = type || "fx";
  6165. var queue = jQuery.queue( elem, type ),
  6166. startLength = queue.length,
  6167. fn = queue.shift(),
  6168. hooks = jQuery._queueHooks( elem, type ),
  6169. next = function() {
  6170. jQuery.dequeue( elem, type );
  6171. };
  6172. // If the fx queue is dequeued, always remove the progress sentinel
  6173. if ( fn === "inprogress" ) {
  6174. fn = queue.shift();
  6175. startLength--;
  6176. }
  6177. if ( fn ) {
  6178. // Add a progress sentinel to prevent the fx queue from being
  6179. // automatically dequeued
  6180. if ( type === "fx" ) {
  6181. queue.unshift( "inprogress" );
  6182. }
  6183. // clear up the last queue stop function
  6184. delete hooks.stop;
  6185. fn.call( elem, next, hooks );
  6186. }
  6187. if ( !startLength && hooks ) {
  6188. hooks.empty.fire();
  6189. }
  6190. },
  6191. // not intended for public consumption - generates a queueHooks object, or returns the current one
  6192. _queueHooks: function( elem, type ) {
  6193. var key = type + "queueHooks";
  6194. return data_priv.get( elem, key ) || data_priv.access( elem, key, {
  6195. empty: jQuery.Callbacks("once memory").add(function() {
  6196. data_priv.remove( elem, [ type + "queue", key ] );
  6197. })
  6198. });
  6199. }
  6200. });
  6201. jQuery.fn.extend({
  6202. queue: function( type, data ) {
  6203. var setter = 2;
  6204. if ( typeof type !== "string" ) {
  6205. data = type;
  6206. type = "fx";
  6207. setter--;
  6208. }
  6209. if ( arguments.length < setter ) {
  6210. return jQuery.queue( this[0], type );
  6211. }
  6212. return data === undefined ?
  6213. this :
  6214. this.each(function() {
  6215. var queue = jQuery.queue( this, type, data );
  6216. // ensure a hooks for this queue
  6217. jQuery._queueHooks( this, type );
  6218. if ( type === "fx" && queue[0] !== "inprogress" ) {
  6219. jQuery.dequeue( this, type );
  6220. }
  6221. });
  6222. },
  6223. dequeue: function( type ) {
  6224. return this.each(function() {
  6225. jQuery.dequeue( this, type );
  6226. });
  6227. },
  6228. clearQueue: function( type ) {
  6229. return this.queue( type || "fx", [] );
  6230. },
  6231. // Get a promise resolved when queues of a certain type
  6232. // are emptied (fx is the type by default)
  6233. promise: function( type, obj ) {
  6234. var tmp,
  6235. count = 1,
  6236. defer = jQuery.Deferred(),
  6237. elements = this,
  6238. i = this.length,
  6239. resolve = function() {
  6240. if ( !( --count ) ) {
  6241. defer.resolveWith( elements, [ elements ] );
  6242. }
  6243. };
  6244. if ( typeof type !== "string" ) {
  6245. obj = type;
  6246. type = undefined;
  6247. }
  6248. type = type || "fx";
  6249. while ( i-- ) {
  6250. tmp = data_priv.get( elements[ i ], type + "queueHooks" );
  6251. if ( tmp && tmp.empty ) {
  6252. count++;
  6253. tmp.empty.add( resolve );
  6254. }
  6255. }
  6256. resolve();
  6257. return defer.promise( obj );
  6258. }
  6259. });
  6260. var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
  6261. var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
  6262. var isHidden = function( elem, el ) {
  6263. // isHidden might be called from jQuery#filter function;
  6264. // in that case, element will be second argument
  6265. elem = el || elem;
  6266. return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
  6267. };
  6268. var rcheckableType = (/^(?:checkbox|radio)$/i);
  6269. (function() {
  6270. var fragment = document.createDocumentFragment(),
  6271. div = fragment.appendChild( document.createElement( "div" ) );
  6272. // #11217 - WebKit loses check when the name is after the checked attribute
  6273. div.innerHTML = "<input type='radio' checked='checked' name='t'/>";
  6274. // Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3
  6275. // old WebKit doesn't clone checked state correctly in fragments
  6276. support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
  6277. // Make sure textarea (and checkbox) defaultValue is properly cloned
  6278. // Support: IE9-IE11+
  6279. div.innerHTML = "<textarea>x</textarea>";
  6280. support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
  6281. })();
  6282. var strundefined = typeof undefined;
  6283. support.focusinBubbles = "onfocusin" in window;
  6284. var
  6285. rkeyEvent = /^key/,
  6286. rmouseEvent = /^(?:mouse|contextmenu)|click/,
  6287. rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
  6288. rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
  6289. function returnTrue() {
  6290. return true;
  6291. }
  6292. function returnFalse() {
  6293. return false;
  6294. }
  6295. function safeActiveElement() {
  6296. try {
  6297. return document.activeElement;
  6298. } catch ( err ) { }
  6299. }
  6300. /*
  6301. * Helper functions for managing events -- not part of the public interface.
  6302. * Props to Dean Edwards' addEvent library for many of the ideas.
  6303. */
  6304. jQuery.event = {
  6305. global: {},
  6306. add: function( elem, types, handler, data, selector ) {
  6307. var handleObjIn, eventHandle, tmp,
  6308. events, t, handleObj,
  6309. special, handlers, type, namespaces, origType,
  6310. elemData = data_priv.get( elem );
  6311. // Don't attach events to noData or text/comment nodes (but allow plain objects)
  6312. if ( !elemData ) {
  6313. return;
  6314. }
  6315. // Caller can pass in an object of custom data in lieu of the handler
  6316. if ( handler.handler ) {
  6317. handleObjIn = handler;
  6318. handler = handleObjIn.handler;
  6319. selector = handleObjIn.selector;
  6320. }
  6321. // Make sure that the handler has a unique ID, used to find/remove it later
  6322. if ( !handler.guid ) {
  6323. handler.guid = jQuery.guid++;
  6324. }
  6325. // Init the element's event structure and main handler, if this is the first
  6326. if ( !(events = elemData.events) ) {
  6327. events = elemData.events = {};
  6328. }
  6329. if ( !(eventHandle = elemData.handle) ) {
  6330. eventHandle = elemData.handle = function( e ) {
  6331. // Discard the second event of a jQuery.event.trigger() and
  6332. // when an event is called after a page has unloaded
  6333. return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
  6334. jQuery.event.dispatch.apply( elem, arguments ) : undefined;
  6335. };
  6336. }
  6337. // Handle multiple events separated by a space
  6338. types = ( types || "" ).match( rnotwhite ) || [ "" ];
  6339. t = types.length;
  6340. while ( t-- ) {
  6341. tmp = rtypenamespace.exec( types[t] ) || [];
  6342. type = origType = tmp[1];
  6343. namespaces = ( tmp[2] || "" ).split( "." ).sort();
  6344. // There *must* be a type, no attaching namespace-only handlers
  6345. if ( !type ) {
  6346. continue;
  6347. }
  6348. // If event changes its type, use the special event handlers for the changed type
  6349. special = jQuery.event.special[ type ] || {};
  6350. // If selector defined, determine special event api type, otherwise given type
  6351. type = ( selector ? special.delegateType : special.bindType ) || type;
  6352. // Update special based on newly reset type
  6353. special = jQuery.event.special[ type ] || {};
  6354. // handleObj is passed to all event handlers
  6355. handleObj = jQuery.extend({
  6356. type: type,
  6357. origType: origType,
  6358. data: data,
  6359. handler: handler,
  6360. guid: handler.guid,
  6361. selector: selector,
  6362. needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
  6363. namespace: namespaces.join(".")
  6364. }, handleObjIn );
  6365. // Init the event handler queue if we're the first
  6366. if ( !(handlers = events[ type ]) ) {
  6367. handlers = events[ type ] = [];
  6368. handlers.delegateCount = 0;
  6369. // Only use addEventListener if the special events handler returns false
  6370. if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
  6371. if ( elem.addEventListener ) {
  6372. elem.addEventListener( type, eventHandle, false );
  6373. }
  6374. }
  6375. }
  6376. if ( special.add ) {
  6377. special.add.call( elem, handleObj );
  6378. if ( !handleObj.handler.guid ) {
  6379. handleObj.handler.guid = handler.guid;
  6380. }
  6381. }
  6382. // Add to the element's handler list, delegates in front
  6383. if ( selector ) {
  6384. handlers.splice( handlers.delegateCount++, 0, handleObj );
  6385. } else {
  6386. handlers.push( handleObj );
  6387. }
  6388. // Keep track of which events have ever been used, for event optimization
  6389. jQuery.event.global[ type ] = true;
  6390. }
  6391. },
  6392. // Detach an event or set of events from an element
  6393. remove: function( elem, types, handler, selector, mappedTypes ) {
  6394. var j, origCount, tmp,
  6395. events, t, handleObj,
  6396. special, handlers, type, namespaces, origType,
  6397. elemData = data_priv.hasData( elem ) && data_priv.get( elem );
  6398. if ( !elemData || !(events = elemData.events) ) {
  6399. return;
  6400. }
  6401. // Once for each type.namespace in types; type may be omitted
  6402. types = ( types || "" ).match( rnotwhite ) || [ "" ];
  6403. t = types.length;
  6404. while ( t-- ) {
  6405. tmp = rtypenamespace.exec( types[t] ) || [];
  6406. type = origType = tmp[1];
  6407. namespaces = ( tmp[2] || "" ).split( "." ).sort();
  6408. // Unbind all events (on this namespace, if provided) for the element
  6409. if ( !type ) {
  6410. for ( type in events ) {
  6411. jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
  6412. }
  6413. continue;
  6414. }
  6415. special = jQuery.event.special[ type ] || {};
  6416. type = ( selector ? special.delegateType : special.bindType ) || type;
  6417. handlers = events[ type ] || [];
  6418. tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
  6419. // Remove matching events
  6420. origCount = j = handlers.length;
  6421. while ( j-- ) {
  6422. handleObj = handlers[ j ];
  6423. if ( ( mappedTypes || origType === handleObj.origType ) &&
  6424. ( !handler || handler.guid === handleObj.guid ) &&
  6425. ( !tmp || tmp.test( handleObj.namespace ) ) &&
  6426. ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
  6427. handlers.splice( j, 1 );
  6428. if ( handleObj.selector ) {
  6429. handlers.delegateCount--;
  6430. }
  6431. if ( special.remove ) {
  6432. special.remove.call( elem, handleObj );
  6433. }
  6434. }
  6435. }
  6436. // Remove generic event handler if we removed something and no more handlers exist
  6437. // (avoids potential for endless recursion during removal of special event handlers)
  6438. if ( origCount && !handlers.length ) {
  6439. if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
  6440. jQuery.removeEvent( elem, type, elemData.handle );
  6441. }
  6442. delete events[ type ];
  6443. }
  6444. }
  6445. // Remove the expando if it's no longer used
  6446. if ( jQuery.isEmptyObject( events ) ) {
  6447. delete elemData.handle;
  6448. data_priv.remove( elem, "events" );
  6449. }
  6450. },
  6451. trigger: function( event, data, elem, onlyHandlers ) {
  6452. var i, cur, tmp, bubbleType, ontype, handle, special,
  6453. eventPath = [ elem || document ],
  6454. type = hasOwn.call( event, "type" ) ? event.type : event,
  6455. namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
  6456. cur = tmp = elem = elem || document;
  6457. // Don't do events on text and comment nodes
  6458. if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
  6459. return;
  6460. }
  6461. // focus/blur morphs to focusin/out; ensure we're not firing them right now
  6462. if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
  6463. return;
  6464. }
  6465. if ( type.indexOf(".") >= 0 ) {
  6466. // Namespaced trigger; create a regexp to match event type in handle()
  6467. namespaces = type.split(".");
  6468. type = namespaces.shift();
  6469. namespaces.sort();
  6470. }
  6471. ontype = type.indexOf(":") < 0 && "on" + type;
  6472. // Caller can pass in a jQuery.Event object, Object, or just an event type string
  6473. event = event[ jQuery.expando ] ?
  6474. event :
  6475. new jQuery.Event( type, typeof event === "object" && event );
  6476. // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
  6477. event.isTrigger = onlyHandlers ? 2 : 3;
  6478. event.namespace = namespaces.join(".");
  6479. event.namespace_re = event.namespace ?
  6480. new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
  6481. null;
  6482. // Clean up the event in case it is being reused
  6483. event.result = undefined;
  6484. if ( !event.target ) {
  6485. event.target = elem;
  6486. }
  6487. // Clone any incoming data and prepend the event, creating the handler arg list
  6488. data = data == null ?
  6489. [ event ] :
  6490. jQuery.makeArray( data, [ event ] );
  6491. // Allow special events to draw outside the lines
  6492. special = jQuery.event.special[ type ] || {};
  6493. if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
  6494. return;
  6495. }
  6496. // Determine event propagation path in advance, per W3C events spec (#9951)
  6497. // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
  6498. if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
  6499. bubbleType = special.delegateType || type;
  6500. if ( !rfocusMorph.test( bubbleType + type ) ) {
  6501. cur = cur.parentNode;
  6502. }
  6503. for ( ; cur; cur = cur.parentNode ) {
  6504. eventPath.push( cur );
  6505. tmp = cur;
  6506. }
  6507. // Only add window if we got to document (e.g., not plain obj or detached DOM)
  6508. if ( tmp === (elem.ownerDocument || document) ) {
  6509. eventPath.push( tmp.defaultView || tmp.parentWindow || window );
  6510. }
  6511. }
  6512. // Fire handlers on the event path
  6513. i = 0;
  6514. while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
  6515. event.type = i > 1 ?
  6516. bubbleType :
  6517. special.bindType || type;
  6518. // jQuery handler
  6519. handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
  6520. if ( handle ) {
  6521. handle.apply( cur, data );
  6522. }
  6523. // Native handler
  6524. handle = ontype && cur[ ontype ];
  6525. if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
  6526. event.result = handle.apply( cur, data );
  6527. if ( event.result === false ) {
  6528. event.preventDefault();
  6529. }
  6530. }
  6531. }
  6532. event.type = type;
  6533. // If nobody prevented the default action, do it now
  6534. if ( !onlyHandlers && !event.isDefaultPrevented() ) {
  6535. if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
  6536. jQuery.acceptData( elem ) ) {
  6537. // Call a native DOM method on the target with the same name name as the event.
  6538. // Don't do default actions on window, that's where global variables be (#6170)
  6539. if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
  6540. // Don't re-trigger an onFOO event when we call its FOO() method
  6541. tmp = elem[ ontype ];
  6542. if ( tmp ) {
  6543. elem[ ontype ] = null;
  6544. }
  6545. // Prevent re-triggering of the same event, since we already bubbled it above
  6546. jQuery.event.triggered = type;
  6547. elem[ type ]();
  6548. jQuery.event.triggered = undefined;
  6549. if ( tmp ) {
  6550. elem[ ontype ] = tmp;
  6551. }
  6552. }
  6553. }
  6554. }
  6555. return event.result;
  6556. },
  6557. dispatch: function( event ) {
  6558. // Make a writable jQuery.Event from the native event object
  6559. event = jQuery.event.fix( event );
  6560. var i, j, ret, matched, handleObj,
  6561. handlerQueue = [],
  6562. args = slice.call( arguments ),
  6563. handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
  6564. special = jQuery.event.special[ event.type ] || {};
  6565. // Use the fix-ed jQuery.Event rather than the (read-only) native event
  6566. args[0] = event;
  6567. event.delegateTarget = this;
  6568. // Call the preDispatch hook for the mapped type, and let it bail if desired
  6569. if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
  6570. return;
  6571. }
  6572. // Determine handlers
  6573. handlerQueue = jQuery.event.handlers.call( this, event, handlers );
  6574. // Run delegates first; they may want to stop propagation beneath us
  6575. i = 0;
  6576. while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
  6577. event.currentTarget = matched.elem;
  6578. j = 0;
  6579. while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
  6580. // Triggered event must either 1) have no namespace, or
  6581. // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
  6582. if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
  6583. event.handleObj = handleObj;
  6584. event.data = handleObj.data;
  6585. ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
  6586. .apply( matched.elem, args );
  6587. if ( ret !== undefined ) {
  6588. if ( (event.result = ret) === false ) {
  6589. event.preventDefault();
  6590. event.stopPropagation();
  6591. }
  6592. }
  6593. }
  6594. }
  6595. }
  6596. // Call the postDispatch hook for the mapped type
  6597. if ( special.postDispatch ) {
  6598. special.postDispatch.call( this, event );
  6599. }
  6600. return event.result;
  6601. },
  6602. handlers: function( event, handlers ) {
  6603. var i, matches, sel, handleObj,
  6604. handlerQueue = [],
  6605. delegateCount = handlers.delegateCount,
  6606. cur = event.target;
  6607. // Find delegate handlers
  6608. // Black-hole SVG <use> instance trees (#13180)
  6609. // Avoid non-left-click bubbling in Firefox (#3861)
  6610. if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
  6611. for ( ; cur !== this; cur = cur.parentNode || this ) {
  6612. // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
  6613. if ( cur.disabled !== true || event.type !== "click" ) {
  6614. matches = [];
  6615. for ( i = 0; i < delegateCount; i++ ) {
  6616. handleObj = handlers[ i ];
  6617. // Don't conflict with Object.prototype properties (#13203)
  6618. sel = handleObj.selector + " ";
  6619. if ( matches[ sel ] === undefined ) {
  6620. matches[ sel ] = handleObj.needsContext ?
  6621. jQuery( sel, this ).index( cur ) >= 0 :
  6622. jQuery.find( sel, this, null, [ cur ] ).length;
  6623. }
  6624. if ( matches[ sel ] ) {
  6625. matches.push( handleObj );
  6626. }
  6627. }
  6628. if ( matches.length ) {
  6629. handlerQueue.push({ elem: cur, handlers: matches });
  6630. }
  6631. }
  6632. }
  6633. }
  6634. // Add the remaining (directly-bound) handlers
  6635. if ( delegateCount < handlers.length ) {
  6636. handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
  6637. }
  6638. return handlerQueue;
  6639. },
  6640. // Includes some event props shared by KeyEvent and MouseEvent
  6641. props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
  6642. fixHooks: {},
  6643. keyHooks: {
  6644. props: "char charCode key keyCode".split(" "),
  6645. filter: function( event, original ) {
  6646. // Add which for key events
  6647. if ( event.which == null ) {
  6648. event.which = original.charCode != null ? original.charCode : original.keyCode;
  6649. }
  6650. return event;
  6651. }
  6652. },
  6653. mouseHooks: {
  6654. props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
  6655. filter: function( event, original ) {
  6656. var eventDoc, doc, body,
  6657. button = original.button;
  6658. // Calculate pageX/Y if missing and clientX/Y available
  6659. if ( event.pageX == null && original.clientX != null ) {
  6660. eventDoc = event.target.ownerDocument || document;
  6661. doc = eventDoc.documentElement;
  6662. body = eventDoc.body;
  6663. event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
  6664. event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
  6665. }
  6666. // Add which for click: 1 === left; 2 === middle; 3 === right
  6667. // Note: button is not normalized, so don't use it
  6668. if ( !event.which && button !== undefined ) {
  6669. event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
  6670. }
  6671. return event;
  6672. }
  6673. },
  6674. fix: function( event ) {
  6675. if ( event[ jQuery.expando ] ) {
  6676. return event;
  6677. }
  6678. // Create a writable copy of the event object and normalize some properties
  6679. var i, prop, copy,
  6680. type = event.type,
  6681. originalEvent = event,
  6682. fixHook = this.fixHooks[ type ];
  6683. if ( !fixHook ) {
  6684. this.fixHooks[ type ] = fixHook =
  6685. rmouseEvent.test( type ) ? this.mouseHooks :
  6686. rkeyEvent.test( type ) ? this.keyHooks :
  6687. {};
  6688. }
  6689. copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
  6690. event = new jQuery.Event( originalEvent );
  6691. i = copy.length;
  6692. while ( i-- ) {
  6693. prop = copy[ i ];
  6694. event[ prop ] = originalEvent[ prop ];
  6695. }
  6696. // Support: Cordova 2.5 (WebKit) (#13255)
  6697. // All events should have a target; Cordova deviceready doesn't
  6698. if ( !event.target ) {
  6699. event.target = document;
  6700. }
  6701. // Support: Safari 6.0+, Chrome < 28
  6702. // Target should not be a text node (#504, #13143)
  6703. if ( event.target.nodeType === 3 ) {
  6704. event.target = event.target.parentNode;
  6705. }
  6706. return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
  6707. },
  6708. special: {
  6709. load: {
  6710. // Prevent triggered image.load events from bubbling to window.load
  6711. noBubble: true
  6712. },
  6713. focus: {
  6714. // Fire native event if possible so blur/focus sequence is correct
  6715. trigger: function() {
  6716. if ( this !== safeActiveElement() && this.focus ) {
  6717. this.focus();
  6718. return false;
  6719. }
  6720. },
  6721. delegateType: "focusin"
  6722. },
  6723. blur: {
  6724. trigger: function() {
  6725. if ( this === safeActiveElement() && this.blur ) {
  6726. this.blur();
  6727. return false;
  6728. }
  6729. },
  6730. delegateType: "focusout"
  6731. },
  6732. click: {
  6733. // For checkbox, fire native event so checked state will be right
  6734. trigger: function() {
  6735. if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
  6736. this.click();
  6737. return false;
  6738. }
  6739. },
  6740. // For cross-browser consistency, don't fire native .click() on links
  6741. _default: function( event ) {
  6742. return jQuery.nodeName( event.target, "a" );
  6743. }
  6744. },
  6745. beforeunload: {
  6746. postDispatch: function( event ) {
  6747. // Support: Firefox 20+
  6748. // Firefox doesn't alert if the returnValue field is not set.
  6749. if ( event.result !== undefined ) {
  6750. event.originalEvent.returnValue = event.result;
  6751. }
  6752. }
  6753. }
  6754. },
  6755. simulate: function( type, elem, event, bubble ) {
  6756. // Piggyback on a donor event to simulate a different one.
  6757. // Fake originalEvent to avoid donor's stopPropagation, but if the
  6758. // simulated event prevents default then we do the same on the donor.
  6759. var e = jQuery.extend(
  6760. new jQuery.Event(),
  6761. event,
  6762. {
  6763. type: type,
  6764. isSimulated: true,
  6765. originalEvent: {}
  6766. }
  6767. );
  6768. if ( bubble ) {
  6769. jQuery.event.trigger( e, null, elem );
  6770. } else {
  6771. jQuery.event.dispatch.call( elem, e );
  6772. }
  6773. if ( e.isDefaultPrevented() ) {
  6774. event.preventDefault();
  6775. }
  6776. }
  6777. };
  6778. jQuery.removeEvent = function( elem, type, handle ) {
  6779. if ( elem.removeEventListener ) {
  6780. elem.removeEventListener( type, handle, false );
  6781. }
  6782. };
  6783. jQuery.Event = function( src, props ) {
  6784. // Allow instantiation without the 'new' keyword
  6785. if ( !(this instanceof jQuery.Event) ) {
  6786. return new jQuery.Event( src, props );
  6787. }
  6788. // Event object
  6789. if ( src && src.type ) {
  6790. this.originalEvent = src;
  6791. this.type = src.type;
  6792. // Events bubbling up the document may have been marked as prevented
  6793. // by a handler lower down the tree; reflect the correct value.
  6794. this.isDefaultPrevented = src.defaultPrevented ||
  6795. // Support: Android < 4.0
  6796. src.defaultPrevented === undefined &&
  6797. src.getPreventDefault && src.getPreventDefault() ?
  6798. returnTrue :
  6799. returnFalse;
  6800. // Event type
  6801. } else {
  6802. this.type = src;
  6803. }
  6804. // Put explicitly provided properties onto the event object
  6805. if ( props ) {
  6806. jQuery.extend( this, props );
  6807. }
  6808. // Create a timestamp if incoming event doesn't have one
  6809. this.timeStamp = src && src.timeStamp || jQuery.now();
  6810. // Mark it as fixed
  6811. this[ jQuery.expando ] = true;
  6812. };
  6813. // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
  6814. // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
  6815. jQuery.Event.prototype = {
  6816. isDefaultPrevented: returnFalse,
  6817. isPropagationStopped: returnFalse,
  6818. isImmediatePropagationStopped: returnFalse,
  6819. preventDefault: function() {
  6820. var e = this.originalEvent;
  6821. this.isDefaultPrevented = returnTrue;
  6822. if ( e && e.preventDefault ) {
  6823. e.preventDefault();
  6824. }
  6825. },
  6826. stopPropagation: function() {
  6827. var e = this.originalEvent;
  6828. this.isPropagationStopped = returnTrue;
  6829. if ( e && e.stopPropagation ) {
  6830. e.stopPropagation();
  6831. }
  6832. },
  6833. stopImmediatePropagation: function() {
  6834. this.isImmediatePropagationStopped = returnTrue;
  6835. this.stopPropagation();
  6836. }
  6837. };
  6838. // Create mouseenter/leave events using mouseover/out and event-time checks
  6839. // Support: Chrome 15+
  6840. jQuery.each({
  6841. mouseenter: "mouseover",
  6842. mouseleave: "mouseout"
  6843. }, function( orig, fix ) {
  6844. jQuery.event.special[ orig ] = {
  6845. delegateType: fix,
  6846. bindType: fix,
  6847. handle: function( event ) {
  6848. var ret,
  6849. target = this,
  6850. related = event.relatedTarget,
  6851. handleObj = event.handleObj;
  6852. // For mousenter/leave call the handler if related is outside the target.
  6853. // NB: No relatedTarget if the mouse left/entered the browser window
  6854. if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
  6855. event.type = handleObj.origType;
  6856. ret = handleObj.handler.apply( this, arguments );
  6857. event.type = fix;
  6858. }
  6859. return ret;
  6860. }
  6861. };
  6862. });
  6863. // Create "bubbling" focus and blur events
  6864. // Support: Firefox, Chrome, Safari
  6865. if ( !support.focusinBubbles ) {
  6866. jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
  6867. // Attach a single capturing handler on the document while someone wants focusin/focusout
  6868. var handler = function( event ) {
  6869. jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
  6870. };
  6871. jQuery.event.special[ fix ] = {
  6872. setup: function() {
  6873. var doc = this.ownerDocument || this,
  6874. attaches = data_priv.access( doc, fix );
  6875. if ( !attaches ) {
  6876. doc.addEventListener( orig, handler, true );
  6877. }
  6878. data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
  6879. },
  6880. teardown: function() {
  6881. var doc = this.ownerDocument || this,
  6882. attaches = data_priv.access( doc, fix ) - 1;
  6883. if ( !attaches ) {
  6884. doc.removeEventListener( orig, handler, true );
  6885. data_priv.remove( doc, fix );
  6886. } else {
  6887. data_priv.access( doc, fix, attaches );
  6888. }
  6889. }
  6890. };
  6891. });
  6892. }
  6893. jQuery.fn.extend({
  6894. on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
  6895. var origFn, type;
  6896. // Types can be a map of types/handlers
  6897. if ( typeof types === "object" ) {
  6898. // ( types-Object, selector, data )
  6899. if ( typeof selector !== "string" ) {
  6900. // ( types-Object, data )
  6901. data = data || selector;
  6902. selector = undefined;
  6903. }
  6904. for ( type in types ) {
  6905. this.on( type, selector, data, types[ type ], one );
  6906. }
  6907. return this;
  6908. }
  6909. if ( data == null && fn == null ) {
  6910. // ( types, fn )
  6911. fn = selector;
  6912. data = selector = undefined;
  6913. } else if ( fn == null ) {
  6914. if ( typeof selector === "string" ) {
  6915. // ( types, selector, fn )
  6916. fn = data;
  6917. data = undefined;
  6918. } else {
  6919. // ( types, data, fn )
  6920. fn = data;
  6921. data = selector;
  6922. selector = undefined;
  6923. }
  6924. }
  6925. if ( fn === false ) {
  6926. fn = returnFalse;
  6927. } else if ( !fn ) {
  6928. return this;
  6929. }
  6930. if ( one === 1 ) {
  6931. origFn = fn;
  6932. fn = function( event ) {
  6933. // Can use an empty set, since event contains the info
  6934. jQuery().off( event );
  6935. return origFn.apply( this, arguments );
  6936. };
  6937. // Use same guid so caller can remove using origFn
  6938. fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
  6939. }
  6940. return this.each( function() {
  6941. jQuery.event.add( this, types, fn, data, selector );
  6942. });
  6943. },
  6944. one: function( types, selector, data, fn ) {
  6945. return this.on( types, selector, data, fn, 1 );
  6946. },
  6947. off: function( types, selector, fn ) {
  6948. var handleObj, type;
  6949. if ( types && types.preventDefault && types.handleObj ) {
  6950. // ( event ) dispatched jQuery.Event
  6951. handleObj = types.handleObj;
  6952. jQuery( types.delegateTarget ).off(
  6953. handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
  6954. handleObj.selector,
  6955. handleObj.handler
  6956. );
  6957. return this;
  6958. }
  6959. if ( typeof types === "object" ) {
  6960. // ( types-object [, selector] )
  6961. for ( type in types ) {
  6962. this.off( type, selector, types[ type ] );
  6963. }
  6964. return this;
  6965. }
  6966. if ( selector === false || typeof selector === "function" ) {
  6967. // ( types [, fn] )
  6968. fn = selector;
  6969. selector = undefined;
  6970. }
  6971. if ( fn === false ) {
  6972. fn = returnFalse;
  6973. }
  6974. return this.each(function() {
  6975. jQuery.event.remove( this, types, fn, selector );
  6976. });
  6977. },
  6978. trigger: function( type, data ) {
  6979. return this.each(function() {
  6980. jQuery.event.trigger( type, data, this );
  6981. });
  6982. },
  6983. triggerHandler: function( type, data ) {
  6984. var elem = this[0];
  6985. if ( elem ) {
  6986. return jQuery.event.trigger( type, data, elem, true );
  6987. }
  6988. }
  6989. });
  6990. var
  6991. rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
  6992. rtagName = /<([\w:]+)/,
  6993. rhtml = /<|&#?\w+;/,
  6994. rnoInnerhtml = /<(?:script|style|link)/i,
  6995. // checked="checked" or checked
  6996. rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
  6997. rscriptType = /^$|\/(?:java|ecma)script/i,
  6998. rscriptTypeMasked = /^true\/(.*)/,
  6999. rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
  7000. // We have to close these tags to support XHTML (#13200)
  7001. wrapMap = {
  7002. // Support: IE 9
  7003. option: [ 1, "<select multiple='multiple'>", "</select>" ],
  7004. thead: [ 1, "<table>", "</table>" ],
  7005. col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
  7006. tr: [ 2, "<table><tbody>", "</tbody></table>" ],
  7007. td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
  7008. _default: [ 0, "", "" ]
  7009. };
  7010. // Support: IE 9
  7011. wrapMap.optgroup = wrapMap.option;
  7012. wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
  7013. wrapMap.th = wrapMap.td;
  7014. // Support: 1.x compatibility
  7015. // Manipulating tables requires a tbody
  7016. function manipulationTarget( elem, content ) {
  7017. return jQuery.nodeName( elem, "table" ) &&
  7018. jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
  7019. elem.getElementsByTagName("tbody")[0] ||
  7020. elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
  7021. elem;
  7022. }
  7023. // Replace/restore the type attribute of script elements for safe DOM manipulation
  7024. function disableScript( elem ) {
  7025. elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
  7026. return elem;
  7027. }
  7028. function restoreScript( elem ) {
  7029. var match = rscriptTypeMasked.exec( elem.type );
  7030. if ( match ) {
  7031. elem.type = match[ 1 ];
  7032. } else {
  7033. elem.removeAttribute("type");
  7034. }
  7035. return elem;
  7036. }
  7037. // Mark scripts as having already been evaluated
  7038. function setGlobalEval( elems, refElements ) {
  7039. var i = 0,
  7040. l = elems.length;
  7041. for ( ; i < l; i++ ) {
  7042. data_priv.set(
  7043. elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
  7044. );
  7045. }
  7046. }
  7047. function cloneCopyEvent( src, dest ) {
  7048. var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
  7049. if ( dest.nodeType !== 1 ) {
  7050. return;
  7051. }
  7052. // 1. Copy private data: events, handlers, etc.
  7053. if ( data_priv.hasData( src ) ) {
  7054. pdataOld = data_priv.access( src );
  7055. pdataCur = data_priv.set( dest, pdataOld );
  7056. events = pdataOld.events;
  7057. if ( events ) {
  7058. delete pdataCur.handle;
  7059. pdataCur.events = {};
  7060. for ( type in events ) {
  7061. for ( i = 0, l = events[ type ].length; i < l; i++ ) {
  7062. jQuery.event.add( dest, type, events[ type ][ i ] );
  7063. }
  7064. }
  7065. }
  7066. }
  7067. // 2. Copy user data
  7068. if ( data_user.hasData( src ) ) {
  7069. udataOld = data_user.access( src );
  7070. udataCur = jQuery.extend( {}, udataOld );
  7071. data_user.set( dest, udataCur );
  7072. }
  7073. }
  7074. function getAll( context, tag ) {
  7075. var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
  7076. context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
  7077. [];
  7078. return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
  7079. jQuery.merge( [ context ], ret ) :
  7080. ret;
  7081. }
  7082. // Support: IE >= 9
  7083. function fixInput( src, dest ) {
  7084. var nodeName = dest.nodeName.toLowerCase();
  7085. // Fails to persist the checked state of a cloned checkbox or radio button.
  7086. if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
  7087. dest.checked = src.checked;
  7088. // Fails to return the selected option to the default selected state when cloning options
  7089. } else if ( nodeName === "input" || nodeName === "textarea" ) {
  7090. dest.defaultValue = src.defaultValue;
  7091. }
  7092. }
  7093. jQuery.extend({
  7094. clone: function( elem, dataAndEvents, deepDataAndEvents ) {
  7095. var i, l, srcElements, destElements,
  7096. clone = elem.cloneNode( true ),
  7097. inPage = jQuery.contains( elem.ownerDocument, elem );
  7098. // Support: IE >= 9
  7099. // Fix Cloning issues
  7100. if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
  7101. !jQuery.isXMLDoc( elem ) ) {
  7102. // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
  7103. destElements = getAll( clone );
  7104. srcElements = getAll( elem );
  7105. for ( i = 0, l = srcElements.length; i < l; i++ ) {
  7106. fixInput( srcElements[ i ], destElements[ i ] );
  7107. }
  7108. }
  7109. // Copy the events from the original to the clone
  7110. if ( dataAndEvents ) {
  7111. if ( deepDataAndEvents ) {
  7112. srcElements = srcElements || getAll( elem );
  7113. destElements = destElements || getAll( clone );
  7114. for ( i = 0, l = srcElements.length; i < l; i++ ) {
  7115. cloneCopyEvent( srcElements[ i ], destElements[ i ] );
  7116. }
  7117. } else {
  7118. cloneCopyEvent( elem, clone );
  7119. }
  7120. }
  7121. // Preserve script evaluation history
  7122. destElements = getAll( clone, "script" );
  7123. if ( destElements.length > 0 ) {
  7124. setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
  7125. }
  7126. // Return the cloned set
  7127. return clone;
  7128. },
  7129. buildFragment: function( elems, context, scripts, selection ) {
  7130. var elem, tmp, tag, wrap, contains, j,
  7131. fragment = context.createDocumentFragment(),
  7132. nodes = [],
  7133. i = 0,
  7134. l = elems.length;
  7135. for ( ; i < l; i++ ) {
  7136. elem = elems[ i ];
  7137. if ( elem || elem === 0 ) {
  7138. // Add nodes directly
  7139. if ( jQuery.type( elem ) === "object" ) {
  7140. // Support: QtWebKit
  7141. // jQuery.merge because push.apply(_, arraylike) throws
  7142. jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
  7143. // Convert non-html into a text node
  7144. } else if ( !rhtml.test( elem ) ) {
  7145. nodes.push( context.createTextNode( elem ) );
  7146. // Convert html into DOM nodes
  7147. } else {
  7148. tmp = tmp || fragment.appendChild( context.createElement("div") );
  7149. // Deserialize a standard representation
  7150. tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
  7151. wrap = wrapMap[ tag ] || wrapMap._default;
  7152. tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
  7153. // Descend through wrappers to the right content
  7154. j = wrap[ 0 ];
  7155. while ( j-- ) {
  7156. tmp = tmp.lastChild;
  7157. }
  7158. // Support: QtWebKit
  7159. // jQuery.merge because push.apply(_, arraylike) throws
  7160. jQuery.merge( nodes, tmp.childNodes );
  7161. // Remember the top-level container
  7162. tmp = fragment.firstChild;
  7163. // Fixes #12346
  7164. // Support: Webkit, IE
  7165. tmp.textContent = "";
  7166. }
  7167. }
  7168. }
  7169. // Remove wrapper from fragment
  7170. fragment.textContent = "";
  7171. i = 0;
  7172. while ( (elem = nodes[ i++ ]) ) {
  7173. // #4087 - If origin and destination elements are the same, and this is
  7174. // that element, do not do anything
  7175. if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
  7176. continue;
  7177. }
  7178. contains = jQuery.contains( elem.ownerDocument, elem );
  7179. // Append to fragment
  7180. tmp = getAll( fragment.appendChild( elem ), "script" );
  7181. // Preserve script evaluation history
  7182. if ( contains ) {
  7183. setGlobalEval( tmp );
  7184. }
  7185. // Capture executables
  7186. if ( scripts ) {
  7187. j = 0;
  7188. while ( (elem = tmp[ j++ ]) ) {
  7189. if ( rscriptType.test( elem.type || "" ) ) {
  7190. scripts.push( elem );
  7191. }
  7192. }
  7193. }
  7194. }
  7195. return fragment;
  7196. },
  7197. cleanData: function( elems ) {
  7198. var data, elem, events, type, key, j,
  7199. special = jQuery.event.special,
  7200. i = 0;
  7201. for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
  7202. if ( jQuery.acceptData( elem ) ) {
  7203. key = elem[ data_priv.expando ];
  7204. if ( key && (data = data_priv.cache[ key ]) ) {
  7205. events = Object.keys( data.events || {} );
  7206. if ( events.length ) {
  7207. for ( j = 0; (type = events[j]) !== undefined; j++ ) {
  7208. if ( special[ type ] ) {
  7209. jQuery.event.remove( elem, type );
  7210. // This is a shortcut to avoid jQuery.event.remove's overhead
  7211. } else {
  7212. jQuery.removeEvent( elem, type, data.handle );
  7213. }
  7214. }
  7215. }
  7216. if ( data_priv.cache[ key ] ) {
  7217. // Discard any remaining `private` data
  7218. delete data_priv.cache[ key ];
  7219. }
  7220. }
  7221. }
  7222. // Discard any remaining `user` data
  7223. delete data_user.cache[ elem[ data_user.expando ] ];
  7224. }
  7225. }
  7226. });
  7227. jQuery.fn.extend({
  7228. text: function( value ) {
  7229. return access( this, function( value ) {
  7230. return value === undefined ?
  7231. jQuery.text( this ) :
  7232. this.empty().each(function() {
  7233. if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  7234. this.textContent = value;
  7235. }
  7236. });
  7237. }, null, value, arguments.length );
  7238. },
  7239. append: function() {
  7240. return this.domManip( arguments, function( elem ) {
  7241. if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  7242. var target = manipulationTarget( this, elem );
  7243. target.appendChild( elem );
  7244. }
  7245. });
  7246. },
  7247. prepend: function() {
  7248. return this.domManip( arguments, function( elem ) {
  7249. if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  7250. var target = manipulationTarget( this, elem );
  7251. target.insertBefore( elem, target.firstChild );
  7252. }
  7253. });
  7254. },
  7255. before: function() {
  7256. return this.domManip( arguments, function( elem ) {
  7257. if ( this.parentNode ) {
  7258. this.parentNode.insertBefore( elem, this );
  7259. }
  7260. });
  7261. },
  7262. after: function() {
  7263. return this.domManip( arguments, function( elem ) {
  7264. if ( this.parentNode ) {
  7265. this.parentNode.insertBefore( elem, this.nextSibling );
  7266. }
  7267. });
  7268. },
  7269. remove: function( selector, keepData /* Internal Use Only */ ) {
  7270. var elem,
  7271. elems = selector ? jQuery.filter( selector, this ) : this,
  7272. i = 0;
  7273. for ( ; (elem = elems[i]) != null; i++ ) {
  7274. if ( !keepData && elem.nodeType === 1 ) {
  7275. jQuery.cleanData( getAll( elem ) );
  7276. }
  7277. if ( elem.parentNode ) {
  7278. if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
  7279. setGlobalEval( getAll( elem, "script" ) );
  7280. }
  7281. elem.parentNode.removeChild( elem );
  7282. }
  7283. }
  7284. return this;
  7285. },
  7286. empty: function() {
  7287. var elem,
  7288. i = 0;
  7289. for ( ; (elem = this[i]) != null; i++ ) {
  7290. if ( elem.nodeType === 1 ) {
  7291. // Prevent memory leaks
  7292. jQuery.cleanData( getAll( elem, false ) );
  7293. // Remove any remaining nodes
  7294. elem.textContent = "";
  7295. }
  7296. }
  7297. return this;
  7298. },
  7299. clone: function( dataAndEvents, deepDataAndEvents ) {
  7300. dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
  7301. deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
  7302. return this.map(function() {
  7303. return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
  7304. });
  7305. },
  7306. html: function( value ) {
  7307. return access( this, function( value ) {
  7308. var elem = this[ 0 ] || {},
  7309. i = 0,
  7310. l = this.length;
  7311. if ( value === undefined && elem.nodeType === 1 ) {
  7312. return elem.innerHTML;
  7313. }
  7314. // See if we can take a shortcut and just use innerHTML
  7315. if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
  7316. !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
  7317. value = value.replace( rxhtmlTag, "<$1></$2>" );
  7318. try {
  7319. for ( ; i < l; i++ ) {
  7320. elem = this[ i ] || {};
  7321. // Remove element nodes and prevent memory leaks
  7322. if ( elem.nodeType === 1 ) {
  7323. jQuery.cleanData( getAll( elem, false ) );
  7324. elem.innerHTML = value;
  7325. }
  7326. }
  7327. elem = 0;
  7328. // If using innerHTML throws an exception, use the fallback method
  7329. } catch( e ) {}
  7330. }
  7331. if ( elem ) {
  7332. this.empty().append( value );
  7333. }
  7334. }, null, value, arguments.length );
  7335. },
  7336. replaceWith: function() {
  7337. var arg = arguments[ 0 ];
  7338. // Make the changes, replacing each context element with the new content
  7339. this.domManip( arguments, function( elem ) {
  7340. arg = this.parentNode;
  7341. jQuery.cleanData( getAll( this ) );
  7342. if ( arg ) {
  7343. arg.replaceChild( elem, this );
  7344. }
  7345. });
  7346. // Force removal if there was no new content (e.g., from empty arguments)
  7347. return arg && (arg.length || arg.nodeType) ? this : this.remove();
  7348. },
  7349. detach: function( selector ) {
  7350. return this.remove( selector, true );
  7351. },
  7352. domManip: function( args, callback ) {
  7353. // Flatten any nested arrays
  7354. args = concat.apply( [], args );
  7355. var fragment, first, scripts, hasScripts, node, doc,
  7356. i = 0,
  7357. l = this.length,
  7358. set = this,
  7359. iNoClone = l - 1,
  7360. value = args[ 0 ],
  7361. isFunction = jQuery.isFunction( value );
  7362. // We can't cloneNode fragments that contain checked, in WebKit
  7363. if ( isFunction ||
  7364. ( l > 1 && typeof value === "string" &&
  7365. !support.checkClone && rchecked.test( value ) ) ) {
  7366. return this.each(function( index ) {
  7367. var self = set.eq( index );
  7368. if ( isFunction ) {
  7369. args[ 0 ] = value.call( this, index, self.html() );
  7370. }
  7371. self.domManip( args, callback );
  7372. });
  7373. }
  7374. if ( l ) {
  7375. fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
  7376. first = fragment.firstChild;
  7377. if ( fragment.childNodes.length === 1 ) {
  7378. fragment = first;
  7379. }
  7380. if ( first ) {
  7381. scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
  7382. hasScripts = scripts.length;
  7383. // Use the original fragment for the last item instead of the first because it can end up
  7384. // being emptied incorrectly in certain situations (#8070).
  7385. for ( ; i < l; i++ ) {
  7386. node = fragment;
  7387. if ( i !== iNoClone ) {
  7388. node = jQuery.clone( node, true, true );
  7389. // Keep references to cloned scripts for later restoration
  7390. if ( hasScripts ) {
  7391. // Support: QtWebKit
  7392. // jQuery.merge because push.apply(_, arraylike) throws
  7393. jQuery.merge( scripts, getAll( node, "script" ) );
  7394. }
  7395. }
  7396. callback.call( this[ i ], node, i );
  7397. }
  7398. if ( hasScripts ) {
  7399. doc = scripts[ scripts.length - 1 ].ownerDocument;
  7400. // Reenable scripts
  7401. jQuery.map( scripts, restoreScript );
  7402. // Evaluate executable scripts on first document insertion
  7403. for ( i = 0; i < hasScripts; i++ ) {
  7404. node = scripts[ i ];
  7405. if ( rscriptType.test( node.type || "" ) &&
  7406. !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
  7407. if ( node.src ) {
  7408. // Optional AJAX dependency, but won't run scripts if not present
  7409. if ( jQuery._evalUrl ) {
  7410. jQuery._evalUrl( node.src );
  7411. }
  7412. } else {
  7413. jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
  7414. }
  7415. }
  7416. }
  7417. }
  7418. }
  7419. }
  7420. return this;
  7421. }
  7422. });
  7423. jQuery.each({
  7424. appendTo: "append",
  7425. prependTo: "prepend",
  7426. insertBefore: "before",
  7427. insertAfter: "after",
  7428. replaceAll: "replaceWith"
  7429. }, function( name, original ) {
  7430. jQuery.fn[ name ] = function( selector ) {
  7431. var elems,
  7432. ret = [],
  7433. insert = jQuery( selector ),
  7434. last = insert.length - 1,
  7435. i = 0;
  7436. for ( ; i <= last; i++ ) {
  7437. elems = i === last ? this : this.clone( true );
  7438. jQuery( insert[ i ] )[ original ]( elems );
  7439. // Support: QtWebKit
  7440. // .get() because push.apply(_, arraylike) throws
  7441. push.apply( ret, elems.get() );
  7442. }
  7443. return this.pushStack( ret );
  7444. };
  7445. });
  7446. var iframe,
  7447. elemdisplay = {};
  7448. /**
  7449. * Retrieve the actual display of a element
  7450. * @param {String} name nodeName of the element
  7451. * @param {Object} doc Document object
  7452. */
  7453. // Called only from within defaultDisplay
  7454. function actualDisplay( name, doc ) {
  7455. var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
  7456. // getDefaultComputedStyle might be reliably used only on attached element
  7457. display = window.getDefaultComputedStyle ?
  7458. // Use of this method is a temporary fix (more like optmization) until something better comes along,
  7459. // since it was removed from specification and supported only in FF
  7460. window.getDefaultComputedStyle( elem[ 0 ] ).display : jQuery.css( elem[ 0 ], "display" );
  7461. // We don't have any data stored on the element,
  7462. // so use "detach" method as fast way to get rid of the element
  7463. elem.detach();
  7464. return display;
  7465. }
  7466. /**
  7467. * Try to determine the default display value of an element
  7468. * @param {String} nodeName
  7469. */
  7470. function defaultDisplay( nodeName ) {
  7471. var doc = document,
  7472. display = elemdisplay[ nodeName ];
  7473. if ( !display ) {
  7474. display = actualDisplay( nodeName, doc );
  7475. // If the simple way fails, read from inside an iframe
  7476. if ( display === "none" || !display ) {
  7477. // Use the already-created iframe if possible
  7478. iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
  7479. // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
  7480. doc = iframe[ 0 ].contentDocument;
  7481. // Support: IE
  7482. doc.write();
  7483. doc.close();
  7484. display = actualDisplay( nodeName, doc );
  7485. iframe.detach();
  7486. }
  7487. // Store the correct default display
  7488. elemdisplay[ nodeName ] = display;
  7489. }
  7490. return display;
  7491. }
  7492. var rmargin = (/^margin/);
  7493. var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
  7494. var getStyles = function( elem ) {
  7495. return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
  7496. };
  7497. function curCSS( elem, name, computed ) {
  7498. var width, minWidth, maxWidth, ret,
  7499. style = elem.style;
  7500. computed = computed || getStyles( elem );
  7501. // Support: IE9
  7502. // getPropertyValue is only needed for .css('filter') in IE9, see #12537
  7503. if ( computed ) {
  7504. ret = computed.getPropertyValue( name ) || computed[ name ];
  7505. }
  7506. if ( computed ) {
  7507. if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
  7508. ret = jQuery.style( elem, name );
  7509. }
  7510. // Support: iOS < 6
  7511. // A tribute to the "awesome hack by Dean Edwards"
  7512. // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
  7513. // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
  7514. if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
  7515. // Remember the original values
  7516. width = style.width;
  7517. minWidth = style.minWidth;
  7518. maxWidth = style.maxWidth;
  7519. // Put in the new values to get a computed value out
  7520. style.minWidth = style.maxWidth = style.width = ret;
  7521. ret = computed.width;
  7522. // Revert the changed values
  7523. style.width = width;
  7524. style.minWidth = minWidth;
  7525. style.maxWidth = maxWidth;
  7526. }
  7527. }
  7528. return ret !== undefined ?
  7529. // Support: IE
  7530. // IE returns zIndex value as an integer.
  7531. ret + "" :
  7532. ret;
  7533. }
  7534. function addGetHookIf( conditionFn, hookFn ) {
  7535. // Define the hook, we'll check on the first run if it's really needed.
  7536. return {
  7537. get: function() {
  7538. if ( conditionFn() ) {
  7539. // Hook not needed (or it's not possible to use it due to missing dependency),
  7540. // remove it.
  7541. // Since there are no other hooks for marginRight, remove the whole object.
  7542. delete this.get;
  7543. return;
  7544. }
  7545. // Hook needed; redefine it so that the support test is not executed again.
  7546. return (this.get = hookFn).apply( this, arguments );
  7547. }
  7548. };
  7549. }
  7550. (function() {
  7551. var pixelPositionVal, boxSizingReliableVal,
  7552. // Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
  7553. divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;" +
  7554. "-moz-box-sizing:content-box;box-sizing:content-box",
  7555. docElem = document.documentElement,
  7556. container = document.createElement( "div" ),
  7557. div = document.createElement( "div" );
  7558. div.style.backgroundClip = "content-box";
  7559. div.cloneNode( true ).style.backgroundClip = "";
  7560. support.clearCloneStyle = div.style.backgroundClip === "content-box";
  7561. container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;" +
  7562. "margin-top:1px";
  7563. container.appendChild( div );
  7564. // Executing both pixelPosition & boxSizingReliable tests require only one layout
  7565. // so they're executed at the same time to save the second computation.
  7566. function computePixelPositionAndBoxSizingReliable() {
  7567. // Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
  7568. div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
  7569. "box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;" +
  7570. "position:absolute;top:1%";
  7571. docElem.appendChild( container );
  7572. var divStyle = window.getComputedStyle( div, null );
  7573. pixelPositionVal = divStyle.top !== "1%";
  7574. boxSizingReliableVal = divStyle.width === "4px";
  7575. docElem.removeChild( container );
  7576. }
  7577. // Use window.getComputedStyle because jsdom on node.js will break without it.
  7578. if ( window.getComputedStyle ) {
  7579. jQuery.extend(support, {
  7580. pixelPosition: function() {
  7581. // This test is executed only once but we still do memoizing
  7582. // since we can use the boxSizingReliable pre-computing.
  7583. // No need to check if the test was already performed, though.
  7584. computePixelPositionAndBoxSizingReliable();
  7585. return pixelPositionVal;
  7586. },
  7587. boxSizingReliable: function() {
  7588. if ( boxSizingReliableVal == null ) {
  7589. computePixelPositionAndBoxSizingReliable();
  7590. }
  7591. return boxSizingReliableVal;
  7592. },
  7593. reliableMarginRight: function() {
  7594. // Support: Android 2.3
  7595. // Check if div with explicit width and no margin-right incorrectly
  7596. // gets computed margin-right based on width of container. (#3333)
  7597. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  7598. // This support function is only executed once so no memoizing is needed.
  7599. var ret,
  7600. marginDiv = div.appendChild( document.createElement( "div" ) );
  7601. marginDiv.style.cssText = div.style.cssText = divReset;
  7602. marginDiv.style.marginRight = marginDiv.style.width = "0";
  7603. div.style.width = "1px";
  7604. docElem.appendChild( container );
  7605. ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
  7606. docElem.removeChild( container );
  7607. // Clean up the div for other support tests.
  7608. div.innerHTML = "";
  7609. return ret;
  7610. }
  7611. });
  7612. }
  7613. })();
  7614. // A method for quickly swapping in/out CSS properties to get correct calculations.
  7615. jQuery.swap = function( elem, options, callback, args ) {
  7616. var ret, name,
  7617. old = {};
  7618. // Remember the old values, and insert the new ones
  7619. for ( name in options ) {
  7620. old[ name ] = elem.style[ name ];
  7621. elem.style[ name ] = options[ name ];
  7622. }
  7623. ret = callback.apply( elem, args || [] );
  7624. // Revert the old values
  7625. for ( name in options ) {
  7626. elem.style[ name ] = old[ name ];
  7627. }
  7628. return ret;
  7629. };
  7630. var
  7631. // swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
  7632. // see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
  7633. rdisplayswap = /^(none|table(?!-c[ea]).+)/,
  7634. rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
  7635. rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
  7636. cssShow = { position: "absolute", visibility: "hidden", display: "block" },
  7637. cssNormalTransform = {
  7638. letterSpacing: 0,
  7639. fontWeight: 400
  7640. },
  7641. cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
  7642. // return a css property mapped to a potentially vendor prefixed property
  7643. function vendorPropName( style, name ) {
  7644. // shortcut for names that are not vendor prefixed
  7645. if ( name in style ) {
  7646. return name;
  7647. }
  7648. // check for vendor prefixed names
  7649. var capName = name[0].toUpperCase() + name.slice(1),
  7650. origName = name,
  7651. i = cssPrefixes.length;
  7652. while ( i-- ) {
  7653. name = cssPrefixes[ i ] + capName;
  7654. if ( name in style ) {
  7655. return name;
  7656. }
  7657. }
  7658. return origName;
  7659. }
  7660. function setPositiveNumber( elem, value, subtract ) {
  7661. var matches = rnumsplit.exec( value );
  7662. return matches ?
  7663. // Guard against undefined "subtract", e.g., when used as in cssHooks
  7664. Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
  7665. value;
  7666. }
  7667. function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
  7668. var i = extra === ( isBorderBox ? "border" : "content" ) ?
  7669. // If we already have the right measurement, avoid augmentation
  7670. 4 :
  7671. // Otherwise initialize for horizontal or vertical properties
  7672. name === "width" ? 1 : 0,
  7673. val = 0;
  7674. for ( ; i < 4; i += 2 ) {
  7675. // both box models exclude margin, so add it if we want it
  7676. if ( extra === "margin" ) {
  7677. val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
  7678. }
  7679. if ( isBorderBox ) {
  7680. // border-box includes padding, so remove it if we want content
  7681. if ( extra === "content" ) {
  7682. val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
  7683. }
  7684. // at this point, extra isn't border nor margin, so remove border
  7685. if ( extra !== "margin" ) {
  7686. val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
  7687. }
  7688. } else {
  7689. // at this point, extra isn't content, so add padding
  7690. val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
  7691. // at this point, extra isn't content nor padding, so add border
  7692. if ( extra !== "padding" ) {
  7693. val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
  7694. }
  7695. }
  7696. }
  7697. return val;
  7698. }
  7699. function getWidthOrHeight( elem, name, extra ) {
  7700. // Start with offset property, which is equivalent to the border-box value
  7701. var valueIsBorderBox = true,
  7702. val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
  7703. styles = getStyles( elem ),
  7704. isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
  7705. // some non-html elements return undefined for offsetWidth, so check for null/undefined
  7706. // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
  7707. // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
  7708. if ( val <= 0 || val == null ) {
  7709. // Fall back to computed then uncomputed css if necessary
  7710. val = curCSS( elem, name, styles );
  7711. if ( val < 0 || val == null ) {
  7712. val = elem.style[ name ];
  7713. }
  7714. // Computed unit is not pixels. Stop here and return.
  7715. if ( rnumnonpx.test(val) ) {
  7716. return val;
  7717. }
  7718. // we need the check for style in case a browser which returns unreliable values
  7719. // for getComputedStyle silently falls back to the reliable elem.style
  7720. valueIsBorderBox = isBorderBox &&
  7721. ( support.boxSizingReliable() || val === elem.style[ name ] );
  7722. // Normalize "", auto, and prepare for extra
  7723. val = parseFloat( val ) || 0;
  7724. }
  7725. // use the active box-sizing model to add/subtract irrelevant styles
  7726. return ( val +
  7727. augmentWidthOrHeight(
  7728. elem,
  7729. name,
  7730. extra || ( isBorderBox ? "border" : "content" ),
  7731. valueIsBorderBox,
  7732. styles
  7733. )
  7734. ) + "px";
  7735. }
  7736. function showHide( elements, show ) {
  7737. var display, elem, hidden,
  7738. values = [],
  7739. index = 0,
  7740. length = elements.length;
  7741. for ( ; index < length; index++ ) {
  7742. elem = elements[ index ];
  7743. if ( !elem.style ) {
  7744. continue;
  7745. }
  7746. values[ index ] = data_priv.get( elem, "olddisplay" );
  7747. display = elem.style.display;
  7748. if ( show ) {
  7749. // Reset the inline display of this element to learn if it is
  7750. // being hidden by cascaded rules or not
  7751. if ( !values[ index ] && display === "none" ) {
  7752. elem.style.display = "";
  7753. }
  7754. // Set elements which have been overridden with display: none
  7755. // in a stylesheet to whatever the default browser style is
  7756. // for such an element
  7757. if ( elem.style.display === "" && isHidden( elem ) ) {
  7758. values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
  7759. }
  7760. } else {
  7761. if ( !values[ index ] ) {
  7762. hidden = isHidden( elem );
  7763. if ( display && display !== "none" || !hidden ) {
  7764. data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css(elem, "display") );
  7765. }
  7766. }
  7767. }
  7768. }
  7769. // Set the display of most of the elements in a second loop
  7770. // to avoid the constant reflow
  7771. for ( index = 0; index < length; index++ ) {
  7772. elem = elements[ index ];
  7773. if ( !elem.style ) {
  7774. continue;
  7775. }
  7776. if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
  7777. elem.style.display = show ? values[ index ] || "" : "none";
  7778. }
  7779. }
  7780. return elements;
  7781. }
  7782. jQuery.extend({
  7783. // Add in style property hooks for overriding the default
  7784. // behavior of getting and setting a style property
  7785. cssHooks: {
  7786. opacity: {
  7787. get: function( elem, computed ) {
  7788. if ( computed ) {
  7789. // We should always get a number back from opacity
  7790. var ret = curCSS( elem, "opacity" );
  7791. return ret === "" ? "1" : ret;
  7792. }
  7793. }
  7794. }
  7795. },
  7796. // Don't automatically add "px" to these possibly-unitless properties
  7797. cssNumber: {
  7798. "columnCount": true,
  7799. "fillOpacity": true,
  7800. "fontWeight": true,
  7801. "lineHeight": true,
  7802. "opacity": true,
  7803. "order": true,
  7804. "orphans": true,
  7805. "widows": true,
  7806. "zIndex": true,
  7807. "zoom": true
  7808. },
  7809. // Add in properties whose names you wish to fix before
  7810. // setting or getting the value
  7811. cssProps: {
  7812. // normalize float css property
  7813. "float": "cssFloat"
  7814. },
  7815. // Get and set the style property on a DOM Node
  7816. style: function( elem, name, value, extra ) {
  7817. // Don't set styles on text and comment nodes
  7818. if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
  7819. return;
  7820. }
  7821. // Make sure that we're working with the right name
  7822. var ret, type, hooks,
  7823. origName = jQuery.camelCase( name ),
  7824. style = elem.style;
  7825. name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
  7826. // gets hook for the prefixed version
  7827. // followed by the unprefixed version
  7828. hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
  7829. // Check if we're setting a value
  7830. if ( value !== undefined ) {
  7831. type = typeof value;
  7832. // convert relative number strings (+= or -=) to relative numbers. #7345
  7833. if ( type === "string" && (ret = rrelNum.exec( value )) ) {
  7834. value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
  7835. // Fixes bug #9237
  7836. type = "number";
  7837. }
  7838. // Make sure that null and NaN values aren't set. See: #7116
  7839. if ( value == null || value !== value ) {
  7840. return;
  7841. }
  7842. // If a number was passed in, add 'px' to the (except for certain CSS properties)
  7843. if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
  7844. value += "px";
  7845. }
  7846. // Fixes #8908, it can be done more correctly by specifying setters in cssHooks,
  7847. // but it would mean to define eight (for every problematic property) identical functions
  7848. if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
  7849. style[ name ] = "inherit";
  7850. }
  7851. // If a hook was provided, use that value, otherwise just set the specified value
  7852. if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
  7853. // Support: Chrome, Safari
  7854. // Setting style to blank string required to delete "style: x !important;"
  7855. style[ name ] = "";
  7856. style[ name ] = value;
  7857. }
  7858. } else {
  7859. // If a hook was provided get the non-computed value from there
  7860. if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
  7861. return ret;
  7862. }
  7863. // Otherwise just get the value from the style object
  7864. return style[ name ];
  7865. }
  7866. },
  7867. css: function( elem, name, extra, styles ) {
  7868. var val, num, hooks,
  7869. origName = jQuery.camelCase( name );
  7870. // Make sure that we're working with the right name
  7871. name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
  7872. // gets hook for the prefixed version
  7873. // followed by the unprefixed version
  7874. hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
  7875. // If a hook was provided get the computed value from there
  7876. if ( hooks && "get" in hooks ) {
  7877. val = hooks.get( elem, true, extra );
  7878. }
  7879. // Otherwise, if a way to get the computed value exists, use that
  7880. if ( val === undefined ) {
  7881. val = curCSS( elem, name, styles );
  7882. }
  7883. //convert "normal" to computed value
  7884. if ( val === "normal" && name in cssNormalTransform ) {
  7885. val = cssNormalTransform[ name ];
  7886. }
  7887. // Return, converting to number if forced or a qualifier was provided and val looks numeric
  7888. if ( extra === "" || extra ) {
  7889. num = parseFloat( val );
  7890. return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
  7891. }
  7892. return val;
  7893. }
  7894. });
  7895. jQuery.each([ "height", "width" ], function( i, name ) {
  7896. jQuery.cssHooks[ name ] = {
  7897. get: function( elem, computed, extra ) {
  7898. if ( computed ) {
  7899. // certain elements can have dimension info if we invisibly show them
  7900. // however, it must have a current display style that would benefit from this
  7901. return elem.offsetWidth === 0 && rdisplayswap.test( jQuery.css( elem, "display" ) ) ?
  7902. jQuery.swap( elem, cssShow, function() {
  7903. return getWidthOrHeight( elem, name, extra );
  7904. }) :
  7905. getWidthOrHeight( elem, name, extra );
  7906. }
  7907. },
  7908. set: function( elem, value, extra ) {
  7909. var styles = extra && getStyles( elem );
  7910. return setPositiveNumber( elem, value, extra ?
  7911. augmentWidthOrHeight(
  7912. elem,
  7913. name,
  7914. extra,
  7915. jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
  7916. styles
  7917. ) : 0
  7918. );
  7919. }
  7920. };
  7921. });
  7922. // Support: Android 2.3
  7923. jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
  7924. function( elem, computed ) {
  7925. if ( computed ) {
  7926. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  7927. // Work around by temporarily setting element display to inline-block
  7928. return jQuery.swap( elem, { "display": "inline-block" },
  7929. curCSS, [ elem, "marginRight" ] );
  7930. }
  7931. }
  7932. );
  7933. // These hooks are used by animate to expand properties
  7934. jQuery.each({
  7935. margin: "",
  7936. padding: "",
  7937. border: "Width"
  7938. }, function( prefix, suffix ) {
  7939. jQuery.cssHooks[ prefix + suffix ] = {
  7940. expand: function( value ) {
  7941. var i = 0,
  7942. expanded = {},
  7943. // assumes a single number if not a string
  7944. parts = typeof value === "string" ? value.split(" ") : [ value ];
  7945. for ( ; i < 4; i++ ) {
  7946. expanded[ prefix + cssExpand[ i ] + suffix ] =
  7947. parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
  7948. }
  7949. return expanded;
  7950. }
  7951. };
  7952. if ( !rmargin.test( prefix ) ) {
  7953. jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
  7954. }
  7955. });
  7956. jQuery.fn.extend({
  7957. css: function( name, value ) {
  7958. return access( this, function( elem, name, value ) {
  7959. var styles, len,
  7960. map = {},
  7961. i = 0;
  7962. if ( jQuery.isArray( name ) ) {
  7963. styles = getStyles( elem );
  7964. len = name.length;
  7965. for ( ; i < len; i++ ) {
  7966. map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
  7967. }
  7968. return map;
  7969. }
  7970. return value !== undefined ?
  7971. jQuery.style( elem, name, value ) :
  7972. jQuery.css( elem, name );
  7973. }, name, value, arguments.length > 1 );
  7974. },
  7975. show: function() {
  7976. return showHide( this, true );
  7977. },
  7978. hide: function() {
  7979. return showHide( this );
  7980. },
  7981. toggle: function( state ) {
  7982. if ( typeof state === "boolean" ) {
  7983. return state ? this.show() : this.hide();
  7984. }
  7985. return this.each(function() {
  7986. if ( isHidden( this ) ) {
  7987. jQuery( this ).show();
  7988. } else {
  7989. jQuery( this ).hide();
  7990. }
  7991. });
  7992. }
  7993. });
  7994. function Tween( elem, options, prop, end, easing ) {
  7995. return new Tween.prototype.init( elem, options, prop, end, easing );
  7996. }
  7997. jQuery.Tween = Tween;
  7998. Tween.prototype = {
  7999. constructor: Tween,
  8000. init: function( elem, options, prop, end, easing, unit ) {
  8001. this.elem = elem;
  8002. this.prop = prop;
  8003. this.easing = easing || "swing";
  8004. this.options = options;
  8005. this.start = this.now = this.cur();
  8006. this.end = end;
  8007. this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
  8008. },
  8009. cur: function() {
  8010. var hooks = Tween.propHooks[ this.prop ];
  8011. return hooks && hooks.get ?
  8012. hooks.get( this ) :
  8013. Tween.propHooks._default.get( this );
  8014. },
  8015. run: function( percent ) {
  8016. var eased,
  8017. hooks = Tween.propHooks[ this.prop ];
  8018. if ( this.options.duration ) {
  8019. this.pos = eased = jQuery.easing[ this.easing ](
  8020. percent, this.options.duration * percent, 0, 1, this.options.duration
  8021. );
  8022. } else {
  8023. this.pos = eased = percent;
  8024. }
  8025. this.now = ( this.end - this.start ) * eased + this.start;
  8026. if ( this.options.step ) {
  8027. this.options.step.call( this.elem, this.now, this );
  8028. }
  8029. if ( hooks && hooks.set ) {
  8030. hooks.set( this );
  8031. } else {
  8032. Tween.propHooks._default.set( this );
  8033. }
  8034. return this;
  8035. }
  8036. };
  8037. Tween.prototype.init.prototype = Tween.prototype;
  8038. Tween.propHooks = {
  8039. _default: {
  8040. get: function( tween ) {
  8041. var result;
  8042. if ( tween.elem[ tween.prop ] != null &&
  8043. (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
  8044. return tween.elem[ tween.prop ];
  8045. }
  8046. // passing an empty string as a 3rd parameter to .css will automatically
  8047. // attempt a parseFloat and fallback to a string if the parse fails
  8048. // so, simple values such as "10px" are parsed to Float.
  8049. // complex values such as "rotate(1rad)" are returned as is.
  8050. result = jQuery.css( tween.elem, tween.prop, "" );
  8051. // Empty strings, null, undefined and "auto" are converted to 0.
  8052. return !result || result === "auto" ? 0 : result;
  8053. },
  8054. set: function( tween ) {
  8055. // use step hook for back compat - use cssHook if its there - use .style if its
  8056. // available and use plain properties where available
  8057. if ( jQuery.fx.step[ tween.prop ] ) {
  8058. jQuery.fx.step[ tween.prop ]( tween );
  8059. } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
  8060. jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
  8061. } else {
  8062. tween.elem[ tween.prop ] = tween.now;
  8063. }
  8064. }
  8065. }
  8066. };
  8067. // Support: IE9
  8068. // Panic based approach to setting things on disconnected nodes
  8069. Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
  8070. set: function( tween ) {
  8071. if ( tween.elem.nodeType && tween.elem.parentNode ) {
  8072. tween.elem[ tween.prop ] = tween.now;
  8073. }
  8074. }
  8075. };
  8076. jQuery.easing = {
  8077. linear: function( p ) {
  8078. return p;
  8079. },
  8080. swing: function( p ) {
  8081. return 0.5 - Math.cos( p * Math.PI ) / 2;
  8082. }
  8083. };
  8084. jQuery.fx = Tween.prototype.init;
  8085. // Back Compat <1.8 extension point
  8086. jQuery.fx.step = {};
  8087. var
  8088. fxNow, timerId,
  8089. rfxtypes = /^(?:toggle|show|hide)$/,
  8090. rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
  8091. rrun = /queueHooks$/,
  8092. animationPrefilters = [ defaultPrefilter ],
  8093. tweeners = {
  8094. "*": [ function( prop, value ) {
  8095. var tween = this.createTween( prop, value ),
  8096. target = tween.cur(),
  8097. parts = rfxnum.exec( value ),
  8098. unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
  8099. // Starting value computation is required for potential unit mismatches
  8100. start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
  8101. rfxnum.exec( jQuery.css( tween.elem, prop ) ),
  8102. scale = 1,
  8103. maxIterations = 20;
  8104. if ( start && start[ 3 ] !== unit ) {
  8105. // Trust units reported by jQuery.css
  8106. unit = unit || start[ 3 ];
  8107. // Make sure we update the tween properties later on
  8108. parts = parts || [];
  8109. // Iteratively approximate from a nonzero starting point
  8110. start = +target || 1;
  8111. do {
  8112. // If previous iteration zeroed out, double until we get *something*
  8113. // Use a string for doubling factor so we don't accidentally see scale as unchanged below
  8114. scale = scale || ".5";
  8115. // Adjust and apply
  8116. start = start / scale;
  8117. jQuery.style( tween.elem, prop, start + unit );
  8118. // Update scale, tolerating zero or NaN from tween.cur()
  8119. // And breaking the loop if scale is unchanged or perfect, or if we've just had enough
  8120. } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
  8121. }
  8122. // Update tween properties
  8123. if ( parts ) {
  8124. start = tween.start = +start || +target || 0;
  8125. tween.unit = unit;
  8126. // If a +=/-= token was provided, we're doing a relative animation
  8127. tween.end = parts[ 1 ] ?
  8128. start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
  8129. +parts[ 2 ];
  8130. }
  8131. return tween;
  8132. } ]
  8133. };
  8134. // Animations created synchronously will run synchronously
  8135. function createFxNow() {
  8136. setTimeout(function() {
  8137. fxNow = undefined;
  8138. });
  8139. return ( fxNow = jQuery.now() );
  8140. }
  8141. // Generate parameters to create a standard animation
  8142. function genFx( type, includeWidth ) {
  8143. var which,
  8144. i = 0,
  8145. attrs = { height: type };
  8146. // if we include width, step value is 1 to do all cssExpand values,
  8147. // if we don't include width, step value is 2 to skip over Left and Right
  8148. includeWidth = includeWidth ? 1 : 0;
  8149. for ( ; i < 4 ; i += 2 - includeWidth ) {
  8150. which = cssExpand[ i ];
  8151. attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
  8152. }
  8153. if ( includeWidth ) {
  8154. attrs.opacity = attrs.width = type;
  8155. }
  8156. return attrs;
  8157. }
  8158. function createTween( value, prop, animation ) {
  8159. var tween,
  8160. collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
  8161. index = 0,
  8162. length = collection.length;
  8163. for ( ; index < length; index++ ) {
  8164. if ( (tween = collection[ index ].call( animation, prop, value )) ) {
  8165. // we're done with this property
  8166. return tween;
  8167. }
  8168. }
  8169. }
  8170. function defaultPrefilter( elem, props, opts ) {
  8171. /* jshint validthis: true */
  8172. var prop, value, toggle, tween, hooks, oldfire, display,
  8173. anim = this,
  8174. orig = {},
  8175. style = elem.style,
  8176. hidden = elem.nodeType && isHidden( elem ),
  8177. dataShow = data_priv.get( elem, "fxshow" );
  8178. // handle queue: false promises
  8179. if ( !opts.queue ) {
  8180. hooks = jQuery._queueHooks( elem, "fx" );
  8181. if ( hooks.unqueued == null ) {
  8182. hooks.unqueued = 0;
  8183. oldfire = hooks.empty.fire;
  8184. hooks.empty.fire = function() {
  8185. if ( !hooks.unqueued ) {
  8186. oldfire();
  8187. }
  8188. };
  8189. }
  8190. hooks.unqueued++;
  8191. anim.always(function() {
  8192. // doing this makes sure that the complete handler will be called
  8193. // before this completes
  8194. anim.always(function() {
  8195. hooks.unqueued--;
  8196. if ( !jQuery.queue( elem, "fx" ).length ) {
  8197. hooks.empty.fire();
  8198. }
  8199. });
  8200. });
  8201. }
  8202. // height/width overflow pass
  8203. if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
  8204. // Make sure that nothing sneaks out
  8205. // Record all 3 overflow attributes because IE9-10 do not
  8206. // change the overflow attribute when overflowX and
  8207. // overflowY are set to the same value
  8208. opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
  8209. // Set display property to inline-block for height/width
  8210. // animations on inline elements that are having width/height animated
  8211. display = jQuery.css( elem, "display" );
  8212. // Get default display if display is currently "none"
  8213. if ( display === "none" ) {
  8214. display = defaultDisplay( elem.nodeName );
  8215. }
  8216. if ( display === "inline" &&
  8217. jQuery.css( elem, "float" ) === "none" ) {
  8218. style.display = "inline-block";
  8219. }
  8220. }
  8221. if ( opts.overflow ) {
  8222. style.overflow = "hidden";
  8223. anim.always(function() {
  8224. style.overflow = opts.overflow[ 0 ];
  8225. style.overflowX = opts.overflow[ 1 ];
  8226. style.overflowY = opts.overflow[ 2 ];
  8227. });
  8228. }
  8229. // show/hide pass
  8230. for ( prop in props ) {
  8231. value = props[ prop ];
  8232. if ( rfxtypes.exec( value ) ) {
  8233. delete props[ prop ];
  8234. toggle = toggle || value === "toggle";
  8235. if ( value === ( hidden ? "hide" : "show" ) ) {
  8236. // If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
  8237. if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
  8238. hidden = true;
  8239. } else {
  8240. continue;
  8241. }
  8242. }
  8243. orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
  8244. }
  8245. }
  8246. if ( !jQuery.isEmptyObject( orig ) ) {
  8247. if ( dataShow ) {
  8248. if ( "hidden" in dataShow ) {
  8249. hidden = dataShow.hidden;
  8250. }
  8251. } else {
  8252. dataShow = data_priv.access( elem, "fxshow", {} );
  8253. }
  8254. // store state if its toggle - enables .stop().toggle() to "reverse"
  8255. if ( toggle ) {
  8256. dataShow.hidden = !hidden;
  8257. }
  8258. if ( hidden ) {
  8259. jQuery( elem ).show();
  8260. } else {
  8261. anim.done(function() {
  8262. jQuery( elem ).hide();
  8263. });
  8264. }
  8265. anim.done(function() {
  8266. var prop;
  8267. data_priv.remove( elem, "fxshow" );
  8268. for ( prop in orig ) {
  8269. jQuery.style( elem, prop, orig[ prop ] );
  8270. }
  8271. });
  8272. for ( prop in orig ) {
  8273. tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
  8274. if ( !( prop in dataShow ) ) {
  8275. dataShow[ prop ] = tween.start;
  8276. if ( hidden ) {
  8277. tween.end = tween.start;
  8278. tween.start = prop === "width" || prop === "height" ? 1 : 0;
  8279. }
  8280. }
  8281. }
  8282. }
  8283. }
  8284. function propFilter( props, specialEasing ) {
  8285. var index, name, easing, value, hooks;
  8286. // camelCase, specialEasing and expand cssHook pass
  8287. for ( index in props ) {
  8288. name = jQuery.camelCase( index );
  8289. easing = specialEasing[ name ];
  8290. value = props[ index ];
  8291. if ( jQuery.isArray( value ) ) {
  8292. easing = value[ 1 ];
  8293. value = props[ index ] = value[ 0 ];
  8294. }
  8295. if ( index !== name ) {
  8296. props[ name ] = value;
  8297. delete props[ index ];
  8298. }
  8299. hooks = jQuery.cssHooks[ name ];
  8300. if ( hooks && "expand" in hooks ) {
  8301. value = hooks.expand( value );
  8302. delete props[ name ];
  8303. // not quite $.extend, this wont overwrite keys already present.
  8304. // also - reusing 'index' from above because we have the correct "name"
  8305. for ( index in value ) {
  8306. if ( !( index in props ) ) {
  8307. props[ index ] = value[ index ];
  8308. specialEasing[ index ] = easing;
  8309. }
  8310. }
  8311. } else {
  8312. specialEasing[ name ] = easing;
  8313. }
  8314. }
  8315. }
  8316. function Animation( elem, properties, options ) {
  8317. var result,
  8318. stopped,
  8319. index = 0,
  8320. length = animationPrefilters.length,
  8321. deferred = jQuery.Deferred().always( function() {
  8322. // don't match elem in the :animated selector
  8323. delete tick.elem;
  8324. }),
  8325. tick = function() {
  8326. if ( stopped ) {
  8327. return false;
  8328. }
  8329. var currentTime = fxNow || createFxNow(),
  8330. remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
  8331. // archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497)
  8332. temp = remaining / animation.duration || 0,
  8333. percent = 1 - temp,
  8334. index = 0,
  8335. length = animation.tweens.length;
  8336. for ( ; index < length ; index++ ) {
  8337. animation.tweens[ index ].run( percent );
  8338. }
  8339. deferred.notifyWith( elem, [ animation, percent, remaining ]);
  8340. if ( percent < 1 && length ) {
  8341. return remaining;
  8342. } else {
  8343. deferred.resolveWith( elem, [ animation ] );
  8344. return false;
  8345. }
  8346. },
  8347. animation = deferred.promise({
  8348. elem: elem,
  8349. props: jQuery.extend( {}, properties ),
  8350. opts: jQuery.extend( true, { specialEasing: {} }, options ),
  8351. originalProperties: properties,
  8352. originalOptions: options,
  8353. startTime: fxNow || createFxNow(),
  8354. duration: options.duration,
  8355. tweens: [],
  8356. createTween: function( prop, end ) {
  8357. var tween = jQuery.Tween( elem, animation.opts, prop, end,
  8358. animation.opts.specialEasing[ prop ] || animation.opts.easing );
  8359. animation.tweens.push( tween );
  8360. return tween;
  8361. },
  8362. stop: function( gotoEnd ) {
  8363. var index = 0,
  8364. // if we are going to the end, we want to run all the tweens
  8365. // otherwise we skip this part
  8366. length = gotoEnd ? animation.tweens.length : 0;
  8367. if ( stopped ) {
  8368. return this;
  8369. }
  8370. stopped = true;
  8371. for ( ; index < length ; index++ ) {
  8372. animation.tweens[ index ].run( 1 );
  8373. }
  8374. // resolve when we played the last frame
  8375. // otherwise, reject
  8376. if ( gotoEnd ) {
  8377. deferred.resolveWith( elem, [ animation, gotoEnd ] );
  8378. } else {
  8379. deferred.rejectWith( elem, [ animation, gotoEnd ] );
  8380. }
  8381. return this;
  8382. }
  8383. }),
  8384. props = animation.props;
  8385. propFilter( props, animation.opts.specialEasing );
  8386. for ( ; index < length ; index++ ) {
  8387. result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
  8388. if ( result ) {
  8389. return result;
  8390. }
  8391. }
  8392. jQuery.map( props, createTween, animation );
  8393. if ( jQuery.isFunction( animation.opts.start ) ) {
  8394. animation.opts.start.call( elem, animation );
  8395. }
  8396. jQuery.fx.timer(
  8397. jQuery.extend( tick, {
  8398. elem: elem,
  8399. anim: animation,
  8400. queue: animation.opts.queue
  8401. })
  8402. );
  8403. // attach callbacks from options
  8404. return animation.progress( animation.opts.progress )
  8405. .done( animation.opts.done, animation.opts.complete )
  8406. .fail( animation.opts.fail )
  8407. .always( animation.opts.always );
  8408. }
  8409. jQuery.Animation = jQuery.extend( Animation, {
  8410. tweener: function( props, callback ) {
  8411. if ( jQuery.isFunction( props ) ) {
  8412. callback = props;
  8413. props = [ "*" ];
  8414. } else {
  8415. props = props.split(" ");
  8416. }
  8417. var prop,
  8418. index = 0,
  8419. length = props.length;
  8420. for ( ; index < length ; index++ ) {
  8421. prop = props[ index ];
  8422. tweeners[ prop ] = tweeners[ prop ] || [];
  8423. tweeners[ prop ].unshift( callback );
  8424. }
  8425. },
  8426. prefilter: function( callback, prepend ) {
  8427. if ( prepend ) {
  8428. animationPrefilters.unshift( callback );
  8429. } else {
  8430. animationPrefilters.push( callback );
  8431. }
  8432. }
  8433. });
  8434. jQuery.speed = function( speed, easing, fn ) {
  8435. var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
  8436. complete: fn || !fn && easing ||
  8437. jQuery.isFunction( speed ) && speed,
  8438. duration: speed,
  8439. easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
  8440. };
  8441. opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
  8442. opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
  8443. // normalize opt.queue - true/undefined/null -> "fx"
  8444. if ( opt.queue == null || opt.queue === true ) {
  8445. opt.queue = "fx";
  8446. }
  8447. // Queueing
  8448. opt.old = opt.complete;
  8449. opt.complete = function() {
  8450. if ( jQuery.isFunction( opt.old ) ) {
  8451. opt.old.call( this );
  8452. }
  8453. if ( opt.queue ) {
  8454. jQuery.dequeue( this, opt.queue );
  8455. }
  8456. };
  8457. return opt;
  8458. };
  8459. jQuery.fn.extend({
  8460. fadeTo: function( speed, to, easing, callback ) {
  8461. // show any hidden elements after setting opacity to 0
  8462. return this.filter( isHidden ).css( "opacity", 0 ).show()
  8463. // animate to the value specified
  8464. .end().animate({ opacity: to }, speed, easing, callback );
  8465. },
  8466. animate: function( prop, speed, easing, callback ) {
  8467. var empty = jQuery.isEmptyObject( prop ),
  8468. optall = jQuery.speed( speed, easing, callback ),
  8469. doAnimation = function() {
  8470. // Operate on a copy of prop so per-property easing won't be lost
  8471. var anim = Animation( this, jQuery.extend( {}, prop ), optall );
  8472. // Empty animations, or finishing resolves immediately
  8473. if ( empty || data_priv.get( this, "finish" ) ) {
  8474. anim.stop( true );
  8475. }
  8476. };
  8477. doAnimation.finish = doAnimation;
  8478. return empty || optall.queue === false ?
  8479. this.each( doAnimation ) :
  8480. this.queue( optall.queue, doAnimation );
  8481. },
  8482. stop: function( type, clearQueue, gotoEnd ) {
  8483. var stopQueue = function( hooks ) {
  8484. var stop = hooks.stop;
  8485. delete hooks.stop;
  8486. stop( gotoEnd );
  8487. };
  8488. if ( typeof type !== "string" ) {
  8489. gotoEnd = clearQueue;
  8490. clearQueue = type;
  8491. type = undefined;
  8492. }
  8493. if ( clearQueue && type !== false ) {
  8494. this.queue( type || "fx", [] );
  8495. }
  8496. return this.each(function() {
  8497. var dequeue = true,
  8498. index = type != null && type + "queueHooks",
  8499. timers = jQuery.timers,
  8500. data = data_priv.get( this );
  8501. if ( index ) {
  8502. if ( data[ index ] && data[ index ].stop ) {
  8503. stopQueue( data[ index ] );
  8504. }
  8505. } else {
  8506. for ( index in data ) {
  8507. if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
  8508. stopQueue( data[ index ] );
  8509. }
  8510. }
  8511. }
  8512. for ( index = timers.length; index--; ) {
  8513. if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
  8514. timers[ index ].anim.stop( gotoEnd );
  8515. dequeue = false;
  8516. timers.splice( index, 1 );
  8517. }
  8518. }
  8519. // start the next in the queue if the last step wasn't forced
  8520. // timers currently will call their complete callbacks, which will dequeue
  8521. // but only if they were gotoEnd
  8522. if ( dequeue || !gotoEnd ) {
  8523. jQuery.dequeue( this, type );
  8524. }
  8525. });
  8526. },
  8527. finish: function( type ) {
  8528. if ( type !== false ) {
  8529. type = type || "fx";
  8530. }
  8531. return this.each(function() {
  8532. var index,
  8533. data = data_priv.get( this ),
  8534. queue = data[ type + "queue" ],
  8535. hooks = data[ type + "queueHooks" ],
  8536. timers = jQuery.timers,
  8537. length = queue ? queue.length : 0;
  8538. // enable finishing flag on private data
  8539. data.finish = true;
  8540. // empty the queue first
  8541. jQuery.queue( this, type, [] );
  8542. if ( hooks && hooks.stop ) {
  8543. hooks.stop.call( this, true );
  8544. }
  8545. // look for any active animations, and finish them
  8546. for ( index = timers.length; index--; ) {
  8547. if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
  8548. timers[ index ].anim.stop( true );
  8549. timers.splice( index, 1 );
  8550. }
  8551. }
  8552. // look for any animations in the old queue and finish them
  8553. for ( index = 0; index < length; index++ ) {
  8554. if ( queue[ index ] && queue[ index ].finish ) {
  8555. queue[ index ].finish.call( this );
  8556. }
  8557. }
  8558. // turn off finishing flag
  8559. delete data.finish;
  8560. });
  8561. }
  8562. });
  8563. jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
  8564. var cssFn = jQuery.fn[ name ];
  8565. jQuery.fn[ name ] = function( speed, easing, callback ) {
  8566. return speed == null || typeof speed === "boolean" ?
  8567. cssFn.apply( this, arguments ) :
  8568. this.animate( genFx( name, true ), speed, easing, callback );
  8569. };
  8570. });
  8571. // Generate shortcuts for custom animations
  8572. jQuery.each({
  8573. slideDown: genFx("show"),
  8574. slideUp: genFx("hide"),
  8575. slideToggle: genFx("toggle"),
  8576. fadeIn: { opacity: "show" },
  8577. fadeOut: { opacity: "hide" },
  8578. fadeToggle: { opacity: "toggle" }
  8579. }, function( name, props ) {
  8580. jQuery.fn[ name ] = function( speed, easing, callback ) {
  8581. return this.animate( props, speed, easing, callback );
  8582. };
  8583. });
  8584. jQuery.timers = [];
  8585. jQuery.fx.tick = function() {
  8586. var timer,
  8587. i = 0,
  8588. timers = jQuery.timers;
  8589. fxNow = jQuery.now();
  8590. for ( ; i < timers.length; i++ ) {
  8591. timer = timers[ i ];
  8592. // Checks the timer has not already been removed
  8593. if ( !timer() && timers[ i ] === timer ) {
  8594. timers.splice( i--, 1 );
  8595. }
  8596. }
  8597. if ( !timers.length ) {
  8598. jQuery.fx.stop();
  8599. }
  8600. fxNow = undefined;
  8601. };
  8602. jQuery.fx.timer = function( timer ) {
  8603. jQuery.timers.push( timer );
  8604. if ( timer() ) {
  8605. jQuery.fx.start();
  8606. } else {
  8607. jQuery.timers.pop();
  8608. }
  8609. };
  8610. jQuery.fx.interval = 13;
  8611. jQuery.fx.start = function() {
  8612. if ( !timerId ) {
  8613. timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
  8614. }
  8615. };
  8616. jQuery.fx.stop = function() {
  8617. clearInterval( timerId );
  8618. timerId = null;
  8619. };
  8620. jQuery.fx.speeds = {
  8621. slow: 600,
  8622. fast: 200,
  8623. // Default speed
  8624. _default: 400
  8625. };
  8626. // Based off of the plugin by Clint Helfers, with permission.
  8627. // http://blindsignals.com/index.php/2009/07/jquery-delay/
  8628. jQuery.fn.delay = function( time, type ) {
  8629. time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
  8630. type = type || "fx";
  8631. return this.queue( type, function( next, hooks ) {
  8632. var timeout = setTimeout( next, time );
  8633. hooks.stop = function() {
  8634. clearTimeout( timeout );
  8635. };
  8636. });
  8637. };
  8638. (function() {
  8639. var input = document.createElement( "input" ),
  8640. select = document.createElement( "select" ),
  8641. opt = select.appendChild( document.createElement( "option" ) );
  8642. input.type = "checkbox";
  8643. // Support: iOS 5.1, Android 4.x, Android 2.3
  8644. // Check the default checkbox/radio value ("" on old WebKit; "on" elsewhere)
  8645. support.checkOn = input.value !== "";
  8646. // Must access the parent to make an option select properly
  8647. // Support: IE9, IE10
  8648. support.optSelected = opt.selected;
  8649. // Make sure that the options inside disabled selects aren't marked as disabled
  8650. // (WebKit marks them as disabled)
  8651. select.disabled = true;
  8652. support.optDisabled = !opt.disabled;
  8653. // Check if an input maintains its value after becoming a radio
  8654. // Support: IE9, IE10
  8655. input = document.createElement( "input" );
  8656. input.value = "t";
  8657. input.type = "radio";
  8658. support.radioValue = input.value === "t";
  8659. })();
  8660. var nodeHook, boolHook,
  8661. attrHandle = jQuery.expr.attrHandle;
  8662. jQuery.fn.extend({
  8663. attr: function( name, value ) {
  8664. return access( this, jQuery.attr, name, value, arguments.length > 1 );
  8665. },
  8666. removeAttr: function( name ) {
  8667. return this.each(function() {
  8668. jQuery.removeAttr( this, name );
  8669. });
  8670. }
  8671. });
  8672. jQuery.extend({
  8673. attr: function( elem, name, value ) {
  8674. var hooks, ret,
  8675. nType = elem.nodeType;
  8676. // don't get/set attributes on text, comment and attribute nodes
  8677. if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
  8678. return;
  8679. }
  8680. // Fallback to prop when attributes are not supported
  8681. if ( typeof elem.getAttribute === strundefined ) {
  8682. return jQuery.prop( elem, name, value );
  8683. }
  8684. // All attributes are lowercase
  8685. // Grab necessary hook if one is defined
  8686. if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
  8687. name = name.toLowerCase();
  8688. hooks = jQuery.attrHooks[ name ] ||
  8689. ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
  8690. }
  8691. if ( value !== undefined ) {
  8692. if ( value === null ) {
  8693. jQuery.removeAttr( elem, name );
  8694. } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
  8695. return ret;
  8696. } else {
  8697. elem.setAttribute( name, value + "" );
  8698. return value;
  8699. }
  8700. } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
  8701. return ret;
  8702. } else {
  8703. ret = jQuery.find.attr( elem, name );
  8704. // Non-existent attributes return null, we normalize to undefined
  8705. return ret == null ?
  8706. undefined :
  8707. ret;
  8708. }
  8709. },
  8710. removeAttr: function( elem, value ) {
  8711. var name, propName,
  8712. i = 0,
  8713. attrNames = value && value.match( rnotwhite );
  8714. if ( attrNames && elem.nodeType === 1 ) {
  8715. while ( (name = attrNames[i++]) ) {
  8716. propName = jQuery.propFix[ name ] || name;
  8717. // Boolean attributes get special treatment (#10870)
  8718. if ( jQuery.expr.match.bool.test( name ) ) {
  8719. // Set corresponding property to false
  8720. elem[ propName ] = false;
  8721. }
  8722. elem.removeAttribute( name );
  8723. }
  8724. }
  8725. },
  8726. attrHooks: {
  8727. type: {
  8728. set: function( elem, value ) {
  8729. if ( !support.radioValue && value === "radio" &&
  8730. jQuery.nodeName( elem, "input" ) ) {
  8731. // Setting the type on a radio button after the value resets the value in IE6-9
  8732. // Reset value to default in case type is set after value during creation
  8733. var val = elem.value;
  8734. elem.setAttribute( "type", value );
  8735. if ( val ) {
  8736. elem.value = val;
  8737. }
  8738. return value;
  8739. }
  8740. }
  8741. }
  8742. }
  8743. });
  8744. // Hooks for boolean attributes
  8745. boolHook = {
  8746. set: function( elem, value, name ) {
  8747. if ( value === false ) {
  8748. // Remove boolean attributes when set to false
  8749. jQuery.removeAttr( elem, name );
  8750. } else {
  8751. elem.setAttribute( name, name );
  8752. }
  8753. return name;
  8754. }
  8755. };
  8756. jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
  8757. var getter = attrHandle[ name ] || jQuery.find.attr;
  8758. attrHandle[ name ] = function( elem, name, isXML ) {
  8759. var ret, handle;
  8760. if ( !isXML ) {
  8761. // Avoid an infinite loop by temporarily removing this function from the getter
  8762. handle = attrHandle[ name ];
  8763. attrHandle[ name ] = ret;
  8764. ret = getter( elem, name, isXML ) != null ?
  8765. name.toLowerCase() :
  8766. null;
  8767. attrHandle[ name ] = handle;
  8768. }
  8769. return ret;
  8770. };
  8771. });
  8772. var rfocusable = /^(?:input|select|textarea|button)$/i;
  8773. jQuery.fn.extend({
  8774. prop: function( name, value ) {
  8775. return access( this, jQuery.prop, name, value, arguments.length > 1 );
  8776. },
  8777. removeProp: function( name ) {
  8778. return this.each(function() {
  8779. delete this[ jQuery.propFix[ name ] || name ];
  8780. });
  8781. }
  8782. });
  8783. jQuery.extend({
  8784. propFix: {
  8785. "for": "htmlFor",
  8786. "class": "className"
  8787. },
  8788. prop: function( elem, name, value ) {
  8789. var ret, hooks, notxml,
  8790. nType = elem.nodeType;
  8791. // don't get/set properties on text, comment and attribute nodes
  8792. if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
  8793. return;
  8794. }
  8795. notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
  8796. if ( notxml ) {
  8797. // Fix name and attach hooks
  8798. name = jQuery.propFix[ name ] || name;
  8799. hooks = jQuery.propHooks[ name ];
  8800. }
  8801. if ( value !== undefined ) {
  8802. return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
  8803. ret :
  8804. ( elem[ name ] = value );
  8805. } else {
  8806. return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
  8807. ret :
  8808. elem[ name ];
  8809. }
  8810. },
  8811. propHooks: {
  8812. tabIndex: {
  8813. get: function( elem ) {
  8814. return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
  8815. elem.tabIndex :
  8816. -1;
  8817. }
  8818. }
  8819. }
  8820. });
  8821. // Support: IE9+
  8822. // Selectedness for an option in an optgroup can be inaccurate
  8823. if ( !support.optSelected ) {
  8824. jQuery.propHooks.selected = {
  8825. get: function( elem ) {
  8826. var parent = elem.parentNode;
  8827. if ( parent && parent.parentNode ) {
  8828. parent.parentNode.selectedIndex;
  8829. }
  8830. return null;
  8831. }
  8832. };
  8833. }
  8834. jQuery.each([
  8835. "tabIndex",
  8836. "readOnly",
  8837. "maxLength",
  8838. "cellSpacing",
  8839. "cellPadding",
  8840. "rowSpan",
  8841. "colSpan",
  8842. "useMap",
  8843. "frameBorder",
  8844. "contentEditable"
  8845. ], function() {
  8846. jQuery.propFix[ this.toLowerCase() ] = this;
  8847. });
  8848. var rclass = /[\t\r\n\f]/g;
  8849. jQuery.fn.extend({
  8850. addClass: function( value ) {
  8851. var classes, elem, cur, clazz, j, finalValue,
  8852. proceed = typeof value === "string" && value,
  8853. i = 0,
  8854. len = this.length;
  8855. if ( jQuery.isFunction( value ) ) {
  8856. return this.each(function( j ) {
  8857. jQuery( this ).addClass( value.call( this, j, this.className ) );
  8858. });
  8859. }
  8860. if ( proceed ) {
  8861. // The disjunction here is for better compressibility (see removeClass)
  8862. classes = ( value || "" ).match( rnotwhite ) || [];
  8863. for ( ; i < len; i++ ) {
  8864. elem = this[ i ];
  8865. cur = elem.nodeType === 1 && ( elem.className ?
  8866. ( " " + elem.className + " " ).replace( rclass, " " ) :
  8867. " "
  8868. );
  8869. if ( cur ) {
  8870. j = 0;
  8871. while ( (clazz = classes[j++]) ) {
  8872. if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
  8873. cur += clazz + " ";
  8874. }
  8875. }
  8876. // only assign if different to avoid unneeded rendering.
  8877. finalValue = jQuery.trim( cur );
  8878. if ( elem.className !== finalValue ) {
  8879. elem.className = finalValue;
  8880. }
  8881. }
  8882. }
  8883. }
  8884. return this;
  8885. },
  8886. removeClass: function( value ) {
  8887. var classes, elem, cur, clazz, j, finalValue,
  8888. proceed = arguments.length === 0 || typeof value === "string" && value,
  8889. i = 0,
  8890. len = this.length;
  8891. if ( jQuery.isFunction( value ) ) {
  8892. return this.each(function( j ) {
  8893. jQuery( this ).removeClass( value.call( this, j, this.className ) );
  8894. });
  8895. }
  8896. if ( proceed ) {
  8897. classes = ( value || "" ).match( rnotwhite ) || [];
  8898. for ( ; i < len; i++ ) {
  8899. elem = this[ i ];
  8900. // This expression is here for better compressibility (see addClass)
  8901. cur = elem.nodeType === 1 && ( elem.className ?
  8902. ( " " + elem.className + " " ).replace( rclass, " " ) :
  8903. ""
  8904. );
  8905. if ( cur ) {
  8906. j = 0;
  8907. while ( (clazz = classes[j++]) ) {
  8908. // Remove *all* instances
  8909. while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
  8910. cur = cur.replace( " " + clazz + " ", " " );
  8911. }
  8912. }
  8913. // only assign if different to avoid unneeded rendering.
  8914. finalValue = value ? jQuery.trim( cur ) : "";
  8915. if ( elem.className !== finalValue ) {
  8916. elem.className = finalValue;
  8917. }
  8918. }
  8919. }
  8920. }
  8921. return this;
  8922. },
  8923. toggleClass: function( value, stateVal ) {
  8924. var type = typeof value;
  8925. if ( typeof stateVal === "boolean" && type === "string" ) {
  8926. return stateVal ? this.addClass( value ) : this.removeClass( value );
  8927. }
  8928. if ( jQuery.isFunction( value ) ) {
  8929. return this.each(function( i ) {
  8930. jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
  8931. });
  8932. }
  8933. return this.each(function() {
  8934. if ( type === "string" ) {
  8935. // toggle individual class names
  8936. var className,
  8937. i = 0,
  8938. self = jQuery( this ),
  8939. classNames = value.match( rnotwhite ) || [];
  8940. while ( (className = classNames[ i++ ]) ) {
  8941. // check each className given, space separated list
  8942. if ( self.hasClass( className ) ) {
  8943. self.removeClass( className );
  8944. } else {
  8945. self.addClass( className );
  8946. }
  8947. }
  8948. // Toggle whole class name
  8949. } else if ( type === strundefined || type === "boolean" ) {
  8950. if ( this.className ) {
  8951. // store className if set
  8952. data_priv.set( this, "__className__", this.className );
  8953. }
  8954. // If the element has a class name or if we're passed "false",
  8955. // then remove the whole classname (if there was one, the above saved it).
  8956. // Otherwise bring back whatever was previously saved (if anything),
  8957. // falling back to the empty string if nothing was stored.
  8958. this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
  8959. }
  8960. });
  8961. },
  8962. hasClass: function( selector ) {
  8963. var className = " " + selector + " ",
  8964. i = 0,
  8965. l = this.length;
  8966. for ( ; i < l; i++ ) {
  8967. if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
  8968. return true;
  8969. }
  8970. }
  8971. return false;
  8972. }
  8973. });
  8974. var rreturn = /\r/g;
  8975. jQuery.fn.extend({
  8976. val: function( value ) {
  8977. var hooks, ret, isFunction,
  8978. elem = this[0];
  8979. if ( !arguments.length ) {
  8980. if ( elem ) {
  8981. hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
  8982. if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
  8983. return ret;
  8984. }
  8985. ret = elem.value;
  8986. return typeof ret === "string" ?
  8987. // handle most common string cases
  8988. ret.replace(rreturn, "") :
  8989. // handle cases where value is null/undef or number
  8990. ret == null ? "" : ret;
  8991. }
  8992. return;
  8993. }
  8994. isFunction = jQuery.isFunction( value );
  8995. return this.each(function( i ) {
  8996. var val;
  8997. if ( this.nodeType !== 1 ) {
  8998. return;
  8999. }
  9000. if ( isFunction ) {
  9001. val = value.call( this, i, jQuery( this ).val() );
  9002. } else {
  9003. val = value;
  9004. }
  9005. // Treat null/undefined as ""; convert numbers to string
  9006. if ( val == null ) {
  9007. val = "";
  9008. } else if ( typeof val === "number" ) {
  9009. val += "";
  9010. } else if ( jQuery.isArray( val ) ) {
  9011. val = jQuery.map( val, function( value ) {
  9012. return value == null ? "" : value + "";
  9013. });
  9014. }
  9015. hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
  9016. // If set returns undefined, fall back to normal setting
  9017. if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
  9018. this.value = val;
  9019. }
  9020. });
  9021. }
  9022. });
  9023. jQuery.extend({
  9024. valHooks: {
  9025. select: {
  9026. get: function( elem ) {
  9027. var value, option,
  9028. options = elem.options,
  9029. index = elem.selectedIndex,
  9030. one = elem.type === "select-one" || index < 0,
  9031. values = one ? null : [],
  9032. max = one ? index + 1 : options.length,
  9033. i = index < 0 ?
  9034. max :
  9035. one ? index : 0;
  9036. // Loop through all the selected options
  9037. for ( ; i < max; i++ ) {
  9038. option = options[ i ];
  9039. // IE6-9 doesn't update selected after form reset (#2551)
  9040. if ( ( option.selected || i === index ) &&
  9041. // Don't return options that are disabled or in a disabled optgroup
  9042. ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
  9043. ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
  9044. // Get the specific value for the option
  9045. value = jQuery( option ).val();
  9046. // We don't need an array for one selects
  9047. if ( one ) {
  9048. return value;
  9049. }
  9050. // Multi-Selects return an array
  9051. values.push( value );
  9052. }
  9053. }
  9054. return values;
  9055. },
  9056. set: function( elem, value ) {
  9057. var optionSet, option,
  9058. options = elem.options,
  9059. values = jQuery.makeArray( value ),
  9060. i = options.length;
  9061. while ( i-- ) {
  9062. option = options[ i ];
  9063. if ( (option.selected = jQuery.inArray( jQuery(option).val(), values ) >= 0) ) {
  9064. optionSet = true;
  9065. }
  9066. }
  9067. // force browsers to behave consistently when non-matching value is set
  9068. if ( !optionSet ) {
  9069. elem.selectedIndex = -1;
  9070. }
  9071. return values;
  9072. }
  9073. }
  9074. }
  9075. });
  9076. // Radios and checkboxes getter/setter
  9077. jQuery.each([ "radio", "checkbox" ], function() {
  9078. jQuery.valHooks[ this ] = {
  9079. set: function( elem, value ) {
  9080. if ( jQuery.isArray( value ) ) {
  9081. return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
  9082. }
  9083. }
  9084. };
  9085. if ( !support.checkOn ) {
  9086. jQuery.valHooks[ this ].get = function( elem ) {
  9087. // Support: Webkit
  9088. // "" is returned instead of "on" if a value isn't specified
  9089. return elem.getAttribute("value") === null ? "on" : elem.value;
  9090. };
  9091. }
  9092. });
  9093. // Return jQuery for attributes-only inclusion
  9094. jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
  9095. "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
  9096. "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
  9097. // Handle event binding
  9098. jQuery.fn[ name ] = function( data, fn ) {
  9099. return arguments.length > 0 ?
  9100. this.on( name, null, data, fn ) :
  9101. this.trigger( name );
  9102. };
  9103. });
  9104. jQuery.fn.extend({
  9105. hover: function( fnOver, fnOut ) {
  9106. return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
  9107. },
  9108. bind: function( types, data, fn ) {
  9109. return this.on( types, null, data, fn );
  9110. },
  9111. unbind: function( types, fn ) {
  9112. return this.off( types, null, fn );
  9113. },
  9114. delegate: function( selector, types, data, fn ) {
  9115. return this.on( types, selector, data, fn );
  9116. },
  9117. undelegate: function( selector, types, fn ) {
  9118. // ( namespace ) or ( selector, types [, fn] )
  9119. return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
  9120. }
  9121. });
  9122. var nonce = jQuery.now();
  9123. var rquery = (/\?/);
  9124. // Support: Android 2.3
  9125. // Workaround failure to string-cast null input
  9126. jQuery.parseJSON = function( data ) {
  9127. return JSON.parse( data + "" );
  9128. };
  9129. // Cross-browser xml parsing
  9130. jQuery.parseXML = function( data ) {
  9131. var xml, tmp;
  9132. if ( !data || typeof data !== "string" ) {
  9133. return null;
  9134. }
  9135. // Support: IE9
  9136. try {
  9137. tmp = new DOMParser();
  9138. xml = tmp.parseFromString( data, "text/xml" );
  9139. } catch ( e ) {
  9140. xml = undefined;
  9141. }
  9142. if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
  9143. jQuery.error( "Invalid XML: " + data );
  9144. }
  9145. return xml;
  9146. };
  9147. var
  9148. // Document location
  9149. ajaxLocParts,
  9150. ajaxLocation,
  9151. rhash = /#.*$/,
  9152. rts = /([?&])_=[^&]*/,
  9153. rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
  9154. // #7653, #8125, #8152: local protocol detection
  9155. rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
  9156. rnoContent = /^(?:GET|HEAD)$/,
  9157. rprotocol = /^\/\//,
  9158. rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
  9159. /* Prefilters
  9160. * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
  9161. * 2) These are called:
  9162. * - BEFORE asking for a transport
  9163. * - AFTER param serialization (s.data is a string if s.processData is true)
  9164. * 3) key is the dataType
  9165. * 4) the catchall symbol "*" can be used
  9166. * 5) execution will start with transport dataType and THEN continue down to "*" if needed
  9167. */
  9168. prefilters = {},
  9169. /* Transports bindings
  9170. * 1) key is the dataType
  9171. * 2) the catchall symbol "*" can be used
  9172. * 3) selection will start with transport dataType and THEN go to "*" if needed
  9173. */
  9174. transports = {},
  9175. // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
  9176. allTypes = "*/".concat("*");
  9177. // #8138, IE may throw an exception when accessing
  9178. // a field from window.location if document.domain has been set
  9179. try {
  9180. ajaxLocation = location.href;
  9181. } catch( e ) {
  9182. // Use the href attribute of an A element
  9183. // since IE will modify it given document.location
  9184. ajaxLocation = document.createElement( "a" );
  9185. ajaxLocation.href = "";
  9186. ajaxLocation = ajaxLocation.href;
  9187. }
  9188. // Segment location into parts
  9189. ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
  9190. // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
  9191. function addToPrefiltersOrTransports( structure ) {
  9192. // dataTypeExpression is optional and defaults to "*"
  9193. return function( dataTypeExpression, func ) {
  9194. if ( typeof dataTypeExpression !== "string" ) {
  9195. func = dataTypeExpression;
  9196. dataTypeExpression = "*";
  9197. }
  9198. var dataType,
  9199. i = 0,
  9200. dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
  9201. if ( jQuery.isFunction( func ) ) {
  9202. // For each dataType in the dataTypeExpression
  9203. while ( (dataType = dataTypes[i++]) ) {
  9204. // Prepend if requested
  9205. if ( dataType[0] === "+" ) {
  9206. dataType = dataType.slice( 1 ) || "*";
  9207. (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
  9208. // Otherwise append
  9209. } else {
  9210. (structure[ dataType ] = structure[ dataType ] || []).push( func );
  9211. }
  9212. }
  9213. }
  9214. };
  9215. }
  9216. // Base inspection function for prefilters and transports
  9217. function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
  9218. var inspected = {},
  9219. seekingTransport = ( structure === transports );
  9220. function inspect( dataType ) {
  9221. var selected;
  9222. inspected[ dataType ] = true;
  9223. jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
  9224. var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
  9225. if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
  9226. options.dataTypes.unshift( dataTypeOrTransport );
  9227. inspect( dataTypeOrTransport );
  9228. return false;
  9229. } else if ( seekingTransport ) {
  9230. return !( selected = dataTypeOrTransport );
  9231. }
  9232. });
  9233. return selected;
  9234. }
  9235. return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
  9236. }
  9237. // A special extend for ajax options
  9238. // that takes "flat" options (not to be deep extended)
  9239. // Fixes #9887
  9240. function ajaxExtend( target, src ) {
  9241. var key, deep,
  9242. flatOptions = jQuery.ajaxSettings.flatOptions || {};
  9243. for ( key in src ) {
  9244. if ( src[ key ] !== undefined ) {
  9245. ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
  9246. }
  9247. }
  9248. if ( deep ) {
  9249. jQuery.extend( true, target, deep );
  9250. }
  9251. return target;
  9252. }
  9253. /* Handles responses to an ajax request:
  9254. * - finds the right dataType (mediates between content-type and expected dataType)
  9255. * - returns the corresponding response
  9256. */
  9257. function ajaxHandleResponses( s, jqXHR, responses ) {
  9258. var ct, type, finalDataType, firstDataType,
  9259. contents = s.contents,
  9260. dataTypes = s.dataTypes;
  9261. // Remove auto dataType and get content-type in the process
  9262. while ( dataTypes[ 0 ] === "*" ) {
  9263. dataTypes.shift();
  9264. if ( ct === undefined ) {
  9265. ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
  9266. }
  9267. }
  9268. // Check if we're dealing with a known content-type
  9269. if ( ct ) {
  9270. for ( type in contents ) {
  9271. if ( contents[ type ] && contents[ type ].test( ct ) ) {
  9272. dataTypes.unshift( type );
  9273. break;
  9274. }
  9275. }
  9276. }
  9277. // Check to see if we have a response for the expected dataType
  9278. if ( dataTypes[ 0 ] in responses ) {
  9279. finalDataType = dataTypes[ 0 ];
  9280. } else {
  9281. // Try convertible dataTypes
  9282. for ( type in responses ) {
  9283. if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
  9284. finalDataType = type;
  9285. break;
  9286. }
  9287. if ( !firstDataType ) {
  9288. firstDataType = type;
  9289. }
  9290. }
  9291. // Or just use first one
  9292. finalDataType = finalDataType || firstDataType;
  9293. }
  9294. // If we found a dataType
  9295. // We add the dataType to the list if needed
  9296. // and return the corresponding response
  9297. if ( finalDataType ) {
  9298. if ( finalDataType !== dataTypes[ 0 ] ) {
  9299. dataTypes.unshift( finalDataType );
  9300. }
  9301. return responses[ finalDataType ];
  9302. }
  9303. }
  9304. /* Chain conversions given the request and the original response
  9305. * Also sets the responseXXX fields on the jqXHR instance
  9306. */
  9307. function ajaxConvert( s, response, jqXHR, isSuccess ) {
  9308. var conv2, current, conv, tmp, prev,
  9309. converters = {},
  9310. // Work with a copy of dataTypes in case we need to modify it for conversion
  9311. dataTypes = s.dataTypes.slice();
  9312. // Create converters map with lowercased keys
  9313. if ( dataTypes[ 1 ] ) {
  9314. for ( conv in s.converters ) {
  9315. converters[ conv.toLowerCase() ] = s.converters[ conv ];
  9316. }
  9317. }
  9318. current = dataTypes.shift();
  9319. // Convert to each sequential dataType
  9320. while ( current ) {
  9321. if ( s.responseFields[ current ] ) {
  9322. jqXHR[ s.responseFields[ current ] ] = response;
  9323. }
  9324. // Apply the dataFilter if provided
  9325. if ( !prev && isSuccess && s.dataFilter ) {
  9326. response = s.dataFilter( response, s.dataType );
  9327. }
  9328. prev = current;
  9329. current = dataTypes.shift();
  9330. if ( current ) {
  9331. // There's only work to do if current dataType is non-auto
  9332. if ( current === "*" ) {
  9333. current = prev;
  9334. // Convert response if prev dataType is non-auto and differs from current
  9335. } else if ( prev !== "*" && prev !== current ) {
  9336. // Seek a direct converter
  9337. conv = converters[ prev + " " + current ] || converters[ "* " + current ];
  9338. // If none found, seek a pair
  9339. if ( !conv ) {
  9340. for ( conv2 in converters ) {
  9341. // If conv2 outputs current
  9342. tmp = conv2.split( " " );
  9343. if ( tmp[ 1 ] === current ) {
  9344. // If prev can be converted to accepted input
  9345. conv = converters[ prev + " " + tmp[ 0 ] ] ||
  9346. converters[ "* " + tmp[ 0 ] ];
  9347. if ( conv ) {
  9348. // Condense equivalence converters
  9349. if ( conv === true ) {
  9350. conv = converters[ conv2 ];
  9351. // Otherwise, insert the intermediate dataType
  9352. } else if ( converters[ conv2 ] !== true ) {
  9353. current = tmp[ 0 ];
  9354. dataTypes.unshift( tmp[ 1 ] );
  9355. }
  9356. break;
  9357. }
  9358. }
  9359. }
  9360. }
  9361. // Apply converter (if not an equivalence)
  9362. if ( conv !== true ) {
  9363. // Unless errors are allowed to bubble, catch and return them
  9364. if ( conv && s[ "throws" ] ) {
  9365. response = conv( response );
  9366. } else {
  9367. try {
  9368. response = conv( response );
  9369. } catch ( e ) {
  9370. return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
  9371. }
  9372. }
  9373. }
  9374. }
  9375. }
  9376. }
  9377. return { state: "success", data: response };
  9378. }
  9379. jQuery.extend({
  9380. // Counter for holding the number of active queries
  9381. active: 0,
  9382. // Last-Modified header cache for next request
  9383. lastModified: {},
  9384. etag: {},
  9385. ajaxSettings: {
  9386. url: ajaxLocation,
  9387. type: "GET",
  9388. isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
  9389. global: true,
  9390. processData: true,
  9391. async: true,
  9392. contentType: "application/x-www-form-urlencoded; charset=UTF-8",
  9393. /*
  9394. timeout: 0,
  9395. data: null,
  9396. dataType: null,
  9397. username: null,
  9398. password: null,
  9399. cache: null,
  9400. throws: false,
  9401. traditional: false,
  9402. headers: {},
  9403. */
  9404. accepts: {
  9405. "*": allTypes,
  9406. text: "text/plain",
  9407. html: "text/html",
  9408. xml: "application/xml, text/xml",
  9409. json: "application/json, text/javascript"
  9410. },
  9411. contents: {
  9412. xml: /xml/,
  9413. html: /html/,
  9414. json: /json/
  9415. },
  9416. responseFields: {
  9417. xml: "responseXML",
  9418. text: "responseText",
  9419. json: "responseJSON"
  9420. },
  9421. // Data converters
  9422. // Keys separate source (or catchall "*") and destination types with a single space
  9423. converters: {
  9424. // Convert anything to text
  9425. "* text": String,
  9426. // Text to html (true = no transformation)
  9427. "text html": true,
  9428. // Evaluate text as a json expression
  9429. "text json": jQuery.parseJSON,
  9430. // Parse text as xml
  9431. "text xml": jQuery.parseXML
  9432. },
  9433. // For options that shouldn't be deep extended:
  9434. // you can add your own custom options here if
  9435. // and when you create one that shouldn't be
  9436. // deep extended (see ajaxExtend)
  9437. flatOptions: {
  9438. url: true,
  9439. context: true
  9440. }
  9441. },
  9442. // Creates a full fledged settings object into target
  9443. // with both ajaxSettings and settings fields.
  9444. // If target is omitted, writes into ajaxSettings.
  9445. ajaxSetup: function( target, settings ) {
  9446. return settings ?
  9447. // Building a settings object
  9448. ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
  9449. // Extending ajaxSettings
  9450. ajaxExtend( jQuery.ajaxSettings, target );
  9451. },
  9452. ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
  9453. ajaxTransport: addToPrefiltersOrTransports( transports ),
  9454. // Main method
  9455. ajax: function( url, options ) {
  9456. // If url is an object, simulate pre-1.5 signature
  9457. if ( typeof url === "object" ) {
  9458. options = url;
  9459. url = undefined;
  9460. }
  9461. // Force options to be an object
  9462. options = options || {};
  9463. var transport,
  9464. // URL without anti-cache param
  9465. cacheURL,
  9466. // Response headers
  9467. responseHeadersString,
  9468. responseHeaders,
  9469. // timeout handle
  9470. timeoutTimer,
  9471. // Cross-domain detection vars
  9472. parts,
  9473. // To know if global events are to be dispatched
  9474. fireGlobals,
  9475. // Loop variable
  9476. i,
  9477. // Create the final options object
  9478. s = jQuery.ajaxSetup( {}, options ),
  9479. // Callbacks context
  9480. callbackContext = s.context || s,
  9481. // Context for global events is callbackContext if it is a DOM node or jQuery collection
  9482. globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
  9483. jQuery( callbackContext ) :
  9484. jQuery.event,
  9485. // Deferreds
  9486. deferred = jQuery.Deferred(),
  9487. completeDeferred = jQuery.Callbacks("once memory"),
  9488. // Status-dependent callbacks
  9489. statusCode = s.statusCode || {},
  9490. // Headers (they are sent all at once)
  9491. requestHeaders = {},
  9492. requestHeadersNames = {},
  9493. // The jqXHR state
  9494. state = 0,
  9495. // Default abort message
  9496. strAbort = "canceled",
  9497. // Fake xhr
  9498. jqXHR = {
  9499. readyState: 0,
  9500. // Builds headers hashtable if needed
  9501. getResponseHeader: function( key ) {
  9502. var match;
  9503. if ( state === 2 ) {
  9504. if ( !responseHeaders ) {
  9505. responseHeaders = {};
  9506. while ( (match = rheaders.exec( responseHeadersString )) ) {
  9507. responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
  9508. }
  9509. }
  9510. match = responseHeaders[ key.toLowerCase() ];
  9511. }
  9512. return match == null ? null : match;
  9513. },
  9514. // Raw string
  9515. getAllResponseHeaders: function() {
  9516. return state === 2 ? responseHeadersString : null;
  9517. },
  9518. // Caches the header
  9519. setRequestHeader: function( name, value ) {
  9520. var lname = name.toLowerCase();
  9521. if ( !state ) {
  9522. name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
  9523. requestHeaders[ name ] = value;
  9524. }
  9525. return this;
  9526. },
  9527. // Overrides response content-type header
  9528. overrideMimeType: function( type ) {
  9529. if ( !state ) {
  9530. s.mimeType = type;
  9531. }
  9532. return this;
  9533. },
  9534. // Status-dependent callbacks
  9535. statusCode: function( map ) {
  9536. var code;
  9537. if ( map ) {
  9538. if ( state < 2 ) {
  9539. for ( code in map ) {
  9540. // Lazy-add the new callback in a way that preserves old ones
  9541. statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
  9542. }
  9543. } else {
  9544. // Execute the appropriate callbacks
  9545. jqXHR.always( map[ jqXHR.status ] );
  9546. }
  9547. }
  9548. return this;
  9549. },
  9550. // Cancel the request
  9551. abort: function( statusText ) {
  9552. var finalText = statusText || strAbort;
  9553. if ( transport ) {
  9554. transport.abort( finalText );
  9555. }
  9556. done( 0, finalText );
  9557. return this;
  9558. }
  9559. };
  9560. // Attach deferreds
  9561. deferred.promise( jqXHR ).complete = completeDeferred.add;
  9562. jqXHR.success = jqXHR.done;
  9563. jqXHR.error = jqXHR.fail;
  9564. // Remove hash character (#7531: and string promotion)
  9565. // Add protocol if not provided (prefilters might expect it)
  9566. // Handle falsy url in the settings object (#10093: consistency with old signature)
  9567. // We also use the url parameter if available
  9568. s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
  9569. .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
  9570. // Alias method option to type as per ticket #12004
  9571. s.type = options.method || options.type || s.method || s.type;
  9572. // Extract dataTypes list
  9573. s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
  9574. // A cross-domain request is in order when we have a protocol:host:port mismatch
  9575. if ( s.crossDomain == null ) {
  9576. parts = rurl.exec( s.url.toLowerCase() );
  9577. s.crossDomain = !!( parts &&
  9578. ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
  9579. ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
  9580. ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
  9581. );
  9582. }
  9583. // Convert data if not already a string
  9584. if ( s.data && s.processData && typeof s.data !== "string" ) {
  9585. s.data = jQuery.param( s.data, s.traditional );
  9586. }
  9587. // Apply prefilters
  9588. inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
  9589. // If request was aborted inside a prefilter, stop there
  9590. if ( state === 2 ) {
  9591. return jqXHR;
  9592. }
  9593. // We can fire global events as of now if asked to
  9594. fireGlobals = s.global;
  9595. // Watch for a new set of requests
  9596. if ( fireGlobals && jQuery.active++ === 0 ) {
  9597. jQuery.event.trigger("ajaxStart");
  9598. }
  9599. // Uppercase the type
  9600. s.type = s.type.toUpperCase();
  9601. // Determine if request has content
  9602. s.hasContent = !rnoContent.test( s.type );
  9603. // Save the URL in case we're toying with the If-Modified-Since
  9604. // and/or If-None-Match header later on
  9605. cacheURL = s.url;
  9606. // More options handling for requests with no content
  9607. if ( !s.hasContent ) {
  9608. // If data is available, append data to url
  9609. if ( s.data ) {
  9610. cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
  9611. // #9682: remove data so that it's not used in an eventual retry
  9612. delete s.data;
  9613. }
  9614. // Add anti-cache in url if needed
  9615. if ( s.cache === false ) {
  9616. s.url = rts.test( cacheURL ) ?
  9617. // If there is already a '_' parameter, set its value
  9618. cacheURL.replace( rts, "$1_=" + nonce++ ) :
  9619. // Otherwise add one to the end
  9620. cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
  9621. }
  9622. }
  9623. // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  9624. if ( s.ifModified ) {
  9625. if ( jQuery.lastModified[ cacheURL ] ) {
  9626. jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
  9627. }
  9628. if ( jQuery.etag[ cacheURL ] ) {
  9629. jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
  9630. }
  9631. }
  9632. // Set the correct header, if data is being sent
  9633. if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
  9634. jqXHR.setRequestHeader( "Content-Type", s.contentType );
  9635. }
  9636. // Set the Accepts header for the server, depending on the dataType
  9637. jqXHR.setRequestHeader(
  9638. "Accept",
  9639. s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
  9640. s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
  9641. s.accepts[ "*" ]
  9642. );
  9643. // Check for headers option
  9644. for ( i in s.headers ) {
  9645. jqXHR.setRequestHeader( i, s.headers[ i ] );
  9646. }
  9647. // Allow custom headers/mimetypes and early abort
  9648. if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
  9649. // Abort if not done already and return
  9650. return jqXHR.abort();
  9651. }
  9652. // aborting is no longer a cancellation
  9653. strAbort = "abort";
  9654. // Install callbacks on deferreds
  9655. for ( i in { success: 1, error: 1, complete: 1 } ) {
  9656. jqXHR[ i ]( s[ i ] );
  9657. }
  9658. // Get transport
  9659. transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
  9660. // If no transport, we auto-abort
  9661. if ( !transport ) {
  9662. done( -1, "No Transport" );
  9663. } else {
  9664. jqXHR.readyState = 1;
  9665. // Send global event
  9666. if ( fireGlobals ) {
  9667. globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
  9668. }
  9669. // Timeout
  9670. if ( s.async && s.timeout > 0 ) {
  9671. timeoutTimer = setTimeout(function() {
  9672. jqXHR.abort("timeout");
  9673. }, s.timeout );
  9674. }
  9675. try {
  9676. state = 1;
  9677. transport.send( requestHeaders, done );
  9678. } catch ( e ) {
  9679. // Propagate exception as error if not done
  9680. if ( state < 2 ) {
  9681. done( -1, e );
  9682. // Simply rethrow otherwise
  9683. } else {
  9684. throw e;
  9685. }
  9686. }
  9687. }
  9688. // Callback for when everything is done
  9689. function done( status, nativeStatusText, responses, headers ) {
  9690. var isSuccess, success, error, response, modified,
  9691. statusText = nativeStatusText;
  9692. // Called once
  9693. if ( state === 2 ) {
  9694. return;
  9695. }
  9696. // State is "done" now
  9697. state = 2;
  9698. // Clear timeout if it exists
  9699. if ( timeoutTimer ) {
  9700. clearTimeout( timeoutTimer );
  9701. }
  9702. // Dereference transport for early garbage collection
  9703. // (no matter how long the jqXHR object will be used)
  9704. transport = undefined;
  9705. // Cache response headers
  9706. responseHeadersString = headers || "";
  9707. // Set readyState
  9708. jqXHR.readyState = status > 0 ? 4 : 0;
  9709. // Determine if successful
  9710. isSuccess = status >= 200 && status < 300 || status === 304;
  9711. // Get response data
  9712. if ( responses ) {
  9713. response = ajaxHandleResponses( s, jqXHR, responses );
  9714. }
  9715. // Convert no matter what (that way responseXXX fields are always set)
  9716. response = ajaxConvert( s, response, jqXHR, isSuccess );
  9717. // If successful, handle type chaining
  9718. if ( isSuccess ) {
  9719. // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  9720. if ( s.ifModified ) {
  9721. modified = jqXHR.getResponseHeader("Last-Modified");
  9722. if ( modified ) {
  9723. jQuery.lastModified[ cacheURL ] = modified;
  9724. }
  9725. modified = jqXHR.getResponseHeader("etag");
  9726. if ( modified ) {
  9727. jQuery.etag[ cacheURL ] = modified;
  9728. }
  9729. }
  9730. // if no content
  9731. if ( status === 204 || s.type === "HEAD" ) {
  9732. statusText = "nocontent";
  9733. // if not modified
  9734. } else if ( status === 304 ) {
  9735. statusText = "notmodified";
  9736. // If we have data, let's convert it
  9737. } else {
  9738. statusText = response.state;
  9739. success = response.data;
  9740. error = response.error;
  9741. isSuccess = !error;
  9742. }
  9743. } else {
  9744. // We extract error from statusText
  9745. // then normalize statusText and status for non-aborts
  9746. error = statusText;
  9747. if ( status || !statusText ) {
  9748. statusText = "error";
  9749. if ( status < 0 ) {
  9750. status = 0;
  9751. }
  9752. }
  9753. }
  9754. // Set data for the fake xhr object
  9755. jqXHR.status = status;
  9756. jqXHR.statusText = ( nativeStatusText || statusText ) + "";
  9757. // Success/Error
  9758. if ( isSuccess ) {
  9759. deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
  9760. } else {
  9761. deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
  9762. }
  9763. // Status-dependent callbacks
  9764. jqXHR.statusCode( statusCode );
  9765. statusCode = undefined;
  9766. if ( fireGlobals ) {
  9767. globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
  9768. [ jqXHR, s, isSuccess ? success : error ] );
  9769. }
  9770. // Complete
  9771. completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
  9772. if ( fireGlobals ) {
  9773. globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
  9774. // Handle the global AJAX counter
  9775. if ( !( --jQuery.active ) ) {
  9776. jQuery.event.trigger("ajaxStop");
  9777. }
  9778. }
  9779. }
  9780. return jqXHR;
  9781. },
  9782. getJSON: function( url, data, callback ) {
  9783. return jQuery.get( url, data, callback, "json" );
  9784. },
  9785. getScript: function( url, callback ) {
  9786. return jQuery.get( url, undefined, callback, "script" );
  9787. }
  9788. });
  9789. jQuery.each( [ "get", "post" ], function( i, method ) {
  9790. jQuery[ method ] = function( url, data, callback, type ) {
  9791. // shift arguments if data argument was omitted
  9792. if ( jQuery.isFunction( data ) ) {
  9793. type = type || callback;
  9794. callback = data;
  9795. data = undefined;
  9796. }
  9797. return jQuery.ajax({
  9798. url: url,
  9799. type: method,
  9800. dataType: type,
  9801. data: data,
  9802. success: callback
  9803. });
  9804. };
  9805. });
  9806. // Attach a bunch of functions for handling common AJAX events
  9807. jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
  9808. jQuery.fn[ type ] = function( fn ) {
  9809. return this.on( type, fn );
  9810. };
  9811. });
  9812. jQuery._evalUrl = function( url ) {
  9813. return jQuery.ajax({
  9814. url: url,
  9815. type: "GET",
  9816. dataType: "script",
  9817. async: false,
  9818. global: false,
  9819. "throws": true
  9820. });
  9821. };
  9822. jQuery.fn.extend({
  9823. wrapAll: function( html ) {
  9824. var wrap;
  9825. if ( jQuery.isFunction( html ) ) {
  9826. return this.each(function( i ) {
  9827. jQuery( this ).wrapAll( html.call(this, i) );
  9828. });
  9829. }
  9830. if ( this[ 0 ] ) {
  9831. // The elements to wrap the target around
  9832. wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
  9833. if ( this[ 0 ].parentNode ) {
  9834. wrap.insertBefore( this[ 0 ] );
  9835. }
  9836. wrap.map(function() {
  9837. var elem = this;
  9838. while ( elem.firstElementChild ) {
  9839. elem = elem.firstElementChild;
  9840. }
  9841. return elem;
  9842. }).append( this );
  9843. }
  9844. return this;
  9845. },
  9846. wrapInner: function( html ) {
  9847. if ( jQuery.isFunction( html ) ) {
  9848. return this.each(function( i ) {
  9849. jQuery( this ).wrapInner( html.call(this, i) );
  9850. });
  9851. }
  9852. return this.each(function() {
  9853. var self = jQuery( this ),
  9854. contents = self.contents();
  9855. if ( contents.length ) {
  9856. contents.wrapAll( html );
  9857. } else {
  9858. self.append( html );
  9859. }
  9860. });
  9861. },
  9862. wrap: function( html ) {
  9863. var isFunction = jQuery.isFunction( html );
  9864. return this.each(function( i ) {
  9865. jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
  9866. });
  9867. },
  9868. unwrap: function() {
  9869. return this.parent().each(function() {
  9870. if ( !jQuery.nodeName( this, "body" ) ) {
  9871. jQuery( this ).replaceWith( this.childNodes );
  9872. }
  9873. }).end();
  9874. }
  9875. });
  9876. jQuery.expr.filters.hidden = function( elem ) {
  9877. // Support: Opera <= 12.12
  9878. // Opera reports offsetWidths and offsetHeights less than zero on some elements
  9879. return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
  9880. };
  9881. jQuery.expr.filters.visible = function( elem ) {
  9882. return !jQuery.expr.filters.hidden( elem );
  9883. };
  9884. var r20 = /%20/g,
  9885. rbracket = /\[\]$/,
  9886. rCRLF = /\r?\n/g,
  9887. rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
  9888. rsubmittable = /^(?:input|select|textarea|keygen)/i;
  9889. function buildParams( prefix, obj, traditional, add ) {
  9890. var name;
  9891. if ( jQuery.isArray( obj ) ) {
  9892. // Serialize array item.
  9893. jQuery.each( obj, function( i, v ) {
  9894. if ( traditional || rbracket.test( prefix ) ) {
  9895. // Treat each array item as a scalar.
  9896. add( prefix, v );
  9897. } else {
  9898. // Item is non-scalar (array or object), encode its numeric index.
  9899. buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
  9900. }
  9901. });
  9902. } else if ( !traditional && jQuery.type( obj ) === "object" ) {
  9903. // Serialize object item.
  9904. for ( name in obj ) {
  9905. buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
  9906. }
  9907. } else {
  9908. // Serialize scalar item.
  9909. add( prefix, obj );
  9910. }
  9911. }
  9912. // Serialize an array of form elements or a set of
  9913. // key/values into a query string
  9914. jQuery.param = function( a, traditional ) {
  9915. var prefix,
  9916. s = [],
  9917. add = function( key, value ) {
  9918. // If value is a function, invoke it and return its value
  9919. value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
  9920. s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
  9921. };
  9922. // Set traditional to true for jQuery <= 1.3.2 behavior.
  9923. if ( traditional === undefined ) {
  9924. traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
  9925. }
  9926. // If an array was passed in, assume that it is an array of form elements.
  9927. if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
  9928. // Serialize the form elements
  9929. jQuery.each( a, function() {
  9930. add( this.name, this.value );
  9931. });
  9932. } else {
  9933. // If traditional, encode the "old" way (the way 1.3.2 or older
  9934. // did it), otherwise encode params recursively.
  9935. for ( prefix in a ) {
  9936. buildParams( prefix, a[ prefix ], traditional, add );
  9937. }
  9938. }
  9939. // Return the resulting serialization
  9940. return s.join( "&" ).replace( r20, "+" );
  9941. };
  9942. jQuery.fn.extend({
  9943. serialize: function() {
  9944. return jQuery.param( this.serializeArray() );
  9945. },
  9946. serializeArray: function() {
  9947. return this.map(function() {
  9948. // Can add propHook for "elements" to filter or add form elements
  9949. var elements = jQuery.prop( this, "elements" );
  9950. return elements ? jQuery.makeArray( elements ) : this;
  9951. })
  9952. .filter(function() {
  9953. var type = this.type;
  9954. // Use .is( ":disabled" ) so that fieldset[disabled] works
  9955. return this.name && !jQuery( this ).is( ":disabled" ) &&
  9956. rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
  9957. ( this.checked || !rcheckableType.test( type ) );
  9958. })
  9959. .map(function( i, elem ) {
  9960. var val = jQuery( this ).val();
  9961. return val == null ?
  9962. null :
  9963. jQuery.isArray( val ) ?
  9964. jQuery.map( val, function( val ) {
  9965. return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
  9966. }) :
  9967. { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
  9968. }).get();
  9969. }
  9970. });
  9971. jQuery.ajaxSettings.xhr = function() {
  9972. try {
  9973. return new XMLHttpRequest();
  9974. } catch( e ) {}
  9975. };
  9976. var xhrId = 0,
  9977. xhrCallbacks = {},
  9978. xhrSuccessStatus = {
  9979. // file protocol always yields status code 0, assume 200
  9980. 0: 200,
  9981. // Support: IE9
  9982. // #1450: sometimes IE returns 1223 when it should be 204
  9983. 1223: 204
  9984. },
  9985. xhrSupported = jQuery.ajaxSettings.xhr();
  9986. // Support: IE9
  9987. // Open requests must be manually aborted on unload (#5280)
  9988. if ( window.ActiveXObject ) {
  9989. jQuery( window ).on( "unload", function() {
  9990. for ( var key in xhrCallbacks ) {
  9991. xhrCallbacks[ key ]();
  9992. }
  9993. });
  9994. }
  9995. support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
  9996. support.ajax = xhrSupported = !!xhrSupported;
  9997. jQuery.ajaxTransport(function( options ) {
  9998. var callback;
  9999. // Cross domain only allowed if supported through XMLHttpRequest
  10000. if ( support.cors || xhrSupported && !options.crossDomain ) {
  10001. return {
  10002. send: function( headers, complete ) {
  10003. var i,
  10004. xhr = options.xhr(),
  10005. id = ++xhrId;
  10006. xhr.open( options.type, options.url, options.async, options.username, options.password );
  10007. // Apply custom fields if provided
  10008. if ( options.xhrFields ) {
  10009. for ( i in options.xhrFields ) {
  10010. xhr[ i ] = options.xhrFields[ i ];
  10011. }
  10012. }
  10013. // Override mime type if needed
  10014. if ( options.mimeType && xhr.overrideMimeType ) {
  10015. xhr.overrideMimeType( options.mimeType );
  10016. }
  10017. // X-Requested-With header
  10018. // For cross-domain requests, seeing as conditions for a preflight are
  10019. // akin to a jigsaw puzzle, we simply never set it to be sure.
  10020. // (it can always be set on a per-request basis or even using ajaxSetup)
  10021. // For same-domain requests, won't change header if already provided.
  10022. if ( !options.crossDomain && !headers["X-Requested-With"] ) {
  10023. headers["X-Requested-With"] = "XMLHttpRequest";
  10024. }
  10025. // Set headers
  10026. for ( i in headers ) {
  10027. xhr.setRequestHeader( i, headers[ i ] );
  10028. }
  10029. // Callback
  10030. callback = function( type ) {
  10031. return function() {
  10032. if ( callback ) {
  10033. delete xhrCallbacks[ id ];
  10034. callback = xhr.onload = xhr.onerror = null;
  10035. if ( type === "abort" ) {
  10036. xhr.abort();
  10037. } else if ( type === "error" ) {
  10038. complete(
  10039. // file: protocol always yields status 0; see #8605, #14207
  10040. xhr.status,
  10041. xhr.statusText
  10042. );
  10043. } else {
  10044. complete(
  10045. xhrSuccessStatus[ xhr.status ] || xhr.status,
  10046. xhr.statusText,
  10047. // Support: IE9
  10048. // Accessing binary-data responseText throws an exception
  10049. // (#11426)
  10050. typeof xhr.responseText === "string" ? {
  10051. text: xhr.responseText
  10052. } : undefined,
  10053. xhr.getAllResponseHeaders()
  10054. );
  10055. }
  10056. }
  10057. };
  10058. };
  10059. // Listen to events
  10060. xhr.onload = callback();
  10061. xhr.onerror = callback("error");
  10062. // Create the abort callback
  10063. callback = xhrCallbacks[ id ] = callback("abort");
  10064. // Do send the request
  10065. // This may raise an exception which is actually
  10066. // handled in jQuery.ajax (so no try/catch here)
  10067. xhr.send( options.hasContent && options.data || null );
  10068. },
  10069. abort: function() {
  10070. if ( callback ) {
  10071. callback();
  10072. }
  10073. }
  10074. };
  10075. }
  10076. });
  10077. // Install script dataType
  10078. jQuery.ajaxSetup({
  10079. accepts: {
  10080. script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
  10081. },
  10082. contents: {
  10083. script: /(?:java|ecma)script/
  10084. },
  10085. converters: {
  10086. "text script": function( text ) {
  10087. jQuery.globalEval( text );
  10088. return text;
  10089. }
  10090. }
  10091. });
  10092. // Handle cache's special case and crossDomain
  10093. jQuery.ajaxPrefilter( "script", function( s ) {
  10094. if ( s.cache === undefined ) {
  10095. s.cache = false;
  10096. }
  10097. if ( s.crossDomain ) {
  10098. s.type = "GET";
  10099. }
  10100. });
  10101. // Bind script tag hack transport
  10102. jQuery.ajaxTransport( "script", function( s ) {
  10103. // This transport only deals with cross domain requests
  10104. if ( s.crossDomain ) {
  10105. var script, callback;
  10106. return {
  10107. send: function( _, complete ) {
  10108. script = jQuery("<script>").prop({
  10109. async: true,
  10110. charset: s.scriptCharset,
  10111. src: s.url
  10112. }).on(
  10113. "load error",
  10114. callback = function( evt ) {
  10115. script.remove();
  10116. callback = null;
  10117. if ( evt ) {
  10118. complete( evt.type === "error" ? 404 : 200, evt.type );
  10119. }
  10120. }
  10121. );
  10122. document.head.appendChild( script[ 0 ] );
  10123. },
  10124. abort: function() {
  10125. if ( callback ) {
  10126. callback();
  10127. }
  10128. }
  10129. };
  10130. }
  10131. });
  10132. var oldCallbacks = [],
  10133. rjsonp = /(=)\?(?=&|$)|\?\?/;
  10134. // Default jsonp settings
  10135. jQuery.ajaxSetup({
  10136. jsonp: "callback",
  10137. jsonpCallback: function() {
  10138. var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
  10139. this[ callback ] = true;
  10140. return callback;
  10141. }
  10142. });
  10143. // Detect, normalize options and install callbacks for jsonp requests
  10144. jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
  10145. var callbackName, overwritten, responseContainer,
  10146. jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
  10147. "url" :
  10148. typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
  10149. );
  10150. // Handle iff the expected data type is "jsonp" or we have a parameter to set
  10151. if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
  10152. // Get callback name, remembering preexisting value associated with it
  10153. callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
  10154. s.jsonpCallback() :
  10155. s.jsonpCallback;
  10156. // Insert callback into url or form data
  10157. if ( jsonProp ) {
  10158. s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
  10159. } else if ( s.jsonp !== false ) {
  10160. s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
  10161. }
  10162. // Use data converter to retrieve json after script execution
  10163. s.converters["script json"] = function() {
  10164. if ( !responseContainer ) {
  10165. jQuery.error( callbackName + " was not called" );
  10166. }
  10167. return responseContainer[ 0 ];
  10168. };
  10169. // force json dataType
  10170. s.dataTypes[ 0 ] = "json";
  10171. // Install callback
  10172. overwritten = window[ callbackName ];
  10173. window[ callbackName ] = function() {
  10174. responseContainer = arguments;
  10175. };
  10176. // Clean-up function (fires after converters)
  10177. jqXHR.always(function() {
  10178. // Restore preexisting value
  10179. window[ callbackName ] = overwritten;
  10180. // Save back as free
  10181. if ( s[ callbackName ] ) {
  10182. // make sure that re-using the options doesn't screw things around
  10183. s.jsonpCallback = originalSettings.jsonpCallback;
  10184. // save the callback name for future use
  10185. oldCallbacks.push( callbackName );
  10186. }
  10187. // Call if it was a function and we have a response
  10188. if ( responseContainer && jQuery.isFunction( overwritten ) ) {
  10189. overwritten( responseContainer[ 0 ] );
  10190. }
  10191. responseContainer = overwritten = undefined;
  10192. });
  10193. // Delegate to script
  10194. return "script";
  10195. }
  10196. });
  10197. // data: string of html
  10198. // context (optional): If specified, the fragment will be created in this context, defaults to document
  10199. // keepScripts (optional): If true, will include scripts passed in the html string
  10200. jQuery.parseHTML = function( data, context, keepScripts ) {
  10201. if ( !data || typeof data !== "string" ) {
  10202. return null;
  10203. }
  10204. if ( typeof context === "boolean" ) {
  10205. keepScripts = context;
  10206. context = false;
  10207. }
  10208. context = context || document;
  10209. var parsed = rsingleTag.exec( data ),
  10210. scripts = !keepScripts && [];
  10211. // Single tag
  10212. if ( parsed ) {
  10213. return [ context.createElement( parsed[1] ) ];
  10214. }
  10215. parsed = jQuery.buildFragment( [ data ], context, scripts );
  10216. if ( scripts && scripts.length ) {
  10217. jQuery( scripts ).remove();
  10218. }
  10219. return jQuery.merge( [], parsed.childNodes );
  10220. };
  10221. // Keep a copy of the old load method
  10222. var _load = jQuery.fn.load;
  10223. /**
  10224. * Load a url into a page
  10225. */
  10226. jQuery.fn.load = function( url, params, callback ) {
  10227. if ( typeof url !== "string" && _load ) {
  10228. return _load.apply( this, arguments );
  10229. }
  10230. var selector, type, response,
  10231. self = this,
  10232. off = url.indexOf(" ");
  10233. if ( off >= 0 ) {
  10234. selector = url.slice( off );
  10235. url = url.slice( 0, off );
  10236. }
  10237. // If it's a function
  10238. if ( jQuery.isFunction( params ) ) {
  10239. // We assume that it's the callback
  10240. callback = params;
  10241. params = undefined;
  10242. // Otherwise, build a param string
  10243. } else if ( params && typeof params === "object" ) {
  10244. type = "POST";
  10245. }
  10246. // If we have elements to modify, make the request
  10247. if ( self.length > 0 ) {
  10248. jQuery.ajax({
  10249. url: url,
  10250. // if "type" variable is undefined, then "GET" method will be used
  10251. type: type,
  10252. dataType: "html",
  10253. data: params
  10254. }).done(function( responseText ) {
  10255. // Save response for use in complete callback
  10256. response = arguments;
  10257. self.html( selector ?
  10258. // If a selector was specified, locate the right elements in a dummy div
  10259. // Exclude scripts to avoid IE 'Permission Denied' errors
  10260. jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
  10261. // Otherwise use the full result
  10262. responseText );
  10263. }).complete( callback && function( jqXHR, status ) {
  10264. self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
  10265. });
  10266. }
  10267. return this;
  10268. };
  10269. jQuery.expr.filters.animated = function( elem ) {
  10270. return jQuery.grep(jQuery.timers, function( fn ) {
  10271. return elem === fn.elem;
  10272. }).length;
  10273. };
  10274. var docElem = window.document.documentElement;
  10275. /**
  10276. * Gets a window from an element
  10277. */
  10278. function getWindow( elem ) {
  10279. return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
  10280. }
  10281. jQuery.offset = {
  10282. setOffset: function( elem, options, i ) {
  10283. var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
  10284. position = jQuery.css( elem, "position" ),
  10285. curElem = jQuery( elem ),
  10286. props = {};
  10287. // Set position first, in-case top/left are set even on static elem
  10288. if ( position === "static" ) {
  10289. elem.style.position = "relative";
  10290. }
  10291. curOffset = curElem.offset();
  10292. curCSSTop = jQuery.css( elem, "top" );
  10293. curCSSLeft = jQuery.css( elem, "left" );
  10294. calculatePosition = ( position === "absolute" || position === "fixed" ) &&
  10295. ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
  10296. // Need to be able to calculate position if either top or left is auto and position is either absolute or fixed
  10297. if ( calculatePosition ) {
  10298. curPosition = curElem.position();
  10299. curTop = curPosition.top;
  10300. curLeft = curPosition.left;
  10301. } else {
  10302. curTop = parseFloat( curCSSTop ) || 0;
  10303. curLeft = parseFloat( curCSSLeft ) || 0;
  10304. }
  10305. if ( jQuery.isFunction( options ) ) {
  10306. options = options.call( elem, i, curOffset );
  10307. }
  10308. if ( options.top != null ) {
  10309. props.top = ( options.top - curOffset.top ) + curTop;
  10310. }
  10311. if ( options.left != null ) {
  10312. props.left = ( options.left - curOffset.left ) + curLeft;
  10313. }
  10314. if ( "using" in options ) {
  10315. options.using.call( elem, props );
  10316. } else {
  10317. curElem.css( props );
  10318. }
  10319. }
  10320. };
  10321. jQuery.fn.extend({
  10322. offset: function( options ) {
  10323. if ( arguments.length ) {
  10324. return options === undefined ?
  10325. this :
  10326. this.each(function( i ) {
  10327. jQuery.offset.setOffset( this, options, i );
  10328. });
  10329. }
  10330. var docElem, win,
  10331. elem = this[ 0 ],
  10332. box = { top: 0, left: 0 },
  10333. doc = elem && elem.ownerDocument;
  10334. if ( !doc ) {
  10335. return;
  10336. }
  10337. docElem = doc.documentElement;
  10338. // Make sure it's not a disconnected DOM node
  10339. if ( !jQuery.contains( docElem, elem ) ) {
  10340. return box;
  10341. }
  10342. // If we don't have gBCR, just use 0,0 rather than error
  10343. // BlackBerry 5, iOS 3 (original iPhone)
  10344. if ( typeof elem.getBoundingClientRect !== strundefined ) {
  10345. box = elem.getBoundingClientRect();
  10346. }
  10347. win = getWindow( doc );
  10348. return {
  10349. top: box.top + win.pageYOffset - docElem.clientTop,
  10350. left: box.left + win.pageXOffset - docElem.clientLeft
  10351. };
  10352. },
  10353. position: function() {
  10354. if ( !this[ 0 ] ) {
  10355. return;
  10356. }
  10357. var offsetParent, offset,
  10358. elem = this[ 0 ],
  10359. parentOffset = { top: 0, left: 0 };
  10360. // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
  10361. if ( jQuery.css( elem, "position" ) === "fixed" ) {
  10362. // We assume that getBoundingClientRect is available when computed position is fixed
  10363. offset = elem.getBoundingClientRect();
  10364. } else {
  10365. // Get *real* offsetParent
  10366. offsetParent = this.offsetParent();
  10367. // Get correct offsets
  10368. offset = this.offset();
  10369. if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
  10370. parentOffset = offsetParent.offset();
  10371. }
  10372. // Add offsetParent borders
  10373. parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
  10374. parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
  10375. }
  10376. // Subtract parent offsets and element margins
  10377. return {
  10378. top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
  10379. left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
  10380. };
  10381. },
  10382. offsetParent: function() {
  10383. return this.map(function() {
  10384. var offsetParent = this.offsetParent || docElem;
  10385. while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
  10386. offsetParent = offsetParent.offsetParent;
  10387. }
  10388. return offsetParent || docElem;
  10389. });
  10390. }
  10391. });
  10392. // Create scrollLeft and scrollTop methods
  10393. jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
  10394. var top = "pageYOffset" === prop;
  10395. jQuery.fn[ method ] = function( val ) {
  10396. return access( this, function( elem, method, val ) {
  10397. var win = getWindow( elem );
  10398. if ( val === undefined ) {
  10399. return win ? win[ prop ] : elem[ method ];
  10400. }
  10401. if ( win ) {
  10402. win.scrollTo(
  10403. !top ? val : window.pageXOffset,
  10404. top ? val : window.pageYOffset
  10405. );
  10406. } else {
  10407. elem[ method ] = val;
  10408. }
  10409. }, method, val, arguments.length, null );
  10410. };
  10411. });
  10412. // Add the top/left cssHooks using jQuery.fn.position
  10413. // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
  10414. // getComputedStyle returns percent when specified for top/left/bottom/right
  10415. // rather than make the css module depend on the offset module, we just check for it here
  10416. jQuery.each( [ "top", "left" ], function( i, prop ) {
  10417. jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
  10418. function( elem, computed ) {
  10419. if ( computed ) {
  10420. computed = curCSS( elem, prop );
  10421. // if curCSS returns percentage, fallback to offset
  10422. return rnumnonpx.test( computed ) ?
  10423. jQuery( elem ).position()[ prop ] + "px" :
  10424. computed;
  10425. }
  10426. }
  10427. );
  10428. });
  10429. // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
  10430. jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
  10431. jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
  10432. // margin is only for outerHeight, outerWidth
  10433. jQuery.fn[ funcName ] = function( margin, value ) {
  10434. var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
  10435. extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
  10436. return access( this, function( elem, type, value ) {
  10437. var doc;
  10438. if ( jQuery.isWindow( elem ) ) {
  10439. // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
  10440. // isn't a whole lot we can do. See pull request at this URL for discussion:
  10441. // https://github.com/jquery/jquery/pull/764
  10442. return elem.document.documentElement[ "client" + name ];
  10443. }
  10444. // Get document width or height
  10445. if ( elem.nodeType === 9 ) {
  10446. doc = elem.documentElement;
  10447. // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
  10448. // whichever is greatest
  10449. return Math.max(
  10450. elem.body[ "scroll" + name ], doc[ "scroll" + name ],
  10451. elem.body[ "offset" + name ], doc[ "offset" + name ],
  10452. doc[ "client" + name ]
  10453. );
  10454. }
  10455. return value === undefined ?
  10456. // Get width or height on the element, requesting but not forcing parseFloat
  10457. jQuery.css( elem, type, extra ) :
  10458. // Set width or height on the element
  10459. jQuery.style( elem, type, value, extra );
  10460. }, type, chainable ? margin : undefined, chainable, null );
  10461. };
  10462. });
  10463. });
  10464. // The number of elements contained in the matched element set
  10465. jQuery.fn.size = function() {
  10466. return this.length;
  10467. };
  10468. jQuery.fn.andSelf = jQuery.fn.addBack;
  10469. // Register as a named AMD module, since jQuery can be concatenated with other
  10470. // files that may use define, but not via a proper concatenation script that
  10471. // understands anonymous AMD modules. A named AMD is safest and most robust
  10472. // way to register. Lowercase jquery is used because AMD module names are
  10473. // derived from file names, and jQuery is normally delivered in a lowercase
  10474. // file name. Do this after creating the global so that if an AMD module wants
  10475. // to call noConflict to hide this version of jQuery, it will work.
  10476. if ( typeof define === "function" && define.amd ) {
  10477. define( "jquery", [], function() {
  10478. return jQuery;
  10479. });
  10480. }
  10481. var
  10482. // Map over jQuery in case of overwrite
  10483. _jQuery = window.jQuery,
  10484. // Map over the $ in case of overwrite
  10485. _$ = window.$;
  10486. jQuery.noConflict = function( deep ) {
  10487. if ( window.$ === jQuery ) {
  10488. window.$ = _$;
  10489. }
  10490. if ( deep && window.jQuery === jQuery ) {
  10491. window.jQuery = _jQuery;
  10492. }
  10493. return jQuery;
  10494. };
  10495. // Expose jQuery and $ identifiers, even in
  10496. // AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
  10497. // and CommonJS for browser emulators (#13566)
  10498. if ( typeof noGlobal === strundefined ) {
  10499. window.jQuery = window.$ = jQuery;
  10500. }
  10501. return jQuery;
  10502. }));
  10503. },{}],11:[function(require,module,exports){
  10504. // Middleware that injects the shared data and sharify script
  10505. module.exports = function(req, res, next) {
  10506. // Clone the "constant" sharify data for the request so
  10507. // request-level data isn't shared across the server potentially
  10508. // exposing sensitive data.
  10509. var data = {};
  10510. for(var key in module.exports.data) {
  10511. data[key] = module.exports.data[key];
  10512. };
  10513. // Inject a sharify object into locals for `= sharify.data` and `= sharify.script()`
  10514. res.locals.sharify = {
  10515. data: data,
  10516. script: function() {
  10517. return '<script type="text/javascript">' +
  10518. 'window.__sharifyData = ' +
  10519. //There are tricky rules about safely embedding JSON within HTML
  10520. //see http://stackoverflow.com/a/4180424/266795
  10521. JSON.stringify(data)
  10522. .replace(/</g, '\\u003c')
  10523. .replace(/-->/g, '--\\>') +
  10524. ';</script>';
  10525. }
  10526. };
  10527. // Alias the sharify short-hand for convience
  10528. res.locals.sd = res.locals.sharify.data;
  10529. next();
  10530. };
  10531. // The shared hash of data
  10532. module.exports.data = {};
  10533. // When required on the client via browserify, run this snippet that reads the
  10534. // sharify.script data and injects it into this module.
  10535. var bootstrapOnClient = module.exports.bootstrapOnClient = function() {
  10536. if (typeof window != 'undefined' && window.__sharifyData) {
  10537. module.exports.data = window.__sharifyData;
  10538. }
  10539. };
  10540. bootstrapOnClient();
  10541. },{}]},{},[3])