[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({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) {
  77              mediaElement.generateError('Code ' + error.name + ': ' + error.message, mediaFiles);
  78          };
  79  
  80          var props = mejs.html5media.properties,
  81              assignGettersSetters = function assignGettersSetters(propName) {
  82  
  83              var capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1);
  84  
  85              vimeo['get' + capName] = function () {
  86                  if (vimeoPlayer !== null) {
  87                      var value = null;
  88  
  89                      switch (propName) {
  90                          case 'currentTime':
  91                              return currentTime;
  92                          case 'duration':
  93                              return duration;
  94                          case 'volume':
  95                              return volume;
  96                          case 'muted':
  97                              return volume === 0;
  98                          case 'paused':
  99                              return paused;
 100                          case 'ended':
 101                              return ended;
 102                          case 'src':
 103                              vimeoPlayer.getVideoUrl().then(function (_url) {
 104                                  url = _url;
 105                              }).catch(function (error) {
 106                                  return errorHandler(error);
 107                              });
 108                              return url;
 109                          case 'buffered':
 110                              return {
 111                                  start: function start() {
 112                                      return 0;
 113                                  },
 114                                  end: function end() {
 115                                      return bufferedTime * duration;
 116                                  },
 117                                  length: 1
 118                              };
 119                          case 'readyState':
 120                              return readyState;
 121                      }
 122                      return value;
 123                  } else {
 124                      return null;
 125                  }
 126              };
 127  
 128              vimeo['set' + capName] = function (value) {
 129                  if (vimeoPlayer !== null) {
 130                      switch (propName) {
 131                          case 'src':
 132                              var _url2 = typeof value === 'string' ? value : value[0].src,
 133                                  videoId = VimeoApi.getVimeoId(_url2);
 134  
 135                              vimeoPlayer.loadVideo(videoId).then(function () {
 136                                  if (mediaElement.originalNode.autoplay) {
 137                                      vimeoPlayer.play();
 138                                  }
 139                              }).catch(function (error) {
 140                                  return errorHandler(error);
 141                              });
 142                              break;
 143                          case 'currentTime':
 144                              vimeoPlayer.setCurrentTime(value).then(function () {
 145                                  currentTime = value;
 146                                  setTimeout(function () {
 147                                      var event = mejs.Utils.createEvent('timeupdate', vimeo);
 148                                      mediaElement.dispatchEvent(event);
 149                                  }, 50);
 150                              }).catch(function (error) {
 151                                  return errorHandler(error);
 152                              });
 153                              break;
 154                          case 'volume':
 155                              vimeoPlayer.setVolume(value).then(function () {
 156                                  volume = value;
 157                                  oldVolume = volume;
 158                                  setTimeout(function () {
 159                                      var event = mejs.Utils.createEvent('volumechange', vimeo);
 160                                      mediaElement.dispatchEvent(event);
 161                                  }, 50);
 162                              }).catch(function (error) {
 163                                  return errorHandler(error);
 164                              });
 165                              break;
 166                          case 'loop':
 167                              vimeoPlayer.setLoop(value).catch(function (error) {
 168                                  return errorHandler(error);
 169                              });
 170                              break;
 171                          case 'muted':
 172                              if (value) {
 173                                  vimeoPlayer.setVolume(0).then(function () {
 174                                      volume = 0;
 175                                      setTimeout(function () {
 176                                          var event = mejs.Utils.createEvent('volumechange', vimeo);
 177                                          mediaElement.dispatchEvent(event);
 178                                      }, 50);
 179                                  }).catch(function (error) {
 180                                      return errorHandler(error);
 181                                  });
 182                              } else {
 183                                  vimeoPlayer.setVolume(oldVolume).then(function () {
 184                                      volume = oldVolume;
 185                                      setTimeout(function () {
 186                                          var event = mejs.Utils.createEvent('volumechange', vimeo);
 187                                          mediaElement.dispatchEvent(event);
 188                                      }, 50);
 189                                  }).catch(function (error) {
 190                                      return errorHandler(error);
 191                                  });
 192                              }
 193                              break;
 194                          case 'readyState':
 195                              var event = mejs.Utils.createEvent('canplay', vimeo);
 196                              mediaElement.dispatchEvent(event);
 197                              break;
 198                          default:
 199                              
 200                              break;
 201                      }
 202                  } else {
 203                      apiStack.push({ type: 'set', propName: propName, value: value });
 204                  }
 205              };
 206          };
 207  
 208          for (var i = 0, total = props.length; i < total; i++) {
 209              assignGettersSetters(props[i]);
 210          }
 211  
 212          var methods = mejs.html5media.methods,
 213              assignMethods = function assignMethods(methodName) {
 214              vimeo[methodName] = function () {
 215                  if (vimeoPlayer !== null) {
 216                      switch (methodName) {
 217                          case 'play':
 218                              paused = false;
 219                              return vimeoPlayer.play();
 220                          case 'pause':
 221                              paused = true;
 222                              return vimeoPlayer.pause();
 223                          case 'load':
 224                              return null;
 225                      }
 226                  } else {
 227                      apiStack.push({ type: 'call', methodName: methodName });
 228                  }
 229              };
 230          };
 231  
 232          for (var _i = 0, _total = methods.length; _i < _total; _i++) {
 233              assignMethods(methods[_i]);
 234          }
 235  
 236          window['__ready__' + vimeo.id] = function (_vimeoPlayer) {
 237  
 238              mediaElement.vimeoPlayer = vimeoPlayer = _vimeoPlayer;
 239  
 240              if (apiStack.length) {
 241                  for (var _i2 = 0, _total2 = apiStack.length; _i2 < _total2; _i2++) {
 242                      var stackItem = apiStack[_i2];
 243  
 244                      if (stackItem.type === 'set') {
 245                          var propName = stackItem.propName,
 246                              capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1);
 247  
 248                          vimeo['set' + capName](stackItem.value);
 249                      } else if (stackItem.type === 'call') {
 250                          vimeo[stackItem.methodName]();
 251                      }
 252                  }
 253              }
 254  
 255              if (mediaElement.originalNode.muted) {
 256                  vimeoPlayer.setVolume(0);
 257                  volume = 0;
 258              }
 259  
 260              var vimeoIframe = document.getElementById(vimeo.id);
 261              var events = void 0;
 262  
 263              events = ['mouseover', 'mouseout'];
 264  
 265              var assignEvents = function assignEvents(e) {
 266                  var event = mejs.Utils.createEvent(e.type, vimeo);
 267                  mediaElement.dispatchEvent(event);
 268              };
 269  
 270              for (var _i3 = 0, _total3 = events.length; _i3 < _total3; _i3++) {
 271                  vimeoIframe.addEventListener(events[_i3], assignEvents, false);
 272              }
 273  
 274              vimeoPlayer.on('loaded', function () {
 275                  vimeoPlayer.getDuration().then(function (loadProgress) {
 276                      duration = loadProgress;
 277                      if (duration > 0) {
 278                          bufferedTime = duration * loadProgress;
 279                          if (mediaElement.originalNode.autoplay) {
 280                              paused = false;
 281                              ended = false;
 282                              var event = mejs.Utils.createEvent('play', vimeo);
 283                              mediaElement.dispatchEvent(event);
 284                          }
 285                      }
 286                  }).catch(function (error) {
 287                      errorHandler(error, vimeo);
 288                  });
 289              });
 290              vimeoPlayer.on('progress', function () {
 291                  vimeoPlayer.getDuration().then(function (loadProgress) {
 292                      duration = loadProgress;
 293  
 294                      if (duration > 0) {
 295                          bufferedTime = duration * loadProgress;
 296                          if (mediaElement.originalNode.autoplay) {
 297                              var initEvent = mejs.Utils.createEvent('play', vimeo);
 298                              mediaElement.dispatchEvent(initEvent);
 299  
 300                              var playingEvent = mejs.Utils.createEvent('playing', vimeo);
 301                              mediaElement.dispatchEvent(playingEvent);
 302                          }
 303                      }
 304  
 305                      var event = mejs.Utils.createEvent('progress', vimeo);
 306                      mediaElement.dispatchEvent(event);
 307                  }).catch(function (error) {
 308                      return errorHandler(error);
 309                  });
 310              });
 311              vimeoPlayer.on('timeupdate', function () {
 312                  vimeoPlayer.getCurrentTime().then(function (seconds) {
 313                      currentTime = seconds;
 314                      var event = mejs.Utils.createEvent('timeupdate', vimeo);
 315                      mediaElement.dispatchEvent(event);
 316                  }).catch(function (error) {
 317                      return errorHandler(error);
 318                  });
 319              });
 320              vimeoPlayer.on('play', function () {
 321                  paused = false;
 322                  ended = false;
 323                  var event = mejs.Utils.createEvent('play', vimeo);
 324                  mediaElement.dispatchEvent(event);
 325  
 326                  var playingEvent = mejs.Utils.createEvent('playing', vimeo);
 327                  mediaElement.dispatchEvent(playingEvent);
 328              });
 329              vimeoPlayer.on('pause', function () {
 330                  paused = true;
 331                  ended = false;
 332  
 333                  var event = mejs.Utils.createEvent('pause', vimeo);
 334                  mediaElement.dispatchEvent(event);
 335              });
 336              vimeoPlayer.on('ended', function () {
 337                  paused = false;
 338                  ended = true;
 339  
 340                  var event = mejs.Utils.createEvent('ended', vimeo);
 341                  mediaElement.dispatchEvent(event);
 342              });
 343  
 344              events = ['rendererready', 'loadedmetadata', 'loadeddata', 'canplay'];
 345  
 346              for (var _i4 = 0, _total4 = events.length; _i4 < _total4; _i4++) {
 347                  var event = mejs.Utils.createEvent(events[_i4], vimeo);
 348                  mediaElement.dispatchEvent(event);
 349              }
 350          };
 351  
 352          var height = mediaElement.originalNode.height,
 353              width = mediaElement.originalNode.width,
 354              vimeoContainer = document.createElement('iframe'),
 355              standardUrl = 'https://player.vimeo.com/video/' + VimeoApi.getVimeoId(mediaFiles[0].src);
 356  
 357          var queryArgs = ~mediaFiles[0].src.indexOf('?') ? '?' + mediaFiles[0].src.slice(mediaFiles[0].src.indexOf('?') + 1) : '';
 358          var args = [];
 359  
 360          if (mediaElement.originalNode.autoplay && queryArgs.indexOf('autoplay') === -1) {
 361              args.push('autoplay=1');
 362          }
 363          if (mediaElement.originalNode.loop && queryArgs.indexOf('loop') === -1) {
 364              args.push('loop=1');
 365          }
 366  
 367          queryArgs = '' + queryArgs + (queryArgs ? '&' : '?') + args.join('&');
 368  
 369          vimeoContainer.setAttribute('id', vimeo.id);
 370          vimeoContainer.setAttribute('width', width);
 371          vimeoContainer.setAttribute('height', height);
 372          vimeoContainer.setAttribute('frameBorder', '0');
 373          vimeoContainer.setAttribute('src', '' + standardUrl + queryArgs);
 374          vimeoContainer.setAttribute('webkitallowfullscreen', 'true');
 375          vimeoContainer.setAttribute('mozallowfullscreen', 'true');
 376          vimeoContainer.setAttribute('allowfullscreen', 'true');
 377          vimeoContainer.setAttribute('allow', 'autoplay');
 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: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7