Difference between revisions of "MediaWiki:Common.js"

m
 
(212 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// <nowiki>
+
/*jshint esversion:6 */
/* globals $, mw, uix, XenForo */
+
/* globals $, mw, uix */
  
 
(function() {
 
(function() {
"use strict";
+
    "use strict";
  
var namespace = window.namespace = mw.config.get('wgCanonicalNamespace');
+
    var namespace = window.namespace = mw.config.get('wgCanonicalNamespace');
var action = window.action = mw.config.values.wgAction;
+
    var action = window.action = mw.config.values.wgAction;
  
/* Add a class to allow per-theme styling of the wiki. */
+
    /* Add a class to allow per-theme styling of the wiki. */
var theme;
+
    var theme;
if (typeof uix === 'undefined') {
+
    if (typeof uix === 'undefined') {
    theme = $("dt:contains('Style')").next().find('a').text();
+
        theme = $("dt:contains('Style')").next().find('a').text();
} else {
+
    } else {
    theme = uix.user.themeName;
+
        theme = uix.user.themeName;
}
+
    }
$('#mw-content-text').addClass('w' + theme.replace(/\s/g,''));
+
    $('#mw-content-text').addClass('w' + theme.replace(/\s/g, ''));
 +
 
 +
    /* Add a class to allow per-namespace styling of the wiki. */
 +
    $('#mw-content-text').addClass('wNamespace' + namespace);
 +
 
 +
    /* Add jQuery UI css */
 +
    var addjQueryCSS = function() {
 +
        $('head').append(stratics.f.util.makehtml('link', {
 +
            rel: 'stylesheet',
 +
            type: 'text/css',
 +
            href: 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-darkness/jquery-ui.min.css'
 +
        }));
 +
 
 +
        /* Add jQuery UI styling for input[type=number] */
 +
        $('head').append(stratics.f.util.makehtml('style', {}, 'input[type=number] {font-size: 13px;font-family: \'Open Sans\',Arial,sans-serif;color: rgb(207, 207, 207);background-color: #101010;padding: 5px 10px;margin-bottom: 2px;border: 1px solid #383838;-webkit-border-radius: 2px;-moz-border-radius: 2px;-khtml-border-radius: 2px;border-radius: 2px;outline: 0;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;-ms-box-sizing: border-box;box-sizing: border-box;min-height: 30}'));
 +
    };
 +
 
 +
    /* Create a common namespace for stratics wiki js */
 +
    (function() {
 +
        window.stratics = {
 +
            data: {},
 +
            f: {
 +
                atlas: {
 +
                    ui: {}
 +
                },
 +
                util: {
 +
                    /* Get the current time. */
 +
                    getTime: function() {
 +
                        var j;
 +
                        var now = new Date(),
 +
                            time = [now.getHours(), now.getMinutes(), now.getSeconds()],
 +
                            suffix = time[0] < 12 ? "AM" : "PM";
 +
                        for (j = 1; 3 > j; j++) {
 +
                            time[j] = ('0' + time[j]).slice(-2);
 +
                        }
 +
                        return [time.join(":"), ' ', suffix].join('');
 +
                    },
 +
                    makehtml: function(type, obj, text) {
 +
                        var str = "<" + type,
 +
                            key;
 +
                        for (key in obj) {
 +
                            if (obj.hasOwnProperty(key)) {
 +
                                str += ' ' + key + '="' + obj[key] + '"';
 +
                            }
 +
                        }
 +
                        return str + ('input' === type ? '' : '>') + ("input" === type ? '/>' + (undefined === text ? '' : text) :
 +
                            (undefined === text ? '' : text) + '</' + type + '>');
 +
                    },
 +
                    purgePage: function() {
 +
                    new mw.Api().post({
 +
    action: 'purge',
 +
    titles: document.location.search.match(/title=(.[^&]+)/)[1],
 +
    format: 'json'
 +
    });
 +
location.reload();
 +
                    },
 +
                    reloadPage: function() {
 +
                        location.reload();
 +
                    }
 +
                },
 +
                wiki: {
 +
                    /* Retrieves the wiki markup for a page; defaults to the current page. */
 +
                    getMarkup: function(page) {
 +
                        var getPage = function(callback, page) {
 +
                            $.get('https://wiki.stratics.com/api.php?action=query&prop=revisions&rvprop=content&format=json&formatversion=2&titles=' + page, function(data) {
 +
                                callback.apply(data);
 +
                            });
 +
                        };
 +
                        getPage(function() {
 +
                        /* Allow scripts to be cached. */
 +
                            $.ajaxSetup({
 +
                                cache: false
 +
                            });
 +
                            window.stratics.wiki.markup = this.query.pages[0].revisions[0].content;
 +
                            $('body').trigger('markupArrived');
 +
                        }, page || mw.config.get("wgPageName"));
 +
                    },
 +
                    /* Submits a markup edit to the server */
 +
                    submitMarkup: function(summary, content) {
 +
                        window.stratics.f.wiki.api.postWithToken("edit", {
 +
                            action: "edit",
 +
                            title: mw.config.get("wgPageName"),
 +
                            summary: summary,
 +
                            text: content
 +
                        }).done(function(result, jqXHR) {
 +
                            mw.log("Saved successfully");
 +
                            $('body').trigger('submitMarkupSuccess');
 +
                        }).fail(function(code, result) {
 +
                            if (code === "http") {
 +
                                mw.log("HTTP error: " + result.textStatus); // result.xhr contains the jqXHR object
 +
                            } else if (code === "ok-but-empty") {
 +
                                mw.log("Got an empty response from the server");
 +
                            } else {
 +
                                mw.log("API error: " + code);
 +
                            }
 +
                            $('body').trigger('submitMarkupFailure');
 +
                        });
 +
                    }
 +
                }
 +
            },
 +
            keycodes: {
 +
                27: 'ESC',
 +
                33: 'NE',
 +
                34: 'SE',
 +
                35: 'SW',
 +
                36: 'NW',
 +
                37: 'W',
 +
                38: 'N',
 +
                39: 'E',
 +
                40: 'S'
 +
            },
 +
            wiki: {
 +
                markup: '',
 +
                openEdits: []
 +
            }
 +
        };
 +
    })(window);
 +
 
 +
    /* Tests if an element is visible on the screen. */
 +
    $.fn.isOnScreen = function() {
 +
        var element = this.get(0);
 +
        var bounds = element.getBoundingClientRect();
 +
        return bounds.top < window.innerHeight && bounds.bottom > 0;
 +
    };
 +
 
 +
    /* Returns the scale transform value for an element. */
 +
    $.fn.getScale = function() {
 +
        var vals = this.css('transform');
 +
        return (vals == 'none') ? 1 : vals.split('(')[1].split(')')[0].split(',')[0];
 +
    };
  
/* Add a class to allow per-namespace styling of the wiki. */
+
    /* Returns an array of the 4 inset values for an element. */
$('#mw-content-text').addClass('wNamespace' + namespace);
+
    $.fn.getInsets = function() {
 +
        var vals = this.css('clip-path');
 +
        if (vals == 'none') {
 +
            vals = this.css('-webkit-clip-path');
 +
        }
 +
        return vals.split('(')[1].split(')')[0].split(/px\s?/);
 +
    };
  
/* Fix broken mail and alert popups while on the wiki */
+
    /* Sort the options within a select alphabetically */
XenForo.ExtLoader = function (f) {
+
    $.fn.sortOptions = function() {
    return function () {
+
         var optionList = this.find('option')
         try {
+
             .sort(function(a, b) {
            f.apply(this, arguments);
+
                 return (a.text > b.text ? 1 : (a.text < b.text ? -1 : 0));
        } catch (e) {
 
            var mailreq = 'http://stratics.com/conversations/popup?_xfRequestUri=%2F&_xfNoRedirect=1&_xfResponseType=json&_xfToken=' + $('input[name=_xfToken]:first').attr('value');
 
             $.getJSON(mailreq, function (data) {
 
                 $('#ConversationsMenu .listPlaceholder').empty().html(data.templateHtml);
 
 
             });
 
             });
             var alertreq = 'http://stratics.com/conversations/alerts-popup?_xfRequestUri=%2F&_xfNoRedirect=1&_xfResponseType=json&_xfToken=' + $('input[name=_xfToken]:first').attr('value');
+
        return this.empty()
             $.getJSON(alertreq, function (data) {
+
             .append(optionList);
                 $('#AlertsMenu .listPlaceholder').empty().html(data.templateHtml);
+
    };
 +
 
 +
    $.fn.extend({
 +
        /* Allow changing tip text */
 +
        changeTip: function (newText) {
 +
             return this.each(function() {
 +
                 var $e = $(this).find('.tooltipstered');
 +
                $e.data($e.data('tooltipster-ns')[0]).Content[0].innerText = newText;
 
             });
 
             });
         }
+
         },
    };
+
        /* Allow retrieving tip text */
}(XenForo.ExtLoader);
+
        getTip: function (newText) {
 +
            return this.data(this.data('tooltipster-ns')[0]).Content[0].innerText;
 +
        },
  
/* Create a common namespace for stratics wiki js */
+
        /* Add visibility equivalents to show/hide/toggle */
(function () {
+
        vis: function() {
    var temp = {
+
            return this.each(function() {
        data: {},
+
                 $(this).css("visibility", "visible");
        f: {
+
            });
            atlas: {
 
                ui: {}
 
            },
 
            util: {
 
              /* Get the current time. */
 
              getTime: function () {
 
                  var j;
 
                  var now = new Date(),
 
                      time = [now.getHours(), now.getMinutes(), now.getSeconds()],
 
                      suffix = time[0] < 12 ? "AM" : "PM";
 
                  for (j = 1; 3 > j; j++) {
 
                      time[j] = ('0' + time[j]).slice(-2);
 
                  }
 
                  return [time.join(":"), ' ', suffix].join('');
 
              },
 
              makehtml: function (type, obj, text) {
 
                    var str = "<" + type, key;
 
                    for (key in obj) {
 
                        if (obj.hasOwnProperty(key)) {
 
                            str += ' ' + key + '="' + obj[key] + '"';
 
                        }
 
                    }
 
                    return str + ('input' === type ? '' : '>') + ("input" === type ? '/>' + (undefined === text ? '' : text)
 
                                                                                  : (undefined === text ? '' : text) + '</' + type + '>');
 
                },
 
              reloadPage: function () { location.reload(); }
 
            },
 
            wiki: {
 
                api: new mw.Api(),
 
                /* Retrieves the wiki markup for a page; defaults to the current page. */
 
                 getMarkup: function (page) {
 
                    var getPage = function (callback, page) {
 
                        $.get('http://stratics.com/w/api.php?action=query&prop=revisions&rvprop=content&format=json&formatversion=2&titles=' + page, function (data) {
 
                            callback.apply(data);
 
                        });
 
                    };
 
                    getPage(function() {
 
                        stratics.wiki.markup = this.query.pages[0].revisions[0].content;
 
                        $('body').trigger('markupArrived');
 
                    }, page || mw.config.get("wgPageName"));
 
                },
 
                /* Submits a markup edit to the server */
 
              submitMarkup: function (summary, content) {
 
                    stratics.f.wiki.api.postWithToken("edit", {
 
                        action: "edit",
 
                        title: mw.config.get("wgPageName"),
 
                        summary: summary,
 
                        text: content
 
                    }).done(function (result, jqXHR) {
 
                        mw.log("Saved successfully");
 
                      $('body').trigger('submitMarkupSuccess');
 
                    }).fail(function (code, result) {
 
                        if (code === "http") {
 
                            mw.log("HTTP error: " + result.textStatus); // result.xhr contains the jqXHR object
 
                        } else if (code === "ok-but-empty") {
 
                            mw.log("Got an empty response from the server");
 
                        } else {
 
                            mw.log("API error: " + code);
 
                        }
 
                        $('body').trigger('submitMarkupFailure');
 
                    });
 
                }
 
            }
 
 
         },
 
         },
         keycodes: {
+
         invis: function() {
             27: 'ESC',
+
             return this.each(function() {
            33: 'NE',
+
                $(this).css("visibility", "hidden");
            34: 'SE',
+
             });
            35: 'SW',
 
            36: 'NW',
 
            37: 'W',
 
             38: 'N',
 
            39: 'E',
 
            40: 'S'
 
 
         },
 
         },
         wiki: {
+
         toggleVis: function() {
             markup: '',
+
             return this.each(function() {
             openEdits: []
+
                $(this).css("visibility", function(b, a) {
 +
                    return "visible" == a ? "hidden" : "visible";
 +
                });
 +
             });
 
         }
 
         }
     };
+
     });
  
     window.stratics = $.extend(true, (undefined === window.stratics) ? {} : window.stratics ,temp); // Avoid clobbering any existing window.stratics object.
+
     /* Start: collapsible navboxes */
})(window);
 
  
/* Tests if an element is visible on the screen. */
+
    $('.navbox-inner:gt(0)').each(function () {
$.fn.isOnScreen = function() {
+
        $(this)[$(this).hasClass('expanded') ? 'removeClass' : 'addClass']('mw-collapsed');
    var element = this.get(0);
+
     });
     var bounds = element.getBoundingClientRect();
+
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
    return bounds.top < window.innerHeight && bounds.bottom > 0;
+
    $('.navbox-inner').makeCollapsible();
};
+
});
  
/* Returns the scale transform value for an element. */
+
    /* End: collapsible navboxes */
$.fn.getScale = function() {
 
    var vals = this.css('transform');
 
    return (vals == 'none') ? 1 : vals.split('(')[1].split(')')[0].split(',')[0];
 
};
 
  
/* Returns an array of the 4 inset values for an element. */
+
  /* Start Item Editor */
$.fn.getInsets = function() {
 
    var vals = this.css('clip-path');
 
    if (vals == 'none') {
 
        vals = this.css('-webkit-clip-path');
 
    }
 
    return vals.split('(')[1].split(')')[0].split(/px\s?/);
 
};
 
  
/* Sort the options within a select alphabetically */
+
if (action === 'edit' && (namespace === 'UO' || namespace === 'User')) {
$.fn.sortOptions = function () {
 
    var optionList = this.find('option')
 
        .sort(function (a, b) {
 
            return (a.text > b.text ? 1 : (a.text < b.text ? -1 : 0));
 
        });
 
    return this.empty()
 
        .append(optionList);
 
};
 
  
/* Add visibility equivalents to show/hide/toggle */
+
  addjQueryCSS();
$.fn.extend({
 
    vis: function () {
 
        return this.each(function () {
 
            $(this).css("visibility", "visible");
 
        });
 
    },
 
    invis: function () {
 
        return this.each(function () {
 
            $(this).css("visibility", "hidden");
 
        });
 
    },
 
    toggleVis: function () {
 
        return this.each(function () {
 
            $(this).css("visibility", function (b, a) {
 
                return "visible" == a ? "hidden" : "visible";
 
            });
 
        });
 
    }
 
});
 
  
/* HTML construction helper function */
+
        /* Load properties JSON */
var makehtml = window.makehtml = function (type, o, text) {
+
        $.getScript('/index.php?title=MediaWiki:PropertyBuilder.js&action=raw&ctype=text/javascript&1.0.1').complete(function() {
    var i = '<' + type;
 
    for (var key in o) {
 
        if (o.hasOwnProperty(key)) {
 
            i += ' ' + key + '="' + o[key] + '"';
 
        }
 
    }
 
    i += (type === 'input') ? '' : '>';
 
    i += (type === 'input') ? '/>' + (text || '') : (text || '') + '</' + type + '>';
 
    return i;
 
};
 
  
/* Add jQuery UI css */
+
          /* Load jQuery UI */
var addjQueryCSS = function () {
+
          mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function() {
    $('head').append(makehtml('link', {
 
            rel: 'stylesheet',
 
            type: 'text/css',
 
            href: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-darkness/jquery-ui.min.css'
 
        }));
 
  
    /* Workaround for jQuery UI/Xenforo/Mediawiki css conflict */
+
              /* Load Editor */
    $('head').append(makehtml('style', {}, 'body .ui-dialog .ui-widget-header,body .ui-button {background:#333!important}'));
+
              $.getScript('/index.php?title=MediaWiki:PropertyEditor.js&action=raw&ctype=text/javascript&1.0.0', function() {
 +
                  loadEditor();
 +
              });
 +
          });
 +
      });
 +
  }
  
     /* Add jQuery UI styling for input[type=number] */
+
     /* End Item Editor  */
    $('head').append(makehtml('style', {}, 'input[type=number] {font-size: 13px;font-family: \'Open Sans\',Arial,sans-serif;color: rgb(207, 207, 207);background-color: #101010;padding: 5px 10px;margin-bottom: 2px;border: 1px solid #383838;-webkit-border-radius: 2px;-moz-border-radius: 2px;-khtml-border-radius: 2px;border-radius: 2px;outline: 0;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;-ms-box-sizing: border-box;box-sizing: border-box;min-height: 30}'));
 
};
 
  
/* Start: collapsible navboxes */
+
    /* Start Atlas Tools */
  
$('.navbox-inner:gt(0)').addClass('mw-collapsed');
+
    /* Only run on UO Atlas pages */
$('.navbox-inner').makeCollapsible();
+
    if (/^UO\:Atlas/.test(mw.config.values.wgPageName)) {  // make current shard visible in the navbox
 +
        setTimeout(function() {
 +
            var $expando = $('.mw-collapsible.uncollapsed').find('.mw-collapsible-text');
 +
            if ($expando.text() == 'Expand') $expando.click();
 +
        }, 1000);
 +
    }
  
/* End: collapsible navboxes */
+
//       addjQueryCSS();
  
/* Start Item Editor */
+
        /* Load jQuery UI */
 +
//        mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function() {
  
if (action === 'edit' && (namespace === 'UO' || namespace === 'User' )) {
+
            /* Load Editor */
 +
//            $.getScript('/index.php?title=MediaWiki:AtlasTools.js&action=raw&ctype=text/javascript');
 +
//        });
 +
//    }
  
     addjQueryCSS();
+
     /* Load Atlas Tools (separate from here to permit ES6 */
 +
    $.getScript('/index.php?title=MediaWiki:Atlas%20Tools.js&action=raw&ctype=text/javascript&1.1.6');
 +
    /* End Atlas Tools */
 +
   
 +
    /* Start Hunter's Guide scripts */
  
     /* Load properties JSON */
+
     if ($('a[title="Category:UO:Mobile"]').length > 0) {
    $.getScript('/w/index.php?title=MediaWiki:PropertyBuilder.js&action=raw&ctype=text/javascript').complete(function () {
 
  
         /* Load jQuery UI */
+
         /* Block clicks to the edit tab as early as possible. */
         mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function () {
+
         $('a[accesskey="e"]').click(function(e) {
 +
            e.preventDefault();
 +
            $('body').data('editClicked', true);
 +
            return false;
 +
        });
  
            /* Load Editor */
+
        /* Allow scripts to be cached. */
            $.getScript('/w/index.php?title=MediaWiki:PropertyEditor.js&action=raw&ctype=text/javascript', function () {
+
        $.ajaxSetup({
                loadEditor();
+
             cache: true
             });
 
 
         });
 
         });
    });
 
}
 
  
/* End Item Editor  */
+
        addjQueryCSS();
 +
 
 +
        /* Load jQuery UI */
 +
        mw.loader.using(['mediawiki.api', 'jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog', 'jquery.ui.selectable'], function() {
 +
        window.stratics.f.wiki.api = new mw.Api();
 +
       
 +
            /* Load jQuery UI selectmenu */
 +
            $.getScript('https://cdn.rawgit.com/jquery/jquery-ui/master/ui/widgets/selectmenu.js').complete(function() {
 +
 
 +
                /* Load Localization */
 +
                $.getScript('/index.php?title=MediaWiki:Localization.js&action=raw&ctype=text/javascript&1.0.5').complete(function() {
  
/* Start Atlas Tools */
+
                    /* Load Mob Editor */
 +
                    $.getScript('/index.php?title=MediaWiki:Mob%20Editor.js&action=raw&ctype=text/javascript&1.1.6');
  
if (/^UO\:Atlas/.test(mw.config.values.wgPageName) && namespace === 'UO' && $('.map-holder').length > 0) { /* Only run on UO Atlas pages which have a map present. */
+
                    /* Load Animal Lore Editor */
 +
                    $.getScript('/index.php?title=MediaWiki:AnimalLoreTool.js&action=raw&ctype=text/javascript&1.2.23');
  
    addjQueryCSS();
+
                });
 +
            });
  
    /* Load jQuery UI */
+
            /* Load OrgChart generator script */
    mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function () {
+
            $.getScript('/index.php?title=MediaWiki:Orgchart.js&action=raw&ctype=text/javascript&1.0.0').complete(function() {
  
        /* Load Editor */
+
                /* Load Mob taxonomy data */
        $.getScript('/w/index.php?title=MediaWiki:AtlasTools.js&action=raw&ctype=text/javascript');
+
                $.getScript('/index.php?title=MediaWiki:MobData.js&action=raw&ctype=text/javascript&1.0.8').complete(function() {
    });
 
}
 
  
/* End Atlas Tools */
+
                    /* Load Taxonomy chart builder */
 +
                    $.getScript('/index.php?title=MediaWiki:MobTaxonomy.js&action=raw&ctype=text/javascript&1.0.1').complete(function() {
  
/* Start Animal Lore submit tool */
+
                    });
 +
                });
 +
            });
 +
        });
 +
    }
  
