]> spindle.queued.net Git - midori/commitdiff
Do not add the form history style more than once
authorAlexander Butenko <a.butenka@gmail.com>
Thu, 17 Dec 2009 19:56:46 +0000 (20:56 +0100)
committerChristian Dywan <christian@twotoasts.de>
Fri, 18 Dec 2009 09:22:59 +0000 (10:22 +0100)
extensions/formhistory.c

index 8e1a2cc41cf3a19ff90bbaee797d90e1c31ef427..b4ec378745dc28cd4be66384064ad5ca76357424 100644 (file)
@@ -58,15 +58,20 @@ formhistory_prepare_js ()
 
    jsforms = g_strdup_printf (
         "%s"
-        "window.addEventListener (\"load\", function () { initSuggestions (); }, true);"
+        "window.addEventListener ('load', function () { initSuggestions (); }, true);"
         "window.addEventListener ('DOMContentLoaded',"
         "function () {"
-        "var mystyle = document.createElement(\"style\");"
-        "mystyle.setAttribute(\"type\", \"text/css\");"
-        "mystyle.appendChild(document.createTextNode(\"%s\"));"
-        "var head = document.getElementsByTagName(\"head\")[0];"
-        "if (head) head.appendChild(mystyle);"
-        "else document.documentElement.insertBefore(mystyle, document.documentElement.firstChild);"
+        "   var styles = document.getElementsByTagName('style');"
+        "   for (i=0; i<styles.length; i++) {"
+        "       if (styles[i].getAttribute('title') == 'formhistory')"
+        "           return;"
+        "   }"
+        "   var mystyle = document.createElement('style');"
+        "   mystyle.setAttribute('type', 'text/css');"
+        "   mystyle.setAttribute('title', 'formhistory');"
+        "   mystyle.appendChild(document.createTextNode('%s'));"
+        "   var head = document.getElementsByTagName('head')[0];"
+        "   if (head) head.appendChild(mystyle);"
         "}, true);",
         autosuggest,
         style);