[101] | 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 |
|
---|
| 8 | (function($, undefined ) {
|
---|
| 9 | // We can greatly reduce some operations by adding to the date object.
|
---|
| 10 | Date.prototype.getISO = function () { return String(this.getFullYear()) + '-' + (( this.getMonth() < 9 ) ? "0" : "") + String(this.getMonth()+1) + '-' + ((this.getDate() < 10 ) ? "0" : "") + String(this.getDate()); };
|
---|
| 11 | Date.prototype.getComp = function () { return parseInt(this.getISO().replace(/-/g,''),10); }
|
---|
| 12 | Date.prototype.copy = function() { return this.copymod(); }
|
---|
| 13 | Date.prototype.copymod = function(adj,over) {
|
---|
| 14 | if ( typeof adj === 'undefined' ) { adj = [0,0,0,0,0,0]; }
|
---|
| 15 | if ( typeof over === 'undefined' ) { over = [0,0,0,0,0,0]; }
|
---|
| 16 | while ( adj.length < 6 ) { adj.push(0); }
|
---|
| 17 | while ( over.length < 6 ) { over.push(0); }
|
---|
| 18 | return new Date(((over[0] > 0 ) ? over[0] : this.getFullYear() + adj[0]),((over[1] > 0 ) ? over[1] : this.getMonth() + adj[1]),((over[2] > 0 ) ? over[2] : this.getDate() + adj[2]),((over[3] > 0 ) ? over[3] : this.getHours() + adj[3]),((over[4] > 0 ) ? over[4] : this.getMinutes() + adj[4]),((over[5] > 0 ) ? over[5] : this.getSeconds() + adj[5]),0);
|
---|
| 19 | }
|
---|
| 20 | Date.prototype.getEpoch = function() { return (this.getTime() - this.getMilliseconds()) / 1000; }
|
---|
| 21 | Date.prototype.adjust = function (type, amount) {
|
---|
| 22 | switch (type) {
|
---|
| 23 | case 'y': this.setFullYear(this.getFullYear() + amount); break;
|
---|
| 24 | case 'm': this.setMonth(this.getMonth() + amount); break;
|
---|
| 25 | case 'd': this.setDate(this.getDate() + amount); break;
|
---|
| 26 | case 'h': this.setHours(this.getHours() + amount); break;
|
---|
| 27 | case 'i': this.setMinutes(this.getMinutes() + amount); break;
|
---|
| 28 | case 's': this.setSeconds(this.getSeconds() + amount); break;
|
---|
| 29 | }
|
---|
| 30 | return this.getTime();
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | $.widget( "mobile.datebox", $.mobile.widget, {
|
---|
| 34 | options: {
|
---|
| 35 | // All widget options, including some internal runtime details
|
---|
| 36 | version: '1.0.1-2012022700', // jQMMajor.jQMMinor.DBoxMinor-YrMoDaySerial
|
---|
| 37 | theme: false,
|
---|
| 38 | defaultTheme: 'c',
|
---|
| 39 | pickPageTheme: 'b',
|
---|
| 40 | pickPageInputTheme: 'e',
|
---|
| 41 | pickPageButtonTheme: 'a',
|
---|
| 42 | pickPageHighButtonTheme: 'e',
|
---|
| 43 | pickPageOHighButtonTheme: 'e',
|
---|
| 44 | pickPageOAHighButtonTheme: 'e',
|
---|
| 45 | pickPageODHighButtonTheme: 'e',
|
---|
| 46 | pickPageTodayButtonTheme: 'e',
|
---|
| 47 | pickPageSlideButtonTheme: 'd',
|
---|
| 48 | pickPageFlipButtonTheme: 'b',
|
---|
| 49 | forceInheritTheme: false,
|
---|
| 50 | centerWindow: false,
|
---|
| 51 | calHighToday: true,
|
---|
| 52 | calHighPicked: true,
|
---|
| 53 | transition: 'pop',
|
---|
| 54 | noAnimation: false,
|
---|
| 55 | disableManualInput: false,
|
---|
| 56 |
|
---|
| 57 | disabled: false,
|
---|
| 58 | wheelExists: false,
|
---|
| 59 | swipeEnabled: true,
|
---|
| 60 | zindex: '500',
|
---|
| 61 | debug: false,
|
---|
| 62 | clickEvent: 'vclick',
|
---|
| 63 | numberInputEnhance: true,
|
---|
| 64 | internalInputType: 'text',
|
---|
| 65 | resizeListener: true,
|
---|
| 66 |
|
---|
| 67 | titleDialogLabel: false,
|
---|
| 68 | meridiemLetters: ['AM', 'PM'],
|
---|
| 69 | timeOutputOverride: false,
|
---|
| 70 | timeFormats: { '12': '%l:%M %p', '24': '%k:%M' },
|
---|
| 71 | durationFormat: 'DD ddd, hh:ii:ss',
|
---|
| 72 | timeOutput: false,
|
---|
| 73 | rolloverMode: { 'm': true, 'd': true, 'h': true, 'i': true, 's': true },
|
---|
| 74 |
|
---|
| 75 | mode: 'datebox',
|
---|
| 76 | calShowDays: true,
|
---|
| 77 | calShowOnlyMonth: false,
|
---|
| 78 | useDialogForceTrue: false,
|
---|
| 79 | useDialogForceFalse: true,
|
---|
| 80 | fullScreen: false,
|
---|
| 81 | fullScreenAlways: false,
|
---|
| 82 | useDialog: false,
|
---|
| 83 | useModal: false,
|
---|
| 84 | useInline: false,
|
---|
| 85 | useInlineBlind: false,
|
---|
| 86 | useClearButton: false,
|
---|
| 87 | collapseButtons: false,
|
---|
| 88 | noButtonFocusMode: false,
|
---|
| 89 | focusMode: false,
|
---|
| 90 | noButton: false,
|
---|
| 91 | noSetButton: false,
|
---|
| 92 | openCallback: false,
|
---|
| 93 | openCallbackArgs: [],
|
---|
| 94 | closeCallback: false,
|
---|
| 95 | closeCallbackArgs: [],
|
---|
| 96 | open: false,
|
---|
| 97 | nestedBox: false,
|
---|
| 98 | lastDuration: false,
|
---|
| 99 |
|
---|
| 100 | fieldsOrder: false,
|
---|
| 101 | fieldsOrderOverride: false,
|
---|
| 102 | durationOrder: ['d', 'h', 'i', 's'],
|
---|
| 103 | defaultDateFormat: '%Y-%m-%d',
|
---|
| 104 | dateFormat: false,
|
---|
| 105 | timeFormatOverride: false,
|
---|
| 106 | headerFormat: false,
|
---|
| 107 | dateOutput: false,
|
---|
| 108 | minuteStep: 1,
|
---|
| 109 | calTodayButton: false,
|
---|
| 110 | calWeekMode: false,
|
---|
| 111 | calWeekModeFirstDay: 1,
|
---|
| 112 | calWeekModeHighlight: true,
|
---|
| 113 | calStartDay: false,
|
---|
| 114 | defaultPickerValue: false,
|
---|
| 115 | defaultDate : false, //this is deprecated and will be removed in the future versions (ok, may be not)
|
---|
| 116 | minYear: false,
|
---|
| 117 | maxYear: false,
|
---|
| 118 | afterToday: false,
|
---|
| 119 | beforeToday: false,
|
---|
| 120 | maxDays: false,
|
---|
| 121 | minDays: false,
|
---|
| 122 | highDays: false,
|
---|
| 123 | highDates: false,
|
---|
| 124 | highDatesAlt: false,
|
---|
| 125 | blackDays: false,
|
---|
| 126 | blackDates: false,
|
---|
| 127 | enableDates: false,
|
---|
| 128 | fixDateArrays: false,
|
---|
| 129 | durationSteppers: {'d': 1, 'h': 1, 'i': 1, 's': 1},
|
---|
| 130 | useLang: 'en',
|
---|
| 131 | lang: {
|
---|
| 132 | 'en' : {
|
---|
| 133 | setDateButtonLabel: 'Set Date',
|
---|
| 134 | setTimeButtonLabel: 'Set Time',
|
---|
| 135 | setDurationButtonLabel: 'Set Duration',
|
---|
| 136 | calTodayButtonLabel: 'Jump to Today',
|
---|
| 137 | titleDateDialogLabel: 'Set Date',
|
---|
| 138 | titleTimeDialogLabel: 'Set Time',
|
---|
| 139 | daysOfWeek: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
---|
| 140 | daysOfWeekShort: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
---|
| 141 | monthsOfYear: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
---|
| 142 | monthsOfYearShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
---|
| 143 | durationLabel: ['Days', 'Hours', 'Minutes', 'Seconds'],
|
---|
| 144 | durationDays: ['Day', 'Days'],
|
---|
| 145 | timeFormat: 24,
|
---|
| 146 | headerFormat: '%A, %B %-d, %Y',
|
---|
| 147 | tooltip: 'Open Date Picker',
|
---|
| 148 | nextMonth: 'Next Month',
|
---|
| 149 | prevMonth: 'Previous Month',
|
---|
| 150 | dateFieldOrder: ['m', 'd', 'y'],
|
---|
| 151 | timeFieldOrder: ['h', 'i', 'a'],
|
---|
| 152 | slideFieldOrder: ['y', 'm', 'd'],
|
---|
| 153 | dateFormat: '%Y-%m-%d',
|
---|
| 154 | useArabicIndic: false,
|
---|
| 155 | isRTL: false,
|
---|
| 156 | calStartDay: 0,
|
---|
| 157 | clearButton: 'Clear'
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | },
|
---|
| 161 | destroy: function () {
|
---|
| 162 | $(this.pickPage).remove();
|
---|
| 163 | $.Widget.prototype.destroy.call(this);
|
---|
| 164 | },
|
---|
| 165 | _dateboxHandler: function(event, payload) {
|
---|
| 166 | var widget = $(this).data('datebox');
|
---|
| 167 | // Handle all event triggers that have an internal effect
|
---|
| 168 | if ( ! event.isPropagationStopped() ) {
|
---|
| 169 | switch (payload.method) {
|
---|
| 170 | case 'close':
|
---|
| 171 | widget.close(payload.fromCloseButton);
|
---|
| 172 | break;
|
---|
| 173 | case 'open':
|
---|
| 174 | widget.open();
|
---|
| 175 | break;
|
---|
| 176 | case 'set':
|
---|
| 177 | $(this).val(payload.value);
|
---|
| 178 | $(this).trigger('change');
|
---|
| 179 | break;
|
---|
| 180 | case 'doset':
|
---|
| 181 | if ( $.inArray(widget.options.mode, ['timebox', 'durationbox', 'timeflipbox']) > -1 ) {
|
---|
| 182 | $(this).trigger('datebox', {'method':'set', 'value':widget._formatTime(widget.theDate), 'date':widget.theDate});
|
---|
| 183 | } else {
|
---|
| 184 | $(this).trigger('datebox', {'method':'set', 'value':widget._formatDate(widget.theDate), 'date':widget.theDate});
|
---|
| 185 | }
|
---|
| 186 | break;
|
---|
| 187 | case 'dooffset':
|
---|
| 188 | widget._offset(payload.type, payload.amount, true);
|
---|
| 189 | break;
|
---|
| 190 | case 'dorefresh':
|
---|
| 191 | widget._update();
|
---|
| 192 | break;
|
---|
| 193 | case 'doreset':
|
---|
| 194 | widget.hardreset();
|
---|
| 195 | break;
|
---|
| 196 | case 'doclear':
|
---|
| 197 | $(this).val('');
|
---|
| 198 | break;
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | },
|
---|
| 202 | _getCoords: function(widget) {
|
---|
| 203 | var self = widget,
|
---|
| 204 | inputOffset = widget.focusedEl.offset(),
|
---|
| 205 | inputHigh = widget.focusedEl.outerHeight(),
|
---|
| 206 | inputWidth = widget.focusedEl.outerWidth(),
|
---|
| 207 | docWinWidth = $.mobile.activePage.width(),
|
---|
| 208 | docWinHighOff = $(window).scrollTop(),
|
---|
| 209 | docWinHigh = $(window).height(),
|
---|
| 210 | diaWinWidth = widget.pickerContent.innerWidth(),
|
---|
| 211 | diaWinHigh = widget.pickerContent.outerHeight(),
|
---|
| 212 | pageitem = false,
|
---|
| 213 | minTop = 0, // Minimum TOP measurment (absolute)
|
---|
| 214 | padTop = 0, // Padding for TOP measurment (fixed header)
|
---|
| 215 | unPadBottom = 0, // Padding for BOTTOM measurement (fixed header)
|
---|
| 216 | maxBottom = $(document).height(), // Max BOTTOM measurement (absolute)
|
---|
| 217 |
|
---|
| 218 | coords = {
|
---|
| 219 | 'high' : $(window).height(),
|
---|
| 220 | 'width' : $.mobile.activePage.width(),
|
---|
| 221 | 'fullTop' : $(window).scrollTop(),
|
---|
| 222 | 'fullLeft': $(window).scrollLeft()
|
---|
| 223 | };
|
---|
| 224 |
|
---|
| 225 | if ( widget.options.centerWindow ) { // If it's centered, no need for lots of checks.
|
---|
| 226 | coords.winTop = docWinHighOff + (( docWinHigh / 2 ) - ( diaWinHigh / 2 ) );
|
---|
| 227 | coords.winLeft = (( docWinWidth / 2 ) - ( diaWinWidth / 2 ) );
|
---|
| 228 | } else {
|
---|
| 229 | pageitem = $('.ui-header', $.mobile.activePage);
|
---|
| 230 | if ( pageitem.length > 0 ) {
|
---|
| 231 | if ( pageitem.is('.ui-header-fixed')) {
|
---|
| 232 | padTop = ( pageitem.outerHeight() + 2 );
|
---|
| 233 | } else {
|
---|
| 234 | minTop += ( pageitem.outerHeight() + 2 );
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 | pageitem = $('.ui-footer', $.mobile.activePage);
|
---|
| 238 | if ( pageitem.length > 0 ) {
|
---|
| 239 | if ( pageitem.is('.ui-footer-fixed')) {
|
---|
| 240 | unPadBottom = ( pageitem.outerHeight() + 2 );
|
---|
| 241 | } else {
|
---|
| 242 | maxBottom -= ( pageitem.outerHeight() + 2 );
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 | coords.winLeft = (inputOffset.left + ( inputWidth / 2 )) - ( diaWinWidth / 2 );
|
---|
| 246 |
|
---|
| 247 | // Trap for small screens (center horizontally instead)
|
---|
| 248 | if ( docWinWidth < 450 ) {
|
---|
| 249 | coords.winLeft = (( docWinWidth / 2 ) - ( diaWinWidth / 2 ) );
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | coords.winTop = (inputOffset.top + ( inputHigh / 2)) - ( diaWinHigh / 2 );
|
---|
| 253 |
|
---|
| 254 | // Not beyond bottom of page or on footer (not fixed)
|
---|
| 255 | if ( (coords.winTop + diaWinHigh) > maxBottom ) {
|
---|
| 256 | coords.winTop += ( maxBottom - ( coords.winTop + diaWinHigh ) );
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | // Not on the footer either (but only if it floats)
|
---|
| 260 | if ( unPadBottom > 0 && (( coords.winTop + diaWinHigh - docWinHighOff ) > (docWinHigh - unPadBottom)) ) {
|
---|
| 261 | coords.winTop = (( docWinHigh - unPadBottom + docWinHighOff - diaWinHigh ));
|
---|
| 262 | }
|
---|
| 263 | // Not on the header (not fixed)
|
---|
| 264 | if ( coords.winTop < minTop ) { coords.winTop = minTop; }
|
---|
| 265 |
|
---|
| 266 | // Not on the floating header either (fixed)
|
---|
| 267 | if ( padTop > 0 && ( coords.winTop < ( docWinHighOff + padTop ) ) ) {
|
---|
| 268 | coords.winTop = docWinHighOff + padTop;
|
---|
| 269 | } else if ( docWinHighOff > minTop && docWinHighOff > coords.winTop ) {
|
---|
| 270 | // This one for non fixed scroll?
|
---|
| 271 | coords.winTop = docWinHighOff + 2;
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | }
|
---|
| 275 | return coords;
|
---|
| 276 | },
|
---|
| 277 | _fixArray: function(arr) {
|
---|
| 278 | var x = 0,
|
---|
| 279 | self = this,
|
---|
| 280 | exp = new RegExp('^([0-9]+)-([0-9]+)-([0-9]+)$'),
|
---|
| 281 | matches = null;
|
---|
| 282 |
|
---|
| 283 | if ( $.isArray(arr) ) {
|
---|
| 284 | for ( x=0; x<arr.length; x++) {
|
---|
| 285 | matches = [0];
|
---|
| 286 | matches = exp.exec(arr[x]);
|
---|
| 287 | if ( matches.length === 4 ) {
|
---|
| 288 | arr[x] = matches[1] + '-' + self._zPad(parseInt(matches[2],10)) + '-' + self._zPad(parseInt(matches[3],10));
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
| 291 | }
|
---|
| 292 | return arr;
|
---|
| 293 | },
|
---|
| 294 | _digitReplace: function(oper, direction) {
|
---|
| 295 | var start = 48,
|
---|
| 296 | end = 57,
|
---|
| 297 | adder = 1584,
|
---|
| 298 | i = null,
|
---|
| 299 | ch = null,
|
---|
| 300 | newd = '';
|
---|
| 301 |
|
---|
| 302 | if ( direction === -1 ) {
|
---|
| 303 | start += adder;
|
---|
| 304 | end += adder;
|
---|
| 305 | adder = -1584;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | for ( i=0; i<oper.length; i++ ) {
|
---|
| 309 | ch = oper.charCodeAt(i);
|
---|
| 310 | if ( ch >= start && ch <= end ) {
|
---|
| 311 | newd = newd + String.fromCharCode(ch+adder);
|
---|
| 312 | } else {
|
---|
| 313 | newd = newd + String.fromCharCode(ch);
|
---|
| 314 | }
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | return newd;
|
---|
| 318 | },
|
---|
| 319 | _makeDisplayIndic: function() {
|
---|
| 320 | var self = this,
|
---|
| 321 | o = this.options;
|
---|
| 322 |
|
---|
| 323 | self.pickerContent.find('*').each(function() {
|
---|
| 324 | if ( $(this).children().length < 1 ) {
|
---|
| 325 | $(this).text(self._digitReplace($(this).text()));
|
---|
| 326 | } else if ( $(this).hasClass('ui-datebox-slideday') ) {
|
---|
| 327 | $(this).html(self._digitReplace($(this).html()));
|
---|
| 328 | }
|
---|
| 329 | });
|
---|
| 330 | self.pickerContent.find('input').each(function() {
|
---|
| 331 | $(this).val(self._digitReplace($(this).val()));
|
---|
| 332 | });
|
---|
| 333 | },
|
---|
| 334 | _zPad: function(number) {
|
---|
| 335 | // Pad a number with a zero, to make it 2 digits
|
---|
| 336 | return ( ( number < 10 ) ? "0" : "" ) + String(number);
|
---|
| 337 | },
|
---|
| 338 | _makeOrd: function (num) {
|
---|
| 339 | // Return an ordinal suffix (1st, 2nd, 3rd, etc)
|
---|
| 340 | var ending = num % 10;
|
---|
| 341 | if ( num > 9 && num < 21 ) { return 'th'; }
|
---|
| 342 | if ( ending > 3 ) { return 'th'; }
|
---|
| 343 | return ['th','st','nd','rd'][ending];
|
---|
| 344 | },
|
---|
| 345 | _isInt: function (s) {
|
---|
| 346 | // Bool, return is a number is an integer
|
---|
| 347 | return (s.toString().search(/^[0-9]+$/) === 0);
|
---|
| 348 | },
|
---|
| 349 | _getFirstDay: function(date) {
|
---|
| 350 | // Get the first DAY of the month (0-6)
|
---|
| 351 | return date.copymod([0],[0,0,1]).getDay();
|
---|
| 352 | },
|
---|
| 353 | _getRecDays: function(year, month, day) {
|
---|
| 354 | // Get the recurring Days of a week for 'year'-'month'
|
---|
| 355 | // (pass nulls for whatever the internal year and month are)
|
---|
| 356 | if ( month === null ) { month = this.theDate.getMonth()+1; }
|
---|
| 357 | if ( year === null ) { year = this.theDate.getFullYear(); }
|
---|
| 358 |
|
---|
| 359 | var self = this,
|
---|
| 360 | tempDate = new Date(year, month-1, 1, 0, 0, 0, 0),
|
---|
| 361 | dates = [], i;
|
---|
| 362 |
|
---|
| 363 | if ( tempDate.getDay() > day ) {
|
---|
| 364 | tempDate.setDate(8 - (tempDate.getDay() - day));
|
---|
| 365 | } else if ( tempDate.getDay() < day ) {
|
---|
| 366 | tempDate.setDate(1 + (day - tempDate.getDay()));
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | dates[0] = tempDate.getISO();
|
---|
| 370 |
|
---|
| 371 | for ( i = 1; i<6; i++ ) {
|
---|
| 372 | tempDate.setDate(tempDate.getDate() + 7);
|
---|
| 373 | if ( (tempDate.getMonth()+1) === month ) {
|
---|
| 374 | dates[i] = tempDate.getISO();
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | return dates;
|
---|
| 379 | },
|
---|
| 380 | _getLastDate: function(date) {
|
---|
| 381 | // Get the last DATE of the month (28,29,30,31)
|
---|
| 382 | return 32 - date.copymod([0],[0,0,32,13]).getDate();
|
---|
| 383 | },
|
---|
| 384 | _getLastDateBefore: function(date) {
|
---|
| 385 | // Get the last DATE of the PREVIOUS month (28,29,30,31)
|
---|
| 386 | return 32 - date.copymod([0,-1],[0,0,32,13]).getDate();
|
---|
| 387 | },
|
---|
| 388 | _formatter: function(format, date) {
|
---|
| 389 | var self = this,
|
---|
| 390 | o = this.options;
|
---|
| 391 | // Format the output date or time (not duration)
|
---|
| 392 | if ( ! format.match(/%/) ) {
|
---|
| 393 | format = format.replace('HH', this._zPad(date.getHours()));
|
---|
| 394 | format = format.replace('GG', date.getHours());
|
---|
| 395 |
|
---|
| 396 | format = format.replace('hh', this._zPad(((date.getHours() === 0 || date.getHours() === 12)?12:((date.getHours()<12)?date.getHours():date.getHours()-12))));
|
---|
| 397 | format = format.replace('gg', ((date.getHours() === 0 || date.getHours() === 12)?12:((date.getHours()<12)?date.getHours():(date.getHours()-12))));
|
---|
| 398 |
|
---|
| 399 | format = format.replace('ii', this._zPad(date.getMinutes()));
|
---|
| 400 | format = format.replace('ss', this._zPad(date.getSeconds()));
|
---|
| 401 | format = format.replace('AA', ((date.getHours() < 12)?this.options.meridiemLetters[0].toUpperCase():this.options.meridiemLetters[1].toUpperCase()));
|
---|
| 402 | format = format.replace('aa', ((date.getHours() < 12)?this.options.meridiemLetters[0].toLowerCase():this.options.meridiemLetters[1].toLowerCase()));
|
---|
| 403 |
|
---|
| 404 | format = format.replace('SS', this._makeOrd(date.getDate()));
|
---|
| 405 | format = format.replace('YYYY', date.getFullYear());
|
---|
| 406 | format = format.replace('mmmm', this.options.lang[this.options.useLang].monthsOfYearShort[date.getMonth()] );
|
---|
| 407 | format = format.replace('mmm', this.options.lang[this.options.useLang].monthsOfYear[date.getMonth()] );
|
---|
| 408 | format = format.replace('MM', this._zPad(date.getMonth() + 1));
|
---|
| 409 | format = format.replace('mm', date.getMonth() + 1);
|
---|
| 410 | format = format.replace('dddd', this.options.lang[this.options.useLang].daysOfWeekShort[date.getDay()] );
|
---|
| 411 | format = format.replace('ddd', this.options.lang[this.options.useLang].daysOfWeek[date.getDay()] );
|
---|
| 412 | format = format.replace('DD', this._zPad(date.getDate()));
|
---|
| 413 | format = format.replace('dd', date.getDate());
|
---|
| 414 | format = format.replace('UU', date.getEpoch());
|
---|
| 415 | } else {
|
---|
| 416 | format = format.replace(/%(0|-)*([a-z])/gi, function(match, pad, oper, offset, s) {
|
---|
| 417 | switch ( oper ) {
|
---|
| 418 | case '%': // Literal %
|
---|
| 419 | return '%';
|
---|
| 420 | case 'a': // Short Day
|
---|
| 421 | return o.lang[o.useLang].daysOfWeekShort[date.getDay()];
|
---|
| 422 | case 'A': // Full Day of week
|
---|
| 423 | return o.lang[o.useLang].daysOfWeek[date.getDay()];
|
---|
| 424 | case 'b': // Short month
|
---|
| 425 | return o.lang[o.useLang].monthsOfYearShort[date.getMonth()];
|
---|
| 426 | case 'B': // Full month
|
---|
| 427 | return o.lang[o.useLang].monthsOfYear[date.getMonth()];
|
---|
| 428 | case 'C': // Century
|
---|
| 429 | return date.getFullYear().toString().substr(0,2);
|
---|
| 430 | case 'd': // Day of month
|
---|
| 431 | return (( pad === '-' ) ? date.getDate() : self._zPad(date.getDate()));
|
---|
| 432 | case 'H': // Hour (01..23)
|
---|
| 433 | case 'k':
|
---|
| 434 | return (( pad === '-' ) ? date.getHours() : self._zPad(date.getHours()));
|
---|
| 435 | case 'I': // Hour (01..12)
|
---|
| 436 | case 'l':
|
---|
| 437 | return (( pad === '-' ) ? ((date.getHours() === 0 || date.getHours() === 12)?12:((date.getHours()<12)?date.getHours():(date.getHours()-12))) : self._zPad(((date.getHours() === 0 || date.getHours() === 12)?12:((date.getHours()<12)?date.getHours():date.getHours()-12))));
|
---|
| 438 | case 'm': // Month
|
---|
| 439 | return (( pad === '-' ) ? date.getMonth()+1 : self._zPad(date.getMonth()+1));
|
---|
| 440 | case 'M': // Minutes
|
---|
| 441 | return (( pad === '-' ) ? date.getMinutes() : self._zPad(date.getMinutes()));
|
---|
| 442 | case 'p': // AM/PM (ucase)
|
---|
| 443 | return ((date.getHours() < 12)?o.meridiemLetters[0].toUpperCase():o.meridiemLetters[1].toUpperCase());
|
---|
| 444 | case 'P': // AM/PM (lcase)
|
---|
| 445 | return ((date.getHours() < 12)?o.meridiemLetters[0].toLowerCase():o.meridiemLetters[1].toLowerCase());
|
---|
| 446 | case 's': // Unix Seconds
|
---|
| 447 | return date.getEpoch;
|
---|
| 448 | case 'S': // Seconds
|
---|
| 449 | return (( pad === '-' ) ? date.getSeconds() : self._zPad(date.getSeconds()));
|
---|
| 450 | case 'w': // Day of week
|
---|
| 451 | return date.getDay();
|
---|
| 452 | case 'y': // Year (2 digit)
|
---|
| 453 | return date.getFullYear().toString().substr(2,2);
|
---|
| 454 | case 'Y': // Year (4 digit)
|
---|
| 455 | return date.getFullYear();
|
---|
| 456 | case 'o': // Ordinals
|
---|
| 457 | return self._makeOrd(date.getDate());
|
---|
| 458 | default:
|
---|
| 459 | return match;
|
---|
| 460 | }
|
---|
| 461 | });
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | if ( this.options.lang[this.options.useLang].useArabicIndic === true ) {
|
---|
| 465 | format = this._digitReplace(format);
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | return format;
|
---|
| 469 | },
|
---|
| 470 | _formatHeader: function(date) {
|
---|
| 471 | // Shortcut function to return headerFormat date/time format
|
---|
| 472 | if ( this.options.headerFormat !== false ) {
|
---|
| 473 | return this._formatter(this.options.headerFormat, date);
|
---|
| 474 | } else {
|
---|
| 475 | return this._formatter(this.options.lang[this.options.useLang].headerFormat, date);
|
---|
| 476 | }
|
---|
| 477 | },
|
---|
| 478 | _formatDate: function(date) {
|
---|
| 479 | // Shortcut function to return dateFormat date/time format
|
---|
| 480 | return this._formatter(this.options.dateOutput, date);
|
---|
| 481 | },
|
---|
| 482 | _formatTime: function(date) {
|
---|
| 483 | // Shortcut to return formatted time, also handles duration
|
---|
| 484 | var self = this,
|
---|
| 485 | dur_collapse = [false,false,false], adv, exp_format, i, j,
|
---|
| 486 | format = this.options.durationFormat,
|
---|
| 487 | dur_comps = [0,0,0,0];
|
---|
| 488 |
|
---|
| 489 | if ( this.options.mode === 'durationbox' ) {
|
---|
| 490 | adv = this.options.durationFormat;
|
---|
| 491 | adv = adv.replace(/ddd/g, '.+?');
|
---|
| 492 | adv = adv.replace(/DD|ss|hh|ii/g, '([0-9Dhis]+)');
|
---|
| 493 | adv = new RegExp('^' + adv + '$');
|
---|
| 494 | exp_format = adv.exec(this.options.durationFormat);
|
---|
| 495 |
|
---|
| 496 | i = self.theDate.getEpoch() - self.initDate.getEpoch(); j = i;
|
---|
| 497 |
|
---|
| 498 | dur_comps[0] = parseInt( i / (60*60*24),10); i = i - (dur_comps[0]*60*60*24); // Days
|
---|
| 499 | dur_comps[1] = parseInt( i / (60*60),10); i = i - (dur_comps[1]*60*60); // Hours
|
---|
| 500 | dur_comps[2] = parseInt( i / (60),10); i = i - (dur_comps[2]*60); // Minutes
|
---|
| 501 | dur_comps[3] = i; // Seconds
|
---|
| 502 |
|
---|
| 503 | if ( ! exp_format[0].match(/DD/) ) { dur_collapse[0] = true; dur_comps[1] = dur_comps[1] + (dur_comps[0]*24);}
|
---|
| 504 | if ( ! exp_format[0].match(/hh/) ) { dur_collapse[1] = true; dur_comps[2] = dur_comps[2] + (dur_comps[1]*60);}
|
---|
| 505 | if ( ! exp_format[0].match(/ii/) ) { dur_collapse[2] = true; dur_comps[3] = dur_comps[3] + (dur_comps[2]*60);}
|
---|
| 506 |
|
---|
| 507 | format = format.replace('DD', dur_comps[0]);
|
---|
| 508 | format = format.replace('ddd', ((dur_comps[0] > 1)?this.options.lang[this.options.useLang].durationDays[1]:this.options.lang[this.options.useLang].durationDays[0]));
|
---|
| 509 | format = format.replace('hh', self._zPad(dur_comps[1]));
|
---|
| 510 | format = format.replace('ii', self._zPad(dur_comps[2]));
|
---|
| 511 | format = format.replace('ss', self._zPad(dur_comps[3]));
|
---|
| 512 |
|
---|
| 513 | if ( this.options.lang[this.options.useLang].useArabicIndic === true ) {
|
---|
| 514 | return this._digitReplace(format);
|
---|
| 515 | } else {
|
---|
| 516 | return format;
|
---|
| 517 | }
|
---|
| 518 | } else {
|
---|
| 519 | return this._formatter(self.options.timeOutput, date);
|
---|
| 520 | }
|
---|
| 521 | },
|
---|
| 522 | _makeDate: function (str) {
|
---|
| 523 | // Date Parser
|
---|
| 524 | str = $.trim(str);
|
---|
| 525 | var o = this.options,
|
---|
| 526 | self = this,
|
---|
| 527 | adv = null,
|
---|
| 528 | exp_input = null,
|
---|
| 529 | exp_format = null,
|
---|
| 530 | exp_temp = null,
|
---|
| 531 | date = new Date(),
|
---|
| 532 | dur_collapse = [false,false,false],
|
---|
| 533 | found_date = [date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds(),0],
|
---|
| 534 | i;
|
---|
| 535 |
|
---|
| 536 | if ( o.lang[this.options.useLang].useArabicIndic === true ) {
|
---|
| 537 | str = this._digitReplace(str, -1);
|
---|
| 538 | }
|
---|
| 539 |
|
---|
| 540 | if ( o.mode === 'durationbox' ) {
|
---|
| 541 | adv = o.durationFormat;
|
---|
| 542 | adv = adv.replace(/ddd/g, '.+?');
|
---|
| 543 | adv = adv.replace(/DD|ss|hh|ii/g, '([0-9Dhis]+)');
|
---|
| 544 | adv = new RegExp('^' + adv + '$');
|
---|
| 545 | exp_input = adv.exec(str);
|
---|
| 546 | exp_format = adv.exec(o.durationFormat);
|
---|
| 547 |
|
---|
| 548 | if ( exp_input === null || exp_input.length !== exp_format.length ) {
|
---|
| 549 | if ( typeof o.defaultPickerValue === "number" && o.defaultPickerValue > 0 ) {
|
---|
| 550 | return new Date((self.initDate.getEpoch() + parseInt(o.defaultPickerValue,10))*1000);
|
---|
| 551 | } else {
|
---|
| 552 | return new Date(self.initDate.getTime());
|
---|
| 553 | }
|
---|
| 554 | } else {
|
---|
| 555 | exp_temp = self.initDate.getEpoch();
|
---|
| 556 | for ( i=0; i<exp_input.length; i++ ) { //0y 1m 2d 3h 4i 5s
|
---|
| 557 | if ( exp_format[i].match(/^DD$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)*60*60*24); }
|
---|
| 558 | if ( exp_format[i].match(/^hh$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)*60*60); }
|
---|
| 559 | if ( exp_format[i].match(/^ii$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)*60); }
|
---|
| 560 | if ( exp_format[i].match(/^ss$/i) ) { exp_temp = exp_temp + (parseInt(exp_input[i],10)); }
|
---|
| 561 | }
|
---|
| 562 | return new Date((exp_temp*1000));
|
---|
| 563 | }
|
---|
| 564 | } else {
|
---|
| 565 | if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) { adv = o.timeOutput; } else { adv = o.dateOutput; }
|
---|
| 566 | if ( adv.match(/%/) ) {
|
---|
| 567 | adv = adv.replace(/%(0|-)*([a-z])/gi, function(match, pad, oper, offset, s) {
|
---|
| 568 | switch (oper) {
|
---|
| 569 | case 'p':
|
---|
| 570 | case 'P':
|
---|
| 571 | case 'b':
|
---|
| 572 | case 'B': return '(' + match + '|' +'.+?' + ')';
|
---|
| 573 | case 'H':
|
---|
| 574 | case 'k':
|
---|
| 575 | case 'I':
|
---|
| 576 | case 'l':
|
---|
| 577 | case 'm':
|
---|
| 578 | case 'M':
|
---|
| 579 | case 'S':
|
---|
| 580 | case 'd': return '(' + match + '|' + (( pad === '-' ) ? '[0-9]{1,2}' : '[0-9]{2}') + ')';
|
---|
| 581 | case 's': return '(' + match + '|' +'[0-9]+' + ')';
|
---|
| 582 | case 'y': return '(' + match + '|' +'[0-9]{2}' + ')';
|
---|
| 583 | case 'Y': return '(' + match + '|' +'[0-9]{1,4}' + ')';
|
---|
| 584 | default: return '.+?';
|
---|
| 585 | }
|
---|
| 586 | });
|
---|
| 587 | adv = new RegExp('^' + adv + '$');
|
---|
| 588 | exp_input = adv.exec(str);
|
---|
| 589 | if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) {
|
---|
| 590 | exp_format = adv.exec(o.timeOutput); // If time, use timeOutput as expected format
|
---|
| 591 | } else {
|
---|
| 592 | exp_format = adv.exec(o.dateOutput); // If date, use dateFormat as expected format
|
---|
| 593 | }
|
---|
| 594 |
|
---|
| 595 | if ( exp_input === null || exp_input.length !== exp_format.length ) {
|
---|
| 596 | if ( o.defaultPickerValue !== false ) {
|
---|
| 597 | if ( $.isArray(o.defaultPickerValue) && o.defaultPickerValue.length === 3 ) {
|
---|
| 598 | if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) {
|
---|
| 599 | return new Date(found_date[0], found_date[1], found_date[2], o.defaultPickerValue[0], o.defaultPickerValue[1], o.defaultPickerValue[2], 0);
|
---|
| 600 | }
|
---|
| 601 | else {
|
---|
| 602 | return new Date(o.defaultPickerValue[0], o.defaultPickerValue[1], o.defaultPickerValue[2], 0, 0, 0, 0);
|
---|
| 603 | }
|
---|
| 604 | }
|
---|
| 605 | else if ( typeof o.defaultPickerValue === "number" ) {
|
---|
| 606 | return new Date(o.defaultPickerValue * 1000);
|
---|
| 607 | }
|
---|
| 608 | else {
|
---|
| 609 | if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) {
|
---|
| 610 | exp_temp = o.defaultPickerValue.split(':');
|
---|
| 611 | if ( exp_temp.length === 3 ) {
|
---|
| 612 | date = new Date(found_date[0], found_date[1], found_date[2], parseInt(exp_temp[0],10),parseInt(exp_temp[1],10),parseInt(exp_temp[2],10),0);
|
---|
| 613 | if ( isNaN(date.getDate()) ) { date = new Date(); }
|
---|
| 614 | }
|
---|
| 615 | }
|
---|
| 616 | else {
|
---|
| 617 | exp_temp = o.defaultPickerValue.split('-');
|
---|
| 618 | if ( exp_temp.length === 3 ) {
|
---|
| 619 | date = new Date(parseInt(exp_temp[0],10),parseInt(exp_temp[1],10)-1,parseInt(exp_temp[2],10),0,0,0,0);
|
---|
| 620 | if ( isNaN(date.getDate()) ) { date = new Date(); }
|
---|
| 621 | }
|
---|
| 622 | }
|
---|
| 623 | }
|
---|
| 624 | }
|
---|
| 625 | } else {
|
---|
| 626 | for ( i=0; i<exp_input.length; i++ ) { //0y 1m 2d 3h 4i 5a 6epoch
|
---|
| 627 | if ( exp_format[i] === '%s' ) { found_date[6] = parseInt(exp_input[i],10); }
|
---|
| 628 | if ( exp_format[i].match(/^%.*S$/) ) { found_date[5] = parseInt(exp_input[i],10); }
|
---|
| 629 | if ( exp_format[i].match(/^%.*M$/) ) { found_date[4] = parseInt(exp_input[i],10); }
|
---|
| 630 | if ( exp_format[i].match(/^%.*(H|k|I|l)$/) ) { found_date[3] = parseInt(exp_input[i],10); }
|
---|
| 631 | if ( exp_format[i].match(/^%.*d$/) ) { found_date[2] = parseInt(exp_input[i],10); }
|
---|
| 632 | if ( exp_format[i].match(/^%.*m$/) ) { found_date[1] = parseInt(exp_input[i],10)-1; }
|
---|
| 633 | if ( exp_format[i].match(/^%.*Y$/) ) { found_date[0] = parseInt(exp_input[i],10); }
|
---|
| 634 | if ( exp_format[i].match(/^%.*y$/) ) {
|
---|
| 635 | if ( o.afterToday === true ) {
|
---|
| 636 | found_date[0] = parseInt('20' + exp_input[i],10);
|
---|
| 637 | } else {
|
---|
| 638 | if ( parseInt(exp_input[i],10) < 38 ) {
|
---|
| 639 | found_date[0] = parseInt('20' + exp_input[i],10);
|
---|
| 640 | } else {
|
---|
| 641 | found_date[0] = parseInt('19' + exp_input[i],10);
|
---|
| 642 | }
|
---|
| 643 | }
|
---|
| 644 | }
|
---|
| 645 | if ( exp_format[i].match(/^%(0|-)*(p|P)$/) ) {
|
---|
| 646 | if ( exp_input[i].toLowerCase().charAt(0) === 'a' && found_date[3] === 12 ) {
|
---|
| 647 | found_date[3] = 0;
|
---|
| 648 | } else if ( exp_input[i].toLowerCase().charAt(0) === 'p' && found_date[3] !== 12 ) {
|
---|
| 649 | found_date[3] = found_date[3] + 12;
|
---|
| 650 | }
|
---|
| 651 | }
|
---|
| 652 | if ( exp_format[i] === '%B' ) {
|
---|
| 653 | exp_temp = $.inArray(exp_input[i], o.lang[o.useLang].monthsOfYear);
|
---|
| 654 | if ( exp_temp > -1 ) { found_date[1] = exp_temp; }
|
---|
| 655 | }
|
---|
| 656 | if ( exp_format[i] === '%b' ) {
|
---|
| 657 | exp_temp = $.inArray(exp_input[i], o.lang[o.useLang].monthsOfYearShort);
|
---|
| 658 | if ( exp_temp > -1 ) { found_date[1] = exp_temp; }
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 | }
|
---|
| 662 | if ( exp_format[0].match(/%s/) ) {
|
---|
| 663 | date = new Date(found_date[6] * 1000);
|
---|
| 664 | }
|
---|
| 665 | else if ( exp_format[0].match(/%(.)*(I|l|H|k|s|M)/) ) {
|
---|
| 666 | date = new Date(found_date[0], found_date[1], found_date[2], found_date[3], found_date[4], found_date[5], 0);
|
---|
| 667 | if ( found_date[0] < 100 ) { date.setFullYear(found_date[0]); }
|
---|
| 668 | } else {
|
---|
| 669 | date = new Date(found_date[0], found_date[1], found_date[2], 0, 0, 0, 0); // Normalize time for raw dates
|
---|
| 670 | if ( found_date[0] < 100 ) { date.setFullYear(found_date[0]); }
|
---|
| 671 | }
|
---|
| 672 | return date;
|
---|
| 673 | } else {
|
---|
| 674 | adv = adv.replace(/dddd|mmmm/g, '(.+?)');
|
---|
| 675 | adv = adv.replace(/ddd|SS/g, '.+?');
|
---|
| 676 | adv = adv.replace(/mmm/g, '(.+?)');
|
---|
| 677 | adv = adv.replace(/ *AA/ig, ' *(.*?)');
|
---|
| 678 | adv = adv.replace(/yyyy|dd|mm|gg|hh|ii/ig, '([0-9yYdDmMgGhHi]+)');
|
---|
| 679 | adv = adv.replace(/ss|UU/g, '([0-9sU]+)');
|
---|
| 680 | adv = new RegExp('^' + adv + '$');
|
---|
| 681 | exp_input = adv.exec(str);
|
---|
| 682 | if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) {
|
---|
| 683 | exp_format = adv.exec(o.timeOutput); // If time, use timeOutput as expected format
|
---|
| 684 | } else {
|
---|
| 685 | exp_format = adv.exec(o.dateOutput); // If date, use dateFormat as expected format
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | if ( exp_input === null || exp_input.length !== exp_format.length ) {
|
---|
| 689 | if ( o.defaultPickerValue !== false ) {
|
---|
| 690 | if ( $.isArray(o.defaultPickerValue) && o.defaultPickerValue.length === 3 ) {
|
---|
| 691 | if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) {
|
---|
| 692 | return new Date(found_date[0], found_date[1], found_date[2], o.defaultPickerValue[0], o.defaultPickerValue[1], o.defaultPickerValue[2], 0);
|
---|
| 693 | }
|
---|
| 694 | else {
|
---|
| 695 | return new Date(o.defaultPickerValue[0], o.defaultPickerValue[1], o.defaultPickerValue[2], 0, 0, 0, 0);
|
---|
| 696 | }
|
---|
| 697 | }
|
---|
| 698 | else if ( typeof o.defaultPickerValue === "number" ) {
|
---|
| 699 | return new Date(o.defaultPickerValue * 1000);
|
---|
| 700 | }
|
---|
| 701 | else {
|
---|
| 702 | if ( o.mode === 'timebox' || o.mode === 'timeflipbox' ) {
|
---|
| 703 | exp_temp = o.defaultPickerValue.split(':');
|
---|
| 704 | if ( exp_temp.length === 3 ) {
|
---|
| 705 | date = new Date(found_date[0], found_date[1], found_date[2], parseInt(exp_temp[0],10),parseInt(exp_temp[1],10),parseInt(exp_temp[2],10),0);
|
---|
| 706 | if ( isNaN(date.getDate()) ) { date = new Date(); }
|
---|
| 707 | }
|
---|
| 708 | }
|
---|
| 709 | else {
|
---|
| 710 | exp_temp = o.defaultPickerValue.split('-');
|
---|
| 711 | if ( exp_temp.length === 3 ) {
|
---|
| 712 | date = new Date(parseInt(exp_temp[0],10),parseInt(exp_temp[1],10)-1,parseInt(exp_temp[2],10),0,0,0,0);
|
---|
| 713 | if ( isNaN(date.getDate()) ) { date = new Date(); }
|
---|
| 714 | }
|
---|
| 715 | }
|
---|
| 716 | }
|
---|
| 717 | }
|
---|
| 718 | } else {
|
---|
| 719 | for ( i=0; i<exp_input.length; i++ ) { //0y 1m 2d 3h 4i 5a 6epoch
|
---|
| 720 | if ( exp_format[i].match(/^UU$/ ) ) { found_date[6] = parseInt(exp_input[i],10); }
|
---|
| 721 | if ( exp_format[i].match(/^gg$/i) ) { found_date[3] = parseInt(exp_input[i],10); }
|
---|
| 722 | if ( exp_format[i].match(/^hh$/i) ) { found_date[3] = parseInt(exp_input[i],10); }
|
---|
| 723 | if ( exp_format[i].match(/^ii$/i) ) { found_date[4] = parseInt(exp_input[i],10); }
|
---|
| 724 | if ( exp_format[i].match(/^ss$/ ) ) { found_date[5] = parseInt(exp_input[i],10); }
|
---|
| 725 | if ( exp_format[i].match(/^dd$/i) ) { found_date[2] = parseInt(exp_input[i],10); }
|
---|
| 726 | if ( exp_format[i].match(/^mm$/i) ) { found_date[1] = parseInt(exp_input[i],10)-1; }
|
---|
| 727 | if ( exp_format[i].match(/^yyyy$/i) ) { found_date[0] = parseInt(exp_input[i],10); }
|
---|
| 728 | if ( exp_format[i].match(/^AA$/i) ) {
|
---|
| 729 | if ( exp_input[i].toLowerCase().charAt(0) === 'a' && found_date[3] === 12 ) {
|
---|
| 730 | found_date[3] = 0;
|
---|
| 731 | } else if ( exp_input[i].toLowerCase().charAt(0) === 'p' && found_date[3] !== 12 ) {
|
---|
| 732 | found_date[3] = found_date[3] + 12;
|
---|
| 733 | }
|
---|
| 734 | }
|
---|
| 735 | if ( exp_format[i].match(/^mmm$/i) ) {
|
---|
| 736 | exp_temp = $.inArray(exp_input[i], o.lang[o.useLang].monthsOfYear);
|
---|
| 737 | if ( exp_temp > -1 ) { found_date[1] = exp_temp; }
|
---|
| 738 | }
|
---|
| 739 | if ( exp_format[i].match(/^mmmm$/i) ) {
|
---|
| 740 | exp_temp = $.inArray(exp_input[i], o.lang[o.useLang].monthsOfYearShort);
|
---|
| 741 | if ( exp_temp > -1 ) { found_date[1] = exp_temp; }
|
---|
| 742 | }
|
---|
| 743 | }
|
---|
| 744 | }
|
---|
| 745 | if ( exp_format[0].match(/UU/) ) {
|
---|
| 746 | return new Date(found_date[6] * 1000);
|
---|
| 747 | }
|
---|
| 748 | else if ( exp_format[0].match(/G|g|i|s|H|h|A/) ) {
|
---|
| 749 | return new Date(found_date[0], found_date[1], found_date[2], found_date[3], found_date[4], found_date[5], 0);
|
---|
| 750 | } else {
|
---|
| 751 | return new Date(found_date[0], found_date[1], found_date[2], 0, 0, 0, 0); // Normalize time for raw dates
|
---|
| 752 | }
|
---|
| 753 | }
|
---|
| 754 | }
|
---|
| 755 | },
|
---|
| 756 | _hoover: function(item) {
|
---|
| 757 | // Hover toggle class, for calendar
|
---|
| 758 | $(item).toggleClass('ui-btn-up-'+$(item).jqmData('theme')+' ui-btn-down-'+$(item).jqmData('theme'));
|
---|
| 759 | },
|
---|
| 760 | _offset: function(mode, amount, update) {
|
---|
| 761 | // Compute a date/time offset.
|
---|
| 762 | // update = false to prevent controls refresh
|
---|
| 763 | var self = this,
|
---|
| 764 | o = this.options,
|
---|
| 765 | ok = false;
|
---|
| 766 |
|
---|
| 767 | if ( typeof(update) === "undefined" ) { update = true; }
|
---|
| 768 | self.input.trigger('datebox', {'method':'offset', 'type':mode, 'amount':amount});
|
---|
| 769 | switch(mode) {
|
---|
| 770 | case 'y': ok = true; break;
|
---|
| 771 | case 'm':
|
---|
| 772 | if ( o.rolloverMode.m || ( self.theDate.getMonth() + amount < 12 && self.theDate.getMonth() + amount > -1 ) ) {
|
---|
| 773 | ok = true;
|
---|
| 774 | }
|
---|
| 775 | break;
|
---|
| 776 | case 'd':
|
---|
| 777 | if ( o.rolloverMode.d || (
|
---|
| 778 | self.theDate.getDate() + amount > 0 &&
|
---|
| 779 | self.theDate.getDate() + amount < (self._getLastDate(self.theDate) + 1) ) ) {
|
---|
| 780 | ok = true;
|
---|
| 781 | }
|
---|
| 782 | break;
|
---|
| 783 | case 'h':
|
---|
| 784 | if ( o.rolloverMode.h || (
|
---|
| 785 | self.theDate.getHours() + amount > -1 &&
|
---|
| 786 | self.theDate.getHours() + amount < 24 ) ) {
|
---|
| 787 | ok = true;
|
---|
| 788 | }
|
---|
| 789 | break;
|
---|
| 790 | case 'i':
|
---|
| 791 | if ( o.rolloverMode.i || (
|
---|
| 792 | self.theDate.getMinutes() + amount > -1 &&
|
---|
| 793 | self.theDate.getMinutes() + amount < 60 ) ) {
|
---|
| 794 | ok = true;
|
---|
| 795 | }
|
---|
| 796 | break;
|
---|
| 797 | case 's':
|
---|
| 798 | if ( o.rolloverMode.s || (
|
---|
| 799 | self.theDate.getSeconds() + amount > -1 &&
|
---|
| 800 | self.theDate.getSeconds() + amount < 60 ) ) {
|
---|
| 801 | ok = true;
|
---|
| 802 | }
|
---|
| 803 | break;
|
---|
| 804 | case 'a':
|
---|
| 805 | if ( self.pickerMeri.val() === o.meridiemLetters[0] ) {
|
---|
| 806 | self._offset('h',12,false);
|
---|
| 807 | } else {
|
---|
| 808 | self._offset('h',-12,false);
|
---|
| 809 | }
|
---|
| 810 | break;
|
---|
| 811 | }
|
---|
| 812 | if ( ok === true ) { self.theDate.adjust(mode,amount); }
|
---|
| 813 | if ( update === true ) { self._update(); }
|
---|
| 814 | },
|
---|
| 815 | _updateduration: function() {
|
---|
| 816 | // Update the duration contols when inputs are directly edited.
|
---|
| 817 | var self = this,
|
---|
| 818 | secs = self.initDate.getEpoch();
|
---|
| 819 |
|
---|
| 820 | if ( !self._isInt(self.pickerDay.val()) ) { self.pickerDay.val(0); }
|
---|
| 821 | if ( !self._isInt(self.pickerHour.val()) ) { self.pickerHour.val(0); }
|
---|
| 822 | if ( !self._isInt(self.pickerMins.val()) ) { self.pickerMins.val(0); }
|
---|
| 823 | if ( !self._isInt(self.pickerSecs.val()) ) { self.pickerSecs.val(0); }
|
---|
| 824 |
|
---|
| 825 | secs = secs + (parseInt(self.pickerDay.val(),10) * 60 * 60 * 24);
|
---|
| 826 | secs = secs + (parseInt(self.pickerHour.val(),10) * 60 * 60);
|
---|
| 827 | secs = secs + (parseInt(self.pickerMins.val(),10) * 60);
|
---|
| 828 | secs = secs + (parseInt(self.pickerSecs.val(),10));
|
---|
| 829 | self.theDate.setTime( secs * 1000 );
|
---|
| 830 | self._update();
|
---|
| 831 | },
|
---|
| 832 | _checkConstraints: function() {
|
---|
| 833 | var self = this,
|
---|
| 834 | testDate = null,
|
---|
| 835 | o = this.options;
|
---|
| 836 |
|
---|
| 837 | self.dateOK = true;
|
---|
| 838 |
|
---|
| 839 | if ( o.afterToday !== false ) {
|
---|
| 840 | testDate = new Date();
|
---|
| 841 | if ( self.theDate < testDate ) { self.theDate = testDate; }
|
---|
| 842 | }
|
---|
| 843 | if ( o.beforeToday !== false ) {
|
---|
| 844 | testDate = new Date();
|
---|
| 845 | if ( self.theDate > testDate ) { self.theDate = testDate; }
|
---|
| 846 | }
|
---|
| 847 | if ( o.maxDays !== false ) {
|
---|
| 848 | testDate = new Date();
|
---|
| 849 | testDate.adjust('d', o.maxDays);
|
---|
| 850 | if ( self.theDate > testDate ) { self.theDate = testDate; }
|
---|
| 851 | }
|
---|
| 852 | if ( o.minDays !== false ) {
|
---|
| 853 | testDate = new Date();
|
---|
| 854 | testDate.adjust('d', -1*o.minDays);
|
---|
| 855 | if ( self.theDate < testDate ) { self.theDate = testDate; }
|
---|
| 856 | }
|
---|
| 857 | if ( o.maxYear !== false ) {
|
---|
| 858 | testDate = new Date(o.maxYear, 0, 1);
|
---|
| 859 | testDate.adjust('d', -1);
|
---|
| 860 | if ( self.theDate > testDate ) { self.theDate = testDate; }
|
---|
| 861 | }
|
---|
| 862 | if ( o.minYear !== false ) {
|
---|
| 863 | testDate = new Date(o.minYear, 0, 1);
|
---|
| 864 | if ( self.theDate < testDate ) { self.theDate = testDate; }
|
---|
| 865 | }
|
---|
| 866 | if ( o.blackDates !== false ) {
|
---|
| 867 | if ( $.inArray(self.theDate.getISO(), o.blackDates) > -1 ) { self.dateOK = false; }
|
---|
| 868 | }
|
---|
| 869 | if ( o.blackDays !== false ) {
|
---|
| 870 | if ( $.inArray(self.theDate.getDay(), o.blackDays) > -1 ) { self.dateOK = false; }
|
---|
| 871 | }
|
---|
| 872 | if ( $.inArray(o.mode, ['timebox','durationbox','timeflipbox']) > -1 ) { self.dateOK = true; }
|
---|
| 873 | },
|
---|
| 874 | _orientChange: function(e) {
|
---|
| 875 | var self = e.data.widget,
|
---|
| 876 | o = e.data.widget.options,
|
---|
| 877 | coords = e.data.widget._getCoords(e.data.widget); // Get the coords now, since we need em.
|
---|
| 878 |
|
---|
| 879 | e.stopPropagation();
|
---|
| 880 | if ( ! self.pickerContent.is(':visible') || o.useDialog === true ) {
|
---|
| 881 | return false; // Not open, or in a dialog (let jQM do it)
|
---|
| 882 | } else {
|
---|
| 883 | if ( o.fullScreen == true && ( coords.width < 400 || o.fullScreenForce === true ) ) {
|
---|
| 884 | self.pickerContent.css({'top': coords.fullTop, 'left': coords.fullLeft, 'height': coords.high, 'width': coords.width, 'maxWidth': coords.width });
|
---|
| 885 | } else {
|
---|
| 886 | self.pickerContent.css({'top': coords.winTop, 'left': coords.winLeft});
|
---|
| 887 | }
|
---|
| 888 | }
|
---|
| 889 | },
|
---|
| 890 | _update: function() {
|
---|
| 891 | // Update the display on date change
|
---|
| 892 | var self = this,
|
---|
| 893 | o = self.options,
|
---|
| 894 | testDate = null,
|
---|
| 895 | i, gridWeek, gridDay, skipThis, thisRow, y, cTheme, inheritDate, thisPRow, tmpVal, disVal,
|
---|
| 896 | interval = {'d': 60*60*24, 'h': 60*60, 'i': 60, 's':1},
|
---|
| 897 | calmode = {};
|
---|
| 898 |
|
---|
| 899 | self.input.trigger('datebox', {'method':'refresh'});
|
---|
| 900 | /* BEGIN:DURATIONBOX */
|
---|
| 901 | if ( o.mode === 'durationbox' ) {
|
---|
| 902 | i = self.theDate.getEpoch() - self.initDate.getEpoch();
|
---|
| 903 | if ( i<0 ) { i = 0; self.theDate.setTime(self.initDate.getTime()); }
|
---|
| 904 | o.lastDuration = i; // Let the number of seconds be sort of public.
|
---|
| 905 |
|
---|
| 906 | /* DAYS */
|
---|
| 907 | y = parseInt( i / interval.d,10);
|
---|
| 908 | i = i - ( y * interval.d );
|
---|
| 909 | self.pickerDay.val(y);
|
---|
| 910 |
|
---|
| 911 | /* HOURS */
|
---|
| 912 | y = parseInt( i / interval.h, 10);
|
---|
| 913 | i = i - ( y * interval.h );
|
---|
| 914 | self.pickerHour.val(y);
|
---|
| 915 |
|
---|
| 916 | /* MINS AND SECS */
|
---|
| 917 | y = parseInt( i / interval.i, 10);
|
---|
| 918 | i = i - ( y * interval.i);
|
---|
| 919 | self.pickerMins.val(y);
|
---|
| 920 | self.pickerSecs.val(parseInt(i,10));
|
---|
| 921 | }
|
---|
| 922 | /* END:DURATIONBOX */
|
---|
| 923 | /* BEGIN:TIMEBOX */
|
---|
| 924 | if ( o.mode === 'timebox' ) {
|
---|
| 925 | if ( o.minuteStep !== 1 ) {
|
---|
| 926 | i = self.theDate.getMinutes() % o.minuteStep;
|
---|
| 927 | if ( i !== 0 ) { self.theDate.adjust('m', -1*i); }
|
---|
| 928 | }
|
---|
| 929 | self.pickerMins.val(self._zPad(self.theDate.getMinutes()));
|
---|
| 930 | if ( o.lang[o.useLang].timeFormat === 12 || o.timeFormatOverride === 12 ) { // Handle meridiems
|
---|
| 931 | if ( self.theDate.getHours() > 11 ) {
|
---|
| 932 | self.pickerMeri.val(o.meridiemLetters[1]);
|
---|
| 933 | if ( self.theDate.getHours() === 12 ) {
|
---|
| 934 | self.pickerHour.val(12);
|
---|
| 935 | } else {
|
---|
| 936 | self.pickerHour.val(self.theDate.getHours() - 12);
|
---|
| 937 | }
|
---|
| 938 | } else {
|
---|
| 939 | self.pickerMeri.val(o.meridiemLetters[0]);
|
---|
| 940 | if ( self.theDate.getHours() === 0 ) {
|
---|
| 941 | self.pickerHour.val(12);
|
---|
| 942 | } else {
|
---|
| 943 | self.pickerHour.val(self.theDate.getHours());
|
---|
| 944 | }
|
---|
| 945 | }
|
---|
| 946 | } else {
|
---|
| 947 | self.pickerHour.val(self.theDate.getHours());
|
---|
| 948 | }
|
---|
| 949 | }
|
---|
| 950 | /* END:TIMEBOX */
|
---|
| 951 | /* BEGIN:FLIPBOX */
|
---|
| 952 | if ( o.mode === 'flipbox' || o.mode === 'timeflipbox' ) {
|
---|
| 953 | self._checkConstraints();
|
---|
| 954 |
|
---|
| 955 | inheritDate = self._makeDate(self.input.val());
|
---|
| 956 |
|
---|
| 957 | self.controlsHeader.empty().html( self._formatHeader(self.theDate) );
|
---|
| 958 |
|
---|
| 959 | for ( y=0; y<o.fieldsOrder.length; y++ ) {
|
---|
| 960 | tmpVal = true;
|
---|
| 961 | switch (o.fieldsOrder[y]) {
|
---|
| 962 | case 'y':
|
---|
| 963 | thisRow = self.pickerYar.find('ul');
|
---|
| 964 | thisRow.empty();
|
---|
| 965 | for ( i=-15; i<16; i++ ) {
|
---|
| 966 | cTheme = ((inheritDate.getFullYear()===(self.theDate.getFullYear() + i))?o.pickPageHighButtonTheme:o.pickPageFlipButtonTheme);
|
---|
| 967 | if ( i === 0 ) { cTheme = o.pickPageButtonTheme; }
|
---|
| 968 | $("<li>", { 'class' : 'ui-body-'+cTheme, 'style':((tmpVal===true)?'margin-top: -453px':'') })
|
---|
| 969 | .html("<span>"+(self.theDate.getFullYear() + i)+"</span>")
|
---|
| 970 | .appendTo(thisRow);
|
---|
| 971 | tmpVal = false;
|
---|
| 972 | }
|
---|
| 973 | break;
|
---|
| 974 | case 'm':
|
---|
| 975 | thisRow = self.pickerMon.find('ul');
|
---|
| 976 | thisRow.empty();
|
---|
| 977 | for ( i=-12; i<13; i++ ) {
|
---|
| 978 | testDate = new Date(self.theDate.getFullYear(), self.theDate.getMonth(), 1);
|
---|
| 979 | testDate.adjust('m',i);
|
---|
| 980 | cTheme = ( inheritDate.getMonth() === testDate.getMonth() && inheritDate.getYear() === testDate.getYear() ) ? o.pickPageHighButtonTheme : o.pickPageFlipButtonTheme;
|
---|
| 981 | if ( i === 0 ) { cTheme = o.pickPageButtonTheme; }
|
---|
| 982 | $("<li>", { 'class' : 'ui-body-'+cTheme, 'style':((tmpVal===true)?'margin-top: -357px':'') })
|
---|
| 983 | .html("<span>"+o.lang[o.useLang].monthsOfYearShort[testDate.getMonth()]+"</span>")
|
---|
| 984 | .appendTo(thisRow);
|
---|
| 985 | tmpVal = false;
|
---|
| 986 | }
|
---|
| 987 | break;
|
---|
| 988 | case 'd':
|
---|
| 989 | thisRow = self.pickerDay.find('ul');
|
---|
| 990 | thisRow.empty();
|
---|
| 991 | for ( i=-15; i<16; i++ ) {
|
---|
| 992 | testDate = self.theDate.copy();
|
---|
| 993 | testDate.adjust('d',i);
|
---|
| 994 | disVal = "";
|
---|
| 995 | if ( ( o.blackDates !== false && $.inArray(testDate.getISO(), o.blackDates) > -1 ) ||
|
---|
| 996 | ( o.blackDays !== false && $.inArray(testDate.getDay(), o.blackDays) > -1 ) ) {
|
---|
| 997 | disVal = " ui-datebox-griddate-disable";
|
---|
| 998 | }
|
---|
| 999 | cTheme = ( inheritDate.getDate() === testDate.getDate() && inheritDate.getMonth() === testDate.getMonth() && inheritDate.getYear() === testDate.getYear() ) ? o.pickPageHighButtonTheme : o.pickPageFlipButtonTheme;
|
---|
| 1000 | if ( i === 0 ) { cTheme = o.pickPageButtonTheme; }
|
---|
| 1001 | $("<li>", { 'class' : 'ui-body-'+cTheme+disVal, 'style':((tmpVal===true)?'margin-top: -453px':'') })
|
---|
| 1002 | .html("<span>"+testDate.getDate()+"</span>")
|
---|
| 1003 | .appendTo(thisRow);
|
---|
| 1004 | tmpVal = false;
|
---|
| 1005 | }
|
---|
| 1006 | break;
|
---|
| 1007 | case 'h':
|
---|
| 1008 | thisRow = self.pickerHour.find('ul');
|
---|
| 1009 | thisRow.empty();
|
---|
| 1010 | for ( i=-12; i<13; i++ ) {
|
---|
| 1011 | testDate = self.theDate.copy();
|
---|
| 1012 | testDate.adjust('h',i);
|
---|
| 1013 | cTheme = ( i === 0 ) ? o.pickPageButtonTheme : o.pickPageFlipButtonTheme;
|
---|
| 1014 | $("<li>", { 'class' : 'ui-body-'+cTheme, 'style':((tmpVal===true)?'margin-top: -357px':'') })
|
---|
| 1015 | .html("<span>"+( ( o.lang[o.useLang].timeFormat === 12 || o.timeFormatOverride === 12 ) ? ( ( testDate.getHours() === 0 ) ? '12' : ( ( testDate.getHours() < 12 ) ? testDate.getHours() : ( ( testDate.getHours() === 12 ) ? '12' : (testDate.getHours()-12) ) ) ) : testDate.getHours() )+"</span>")
|
---|
| 1016 | .appendTo(thisRow);
|
---|
| 1017 | tmpVal = false;
|
---|
| 1018 | }
|
---|
| 1019 | break;
|
---|
| 1020 | case 'i':
|
---|
| 1021 | thisRow = self.pickerMins.find('ul');
|
---|
| 1022 | thisRow.empty();
|
---|
| 1023 | for ( i=-30; i<31; i++ ) {
|
---|
| 1024 | if ( o.minuteStep > 1 ) { self.theDate.setMinutes(self.theDate.getMinutes() - (self.theDate.getMinutes() % o.minuteStep)); }
|
---|
| 1025 | testDate = self.theDate.copy();
|
---|
| 1026 | testDate.adjust('i',(i*o.minuteStep));
|
---|
| 1027 | cTheme = ( i === 0 ) ? o.pickPageButtonTheme : o.pickPageFlipButtonTheme;
|
---|
| 1028 | $("<li>", { 'class' : 'ui-body-'+cTheme, 'style':((tmpVal===true)?'margin-top: -933px':'') })
|
---|
| 1029 | .html("<span>"+self._zPad(testDate.getMinutes())+"</span>")
|
---|
| 1030 | .appendTo(thisRow);
|
---|
| 1031 | tmpVal = false;
|
---|
| 1032 | }
|
---|
| 1033 | break;
|
---|
| 1034 | case 'a':
|
---|
| 1035 | thisRow = self.pickerMeri.find('ul');
|
---|
| 1036 | thisRow.empty();
|
---|
| 1037 | if ( self.theDate.getHours() > 11 ) {
|
---|
| 1038 | tmpVal = '-65';
|
---|
| 1039 | cTheme = [o.pickPageFlipButtonTheme, o.pickPageButtonTheme];
|
---|
| 1040 | } else {
|
---|
| 1041 | tmpVal = '-33';
|
---|
| 1042 | cTheme = [o.pickPageButtonTheme, o.pickPageFlipButtonTheme];
|
---|
| 1043 | }
|
---|
| 1044 | $("<li>").appendTo(thisRow).clone().appendTo(thisRow);
|
---|
| 1045 | $("<li>", { 'class' : 'ui-body-'+cTheme[0], 'style':'margin-top: '+tmpVal+'px' })
|
---|
| 1046 | .html("<span>"+o.meridiemLetters[0]+"</span>")
|
---|
| 1047 | .appendTo(thisRow);
|
---|
| 1048 | $("<li>", { 'class' : 'ui-body-'+cTheme[1] })
|
---|
| 1049 | .html("<span>"+o.meridiemLetters[1]+"</span>")
|
---|
| 1050 | .appendTo(thisRow);
|
---|
| 1051 | $("<li>").appendTo(thisRow).clone().appendTo(thisRow);
|
---|
| 1052 | break;
|
---|
| 1053 | }
|
---|
| 1054 | }
|
---|
| 1055 | }
|
---|
| 1056 | /* END:FLIPBOX */
|
---|
| 1057 | /* BEGIN:SLIDEBOX */
|
---|
| 1058 | if ( o.mode === 'slidebox' ) {
|
---|
| 1059 | self._checkConstraints();
|
---|
| 1060 |
|
---|
| 1061 | inheritDate = self._makeDate(self.input.val());
|
---|
| 1062 |
|
---|
| 1063 | self.controlsHeader.empty().html( self._formatHeader(self.theDate) );
|
---|
| 1064 | self.controlsInput.empty();
|
---|
| 1065 |
|
---|
| 1066 | self.controlsInput.delegate('.ui-datebox-sliderow-int>div', o.clickEvent, function(e) {
|
---|
| 1067 | e.preventDefault();
|
---|
| 1068 | self._offset($(this).parent().jqmData('rowtype'), parseInt($(this).jqmData('offset'),10));
|
---|
| 1069 | });
|
---|
| 1070 | self.controlsInput.delegate('.ui-datebox-sliderow-int>div', 'vmouseover vmouseout', function() {
|
---|
| 1071 | self._hoover(this);
|
---|
| 1072 | });
|
---|
| 1073 |
|
---|
| 1074 | if ( o.wheelExists ) {
|
---|
| 1075 | self.controlsInput.delegate('.ui-datebox-sliderow-int', 'mousewheel', function(e,d) {
|
---|
| 1076 | e.preventDefault();
|
---|
| 1077 | self._offset($(this).jqmData('rowtype'), ((d>0)?1:-1));
|
---|
| 1078 | });
|
---|
| 1079 | }
|
---|
| 1080 |
|
---|
| 1081 | if ( o.swipeEnabled ) {
|
---|
| 1082 | self.controlsInput.delegate('.ui-datebox-sliderow-int', self.START_DRAG, function(e) {
|
---|
| 1083 | if ( !self.dragMove ) {
|
---|
| 1084 | self.dragMove = true;
|
---|
| 1085 | self.dragTarget = $(this);
|
---|
| 1086 | self.dragPos = parseInt(self.dragTarget.css('marginLeft').replace(/px/i, ''),10);
|
---|
| 1087 | self.dragStart = self.touch ? e.originalEvent.changedTouches[0].pageX : e.pageX;
|
---|
| 1088 | self.dragEnd = false;
|
---|
| 1089 | e.stopPropagation();
|
---|
| 1090 | e.preventDefault();
|
---|
| 1091 | }
|
---|
| 1092 | });
|
---|
| 1093 | }
|
---|
| 1094 |
|
---|
| 1095 | for ( y=0; y<o.fieldsOrder.length; y++ ) {
|
---|
| 1096 | thisPRow = $("<div>").jqmData('rowtype', o.fieldsOrder[y]);
|
---|
| 1097 | thisRow = $("<div>", {'class': 'ui-datebox-sliderow-int'}).jqmData('rowtype',o.fieldsOrder[y]).appendTo(thisPRow);
|
---|
| 1098 |
|
---|
| 1099 | if ( o.lang[o.useLang].isRTL === true ) { thisRow.css('direction', 'rtl'); }
|
---|
| 1100 |
|
---|
| 1101 | switch (o.fieldsOrder[y]) {
|
---|
| 1102 | case 'y':
|
---|
| 1103 | thisPRow.addClass('ui-datebox-sliderow-ym');
|
---|
| 1104 | thisRow.css('marginLeft', '-333px');
|
---|
| 1105 | for ( i=-5; i<6; i++ ) {
|
---|
| 1106 | cTheme = ((inheritDate.getFullYear()===(self.theDate.getFullYear() + i))?o.pickPageHighButtonTheme:o.pickPageSlideButtonTheme);
|
---|
| 1107 | if ( i === 0 ) { cTheme = o.pickPageButtonTheme; }
|
---|
| 1108 | $("<div>", { 'class' : 'ui-datebox-slideyear ui-corner-all ui-btn-up-'+cTheme })
|
---|
| 1109 | .html(self.theDate.getFullYear() + i)
|
---|
| 1110 | .jqmData('offset', i)
|
---|
| 1111 | .jqmData('theme', cTheme)
|
---|
| 1112 | .appendTo(thisRow);
|
---|
| 1113 | }
|
---|
| 1114 | break;
|
---|
| 1115 | case 'm':
|
---|
| 1116 | thisPRow.addClass('ui-datebox-sliderow-ym');
|
---|
| 1117 | thisRow.css('marginLeft', '-204px');
|
---|
| 1118 | for ( i=-6; i<7; i++ ) {
|
---|
| 1119 | testDate = new Date(self.theDate.getFullYear(), self.theDate.getMonth(), 1);
|
---|
| 1120 | testDate.adjust('m',i);
|
---|
| 1121 | cTheme = ( inheritDate.getMonth() === testDate.getMonth() && inheritDate.getYear() === testDate.getYear() ) ? o.pickPageHighButtonTheme : o.pickPageSlideButtonTheme;
|
---|
| 1122 | if ( i === 0 ) { cTheme = o.pickPageButtonTheme; }
|
---|
| 1123 | $("<div>", { 'class' : 'ui-datebox-slidemonth ui-corner-all ui-btn-up-'+cTheme })
|
---|
| 1124 | .jqmData('offset', i)
|
---|
| 1125 | .jqmData('theme', cTheme)
|
---|
| 1126 | .html(o.lang[o.useLang].monthsOfYearShort[testDate.getMonth()])
|
---|
| 1127 | .appendTo(thisRow);
|
---|
| 1128 | }
|
---|
| 1129 | break;
|
---|
| 1130 | case 'd':
|
---|
| 1131 | thisPRow.addClass('ui-datebox-sliderow-d');
|
---|
| 1132 | thisRow.css('marginLeft', '-386px');
|
---|
| 1133 | for ( i=-15; i<16; i++ ) {
|
---|
| 1134 | testDate = self.theDate.copy();
|
---|
| 1135 | testDate.adjust('d',i);
|
---|
| 1136 | disVal = "";
|
---|
| 1137 | if ( ( o.blackDates !== false && $.inArray(testDate.getISO(), o.blackDates) > -1 ) ||
|
---|
| 1138 | ( o.blackDays !== false && $.inArray(testDate.getDay(), o.blackDays) > -1 ) ) {
|
---|
| 1139 | disVal = " ui-datebox-griddate-disable";
|
---|
| 1140 | }
|
---|
| 1141 | cTheme = ( inheritDate.getDate() === testDate.getDate() && inheritDate.getMonth() === testDate.getMonth() && inheritDate.getYear() === testDate.getYear() ) ? o.pickPageHighButtonTheme : o.pickPageSlideButtonTheme;
|
---|
| 1142 | if ( i === 0 ) { cTheme = o.pickPageButtonTheme; }
|
---|
| 1143 |
|
---|
| 1144 | $("<div>", { 'class' : 'ui-datebox-slideday ui-corner-all ui-btn-up-'+cTheme+disVal })
|
---|
| 1145 | .jqmData('offset', i)
|
---|
| 1146 | .jqmData('theme', cTheme)
|
---|
| 1147 | .html(testDate.getDate() + '<br /><span class="ui-datebox-slidewday">' + o.lang[o.useLang].daysOfWeekShort[testDate.getDay()] + '</span>')
|
---|
| 1148 | .appendTo(thisRow);
|
---|
| 1149 | }
|
---|
| 1150 | break;
|
---|
| 1151 | case 'h':
|
---|
| 1152 | thisPRow.addClass('ui-datebox-sliderow-hi');
|
---|
| 1153 | thisRow.css('marginLeft', '-284px');
|
---|
| 1154 | for ( i=-12; i<13; i++ ) {
|
---|
| 1155 | testDate = self.theDate.copy();
|
---|
| 1156 | testDate.adjust('h',i);
|
---|
| 1157 | cTheme = ( i === 0 ) ? o.pickPageButtonTheme : o.pickPageSlideButtonTheme;
|
---|
| 1158 | $("<div>", { 'class' : 'ui-datebox-slidehour ui-corner-all ui-btn-up-'+cTheme })
|
---|
| 1159 | .jqmData('offset', i)
|
---|
| 1160 | .jqmData('theme', cTheme)
|
---|
| 1161 | .html(( ( o.lang[o.useLang].timeFormat === 12 || o.timeFormatOverride === 12 ) ? ( ( testDate.getHours() === 0 ) ? '12<span class="ui-datebox-slidewday">AM</span>' : ( ( testDate.getHours() < 12 ) ? testDate.getHours() + '<span class="ui-datebox-slidewday">AM</span>' : ( ( testDate.getHours() === 12 ) ? '12<span class="ui-datebox-slidewday">PM</span>' : (testDate.getHours()-12) + '<span class="ui-datebox-slidewday">PM</span>') ) ) : testDate.getHours() ))
|
---|
| 1162 | .appendTo(thisRow);
|
---|
| 1163 | }
|
---|
| 1164 | break;
|
---|
| 1165 | case 'i':
|
---|
| 1166 | thisPRow.addClass('ui-datebox-sliderow-hi');
|
---|
| 1167 | thisRow.css('marginLeft', '-896px');
|
---|
| 1168 | for ( i=-30; i<31; i++ ) {
|
---|
| 1169 | testDate = self.theDate.copy();
|
---|
| 1170 | testDate.adjust('i',i);
|
---|
| 1171 | cTheme = ( i === 0 ) ? o.pickPageButtonTheme : o.pickPageSlideButtonTheme;
|
---|
| 1172 | $("<div>", { 'class' : 'ui-datebox-slidemins ui-corner-all ui-btn-up-'+cTheme })
|
---|
| 1173 | .jqmData('offset', i)
|
---|
| 1174 | .jqmData('theme', cTheme)
|
---|
| 1175 | .html(self._zPad(testDate.getMinutes()))
|
---|
| 1176 | .appendTo(thisRow);
|
---|
| 1177 | }
|
---|
| 1178 | break;
|
---|
| 1179 | }
|
---|
| 1180 | thisPRow.appendTo(self.controlsInput);
|
---|
| 1181 | }
|
---|
| 1182 | }
|
---|
| 1183 | /* END:SLIDEBOX */
|
---|
| 1184 | /* BEGIN:DATEBOX */
|
---|
| 1185 | if ( o.mode === 'datebox' ) {
|
---|
| 1186 | self._checkConstraints();
|
---|
| 1187 |
|
---|
| 1188 | self.controlsHeader.empty().html( self._formatHeader(self.theDate) );
|
---|
| 1189 | self.pickerMon.val(self.theDate.getMonth() + 1);
|
---|
| 1190 | self.pickerDay.val(self.theDate.getDate());
|
---|
| 1191 | self.pickerYar.val(self.theDate.getFullYear());
|
---|
| 1192 |
|
---|
| 1193 | if ( self.dateOK !== true ) {
|
---|
| 1194 | self.controlsInput.find('input').addClass('ui-datebox-griddate-disable');
|
---|
| 1195 | } else {
|
---|
| 1196 | self.controlsInput.find('.ui-datebox-griddate-disable').removeClass('ui-datebox-griddate-disable');
|
---|
| 1197 | }
|
---|
| 1198 | }
|
---|
| 1199 | /* END:DATEBOX */
|
---|
| 1200 | /* BEGIN:CALBOX */
|
---|
| 1201 | if ( o.mode === 'calbox' ) { // Meat and potatos - make the calendar grid.
|
---|
| 1202 | self.controlsInput.empty().html( o.lang[o.useLang].monthsOfYear[self.theDate.getMonth()] + " " + self.theDate.getFullYear() );
|
---|
| 1203 | self.controlsPlus.empty();
|
---|
| 1204 |
|
---|
| 1205 | calmode = {'today': -1, 'highlightDay': -1, 'presetDay': -1, 'nexttoday': 1,
|
---|
| 1206 | 'thisDate': new Date(), 'maxDate': new Date(), 'minDate': new Date(), 'startDay': false,
|
---|
| 1207 | 'currentMonth': false, 'weekMode': 0, 'weekDays': null, 'thisTheme': o.pickPageButtonTheme };
|
---|
| 1208 | calmode.start = self._getFirstDay(self.theDate);
|
---|
| 1209 | calmode.end = self._getLastDate(self.theDate);
|
---|
| 1210 | calmode.lastend = self._getLastDateBefore(self.theDate);
|
---|
| 1211 | calmode.presetDate = self._makeDate(self.input.val());
|
---|
| 1212 |
|
---|
| 1213 | if ( o.calStartDay !== false || typeof o.lang[o.useLang].calStartDay === "number" ) {
|
---|
| 1214 | if ( o.calStartDay !== false ) {
|
---|
| 1215 | calmode.start = calmode.start - o.calStartDay;
|
---|
| 1216 | calmode.startDay = o.calStartDay;
|
---|
| 1217 | } else {
|
---|
| 1218 | calmode.start = calmode.start - o.lang[o.useLang].calStartDay;
|
---|
| 1219 | calmode.startDay = o.lang[o.useLang].calStartDay;
|
---|
| 1220 | }
|
---|
| 1221 | if ( calmode.start < 0 ) { calmode.start = calmode.start + 7; }
|
---|
| 1222 | }
|
---|
| 1223 |
|
---|
| 1224 | calmode.prevtoday = calmode.lastend - (calmode.start - 1);
|
---|
| 1225 | calmode.checkDates = ( o.enableDates === false && ( o.afterToday !== false || o.beforeToday !== false || o.notToday !== false || o.maxDays !== false || o.minDays !== false || o.blackDates !== false || o.blackDays !== false ) );
|
---|
| 1226 |
|
---|
| 1227 | if ( calmode.thisDate.getMonth() === self.theDate.getMonth() && calmode.thisDate.getFullYear() === self.theDate.getFullYear() ) { calmode.currentMonth = true; calmode.highlightDay = calmode.thisDate.getDate(); }
|
---|
| 1228 | if ( calmode.presetDate.getComp() === self.theDate.getComp() ) { calmode.presetDay = calmode.presetDate.getDate(); }
|
---|
| 1229 |
|
---|
| 1230 | self.calNoPrev = false; self.calNoNext = false;
|
---|
| 1231 |
|
---|
| 1232 | if ( o.afterToday === true &&
|
---|
| 1233 | ( calmode.currentMonth === true || ( calmode.thisDate.getMonth() >= self.theDate.getMonth() && self.theDate.getFullYear() === calmode.thisDate.getFullYear() ) ) ) {
|
---|
| 1234 | self.calNoPrev = true; }
|
---|
| 1235 | if ( o.beforeToday === true &&
|
---|
| 1236 | ( calmode.currentMonth === true || ( calmode.thisDate.getMonth() <= self.theDate.getMonth() && self.theDate.getFullYear() === calmode.thisDate.getFullYear() ) ) ) {
|
---|
| 1237 | self.calNoNext = true; }
|
---|
| 1238 |
|
---|
| 1239 | if ( o.minDays !== false ) {
|
---|
| 1240 | calmode.minDate.adjust('d', -1*o.minDays);
|
---|
| 1241 | if ( self.theDate.getFullYear() === calmode.minDate.getFullYear() && self.theDate.getMonth() <= calmode.minDate.getMonth() ) { self.calNoPrev = true;}
|
---|
| 1242 | }
|
---|
| 1243 | if ( o.maxDays !== false ) {
|
---|
| 1244 | calmode.maxDate.adjust('d', o.maxDays);
|
---|
| 1245 | if ( self.theDate.getFullYear() === calmode.maxDate.getFullYear() && self.theDate.getMonth() >= calmode.maxDate.getMonth() ) { self.calNoNext = true;}
|
---|
| 1246 | }
|
---|
| 1247 |
|
---|
| 1248 | if ( o.calShowDays ) {
|
---|
| 1249 | if ( o.lang[o.useLang].daysOfWeekShort.length < 8 ) { o.daysOfWeekShort = o.lang[o.useLang].daysOfWeekShort.concat(o.lang[o.useLang].daysOfWeekShort); }
|
---|
| 1250 | calmode.weekDays = $("<div>", {'class':'ui-datebox-gridrow'}).appendTo(self.controlsPlus);
|
---|
| 1251 | if ( o.lang[o.useLang].isRTL === true ) { calmode.weekDays.css('direction', 'rtl'); }
|
---|
| 1252 | for ( i=0; i<=6;i++ ) {
|
---|
| 1253 | $("<div>"+o.lang[o.useLang].daysOfWeekShort[(i+calmode.startDay)%7]+"</div>").addClass('ui-datebox-griddate ui-datebox-griddate-empty ui-datebox-griddate-label').appendTo(calmode.weekDays);
|
---|
| 1254 | }
|
---|
| 1255 | }
|
---|
| 1256 |
|
---|
| 1257 | if ( o.fixDateArrays === true ) {
|
---|
| 1258 | o.blackDates = self._fixArray(o.blackDates);
|
---|
| 1259 | o.highDates = self._fixArray(o.highDates);
|
---|
| 1260 | o.highDatesAlt = self._fixArray(o.highDatesAlt);
|
---|
| 1261 | o.enableDates = self._fixArray(o.enableDates);
|
---|
| 1262 | }
|
---|
| 1263 |
|
---|
| 1264 | for ( gridWeek=0; gridWeek<=5; gridWeek++ ) {
|
---|
| 1265 | if ( gridWeek === 0 || ( gridWeek > 0 && (calmode.today > 0 && calmode.today <= calmode.end) ) ) {
|
---|
| 1266 | thisRow = $("<div>", {'class': 'ui-datebox-gridrow'});
|
---|
| 1267 | if ( o.lang[o.useLang].isRTL === true ) { thisRow.css('direction', 'rtl'); }
|
---|
| 1268 | for ( gridDay=0; gridDay<=6; gridDay++) {
|
---|
| 1269 | if ( gridDay === 0 ) { calmode.weekMode = ( calmode.today < 1 ) ? (calmode.prevtoday - calmode.lastend + o.calWeekModeFirstDay) : (calmode.today + o.calWeekModeFirstDay); }
|
---|
| 1270 | if ( gridDay === calmode.start && gridWeek === 0 ) { calmode.today = 1; }
|
---|
| 1271 | if ( calmode.today > calmode.end ) { calmode.today = -1; }
|
---|
| 1272 | if ( calmode.today < 1 ) {
|
---|
| 1273 | if ( o.calShowOnlyMonth ) {
|
---|
| 1274 | $("<div>", {'class': 'ui-datebox-griddate ui-datebox-griddate-empty'}).appendTo(thisRow);
|
---|
| 1275 | } else {
|
---|
| 1276 | if ( o.enableDates !== false ) {
|
---|
| 1277 | if (
|
---|
| 1278 | ( $.inArray(self.theDate.copymod([0,-1],[0,0,calmode.prevtoday]).getISO(), o.enableDates) > -1 ) ||
|
---|
| 1279 | ( $.inArray(self.theDate.copymod([0,1],[0,0,calmode.nexttoday]).getISO(), o.enableDates) > -1 ) ) {
|
---|
| 1280 | skipThis = false;
|
---|
| 1281 | } else { skipThis = true; }
|
---|
| 1282 | } else {
|
---|
| 1283 | if (
|
---|
| 1284 | ( o.afterToday !== false && gridWeek === 0 && calmode.thisDate.getMonth() >= self.theDate.getMonth()-1 && self.theDate.getFullYear() === calmode.thisDate.getFullYear() && calmode.thisDate.getDate() > calmode.prevtoday ) ||
|
---|
| 1285 | ( o.beforeToday !== false && gridWeek !== 0 && calmode.thisDate.getMonth() <= self.theDate.getMonth()+1 && self.theDate.getFullYear() === calmode.thisDate.getFullYear() && calmode.thisDate.getDate() < calmode.nexttoday ) ||
|
---|
| 1286 | ( o.blackDays !== false && $.inArray(gridDay, o.blackDays) > -1 ) ||
|
---|
| 1287 | ( o.blackDates !== false && $.inArray(self.theDate.copymod([0,-1],[0,0,calmode.prevtoday]).getISO(), o.blackDates) > -1 ) ||
|
---|
| 1288 | ( o.blackDates !== false && $.inArray(self.theDate.copymod([0,1],[0,0,calmode.nexttoday]).getISO(), o.blackDates) > -1 ) ) {
|
---|
| 1289 | skipThis = true;
|
---|
| 1290 | } else { skipThis = false; }
|
---|
| 1291 | }
|
---|
| 1292 |
|
---|
| 1293 | if ( gridWeek === 0 ) {
|
---|
| 1294 | $("<div>"+String(calmode.prevtoday)+"</div>")
|
---|
| 1295 | .addClass('ui-datebox-griddate ui-datebox-griddate-empty').appendTo(thisRow)
|
---|
| 1296 | .jqmData('date', ((o.calWeekMode)?(calmode.weekMode+calmode.lastend):calmode.prevtoday))
|
---|
| 1297 | .jqmData('enabled', (!skipThis && !self.calNoPrev))
|
---|
| 1298 | .jqmData('month', -1);
|
---|
| 1299 | calmode.prevtoday++;
|
---|
| 1300 | } else {
|
---|
| 1301 | $("<div>"+String(calmode.nexttoday)+"</div>")
|
---|
| 1302 | .addClass('ui-datebox-griddate ui-datebox-griddate-empty').appendTo(thisRow)
|
---|
| 1303 | .jqmData('date', ((o.calWeekMode)?calmode.weekMode:calmode.nexttoday))
|
---|
| 1304 | .jqmData('enabled', (!skipThis && !self.calNoNext))
|
---|
| 1305 | .jqmData('month', 1);
|
---|
| 1306 | calmode.nexttoday++;
|
---|
| 1307 | }
|
---|
| 1308 | }
|
---|
| 1309 | } else {
|
---|
| 1310 | skipThis = false;
|
---|
| 1311 | if ( o.enableDates ) {
|
---|
| 1312 | if ( $.inArray(self.theDate.copymod([0],[0,0,calmode.today]).getISO(), o.enableDates) < 0 ) {
|
---|
| 1313 | skipThis = true;
|
---|
| 1314 | }
|
---|
| 1315 | }
|
---|
| 1316 | if ( calmode.checkDates ) {
|
---|
| 1317 | if ( o.afterToday && calmode.thisDate.getComp() > (self.theDate.getComp()+calmode.today-self.theDate.getDate()) ) {
|
---|
| 1318 | skipThis = true;
|
---|
| 1319 | }
|
---|
| 1320 | if ( !skipThis && o.beforeToday && calmode.thisDate.getComp() < (self.theDate.getComp()+calmode.today-self.theDate.getDate()) ) {
|
---|
| 1321 | skipThis = true;
|
---|
| 1322 | }
|
---|
| 1323 | if ( !skipThis && o.notToday && calmode.today === calmode.highlightDay ) {
|
---|
| 1324 | skipThis = true;
|
---|
| 1325 | }
|
---|
| 1326 | if ( !skipThis && o.maxDays !== false && calmode.maxDate.getComp() < (self.theDate.getComp()+calmode.today-self.theDate.getDate()) ) {
|
---|
| 1327 | skipThis = true;
|
---|
| 1328 | }
|
---|
| 1329 | if ( !skipThis && o.minDays !== false && calmode.minDate.getComp() > (self.theDate.getComp()+calmode.today-self.theDate.getDate()) ) {
|
---|
| 1330 | skipThis = true;
|
---|
| 1331 | }
|
---|
| 1332 | if ( !skipThis && ( o.blackDays !== false || o.blackDates !== false ) ) { // Blacklists
|
---|
| 1333 | if (
|
---|
| 1334 | ( $.inArray(gridDay, o.blackDays) > -1 ) ||
|
---|
| 1335 | ( $.inArray(self.theDate.copymod([0],[0,0,calmode.today]).getISO(), o.blackDates) > -1 ) ) {
|
---|
| 1336 | skipThis = true;
|
---|
| 1337 | }
|
---|
| 1338 | }
|
---|
| 1339 | }
|
---|
| 1340 |
|
---|
| 1341 | if ( o.calHighPicked && calmode.today === calmode.presetDay ) {
|
---|
| 1342 | calmode.thisTheme = o.pickPageHighButtonTheme;
|
---|
| 1343 | } else if ( o.calHighToday && calmode.today === calmode.highlightDay ) {
|
---|
| 1344 | calmode.thisTheme = o.pickPageTodayButtonTheme;
|
---|
| 1345 | } else if ( $.isArray(o.highDatesAlt) && ($.inArray(self.theDate.copymod([0],[0,0,calmode.today]).getISO(), o.highDatesAlt) > -1 ) ) {
|
---|
| 1346 | calmode.thisTheme = o.pickPageOAHighButtonTheme;
|
---|
| 1347 | } else if ( $.isArray(o.highDates) && ($.inArray(self.theDate.copymod([0],[0,0,calmode.today]).getISO(), o.highDates) > -1 ) ) {
|
---|
| 1348 | calmode.thisTheme = o.pickPageOHighButtonTheme;
|
---|
| 1349 | } else if ( $.isArray(o.highDays) && $.inArray(gridDay, o.highDays) > -1 ) {
|
---|
| 1350 | calmode.thisTheme = o.pickPageODHighButtonTheme;
|
---|
| 1351 | } else {
|
---|
| 1352 | calmode.thisTheme = o.pickPageButtonTheme;
|
---|
| 1353 | }
|
---|
| 1354 |
|
---|
| 1355 | $("<div>"+String(calmode.today)+"</div>")
|
---|
| 1356 | .addClass('ui-datebox-griddate ui-corner-all ui-btn-up-' + calmode.thisTheme + ((skipThis)?' ui-datebox-griddate-disable':''))
|
---|
| 1357 | .jqmData('date', ((o.calWeekMode)?calmode.weekMode:calmode.today))
|
---|
| 1358 | .jqmData('theme', calmode.thisTheme)
|
---|
| 1359 | .jqmData('enabled', !skipThis)
|
---|
| 1360 | .jqmData('month', 0)
|
---|
| 1361 | .appendTo(thisRow);
|
---|
| 1362 | calmode.today++;
|
---|
| 1363 | }
|
---|
| 1364 | }
|
---|
| 1365 | }
|
---|
| 1366 | thisRow.appendTo(self.controlsPlus);
|
---|
| 1367 | }
|
---|
| 1368 | self.controlsPlus.delegate('div.ui-datebox-griddate', o.clickEvent + ' vmouseover vmouseout', function(e) {
|
---|
| 1369 | if ( e.type === o.clickEvent ) {
|
---|
| 1370 | e.preventDefault();
|
---|
| 1371 | if ( $(this).jqmData('enabled') ) {
|
---|
| 1372 |
|
---|
| 1373 | if ( $(this).jqmData('month') < 0 ) {
|
---|
| 1374 | self.theDate.adjust('m', -1);
|
---|
| 1375 | self.theDate.setDate($(this).jqmData('date'));
|
---|
| 1376 | } else if ( $(this).jqmData('month') > 0 ) {
|
---|
| 1377 | self.theDate.setDate($(this).jqmData('date'));
|
---|
| 1378 | if ( !o.calWeekMode ) { self.theDate.adjust('m',1); }
|
---|
| 1379 | } else {
|
---|
| 1380 | self.theDate.setDate($(this).jqmData('date'));
|
---|
| 1381 | }
|
---|
| 1382 | self.input.trigger('datebox', {'method':'set', 'value':self._formatDate(self.theDate), 'date':self.theDate});
|
---|
| 1383 | self.input.trigger('datebox', {'method':'close'});
|
---|
| 1384 | }
|
---|
| 1385 | } else {
|
---|
| 1386 | if ( $(this).jqmData('enabled') && typeof $(this).jqmData('theme') !== 'undefined' ) {
|
---|
| 1387 | if ( o.calWeekMode !== false && o.calWeekModeHighlight === true ) {
|
---|
| 1388 | $(this).parent().find('div').each(function() { self._hoover(this); });
|
---|
| 1389 | } else { self._hoover(this); }
|
---|
| 1390 | }
|
---|
| 1391 | }
|
---|
| 1392 | });
|
---|
| 1393 | }
|
---|
| 1394 | /* END:CALBOX */
|
---|
| 1395 |
|
---|
| 1396 | if ( o.lang[this.options.useLang].useArabicIndic === true ) {
|
---|
| 1397 | self._makeDisplayIndic();
|
---|
| 1398 | }
|
---|
| 1399 | },
|
---|
| 1400 | _getLongOptions: function(element) {
|
---|
| 1401 | var key, retty = {}, prefix, temp;
|
---|
| 1402 |
|
---|
| 1403 | if ( $.mobile.ns == "" ) {
|
---|
| 1404 | prefix = "datebox";
|
---|
| 1405 | } else {
|
---|
| 1406 | prefix = $.mobile.ns.substr(0, $.mobile.ns.length - 1) + 'Datebox';
|
---|
| 1407 | }
|
---|
| 1408 |
|
---|
| 1409 | for ( key in element.data() ) {
|
---|
| 1410 | if ( key.substr(0, prefix.length) === prefix && key.length > prefix.length ) {
|
---|
| 1411 | temp = key.substr(prefix.length);
|
---|
| 1412 | temp = temp.charAt(0).toLowerCase() + temp.slice(1);
|
---|
| 1413 | retty[temp] = element.data(key);
|
---|
| 1414 | }
|
---|
| 1415 | }
|
---|
| 1416 | return retty;
|
---|
| 1417 | },
|
---|
| 1418 | _create: function() {
|
---|
| 1419 | // Create the widget, called automatically by widget system
|
---|
| 1420 |
|
---|
| 1421 | // Trigger dateboxcreate
|
---|
| 1422 | $( document ).trigger( "dateboxcreate" );
|
---|
| 1423 |
|
---|
| 1424 | var self = this,
|
---|
| 1425 | o = $.extend(this.options, this.element.jqmData('options')),
|
---|
| 1426 | o = ((typeof this.element.jqmData('options') === 'undefined') ? $.extend(o, this._getLongOptions(this.element)) : o);
|
---|
| 1427 | input = this.element,
|
---|
| 1428 | thisTheme = ( o.theme === false && typeof($(self).jqmData('theme')) === 'undefined' ) ?
|
---|
| 1429 | ( ( typeof(input.parentsUntil(':jqmData(theme)').parent().jqmData('theme')) === 'undefined' ) ?
|
---|
| 1430 | o.defaultTheme : input.parentsUntil(':jqmData(theme)').parent().jqmData('theme') )
|
---|
| 1431 | : o.theme,
|
---|
| 1432 | focusedEl = input.wrap('<div class="ui-input-datebox ui-shadow-inset ui-corner-all ui-body-'+ thisTheme +'"></div>').parent(),
|
---|
| 1433 | theDate = new Date(), // Internal date object, used for all operations
|
---|
| 1434 | initDate = new Date(theDate.getTime()), // Initilization time - used for duration
|
---|
| 1435 |
|
---|
| 1436 | // This is the button that is added to the original input
|
---|
| 1437 | openbutton = $('<a href="#" class="ui-input-clear" title="'+((typeof o.lang[o.useLang].tooltip !== 'undefined')?o.lang[o.useLang].tooltip:o.lang.en.tooltip)+'">'+((typeof o.lang[o.useLang].tooltip !== 'undefined')?o.lang[o.useLang].tooltip:o.lang.en.tooltip)+'</a>')
|
---|
| 1438 | .bind(o.clickEvent, function (e) {
|
---|
| 1439 | e.preventDefault();
|
---|
| 1440 | if ( !o.disabled ) { self.input.trigger('datebox', {'method': 'open'}); self.focusedEl.addClass('ui-focus'); }
|
---|
| 1441 | setTimeout( function() { $(e.target).closest("a").removeClass($.mobile.activeBtnClass); }, 300);
|
---|
| 1442 | })
|
---|
| 1443 | .appendTo(focusedEl).buttonMarkup({icon: 'grid', iconpos: 'notext', corners:true, shadow:true})
|
---|
| 1444 | .css({'vertical-align': 'middle', 'display': 'inline-block'}),
|
---|
| 1445 | thisPage = input.closest('.ui-page'),
|
---|
| 1446 | ns = (typeof $.mobile.ns !== 'undefined')?$.mobile.ns:'',
|
---|
| 1447 | pickPage = $("<div data-"+ns+"role='dialog' class='ui-dialog-datebox' data-"+ns+"theme='" + ((o.forceInheritTheme === false ) ? o.pickPageTheme : thisTheme ) + "' >" +
|
---|
| 1448 | "<div data-"+ns+"role='header' data-"+ns+"backbtn='false' data-"+ns+"theme='a'>" +
|
---|
| 1449 | "<div class='ui-title'>PlaceHolder</div>"+
|
---|
| 1450 | "</div>"+
|
---|
| 1451 | "<div data-"+ns+"role='content'></div>"+
|
---|
| 1452 | "</div>")
|
---|
| 1453 | .appendTo( $.mobile.pageContainer )
|
---|
| 1454 | .page().css('minHeight', '0px').css('zIndex', o.zindex).addClass(o.transition),
|
---|
| 1455 | pickPageTitle = pickPage.find('.ui-title'),
|
---|
| 1456 | pickPageContent = pickPage.find( ".ui-content" ),
|
---|
| 1457 | touch = ( typeof window.ontouchstart !== 'undefined' ),
|
---|
| 1458 | START_EVENT = touch ? 'touchstart' : 'mousedown',
|
---|
| 1459 | MOVE_EVENT = touch ? 'touchmove' : 'mousemove',
|
---|
| 1460 | END_EVENT = touch ? 'touchend' : 'mouseup',
|
---|
| 1461 | dragMove = false,
|
---|
| 1462 | dragStart = false,
|
---|
| 1463 | dragEnd = false,
|
---|
| 1464 | dragPos = false,
|
---|
| 1465 | dragTarget = false,
|
---|
| 1466 | dragThisDelta = 0;
|
---|
| 1467 |
|
---|
| 1468 | o.theme = thisTheme;
|
---|
| 1469 |
|
---|
| 1470 | $.extend(self, {
|
---|
| 1471 | input: input,
|
---|
| 1472 | focusedEl: focusedEl });
|
---|
| 1473 |
|
---|
| 1474 | if ( o.forceInheritTheme ) {
|
---|
| 1475 | o.pickPageTheme = thisTheme;
|
---|
| 1476 | o.pickPageInputTheme = thisTheme;
|
---|
| 1477 | o.pickPageButtonTheme = thisTheme;
|
---|
| 1478 | }
|
---|
| 1479 |
|
---|
| 1480 | if ( o.defaultPickerValue===false && o.defaultDate!==false ) {
|
---|
| 1481 | o.defaultPickerValue = o.defaultDate;
|
---|
| 1482 | }
|
---|
| 1483 |
|
---|
| 1484 | if ( o.numberInputEnhance === true ) {
|
---|
| 1485 | if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ){
|
---|
| 1486 | o.internalInputType = 'number';
|
---|
| 1487 | }
|
---|
| 1488 | }
|
---|
| 1489 |
|
---|
| 1490 | $('label[for=\''+input.attr('id')+'\']').addClass('ui-input-text').css('verticalAlign', 'middle');
|
---|
| 1491 |
|
---|
| 1492 | /* BUILD:MODE */
|
---|
| 1493 |
|
---|
| 1494 | if ( o.mode === "timeflipbox" ) { // No header in time flipbox.
|
---|
| 1495 | o.lang[o.useLang].headerFormat = ' ';
|
---|
| 1496 | }
|
---|
| 1497 |
|
---|
| 1498 | // For focus mode, disable button, and bind click of input element and it's parent
|
---|
| 1499 | if ( o.noButtonFocusMode || o.useInline || o.noButton ) { openbutton.hide(); }
|
---|
| 1500 |
|
---|
| 1501 | self.focusedEl.bind(o.clickEvent, function() {
|
---|
| 1502 | if ( !o.disabled && ( o.noButtonFocusMode || o.focusMode ) ) {
|
---|
| 1503 | self.input.trigger('datebox', {'method': 'open'});
|
---|
| 1504 | self.focusedEl.addClass('ui-focus');
|
---|
| 1505 | self.input.removeClass('ui-focus');
|
---|
| 1506 | }
|
---|
| 1507 | });
|
---|
| 1508 |
|
---|
| 1509 |
|
---|
| 1510 | self.input
|
---|
| 1511 | .removeClass('ui-corner-all ui-shadow-inset')
|
---|
| 1512 | .focus(function(){
|
---|
| 1513 | if ( ! o.disabled ) {
|
---|
| 1514 | self.focusedEl.addClass('ui-focus');
|
---|
| 1515 | }
|
---|
| 1516 | self.input.removeClass('ui-focus');
|
---|
| 1517 | })
|
---|
| 1518 | .blur(function(){
|
---|
| 1519 | self.focusedEl.removeClass('ui-focus');
|
---|
| 1520 | self.input.removeClass('ui-focus');
|
---|
| 1521 | })
|
---|
| 1522 | .change(function() {
|
---|
| 1523 | self.theDate = self._makeDate(self.input.val());
|
---|
| 1524 | self._update();
|
---|
| 1525 | });
|
---|
| 1526 |
|
---|
| 1527 | // Bind the master handler.
|
---|
| 1528 | self.input.bind('datebox', self._dateboxHandler);
|
---|
| 1529 |
|
---|
| 1530 | // Bind the close button on the DIALOG mode. (after unbinding the default)
|
---|
| 1531 | pickPage.find( ".ui-header a").unbind('click vclick').bind(o.clickEvent, function(e) {
|
---|
| 1532 | e.preventDefault();
|
---|
| 1533 | e.stopImmediatePropagation();
|
---|
| 1534 | self.input.trigger('datebox', {'method':'close', 'fromCloseButton':false});
|
---|
| 1535 | });
|
---|
| 1536 |
|
---|
| 1537 | $.extend(self, {
|
---|
| 1538 | pickPage: pickPage,
|
---|
| 1539 | thisPage: thisPage,
|
---|
| 1540 | pickPageContent: pickPageContent,
|
---|
| 1541 | pickPageTitle: pickPageTitle,
|
---|
| 1542 | theDate: theDate,
|
---|
| 1543 | initDate: initDate,
|
---|
| 1544 | touch: touch,
|
---|
| 1545 | START_DRAG: START_EVENT,
|
---|
| 1546 | MOVE_DRAG: MOVE_EVENT,
|
---|
| 1547 | END_DRAG: END_EVENT,
|
---|
| 1548 | dragMove: dragMove,
|
---|
| 1549 | dragStart: dragStart,
|
---|
| 1550 | dragEnd: dragEnd,
|
---|
| 1551 | dragPos: dragPos
|
---|
| 1552 | });
|
---|
| 1553 |
|
---|
| 1554 | // Check if mousewheel plugin is loaded
|
---|
| 1555 | if ( typeof $.event.special.mousewheel !== 'undefined' ) { o.wheelExists = true; }
|
---|
| 1556 |
|
---|
| 1557 | self._buildPage();
|
---|
| 1558 |
|
---|
| 1559 | // drag and drop support, all ending and moving events are defined here, start events are handled in _buildPage or update
|
---|
| 1560 | if ( o.swipeEnabled ) {
|
---|
| 1561 | $(document).bind(self.MOVE_DRAG, function(e) {
|
---|
| 1562 | if ( self.dragMove ) {
|
---|
| 1563 | if ( o.mode === 'slidebox' ) {
|
---|
| 1564 | self.dragEnd = self.touch ? e.originalEvent.changedTouches[0].pageX : e.pageX;
|
---|
| 1565 | self.dragTarget.css('marginLeft', (self.dragPos + self.dragEnd - self.dragStart) + 'px');
|
---|
| 1566 | e.preventDefault();
|
---|
| 1567 | e.stopPropagation();
|
---|
| 1568 | return false;
|
---|
| 1569 | } else if ( o.mode === 'flipbox' || o.mode === 'timeflipbox' ) {
|
---|
| 1570 | self.dragEnd = self.touch ? e.originalEvent.changedTouches[0].pageY : e.pageY;
|
---|
| 1571 | self.dragTarget.css('marginTop', (self.dragPos + self.dragEnd - self.dragStart) + 'px');
|
---|
| 1572 | e.preventDefault();
|
---|
| 1573 | e.stopPropagation();
|
---|
| 1574 | return false;
|
---|
| 1575 | } else if ( o.mode === 'durationbox' || o.mode === 'timebox' || o.mode === 'datebox' ) {
|
---|
| 1576 | self.dragEnd = self.touch ? e.originalEvent.changedTouches[0].pageY : e.pageY;
|
---|
| 1577 | if ( (self.dragEnd - self.dragStart) % 2 === 0 ) {
|
---|
| 1578 | dragThisDelta = (self.dragEnd - self.dragStart) / -2;
|
---|
| 1579 | if ( dragThisDelta < self.dragPos ) {
|
---|
| 1580 | self._offset(self.dragTarget, -1*(self.dragTarget==='i'?o.minuteStep:1));
|
---|
| 1581 | } else if ( dragThisDelta > self.dragPos ) {
|
---|
| 1582 | self._offset(self.dragTarget, (self.dragTarget==='i'?o.minuteStep:1));
|
---|
| 1583 | }
|
---|
| 1584 | self.dragPos = dragThisDelta;
|
---|
| 1585 | }
|
---|
| 1586 | e.preventDefault();
|
---|
| 1587 | e.stopPropagation();
|
---|
| 1588 | return false;
|
---|
| 1589 | }
|
---|
| 1590 | }
|
---|
| 1591 | });
|
---|
| 1592 | $(document).bind(self.END_DRAG, function(e) {
|
---|
| 1593 | if ( self.dragMove ) {
|
---|
| 1594 | self.dragMove = false;
|
---|
| 1595 | if ( o.mode === 'slidebox' ) {
|
---|
| 1596 | if ( self.dragEnd !== false && Math.abs(self.dragStart - self.dragEnd) > 25 ) {
|
---|
| 1597 | e.preventDefault();
|
---|
| 1598 | e.stopPropagation();
|
---|
| 1599 | switch(self.dragTarget.parent().jqmData('rowtype')) {
|
---|
| 1600 | case 'y':
|
---|
| 1601 | self._offset('y', parseInt(( self.dragStart - self.dragEnd ) / 84, 10));
|
---|
| 1602 | break;
|
---|
| 1603 | case 'm':
|
---|
| 1604 | self._offset('m', parseInt(( self.dragStart - self.dragEnd ) / 51, 10));
|
---|
| 1605 | break;
|
---|
| 1606 | case 'd':
|
---|
| 1607 | self._offset('d', parseInt(( self.dragStart - self.dragEnd ) / 32, 10));
|
---|
| 1608 | break;
|
---|
| 1609 | case 'h':
|
---|
| 1610 | self._offset('h', parseInt(( self.dragStart - self.dragEnd ) / 32, 10));
|
---|
| 1611 | break;
|
---|
| 1612 | case 'i':
|
---|
| 1613 | self._offset('i', parseInt(( self.dragStart - self.dragEnd ) / 32, 10));
|
---|
| 1614 | break;
|
---|
| 1615 | }
|
---|
| 1616 | }
|
---|
| 1617 | } else if ( o.mode === 'flipbox' || o.mode === 'timeflipbox' ) {
|
---|
| 1618 | if ( self.dragEnd !== false ) {
|
---|
| 1619 | e.preventDefault();
|
---|
| 1620 | e.stopPropagation();
|
---|
| 1621 | var fld = self.dragTarget.parent().parent().jqmData('field'),
|
---|
| 1622 | amount = parseInt(( self.dragStart - self.dragEnd ) / 30,10);
|
---|
| 1623 | self._offset(fld, amount * ( (fld === "i") ? o.minuteStep : 1 ));
|
---|
| 1624 | }
|
---|
| 1625 | }
|
---|
| 1626 | self.dragStart = false;
|
---|
| 1627 | self.dragEnd = false;
|
---|
| 1628 | }
|
---|
| 1629 | });
|
---|
| 1630 | }
|
---|
| 1631 |
|
---|
| 1632 | // Disable when done if element attribute disabled is true.
|
---|
| 1633 | if ( self.input.is(':disabled') ) {
|
---|
| 1634 | self.disable();
|
---|
| 1635 | }
|
---|
| 1636 | // Turn input readonly if requested (on by default)
|
---|
| 1637 | if ( o.disableManualInput === true ) {
|
---|
| 1638 | self.input.attr("readonly", true);
|
---|
| 1639 | }
|
---|
| 1640 |
|
---|
| 1641 | //Throw dateboxinit event
|
---|
| 1642 | $( document ).trigger( "dateboxaftercreate" );
|
---|
| 1643 | },
|
---|
| 1644 | _makeElement: function(source, parts) {
|
---|
| 1645 | var self = this,
|
---|
| 1646 | part = false,
|
---|
| 1647 | retty = false;
|
---|
| 1648 |
|
---|
| 1649 | retty = source.clone();
|
---|
| 1650 |
|
---|
| 1651 | if ( typeof parts.attr !== 'undefined' ) {
|
---|
| 1652 | for ( part in parts.attr ) {
|
---|
| 1653 | if ( parts.attr.hasOwnProperty(part) ) {
|
---|
| 1654 | retty.jqmData(part, parts.attr[part]);
|
---|
| 1655 | }
|
---|
| 1656 | }
|
---|
| 1657 | }
|
---|
| 1658 | return retty;
|
---|
| 1659 | },
|
---|
| 1660 | _eventEnterValue: function (item) {
|
---|
| 1661 | var self = this,
|
---|
| 1662 | o = self.options,
|
---|
| 1663 | newHour = false;
|
---|
| 1664 |
|
---|
| 1665 | if ( item.val() !== '' && self._isInt(item.val()) ) {
|
---|
| 1666 | switch(item.jqmData('field')) {
|
---|
| 1667 | case 'm':
|
---|
| 1668 | self.theDate.setMonth(parseInt(item.val(),10)-1); break;
|
---|
| 1669 | case 'd':
|
---|
| 1670 | self.theDate.setDate(parseInt(item.val(),10)); break;
|
---|
| 1671 | case 'y':
|
---|
| 1672 | self.theDate.setFullYear(parseInt(item.val(),10)); break;
|
---|
| 1673 | case 'i':
|
---|
| 1674 | self.theDate.setMinutes(parseInt(item.val(),10)); break;
|
---|
| 1675 | case 'h':
|
---|
| 1676 | newHour = parseInt(item.val(),10);
|
---|
| 1677 | if ( newHour === 12 ) {
|
---|
| 1678 | if ( ( o.lang[o.useLang].timeFormat === 12 || o.timeFormatOverride === 12 ) && self.pickerMeri.val() === o.meridiemLetters[0] ) { newHour = 0; }
|
---|
| 1679 | }
|
---|
| 1680 | self.theDate.setHours(newHour);
|
---|
| 1681 | break;
|
---|
| 1682 | }
|
---|
| 1683 | self._update();
|
---|
| 1684 | }
|
---|
| 1685 | },
|
---|
| 1686 | _buildInternals: function () {
|
---|
| 1687 | // Build the POSSIBLY VARIABLE controls (these might change)
|
---|
| 1688 | var self = this,
|
---|
| 1689 | o = self.options, x, y, newHour, fld,
|
---|
| 1690 | linkdiv =$("<div><a href='#'></a></div>"),
|
---|
| 1691 | pickerContent = $("<div>", { "class": 'ui-datebox-container ui-overlay-shadow ui-corner-all ui-datebox-hidden pop ui-body-'+o.pickPageTheme} ).css('zIndex', o.zindex),
|
---|
| 1692 | templInput = $("<input type='"+o.internalInputType+"' />").addClass('ui-input-text ui-corner-all ui-shadow-inset ui-datebox-input ui-body-'+o.pickPageInputTheme),
|
---|
| 1693 | templInputT = $("<input type='text' />").addClass('ui-input-text ui-corner-all ui-shadow-inset ui-datebox-input ui-body-'+o.pickPageInputTheme),
|
---|
| 1694 | templControls = $("<div>", { "class":'ui-datebox-controls' }),
|
---|
| 1695 | templFlip = $("<div class='ui-overlay-shadow'><ul></ul></div>"),
|
---|
| 1696 | controlsPlus, controlsInput, controlsMinus, controlsSet, controlsHeader,
|
---|
| 1697 | pickerHour, pickerMins, pickerMeri, pickerMon, pickerDay, pickerYar, pickerSecs;
|
---|
| 1698 |
|
---|
| 1699 | self.calNoNext = false;
|
---|
| 1700 | self.calNoPrev = false;
|
---|
| 1701 | self.setButton = false;
|
---|
| 1702 | self.clearButton = false;
|
---|
| 1703 | self.dateOK = true;
|
---|
| 1704 |
|
---|
| 1705 | if ( o.fieldsOrderOverride === false ) {
|
---|
| 1706 | switch (o.mode) {
|
---|
| 1707 | case 'timebox':
|
---|
| 1708 | case 'timeflipbox':
|
---|
| 1709 | o.fieldsOrder = o.lang[o.useLang].timeFieldOrder;
|
---|
| 1710 | break;
|
---|
| 1711 | case 'slidebox':
|
---|
| 1712 | o.fieldsOrder = o.lang[o.useLang].slideFieldOrder;
|
---|
| 1713 | break;
|
---|
| 1714 | default:
|
---|
| 1715 | o.fieldsOrder = o.lang[o.useLang].dateFieldOrder;
|
---|
| 1716 | }
|
---|
| 1717 | } else {
|
---|
| 1718 | o.fieldsOrder = o.fieldsOrderOverride;
|
---|
| 1719 | }
|
---|
| 1720 |
|
---|
| 1721 | /* Do the Date / Time Format */
|
---|
| 1722 | if ( o.timeOutputOverride !== false ) {
|
---|
| 1723 | o.timeOutput = o.timeOutputOverride;
|
---|
| 1724 | } else if ( o.timeFormatOverride === false ) {
|
---|
| 1725 | o.timeOutput = o.timeFormats[o.lang[o.useLang].timeFormat];
|
---|
| 1726 | } else {
|
---|
| 1727 | o.timeOutput = o.timeFormats[o.timeFormatOverride];
|
---|
| 1728 | }
|
---|
| 1729 |
|
---|
| 1730 | if ( o.dateFormat !== false ) {
|
---|
| 1731 | o.dateOutput = o.dateFormat;
|
---|
| 1732 | } else {
|
---|
| 1733 | if ( typeof o.lang[o.useLang].dateFormat !== 'undefined' ) {
|
---|
| 1734 | o.dateOutput = o.lang[o.useLang].dateFormat;
|
---|
| 1735 | } else {
|
---|
| 1736 | o.dateOutput = o.defaultDateFormat;
|
---|
| 1737 | }
|
---|
| 1738 | }
|
---|
| 1739 |
|
---|
| 1740 | self.pickerContent.empty();
|
---|
| 1741 |
|
---|
| 1742 | /* BEGIN:DATETIME */
|
---|
| 1743 | if ( o.mode === 'datebox' || o.mode === 'timebox' ) {
|
---|
| 1744 | controlsHeader = $("<div class='ui-datebox-header'><h4>Uninitialized</h4></div>").appendTo(self.pickerContent).find("h4");
|
---|
| 1745 | controlsPlus = templControls.clone().appendTo(self.pickerContent);
|
---|
| 1746 | controlsInput = templControls.clone().appendTo(self.pickerContent);
|
---|
| 1747 | controlsMinus = templControls.clone().appendTo(self.pickerContent);
|
---|
| 1748 | controlsSet = templControls.clone().appendTo(self.pickerContent);
|
---|
| 1749 |
|
---|
| 1750 | if ( o.mode === 'timebox' ) { controlsHeader.parent().empty(); } // Time mode has no header
|
---|
| 1751 |
|
---|
| 1752 | pickerMon = self._makeElement(templInput, {'attr': {'field':'m', 'amount':1} });
|
---|
| 1753 | pickerDay = self._makeElement(templInput, {'attr': {'field':'d', 'amount':1} });
|
---|
| 1754 | pickerYar = self._makeElement(templInput, {'attr': {'field':'y', 'amount':1} });
|
---|
| 1755 | pickerHour = self._makeElement(templInput, {'attr': {'field':'h', 'amount':1} });
|
---|
| 1756 | pickerMins = self._makeElement(templInput, {'attr': {'field':'i', 'amount':1} });
|
---|
| 1757 | pickerMeri = self._makeElement(templInputT, {'attr': {'field':'a', 'amount':o.minuteStep} });
|
---|
| 1758 |
|
---|
| 1759 | controlsInput.delegate('input', 'keyup', function() {
|
---|
| 1760 | self._eventEnterValue($(this));
|
---|
| 1761 | });
|
---|
| 1762 |
|
---|
| 1763 | if ( o.wheelExists ) { // Mousewheel operation, if plugin is loaded
|
---|
| 1764 | controlsInput.delegate('input', 'mousewheel', function(e,d) {
|
---|
| 1765 | e.preventDefault();
|
---|
| 1766 | self._offset($(this).jqmData('field'), ((d<0)?-1:1)*$(this).jqmData('amount'));
|
---|
| 1767 | });
|
---|
| 1768 | }
|
---|
| 1769 |
|
---|
| 1770 | for(x=0; x<=o.fieldsOrder.length; x++) { // Use fieldsOrder to decide what goes where
|
---|
| 1771 | if (o.fieldsOrder[x] === 'y') { pickerYar.appendTo(controlsInput); }
|
---|
| 1772 | if (o.fieldsOrder[x] === 'm') { pickerMon.appendTo(controlsInput); }
|
---|
| 1773 | if (o.fieldsOrder[x] === 'd') { pickerDay.appendTo(controlsInput); }
|
---|
| 1774 | if (o.fieldsOrder[x] === 'h') { pickerHour.appendTo(controlsInput); }
|
---|
| 1775 | if (o.fieldsOrder[x] === 'i') { pickerMins.appendTo(controlsInput); }
|
---|
| 1776 | if (o.fieldsOrder[x] === 'a' && ( o.lang[o.useLang].timeFormat === 12 || o.timeFormatOverride === 12 ) ) { pickerMeri.appendTo(controlsInput); }
|
---|
| 1777 | }
|
---|
| 1778 |
|
---|
| 1779 | if ( o.swipeEnabled ) { // Drag and drop support
|
---|
| 1780 | controlsInput.delegate('input', self.START_DRAG, function(e) {
|
---|
| 1781 | if ( !self.dragMove ) {
|
---|
| 1782 | self.dragMove = true;
|
---|
| 1783 | self.dragTarget = $(this).jqmData('field');
|
---|
| 1784 | self.dragPos = 0;
|
---|
| 1785 | self.dragStart = self.touch ? e.originalEvent.changedTouches[0].pageY : e.pageY;
|
---|
| 1786 | self.dragEnd = false;
|
---|
| 1787 | e.stopPropagation();
|
---|
| 1788 | }
|
---|
| 1789 | });
|
---|
| 1790 | }
|
---|
| 1791 |
|
---|
| 1792 | if ( o.noSetButton === false ) { // Set button at bottom
|
---|
| 1793 | self.setButton = $("<a href='#'>PlaceHolder</a>")
|
---|
| 1794 | .appendTo(controlsSet).buttonMarkup({theme: o.pickPageTheme, icon: 'check', iconpos: 'left', corners:true, shadow:true})
|
---|
| 1795 | .bind(o.clickEvent, function(e) {
|
---|
| 1796 | e.preventDefault();
|
---|
| 1797 | if ( self.dateOK === true ) {
|
---|
| 1798 | if ( o.mode === 'timebox' ) { self.input.trigger('datebox', {'method':'set', 'value':self._formatTime(self.theDate), 'date':self.theDate}); }
|
---|
| 1799 | else { self.input.trigger('datebox', {'method':'set', 'value':self._formatDate(self.theDate), 'date':self.theDate}); }
|
---|
| 1800 | self.input.trigger('datebox', {'method':'close'});
|
---|
| 1801 | }
|
---|
| 1802 | });
|
---|
| 1803 | }
|
---|
| 1804 |
|
---|
| 1805 | for( x=0; x<self.options.fieldsOrder.length; x++ ) { // Generate the plus and minus buttons, use fieldsOrder again
|
---|
| 1806 | if ( o.fieldsOrder[x] !== 'a' || o.lang[o.useLang].timeFormat === 12 || o.timeFormatOverride === 12 ) {
|
---|
| 1807 | for ( y=0; y<2; y++ ) {
|
---|
| 1808 | linkdiv.clone()
|
---|
| 1809 | .appendTo(((y===0)?controlsPlus:controlsMinus))
|
---|
| 1810 | .buttonMarkup({theme: o.pickPageButtonTheme, icon: ((y===0)?'plus':'minus'), iconpos: 'bottom', corners:true, shadow:true})
|
---|
| 1811 | .jqmData('field', o.fieldsOrder[x])
|
---|
| 1812 | .jqmData('amount', ((o.fieldsOrder[x]==='i')?o.minuteStep:1));
|
---|
| 1813 | }
|
---|
| 1814 | }
|
---|
| 1815 | }
|
---|
| 1816 |
|
---|
| 1817 | controlsPlus.delegate('div', o.clickEvent, function(e) {
|
---|
| 1818 | e.preventDefault();
|
---|
| 1819 | self._offset($(this).jqmData('field'), $(this).jqmData('amount'));
|
---|
| 1820 | });
|
---|
| 1821 | controlsMinus.delegate('div', o.clickEvent, function(e) {
|
---|
| 1822 | e.preventDefault();
|
---|
| 1823 | self._offset($(this).jqmData('field'), $(this).jqmData('amount')*-1);
|
---|
| 1824 | });
|
---|
| 1825 |
|
---|
| 1826 | $.extend(self, {
|
---|
| 1827 | controlsHeader: controlsHeader,
|
---|
| 1828 | pickerDay: pickerDay,
|
---|
| 1829 | pickerMon: pickerMon,
|
---|
| 1830 | pickerYar: pickerYar,
|
---|
| 1831 | pickerHour: pickerHour,
|
---|
| 1832 | pickerMins: pickerMins,
|
---|
| 1833 | pickerMeri: pickerMeri,
|
---|
| 1834 | controlsInput: controlsInput
|
---|
| 1835 | });
|
---|
| 1836 |
|
---|
| 1837 | self.pickerContent.appendTo(self.thisPage);
|
---|
| 1838 | }
|
---|
| 1839 | /* END:DATETIME */
|
---|
| 1840 |
|
---|
| 1841 | /* BEGIN:DURATIONBOX */
|
---|
| 1842 | if ( o.mode === 'durationbox' ) {
|
---|
| 1843 | controlsPlus = templControls.clone().removeClass('ui-datebox-controls').addClass('ui-datebox-scontrols').appendTo(self.pickerContent);
|
---|
| 1844 | controlsInput = controlsPlus.clone().appendTo(self.pickerContent);
|
---|
| 1845 | controlsMinus = controlsPlus.clone().appendTo(self.pickerContent);
|
---|
| 1846 | controlsSet = templControls.clone().appendTo(self.pickerContent);
|
---|
| 1847 |
|
---|
| 1848 | pickerDay = templInput.removeClass('ui-datebox-input');
|
---|
| 1849 | pickerHour = pickerDay.clone();
|
---|
| 1850 | pickerMins = pickerDay.clone();
|
---|
| 1851 | pickerSecs = pickerDay.clone();
|
---|
| 1852 |
|
---|
| 1853 | controlsInput.delegate('input', 'keyup', function() {
|
---|
| 1854 | if ( $(this).val() !== '' ) { self._updateduration(); }
|
---|
| 1855 | });
|
---|
| 1856 |
|
---|
| 1857 | if ( o.wheelExists ) { // Mousewheel operation, if the plgin is loaded
|
---|
| 1858 | controlsInput.delegate('input', 'mousewheel', function(e,d) {
|
---|
| 1859 | e.preventDefault();
|
---|
| 1860 | self._offset($(this).parent().jqmData('field'), ((d<0)?-1:1));
|
---|
| 1861 | });
|
---|
| 1862 | }
|
---|
| 1863 |
|
---|
| 1864 | for ( x=0; x<o.durationOrder.length; x++ ) { // Use durationOrder to decide what goes where
|
---|
| 1865 | switch ( o.durationOrder[x] ) {
|
---|
| 1866 | case 'd':
|
---|
| 1867 | $('<div>', {'class': 'ui-datebox-sinput'}).jqmData('field', 'd').append(pickerDay).appendTo(controlsInput).prepend('<label>'+o.lang[o.useLang].durationLabel[0]+'</label>');
|
---|
| 1868 | break;
|
---|
| 1869 | case 'h':
|
---|
| 1870 | $('<div>', {'class': 'ui-datebox-sinput'}).jqmData('field', 'h').append(pickerHour).appendTo(controlsInput).prepend('<label>'+o.lang[o.useLang].durationLabel[1]+'</label>');
|
---|
| 1871 | break;
|
---|
| 1872 | case 'i':
|
---|
| 1873 | $('<div>', {'class': 'ui-datebox-sinput'}).jqmData('field', 'i').append(pickerMins).appendTo(controlsInput).prepend('<label>'+o.lang[o.useLang].durationLabel[2]+'</label>');
|
---|
| 1874 | break;
|
---|
| 1875 | case 's':
|
---|
| 1876 | $('<div>', {'class': 'ui-datebox-sinput'}).jqmData('field', 's').append(pickerSecs).appendTo(controlsInput).prepend('<label>'+o.lang[o.useLang].durationLabel[3]+'</label>');
|
---|
| 1877 | break;
|
---|
| 1878 | }
|
---|
| 1879 | }
|
---|
| 1880 |
|
---|
| 1881 | if ( o.swipeEnabled ) { // Drag and drop operation
|
---|
| 1882 | controlsInput.delegate('input', self.START_DRAG, function(e) {
|
---|
| 1883 | if ( !self.dragMove ) {
|
---|
| 1884 | self.dragMove = true;
|
---|
| 1885 | self.dragTarget = $(this).parent().jqmData('field');
|
---|
| 1886 | self.dragPos = 0;
|
---|
| 1887 | self.dragStart = self.touch ? e.originalEvent.changedTouches[0].pageY : e.pageY;
|
---|
| 1888 | self.dragEnd = false;
|
---|
| 1889 | e.stopPropagation();
|
---|
| 1890 | }
|
---|
| 1891 | });
|
---|
| 1892 | }
|
---|
| 1893 |
|
---|
| 1894 | if ( o.noSetButton === false ) { // Bottom set button
|
---|
| 1895 | self.setButton = $("<a href='#'>PlaceHolder</a>")
|
---|
| 1896 | .appendTo(controlsSet).buttonMarkup({theme: o.pickPageTheme, icon: 'check', iconpos: 'left', corners:true, shadow:true})
|
---|
| 1897 | .bind(o.clickEvent, function(e) {
|
---|
| 1898 | e.preventDefault();
|
---|
| 1899 | self.input.trigger('datebox', {'method':'set', 'value':self._formatTime(self.theDate), 'date':self.theDate});
|
---|
| 1900 | self.input.trigger('datebox', {'method':'close'});
|
---|
| 1901 | });
|
---|
| 1902 | }
|
---|
| 1903 |
|
---|
| 1904 | for ( x=0; x<o.durationOrder.length; x++ ) {
|
---|
| 1905 | for ( y=0; y<2; y++ ) {
|
---|
| 1906 | linkdiv.clone()
|
---|
| 1907 | .appendTo(((y===0)?controlsPlus:controlsMinus))
|
---|
| 1908 | .buttonMarkup({theme: o.pickPageButtonTheme, icon: ((y===0)?'plus':'minus'), iconpos: 'bottom', corners:true, shadow:true})
|
---|
| 1909 | .jqmData('field', o.durationOrder[x]);
|
---|
| 1910 | }
|
---|
| 1911 | }
|
---|
| 1912 |
|
---|
| 1913 | controlsPlus.delegate('div', o.clickEvent, function(e) {
|
---|
| 1914 | e.preventDefault();
|
---|
| 1915 | self._offset($(this).jqmData('field'), o.durationSteppers[$(this).jqmData('field')]);
|
---|
| 1916 | });
|
---|
| 1917 | controlsMinus.delegate('div', o.clickEvent, function(e) {
|
---|
| 1918 | e.preventDefault();
|
---|
| 1919 | self._offset($(this).jqmData('field'), o.durationSteppers[$(this).jqmData('field')]*-1);
|
---|
| 1920 | });
|
---|
| 1921 |
|
---|
| 1922 | $.extend(self, {
|
---|
| 1923 | pickerHour: pickerHour,
|
---|
| 1924 | pickerMins: pickerMins,
|
---|
| 1925 | pickerDay: pickerDay,
|
---|
| 1926 | pickerSecs: pickerSecs
|
---|
| 1927 | });
|
---|
| 1928 |
|
---|
| 1929 | self.pickerContent.appendTo(self.thisPage);
|
---|
| 1930 | }
|
---|
| 1931 | /* END:DURATIONBOX */
|
---|
| 1932 |
|
---|
| 1933 | /* BEGIN:SLIDEBOX */
|
---|
| 1934 | if ( o.mode === 'slidebox' ) {
|
---|
| 1935 | controlsHeader = $("<div class='ui-datebox-header'><h4>Uninitialized</h4></div>").appendTo(self.pickerContent).find("h4");
|
---|
| 1936 | controlsInput = $('<div>').addClass('ui-datebox-slide').appendTo(self.pickerContent);
|
---|
| 1937 | controlsSet = $("<div>", { "class":'ui-datebox-controls'}).appendTo(self.pickerContent);
|
---|
| 1938 |
|
---|
| 1939 | if ( o.noSetButton === false ) { // Show set button at bottom
|
---|
| 1940 | self.setButton = $("<a href='#'>PlaceHolder</a>")
|
---|
| 1941 | .appendTo(controlsSet).buttonMarkup({theme: o.pickPageTheme, icon: 'check', iconpos: 'left', corners:true, shadow:true})
|
---|
| 1942 | .bind(o.clickEvent, function(e) {
|
---|
| 1943 | e.preventDefault();
|
---|
| 1944 | if ( self.dateOK === true ) {
|
---|
| 1945 | self.input.trigger('datebox', {'method':'set', 'value':self._formatDate(self.theDate), 'date':self.theDate});
|
---|
| 1946 | self.input.trigger('datebox', {'method':'close'});
|
---|
| 1947 | }
|
---|
| 1948 | });
|
---|
| 1949 | }
|
---|
| 1950 |
|
---|
| 1951 | $.extend(self, {
|
---|
| 1952 | controlsHeader: controlsHeader,
|
---|
| 1953 | controlsInput: controlsInput
|
---|
| 1954 | });
|
---|
| 1955 |
|
---|
| 1956 | self.pickerContent.appendTo(self.thisPage);
|
---|
| 1957 | }
|
---|
| 1958 | /* END:SLIDEBOX */
|
---|
| 1959 |
|
---|
| 1960 | /* BEGIN:FLIPBOX */
|
---|
| 1961 | if ( o.mode === 'flipbox' || o.mode === 'timeflipbox' ) {
|
---|
| 1962 | controlsHeader = $("<div class='ui-datebox-header'><h4>Uninitialized</h4></div>").appendTo(self.pickerContent).find("h4");
|
---|
| 1963 | controlsInput = $("<div>", {"class":'ui-datebox-flipcontent'}).appendTo(self.pickerContent);
|
---|
| 1964 | controlsPlus = $("<div>", {"class":'ui-datebox-flipcenter ui-overlay-shadow'}).css('pointerEvents', 'none').appendTo(self.pickerContent);
|
---|
| 1965 | controlsSet = templControls.clone().appendTo(self.pickerContent);
|
---|
| 1966 |
|
---|
| 1967 | pickerDay = self._makeElement(templFlip, {'attr': {'field':'d','amount':1} });
|
---|
| 1968 | pickerMon = self._makeElement(templFlip, {'attr': {'field':'m','amount':1} });
|
---|
| 1969 | pickerYar = self._makeElement(templFlip, {'attr': {'field':'y','amount':1} });
|
---|
| 1970 | pickerHour = self._makeElement(templFlip, {'attr': {'field':'h','amount':1} });
|
---|
| 1971 | pickerMins = self._makeElement(templFlip, {'attr': {'field':'i','amount':o.minuteStep} });
|
---|
| 1972 | pickerMeri = self._makeElement(templFlip, {'attr': {'field':'a','amount':1} });
|
---|
| 1973 |
|
---|
| 1974 | if ( o.wheelExists ) { // Mousewheel operation, if the plugin is loaded.
|
---|
| 1975 | controlsInput.delegate('div', 'mousewheel', function(e,d) {
|
---|
| 1976 | e.preventDefault();
|
---|
| 1977 | self._offset($(this).jqmData('field'), ((d<0)?-1:1)*$(this).jqmData('amount'));
|
---|
| 1978 | });
|
---|
| 1979 | }
|
---|
| 1980 |
|
---|
| 1981 | for(x=0; x<=o.fieldsOrder.length; x++) { // Use fieldsOrder to decide which to show.
|
---|
| 1982 | if (o.fieldsOrder[x] === 'y') { pickerYar.appendTo(controlsInput); }
|
---|
| 1983 | if (o.fieldsOrder[x] === 'm') { pickerMon.appendTo(controlsInput); }
|
---|
| 1984 | if (o.fieldsOrder[x] === 'd') { pickerDay.appendTo(controlsInput); }
|
---|
| 1985 | if (o.fieldsOrder[x] === 'h') { pickerHour.appendTo(controlsInput); }
|
---|
| 1986 | if (o.fieldsOrder[x] === 'i') { pickerMins.appendTo(controlsInput); }
|
---|
| 1987 | if (o.fieldsOrder[x] === 'a' && ( o.lang[o.useLang].timeFormat === 12 || o.timeFormatOverride === 12 ) ) { pickerMeri.appendTo(controlsInput); }
|
---|
| 1988 | }
|
---|
| 1989 |
|
---|
| 1990 | if ( o.swipeEnabled ) { // Drag and drop support
|
---|
| 1991 | controlsInput.delegate('ul', self.START_DRAG, function(e,f) {
|
---|
| 1992 | if ( !self.dragMove ) {
|
---|
| 1993 | if ( typeof f !== "undefined" ) { e = f; }
|
---|
| 1994 | self.dragMove = true;
|
---|
| 1995 | self.dragTarget = $(this).find('li').first();
|
---|
| 1996 | self.dragPos = parseInt(self.dragTarget.css('marginTop').replace(/px/i, ''),10);
|
---|
| 1997 | self.dragStart = self.touch ? e.originalEvent.changedTouches[0].pageY : e.pageY;
|
---|
| 1998 | self.dragEnd = false;
|
---|
| 1999 | e.stopPropagation();
|
---|
| 2000 | e.preventDefault();
|
---|
| 2001 | }
|
---|
| 2002 | });
|
---|
| 2003 | controlsPlus.bind(self.START_DRAG, function(e) { // ONLY USED ON OLD BROWSERS & IE
|
---|
| 2004 | if ( !self.dragMove ) {
|
---|
| 2005 | self.dragTarget = self.touch ? e.originalEvent.changedTouches[0].pageX - $(e.currentTarget).offset().left : e.pageX - $(e.currentTarget).offset().left;
|
---|
| 2006 | if ( o.fieldsOrder.length === 3 ) {
|
---|
| 2007 | $(self.controlsInput.find('ul').get(parseInt(self.dragTarget / 87, 10))).trigger(self.START_DRAG, e);
|
---|
| 2008 | } else if ( o.fieldsOrder.length === 2 ) {
|
---|
| 2009 | $(self.controlsInput.find('ul').get(parseInt(self.dragTarget / 130, 10))).trigger(self.START_DRAG, e);
|
---|
| 2010 | }
|
---|
| 2011 | }
|
---|
| 2012 | });
|
---|
| 2013 | }
|
---|
| 2014 |
|
---|
| 2015 | if ( o.noSetButton === false ) { // Set button at bottom
|
---|
| 2016 | self.setButton = $("<a href='#'>PlaceHolder</a>")
|
---|
| 2017 | .appendTo(controlsSet).buttonMarkup({theme: o.pickPageTheme, icon: 'check', iconpos: 'left', corners:true, shadow:true})
|
---|
| 2018 | .bind(o.clickEvent, function(e) {
|
---|
| 2019 | e.preventDefault();
|
---|
| 2020 | if ( self.dateOK === true ) {
|
---|
| 2021 | if ( o.mode === 'timeflipbox' ) { self.input.trigger('datebox', {'method':'set', 'value':self._formatTime(self.theDate), 'date':self.theDate}); }
|
---|
| 2022 | else { self.input.trigger('datebox', {'method':'set', 'value':self._formatDate(self.theDate), 'date':self.theDate}); }
|
---|
| 2023 | self.input.trigger('datebox', {'method':'close'});
|
---|
| 2024 | }
|
---|
| 2025 | });
|
---|
| 2026 | }
|
---|
| 2027 |
|
---|
| 2028 | $.extend(self, {
|
---|
| 2029 | controlsHeader: controlsHeader,
|
---|
| 2030 | controlsInput: controlsInput,
|
---|
| 2031 | pickerDay: pickerDay,
|
---|
| 2032 | pickerMon: pickerMon,
|
---|
| 2033 | pickerYar: pickerYar,
|
---|
| 2034 | pickerHour: pickerHour,
|
---|
| 2035 | pickerMins: pickerMins,
|
---|
| 2036 | pickerMeri: pickerMeri
|
---|
| 2037 | });
|
---|
| 2038 |
|
---|
| 2039 | self.pickerContent.appendTo(self.thisPage);
|
---|
| 2040 |
|
---|
| 2041 | }
|
---|
| 2042 | /* END:FLIPBOX */
|
---|
| 2043 |
|
---|
| 2044 | /* BEGIN:CALBOX */
|
---|
| 2045 | if ( o.mode === 'calbox' ) {
|
---|
| 2046 | controlsHeader = $("<div>", {"class": 'ui-datebox-gridheader'}).appendTo(self.pickerContent);
|
---|
| 2047 | controlsPlus = $("<div>", {"class": 'ui-datebox-grid'}).appendTo(self.pickerContent);
|
---|
| 2048 | controlsSet = templControls.clone().appendTo(self.pickerContent);
|
---|
| 2049 | controlsInput = $("<div class='ui-datebox-gridlabel'><h4>Uninitialized</h4></div>").appendTo(controlsHeader).find('h4');
|
---|
| 2050 |
|
---|
| 2051 | if ( o.swipeEnabled ) { // Calendar swipe left and right
|
---|
| 2052 | self.pickerContent
|
---|
| 2053 | .bind('swipeleft', function() { if ( !self.calNoNext ) { self._offset('m', 1); } })
|
---|
| 2054 | .bind('swiperight', function() { if ( !self.calNoPrev ) { self._offset('m', -1); } });
|
---|
| 2055 | }
|
---|
| 2056 |
|
---|
| 2057 | if ( o.wheelExists) { // Mousewheel operations, if plugin is loaded
|
---|
| 2058 | self.pickerContent.bind('mousewheel', function(e,d) {
|
---|
| 2059 | e.preventDefault();
|
---|
| 2060 | if ( d > 0 && !self.calNoNext ) {
|
---|
| 2061 | if ( self.theDate.getDate() > 28 ) { self.theDate.setDate(1); }
|
---|
| 2062 | self._offset('m', 1);
|
---|
| 2063 | }
|
---|
| 2064 | if ( d < 0 && !self.calNoPrev ) {
|
---|
| 2065 | if ( self.theDate.getDate() > 28 ) { self.theDate.setDate(1); }
|
---|
| 2066 | self._offset('m', -1);
|
---|
| 2067 | }
|
---|
| 2068 | });
|
---|
| 2069 | }
|
---|
| 2070 |
|
---|
| 2071 | // Previous and next month buttons, define booleans to decide if they should do anything
|
---|
| 2072 | $("<div class='ui-datebox-gridplus"+((o.lang[o.useLang].isRTL===true)?'-rtl':'')+"'><a href='#'>"+((typeof o.lang[o.useLang].nextMonth !== 'undefined')?o.lang[o.useLang].nextMonth:o.lang.en.nextMonth)+"</a></div>")
|
---|
| 2073 | .prependTo(controlsHeader).buttonMarkup({theme: o.pickPageButtonTheme, icon: 'plus', inline: true, iconpos: 'notext', corners:true, shadow:true})
|
---|
| 2074 | .bind(o.clickEvent, function(e) {
|
---|
| 2075 | e.preventDefault();
|
---|
| 2076 | if ( ! self.calNoNext ) {
|
---|
| 2077 | if ( self.theDate.getDate() > 28 ) { self.theDate.setDate(1); }
|
---|
| 2078 | self._offset('m',1);
|
---|
| 2079 | }
|
---|
| 2080 | });
|
---|
| 2081 | $("<div class='ui-datebox-gridminus"+((o.lang[o.useLang].isRTL===true)?'-rtl':'')+"'><a href='#'>"+((typeof o.lang[o.useLang].prevMonth !== 'undefined')?o.lang[o.useLang].prevMonth:o.lang.en.prevMonth)+"</a></div>")
|
---|
| 2082 | .prependTo(controlsHeader).buttonMarkup({theme: o.pickPageButtonTheme, icon: 'minus', inline: true, iconpos: 'notext', corners:true, shadow:true})
|
---|
| 2083 | .bind(o.clickEvent, function(e) {
|
---|
| 2084 | e.preventDefault();
|
---|
| 2085 | if ( ! self.calNoPrev ) {
|
---|
| 2086 | if ( self.theDate.getDate() > 28 ) { self.theDate.setDate(1); }
|
---|
| 2087 | self._offset('m',-1);
|
---|
| 2088 | }
|
---|
| 2089 | });
|
---|
| 2090 |
|
---|
| 2091 | if ( o.calTodayButton === true ) { // Show today button at bottom
|
---|
| 2092 | self.setButton = $("<a href='#'>PlaceHolder</a>")
|
---|
| 2093 | .appendTo(controlsSet).buttonMarkup({theme: o.pickPageTheme, icon: 'check', iconpos: 'left', corners:true, shadow:true})
|
---|
| 2094 | .bind(o.clickEvent, function(e) {
|
---|
| 2095 | e.preventDefault();
|
---|
| 2096 | self.theDate = new Date();
|
---|
| 2097 | self.theDate = new Date(self.theDate.getFullYear(), self.theDate.getMonth(), self.theDate.getDate(), 0,0,0,0);
|
---|
| 2098 | self.input.trigger('datebox', {'method':'doset'});
|
---|
| 2099 | });
|
---|
| 2100 | }
|
---|
| 2101 |
|
---|
| 2102 | $.extend(self, {
|
---|
| 2103 | controlsInput: controlsInput,
|
---|
| 2104 | controlsPlus: controlsPlus
|
---|
| 2105 | });
|
---|
| 2106 |
|
---|
| 2107 | self.pickerContent.appendTo(self.thisPage);
|
---|
| 2108 | }
|
---|
| 2109 | /* END:CALBOX */
|
---|
| 2110 |
|
---|
| 2111 | if ( o.useClearButton === true ) { // Clear button at very bottom
|
---|
| 2112 | self.clearButton = $("<a href='#'>PlaceHolder</a>")
|
---|
| 2113 | .appendTo(controlsSet).buttonMarkup({theme: o.pickPageTheme, icon: 'delete', iconpos: 'left', corners:true, shadow:true})
|
---|
| 2114 | .bind(o.clickEvent, function(e) {
|
---|
| 2115 | e.preventDefault();
|
---|
| 2116 | self.input.val('');
|
---|
| 2117 | self.input.trigger('datebox', {'method':'clear'});
|
---|
| 2118 | self.input.trigger('datebox', {'method':'close'});
|
---|
| 2119 | });
|
---|
| 2120 | }
|
---|
| 2121 | if ( o.collapseButtons && ( self.clearButton !== false && self.setButton !== false ) ) {
|
---|
| 2122 | controlsSet.addClass('ui-datebox-collapse');
|
---|
| 2123 | }
|
---|
| 2124 |
|
---|
| 2125 | },
|
---|
| 2126 | _buttonsTitle: function () {
|
---|
| 2127 | var self = this,
|
---|
| 2128 | o = this.options;
|
---|
| 2129 |
|
---|
| 2130 | // FIX THE DIALOG TITLE LABEL
|
---|
| 2131 | if ( o.titleDialogLabel === false ) {
|
---|
| 2132 | if ( typeof this.element.attr('title') !== 'undefined' ) {
|
---|
| 2133 | self.pickPageTitle.html(this.element.attr('title'));
|
---|
| 2134 | } else if ( this.focusedEl.parent().find('label').text() !== '' ) {
|
---|
| 2135 | self.pickPageTitle.html(this.focusedEl.parent().find('label').text());
|
---|
| 2136 | } else {
|
---|
| 2137 | switch (o.mode) {
|
---|
| 2138 | case "timebox":
|
---|
| 2139 | case "timeflipbox":
|
---|
| 2140 | self.pickPageTitle.html(o.lang[o.useLang].titleTimeDialogLabel);
|
---|
| 2141 | break;
|
---|
| 2142 | default:
|
---|
| 2143 | self.pickPageTitle.html(o.lang[o.useLang].titleDateDialogLabel);
|
---|
| 2144 | break;
|
---|
| 2145 | }
|
---|
| 2146 | }
|
---|
| 2147 | } else {
|
---|
| 2148 | self.pickPageTitle.html(o.titleDialogLabel);
|
---|
| 2149 | }
|
---|
| 2150 |
|
---|
| 2151 | // FIX THE CLEAR BUTTON
|
---|
| 2152 | if ( self.clearButton !== false ) {
|
---|
| 2153 | self.clearButton.find('.ui-btn-text').html(o.lang[o.useLang].clearButton);
|
---|
| 2154 | }
|
---|
| 2155 |
|
---|
| 2156 | // FIX THE SET BUTTON
|
---|
| 2157 | if ( self.setButton !== false ) {
|
---|
| 2158 | switch (o.mode) {
|
---|
| 2159 | case "timebox":
|
---|
| 2160 | case "timeflipbox":
|
---|
| 2161 | self.setButton.find('.ui-btn-text').html(o.lang[o.useLang].setTimeButtonLabel);
|
---|
| 2162 | break;
|
---|
| 2163 | case "durationbox":
|
---|
| 2164 | self.setButton.find('.ui-btn-text').html(o.lang[o.useLang].setDurationButtonLabel);
|
---|
| 2165 | break;
|
---|
| 2166 | case "calbox":
|
---|
| 2167 | self.setButton.find('.ui-btn-text').html(o.lang[o.useLang].calTodayButtonLabel);
|
---|
| 2168 | break;
|
---|
| 2169 | default:
|
---|
| 2170 | self.setButton.find('.ui-btn-text').html(o.lang[o.useLang].setDateButtonLabel);
|
---|
| 2171 | break;
|
---|
| 2172 | }
|
---|
| 2173 | }
|
---|
| 2174 | },
|
---|
| 2175 | _buildPage: function () {
|
---|
| 2176 | // Build the CONSTANT controls (these never change)
|
---|
| 2177 | var self = this,
|
---|
| 2178 | o = self.options,
|
---|
| 2179 | pickerContent = $("<div>", { "class": 'ui-datebox-container ui-overlay-shadow ui-corner-all ui-datebox-hidden '+o.transition+' ui-body-'+o.pickPageTheme} ).css('zIndex', o.zindex),
|
---|
| 2180 | screen = $("<div>", {'class':'ui-datebox-screen ui-datebox-hidden'+((o.useModal)?' ui-datebox-screen-modal':'')})
|
---|
| 2181 | .css({'z-index': o.zindex-1})
|
---|
| 2182 | .appendTo(self.thisPage)
|
---|
| 2183 | .bind(o.clickEvent, function(event) {
|
---|
| 2184 | event.preventDefault();
|
---|
| 2185 | self.input.trigger('datebox', {'method':'close'});
|
---|
| 2186 | });
|
---|
| 2187 |
|
---|
| 2188 | if ( o.noAnimation ) { pickerContent.removeClass(o.transition); }
|
---|
| 2189 |
|
---|
| 2190 | $.extend(self, {
|
---|
| 2191 | pickerContent: pickerContent,
|
---|
| 2192 | screen: screen
|
---|
| 2193 | });
|
---|
| 2194 |
|
---|
| 2195 | self._buildInternals();
|
---|
| 2196 |
|
---|
| 2197 | // If useInline mode, drop it into the document, and stop a few events from working (or just hide the trigger)
|
---|
| 2198 | if ( o.useInline || o.useInlineBlind ) {
|
---|
| 2199 | self.input.parent().parent().append(self.pickerContent);
|
---|
| 2200 | if ( o.useInlineHideInput ) { self.input.parent().hide(); }
|
---|
| 2201 | self.input.trigger('change');
|
---|
| 2202 | self.pickerContent.removeClass('ui-datebox-hidden');
|
---|
| 2203 | } else if ( o.centerWindow && o.useInlineHideInput ) {
|
---|
| 2204 | self.input.parent().hide();
|
---|
| 2205 | }
|
---|
| 2206 | if ( o.useInline ) {
|
---|
| 2207 | self.pickerContent.addClass('ui-datebox-inline');
|
---|
| 2208 | self.open();
|
---|
| 2209 | }
|
---|
| 2210 | if ( o.useInlineBlind ) {
|
---|
| 2211 | self.pickerContent.addClass('ui-datebox-inlineblind');
|
---|
| 2212 | self.pickerContent.hide();
|
---|
| 2213 | }
|
---|
| 2214 |
|
---|
| 2215 | },
|
---|
| 2216 | hardreset: function() {
|
---|
| 2217 | // Public shortcut to rebuild all internals
|
---|
| 2218 | this._buildInternals();
|
---|
| 2219 | this.refresh();
|
---|
| 2220 | this._buttonsTitle();
|
---|
| 2221 | },
|
---|
| 2222 | refresh: function() {
|
---|
| 2223 | // Pulic shortcut to _update, with an extra hook for inline mode.
|
---|
| 2224 | if ( this.options.useInline === true ) {
|
---|
| 2225 | this.input.trigger('change');
|
---|
| 2226 | }
|
---|
| 2227 | this._update();
|
---|
| 2228 | },
|
---|
| 2229 | open: function() {
|
---|
| 2230 | var self = this,
|
---|
| 2231 | o = this.options,
|
---|
| 2232 | coords = false, // Later, if need be
|
---|
| 2233 | transition = o.noAnimation ? 'none' : o.transition,
|
---|
| 2234 | callback, activePage;
|
---|
| 2235 |
|
---|
| 2236 | // Call the open callback if provided. Additionally, if this
|
---|
| 2237 | // returns falsy then the open of the dialog will be canceled
|
---|
| 2238 | if ( o.openCallback !== false ) {
|
---|
| 2239 | if ( ! $.isFunction(this.options.openCallback) ) {
|
---|
| 2240 | if ( typeof window[o.openCallback] !== 'undefined' ) {
|
---|
| 2241 | o.openCallback = window[o.openCallback];
|
---|
| 2242 | } else {
|
---|
| 2243 | o.openCallback = new Function(o.openCallback);
|
---|
| 2244 | }
|
---|
| 2245 | }
|
---|
| 2246 | callback = o.openCallback.apply(self, $.merge([self.theDate],o.openCallbackArgs));
|
---|
| 2247 | if ( callback == false ) { return false; }
|
---|
| 2248 | }
|
---|
| 2249 |
|
---|
| 2250 |
|
---|
| 2251 | self._buttonsTitle();
|
---|
| 2252 |
|
---|
| 2253 | // Open the controls
|
---|
| 2254 | if ( this.options.useInlineBlind ) { this.pickerContent.slideDown(); return false; } // Just slide if blinds mode
|
---|
| 2255 | if ( this.options.useInline ) { return true; } // Ignore if inline
|
---|
| 2256 | if ( this.pickPage.is(':visible') ) { return false; } // Ignore if already open
|
---|
| 2257 |
|
---|
| 2258 | this.theDate = this._makeDate(this.input.val());
|
---|
| 2259 | this._update();
|
---|
| 2260 | this.input.blur(); // Grab latest value of input, in case it changed
|
---|
| 2261 |
|
---|
| 2262 | // If the window is less than 400px wide, use the jQM dialog method unless otherwise forced
|
---|
| 2263 | if ( ( $(document).width() > 400 && !o.useDialogForceTrue ) || o.useDialogForceFalse || o.fullScreen ) {
|
---|
| 2264 | coords = this._getCoords(this); // Get the coords now, since we need em.
|
---|
| 2265 | o.useDialog = false;
|
---|
| 2266 | if ( o.nestedBox === true && o.fullScreen === false ) {
|
---|
| 2267 | activePage = $('.ui-page-active').first();
|
---|
| 2268 | $(activePage).append(self.pickerContent);
|
---|
| 2269 | $(activePage).append(self.screen);
|
---|
| 2270 | }
|
---|
| 2271 | if ( o.fullScreenAlways === false || coords.width > 399 ) {
|
---|
| 2272 | if ( o.useModal === true ) { // If model, fade the background screen
|
---|
| 2273 | self.screen.fadeIn('slow');
|
---|
| 2274 | } else { // Else just unhide it since it's transparent (with a delay to prevent insta-close)
|
---|
| 2275 | setTimeout(function() {self.screen.removeClass('ui-datebox-hidden');}, 500);
|
---|
| 2276 | }
|
---|
| 2277 | }
|
---|
| 2278 |
|
---|
| 2279 | if ( o.fullScreenAlways === true || ( o.fullScreen === true && coords.width < 400 ) ) {
|
---|
| 2280 | self.pickerContent.addClass('in').css({'position': 'absolute', 'text-align': 'center', 'top': coords.fullTop-5, 'left': coords.fullLeft-5, 'height': coords.high, 'width': coords.width}).removeClass('ui-datebox-hidden');
|
---|
| 2281 | } else {
|
---|
| 2282 | self.pickerContent.addClass('ui-overlay-shadow in').css({'position': 'absolute', 'top': coords.winTop, 'left': coords.winLeft}).removeClass('ui-datebox-hidden');
|
---|
| 2283 | $(document).bind('orientationchange.datebox', {widget:self}, function(e) { self._orientChange(e); });
|
---|
| 2284 | if ( o.resizeListener === true ) {
|
---|
| 2285 | $(window).bind('resize.datebox', {widget:self}, function (e) { self._orientChange(e); });
|
---|
| 2286 | }
|
---|
| 2287 | }
|
---|
| 2288 | } else {
|
---|
| 2289 | // prevent the parent page from being removed from the DOM,
|
---|
| 2290 | self.thisPage.unbind( "pagehide.remove" );
|
---|
| 2291 | o.useDialog = true;
|
---|
| 2292 | self.pickPageContent.append(self.pickerContent);
|
---|
| 2293 | self.pickerContent.css({'top': 'auto', 'left': 'auto', 'marginLeft': 'auto', 'marginRight': 'auto'}).removeClass('ui-overlay-shadow ui-datebox-hidden');
|
---|
| 2294 | $.mobile.changePage(self.pickPage, {'transition': transition});
|
---|
| 2295 | }
|
---|
| 2296 | },
|
---|
| 2297 | close: function(fromCloseButton) {
|
---|
| 2298 | // Close the controls
|
---|
| 2299 | var self = this,
|
---|
| 2300 | o = this.options,
|
---|
| 2301 | callback;
|
---|
| 2302 |
|
---|
| 2303 | if ( o.useInlineBlind ) {
|
---|
| 2304 | self.pickerContent.slideUp();
|
---|
| 2305 | return false; // No More!
|
---|
| 2306 | }
|
---|
| 2307 | if ( o.useInline ) {
|
---|
| 2308 | return true;
|
---|
| 2309 | }
|
---|
| 2310 |
|
---|
| 2311 | // Check options to see if we are closing a dialog, or removing a popup
|
---|
| 2312 | if ( o.useDialog ) {
|
---|
| 2313 | if (!fromCloseButton) {
|
---|
| 2314 | $(self.pickPage).dialog('close');
|
---|
| 2315 | }
|
---|
| 2316 | if( !self.thisPage.jqmData("page").options.domCache ){
|
---|
| 2317 | self.thisPage.bind( "pagehide.remove", function() {
|
---|
| 2318 | $(self).remove();
|
---|
| 2319 | });
|
---|
| 2320 | }
|
---|
| 2321 | self.pickerContent.addClass('ui-datebox-hidden').removeAttr('style').css('zIndex', self.options.zindex);
|
---|
| 2322 | self.thisPage.append(self.pickerContent);
|
---|
| 2323 | } else {
|
---|
| 2324 | if ( o.useModal ) {
|
---|
| 2325 | self.screen.fadeOut('slow');
|
---|
| 2326 | } else {
|
---|
| 2327 | self.screen.addClass('ui-datebox-hidden');
|
---|
| 2328 | }
|
---|
| 2329 | self.pickerContent.addClass('ui-datebox-hidden').removeAttr('style').css('zIndex', self.options.zindex).removeClass('in');
|
---|
| 2330 | }
|
---|
| 2331 | self.focusedEl.removeClass('ui-focus');
|
---|
| 2332 |
|
---|
| 2333 | $(document).unbind('orientationchange.datebox');
|
---|
| 2334 | if ( o.resizeListener === true ) {
|
---|
| 2335 | $(window).unbind('resize.datebox');
|
---|
| 2336 | }
|
---|
| 2337 |
|
---|
| 2338 |
|
---|
| 2339 | if ( o.closeCallback !== false ) {
|
---|
| 2340 | if ( ! $.isFunction(o.closeCallback) ) {
|
---|
| 2341 | if ( typeof window[o.closeCallback] !== 'undefined' ) {
|
---|
| 2342 | o.closeCallback = window[o.closeCallback];
|
---|
| 2343 | } else {
|
---|
| 2344 | o.closeCallback = new Function(o.closeCallback);
|
---|
| 2345 | }
|
---|
| 2346 | }
|
---|
| 2347 | o.closeCallback.apply(self, $.merge([self.theDate], o.closeCallbackArgs));
|
---|
| 2348 |
|
---|
| 2349 | }
|
---|
| 2350 | },
|
---|
| 2351 | disable: function(){
|
---|
| 2352 | // Disable the element
|
---|
| 2353 | this.element.attr("disabled",true);
|
---|
| 2354 | this.element.parent().addClass("ui-disabled");
|
---|
| 2355 | this.options.disabled = true;
|
---|
| 2356 | this.element.blur();
|
---|
| 2357 | this.input.trigger('datebox', {'method':'disable'});
|
---|
| 2358 | },
|
---|
| 2359 | enable: function(){
|
---|
| 2360 | // Enable the element
|
---|
| 2361 | this.element.attr("disabled", false);
|
---|
| 2362 | this.element.parent().removeClass("ui-disabled");
|
---|
| 2363 | this.options.disabled = false;
|
---|
| 2364 | this.input.trigger('datebox', {'method':'enable'});
|
---|
| 2365 | },
|
---|
| 2366 | _setOption: function( key, value ) {
|
---|
| 2367 | var noReset = ['minYear','maxYear','afterToday','beforeToday','maxDays','minDays','highDays','highDates','blackDays','blackDates','enableDates'];
|
---|
| 2368 | $.Widget.prototype._setOption.apply( this, arguments );
|
---|
| 2369 | if ( $.inArray(key, noReset) > -1 ) {
|
---|
| 2370 | this.refresh();
|
---|
| 2371 | } else {
|
---|
| 2372 | this.hardreset();
|
---|
| 2373 | }
|
---|
| 2374 | }
|
---|
| 2375 |
|
---|
| 2376 | });
|
---|
| 2377 |
|
---|
| 2378 | // Degrade date inputs to text inputs, suppress standard UI functions.
|
---|
| 2379 | $( document ).bind( "pagebeforecreate", function( e ) {
|
---|
| 2380 | $( ":jqmData(role='datebox')", e.target ).each(function() {
|
---|
| 2381 | $(this).prop('type', 'text');
|
---|
| 2382 | });
|
---|
| 2383 | });
|
---|
| 2384 | // Automatically bind to data-role='datebox' items.
|
---|
| 2385 | $( document ).bind( "pagecreate create", function( e ){
|
---|
| 2386 | $( document ).trigger( "dateboxbeforecreate" );
|
---|
| 2387 | $( ":jqmData(role='datebox')", e.target ).each(function() {
|
---|
| 2388 | if ( typeof($(this).data('datebox')) === "undefined" ) {
|
---|
| 2389 | $(this).datebox();
|
---|
| 2390 | }
|
---|
| 2391 | });
|
---|
| 2392 | });
|
---|
| 2393 |
|
---|
| 2394 | })( jQuery );
|
---|