remove unnecessary uses of innerHTML

pull/428/merge
nightwing 2017-06-29 16:02:53 +04:00
rodzic f14b7d1914
commit 8c26c4e16b
18 zmienionych plików z 41 dodań i 327 usunięć

Wyświetl plik

@ -160,9 +160,9 @@ define(function(require, exports, module) {
function createGrabber(editor) {
var htmlNode = editor.ace.container.parentNode;
var grabber = document.createElement("div");
htmlNode.appendChild(grabber);
grabber.className = "splitgrabber";
grabber.innerHTML = "=";
grabber.textContent = "=";
htmlNode.appendChild(grabber);
grabber.addEventListener("mousedown", function(e) {
startSplit(e, grabber, editor);

Wyświetl plik

@ -100,7 +100,7 @@ define(function(require, exports, module) {
var chatHistory = workspace.chatHistory || [];
chatHistory.forEach(addMessage);
scrollDown();
chatCounter.innerHTML = chatHistory.length;
chatCounter.textContent = chatHistory.length;
}
chatInput.ace.commands.addCommands([

Wyświetl plik

@ -258,7 +258,7 @@ define(function(require, module, exports) {
document.body.appendChild(node);
node.className = "cool_tooltip_cursor";
node.innerHTML = "<span class='cool_tooltip_cursor_caption'>" + apf.htmlentities(fullname) + "</span>";
node.innerHTML = "<span class='cool_tooltip_cursor_caption'>" + util.escapeHTML(fullname) + "</span>";
// create the arrow
var arrow = document.createElement("div");

Wyświetl plik

@ -174,7 +174,7 @@ define(function(require, exports, module) {
if (bubble) {
if (count) {
bubble.innerHTML = count;
bubble.textContent = count;
bubble.style.display = "block";
bubble.className = "newnotifs size" + String(count).length;
} else {

Wyświetl plik

@ -130,20 +130,20 @@ define(function(require, module, exports) {
var port = (options.local ? ":" + (c9.port || "8080") : "");
if (!options.local) {
var l = location;
shareLinkEditor.innerHTML = l.protocol + "//" + l.host + l.pathname;
shareLinkEditor.textContent = l.protocol + "//" + l.host + l.pathname;
}
else {
shareLinkEditor.innerHTML = "https://ide.c9.io/" + c9.workspaceId;
shareLinkEditor.textContent = "https://ide.c9.io/" + c9.workspaceId;
}
shareLinkApp.innerHTML = (c9.hostname
shareLinkApp.textContent = (c9.hostname
? "https://" + c9.hostname
: "http://localhost") + port;
shareLinkPreview.innerHTML = options.previewUrl;
shareLinkPreview.textContent = options.previewUrl;
[shareLinkEditor, shareLinkApp, shareLinkPreview].forEach(function(div) {
div.addEventListener("click", function(e) {
mnuLink.meta.linkText = this.innerHTML;
mnuLink.meta.linkText = this.textContent;
mnuLink.show(e.clientX + 1, e.clientY);
});
div.addEventListener("contextmenu", function(e) {

Wyświetl plik

@ -367,7 +367,7 @@ define(function(require, exports, module) {
sliderProgress.style.transition = "none";
var newSliderPos = calcSliderPos(evt2.clientX);
revisionLabel.innerHTML = "Version " + newSliderPos;
revisionLabel.textContent = "Version " + newSliderPos;
setHandleLeft(clamp(evt2.clientX));
if (sliderPos != newSliderPos) {
sliderPos = newSliderPos;
@ -476,7 +476,7 @@ define(function(require, exports, module) {
}
function updateTimer(time) {
revisionDate.innerHTML = dateFormat(time);
revisionDate.textContent = dateFormat(time);
}
function calcHandlerLeft(pos) {
@ -492,11 +492,11 @@ define(function(require, exports, module) {
setHandleLeft(calcHandlerLeft(newpos));
if (savedRevisionNums.indexOf(newpos) === -1) {
revisionLabel.innerHTML = "Version " + newpos;
revisionLabel.textContent = "Version " + newpos;
revisionLabel.className = "revision_label";
}
else {
revisionLabel.innerHTML = "Saved Version " + newpos;
revisionLabel.textContent = "Saved Version " + newpos;
revisionLabel.className = "revision_label saved";
}

Wyświetl plik

@ -51,7 +51,7 @@ define(function(require, module, exports) {
function show(title, description, onChoose, onCancel, options) {
draw();
lblExplanation.$ext.innerHTML = util.escapeXml(description);
lblExplanation.$ext.textContent = description;
plugin.title = title || "Please Sign In";
var chosen;

Wyświetl plik

@ -454,7 +454,7 @@ define(function(require, module, exports) {
* Example:
*
* doc.on("setValue", function(e) {
* myDiv.innerHTML = e.value
* myDiv.textContent = e.value
* }, doc.getSession());
*
* @event setValue

Wyświetl plik

@ -66,7 +66,7 @@ define(function(require, exports, module) {
+ dt.getSeconds();
if (doc.tab.isActive())
editor.innerHTML = time;
editor.textContent = time;
doc.title = time;
}, 1);
});

Wyświetl plik

@ -134,7 +134,7 @@ module.exports = function(settings, execFind, toggleDialog, restore, toggleOptio
new RegExp(searchTxt);
}
catch (e) {
tooltip.$ext.innerHTML = apf.escapeXML(e.message.replace(": /" + searchTxt + "/", ""));
tooltip.$ext.textContent = e.message.replace(": /" + searchTxt + "/", "");
tooltip.$ext.style.opacity = 1;
var pos = apf.getAbsolutePosition(win.$ext);

Wyświetl plik

@ -133,8 +133,7 @@ define(function(require, exports, module) {
aboutDialog.show();
// shorten commit hash in c9.version
var version = c9.version.replace(/([a-f\d]{10})[a-f\d]{30}/, "$1");
document.getElementById("c9Version").innerHTML
= ui.escapeXML("Version " + version);
document.getElementById("c9Version").textContent = "Version " + version;
}
/***** Lifecycle *****/

Wyświetl plik

@ -305,7 +305,6 @@ define(function(require, exports, module) {
? path
: vfs.url(path);
// editor.setProperty("value", apf.escapeXML(fullpath));
loadCanvas(doc.tab, fullpath, callback);
}

Wyświetl plik

@ -464,7 +464,7 @@ define(function(require, exports, module) {
lastCell = cell;
if (cell.html)
cell.html.innerHTML = "";
cell.html.textContent = "";
evaluateHeadless(expression, function(result) {
if (cell.setError && result["$$error"])

Wyświetl plik

@ -329,7 +329,7 @@ define(function(require, exports, module) {
});
plugin.addOther(function() {
div.innerHTML = "";
div.textContent = "";
div.parentNode.removeChild(div);
terminal.destroy();

Wyświetl plik

@ -76,7 +76,7 @@
location.hash = location.hash.replace(/&?create/, "");
}
document.querySelector("#loadingide .cool-message").innerHTML = msg;
document.querySelector("#loadingide .cool-message").textContent = msg;
setTimeout(function(){
var s = document.querySelector("#loadingide .status");

Wyświetl plik

@ -155,7 +155,7 @@ define(function(require, exports, module) {
draw();
var amount = button.$ext.querySelector(".amount");
amount.innerHTML = totalCoverage + "%";
amount.textContent = totalCoverage + "%";
button.show();
}

Wyświetl plik

@ -460,9 +460,6 @@ define(["require", "module", "exports", "./lib/menu/menu", "./lib/crypto",
return null;
},
html_entity_decode: function(s){return s},
htmlentities: function(s){return s},
/**
* Formats an Ajax.org Platform error message.
* @param {Number} number The number of the error. This can be used to look up more information about the error.
@ -1733,111 +1730,6 @@ if (!String.prototype.repeat) {
return Array(times + 1).join(this);
};
}
/*
* Count the number of occurences of substring 'str' inside a string
*
* @param {String} str
* @type {Number}
*/
String.prototype.count = function(str) {
return this.split(str).length - 1;
};
/*
* Remove HTML or any XML-like tags from a string
*
* @type {String}
*/
String.prototype.stripTags = function() {
return this.replace(/<\/?[^>]+>/gi, "");
};
/*
* Wrapper for the global 'escape' function for strings
*
* @type {String}
*/
String.prototype.escape = function() {
return escape(this);
};
/*
* Returns an xml document
* @type {XMLElement}
*/
String.prototype.toXml = function(){
var node = apf.getXml("<root>" + this + "</root>");
if (node.childNodes.length == 1) {
return node.childNodes[0];
}
else {
var docFrag = node.ownerDocument.createDocumentFragment(),
nodes = node.childNodes;
while (nodes.length)
docFrag.appendChild(nodes[0]);
return docFrag;
}
};
if (typeof window != "undefined" && typeof window.document != "undefined"
&& typeof window.document.createElement == "function") {
/*
* Encode HTML entities to its HTML equivalents, like '&amp;' to '&amp;amp;'
* and '&lt;' to '&amp;lt;'.
*
* @type {String}
* @todo is this fast?
*/
String.prototype.escapeHTML = function() {
this.escapeHTML.text.data = this;
return this.escapeHTML.div.innerHTML;
};
/*
* Decode HTML equivalent entities to characters, like '&amp;amp;' to '&amp;'
* and '&amp;lt;' to '&lt;'.
*
* @type {String}
*/
String.prototype.unescapeHTML = function() {
var div = document.createElement("div");
div.innerHTML = this.stripTags();
if (div.childNodes[0]) {
if (div.childNodes.length > 1) {
var out = [];
for (var i = 0; i < div.childNodes.length; i++)
out.push(div.childNodes[i].nodeValue);
return out.join("");
}
else
return div.childNodes[0].nodeValue;
}
return "";
};
String.prototype.escapeHTML.div = document.createElement("div");
String.prototype.escapeHTML.text = document.createTextNode("");
String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text);
if ("<\n>".escapeHTML() !== "&lt;\n&gt;")
String.prototype.escapeHTML = null;
if ("&lt;\n&gt;".unescapeHTML() !== "<\n>")
String.prototype.unescapeHTML = null;
}
if (!String.prototype.escapeHTML) {
String.prototype.escapeHTML = function() {
return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
};
}
if (!String.prototype.unescapeHTML) {
String.prototype.unescapeHTML = function() {
return this.stripTags().replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");
};
}
/*
* Trim a string down to a specific number of characters. Optionally, append an
@ -1885,34 +1777,6 @@ String.prototype.splitSafe = function(separator, limit, bLowerCase) {
.split(new RegExp("[\\s ]*" + separator + "[\\s ]*", "g"), limit || 999);
};
/*
* Appends a random number with a specified length to this String instance.
*
* @see randomGenerator
* @param {Number} length
* @type {String}
*/
String.prototype.appendRandomNumber = function(length) {
for (var arr = [], i = 1; i <= length; i++)
arr.push(apf.randomGenerator.generate(1, 9));
// Create a new string from the old one, don't just create a copy
return this.toString() + arr.join("");
};
/*
* Prepends a random number with a specified length to this String instance.
*
* @see randomGenerator
* @param {Number} length
* @type {String}
*/
String.prototype.prependRandomNumber = function(length) {
for (var arr = [], i = 1; i <= length; i++)
arr.push(apf.randomGenerator.generate(1, 9));
// Create a new string from the old one, don't just create a copy
return arr.join("") + this.toString();
};
/*
* Returns a string produced according to the formatting string. It replaces
* all <i>%s</i> occurrences with the arguments provided.
@ -2870,43 +2734,6 @@ apf.getHtmlInnerHeight = function(oHtml) {
- (parseInt(apf.getStyle(oHtml, "borderBottomWidth")) || 0));
};
/**
* Escapes HTML from a string.
* @param {String} str The html to be escaped.
* @return {String} The escaped string.
*/
apf.htmlentities = function(str) {
return str.escapeHTML();
};
/**
* Escape an XML string, making it ascii compatible.
* @param {String} str The xml string to escape.
* @return {String} The escaped string.
* @method xmlentities
*
*/
/* @todo This function does something completely different from htmlentities,
* the name is confusing and misleading.
*/
apf.xmlentities = apf.escapeXML;
/**
* Unescape an HTML string.
* @param {String} str The string to unescape.
* @return {String} The unescaped string.
*/
apf.html_entity_decode = function(str) {
return (str || "").replace(/\&\#38;/g, "&").replace(/&lt;/g, "<")
.replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&nbsp;/g, " ");
};
/**
* Determines whether the keyboard input was a character that can influence
* the value of an element (like a textbox).
@ -3233,125 +3060,18 @@ apf.isChildOf = function(pNode, childnode, orItself) {
return false;
};
apf.xmlEntityMap = {
"quot": "34", "amp": "38", "apos": "39", "lt": "60", "gt": "62",
"nbsp": "160", "iexcl": "161", "cent": "162", "pound": "163", "curren": "164",
"yen": "165", "brvbar": "166", "sect": "167", "uml": "168", "copy": "169",
"ordf": "170", "laquo": "171", "not": "172", "shy": "173", "reg": "174",
"macr": "175", "deg": "176", "plusmn": "177", "sup2": "178", "sup3": "179",
"acute": "180", "micro": "181", "para": "182", "middot": "183", "cedil": "184",
"sup1": "185", "ordm": "186", "raquo": "187", "frac14": "188", "frac12": "189",
"frac34": "190", "iquest": "191", "agrave": ["192", "224"], "aacute": ["193", "225"],
"acirc": ["194", "226"], "atilde": ["195", "227"], "auml": ["196", "228"],
"aring": ["197", "229"], "aelig": ["198", "230"], "ccedil": ["199", "231"],
"egrave": ["200", "232"], "eacute": ["201", "233"], "ecirc": ["202", "234"],
"euml": ["203", "235"], "igrave": ["204", "236"], "iacute": ["205", "237"],
"icirc": ["206", "238"], "iuml": ["207", "239"], "eth": ["208", "240"],
"ntilde": ["209", "241"], "ograve": ["210", "242"], "oacute": ["211", "243"],
"ocirc": ["212", "244"], "otilde": ["213", "245"], "ouml": ["214", "246"],
"times": "215", "oslash": ["216", "248"], "ugrave": ["217", "249"],
"uacute": ["218", "250"], "ucirc": ["219", "251"], "uuml": ["220", "252"],
"yacute": ["221", "253"], "thorn": ["222", "254"], "szlig": "223", "divide": "247",
"yuml": ["255", "376"], "oelig": ["338", "339"], "scaron": ["352", "353"],
"fnof": "402", "circ": "710", "tilde": "732", "alpha": ["913", "945"],
"beta": ["914", "946"], "gamma": ["915", "947"], "delta": ["916", "948"],
"epsilon": ["917", "949"], "zeta": ["918", "950"], "eta": ["919", "951"],
"theta": ["920", "952"], "iota": ["921", "953"], "kappa": ["922", "954"],
"lambda": ["923", "955"], "mu": ["924", "956"], "nu": ["925", "957"],
"xi": ["926", "958"], "omicron": ["927", "959"], "pi": ["928", "960"],
"rho": ["929", "961"], "sigma": ["931", "963"], "tau": ["932", "964"],
"upsilon": ["933", "965"], "phi": ["934", "966"], "chi": ["935", "967"],
"psi": ["936", "968"], "omega": ["937", "969"], "sigmaf": "962", "thetasym": "977",
"upsih": "978", "piv": "982", "ensp": "8194", "emsp": "8195", "thinsp": "8201",
"zwnj": "8204", "zwj": "8205", "lrm": "8206", "rlm": "8207", "ndash": "8211",
"mdash": "8212", "lsquo": "8216", "rsquo": "8217", "sbquo": "8218", "ldquo": "8220",
"rdquo": "8221", "bdquo": "8222", "dagger": ["8224", "8225"], "bull": "8226",
"hellip": "8230", "permil": "8240", "prime": ["8242", "8243"], "lsaquo": "8249",
"rsaquo": "8250", "oline": "8254", "frasl": "8260", "euro": "8364",
"image": "8465", "weierp": "8472", "real": "8476", "trade": "8482",
"alefsym": "8501", "larr": ["8592", "8656"], "uarr": ["8593", "8657"],
"rarr": ["8594", "8658"], "darr": ["8595", "8659"], "harr": ["8596", "8660"],
"crarr": "8629", "forall": "8704", "part": "8706", "exist": "8707", "empty": "8709",
"nabla": "8711", "isin": "8712", "notin": "8713", "ni": "8715", "prod": "8719",
"sum": "8721", "minus": "8722", "lowast": "8727", "radic": "8730", "prop": "8733",
"infin": "8734", "ang": "8736", "and": "8743", "or": "8744", "cap": "8745",
"cup": "8746", "int": "8747", "there4": "8756", "sim": "8764", "cong": "8773",
"asymp": "8776", "ne": "8800", "equiv": "8801", "le": "8804", "ge": "8805",
"sub": "8834", "sup": "8835", "nsub": "8836", "sube": "8838", "supe": "8839",
"oplus": "8853", "otimes": "8855", "perp": "8869", "sdot": "8901", "lceil": "8968",
"rceil": "8969", "lfloor": "8970", "rfloor": "8971", "lang": "9001", "rang": "9002",
"loz": "9674", "spades": "9824", "clubs": "9827", "hearts": "9829", "diams": "9830"
var HTML_ENTITY_MAP = {
"&": "&#38;",
"<": "&#60;",
">": "&#62;",
'"': "&#34;",
"'": "&#39;"
};
/**
* Escapes "&amp;", greater than, less than signs, quotation marks, and others into
* the proper XML entities.
*
* @param {String} str The XML string to escape.
* @param {Boolean} strictMode By default, this function attempts to NOT double-escape XML entities. This flag turns that behavior off when set to `true`.
* @return {String} The escaped string
*/
apf.escapeXML = function(str, strictMode) {
if (typeof str != "string")
return str;
if (strictMode)
str = (str || "").replace(/&/g, "&#38;");
else
str = (str || "").replace(/&(?!#[0-9]{2,5};|[a-zA-Z]{2,};)/g, "&#38;");
var map = apf.xmlEntityMap;
var isArray = apf.isArray;
return str
.replace(/"/g, "&#34;")
.replace(/</g, "&#60;")
.replace(/>/g, "&#62;")
.replace(/'/g, "&#39;")
.replace(/&([a-zA-Z]+);/gi, function(a, m) {
var x = map[m.toLowerCase()];
if (x)
return "&#" + (isArray(x) ? x[0] : x) + ";";
return a;
});
};
/**
* Unescapes `"&#38;"` and other similar XML entities into HTML entities, and then replaces
* 'special' ones (`&apos;`, `&gt;`, `&lt;`, `&quot;`, `&amp;`) into characters
* (`'`, `>`, `<`, `"`, `&`).
*
* @param {String} str The XML string to unescape
* @return {String} The unescaped string
*/
apf.unescapeXML = function(str) {
if (typeof str != "string")
return str;
var map = apf.xmlEntityMapReverse;
var isArray = apf.isArray;
if (!map) {
map = apf.xmlEntityMapReverse = {};
var origMap = apf.xmlEntityMap;
var keys = Object.keys(origMap);
for (var val, j, l2, i = 0, l = keys.length; i < l; ++i) {
val = origMap[keys[i]];
if (isArray(val)) {
for (j = 0, l2 = val.length; j < l2; ++j)
map[val[j]] = keys[i];
}
else
map[val] = keys[i];
}
}
return str
.replace(/&#([0-9]{2,5});/g, function(a, m) {
var x = map[m];
if (x)
return "&" + x + ";";
return a;
})
.replace(/&apos;/gi, "'")
.replace(/&gt;/gi, ">")
.replace(/&lt;/gi, "<")
.replace(/&quot;/gi, "\"")
.replace(/&amp;/gi, "&");
var HTML_CHARACTERS_EXPRESSION = /[&"'<>]/gm;
apf.escapeHTML = apf.escapeXML = function(text) {
return text && text.replace(HTML_CHARACTERS_EXPRESSION, function(c) {
return HTML_ENTITY_MAP[c] || c;
});
};
/**
@ -6400,7 +6120,7 @@ apf.AmlElement = function(struct, tagName) {
if (node.localName == "application") {
el = parent;
} else {
var namespace = node.prefix === "a" ? apf.aml : apf.xhtml;
var namespace = node.prefix == "a" ? apf.aml : apf.xhtml;
var ElementType = namespace.elements[node.localName] || namespace.elements["@default"];
var el = new ElementType({}, node.localName);
var a = node.attributes;
@ -6932,9 +6652,9 @@ apf.AmlDocument = function(){
*/
this.createElement = function(qualifiedName) {
var parts = qualifiedName.split(":");
var prefix = parts.length === 1 ? "" : parts[0];
var name = parts.length === 1 ? parts[0]: parts[1];
var namespace = prefix === "a" ? apf.aml : apf.xhtml;
var prefix = parts.length == 1 ? "" : parts[0];
var name = parts.length == 1 ? parts[0]: parts[1];
var namespace = prefix == "a" ? apf.aml : apf.xhtml;
var ElementType = namespace.elements[name] || namespace.elements["@default"];
return new ElementType({}, qualifiedName);
};
@ -17675,12 +17395,8 @@ apf.textbox = function(struct, tagName) {
this.getValue = function(){
var v;
if (this.isHTMLBox) {
//Chrome has a bug, innerText is cleared when display property is changed
v = apf.html_entity_decode(this.$input.innerHTML
.replace(/<br\/?\>/g, "\n")
.replace(/<[^>]*>/g, ""));
}
if (this.isHTMLBox)
v = this.$input.innerText;
else
v = this.$input.value;

Wyświetl plik

@ -78,7 +78,7 @@
if (idx == messages.length) idx = messages.length - 1;
var msg = messages[idx];
document.querySelector("#loadingide .cool-message").innerHTML = msg;
document.querySelector("#loadingide .cool-message").textContent = msg;
setTimeout(function(){
var s = document.querySelector("#loadingide .status");