sogo/UI/WebServerResources/HTMLInputElement.js
Wolfgang Sourdeau 0885f51b6f Monotone-Parent: b71cb031b6d81c362bbb5a411baf4cd30bcf1b01
Monotone-Revision: f0e01017c45580ffb00a3ec0ea376689e815bd26

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2006-11-07T16:13:03
Monotone-Branch: ca.inverse.sogo
2006-11-07 16:13:03 +00:00

76 lines
2.1 KiB
JavaScript

HTMLInputElement.prototype._replicate = function() {
if (this.replica) {
this.replica.value = this.value;
var onReplicaChangeEvent = document.createEvent("Event");
onReplicaChangeEvent.initEvent("change", true, true);
this.replica.dispatchEvent(onReplicaChangeEvent);
}
}
HTMLInputElement.prototype.assignReplica = function(otherInput) {
if (!this._onChangeBound) {
this.addEventListener("change", this._replicate, false);
this._onChangeBound = true;
}
this.replica = otherInput;
}
HTMLInputElement.prototype.valueAsDate = function () {
return this.value.asDate();
}
HTMLInputElement.prototype.setValueAsDate = function(dateValue) {
if (!this.dateSeparator)
this._detectDateSeparator();
this.value = dateValue.stringWithSeparator(this.dateSeparator);
}
HTMLInputElement.prototype.updateShadowValue = function () {
this.setAttribute("shadow-value", this.value);
}
HTMLInputElement.prototype._detectDateSeparator = function() {
var date = this.value.split("/");
if (date.length == 3)
this.dateSeparator = "/";
else
this.dateSeparator = "-";
}
HTMLInputElement.prototype.valueAsShortDateString = function() {
var dateStr = '';
if (!this.dateSeparator)
this._detectDateSeparator();
var date = this.value.split(this.dateSeparator);
if (this.dateSeparator == '/')
dateStr += date[2] + date[1] + date[0];
else
dateStr += date[0] + date[1] + date[2];
return dateStr;
}
/* "select" is part of the inputs so it's included here */
HTMLSelectElement.prototype._replicate = function() {
if (this.replica) {
this.replica.value = this.value;
var onReplicaChangeEvent = document.createEvent("Event");
onReplicaChangeEvent.initEvent("change", true, true);
this.replica.dispatchEvent(onReplicaChangeEvent);
}
}
HTMLSelectElement.prototype.assignReplica = function(otherSelect) {
if (!this._onChangeBound) {
this.addEventListener("change", this._replicate, false);
this._onChangeBound = true;
}
this.replica = otherSelect;
}
HTMLSelectElement.prototype.updateShadowValue = function () {
this.setAttribute("shadow-value", this.value);
}