MediaWiki:AboutArticle.js: различия между версиями

Материал из ЕЖЕВИКИ - EJWiki.org - Академической Вики-энциклопедии по еврейским и израильским темам
Перейти к навигацииПерейти к поиску
Arielybot (обсуждение | вклад)
м Замена текста — «| АВТОР1» на «| АВТОР»
 
BorisG (обсуждение | вклад)
Нет описания правки
 
Строка 8: Строка 8:
// For a description, see [[User:Mr.Z-man/refToolbar]]
// For a description, see [[User:Mr.Z-man/refToolbar]]


var numforms = 0;
//modified to work with new Wiki API - 2014-11-04 - BaruchG
var numforms1 = 0;
//modified to change the template fields - 2014-11-04 - BaruchG
//modified to change the template fields - 2014-11-13 - BaruchG
 
//var numforms = 0;
//var numforms1 = 0;
//var isIE = detectIE();
 
var supervisors = [
      ["0", ""],
      ["1", "Пинхас Полонский"],
      ["2", "Арье Ольман"],
      ["3", "Шломо Коль-Яаков"],
      ["4", "Александр Черницкий"],
      ["5", "Борис Гулько"],
      ["6", "Леви Китросский"],
      ["7", "Г. Ахиезер"],
      ["8", "Анна Гейфман"],
      ["9", "Ш. Гендельман"],
      ["10", "Илья Дворкин"],
      ["11", "Давид Копелиович"],
      ["12", "М. Левинов"],
      ["13", "Л. Прайсман"],
      ["14", "Михаэль Рыжик"],
      ["15", "Тали Тамарин"],
      ["16", "Яков Файтельсон"],
      ["17", "Зеев Ханин"],
      ["18", "Велвл Чернин"],
      ["19", "М. Шерман"],
      ["20", "Михаил Шнейдер"],
      ["21", "Ася Энтова"],
      ["22", "Моше Гончарок"]
];


function Articlebutton() {
function Articlebutton() {
  if (mwCustomEditButtons && document.getElementById('toolbar') ) {
  if (document.getElementById('wpTextbox1')) {
    button = document.createElement('a');
//      if (document.getElementById('toolbar')) {
    button.href = "javascript:easyArticleMain()";
//    var button = document.createElement('a');
    button.title = "Добавить шаблон О_статье";
//    button.href = "javascript:easyArticleMain()";
    buttonimage = document.createElement('img');
//    button.title = "Добавить шаблон О_статье";
    buttonimage.src = "http://upload.wikimedia.org/wikipedia/commons/9/9f/Button_defaultsort.png";
//    buttonimage = document.createElement('img');
    buttonimage.alt = "Вставить описание статьи";
//    buttonimage.src = "http://upload.wikimedia.org/wikipedia/commons/9/9f/Button_defaultsort.png";
    button.appendChild(buttonimage);
//    buttonimage.alt = "Вставить описание статьи";
    var toolbar = document.getElementById('toolbar');
//    button.appendChild(buttonimage);
    if (navigator.userAgent.indexOf('MSIE') == -1) {
//    var toolbar = document.getElementById('toolbar');
      if (toolbar.style != null) {
 
        toolbar.style.height = 'auto';
      var toolbar = jQuery('#wikiEditor-ui-toolbar').find('.group-insert')[0];
      var buttonTitle = "Добавить шаблон О_статье";
      var buttonImageSrc = "http://upload.wikimedia.org/wikipedia/commons/9/9f/Button_defaultsort.png";
//    var buttonimageAlt = "Вставить описание статьи";
 
 
//      if (!isIE) { //navigator.userAgent.indexOf('MSIE') == -1) {
//        if (toolbar.style != null) {
//            toolbar.style.height = 'auto';
//        }
//        else {
//            toolbar.setAttribute('style', 'margin-bottom: 6px; height: auto;');
//        }
//        toolbar.appendChild(button);
 
      try {
        jQuery('#wpTextbox1').wikiEditor('addToToolbar', {
            section: 'advanced',
            group: 'insert',
            tools: {
              buttonId: {
                  label: buttonTitle,
                  type: 'button',
                  icon: buttonImageSrc,
                  action: {
                    type: 'callback',
                    execute: function(context) {
                        easyArticleMain();
                    }
                  }
              }
            }
        });
      } catch (e) {
        console.log(e.message);
       }
       }
      else {
//
      toolbar.setAttribute('style', 'margin-bottom: 6px; height: auto;');
       var articlemain = document.createElement('div');
      }
      toolbar.appendChild(button);
       articlemain = document.createElement('div');
       articlemain.style.display = 'none';
       articlemain.style.display = 'none';
       articlemain.style.margin = '0.2em 0 -0.2em 0';
       articlemain.style.margin = '0.2em 0 -0.2em 0';
       articlemain.setAttribute('Id', 'articleselect');
       articlemain.setAttribute('Id', 'articleselect');
       articlemain.appendChild( addOption("aboutArticle()", "О статье") );
       articlemain.appendChild(addOption("aboutArticle()", "О статье"));
       articlemain.appendChild( addOption("aboutTemplate()", "?") );
       articlemain.appendChild(addOption("aboutTemplate()", "?"));
       articlemain.appendChild( addOption("hideInit()", "Отмена") );
       articlemain.appendChild(addOption("hideInit()", "Отмена"));
       toolbar.appendChild(articlemain);
       toolbar.appendChild(articlemain);
    }
//      }
    else {
//      else {
      toolbar.appendChild(button);
//        toolbar.appendChild(button);
      selection = '<div id="articleselect" style="display:none"><input type="button" value="О статье" onclick="aboutArticle()" />'+
//        selection = '<div id="articleselect" style="display:none"><input type="button" value="О статье" onclick="aboutArticle()" />' +
      '<input type="button" value="?" onclick="aboutTemplate()" />'+
//            '<input type="button" value="?" onclick="aboutTemplate()" />' +
      '<input type="button" value="Отмена" onclick="hideInit()" /></div>';
//            '<input type="button" value="Отмена" onclick="hideInit()" /></div>';
      document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML;
//        document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML;
    }
//      }
  }
  }
}
}


