User:Alexis Jazz/Factotum/modules/Emoji-inator.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
if ( typeof window.FTTModules == 'undefined' ) { window.FTTModules=[]; }
/*globals $:false,mw:false,OO:false*/
window.FTTModules.push({'load':['afterOpenForm','processComment'],'afterOpenFormFunc':function(emoInt){
	FTT.MD.emoji = {};
	FTT.MD.emoji.div = document.createElement('div');
	FTT.MD.emoji.div.id = 'FTTEmojiContainer';
	FTT.MD.emoji.divAll = document.createElement('div');
	FTT.MD.emoji.divAll.id = 'FTTEmojiButtons';
	FTT.MD.emoji.emojis = [ //descriptions copied from [[:Emoticons (Unicode block)]] (CC BY-SA 3.0) which is partially based on https://unicode.org/Public/UNIDATA/emoji/emoji-data.txt (https://www.unicode.org/license.txt)
		['😀',new RegExp(':\\-D','g'),'grinning face'],
		['😁',null,'grinning face with smiling eyes'],
		['😂',null,'face with tears of joy'],
		['😃',new RegExp(':-\\)','g'),'smiling face with open mouth (c.f. ☺)'],
		['😄',null,'smiling face with open mouth and smiling eyes'],
		['😅',null,'smiling face with open mouth and cold sweat'],
		['😆',null,'smiling face with open mouth and tightly-closed eyes'],
		['😇',null,'smiling face with halo '],
		['😈',null,'smiling face with horns (c.f. 👿 "imp")'],
		['😉',new RegExp(';-\\)','g'),'winking face'],
		['😊',null,'smiling face with smiling eyes'],
		['😋',null,'face savouring delicious food'],
		['😌',null,'relieved face'],
		['😍',null,'smiling face with heart-shaped eyes'],
		['😎',null,'smiling face with sunglasses'],
		['😏',null,'smirking face'],
		['😐',null,'neutral face (also used for "west wind" 西 in some Mahjong annotation)'],
		['😑',null,'expressionless face'],
		['😒',null,'unamused face'],
		['😓',null,'face with cold sweat'],
		['😔',null,'pensive face'],
		['😕',null,'confused face'],
		['😖',null,'confounded face'],
		['😗',null,'kissing face'],
		['😘',null,'face throwing a kiss'],
		['😙',null,'kissing face with smiling eyes'],
		['😚',null,'kissing face with closed eyes'],
		['😛',null,'face with stuck-out tongue'],
		['😜',null,'face with stuck-out tongue and winking eye'],
		['😝',null,'face with stuck-out tongue and tightly-closed eyes'],
		['😞',null,'disappointed face'],
		['😟',null,'worried face'],
		['😠',null,'angry face'],
		['😡',null,'pouting face'],
		['😢',null,'crying face'],
		['😣',null,'persevering face'],
		['😤',null,'Unicode: face with look of triumph, Apple: huffing with anger face'],
		['😥',null,'disappointed but relieved face'],
		['😦',null,'frowning face with open mouth'],
		['😧',null,'anguished face'],
		['😨',null,'fearful face'],
		['😩',null,'weary face'],
		['😪',null,'sleepy face'],
		['😫',null,'tired face'],
		['😬',null,'grimacing face'],
		['😭',null,'loudly crying face'],
		['😮',null,'face with open mouth'],
		['😯',null,'hushed face'],
		['😰',null,'face with open mouth and cold sweat'],
		['😱',null,'face screaming in fear'],
		['😲',null,'astonished face'],
		['😳',null,'flushed face'],
		['😴',null,'sleeping face'],
		['😵',null,'dizzy face'],
		['😶',null,'face without mouth (c.f. ⚇ "white circle with two dots")'],
		['😷',null,'face with medical mask'],
		['😸',null,'grinning cat face with smiling eyes'],
		['😹',null,'cat face with tears of joy'],
		['😺',null,'smiling cat face with open mouth'],
		['😻',null,'smiling cat face with heart-shape eyes'],
		['😼',null,'cat face with wry smile'],
		['😽',null,'kissing cat face with closed eyes'],
		['😾',null,'pouting cat face'],
		['😿',null,'crying cat face '],
		['🙀',null,'weary cat face'],
		['🙁',null,'slightly frowning face'],
		['🙂',null,'slightly smiling face'],
		['🙃',null,'upside-down face'],
		['🙄',null,'face with rolling eyes'],
		['🙅',null,'face with "no good" gesture, with lower arms crossed, derived from the japanese gesture for "no". Intended as gender-neutral but represented as a woman on most platforms (Apple name: "Woman Gesturing No").'],
		['🙆',null,'face with "ok" gesture, described as a person with arms raised above the head forming a "circle", interpreted as "OK sign" (derived from the japanese gesture for "OK"). Intended as gender-neutral but represented as a woman on most platforms (Apple name: "Woman Gesturing OK").'],
		['🙇',null,'person bowing (dogeza), depicted as a man on most platforms (Apple name: "Man Bowing")'],
		['🙈',null,'see-no-evil monkey'],
		['🙉',null,'hear-no-evil monkey'],
		['🙊',null,'speak-no-evil monkey'],
		['🙋',null,'happy person raising one hand, a person raising one hand as if to answer a question, intended as gender-neutral but represented as a woman on most platforms (Apple name: "Happy Woman Raising One Hand")'],
		['🙌',null,'person raising both hands in celebration, on many platforms depicted as just the raised hands (Apple name: "Hands Raised in Celebration")'],
		['🙍',null,'person frowning'],
		['🙎',null,'person with pouting face'],
		['🙏',null,'person with folded hands (to indicate variously sorrow, regret, pleading, praying, bowing, thanking). In most platforms depicted as just the hand, pressed together but not folded (Apple name: "Hands Pressed Together").']
	];
	FTT.MD.emoji.buttons = [];
	FTT.MD.emoji.makeButton = function(int,emoji,desc){
		FTT.MD.emoji.buttons[int] = new OO.ui.ButtonWidget({label:emoji,title:desc,framed:false});
		FTT.MD.emoji.buttons[int].$button.attr('aria-label',desc);
		FTT.MD.emoji.buttons[int].on('click',function(){ console.log(this);FTT.insertMarkup('cI','',emoji+' ','',FTT.focusNode,FTT.focusOffset,FTT.anchorNode,FTT.anchorOffset);});
	};
	for(emoInt=0;emoInt<FTT.MD.emoji.emojis.length;emoInt++) {
		FTT.MD.emoji.makeButton(emoInt,FTT.MD.emoji.emojis[emoInt][0],FTT.MD.emoji.emojis[emoInt][1]);
	}
	FTT.MD.emoji.horizontalLayout = new OO.ui.HorizontalLayout({items:FTT.MD.emoji.buttons});
	FTT.MD.emoji.divAll.append(FTT.MD.emoji.horizontalLayout.$element[0]);
	FTT.insertAfter($('#FTTCustomInserts')[0],FTT.MD.emoji.divAll);
	if ( ! FTT.MD.emoji.addedCSS ) {
		mw.util.addCSS('#FTTEmojiButtons .oo-ui-buttonElement-frameless.oo-ui-labelElement:first-child{margin-left:unset !important} #FTTEmojiButtons .oo-ui-buttonElement-button:active{border:none !important} #FTTEmojiButtons .oo-ui-buttonElement-frameless.oo-ui-labelElement > .oo-ui-buttonElement-button{border-width:0 !important}');
		FTT.MD.emoji.addedCSS = 1;
	}
	},processCommentFunc:function(text1,emoInt2){
		if ( ! text1 || ! FTT.MD.emoji ) {
			return text1;
		}
		for(emoInt2=0;emoInt2<FTT.MD.emoji.emojis.length;emoInt2++) {
			if ( FTT.MD.emoji.emojis[emoInt2][1] ) {
				text1 = text1.replace(FTT.MD.emoji.emojis[emoInt2][1],FTT.MD.emoji.emojis[emoInt2][0]);
			}
		}
		return text1;
	}
});