request.js 155 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232
  1. var $ = (function () {
  2. var deletedIds = [];
  3. var slice = deletedIds.slice;
  4. var concat = deletedIds.concat;
  5. var push = deletedIds.push;
  6. var indexOf = deletedIds.indexOf;
  7. var class2type = {};
  8. var toString = class2type.toString;
  9. var hasOwn = class2type.hasOwnProperty;
  10. var support = {};
  11. var
  12. version = "1.11.1 -css,-css/addGetHookIf,-css/curCSS,-css/defaultDisplay,-css/hiddenVisibleSelectors,-css/support,-css/swap,-css/var/cssExpand,-css/var/isHidden,-css/var/rmargin,-css/var/rnumnonpx,-effects,-effects/Tween,-effects/animatedSelector,-effects/support,-dimensions,-offset,-deprecated,-event-alias,-wrap",
  13. // Define a local copy of jQuery
  14. jQuery = function (selector, context) {
  15. // The jQuery object is actually just the init constructor 'enhanced'
  16. // Need init if jQuery is called (just allow error to be thrown if not included)
  17. return new jQuery.fn.init(selector, context);
  18. },
  19. // Support: Android<4.1, IE<9
  20. // Make sure we trim BOM and NBSP
  21. rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
  22. // Matches dashed string for camelizing
  23. rmsPrefix = /^-ms-/,
  24. rdashAlpha = /-([\da-z])/gi,
  25. // Used by jQuery.camelCase as callback to replace()
  26. fcamelCase = function (all, letter) {
  27. return letter.toUpperCase();
  28. };
  29. jQuery.fn = jQuery.prototype = {
  30. // The current version of jQuery being used
  31. jquery: version,
  32. constructor: jQuery,
  33. // Start with an empty selector
  34. selector: "",
  35. // The default length of a jQuery object is 0
  36. length: 0,
  37. toArray: function () {
  38. return slice.call(this);
  39. },
  40. // Get the Nth element in the matched element set OR
  41. // Get the whole matched element set as a clean array
  42. get: function (num) {
  43. return num != null ?
  44. // Return just the one element from the set
  45. ( num < 0 ? this[num + this.length] : this[num] ) :
  46. // Return all the elements in a clean array
  47. slice.call(this);
  48. },
  49. // Take an array of elements and push it onto the stack
  50. // (returning the new matched element set)
  51. pushStack: function (elems) {
  52. // Build a new jQuery matched element set
  53. var ret = jQuery.merge(this.constructor(), elems);
  54. // Add the old object onto the stack (as a reference)
  55. ret.prevObject = this;
  56. ret.context = this.context;
  57. // Return the newly-formed element set
  58. return ret;
  59. },
  60. // Execute a callback for every element in the matched set.
  61. // (You can seed the arguments with an array of args, but this is
  62. // only used internally.)
  63. each: function (callback, args) {
  64. return jQuery.each(this, callback, args);
  65. },
  66. map: function (callback) {
  67. return this.pushStack(jQuery.map(this, function (elem, i) {
  68. return callback.call(elem, i, elem);
  69. }));
  70. },
  71. slice: function () {
  72. return this.pushStack(slice.apply(this, arguments));
  73. },
  74. first: function () {
  75. return this.eq(0);
  76. },
  77. last: function () {
  78. return this.eq(-1);
  79. },
  80. eq: function (i) {
  81. var len = this.length,
  82. j = +i + ( i < 0 ? len : 0 );
  83. return this.pushStack(j >= 0 && j < len ? [this[j]] : []);
  84. },
  85. end: function () {
  86. return this.prevObject || this.constructor(null);
  87. },
  88. // For internal use only.
  89. // Behaves like an Array's method, not like a jQuery method.
  90. push: push,
  91. sort: deletedIds.sort,
  92. splice: deletedIds.splice
  93. };
  94. jQuery.extend = jQuery.fn.extend = function () {
  95. var src, copyIsArray, copy, name, options, clone,
  96. target = arguments[0] || {},
  97. i = 1,
  98. length = arguments.length,
  99. deep = false;
  100. // Handle a deep copy situation
  101. if (typeof target === "boolean") {
  102. deep = target;
  103. // skip the boolean and the target
  104. target = arguments[i] || {};
  105. i++;
  106. }
  107. // Handle case when target is a string or something (possible in deep copy)
  108. if (typeof target !== "object" && !jQuery.isFunction(target)) {
  109. target = {};
  110. }
  111. // extend jQuery itself if only one argument is passed
  112. if (i === length) {
  113. target = this;
  114. i--;
  115. }
  116. for (; i < length; i++) {
  117. // Only deal with non-null/undefined values
  118. if ((options = arguments[i]) != null) {
  119. // Extend the base object
  120. for (name in options) {
  121. src = target[name];
  122. copy = options[name];
  123. // Prevent never-ending loop
  124. if (target === copy) {
  125. continue;
  126. }
  127. // Recurse if we're merging plain objects or arrays
  128. if (deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) )) {
  129. if (copyIsArray) {
  130. copyIsArray = false;
  131. clone = src && jQuery.isArray(src) ? src : [];
  132. } else {
  133. clone = src && jQuery.isPlainObject(src) ? src : {};
  134. }
  135. // Never move original objects, clone them
  136. target[name] = jQuery.extend(deep, clone, copy);
  137. // Don't bring in undefined values
  138. } else if (copy !== undefined) {
  139. target[name] = copy;
  140. }
  141. }
  142. }
  143. }
  144. // Return the modified object
  145. return target;
  146. };
  147. jQuery.extend({
  148. // Unique for each copy of jQuery on the page
  149. expando: "jQuery" + ( version + Math.random() ).replace(/\D/g, ""),
  150. // Assume jQuery is ready without the ready module
  151. isReady: true,
  152. error: function (msg) {
  153. throw new Error(msg);
  154. },
  155. noop: function () {
  156. },
  157. // See test/unit/core.js for details concerning isFunction.
  158. // Since version 1.3, DOM methods and functions like alert
  159. // aren't supported. They return false on IE (#2968).
  160. isFunction: function (obj) {
  161. return jQuery.type(obj) === "function";
  162. },
  163. isArray: Array.isArray || function (obj) {
  164. return jQuery.type(obj) === "array";
  165. },
  166. isWindow: function (obj) {
  167. /* jshint eqeqeq: false */
  168. return obj != null && obj == obj.window;
  169. },
  170. isNumeric: function (obj) {
  171. // parseFloat NaNs numeric-cast false positives (null|true|false|"")
  172. // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  173. // subtraction forces infinities to NaN
  174. return !jQuery.isArray(obj) && obj - parseFloat(obj) >= 0;
  175. },
  176. isEmptyObject: function (obj) {
  177. var name;
  178. for (name in obj) {
  179. return false;
  180. }
  181. return true;
  182. },
  183. isPlainObject: function (obj) {
  184. var key;
  185. // Must be an Object.
  186. // Because of IE, we also have to check the presence of the constructor property.
  187. // Make sure that DOM nodes and window objects don't pass through, as well
  188. if (!obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow(obj)) {
  189. return false;
  190. }
  191. try {
  192. // Not own constructor property must be Object
  193. if (obj.constructor &&
  194. !hasOwn.call(obj, "constructor") &&
  195. !hasOwn.call(obj.constructor.prototype, "isPrototypeOf")) {
  196. return false;
  197. }
  198. } catch (e) {
  199. // IE8,9 Will throw exceptions on certain host objects #9897
  200. return false;
  201. }
  202. // Support: IE<9
  203. // Handle iteration over inherited properties before own properties.
  204. if (support.ownLast) {
  205. for (key in obj) {
  206. return hasOwn.call(obj, key);
  207. }
  208. }
  209. // Own properties are enumerated firstly, so to speed up,
  210. // if last one is own, then all properties are own.
  211. for (key in obj) {
  212. }
  213. return key === undefined || hasOwn.call(obj, key);
  214. },
  215. type: function (obj) {
  216. if (obj == null) {
  217. return obj + "";
  218. }
  219. return typeof obj === "object" || typeof obj === "function" ?
  220. class2type[toString.call(obj)] || "object" :
  221. typeof obj;
  222. },
  223. // Evaluates a script in a global context
  224. // Workarounds based on findings by Jim Driscoll
  225. // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
  226. globalEval: function (data) {
  227. if (data && jQuery.trim(data)) {
  228. // We use execScript on Internet Explorer
  229. // We use an anonymous function so that context is window
  230. // rather than jQuery in Firefox
  231. ( window.execScript || function (data) {
  232. window["eval"].call(window, data);
  233. } )(data);
  234. }
  235. },
  236. // Convert dashed to camelCase; used by the css and data modules
  237. // Microsoft forgot to hump their vendor prefix (#9572)
  238. camelCase: function (string) {
  239. return string.replace(rmsPrefix, "ms-").replace(rdashAlpha, fcamelCase);
  240. },
  241. nodeName: function (elem, name) {
  242. return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
  243. },
  244. // args is for internal usage only
  245. each: function (obj, callback, args) {
  246. var value,
  247. i = 0,
  248. length = obj.length,
  249. isArray = isArraylike(obj);
  250. if (args) {
  251. if (isArray) {
  252. for (; i < length; i++) {
  253. value = callback.apply(obj[i], args);
  254. if (value === false) {
  255. break;
  256. }
  257. }
  258. } else {
  259. for (i in obj) {
  260. value = callback.apply(obj[i], args);
  261. if (value === false) {
  262. break;
  263. }
  264. }
  265. }
  266. // A special, fast, case for the most common use of each
  267. } else {
  268. if (isArray) {
  269. for (; i < length; i++) {
  270. value = callback.call(obj[i], i, obj[i]);
  271. if (value === false) {
  272. break;
  273. }
  274. }
  275. } else {
  276. for (i in obj) {
  277. value = callback.call(obj[i], i, obj[i]);
  278. if (value === false) {
  279. break;
  280. }
  281. }
  282. }
  283. }
  284. return obj;
  285. },
  286. // Support: Android<4.1, IE<9
  287. trim: function (text) {
  288. return text == null ?
  289. "" :
  290. ( text + "" ).replace(rtrim, "");
  291. },
  292. // results is for internal usage only
  293. makeArray: function (arr, results) {
  294. var ret = results || [];
  295. if (arr != null) {
  296. if (isArraylike(Object(arr))) {
  297. jQuery.merge(ret,
  298. typeof arr === "string" ?
  299. [arr] : arr
  300. );
  301. } else {
  302. push.call(ret, arr);
  303. }
  304. }
  305. return ret;
  306. },
  307. inArray: function (elem, arr, i) {
  308. var len;
  309. if (arr) {
  310. if (indexOf) {
  311. return indexOf.call(arr, elem, i);
  312. }
  313. len = arr.length;
  314. i = i ? i < 0 ? Math.max(0, len + i) : i : 0;
  315. for (; i < len; i++) {
  316. // Skip accessing in sparse arrays
  317. if (i in arr && arr[i] === elem) {
  318. return i;
  319. }
  320. }
  321. }
  322. return -1;
  323. },
  324. merge: function (first, second) {
  325. var len = +second.length,
  326. j = 0,
  327. i = first.length;
  328. while (j < len) {
  329. first[i++] = second[j++];
  330. }
  331. // Support: IE<9
  332. // Workaround casting of .length to NaN on otherwise arraylike objects (e.g., NodeLists)
  333. if (len !== len) {
  334. while (second[j] !== undefined) {
  335. first[i++] = second[j++];
  336. }
  337. }
  338. first.length = i;
  339. return first;
  340. },
  341. grep: function (elems, callback, invert) {
  342. var callbackInverse,
  343. matches = [],
  344. i = 0,
  345. length = elems.length,
  346. callbackExpect = !invert;
  347. // Go through the array, only saving the items
  348. // that pass the validator function
  349. for (; i < length; i++) {
  350. callbackInverse = !callback(elems[i], i);
  351. if (callbackInverse !== callbackExpect) {
  352. matches.push(elems[i]);
  353. }
  354. }
  355. return matches;
  356. },
  357. // arg is for internal usage only
  358. map: function (elems, callback, arg) {
  359. var value,
  360. i = 0,
  361. length = elems.length,
  362. isArray = isArraylike(elems),
  363. ret = [];
  364. // Go through the array, translating each of the items to their new values
  365. if (isArray) {
  366. for (; i < length; i++) {
  367. value = callback(elems[i], i, arg);
  368. if (value != null) {
  369. ret.push(value);
  370. }
  371. }
  372. // Go through every key on the object,
  373. } else {
  374. for (i in elems) {
  375. value = callback(elems[i], i, arg);
  376. if (value != null) {
  377. ret.push(value);
  378. }
  379. }
  380. }
  381. // Flatten any nested arrays
  382. return concat.apply([], ret);
  383. },
  384. // A global GUID counter for objects
  385. guid: 1,
  386. // Bind a function to a context, optionally partially applying any
  387. // arguments.
  388. proxy: function (fn, context) {
  389. var args, proxy, tmp;
  390. if (typeof context === "string") {
  391. tmp = fn[context];
  392. context = fn;
  393. fn = tmp;
  394. }
  395. // Quick check to determine if target is callable, in the spec
  396. // this throws a TypeError, but we will just return undefined.
  397. if (!jQuery.isFunction(fn)) {
  398. return undefined;
  399. }
  400. // Simulated bind
  401. args = slice.call(arguments, 2);
  402. proxy = function () {
  403. return fn.apply(context || this, args.concat(slice.call(arguments)));
  404. };
  405. // Set the guid of unique handler to the same of original handler, so it can be removed
  406. proxy.guid = fn.guid = fn.guid || jQuery.guid++;
  407. return proxy;
  408. },
  409. now: function () {
  410. return +( new Date() );
  411. },
  412. // jQuery.support is not used in Core but other projects attach their
  413. // properties to it so it needs to exist.
  414. support: support
  415. });
  416. // Populate the class2type map
  417. jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function (i, name) {
  418. class2type["[object " + name + "]"] = name.toLowerCase();
  419. });
  420. function isArraylike(obj) {
  421. var length = obj.length,
  422. type = jQuery.type(obj);
  423. if (type === "function" || jQuery.isWindow(obj)) {
  424. return false;
  425. }
  426. if (obj.nodeType === 1 && length) {
  427. return true;
  428. }
  429. return type === "array" || length === 0 ||
  430. typeof length === "number" && length > 0 && ( length - 1 ) in obj;
  431. }
  432. // Initialize a jQuery object
  433. // A central reference to the root jQuery(document)
  434. var rootjQuery,
  435. // Use the correct document accordingly with window argument (sandbox)
  436. document = window.document,
  437. // A simple way to check for HTML strings
  438. // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
  439. // Strict HTML recognition (#11290: must start with <)
  440. rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
  441. init = jQuery.fn.init = function (selector, context) {
  442. var match, elem;
  443. // HANDLE: $(""), $(null), $(undefined), $(false)
  444. if (!selector) {
  445. return this;
  446. }
  447. // Handle HTML strings
  448. if (typeof selector === "string") {
  449. if (selector.charAt(0) === "<" && selector.charAt(selector.length - 1) === ">" && selector.length >= 3) {
  450. // Assume that strings that start and end with <> are HTML and skip the regex check
  451. match = [null, selector, null];
  452. } else {
  453. match = rquickExpr.exec(selector);
  454. }
  455. // Match html or make sure no context is specified for #id
  456. if (match && (match[1] || !context)) {
  457. // HANDLE: $(html) -> $(array)
  458. if (match[1]) {
  459. context = context instanceof jQuery ? context[0] : context;
  460. // scripts is true for back-compat
  461. // Intentionally let the error be thrown if parseHTML is not present
  462. jQuery.merge(this, jQuery.parseHTML(
  463. match[1],
  464. context && context.nodeType ? context.ownerDocument || context : document,
  465. true
  466. ));
  467. // HANDLE: $(html, props)
  468. if (rsingleTag.test(match[1]) && jQuery.isPlainObject(context)) {
  469. for (match in context) {
  470. // Properties of context are called as methods if possible
  471. if (jQuery.isFunction(this[match])) {
  472. this[match](context[match]);
  473. // ...and otherwise set as attributes
  474. } else {
  475. this.attr(match, context[match]);
  476. }
  477. }
  478. }
  479. return this;
  480. // HANDLE: $(#id)
  481. } else {
  482. elem = document.getElementById(match[2]);
  483. // Check parentNode to catch when Blackberry 4.6 returns
  484. // nodes that are no longer in the document #6963
  485. if (elem && elem.parentNode) {
  486. // Handle the case where IE and Opera return items
  487. // by name instead of ID
  488. if (elem.id !== match[2]) {
  489. return rootjQuery.find(selector);
  490. }
  491. // Otherwise, we inject the element directly into the jQuery object
  492. this.length = 1;
  493. this[0] = elem;
  494. }
  495. this.context = document;
  496. this.selector = selector;
  497. return this;
  498. }
  499. // HANDLE: $(expr, $(...))
  500. } else if (!context || context.jquery) {
  501. return ( context || rootjQuery ).find(selector);
  502. // HANDLE: $(expr, context)
  503. // (which is just equivalent to: $(context).find(expr)
  504. } else {
  505. return this.constructor(context).find(selector);
  506. }
  507. // HANDLE: $(DOMElement)
  508. } else if (selector.nodeType) {
  509. this.context = this[0] = selector;
  510. this.length = 1;
  511. return this;
  512. // HANDLE: $(function)
  513. // Shortcut for document ready
  514. } else if (jQuery.isFunction(selector)) {
  515. return typeof rootjQuery.ready !== "undefined" ?
  516. rootjQuery.ready(selector) :
  517. // Execute immediately if ready is not present
  518. selector(jQuery);
  519. }
  520. if (selector.selector !== undefined) {
  521. this.selector = selector.selector;
  522. this.context = selector.context;
  523. }
  524. return jQuery.makeArray(selector, this);
  525. };
  526. // Give the init function the jQuery prototype for later instantiation
  527. init.prototype = jQuery.fn;
  528. // Initialize central reference
  529. rootjQuery = jQuery(document);
  530. var rnotwhite = (/\S+/g);
  531. // String to Object options format cache
  532. var optionsCache = {};
  533. // Convert String-formatted options into Object-formatted ones and store in cache
  534. function createOptions(options) {
  535. var object = optionsCache[options] = {};
  536. jQuery.each(options.match(rnotwhite) || [], function (_, flag) {
  537. object[flag] = true;
  538. });
  539. return object;
  540. }
  541. /*
  542. * Create a callback list using the following parameters:
  543. *
  544. * options: an optional list of space-separated options that will change how
  545. * the callback list behaves or a more traditional option object
  546. *
  547. * By default a callback list will act like an event callback list and can be
  548. * "fired" multiple times.
  549. *
  550. * Possible options:
  551. *
  552. * once: will ensure the callback list can only be fired once (like a Deferred)
  553. *
  554. * memory: will keep track of previous values and will call any callback added
  555. * after the list has been fired right away with the latest "memorized"
  556. * values (like a Deferred)
  557. *
  558. * unique: will ensure a callback can only be added once (no duplicate in the list)
  559. *
  560. * stopOnFalse: interrupt callings when a callback returns false
  561. *
  562. */
  563. jQuery.Callbacks = function (options) {
  564. // Convert options from String-formatted to Object-formatted if needed
  565. // (we check in cache first)
  566. options = typeof options === "string" ?
  567. ( optionsCache[options] || createOptions(options) ) :
  568. jQuery.extend({}, options);
  569. var // Flag to know if list is currently firing
  570. firing,
  571. // Last fire value (for non-forgettable lists)
  572. memory,
  573. // Flag to know if list was already fired
  574. fired,
  575. // End of the loop when firing
  576. firingLength,
  577. // Index of currently firing callback (modified by remove if needed)
  578. firingIndex,
  579. // First callback to fire (used internally by add and fireWith)
  580. firingStart,
  581. // Actual callback list
  582. list = [],
  583. // Stack of fire calls for repeatable lists
  584. stack = !options.once && [],
  585. // Fire callbacks
  586. fire = function (data) {
  587. memory = options.memory && data;
  588. fired = true;
  589. firingIndex = firingStart || 0;
  590. firingStart = 0;
  591. firingLength = list.length;
  592. firing = true;
  593. for (; list && firingIndex < firingLength; firingIndex++) {
  594. if (list[firingIndex].apply(data[0], data[1]) === false && options.stopOnFalse) {
  595. memory = false; // To prevent further calls using add
  596. break;
  597. }
  598. }
  599. firing = false;
  600. if (list) {
  601. if (stack) {
  602. if (stack.length) {
  603. fire(stack.shift());
  604. }
  605. } else if (memory) {
  606. list = [];
  607. } else {
  608. self.disable();
  609. }
  610. }
  611. },
  612. // Actual Callbacks object
  613. self = {
  614. // Add a callback or a collection of callbacks to the list
  615. add: function () {
  616. if (list) {
  617. // First, we save the current length
  618. var start = list.length;
  619. (function add(args) {
  620. jQuery.each(args, function (_, arg) {
  621. var type = jQuery.type(arg);
  622. if (type === "function") {
  623. if (!options.unique || !self.has(arg)) {
  624. list.push(arg);
  625. }
  626. } else if (arg && arg.length && type !== "string") {
  627. // Inspect recursively
  628. add(arg);
  629. }
  630. });
  631. })(arguments);
  632. // Do we need to add the callbacks to the
  633. // current firing batch?
  634. if (firing) {
  635. firingLength = list.length;
  636. // With memory, if we're not firing then
  637. // we should call right away
  638. } else if (memory) {
  639. firingStart = start;
  640. fire(memory);
  641. }
  642. }
  643. return this;
  644. },
  645. // Remove a callback from the list
  646. remove: function () {
  647. if (list) {
  648. jQuery.each(arguments, function (_, arg) {
  649. var index;
  650. while (( index = jQuery.inArray(arg, list, index) ) > -1) {
  651. list.splice(index, 1);
  652. // Handle firing indexes
  653. if (firing) {
  654. if (index <= firingLength) {
  655. firingLength--;
  656. }
  657. if (index <= firingIndex) {
  658. firingIndex--;
  659. }
  660. }
  661. }
  662. });
  663. }
  664. return this;
  665. },
  666. // Check if a given callback is in the list.
  667. // If no argument is given, return whether or not list has callbacks attached.
  668. has: function (fn) {
  669. return fn ? jQuery.inArray(fn, list) > -1 : !!( list && list.length );
  670. },
  671. // Remove all callbacks from the list
  672. empty: function () {
  673. list = [];
  674. firingLength = 0;
  675. return this;
  676. },
  677. // Have the list do nothing anymore
  678. disable: function () {
  679. list = stack = memory = undefined;
  680. return this;
  681. },
  682. // Is it disabled?
  683. disabled: function () {
  684. return !list;
  685. },
  686. // Lock the list in its current state
  687. lock: function () {
  688. stack = undefined;
  689. if (!memory) {
  690. self.disable();
  691. }
  692. return this;
  693. },
  694. // Is it locked?
  695. locked: function () {
  696. return !stack;
  697. },
  698. // Call all callbacks with the given context and arguments
  699. fireWith: function (context, args) {
  700. if (list && ( !fired || stack )) {
  701. args = args || [];
  702. args = [context, args.slice ? args.slice() : args];
  703. if (firing) {
  704. stack.push(args);
  705. } else {
  706. fire(args);
  707. }
  708. }
  709. return this;
  710. },
  711. // Call all the callbacks with the given arguments
  712. fire: function () {
  713. self.fireWith(this, arguments);
  714. return this;
  715. },
  716. // To know if the callbacks have already been called at least once
  717. fired: function () {
  718. return !!fired;
  719. }
  720. };
  721. return self;
  722. };
  723. jQuery.extend({
  724. Deferred: function (func) {
  725. var tuples = [
  726. // action, add listener, listener list, final state
  727. ["resolve", "done", jQuery.Callbacks("once memory"), "resolved"],
  728. ["reject", "fail", jQuery.Callbacks("once memory"), "rejected"],
  729. ["notify", "progress", jQuery.Callbacks("memory")]
  730. ],
  731. state = "pending",
  732. promise = {
  733. state: function () {
  734. return state;
  735. },
  736. always: function () {
  737. deferred.done(arguments).fail(arguments);
  738. return this;
  739. },
  740. then: function (/* fnDone, fnFail, fnProgress */) {
  741. var fns = arguments;
  742. return jQuery.Deferred(function (newDefer) {
  743. jQuery.each(tuples, function (i, tuple) {
  744. var fn = jQuery.isFunction(fns[i]) && fns[i];
  745. // deferred[ done | fail | progress ] for forwarding actions to newDefer
  746. deferred[tuple[1]](function () {
  747. var returned = fn && fn.apply(this, arguments);
  748. if (returned && jQuery.isFunction(returned.promise)) {
  749. returned.promise()
  750. .done(newDefer.resolve)
  751. .fail(newDefer.reject)
  752. .progress(newDefer.notify);
  753. } else {
  754. newDefer[tuple[0] + "With"](this === promise ? newDefer.promise() : this, fn ? [returned] : arguments);
  755. }
  756. });
  757. });
  758. fns = null;
  759. }).promise();
  760. },
  761. // Get a promise for this deferred
  762. // If obj is provided, the promise aspect is added to the object
  763. promise: function (obj) {
  764. return obj != null ? jQuery.extend(obj, promise) : promise;
  765. }
  766. },
  767. deferred = {};
  768. // Keep pipe for back-compat
  769. promise.pipe = promise.then;
  770. // Add list-specific methods
  771. jQuery.each(tuples, function (i, tuple) {
  772. var list = tuple[2],
  773. stateString = tuple[3];
  774. // promise[ done | fail | progress ] = list.add
  775. promise[tuple[1]] = list.add;
  776. // Handle state
  777. if (stateString) {
  778. list.add(function () {
  779. // state = [ resolved | rejected ]
  780. state = stateString;
  781. // [ reject_list | resolve_list ].disable; progress_list.lock
  782. }, tuples[i ^ 1][2].disable, tuples[2][2].lock);
  783. }
  784. // deferred[ resolve | reject | notify ]
  785. deferred[tuple[0]] = function () {
  786. deferred[tuple[0] + "With"](this === deferred ? promise : this, arguments);
  787. return this;
  788. };
  789. deferred[tuple[0] + "With"] = list.fireWith;
  790. });
  791. // Make the deferred a promise
  792. promise.promise(deferred);
  793. // Call given func if any
  794. if (func) {
  795. func.call(deferred, deferred);
  796. }
  797. // All done!
  798. return deferred;
  799. },
  800. // Deferred helper
  801. when: function (subordinate /* , ..., subordinateN */) {
  802. var i = 0,
  803. resolveValues = slice.call(arguments),
  804. length = resolveValues.length,
  805. // the count of uncompleted subordinates
  806. remaining = length !== 1 || ( subordinate && jQuery.isFunction(subordinate.promise) ) ? length : 0,
  807. // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
  808. deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
  809. // Update function for both resolve and progress values
  810. updateFunc = function (i, contexts, values) {
  811. return function (value) {
  812. contexts[i] = this;
  813. values[i] = arguments.length > 1 ? slice.call(arguments) : value;
  814. if (values === progressValues) {
  815. deferred.notifyWith(contexts, values);
  816. } else if (!(--remaining)) {
  817. deferred.resolveWith(contexts, values);
  818. }
  819. };
  820. },
  821. progressValues, progressContexts, resolveContexts;
  822. // add listeners to Deferred subordinates; treat others as resolved
  823. if (length > 1) {
  824. progressValues = new Array(length);
  825. progressContexts = new Array(length);
  826. resolveContexts = new Array(length);
  827. for (; i < length; i++) {
  828. if (resolveValues[i] && jQuery.isFunction(resolveValues[i].promise)) {
  829. resolveValues[i].promise()
  830. .done(updateFunc(i, resolveContexts, resolveValues))
  831. .fail(deferred.reject)
  832. .progress(updateFunc(i, progressContexts, progressValues));
  833. } else {
  834. --remaining;
  835. }
  836. }
  837. }
  838. // if we're not waiting on anything, resolve the master
  839. if (!remaining) {
  840. deferred.resolveWith(resolveContexts, resolveValues);
  841. }
  842. return deferred.promise();
  843. }
  844. });
  845. // The deferred used on DOM ready
  846. var readyList;
  847. jQuery.fn.ready = function (fn) {
  848. // Add the callback
  849. jQuery.ready.promise().done(fn);
  850. return this;
  851. };
  852. jQuery.extend({
  853. // Is the DOM ready to be used? Set to true once it occurs.
  854. isReady: false,
  855. // A counter to track how many items to wait for before
  856. // the ready event fires. See #6781
  857. readyWait: 1,
  858. // Hold (or release) the ready event
  859. holdReady: function (hold) {
  860. if (hold) {
  861. jQuery.readyWait++;
  862. } else {
  863. jQuery.ready(true);
  864. }
  865. },
  866. // Handle when the DOM is ready
  867. ready: function (wait) {
  868. // Abort if there are pending holds or we're already ready
  869. if (wait === true ? --jQuery.readyWait : jQuery.isReady) {
  870. return;
  871. }
  872. // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
  873. if (!document.body) {
  874. return setTimeout(jQuery.ready);
  875. }
  876. // Remember that the DOM is ready
  877. jQuery.isReady = true;
  878. // If a normal DOM Ready event fired, decrement, and wait if need be
  879. if (wait !== true && --jQuery.readyWait > 0) {
  880. return;
  881. }
  882. // If there are functions bound, to execute
  883. readyList.resolveWith(document, [jQuery]);
  884. // Trigger any bound ready events
  885. if (jQuery.fn.triggerHandler) {
  886. jQuery(document).triggerHandler("ready");
  887. jQuery(document).off("ready");
  888. }
  889. }
  890. });
  891. /**
  892. * Clean-up method for dom ready events
  893. */
  894. function detach() {
  895. if (document.addEventListener) {
  896. document.removeEventListener("DOMContentLoaded", completed, false);
  897. window.removeEventListener("load", completed, false);
  898. } else {
  899. document.detachEvent("onreadystatechange", completed);
  900. window.detachEvent("onload", completed);
  901. }
  902. }
  903. /**
  904. * The ready event handler and self cleanup method
  905. */
  906. function completed() {
  907. // readyState === "complete" is good enough for us to call the dom ready in oldIE
  908. if (document.addEventListener || event.type === "load" || document.readyState === "complete") {
  909. detach();
  910. jQuery.ready();
  911. }
  912. }
  913. jQuery.ready.promise = function (obj) {
  914. if (!readyList) {
  915. readyList = jQuery.Deferred();
  916. // Catch cases where $(document).ready() is called after the browser event has already occurred.
  917. // we once tried to use readyState "interactive" here, but it caused issues like the one
  918. // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
  919. if (document.readyState === "complete") {
  920. // Handle it asynchronously to allow scripts the opportunity to delay ready
  921. setTimeout(jQuery.ready);
  922. // Standards-based browsers support DOMContentLoaded
  923. } else if (document.addEventListener) {
  924. // Use the handy event callback
  925. document.addEventListener("DOMContentLoaded", completed, false);
  926. // A fallback to window.onload, that will always work
  927. window.addEventListener("load", completed, false);
  928. // If IE event model is used
  929. } else {
  930. // Ensure firing before onload, maybe late but safe also for iframes
  931. document.attachEvent("onreadystatechange", completed);
  932. // A fallback to window.onload, that will always work
  933. window.attachEvent("onload", completed);
  934. // If IE and not a frame
  935. // continually check to see if the document is ready
  936. var top = false;
  937. try {
  938. top = window.frameElement == null && document.documentElement;
  939. } catch (e) {
  940. }
  941. if (top && top.doScroll) {
  942. (function doScrollCheck() {
  943. if (!jQuery.isReady) {
  944. try {
  945. // Use the trick by Diego Perini
  946. // http://javascript.nwbox.com/IEContentLoaded/
  947. top.doScroll("left");
  948. } catch (e) {
  949. return setTimeout(doScrollCheck, 50);
  950. }
  951. // detach all dom ready events
  952. detach();
  953. // and execute any waiting functions
  954. jQuery.ready();
  955. }
  956. })();
  957. }
  958. }
  959. }
  960. return readyList.promise(obj);
  961. };
  962. var strundefined = typeof undefined;
  963. // Support: IE<9
  964. // Iteration over object's inherited properties before its own
  965. var i;
  966. for (i in jQuery(support)) {
  967. break;
  968. }
  969. support.ownLast = i !== "0";
  970. // Note: most support tests are defined in their respective modules.
  971. // false until the test is run
  972. support.inlineBlockNeedsLayout = false;
  973. // Execute ASAP in case we need to set body.style.zoom
  974. jQuery(function () {
  975. // Minified: var a,b,c,d
  976. var val, div, body, container;
  977. body = document.getElementsByTagName("body")[0];
  978. if (!body || !body.style) {
  979. // Return for frameset docs that don't have a body
  980. return;
  981. }
  982. // Setup
  983. div = document.createElement("div");
  984. container = document.createElement("div");
  985. container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
  986. body.appendChild(container).appendChild(div);
  987. if (typeof div.style.zoom !== strundefined) {
  988. // Support: IE<8
  989. // Check if natively block-level elements act like inline-block
  990. // elements when setting their display to 'inline' and giving
  991. // them layout
  992. div.style.cssText = "display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1";
  993. support.inlineBlockNeedsLayout = val = div.offsetWidth === 3;
  994. if (val) {
  995. // Prevent IE 6 from affecting layout for positioned elements #11048
  996. // Prevent IE from shrinking the body in IE 7 mode #12869
  997. // Support: IE<8
  998. body.style.zoom = 1;
  999. }
  1000. }
  1001. body.removeChild(container);
  1002. });
  1003. (function () {
  1004. var div = document.createElement("div");
  1005. // Execute the test only if not already executed in another module.
  1006. if (support.deleteExpando == null) {
  1007. // Support: IE<9
  1008. support.deleteExpando = true;
  1009. try {
  1010. delete div.test;
  1011. } catch (e) {
  1012. support.deleteExpando = false;
  1013. }
  1014. }
  1015. // Null elements to avoid leaks in IE.
  1016. div = null;
  1017. })();
  1018. /**
  1019. * Determines whether an object can have data
  1020. */
  1021. jQuery.acceptData = function (elem) {
  1022. var noData = jQuery.noData[(elem.nodeName + " ").toLowerCase()],
  1023. nodeType = +elem.nodeType || 1;
  1024. // Do not set data on non-element DOM nodes because it will not be cleared (#8335).
  1025. return nodeType !== 1 && nodeType !== 9 ?
  1026. false :
  1027. // Nodes accept data unless otherwise specified; rejection can be conditional
  1028. !noData || noData !== true && elem.getAttribute("classid") === noData;
  1029. };
  1030. var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
  1031. rmultiDash = /([A-Z])/g;
  1032. function dataAttr(elem, key, data) {
  1033. // If nothing was found internally, try to fetch any
  1034. // data from the HTML5 data-* attribute
  1035. if (data === undefined && elem.nodeType === 1) {
  1036. var name = "data-" + key.replace(rmultiDash, "-$1").toLowerCase();
  1037. data = elem.getAttribute(name);
  1038. if (typeof data === "string") {
  1039. try {
  1040. data = data === "true" ? true :
  1041. data === "false" ? false :
  1042. data === "null" ? null :
  1043. // Only convert to a number if it doesn't change the string
  1044. +data + "" === data ? +data :
  1045. rbrace.test(data) ? jQuery.parseJSON(data) :
  1046. data;
  1047. } catch (e) {
  1048. }
  1049. // Make sure we set the data so it isn't changed later
  1050. jQuery.data(elem, key, data);
  1051. } else {
  1052. data = undefined;
  1053. }
  1054. }
  1055. return data;
  1056. }
  1057. // checks a cache object for emptiness
  1058. function isEmptyDataObject(obj) {
  1059. var name;
  1060. for (name in obj) {
  1061. // if the public data object is empty, the private is still empty
  1062. if (name === "data" && jQuery.isEmptyObject(obj[name])) {
  1063. continue;
  1064. }
  1065. if (name !== "toJSON") {
  1066. return false;
  1067. }
  1068. }
  1069. return true;
  1070. }
  1071. function internalData(elem, name, data, pvt /* Internal Use Only */) {
  1072. if (!jQuery.acceptData(elem)) {
  1073. return;
  1074. }
  1075. var ret, thisCache,
  1076. internalKey = jQuery.expando,
  1077. // We have to handle DOM nodes and JS objects differently because IE6-7
  1078. // can't GC object references properly across the DOM-JS boundary
  1079. isNode = elem.nodeType,
  1080. // Only DOM nodes need the global jQuery cache; JS object data is
  1081. // attached directly to the object so GC can occur automatically
  1082. cache = isNode ? jQuery.cache : elem,
  1083. // Only defining an ID for JS objects if its cache already exists allows
  1084. // the code to shortcut on the same path as a DOM node with no cache
  1085. id = isNode ? elem[internalKey] : elem[internalKey] && internalKey;
  1086. // Avoid doing any more work than we need to when trying to get data on an
  1087. // object that has no data at all
  1088. if ((!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string") {
  1089. return;
  1090. }
  1091. if (!id) {
  1092. // Only DOM nodes need a new unique ID for each element since their data
  1093. // ends up in the global cache
  1094. if (isNode) {
  1095. id = elem[internalKey] = deletedIds.pop() || jQuery.guid++;
  1096. } else {
  1097. id = internalKey;
  1098. }
  1099. }
  1100. if (!cache[id]) {
  1101. // Avoid exposing jQuery metadata on plain JS objects when the object
  1102. // is serialized using JSON.stringify
  1103. cache[id] = isNode ? {} : {toJSON: jQuery.noop};
  1104. }
  1105. // An object can be passed to jQuery.data instead of a key/value pair; this gets
  1106. // shallow copied over onto the existing cache
  1107. if (typeof name === "object" || typeof name === "function") {
  1108. if (pvt) {
  1109. cache[id] = jQuery.extend(cache[id], name);
  1110. } else {
  1111. cache[id].data = jQuery.extend(cache[id].data, name);
  1112. }
  1113. }
  1114. thisCache = cache[id];
  1115. // jQuery data() is stored in a separate object inside the object's internal data
  1116. // cache in order to avoid key collisions between internal data and user-defined
  1117. // data.
  1118. if (!pvt) {
  1119. if (!thisCache.data) {
  1120. thisCache.data = {};
  1121. }
  1122. thisCache = thisCache.data;
  1123. }
  1124. if (data !== undefined) {
  1125. thisCache[jQuery.camelCase(name)] = data;
  1126. }
  1127. // Check for both converted-to-camel and non-converted data property names
  1128. // If a data property was specified
  1129. if (typeof name === "string") {
  1130. // First Try to find as-is property data
  1131. ret = thisCache[name];
  1132. // Test for null|undefined property data
  1133. if (ret == null) {
  1134. // Try to find the camelCased property
  1135. ret = thisCache[jQuery.camelCase(name)];
  1136. }
  1137. } else {
  1138. ret = thisCache;
  1139. }
  1140. return ret;
  1141. }
  1142. function internalRemoveData(elem, name, pvt) {
  1143. if (!jQuery.acceptData(elem)) {
  1144. return;
  1145. }
  1146. var thisCache, i,
  1147. isNode = elem.nodeType,
  1148. // See jQuery.data for more information
  1149. cache = isNode ? jQuery.cache : elem,
  1150. id = isNode ? elem[jQuery.expando] : jQuery.expando;
  1151. // If there is already no cache entry for this object, there is no
  1152. // purpose in continuing
  1153. if (!cache[id]) {
  1154. return;
  1155. }
  1156. if (name) {
  1157. thisCache = pvt ? cache[id] : cache[id].data;
  1158. if (thisCache) {
  1159. // Support array or space separated string names for data keys
  1160. if (!jQuery.isArray(name)) {
  1161. // try the string as a key before any manipulation
  1162. if (name in thisCache) {
  1163. name = [name];
  1164. } else {
  1165. // split the camel cased version by spaces unless a key with the spaces exists
  1166. name = jQuery.camelCase(name);
  1167. if (name in thisCache) {
  1168. name = [name];
  1169. } else {
  1170. name = name.split(" ");
  1171. }
  1172. }
  1173. } else {
  1174. // If "name" is an array of keys...
  1175. // When data is initially created, via ("key", "val") signature,
  1176. // keys will be converted to camelCase.
  1177. // Since there is no way to tell _how_ a key was added, remove
  1178. // both plain key and camelCase key. #12786
  1179. // This will only penalize the array argument path.
  1180. name = name.concat(jQuery.map(name, jQuery.camelCase));
  1181. }
  1182. i = name.length;
  1183. while (i--) {
  1184. delete thisCache[name[i]];
  1185. }
  1186. // If there is no data left in the cache, we want to continue
  1187. // and let the cache object itself get destroyed
  1188. if (pvt ? !isEmptyDataObject(thisCache) : !jQuery.isEmptyObject(thisCache)) {
  1189. return;
  1190. }
  1191. }
  1192. }
  1193. // See jQuery.data for more information
  1194. if (!pvt) {
  1195. delete cache[id].data;
  1196. // Don't destroy the parent cache unless the internal data object
  1197. // had been the only thing left in it
  1198. if (!isEmptyDataObject(cache[id])) {
  1199. return;
  1200. }
  1201. }
  1202. // Destroy the cache
  1203. if (isNode) {
  1204. jQuery.cleanData([elem], true);
  1205. // Use delete when supported for expandos or `cache` is not a window per isWindow (#10080)
  1206. /* jshint eqeqeq: false */
  1207. } else if (support.deleteExpando || cache != cache.window) {
  1208. /* jshint eqeqeq: true */
  1209. delete cache[id];
  1210. // When all else fails, null
  1211. } else {
  1212. cache[id] = null;
  1213. }
  1214. }
  1215. jQuery.extend({
  1216. cache: {},
  1217. // The following elements (space-suffixed to avoid Object.prototype collisions)
  1218. // throw uncatchable exceptions if you attempt to set expando properties
  1219. noData: {
  1220. "applet ": true,
  1221. "embed ": true,
  1222. // ...but Flash objects (which have this classid) *can* handle expandos
  1223. "object ": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  1224. },
  1225. hasData: function (elem) {
  1226. elem = elem.nodeType ? jQuery.cache[elem[jQuery.expando]] : elem[jQuery.expando];
  1227. return !!elem && !isEmptyDataObject(elem);
  1228. },
  1229. data: function (elem, name, data) {
  1230. return internalData(elem, name, data);
  1231. },
  1232. removeData: function (elem, name) {
  1233. return internalRemoveData(elem, name);
  1234. },
  1235. // For internal use only.
  1236. _data: function (elem, name, data) {
  1237. return internalData(elem, name, data, true);
  1238. },
  1239. _removeData: function (elem, name) {
  1240. return internalRemoveData(elem, name, true);
  1241. }
  1242. });
  1243. jQuery.fn.extend({
  1244. data: function (key, value) {
  1245. var i, name, data,
  1246. elem = this[0],
  1247. attrs = elem && elem.attributes;
  1248. // Special expections of .data basically thwart jQuery.access,
  1249. // so implement the relevant behavior ourselves
  1250. // Gets all values
  1251. if (key === undefined) {
  1252. if (this.length) {
  1253. data = jQuery.data(elem);
  1254. if (elem.nodeType === 1 && !jQuery._data(elem, "parsedAttrs")) {
  1255. i = attrs.length;
  1256. while (i--) {
  1257. // Support: IE11+
  1258. // The attrs elements can be null (#14894)
  1259. if (attrs[i]) {
  1260. name = attrs[i].name;
  1261. if (name.indexOf("data-") === 0) {
  1262. name = jQuery.camelCase(name.slice(5));
  1263. dataAttr(elem, name, data[name]);
  1264. }
  1265. }
  1266. }
  1267. jQuery._data(elem, "parsedAttrs", true);
  1268. }
  1269. }
  1270. return data;
  1271. }
  1272. // Sets multiple values
  1273. if (typeof key === "object") {
  1274. return this.each(function () {
  1275. jQuery.data(this, key);
  1276. });
  1277. }
  1278. return arguments.length > 1 ?
  1279. // Sets one value
  1280. this.each(function () {
  1281. jQuery.data(this, key, value);
  1282. }) :
  1283. // Gets one value
  1284. // Try to fetch any internally stored data first
  1285. elem ? dataAttr(elem, key, jQuery.data(elem, key)) : undefined;
  1286. },
  1287. removeData: function (key) {
  1288. return this.each(function () {
  1289. jQuery.removeData(this, key);
  1290. });
  1291. }
  1292. });
  1293. jQuery.extend({
  1294. queue: function (elem, type, data) {
  1295. var queue;
  1296. if (elem) {
  1297. type = ( type || "fx" ) + "queue";
  1298. queue = jQuery._data(elem, type);
  1299. // Speed up dequeue by getting out quickly if this is just a lookup
  1300. if (data) {
  1301. if (!queue || jQuery.isArray(data)) {
  1302. queue = jQuery._data(elem, type, jQuery.makeArray(data));
  1303. } else {
  1304. queue.push(data);
  1305. }
  1306. }
  1307. return queue || [];
  1308. }
  1309. },
  1310. dequeue: function (elem, type) {
  1311. type = type || "fx";
  1312. var queue = jQuery.queue(elem, type),
  1313. startLength = queue.length,
  1314. fn = queue.shift(),
  1315. hooks = jQuery._queueHooks(elem, type),
  1316. next = function () {
  1317. jQuery.dequeue(elem, type);
  1318. };
  1319. // If the fx queue is dequeued, always remove the progress sentinel
  1320. if (fn === "inprogress") {
  1321. fn = queue.shift();
  1322. startLength--;
  1323. }
  1324. if (fn) {
  1325. // Add a progress sentinel to prevent the fx queue from being
  1326. // automatically dequeued
  1327. if (type === "fx") {
  1328. queue.unshift("inprogress");
  1329. }
  1330. // clear up the last queue stop function
  1331. delete hooks.stop;
  1332. fn.call(elem, next, hooks);
  1333. }
  1334. if (!startLength && hooks) {
  1335. hooks.empty.fire();
  1336. }
  1337. },
  1338. // not intended for public consumption - generates a queueHooks object, or returns the current one
  1339. _queueHooks: function (elem, type) {
  1340. var key = type + "queueHooks";
  1341. return jQuery._data(elem, key) || jQuery._data(elem, key, {
  1342. empty: jQuery.Callbacks("once memory").add(function () {
  1343. jQuery._removeData(elem, type + "queue");
  1344. jQuery._removeData(elem, key);
  1345. })
  1346. });
  1347. }
  1348. });
  1349. jQuery.fn.extend({
  1350. queue: function (type, data) {
  1351. var setter = 2;
  1352. if (typeof type !== "string") {
  1353. data = type;
  1354. type = "fx";
  1355. setter--;
  1356. }
  1357. if (arguments.length < setter) {
  1358. return jQuery.queue(this[0], type);
  1359. }
  1360. return data === undefined ?
  1361. this :
  1362. this.each(function () {
  1363. var queue = jQuery.queue(this, type, data);
  1364. // ensure a hooks for this queue
  1365. jQuery._queueHooks(this, type);
  1366. if (type === "fx" && queue[0] !== "inprogress") {
  1367. jQuery.dequeue(this, type);
  1368. }
  1369. });
  1370. },
  1371. dequeue: function (type) {
  1372. return this.each(function () {
  1373. jQuery.dequeue(this, type);
  1374. });
  1375. },
  1376. clearQueue: function (type) {
  1377. return this.queue(type || "fx", []);
  1378. },
  1379. // Get a promise resolved when queues of a certain type
  1380. // are emptied (fx is the type by default)
  1381. promise: function (type, obj) {
  1382. var tmp,
  1383. count = 1,
  1384. defer = jQuery.Deferred(),
  1385. elements = this,
  1386. i = this.length,
  1387. resolve = function () {
  1388. if (!( --count )) {
  1389. defer.resolveWith(elements, [elements]);
  1390. }
  1391. };
  1392. if (typeof type !== "string") {
  1393. obj = type;
  1394. type = undefined;
  1395. }
  1396. type = type || "fx";
  1397. while (i--) {
  1398. tmp = jQuery._data(elements[i], type + "queueHooks");
  1399. if (tmp && tmp.empty) {
  1400. count++;
  1401. tmp.empty.add(resolve);
  1402. }
  1403. }
  1404. resolve();
  1405. return defer.promise(obj);
  1406. }
  1407. });
  1408. /*
  1409. * Helper functions for managing events -- not part of the public interface.
  1410. * Props to Dean Edwards' addEvent library for many of the ideas.
  1411. */
  1412. jQuery.event = {
  1413. global: {},
  1414. add: function (elem, types, handler, data, selector) {
  1415. var tmp, events, t, handleObjIn,
  1416. special, eventHandle, handleObj,
  1417. handlers, type, namespaces, origType,
  1418. elemData = jQuery._data(elem);
  1419. // Don't attach events to noData or text/comment nodes (but allow plain objects)
  1420. if (!elemData) {
  1421. return;
  1422. }
  1423. // Caller can pass in an object of custom data in lieu of the handler
  1424. if (handler.handler) {
  1425. handleObjIn = handler;
  1426. handler = handleObjIn.handler;
  1427. selector = handleObjIn.selector;
  1428. }
  1429. // Make sure that the handler has a unique ID, used to find/remove it later
  1430. if (!handler.guid) {
  1431. handler.guid = jQuery.guid++;
  1432. }
  1433. // Init the element's event structure and main handler, if this is the first
  1434. if (!(events = elemData.events)) {
  1435. events = elemData.events = {};
  1436. }
  1437. if (!(eventHandle = elemData.handle)) {
  1438. eventHandle = elemData.handle = function (e) {
  1439. // Discard the second event of a jQuery.event.trigger() and
  1440. // when an event is called after a page has unloaded
  1441. return typeof jQuery !== strundefined && (!e || jQuery.event.triggered !== e.type) ?
  1442. jQuery.event.dispatch.apply(eventHandle.elem, arguments) :
  1443. undefined;
  1444. };
  1445. // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events
  1446. eventHandle.elem = elem;
  1447. }
  1448. // Handle multiple events separated by a space
  1449. types = ( types || "" ).match(rnotwhite) || [""];
  1450. t = types.length;
  1451. while (t--) {
  1452. tmp = rtypenamespace.exec(types[t]) || [];
  1453. type = origType = tmp[1];
  1454. namespaces = ( tmp[2] || "" ).split(".").sort();
  1455. // There *must* be a type, no attaching namespace-only handlers
  1456. if (!type) {
  1457. continue;
  1458. }
  1459. // If event changes its type, use the special event handlers for the changed type
  1460. special = jQuery.event.special[type] || {};
  1461. // If selector defined, determine special event api type, otherwise given type
  1462. type = ( selector ? special.delegateType : special.bindType ) || type;
  1463. // Update special based on newly reset type
  1464. special = jQuery.event.special[type] || {};
  1465. // handleObj is passed to all event handlers
  1466. handleObj = jQuery.extend({
  1467. type: type,
  1468. origType: origType,
  1469. data: data,
  1470. handler: handler,
  1471. guid: handler.guid,
  1472. selector: selector,
  1473. needsContext: selector && jQuery.expr.match.needsContext.test(selector),
  1474. namespace: namespaces.join(".")
  1475. }, handleObjIn);
  1476. // Init the event handler queue if we're the first
  1477. if (!(handlers = events[type])) {
  1478. handlers = events[type] = [];
  1479. handlers.delegateCount = 0;
  1480. // Only use addEventListener/attachEvent if the special events handler returns false
  1481. if (!special.setup || special.setup.call(elem, data, namespaces, eventHandle) === false) {
  1482. // Bind the global event handler to the element
  1483. if (elem.addEventListener) {
  1484. elem.addEventListener(type, eventHandle, false);
  1485. } else if (elem.attachEvent) {
  1486. elem.attachEvent("on" + type, eventHandle);
  1487. }
  1488. }
  1489. }
  1490. if (special.add) {
  1491. special.add.call(elem, handleObj);
  1492. if (!handleObj.handler.guid) {
  1493. handleObj.handler.guid = handler.guid;
  1494. }
  1495. }
  1496. // Add to the element's handler list, delegates in front
  1497. if (selector) {
  1498. handlers.splice(handlers.delegateCount++, 0, handleObj);
  1499. } else {
  1500. handlers.push(handleObj);
  1501. }
  1502. // Keep track of which events have ever been used, for event optimization
  1503. jQuery.event.global[type] = true;
  1504. }
  1505. // Nullify elem to prevent memory leaks in IE
  1506. elem = null;
  1507. },
  1508. // Detach an event or set of events from an element
  1509. remove: function (elem, types, handler, selector, mappedTypes) {
  1510. var j, handleObj, tmp,
  1511. origCount, t, events,
  1512. special, handlers, type,
  1513. namespaces, origType,
  1514. elemData = jQuery.hasData(elem) && jQuery._data(elem);
  1515. if (!elemData || !(events = elemData.events)) {
  1516. return;
  1517. }
  1518. // Once for each type.namespace in types; type may be omitted
  1519. types = ( types || "" ).match(rnotwhite) || [""];
  1520. t = types.length;
  1521. while (t--) {
  1522. tmp = rtypenamespace.exec(types[t]) || [];
  1523. type = origType = tmp[1];
  1524. namespaces = ( tmp[2] || "" ).split(".").sort();
  1525. // Unbind all events (on this namespace, if provided) for the element
  1526. if (!type) {
  1527. for (type in events) {
  1528. jQuery.event.remove(elem, type + types[t], handler, selector, true);
  1529. }
  1530. continue;
  1531. }
  1532. special = jQuery.event.special[type] || {};
  1533. type = ( selector ? special.delegateType : special.bindType ) || type;
  1534. handlers = events[type] || [];
  1535. tmp = tmp[2] && new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)");
  1536. // Remove matching events
  1537. origCount = j = handlers.length;
  1538. while (j--) {
  1539. handleObj = handlers[j];
  1540. if (( mappedTypes || origType === handleObj.origType ) &&
  1541. ( !handler || handler.guid === handleObj.guid ) &&
  1542. ( !tmp || tmp.test(handleObj.namespace) ) &&
  1543. ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector )) {
  1544. handlers.splice(j, 1);
  1545. if (handleObj.selector) {
  1546. handlers.delegateCount--;
  1547. }
  1548. if (special.remove) {
  1549. special.remove.call(elem, handleObj);
  1550. }
  1551. }
  1552. }
  1553. // Remove generic event handler if we removed something and no more handlers exist
  1554. // (avoids potential for endless recursion during removal of special event handlers)
  1555. if (origCount && !handlers.length) {
  1556. if (!special.teardown || special.teardown.call(elem, namespaces, elemData.handle) === false) {
  1557. jQuery.removeEvent(elem, type, elemData.handle);
  1558. }
  1559. delete events[type];
  1560. }
  1561. }
  1562. // Remove the expando if it's no longer used
  1563. if (jQuery.isEmptyObject(events)) {
  1564. delete elemData.handle;
  1565. // removeData also checks for emptiness and clears the expando if empty
  1566. // so use it instead of delete
  1567. jQuery._removeData(elem, "events");
  1568. }
  1569. },
  1570. trigger: function (event, data, elem, onlyHandlers) {
  1571. var handle, ontype, cur,
  1572. bubbleType, special, tmp, i,
  1573. eventPath = [elem || document],
  1574. type = hasOwn.call(event, "type") ? event.type : event,
  1575. namespaces = hasOwn.call(event, "namespace") ? event.namespace.split(".") : [];
  1576. cur = tmp = elem = elem || document;
  1577. // Don't do events on text and comment nodes
  1578. if (elem.nodeType === 3 || elem.nodeType === 8) {
  1579. return;
  1580. }
  1581. // focus/blur morphs to focusin/out; ensure we're not firing them right now
  1582. if (rfocusMorph.test(type + jQuery.event.triggered)) {
  1583. return;
  1584. }
  1585. if (type.indexOf(".") >= 0) {
  1586. // Namespaced trigger; create a regexp to match event type in handle()
  1587. namespaces = type.split(".");
  1588. type = namespaces.shift();
  1589. namespaces.sort();
  1590. }
  1591. ontype = type.indexOf(":") < 0 && "on" + type;
  1592. // Caller can pass in a jQuery.Event object, Object, or just an event type string
  1593. event = event[jQuery.expando] ?
  1594. event :
  1595. new jQuery.Event(type, typeof event === "object" && event);
  1596. // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
  1597. event.isTrigger = onlyHandlers ? 2 : 3;
  1598. event.namespace = namespaces.join(".");
  1599. event.namespace_re = event.namespace ?
  1600. new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)") :
  1601. null;
  1602. // Clean up the event in case it is being reused
  1603. event.result = undefined;
  1604. if (!event.target) {
  1605. event.target = elem;
  1606. }
  1607. // Clone any incoming data and prepend the event, creating the handler arg list
  1608. data = data == null ?
  1609. [event] :
  1610. jQuery.makeArray(data, [event]);
  1611. // Allow special events to draw outside the lines
  1612. special = jQuery.event.special[type] || {};
  1613. if (!onlyHandlers && special.trigger && special.trigger.apply(elem, data) === false) {
  1614. return;
  1615. }
  1616. // Determine event propagation path in advance, per W3C events spec (#9951)
  1617. // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
  1618. if (!onlyHandlers && !special.noBubble && !jQuery.isWindow(elem)) {
  1619. bubbleType = special.delegateType || type;
  1620. if (!rfocusMorph.test(bubbleType + type)) {
  1621. cur = cur.parentNode;
  1622. }
  1623. for (; cur; cur = cur.parentNode) {
  1624. eventPath.push(cur);
  1625. tmp = cur;
  1626. }
  1627. // Only add window if we got to document (e.g., not plain obj or detached DOM)
  1628. if (tmp === (elem.ownerDocument || document)) {
  1629. eventPath.push(tmp.defaultView || tmp.parentWindow || window);
  1630. }
  1631. }
  1632. // Fire handlers on the event path
  1633. i = 0;
  1634. while ((cur = eventPath[i++]) && !event.isPropagationStopped()) {
  1635. event.type = i > 1 ?
  1636. bubbleType :
  1637. special.bindType || type;
  1638. // jQuery handler
  1639. handle = ( jQuery._data(cur, "events") || {} )[event.type] && jQuery._data(cur, "handle");
  1640. if (handle) {
  1641. handle.apply(cur, data);
  1642. }
  1643. // Native handler
  1644. handle = ontype && cur[ontype];
  1645. if (handle && handle.apply && jQuery.acceptData(cur)) {
  1646. event.result = handle.apply(cur, data);
  1647. if (event.result === false) {
  1648. event.preventDefault();
  1649. }
  1650. }
  1651. }
  1652. event.type = type;
  1653. // If nobody prevented the default action, do it now
  1654. if (!onlyHandlers && !event.isDefaultPrevented()) {
  1655. if ((!special._default || special._default.apply(eventPath.pop(), data) === false) &&
  1656. jQuery.acceptData(elem)) {
  1657. // Call a native DOM method on the target with the same name name as the event.
  1658. // Can't use an .isFunction() check here because IE6/7 fails that test.
  1659. // Don't do default actions on window, that's where global variables be (#6170)
  1660. if (ontype && elem[type] && !jQuery.isWindow(elem)) {
  1661. // Don't re-trigger an onFOO event when we call its FOO() method
  1662. tmp = elem[ontype];
  1663. if (tmp) {
  1664. elem[ontype] = null;
  1665. }
  1666. // Prevent re-triggering of the same event, since we already bubbled it above
  1667. jQuery.event.triggered = type;
  1668. try {
  1669. elem[type]();
  1670. } catch (e) {
  1671. // IE<9 dies on focus/blur to hidden element (#1486,#12518)
  1672. // only reproducible on winXP IE8 native, not IE9 in IE8 mode
  1673. }
  1674. jQuery.event.triggered = undefined;
  1675. if (tmp) {
  1676. elem[ontype] = tmp;
  1677. }
  1678. }
  1679. }
  1680. }
  1681. return event.result;
  1682. },
  1683. dispatch: function (event) {
  1684. // Make a writable jQuery.Event from the native event object
  1685. event = jQuery.event.fix(event);
  1686. var i, ret, handleObj, matched, j,
  1687. handlerQueue = [],
  1688. args = slice.call(arguments),
  1689. handlers = ( jQuery._data(this, "events") || {} )[event.type] || [],
  1690. special = jQuery.event.special[event.type] || {};
  1691. // Use the fix-ed jQuery.Event rather than the (read-only) native event
  1692. args[0] = event;
  1693. event.delegateTarget = this;
  1694. // Call the preDispatch hook for the mapped type, and let it bail if desired
  1695. if (special.preDispatch && special.preDispatch.call(this, event) === false) {
  1696. return;
  1697. }
  1698. // Determine handlers
  1699. handlerQueue = jQuery.event.handlers.call(this, event, handlers);
  1700. // Run delegates first; they may want to stop propagation beneath us
  1701. i = 0;
  1702. while ((matched = handlerQueue[i++]) && !event.isPropagationStopped()) {
  1703. event.currentTarget = matched.elem;
  1704. j = 0;
  1705. while ((handleObj = matched.handlers[j++]) && !event.isImmediatePropagationStopped()) {
  1706. // Triggered event must either 1) have no namespace, or
  1707. // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
  1708. if (!event.namespace_re || event.namespace_re.test(handleObj.namespace)) {
  1709. event.handleObj = handleObj;
  1710. event.data = handleObj.data;
  1711. ret = ( (jQuery.event.special[handleObj.origType] || {}).handle || handleObj.handler )
  1712. .apply(matched.elem, args);
  1713. if (ret !== undefined) {
  1714. if ((event.result = ret) === false) {
  1715. event.preventDefault();
  1716. event.stopPropagation();
  1717. }
  1718. }
  1719. }
  1720. }
  1721. }
  1722. // Call the postDispatch hook for the mapped type
  1723. if (special.postDispatch) {
  1724. special.postDispatch.call(this, event);
  1725. }
  1726. return event.result;
  1727. },
  1728. handlers: function (event, handlers) {
  1729. var sel, handleObj, matches, i,
  1730. handlerQueue = [],
  1731. delegateCount = handlers.delegateCount,
  1732. cur = event.target;
  1733. // Find delegate handlers
  1734. // Black-hole SVG <use> instance trees (#13180)
  1735. // Avoid non-left-click bubbling in Firefox (#3861)
  1736. if (delegateCount && cur.nodeType && (!event.button || event.type !== "click")) {
  1737. /* jshint eqeqeq: false */
  1738. for (; cur != this; cur = cur.parentNode || this) {
  1739. /* jshint eqeqeq: true */
  1740. // Don't check non-elements (#13208)
  1741. // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
  1742. if (cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click")) {
  1743. matches = [];
  1744. for (i = 0; i < delegateCount; i++) {
  1745. handleObj = handlers[i];
  1746. // Don't conflict with Object.prototype properties (#13203)
  1747. sel = handleObj.selector + " ";
  1748. if (matches[sel] === undefined) {
  1749. matches[sel] = handleObj.needsContext ?
  1750. jQuery(sel, this).index(cur) >= 0 :
  1751. jQuery.find(sel, this, null, [cur]).length;
  1752. }
  1753. if (matches[sel]) {
  1754. matches.push(handleObj);
  1755. }
  1756. }
  1757. if (matches.length) {
  1758. handlerQueue.push({elem: cur, handlers: matches});
  1759. }
  1760. }
  1761. }
  1762. }
  1763. // Add the remaining (directly-bound) handlers
  1764. if (delegateCount < handlers.length) {
  1765. handlerQueue.push({elem: this, handlers: handlers.slice(delegateCount)});
  1766. }
  1767. return handlerQueue;
  1768. },
  1769. fix: function (event) {
  1770. if (event[jQuery.expando]) {
  1771. return event;
  1772. }
  1773. // Create a writable copy of the event object and normalize some properties
  1774. var i, prop, copy,
  1775. type = event.type,
  1776. originalEvent = event,
  1777. fixHook = this.fixHooks[type];
  1778. if (!fixHook) {
  1779. this.fixHooks[type] = fixHook =
  1780. rmouseEvent.test(type) ? this.mouseHooks :
  1781. rkeyEvent.test(type) ? this.keyHooks :
  1782. {};
  1783. }
  1784. copy = fixHook.props ? this.props.concat(fixHook.props) : this.props;
  1785. event = new jQuery.Event(originalEvent);
  1786. i = copy.length;
  1787. while (i--) {
  1788. prop = copy[i];
  1789. event[prop] = originalEvent[prop];
  1790. }
  1791. // Support: IE<9
  1792. // Fix target property (#1925)
  1793. if (!event.target) {
  1794. event.target = originalEvent.srcElement || document;
  1795. }
  1796. // Support: Chrome 23+, Safari?
  1797. // Target should not be a text node (#504, #13143)
  1798. if (event.target.nodeType === 3) {
  1799. event.target = event.target.parentNode;
  1800. }
  1801. // Support: IE<9
  1802. // For mouse/key events, metaKey==false if it's undefined (#3368, #11328)
  1803. event.metaKey = !!event.metaKey;
  1804. return fixHook.filter ? fixHook.filter(event, originalEvent) : event;
  1805. },
  1806. // Includes some event props shared by KeyEvent and MouseEvent
  1807. props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
  1808. fixHooks: {},
  1809. keyHooks: {
  1810. props: "char charCode key keyCode".split(" "),
  1811. filter: function (event, original) {
  1812. // Add which for key events
  1813. if (event.which == null) {
  1814. event.which = original.charCode != null ? original.charCode : original.keyCode;
  1815. }
  1816. return event;
  1817. }
  1818. },
  1819. mouseHooks: {
  1820. props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
  1821. filter: function (event, original) {
  1822. var body, eventDoc, doc,
  1823. button = original.button,
  1824. fromElement = original.fromElement;
  1825. // Calculate pageX/Y if missing and clientX/Y available
  1826. if (event.pageX == null && original.clientX != null) {
  1827. eventDoc = event.target.ownerDocument || document;
  1828. doc = eventDoc.documentElement;
  1829. body = eventDoc.body;
  1830. event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
  1831. event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
  1832. }
  1833. // Add relatedTarget, if necessary
  1834. if (!event.relatedTarget && fromElement) {
  1835. event.relatedTarget = fromElement === event.target ? original.toElement : fromElement;
  1836. }
  1837. // Add which for click: 1 === left; 2 === middle; 3 === right
  1838. // Note: button is not normalized, so don't use it
  1839. if (!event.which && button !== undefined) {
  1840. event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
  1841. }
  1842. return event;
  1843. }
  1844. },
  1845. special: {
  1846. load: {
  1847. // Prevent triggered image.load events from bubbling to window.load
  1848. noBubble: true
  1849. },
  1850. focus: {
  1851. // Fire native event if possible so blur/focus sequence is correct
  1852. trigger: function () {
  1853. if (this !== safeActiveElement() && this.focus) {
  1854. try {
  1855. this.focus();
  1856. return false;
  1857. } catch (e) {
  1858. // Support: IE<9
  1859. // If we error on focus to hidden element (#1486, #12518),
  1860. // let .trigger() run the handlers
  1861. }
  1862. }
  1863. },
  1864. delegateType: "focusin"
  1865. },
  1866. blur: {
  1867. trigger: function () {
  1868. if (this === safeActiveElement() && this.blur) {
  1869. this.blur();
  1870. return false;
  1871. }
  1872. },
  1873. delegateType: "focusout"
  1874. },
  1875. click: {
  1876. // For checkbox, fire native event so checked state will be right
  1877. trigger: function () {
  1878. if (jQuery.nodeName(this, "input") && this.type === "checkbox" && this.click) {
  1879. this.click();
  1880. return false;
  1881. }
  1882. },
  1883. // For cross-browser consistency, don't fire native .click() on links
  1884. _default: function (event) {
  1885. return jQuery.nodeName(event.target, "a");
  1886. }
  1887. },
  1888. beforeunload: {
  1889. postDispatch: function (event) {
  1890. // Support: Firefox 20+
  1891. // Firefox doesn't alert if the returnValue field is not set.
  1892. if (event.result !== undefined && event.originalEvent) {
  1893. event.originalEvent.returnValue = event.result;
  1894. }
  1895. }
  1896. }
  1897. },
  1898. simulate: function (type, elem, event, bubble) {
  1899. // Piggyback on a donor event to simulate a different one.
  1900. // Fake originalEvent to avoid donor's stopPropagation, but if the
  1901. // simulated event prevents default then we do the same on the donor.
  1902. var e = jQuery.extend(
  1903. new jQuery.Event(),
  1904. event,
  1905. {
  1906. type: type,
  1907. isSimulated: true,
  1908. originalEvent: {}
  1909. }
  1910. );
  1911. if (bubble) {
  1912. jQuery.event.trigger(e, null, elem);
  1913. } else {
  1914. jQuery.event.dispatch.call(elem, e);
  1915. }
  1916. if (e.isDefaultPrevented()) {
  1917. event.preventDefault();
  1918. }
  1919. }
  1920. };
  1921. jQuery.removeEvent = document.removeEventListener ?
  1922. function (elem, type, handle) {
  1923. if (elem.removeEventListener) {
  1924. elem.removeEventListener(type, handle, false);
  1925. }
  1926. } :
  1927. function (elem, type, handle) {
  1928. var name = "on" + type;
  1929. if (elem.detachEvent) {
  1930. // #8545, #7054, preventing memory leaks for custom events in IE6-8
  1931. // detachEvent needed property on element, by name of that event, to properly expose it to GC
  1932. if (typeof elem[name] === strundefined) {
  1933. elem[name] = null;
  1934. }
  1935. elem.detachEvent(name, handle);
  1936. }
  1937. };
  1938. jQuery.Event = function (src, props) {
  1939. // Allow instantiation without the 'new' keyword
  1940. if (!(this instanceof jQuery.Event)) {
  1941. return new jQuery.Event(src, props);
  1942. }
  1943. // Event object
  1944. if (src && src.type) {
  1945. this.originalEvent = src;
  1946. this.type = src.type;
  1947. // Events bubbling up the document may have been marked as prevented
  1948. // by a handler lower down the tree; reflect the correct value.
  1949. this.isDefaultPrevented = src.defaultPrevented ||
  1950. src.defaultPrevented === undefined &&
  1951. // Support: IE < 9, Android < 4.0
  1952. src.returnValue === false ?
  1953. returnTrue :
  1954. returnFalse;
  1955. // Event type
  1956. } else {
  1957. this.type = src;
  1958. }
  1959. // Put explicitly provided properties onto the event object
  1960. if (props) {
  1961. jQuery.extend(this, props);
  1962. }
  1963. // Create a timestamp if incoming event doesn't have one
  1964. this.timeStamp = src && src.timeStamp || jQuery.now();
  1965. // Mark it as fixed
  1966. this[jQuery.expando] = true;
  1967. };
  1968. var rformElems = /^(?:input|select|textarea)$/i,
  1969. rkeyEvent = /^key/,
  1970. rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
  1971. rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
  1972. rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
  1973. function returnTrue() {
  1974. return true;
  1975. }
  1976. function returnFalse() {
  1977. return false;
  1978. }
  1979. // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
  1980. // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
  1981. jQuery.Event.prototype = {
  1982. isDefaultPrevented: returnFalse,
  1983. isPropagationStopped: returnFalse,
  1984. isImmediatePropagationStopped: returnFalse,
  1985. preventDefault: function () {
  1986. var e = this.originalEvent;
  1987. this.isDefaultPrevented = returnTrue;
  1988. if (!e) {
  1989. return;
  1990. }
  1991. // If preventDefault exists, run it on the original event
  1992. if (e.preventDefault) {
  1993. e.preventDefault();
  1994. // Support: IE
  1995. // Otherwise set the returnValue property of the original event to false
  1996. } else {
  1997. e.returnValue = false;
  1998. }
  1999. },
  2000. stopPropagation: function () {
  2001. var e = this.originalEvent;
  2002. this.isPropagationStopped = returnTrue;
  2003. if (!e) {
  2004. return;
  2005. }
  2006. // If stopPropagation exists, run it on the original event
  2007. if (e.stopPropagation) {
  2008. e.stopPropagation();
  2009. }
  2010. // Support: IE
  2011. // Set the cancelBubble property of the original event to true
  2012. e.cancelBubble = true;
  2013. },
  2014. stopImmediatePropagation: function () {
  2015. var e = this.originalEvent;
  2016. this.isImmediatePropagationStopped = returnTrue;
  2017. if (e && e.stopImmediatePropagation) {
  2018. e.stopImmediatePropagation();
  2019. }
  2020. this.stopPropagation();
  2021. }
  2022. };
  2023. // IE submit delegation
  2024. if (!support.submitBubbles) {
  2025. jQuery.event.special.submit = {
  2026. setup: function () {
  2027. // Only need this for delegated form submit events
  2028. if (jQuery.nodeName(this, "form")) {
  2029. return false;
  2030. }
  2031. // Lazy-add a submit handler when a descendant form may potentially be submitted
  2032. jQuery.event.add(this, "click._submit keypress._submit", function (e) {
  2033. // Node name check avoids a VML-related crash in IE (#9807)
  2034. var elem = e.target,
  2035. form = jQuery.nodeName(elem, "input") || jQuery.nodeName(elem, "button") ? elem.form : undefined;
  2036. if (form && !jQuery._data(form, "submitBubbles")) {
  2037. jQuery.event.add(form, "submit._submit", function (event) {
  2038. event._submit_bubble = true;
  2039. });
  2040. jQuery._data(form, "submitBubbles", true);
  2041. }
  2042. });
  2043. // return undefined since we don't need an event listener
  2044. },
  2045. postDispatch: function (event) {
  2046. // If form was submitted by the user, bubble the event up the tree
  2047. if (event._submit_bubble) {
  2048. delete event._submit_bubble;
  2049. if (this.parentNode && !event.isTrigger) {
  2050. jQuery.event.simulate("submit", this.parentNode, event, true);
  2051. }
  2052. }
  2053. },
  2054. teardown: function () {
  2055. // Only need this for delegated form submit events
  2056. if (jQuery.nodeName(this, "form")) {
  2057. return false;
  2058. }
  2059. // Remove delegated handlers; cleanData eventually reaps submit handlers attached above
  2060. jQuery.event.remove(this, "._submit");
  2061. }
  2062. };
  2063. }
  2064. // IE change delegation and checkbox/radio fix
  2065. if (!support.changeBubbles) {
  2066. jQuery.event.special.change = {
  2067. setup: function () {
  2068. if (rformElems.test(this.nodeName)) {
  2069. // IE doesn't fire change on a check/radio until blur; trigger it on click
  2070. // after a propertychange. Eat the blur-change in special.change.handle.
  2071. // This still fires onchange a second time for check/radio after blur.
  2072. if (this.type === "checkbox" || this.type === "radio") {
  2073. jQuery.event.add(this, "propertychange._change", function (event) {
  2074. if (event.originalEvent.propertyName === "checked") {
  2075. this._just_changed = true;
  2076. }
  2077. });
  2078. jQuery.event.add(this, "click._change", function (event) {
  2079. if (this._just_changed && !event.isTrigger) {
  2080. this._just_changed = false;
  2081. }
  2082. // Allow triggered, simulated change events (#11500)
  2083. jQuery.event.simulate("change", this, event, true);
  2084. });
  2085. }
  2086. return false;
  2087. }
  2088. // Delegated event; lazy-add a change handler on descendant inputs
  2089. jQuery.event.add(this, "beforeactivate._change", function (e) {
  2090. var elem = e.target;
  2091. if (rformElems.test(elem.nodeName) && !jQuery._data(elem, "changeBubbles")) {
  2092. jQuery.event.add(elem, "change._change", function (event) {
  2093. if (this.parentNode && !event.isSimulated && !event.isTrigger) {
  2094. jQuery.event.simulate("change", this.parentNode, event, true);
  2095. }
  2096. });
  2097. jQuery._data(elem, "changeBubbles", true);
  2098. }
  2099. });
  2100. },
  2101. handle: function (event) {
  2102. var elem = event.target;
  2103. // Swallow native change events from checkbox/radio, we already triggered them above
  2104. if (this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox")) {
  2105. return event.handleObj.handler.apply(this, arguments);
  2106. }
  2107. },
  2108. teardown: function () {
  2109. jQuery.event.remove(this, "._change");
  2110. return !rformElems.test(this.nodeName);
  2111. }
  2112. };
  2113. }
  2114. // Create "bubbling" focus and blur events
  2115. if (!support.focusinBubbles) {
  2116. jQuery.each({focus: "focusin", blur: "focusout"}, function (orig, fix) {
  2117. // Attach a single capturing handler on the document while someone wants focusin/focusout
  2118. var handler = function (event) {
  2119. jQuery.event.simulate(fix, event.target, jQuery.event.fix(event), true);
  2120. };
  2121. jQuery.event.special[fix] = {
  2122. setup: function () {
  2123. var doc = this.ownerDocument || this,
  2124. attaches = jQuery._data(doc, fix);
  2125. if (!attaches) {
  2126. doc.addEventListener(orig, handler, true);
  2127. }
  2128. jQuery._data(doc, fix, ( attaches || 0 ) + 1);
  2129. },
  2130. teardown: function () {
  2131. var doc = this.ownerDocument || this,
  2132. attaches = jQuery._data(doc, fix) - 1;
  2133. if (!attaches) {
  2134. doc.removeEventListener(orig, handler, true);
  2135. jQuery._removeData(doc, fix);
  2136. } else {
  2137. jQuery._data(doc, fix, attaches);
  2138. }
  2139. }
  2140. };
  2141. });
  2142. }
  2143. jQuery.fn.extend({
  2144. on: function (types, selector, data, fn, /*INTERNAL*/ one) {
  2145. var type, origFn;
  2146. // Types can be a map of types/handlers
  2147. if (typeof types === "object") {
  2148. // ( types-Object, selector, data )
  2149. if (typeof selector !== "string") {
  2150. // ( types-Object, data )
  2151. data = data || selector;
  2152. selector = undefined;
  2153. }
  2154. for (type in types) {
  2155. this.on(type, selector, data, types[type], one);
  2156. }
  2157. return this;
  2158. }
  2159. if (data == null && fn == null) {
  2160. // ( types, fn )
  2161. fn = selector;
  2162. data = selector = undefined;
  2163. } else if (fn == null) {
  2164. if (typeof selector === "string") {
  2165. // ( types, selector, fn )
  2166. fn = data;
  2167. data = undefined;
  2168. } else {
  2169. // ( types, data, fn )
  2170. fn = data;
  2171. data = selector;
  2172. selector = undefined;
  2173. }
  2174. }
  2175. if (fn === false) {
  2176. fn = returnFalse;
  2177. } else if (!fn) {
  2178. return this;
  2179. }
  2180. if (one === 1) {
  2181. origFn = fn;
  2182. fn = function (event) {
  2183. // Can use an empty set, since event contains the info
  2184. jQuery().off(event);
  2185. return origFn.apply(this, arguments);
  2186. };
  2187. // Use same guid so caller can remove using origFn
  2188. fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
  2189. }
  2190. return this.each(function () {
  2191. jQuery.event.add(this, types, fn, data, selector);
  2192. });
  2193. },
  2194. one: function (types, selector, data, fn) {
  2195. return this.on(types, selector, data, fn, 1);
  2196. },
  2197. off: function (types, selector, fn) {
  2198. var handleObj, type;
  2199. if (types && types.preventDefault && types.handleObj) {
  2200. // ( event ) dispatched jQuery.Event
  2201. handleObj = types.handleObj;
  2202. jQuery(types.delegateTarget).off(
  2203. handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
  2204. handleObj.selector,
  2205. handleObj.handler
  2206. );
  2207. return this;
  2208. }
  2209. if (typeof types === "object") {
  2210. // ( types-object [, selector] )
  2211. for (type in types) {
  2212. this.off(type, selector, types[type]);
  2213. }
  2214. return this;
  2215. }
  2216. if (selector === false || typeof selector === "function") {
  2217. // ( types [, fn] )
  2218. fn = selector;
  2219. selector = undefined;
  2220. }
  2221. if (fn === false) {
  2222. fn = returnFalse;
  2223. }
  2224. return this.each(function () {
  2225. jQuery.event.remove(this, types, fn, selector);
  2226. });
  2227. },
  2228. trigger: function (type, data) {
  2229. return this.each(function () {
  2230. jQuery.event.trigger(type, data, this);
  2231. });
  2232. },
  2233. triggerHandler: function (type, data) {
  2234. var elem = this[0];
  2235. if (elem) {
  2236. return jQuery.event.trigger(type, data, elem, true);
  2237. }
  2238. }
  2239. });
  2240. // Based off of the plugin by Clint Helfers, with permission.
  2241. // http://blindsignals.com/index.php/2009/07/jquery-delay/
  2242. jQuery.fn.delay = function (time, type) {
  2243. time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
  2244. type = type || "fx";
  2245. return this.queue(type, function (next, hooks) {
  2246. var timeout = setTimeout(next, time);
  2247. hooks.stop = function () {
  2248. clearTimeout(timeout);
  2249. };
  2250. });
  2251. };
  2252. var nonce = jQuery.now();
  2253. var rquery = (/\?/);
  2254. var rvalidtokens = /(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g;
  2255. jQuery.parseJSON = function (data) {
  2256. // Attempt to parse using the native JSON parser first
  2257. if (window.JSON && window.JSON.parse) {
  2258. // Support: Android 2.3
  2259. // Workaround failure to string-cast null input
  2260. return window.JSON.parse(data + "");
  2261. }
  2262. var requireNonComma,
  2263. depth = null,
  2264. str = jQuery.trim(data + "");
  2265. // Guard against invalid (and possibly dangerous) input by ensuring that nothing remains
  2266. // after removing valid tokens
  2267. return str && !jQuery.trim(str.replace(rvalidtokens, function (token, comma, open, close) {
  2268. // Force termination if we see a misplaced comma
  2269. if (requireNonComma && comma) {
  2270. depth = 0;
  2271. }
  2272. // Perform no more replacements after returning to outermost depth
  2273. if (depth === 0) {
  2274. return token;
  2275. }
  2276. // Commas must not follow "[", "{", or ","
  2277. requireNonComma = open || comma;
  2278. // Determine new depth
  2279. // array/object open ("[" or "{"): depth += true - false (increment)
  2280. // array/object close ("]" or "}"): depth += false - true (decrement)
  2281. // other cases ("," or primitive): depth += true - true (numeric cast)
  2282. depth += !close - !open;
  2283. // Remove this token
  2284. return "";
  2285. })) ?
  2286. ( Function("return " + str) )() :
  2287. jQuery.error("Invalid JSON: " + data);
  2288. };
  2289. // Cross-browser xml parsing
  2290. jQuery.parseXML = function (data) {
  2291. var xml, tmp;
  2292. if (!data || typeof data !== "string") {
  2293. return null;
  2294. }
  2295. try {
  2296. if (window.DOMParser) { // Standard
  2297. tmp = new DOMParser();
  2298. xml = tmp.parseFromString(data, "text/xml");
  2299. } else { // IE
  2300. xml = new ActiveXObject("Microsoft.XMLDOM");
  2301. xml.async = "false";
  2302. xml.loadXML(data);
  2303. }
  2304. } catch (e) {
  2305. xml = undefined;
  2306. }
  2307. if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
  2308. jQuery.error("Invalid XML: " + data);
  2309. }
  2310. return xml;
  2311. };
  2312. var
  2313. // Document location
  2314. ajaxLocParts,
  2315. ajaxLocation,
  2316. rhash = /#.*$/,
  2317. rts = /([?&])_=[^&]*/,
  2318. rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
  2319. // #7653, #8125, #8152: local protocol detection
  2320. rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
  2321. rnoContent = /^(?:GET|HEAD)$/,
  2322. rprotocol = /^\/\//,
  2323. rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
  2324. /* Prefilters
  2325. * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
  2326. * 2) These are called:
  2327. * - BEFORE asking for a transport
  2328. * - AFTER param serialization (s.data is a string if s.processData is true)
  2329. * 3) key is the dataType
  2330. * 4) the catchall symbol "*" can be used
  2331. * 5) execution will start with transport dataType and THEN continue down to "*" if needed
  2332. */
  2333. prefilters = {},
  2334. /* Transports bindings
  2335. * 1) key is the dataType
  2336. * 2) the catchall symbol "*" can be used
  2337. * 3) selection will start with transport dataType and THEN go to "*" if needed
  2338. */
  2339. transports = {},
  2340. // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
  2341. allTypes = "*/".concat("*");
  2342. // #8138, IE may throw an exception when accessing
  2343. // a field from window.location if document.domain has been set
  2344. try {
  2345. ajaxLocation = location.href;
  2346. } catch (e) {
  2347. // Use the href attribute of an A element
  2348. // since IE will modify it given document.location
  2349. ajaxLocation = document.createElement("a");
  2350. ajaxLocation.href = "";
  2351. ajaxLocation = ajaxLocation.href;
  2352. }
  2353. // Segment location into parts
  2354. ajaxLocParts = rurl.exec(ajaxLocation.toLowerCase()) || [];
  2355. // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
  2356. function addToPrefiltersOrTransports(structure) {
  2357. // dataTypeExpression is optional and defaults to "*"
  2358. return function (dataTypeExpression, func) {
  2359. if (typeof dataTypeExpression !== "string") {
  2360. func = dataTypeExpression;
  2361. dataTypeExpression = "*";
  2362. }
  2363. var dataType,
  2364. i = 0,
  2365. dataTypes = dataTypeExpression.toLowerCase().match(rnotwhite) || [];
  2366. if (jQuery.isFunction(func)) {
  2367. // For each dataType in the dataTypeExpression
  2368. while ((dataType = dataTypes[i++])) {
  2369. // Prepend if requested
  2370. if (dataType.charAt(0) === "+") {
  2371. dataType = dataType.slice(1) || "*";
  2372. (structure[dataType] = structure[dataType] || []).unshift(func);
  2373. // Otherwise append
  2374. } else {
  2375. (structure[dataType] = structure[dataType] || []).push(func);
  2376. }
  2377. }
  2378. }
  2379. };
  2380. }
  2381. // Base inspection function for prefilters and transports
  2382. function inspectPrefiltersOrTransports(structure, options, originalOptions, jqXHR) {
  2383. var inspected = {},
  2384. seekingTransport = ( structure === transports );
  2385. function inspect(dataType) {
  2386. var selected;
  2387. inspected[dataType] = true;
  2388. jQuery.each(structure[dataType] || [], function (_, prefilterOrFactory) {
  2389. var dataTypeOrTransport = prefilterOrFactory(options, originalOptions, jqXHR);
  2390. if (typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[dataTypeOrTransport]) {
  2391. options.dataTypes.unshift(dataTypeOrTransport);
  2392. inspect(dataTypeOrTransport);
  2393. return false;
  2394. } else if (seekingTransport) {
  2395. return !( selected = dataTypeOrTransport );
  2396. }
  2397. });
  2398. return selected;
  2399. }
  2400. return inspect(options.dataTypes[0]) || !inspected["*"] && inspect("*");
  2401. }
  2402. // A special extend for ajax options
  2403. // that takes "flat" options (not to be deep extended)
  2404. // Fixes #9887
  2405. function ajaxExtend(target, src) {
  2406. var deep, key,
  2407. flatOptions = jQuery.ajaxSettings.flatOptions || {};
  2408. for (key in src) {
  2409. if (src[key] !== undefined) {
  2410. ( flatOptions[key] ? target : ( deep || (deep = {}) ) )[key] = src[key];
  2411. }
  2412. }
  2413. if (deep) {
  2414. jQuery.extend(true, target, deep);
  2415. }
  2416. return target;
  2417. }
  2418. /* Handles responses to an ajax request:
  2419. * - finds the right dataType (mediates between content-type and expected dataType)
  2420. * - returns the corresponding response
  2421. */
  2422. function ajaxHandleResponses(s, jqXHR, responses) {
  2423. var firstDataType, ct, finalDataType, type,
  2424. contents = s.contents,
  2425. dataTypes = s.dataTypes;
  2426. // Remove auto dataType and get content-type in the process
  2427. while (dataTypes[0] === "*") {
  2428. dataTypes.shift();
  2429. if (ct === undefined) {
  2430. ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
  2431. }
  2432. }
  2433. // Check if we're dealing with a known content-type
  2434. if (ct) {
  2435. for (type in contents) {
  2436. if (contents[type] && contents[type].test(ct)) {
  2437. dataTypes.unshift(type);
  2438. break;
  2439. }
  2440. }
  2441. }
  2442. // Check to see if we have a response for the expected dataType
  2443. if (dataTypes[0] in responses) {
  2444. finalDataType = dataTypes[0];
  2445. } else {
  2446. // Try convertible dataTypes
  2447. for (type in responses) {
  2448. if (!dataTypes[0] || s.converters[type + " " + dataTypes[0]]) {
  2449. finalDataType = type;
  2450. break;
  2451. }
  2452. if (!firstDataType) {
  2453. firstDataType = type;
  2454. }
  2455. }
  2456. // Or just use first one
  2457. finalDataType = finalDataType || firstDataType;
  2458. }
  2459. // If we found a dataType
  2460. // We add the dataType to the list if needed
  2461. // and return the corresponding response
  2462. if (finalDataType) {
  2463. if (finalDataType !== dataTypes[0]) {
  2464. dataTypes.unshift(finalDataType);
  2465. }
  2466. return responses[finalDataType];
  2467. }
  2468. }
  2469. /* Chain conversions given the request and the original response
  2470. * Also sets the responseXXX fields on the jqXHR instance
  2471. */
  2472. function ajaxConvert(s, response, jqXHR, isSuccess) {
  2473. var conv2, current, conv, tmp, prev,
  2474. converters = {},
  2475. // Work with a copy of dataTypes in case we need to modify it for conversion
  2476. dataTypes = s.dataTypes.slice();
  2477. // Create converters map with lowercased keys
  2478. if (dataTypes[1]) {
  2479. for (conv in s.converters) {
  2480. converters[conv.toLowerCase()] = s.converters[conv];
  2481. }
  2482. }
  2483. current = dataTypes.shift();
  2484. // Convert to each sequential dataType
  2485. while (current) {
  2486. if (s.responseFields[current]) {
  2487. jqXHR[s.responseFields[current]] = response;
  2488. }
  2489. // Apply the dataFilter if provided
  2490. if (!prev && isSuccess && s.dataFilter) {
  2491. response = s.dataFilter(response, s.dataType);
  2492. }
  2493. prev = current;
  2494. current = dataTypes.shift();
  2495. if (current) {
  2496. // There's only work to do if current dataType is non-auto
  2497. if (current === "*") {
  2498. current = prev;
  2499. // Convert response if prev dataType is non-auto and differs from current
  2500. } else if (prev !== "*" && prev !== current) {
  2501. // Seek a direct converter
  2502. conv = converters[prev + " " + current] || converters["* " + current];
  2503. // If none found, seek a pair
  2504. if (!conv) {
  2505. for (conv2 in converters) {
  2506. // If conv2 outputs current
  2507. tmp = conv2.split(" ");
  2508. if (tmp[1] === current) {
  2509. // If prev can be converted to accepted input
  2510. conv = converters[prev + " " + tmp[0]] ||
  2511. converters["* " + tmp[0]];
  2512. if (conv) {
  2513. // Condense equivalence converters
  2514. if (conv === true) {
  2515. conv = converters[conv2];
  2516. // Otherwise, insert the intermediate dataType
  2517. } else if (converters[conv2] !== true) {
  2518. current = tmp[0];
  2519. dataTypes.unshift(tmp[1]);
  2520. }
  2521. break;
  2522. }
  2523. }
  2524. }
  2525. }
  2526. // Apply converter (if not an equivalence)
  2527. if (conv !== true) {
  2528. // Unless errors are allowed to bubble, catch and return them
  2529. if (conv && s["throws"]) {
  2530. response = conv(response);
  2531. } else {
  2532. try {
  2533. response = conv(response);
  2534. } catch (e) {
  2535. return {
  2536. state: "parsererror",
  2537. error: conv ? e : "No conversion from " + prev + " to " + current
  2538. };
  2539. }
  2540. }
  2541. }
  2542. }
  2543. }
  2544. }
  2545. return {state: "success", data: response};
  2546. }
  2547. jQuery.extend({
  2548. // Counter for holding the number of active queries
  2549. active: 0,
  2550. // Last-Modified header cache for next request
  2551. lastModified: {},
  2552. etag: {},
  2553. ajaxSettings: {
  2554. url: ajaxLocation,
  2555. type: "GET",
  2556. isLocal: rlocalProtocol.test(ajaxLocParts[1]),
  2557. global: true,
  2558. processData: true,
  2559. async: true,
  2560. contentType: "application/x-www-form-urlencoded; charset=UTF-8",
  2561. /*
  2562. timeout: 0,
  2563. data: null,
  2564. dataType: null,
  2565. username: null,
  2566. password: null,
  2567. cache: null,
  2568. throws: false,
  2569. traditional: false,
  2570. headers: {},
  2571. */
  2572. accepts: {
  2573. "*": allTypes,
  2574. text: "text/plain",
  2575. html: "text/html",
  2576. xml: "application/xml, text/xml",
  2577. json: "application/json, text/javascript"
  2578. },
  2579. contents: {
  2580. xml: /xml/,
  2581. html: /html/,
  2582. json: /json/
  2583. },
  2584. responseFields: {
  2585. xml: "responseXML",
  2586. text: "responseText",
  2587. json: "responseJSON"
  2588. },
  2589. // Data converters
  2590. // Keys separate source (or catchall "*") and destination types with a single space
  2591. converters: {
  2592. // Convert anything to text
  2593. "* text": String,
  2594. // Text to html (true = no transformation)
  2595. "text html": true,
  2596. // Evaluate text as a json expression
  2597. "text json": jQuery.parseJSON,
  2598. // Parse text as xml
  2599. "text xml": jQuery.parseXML
  2600. },
  2601. // For options that shouldn't be deep extended:
  2602. // you can add your own custom options here if
  2603. // and when you create one that shouldn't be
  2604. // deep extended (see ajaxExtend)
  2605. flatOptions: {
  2606. url: true,
  2607. context: true
  2608. }
  2609. },
  2610. // Creates a full fledged settings object into target
  2611. // with both ajaxSettings and settings fields.
  2612. // If target is omitted, writes into ajaxSettings.
  2613. ajaxSetup: function (target, settings) {
  2614. return settings ?
  2615. // Building a settings object
  2616. ajaxExtend(ajaxExtend(target, jQuery.ajaxSettings), settings) :
  2617. // Extending ajaxSettings
  2618. ajaxExtend(jQuery.ajaxSettings, target);
  2619. },
  2620. ajaxPrefilter: addToPrefiltersOrTransports(prefilters),
  2621. ajaxTransport: addToPrefiltersOrTransports(transports),
  2622. // Main method
  2623. ajax: function (url, options) {
  2624. // If url is an object, simulate pre-1.5 signature
  2625. if (typeof url === "object") {
  2626. options = url;
  2627. url = undefined;
  2628. }
  2629. // Force options to be an object
  2630. options = options || {};
  2631. var // Cross-domain detection vars
  2632. parts,
  2633. // Loop variable
  2634. i,
  2635. // URL without anti-cache param
  2636. cacheURL,
  2637. // Response headers as string
  2638. responseHeadersString,
  2639. // timeout handle
  2640. timeoutTimer,
  2641. // To know if global events are to be dispatched
  2642. fireGlobals,
  2643. transport,
  2644. // Response headers
  2645. responseHeaders,
  2646. // Create the final options object
  2647. s = jQuery.ajaxSetup({}, options),
  2648. // Callbacks context
  2649. callbackContext = s.context || s,
  2650. // Context for global events is callbackContext if it is a DOM node or jQuery collection
  2651. globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
  2652. jQuery(callbackContext) :
  2653. jQuery.event,
  2654. // Deferreds
  2655. deferred = jQuery.Deferred(),
  2656. completeDeferred = jQuery.Callbacks("once memory"),
  2657. // Status-dependent callbacks
  2658. statusCode = s.statusCode || {},
  2659. // Headers (they are sent all at once)
  2660. requestHeaders = {},
  2661. requestHeadersNames = {},
  2662. // The jqXHR state
  2663. state = 0,
  2664. // Default abort message
  2665. strAbort = "canceled",
  2666. // Fake xhr
  2667. jqXHR = {
  2668. readyState: 0,
  2669. // Builds headers hashtable if needed
  2670. getResponseHeader: function (key) {
  2671. var match;
  2672. if (state === 2) {
  2673. if (!responseHeaders) {
  2674. responseHeaders = {};
  2675. while ((match = rheaders.exec(responseHeadersString))) {
  2676. responseHeaders[match[1].toLowerCase()] = match[2];
  2677. }
  2678. }
  2679. match = responseHeaders[key.toLowerCase()];
  2680. }
  2681. return match == null ? null : match;
  2682. },
  2683. // Raw string
  2684. getAllResponseHeaders: function () {
  2685. return state === 2 ? responseHeadersString : null;
  2686. },
  2687. // Caches the header
  2688. setRequestHeader: function (name, value) {
  2689. var lname = name.toLowerCase();
  2690. if (!state) {
  2691. name = requestHeadersNames[lname] = requestHeadersNames[lname] || name;
  2692. requestHeaders[name] = value;
  2693. }
  2694. return this;
  2695. },
  2696. // Overrides response content-type header
  2697. overrideMimeType: function (type) {
  2698. if (!state) {
  2699. s.mimeType = type;
  2700. }
  2701. return this;
  2702. },
  2703. // Status-dependent callbacks
  2704. statusCode: function (map) {
  2705. var code;
  2706. if (map) {
  2707. if (state < 2) {
  2708. for (code in map) {
  2709. // Lazy-add the new callback in a way that preserves old ones
  2710. statusCode[code] = [statusCode[code], map[code]];
  2711. }
  2712. } else {
  2713. // Execute the appropriate callbacks
  2714. jqXHR.always(map[jqXHR.status]);
  2715. }
  2716. }
  2717. return this;
  2718. },
  2719. // Cancel the request
  2720. abort: function (statusText) {
  2721. var finalText = statusText || strAbort;
  2722. if (transport) {
  2723. transport.abort(finalText);
  2724. }
  2725. done(0, finalText);
  2726. return this;
  2727. }
  2728. };
  2729. // Attach deferreds
  2730. deferred.promise(jqXHR).complete = completeDeferred.add;
  2731. jqXHR.success = jqXHR.done;
  2732. jqXHR.error = jqXHR.fail;
  2733. // Remove hash character (#7531: and string promotion)
  2734. // Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
  2735. // Handle falsy url in the settings object (#10093: consistency with old signature)
  2736. // We also use the url parameter if available
  2737. s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace(rhash, "").replace(rprotocol, ajaxLocParts[1] + "//");
  2738. // Alias method option to type as per ticket #12004
  2739. s.type = options.method || options.type || s.method || s.type;
  2740. // Extract dataTypes list
  2741. s.dataTypes = jQuery.trim(s.dataType || "*").toLowerCase().match(rnotwhite) || [""];
  2742. // A cross-domain request is in order when we have a protocol:host:port mismatch
  2743. if (s.crossDomain == null) {
  2744. parts = rurl.exec(s.url.toLowerCase());
  2745. s.crossDomain = !!( parts &&
  2746. ( parts[1] !== ajaxLocParts[1] || parts[2] !== ajaxLocParts[2] ||
  2747. ( parts[3] || ( parts[1] === "http:" ? "80" : "443" ) ) !==
  2748. ( ajaxLocParts[3] || ( ajaxLocParts[1] === "http:" ? "80" : "443" ) ) )
  2749. );
  2750. }
  2751. // Convert data if not already a string
  2752. if (s.data && s.processData && typeof s.data !== "string") {
  2753. s.data = jQuery.param(s.data, s.traditional);
  2754. }
  2755. // Apply prefilters
  2756. inspectPrefiltersOrTransports(prefilters, s, options, jqXHR);
  2757. // If request was aborted inside a prefilter, stop there
  2758. if (state === 2) {
  2759. return jqXHR;
  2760. }
  2761. // We can fire global events as of now if asked to
  2762. fireGlobals = s.global;
  2763. // Watch for a new set of requests
  2764. if (fireGlobals && jQuery.active++ === 0) {
  2765. jQuery.event.trigger("ajaxStart");
  2766. }
  2767. // Uppercase the type
  2768. s.type = s.type.toUpperCase();
  2769. // Determine if request has content
  2770. s.hasContent = !rnoContent.test(s.type);
  2771. // Save the URL in case we're toying with the If-Modified-Since
  2772. // and/or If-None-Match header later on
  2773. cacheURL = s.url;
  2774. // More options handling for requests with no content
  2775. if (!s.hasContent) {
  2776. // If data is available, append data to url
  2777. if (s.data) {
  2778. cacheURL = ( s.url += ( rquery.test(cacheURL) ? "&" : "?" ) + s.data );
  2779. // #9682: remove data so that it's not used in an eventual retry
  2780. delete s.data;
  2781. }
  2782. // Add anti-cache in url if needed
  2783. if (s.cache === false) {
  2784. s.url = rts.test(cacheURL) ?
  2785. // If there is already a '_' parameter, set its value
  2786. cacheURL.replace(rts, "$1_=" + nonce++) :
  2787. // Otherwise add one to the end
  2788. cacheURL + ( rquery.test(cacheURL) ? "&" : "?" ) + "_=" + nonce++;
  2789. }
  2790. }
  2791. // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  2792. if (s.ifModified) {
  2793. if (jQuery.lastModified[cacheURL]) {
  2794. jqXHR.setRequestHeader("If-Modified-Since", jQuery.lastModified[cacheURL]);
  2795. }
  2796. if (jQuery.etag[cacheURL]) {
  2797. jqXHR.setRequestHeader("If-None-Match", jQuery.etag[cacheURL]);
  2798. }
  2799. }
  2800. // Set the correct header, if data is being sent
  2801. if (s.data && s.hasContent && s.contentType !== false || options.contentType) {
  2802. jqXHR.setRequestHeader("Content-Type", s.contentType);
  2803. }
  2804. // Set the Accepts header for the server, depending on the dataType
  2805. // jqXHR.setRequestHeader(
  2806. // "Accept",
  2807. // s.dataTypes[0] && s.accepts[s.dataTypes[0]] ?
  2808. // s.accepts[s.dataTypes[0]] + ( s.dataTypes[0] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
  2809. // s.accepts["*"]
  2810. // );
  2811. // Check for headers option
  2812. for (i in s.headers) {
  2813. jqXHR.setRequestHeader(i, s.headers[i]);
  2814. }
  2815. // Allow custom headers/mimetypes and early abort
  2816. if (s.beforeSend && ( s.beforeSend.call(callbackContext, jqXHR, s) === false || state === 2 )) {
  2817. // Abort if not done already and return
  2818. return jqXHR.abort();
  2819. }
  2820. // aborting is no longer a cancellation
  2821. strAbort = "abort";
  2822. // Install callbacks on deferreds
  2823. for (i in {success: 1, error: 1, complete: 1}) {
  2824. jqXHR[i](s[i]);
  2825. }
  2826. // Get transport
  2827. transport = inspectPrefiltersOrTransports(transports, s, options, jqXHR);
  2828. // If no transport, we auto-abort
  2829. if (!transport) {
  2830. done(-1, "No Transport");
  2831. } else {
  2832. jqXHR.readyState = 1;
  2833. // Send global event
  2834. if (fireGlobals) {
  2835. globalEventContext.trigger("ajaxSend", [jqXHR, s]);
  2836. }
  2837. // Timeout
  2838. if (s.async && s.timeout > 0) {
  2839. timeoutTimer = setTimeout(function () {
  2840. jqXHR.abort("timeout");
  2841. }, s.timeout);
  2842. }
  2843. try {
  2844. state = 1;
  2845. transport.send(requestHeaders, done);
  2846. } catch (e) {
  2847. // Propagate exception as error if not done
  2848. if (state < 2) {
  2849. done(-1, e);
  2850. // Simply rethrow otherwise
  2851. } else {
  2852. throw e;
  2853. }
  2854. }
  2855. }
  2856. // Callback for when everything is done
  2857. function done(status, nativeStatusText, responses, headers) {
  2858. var isSuccess, success, error, response, modified,
  2859. statusText = nativeStatusText;
  2860. // Called once
  2861. if (state === 2) {
  2862. return;
  2863. }
  2864. // State is "done" now
  2865. state = 2;
  2866. // Clear timeout if it exists
  2867. if (timeoutTimer) {
  2868. clearTimeout(timeoutTimer);
  2869. }
  2870. // Dereference transport for early garbage collection
  2871. // (no matter how long the jqXHR object will be used)
  2872. transport = undefined;
  2873. // Cache response headers
  2874. responseHeadersString = headers || "";
  2875. // Set readyState
  2876. jqXHR.readyState = status > 0 ? 4 : 0;
  2877. // Determine if successful
  2878. isSuccess = status >= 200 && status < 300 || status === 304;
  2879. // Get response data
  2880. if (responses) {
  2881. response = ajaxHandleResponses(s, jqXHR, responses);
  2882. }
  2883. // Convert no matter what (that way responseXXX fields are always set)
  2884. response = ajaxConvert(s, response, jqXHR, isSuccess);
  2885. // If successful, handle type chaining
  2886. if (isSuccess) {
  2887. // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  2888. if (s.ifModified) {
  2889. modified = jqXHR.getResponseHeader("Last-Modified");
  2890. if (modified) {
  2891. jQuery.lastModified[cacheURL] = modified;
  2892. }
  2893. modified = jqXHR.getResponseHeader("etag");
  2894. if (modified) {
  2895. jQuery.etag[cacheURL] = modified;
  2896. }
  2897. }
  2898. // if no content
  2899. if (status === 204 || s.type === "HEAD") {
  2900. statusText = "nocontent";
  2901. // if not modified
  2902. } else if (status === 304) {
  2903. statusText = "notmodified";
  2904. // If we have data, let's convert it
  2905. } else {
  2906. statusText = response.state;
  2907. success = response.data;
  2908. error = response.error;
  2909. isSuccess = !error;
  2910. }
  2911. } else {
  2912. // We extract error from statusText
  2913. // then normalize statusText and status for non-aborts
  2914. error = statusText;
  2915. if (status || !statusText) {
  2916. statusText = "error";
  2917. if (status < 0) {
  2918. status = 0;
  2919. }
  2920. }
  2921. }
  2922. // Set data for the fake xhr object
  2923. jqXHR.status = status;
  2924. jqXHR.statusText = ( nativeStatusText || statusText ) + "";
  2925. // Success/Error
  2926. if (isSuccess) {
  2927. deferred.resolveWith(callbackContext, [success, statusText, jqXHR]);
  2928. } else {
  2929. deferred.rejectWith(callbackContext, [jqXHR, statusText, error]);
  2930. }
  2931. // Status-dependent callbacks
  2932. jqXHR.statusCode(statusCode);
  2933. statusCode = undefined;
  2934. if (fireGlobals) {
  2935. globalEventContext.trigger(isSuccess ? "ajaxSuccess" : "ajaxError",
  2936. [jqXHR, s, isSuccess ? success : error]);
  2937. }
  2938. // Complete
  2939. completeDeferred.fireWith(callbackContext, [jqXHR, statusText]);
  2940. if (fireGlobals) {
  2941. globalEventContext.trigger("ajaxComplete", [jqXHR, s]);
  2942. // Handle the global AJAX counter
  2943. if (!( --jQuery.active )) {
  2944. jQuery.event.trigger("ajaxStop");
  2945. }
  2946. }
  2947. }
  2948. return jqXHR;
  2949. },
  2950. getJSON: function (url, data, callback) {
  2951. return jQuery.get(url, data, callback, "json");
  2952. },
  2953. getScript: function (url, callback) {
  2954. return jQuery.get(url, undefined, callback, "script");
  2955. }
  2956. });
  2957. jQuery.each(["get", "post"], function (i, method) {
  2958. jQuery[method] = function (url, data, callback, type) {
  2959. // shift arguments if data argument was omitted
  2960. if (jQuery.isFunction(data)) {
  2961. type = type || callback;
  2962. callback = data;
  2963. data = undefined;
  2964. }
  2965. return jQuery.ajax({
  2966. url: url,
  2967. type: method,
  2968. dataType: type,
  2969. data: data,
  2970. success: callback
  2971. });
  2972. };
  2973. });
  2974. // Attach a bunch of functions for handling common AJAX events
  2975. jQuery.each(["ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend"], function (i, type) {
  2976. jQuery.fn[type] = function (fn) {
  2977. return this.on(type, fn);
  2978. };
  2979. });
  2980. jQuery._evalUrl = function (url) {
  2981. return jQuery.ajax({
  2982. url: url,
  2983. type: "GET",
  2984. dataType: "script",
  2985. async: false,
  2986. global: false,
  2987. "throws": true
  2988. });
  2989. };
  2990. var r20 = /%20/g,
  2991. rbracket = /\[\]$/,
  2992. rCRLF = /\r?\n/g,
  2993. rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
  2994. rsubmittable = /^(?:input|select|textarea|keygen)/i;
  2995. function buildParams(prefix, obj, traditional, add) {
  2996. var name;
  2997. if (jQuery.isArray(obj)) {
  2998. // Serialize array item.
  2999. jQuery.each(obj, function (i, v) {
  3000. if (traditional || rbracket.test(prefix)) {
  3001. // Treat each array item as a scalar.
  3002. add(prefix, v);
  3003. } else {
  3004. // Item is non-scalar (array or object), encode its numeric index.
  3005. buildParams(prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add);
  3006. }
  3007. });
  3008. } else if (!traditional && jQuery.type(obj) === "object") {
  3009. // Serialize object item.
  3010. for (name in obj) {
  3011. buildParams(prefix + "[" + name + "]", obj[name], traditional, add);
  3012. }
  3013. } else {
  3014. // Serialize scalar item.
  3015. add(prefix, obj);
  3016. }
  3017. }
  3018. // Serialize an array of form elements or a set of
  3019. // key/values into a query string
  3020. jQuery.param = function (a, traditional) {
  3021. var prefix,
  3022. s = [],
  3023. add = function (key, value) {
  3024. // If value is a function, invoke it and return its value
  3025. value = jQuery.isFunction(value) ? value() : ( value == null ? "" : value );
  3026. s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
  3027. };
  3028. // Set traditional to true for jQuery <= 1.3.2 behavior.
  3029. if (traditional === undefined) {
  3030. traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
  3031. }
  3032. // If an array was passed in, assume that it is an array of form elements.
  3033. if (jQuery.isArray(a) || ( a.jquery && !jQuery.isPlainObject(a) )) {
  3034. // Serialize the form elements
  3035. jQuery.each(a, function () {
  3036. add(this.name, this.value);
  3037. });
  3038. } else {
  3039. // If traditional, encode the "old" way (the way 1.3.2 or older
  3040. // did it), otherwise encode params recursively.
  3041. for (prefix in a) {
  3042. buildParams(prefix, a[prefix], traditional, add);
  3043. }
  3044. }
  3045. // Return the resulting serialization
  3046. return s.join("&").replace(r20, "+");
  3047. };
  3048. jQuery.fn.extend({
  3049. serialize: function () {
  3050. return jQuery.param(this.serializeArray());
  3051. },
  3052. serializeArray: function () {
  3053. return this.map(function () {
  3054. // Can add propHook for "elements" to filter or add form elements
  3055. var elements = jQuery.prop(this, "elements");
  3056. return elements ? jQuery.makeArray(elements) : this;
  3057. })
  3058. .filter(function () {
  3059. var type = this.type;
  3060. // Use .is(":disabled") so that fieldset[disabled] works
  3061. return this.name && !jQuery(this).is(":disabled") &&
  3062. rsubmittable.test(this.nodeName) && !rsubmitterTypes.test(type) &&
  3063. ( this.checked || !rcheckableType.test(type) );
  3064. })
  3065. .map(function (i, elem) {
  3066. var val = jQuery(this).val();
  3067. return val == null ?
  3068. null :
  3069. jQuery.isArray(val) ?
  3070. jQuery.map(val, function (val) {
  3071. return {name: elem.name, value: val.replace(rCRLF, "\r\n")};
  3072. }) :
  3073. {name: elem.name, value: val.replace(rCRLF, "\r\n")};
  3074. }).get();
  3075. }
  3076. });
  3077. // Create the request object
  3078. // (This is still attached to ajaxSettings for backward compatibility)
  3079. jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ?
  3080. // Support: IE6+
  3081. function () {
  3082. // XHR cannot access local files, always use ActiveX for that case
  3083. return !this.isLocal &&
  3084. // Support: IE7-8
  3085. // oldIE XHR does not support non-RFC2616 methods (#13240)
  3086. // See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx
  3087. // and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9
  3088. // Although this check for six methods instead of eight
  3089. // since IE also does not support "trace" and "connect"
  3090. /^(get|post|head|put|delete|options)$/i.test(this.type) &&
  3091. createStandardXHR() || createActiveXHR();
  3092. } :
  3093. // For all other browsers, use the standard XMLHttpRequest object
  3094. createStandardXHR;
  3095. var xhrId = 0,
  3096. xhrCallbacks = {},
  3097. xhrSupported = jQuery.ajaxSettings.xhr();
  3098. // Support: IE<10
  3099. // Open requests must be manually aborted on unload (#5280)
  3100. if (window.ActiveXObject) {
  3101. jQuery(window).on("unload", function () {
  3102. for (var key in xhrCallbacks) {
  3103. xhrCallbacks[key](undefined, true);
  3104. }
  3105. });
  3106. }
  3107. // Determine support properties
  3108. support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
  3109. xhrSupported = support.ajax = !!xhrSupported;
  3110. // Create transport if the browser can provide an xhr
  3111. if (xhrSupported) {
  3112. jQuery.ajaxTransport(function (options) {
  3113. // Cross domain only allowed if supported through XMLHttpRequest
  3114. if (!options.crossDomain || support.cors) {
  3115. var callback;
  3116. return {
  3117. send: function (headers, complete) {
  3118. var i,
  3119. xhr = options.xhr(),
  3120. id = ++xhrId;
  3121. // Open the socket
  3122. xhr.open(options.type, options.url, options.async, options.username, options.password);
  3123. // Apply custom fields if provided
  3124. if (options.xhrFields) {
  3125. for (i in options.xhrFields) {
  3126. xhr[i] = options.xhrFields[i];
  3127. }
  3128. }
  3129. // Override mime type if needed
  3130. if (options.mimeType && xhr.overrideMimeType) {
  3131. xhr.overrideMimeType(options.mimeType);
  3132. }
  3133. // X-Requested-With header
  3134. // For cross-domain requests, seeing as conditions for a preflight are
  3135. // akin to a jigsaw puzzle, we simply never set it to be sure.
  3136. // (it can always be set on a per-request basis or even using ajaxSetup)
  3137. // For same-domain requests, won't change header if already provided.
  3138. if (!options.crossDomain && !headers["X-Requested-With"]) {
  3139. headers["X-Requested-With"] = "XMLHttpRequest";
  3140. }
  3141. // Set headers
  3142. for (i in headers) {
  3143. // Support: IE<9
  3144. // IE's ActiveXObject throws a 'Type Mismatch' exception when setting
  3145. // request header to a null-value.
  3146. //
  3147. // To keep consistent with other XHR implementations, cast the value
  3148. // to string and ignore `undefined`.
  3149. if (headers[i] !== undefined) {
  3150. xhr.setRequestHeader(i, headers[i] + "");
  3151. }
  3152. }
  3153. if (xhr.upload && options.progress) {
  3154. xhr.upload.onprogress = options.progress;
  3155. }
  3156. // Do send the request
  3157. // This may raise an exception which is actually
  3158. // handled in jQuery.ajax (so no try/catch here)
  3159. xhr.send(( options.hasContent && (options.body || options.data)) || null);
  3160. // Listener
  3161. callback = function (_, isAbort) {
  3162. var status, statusText, responses;
  3163. // Was never called and is aborted or complete
  3164. if (callback && ( isAbort || xhr.readyState === 4 )) {
  3165. // Clean up
  3166. delete xhrCallbacks[id];
  3167. callback = undefined;
  3168. xhr.onreadystatechange = jQuery.noop;
  3169. // Abort manually if needed
  3170. if (isAbort) {
  3171. if (xhr.readyState !== 4) {
  3172. xhr.abort();
  3173. }
  3174. } else {
  3175. responses = {};
  3176. status = xhr.status;
  3177. // Support: IE<10
  3178. // Accessing binary-data responseText throws an exception
  3179. // (#11426)
  3180. if (typeof xhr.responseText === "string") {
  3181. responses.text = xhr.responseText;
  3182. }
  3183. // Firefox throws an exception when accessing
  3184. // statusText for faulty cross-domain requests
  3185. try {
  3186. statusText = xhr.statusText;
  3187. } catch (e) {
  3188. // We normalize with Webkit giving an empty statusText
  3189. statusText = "";
  3190. }
  3191. // Filter status for non standard behaviors
  3192. // If the request is local and we have data: assume a success
  3193. // (success with no data won't get notified, that's the best we
  3194. // can do given current implementations)
  3195. if (!status && options.isLocal && !options.crossDomain) {
  3196. status = responses.text ? 200 : 404;
  3197. // IE - #1450: sometimes returns 1223 when it should be 204
  3198. } else if (status === 1223) {
  3199. status = 204;
  3200. }
  3201. }
  3202. }
  3203. // Call complete if needed
  3204. if (responses) {
  3205. complete(status, statusText, responses, xhr.getAllResponseHeaders());
  3206. }
  3207. };
  3208. if (!options.async) {
  3209. // if we're in sync mode we fire the callback
  3210. callback();
  3211. } else if (xhr.readyState === 4) {
  3212. // (IE6 & IE7) if it's in cache and has been
  3213. // retrieved directly we need to fire the callback
  3214. setTimeout(callback);
  3215. } else {
  3216. // Add to the list of active xhr callbacks
  3217. xhr.onreadystatechange = xhrCallbacks[id] = callback;
  3218. }
  3219. },
  3220. abort: function () {
  3221. if (callback) {
  3222. callback(undefined, true);
  3223. }
  3224. }
  3225. };
  3226. }
  3227. });
  3228. }
  3229. // Functions to create xhrs
  3230. function createStandardXHR() {
  3231. try {
  3232. return new window.XMLHttpRequest();
  3233. } catch (e) {
  3234. }
  3235. }
  3236. function createActiveXHR() {
  3237. try {
  3238. return new window.ActiveXObject("Microsoft.XMLHTTP");
  3239. } catch (e) {
  3240. }
  3241. }
  3242. // Install script dataType
  3243. jQuery.ajaxSetup({
  3244. accepts: {
  3245. script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
  3246. },
  3247. contents: {
  3248. script: /(?:java|ecma)script/
  3249. },
  3250. converters: {
  3251. "text script": function (text) {
  3252. jQuery.globalEval(text);
  3253. return text;
  3254. }
  3255. }
  3256. });
  3257. // Handle cache's special case and global
  3258. jQuery.ajaxPrefilter("script", function (s) {
  3259. if (s.cache === undefined) {
  3260. s.cache = false;
  3261. }
  3262. if (s.crossDomain) {
  3263. s.type = "GET";
  3264. s.global = false;
  3265. }
  3266. });
  3267. // Bind script tag hack transport
  3268. jQuery.ajaxTransport("script", function (s) {
  3269. // This transport only deals with cross domain requests
  3270. if (s.crossDomain) {
  3271. var script,
  3272. head = document.head || jQuery("head")[0] || document.documentElement;
  3273. return {
  3274. send: function (_, callback) {
  3275. script = document.createElement("script");
  3276. script.async = true;
  3277. if (s.scriptCharset) {
  3278. script.charset = s.scriptCharset;
  3279. }
  3280. script.src = s.url;
  3281. // Attach handlers for all browsers
  3282. script.onload = script.onreadystatechange = function (_, isAbort) {
  3283. if (isAbort || !script.readyState || /loaded|complete/.test(script.readyState)) {
  3284. // Handle memory leak in IE
  3285. script.onload = script.onreadystatechange = null;
  3286. // Remove the script
  3287. if (script.parentNode) {
  3288. script.parentNode.removeChild(script);
  3289. }
  3290. // Dereference the script
  3291. script = null;
  3292. // Callback if not abort
  3293. if (!isAbort) {
  3294. callback(200, "success");
  3295. }
  3296. }
  3297. };
  3298. // Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending
  3299. // Use native DOM manipulation to avoid our domManip AJAX trickery
  3300. head.insertBefore(script, head.firstChild);
  3301. },
  3302. abort: function () {
  3303. if (script) {
  3304. script.onload(undefined, true);
  3305. }
  3306. }
  3307. };
  3308. }
  3309. });
  3310. var oldCallbacks = [],
  3311. rjsonp = /(=)\?(?=&|$)|\?\?/;
  3312. // Default jsonp settings
  3313. jQuery.ajaxSetup({
  3314. jsonp: "callback",
  3315. jsonpCallback: function () {
  3316. var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
  3317. this[callback] = true;
  3318. return callback;
  3319. }
  3320. });
  3321. // Detect, normalize options and install callbacks for jsonp requests
  3322. jQuery.ajaxPrefilter("json jsonp", function (s, originalSettings, jqXHR) {
  3323. var callbackName, overwritten, responseContainer,
  3324. jsonProp = s.jsonp !== false && ( rjsonp.test(s.url) ?
  3325. "url" :
  3326. typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test(s.data) && "data"
  3327. );
  3328. // Handle iff the expected data type is "jsonp" or we have a parameter to set
  3329. if (jsonProp || s.dataTypes[0] === "jsonp") {
  3330. // Get callback name, remembering preexisting value associated with it
  3331. callbackName = s.jsonpCallback = jQuery.isFunction(s.jsonpCallback) ?
  3332. s.jsonpCallback() :
  3333. s.jsonpCallback;
  3334. // Insert callback into url or form data
  3335. if (jsonProp) {
  3336. s[jsonProp] = s[jsonProp].replace(rjsonp, "$1" + callbackName);
  3337. } else if (s.jsonp !== false) {
  3338. s.url += ( rquery.test(s.url) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
  3339. }
  3340. // Use data converter to retrieve json after script execution
  3341. s.converters["script json"] = function () {
  3342. if (!responseContainer) {
  3343. jQuery.error(callbackName + " was not called");
  3344. }
  3345. return responseContainer[0];
  3346. };
  3347. // force json dataType
  3348. s.dataTypes[0] = "json";
  3349. // Install callback
  3350. overwritten = window[callbackName];
  3351. window[callbackName] = function () {
  3352. responseContainer = arguments;
  3353. };
  3354. // Clean-up function (fires after converters)
  3355. jqXHR.always(function () {
  3356. // Restore preexisting value
  3357. window[callbackName] = overwritten;
  3358. // Save back as free
  3359. if (s[callbackName]) {
  3360. // make sure that re-using the options doesn't screw things around
  3361. s.jsonpCallback = originalSettings.jsonpCallback;
  3362. // save the callback name for future use
  3363. oldCallbacks.push(callbackName);
  3364. }
  3365. // Call if it was a function and we have a response
  3366. if (responseContainer && jQuery.isFunction(overwritten)) {
  3367. overwritten(responseContainer[0]);
  3368. }
  3369. responseContainer = overwritten = undefined;
  3370. });
  3371. // Delegate to script
  3372. return "script";
  3373. }
  3374. });
  3375. // data: string of html
  3376. // context (optional): If specified, the fragment will be created in this context, defaults to document
  3377. // keepScripts (optional): If true, will include scripts passed in the html string
  3378. jQuery.parseHTML = function (data, context, keepScripts) {
  3379. if (!data || typeof data !== "string") {
  3380. return null;
  3381. }
  3382. if (typeof context === "boolean") {
  3383. keepScripts = context;
  3384. context = false;
  3385. }
  3386. context = context || document;
  3387. var parsed = rsingleTag.exec(data),
  3388. scripts = !keepScripts && [];
  3389. // Single tag
  3390. if (parsed) {
  3391. return [context.createElement(parsed[1])];
  3392. }
  3393. parsed = jQuery.buildFragment([data], context, scripts);
  3394. if (scripts && scripts.length) {
  3395. jQuery(scripts).remove();
  3396. }
  3397. return jQuery.merge([], parsed.childNodes);
  3398. };
  3399. return jQuery;
  3400. })();
  3401. var stringifyPrimitive = function(v) {
  3402. switch (typeof v) {
  3403. case 'string':
  3404. return v;
  3405. case 'boolean':
  3406. return v ? 'true' : 'false';
  3407. case 'number':
  3408. return isFinite(v) ? v : '';
  3409. default:
  3410. return '';
  3411. }
  3412. };
  3413. var queryStringify = function(obj, sep, eq, name) {
  3414. sep = sep || '&';
  3415. eq = eq || '=';
  3416. if (obj === null) {
  3417. obj = undefined;
  3418. }
  3419. if (typeof obj === 'object') {
  3420. return Object.keys(obj).map(function(k) {
  3421. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  3422. if (Array.isArray(obj[k])) {
  3423. return obj[k].map(function(v) {
  3424. return ks + encodeURIComponent(stringifyPrimitive(v));
  3425. }).join(sep);
  3426. } else {
  3427. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  3428. }
  3429. }).filter(Boolean).join(sep);
  3430. }
  3431. if (!name) return '';
  3432. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  3433. encodeURIComponent(stringifyPrimitive(obj));
  3434. };
  3435. var request = function (options, callback) {
  3436. options = $.extend(true, {headers: {}, qs: {}}, options);
  3437. // method
  3438. options.type = options.method;
  3439. delete options.method;
  3440. // progress
  3441. if (options.onProgress) {
  3442. options.progress = options.onProgress;
  3443. delete options.onProgress;
  3444. }
  3445. // qs
  3446. if (options.qs) {
  3447. var qsStr = queryStringify(options.qs);
  3448. if (qsStr) {
  3449. options.url += (options.url.indexOf('?') === -1 ? '?' : '&') + qsStr;
  3450. }
  3451. delete options.qs;
  3452. }
  3453. // json
  3454. if (options.json) {
  3455. options.data = options.body;
  3456. delete options.json;
  3457. delete options.body;
  3458. !options.headers && (options.headers = {});
  3459. options.headers['Content-Type'] = 'application/json';
  3460. }
  3461. // body
  3462. if (options.body) {
  3463. if (!(options.body instanceof Blob || options.body.toString() === '[object File]' || options.body.toString() === '[object Blob]')) {
  3464. options.data = options.body;
  3465. delete options.body;
  3466. }
  3467. }
  3468. // headers
  3469. if (options.headers) {
  3470. var headers = options.headers;
  3471. delete options.headers;
  3472. options.beforeSend = function (xhr) {
  3473. for (var key in headers) {
  3474. if (headers.hasOwnProperty(key) &&
  3475. key.toLowerCase() !== 'content-length' &&
  3476. key.toLowerCase() !== 'user-agent' &&
  3477. key.toLowerCase() !== 'origin' &&
  3478. key.toLowerCase() !== 'host') {
  3479. xhr.setRequestHeader(key, headers[key]);
  3480. }
  3481. }
  3482. };
  3483. }
  3484. var getResponse = function (xhr) {
  3485. var headers = {};
  3486. xhr.getAllResponseHeaders().trim().split('\n').forEach(function (item) {
  3487. if (item) {
  3488. var index = item.indexOf(':');
  3489. var key = item.substr(0, index).trim().toLowerCase();
  3490. var val = item.substr(index + 1).trim();
  3491. headers[key] = val;
  3492. }
  3493. });
  3494. return {
  3495. statusCode: xhr.status,
  3496. statusMessage: xhr.statusText,
  3497. headers: headers
  3498. };
  3499. };
  3500. // callback
  3501. options.success = function (data, state, xhr) {
  3502. callback(null, getResponse(xhr), data);
  3503. };
  3504. options.error = function (xhr) {
  3505. if (xhr.responseText) {
  3506. callback(null, getResponse(xhr), xhr.responseText);
  3507. } else {
  3508. callback(xhr.statusText, getResponse(xhr), xhr.responseText);
  3509. }
  3510. };
  3511. options.dataType = 'text';
  3512. // send
  3513. return $.ajax(options);
  3514. };
  3515. module.exports = request;