function addOption(script, text) {
function addOption(script, text) {
   option = document.createElement('input');
   var option = document.createElement('input');
   option.setAttribute('type', 'button');
   option.setAttribute('type', 'button');
   option.setAttribute('onclick', script);
   option.setAttribute('onclick', script);
Строка 55: Строка 117:
   return option;
   return option;
}
}
 
function hideInit() {
function hideInit() {
   document.getElementById('articleselect').style.display = 'none';
   document.getElementById('articleselect').style.display = 'none';
   oldFormHide1();
   oldFormHide1();
}
}
 
function oldFormHide1() {
function oldFormHide1() {
  if (numforms != 0) {
//  if (numforms != 0) {
    document.getElementById('articlediv'+numforms).style.display = 'none';
//    document.getElementById('articlediv'+numforms).style.display = 'none';
  }
//  }
  if (numforms1 != 0) {
//  if (numforms1 != 0) {
    document.getElementById('helpdiv'+numforms1).style.display = 'none';
//    document.getElementById('helpdiv'+numforms1).style.display = 'none';
  }
//  }
 
  jQuery('#articlediv1').css("display", 'none');
  jQuery('#helpdiv1').css("display", 'none');
}
}
 
function easyArticleMain() {
function easyArticleMain() {
   document.getElementById('articleselect').style.display = '';
   document.getElementById('articleselect').style.display = '';
}
}
 
function getTime() {
function getTime() {
   var time = new Date();
   var time = new Date();
Строка 82: Строка 145:
   if (nowmonth<10) { nowmonth = "0"+ nowmonth.toString(); }
   if (nowmonth<10) { nowmonth = "0"+ nowmonth.toString(); }
   var nowyear = time.getUTCFullYear();
   var nowyear = time.getUTCFullYear();
   newtime =  nowdate + '/' + nowmonth + '/' + nowyear;
   var newtime =  nowdate + '/' + nowmonth + '/' + nowyear;
   return (newtime);
   return (newtime);
}
}


function aboutTemplate() {
function aboutTemplate() {
  oldFormHide1();
  oldFormHide1();
  var legend;
  var legend;
 
  legend = "Справка";
//  numforms1++;


  legend = "Справка";
  var form = '<div id="helpdiv1" style="background-color:white">' +
  numforms1++;
      '<fieldset><legend>' + legend + '</legend>' +
      '{{О_статье  <br>' +
      '| ТИП СТАТЬИ            =  <br>' +
      '&nbsp;&nbsp;&nbsp;1. Регулярная статья<br>' +
      '&nbsp;&nbsp;&nbsp;2. Регулярная исправленная статья<br>' +
//  '&nbsp;&nbsp;&nbsp;3. Статья-справка<br>'+
//  '&nbsp;&nbsp;&nbsp;4. Текст унаследован из Википедии<br>'+
      '&nbsp;&nbsp;&nbsp;3. Служебная статья<br>' +
      '| АВТОР1                =  <br>' +
      '| АВТОР2                =  <br>' +
      '| АВТОР3                =  <br>' +
      '| СУПЕРВАЙЗЕР          =  <br>' +
      '| ПРОЕКТ                =  <br>' +
//'| ПОДТЕМА              =  <br>'+
//'| КАЧЕСТВО              =  <br>'+
//'| УРОВЕНЬ              =  <br>'+
      '| ДАТА СОЗДАНИЯ        =  <br>' +
//'| ВИКИПЕДИЯ            =  <br>'+
//'| НЕОДНОЗНАЧНОСТЬ      =  <br>'+
      '}} <br> <br>' +
      '</fieldset></div>';


  form = '<div id="helpdiv'+numforms1+'">'+
  if (jQuery('#helpdiv1').length > 0) {
    '<fieldset><legend>'+legend+'</legend>'+
       jQuery('#helpdiv1').replaceWith(form);
       '{{О_статье  <br>'+
  } else {
'| ТИП СТАТЬИ            =  <br>'+
       document.getElementById('articleselect').innerHTML += form;
  '&nbsp;&nbsp;&nbsp;1. Регулярная статья<br>'+
  }
  '&nbsp;&nbsp;&nbsp;2. Регулярная исправленная статья<br>'+
  '&nbsp;&nbsp;&nbsp;3. Статья-справка<br>'+
  '&nbsp;&nbsp;&nbsp;4. Текст унаследован из Википедии<br>'+
  '&nbsp;&nbsp;&nbsp;5. Служебная статья<br>'+
'| АВТОР                =  <br>'+
'| АВТОР2                =  <br>'+
'| АВТОР3                =  <br>'+
'| СУПЕРВАЙЗЕР          =  <br>'+
'| ПРОЕКТ                =  <br>'+
'| ПОДТЕМА              =  <br>'+
'| КАЧЕСТВО              =  <br>'+
'| УРОВЕНЬ              =  <br>'+
'| ДАТА СОЗДАНИЯ        =  <br>'+
'| ВИКИПЕДИЯ            =  <br>'+
'| НЕОДНОЗНАЧНОСТЬ       =  <br>'+
'}} <br> <br>'+
    '</fieldset></div>';
    document.getElementById('articleselect').innerHTML += form;
}
}


