Topic on Extension talk:EmbedVideo

Add "Embed Video" icon to WikiEditor toolbar

3
Felix Englisch (talkcontribs)

If you are using EmbedVideo in combination with Extension:WikiEditor, you might want to make it easier for your users to insert a video. It is quite easy to add an icon to the toolbar which automatically inserts the code snippet required for embedding. Simply add the following to you LocalSettings.php:

$wgUseSiteJs = true;


Then, open the page "MediaWiki:Common.js" on your wiki and insert the following:

var customizeToolbar = function () {
  $('#wpTextbox1').wikiEditor('addToToolbar', {
      section: 'advanced',
      group: 'insert',
      tools: {
        "Video": {
          label: 'Embed video',
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/6/64/Video_Camera_-_The_Noun_Project.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{#ev:youtube|',
              peri: "Link to YouTube video",
              post: '|400|right|Caption}}'
            }
          }
        }
      }
    });
};
    
    /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
    if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    mw.loader.using( 'user.options' ).then( function () {
    if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
      $.when(
        mw.loader.using( 'ext.wikiEditor' ), $.ready
      ).then( customizeToolbar );
    }
  } );
}


Of course, you can change the default parameters of the video and also the icon. Just visit https://commons.wikimedia.org/wiki/Main_Page and look for a better one. And for more information about editing the toolbar, see Extension:WikiEditor/Toolbar customization.

Have fun!


Uncopy (talkcontribs)

Thanks Felix for updating you code, I removed my copy.

Felix Englisch (talkcontribs)

Thank you, User:Uncopy, that helped a lot! Due to your reply I also found some mistakes in my code (which are still in yours, I am sorry), so this was more than helpful.

Reply to "Add "Embed Video" icon to WikiEditor toolbar"