legacy-debug.js 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835
  1. var $jscomp = $jscomp || {};
  2. $jscomp.scope = {};
  3. $jscomp.ASSUME_ES5 = false;
  4. $jscomp.ASSUME_NO_NATIVE_MAP = false;
  5. $jscomp.ASSUME_NO_NATIVE_SET = false;
  6. $jscomp.defineProperty = $jscomp.ASSUME_ES5 || typeof Object.defineProperties == 'function' ? Object.defineProperty : function(target, property, descriptor) {
  7. descriptor = descriptor;
  8. if (target == Array.prototype || target == Object.prototype) {
  9. return;
  10. }
  11. target[property] = descriptor.value;
  12. };
  13. $jscomp.getGlobal = function(maybeGlobal) {
  14. return typeof window != 'undefined' && window === maybeGlobal ? maybeGlobal : typeof global != 'undefined' && global != null ? global : maybeGlobal;
  15. };
  16. $jscomp.global = $jscomp.getGlobal(this);
  17. $jscomp.polyfill = function(target, polyfill, fromLang, toLang) {
  18. if (!polyfill) {
  19. return;
  20. }
  21. var obj = $jscomp.global;
  22. var split = target.split('.');
  23. for (var i = 0; i < split.length - 1; i++) {
  24. var key = split[i];
  25. if (!(key in obj)) {
  26. obj[key] = {};
  27. }
  28. obj = obj[key];
  29. }
  30. var property = split[split.length - 1];
  31. var orig = obj[property];
  32. var impl = polyfill(orig);
  33. if (impl == orig || impl == null) {
  34. return;
  35. }
  36. $jscomp.defineProperty(obj, property, {configurable:true, writable:true, value:impl});
  37. };
  38. $jscomp.polyfill('Array.prototype.copyWithin', function(orig) {
  39. if (orig) {
  40. return orig;
  41. }
  42. var polyfill = function(target, start, opt_end) {
  43. var len = this.length;
  44. target = Number(target);
  45. start = Number(start);
  46. opt_end = Number(opt_end != null ? opt_end : len);
  47. if (target < start) {
  48. opt_end = Math.min(opt_end, len);
  49. while (start < opt_end) {
  50. if (start in this) {
  51. this[target++] = this[start++];
  52. } else {
  53. delete this[target++];
  54. start++;
  55. }
  56. }
  57. } else {
  58. opt_end = Math.min(opt_end, len + start - target);
  59. target += opt_end - start;
  60. while (opt_end > start) {
  61. if (--opt_end in this) {
  62. this[--target] = this[opt_end];
  63. } else {
  64. delete this[target];
  65. }
  66. }
  67. }
  68. return this;
  69. };
  70. return polyfill;
  71. }, 'es6', 'es3');
  72. $jscomp.SYMBOL_PREFIX = 'jscomp_symbol_';
  73. $jscomp.initSymbol = function() {
  74. $jscomp.initSymbol = function() {
  75. };
  76. if (!$jscomp.global['Symbol']) {
  77. $jscomp.global['Symbol'] = $jscomp.Symbol;
  78. }
  79. };
  80. $jscomp.Symbol = function() {
  81. var counter = 0;
  82. function Symbol(opt_description) {
  83. return $jscomp.SYMBOL_PREFIX + (opt_description || '') + counter++;
  84. }
  85. return Symbol;
  86. }();
  87. $jscomp.initSymbolIterator = function() {
  88. $jscomp.initSymbol();
  89. var symbolIterator = $jscomp.global['Symbol'].iterator;
  90. if (!symbolIterator) {
  91. symbolIterator = $jscomp.global['Symbol'].iterator = $jscomp.global['Symbol']('iterator');
  92. }
  93. if (typeof Array.prototype[symbolIterator] != 'function') {
  94. $jscomp.defineProperty(Array.prototype, symbolIterator, {configurable:true, writable:true, value:function() {
  95. return $jscomp.arrayIterator(this);
  96. }});
  97. }
  98. $jscomp.initSymbolIterator = function() {
  99. };
  100. };
  101. $jscomp.arrayIterator = function(array) {
  102. var index = 0;
  103. return $jscomp.iteratorPrototype(function() {
  104. if (index < array.length) {
  105. return {done:false, value:array[index++]};
  106. } else {
  107. return {done:true};
  108. }
  109. });
  110. };
  111. $jscomp.iteratorPrototype = function(next) {
  112. $jscomp.initSymbolIterator();
  113. var iterator = {next:next};
  114. iterator[$jscomp.global['Symbol'].iterator] = function() {
  115. return this;
  116. };
  117. return iterator;
  118. };
  119. $jscomp.iteratorFromArray = function(array, transform) {
  120. $jscomp.initSymbolIterator();
  121. if (array instanceof String) {
  122. array = array + '';
  123. }
  124. var i = 0;
  125. var iter = {next:function() {
  126. if (i < array.length) {
  127. var index = i++;
  128. return {value:transform(index, array[index]), done:false};
  129. }
  130. iter.next = function() {
  131. return {done:true, value:void 0};
  132. };
  133. return iter.next();
  134. }};
  135. iter[Symbol.iterator] = function() {
  136. return iter;
  137. };
  138. return iter;
  139. };
  140. $jscomp.polyfill('Array.prototype.entries', function(orig) {
  141. if (orig) {
  142. return orig;
  143. }
  144. var polyfill = function() {
  145. return $jscomp.iteratorFromArray(this, function(i, v) {
  146. return [i, v];
  147. });
  148. };
  149. return polyfill;
  150. }, 'es6', 'es3');
  151. $jscomp.polyfill('Array.prototype.fill', function(orig) {
  152. if (orig) {
  153. return orig;
  154. }
  155. var polyfill = function(value, opt_start, opt_end) {
  156. var length = this.length || 0;
  157. if (opt_start < 0) {
  158. opt_start = Math.max(0, length + opt_start);
  159. }
  160. if (opt_end == null || opt_end > length) {
  161. opt_end = length;
  162. }
  163. opt_end = Number(opt_end);
  164. if (opt_end < 0) {
  165. opt_end = Math.max(0, length + opt_end);
  166. }
  167. for (var i = Number(opt_start || 0); i < opt_end; i++) {
  168. this[i] = value;
  169. }
  170. return this;
  171. };
  172. return polyfill;
  173. }, 'es6', 'es3');
  174. $jscomp.findInternal = function(array, callback, thisArg) {
  175. if (array instanceof String) {
  176. array = String(array);
  177. }
  178. var len = array.length;
  179. for (var i = 0; i < len; i++) {
  180. var value = array[i];
  181. if (callback.call(thisArg, value, i, array)) {
  182. return {i:i, v:value};
  183. }
  184. }
  185. return {i:-1, v:void 0};
  186. };
  187. $jscomp.polyfill('Array.prototype.find', function(orig) {
  188. if (orig) {
  189. return orig;
  190. }
  191. var polyfill = function(callback, opt_thisArg) {
  192. return $jscomp.findInternal(this, callback, opt_thisArg).v;
  193. };
  194. return polyfill;
  195. }, 'es6', 'es3');
  196. $jscomp.polyfill('Array.prototype.findIndex', function(orig) {
  197. if (orig) {
  198. return orig;
  199. }
  200. var polyfill = function(callback, opt_thisArg) {
  201. return $jscomp.findInternal(this, callback, opt_thisArg).i;
  202. };
  203. return polyfill;
  204. }, 'es6', 'es3');
  205. $jscomp.polyfill('Array.from', function(orig) {
  206. if (orig) {
  207. return orig;
  208. }
  209. var polyfill = function(arrayLike, opt_mapFn, opt_thisArg) {
  210. $jscomp.initSymbolIterator();
  211. opt_mapFn = opt_mapFn != null ? opt_mapFn : function(x) {
  212. return x;
  213. };
  214. var result = [];
  215. var iteratorFunction = arrayLike[Symbol.iterator];
  216. if (typeof iteratorFunction == 'function') {
  217. arrayLike = iteratorFunction.call(arrayLike);
  218. var next;
  219. var k = 0;
  220. while (!(next = arrayLike.next()).done) {
  221. result.push(opt_mapFn.call(opt_thisArg, next.value, k++));
  222. }
  223. } else {
  224. var len = arrayLike.length;
  225. for (var i = 0; i < len; i++) {
  226. result.push(opt_mapFn.call(opt_thisArg, arrayLike[i], i));
  227. }
  228. }
  229. return result;
  230. };
  231. return polyfill;
  232. }, 'es6', 'es3');
  233. $jscomp.polyfill('Object.is', function(orig) {
  234. if (orig) {
  235. return orig;
  236. }
  237. var polyfill = function(left, right) {
  238. if (left === right) {
  239. return left !== 0 || 1 / left === 1 / right;
  240. } else {
  241. return left !== left && right !== right;
  242. }
  243. };
  244. return polyfill;
  245. }, 'es6', 'es3');
  246. $jscomp.polyfill('Array.prototype.includes', function(orig) {
  247. if (orig) {
  248. return orig;
  249. }
  250. var includes = function(searchElement, opt_fromIndex) {
  251. var array = this;
  252. if (array instanceof String) {
  253. array = String(array);
  254. }
  255. var len = array.length;
  256. var i = opt_fromIndex || 0;
  257. if (i < 0) {
  258. i = Math.max(i + len, 0);
  259. }
  260. for (; i < len; i++) {
  261. var element = array[i];
  262. if (element === searchElement || Object.is(element, searchElement)) {
  263. return true;
  264. }
  265. }
  266. return false;
  267. };
  268. return includes;
  269. }, 'es7', 'es3');
  270. $jscomp.polyfill('Array.prototype.keys', function(orig) {
  271. if (orig) {
  272. return orig;
  273. }
  274. var polyfill = function() {
  275. return $jscomp.iteratorFromArray(this, function(i) {
  276. return i;
  277. });
  278. };
  279. return polyfill;
  280. }, 'es6', 'es3');
  281. $jscomp.polyfill('Array.of', function(orig) {
  282. if (orig) {
  283. return orig;
  284. }
  285. var polyfill = function(var_args) {
  286. return Array.from(arguments);
  287. };
  288. return polyfill;
  289. }, 'es6', 'es3');
  290. $jscomp.polyfill('Array.prototype.values', function(orig) {
  291. if (orig) {
  292. return orig;
  293. }
  294. var polyfill = function() {
  295. return $jscomp.iteratorFromArray(this, function(k, v) {
  296. return v;
  297. });
  298. };
  299. return polyfill;
  300. }, 'es8', 'es3');
  301. $jscomp.makeIterator = function(iterable) {
  302. $jscomp.initSymbolIterator();
  303. var iteratorFunction = iterable[Symbol.iterator];
  304. return iteratorFunction ? iteratorFunction.call(iterable) : $jscomp.arrayIterator(iterable);
  305. };
  306. $jscomp.FORCE_POLYFILL_PROMISE = false;
  307. $jscomp.polyfill('Promise', function(NativePromise) {
  308. if (NativePromise && !$jscomp.FORCE_POLYFILL_PROMISE) {
  309. return NativePromise;
  310. }
  311. function AsyncExecutor() {
  312. this.batch_ = null;
  313. }
  314. AsyncExecutor.prototype.asyncExecute = function(f) {
  315. if (this.batch_ == null) {
  316. this.batch_ = [];
  317. this.asyncExecuteBatch_();
  318. }
  319. this.batch_.push(f);
  320. return this;
  321. };
  322. AsyncExecutor.prototype.asyncExecuteBatch_ = function() {
  323. var self = this;
  324. this.asyncExecuteFunction(function() {
  325. self.executeBatch_();
  326. });
  327. };
  328. var nativeSetTimeout = $jscomp.global['setTimeout'];
  329. AsyncExecutor.prototype.asyncExecuteFunction = function(f) {
  330. nativeSetTimeout(f, 0);
  331. };
  332. AsyncExecutor.prototype.executeBatch_ = function() {
  333. while (this.batch_ && this.batch_.length) {
  334. var executingBatch = this.batch_;
  335. this.batch_ = [];
  336. for (var i = 0; i < executingBatch.length; ++i) {
  337. var f = executingBatch[i];
  338. executingBatch[i] = null;
  339. try {
  340. f();
  341. } catch (error) {
  342. this.asyncThrow_(error);
  343. }
  344. }
  345. }
  346. this.batch_ = null;
  347. };
  348. AsyncExecutor.prototype.asyncThrow_ = function(exception) {
  349. this.asyncExecuteFunction(function() {
  350. throw exception;
  351. });
  352. };
  353. var PromiseState = {PENDING:0, FULFILLED:1, REJECTED:2};
  354. var PolyfillPromise = function(executor) {
  355. this.state_ = PromiseState.PENDING;
  356. this.result_ = undefined;
  357. this.onSettledCallbacks_ = [];
  358. var resolveAndReject = this.createResolveAndReject_();
  359. try {
  360. executor(resolveAndReject.resolve, resolveAndReject.reject);
  361. } catch (e) {
  362. resolveAndReject.reject(e);
  363. }
  364. };
  365. PolyfillPromise.prototype.createResolveAndReject_ = function() {
  366. var thisPromise = this;
  367. var alreadyCalled = false;
  368. function firstCallWins(method) {
  369. return function(x) {
  370. if (!alreadyCalled) {
  371. alreadyCalled = true;
  372. method.call(thisPromise, x);
  373. }
  374. };
  375. }
  376. return {resolve:firstCallWins(this.resolveTo_), reject:firstCallWins(this.reject_)};
  377. };
  378. PolyfillPromise.prototype.resolveTo_ = function(value) {
  379. if (value === this) {
  380. this.reject_(new TypeError('A Promise cannot resolve to itself'));
  381. } else {
  382. if (value instanceof PolyfillPromise) {
  383. this.settleSameAsPromise_(value);
  384. } else {
  385. if (isObject(value)) {
  386. this.resolveToNonPromiseObj_(value);
  387. } else {
  388. this.fulfill_(value);
  389. }
  390. }
  391. }
  392. };
  393. PolyfillPromise.prototype.resolveToNonPromiseObj_ = function(obj) {
  394. var thenMethod = undefined;
  395. try {
  396. thenMethod = obj.then;
  397. } catch (error) {
  398. this.reject_(error);
  399. return;
  400. }
  401. if (typeof thenMethod == 'function') {
  402. this.settleSameAsThenable_(thenMethod, obj);
  403. } else {
  404. this.fulfill_(obj);
  405. }
  406. };
  407. function isObject(value) {
  408. switch(typeof value) {
  409. case 'object':
  410. return value != null;
  411. case 'function':
  412. return true;
  413. default:
  414. return false;
  415. }
  416. }
  417. PolyfillPromise.prototype.reject_ = function(reason) {
  418. this.settle_(PromiseState.REJECTED, reason);
  419. };
  420. PolyfillPromise.prototype.fulfill_ = function(value) {
  421. this.settle_(PromiseState.FULFILLED, value);
  422. };
  423. PolyfillPromise.prototype.settle_ = function(settledState, valueOrReason) {
  424. if (this.state_ != PromiseState.PENDING) {
  425. throw new Error('Cannot settle(' + settledState + ', ' + valueOrReason + '): Promise already settled in state' + this.state_);
  426. }
  427. this.state_ = settledState;
  428. this.result_ = valueOrReason;
  429. this.executeOnSettledCallbacks_();
  430. };
  431. PolyfillPromise.prototype.executeOnSettledCallbacks_ = function() {
  432. if (this.onSettledCallbacks_ != null) {
  433. for (var i = 0; i < this.onSettledCallbacks_.length; ++i) {
  434. asyncExecutor.asyncExecute(this.onSettledCallbacks_[i]);
  435. }
  436. this.onSettledCallbacks_ = null;
  437. }
  438. };
  439. var asyncExecutor = new AsyncExecutor;
  440. PolyfillPromise.prototype.settleSameAsPromise_ = function(promise) {
  441. var methods = this.createResolveAndReject_();
  442. promise.callWhenSettled_(methods.resolve, methods.reject);
  443. };
  444. PolyfillPromise.prototype.settleSameAsThenable_ = function(thenMethod, thenable) {
  445. var methods = this.createResolveAndReject_();
  446. try {
  447. thenMethod.call(thenable, methods.resolve, methods.reject);
  448. } catch (error) {
  449. methods.reject(error);
  450. }
  451. };
  452. PolyfillPromise.prototype.then = function(onFulfilled, onRejected) {
  453. var resolveChild;
  454. var rejectChild;
  455. var childPromise = new PolyfillPromise(function(resolve, reject) {
  456. resolveChild = resolve;
  457. rejectChild = reject;
  458. });
  459. function createCallback(paramF, defaultF) {
  460. if (typeof paramF == 'function') {
  461. return function(x) {
  462. try {
  463. resolveChild(paramF(x));
  464. } catch (error) {
  465. rejectChild(error);
  466. }
  467. };
  468. } else {
  469. return defaultF;
  470. }
  471. }
  472. this.callWhenSettled_(createCallback(onFulfilled, resolveChild), createCallback(onRejected, rejectChild));
  473. return childPromise;
  474. };
  475. PolyfillPromise.prototype['catch'] = function(onRejected) {
  476. return this.then(undefined, onRejected);
  477. };
  478. PolyfillPromise.prototype.callWhenSettled_ = function(onFulfilled, onRejected) {
  479. var thisPromise = this;
  480. function callback() {
  481. switch(thisPromise.state_) {
  482. case PromiseState.FULFILLED:
  483. onFulfilled(thisPromise.result_);
  484. break;
  485. case PromiseState.REJECTED:
  486. onRejected(thisPromise.result_);
  487. break;
  488. default:
  489. throw new Error('Unexpected state: ' + thisPromise.state_);
  490. }
  491. }
  492. if (this.onSettledCallbacks_ == null) {
  493. asyncExecutor.asyncExecute(callback);
  494. } else {
  495. this.onSettledCallbacks_.push(callback);
  496. }
  497. };
  498. function resolvingPromise(opt_value) {
  499. if (opt_value instanceof PolyfillPromise) {
  500. return opt_value;
  501. } else {
  502. return new PolyfillPromise(function(resolve, reject) {
  503. resolve(opt_value);
  504. });
  505. }
  506. }
  507. PolyfillPromise['resolve'] = resolvingPromise;
  508. PolyfillPromise['reject'] = function(opt_reason) {
  509. return new PolyfillPromise(function(resolve, reject) {
  510. reject(opt_reason);
  511. });
  512. };
  513. PolyfillPromise['race'] = function(thenablesOrValues) {
  514. return new PolyfillPromise(function(resolve, reject) {
  515. var iterator = $jscomp.makeIterator(thenablesOrValues);
  516. for (var iterRec = iterator.next(); !iterRec.done; iterRec = iterator.next()) {
  517. resolvingPromise(iterRec.value).callWhenSettled_(resolve, reject);
  518. }
  519. });
  520. };
  521. PolyfillPromise['all'] = function(thenablesOrValues) {
  522. var iterator = $jscomp.makeIterator(thenablesOrValues);
  523. var iterRec = iterator.next();
  524. if (iterRec.done) {
  525. return resolvingPromise([]);
  526. } else {
  527. return new PolyfillPromise(function(resolveAll, rejectAll) {
  528. var resultsArray = [];
  529. var unresolvedCount = 0;
  530. function onFulfilled(i) {
  531. return function(ithResult) {
  532. resultsArray[i] = ithResult;
  533. unresolvedCount--;
  534. if (unresolvedCount == 0) {
  535. resolveAll(resultsArray);
  536. }
  537. };
  538. }
  539. do {
  540. resultsArray.push(undefined);
  541. unresolvedCount++;
  542. resolvingPromise(iterRec.value).callWhenSettled_(onFulfilled(resultsArray.length - 1), rejectAll);
  543. iterRec = iterator.next();
  544. } while (!iterRec.done);
  545. });
  546. }
  547. };
  548. return PolyfillPromise;
  549. }, 'es6', 'es3');
  550. $jscomp.polyfill('Promise.prototype.finally', function(orig) {
  551. if (orig) {
  552. return orig;
  553. }
  554. var polyfill = function(onFinally) {
  555. return this.then(function(value) {
  556. var promise = Promise.resolve(onFinally());
  557. return promise.then(function() {
  558. return value;
  559. });
  560. }, function(reason) {
  561. var promise = Promise.resolve(onFinally());
  562. return promise.then(function() {
  563. throw reason;
  564. });
  565. });
  566. };
  567. return polyfill;
  568. }, 'es9', 'es3');
  569. $jscomp.underscoreProtoCanBeSet = function() {
  570. var x = {a:true};
  571. var y = {};
  572. try {
  573. y.__proto__ = x;
  574. return y.a;
  575. } catch (e) {
  576. }
  577. return false;
  578. };
  579. $jscomp.setPrototypeOf = typeof Object.setPrototypeOf == 'function' ? Object.setPrototypeOf : $jscomp.underscoreProtoCanBeSet() ? function(target, proto) {
  580. target.__proto__ = proto;
  581. if (target.__proto__ !== proto) {
  582. throw new TypeError(target + ' is not extensible');
  583. }
  584. return target;
  585. } : null;
  586. $jscomp.generator = {};
  587. $jscomp.generator.ensureIteratorResultIsObject_ = function(result) {
  588. if (result instanceof Object) {
  589. return;
  590. }
  591. throw new TypeError('Iterator result ' + result + ' is not an object');
  592. };
  593. $jscomp.generator.Context = function() {
  594. this.isRunning_ = false;
  595. this.yieldAllIterator_ = null;
  596. this.yieldResult = undefined;
  597. this.nextAddress = 1;
  598. this.catchAddress_ = 0;
  599. this.finallyAddress_ = 0;
  600. this.abruptCompletion_ = null;
  601. this.finallyContexts_ = null;
  602. };
  603. $jscomp.generator.Context.prototype.start_ = function() {
  604. if (this.isRunning_) {
  605. throw new TypeError('Generator is already running');
  606. }
  607. this.isRunning_ = true;
  608. };
  609. $jscomp.generator.Context.prototype.stop_ = function() {
  610. this.isRunning_ = false;
  611. };
  612. $jscomp.generator.Context.prototype.jumpToErrorHandler_ = function() {
  613. this.nextAddress = this.catchAddress_ || this.finallyAddress_;
  614. };
  615. $jscomp.generator.Context.prototype.next_ = function(value) {
  616. this.yieldResult = value;
  617. };
  618. $jscomp.generator.Context.prototype.throw_ = function(e) {
  619. this.abruptCompletion_ = {exception:e, isException:true};
  620. this.jumpToErrorHandler_();
  621. };
  622. $jscomp.generator.Context.prototype['return'] = function(value) {
  623. this.abruptCompletion_ = {'return':value};
  624. this.nextAddress = this.finallyAddress_;
  625. };
  626. $jscomp.generator.Context.prototype.jumpThroughFinallyBlocks = function(nextAddress) {
  627. this.abruptCompletion_ = {jumpTo:nextAddress};
  628. this.nextAddress = this.finallyAddress_;
  629. };
  630. $jscomp.generator.Context.prototype.yield = function(value, resumeAddress) {
  631. this.nextAddress = resumeAddress;
  632. return {value:value};
  633. };
  634. $jscomp.generator.Context.prototype.yieldAll = function(iterable, resumeAddress) {
  635. var iterator = $jscomp.makeIterator(iterable);
  636. var result = iterator.next();
  637. $jscomp.generator.ensureIteratorResultIsObject_(result);
  638. if (result.done) {
  639. this.yieldResult = result.value;
  640. this.nextAddress = resumeAddress;
  641. return;
  642. }
  643. this.yieldAllIterator_ = iterator;
  644. return this.yield(result.value, resumeAddress);
  645. };
  646. $jscomp.generator.Context.prototype.jumpTo = function(nextAddress) {
  647. this.nextAddress = nextAddress;
  648. };
  649. $jscomp.generator.Context.prototype.jumpToEnd = function() {
  650. this.nextAddress = 0;
  651. };
  652. $jscomp.generator.Context.prototype.setCatchFinallyBlocks = function(catchAddress, finallyAddress) {
  653. this.catchAddress_ = catchAddress;
  654. if (finallyAddress != undefined) {
  655. this.finallyAddress_ = finallyAddress;
  656. }
  657. };
  658. $jscomp.generator.Context.prototype.setFinallyBlock = function(finallyAddress) {
  659. this.catchAddress_ = 0;
  660. this.finallyAddress_ = finallyAddress || 0;
  661. };
  662. $jscomp.generator.Context.prototype.leaveTryBlock = function(nextAddress, catchAddress) {
  663. this.nextAddress = nextAddress;
  664. this.catchAddress_ = catchAddress || 0;
  665. };
  666. $jscomp.generator.Context.prototype.enterCatchBlock = function(nextCatchBlockAddress) {
  667. this.catchAddress_ = nextCatchBlockAddress || 0;
  668. var exception = this.abruptCompletion_.exception;
  669. this.abruptCompletion_ = null;
  670. return exception;
  671. };
  672. $jscomp.generator.Context.prototype.enterFinallyBlock = function(nextCatchAddress, nextFinallyAddress, finallyDepth) {
  673. if (!finallyDepth) {
  674. this.finallyContexts_ = [this.abruptCompletion_];
  675. } else {
  676. this.finallyContexts_[finallyDepth] = this.abruptCompletion_;
  677. }
  678. this.catchAddress_ = nextCatchAddress || 0;
  679. this.finallyAddress_ = nextFinallyAddress || 0;
  680. };
  681. $jscomp.generator.Context.prototype.leaveFinallyBlock = function(nextAddress, finallyDepth) {
  682. var preservedContext = this.finallyContexts_.splice(finallyDepth || 0)[0];
  683. var abruptCompletion = this.abruptCompletion_ = this.abruptCompletion_ || preservedContext;
  684. if (abruptCompletion) {
  685. if (abruptCompletion.isException) {
  686. return this.jumpToErrorHandler_();
  687. }
  688. if (abruptCompletion.jumpTo != undefined && this.finallyAddress_ < abruptCompletion.jumpTo) {
  689. this.nextAddress = abruptCompletion.jumpTo;
  690. this.abruptCompletion_ = null;
  691. } else {
  692. this.nextAddress = this.finallyAddress_;
  693. }
  694. } else {
  695. this.nextAddress = nextAddress;
  696. }
  697. };
  698. $jscomp.generator.Context.prototype.forIn = function(object) {
  699. return new $jscomp.generator.Context.PropertyIterator(object);
  700. };
  701. $jscomp.generator.Context.PropertyIterator = function(object) {
  702. this.object_ = object;
  703. this.properties_ = [];
  704. for (var property in object) {
  705. this.properties_.push(property);
  706. }
  707. this.properties_.reverse();
  708. };
  709. $jscomp.generator.Context.PropertyIterator.prototype.getNext = function() {
  710. while (this.properties_.length > 0) {
  711. var property = this.properties_.pop();
  712. if (property in this.object_) {
  713. return property;
  714. }
  715. }
  716. return null;
  717. };
  718. $jscomp.generator.Engine_ = function(program) {
  719. this.context_ = new $jscomp.generator.Context;
  720. this.program_ = program;
  721. };
  722. $jscomp.generator.Engine_.prototype.next_ = function(value) {
  723. this.context_.start_();
  724. if (this.context_.yieldAllIterator_) {
  725. return this.yieldAllStep_(this.context_.yieldAllIterator_.next, value, this.context_.next_);
  726. }
  727. this.context_.next_(value);
  728. return this.nextStep_();
  729. };
  730. $jscomp.generator.Engine_.prototype.return_ = function(value) {
  731. this.context_.start_();
  732. var yieldAllIterator = this.context_.yieldAllIterator_;
  733. if (yieldAllIterator) {
  734. var returnFunction = 'return' in yieldAllIterator ? yieldAllIterator['return'] : function(v) {
  735. return {value:v, done:true};
  736. };
  737. return this.yieldAllStep_(returnFunction, value, this.context_['return']);
  738. }
  739. this.context_['return'](value);
  740. return this.nextStep_();
  741. };
  742. $jscomp.generator.Engine_.prototype.throw_ = function(exception) {
  743. this.context_.start_();
  744. if (this.context_.yieldAllIterator_) {
  745. return this.yieldAllStep_(this.context_.yieldAllIterator_['throw'], exception, this.context_.next_);
  746. }
  747. this.context_.throw_(exception);
  748. return this.nextStep_();
  749. };
  750. $jscomp.generator.Engine_.prototype.yieldAllStep_ = function(action, value, nextAction) {
  751. try {
  752. var result = action.call(this.context_.yieldAllIterator_, value);
  753. $jscomp.generator.ensureIteratorResultIsObject_(result);
  754. if (!result.done) {
  755. this.context_.stop_();
  756. return result;
  757. }
  758. var resultValue = result.value;
  759. } catch (e) {
  760. this.context_.yieldAllIterator_ = null;
  761. this.context_.throw_(e);
  762. return this.nextStep_();
  763. }
  764. this.context_.yieldAllIterator_ = null;
  765. nextAction.call(this.context_, resultValue);
  766. return this.nextStep_();
  767. };
  768. $jscomp.generator.Engine_.prototype.nextStep_ = function() {
  769. while (this.context_.nextAddress) {
  770. try {
  771. var yieldValue = this.program_(this.context_);
  772. if (yieldValue) {
  773. this.context_.stop_();
  774. return {value:yieldValue.value, done:false};
  775. }
  776. } catch (e) {
  777. this.context_.yieldResult = undefined;
  778. this.context_.throw_(e);
  779. }
  780. }
  781. this.context_.stop_();
  782. if (this.context_.abruptCompletion_) {
  783. var abruptCompletion = this.context_.abruptCompletion_;
  784. this.context_.abruptCompletion_ = null;
  785. if (abruptCompletion.isException) {
  786. throw abruptCompletion.exception;
  787. }
  788. return {value:abruptCompletion['return'], done:true};
  789. }
  790. return {value:undefined, done:true};
  791. };
  792. $jscomp.generator.Generator_ = function(engine) {
  793. this.next = function(opt_value) {
  794. return engine.next_(opt_value);
  795. };
  796. this['throw'] = function(exception) {
  797. return engine.throw_(exception);
  798. };
  799. this['return'] = function(value) {
  800. return engine.return_(value);
  801. };
  802. $jscomp.initSymbolIterator();
  803. this[Symbol.iterator] = function() {
  804. return this;
  805. };
  806. };
  807. $jscomp.generator.createGenerator = function(generator, program) {
  808. var result = new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(program));
  809. if ($jscomp.setPrototypeOf) {
  810. $jscomp.setPrototypeOf(result, generator.prototype);
  811. }
  812. return result;
  813. };
  814. $jscomp.asyncExecutePromiseGenerator = function(generator) {
  815. function passValueToGenerator(value) {
  816. return generator.next(value);
  817. }
  818. function passErrorToGenerator(error) {
  819. return generator['throw'](error);
  820. }
  821. return new Promise(function(resolve, reject) {
  822. function handleGeneratorRecord(genRec) {
  823. if (genRec.done) {
  824. resolve(genRec.value);
  825. } else {
  826. Promise.resolve(genRec.value).then(passValueToGenerator, passErrorToGenerator).then(handleGeneratorRecord, reject);
  827. }
  828. }
  829. handleGeneratorRecord(generator.next());
  830. });
  831. };
  832. $jscomp.asyncExecutePromiseGeneratorFunction = function(generatorFunction) {
  833. return $jscomp.asyncExecutePromiseGenerator(generatorFunction());
  834. };
  835. $jscomp.asyncExecutePromiseGeneratorProgram = function(program) {
  836. return $jscomp.asyncExecutePromiseGenerator(new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(program)));
  837. };
  838. $jscomp.checkEs6ConformanceViaProxy = function() {
  839. try {
  840. var proxied = {};
  841. var proxy = Object.create(new $jscomp.global['Proxy'](proxied, {'get':function(target, key, receiver) {
  842. return target == proxied && key == 'q' && receiver == proxy;
  843. }}));
  844. return proxy['q'] === true;
  845. } catch (err) {
  846. return false;
  847. }
  848. };
  849. $jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS = false;
  850. $jscomp.ES6_CONFORMANCE = $jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS && $jscomp.checkEs6ConformanceViaProxy();
  851. $jscomp.owns = function(obj, prop) {
  852. return Object.prototype.hasOwnProperty.call(obj, prop);
  853. };
  854. $jscomp.polyfill('WeakMap', function(NativeWeakMap) {
  855. function isConformant() {
  856. if (!NativeWeakMap || !Object.seal) {
  857. return false;
  858. }
  859. try {
  860. var x = Object.seal({});
  861. var y = Object.seal({});
  862. var map = new NativeWeakMap([[x, 2], [y, 3]]);
  863. if (map.get(x) != 2 || map.get(y) != 3) {
  864. return false;
  865. }
  866. map['delete'](x);
  867. map.set(y, 4);
  868. return !map.has(x) && map.get(y) == 4;
  869. } catch (err) {
  870. return false;
  871. }
  872. }
  873. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  874. if (NativeWeakMap && $jscomp.ES6_CONFORMANCE) {
  875. return NativeWeakMap;
  876. }
  877. } else {
  878. if (isConformant()) {
  879. return NativeWeakMap;
  880. }
  881. }
  882. var prop = '$jscomp_hidden_' + Math.random();
  883. function insert(target) {
  884. if (!$jscomp.owns(target, prop)) {
  885. var obj = {};
  886. $jscomp.defineProperty(target, prop, {value:obj});
  887. }
  888. }
  889. function patch(name) {
  890. var prev = Object[name];
  891. if (prev) {
  892. Object[name] = function(target) {
  893. insert(target);
  894. return prev(target);
  895. };
  896. }
  897. }
  898. patch('freeze');
  899. patch('preventExtensions');
  900. patch('seal');
  901. var index = 0;
  902. var PolyfillWeakMap = function(opt_iterable) {
  903. this.id_ = (index += Math.random() + 1).toString();
  904. if (opt_iterable) {
  905. $jscomp.initSymbol();
  906. $jscomp.initSymbolIterator();
  907. var iter = $jscomp.makeIterator(opt_iterable);
  908. var entry;
  909. while (!(entry = iter.next()).done) {
  910. var item = entry.value;
  911. this.set(item[0], item[1]);
  912. }
  913. }
  914. };
  915. PolyfillWeakMap.prototype.set = function(key, value) {
  916. insert(key);
  917. if (!$jscomp.owns(key, prop)) {
  918. throw new Error('WeakMap key fail: ' + key);
  919. }
  920. key[prop][this.id_] = value;
  921. return this;
  922. };
  923. PolyfillWeakMap.prototype.get = function(key) {
  924. return $jscomp.owns(key, prop) ? key[prop][this.id_] : undefined;
  925. };
  926. PolyfillWeakMap.prototype.has = function(key) {
  927. return $jscomp.owns(key, prop) && $jscomp.owns(key[prop], this.id_);
  928. };
  929. PolyfillWeakMap.prototype['delete'] = function(key) {
  930. if (!$jscomp.owns(key, prop) || !$jscomp.owns(key[prop], this.id_)) {
  931. return false;
  932. }
  933. return delete key[prop][this.id_];
  934. };
  935. return PolyfillWeakMap;
  936. }, 'es6', 'es3');
  937. $jscomp.MapEntry = function() {
  938. this.previous;
  939. this.next;
  940. this.head;
  941. this.key;
  942. this.value;
  943. };
  944. $jscomp.polyfill('Map', function(NativeMap) {
  945. function isConformant() {
  946. if ($jscomp.ASSUME_NO_NATIVE_MAP || !NativeMap || typeof NativeMap != 'function' || !NativeMap.prototype.entries || typeof Object.seal != 'function') {
  947. return false;
  948. }
  949. try {
  950. NativeMap = NativeMap;
  951. var key = Object.seal({x:4});
  952. var map = new NativeMap($jscomp.makeIterator([[key, 's']]));
  953. if (map.get(key) != 's' || map.size != 1 || map.get({x:4}) || map.set({x:4}, 't') != map || map.size != 2) {
  954. return false;
  955. }
  956. var iter = map.entries();
  957. var item = iter.next();
  958. if (item.done || item.value[0] != key || item.value[1] != 's') {
  959. return false;
  960. }
  961. item = iter.next();
  962. if (item.done || item.value[0].x != 4 || item.value[1] != 't' || !iter.next().done) {
  963. return false;
  964. }
  965. return true;
  966. } catch (err) {
  967. return false;
  968. }
  969. }
  970. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  971. if (NativeMap && $jscomp.ES6_CONFORMANCE) {
  972. return NativeMap;
  973. }
  974. } else {
  975. if (isConformant()) {
  976. return NativeMap;
  977. }
  978. }
  979. $jscomp.initSymbol();
  980. $jscomp.initSymbolIterator();
  981. var idMap = new WeakMap;
  982. var PolyfillMap = function(opt_iterable) {
  983. this.data_ = {};
  984. this.head_ = createHead();
  985. this.size = 0;
  986. if (opt_iterable) {
  987. var iter = $jscomp.makeIterator(opt_iterable);
  988. var entry;
  989. while (!(entry = iter.next()).done) {
  990. var item = entry.value;
  991. this.set(item[0], item[1]);
  992. }
  993. }
  994. };
  995. PolyfillMap.prototype.set = function(key, value) {
  996. key = key === 0 ? 0 : key;
  997. var r = maybeGetEntry(this, key);
  998. if (!r.list) {
  999. r.list = this.data_[r.id] = [];
  1000. }
  1001. if (!r.entry) {
  1002. r.entry = {next:this.head_, previous:this.head_.previous, head:this.head_, key:key, value:value};
  1003. r.list.push(r.entry);
  1004. this.head_.previous.next = r.entry;
  1005. this.head_.previous = r.entry;
  1006. this.size++;
  1007. } else {
  1008. r.entry.value = value;
  1009. }
  1010. return this;
  1011. };
  1012. PolyfillMap.prototype['delete'] = function(key) {
  1013. var r = maybeGetEntry(this, key);
  1014. if (r.entry && r.list) {
  1015. r.list.splice(r.index, 1);
  1016. if (!r.list.length) {
  1017. delete this.data_[r.id];
  1018. }
  1019. r.entry.previous.next = r.entry.next;
  1020. r.entry.next.previous = r.entry.previous;
  1021. r.entry.head = null;
  1022. this.size--;
  1023. return true;
  1024. }
  1025. return false;
  1026. };
  1027. PolyfillMap.prototype.clear = function() {
  1028. this.data_ = {};
  1029. this.head_ = this.head_.previous = createHead();
  1030. this.size = 0;
  1031. };
  1032. PolyfillMap.prototype.has = function(key) {
  1033. return !!maybeGetEntry(this, key).entry;
  1034. };
  1035. PolyfillMap.prototype.get = function(key) {
  1036. var entry = maybeGetEntry(this, key).entry;
  1037. return entry && entry.value;
  1038. };
  1039. PolyfillMap.prototype.entries = function() {
  1040. return makeIterator(this, function(entry) {
  1041. return [entry.key, entry.value];
  1042. });
  1043. };
  1044. PolyfillMap.prototype.keys = function() {
  1045. return makeIterator(this, function(entry) {
  1046. return entry.key;
  1047. });
  1048. };
  1049. PolyfillMap.prototype.values = function() {
  1050. return makeIterator(this, function(entry) {
  1051. return entry.value;
  1052. });
  1053. };
  1054. PolyfillMap.prototype.forEach = function(callback, opt_thisArg) {
  1055. var iter = this.entries();
  1056. var item;
  1057. while (!(item = iter.next()).done) {
  1058. var entry = item.value;
  1059. callback.call(opt_thisArg, entry[1], entry[0], this);
  1060. }
  1061. };
  1062. PolyfillMap.prototype[Symbol.iterator] = PolyfillMap.prototype.entries;
  1063. var maybeGetEntry = function(map, key) {
  1064. var id = getId(key);
  1065. var list = map.data_[id];
  1066. if (list && $jscomp.owns(map.data_, id)) {
  1067. for (var index = 0; index < list.length; index++) {
  1068. var entry = list[index];
  1069. if (key !== key && entry.key !== entry.key || key === entry.key) {
  1070. return {id:id, list:list, index:index, entry:entry};
  1071. }
  1072. }
  1073. }
  1074. return {id:id, list:list, index:-1, entry:undefined};
  1075. };
  1076. var makeIterator = function(map, func) {
  1077. var entry = map.head_;
  1078. return $jscomp.iteratorPrototype(function() {
  1079. if (entry) {
  1080. while (entry.head != map.head_) {
  1081. entry = entry.previous;
  1082. }
  1083. while (entry.next != entry.head) {
  1084. entry = entry.next;
  1085. return {done:false, value:func(entry)};
  1086. }
  1087. entry = null;
  1088. }
  1089. return {done:true, value:void 0};
  1090. });
  1091. };
  1092. var createHead = function() {
  1093. var head = {};
  1094. head.previous = head.next = head.head = head;
  1095. return head;
  1096. };
  1097. var mapIndex = 0;
  1098. var getId = function(obj) {
  1099. var type = obj && typeof obj;
  1100. if (type == 'object' || type == 'function') {
  1101. obj = obj;
  1102. if (!idMap.has(obj)) {
  1103. var id = '' + ++mapIndex;
  1104. idMap.set(obj, id);
  1105. return id;
  1106. }
  1107. return idMap.get(obj);
  1108. }
  1109. return 'p_' + obj;
  1110. };
  1111. return PolyfillMap;
  1112. }, 'es6', 'es3');
  1113. $jscomp.polyfill('Math.acosh', function(orig) {
  1114. if (orig) {
  1115. return orig;
  1116. }
  1117. var polyfill = function(x) {
  1118. x = Number(x);
  1119. return Math.log(x + Math.sqrt(x * x - 1));
  1120. };
  1121. return polyfill;
  1122. }, 'es6', 'es3');
  1123. $jscomp.polyfill('Math.asinh', function(orig) {
  1124. if (orig) {
  1125. return orig;
  1126. }
  1127. var polyfill = function(x) {
  1128. x = Number(x);
  1129. if (x === 0) {
  1130. return x;
  1131. }
  1132. var y = Math.log(Math.abs(x) + Math.sqrt(x * x + 1));
  1133. return x < 0 ? -y : y;
  1134. };
  1135. return polyfill;
  1136. }, 'es6', 'es3');
  1137. $jscomp.polyfill('Math.log1p', function(orig) {
  1138. if (orig) {
  1139. return orig;
  1140. }
  1141. var polyfill = function(x) {
  1142. x = Number(x);
  1143. if (x < 0.25 && x > -0.25) {
  1144. var y = x;
  1145. var d = 1;
  1146. var z = x;
  1147. var zPrev = 0;
  1148. var s = 1;
  1149. while (zPrev != z) {
  1150. y *= x;
  1151. s *= -1;
  1152. z = (zPrev = z) + s * y / ++d;
  1153. }
  1154. return z;
  1155. }
  1156. return Math.log(1 + x);
  1157. };
  1158. return polyfill;
  1159. }, 'es6', 'es3');
  1160. $jscomp.polyfill('Math.atanh', function(orig) {
  1161. if (orig) {
  1162. return orig;
  1163. }
  1164. var log1p = Math.log1p;
  1165. var polyfill = function(x) {
  1166. x = Number(x);
  1167. return (log1p(x) - log1p(-x)) / 2;
  1168. };
  1169. return polyfill;
  1170. }, 'es6', 'es3');
  1171. $jscomp.polyfill('Math.cbrt', function(orig) {
  1172. if (orig) {
  1173. return orig;
  1174. }
  1175. var polyfill = function(x) {
  1176. if (x === 0) {
  1177. return x;
  1178. }
  1179. x = Number(x);
  1180. var y = Math.pow(Math.abs(x), 1 / 3);
  1181. return x < 0 ? -y : y;
  1182. };
  1183. return polyfill;
  1184. }, 'es6', 'es3');
  1185. $jscomp.polyfill('Math.clz32', function(orig) {
  1186. if (orig) {
  1187. return orig;
  1188. }
  1189. var polyfill = function(x) {
  1190. x = Number(x) >>> 0;
  1191. if (x === 0) {
  1192. return 32;
  1193. }
  1194. var result = 0;
  1195. if ((x & 4294901760) === 0) {
  1196. x <<= 16;
  1197. result += 16;
  1198. }
  1199. if ((x & 4278190080) === 0) {
  1200. x <<= 8;
  1201. result += 8;
  1202. }
  1203. if ((x & 4026531840) === 0) {
  1204. x <<= 4;
  1205. result += 4;
  1206. }
  1207. if ((x & 3221225472) === 0) {
  1208. x <<= 2;
  1209. result += 2;
  1210. }
  1211. if ((x & 2147483648) === 0) {
  1212. result++;
  1213. }
  1214. return result;
  1215. };
  1216. return polyfill;
  1217. }, 'es6', 'es3');
  1218. $jscomp.polyfill('Math.cosh', function(orig) {
  1219. if (orig) {
  1220. return orig;
  1221. }
  1222. var exp = Math.exp;
  1223. var polyfill = function(x) {
  1224. x = Number(x);
  1225. return (exp(x) + exp(-x)) / 2;
  1226. };
  1227. return polyfill;
  1228. }, 'es6', 'es3');
  1229. $jscomp.polyfill('Math.expm1', function(orig) {
  1230. if (orig) {
  1231. return orig;
  1232. }
  1233. var polyfill = function(x) {
  1234. x = Number(x);
  1235. if (x < .25 && x > -.25) {
  1236. var y = x;
  1237. var d = 1;
  1238. var z = x;
  1239. var zPrev = 0;
  1240. while (zPrev != z) {
  1241. y *= x / ++d;
  1242. z = (zPrev = z) + y;
  1243. }
  1244. return z;
  1245. }
  1246. return Math.exp(x) - 1;
  1247. };
  1248. return polyfill;
  1249. }, 'es6', 'es3');
  1250. $jscomp.polyfill('Math.hypot', function(orig) {
  1251. if (orig) {
  1252. return orig;
  1253. }
  1254. var polyfill = function(x, y, var_args) {
  1255. x = Number(x);
  1256. y = Number(y);
  1257. var i, z, sum;
  1258. var max = Math.max(Math.abs(x), Math.abs(y));
  1259. for (i = 2; i < arguments.length; i++) {
  1260. max = Math.max(max, Math.abs(arguments[i]));
  1261. }
  1262. if (max > 1e100 || max < 1e-100) {
  1263. if (!max) {
  1264. return max;
  1265. }
  1266. x = x / max;
  1267. y = y / max;
  1268. sum = x * x + y * y;
  1269. for (i = 2; i < arguments.length; i++) {
  1270. z = Number(arguments[i]) / max;
  1271. sum += z * z;
  1272. }
  1273. return Math.sqrt(sum) * max;
  1274. } else {
  1275. sum = x * x + y * y;
  1276. for (i = 2; i < arguments.length; i++) {
  1277. z = Number(arguments[i]);
  1278. sum += z * z;
  1279. }
  1280. return Math.sqrt(sum);
  1281. }
  1282. };
  1283. return polyfill;
  1284. }, 'es6', 'es3');
  1285. $jscomp.polyfill('Math.imul', function(orig) {
  1286. if (orig) {
  1287. return orig;
  1288. }
  1289. var polyfill = function(a, b) {
  1290. a = Number(a);
  1291. b = Number(b);
  1292. var ah = a >>> 16 & 65535;
  1293. var al = a & 65535;
  1294. var bh = b >>> 16 & 65535;
  1295. var bl = b & 65535;
  1296. var lh = ah * bl + al * bh << 16 >>> 0;
  1297. return al * bl + lh | 0;
  1298. };
  1299. return polyfill;
  1300. }, 'es6', 'es3');
  1301. $jscomp.polyfill('Math.log10', function(orig) {
  1302. if (orig) {
  1303. return orig;
  1304. }
  1305. var polyfill = function(x) {
  1306. return Math.log(x) / Math.LN10;
  1307. };
  1308. return polyfill;
  1309. }, 'es6', 'es3');
  1310. $jscomp.polyfill('Math.log2', function(orig) {
  1311. if (orig) {
  1312. return orig;
  1313. }
  1314. var polyfill = function(x) {
  1315. return Math.log(x) / Math.LN2;
  1316. };
  1317. return polyfill;
  1318. }, 'es6', 'es3');
  1319. $jscomp.polyfill('Math.sign', function(orig) {
  1320. if (orig) {
  1321. return orig;
  1322. }
  1323. var polyfill = function(x) {
  1324. x = Number(x);
  1325. return x === 0 || isNaN(x) ? x : x > 0 ? 1 : -1;
  1326. };
  1327. return polyfill;
  1328. }, 'es6', 'es3');
  1329. $jscomp.polyfill('Math.sinh', function(orig) {
  1330. if (orig) {
  1331. return orig;
  1332. }
  1333. var exp = Math.exp;
  1334. var polyfill = function(x) {
  1335. x = Number(x);
  1336. if (x === 0) {
  1337. return x;
  1338. }
  1339. return (exp(x) - exp(-x)) / 2;
  1340. };
  1341. return polyfill;
  1342. }, 'es6', 'es3');
  1343. $jscomp.polyfill('Math.tanh', function(orig) {
  1344. if (orig) {
  1345. return orig;
  1346. }
  1347. var polyfill = function(x) {
  1348. x = Number(x);
  1349. if (x === 0) {
  1350. return x;
  1351. }
  1352. var y = Math.exp(-2 * Math.abs(x));
  1353. var z = (1 - y) / (1 + y);
  1354. return x < 0 ? -z : z;
  1355. };
  1356. return polyfill;
  1357. }, 'es6', 'es3');
  1358. $jscomp.polyfill('Math.trunc', function(orig) {
  1359. if (orig) {
  1360. return orig;
  1361. }
  1362. var polyfill = function(x) {
  1363. x = Number(x);
  1364. if (isNaN(x) || x === Infinity || x === -Infinity || x === 0) {
  1365. return x;
  1366. }
  1367. var y = Math.floor(Math.abs(x));
  1368. return x < 0 ? -y : y;
  1369. };
  1370. return polyfill;
  1371. }, 'es6', 'es3');
  1372. $jscomp.polyfill('Number.EPSILON', function(orig) {
  1373. return Math.pow(2, -52);
  1374. }, 'es6', 'es3');
  1375. $jscomp.polyfill('Number.MAX_SAFE_INTEGER', function() {
  1376. return 9007199254740991;
  1377. }, 'es6', 'es3');
  1378. $jscomp.polyfill('Number.MIN_SAFE_INTEGER', function() {
  1379. return -9007199254740991;
  1380. }, 'es6', 'es3');
  1381. $jscomp.polyfill('Number.isFinite', function(orig) {
  1382. if (orig) {
  1383. return orig;
  1384. }
  1385. var polyfill = function(x) {
  1386. if (typeof x !== 'number') {
  1387. return false;
  1388. }
  1389. return !isNaN(x) && x !== Infinity && x !== -Infinity;
  1390. };
  1391. return polyfill;
  1392. }, 'es6', 'es3');
  1393. $jscomp.polyfill('Number.isInteger', function(orig) {
  1394. if (orig) {
  1395. return orig;
  1396. }
  1397. var polyfill = function(x) {
  1398. if (!Number.isFinite(x)) {
  1399. return false;
  1400. }
  1401. return x === Math.floor(x);
  1402. };
  1403. return polyfill;
  1404. }, 'es6', 'es3');
  1405. $jscomp.polyfill('Number.isNaN', function(orig) {
  1406. if (orig) {
  1407. return orig;
  1408. }
  1409. var polyfill = function(x) {
  1410. return typeof x === 'number' && isNaN(x);
  1411. };
  1412. return polyfill;
  1413. }, 'es6', 'es3');
  1414. $jscomp.polyfill('Number.isSafeInteger', function(orig) {
  1415. if (orig) {
  1416. return orig;
  1417. }
  1418. var polyfill = function(x) {
  1419. return Number.isInteger(x) && Math.abs(x) <= Number.MAX_SAFE_INTEGER;
  1420. };
  1421. return polyfill;
  1422. }, 'es6', 'es3');
  1423. $jscomp.polyfill('Number.parseFloat', function(orig) {
  1424. return orig || parseFloat;
  1425. }, 'es6', 'es3');
  1426. $jscomp.polyfill('Number.parseInt', function(orig) {
  1427. return orig || parseInt;
  1428. }, 'es6', 'es3');
  1429. $jscomp.assign = typeof Object.assign == 'function' ? Object.assign : function(target, var_args) {
  1430. for (var i = 1; i < arguments.length; i++) {
  1431. var source = arguments[i];
  1432. if (!source) {
  1433. continue;
  1434. }
  1435. for (var key in source) {
  1436. if ($jscomp.owns(source, key)) {
  1437. target[key] = source[key];
  1438. }
  1439. }
  1440. }
  1441. return target;
  1442. };
  1443. $jscomp.polyfill('Object.assign', function(orig) {
  1444. return orig || $jscomp.assign;
  1445. }, 'es6', 'es3');
  1446. $jscomp.polyfill('Object.entries', function(orig) {
  1447. if (orig) {
  1448. return orig;
  1449. }
  1450. var entries = function(obj) {
  1451. var result = [];
  1452. for (var key in obj) {
  1453. if ($jscomp.owns(obj, key)) {
  1454. result.push([key, obj[key]]);
  1455. }
  1456. }
  1457. return result;
  1458. };
  1459. return entries;
  1460. }, 'es8', 'es3');
  1461. $jscomp.polyfill('Object.getOwnPropertySymbols', function(orig) {
  1462. if (orig) {
  1463. return orig;
  1464. }
  1465. return function() {
  1466. return [];
  1467. };
  1468. }, 'es6', 'es5');
  1469. $jscomp.polyfill('Reflect.ownKeys', function(orig) {
  1470. if (orig) {
  1471. return orig;
  1472. }
  1473. var symbolPrefix = 'jscomp_symbol_';
  1474. function isSymbol(key) {
  1475. return key.substring(0, symbolPrefix.length) == symbolPrefix;
  1476. }
  1477. var polyfill = function(target) {
  1478. var keys = [];
  1479. var names = Object.getOwnPropertyNames(target);
  1480. var symbols = Object.getOwnPropertySymbols(target);
  1481. for (var i = 0; i < names.length; i++) {
  1482. (isSymbol(names[i]) ? symbols : keys).push(names[i]);
  1483. }
  1484. return keys.concat(symbols);
  1485. };
  1486. return polyfill;
  1487. }, 'es6', 'es5');
  1488. $jscomp.polyfill('Object.getOwnPropertyDescriptors', function(orig) {
  1489. if (orig) {
  1490. return orig;
  1491. }
  1492. var getOwnPropertyDescriptors = function(obj) {
  1493. var result = {};
  1494. var keys = Reflect.ownKeys(obj);
  1495. for (var i = 0; i < keys.length; i++) {
  1496. result[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  1497. }
  1498. return result;
  1499. };
  1500. return getOwnPropertyDescriptors;
  1501. }, 'es8', 'es5');
  1502. $jscomp.polyfill('Object.setPrototypeOf', function(orig) {
  1503. return orig || $jscomp.setPrototypeOf;
  1504. }, 'es6', 'es5');
  1505. $jscomp.polyfill('Object.values', function(orig) {
  1506. if (orig) {
  1507. return orig;
  1508. }
  1509. var values = function(obj) {
  1510. var result = [];
  1511. for (var key in obj) {
  1512. if ($jscomp.owns(obj, key)) {
  1513. result.push(obj[key]);
  1514. }
  1515. }
  1516. return result;
  1517. };
  1518. return values;
  1519. }, 'es8', 'es3');
  1520. $jscomp.polyfill('Reflect.apply', function(orig) {
  1521. if (orig) {
  1522. return orig;
  1523. }
  1524. var apply = Function.prototype.apply;
  1525. var polyfill = function(target, thisArg, argList) {
  1526. return apply.call(target, thisArg, argList);
  1527. };
  1528. return polyfill;
  1529. }, 'es6', 'es3');
  1530. $jscomp.objectCreate = $jscomp.ASSUME_ES5 || typeof Object.create == 'function' ? Object.create : function(prototype) {
  1531. var ctor = function() {
  1532. };
  1533. ctor.prototype = prototype;
  1534. return new ctor;
  1535. };
  1536. $jscomp.construct = function() {
  1537. function reflectConstructWorks() {
  1538. function Base() {
  1539. }
  1540. function Derived() {
  1541. }
  1542. new Base;
  1543. Reflect.construct(Base, [], Derived);
  1544. return new Base instanceof Base;
  1545. }
  1546. if (typeof Reflect != 'undefined' && Reflect.construct) {
  1547. if (reflectConstructWorks()) {
  1548. return Reflect.construct;
  1549. }
  1550. var brokenConstruct = Reflect.construct;
  1551. var patchedConstruct = function(target, argList, opt_newTarget) {
  1552. var out = brokenConstruct(target, argList);
  1553. if (opt_newTarget) {
  1554. Reflect.setPrototypeOf(out, opt_newTarget.prototype);
  1555. }
  1556. return out;
  1557. };
  1558. return patchedConstruct;
  1559. }
  1560. function construct(target, argList, opt_newTarget) {
  1561. if (opt_newTarget === undefined) {
  1562. opt_newTarget = target;
  1563. }
  1564. var proto = opt_newTarget.prototype || Object.prototype;
  1565. var obj = $jscomp.objectCreate(proto);
  1566. var apply = Function.prototype.apply;
  1567. var out = apply.call(target, obj, argList);
  1568. return out || obj;
  1569. }
  1570. return construct;
  1571. }();
  1572. $jscomp.polyfill('Reflect.construct', function(orig) {
  1573. return $jscomp.construct;
  1574. }, 'es6', 'es3');
  1575. $jscomp.polyfill('Reflect.defineProperty', function(orig) {
  1576. if (orig) {
  1577. return orig;
  1578. }
  1579. var polyfill = function(target, propertyKey, attributes) {
  1580. try {
  1581. Object.defineProperty(target, propertyKey, attributes);
  1582. var desc = Object.getOwnPropertyDescriptor(target, propertyKey);
  1583. if (!desc) {
  1584. return false;
  1585. }
  1586. return desc.configurable === (attributes.configurable || false) && desc.enumerable === (attributes.enumerable || false) && ('value' in desc ? desc.value === attributes.value && desc.writable === (attributes.writable || false) : desc.get === attributes.get && desc.set === attributes.set);
  1587. } catch (err) {
  1588. return false;
  1589. }
  1590. };
  1591. return polyfill;
  1592. }, 'es6', 'es5');
  1593. $jscomp.polyfill('Reflect.deleteProperty', function(orig) {
  1594. if (orig) {
  1595. return orig;
  1596. }
  1597. var polyfill = function(target, propertyKey) {
  1598. if (!$jscomp.owns(target, propertyKey)) {
  1599. return true;
  1600. }
  1601. try {
  1602. return delete target[propertyKey];
  1603. } catch (err) {
  1604. return false;
  1605. }
  1606. };
  1607. return polyfill;
  1608. }, 'es6', 'es3');
  1609. $jscomp.polyfill('Reflect.getOwnPropertyDescriptor', function(orig) {
  1610. return orig || Object.getOwnPropertyDescriptor;
  1611. }, 'es6', 'es5');
  1612. $jscomp.polyfill('Reflect.getPrototypeOf', function(orig) {
  1613. return orig || Object.getPrototypeOf;
  1614. }, 'es6', 'es5');
  1615. $jscomp.findDescriptor = function(target, propertyKey) {
  1616. var obj = target;
  1617. while (obj) {
  1618. var property = Reflect.getOwnPropertyDescriptor(obj, propertyKey);
  1619. if (property) {
  1620. return property;
  1621. }
  1622. obj = Reflect.getPrototypeOf(obj);
  1623. }
  1624. return undefined;
  1625. };
  1626. $jscomp.polyfill('Reflect.get', function(orig) {
  1627. if (orig) {
  1628. return orig;
  1629. }
  1630. var polyfill = function(target, propertyKey, opt_receiver) {
  1631. if (arguments.length <= 2) {
  1632. return target[propertyKey];
  1633. }
  1634. var property = $jscomp.findDescriptor(target, propertyKey);
  1635. if (property) {
  1636. return property.get ? property.get.call(opt_receiver) : property.value;
  1637. }
  1638. return undefined;
  1639. };
  1640. return polyfill;
  1641. }, 'es6', 'es5');
  1642. $jscomp.polyfill('Reflect.has', function(orig) {
  1643. if (orig) {
  1644. return orig;
  1645. }
  1646. var polyfill = function(target, propertyKey) {
  1647. return propertyKey in target;
  1648. };
  1649. return polyfill;
  1650. }, 'es6', 'es3');
  1651. $jscomp.polyfill('Reflect.isExtensible', function(orig) {
  1652. if (orig) {
  1653. return orig;
  1654. }
  1655. if ($jscomp.ASSUME_ES5 || typeof Object.isExtensible == 'function') {
  1656. return Object.isExtensible;
  1657. }
  1658. return function() {
  1659. return true;
  1660. };
  1661. }, 'es6', 'es3');
  1662. $jscomp.polyfill('Reflect.preventExtensions', function(orig) {
  1663. if (orig) {
  1664. return orig;
  1665. }
  1666. if (!($jscomp.ASSUME_ES5 || typeof Object.preventExtensions == 'function')) {
  1667. return function() {
  1668. return false;
  1669. };
  1670. }
  1671. var polyfill = function(target) {
  1672. Object.preventExtensions(target);
  1673. return !Object.isExtensible(target);
  1674. };
  1675. return polyfill;
  1676. }, 'es6', 'es3');
  1677. $jscomp.polyfill('Reflect.set', function(orig) {
  1678. if (orig) {
  1679. return orig;
  1680. }
  1681. var polyfill = function(target, propertyKey, value, opt_receiver) {
  1682. var property = $jscomp.findDescriptor(target, propertyKey);
  1683. if (!property) {
  1684. if (Reflect.isExtensible(target)) {
  1685. target[propertyKey] = value;
  1686. return true;
  1687. }
  1688. return false;
  1689. }
  1690. if (property.set) {
  1691. property.set.call(arguments.length > 3 ? opt_receiver : target, value);
  1692. return true;
  1693. } else {
  1694. if (property.writable && !Object.isFrozen(target)) {
  1695. target[propertyKey] = value;
  1696. return true;
  1697. }
  1698. }
  1699. return false;
  1700. };
  1701. return polyfill;
  1702. }, 'es6', 'es5');
  1703. $jscomp.polyfill('Reflect.setPrototypeOf', function(orig) {
  1704. if (orig) {
  1705. return orig;
  1706. } else {
  1707. if ($jscomp.setPrototypeOf) {
  1708. var setPrototypeOf = $jscomp.setPrototypeOf;
  1709. var polyfill = function(target, proto) {
  1710. try {
  1711. setPrototypeOf(target, proto);
  1712. return true;
  1713. } catch (e) {
  1714. return false;
  1715. }
  1716. };
  1717. return polyfill;
  1718. } else {
  1719. return null;
  1720. }
  1721. }
  1722. }, 'es6', 'es5');
  1723. $jscomp.polyfill('Set', function(NativeSet) {
  1724. function isConformant() {
  1725. if ($jscomp.ASSUME_NO_NATIVE_SET || !NativeSet || typeof NativeSet != 'function' || !NativeSet.prototype.entries || typeof Object.seal != 'function') {
  1726. return false;
  1727. }
  1728. try {
  1729. NativeSet = NativeSet;
  1730. var value = Object.seal({x:4});
  1731. var set = new NativeSet($jscomp.makeIterator([value]));
  1732. if (!set.has(value) || set.size != 1 || set.add(value) != set || set.size != 1 || set.add({x:4}) != set || set.size != 2) {
  1733. return false;
  1734. }
  1735. var iter = set.entries();
  1736. var item = iter.next();
  1737. if (item.done || item.value[0] != value || item.value[1] != value) {
  1738. return false;
  1739. }
  1740. item = iter.next();
  1741. if (item.done || item.value[0] == value || item.value[0].x != 4 || item.value[1] != item.value[0]) {
  1742. return false;
  1743. }
  1744. return iter.next().done;
  1745. } catch (err) {
  1746. return false;
  1747. }
  1748. }
  1749. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  1750. if (NativeSet && $jscomp.ES6_CONFORMANCE) {
  1751. return NativeSet;
  1752. }
  1753. } else {
  1754. if (isConformant()) {
  1755. return NativeSet;
  1756. }
  1757. }
  1758. $jscomp.initSymbol();
  1759. $jscomp.initSymbolIterator();
  1760. var PolyfillSet = function(opt_iterable) {
  1761. this.map_ = new Map;
  1762. if (opt_iterable) {
  1763. var iter = $jscomp.makeIterator(opt_iterable);
  1764. var entry;
  1765. while (!(entry = iter.next()).done) {
  1766. var item = entry.value;
  1767. this.add(item);
  1768. }
  1769. }
  1770. this.size = this.map_.size;
  1771. };
  1772. PolyfillSet.prototype.add = function(value) {
  1773. value = value === 0 ? 0 : value;
  1774. this.map_.set(value, value);
  1775. this.size = this.map_.size;
  1776. return this;
  1777. };
  1778. PolyfillSet.prototype['delete'] = function(value) {
  1779. var result = this.map_['delete'](value);
  1780. this.size = this.map_.size;
  1781. return result;
  1782. };
  1783. PolyfillSet.prototype.clear = function() {
  1784. this.map_.clear();
  1785. this.size = 0;
  1786. };
  1787. PolyfillSet.prototype.has = function(value) {
  1788. return this.map_.has(value);
  1789. };
  1790. PolyfillSet.prototype.entries = function() {
  1791. return this.map_.entries();
  1792. };
  1793. PolyfillSet.prototype.values = function() {
  1794. return this.map_.values();
  1795. };
  1796. PolyfillSet.prototype.keys = PolyfillSet.prototype.values;
  1797. PolyfillSet.prototype[Symbol.iterator] = PolyfillSet.prototype.values;
  1798. PolyfillSet.prototype.forEach = function(callback, opt_thisArg) {
  1799. var set = this;
  1800. this.map_.forEach(function(value) {
  1801. return callback.call(opt_thisArg, value, value, set);
  1802. });
  1803. };
  1804. return PolyfillSet;
  1805. }, 'es6', 'es3');
  1806. $jscomp.checkStringArgs = function(thisArg, arg, func) {
  1807. if (thisArg == null) {
  1808. throw new TypeError("The 'this' value for String.prototype." + func + ' must not be null or undefined');
  1809. }
  1810. if (arg instanceof RegExp) {
  1811. throw new TypeError('First argument to String.prototype.' + func + ' must not be a regular expression');
  1812. }
  1813. return thisArg + '';
  1814. };
  1815. $jscomp.polyfill('String.prototype.codePointAt', function(orig) {
  1816. if (orig) {
  1817. return orig;
  1818. }
  1819. var polyfill = function(position) {
  1820. var string = $jscomp.checkStringArgs(this, null, 'codePointAt');
  1821. var size = string.length;
  1822. position = Number(position) || 0;
  1823. if (!(position >= 0 && position < size)) {
  1824. return void 0;
  1825. }
  1826. position = position | 0;
  1827. var first = string.charCodeAt(position);
  1828. if (first < 55296 || first > 56319 || position + 1 === size) {
  1829. return first;
  1830. }
  1831. var second = string.charCodeAt(position + 1);
  1832. if (second < 56320 || second > 57343) {
  1833. return first;
  1834. }
  1835. return (first - 55296) * 1024 + second + 9216;
  1836. };
  1837. return polyfill;
  1838. }, 'es6', 'es3');
  1839. $jscomp.polyfill('String.prototype.endsWith', function(orig) {
  1840. if (orig) {
  1841. return orig;
  1842. }
  1843. var polyfill = function(searchString, opt_position) {
  1844. var string = $jscomp.checkStringArgs(this, searchString, 'endsWith');
  1845. searchString = searchString + '';
  1846. if (opt_position === void 0) {
  1847. opt_position = string.length;
  1848. }
  1849. var i = Math.max(0, Math.min(opt_position | 0, string.length));
  1850. var j = searchString.length;
  1851. while (j > 0 && i > 0) {
  1852. if (string[--i] != searchString[--j]) {
  1853. return false;
  1854. }
  1855. }
  1856. return j <= 0;
  1857. };
  1858. return polyfill;
  1859. }, 'es6', 'es3');
  1860. $jscomp.polyfill('String.fromCodePoint', function(orig) {
  1861. if (orig) {
  1862. return orig;
  1863. }
  1864. var polyfill = function(var_args) {
  1865. var result = '';
  1866. for (var i = 0; i < arguments.length; i++) {
  1867. var code = Number(arguments[i]);
  1868. if (code < 0 || code > 1114111 || code !== Math.floor(code)) {
  1869. throw new RangeError('invalid_code_point ' + code);
  1870. }
  1871. if (code <= 65535) {
  1872. result += String.fromCharCode(code);
  1873. } else {
  1874. code -= 65536;
  1875. result += String.fromCharCode(code >>> 10 & 1023 | 55296);
  1876. result += String.fromCharCode(code & 1023 | 56320);
  1877. }
  1878. }
  1879. return result;
  1880. };
  1881. return polyfill;
  1882. }, 'es6', 'es3');
  1883. $jscomp.polyfill('String.prototype.includes', function(orig) {
  1884. if (orig) {
  1885. return orig;
  1886. }
  1887. var polyfill = function(searchString, opt_position) {
  1888. var string = $jscomp.checkStringArgs(this, searchString, 'includes');
  1889. return string.indexOf(searchString, opt_position || 0) !== -1;
  1890. };
  1891. return polyfill;
  1892. }, 'es6', 'es3');
  1893. $jscomp.polyfill('String.prototype.repeat', function(orig) {
  1894. if (orig) {
  1895. return orig;
  1896. }
  1897. var polyfill = function(copies) {
  1898. var string = $jscomp.checkStringArgs(this, null, 'repeat');
  1899. if (copies < 0 || copies > 1342177279) {
  1900. throw new RangeError('Invalid count value');
  1901. }
  1902. copies = copies | 0;
  1903. var result = '';
  1904. while (copies) {
  1905. if (copies & 1) {
  1906. result += string;
  1907. }
  1908. if (copies >>>= 1) {
  1909. string += string;
  1910. }
  1911. }
  1912. return result;
  1913. };
  1914. return polyfill;
  1915. }, 'es6', 'es3');
  1916. $jscomp.stringPadding = function(padString, padLength) {
  1917. var padding = padString !== undefined ? String(padString) : ' ';
  1918. if (!(padLength > 0) || !padding) {
  1919. return '';
  1920. }
  1921. var repeats = Math.ceil(padLength / padding.length);
  1922. return padding.repeat(repeats).substring(0, padLength);
  1923. };
  1924. $jscomp.polyfill('String.prototype.padEnd', function(orig) {
  1925. if (orig) {
  1926. return orig;
  1927. }
  1928. var padEnd = function(targetLength, opt_padString) {
  1929. var string = $jscomp.checkStringArgs(this, null, 'padStart');
  1930. var padLength = targetLength - string.length;
  1931. return string + $jscomp.stringPadding(opt_padString, padLength);
  1932. };
  1933. return padEnd;
  1934. }, 'es8', 'es3');
  1935. $jscomp.polyfill('String.prototype.padStart', function(orig) {
  1936. if (orig) {
  1937. return orig;
  1938. }
  1939. var padStart = function(targetLength, opt_padString) {
  1940. var string = $jscomp.checkStringArgs(this, null, 'padStart');
  1941. var padLength = targetLength - string.length;
  1942. return $jscomp.stringPadding(opt_padString, padLength) + string;
  1943. };
  1944. return padStart;
  1945. }, 'es8', 'es3');
  1946. $jscomp.polyfill('String.prototype.startsWith', function(orig) {
  1947. if (orig) {
  1948. return orig;
  1949. }
  1950. var polyfill = function(searchString, opt_position) {
  1951. var string = $jscomp.checkStringArgs(this, searchString, 'startsWith');
  1952. searchString = searchString + '';
  1953. var strLen = string.length;
  1954. var searchLen = searchString.length;
  1955. var i = Math.max(0, Math.min(opt_position | 0, string.length));
  1956. var j = 0;
  1957. while (j < searchLen && i < strLen) {
  1958. if (string[i++] != searchString[j++]) {
  1959. return false;
  1960. }
  1961. }
  1962. return j >= searchLen;
  1963. };
  1964. return polyfill;
  1965. }, 'es6', 'es3');
  1966. $jscomp.arrayFromIterator = function(iterator) {
  1967. var i;
  1968. var arr = [];
  1969. while (!(i = iterator.next()).done) {
  1970. arr.push(i.value);
  1971. }
  1972. return arr;
  1973. };
  1974. $jscomp.arrayFromIterable = function(iterable) {
  1975. if (iterable instanceof Array) {
  1976. return iterable;
  1977. } else {
  1978. return $jscomp.arrayFromIterator($jscomp.makeIterator(iterable));
  1979. }
  1980. };
  1981. $jscomp.inherits = function(childCtor, parentCtor) {
  1982. childCtor.prototype = $jscomp.objectCreate(parentCtor.prototype);
  1983. childCtor.prototype.constructor = childCtor;
  1984. if ($jscomp.setPrototypeOf) {
  1985. var setPrototypeOf = $jscomp.setPrototypeOf;
  1986. setPrototypeOf(childCtor, parentCtor);
  1987. } else {
  1988. for (var p in parentCtor) {
  1989. if (p == 'prototype') {
  1990. continue;
  1991. }
  1992. if (Object.defineProperties) {
  1993. var descriptor = Object.getOwnPropertyDescriptor(parentCtor, p);
  1994. if (descriptor) {
  1995. Object.defineProperty(childCtor, p, descriptor);
  1996. }
  1997. } else {
  1998. childCtor[p] = parentCtor[p];
  1999. }
  2000. }
  2001. }
  2002. childCtor.superClass_ = parentCtor.prototype;
  2003. };
  2004. $jscomp.polyfill('WeakSet', function(NativeWeakSet) {
  2005. function isConformant() {
  2006. if (!NativeWeakSet || !Object.seal) {
  2007. return false;
  2008. }
  2009. try {
  2010. var x = Object.seal({});
  2011. var y = Object.seal({});
  2012. var set = new NativeWeakSet([x]);
  2013. if (!set.has(x) || set.has(y)) {
  2014. return false;
  2015. }
  2016. set['delete'](x);
  2017. set.add(y);
  2018. return !set.has(x) && set.has(y);
  2019. } catch (err) {
  2020. return false;
  2021. }
  2022. }
  2023. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  2024. if (NativeWeakSet && $jscomp.ES6_CONFORMANCE) {
  2025. return NativeWeakSet;
  2026. }
  2027. } else {
  2028. if (isConformant()) {
  2029. return NativeWeakSet;
  2030. }
  2031. }
  2032. var PolyfillWeakSet = function(opt_iterable) {
  2033. this.map_ = new WeakMap;
  2034. if (opt_iterable) {
  2035. $jscomp.initSymbol();
  2036. $jscomp.initSymbolIterator();
  2037. var iter = $jscomp.makeIterator(opt_iterable);
  2038. var entry;
  2039. while (!(entry = iter.next()).done) {
  2040. var item = entry.value;
  2041. this.add(item);
  2042. }
  2043. }
  2044. };
  2045. PolyfillWeakSet.prototype.add = function(elem) {
  2046. this.map_.set(elem, true);
  2047. return this;
  2048. };
  2049. PolyfillWeakSet.prototype.has = function(elem) {
  2050. return this.map_.has(elem);
  2051. };
  2052. PolyfillWeakSet.prototype['delete'] = function(elem) {
  2053. return this.map_['delete'](elem);
  2054. };
  2055. return PolyfillWeakSet;
  2056. }, 'es6', 'es3');
  2057. try {
  2058. if (Array.prototype.values.toString().indexOf('[native code]') == -1) {
  2059. delete Array.prototype.values;
  2060. }
  2061. } catch (e) {
  2062. }
  2063. Ext.define('Ext.data.proxy.Sql', {alias:'proxy.sql', extend:'Ext.data.proxy.Client', alternateClassName:'Ext.data.proxy.SQL', isSQLProxy:true, config:{reader:null, writer:null, table:null, database:'Sencha'}, _createOptions:{silent:true, dirty:false}, updateModel:function(model) {
  2064. var me = this, modelName, len, i, columns, quoted;
  2065. if (model) {
  2066. me.uniqueIdStrategy = model.identifier.isUnique;
  2067. if (!me.getTable()) {
  2068. modelName = model.entityName;
  2069. me.setTable(modelName.slice(modelName.lastIndexOf('.') + 1));
  2070. }
  2071. me.columns = columns = me.getPersistedModelColumns(model);
  2072. me.quotedColumns = quoted = [];
  2073. for (i = 0, len = columns.length; i < len; ++i) {
  2074. quoted.push('"' + columns[i] + '"');
  2075. }
  2076. }
  2077. me.callParent([model]);
  2078. }, setException:function(operation, error) {
  2079. operation.setException(error);
  2080. }, create:function(operation) {
  2081. var me = this, records = operation.getRecords(), result, error;
  2082. operation.setStarted();
  2083. me.executeTransaction(function(transaction) {
  2084. me.insertRecords(records, transaction, function(resultSet, statementError) {
  2085. result = resultSet;
  2086. error = statementError;
  2087. });
  2088. }, function(transactionError) {
  2089. operation.setException(transactionError);
  2090. }, function() {
  2091. if (error) {
  2092. operation.setException(statementError);
  2093. } else {
  2094. operation.process(result);
  2095. }
  2096. });
  2097. }, read:function(operation) {
  2098. var me = this, model = me.getModel(), records = operation.getRecords(), record = records ? records[0] : null, result, error, id, params;
  2099. if (record && !record.phantom) {
  2100. id = record.getId();
  2101. } else {
  2102. id = operation.getId();
  2103. }
  2104. if (id !== undefined) {
  2105. params = {idOnly:true, id:id};
  2106. } else {
  2107. params = {page:operation.getPage(), start:operation.getStart(), limit:operation.getLimit(), sorters:operation.getSorters(), filters:operation.getFilters()};
  2108. }
  2109. operation.setStarted();
  2110. me.executeTransaction(function(transaction) {
  2111. me.selectRecords(transaction, params, function(resultSet, statementError) {
  2112. result = resultSet;
  2113. error = statementError;
  2114. });
  2115. }, function(transactionError) {
  2116. operation.setException(transactionError);
  2117. }, function() {
  2118. if (error) {
  2119. operation.setException(statementError);
  2120. } else {
  2121. operation.process(result);
  2122. }
  2123. });
  2124. }, update:function(operation) {
  2125. var me = this, records = operation.getRecords(), result, error;
  2126. operation.setStarted();
  2127. me.executeTransaction(function(transaction) {
  2128. me.updateRecords(transaction, records, function(resultSet, statementError) {
  2129. result = resultSet;
  2130. error = statementError;
  2131. });
  2132. }, function(transactionError) {
  2133. operation.setException(transactionError);
  2134. }, function() {
  2135. if (error) {
  2136. operation.setException(statementError);
  2137. } else {
  2138. operation.process(result);
  2139. }
  2140. });
  2141. }, erase:function(operation) {
  2142. var me = this, records = operation.getRecords(), result, error;
  2143. operation.setStarted();
  2144. me.executeTransaction(function(transaction) {
  2145. me.destroyRecords(transaction, records, function(resultSet, statementError) {
  2146. result = resultSet;
  2147. error = statementError;
  2148. });
  2149. }, function(transactionError) {
  2150. operation.setException(transactionError);
  2151. }, function() {
  2152. if (error) {
  2153. operation.setException(error);
  2154. } else {
  2155. operation.process(result);
  2156. }
  2157. });
  2158. }, createTable:function(transaction) {
  2159. var me = this;
  2160. if (!transaction) {
  2161. me.executeTransaction(function(transaction) {
  2162. me.createTable(transaction);
  2163. });
  2164. return;
  2165. }
  2166. me.executeStatement(transaction, 'CREATE TABLE IF NOT EXISTS "' + me.getTable() + '" (' + me.getSchemaString() + ')', function() {
  2167. me.tableExists = true;
  2168. });
  2169. }, insertRecords:function(records, transaction, callback) {
  2170. var me = this, columns = me.columns, totalRecords = records.length, executed = 0, uniqueIdStrategy = me.uniqueIdStrategy, setOptions = me._createOptions, len = records.length, i, record, placeholders, sql, data, values, errors, completeIf;
  2171. completeIf = function(transaction) {
  2172. ++executed;
  2173. if (executed === totalRecords) {
  2174. callback.call(me, new Ext.data.ResultSet({success:!errors}), errors);
  2175. }
  2176. };
  2177. placeholders = Ext.String.repeat('?', columns.length, ',');
  2178. sql = 'INSERT INTO "' + me.getTable() + '" (' + me.quotedColumns.join(',') + ') VALUES (' + placeholders + ')';
  2179. for (i = 0; i < len; ++i) {
  2180. record = records[i];
  2181. data = me.getRecordData(record);
  2182. values = me.getColumnValues(columns, data);
  2183. (function(record) {
  2184. me.executeStatement(transaction, sql, values, function(transaction, resultSet) {
  2185. if (!uniqueIdStrategy) {
  2186. record.setId(resultSet.insertId, setOptions);
  2187. }
  2188. completeIf();
  2189. }, function(transaction, error) {
  2190. if (!errors) {
  2191. errors = [];
  2192. }
  2193. errors.push(error);
  2194. completeIf();
  2195. });
  2196. })(record);
  2197. }
  2198. }, selectRecords:function(transaction, params, callback, scope) {
  2199. var me = this, Model = me.getModel(), idProperty = Model.idProperty, sql = 'SELECT * FROM "' + me.getTable() + '"', filterStatement = ' WHERE ', sortStatement = ' ORDER BY ', values = [], sorters, filters, placeholder, i, len, result, filter, sorter, property, operator, value;
  2200. if (params.idOnly) {
  2201. sql += filterStatement + '"' + idProperty + '" \x3d ?';
  2202. values.push(params);
  2203. } else {
  2204. filters = params.filters;
  2205. len = filters && filters.length;
  2206. if (len) {
  2207. for (i = 0; i < len; i++) {
  2208. filter = filters[i];
  2209. property = filter.getProperty();
  2210. value = me.toSqlValue(filter.getValue(), Model.getField(property));
  2211. operator = filter.getOperator();
  2212. if (property !== null) {
  2213. operator = operator || '\x3d';
  2214. placeholder = '?';
  2215. if (operator === 'like' || operator === '\x3d' && filter.getAnyMatch()) {
  2216. operator = 'LIKE';
  2217. value = '%' + value + '%';
  2218. }
  2219. if (operator === 'in' || operator === 'notin') {
  2220. if (operator === 'notin') {
  2221. operator = 'not in';
  2222. }
  2223. placeholder = '(' + Ext.String.repeat('?', value.length, ',') + ')';
  2224. values = values.concat(value);
  2225. } else {
  2226. values.push(value);
  2227. }
  2228. sql += filterStatement + '"' + property + '" ' + operator + ' ' + placeholder;
  2229. filterStatement = ' AND ';
  2230. }
  2231. }
  2232. }
  2233. sorters = params.sorters;
  2234. len = sorters && sorters.length;
  2235. if (len) {
  2236. for (i = 0; i < len; i++) {
  2237. sorter = sorters[i];
  2238. property = sorter.getProperty();
  2239. if (property !== null) {
  2240. sql += sortStatement + '"' + property + '" ' + sorter.getDirection();
  2241. sortStatement = ', ';
  2242. }
  2243. }
  2244. }
  2245. if (params.page !== undefined) {
  2246. sql += ' LIMIT ' + parseInt(params.start, 10) + ', ' + parseInt(params.limit, 10);
  2247. }
  2248. }
  2249. me.executeStatement(transaction, sql, values, function(transaction, resultSet) {
  2250. var rows = resultSet.rows, count = rows.length, records = [], fields = Model.fields, fieldsLen = fields.length, raw, data, i, len, j, field, name;
  2251. for (i = 0, len = count; i < len; ++i) {
  2252. raw = rows.item(i);
  2253. data = {};
  2254. for (j = 0; j < fieldsLen; ++j) {
  2255. field = fields[j];
  2256. name = field.name;
  2257. data[name] = me.fromSqlValue(raw[name], field);
  2258. }
  2259. records.push(new Model(data));
  2260. }
  2261. callback.call(me, new Ext.data.ResultSet({records:records, success:true, total:count, count:count}));
  2262. }, function(transaction, error) {
  2263. callback.call(me, new Ext.data.ResultSet({success:false, total:0, count:0}), error);
  2264. });
  2265. }, updateRecords:function(transaction, records, callback) {
  2266. var me = this, columns = me.columns, quotedColumns = me.quotedColumns, totalRecords = records.length, executed = 0, updates = [], setOptions = me._createOptions, len, i, record, placeholders, sql, data, values, errors, completeIf;
  2267. completeIf = function(transaction) {
  2268. ++executed;
  2269. if (executed === totalRecords) {
  2270. callback.call(me, new Ext.data.ResultSet({success:!errors}), errors);
  2271. }
  2272. };
  2273. for (i = 0, len = quotedColumns.length; i < len; i++) {
  2274. updates.push(quotedColumns[i] + ' \x3d ?');
  2275. }
  2276. sql = 'UPDATE "' + me.getTable() + '" SET ' + updates.join(', ') + ' WHERE "' + me.getModel().idProperty + '" \x3d ?';
  2277. for (i = 0, len = records.length; i < len; ++i) {
  2278. record = records[i];
  2279. data = me.getRecordData(record);
  2280. values = me.getColumnValues(columns, data);
  2281. values.push(record.getId());
  2282. (function(record) {
  2283. me.executeStatement(transaction, sql, values, function(transaction, resultSet) {
  2284. completeIf();
  2285. }, function(transaction, error) {
  2286. if (!errors) {
  2287. errors = [];
  2288. }
  2289. errors.push(error);
  2290. completeIf();
  2291. });
  2292. })(record);
  2293. }
  2294. }, destroyRecords:function(transaction, records, callback) {
  2295. var me = this, table = me.getTable(), idProperty = me.getModel().idProperty, ids = [], values = [], destroyedRecords = [], len = records.length, idStr = '"' + idProperty + '" \x3d ?', i, result, record, sql;
  2296. for (i = 0; i < len; i++) {
  2297. ids.push(idStr);
  2298. values.push(records[i].getId());
  2299. }
  2300. sql = 'DELETE FROM "' + me.getTable() + '" WHERE ' + ids.join(' OR ');
  2301. me.executeStatement(transaction, sql, values, function(transaction, resultSet) {
  2302. callback.call(me, new Ext.data.ResultSet({success:true}));
  2303. }, function(transaction, error) {
  2304. callback.call(me, new Ext.data.ResultSet({success:false}), error);
  2305. });
  2306. }, getRecordData:function(record) {
  2307. var me = this, fields = record.fields, idProperty = record.idProperty, uniqueIdStrategy = me.uniqueIdStrategy, data = {}, len = fields.length, recordData = record.data, i, name, value, field;
  2308. for (i = 0; i < len; ++i) {
  2309. field = fields[i];
  2310. if (field.persist !== false) {
  2311. name = field.name;
  2312. if (name === idProperty && !uniqueIdStrategy) {
  2313. continue;
  2314. }
  2315. data[name] = me.toSqlValue(recordData[name], field);
  2316. }
  2317. }
  2318. return data;
  2319. }, getColumnValues:function(columns, data) {
  2320. var len = columns.length, values = [], i, column, value;
  2321. for (i = 0; i < len; i++) {
  2322. column = columns[i];
  2323. value = data[column];
  2324. if (value !== undefined) {
  2325. values.push(value);
  2326. }
  2327. }
  2328. return values;
  2329. }, getSchemaString:function() {
  2330. var me = this, schema = [], model = me.getModel(), idProperty = model.idProperty, fields = model.fields, uniqueIdStrategy = me.uniqueIdStrategy, len = fields.length, i, field, type, name;
  2331. for (i = 0; i < len; i++) {
  2332. field = fields[i];
  2333. type = field.getType();
  2334. name = field.name;
  2335. if (name === idProperty) {
  2336. if (uniqueIdStrategy) {
  2337. type = me.convertToSqlType(type);
  2338. schema.unshift('"' + idProperty + '" ' + type);
  2339. } else {
  2340. schema.unshift('"' + idProperty + '" INTEGER PRIMARY KEY AUTOINCREMENT');
  2341. }
  2342. } else {
  2343. type = me.convertToSqlType(type);
  2344. schema.push('"' + name + '" ' + type);
  2345. }
  2346. }
  2347. return schema.join(', ');
  2348. }, convertToSqlType:function(type) {
  2349. switch(type.toLowerCase()) {
  2350. case 'string':
  2351. case 'auto':
  2352. return 'TEXT';
  2353. case 'int':
  2354. case 'date':
  2355. return 'INTEGER';
  2356. case 'float':
  2357. return 'REAL';
  2358. case 'bool':
  2359. return 'NUMERIC';
  2360. }
  2361. }, dropTable:function() {
  2362. var me = this;
  2363. me.executeTransaction(function(transaction) {
  2364. me.executeStatement(transaction, 'DROP TABLE "' + me.getTable() + '"', function() {
  2365. me.tableExists = false;
  2366. });
  2367. }, null, null, false);
  2368. }, getDatabaseObject:function() {
  2369. return window.openDatabase(this.getDatabase(), '1.0', 'Sencha Database', 5 * 1024 * 1024);
  2370. }, privates:{executeStatement:function(transaction, sql, values, success, failure) {
  2371. var me = this;
  2372. transaction.executeSql(sql, values, success ? function() {
  2373. success.apply(me, arguments);
  2374. } : null, failure ? function() {
  2375. failure.apply(me, arguments);
  2376. } : null);
  2377. }, executeTransaction:function(runner, failure, success, autoCreateTable) {
  2378. var me = this;
  2379. autoCreateTable = autoCreateTable !== false;
  2380. me.getDatabaseObject().transaction(runner ? function(transaction) {
  2381. if (autoCreateTable && !me.tableExists) {
  2382. me.createTable(transaction);
  2383. }
  2384. runner.apply(me, arguments);
  2385. } : null, failure ? function() {
  2386. failure.apply(me, arguments);
  2387. } : null, success ? function() {
  2388. success.apply(me, arguments);
  2389. } : null);
  2390. }, fromSqlValue:function(value, field) {
  2391. if (field.isDateField) {
  2392. value = value ? new Date(value) : null;
  2393. } else {
  2394. if (field.isBooleanField) {
  2395. value = value === 1;
  2396. }
  2397. }
  2398. return value;
  2399. }, getPersistedModelColumns:function(model) {
  2400. var fields = model.fields, uniqueIdStrategy = this.uniqueIdStrategy, idProperty = model.idProperty, columns = [], len = fields.length, i, field, name;
  2401. for (i = 0; i < len; ++i) {
  2402. field = fields[i];
  2403. name = field.name;
  2404. if (name === idProperty && !uniqueIdStrategy) {
  2405. continue;
  2406. }
  2407. if (field.persist !== false) {
  2408. columns.push(field.name);
  2409. }
  2410. }
  2411. return columns;
  2412. }, toSqlValue:function(value, field) {
  2413. if (field.isDateField) {
  2414. value = value ? value.getTime() : null;
  2415. } else {
  2416. if (field.isBooleanField) {
  2417. value = value ? 1 : 0;
  2418. }
  2419. }
  2420. return value;
  2421. }}});
  2422. Ext.define('Ext.device.accelerometer.Abstract', {config:{frequency:10000}, getCurrentAcceleration:function(config) {
  2423. if (!config.success) {
  2424. Ext.Logger.warn('You need to specify a `success` function for #getCurrentAcceleration');
  2425. }
  2426. return config;
  2427. }, watchAcceleration:function(config) {
  2428. var defaultConfig = Ext.device.accelerometer.Abstract.prototype.config;
  2429. config = Ext.applyIf(config, {frequency:defaultConfig.frequency});
  2430. if (!config.callback) {
  2431. Ext.Logger.warn('You need to specify a `callback` function for #watchAcceleration');
  2432. }
  2433. return config;
  2434. }, clearWatch:Ext.emptyFn});
  2435. Ext.define('Ext.device.accelerometer.Cordova', {alternateClassName:'Ext.device.accelerometer.PhoneGap', extend:'Ext.device.accelerometer.Abstract', activeWatchID:null, getCurrentAcceleration:function(config) {
  2436. config = this.callParent(arguments);
  2437. navigator.accelerometer.getCurrentAcceleration(config.success, config.failure);
  2438. return config;
  2439. }, watchAcceleration:function(config) {
  2440. config = this.callParent(arguments);
  2441. if (this.activeWatchID) {
  2442. this.clearWatch();
  2443. }
  2444. this.activeWatchID = navigator.accelerometer.watchAcceleration(config.callback, config.failure, config);
  2445. return config;
  2446. }, clearWatch:function() {
  2447. if (this.activeWatchID) {
  2448. navigator.accelerometer.clearWatch(this.activeWatchID);
  2449. this.activeWatchID = null;
  2450. }
  2451. }});
  2452. Ext.define('Ext.device.accelerometer.Simulator', {extend:'Ext.device.accelerometer.Abstract'});
  2453. Ext.define('Ext.device.Accelerometer', {singleton:true, requires:['Ext.device.accelerometer.Cordova', 'Ext.device.accelerometer.Simulator'], constructor:function() {
  2454. var browserEnv = Ext.browser.is;
  2455. if (browserEnv.WebView && browserEnv.Cordova) {
  2456. return Ext.create('Ext.device.accelerometer.Cordova');
  2457. }
  2458. return Ext.create('Ext.device.accelerometer.Simulator');
  2459. }});
  2460. Ext.define('Ext.device.communicator.Default', {SERVER_URL:'http://localhost:3000', callbackDataMap:{}, callbackIdMap:{}, idSeed:0, globalScopeId:'0', generateId:function() {
  2461. return String(++this.idSeed);
  2462. }, getId:function(object) {
  2463. var id = object.$callbackId;
  2464. if (!id) {
  2465. object.$callbackId = id = this.generateId();
  2466. }
  2467. return id;
  2468. }, getCallbackId:function(callback, scope) {
  2469. var idMap = this.callbackIdMap, dataMap = this.callbackDataMap, id, scopeId, callbackId, data;
  2470. if (!scope) {
  2471. scopeId = this.globalScopeId;
  2472. } else {
  2473. if (scope.isIdentifiable) {
  2474. scopeId = scope.getId();
  2475. } else {
  2476. scopeId = this.getId(scope);
  2477. }
  2478. }
  2479. callbackId = this.getId(callback);
  2480. if (!idMap[scopeId]) {
  2481. idMap[scopeId] = {};
  2482. }
  2483. if (!idMap[scopeId][callbackId]) {
  2484. id = this.generateId();
  2485. data = {callback:callback, scope:scope};
  2486. idMap[scopeId][callbackId] = id;
  2487. dataMap[id] = data;
  2488. }
  2489. return idMap[scopeId][callbackId];
  2490. }, getCallbackData:function(id) {
  2491. return this.callbackDataMap[id];
  2492. }, invoke:function(id, args) {
  2493. var data = this.getCallbackData(id);
  2494. data.callback.apply(data.scope, args);
  2495. }, send:function(args) {
  2496. var callbacks, scope, name, callback;
  2497. if (!args) {
  2498. args = {};
  2499. } else {
  2500. if (args.callbacks) {
  2501. callbacks = args.callbacks;
  2502. scope = args.scope;
  2503. delete args.callbacks;
  2504. delete args.scope;
  2505. for (name in callbacks) {
  2506. if (callbacks.hasOwnProperty(name)) {
  2507. callback = callbacks[name];
  2508. if (typeof callback === 'function') {
  2509. args[name] = this.getCallbackId(callback, scope);
  2510. }
  2511. }
  2512. }
  2513. }
  2514. }
  2515. args.__source = document.location.href;
  2516. var result = this.doSend(args);
  2517. return result && result.length > 0 ? JSON.parse(result) : null;
  2518. }, doSend:function(args) {
  2519. var xhr = new XMLHttpRequest;
  2520. xhr.open('GET', this.SERVER_URL + '?' + Ext.Object.toQueryString(args) + '\x26_dc\x3d' + (new Date).getTime(), false);
  2521. try {
  2522. xhr.send(null);
  2523. return xhr.responseText;
  2524. } catch (e$0) {
  2525. if (args.failure) {
  2526. this.invoke(args.failure);
  2527. } else {
  2528. if (args.callback) {
  2529. this.invoke(args.callback);
  2530. }
  2531. }
  2532. }
  2533. }});
  2534. Ext.define('Ext.device.communicator.Android', {extend:'Ext.device.communicator.Default', doSend:function(args) {
  2535. return window.Sencha.action(JSON.stringify(args));
  2536. }});
  2537. Ext.define('Ext.device.Communicator', {requires:['Ext.device.communicator.Default', 'Ext.device.communicator.Android'], singleton:true, constructor:function() {
  2538. if (Ext.os.is.Android) {
  2539. return new Ext.device.communicator.Android;
  2540. }
  2541. return new Ext.device.communicator.Default;
  2542. }});
  2543. Ext.define('Ext.device.analytics.Abstract', {config:{accountID:null}, updateAccountID:function(newID) {
  2544. if (newID) {
  2545. window.plugins.googleAnalyticsPlugin.startTrackerWithAccountID(newID);
  2546. }
  2547. }, registerAccount:function(accountID) {
  2548. this.setAccountID(accountID);
  2549. }, trackEvent:Ext.emptyFn, trackPageview:Ext.emptyFn});
  2550. Ext.define('Ext.device.analytics.Cordova', {extend:'Ext.device.analytics.Abstract', trackEvent:function(config) {
  2551. if (!this.getAccountID()) {
  2552. return;
  2553. }
  2554. window.plugins.googleAnalyticsPlugin.trackEvent(config.category, config.action, config.label, config.value, config.nonInteraction);
  2555. }, trackPageview:function(page) {
  2556. if (!this.getAccountID()) {
  2557. return;
  2558. }
  2559. window.plugins.googleAnalyticsPlugin.trackPageview(page);
  2560. }});
  2561. Ext.define('Ext.device.Analytics', {alternateClassName:'Ext.ux.device.Analytics', singleton:true, requires:['Ext.device.Communicator', 'Ext.device.analytics.*'], constructor:function() {
  2562. var browserEnv = Ext.browser.is;
  2563. if (browserEnv.WebView && browserEnv.Cordova) {
  2564. return Ext.create('Ext.device.analytics.Cordova');
  2565. } else {
  2566. return Ext.create('Ext.device.analytics.Abstract');
  2567. }
  2568. }});
  2569. Ext.define('Ext.device.browser.Abstract', {open:Ext.emptyFn, close:Ext.emptyFn});
  2570. Ext.define('Ext.device.browser.Cordova', {extend:'Ext.device.browser.Abstract', open:function(config) {
  2571. if (!this._window) {
  2572. this._window = Ext.create('Ext.device.browser.Window');
  2573. }
  2574. this._window.open(config);
  2575. return this._window;
  2576. }, close:function() {
  2577. if (!this._window) {
  2578. return;
  2579. }
  2580. this._window.close();
  2581. }});
  2582. Ext.define('Ext.device.browser.Simulator', {open:function(config) {
  2583. window.open(config.url, '_blank');
  2584. }, close:Ext.emptyFn});
  2585. Ext.define('Ext.device.Browser', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.browser.Cordova', 'Ext.device.browser.Simulator'], constructor:function() {
  2586. var browserEnv = Ext.browser.is;
  2587. if (browserEnv.WebView && browserEnv.Cordova) {
  2588. return Ext.create('Ext.device.browser.Cordova');
  2589. }
  2590. return Ext.create('Ext.device.browser.Simulator');
  2591. }});
  2592. Ext.define('Ext.device.camera.Abstract', {source:{library:0, camera:1, album:2}, destination:{data:0, file:1, 'native':2}, encoding:{jpeg:0, jpg:0, png:1}, media:{picture:0, video:1, all:2}, direction:{back:0, front:1}, capture:Ext.emptyFn, getPicture:Ext.emptyFn, cleanup:Ext.emptyFn});
  2593. Ext.define('Ext.device.camera.Cordova', {alternateClassName:'Ext.device.camera.PhoneGap', extend:'Ext.device.camera.Abstract', getPicture:function(onSuccess, onError, options) {
  2594. try {
  2595. navigator.camera.getPicture(onSuccess, onError, options);
  2596. } catch (e$1) {
  2597. alert(e$1);
  2598. }
  2599. }, cleanup:function(onSuccess, onError) {
  2600. try {
  2601. navigator.camera.cleanup(onSuccess, onError);
  2602. } catch (e$2) {
  2603. alert(e$2);
  2604. }
  2605. }, capture:function(args) {
  2606. var onSuccess = args.success, onError = args.failure, scope = args.scope, sources = this.source, destinations = this.destination, encodings = this.encoding, source = args.source, destination = args.destination, encoding = args.encoding, options = {};
  2607. if (scope) {
  2608. onSuccess = Ext.Function.bind(onSuccess, scope);
  2609. onError = Ext.Function.bind(onError, scope);
  2610. }
  2611. if (source !== undefined) {
  2612. options.sourceType = sources.hasOwnProperty(source) ? sources[source] : source;
  2613. }
  2614. if (destination !== undefined) {
  2615. options.destinationType = destinations.hasOwnProperty(destination) ? destinations[destination] : destination;
  2616. }
  2617. if (encoding !== undefined) {
  2618. options.encodingType = encodings.hasOwnProperty(encoding) ? encodings[encoding] : encoding;
  2619. }
  2620. if ('quality' in args) {
  2621. options.quality = args.quality;
  2622. }
  2623. if ('width' in args) {
  2624. options.targetWidth = args.width;
  2625. }
  2626. if ('height' in args) {
  2627. options.targetHeight = args.height;
  2628. }
  2629. this.getPicture(onSuccess, onError, options);
  2630. }});
  2631. Ext.define('Ext.device.camera.Simulator', {extend:'Ext.device.camera.Abstract', config:{samples:[{success:'http://www.sencha.com/img/sencha-large.png'}]}, constructor:function(config) {
  2632. this.initConfig(config);
  2633. }, updateSamples:function(samples) {
  2634. this.sampleIndex = 0;
  2635. }, capture:function(options) {
  2636. var index = this.sampleIndex, samples = this.getSamples(), samplesCount = samples.length, sample = samples[index], scope = options.scope, success = options.success, failure = options.failure;
  2637. if ('success' in sample) {
  2638. if (success) {
  2639. success.call(scope, sample.success);
  2640. }
  2641. } else {
  2642. if (failure) {
  2643. failure.call(scope, sample.failure);
  2644. }
  2645. }
  2646. if (++index > samplesCount - 1) {
  2647. index = 0;
  2648. }
  2649. this.sampleIndex = index;
  2650. }});
  2651. Ext.define('Ext.device.Camera', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.camera.Cordova', 'Ext.device.camera.Simulator'], constructor:function() {
  2652. var browserEnv = Ext.browser.is;
  2653. if (browserEnv.WebView) {
  2654. if (browserEnv.Cordova) {
  2655. return Ext.create('Ext.device.camera.Cordova');
  2656. }
  2657. }
  2658. return Ext.create('Ext.device.camera.Simulator');
  2659. }});
  2660. Ext.define('Ext.device.capture.Cordova', {captureAudio:function(config) {
  2661. if (!config.success) {
  2662. Ext.Logger.warn('You need to specify a `success` function for #captureAudio');
  2663. }
  2664. var options = {limit:config.limit, duration:config.maximumDuration};
  2665. navigator.device.capture.captureAudio(config.success, config.failure, options);
  2666. }, captureVideo:function(config) {
  2667. if (!config.success) {
  2668. Ext.Logger.warn('You need to specify a `success` function for #captureVideo');
  2669. }
  2670. var options = {limit:config.limit, duration:config.maximumDuration};
  2671. navigator.device.capture.captureVideo(config.success, config.failure, options);
  2672. }});
  2673. Ext.define('Ext.device.capture.Abstract', {alternateClassName:'Ext.device.capture.Simulator', captureAudio:Ext.emptyFn, captureVideo:Ext.emptyFn});
  2674. Ext.define('Ext.device.Capture', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.capture.Cordova', 'Ext.device.capture.Simulator'], constructor:function() {
  2675. var browserEnv = Ext.browser.is;
  2676. if (browserEnv.WebView && browserEnv.Cordova) {
  2677. return Ext.create('Ext.device.capture.Cordova');
  2678. }
  2679. return Ext.create('Ext.device.capture.Simulator');
  2680. }});
  2681. Ext.define('Ext.device.compass.Abstract', {config:{frequency:100}, getHeadingAvailable:function(config) {
  2682. if (!config.callback) {
  2683. Ext.Logger.warn('You need to specify a `callback` function for #getHeadingAvailable');
  2684. }
  2685. return config;
  2686. }, getCurrentHeading:function(config) {
  2687. if (!config.success) {
  2688. Ext.Logger.warn('You need to specify a `success` function for #getCurrentHeading');
  2689. }
  2690. return config;
  2691. }, watchHeading:function(config) {
  2692. var defaultConfig = Ext.device.compass.Abstract.prototype.config;
  2693. config = Ext.applyIf(config, {frequency:defaultConfig.frequency});
  2694. if (!config.callback) {
  2695. Ext.Logger.warn('You need to specify a `callback` function for #watchHeading');
  2696. }
  2697. return config;
  2698. }, clearWatch:Ext.emptyFn});
  2699. Ext.define('Ext.device.compass.Cordova', {alternateClassName:'Ext.device.compass.PhoneGap', extend:'Ext.device.compass.Abstract', activeWatchID:null, getHeadingAvailable:function(config) {
  2700. var callback = function(result) {
  2701. if (result.hasOwnProperty('code')) {
  2702. config.callback.call(config.scope || this, false);
  2703. } else {
  2704. config.callback.call(config.scope || this, true);
  2705. }
  2706. };
  2707. this.getCurrentHeading({success:callback, failure:callback});
  2708. }, getCurrentHeading:function(config) {
  2709. config = this.callParent(arguments);
  2710. navigator.compass.getCurrentHeading(config.success, config.failure);
  2711. return config;
  2712. }, watchHeading:function(config) {
  2713. config = this.callParent(arguments);
  2714. if (this.activeWatchID) {
  2715. this.clearWatch();
  2716. }
  2717. this.activeWatchID = navigator.compass.watchHeading(config.callback, config.failure, config);
  2718. return config;
  2719. }, clearWatch:function() {
  2720. if (this.activeWatchID) {
  2721. navigator.compass.clearWatch(this.activeWatchID);
  2722. this.activeWatchID = null;
  2723. }
  2724. }});
  2725. Ext.define('Ext.device.compass.Simulator', {extend:'Ext.device.compass.Abstract'});
  2726. Ext.define('Ext.device.Compass', {singleton:true, requires:['Ext.device.compass.Cordova', 'Ext.device.compass.Simulator'], constructor:function() {
  2727. var browserEnv = Ext.browser.is;
  2728. if (browserEnv.WebView && browserEnv.Cordova) {
  2729. return Ext.create('Ext.device.compass.Cordova');
  2730. }
  2731. return Ext.create('Ext.device.compass.Simulator');
  2732. }});
  2733. Ext.define('Ext.device.connection.Abstract', {extend:'Ext.Evented', mixins:['Ext.mixin.Observable'], config:{online:false, type:null}, UNKNOWN:'Unknown connection', ETHERNET:'Ethernet connection', WIFI:'WiFi connection', CELL_2G:'Cell 2G connection', CELL_3G:'Cell 3G connection', CELL_4G:'Cell 4G connection', NONE:'No network connection', isOnline:function() {
  2734. return this.getOnline();
  2735. }});
  2736. Ext.define('Ext.device.connection.Cordova', {alternateClassName:'Ext.device.connection.PhoneGap', extend:'Ext.device.connection.Abstract', constructor:function() {
  2737. var me = this;
  2738. document.addEventListener('online', function() {
  2739. me.fireEvent('online', me);
  2740. });
  2741. document.addEventListener('offline', function() {
  2742. me.fireEvent('offline', me);
  2743. });
  2744. }, syncOnline:function() {
  2745. var type = navigator.connection.type;
  2746. this._type = type;
  2747. this._online = type != Connection.NONE;
  2748. }, getOnline:function() {
  2749. this.syncOnline();
  2750. return this._online;
  2751. }, getType:function() {
  2752. this.syncOnline();
  2753. return this._type;
  2754. }});
  2755. Ext.define('Ext.device.connection.Simulator', {extend:'Ext.device.connection.Abstract', getOnline:function() {
  2756. this._online = navigator.onLine;
  2757. this._type = Ext.device.Connection.UNKNOWN;
  2758. return this._online;
  2759. }});
  2760. Ext.define('Ext.device.Connection', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.connection.Cordova', 'Ext.device.connection.Simulator'], constructor:function() {
  2761. var browserEnv = Ext.browser.is;
  2762. if (browserEnv.WebView) {
  2763. if (browserEnv.Cordova) {
  2764. return Ext.create('Ext.device.connection.Cordova');
  2765. }
  2766. }
  2767. return Ext.create('Ext.device.connection.Simulator');
  2768. }});
  2769. Ext.define('Ext.device.contacts.Abstract', {mixins:['Ext.mixin.Observable'], config:{includeImages:false}, getContacts:function(config) {
  2770. if (!this._store) {
  2771. this._store = [{first:'Peter', last:'Venkman', emails:{work:'peter.venkman@gb.com'}}, {first:'Egon', last:'Spengler', emails:{work:'egon.spengler@gb.com'}}];
  2772. }
  2773. config.success.call(config.scope || this, this._store);
  2774. }, getThumbnail:function(config) {
  2775. config.callback.call(config.scope || this, '');
  2776. }, getLocalizedLabel:function(config) {
  2777. config.callback.call(config.scope || this, config.label.toUpperCase(), config.label);
  2778. }});
  2779. Ext.define('Ext.device.contacts.Cordova', {alternateClassName:'Ext.device.contacts.PhoneGap', extend:'Ext.device.contacts.Abstract', getContacts:function(config) {
  2780. if (!config) {
  2781. Ext.Logger.warn('Ext.device.Contacts#getContacts: You must specify a `config` object.');
  2782. return false;
  2783. }
  2784. if (!config.success) {
  2785. Ext.Logger.warn('Ext.device.Contacts#getContacts: You must specify a `success` method.');
  2786. return false;
  2787. }
  2788. if (!config.fields) {
  2789. config.fields = ['*'];
  2790. }
  2791. if (!Ext.isArray(config.fields)) {
  2792. config.fields = [config.fields];
  2793. }
  2794. if (Ext.isEmpty(config.multiple)) {
  2795. config.multiple = true;
  2796. }
  2797. navigator.contacts.find(config.fields, config.success, config.failure, config);
  2798. }});
  2799. Ext.define('Ext.device.Contacts', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.contacts.Cordova'], constructor:function() {
  2800. var browserEnv = Ext.browser.is;
  2801. if (browserEnv.WebView) {
  2802. if (browserEnv.Cordova) {
  2803. return Ext.create('Ext.device.contacts.Cordova');
  2804. }
  2805. }
  2806. return Ext.create('Ext.device.contacts.Abstract');
  2807. }});
  2808. Ext.define('Ext.device.device.Abstract', {mixins:['Ext.mixin.Observable'], name:'not available', uuid:'anonymous', platform:Ext.os.name, scheme:false, openURL:function(url) {
  2809. window.location = url;
  2810. }});
  2811. Ext.define('Ext.device.device.Cordova', {alternateClassName:'Ext.device.device.PhoneGap', extend:'Ext.device.device.Abstract', availableListeners:['pause', 'resume', 'backbutton', 'batterycritical', 'batterylow', 'batterystatus', 'menubutton', 'searchbutton', 'startcallbutton', 'endcallbutton', 'volumeupbutton', 'volumedownbutton'], constructor:function() {
  2812. if (Ext.isReady) {
  2813. this.onReady();
  2814. } else {
  2815. Ext.onReady(this.onReady, this, {single:true});
  2816. }
  2817. }, onReady:function() {
  2818. var me = this, device = window.device;
  2819. me.name = device.name || device.model;
  2820. me.cordova = device.cordova;
  2821. me.platform = device.platform || Ext.os.name;
  2822. me.uuid = device.uuid;
  2823. me.version = device.version;
  2824. me.model = device.model;
  2825. }, privates:{doAddListener:function(name) {
  2826. var me = this;
  2827. if (!me.addedListeners) {
  2828. me.addedListeners = [];
  2829. }
  2830. if (me.availableListeners.indexOf(name) != -1 && me.addedListeners.indexOf(name) == -1) {
  2831. me.addedListeners.push(name);
  2832. document.addEventListener(name, function() {
  2833. me.fireEvent(name, me);
  2834. });
  2835. }
  2836. Ext.device.Device.mixins.observable.doAddListener.apply(Ext.device.Device.mixins.observable, arguments);
  2837. }}});
  2838. Ext.define('Ext.device.device.Simulator', {extend:'Ext.device.device.Abstract'});
  2839. Ext.define('Ext.device.Device', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.device.Cordova', 'Ext.device.device.Simulator'], constructor:function() {
  2840. var browserEnv = Ext.browser.is;
  2841. if (browserEnv.WebView) {
  2842. if (browserEnv.Cordova) {
  2843. return Ext.create('Ext.device.device.Cordova');
  2844. }
  2845. }
  2846. return Ext.create('Ext.device.device.Simulator');
  2847. }});
  2848. Ext.define('Ext.device.filesystem.Abstract', {config:{fileSystemType:1, fileSystemSize:0, readerType:'text', stringEncoding:'UTF8'}, requestFileSystem:function(config) {
  2849. var defaultConfig = Ext.device.filesystem.Abstract.prototype.config;
  2850. config = Ext.applyIf(config, {type:defaultConfig.fileSystemType, size:defaultConfig.fileSystemSize, success:Ext.emptyFn, failure:Ext.emptyFn});
  2851. return config;
  2852. }});
  2853. Ext.define('Ext.device.filesystem.HTML5', {extend:'Ext.device.filesystem.Abstract', requestFileSystem:function(config) {
  2854. if (!config.success) {
  2855. Ext.Logger.error('Ext.device.filesystem#requestFileSystem: You must specify a `success` callback.');
  2856. return null;
  2857. }
  2858. var me = this, successCallback = function(fs) {
  2859. var fileSystem = Ext.create('Ext.device.filesystem.FileSystem', fs);
  2860. config.success.call(config.scope || me, fileSystem);
  2861. };
  2862. window.requestFileSystem(config.type, config.size, successCallback, config.failure || Ext.emptyFn);
  2863. }}, function() {
  2864. Ext.define('Ext.device.filesystem.FileSystem', {fs:null, root:null, constructor:function(fs) {
  2865. this.fs = fs;
  2866. this.root = Ext.create('Ext.device.filesystem.DirectoryEntry', '/', this);
  2867. }, getRoot:function() {
  2868. return this.root;
  2869. }}, function() {
  2870. Ext.define('Ext.device.filesystem.Entry', {directory:false, path:0, fileSystem:null, entry:null, constructor:function(directory, path, fileSystem) {
  2871. this.directory = directory;
  2872. this.path = path;
  2873. this.fileSystem = fileSystem;
  2874. }, isFile:function() {
  2875. return !this.directory;
  2876. }, isDirectory:function() {
  2877. return this.directory;
  2878. }, getName:function() {
  2879. var components = this.path.split('/');
  2880. for (var i = components.length - 1; i >= 0; --i) {
  2881. if (components[i].length > 0) {
  2882. return components[i];
  2883. }
  2884. }
  2885. return '/';
  2886. }, getFullPath:function() {
  2887. return this.path;
  2888. }, getFileSystem:function() {
  2889. return this.fileSystem;
  2890. }, getEntry:function() {
  2891. return null;
  2892. }, moveTo:function(config) {
  2893. if (config.parent == null) {
  2894. Ext.Logger.error('Ext.device.filesystem.Entry#moveTo: You must specify a new `parent` of the entry.');
  2895. return null;
  2896. }
  2897. var me = this;
  2898. this.getEntry({options:config.options || {}, success:function(sourceEntry) {
  2899. config.parent.getEntry({options:config.options || {}, success:function(destinationEntry) {
  2900. if (config.copy) {
  2901. sourceEntry.copyTo(destinationEntry, config.newName, function(entry) {
  2902. config.success.call(config.scope || me, entry.isDirectory ? Ext.create('Ext.device.filesystem.DirectoryEntry', entry.fullPath, me.fileSystem) : Ext.create('Ext.device.filesystem.FileEntry', entry.fullPath, me.fileSystem));
  2903. }, config.failure);
  2904. } else {
  2905. sourceEntry.moveTo(destinationEntry, config.newName, function(entry) {
  2906. config.success.call(config.scope || me, entry.isDirectory ? Ext.create('Ext.device.filesystem.DirectoryEntry', entry.fullPath, me.fileSystem) : Ext.create('Ext.device.filesystem.FileEntry', entry.fullPath, me.fileSystem));
  2907. }, config.failure);
  2908. }
  2909. }, failure:config.failure});
  2910. }, failure:config.failure});
  2911. }, copyTo:function(config) {
  2912. this.moveTo(Ext.apply(config, {copy:true}));
  2913. }, remove:function(config) {
  2914. this.getEntry({success:function(entry) {
  2915. if (config.recursively && this.directory) {
  2916. entry.removeRecursively(config.success, config.failure);
  2917. } else {
  2918. entry.remove(config.success, config.failure);
  2919. }
  2920. }, failure:config.failure});
  2921. }, getParent:function(config) {
  2922. if (!config.success) {
  2923. Ext.Logger.error('Ext.device.filesystem.Entry#getParent: You must specify a `success` callback.');
  2924. return null;
  2925. }
  2926. var me = this;
  2927. this.getEntry({options:config.options || {}, success:function(entry) {
  2928. entry.getParent(function(parentEntry) {
  2929. config.success.call(config.scope || me, parentEntry.isDirectory ? Ext.create('Ext.device.filesystem.DirectoryEntry', parentEntry.fullPath, me.fileSystem) : Ext.create('Ext.device.filesystem.FileEntry', parentEntry.fullPath, me.fileSystem));
  2930. }, config.failure);
  2931. }, failure:config.failure});
  2932. }});
  2933. Ext.define('Ext.device.filesystem.DirectoryEntry', {extend:'Ext.device.filesystem.Entry', cachedDirectory:null, constructor:function(path, fileSystem) {
  2934. this.callParent([true, path, fileSystem]);
  2935. }, getEntry:function(config) {
  2936. var me = this, callback = config.success;
  2937. if (config.options && config.options.create && this.path) {
  2938. var folders = this.path.split('/');
  2939. if (folders[0] == '.' || folders[0] == '') {
  2940. folders = folders.slice(1);
  2941. }
  2942. var recursiveCreation = function(dirEntry) {
  2943. if (folders.length) {
  2944. dirEntry.getDirectory(folders.shift(), config.options, recursiveCreation, config.failure);
  2945. } else {
  2946. callback(dirEntry);
  2947. }
  2948. };
  2949. recursiveCreation(this.fileSystem.fs.root);
  2950. } else {
  2951. this.fileSystem.fs.root.getDirectory(this.path, config.options, function(directory) {
  2952. config.success.call(config.scope || me, directory);
  2953. }, config.failure);
  2954. }
  2955. }, readEntries:function(config) {
  2956. if (!config.success) {
  2957. Ext.Logger.error('Ext.device.filesystem.DirectoryEntry#readEntries: You must specify a `success` callback.');
  2958. return null;
  2959. }
  2960. var me = this;
  2961. this.getEntry({success:function(dirEntry) {
  2962. var directoryReader = dirEntry.createReader();
  2963. directoryReader.readEntries(function(entryInfos) {
  2964. var entries = [], i = 0, len = entryInfos.length;
  2965. for (; i < len; i++) {
  2966. entryInfo = entryInfos[i];
  2967. entries[i] = entryInfo.isDirectory ? Ext.create('Ext.device.filesystem.DirectoryEntry', entryInfo.fullPath, me.fileSystem) : Ext.create('Ext.device.filesystem.FileEntry', entryInfo.fullPath, me.fileSystem);
  2968. }
  2969. config.success.call(config.scope || this, entries);
  2970. }, function(error) {
  2971. if (config.failure) {
  2972. config.failure.call(config.scope || this, error);
  2973. }
  2974. });
  2975. }, failure:config.failure});
  2976. }, getFile:function(config) {
  2977. if (config.path == null) {
  2978. Ext.Logger.error('Ext.device.filesystem.DirectoryEntry#getFile: You must specify a `path` of the file.');
  2979. return null;
  2980. }
  2981. var me = this, fullPath = this.path + config.path, fileEntry = Ext.create('Ext.device.filesystem.FileEntry', fullPath, this.fileSystem);
  2982. fileEntry.getEntry({success:function() {
  2983. config.success.call(config.scope || me, fileEntry);
  2984. }, options:config.options || {}, failure:config.failure});
  2985. }, getDirectory:function(config) {
  2986. if (config.path == null) {
  2987. Ext.Logger.error('Ext.device.filesystem.DirectoryEntry#getFile: You must specify a `path` of the file.');
  2988. return null;
  2989. }
  2990. var me = this, fullPath = this.path + config.path, directoryEntry = Ext.create('Ext.device.filesystem.DirectoryEntry', fullPath, this.fileSystem);
  2991. directoryEntry.getEntry({success:function() {
  2992. config.success.call(config.scope || me, directoryEntry);
  2993. }, options:config.options || {}, failure:config.failure});
  2994. }, removeRecursively:function(config) {
  2995. this.remove(Ext.apply(config, {recursively:true}));
  2996. }});
  2997. Ext.define('Ext.device.filesystem.FileEntry', {extend:'Ext.device.filesystem.Entry', length:0, offset:0, constructor:function(path, fileSystem) {
  2998. this.callParent([false, path, fileSystem]);
  2999. this.offset = 0;
  3000. this.length = 0;
  3001. }, getEntry:function(config) {
  3002. var me = this, originalConfig = Ext.applyIf({}, config);
  3003. if (this.fileSystem) {
  3004. var failure = function(evt) {
  3005. if (config.options && config.options.create && Ext.isString(this.path)) {
  3006. var folders = this.path.split('/');
  3007. if (folders[0] == '.' || folders[0] == '') {
  3008. folders = folders.slice(1);
  3009. }
  3010. if (folders.length > 1 && !config.recursive === true) {
  3011. folders.pop();
  3012. var dirEntry = Ext.create('Ext.device.filesystem.DirectoryEntry', folders.join('/'), me.fileSystem);
  3013. dirEntry.getEntry({options:config.options, success:function() {
  3014. originalConfig.recursive = true;
  3015. me.getEntry(originalConfig);
  3016. }, failure:config.failure});
  3017. } else {
  3018. if (config.failure) {
  3019. config.failure.call(config.scope || me, evt);
  3020. }
  3021. }
  3022. } else {
  3023. if (config.failure) {
  3024. config.failure.call(config.scope || me, evt);
  3025. }
  3026. }
  3027. };
  3028. this.fileSystem.fs.root.getFile(this.path, config.options || null, function(fileEntry) {
  3029. fileEntry.file(function(file) {
  3030. me.length = file.size;
  3031. originalConfig.success.call(config.scope || me, fileEntry);
  3032. }, function(error) {
  3033. failure.call(config.scope || me, error);
  3034. });
  3035. }, function(error) {
  3036. failure.call(config.scope || me, error);
  3037. });
  3038. } else {
  3039. config.failure({code:-1, message:'FileSystem not Initialized'});
  3040. }
  3041. }, getOffset:function() {
  3042. return this.offset;
  3043. }, seek:function(config) {
  3044. if (config.offset == null) {
  3045. Ext.Logger.error('Ext.device.filesystem.FileEntry#seek: You must specify an `offset` in the file.');
  3046. return null;
  3047. }
  3048. this.offset = config.offset || 0;
  3049. if (config.success) {
  3050. config.success.call(config.scope || this);
  3051. }
  3052. }, read:function(config) {
  3053. var me = this;
  3054. this.getEntry({success:function(fileEntry) {
  3055. fileEntry.file(function(file) {
  3056. if (Ext.isNumber(config.length)) {
  3057. if (Ext.isFunction(file.slice)) {
  3058. file = file.slice(me.offset, config.length);
  3059. } else {
  3060. if (config.failure) {
  3061. config.failure.call(config.scope || me, {code:-2, message:'File missing slice functionality'});
  3062. }
  3063. return;
  3064. }
  3065. }
  3066. var reader = new FileReader;
  3067. reader.onloadend = function(evt) {
  3068. config.success.call(config.scope || me, evt.target.result);
  3069. };
  3070. reader.onerror = function(error) {
  3071. config.failure.call(config.scope || me, error);
  3072. };
  3073. if (config.reader) {
  3074. reader = Ext.applyIf(reader, config.reader);
  3075. }
  3076. config.encoding = config.encoding || 'UTF8';
  3077. switch(config.type) {
  3078. default:
  3079. case 'text':
  3080. reader.readAsText(file, config.encoding);
  3081. break;
  3082. case 'dataURL':
  3083. reader.readAsDataURL(file);
  3084. break;
  3085. case 'binaryString':
  3086. reader.readAsBinaryString(file);
  3087. break;
  3088. case 'arrayBuffer':
  3089. reader.readAsArrayBuffer(file);
  3090. break;
  3091. }
  3092. }, function(error) {
  3093. config.failure.call(config.scope || me, error);
  3094. });
  3095. }, failure:function(error) {
  3096. config.failure.call(config.scope || me, error);
  3097. }});
  3098. }, write:function(config) {
  3099. if (config.data == null) {
  3100. Ext.Logger.error('Ext.device.filesystem.FileEntry#write: You must specify `data` to write into the file.');
  3101. return null;
  3102. }
  3103. var me = this;
  3104. this.getEntry({options:config.options || {}, success:function(fileEntry) {
  3105. fileEntry.createWriter(function(writer) {
  3106. writer.onwriteend = function(evt) {
  3107. me.length = evt.target.length;
  3108. config.success.call(config.scope || me, evt.result);
  3109. };
  3110. writer.onerror = function(error) {
  3111. config.failure.call(config.scope || me, error);
  3112. };
  3113. if (config.writer) {
  3114. writer = Ext.applyIf(writer, config.writer);
  3115. }
  3116. if (me.offset) {
  3117. writer.seek(me.offset);
  3118. } else {
  3119. if (config.append) {
  3120. writer.seek(me.length);
  3121. }
  3122. }
  3123. me.writeData(writer, config.data);
  3124. }, function(error) {
  3125. config.failure.call(config.scope || me, error);
  3126. });
  3127. }, failure:function(error) {
  3128. config.failure.call(config.scope || me, error);
  3129. }});
  3130. }, writeData:function(writer, data) {
  3131. writer.write(new Blob([data]));
  3132. }, truncate:function(config) {
  3133. if (config.size == null) {
  3134. Ext.Logger.error('Ext.device.filesystem.FileEntry#write: You must specify a `size` of the file.');
  3135. return null;
  3136. }
  3137. var me = this;
  3138. this.getEntry({success:function(fileEntry) {
  3139. fileEntry.createWriter(function(writer) {
  3140. writer.truncate(config.size);
  3141. config.success.call(config.scope || me, me);
  3142. }, function(error) {
  3143. config.failure.call(config.scope || me, error);
  3144. });
  3145. }, failure:function(error) {
  3146. config.failure.call(config.scope || me, error);
  3147. }});
  3148. }});
  3149. });
  3150. });
  3151. Ext.define('Ext.device.filesystem.Cordova', {alternateClassName:'Ext.device.filesystem.PhoneGap', extend:'Ext.device.filesystem.HTML5', constructor:function() {
  3152. Ext.override(Ext.device.filesystem.Entry, {writeMetadata:function(config) {
  3153. var me = this;
  3154. this.getEntry({options:config.options, success:function(entry) {
  3155. entry.setMetadata(function() {
  3156. config.success.call(config.scope || me);
  3157. }, function(error) {
  3158. config.failure.call(config.scope || me, error);
  3159. }, config.metadata);
  3160. }, failure:function(error) {
  3161. config.failure.call(config.scope || me, error);
  3162. }});
  3163. }, readMetadata:function(config) {
  3164. var me = this;
  3165. this.getEntry({options:config.options, success:function(entry) {
  3166. entry.getMetadata(function(metadata) {
  3167. config.success.call(config.scope || me, metadata);
  3168. }, function(error) {
  3169. config.failure.call(config.scope || me, error);
  3170. });
  3171. }, failure:function(error) {
  3172. config.failure.call(config.scope || me, error);
  3173. }});
  3174. }});
  3175. Ext.override(Ext.device.filesystem.FileEntry, {writeData:function(writer, data) {
  3176. writer.write(data.toString());
  3177. }, upload:function(config) {
  3178. var options = new FileUploadOptions;
  3179. options.fileKey = config.fileKey || 'file';
  3180. options.fileName = this.path.substr(this.path.lastIndexOf('/') + 1);
  3181. options.mimeType = config.mimeType || 'image/jpeg';
  3182. options.params = config.params || {};
  3183. options.headers = config.headers || {};
  3184. options.chunkMode = config.chunkMode || true;
  3185. var fileTransfer = new FileTransfer;
  3186. fileTransfer.upload(this.path, encodeURI(config.url), config.success, config.failure, options, config.trustAllHosts || false);
  3187. return fileTransfer;
  3188. }, download:function(config) {
  3189. var fileTransfer = new FileTransfer;
  3190. fileTransfer.download(encodeURI(config.source), this.path, config.success, config.failure, config.trustAllHosts || false, config.options || {});
  3191. return fileTransfer;
  3192. }});
  3193. }});
  3194. Ext.define('Ext.device.filesystem.Chrome', {extend:'Ext.device.filesystem.HTML5', requestFileSystem:function(config) {
  3195. var me = this;
  3196. config = Ext.device.filesystem.Abstract.prototype.requestFileSystem(config);
  3197. var successCallback = function(fs) {
  3198. var fileSystem = Ext.create('Ext.device.filesystem.FileSystem', fs);
  3199. config.success.call(config.scope || me, fileSystem);
  3200. };
  3201. if (config.type == window.PERSISTENT) {
  3202. if (navigator.webkitPersistentStorage) {
  3203. navigator.webkitPersistentStorage.requestQuota(config.size, function(grantedBytes) {
  3204. window.webkitRequestFileSystem(config.type, grantedBytes, successCallback, config.failure);
  3205. });
  3206. } else {
  3207. window.webkitStorageInfo.requestQuota(window.PERSISTENT, config.size, function(grantedBytes) {
  3208. window.webkitRequestFileSystem(config.type, grantedBytes, successCallback, config.failure);
  3209. });
  3210. }
  3211. } else {
  3212. window.webkitRequestFileSystem(config.type, config.size, successCallback, config.failure);
  3213. }
  3214. }});
  3215. Ext.define('Ext.device.filesystem.Simulator', {extend:'Ext.device.filesystem.HTML5'});
  3216. Ext.define('Ext.device.FileSystem', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.filesystem.Cordova', 'Ext.device.filesystem.Chrome', 'Ext.device.filesystem.Simulator'], constructor:function() {
  3217. var browserEnv = Ext.browser.is;
  3218. if (browserEnv.WebView) {
  3219. if (browserEnv.Cordova) {
  3220. return Ext.create('Ext.device.filesystem.Cordova');
  3221. }
  3222. } else {
  3223. if (browserEnv.Chrome) {
  3224. return Ext.create('Ext.device.filesystem.Chrome');
  3225. }
  3226. }
  3227. return Ext.create('Ext.device.filesystem.Simulator');
  3228. }});
  3229. Ext.define('Ext.device.geolocation.Abstract', {config:{maximumAge:0, frequency:10000, allowHighAccuracy:false, timeout:Infinity}, getCurrentPosition:function(config) {
  3230. var defaultConfig = Ext.device.geolocation.Abstract.prototype.config;
  3231. config = Ext.applyIf(config, {maximumAge:defaultConfig.maximumAge, frequency:defaultConfig.frequency, allowHighAccuracy:defaultConfig.allowHighAccuracy, timeout:defaultConfig.timeout});
  3232. if (!config.success) {
  3233. Ext.Logger.warn('You need to specify a `success` function for #getCurrentPosition');
  3234. }
  3235. return config;
  3236. }, watchPosition:function(config) {
  3237. var defaultConfig = Ext.device.geolocation.Abstract.prototype.config;
  3238. config = Ext.applyIf(config, {maximumAge:defaultConfig.maximumAge, frequency:defaultConfig.frequency, allowHighAccuracy:defaultConfig.allowHighAccuracy, timeout:defaultConfig.timeout});
  3239. if (!config.callback) {
  3240. Ext.Logger.warn('You need to specify a `callback` function for #watchPosition');
  3241. }
  3242. return config;
  3243. }, clearWatch:function() {
  3244. }});
  3245. Ext.define('Ext.device.geolocation.Cordova', {alternateClassName:'Ext.device.geolocation.PhoneGap', extend:'Ext.device.geolocation.Abstract', activeWatchID:null, getCurrentPosition:function(config) {
  3246. config = this.callParent(arguments);
  3247. navigator.geolocation.getCurrentPosition(config.success, config.failure, config);
  3248. return config;
  3249. }, watchPosition:function(config) {
  3250. config = this.callParent(arguments);
  3251. if (this.activeWatchID) {
  3252. this.clearWatch();
  3253. }
  3254. this.activeWatchID = navigator.geolocation.watchPosition(config.callback, config.failure, config);
  3255. return config;
  3256. }, clearWatch:function() {
  3257. if (this.activeWatchID) {
  3258. navigator.geolocation.clearWatch(this.activeWatchID);
  3259. this.activeWatchID = null;
  3260. }
  3261. }});
  3262. Ext.define('Ext.device.geolocation.Simulator', {extend:'Ext.device.geolocation.Abstract', requires:['Ext.util.Geolocation'], getCurrentPosition:function(config) {
  3263. config = this.callParent([config]);
  3264. Ext.apply(config, {autoUpdate:false, listeners:{scope:this, locationupdate:function(geolocation) {
  3265. if (config.success) {
  3266. config.success.call(config.scope || this, geolocation.position);
  3267. }
  3268. }, locationerror:function() {
  3269. if (config.failure) {
  3270. config.failure.call(config.scope || this);
  3271. }
  3272. }}});
  3273. this.geolocation = Ext.create('Ext.util.Geolocation', config);
  3274. this.geolocation.updateLocation();
  3275. return config;
  3276. }, watchPosition:function(config) {
  3277. config = this.callParent([config]);
  3278. Ext.apply(config, {listeners:{scope:this, locationupdate:function(geolocation) {
  3279. if (config.callback) {
  3280. config.callback.call(config.scope || this, geolocation.position);
  3281. }
  3282. }, locationerror:function() {
  3283. if (config.failure) {
  3284. config.failure.call(config.scope || this);
  3285. }
  3286. }}});
  3287. this.geolocation = Ext.create('Ext.util.Geolocation', config);
  3288. return config;
  3289. }, clearWatch:function() {
  3290. if (this.geolocation) {
  3291. this.geolocation.destroy();
  3292. }
  3293. this.geolocation = null;
  3294. }});
  3295. Ext.define('Ext.device.Geolocation', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.geolocation.Cordova', 'Ext.device.geolocation.Simulator'], constructor:function() {
  3296. var browserEnv = Ext.browser.is;
  3297. if (browserEnv.WebView) {
  3298. if (browserEnv.Cordova) {
  3299. return Ext.create('Ext.device.geolocation.Cordova');
  3300. }
  3301. }
  3302. return Ext.create('Ext.device.geolocation.Simulator');
  3303. }});
  3304. Ext.define('Ext.device.globalization.Abstract', {mixins:['Ext.mixin.Observable'], config:{formatLength:'full', selector:'date and time', dateType:'wide', items:'months', numberType:'decimal', currencyCode:'USD'}, getPreferredLanguage:function(config) {
  3305. if (!config.success) {
  3306. Ext.Logger.warn('You need to specify a `success` function for #getPreferredLanguage');
  3307. }
  3308. return config;
  3309. }, getLocaleName:function(config) {
  3310. if (!config.success) {
  3311. Ext.Logger.warn('You need to specify a `success` function for #getLocaleName');
  3312. }
  3313. return config;
  3314. }, dateToString:function(config) {
  3315. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3316. config = Ext.applyIf(config, {date:new Date, formatLength:defaultConfig.formatLength, selector:defaultConfig.selector});
  3317. if (!config.success) {
  3318. Ext.Logger.warn('You need to specify a `success` function for #dateToString');
  3319. }
  3320. return config;
  3321. }, stringToDate:function(config) {
  3322. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3323. config = Ext.applyIf(config, {dateString:Ext.util.Format.date(new Date, 'm/d/Y'), formatLength:defaultConfig.formatLength, selector:defaultConfig.selector});
  3324. if (!config.success) {
  3325. Ext.Logger.warn('You need to specify a `success` function for #stringToDate');
  3326. }
  3327. return config;
  3328. }, getDatePattern:function(config) {
  3329. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3330. config = Ext.applyIf(config, {formatLength:defaultConfig.formatLength, selector:defaultConfig.selector});
  3331. if (!config.success) {
  3332. Ext.Logger.warn('You need to specify a `success` function for #getDatePattern');
  3333. }
  3334. return config;
  3335. }, getDateNames:function(config) {
  3336. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3337. config = Ext.applyIf(config, {type:defaultConfig.dateType, items:defaultConfig.items});
  3338. if (!config.success) {
  3339. Ext.Logger.warn('You need to specify a `success` function for #getDateNames');
  3340. }
  3341. return config;
  3342. }, isDayLightSavingsTime:function(config) {
  3343. config = Ext.applyIf(config, {date:new Date});
  3344. if (!config.success) {
  3345. Ext.Logger.warn('You need to specify a `success` function for #isDayLightSavingsTime');
  3346. }
  3347. return config;
  3348. }, getFirstDayOfWeek:function(config) {
  3349. if (!config.success) {
  3350. Ext.Logger.warn('You need to specify a `success` function for #getFirstDayOfWeek');
  3351. }
  3352. return config;
  3353. }, numberToString:function(config) {
  3354. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3355. config = Ext.applyIf(config, {number:defaultConfig.number, type:defaultConfig.numberType});
  3356. if (!config.number) {
  3357. Ext.Logger.warn('You need to specify a `number` for #numberToString');
  3358. }
  3359. if (!config.success) {
  3360. Ext.Logger.warn('You need to specify a `success` function for #numberToString');
  3361. }
  3362. return config;
  3363. }, stringToNumber:function(config) {
  3364. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3365. config = Ext.applyIf(config, {type:defaultConfig.numberType});
  3366. if (!config.number) {
  3367. Ext.Logger.warn('You need to specify a `string` for #stringToNumber');
  3368. }
  3369. if (!config.success) {
  3370. Ext.Logger.warn('You need to specify a `success` function for #stringToNumber');
  3371. }
  3372. return config;
  3373. }, getNumberPattern:function(config) {
  3374. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3375. config = Ext.applyIf(config, {type:defaultConfig.numberType});
  3376. if (!config.success) {
  3377. Ext.Logger.warn('You need to specify a `success` function for #getNumberPattern');
  3378. }
  3379. return config;
  3380. }, getCurrencyPattern:function(config) {
  3381. var defaultConfig = Ext.device.globalization.Abstract.prototype.config;
  3382. config = Ext.applyIf(config, {currencyCode:defaultConfig.currencyCode});
  3383. if (!config.success) {
  3384. Ext.Logger.warn('You need to specify a `success` function for #getCurrency');
  3385. }
  3386. return config;
  3387. }});
  3388. Ext.define('Ext.device.globalization.Cordova', {alternateClassName:'Ext.device.globalization.PhoneGap', extend:'Ext.device.globalization.Abstract', getPreferredLanguage:function(config) {
  3389. config = this.callParent(arguments);
  3390. navigator.globalization.getPreferredLanguage(config.success, config.error);
  3391. }, getLocaleName:function(config) {
  3392. config = this.callParent(arguments);
  3393. navigator.globalization.getLocaleName(config.success, config.error);
  3394. }, dateToString:function(config) {
  3395. config = this.callParent(arguments);
  3396. navigator.globalization.dateToString(config.date, config.success, config.error, config);
  3397. }, stringToDate:function(config) {
  3398. config = this.callParent(arguments);
  3399. navigator.globalization.stringToDate(config.dateString, config.success, config.error, config);
  3400. }, getDatePattern:function(config) {
  3401. config = this.callParent(arguments);
  3402. navigator.globalization.getDatePattern(config.success, config.error, config);
  3403. }, getDateNames:function(config) {
  3404. config = this.callParent(arguments);
  3405. navigator.globalization.getDateNames(config.success, config.error, config);
  3406. }, isDayLightSavingsTime:function(config) {
  3407. config = this.callParent(arguments);
  3408. navigator.globalization.isDayLightSavingsTime(config.date, config.success, config.error, config);
  3409. }, getFirstDayOfWeek:function(config) {
  3410. config = this.callParent(arguments);
  3411. navigator.globalization.getFirstDayOfWeek(config.success, config.error);
  3412. }, numberToString:function(config) {
  3413. config = this.callParent(arguments);
  3414. navigator.globalization.numberToString(config.number, config.success, config.error, config);
  3415. }, stringToNumber:function(config) {
  3416. config = this.callParent(arguments);
  3417. navigator.globalization.stringToNumber(config.string, config.success, config.error, config);
  3418. }, getNumberPattern:function(config) {
  3419. config = this.callParent(arguments);
  3420. navigator.globalization.getNumberPattern(config.success, config.error, config);
  3421. }, getCurrencyPattern:function(config) {
  3422. config = this.callParent(arguments);
  3423. navigator.globalization.getCurrencyPattern(config.currencyCode, config.success, config.error);
  3424. }});
  3425. Ext.define('Ext.device.globalization.Simulator', {extend:'Ext.device.globalization.Abstract'});
  3426. Ext.define('Ext.device.Globalization', {singleton:true, requires:['Ext.device.globalization.Cordova', 'Ext.device.globalization.Simulator'], constructor:function() {
  3427. var browserEnv = Ext.browser.is;
  3428. if (browserEnv.WebView) {
  3429. if (browserEnv.Cordova) {
  3430. return Ext.create('Ext.device.globalization.Cordova');
  3431. }
  3432. }
  3433. return Ext.create('Ext.device.globalization.Simulator');
  3434. }});
  3435. Ext.define('Ext.device.media.Abstract', {mixins:['Ext.mixin.Observable'], config:{src:null}, play:Ext.emptyFn, pause:Ext.emptyFn, stop:Ext.emptyFn, release:Ext.emptyFn, seekTo:Ext.emptyFn, getCurrentPosition:Ext.emptyFn, getDuration:Ext.emptyFn, startRecord:Ext.emptyFn, stopRecord:Ext.emptyFn});
  3436. Ext.define('Ext.device.media.Cordova', {alternateClassName:'Ext.device.media.PhoneGap', extend:'Ext.device.media.Abstract', config:{src:null, media:null}, updateSrc:function(newSrc, oldSrc) {
  3437. this.setMedia(new Media(newSrc));
  3438. }, play:function() {
  3439. var media = this.getMedia();
  3440. if (media) {
  3441. media.play();
  3442. }
  3443. }, pause:function() {
  3444. var media = this.getMedia();
  3445. if (media) {
  3446. media.pause();
  3447. }
  3448. }, stop:function() {
  3449. var media = this.getMedia();
  3450. if (media) {
  3451. media.stop();
  3452. }
  3453. }, release:function() {
  3454. var media = this.getMedia();
  3455. if (media) {
  3456. media.release();
  3457. }
  3458. }, seekTo:function(miliseconds) {
  3459. var media = this.getMedia();
  3460. if (media) {
  3461. media.seekTo(miliseconds);
  3462. }
  3463. }, getDuration:function() {
  3464. var media = this.getMedia();
  3465. if (media) {
  3466. media.getDuration();
  3467. }
  3468. }, startRecord:function() {
  3469. var media = this.getMedia();
  3470. if (!media) {
  3471. this.setSrc(null);
  3472. }
  3473. media.startRecord();
  3474. }, stopRecord:function() {
  3475. var media = this.getMedia();
  3476. if (media) {
  3477. media.stopRecord();
  3478. }
  3479. }});
  3480. Ext.define('Ext.device.Media', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.media.Cordova'], constructor:function() {
  3481. var browserEnv = Ext.browser.is;
  3482. if (browserEnv.WebView && browserEnv.Cordova) {
  3483. return Ext.create('Ext.device.media.Cordova');
  3484. }
  3485. return Ext.create('Ext.device.media.Abstract');
  3486. }});
  3487. Ext.define('Ext.device.notification.Abstract', {show:function(config) {
  3488. if (!config.message) {
  3489. throw '[Ext.device.Notification#show] You passed no message';
  3490. }
  3491. if (!config.buttons) {
  3492. config.buttons = ['OK', 'Cancel'];
  3493. }
  3494. if (!Ext.isArray(config.buttons)) {
  3495. config.buttons = [config.buttons];
  3496. }
  3497. if (!config.scope) {
  3498. config.scope = this;
  3499. }
  3500. return config;
  3501. }, alert:function(config) {
  3502. if (!config.message) {
  3503. throw '[Ext.device.Notification#alert] You passed no message';
  3504. }
  3505. if (!config.scope) {
  3506. config.scope = this;
  3507. }
  3508. return config;
  3509. }, confirm:function(config) {
  3510. if (!config.message) {
  3511. throw '[Ext.device.Notification#confirm] You passed no message';
  3512. }
  3513. if (!config.buttons) {
  3514. config.buttons = ['OK', 'Cancel'];
  3515. }
  3516. if (!Ext.isArray(config.buttons)) {
  3517. config.buttons = [config.buttons];
  3518. }
  3519. if (!config.scope) {
  3520. config.scope = this;
  3521. }
  3522. return config;
  3523. }, prompt:function(config) {
  3524. if (!config.message) {
  3525. throw '[Ext.device.Notification#prompt] You passed no message';
  3526. }
  3527. if (!config.buttons) {
  3528. config.buttons = ['OK', 'Cancel'];
  3529. }
  3530. if (!Ext.isArray(config.buttons)) {
  3531. config.buttons = [config.buttons];
  3532. }
  3533. if (!config.scope) {
  3534. config.scope = this;
  3535. }
  3536. return config;
  3537. }, vibrate:Ext.emptyFn, beep:Ext.emptyFn});
  3538. Ext.define('Ext.device.notification.Cordova', {alternateClassName:'Ext.device.notification.PhoneGap', extend:'Ext.device.notification.Abstract', requires:['Ext.device.Communicator'], show:function(config) {
  3539. config = this.callParent(arguments);
  3540. this.confirm(config);
  3541. }, confirm:function(config) {
  3542. config = this.callParent(arguments);
  3543. var buttons = config.buttons, ln = config.buttons.length;
  3544. if (ln && typeof buttons[0] !== 'string') {
  3545. var newButtons = [], i;
  3546. for (i = 0; i < ln; i++) {
  3547. newButtons.push(buttons[i].text);
  3548. }
  3549. buttons = newButtons;
  3550. }
  3551. var callback = function(index) {
  3552. if (config.callback) {
  3553. config.callback.apply(config.scope, buttons ? [buttons[index - 1].toLowerCase()] : []);
  3554. }
  3555. };
  3556. navigator.notification.confirm(config.message, callback, config.title, buttons);
  3557. }, alert:function(config) {
  3558. navigator.notification.alert(config.message, config.callback, config.title, config.buttonName);
  3559. }, prompt:function(config) {
  3560. config = this.callParent(arguments);
  3561. var buttons = config.buttons, ln = config.buttons.length;
  3562. if (ln && typeof buttons[0] !== 'string') {
  3563. var newButtons = [], i;
  3564. for (i = 0; i < ln; i++) {
  3565. newButtons.push(buttons[i].text);
  3566. }
  3567. buttons = newButtons;
  3568. }
  3569. var callback = function(result) {
  3570. if (config.callback) {
  3571. config.callback.call(config.scope, buttons ? buttons[result.buttonIndex - 1].toLowerCase() : null, result.input1);
  3572. }
  3573. };
  3574. navigator.notification.prompt(config.message, callback, config.title, buttons);
  3575. }, vibrate:function(time) {
  3576. navigator.notification.vibrate(time);
  3577. }, beep:function(times) {
  3578. navigator.notification.vibrate(times);
  3579. }});
  3580. Ext.define('Ext.device.notification.Simulator', {extend:'Ext.device.notification.Abstract', requires:['Ext.MessageBox', 'Ext.util.Audio'], msg:null, show:function() {
  3581. var config = this.callParent(arguments), buttons = [], ln = config.buttons.length, button, i, callback;
  3582. for (i = 0; i < ln; i++) {
  3583. button = config.buttons[i];
  3584. if (Ext.isString(button)) {
  3585. button = {text:config.buttons[i], itemId:config.buttons[i].toLowerCase()};
  3586. }
  3587. buttons.push(button);
  3588. }
  3589. this.msg = Ext.create('Ext.MessageBox');
  3590. callback = function(itemId) {
  3591. if (config.callback) {
  3592. config.callback.apply(config.scope, [itemId]);
  3593. }
  3594. };
  3595. this.msg.show({title:config.title, message:config.message, scope:this.msg, buttons:buttons, fn:callback});
  3596. }, alert:function() {
  3597. var config = this.callParent(arguments);
  3598. if (config.buttonName) {
  3599. config.buttons = [config.buttonName];
  3600. }
  3601. this.show(config);
  3602. }, confirm:function() {
  3603. var config = this.callParent(arguments);
  3604. this.show(config);
  3605. }, prompt:function() {
  3606. var config = this.callParent(arguments), buttons = [], ln = config.buttons.length, button, i, callback;
  3607. for (i = 0; i < ln; i++) {
  3608. button = config.buttons[i];
  3609. if (Ext.isString(button)) {
  3610. button = {text:config.buttons[i], itemId:config.buttons[i].toLowerCase()};
  3611. }
  3612. buttons.push(button);
  3613. }
  3614. this.msg = Ext.create('Ext.MessageBox');
  3615. callback = function(buttonText, value) {
  3616. if (config.callback) {
  3617. config.callback.apply(config.scope, [buttonText, value]);
  3618. }
  3619. };
  3620. this.msg.prompt(config.title, config.message, callback, this.msg, config.multiLine, config.value, config.prompt);
  3621. }, beep:function(times) {
  3622. if (!Ext.isNumber(times)) {
  3623. times = 1;
  3624. }
  3625. var count = 0, callback = function() {
  3626. if (count < times) {
  3627. Ext.defer(function() {
  3628. Ext.util.Audio.beep(callback);
  3629. }, 50);
  3630. }
  3631. count++;
  3632. };
  3633. callback();
  3634. }, vibrate:function() {
  3635. var animation = ['@-webkit-keyframes vibrate{', ' from {', ' -webkit-transform: rotate(-2deg);', ' }', ' to{', ' -webkit-transform: rotate(2deg);', ' }', '}', 'body {', ' -webkit-animation: vibrate 50ms linear 10 alternate;', '}'], head = document.getElementsByTagName('head')[0], cssNode = document.createElement('style');
  3636. cssNode.innerHTML = animation.join('\n');
  3637. head.appendChild(cssNode);
  3638. Ext.defer(function() {
  3639. head.removeChild(cssNode);
  3640. }, 400);
  3641. }});
  3642. Ext.define('Ext.device.Notification', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.notification.Cordova', 'Ext.device.notification.Simulator'], constructor:function() {
  3643. var browserEnv = Ext.browser.is;
  3644. if (browserEnv.WebView) {
  3645. if (browserEnv.Cordova) {
  3646. return Ext.create('Ext.device.notification.Cordova');
  3647. }
  3648. }
  3649. return Ext.create('Ext.device.notification.Simulator');
  3650. }});
  3651. Ext.define('Ext.device.orientation.Abstract', {mixins:['Ext.mixin.Observable'], onDeviceOrientation:function(e) {
  3652. this.doFireEvent('orientationchange', [e]);
  3653. }});
  3654. Ext.define('Ext.device.orientation.HTML5', {extend:'Ext.device.orientation.Abstract', constructor:function() {
  3655. this.callParent(arguments);
  3656. this.onDeviceOrientation = Ext.Function.bind(this.onDeviceOrientation, this);
  3657. window.addEventListener('deviceorientation', this.onDeviceOrientation, true);
  3658. }});
  3659. Ext.define('Ext.device.Orientation', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.orientation.HTML5'], constructor:function() {
  3660. return Ext.create('Ext.device.orientation.HTML5');
  3661. }});
  3662. Ext.define('Ext.device.push.Abstract', {ALERT:1, BADGE:2, SOUND:4, register:function(config) {
  3663. var me = this;
  3664. if (!config.received) {
  3665. Ext.Logger.error('Failed to pass a received callback. This is required.');
  3666. }
  3667. if (config.type == null) {
  3668. Ext.Logger.error('Failed to pass a type. This is required.');
  3669. }
  3670. return {success:function(token) {
  3671. me.onSuccess(token, config.success, config.scope || me);
  3672. }, failure:function(error) {
  3673. me.onFailure(error, config.failure, config.scope || me);
  3674. }, received:function(notifications) {
  3675. me.onReceived(notifications, config.received, config.scope || me);
  3676. }, type:config.type};
  3677. }, onSuccess:function(token, callback, scope) {
  3678. if (callback) {
  3679. callback.call(scope, token);
  3680. }
  3681. }, onFailure:function(error, callback, scope) {
  3682. if (callback) {
  3683. callback.call(scope, error);
  3684. }
  3685. }, onReceived:function(notifications, callback, scope) {
  3686. if (callback) {
  3687. callback.call(scope, notifications);
  3688. }
  3689. }});
  3690. Ext.define('Ext.device.push.Cordova', {extend:'Ext.device.push.Abstract', statics:{callbacks:{}}, setPushConfig:function(config) {
  3691. var methodName = Ext.id(null, 'callback');
  3692. Ext.device.push.Cordova.callbacks[methodName] = config.callbacks.received;
  3693. return {'badge':config.callbacks.type === Ext.device.Push.BADGE ? 'true' : 'false', 'sound':config.callbacks.type === Ext.device.Push.SOUND ? 'true' : 'false', 'alert':config.callbacks.type === Ext.device.Push.ALERT ? 'true' : 'false', 'ecb':'Ext.device.push.Cordova.callbacks.' + methodName, 'senderID':config.senderID};
  3694. }, register:function() {
  3695. var config = arguments[0];
  3696. config.callbacks = this.callParent(arguments);
  3697. var pushConfig = this.setPushConfig(config), plugin = window.plugins.pushNotification;
  3698. plugin.register(config.callbacks.success, config.callbacks.failure, pushConfig);
  3699. }});
  3700. Ext.define('Ext.device.Push', {singleton:true, requires:['Ext.device.Communicator', 'Ext.device.push.Cordova'], constructor:function() {
  3701. var browserEnv = Ext.browser.is;
  3702. if (browserEnv.WebView) {
  3703. if (browserEnv.Cordova) {
  3704. return Ext.create('Ext.device.push.Cordova');
  3705. }
  3706. }
  3707. return Ext.create('Ext.device.push.Abstract');
  3708. }});
  3709. Ext.define('Ext.device.splashscreen.Abstract', {show:Ext.emptyFn, hide:Ext.emptyFn});
  3710. Ext.define('Ext.device.splashscreen.Cordova', {alternateClassName:'Ext.device.splashscreen.PhoneGap', extend:'Ext.device.splashscreen.Abstract', show:function() {
  3711. navigator.splashscreen.show();
  3712. }, hide:function() {
  3713. navigator.splashscreen.hide();
  3714. }});
  3715. Ext.define('Ext.device.splashscreen.Simulator', {extend:'Ext.device.splashscreen.Abstract'});
  3716. Ext.define('Ext.device.Splashscreen', {singleton:true, requires:['Ext.device.splashscreen.Cordova', 'Ext.device.splashscreen.Simulator'], constructor:function() {
  3717. var browserEnv = Ext.browser.is;
  3718. if (browserEnv.WebView) {
  3719. if (browserEnv.Cordova) {
  3720. return Ext.create('Ext.device.splashscreen.Cordova');
  3721. }
  3722. }
  3723. return Ext.create('Ext.device.splashscreen.Simulator');
  3724. }});
  3725. Ext.define('Ext.device.storage.Abstract', {config:{databaseName:'Sencha', databaseVersion:'1.0', databaseDisplayName:'Sencha Database', databaseSize:5 * 1024 * 1024}, openDatabase:function(config) {
  3726. var defaultConfig = Ext.device.storage.Abstract.prototype.config;
  3727. config = Ext.applyIf(config, {name:defaultConfig.databaseName, version:defaultConfig.databaseVersion, displayName:defaultConfig.databaseDisplayName, size:defaultConfig.databaseSize});
  3728. return config;
  3729. }, numKeys:Ext.emptyFn, getKey:Ext.emptyFn, getItem:Ext.emptyFn, setItem:Ext.emptyFn, removeItem:Ext.emptyFn, clear:Ext.emptyFn});
  3730. Ext.define('Ext.device.storage.HTML5.SQLStatement', {extend:'Ext.Base', sql:null, 'arguments':null, success:Ext.emptyFn, failure:Ext.emptyFn, constructor:function(config) {
  3731. this.sql = config.sql;
  3732. this.arguments = config.arguments;
  3733. this.success = config.success;
  3734. this.failure = config.failure;
  3735. }});
  3736. Ext.define('Ext.device.storage.HTML5.Database', {requires:['Ext.device.storage.HTML5.SQLStatement'], db:null, constructor:function(config) {
  3737. this.db = window.openDatabase(config.name, config.version, config.displayName, config.size);
  3738. }, getVersion:function() {
  3739. if (this.db) {
  3740. return this.db.version;
  3741. }
  3742. Ext.Logger.warn('Database has not been opened before calling function #getVersion');
  3743. return null;
  3744. }, transaction:function(sql, success, failure) {
  3745. if (!this.db) {
  3746. Ext.Logger.warn('Database has not been opened before calling function #transaction');
  3747. return;
  3748. }
  3749. if (!Ext.isArray(sql)) {
  3750. sql = [sql];
  3751. }
  3752. var txFn = function(tx) {
  3753. Ext.each(sql, function(sqlStatement) {
  3754. if (Ext.isString(sqlStatement)) {
  3755. tx.executeSql(sqlStatement);
  3756. } else {
  3757. if (Ext.isObject(sqlStatement)) {
  3758. tx.executeSql(sqlStatement.sql, sqlStatement.arguments, sqlStatement.success, sqlStatement.failure);
  3759. }
  3760. }
  3761. });
  3762. };
  3763. this.db.transaction(txFn, failure, success);
  3764. }});
  3765. Ext.define('Ext.device.storage.HTML5.HTML5', {extend:'Ext.device.storage.Abstract', requires:['Ext.device.storage.HTML5.Database'], dbCache:{}, openDatabase:function(config) {
  3766. config = this.callParent(arguments);
  3767. if (!this.dbCache[config.name] || config.noCache) {
  3768. this.dbCache[config.name] = Ext.create('Ext.device.storage.HTML5.Database', config);
  3769. }
  3770. return this.dbCache[config.name];
  3771. }, numKeys:function() {
  3772. return window.localStorage.length;
  3773. }, getKey:function(index) {
  3774. return window.localStorage.key(index);
  3775. }, getItem:function(key) {
  3776. return window.localStorage.getItem(key);
  3777. }, setItem:function(key, value) {
  3778. return window.localStorage.setItem(key, value);
  3779. }, removeItem:function(key) {
  3780. return window.localStorage.removeItem(key);
  3781. }, clear:function() {
  3782. return window.localStorage.clear();
  3783. }});
  3784. Ext.define('Ext.device.storage.Cordova', {alternateClassName:'Ext.device.storage.PhoneGap', extend:'Ext.device.storage.HTML5.HTML5'});
  3785. Ext.define('Ext.device.storage.Simulator', {extend:'Ext.device.storage.HTML5.HTML5'});
  3786. Ext.define('Ext.device.Storage', {singleton:true, requires:['Ext.device.storage.Cordova', 'Ext.device.storage.Simulator'], constructor:function() {
  3787. var browserEnv = Ext.browser.is;
  3788. if (browserEnv.WebView) {
  3789. if (browserEnv.Cordova) {
  3790. return Ext.create('Ext.device.storage.Cordova');
  3791. }
  3792. }
  3793. return Ext.create('Ext.device.storage.Simulator');
  3794. }});
  3795. Ext.define('Ext.device.twitter.Abstract', {compose:Ext.emptyFn, getPublicTimeline:Ext.emptyFn, getMentions:Ext.emptyFn, getTwitterUsername:Ext.emptyFn, getTwitterRequest:Ext.emptyFn});
  3796. Ext.define('Ext.device.twitter.Cordova', {compose:function(config) {
  3797. window.plugins.twitter.composeTweet(config.success, config.failure, config.tweet, {urlAttach:config.url, imageAttach:config.image});
  3798. }, getPublicTimeline:function(config) {
  3799. window.plugins.twitter.getPublicTimeline(config.success, config.failure);
  3800. }, getMentions:function(config) {
  3801. window.plugins.twitter.getMentions(config.success, config.failure);
  3802. }, getTwitterUsername:function(config) {
  3803. window.plugins.twitter.getTwitterUsername(config.success, config.failure);
  3804. }, getTwitterRequest:function(config) {
  3805. window.plugins.twitter.getTWRequest(config.url, config.params, config.success, config.failure, config.options);
  3806. }});
  3807. Ext.define('Ext.device.Twitter', {alternateClassName:'Ext.ux.device.Twitter', singleton:true, requires:['Ext.device.Communicator', 'Ext.device.twitter.*'], constructor:function() {
  3808. var browserEnv = Ext.browser.is;
  3809. if (browserEnv.WebView && browserEnv.Cordova) {
  3810. return Ext.create('Ext.device.twitter.Cordova');
  3811. } else {
  3812. return Ext.create('Ext.device.twitter.Abstract');
  3813. }
  3814. }});
  3815. Ext.define('Ext.device.browser.Window', {extend:'Ext.Evented', open:function(config) {
  3816. var me = this;
  3817. this._window = window.open(config.url, config.showToolbar ? '_blank' : '_self', config.options || null);
  3818. this._window.addEventListener('loadstart', function() {
  3819. me.fireEvent('loadstart', me);
  3820. });
  3821. this._window.addEventListener('loadstop', function() {
  3822. me.fireEvent('loadstop', me);
  3823. });
  3824. this._window.addEventListener('loaderror', function() {
  3825. me.fireEvent('loaderror', me);
  3826. });
  3827. this._window.addEventListener('exit', function() {
  3828. me.fireEvent('close', me);
  3829. });
  3830. }, close:function() {
  3831. if (!this._window) {
  3832. return;
  3833. }
  3834. this._window.close();
  3835. }});