মিডিয়াউইকি:Gadget-subpagesMenu.js

উইকিসংকলন থেকে
টীকা: সংরক্ষণ করার পর, পরিবর্তনসমূহ তৎক্ষণাৎ নাও দেখাতে পারে। আপনার ব্রাউজারের ক্যাশ কিভাবে এড়াবেন তা জানতে এখানে ক্লিক করুন।
  • ফায়ারফক্স / সাফারি: Shift ধরে রাখা অবস্থায়পুনঃলোড করুন-এ ক্লিক করুন, অথবা Ctrl-F5 বা Ctrl-R (ম্যাক-এ ⌘-R) চাপুন
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাক-এ ⌘-Shift-R) চাপুন
  • ইন্টারনেট এক্সপ্লোরার: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 চাপুন
  • অপেরা: মেনু → ব্যবস্থাপনাসমূহ-এ যান (ম্যাকে অপেরা → পছন্দসমূহ) এবং এরপর গোপনীয়তা ও সুরক্ষা → ব্রাউজিং-এর তথ্য পরিষ্কার করুন → ক্যাশে করা ছবি ও ফাইলগুলি

অন্যান্য ব্রাউজার সম্পর্কে বিশদ নির্দেশাবলীর জন্য, উইকিপিডিয়া:আপনার ক্যাশে বাইপাস করুন দেখুন।

/**
* Add a menu for selecting subpages after the page title.
*/

jQuery(function($) {
    var api, request, localization;

    /**
     * Add pages that are direct descendants of the current one.
     *
     * A "direct descendant" is a page whose title starts with the
     * title of the current page, and contain one more slash. I.e. "A/B" is a
     * direct descendant of "A", but "A/B/C" is not. "Empty" subpages, pages
     * that don't have content themselves, but have subpages of their own, are
     * also added.
     */

	localization = {
		dropdownTooltip: "একটি উপপাতা নির্বাচন করুন"
	};

    function addSubPagesToDropdown(data) {
        var page, $option, parts, i, subpageTitle;

        console.log("[Subpages] data =", data);
        for(i = 0; i < data.query.allpages.length; i ++) {
        	page = data.query.allpages[i];
            // The part of the title following the title of the
            // current page.
            subpageTitle =
            	page.title.slice(mw.config.get("wgPageName").length + 1);
            parts = subpageTitle.split("/");
            if($("#subpages-menu").children().filter(function() {
            	return this.textContent.slice(1) === parts[0];
            }).length === 0)
            {
            	// Add the subpage if it's not already in the dropdown.
                $("<option></option>").text("/" + parts[0])
                    .appendTo($("#subpages-menu"));
            }
        }
        // Using data.continue gives a syntax error, hence the atypical syntax
        // below.
        if(data["continue"]) {
            request["continue"] = data["continue"]["continue"];
            request.apcontinue = data["continue"].apcontinue;
            api.get(request).done(getSubPages);
        }
    }

    /**
     * Create the dropdown menu.
     */

    function addDropdown() {
        $("<select></select>")
            .attr("id", "subpages-menu")
            .addClass("subpages-controls")
            .prop("title", localization.dropdownTooltip)
            .appendTo($("#firstHeading"));
        // Add a slash as the first item. Without this, it's initially
        // impossible to select the first subpage. It also serves as
        // an visual indication as to what the dropdown does.
        $("<option></option>").text("/").appendTo($("#subpages-menu"));
        $("#subpages-menu").change(function(event) {
            if(this.value !== "/") {
                // Don't do anything if the user manage to select the
                // initial slash
                var subpageUrl = mw.config.get("wgServer") +
                    mw.util.getUrl(mw.config.get("wgPageName") + this.value);
                window.location = subpageUrl.toString();
            }
        });
    }
    
      mw.loader.using(["mediawiki.api", "mediawiki.util"]).done(function() {
      if(mw.config.get('wgNamespaceNumber') == 0){
        addDropdown();
        api = new mw.Api();
        request = {
            "action": "query",
            "format": "json",
            "list": "allpages",
            "apprefix": mw.config.get("wgTitle") + "/",
            "apnamespace": mw.config.get("wgNamespaceNumber"),
            "aplimit": 500,
            "continue": ""
        };
        console.log("[Subpages] request =", request);
        api.get(request).done(addSubPagesToDropdown);
    	addAddButton();
    	addAddField();
    	$(window).on("pageshow", function() {
	        // Select the slash item. If you go back, the page may otherwise have
        	// the last selected item selected, which means you can't change to
        	// that.
        	$("#subpages-menu").get(0).selectedIndex = 0;
		});
      }
    });
});