コンテンツにスキップ

「MediaWiki:MobileUI.js」の版間の差分

提供: Vikipedia
編集の要約なし
タグ: モバイル編集 モバイルウェブ編集
編集の要約なし
タグ: モバイル編集 モバイルウェブ編集
1行目: 1行目:
// @ts-check
// @ts-check


(async () => {
/**
    /**
* @typedef MobileUIMenuItem
    * @typedef {import("jquery")} JQueryStatic
* @prop {string} title
    */
* @prop {string} page
 
* @prop {string | string[]} [class]
    /**
*/
    * @typedef MobileUIMenuItem
    * @prop {string} title
    * @prop {string} page
    * @prop {string | string[]} [class]
    */


    /**
/**
    * @typedef MobileUI
* @typedef MobileUI
    * @prop {MobileUIMenuItem[]} menu
* @prop {MobileUIMenuItem[]} menu
    */
*/


/**
* @param {import("jquery")} $
* @param {any} mw
* @param {MobileUI} mobileUI
*/
function applyMobileUI($, mw, mobileUI) {
     const config = {
     const config = {
         wgArticleId: Number(),
         wgArticleId: Number(),
27行目: 28行目:


     const wikiURL = `${config.wgServer}${config.wgScriptPath}`;
     const wikiURL = `${config.wgServer}${config.wgScriptPath}`;
    const mobileUIPath = `${wikiURL}/index.php?title=MediaWiki:MobileUI.json&action=raw&ctype=application/json`;
    const response = await window.fetch(mobileUIPath);
    /**
    * @type {MobileUI}
    */
    const mobileUI = await response.json();


     /**
     /**
83行目: 76行目:
     }
     }


     $(".menu").ready(() => {
     $(".menu").ready($ => {
         const menu = $(".menu");
         const menu = $(".menu");
         menu.find("ul").first().remove();
         menu.find("ul").first().remove();
         menu.prepend(groups);
         menu.prepend(groups);
     });
     });
})();
}

2019年6月24日 (月) 00:23時点における版

// @ts-check

/**
 * @typedef MobileUIMenuItem
 * @prop {string} title
 * @prop {string} page
 * @prop {string | string[]} [class]
 */

/**
 * @typedef MobileUI
 * @prop {MobileUIMenuItem[]} menu
 */

/**
 * @param {import("jquery")} $
 * @param {any} mw
 * @param {MobileUI} mobileUI
 */
function applyMobileUI($, mw, mobileUI) {
    const config = {
        wgArticleId: Number(),
        wgServer: "",
        wgScriptPath: String(),
    };

    Object.assign(config, mw.config.get(Object.keys(config)));

    const wikiURL = `${config.wgServer}${config.wgScriptPath}`;

    /**
     * @type {JQuery<HTMLElement>[]}
     */
    const groups = [];

    const ul = $("<ul>");

    groups.push(ul);

    for (const menuItem of mobileUI.menu) {
        const li = $("<li>").appendTo(ul);

        $("<a>")
            .text(menuItem.title)
            .addClass(["mw-ui-icon", "mw-ui-icon-before"])
            .attr("href", menuItem.page)
            .appendTo(li);
    }

    if (config.wgArticleId > 1) {
        const hlist = $("<ul>")
            .addClass("hlist")
            .css("word-break", "break-all");

        const li = $("<li>").appendTo(hlist);
        const dl = $("<dl>").appendTo(li);

        $("<dt>")
            .text("ページの短縮URL")
            .css("display", "block")
            .css("padding-left", "1em")
            .appendTo(dl);

        const dd = $("<dd>")
            .css("display", "block")
            .appendTo(dl);

        const shortURL = `${wikiURL}/?curid=${config.wgArticleId}`;

        $("<a>")
            .text(shortURL)
            .attr("href", shortURL)
            .appendTo(dd);

        groups.push(hlist);
    }

    $(".menu").ready($ => {
        const menu = $(".menu");
        menu.find("ul").first().remove();
        menu.prepend(groups);
    });
}
Cookieは私達のサービスを提供するのに役立ちます。このサービスを使用することにより、お客様はCookieの使用に同意するものとします。