mobisroll-1412.js 154 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498
  1. //**mobiscroll.core.js
  2. /*!
  3. * Mobiscroll v2.17.1
  4. * http://mobiscroll.com
  5. *
  6. * Copyright 2010-2015, Acid Media
  7. * Licensed under the MIT license.
  8. *
  9. */
  10. (function ($, undefined) {
  11. function testProps(props) {
  12. var i;
  13. for (i in props) {
  14. if (mod[props[i]] !== undefined) {
  15. return true;
  16. }
  17. }
  18. return false;
  19. }
  20. function testPrefix() {
  21. var prefixes = ['Webkit', 'Moz', 'O', 'ms'],
  22. p;
  23. for (p in prefixes) {
  24. if (testProps([prefixes[p] + 'Transform'])) {
  25. return '-' + prefixes[p].toLowerCase() + '-';
  26. }
  27. }
  28. return '';
  29. }
  30. function init(that, options, args) {
  31. var ret = that;
  32. // Init
  33. if (typeof options === 'object') {
  34. return that.each(function () {
  35. if (instances[this.id]) {
  36. instances[this.id].destroy();
  37. }
  38. new $.mobiscroll.classes[options.component || 'Scroller'](this, options);
  39. });
  40. }
  41. // Method call
  42. if (typeof options === 'string') {
  43. that.each(function () {
  44. var r,
  45. inst = instances[this.id];
  46. if (inst && inst[options]) {
  47. r = inst[options].apply(this, Array.prototype.slice.call(args, 1));
  48. if (r !== undefined) {
  49. ret = r;
  50. return false;
  51. }
  52. }
  53. });
  54. }
  55. return ret;
  56. }
  57. var ms,
  58. id = +new Date(),
  59. instances = {},
  60. extend = $.extend,
  61. mod = document.createElement('modernizr').style,
  62. has3d = testProps(['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']),
  63. hasFlex = testProps(['flex', 'msFlex', 'WebkitBoxDirection']),
  64. prefix = testPrefix(),
  65. pr = prefix.replace(/^\-/, '').replace(/\-$/, '').replace('moz', 'Moz');
  66. $.fn.mobiscroll = function (method) {
  67. extend(this, $.mobiscroll.components);
  68. return init(this, method, arguments);
  69. };
  70. ms = $.mobiscroll = $.mobiscroll || {
  71. version: '2.17.1',
  72. util: {
  73. prefix: prefix,
  74. jsPrefix: pr,
  75. has3d: has3d,
  76. hasFlex: hasFlex,
  77. isOldAndroid: /android [1-3]/i.test(navigator.userAgent),
  78. preventClick: function () {
  79. // Prevent ghost click
  80. ms.tapped++;
  81. setTimeout(function () {
  82. ms.tapped--;
  83. }, 500);
  84. },
  85. testTouch: function (e, elm) {
  86. if (e.type == 'touchstart') {
  87. $(elm).attr('data-touch', '1');
  88. } else if ($(elm).attr('data-touch')) {
  89. $(elm).removeAttr('data-touch');
  90. return false;
  91. }
  92. return true;
  93. },
  94. objectToArray: function (obj) {
  95. var arr = [],
  96. i;
  97. for (i in obj) {
  98. arr.push(obj[i]);
  99. }
  100. return arr;
  101. },
  102. arrayToObject: function (arr) {
  103. var obj = {},
  104. i;
  105. if (arr) {
  106. for (i = 0; i < arr.length; i++) {
  107. obj[arr[i]] = arr[i];
  108. }
  109. }
  110. return obj;
  111. },
  112. isNumeric: function (a) {
  113. return a - parseFloat(a) >= 0;
  114. },
  115. isString: function (s) {
  116. return typeof s === 'string';
  117. },
  118. getCoord: function (e, c, page) {
  119. var ev = e.originalEvent || e,
  120. prop = (page ? 'page' : 'client') + c;
  121. return ev.changedTouches ? ev.changedTouches[0][prop] : e[prop];
  122. },
  123. getPosition: function (t, vertical) {
  124. var style = window.getComputedStyle ? getComputedStyle(t[0]) : t[0].style,
  125. matrix,
  126. px;
  127. if (has3d) {
  128. $.each(['t', 'webkitT', 'MozT', 'OT', 'msT'], function (i, v) {
  129. if (style[v + 'ransform'] !== undefined) {
  130. matrix = style[v + 'ransform'];
  131. return false;
  132. }
  133. });
  134. matrix = matrix.split(')')[0].split(', ');
  135. px = vertical ? (matrix[13] || matrix[5]) : (matrix[12] || matrix[4]);
  136. } else {
  137. px = vertical ? style.top.replace('px', '') : style.left.replace('px', '');
  138. }
  139. return px;
  140. },
  141. addIcon: function ($control, ic) {
  142. var icons = {},
  143. $parent = $control.parent(),
  144. errorMsg = $parent.find('.mbsc-err-msg'),
  145. align = $control.attr('data-icon-align') || 'left',
  146. icon = $control.attr('data-icon');
  147. // Wrap input
  148. $('<span class="mbsc-input-wrap"></span>').insertAfter($control).append($control);
  149. if (errorMsg) {
  150. $parent.find('.mbsc-input-wrap').append(errorMsg);
  151. }
  152. if (icon) {
  153. if (icon.indexOf('{') !== -1) {
  154. icons = JSON.parse(icon);
  155. } else {
  156. icons[align] = icon;
  157. }
  158. extend(icons, ic);
  159. $parent
  160. .addClass((icons.right ? 'mbsc-ic-right ' : '') + (icons.left ? ' mbsc-ic-left' : ''))
  161. .find('.mbsc-input-wrap')
  162. .append(icons.left ? '<span class="mbsc-input-ic mbsc-left-ic mbsc-ic mbsc-ic-' + icons.left + '"></span>' : '')
  163. .append(icons.right ? '<span class="mbsc-input-ic mbsc-right-ic mbsc-ic mbsc-ic-' + icons.right + '"></span>' : '');
  164. }
  165. },
  166. constrain: function (val, min, max) {
  167. return Math.max(min, Math.min(val, max));
  168. },
  169. vibrate: function (time) {
  170. if ('vibrate' in navigator) {
  171. navigator.vibrate(time || 50);
  172. }
  173. }
  174. },
  175. tapped: 0,
  176. autoTheme: 'mobiscroll',
  177. presets: {
  178. scroller: {},
  179. numpad: {},
  180. listview: {},
  181. menustrip: {}
  182. },
  183. themes: {
  184. form: {},
  185. frame: {},
  186. listview: {},
  187. menustrip: {},
  188. progress: {}
  189. },
  190. i18n: {},
  191. instances: instances,
  192. classes: {},
  193. components: {},
  194. defaults: {
  195. context: 'body',
  196. mousewheel: true,
  197. vibrate: true
  198. },
  199. setDefaults: function (o) {
  200. extend(this.defaults, o);
  201. },
  202. presetShort: function (name, c, p) {
  203. this.components[name] = function (s) {
  204. return init(this, extend(s, {
  205. component: c,
  206. preset: p === false ? undefined : name
  207. }), arguments);
  208. };
  209. }
  210. };
  211. $.mobiscroll.classes.Base = function (el, settings) {
  212. var lang,
  213. preset,
  214. s,
  215. theme,
  216. themeName,
  217. defaults,
  218. ms = $.mobiscroll,
  219. util = ms.util,
  220. getCoord = util.getCoord,
  221. that = this;
  222. that.settings = {};
  223. that._presetLoad = function () {};
  224. that._init = function (ss) {
  225. s = that.settings;
  226. // Update original user settings
  227. extend(settings, ss);
  228. // Load user defaults
  229. if (that._hasDef) {
  230. defaults = ms.defaults;
  231. }
  232. // Create settings object
  233. extend(s, that._defaults, defaults, settings);
  234. // Get theme defaults
  235. if (that._hasTheme) {
  236. themeName = s.theme;
  237. if (themeName == 'auto' || !themeName) {
  238. themeName = ms.autoTheme;
  239. }
  240. if (themeName == 'default') {
  241. themeName = 'mobiscroll';
  242. }
  243. settings.theme = themeName;
  244. theme = ms.themes[that._class] ? ms.themes[that._class][themeName] : {};
  245. }
  246. // Get language defaults
  247. if (that._hasLang) {
  248. lang = ms.i18n[s.lang];
  249. }
  250. if (that._hasTheme) {
  251. that.trigger('onThemeLoad', [lang, settings]);
  252. }
  253. // Update settings object
  254. extend(s, theme, lang, defaults, settings);
  255. // Load preset settings
  256. if (that._hasPreset) {
  257. that._presetLoad(s);
  258. preset = ms.presets[that._class][s.preset];
  259. if (preset) {
  260. preset = preset.call(el, that);
  261. extend(s, preset, settings);
  262. }
  263. }
  264. };
  265. that._destroy = function () {
  266. that.trigger('onDestroy', []);
  267. // Delete scroller instance
  268. delete instances[el.id];
  269. that = null;
  270. };
  271. /**
  272. * Attach tap event to the given element.
  273. */
  274. that.tap = function (el, handler, prevent) {
  275. var startX,
  276. startY,
  277. target,
  278. moved;
  279. function onStart(ev) {
  280. if (!target) {
  281. // Can't always call preventDefault here, it kills page scroll
  282. if (prevent) {
  283. ev.preventDefault();
  284. }
  285. target = this;
  286. startX = getCoord(ev, 'X');
  287. startY = getCoord(ev, 'Y');
  288. moved = false;
  289. if (ev.type == 'pointerdown') {
  290. $(document)
  291. .on('pointermove', onMove)
  292. .on('pointerup', onEnd);
  293. }
  294. }
  295. }
  296. function onMove(ev) {
  297. // If movement is more than 20px, don't fire the click event handler
  298. if (target && !moved && Math.abs(getCoord(ev, 'X') - startX) > 9 || Math.abs(getCoord(ev, 'Y') - startY) > 9) {
  299. moved = true;
  300. }
  301. }
  302. function onEnd(ev) {
  303. if (target) {
  304. if (!moved) {
  305. ev.preventDefault();
  306. handler.call(target, ev, that);
  307. }
  308. if (ev.type == 'pointerup') {
  309. $(document)
  310. .off('pointermove', onMove)
  311. .off('pointerup', onEnd);
  312. }
  313. target = false;
  314. util.preventClick();
  315. }
  316. }
  317. function onCancel() {
  318. target = false;
  319. }
  320. if (s.tap) {
  321. el
  322. .on('touchstart.dw pointerdown.dw', onStart)
  323. .on('touchcancel.dw pointercancel.dw', onCancel)
  324. .on('touchmove.dw', onMove)
  325. .on('touchend.dw', onEnd);
  326. }
  327. el.on('click.dw', function (ev) {
  328. ev.preventDefault();
  329. // If handler was not called on touchend, call it on click;
  330. handler.call(this, ev, that);
  331. });
  332. };
  333. /**
  334. * Triggers an event
  335. */
  336. that.trigger = function (name, args) {
  337. var ret;
  338. args.push(that);
  339. $.each([defaults, theme, preset, settings], function (i, v) {
  340. if (v && v[name]) { // Call preset event
  341. ret = v[name].apply(el, args);
  342. }
  343. });
  344. return ret;
  345. };
  346. /**
  347. * Sets one ore more options.
  348. */
  349. that.option = function (opt, value) {
  350. var obj = {};
  351. if (typeof opt === 'object') {
  352. obj = opt;
  353. } else {
  354. obj[opt] = value;
  355. }
  356. that.init(obj);
  357. };
  358. /**
  359. * Returns the mobiscroll instance.
  360. */
  361. that.getInst = function () {
  362. return that;
  363. };
  364. settings = settings || {};
  365. $(el).addClass('mbsc-comp');
  366. // Autogenerate id
  367. if (!el.id) {
  368. el.id = 'mobiscroll' + (++id);
  369. }
  370. // Save instance
  371. instances[el.id] = that;
  372. };
  373. // Prevent standard behaviour on body click
  374. function preventClick(ev) {
  375. // Textarea needs the mousedown event
  376. if (ms.tapped && !ev.tap && !(ev.target.nodeName == 'TEXTAREA' && ev.type == 'mousedown')) {
  377. ev.stopPropagation();
  378. ev.preventDefault();
  379. return false;
  380. }
  381. }
  382. if (document.addEventListener) {
  383. $.each(['mouseover', 'mousedown', 'mouseup', 'click'], function (i, ev) {
  384. document.addEventListener(ev, preventClick, true);
  385. });
  386. }
  387. })(jQuery);
  388. //**mobiscroll.frame.js
  389. (function ($, window, document, undefined) {
  390. var $activeElm,
  391. preventShow,
  392. ms = $.mobiscroll,
  393. util = ms.util,
  394. pr = util.jsPrefix,
  395. has3d = util.has3d,
  396. constrain = util.constrain,
  397. isString = util.isString,
  398. isOldAndroid = util.isOldAndroid,
  399. isIOS8 = /(iphone|ipod|ipad).* os 8_/i.test(navigator.userAgent),
  400. animEnd = 'webkitAnimationEnd animationend',
  401. empty = function () {},
  402. prevdef = function (ev) {
  403. ev.preventDefault();
  404. };
  405. ms.classes.Frame = function (el, settings, inherit) {
  406. var $ariaDiv,
  407. $ctx,
  408. $header,
  409. $markup,
  410. $overlay,
  411. $persp,
  412. $popup,
  413. $wnd,
  414. $wrapper,
  415. buttons,
  416. btn,
  417. doAnim,
  418. event,
  419. hasButtons,
  420. isModal,
  421. modalWidth,
  422. modalHeight,
  423. posEvents,
  424. preventPos,
  425. s,
  426. scrollLock,
  427. setReadOnly,
  428. wndWidth,
  429. wndHeight,
  430. that = this,
  431. $elm = $(el),
  432. elmList = [],
  433. posDebounce = {};
  434. function onBtnStart(ev) {
  435. // Can't call preventDefault here, it kills page scroll
  436. if (btn) {
  437. btn.removeClass('dwb-a');
  438. }
  439. btn = $(this);
  440. // Active button
  441. if (!btn.hasClass('dwb-d') && !btn.hasClass('dwb-nhl')) {
  442. btn.addClass('dwb-a');
  443. }
  444. if (ev.type === 'mousedown') {
  445. $(document).on('mouseup', onBtnEnd);
  446. } else if (ev.type === 'pointerdown') {
  447. $(document).on('pointerup', onBtnEnd);
  448. }
  449. }
  450. function onBtnEnd(ev) {
  451. if (btn) {
  452. btn.removeClass('dwb-a');
  453. btn = null;
  454. }
  455. if (ev.type === 'mouseup') {
  456. $(document).off('mouseup', onBtnEnd);
  457. } else if (ev.type === 'pointerup') {
  458. $(document).off('pointerup', onBtnEnd);
  459. }
  460. }
  461. function onWndKeyDown(ev) {
  462. if (ev.keyCode == 13) {
  463. that.select();
  464. } else if (ev.keyCode == 27) {
  465. that.cancel();
  466. }
  467. }
  468. function onShow(prevFocus) {
  469. if (!prevFocus) {
  470. $popup.focus();
  471. }
  472. that.ariaMessage(s.ariaMessage);
  473. }
  474. function onHide(prevAnim) {
  475. var activeEl,
  476. value,
  477. type,
  478. focus = s.focusOnClose;
  479. setTimeout(function(){
  480. that._markupRemove();
  481. $markup.remove();
  482. },500);
  483. if ($activeElm && !prevAnim) {
  484. setTimeout(function () {
  485. if (focus === undefined || focus === true) {
  486. preventShow = true;
  487. activeEl = $activeElm[0];
  488. type = activeEl.type;
  489. value = activeEl.value;
  490. try {
  491. activeEl.type = 'button';
  492. } catch (ex) {}
  493. $activeElm.focus();
  494. activeEl.type = type;
  495. activeEl.value = value;
  496. } else if (focus) {
  497. $(focus).focus();
  498. }
  499. }, 200);
  500. }
  501. that._isVisible = false;
  502. event('onHide', []);
  503. }
  504. function onPosition(ev) {
  505. clearTimeout(posDebounce[ev.type]);
  506. posDebounce[ev.type] = setTimeout(function () {
  507. var isScroll = ev.type == 'scroll';
  508. if (isScroll && !scrollLock) {
  509. return;
  510. }
  511. that.position(!isScroll);
  512. }, 200);
  513. }
  514. function onFocus(ev) {
  515. if (ev.target.nodeType && !$popup[0].contains(ev.target)) {
  516. $popup.focus();
  517. }
  518. }
  519. function onBlur() {
  520. $(this).off('blur', onBlur);
  521. setTimeout(function () {
  522. that.position();
  523. }, 100);
  524. }
  525. function show(beforeShow, $elm) {
  526. if (beforeShow) {
  527. beforeShow();
  528. }
  529. // Hide virtual keyboard
  530. if ($(document.activeElement).is('input,textarea')) {
  531. $(document.activeElement).blur();
  532. }
  533. if (that.show() !== false) {
  534. $activeElm = $elm;
  535. setTimeout(function () {
  536. preventShow = false;
  537. }, 300); // With jQuery < 1.9 focus is fired twice in IE
  538. }
  539. }
  540. function set() {
  541. that._fillValue();
  542. event('onSelect', [that._value]);
  543. }
  544. function cancel() {
  545. event('onCancel', [that._value]);
  546. }
  547. function clear() {
  548. that.setVal(null, true);
  549. }
  550. // Call the parent constructor
  551. ms.classes.Base.call(this, el, settings, true);
  552. /**
  553. * Positions the scroller on the screen.
  554. */
  555. that.position = function (check) {
  556. var w,
  557. l,
  558. t,
  559. anchor,
  560. aw, // anchor width
  561. ah, // anchor height
  562. ap, // anchor position
  563. at, // anchor top
  564. al, // anchor left
  565. arr, // arrow
  566. arrw, // arrow width
  567. arrl, // arrow left
  568. dh,
  569. scroll,
  570. sl, // scroll left
  571. st, // scroll top
  572. totalw = 0,
  573. minw = 0,
  574. css = {},
  575. nw = Math.min($wnd[0].innerWidth || $wnd.innerWidth(), $persp.width()), //$persp.width(), // To get the width without scrollbar
  576. nh = $wnd[0].innerHeight || $wnd.innerHeight(),
  577. $focused = $(document.activeElement);
  578. if ($focused.is('input,textarea') && !/(button|submit|checkbox|radio)/.test($focused.attr('type'))) {
  579. $focused.on('blur', onBlur);
  580. return;
  581. }
  582. if ((wndWidth === nw && wndHeight === nh && check) || preventPos) {
  583. return;
  584. }
  585. if (that._isFullScreen || /top|bottom/.test(s.display)) {
  586. // Set width, if document is larger than viewport, needs to be set before onPosition (for calendar)
  587. $popup.width(nw);
  588. }
  589. if (event('onPosition', [$markup, nw, nh]) === false || !isModal) {
  590. return;
  591. }
  592. sl = $wnd.scrollLeft();
  593. st = $wnd.scrollTop();
  594. anchor = s.anchor === undefined ? $elm : $(s.anchor);
  595. // Set / unset liquid layout based on screen width, but only if not set explicitly by the user
  596. if (that._isLiquid && s.layout !== 'liquid') {
  597. if (nw < 400) {
  598. $markup.addClass('dw-liq');
  599. } else {
  600. $markup.removeClass('dw-liq');
  601. }
  602. }
  603. if (!that._isFullScreen && /modal|bubble/.test(s.display)) {
  604. $wrapper.width('');
  605. $('.mbsc-w-p', $markup).each(function () {
  606. w = $(this).outerWidth(true);
  607. totalw += w;
  608. minw = (w > minw) ? w : minw;
  609. });
  610. w = totalw > nw ? minw : totalw;
  611. $wrapper.width(w + 1).css('white-space', totalw > nw ? '' : 'nowrap');
  612. }
  613. modalWidth = $popup.outerWidth();
  614. modalHeight = $popup.outerHeight(true);
  615. scrollLock = modalHeight <= nh && modalWidth <= nw;
  616. that.scrollLock = scrollLock;
  617. if (scrollLock) {
  618. $ctx.addClass('mbsc-fr-lock');
  619. } else {
  620. $ctx.removeClass('mbsc-fr-lock');
  621. }
  622. if (s.display == 'modal') {
  623. l = Math.max(0, sl + (nw - modalWidth) / 2);
  624. t = st + (nh - modalHeight) / 2;
  625. } else if (s.display == 'bubble') {
  626. // Scroll only if width also changed
  627. // to prevent scroll when address bar appears / hides
  628. scroll = wndWidth !== nw;
  629. arr = $('.dw-arrw-i', $markup);
  630. ap = anchor.offset();
  631. at = Math.abs($ctx.offset().top - ap.top);
  632. al = Math.abs($ctx.offset().left - ap.left);
  633. // horizontal positioning
  634. aw = anchor.outerWidth();
  635. ah = anchor.outerHeight();
  636. l = constrain(al - ($popup.outerWidth(true) - aw) / 2, sl + 3, sl + nw - modalWidth - 3);
  637. // vertical positioning
  638. t = at - modalHeight; // above the input
  639. if ((t < st) || (at > st + nh)) { // if doesn't fit above or the input is out of the screen
  640. $popup.removeClass('dw-bubble-top').addClass('dw-bubble-bottom');
  641. t = at + ah; // below the input
  642. } else {
  643. $popup.removeClass('dw-bubble-bottom').addClass('dw-bubble-top');
  644. }
  645. // Calculate Arrow position
  646. arrw = arr.outerWidth();
  647. arrl = constrain(al + aw / 2 - (l + (modalWidth - arrw) / 2), 0, arrw);
  648. // Limit Arrow position
  649. $('.dw-arr', $markup).css({
  650. left: arrl
  651. });
  652. } else {
  653. l = sl;
  654. if (s.display == 'top') {
  655. t = st;
  656. } else if (s.display == 'bottom') {
  657. t = st + nh - modalHeight;
  658. }
  659. }
  660. t = t < 0 ? 0 : t;
  661. css.top = t;
  662. css.left = l;
  663. $popup.css(css);
  664. // If top + modal height > doc height, increase doc height
  665. $persp.height(0);
  666. dh = Math.max(t + modalHeight, s.context == 'body' ? $(document).height() : $ctx[0].scrollHeight);
  667. $persp.css({
  668. height: dh
  669. });
  670. // Scroll needed
  671. if (scroll && ((t + modalHeight > st + nh) || (at > st + nh))) {
  672. preventPos = true;
  673. setTimeout(function () {
  674. preventPos = false;
  675. }, 300);
  676. $wnd.scrollTop(Math.min(at, t + modalHeight - nh, dh - nh));
  677. }
  678. wndWidth = nw;
  679. wndHeight = nh;
  680. // Call position for nested mobiscroll components
  681. $('.mbsc-comp', $markup).each(function () {
  682. var inst = $(this).mobiscroll('getInst');
  683. if (inst !== that && inst.position) {
  684. inst.position();
  685. }
  686. });
  687. };
  688. /**
  689. * Show mobiscroll on focus and click event of the parameter.
  690. * @param {jQuery} $elm - Events will be attached to this element.
  691. * @param {Function} [beforeShow=undefined] - Optional function to execute before showing mobiscroll.
  692. */
  693. that.attachShow = function ($elm, beforeShow) {
  694. elmList.push({
  695. readOnly: $elm.prop('readonly'),
  696. el: $elm
  697. });
  698. if (s.display !== 'inline') {
  699. if (setReadOnly && $elm.is('input')) {
  700. $elm.prop('readonly', true).on('mousedown.dw', function (ev) {
  701. // Prevent input to get focus on tap (virtual keyboard pops up on some devices)
  702. ev.preventDefault();
  703. });
  704. }
  705. if (s.showOnFocus) {
  706. $elm.on('focus.dw', function () {
  707. if (!preventShow) {
  708. show(beforeShow, $elm);
  709. }
  710. });
  711. }
  712. if (s.showOnTap) {
  713. $elm.on('keydown.dw', function (ev) {
  714. if (ev.keyCode == 32 || ev.keyCode == 13) { // Space or Enter
  715. ev.preventDefault();
  716. ev.stopPropagation();
  717. show(beforeShow, $elm);
  718. }
  719. });
  720. that.tap($elm, function () {
  721. show(beforeShow, $elm);
  722. });
  723. }
  724. }
  725. };
  726. /**
  727. * Set button handler.
  728. */
  729. that.select = function () {
  730. if (isModal) {
  731. that.hide(false, 'set', false, set);
  732. } else {
  733. set();
  734. }
  735. };
  736. /**
  737. * Cancel and hide the scroller instance.
  738. */
  739. that.cancel = function () {
  740. if (isModal) {
  741. that.hide(false, 'cancel', false, cancel);
  742. } else {
  743. set();
  744. }
  745. };
  746. /**
  747. * Clear button handler.
  748. */
  749. that.clear = function () {
  750. event('onClear', [$markup]);
  751. if (isModal && that._isVisible && !that.live) {
  752. that.hide(false, 'clear', false, clear);
  753. } else {
  754. clear();
  755. }
  756. };
  757. /**
  758. * Enables the scroller and the associated input.
  759. */
  760. that.enable = function () {
  761. s.disabled = false;
  762. if (that._isInput) {
  763. $elm.prop('disabled', false);
  764. }
  765. };
  766. /**
  767. * Disables the scroller and the associated input.
  768. */
  769. that.disable = function () {
  770. s.disabled = true;
  771. if (that._isInput) {
  772. $elm.prop('disabled', true);
  773. }
  774. };
  775. /**
  776. * Shows the scroller instance.
  777. * @param {Boolean} prevAnim - Prevent animation if true
  778. * @param {Boolean} prevFocus - Prevent focusing if true
  779. */
  780. that.show = function (prevAnim, prevFocus) {
  781. // Create wheels
  782. var html;
  783. if (s.disabled || that._isVisible) {
  784. return;
  785. }
  786. // Parse value from input
  787. that._readValue();
  788. if (event('onBeforeShow', []) === false) {
  789. return false;
  790. }
  791. doAnim = isOldAndroid ? false : s.animate;
  792. /*if (doAnim !== false) {
  793. if (s.display == 'top') {
  794. doAnim = 'slidedown';
  795. }
  796. if (s.display == 'bottom') {
  797. doAnim = 'slideup';
  798. }
  799. }*/
  800. // Create wheels containers
  801. html = '<div lang="' + s.lang + '" class="mbsc-' + s.theme + (s.baseTheme ? ' mbsc-' + s.baseTheme : '') + ' dw-' + s.display + ' ' +
  802. (s.cssClass || '') +
  803. (that._isLiquid ? ' dw-liq' : '') +
  804. (isOldAndroid ? ' mbsc-old' : '') +
  805. (hasButtons ? '' : ' dw-nobtn') + '">' +
  806. '<div class="dw-persp">' +
  807. (isModal ? '<div class="dwo"></div>' : '') + // Overlay
  808. '<div' + (isModal ? ' role="dialog" tabindex="-1"' : '') + ' class="dw' + (s.rtl ? ' dw-rtl' : ' dw-ltr') + '">' + // Popup
  809. (s.display === 'bubble' ? '<div class="dw-arrw"><div class="dw-arrw-i"><div class="dw-arr"></div></div></div>' : '') + // Bubble arrow
  810. '<div class="dwwr">' + // Popup content
  811. '<div aria-live="assertive" class="dw-aria dw-hidden"></div>' +
  812. (s.headerText ? '<div class="dwv">' + (isString(s.headerText) ? s.headerText : '') + '</div>' : '') + // Header
  813. '<div class="dwcc">'; // Wheel group container
  814. html += that._generateContent();
  815. html += '</div>';
  816. if (hasButtons) {
  817. html += '<div class="dwbc">';
  818. $.each(buttons, function (i, b) {
  819. b = isString(b) ? that.buttons[b] : b;
  820. if (b.handler === 'set') {
  821. b.parentClass = 'dwb-s';
  822. }
  823. if (b.handler === 'cancel') {
  824. b.parentClass = 'dwb-c';
  825. }
  826. if (b.handler === 'now') {
  827. b.parentClass = 'dwb-n';
  828. }
  829. html += '<div' + (s.btnWidth ? ' style="width:' + (100 / buttons.length) + '%"' : '') + ' class="dwbw ' + (b.parentClass || '') + '"><div tabindex="0" role="button" class="dwb' + i + ' dwb-e ' + (b.cssClass === undefined ? s.btnClass : b.cssClass) + (b.icon ? ' mbsc-ic mbsc-ic-' + b.icon : '') + '">' + (b.text || '') + '</div></div>';
  830. });
  831. html += '</div>';
  832. }
  833. html += '</div></div></div></div>';
  834. $markup = $(html);
  835. $persp = $('.dw-persp', $markup);
  836. $overlay = $('.dwo', $markup);
  837. $wrapper = $('.dwwr', $markup);
  838. $header = $('.dwv', $markup);
  839. $popup = $('.dw', $markup);
  840. $ariaDiv = $('.dw-aria', $markup);
  841. that._markup = $markup;
  842. that._header = $header;
  843. that._isVisible = true;
  844. posEvents = 'orientationchange resize';
  845. that._markupReady($markup);
  846. event('onMarkupReady', [$markup]);
  847. // Show
  848. if (isModal) {
  849. // Enter / ESC
  850. $(window).on('keydown', onWndKeyDown);
  851. // Prevent scroll if not specified otherwise
  852. if (s.scrollLock) {
  853. $markup.on('touchmove mousewheel wheel', function (ev) {
  854. if (scrollLock) {
  855. ev.preventDefault();
  856. }
  857. });
  858. }
  859. // Disable inputs to prevent bleed through (Android bug)
  860. if (pr !== 'Moz') {
  861. $('input,select,button', $ctx).each(function () {
  862. if (!this.disabled) {
  863. $(this).addClass('dwtd').prop('disabled', true);
  864. }
  865. });
  866. }
  867. if (ms.activeInstance) {
  868. ms.activeInstance.hide();
  869. }
  870. posEvents += ' scroll';
  871. ms.activeInstance = that;
  872. $markup.appendTo($ctx);
  873. if (s.focusTrap) {
  874. $wnd.on('focusin', onFocus);
  875. }
  876. if (has3d && doAnim && !prevAnim) {
  877. $markup.addClass('dw-in dw-trans').on(animEnd, function () {
  878. $markup.off(animEnd).removeClass('dw-in dw-trans').find('.dw').removeClass('dw-' + doAnim);
  879. onShow(prevFocus);
  880. }).find('.dw').addClass('dw-' + doAnim);
  881. }
  882. } else if ($elm.is('div') && !that._hasContent) {
  883. $elm.html($markup);
  884. } else {
  885. $markup.insertAfter($elm);
  886. }
  887. that._markupInserted($markup);
  888. event('onMarkupInserted', [$markup]);
  889. // Set position
  890. that.position();
  891. $wnd.on(posEvents, onPosition);
  892. // Events
  893. $markup
  894. .on('selectstart mousedown', prevdef) // Prevents blue highlight on Android and text selection in IE
  895. .on('click', '.dwb-e', prevdef)
  896. .on('keydown', '.dwb-e', function (ev) {
  897. if (ev.keyCode == 32) { // Space
  898. ev.preventDefault();
  899. ev.stopPropagation();
  900. $(this).click();
  901. }
  902. })
  903. .on('keydown', function (ev) { // Trap focus inside modal
  904. if (ev.keyCode == 32) { // Space
  905. ev.preventDefault();
  906. } else if (ev.keyCode == 9 && isModal && s.focusTrap) { // Tab
  907. var $focusable = $markup.find('[tabindex="0"]').filter(function () {
  908. return this.offsetWidth > 0 || this.offsetHeight > 0;
  909. }),
  910. index = $focusable.index($(':focus', $markup)),
  911. i = $focusable.length - 1,
  912. target = 0;
  913. if (ev.shiftKey) {
  914. i = 0;
  915. target = -1;
  916. }
  917. if (index === i) {
  918. $focusable.eq(target).focus();
  919. ev.preventDefault();
  920. }
  921. }
  922. });
  923. $('input,select,textarea', $markup).on('selectstart mousedown', function (ev) {
  924. ev.stopPropagation();
  925. }).on('keydown', function (ev) {
  926. if (ev.keyCode == 32) { // Space
  927. ev.stopPropagation();
  928. }
  929. });
  930. //setTimeout(function () {
  931. // Init buttons
  932. $.each(buttons, function (i, b) {
  933. that.tap($('.dwb' + i, $markup), function (ev) {
  934. b = isString(b) ? that.buttons[b] : b;
  935. (isString(b.handler) ? that.handlers[b.handler] : b.handler).call(this, ev, that);
  936. }, true);
  937. });
  938. if (s.closeOnOverlay) {
  939. that.tap($overlay, function () {
  940. that.cancel();
  941. });
  942. }
  943. if (isModal && !doAnim) {
  944. onShow(prevFocus);
  945. }
  946. $markup
  947. .on('touchstart mousedown pointerdown', '.dwb-e', onBtnStart)
  948. .on('touchend', '.dwb-e', onBtnEnd);
  949. that._attachEvents($markup);
  950. //}, 300);
  951. event('onShow', [$markup, that._tempValue]);
  952. };
  953. /**
  954. * Hides the scroller instance.
  955. */
  956. that.hide = function (prevAnim, btn, force, callback) {
  957. // If onClose handler returns false, prevent hide
  958. if (!that._isVisible || (!force && !that._isValid && btn == 'set') || (!force && event('onBeforeClose', [that._tempValue, btn]) === false)) {
  959. return false;
  960. }
  961. // Hide wheels and overlay
  962. if ($markup) {
  963. // Re-enable temporary disabled fields
  964. if (pr !== 'Moz') {
  965. $('.dwtd', $ctx).each(function () {
  966. $(this).prop('disabled', false).removeClass('dwtd');
  967. });
  968. }
  969. if (has3d && isModal && doAnim && !prevAnim && !$markup.hasClass('dw-trans')) { // If dw-trans class was not removed, means that there was no animation
  970. $markup.addClass('dw-out dw-trans').on(animEnd, function () {
  971. onHide(prevAnim);
  972. }).find('.dw').addClass('dw-' + doAnim);
  973. } else {
  974. onHide(prevAnim);
  975. }
  976. // Stop positioning on window resize
  977. $wnd
  978. .off(posEvents, onPosition)
  979. .off('focusin', onFocus);
  980. }
  981. if (isModal) {
  982. $ctx.removeClass('mbsc-fr-lock');
  983. $(window).off('keydown', onWndKeyDown);
  984. delete ms.activeInstance;
  985. }
  986. if (callback) {
  987. callback();
  988. }
  989. event('onClosed', [that._value]);
  990. };
  991. that.ariaMessage = function (txt) {
  992. $ariaDiv.html('');
  993. setTimeout(function () {
  994. $ariaDiv.html(txt);
  995. }, 100);
  996. };
  997. /**
  998. * Return true if the scroller is currently visible.
  999. */
  1000. that.isVisible = function () {
  1001. return that._isVisible;
  1002. };
  1003. // Protected functions to override
  1004. that.setVal = empty;
  1005. that.getVal = empty;
  1006. that._generateContent = empty;
  1007. that._attachEvents = empty;
  1008. that._readValue = empty;
  1009. that._fillValue = empty;
  1010. that._markupReady = empty;
  1011. that._markupInserted = empty;
  1012. that._markupRemove = empty;
  1013. that._processSettings = empty;
  1014. that._presetLoad = function (s) {
  1015. // Add default buttons
  1016. s.buttons = s.buttons || (s.display !== 'inline' ? ['set', 'cancel','now'] : []);
  1017. // Hide header text in inline mode by default
  1018. s.headerText = s.headerText === undefined ? (s.display !== 'inline' ? '{value}' : false) : s.headerText;
  1019. };
  1020. // Generic frame functions
  1021. /**
  1022. * Destroys the mobiscroll instance.
  1023. */
  1024. that.destroy = function () {
  1025. // Force hide without animation
  1026. that.hide(true, false, true);
  1027. // Remove all events from elements
  1028. $.each(elmList, function (i, v) {
  1029. v.el.off('.dw').prop('readonly', v.readOnly);
  1030. });
  1031. that._destroy();
  1032. };
  1033. /**
  1034. * Scroller initialization.
  1035. */
  1036. that.init = function (ss) {
  1037. // @deprecated since 2.17.0, backward compatibility code
  1038. // ---
  1039. if (ss.onClose) {
  1040. ss.onBeforeClose = ss.onClose;
  1041. }
  1042. // ---
  1043. that._init(ss);
  1044. that._isLiquid = (s.layout || (/top|bottom/.test(s.display) ? 'liquid' : '')) === 'liquid';
  1045. that._processSettings();
  1046. // Unbind all events (if re-init)
  1047. $elm.off('.dw');
  1048. buttons = s.buttons || [];
  1049. isModal = s.display !== 'inline';
  1050. setReadOnly = s.showOnFocus || s.showOnTap;
  1051. that._window = $wnd = $(s.context == 'body' ? window : s.context);
  1052. that._context = $ctx = $(s.context);
  1053. that.live = true;
  1054. // If no set button is found, live mode is activated
  1055. $.each(buttons, function (i, b) {
  1056. if (b == 'ok' || b == 'set' || b.handler == 'set') {
  1057. that.live = false;
  1058. return false;
  1059. }
  1060. });
  1061. that.buttons.set = {
  1062. text: s.setText,
  1063. handler: 'set'
  1064. };
  1065. that.buttons.cancel = {
  1066. text: (that.live) ? s.closeText : s.cancelText,
  1067. handler: 'cancel'
  1068. };
  1069. that.buttons.clear = {
  1070. text: s.clearText,
  1071. handler: 'clear'
  1072. };
  1073. that._isInput = $elm.is('input');
  1074. hasButtons = buttons.length > 0;
  1075. if (that._isVisible) {
  1076. that.hide(true, false, true);
  1077. }
  1078. event('onInit', []);
  1079. if (isModal) {
  1080. that._readValue();
  1081. if (!that._hasContent) {
  1082. that.attachShow($elm);
  1083. }
  1084. } else {
  1085. that.show();
  1086. }
  1087. $elm.on('change.dw', function () {
  1088. if (!that._preventChange) {
  1089. that.setVal($elm.val(), true, false);
  1090. }
  1091. that._preventChange = false;
  1092. });
  1093. };
  1094. that.buttons = {};
  1095. that.handlers = {
  1096. set: that.select,
  1097. cancel: that.cancel,
  1098. clear: that.clear,
  1099. now:that.now,
  1100. };
  1101. that._value = null;
  1102. that._isValid = true;
  1103. that._isVisible = false;
  1104. // Constructor
  1105. s = that.settings;
  1106. event = that.trigger;
  1107. if (!inherit) {
  1108. that.init(settings);
  1109. }
  1110. };
  1111. ms.classes.Frame.prototype._defaults = {
  1112. // Localization
  1113. lang: 'en',
  1114. setText: 'Set',
  1115. selectedText: '{count} selected',
  1116. closeText: 'Close',
  1117. cancelText: 'Cancel',
  1118. clearText: 'Clear',
  1119. // Options
  1120. disabled: false,
  1121. closeOnOverlay: true,
  1122. showOnFocus: false,
  1123. showOnTap: true,
  1124. display: 'bottom',
  1125. scrollLock: true,
  1126. tap: false,
  1127. btnClass: 'dwb',
  1128. btnWidth: false,
  1129. focusTrap: true,
  1130. focusOnClose: !isIOS8 // Temporary for iOS8
  1131. };
  1132. ms.themes.frame.mobiscroll = {
  1133. rows: 5,
  1134. showLabel: false,
  1135. headerText: false,
  1136. btnWidth: false,
  1137. selectedLineHeight: true,
  1138. selectedLineBorder: 1,
  1139. dateOrder: 'MMddyy',
  1140. weekDays: 'min',
  1141. checkIcon: 'ion-ios7-checkmark-empty',
  1142. btnPlusClass: 'mbsc-ic mbsc-ic-arrow-down5',
  1143. btnMinusClass: 'mbsc-ic mbsc-ic-arrow-up5',
  1144. btnCalPrevClass: 'mbsc-ic mbsc-ic-arrow-left5',
  1145. btnCalNextClass: 'mbsc-ic mbsc-ic-arrow-right5'
  1146. };
  1147. // Prevent re-show on window focus
  1148. $(window).on('focus', function () {
  1149. if ($activeElm) {
  1150. preventShow = true;
  1151. }
  1152. });
  1153. })(jQuery, window, document);
  1154. //**mobiscroll.scroller.js
  1155. (function ($, window, document, undefined) {
  1156. var ms = $.mobiscroll,
  1157. classes = ms.classes,
  1158. util = ms.util,
  1159. pr = util.jsPrefix,
  1160. has3d = util.has3d,
  1161. hasFlex = util.hasFlex,
  1162. getCoord = util.getCoord,
  1163. constrain = util.constrain,
  1164. testTouch = util.testTouch;
  1165. ms.presetShort('scroller', 'Scroller', false);
  1166. classes.Scroller = function (el, settings, inherit) {
  1167. var $markup,
  1168. btn,
  1169. isScrollable,
  1170. itemHeight,
  1171. multiple,
  1172. pixels,
  1173. s,
  1174. scrollDebounce,
  1175. trigger,
  1176. click,
  1177. moved,
  1178. start,
  1179. startTime,
  1180. stop,
  1181. p,
  1182. min,
  1183. max,
  1184. target,
  1185. index,
  1186. lines,
  1187. timer,
  1188. that = this,
  1189. $elm = $(el),
  1190. iv = {},
  1191. pos = {},
  1192. wheels = [];
  1193. // Event handlers
  1194. function onStart(ev) {
  1195. // Scroll start
  1196. if (testTouch(ev, this) && !target && !click && !btn && !isReadOnly(this)) {
  1197. // Prevent touch highlight
  1198. ev.preventDefault();
  1199. // Better performance if there are tap events on document
  1200. ev.stopPropagation();
  1201. isScrollable = s.mode != 'clickpick';
  1202. target = $('.dw-ul', this);
  1203. setGlobals(target);
  1204. moved = iv[index] !== undefined; // Don't allow tap, if still moving
  1205. p = moved ? getCurrentPosition(target) : pos[index];
  1206. start = getCoord(ev, 'Y', true);
  1207. startTime = new Date();
  1208. stop = start;
  1209. scroll(target, index, p, 0.001);
  1210. if (isScrollable) {
  1211. target.closest('.dwwl').addClass('dwa');
  1212. }
  1213. if (ev.type === 'mousedown') {
  1214. $(document).on('mousemove', onMove).on('mouseup', onEnd);
  1215. }
  1216. }
  1217. }
  1218. function onMove(ev) {
  1219. if (target) {
  1220. if (isScrollable) {
  1221. // Prevent scroll
  1222. ev.preventDefault();
  1223. ev.stopPropagation();
  1224. stop = getCoord(ev, 'Y', true);
  1225. if (Math.abs(stop - start) > 3 || moved) {
  1226. scroll(target, index, constrain(p + (start - stop) / itemHeight, min - 1, max + 1));
  1227. moved = true;
  1228. }
  1229. }
  1230. }
  1231. }
  1232. function onEnd(ev) {
  1233. if (target) {
  1234. var time = new Date() - startTime,
  1235. curr = constrain(Math.round(p + (start - stop) / itemHeight), min - 1, max + 1),
  1236. val = curr,
  1237. speed,
  1238. dist,
  1239. ttop = target.offset().top;
  1240. // Better performance if there are tap events on document
  1241. ev.stopPropagation();
  1242. if (ev.type === 'mouseup') {
  1243. $(document).off('mousemove', onMove).off('mouseup', onEnd);
  1244. }
  1245. if (has3d && time < 300) {
  1246. speed = (stop - start) / time;
  1247. dist = (speed * speed) / s.speedUnit;
  1248. if (stop - start < 0) {
  1249. dist = -dist;
  1250. }
  1251. } else {
  1252. dist = stop - start;
  1253. }
  1254. if (!moved) { // this is a "tap"
  1255. var idx = Math.floor((stop - ttop) / itemHeight),
  1256. li = $($('.dw-li', target)[idx]),
  1257. valid = li.hasClass('dw-v'),
  1258. hl = isScrollable;
  1259. time = 0.1;
  1260. if (trigger('onValueTap', [li]) !== false && valid) {
  1261. val = idx;
  1262. } else {
  1263. hl = true;
  1264. }
  1265. if (hl && valid) {
  1266. li.addClass('dw-hl'); // Highlight
  1267. setTimeout(function () {
  1268. li.removeClass('dw-hl');
  1269. }, 100);
  1270. }
  1271. if (!multiple && (s.confirmOnTap === true || s.confirmOnTap[index]) && li.hasClass('dw-sel')) {
  1272. that.select();
  1273. target = false;
  1274. return;
  1275. }
  1276. } else {
  1277. val = constrain(Math.round(p - dist / itemHeight), min, max);
  1278. time = speed ? Math.max(0.1, Math.abs((val - curr) / speed) * s.timeUnit) : 0.1;
  1279. }
  1280. if (isScrollable) {
  1281. calc(target, index, val, 0, time, true);
  1282. }
  1283. target = false;
  1284. }
  1285. }
  1286. function onBtnStart(ev) {
  1287. btn = $(this);
  1288. // +/- buttons
  1289. if (testTouch(ev, this)) {
  1290. step(ev, btn.closest('.dwwl'), btn.hasClass('dwwbp') ? plus : minus);
  1291. }
  1292. if (ev.type === 'mousedown') {
  1293. $(document).on('mouseup', onBtnEnd);
  1294. }
  1295. }
  1296. function onBtnEnd(ev) {
  1297. btn = null;
  1298. if (click) {
  1299. clearInterval(timer);
  1300. click = false;
  1301. }
  1302. if (ev.type === 'mouseup') {
  1303. $(document).off('mouseup', onBtnEnd);
  1304. }
  1305. }
  1306. function onKeyDown(ev) {
  1307. if (ev.keyCode == 38) { // up
  1308. step(ev, $(this), minus);
  1309. } else if (ev.keyCode == 40) { // down
  1310. step(ev, $(this), plus);
  1311. }
  1312. }
  1313. function onKeyUp() {
  1314. if (click) {
  1315. clearInterval(timer);
  1316. click = false;
  1317. }
  1318. }
  1319. function onScroll(ev) {
  1320. if (!isReadOnly(this)) {
  1321. ev.preventDefault();
  1322. ev = ev.originalEvent || ev;
  1323. var delta = ev.deltaY || ev.wheelDelta || ev.detail,
  1324. t = $('.dw-ul', this);
  1325. setGlobals(t);
  1326. scroll(t, index, constrain(((delta < 0 ? -20 : 20) - pixels[index]) / itemHeight, min - 1, max + 1));
  1327. clearTimeout(scrollDebounce);
  1328. scrollDebounce = setTimeout(function () {
  1329. calc(t, index, Math.round(pos[index]), delta > 0 ? 1 : 2, 0.1);
  1330. }, 200);
  1331. }
  1332. }
  1333. // Private functions
  1334. function step(ev, w, func) {
  1335. ev.stopPropagation();
  1336. ev.preventDefault();
  1337. if (!click && !isReadOnly(w) && !w.hasClass('dwa')) {
  1338. click = true;
  1339. // + Button
  1340. var t = w.find('.dw-ul');
  1341. setGlobals(t);
  1342. clearInterval(timer);
  1343. timer = setInterval(function () {
  1344. func(t);
  1345. }, s.delay);
  1346. func(t);
  1347. }
  1348. }
  1349. function isReadOnly(wh) {
  1350. if ($.isArray(s.readonly)) {
  1351. var i = $('.dwwl', $markup).index(wh);
  1352. return s.readonly[i];
  1353. }
  1354. return s.readonly;
  1355. }
  1356. function generateWheelItems(i,lbl) {
  1357. var html = '<div class="dw-bf">',
  1358. w = wheels[i],
  1359. l = 1,
  1360. labels = w.labels || [],
  1361. values = w.values || [],
  1362. keys = w.keys || values;
  1363. var classdd = lbl=="年"?'dw-l':'dw-r';
  1364. $.each(values, function (j, v) {
  1365. if (l % 20 === 0) {
  1366. html += '</div><div class="dw-bf">';
  1367. }
  1368. if(s.customWheels){
  1369. var keysHtml="{keys:\'" + keys[j] + "\',values:\'"+ values[j] +"\'}";
  1370. }else{
  1371. var keysHtml=keys[j];
  1372. }
  1373. html += '<div role="option" aria-selected="false" class="dw-li dw-v" data-val="' + keysHtml + '"' + (labels[j] ? ' aria-label="' + labels[j] + '"' : '') + ' style="height:' + itemHeight + 'px;line-height:' + itemHeight + 'px;">' +
  1374. '<div class="dw-i '+classdd+'"' + (lines > 1 ? ' style="line-height:' + Math.round(itemHeight / lines) + 'px;font-size:' + Math.round(itemHeight / lines * 0.8) + 'px;"' : '') + '>' + v+lbl + '</div></div>';
  1375. l++;
  1376. /*html += '<div role="option" aria-selected="false" class="dw-li dw-v" data-val="' + keys[j] + '"' + (labels[j] ? ' aria-label="' + labels[j] + '"' : '') + ' style="height:' + itemHeight + 'px;line-height:' + itemHeight + 'px;">' +
  1377. '<div class="dw-i"' + (lines > 1 ? ' style="line-height:' + Math.round(itemHeight / lines) + 'px;font-size:' + Math.round(itemHeight / lines * 0.8) + 'px;"' : '') + '>' + v + '</div></div>';
  1378. l++;*/
  1379. });
  1380. html += '</div>';
  1381. return html;
  1382. }
  1383. function setGlobals(t) {
  1384. multiple = t.closest('.dwwl').hasClass('dwwms');
  1385. min = $('.dw-li', t).index($(multiple ? '.dw-li' : '.dw-v', t).eq(0));
  1386. max = Math.max(min, $('.dw-li', t).index($(multiple ? '.dw-li' : '.dw-v', t).eq(-1)) - (multiple ? s.rows - (s.mode == 'scroller' ? 1 : 3) : 0));
  1387. index = $('.dw-ul', $markup).index(t);
  1388. }
  1389. function formatHeader(v) {
  1390. var t = s.headerText;
  1391. return t ? (typeof t === 'function' ? t.call(el, v) : t.replace(/\{value\}/i, v)) : '';
  1392. }
  1393. function getCurrentPosition(t) {
  1394. return Math.round(-util.getPosition(t, true) / itemHeight);
  1395. }
  1396. function ready(t, i) {
  1397. clearTimeout(iv[i]);
  1398. delete iv[i];
  1399. t.closest('.dwwl').removeClass('dwa');
  1400. }
  1401. function scroll(t, index, val, time, active) {
  1402. var px = -val * itemHeight,
  1403. style = t[0].style;
  1404. if (px == pixels[index] && iv[index]) {
  1405. return;
  1406. }
  1407. //if (time && px != pixels[index]) {
  1408. // Trigger animation start event
  1409. //trigger('onAnimStart', [$markup, index, time]);
  1410. //}
  1411. pixels[index] = px;
  1412. if (has3d) {
  1413. style[pr + 'Transition'] = util.prefix + 'transform ' + (time ? time.toFixed(3) : 0) + 's ease-out';
  1414. style[pr + 'Transform'] = 'translate3d(0,' + px + 'px,0)';
  1415. } else {
  1416. style.top = px + 'px';
  1417. }
  1418. if (iv[index]) {
  1419. ready(t, index);
  1420. }
  1421. if (time && active) {
  1422. t.closest('.dwwl').addClass('dwa');
  1423. iv[index] = setTimeout(function () {
  1424. ready(t, index);
  1425. }, time * 1000);
  1426. }
  1427. pos[index] = val;
  1428. }
  1429. function getValid(val, t, dir, multiple, select) {
  1430. var selected,
  1431. cell = $('.dw-li[data-val="' + val + '"]', t),
  1432. cells = $('.dw-li', t),
  1433. v = cells.index(cell),
  1434. l = cells.length;
  1435. if (multiple) {
  1436. setGlobals(t);
  1437. } else if (!cell.hasClass('dw-v')) { // Scroll to a valid cell
  1438. var cell1 = cell,
  1439. cell2 = cell,
  1440. dist1 = 0,
  1441. dist2 = 0;
  1442. while (v - dist1 >= 0 && !cell1.hasClass('dw-v')) {
  1443. dist1++;
  1444. cell1 = cells.eq(v - dist1);
  1445. }
  1446. while (v + dist2 < l && !cell2.hasClass('dw-v')) {
  1447. dist2++;
  1448. cell2 = cells.eq(v + dist2);
  1449. }
  1450. // If we have direction (+/- or mouse wheel), the distance does not count
  1451. if (((dist2 < dist1 && dist2 && dir !== 2) || !dist1 || (v - dist1 < 0) || dir == 1) && cell2.hasClass('dw-v')) {
  1452. cell = cell2;
  1453. v = v + dist2;
  1454. } else {
  1455. cell = cell1;
  1456. v = v - dist1;
  1457. }
  1458. }
  1459. selected = cell.hasClass('dw-sel');
  1460. if (select) {
  1461. if (!multiple) {
  1462. $('.dw-sel', t).removeAttr('aria-selected');
  1463. cell.attr('aria-selected', 'true');
  1464. }
  1465. // Add selected class to cell
  1466. $('.dw-sel', t).removeClass('dw-sel');
  1467. cell.addClass('dw-sel');
  1468. }
  1469. return {
  1470. selected: selected,
  1471. v: multiple ? constrain(v, min, max) : v,
  1472. val: cell.hasClass('dw-v') || multiple ? cell.attr('data-val') : null
  1473. };
  1474. }
  1475. function scrollToPos(time, index, manual, dir, active) {
  1476. // Call validation event
  1477. if (trigger('validate', [$markup, index, time, dir]) !== false) {
  1478. // Set scrollers to position
  1479. $('.dw-ul', $markup).each(function (i) {
  1480. var t = $(this),
  1481. multiple = t.closest('.dwwl').hasClass('dwwms'),
  1482. sc = i == index || index === undefined,
  1483. res = getValid(that._tempWheelArray[i], t, dir, multiple, true),
  1484. selected = res.selected;
  1485. if (!selected || sc) {
  1486. // Set valid value
  1487. that._tempWheelArray[i] = res.val;
  1488. // Scroll to position
  1489. scroll(t, i, res.v, sc ? time : 0.1, sc ? active : false);
  1490. }
  1491. });
  1492. trigger('onValidated', [index]);
  1493. // Reformat value if validation changed something
  1494. that._tempValue = s.formatValue(that._tempWheelArray, that);
  1495. if (that.live) {
  1496. that._hasValue = manual || that._hasValue;
  1497. setValue(manual, manual, 0, true);
  1498. }
  1499. that._header.html(formatHeader(that._tempValue));
  1500. if (manual) {
  1501. trigger('onChange', [that._tempValue]);
  1502. }
  1503. }
  1504. }
  1505. function calc(t, idx, val, dir, time, active) {
  1506. //val = constrain(val, min, max);
  1507. // Set selected scroller value
  1508. that._tempWheelArray[idx] = $('.dw-li', t).eq(val).attr('data-val');
  1509. //scroll(t, idx, val, time, active);
  1510. setTimeout(function () {
  1511. // Validate
  1512. scrollToPos(time, idx, true, dir, active);
  1513. }, 10);
  1514. }
  1515. function plus(t) {
  1516. var val = pos[index] + 1;
  1517. calc(t, index, val > max ? min : val, 1, 0.1);
  1518. }
  1519. function minus(t) {
  1520. var val = pos[index] - 1;
  1521. calc(t, index, val < min ? max : val, 2, 0.1);
  1522. }
  1523. function setValue(fill, change, time, noscroll, temp) {
  1524. if (that._isVisible && !noscroll) {
  1525. scrollToPos(time);
  1526. }
  1527. that._tempValue = s.formatValue(that._tempWheelArray, that);
  1528. if (!temp) {
  1529. that._wheelArray = that._tempWheelArray.slice(0);
  1530. that._value = that._hasValue ? that._tempValue : null;
  1531. }
  1532. if (fill) {
  1533. trigger('onValueFill', [that._hasValue ? that._tempValue : '', change]);
  1534. if (that._isInput) {
  1535. $elm.val(that._hasValue ? that._tempValue : '');
  1536. }
  1537. if (change) {
  1538. that._preventChange = true;
  1539. $elm.change();
  1540. }
  1541. }
  1542. }
  1543. // Call the parent constructor
  1544. classes.Frame.call(this, el, settings, true);
  1545. // Public functions
  1546. /**
  1547. * Gets the selected wheel values, formats it, and set the value of the scroller instance.
  1548. * If input parameter is true, populates the associated input element.
  1549. * @param {Array} values Wheel values.
  1550. * @param {Boolean} [fill=false] Also set the value of the associated input element.
  1551. * @param {Number} [time=0] Animation time
  1552. * @param {Boolean} [temp=false] If true, then only set the temporary value.(only scroll there but not set the value)
  1553. * @param {Boolean} [change=false] Trigger change on the input element
  1554. */
  1555. that.setVal = that._setVal = function (val, fill, change, temp, time) {
  1556. that._hasValue = val !== null && val !== undefined;
  1557. that._tempWheelArray = $.isArray(val) ? val.slice(0) : s.parseValue.call(el, val, that) || [];
  1558. setValue(fill, change === undefined ? fill : change, time, false, temp);
  1559. };
  1560. /**
  1561. * Returns the selected value
  1562. */
  1563. that.getVal = that._getVal = function (temp) {
  1564. var val = that._hasValue || temp ? that[temp ? '_tempValue' : '_value'] : null;
  1565. return util.isNumeric(val) ? +val : val;
  1566. };
  1567. /*
  1568. * Sets the wheel values (passed as an array)
  1569. */
  1570. that.setArrayVal = that.setVal;
  1571. /*
  1572. * Returns the selected wheel values as an array
  1573. */
  1574. that.getArrayVal = function (temp) {
  1575. return temp ? that._tempWheelArray : that._wheelArray;
  1576. };
  1577. // @deprecated since 2.14.0, backward compatibility code
  1578. // ---
  1579. that.setValue = function (val, fill, time, temp, change) {
  1580. that.setVal(val, fill, change, temp, time);
  1581. };
  1582. /**
  1583. * Return the selected wheel values.
  1584. */
  1585. that.getValue = that.getArrayVal;
  1586. // ---
  1587. /**
  1588. * Changes the values of a wheel, and scrolls to the correct position
  1589. * @param {Array} idx Indexes of the wheels to change.
  1590. * @param {Number} [time=0] Animation time when scrolling to the selected value on the new wheel.
  1591. * @param {Boolean} [manual=false] Indicates that the change was triggered by the user or from code.
  1592. */
  1593. that.changeWheel = function (idx, time, manual) {
  1594. if ($markup) {
  1595. var i = 0,
  1596. nr = idx.length;
  1597. $.each(s.wheels, function (j, wg) {
  1598. $.each(wg, function (k, w) {
  1599. if ($.inArray(i, idx) > -1) {
  1600. wheels[i] = w;
  1601. $('.dw-ul', $markup).eq(i).html(generateWheelItems(i));
  1602. nr--;
  1603. if (!nr) {
  1604. that.position();
  1605. scrollToPos(time, undefined, manual);
  1606. return false;
  1607. }
  1608. }
  1609. i++;
  1610. });
  1611. if (!nr) {
  1612. return false;
  1613. }
  1614. });
  1615. }
  1616. };
  1617. that.selectWheel = function (keyVal, time, manual) {
  1618. $.each(s.wheels, function (j, wg) {
  1619. $.each(wg, function (k, w) {
  1620. $.each(w.keys,function(l,d){
  1621. if(keyVal[k]==d){
  1622. var $el=$('.dwfl',that._markup).eq(k);
  1623. calc($el, k, l, 1, 0.1);
  1624. }
  1625. });
  1626. });
  1627. });
  1628. };
  1629. /**
  1630. * Returns the closest valid cell.
  1631. */
  1632. that.getValidCell = getValid;
  1633. that.scroll = scroll;
  1634. // Protected overrides
  1635. that._generateContent = function () {
  1636. var lbl,
  1637. html = '',
  1638. l = 0;
  1639. $.each(s.wheels, function (i, wg) { // Wheel groups
  1640. html += '<div class="mbsc-w-p dwc' + (s.mode != 'scroller' ? ' dwpm' : ' dwsc') + (s.showLabel ? '' : ' dwhl') + '">' +
  1641. '<div class="dwwc"' + (s.maxWidth ? '' : ' style="max-width:600px;"') + '>' +
  1642. (hasFlex ? '' : '<table class="dw-tbl" cellpadding="0" cellspacing="0"><tr>');
  1643. $.each(wg, function (j, w) { // Wheels
  1644. wheels[l] = w;
  1645. lbl = w.label !== undefined ? w.label : j;
  1646. html += '<' + (hasFlex ? 'div' : 'td') + ' class="dwfl"' + ' style="' +
  1647. (s.fixedWidth ? ('width:' + (s.fixedWidth[l] || s.fixedWidth) + 'px;') :
  1648. (s.minWidth ? ('min-width:' + (s.minWidth[l] || s.minWidth) + 'px;') : 'min-width:' + s.width + 'px;') +
  1649. (s.maxWidth ? ('max-width:' + (s.maxWidth[l] || s.maxWidth) + 'px;') : '')) + '">' +
  1650. '<div class="dwwl dwwl' + l + (w.multiple ? ' dwwms' : '') + '">' +
  1651. (s.mode != 'scroller' ?
  1652. '<div class="dwb-e dwwb dwwbp ' + (s.btnPlusClass || '') + '" style="height:' + itemHeight + 'px;line-height:' + itemHeight + 'px;"><span>+</span></div>' + // + button
  1653. '<div class="dwb-e dwwb dwwbm ' + (s.btnMinusClass || '') + '" style="height:' + itemHeight + 'px;line-height:' + itemHeight + 'px;"><span>&ndash;</span></div>' : '') + // - button
  1654. '<div class="dwl">' + lbl + '</div>' + // Wheel label
  1655. '<div tabindex="0" aria-live="off" aria-label="' + lbl + '" role="listbox" class="dwww">' +
  1656. '<div class="dww" style="height:' + (s.rows * itemHeight) + 'px;">' +
  1657. '<div class="dw-ul" style="margin-top:' + (w.multiple ? (s.mode == 'scroller' ? 0 : itemHeight) : s.rows / 2 * itemHeight - itemHeight / 2) + 'px;">';
  1658. // Create wheel values
  1659. html += generateWheelItems(l,lbl) +
  1660. '</div></div><div class="dwwo"></div></div><div class="dwwol"' +
  1661. (s.selectedLineHeight ? ' style="height:' + itemHeight + 'px;margin-top:-' + (itemHeight / 2 + (s.selectedLineBorder || 0)) + 'px;"' : '') + '></div></div>' +
  1662. (hasFlex ? '</div>' : '</td>');
  1663. l++;
  1664. });
  1665. html += (hasFlex ? '' : '</tr></table>') + '</div></div>';
  1666. });
  1667. return html;
  1668. };
  1669. that._attachEvents = function ($markup) {
  1670. $markup
  1671. .on('keydown', '.dwwl', onKeyDown)
  1672. .on('keyup', '.dwwl', onKeyUp)
  1673. .on('touchstart mousedown', '.dwwl', onStart)
  1674. .on('touchmove', '.dwwl', onMove)
  1675. .on('touchend', '.dwwl', onEnd)
  1676. .on('touchstart mousedown', '.dwwb', onBtnStart)
  1677. .on('touchend touchcancel', '.dwwb', onBtnEnd);
  1678. if (s.mousewheel) {
  1679. $markup.on('wheel mousewheel', '.dwwl', onScroll);
  1680. }
  1681. };
  1682. that._markupReady = function ($m) {
  1683. $markup = $m;
  1684. pixels = {};
  1685. scrollToPos();
  1686. };
  1687. that._fillValue = function () {
  1688. that._hasValue = true;
  1689. setValue(true, true, 0, true);
  1690. };
  1691. that._readValue = function () {
  1692. var v = $elm.val() || '';
  1693. if (v !== '') {
  1694. that._hasValue = true;
  1695. }
  1696. that._tempWheelArray = that._hasValue && that._wheelArray ? that._wheelArray.slice(0) : s.parseValue.call(el, v, that) || [];
  1697. setValue();
  1698. };
  1699. that._processSettings = function () {
  1700. s = that.settings;
  1701. trigger = that.trigger;
  1702. itemHeight = s.height;
  1703. lines = s.multiline;
  1704. that._isLiquid = (s.layout || (/top|bottom/.test(s.display) && s.wheels.length == 1 ? 'liquid' : '')) === 'liquid';
  1705. // @deprecated since 2.15.0, backward compatibility code
  1706. // ---
  1707. if (s.formatResult) {
  1708. s.formatValue = s.formatResult;
  1709. }
  1710. // ---
  1711. if (lines > 1) {
  1712. s.cssClass = (s.cssClass || '') + ' dw-ml';
  1713. }
  1714. // Ensure a minimum number of 3 items if clickpick buttons present
  1715. if (s.mode != 'scroller') {
  1716. s.rows = Math.max(3, s.rows);
  1717. }
  1718. };
  1719. // Properties
  1720. that._selectedValues = {};
  1721. // Constructor
  1722. if (!inherit) {
  1723. that.init(settings);
  1724. }
  1725. };
  1726. // Extend defaults
  1727. classes.Scroller.prototype = {
  1728. _hasDef: true,
  1729. _hasTheme: true,
  1730. _hasLang: true,
  1731. _hasPreset: true,
  1732. _class: 'scroller',
  1733. _defaults: $.extend({}, classes.Frame.prototype._defaults, {
  1734. // Options
  1735. minWidth: 80,
  1736. height: 45,
  1737. rows: 3,
  1738. multiline: 1,
  1739. delay: 300,
  1740. readonly: false,
  1741. showLabel: false,
  1742. confirmOnTap: true,
  1743. wheels: [],
  1744. mode: 'scroller',
  1745. preset: '',
  1746. speedUnit: 0.0012,
  1747. timeUnit: 0.08,
  1748. formatValue: function (d) {
  1749. return d.join(' ');
  1750. },
  1751. parseValue: function (value, inst) {
  1752. var val = [],
  1753. ret = [],
  1754. i = 0,
  1755. found,
  1756. keys;
  1757. if (value !== null && value !== undefined) {
  1758. val = (value + '').split(' ');
  1759. }
  1760. $.each(inst.settings.wheels, function (j, wg) {
  1761. $.each(wg, function (k, w) {
  1762. keys = w.keys || w.values;
  1763. found = keys[0]; // Default to first wheel value if not found
  1764. $.each(keys, function (l, key) {
  1765. if (val[i] == key) { // Don't do strict comparison
  1766. found = key;
  1767. return false;
  1768. }
  1769. });
  1770. ret.push(found);
  1771. i++;
  1772. });
  1773. });
  1774. return ret;
  1775. }
  1776. })
  1777. };
  1778. ms.themes.scroller = ms.themes.frame;
  1779. })(jQuery, window, document);
  1780. //**mobiscroll.util.datetime.js
  1781. (function ($, undefined) {
  1782. var ms = $.mobiscroll;
  1783. ms.datetime = {
  1784. defaults: {
  1785. shortYearCutoff: '+10',
  1786. monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  1787. monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  1788. dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  1789. dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  1790. dayNamesMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
  1791. amText: 'am',
  1792. pmText: 'pm',
  1793. getYear: function (d) { return d.getFullYear(); },
  1794. getMonth: function (d) { return d.getMonth(); },
  1795. getDay: function (d) { return d.getDate(); },
  1796. getDate: function (y, m, d, h, i, s, u) { return new Date(y, m, d, h || 0, i || 0, s || 0, u || 0); },
  1797. getMaxDayOfMonth: function (y, m) { return 32 - new Date(y, m, 32).getDate(); },
  1798. getWeekNumber: function (d) {
  1799. // Copy date so don't modify original
  1800. d = new Date(d);
  1801. d.setHours(0, 0, 0);
  1802. // Set to nearest Thursday: current date + 4 - current day number
  1803. // Make Sunday's day number 7
  1804. d.setDate(d.getDate() + 4 - (d.getDay() || 7));
  1805. // Get first day of year
  1806. var yearStart = new Date(d.getFullYear(), 0, 1);
  1807. // Calculate full weeks to nearest Thursday
  1808. return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
  1809. }
  1810. },
  1811. /**
  1812. * Format a date into a string value with a specified format.
  1813. * @param {String} format Output format.
  1814. * @param {Date} date Date to format.
  1815. * @param {Object} [settings={}] Settings.
  1816. * @return {String} Returns the formatted date string.
  1817. */
  1818. formatDate: function (format, date, settings) {
  1819. if (!date) {
  1820. return null;
  1821. }
  1822. var s = $.extend({}, ms.datetime.defaults, settings),
  1823. look = function (m) { // Check whether a format character is doubled
  1824. var n = 0;
  1825. while (i + 1 < format.length && format.charAt(i + 1) == m) {
  1826. n++;
  1827. i++;
  1828. }
  1829. return n;
  1830. },
  1831. f1 = function (m, val, len) { // Format a number, with leading zero if necessary
  1832. var n = '' + val;
  1833. if (look(m)) {
  1834. while (n.length < len) {
  1835. n = '0' + n;
  1836. }
  1837. }
  1838. return n;
  1839. },
  1840. f2 = function (m, val, s, l) { // Format a name, short or long as requested
  1841. return (look(m) ? l[val] : s[val]);
  1842. },
  1843. i,
  1844. year,
  1845. output = '',
  1846. literal = false;
  1847. for (i = 0; i < format.length; i++) {
  1848. if (literal) {
  1849. if (format.charAt(i) == "'" && !look("'")) {
  1850. literal = false;
  1851. } else {
  1852. output += format.charAt(i);
  1853. }
  1854. } else {
  1855. switch (format.charAt(i)) {
  1856. case 'd':
  1857. output += f1('d', s.getDay(date), 2);
  1858. break;
  1859. case 'D':
  1860. output += f2('D', date.getDay(), s.dayNamesShort, s.dayNames);
  1861. break;
  1862. case 'o':
  1863. output += f1('o', (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000, 3);
  1864. break;
  1865. case 'm':
  1866. output += f1('m', s.getMonth(date) + 1, 2);
  1867. break;
  1868. case 'M':
  1869. output += f2('M', s.getMonth(date), s.monthNamesShort, s.monthNames);
  1870. break;
  1871. case 'y':
  1872. year = s.getYear(date);
  1873. output += (look('y') ? year : (year % 100 < 10 ? '0' : '') + year % 100);
  1874. //output += (look('y') ? date.getFullYear() : (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
  1875. break;
  1876. case 'h':
  1877. var h = date.getHours();
  1878. output += f1('h', (h > 12 ? (h - 12) : (h === 0 ? 12 : h)), 2);
  1879. break;
  1880. case 'H':
  1881. output += f1('H', date.getHours(), 2);
  1882. break;
  1883. case 'i':
  1884. output += f1('i', date.getMinutes(), 2);
  1885. break;
  1886. case 's':
  1887. output += f1('s', date.getSeconds(), 2);
  1888. break;
  1889. case 'a':
  1890. output += date.getHours() > 11 ? s.pmText : s.amText;
  1891. break;
  1892. case 'A':
  1893. output += date.getHours() > 11 ? s.pmText.toUpperCase() : s.amText.toUpperCase();
  1894. break;
  1895. case "'":
  1896. if (look("'")) {
  1897. output += "'";
  1898. } else {
  1899. literal = true;
  1900. }
  1901. break;
  1902. default:
  1903. output += format.charAt(i);
  1904. }
  1905. }
  1906. }
  1907. return output;
  1908. },
  1909. /**
  1910. * Extract a date from a string value with a specified format.
  1911. * @param {String} format Input format.
  1912. * @param {String} value String to parse.
  1913. * @param {Object} [settings={}] Settings.
  1914. * @return {Date} Returns the extracted date.
  1915. */
  1916. parseDate: function (format, value, settings) {
  1917. var s = $.extend({}, ms.datetime.defaults, settings),
  1918. def = s.defaultValue || new Date();
  1919. if (!format || !value) {
  1920. return def;
  1921. }
  1922. // If already a date object
  1923. if (value.getTime) {
  1924. return value;
  1925. }
  1926. value = (typeof value == 'object' ? value.toString() : value + '');
  1927. var shortYearCutoff = s.shortYearCutoff,
  1928. year = s.getYear(def),
  1929. month = s.getMonth(def) + 1,
  1930. day = s.getDay(def),
  1931. doy = -1,
  1932. hours = def.getHours(),
  1933. minutes = def.getMinutes(),
  1934. seconds = 0, //def.getSeconds(),
  1935. ampm = -1,
  1936. literal = false, // Check whether a format character is doubled
  1937. lookAhead = function (match) {
  1938. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  1939. if (matches) {
  1940. iFormat++;
  1941. }
  1942. return matches;
  1943. },
  1944. getNumber = function (match) { // Extract a number from the string value
  1945. lookAhead(match);
  1946. var size = (match == '@' ? 14 : (match == '!' ? 20 : (match == 'y' ? 4 : (match == 'o' ? 3 : 2)))),
  1947. digits = new RegExp('^\\d{1,' + size + '}'),
  1948. num = value.substr(iValue).match(digits);
  1949. if (!num) {
  1950. return 0;
  1951. }
  1952. iValue += num[0].length;
  1953. return parseInt(num[0], 10);
  1954. },
  1955. getName = function (match, s, l) { // Extract a name from the string value and convert to an index
  1956. var names = (lookAhead(match) ? l : s),
  1957. i;
  1958. for (i = 0; i < names.length; i++) {
  1959. if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
  1960. iValue += names[i].length;
  1961. return i + 1;
  1962. }
  1963. }
  1964. return 0;
  1965. },
  1966. checkLiteral = function () {
  1967. iValue++;
  1968. },
  1969. iValue = 0,
  1970. iFormat;
  1971. for (iFormat = 0; iFormat < format.length; iFormat++) {
  1972. if (literal) {
  1973. if (format.charAt(iFormat) == "'" && !lookAhead("'")) {
  1974. literal = false;
  1975. } else {
  1976. checkLiteral();
  1977. }
  1978. } else {
  1979. switch (format.charAt(iFormat)) {
  1980. case 'd':
  1981. day = getNumber('d');
  1982. break;
  1983. case 'D':
  1984. getName('D', s.dayNamesShort, s.dayNames);
  1985. break;
  1986. case 'o':
  1987. doy = getNumber('o');
  1988. break;
  1989. case 'm':
  1990. month = getNumber('m');
  1991. break;
  1992. case 'M':
  1993. month = getName('M', s.monthNamesShort, s.monthNames);
  1994. break;
  1995. case 'y':
  1996. year = getNumber('y');
  1997. break;
  1998. case 'H':
  1999. hours = getNumber('H');
  2000. break;
  2001. case 'h':
  2002. hours = getNumber('h');
  2003. break;
  2004. case 'i':
  2005. minutes = getNumber('i');
  2006. break;
  2007. case 's':
  2008. seconds = getNumber('s');
  2009. break;
  2010. case 'a':
  2011. ampm = getName('a', [s.amText, s.pmText], [s.amText, s.pmText]) - 1;
  2012. break;
  2013. case 'A':
  2014. ampm = getName('A', [s.amText, s.pmText], [s.amText, s.pmText]) - 1;
  2015. break;
  2016. case "'":
  2017. if (lookAhead("'")) {
  2018. checkLiteral();
  2019. } else {
  2020. literal = true;
  2021. }
  2022. break;
  2023. default:
  2024. checkLiteral();
  2025. }
  2026. }
  2027. }
  2028. if (year < 100) {
  2029. year += new Date().getFullYear() - new Date().getFullYear() % 100 +
  2030. (year <= (typeof shortYearCutoff != 'string' ? shortYearCutoff : new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10)) ? 0 : -100);
  2031. }
  2032. if (doy > -1) {
  2033. month = 1;
  2034. day = doy;
  2035. do {
  2036. var dim = 32 - new Date(year, month - 1, 32).getDate();
  2037. if (day <= dim) {
  2038. break;
  2039. }
  2040. month++;
  2041. day -= dim;
  2042. } while (true);
  2043. }
  2044. hours = (ampm == -1) ? hours : ((ampm && hours < 12) ? (hours + 12) : (!ampm && hours == 12 ? 0 : hours));
  2045. var date = s.getDate(year, month - 1, day, hours, minutes, seconds);
  2046. if (s.getYear(date) != year || s.getMonth(date) + 1 != month || s.getDay(date) != day) {
  2047. return def; // Invalid date
  2048. }
  2049. return date;
  2050. }
  2051. };
  2052. // @deprecated since 2.11.0, backward compatibility code
  2053. // ---
  2054. ms.formatDate = ms.datetime.formatDate;
  2055. ms.parseDate = ms.datetime.parseDate;
  2056. // ---
  2057. })(jQuery);
  2058. //**mobiscroll.datetimebase.js
  2059. (function ($, undefined) {
  2060. var ms = $.mobiscroll,
  2061. datetime = ms.datetime,
  2062. date = new Date(),
  2063. defaults = {
  2064. startYear: date.getFullYear() - 100,
  2065. endYear: date.getFullYear() + 1,
  2066. separator: ' ',
  2067. // Localization
  2068. dateFormat: 'mm/dd/yy',
  2069. dateOrder: 'mmddy',
  2070. timeWheels: 'hhiiA',
  2071. timeFormat: 'hh:ii A',
  2072. dayText: 'Day',
  2073. monthText: 'Month',
  2074. yearText: 'Year',
  2075. hourText: 'Hours',
  2076. minuteText: 'Minutes',
  2077. ampmText: '&nbsp;',
  2078. secText: 'Seconds',
  2079. nowText: 'Now'
  2080. },
  2081. /**
  2082. * @class Mobiscroll.datetime
  2083. * @extends Mobiscroll
  2084. * Mobiscroll Datetime component
  2085. */
  2086. preset = function (inst) {
  2087. var that = $(this),
  2088. html5def = {},
  2089. format;
  2090. // Force format for html5 date inputs (experimental)
  2091. if (that.is('input')) {
  2092. switch (that.attr('type')) {
  2093. case 'date':
  2094. format = 'yy-mm-dd';
  2095. break;
  2096. case 'datetime':
  2097. format = 'yy-mm-ddTHH:ii:ssZ';
  2098. break;
  2099. case 'datetime-local':
  2100. format = 'yy-mm-ddTHH:ii:ss';
  2101. break;
  2102. case 'month':
  2103. format = 'yy-mm';
  2104. html5def.dateOrder = 'mmyy';
  2105. break;
  2106. case 'time':
  2107. format = 'HH:ii:ss';
  2108. break;
  2109. }
  2110. // Check for min/max attributes
  2111. var min = that.attr('min'),
  2112. max = that.attr('max');
  2113. if (min) {
  2114. html5def.minDate = datetime.parseDate(format, min);
  2115. }
  2116. if (max) {
  2117. html5def.maxDate = datetime.parseDate(format, max);
  2118. }
  2119. }
  2120. // Set year-month-day order
  2121. var i,
  2122. k,
  2123. keys,
  2124. values,
  2125. wg,
  2126. start,
  2127. end,
  2128. hasTime,
  2129. mins,
  2130. maxs,
  2131. orig = $.extend({}, inst.settings),
  2132. s = $.extend(inst.settings, ms.datetime.defaults, defaults, html5def, orig),
  2133. offset = 0,
  2134. validValues = [],
  2135. wheels = [],
  2136. ord = [],
  2137. o = {},
  2138. innerValues = {},
  2139. f = {
  2140. y: getYear,
  2141. m: getMonth,
  2142. d: getDay,
  2143. h: getHour,
  2144. i: getMinute,
  2145. s: getSecond,
  2146. u: getMillisecond,
  2147. a: getAmPm
  2148. },
  2149. invalid = s.invalid,
  2150. valid = s.valid,
  2151. p = s.preset,
  2152. dord = s.dateOrder,
  2153. tord = s.timeWheels,
  2154. regen = dord.match(/D/),
  2155. ampm = tord.match(/a/i),
  2156. hampm = tord.match(/h/),
  2157. hformat = p == 'datetime' ? s.dateFormat + s.separator + s.timeFormat : p == 'time' ? s.timeFormat : s.dateFormat,
  2158. defd = new Date(),
  2159. steps = s.steps || {},
  2160. stepH = steps.hour || s.stepHour || 1,
  2161. stepM = steps.minute || s.stepMinute || 1,
  2162. stepS = steps.second || s.stepSecond || 1,
  2163. zeroBased = steps.zeroBased,
  2164. mind = s.minDate || new Date(s.startYear, 0, 1),
  2165. maxd = s.maxDate || new Date(s.endYear, 11, 31, 23, 59, 59),
  2166. minH = zeroBased ? 0 : mind.getHours() % stepH,
  2167. minM = zeroBased ? 0 : mind.getMinutes() % stepM,
  2168. minS = zeroBased ? 0 : mind.getSeconds() % stepS,
  2169. maxH = getMax(stepH, minH, (hampm ? 11 : 23)),
  2170. maxM = getMax(stepM, minM, 59),
  2171. maxS = getMax(stepM, minM, 59);
  2172. format = format || hformat;
  2173. if (p.match(/date/i)) {
  2174. // Determine the order of year, month, day wheels
  2175. $.each(['y', 'm', 'd'], function (j, v) {
  2176. i = dord.search(new RegExp(v, 'i'));
  2177. if (i > -1) {
  2178. ord.push({
  2179. o: i,
  2180. v: v
  2181. });
  2182. }
  2183. });
  2184. ord.sort(function (a, b) {
  2185. return a.o > b.o ? 1 : -1;
  2186. });
  2187. $.each(ord, function (i, v) {
  2188. o[v.v] = i;
  2189. });
  2190. wg = [];
  2191. for (k = 0; k < 3; k++) {
  2192. if (k == o.y) {
  2193. offset++;
  2194. values = [];
  2195. keys = [];
  2196. start = s.getYear(mind);
  2197. end = s.getYear(maxd);
  2198. for (i = start; i <= end; i++) {
  2199. keys.push(i);
  2200. values.push((dord.match(/yy/i) ? i : (i + '').substr(2, 2)) + (s.yearSuffix || ''));
  2201. }
  2202. addWheel(wg, keys, values, s.yearText);
  2203. } else if (k == o.m) {
  2204. offset++;
  2205. values = [];
  2206. keys = [];
  2207. for (i = 0; i < 12; i++) {
  2208. var str = dord.replace(/[dy]/gi, '').replace(/mm/, (i < 9 ? '0' + (i + 1) : i + 1) + (s.monthSuffix || '')).replace(/m/, i + 1 + (s.monthSuffix || ''));
  2209. keys.push(i);
  2210. values.push(str.match(/MM/) ? str.replace(/MM/, '<span class="dw-mon">' + s.monthNames[i] + '</span>') : str.replace(/M/, '<span class="dw-mon">' + s.monthNamesShort[i] + '</span>'));
  2211. }
  2212. addWheel(wg, keys, values, s.monthText);
  2213. } else if (k == o.d) {
  2214. offset++;
  2215. values = [];
  2216. keys = [];
  2217. for (i = 1; i < 32; i++) {
  2218. keys.push(i);
  2219. values.push((dord.match(/dd/i) && i < 10 ? '0' + i : i) + (s.daySuffix || ''));
  2220. }
  2221. addWheel(wg, keys, values, s.dayText);
  2222. }
  2223. }
  2224. wheels.push(wg);
  2225. }
  2226. if (p.match(/time/i)) {
  2227. hasTime = true;
  2228. // Determine the order of hours, minutes, seconds wheels
  2229. ord = [];
  2230. $.each(['h', 'i', 's', 'a'], function (i, v) {
  2231. i = tord.search(new RegExp(v, 'i'));
  2232. if (i > -1) {
  2233. ord.push({
  2234. o: i,
  2235. v: v
  2236. });
  2237. }
  2238. });
  2239. ord.sort(function (a, b) {
  2240. return a.o > b.o ? 1 : -1;
  2241. });
  2242. $.each(ord, function (i, v) {
  2243. o[v.v] = offset + i;
  2244. });
  2245. wg = [];
  2246. for (k = offset; k < offset + 4; k++) {
  2247. if (k == o.h) {
  2248. offset++;
  2249. values = [];
  2250. keys = [];
  2251. for (i = minH; i < (hampm ? 12 : 24); i += stepH) {
  2252. keys.push(i);
  2253. values.push(hampm && i === 0 ? 12 : tord.match(/hh/i) && i < 10 ? '0' + i : i);
  2254. }
  2255. addWheel(wg, keys, values, s.hourText);
  2256. } else if (k == o.i) {
  2257. offset++;
  2258. values = [];
  2259. keys = [];
  2260. for (i = minM; i < 60; i += stepM) {
  2261. keys.push(i);
  2262. values.push(tord.match(/ii/) && i < 10 ? '0' + i : i);
  2263. }
  2264. addWheel(wg, keys, values, s.minuteText);
  2265. } else if (k == o.s) {
  2266. offset++;
  2267. values = [];
  2268. keys = [];
  2269. for (i = minS; i < 60; i += stepS) {
  2270. keys.push(i);
  2271. values.push(tord.match(/ss/) && i < 10 ? '0' + i : i);
  2272. }
  2273. addWheel(wg, keys, values, s.secText);
  2274. } else if (k == o.a) {
  2275. offset++;
  2276. var upper = tord.match(/A/);
  2277. addWheel(wg, [0, 1], upper ? [s.amText.toUpperCase(), s.pmText.toUpperCase()] : [s.amText, s.pmText], s.ampmText);
  2278. }
  2279. }
  2280. wheels.push(wg);
  2281. }
  2282. function get(d, i, def) {
  2283. if (o[i] !== undefined) {
  2284. return +d[o[i]];
  2285. }
  2286. if (innerValues[i] !== undefined) {
  2287. return innerValues[i];
  2288. }
  2289. if (def !== undefined) {
  2290. return def;
  2291. }
  2292. return f[i](defd);
  2293. }
  2294. function addWheel(wg, k, v, lbl) {
  2295. wg.push({
  2296. values: v,
  2297. keys: k,
  2298. label: lbl
  2299. });
  2300. }
  2301. function step(v, st, min, max) {
  2302. return Math.min(max, Math.floor(v / st) * st + min);
  2303. }
  2304. function getYear(d) {
  2305. return s.getYear(d);
  2306. }
  2307. function getMonth(d) {
  2308. return s.getMonth(d);
  2309. }
  2310. function getDay(d) {
  2311. return s.getDay(d);
  2312. }
  2313. function getHour(d) {
  2314. var hour = d.getHours();
  2315. hour = hampm && hour >= 12 ? hour - 12 : hour;
  2316. return step(hour, stepH, minH, maxH);
  2317. }
  2318. function getMinute(d) {
  2319. return step(d.getMinutes(), stepM, minM, maxM);
  2320. }
  2321. function getSecond(d) {
  2322. return step(d.getSeconds(), stepS, minS, maxS);
  2323. }
  2324. function getMillisecond(d) {
  2325. return d.getMilliseconds();
  2326. }
  2327. function getAmPm(d) {
  2328. return ampm && d.getHours() > 11 ? 1 : 0;
  2329. }
  2330. function getDate(d) {
  2331. if (d === null) {
  2332. return d;
  2333. }
  2334. var year = get(d, 'y'),
  2335. month = get(d, 'm'),
  2336. day = Math.min(get(d, 'd'), s.getMaxDayOfMonth(year, month)),
  2337. hour = get(d, 'h', 0);
  2338. return s.getDate(year, month, day, get(d, 'a', 0) ? hour + 12 : hour, get(d, 'i', 0), get(d, 's', 0), get(d, 'u', 0));
  2339. }
  2340. function getMax(step, min, max) {
  2341. return Math.floor((max - min) / step) * step + min;
  2342. }
  2343. function getClosestValidDate(d, dir) {
  2344. var next,
  2345. prev,
  2346. nextValid = false,
  2347. prevValid = false,
  2348. up = 0,
  2349. down = 0;
  2350. // Normalize min and max dates for comparing later (set default values where there are no values from wheels)
  2351. mind = getDate(getArray(mind));
  2352. maxd = getDate(getArray(maxd));
  2353. if (isValid(d)) {
  2354. return d;
  2355. }
  2356. if (d < mind) {
  2357. d = mind;
  2358. }
  2359. if (d > maxd) {
  2360. d = maxd;
  2361. }
  2362. next = d;
  2363. prev = d;
  2364. if (dir !== 2) {
  2365. nextValid = isValid(next);
  2366. while (!nextValid && next < maxd) {
  2367. next = new Date(next.getTime() + 1000 * 60 * 60 * 24);
  2368. nextValid = isValid(next);
  2369. up++;
  2370. }
  2371. }
  2372. if (dir !== 1) {
  2373. prevValid = isValid(prev);
  2374. while (!prevValid && prev > mind) {
  2375. prev = new Date(prev.getTime() - 1000 * 60 * 60 * 24);
  2376. prevValid = isValid(prev);
  2377. down++;
  2378. }
  2379. }
  2380. if (dir === 1 && nextValid) {
  2381. return next;
  2382. }
  2383. if (dir === 2 && prevValid) {
  2384. return prev;
  2385. }
  2386. return down <= up && prevValid ? prev : next;
  2387. }
  2388. function isValid(d) {
  2389. if (d < mind) {
  2390. return false;
  2391. }
  2392. if (d > maxd) {
  2393. return false;
  2394. }
  2395. if (isInObj(d, valid)) {
  2396. return true;
  2397. }
  2398. if (isInObj(d, invalid)) {
  2399. return false;
  2400. }
  2401. return true;
  2402. }
  2403. function isInObj(d, obj) {
  2404. var curr,
  2405. j,
  2406. v;
  2407. if (obj) {
  2408. for (j = 0; j < obj.length; j++) {
  2409. curr = obj[j];
  2410. v = curr + '';
  2411. if (!curr.start) {
  2412. if (curr.getTime) { // Exact date
  2413. if (d.getFullYear() == curr.getFullYear() && d.getMonth() == curr.getMonth() && d.getDate() == curr.getDate()) {
  2414. return true;
  2415. }
  2416. } else if (!v.match(/w/i)) { // Day of month
  2417. v = v.split('/');
  2418. if (v[1]) {
  2419. if ((v[0] - 1) == d.getMonth() && v[1] == d.getDate()) {
  2420. return true;
  2421. }
  2422. } else if (v[0] == d.getDate()) {
  2423. return true;
  2424. }
  2425. } else { // Day of week
  2426. v = +v.replace('w', '');
  2427. if (v == d.getDay()) {
  2428. return true;
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. return false;
  2435. }
  2436. function validateDates(obj, y, m, first, maxdays, idx, val) {
  2437. var j, d, v;
  2438. if (obj) {
  2439. for (j = 0; j < obj.length; j++) {
  2440. d = obj[j];
  2441. v = d + '';
  2442. if (!d.start) {
  2443. if (d.getTime) { // Exact date
  2444. if (s.getYear(d) == y && s.getMonth(d) == m) {
  2445. idx[s.getDay(d) - 1] = val;
  2446. }
  2447. } else if (!v.match(/w/i)) { // Day of month
  2448. v = v.split('/');
  2449. if (v[1]) {
  2450. if (v[0] - 1 == m) {
  2451. idx[v[1] - 1] = val;
  2452. }
  2453. } else {
  2454. idx[v[0] - 1] = val;
  2455. }
  2456. } else { // Day of week
  2457. v = +v.replace('w', '');
  2458. for (k = v - first; k < maxdays; k += 7) {
  2459. if (k >= 0) {
  2460. idx[k] = val;
  2461. }
  2462. }
  2463. }
  2464. }
  2465. }
  2466. }
  2467. }
  2468. function validateTimes(vobj, i, v, temp, y, m, d, target, valid) {
  2469. var dd, ss, str, parts1, parts2, prop1, prop2, v1, v2, j, i1, i2, add, remove, all, hours1, hours2, hours3,
  2470. spec = {},
  2471. steps = {
  2472. h: stepH,
  2473. i: stepM,
  2474. s: stepS,
  2475. a: 1
  2476. },
  2477. day = s.getDate(y, m, d),
  2478. w = ['a', 'h', 'i', 's'];
  2479. if (vobj) {
  2480. $.each(vobj, function (i, obj) {
  2481. if (obj.start) {
  2482. obj.apply = false;
  2483. dd = obj.d;
  2484. ss = dd + '';
  2485. str = ss.split('/');
  2486. if (dd && ((dd.getTime && y == s.getYear(dd) && m == s.getMonth(dd) && d == s.getDay(dd)) || // Exact date
  2487. (!ss.match(/w/i) && ((str[1] && d == str[1] && m == str[0] - 1) || (!str[1] && d == str[0]))) || // Day of month
  2488. (ss.match(/w/i) && day.getDay() == +ss.replace('w', '')) // Day of week
  2489. )) {
  2490. obj.apply = true;
  2491. spec[day] = true; // Prevent applying generic rule on day, if specific exists
  2492. }
  2493. }
  2494. });
  2495. $.each(vobj, function (x, obj) {
  2496. add = 0;
  2497. remove = 0;
  2498. i1 = 0;
  2499. i2 = undefined;
  2500. prop1 = true;
  2501. prop2 = true;
  2502. all = false;
  2503. if (obj.start && (obj.apply || (!obj.d && !spec[day]))) {
  2504. // Define time parts
  2505. parts1 = obj.start.split(':');
  2506. parts2 = obj.end.split(':');
  2507. for (j = 0; j < 3; j++) {
  2508. if (parts1[j] === undefined) {
  2509. parts1[j] = 0;
  2510. }
  2511. if (parts2[j] === undefined) {
  2512. parts2[j] = 59;
  2513. }
  2514. parts1[j] = +parts1[j];
  2515. parts2[j] = +parts2[j];
  2516. }
  2517. parts1.unshift(parts1[0] > 11 ? 1 : 0);
  2518. parts2.unshift(parts2[0] > 11 ? 1 : 0);
  2519. if (hampm) {
  2520. if (parts1[1] >= 12) {
  2521. parts1[1] = parts1[1] - 12;
  2522. }
  2523. if (parts2[1] >= 12) {
  2524. parts2[1] = parts2[1] - 12;
  2525. }
  2526. }
  2527. // Look behind
  2528. for (j = 0; j < i; j++) {
  2529. if (validValues[j] !== undefined) {
  2530. v1 = step(parts1[j], steps[w[j]], mins[w[j]], maxs[w[j]]);
  2531. v2 = step(parts2[j], steps[w[j]], mins[w[j]], maxs[w[j]]);
  2532. hours1 = 0;
  2533. hours2 = 0;
  2534. hours3 = 0;
  2535. if (hampm && j == 1) {
  2536. hours1 = parts1[0] ? 12 : 0;
  2537. hours2 = parts2[0] ? 12 : 0;
  2538. hours3 = validValues[0] ? 12 : 0;
  2539. }
  2540. if (!prop1) {
  2541. v1 = 0;
  2542. }
  2543. if (!prop2) {
  2544. v2 = maxs[w[j]];
  2545. }
  2546. if ((prop1 || prop2) && (v1 + hours1 < validValues[j] + hours3 && validValues[j] + hours3 < v2 + hours2)) {
  2547. all = true;
  2548. }
  2549. if (validValues[j] != v1) {
  2550. prop1 = false;
  2551. }
  2552. if (validValues[j] != v2) {
  2553. prop2 = false;
  2554. }
  2555. }
  2556. }
  2557. // Look ahead
  2558. if (!valid) {
  2559. for (j = i + 1; j < 4; j++) {
  2560. if (parts1[j] > 0) {
  2561. add = steps[v];
  2562. }
  2563. if (parts2[j] < maxs[w[j]]) {
  2564. remove = steps[v];
  2565. }
  2566. }
  2567. }
  2568. if (!all) {
  2569. // Calculate min and max values
  2570. v1 = step(parts1[i], steps[v], mins[v], maxs[v]) + add;
  2571. v2 = step(parts2[i], steps[v], mins[v], maxs[v]) - remove;
  2572. if (prop1) {
  2573. i1 = getValidIndex(target, v1, maxs[v], 0);
  2574. }
  2575. if (prop2) {
  2576. i2 = getValidIndex(target, v2, maxs[v], 1);
  2577. }
  2578. }
  2579. // Disable values
  2580. if (prop1 || prop2 || all) {
  2581. if (valid) {
  2582. $('.dw-li', target).slice(i1, i2).addClass('dw-v');
  2583. } else {
  2584. $('.dw-li', target).slice(i1, i2).removeClass('dw-v');
  2585. }
  2586. }
  2587. }
  2588. });
  2589. }
  2590. }
  2591. function getIndex(t, v) {
  2592. return $('.dw-li', t).index($('.dw-li[data-val="' + v + '"]', t));
  2593. }
  2594. function getValidIndex(t, v, max, add) {
  2595. if (v < 0) {
  2596. return 0;
  2597. }
  2598. if (v > max) {
  2599. return $('.dw-li', t).length;
  2600. }
  2601. return getIndex(t, v) + add;
  2602. }
  2603. function getArray(d, fillInner) {
  2604. var ret = [];
  2605. if (d === null || d === undefined) {
  2606. return d;
  2607. }
  2608. $.each(['y', 'm', 'd', 'a', 'h', 'i', 's', 'u'], function (x, i) {
  2609. if (o[i] !== undefined) {
  2610. ret[o[i]] = f[i](d);
  2611. }
  2612. if (fillInner) {
  2613. innerValues[i] = f[i](d);
  2614. }
  2615. });
  2616. return ret;
  2617. }
  2618. function convertRanges(arr) {
  2619. var i, v, start,
  2620. ret = [];
  2621. if (arr) {
  2622. for (i = 0; i < arr.length; i++) {
  2623. v = arr[i];
  2624. if (v.start && v.start.getTime) {
  2625. start = new Date(v.start);
  2626. while (start <= v.end) {
  2627. ret.push(new Date(start.getFullYear(), start.getMonth(), start.getDate()));
  2628. start.setDate(start.getDate() + 1);
  2629. }
  2630. } else {
  2631. ret.push(v);
  2632. }
  2633. }
  2634. return ret;
  2635. }
  2636. return arr;
  2637. }
  2638. // Extended methods
  2639. // ---
  2640. inst.getVal = function (temp) {
  2641. return inst._hasValue || temp ? getDate(inst.getArrayVal(temp)) : null;
  2642. };
  2643. /**
  2644. * Sets the selected date
  2645. *
  2646. * @param {Date} d Date to select.
  2647. * @param {Boolean} [fill=false] Also set the value of the associated input element. Default is true.
  2648. * @param {Number} [time=0] Animation time to scroll to the selected date.
  2649. * @param {Boolean} [temp=false] Set temporary value only.
  2650. * @param {Boolean} [change=fill] Trigger change on input element.
  2651. */
  2652. inst.setDate = function (d, fill, time, temp, change) {
  2653. inst.setArrayVal(getArray(d), fill, change, temp, time);
  2654. };
  2655. /**
  2656. * Returns the selected date.
  2657. *
  2658. * @param {Boolean} [temp=false] If true, return the currently shown date on the picker, otherwise the last selected one.
  2659. * @return {Date}
  2660. */
  2661. inst.getDate = inst.getVal;
  2662. // ---
  2663. // Initializations
  2664. // ---
  2665. inst.format = hformat;
  2666. inst.order = o;
  2667. inst.handlers.now = function () {
  2668. inst.setDate(new Date(), false, 0.3, true, true);
  2669. };
  2670. inst.buttons.now = {
  2671. text: s.resetText,
  2672. handler: 'now'
  2673. };
  2674. invalid = convertRanges(invalid);
  2675. valid = convertRanges(valid);
  2676. mins = {
  2677. y: mind.getFullYear(),
  2678. m: 0,
  2679. d: 1,
  2680. h: minH,
  2681. i: minM,
  2682. s: minS,
  2683. a: 0
  2684. };
  2685. maxs = {
  2686. y: maxd.getFullYear(),
  2687. m: 11,
  2688. d: 31,
  2689. h: maxH,
  2690. i: maxM,
  2691. s: maxS,
  2692. a: 1
  2693. };
  2694. // ---
  2695. return {
  2696. wheels: wheels,
  2697. headerText: s.headerText ? function () {
  2698. return datetime.formatDate(hformat, getDate(inst.getArrayVal(true)), s);
  2699. } : false,
  2700. formatValue: function (d) {
  2701. return datetime.formatDate(format, getDate(d), s);
  2702. },
  2703. parseValue: function (val) {
  2704. if (!val) {
  2705. innerValues = {};
  2706. }
  2707. return getArray(val ? datetime.parseDate(format, val, s) : (s.defaultValue || new Date()), !!val && !!val.getTime);
  2708. },
  2709. validate: function (dw, i, time, dir) {
  2710. var validated = getClosestValidDate(getDate(inst.getArrayVal(true)), dir),
  2711. temp = getArray(validated),
  2712. y = get(temp, 'y'),
  2713. m = get(temp, 'm'),
  2714. minprop = true,
  2715. maxprop = true;
  2716. $.each(['y', 'm', 'd', 'a', 'h', 'i', 's'], function (x, i) {
  2717. if (o[i] !== undefined) {
  2718. var min = mins[i],
  2719. max = maxs[i],
  2720. maxdays = 31,
  2721. val = get(temp, i),
  2722. t = $('.dw-ul', dw).eq(o[i]);
  2723. if (i == 'd') {
  2724. maxdays = s.getMaxDayOfMonth(y, m);
  2725. max = maxdays;
  2726. if (regen) {
  2727. $('.dw-li', t).each(function () {
  2728. var that = $(this),
  2729. d = that.data('val'),
  2730. w = s.getDate(y, m, d).getDay(),
  2731. str = dord.replace(/[my]/gi, '').replace(/dd/, (d < 10 ? '0' + d : d) + (s.daySuffix || '')).replace(/d/, d + (s.daySuffix || ''));
  2732. $('.dw-i', that).html(str.match(/DD/) ? str.replace(/DD/, '<span class="dw-day">' + s.dayNames[w] + '</span>') : str.replace(/D/, '<span class="dw-day">' + s.dayNamesShort[w] + '</span>'));
  2733. });
  2734. }
  2735. }
  2736. if (minprop && mind) {
  2737. min = f[i](mind);
  2738. }
  2739. if (maxprop && maxd) {
  2740. max = f[i](maxd);
  2741. }
  2742. if (i != 'y') {
  2743. var i1 = getIndex(t, min),
  2744. i2 = getIndex(t, max);
  2745. $('.dw-li', t).removeClass('dw-v').slice(i1, i2 + 1).addClass('dw-v');
  2746. if (i == 'd') { // Hide days not in month
  2747. $('.dw-li', t).removeClass('dw-h').slice(maxdays).addClass('dw-h');
  2748. }
  2749. }
  2750. if (val < min) {
  2751. val = min;
  2752. }
  2753. if (val > max) {
  2754. val = max;
  2755. }
  2756. if (minprop) {
  2757. minprop = val == min;
  2758. }
  2759. if (maxprop) {
  2760. maxprop = val == max;
  2761. }
  2762. // Disable some days
  2763. if (i == 'd') {
  2764. var first = s.getDate(y, m, 1).getDay(),
  2765. idx = {};
  2766. // Set invalid indexes
  2767. validateDates(invalid, y, m, first, maxdays, idx, 1);
  2768. // Delete indexes which are valid
  2769. validateDates(valid, y, m, first, maxdays, idx, 0);
  2770. $.each(idx, function (i, v) {
  2771. if (v) {
  2772. $('.dw-li', t).eq(i).removeClass('dw-v');
  2773. }
  2774. });
  2775. }
  2776. }
  2777. });
  2778. // Invalid times
  2779. if (hasTime) {
  2780. $.each(['a', 'h', 'i', 's'], function (i, v) {
  2781. var val = get(temp, v),
  2782. d = get(temp, 'd'),
  2783. t = $('.dw-ul', dw).eq(o[v]);
  2784. if (o[v] !== undefined) {
  2785. validateTimes(invalid, i, v, temp, y, m, d, t, 0);
  2786. validateTimes(valid, i, v, temp, y, m, d, t, 1);
  2787. // Get valid value
  2788. validValues[i] = +inst.getValidCell(val, t, dir).val;
  2789. }
  2790. });
  2791. }
  2792. inst._tempWheelArray = temp;
  2793. }
  2794. };
  2795. };
  2796. $.each(['date', 'time', 'datetime'], function (i, v) {
  2797. ms.presets.scroller[v] = preset;
  2798. });
  2799. })(jQuery);
  2800. //**mobiscroll.datetime.js
  2801. (function ($) {
  2802. $.each(['date', 'time', 'datetime'], function (i, v) {
  2803. $.mobiscroll.presetShort(v);
  2804. });
  2805. })(jQuery);
  2806. //**mobiscroll.select.js
  2807. (function ($, undefined) {
  2808. var ms = $.mobiscroll,
  2809. util = ms.util,
  2810. isString = util.isString,
  2811. defaults = {
  2812. batch: 40,
  2813. inputClass: '',
  2814. invalid: [],
  2815. rtl: false,
  2816. showInput: true,
  2817. groupLabel: 'Groups',
  2818. checkIcon: 'checkmark',
  2819. dataText: 'text',
  2820. dataValue: 'value',
  2821. dataGroup: 'group',
  2822. dataDisabled: 'disabled'
  2823. };
  2824. ms.presetShort('select');
  2825. ms.presets.scroller.select = function (inst) {
  2826. var change,
  2827. defaultValue,
  2828. group,
  2829. groupArray,
  2830. groupChanged,
  2831. groupTap,
  2832. groupWheelIdx,
  2833. i,
  2834. input,
  2835. optionArray,
  2836. optionWheelIdx,
  2837. option,
  2838. origValues,
  2839. prevGroup,
  2840. timer,
  2841. batchChanged = {},
  2842. batchStart = {},
  2843. batchEnd = {},
  2844. tempBatchStart = {},
  2845. tempBatchEnd = {},
  2846. orig = $.extend({}, inst.settings),
  2847. s = $.extend(inst.settings, defaults, orig),
  2848. batch = s.batch,
  2849. layout = s.layout || (/top|bottom/.test(s.display) ? 'liquid' : ''),
  2850. isLiquid = layout == 'liquid',
  2851. elm = $(this),
  2852. multiple = s.multiple || elm.prop('multiple'),
  2853. maxSelect = util.isNumeric(s.multiple) ? s.multiple : Infinity,
  2854. id = this.id + '_dummy',
  2855. lbl = $('label[for="' + this.id + '"]').attr('for', id),
  2856. label = s.label !== undefined ? s.label : (lbl.length ? lbl.text() : elm.attr('name')),
  2857. selectedClass = 'dw-msel mbsc-ic mbsc-ic-' + s.checkIcon,
  2858. origReadOnly = s.readonly,
  2859. data = s.data,
  2860. hasData = !!data,
  2861. hasGroups = hasData ? !!s.group : $('optgroup', elm).length,
  2862. groupSetup = s.group,
  2863. groupWheel = hasGroups && groupSetup && groupSetup.groupWheel !== false,
  2864. groupSep = hasGroups && groupSetup && groupWheel && groupSetup.clustered === true,
  2865. groupHdr = hasGroups && (!groupSetup || (groupSetup.header !== false && !groupSep)),
  2866. values = elm.val() || [],
  2867. invalid = [],
  2868. selectedValues = {},
  2869. options = {},
  2870. groups = {};
  2871. function prepareData() {
  2872. var gr,
  2873. lbl,
  2874. opt,
  2875. txt,
  2876. val,
  2877. l = 0,
  2878. c = 0,
  2879. groupIndexes = {};
  2880. options = {};
  2881. groups = {};
  2882. optionArray = [];
  2883. groupArray = [];
  2884. // Reset invalids
  2885. invalid.length = 0;
  2886. if (hasData) {
  2887. $.each(s.data, function (i, v) {
  2888. txt = v[s.dataText];
  2889. val = v[s.dataValue];
  2890. lbl = v[s.dataGroup];
  2891. opt = {
  2892. value: val,
  2893. text: txt,
  2894. index: i
  2895. };
  2896. options[val] = opt;
  2897. optionArray.push(opt);
  2898. if (hasGroups) {
  2899. if (groupIndexes[lbl] === undefined) {
  2900. gr = {
  2901. text: lbl,
  2902. value: c,
  2903. options: [],
  2904. index: c
  2905. };
  2906. groups[c] = gr;
  2907. groupIndexes[lbl] = c;
  2908. groupArray.push(gr);
  2909. c++;
  2910. } else {
  2911. gr = groups[groupIndexes[lbl]];
  2912. }
  2913. if (groupSep) {
  2914. opt.index = gr.options.length;
  2915. }
  2916. opt.group = groupIndexes[lbl];
  2917. gr.options.push(opt);
  2918. }
  2919. if (v[s.dataDisabled]) {
  2920. invalid.push(val);
  2921. }
  2922. });
  2923. } else {
  2924. if (hasGroups) {
  2925. $('optgroup', elm).each(function (i) {
  2926. groups[i] = {
  2927. text: this.label,
  2928. value: i,
  2929. options: [],
  2930. index: i
  2931. };
  2932. groupArray.push(groups[i]);
  2933. $('option', this).each(function (j) {
  2934. opt = {
  2935. value: this.value,
  2936. text: this.text,
  2937. index: groupSep ? j : l++,
  2938. group: i
  2939. };
  2940. options[this.value] = opt;
  2941. optionArray.push(opt);
  2942. groups[i].options.push(opt);
  2943. if (this.disabled) {
  2944. invalid.push(this.value);
  2945. }
  2946. });
  2947. });
  2948. } else {
  2949. $('option', elm).each(function (i) {
  2950. opt = {
  2951. value: this.value,
  2952. text: this.text,
  2953. index: i
  2954. };
  2955. options[this.value] = opt;
  2956. optionArray.push(opt);
  2957. if (this.disabled) {
  2958. invalid.push(this.value);
  2959. }
  2960. });
  2961. }
  2962. }
  2963. if (optionArray.length) {
  2964. defaultValue = optionArray[0].value;
  2965. }
  2966. if (groupHdr) {
  2967. optionArray = [];
  2968. l = 0;
  2969. $.each(groups, function (i, gr) {
  2970. val = '__group' + i;
  2971. opt = {
  2972. text: gr.text,
  2973. value: val,
  2974. group: i,
  2975. index: l++
  2976. };
  2977. options[val] = opt;
  2978. optionArray.push(opt);
  2979. invalid.push(opt.value);
  2980. $.each(gr.options, function (j, opt) {
  2981. opt.index = l++;
  2982. optionArray.push(opt);
  2983. });
  2984. });
  2985. }
  2986. }
  2987. function genValues(w, data, dataMap, value, index, multiple, label) {
  2988. var i,
  2989. wheel,
  2990. keys = [],
  2991. values = [],
  2992. selectedIndex = dataMap[value] !== undefined ? dataMap[value].index : 0,
  2993. start = Math.max(0, selectedIndex - batch),
  2994. end = Math.min(data.length - 1, start + batch * 2);
  2995. if (batchStart[index] !== start || batchEnd[index] !== end) {
  2996. for (i = start; i <= end; i++) {
  2997. values.push(data[i].text);
  2998. keys.push(data[i].value);
  2999. }
  3000. batchChanged[index] = true;
  3001. tempBatchStart[index] = start;
  3002. tempBatchEnd[index] = end;
  3003. wheel = {
  3004. multiple: multiple,
  3005. values: values,
  3006. keys: keys,
  3007. label: label
  3008. };
  3009. if (isLiquid) {
  3010. w[0][index] = wheel;
  3011. } else {
  3012. w[index] = [wheel];
  3013. }
  3014. } else {
  3015. batchChanged[index] = false;
  3016. }
  3017. }
  3018. function genGroupWheel(w) {
  3019. genValues(w, groupArray, groups, group, groupWheelIdx, false, s.groupLabel);
  3020. }
  3021. function genOptWheel(w) {
  3022. genValues(w, groupSep ? groups[group].options : optionArray, options, option, optionWheelIdx, multiple, label);
  3023. }
  3024. function genWheels() {
  3025. var w = [
  3026. []
  3027. ];
  3028. if (groupWheel) {
  3029. genGroupWheel(w);
  3030. }
  3031. genOptWheel(w);
  3032. return w;
  3033. }
  3034. function getOption(v) {
  3035. if (multiple) {
  3036. if (v && isString(v)) {
  3037. v = v.split(',');
  3038. }
  3039. if ($.isArray(v)) {
  3040. v = v[0];
  3041. }
  3042. }
  3043. option = v === undefined || v === null || v === '' || !options[v] ? defaultValue : v;
  3044. if (groupWheel) {
  3045. group = options[option] ? options[option].group : null;
  3046. prevGroup = group;
  3047. }
  3048. }
  3049. function getVal(temp, group) {
  3050. var val = temp ? inst._tempWheelArray : (inst._hasValue ? inst._wheelArray : null);
  3051. return val ? (s.group && group ? val : val[optionWheelIdx]) : null;
  3052. }
  3053. function onFill() {
  3054. var txt,
  3055. val,
  3056. sel = [],
  3057. i = 0;
  3058. if (multiple) {
  3059. val = [];
  3060. for (i in selectedValues) {
  3061. sel.push(options[i] ? options[i].text : '');
  3062. val.push(i);
  3063. }
  3064. txt = sel.join(', ');
  3065. } else {
  3066. val = option;
  3067. txt = options[option] ? options[option].text : '';
  3068. }
  3069. inst._tempValue = val;
  3070. input.val(txt);
  3071. elm.val(val);
  3072. }
  3073. function onTap(li) {
  3074. var val = li.attr('data-val'),
  3075. selected = li.hasClass('dw-msel');
  3076. if (multiple && li.closest('.dwwl').hasClass('dwwms')) {
  3077. if (li.hasClass('dw-v')) {
  3078. if (selected) {
  3079. li.removeClass(selectedClass).removeAttr('aria-selected');
  3080. delete selectedValues[val];
  3081. } else if (util.objectToArray(selectedValues).length < maxSelect) {
  3082. li.addClass(selectedClass).attr('aria-selected', 'true');
  3083. selectedValues[val] = val;
  3084. }
  3085. }
  3086. return false;
  3087. } else if (li.hasClass('dw-w-gr')) {
  3088. groupTap = li.attr('data-val');
  3089. }
  3090. }
  3091. if (!s.invalid.length) {
  3092. s.invalid = invalid;
  3093. }
  3094. if (groupWheel) {
  3095. groupWheelIdx = 0;
  3096. optionWheelIdx = 1;
  3097. } else {
  3098. groupWheelIdx = -1;
  3099. optionWheelIdx = 0;
  3100. }
  3101. if (multiple) {
  3102. elm.prop('multiple', true);
  3103. if (values && isString(values)) {
  3104. values = values.split(',');
  3105. }
  3106. for (i = 0; i < values.length; i++) {
  3107. selectedValues[values[i]] = values[i];
  3108. }
  3109. }
  3110. prepareData();
  3111. getOption(elm.val());
  3112. $('#' + id).remove();
  3113. if (elm.next().is('input.mbsc-control')) {
  3114. input = elm.off('.mbsc-form').next().removeAttr('tabindex');
  3115. } else {
  3116. input = $('<input type="text" id="' + id + '" class="mbsc-control mbsc-control-ev ' + s.inputClass + '" readonly />');
  3117. if (s.showInput) {
  3118. input.insertBefore(elm);
  3119. }
  3120. }
  3121. inst.attachShow(input.attr('placeholder', s.placeholder || ''));
  3122. elm.addClass('dw-hsel').attr('tabindex', -1).closest('.ui-field-contain').trigger('create');
  3123. onFill();
  3124. // Extended methods
  3125. // ---
  3126. inst.setVal = function (val, fill, change, temp, time) {
  3127. if (multiple) {
  3128. if (val && isString(val)) {
  3129. val = val.split(',');
  3130. }
  3131. selectedValues = util.arrayToObject(val);
  3132. val = val ? val[0] : null;
  3133. }
  3134. inst._setVal(val, fill, change, temp, time);
  3135. };
  3136. inst.getVal = function (temp, group) {
  3137. if (multiple) {
  3138. return util.objectToArray(selectedValues);
  3139. }
  3140. return getVal(temp, group);
  3141. };
  3142. inst.refresh = function () {
  3143. prepareData();
  3144. batchStart = {};
  3145. batchEnd = {};
  3146. s.wheels = genWheels();
  3147. batchStart[groupWheelIdx] = tempBatchStart[groupWheelIdx];
  3148. batchEnd[groupWheelIdx] = tempBatchEnd[groupWheelIdx];
  3149. batchStart[optionWheelIdx] = tempBatchStart[optionWheelIdx];
  3150. batchEnd[optionWheelIdx] = tempBatchEnd[optionWheelIdx];
  3151. // Prevent wheel generation on initial validation
  3152. change = true;
  3153. getOption(option);
  3154. inst._tempWheelArray = groupWheel ? [group, option] : [option];
  3155. if (inst._isVisible) {
  3156. inst.changeWheel(groupWheel ? [groupWheelIdx, optionWheelIdx] : [optionWheelIdx]);
  3157. }
  3158. };
  3159. // @deprecated since 2.14.0, backward compatibility code
  3160. // ---
  3161. inst.getValues = inst.getVal;
  3162. inst.getValue = getVal;
  3163. // ---
  3164. // ---
  3165. return {
  3166. width: 50,
  3167. layout: layout,
  3168. headerText: false,
  3169. anchor: input,
  3170. confirmOnTap: groupWheel ? [false, true] : true,
  3171. formatValue: function (d) {
  3172. var i,
  3173. opt,
  3174. sel = [];
  3175. if (multiple) {
  3176. for (i in selectedValues) {
  3177. sel.push(options[i] ? options[i].text : '');
  3178. }
  3179. return sel.join(', ');
  3180. }
  3181. opt = d[optionWheelIdx];
  3182. return options[opt] ? options[opt].text : '';
  3183. },
  3184. parseValue: function (val) {
  3185. getOption(val === undefined ? elm.val() : val);
  3186. return groupWheel ? [group, option] : [option];
  3187. },
  3188. onValueTap: onTap,
  3189. onValueFill: onFill,
  3190. onBeforeShow: function () {
  3191. if (multiple && s.counter) {
  3192. s.headerText = function () {
  3193. var length = 0;
  3194. $.each(selectedValues, function () {
  3195. length++;
  3196. });
  3197. return (length > 1 ? s.selectedPluralText || s.selectedText : s.selectedText).replace(/{count}/, length);
  3198. };
  3199. }
  3200. getOption(elm.val());
  3201. if (groupWheel) {
  3202. inst._tempWheelArray = [group, option];
  3203. }
  3204. inst.refresh();
  3205. },
  3206. onMarkupReady: function (dw) {
  3207. dw.addClass('dw-select');
  3208. $('.dwwl' + groupWheelIdx, dw).on('mousedown touchstart', function () {
  3209. clearTimeout(timer);
  3210. });
  3211. $('.dwwl' + optionWheelIdx, dw).on('mousedown touchstart', function () {
  3212. if (!groupChanged) {
  3213. clearTimeout(timer);
  3214. }
  3215. });
  3216. if (groupHdr) {
  3217. $('.dwwl' + optionWheelIdx, dw).addClass('dw-select-gr');
  3218. }
  3219. if (multiple) {
  3220. dw.addClass('dwms');
  3221. $('.dwwl', dw).on('keydown', function (e) {
  3222. if (e.keyCode == 32) { // Space
  3223. e.preventDefault();
  3224. e.stopPropagation();
  3225. onTap($('.dw-sel', this));
  3226. }
  3227. }).eq(optionWheelIdx).attr('aria-multiselectable', 'true');
  3228. origValues = $.extend({}, selectedValues);
  3229. }
  3230. },
  3231. validate: function (dw, i, time, dir) {
  3232. var j,
  3233. v,
  3234. changes = [],
  3235. temp = inst.getArrayVal(true),
  3236. tempGr = temp[groupWheelIdx],
  3237. tempOpt = temp[optionWheelIdx],
  3238. t1 = $('.dw-ul', dw).eq(groupWheelIdx),
  3239. t2 = $('.dw-ul', dw).eq(optionWheelIdx);
  3240. if (batchStart[groupWheelIdx] > 1) {
  3241. $('.dw-li', t1).slice(0, 2).removeClass('dw-v').addClass('dw-fv');
  3242. }
  3243. if (batchEnd[groupWheelIdx] < groupArray.length - 2) {
  3244. $('.dw-li', t1).slice(-2).removeClass('dw-v').addClass('dw-fv');
  3245. }
  3246. if (batchStart[optionWheelIdx] > 1) {
  3247. $('.dw-li', t2).slice(0, 2).removeClass('dw-v').addClass('dw-fv');
  3248. }
  3249. if (batchEnd[optionWheelIdx] < (groupSep ? groups[tempGr].options : optionArray).length - 2) {
  3250. $('.dw-li', t2).slice(-2).removeClass('dw-v').addClass('dw-fv');
  3251. }
  3252. if (!change) {
  3253. option = tempOpt;
  3254. if (groupWheel) {
  3255. group = options[option].group;
  3256. // If group changed, load group options
  3257. if (i === undefined || i === groupWheelIdx) {
  3258. group = +temp[groupWheelIdx];
  3259. groupChanged = false;
  3260. if (group !== prevGroup) {
  3261. option = groups[group].options[0].value;
  3262. batchStart[optionWheelIdx] = null;
  3263. batchEnd[optionWheelIdx] = null;
  3264. groupChanged = true;
  3265. s.readonly = [false, true];
  3266. } else {
  3267. s.readonly = origReadOnly;
  3268. }
  3269. }
  3270. }
  3271. // Adjust value to the first group option if group header was selected
  3272. if (hasGroups && (/__group/.test(option) || groupTap)) {
  3273. option = groups[options[groupTap || option].group].options[0].value;
  3274. tempOpt = option;
  3275. groupTap = false;
  3276. }
  3277. // Update values if changed
  3278. // Don't set the new option yet (if group changed), because it's not on the wheel yet
  3279. inst._tempWheelArray = groupWheel ? [tempGr, tempOpt] : [tempOpt];
  3280. // Generate new wheel batches
  3281. if (groupWheel) {
  3282. genGroupWheel(s.wheels);
  3283. if (batchChanged[groupWheelIdx]) {
  3284. changes.push(groupWheelIdx);
  3285. }
  3286. }
  3287. genOptWheel(s.wheels);
  3288. if (batchChanged[optionWheelIdx]) {
  3289. changes.push(optionWheelIdx);
  3290. }
  3291. clearTimeout(timer);
  3292. timer = setTimeout(function () {
  3293. if (changes.length) {
  3294. change = true;
  3295. groupChanged = false;
  3296. prevGroup = group;
  3297. // Save current batch boundaries
  3298. batchStart[groupWheelIdx] = tempBatchStart[groupWheelIdx];
  3299. batchEnd[groupWheelIdx] = tempBatchEnd[groupWheelIdx];
  3300. batchStart[optionWheelIdx] = tempBatchStart[optionWheelIdx];
  3301. batchEnd[optionWheelIdx] = tempBatchEnd[optionWheelIdx];
  3302. // Set the updated values
  3303. inst._tempWheelArray = groupWheel ? [tempGr, option] : [option];
  3304. // Change the wheels
  3305. inst.changeWheel(changes, 0, i !== undefined);
  3306. }
  3307. if (groupWheel) {
  3308. if (i === optionWheelIdx) {
  3309. inst.scroll(t1, groupWheelIdx, inst.getValidCell(group, t1, dir, false, true).v, 0.1);
  3310. }
  3311. inst._tempWheelArray[groupWheelIdx] = group;
  3312. }
  3313. // Restore readonly status
  3314. s.readonly = origReadOnly;
  3315. }, i === undefined ? 100 : time * 1000);
  3316. if (changes.length) {
  3317. return groupChanged ? false : true;
  3318. }
  3319. }
  3320. // Add selected styling to selected elements in case of multiselect
  3321. if (i === undefined && multiple) {
  3322. v = selectedValues;
  3323. j = 0;
  3324. $('.dwwl' + optionWheelIdx + ' .dw-li', dw).removeClass(selectedClass).removeAttr('aria-selected');
  3325. for (j in v) {
  3326. $('.dwwl' + optionWheelIdx + ' .dw-li[data-val="' + v[j] + '"]', dw).addClass(selectedClass).attr('aria-selected', 'true');
  3327. }
  3328. }
  3329. // Add styling to group headers
  3330. if (groupHdr) {
  3331. $('.dw-li[data-val^="__group"]', dw).addClass('dw-w-gr');
  3332. }
  3333. // Disable invalid options
  3334. $.each(s.invalid, function (i, v) {
  3335. $('.dw-li[data-val="' + v + '"]', t2).removeClass('dw-v dw-fv');
  3336. });
  3337. change = false;
  3338. },
  3339. onValidated: function () {
  3340. option = inst._tempWheelArray[optionWheelIdx];
  3341. },
  3342. onClear: function (dw) {
  3343. selectedValues = {};
  3344. input.val('');
  3345. $('.dwwl' + optionWheelIdx + ' .dw-li', dw).removeClass(selectedClass).removeAttr('aria-selected');
  3346. },
  3347. onCancel: function () {
  3348. if (!inst.live && multiple) {
  3349. selectedValues = $.extend({}, origValues);
  3350. }
  3351. },
  3352. onDestroy: function () {
  3353. if (!input.hasClass('mbsc-control')) {
  3354. input.remove();
  3355. }
  3356. elm.removeClass('dw-hsel').removeAttr('tabindex');
  3357. }
  3358. };
  3359. };
  3360. })(jQuery);
  3361. //**mobiscroll.listbase.js
  3362. (function ($, undefined) {
  3363. var ms = $.mobiscroll,
  3364. defaults = {
  3365. invalid: [],
  3366. showInput: true,
  3367. inputClass: ''
  3368. };
  3369. ms.presets.scroller.list = function (inst) {
  3370. var orig = $.extend({}, inst.settings),
  3371. s = $.extend(inst.settings, defaults, orig),
  3372. layout = s.layout || (/top|bottom/.test(s.display) ? 'liquid' : ''),
  3373. isLiquid = layout == 'liquid',
  3374. origReadOnly = s.readonly,
  3375. elm = $(this),
  3376. input,
  3377. prevent,
  3378. id = this.id + '_dummy',
  3379. lvl = 0,
  3380. ilvl = 0,
  3381. timer = {},
  3382. currLevel,
  3383. currWheelVector = [],
  3384. wa = s.wheelArray || createWheelArray(elm),
  3385. labels = generateLabels(lvl),
  3386. fwv = firstWheelVector(wa),
  3387. w = generateWheelsFromVector(fwv, lvl);
  3388. /**
  3389. * Disables the invalid items on the wheels
  3390. * @param {Object} dw - the jQuery mobiscroll object
  3391. * @param {Number} nrWheels - the number of the current wheels
  3392. * @param {Array} whArray - The wheel array objects containing the wheel tree
  3393. * @param {Array} whVector - the wheel vector containing the current keys
  3394. */
  3395. function setDisabled(dw, nrWheels, whArray, whVector) {
  3396. var j,
  3397. i = 0;
  3398. while (i < nrWheels) {
  3399. var currWh = $('.dwwl' + i, dw),
  3400. inv = getInvalidKeys(whVector, i, whArray);
  3401. for (j = 0; j < inv.length; j++) {
  3402. $('.dw-li[data-val="' + inv[j] + '"]', currWh).removeClass('dw-v');
  3403. }
  3404. i++;
  3405. }
  3406. }
  3407. /**
  3408. * Returns the invalid keys of one wheel as an array
  3409. * @param {Array} whVector - the wheel vector used to search for the wheel in the wheel array
  3410. * @param {Number} index - index of the wheel in the wheel vector, that we are interested in
  3411. * @param {Array} whArray - the wheel array we are searching in
  3412. * @return {Array} - list of invalid keys
  3413. */
  3414. function getInvalidKeys(whVector, index, whArray) {
  3415. var i = 0,
  3416. n,
  3417. whObjA = whArray,
  3418. invalids = [];
  3419. while (i < index) {
  3420. var ii = whVector[i];
  3421. //whObjA = whObjA[ii].children;
  3422. for (n in whObjA) {
  3423. if (whObjA[n].key == ii) {
  3424. whObjA = whObjA[n].children;
  3425. break;
  3426. }
  3427. }
  3428. i++;
  3429. }
  3430. i = 0;
  3431. while (i < whObjA.length) {
  3432. if (whObjA[i].invalid) {
  3433. invalids.push(whObjA[i].key);
  3434. }
  3435. i++;
  3436. }
  3437. return invalids;
  3438. }
  3439. /**
  3440. * Creates a Boolean vector with true values (except one) that can be used as the readonly vector
  3441. * n - the length of the vector
  3442. * i - the index of the value that's going to be false
  3443. */
  3444. function createROVector(n, i) {
  3445. var a = [];
  3446. while (n) {
  3447. a[--n] = true;
  3448. }
  3449. a[i] = false;
  3450. return a;
  3451. }
  3452. /**
  3453. * Creates a labels vector, from values if they are defined, otherwise from numbers
  3454. * l - the length of the vector
  3455. */
  3456. function generateLabels(l) {
  3457. var a = [],
  3458. i;
  3459. for (i = 0; i < l; i++) {
  3460. a[i] = s.labels && s.labels[i] ? s.labels[i] : i;
  3461. }
  3462. return a;
  3463. }
  3464. /**
  3465. * Creates the wheel array from the vector provided
  3466. * wv - wheel vector containing the values that should be selected on the wheels
  3467. * l - the length of the wheel array
  3468. */
  3469. function generateWheelsFromVector(wv, l, index) {
  3470. var i = 0,
  3471. j, obj, chInd,
  3472. w = [
  3473. []
  3474. ],
  3475. wtObjA = wa;
  3476. if (l) { // if length is defined we need to generate that many wheels (even if they are empty)
  3477. for (j = 0; j < l; j++) {
  3478. if (isLiquid) {
  3479. w[0][j] = {};
  3480. } else {
  3481. w[j] = [{}];
  3482. }
  3483. }
  3484. }
  3485. while (i < wv.length) { // we generate the wheels until the length of the wheel vector
  3486. if (isLiquid) {
  3487. w[0][i] = getWheelFromObjA(wtObjA, labels[i]);
  3488. } else {
  3489. w[i] = [getWheelFromObjA(wtObjA, labels[i])];
  3490. }
  3491. j = 0;
  3492. chInd = undefined;
  3493. while (j < wtObjA.length && chInd === undefined) {
  3494. if (wtObjA[j].key == wv[i] && ((index !== undefined && i <= index) || index === undefined)) {
  3495. chInd = j;
  3496. }
  3497. j++;
  3498. }
  3499. if (chInd !== undefined && wtObjA[chInd].children) {
  3500. i++;
  3501. wtObjA = wtObjA[chInd].children;
  3502. } else if ((obj = getFirstValidItemObjOrInd(wtObjA)) && obj.children) {
  3503. i++;
  3504. wtObjA = obj.children;
  3505. } else {
  3506. return w;
  3507. }
  3508. }
  3509. return w;
  3510. }
  3511. /**
  3512. * Returns the first valid Wheel Node Object or its index from a Wheel Node Object Array
  3513. * getInd - if it is true then the return value is going to be the index, otherwise the object itself
  3514. */
  3515. function getFirstValidItemObjOrInd(wtObjA, getInd) {
  3516. if (!wtObjA) {
  3517. return false;
  3518. }
  3519. var i = 0,
  3520. obj;
  3521. while (i < wtObjA.length) {
  3522. if (!(obj = wtObjA[i++]).invalid) {
  3523. return getInd ? i - 1 : obj;
  3524. }
  3525. }
  3526. return false;
  3527. }
  3528. function getWheelFromObjA(objA, lbl) {
  3529. var wheel = {
  3530. keys: [],
  3531. values: [],
  3532. label: lbl
  3533. },
  3534. j = 0;
  3535. while (j < objA.length) {
  3536. wheel.values.push(objA[j].value);
  3537. wheel.keys.push(objA[j].key);
  3538. j++;
  3539. }
  3540. return wheel;
  3541. }
  3542. /**
  3543. * Hides the last i number of wheels
  3544. * i - the last number of wheels that has to be hidden
  3545. */
  3546. function hideWheels(dw, i) {
  3547. $('.dwfl', dw).css('display', '').slice(i).hide();
  3548. }
  3549. /**
  3550. * Generates the first wheel vector from the wheeltree
  3551. * wt - the wheel tree object
  3552. * uses the lvl global variable to determine the length of the vector
  3553. */
  3554. function firstWheelVector(wa) {
  3555. var t = [],
  3556. ndObjA = wa,
  3557. obj,
  3558. ok = true,
  3559. i = 0;
  3560. while (ok) {
  3561. obj = getFirstValidItemObjOrInd(ndObjA);
  3562. t[i++] = obj.key;
  3563. ok = obj.children;
  3564. if (ok) {
  3565. ndObjA = ok;
  3566. }
  3567. }
  3568. return t;
  3569. }
  3570. /**
  3571. * Calculates the level of a wheel vector and the new wheel vector, depending on current wheel vector and the index of the changed wheel
  3572. * wv - current wheel vector
  3573. * index - index of the changed wheel
  3574. */
  3575. function calcLevelOfVector2(wv, index) {
  3576. var t = [],
  3577. ndObjA = wa,
  3578. lvl = 0,
  3579. next = false,
  3580. i,
  3581. childName,
  3582. chInd;
  3583. if (wv[lvl] !== undefined && lvl <= index) {
  3584. i = 0;
  3585. childName = wv[lvl];
  3586. chInd = undefined;
  3587. while (i < ndObjA.length && chInd === undefined) {
  3588. if (ndObjA[i].key == wv[lvl] && !ndObjA[i].invalid) {
  3589. chInd = i;
  3590. }
  3591. i++;
  3592. }
  3593. } else {
  3594. chInd = getFirstValidItemObjOrInd(ndObjA, true);
  3595. childName = ndObjA[chInd].key;
  3596. }
  3597. next = chInd !== undefined ? ndObjA[chInd].children : false;
  3598. t[lvl] = childName;
  3599. while (next) {
  3600. ndObjA = ndObjA[chInd].children;
  3601. lvl++;
  3602. next = false;
  3603. chInd = undefined;
  3604. if (wv[lvl] !== undefined && lvl <= index) {
  3605. i = 0;
  3606. childName = wv[lvl];
  3607. chInd = undefined;
  3608. while (i < ndObjA.length && chInd === undefined) {
  3609. if (ndObjA[i].key == wv[lvl] && !ndObjA[i].invalid) {
  3610. chInd = i;
  3611. }
  3612. i++;
  3613. }
  3614. } else {
  3615. chInd = getFirstValidItemObjOrInd(ndObjA, true);
  3616. chInd = chInd === false ? undefined : chInd;
  3617. childName = ndObjA[chInd].key;
  3618. }
  3619. next = chInd !== undefined && getFirstValidItemObjOrInd(ndObjA[chInd].children) ? ndObjA[chInd].children : false;
  3620. t[lvl] = childName;
  3621. }
  3622. return {
  3623. lvl: lvl + 1,
  3624. nVector: t
  3625. }; // return the calculated level and the wheel vector as an object
  3626. }
  3627. function createWheelArray(ul) {
  3628. var wheelArray = [];
  3629. lvl = lvl > ilvl++ ? lvl : ilvl;
  3630. ul.children('li').each(function (index) {
  3631. var that = $(this),
  3632. c = that.clone();
  3633. c.children('ul,ol').remove();
  3634. var v = inst._processMarkup ? inst._processMarkup(c) : c.html().replace(/^\s\s*/, '').replace(/\s\s*$/, ''),
  3635. inv = that.attr('data-invalid') ? true : false,
  3636. wheelObj = {
  3637. key: that.attr('data-val') === undefined || that.attr('data-val') === null ? index : that.attr('data-val'),
  3638. value: v,
  3639. invalid: inv,
  3640. children: null
  3641. },
  3642. nest = that.children('ul,ol');
  3643. if (nest.length) {
  3644. wheelObj.children = createWheelArray(nest);
  3645. }
  3646. wheelArray.push(wheelObj);
  3647. });
  3648. ilvl--;
  3649. return wheelArray;
  3650. }
  3651. $('#' + id).remove(); // Remove input if exists
  3652. if (s.showInput) {
  3653. input = $('<input type="text" id="' + id + '" value="" class="' + s.inputClass + '" placeholder="' + (s.placeholder || '') + '" readonly />').insertBefore(elm);
  3654. s.anchor = input; // give the core the input element for the bubble positioning
  3655. inst.attachShow(input);
  3656. }
  3657. if (!s.wheelArray) {
  3658. elm.hide().closest('.ui-field-contain').trigger('create');
  3659. }
  3660. return {
  3661. width: 50,
  3662. wheels: w,
  3663. layout: layout,
  3664. headerText: false,
  3665. formatValue: function (d) {
  3666. if (currLevel === undefined) {
  3667. currLevel = calcLevelOfVector2(d, d.length).lvl;
  3668. }
  3669. return d.slice(0, currLevel).join(' ');
  3670. },
  3671. parseValue: function (value) {
  3672. return value ? (value + '').split(' ') : (s.defaultValue || fwv).slice(0);
  3673. },
  3674. onBeforeShow: function () {
  3675. var t = inst.getArrayVal(true);
  3676. currWheelVector = t.slice(0);
  3677. s.wheels = generateWheelsFromVector(t, lvl, lvl);
  3678. prevent = true;
  3679. },
  3680. onValueFill: function (v) {
  3681. currLevel = undefined;
  3682. if (input) {
  3683. input.val(v);
  3684. }
  3685. },
  3686. onShow: function (dw) {
  3687. $('.dwwl', dw).on('mousedown touchstart', function () {
  3688. clearTimeout(timer[$('.dwwl', dw).index(this)]);
  3689. });
  3690. },
  3691. onDestroy: function () {
  3692. if (input) {
  3693. input.remove();
  3694. }
  3695. elm.show();
  3696. },
  3697. validate: function (dw, index, time) {
  3698. var args = [],
  3699. t = inst.getArrayVal(true),
  3700. i = (index || 0) + 1,
  3701. j,
  3702. o;
  3703. if ((index !== undefined && currWheelVector[index] != t[index]) || (index === undefined && !prevent)) {
  3704. s.wheels = generateWheelsFromVector(t, null, index);
  3705. o = calcLevelOfVector2(t, index === undefined ? t.length : index);
  3706. currLevel = o.lvl;
  3707. for (j = 0; j < t.length; j++) {
  3708. t[j] = o.nVector[j] || 0;
  3709. }
  3710. while (i < o.lvl) {
  3711. args.push(i++);
  3712. }
  3713. if (args.length) {
  3714. s.readonly = createROVector(lvl, index);
  3715. clearTimeout(timer[index]);
  3716. timer[index] = setTimeout(function () {
  3717. prevent = true;
  3718. hideWheels(dw, o.lvl);
  3719. currWheelVector = t.slice(0);
  3720. inst.changeWheel(args, index === undefined ? time : 0, index !== undefined);
  3721. s.readonly = origReadOnly;
  3722. }, index === undefined ? 0 : time * 1000);
  3723. return false;
  3724. }
  3725. } else {
  3726. o = calcLevelOfVector2(t, t.length);
  3727. currLevel = o.lvl;
  3728. }
  3729. currWheelVector = t.slice(0);
  3730. setDisabled(dw, o.lvl, wa, t);
  3731. hideWheels(dw, o.lvl);
  3732. prevent = false;
  3733. }
  3734. };
  3735. };
  3736. })(jQuery);
  3737. //**mobiscroll.image.js
  3738. (function ($) {
  3739. var ms = $.mobiscroll,
  3740. presets = ms.presets.scroller;
  3741. ms.presetShort('image');
  3742. presets.image = function (inst) {
  3743. if (inst.settings.enhance) {
  3744. inst._processMarkup = function (li) {
  3745. var hasIcon = li.attr('data-icon');
  3746. li.children().each(function (i, v) {
  3747. v = $(v);
  3748. if (v.is('img')) {
  3749. $('<div class="mbsc-img-c"></div>').insertAfter(v).append(v.addClass('mbsc-img'));
  3750. } else if (v.is('p')) {
  3751. v.addClass('mbsc-img-txt');
  3752. }
  3753. });
  3754. if (hasIcon) {
  3755. li.prepend('<div class="mbsc-ic mbsc-ic-' + hasIcon + '"></div');
  3756. }
  3757. li.html('<div class="mbsc-img-w">' + li.html() + '</div>');
  3758. return li.html();
  3759. };
  3760. }
  3761. return presets.list.call(this, inst);
  3762. };
  3763. })(jQuery);
  3764. //**mobiscroll.treelist.js
  3765. (function ($) {
  3766. var ms = $.mobiscroll,
  3767. presets = ms.presets.scroller;
  3768. presets.treelist = presets.list;
  3769. ms.presetShort('list');
  3770. ms.presetShort('treelist');
  3771. })(jQuery);
  3772. //**mobiscroll.frame.android.js
  3773. (function ($) {
  3774. $.mobiscroll.themes.frame.android = {
  3775. dateOrder: 'Mddyy',
  3776. mode: 'clickpick',
  3777. height: 50,
  3778. showLabel: false,
  3779. btnStartClass: 'mbsc-ic mbsc-ic-play3',
  3780. btnStopClass: 'mbsc-ic mbsc-ic-pause2',
  3781. btnResetClass: 'mbsc-ic mbsc-ic-stop2',
  3782. btnLapClass: 'mbsc-ic mbsc-ic-loop2'
  3783. };
  3784. })(jQuery);
  3785. //**mobiscroll.frame.android-holo.js
  3786. (function ($) {
  3787. var themes = $.mobiscroll.themes.frame,
  3788. theme = {
  3789. dateOrder: 'Mddyy',
  3790. //mode: 'mixed',
  3791. rows: 5,
  3792. minWidth: 76,
  3793. height: 36,
  3794. showLabel: false,
  3795. selectedLineHeight: true,
  3796. selectedLineBorder: 2,
  3797. useShortLabels: true,
  3798. icon: { filled: 'star3', empty: 'star' },
  3799. btnPlusClass: 'mbsc-ic mbsc-ic-arrow-down6',
  3800. btnMinusClass: 'mbsc-ic mbsc-ic-arrow-up6',
  3801. // @deprecated since 2.12.0, backward compatibility code
  3802. // ---
  3803. onThemeLoad: function (lang, s) {
  3804. if (s.theme) {
  3805. s.theme = s.theme.replace('android-ics', 'android-holo');
  3806. }
  3807. },
  3808. // ---
  3809. onMarkupReady: function (markup) {
  3810. markup.addClass('mbsc-android-holo');
  3811. }
  3812. };
  3813. themes['android-holo'] = theme;
  3814. themes['android-holo-light'] = theme;
  3815. // @deprecated since 2.12.0, backward compatibility code
  3816. themes['android-ics'] = theme;
  3817. themes['android-ics light'] = theme;
  3818. themes['android-holo light'] = theme;
  3819. })(jQuery);
  3820. //**i18n/mobiscroll.i18n.zh.js
  3821. (function ($) {
  3822. $.mobiscroll.i18n.zh = {
  3823. // Core
  3824. setText: '确定',
  3825. cancelText: '取消',
  3826. clearText: '明确',
  3827. selectedText: '{count} 选',
  3828. // Datetime component
  3829. dateFormat: 'yy/mm/dd',
  3830. dateOrder: 'yymmdd',
  3831. dayNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
  3832. dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
  3833. dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
  3834. dayText: '日',
  3835. hourText: '时',
  3836. minuteText: '分',
  3837. monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  3838. monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
  3839. monthText: '月',
  3840. secText: '秒',
  3841. timeFormat: 'HH:ii',
  3842. timeWheels: 'HHii',
  3843. yearText: '年',
  3844. nowText: '当前',
  3845. pmText: '下午',
  3846. amText: '上午',
  3847. // Calendar component
  3848. dateText: '日',
  3849. timeText: '时间',
  3850. calendarText: '日历',
  3851. closeText: '关闭',
  3852. // Daterange component
  3853. fromText: '开始时间',
  3854. toText: '结束时间',
  3855. // Measurement components
  3856. wholeText: '合计',
  3857. fractionText: '分数',
  3858. unitText: '单位',
  3859. // Time / Timespan component
  3860. labels: ['年', '月', '日', '小时', '分钟', '秒', ''],
  3861. labelsShort: ['年', '月', '日', '点', '分', '秒', ''],
  3862. // Timer component
  3863. startText: '开始',
  3864. stopText: '停止',
  3865. resetText: '重置',
  3866. lapText: '圈',
  3867. hideText: '隐藏',
  3868. // Listview
  3869. backText: '背部',
  3870. undoText: '复原',
  3871. // Form
  3872. offText: '关闭',
  3873. onText: '开启',
  3874. // Numpad
  3875. decimalSeparator: ',',
  3876. thousandsSeparator: ' '
  3877. };
  3878. })(jQuery);