4,554
edits
| No edit summary | No edit summary | ||
| Line 9: | Line 9: | ||
|          window.location.href = '/Main_Page'; // Redirects to the home page |          window.location.href = '/Main_Page'; // Redirects to the home page | ||
|      }); |      }); | ||
|      // Loop through each card to format related articles |      // Loop through each card to format related articles | ||
| Line 1,080: | Line 1,048: | ||
|      // Print current entry only |      // Print current entry only | ||
|      $('#print-button').on('click', function () { |      $('#print-button').on('click', function () { | ||
|          var title = window.currentEntryTitle; |          var title = window.currentEntryTitle; // e.g. "090" | ||
|          if (!title) { console.warn('[print] no currentEntryTitle'); window.print(); return; } |          if (!title) { console.warn('[print] no currentEntryTitle'); window.print(); return; } | ||
|          console.log('[print]  |         var pageUrl = mw.util.getUrl(title); // respects /log/$1 | ||
|          console.log('[print] fetching page HTML:', pageUrl); | |||
|          $.get(pageUrl).done(function (html) { | |||
|              var $tmp = $('<div>').html(html); |              var $tmp = $('<div>').html(html); | ||
|              var $print = $tmp.find('.print-only').first(); |              var $print = $tmp.find('.print-only').first(); | ||
|              console.log('[print] .print-only found:', $print.length); |              console.log('[print] .print-only found:', $print.length); | ||
|              if (!$print.length) { console.warn('[print] no .print-only  |              if (!$print.length) { console.warn('[print] no .print-only found; fallback print'); window.print(); return; } | ||
|              var iframe = document.createElement('iframe'); |              var iframe = document.createElement('iframe'); | ||
|              iframe.style.position = 'fixed'; |              iframe.style.position = 'fixed'; | ||
| Line 1,125: | Line 1,071: | ||
|              var doc = iframe.contentDocument || iframe.contentWindow.document; |              var doc = iframe.contentDocument || iframe.contentWindow.document; | ||
|              var printCssUrl = '/index.php?title=MediaWiki:Print.css&action=raw&ctype=text/css'; |              var printCssUrl = '/index.php?title=MediaWiki:Print.css&action=raw&ctype=text/css'; | ||
|              doc.open(); |              doc.open(); | ||
|              doc.write( |              doc.write( | ||
|             '<!doctype html><html><head><meta charset="utf-8">' + | |||
|             '<title>Print</title>' + | |||
|             '<link rel="stylesheet" href="' + printCssUrl + '">' + | |||
|             '</head><body>' + $print.prop('outerHTML') + '</body></html>' | |||
|              ); |              ); | ||
|              doc.close(); |              doc.close(); | ||
|              iframe.onload = function () { |              iframe.onload = function () { | ||
|             try { iframe.contentWindow.focus(); iframe.contentWindow.print(); } | |||
|             finally { setTimeout(function () { document.body.removeChild(iframe); }, 500); } | |||
|              }; |              }; | ||
|         }).fail(function (xhr) { | |||
|              console.warn('[print]  |              console.warn('[print] fetch failed:', xhr && xhr.status, xhr && xhr.statusText); | ||
|              window.print(); |              window.print(); | ||
|          }); |          }); | ||
|      }); |      }); | ||
|      // Close modal with Close button |      // Close modal with Close button | ||