1/** 2 * Datepicker wrapper. 3 * 4 * @author Htmlstream 5 * @version 1.0 6 * 7 */ 8;(function ($) { 9 'use strict'; 10 11 $.HSCore.components.HSDatepicker = { 12 /** 13 * 14 * 15 * @var Object _baseConfig 16 */ 17 _baseConfig: { 18 dateFormat: 'yy-mm-dd', 19 dayNamesMin: [ 20 'Sun', 21 'Mon', 22 'Tue', 23 'Wed', 24 'Thu', 25 'Fri', 26 'Sat' 27 ], 28 prevText: '<i class="fa fa-angle-left"></i>', 29 nextText: '<i class="fa fa-angle-right"></i>' 30 }, 31 32 /** 33 * 34 * 35 * @var jQuery pageCollection 36 */ 37 pageCollection: $(), 38 39 /** 40 * Initialization of Datepicker wrapper. 41 * 42 * @param String selector (optional) 43 * @param Object config (optional) 44 * 45 * @return jQuery pageCollection - collection of initialized items. 46 */ 47 48 init: function (selector, config) { 49 50 this.collection = selector && $(selector).length ? $(selector) : $(); 51 if (!$(selector).length) return; 52 53 this.config = config && $.isPlainObject(config) ? 54 $.extend({}, this._baseConfig, config) : this._baseConfig; 55 56 this.config.itemSelector = selector; 57 58 this.initDatepicker(); 59 60 return this.pageCollection; 61 62 }, 63 64 initDatepicker: function () { 65 //Variables 66 var $self = this, 67 config = $self.config, 68 collection = $self.pageCollection; 69 70 //Actions 71 this.collection.each(function (i, el) { 72 //Variables 73 var $this = $(el), 74 to = $this.data('to'), 75 rangeBoolean = $this.data('range'); 76 77 if (rangeBoolean == 1) { 78 var dateFrom = $this.datepicker({ 79 dateFormat: config['dateFormat'], 80 defaultDate: '+1w', 81 dayNamesMin: config['dayNamesMin'], 82 numberOfMonths: 1, 83 showOtherMonths: true, 84 prevText: config['prevText'], 85 nextText: config['nextText'], 86 beforeShow: $self.datepickerCustomClass 87 }).on('change', function () { 88 dateTo.datepicker('option', 'minDate', $self.getDate(this)); 89 }); 90 91 var dateTo = $('#' + to).datepicker({ 92 dateFormat: config['dateFormat'], 93 defaultDate: '+1w', 94 dayNamesMin: config['dayNamesMin'], 95 numberOfMonths: 1, 96 showOtherMonths: true, 97 prevText: config['prevText'], 98 nextText: config['nextText'], 99 beforeShow: $self.datepickerCustomClass 100 }).on('change', function () { 101 dateFrom.datepicker('option', 'maxDate', $self.getDate(this)); 102 }); 103 } else { 104 $this.datepicker({ 105 dateFormat: config['dateFormat'], 106 dayNamesMin: config['dayNamesMin'], 107 showOtherMonths: true, 108 prevText: config['prevText'], 109 nextText: config['nextText'], 110 beforeShow: $self.datepickerCustomClass 111 }); 112 } 113 114 //Actions 115 collection = collection.add($this); 116 }); 117 }, 118 119 datepickerCustomClass: function (el, attr) { 120 var arrayOfClasses, customClass, i; 121 122 arrayOfClasses = attr.input[0].className.split(' '); 123 124 for (i = 0; arrayOfClasses.length > i; i++) { 125 if (arrayOfClasses[i].substring(0, 6) == 'u-date') { 126 customClass = arrayOfClasses[i]; 127 } 128 } 129 130 $('#ui-datepicker-div').addClass(customClass); 131 }, 132 133 getDate: function (element) { 134 var $self = this, 135 date, 136 config = $self.config; 137 138 try { 139 date = $.datepicker.parseDate(config['dateFormat'], element.value); 140 } catch (error) { 141 date = null; 142 } 143 144 return date; 145 } 146 147 }; 148 149})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.