Difference between revisions of "MediaWiki:Common.js"

From LQ's wiki
Jump to: navigation, search
Line 2: Line 2:
 
   
 
   
 
(function() {
 
(function() {
 
 
     var CLASS = 'custom-print';
 
     var CLASS = 'custom-print';
 +
    var PREVIEW_TEXT = 'Preview';
 +
    var EDIT_TEXT = 'Edit';
 
     var isPrintMode = false;
 
     var isPrintMode = false;
     var printButton = $('<span class="custom-print-toggle">Normal</span>');
+
     var printButton = $('<span class="custom-print-toggle">' + PREVIEW_TEXT + '</span>');
 
     var body = $('body');
 
     var body = $('body');
 
   
 
   
Line 12: Line 13:
 
     printButton.click(function() {
 
     printButton.click(function() {
 
         if(isPrintMode === true) {
 
         if(isPrintMode === true) {
             printButton.html('Preview');
+
             printButton.html(PREVIEW_TEXT);
 
             printButton.removeClass('print-mode');
 
             printButton.removeClass('print-mode');
 
             body.removeClass(CLASS);
 
             body.removeClass(CLASS);
 
             isPrintMode = false;
 
             isPrintMode = false;
 
         } else {
 
         } else {
             printButton.html('Edit');
+
             printButton.html(EDIT_TEXT);
 
             printButton.addClass('print-mode');
 
             printButton.addClass('print-mode');
 
             body.addClass(CLASS);
 
             body.addClass(CLASS);

Revision as of 14:47, 23 January 2014

/* Any JavaScript here will be loaded for all users on every page load. */
 
(function() {
    var CLASS = 'custom-print';
    var PREVIEW_TEXT = 'Preview';
    var EDIT_TEXT = 'Edit';
    var isPrintMode = false;
    var printButton = $('<span class="custom-print-toggle">' + PREVIEW_TEXT + '</span>');
    var body = $('body');
 
    $('#firstHeading').append(printButton);
 
    printButton.click(function() {
        if(isPrintMode === true) {
            printButton.html(PREVIEW_TEXT);
            printButton.removeClass('print-mode');
            body.removeClass(CLASS);
            isPrintMode = false;
        } else {
            printButton.html(EDIT_TEXT);
            printButton.addClass('print-mode');
            body.addClass(CLASS);
            isPrintMode = true;
        }
 
    });
 
}());