/* gui-js/menu.js This file is distributed under terms of the Affero GPL v3 license or later, see http://yasep.org created mar. août 30 02:24:47 CEST 2011 by whygee@f-cpu.org version lun. sept 12 08:17:07 CEST 2011 init_obj() added version mer. avril 11 21:36:51 CEST 2012 : console.info removed version mer. mai 9 12:58:55 CEST 2012 : changed the argument formats. This file implements a menu bar that can be independent from ygwm. some features depend on winman and avoid closure. */ init_obj.push(menu={ list:{}, unfold_menuItem: function(){ if (ygwm.moved_div) return; // No display if ygwm (or dragndrop) is currently moving something if (this.listlength > 0) this.menuItemList.style.display=""; // display only if something to show }, fold_menuItem: function(){ this.menuItemList.style.display="none"; }, onClick: function(){ winman.activate_window(this.key); }, // langlist is a list of strings, that can be HTML to make links and pictures and stuff // The first element is used as a "key" to find the entry later. // func can be a ygwm key string or a normal function. Leave empty if nothing. subMenuItem: function(n,langlist,func, sep, t){ // if (typeof langlist!="object") // return alert("subMenuItem: expecting langlist argument to be an array"); /* if (!n) { var s="",i; for (i in arguments){ s+="\n"+i+"="+arguments[i]; } alert(s); } */ var name=langlist[0], l; if (l=n.list[name]) return l; // don't create duplicates var o=dcE("DIV"); o.className=(sep===1)?"menuSeparator":"menuItem"; setHTML(o,langlist); setTitle(o,t); // click behaviour if (typeof func == "function") o.onclick=func; else { if (typeof func == "string") { o.onclick=menu.onClick; o.key=func; // avoid closure } } n.list[name]=o; n.listlength++; n.menuItemList.appendChild(o); return o; }, mainMenuItem: function(langlist,dir,t){ var i,k,l; if (typeof langlist=="string") { if (l=menu.list[langlist]) return l; ////// LOOKUP SHOULD BE DONE WITH menu.list["xyz"] else alert(langlist+" "+I8N("not found")); } var name=langlist[0], m=dcE("DIV"), n=dcE("DIV"), o=dcE("SPAN"); if (dir != "R") dir="L"; // class "L" by default (left-justified unless told otherwise) n.className="menuBarItem"+dir; menu.list[name]=n; setHTML(o,langlist); setTitle(o,t); n.appendChild(o); n.list={}; n.listlength=0; n.onmouseout =menu.fold_menuItem; n.onmouseover=menu.unfold_menuItem; menu.mainMenu_id.appendChild(n); // n.style.width=n.scrollWidth+"px"; // sets the size once and for all // create the folding list m.className="menuItemList"; m.style.display="none"; n.appendChild(m); n.menuItemList=m; return n; }, /////////////////////////////// Stupid code... but somewhat fun /////////////////////////////// rainbow_x:5, rainbow_i:0, iterate_rainbow:function(){ /* create a "rainbow" */ var j=YGCSS.ColorStylesNames[--menu.rainbow_i]; ygwm.new_window(j, null, "none", 160,90, menu.rainbow_x, Math.ceil((menu.rainbow_x/2)+60), false, true, true, true, false, j); menu.rainbow_x+=40; if (menu.rainbow_i>0) redraw(menu.iterate_rainbow); }, key_count:0, key_time:0, iterate_keys:function(){ if (menu.key_count>0) { redraw(menu.iterate_keys); winman.activate_window(winman.keys_list[--menu.key_count]); } else alert("Elapsed : "+(+new Date()-menu.key_time)+"ms"); }, create_menu:function(){ (menu.mainMenu_id=dcE("DIV")).id="MainMenuBar"; document.body.appendChild(menu.mainMenu_id); }, /* close_all:function(){ menu.key_count=0; var w=ygwm.top_window.previousSibling; if(w.winTitle){ ygwm.erase_window(w); } }, */ /////////////////////////////////////////////////////////////////////////// // Build a YASEP-specific menu : init_obj: function(){ var i, j, l='Contact']); sublink(i8n.Dnl,"yasep.tbz"); sublink(i8n.Lic,"license/agpl.txt"); t([l+'http://news.yasep.org/">blog']); t([l+'https://www.facebook.com/pages/The-YASEP/167478153314916">facebook']); t([l+'http://yasep.org">yasep.org']); t([l+'http://archives.yasep.org">Archives']); t([l+'http://defora.org">defora']); // To be called AFTER init_cookies() ! // Create the language picker menu j=menu.mainMenuItem(["LNG"],"R",i8n.SelLn); for (i in i8n.LANGS) // /!\ i is a string ! menu.subMenuItem(j, [ LANG.FLAGS[i]='
' ], // Initialises the array function(i){ return function(){ LANG.change_lang(i) // looks weird but it is a function that } // creates another function then calls it for getting a function with closure... }(i), 0, // not a separator i8n.LANGUAGES[i] ); // got it ? :-P LANG.change_innerHTML.push([j.firstChild, LANG.FLAGS]); // LANG.change_title.push([j,i8n.SelLn]); // set to the current language logo // LANG.change_lang(LNG); // done later in cookies.init } });