ผลต่างระหว่างรุ่นของ "มีเดียวิกิ:Gadget-site-source-links.js"

เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
Geonuch (คุย | ส่วนร่วม)
สร้างหน้าด้วย "// ================================================================== // source_link_adder.js // // Adds a source link in the Translation namespace, pend..."
(ไม่แตกต่าง)

รุ่นแก้ไขเมื่อ 21:57, 20 กุมภาพันธ์ 2564

// ==================================================================
// source_link_adder.js
//
// Adds a source link in the Translation namespace, pending
// a resolution of [[phab:T53980]] (from pre 2013)
// And also in the Minerva (mobile) skin: [[phab:T274350]]
//
// Also enables in any sandbox page for testing purposes
// ==================================================================


(function($, mw) {

  "strict";

  var cns = mw.config.get("wgCanonicalNamespace");
  var skin = mw.config.get("skin");

  if (!( (["Translation"].indexOf(cns) !== -1)
      || (mw.config.get("wgTitle").indexOf("Sandbox") !== -1)
      || (["minerva"].indexOf(skin) !== -1))) {
    return;
  }

  var SourceLinker = {
    signature: "source_link_adder",
    strings: {
      link_tooltip: 'Scanned edition used to establish this text',
      link_text: 'Source',
    }
  };

  function add_to_tabs($link) {
    switch (skin) {
      case "vector":
      case "monobook":
      case "modern":
      case "timeless":
        $("#ca-talk").before($("<li>").append($link));
        break;
      case "minerva":
        $(".minerva__tab-container a:first-child")
          .after($link
            .addClass("minerva__tab"));
          break;
    }
  }

  function get_index_link() {
    // Look for a .pagenum and take the index from the first one
    var pages = $(".pagenum");
    var $link;
    if (pages.length > 0) {

      var index = pages[0].getAttribute("data-page-name")
        .replace(/\/+\d+$/, "")
        .replace(/^Page:/, "Index:");

      var index_href = mw.config.get("wgServer")
              + mw.config.get("wgArticlePath").replace("$1", index);

      $link = $("<a>")
        .attr({
            href: index_href,
            title: SourceLinker.strings.link_tooltip,
        })
        .append(SourceLinker.strings.link_text);
    }

    return $link;
  }

  $(function() {
    if ($("#ca-proofread-source").length > 0) {
      return;
    }
    var $link = get_index_link();
    if ($link){
      add_to_tabs($link);
    }
  });

}(jQuery, mediaWiki));