if ($('a[title="Category:UO:Mobile"]').length > 0) {
+
    /* Add quick links to the Hunter's Guide main page. */
 +
    if (/\?title=UO:Hunter%27s_Guide/.test(location.search)) {
 +
        $.getScript('/index.php?title=MediaWiki:AddQuickLinks.js&action=raw&ctype=text/javascript&1.0.0');
 +
    }
  
if (document.location == 'http://stratics.com/w/index.php?title=User:BrianFreud/ALTest') {
+
    /* End Hunter's Guide scripts */
  
     addjQueryCSS();
+
     /* Start suit-page scripts */
 +
    // This sorts the display order of suit parts, regardless of the order they are specified in the template call.
 +
    if ($('table.suittable').length > 0) {
 +
        $.getScript('/index.php?title=MediaWiki:Stupidtable.min.js&action=raw&ctype=text/javascript&1.0.0').complete(function() {
 +
          $('.suittable').stupidtable().each(function () {
 +
              $(this).find("th").eq(3).click();
 +
          });
 +
        });
 +
    }
 +
    /* End suit-page scripts */
  
     /* Load jQuery UI */
+
     /* Start crafter table script */
    mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog', 'jquery.ui.selectable'], function () {
 
  
         /* Load Localization */
+
    if ($('table.crafteditems').length > 0) {
         $.getScript('/w/index.php?title=MediaWiki:Localization.js&action=raw&ctype=text/javascript');
+
         /* Load StupidTable plugin */
 +
         $.getScript('/index.php?title=MediaWiki:Stupidtable.min.js&action=raw&ctype=text/javascript&1.0.0').complete(function() {
  
        /* Load Editor */
+
            // This next works around the fact that mediawiki doesn't build proper HTML for tables.
        $.getScript('/w/index.php?title=MediaWiki:AnimalLoreTool.js&action=raw&ctype=text/javascript');
+
            $('.crafteditems:not(.nosort)').each(function () {
    });
+
                var th, trs, $this = $(this);
}
+
                th = $this.find('tr:first').detach();
 +
                trs = $this.find('tr').detach();
 +
                $this.empty();
 +
                $this.append('<thead></thead><tbody></tbody>');
 +
                $this.find('thead').append(th);
 +
                $this.find('tbody').append(trs);
 +
            });
 +
 
 +
            // Init stupidtable
 +
            $('table.crafteditems').stupidtable();
 +
            setTimeout(function(){
 +
                $('.craftablecategory').click();
 +
            }, 1);
 +
 
 +
        });
 +
    }
  
}
+
  /* End crafter table scripts */
  