function aboutArticle() {
function aboutArticle() {
  oldFormHide1();
  oldFormHide1();
  var legend;
  var legend;
   template = "О_статье";
  var template = "О_статье";
 
  legend = "Описание статьи";
  var newtime = getTime();
//   numforms++;
 
  var form = '<div id="articlediv1" style="background-color:white">' +
      '<fieldset><legend>' + legend + '</legend>' +
      '<table cellspacing="6">' +
      '<input type="hidden" value="' + template + '" id="template">' +
 
      '<tr>' +
      '<td width="150"><label for="АВТОР1">&nbsp;основной автор: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР1"></td>' +
      '<td width="150"><label for="ТИП СТАТЬИ">&nbsp;&nbsp;&nbsp;тип статьи: </label></td>' +
      '<td width="80">' +
      '<SELECT NAME="ТИП СТАТЬИ" SIZE=0 id="typebox">' +
      '<OPTION VALUE="0"></option>' +
      '<OPTION VALUE="1">1. Регулярная статья</option>' +
      '<OPTION VALUE="2">2. Регулярная исправленная статья</option>' +
      //      '<OPTION VALUE="3">3. Статья-справка</option>' +
      //      '<OPTION VALUE="4">4. Текст унаследован из Википедии</option>' +
      '<OPTION VALUE="3">3. Служебная статья</option>' +
      '</SELECT>' +
      '</td>' +
      '</tr>' +
 
      '<tr>' +
      '<td width="150"><label for="АВТОР2">&nbsp;автор 2: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР2"></td>' +
//      '<td width="150"><label for="УРОВЕНЬ">&nbsp;&nbsp;&nbsp;энциклопедический &nbsp;&nbsp;&nbsp;уровень: </label></td>' +
//      '<td width="80"><SELECT NAME="УРОВЕНЬ" SIZE=0 id="level">' +
//      '<OPTION VALUE="0"></option>' +
//      '<OPTION VALUE="1">I. Обычная статья</option>' +
//      '<OPTION VALUE="2">II. Корневая статья</option>' +
//      '<OPTION VALUE="3">III. Краткое общее объяснение</option>' +
//      '<OPTION VALUE="4">IV. Детальное и техническое обсуждение</option></SELECT></td>' +
      '</tr>' +
 
      '<tr>' +
      '<td width="150"><label for="АВТОР3">&nbsp;автор 3: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР3"></td>' +
//      '<td width="150"><label for="КАЧЕСТВО">&nbsp;&nbsp;&nbsp;качество: </label></td>' +
//      '<td width="80"><SELECT NAME="КАЧЕСТВО" SIZE=0 id="quality">' +
//      '<OPTION VALUE="0"></option>' +
//      '<OPTION VALUE="1">25%</option>' +
//      '<OPTION VALUE="2">50%</option>' +
//      '<OPTION VALUE="3">75%</option>' +
//      '<OPTION VALUE="4">100%</option></SELECT></td>' +
      '</tr>' +


  legend = "Описание статьи";
      '<tr><td width="200"><label for="СУПЕРВАЙЗЕР">&nbsp;академический &nbsp;супервайзер: </label></td>' +
  newtime = getTime();
      '<td width="100">' +
  numforms++;


  form = '<div id="articlediv'+numforms+'">'+
       '<SELECT NAME="СУПЕРВАЙЗЕР" SIZE=0 id="supervisor">';
    '<fieldset><legend>'+legend+'</legend>'+
      for (var i = 0; i < supervisors.length; i++) {
    '<table cellspacing="6">'+
        form += '<OPTION VALUE="' + supervisors[i][0] + '">' + supervisors[i][1] + '</option>';
    '<input type="hidden" value="'+template+'" id="template">'+
       }
    '<tr><td width="150"><label for="АВТОР1">&nbsp;основной автор: </label></td>'+
      form += '</SELECT>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР1"></td>'+
    '<td width="150"><label for="ТИП СТАТЬИ">&nbsp;&nbsp;&nbsp;тип статьи: </label></td>'+
       '<td width="80"><SELECT NAME="ТИП СТАТЬИ" SIZE=0 id="typebox">'+
            '<OPTION VALUE="0"></option>'+
            '<OPTION VALUE="1">1. Регулярная статья</option>'+
            '<OPTION VALUE="2">2. Регулярная исправленная статья</option>'+
            '<OPTION VALUE="3">3. Статья-справка</option>'+
            '<OPTION VALUE="4">4. Текст унаследован из Википедии</option>'+
            '<OPTION VALUE="5">5. Служебная статья</option></SELECT></td></tr>'+
    '<tr><td width="150"><label for="АВТОР2">&nbsp;автор 2: </label></td>'+
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР2"></td>'+
    '<td width="150"><label for="УРОВЕНЬ">&nbsp;&nbsp;&nbsp;энциклопедический &nbsp;&nbsp;&nbsp;уровень: </label></td>'+
       '<td width="80"><SELECT NAME="УРОВЕНЬ" SIZE=0 id="level">'+
            '<OPTION VALUE="0"></option>'+
            '<OPTION VALUE="1">I. Общий обзор темы</option>'+
            '<OPTION VALUE="2">II. Начальное введение в тему</option>'+
            '<OPTION VALUE="3">III. Популярное изложение темы</option>'+
            '<OPTION VALUE="4">IV. Академическая статья</option></SELECT></td></tr>'+


    '<tr><td width="150"><label for="АВТОР3">&nbsp;автор 3: </label></td>'+
      '</td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР3"></td>'+
//      '<td width="150"><label for="ВИКИПЕДИЯ">&nbsp;&nbsp;&nbsp;в Википедии: </label></td>' +
    '<td width="150"><label for="КАЧЕСТВО">&nbsp;&nbsp;&nbsp;качество: </label></td>'+
//      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ВИКИПЕДИЯ"></td>' +
       '<td width="80"><SELECT NAME="КАЧЕСТВО" SIZE=0 id="quality">'+
       '</tr>' +
            '<OPTION VALUE="0"></option>'+
            '<OPTION VALUE="1">25%</option>'+
            '<OPTION VALUE="2">50%</option>'+
            '<OPTION VALUE="3">75%</option>'+
            '<OPTION VALUE="4">100%</option></SELECT></td></tr>'+


    '<tr><td width="200"><label for="СУПЕРВАЙЗЕР">&nbsp;академический &nbsp;супервайзер: </label></td>'+
      '<tr>' +
       '<td width="100"><SELECT NAME="СУПЕРВАЙЗЕР" SIZE=0 id="supervisor">'+
      '<td width="150"><label for="ПРОЕКТ">&nbsp;тематический &nbsp;проект: </label></td>' +
            '<OPTION VALUE="0"></option>'+
       '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ПРОЕКТ"></td>' +
            '<OPTION VALUE="1">Пинхас Полонский</option></SELECT></td>'+
//     '<td width="150"><label for="НЕОДНОЗНАЧНОСТЬ">&nbsp;&nbsp;&nbsp;разрешение &nbsp;&nbsp;&nbsp;неоднозначности: </label></td>' +
    '<td width="150"><label for="ВИКИПЕДИЯ">&nbsp;&nbsp;&nbsp;в Википедии: </label></td>'+
//      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="НЕОДНОЗНАЧНОСТЬ"></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ВИКИПЕДИЯ"></td></tr>'+
      '</tr>' +


    '<tr><td width="150"><label for="ПРОЕКТ">&nbsp;тематический &nbsp;проект: </label></td>'+
      '<tr>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ПРОЕКТ"></td>'+
//      '<td width="150"><label for="ПОДТЕМА">&nbsp;подтема: </label></td>' +
    '<td width="150"><label for="НЕОДНОЗНАЧНОСТЬ">&nbsp;&nbsp;&nbsp;разрешение &nbsp;&nbsp;&nbsp;неоднозначности: </label></td>'+
//      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ПОДТЕМА"></td>' +
       '<td width="300"><input type="text" tabindex=1 style="width:100%" id="НЕОДНОЗНАЧНОСТЬ"></td></tr>'+
      '<td width="150"><label for="ДАТА СОЗДАНИЯ">&nbsp;&nbsp;&nbsp;дата &nbsp;&nbsp;&nbsp;создания: </label></td>' +
       '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ДАТА СОЗДАНИЯ" value="' + newtime + '"></td>' +
      '</tr>' +


    '<tr><td width="150"><label for="ПОДТЕМА">&nbsp;подтема: </label></td>'+
      '</table>' +
       '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ПОДТЕМА"></td>'+
       '<input type="button" value="Добавить" onClick="addtemplate()">' +
    '<td width="150"><label for="ДАТА СОЗДАНИЯ">&nbsp;&nbsp;&nbsp;дата &nbsp;&nbsp;&nbsp;создания: </label></td>'+
       '</fieldset></div>';
       '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ДАТА СОЗДАНИЯ" value="'+ newtime +'"></td></tr>'+


    '</table>'+
  if (jQuery('#articlediv1').length > 0) {
    '<input type="button" value="Добавить" onClick="addtemplate()">'+
      jQuery('#articlediv1').replaceWith(form);
'</fieldset></div>';
   } else {
   document.getElementById('articleselect').innerHTML += form;
      document.getElementById('articleselect').innerHTML += form;
  }
}
}


