MediaWiki:Common.js: Difference between revisions

From Dragon Quest Wiki
Jump to navigation Jump to search
No edit summary
(Removing jquery functions instead of just commenting them out)
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/** Begin shared desktop + mobile view script **/
 
/* Make sure any changes are copied to MediaWiki:Mobile.js and vice versa. */
/* Any JavaScript here will be loaded in desktop and mobile view skins on every page load. */
 
/* Any JavaScript here will be loaded in both desktop view and mobile view skins on every page load. */
 
/***************************************
* Name: hasClass
* Description: Checks if a element has a specified class name.  Uses regular expressions and caching for better performance.
* Maintainers (Wikipedia): [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
* Source: Wikipedia Common.js, imported 2/1/10
* Additional Notes: This is a utility method used in other methods.
*/
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();


/***********************************************************
/***********************************************************
  *  Name: createJQueryTabs
  *  Name: dragscroll
  *  Description: Runs at page load, inserts jQuery tabs into a page wherever a <div> with class "tabs" is found.
  *  Description: Scrolls a .dragscroll's contents when clicked and dragged.
  *  Maintainers: [[User:FlyingRagnar]]
  *  Additional Notes: https://github.com/asvd/dragscroll
  *  Additional Notes: This function effectively replaces the Tabber extension which was
  */
  * previously used to insert tabs into a pageThe template [[Template:VersionTabs]] is
/**
  * the primary method to use when inserting jQuery tabs into a page. It is tightly
  * @fileoverview dragscroll - scroll area by dragging
  * coupled to this function.
  * @version 0.0.5
  *
  * @license MIT, see http://github.com/asvd/intence
  * @copyright 2015 asvd <heliosframework@gmail.com>
  */
  */
mw.loader.load( 'jquery.ui.tabs' );
function createJQueryTabs()
{
    var tabGroup = 0;
    var Tabs = document.getElementsByTagName( "div" );
    for ( var i = 0; i < Tabs.length; i++ ) {
        if ( hasClass( Tabs[i], "tabs" ) ) {
            Tabs[i].setAttribute("id", "tabs" + tabGroup);


            var children = Tabs[i].childNodes;
 
            var h = 0;
(function (root, factory) {
            for( var j = 0; j < children.length; j++ ) {
    if (typeof define === 'function' && define.amd) {
              if ( children[j].nodeName == "UL" ) {
        define(['exports'], factory);
                  var Tlinks = children[j].getElementsByTagName( "a" );
    } else if (typeof exports !== 'undefined') {
                  for( var k = h; k < Tlinks.length; k++ ) {
        factory(exports);
                    Tlinks[k].setAttribute("href", "#tabs" + tabGroup + "-" + (k+1));  
    } else {
                  }
        factory((root.dragscroll = {}));
              } else if ( children[j].nodeName == "DIV" ) {
    }
                  children[j].setAttribute("id", "tabs" + tabGroup + "-" + (h+1));
}(this, function (exports) {
                  h++;  
    var _window = window;
              }
    var _document = document;
            }
    var mousemove = 'mousemove';
            // apply the jQuery code to take effect
    var mouseup = 'mouseup';
            jQuery( "#tabs" + tabGroup ).tabs({ /*event: "mouseover"*/ });
    var mousedown = 'mousedown';
            tabGroup++;
    var EventListener = 'EventListener';
    var addEventListener = 'add'+EventListener;
    var removeEventListener = 'remove'+EventListener;
 
    var dragged = [];
    var reset = function(i, el) {
        for (i = 0; i < dragged.length;) {
            el = dragged[i++];
            el[removeEventListener](mousedown, el.md, 0);
            _window[removeEventListener](mouseup, el.mu, 0);
            _window[removeEventListener](mousemove, el.mm, 0);
        }
 
        dragged = _document.getElementsByClassName('dragscroll');
        for (i = 0; i < dragged.length;) {
            (function(el, lastClientX, lastClientY, pushed){
                el[addEventListener](
                    mousedown,
                    el.md = function(e) {
                        pushed = 1;
                        lastClientX = e.clientX;
                        lastClientY = e.clientY;
 
                        e.preventDefault();
                        e.stopPropagation();
                    }, 0
                );
               
                _window[addEventListener](
                    mouseup, el.mu = function() {pushed = 0;}, 0
                );
               
                _window[addEventListener](
                    mousemove,
                    el.mm = function(e, scroller) {
                        scroller = el.scroller||el;
                        if (pushed) {
                            scroller.scrollLeft -=
                                (- lastClientX + (lastClientX=e.clientX));
                            scroller.scrollTop -=
                                (- lastClientY + (lastClientY=e.clientY));
                        }
                    }, 0
                );
            })(dragged[i++]);
         }
         }
     }
     }
}


mw.loader.load( 'jquery.ui.accordion' );
     
function accordionVideos()
    if (_document.readyState == 'complete') {
{
        reset();
  jQuery( "#accordion" ).accordion({ collapsible: true, active: false });
    } else {
}  
        _window[addEventListener]('load', reset, 0);
    }


jQuery( document ).ready( function( $ ) {
    exports.reset = reset;
        mw.loader.using( 'jquery.ui.tabs', function() {createJQueryTabs();} );
}));
        mw.loader.using( 'jquery.ui.accordion', function() {accordionVideos();} );
        createSpoilerCollapseButtons();


} );
/** End shared desktop + mobile view script **/

