From: arno Date: Sat, 21 Aug 2010 11:22:23 +0000 (+0200) Subject: utils: jquery text() equivalent X-Git-Tag: v0.2~27 X-Git-Url: https://dev.renevier.net/?p=syj.git;a=commitdiff_plain;h=681ed303769262b6108e2e5893fceff999fa92d9 utils: jquery text() equivalent --- diff --git a/public/js/syj.js b/public/js/syj.js index 54677a2..916d277 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -1090,13 +1090,12 @@ var Nominatim = (function() { }); anchor.observe('click', clickhandler(item.boundingbox)); + Element.text(anchor, item.display_name); - var text = document.createTextNode(item.display_name); var icon = new Element("img", { className: "nominatim-suggestions-icon", src: item.icon || 'icons/world.png' }); - anchor.appendChild(text); // insert does not work; see prototype #1125 li.insert(icon).insert(anchor); $("nominatim-suggestions-list").insert(li); if ($("nominatim-suggestions-list").childNodes.length >= 6) { diff --git a/public/js/utils.js b/public/js/utils.js index 348e3a7..5dd8c69 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -122,6 +122,23 @@ Element.addMethods({ Element.setStyle(element, {'backgroundColor': color}); Element.setStyle.delay(timeout, element, {'backgroundColor': current}); return element; + }, + text: function(element, content) { + if (typeof content === "undefined") { // getter + if (element.nodeType === 8) { + return ""; + } else if (element.nodeType === 3 || element.nodeType === 4) { + return element.nodeValue; + } else { + return $A(element.childNodes).inject("", function(acc, el) { + return acc + Element.text(el); + }); + } + } else { // setter + var node = document.createTextNode(content); + element.update().appendChild(node); + return element; + } } });