From c3f362e796b43eb46cd6bf6fae06b968eb2ac059 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 23 May 2017 01:38:52 +0400 Subject: [PATCH] fix tests failing on phantomjs --- .../build_support/mini_require.js | 4 +- plugins/c9.ide.find.replace/libsearch.js | 8 +- plugins/c9.ide.run.debug/data/data.js | 2 +- plugins/c9.ide.ui/lib/page.js | 1 - plugins/c9.ide.ui/lib_apf.js | 337 ++++++------------ plugins/c9.ide.ui/tooltip.js | 5 +- 6 files changed, 123 insertions(+), 234 deletions(-) diff --git a/node_modules/architect-build/build_support/mini_require.js b/node_modules/architect-build/build_support/mini_require.js index 06a60e91..d08dfe93 100644 --- a/node_modules/architect-build/build_support/mini_require.js +++ b/node_modules/architect-build/build_support/mini_require.js @@ -512,7 +512,7 @@ function checkCache() { config.useCache = ideCachePromiss = ideCache = null; }).then(function(ideCache_) { ideCache = ideCache_; - return ideCache.keys(); + return ideCache ? ideCache.keys() : []; }).then(function(keys) { baseUrl = config.baseUrl; if (baseUrl[0] == "/") @@ -525,7 +525,7 @@ function checkCache() { return ""; return r.headers.get("etag") + " " + url; }).join("\n") + "\n"; - if (val.length == 1) { + if (val.length <= 1) { ideCachePromiss = null; return ideCache; } diff --git a/plugins/c9.ide.find.replace/libsearch.js b/plugins/c9.ide.find.replace/libsearch.js index bbb36f3c..e2fd0cd8 100644 --- a/plugins/c9.ide.find.replace/libsearch.js +++ b/plugins/c9.ide.find.replace/libsearch.js @@ -1,8 +1,4 @@ -/** - * Search Helper Library for the Cloud9 - * - * @copyright 2013, Ajax.org B.V. - */ +/*global apf*/ define(function(require, exports, module) { @@ -139,7 +135,7 @@ module.exports = function(settings, execFind, toggleDialog, restore, toggleOptio } catch (e) { tooltip.$ext.innerHTML = apf.escapeXML(e.message.replace(": /" + searchTxt + "/", "")); - apf.setOpacity(tooltip.$ext, 1); + tooltip.$ext.style.opacity = 1; var pos = apf.getAbsolutePosition(win.$ext); tooltip.$ext.style.left = pos[0] + txtFind.getLeft() + "px"; diff --git a/plugins/c9.ide.run.debug/data/data.js b/plugins/c9.ide.run.debug/data/data.js index 9a742052..8eb05cf9 100644 --- a/plugins/c9.ide.run.debug/data/data.js +++ b/plugins/c9.ide.run.debug/data/data.js @@ -45,7 +45,7 @@ define(function(require, exports, module) { this.data = v; }, toString: function() { - return this.xml; + return this.json; } }; diff --git a/plugins/c9.ide.ui/lib/page.js b/plugins/c9.ide.ui/lib/page.js index 25ea879f..04fabb7f 100644 --- a/plugins/c9.ide.ui/lib/page.js +++ b/plugins/c9.ide.ui/lib/page.js @@ -1527,7 +1527,6 @@ apf.BaseTab = function() { //Skin changing support if (this.$int) { - //apf.AmlParser.replaceNode(this.oPages, oPages); this.$int = this.oPages; page = true; diff --git a/plugins/c9.ide.ui/lib_apf.js b/plugins/c9.ide.ui/lib_apf.js index 2525b29e..d7d24991 100644 --- a/plugins/c9.ide.ui/lib_apf.js +++ b/plugins/c9.ide.ui/lib_apf.js @@ -2377,7 +2377,7 @@ apf.plane = { var toOpacity = parseFloat(options && options.opacity) || 1; if (this.animate) { var _self = this; - apf.setOpacity(this.plane, 0); + this.plane.style.opacity = 0; setTimeout(function(){ apf.tween.single(_self.plane, { steps: 5, @@ -2389,7 +2389,7 @@ apf.plane = { }, 100); } else - apf.setOpacity(this.plane, toOpacity); + this.plane.style.opacity = toOpacity; var diff = apf.getDiff(plane); this.plane.style.width = "100%";//(pWidth - diff[0]) + "px"; @@ -2421,7 +2421,7 @@ apf.plane = { steps: 5, interval: 10, type: "fade", - from: apf.getOpacity(_self.plane), + from: apf.getStyle(_self.plane, "opacity"), to: 0, onfinish: function(){ _self.plane.style.display = "none"; @@ -2433,7 +2433,7 @@ apf.plane = { }, 100); } else { - apf.setOpacity(this.plane, 0); + this.plane.style.opacity = 0; if (this.current) apf.window.zManager.clear(this.plane, this.current); this.plane.style.display = "none"; @@ -8516,7 +8516,6 @@ apf.GuiElement.propHandlers = { // crazy stuff! !function(){ - if (apf.isO3) return; var prot = apf.XhtmlElement.prototype; prot.implement( @@ -12036,9 +12035,6 @@ apf.window = new apf.window(); * @private */ apf.runGecko = function(){ - if (apf.runNonIe) - apf.runNonIe(); - apf.getHtmlLeft = function(oHtml) { return (oHtml.offsetLeft + (parseInt(apf.getStyle(oHtml.parentNode, "borderLeftWidth")) || 0)); @@ -12209,211 +12205,115 @@ function findNodes(htmlNode, textNode, result, re) { +// *** XML Serialization *** // +if (XMLDocument.prototype.__defineGetter__) { + //XMLDocument.xml + XMLDocument.prototype.__defineGetter__("xml", function(){ + return (new XMLSerializer()).serializeToString(this); + }); + XMLDocument.prototype.__defineSetter__("xml", function(){ + throw new Error(apf.formatErrorString(1042, null, "XML serializer", "Invalid assignment on read-only property 'xml'.")); + }); + + //Node.xml + Node.prototype.__defineGetter__("xml", function(){ + if (this.nodeType == 3 || this.nodeType == 4 || this.nodeType == 2) + return this.nodeValue; + return (new XMLSerializer()).serializeToString(this); + }); + + //Node.xml + Element.prototype.__defineGetter__("xml", function(){ + return (new XMLSerializer()).serializeToString(this); + }); +} + +if (typeof HTMLElement!="undefined") { + //HTMLElement.removeNode + HTMLElement.prototype.removeNode = function(){ + if (!this.parentNode) return; + this.parentNode.removeChild(this); + }; +} + +//Document.prototype.onreadystatechange = null; +Document.prototype.parseError = 0; + +defineProp(Array.prototype, "item", function(i){return this[i];}); +defineProp(Array.prototype, "expr", ""); + +Node.prototype.getElementById = function(id) {}; /** - * @private + * This method retrieves the current value of a property on a HTML element + * @param {HTMLElement} el the element to read the property from + * @param {String} prop the property to read + * @returns {String} */ -apf.runNonIe = function (){ - - - DocumentFragment.prototype.getElementById = function(id) { - return this.childNodes.length ? this.childNodes[0].ownerDocument.getElementById(id) : null; - }; - - - - // *** XML Serialization *** // - if (XMLDocument.prototype.__defineGetter__) { - //XMLDocument.xml - XMLDocument.prototype.__defineGetter__("xml", function(){ - return (new XMLSerializer()).serializeToString(this); - }); - XMLDocument.prototype.__defineSetter__("xml", function(){ - throw new Error(apf.formatErrorString(1042, null, "XML serializer", "Invalid assignment on read-only property 'xml'.")); - }); - - //Node.xml - Node.prototype.__defineGetter__("xml", function(){ - if (this.nodeType == 3 || this.nodeType == 4 || this.nodeType == 2) - return this.nodeValue; - return (new XMLSerializer()).serializeToString(this); - }); - - //Node.xml - Element.prototype.__defineGetter__("xml", function(){ - return (new XMLSerializer()).serializeToString(this); - }); - } - - /* ******** HTML Interfaces ************************************************** - insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement() - ****************************************************************************/ - if (typeof HTMLElement!="undefined") { - if (!HTMLElement.prototype.insertAdjacentElement) { - Text.prototype.insertAdjacentElement = - HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode) { - switch (where.toLowerCase()) { - case "beforebegin": - this.parentNode.insertBefore(parsedNode,this); - break; - case "afterbegin": - this.insertBefore(parsedNode,this.firstChild); - break; - case "beforeend": - this.appendChild(parsedNode); - break; - case "afterend": - if (this.nextSibling) - this.parentNode.insertBefore(parsedNode,this.nextSibling); - else - this.parentNode.appendChild(parsedNode); - break; - } - }; - } - - if (!HTMLElement.prototype.insertAdjacentHTML) { - Text.prototype.insertAdjacentHTML = - HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr) { - var r = this.ownerDocument.createRange(); - r.setStartBefore(apf.isWebkit - ? document.body - : (self.document ? document.body : this)); - var parsedHTML = r.createContextualFragment(htmlStr); - this.insertAdjacentElement(where, parsedHTML); - }; - } - - if (!HTMLBodyElement.prototype.insertAdjacentHTML) //apf.isWebkit) - HTMLBodyElement.prototype.insertAdjacentHTML = HTMLElement.prototype.insertAdjacentHTML; - - if (!HTMLElement.prototype.insertAdjacentText) { - Text.prototype.insertAdjacentText = - HTMLElement.prototype.insertAdjacentText = function(where,txtStr) { - var parsedText = document.createTextNode(txtStr); - this.insertAdjacentElement(where,parsedText); - }; - } - - //HTMLElement.removeNode - HTMLElement.prototype.removeNode = function(){ - if (!this.parentNode) return; - - this.parentNode.removeChild(this); - }; - } - - /* ******** XML Compatibility ************************************************ - Giving the Mozilla XML Parser the same interface as IE's Parser - ****************************************************************************/ - var ASYNCNOTSUPPORTED = false; - - //Test if Async is supported - try { - XMLDocument.prototype.async = true; - ASYNCNOTSUPPORTED = true; - } catch (e) {/*trap*/} - - //Document.prototype.onreadystatechange = null; - Document.prototype.parseError = 0; - - defineProp(Array.prototype, "item", function(i){return this[i];}); - defineProp(Array.prototype, "expr", ""); - - Node.prototype.getElementById = function(id) {}; - - HTMLElement.prototype.replaceNode = - Element.prototype.replaceNode = function(xmlNode) { - if (!this.parentNode) return; - - this.parentNode.insertBefore(xmlNode, this); - this.parentNode.removeChild(this); - }; - - - - /** - * This method retrieves the current value of a property on a HTML element - * @param {HTMLElement} el the element to read the property from - * @param {String} prop the property to read - * @returns {String} - */ - var getStyle = apf.getStyle = function(el, prop) { - try{ - return (window.getComputedStyle(el, "") || {})[prop] || ""; - }catch(e) {} - }; - - //XMLDocument.setProperty - HTMLDocument.prototype.setProperty = - XMLDocument.prototype.setProperty = function(x,y) {}; - - /* ******** XML Compatibility ************************************************ - ****************************************************************************/ - apf.getXmlDom = function(message, noError, preserveWhiteSpaces) { - var xmlParser; - if (message) { - if (preserveWhiteSpaces === false) - message = message.replace(/>[\s\n\r]*<"); - - xmlParser = new DOMParser(); - xmlParser = xmlParser.parseFromString(message, "text/xml"); - - - if (!noError) - this.xmlParseError(xmlParser); - } - else { - xmlParser = document.implementation.createDocument("", "", null); - } - - return xmlParser; - }; - - apf.xmlParseError = function(xml) { - //if (xml.documentElement.tagName == "parsererror") { - if (xml.getElementsByTagName("parsererror").length) { - var nodeValue = xml.documentElement.firstChild.nodeValue; - - if (nodeValue != null) { - var str = nodeValue.split("\n"), - linenr = str[2].match(/\w+ (\d+)/)[1], - message = str[0].replace(/\w+ \w+ \w+: (.*)/, "$1"); - } else { - if (nodeValue = xml.documentElement.firstChild.getElementsByTagName('div')[0].firstChild.nodeValue) { - var linenr = nodeValue.match(/line\s(\d*)/)[1] || "N/A", - message = nodeValue.match(/column\s\d*:(.*)/)[1] || "N/A"; - } - else { - var linenr = "N/A", - message = "N/A"; - } - } - - var srcText = xml.documentElement.lastChild.firstChild,//.split("\n")[0]; - srcMsg = ""; - if (srcText && srcText.nodeValue) { - srcMsg = "\nSource Text : " + srcText.nodeValue.replace(/\t/gi, " ") - } - throw new Error(apf.formatErrorString(1050, null, - "XML Parse Error on line " + linenr, message + srcMsg)); - } - - return xml; - }; - - - apf.getOpacity = function(oHtml) { - return apf.getStyle(oHtml, "opacity"); - }; - - apf.setOpacity = function(oHtml, value) { - oHtml.style.opacity = value; - }; +var getStyle = apf.getStyle = function(el, prop) { + try{ + return (window.getComputedStyle(el, "") || {})[prop] || ""; + }catch(e) {} }; +//XMLDocument.setProperty +HTMLDocument.prototype.setProperty = +XMLDocument.prototype.setProperty = function(x,y) {}; +/* ******** XML Compatibility ************************************************ +****************************************************************************/ +apf.getXmlDom = function(message, noError, preserveWhiteSpaces) { + var xmlParser; + if (message) { + if (preserveWhiteSpaces === false) + message = message.replace(/>[\s\n\r]*<"); + + xmlParser = new DOMParser(); + xmlParser = xmlParser.parseFromString(message, "text/xml"); + + + if (!noError) + this.xmlParseError(xmlParser); + } + else { + xmlParser = document.implementation.createDocument("", "", null); + } + + return xmlParser; +}; + +apf.xmlParseError = function(xml) { + //if (xml.documentElement.tagName == "parsererror") { + if (xml.getElementsByTagName("parsererror").length) { + var nodeValue = xml.documentElement.firstChild.nodeValue; + + if (nodeValue != null) { + var str = nodeValue.split("\n"), + linenr = str[2].match(/\w+ (\d+)/)[1], + message = str[0].replace(/\w+ \w+ \w+: (.*)/, "$1"); + } else { + if (nodeValue = xml.documentElement.firstChild.getElementsByTagName('div')[0].firstChild.nodeValue) { + var linenr = nodeValue.match(/line\s(\d*)/)[1] || "N/A", + message = nodeValue.match(/column\s\d*:(.*)/)[1] || "N/A"; + } + else { + var linenr = "N/A", + message = "N/A"; + } + } + + var srcText = xml.documentElement.lastChild.firstChild,//.split("\n")[0]; + srcMsg = ""; + if (srcText && srcText.nodeValue) { + srcMsg = "\nSource Text : " + srcText.nodeValue.replace(/\t/gi, " ") + } + throw new Error(apf.formatErrorString(1050, null, + "XML Parse Error on line " + linenr, message + srcMsg)); + } + + return xml; +}; @@ -12452,9 +12352,6 @@ apf.runWebkit = function(){ - (parseInt(apf.getStyle(p, "borderTopWidth")) || 0) - (parseInt(apf.getStyle(p, "borderBottomWidth")) || 0)); }; - - if (apf.runNonIe) - apf.runNonIe(); }; @@ -12472,20 +12369,16 @@ apf.runWebkit = function(){ apf.application = function(){ this.$init("application", apf.NODE_HIDDEN); - if (!apf.isO3) { - this.$int = document.body; - this.$tabList = []; //Prevents documentElement from being focussed - // this.$focussable = apf.KEYBOARD; - // this.focussable = true; - this.visible = true; - this.$isWindowContainer = true; - this.focus = function(){ this.dispatchEvent("focus"); }; - this.blur = function(){ this.dispatchEvent("blur"); }; + this.$int = document.body; + this.$tabList = []; //Prevents documentElement from being focussed + // this.$focussable = apf.KEYBOARD; + // this.focussable = true; + this.visible = true; + this.$isWindowContainer = true; + this.focus = function(){ this.dispatchEvent("focus"); }; + this.blur = function(){ this.dispatchEvent("blur"); }; - - apf.window.$addFocus(this); - - } + apf.window.$addFocus(this); }; apf.application.prototype = new apf.AmlElement(); apf.aml.setElement("application", apf.application); diff --git a/plugins/c9.ide.ui/tooltip.js b/plugins/c9.ide.ui/tooltip.js index 70160ac6..07b4c550 100644 --- a/plugins/c9.ide.ui/tooltip.js +++ b/plugins/c9.ide.ui/tooltip.js @@ -1,3 +1,4 @@ +/*global apf*/ define(function(require, exports, module) { main.consumes = ["Plugin", "ui"]; main.provides = ["tooltip"]; @@ -85,7 +86,7 @@ define(function(require, exports, module) { if (options.control) options.control.stop(); - apf.setOpacity(this, 1); + this.style.display = "none"; } function ttmouseout(e) { @@ -134,7 +135,7 @@ define(function(require, exports, module) { control: options.control = {}}); } else { - apf.setOpacity(options.tooltip, 1); + options.tooltip.style.opacity = 1; } }, options.timeout); }