User:Alex brollo/PersonalButtons.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

ws.xf=function (opt) {
    if (opt===undefined) opt=0;
    var tags=[
    	["",""], // opt 0, no action
        ["<poem>\n","\n</poem>"], //opt 1, poem
        ["«","»"], // opt 2, «»
        ["“","”"], // opt 3, “”
        ["<section begin='s1' />","<section end='s1' />"], // opt 4, sections
        ["‛","’"] // opt 5, ‛’
    ];
    $(mw.activeElement).textSelection( 'encapsulateSelection', { pre:tags[opt][0], post: tags[opt][1] } );
};

// divide la pagina in due section s1 e s2, oppure una section s2 in una s2 e s3, usando come punto di separazione
	// la posizione del puntatore. Usa sel() 
ws.newSections = function() {
		
		var s=ws.selection();
		if (s[2].indexOf('<section end="s2" />')===-1) {
			s[0]='<section begin="s1" />'+s[0]+'<section end="s1" />';
			s[2]='<section begin="s2" />'+s[2]+'<section end="s2" />'; 
		}
		else {
			s[0]=s[0]+'<section end="s2" />';
			s[2]='<section begin="s3" />'+s[2].replace('<section end="s2" />','<section end="s3" />');    
		}
		s[0].value=s[0]+s[1]+s[2];
		ws.scriviSel(s);
		return;
	};
ws.shortcut.add("Ctrl+Shift+k",function()   {
	ws.scriviBox("",0);
	ws.newRi();
});
ws.newButton("sect","ws.newSections()","es","inserimento s1-s2");
ws.newButton("poem","ws.xf(1)","es","inserimento poem");
ws.newButton("«»","ws.xf(2)","es","inserimento caporali");
ws.newButton("“”","ws.xf(3)","es","inserimento doppi apostrofi");
// ws.newButton("sect","ws.xf(4)","es","inserimento section");
ws.newButton("‛’","ws.xf(5)","es","inserimento pages");