Mabinogi World Wiki is brought to you by Coty C., 808idiotz, our other patrons, and contributors like you!!
Want to make the wiki better? Contribute towards getting larger projects done on our Patreon!

MediaWiki:Toolbar.js

From Mabinogi World Wiki

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(function(){if ($().wikiEditor) {
////////// Insertables //////////
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
  'section': 'main',
  'group': 'insert',
  'tools': {
    'youtube': {
      label: 'YouTube Video',
      type: 'button',
      icon: '//forums.mabi.world/extensions/WikiEditor/modules/images/toolbar/youtube.png',
      action: {
        type: 'encapsulate',
        options: {
          pre: "{{youtube|",
          peri: "ViDe0id",
          post: "}}"
        }
      }
    }
  }
} );

////// Forums/Talk Section //////
var emoteNames = ["Angry", "Close2Tears", "Confused", "Cool", "Cry", "Cute", "Evil", "EyesClosed", "Fart", "Fear", "HappyTears", "Happy", "Hazy", "Impressed", "Jeah", "Justice", "Laugh", "Lucky", "Mischevious", "Naive", "Pain", "Perv", "Puzzled", "Question", "Relief", "Sad", "SelfControl", "Serious", "Shriek", "Shy", "Sour", "Sparkling", "Surprised", "Suspicious", "Sympathy", "Vacant", "Warm", "WhatThe", "WickedPlan", "Wicked", "Wink", "Yawn"];

var colors = ["Transparent", "", "White", "Red", "Pink", "LightPink", "Orange", "Yellow", "Green", "Blue", "LightBlue", "Purple", "Black"];
var borders = ["transparent", "", "#7f7f7f", "darkred", "#df0027", "pink", "darkorange", "#7f7f00", "darkgreen", "darkblue", "blue", "#400040", "black"];

function buildEmoteAction(replacement) {
  return {
    type: 'replace',
    options: {
      peri: replacement,
      selectPeri: false
    }
  }
}

function buildEmotes(i, emoteSrcs) {
  var emotes = [];
  var style = ';padding:0px;height:20px;width:20px;margin:-2px 0px 0px -2px';
  var color = colors[i];
  
  for (var j = 0; j < emoteNames.length; j++) {
    var name = emoteNames[j];
    var img = '<img alt="' + name + '" src="' + emoteSrcs[j] + '" title="' + name + '" width="24" height="24">';
    if (color == "") {
      emotes.push({
        'mode': 'html',
        'label': '<span class="emoticon" style="border-color:#CCBB00' + style + '">' + img + '</span>',
        'action': buildEmoteAction('{{Emote|' + name + '}}'),
        'titleMsg': name
      });
    } else {
      emotes.push({
        'mode': 'html',
        'label': '<span class="emoticon" style="background-color:' + color + '; background:radial-gradient(ellipse at 4px 4px, #f2f1f1 0%,' + color + ' 100%);border-color:' + borders[i] + style + '">' + img + '</span>',
        'action': buildEmoteAction('{{Emote|' + name + '|' + color + '}}'),
        'titleMsg': name + '-' + color
      });
    }
  }

  return emotes;
}

function buildPages(emoteSrcs) {
  var pages = {};
  for (var i = 0; i < colors.length; i++) {
    var color = colors[i];

    pages[color.toLowerCase()] = {
      'layout': 'characters',
      'color': color.toLowerCase() || "#f1da36",
      'label': color || "Default",
      'characters': buildEmotes(i, emoteSrcs),
    }
  }

  return pages;
}

$.ajax({
  'url': '/api.php?action=query&titles=File:Emoticon' + emoteNames.join('.png|File:Emoticon') + '.png&prop=imageinfo&iiprop=url&format=json',
  'success': function (data) {
    $('#wpTextbox1').wikiEditor('addToToolbar', {
      'sections': {
        'emotes': {
          'filters': [ 'body.ns-talk', 'body.mw-special-WikiForum' ],
          'type': 'booklet',
          'label': 'Emotes'
        }
      }
    });

    var emoteSrcs = new Array(emoteNames.length);
    for(var page in data.query.pages) {
      page = data.query.pages[page];
      var emote = page.title.match(/File:Emoticon([^.]+)\.png/)[1];
      emoteSrcs[emoteNames.indexOf(emote)] = page.imageinfo[0].url;
    }

    $('#wpTextbox1').wikiEditor('addToToolbar', {
      'section': 'emotes',
      'pages': buildPages(emoteSrcs),
    });
  }
});
/////////////////////////////////

}});