UESPWiki:Javascript/ajaxRC.js

//  
//  
/*   */
/*

 * ADVANCED AJAX AUTO-REFRESHING ARTICLES

 *

 * Original by pcj of Wowpedia

 * Maintenance, cleanup, style and bug fixes by:

 *   Grunny (

 *   Kangaroopower (

 *   Cqm (

 */
/*jshint browser:true, camelcase:true, curly:true, eqeqeq:true, immed:true, jquery:true, latedef:true, newcap:true, noarg:true, noempty:true, nonew:true, quotmark:single, trailing:true, undef:true, unused:true, onevar:true */

/*global mediaWiki:true */
;( function ( window, $, mw, dev ) {

'use strict';
var config = dev.ajaxRC || {},

ns = {};

// Some util stuff for AjaxRC

ns.util = {

mw: mw.config.get( [

'stylepath',

'wgAction',

'wgCanonicalSpecialPageName',

'wgPageName'

] ),

timer: false

};
// AjaxRC config

// Maintain backwards compatibility with older configuration options

ns.config = {

pages: config.pages || window.ajaxPages || [ 'Special:RecentChanges' ],

// use common file for default as it's very likely to be already cached by user

// used in oasis sidebar loading, preview modal, etc.

indicator: config.indicator || window.ajaxIndicator || '//upload.wikimedia.org/wikipedia/commons/2/26/Ajax-loader2.gif',

refresh: config.refresh || window.ajaxRefresh || 60000,

text: config.text || window.AjaxRCRefreshText || 'AJAX',

hovertext: config.hovertext ||  window.AjaxRCRefreshHoverText || 'Enable auto-refreshing page loads'

};
/**

storage function to save checkbox value for future use

@param setTo {boolean} If given, this is the value saved to localStorage

                       that contains whether the ajaxRC checkbox is checked (true)

                       or isn't checked (false)

/

ns.storage = function ( setTo ) {

if ( localStorage.getItem( 'AjaxRC-refresh' ) === null ) {

localStorage.setItem( 'AjaxRC-refresh', true );

}
if ( typeof setTo === 'boolean' ) {

localStorage.setItem( 'AjaxRC-refresh', setTo );

}
return JSON.parse( localStorage.getItem( 'AjaxRC-refresh' ) );

};

/**

Main function to start the Auto-refresh process

/

ns.preloadAJAXRL = function () {

var $appTo = $( '.firstHeading' ),

$checkbox = $( '  ' )

.css( { 'font-size': 'xx-small', 'line-height': '100%', 'margin-left': '5px' } )

.append(

$( '  ' )

.css( { 'border-bottom': '1px dotted', 'cursor': 'help' } )

.attr( 'title', ns.config.hovertext )

.text( ns.config.text + ':' ),

$( ' ' )

.css( { 'margin-bottom': 0 } ),

$( '  ' )

.css( 'display', 'none' )

.append(

$( ' ' )

.css( { 'vertical-align': 'baseline', 'float': 'none', 'border': 0 } )

.attr( {'src': ns.config.indicator, 'alt': 'Refreshing page' } )

)

),

$throbber;
// fallback for pages with profile masthead

$appTo.append( $checkbox );
$throbber = $appTo.find( '#ajaxLoadProgress' );
$( document ).ajaxSend( function ( event, xhr, settings ) {

if ( location.href === settings.url ) {

$throbber.show();

}

} ).ajaxComplete ( function ( event, xhr, settings ) {

var $collapsibleElements = $( '#mw-content-text' ).find( '.mw-collapsible' ),

i;
ns.config.ajCallAgain = dev.ajaxRC.ajaxCallAgain || window.ajaxCallAgain || [];
if ( location.href === settings.url ) {

$throbber.hide();

if ( $collapsibleElements.length ) {

$collapsibleElements.makeCollapsible();

}

if ( ns.util.mw.wgCanonicalSpecialPageName === 'Recentchanges' ) {

mw.special.recentchanges.init();
}
for ( i = 0; i   */