Manjaro Difference between revisions of "MediaWiki:Common.js"

Difference between revisions of "MediaWiki:Common.js"

MediaWiki interface page
m (added copy text script)
m (changed copy to text)
Line 2: Line 2:
mw.loader.load( 'https://cdn.jsdelivr.net/npm/uikit@3.5.8/dist/js/uikit.min.js' );
mw.loader.load( 'https://cdn.jsdelivr.net/npm/uikit@3.5.8/dist/js/uikit.min.js' );
mw.loader.load( 'https://cdn.jsdelivr.net/npm/uikit@3.5.8/dist/js/uikit-icons.min.js' );
mw.loader.load( 'https://cdn.jsdelivr.net/npm/uikit@3.5.8/dist/js/uikit-icons.min.js' );
(function () {
 
     if (window.CopyTextLoaded) {
function copyTextToCb() {
        return;
      /* Get the text field */
      var copyText = document.getElementById("copy-to-clipboard-text");
      
      /* Select the text field */
      copyText.select();
      copyText.setSelectionRange(0, 99999); /*For mobile devices*/
   
      /* Copy the text inside the text field */
      document.execCommand("copy");
   
      /* Alert the copied text */
      alert("Copied the text: " + copyText.value);
     }
     }
    window.CopyTextLoaded = true;
    mw.hook('dev.i18n').add(function (i18n) {
        i18n.loadMessages('CopyText').done(function (i18n) {
            function showSuccess() {
                if (window.BannerNotification) {
                    new BannerNotification(i18n.msg('success').escape(), 'confirm').show();
                } else {
                    mw.loader.using('mediawiki.notify').then(function () {
                        mw.notify(i18n.msg('success').plain());
                    });
                }
            }
            $('body').on('click', '.copy-to-clipboard-button', function(e){
                var text = $(this).data('text'),
                $input = $('<textarea>', { type: 'text' })
                    .val($('.copy-to-clipboard-text').filter(function() {
                        return $(this).data('text') == text;
                    }).first().text())
                    .appendTo('body')
                    .select();
                var success = document.execCommand('Copy');
                $input.remove();
                if (success) {
                    showSuccess();
                } else {
                    if (window.navigator && navigator.clipboard && navigator.clipboard.writeText) {
                        navigator.clipboard.writeText(text).then(function() {
                            showSuccess();
                        });
                    }
                }
            });
        });
    });
})();

Revision as of 09:43, 26 September 2021

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.load( 'https://cdn.jsdelivr.net/npm/uikit@3.5.8/dist/js/uikit.min.js' );
mw.loader.load( 'https://cdn.jsdelivr.net/npm/uikit@3.5.8/dist/js/uikit-icons.min.js' );

 function copyTextToCb() {
      /* Get the text field */
      var copyText = document.getElementById("copy-to-clipboard-text");
    
      /* Select the text field */
      copyText.select();
      copyText.setSelectionRange(0, 99999); /*For mobile devices*/
    
      /* Copy the text inside the text field */
      document.execCommand("copy");
    
      /* Alert the copied text */
      alert("Copied the text: " + copyText.value);
    }
Cookies help us deliver our services. By using our services, you agree to our use of cookies.