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