Latest revision as of 03:58, 26 February 2022

/** Begin shared desktop + mobile view script **/

/* Make sure any changes are copied to MediaWiki:Mobile.js and vice versa. */
/* Any JavaScript here will be loaded in desktop and mobile view skins on every page load. */

/* Any JavaScript here will be loaded in both desktop view and mobile view skins on every page load. */

/***************************************
 * Name: hasClass
 * Description: Checks if a element has a specified class name.  Uses regular expressions and caching for better performance.
 * Maintainers (Wikipedia): [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 * Source: Wikipedia Common.js, imported 2/1/10
 * Additional Notes: This is a utility method used in other methods.
 */
 
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();

/***********************************************************
 *  Name: dragscroll
 *  Description: Scrolls a .dragscroll's contents when clicked and dragged.
 *  Additional Notes: https://github.com/asvd/dragscroll
 */
/**
 * @fileoverview dragscroll - scroll area by dragging
 * @version 0.0.5
 * 
 * @license MIT, see http://github.com/asvd/intence
 * @copyright 2015 asvd <heliosframework@gmail.com> 
 */


(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define(['exports'], factory);
    } else if (typeof exports !== 'undefined') {
        factory(exports);
    } else {
        factory((root.dragscroll = {}));
    }
}(this, function (exports) {
    var _window = window;
    var _document = document;
    var mousemove = 'mousemove';
    var mouseup = 'mouseup';
    var mousedown = 'mousedown';
    var EventListener = 'EventListener';
    var addEventListener = 'add'+EventListener;
    var removeEventListener = 'remove'+EventListener;

    var dragged = [];
    var reset = function(i, el) {
        for (i = 0; i < dragged.length;) {
            el = dragged[i++];
            el[removeEventListener](mousedown, el.md, 0);
            _window[removeEventListener](mouseup, el.mu, 0);
            _window[removeEventListener](mousemove, el.mm, 0);
        }

        dragged = _document.getElementsByClassName('dragscroll');
        for (i = 0; i < dragged.length;) {
            (function(el, lastClientX, lastClientY, pushed){
                el[addEventListener](
                    mousedown,
                    el.md = function(e) {
                        pushed = 1;
                        lastClientX = e.clientX;
                        lastClientY = e.clientY;

                        e.preventDefault();
                        e.stopPropagation();
                    }, 0
                );
                 
                 _window[addEventListener](
                     mouseup, el.mu = function() {pushed = 0;}, 0
                 );
                 
                _window[addEventListener](
                    mousemove,
                    el.mm = function(e, scroller) {
                        scroller = el.scroller||el;
                        if (pushed) {
                             scroller.scrollLeft -=
                                 (- lastClientX + (lastClientX=e.clientX));
                             scroller.scrollTop -=
                                 (- lastClientY + (lastClientY=e.clientY));
                        }
                    }, 0
                );
             })(dragged[i++]);
        }
    }

      
    if (_document.readyState == 'complete') {
        reset();
    } else {
        _window[addEventListener]('load', reset, 0);
    }

    exports.reset = reset;
}));

/** End shared desktop + mobile view script **/