Difference between revisions of "MediaWiki:Common.js"

From DoomWiki.org

(Add code for tabs)
 
m (Add code to load edit.js subpage when editing)
Line 28: Line 28:
 
   });
 
   });
 
})(jQuery);
 
})(jQuery);
 +
 +
// Load other modules when needed:
 +
if(mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit' || mw.config.get('wgCanonicalSpecialPageName') === 'Upload') {
 +
  // scripts specific to editing pages
 +
  importScript('MediaWiki:Common.js/edit.js');
 +
}

Revision as of 10:34, 21 August 2015

/* Any JavaScript here will be loaded for all users on every page load. */

// haleyjd 20150624: Tab toggling code
(function($) {
   // tab data object
   var TabCollection = function (elem) {
      var tabContents = elem.closest('.dw-tabcontainer').parent().children('.dw-tabcontents'); // content container parent node

      this.tabs       = elem.parent().children();                         // set of all tabs
      this.allContent = tabContents.children('.dw-tabcontent');           // all content containers
      this.myContent  = tabContents.children().eq(this.tabs.index(elem)); // the content container belonging to this tab
   };
   // run on document ready:
   $(function () {
      // add a click callback to every tab
      $('.dw-tab').click(function () {
         var elem = $(this);
         var tc   = elem.data('dwTabCollection');
         if(!tc)
            elem.data('dwTabCollection', (tc = new TabCollection(elem)));
         
         tc.tabs.removeClass('dw-tab-active'); // turn off all tabs
         elem.addClass('dw-tab-active');       // turn on this tab
         
         tc.allContent.css('display', 'none'); // hide all content
         tc.myContent.css('display', 'block'); // display own content
      });
   });
})(jQuery);

// Load other modules when needed:
if(mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit' || mw.config.get('wgCanonicalSpecialPageName') === 'Upload') {
   // scripts specific to editing pages
   importScript('MediaWiki:Common.js/edit.js');
}