From 681ed303769262b6108e2e5893fceff999fa92d9 Mon Sep 17 00:00:00 2001 From: arno Date: Sat, 21 Aug 2010 13:22:23 +0200 Subject: [PATCH] utils: jquery text() equivalent --- public/js/syj.js | 3 +-- public/js/utils.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) 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; + } } }); -- 2.39.2