xdan-datetimepicker-rails 2.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aaf6cad5e688683672d3abca3e58770c388a50d6
4
+ data.tar.gz: ae36d36f213ce8c0dae5c622fbf4284d1bd236f3
5
+ SHA512:
6
+ metadata.gz: d70510b01d80ce8f3990c4bfaad7231285b6fe72686efa0b6436cbdf7be736911731343d0f63b8088bad31d81dccb005da3721a22c404c96b11b8eb2fb37414c
7
+ data.tar.gz: f6972b1944a27a35b4f01b31d812fcd6a0b7d6f65e096eedff88044ac5c6bc1cb30ead49311723c8a3523d63c9e3af43dedca77e60b48d893bd4e1a59be65139
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joshua Kovach
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Xdan Datetimepicker Rails
2
+
3
+ This gem adds @xdan's [datetimepicker] to the Rails asset pipeline.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'xdan-datetimepicker-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install xdan-datetimepicker-rails
18
+
19
+ ## Usage
20
+
21
+ Require the jquery file into your `application.js.coffee` file:
22
+
23
+ ```coffee
24
+ #= require jquery.xdan.datetimepicker
25
+ ```
26
+
27
+ Import the stylesheet in your `application.css.scss` file:
28
+
29
+ ```sass
30
+ @import "jquery.xdan.datetimepicker";
31
+ ```
32
+
33
+ Start using it!
34
+
35
+ ```coffee
36
+ $ ->
37
+ $(".datetimepicker").datetimepicker()
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( http://github.com/<my-github-username>/xdan-datetimepicker-rails/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'net/http'
4
+ require 'open-uri'
5
+
6
+ namespace :source do
7
+ desc "update the source file"
8
+ task :update do
9
+ puts "Downloading jquery.datetimepicker.js..."
10
+ download "https://raw.github.com/xdan/datetimepicker/master/jquery.datetimepicker.js", "app/assets/javascripts/jquery.xdan.datetimepicker.js"
11
+
12
+ puts "Downloading jquery.datetimepicker.css..."
13
+ download "https://raw.github.com/xdan/datetimepicker/master/jquery.datetimepicker.css", "app/assets/stylesheets/jquery.xdan.datetimepicker.css"
14
+ end
15
+ end
16
+
17
+
18
+ def download remote_path, local_path
19
+ `wget -O #{local_path} #{remote_path}`
20
+ # File.open(local_path, "wb") do |saved_file|
21
+ # # the following "open" is provided by open-uri
22
+ # open(remote_path, "rb") do |read_file|
23
+ # saved_file.write(read_file.read)
24
+ # end
25
+ # end
26
+ end
@@ -0,0 +1,1126 @@
1
+ /**
2
+ * @preserve jQuery DateTimePicker plugin v2.1.9
3
+ * @homepage http://xdsoft.net/jqplugins/datetimepicker/
4
+ * (c) 2014, Chupurnov Valeriy.
5
+ */
6
+ (function( $ ) {
7
+ 'use strict'
8
+ var default_options = {
9
+ i18n:{
10
+ ru:{ // Russian
11
+ months:[
12
+ 'Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'
13
+ ],
14
+ dayOfWeek:[
15
+ "Вск", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
16
+ ]
17
+ },
18
+ en:{ // English
19
+ months: [
20
+ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
21
+ ],
22
+ dayOfWeek: [
23
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
24
+ ]
25
+ },
26
+ de:{ // German
27
+ months:[
28
+ 'Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'
29
+ ],
30
+ dayOfWeek:[
31
+ "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"
32
+ ]
33
+ },
34
+ nl:{ // Dutch
35
+ months:[
36
+ "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"
37
+ ],
38
+ dayOfWeek:[
39
+ "zo", "ma", "di", "wo", "do", "vr", "za"
40
+ ]
41
+ },
42
+ tr:{ // Turkish
43
+ months:[
44
+ "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"
45
+ ],
46
+ dayOfWeek:[
47
+ "Paz", "Pts", "Sal", "Çar", "Per", "Cum", "Cts"
48
+ ]
49
+ },
50
+ fr:{ //French
51
+ months:[
52
+ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
53
+ ],
54
+ dayOfWeek:[
55
+ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"
56
+ ]
57
+ },
58
+ es:{ // Spanish
59
+ months: [
60
+ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
61
+ ],
62
+ dayOfWeek: [
63
+ "Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"
64
+ ]
65
+ },
66
+ th:{ // Thai
67
+ months:[
68
+ 'มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'
69
+ ],
70
+ dayOfWeek:[
71
+ 'อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'
72
+ ]
73
+ },
74
+ pl:{ // Polish
75
+ months: [
76
+ "styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień"
77
+ ],
78
+ dayOfWeek: [
79
+ "nd", "pn", "wt", "śr", "cz", "pt", "sb"
80
+ ]
81
+ },
82
+ pt:{ // Portuguese
83
+ months: [
84
+ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"
85
+ ],
86
+ dayOfWeek: [
87
+ "Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"
88
+ ]
89
+ },
90
+ ch:{ // Simplified Chinese
91
+ months: [
92
+ "一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"
93
+ ],
94
+ dayOfWeek: [
95
+ "日", "一","二","三","四","五","六"
96
+ ]
97
+ },
98
+ se:{ // Swedish
99
+ months: [
100
+ "Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September","Oktober", "November", "December"
101
+ ],
102
+ dayOfWeek: [
103
+ "Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"
104
+ ]
105
+ }
106
+ },
107
+ value:'',
108
+ lang:'en',
109
+ format:'Y/m/d H:i',
110
+ formatTime:'H:i',
111
+ formatDate:'Y/m/d',
112
+ step:60,
113
+ closeOnDateSelect:0,
114
+ closeOnWithoutClick:true,
115
+ timepicker:true,
116
+ datepicker:true,
117
+ minDate:false,
118
+ maxDate:false,
119
+ minTime:false,
120
+ maxTime:false,
121
+ allowTimes:[],
122
+ opened:false,
123
+ inline:false,
124
+ onSelectDate:function() {},
125
+ onSelectTime:function() {},
126
+ onChangeMonth:function() {},
127
+ onChangeDateTime:function() {},
128
+ onShow:function() {},
129
+ onClose:function() {},
130
+ onGenerate:function() {},
131
+ withoutCopyright:true,
132
+ inverseButton:false,
133
+ hours12:false,
134
+ next: 'xdsoft_next',
135
+ prev : 'xdsoft_prev',
136
+ dayOfWeekStart:0,
137
+ timeHeightInTimePicker:25,
138
+ timepickerScrollbar:true,
139
+ todayButton:true, // 2.1.0
140
+ defaultSelect:true, // 2.1.0
141
+ scrollMonth:true,
142
+ scrollTime:true,
143
+ scrollInput:true,
144
+ mask:false,
145
+ validateOnBlur:true,
146
+ allowBlank:false,
147
+ yearStart:1950,
148
+ yearEnd:2050,
149
+ style:'',
150
+ id:'',
151
+ roundTime:'round', // ceil, floor
152
+ className:'',
153
+ weekends : [],
154
+ yearOffset:0
155
+ };
156
+ // fix for ie8
157
+ if ( !Array.prototype.indexOf ) {
158
+ Array.prototype.indexOf = function(obj, start) {
159
+ for (var i = (start || 0), j = this.length; i < j; i++) {
160
+ if (this[i] === obj) { return i; }
161
+ }
162
+ return -1;
163
+ }
164
+ };
165
+ $.fn.xdsoftScroller = function( _percent ) {
166
+ return this.each(function() {
167
+ var timeboxparent = $(this);
168
+ if( !$(this).hasClass('xdsoft_scroller_box') ) {
169
+ var pointerEventToXY = function( e ) {
170
+ var out = {x:0, y:0};
171
+ if( e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel' ) {
172
+ var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
173
+ out.x = touch.pageX;
174
+ out.y = touch.pageY;
175
+ }else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
176
+ out.x = e.pageX;
177
+ out.y = e.pageY;
178
+ }
179
+ return out;
180
+ },
181
+ move = 0,
182
+ timebox = timeboxparent.children().eq(0),
183
+ parentHeight = timeboxparent[0].clientHeight,
184
+ height = timebox[0].offsetHeight,
185
+ scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
186
+ scroller = $('<div class="xdsoft_scroller"></div>'),
187
+ maximumOffset = 100,
188
+ start = false;
189
+
190
+ scrollbar.append(scroller);
191
+
192
+ timeboxparent.addClass('xdsoft_scroller_box').append(scrollbar);
193
+ scroller.on('mousedown.xdsoft_scroller',function ( event ) {
194
+ if( !parentHeight )
195
+ timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
196
+ var pageY = event.pageY,
197
+ top = parseInt(scroller.css('margin-top')),
198
+ h1 = scrollbar[0].offsetHeight;
199
+ $(document.body).addClass('xdsoft_noselect');
200
+ $([document.body,window]).on('mouseup.xdsoft_scroller',function arguments_callee() {
201
+ $([document.body,window]).off('mouseup.xdsoft_scroller',arguments_callee)
202
+ .off('mousemove.xdsoft_scroller',move)
203
+ .removeClass('xdsoft_noselect');
204
+ });
205
+ $(document.body).on('mousemove.xdsoft_scroller',move = function(event) {
206
+ var offset = event.pageY-pageY+top;
207
+ if( offset<0 )
208
+ offset = 0;
209
+ if( offset+scroller[0].offsetHeight>h1 )
210
+ offset = h1-scroller[0].offsetHeight;
211
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[maximumOffset?offset/maximumOffset:0]);
212
+ });
213
+ });
214
+
215
+ timeboxparent
216
+ .on('scroll_element.xdsoft_scroller',function( event,percent ) {
217
+ if( !parentHeight )
218
+ timeboxparent.trigger('resize_scroll.xdsoft_scroller',[percent,true]);
219
+ percent = percent>1?1:(percent<0||isNaN(percent))?0:percent;
220
+ scroller.css('margin-top',maximumOffset*percent);
221
+ timebox.css('marginTop',-parseInt((height-parentHeight)*percent))
222
+ })
223
+ .on('resize_scroll.xdsoft_scroller',function( event,_percent,noTriggerScroll ) {
224
+ parentHeight = timeboxparent[0].clientHeight;
225
+ height = timebox[0].offsetHeight;
226
+ var percent = parentHeight/height,
227
+ sh = percent*scrollbar[0].offsetHeight;
228
+ if( percent>1 )
229
+ scroller.hide();
230
+ else{
231
+ scroller.show();
232
+ scroller.css('height',parseInt(sh>10?sh:10));
233
+ maximumOffset = scrollbar[0].offsetHeight-scroller[0].offsetHeight;
234
+ if( noTriggerScroll!==true )
235
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[_percent?_percent:Math.abs(parseInt(timebox.css('marginTop')))/(height-parentHeight)]);
236
+ }
237
+ });
238
+ timeboxparent.mousewheel&&timeboxparent.mousewheel(function(event, delta, deltaX, deltaY) {
239
+ var top = Math.abs(parseInt(timebox.css('marginTop')));
240
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-delta*20)/(height-parentHeight)]);
241
+ event.stopPropagation();
242
+ return false;
243
+ });
244
+ timeboxparent.on('touchstart',function( event ) {
245
+ start = pointerEventToXY(event);
246
+ });
247
+ timeboxparent.on('touchmove',function( event ) {
248
+ if( start ) {
249
+ var coord = pointerEventToXY(event), top = Math.abs(parseInt(timebox.css('marginTop')));
250
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-(coord.y-start.y))/(height-parentHeight)]);
251
+ event.stopPropagation();
252
+ event.preventDefault();
253
+ };
254
+ });
255
+ timeboxparent.on('touchend touchcancel',function( event ) {
256
+ start = false;
257
+ });
258
+ }
259
+ timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
260
+ });
261
+ };
262
+ $.fn.datetimepicker = function( opt ) {
263
+ var KEY0 = 48,
264
+ KEY9 = 57,
265
+ _KEY0 = 96,
266
+ _KEY9 = 105,
267
+ CTRLKEY = 17,
268
+ DEL = 46,
269
+ ENTER = 13,
270
+ ESC = 27,
271
+ BACKSPACE = 8,
272
+ ARROWLEFT = 37,
273
+ ARROWUP = 38,
274
+ ARROWRIGHT = 39,
275
+ ARROWDOWN = 40,
276
+ TAB = 9,
277
+ F5 = 116,
278
+ AKEY = 65,
279
+ CKEY = 67,
280
+ VKEY = 86,
281
+ ZKEY = 90,
282
+ YKEY = 89,
283
+ ctrlDown = false,
284
+ options = ($.isPlainObject(opt)||!opt)?$.extend(true,{},default_options,opt):$.extend({},default_options),
285
+ createDateTimePicker = function( input ) {
286
+ var datetimepicker = $('<div '+(options.id?'id="'+options.id+'"':'')+' '+(options.style?'style="'+options.style+'"':'')+' class="xdsoft_datetimepicker xdsoft_noselect '+options.className+'"></div>'),
287
+ xdsoft_copyright = $('<div class="xdsoft_copyright"><a target="_blank" href="http://xdsoft.net/jqplugins/datetimepicker/">xdsoft.net</a></div>'),
288
+ datepicker = $('<div class="xdsoft_datepicker active"></div>'),
289
+ mounth_picker = $('<div class="xdsoft_mounthpicker"><button type="button" class="xdsoft_prev"></button><button type="button" class="xdsoft_today_button"></button><div class="xdsoft_label xdsoft_month"><span></span></div><div class="xdsoft_label xdsoft_year"><span></span></div><button type="button" class="xdsoft_next"></button></div>'),
290
+ calendar = $('<div class="xdsoft_calendar"></div>'),
291
+ timepicker = $('<div class="xdsoft_timepicker active"><button type="button" class="xdsoft_prev"></button><div class="xdsoft_time_box"></div><button type="button" class="xdsoft_next"></button></div>'),
292
+ timeboxparent = timepicker.find('.xdsoft_time_box').eq(0),
293
+ timebox = $('<div class="xdsoft_time_variant"></div>'),
294
+ scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
295
+ scroller = $('<div class="xdsoft_scroller"></div>'),
296
+ monthselect =$('<div class="xdsoft_select xdsoft_monthselect"><div></div></div>'),
297
+ yearselect =$('<div class="xdsoft_select xdsoft_yearselect"><div></div></div>');
298
+
299
+ //constructor lego
300
+ mounth_picker
301
+ .find('.xdsoft_month span')
302
+ .after(monthselect);
303
+ mounth_picker
304
+ .find('.xdsoft_year span')
305
+ .after(yearselect);
306
+
307
+ mounth_picker
308
+ .find('.xdsoft_month,.xdsoft_year')
309
+ .on('mousedown.xdsoft',function(event) {
310
+ mounth_picker
311
+ .find('.xdsoft_select')
312
+ .hide();
313
+ var select = $(this).find('.xdsoft_select').eq(0),
314
+ val = 0,
315
+ top = 0;
316
+
317
+ if( _xdsoft_datetime.currentTime )
318
+ val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month')?'getMonth':'getFullYear']();
319
+
320
+ select.show();
321
+ for(var items = select.find('div.xdsoft_option'),i = 0;i<items.length;i++) {
322
+ if( items.eq(i).data('value')==val ) {
323
+ break;
324
+ }else top+=items[0].offsetHeight;
325
+ }
326
+
327
+ select.xdsoftScroller(top/(select.children()[0].offsetHeight-(select[0].clientHeight)));
328
+ event.stopPropagation();
329
+ return false;
330
+ });
331
+
332
+ mounth_picker
333
+ .find('.xdsoft_select')
334
+ .xdsoftScroller()
335
+ .on('mousedown.xdsoft',function( event ) {
336
+ event.stopPropagation();
337
+ event.preventDefault();
338
+ })
339
+ .on('mousedown.xdsoft','.xdsoft_option',function( event ) {
340
+ if( _xdsoft_datetime&&_xdsoft_datetime.currentTime )
341
+ _xdsoft_datetime.currentTime[$(this).parent().parent().hasClass('xdsoft_monthselect')?'setMonth':'setFullYear']($(this).data('value'));
342
+ $(this).parent().parent().hide();
343
+ datetimepicker.trigger('xchange.xdsoft');
344
+ options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
345
+ });
346
+
347
+
348
+ // set options
349
+ datetimepicker.setOptions = function( _options ) {
350
+ options = $.extend(true,{},options,_options);
351
+ if( (options.open||options.opened)&&(!options.inline) ) {
352
+ input.trigger('open.xdsoft');
353
+ }
354
+
355
+ if( options.inline ) {
356
+ datetimepicker.addClass('xdsoft_inline');
357
+ input.after(datetimepicker).hide();
358
+ datetimepicker.trigger('afterOpen.xdsoft');
359
+ }
360
+
361
+ if( options.inverseButton ) {
362
+ options.next = 'xdsoft_prev';
363
+ options.prev = 'xdsoft_next';
364
+ }
365
+
366
+ if( !options.datepicker && options.timepicker )
367
+ datepicker.removeClass('active');
368
+
369
+ if( options.datepicker && !options.timepicker )
370
+ timepicker.removeClass('active');
371
+
372
+ if( options.value ){
373
+ input&&input.val&&input.val(options.value);
374
+ _xdsoft_datetime.setCurrentTime(options.value);
375
+ }
376
+
377
+ if( isNaN(options.dayOfWeekStart)||parseInt(options.dayOfWeekStart)<0||parseInt(options.dayOfWeekStart)>6 )
378
+ options.dayOfWeekStart = 0;
379
+ else
380
+ options.dayOfWeekStart = parseInt(options.dayOfWeekStart);
381
+
382
+ if( !options.timepickerScrollbar )
383
+ scrollbar.hide();
384
+
385
+ var tmpDate = [],timeOffset;
386
+ if( options.minDate && ( tmpDate = /^-(.*)$/.exec(options.minDate) ) && (tmpDate=Date.parseDate(tmpDate[1], options.formatDate)) ) {
387
+ timeOffset = tmpDate.getTime()+-1*(tmpDate.getTimezoneOffset())*60000;
388
+ options.minDate = new Date((_xdsoft_datetime.now()).getTime()-timeOffset).dateFormat( options.formatDate );
389
+ }
390
+ if( options.maxDate && ( tmpDate = /^\+(.*)$/.exec(options.maxDate) ) && (tmpDate=Date.parseDate(tmpDate[1], options.formatDate)) ) {
391
+ timeOffset = tmpDate.getTime()+-1*(tmpDate.getTimezoneOffset())*60000;
392
+ options.maxDate = new Date((_xdsoft_datetime.now()).getTime()+timeOffset).dateFormat( options.formatDate );
393
+ }
394
+
395
+ mounth_picker
396
+ .find('.xdsoft_today_button')
397
+ .css('visibility',!options.todayButton?'hidden':'visible');
398
+
399
+ if( options.mask ) {
400
+ var e,
401
+ getCaretPos = function ( input ) {
402
+ try{
403
+ if ( document.selection && document.selection.createRange ) {
404
+ var range = document.selection.createRange();
405
+ return range.getBookmark().charCodeAt(2) - 2;
406
+ }else
407
+ if ( input.setSelectionRange )
408
+ return input.selectionStart;
409
+ }catch(e) {
410
+ return 0;
411
+ }
412
+ },
413
+ setCaretPos = function ( node,pos ) {
414
+ var node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node;
415
+ if(!node) {
416
+ return false;
417
+ }else if(node.createTextRange) {
418
+ var textRange = node.createTextRange();
419
+ textRange.collapse(true);
420
+ textRange.moveEnd(pos);
421
+ textRange.moveStart(pos);
422
+ textRange.select();
423
+ return true;
424
+ }else if(node.setSelectionRange) {
425
+ node.setSelectionRange(pos,pos);
426
+ return true;
427
+ }
428
+ return false;
429
+ },
430
+ isValidValue = function ( mask,value ) {
431
+ var reg = mask
432
+ .replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g,'\\$1')
433
+ .replace(/_/g,'{digit+}')
434
+ .replace(/([0-9]{1})/g,'{digit$1}')
435
+ .replace(/\{digit([0-9]{1})\}/g,'[0-$1_]{1}')
436
+ .replace(/\{digit[\+]\}/g,'[0-9_]{1}');
437
+ return RegExp(reg).test(value);
438
+ };
439
+ input.off('keydown.xdsoft');
440
+ switch(true) {
441
+ case ( options.mask===true ):
442
+ //options.mask = (new Date()).dateFormat( options.format );
443
+ //options.mask = options.mask.replace(/[0-9]/g,'_');
444
+ options.mask = options.format
445
+ .replace(/Y/g,'9999')
446
+ .replace(/F/g,'9999')
447
+ .replace(/m/g,'19')
448
+ .replace(/d/g,'39')
449
+ .replace(/H/g,'29')
450
+ .replace(/i/g,'59')
451
+ .replace(/s/g,'59');
452
+ case ( $.type(options.mask) == 'string' ):
453
+ if( !isValidValue( options.mask,input.val() ) )
454
+ input.val(options.mask.replace(/[0-9]/g,'_'));
455
+
456
+ input.on('keydown.xdsoft',function( event ) {
457
+ var val = this.value,
458
+ key = event.which;
459
+ switch(true) {
460
+ case (( key>=KEY0&&key<=KEY9 )||( key>=_KEY0&&key<=_KEY9 ))||(key==BACKSPACE||key==DEL):
461
+ var pos = getCaretPos(this),
462
+ digit = ( key!=BACKSPACE&&key!=DEL )?String.fromCharCode((_KEY0 <= key && key <= _KEY9)? key-KEY0 : key):'_';
463
+ if( (key==BACKSPACE||key==DEL)&&pos ) {
464
+ pos--;
465
+ digit='_';
466
+ }
467
+ while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
468
+ pos+=( key==BACKSPACE||key==DEL )?-1:1;
469
+
470
+ val = val.substr(0,pos)+digit+val.substr(pos+1);
471
+ if( $.trim(val)=='' )
472
+ val = options.mask.replace(/[0-9]/g,'_');
473
+ else
474
+ if( pos==options.mask.length )
475
+ break;
476
+
477
+ pos+=(key==BACKSPACE||key==DEL)?0:1;
478
+ while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
479
+ pos+=(key==BACKSPACE||key==DEL)?-1:1;
480
+ if( isValidValue( options.mask,val ) ) {
481
+ this.value = val;
482
+ setCaretPos(this,pos);
483
+ }else if( $.trim(val)=='' )
484
+ this.value = options.mask.replace(/[0-9]/g,'_');
485
+ else{
486
+ input.trigger('error_input.xdsoft');
487
+ }
488
+ break;
489
+ case ( !!~([AKEY,CKEY,VKEY,ZKEY,YKEY].indexOf(key))&&ctrlDown ):
490
+ case !!~([ESC,ARROWUP,ARROWDOWN,ARROWLEFT,ARROWRIGHT,F5,CTRLKEY,TAB,ENTER].indexOf(key)):
491
+ return true;
492
+ }
493
+ event.preventDefault();
494
+ return false;
495
+ });
496
+ break;
497
+ }
498
+ }
499
+ if( options.validateOnBlur ) {
500
+ input
501
+ .off('blur.xdsoft')
502
+ .on('blur.xdsoft', function() {
503
+ if( options.allowBlank && !$.trim($(this).val()).length ) {
504
+ $(this).val(null);
505
+ datetimepicker.data('xdsoft_datetime').empty();
506
+ }else if( !Date.parseDate( $(this).val(), options.format ) ) {
507
+ $(this).val((_xdsoft_datetime.now()).dateFormat( options.format ));
508
+ datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
509
+ }
510
+ else{
511
+ datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
512
+ }
513
+ datetimepicker.trigger('changedatetime.xdsoft');
514
+ });
515
+ }
516
+ options.dayOfWeekStartPrev = (options.dayOfWeekStart==0)?6:options.dayOfWeekStart-1;
517
+ datetimepicker
518
+ .trigger('xchange.xdsoft');
519
+ };
520
+
521
+ datetimepicker
522
+ .data('options',options)
523
+ .on('mousedown.xdsoft',function( event ) {
524
+ event.stopPropagation();
525
+ event.preventDefault();
526
+ yearselect.hide();
527
+ monthselect.hide();
528
+ return false;
529
+ });
530
+
531
+ var scroll_element = timepicker.find('.xdsoft_time_box');
532
+ scroll_element.append(timebox);
533
+ scroll_element.xdsoftScroller();
534
+ datetimepicker.on('afterOpen.xdsoft',function() {
535
+ scroll_element.xdsoftScroller();
536
+ });
537
+
538
+ datetimepicker
539
+ .append(datepicker)
540
+ .append(timepicker);
541
+
542
+ if( options.withoutCopyright!==true )
543
+ datetimepicker
544
+ .append(xdsoft_copyright);
545
+
546
+ datepicker
547
+ .append(mounth_picker)
548
+ .append(calendar);
549
+
550
+ $('body').append(datetimepicker);
551
+
552
+ var _xdsoft_datetime = new function() {
553
+ var _this = this;
554
+ _this.now = function() {
555
+ var d = new Date();
556
+ if( options.yearOffset )
557
+ d.setFullYear(d.getFullYear()+options.yearOffset);
558
+ return d;
559
+ };
560
+
561
+ _this.currentTime = this.now();
562
+ _this.isValidDate = function (d) {
563
+ if ( Object.prototype.toString.call(d) !== "[object Date]" )
564
+ return false;
565
+ return !isNaN(d.getTime());
566
+ };
567
+
568
+ _this.setCurrentTime = function( dTime) {
569
+ _this.currentTime = (typeof dTime == 'string')? _this.strtodatetime(dTime) : _this.isValidDate(dTime) ? dTime: _this.now();
570
+ datetimepicker.trigger('xchange.xdsoft');
571
+ };
572
+
573
+ _this.empty = function() {
574
+ _this.currentTime = null;
575
+ };
576
+
577
+ _this.getCurrentTime = function( dTime) {
578
+ return _this.currentTime;
579
+ };
580
+
581
+ _this.nextMonth = function() {
582
+ var month = _this.currentTime.getMonth()+1;
583
+ if( month==12 ) {
584
+ _this.currentTime.setFullYear(_this.currentTime.getFullYear()+1);
585
+ month = 0;
586
+ }
587
+ _this.currentTime.setDate(
588
+ Math.min(
589
+ Date.daysInMonth[month],
590
+ _this.currentTime.getDate()
591
+ )
592
+ )
593
+ _this.currentTime.setMonth(month);
594
+ options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
595
+ datetimepicker.trigger('xchange.xdsoft');
596
+ return month;
597
+ };
598
+
599
+ _this.prevMonth = function() {
600
+ var month = _this.currentTime.getMonth()-1;
601
+ if( month==-1 ) {
602
+ _this.currentTime.setFullYear(_this.currentTime.getFullYear()-1);
603
+ month = 11;
604
+ }
605
+ _this.currentTime.setDate(
606
+ Math.min(
607
+ Date.daysInMonth[month],
608
+ _this.currentTime.getDate()
609
+ )
610
+ )
611
+ _this.currentTime.setMonth(month);
612
+ options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
613
+ datetimepicker.trigger('xchange.xdsoft');
614
+ return month;
615
+ };
616
+
617
+ _this.strtodatetime = function( sDateTime ) {
618
+ var currentTime = sDateTime?Date.parseDate(sDateTime, options.format):_this.now();
619
+ if( !_this.isValidDate(currentTime) )
620
+ currentTime = _this.now();
621
+ return currentTime;
622
+ };
623
+
624
+ _this.strtodate = function( sDate ) {
625
+ var currentTime = sDate?Date.parseDate(sDate, options.formatDate):_this.now();
626
+ if( !_this.isValidDate(currentTime) )
627
+ currentTime = _this.now();
628
+ return currentTime;
629
+ };
630
+
631
+ _this.strtotime = function( sTime ) {
632
+ var currentTime = sTime?Date.parseDate(sTime, options.formatTime):_this.now();
633
+ if( !_this.isValidDate(currentTime) )
634
+ currentTime = _this.now();
635
+ return currentTime;
636
+ };
637
+
638
+ _this.str = function() {
639
+ return _this.currentTime.dateFormat(options.format);
640
+ };
641
+ };
642
+ mounth_picker
643
+ .find('.xdsoft_today_button')
644
+ .on('mousedown.xdsoft',function() {
645
+ datetimepicker.data('changed',true);
646
+ _xdsoft_datetime.setCurrentTime(0);
647
+ datetimepicker.trigger('afterOpen.xdsoft');
648
+ }).on('dblclick.xdsoft',function(){
649
+ input.val( _xdsoft_datetime.str() );
650
+ datetimepicker.trigger('close.xdsoft');
651
+ });
652
+ mounth_picker
653
+ .find('.xdsoft_prev,.xdsoft_next')
654
+ .on('mousedown.xdsoft',function() {
655
+ var $this = $(this),
656
+ timer = 0,
657
+ stop = false;
658
+
659
+ (function arguments_callee1(v) {
660
+ var month = _xdsoft_datetime.currentTime.getMonth();
661
+ if( $this.hasClass( options.next ) ) {
662
+ _xdsoft_datetime.nextMonth();
663
+ }else if( $this.hasClass( options.prev ) ) {
664
+ _xdsoft_datetime.prevMonth();
665
+ }
666
+ !stop&&(timer = setTimeout(arguments_callee1,v?v:100));
667
+ })(500);
668
+
669
+ $([document.body,window]).on('mouseup.xdsoft',function arguments_callee2() {
670
+ clearTimeout(timer);
671
+ stop = true;
672
+ $([document.body,window]).off('mouseup.xdsoft',arguments_callee2);
673
+ });
674
+ });
675
+
676
+ timepicker
677
+ .find('.xdsoft_prev,.xdsoft_next')
678
+ .on('mousedown.xdsoft',function() {
679
+ var $this = $(this),
680
+ timer = 0,
681
+ stop = false,
682
+ period = 110;
683
+ (function arguments_callee4(v) {
684
+ var pheight = timeboxparent[0].clientHeight,
685
+ height = timebox[0].offsetHeight,
686
+ top = Math.abs(parseInt(timebox.css('marginTop')));
687
+ if( $this.hasClass(options.next) && (height-pheight)- options.timeHeightInTimePicker>=top ) {
688
+ timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px')
689
+ }else if( $this.hasClass(options.prev) && top-options.timeHeightInTimePicker>=0 ) {
690
+ timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px')
691
+ }
692
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
693
+ period= ( period>10 )?10:period-10;
694
+ !stop&&(timer = setTimeout(arguments_callee4,v?v:period));
695
+ })(500);
696
+ $([document.body,window]).on('mouseup.xdsoft',function arguments_callee5() {
697
+ clearTimeout(timer);
698
+ stop = true;
699
+ $([document.body,window])
700
+ .off('mouseup.xdsoft',arguments_callee5);
701
+ });
702
+ });
703
+
704
+ // base handler - generating a calendar and timepicker
705
+ datetimepicker
706
+ .on('xchange.xdsoft',function( event ) {
707
+ var table = '',
708
+ start = new Date(_xdsoft_datetime.currentTime.getFullYear(),_xdsoft_datetime.currentTime.getMonth(),1),
709
+ i = 0,
710
+ today = _xdsoft_datetime.now();
711
+ while( start.getDay()!=options.dayOfWeekStart )
712
+ start.setDate(start.getDate()-1);
713
+
714
+ //generate calendar
715
+ table+='<table><thead><tr>';
716
+
717
+ // days
718
+ for(var j = 0; j<7; j++) {
719
+ table+='<th>'+options.i18n[options.lang].dayOfWeek[(j+options.dayOfWeekStart)>6?0:j+options.dayOfWeekStart]+'</th>';
720
+ }
721
+
722
+ table+='</tr></thead>';
723
+ table+='<tbody><tr>';
724
+ var maxDate = false, minDate = false;
725
+ if( options.maxDate!==false ) {
726
+ maxDate = _xdsoft_datetime.strtodate(options.maxDate);
727
+ maxDate = new Date(maxDate.getFullYear(),maxDate.getMonth(),maxDate.getDate(),23,59,59,999);
728
+ }
729
+ if( options.minDate!==false ) {
730
+ minDate = _xdsoft_datetime.strtodate(options.minDate);
731
+ minDate = new Date(minDate.getFullYear(),minDate.getMonth(),minDate.getDate());
732
+ }
733
+ var d,y,m,classes = [];
734
+ while( i<_xdsoft_datetime.currentTime.getDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ) {
735
+ classes = [];
736
+ i++;
737
+
738
+ d = start.getDate(); y = start.getFullYear(); m = start.getMonth();
739
+
740
+ classes.push('xdsoft_date');
741
+
742
+ if( ( maxDate!==false && start > maxDate )||( minDate!==false && start < minDate ) ){
743
+ classes.push('xdsoft_disabled');
744
+ }
745
+
746
+ if( _xdsoft_datetime.currentTime.getMonth()!=m ) classes.push('xdsoft_other_month');
747
+
748
+ if( (options.defaultSelect||datetimepicker.data('changed')) && _xdsoft_datetime.currentTime.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
749
+ classes.push('xdsoft_current');
750
+ }
751
+
752
+ if( today.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
753
+ classes.push('xdsoft_today');
754
+ }
755
+
756
+ if( start.getDay()==0||start.getDay()==6||~options.weekends.indexOf(start.dateFormat('d.m.Y')) ) {
757
+ classes.push('xdsoft_weekend');
758
+ }
759
+
760
+ table+='<td data-date="'+d+'" data-month="'+m+'" data-year="'+y+'"'+' class="xdsoft_date xdsoft_day_of_week'+start.getDay()+' '+ classes.join(' ')+'">'+
761
+ '<div>'+d+'</div>'+
762
+ '</td>';
763
+
764
+ if( start.getDay()==options.dayOfWeekStartPrev ) {
765
+ table+='</tr>';
766
+ }
767
+
768
+ start.setDate(d+1);
769
+ }
770
+ table+='</tbody></table>';
771
+
772
+ calendar.html(table);
773
+
774
+ mounth_picker.find('.xdsoft_label span').eq(0).text(options.i18n[options.lang].months[_xdsoft_datetime.currentTime.getMonth()]);
775
+ mounth_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear());
776
+
777
+ // generate timebox
778
+ var time = '',
779
+ h = '',
780
+ m ='',
781
+ line_time = function line_time( h,m ) {
782
+ var now = _xdsoft_datetime.now();
783
+ now.setHours(h);
784
+ h = parseInt(now.getHours());
785
+ now.setMinutes(m);
786
+ m = parseInt(now.getMinutes());
787
+
788
+ classes = [];
789
+ if( (options.maxTime!==false&&_xdsoft_datetime.strtotime(options.maxTime).getTime()<now.getTime())||(options.minTime!==false&&_xdsoft_datetime.strtotime(options.minTime).getTime()>now.getTime()))
790
+ classes.push('xdsoft_disabled');
791
+ if( (options.defaultSelect||datetimepicker.data('changed')) && parseInt(_xdsoft_datetime.currentTime.getHours())==parseInt(h)&&(options.step>59||Math[options.roundTime](_xdsoft_datetime.currentTime.getMinutes()/options.step)*options.step==parseInt(m)))
792
+ classes.push('xdsoft_current');
793
+ if( parseInt(today.getHours())==parseInt(h)&&parseInt(today.getMinutes())==parseInt(m))
794
+ classes.push('xdsoft_today');
795
+ time+= '<div class="xdsoft_time '+classes.join(' ')+'" data-hour="'+h+'" data-minute="'+m+'">'+now.dateFormat(options.formatTime)+'</div>';
796
+ };
797
+
798
+ if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ) {
799
+ for( var i=0,j=0;i<(options.hours12?12:24);i++ ) {
800
+ for( j=0;j<60;j+=options.step ) {
801
+ h = (i<10?'0':'')+i;
802
+ m = (j<10?'0':'')+j;
803
+ line_time( h,m );
804
+ }
805
+ }
806
+ }else{
807
+ for( var i=0;i<options.allowTimes.length;i++ ) {
808
+ h = _xdsoft_datetime.strtotime(options.allowTimes[i]).getHours();
809
+ m = _xdsoft_datetime.strtotime(options.allowTimes[i]).getMinutes();
810
+ line_time( h,m );
811
+ }
812
+ }
813
+
814
+ timebox.html(time);
815
+
816
+ var opt = '',
817
+ i = 0;
818
+
819
+ for( i = parseInt(options.yearStart,10)+options.yearOffset;i<= parseInt(options.yearEnd,10)+options.yearOffset;i++ ) {
820
+ opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getFullYear()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+i+'</div>';
821
+ }
822
+ yearselect.children().eq(0)
823
+ .html(opt);
824
+
825
+ for( i = 0,opt = '';i<= 11;i++ ) {
826
+ opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getMonth()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+options.i18n[options.lang].months[i]+'</div>';
827
+ }
828
+ monthselect.children().eq(0).html(opt);
829
+ $(this).trigger('generate.xdsoft');
830
+ event.stopPropagation();
831
+ })
832
+ .on('afterOpen.xdsoft',function() {
833
+ if( options.timepicker && timebox.find('.xdsoft_current').length ) {
834
+ var pheight = timeboxparent[0].clientHeight,
835
+ height = timebox[0].offsetHeight,
836
+ top = timebox.find('.xdsoft_current').index()*options.timeHeightInTimePicker+1;
837
+ if( (height-pheight)<top )
838
+ top = height-pheight;
839
+ timebox.css('marginTop','-'+parseInt(top)+'px');
840
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[parseInt(top)/(height-pheight)]);
841
+ }
842
+ });
843
+ var timerclick = 0;
844
+ calendar
845
+ .on('click.xdsoft','td',function() {
846
+ timerclick++;
847
+ var $this = $(this),
848
+ currentTime = _xdsoft_datetime.currentTime;
849
+ if( $this.hasClass('xdsoft_disabled') )
850
+ return false;
851
+
852
+ currentTime.setFullYear( $this.data('year') );
853
+ currentTime.setDate( $this.data('date') );
854
+ currentTime.setMonth( $this.data('month') );
855
+ datetimepicker.trigger('select.xdsoft',[currentTime]);
856
+
857
+ input.val( _xdsoft_datetime.str() );
858
+ if( (timerclick>1||(options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker )))&&!options.inline ) {
859
+ datetimepicker.trigger('close.xdsoft');
860
+ }
861
+
862
+ if( options.onSelectDate && options.onSelectDate.call ) {
863
+ options.onSelectDate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
864
+ }
865
+
866
+ datetimepicker.data('changed',true);
867
+ datetimepicker.trigger('xchange.xdsoft');
868
+ datetimepicker.trigger('changedatetime.xdsoft');
869
+ setTimeout(function(){
870
+ timerclick = 0;
871
+ },200);
872
+ });
873
+
874
+ timebox
875
+ .on('click.xdsoft','div',function() {
876
+ var $this = $(this),
877
+ currentTime = _xdsoft_datetime.currentTime;
878
+ if( $this.hasClass('xdsoft_disabled') )
879
+ return false;
880
+ currentTime.setHours($this.data('hour'));
881
+ currentTime.setMinutes($this.data('minute'));
882
+ datetimepicker.trigger('select.xdsoft',[currentTime]);
883
+
884
+ datetimepicker.data('input').val( _xdsoft_datetime.str() );
885
+
886
+ !options.inline&&datetimepicker.trigger('close.xdsoft');
887
+
888
+ if( options.onSelectTime&&options.onSelectTime.call ) {
889
+ options.onSelectTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
890
+ }
891
+ datetimepicker.data('changed',true);
892
+ datetimepicker.trigger('xchange.xdsoft');
893
+ datetimepicker.trigger('changedatetime.xdsoft');
894
+ });
895
+
896
+ datetimepicker.mousewheel&&datepicker.mousewheel(function(event, delta, deltaX, deltaY) {
897
+ if( !options.scrollMonth )
898
+ return true;
899
+ if( delta<0 )
900
+ _xdsoft_datetime.nextMonth();
901
+ else
902
+ _xdsoft_datetime.prevMonth();
903
+ return false;
904
+ });
905
+
906
+ datetimepicker.mousewheel&&timeboxparent.unmousewheel().mousewheel(function(event, delta, deltaX, deltaY) {
907
+ if( !options.scrollTime )
908
+ return true;
909
+ var pheight = timeboxparent[0].clientHeight,
910
+ height = timebox[0].offsetHeight,
911
+ top = Math.abs(parseInt(timebox.css('marginTop'))),
912
+ fl = true;
913
+ if( delta<0 && (height-pheight)-options.timeHeightInTimePicker>=top ) {
914
+ timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px');
915
+ fl = false;
916
+ }else if( delta>0&&top-options.timeHeightInTimePicker>=0 ) {
917
+ timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px');
918
+ fl = false;
919
+ }
920
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
921
+ event.stopPropagation();
922
+ return fl;
923
+ });
924
+
925
+ datetimepicker
926
+ .on('changedatetime.xdsoft',function() {
927
+ if( options.onChangeDateTime&&options.onChangeDateTime.call )
928
+ options.onChangeDateTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
929
+ })
930
+ .on('generate.xdsoft',function() {
931
+ if( options.onGenerate&&options.onGenerate.call )
932
+ options.onGenerate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
933
+ });
934
+
935
+ var current_time_index = 0;
936
+ input.mousewheel&&input.mousewheel(function( event, delta, deltaX, deltaY ) {
937
+ if( !options.scrollInput )
938
+ return true;
939
+ if( !options.datepicker && options.timepicker ) {
940
+ current_time_index = timebox.find('.xdsoft_current').length?timebox.find('.xdsoft_current').eq(0).index():0;
941
+ if( current_time_index+delta>=0&&current_time_index+delta<timebox.children().length )
942
+ current_time_index+=delta;
943
+ timebox.children().eq(current_time_index).length&&timebox.children().eq(current_time_index).trigger('mousedown');
944
+ return false;
945
+ }else if( options.datepicker && !options.timepicker ) {
946
+ datepicker.trigger( event, [delta, deltaX, deltaY]);
947
+ input.val&&input.val( _xdsoft_datetime.str() );
948
+ datetimepicker.trigger('changedatetime.xdsoft');
949
+ return false;
950
+ }
951
+ });
952
+ var setPos = function() {
953
+ var offset = datetimepicker.data('input').offset(), top = offset.top+datetimepicker.data('input')[0].offsetHeight-1, left = offset.left;
954
+ if( top+datetimepicker[0].offsetHeight>$(window).height()+$(window).scrollTop() )
955
+ top = offset.top-datetimepicker[0].offsetHeight+1;
956
+ if( left+datetimepicker[0].offsetWidth>$(window).width() )
957
+ left = offset.left-datetimepicker[0].offsetWidth+datetimepicker.data('input')[0].offsetWidth;
958
+ datetimepicker.css({
959
+ left:left,
960
+ top:top
961
+ });
962
+ };
963
+ datetimepicker
964
+ .on('open.xdsoft', function() {
965
+ var onShow = true;
966
+ if( options.onShow&&options.onShow.call) {
967
+ onShow = options.onShow.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
968
+ }
969
+ if( onShow!==false ) {
970
+ datetimepicker.show();
971
+ datetimepicker.trigger('afterOpen.xdsoft');
972
+ setPos();
973
+ $(window)
974
+ .off('resize.xdsoft',setPos)
975
+ .on('resize.xdsoft',setPos);
976
+
977
+ if( options.closeOnWithoutClick ) {
978
+ $([document.body,window]).on('mousedown.xdsoft',function arguments_callee6() {
979
+ datetimepicker.trigger('close.xdsoft');
980
+ $([document.body,window]).off('mousedown.xdsoft',arguments_callee6);
981
+ });
982
+ }
983
+ }
984
+ })
985
+ .on('close.xdsoft', function( event ) {
986
+ var onClose = true;
987
+ if( options.onClose&&options.onClose.call ) {
988
+ onClose=options.onClose.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
989
+ }
990
+ if( onClose!==false&&!options.opened&&!options.inline ) {
991
+ datetimepicker.hide();
992
+ }
993
+ event.stopPropagation();
994
+ })
995
+ .data('input',input);
996
+
997
+ var timer = 0,
998
+ timer1 = 0;
999
+
1000
+ datetimepicker.data('xdsoft_datetime',_xdsoft_datetime);
1001
+ datetimepicker.setOptions(options);
1002
+
1003
+ var ct = options.value?options.value:(input&&input.val&&input.val())?input.val():'';
1004
+ if( ct && _xdsoft_datetime.isValidDate(ct = Date.parseDate(ct, options.format)) ) {
1005
+ datetimepicker.data('changed',true);
1006
+ }else
1007
+ ct = '';
1008
+
1009
+ _xdsoft_datetime.setCurrentTime( ct?ct:0 );
1010
+
1011
+ datetimepicker.trigger('afterOpen.xdsoft');
1012
+
1013
+ input
1014
+ .data( 'xdsoft_datetimepicker',datetimepicker )
1015
+ .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event) {
1016
+ if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') )
1017
+ return;
1018
+ clearTimeout(timer);
1019
+ timer = setTimeout(function() {
1020
+ if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') )
1021
+ return;
1022
+ _xdsoft_datetime.setCurrentTime((input&&input.val&&input.val())?input.val():0);
1023
+ datetimepicker.trigger('open.xdsoft');
1024
+ },100);
1025
+ })
1026
+ .on('keydown.xdsoft',function( event ) {
1027
+ var val = this.value,
1028
+ key = event.which;
1029
+ switch(true) {
1030
+ case !!~([ENTER].indexOf(key)):
1031
+ var elementSelector = $("input:visible,textarea:visible");
1032
+ datetimepicker.trigger('close.xdsoft');
1033
+ elementSelector.eq(elementSelector.index(this) + 1).focus();
1034
+ return false;
1035
+ case !!~[TAB].indexOf(key):
1036
+ datetimepicker.trigger('close.xdsoft');
1037
+ return true;
1038
+ }
1039
+ });
1040
+ },
1041
+ destroyDateTimePicker = function( input ) {
1042
+ var datetimepicker = input.data('xdsoft_datetimepicker');
1043
+ if( datetimepicker ) {
1044
+ datetimepicker.data('xdsoft_datetime',null);
1045
+ datetimepicker.remove();
1046
+ input
1047
+ .data( 'xdsoft_datetimepicker',null )
1048
+ .off( 'open.xdsoft focusin.xdsoft focusout.xdsoft mousedown.xdsoft blur.xdsoft keydown.xdsoft' );
1049
+ $(window).off('resize.xdsoft');
1050
+ $([window,document.body]).off('mousedown.xdsoft');
1051
+ input.unmousewheel&&input.unmousewheel();
1052
+ }
1053
+ };
1054
+ $(document)
1055
+ .off('keydown.xdsoftctrl keyup.xdsoftctrl')
1056
+ .on('keydown.xdsoftctrl',function(e) {
1057
+ if ( e.keyCode == CTRLKEY )
1058
+ ctrlDown = true;
1059
+ })
1060
+ .on('keyup.xdsoftctrl',function(e) {
1061
+ if ( e.keyCode == CTRLKEY )
1062
+ ctrlDown = false;
1063
+ });
1064
+ return this.each(function() {
1065
+ var datetimepicker;
1066
+ if( datetimepicker = $(this).data('xdsoft_datetimepicker') ) {
1067
+ if( $.type(opt) === 'string' ) {
1068
+ switch(opt) {
1069
+ case 'show':
1070
+ $(this).select().focus();
1071
+ datetimepicker.trigger( 'open.xdsoft' );
1072
+ break;
1073
+ case 'hide':
1074
+ datetimepicker.trigger('close.xdsoft');
1075
+ break;
1076
+ case 'destroy':
1077
+ destroyDateTimePicker($(this));
1078
+ break;
1079
+ case 'reset':
1080
+ this.value = this.defaultValue;
1081
+ if(!this.value || !datetimepicker.data('xdsoft_datetime').isValidDate(Date.parseDate(this.value, options.format)))
1082
+ datetimepicker.data('changed',false);
1083
+ datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value);
1084
+ break;
1085
+ }
1086
+ }else{
1087
+ datetimepicker
1088
+ .setOptions(opt);
1089
+ }
1090
+ return 0;
1091
+ }else
1092
+ ($.type(opt) !== 'string')&&createDateTimePicker($(this));
1093
+ });
1094
+ };
1095
+ })( jQuery );
1096
+
1097
+ //http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
1098
+ /*
1099
+ * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
1100
+ *
1101
+ * This program is free software; you can redistribute it and/or modify it
1102
+ * under the terms of the GNU Lesser General Public License as published by the
1103
+ * Free Software Foundation, version 2.1.
1104
+ *
1105
+ * This program is distributed in the hope that it will be useful, but WITHOUT
1106
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1107
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1108
+ * details.
1109
+ */
1110
+ Date.parseFunctions={count:0};Date.parseRegexes=[];Date.formatFunctions={count:0};Date.prototype.dateFormat=function(format) {if(Date.formatFunctions[format]==null) {Date.createNewFormat(format)}var func=Date.formatFunctions[format];return this[func]()};Date.createNewFormat=function(format) {var funcName="format"+Date.formatFunctions.count++;Date.formatFunctions[format]=funcName;var code="Date.prototype."+funcName+" = function() {return ";var special=false;var ch='';for(var i=0;i<format.length;++i) {ch=format.charAt(i);if(!special&&ch=="\\") {special=true}else if(special) {special=false;code+="'"+String.escape(ch)+"' + "}else{code+=Date.getFormatCode(ch)}}eval(code.substring(0,code.length-3)+";}")};Date.getFormatCode=function(character) {switch(character) {case"d":return"String.leftPad(this.getDate(), 2, '0') + ";case"D":return"Date.dayNames[this.getDay()].substring(0, 3) + ";case"j":return"this.getDate() + ";case"l":return"Date.dayNames[this.getDay()] + ";case"S":return"this.getSuffix() + ";case"w":return"this.getDay() + ";case"z":return"this.getDayOfYear() + ";case"W":return"this.getWeekOfYear() + ";case"F":return"Date.monthNames[this.getMonth()] + ";case"m":return"String.leftPad(this.getMonth() + 1, 2, '0') + ";case"M":return"Date.monthNames[this.getMonth()].substring(0, 3) + ";case"n":return"(this.getMonth() + 1) + ";case"t":return"this.getDaysInMonth() + ";case"L":return"(this.isLeapYear() ? 1 : 0) + ";case"Y":return"this.getFullYear() + ";case"y":return"('' + this.getFullYear()).substring(2, 4) + ";case"a":return"(this.getHours() < 12 ? 'am' : 'pm') + ";case"A":return"(this.getHours() < 12 ? 'AM' : 'PM') + ";case"g":return"((this.getHours() %12) ? this.getHours() % 12 : 12) + ";case"G":return"this.getHours() + ";case"h":return"String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";case"H":return"String.leftPad(this.getHours(), 2, '0') + ";case"i":return"String.leftPad(this.getMinutes(), 2, '0') + ";case"s":return"String.leftPad(this.getSeconds(), 2, '0') + ";case"O":return"this.getGMTOffset() + ";case"T":return"this.getTimezone() + ";case"Z":return"(this.getTimezoneOffset() * -60) + ";default:return"'"+String.escape(character)+"' + "}};Date.parseDate=function(input,format) {if(Date.parseFunctions[format]==null) {Date.createParser(format)}var func=Date.parseFunctions[format];return Date[func](input)};Date.createParser=function(format) {var funcName="parse"+Date.parseFunctions.count++;var regexNum=Date.parseRegexes.length;var currentGroup=1;Date.parseFunctions[format]=funcName;var code="Date."+funcName+" = function(input) {\n"+"var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n"+"var d = new Date();\n"+"y = d.getFullYear();\n"+"m = d.getMonth();\n"+"d = d.getDate();\n"+"var results = input.match(Date.parseRegexes["+regexNum+"]);\n"+"if (results && results.length > 0) {";var regex="";var special=false;var ch='';for(var i=0;i<format.length;++i) {ch=format.charAt(i);if(!special&&ch=="\\") {special=true}else if(special) {special=false;regex+=String.escape(ch)}else{obj=Date.formatCodeToRegex(ch,currentGroup);currentGroup+=obj.g;regex+=obj.s;if(obj.g&&obj.c) {code+=obj.c}}}code+="if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"+"{return new Date(y, m, d, h, i, s);}\n"+"else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"+"{return new Date(y, m, d, h, i);}\n"+"else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n"+"{return new Date(y, m, d, h);}\n"+"else if (y > 0 && m >= 0 && d > 0)\n"+"{return new Date(y, m, d);}\n"+"else if (y > 0 && m >= 0)\n"+"{return new Date(y, m);}\n"+"else if (y > 0)\n"+"{return new Date(y);}\n"+"}return null;}";Date.parseRegexes[regexNum]=new RegExp("^"+regex+"$");eval(code)};Date.formatCodeToRegex=function(character,currentGroup) {switch(character) {case"D":return{g:0,c:null,s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};case"j":case"d":return{g:1,c:"d = parseInt(results["+currentGroup+"], 10);\n",s:"(\\d{1,2})"};case"l":return{g:0,c:null,s:"(?:"+Date.dayNames.join("|")+")"};case"S":return{g:0,c:null,s:"(?:st|nd|rd|th)"};case"w":return{g:0,c:null,s:"\\d"};case"z":return{g:0,c:null,s:"(?:\\d{1,3})"};case"W":return{g:0,c:null,s:"(?:\\d{2})"};case"F":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+currentGroup+"].substring(0, 3)], 10);\n",s:"("+Date.monthNames.join("|")+")"};case"M":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+currentGroup+"]], 10);\n",s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};case"n":case"m":return{g:1,c:"m = parseInt(results["+currentGroup+"], 10) - 1;\n",s:"(\\d{1,2})"};case"t":return{g:0,c:null,s:"\\d{1,2}"};case"L":return{g:0,c:null,s:"(?:1|0)"};case"Y":return{g:1,c:"y = parseInt(results["+currentGroup+"], 10);\n",s:"(\\d{4})"};case"y":return{g:1,c:"var ty = parseInt(results["+currentGroup+"], 10);\n"+"y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",s:"(\\d{1,2})"};case"a":return{g:1,c:"if (results["+currentGroup+"] == 'am') {\n"+"if (h == 12) { h = 0; }\n"+"} else { if (h < 12) { h += 12; }}",s:"(am|pm)"};case"A":return{g:1,c:"if (results["+currentGroup+"] == 'AM') {\n"+"if (h == 12) { h = 0; }\n"+"} else { if (h < 12) { h += 12; }}",s:"(AM|PM)"};case"g":case"G":case"h":case"H":return{g:1,c:"h = parseInt(results["+currentGroup+"], 10);\n",s:"(\\d{1,2})"};case"i":return{g:1,c:"i = parseInt(results["+currentGroup+"], 10);\n",s:"(\\d{2})"};case"s":return{g:1,c:"s = parseInt(results["+currentGroup+"], 10);\n",s:"(\\d{2})"};case"O":return{g:0,c:null,s:"[+-]\\d{4}"};case"T":return{g:0,c:null,s:"[A-Z]{3}"};case"Z":return{g:0,c:null,s:"[+-]\\d{1,5}"};default:return{g:0,c:null,s:String.escape(character)}}};Date.prototype.getTimezone=function() {return this.toString().replace(/^.*? ([A-Z]{3}) [0-9]{4}.*$/,"$1").replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/,"$1$2$3")};Date.prototype.getGMTOffset=function() {return(this.getTimezoneOffset()>0?"-":"+")+String.leftPad(Math.floor(Math.abs(this.getTimezoneOffset())/60),2,"0")+String.leftPad(Math.abs(this.getTimezoneOffset())%60,2,"0")};Date.prototype.getDayOfYear=function() {var num=0;Date.daysInMonth[1]=this.isLeapYear()?29:28;for(var i=0;i<this.getMonth();++i) {num+=Date.daysInMonth[i]}return num+this.getDate()-1};Date.prototype.getWeekOfYear=function() {var now=this.getDayOfYear()+(4-this.getDay());var jan1=new Date(this.getFullYear(),0,1);var then=(7-jan1.getDay()+4);document.write(then);return String.leftPad(((now-then)/7)+1,2,"0")};Date.prototype.isLeapYear=function() {var year=this.getFullYear();return((year&3)==0&&(year%100||(year%400==0&&year)))};Date.prototype.getFirstDayOfMonth=function() {var day=(this.getDay()-(this.getDate()-1))%7;return(day<0)?(day+7):day};Date.prototype.getLastDayOfMonth=function() {var day=(this.getDay()+(Date.daysInMonth[this.getMonth()]-this.getDate()))%7;return(day<0)?(day+7):day};Date.prototype.getDaysInMonth=function() {Date.daysInMonth[1]=this.isLeapYear()?29:28;return Date.daysInMonth[this.getMonth()]};Date.prototype.getSuffix=function() {switch(this.getDate()) {case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th"}};String.escape=function(string) {return string.replace(/('|\\)/g,"\\$1")};String.leftPad=function(val,size,ch) {var result=new String(val);if(ch==null) {ch=" "}while(result.length<size) {result=ch+result}return result};Date.daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];Date.monthNames=["January","February","March","April","May","June","July","August","September","October","November","December"];Date.dayNames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];Date.y2kYear=50;Date.monthNumbers={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};Date.patterns={ISO8601LongPattern:"Y-m-d H:i:s",ISO8601ShortPattern:"Y-m-d",ShortDatePattern:"n/j/Y",LongDatePattern:"l, F d, Y",FullDateTimePattern:"l, F d, Y g:i:s A",MonthDayPattern:"F d",ShortTimePattern:"g:i A",LongTimePattern:"g:i:s A",SortableDateTimePattern:"Y-m-d\\TH:i:s",UniversalSortableDateTimePattern:"Y-m-d H:i:sO",YearMonthPattern:"F, Y"};
1111
+
1112
+ //https://github.com/brandonaaron/jquery-mousewheel/blob/master/jquery.mousewheel.js
1113
+ /*
1114
+ * Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
1115
+ *
1116
+ * Licensed under the MIT License (LICENSE.txt).
1117
+ *
1118
+ * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
1119
+ * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
1120
+ * Thanks to: Seamus Leahy for adding deltaX and deltaY
1121
+ *
1122
+ * Version: 3.1.3
1123
+ *
1124
+ * Requires: 1.2.2+
1125
+ */
1126
+ (function(factory) {if(typeof define==='function'&&define.amd) {define(['jquery'],factory)}else if(typeof exports==='object') {module.exports=factory}else{factory(jQuery)}}(function($) {var toFix=['wheel','mousewheel','DOMMouseScroll','MozMousePixelScroll'];var toBind='onwheel'in document||document.documentMode>=9?['wheel']:['mousewheel','DomMouseScroll','MozMousePixelScroll'];var lowestDelta,lowestDeltaXY;if($.event.fixHooks) {for(var i=toFix.length;i;) {$.event.fixHooks[toFix[--i]]=$.event.mouseHooks}}$.event.special.mousewheel={setup:function() {if(this.addEventListener) {for(var i=toBind.length;i;) {this.addEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=handler}},teardown:function() {if(this.removeEventListener) {for(var i=toBind.length;i;) {this.removeEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=null}}};$.fn.extend({mousewheel:function(fn) {return fn?this.bind("mousewheel",fn):this.trigger("mousewheel")},unmousewheel:function(fn) {return this.unbind("mousewheel",fn)}});function handler(event) {var orgEvent=event||window.event,args=[].slice.call(arguments,1),delta=0,deltaX=0,deltaY=0,absDelta=0,absDeltaXY=0,fn;event=$.event.fix(orgEvent);event.type="mousewheel";if(orgEvent.wheelDelta) {delta=orgEvent.wheelDelta}if(orgEvent.detail) {delta=orgEvent.detail*-1}if(orgEvent.deltaY) {deltaY=orgEvent.deltaY*-1;delta=deltaY}if(orgEvent.deltaX) {deltaX=orgEvent.deltaX;delta=deltaX*-1}if(orgEvent.wheelDeltaY!==undefined) {deltaY=orgEvent.wheelDeltaY}if(orgEvent.wheelDeltaX!==undefined) {deltaX=orgEvent.wheelDeltaX*-1}absDelta=Math.abs(delta);if(!lowestDelta||absDelta<lowestDelta) {lowestDelta=absDelta}absDeltaXY=Math.max(Math.abs(deltaY),Math.abs(deltaX));if(!lowestDeltaXY||absDeltaXY<lowestDeltaXY) {lowestDeltaXY=absDeltaXY}fn=delta>0?'floor':'ceil';delta=Math[fn](delta/lowestDelta);deltaX=Math[fn](deltaX/lowestDeltaXY);deltaY=Math[fn](deltaY/lowestDeltaXY);args.unshift(event,delta,deltaX,deltaY);return($.event.dispatch||$.event.handle).apply(this,args)}}));