Utilisateur:Dr Brains/LiveRC/VisualeditorTagExtension.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/* ************************************************************************************************************************************************
// Extension de LiveRC
 
// Permet de :
// * Filtrer les modifications par mode d'édition (Visual Editor ou Wikitexte)
// * Modifier l'apparence des modification faites avec le Visual Editor
 
 
{{Catégorisation JS|LiveRC}} 
 
************************************************************************************************************************************************ */
if (typeof(lrcHooks)!="undefined") { // DÉBUT IF

/* ************************************************************************************************************************************************ */

/* Personnalisations */

// Paramètres
try{
lrcParams["VISUALEDITOR_ModifyTag"] = true;
}catch(e){ }

// Options
try{
lrcOptionMenuValues.VISUALEDITOR = false;
lrcOptionMenuValues.VISUALEDITOR_NEW = true;
lrcOptionMenuValues.VISUALEDITOR_OLD = true;
}catch(e){ }
 
// textes
try{
lrcTexts.VISUALEDITOR_SHORT = "Édition";
lrcTexts.VISUALEDITOR_TIP = "Filter selon le mode d’édition";
lrcTexts.VISUALEDITOR_SHORT_NEW = "Visual editor";
lrcTexts.VISUALEDITOR_SHORT_OLD = "Wikitexte";
lrcTexts.VISUALEDITOR_Tag_Title = "Visual editor";
}catch(e){ }
 
// Icônes
try{
lrcIcons["VISUALEDITOR_Tag"] = {"type":0,
                               "src":"thumb/1/12/VisualEditor-logo.svg/50px-VisualEditor-logo.svg.png",
                               "width":50,
                               "height":18
}
}catch(e){ }
 
// Descriptions
try{
lrcParamDesc["DescVISUALEDITOR_ModifyTag"] = '[VisualeditorTag] Modifier le rendu des modifs Visual Editor';
lrcParamDesc["DescVISUALEDITOR"]           = '[VisualeditorTag] Case "Édition"';
lrcParamDesc["DescVISUALEDITOR_NEW"]       = '[VisualeditorTag] Case "Visual editor"';
lrcParamDesc["DescVISUALEDITOR_OLD"]       = '[VisualeditorTag] Case "Wikitexte"';
lrcParamDesc["DescVISUALEDITOR_SHORT"]     = '[VisualeditorTag] Texte de la case "Édition"';
lrcParamDesc["DescVISUALEDITOR_TIP"]       = '[VisualeditorTag] Infobulle de la case "Édition"';
lrcParamDesc["DescVISUALEDITOR_SHORT_NEW"] = '[VisualeditorTag] Texte de la case "Visual editor"';
lrcParamDesc["DescVISUALEDITOR_SHORT_OLD"] = '[VisualeditorTag] Texte de la case "Wikitexte"';
lrcParamDesc["DescVISUALEDITOR_Tag"]       = '[VisualeditorTag] Modif avec Visual Editor';
lrcParamDesc["DescVISUALEDITOR_Tag_Title"] = "[VisualeditorTag] Tooltip de l’icône Visual editor";
}catch(e){ }


/* Code */

function LiveRC_VisualeditorTagExtension_getOptions(){
  var Options = [
    {value:"NEW",text:lrcMakeText("VISUALEDITOR_SHORT_NEW")},
    {value:"OLD",text:lrcMakeText("VISUALEDITOR_SHORT_OLD")}
  ];
  return Options;
}

function LiveRC_VisualeditorTagExtension_AddButton(){    
    var UserTypeForm = document.getElementById('UserTypeForm');
    if(!UserTypeForm) return;

  var ModeSelectionForm = document.createElement('form');   
  ModeSelectionForm.id ="EditTypeForm";
  var FormContent = ''
    + '<span title="' + lrcMakeText("VISUALEDITOR_TIP") + '" style="padding:3px;">'
    + '<input id="showEditType" type="checkbox" '+(lrcMakeOption("VISUALEDITOR") ? 'checked="checked"':'')+' />'
    + '<label for="showEditType">' + lrcMakeText("VISUALEDITOR_SHORT")  + ' </label>'
    + '</span>';
  ModeSelectionForm.innerHTML = FormContent;
  UserTypeForm.parentNode.insertBefore(ModeSelectionForm, UserTypeForm.nextSibling);
  var SepSpan = document.createElement('span');
  SepSpan.appendChild(document.createTextNode("·"));
  UserTypeForm.parentNode.insertBefore(SepSpan, UserTypeForm.nextSibling);
  addEdittypesCheckInMenu();
}
LiveRC_AddHook("AfterOptions", LiveRC_VisualeditorTagExtension_AddButton);

function addEdittypesCheckInMenu(){
  var Lines = new Array();
  var options = new Array("NEW", "OLD");
  for(var a=0,l=options.length;a<l;a++){
    var opt = options[a];
    var text = lrcMakeText("VISUALEDITOR_SHORT_"+opt);
    var checked = ( lrcMakeOption("VISUALEDITOR_"+opt) ? ' checked="checked" ' : '');
    var LineContent = '<input id="showEditType_'+opt+'" type="checkbox" value="'+opt+'" ' + checked + ' />'
                    + '<label for="showEditType_'+opt+'">' + text + ' </label>';
    Lines.push(LineContent);
  }
  createChecklistMenu("showEditType", Lines);
}

function LiveRC_VisualeditorTagExtension_CheckLine(Args){
    var TR = document.getElementById(Args.id);
    if (!TR) return;
    var rc = Args.rc;
    var visualeditortag = false; 
    var MustBeDeleted = false;
    var EditorFilter = document.getElementById("showEditType");
    var EditorFilerEnabled = EditorFilter.checked;
    if(lrcHasState(rc.state, "TAG")){
      var tags = rc.tags;     
      for(var a=0,l=tags.length;a<l;a++){
        var tagname = (tags[a].firstChild ? tags[a].firstChild.nodeValue : "");
        if(tagname == "visualeditor" ){
          visualeditortag = true; 
          $(TR).addClass("RcVisualEditor");
        }
      }
    }
    var ShowVisualEditor = document.getElementById("showEditType_NEW");
    var ShowWikitext = document.getElementById("showEditType_OLD");
    if(EditorFilerEnabled && ShowVisualEditor && !ShowVisualEditor.checked &&  visualeditortag) MustBeDeleted = true;
    if(EditorFilerEnabled && ShowWikitext && !ShowWikitext.checked &&  !visualeditortag) MustBeDeleted = true;

    if(MustBeDeleted && !lrcHasState(rc.state, "LOG")){
      supprLigne(TR.id);
    }else if(visualeditortag && lrcMakeParam("VISUALEDITOR_ModifyTag")){
      LiveRC_VisualeditorTagExtension_ToggleTag(TR, rc);
    }
}
LiveRC_AddHook("AfterRC", LiveRC_VisualeditorTagExtension_CheckLine);


function LiveRC_VisualeditorTagExtension_ToggleTag(TR, rc){
  var temp = new Array();
  var tags = rc.tags;
  for(var a=0,l=tags.length;a<l;a++){
    var tagname = (tags[a].firstChild ? tags[a].firstChild.nodeValue : "");
    if(tagname != "visualeditor" ){
      temp.push('<span class="tagName">' + tagname + '</span>');
    }else{
      rc.state = lrcAddState(rc.state, "VISUALEDITOR");
    }        
  }
  var CommentTD = TR.querySelector('td.td3RC');
  if(!CommentTD) return;
  if(temp.length ===0){
    /* Remove all tags */
    $(TR).removeClass("RcTag");
    var BR = CommentTD.getElementsByTagName('br')[0];
    if(BR){
      while(BR.nextSibling){ BR.parentNode.removeChild(BR.nextSibling); };
      BR.parentNode.removeChild(BR);
    }
  }else{
    /* Remove only visualeditor tag */
    var TagList = CommentTD.querySelector('span.tagList');
    if(TagList) TagList.innerHTML = temp.join(" | ");
  }
  var Icon = document.createElement('span');
  Icon.id = "VisualEditorIcon"; 
  Icon.setAttribute("style", "float:right;");
  Icon.innerHTML = lrcMakeIcon("VISUALEDITOR_Tag");
  CommentTD.insertBefore(Icon, CommentTD.firstChild);
}


/* ************************************************************************************************************************************************ */
} // FIN IF