Difference between revisions of "MediaWiki:Common.js"

m
 
(236 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// <nowiki>
+
/*jshint esversion:6 */
 +
/* globals $, mw, uix */
  
 
(function() {
 
(function() {
    /* globals $, mw, uix, XenForo */
 
 
     "use strict";
 
     "use strict";
  
var page = window.page = mw.config.values.wgPageName;
+
    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. */
+
    /* Add a class to allow per-namespace styling of the wiki. */
$('#mw-content-text').addClass('wNamespace' + namespace);
+
    $('#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'
 +
        }));
  
/* Fix broken mail and alert popups while on the wiki */
+
        /* Add jQuery UI styling for input[type=number] */
XenForo.ExtLoader = function (f) {
+
        $('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}'));
    return function () {
 
        try {
 
            f.apply(this, arguments);
 
        } 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');
 
            $.getJSON(alertreq, function (data) {
 
                $('#AlertsMenu .listPlaceholder').empty().html(data.templateHtml);
 
            });
 
        }
 
 
     };
 
     };
}(XenForo.ExtLoader);
 
  
/* Tests if an element is visible on the screen. */
+
    /* Create a common namespace for stratics wiki js */
$.fn.isOnScreen = function() {
+
    (function() {
    var element = this.get(0);
+
        window.stratics = {
    var bounds = element.getBoundingClientRect();
+
            data: {},
    return bounds.top < window.innerHeight && bounds.bottom > 0;
+
            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);
  
/* Returns the scale transform value for an element. */
+
    /* Tests if an element is visible on the screen. */
$.fn.getScale = function() {
+
    $.fn.isOnScreen = function() {
    var vals = this.css('transform');
+
        var element = this.get(0);
    return (vals == 'none') ? 1 : vals.split('(')[1].split(')')[0].split(',')[0];
+
        var bounds = element.getBoundingClientRect();
};
+
        return bounds.top < window.innerHeight && bounds.bottom > 0;
 +
    };
  
/* Returns an array of the 4 inset values for an element. */
+
    /* Returns the scale transform value for an element. */
$.fn.getInsets = function() {
+
    $.fn.getScale = function() {
    var vals = this.css('clip-path');
+
        var vals = this.css('transform');
    if (vals == 'none') {
+
        return (vals == 'none') ? 1 : vals.split('(')[1].split(')')[0].split(',')[0];
        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);
 
};
 
 
 
/* Add visibility equivalents to show/hide/toggle */
 
$.fn.extend({
 
    vis: function () {
 
        return this.css("visibility", "visible");
 
    },
 
    invis: function () {
 
        return this.css("visibility", "hidden");
 
    },
 
    toggleVis: function () {
 
        return this.css("visibility", (b, a) => {
 
            return "visible" == a ? "hidden" : "visible";
 
        });
 
    }
 
});
 
  
/* HTML construction helper function */
+
    /* Returns an array of the 4 inset values for an element. */
var makehtml = window.makehtml = function (type, o, text) {
+
    $.fn.getInsets = function() {
    var i = '<' + type;
+
        var vals = this.css('clip-path');
    for (var key in o) {
+
         if (vals == 'none') {
         if (o.hasOwnProperty(key)) {
+
             vals = this.css('-webkit-clip-path');
             i += ' ' + key + '="' + o[key] + '"';
 
 
         }
 
         }
    }
+
        return vals.split('(')[1].split(')')[0].split(/px\s?/);
    i += (type === 'input') ? '' : '>';
+
     };
    i += (type === 'input') ? '/>' + (text || '') : (text || '') + '</' + type + '>';
 
     return i;
 
};
 
  
/* Add jQuery UI css */
+
    /* Sort the options within a select alphabetically */
var addjQueryCSS = function () {
+
    $.fn.sortOptions = function() {
    $('head').append(makehtml('link', {
+
        var optionList = this.find('option')
            rel: 'stylesheet',
+
            .sort(function(a, b) {
            type: 'text/css',
+
                return (a.text > b.text ? 1 : (a.text < b.text ? -1 : 0));
            href: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-darkness/jquery-ui.min.css'
+
            });
        }));
+
        return this.empty()
 +
            .append(optionList);
 +
    };
  
     /* Workaround for jQuery UI/Xenforo/Mediawiki css conflict */
+
     $.fn.extend({
    $('head').append(makehtml('style', {}, 'body .ui-dialog .ui-widget-header,body .ui-button {background:#333!important}'));
+
        /* 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 jQuery UI styling for input[type=number] */
+
        /* Add visibility equivalents to show/hide/toggle */
    $('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}'));
+
        vis: function() {
};
+
            return this.each(function() {
 
+
                $(this).css("visibility", "visible");
if (/^UO\:Atlas/.test(page) && namespace === 'UO' && $('.map-holder').length > 0) { /* Only run on UO Atlas pages which have a map present. */
+
            });
 
+
        },
    /* Remove unwanted default title attributes that cause browser tooltips. */
+
        invis: function() {
    $('a').each(function() {
+
            return this.each(function() {
        $(this).removeAttr("title");
+
                $(this).css("visibility", "hidden");
 +
            });
 +
        },
 +
        toggleVis: function() {
 +
            return this.each(function() {
 +
                $(this).css("visibility", function(b, a) {
 +
                    return "visible" == a ? "hidden" : "visible";
 +
                });
 +
            });
 +
        }
 
     });
 
     });
  
     /* Keep the map visible while scrolling. */
+
     /* Start: collapsible navboxes */
    var $body = $('#bodyContent'),
 
        $map = $('.map-holder:not(.noscroll)'),
 
        $doc = $(document);
 
    if ($map.length > 0) {
 
        var mapleft = $map[0].getBoundingClientRect().left;
 
        $map.css({
 
            position: 'fixed',
 
            left: mapleft,
 
            top: $body.offset().top - $doc.scrollTop()
 
        });
 
        $(window).scroll(function() {
 
            var ymax = $body.offset().top + $body.height() - $map.height() - $doc.scrollTop();
 
            if (ymax < 0) {
 
                $map.css('top', ymax);
 
            } else if ($('#mw-head').isOnScreen()) {
 
                $map.css('top', $body.offset().top - $doc.scrollTop());
 
            } else {
 
                $map.css('top', $('#navigation').height());
 
            }
 
        });
 
    }
 
  
    /* Flash icons on hover. */
+
     $('.navbox-inner:gt(0)').each(function () {
     $("span.pin").each(function () {
+
         $(this)[$(this).hasClass('expanded') ? 'removeClass' : 'addClass']('mw-collapsed');
         $(this).find('img').before('<span>');
 
    });
 
    $("#UOLinksList").on("mouseover", "span", function() {
 
        $("#" + $(this).attr("data-pair")).addClass('highlight').find('span').addClass('pin-circle');
 
    }).on("mouseout", "span", function() {
 
        $("#" + $(this).attr("data-pair")).removeClass('highlight').find('span').removeClass('pin-circle');
 
 
     });
 
     });
 +
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
 +
    $('.navbox-inner').makeCollapsible();
 +
});
  
     addjQueryCSS();
+
     /* End: collapsible navboxes */
  
    /* Add jCanvas (http://projects.calebevans.me/jcanvas/docs/) */
+
  /* Start Item Editor */
    $('head').append(makehtml('script', {
 
        src: 'https://cdnjs.cloudflare.com/ajax/libs/jcanvas/16.7.3/jcanvas.min.js'
 
    }));
 
  
    /* Adds a new canvas layer for each map */
+
if (action === 'edit' && (namespace === 'UO' || namespace === 'User')) {
    var addCanvas = function(thisClass, z) {
 
        $('.map:not(.mapcanvas)').each(function() {
 
            var $img = $(this).find('img');
 
            $(this).after(makehtml('div', {
 
                    class: 'map mapcanvas',
 
                    style: $(this).attr('style') + ((z === undefined) ? '' : 'z-index:' + z)
 
                },
 
                makehtml('canvas', {
 
                    class: thisClass,
 
                    width: $img.attr('width'),
 
                    height: $img.attr('height'),
 
                })
 
            ));
 
        });
 
    };
 
  
    /* Create the trigger icon */
+
  addjQueryCSS();
    $('.map-holder').append(makehtml('aside', {
 
        class: 'pin menutrigger',
 
        style: 'font-size: 25px;color:rgb(224, 171, 67);'
 
    }, '&#9881;'));
 
  
    /* Create and add the base tab html */
+
        /* Load properties JSON */
    var loc = location.href.toString().split('#')[0],
+
        $.getScript('/index.php?title=MediaWiki:PropertyBuilder.js&action=raw&ctype=text/javascript&1.0.1').complete(function() {
        tab1 = makehtml('li', {}, makehtml('a', {
 
            href: loc + '#mapoptions'
 
        }, 'Options')),
 
        tab2 = makehtml('li', {}, makehtml('a', {
 
            href: loc + '#mylocation'
 
        }, 'Find your location')),
 
        tab3 = makehtml('li', {}, makehtml('a', {
 
            href: loc + '#showhide'
 
        }, 'Show/hide icons')),
 
        tab4 = makehtml('li', {}, makehtml('a', {
 
            href: loc + '#addlocation'
 
        }, 'Add location')),
 
        tab5 = makehtml('li', {}, makehtml('a', {
 
            href: loc + '#editlocation'
 
        }, 'Edit location'));
 
    $("#toolmenu").prepend(makehtml('ul', {}, tab1 + tab2 + tab3 + tab4 + tab5));
 
  
    /* Create UI for 'find me' tab */
+
          /* Load jQuery UI */
    var xinput = makehtml('input', {
+
          mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function() {
            id: 'xcoord',
 
            maxlength: '4',
 
            size: '4',
 
            style: 'margin-top: 13px;padding: 2px 5px;min-height: 0;',
 
            type: 'text'
 
        }),
 
        yinput = makehtml('input', {
 
            id: 'ycoord',
 
            maxlength: '4',
 
            size: '4',
 
            style: 'margin-top: 13px;padding: 2px 5px;min-height: 0;margin-right: 7px;',
 
            type: 'text'
 
        }),
 
        findbutton = makehtml('input', {
 
            id: 'findme',
 
            type: 'button',
 
            value: 'Find me'
 
        }),
 
        removebutton = makehtml('input', {
 
            id: 'findme',
 
            type: 'button',
 
            value: 'Remove me from the map'
 
        });
 
    $('#mylocation').append('x: ' + xinput + 'y: ' + yinput + ' ' + findbutton + ' ' + removebutton);
 
  
    /* Populate the list of pintypes being used */
+
              /* Load Editor */
    var $checkboxes = $(makehtml('div', {
+
              $.getScript('/index.php?title=MediaWiki:PropertyEditor.js&action=raw&ctype=text/javascript&1.0.0', function() {
        id: 'pinlist'
+
                  loadEditor();
    }));
+
              });
    $('.pin-types').each(function() {
+
          });
        var inputText = $(this).attr('data-name'),
+
      });
            inputType = $(this).attr('data-pin');
+
  }
        $checkboxes.append(makehtml('label', {}, makehtml('input', {
 
            'data-type': inputType,
 
            type: 'checkbox',
 
            checked: 'true'
 
        }, inputText)) + '<br>');
 
    });
 
    $('#showhide').append($checkboxes);
 
  
     /* Populate the options tab for the gridlines option */
+
     /* End Item Editor  */
    $('#mapoptions').append(makehtml('label', {}, makehtml('input', {
 
        'data-option': 'gridlines',
 
        type: 'checkbox',
 
      }, 'Show gridlines')));
 
  
     /* Populate the options tab for the radar map option */
+
     /* Start Atlas Tools */
    $('#mapoptions').append('<br><br>' + makehtml( + 'label', {}, makehtml('input', {
 
        'data-option': 'radarMap',
 
        type: 'checkbox',
 
      }, 'Tilt map like radar view')));
 
  
     /* Enable the HTML for the add location tab */
+
     /* Only run on UO Atlas pages */
     var $addloc = $('#addlocation');
+
     if (/^UO\:Atlas/.test(mw.config.values.wgPageName)) {  // make current shard visible in the navbox
    $addloc.html($addloc.html().replace(/&lt;/g,'<').replace(/&gt;/g,'>'));
+
        setTimeout(function() {
 +
            var $expando = $('.mw-collapsible.uncollapsed').find('.mw-collapsible-text');
 +
            if ($expando.text() == 'Expand') $expando.click();
 +
        }, 1000);
 +
    }
  
    /* Add the control buttons for the pin edit tabs */
+
//       addjQueryCSS();
    $('.editPinButtons').append([
 
        '<input type="button" class="pinEditCancel" value="Cancel editing this pin" />',
 
        '<input type="button" class="pinEditStore" value="Store edits to this pin" />',
 
        '<input type="button" class="pinEditSubmit" value="Submit all edits" />'
 
    ]);
 
  
    /* Load jQuery UI */
+
        /* Load jQuery UI */
    mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function() {
+
//        mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function() {
  
        /* Initialize tabs and popup dialog */
+
            /* Load Editor */
        $("#toolmenu").tabs({
+
//            $.getScript('/index.php?title=MediaWiki:AtlasTools.js&action=raw&ctype=text/javascript');
            activate: function (event, ui) {
+
//        });
                var active = $('#toolmenu').tabs('option', 'active');
+
//    }
                $("#toolmenu").dialog({
 
                    height: {
 
                        mylocation:  225,
 
                        mapoptions:  285,
 
                        toolmenu:    700,
 
                        addlocation:  500,
 
                        editlocation: 400
 
                    }[$("#toolmenu ul>li a").eq(active).attr('href').split('#')[1]]
 
                });
 
            }
 
        }).dialog({
 
            autoOpen: false,
 
            draggable: true,
 
            width: 700,
 
            height: 285
 
        });
 
        $('.pinEditCancel, .pinEditStore .pinEditSubmit').invis();
 
  
        /* Add event handler for opening the dialog */
+
    /* Load Atlas Tools (separate from here to permit ES6 */
        $(".menutrigger").on("click", function() {
+
    $.getScript('/index.php?title=MediaWiki:Atlas%20Tools.js&action=raw&ctype=text/javascript&1.1.6');
            $('.mapmarker').remove();
+
    /* End Atlas Tools */
            $("#toolmenu").dialog("open").parent().css({
+
   
                opacity: '.8'
+
    /* Start Hunter's Guide scripts */
            });
 
            $(this).parent().find('div:eq(0)').append(makehtml('span', {
 
                class: 'mapmarker'
 
            }));
 
        });
 
  
        /* Add event handler for 'find me' button */
+
    if ($('a[title="Category:UO:Mobile"]').length > 0) {
        $('#findme').click(function() {
 
  
            var mainAtlas = /^UO\:Atlas\/[A-Za-z]+\//.test(mw.config.values.wgPageName);
+
        /* Block clicks to the edit tab as early as possible. */
            $('.mapmarker').after(makehtml('span', {
+
        $('a[accesskey="e"]').click(function(e) {
                    class: 'yourposition ' + $('.mapmarker').prev().attr('class'),
+
            e.preventDefault();
                    'data-name': 'Your location',
+
            $('body').data('editClicked', true);
                    style: 'left: ' + $("#xcoord").val() + 'px; top: ' + $("#ycoord").val() + 'px;'
+
             return false;
                },
 
                makehtml('img', {
 
                    src: 'http://stratics.com/w/images/b/b4/UO-icon-player.png',
 
                    width: (mainAtlas ? 6 : 12),
 
                    height: (mainAtlas ? 13 : 26)
 
                })
 
            ));
 
             $("#toolmenu").dialog("close");
 
 
         });
 
         });
  
         /* Add event handler for 'remove me' button */
+
         /* Allow scripts to be cached. */
         $('#removeme').click(function() {
+
         $.ajaxSetup({
             $('.yourposition').remove();
+
             cache: true
 
         });
 
         });
  
         /* Add event handler for changes to the pin list checkboxes */
+
         addjQueryCSS();
        $('#pinlist').on('change', 'input', function() {
 
            var pintype = $(this).attr('data-type');
 
            $('.' + pintype)[this.checked ? 'show' : 'hide']();
 
        });
 
  
        /* Add container for the radar map option */
+
        /* Load jQuery UI */
        $('.map').parent().wrap('<div class="mapCollection"><div>');
+
        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();
        /* Add event handler for selections on the options tab */
+
       
        $('#mapoptions').on('change', 'input', function() {
+
            /* Load jQuery UI selectmenu */
            var option = $(this).attr('data-option');
+
            $.getScript('https://cdn.rawgit.com/jquery/jquery-ui/master/ui/widgets/selectmenu.js').complete(function() {
            switch (option) {
 
                case 'gridlines':
 
                case 'serverlines':
 
                    $('.' + option).toggle();
 
                    break;
 
                case 'radarMap':
 
                    $('.mapCollection').toggleClass('radarMap');
 
                    break;
 
            }
 
        });
 
 
 
        /* Create gridline overlays */
 
        addCanvas('gridlines', 1);
 
        $('.gridlines').hide().each(function() {
 
            var x,
 
                y,
 
                width = $(this).width(),
 
                height = $(this).height(),
 
                scale = $(this).parent().parent().getScale(),
 
                insets = $(this).parent().getInsets();
 
            var visibleX = parseInt(insets[3], 10) + 4 + (96 / scale),
 
                visibleY = parseInt(insets[0], 10) + (72 / scale),
 
                linewidth = Math.ceil(5 / scale),
 
                fontsize = Math.ceil(60 / scale) * 1.4;
 
   
 
            fontsize = (fontsize > 60) ? 60 : fontsize;
 
   
 
            for (y = 0; y < height; y = y + 100) {
 
                $(this).drawLine({
 
                    strokeStyle: 'rgb(224, 171, 67)',
 
                    strokeWidth: linewidth,
 
                    x1: 0,
 
                    y1: y,
 
                    x2: width,
 
                    y2: y
 
                }).drawText({
 
                    fillStyle: '#fff',
 
                    x: visibleX,
 
                    y: y + 5,
 
                    fontSize: fontsize,
 
                    fontFamily: 'Verdana, sans-serif',
 
                    text: y
 
                });
 
            }
 
   
 
            for (x = 100; x < width; x = x + 100) {
 
                $(this).drawLine({
 
                    strokeStyle: 'rgb(224, 171, 67)',
 
                    strokeWidth: linewidth,
 
                    x1: x,
 
                    y1: 0,
 
                    x2: x,
 
                    y2: height
 
                });
 
            }
 
   
 
            for (x = 100; x < width; x = x + ((scale == 1) ? 200 : 100)) {
 
                $(this).drawText({
 
                    fillStyle: '#fff',
 
                    x: x,
 
                    y: visibleY,
 
                    fontSize: fontsize,
 
                    fontFamily: 'Verdana, sans-serif',
 
                    text: x
 
                });
 
            }
 
        });
 
  
        /* Add functionality for the Add Location tab */
+
                /* Load Localization */
        addCanvas('addlocation', 3);
+
                $.getScript('/index.php?title=MediaWiki:Localization.js&action=raw&ctype=text/javascript&1.0.5').complete(function() {
        $('#getlocbtn').click(function() {
 
            $("#toolmenu").dialog("close");
 
            $('.addlocation,.gridlines,.serverlines').css('cursor', 'crosshair').click(function(event) {
 
                var $this = $(this),
 
                    rect = this.getBoundingClientRect();
 
                var x = Math.round($this.width() / rect.width * (event.clientX - rect.left)),
 
                    y = Math.round($this.height() / rect.height * (event.clientY - rect.top));
 
                var makeWiki = function() {
 
                    var str = '-->{{UOAddPin|';
 
                    str += $('#getlocselect').val() + '|';
 
                    str += x + '|' + y + '|' + $('#getlocdescription').val();
 
                    var wiki = $('#getlocwikipage').val();
 
                    if (wiki.length > 0) {
 
                        str += '|link=' + wiki;
 
                    }
 
                    str += '}}<!--';
 
                    return str;
 
                };
 
  
                $('.addlocation,.gridlines,.serverlines').css('cursor', 'auto');
+
                    /* Load Mob Editor */
                $('#getloccoords').text(x + ' x ' + y);
+
                    $.getScript('/index.php?title=MediaWiki:Mob%20Editor.js&action=raw&ctype=text/javascript&1.1.6');
                $('#getlocresult').text(makeWiki);
 
                $('#getloctext').show();
 
                $("#toolmenu").dialog("open");
 
                $('#getlocwikipage, #getlocselect, #getlocdescription').on("change keyup", function() {
 
                    $('#getlocresult').text(makeWiki);
 
                });
 
            });
 
        });
 
  
        if (/^UO\:Atlas\/(?:Fel|Tram)/.test(page)) { /* Only run on Felucca and Trammel maps. */
+
                    /* Load Animal Lore Editor */
 +
                    $.getScript('/index.php?title=MediaWiki:AnimalLoreTool.js&action=raw&ctype=text/javascript&1.2.23');
  
            /* Populate the options tab for the gridlines option */
+
                });
            $('#mapoptions').append('<br><br>' + makehtml('label', {}, makehtml('input', {
+
            });
                'data-option': 'serverlines',
 
                type: 'checkbox',
 
            }, 'Show server lines')));
 
  
            /* Create server line overlays */
+
            /* Load OrgChart generator script */
            addCanvas('serverlines', 2);
+
            $.getScript('/index.php?title=MediaWiki:Orgchart.js&action=raw&ctype=text/javascript&1.0.0').complete(function() {
            $('.serverlines').hide().each(function() {
 
                var $this = $(this);
 
                var height = $this.height(),
 
                    scale = $this.parent().parent().getScale();
 
                var linewidth = Math.ceil(5 / scale);
 
                var makeLine = function(x1, y1, x2, y2) {
 
                    $this.drawLine({
 
                        strokeStyle: 'red',
 
                        strokeWidth: linewidth,
 
                        x1: x1,
 
                        y1: y1,
 
                        x2: x2,
 
                        y2: y2
 
                    });
 
                };
 
  
                makeLine(0, 2030, 2678, 2030);
+
                /* Load Mob taxonomy data */
                makeLine(2678, 0, 2678, height);
+
                $.getScript('/index.php?title=MediaWiki:MobData.js&action=raw&ctype=text/javascript&1.0.8').complete(function() {
                makeLine(0, 1281, 2679, 1281);
 
                makeLine(1536, 1281, 1536, 0);
 
                makeLine(3838, 0, 3838, height);
 
            });
 
  
        }
+
                    /* 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');
 +
    }
  
/* Start: collapsible navboxes */
+
    /* End Hunter's Guide scripts */
  
$('.navbox-inner:gt(0)').addClass('mw-collapsed');
+
    /* Start suit-page scripts */
$('.navbox-inner').makeCollapsible();
+
    // 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 */
  
/* End: collapsible navboxes */
+
    /* Start crafter table script */
  
/* Start property editor */
+
    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() {
  
if (action === 'edit' && (namespace === 'UO' || namespace === 'User' )) {
+
            // This next works around the fact that mediawiki doesn't build proper HTML for tables.
    addjQueryCSS();
+
            $('.crafteditems:not(.nosort)').each(function () {
    /* Load properties JSON */
+
                var th, trs, $this = $(this);
    $.getScript('/w/index.php?title=MediaWiki:PropertyBuilder.js&action=raw&ctype=text/javascript').complete(function () {
+
                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);
 +
            });
  
        /* Load jQuery UI */
+
            // Init stupidtable
        mw.loader.using(['jquery.ui.button', 'jquery.ui.tabs', 'jquery.ui.dialog'], function () {
+
            $('table.crafteditems').stupidtable();
 +
            setTimeout(function(){
 +
                $('.craftablecategory').click();
 +
            }, 1);
  
            /* Load Editor */
 
            $.getScript('/w/index.php?title=MediaWiki:PropertyEditor.js&action=raw&ctype=text/javascript', function () {
 
                loadEditor();
 
            });
 
 
         });
 
         });
     });
+
     }
}
+
 
 +
  /* End crafter table scripts */
  
/* End property editor */
+
    /* 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();
}());