PageSourceSearch

https://investbraga.pt/Content/Assets/js/components/hs.datepicker.js?v=15

js investbraga.pt collected 2026-09-26 02:44:57 UTC 4,886 bytes, 177 lines download raw bytes

1/**
2 * Datepicker wrapper.
3 *
4 * @author Htmlstream
5 * @version 1.1
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          type = $this.data('type'),
76          minDate,
77          maxDate;
78
79        if (type == 'one-field-range') {
80          var datePicker = $this.datepicker({
81            dateFormat: config['dateFormat'],
82            defaultDate: '+1w',
83            dayNamesMin: config['dayNamesMin'],
84            numberOfMonths: 1,
85            showOtherMonths: true,
86            prevText: config['prevText'],
87            nextText: config['nextText'],
88            beforeShow: $self.datepickerCustomClass,
89            onSelect: function(dateText, inst) {
90              console.log(inst);
91            }
92          }).on('change', function () {
93            var activeDate = datePicker.datepicker("getDate");
94
95            if(minDate == null) {
96              minDate = activeDate;
97            } else if(activeDate < minDate) {
98              minDate = activeDate;
99            }
100
101            if(maxDate == null && activeDate > minDate) {
102              maxDate = activeDate;
103            } else if(activeDate > maxDate) {
104              maxDate = activeDate;
105            }
106          });
107        } else if (type == 'range') {
108          var dateFrom = $this.datepicker({
109            dateFormat: config['dateFormat'],
110            defaultDate: '+1w',
111            dayNamesMin: config['dayNamesMin'],
112            numberOfMonths: 1,
113            showOtherMonths: true,
114            prevText: config['prevText'],
115            nextText: config['nextText'],
116            beforeShow: $self.datepickerCustomClass
117          }).on('change', function () {
118            dateTo.datepicker('option', 'minDate', $self.getDate(this));
119          });
120
121          var dateTo = $('#' + to).datepicker({
122            dateFormat: config['dateFormat'],
123            defaultDate: '+1w',
124            dayNamesMin: config['dayNamesMin'],
125            numberOfMonths: 1,
126            showOtherMonths: true,
127            prevText: config['prevText'],
128            nextText: config['nextText'],
129            beforeShow: $self.datepickerCustomClass
130          }).on('change', function () {
131            dateFrom.datepicker('option', 'maxDate', $self.getDate(this));
132          });
133        } else {
134          $this.datepicker({
135            dateFormat: config['dateFormat'],
136            dayNamesMin: config['dayNamesMin'],
137            showOtherMonths: true,
138            prevText: config['prevText'],
139            nextText: config['nextText'],
140            beforeShow: $self.datepickerCustomClass
141          });
142        }
143
144        //Actions
145        collection = collection.add($this);
146      });
147    },
148
149    datepickerCustomClass: function (el, attr) {
150      var arrayOfClasses, customClass, i;
151
152      arrayOfClasses = attr.input[0].className.split(' ');
153
154      for (i = 0; arrayOfClasses.length > i; i++) {
155        if (arrayOfClasses[i].substring(0, 6) == 'u-date') {
156          customClass = arrayOfClasses[i];
157        }
158      }
159
160      $('#ui-datepicker-div').addClass(customClass);
161    },
162
163    getDate: function (element) {
164      var $self = this,
165        date,
166        config = $self.config;
167
168      try {
169        date = $.datepicker.parseDate(config['dateFormat'], element.value);
170      } catch (error) {
171        date = null;
172      }
173
174      return date;
175    }
176  };
177})(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.