Datetimepicker: picker position has been fixed when browser resize event fired
[platform/framework/web/web-ui-fw.git] / src / js / widgets / jquery.mobile.tizen.datetimepicker.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Shows date and time, and make them able to be changed by user
3 //>>label: Datetime picker
4 //>>group: Tizen:Widgets
5
6 define( [ 'jquery.mobile.tizen.widgetex', 'jquery.mobile.tizen.popupwindow', 'jquery.mobile.tizen.popupwindow.ctxpopup' ], function ( ) {
7 //>>excludeEnd("jqmBuildExclude");
8
9 /*global Globalize:false, range:false, regexp:false*/
10 /*
11  * jQuery Mobile Widget @VERSION
12  *
13  * This software is licensed under the MIT licence (as defined by the OSI at
14  * http://www.opensource.org/licenses/mit-license.php)
15  *
16  * ***************************************************************************
17  * Copyright (C) 2011 by Intel Corporation Ltd.
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining a
20  * copy of this software and associated documentation files (the "Software"),
21  * to deal in the Software without restriction, including without limitation
22  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
23  * and/or sell copies of the Software, and to permit persons to whom the
24  * Software is furnished to do so, subject to the following conditions:
25  *
26  * The above copyright notice and this permission notice shall be included in
27  * all copies or substantial portions of the Software.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35  * DEALINGS IN THE SOFTWARE.
36  * ***************************************************************************
37  *
38  * Authors: Salvatore Iovene <salvatore.iovene@intel.com>
39  *                      Daehyon Jung <darrenh.jung@samsung.com>
40  */
41
42 /**
43  * datetimepicker is a widget that lets the user select a date and/or a 
44  * time. If you'd prefer use as auto-initialization of form elements, 
45  * use input elements with type=date/time/datetime within form tag
46  * as same as other form elements.
47  * 
48  * HTML Attributes:
49  * 
50  *      data-role: 'datetimepicker'
51  *      data-format: date format string. e.g) "MMM dd yyyy, HH:mm"
52  *      type: 'date', 'datetime', 'time'
53  *      value: pre-set value. only accepts ISO date string. e.g) "2012-05-04", "2012-05-04T01:02:03+09:00" 
54  *      data-date: any date/time string "new Date()" accepts.
55  *
56  * Options:
57  *      type: 'date', 'datetime', 'time'
58  *      format: see data-format in HTML Attributes.
59  *      value: see value in HTML Attributes.
60  *      date: preset value as JavaScript Date Object representation.
61  *
62  * APIs:
63  *      value( datestring )
64  *              : Set date/time to 'datestring'.
65  *      value()
66  *              : Get current selected date/time as W3C DTF style string.
67  *      getValue() - replaced with 'value()'
68  *              : same as value()
69  *      setValue( datestring ) - replaced with 'value(datestring)'
70  *              : same as value( datestring )
71  *      changeTypeFormat( type, format ) - deprecated
72  *              : Change Type and Format options. use datetimepicker( "option", "format" ) instead
73  *
74  * Events:
75  *      date-changed: Raised when date/time was changed.
76  *
77  * Examples:
78  *      <ul data-role="listview">
79  *              <li class="ui-li-3-2-2">
80  *                      <span class="ui-li-text-main">
81  *                              <input type="datetime" name="demo-date" id="demo-date" 
82  *                                      data-format="MMM dd yyyy hh:mm tt"/>
83  *                      </span>
84  *                      <span class="ui-li-text-sub">
85  *                              Date/Time Picker - <span id="selected-date1"><em>(select a date first)</em></span>
86  *                      </span>
87  *              </li>
88  *              <li class="ui-li-3-2-2">
89  *                      <span class="ui-li-text-main">
90  *                              <input type="date" name="demo-date2" id="demo-date2"/>
91  *                      </span>
92  *                      <span class="ui-li-text-sub">
93  *                              Date Picker  - <span id="selected-date2"><em>(select a date first)</em></span>
94  *                      </span>
95  *              </li>
96  *              <li class="ui-li-3-2-2">
97  *                      <span class="ui-li-text-main">
98  *                              <input type="time" name="demo-date3" id="demo-date3"/>
99  *                      </span>
100  *                      <span class="ui-li-text-sub">
101  *                              Time Picker - <span id="selected-date3"><em>(select a date first)</em></span>
102  *                      </span>
103  *              </li>
104  *      </ul>
105  * How to get a return value:
106  * ==========================
107  * Bind to the 'date-changed' event, e.g.:
108  *    $("#myDatetimepicker").bind("date-changed", function(e, date) {
109  *        alert("New date: " + date.toString());
110  *    });
111  */
112
113 /**
114         @class DateTimePicker
115         The picker widgets show a control that you can use to enter date and time values. <br/> To add a date time picker widget to the application, use the following code:
116
117                         <li class="ui-li-dialogue ui-datetime">
118                                 <div class="ui-datetime-text-main">
119                                         <input type="datetime" data-format="MMM dd yyyy hh:mm:ss" name="demo-date" id="demo-date" />
120                                 </div>
121                                 <div class="ui-li-text-sub">Date/Time Picker
122                                         <span id="selected-date1"><em>(select a date first)</em></span>
123                                 </div>
124                         </li>
125 */
126
127
128 ( function ( $, window, undefined ) {
129         $.widget( "tizen.datetimepicker", $.tizen.widgetex, {
130
131                 options: {
132                         type: null, // date, time, datetime applicable
133                         format: null,
134                         date: null,
135                         initSelector: "input[type='date'], input[type='datetime'], input[type='time'], :jqmData(role='datetimepicker')"
136                 },
137
138                 _calendar: function () {
139                         return window.Globalize.culture().calendars.standard;
140                 },
141
142                 _value: {
143                         attr: "data-" + ( $.mobile.ns || "" ) + "date",
144                         signal: "date-changed"
145                 },
146
147                 _daysInMonth: [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ],
148
149                 _isLeapYear: function ( year ) {
150                         return year % 4 ? 0 : ( year % 100 ? 1 : ( year % 400 ? 0 : 1 ) );
151                 },
152
153                 _makeTwoDigits: function ( val ) {
154                         var ret = val.toString(10);
155                         if ( val < 10 ) {
156                                 ret = "0" + ret;
157                         }
158                         return ret;
159                 },
160
161                 _setType: function ( type ) {
162                         //datetime, date, time
163                         switch (type) {
164                         case 'datetime':
165                         case 'date':
166                         case 'time':
167                                 this.options.type = type;
168                                 break;
169                         default:
170                                 this.options.type = 'datetime';
171                                 break;
172                         }
173
174                         this.element.attr( "data-" + ( $.mobile.ns ? $.mobile.ns + "-" : "" ) + "type", this.options.type );
175                         return this.options.type;
176                 },
177
178                 _setFormat: function ( format ) {
179                         if ( this.options.format != format ) {
180                                 this.options.format = format;
181                         } else {
182                                 return;
183                         }
184
185                         this.ui.children().remove();
186
187                         var token = this._parsePattern( format ),
188                                 div = document.createElement('div'),
189                                 pat,
190                                 tpl,
191                                 period,
192                                 btn,
193                                 obj = this;
194
195                         while ( token.length > 0 ) {
196                                 pat = token.shift();
197                                 tpl = '<span class="ui-datefield-%1" data-pat="' + pat + '">%2</span>';
198                                 switch ( pat ) {
199                                 case 'H': //0 1 2 3 ... 21 22 23
200                                 case 'HH': //00 01 02 ... 21 22 23
201                                 case 'h': //0 1 2 3 ... 11 12
202                                 case 'hh': //00 01 02 ... 11 12
203                                         $(div).append( tpl.replace('%1', 'hour') );
204                                         break;
205                                 case 'mm': //00 01 ... 59
206                                 case 'm': //0 1 2 ... 59
207                                         if ( this.options.type == 'date' ) {
208                                                 $(div).append( tpl.replace('%1', 'month') );
209                                         } else {
210                                                 $(div).append( tpl.replace('%1', 'min') );
211                                         }
212                                         break;
213                                 case 'ss':
214                                 case 's':
215                                         $(div).append( tpl.replace('%1', 'sec') );
216                                         break;
217                                 case 'd': // day of month 5
218                                 case 'dd': // day of month(leading zero) 05
219                                         $(div).append( tpl.replace('%1', 'day') );
220                                         break;
221                                 case 'M': // Month of year 9
222                                 case 'MM': // Month of year(leading zero) 09
223                                 case 'MMM':
224                                 case 'MMMM':
225                                         $(div).append( tpl.replace('%1', 'month') );
226                                         break;
227                                 case 'yy':      // year two digit
228                                 case 'yyyy': // year four digit
229                                         $(div).append( tpl.replace('%1', 'year') );
230                                         break;
231                                 case 't': //AM / PM indicator(first letter) A, P
232                                         // add button
233                                 case 'tt': //AM / PM indicator AM/PM
234                                         // add button
235                                         btn = '<a href="#" class="ui-datefield-period"' +
236                                                 ' data-role="button" data-inline="true">period</a>';
237                                         $(div).append( btn );
238                                         break;
239                                 case 'g':
240                                 case 'gg':
241                                         $(div).append( tpl.replace('%1', 'era').replace('%2', this._calendar().eras.name) );
242                                         break;
243                                 case '\t':
244                                         $(div).append( tpl.replace('%1', 'tab').replace('%2', pat) );
245                                         break;
246                                 default : // string or any non-clickable object
247                                         $(div).append( tpl.replace('%1', 'seperator').replace('%2', pat) );
248                                         break;
249                                 }
250                         }
251
252                         this.ui.append( div );
253                         if ( this.options.date ) {
254                                 this._setDate( this.options.date );
255                         }
256
257                         this.ui.find('.ui-datefield-period').buttonMarkup().bind( 'vclick', function ( e ) {
258                                 obj._switchAmPm( obj );
259                         });
260
261                         this.element.attr( "data-" + ( $.mobile.ns ? $.mobile.ns + "-" : "" ) + "format", this.options.format );
262                         return this.options.format;
263                 },
264
265                 _setDate: function ( newdate ) {
266                         if ( typeof ( newdate ) == "string" ) {
267                                 newdate = new Date( newdate );
268                         }
269
270                         var fields = $('span,a', this.ui),
271                                 type,
272                                 fn,
273                                 $field,
274                                 btn,
275                                 i;
276
277                         function getMonth() {
278                                 return newdate.getMonth() + 1;
279                         }
280
281                         for ( i = 0; i < fields.length; i++ ) {
282                                 $field = $(fields[i]);
283                                 type = $field.attr("class").match(/ui-datefield-([\w]*)/);
284                                 if ( !type ) {
285                                         type = "";
286                                 }
287                                 switch ( type[1] ) {
288                                 case 'hour':
289                                         fn = newdate.getHours;
290                                         break;
291                                 case 'min':
292                                         fn = newdate.getMinutes;
293                                         break;
294                                 case 'sec':
295                                         fn = newdate.getSeconds;
296                                         break;
297                                 case 'year':
298                                         fn = newdate.getFullYear;
299                                         break;
300                                 case 'month':
301                                         fn = getMonth;
302                                         break;
303                                 case 'day':
304                                         fn = newdate.getDate;
305                                         break;
306                                 case 'period':
307                                         fn = newdate.getHours() < 12 ? this._calendar().AM[0] : this._calendar().PM[0];
308                                         btn = $field.find( '.ui-btn-text' );
309                                         if ( btn.length == 0 ) {
310                                                 $field.text(fn);
311                                         } else if ( btn.text() != fn ) {
312                                                 btn.text( fn );
313                                         }
314                                         fn = null;
315                                         break;
316                                 default:
317                                         fn = null;
318                                         break;
319                                 }
320                                 if ( fn ) {
321                                         this._updateField( $field, fn.call( newdate ) );
322                                 }
323                         }
324
325                         this.options.date = newdate;
326
327                         this._setValue( newdate );
328
329                         this.element.attr( "data-" + ( $.mobile.ns ? $.mobile.ns + "-" : "" ) + "date", this.options.date );
330                         return this.options.date;
331                 },
332
333                 destroy: function () {
334                         if ( this.ui ) {
335                                 this.ui.remove();
336                         }
337
338                         if ( this.element ) {
339                                 this.element.show();
340                         }
341                 },
342
343                 value: function ( val ) {
344                         function timeStr( t, obj ) {
345                                 return obj._makeTwoDigits( t.getHours() ) + ':' +
346                                         obj._makeTwoDigits( t.getMinutes() ) + ':' +
347                                         obj._makeTwoDigits( t.getSeconds() );
348                         }
349
350                         function dateStr( d, obj ) {
351                                 return ( ( d.getFullYear() % 10000 ) + 10000 ).toString().substr(1) + '-' +
352                                         obj._makeTwoDigits( d.getMonth() + 1 ) + '-' +
353                                         obj._makeTwoDigits( d.getDate() );
354                         }
355
356                         var rvalue = null;
357                         if ( val ) {
358                                 rvalue = this._setDate( val );
359                         } else {
360                                 switch ( this.options.type ) {
361                                 case 'time':
362                                         rvalue = timeStr( this.options.date, this );
363                                         break;
364                                 case 'date':
365                                         rvalue = dateStr( this.options.date, this );
366                                         break;
367                                 default:
368                                         rvalue = dateStr( this.options.date, this ) + 'T' + timeStr( this.options.date, this );
369                                         break;
370                                 }
371                         }
372                         return rvalue;
373                 },
374
375                 setValue: function ( newdate ) {
376                         console.warn( "setValue was deprecated. use datetimepicker('option', 'date', value) instead." );
377                         return this.value( newdate );
378                 },
379
380                 /**
381                  * return W3C DTF string
382                  */
383                 getValue: function () {
384                         console.warn("getValue() was deprecated. use datetimepicker('value') instead.");
385                         return this.value();
386                 },
387
388                 _updateField: function ( target, value ) {
389                         if ( !target || target.length == 0 ) {
390                                 return;
391                         }
392
393                         if ( value == 0 ) {
394                                 value = "0";
395                         }
396
397                         var pat = target.jqmData( 'pat' ),
398                                 hour,
399                                 text,
400                                 self = this;
401
402                         switch ( pat ) {
403                         case 'H':
404                         case 'HH':
405                         case 'h':
406                         case 'hh':
407                                 hour = value;
408                                 if ( pat.charAt(0) == 'h' ) {
409                                         if ( hour > 12 ) {
410                                                 hour -= 12;
411                                         } else if ( hour == 0 ) {
412                                                 hour = 12;
413                                         }
414                                 }
415                                 hour = this._makeTwoDigits( hour );
416                                 text = hour;
417                                 break;
418                         case 'm':
419                         case 'M':
420                         case 'd':
421                         case 's':
422                                 text = value;
423                                 break;
424                         case 'mm':
425                         case 'dd':
426                         case 'MM':
427                         case 'ss':
428                                 text = this._makeTwoDigits( value );
429                                 break;
430                         case 'MMM':
431                                 text = this._calendar().months.namesAbbr[ value - 1];
432                                 break;
433                         case 'MMMM':
434                                 text = this._calendar().months.names[ value - 1 ];
435                                 break;
436                         case 'yy':
437                                 text = this._makeTwoDigits( value % 100 );
438                                 break;
439                         case 'yyyy':
440                                 if ( value < 10 ) {
441                                         value = '000' + value;
442                                 } else if ( value < 100 ) {
443                                         value = '00' + value;
444                                 } else if ( value < 1000 ) {
445                                         value = '0' + value;
446                                 }
447                                 text = value;
448                                 break;
449                         }
450
451                         // to avoid reflow where its value isn't out-dated
452                         if ( target.text() != text ) {
453                                 if ( target.hasClass("ui-datefield-selected") ) {
454                                         target.addClass("out");
455                                         this._new_value = text;
456
457                                         target.animationComplete( function () {
458                                                 target.text( self._new_value);
459                                                 target.addClass("in")
460                                                         .removeClass("out");
461
462                                                 target.animationComplete( function () {
463                                                         target.removeClass("in").
464                                                                 removeClass("ui-datefield-selected");
465                                                 });
466                                         });
467                                 } else {
468                                         target.text( text );
469                                 }
470                         }
471                 },
472
473                 _switchAmPm: function ( obj ) {
474                         if ( this._calendar().AM != null ) {
475                                 var date = new Date( this.options.date ),
476                                         text,
477                                         change = 1000 * 60 * 60 * 12;
478                                 if ( date.getHours() > 11 ) {
479                                         change = -change;
480                                 }
481                                 date.setTime( date.getTime() + change );
482                                 this._setDate( date );
483                         }
484                 },
485
486                 _parsePattern: function ( pattern ) {
487                         var regex = /\/|\s|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|f|gg|g|\'[\w\W]*\'$|[\w\W]/g,
488                                 matches,
489                                 i;
490
491                         matches = pattern.match( regex );
492
493                         for ( i = 0; i < matches.length; i++ ) {
494                                 if ( matches[i].charAt(0) == "'" ) {
495                                         matches[i] = matches[i].substr( 1, matches[i].length - 2 );
496                                 }
497                         }
498
499                         return matches;
500                 },
501
502                 changeTypeFormat: function ( type, format ) {
503                         console.warn('changeTypeFormat() was deprecated. use datetimepicker("option", "type"|"format", value) instead');
504                         if ( type ) {
505                                 this._setType( type );
506                         }
507
508                         if ( format ) {
509                                 this._setFormat( format );
510                         }
511                 },
512
513                 _create: function () {
514                         var obj = this;
515
516                         if ( this.element.is( "input" ) ) {
517                                 ( function ( obj ) {
518                                         var type, value, format;
519
520                                         type = obj.element.get(0).getAttribute( "type" );
521                                         obj.options.type = type;
522
523                                         value = obj.element.get(0).getAttribute( "value" );
524                                         if ( value ) {
525                                                 obj.options.date = new Date( value );
526                                         }
527                                 }( this ) );
528                         }
529
530                         if ( !this.options.format ) {
531                                 switch ( this.options.type ) {
532                                 case 'datetime':
533                                         this.options.format = this._calendar().patterns.d + "\t" + this._calendar().patterns.t;
534                                         break;
535                                 case 'date':
536                                         this.options.format = this._calendar().patterns.d;
537                                         break;
538                                 case 'time':
539                                         this.options.format = this._calendar().patterns.t;
540                                         break;
541                                 }
542                         }
543
544                         if ( !this.options.date ) {
545                                 this.options.date = new Date();
546                         }
547
548                         this.element.hide();
549                         this.ui = $('<div class="ui-datefield"></div>');
550                         $(this.element).after( this.ui );
551
552                         this._popup_open = false;
553                         this.ui.bind('vclick', function ( e ) {
554                                 obj._showDataSelector( obj, this, e.target );
555                         });
556                 },
557
558                 _populateDataSelector: function ( field, pat ) {
559                         var values,
560                                 numItems,
561                                 current,
562                                 data,
563                                 range = window.range,
564                                 local,
565                                 yearlb,
566                                 yearhb,
567                                 day;
568
569                         switch ( field ) {
570                         case 'hour':
571                                 if ( pat == 'H' || pat == 'HH' ) {
572                                         // twentyfour
573                                         values = range( 0, 23 );
574                                         data = range( 0, 23 );
575                                         current = this.options.date.getHours();
576                                 } else {
577                                         values = range( 1, 12 );
578                                         current = this.options.date.getHours() - 1;//11
579                                         if ( current >= 11 ) {
580                                                 current = current - 12;
581                                                 data = range( 13, 23 );
582                                                 data.push( 12 ); // consider 12:00 am as 00:00
583                                         } else {
584                                                 data = range( 1, 11 );
585                                                 data.push( 0 );
586                                         }
587                                         if ( current < 0 ) {
588                                                 current = 11; // 12:00 or 00:00
589                                         }
590                                 }
591                                 if ( pat.length == 2 ) {
592                                         // two digit
593                                         values = values.map( this._makeTwoDigits );
594                                 }
595                                 numItems = values.length;
596                                 break;
597                         case 'min':
598                         case 'sec':
599                                 values = range( 0, 59 );
600                                 if ( pat.length == 2 ) {
601                                         values = values.map( this._makeTwoDigits );
602                                 }
603                                 data = range( 0, 59 );
604                                 current = ( field == 'min' ? this.options.date.getMinutes() : this.options.date.getSeconds() );
605                                 numItems = values.length;
606                                 break;
607                         case 'year':
608                                 yearlb = 1900;
609                                 yearhb = 2100;
610                                 data = range( yearlb, yearhb );
611                                 current = this.options.date.getFullYear() - yearlb;
612                                 values = range( yearlb, yearhb );
613                                 numItems = values.length;
614                                 break;
615                         case 'month':
616                                 switch ( pat.length ) {
617                                 case 1:
618                                         values = range( 1, 12 );
619                                         break;
620                                 case 2:
621                                         values = range( 1, 12 ).map( this._makeTwoDigits );
622                                         break;
623                                 case 3:
624                                         values = this._calendar().months.namesAbbr.slice();
625                                         break;
626                                 case 4:
627                                         values = this._calendar().months.names.slice();
628                                         break;
629                                 }
630                                 if ( values.length == 13 ) { // @TODO Lunar calendar support
631                                         if ( values[12] == "" ) { // to remove lunar calendar reserved space
632                                                 values.pop();
633                                         }
634                                 }
635                                 data = range( 1, values.length );
636                                 current = this.options.date.getMonth();
637                                 numItems = values.length;
638                                 break;
639                         case 'day':
640                                 day = this._daysInMonth[ this.options.date.getMonth() ];
641                                 if ( day == 28 ) {
642                                         day += this._isLeapYear( this.options.date.getFullYear() );
643                                 }
644                                 values = range( 1, day );
645                                 if ( pat.length == 2 ) {
646                                         values = values.map( this._makeTwoDigits );
647                                 }
648                                 data = range( 1, day );
649                                 current = this.options.date.getDate() - 1;
650                                 numItems = day;
651                                 break;
652                         }
653
654                         return {
655                                 values: values,
656                                 data: data,
657                                 numItems: numItems,
658                                 current: current
659                         };
660
661                 },
662
663                 _showDataSelector: function ( obj, ui, target ) {
664                         target = $(target);
665
666                         var attr = target.attr("class"),
667                                 field = attr ? attr.match(/ui-datefield-([\w]*)/) : undefined,
668                                 pat,
669                                 data,
670                                 values,
671                                 numItems,
672                                 current,
673                                 valuesData,
674                                 html,
675                                 datans,
676                                 $ul,
677                                 $div,
678                                 $ctx,
679                                 $li,
680                                 i,
681                                 newLeft = 10,
682                                 self = this;
683
684                         if ( !attr ) {
685                                 return;
686                         }
687                         if ( !field ) {
688                                 return;
689                         }
690                         if ( this._popup_open ) {
691                                 return;
692                         }
693
694                         target.not('.ui-datefield-seperator').addClass('ui-datefield-selected');
695
696                         pat = target.jqmData('pat');
697                         data = obj._populateDataSelector.call( obj, field[1], pat );
698
699                         values = data.values;
700                         numItems = data.numItems;
701                         current = data.current;
702                         valuesData = data.data;
703
704                         if ( values ) {
705                                 datans = "data-" + ($.mobile.ns ? ($.mobile.ns + '-') : "") + 'val="';
706                                 for ( i = 0; i < values.length; i++ ) {
707                                         html += '<li><a class="ui-link" ' + datans + valuesData[i] + '">' + values[i] + '</a></li>';
708                                 }
709
710                                 $ul = $("<ul></ul>");
711                                 $div = $('<div class="ui-datetimepicker-selector" data-transition="fade" data-fade="false"></div>');
712                                 $div.append( $ul ).appendTo( ui );
713                                 $ctx = $div.ctxpopup();
714                                 $ctx.parents('.ui-popupwindow').addClass('ui-datetimepicker');
715                                 $li = $(html);
716                                 $( $li[current] ).addClass("current");
717                                 $div.jqmData( "list", $li );
718                                 $div.circularview();
719                                 if( !obj._reflow ) {
720                                         obj._reflow = function() {
721                                                 $div.circularview( "reflow" );
722                                                 $div.circularview( 'centerTo', '.current', 0 );
723                                         }
724                                         $(window).bind( "resize" , obj._reflow );
725                                 }
726                                 // cause ctxpopup forced to subtract 10
727                                 if ( $( window ).width() / 2 < target.offset().left ) {
728                                         newLeft = -10;
729                                 }
730                                 $ctx.popupwindow( 'open',
731                                                 target.offset().left + ( target.width() / 2 ) + newLeft - window.pageXOffset ,
732                                                 target.offset().top + target.height() - window.pageYOffset );
733
734                                 this._popup_open = true;
735
736                                 $div.bind('popupafterclose', function ( e ) {
737                                         if ( obj._reflow ) {
738                                                 $(window).unbind("resize", obj._reflow);
739                                                 obj._reflow = null;
740                                         }
741
742                                         if ( !( target.hasClass("in") || target.hasClass("out") ) ) {
743                                                 target.removeClass("ui-datefield-selected");
744                                         }
745
746                                         $div.unbind( 'popupafterclose' );
747                                         $ul.unbind( 'vclick' );
748                                         $(obj).unbind( 'update' );
749                                         $ctx.popupwindow( 'destroy' );
750                                         $div.remove();
751
752                                         self._popup_open = false;
753                                 });
754
755                                 $(obj).bind( 'update', function ( e, val ) {
756                                         var date = new Date( this.options.date ),
757                                                 month,
758                                                 date_calibration = function () {
759                                                         date.setDate( 1 );
760                                                         date.setDate( date.getDate() - 1 );
761                                                 };
762
763                                         switch ( field[1] ) {
764                                         case 'min':
765                                                 date.setMinutes( val );
766                                                 break;
767                                         case 'hour':
768                                                 date.setHours( val );
769                                                 break;
770                                         case 'sec':
771                                                 date.setSeconds( val );
772                                                 break;
773                                         case 'year':
774                                                 month = date.getMonth();
775                                                 date.setFullYear( val );
776
777                                                 if ( date.getMonth() != month ) {
778                                                         date_calibration();
779                                                 }
780                                                 break;
781                                         case 'month':
782                                                 date.setMonth( val - 1 );
783
784                                                 if ( date.getMonth() == val ) {
785                                                         date_calibration();
786                                                 }
787                                                 break;
788                                         case 'day':
789                                                 date.setDate( val );
790                                                 break;
791                                         }
792
793                                         obj._setDate( date );
794
795                                         $ctx.popupwindow( 'close' );
796                                 });
797
798                                 $ul.bind( 'click', function ( e ) {
799                                         if ( $(e.target).is('a') ) {
800                                                 $ul.find(".current").removeClass("current");
801                                                 $(e.target).parent().addClass('current');
802                                                 var val = $(e.target).jqmData("val");
803                                                 $(obj).trigger( 'update', val ); // close popup, unselect field
804                                         }
805                                 });
806
807                                 $div.circularview( 'centerTo', '.current', 500 );
808                                 $div.bind( 'scrollend' , function ( e ) {
809                                         if ( !obj._reflow ) {
810                                                 obj._reflow = function () {
811                                                         $div.circularview("reflow");
812                                                 };
813                                                 $(window).bind("resize", obj._reflow);
814                                         }
815                                 });
816                         }
817                         return ui;
818                 }
819
820         });
821
822         $(document).bind("pagecreate create", function ( e ) {
823                 $($.tizen.datetimepicker.prototype.options.initSelector, e.target)
824                         .not(":jqmData(role='none'), :jqmData(role='nojs')")
825                         .datetimepicker();
826         });
827
828 } ( jQuery, this ) );
829
830 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
831 } );
832 //>>excludeEnd("jqmBuildExclude");