משתמש:1Or/Emoji.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
mw.loader.using(["oojs-ui", "jquery.ui", "mediawiki.api", "mediawiki.util", 'ext.wikiEditor', 'jquery.textSelection']).done(function(){
	$(function($) {
		function done(template, dialog) {
			dialog.dialog("close");
			var messageDialog = new OO.ui.MessageDialog();
			var windowManager = new OO.ui.WindowManager();
			$( 'body' ).append( windowManager.$element );
			windowManager.addWindows( [ messageDialog ] );
			windowManager.openWindow( messageDialog, {
			  message: 'כמה פעמים לשים את האמוג\'י?',
			  actions: [
			    { label: 'פעם אחת', action: '1' },
			    { label: 'פעמיים', action: '2' },
			    { label: 'שלוש פעמיים', action: '3' }
			  ],
			} ).closed.then( function ( data ) {
				  if ( data && data.action ) {
				    switch ( data.action ) {
				    	case "1":
				    		$('#wpTextbox1').textSelection('encapsulateSelection',{
								pre: "",
								peri: template,
								post: ""
							});
				    		break;
				    	case "2":
				    		$('#wpTextbox1').textSelection('encapsulateSelection',{
								pre: "",
								peri: template + " " + template,
								post: ""
							});
				    		break;
				    	case "3":
				    		$('#wpTextbox1').textSelection('encapsulateSelection',{
								pre: "",
								peri: template + " " + template + " " + template,
								post: ""
							});
				    		break;
				    }
				}
			});
		}
		if ((typeof $.wikiEditor != 'undefined') && ( mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit' )) {
			toolBarOptions = {
				'section': 'main',
				'group': 'insert',
				'tools': {}
			};
			toolBarOptions.tools['Emoji'] = {
				label: "Emoji",
				type: "button",
				icon: "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Emojione_263A.svg/24px-Emojione_263A.svg.png",
				action: 
					{type: "callback",
					execute: function() {
						var param1 = "";
						var param2 = "";
						new mw.Api().get({"action": "parse", "page": "תבנית:אמוג'י/גלריה"}).done(function(info) {
							var dialog = $("<div>").dialog({position: [$('body').width() * 0.05, $('body').height() * 0.05], width: 'auto', height: 'auto', title: "Emoji"}).html((info.parse.text["*"]));
							$("code").click(function($this){
								console.log($this);
								if (!$this.target.innerText.match(/\{\{/)) {
									if ($this.target.innerText.match(/סגנון/)) {
										param1 = $this.target.innerText;
									} else {
										param2 = $this.target.innerText;
									}
								} else {
									done($this.target.innerText.replace(/\}\}/, param1 + param2 + "}}"), dialog);
								}
							});
			            });
					}
				}
			};
			$('#wpTextbox1').wikiEditor('addToToolbar', toolBarOptions);
		}
	});
});