function addtemplate() {
function addtemplate() {
  cites = document.getElementById('articlediv'+numforms).getElementsByTagName('input');
  var cites = document.getElementById('articlediv1').getElementsByTagName('input');
  var citebegin = '';
  var citebegin = '';
  var citeinner = '';
  var citeinner = '';


if (document.getElementById ('typebox').selectedIndex !="0") {
  if (document.getElementById('typebox').selectedIndex != "0") {
       citeinner += "\n|" + document.getElementById ('typebox').name + "=" + document.getElementById ('typebox').selectedIndex;
       citeinner += "\n|" + document.getElementById('typebox').name + "=" + document.getElementById('typebox').selectedIndex;
  }
  }
else {
  else {
  citeinner += "\n|" + document.getElementById ('typebox').name + "="
      citeinner += "\n|" + document.getElementById('typebox').name + "="
  }
  }
if (document.getElementById ('supervisor').selectedIndex !="0") {
  if (document.getElementById('supervisor').selectedIndex != "0") {
       citeinner += "\n|" + document.getElementById ('supervisor').name + "=" + document.getElementById ('supervisor').selectedIndex;
       citeinner += "\n|" + document.getElementById('supervisor').name + "=" + document.getElementById('supervisor').selectedIndex;
  }
  }
else {
  else {
  citeinner += "\n|" + document.getElementById ('supervisor').name + "="
      citeinner += "\n|" + document.getElementById('supervisor').name + "="
  }
  }
if (document.getElementById ('level').selectedIndex !="0") {
//  if (document.getElementById('level').selectedIndex != "0") {
      citeinner += "\n|" + document.getElementById ('level').name + "=" + document.getElementById ('level').selectedIndex;
//      citeinner += "\n|" + document.getElementById('level').name + "=" + document.getElementById('level').selectedIndex;
   }
//   }
else {
//  else {
  citeinner += "\n|" + document.getElementById ('level').name + "="
//      citeinner += "\n|" + document.getElementById('level').name + "="
   }
//   }
if (document.getElementById ('quality').selectedIndex !="0") {
//  if (document.getElementById('quality').selectedIndex != "0") {
      citeinner += "\n|" + document.getElementById ('quality').name + "=" + document.getElementById ('quality').selectedIndex;
//      citeinner += "\n|" + document.getElementById('quality').name + "=" + document.getElementById('quality').selectedIndex;
   }
//   }
else {
//  else {
  citeinner += "\n|" + document.getElementById ('quality').name + "="
//      citeinner += "\n|" + document.getElementById('quality').name + "="
   }
//   }


  for (var i=0; i<cites.length-1; i++) {
  for (var i = 0; i < cites.length - 1; i++) {
    if (cites[i].id != "template") {
      if (cites[i].id != "template") {
      citeinner += "\n|" + cites[i].id + "=" + cites[i].value;
        citeinner += "\n|" + cites[i].id + "=" + cites[i].value;
    }
      }
    else if (cites[i].id == "template") {
      else if (cites[i].id == "template") {
      citebegin = '{{' + cites[i].value;
        citebegin = '{{' + cites[i].value;
    }
      }
  }
  }


  cite = citebegin + citeinner + "\n}}\n";
  var cite = citebegin + citeinner + "\n}}\n";
  insertTags(cite, '', '');
  insertTags(cite, '', '');
   document.getElementById('articlediv'+numforms).style.display = 'none';
//   insertFilledTemplate(cite);
  document.getElementById('articlediv1').style.display = 'none';
}
}


