PageSourceSearch

https://femme.gr/wp-content/plugins/clearblue-due-date-calculator/…/clearblue-due-date-calculator.js?ver=1.0.4

js femme.gr collected 2026-10-02 14:24:48 UTC 4,485 bytes, 182 lines download raw bytes

1(function ($, window, document, undefined) { 'use strict';
2
3    /*
4    *  Class creation
5    */
6	var CbDueDateCalculator = function(el) { this.constructor(el); }
7
8    /*
9    *  @function
10    *  constructor
11    */
12	CbDueDateCalculator.prototype.constructor = function(el) {
13		this.$container = $(el);
14		this.locale = this.$container.attr('data-locale');
15		this.$tool = this.$container.find('.cbddc-tool');
16		this.$datepickers = this.$tool.find('.cbddc-datepicker');
17		this.$results = this.$container.find('.cbddc-results');
18		this.$buttonResults = this.$tool.find('.cbddc-button--arrow-right');
19		this.$buttonModify = this.$results.find('.cbddc-button--arrow-left');
20
21		this.initInputs();
22		this.initDatepickers();
23
24		this.$buttonResults.on('click', this.onClickButtonResults.bind(this));
25		this.$buttonModify.on('click', this.onClickButtonModify.bind(this));
26	}
27
28    /*
29    *  @function
30    *  initInputs
31    */
32	CbDueDateCalculator.prototype.initInputs = function() {
33		var inputs = {};
34		this.$inputs = this.$tool.find('input, select, textarea');
35
36		this.$inputs.each(function() {
37			var $input = $(this),
38				name = $input.attr('name');
39
40			inputs[name] = {
41				$el: $input,
42				$wrapper: $input.parents('.cbddc-input-line'),
43				value: $input.val(),
44				required: !!$input.prop('required')
45			};
46		});
47
48		this.$inputs.on('change', this.onInputChange.bind(this));
49		this.inputs = inputs;
50	}
51
52    /*
53    *  @function
54    *  initDatepickers
55    */
56	CbDueDateCalculator.prototype.initDatepickers = function() {
57		var tool = this;
58
59		this.$datepickers.each(function() {
60			new CbDatepicker(this, tool);
61		});
62	}
63
64    /*
65    *  @eventListener
66    *  onInputChange
67    */
68	CbDueDateCalculator.prototype.onInputChange = function(e) {
69		var $input = $(e.currentTarget),	
70			name = $input.attr('name'),
71			value = $input.val();
72
73		this.inputs[name].value = value;
74		this.checkRequiredInput(this.inputs[name]);
75	}
76
77    /*
78    *  @eventListener
79    *  onSelectDate
80    */
81	CbDueDateCalculator.prototype.onSelectDate = function(formattedDate, date, name) {
82		this.inputs[name].value = date;
83		this.checkRequiredInput(this.inputs[name]);
84	}
85
86    /*
87    *  @function
88    *  checkRequired
89    */
90	CbDueDateCalculator.prototype.checkRequired = function() {
91		var errors = false;
92
93		for (var i in this.inputs) {
94			errors = (this.checkRequiredInput(this.inputs[i]) === true) ? true : errors;
95		}
96
97		return errors;
98	}
99
100    /*
101    *  @function
102    *  checkRequiredInput
103    */
104	CbDueDateCalculator.prototype.checkRequiredInput = function(input) {
105		if (input.required && !!input.value === false) {
106			input.$wrapper.addClass('-error');
107			return true;
108		}
109		else {
110			input.$wrapper.removeClass('-error');
111			return false;
112		}
113	}
114
115    /*
116    *  @eventListener
117    *  onClickButtonResults
118    */
119	CbDueDateCalculator.prototype.onClickButtonResults = function() {
120		var errors = this.checkRequired();
121
122		if (!errors) {
123			this.showResults();
124		}
125	}
126
127    /*
128    *  @eventListener
129    *  onClickButtonModify
130    */
131	CbDueDateCalculator.prototype.onClickButtonModify = function() {
132		this.hideResults();
133	}
134
135    /*
136    *  @function
137    *  calculate
138    */
139	CbDueDateCalculator.prototype.calculate = function() {
140		var cycleLength = parseInt(this.inputs['cbddc-cycle-length'].value),
141			startDate = this.inputs['cbddc-last-period-start-date'].value,
142			resultDate = (cycleLength == 0) ? startDate.addDays(280) : startDate.addDays(252 + cycleLength);
143
144		this.$results.find('.cbddc-result-date').text(this.formatDateStr(resultDate, CBDDC_LOCALE.dateFormatLong));
145	}
146
147    /*
148    *  @function
149    *  showResults
150    */
151	CbDueDateCalculator.prototype.showResults = function() {
152		this.calculate();
153		this.$tool.removeClass('-active');
154		this.$results.addClass('-active');
155	}
156
157    /*
158    *  @function
159    *  hideResults
160    */
161	CbDueDateCalculator.prototype.hideResults = function() {
162		this.$tool.addClass('-active');
163		this.$results.removeClass('-active');
164	}
165
166    /*
167    *  @function
168    *  formatDateStr
169    */
170	CbDueDateCalculator.prototype.formatDateStr = function(date, format) {
171		format = format || CBDDC_LOCALE.dateFormat;
172		return date.formatCustom(format, CBDDC_LOCALE);
173	}
174
175    /*
176    *  Instanciation
177    */
178    $('.cbddc').each(function() {
179    	new CbDueDateCalculator(this);
180    });
181
182})(jQuery, window, document);

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.