From: Giuseppe Bilotta Date: Sat, 21 Aug 2010 08:54:07 +0000 (+0200) Subject: Styling for the menu X-Git-Url: http://git.oblomov.eu/provvstudienna.user.js/commitdiff_plain?ds=inline Styling for the menu --- diff --git a/provvstudienna.user.js b/provvstudienna.user.js index b10d8ef..be19a1c 100644 --- a/provvstudienna.user.js +++ b/provvstudienna.user.js @@ -10,6 +10,10 @@ if (typeof(unsafeWindow) == 'undefined') unsafeWindow = window; +String.prototype.ltrim = function() { return this.replace(/^\s+/,'') }; +String.prototype.rtrim = function() { return this.replace(/\s+$/,'') }; +String.prototype.trim = function() { return this.ltrim().rtrim() }; + (function () { /* replace the non-standard startDownload() behavior with standard XMLHttpRequest */ @@ -49,12 +53,12 @@ if (typeof(unsafeWindow) == 'undefined') unsafeWindow = window; var param = nodes[i]; var match = /^(\d+)-Label$/.exec(param.name); if (match) { - ops[parseFloat(match[1])-1] = {label: param.value, entry: []}; + ops[parseFloat(match[1])-1] = {label: param.value.trim(), entry: []}; continue; } match = /^(\d+)-Entry(\d+)$/.exec(param.name); if (match) { - ops[parseFloat(match[1])-1].entry[parseFloat(match[2]-1)] = {label: param.value}; + ops[parseFloat(match[1])-1].entry[parseFloat(match[2]-1)] = {label: param.value.trim()}; continue; } match = /^(\d+)-URL(\d+)$/.exec(param.name); @@ -76,20 +80,42 @@ if (typeof(unsafeWindow) == 'undefined') unsafeWindow = window; menu.appendChild(document.createElement('li')); var item = menu.lastChild; item.id = ops[i].label.replace(/\./g,'').replace(/\W/g,'-').toLowerCase(); - item.appendChild(document.createTextNode(ops[i].label)); + item.appendChild(document.createElement('p')); + item.lastChild.appendChild(document.createTextNode(ops[i].label)); item.appendChild(document.createElement('ul')); + item = item.lastChild; for (var j = 0; j < ops[i].entry.length; ++j) { item.appendChild(document.createElement('li')); - item = item.lastChild; - // item.id = ops[i].entry[j].label.replace(/\./g,'').replace(/\W/g,'-').toLowerCase(); - item.appendChild(document.createElement('a')); - item = item.lastChild; - item.href = ops[i].entry[j].url; - item.appendChild(document.createTextNode(ops[i].entry[j].label)); + item.lastChild.appendChild(document.createElement('a')); + link = item.lastChild.lastChild; + link.href = ops[i].entry[j].url; + link.appendChild(document.createTextNode(ops[i].entry[j].label)); } } pnode.appendChild(menu); } } + /* Styling for the menu */ + /* we could grab most of these from the params to the java applet, but I'm too lazy to write that code for now */ + /* TODO: metal effect */ + style = '#hypermenu { font-family: Dialog, sans-serif; font-size: 12px; list-style-type: none; text-align: left; background-color: #e2e2e2; margin:0 auto; padding:0;width: 100%}'; + style += '#hypermenu > li { margin:0; padding:0}'; + style += '#hypermenu > li > p { font-weight: bold; background-color: #284828; margin:0; padding: 6px 0 6px 3px; }'; + style += '#hypermenu > li > p:hover { color: #00FF00; }'; + style += '#hypermenu ul { color:black; font-weight:normal; list-style-type: none; margin:0; padding:0; background-color: #C0C0C0}'; + style += '#hypermenu ul > li { padding: 3px}'; + style += '#hypermenu ul > li:hover { color: #CC0000; font-weight: bold}'; + style += '#hypermenu a { color:inherit; text-decoration:none }' ; + + /* rolling effect */ + style += '#hypermenu > li > p { border: 1px solid gray }'; + style += '#hypermenu > li > ul {display:none}'; + style += '#hypermenu > li:hover > ul {display:block}'; + + stel = unsafeWindow.document.createElement('style'); + stel.appendChild(document.createTextNode(style)); + unsafeWindow.document.getElementsByTagName('head')[0].appendChild(stel); + + })();