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

Difference between revisions of "MediaWiki:Common.js"

MediaWiki interface page
m (added copy text script)
m (test)
 
(9 intermediate revisions by the same user not shown)
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 () {
mw.loader.load( 'https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js' );
    if (window.CopyTextLoaded) {
 
        return;
 
    }
 
    window.CopyTextLoaded = true;
$(function() {
    mw.hook('dev.i18n').add(function (i18n) {
$(document).on("click", ".copy-to-clipboard-button", function() {
        i18n.loadMessages('CopyText').done(function (i18n) {
var clipboard = new ClipboardJS('.copy-to-clipboard-button');
            function showSuccess() {
 
                if (window.BannerNotification) {
      clipboard.on('success', function (e) {
                    new BannerNotification(i18n.msg('success').escape(), 'confirm').show();
        console.log(e);
                } else {
      });
                    mw.loader.using('mediawiki.notify').then(function () {
 
                        mw.notify(i18n.msg('success').plain());
      clipboard.on('error', function (e) {
                    });
        console.log(e);
                }
      });
            }
  });
            $('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();
                        });
                    }
                }
            });
        });
    });
})();

Latest revision as of 10:16, 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' );
mw.loader.load( 'https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js' );



$(function() {
$(document).on("click", ".copy-to-clipboard-button", function() {
	 var clipboard = new ClipboardJS('.copy-to-clipboard-button');

      clipboard.on('success', function (e) {
        console.log(e);
      });

      clipboard.on('error', function (e) {
        console.log(e);
      });
  });
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.