mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-26 22:05:23 +00:00
Monotone-Parent: d945e377de4cef58cd3319068ed383074d42b243
Monotone-Revision: 02b28f2db3113bf19ebb8c67799e466346406b49 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2006-11-01T20:28:35 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
/* custom extensions to the DOM api */
|
||||
HTMLElement.prototype.childNodesWithTag = function(tagName) {
|
||||
var matchingNodes = new Array();
|
||||
var tagName = tagName.toUpperCase();
|
||||
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
// log("(" + tagName + ") childNodes " + i + " = " + this.childNodes[i]);
|
||||
if (typeof(this.childNodes[i]) == "object"
|
||||
&& this.childNodes[i].tagName
|
||||
&& this.childNodes[i].tagName.toUpperCase() == tagName)
|
||||
matchingNodes.push(this.childNodes[i]);
|
||||
}
|
||||
|
||||
// log ("matching: " + matchingNodes.length);
|
||||
|
||||
return matchingNodes;
|
||||
}
|
||||
|
||||
HTMLElement.prototype.addClassName = function(className) {
|
||||
var classStr = '' + this.getAttribute("class");
|
||||
|
||||
position = classStr.indexOf(className, 0);
|
||||
if (position < 0) {
|
||||
classStr = classStr + ' ' + className;
|
||||
this.setAttribute('class', classStr);
|
||||
}
|
||||
}
|
||||
|
||||
HTMLElement.prototype.removeClassName = function(className) {
|
||||
var classStr = '' + this.getAttribute('class');
|
||||
|
||||
position = classStr.indexOf(className, 0);
|
||||
while (position > -1) {
|
||||
classStr1 = classStr.substring(0, position);
|
||||
classStr2 = classStr.substring(position + 10, classStr.length);
|
||||
classStr = classStr1 + classStr2;
|
||||
position = classStr.indexOf(className, 0);
|
||||
}
|
||||
|
||||
this.setAttribute('class', classStr);
|
||||
}
|
||||
|
||||
HTMLElement.prototype.hasClassName = function(className) {
|
||||
var classStr = '' + this.getAttribute('class');
|
||||
position = classStr.indexOf(className, 0);
|
||||
return (position > -1);
|
||||
}
|
||||
|
||||
HTMLElement.prototype.getParentWithTagName = function(tagName) {
|
||||
var currentElement = this;
|
||||
tagName = tagName.toUpperCase();
|
||||
|
||||
currentElement = currentElement.parentNode;
|
||||
while (currentElement
|
||||
&& currentElement.tagName != tagName) {
|
||||
currentElement = currentElement.parentNode;
|
||||
}
|
||||
|
||||
return currentElement;
|
||||
}
|
||||
|
||||
HTMLElement.prototype.cascadeLeftOffset = function() {
|
||||
var currentElement = this;
|
||||
|
||||
var offset = 0;
|
||||
while (currentElement) {
|
||||
offset += currentElement.offsetLeft;
|
||||
currentElement = currentElement.getParentWithTagName("div");
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
HTMLElement.prototype.cascadeTopOffset = function() {
|
||||
var currentElement = this;
|
||||
var offset = 0;
|
||||
|
||||
var i = 0;
|
||||
|
||||
while (currentElement
|
||||
&& currentElement instanceof HTMLElement) {
|
||||
offset += currentElement.offsetTop;
|
||||
currentElement = currentElement.parentNode;
|
||||
i++;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
HTMLElement.prototype.dump = function(additionalInfo, additionalKeys) {
|
||||
var id = this.getAttribute("id");
|
||||
var nclass = this.getAttribute("class");
|
||||
|
||||
var str = this.tagName;
|
||||
if (id)
|
||||
str += "; id = " + id;
|
||||
if (nclass)
|
||||
str += "; class = " + nclass;
|
||||
|
||||
if (additionalInfo)
|
||||
str += "; " + additionalInfo;
|
||||
|
||||
if (additionalKeys)
|
||||
for (var i = 0; i < additionalKeys.length; i++) {
|
||||
var value = this.getAttribute(additionalKeys[i]);
|
||||
if (value)
|
||||
str += "; " + additionalKeys[i] + " = " + value;
|
||||
}
|
||||
|
||||
log (str);
|
||||
}
|
||||
|
||||
HTMLElement.prototype.getSelectedNodes = function() {
|
||||
var selArray = new Array();
|
||||
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
node = this.childNodes.item(i);
|
||||
if (node.nodeType == 1
|
||||
&& isNodeSelected(node))
|
||||
selArray.push(node);
|
||||
}
|
||||
|
||||
return selArray;
|
||||
}
|
||||
|
||||
HTMLElement.prototype.getSelectedNodesId = function() {
|
||||
var selArray = new Array();
|
||||
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
node = this.childNodes.item(i);
|
||||
if (node.nodeType == 1
|
||||
&& isNodeSelected(node))
|
||||
selArray.push(node.getAttribute("id"));
|
||||
}
|
||||
|
||||
return selArray;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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 () {
|
||||
var newDate;
|
||||
var date = this.value.split("/");
|
||||
if (date.length == 3)
|
||||
newDate = new Date(date[2], date[1] - 1, date[0]);
|
||||
else {
|
||||
date = this.value.split("-");
|
||||
newDate = new Date(date[0], date[1] - 1, date[2]);
|
||||
}
|
||||
|
||||
return newDate;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
HTMLTableElement.prototype.getSelectedRows = function() {
|
||||
var tbody = (this.getElementsByTagName('tbody'))[0];
|
||||
|
||||
return tbody.getSelectedNodes();
|
||||
}
|
||||
|
||||
HTMLTableElement.prototype.getSelectedRowsId = function() {
|
||||
var tbody = (this.getElementsByTagName('tbody'))[0];
|
||||
|
||||
return tbody.getSelectedNodesId();
|
||||
}
|
||||
|
||||
HTMLTableElement.prototype.selectRowsMatchingClass = function(className) {
|
||||
var tbody = (this.getElementsByTagName('tbody'))[0];
|
||||
var nodes = tbody.childNodes;
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes.item(i);
|
||||
if (node instanceof HTMLElement) {
|
||||
var classStr = '' + node.getAttribute("class");
|
||||
if (classStr.indexOf(className, 0) >= 0)
|
||||
selectNode(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HTMLTableElement.prototype.deselectAll = function() {
|
||||
var nodes = this.getSelectedRows();
|
||||
for (var i = 0; i < nodes.length; i++)
|
||||
deselectNode(nodes[i]);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
HTMLUListElement.prototype.getSelectedRows = function() {
|
||||
return this.getSelectedNodes();
|
||||
}
|
||||
|
||||
HTMLUListElement.prototype.getSelectedRowsId = function() {
|
||||
return this.getSelectedNodesId();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
String.prototype.trim = function() {
|
||||
return this.replace(/(^\s+|\s+$)/g, '');
|
||||
}
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
return this.replace(/\w+/g,
|
||||
function(a) {
|
||||
return ( a.charAt(0).toUpperCase()
|
||||
+ a.substr(1).toLowerCase() );
|
||||
});
|
||||
}
|
||||
|
||||
String.prototype.decodeEntities = function() {
|
||||
return this.replace(/&#(\d+);/g,
|
||||
function(wholematch, parenmatch1) {
|
||||
return String.fromCharCode(+parenmatch1);
|
||||
});
|
||||
}
|
||||
|
||||
Date.prototype.sogoDayName = function() {
|
||||
var dayName = "";
|
||||
|
||||
var day = this.getDay();
|
||||
if (day == 0) {
|
||||
dayName = labels['a2_Sunday'];
|
||||
} else if (day == 1) {
|
||||
dayName = labels['a2_Monday'];
|
||||
} else if (day == 2) {
|
||||
dayName = labels['a2_Tuesday'];
|
||||
} else if (day == 3) {
|
||||
dayName = labels['a2_Wednesday'];
|
||||
} else if (day == 4) {
|
||||
dayName = labels['a2_Thursday'];
|
||||
} else if (day == 5) {
|
||||
dayName = labels['a2_Friday'];
|
||||
} else if (day == 6) {
|
||||
dayName = labels['a2_Saturday'];
|
||||
}
|
||||
|
||||
return dayName;
|
||||
}
|
||||
|
||||
Date.prototype.daysUpTo = function(otherDate) {
|
||||
var days = new Array();
|
||||
var day1 = this.getTime();
|
||||
var day2 = otherDate.getTime();
|
||||
|
||||
var nbrDays = Math.floor((day2 - day1) / 86400000) + 1;
|
||||
for (var i = 0; i < nbrDays; i++) {
|
||||
var newDate = new Date();
|
||||
newDate.setTime(day1 + (i * 86400000));
|
||||
days.push(newDate);
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
Date.prototype.sogoFreeBusyStringWithSeparator = function(separator) {
|
||||
var str = this.sogoDayName() + ", ";
|
||||
if (separator == '-')
|
||||
str += (this.getYear() + 1900) + '-' + (this.getMonth() + 1) + '-' + this.getDate();
|
||||
else
|
||||
str += this.getDate() + '/' + (this.getMonth() + 1) + '/' + (this.getYear() + 1900);
|
||||
|
||||
return str;
|
||||
}
|
||||
Reference in New Issue
Block a user