User:Prosody/layoutchoice.js

function toggle_layout2 { var n=0; for( key in self.ws_layouts ) n++; layout_num = (layout_num+1) % n; SetSiteCookie("layout",""+layout_num); set_layout2(layout_num); }

function SetSiteCookie(name,value) { document.cookie = name + "=" + escape(value) + ";" + "path=/"; }

function set_layout2(layout_num) { var i=0; for( key in self.ws_layouts ) { if(i==layout_num) layout_name = key; i++; } d = self.ws_layouts[layout_name]; for( key in d ) { if(key.substring(0,1)=='.') { var t = get_elements_by_classname( key.substring(1,key.length) ,"span"); for(var i=0; i"+layout_name+""; refresh_pagenumbers; }

function init_page_layout2 { if(self.debug_page_layout) return;

if(document.URL.indexOf("match=") > 0 ) return; if(document.URL.indexOf("diff=") > 0 ) return;

var k=false; for( key in self.ws_layouts ) { k = true;} if(!k) return;

add_page_container;

if(document.getElementById("text-wrap")) { var optlist = get_optlist; /*p = document.getElementById('p-displayOptions'); if(self.proofreadpage_debug) alert(p);*/ mw.util.addPortletLink ('p-displayOptions', 'javascript:toggle_layout2;', ws_msg('layout'), 'option-textLayout', '' ); var regex = new RegExp(/style=(\d)/); var results = regex.exec(window.location.search); if(results) { layout_num = parseInt(results[1]); }      if (!layout_num) { var stylenum = 0; for (stylename in ws_layouts) { if (document.getElementById(stylename.replace(/ /, "_"))) layout_num=stylenum; stylenum = stylenum+1; }      }       if (!layout_num) { layout = GetCookie("layout") ; if(layout) layout_num = parseInt( layout ); }      if(!layout_num) layout_num = 0; set_layout2(layout_num); } }

function repOnloadHook(functName, hookFunct) { for (var i in onloadFuncts) { if (onloadFuncts[i].name==functName) { onloadFuncts[i]=hookFunct; }   } }

onloadFuncts.unshift(function {repOnloadHook("init_page_layout", init_page_layout2);});