Jump to content

MediaWiki:Gadget-EmojiVE.js: Difference between revisions

Cdjensen94
Cdjensen94 (talk | contribs) (Created page with "// MediaWiki:Gadget-EmojiVE.js — VisualEditor tool mw.loader.using(['ext.visualEditor.desktopArticleTarget.init']).then(async () => { // Load the picker module const { EmojiButton } = await import('https://cdn.jsdelivr.net/npm/@joeattardi/emoji-button@4.6.4/dist/index.js'); // Define a simple command that opens the picker and inserts the result function openEmojiPickerWithSurface(surface, anchorEl) { const picker = new EmojiButton({ showSearch: true, show...")
 
 
Line 1: Line 1:
// MediaWiki:Gadget-EmojiVE.js — VisualEditor tool
/* MediaWiki:Gadget-EmojiVE.js (ES5) */
mw.loader.using(['ext.visualEditor.desktopArticleTarget.init']).then(async () => {
mw.loader.using(['ext.visualEditor.desktopArticleTarget.init']).done(function () {
   // Load the picker module
   var EmojiButton = window.EmojiButton;
   const { EmojiButton } = await import('https://cdn.jsdelivr.net/npm/@joeattardi/emoji-button@4.6.4/dist/index.js');
   if (!EmojiButton) { mw.log.error('EmojiButton global missing (enable EmojiLib or include the UMD build)'); return; }


  // Define a simple command that opens the picker and inserts the result
   function openPicker(surface, anchor) {
   function openEmojiPickerWithSurface(surface, anchorEl) {
     var picker = new EmojiButton({ showSearch: true, showRecents: true });
     const picker = new EmojiButton({ showSearch: true, showRecents: true });
     picker.on('emoji', function (sel) {
     picker.on('emoji', sel => {
       var fragment = surface.getModel().getFragment();
       const dmDoc = surface.getModel().getDocument();
      const fragment = surface.getModel().getFragment();
       fragment.insertContent(sel.emoji);
       fragment.insertContent(sel.emoji);
       surface.getView().focus();
       surface.getView().focus();
     });
     });
     picker.togglePicker(anchorEl);
     picker.togglePicker(anchor);
   }
   }


  // Create a VE tool
   function registerTool() {
   function registerTool() {
     function EmojiTool() {
     function EmojiTool() { EmojiTool.super.apply(this, arguments); }
      EmojiTool.super.apply(this, arguments);
    }
     OO.inheritClass(EmojiTool, ve.ui.Tool);
     OO.inheritClass(EmojiTool, ve.ui.Tool);
     EmojiTool.static.name = 'emojiButton';
     EmojiTool.static.name = 'emojiButton';
     EmojiTool.static.group = 'insert';
     EmojiTool.static.group = 'insert';
     EmojiTool.static.icon = 'smiley'; // built-in OOUI icon
     EmojiTool.static.icon = 'smiley';
     EmojiTool.static.title = 'Insert emoji';
     EmojiTool.static.title = 'Insert emoji';


     EmojiTool.prototype.onSelect = function () {
     EmojiTool.prototype.onSelect = function () {
       const surface = this.toolbar.getSurface();
       var surface = this.toolbar.getSurface();
       const anchor = this.$element[0]; // button element as anchor
       openPicker(surface, this.$element[0]);
      openEmojiPickerWithSurface(surface, anchor);
       this.setActive(false);
       this.setActive(false);
     };
     };
Line 39: Line 34:
   }
   }


  // Wait until VE is ready on the page, then register
   mw.hook('ve.activationComplete').add(function () { registerTool(); });
   mw.hook('ve.activationComplete').add(() => registerTool());
});
});