1 |
85ad3d82
|
Assos Assos
|
(function ($) {
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
Drupal.behaviors.dateSelect = {};
|
5 |
|
|
|
6 |
|
|
Drupal.behaviors.dateSelect.attach = function (context, settings) {
|
7 |
|
|
var $widget = $('.form-type-date-select').parents('fieldset').once('date');
|
8 |
|
|
var i;
|
9 |
|
|
for (i = 0; i < $widget.length; i++) {
|
10 |
|
|
new Drupal.date.EndDateHandler($widget[i]);
|
11 |
|
|
}
|
12 |
|
|
};
|
13 |
|
|
|
14 |
|
|
Drupal.date = Drupal.date || {};
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
Drupal.date.EndDateHandler = function (widget) {
|
27 |
|
|
this.$widget = $(widget);
|
28 |
|
|
this.$start = this.$widget.find('.form-type-date-select[class$=value]');
|
29 |
|
|
this.$end = this.$widget.find('.form-type-date-select[class$=value2]');
|
30 |
b720ea3e
|
Assos Assos
|
if (this.$end.length === 0) {
|
31 |
85ad3d82
|
Assos Assos
|
return;
|
32 |
|
|
}
|
33 |
|
|
this.initializeSelects();
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
if (this.endDateIsBlank() || this.endDateIsSame()) {
|
38 |
|
|
this.bindClickHandlers();
|
39 |
|
|
|
40 |
|
|
this.syncEndDate();
|
41 |
|
|
}
|
42 |
|
|
};
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
Drupal.date.EndDateHandler.prototype.initializeSelects = function () {
|
48 |
|
|
var $starts = this.$start.find('select');
|
49 |
|
|
var $end, $start, endId, i, id;
|
50 |
|
|
this.selects = {};
|
51 |
|
|
for (i = 0; i < $starts.length; i++) {
|
52 |
|
|
$start = $($starts[i]);
|
53 |
|
|
id = $start.attr('id');
|
54 |
|
|
endId = id.replace('-value-', '-value2-');
|
55 |
|
|
$end = $('#' + endId);
|
56 |
|
|
this.selects[id] = {
|
57 |
|
|
'id': id,
|
58 |
|
|
'start': $start,
|
59 |
|
|
'end': $end
|
60 |
|
|
};
|
61 |
|
|
}
|
62 |
|
|
};
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
Drupal.date.EndDateHandler.prototype.endDateIsBlank = function () {
|
68 |
|
|
var id;
|
69 |
|
|
for (id in this.selects) {
|
70 |
|
|
if (this.selects.hasOwnProperty(id)) {
|
71 |
b720ea3e
|
Assos Assos
|
if (this.selects[id].end.val() !== '') {
|
72 |
85ad3d82
|
Assos Assos
|
return false;
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
return true;
|
77 |
|
|
};
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
Drupal.date.EndDateHandler.prototype.endDateIsSame = function () {
|
83 |
|
|
var id;
|
84 |
|
|
for (id in this.selects) {
|
85 |
|
|
if (this.selects.hasOwnProperty(id)) {
|
86 |
|
|
if (this.selects[id].end.val() != this.selects[id].start.val()) {
|
87 |
|
|
return false;
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
return true;
|
92 |
|
|
};
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
Drupal.date.EndDateHandler.prototype.bindClickHandlers = function () {
|
98 |
|
|
var id;
|
99 |
|
|
for (id in this.selects) {
|
100 |
|
|
if (this.selects.hasOwnProperty(id)) {
|
101 |
|
|
this.selects[id].start.bind('click.endDateHandler', this.startClickHandler.bind(this));
|
102 |
|
|
this.selects[id].end.bind('focus', this.endFocusHandler.bind(this));
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
};
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
Drupal.date.EndDateHandler.prototype.startClickHandler = function (event) {
|
111 |
|
|
this.syncEndDate();
|
112 |
|
|
};
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
Drupal.date.EndDateHandler.prototype.endFocusHandler = function (event) {
|
118 |
|
|
var id;
|
119 |
|
|
for (id in this.selects) {
|
120 |
|
|
if (this.selects.hasOwnProperty(id)) {
|
121 |
|
|
this.selects[id].start.unbind('click.endDateHandler');
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
|
|
$(event.target).unbind('focus', this.endFocusHandler);
|
125 |
|
|
};
|
126 |
|
|
|
127 |
|
|
Drupal.date.EndDateHandler.prototype.syncEndDate = function () {
|
128 |
|
|
var id;
|
129 |
|
|
for (id in this.selects) {
|
130 |
|
|
if (this.selects.hasOwnProperty(id)) {
|
131 |
|
|
this.selects[id].end.val(this.selects[id].start.val());
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
};
|
135 |
|
|
|
136 |
|
|
}(jQuery));
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
if (!Function.prototype.bind) {
|
143 |
|
|
Function.prototype.bind = function (oThis) {
|
144 |
|
|
if (typeof this !== "function")
|
145 |
|
|
throw new TypeError("Function.prototype.bind - what is trying to be fBound is not callable");
|
146 |
|
|
|
147 |
|
|
var aArgs = Array.prototype.slice.call(arguments, 1),
|
148 |
|
|
fToBind = this,
|
149 |
|
|
fNOP = function () {},
|
150 |
|
|
fBound = function () {
|
151 |
|
|
return fToBind.apply(this instanceof fNOP ? this : oThis || window, aArgs.concat(Array.prototype.slice.call(arguments)));
|
152 |
|
|
};
|
153 |
|
|
|
154 |
|
|
fNOP.prototype = this.prototype;
|
155 |
|
|
fBound.prototype = new fNOP();
|
156 |
|
|
|
157 |
|
|
return fBound;
|
158 |
|
|
};
|
159 |
|
|
} |