/* End Animal Lore submit tool */
+
    /* Allow combining DPL results that need to be broken into multiple queries (ie, mobiles). */
 +
    $('.mergetablefrom').find('th').parent().remove();
 +
    $('.mergetableto').append($('.mergetablefrom').find('tr').detach());
 +
    $('.mergetablefrom').remove();
  
 +
  /* Automate purge page confirmation */
 +
if (action === 'purge'){
 +
    $('button[type="submit"]').click();
 +
}
 +
 +
/* css selector level 4 spec.  Works in jQuery, but not yet implemented in browsers. */
 +
$('dl.hideEmpty:not(:has(dd))').hide();
 
}());
 
}());
 
// </nowiki>
 

Latest revision as of 11:07, 19 October 2020

/*jshint esversion:6 */
/* globals $, mw, uix */

(function() {
    "use strict";

    var namespace = window.namespace = mw.config.get('wgCanonicalNamespace');
    var action = window.action = mw.config.values.wgAction;

    /* Add a class to allow per-theme styling of the wiki. */
    var theme;
    if (typeof uix === 'undefined') {
        theme = $("dt:contains('Style')").next().find('a').text();
    } else {
        theme = uix.user.themeName;
    }
    $('#mw-content-text').addClass('w' + theme.replace(/\s/g, ''));

    /* Add a class to allow per-namespace styling of the wiki. */
    $('#mw-content-text').addClass('wNamespace' + namespace);

    /* Add jQuery UI css */
    var addjQueryCSS = function() {
        $('head').append(stratics.f.util.makehtml('link', {
            rel: 'stylesheet',
            type: 'text/css',
            href: 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-darkness/jquery-ui.min.css'
        }));

        /* Add jQuery UI styling for input[type=number] */
        $('head').append(stratics.f.util.makehtml('style', {}, 'input[type=number] {font-size: 13px;font-family: \'Open Sans\',Arial,sans-serif;color: rgb(207, 207, 207);background-color: #101010;padding: 5px 10px;margin-bottom: 2px;border: 1px solid #383838;-webkit-border-radius: 2px;-moz-border-radius: 2px;-khtml-border-radius: 2px;border-radius: 2px;outline: 0;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;-ms-box-sizing: border-box;box-sizing: border-box;min-height: 30}'));
    };

    /* Create a common namespace for stratics wiki js */
    (function() {
    	    window.stratics = {
	            data: {},
	            f: {
            	    atlas: {
        	            ui: {}
    	            },
	                util: {
                	    /* Get the current time. */
            	        getTime: function() {
        	                var j;
    	                    var now = new Date(),
	                            time = [now.getHours(), now.getMinutes(), now.getSeconds()],
                            	suffix = time[0] < 12 ? "AM" : "PM";
                        	for (j = 1; 3 > j; j++) {
                    	        time[j] = ('0' + time[j]).slice(-2);
                	        }
            	            return [time.join(":"), ' ', suffix].join('');
        	            },
    	                makehtml: function(type, obj, text) {
	                        var str = "<" + type,
                        	    key;
                    	    for (key in obj) {
                	            if (obj.hasOwnProperty(key)) {
            	                    str += ' ' + key + '="' + obj[key] + '"';
        	                    }
    	                    }
	                        return str + ('input' === type ? '' : '>') + ("input" === type ? '/>' + (undefined === text ? '' : text) :
                        	    (undefined === text ? '' : text) + '</' + type + '>');
                    	},
                	    purgePage: function() {
	                    	new mw.Api().post({
    							action: 'purge',
							    titles: document.location.search.match(/title=(.[^&]+)/)[1],
							    format: 'json'
    						});
							location.reload();
        	            },
                	    reloadPage: function() {
            	            location.reload();
        	            }
    	            },
	                wiki: {
        	            /* Retrieves the wiki markup for a page; defaults to the current page. */
    	                getMarkup: function(page) {
	                        var getPage = function(callback, page) {
                        	    $.get('https://wiki.stratics.com/api.php?action=query&prop=revisions&rvprop=content&format=json&formatversion=2&titles=' + page, function(data) {
                    	            callback.apply(data);
                	            });
            	            };
        	                getPage(function() {
    	                    /* Allow scripts to be cached. */
	                            $.ajaxSetup({
                            	    cache: false
                        	    });
                    	        window.stratics.wiki.markup = this.query.pages[0].revisions[0].content;
                	            $('body').trigger('markupArrived');
            	            }, page || mw.config.get("wgPageName"));
        	            },
    	                /* Submits a markup edit to the server */
	                    submitMarkup: function(summary, content) {
                    	    window.stratics.f.wiki.api.postWithToken("edit", {
                	            action: "edit",
            	                title: mw.config.get("wgPageName"),
        	                    summary: summary,
    	                        text: content
	                        }).done(function(result, jqXHR) {
                            	mw.log("Saved successfully");
                            	$('body').trigger('submitMarkupSuccess');
                        	}).fail(function(code, result) {
                            	if (code === "http") {
                                	mw.log("HTTP error: " + result.textStatus); // result.xhr contains the jqXHR object
                            	} else if (code === "ok-but-empty") {
                                	mw.log("Got an empty response from the server");
                            	} else {
                                	mw.log("API error: " + code);
                            	}
                            	$('body').trigger('submitMarkupFailure');
                        	});
                    	}
	                }
    	        },
        	    keycodes: {
            	    27: 'ESC',
                	33: 'NE',
	                34: 'SE',
    	            35: 'SW',
        	        36: 'NW',
            	    37: 'W',
                	38: 'N',
	                39: 'E',
    	            40: 'S'
        	    },
            	wiki: {
                	markup: '',
                	openEdits: []
            	}
        	};
    })(window);

    /* Tests if an element is visible on the screen. */
    $.fn.isOnScreen = function() {
        var element = this.get(0);
        var bounds = element.getBoundingClientRect();
        return bounds.top < window.innerHeight && bounds.bottom > 0;
    };

    /* Returns the scale transform value for an element. */
    $.fn.getScale = function() {
        var vals = this.css('transform');
        return (vals == 'none') ? 1 : vals.split('(')[1].split(')')[0].split(',')[0];
    };

    /* Returns an array of the 4 inset values for an element. */
    $.fn.getInsets = function() {
        var vals = this.css('clip-path');
        if (vals == 'none') {
            vals = this.css('-webkit-clip-path');
        }
        return vals.split('(')[1].split(')')[0].split(/px\s?/);
    };

    /* Sort the options within a select alphabetically */
    $.fn.sortOptions = function() {
        var optionList = this.find('option')
            .sort(function(a, b) {
                return (a.text > b.text ? 1 : (a.text < b.text ? -1 : 0));
            });
        return this.empty()
            .append(optionList);
    };

    $.fn.extend({
        /* Allow changing tip text */
        changeTip: function (newText) {
            return this.each(function() {
                var $e = $(this).find('.tooltipstered');
                $e.data($e.data('tooltipster-ns')[0]).Content[0].innerText = newText;
            });
        },
        /* Allow retrieving tip text */
        getTip: function (newText) {
            return this.data(this.data('tooltipster-ns')[0]).Content[0].innerText;
        },

        /* Add visibility equivalents to show/hide/toggle */
        vis: function() {
            return this.each(function() {
                $(this).css("visibility", "visible");
            });
        },
        invis: function() {
            return this.each(function() {
                $(this).css("visibility", "hidden");
            });
        },
        toggleVis: function() {
            return this.each(function() {
                $(this).css("visibility", function(b, a) {
                    return "visible" == a ? "hidden" : "visible";
                });
            });
        }
    });

    /* Start: collapsible navboxes */

    $('.navbox-inner:gt(0)').each(function () {
        $(this)[$(this).hasClass('expanded') ? 'removeClass' : 'addClass']('mw-collapsed');
    });
	mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
    	$('.navbox-inner').makeCollapsible();
	});

    /* End: collapsible navboxes */

   	/* Start Item Editor */

	if (action === 'edit' && (namespace === 'UO' || namespace === 'User')) {

   		addjQueryCSS();

        /* Load properties JSON */
        $.getScript('/index.php?title=MediaWiki:PropertyBuilder.js&action=raw&ctype=text/javascript&1.0.1').complete(function() {

           	/* Load jQuery UI */
           	mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function() {

               	/* Load Editor */
               	$.getScript('/index.php?title=MediaWiki:PropertyEditor.js&action=raw&ctype=text/javascript&1.0.0', function() {
                   	loadEditor();
               	});
           	});
       	});
   	}

    /* End Item Editor  */

    /* Start Atlas Tools */

    /* Only run on UO Atlas pages */
    if (/^UO\:Atlas/.test(mw.config.values.wgPageName)) {  // make current shard visible in the navbox
        setTimeout(function() {
            var $expando = $('.mw-collapsible.uncollapsed').find('.mw-collapsible-text');
            if ($expando.text() == 'Expand') $expando.click();
        }, 1000);
    }

