[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/mediaelement/renderers/ -> vimeo.js (source)

   1  /*!
   2   * MediaElement.js
   3   * http://www.mediaelementjs.com/
   4   *
   5   * Wrapper that mimics native HTML5 MediaElement (audio and video)
   6   * using a variety of technologies (pure JavaScript, Flash, iframe)
   7   *
   8   * Copyright 2010-2017, John Dyer (http://j.hn/)
   9   * License: MIT
  10   *
  11   */(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  12  'use strict';
  13  
  14  var VimeoApi = {
  15  
  16      promise: null,
  17  
  18      load: function load(settings) {
  19  
  20          if (typeof Vimeo !== 'undefined') {
  21              VimeoApi._createPlayer(settings);
  22          } else {
  23              VimeoApi.promise = VimeoApi.promise || mejs.Utils.loadScript('https://player.vimeo.com/api/player.js');
  24              VimeoApi.promise.then(function () {
  25                  VimeoApi._createPlayer(settings);
  26              });
  27          }
  28      },
  29  
  30      _createPlayer: function _createPlayer(settings) {
  31          var player = new Vimeo.Player(settings.iframe);
  32          window['__ready__' + settings.id](player);
  33      },
  34  
  35      getVimeoId: function getVimeoId(url) {
  36          if (url === undefined || url === null) {
  37              return null;
  38          }
  39  
  40          var parts = url.split('?');
  41          url = parts[0];
  42          return parseInt(url.substring(url.lastIndexOf('/') + 1), 10);
  43      }
  44  };
  45  
  46  var vimeoIframeRenderer = {
  47  
  48      name: 'vimeo_iframe',
  49      options: {
  50          prefix: 'vimeo_iframe'
  51      },
  52  
  53      canPlayType: function canPlayType(type) {
  54          return ~['video/vimeo', 'video/x-vimeo'].indexOf(type.toLowerCase());
  55      },
  56  
  57      create: function create(mediaElement, options, mediaFiles) {
  58          var apiStack = [],
  59              vimeo = {},
  60              readyState = 4;
  61  
  62          var paused = true,
  63              volume = 1,
  64              oldVolume = volume,
  65              currentTime = 0,
  66              bufferedTime = 0,
  67              ended = false,
  68              duration = 0,
  69              vimeoPlayer = null,
  70              url = '';
  71  
  72          vimeo.options = options;
  73          vimeo.id = mediaElement.id + '_' + options.prefix;
  74          vimeo.mediaElement = mediaElement;
  75  
  76          var errorHandler = function errorHandler(error, target) {
  77              var event = mejs.Utils.createEvent('error', target);
  78              event.message = error.name + ': ' + error.message;
  79              mediaElement.dispatchEvent(event);
  80          };
  81  
  82          var props = mejs.html5media.properties,
  83              assignGettersSetters = function assignGettersSetters(propName) {
  84  
  85              var capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1);
  86  
  87              vimeo['get' + capName] = function () {
  88                  if (vimeoPlayer !== null) {
  89                      var value = null;
  90  
  91                      switch (propName) {
  92                          case 'currentTime':
  93                              return currentTime;
  94  
  95                          case 'duration':
  96                              return duration;
  97  
  98                          case 'volume':
  99                              return volume;
 100                          case 'muted':
 101                              return volume === 0;
 102                          case 'paused':
 103                              return paused;
 104                          case 'ended':
 105                              return ended;
 106  
 107                          case 'src':
 108                              vimeoPlayer.getVideoUrl().then(function (_url) {
 109                                  url = _url;
 110                              });
 111  
 112                              return url;
 113                          case 'buffered':
 114                              return {
 115                                  start: function start() {
 116                                      return 0;
 117                                  },
 118                                  end: function end() {
 119                                      return bufferedTime * duration;
 120                                  },
 121                                  length: 1
 122                              };
 123                          case 'readyState':
 124                              return readyState;
 125                      }
 126                      return value;
 127                  } else {
 128                      return null;
 129                  }
 130              };
 131  
 132              vimeo['set' + capName] = function (value) {
 133                  if (vimeoPlayer !== null) {
 134                      switch (propName) {
 135                          case 'src':
 136                              var _url2 = typeof value === 'string' ? value : value[0].src,
 137                                  videoId = VimeoApi.getVimeoId(_url2);
 138  
 139                              vimeoPlayer.loadVideo(videoId).then(function () {
 140                                  if (mediaElement.originalNode.autoplay) {
 141                                      vimeoPlayer.play();
 142                                  }
 143                              }).catch(function (error) {
 144                                  errorHandler(error, vimeo);
 145                              });
 146                              break;
 147                          case 'currentTime':
 148                              vimeoPlayer.setCurrentTime(value).then(function () {
 149                                  currentTime = value;
 150                                  setTimeout(function () {
 151                                      var event = mejs.Utils.createEvent('timeupdate', vimeo);
 152                                      mediaElement.dispatchEvent(event);
 153                                  }, 50);
 154                              }).catch(function (error) {
 155                                  errorHandler(error, vimeo);
 156                              });
 157                              break;
 158                          case 'volume':
 159                              vimeoPlayer.setVolume(value).then(function () {
 160                                  volume = value;
 161                                  oldVolume = volume;
 162                                  setTimeout(function () {
 163                                      var event = mejs.Utils.createEvent('volumechange', vimeo);
 164                                      mediaElement.dispatchEvent(event);
 165                                  }, 50);
 166                              }).catch(function (error) {
 167                                  errorHandler(error, vimeo);
 168                              });
 169                              break;
 170                          case 'loop':
 171                              vimeoPlayer.setLoop(value).catch(function (error) {
 172                                  errorHandler(error, vimeo);
 173                              });
 174                              break;
 175                          case 'muted':
 176                              if (value) {
 177                                  vimeoPlayer.setVolume(0).then(function () {
 178                                      volume = 0;
 179                                      setTimeout(function () {
 180                                          var event = mejs.Utils.createEvent('volumechange', vimeo);
 181                                          mediaElement.dispatchEvent(event);
 182                                      }, 50);
 183                                  }).catch(function (error) {
 184                                      errorHandler(error, vimeo);
 185                                  });
 186                              } else {
 187                                  vimeoPlayer.setVolume(oldVolume).then(function () {
 188                                      volume = oldVolume;
 189                                      setTimeout(function () {
 190                                          var event = mejs.Utils.createEvent('volumechange', vimeo);
 191                                          mediaElement.dispatchEvent(event);
 192                                      }, 50);
 193                                  }).catch(function (error) {
 194                                      errorHandler(error, vimeo);
 195                                  });
 196                              }
 197                              break;
 198                          case 'readyState':
 199                              var event = mejs.Utils.createEvent('canplay', vimeo);
 200                              mediaElement.dispatchEvent(event);
 201                              break;
 202                          default:
 203                              
 204                              break;
 205                      }
 206                  } else {
 207                      apiStack.push({ type: 'set', propName: propName, value: value });
 208                  }
 209              };
 210          };
 211  
 212          for (var i = 0, total = props.length; i < total; i++) {
 213              assignGettersSetters(props[i]);
 214          }
 215  
 216          var methods = mejs.html5media.methods,
 217              assignMethods = function assignMethods(methodName) {
 218              vimeo[methodName] = function () {
 219                  if (vimeoPlayer !== null) {
 220                      switch (methodName) {
 221                          case 'play':
 222                              paused = false;
 223                              return vimeoPlayer.play();
 224                          case 'pause':
 225                              paused = true;
 226                              return vimeoPlayer.pause();
 227                          case 'load':
 228                              return null;
 229                      }
 230                  } else {
 231                      apiStack.push({ type: 'call', methodName: methodName });
 232                  }
 233              };
 234          };
 235  
 236          for (var _i = 0, _total = methods.length; _i < _total; _i++) {
 237              assignMethods(methods[_i]);
 238          }
 239  
 240          window['__ready__' + vimeo.id] = function (_vimeoPlayer) {
 241  
 242              mediaElement.vimeoPlayer = vimeoPlayer = _vimeoPlayer;
 243  
 244              if (apiStack.length) {
 245                  for (var _i2 = 0, _total2 = apiStack.length; _i2 < _total2; _i2++) {
 246                      var stackItem = apiStack[_i2];
 247  
 248                      if (stackItem.type === 'set') {
 249                          var propName = stackItem.propName,
 250                              capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1);
 251  
 252                          vimeo['set' + capName](stackItem.value);
 253                      } else if (stackItem.type === 'call') {
 254                          vimeo[stackItem.methodName]();
 255                      }
 256                  }
 257              }
 258  
 259              if (mediaElement.originalNode.muted) {
 260                  vimeoPlayer.setVolume(0);
 261                  volume = 0;
 262              }
 263  
 264              var vimeoIframe = document.getElementById(vimeo.id);
 265              var events = void 0;
 266  
 267              events = ['mouseover', 'mouseout'];
 268  
 269              var assignEvents = function assignEvents(e) {
 270                  var event = mejs.Utils.createEvent(e.type, vimeo);
 271                  mediaElement.dispatchEvent(event);
 272              };
 273  
 274              for (var _i3 = 0, _total3 = events.length; _i3 < _total3; _i3++) {
 275                  vimeoIframe.addEventListener(events[_i3], assignEvents, false);
 276              }
 277  
 278              vimeoPlayer.on('loaded', function () {
 279                  vimeoPlayer.getDuration().then(function (loadProgress) {
 280                      duration = loadProgress;
 281                      if (duration > 0) {
 282                          bufferedTime = duration * loadProgress;
 283                          if (mediaElement.originalNode.autoplay) {
 284                              paused = false;
 285                              ended = false;
 286                              var event = mejs.Utils.createEvent('play', vimeo);
 287                              mediaElement.dispatchEvent(event);
 288                          }
 289                      }
 290                  }).catch(function (error) {
 291                      errorHandler(error, vimeo);
 292                  });
 293              });
 294              vimeoPlayer.on('progress', function () {
 295                  vimeoPlayer.getDuration().then(function (loadProgress) {
 296                      duration = loadProgress;
 297  
 298                      if (duration > 0) {
 299                          bufferedTime = duration * loadProgress;
 300                          if (mediaElement.originalNode.autoplay) {
 301                              var initEvent = mejs.Utils.createEvent('play', vimeo);
 302                              mediaElement.dispatchEvent(initEvent);
 303  
 304                              var playingEvent = mejs.Utils.createEvent('playing', vimeo);
 305                              mediaElement.dispatchEvent(playingEvent);
 306                          }
 307                      }
 308  
 309                      var event = mejs.Utils.createEvent('progress', vimeo);
 310                      mediaElement.dispatchEvent(event);
 311                  }).catch(function (error) {
 312                      errorHandler(error, vimeo);
 313                  });
 314              });
 315              vimeoPlayer.on('timeupdate', function () {
 316                  vimeoPlayer.getCurrentTime().then(function (seconds) {
 317                      currentTime = seconds;
 318  
 319                      var event = mejs.Utils.createEvent('timeupdate', vimeo);
 320                      mediaElement.dispatchEvent(event);
 321                  }).catch(function (error) {
 322                      errorHandler(error, vimeo);
 323                  });
 324              });
 325              vimeoPlayer.on('play', function () {
 326                  paused = false;
 327                  ended = false;
 328                  var event = mejs.Utils.createEvent('play', vimeo);
 329                  mediaElement.dispatchEvent(event);
 330  
 331                  var playingEvent = mejs.Utils.createEvent('playing', vimeo);
 332                  mediaElement.dispatchEvent(playingEvent);
 333              });
 334              vimeoPlayer.on('pause', function () {
 335                  paused = true;
 336                  ended = false;
 337  
 338                  var event = mejs.Utils.createEvent('pause', vimeo);
 339                  mediaElement.dispatchEvent(event);
 340              });
 341              vimeoPlayer.on('ended', function () {
 342                  paused = false;
 343                  ended = true;
 344  
 345                  var event = mejs.Utils.createEvent('ended', vimeo);
 346                  mediaElement.dispatchEvent(event);
 347              });
 348  
 349              events = ['rendererready', 'loadedmetadata', 'loadeddata', 'canplay'];
 350  
 351              for (var _i4 = 0, _total4 = events.length; _i4 < _total4; _i4++) {
 352                  var event = mejs.Utils.createEvent(events[_i4], vimeo);
 353                  mediaElement.dispatchEvent(event);
 354              }
 355          };
 356  
 357          var height = mediaElement.originalNode.height,
 358              width = mediaElement.originalNode.width,
 359              vimeoContainer = document.createElement('iframe'),
 360              standardUrl = 'https://player.vimeo.com/video/' + VimeoApi.getVimeoId(mediaFiles[0].src);
 361  
 362          var queryArgs = ~mediaFiles[0].src.indexOf('?') ? '?' + mediaFiles[0].src.slice(mediaFiles[0].src.indexOf('?') + 1) : '';
 363          if (queryArgs && mediaElement.originalNode.autoplay && queryArgs.indexOf('autoplay') === -1) {
 364              queryArgs += '&autoplay=1';
 365          }
 366          if (queryArgs && mediaElement.originalNode.loop && queryArgs.indexOf('loop') === -1) {
 367              queryArgs += '&loop=1';
 368          }
 369  
 370          vimeoContainer.setAttribute('id', vimeo.id);
 371          vimeoContainer.setAttribute('width', width);
 372          vimeoContainer.setAttribute('height', height);
 373          vimeoContainer.setAttribute('frameBorder', '0');
 374          vimeoContainer.setAttribute('src', '' + standardUrl + queryArgs);
 375          vimeoContainer.setAttribute('webkitallowfullscreen', '');
 376          vimeoContainer.setAttribute('mozallowfullscreen', '');
 377          vimeoContainer.setAttribute('allowfullscreen', '');
 378  
 379          mediaElement.originalNode.parentNode.insertBefore(vimeoContainer, mediaElement.originalNode);
 380          mediaElement.originalNode.style.display = 'none';
 381  
 382          VimeoApi.load({
 383              iframe: vimeoContainer,
 384              id: vimeo.id
 385          });
 386  
 387          vimeo.hide = function () {
 388              vimeo.pause();
 389              if (vimeoPlayer) {
 390                  vimeoContainer.style.display = 'none';
 391              }
 392          };
 393          vimeo.setSize = function (width, height) {
 394              vimeoContainer.setAttribute('width', width);
 395              vimeoContainer.setAttribute('height', height);
 396          };
 397          vimeo.show = function () {
 398              if (vimeoPlayer) {
 399                  vimeoContainer.style.display = '';
 400              }
 401          };
 402  
 403          vimeo.destroy = function () {};
 404  
 405          return vimeo;
 406      }
 407  };
 408  
 409  mejs.Utils.typeChecks.push(function (url) {
 410      return (/(\/\/player\.vimeo|vimeo\.com)/i.test(url) ? 'video/x-vimeo' : null
 411      );
 412  });
 413  
 414  mejs.Renderers.add(vimeoIframeRenderer);
 415  
 416  },{}]},{},[1]);


Generated: Wed Jul 24 01:00:02 2019 Cross-referenced by PHPXref 0.7.1