[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/ -> media-audiovideo.js (source)

   1  /******/ (function(modules) { // webpackBootstrap
   2  /******/     // The module cache
   3  /******/     var installedModules = {};
   4  /******/
   5  /******/     // The require function
   6  /******/ 	function __webpack_require__(moduleId) {
   7  /******/
   8  /******/         // Check if module is in cache
   9  /******/         if(installedModules[moduleId]) {
  10  /******/             return installedModules[moduleId].exports;
  11  /******/         }
  12  /******/         // Create a new module (and put it into the cache)
  13  /******/         var module = installedModules[moduleId] = {
  14  /******/             i: moduleId,
  15  /******/             l: false,
  16  /******/             exports: {}
  17  /******/         };
  18  /******/
  19  /******/         // Execute the module function
  20  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21  /******/
  22  /******/         // Flag the module as loaded
  23  /******/         module.l = true;
  24  /******/
  25  /******/         // Return the exports of the module
  26  /******/         return module.exports;
  27  /******/     }
  28  /******/
  29  /******/
  30  /******/     // expose the modules object (__webpack_modules__)
  31  /******/     __webpack_require__.m = modules;
  32  /******/
  33  /******/     // expose the module cache
  34  /******/     __webpack_require__.c = installedModules;
  35  /******/
  36  /******/     // define getter function for harmony exports
  37  /******/     __webpack_require__.d = function(exports, name, getter) {
  38  /******/         if(!__webpack_require__.o(exports, name)) {
  39  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  40  /******/         }
  41  /******/     };
  42  /******/
  43  /******/     // define __esModule on exports
  44  /******/     __webpack_require__.r = function(exports) {
  45  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  46  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  47  /******/         }
  48  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  49  /******/     };
  50  /******/
  51  /******/     // create a fake namespace object
  52  /******/     // mode & 1: value is a module id, require it
  53  /******/     // mode & 2: merge all properties of value into the ns
  54  /******/     // mode & 4: return value when already ns object
  55  /******/     // mode & 8|1: behave like require
  56  /******/     __webpack_require__.t = function(value, mode) {
  57  /******/         if(mode & 1) value = __webpack_require__(value);
  58  /******/         if(mode & 8) return value;
  59  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  60  /******/         var ns = Object.create(null);
  61  /******/         __webpack_require__.r(ns);
  62  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  63  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  64  /******/         return ns;
  65  /******/     };
  66  /******/
  67  /******/     // getDefaultExport function for compatibility with non-harmony modules
  68  /******/     __webpack_require__.n = function(module) {
  69  /******/         var getter = module && module.__esModule ?
  70  /******/ 			function getDefault() { return module['default']; } :
  71  /******/ 			function getModuleExports() { return module; };
  72  /******/         __webpack_require__.d(getter, 'a', getter);
  73  /******/         return getter;
  74  /******/     };
  75  /******/
  76  /******/     // Object.prototype.hasOwnProperty.call
  77  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  78  /******/
  79  /******/     // __webpack_public_path__
  80  /******/     __webpack_require__.p = "";
  81  /******/
  82  /******/
  83  /******/     // Load entry module and return exports
  84  /******/     return __webpack_require__(__webpack_require__.s = 0);
  85  /******/ })
  86  /************************************************************************/
  87  /******/ ([
  88  /* 0 */
  89  /***/ (function(module, exports, __webpack_require__) {
  90  
  91  module.exports = __webpack_require__(1);
  92  
  93  
  94  /***/ }),
  95  /* 1 */
  96  /***/ (function(module, exports, __webpack_require__) {
  97  
  98  /**
  99   * @output wp-includes/js/media-audiovideo.js
 100   */
 101  
 102  var media = wp.media,
 103      baseSettings = window._wpmejsSettings || {},
 104      l10n = window._wpMediaViewsL10n || {};
 105  
 106  /**
 107   *
 108   * Defines the wp.media.mixin object.
 109   *
 110   * @mixin
 111   *
 112   * @since 4.2.0
 113   */
 114  wp.media.mixin = {
 115      mejsSettings: baseSettings,
 116  
 117      /**
 118       * Pauses and removes all players.
 119       *
 120       * @since 4.2.0
 121       *
 122       * @return {void}
 123       */
 124      removeAllPlayers: function() {
 125          var p;
 126  
 127          if ( window.mejs && window.mejs.players ) {
 128              for ( p in window.mejs.players ) {
 129                  window.mejs.players[p].pause();
 130                  this.removePlayer( window.mejs.players[p] );
 131              }
 132          }
 133      },
 134  
 135      /**
 136       * Removes the player.
 137       *
 138       * Override the MediaElement method for removing a player.
 139       * MediaElement tries to pull the audio/video tag out of
 140       * its container and re-add it to the DOM.
 141       *
 142       * @since 4.2.0
 143       *
 144       * @return {void}
 145       */
 146      removePlayer: function(t) {
 147          var featureIndex, feature;
 148  
 149          if ( ! t.options ) {
 150              return;
 151          }
 152  
 153          // invoke features cleanup
 154          for ( featureIndex in t.options.features ) {
 155              feature = t.options.features[featureIndex];
 156              if ( t['clean' + feature] ) {
 157                  try {
 158                      t['clean' + feature](t);
 159                  } catch (e) {}
 160              }
 161          }
 162  
 163          if ( ! t.isDynamic ) {
 164              t.node.remove();
 165          }
 166  
 167          if ( 'html5' !== t.media.rendererName ) {
 168              t.media.remove();
 169          }
 170  
 171          delete window.mejs.players[t.id];
 172  
 173          t.container.remove();
 174          t.globalUnbind('resize', t.globalResizeCallback);
 175          t.globalUnbind('keydown', t.globalKeydownCallback);
 176          t.globalUnbind('click', t.globalClickCallback);
 177          delete t.media.player;
 178      },
 179  
 180      /**
 181       *
 182       * Removes and resets all players.
 183       *
 184       * Allows any class that has set 'player' to a MediaElementPlayer
 185       * instance to remove the player when listening to events.
 186       *
 187       * Examples: modal closes, shortcode properties are removed, etc.
 188       *
 189       * @since 4.2.0
 190       */
 191      unsetPlayers : function() {
 192          if ( this.players && this.players.length ) {
 193              _.each( this.players, function (player) {
 194                  player.pause();
 195                  wp.media.mixin.removePlayer( player );
 196              } );
 197              this.players = [];
 198          }
 199      }
 200  };
 201  
 202  /**
 203   * Shortcode modeling for playlists.
 204   *
 205   * @since 4.2.0
 206   */
 207  wp.media.playlist = new wp.media.collection({
 208      tag: 'playlist',
 209      editTitle : l10n.editPlaylistTitle,
 210      defaults : {
 211          id: wp.media.view.settings.post.id,
 212          style: 'light',
 213          tracklist: true,
 214          tracknumbers: true,
 215          images: true,
 216          artists: true,
 217          type: 'audio'
 218      }
 219  });
 220  
 221  /**
 222   * Shortcode modeling for audio.
 223   *
 224   * `edit()` prepares the shortcode for the media modal.
 225   * `shortcode()` builds the new shortcode after an update.
 226   *
 227   * @namespace
 228   *
 229   * @since 4.2.0
 230   */
 231  wp.media.audio = {
 232      coerce : wp.media.coerce,
 233  
 234      defaults : {
 235          id : wp.media.view.settings.post.id,
 236          src : '',
 237          loop : false,
 238          autoplay : false,
 239          preload : 'none',
 240          width : 400
 241      },
 242  
 243      /**
 244       * Instantiates a new media object with the next matching shortcode.
 245       *
 246       * @since 4.2.0
 247       *
 248       * @param {string} data The text to apply the shortcode on.
 249       * @returns {wp.media} The media object.
 250       */
 251      edit : function( data ) {
 252          var frame, shortcode = wp.shortcode.next( 'audio', data ).shortcode;
 253  
 254          frame = wp.media({
 255              frame: 'audio',
 256              state: 'audio-details',
 257              metadata: _.defaults( shortcode.attrs.named, this.defaults )
 258          });
 259  
 260          return frame;
 261      },
 262  
 263      /**
 264       * Generates an audio shortcode.
 265       *
 266       * @since 4.2.0
 267       *
 268       * @param {Array} model Array with attributes for the shortcode.
 269       * @returns {wp.shortcode} The audio shortcode object.
 270       */
 271      shortcode : function( model ) {
 272          var content;
 273  
 274          _.each( this.defaults, function( value, key ) {
 275              model[ key ] = this.coerce( model, key );
 276  
 277              if ( value === model[ key ] ) {
 278                  delete model[ key ];
 279              }
 280          }, this );
 281  
 282          content = model.content;
 283          delete model.content;
 284  
 285          return new wp.shortcode({
 286              tag: 'audio',
 287              attrs: model,
 288              content: content
 289          });
 290      }
 291  };
 292  
 293  /**
 294   * Shortcode modeling for video.
 295   *
 296   *  `edit()` prepares the shortcode for the media modal.
 297   *  `shortcode()` builds the new shortcode after update.
 298   *
 299   * @since 4.2.0
 300   *
 301   * @namespace
 302   */
 303  wp.media.video = {
 304      coerce : wp.media.coerce,
 305  
 306      defaults : {
 307          id : wp.media.view.settings.post.id,
 308          src : '',
 309          poster : '',
 310          loop : false,
 311          autoplay : false,
 312          preload : 'metadata',
 313          content : '',
 314          width : 640,
 315          height : 360
 316      },
 317  
 318      /**
 319       * Instantiates a new media object with the next matching shortcode.
 320       *
 321       * @since 4.2.0
 322       *
 323       * @param {string} data The text to apply the shortcode on.
 324       * @returns {wp.media} The media object.
 325       */
 326      edit : function( data ) {
 327          var frame,
 328              shortcode = wp.shortcode.next( 'video', data ).shortcode,
 329              attrs;
 330  
 331          attrs = shortcode.attrs.named;
 332          attrs.content = shortcode.content;
 333  
 334          frame = wp.media({
 335              frame: 'video',
 336              state: 'video-details',
 337              metadata: _.defaults( attrs, this.defaults )
 338          });
 339  
 340          return frame;
 341      },
 342  
 343      /**
 344       * Generates an video shortcode.
 345       *
 346       * @since 4.2.0
 347       *
 348       * @param {Array} model Array with attributes for the shortcode.
 349       * @returns {wp.shortcode} The video shortcode object.
 350       */
 351      shortcode : function( model ) {
 352          var content;
 353  
 354          _.each( this.defaults, function( value, key ) {
 355              model[ key ] = this.coerce( model, key );
 356  
 357              if ( value === model[ key ] ) {
 358                  delete model[ key ];
 359              }
 360          }, this );
 361  
 362          content = model.content;
 363          delete model.content;
 364  
 365          return new wp.shortcode({
 366              tag: 'video',
 367              attrs: model,
 368              content: content
 369          });
 370      }
 371  };
 372  
 373  media.model.PostMedia = __webpack_require__( 2 );
 374  media.controller.AudioDetails = __webpack_require__( 3 );
 375  media.controller.VideoDetails = __webpack_require__( 4 );
 376  media.view.MediaFrame.MediaDetails = __webpack_require__( 5 );
 377  media.view.MediaFrame.AudioDetails = __webpack_require__( 6 );
 378  media.view.MediaFrame.VideoDetails = __webpack_require__( 7 );
 379  media.view.MediaDetails = __webpack_require__( 8 );
 380  media.view.AudioDetails = __webpack_require__( 9 );
 381  media.view.VideoDetails = __webpack_require__( 10 );
 382  
 383  
 384  /***/ }),
 385  /* 2 */
 386  /***/ (function(module, exports) {
 387  
 388  /**
 389   * wp.media.model.PostMedia
 390   *
 391   * Shared model class for audio and video. Updates the model after
 392   *   "Add Audio|Video Source" and "Replace Audio|Video" states return
 393   *
 394   * @memberOf wp.media.model
 395   *
 396   * @class
 397   * @augments Backbone.Model
 398   */
 399  var PostMedia = Backbone.Model.extend(/** @lends wp.media.model.PostMedia.prototype */{
 400      initialize: function() {
 401          this.attachment = false;
 402      },
 403  
 404      setSource: function( attachment ) {
 405          this.attachment = attachment;
 406          this.extension = attachment.get( 'filename' ).split('.').pop();
 407  
 408          if ( this.get( 'src' ) && this.extension === this.get( 'src' ).split('.').pop() ) {
 409              this.unset( 'src' );
 410          }
 411  
 412          if ( _.contains( wp.media.view.settings.embedExts, this.extension ) ) {
 413              this.set( this.extension, this.attachment.get( 'url' ) );
 414          } else {
 415              this.unset( this.extension );
 416          }
 417      },
 418  
 419      changeAttachment: function( attachment ) {
 420          this.setSource( attachment );
 421  
 422          this.unset( 'src' );
 423          _.each( _.without( wp.media.view.settings.embedExts, this.extension ), function( ext ) {
 424              this.unset( ext );
 425          }, this );
 426      }
 427  });
 428  
 429  module.exports = PostMedia;
 430  
 431  
 432  /***/ }),
 433  /* 3 */
 434  /***/ (function(module, exports) {
 435  
 436  var State = wp.media.controller.State,
 437      l10n = wp.media.view.l10n,
 438      AudioDetails;
 439  
 440  /**
 441   * wp.media.controller.AudioDetails
 442   *
 443   * The controller for the Audio Details state
 444   *
 445   * @memberOf wp.media.controller
 446   *
 447   * @class
 448   * @augments wp.media.controller.State
 449   * @augments Backbone.Model
 450   */
 451  AudioDetails = State.extend(/** @lends wp.media.controller.AudioDetails.prototype */{
 452      defaults: {
 453          id: 'audio-details',
 454          toolbar: 'audio-details',
 455          title: l10n.audioDetailsTitle,
 456          content: 'audio-details',
 457          menu: 'audio-details',
 458          router: false,
 459          priority: 60
 460      },
 461  
 462      initialize: function( options ) {
 463          this.media = options.media;
 464          State.prototype.initialize.apply( this, arguments );
 465      }
 466  });
 467  
 468  module.exports = AudioDetails;
 469  
 470  
 471  /***/ }),
 472  /* 4 */
 473  /***/ (function(module, exports) {
 474  
 475  /**
 476   * wp.media.controller.VideoDetails
 477   *
 478   * The controller for the Video Details state
 479   *
 480   * @memberOf wp.media.controller
 481   *
 482   * @class
 483   * @augments wp.media.controller.State
 484   * @augments Backbone.Model
 485   */
 486  var State = wp.media.controller.State,
 487      l10n = wp.media.view.l10n,
 488      VideoDetails;
 489  
 490  VideoDetails = State.extend(/** @lends wp.media.controller.VideoDetails.prototype */{
 491      defaults: {
 492          id: 'video-details',
 493          toolbar: 'video-details',
 494          title: l10n.videoDetailsTitle,
 495          content: 'video-details',
 496          menu: 'video-details',
 497          router: false,
 498          priority: 60
 499      },
 500  
 501      initialize: function( options ) {
 502          this.media = options.media;
 503          State.prototype.initialize.apply( this, arguments );
 504      }
 505  });
 506  
 507  module.exports = VideoDetails;
 508  
 509  
 510  /***/ }),
 511  /* 5 */
 512  /***/ (function(module, exports) {
 513  
 514  var Select = wp.media.view.MediaFrame.Select,
 515      l10n = wp.media.view.l10n,
 516      MediaDetails;
 517  
 518  /**
 519   * wp.media.view.MediaFrame.MediaDetails
 520   *
 521   * @memberOf wp.media.view.MediaFrame
 522   *
 523   * @class
 524   * @augments wp.media.view.MediaFrame.Select
 525   * @augments wp.media.view.MediaFrame
 526   * @augments wp.media.view.Frame
 527   * @augments wp.media.View
 528   * @augments wp.Backbone.View
 529   * @augments Backbone.View
 530   * @mixes wp.media.controller.StateMachine
 531   */
 532  MediaDetails = Select.extend(/** @lends wp.media.view.MediaFrame.MediaDetails.prototype */{
 533      defaults: {
 534          id:      'media',
 535          url:     '',
 536          menu:    'media-details',
 537          content: 'media-details',
 538          toolbar: 'media-details',
 539          type:    'link',
 540          priority: 120
 541      },
 542  
 543      initialize: function( options ) {
 544          this.DetailsView = options.DetailsView;
 545          this.cancelText = options.cancelText;
 546          this.addText = options.addText;
 547  
 548          this.media = new wp.media.model.PostMedia( options.metadata );
 549          this.options.selection = new wp.media.model.Selection( this.media.attachment, { multiple: false } );
 550          Select.prototype.initialize.apply( this, arguments );
 551      },
 552  
 553      bindHandlers: function() {
 554          var menu = this.defaults.menu;
 555  
 556          Select.prototype.bindHandlers.apply( this, arguments );
 557  
 558          this.on( 'menu:create:' + menu, this.createMenu, this );
 559          this.on( 'content:render:' + menu, this.renderDetailsContent, this );
 560          this.on( 'menu:render:' + menu, this.renderMenu, this );
 561          this.on( 'toolbar:render:' + menu, this.renderDetailsToolbar, this );
 562      },
 563  
 564      renderDetailsContent: function() {
 565          var view = new this.DetailsView({
 566              controller: this,
 567              model: this.state().media,
 568              attachment: this.state().media.attachment
 569          }).render();
 570  
 571          this.content.set( view );
 572      },
 573  
 574      renderMenu: function( view ) {
 575          var lastState = this.lastState(),
 576              previous = lastState && lastState.id,
 577              frame = this;
 578  
 579          view.set({
 580              cancel: {
 581                  text:     this.cancelText,
 582                  priority: 20,
 583                  click:    function() {
 584                      if ( previous ) {
 585                          frame.setState( previous );
 586                      } else {
 587                          frame.close();
 588                      }
 589                  }
 590              },
 591              separateCancel: new wp.media.View({
 592                  className: 'separator',
 593                  priority: 40
 594              })
 595          });
 596  
 597      },
 598  
 599      setPrimaryButton: function(text, handler) {
 600          this.toolbar.set( new wp.media.view.Toolbar({
 601              controller: this,
 602              items: {
 603                  button: {
 604                      style:    'primary',
 605                      text:     text,
 606                      priority: 80,
 607                      click:    function() {
 608                          var controller = this.controller;
 609                          handler.call( this, controller, controller.state() );
 610                          // Restore and reset the default state.
 611                          controller.setState( controller.options.state );
 612                          controller.reset();
 613                      }
 614                  }
 615              }
 616          }) );
 617      },
 618  
 619      renderDetailsToolbar: function() {
 620          this.setPrimaryButton( l10n.update, function( controller, state ) {
 621              controller.close();
 622              state.trigger( 'update', controller.media.toJSON() );
 623          } );
 624      },
 625  
 626      renderReplaceToolbar: function() {
 627          this.setPrimaryButton( l10n.replace, function( controller, state ) {
 628              var attachment = state.get( 'selection' ).single();
 629              controller.media.changeAttachment( attachment );
 630              state.trigger( 'replace', controller.media.toJSON() );
 631          } );
 632      },
 633  
 634      renderAddSourceToolbar: function() {
 635          this.setPrimaryButton( this.addText, function( controller, state ) {
 636              var attachment = state.get( 'selection' ).single();
 637              controller.media.setSource( attachment );
 638              state.trigger( 'add-source', controller.media.toJSON() );
 639          } );
 640      }
 641  });
 642  
 643  module.exports = MediaDetails;
 644  
 645  
 646  /***/ }),
 647  /* 6 */
 648  /***/ (function(module, exports) {
 649  
 650  var MediaDetails = wp.media.view.MediaFrame.MediaDetails,
 651      MediaLibrary = wp.media.controller.MediaLibrary,
 652  
 653      l10n = wp.media.view.l10n,
 654      AudioDetails;
 655  
 656  /**
 657   * wp.media.view.MediaFrame.AudioDetails
 658   *
 659   * @memberOf wp.media.view.MediaFrame
 660   *
 661   * @class
 662   * @augments wp.media.view.MediaFrame.MediaDetails
 663   * @augments wp.media.view.MediaFrame.Select
 664   * @augments wp.media.view.MediaFrame
 665   * @augments wp.media.view.Frame
 666   * @augments wp.media.View
 667   * @augments wp.Backbone.View
 668   * @augments Backbone.View
 669   * @mixes wp.media.controller.StateMachine
 670   */
 671  AudioDetails = MediaDetails.extend(/** @lends wp.media.view.MediaFrame.AudioDetails.prototype */{
 672      defaults: {
 673          id:      'audio',
 674          url:     '',
 675          menu:    'audio-details',
 676          content: 'audio-details',
 677          toolbar: 'audio-details',
 678          type:    'link',
 679          title:    l10n.audioDetailsTitle,
 680          priority: 120
 681      },
 682  
 683      initialize: function( options ) {
 684          options.DetailsView = wp.media.view.AudioDetails;
 685          options.cancelText = l10n.audioDetailsCancel;
 686          options.addText = l10n.audioAddSourceTitle;
 687  
 688          MediaDetails.prototype.initialize.call( this, options );
 689      },
 690  
 691      bindHandlers: function() {
 692          MediaDetails.prototype.bindHandlers.apply( this, arguments );
 693  
 694          this.on( 'toolbar:render:replace-audio', this.renderReplaceToolbar, this );
 695          this.on( 'toolbar:render:add-audio-source', this.renderAddSourceToolbar, this );
 696      },
 697  
 698      createStates: function() {
 699          this.states.add([
 700              new wp.media.controller.AudioDetails( {
 701                  media: this.media
 702              } ),
 703  
 704              new MediaLibrary( {
 705                  type: 'audio',
 706                  id: 'replace-audio',
 707                  title: l10n.audioReplaceTitle,
 708                  toolbar: 'replace-audio',
 709                  media: this.media,
 710                  menu: 'audio-details'
 711              } ),
 712  
 713              new MediaLibrary( {
 714                  type: 'audio',
 715                  id: 'add-audio-source',
 716                  title: l10n.audioAddSourceTitle,
 717                  toolbar: 'add-audio-source',
 718                  media: this.media,
 719                  menu: false
 720              } )
 721          ]);
 722      }
 723  });
 724  
 725  module.exports = AudioDetails;
 726  
 727  
 728  /***/ }),
 729  /* 7 */
 730  /***/ (function(module, exports) {
 731  
 732  var MediaDetails = wp.media.view.MediaFrame.MediaDetails,
 733      MediaLibrary = wp.media.controller.MediaLibrary,
 734      l10n = wp.media.view.l10n,
 735      VideoDetails;
 736  
 737  /**
 738   * wp.media.view.MediaFrame.VideoDetails
 739   *
 740   * @memberOf wp.media.view.MediaFrame
 741   *
 742   * @class
 743   * @augments wp.media.view.MediaFrame.MediaDetails
 744   * @augments wp.media.view.MediaFrame.Select
 745   * @augments wp.media.view.MediaFrame
 746   * @augments wp.media.view.Frame
 747   * @augments wp.media.View
 748   * @augments wp.Backbone.View
 749   * @augments Backbone.View
 750   * @mixes wp.media.controller.StateMachine
 751   */
 752  VideoDetails = MediaDetails.extend(/** @lends wp.media.view.MediaFrame.VideoDetails.prototype */{
 753      defaults: {
 754          id:      'video',
 755          url:     '',
 756          menu:    'video-details',
 757          content: 'video-details',
 758          toolbar: 'video-details',
 759          type:    'link',
 760          title:    l10n.videoDetailsTitle,
 761          priority: 120
 762      },
 763  
 764      initialize: function( options ) {
 765          options.DetailsView = wp.media.view.VideoDetails;
 766          options.cancelText = l10n.videoDetailsCancel;
 767          options.addText = l10n.videoAddSourceTitle;
 768  
 769          MediaDetails.prototype.initialize.call( this, options );
 770      },
 771  
 772      bindHandlers: function() {
 773          MediaDetails.prototype.bindHandlers.apply( this, arguments );
 774  
 775          this.on( 'toolbar:render:replace-video', this.renderReplaceToolbar, this );
 776          this.on( 'toolbar:render:add-video-source', this.renderAddSourceToolbar, this );
 777          this.on( 'toolbar:render:select-poster-image', this.renderSelectPosterImageToolbar, this );
 778          this.on( 'toolbar:render:add-track', this.renderAddTrackToolbar, this );
 779      },
 780  
 781      createStates: function() {
 782          this.states.add([
 783              new wp.media.controller.VideoDetails({
 784                  media: this.media
 785              }),
 786  
 787              new MediaLibrary( {
 788                  type: 'video',
 789                  id: 'replace-video',
 790                  title: l10n.videoReplaceTitle,
 791                  toolbar: 'replace-video',
 792                  media: this.media,
 793                  menu: 'video-details'
 794              } ),
 795  
 796              new MediaLibrary( {
 797                  type: 'video',
 798                  id: 'add-video-source',
 799                  title: l10n.videoAddSourceTitle,
 800                  toolbar: 'add-video-source',
 801                  media: this.media,
 802                  menu: false
 803              } ),
 804  
 805              new MediaLibrary( {
 806                  type: 'image',
 807                  id: 'select-poster-image',
 808                  title: l10n.videoSelectPosterImageTitle,
 809                  toolbar: 'select-poster-image',
 810                  media: this.media,
 811                  menu: 'video-details'
 812              } ),
 813  
 814              new MediaLibrary( {
 815                  type: 'text',
 816                  id: 'add-track',
 817                  title: l10n.videoAddTrackTitle,
 818                  toolbar: 'add-track',
 819                  media: this.media,
 820                  menu: 'video-details'
 821              } )
 822          ]);
 823      },
 824  
 825      renderSelectPosterImageToolbar: function() {
 826          this.setPrimaryButton( l10n.videoSelectPosterImageTitle, function( controller, state ) {
 827              var urls = [], attachment = state.get( 'selection' ).single();
 828  
 829              controller.media.set( 'poster', attachment.get( 'url' ) );
 830              state.trigger( 'set-poster-image', controller.media.toJSON() );
 831  
 832              _.each( wp.media.view.settings.embedExts, function (ext) {
 833                  if ( controller.media.get( ext ) ) {
 834                      urls.push( controller.media.get( ext ) );
 835                  }
 836              } );
 837  
 838              wp.ajax.send( 'set-attachment-thumbnail', {
 839                  data : {
 840                      urls: urls,
 841                      thumbnail_id: attachment.get( 'id' )
 842                  }
 843              } );
 844          } );
 845      },
 846  
 847      renderAddTrackToolbar: function() {
 848          this.setPrimaryButton( l10n.videoAddTrackTitle, function( controller, state ) {
 849              var attachment = state.get( 'selection' ).single(),
 850                  content = controller.media.get( 'content' );
 851  
 852              if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) {
 853                  content += [
 854                      '<track srclang="en" label="English" kind="subtitles" src="',
 855                      attachment.get( 'url' ),
 856                      '" />'
 857                  ].join('');
 858  
 859                  controller.media.set( 'content', content );
 860              }
 861              state.trigger( 'add-track', controller.media.toJSON() );
 862          } );
 863      }
 864  });
 865  
 866  module.exports = VideoDetails;
 867  
 868  
 869  /***/ }),
 870  /* 8 */
 871  /***/ (function(module, exports) {
 872  
 873  /* global MediaElementPlayer */
 874  var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
 875      $ = jQuery,
 876      MediaDetails;
 877  
 878  /**
 879   * wp.media.view.MediaDetails
 880   *
 881   * @memberOf wp.media.view
 882   *
 883   * @class
 884   * @augments wp.media.view.Settings.AttachmentDisplay
 885   * @augments wp.media.view.Settings
 886   * @augments wp.media.View
 887   * @augments wp.Backbone.View
 888   * @augments Backbone.View
 889   */
 890  MediaDetails = AttachmentDisplay.extend(/** @lends wp.media.view.MediaDetails.prototype */{
 891      initialize: function() {
 892          _.bindAll(this, 'success');
 893          this.players = [];
 894          this.listenTo( this.controller, 'close', wp.media.mixin.unsetPlayers );
 895          this.on( 'ready', this.setPlayer );
 896          this.on( 'media:setting:remove', wp.media.mixin.unsetPlayers, this );
 897          this.on( 'media:setting:remove', this.render );
 898          this.on( 'media:setting:remove', this.setPlayer );
 899  
 900          AttachmentDisplay.prototype.initialize.apply( this, arguments );
 901      },
 902  
 903      events: function(){
 904          return _.extend( {
 905              'click .remove-setting' : 'removeSetting',
 906              'change .content-track' : 'setTracks',
 907              'click .remove-track' : 'setTracks',
 908              'click .add-media-source' : 'addSource'
 909          }, AttachmentDisplay.prototype.events );
 910      },
 911  
 912      prepare: function() {
 913          return _.defaults({
 914              model: this.model.toJSON()
 915          }, this.options );
 916      },
 917  
 918      /**
 919       * Remove a setting's UI when the model unsets it
 920       *
 921       * @fires wp.media.view.MediaDetails#media:setting:remove
 922       *
 923       * @param {Event} e
 924       */
 925      removeSetting : function(e) {
 926          var wrap = $( e.currentTarget ).parent(), setting;
 927          setting = wrap.find( 'input' ).data( 'setting' );
 928  
 929          if ( setting ) {
 930              this.model.unset( setting );
 931              this.trigger( 'media:setting:remove', this );
 932          }
 933  
 934          wrap.remove();
 935      },
 936  
 937      /**
 938       *
 939       * @fires wp.media.view.MediaDetails#media:setting:remove
 940       */
 941      setTracks : function() {
 942          var tracks = '';
 943  
 944          _.each( this.$('.content-track'), function(track) {
 945              tracks += $( track ).val();
 946          } );
 947  
 948          this.model.set( 'content', tracks );
 949          this.trigger( 'media:setting:remove', this );
 950      },
 951  
 952      addSource : function( e ) {
 953          this.controller.lastMime = $( e.currentTarget ).data( 'mime' );
 954          this.controller.setState( 'add-' + this.controller.defaults.id + '-source' );
 955      },
 956  
 957      loadPlayer: function () {
 958          this.players.push( new MediaElementPlayer( this.media, this.settings ) );
 959          this.scriptXhr = false;
 960      },
 961  
 962      setPlayer : function() {
 963          var src;
 964  
 965          if ( this.players.length || ! this.media || this.scriptXhr ) {
 966              return;
 967          }
 968  
 969          src = this.model.get( 'src' );
 970  
 971          if ( src && src.indexOf( 'vimeo' ) > -1 && ! ( 'Vimeo' in window ) ) {
 972              this.scriptXhr = $.getScript( 'https://player.vimeo.com/api/player.js', _.bind( this.loadPlayer, this ) );
 973          } else {
 974              this.loadPlayer();
 975          }
 976      },
 977  
 978      /**
 979       * @abstract
 980       */
 981      setMedia : function() {
 982          return this;
 983      },
 984  
 985      success : function(mejs) {
 986          var autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
 987  
 988          if ( 'flash' === mejs.pluginType && autoplay ) {
 989              mejs.addEventListener( 'canplay', function() {
 990                  mejs.play();
 991              }, false );
 992          }
 993  
 994          this.mejs = mejs;
 995      },
 996  
 997      /**
 998       * @returns {media.view.MediaDetails} Returns itself to allow chaining
 999       */
1000      render: function() {
1001          AttachmentDisplay.prototype.render.apply( this, arguments );
1002  
1003          setTimeout( _.bind( function() {
1004              this.scrollToTop();
1005          }, this ), 10 );
1006  
1007          this.settings = _.defaults( {
1008              success : this.success
1009          }, wp.media.mixin.mejsSettings );
1010  
1011          return this.setMedia();
1012      },
1013  
1014      scrollToTop: function() {
1015          this.$( '.embed-media-settings' ).scrollTop( 0 );
1016      }
1017  },/** @lends wp.media.view.MediaDetails */{
1018      instances : 0,
1019      /**
1020       * When multiple players in the DOM contain the same src, things get weird.
1021       *
1022       * @param {HTMLElement} elem
1023       * @returns {HTMLElement}
1024       */
1025      prepareSrc : function( elem ) {
1026          var i = MediaDetails.instances++;
1027          _.each( $( elem ).find( 'source' ), function( source ) {
1028              source.src = [
1029                  source.src,
1030                  source.src.indexOf('?') > -1 ? '&' : '?',
1031                  '_=',
1032                  i
1033              ].join('');
1034          } );
1035  
1036          return elem;
1037      }
1038  });
1039  
1040  module.exports = MediaDetails;
1041  
1042  
1043  /***/ }),
1044  /* 9 */
1045  /***/ (function(module, exports) {
1046  
1047  var MediaDetails = wp.media.view.MediaDetails,
1048      AudioDetails;
1049  
1050  /**
1051   * wp.media.view.AudioDetails
1052   *
1053   * @memberOf wp.media.view
1054   *
1055   * @class
1056   * @augments wp.media.view.MediaDetails
1057   * @augments wp.media.view.Settings.AttachmentDisplay
1058   * @augments wp.media.view.Settings
1059   * @augments wp.media.View
1060   * @augments wp.Backbone.View
1061   * @augments Backbone.View
1062   */
1063  AudioDetails = MediaDetails.extend(/** @lends wp.media.view.AudioDetails.prototype */{
1064      className: 'audio-details',
1065      template:  wp.template('audio-details'),
1066  
1067      setMedia: function() {
1068          var audio = this.$('.wp-audio-shortcode');
1069  
1070          if ( audio.find( 'source' ).length ) {
1071              if ( audio.is(':hidden') ) {
1072                  audio.show();
1073              }
1074              this.media = MediaDetails.prepareSrc( audio.get(0) );
1075          } else {
1076              audio.hide();
1077              this.media = false;
1078          }
1079  
1080          return this;
1081      }
1082  });
1083  
1084  module.exports = AudioDetails;
1085  
1086  
1087  /***/ }),
1088  /* 10 */
1089  /***/ (function(module, exports) {
1090  
1091  var MediaDetails = wp.media.view.MediaDetails,
1092      VideoDetails;
1093  
1094  /**
1095   * wp.media.view.VideoDetails
1096   *
1097   * @memberOf wp.media.view
1098   *
1099   * @class
1100   * @augments wp.media.view.MediaDetails
1101   * @augments wp.media.view.Settings.AttachmentDisplay
1102   * @augments wp.media.view.Settings
1103   * @augments wp.media.View
1104   * @augments wp.Backbone.View
1105   * @augments Backbone.View
1106   */
1107  VideoDetails = MediaDetails.extend(/** @lends wp.media.view.VideoDetails.prototype */{
1108      className: 'video-details',
1109      template:  wp.template('video-details'),
1110  
1111      setMedia: function() {
1112          var video = this.$('.wp-video-shortcode');
1113  
1114          if ( video.find( 'source' ).length ) {
1115              if ( video.is(':hidden') ) {
1116                  video.show();
1117              }
1118  
1119              if ( ! video.hasClass( 'youtube-video' ) && ! video.hasClass( 'vimeo-video' ) ) {
1120                  this.media = MediaDetails.prepareSrc( video.get(0) );
1121              } else {
1122                  this.media = video.get(0);
1123              }
1124          } else {
1125              video.hide();
1126              this.media = false;
1127          }
1128  
1129          return this;
1130      }
1131  });
1132  
1133  module.exports = VideoDetails;
1134  
1135  
1136  /***/ })
1137  /******/ ]);


Generated: Mon Jul 22 01:00:03 2019 Cross-referenced by PHPXref 0.7.1