//        addjQueryCSS();

        /* Load jQuery UI */
//        mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function() {

            /* Load Editor */
//            $.getScript('/index.php?title=MediaWiki:AtlasTools.js&action=raw&ctype=text/javascript');
//        });
//    }

    /* Load Atlas Tools (separate from here to permit ES6 */
    $.getScript('/index.php?title=MediaWiki:Atlas%20Tools.js&action=raw&ctype=text/javascript&1.1.6');
    /* End Atlas Tools */
    
    /* Start Hunter's Guide scripts */

    if ($('a[title="Category:UO:Mobile"]').length > 0) {

        /* Block clicks to the edit tab as early as possible. */
        $('a[accesskey="e"]').click(function(e) {
            e.preventDefault();
            $('body').data('editClicked', true);
            return false;
        });

        /* Allow scripts to be cached. */
        $.ajaxSetup({
            cache: true
        });

        addjQueryCSS();

        	/* Load jQuery UI */
        	mw.loader.using(['mediawiki.api', 'jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog', 'jquery.ui.selectable'], function() {
	        	window.stratics.f.wiki.api = new mw.Api();
        	
            	/* Load jQuery UI selectmenu */
            	$.getScript('https://cdn.rawgit.com/jquery/jquery-ui/master/ui/widgets/selectmenu.js').complete(function() {

                	/* Load Localization */
                	$.getScript('/index.php?title=MediaWiki:Localization.js&action=raw&ctype=text/javascript&1.0.5').complete(function() {

            	        /* Load Mob Editor */
        	            $.getScript('/index.php?title=MediaWiki:Mob%20Editor.js&action=raw&ctype=text/javascript&1.1.6');

    	                /* Load Animal Lore Editor */
	                    $.getScript('/index.php?title=MediaWiki:AnimalLoreTool.js&action=raw&ctype=text/javascript&1.2.23');

                	});
            	});

            	/* Load OrgChart generator script */
            	$.getScript('/index.php?title=MediaWiki:Orgchart.js&action=raw&ctype=text/javascript&1.0.0').complete(function() {

                	/* Load Mob taxonomy data */
                	$.getScript('/index.php?title=MediaWiki:MobData.js&action=raw&ctype=text/javascript&1.0.8').complete(function() {

                    	/* Load Taxonomy chart builder */
                    	$.getScript('/index.php?title=MediaWiki:MobTaxonomy.js&action=raw&ctype=text/javascript&1.0.1').complete(function() {

                    	});
                	});
            	});
        	});
    }

    /* Add quick links to the Hunter's Guide main page. */
    if (/\?title=UO:Hunter%27s_Guide/.test(location.search)) {
        $.getScript('/index.php?title=MediaWiki:AddQuickLinks.js&action=raw&ctype=text/javascript&1.0.0');
    }

    /* End Hunter's Guide scripts */

    /* Start suit-page scripts */
    // This sorts the display order of suit parts, regardless of the order they are specified in the template call.
    if ($('table.suittable').length > 0) {
        $.getScript('/index.php?title=MediaWiki:Stupidtable.min.js&action=raw&ctype=text/javascript&1.0.0').complete(function() {
           $('.suittable').stupidtable().each(function () {
               $(this).find("th").eq(3).click(); 
           });
        });
    }
    /* End suit-page scripts */

    /* Start crafter table script */

    if ($('table.crafteditems').length > 0) {
        /* Load StupidTable plugin */
        $.getScript('/index.php?title=MediaWiki:Stupidtable.min.js&action=raw&ctype=text/javascript&1.0.0').complete(function() {

            // This next works around the fact that mediawiki doesn't build proper HTML for tables.
            $('.crafteditems:not(.nosort)').each(function () {
                var th, trs, $this = $(this);
                th = $this.find('tr:first').detach();
                trs = $this.find('tr').detach();
                $this.empty();
                $this.append('<thead></thead><tbody></tbody>');
                $this.find('thead').append(th);
                $this.find('tbody').append(trs);
            });

            // Init stupidtable
            $('table.crafteditems').stupidtable();
            setTimeout(function(){ 
                $('.craftablecategory').click();
            }, 1);

        });
    }

   /* End crafter table scripts */

    /* Allow combining DPL results that need to be broken into multiple queries (ie, mobiles). */
    $('.mergetablefrom').find('th').parent().remove();
    $('.mergetableto').append($('.mergetablefrom').find('tr').detach());
    $('.mergetablefrom').remove();

   	/* Automate purge page confirmation */
	if (action === 'purge'){
	    $('button[type="submit"]').click();
	}
	
	/* css selector level 4 spec.  Works in jQuery, but not yet implemented in browsers. */
	$('dl.hideEmpty:not(:has(dd))').hide();
}());