ميدياويكي:Gadget-AncreTitres.js

من كوبتيكبيديا
اذهب إلى التنقل اذهب إلى البحث
لم تعد النسخة القابلة للطباعة مدعومة وقد تحتوي على أخطاء في العرض. يرجى تحديث علامات متصفحك المرجعية واستخدام وظيفة الطباعة الافتراضية في متصفحك بدلا منها.

ملاحظة: بعد النشر، أنت قد تحتاج إلى إفراغ الكاش الخاص بمتصفحك لرؤية التغييرات.

  • فايرفوكس / سافاري: أمسك Shift أثناء ضغط Reload، أو اضغط على إما Ctrl-F5 أو Ctrl-R (⌘-R على ماك)
  • جوجل كروم: اضغط Ctrl-Shift-R (⌘-Shift-R على ماك)
  • إنترنت إكسبلورر/إيدج: أمسك Ctrl أثناء ضغط Refresh، أو اضغط Ctrl-F5
  • أوبرا: اضغط Ctrl-F5.
/*
 * Updated version from [[fa:مدیاویکی:Gadget-AncreTitres.js]]. (Oct 2019)
*/
/*jslint browser:true */
/*global $, wgServer, wgScript, wgPageName */
/*global alert, jQuery, mediaWiki, window */
// <nowiki>
(function (mw, $) {
    'use strict';
    function toClipboard(what, text) {
        // https://stackoverflow.com/a/30810322/2705757
        var textArea = document.createElement("textarea");
        // Prevent scrolling to bottom of page in MS Edge/FF
        textArea.style.position = "fixed";
        textArea.style.top = 0;
        textArea.style.left = 0;
        // Ensure it has a small width and height. Setting to 1px / 1em
        // doesn't work as this gives a negative w/h on some browsers.
        textArea.style.width = '2em';
        textArea.style.height = '2em';
        // We don't need padding, reducing the size if it does flash render.
        textArea.style.padding = 0;
        // Clean up any borders.
        textArea.style.border = 'none';
        textArea.style.outline = 'none';
        textArea.style.boxShadow = 'none';
        // Avoid flash of white box if rendered for any reason.
        textArea.style.background = 'transparent';
        textArea.value = text;
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();
        try {
            document.execCommand('copy');
        } catch (err) {
            mw.notify('تعذر النسخ إلى الحافظة');
            return;
        }
        finally {
            document.body.removeChild(textArea);
        }
        mw.notify('تم نسخ ' + what + ' للحافظة');
    }
    $(function () {
        var _option = {
            nom_permalink: 'وصلة دائمة',
            nom_ancre: 'وصلة ويب',
            nom_lien_interne: 'وصلة داخلية',
            description_pl: 'نسخ وصلة دائمة للقسم إلى الحافظة',
            description: 'نسخ وصلة ويب للقسم إلى الحافظة',
            descinterne: 'نسخ وصلة داخلية للقسم إلى الحافظة',
        };
        if (typeof window.AncreTitres !== 'undefined') {
            $.extend(_option, window.AncreTitres);
        }

        var sep = $('<span> | </span>');
        var permalink = $('#t-permalink a').length && $('#t-permalink a')[0].href;
        var urlPrefix = 'https:' + mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName');

        $('.mw-headline').each(function (_, headline) {
            var linksSection = $('<span> <span class="mw-editsection-bracket">[</span><span class="mw-editsection-bracket">]</span></span>');
            var lastBracket = linksSection.find('.mw-editsection-bracket').last();
            linksSection.css({
                '-moz-user-select': 'none',
                '-ms-user-select': 'none',
                '-webkit-user-select': 'none',
                'user-select': 'none',
                'font-size': 'small',
                'font-weight': 'normal',
                'line-height': '1em'
            });

            if (headline.id) {
                var anchor = '#' + headline.id.replace(/\|/g, encodeURIComponent);
            } else {
                var anchor = '';
            }

            $('<a href="#" title="' + _option.description + '">' + _option.nom_ancre + '</a>').click(function () {
                toClipboard('عنوان يو آر إل عادي', urlPrefix + anchor);
                return false;
            }).insertBefore(lastBracket);

            if (permalink) {
                sep.clone().insertBefore(lastBracket);
                $('<a href="#" title="' + _option.description_pl + '">' + _option.nom_permalink + '</a>').click(function () {
                    toClipboard('وصلة دائمة', permalink + anchor);
                    return false;
                }).insertBefore(lastBracket);
            }

            sep.clone().insertBefore(lastBracket);
            $('<a href="#" title="' + _option.descinterne + '">' + _option.nom_lien_interne + '</a>').click(function () {
                toClipboard('وصلة داخلية', '[[' + mw.config.get('wgPageName') + anchor + ']]');
                return false;
            }).insertBefore(lastBracket);

            if (headline.nextElementSibling && headline.nextElementSibling.className === 'mw-editsection') {
                linksSection.appendTo(headline.nextElementSibling);
            } else {
                linksSection.appendTo(headline);
            }
        });
    });
}(mediaWiki, jQuery));
// </nowiki>