MediaWiki:Gadget-highlightTable-core.js: Difference between revisions

Created page with " * highlightTable.js * * Description: * Adds highlighting to tables * * History: * - 1.0: Row highlighting - Quarenon * - 1.1: Update from pengLo..."
 
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
/** <pre>
  * highlightTable.js
  * highlightTable.js
  *
  *
Line 4: Line 5:
  * Adds highlighting to tables
  * Adds highlighting to tables
  *
  *
* History:
* - 1.0: Row highlighting                        - Quarenon
* - 1.1: Update from pengLocations.js v1.0      - Quarenon
* - 2.0: pengLocations v2.1, Granular cookie    - Saftzie
* - 2.1: Made compatible with jquery.tablesorter - Cqm
* - 2.2: Switch to localStorage                  - Cqm
* - 3.0: Allow cell highlighting                - mejrs
*
* @todo Allow the stored data to be coupled to the table in question. Currently the data is stored
*      on the page itself, so if any tables are shuffled, the highlighting doesn't follow. For
*      the same reason tables hosted on other pages are not synchronized.
  */
  */


Line 86: Line 76:
*/
*/


(function($, mw, OO, rs) {
(function($, mw, OO, gs) {
     'use strict';
     'use strict';


     // constants
     // constants
     var STORAGE_KEY = 'rs:lightTable',
     var STORAGE_KEY = 'gs:lightTable',
         TABLE_CLASS = 'lighttable',
         TABLE_CLASS = 'lighttable',
         LIGHT_ON_CLASS = 'highlight-on',
         LIGHT_ON_CLASS = 'highlight-on',
Line 109: Line 99:
             * Perform initial checks on the page and browser.
             * Perform initial checks on the page and browser.
             */
             */
             init: function() {
             init: function(sorted) {
                 var $tables = $('table.' + TABLE_CLASS),
                 var $tables = $('table.' + TABLE_CLASS),
                     hashedPageName = self.hashString(mw.config.get('wgPageName'));
                     hashedPageName = self.hashString(mw.config.get('wgPageName'));
Line 118: Line 108:
                 }
                 }
                 // check the browser supports local storage
                 // check the browser supports local storage
                 if (!rs.hasLocalStorage()) {
                 if (!gs.hasLocalStorage()) {
                     return;
                     return;
                }
                // check if any of the tables are autosort tables
                // and, if so, ensure the autosort gadget runs first
                if (!sorted && $tables.filter('[class*="autosort="]').length) {
                mw.hook('gadget.autosort.sorted').add(function delayInit() {
                self.init(true);
               
                // only run once
                mw.hook('gadget.autosort.sorted').remove(delayInit);
                });
               
                return;
                 }
                 }


Line 501: Line 503:
     */
     */


}(this.jQuery, this.mediaWiki, this.OO, this.rswiki));
}(this.jQuery, this.mediaWiki, this.OO, this.gswiki));


// </pre>
// </pre>