प्रयोगकर्ता:SM7/tagIt.js

विकिपिडिया बठेइ

टिप्पणी सङ्ग्रह गरेपछि, परिवर्तन हेर्नको लागि तपाईंले आफ्नो ब्राउजरको क्याच बाईपास गर्नु पर्ने हुनसक्छ।

  • फायरफक्स / सफारीमा: Shift कुञ्जी थिची राखेर Reload क्लिक गर्नुपर्छ, वा Ctrl-F5 वा Ctrl-R दबाउनुहोस् (म्याकमा ⌘-R)
  • गुगल क्रोम: Ctrl-Shift-R कुञ्जी दबाउनुहोस् (म्याकमा ⌘-R)
  • ओपेरा: Tools → Preferences मा गएर क्याश हटाउनुहोस्
  • इन्टरनेट एक्सप्लोरर: Ctrl लाई थिची राखेर Refresh क्लिक गर्नुहोस् वा Ctrl-F5 थिच्नुहोस्
var tagItYes_nomdate = null;
(function ($) { // Wrap with anonymous function
    function tagItTab() {
        var $h, $hb, $newa,
            // A list of subpages of WikiProject Stub sorting/Stub types/ that are relevant to this
            a = ['tag0' , 'tag1', 'tag2'];

        $h = $("<div></div>", { "id": "tagIttab" })
                 .css({
                     "color": "#000000",
                     "background-color": "#fff8f8",
                     "text-align": "center"
                 });
        for (var i = 0; i < a.length; i++) {
            $newa = $("<a href=\"#\"></a>");
            $newa.click(function (e) {
                e.preventDefault();
                tagItMenu($(this).text());
            });
            $newa.text(a[i]);
            $h.append($newa);
            if ((i + 1) < a.length) {
                $h.append(" &bull; ");
            }
        }
        $("#contentSub").append($h);

        $hb = $("<div></div>", {
                  "color": "#000000",
                  "background-color": "#fffff8"
              });
        $hb.attr("id", "tagItmenu");
        $("#contentSub").append($hb);
    }

    function tagItMenuRender(data) {
        var $parseData = $(data.parse.text["*"]);
        $parseData.find("a").each(function () {
            var link = $(this).attr("href"),
                index = link.indexOf("E:");
            if (index === -1) {
                $(this).attr({
                    "href": null,
                    "title": null
                });
                $(this).css({
                    "color": "#000000",
                    "text-decoration": "none"
                });
            } else {
                $(this).attr("href", mw.config.get("wgServer") + mw.config.get("wgScript")
                    + "?title=" + encodeURIComponent(mw.config.get("wgPageName"))
                    + "&action=edit&autoaddtagIt=" + encodeURIComponent(link.slice(index + 2)));
            }
        });
        $("#tagItmenu").html($parseData);
    }

    function tagItMenuFail() {
        $("#tagItmenu").html("Failed to load tags.");
    }

    function tagItMenu(stubType) {
        // Add loading message
        $("#tagItmenu").html("Loading tags, please wait...");

        // Fetch the relevant subpage of the WikiProject
        $.ajax({
            url: mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/api.php?action=parse&prop=text&text=' + encodeURIComponent('__NOTOC____NOEDITSECTION__\{\{प्रयोगकर्ता:SM7/sandbox/' + stubType + '}}') + '&format=json',
            dataType: "json",
            success: tagItMenuRender,
            error: tagItMenuFail
        });
    }

    $(function () {
        if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view"
                && $("#ca-edit").length !== 0) {
            var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Oh! Tag It!', 'ca-tagIt', 'Add a tag to this page', '');
            $(portletLink).click(function (e) {
                e.preventDefault();
                if (!$("#tagIttab").length) {
                    tagItTab();
                }
            });
        }
        if (location.href.indexOf("&autoaddtagIt=") !== -1 && $("#wpTextbox1").length !== 0) {
            var x = decodeURIComponent(location.href.split("&autoaddtagIt=")[1]);
            var txt = document.editform.wpTextbox1;                                                                                        //Get text for replacing pre-existing stub tags
		        if (tagItYes_nomdate === null) {
                tagItYes_nomdate = prompt("Give reason/date etc. as needed !", '');
            }
			$("#wpTextbox1").val("{" + "{" + x + "|" + tagItYes_nomdate + "}}\n" + $("#wpTextbox1").val()); // add to the end of the article
            $("#wpSummary").val("[[प्रयोगकर्ता:SM7/tagIt.js|TagIt]] adding " + x + " Tag.");
            $("#wpPreview").trigger("click");
        }
    });
} (jQuery)); // End wrap with anonymous function