User:Jennica/global.js

/** /*global jQuery, mediaWiki*/ /*jshint eqeqeq:true, forin:false, laxbreak:true, trailing:true, undef:true, unused:true, white:false, smarttabs:true */ (function ($, mw) { "use strict"; if (typeof mw.libs.wikiEditorEmoticons === 'function') return; // load only once // $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', { 'section': 'emoticons' }); // Remove // window.customSmilies = [':-)',';-)',':-D',':-S','X-)','mm','lol','doh','=>'];
 * Insert WikiEditor (sMirC) emoticons buttons
 * @created 2014-08-16
 * @source mw:Extension:WikiEditor/Toolbar customization, SMirC
 * @version 0.2.2 (00:22, 5 October 2016 (UTC))
 * @author User:Perhelion, 2014
 * @license released in the public domain
 * @ToDo:
 * Classic toolbar support?
 * Flow support?
 * Config UI with autoamtic save
 * meh
 * @required modules: mw.user, wikiEditor

// Pool of available smilies var smilyPool = { ":-)" : ["6/69", "smile"], ";-)" : ["e/ec", "wink"], ":-D" : ["e/e3", "beam"], ":-S" : ["8/8c", "dunno"], "X-)" : ["6/66", "grin"], "=>" : ["9/90", "happy"], "lol" : ["5/5a", "laugh"], "doh" : ["a/a2", "doh"], "mm" : ["0/00", "mmm"], "-.-" : ["6/6d", "bored"], "\"-:" : ["0/0b", "whistle"], "^_^" : ["9/91", "chuckle"], "B)" : ["0/08", "cool"], "ʕ•ᴥ•ʔ" : ["e/e3", "bearhug"], "0:)" : ["3/3f", "angel"], "3:D" : ["4/40", "devil"], "*,,*" : ["c/c2", "vamp"], "(.V.)" : ["b/bf", "alien"], "☠" : ["b/b3", "dead"], "@_,@" : ["b/b3", "stoned"], "(ﾟ＊ﾟ)" : ["5/56", "puke"], "(°₀°)" : ["5/54", "jealous"], ">:[]" : ["0/0e", "angry"], "♨" : ["0/0d", "hot"], ":-{}" : ["9/93", "freezing"], "x_x" : ["3/3d", "spent"], "hi" : ["5/5a", "hi"], "stop" : ["4/47", "beware"], "-<-@" : ["6/62", "congrats"], "*<:o)" : ["f/f5", "party"], "yes" : ["1/1f", "thumbsup"], "no" : ["c/c8", "thumbsdown"], "O_O" : ["0/0c", "shock"], "°o°" : ["5/5f", "goggle"], "8-O" : ["e/e8", "scream"], // 35 ":-(" : ["3/39", "sad"], ":-|" : ["d/d5", "medium"], "8-(" : ["a/aa", "puppyeyes"], "8)" : ["6/66", "rolleyes"], "(~_~)" : ["e/e3", "unnerved"], ";,(" : ["a/ae", "cry"], "<3" : ["b/b6", "love"], ":-*" : ["8/80", "kiss"], "???" : ["3/35", "what"], "zZz" : ["4/4b", "zzz"], ";-/" : ["c/c2", "sceptic"], ":-x" : ["5/58", "silent"], ":-P" : ["c/c3", "tongue"], "%Þ" : ["1/1e", "crazy"], "<3Þ" : ["6/64", "horny"], "$Þ" : ["e/ec", "greedy"], "●^_^●" : ["0/00", "shy"], "●°.°●" : ["7/7f", "embarassed"], "8-)" : ["d/d2", "nerd"], "8-°" : ["d/d8", "wasntI"], "8-[" : ["8/85", "worry"], "o_O" : ["8/8b", "wtf"], "(-°-)" : ["1/17", "martial"], "xmas" : ["a/ab", "xmas"], "C(_)" : ["3/33", "coffeebreak"], "m(" : ["9/95", "facepalm"], "daisy" : ["2/23", "daisy"], "☀" : ["5/5d", "sunny"], "☁" : ["3/37", "cloudy"], "☂" : ["d/d2", "rainy"], "☈" : ["2/27", "thundery"], "☃" : ["9/9e", "snowy"], "≈" : ["5/55", "hazy"], "\\S/" : ["d/d3", "super"], "wine" : ["0/07", "wine"], "palm" : ["9/90", "palm"], "(_*_)" : ["1/10", "ass"] }, smilies = [];

// Add smilies to the toolbar in the specified order and count var order = window.customSmilies; if ( $.isArray(order) ) { for (var i = 0, l = order.length; i < l; i++) { var smilie = smilyPool[order[i]]; if (!smilie) throw new Error('Unknown smilie: ' + order[i]); else { // Dict to array smilie.push(order[i]); smilies.push(smilie); }	} } else { // Dict to array for ( var k in smilyPool ) { smilyPool[k].push( k ); smilies.push( smilyPool[k] ); } }

var ns = mw.config.get('wgNamespaceNumber'), cUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/', //Commons /** sMirC emoticons only **/ s = 'SMirC-', sMList = {}, sRlen = Math.max(Math.ceil(smilies.length / 2), 35), // Max 35 preferred sRo = ['¹','²','³','⁴'], // Max 2 rows supported? sRi = 0;

if (smilies.length > sRlen) { addSmilie(sRo[sRi], smilies.splice(0, sRlen) ); sRi++; } if (smilies.length) addSmilie(sRo[sRi], smilies);

function addSmilie(gp, sL) { // Make buttons var sb = {}, // Smilie buttons fns = 'x20px|' + k + '' } }		};	}	sMList[gp] = { label : gp, tools : sb	}; } mw.libs.wikiEditorEmoticons = function { // make to toolbar $('#wpTextbox1').wikiEditor('addToToolbar', {		'sections' : {			'emoticons' : {				'type' : 'toolbar',				//'deferLoad': true,				'groups' : sMList			}		}	}); $('.tab-emoticons a').append($(' ') // made section button (hack)		.attr({ src : cUrl + '5/59/Cute_Ball_-_Games.png/22px-Cute_Ball_-_Games.png', width : 22, height : 22, title : 'Emoticons', rel : s,			role : 'button', 'class' : 'tool tool-button' }));	if ($(document).width < 1100) // made bar wider (hack) mw.util.addCSS(".section-emoticons .label {display:none}" +			".section-emoticons {width:900px;margin-left:-5px}" +			"#content {margin-left:140px; margin-right:-54px; padding: 9px}" +			"#mw-panel {margin-left:-22px}"); };

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar… */ $(function {	if ((ns % 2 === 1 || $.inArray(ns, [2, 4]) !== -1) && mw.config.get('wgPageContentModel') === "wikitext")		mw.loader.using(['mediawiki.util', 'user.options'], function  { if (mw.toolbar && (mw.user.options.get('usebetatoolbar') || /^(load|ready)/.test(mw.loader.getState('ext.wikiEditor')))) $.when(mw.loader.using(['ext.wikiEditor']), $.ready).then(mw.libs.wikiEditorEmoticons); //else console.log('You have not enabled the enhanced toolbar (WikiEditor) to show the Emoticons bar!'); }); }); })(jQuery, mediaWiki);