source: uKadecot/trunk/tools/EcnlControllerUI/EcnlCtrlUI/js/jqm-datebox/jqm-datebox.core.js@ 101

Last change on this file since 101 was 101, checked in by coas-nagasima, 9 years ago

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 48.5 KB
Line 
1/*
2 * jQuery Mobile Framework : plugin to provide a date and time picker.
3 * Copyright (c) JTSage
4 * CC 3.0 Attribution. May be relicensed without permission/notification.
5 * https://github.com/jtsage/jquery-mobile-datebox
6 */
7/* CORE Functions */
8
9(function($) {
10 $.widget( "mobile.datebox", $.mobile.widget, {
11 options: {
12 // All widget options, including some internal runtime details
13 version: '2-1.4.0-2013070300', // jQMMajor.jQMMinor.DBoxMinor-YrMoDaySerial
14 mobVer: parseInt($.mobile.version.replace(/\./g,'')),
15 theme: false,
16 themeDefault: 'a',
17 themeHeader: 'a',
18 mode: false,
19
20 centerHoriz: false,
21 centerVert: false,
22 transition: 'pop',
23 useAnimation: true,
24 hideInput: false,
25 hideFixedToolbars: false,
26
27 lockInput: true,
28 enhanceInput: true,
29
30 zindex: '500',
31 clickEvent: 'vclick',
32 clickEventAlt: 'click',
33 resizeListener: true,
34
35 defaultValue: false,
36 showInitialValue: false,
37
38 dialogEnable: false,
39 dialogForce: false,
40 enablePopup: false,
41
42 popupPosition: false,
43 popupForceX: false,
44 popupForceY: false,
45
46 useModal: false,
47 useInline: false,
48 useInlineBlind: false,
49 useHeader: true,
50 useImmediate: false,
51 useNewStyle: false,
52 useAltIcon: false,
53 overrideStyleClass: false,
54
55 useButton: true,
56 useFocus: false,
57 useClearButton: false,
58 useCollapsedBut: false,
59 usePlaceholder: false,
60
61 openCallback: false,
62 openCallbackArgs: [],
63 closeCallback: false,
64 closeCallbackArgs: [],
65
66 startOffsetYears: false,
67 startOffsetMonths: false,
68 startOffsetDays: false,
69 afterToday: false,
70 beforeToday: false,
71 notToday: false,
72 maxDays: false,
73 minDays: false,
74 maxYear: false,
75 minYear: false,
76 blackDates: false,
77 blackDatesRec: false,
78 blackDays: false,
79 minHour: false,
80 maxHour: false,
81 minuteStep: 1,
82 minuteStepRound: 0,
83
84 rolloverMode: { 'm': true, 'd': true, 'h': true, 'i': true, 's': true },
85
86 useLang: 'default',
87 lang: {
88 'default' : {
89 setDateButtonLabel: 'Set Date',
90 setTimeButtonLabel: 'Set Time',
91 setDurationButtonLabel: 'Set Duration',
92 calTodayButtonLabel: 'Jump to Today',
93 titleDateDialogLabel: 'Set Date',
94 titleTimeDialogLabel: 'Set Time',
95 daysOfWeek: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
96 daysOfWeekShort: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
97 monthsOfYear: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
98 monthsOfYearShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
99 durationLabel: ['Days', 'Hours', 'Minutes', 'Seconds'],
100 durationDays: ['Day', 'Days'],
101 timeFormat: 24,
102 headerFormat: '%A, %B %-d, %Y',
103 tooltip: 'Open Date Picker',
104 nextMonth: 'Next Month',
105 prevMonth: 'Previous Month',
106 dateFieldOrder: ['m', 'd', 'y'],
107 timeFieldOrder: ['h', 'i', 'a'],
108 slideFieldOrder: ['y', 'm', 'd'],
109 dateFormat: '%Y-%m-%d',
110 useArabicIndic: false,
111 isRTL: false,
112 calStartDay: 0,
113 clearButton: 'Clear',
114 durationOrder: ['d', 'h', 'i', 's'],
115 meridiem: ['AM', 'PM'],
116 timeOutput: '%k:%M', //{ '12': '%l:%M %p', '24': '%k:%M' },
117 durationFormat: '%Dd %DA, %Dl:%DM:%DS',
118 calDateListLabel: 'Other Dates',
119 calHeaderFormat: '%B %Y'
120 }
121 }
122 },
123 _enhanceDate: function() {
124 $.extend(this._date.prototype, {
125 copy: function(adjust, override) {
126 /* Get a modified copy of the date.
127 * First array - Offset the new date by # (position determines date part)
128 * Second array - If non-zero, force the new date by # (position determines date part)
129 */
130 if ( typeof adjust === 'undefined' ) { adjust = [0,0,0,0,0,0,0]; }
131 if ( typeof override === 'undefined' ) { override = [0,0,0,0,0,0,0]; }
132 while ( adjust.length < 7 ) { adjust.push(0); }
133 while ( override.length < 7 ) { override.push(0); }
134 return new Date(
135 ((override[0] > 0 ) ? override[0] : this.getFullYear() + adjust[0]),
136 ((override[1] > 0 ) ? override[1] : this.getMonth() + adjust[1]),
137 ((override[2] > 0 ) ? override[2] : this.getDate() + adjust[2]),
138 ((override[3] > 0 ) ? override[3] : this.getHours() + adjust[3]),
139 ((override[4] > 0 ) ? override[4] : this.getMinutes() + adjust[4]),
140 ((override[5] > 0 ) ? override[5] : this.getSeconds() + adjust[5]),
141 ((override[6] > 0 ) ? override[5] : this.getMilliseconds() + adjust[6]));
142 },
143 adj: function (type, amount) {
144 /* Adjust the date. Yes, this is chainable */
145 if ( typeof amount !== 'number' ) {
146 throw new Error("Adjustment value not specified");
147 }
148 if ( typeof type !== 'number' ) {
149 throw new Error("Adjustment type not specified");
150 }
151 switch ( type ) {
152 case 0: this.setFullYear(this.getFullYear() + amount); break;
153 case 1: this.setMonth(this.getMonth() + amount); break;
154 case 2: this.setDate(this.getDate() + amount); break;
155 case 3: this.setHours(this.getHours() + amount); break;
156 case 4: this.setMinutes(this.getMinutes() + amount); break;
157 case 5: this.setSeconds(this.getSeconds() + amount); break;
158 case 6: this.setMilliseconds(this.getMilliseconds() + amount); break;
159 }
160 return this;
161 },
162 setD: function(type, amount) {
163 /* A chainable version of setWhatever() */
164 switch ( type ) {
165 case 0: this.setFullYear(amount); break;
166 case 1: this.setMonth(amount); break;
167 case 2: this.setDate(amount); break;
168 case 3: this.setHours(amount); break;
169 case 4: this.setMinutes(amount); break;
170 case 5: this.setSeconds(amount); break;
171 case 6: this.setMilliseconds(amount); break;
172 }
173 return this;
174 },
175 get: function(type) {
176 switch ( type ) {
177 case 0: return this.getFullYear();
178 case 1: return this.getMonth();
179 case 2: return this.getDate();
180 case 3: return this.getHours();
181 case 4: return this.getMinutes();
182 case 5: return this.getSeconds();
183 }
184 return false;
185 },
186 iso: function() {
187 return String(this.getFullYear()) + '-' + (( this.getMonth() < 9 ) ? "0" : "") + String(this.getMonth()+1) + '-' + ((this.getDate() < 10 ) ? "0" : "") + String(this.getDate());
188 },
189 comp: function () {
190 return parseInt(this.iso().replace(/-/g,''),10);
191 },
192 getEpoch: function() {
193 return (this.getTime() - this.getMilliseconds()) / 1000;
194 },
195 getArray: function() {
196 return [this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()];
197 },
198 setFirstDay: function (day) {
199 this.setD(2,1).adj(2, (day - this.getDay()));
200 if ( this.get(2) > 10 ) { this.adj(2,7); }
201 return this;
202 },
203 setDWeek: function (type,num) {
204 if ( type === 4 ) {
205 return this.setD(1,0).setD(2,1).setFirstDay(4).adj(2,-3).adj(2,(num-1)*7);
206 }
207 return this.setD(1,0).setD(2,1).setFirstDay(type).adj(2,(num-1)*7);
208 },
209 getDWeek: function (type) {
210 var t1, t2;
211
212 switch ( type ) {
213 case 0:
214 t1 = this.copy([0,-1*this.getMonth()]).setFirstDay(0);
215 return Math.floor((this.getTime() - ( t1.getTime() + (( this.getTimezoneOffset() - t1.getTimezoneOffset()) * 60000))) / 6048e5) + 1;
216 //return Math.floor((this.getTime() - t1.getTime()) / 6048e5) + 1;
217 case 1:
218 t1 = this.copy([0,-1*this.getMonth()]).setFirstDay(1);
219 return Math.floor((this.getTime() - ( t1.getTime() + (( this.getTimezoneOffset() - t1.getTimezoneOffset()) * 60000))) / 6048e5) + 1;
220 //return Math.floor((this.getTime() - t1.getTime()) / 6048e5) + 1;
221 case 4:
222 // this line is some bullshit. but it does work.
223 // (trap for dec 29, 30, or 31st being in the new year's week - these are the
224 // only 3 that can possibly fall like this)
225 if ( this.getMonth() === 11 && this.getDate() > 28 ) { return 1; }
226
227 t1 = this.copy([0,-1*this.getMonth()],true).setFirstDay(4).adj(2,-3);
228 t2 = Math.floor((this.getTime() - ( t1.getTime() + (( this.getTimezoneOffset() - t1.getTimezoneOffset()) * 60000))) / 6048e5) + 1;
229
230 if ( t2 < 1 ) {
231 t1 = this.copy([-1,-1*this.getMonth()]).setFirstDay(4).adj(2,-3);
232 return Math.floor((this.getTime() - t1.getTime()) / 6048e5) + 1;
233 }
234 return t2;
235 default:
236 return 0;
237 }
238 }
239 });
240 },
241 _event: function(e, p) {
242 var w = $(this).data(parseInt($.mobile.version.replace(/\./g,''),10) > 110 ? 'mobile-datebox' : 'datebox');
243 if ( ! e.isPropagationStopped() ) {
244 switch (p.method) {
245 case 'close':
246 w.close(); break;
247 case 'open':
248 w.open(); break;
249 case 'set':
250 $(this).val(p.value);
251 $(this).trigger('change');
252 break;
253 case 'doset':
254 if ( $.isFunction(w['_'+w.options.mode+'DoSet']) ) {
255 w['_'+w.options.mode+'DoSet'].apply(w,[]);
256 } else {
257 $(this).trigger('datebox', {'method':'set', 'value':w._formatter(w.__fmt(), w.theDate), 'date':w.theDate});
258 }
259 break;
260 case 'dooffset':
261 if (p.type) { w._offset(p.type, p.amount, true); } break;
262 case 'dorefresh':
263 w.refresh(); break;
264 case 'doreset':
265 w.hardreset(); break;
266 case 'doclear':
267 $(this).val('').trigger('change'); break;
268 case 'clear':
269 $(this).trigger('change');
270 }
271 }
272 },
273 _hoover: function(item) {
274 // Hover toggle class, for calendar
275 $(item).toggleClass('ui-btn-up-'+$(item).jqmData('theme')+' ui-btn-down-'+$(item).jqmData('theme'));
276 },
277 _ord: {
278 'default': function (num) {
279 // Return an ordinal suffix (1st, 2nd, 3rd, etc)
280 var ending = num % 10;
281 if ( num > 9 && num < 21 ) { return 'th'; }
282 if ( ending > 3 ) { return 'th'; }
283 return ['th','st','nd','rd'][ending];
284 }
285 },
286 __ : function(val) {
287 var o = this.options,
288 oride = 'override' + val.charAt(0).toUpperCase() + val.slice(1);
289
290 if ( typeof o[oride] !== 'undefined' ) { return o[oride]; }
291 if ( typeof o.lang[o.useLang][val] !== 'undefined' ) { return o.lang[o.useLang][val]; }
292 if ( typeof o[o.mode+'lang'] !== 'undefined' && typeof o[o.mode+'lang'][val] !== 'undefined' ) { return o[o.mode+'lang'][val]; }
293 return o.lang['default'][val];
294 },
295 __fmt: function() {
296 var w = this,
297 o = this.options;
298
299 switch ( o.mode ) {
300 case 'timebox':
301 case 'timeflipbox':
302 return w.__('timeOutput');
303 case 'durationbox':
304 case 'durationflipbox':
305 return w.__('durationFormat');
306 default:
307 return w.__('dateFormat');
308 }
309 },
310 _zPad: function(number) {
311 return (( number < 10 ) ? '0' + String(number) : String(number));
312 },
313 _dRep: function(oper, direction) {
314 var start = 48,
315 end = 57,
316 adder = 1584,
317 i = null,
318 ch = null,
319 newd = '';
320
321 if ( direction === -1 ) {
322 start += adder;
323 end += adder;
324 adder = -1584;
325 }
326
327 for ( i=0; i<oper.length; i++ ) {
328 ch = oper.charCodeAt(i);
329 if ( ch >= start && ch <= end ) {
330 newd = newd + String.fromCharCode(ch+adder);
331 } else {
332 newd = newd + String.fromCharCode(ch);
333 }
334 }
335
336 return newd;
337 },
338 _doIndic: function() {
339 var w = this;
340
341 w.d.intHTML.find('*').each(function() {
342 if ( $(this).children().length < 1 ) {
343 $(this).text(w._dRep($(this).text()));
344 } else if ( $(this).hasClass('ui-datebox-slideday') ) {
345 $(this).html(w._dRep($(this).html()));
346 }
347 });
348 w.d.intHTML.find('input').each(function() {
349 $(this).val(w._dRep($(this).val()));
350 });
351 },
352 _parser: {
353 'default': function (str) { return false; }
354 },
355 _n: function (val,def) {
356 return ( val < 0 ) ? def : val;
357 },
358 _pa: function (arr,date) {
359 if ( typeof date === 'boolean' ) { return new this._date(arr[0],arr[1],arr[2],0,0,0,0); }
360 return new this._date(date.getFullYear(), date.getMonth(), date.getDate(), arr[0], arr[1], arr[2], 0);
361 },
362 _makeDate: function (str) {
363 // Date Parser
364 str = $.trim(((this.__('useArabicIndic') === true)?this._dRep(str, -1):str));
365 var w = this,
366 o = this.options,
367 adv = w.__fmt(),
368 exp_input = null,
369 exp_names = [],
370 exp_format = null,
371 exp_temp = null,
372 date = new w._date(),
373 d = { year: -1, mont: -1, date: -1, hour: -1, mins: -1, secs: -1, week: false, wtyp: 4, wday: false, yday: false, meri: 0 },
374 i;
375
376 if ( typeof o.mode === 'undefined' ) { return date; }
377 if ( typeof w._parser[o.mode] !== 'undefined' ) { return w._parser[o.mode].apply(w,[str]); }
378
379 if ( o.mode === 'durationbox' || o.mode === 'durationflipbox' ) {
380 adv = adv.replace(/%D([a-z])/gi, function(match, oper) {
381 switch (oper) {
382 case 'd':
383 case 'l':
384 case 'M':
385 case 'S': return '(' + match + '|' +'[0-9]+' + ')';
386 default: return '.+?';
387 }
388 });
389
390 adv = new RegExp('^' + adv + '$');
391 exp_input = adv.exec(str);
392 exp_format = adv.exec(w.__fmt());
393
394 if ( exp_input === null || exp_input.length !== exp_format.length ) {
395 if ( typeof o.defaultValue === "number" && o.defaultValue > 0 ) {
396 return new w._date((w.initDate.getEpoch() + parseInt(o.defaultValue,10))*1000);
397 }
398 return new w._date(w.initDate.getTime());
399 }
400
401 exp_temp = w.initDate.getEpoch();
402 for ( i=0; i<exp_input.length; i++ ) { //0y 1m 2d 3h 4i 5s
403 if ( exp_format[i].match(/^%Dd$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)*60*60*24); }
404 if ( exp_format[i].match(/^%Dl$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)*60*60); }
405 if ( exp_format[i].match(/^%DM$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)*60); }
406 if ( exp_format[i].match(/^%DS$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)); }
407 }
408 return new w._date((exp_temp*1000));
409 }
410
411 adv = adv.replace(/%(0|-)*([a-z])/gi, function(match, pad, oper) {
412 exp_names.push(oper);
413 switch (oper) {
414 case 'p':
415 case 'P':
416 case 'b':
417 case 'B': return '(' + match + '|' +'.+?' + ')';
418 case 'H':
419 case 'k':
420 case 'I':
421 case 'l':
422 case 'm':
423 case 'M':
424 case 'S':
425 case 'V':
426 case 'U':
427 case 'u':
428 case 'W':
429 case 'd': return '(' + match + '|' + (( pad === '-' ) ? '[0-9]{1,2}' : '[0-9]{2}') + ')';
430 case 'j': return '(' + match + '|' + '[0-9]{3}' + ')';
431 case 's': return '(' + match + '|' + '[0-9]+' + ')';
432 case 'g':
433 case 'y': return '(' + match + '|' + '[0-9]{2}' + ')';
434 case 'E':
435 case 'G':
436 case 'Y': return '(' + match + '|' + '[0-9]{1,4}' + ')';
437 default: exp_names.pop(); return '.+?';
438 }
439 });
440
441 adv = new RegExp('^' + adv + '$');
442 exp_input = adv.exec(str);
443 exp_format = adv.exec(w.__fmt());
444
445 if ( exp_input === null || exp_input.length !== exp_format.length ) {
446 if ( o.defaultValue !== false ) {
447 switch ( typeof o.defaultValue ) {
448 case 'object':
449 if ( o.defaultValue.length === 3 ) {
450 date = w._pa(o.defaultValue,((o.mode === 'timebox' || o.mode === 'timeflipbox') ? date : false));
451 } break;
452 case 'number':
453 date = new w._date(o.defaultValue * 1000); break;
454 case 'string':
455 if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) {
456 exp_temp = o.defaultValue.split(':');
457 if ( exp_temp.length === 3 ) { date = w._pa([exp_temp[0],exp_temp[1],exp_temp[2]], date); }
458 else if ( exp_temp.length === 2 ) { date = w._pa([exp_temp[0],exp_temp[1],0], date); }
459 } else {
460 exp_temp = o.defaultValue.split('-');
461 if ( exp_temp.length === 3 ) { date = w._pa([exp_temp[0],exp_temp[1]-1,exp_temp[2]], false); }
462 } break;
463 }
464 }
465 if ( isNaN(date.getDate()) ) { date = new w._date(); }
466 } else {
467 for ( i=1; i<exp_input.length; i++ ) {
468 switch ( exp_names[i-1] ) {
469 case 's': return new w._date(parseInt(exp_input[i],10) * 1000);
470 case 'Y':
471 case 'G': d.year = parseInt(exp_input[i],10); break;
472 case 'E': d.year = parseInt(exp_input[i],10) - 543; break;
473 case 'y':
474 case 'g':
475 if ( o.afterToday === true || parseInt(exp_input[i],10) < 38 ) {
476 d.year = parseInt('20' + exp_input[i],10);
477 } else {
478 d.year = parseInt('19' + exp_input[i],10);
479 } break;
480 case 'm': d.mont = parseInt(exp_input[i],10)-1; break;
481 case 'd': d.date = parseInt(exp_input[i],10); break;
482 case 'H':
483 case 'k':
484 case 'I':
485 case 'l': d.hour = parseInt(exp_input[i],10); break;
486 case 'M': d.mins = parseInt(exp_input[i],10); break;
487 case 'S': d.secs = parseInt(exp_input[i],10); break;
488 case 'u': d.wday = parseInt(exp_input[i],10)-1; break;
489 case 'w': d.wday = parseInt(exp_input[i],10); break;
490 case 'j': d.yday = parseInt(exp_input[i],10); break;
491 case 'V': d.week = parseInt(exp_input[i],10); d.wtyp = 4; break;
492 case 'U': d.week = parseInt(exp_input[i],10); d.wtyp = 0; break;
493 case 'W': d.week = parseInt(exp_input[i],10); d.wtyp = 1; break;
494 case 'p':
495 case 'P': d.meri = (( exp_input[i].toLowerCase() === w.__('meridiem')[0].toLowerCase() )? -1:1); break;
496 case 'b':
497 exp_temp = $.inArray(exp_input[i], w.__('monthsOfYearShort'));
498 if ( exp_temp > -1 ) { d.mont = exp_temp; }
499 break;
500 case 'B':
501 exp_temp = $.inArray(exp_input[i], w.__('monthsOfYear'));
502 if ( exp_temp > -1 ) { d.mont = exp_temp; }
503 break;
504 }
505 }
506 if ( d.meri !== 0 ) {
507 if ( d.meri === -1 && d.hour === 12 ) { d.hour = 0; }
508 if ( d.meri === 1 && d.hour !== 12 ) { d.hour = d.hour + 12; }
509 }
510
511 date = new w._date(w._n(d.year,0),w._n(d.mont,0),w._n(d.date,1),w._n(d.hour,0),w._n(d.mins,0),w._n(d.secs,0),0);
512
513 if ( d.year < 100 && d.year !== -1 ) { date.setFullYear(d.year); }
514
515 if ( ( d.mont > -1 && d.date > -1 ) || ( d.hour > -1 && d.mins > -1 && d.secs > -1 ) ) { return date; }
516
517 if ( d.week !== false ) {
518 date.setDWeek(d.wtyp, d.week);
519 if ( d.date > -1 ) { date.setDate(d.date); }
520 }
521 if ( d.yday !== false ) { date.setD(1,0).setD(2,1).adj(2,(d.yday-1)); }
522 if ( d.wday !== false ) { date.adj(2,(d.wday - date.getDay())); }
523 }
524 return date;
525 },
526 _customformat: {
527 'default': function(oper, date) { return false; }
528 },
529 _formatter: function(format, date) {
530 var w = this,
531 o = this.options, tmp,
532 dur = {
533 part: [0,0,0,0], tp: 0
534 };
535
536 if ( o.mode === 'durationbox' || o.mode === 'durationflipbox' ) {
537 dur.tp = this.theDate.getEpoch() - this.initDate.getEpoch();
538 dur.part[0] = parseInt( dur.tp / (60*60*24),10); dur.tp -=(dur.part[0]*60*60*24); // Days
539 dur.part[1] = parseInt( dur.tp / (60*60),10); dur.tp -= (dur.part[1]*60*60); // Hours
540 dur.part[2] = parseInt( dur.tp / (60),10); dur.tp -= (dur.part[2]*60); // Minutes
541 dur.part[3] = dur.tp; // Seconds
542
543 if ( ! format.match(/%Dd/) ) { dur.part[1] += (dur.part[0]*24);}
544 if ( ! format.match(/%Dl/) ) { dur.part[2] += (dur.part[1]*60);}
545 if ( ! format.match(/%DM/) ) { dur.part[3] += (dur.part[2]*60);}
546 }
547
548 format = format.replace(/%(D|X|0|-)*([1-9a-zA-Z])/g, function(match, pad, oper) {
549 if ( pad === 'X' ) {
550 if ( typeof w._customformat[o.mode] !== 'undefined' ) { return w._customformat[o.mode](oper, date, o); }
551 return match;
552 }
553 if ( pad === 'D' ) {
554 switch ( oper ) {
555 case 'd': return dur.part[0];
556 case 'l': return w._zPad(dur.part[1]);
557 case 'M': return w._zPad(dur.part[2]);
558 case 'S': return w._zPad(dur.part[3]);
559 case 'A': return ((dur.part[0] > 1)?w.__('durationDays')[1]:w.__('durationDays')[0]);
560 default: return match;
561 }
562 }
563 switch ( oper ) {
564 case '%': // Literal %
565 return '%';
566 case 'a': // Short Day
567 return w.__('daysOfWeekShort')[date.getDay()];
568 case 'A': // Full Day of week
569 return w.__('daysOfWeek')[date.getDay()];
570 case 'b': // Short month
571 return w.__('monthsOfYearShort')[date.getMonth()];
572 case 'B': // Full month
573 return w.__('monthsOfYear')[date.getMonth()];
574 case 'C': // Century
575 return date.getFullYear().toString().substr(0,2);
576 case 'd': // Day of month
577 return (( pad === '-' ) ? date.getDate() : w._zPad(date.getDate()));
578 case 'H': // Hour (01..23)
579 case 'k':
580 return (( pad === '-' ) ? date.getHours() : w._zPad(date.getHours()));
581 case 'I': // Hour (01..12)
582 case 'l':
583 return (( pad === '-' ) ? ((date.getHours() === 0 || date.getHours() === 12)?12:((date.getHours()<12)?date.getHours():(date.getHours()-12))) : w._zPad(((date.getHours() === 0 || date.getHours() === 12)?12:((date.getHours()<12)?date.getHours():date.getHours()-12))));
584 case 'm': // Month
585 return (( pad === '-' ) ? date.getMonth()+1 : w._zPad(date.getMonth()+1));
586 case 'M': // Minutes
587 return (( pad === '-' ) ? date.getMinutes() : w._zPad(date.getMinutes()));
588 case 'p': // AM/PM (ucase)
589 return ((date.getHours() < 12)?w.__('meridiem')[0].toUpperCase():w.__('meridiem')[1].toUpperCase());
590 case 'P': // AM/PM (lcase)
591 return ((date.getHours() < 12)?w.__('meridiem')[0].toLowerCase():w.__('meridiem')[1].toLowerCase());
592 case 's': // Unix Seconds
593 return date.getEpoch();
594 case 'S': // Seconds
595 return (( pad === '-' ) ? date.getSeconds() : w._zPad(date.getSeconds()));
596 case 'u': // Day of week (1-7)
597 return (( pad === '-' ) ? date.getDay() + 1 : w._zPad(date.getDay() + 1));
598 case 'w': // Day of week
599 return date.getDay();
600 case 'y': // Year (2 digit)
601 return date.getFullYear().toString().substr(2,2);
602 case 'Y': // Year (4 digit)
603 return date.getFullYear();
604 case 'E': // BE (Buddist Era, 4 Digit)
605 return date.getFullYear() + 543;
606 case 'V':
607 return (( pad === '-' ) ? date.getDWeek(4) : w._zPad(date.getDWeek(4)));
608 case 'U':
609 return (( pad === '-' ) ? date.getDWeek(0) : w._zPad(date.getDWeek(0)));
610 case 'W':
611 return (( pad === '-' ) ? date.getDWeek(1) : w._zPad(date.getDWeek(1)));
612 case 'o': // Ordinals
613 if ( typeof w._ord[o.useLang] !== 'undefined' ) { return w._ord[o.useLang](date.getDate()); }
614 return w._ord['default'](date.getDate());
615 case 'j':
616 tmp = new Date(date.getFullYear(),0,1);
617 tmp = Math.ceil((date - tmp) / 86400000)+1;
618 return (( tmp < 100 ) ? (( tmp < 10 )? '00' : '0') : '' ) + String(tmp);
619 case 'G':
620 if ( date.getDWeek(4) === 1 && date.getMonth() > 0 ) { return date.getFullYear() + 1; }
621 if ( date.getDWeek(4) > 51 && date.getMonth() < 11 ) { return date.getFullYear() - 1; }
622 return date.getFullYear();
623 case 'g':
624 if ( date.getDWeek(4) === 1 && date.getMonth() > 0 ) { return parseInt(date.getFullYear().toString().substr(2,2),10) + 1; }
625 if ( date.getDWeek(4) > 51 && date.getMonth() < 11 ) { return parseInt(date.getFullYear().toString().substr(2,2),10) - 1; }
626 return date.getFullYear().toString().substr(2,2);
627 default:
628 return match;
629 }
630 });
631
632 if ( w.__('useArabicIndic') === true ) {
633 format = w._dRep(format);
634 }
635
636 return format;
637 },
638 _btwn: function(value, low, high) {
639 return ( value > low && value < high );
640 },
641 _minStepFix: function() {
642 var tempMin = this.theDate.get(4), tmp,
643 w = this,
644 o = this.options;
645
646 if ( o.minuteStep > 1 && tempMin % o.minuteStep > 0 ) {
647 if ( o.minuteStepRound < 0 ) {
648 tempMin = tempMin - (tempMin % o.minuteStep);
649 } else if ( o.minStepRound > 0 ) {
650 tempMin = tempMin + ( o.minuteStep - ( tempMin % o.minuteStep ) );
651 } else {
652 if ( tempMin % o.minuteStep < o.minuteStep / 2 ) {
653 tempMin = tempMin - (tempMin % o.minuteStep);
654 } else {
655 tempMin = tempMin + ( o.minuteStep - ( tempMin % o.minuteStep ) );
656 }
657 }
658 w.theDate.setMinutes(tempMin);
659 }
660 },
661 _offset: function(mode, amount, update) {
662 // Compute a date/time offset.
663 // update = false to prevent controls refresh
664 var w = this,
665 o = this.options,
666 ok = false;
667
668 mode = (mode || "").toLowerCase();
669
670 if ( typeof(update) === "undefined" ) { update = true; }
671 w.d.input.trigger('datebox', {'method':'offset', 'type':mode, 'amount':amount});
672
673 if ( mode !== 'a' && ( typeof o.rolloverMode[mode] === 'undefined' || o.rolloverMode[mode] === true )) {
674 ok = $.inArray(mode, ['y','m','d','h','i','s']);
675 } else {
676 switch(mode) {
677 case 'y': ok = 0; break;
678 case 'm':
679 if ( w._btwn(w.theDate.getMonth()+amount,-1,12) ) { ok = 1; }
680 break;
681 case 'd':
682 if ( w._btwn(w.theDate.getDate() + amount,0,(32 - w.theDate.copy([0],[0,0,32,13]).getDate() + 1) )) { ok = 2; }
683 break;
684 case 'h':
685 if ( w._btwn(w.theDate.getHours() + amount,-1,24) ) { ok = 3; }
686 break;
687 case 'i':
688 if ( w._btwn(w.theDate.getMinutes() + amount,-1,60) ) { ok = 4; }
689 break;
690 case 's':
691 if ( w._btwn(w.theDate.getSeconds() + amount,-1,60) ) { ok = 5; }
692 break;
693 case 'a':
694 w._offset('h',((amount>0)?1:-1)*12,false);
695 break;
696 }
697 }
698 if ( ok !== false ) { w.theDate.adj(ok,amount); }
699 if ( update === true ) { w.refresh(); }
700 if ( o.useImmediate ) { w.d.input.trigger('datebox', {'method':'doset'}); }
701 },
702 _startOffset: function(date) {
703 var o = this.options;
704
705 if ( o.startOffsetYears !== false ) {
706 date.adj(0, o.startOffsetYears);
707 }
708 if ( o.startOffsetMonths !== false ) {
709 date.adj(1, o.startOffsetMonths);
710 }
711 if ( o.startOffsetDays !== false ) {
712 date.adj(2, o.startOffsetDays);
713 }
714 return date;
715 },
716 _create: function() {
717 // Create the widget, called automatically by widget system
718 $( document ).trigger( "dateboxcreate" );
719
720 var w = this,
721 o = $.extend(this.options, (typeof this.element.jqmData('options') !== 'undefined') ? this.element.jqmData('options') : this._getLongOptions(this.element) ),
722 thisTheme = ( o.theme === false && typeof($(this).jqmData('theme')) === 'undefined' ) ?
723 ( ( typeof(this.element.parentsUntil(':jqmData(theme)').parent().jqmData('theme')) === 'undefined' ) ?
724 o.themeDefault : this.element.parentsUntil(':jqmData(theme)').parent().jqmData('theme') )
725 : o.theme,
726 trans = o.useAnimation ? o.transition : 'none',
727 d = o.useNewStyle === false ? {
728 input: this.element,
729 wrap: this.element.wrap('<div class="ui-input-datebox ui-shadow-inset ui-corner-all '+ (this.element.jqmData("mini") === true ? 'ui-mini ':'') +'ui-body-'+ thisTheme +'"></div>').parent(),
730 mainWrap: $("<div>", { "class": 'ui-datebox-container ui-overlay-shadow ui-corner-all ui-datebox-hidden '+trans+' ui-body-'+thisTheme} ).css('zIndex', o.zindex),
731 intHTML: false
732 } : {
733 input: this.element,
734 wrap: this.element,
735 mainWrap: $("<div>", { "class": 'ui-datebox-container ui-overlay-shadow ui-corner-all ui-datebox-hidden '+trans+' ui-body-'+thisTheme} ).css('zIndex', o.zindex),
736 intHTML: false
737 },
738 touch = ( typeof window.ontouchstart !== 'undefined' ),
739 drag = {
740 eStart : (touch ? 'touchstart' : 'mousedown')+'.datebox',
741 eMove : (touch ? 'touchmove' : 'mousemove')+'.datebox',
742 eEnd : (touch ? 'touchend' : 'mouseup')+'.datebox',
743 eEndA : (touch ? 'mouseup.datebox touchend.datebox touchcancel.datebox touchmove.datebox' : 'mouseup.datebox'),
744 move : false,
745 start : false,
746 end : false,
747 pos : false,
748 target : false,
749 delta : false,
750 tmp : false
751 },
752 calc = { },
753 ns = (typeof $.mobile.ns !== 'undefined')?$.mobile.ns:'';
754
755 $.extend(w, {d: d, ns: ns, drag: drag, touch:touch});
756
757 if ( o.usePlaceholder !== false ) {
758 if ( o.usePlaceholder === true && w._grabLabel() !== false ) { w.d.input.attr('placeholder', w._grabLabel()); }
759 if ( typeof o.usePlaceholder === 'string' ) { w.d.input.attr('placeholder', o.usePlaceholder); }
760 }
761
762 o.theme = thisTheme;
763
764 w.clearFunc = false;
765 w.disabled = false;
766 w.runButton = false;
767 w._date = window.Date;
768 w._enhanceDate();
769 w.baseID = w.d.input.attr('id');
770
771 w.initDate = new w._date();
772 w.theDate = (o.defaultValue) ? w._makeDate(o.defaultValue) : ( (w.d.input.val() !== "") ? w._makeDate(w.d.input.val()) : new w._date() );
773 w.initDone = false;
774
775 if ( o.showInitialValue === true ) {
776 w.d.input.val(w._formatter(w.__fmt(), w.theDate));
777 }
778
779 if ( o.useButton === true && o.useInline === false && o.useNewStyle === false ) {
780 w.d.open = $('<a href="#" class="ui-input-clear" title="'+this.__('tooltip')+'">'+this.__('tooltip')+'</a>')
781 .on(o.clickEvent, function(e) {
782 e.preventDefault();
783 if ( !w.disabled ) { w.d.input.trigger('datebox', {'method': 'open'}); w.d.wrap.parent().addClass('ui-focus'); w.d.input.parent().removeClass('ui-focus'); }
784 setTimeout( function() { $(e.target).closest('a').removeClass($.mobile.activeBtnClass); }, 300);
785 }).appendTo(w.d.wrap).buttonMarkup({icon: 'grid', iconpos: 'notext', corners:true, shadow:true})
786 .css({'vertical-align': 'middle', 'display': 'inline-block'});
787 }
788
789 w.d.screen = $("<div>", {'class':'ui-datebox-screen ui-datebox-hidden'+((o.useModal)?' ui-datebox-screen-modal':'')})
790 .css({'z-index': o.zindex-1})
791 .on(o.clickEventAlt, function(e) {
792 e.preventDefault();
793 w.d.input.trigger('datebox', {'method':'close'});
794 });
795
796 if ( o.enhanceInput === true && navigator.userAgent.match(/Android/i) ){
797 w.inputType = 'number';
798 } else {
799 w.inputType = 'text';
800 }
801
802 if ( o.hideInput ) { w.d.wrap.parent().hide(); }
803
804 if ( o.mobVer < 140 ) {
805 $('label[for=\''+w.d.input.attr('id')+'\']').addClass('ui-input-text').css('verticalAlign', 'middle');
806 }
807
808 w.d.wrap.on(o.clickEvent, function() {
809 if ( !w.disabled && ( o.noButtonFocusMode || o.focusMode ) ) {
810 w.d.input.trigger('datebox', {'method': 'open'});
811 w.d.wrap.addClass('ui-focus');
812 w.d.input.removeClass('ui-focus');
813 }
814 });
815
816 w.d.input
817 .removeClass('ui-corner-all ui-shadow-inset')
818 .bind(w.touch?'touchend':'click', function(e){
819 if ( w.disabled === false && o.useNewStyle === true && o.useFocus === false ) {
820 if ( ((w.touch ? e.originalEvent.changedTouches[0].pageX : e.pageX) - e.target.offsetLeft) > (e.target.offsetWidth - 20) ) {
821 w.d.input.trigger('datebox', {'method': 'open'}); w.d.wrap.parent().addClass('ui-focus'); w.d.input.removeClass('ui-focus');
822 //setTimeout(function(){w.d.wrap.addClass('ui-focus');}, 200);
823 }
824 }
825 })
826 .focus(function(){
827 if ( w.disabled === false && o.useFocus === true ) {
828 w.d.input.trigger('datebox', {'method': 'open'}); w.d.wrap.addClass('ui-focus'); w.d.input.removeClass('ui-focus');
829 if ( o.useNewStyle === false ) { w.d.input.parent().removeClass('ui-focus'); w.d.wrap.parent().addClass('ui-focus'); }
830 }
831 if ( o.useNewStyle === false ) { w.d.input.removeClass('ui-focus'); }
832 })
833 .blur(function(){
834 w.d.wrap.removeClass('ui-focus');
835 w.d.input.removeClass('ui-focus');
836 })
837 .change(function() {
838 w.theDate = w._makeDate(w.d.input.val());
839 w.refresh();
840 })
841 .attr("readonly", o.lockInput)
842 .on('datebox', w._event);
843
844 if ( o.useNewStyle === true ) {
845 w.d.input.addClass('ui-corner-all '+((o.useAltIcon===true)?'ui-icon-datebox-alt':'ui-icon-datebox'));
846 if ( o.overrideStyleClass !== false ) { w.d.input.addClass(o.overrideStyleClass); }
847 } else {
848 w.d.input.parent().css('border', 'none').removeClass('ui-shadow-inset');
849 }
850
851 w.d.wrap.parent().on(o.clickEvent, function() {
852 if ( !w.disabled && o.useFocus === true && o.useNewStyle === false ) {
853 w.d.input.trigger('datebox', {'method': 'open'}); w.d.wrap.addClass('ui-focus'); w.d.input.removeClass('ui-focus');
854 setTimeout(function(){
855 w.d.wrap.removeClass('ui-focus');
856 w.d.wrap.parent().addClass('ui-focus');
857 }, 500);
858 }
859 });
860
861 // Check if mousewheel plugin is loaded
862 if ( typeof $.event.special.mousewheel !== 'undefined' ) { w.wheelExists = true; }
863
864 // Disable when done if element attribute disabled is true.
865 if ( w.d.input.is(':disabled') ) {
866 w.disable();
867 }
868
869 if ( o.useInline === true || o.useInlineBlind ) { w.open(); }
870
871 w.applyMinMax(false, false);
872
873 //Throw dateboxinit event
874 $( document ).trigger( "dateboxaftercreate" );
875 },
876 applyMinMax: function(refresh, override) {
877 var w = this,
878 o = this.options,
879 calc = {};
880
881 if ( typeof refresh === 'undefined' ) { refresh = false; }
882 if ( typeof override === 'undefined' ) { override = true; }
883
884 if ( ( override === true || o.minDays === false ) && typeof(w.d.input.attr('min')) !== 'undefined' ) {
885 calc.today = new w._date();
886 calc.lod = 24 * 60 * 60 * 1000;
887 calc.todayc = new w._date(calc.today.getFullYear(), calc.today.getMonth(), calc.today.getDate(), 0,0,0,0);
888 calc.fromel = w.d.input.attr('min').split('-');
889 calc.compdt = new w._date(calc.fromel[0],calc.fromel[1]-1,calc.fromel[2],0,0,0,0);
890 o.minDays = parseInt((((calc.compdt.getTime() - calc.todayc.getTime()) / calc.lod))*-1,10);
891 }
892 if ( ( override === true || o.maxDays === false ) && typeof(w.d.input.attr('max')) !== 'undefined' ) {
893 calc.today = new w._date();
894 calc.lod = 24 * 60 * 60 * 1000;
895 calc.todayc = new w._date(calc.today.getFullYear(), calc.today.getMonth(), calc.today.getDate(), 0,0,0,0);
896 calc.fromel = w.d.input.attr('max').split('-');
897 calc.compdt = new w._date(calc.fromel[0],calc.fromel[1]-1,calc.fromel[2],0,0,0,0);
898 o.maxDays = parseInt((((calc.compdt.getTime() - calc.todayc.getTime()) / calc.lod)),10);
899 }
900
901 if ( refresh === true ) { w.refresh(); }
902 },
903 _build: {
904 'default': function () {
905 this.d.headerText = "Error";
906 this.d.intHTML = $("<div class='ui-body-b'><h2 style='text-align:center'>There is no mode by that name loaded / mode not given</h2></div>");
907 }
908 },
909 _applyCoords: function(e) {
910 var w = e.widget,
911 o = e.widget.options,
912 fixd = {
913 h: $.mobile.activePage.find('.ui-header').jqmData('position'),
914 f: $.mobile.activePage.find('.ui-footer').jqmData('position'),
915 fh: $.mobile.activePage.find('.ui-footer').outerHeight(),
916 hh: $.mobile.activePage.find('.ui-header').outerHeight()
917 },
918 iput = {
919 x: w.d.wrap.offset().left + (w.d.wrap.outerWidth() / 2),
920 y: w.d.wrap.offset().top + (w.d.wrap.outerHeight() / 2)
921 },
922 size = {
923 w: w.d.mainWrap.outerWidth(),
924 h: w.d.mainWrap.outerHeight()
925 },
926 doc = {
927 t: $(window).scrollTop(),
928 h: $(window).height(),
929 w: $.mobile.activePage.width(),
930 ah: $(document).height()
931 },
932 pos = {
933 y: (o.centerVert) ? doc.t + ((doc.h / 2) - (size.h / 2)) : iput.y - ( size.h / 2 ),
934 x: (doc.w < 400 || o.centerHoriz ) ? (doc.w / 2) - (size.w /2) : iput.x - (size.w / 2)
935 };
936
937 if ( o.centerVert === false ) {
938 if ( o.hideFixedToolbars === true && ( typeof fixd.f !== 'undefined' || typeof fixd.h !== 'undefined' )) {
939 $.mobile.activePage.find(":jqmData(position='fixed')").fixedtoolbar('hide');
940 fixd.f = undefined;
941 fixd.h = undefined;
942 }
943
944 if ( typeof fixd.f !== 'undefined' ) {
945 if ( ( pos.y + size.h ) > ( doc.h - fixd.fh - 2 ) ) {
946 pos.y = doc.h - fixd.fh - 2 - size.h;
947 }
948 } else {
949 if ( ( pos.y + size.h ) > ( doc.ah - fixd.fh - 2 ) ) {
950 pos.y = doc.ah - fixd.fh - 2 - size.h;
951 }
952 if ( ( doc.h + doc.t ) < ( size.h + pos.y + 2 ) ) {
953 pos.y = doc.h + doc.t - size.h - 2;
954 }
955 }
956
957 if ( typeof fixd.h !== 'undefined' ) {
958 if ( ( doc.t + fixd.hh + 2 ) > pos.y ) {
959 pos.y = doc.t + fixd.hh + 2;
960 }
961 } else {
962 if ( fixd.hh + 2 > pos.y ) {
963 pos.y = fixd.hh + 2;
964 }
965 if ( pos.y < doc.t + 2 ) {
966 pos.y = doc.t + 2;
967 }
968 }
969 }
970 w.d.mainWrap.css({'position': 'absolute', 'top': pos.y, 'left': pos.x});
971 },
972 _drag: {
973 'default': function () { return false; }
974 },
975 open: function () {
976 var w = this,
977 o = this.options,
978 popopts = {},
979 basepop = {'history':false},
980 qns = 'data-'+this.ns,
981 trans = o.useAnimation ? o.transition : 'none';
982
983 if ( o.useFocus === true && w.fastReopen === true ) { w.d.input.blur(); return false; }
984 if ( w.clearFunc !== false ) {
985 clearTimeout(w.clearFunc); w.clearFunc = false;
986 }
987
988 // Call the open callback if provided. Additionally, if this
989 // returns false then the open/update will stop.
990 if ( o.openCallback !== false ) {
991 if ( ! $.isFunction(o.openCallback) ) {
992 if ( typeof window[o.openCallback] !== 'undefined' ) {
993 o.openCallback = window[o.openCallback];
994 } else {
995 o.openCallback = new Function(o.openCallback);
996 }
997 }
998 if ( o.openCallback.apply(w, $.merge([w.theDate],o.openCallbackArgs)) === false ) { return false; }
999 }
1000
1001 w.theDate = w._makeDate(w.d.input.val());
1002 if ( w.d.input.val() === "" ) { w._startOffset(w.theDate); }
1003 w.d.input.blur();
1004
1005 if ( typeof w._build[o.mode] === 'undefined' ) {
1006 w._build['default'].apply(w,[]);
1007 } else {
1008 w._build[o.mode].apply(w,[]);
1009 }
1010 if ( typeof w._drag[o.mode] !== 'undefined' ) {
1011 w._drag[o.mode].apply(w, []);
1012 }
1013 w.d.input.trigger('datebox', {'method':'refresh'});
1014 if ( w.__('useArabicIndic') === true ) { w._doIndic(); }
1015
1016 if ( ( o.useInline === true || o.useInlineBlind === true ) && w.initDone === false ) {
1017 w.d.mainWrap.append(w.d.intHTML);
1018 w.d.input.parent().parent().append(w.d.mainWrap);
1019 w.d.mainWrap.removeClass('ui-datebox-hidden');
1020 if ( o.useInline === true ) {
1021 w.d.mainWrap.addClass('ui-datebox-inline');
1022 } else {
1023 w.d.mainWrap.addClass('ui-datebox-inlineblind');
1024 w.d.mainWrap.hide();
1025 }
1026 w.initDone = false;
1027 w.d.input.trigger('datebox',{'method':'postrefresh'});
1028 }
1029
1030 if ( o.useImmediate ) { w.d.input.trigger('datebox', {'method':'doset'}); }
1031 if ( o.useInline ) { return true; }
1032 if ( o.useInlineBlind ) {
1033 if ( w.initDone ) { w.d.mainWrap.slideDown(); }
1034 else { w.initDone = true; }
1035 return true;
1036 }
1037 if ( w.d.intHTML.is(':visible') ) { return false; } // Ignore if already open
1038
1039 if ( o.enablePopup === true ) {
1040 w.d.dialogPage = false;
1041 w.d.mainWrap.empty();
1042 if ( o.useHeader === true ) {
1043 w.d.headHTML = $('<div class="ui-header ui-bar-'+o.themeHeader+'"></div>');
1044 $("<a class='ui-btn-left' href='#'>Close</a>").appendTo(w.d.headHTML)
1045 .buttonMarkup({ theme : o.themeHeader, icon : 'delete', iconpos: 'notext', corners: true, shadow : true })
1046 .on(o.clickEventAlt, function(e) { e.preventDefault(); w.d.input.trigger('datebox', {'method':'close'}); });
1047 $('<h1 class="ui-title">'+w.d.headerText+'</h1>').appendTo(w.d.headHTML);
1048 w.d.mainWrap.append(w.d.headHTML);
1049 }
1050 w.d.mainWrap.append(w.d.intHTML).css('zIndex', o.zindex);
1051 w.d.input.trigger('datebox',{'method':'postrefresh'});
1052
1053 if ( o.useAnimation === true ) {
1054 popopts.transition = o.transition;
1055 } else {
1056 popopts.transition = "none";
1057 }
1058
1059 if ( o.popupForceX !== false && o.popupForceY !== false ) {
1060 popopts.x = o.popupForceX;
1061 popopts.y = o.popupForceY;
1062 }
1063
1064 if ( o.popupPosition !== false ) {
1065 popopts.positionTo = o.popupPosition;
1066 } else {
1067 if ( typeof w.baseID !== undefined ) {
1068 popopts.positionTo = '#' + w.baseID;
1069 } else {
1070 popopts.positionTo = 'window';
1071 }
1072 }
1073
1074 if ( o.useModal === true ) { basepop.overlayTheme = "a"; }
1075
1076 w.d.mainWrap.removeClass('ui-datebox-hidden').popup(basepop).popup("open", popopts);
1077 w.refresh();
1078 } else {
1079 if ( o.dialogForce || ( o.dialogEnable && window.width() < 400 ) ) {
1080 w.d.dialogPage = $("<div "+qns+"role='dialog' "+qns+"theme='"+o.theme+"' >" +
1081 "<div "+qns+"role='header' "+qns+"theme='"+o.themeHeader+"'>" +
1082 "<h1>"+w.d.headerText+"</h1></div><div "+qns+"role='content'></div>")
1083 .appendTo( $.mobile.pageContainer )
1084 .page().css('minHeight', '0px').addClass(trans);
1085 w.d.dialogPage.find('.ui-header').find('a').off('click vclick').on(o.clickEventAlt, function(e) { e.preventDefault(); w.d.input.trigger('datebox', {'method':'close'}); });
1086 w.d.mainWrap.append(w.d.intHTML).css({'marginLeft':'auto', 'marginRight':'auto'}).removeClass('ui-datebox-hidden');
1087 w.d.dialogPage.find('.ui-content').append(w.d.mainWrap);
1088 w.d.input.trigger('datebox',{'method':'postrefresh'});
1089 $.mobile.activePage.off( "pagehide.remove" );
1090 $.mobile.changePage(w.d.dialogPage, {'transition': trans});
1091 } else {
1092 w.d.dialogPage = false;
1093 w.d.mainWrap.empty();
1094 if ( o.useHeader === true ) {
1095 w.d.headHTML = $('<div class="ui-header ui-bar-'+o.themeHeader+'"></div>');
1096 $("<a class='ui-btn-left' href='#'>Close</a>").appendTo(w.d.headHTML)
1097 .buttonMarkup({ theme : o.themeHeader, icon : 'delete', iconpos: 'notext', corners: true, shadow : true })
1098 .on(o.clickEventAlt, function(e) { e.preventDefault(); w.d.input.trigger('datebox', {'method':'close'}); });
1099 $('<h1 class="ui-title">'+w.d.headerText+'</h1>').appendTo(w.d.headHTML);
1100 w.d.mainWrap.append(w.d.headHTML);
1101 }
1102 w.d.mainWrap.append(w.d.intHTML).css('zIndex', o.zindex);
1103 w.d.mainWrap.appendTo($.mobile.activePage);
1104 w.d.screen.appendTo($.mobile.activePage);
1105 w.d.input.trigger('datebox',{'method':'postrefresh'});
1106 w._applyCoords({widget:w});
1107
1108 if ( o.useModal === true ) {
1109 if(o.useAnimation) {
1110 w.d.screen.fadeIn('slow');
1111 } else {
1112 w.d.screen.show();
1113 }
1114 } else {
1115 setTimeout(function () { w.d.screen.removeClass('ui-datebox-hidden');}, 500);
1116 }
1117
1118 w.d.mainWrap.addClass('ui-overlay-shadow in').removeClass('ui-datebox-hidden');
1119
1120 $(document).on('orientationchange.datebox', {widget:w}, function(e) { w._applyCoords(e.data); });
1121 if ( o.resizeListener === true ) {
1122 $(window).on('resize.datebox', {widget:w}, function (e) { w._applyCoords(e.data); });
1123 }
1124 }
1125 }
1126 },
1127 close: function() {
1128 var w = this,
1129 o = this.options;
1130
1131 if ( o.useInlineBlind === true ) { w.d.mainWrap.slideUp(); return true;}
1132 if ( o.useInline === true || w.d.intHTML === false ) { return true; }
1133
1134 if ( w.d.dialogPage !== false ) {
1135 $(w.d.dialogPage).dialog('close');
1136
1137 if ( ! $.mobile.activePage.jqmData('mobile-page').options.domCache ) {
1138 $.mobile.activePage.on('pagehide.remove', function () { $(this).remove(); });
1139 }
1140
1141 w.d.intHTML.detach().empty();
1142 w.d.mainWrap.detach().empty();
1143 w.d.wrap.removeClass('ui-focus');
1144 w.clearFunc = setTimeout(function () { w.d.dialogPage.empty().remove(); w.clearFunc = false; }, 1500);
1145 } else {
1146 if ( o.enablePopup === true ) {
1147 w.d.mainWrap.popup('close');
1148 w.d.wrap.removeClass('ui-focus');
1149 } else {
1150 if ( o.useModal ) {
1151 if(o.useAnimation) {
1152 w.d.screen.fadeOut('slow');
1153 } else {
1154 w.d.screen.hide();
1155 }
1156 } else {
1157 w.d.screen.addClass('ui-datebox-hidden');
1158 }
1159 w.d.screen.detach();
1160 w.d.mainWrap.addClass('ui-datebox-hidden').removeAttr('style').removeClass('in ui-overlay-shadow').empty().detach();
1161 w.d.intHTML.detach();
1162 w.d.wrap.removeClass('ui-focus');
1163
1164 $(document).off('orientationchange.datebox');
1165 if ( o.resizeListener === true ) {
1166 $(window).off('resize.datebox');
1167 }
1168 }
1169 }
1170 w.d.wrap.parent().removeClass('ui-focus');
1171
1172 $(document).off(w.drag.eMove);
1173 $(document).off(w.drag.eEnd);
1174 $(document).off(w.drag.eEndA);
1175
1176 if ( o.useFocus ) {
1177 w.fastReopen = true;
1178 setTimeout(function(t) { return function () { t.fastReopen = false; };}(w), 300);
1179 }
1180
1181 if ( o.closeCallback !== false ) {
1182 if ( ! $.isFunction(o.closeCallback) ) {
1183 if ( typeof window[o.closeCallback] !== 'undefined' ) {
1184 o.closeCallback = window[o.closeCallback];
1185 } else {
1186 o.closeCallback = new Function(o.closeCallback);
1187 }
1188 }
1189 o.closeCallback.apply(w, $.merge([w.theDate], o.closeCallbackArgs));
1190 }
1191 },
1192 refresh: function() {
1193 if ( typeof this._build[this.options.mode] === 'undefined' ) {
1194 this._build['default'].apply(this,[]);
1195 } else {
1196 this._build[this.options.mode].apply(this,[]);
1197 }
1198 if ( this.__('useArabicIndic') === true ) { this._doIndic(); }
1199 this.d.mainWrap.append(this.d.intHTML);
1200 this.d.input.trigger('datebox',{'method':'postrefresh'});
1201 },
1202 _check: function() {
1203 var w = this,
1204 td = null,
1205 o = this.options;
1206
1207 w.dateOK = true;
1208
1209 if ( o.afterToday !== false ) {
1210 td = new w._date();
1211 if ( w.theDate < td ) { w.theDate = td; }
1212 }
1213 if ( o.beforeToday !== false ) {
1214 td = new w._date();
1215 if ( w.theDate > td ) { w.theDate = td; }
1216 }
1217 if ( o.maxDays !== false ) {
1218 td = new w._date();
1219 td.adj(2, o.maxDays);
1220 if ( w.theDate > td ) { w.theDate = td; }
1221 }
1222 if ( o.minDays !== false ) {
1223 td = new w._date();
1224 td.adj(2, -1*o.minDays);
1225 if ( w.theDate < td ) { w.theDate = td; }
1226 }
1227 if ( o.minHour !== false ) {
1228 if ( w.theDate.getHours() < o.minHour ) {
1229 w.theDate.setHours(o.minHour);
1230 }
1231 }
1232 if ( o.maxHour !== false ) {
1233 if ( w.theDate.getHours() > o.maxHour ) {
1234 w.theDate.setHours(o.maxHour);
1235 }
1236 }
1237 if ( o.maxYear !== false ) {
1238 td = new w._date(o.maxYear, 0, 1);
1239 td.adj(2, -1);
1240 if ( w.theDate > td ) { w.theDate = td; }
1241 }
1242 if ( o.minYear !== false ) {
1243 td = new w._date(o.minYear, 0, 1);
1244 if ( w.theDate < td ) { w.theDate = td; }
1245 }
1246
1247 if ( $.inArray(o.mode, ['timebox','durationbox','durationflipbox','timeflipbox']) > -1 ) {
1248 if ( o.mode === 'timeflipbox' && o.validHours !== false ) {
1249 if ( $.inArray(w.theDate.getHours(), o.validHours) < 0 ) { w.dateOK = false; }
1250 }
1251 } else {
1252 if ( o.blackDatesRec !== false ) {
1253 for ( i=0; i<o.blackDatesRec.length; i++ ) {
1254 if (
1255 ( o.blackDatesRec[i][0] === -1 || o.blackDatesRec[i][0] === year ) &&
1256 ( o.blackDatesRec[i][1] === -1 || o.blackDatesRec[i][1] === month ) &&
1257 ( o.blackDatesRec[i][2] === -1 || o.blackDatesRec[i][2] === date )
1258 ) { w.dateOK = false; }
1259 }
1260 }
1261 if ( o.blackDates !== false ) {
1262 if ( $.inArray(w.theDate.iso(), o.blackDates) > -1 ) { w.dateOK = false; }
1263 }
1264 if ( o.blackDays !== false ) {
1265 if ( $.inArray(w.theDate.getDay(), o.blackDays) > -1 ) { w.dateOK = false; }
1266 }
1267 }
1268 },
1269 _grabLabel: function() {
1270 var w = this,
1271 o = this.options;
1272
1273 if ( typeof o.overrideDialogLabel === 'undefined' ) {
1274 if ( typeof w.d.input.attr('placeholder') !== 'undefined' ) { return w.d.input.attr('placeholder'); }
1275 if ( typeof w.d.input.attr('title') !== 'undefined' ) { return w.d.input.attr('title'); }
1276 if ( w.d.wrap.parent().find('label[for=\''+w.d.input.attr('id')+'\']').text() !== '' ) {
1277 return w.d.wrap.parent().find('label[for=\''+w.d.input.attr('id')+'\']').text();
1278 }
1279 return false;
1280 }
1281 return o.overrideDialogLabel;
1282 },
1283 _makeEl: function(source, parts) {
1284 var part = false,
1285 retty = false;
1286
1287 retty = source.clone();
1288
1289 if ( typeof parts.attr !== 'undefined' ) {
1290 for ( part in parts.attr ) {
1291 if ( parts.attr.hasOwnProperty(part) ) {
1292 retty.jqmData(part, parts.attr[part]);
1293 }
1294 }
1295 }
1296 return retty;
1297 },
1298 _getLongOptions: function(element) {
1299 var key, retty = {}, prefix, temp;
1300
1301 if ( $.mobile.ns === "" ) {
1302 prefix = "datebox";
1303 } else {
1304 prefix = $.mobile.ns.substr(0, $.mobile.ns.length - 1) + 'Datebox';
1305 }
1306
1307 for ( key in element.data() ) {
1308 if ( key.substr(0, prefix.length) === prefix && key.length > prefix.length ) {
1309 temp = key.substr(prefix.length);
1310 temp = temp.charAt(0).toLowerCase() + temp.slice(1);
1311 retty[temp] = element.data(key);
1312 }
1313 }
1314 return retty;
1315 },
1316 disable: function(){
1317 // Disable the element
1318 this.d.input.attr("disabled",true);
1319 this.d.wrap.addClass("ui-disabled").blur();
1320 this.disabled = true;
1321 this.d.input.trigger('datebox', {'method':'disable'});
1322 },
1323 enable: function(){
1324 // Enable the element
1325 this.d.input.attr("disabled", false);
1326 this.d.wrap.removeClass("ui-disabled");
1327 this.disabled = false;
1328 this.d.input.trigger('datebox', {'method':'enable'});
1329 },
1330 _setOption: function() {
1331 $.Widget.prototype._setOption.apply( this, arguments );
1332 this.refresh();
1333 },
1334 getTheDate: function() {
1335 return this.theDate;
1336 },
1337 getLastDur: function() {
1338 return this.lastDuration;
1339 },
1340 setTheDate: function(newDate) {
1341 this.theDate = newDate;
1342 this.refresh();
1343 },
1344 callFormat: function(format, date) {
1345 return this._formatter(format, date);
1346 }
1347 });
1348
1349 // Degrade date inputs to text inputs, suppress standard UI functions.
1350 $( document ).on( "pagebeforecreate", function( e ) {
1351 $( ":jqmData(role='datebox')", e.target ).each(function() {
1352 $(this).prop('type', 'text');
1353 });
1354 });
1355 // Automatically bind to data-role='datebox' items.
1356 $( document ).on( "pagecreate create", function( e ){
1357 $( document ).trigger( "dateboxbeforecreate" );
1358 $( ":jqmData(role='datebox')", e.target ).each(function() {
1359 var defed = typeof ($(this).data(parseInt($.mobile.version.replace(/\./g,''),10) > 111 ? 'mobile-datebox' : 'datebox'));
1360 if ( defed === "undefined" ) {
1361 $(this).datebox();
1362 }
1363 });
1364 });
1365})( jQuery );
Note: See TracBrowser for help on using the repository browser.