-/*globals window, document, jQuery, _, Backbone, _wpmejsSettings */
+/* global _wpmejsSettings, MediaElementPlayer */
(function ($, _, Backbone) {
- "use strict";
+ 'use strict';
var WPPlaylistView = Backbone.View.extend({
initialize : function (options) {
this.index = 0;
this.settings = {};
- this.compatMode = $( 'body' ).hasClass( 'wp-admin' ) && $( '#content_ifr' ).length;
- this.data = options.metadata || $.parseJSON( this.$('script').html() );
+ this.data = options.metadata || $.parseJSON( this.$('script.wp-playlist-script').html() );
this.playerNode = this.$( this.data.type );
this.tracks = new Backbone.Collection( this.data.tracks );
this.renderTracks();
}
- if ( this.isCompatibleSrc() ) {
- this.playerNode.attr( 'src', this.current.get( 'src' ) );
- }
+ this.playerNode.attr( 'src', this.current.get( 'src' ) );
_.bindAll( this, 'bindPlayer', 'bindResetPlayer', 'setPlayer', 'ended', 'clickTrack' );
if ( ! _.isUndefined( window._wpmejsSettings ) ) {
- this.settings.pluginPath = _wpmejsSettings.pluginPath;
+ this.settings = _.clone( _wpmejsSettings );
}
this.settings.success = this.bindPlayer;
this.setPlayer();
bindResetPlayer : function (mejs) {
this.bindPlayer( mejs );
- if ( this.isCompatibleSrc() ) {
- this.playCurrentSrc();
- }
- },
-
- isCompatibleSrc: function () {
- var testNode;
-
- if ( this.compatMode ) {
- testNode = $( '<span><source type="' + this.current.get( 'type' ) + '" /></span>' );
-
- if ( ! wp.media.mixin.isCompatible( testNode ) ) {
- this.playerNode.removeAttr( 'src' );
- this.playerNode.removeAttr( 'poster' );
- return;
- }
- }
-
- return true;
+ this.playCurrentSrc();
},
setPlayer: function (force) {
}
if (force) {
- if ( this.isCompatibleSrc() ) {
- this.playerNode.attr( 'src', this.current.get( 'src' ) );
- }
+ this.playerNode.attr( 'src', this.current.get( 'src' ) );
this.settings.success = this.bindResetPlayer;
}
this.next();
} else {
this.index = 0;
- this.current = this.tracks.at( this.index );
- this.loadCurrent();
+ this.setCurrent();
}
},
if ( last !== current ) {
this.setPlayer( true );
- } else if ( this.isCompatibleSrc() ) {
+ } else {
this.playerNode.attr( 'src', this.current.get( 'src' ) );
this.playCurrentSrc();
}
});
$(document).ready(function () {
- if ( ! $( 'body' ).hasClass( 'wp-admin' ) || $( 'body' ).hasClass( 'about-php' ) ) {
- $('.wp-playlist').each(function () {
- return new WPPlaylistView({ el: this });
- });
- }
+ $('.wp-playlist').each( function() {
+ return new WPPlaylistView({ el: this });
+ } );
});
window.WPPlaylistView = WPPlaylistView;
-}(jQuery, _, Backbone));
\ No newline at end of file
+}(jQuery, _, Backbone));