1.0.4 • Published 2 years ago

grapesjs-video-embed-manager v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Video Embed Manager

DEMO

HTML

<link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet">
<script src="https://unpkg.com/grapesjs"></script>
<script src="https://unpkg.com/grapesjs-video-embed-manager"></script>

<div id="gjs"></div>

JS

const editor = grapesjs.init({
	container: '#gjs',
  height: '100%',
  storageManager: false,
  plugins: ['grapesjs-video-embed-manager'],
});

Summary

  • Plugin name: grapesjs-video-embed-manager
  • A wrapper that turns the grapesjs video component into a dynamic experience, opening a modal similar to the GrapesJS Asset Manager. This plugin has been optimized to work with Youtube, Vimeo, and a local video server. No loading of components or blocks necessary.

Options

*See src/video_media_manager/config/config.js for detailed information about each option.

OptionDescriptionDefault
resourcesThe resources to query to get your videos. Valid options are youtube, vimeo, and local.[]
youtubeLoadUrlThe server url used to manage getting videos.null
youtubeLoadCallbackOnly for youtube since there are public videos. This is a custom callback that can be used to obtain the vidoes instead.null
youtubeBeforeLoadADVANCED: If you need to alter the data before it is loaded. This is best used if you have little control over how the data is returned.null
youtubeBeforeInsertADVANCED: If you want to alter the video data before it is inserted. This will probably only be used if you have a custom video component.null
youtubeDataThis is a pseudo option mainly used for demo purposes. Used to manage what videos are currently showing on page.null
youtubeHeadersAny headers that need to be passed in your request.{}
youtubeParamsAny parameters that need to be passed in your request.{}
vimeoLoadUrlSee youtube description. Same value used for Vimeo.null
vimeoBeforeLoadSee youtube description. Same value used for Vimeo.null
vimeoBeforeInsertSee youtube description. Same value used for Vimeo.null
vimeoDataSee youtube description. Same value used for Vimeo.null
vimeoHeadersSee youtube description. Same value used for Vimeo.{}
vimeoParamsSee youtube description. Same value used for Vimeo.{}
localLoadUrlSee youtube description. Same value used for your local videos.null
localBeforeLoadSee youtube description. Same value used for your local videos.null
localBeforeInsertSee youtube description. Same value used for your local videos.null
localDataSee youtube description. Same value used for your local videos.null
localHeadersSee youtube description. Same value used for your local videos.{}
localParamsSee youtube description. Same value used for your local videos.{}
preloaderimage src string used for the loading preloader. If not provided, the manager will just say "loading".null
per_pageThe amount of videos to show in manager view. Will be used in your server queries.12

Query Values for local development

OptionDescription
per_pageThis will tell your server how many videos to return.
pageThis will tell your server which page number you are requesting
page_tokenUsed only for youtube, but I suppose you could emulate their style and use page tokens instead of page numbers

What's with the Error Codes?

If the Video Manager errors due to improper setup or other factor, sometimes a message accompanied by an HTTP Status Code will appear. Technically, some of the errors are client side and not from a server, however, there aren't good status codes for client side (unless I am completely in the dark). Because of this, a somewhat descriptive HTTP Status Code will be used alongside the error so you can make an educated guess as to why something has happened.

Download

  • CDN
    • https://unpkg.com/grapesjs-video-embed-manager
  • NPM
    • npm i grapesjs-video-embed-manager
  • GIT
    • git clone https://github.com/booellean/grapesjs-video-embed-manager.git

Usage

Directly in the browser

<link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/grapesjs"></script>
<script src="path/to/grapesjs-video-embed-manager.min.js"></script>

<div id="gjs"></div>

<script type="text/javascript">
  var editor = grapesjs.init({
      container: '#gjs',
      // ...
      plugins: ['grapesjs-video-embed-manager'],
      pluginsOpts: {
        'grapesjs-video-embed-manager': { 
          preloader : 'https://gifimage.net/wp-content/uploads/2018/04/loading-icon-gif-6.gif',
          resources: [ 'youtube', 'vimeo', 'local' ],
          per_page: 5,
          youtubeLoadCallback: (data) => data,
          youtubeLoadUrl: '/fake/callback'
      }
  });
</script>

Modern javascript

import grapesjs from 'grapesjs';
import plugin from 'grapesjs-video-embed-manager';
import 'grapesjs/dist/css/grapes.min.css';

const editor = grapesjs.init({
  container : '#gjs',
  // ...
  plugins: [grapesjs-video-embed-manager],
  pluginsOpts: {
    'grapesjs-video-embed-manager': { /* options */ }
  }
  // or
  plugins: [
    editor => ['grapesjs-video-embed-manager'](editor, { /* options */ }),
  ],
});

Development

Clone the repository

$ git clone https://github.com/booellean/grapesjs-video-embed-manager.git
$ cd grapesjs-video-embed-manager

Install dependencies

$ npm i

Start the dev server

$ npm start

Build the source

$ npm run build

License

MIT

Important Note

This plugin adds to the dblclick event of the video component. This was decided by the dev so that the end user wouldn't have to load a custom component that is exactly the same as the video componenet, but with this one feature. It has been tested to not override any future dblcick events if the video component is ever updated.