User:Pecoes/global.js

$(function {    window.Sine = function (my) {        my = $.extend(true, { sine: '' + String.fromCharCode(126) + '~', spacer: '--' }, my);       if (!my.talkNameSpaces) my.talkNameSpaces = [1,3,5,7,9,11,13,15,110,111,114,401,500,501,502,503];        if (-1 == $.inArray(wgNamespaceNumber, my.talkNameSpaces) || 'edit' != $.getUrlVar('action')) return;        my.add = function  {            if ($('input#wpMinoredit').is(':checked')) return;            console.clear;            console.log('Sine.add');            switch (editorInstance.mode) {                case 'wysiwyg':                    sineWYSIWYG;                    break;                case 'source':                    sineSource;                    break;            }        };        my.init = function  {            if (undefined == window.editorInstance) {                console.log('Sine is waiting');                window.setTimeout( function { window.Sine.init; }, 100               )                return;            }            $('input#wpSave').click(window.Sine.add);            $('a#publish').click(window.Sine.add);            console.log('Sine is ready');        };        var blocks;        function sineWYSIWYG  {            var wysiwyg = editorInstance.getEditbox;            if (isSined(wysiwyg)) return;            blocks = wysiwyg.find('> *');            console.log('blocks: %o', blocks);            if (!blocks.length) return;            var b = blocks.last;            var inserted = false;            if (b.is('p,dl')) {                inserted = insertSine(b);            }            if (!inserted) {                console.log(' ');                console.log(b);                wysiwyg.append(createSine);            }        }        function createSine  {            var s, left, depth, type = getIndentType; console.log('indent type: '+type); switch (type) { case 'p': left = getIndent('p'); console.log('left: '+left); s = $(' ' + sine + ' '); if (left) s = s.css({ marginLeft: left }); break; case 'dl': depth = getIndent('dl'); console.log('depth: '+depth); s = sine; for (var i = 0; i < depth; i++) { s = '' + s + ''; }               break; }           return s;        } function getIndentType { for (var i = blocks.length - 1; i >= 0 ; i--) { var b = $(blocks[i]); if (b.is('p')) return 'p'; if (b.is('dl')) return 'dl'; }           return 'p'; }       function getIndent (type) { var b, left, depth; console.log('getIndent'); for (var i = blocks.length - 1; i >= 0 ; i--) { b = $(blocks[i]); console.log(b); if (b.is('p')) { left = b.css('marginLeft'); return 'p' == type ? left : parseInt(left) / 20; }               else if (b.is('dl')) { depth = 0; console.log(b.parents('dd')); while (b.parents('dl').length) b = b.parents('dl'); b.find('dl').each( function{                       var d = $(this).parents('dl').length + 1;                        if (d > depth) depth = d;                    }); console.log(depth); return 'dl' == type ? depth : (depth * 20).toString + 'px'; }           }            return 0; }       function basicSine  { return my.sine; }       function isText (element) { console.log(element[0].nodeName); return '#text' == element[0].nodeName; }       function isSined (element) { console.log('sine: %s', basicSine); console.log('signed: ' + (basicSine == element.text.trim.substr(-basicSine.length))); return basicSine == element.text.trim.substr(-basicSine.length); }       function spacedSine  { return (my.spacer.length ? ' ' + my.spacer + ' ' : ' ') + basicSine; }

function isInline (element) { return 'inline' == element.css('display') && !element.is('img[class*="placeholder"]'); }       function insertSine (block) { var b = block; if (block.is('dl')) { b = block.find('dd:last'); b = b.parent.children.last; if (!b.is('dd,p')) return false; }           var contents = $.makeArray(b.contents); console.log(contents); if (!contents.length) { b.append(basicSine); return true; }           var c = $(contents.pop); console.log('last content: %o; nodeType: %i, nodeName: %s', c, c[0].nodeType, c[0].nodeName); if ('#text' == c[0].nodeName) { console.log('appending Sine to text'); c.after(spacedSine); return true; }           else if (c.is('br')) { var s = basicSine; if (contents.length) { var prev = $(contents.pop); console.log("prev: %o; nodeName: %s", prev, prev[0].nodeName); if ('#text' != prev[0].nodeName && !isInline(prev)) return false; s = spacedSine; }               console.log('prepending sine to br'); c.before(s); return true; }           else if (isInline(c)) { console.log('appending Sine to inline node'); c.after(spacedSine); return true; }           return false; }       function isList (line) { return /^\:*[*#]/.test(line); }       function isHeader (line) { return /^(={2,6})[^=]+\1$/.test(line); }       function isBlock (line) { return /(?:|\}\}|<\/(?:blockquote|div|pre|code|nowiki)>)$/.test(line); }       function sineSource  { var source = editorInstance.getContent; if (!source.trim.length) return; var lines = source.split(/\r\n|\r|\n/).reverse; var l = lines[0].trim; var s = basicSine; if (l.length) { if (basicSine == l.substr(-4)) return; if (isList(l) || isHeader(l) || isBlock(l)) { s = "\r\n" + emptySine(lines); } else { s = spacedSine; }           } else { s = emptySine(lines); if (!s) return; }           editorInstance.setContent(source + s); }       function emptySine (lines) { var s = basicSine; for (var i = 1; i < Math.min(4, lines.length); i++) { var l = lines[i].trim; if (!l.length) continue; if (basicSine == l.substr(-4)) return false; var m = l.match(/^(\:+)/); if (m) s = m[1] + s;               break; }           return s;        } my.init; return my; }(window.Sine || {}); });

importScriptPage('FixWantedFiles/code.js', 'dev'); importScriptPage('FastDelete/code.js', 'dev'); importScriptPage('AjaxUndo/code.js', 'dev'); importScriptPage('PurgeButton/code.js', 'dev' );

var menu = [ ['JE Modding', 'http://jadeempire-modding.wikia.com/', ['Admin Dashboard', 'http://jadeempire-modding.wikia.com/wiki/Special:AdminDashboard'], ['Sandbox', 'http://jadeempire-modding.wikia.com/wiki/User:Pecoes/Sandbox'], ['Wikia.css', 'http://jadeempire-modding.wikia.com/wiki/MediaWiki:Wikia.css'], ['Common.js', 'http://jadeempire-modding.wikia.com/wiki/MediaWiki:Common.js'] ],   ['Community Central', 'http://community.wikia.com/', ['Admin Forum', 'http://community.wikia.com/wiki/Admin_Central:Forum'], ['Community Forum', 'http://community.wikia.com/wiki/Forum:Community_Central_Forum'], ['Global.js',, 'http://community.wikia.com/wiki/User:Pecoes/global.js'], ],   ['Dev', 'http://dev.wikia.com/', ['Cheatsheet', 'http://dev.wikia.com/wiki/JS_and_CSS_Cheatsheet'], ['JavaScript', 'http://dev.wikia.com/wiki/List_of_JavaScript_Enhancements'] ],   ['API', 'http://jadeempire-modding.wikia.com/api.php'] ];

function renderMenu (menu) { if (undefined == window.wgUserName) return ''; var html = ''; html += ''; html += ''; html += ''; if (undefined != menu && menu instanceof Array) { html += ''; for (var i = 0; i < menu.length; i++) { html += renderMenuLevelOne(menu[i]); }       html += ""; }   html += ''; return html; }

function renderMenuLevelOne (menu) { if (undefined == menu || !(menu instanceof Array)) return ' '; var url, title, html; title = typeof menu[0] == 'string' ? menu[0] : 'undefined'; url  = typeof menu[1] == 'string' ? menu[1] : 'undefined'; html = ''; html += '' + title; if (menu.length > 2) { html += ''; html += ''; html += ''; for (var i = 2; i < menu.length; i++) { html += renderMenuLevelTwo(menu[i]); }       html += "</ul>"; }   else html += '</a>'; html += '</li>'; return html; }

function renderMenuLevelTwo (menu) { var url, title, html; title = typeof menu[0] == 'string' ? menu[0] : 'undefined'; url  = typeof menu[1] == 'string' ? menu[1] : 'undefined'; html = '<a class="subnav-3a" href="' + url + '">' + title + '</a></li>'; return html; }

$(function {

// bookmark menu: $('#WikiHeader nav ul:first').append(renderMenu(menu)); $('#WikiHeader > nav').css({ width: "580" }); var navWidth = 0; $('#WikiHeader > nav > ul > li').each(function { navWidth += $(this).width; }); if (560 < navWidth) $('#WikiHeader > nav > ul > li > a').css({ paddingLeft: "11px", paddingRight: "11px" }); if (typeof WikiHeaderV2 != "undefined") WikiHeaderV2.init;

});