//function detectIE() {
////  return doXjo.isIE;
//  var ieVersion;
//  try {
//    if (jQuery.browser.msie) {
//      ieVersion = jQuery.browser.version;
//      ieVersion = parseInt(extractSubstring(ieVersion, "", "."));
////      console.debug("!!!!");
//    }
//    else if (jQuery.browser.mozilla && jQuery.browser.version === "11.0") {
//      ieVersion = 11;
//    }
//  } catch (e) {
////    console.debug("----");
//  }
//
//  return ieVersion;
//}
//
//function extractSubstring(value,startstring,endstring, ignoreCase){
//  var valueString;
//  if (ignoreCase) {
//    valueString = value.toLowerCase();
//    startstring = startstring.toLowerCase();
//    endstring = endstring.toLowerCase();
//  } else {
//    valueString = value;
//  }
//  var startIndex = valueString.indexOf(startstring);
//  var endIndex = valueString.indexOf(endstring, startIndex+1);
//  if(startIndex != -1){
//    if(endIndex != null && endIndex > startIndex)
//    return value.substring(startIndex + startstring.length,endIndex);
//    else
//    return value.substring(startIndex + startstring.length);
//  }
//  else
//    return value;
//}// end function
//function insertFilledTemplate(filledTemplate) {
//    jQuery('#wpTextbox1').wikiEditor("setContent", filledTemplate);
//}
//hookEvent("load", Articlebutton);
//hookEvent("load", Articlebutton);
addOnloadHook(Articlebutton);
//addOnloadHook(Articlebutton);
//$(document).ready(function(){
//  setTimeout(Articlebutton, 1000);
//});
 
jQuery( '#wpTextbox1' ).on('wikiEditor-toolbar-doneInitialSections', function () {
    Articlebutton();
});

Текущая версия от 18:40, 13 ноября 2014

