Created
May 23, 2013 07:49
-
-
Save bitsprint/5633357 to your computer and use it in GitHub Desktop.
jQuery UI DateTime extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var App = { namespace: 'foo' }; | |
| (function (factory) { | |
| 'use strict'; | |
| if (typeof define === 'function' && define.amd) { | |
| // Register as an anonymous AMD module: | |
| define([ | |
| 'jquery' | |
| , 'jqueryui' | |
| , App | |
| ], factory); | |
| } else { | |
| // Browser globals: | |
| factory(window.jQuery, window.jQuery.ui, App || {}); | |
| } | |
| }(function ($, ui, App) { | |
| 'use strict'; | |
| App.UiExtensions = function(options) { | |
| if (!(this instanceof App.UiExtensions)) | |
| throw new Error('Constructor invoked as a function!'); | |
| if (typeof $ === undefined) | |
| throw new Error('The following dependency was not satisfied: jQuery'); | |
| if (typeof $.ui === undefined) | |
| throw new Error('The following dependency was not satisfied: jQuery.ui'); | |
| this.defaults = { | |
| dateTimeSelector: 'input.datetime:not(.hasDatepicker)' | |
| , zIndex: 200 | |
| , dateFormat: 'dd/mm/yy' | |
| , changeMonth: true | |
| , changeYear: true | |
| , maxDate: 0 | |
| , minDate: new Date(1970, 0, 1) | |
| , yearRange: '-40:+0' | |
| }; | |
| this.settings = $.extend({}, this.defaults, options); | |
| }; | |
| App.UiExtensions.prototype = function() { | |
| return { | |
| initDatePicker: function () { | |
| var self = this | |
| , zIndex = self.settings.zIndex | |
| , dateFormat = self.settings.dateFormat | |
| , changeMonth = self.settings.changeMonth | |
| , changeYear = self.settings.changeYear | |
| , maxDate = self.settings.maxDate | |
| , minDate = self.settings.minDate | |
| , yearRange = self.settings.yearRange; | |
| $(document).on('focus', this.settings.dateTimeSelector, function (event) { | |
| $(this).datepicker({ | |
| dateFormat: dateFormat, | |
| changeMonth: changeMonth, | |
| changeYear: changeYear, | |
| maxDate: maxDate, | |
| minDate: minDate, | |
| yearRange: yearRange, | |
| onSelect: function () { $(this).valid(); } | |
| }).css('z-index', zIndex); | |
| // fix for ie8 whereby the datepicker div is not hidden | |
| //setTimeout(function () { $(".ui-datepicker").hide(); }, 20); | |
| }); | |
| } | |
| }; | |
| }(); | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment