40 "DOMEventListenerSet",
50 const Cc = Components.classes;
51 const Ci = Components.interfaces;
52 const Cr = Components.results
53 const Cu = Components.utils
78 loadDocument:
function DOMUtils_loadDocument(aDocumentURI) {
80 var ioSvc =
Cc[
"@mozilla.org/network/io-service;1"]
81 .getService(
Ci.nsIIOService);
82 var channel = ioSvc.newChannel(aDocumentURI,
null,
null);
83 var inputStream = channel.open();
86 var domParser =
Cc[
"@mozilla.org/xmlextras/domparser;1"]
87 .createInstance(
Ci.nsIDOMParser);
88 return domParser.parseFromStream(inputStream,
90 channel.contentLength,
114 importChildElements:
function DOMUtils_importChildElements(aDstNode,
119 var dstDoc = aDstNode.ownerDocument;
120 var srcChildList = aSrcDocument.getElementById(aSrcParentID).childNodes;
123 for (var
i = 0;
i < srcChildList.length;
i++) {
125 var srcChild = srcChildList[
i];
126 if (srcChild.nodeType !=
Ci.nsIDOMNode.ELEMENT_NODE)
130 var dstChild = dstDoc.importNode(srcChild,
true);
133 aDstNode.appendChild(dstChild);
136 for (var attrName in aChildAttrList) {
137 dstChild.setAttribute(attrName, aChildAttrList[attrName]);
157 copyAttributes:
function DOMUtils_copyAttributes(aSrcElem,
162 for (var
i = 0;
i < aAttributeList.length;
i++) {
164 var attribute = aAttributeList[
i];
168 if (!aSrcElem.hasAttribute(attribute)) {
169 if (aRemoveAttributes)
170 aDstElem.removeAttribute(attribute);
176 var srcAttributeVal = aSrcElem.getAttribute(attribute);
177 var dstAttributeVal = aDstElem.getAttribute(attribute);
178 if (srcAttributeVal != dstAttributeVal)
179 aDstElem.setAttribute(attribute, srcAttributeVal);
198 getElementsByAttribute:
function DOMUtils_getElementsByAttribute(aRootElem,
203 this._getElementsByAttribute(aRootElem, aAttrName, aAttrValue, matchList);
208 _getElementsByAttribute:
function
209 DOMUtils__getElementsByAttribute(aRootElem,
214 var childList = aRootElem.childNodes;
215 for (var
i = 0;
i < childList.length;
i++) {
217 var child = childList[
i];
218 if (child.hasAttributes() && child.hasAttribute(aAttrName)) {
219 if (!aAttrValue || (child.getAttribute(aAttrName) == aAttrValue))
220 aMatchList.push(child);
224 this._getElementsByAttribute(child, aAttrName, aAttrValue, aMatchList);
238 encodeTextForXML:
function DOMUtils_encodeTextForXML(aText) {
240 var xmlDocument =
Cc[
"@mozilla.org/xml/xml-document;1"]
241 .createInstance(
Ci.nsIDOMDocument);
242 var xmlTextNode = xmlDocument.createTextNode(aText);
245 var domSerializer =
Cc[
"@mozilla.org/xmlextras/xmlserializer;1"]
246 .createInstance(
Ci.nsIDOMSerializer);
247 var encodedXMLText = domSerializer.serializeToString(xmlTextNode);
249 return encodedXMLText;
265 rebindXBL:
function DOMUtils_rebindXBL(aElem) {
268 aElem.cloneNode(
false);
286 setClass:
function DOMUtils_setClass(aElem, aClass) {
288 var classAttr = aElem.getAttribute(
"class");
290 aElem.setAttribute(
"class", aClass);
295 var classList = classAttr.split(
" ");
296 if (classList.indexOf(aClass) < 0) {
297 classList.push(aClass);
298 aElem.setAttribute(
"class", classList.join(
" "));
311 clearClass:
function DOMUtils_clearClass(aElem, aClass) {
313 var classAttr = aElem.getAttribute(
"class");
318 var classList = classAttr.split(
" ");
319 var classCount = classList.length;
320 for (var
i = classCount - 1;
i >= 0;
i--) {
321 if (classList[
i] == aClass)
322 classList.splice(
i, 1);
324 if (classList.length < classCount)
325 aElem.setAttribute(
"class", classList.join(
" "));
339 isClassSet:
function DOMUtils_isClassSet(aElem, aClass) {
340 var classAttr = aElem.getAttribute(
"class");
341 var classList = classAttr.split(
" ");
342 if (classList.indexOf(aClass) < 0)
380 addNodeDestroyFunc:
function DOMUtils_addNodeDestroyFunc(aNode,
383 if (!aNode.destroyFuncList)
384 aNode.destroyFuncList = [];
387 aNode.destroyFuncList.push(aFunc);
398 destroyNode:
function DOMUtils_destroyNode(aNode) {
400 if (aNode.nodeType !=
Ci.nsIDOMNode.ELEMENT_NODE)
404 var nodeDocument = aNode.ownerDocument;
405 this.destroyNodeList(nodeDocument.getAnonymousNodes(aNode));
406 this.destroyNodeList(aNode.childNodes);
409 while (aNode.destroyFuncList) {
411 var destroyFunc = aNode.destroyFuncList.pop();
415 var
msg =
"Exception: " + ex +
416 " at " + ex.fileName +
417 ", line " + ex.lineNumber;
422 if (!aNode.destroyFuncList.length)
423 aNode.destroyFuncList =
null;
434 destroyNodeList:
function DOMUtils_destroyNodeList(aNodeList) {
438 for (var
i = 0;
i < aNodeList.length;
i++) {
439 this.destroyNode(aNodeList[
i]);
499 if (attribute ==
"class") {
508 var blinkDuration = aBlinkDuration;
510 blinkDuration = this.defaultBlinkDuration;
514 this._element = aElement;
516 this._attribute = attribute;
517 this._blinkDuration = blinkDuration;
550 function sbDOMHighlighter_highlightElement(aWindow,
580 defaultBlinkDuration: 2000,
602 _domEventListenerSet:
null,
605 _isHighlighted:
false,
612 start:
function sbDOMHighlighter_start() {
620 func =
function _onClickWrapper() {
self._onClick(); };
621 this._domEventListenerSet.add(this._element.ownerDocument,
626 func =
function _onUnloadWrapper() {
self._onUnload(); };
627 this._domEventListenerSet.add(this.
_window,
"unload", func,
false);
634 this._blinkStart = Date.now();
636 var func =
function _blinkWrapper() {
self._blink(); };
637 this._blinkTimer =
Cc[
"@mozilla.org/timer;1"].createInstance(
Ci.nsITimer);
638 this._blinkTimer.initWithCallback(func,
640 Ci.nsITimer.TYPE_REPEATING_SLACK);
648 cancel:
function sbDOMHighlighter_cancel() {
650 if (this._domEventListenerSet)
651 this._domEventListenerSet.removeAll();
654 if (this._blinkTimer)
655 this._blinkTimer.cancel();
658 this._element =
null;
659 this._domEventListenerSet =
null;
660 this._blinkTimer =
null;
668 setHighlight:
function sbDOMHighlighter_setHighlight() {
670 if (this._attribute ==
"class") {
671 DOMUtils.setClass(this._element, this._value);
674 this._element.setAttribute(this._attribute, this._value);
678 this._isHighlighted =
true;
686 clearHighlight:
function sbDOMHighlighter_clearHighlight() {
688 if (this._attribute ==
"class") {
689 DOMUtils.clearClass(this._element, this._value);
692 this._element.removeAttribute(this._attribute);
696 this._isHighlighted =
false;
710 _blink:
function sbDOMHighlighter__blink() {
713 var blinkTime = Date.now() - this._blinkStart;
714 if (blinkTime >= this._blinkDuration) {
715 this._blinkTimer.cancel();
716 this._blinkTimer =
null;
722 if (this._isHighlighted) {
723 this.clearHighlight();
735 _onClick:
function sbDOMHighlighter__onClick() {
737 this.clearHighlight();
746 _onUnload:
function sbDOMHighlighter__onUnload() {
769 this._eventListenerList = {};
784 _eventListenerList:
null,
785 _nextEventListenerID: 0,
806 add:
function DOMEventListenerSet_add(aElement,
813 var eventListener = {};
814 eventListener.id = this._nextEventListenerID++;
815 eventListener.element = aElement;
816 eventListener.type = aType;
817 eventListener.listener = aListener;
818 eventListener.useCapture = aUseCapture;
819 eventListener.oneShot = aOneShot;
820 eventListener.wantsUntrusted = aWantsUntrusted ==
true ?
true :
false;
823 var listenerFunc = eventListener.listener;
824 if (eventListener.oneShot) {
827 function(aEvent) {
return _this._doOneShot(aEvent, eventListener); };
829 eventListener.addedListener = listenerFunc;
832 eventListener.element.addEventListener(eventListener.type,
833 eventListener.addedListener,
834 eventListener.useCapture,
835 eventListener.wantsUntrusted);
836 this._eventListenerList[eventListener.id] = eventListener;
838 return (eventListener.id);
848 remove:
function DOMEventListenerSet_remove(aEventListenerID) {
850 var eventListener = this._eventListenerList[aEventListenerID];
855 eventListener.element.removeEventListener(eventListener.type,
856 eventListener.addedListener,
857 eventListener.useCapture);
858 delete this._eventListenerList[aEventListenerID];
866 removeAll:
function DOMEventListenerSet_removeAll() {
868 for (var
id in this._eventListenerList) {
871 this._eventListenerList = {};
889 _doOneShot:
function DOMEventListenerSet__doOneShot(aEvent, aEventListener) {
891 if (aEventListener.oneShot)
892 this.
remove(aEventListener.id);
895 return aEventListener.listener(aEvent);
926 getColorFromCSSColor:
function sbColorUtils_getCSSColor(aCSSColor) {
928 var rgba = aCSSColor.match(/^rgba?\((.*)\)/)
929 if (!rgba || (rgba.length < 2))
934 rgba = rgba.split(
",");
940 red: parseFloat(rgba[0]) / 255.0,
941 green: parseFloat(rgba[1]) / 255.0,
942 blue: parseFloat(rgba[2]) / 255.0
945 color.alpha = parseFloat(rgba[3])
962 getDOMColorString:
function sbColorUtils_getDOMColorString(aColor) {
964 var red = Math.round(aColor.red * 255.0);
965 var green = Math.round(aColor.green * 255.0);
966 var blue = Math.round(aColor.blue * 255.0);
969 var colorValue = (red << 16) | (green << 8) | blue;
973 var colorString = (0x01000000 + colorValue).toString(16);
974 colorString =
"#" + colorString.slice(1);
function sbDOMHighlighter(aWindow, aElement, aValue, aAttribute, aBlinkDuration)
function DOMEventListenerSet()
ui plugin add("draggable","cursor",{start:function(e, ui){var t=$('body');if(t.css("cursor")) ui.options._cursor=t.css("cursor");t.css("cursor", ui.options.cursor);}, stop:function(e, ui){if(ui.options._cursor)$('body').css("cursor", ui.options._cursor);}})
DOMEventListenerSet prototype constructor
_getWindowDimension aAttribute
_getSelectedPageStyle s i