//  ____________________________________________________________________________________________
// |                                                                                            |
// |                    Основано на версии 264413579 гаджета refToolbar.js                      |
// | (http://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-refToolbar.js&oldid=264413579) |
// |____________________________________________________________________________________________|
//
// Imported from revision 264412998 as of 2009-01-16T05:53:39 from [[User:Mr.Z-man/refToolbar.js]]
// For a description, see [[User:Mr.Z-man/refToolbar]]

//modified to work with new Wiki API - 2014-11-04 - BaruchG
//modified to change the template fields - 2014-11-04 - BaruchG
//modified to change the template fields - 2014-11-13 - BaruchG

//var numforms = 0;
//var numforms1 = 0;
//var isIE = detectIE();

var supervisors = [
      ["0", ""],
      ["1", "Пинхас Полонский"],
      ["2", "Арье Ольман"],
      ["3", "Шломо Коль-Яаков"],
      ["4", "Александр Черницкий"],
      ["5", "Борис Гулько"],
      ["6", "Леви Китросский"],
      ["7", "Г. Ахиезер"],
      ["8", "Анна Гейфман"],
      ["9", "Ш. Гендельман"],
      ["10", "Илья Дворкин"],
      ["11", "Давид Копелиович"],
      ["12", "М. Левинов"],
      ["13", "Л. Прайсман"],
      ["14", "Михаэль Рыжик"],
      ["15", "Тали Тамарин"],
      ["16", "Яков Файтельсон"],
      ["17", "Зеев Ханин"],
      ["18", "Велвл Чернин"],
      ["19", "М. Шерман"],
      ["20", "Михаил Шнейдер"],
      ["21", "Ася Энтова"],
      ["22", "Моше Гончарок"]
];

function Articlebutton() {
   if (document.getElementById('wpTextbox1')) {
//      if (document.getElementById('toolbar')) {
//    var button = document.createElement('a');
//    button.href = "javascript:easyArticleMain()";
//    button.title = "Добавить шаблон О_статье";
//    buttonimage = document.createElement('img');
//    buttonimage.src = "http://upload.wikimedia.org/wikipedia/commons/9/9f/Button_defaultsort.png";
//    buttonimage.alt = "Вставить описание статьи";
//    button.appendChild(buttonimage);
//    var toolbar = document.getElementById('toolbar');

      var toolbar = jQuery('#wikiEditor-ui-toolbar').find('.group-insert')[0];
      var buttonTitle = "Добавить шаблон О_статье";
      var buttonImageSrc = "http://upload.wikimedia.org/wikipedia/commons/9/9f/Button_defaultsort.png";
//    var buttonimageAlt = "Вставить описание статьи";


//      if (!isIE) { //navigator.userAgent.indexOf('MSIE') == -1) {
//         if (toolbar.style != null) {
//            toolbar.style.height = 'auto';
//         }
//         else {
//            toolbar.setAttribute('style', 'margin-bottom: 6px; height: auto;');
//         }
//         toolbar.appendChild(button);

      try {
         jQuery('#wpTextbox1').wikiEditor('addToToolbar', {
            section: 'advanced',
            group: 'insert',
            tools: {
               buttonId: {
                  label: buttonTitle,
                  type: 'button',
                  icon: buttonImageSrc,
                  action: {
                     type: 'callback',
                     execute: function(context) {
                        easyArticleMain();
                     }
                  }
               }
            }
         });
      } catch (e) {
         console.log(e.message);
      }
//
      var articlemain = document.createElement('div');
      articlemain.style.display = 'none';
      articlemain.style.margin = '0.2em 0 -0.2em 0';
      articlemain.setAttribute('Id', 'articleselect');
      articlemain.appendChild(addOption("aboutArticle()", "О статье"));
      articlemain.appendChild(addOption("aboutTemplate()", "?"));
      articlemain.appendChild(addOption("hideInit()", "Отмена"));
      toolbar.appendChild(articlemain);
//      }
//      else {
//         toolbar.appendChild(button);
//         selection = '<div id="articleselect" style="display:none"><input type="button" value="О статье" onclick="aboutArticle()" />' +
//            '<input type="button" value="?" onclick="aboutTemplate()" />' +
//            '<input type="button" value="Отмена" onclick="hideInit()" /></div>';
//         document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML;
//      }
   }
}

function addOption(script, text) {
  var option = document.createElement('input');
  option.setAttribute('type', 'button');
  option.setAttribute('onclick', script);
  option.setAttribute("value", text);
  return option;
}
 
function hideInit() {
  document.getElementById('articleselect').style.display = 'none';
  oldFormHide1();
}
 
function oldFormHide1() {
//  if (numforms != 0) {
//    document.getElementById('articlediv'+numforms).style.display = 'none';
//  }
//  if (numforms1 != 0) {
//    document.getElementById('helpdiv'+numforms1).style.display = 'none';
//  }
   jQuery('#articlediv1').css("display", 'none');
   jQuery('#helpdiv1').css("display", 'none');
}
 
function easyArticleMain() {
  document.getElementById('articleselect').style.display = '';
}
 
