MediaWiki:Gadget-edittop.js: Difference between revisions

From Sarkarverse
Jump to navigation Jump to search
m (Let's try a different version of this)
(Copyedit)
Line 5: Line 5:
// **                                                                  **
// **                                                                  **
// **********************************************************************
// **********************************************************************
// Imported from [[User:Alex Smotrov/edittop.js]], version as of: 2008-10-06T04:28:52
// Imported from [[User:Alex Smotrov/edittop.js]], version as of: 2007-06-19T04:28:52
// Updated from [[User:TheDJ/Gadget-edittop.js]], version as of: 2009-04-28T11:54:22


if ((wgAction == 'view' || wgAction == 'purge') && wgNamespaceNumber >=0)
if ($.inArray( mw.config.get('wgAction'), [ 'view', 'purge' ]) !== -1 && mw.config.get( 'wgNamespaceNumber' ) >=0) {
addOnloadHook(function edittop_hook(){
  $(function edittop_hook () {
var h2s = document.getElementsByTagName('H2');
    var localtitles = {
var h2 = h2s[0];
      cs: 'Editovat úvodní sekci',
if (!h2) return;
      en: 'Edit lead section',
if (h2.parentNode.id == 'toctitle') h2 = h2s[1];
      fa: 'ویرایش بخش آغازین',
if (!h2) return;
      fr: 'Modifier le résumé introductif',
var span = h2.firstChild;
      id: 'Sunting bagian atas',
if (!span || span.className != 'editsection') return;
      it: 'Modifica della sezione iniziale',
var zero = span.cloneNode(true);
      ja: '導入部を編集',
if (document.getElementById('featured-star')) zero.style.marginRight = '25px';
      min: 'Suntiang bagian ateh',
if (document.getElementById('spoken-icon')) zero.style.marginRight = '45px';
      ko: '도입부를 편집',
if (document.getElementById('protected-icon') && zero.style.marginRight) zero.style.marginRight = '70px';
      pa: 'ਸੋਧ',
var parent = document.getElementsByTagName('H1')[0];
      pt: 'Editar a seção superior',
parent.insertBefore(zero, parent.firstChild);
      'pt-br': 'Editar a seção superior',
var a = zero.getElementsByTagName('A')[0];
      sr: 'Уреди уводни део',
if (a.href.indexOf('&section=T') == -1){
      vi: 'Sửa phần mở đầu'
  a.title = a.title.replace(/:.*$/,': 0')
    };
  a.setAttribute('href', a.href.replace(/&section=\d+/,'&section=0'));
 
}else{//transcluded
    var our_content = $("#content, #mw_content").first();
  a.title = 'Edit section: 0'
    var span1 = our_content.find("span.mw-editsection:not(.plainlinks)").first();
  a.setAttribute('href', wgScript+'?title='+encodeURIComponent(wgPageName)+'&action=edit&section=0')
    if (!span1.length) {
}
      return;
})
    }
    var span0 = span1.clone();
 
    if ( mw.user.options.get( 'gadget-righteditlinks' ) == 1 ) {
      var editwidth = span1.outerWidth() + (mw.config.get("skin") == "monobook" ? 10 : 0);
      $("div.topicon, #mw-fr-revisiontag").css("margin-right", editwidth + "px");
    }
    $("#mw_header h1, #content h1").first().append(span0);
    span0.find("a").each(function (idx) {
      var a = $(this);
      a.attr("title", localtitles[mw.config.get( 'wgUserLanguage' )] || localtitles.en);
      if (a.attr("href").indexOf("&section=T") == -1) {
        a.attr("href", a.attr("href").replace(/&section=\d+/, "&section=0&summary=/*%20top%20*/%20"));
      }
      else { //transcluded
        a.attr("href", mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) ) + "?action=edit&section=0&summary=/*%20top%20*/%20");
      }
    });
  });
}

Revision as of 16:34, 13 March 2014

// **********************************************************************
// **                 ***WARNING GLOBAL GADGET FILE***                 **
// **             changes to this file affect many users.              **
// **           please discuss on the talk page before editing         **
// **                                                                  **
// **********************************************************************
// Imported from [[User:Alex Smotrov/edittop.js]], version as of: 2007-06-19T04:28:52
// Updated from [[User:TheDJ/Gadget-edittop.js]], version as of: 2009-04-28T11:54:22

if ($.inArray( mw.config.get('wgAction'), [ 'view', 'purge' ]) !== -1 && mw.config.get( 'wgNamespaceNumber' ) >=0) {
  $(function edittop_hook () {
    var localtitles = {
      cs: 'Editovat úvodní sekci',
      en: 'Edit lead section',
      fa: 'ویرایش بخش آغازین',
      fr: 'Modifier le résumé introductif',
      id: 'Sunting bagian atas',
      it: 'Modifica della sezione iniziale',
      ja: '導入部を編集',
      min: 'Suntiang bagian ateh',
      ko: '도입부를 편집',
      pa: 'ਸੋਧ',
      pt: 'Editar a seção superior',
      'pt-br': 'Editar a seção superior',
      sr: 'Уреди уводни део',
      vi: 'Sửa phần mở đầu'
    };

    var our_content = $("#content, #mw_content").first();
    var span1 = our_content.find("span.mw-editsection:not(.plainlinks)").first();
    if (!span1.length) {
      return;
    }
    var span0 = span1.clone();

    if ( mw.user.options.get( 'gadget-righteditlinks' ) == 1 ) {
      var editwidth = span1.outerWidth() + (mw.config.get("skin") == "monobook" ? 10 : 0);
      $("div.topicon, #mw-fr-revisiontag").css("margin-right", editwidth + "px");
    }
    $("#mw_header h1, #content h1").first().append(span0);
    span0.find("a").each(function (idx) {
      var a = $(this);
      a.attr("title", localtitles[mw.config.get( 'wgUserLanguage' )] || localtitles.en);
      if (a.attr("href").indexOf("&section=T") == -1) {
        a.attr("href", a.attr("href").replace(/&section=\d+/, "&section=0&summary=/*%20top%20*/%20"));
      }
      else { //transcluded
        a.attr("href", mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) ) + "?action=edit&section=0&summary=/*%20top%20*/%20");
      }
    });
  });
}