ux-debug.js 183 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110
  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(null, {override:'Ext.ux.gauge.needle.Abstract', compatibility:Ext.isIE10p, setTransform:function(centerX, centerY, rotation) {
  2064. var needleGroup = this.getNeedleGroup();
  2065. this.callParent([centerX, centerY, rotation]);
  2066. needleGroup.set({transform:getComputedStyle(needleGroup.dom).getPropertyValue('transform')});
  2067. }, updateStyle:function(style) {
  2068. var pathElement;
  2069. this.callParent([style]);
  2070. if (Ext.isObject(style) && 'transform' in style) {
  2071. pathElement = this.getNeedlePath();
  2072. pathElement.set({transform:getComputedStyle(pathElement.dom).getPropertyValue('transform')});
  2073. }
  2074. }});
  2075. Ext.define('Ext.ux.ajax.Simlet', function() {
  2076. var urlRegex = /([^?#]*)(#.*)?$/, dateRegex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/, intRegex = /^[+-]?\d+$/, floatRegex = /^[+-]?\d+\.\d+$/;
  2077. function parseParamValue(value) {
  2078. var m;
  2079. if (Ext.isDefined(value)) {
  2080. value = decodeURIComponent(value);
  2081. if (intRegex.test(value)) {
  2082. value = parseInt(value, 10);
  2083. } else {
  2084. if (floatRegex.test(value)) {
  2085. value = parseFloat(value);
  2086. } else {
  2087. if (!!(m = dateRegex.exec(value))) {
  2088. value = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]));
  2089. }
  2090. }
  2091. }
  2092. }
  2093. return value;
  2094. }
  2095. return {alias:'simlet.basic', isSimlet:true, responseProps:['responseText', 'responseXML', 'status', 'statusText', 'responseHeaders'], status:200, statusText:'OK', constructor:function(config) {
  2096. Ext.apply(this, config);
  2097. }, doGet:function(ctx) {
  2098. return this.handleRequest(ctx);
  2099. }, doPost:function(ctx) {
  2100. return this.handleRequest(ctx);
  2101. }, doRedirect:function(ctx) {
  2102. return false;
  2103. }, doDelete:function(ctx) {
  2104. var me = this, xhr = ctx.xhr, records = xhr.options.records;
  2105. me.removeFromData(ctx, records);
  2106. }, exec:function(xhr) {
  2107. var me = this, ret = {}, method = 'do' + Ext.String.capitalize(xhr.method.toLowerCase()), fn = me[method];
  2108. if (fn) {
  2109. ret = fn.call(me, me.getCtx(xhr.method, xhr.url, xhr));
  2110. } else {
  2111. ret = {status:405, statusText:'Method Not Allowed'};
  2112. }
  2113. return ret;
  2114. }, getCtx:function(method, url, xhr) {
  2115. return {method:method, params:this.parseQueryString(url), url:url, xhr:xhr};
  2116. }, handleRequest:function(ctx) {
  2117. var me = this, ret = {}, val;
  2118. Ext.Array.forEach(me.responseProps, function(prop) {
  2119. if (prop in me) {
  2120. val = me[prop];
  2121. if (Ext.isFunction(val)) {
  2122. val = val.call(me, ctx);
  2123. }
  2124. ret[prop] = val;
  2125. }
  2126. });
  2127. return ret;
  2128. }, openRequest:function(method, url, options, async) {
  2129. var ctx = this.getCtx(method, url), redirect = this.doRedirect(ctx), xhr;
  2130. if (options.action === 'destroy') {
  2131. method = 'delete';
  2132. }
  2133. if (redirect) {
  2134. xhr = redirect;
  2135. } else {
  2136. xhr = new Ext.ux.ajax.SimXhr({mgr:this.manager, simlet:this, options:options});
  2137. xhr.open(method, url, async);
  2138. }
  2139. return xhr;
  2140. }, parseQueryString:function(str) {
  2141. var m = urlRegex.exec(str), ret = {}, key, value, pair, parts, i, n;
  2142. if (m && m[1]) {
  2143. parts = m[1].split('\x26');
  2144. for (i = 0, n = parts.length; i < n; ++i) {
  2145. if ((pair = parts[i].split('\x3d'))[0]) {
  2146. key = decodeURIComponent(pair.shift());
  2147. value = parseParamValue(pair.length > 1 ? pair.join('\x3d') : pair[0]);
  2148. if (!(key in ret)) {
  2149. ret[key] = value;
  2150. } else {
  2151. if (Ext.isArray(ret[key])) {
  2152. ret[key].push(value);
  2153. } else {
  2154. ret[key] = [ret[key], value];
  2155. }
  2156. }
  2157. }
  2158. }
  2159. }
  2160. return ret;
  2161. }, redirect:function(method, url, params) {
  2162. switch(arguments.length) {
  2163. case 2:
  2164. if (typeof url === 'string') {
  2165. break;
  2166. }
  2167. params = url;
  2168. case 1:
  2169. url = method;
  2170. method = 'GET';
  2171. break;
  2172. }
  2173. if (params) {
  2174. url = Ext.urlAppend(url, Ext.Object.toQueryString(params));
  2175. }
  2176. return this.manager.openRequest(method, url);
  2177. }, removeFromData:function(ctx, records) {
  2178. var me = this, data = me.getData(ctx), model = ctx.xhr.options.proxy && ctx.xhr.options.proxy.getModel() || {}, idProperty = model.idProperty || 'id', i;
  2179. Ext.each(records, function(record) {
  2180. var id = record.get(idProperty);
  2181. for (i = data.length; i-- > 0;) {
  2182. if (data[i][idProperty] === id) {
  2183. me.deleteRecord(i);
  2184. break;
  2185. }
  2186. }
  2187. });
  2188. }};
  2189. }());
  2190. Ext.define('Ext.ux.ajax.DataSimlet', function() {
  2191. function makeSortFn(def, cmp) {
  2192. var order = def.direction, sign = order && order.toUpperCase() === 'DESC' ? -1 : 1;
  2193. return function(leftRec, rightRec) {
  2194. var lhs = leftRec[def.property], rhs = rightRec[def.property], c = lhs < rhs ? -1 : rhs < lhs ? 1 : 0;
  2195. if (c || !cmp) {
  2196. return c * sign;
  2197. }
  2198. return cmp(leftRec, rightRec);
  2199. };
  2200. }
  2201. function makeSortFns(defs, cmp) {
  2202. var sortFn, i;
  2203. for (sortFn = cmp, i = defs && defs.length; i;) {
  2204. sortFn = makeSortFn(defs[--i], sortFn);
  2205. }
  2206. return sortFn;
  2207. }
  2208. return {extend:'Ext.ux.ajax.Simlet', buildNodes:function(node, path) {
  2209. var me = this, nodeData = {data:[]}, len = node.length, children, i, child, name;
  2210. me.nodes[path] = nodeData;
  2211. for (i = 0; i < len; ++i) {
  2212. nodeData.data.push(child = node[i]);
  2213. name = child.text || child.title;
  2214. child.id = path ? path + '/' + name : name;
  2215. children = child.children;
  2216. if (!(child.leaf = !children)) {
  2217. delete child.children;
  2218. me.buildNodes(children, child.id);
  2219. }
  2220. }
  2221. }, deleteRecord:function(pos) {
  2222. if (this.data && typeof this.data !== 'function') {
  2223. Ext.Array.removeAt(this.data, pos);
  2224. }
  2225. }, fixTree:function(ctx, tree) {
  2226. var me = this, node = ctx.params.node, nodes;
  2227. if (!(nodes = me.nodes)) {
  2228. me.nodes = nodes = {};
  2229. me.buildNodes(tree, '');
  2230. }
  2231. node = nodes[node];
  2232. if (node) {
  2233. if (me.node) {
  2234. me.node.sortedData = me.sortedData;
  2235. me.node.currentOrder = me.currentOrder;
  2236. }
  2237. me.node = node;
  2238. me.data = node.data;
  2239. me.sortedData = node.sortedData;
  2240. me.currentOrder = node.currentOrder;
  2241. } else {
  2242. me.data = null;
  2243. }
  2244. }, getData:function(ctx) {
  2245. var me = this, params = ctx.params, order = (params.filter || '') + (params.group || '') + '-' + (params.sort || '') + '-' + (params.dir || ''), tree = me.tree, dynamicData, data, fields, sortFn, filters;
  2246. if (tree) {
  2247. me.fixTree(ctx, tree);
  2248. }
  2249. data = me.data;
  2250. if (typeof data === 'function') {
  2251. dynamicData = true;
  2252. data = data.call(this, ctx);
  2253. }
  2254. if (!data || order === '--') {
  2255. return data || [];
  2256. }
  2257. if (!dynamicData && order === me.currentOrder) {
  2258. return me.sortedData;
  2259. }
  2260. ctx.filterSpec = params.filter && Ext.decode(params.filter);
  2261. ctx.groupSpec = params.group && Ext.decode(params.group);
  2262. fields = params.sort;
  2263. if (params.dir) {
  2264. fields = [{direction:params.dir, property:fields}];
  2265. } else {
  2266. if (params.sort) {
  2267. fields = Ext.decode(params.sort);
  2268. } else {
  2269. fields = null;
  2270. }
  2271. }
  2272. if (ctx.filterSpec) {
  2273. filters = new Ext.util.FilterCollection;
  2274. filters.add(this.processFilters(ctx.filterSpec));
  2275. data = Ext.Array.filter(data, filters.getFilterFn());
  2276. }
  2277. sortFn = makeSortFns(ctx.sortSpec = fields);
  2278. if (ctx.groupSpec) {
  2279. sortFn = makeSortFns([ctx.groupSpec], sortFn);
  2280. }
  2281. data = Ext.isArray(data) ? data.slice(0) : data;
  2282. if (sortFn) {
  2283. Ext.Array.sort(data, sortFn);
  2284. }
  2285. me.sortedData = data;
  2286. me.currentOrder = order;
  2287. return data;
  2288. }, processFilters:Ext.identityFn, getPage:function(ctx, data) {
  2289. var ret = data, length = data.length, start = ctx.params.start || 0, end = ctx.params.limit ? Math.min(length, start + ctx.params.limit) : length;
  2290. if (start || end < length) {
  2291. ret = ret.slice(start, end);
  2292. }
  2293. return ret;
  2294. }, getGroupSummary:function(groupField, rows, ctx) {
  2295. return rows[0];
  2296. }, getSummary:function(ctx, data, page) {
  2297. var me = this, groupField = ctx.groupSpec.property, accum, todo = {}, summary = [], fieldValue, lastFieldValue;
  2298. Ext.each(page, function(rec) {
  2299. fieldValue = rec[groupField];
  2300. todo[fieldValue] = true;
  2301. });
  2302. function flush() {
  2303. if (accum) {
  2304. summary.push(me.getGroupSummary(groupField, accum, ctx));
  2305. accum = null;
  2306. }
  2307. }
  2308. Ext.each(data, function(rec) {
  2309. fieldValue = rec[groupField];
  2310. if (lastFieldValue !== fieldValue) {
  2311. flush();
  2312. lastFieldValue = fieldValue;
  2313. }
  2314. if (!todo[fieldValue]) {
  2315. return !summary.length;
  2316. }
  2317. if (accum) {
  2318. accum.push(rec);
  2319. } else {
  2320. accum = [rec];
  2321. }
  2322. return true;
  2323. });
  2324. flush();
  2325. return summary;
  2326. }};
  2327. }());
  2328. Ext.define('Ext.ux.ajax.JsonSimlet', {extend:'Ext.ux.ajax.DataSimlet', alias:'simlet.json', doGet:function(ctx) {
  2329. var me = this, data = me.getData(ctx), page = me.getPage(ctx, data), reader = ctx.xhr.options.proxy && ctx.xhr.options.proxy.getReader(), root = reader && reader.getRootProperty(), ret = me.callParent(arguments), response = {};
  2330. if (root && Ext.isArray(page)) {
  2331. response[root] = page;
  2332. response[reader.getTotalProperty()] = data.length;
  2333. } else {
  2334. response = page;
  2335. }
  2336. if (ctx.groupSpec) {
  2337. response.summaryData = me.getSummary(ctx, data, page);
  2338. }
  2339. ret.responseText = Ext.encode(response);
  2340. return ret;
  2341. }, doPost:function(ctx) {
  2342. return this.doGet(ctx);
  2343. }});
  2344. Ext.define('Ext.ux.ajax.GroupingSimlet', {extend:'Ext.ux.ajax.JsonSimlet', alias:'simlet.grouping', lastPost:null, lastResponse:null, doGet:function(ctx) {
  2345. var me = this, data = me.getData(ctx), page = me.getPage(ctx, data), reader = ctx.xhr.options.proxy && ctx.xhr.options.proxy.getReader(), root = reader && reader.getRootProperty(), ret = me.callParent(arguments), response = {}, summary = {}, i, len, s;
  2346. if (root && Ext.isArray(page)) {
  2347. response[root] = page;
  2348. response[reader.getTotalProperty()] = data.length;
  2349. } else {
  2350. response = page;
  2351. }
  2352. if (ctx.groupSpec && ctx.summarySpec) {
  2353. response[reader.getGroupRootProperty()] = me.getGroupSummaries(ctx, data, page);
  2354. len = ctx.summarySpec.length;
  2355. for (i = 0; i < len; i++) {
  2356. s = ctx.summarySpec[i];
  2357. summary[s.name] = s.data.calculate(data, s.name, null, 0, data.length);
  2358. }
  2359. response[reader.getSummaryRootProperty()] = summary;
  2360. }
  2361. me.lastResponse = response;
  2362. ret.responseText = Ext.encode(me.lastResponse);
  2363. return ret;
  2364. }, doPost:function(ctx) {
  2365. return this.doGet(ctx);
  2366. }, getData:function(ctx) {
  2367. var me = this, params = ctx.params, order = (params.filter || '') + (params.group || '') + '-' + (params.sort || '') + '-' + (params.dir || ''), tree = me.tree, data, fields, sortFn, filters;
  2368. if (tree) {
  2369. me.fixTree(ctx, tree);
  2370. }
  2371. me.lastPost = params;
  2372. data = me.data;
  2373. if (typeof data === 'function') {
  2374. data = data.call(this, ctx);
  2375. }
  2376. if (!data || order === '--') {
  2377. return data || [];
  2378. }
  2379. ctx.filterSpec = params.filter && Ext.decode(params.filter);
  2380. ctx.groupSpec = params.group && Ext.decode(params.group);
  2381. ctx.summarySpec = params.summary && Ext.decode(params.summary);
  2382. fields = params.sort;
  2383. if (params.dir) {
  2384. fields = [{direction:params.dir, property:fields}];
  2385. } else {
  2386. fields = params.sort && Ext.decode(params.sort);
  2387. }
  2388. if (ctx.filterSpec) {
  2389. filters = new Ext.util.FilterCollection;
  2390. filters.add(this.processFilters(ctx.filterSpec));
  2391. data = Ext.Array.filter(data, filters.getFilterFn());
  2392. }
  2393. sortFn = this.makeSortFns(ctx.sortSpec = fields);
  2394. if (ctx.groupSpec) {
  2395. sortFn = this.makeSortFns(ctx.groupSpec, sortFn);
  2396. }
  2397. data = Ext.isArray(data) ? data.slice(0) : data;
  2398. if (sortFn) {
  2399. Ext.Array.sort(data, sortFn);
  2400. }
  2401. me.sortedData = data;
  2402. me.currentOrder = order;
  2403. return data;
  2404. }, getGroupSummaries:function(ctx, data, page) {
  2405. var groupers = ctx.groupSpec, summaries = ctx.summarySpec, out = [], i, j, k, len, length, len2, grouper, record, values, summary, keys;
  2406. len = groupers.length;
  2407. for (i = 0; i < len; i++) {
  2408. grouper = groupers[i];
  2409. values = Ext.Array.pluck(page, grouper.property);
  2410. grouper.values = Ext.Array.unique(values);
  2411. }
  2412. for (i = 0; i < len; i++) {
  2413. grouper = groupers[i];
  2414. values = grouper.values;
  2415. length = values.length;
  2416. record = {};
  2417. if (i > 0) {
  2418. len2 = out.length;
  2419. for (j = 0; j < len2; j++) {
  2420. for (k = 0; k < length; k++) {
  2421. record = Ext.clone(out[j]);
  2422. record[grouper.property] = values[k];
  2423. out.push(record);
  2424. }
  2425. }
  2426. } else {
  2427. for (j = 0; j < length; j++) {
  2428. record = {};
  2429. record[grouper.property] = values[j];
  2430. out.push(record);
  2431. }
  2432. }
  2433. }
  2434. len = out.length;
  2435. for (i = 0; i < len; i++) {
  2436. record = out[i];
  2437. keys = Ext.Object.getKeys(record);
  2438. values = Ext.Array.filter(data, function(item) {
  2439. var match = true, i, len, key;
  2440. len = keys.length;
  2441. for (i = 0; i < len; i++) {
  2442. key = keys[i];
  2443. match = match && item[key] === record[key];
  2444. }
  2445. return match;
  2446. });
  2447. length = summaries.length;
  2448. for (j = 0; j < length; j++) {
  2449. summary = summaries[j];
  2450. if (!summary.data) {
  2451. summary.data = Ext.Factory.dataSummary(summary.summary);
  2452. }
  2453. record[summary.name] = summary.data.calculate(values, summary.name, null, 0, values.length);
  2454. }
  2455. }
  2456. return out;
  2457. }, makeSortFn:function(def, cmp) {
  2458. var order = def.direction, sign = order && order.toUpperCase() === 'DESC' ? -1 : 1;
  2459. return function(leftRec, rightRec) {
  2460. var lhs = leftRec[def.property], rhs = rightRec[def.property], c = lhs < rhs ? -1 : rhs < lhs ? 1 : 0;
  2461. if (c || !cmp) {
  2462. return c * sign;
  2463. }
  2464. return cmp(leftRec, rightRec);
  2465. };
  2466. }, makeSortFns:function(defs, cmp) {
  2467. var sortFn, i;
  2468. defs = Ext.Array.from(defs);
  2469. for (sortFn = cmp, i = defs && defs.length; i;) {
  2470. sortFn = this.makeSortFn(defs[--i], sortFn);
  2471. }
  2472. return sortFn;
  2473. }});
  2474. Ext.define('Ext.ux.ajax.PivotSimlet', {extend:'Ext.ux.ajax.JsonSimlet', alias:'simlet.pivot', lastPost:null, lastResponse:null, keysSeparator:'', grandTotalKey:'', doPost:function(ctx) {
  2475. var me = this, ret = me.callParent(arguments);
  2476. me.lastResponse = me.processData(me.getData(ctx), Ext.decode(ctx.xhr.body));
  2477. ret.responseText = Ext.encode(me.lastResponse);
  2478. return ret;
  2479. }, processData:function(data, params) {
  2480. var me = this, len = data.length, response = {success:true, leftAxis:[], topAxis:[], results:[]}, leftAxis = new Ext.util.MixedCollection, topAxis = new Ext.util.MixedCollection, results = new Ext.util.MixedCollection, i, j, k, leftKeys, topKeys, item, agg;
  2481. me.lastPost = params;
  2482. me.keysSeparator = params.keysSeparator;
  2483. me.grandTotalKey = params.grandTotalKey;
  2484. for (i = 0; i < len; i++) {
  2485. leftKeys = me.extractValues(data[i], params.leftAxis, leftAxis);
  2486. topKeys = me.extractValues(data[i], params.topAxis, topAxis);
  2487. me.addResult(data[i], me.grandTotalKey, me.grandTotalKey, results);
  2488. for (j = 0; j < leftKeys.length; j++) {
  2489. me.addResult(data[i], leftKeys[j], me.grandTotalKey, results);
  2490. for (k = 0; k < topKeys.length; k++) {
  2491. me.addResult(data[i], leftKeys[j], topKeys[k], results);
  2492. }
  2493. }
  2494. for (j = 0; j < topKeys.length; j++) {
  2495. me.addResult(data[i], me.grandTotalKey, topKeys[j], results);
  2496. }
  2497. }
  2498. response.leftAxis = leftAxis.getRange();
  2499. response.topAxis = topAxis.getRange();
  2500. len = results.getCount();
  2501. for (i = 0; i < len; i++) {
  2502. item = results.getAt(i);
  2503. item.values = {};
  2504. for (j = 0; j < params.aggregate.length; j++) {
  2505. agg = params.aggregate[j];
  2506. item.values[agg.id] = me[agg.aggregator](item.records, agg.dataIndex, item.leftKey, item.topKey);
  2507. }
  2508. delete item.records;
  2509. response.results.push(item);
  2510. }
  2511. leftAxis.clear();
  2512. topAxis.clear();
  2513. results.clear();
  2514. return response;
  2515. }, getKey:function(value) {
  2516. var me = this;
  2517. me.keysMap = me.keysMap || {};
  2518. if (!Ext.isDefined(me.keysMap[value])) {
  2519. me.keysMap[value] = Ext.id();
  2520. }
  2521. return me.keysMap[value];
  2522. }, extractValues:function(record, dimensions, col) {
  2523. var len = dimensions.length, keys = [], j, key, item, dim;
  2524. key = '';
  2525. for (j = 0; j < len; j++) {
  2526. dim = dimensions[j];
  2527. key += (j > 0 ? this.keysSeparator : '') + this.getKey(record[dim.dataIndex]);
  2528. item = col.getByKey(key);
  2529. if (!item) {
  2530. item = col.add(key, {key:key, value:record[dim.dataIndex], dimensionId:dim.id});
  2531. }
  2532. keys.push(key);
  2533. }
  2534. return keys;
  2535. }, addResult:function(record, leftKey, topKey, results) {
  2536. var item = results.getByKey(leftKey + '/' + topKey);
  2537. if (!item) {
  2538. item = results.add(leftKey + '/' + topKey, {leftKey:leftKey, topKey:topKey, records:[]});
  2539. }
  2540. item.records.push(record);
  2541. }, sum:function(records, measure, rowGroupKey, colGroupKey) {
  2542. var length = records.length, total = 0, i;
  2543. for (i = 0; i < length; i++) {
  2544. total += Ext.Number.from(records[i][measure], 0);
  2545. }
  2546. return total;
  2547. }, avg:function(records, measure, rowGroupKey, colGroupKey) {
  2548. var length = records.length, total = 0, i;
  2549. for (i = 0; i < length; i++) {
  2550. total += Ext.Number.from(records[i][measure], 0);
  2551. }
  2552. return length > 0 ? total / length : 0;
  2553. }, min:function(records, measure, rowGroupKey, colGroupKey) {
  2554. var data = [], length = records.length, i, v;
  2555. for (i = 0; i < length; i++) {
  2556. data.push(records[i][measure]);
  2557. }
  2558. v = Ext.Array.min(data);
  2559. return v;
  2560. }, max:function(records, measure, rowGroupKey, colGroupKey) {
  2561. var data = [], length = records.length, i, v;
  2562. for (i = 0; i < length; i++) {
  2563. data.push(records[i][measure]);
  2564. }
  2565. v = Ext.Array.max(data);
  2566. return v;
  2567. }, count:function(records, measure, rowGroupKey, colGroupKey) {
  2568. return records.length;
  2569. }, variance:function(records, measure, rowGroupKey, colGroupKey) {
  2570. var me = Ext.pivot.Aggregators, length = records.length, avg = me.avg.apply(me, arguments), total = 0, i;
  2571. if (avg > 0) {
  2572. for (i = 0; i < length; i++) {
  2573. total += Math.pow(Ext.Number.from(records[i][measure], 0) - avg, 2);
  2574. }
  2575. }
  2576. return total > 0 && length > 1 ? total / (length - 1) : 0;
  2577. }, varianceP:function(records, measure, rowGroupKey, colGroupKey) {
  2578. var me = Ext.pivot.Aggregators, length = records.length, avg = me.avg.apply(me, arguments), total = 0, i;
  2579. if (avg > 0) {
  2580. for (i = 0; i < length; i++) {
  2581. total += Math.pow(Ext.Number.from(records[i][measure], 0) - avg, 2);
  2582. }
  2583. }
  2584. return total > 0 && length > 0 ? total / length : 0;
  2585. }, stdDev:function(records, measure, rowGroupKey, colGroupKey) {
  2586. var me = Ext.pivot.Aggregators, v = me.variance.apply(me, arguments);
  2587. return v > 0 ? Math.sqrt(v) : 0;
  2588. }, stdDevP:function(records, measure, rowGroupKey, colGroupKey) {
  2589. var me = Ext.pivot.Aggregators, v = me.varianceP.apply(me, arguments);
  2590. return v > 0 ? Math.sqrt(v) : 0;
  2591. }});
  2592. Ext.define('Ext.ux.ajax.SimXhr', {readyState:0, mgr:null, simlet:null, constructor:function(config) {
  2593. var me = this;
  2594. Ext.apply(me, config);
  2595. me.requestHeaders = {};
  2596. }, abort:function() {
  2597. var me = this;
  2598. if (me.timer) {
  2599. Ext.undefer(me.timer);
  2600. me.timer = null;
  2601. }
  2602. me.aborted = true;
  2603. }, getAllResponseHeaders:function() {
  2604. var headers = [];
  2605. if (Ext.isObject(this.responseHeaders)) {
  2606. Ext.Object.each(this.responseHeaders, function(name, value) {
  2607. headers.push(name + ': ' + value);
  2608. });
  2609. }
  2610. return headers.join('\r\n');
  2611. }, getResponseHeader:function(header) {
  2612. var headers = this.responseHeaders;
  2613. return headers && headers[header] || null;
  2614. }, open:function(method, url, async, user, password) {
  2615. var me = this;
  2616. me.method = method;
  2617. me.url = url;
  2618. me.async = async !== false;
  2619. me.user = user;
  2620. me.password = password;
  2621. me.setReadyState(1);
  2622. }, overrideMimeType:function(mimeType) {
  2623. this.mimeType = mimeType;
  2624. }, schedule:function() {
  2625. var me = this, delay = me.simlet.delay || me.mgr.delay;
  2626. if (delay) {
  2627. me.timer = Ext.defer(function() {
  2628. me.onTick();
  2629. }, delay);
  2630. } else {
  2631. me.onTick();
  2632. }
  2633. }, send:function(body) {
  2634. var me = this;
  2635. me.body = body;
  2636. if (me.async) {
  2637. me.schedule();
  2638. } else {
  2639. me.onComplete();
  2640. }
  2641. }, setReadyState:function(state) {
  2642. var me = this;
  2643. if (me.readyState !== state) {
  2644. me.readyState = state;
  2645. me.onreadystatechange();
  2646. }
  2647. }, setRequestHeader:function(header, value) {
  2648. this.requestHeaders[header] = value;
  2649. }, onreadystatechange:Ext.emptyFn, onComplete:function() {
  2650. var me = this, callback, text;
  2651. me.readyState = 4;
  2652. Ext.apply(me, me.simlet.exec(me));
  2653. callback = me.jsonpCallback;
  2654. if (callback) {
  2655. text = callback + '(' + me.responseText + ')';
  2656. eval(text);
  2657. }
  2658. }, onTick:function() {
  2659. var me = this;
  2660. me.timer = null;
  2661. me.onComplete();
  2662. if (me.onreadystatechange) {
  2663. me.onreadystatechange();
  2664. }
  2665. }});
  2666. Ext.define('Ext.ux.ajax.SimManager', {singleton:true, requires:['Ext.data.Connection', 'Ext.ux.ajax.SimXhr', 'Ext.ux.ajax.Simlet', 'Ext.ux.ajax.JsonSimlet'], defaultType:'basic', delay:150, ready:false, constructor:function() {
  2667. this.simlets = [];
  2668. }, getSimlet:function(url) {
  2669. var me = this, index = url.indexOf('?'), simlets = me.simlets, len = simlets.length, i, simlet, simUrl, match;
  2670. if (index < 0) {
  2671. index = url.indexOf('#');
  2672. }
  2673. if (index > 0) {
  2674. url = url.substring(0, index);
  2675. }
  2676. for (i = 0; i < len; ++i) {
  2677. simlet = simlets[i];
  2678. simUrl = simlet.url;
  2679. if (simUrl instanceof RegExp) {
  2680. match = simUrl.test(url);
  2681. } else {
  2682. match = simUrl === url;
  2683. }
  2684. if (match) {
  2685. return simlet;
  2686. }
  2687. }
  2688. return me.defaultSimlet;
  2689. }, getXhr:function(method, url, options, async) {
  2690. var simlet = this.getSimlet(url);
  2691. if (simlet) {
  2692. return simlet.openRequest(method, url, options, async);
  2693. }
  2694. return null;
  2695. }, init:function(config) {
  2696. var me = this;
  2697. Ext.apply(me, config);
  2698. if (!me.ready) {
  2699. me.ready = true;
  2700. if (!('defaultSimlet' in me)) {
  2701. me.defaultSimlet = new Ext.ux.ajax.Simlet({status:404, statusText:'Not Found'});
  2702. }
  2703. me._openRequest = Ext.data.Connection.prototype.openRequest;
  2704. Ext.data.request.Ajax.override({openRequest:function(options, requestOptions, async) {
  2705. var xhr = !options.nosim && me.getXhr(requestOptions.method, requestOptions.url, options, async);
  2706. if (!xhr) {
  2707. xhr = this.callParent(arguments);
  2708. }
  2709. return xhr;
  2710. }});
  2711. if (Ext.data.JsonP) {
  2712. Ext.data.JsonP.self.override({createScript:function(url, params, options) {
  2713. var fullUrl = Ext.urlAppend(url, Ext.Object.toQueryString(params)), script = !options.nosim && me.getXhr('GET', fullUrl, options, true);
  2714. if (!script) {
  2715. script = this.callParent(arguments);
  2716. }
  2717. return script;
  2718. }, loadScript:function(request) {
  2719. var script = request.script;
  2720. if (script.simlet) {
  2721. script.jsonpCallback = request.params[request.callbackKey];
  2722. script.send(null);
  2723. request.script = document.createElement('script');
  2724. } else {
  2725. this.callParent(arguments);
  2726. }
  2727. }});
  2728. }
  2729. }
  2730. return me;
  2731. }, openRequest:function(method, url, async) {
  2732. var opt = {method:method, url:url};
  2733. return this._openRequest.call(Ext.data.Connection.prototype, {}, opt, async);
  2734. }, register:function(simlet) {
  2735. var me = this;
  2736. me.init();
  2737. function reg(one) {
  2738. var simlet = one;
  2739. if (!simlet.isSimlet) {
  2740. simlet = Ext.create('simlet.' + (simlet.type || simlet.stype || me.defaultType), one);
  2741. }
  2742. me.simlets.push(simlet);
  2743. simlet.manager = me;
  2744. }
  2745. if (Ext.isArray(simlet)) {
  2746. Ext.each(simlet, reg);
  2747. } else {
  2748. if (simlet.isSimlet || simlet.url) {
  2749. reg(simlet);
  2750. } else {
  2751. Ext.Object.each(simlet, function(url, s) {
  2752. s.url = url;
  2753. reg(s);
  2754. });
  2755. }
  2756. }
  2757. return me;
  2758. }});
  2759. Ext.define('Ext.ux.ajax.XmlSimlet', {extend:'Ext.ux.ajax.DataSimlet', alias:'simlet.xml', xmlTpl:['\x3c{root}\x3e\n', '\x3ctpl for\x3d"data"\x3e', ' \x3c{parent.record}\x3e\n', '\x3ctpl for\x3d"parent.fields"\x3e', ' \x3c{name}\x3e{[parent[values.name]]}\x3c/{name}\x3e\n', '\x3c/tpl\x3e', ' \x3c/{parent.record}\x3e\n', '\x3c/tpl\x3e', '\x3c/{root}\x3e'], doGet:function(ctx) {
  2760. var me = this, data = me.getData(ctx), page = me.getPage(ctx, data), proxy = ctx.xhr.options.operation.getProxy(), reader = proxy && proxy.getReader(), model = reader && reader.getModel(), ret = me.callParent(arguments), response = {data:page, reader:reader, fields:model && model.fields, root:reader && reader.getRootProperty(), record:reader && reader.record}, tpl, xml, doc;
  2761. if (ctx.groupSpec) {
  2762. response.summaryData = me.getSummary(ctx, data, page);
  2763. }
  2764. if (me.xmlTpl) {
  2765. tpl = Ext.XTemplate.getTpl(me, 'xmlTpl');
  2766. xml = tpl.apply(response);
  2767. } else {
  2768. xml = data;
  2769. }
  2770. if (typeof DOMParser !== 'undefined') {
  2771. doc = (new DOMParser).parseFromString(xml, 'text/xml');
  2772. } else {
  2773. doc = new ActiveXObject('Microsoft.XMLDOM');
  2774. doc.async = false;
  2775. doc.loadXML(xml);
  2776. }
  2777. ret.responseText = xml;
  2778. ret.responseXML = doc;
  2779. return ret;
  2780. }, fixTree:function() {
  2781. var buffer = [];
  2782. this.callParent(arguments);
  2783. this.buildTreeXml(this.data, buffer);
  2784. this.data = buffer.join('');
  2785. }, buildTreeXml:function(nodes, buffer) {
  2786. var rootProperty = this.rootProperty, recordProperty = this.recordProperty;
  2787. buffer.push('\x3c', rootProperty, '\x3e');
  2788. Ext.Array.forEach(nodes, function(node) {
  2789. var key;
  2790. buffer.push('\x3c', recordProperty, '\x3e');
  2791. for (key in node) {
  2792. if (key === 'children') {
  2793. this.buildTreeXml(node.children, buffer);
  2794. } else {
  2795. buffer.push('\x3c', key, '\x3e', node[key], '\x3c/', key, '\x3e');
  2796. }
  2797. }
  2798. buffer.push('\x3c/', recordProperty, '\x3e');
  2799. });
  2800. buffer.push('\x3c/', rootProperty, '\x3e');
  2801. }});
  2802. Ext.define('Ext.ux.event.Driver', {extend:'Ext.util.Observable', active:null, specialKeysByName:{PGUP:33, PGDN:34, END:35, HOME:36, LEFT:37, UP:38, RIGHT:39, DOWN:40}, specialKeysByCode:{}, getTextSelection:function(el) {
  2803. var doc = el.ownerDocument, range, range2, start, end;
  2804. if (typeof el.selectionStart === 'number') {
  2805. start = el.selectionStart;
  2806. end = el.selectionEnd;
  2807. } else {
  2808. if (doc.selection) {
  2809. range = doc.selection.createRange();
  2810. range2 = el.createTextRange();
  2811. range2.setEndPoint('EndToStart', range);
  2812. start = range2.text.length;
  2813. end = start + range.text.length;
  2814. }
  2815. }
  2816. return [start, end];
  2817. }, getTime:function() {
  2818. return (new Date).getTime();
  2819. }, getTimestamp:function() {
  2820. var d = this.getTime();
  2821. return d - this.startTime;
  2822. }, onStart:function() {
  2823. }, onStop:function() {
  2824. }, start:function() {
  2825. var me = this;
  2826. if (!me.active) {
  2827. me.active = new Date;
  2828. me.startTime = me.getTime();
  2829. me.onStart();
  2830. me.fireEvent('start', me);
  2831. }
  2832. }, stop:function() {
  2833. var me = this;
  2834. if (me.active) {
  2835. me.active = null;
  2836. me.onStop();
  2837. me.fireEvent('stop', me);
  2838. }
  2839. }}, function() {
  2840. var proto = this.prototype;
  2841. Ext.Object.each(proto.specialKeysByName, function(name, value) {
  2842. proto.specialKeysByCode[value] = name;
  2843. });
  2844. });
  2845. Ext.define('Ext.ux.event.Maker', {eventQueue:[], startAfter:500, timerIncrement:500, currentTiming:0, constructor:function(config) {
  2846. var me = this;
  2847. me.currentTiming = me.startAfter;
  2848. if (!Ext.isArray(config)) {
  2849. config = [config];
  2850. }
  2851. Ext.Array.each(config, function(item) {
  2852. item.el = item.el || 'el';
  2853. Ext.Array.each(Ext.ComponentQuery.query(item.cmpQuery), function(cmp) {
  2854. var event = {}, x, y, el;
  2855. if (!item.domQuery) {
  2856. el = cmp[item.el];
  2857. } else {
  2858. el = cmp.el.down(item.domQuery);
  2859. }
  2860. event.target = '#' + el.dom.id;
  2861. event.type = item.type;
  2862. event.button = config.button || 0;
  2863. x = el.getX() + el.getWidth() / 2;
  2864. y = el.getY() + el.getHeight() / 2;
  2865. event.xy = [x, y];
  2866. event.ts = me.currentTiming;
  2867. me.currentTiming += me.timerIncrement;
  2868. me.eventQueue.push(event);
  2869. });
  2870. if (item.screenshot) {
  2871. me.eventQueue[me.eventQueue.length - 1].screenshot = true;
  2872. }
  2873. });
  2874. return me.eventQueue;
  2875. }});
  2876. Ext.define('Ext.ux.event.Player', function(Player) {
  2877. var defaults = {}, mouseEvents = {}, keyEvents = {}, doc, uiEvents = {}, bubbleEvents = {resize:1, reset:1, submit:1, change:1, select:1, error:1, abort:1};
  2878. Ext.each(['click', 'dblclick', 'mouseover', 'mouseout', 'mousedown', 'mouseup', 'mousemove'], function(type) {
  2879. bubbleEvents[type] = defaults[type] = mouseEvents[type] = {bubbles:true, cancelable:type !== 'mousemove', detail:1, screenX:0, screenY:0, clientX:0, clientY:0, ctrlKey:false, altKey:false, shiftKey:false, metaKey:false, button:0};
  2880. });
  2881. Ext.each(['keydown', 'keyup', 'keypress'], function(type) {
  2882. bubbleEvents[type] = defaults[type] = keyEvents[type] = {bubbles:true, cancelable:true, ctrlKey:false, altKey:false, shiftKey:false, metaKey:false, keyCode:0, charCode:0};
  2883. });
  2884. Ext.each(['blur', 'change', 'focus', 'resize', 'scroll', 'select'], function(type) {
  2885. defaults[type] = uiEvents[type] = {bubbles:type in bubbleEvents, cancelable:false, detail:1};
  2886. });
  2887. var inputSpecialKeys = {8:function(target, start, end) {
  2888. if (start < end) {
  2889. target.value = target.value.substring(0, start) + target.value.substring(end);
  2890. } else {
  2891. if (start > 0) {
  2892. target.value = target.value.substring(0, --start) + target.value.substring(end);
  2893. }
  2894. }
  2895. this.setTextSelection(target, start, start);
  2896. }, 46:function(target, start, end) {
  2897. if (start < end) {
  2898. target.value = target.value.substring(0, start) + target.value.substring(end);
  2899. } else {
  2900. if (start < target.value.length - 1) {
  2901. target.value = target.value.substring(0, start) + target.value.substring(start + 1);
  2902. }
  2903. }
  2904. this.setTextSelection(target, start, start);
  2905. }};
  2906. return {extend:'Ext.ux.event.Driver', keyFrameEvents:{click:true}, pauseForAnimations:true, speed:1, stallTime:0, _inputSpecialKeys:{INPUT:inputSpecialKeys, TEXTAREA:Ext.apply({}, inputSpecialKeys)}, tagPathRegEx:/(\w+)(?:\[(\d+)\])?/, xpathRe:/^[#~](?:[a-z][-a-z0-9_]*)(?:\/[a-z]+)*$/i, constructor:function(config) {
  2907. var me = this;
  2908. me.callParent(arguments);
  2909. me.timerFn = function() {
  2910. me.onTick();
  2911. };
  2912. me.attachTo = me.attachTo || window;
  2913. me.counter = 0;
  2914. doc = me.attachTo.document;
  2915. }, getElementFromXPath:function(xpath) {
  2916. var me = this, parts = xpath.split('/'), regex = me.tagPathRegEx, i, n, m, count, tag, child, el = me.attachTo.document;
  2917. el = parts[0] === '~' ? el.body : el.getElementById(parts[0].substring(1));
  2918. for (i = 1, n = parts.length; el && i < n; ++i) {
  2919. m = regex.exec(parts[i]);
  2920. count = m[2] ? parseInt(m[2], 10) : 1;
  2921. tag = m[1].toUpperCase();
  2922. for (child = el.firstChild; child; child = child.nextSibling) {
  2923. if (child.tagName === tag) {
  2924. if (count === 1) {
  2925. break;
  2926. }
  2927. --count;
  2928. }
  2929. }
  2930. el = child;
  2931. }
  2932. return el;
  2933. }, locateElement:function(locator) {
  2934. var cmp, cq, dq, el, parts;
  2935. if (this.xpathRe.test(locator)) {
  2936. el = this.getElementFromXPath(locator);
  2937. } else {
  2938. parts = locator.split('\x3d\x3e');
  2939. cq = Ext.String.trim(parts[0]);
  2940. dq = Ext.String.trim(parts[1]);
  2941. if (cq) {
  2942. cmp = Ext.first(cq);
  2943. el = cmp && cmp.el;
  2944. } else {
  2945. el = Ext.getBody();
  2946. }
  2947. if (dq && el) {
  2948. el = Ext.query(dq, true, el);
  2949. el = el && el[0];
  2950. }
  2951. }
  2952. return el;
  2953. }, offsetToRangeCharacterMove:function(el, offset) {
  2954. return offset - (el.value.slice(0, offset).split('\r\n').length - 1);
  2955. }, setTextSelection:function(el, startOffset, endOffset) {
  2956. var range, startCharMove;
  2957. if (startOffset < 0) {
  2958. startOffset += el.value.length;
  2959. }
  2960. if (endOffset == null) {
  2961. endOffset = startOffset;
  2962. }
  2963. if (endOffset < 0) {
  2964. endOffset += el.value.length;
  2965. }
  2966. if (typeof el.selectionStart === 'number') {
  2967. el.selectionStart = startOffset;
  2968. el.selectionEnd = endOffset;
  2969. } else {
  2970. range = el.createTextRange();
  2971. startCharMove = this.offsetToRangeCharacterMove(el, startOffset);
  2972. range.collapse(true);
  2973. if (startOffset === endOffset) {
  2974. range.move('character', startCharMove);
  2975. } else {
  2976. range.moveEnd('character', this.offsetToRangeCharacterMove(el, endOffset));
  2977. range.moveStart('character', startCharMove);
  2978. }
  2979. range.select();
  2980. }
  2981. }, getTimeIndex:function() {
  2982. var t = this.getTimestamp() - this.stallTime;
  2983. return t * this.speed;
  2984. }, makeToken:function(eventDescriptor, signal) {
  2985. var me = this, t0;
  2986. eventDescriptor[signal] = true;
  2987. eventDescriptor.defer = function() {
  2988. eventDescriptor[signal] = false;
  2989. t0 = me.getTime();
  2990. };
  2991. eventDescriptor.finish = function() {
  2992. eventDescriptor[signal] = true;
  2993. me.stallTime += me.getTime() - t0;
  2994. me.schedule();
  2995. };
  2996. }, nextEvent:function(eventDescriptor) {
  2997. var me = this, index = ++me.queueIndex;
  2998. if (me.keyFrameEvents[eventDescriptor.type]) {
  2999. Ext.Array.insert(me.eventQueue, index, [{keyframe:true, ts:eventDescriptor.ts}]);
  3000. }
  3001. }, peekEvent:function() {
  3002. var ev = this.eventQueue[this.queueIndex] || null;
  3003. if (ev && ev.seq === undefined) {
  3004. ev.seq = this.counter++;
  3005. }
  3006. return ev;
  3007. }, replaceEvent:function(index, events) {
  3008. for (var t, i = 0, n = events.length; i < n; ++i) {
  3009. if (i) {
  3010. t = events[i - 1];
  3011. delete t.afterplay;
  3012. delete t.screenshot;
  3013. delete events[i].beforeplay;
  3014. }
  3015. }
  3016. Ext.Array.replace(this.eventQueue, index == null ? this.queueIndex : index, 1, events);
  3017. }, processEvents:function() {
  3018. var me = this, animations = me.pauseForAnimations && me.attachTo.Ext.fx.Manager.items, eventDescriptor;
  3019. while ((eventDescriptor = me.peekEvent()) !== null) {
  3020. if (animations && animations.getCount()) {
  3021. return true;
  3022. }
  3023. if (eventDescriptor.keyframe) {
  3024. if (!me.processKeyFrame(eventDescriptor)) {
  3025. return false;
  3026. }
  3027. me.nextEvent(eventDescriptor);
  3028. } else {
  3029. if (eventDescriptor.ts <= me.getTimeIndex() && me.fireEvent('beforeplay', me, eventDescriptor) !== false && me.playEvent(eventDescriptor)) {
  3030. me.nextEvent(eventDescriptor);
  3031. } else {
  3032. return true;
  3033. }
  3034. }
  3035. }
  3036. me.stop();
  3037. return false;
  3038. }, processKeyFrame:function(eventDescriptor) {
  3039. var me = this;
  3040. if (!eventDescriptor.defer) {
  3041. me.makeToken(eventDescriptor, 'done');
  3042. me.fireEvent('keyframe', me, eventDescriptor);
  3043. }
  3044. return eventDescriptor.done;
  3045. }, injectEvent:function(target, event) {
  3046. var me = this, type = event.type, options = Ext.apply({}, event, defaults[type]), handler;
  3047. if (type === 'type') {
  3048. handler = me._inputSpecialKeys[target.tagName];
  3049. if (handler) {
  3050. return me.injectTypeInputEvent(target, event, handler);
  3051. }
  3052. return me.injectTypeEvent(target, event);
  3053. }
  3054. if (type === 'focus' && target.focus) {
  3055. target.focus();
  3056. return true;
  3057. }
  3058. if (type === 'blur' && target.blur) {
  3059. target.blur();
  3060. return true;
  3061. }
  3062. if (type === 'scroll') {
  3063. target.scrollLeft = event.pos[0];
  3064. target.scrollTop = event.pos[1];
  3065. return true;
  3066. }
  3067. if (type === 'mduclick') {
  3068. return me.injectEvent(target, Ext.applyIf({type:'mousedown'}, event)) && me.injectEvent(target, Ext.applyIf({type:'mouseup'}, event)) && me.injectEvent(target, Ext.applyIf({type:'click'}, event));
  3069. }
  3070. if (mouseEvents[type]) {
  3071. return Player.injectMouseEvent(target, options, me.attachTo);
  3072. }
  3073. if (keyEvents[type]) {
  3074. return Player.injectKeyEvent(target, options, me.attachTo);
  3075. }
  3076. if (uiEvents[type]) {
  3077. return Player.injectUIEvent(target, type, options.bubbles, options.cancelable, options.view || me.attachTo, options.detail);
  3078. }
  3079. return false;
  3080. }, injectTypeEvent:function(target, event) {
  3081. var me = this, text = event.text, xlat = [], ch, chUp, i, n, upper;
  3082. if (text) {
  3083. delete event.text;
  3084. upper = text.toUpperCase();
  3085. for (i = 0, n = text.length; i < n; ++i) {
  3086. ch = text.charCodeAt(i);
  3087. chUp = upper.charCodeAt(i);
  3088. xlat.push(Ext.applyIf({type:'keydown', charCode:chUp, keyCode:chUp}, event), Ext.applyIf({type:'keypress', charCode:ch, keyCode:ch}, event), Ext.applyIf({type:'keyup', charCode:chUp, keyCode:chUp}, event));
  3089. }
  3090. } else {
  3091. xlat.push(Ext.applyIf({type:'keydown', charCode:event.keyCode}, event), Ext.applyIf({type:'keyup', charCode:event.keyCode}, event));
  3092. }
  3093. for (i = 0, n = xlat.length; i < n; ++i) {
  3094. me.injectEvent(target, xlat[i]);
  3095. }
  3096. return true;
  3097. }, injectTypeInputEvent:function(target, event, handler) {
  3098. var me = this, text = event.text, sel, n;
  3099. if (handler) {
  3100. sel = me.getTextSelection(target);
  3101. if (text) {
  3102. n = sel[0];
  3103. target.value = target.value.substring(0, n) + text + target.value.substring(sel[1]);
  3104. n += text.length;
  3105. me.setTextSelection(target, n, n);
  3106. } else {
  3107. if (!(handler = handler[event.keyCode])) {
  3108. if ('caret' in event) {
  3109. me.setTextSelection(target, event.caret, event.caret);
  3110. } else {
  3111. if (event.selection) {
  3112. me.setTextSelection(target, event.selection[0], event.selection[1]);
  3113. }
  3114. }
  3115. return me.injectTypeEvent(target, event);
  3116. }
  3117. handler.call(this, target, sel[0], sel[1]);
  3118. return true;
  3119. }
  3120. }
  3121. return true;
  3122. }, playEvent:function(eventDescriptor) {
  3123. var me = this, target = me.locateElement(eventDescriptor.target), now = me.getTimeIndex(), timeout = eventDescriptor.timeout, event;
  3124. if (eventDescriptor.startedAt === undefined) {
  3125. eventDescriptor.startedAt = now;
  3126. }
  3127. if (!target) {
  3128. if (timeout !== null) {
  3129. timeout = timeout || 30000;
  3130. if (now - eventDescriptor.startedAt > timeout) {
  3131. me.playEventHook(eventDescriptor, 'timeout', 'onEventTimeout');
  3132. }
  3133. }
  3134. return false;
  3135. }
  3136. if (!me.playEventHook(eventDescriptor, 'beforeplay')) {
  3137. return false;
  3138. }
  3139. if (!eventDescriptor.injected) {
  3140. eventDescriptor.injected = true;
  3141. event = me.translateEvent(eventDescriptor, target);
  3142. me.injectEvent(target, event);
  3143. }
  3144. return me.playEventHook(eventDescriptor, 'afterplay');
  3145. }, playEventHook:function(eventDescriptor, hookName, hookHandler) {
  3146. var me = this, doneName = hookName + '.done', firedName = hookName + '.fired', hook = hookHandler || eventDescriptor[hookName];
  3147. if (hook && !eventDescriptor[doneName]) {
  3148. if (!eventDescriptor[firedName]) {
  3149. eventDescriptor[firedName] = true;
  3150. me.makeToken(eventDescriptor, doneName);
  3151. if (me.eventScope && Ext.isString(hook)) {
  3152. hook = me.eventScope[hook];
  3153. }
  3154. if (hook) {
  3155. hook.call(me.eventScope || me, eventDescriptor);
  3156. }
  3157. }
  3158. return false;
  3159. }
  3160. return true;
  3161. }, schedule:function() {
  3162. var me = this;
  3163. if (!me.timer) {
  3164. me.timer = Ext.defer(me.timerFn, 10);
  3165. }
  3166. }, _translateAcross:['type', 'button', 'charCode', 'keyCode', 'caret', 'pos', 'text', 'selection'], translateEvent:function(eventDescriptor, target) {
  3167. var me = this, event = {}, modKeys = eventDescriptor.modKeys || '', names = me._translateAcross, i = names.length, name, xy;
  3168. while (i--) {
  3169. name = names[i];
  3170. if (name in eventDescriptor) {
  3171. event[name] = eventDescriptor[name];
  3172. }
  3173. }
  3174. event.altKey = modKeys.indexOf('A') > 0;
  3175. event.ctrlKey = modKeys.indexOf('C') > 0;
  3176. event.metaKey = modKeys.indexOf('M') > 0;
  3177. event.shiftKey = modKeys.indexOf('S') > 0;
  3178. if (target && 'x' in eventDescriptor) {
  3179. xy = Ext.fly(target).getXY();
  3180. xy[0] += eventDescriptor.x;
  3181. xy[1] += eventDescriptor.y;
  3182. } else {
  3183. if ('x' in eventDescriptor) {
  3184. xy = [eventDescriptor.x, eventDescriptor.y];
  3185. } else {
  3186. if ('px' in eventDescriptor) {
  3187. xy = [eventDescriptor.px, eventDescriptor.py];
  3188. }
  3189. }
  3190. }
  3191. if (xy) {
  3192. event.clientX = event.screenX = xy[0];
  3193. event.clientY = event.screenY = xy[1];
  3194. }
  3195. if (eventDescriptor.key) {
  3196. event.keyCode = me.specialKeysByName[eventDescriptor.key];
  3197. }
  3198. if (eventDescriptor.type === 'wheel') {
  3199. if ('onwheel' in me.attachTo.document) {
  3200. event.wheelX = eventDescriptor.dx;
  3201. event.wheelY = eventDescriptor.dy;
  3202. } else {
  3203. event.type = 'mousewheel';
  3204. event.wheelDeltaX = -40 * eventDescriptor.dx;
  3205. event.wheelDeltaY = event.wheelDelta = -40 * eventDescriptor.dy;
  3206. }
  3207. }
  3208. return event;
  3209. }, onStart:function() {
  3210. var me = this;
  3211. me.queueIndex = 0;
  3212. me.schedule();
  3213. }, onStop:function() {
  3214. var me = this;
  3215. if (me.timer) {
  3216. Ext.undefer(me.timer);
  3217. me.timer = null;
  3218. }
  3219. }, onTick:function() {
  3220. var me = this;
  3221. me.timer = null;
  3222. if (me.processEvents()) {
  3223. me.schedule();
  3224. }
  3225. }, statics:{ieButtonCodeMap:{0:1, 1:4, 2:2}, injectKeyEvent:function(target, options, view) {
  3226. var type = options.type, customEvent = null;
  3227. if (type === 'textevent') {
  3228. type = 'keypress';
  3229. }
  3230. view = view || window;
  3231. if (doc.createEvent) {
  3232. try {
  3233. customEvent = doc.createEvent('KeyEvents');
  3234. customEvent.initKeyEvent(type, options.bubbles, options.cancelable, view, options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.keyCode, options.charCode);
  3235. } catch (ex) {
  3236. try {
  3237. customEvent = doc.createEvent('Events');
  3238. } catch (uierror) {
  3239. customEvent = doc.createEvent('UIEvents');
  3240. } finally {
  3241. customEvent.initEvent(type, options.bubbles, options.cancelable);
  3242. customEvent.view = view;
  3243. customEvent.altKey = options.altKey;
  3244. customEvent.ctrlKey = options.ctrlKey;
  3245. customEvent.shiftKey = options.shiftKey;
  3246. customEvent.metaKey = options.metaKey;
  3247. customEvent.keyCode = options.keyCode;
  3248. customEvent.charCode = options.charCode;
  3249. }
  3250. }
  3251. target.dispatchEvent(customEvent);
  3252. } else {
  3253. if (doc.createEventObject) {
  3254. customEvent = doc.createEventObject();
  3255. customEvent.bubbles = options.bubbles;
  3256. customEvent.cancelable = options.cancelable;
  3257. customEvent.view = view;
  3258. customEvent.ctrlKey = options.ctrlKey;
  3259. customEvent.altKey = options.altKey;
  3260. customEvent.shiftKey = options.shiftKey;
  3261. customEvent.metaKey = options.metaKey;
  3262. customEvent.keyCode = options.charCode > 0 ? options.charCode : options.keyCode;
  3263. target.fireEvent('on' + type, customEvent);
  3264. } else {
  3265. return false;
  3266. }
  3267. }
  3268. return true;
  3269. }, injectMouseEvent:function(target, options, view) {
  3270. var type = options.type, customEvent = null;
  3271. view = view || window;
  3272. if (doc.createEvent) {
  3273. customEvent = doc.createEvent('MouseEvents');
  3274. if (customEvent.initMouseEvent) {
  3275. customEvent.initMouseEvent(type, options.bubbles, options.cancelable, view, options.detail, options.screenX, options.screenY, options.clientX, options.clientY, options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, options.relatedTarget);
  3276. } else {
  3277. customEvent = doc.createEvent('UIEvents');
  3278. customEvent.initEvent(type, options.bubbles, options.cancelable);
  3279. customEvent.view = view;
  3280. customEvent.detail = options.detail;
  3281. customEvent.screenX = options.screenX;
  3282. customEvent.screenY = options.screenY;
  3283. customEvent.clientX = options.clientX;
  3284. customEvent.clientY = options.clientY;
  3285. customEvent.ctrlKey = options.ctrlKey;
  3286. customEvent.altKey = options.altKey;
  3287. customEvent.metaKey = options.metaKey;
  3288. customEvent.shiftKey = options.shiftKey;
  3289. customEvent.button = options.button;
  3290. customEvent.relatedTarget = options.relatedTarget;
  3291. }
  3292. if (options.relatedTarget && !customEvent.relatedTarget) {
  3293. if (type === 'mouseout') {
  3294. customEvent.toElement = options.relatedTarget;
  3295. } else {
  3296. if (type === 'mouseover') {
  3297. customEvent.fromElement = options.relatedTarget;
  3298. }
  3299. }
  3300. }
  3301. target.dispatchEvent(customEvent);
  3302. } else {
  3303. if (doc.createEventObject) {
  3304. customEvent = doc.createEventObject();
  3305. customEvent.bubbles = options.bubbles;
  3306. customEvent.cancelable = options.cancelable;
  3307. customEvent.view = view;
  3308. customEvent.detail = options.detail;
  3309. customEvent.screenX = options.screenX;
  3310. customEvent.screenY = options.screenY;
  3311. customEvent.clientX = options.clientX;
  3312. customEvent.clientY = options.clientY;
  3313. customEvent.ctrlKey = options.ctrlKey;
  3314. customEvent.altKey = options.altKey;
  3315. customEvent.metaKey = options.metaKey;
  3316. customEvent.shiftKey = options.shiftKey;
  3317. customEvent.button = Player.ieButtonCodeMap[options.button] || 0;
  3318. customEvent.relatedTarget = options.relatedTarget;
  3319. target.fireEvent('on' + type, customEvent);
  3320. } else {
  3321. return false;
  3322. }
  3323. }
  3324. return true;
  3325. }, injectUIEvent:function(target, options, view) {
  3326. var customEvent = null;
  3327. view = view || window;
  3328. if (doc.createEvent) {
  3329. customEvent = doc.createEvent('UIEvents');
  3330. customEvent.initUIEvent(options.type, options.bubbles, options.cancelable, view, options.detail);
  3331. target.dispatchEvent(customEvent);
  3332. } else {
  3333. if (doc.createEventObject) {
  3334. customEvent = doc.createEventObject();
  3335. customEvent.bubbles = options.bubbles;
  3336. customEvent.cancelable = options.cancelable;
  3337. customEvent.view = view;
  3338. customEvent.detail = options.detail;
  3339. target.fireEvent('on' + options.type, customEvent);
  3340. } else {
  3341. return false;
  3342. }
  3343. }
  3344. return true;
  3345. }}};
  3346. });
  3347. Ext.define('Ext.ux.event.Recorder', function(Recorder) {
  3348. var eventsToRecord, eventKey;
  3349. function apply() {
  3350. var a = arguments, n = a.length, obj = {kind:'other'}, i;
  3351. for (i = 0; i < n; ++i) {
  3352. Ext.apply(obj, arguments[i]);
  3353. }
  3354. if (obj.alt && !obj.event) {
  3355. obj.event = obj.alt;
  3356. }
  3357. return obj;
  3358. }
  3359. function key(extra) {
  3360. return apply({kind:'keyboard', modKeys:true, key:true}, extra);
  3361. }
  3362. function mouse(extra) {
  3363. return apply({kind:'mouse', button:true, modKeys:true, xy:true}, extra);
  3364. }
  3365. eventsToRecord = {keydown:key(), keypress:key(), keyup:key(), dragmove:mouse({alt:'mousemove', pageCoords:true, whileDrag:true}), mousemove:mouse({pageCoords:true}), mouseover:mouse(), mouseout:mouse(), click:mouse(), wheel:mouse({wheel:true}), mousedown:mouse({press:true}), mouseup:mouse({release:true}), scroll:apply({listen:false}), focus:apply(), blur:apply()};
  3366. for (eventKey in eventsToRecord) {
  3367. if (!eventsToRecord[eventKey].event) {
  3368. eventsToRecord[eventKey].event = eventKey;
  3369. }
  3370. }
  3371. eventsToRecord.wheel.event = null;
  3372. return {extend:'Ext.ux.event.Driver', eventsToRecord:eventsToRecord, ignoreIdRegEx:/ext-gen(?:\d+)/, inputRe:/^(input|textarea)$/i, constructor:function(config) {
  3373. var me = this, events = config && config.eventsToRecord;
  3374. if (events) {
  3375. me.eventsToRecord = Ext.apply(Ext.apply({}, me.eventsToRecord), events);
  3376. delete config.eventsToRecord;
  3377. }
  3378. me.callParent(arguments);
  3379. me.clear();
  3380. me.modKeys = [];
  3381. me.attachTo = me.attachTo || window;
  3382. }, clear:function() {
  3383. this.eventsRecorded = [];
  3384. }, listenToEvent:function(event) {
  3385. var me = this, el = me.attachTo.document.body, fn = function() {
  3386. return me.onEvent.apply(me, arguments);
  3387. }, cleaner = {};
  3388. if (el.attachEvent && el.ownerDocument.documentMode < 10) {
  3389. event = 'on' + event;
  3390. el.attachEvent(event, fn);
  3391. cleaner.destroy = function() {
  3392. if (fn) {
  3393. el.detachEvent(event, fn);
  3394. fn = null;
  3395. }
  3396. };
  3397. } else {
  3398. el.addEventListener(event, fn, true);
  3399. cleaner.destroy = function() {
  3400. if (fn) {
  3401. el.removeEventListener(event, fn, true);
  3402. fn = null;
  3403. }
  3404. };
  3405. }
  3406. return cleaner;
  3407. }, coalesce:function(rec, ev) {
  3408. var me = this, events = me.eventsRecorded, length = events.length, tail = length && events[length - 1], tail2 = length > 1 && events[length - 2], tail3 = length > 2 && events[length - 3];
  3409. if (!tail) {
  3410. return false;
  3411. }
  3412. if (rec.type === 'mousemove') {
  3413. if (tail.type === 'mousemove' && rec.ts - tail.ts < 200) {
  3414. rec.ts = tail.ts;
  3415. events[length - 1] = rec;
  3416. return true;
  3417. }
  3418. } else {
  3419. if (rec.type === 'click') {
  3420. if (tail2 && tail.type === 'mouseup' && tail2.type === 'mousedown') {
  3421. if (rec.button === tail.button && rec.button === tail2.button && rec.target === tail.target && rec.target === tail2.target && me.samePt(rec, tail) && me.samePt(rec, tail2)) {
  3422. events.pop();
  3423. tail2.type = 'mduclick';
  3424. return true;
  3425. }
  3426. }
  3427. } else {
  3428. if (rec.type === 'keyup') {
  3429. if (tail2 && tail.type === 'keypress' && tail2.type === 'keydown') {
  3430. if (rec.target === tail.target && rec.target === tail2.target) {
  3431. events.pop();
  3432. tail2.type = 'type';
  3433. tail2.text = String.fromCharCode(tail.charCode);
  3434. delete tail2.charCode;
  3435. delete tail2.keyCode;
  3436. if (tail3 && tail3.type === 'type') {
  3437. if (tail3.text && tail3.target === tail2.target) {
  3438. tail3.text += tail2.text;
  3439. events.pop();
  3440. }
  3441. }
  3442. return true;
  3443. }
  3444. } else {
  3445. if (me.completeKeyStroke(tail, rec)) {
  3446. tail.type = 'type';
  3447. me.completeSpecialKeyStroke(ev.target, tail, rec);
  3448. return true;
  3449. } else {
  3450. if (tail.type === 'scroll' && me.completeKeyStroke(tail2, rec)) {
  3451. tail2.type = 'type';
  3452. me.completeSpecialKeyStroke(ev.target, tail2, rec);
  3453. events.pop();
  3454. events.pop();
  3455. events.push(tail, tail2);
  3456. return true;
  3457. }
  3458. }
  3459. }
  3460. }
  3461. }
  3462. }
  3463. return false;
  3464. }, completeKeyStroke:function(down, up) {
  3465. if (down && down.type === 'keydown' && down.keyCode === up.keyCode) {
  3466. delete down.charCode;
  3467. return true;
  3468. }
  3469. return false;
  3470. }, completeSpecialKeyStroke:function(target, down, up) {
  3471. var key = this.specialKeysByCode[up.keyCode];
  3472. if (key && this.inputRe.test(target.tagName)) {
  3473. delete down.keyCode;
  3474. down.key = key;
  3475. down.selection = this.getTextSelection(target);
  3476. if (down.selection[0] === down.selection[1]) {
  3477. down.caret = down.selection[0];
  3478. delete down.selection;
  3479. }
  3480. return true;
  3481. }
  3482. return false;
  3483. }, getElementXPath:function(el) {
  3484. var me = this, good = false, xpath = [], count, sibling, t, tag;
  3485. for (t = el; t; t = t.parentNode) {
  3486. if (t === me.attachTo.document.body) {
  3487. xpath.unshift('~');
  3488. good = true;
  3489. break;
  3490. }
  3491. if (t.id && !me.ignoreIdRegEx.test(t.id)) {
  3492. xpath.unshift('#' + t.id);
  3493. good = true;
  3494. break;
  3495. }
  3496. for (count = 1, sibling = t; !!(sibling = sibling.previousSibling);) {
  3497. if (sibling.tagName === t.tagName) {
  3498. ++count;
  3499. }
  3500. }
  3501. tag = t.tagName.toLowerCase();
  3502. if (count < 2) {
  3503. xpath.unshift(tag);
  3504. } else {
  3505. xpath.unshift(tag + '[' + count + ']');
  3506. }
  3507. }
  3508. return good ? xpath.join('/') : null;
  3509. }, getRecordedEvents:function() {
  3510. return this.eventsRecorded;
  3511. }, onEvent:function(ev) {
  3512. var me = this, e = new Ext.event.Event(ev), info = me.eventsToRecord[e.type], root, modKeys, elXY, rec = {type:e.type, ts:me.getTimestamp(), target:me.getElementXPath(e.target)}, xy;
  3513. if (!info || !rec.target) {
  3514. return;
  3515. }
  3516. root = e.target.ownerDocument;
  3517. root = root.defaultView || root.parentWindow;
  3518. if (root !== me.attachTo) {
  3519. return;
  3520. }
  3521. if (me.eventsToRecord.scroll) {
  3522. me.syncScroll(e.target);
  3523. }
  3524. if (info.xy) {
  3525. xy = e.getXY();
  3526. if (info.pageCoords || !rec.target) {
  3527. rec.px = xy[0];
  3528. rec.py = xy[1];
  3529. } else {
  3530. elXY = Ext.fly(e.getTarget()).getXY();
  3531. xy[0] -= elXY[0];
  3532. xy[1] -= elXY[1];
  3533. rec.x = xy[0];
  3534. rec.y = xy[1];
  3535. }
  3536. }
  3537. if (info.button) {
  3538. if ('buttons' in ev) {
  3539. rec.button = ev.buttons;
  3540. } else {
  3541. rec.button = ev.button;
  3542. }
  3543. if (!rec.button && info.whileDrag) {
  3544. return;
  3545. }
  3546. }
  3547. if (info.wheel) {
  3548. rec.type = 'wheel';
  3549. if (info.event === 'wheel') {
  3550. rec.dx = ev.deltaX;
  3551. rec.dy = ev.deltaY;
  3552. } else {
  3553. if (typeof ev.wheelDeltaX === 'number') {
  3554. rec.dx = -1 / 40 * ev.wheelDeltaX;
  3555. rec.dy = -1 / 40 * ev.wheelDeltaY;
  3556. } else {
  3557. if (ev.wheelDelta) {
  3558. rec.dy = -1 / 40 * ev.wheelDelta;
  3559. } else {
  3560. if (ev.detail) {
  3561. rec.dy = ev.detail;
  3562. }
  3563. }
  3564. }
  3565. }
  3566. }
  3567. if (info.modKeys) {
  3568. me.modKeys[0] = e.altKey ? 'A' : '';
  3569. me.modKeys[1] = e.ctrlKey ? 'C' : '';
  3570. me.modKeys[2] = e.metaKey ? 'M' : '';
  3571. me.modKeys[3] = e.shiftKey ? 'S' : '';
  3572. modKeys = me.modKeys.join('');
  3573. if (modKeys) {
  3574. rec.modKeys = modKeys;
  3575. }
  3576. }
  3577. if (info.key) {
  3578. rec.charCode = e.getCharCode();
  3579. rec.keyCode = e.getKey();
  3580. }
  3581. if (me.coalesce(rec, e)) {
  3582. me.fireEvent('coalesce', me, rec);
  3583. } else {
  3584. me.eventsRecorded.push(rec);
  3585. me.fireEvent('add', me, rec);
  3586. }
  3587. }, onStart:function() {
  3588. var me = this, ddm = me.attachTo.Ext.dd.DragDropManager, evproto = me.attachTo.Ext.EventObjectImpl.prototype, special = [];
  3589. Recorder.prototype.eventsToRecord.wheel.event = 'onwheel' in me.attachTo.document ? 'wheel' : 'mousewheel';
  3590. me.listeners = [];
  3591. Ext.Object.each(me.eventsToRecord, function(name, value) {
  3592. if (value && value.listen !== false) {
  3593. if (!value.event) {
  3594. value.event = name;
  3595. }
  3596. if (value.alt && value.alt !== name) {
  3597. if (!me.eventsToRecord[value.alt]) {
  3598. special.push(value);
  3599. }
  3600. } else {
  3601. me.listeners.push(me.listenToEvent(value.event));
  3602. }
  3603. }
  3604. });
  3605. Ext.each(special, function(info) {
  3606. me.eventsToRecord[info.alt] = info;
  3607. me.listeners.push(me.listenToEvent(info.alt));
  3608. });
  3609. me.ddmStopEvent = ddm.stopEvent;
  3610. ddm.stopEvent = Ext.Function.createSequence(ddm.stopEvent, function(e) {
  3611. me.onEvent(e);
  3612. });
  3613. me.evStopEvent = evproto.stopEvent;
  3614. evproto.stopEvent = Ext.Function.createSequence(evproto.stopEvent, function() {
  3615. me.onEvent(this);
  3616. });
  3617. }, onStop:function() {
  3618. var me = this;
  3619. Ext.destroy(me.listeners);
  3620. me.listeners = null;
  3621. me.attachTo.Ext.dd.DragDropManager.stopEvent = me.ddmStopEvent;
  3622. me.attachTo.Ext.EventObjectImpl.prototype.stopEvent = me.evStopEvent;
  3623. }, samePt:function(pt1, pt2) {
  3624. return pt1.x === pt2.x && pt1.y === pt2.y;
  3625. }, syncScroll:function(el) {
  3626. var me = this, ts = me.getTimestamp(), oldX, oldY, x, y, scrolled, rec, p;
  3627. for (p = el; p; p = p.parentNode) {
  3628. oldX = p.$lastScrollLeft;
  3629. oldY = p.$lastScrollTop;
  3630. x = p.scrollLeft;
  3631. y = p.scrollTop;
  3632. scrolled = false;
  3633. if (oldX !== x) {
  3634. if (x) {
  3635. scrolled = true;
  3636. }
  3637. p.$lastScrollLeft = x;
  3638. }
  3639. if (oldY !== y) {
  3640. if (y) {
  3641. scrolled = true;
  3642. }
  3643. p.$lastScrollTop = y;
  3644. }
  3645. if (scrolled) {
  3646. me.eventsRecorded.push(rec = {type:'scroll', target:me.getElementXPath(p), ts:ts, pos:[x, y]});
  3647. me.fireEvent('add', me, rec);
  3648. }
  3649. if (p.tagName === 'BODY') {
  3650. break;
  3651. }
  3652. }
  3653. }};
  3654. });
  3655. Ext.define('Ext.ux.gauge.needle.Abstract', {mixins:['Ext.mixin.Factoryable'], alias:'gauge.needle.abstract', isNeedle:true, config:{path:null, innerRadius:25, outerRadius:'100% - 20', style:null, radius:0, gauge:null}, constructor:function(config) {
  3656. this.initConfig(config);
  3657. }, applyInnerRadius:function(innerRadius) {
  3658. return this.getGauge().getRadiusFn(innerRadius);
  3659. }, applyOuterRadius:function(outerRadius) {
  3660. return this.getGauge().getRadiusFn(outerRadius);
  3661. }, updateRadius:function() {
  3662. this.regeneratePath();
  3663. }, setTransform:function(centerX, centerY, rotation) {
  3664. var needleGroup = this.getNeedleGroup();
  3665. needleGroup.setStyle('transform', 'translate(' + centerX + 'px,' + centerY + 'px) ' + 'rotate(' + rotation + 'deg)');
  3666. }, applyPath:function(path) {
  3667. return Ext.isFunction(path) ? path : null;
  3668. }, updatePath:function(path) {
  3669. this.regeneratePath(path);
  3670. }, regeneratePath:function(path) {
  3671. path = path || this.getPath();
  3672. var me = this, radius = me.getRadius(), inner = me.getInnerRadius()(radius), outer = me.getOuterRadius()(radius), d = outer > inner ? path(inner, outer) : '';
  3673. me.getNeedlePath().dom.setAttribute('d', d);
  3674. }, getNeedleGroup:function() {
  3675. var gauge = this.getGauge(), group = this.needleGroup;
  3676. if (!group) {
  3677. group = this.needleGroup = Ext.get(document.createElementNS(gauge.svgNS, 'g'));
  3678. gauge.getSvg().appendChild(group);
  3679. }
  3680. return group;
  3681. }, getNeedlePath:function() {
  3682. var me = this, pathElement = me.pathElement;
  3683. if (!pathElement) {
  3684. pathElement = me.pathElement = Ext.get(document.createElementNS(me.getGauge().svgNS, 'path'));
  3685. pathElement.dom.setAttribute('class', Ext.baseCSSPrefix + 'gauge-needle');
  3686. me.getNeedleGroup().appendChild(pathElement);
  3687. }
  3688. return pathElement;
  3689. }, updateStyle:function(style) {
  3690. var pathElement = this.getNeedlePath();
  3691. if (Ext.isObject(style)) {
  3692. pathElement.setStyle(style);
  3693. } else {
  3694. pathElement.dom.removeAttribute('style');
  3695. }
  3696. }, destroy:function() {
  3697. var me = this;
  3698. me.pathElement = Ext.destroy(me.pathElement);
  3699. me.needleGroup = Ext.destroy(me.needleGroup);
  3700. me.setGauge(null);
  3701. }});
  3702. Ext.define('Ext.ux.gauge.Gauge', {alternateClassName:'Ext.ux.Gauge', extend:'Ext.Gadget', xtype:'gauge', requires:['Ext.ux.gauge.needle.Abstract', 'Ext.util.Region'], config:{padding:10, trackStart:135, trackLength:270, angleOffset:0, minValue:0, maxValue:100, value:50, needle:null, needleDefaults:{cached:true, $value:{type:'diamond'}}, clockwise:true, textTpl:['\x3ctpl\x3e{value:number("0.00")}%\x3c/tpl\x3e'], textAlign:'c-c', textOffset:{dx:0, dy:0}, trackStyle:{outerRadius:'100%', innerRadius:'100% - 20',
  3703. round:false}, valueStyle:{outerRadius:'100% - 2', innerRadius:'100% - 18', round:false}, animation:true}, baseCls:Ext.baseCSSPrefix + 'gauge', template:[{reference:'bodyElement', children:[{reference:'textElement', cls:Ext.baseCSSPrefix + 'gauge-text'}]}], defaultBindProperty:'value', pathAttributes:{fill:true, fillOpacity:true, stroke:true, strokeOpacity:true, strokeWidth:true}, easings:{linear:Ext.identityFn, 'in':function(t) {
  3704. return t * t * t;
  3705. }, out:function(t) {
  3706. return --t * t * t + 1;
  3707. }, inOut:function(t) {
  3708. return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
  3709. }}, resizeDelay:0, resizeTimerId:0, size:null, svgNS:'http://www.w3.org/2000/svg', svg:null, defs:null, trackArc:null, valueArc:null, trackGradient:null, valueGradient:null, fx:null, fxValue:0, fxAngleOffset:0, constructor:function(config) {
  3710. var me = this;
  3711. me.fitSectorInRectCache = {startAngle:null, lengthAngle:null, minX:null, maxX:null, minY:null, maxY:null};
  3712. me.interpolator = me.createInterpolator();
  3713. me.callParent([config]);
  3714. me.el.on('resize', 'onElementResize', me);
  3715. }, doDestroy:function() {
  3716. var me = this;
  3717. Ext.undefer(me.resizeTimerId);
  3718. me.el.un('resize', 'onElementResize', me);
  3719. me.stopAnimation();
  3720. me.setNeedle(null);
  3721. me.trackGradient = Ext.destroy(me.trackGradient);
  3722. me.valueGradient = Ext.destroy(me.valueGradient);
  3723. me.defs = Ext.destroy(me.defs);
  3724. me.svg = Ext.destroy(me.svg);
  3725. me.callParent();
  3726. }, onElementResize:function(element, size) {
  3727. this.handleResize(size);
  3728. }, handleResize:function(size, instantly) {
  3729. var me = this, el = me.element;
  3730. if (!(el && (size = size || el.getSize()) && size.width && size.height)) {
  3731. return;
  3732. }
  3733. me.resizeTimerId = Ext.undefer(me.resizeTimerId);
  3734. if (!instantly && me.resizeDelay) {
  3735. me.resizeTimerId = Ext.defer(me.handleResize, me.resizeDelay, me, [size, true]);
  3736. return;
  3737. }
  3738. me.size = size;
  3739. me.resizeHandler(size);
  3740. }, updateMinValue:function(minValue) {
  3741. var me = this;
  3742. me.interpolator.setDomain(minValue, me.getMaxValue());
  3743. if (!me.isConfiguring) {
  3744. me.render();
  3745. }
  3746. }, updateMaxValue:function(maxValue) {
  3747. var me = this;
  3748. me.interpolator.setDomain(me.getMinValue(), maxValue);
  3749. if (!me.isConfiguring) {
  3750. me.render();
  3751. }
  3752. }, updateAngleOffset:function(angleOffset, oldAngleOffset) {
  3753. var me = this, animation = me.getAnimation();
  3754. me.fxAngleOffset = angleOffset;
  3755. if (me.isConfiguring) {
  3756. return;
  3757. }
  3758. if (animation.duration) {
  3759. me.animate(oldAngleOffset, angleOffset, animation.duration, me.easings[animation.easing], function(angleOffset) {
  3760. me.fxAngleOffset = angleOffset;
  3761. me.render();
  3762. });
  3763. } else {
  3764. me.render();
  3765. }
  3766. }, applyTrackStart:function(trackStart) {
  3767. if (trackStart < 0 || trackStart >= 360) {
  3768. Ext.raise("'trackStart' should be within [0, 360).");
  3769. }
  3770. return trackStart;
  3771. }, applyTrackLength:function(trackLength) {
  3772. if (trackLength <= 0 || trackLength > 360) {
  3773. Ext.raise("'trackLength' should be within (0, 360].");
  3774. }
  3775. return trackLength;
  3776. }, updateTrackStart:function(trackStart) {
  3777. var me = this;
  3778. if (!me.isConfiguring) {
  3779. me.render();
  3780. }
  3781. }, updateTrackLength:function(trackLength) {
  3782. var me = this;
  3783. me.interpolator.setRange(0, trackLength);
  3784. if (!me.isConfiguring) {
  3785. me.render();
  3786. }
  3787. }, applyPadding:function(padding) {
  3788. var ratio;
  3789. if (typeof padding === 'string') {
  3790. ratio = parseFloat(padding) / 100;
  3791. return function(x) {
  3792. return x * ratio;
  3793. };
  3794. }
  3795. return function() {
  3796. return padding;
  3797. };
  3798. }, updatePadding:function() {
  3799. if (!this.isConfiguring) {
  3800. this.render();
  3801. }
  3802. }, applyValue:function(value) {
  3803. var minValue = this.getMinValue(), maxValue = this.getMaxValue();
  3804. return Math.min(Math.max(value, minValue), maxValue);
  3805. }, updateValue:function(value, oldValue) {
  3806. var me = this, animation = me.getAnimation();
  3807. me.fxValue = value;
  3808. if (me.isConfiguring) {
  3809. return;
  3810. }
  3811. me.writeText();
  3812. if (animation.duration) {
  3813. me.animate(oldValue, value, animation.duration, me.easings[animation.easing], function(value) {
  3814. me.fxValue = value;
  3815. me.render();
  3816. });
  3817. } else {
  3818. me.render();
  3819. }
  3820. }, applyTextTpl:function(textTpl) {
  3821. if (textTpl && !textTpl.isTemplate) {
  3822. textTpl = new Ext.XTemplate(textTpl);
  3823. }
  3824. return textTpl;
  3825. }, applyTextOffset:function(offset) {
  3826. offset = offset || {};
  3827. offset.dx = offset.dx || 0;
  3828. offset.dy = offset.dy || 0;
  3829. return offset;
  3830. }, updateTextTpl:function() {
  3831. this.writeText();
  3832. if (!this.isConfiguring) {
  3833. this.centerText();
  3834. }
  3835. }, writeText:function(options) {
  3836. var me = this, value = me.getValue(), minValue = me.getMinValue(), maxValue = me.getMaxValue(), delta = maxValue - minValue, textTpl = me.getTextTpl();
  3837. textTpl.overwrite(me.textElement, {value:value, percent:(value - minValue) / delta * 100, minValue:minValue, maxValue:maxValue, delta:delta});
  3838. }, centerText:function(cx, cy, sectorRegion, innerRadius, outerRadius) {
  3839. var textElement = this.textElement, textAlign = this.getTextAlign(), alignedRegion, textBox;
  3840. if (Ext.Number.isEqual(innerRadius, 0, 0.1) || sectorRegion.isOutOfBound({x:cx, y:cy})) {
  3841. alignedRegion = textElement.getRegion().alignTo({align:textAlign, target:sectorRegion});
  3842. textElement.setLeft(alignedRegion.left);
  3843. textElement.setTop(alignedRegion.top);
  3844. } else {
  3845. textBox = textElement.getBox();
  3846. textElement.setLeft(cx - textBox.width / 2);
  3847. textElement.setTop(cy - textBox.height / 2);
  3848. }
  3849. }, camelCaseRe:/([a-z])([A-Z])/g, camelToHyphen:function(name) {
  3850. return name.replace(this.camelCaseRe, '$1-$2').toLowerCase();
  3851. }, applyTrackStyle:function(trackStyle) {
  3852. var me = this, trackGradient;
  3853. trackStyle.innerRadius = me.getRadiusFn(trackStyle.innerRadius);
  3854. trackStyle.outerRadius = me.getRadiusFn(trackStyle.outerRadius);
  3855. if (Ext.isArray(trackStyle.fill)) {
  3856. trackGradient = me.getTrackGradient();
  3857. me.setGradientStops(trackGradient, trackStyle.fill);
  3858. trackStyle.fill = 'url(#' + trackGradient.dom.getAttribute('id') + ')';
  3859. }
  3860. return trackStyle;
  3861. }, updateTrackStyle:function(trackStyle) {
  3862. var me = this, trackArc = Ext.fly(me.getTrackArc()), name;
  3863. for (name in trackStyle) {
  3864. if (name in me.pathAttributes) {
  3865. trackArc.setStyle(me.camelToHyphen(name), trackStyle[name]);
  3866. } else {
  3867. trackArc.setStyle(name, trackStyle[name]);
  3868. }
  3869. }
  3870. }, applyValueStyle:function(valueStyle) {
  3871. var me = this, valueGradient;
  3872. valueStyle.innerRadius = me.getRadiusFn(valueStyle.innerRadius);
  3873. valueStyle.outerRadius = me.getRadiusFn(valueStyle.outerRadius);
  3874. if (Ext.isArray(valueStyle.fill)) {
  3875. valueGradient = me.getValueGradient();
  3876. me.setGradientStops(valueGradient, valueStyle.fill);
  3877. valueStyle.fill = 'url(#' + valueGradient.dom.getAttribute('id') + ')';
  3878. }
  3879. return valueStyle;
  3880. }, updateValueStyle:function(valueStyle) {
  3881. var me = this, valueArc = Ext.fly(me.getValueArc()), name;
  3882. for (name in valueStyle) {
  3883. if (name in me.pathAttributes) {
  3884. valueArc.setStyle(me.camelToHyphen(name), valueStyle[name]);
  3885. } else {
  3886. valueArc.setStyle(name, valueStyle[name]);
  3887. }
  3888. }
  3889. }, getRadiusFn:function(radius) {
  3890. var result, pos, ratio, increment = 0;
  3891. if (Ext.isNumber(radius)) {
  3892. result = function() {
  3893. return radius;
  3894. };
  3895. } else {
  3896. if (Ext.isString(radius)) {
  3897. radius = radius.replace(/ /g, '');
  3898. ratio = parseFloat(radius) / 100;
  3899. pos = radius.search('%');
  3900. if (pos < radius.length - 1) {
  3901. increment = parseFloat(radius.substr(pos + 1));
  3902. }
  3903. result = function(radius) {
  3904. return radius * ratio + increment;
  3905. };
  3906. result.ratio = ratio;
  3907. }
  3908. }
  3909. return result;
  3910. }, getSvg:function() {
  3911. var me = this, svg = me.svg;
  3912. if (!svg) {
  3913. svg = me.svg = Ext.get(document.createElementNS(me.svgNS, 'svg'));
  3914. me.bodyElement.append(svg);
  3915. }
  3916. return svg;
  3917. }, getTrackArc:function() {
  3918. var me = this, trackArc = me.trackArc;
  3919. if (!trackArc) {
  3920. trackArc = me.trackArc = document.createElementNS(me.svgNS, 'path');
  3921. me.getSvg().append(trackArc, true);
  3922. trackArc.setAttribute('class', Ext.baseCSSPrefix + 'gauge-track');
  3923. }
  3924. return trackArc;
  3925. }, getValueArc:function() {
  3926. var me = this, valueArc = me.valueArc;
  3927. me.getTrackArc();
  3928. if (!valueArc) {
  3929. valueArc = me.valueArc = document.createElementNS(me.svgNS, 'path');
  3930. me.getSvg().append(valueArc, true);
  3931. valueArc.setAttribute('class', Ext.baseCSSPrefix + 'gauge-value');
  3932. }
  3933. return valueArc;
  3934. }, applyNeedle:function(needle, oldNeedle) {
  3935. this.getValueArc();
  3936. return Ext.Factory.gaugeNeedle.update(oldNeedle, needle, this, 'createNeedle', 'needleDefaults');
  3937. }, createNeedle:function(config) {
  3938. return Ext.apply({gauge:this}, config);
  3939. }, getDefs:function() {
  3940. var me = this, defs = me.defs;
  3941. if (!defs) {
  3942. defs = me.defs = Ext.get(document.createElementNS(me.svgNS, 'defs'));
  3943. me.getSvg().appendChild(defs);
  3944. }
  3945. return defs;
  3946. }, setGradientSize:function(gradient, x1, y1, x2, y2) {
  3947. gradient.setAttribute('x1', x1);
  3948. gradient.setAttribute('y1', y1);
  3949. gradient.setAttribute('x2', x2);
  3950. gradient.setAttribute('y2', y2);
  3951. }, resizeGradients:function(size) {
  3952. var me = this, trackGradient = me.getTrackGradient(), valueGradient = me.getValueGradient(), x1 = 0, y1 = size.height / 2, x2 = size.width, y2 = size.height / 2;
  3953. me.setGradientSize(trackGradient.dom, x1, y1, x2, y2);
  3954. me.setGradientSize(valueGradient.dom, x1, y1, x2, y2);
  3955. }, setGradientStops:function(gradient, stops) {
  3956. var ln = stops.length, i, stopCfg, stopEl;
  3957. while (gradient.firstChild) {
  3958. gradient.removeChild(gradient.firstChild);
  3959. }
  3960. for (i = 0; i < ln; i++) {
  3961. stopCfg = stops[i];
  3962. stopEl = document.createElementNS(this.svgNS, 'stop');
  3963. gradient.appendChild(stopEl);
  3964. stopEl.setAttribute('offset', stopCfg.offset);
  3965. stopEl.setAttribute('stop-color', stopCfg.color);
  3966. if ('opacity' in stopCfg) {
  3967. stopEl.setAttribute('stop-opacity', stopCfg.opacity);
  3968. }
  3969. }
  3970. }, getTrackGradient:function() {
  3971. var me = this, trackGradient = me.trackGradient;
  3972. if (!trackGradient) {
  3973. trackGradient = me.trackGradient = Ext.get(document.createElementNS(me.svgNS, 'linearGradient'));
  3974. trackGradient.dom.setAttribute('gradientUnits', 'userSpaceOnUse');
  3975. me.getDefs().appendChild(trackGradient);
  3976. Ext.get(trackGradient);
  3977. }
  3978. return trackGradient;
  3979. }, getValueGradient:function() {
  3980. var me = this, valueGradient = me.valueGradient;
  3981. if (!valueGradient) {
  3982. valueGradient = me.valueGradient = Ext.get(document.createElementNS(me.svgNS, 'linearGradient'));
  3983. valueGradient.dom.setAttribute('gradientUnits', 'userSpaceOnUse');
  3984. me.getDefs().appendChild(valueGradient);
  3985. Ext.get(valueGradient);
  3986. }
  3987. return valueGradient;
  3988. }, getArcPoint:function(centerX, centerY, radius, degrees) {
  3989. var radians = degrees / 180 * Math.PI;
  3990. return [centerX + radius * Math.cos(radians), centerY + radius * Math.sin(radians)];
  3991. }, isCircle:function(startAngle, endAngle) {
  3992. return Ext.Number.isEqual(Math.abs(endAngle - startAngle), 360, 0.001);
  3993. }, getArcPath:function(centerX, centerY, innerRadius, outerRadius, startAngle, endAngle, round) {
  3994. var me = this, isCircle = me.isCircle(startAngle, endAngle), endAngle = endAngle - 0.01, innerStartPoint = me.getArcPoint(centerX, centerY, innerRadius, startAngle), innerEndPoint = me.getArcPoint(centerX, centerY, innerRadius, endAngle), outerStartPoint = me.getArcPoint(centerX, centerY, outerRadius, startAngle), outerEndPoint = me.getArcPoint(centerX, centerY, outerRadius, endAngle), large = endAngle - startAngle <= 180 ? 0 : 1, path = ['M', innerStartPoint[0], innerStartPoint[1], 'A', innerRadius,
  3995. innerRadius, 0, large, 1, innerEndPoint[0], innerEndPoint[1]], capRadius = (outerRadius - innerRadius) / 2;
  3996. if (isCircle) {
  3997. path.push('M', outerEndPoint[0], outerEndPoint[1]);
  3998. } else {
  3999. if (round) {
  4000. path.push('A', capRadius, capRadius, 0, 0, 0, outerEndPoint[0], outerEndPoint[1]);
  4001. } else {
  4002. path.push('L', outerEndPoint[0], outerEndPoint[1]);
  4003. }
  4004. }
  4005. path.push('A', outerRadius, outerRadius, 0, large, 0, outerStartPoint[0], outerStartPoint[1]);
  4006. if (round && !isCircle) {
  4007. path.push('A', capRadius, capRadius, 0, 0, 0, innerStartPoint[0], innerStartPoint[1]);
  4008. }
  4009. path.push('Z');
  4010. return path.join(' ');
  4011. }, resizeHandler:function(size) {
  4012. var me = this, svg = me.getSvg();
  4013. svg.setSize(size);
  4014. me.resizeGradients(size);
  4015. me.render();
  4016. }, createInterpolator:function(rangeCheck) {
  4017. var domainStart = 0, domainDelta = 1, rangeStart = 0, rangeEnd = 1, interpolator = function(x, invert) {
  4018. var t = 0;
  4019. if (domainDelta) {
  4020. t = (x - domainStart) / domainDelta;
  4021. if (rangeCheck) {
  4022. t = Math.max(0, t);
  4023. t = Math.min(1, t);
  4024. }
  4025. if (invert) {
  4026. t = 1 - t;
  4027. }
  4028. }
  4029. return (1 - t) * rangeStart + t * rangeEnd;
  4030. };
  4031. interpolator.setDomain = function(a, b) {
  4032. domainStart = a;
  4033. domainDelta = b - a;
  4034. return this;
  4035. };
  4036. interpolator.setRange = function(a, b) {
  4037. rangeStart = a;
  4038. rangeEnd = b;
  4039. return this;
  4040. };
  4041. interpolator.getDomain = function() {
  4042. return [domainStart, domainStart + domainDelta];
  4043. };
  4044. interpolator.getRange = function() {
  4045. return [rangeStart, rangeEnd];
  4046. };
  4047. return interpolator;
  4048. }, applyAnimation:function(animation) {
  4049. if (true === animation) {
  4050. animation = {};
  4051. } else {
  4052. if (false === animation) {
  4053. animation = {duration:0};
  4054. }
  4055. }
  4056. if (!('duration' in animation)) {
  4057. animation.duration = 1000;
  4058. }
  4059. if (!(animation.easing in this.easings)) {
  4060. animation.easing = 'out';
  4061. }
  4062. return animation;
  4063. }, updateAnimation:function() {
  4064. this.stopAnimation();
  4065. }, animate:function(from, to, duration, easing, fn, scope) {
  4066. var me = this, start = Ext.now(), interpolator = me.createInterpolator().setRange(from, to);
  4067. function frame() {
  4068. var now = Ext.AnimationQueue.frameStartTime, t = Math.min(now - start, duration) / duration, value = interpolator(easing(t));
  4069. if (scope) {
  4070. if (typeof fn === 'string') {
  4071. scope[fn].call(scope, value);
  4072. } else {
  4073. fn.call(scope, value);
  4074. }
  4075. } else {
  4076. fn(value);
  4077. }
  4078. if (t >= 1) {
  4079. Ext.AnimationQueue.stop(frame, scope);
  4080. me.fx = null;
  4081. }
  4082. }
  4083. me.stopAnimation();
  4084. Ext.AnimationQueue.start(frame, scope);
  4085. me.fx = {frame:frame, scope:scope};
  4086. }, stopAnimation:function() {
  4087. var me = this;
  4088. if (me.fx) {
  4089. Ext.AnimationQueue.stop(me.fx.frame, me.fx.scope);
  4090. me.fx = null;
  4091. }
  4092. }, unitCircleExtrema:{0:[1, 0], 90:[0, 1], 180:[-1, 0], 270:[0, -1], 360:[1, 0], 450:[0, 1], 540:[-1, 0], 630:[0, -1]}, getUnitSectorExtrema:function(startAngle, lengthAngle) {
  4093. var extrema = this.unitCircleExtrema, points = [], angle;
  4094. for (angle in extrema) {
  4095. if (angle > startAngle && angle < startAngle + lengthAngle) {
  4096. points.push(extrema[angle]);
  4097. }
  4098. }
  4099. return points;
  4100. }, fitSectorInRect:function(width, height, startAngle, lengthAngle, ratio) {
  4101. if (Ext.Number.isEqual(lengthAngle, 360, 0.001)) {
  4102. return {cx:width / 2, cy:height / 2, radius:Math.min(width, height) / 2, region:new Ext.util.Region(0, width, height, 0)};
  4103. }
  4104. var me = this, points, xx, yy, minX, maxX, minY, maxY, cache = me.fitSectorInRectCache, sameAngles = cache.startAngle === startAngle && cache.lengthAngle === lengthAngle;
  4105. if (sameAngles) {
  4106. minX = cache.minX;
  4107. maxX = cache.maxX;
  4108. minY = cache.minY;
  4109. maxY = cache.maxY;
  4110. } else {
  4111. points = me.getUnitSectorExtrema(startAngle, lengthAngle).concat([me.getArcPoint(0, 0, 1, startAngle), me.getArcPoint(0, 0, ratio, startAngle), me.getArcPoint(0, 0, 1, startAngle + lengthAngle), me.getArcPoint(0, 0, ratio, startAngle + lengthAngle)]);
  4112. xx = points.map(function(point) {
  4113. return point[0];
  4114. });
  4115. yy = points.map(function(point) {
  4116. return point[1];
  4117. });
  4118. minX = Math.min.apply(null, xx);
  4119. maxX = Math.max.apply(null, xx);
  4120. minY = Math.min.apply(null, yy);
  4121. maxY = Math.max.apply(null, yy);
  4122. cache.startAngle = startAngle;
  4123. cache.lengthAngle = lengthAngle;
  4124. cache.minX = minX;
  4125. cache.maxX = maxX;
  4126. cache.minY = minY;
  4127. cache.maxY = maxY;
  4128. }
  4129. var sectorWidth = maxX - minX, sectorHeight = maxY - minY, scaleX = width / sectorWidth, scaleY = height / sectorHeight, scale = Math.min(scaleX, scaleY), sectorRegion = new Ext.util.Region(minY * scale, maxX * scale, maxY * scale, minX * scale), rectRegion = new Ext.util.Region(0, width, height, 0), alignedRegion = sectorRegion.alignTo({align:'c-c', target:rectRegion}), dx = alignedRegion.left - minX * scale, dy = alignedRegion.top - minY * scale;
  4130. return {cx:dx, cy:dy, radius:scale, region:alignedRegion};
  4131. }, fitSectorInPaddedRect:function(width, height, padding, startAngle, lengthAngle, ratio) {
  4132. var result = this.fitSectorInRect(width - padding * 2, height - padding * 2, startAngle, lengthAngle, ratio);
  4133. result.cx += padding;
  4134. result.cy += padding;
  4135. result.region.translateBy(padding, padding);
  4136. return result;
  4137. }, normalizeAngle:function(angle) {
  4138. return (angle % 360 + 360) % 360;
  4139. }, render:function() {
  4140. if (!this.size) {
  4141. return;
  4142. }
  4143. var me = this, textOffset = me.getTextOffset(), trackArc = me.getTrackArc(), valueArc = me.getValueArc(), needle = me.getNeedle(), clockwise = me.getClockwise(), value = me.fxValue, angleOffset = me.fxAngleOffset, trackLength = me.getTrackLength(), width = me.size.width, height = me.size.height, paddingFn = me.getPadding(), padding = paddingFn(Math.min(width, height)), trackStart = me.normalizeAngle(me.getTrackStart() + angleOffset), trackEnd = trackStart + trackLength, valueLength = me.interpolator(value),
  4144. trackStyle = me.getTrackStyle(), valueStyle = me.getValueStyle(), sector = me.fitSectorInPaddedRect(width, height, padding, trackStart, trackLength, trackStyle.innerRadius.ratio), cx = sector.cx, cy = sector.cy, radius = sector.radius, trackInnerRadius = Math.max(0, trackStyle.innerRadius(radius)), trackOuterRadius = Math.max(0, trackStyle.outerRadius(radius)), valueInnerRadius = Math.max(0, valueStyle.innerRadius(radius)), valueOuterRadius = Math.max(0, valueStyle.outerRadius(radius)), trackPath =
  4145. me.getArcPath(cx, cy, trackInnerRadius, trackOuterRadius, trackStart, trackEnd, trackStyle.round), valuePath = me.getArcPath(cx, cy, valueInnerRadius, valueOuterRadius, clockwise ? trackStart : trackEnd - valueLength, clockwise ? trackStart + valueLength : trackEnd, valueStyle.round);
  4146. me.centerText(cx + textOffset.dx, cy + textOffset.dy, sector.region, trackInnerRadius, trackOuterRadius);
  4147. trackArc.setAttribute('d', trackPath);
  4148. valueArc.setAttribute('d', valuePath);
  4149. if (needle) {
  4150. needle.setRadius(radius);
  4151. needle.setTransform(cx, cy, -90 + trackStart + valueLength);
  4152. }
  4153. me.fireEvent('render', me);
  4154. }});
  4155. Ext.define('Ext.ux.gauge.needle.Arrow', {extend:'Ext.ux.gauge.needle.Abstract', alias:'gauge.needle.arrow', config:{path:function(ir, or) {
  4156. return or - ir > 30 ? 'M0,' + (ir + 5) + ' L-4,' + ir + ' L-4,' + (ir + 10) + ' L-1,' + (ir + 15) + ' L-1,' + (or - 7) + ' L-5,' + (or - 10) + ' L0,' + or + ' L5,' + (or - 10) + ' L1,' + (or - 7) + ' L1,' + (ir + 15) + ' L4,' + (ir + 10) + ' L4,' + ir + ' Z' : '';
  4157. }}});
  4158. Ext.define('Ext.ux.gauge.needle.Diamond', {extend:'Ext.ux.gauge.needle.Abstract', alias:'gauge.needle.diamond', config:{path:function(ir, or) {
  4159. return or - ir > 10 ? 'M0,' + ir + ' L-4,' + (ir + 5) + ' L0,' + or + ' L4,' + (ir + 5) + ' Z' : '';
  4160. }}});
  4161. Ext.define('Ext.ux.gauge.needle.Rectangle', {extend:'Ext.ux.gauge.needle.Abstract', alias:'gauge.needle.rectangle', config:{path:function(ir, or) {
  4162. return or - ir > 10 ? 'M-2,' + ir + ' L2,' + ir + ' L2,' + or + ' L-2,' + or + ' Z' : '';
  4163. }}});
  4164. Ext.define('Ext.ux.gauge.needle.Spike', {extend:'Ext.ux.gauge.needle.Abstract', alias:'gauge.needle.spike', config:{path:function(ir, or) {
  4165. return or - ir > 10 ? 'M0,' + (ir + 5) + ' L-4,' + ir + ' L0,' + or + ' L4,' + ir + ' Z' : '';
  4166. }}});
  4167. Ext.define('Ext.ux.gauge.needle.Wedge', {extend:'Ext.ux.gauge.needle.Abstract', alias:'gauge.needle.wedge', config:{path:function(ir, or) {
  4168. return or - ir > 10 ? 'M-4,' + ir + ' L0,' + or + ' L4,' + ir + ' Z' : '';
  4169. }}});
  4170. Ext.define('Ext.ux.rating.Picker', {extend:'Ext.Gadget', xtype:'rating', focusable:true, cachedConfig:{family:'monospace', glyphs:'☆★', minimum:1, limit:5, overStyle:null, rounding:1, scale:'125%', selectedStyle:null, tip:null, trackOver:true, value:null, tooltipText:null, trackingValue:null}, config:{animate:null}, element:{cls:'u' + Ext.baseCSSPrefix + 'rating-picker', reference:'element', children:[{reference:'innerEl', cls:'u' + Ext.baseCSSPrefix + 'rating-picker-inner', listeners:{click:'onClick',
  4171. mousemove:'onMouseMove', mouseenter:'onMouseEnter', mouseleave:'onMouseLeave'}, children:[{reference:'valueEl', cls:'u' + Ext.baseCSSPrefix + 'rating-picker-value'}, {reference:'trackerEl', cls:'u' + Ext.baseCSSPrefix + 'rating-picker-tracker'}]}]}, defaultBindProperty:'value', twoWayBindable:'value', overCls:'u' + Ext.baseCSSPrefix + 'rating-picker-over', trackOverCls:'u' + Ext.baseCSSPrefix + 'rating-picker-track-over', applyGlyphs:function(value) {
  4172. if (typeof value === 'string') {
  4173. if (value.length !== 2) {
  4174. Ext.raise('Expected 2 characters for "glyphs" not "' + value + '".');
  4175. }
  4176. value = [value.charAt(0), value.charAt(1)];
  4177. } else {
  4178. if (typeof value[0] === 'number') {
  4179. value = [String.fromCharCode(value[0]), String.fromCharCode(value[1])];
  4180. }
  4181. }
  4182. return value;
  4183. }, applyOverStyle:function(style) {
  4184. this.trackerEl.applyStyles(style);
  4185. }, applySelectedStyle:function(style) {
  4186. this.valueEl.applyStyles(style);
  4187. }, applyTip:function(tip) {
  4188. if (tip && typeof tip !== 'function') {
  4189. if (!tip.isTemplate) {
  4190. tip = new Ext.XTemplate(tip);
  4191. }
  4192. tip = tip.apply.bind(tip);
  4193. }
  4194. return tip;
  4195. }, applyTrackingValue:function(value) {
  4196. return this.applyValue(value);
  4197. }, applyValue:function(v) {
  4198. var rounding, limit, min;
  4199. if (v !== null) {
  4200. rounding = this.getRounding();
  4201. limit = this.getLimit();
  4202. min = this.getMinimum();
  4203. v = Math.round(Math.round(v / rounding) * rounding * 1000) / 1000;
  4204. v = v < min ? min : v > limit ? limit : v;
  4205. }
  4206. return v;
  4207. }, onClick:function(event) {
  4208. var value = this.valueFromEvent(event);
  4209. this.setValue(value);
  4210. }, onMouseEnter:function() {
  4211. this.element.addCls(this.overCls);
  4212. }, onMouseLeave:function() {
  4213. this.element.removeCls(this.overCls);
  4214. }, onMouseMove:function(event) {
  4215. var value = this.valueFromEvent(event);
  4216. this.setTrackingValue(value);
  4217. }, updateFamily:function(family) {
  4218. this.element.setStyle('fontFamily', "'" + family + "'");
  4219. }, updateGlyphs:function() {
  4220. this.refreshGlyphs();
  4221. }, updateLimit:function() {
  4222. this.refreshGlyphs();
  4223. }, updateScale:function(size) {
  4224. this.element.setStyle('fontSize', size);
  4225. }, updateTip:function() {
  4226. this.refreshTip();
  4227. }, updateTooltipText:function(text) {
  4228. this.setTooltip(text);
  4229. }, updateTrackingValue:function(value) {
  4230. var me = this, trackerEl = me.trackerEl, newWidth = me.valueToPercent(value);
  4231. trackerEl.setStyle('width', newWidth);
  4232. me.refreshTip();
  4233. }, updateTrackOver:function(trackOver) {
  4234. this.element.toggleCls(this.trackOverCls, trackOver);
  4235. }, updateValue:function(value, oldValue) {
  4236. var me = this, animate = me.getAnimate(), valueEl = me.valueEl, newWidth = me.valueToPercent(value), column, record;
  4237. if (me.isConfiguring || !animate) {
  4238. valueEl.setStyle('width', newWidth);
  4239. } else {
  4240. valueEl.stopAnimation();
  4241. valueEl.animate(Ext.merge({from:{width:me.valueToPercent(oldValue)}, to:{width:newWidth}}, animate));
  4242. }
  4243. me.refreshTip();
  4244. if (!me.isConfiguring) {
  4245. if (me.hasListeners.change) {
  4246. me.fireEvent('change', me, value, oldValue);
  4247. }
  4248. column = me.getWidgetColumn && me.getWidgetColumn();
  4249. record = column && me.getWidgetRecord && me.getWidgetRecord();
  4250. if (record && column.dataIndex) {
  4251. record.set(column.dataIndex, value);
  4252. }
  4253. }
  4254. }, afterCachedConfig:function() {
  4255. this.refresh();
  4256. return this.callParent(arguments);
  4257. }, initConfig:function(instanceConfig) {
  4258. this.isConfiguring = true;
  4259. this.callParent([instanceConfig]);
  4260. this.refresh();
  4261. }, setConfig:function() {
  4262. var me = this;
  4263. me.isReconfiguring = true;
  4264. me.callParent(arguments);
  4265. me.isReconfiguring = false;
  4266. me.refresh();
  4267. return me;
  4268. }, privates:{getGlyphTextNode:function(dom) {
  4269. var node = dom.lastChild;
  4270. if (!node || node.nodeType !== 3) {
  4271. node = dom.ownerDocument.createTextNode('');
  4272. dom.appendChild(node);
  4273. }
  4274. return node;
  4275. }, getTooltipData:function() {
  4276. var me = this;
  4277. return {component:me, tracking:me.getTrackingValue(), trackOver:me.getTrackOver(), value:me.getValue()};
  4278. }, refresh:function() {
  4279. var me = this;
  4280. if (me.invalidGlyphs) {
  4281. me.refreshGlyphs(true);
  4282. }
  4283. if (me.invalidTip) {
  4284. me.refreshTip(true);
  4285. }
  4286. }, refreshGlyphs:function(now) {
  4287. var me = this, later = !now && (me.isConfiguring || me.isReconfiguring), el, glyphs, limit, on, off, trackerEl, valueEl;
  4288. if (!later) {
  4289. el = me.getGlyphTextNode(me.innerEl.dom);
  4290. valueEl = me.getGlyphTextNode(me.valueEl.dom);
  4291. trackerEl = me.getGlyphTextNode(me.trackerEl.dom);
  4292. glyphs = me.getGlyphs();
  4293. limit = me.getLimit();
  4294. for (on = off = ''; limit--;) {
  4295. off += glyphs[0];
  4296. on += glyphs[1];
  4297. }
  4298. el.nodeValue = off;
  4299. valueEl.nodeValue = on;
  4300. trackerEl.nodeValue = on;
  4301. }
  4302. me.invalidGlyphs = later;
  4303. }, refreshTip:function(now) {
  4304. var me = this, later = !now && (me.isConfiguring || me.isReconfiguring), data, text, tooltip;
  4305. if (!later) {
  4306. tooltip = me.getTip();
  4307. if (tooltip) {
  4308. data = me.getTooltipData();
  4309. text = tooltip(data);
  4310. me.setTooltipText(text);
  4311. }
  4312. }
  4313. me.invalidTip = later;
  4314. }, valueFromEvent:function(event) {
  4315. var me = this, el = me.innerEl, ex = event.getX(), rounding = me.getRounding(), cx = el.getX(), x = ex - cx, w = el.getWidth(), limit = me.getLimit(), v;
  4316. if (me.getInherited().rtl) {
  4317. x = w - x;
  4318. }
  4319. v = x / w * limit;
  4320. v = Math.ceil(v / rounding) * rounding;
  4321. return v;
  4322. }, valueToPercent:function(value) {
  4323. value = value / this.getLimit() * 100;
  4324. return value + '%';
  4325. }}});
  4326. Ext.define('Ext.ux.colorpick.Selection', {mixinId:'colorselection', config:{format:'hex6', value:'FF0000', color:null, previousColor:null, alphaDecimalFormat:'#.##'}, applyColor:function(color) {
  4327. var c = color;
  4328. if (Ext.isString(c)) {
  4329. c = Ext.ux.colorpick.ColorUtils.parseColor(color, this.getAlphaDecimalFormat());
  4330. }
  4331. return c;
  4332. }, applyValue:function(color) {
  4333. var c = Ext.ux.colorpick.ColorUtils.parseColor(color || '#000000', this.getAlphaDecimalFormat());
  4334. return this.formatColor(c);
  4335. }, formatColor:function(color) {
  4336. return Ext.ux.colorpick.ColorUtils.formats[this.getFormat()](color);
  4337. }, updateColor:function(color) {
  4338. var me = this;
  4339. if (!me.syncing) {
  4340. me.syncing = true;
  4341. me.setValue(me.formatColor(color));
  4342. me.syncing = false;
  4343. }
  4344. }, updateValue:function(value, oldValue) {
  4345. var me = this;
  4346. if (!me.syncing) {
  4347. me.syncing = true;
  4348. me.setColor(value);
  4349. me.syncing = false;
  4350. }
  4351. this.fireEvent('change', me, value, oldValue);
  4352. }});
  4353. Ext.define('Ext.ux.colorpick.ColorUtils', function(ColorUtils) {
  4354. return {singleton:true, constructor:function() {
  4355. ColorUtils = this;
  4356. }, backgroundTpl:'background: {rgba};', setBackground:function(el, color) {
  4357. var tpl, data, bgStyle;
  4358. if (el) {
  4359. tpl = Ext.XTemplate.getTpl(ColorUtils, 'backgroundTpl');
  4360. data = {rgba:ColorUtils.getRGBAString(color)};
  4361. bgStyle = tpl.apply(data);
  4362. el.applyStyles(bgStyle);
  4363. }
  4364. }, formats:{HEX6:function(colorO) {
  4365. return ColorUtils.rgb2hex(colorO && colorO.r, colorO && colorO.g, colorO && colorO.b);
  4366. }, HEX8:function(colorO) {
  4367. var hex = ColorUtils.rgb2hex(colorO.r, colorO.g, colorO.b), opacityHex = Math.round(colorO.a * 255).toString(16);
  4368. if (opacityHex.length < 2) {
  4369. hex += '0';
  4370. }
  4371. hex += opacityHex.toUpperCase();
  4372. return hex;
  4373. }, rgb:function(color) {
  4374. return ColorUtils.getRGBString(color);
  4375. }, rgba:function(color) {
  4376. return ColorUtils.getRGBAString(color);
  4377. }}, hexRe:/^#?([0-9a-f]{3,8})/i, rgbaAltRe:/rgba\(\s*([\w#\d]+)\s*,\s*([\d\.]+)\s*\)/, rgbaRe:/rgba\(\s*([\d\.]+)\s*,\s*([\d\.]+)\s*,\s*([\d\.]+)\s*,\s*([\d\.]+)\s*\)/, rgbRe:/rgb\(\s*([\d\.]+)\s*,\s*([\d\.]+)\s*,\s*([\d\.]+)\s*\)/, parseColor:function(color, alphaFormat) {
  4378. var me = this, rgb, match, ret, hsv;
  4379. if (!color) {
  4380. return null;
  4381. }
  4382. rgb = me.colorMap[color];
  4383. if (rgb) {
  4384. ret = {r:rgb[0], g:rgb[1], b:rgb[2], a:1};
  4385. } else {
  4386. if (color === 'transparent') {
  4387. ret = {r:0, g:0, b:0, a:0};
  4388. } else {
  4389. match = me.hexRe.exec(color);
  4390. if (match) {
  4391. match = match[1];
  4392. switch(match.length) {
  4393. default:
  4394. return null;
  4395. case 3:
  4396. ret = {r:parseInt(match[0] + match[0], 16), g:parseInt(match[1] + match[1], 16), b:parseInt(match[2] + match[2], 16), a:1};
  4397. break;
  4398. case 6:
  4399. case 8:
  4400. ret = {r:parseInt(match.substr(0, 2), 16), g:parseInt(match.substr(2, 2), 16), b:parseInt(match.substr(4, 2), 16), a:parseInt(match.substr(6, 2) || 'ff', 16) / 255};
  4401. break;
  4402. }
  4403. } else {
  4404. match = me.rgbaRe.exec(color);
  4405. if (match) {
  4406. ret = {r:parseFloat(match[1]), g:parseFloat(match[2]), b:parseFloat(match[3]), a:parseFloat(match[4])};
  4407. } else {
  4408. match = me.rgbaAltRe.exec(color);
  4409. if (match) {
  4410. ret = me.parseColor(match[1]);
  4411. ret.a = parseFloat(match[2]);
  4412. return ret;
  4413. }
  4414. match = me.rgbRe.exec(color);
  4415. if (match) {
  4416. ret = {r:parseFloat(match[1]), g:parseFloat(match[2]), b:parseFloat(match[3]), a:1};
  4417. } else {
  4418. return null;
  4419. }
  4420. }
  4421. }
  4422. }
  4423. }
  4424. if (alphaFormat) {
  4425. ret.a = Ext.util.Format.number(ret.a, alphaFormat);
  4426. }
  4427. hsv = this.rgb2hsv(ret.r, ret.g, ret.b);
  4428. return Ext.apply(ret, hsv);
  4429. }, isValid:function(color) {
  4430. return ColorUtils.parseColor(color) !== null;
  4431. }, getRGBAString:function(rgba) {
  4432. rgba = rgba === null ? {r:0, g:0, b:0, h:1, s:1, v:1, a:'1'} : rgba;
  4433. return 'rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + rgba.a + ')';
  4434. }, getRGBString:function(rgb) {
  4435. return 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')';
  4436. }, hsv2rgb:function(h, s, v) {
  4437. var c, hprime, x, rgb, m;
  4438. h = h > 1 ? 1 : h;
  4439. s = s > 1 ? 1 : s;
  4440. v = v > 1 ? 1 : v;
  4441. h = h === undefined ? 1 : h;
  4442. h = h * 360;
  4443. if (h === 360) {
  4444. h = 0;
  4445. }
  4446. c = v * s;
  4447. hprime = h / 60;
  4448. x = c * (1 - Math.abs(hprime % 2 - 1));
  4449. rgb = [0, 0, 0];
  4450. switch(Math.floor(hprime)) {
  4451. case 0:
  4452. rgb = [c, x, 0];
  4453. break;
  4454. case 1:
  4455. rgb = [x, c, 0];
  4456. break;
  4457. case 2:
  4458. rgb = [0, c, x];
  4459. break;
  4460. case 3:
  4461. rgb = [0, x, c];
  4462. break;
  4463. case 4:
  4464. rgb = [x, 0, c];
  4465. break;
  4466. case 5:
  4467. rgb = [c, 0, x];
  4468. break;
  4469. default:
  4470. console.error('unknown color ' + h + ' ' + s + ' ' + v);
  4471. break;
  4472. }
  4473. m = v - c;
  4474. rgb[0] += m;
  4475. rgb[1] += m;
  4476. rgb[2] += m;
  4477. rgb[0] = Math.round(rgb[0] * 255);
  4478. rgb[1] = Math.round(rgb[1] * 255);
  4479. rgb[2] = Math.round(rgb[2] * 255);
  4480. return {r:rgb[0], g:rgb[1], b:rgb[2]};
  4481. }, rgb2hsv:function(r, g, b) {
  4482. var M, m, c, hprime, h, v, s;
  4483. r = r / 255;
  4484. g = g / 255;
  4485. b = b / 255;
  4486. M = Math.max(r, g, b);
  4487. m = Math.min(r, g, b);
  4488. c = M - m;
  4489. hprime = 0;
  4490. if (c !== 0) {
  4491. if (M === r) {
  4492. hprime = (g - b) / c % 6;
  4493. } else {
  4494. if (M === g) {
  4495. hprime = (b - r) / c + 2;
  4496. } else {
  4497. if (M === b) {
  4498. hprime = (r - g) / c + 4;
  4499. }
  4500. }
  4501. }
  4502. }
  4503. h = hprime * 60;
  4504. if (h === 360) {
  4505. h = 0;
  4506. }
  4507. v = M;
  4508. s = 0;
  4509. if (c !== 0) {
  4510. s = c / v;
  4511. }
  4512. h = h / 360;
  4513. if (h < 0) {
  4514. h = h + 1;
  4515. }
  4516. return {h:h, s:s, v:v};
  4517. }, rgb2hex:function(r, g, b) {
  4518. r = r === null ? r : r.toString(16);
  4519. g = g === null ? g : g.toString(16);
  4520. b = b === null ? b : b.toString(16);
  4521. if (r === null || r.length < 2) {
  4522. r = '0' + r || '0';
  4523. }
  4524. if (g === null || g.length < 2) {
  4525. g = '0' + g || '0';
  4526. }
  4527. if (b === null || b.length < 2) {
  4528. b = '0' + b || '0';
  4529. }
  4530. if (r === null || r.length > 2) {
  4531. r = 'ff';
  4532. }
  4533. if (g === null || g.length > 2) {
  4534. g = 'ff';
  4535. }
  4536. if (b === null || b.length > 2) {
  4537. b = 'ff';
  4538. }
  4539. return (r + g + b).toUpperCase();
  4540. }, colorMap:{aliceblue:[240, 248, 255], antiquewhite:[250, 235, 215], aqua:[0, 255, 255], aquamarine:[127, 255, 212], azure:[240, 255, 255], beige:[245, 245, 220], bisque:[255, 228, 196], black:[0, 0, 0], blanchedalmond:[255, 235, 205], blue:[0, 0, 255], blueviolet:[138, 43, 226], brown:[165, 42, 42], burlywood:[222, 184, 135], cadetblue:[95, 158, 160], chartreuse:[127, 255, 0], chocolate:[210, 105, 30], coral:[255, 127, 80], cornflowerblue:[100, 149, 237], cornsilk:[255, 248, 220], crimson:[220,
  4541. 20, 60], cyan:[0, 255, 255], darkblue:[0, 0, 139], darkcyan:[0, 139, 139], darkgoldenrod:[184, 132, 11], darkgray:[169, 169, 169], darkgreen:[0, 100, 0], darkgrey:[169, 169, 169], darkkhaki:[189, 183, 107], darkmagenta:[139, 0, 139], darkolivegreen:[85, 107, 47], darkorange:[255, 140, 0], darkorchid:[153, 50, 204], darkred:[139, 0, 0], darksalmon:[233, 150, 122], darkseagreen:[143, 188, 143], darkslateblue:[72, 61, 139], darkslategray:[47, 79, 79], darkslategrey:[47, 79, 79], darkturquoise:[0,
  4542. 206, 209], darkviolet:[148, 0, 211], deeppink:[255, 20, 147], deepskyblue:[0, 191, 255], dimgray:[105, 105, 105], dimgrey:[105, 105, 105], dodgerblue:[30, 144, 255], firebrick:[178, 34, 34], floralwhite:[255, 255, 240], forestgreen:[34, 139, 34], fuchsia:[255, 0, 255], gainsboro:[220, 220, 220], ghostwhite:[248, 248, 255], gold:[255, 215, 0], goldenrod:[218, 165, 32], gray:[128, 128, 128], green:[0, 128, 0], greenyellow:[173, 255, 47], grey:[128, 128, 128], honeydew:[240, 255, 240], hotpink:[255,
  4543. 105, 180], indianred:[205, 92, 92], indigo:[75, 0, 130], ivory:[255, 255, 240], khaki:[240, 230, 140], lavender:[230, 230, 250], lavenderblush:[255, 240, 245], lawngreen:[124, 252, 0], lemonchiffon:[255, 250, 205], lightblue:[173, 216, 230], lightcoral:[240, 128, 128], lightcyan:[224, 255, 255], lightgoldenrodyellow:[250, 250, 210], lightgray:[211, 211, 211], lightgreen:[144, 238, 144], lightgrey:[211, 211, 211], lightpink:[255, 182, 193], lightsalmon:[255, 160, 122], lightseagreen:[32, 178, 170],
  4544. lightskyblue:[135, 206, 250], lightslategray:[119, 136, 153], lightslategrey:[119, 136, 153], lightsteelblue:[176, 196, 222], lightyellow:[255, 255, 224], lime:[0, 255, 0], limegreen:[50, 205, 50], linen:[250, 240, 230], magenta:[255, 0, 255], maroon:[128, 0, 0], mediumaquamarine:[102, 205, 170], mediumblue:[0, 0, 205], mediumorchid:[186, 85, 211], mediumpurple:[147, 112, 219], mediumseagreen:[60, 179, 113], mediumslateblue:[123, 104, 238], mediumspringgreen:[0, 250, 154], mediumturquoise:[72,
  4545. 209, 204], mediumvioletred:[199, 21, 133], midnightblue:[25, 25, 112], mintcream:[245, 255, 250], mistyrose:[255, 228, 225], moccasin:[255, 228, 181], navajowhite:[255, 222, 173], navy:[0, 0, 128], oldlace:[253, 245, 230], olive:[128, 128, 0], olivedrab:[107, 142, 35], orange:[255, 165, 0], orangered:[255, 69, 0], orchid:[218, 112, 214], palegoldenrod:[238, 232, 170], palegreen:[152, 251, 152], paleturquoise:[175, 238, 238], palevioletred:[219, 112, 147], papayawhip:[255, 239, 213], peachpuff:[255,
  4546. 218, 185], peru:[205, 133, 63], pink:[255, 192, 203], plum:[221, 160, 203], powderblue:[176, 224, 230], purple:[128, 0, 128], red:[255, 0, 0], rosybrown:[188, 143, 143], royalblue:[65, 105, 225], saddlebrown:[139, 69, 19], salmon:[250, 128, 114], sandybrown:[244, 164, 96], seagreen:[46, 139, 87], seashell:[255, 245, 238], sienna:[160, 82, 45], silver:[192, 192, 192], skyblue:[135, 206, 235], slateblue:[106, 90, 205], slategray:[119, 128, 144], slategrey:[119, 128, 144], snow:[255, 255, 250], springgreen:[0,
  4547. 255, 127], steelblue:[70, 130, 180], tan:[210, 180, 140], teal:[0, 128, 128], thistle:[216, 191, 216], tomato:[255, 99, 71], turquoise:[64, 224, 208], violet:[238, 130, 238], wheat:[245, 222, 179], white:[255, 255, 255], whitesmoke:[245, 245, 245], yellow:[255, 255, 0], yellowgreen:[154, 205, 5]}};
  4548. }, function(ColorUtils) {
  4549. var formats = ColorUtils.formats, lowerized = {};
  4550. formats['#HEX6'] = function(color) {
  4551. return '#' + formats.HEX6(color);
  4552. };
  4553. formats['#HEX8'] = function(color) {
  4554. return '#' + formats.HEX8(color);
  4555. };
  4556. Ext.Object.each(formats, function(name, fn) {
  4557. lowerized[name.toLowerCase()] = function(color) {
  4558. var ret = fn(color);
  4559. return ret.toLowerCase();
  4560. };
  4561. });
  4562. Ext.apply(formats, lowerized);
  4563. });
  4564. Ext.define('Ext.ux.colorpick.ColorMapController', {extend:'Ext.app.ViewController', alias:'controller.colorpickercolormapcontroller', requires:['Ext.ux.colorpick.ColorUtils'], init:function() {
  4565. var me = this, colorMap = me.getView();
  4566. me.mon(colorMap.bodyElement, {mousedown:me.onMouseDown, mouseup:me.onMouseUp, mousemove:me.onMouseMove, scope:me});
  4567. }, onHandleDrag:function(componentDragger, e) {
  4568. var me = this, container = me.getView(), dragHandle = container.down('#dragHandle').element, x = dragHandle.getX() - container.element.getX(), y = dragHandle.getY() - container.element.getY(), containerEl = container.bodyElement, containerWidth = containerEl.getWidth(), containerHeight = containerEl.getHeight(), xRatio = x / containerWidth, yRatio = y / containerHeight;
  4569. if (xRatio > 0.99) {
  4570. xRatio = 1;
  4571. }
  4572. if (yRatio > 0.99) {
  4573. yRatio = 1;
  4574. }
  4575. if (xRatio < 0) {
  4576. xRatio = 0;
  4577. }
  4578. if (yRatio < 0) {
  4579. yRatio = 0;
  4580. }
  4581. container.fireEvent('handledrag', xRatio, yRatio);
  4582. }, onMouseDown:function(e) {
  4583. var me = this;
  4584. me.onMapClick(e);
  4585. me.onHandleDrag();
  4586. me.isDragging = true;
  4587. }, onMouseUp:function(e) {
  4588. var me = this;
  4589. me.onMapClick(e);
  4590. me.onHandleDrag();
  4591. me.isDragging = false;
  4592. }, onMouseMove:function(e) {
  4593. var me = this;
  4594. if (me.isDragging) {
  4595. me.onMapClick(e);
  4596. me.onHandleDrag();
  4597. }
  4598. }, onMapClick:function(e) {
  4599. var me = this, container = me.getView(), dragHandle = container.down('#dragHandle'), cXY = container.element.getXY(), eXY = e.getXY(), left, top;
  4600. left = eXY[0] - cXY[0];
  4601. top = eXY[1] - cXY[1];
  4602. dragHandle.element.setStyle({left:left + 'px', top:top + 'px'});
  4603. e.preventDefault();
  4604. me.onHandleDrag();
  4605. }, onColorBindingChanged:function(selectedColor) {
  4606. var me = this, vm = me.getViewModel(), rgba = vm.get('selectedColor'), hsv, container = me.getView(), dragHandle = container.down('#dragHandle'), containerEl = container.bodyElement, containerWidth = containerEl.getWidth(), containerHeight = containerEl.getHeight(), xRatio, yRatio, left, top;
  4607. rgba = rgba === null ? {r:0, g:0, b:0, h:1, s:1, v:1, a:'1'} : rgba;
  4608. hsv = Ext.ux.colorpick.ColorUtils.rgb2hsv(rgba.r, rgba.g, rgba.b);
  4609. xRatio = hsv.s;
  4610. left = containerWidth * xRatio;
  4611. yRatio = 1 - hsv.v;
  4612. top = containerHeight * yRatio;
  4613. dragHandle.element.setStyle({left:left + 'px', top:top + 'px'});
  4614. }, onHueBindingChanged:function(hue) {
  4615. var me = this, fullColorRGB, hex;
  4616. fullColorRGB = Ext.ux.colorpick.ColorUtils.hsv2rgb(hue, 1, 1);
  4617. hex = Ext.ux.colorpick.ColorUtils.rgb2hex(fullColorRGB.r, fullColorRGB.g, fullColorRGB.b);
  4618. me.getView().element.applyStyles({'background-color':'#' + hex});
  4619. }});
  4620. Ext.define('Ext.ux.colorpick.ColorMap', {extend:'Ext.container.Container', alias:'widget.colorpickercolormap', controller:'colorpickercolormapcontroller', requires:['Ext.ux.colorpick.ColorMapController'], cls:Ext.baseCSSPrefix + 'colorpicker-colormap', items:[{xtype:'component', cls:Ext.baseCSSPrefix + 'colorpicker-colormap-draghandle-container', itemId:'dragHandle', width:1, height:1, style:{position:'relative'}, html:'\x3cdiv class\x3d"' + Ext.baseCSSPrefix + 'colorpicker-colormap-draghandle"\x3e\x3c/div\x3e'}],
  4621. listeners:{colorbindingchanged:{fn:'onColorBindingChanged', scope:'controller'}, huebindingchanged:{fn:'onHueBindingChanged', scope:'controller'}}, afterRender:function() {
  4622. var me = this, src = me.mapGradientUrl, el = me.el;
  4623. me.callParent();
  4624. if (!src) {
  4625. src = el.getStyle('background-image');
  4626. src = src.substring(4, src.length - 1);
  4627. if (src.indexOf('"') === 0) {
  4628. src = src.substring(1, src.length - 1);
  4629. }
  4630. Ext.ux.colorpick.ColorMap.prototype.mapGradientUrl = src;
  4631. }
  4632. el.setStyle('background-image', 'none');
  4633. el = me.bodyElement;
  4634. el.createChild({tag:'img', cls:Ext.baseCSSPrefix + 'colorpicker-colormap-blender', src:src});
  4635. }, setPosition:function(data) {
  4636. var me = this, dragHandle = me.down('#dragHandle');
  4637. if (dragHandle.isDragging) {
  4638. return;
  4639. }
  4640. this.fireEvent('colorbindingchanged', data);
  4641. }, setHue:function(hue) {
  4642. var me = this;
  4643. me.fireEvent('huebindingchanged', hue);
  4644. }});
  4645. Ext.define('Ext.ux.colorpick.SelectorModel', {extend:'Ext.app.ViewModel', alias:'viewmodel.colorpick-selectormodel', requires:['Ext.ux.colorpick.ColorUtils'], data:{selectedColor:{r:255, g:255, b:255, h:0, s:1, v:1, a:1}, previousColor:{r:0, g:0, b:0, h:0, s:1, v:1, a:1}}, formulas:{hex:{get:function(get) {
  4646. var r = get('selectedColor.r') === null ? get('selectedColor.r') : get('selectedColor.r').toString(16), g = get('selectedColor.g') === null ? get('selectedColor.g') : get('selectedColor.g').toString(16), b = get('selectedColor.b') === null ? get('selectedColor.b') : get('selectedColor.b').toString(16), result;
  4647. result = Ext.ux.colorpick.ColorUtils.rgb2hex(r, g, b);
  4648. return '#' + result;
  4649. }, set:function(hex) {
  4650. var rgb;
  4651. if (!Ext.isEmpty(hex)) {
  4652. rgb = Ext.ux.colorpick.ColorUtils.parseColor(hex);
  4653. this.changeRGB(rgb);
  4654. }
  4655. }}, red:{get:function(get) {
  4656. return get('selectedColor.r');
  4657. }, set:function(r) {
  4658. this.changeRGB({r:r});
  4659. }}, green:{get:function(get) {
  4660. return get('selectedColor.g');
  4661. }, set:function(g) {
  4662. this.changeRGB({g:g});
  4663. }}, blue:{get:function(get) {
  4664. return get('selectedColor.b');
  4665. }, set:function(b) {
  4666. this.changeRGB({b:b});
  4667. }}, hue:{get:function(get) {
  4668. return get('selectedColor.h') * 360;
  4669. }, set:function(hue) {
  4670. this.changeHSV({h:hue && hue / 360});
  4671. }}, saturation:{get:function(get) {
  4672. return get('selectedColor.s') * 100;
  4673. }, set:function(saturation) {
  4674. this.changeHSV({s:saturation && saturation / 100});
  4675. }}, value:{get:function(get) {
  4676. var v = get('selectedColor.v');
  4677. return v * 100;
  4678. }, set:function(value) {
  4679. this.changeHSV({v:value && value / 100});
  4680. }}, alpha:{get:function(data) {
  4681. var a = data('selectedColor.a');
  4682. return a * 100;
  4683. }, set:function(alpha) {
  4684. if (alpha !== null) {
  4685. this.set('selectedColor', Ext.applyIf({a:alpha / 100}, this.data.selectedColor));
  4686. }
  4687. }}}, changeHSV:function(hsv) {
  4688. var rgb;
  4689. if (hsv.h !== null && hsv.s !== null && hsv.v !== null) {
  4690. Ext.applyIf(hsv, this.data.selectedColor);
  4691. rgb = Ext.ux.colorpick.ColorUtils.hsv2rgb(hsv.h, hsv.s, hsv.v);
  4692. hsv.r = rgb.r;
  4693. hsv.g = rgb.g;
  4694. hsv.b = rgb.b;
  4695. this.set('selectedColor', hsv);
  4696. }
  4697. }, changeRGB:function(rgb) {
  4698. var hsv;
  4699. Ext.applyIf(rgb, this.data.selectedColor);
  4700. if (rgb) {
  4701. if (rgb.r !== null && rgb.g !== null && rgb.b !== null) {
  4702. hsv = Ext.ux.colorpick.ColorUtils.rgb2hsv(rgb.r, rgb.g, rgb.b);
  4703. rgb.h = hsv.h;
  4704. rgb.s = hsv.s;
  4705. rgb.v = hsv.v;
  4706. this.set('selectedColor', rgb);
  4707. }
  4708. }
  4709. }});
  4710. Ext.define('Ext.ux.colorpick.SelectorController', {extend:'Ext.app.ViewController', alias:'controller.colorpick-selectorcontroller', requires:['Ext.ux.colorpick.ColorUtils'], destroy:function() {
  4711. var me = this, view = me.getView(), childViewModel = view.childViewModel;
  4712. if (childViewModel) {
  4713. childViewModel.destroy();
  4714. view.childViewModel = null;
  4715. }
  4716. me.callParent();
  4717. }, changeHSV:function(hsv) {
  4718. var view = this.getView(), color = view.getColor(), rgb;
  4719. Ext.applyIf(hsv, color);
  4720. rgb = Ext.ux.colorpick.ColorUtils.hsv2rgb(hsv.h, hsv.s, hsv.v);
  4721. Ext.apply(hsv, rgb);
  4722. view.setColor(hsv);
  4723. }, onColorMapHandleDrag:function(xPercent, yPercent) {
  4724. this.changeHSV({s:xPercent, v:1 - yPercent});
  4725. }, onValueSliderHandleDrag:function(yPercent) {
  4726. this.changeHSV({v:1 - yPercent});
  4727. }, onSaturationSliderHandleDrag:function(yPercent) {
  4728. this.changeHSV({s:1 - yPercent});
  4729. }, onHueSliderHandleDrag:function(yPercent) {
  4730. this.changeHSV({h:1 - yPercent});
  4731. }, onAlphaSliderHandleDrag:function(yPercent) {
  4732. var view = this.getView(), color = view.getColor(), newColor = Ext.applyIf({a:1 - yPercent}, color);
  4733. view.setColor(newColor);
  4734. view.el.repaint();
  4735. }, onPreviousColorSelected:function(comp, color) {
  4736. var view = this.getView();
  4737. view.setColor(color);
  4738. }, onOK:function() {
  4739. var me = this, view = me.getView();
  4740. view.fireEvent('ok', view, view.getValue());
  4741. }, onCancel:function() {
  4742. this.fireViewEvent('cancel', this.getView());
  4743. }, onResize:function() {
  4744. var me = this, view = me.getView(), vm = view.childViewModel, refs = me.getReferences(), h, s, v, a;
  4745. h = vm.get('hue');
  4746. s = vm.get('saturation');
  4747. v = vm.get('value');
  4748. a = vm.get('alpha');
  4749. refs.colorMap.setPosition(vm.getData());
  4750. refs.hueSlider.setHue(h);
  4751. refs.satSlider.setSaturation(s);
  4752. refs.valueSlider.setValue(v);
  4753. refs.alphaSlider.setAlpha(a);
  4754. }});
  4755. Ext.define('Ext.ux.colorpick.ColorPreview', {extend:'Ext.Component', alias:'widget.colorpickercolorpreview', requires:['Ext.util.Format'], cls:Ext.baseCSSPrefix + 'colorpreview', getTemplate:function() {
  4756. return [{reference:'filterElement', cls:Ext.baseCSSPrefix + 'colorpreview-filter-el'}, {reference:'btnElement', cls:Ext.baseCSSPrefix + 'colorpreview-btn-el', tag:'a'}];
  4757. }, onRender:function() {
  4758. var me = this;
  4759. me.callParent(arguments);
  4760. me.mon(me.btnElement, 'click', me.onClick, me);
  4761. }, onClick:function(e) {
  4762. e.preventDefault();
  4763. this.fireEvent('click', this, this.color);
  4764. }, setColor:function(color) {
  4765. this.color = color;
  4766. this.applyBgStyle(color);
  4767. }, applyBgStyle:function(color) {
  4768. var me = this, colorUtils = Ext.ux.colorpick.ColorUtils, el = me.filterElement, rgba;
  4769. rgba = colorUtils.getRGBAString(color);
  4770. el.applyStyles({background:rgba});
  4771. }});
  4772. Ext.define('Ext.ux.colorpick.SliderController', {extend:'Ext.app.ViewController', alias:'controller.colorpick-slidercontroller', getDragHandle:function() {
  4773. return this.view.lookupReference('dragHandle');
  4774. }, getDragContainer:function() {
  4775. return this.view.lookupReference('dragHandleContainer');
  4776. }, onHandleDrag:function(e) {
  4777. var me = this, view = me.getView(), container = me.getDragContainer(), dragHandle = me.getDragHandle(), containerEl = container.bodyElement, top = containerEl.getY(), y = e.getY() - containerEl.getY(), containerHeight = containerEl.getHeight(), yRatio = y / containerHeight;
  4778. if (y >= 0 && y < containerHeight) {
  4779. dragHandle.element.setY(y + top);
  4780. } else {
  4781. return;
  4782. }
  4783. if (yRatio > 0.99) {
  4784. yRatio = 1;
  4785. }
  4786. e.preventDefault();
  4787. view.fireEvent('handledrag', yRatio);
  4788. dragHandle.el.repaint();
  4789. }, onMouseDown:function(e) {
  4790. var me = this, dragHandle = me.getDragHandle();
  4791. dragHandle.isDragging = true;
  4792. me.onHandleDrag(e);
  4793. }, onMouseMove:function(e) {
  4794. var me = this, dragHandle = me.getDragHandle();
  4795. if (dragHandle.isDragging) {
  4796. me.onHandleDrag(e);
  4797. }
  4798. }, onMouseUp:function(e) {
  4799. var me = this, dragHandle = me.getDragHandle();
  4800. if (dragHandle.isDragging) {
  4801. me.onHandleDrag(e);
  4802. }
  4803. dragHandle.isDragging = false;
  4804. }});
  4805. Ext.define('Ext.ux.colorpick.Slider', {extend:'Ext.container.Container', xtype:'colorpickerslider', controller:'colorpick-slidercontroller', afterRender:function() {
  4806. var width, dragCt, dragWidth;
  4807. this.callParent(arguments);
  4808. width = this.getWidth();
  4809. dragCt = this.lookupReference('dragHandleContainer');
  4810. dragWidth = dragCt.getWidth();
  4811. dragCt.el.setStyle('left', (width - dragWidth) / 4 + 'px');
  4812. }, baseCls:Ext.baseCSSPrefix + 'colorpicker-slider', requires:['Ext.ux.colorpick.SliderController'], referenceHolder:true, listeners:{element:'element', touchstart:'onMouseDown', touchend:'onMouseUp', touchmove:'onMouseMove'}, autoSize:false, items:{xtype:'container', cls:Ext.baseCSSPrefix + 'colorpicker-draghandle-container', reference:'dragHandleContainer', height:'100%', items:{xtype:'component', cls:Ext.baseCSSPrefix + 'colorpicker-draghandle-outer', style:{position:'relative'}, reference:'dragHandle',
  4813. width:'100%', height:1, html:'\x3cdiv class\x3d"' + Ext.baseCSSPrefix + 'colorpicker-draghandle"\x3e\x3c/div\x3e'}}, setHue:function() {
  4814. Ext.raise('Must implement setHue() in a child class!');
  4815. }, getDragHandle:function() {
  4816. return this.lookupReference('dragHandle');
  4817. }, getDragContainer:function() {
  4818. return this.lookupReference('dragHandleContainer');
  4819. }});
  4820. Ext.define('Ext.ux.colorpick.SliderAlpha', {extend:'Ext.ux.colorpick.Slider', alias:'widget.colorpickerslideralpha', cls:Ext.baseCSSPrefix + 'colorpicker-alpha', requires:['Ext.XTemplate'], gradientStyleTpl:Ext.create('Ext.XTemplate', 'background: -moz-linear-gradient(top, rgba({r}, {g}, {b}, 1) 0%, rgba({r}, {g}, {b}, 0) 100%);' + 'background: -webkit-linear-gradient(top,rgba({r}, {g}, {b}, 1) 0%, rgba({r}, {g}, {b}, 0) 100%);' + 'background: -o-linear-gradient(top, rgba({r}, {g}, {b}, 1) 0%, rgba({r}, {g}, {b}, 0) 100%);' +
  4821. 'background: -ms-linear-gradient(top, rgba({r}, {g}, {b}, 1) 0%, rgba({r}, {g}, {b}, 0) 100%);' + 'background: linear-gradient(to bottom, rgba({r}, {g}, {b}, 1) 0%, rgba({r}, {g}, {b}, 0) 100%);'), setAlpha:function(value) {
  4822. var me = this, container = me.getDragContainer(), dragHandle = me.getDragHandle(), containerEl = container.bodyElement, containerHeight = containerEl.getHeight(), el, top;
  4823. value = Math.max(value, 0);
  4824. value = Math.min(value, 100);
  4825. if (dragHandle.isDragging) {
  4826. return;
  4827. }
  4828. top = containerHeight * (1 - value / 100);
  4829. el = dragHandle.element;
  4830. el.setStyle({top:top + 'px'});
  4831. }, setColor:function(color) {
  4832. var me = this, container = me.getDragContainer(), hex, el;
  4833. color = color === null ? {r:0, g:0, b:0, h:1, s:1, v:1, a:'1'} : color;
  4834. hex = Ext.ux.colorpick.ColorUtils.rgb2hex(color.r, color.g, color.b);
  4835. el = container.bodyElement;
  4836. el.applyStyles(me.gradientStyleTpl.apply({hex:hex, r:color.r, g:color.g, b:color.b}));
  4837. }});
  4838. Ext.define('Ext.ux.colorpick.SliderSaturation', {extend:'Ext.ux.colorpick.Slider', alias:'widget.colorpickerslidersaturation', cls:Ext.baseCSSPrefix + 'colorpicker-saturation', gradientStyleTpl:Ext.create('Ext.XTemplate', 'background: -mox-linear-gradient(top,#{hex} 0%, #ffffff 100%);' + 'background: -webkit-linear-gradient(top, #{hex} 0%,#ffffff 100%);' + 'background: -o-linear-gradient(top, #{hex} 0%,#ffffff 100%);' + 'background: -ms-linear-gradient(top, #{hex} 0%,#ffffff 100%);' + 'background: linear-gradient(to bottom, #{hex} 0%,#ffffff 100%);'),
  4839. setSaturation:function(saturation) {
  4840. var me = this, container = me.getDragContainer(), dragHandle = me.getDragHandle(), containerEl = container.bodyElement, containerHeight = containerEl.getHeight(), yRatio, top;
  4841. saturation = Math.max(saturation, 0);
  4842. saturation = Math.min(saturation, 100);
  4843. if (dragHandle.isDragging) {
  4844. return;
  4845. }
  4846. yRatio = 1 - saturation / 100;
  4847. top = containerHeight * yRatio;
  4848. dragHandle.element.setStyle({top:top + 'px'});
  4849. }, setHue:function(hue) {
  4850. var me = this, container = me.getDragContainer(), rgb, hex;
  4851. rgb = Ext.ux.colorpick.ColorUtils.hsv2rgb(hue, 1, 1);
  4852. hex = Ext.ux.colorpick.ColorUtils.rgb2hex(rgb.r, rgb.g, rgb.b);
  4853. container.element.applyStyles(me.gradientStyleTpl.apply({hex:hex}));
  4854. }});
  4855. Ext.define('Ext.ux.colorpick.SliderValue', {extend:'Ext.ux.colorpick.Slider', alias:'widget.colorpickerslidervalue', cls:Ext.baseCSSPrefix + 'colorpicker-value', requires:['Ext.XTemplate'], gradientStyleTpl:Ext.create('Ext.XTemplate', 'background: -mox-linear-gradient(top, #{hex} 0%, #000000 100%);' + 'background: -webkit-linear-gradient(top, #{hex} 0%,#000000 100%);' + 'background: -o-linear-gradient(top, #{hex} 0%,#000000 100%);' + 'background: -ms-linear-gradient(top, #{hex} 0%,#000000 100%);' +
  4856. 'background: linear-gradient(to bottom, #{hex} 0%,#000000 100%);'), setValue:function(value) {
  4857. var me = this, container = me.getDragContainer(), dragHandle = me.getDragHandle(), containerEl = container.bodyElement, containerHeight = containerEl.getHeight(), yRatio, top;
  4858. value = Math.max(value, 0);
  4859. value = Math.min(value, 100);
  4860. if (dragHandle.isDragging) {
  4861. return;
  4862. }
  4863. yRatio = 1 - value / 100;
  4864. top = containerHeight * yRatio;
  4865. dragHandle.element.setStyle({top:top + 'px'});
  4866. }, setHue:function(hue) {
  4867. var me = this, container = me.getDragContainer(), rgb, hex;
  4868. if (!me.element) {
  4869. return;
  4870. }
  4871. rgb = Ext.ux.colorpick.ColorUtils.hsv2rgb(hue, 1, 1);
  4872. hex = Ext.ux.colorpick.ColorUtils.rgb2hex(rgb.r, rgb.g, rgb.b);
  4873. container.bodyElement.applyStyles(me.gradientStyleTpl.apply({hex:hex}));
  4874. }});
  4875. Ext.define('Ext.ux.colorpick.SliderHue', {extend:'Ext.ux.colorpick.Slider', alias:'widget.colorpickersliderhue', cls:Ext.baseCSSPrefix + 'colorpicker-hue', afterRender:function() {
  4876. var me = this, src = me.gradientUrl, el = me.el;
  4877. me.callParent();
  4878. if (!src) {
  4879. src = el.getStyle('background-image');
  4880. src = src.substring(4, src.length - 1);
  4881. if (src.indexOf('"') === 0) {
  4882. src = src.substring(1, src.length - 1);
  4883. }
  4884. Ext.ux.colorpick.SliderHue.prototype.gradientUrl = src;
  4885. }
  4886. el.setStyle('background-image', 'none');
  4887. el = me.getDragContainer().el;
  4888. el.createChild({tag:'img', cls:Ext.baseCSSPrefix + 'colorpicker-hue-gradient', src:src});
  4889. }, setHue:function(hue) {
  4890. var me = this, container = me.getDragContainer(), dragHandle = me.getDragHandle(), containerEl = container.bodyElement, containerHeight = containerEl.getHeight(), top, yRatio;
  4891. hue = hue > 1 ? hue / 360 : hue;
  4892. if (dragHandle.isDragging) {
  4893. return;
  4894. }
  4895. yRatio = 1 - hue;
  4896. top = containerHeight * yRatio;
  4897. dragHandle.element.setStyle({top:top + 'px'});
  4898. }});
  4899. Ext.define('Ext.ux.colorpick.Selector', {extend:'Ext.panel.Panel', xtype:'colorselector', mixins:['Ext.ux.colorpick.Selection'], controller:'colorpick-selectorcontroller', requires:['Ext.field.Text', 'Ext.field.Number', 'Ext.ux.colorpick.ColorMap', 'Ext.ux.colorpick.SelectorModel', 'Ext.ux.colorpick.SelectorController', 'Ext.ux.colorpick.ColorPreview', 'Ext.ux.colorpick.Slider', 'Ext.ux.colorpick.SliderAlpha', 'Ext.ux.colorpick.SliderSaturation', 'Ext.ux.colorpick.SliderValue', 'Ext.ux.colorpick.SliderHue'],
  4900. config:{hexReadOnly:false}, width:Ext.platformTags.phone ? 'auto' : 580, height:337, cls:Ext.baseCSSPrefix + 'colorpicker', padding:10, layout:{type:Ext.platformTags.phone ? 'vbox' : 'hbox', align:'stretch'}, defaultBindProperty:'value', twoWayBindable:['value', 'hidden'], fieldWidth:50, fieldPad:5, showPreviousColor:false, okButtonText:'OK', cancelButtonText:'Cancel', showOkCancelButtons:false, listeners:{resize:'onResize', show:'onResize'}, initConfig:function(config) {
  4901. var me = this, childViewModel = Ext.Factory.viewModel('colorpick-selectormodel');
  4902. me.childViewModel = childViewModel;
  4903. if (Ext.platformTags.phone && !(Ext.Viewport.getOrientation() === 'landscape')) {
  4904. me.fieldWidth = 35;
  4905. }
  4906. if (Ext.platformTags.phone) {
  4907. config.items = [me.getPreviewForMobile(childViewModel, config), {xtype:'container', padding:'4px 0 0 0', layout:{type:'hbox', align:'stretch'}, flex:1, items:[me.getMapAndHexRGBFields(childViewModel), me.getSliderAndHField(childViewModel), me.getSliderAndSField(childViewModel), me.getSliderAndVField(childViewModel), me.getSliderAndAField(childViewModel)]}, me.getButtonForMobile(childViewModel, config)];
  4908. } else {
  4909. config.items = [me.getMapAndHexRGBFields(childViewModel), me.getSliderAndHField(childViewModel), me.getSliderAndSField(childViewModel), me.getSliderAndVField(childViewModel), me.getSliderAndAField(childViewModel), me.getPreviewAndButtons(childViewModel, config)];
  4910. }
  4911. me.childViewModel.bind('{selectedColor}', function(color) {
  4912. me.setColor(color);
  4913. });
  4914. this.callParent(arguments);
  4915. }, updateColor:function(color) {
  4916. var me = this;
  4917. me.mixins.colorselection.updateColor.call(me, color);
  4918. me.childViewModel.set('selectedColor', color);
  4919. }, updatePreviousColor:function(color) {
  4920. this.childViewModel.set('previousColor', color);
  4921. }, getMapAndHexRGBFields:function(childViewModel) {
  4922. var me = this, fieldMargin = '0 ' + me.fieldPad + ' 0 0', fieldWidth = me.fieldWidth;
  4923. return {xtype:'container', viewModel:childViewModel, cls:Ext.baseCSSPrefix + 'colorpicker-escape-overflow', flex:1, autoSize:false, layout:{type:'vbox', constrainAlign:true}, margin:'0 10 0 0', items:[{xtype:'colorpickercolormap', reference:'colorMap', flex:1, bind:{position:{bindTo:'{selectedColor}', deep:true}, hue:'{selectedColor.h}'}, listeners:{handledrag:'onColorMapHandleDrag'}}, {xtype:'container', layout:'hbox', autoSize:null, defaults:{labelAlign:'top', allowBlank:false}, items:[{xtype:'textfield',
  4924. label:'HEX', flex:1, bind:'{hex}', clearable:Ext.platformTags.phone ? false : true, margin:fieldMargin, validators:/^#[0-9a-f]{6}$/i, readOnly:me.getHexReadOnly(), required:true}, {xtype:'numberfield', clearable:false, label:'R', bind:'{red}', width:fieldWidth, hideTrigger:true, validators:/^(0|[1-9]\d*)$/i, maxValue:255, minValue:0, margin:fieldMargin, required:true}, {xtype:'numberfield', clearable:false, label:'G', bind:'{green}', width:fieldWidth, hideTrigger:true, validators:/^(0|[1-9]\d*)$/i,
  4925. maxValue:255, minValue:0, margin:fieldMargin, required:true}, {xtype:'numberfield', clearable:false, label:'B', bind:'{blue}', width:fieldWidth, hideTrigger:true, validators:/^(0|[1-9]\d*)$/i, maxValue:255, minValue:0, margin:0, required:true}]}]};
  4926. }, getSliderAndHField:function(childViewModel) {
  4927. var me = this, fieldWidth = me.fieldWidth;
  4928. return {xtype:'container', viewModel:childViewModel, cls:Ext.baseCSSPrefix + 'colorpicker-escape-overflow', width:fieldWidth, layout:{type:'vbox', align:'stretch'}, items:[{xtype:'colorpickersliderhue', reference:'hueSlider', flex:1, bind:{hue:'{selectedColor.h}'}, width:fieldWidth, listeners:{handledrag:'onHueSliderHandleDrag'}}, {xtype:'numberfield', reference:'hnumberfield', clearable:false, label:'H', labelAlign:'top', bind:'{hue}', hideTrigger:true, maxValue:360, minValue:0, allowBlank:false,
  4929. margin:0, required:true}]};
  4930. }, getSliderAndSField:function(childViewModel) {
  4931. var me = this, fieldWidth = me.fieldWidth, fieldPad = me.fieldPad;
  4932. return {xtype:'container', viewModel:childViewModel, cls:[Ext.baseCSSPrefix + 'colorpicker-escape-overflow', Ext.baseCSSPrefix + 'colorpicker-column-sslider'], width:fieldWidth, layout:{type:'vbox', align:'stretch'}, margin:'0 ' + fieldPad + ' 0 ' + fieldPad, items:[{xtype:'colorpickerslidersaturation', reference:'satSlider', flex:1, bind:{saturation:'{saturation}', hue:'{selectedColor.h}'}, width:fieldWidth, listeners:{handledrag:'onSaturationSliderHandleDrag'}}, {xtype:'numberfield', reference:'snumberfield',
  4933. clearable:false, label:'S', labelAlign:'top', bind:'{saturation}', hideTrigger:true, maxValue:100, minValue:0, allowBlank:false, margin:0, required:true}]};
  4934. }, getSliderAndVField:function(childViewModel) {
  4935. var me = this, fieldWidth = me.fieldWidth;
  4936. return {xtype:'container', viewModel:childViewModel, cls:[Ext.baseCSSPrefix + 'colorpicker-escape-overflow', Ext.baseCSSPrefix + 'colorpicker-column-vslider'], width:fieldWidth, layout:{type:'vbox', align:'stretch'}, items:[{xtype:'colorpickerslidervalue', reference:'valueSlider', flex:1, bind:{value:'{value}', hue:'{selectedColor.h}'}, width:fieldWidth, listeners:{handledrag:'onValueSliderHandleDrag'}}, {xtype:'numberfield', reference:'vnumberfield', clearable:false, label:'V', labelAlign:'top',
  4937. bind:'{value}', hideTrigger:true, maxValue:100, minValue:0, allowBlank:false, margin:0, required:true}]};
  4938. }, getSliderAndAField:function(childViewModel) {
  4939. var me = this, fieldWidth = me.fieldWidth;
  4940. return {xtype:'container', viewModel:childViewModel, cls:Ext.baseCSSPrefix + 'colorpicker-escape-overflow', width:fieldWidth, layout:{type:'vbox', align:'stretch'}, margin:'0 0 0 ' + me.fieldPad, items:[{xtype:'colorpickerslideralpha', reference:'alphaSlider', flex:1, bind:{alpha:'{alpha}', color:{bindTo:'{selectedColor}', deep:true}}, width:fieldWidth, listeners:{handledrag:'onAlphaSliderHandleDrag'}}, {xtype:'numberfield', reference:'anumberfield', clearable:false, label:'A', labelAlign:'top',
  4941. bind:'{alpha}', hideTrigger:true, maxValue:100, minValue:0, allowBlank:false, margin:0, required:true}]};
  4942. }, getPreviewAndButtons:function(childViewModel, config) {
  4943. var items = [{xtype:'colorpickercolorpreview', flex:1, bind:{color:{bindTo:'{selectedColor}', deep:true}}}];
  4944. if (config.showPreviousColor) {
  4945. items.push({xtype:'colorpickercolorpreview', flex:1, bind:{color:{bindTo:'{previousColor}', deep:true}}, listeners:{click:'onPreviousColorSelected'}});
  4946. }
  4947. if (config.showOkCancelButtons) {
  4948. items.push({xtype:'button', text:this.okButtonText, margin:'10 0 0 0', handler:'onOK'}, {xtype:'button', text:this.cancelButtonText, margin:'10 0 0 0', handler:'onCancel'});
  4949. }
  4950. return {xtype:'container', viewModel:childViewModel, cls:Ext.baseCSSPrefix + 'colorpicker-column-preview', width:70, margin:'0 0 0 10', items:items, layout:{type:'vbox', align:'stretch'}};
  4951. }, getPreviewForMobile:function(childViewModel, config) {
  4952. var items = [{xtype:'colorpickercolorpreview', flex:1, bind:{color:{bindTo:'{selectedColor}', deep:true}}}];
  4953. if (config.showPreviousColor) {
  4954. items.push({xtype:'colorpickercolorpreview', flex:1, bind:{color:{bindTo:'{previousColor}', deep:true}}, listeners:{click:'onPreviousColorSelected'}});
  4955. }
  4956. return {xtype:'container', viewModel:childViewModel, cls:Ext.baseCSSPrefix + 'colorpicker-column-mobile-preview', height:40, margin:'10 0 10 0', items:items, layout:{type:'hbox', align:'stretch'}};
  4957. }, getButtonForMobile:function(childViewModel, config) {
  4958. var items = [];
  4959. if (config.showOkCancelButtons) {
  4960. items.push({xtype:'container', flex:1}, {xtype:'button', text:this.cancelButtonText, minWidth:70, margin:'5 5 0 5', handler:'onCancel'}, {xtype:'button', text:this.okButtonText, margin:'5 5 0 5', minWidth:50, handler:'onOK'});
  4961. return {xtype:'container', viewModel:childViewModel, cls:Ext.baseCSSPrefix + 'colorpicker-column-mobile-button', width:'100%', height:40, margin:'0', align:'right', items:items, layout:{type:'hbox', align:'stretch'}};
  4962. }
  4963. return {};
  4964. }});
  4965. Ext.define('Ext.ux.colorpick.ButtonController', {extend:'Ext.app.ViewController', alias:'controller.colorpick-buttoncontroller', requires:['Ext.Dialog', 'Ext.ux.colorpick.Selector', 'Ext.ux.colorpick.ColorUtils'], afterRender:function(view) {
  4966. view.updateColor(view.getColor());
  4967. }, destroy:function() {
  4968. var view = this.getView(), colorPickerWindow = view.colorPickerWindow;
  4969. if (colorPickerWindow) {
  4970. colorPickerWindow.destroy();
  4971. view.colorPickerWindow = view.colorPicker = null;
  4972. }
  4973. this.callParent();
  4974. }, getPopup:function() {
  4975. var view = this.getView(), popup = view.colorPickerWindow, selector;
  4976. if (!popup) {
  4977. popup = Ext.create(view.getPopup());
  4978. view.colorPickerWindow = popup;
  4979. popup.colorPicker = view.colorPicker = selector = popup.lookupReference('selector');
  4980. selector.setFormat(view.getFormat());
  4981. selector.on({ok:'onColorPickerOK', cancel:'onColorPickerCancel', scope:this});
  4982. popup.on({close:'onColorPickerCancel', scope:this});
  4983. }
  4984. return popup;
  4985. }, onClick:function() {
  4986. var me = this, view = me.getView(), color = view.getColor(), popup = me.getPopup(), colorPicker = popup.colorPicker;
  4987. colorPicker.setColor(color);
  4988. colorPicker.setPreviousColor(color);
  4989. popup.show();
  4990. }, onColorPickerOK:function(picker) {
  4991. var view = this.getView(), color = picker.getColor(), cpWin = view.colorPickerWindow;
  4992. cpWin.hide();
  4993. view.setColor(color);
  4994. }, onColorPickerCancel:function() {
  4995. var view = this.getView(), cpWin = view.colorPickerWindow;
  4996. cpWin.hide();
  4997. }, syncColor:function(color) {
  4998. var view = this.getView();
  4999. Ext.ux.colorpick.ColorUtils.setBackground(view.filterEl, color);
  5000. }});
  5001. Ext.define('Ext.ux.colorpick.Button', {extend:'Ext.Component', xtype:'colorbutton', controller:'colorpick-buttoncontroller', mixins:['Ext.ux.colorpick.Selection'], requires:['Ext.ux.colorpick.ButtonController'], baseCls:Ext.baseCSSPrefix + 'colorpicker-button', width:20, height:20, childEls:['btnEl', 'filterEl'], config:{popup:{lazy:true, $value:{xtype:'dialog', closeAction:'hide', referenceHolder:true, header:false, resizable:true, scrollable:true, items:{xtype:'colorselector', reference:'selector',
  5002. flex:'1 1 auto', showPreviousColor:true, showOkCancelButtons:true}}}}, defaultBindProperty:'value', twoWayBindable:'value', getTemplate:function() {
  5003. return [{reference:'filterEl', cls:Ext.baseCSSPrefix + 'colorbutton-filter-el'}, {reference:'btnEl', tag:'a', cls:Ext.baseCSSPrefix + 'colorbutton-btn-el'}];
  5004. }, listeners:{click:'onClick', element:'btnEl'}, updateColor:function(color) {
  5005. var me = this, cp = me.colorPicker;
  5006. me.mixins.colorselection.updateColor.call(me, color);
  5007. Ext.ux.colorpick.ColorUtils.setBackground(me.filterEl, color);
  5008. if (cp) {
  5009. cp.setColor(color);
  5010. }
  5011. }, updateFormat:function(format) {
  5012. var cp = this.colorPicker;
  5013. if (cp) {
  5014. cp.setFormat(format);
  5015. }
  5016. }});
  5017. Ext.define('Ext.ux.colorpick.Field', {extend:'Ext.field.Picker', xtype:'colorfield', mixins:['Ext.ux.colorpick.Selection'], requires:['Ext.window.Window', 'Ext.ux.colorpick.Selector', 'Ext.ux.colorpick.ColorUtils'], editable:false, focusable:true, matchFieldWidth:false, html:['\x3cdiv class\x3d"' + Ext.baseCSSPrefix + 'colorpicker-field-swatch"\x3e' + '\x3cdiv class\x3d"' + Ext.baseCSSPrefix + 'colorpicker-field-swatch-inner"\x3e\x3c/div\x3e' + '\x3c/div\x3e'], cls:Ext.baseCSSPrefix + 'colorpicker-field',
  5018. config:{popup:{lazy:true, $value:{xtype:'window', closeAction:'hide', modal:Ext.platformTags.phone ? true : false, referenceHolder:true, width:Ext.platformTags.phone ? '100%' : 'auto', layout:Ext.platformTags.phone ? 'hbox' : 'vbox', header:false, resizable:true, scrollable:true, items:{xtype:'colorselector', reference:'selector', flex:'1 1 auto', showPreviousColor:true, showOkCancelButtons:true}}}}, afterRender:function() {
  5019. this.callParent();
  5020. this.updateValue(this.value);
  5021. }, createFloatedPicker:function() {
  5022. var me = this, popup = me.getPopup(), picker;
  5023. me.colorPickerWindow = popup = Ext.create(popup);
  5024. picker = me.colorPicker = popup.lookupReference('selector');
  5025. picker.setColor(me.getColor());
  5026. picker.setHexReadOnly(!me.editable);
  5027. picker.on({ok:'onColorPickerOK', cancel:'onColorPickerCancel', close:'onColorPickerCancel', scope:me});
  5028. me.colorPicker.ownerCmp = me;
  5029. return me.colorPickerWindow;
  5030. }, createEdgePicker:function() {
  5031. var me = this, popup = me.getPopup(), picker;
  5032. me.colorPickerWindow = popup = Ext.create(popup);
  5033. picker = me.colorPicker = popup.lookupReference('selector');
  5034. me.pickerType = 'floated';
  5035. picker.setColor(me.getColor());
  5036. picker.on({ok:'onColorPickerOK', cancel:'onColorPickerCancel', close:'onColorPickerCancel', scope:me});
  5037. me.colorPicker.ownerCmp = me;
  5038. return me.colorPickerWindow;
  5039. }, collapse:function() {
  5040. var picker = this.getPicker();
  5041. if (this.expanded) {
  5042. picker.hide();
  5043. }
  5044. }, showPicker:function() {
  5045. var me = this, alignTarget = me[me.alignTarget], picker = me.getPicker(), color = this.getColor();
  5046. if (this.colorPicker) {
  5047. this.colorPicker.setColor(this.getColor());
  5048. this.colorPicker.setPreviousColor(color);
  5049. }
  5050. if (me.getMatchFieldWidth()) {
  5051. picker.setWidth(alignTarget.getWidth());
  5052. }
  5053. if (Ext.platformTags.phone) {
  5054. picker.show();
  5055. } else {
  5056. picker.showBy(alignTarget, me.getFloatedPickerAlign(), {minHeight:100});
  5057. }
  5058. me.touchListeners = Ext.getDoc().on({translate:false, touchstart:me.collapseIf, scope:me, delegated:false, destroyable:true});
  5059. }, onFocusLeave:function(e) {
  5060. if (e.type !== 'focusenter') {
  5061. this.callParent(arguments);
  5062. }
  5063. }, onColorPickerOK:function(colorPicker) {
  5064. this.setColor(colorPicker.getColor());
  5065. this.collapse();
  5066. }, onColorPickerCancel:function() {
  5067. this.collapse();
  5068. }, onExpandTap:function() {
  5069. var color = this.getColor();
  5070. if (this.colorPicker) {
  5071. this.colorPicker.setPreviousColor(color);
  5072. }
  5073. this.callParent(arguments);
  5074. }, setValue:function(color) {
  5075. var me = this, c;
  5076. if (Ext.ux.colorpick.ColorUtils.isValid(color)) {
  5077. c = me.mixins.colorselection.applyValue.call(me, color);
  5078. me.callParent([c]);
  5079. }
  5080. }, updateFormat:function(format) {
  5081. var cp = this.colorPicker;
  5082. if (cp) {
  5083. cp.setFormat(format);
  5084. }
  5085. }, updateValue:function(color) {
  5086. var me = this, swatchEl = this.element.down('.x-colorpicker-field-swatch-inner'), c;
  5087. if (!me.syncing) {
  5088. me.syncing = true;
  5089. me.setColor(color);
  5090. me.syncing = false;
  5091. }
  5092. c = me.getColor();
  5093. Ext.ux.colorpick.ColorUtils.setBackground(swatchEl, c);
  5094. if (me.colorPicker) {
  5095. me.colorPicker.setColor(c);
  5096. }
  5097. me.inputElement.dom.value = me.getValue();
  5098. }, validator:function(val) {
  5099. if (!Ext.ux.colorpick.ColorUtils.isValid(val)) {
  5100. return this.invalidText;
  5101. }
  5102. return true;
  5103. }, updateColor:function(color) {
  5104. var me = this, cp = me.colorPicker, swatchEl = this.element.down('.x-colorpicker-field-swatch-inner');
  5105. me.mixins.colorselection.updateColor.call(me, color);
  5106. Ext.ux.colorpick.ColorUtils.setBackground(swatchEl, color);
  5107. if (cp) {
  5108. cp.setColor(color);
  5109. }
  5110. }});