function getTime() {
  var time = new Date();
  var nowdate = time.getUTCDate();
  if (nowdate<10) { nowdate = "0"+ nowdate.toString(); }
  var nowmonth = time.getUTCMonth()+1;
  if (nowmonth<10) { nowmonth = "0"+ nowmonth.toString(); }
  var nowyear = time.getUTCFullYear();
  var newtime =  nowdate + '/' + nowmonth + '/' + nowyear;
  return (newtime);
}

function aboutTemplate() {
   oldFormHide1();
   var legend;

   legend = "Справка";
//  numforms1++;

   var form = '<div id="helpdiv1" style="background-color:white">' +
      '<fieldset><legend>' + legend + '</legend>' +
      '{{О_статье  <br>' +
      '| ТИП СТАТЬИ            =  <br>' +
      '&nbsp;&nbsp;&nbsp;1. Регулярная статья<br>' +
      '&nbsp;&nbsp;&nbsp;2. Регулярная исправленная статья<br>' +
//  '&nbsp;&nbsp;&nbsp;3. Статья-справка<br>'+
//  '&nbsp;&nbsp;&nbsp;4. Текст унаследован из Википедии<br>'+
      '&nbsp;&nbsp;&nbsp;3. Служебная статья<br>' +
      '| АВТОР1                =  <br>' +
      '| АВТОР2                =  <br>' +
      '| АВТОР3                =  <br>' +
      '| СУПЕРВАЙЗЕР           =  <br>' +
      '| ПРОЕКТ                =  <br>' +
//'| ПОДТЕМА               =  <br>'+
//'| КАЧЕСТВО              =  <br>'+
//'| УРОВЕНЬ               =  <br>'+
      '| ДАТА СОЗДАНИЯ         =  <br>' +
//'| ВИКИПЕДИЯ             =  <br>'+
//'| НЕОДНОЗНАЧНОСТЬ       =  <br>'+
      '}} <br> <br>' +
      '</fieldset></div>';

   if (jQuery('#helpdiv1').length > 0) {
      jQuery('#helpdiv1').replaceWith(form);
   } else {
      document.getElementById('articleselect').innerHTML += form;
   }
}

function aboutArticle() {
   oldFormHide1();
   var legend;
   var template = "О_статье";

   legend = "Описание статьи";
   var newtime = getTime();
//   numforms++;

   var form = '<div id="articlediv1" style="background-color:white">' +
      '<fieldset><legend>' + legend + '</legend>' +
      '<table cellspacing="6">' +
      '<input type="hidden" value="' + template + '" id="template">' +

      '<tr>' +
      '<td width="150"><label for="АВТОР1">&nbsp;основной автор: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР1"></td>' +
      '<td width="150"><label for="ТИП СТАТЬИ">&nbsp;&nbsp;&nbsp;тип статьи: </label></td>' +
      '<td width="80">' +
      '<SELECT NAME="ТИП СТАТЬИ" SIZE=0 id="typebox">' +
      '<OPTION VALUE="0"></option>' +
      '<OPTION VALUE="1">1. Регулярная статья</option>' +
      '<OPTION VALUE="2">2. Регулярная исправленная статья</option>' +
      //      '<OPTION VALUE="3">3. Статья-справка</option>' +
      //      '<OPTION VALUE="4">4. Текст унаследован из Википедии</option>' +
      '<OPTION VALUE="3">3. Служебная статья</option>' +
      '</SELECT>' +
      '</td>' +
      '</tr>' +

      '<tr>' +
      '<td width="150"><label for="АВТОР2">&nbsp;автор 2: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР2"></td>' +
//      '<td width="150"><label for="УРОВЕНЬ">&nbsp;&nbsp;&nbsp;энциклопедический &nbsp;&nbsp;&nbsp;уровень: </label></td>' +
//      '<td width="80"><SELECT NAME="УРОВЕНЬ" SIZE=0 id="level">' +
//      '<OPTION VALUE="0"></option>' +
//      '<OPTION VALUE="1">I. Обычная статья</option>' +
//      '<OPTION VALUE="2">II. Корневая статья</option>' +
//      '<OPTION VALUE="3">III. Краткое общее объяснение</option>' +
//      '<OPTION VALUE="4">IV. Детальное и техническое обсуждение</option></SELECT></td>' +
      '</tr>' +

      '<tr>' +
      '<td width="150"><label for="АВТОР3">&nbsp;автор 3: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="АВТОР3"></td>' +
//      '<td width="150"><label for="КАЧЕСТВО">&nbsp;&nbsp;&nbsp;качество: </label></td>' +
//      '<td width="80"><SELECT NAME="КАЧЕСТВО" SIZE=0 id="quality">' +
//      '<OPTION VALUE="0"></option>' +
//      '<OPTION VALUE="1">25%</option>' +
//      '<OPTION VALUE="2">50%</option>' +
//      '<OPTION VALUE="3">75%</option>' +
//      '<OPTION VALUE="4">100%</option></SELECT></td>' +
      '</tr>' +

      '<tr><td width="200"><label for="СУПЕРВАЙЗЕР">&nbsp;академический &nbsp;супервайзер: </label></td>' +
      '<td width="100">' +

      '<SELECT NAME="СУПЕРВАЙЗЕР" SIZE=0 id="supervisor">';
      for (var i = 0; i < supervisors.length; i++) {
         form += '<OPTION VALUE="' + supervisors[i][0] + '">' + supervisors[i][1] + '</option>';
      }
      form += '</SELECT>' +

      '</td>' +
//      '<td width="150"><label for="ВИКИПЕДИЯ">&nbsp;&nbsp;&nbsp;в Википедии: </label></td>' +
//      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ВИКИПЕДИЯ"></td>' +
      '</tr>' +

      '<tr>' +
      '<td width="150"><label for="ПРОЕКТ">&nbsp;тематический &nbsp;проект: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ПРОЕКТ"></td>' +
//      '<td width="150"><label for="НЕОДНОЗНАЧНОСТЬ">&nbsp;&nbsp;&nbsp;разрешение &nbsp;&nbsp;&nbsp;неоднозначности: </label></td>' +
//      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="НЕОДНОЗНАЧНОСТЬ"></td>' +
      '</tr>' +

      '<tr>' +
//      '<td width="150"><label for="ПОДТЕМА">&nbsp;подтема: </label></td>' +
//      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ПОДТЕМА"></td>' +
      '<td width="150"><label for="ДАТА СОЗДАНИЯ">&nbsp;&nbsp;&nbsp;дата &nbsp;&nbsp;&nbsp;создания: </label></td>' +
      '<td width="300"><input type="text" tabindex=1 style="width:100%" id="ДАТА СОЗДАНИЯ" value="' + newtime + '"></td>' +
      '</tr>' +

      '</table>' +
      '<input type="button" value="Добавить" onClick="addtemplate()">' +
      '</fieldset></div>';

   if (jQuery('#articlediv1').length > 0) {
      jQuery('#articlediv1').replaceWith(form);
   } else {
      document.getElementById('articleselect').innerHTML += form;
   }
}

