/usr/share/GNUstep/SOGo/WebServerResources/SOGoTimePicker.js is in sogo-common 2.1.1b-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | /* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Time picker widget interface to be added to an INPUT (this!)
*
* Available events:
* time:change -- fired once the value of the input has changed
*
*/
var SOGoTimePickerInterface = {
div: null,
extendedButton: null,
pos: 'bellow',
minutes: '00',
hours: '00',
extended: false,
mouseInside: false,
disposeHandler: null,
bind: function () {
// Build widget
this.div = new Element("div", {'class': 'SOGoTimePickerMenu ' + this.pos});
this.div.hide();
document.body.appendChild(this.div);
var inner = new Element("div");
this.div.appendChild(inner);
var hours = new Element("div", {'class': 'hours'});
inner.appendChild(hours);
for (var i = 0; i < 24; i++) {
var v = (i < 10)? '0' + i : i;
var content = new Element("div", {'class': 'SOGoTimePickerHour_'+v}).update(v);
content.on("click", this.onHourClick.bindAsEventListener(this));
var span = new Element("span", {'class': 'cell'});
span.appendChild(content);
hours.appendChild(span);
if (i == 11) {
hours = new Element("div", {'class': 'hours'});
inner.appendChild(hours);
}
}
var minutes = new Element("div", {'class': 'minutes min5'});
inner.appendChild(minutes);
for (var i = 0; i < 60; i += 5) {
var v = (i < 10)? '0' + i : i;
var content = new Element("div", {'class': 'SOGoTimePickerMinute_'+v}).update(":"+v);
content.on("click", this.onMinuteClick.bindAsEventListener(this));
var span = new Element("span", {'class': 'cell'});
span.appendChild(content);
minutes.appendChild(span);
if (i == 25) {
minutes = new Element("div", {'class': 'minutes min5'});
inner.appendChild(minutes);
}
}
var minutes = new Element("div", {'class': 'minutes min1'});
minutes.hide();
inner.appendChild(minutes);
for (var i = 0; i < 60;) {
var v = (i < 10)? '0' + i : i;
var content = new Element("div", {'class': 'SOGoTimePickerMinute_'+v}).update(":"+v);
content.on("click", this.onMinuteClick.bindAsEventListener(this));
var span = new Element("span", {'class': 'cell'});
span.appendChild(content);
minutes.appendChild(span);
i++;
if (i % 5 == 0) {
minutes = new Element("div", {'class': 'minutes min1'});
minutes.hide();
inner.appendChild(minutes);
}
}
var a = new Element("a", {'class': 'button'});
a.on("click", this.toggleExtendedView.bindAsEventListener(this));
this.extendedButton = new Element("span").update('>>');
a.appendChild(this.extendedButton);
inner.appendChild(a);
inner.appendChild(new Element("hr"));
// Compute position
this.position();
// Register observers
this.on("click", this.toggleVisibility.bindAsEventListener(this));
this.on("change", this.onChange.bindAsEventListener(this));
this.on("keydown", this.onKeydown.bindAsEventListener(this));
this.div.on("mouseenter", this.onEnter.bindAsEventListener(this));
this.div.on("mouseleave", this.onLeave.bindAsEventListener(this));
this.disposeHandler = $(document.body).on("click", this.onDispose.bindAsEventListener(this));
this.disposeHandler.stop();
// Apply current input value if defined
this.onChange();
},
setPosition: function (newPos) {
if (newPos == 'bellow' || newPos == 'above') {
this.div.removeClassName(this.pos);
this.div.addClassName(newPos);
this.pos = newPos;
this.position();
}
},
position: function () {
var inputPosition = this.cumulativeOffset();
var inputDimensions = this.getDimensions();
var divWidth = this.div.getWidth();
var windowWidth = window.width();
var left = inputPosition[0];
var arrow = -1000 + inputDimensions['width'] - 10;
if (left + divWidth > windowWidth) {
left = windowWidth - divWidth - 4;
arrow += (inputPosition[0] - left);
}
var top = inputPosition[1];
if (this.pos == 'bellow')
top += 22;
else
top -= this.div.getHeight();
this.div.setStyle({ top: top+"px",
left: left+"px",
backgroundPosition: arrow+'px top'});
},
onHourClick: function (event) {
this.div.down('.SOGoTimePickerHour_' + this.hours).removeClassName("selected");
this.hours = Event.findElement(event).className.substring(19);
this.div.down('.SOGoTimePickerHour_' + this.hours).addClassName("selected");
this._updateValue();
},
onMinuteClick: function (event) {
this.div.select('.SOGoTimePickerMinute_' + this.minutes).each(function(e) { e.removeClassName("selected") });
this.minutes = Event.findElement(event).className.substring(21);
this.div.select('.SOGoTimePickerMinute_' + this.minutes).each(function(e) { e.addClassName("selected") });
this._updateValue();
this.div.hide();
},
toggleExtendedView: function (event) {
this.extended = !this.extended;
if (this.extended) {
this.extendedButton.update('<<');
this.div.select("DIV.min5").invoke('hide');
this.div.select("DIV.min1").invoke('show');
}
else {
this.extendedButton.update('>>');
this.div.select("DIV.min1").invoke('hide');
this.div.select("DIV.min5").invoke('show');
}
if (this.pos == 'above')
this.position();
},
toggleVisibility: function (event) {
if (this.div.visible())
this.div.hide();
else {
$$('DIV.SOGoTimePickerMenu').invoke('hide');
this.div.show();
this.disposeHandler.start();
}
Event.stop(event);
},
onChange: function (event) {
this.div.down('.SOGoTimePickerHour_' + this.hours).removeClassName("selected");
this.div.select('.SOGoTimePickerMinute_' + this.minutes).each(function(e) { e.removeClassName("selected") });
var matches = this.value.match(/([0-9]{1,2}):?([0-9]{2})/);
if (matches) {
this.hours = matches[1];
this.minutes = matches[2] || '0';
if (parseInt(this.hours, 10) > 23) this.hours = 23;
if (parseInt(this.minutes, 10) > 59) this.minutes = 59;
if (this.minutes % 5 == 0) {
if (this.extended)
this.toggleExtendedView();
}
else if (!this.extended)
this.toggleExtendedView();
if (this.hours.length < 2) this.hours = '0' + this.hours;
if (this.minutes.length < 2) this.minutes = '0' + this.minutes;
this.div.down('.SOGoTimePickerHour_' + this.hours).addClassName("selected");
this.div.select('.SOGoTimePickerMinute_' + this.minutes).each(function(e) { e.addClassName("selected") });
}
this._updateValue(true);
},
onKeydown: function (event) {
this.div.hide();
this.disposeHandler.stop();
if (event.metaKey == 1 || event.ctrlKey == 1 ||
event.keyCode == Event.KEY_TAB ||
event.keyCode == Event.KEY_BACKSPACE)
return true;
if (event.keyCode > 57 && event.keyCode != 186 && event.keyCode != 59 ||
(event.keyCode == 186 || event.keyCode == 59) && this.value.indexOf(":") >= 0)
Event.stop(event);
},
onEnter: function (event) {
this.mouseInside = true;
this.disposeHandler.stop();
},
onLeave: function (event) {
this.mouseInside = false;
this.disposeHandler.start();
},
onDispose: function (event) {
if (!this.mouseInside) {
this.div.hide();
this.disposeHandler.stop();
Event.stop(event);
}
},
_updateValue: function (force) {
var value = this.hours + ':' + this.minutes;
if (force || value != this.value) {
this.value = value;
this.fire("time:change");
}
}
};
|