Do not add the form history style more than once

This commit is contained in:
Alexander Butenko 2009-12-17 20:56:46 +01:00 committed by Christian Dywan
parent e1b82af2c7
commit 82697f0afb

View 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];"
" 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);"
"else document.documentElement.insertBefore(mystyle, document.documentElement.firstChild);"
"}, true);",
autosuggest,
style);