Monotone-Parent: d9866f043739db58312281104e3d2147eb8f2b42
Monotone-Revision: 46e206273b36aeb266cafd33197519317f26649e Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2007-05-18T21:03:32 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
parent
31538608ee
commit
acac018430
|
@ -1,236 +1,178 @@
|
|||
if (navigator.vendor == "Apple Computer, Inc." || navigator.vendor == "KDE") { // WebCore/KHTML
|
||||
/*
|
||||
Crossbrowser HTMLElement Prototyping
|
||||
Copyright (C) 2005 Jason Davis, http://www.browserland.org
|
||||
Additional thanks to Brothercake, http://www.brothercake.com
|
||||
Element.addMethods({
|
||||
|
||||
addInterface: function(element, objectInterface) {
|
||||
element = $(element);
|
||||
Object.extend(element, objectInterface);
|
||||
if (element.bind)
|
||||
element.bind();
|
||||
},
|
||||
|
||||
childNodesWithTag: function(element, tagName) {
|
||||
element = $(element);
|
||||
var matchingNodes = new Array();
|
||||
var tagName = tagName.toUpperCase();
|
||||
|
||||
for (var i = 0; i < element.childNodes.length; i++) {
|
||||
if (typeof(element.childNodes[i]) == "object"
|
||||
&& element.childNodes[i].tagName
|
||||
&& element.childNodes[i].tagName.toUpperCase() == tagName)
|
||||
matchingNodes.push(element.childNodes[i]);
|
||||
}
|
||||
|
||||
This code is licensed under the LGPL:
|
||||
http://www.gnu.org/licenses/lgpl.html
|
||||
*/
|
||||
return matchingNodes;
|
||||
},
|
||||
|
||||
(function(c) {
|
||||
for (var i in c)
|
||||
window["HTML" + i + "Element"] = document.createElement(c[ i ]).constructor;
|
||||
})({
|
||||
Html: "html", Head: "head", Link: "link", Title: "title", Meta: "meta",
|
||||
Base: "base", IsIndex: "isindex", Style: "style", Body: "body", Form: "form",
|
||||
Select: "select", OptGroup: "optgroup", Option: "option", Input: "input",
|
||||
TextArea: "textarea", Button: "button", Label: "label", FieldSet: "fieldset",
|
||||
Legend: "legend", UList: "ul", OList: "ol", DList: "dl", Directory: "dir",
|
||||
Menu: "menu", LI: "li", Div: "div", Paragraph: "p", Heading: "h1", Quote: "q",
|
||||
Pre: "pre", BR: "br", BaseFont: "basefont", Font: "font", HR: "hr", Mod: "ins",
|
||||
Anchor: "a", Image: "img", Object: "object", Param: "param", Applet: "applet",
|
||||
Map: "map", Area: "area", Script: "script", Table: "table", TableCaption: "caption",
|
||||
TableCol: "col", TableSection: "tbody", TableRow: "tr", TableCell: "td",
|
||||
FrameSet: "frameset", Frame: "frame", IFrame: "iframe"
|
||||
});
|
||||
|
||||
function HTMLElement() {}
|
||||
//HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__;
|
||||
var HTMLDocument = document.constructor;
|
||||
var HTMLCollection = document.links.constructor;
|
||||
var HTMLOptionsCollection = document.createElement("select").options.constructor;
|
||||
var Text = document.createTextNode("").constructor;
|
||||
//var Node = Text;
|
||||
|
||||
// More efficient for Safari 2
|
||||
function Document() {}
|
||||
function Event() {}
|
||||
function HTMLCollection() {}
|
||||
function HTMLElement() {}
|
||||
function Node() {}
|
||||
Document.prototype = window["[[DOMDocument]]"];
|
||||
Event.prototype = window["[[DOMEvent]]"];
|
||||
HTMLCollection.prototype = window["[[HTMLCollection.prototype]]"];
|
||||
HTMLElement.prototype = window["[[DOMElement.prototype]]"];
|
||||
Node.prototype = window["[[DOMNode.prototype]]"];
|
||||
}
|
||||
|
||||
/* custom extensions to the DOM api */
|
||||
HTMLElement.prototype.addInterface = function(objectInterface) {
|
||||
Object.extend(this, objectInterface);
|
||||
if (this.bind)
|
||||
this.bind();
|
||||
}
|
||||
|
||||
HTMLElement.prototype.childNodesWithTag = function(tagName) {
|
||||
var matchingNodes = new Array();
|
||||
var tagName = tagName.toUpperCase();
|
||||
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
if (typeof(this.childNodes[i]) == "object"
|
||||
&& this.childNodes[i].tagName
|
||||
&& this.childNodes[i].tagName.toUpperCase() == tagName)
|
||||
matchingNodes.push(this.childNodes[i]);
|
||||
}
|
||||
|
||||
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) {
|
||||
getParentWithTagName: function(element, tagName) {
|
||||
element = $(element);
|
||||
var currentElement = element;
|
||||
tagName = tagName.toUpperCase();
|
||||
|
||||
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;
|
||||
while (currentElement
|
||||
&& currentElement.tagName != tagName) {
|
||||
currentElement = currentElement.parentNode;
|
||||
}
|
||||
|
||||
log (str);
|
||||
}
|
||||
return currentElement;
|
||||
},
|
||||
|
||||
HTMLElement.prototype.getSelectedNodes = function() {
|
||||
var selArray = new Array();
|
||||
cascadeLeftOffset: function(element) {
|
||||
element = $(element);
|
||||
var currentElement = element;
|
||||
|
||||
var offset = 0;
|
||||
while (currentElement) {
|
||||
offset += currentElement.offsetLeft;
|
||||
currentElement = currentElement.getParentWithTagName("div");
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
node = this.childNodes.item(i);
|
||||
if (node.nodeType == 1
|
||||
&& isNodeSelected(node))
|
||||
selArray.push(node);
|
||||
return offset;
|
||||
},
|
||||
|
||||
cascadeTopOffset: function(element) {
|
||||
element = $(element);
|
||||
var currentElement = element;
|
||||
var offset = 0;
|
||||
|
||||
var i = 0;
|
||||
while (currentElement
|
||||
&& currentElement instanceof HTMLElement) {
|
||||
offset += currentElement.offsetTop;
|
||||
currentElement = currentElement.parentNode;
|
||||
i++;
|
||||
}
|
||||
|
||||
return offset;
|
||||
},
|
||||
|
||||
dump: function(element, additionalInfo, additionalKeys) {
|
||||
element = $(element);
|
||||
var id = element.getAttribute("id");
|
||||
var nclass = element.getAttribute("class");
|
||||
|
||||
var str = element.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 = element.getAttribute(additionalKeys[i]);
|
||||
if (value)
|
||||
str += "; " + additionalKeys[i] + " = " + value;
|
||||
}
|
||||
|
||||
log (str);
|
||||
},
|
||||
|
||||
getSelectedNodes: function(element) {
|
||||
element = $(element);
|
||||
var selArray = new Array();
|
||||
|
||||
for (var i = 0; i < element.childNodes.length; i++) {
|
||||
node = element.childNodes.item(i);
|
||||
if (node.nodeType == 1
|
||||
&& isNodeSelected(node))
|
||||
selArray.push(node);
|
||||
}
|
||||
|
||||
return selArray;
|
||||
},
|
||||
|
||||
getSelectedNodesId: function(element) {
|
||||
element = $(element);
|
||||
var selArray = new Array();
|
||||
|
||||
for (var i = 0; i < element.childNodes.length; i++) {
|
||||
node = element.childNodes.item(i);
|
||||
if (node.nodeType == 1
|
||||
&& isNodeSelected(node))
|
||||
selArray.push(node.getAttribute("id"));
|
||||
}
|
||||
|
||||
return selArray;
|
||||
},
|
||||
|
||||
onContextMenu: function(element, event) {
|
||||
element = $(element);
|
||||
var popup = element.sogoContextMenu;
|
||||
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(event, document.currentPopupMenu);
|
||||
|
||||
var menuTop = event.pageY;
|
||||
var menuLeft = event.pageX;
|
||||
var heightDiff = (window.innerHeight
|
||||
- (menuTop + popup.offsetHeight));
|
||||
if (heightDiff < 0)
|
||||
menuTop += heightDiff;
|
||||
|
||||
var leftDiff = (window.innerWidth
|
||||
- (menuLeft + popup.offsetWidth));
|
||||
if (leftDiff < 0)
|
||||
menuLeft -= popup.offsetWidth;
|
||||
|
||||
popup.style.top = menuTop + "px;";
|
||||
popup.style.left = menuLeft + "px;";
|
||||
popup.style.visibility = "visible;";
|
||||
|
||||
bodyOnClick = "" + document.body.getAttribute("onclick");
|
||||
document.body.setAttribute("onclick", "onBodyClick(event);");
|
||||
document.currentPopupMenu = popup;
|
||||
},
|
||||
|
||||
attachMenu: function(element, menuName) {
|
||||
element = $(element);
|
||||
element.sogoContextMenu = $(menuName);
|
||||
element.addEventListener("contextmenu", element.onContextMenu, true);
|
||||
},
|
||||
|
||||
select: function(element) {
|
||||
element = $(element);
|
||||
element.addClassName('_selected');
|
||||
},
|
||||
|
||||
deselect: function(element) {
|
||||
element = $(element);
|
||||
element.removeClassName('_selected');
|
||||
},
|
||||
|
||||
deselectAll: function(element) {
|
||||
element = $(element);
|
||||
var nodes;
|
||||
if (element.tagName == 'TABLE')
|
||||
nodes = element.getSelectedRows();
|
||||
else
|
||||
nodes = element.childNodes;
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes.item(i);
|
||||
if (node.nodeType == 1)
|
||||
node.deselect();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
HTMLElement.prototype.onContextMenu = function(event) {
|
||||
var popup = this.sogoContextMenu;
|
||||
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(event, document.currentPopupMenu);
|
||||
|
||||
var menuTop = event.pageY;
|
||||
var menuLeft = event.pageX;
|
||||
var heightDiff = (window.innerHeight
|
||||
- (menuTop + popup.offsetHeight));
|
||||
if (heightDiff < 0)
|
||||
menuTop += heightDiff;
|
||||
|
||||
var leftDiff = (window.innerWidth
|
||||
- (menuLeft + popup.offsetWidth));
|
||||
if (leftDiff < 0)
|
||||
menuLeft -= popup.offsetWidth;
|
||||
|
||||
popup.style.top = menuTop + "px;";
|
||||
popup.style.left = menuLeft + "px;";
|
||||
popup.style.visibility = "visible;";
|
||||
|
||||
bodyOnClick = "" + document.body.getAttribute("onclick");
|
||||
document.body.setAttribute("onclick", "onBodyClick(event);");
|
||||
document.currentPopupMenu = popup;
|
||||
}
|
||||
|
||||
HTMLElement.prototype.attachMenu = function(menuName) {
|
||||
this.sogoContextMenu = $(menuName);
|
||||
this.addEventListener("contextmenu", this.onContextMenu, true);
|
||||
}
|
||||
|
||||
HTMLElement.prototype.select = function() {
|
||||
this.addClassName('_selected');
|
||||
}
|
||||
|
||||
HTMLElement.prototype.deselect = function() {
|
||||
this.removeClassName('_selected');
|
||||
}
|
||||
|
||||
HTMLElement.prototype.deselectAll = function () {
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
var node = this.childNodes.item(i);
|
||||
if (node.nodeType == 1)
|
||||
node.deselect();
|
||||
}
|
||||
}
|
||||
}); // Element.addMethods
|
||||
|
|
|
@ -1,75 +1,61 @@
|
|||
HTMLInputElement.prototype._replicate = function() {
|
||||
if (this.replica) {
|
||||
this.replica.value = this.value;
|
||||
Form.Element.Methods._replicate = function(element) {
|
||||
element = $(element);
|
||||
if (element.replica) {
|
||||
element.replica.value = $F(element);
|
||||
var onReplicaChangeEvent = document.createEvent("UIEvents");
|
||||
onReplicaChangeEvent.initEvent("change", true, true);
|
||||
this.replica.dispatchEvent(onReplicaChangeEvent);
|
||||
element.replica.dispatchEvent(onReplicaChangeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
HTMLInputElement.prototype.assignReplica = function(otherInput) {
|
||||
if (!this._onChangeBound) {
|
||||
this.addEventListener("change", this._replicate, false);
|
||||
this._onChangeBound = true;
|
||||
Form.Element.Methods.assignReplica = function(element, otherInput) {
|
||||
element = $(element);
|
||||
if (!element._onChangeBound) {
|
||||
element.addEventListener("change", element._replicate, false);
|
||||
element._onChangeBound = true;
|
||||
}
|
||||
this.replica = otherInput;
|
||||
element.replica = otherInput;
|
||||
}
|
||||
|
||||
HTMLInputElement.prototype.valueAsDate = function () {
|
||||
return this.value.asDate();
|
||||
Form.Element.Methods.valueAsDate = function(element) {
|
||||
return $F(element).asDate();
|
||||
}
|
||||
|
||||
HTMLInputElement.prototype.setValueAsDate = function(dateValue) {
|
||||
if (!this.dateSeparator)
|
||||
this._detectDateSeparator();
|
||||
this.value = dateValue.stringWithSeparator(this.dateSeparator);
|
||||
Form.Element.Methods.setValueAsDate = function(element, dateValue) {
|
||||
element = $(element);
|
||||
if (!element.dateSeparator)
|
||||
element._detectDateSeparator();
|
||||
element.value = dateValue.stringWithSeparator(element.dateSeparator);
|
||||
}
|
||||
|
||||
HTMLInputElement.prototype.updateShadowValue = function () {
|
||||
this.setAttribute("shadow-value", this.value);
|
||||
Form.Element.Methods.updateShadowValue = function(element) {
|
||||
element = $(element);
|
||||
element.setAttribute("shadow-value", $F(element));
|
||||
}
|
||||
|
||||
HTMLInputElement.prototype._detectDateSeparator = function() {
|
||||
var date = this.value.split("/");
|
||||
Form.Element.Methods._detectDateSeparator = function(element) {
|
||||
element = $(element);
|
||||
var date = $F(element).split("/");
|
||||
if (date.length == 3)
|
||||
this.dateSeparator = "/";
|
||||
element.dateSeparator = "/";
|
||||
else
|
||||
this.dateSeparator = "-";
|
||||
element.dateSeparator = "-";
|
||||
}
|
||||
|
||||
HTMLInputElement.prototype.valueAsShortDateString = function() {
|
||||
Form.Element.Methods.valueAsShortDateString = function(element) {
|
||||
element = $(element);
|
||||
var dateStr = '';
|
||||
|
||||
if (!this.dateSeparator)
|
||||
this._detectDateSeparator();
|
||||
|
||||
var date = this.value.split(this.dateSeparator);
|
||||
if (this.dateSeparator == '/')
|
||||
|
||||
if (!element.dateSeparator)
|
||||
element._detectDateSeparator();
|
||||
|
||||
var date = $F(element).split(element.dateSeparator);
|
||||
if (element.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("UIEvents");
|
||||
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);
|
||||
}
|
||||
Element.addMethods();
|
||||
|
|
|
@ -1,28 +1,41 @@
|
|||
HTMLTableElement.prototype.getSelectedRows = function() {
|
||||
var tbody = (this.getElementsByTagName('tbody'))[0];
|
||||
Element.addMethods({
|
||||
|
||||
return tbody.getSelectedNodes();
|
||||
}
|
||||
getSelectedRows: function(element) {
|
||||
element = $(element);
|
||||
if (element.tagName == 'TABLE') {
|
||||
var tbody = (element.getElementsByTagName('tbody'))[0];
|
||||
|
||||
return tbody.getSelectedNodes();
|
||||
}
|
||||
else if (element.tagName == 'UL') {
|
||||
return element.getSelectedNodes();
|
||||
}
|
||||
},
|
||||
|
||||
HTMLTableElement.prototype.getSelectedRowsId = function() {
|
||||
var tbody = (this.getElementsByTagName('tbody'))[0];
|
||||
getSelectedRowsId: function(element) {
|
||||
element = $(element);
|
||||
if (element.tagName == 'TABLE') {
|
||||
var tbody = (element.getElementsByTagName('tbody'))[0];
|
||||
|
||||
return tbody.getSelectedNodesId();
|
||||
}
|
||||
else if (element.tagName == 'UL') {
|
||||
return element.getSelectedNodesId();
|
||||
}
|
||||
},
|
||||
|
||||
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
|
||||
&& node.hasClassName(className))
|
||||
node.select();
|
||||
selectRowsMatchingClass: function(element, className) {
|
||||
element = $(element);
|
||||
if (element.tagName == 'TABLE') {
|
||||
var tbody = (element.getElementsByTagName('tbody'))[0];
|
||||
var nodes = tbody.childNodes;
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes.item(i);
|
||||
if (node instanceof HTMLElement
|
||||
&& node.hasClassName(className))
|
||||
node.select();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HTMLTableElement.prototype.deselectAll = function() {
|
||||
var nodes = this.getSelectedRows();
|
||||
for (var i = 0; i < nodes.length; i++)
|
||||
nodes[i].deselect();
|
||||
}
|
||||
}); // Element.addMethods
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
HTMLUListElement.prototype.getSelectedRows = function() {
|
||||
return this.getSelectedNodes();
|
||||
}
|
||||
|
||||
HTMLUListElement.prototype.getSelectedRowsId = function() {
|
||||
return this.getSelectedNodesId();
|
||||
}
|
||||
//HTMLUListElement.prototype.getSelectedRows = function() {
|
||||
// return this.getSelectedNodes();
|
||||
//}
|
||||
//
|
||||
//HTMLUListElement.prototype.getSelectedRowsId = function() {
|
||||
// return this.getSelectedNodesId();
|
||||
//}
|
||||
|
|
Loading…
Reference in a new issue