|
2101 | 2101 | }; |
2102 | 2102 |
|
2103 | 2103 | picker.keyBinds = function (keyBinds) { |
| 2104 | + if (arguments.length === 0) { |
| 2105 | + return options.keyBinds; |
| 2106 | + } |
| 2107 | + |
2104 | 2108 | options.keyBinds = keyBinds; |
2105 | 2109 | return picker; |
2106 | 2110 | }; |
|
2373 | 2377 | ********************************************************************************/ |
2374 | 2378 |
|
2375 | 2379 | $.fn.datetimepicker = function (options) { |
2376 | | - return this.each(function () { |
2377 | | - var $this = $(this); |
2378 | | - if (!$this.data('DateTimePicker')) { |
2379 | | - // create a private copy of the defaults object |
2380 | | - options = $.extend(true, {}, $.fn.datetimepicker.defaults, options); |
2381 | | - $this.data('DateTimePicker', dateTimePicker($this, options)); |
2382 | | - } |
2383 | | - }); |
| 2380 | + options = options || {}; |
| 2381 | + |
| 2382 | + var args = Array.prototype.slice.call(arguments, 1), |
| 2383 | + isInstance = true, |
| 2384 | + thisMethods = ['destroy', 'hide', 'show', 'toggle'], |
| 2385 | + returnValue; |
| 2386 | + |
| 2387 | + if (typeof options === 'object') { |
| 2388 | + return this.each(function () { |
| 2389 | + var $this = $(this); |
| 2390 | + if (!$this.data('DateTimePicker')) { |
| 2391 | + // create a private copy of the defaults object |
| 2392 | + options = $.extend(true, {}, $.fn.datetimepicker.defaults, options); |
| 2393 | + $this.data('DateTimePicker', dateTimePicker($this, options)); |
| 2394 | + } |
| 2395 | + }); |
| 2396 | + } else if (typeof options === 'string') { |
| 2397 | + this.each(function () { |
| 2398 | + var $this = $(this), |
| 2399 | + instance = $this.data('DateTimePicker'); |
| 2400 | + if (!instance) { |
| 2401 | + throw new Error('bootstrap-datetimepicker("' + options + '") method was called on an element that is not using DateTimePicker'); |
| 2402 | + } |
| 2403 | + |
| 2404 | + returnValue = instance[options].apply(instance, args); |
| 2405 | + isInstance = returnValue === instance; |
| 2406 | + }); |
| 2407 | + |
| 2408 | + if (isInstance || $.inArray(options, thisMethods) > -1) { |
| 2409 | + return this; |
| 2410 | + } |
| 2411 | + |
| 2412 | + return returnValue; |
| 2413 | + } |
| 2414 | + |
| 2415 | + throw new TypeError('Invalid arguments for DateTimePicker: ' + options); |
2384 | 2416 | }; |
2385 | 2417 |
|
2386 | 2418 | $.fn.datetimepicker.defaults = { |
|
0 commit comments