MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 774: Line 774:
         if (!pageTitle) return;
         if (!pageTitle) return;


         const api = mw.util.wikiScript('api');
         var api = mw.util.wikiScript('api');
 
         // remove any previous print block so we don't duplicate
         // remove any previous print block so we don't duplicate
         $('#show-article .print-only').remove();
         $('#show-article .print-only').remove();
Line 782: Line 783:
             page: pageTitle,
             page: pageTitle,
             prop: 'text',
             prop: 'text',
             format: 'json',
             format: 'json'
            origin: '*' // safe for CORS if needed
         }).done(function (res) {
         }).done(function (res) {
             const html = res?.parse?.text?.['*'];
             var html = res && res.parse && res.parse.text && res.parse.text['*'];
             if (!html) return;
             if (!html) return;


             const $tmp = $('<div>').html(html);
             var $tmp = $('<div>').html(html);
             const $printBlock = $tmp.find('.print-only').first();
             var $printBlock = $tmp.find('.print-only').first();
             if ($printBlock.length) {
             if ($printBlock.length) {
             $('#show-article').append($printBlock);
             $('#show-article').append($printBlock);
             }
             }
        }).fail(function () {
            // silently ignore; we just won't have the print layout
         });
         });
     }
     }


     function openModal(cardElement, event) {
     function openModal(cardElement, event) {
         event.stopPropagation();  
         event.stopPropagation();  
         console.log("openModal function called.");
          
 
         // ⬇️ NEW: detect the entry page title from the clicked card and fetch print layout
         // ⬇️ NEW: detect the entry page title from the clicked card and fetch print layout
         var pageTitle = $(cardElement).data('page'); // set by ShowEntries
         var pageTitle = $(cardElement).data('page'); // set by ShowEntries
Line 1,085: Line 1,081:
     $('#print-button').on('click', function () {
     $('#print-button').on('click', function () {
         $('body').addClass('print-entry-only');
         $('body').addClass('print-entry-only');
         requestAnimationFrame(() => {
         requestAnimationFrame(function () {
             requestAnimationFrame(() => { window.print(); });
             requestAnimationFrame(function () {
            window.print();
            });
         });
         });
     });
     });

Navigation menu