Utente:Alex brollo/eiv.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
Riga 20: | Riga 20: | ||
var alex={}; |
var alex={}; |
||
var eiv={}; |
var eiv={}; |
||
eiv.cp={}; |
|||
(function ($,mw) { |
(function ($,mw) { |
||
console.log("passo 1"); |
console.log("passo 1"); |
||
Riga 113: | Riga 113: | ||
localStorage.p=p; |
localStorage.p=p; |
||
try { |
try { |
||
eiv.p_2=[p[0][0],splitPagina(p[0][1])]; |
|||
⚫ | |||
catch(err) {eiv.p_2=["",[[],[],[]] ];} |
catch(err) {eiv.p_2=["",[[],[],[]] ];} |
||
try { |
try { |
||
eiv.p_1=[p[1][0],splitPagina(p[1][1])]; |
eiv.p_1=[p[1][0],splitPagina(p[1][1])]; |
||
⚫ | |||
catch(err) {eiv.p_1=["",[[],[],[]] ];} |
catch(err) {eiv.p_1=["",[[],[],[]] ];} |
||
try { |
try { |
||
eiv.p_0=[p[2][0],splitPagina(p[2][1])]; |
eiv.p_0=[p[2][0],splitPagina(p[2][1])]; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
$("#wpHeaderTextbox").val(eiv.header); |
|||
$("#wpFooterTextbox").val(eiv.footer); |
|||
⚫ | |||
⚫ | |||
catch(err) {eiv.p_0=["",[[],[],[]] ];} |
catch(err) {eiv.p_0=["",[[],[],[]] ];} |
||
} ); |
} ); |
||
} |
} |
||
function pageParse(oggetto) { |
|||
oggetto.contenuto={}; |
|||
var headerEnd = oggetto[1][0].indexOf("</noinclude>") + "</noinclude>".length; |
|||
var footerStart = oggetto[1][0].lastIndexOf("<noinclude>"); |
|||
oggetto.contenuto.body = oggetto[1][0].substring(headerEnd,footerStart); |
|||
oggetto.contenuto.header= oggetto[1][0].substring(0, headerEnd); |
|||
oggetto.contenuto.footer= oggetto[1][0].codice.substring(footerStart); |
|||
try { |
|||
⚫ | |||
⚫ | |||
catch(err) { |
|||
oggetto.contenuto.level ="1"; |
|||
⚫ | |||
try { |
|||
⚫ | |||
⚫ | |||
catch(err) { |
|||
oggetto.contenuto.user =mw.config.get("wgUserName"); |
|||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
})($,mw); |
})($,mw); |
Versione delle 22:46, 3 ott 2016
// mw.loader.load('//wikisource.org/w/index.php?title=User:Alex brollo/common.js&action=raw&ctype=text/javascript');
/*
Edit In View, versione ottobre 2016
Alex brollo
Logica:
1. costruire l'ambiente (contentore generale, box di edit, box immagine, box anteprima)
2. costruire i box di e gli strumenti base (level, salva, annulla)
3. leggere il codice pagine e popolare gli oggetti-pagina
4. assegnare a tali oggetti appositi metodi
5. verificare caricamento e funzionamento di tutti i tool di edit
*/
// creo un'unica variabile globale, non si sa mai che mi serva; anzi proviamo senza
mw.loader.load("jquery.ui.draggable");
var alex={};
var eiv={};
eiv.cp={};
(function ($,mw) {
console.log("passo 1");
if(mw.config.get("wgCanonicalNamespace")!=="Page" || mw.config.get("wgAction")!=="view") { console.log("eiv non eseguito"); return false;}
console.log("passo 2");
/* passo 1 : costruire l'ambiente */
// in nsPage, and in view mode, eiv environment is built
creabox();
activate();
function toggle() {
$("#sfondoEiv").toggle();
return false;
}
function activate() {
// access button
$('<li id="ca-eiv"><span><a href="#" title="Attiva eiv" >eiv</a></span></li>').click(function() {toggle();}).insertAfter($("#ca-view"));
// loading wikitext of three pages
pp();
return false;
}
function creabox() {
$('<div id="sfondoEiv" style="width: 100%; height: 100%; position: fixed; z-index: 100; top: 0px; left: 0px; background-color: rgb(250, 250, 250); display:none;"></div>').appendTo($("#content"));
$(".prp-page-image").clone().appendTo($("#sfondoEiv"));
$("#sfondoEiv .prp-page-image").css("width","40%");
$("#sfondoEiv .prp-page-image img").draggable();
var box=$('<div style="display:block; border:1px solid black; position:fixed; top:10px; left:10px; /* z-index:999; */ background-color:#efefef;padding:6px;" id="editBox"></div>');
box.append($("<div id='handle' style='width:100%; background-color:#dfdfdf; min-height:10px;' ><div id='areaBottoni' style='float:left;max-width:400px'></div> </div>"));
box.append($("<textarea name='wpHeaderTextbox' id='wpHeaderTextbox' style='width:100%; height:30px; border:1px solid gray;' />"));
box.append($("<textarea name='wpTextbox1' id='wpTextbox1' rows='35' style='width:550px; border:1px solid gray;' />"));
box.append($("<textarea name='wpFooterTextbox' id='wpFooterTextbox' style='width:100%; height:30px; border:1px solid gray;' />"));
$("#sfondoEiv").append(box);
// attivazione alex.activeEleme
$("#editBox textarea").focusin(function () {alex.activeElement=this;});
$("#editBox").draggable({ handle: "areaBottoni" });
var qb='<span id="radiobuttons" style="float:right">'+
'<span class="quality0"><input tabindex="5" title="Pagine_SAL_00%" type="radio" value="0" name="wpQuality"></span>'+
'<span class="quality2"><input tabindex="6" title="Pagine_SAL_50%" type="radio" value="2" name="wpQuality"></span>'+
'<span class="quality1"><input tabindex="7" title="Pagine_SAL_25%" type="radio" value="1" name="wpQuality"></span>'+
'<span class="quality3"><input tabindex="8" title="Pagine_SAL_75%" checked="" type="radio" value="3" name="wpQuality"></span>'+
'<span id="radioQuality4" class="quality4"><input tabindex="9" title="Pagine_SAL_100%" type="radio" value="4" name="wpQuality"></span></span>';
qb+='<br><span style="float:right">'+
'<button class="baseButton" id="wpSave" style="display: inline; padding: 1px 2px;" type="button" title="Salva le modifiche" onclick="alex.eiv.salvaPagina()"><small>Salva</small></button>'+
'<button class="baseButton" id="wpPreview" style="display: inline; padding: 1px 2px;" type="button" title="Visualizza anteprima" onclick="alex.eiv.pagePreview()"><small>Anteprima</small></button>'+
'<button class="baseButton" style="display: inline; padding: 1px 2px;" type="button" title="Annulla e chiudi" onclick="alex.eiv.chiudiEditBox()"><small>Annulla</small></button>'+
'</span>';
$("#handle").append($(qb));
}
// splits wiki code into header,body,footer
function splitPagina(tpp) {
var testo = ["", "", ""];
testo[0] = tpp.substring(0, tpp.indexOf("</noinclude>") + 12);
testo[2] = tpp.substring(tpp.lastIndexOf("<noinclude>"));
testo[1] = tpp.substring(testo[0].length, tpp.length - testo[2].length);
return testo;
}
// reads three pages code (current, previous, previous of previous)
function pp() {
eiv.p_0=[];
eiv.p_1=[];
eiv.p_2=[];
var p=[];
var t=(/(.+\/)(.+)$/).exec(mw.config.get("wgPageName"));
var t1=t[2]*1-1;
var t2=t[2]*1-2;
var api = new mw.Api();
api.get( {
action: 'query',
prop: 'revisions',
titles:t[1]+t2+"|"+t[1]+t1+"|"+t[1]+t[2],
rvprop:"content"
} ).done( function ( data ) {
$.each(data.query.pages, function(index,value) {
try {p.push([value.title,value.revisions[0]["*"]]);}
catch(err) {p.push([value.title,""]);}
});
localStorage.p=p;
try {
eiv.p_2=[p[0][0],splitPagina(p[0][1])];
}
catch(err) {eiv.p_2=["",[[],[],[]] ];}
try {
eiv.p_1=[p[1][0],splitPagina(p[1][1])];
}
catch(err) {eiv.p_1=["",[[],[],[]] ];}
try {
eiv.p_0=[p[2][0],splitPagina(p[2][1])];
eiv.user=eiv.p_0[1][0].match(/user=\"([^"]+)\" \/>/)[1];
eiv.level=eiv.p_0[1][0].match(/level=\"(\d+)\" /)[1];
eiv.header=$.trim(eiv.p_0[1][0].replace(/<noinclude\><pagequality.+?>/,"").replace("</noinclude>",""));
eiv.footer=$.trim(eiv.p_0[1][2].replace("<noinclude>","").replace("<references/>","").replace("</noinclude>",""));
$("#wpHeaderTextbox").val(eiv.header);
$("#wpFooterTextbox").val(eiv.footer);
$("wpTextbox1").val(eiv.p_0[1][1]);
}
catch(err) {eiv.p_0=["",[[],[],[]] ];}
} );
}
})($,mw);