function addtemplate() {
   var cites = document.getElementById('articlediv1').getElementsByTagName('input');
   var citebegin = '';
   var citeinner = '';

   if (document.getElementById('typebox').selectedIndex != "0") {
      citeinner += "\n|" + document.getElementById('typebox').name + "=" + document.getElementById('typebox').selectedIndex;
   }
   else {
      citeinner += "\n|" + document.getElementById('typebox').name + "="
   }
   if (document.getElementById('supervisor').selectedIndex != "0") {
      citeinner += "\n|" + document.getElementById('supervisor').name + "=" + document.getElementById('supervisor').selectedIndex;
   }
   else {
      citeinner += "\n|" + document.getElementById('supervisor').name + "="
   }
//   if (document.getElementById('level').selectedIndex != "0") {
//      citeinner += "\n|" + document.getElementById('level').name + "=" + document.getElementById('level').selectedIndex;
//   }
//   else {
//      citeinner += "\n|" + document.getElementById('level').name + "="
//   }
//   if (document.getElementById('quality').selectedIndex != "0") {
//      citeinner += "\n|" + document.getElementById('quality').name + "=" + document.getElementById('quality').selectedIndex;
//   }
//   else {
//      citeinner += "\n|" + document.getElementById('quality').name + "="
//   }

   for (var i = 0; i < cites.length - 1; i++) {
      if (cites[i].id != "template") {
         citeinner += "\n|" + cites[i].id + "=" + cites[i].value;
      }
      else if (cites[i].id == "template") {
         citebegin = '{{' + cites[i].value;
      }
   }

   var cite = citebegin + citeinner + "\n}}\n";
   insertTags(cite, '', '');
//   insertFilledTemplate(cite);
   document.getElementById('articlediv1').style.display = 'none';
}

//function detectIE() {
////  return doXjo.isIE;
//  var ieVersion;
//  try {
//    if (jQuery.browser.msie) {
//      ieVersion = jQuery.browser.version;
//      ieVersion = parseInt(extractSubstring(ieVersion, "", "."));
////      console.debug("!!!!");
//    }
//    else if (jQuery.browser.mozilla && jQuery.browser.version === "11.0") {
//       ieVersion = 11;
//    }
//  } catch (e) {
////    console.debug("----");
//  }
//
//  return ieVersion;
//}
//
//function extractSubstring(value,startstring,endstring, ignoreCase){
//   var valueString;
//   if (ignoreCase) {
//    valueString = value.toLowerCase();
//    startstring = startstring.toLowerCase();
//    endstring = endstring.toLowerCase();
//   } else {
//    valueString = value;
//   }
//   var startIndex = valueString.indexOf(startstring);
//   var endIndex = valueString.indexOf(endstring, startIndex+1);
//   if(startIndex != -1){
//     if(endIndex != null && endIndex > startIndex)
//  	   return value.substring(startIndex + startstring.length,endIndex);
//     else
//  	   return value.substring(startIndex + startstring.length);
//   }
//   else
//     return value;
//}// end function

//function insertFilledTemplate(filledTemplate) {
//     jQuery('#wpTextbox1').wikiEditor("setContent", filledTemplate);
//}
 
//hookEvent("load", Articlebutton);
//addOnloadHook(Articlebutton);
//$(document).ready(function(){
//   setTimeout(Articlebutton, 1000);
//});

jQuery( '#wpTextbox1' ).on('wikiEditor-toolbar-doneInitialSections', function () {
    Articlebutton();
});