mobiscroll.min.js 91 KB

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