Вход Регистрация
Файл: wordpress/wp-includes/js/mediaelement/wp-playlist.js
Строк: 160
<?php
/*globals window, document, jQuery, _, Backbone, _wpmejsSettings */

(function ($, _Backbone) {
    
"use strict";

    var 
WPPlaylistView Backbone.View.extend({
        
initialize : function (options) {
            
this.index 0;
            
this.settings = {};
            
this.data options.metadata || $.parseJSONthis.$('script.wp-playlist-script').html() );
            
this.playerNode this.$( this.data.type );

            
this.tracks = new Backbone.Collectionthis.data.tracks );
            
this.current this.tracks.first();

            if ( 
'audio' === this.data.type ) {
                
this.currentTemplate wp.template'wp-playlist-current-item' );
                
this.currentNode this.$( '.wp-playlist-current-item' );
            }

            
this.renderCurrent();

            if ( 
this.data.tracklist ) {
                
this.itemTemplate wp.template'wp-playlist-item' );
                
this.playingClass 'wp-playlist-playing';
                
this.renderTracks();
            }

            
this.playerNode.attr'src'this.current.get'src' ) );

            
_.bindAllthis'bindPlayer''bindResetPlayer''setPlayer''ended''clickTrack' );

            if ( ! 
_.isUndefinedwindow._wpmejsSettings ) ) {
                
this.settings _wpmejsSettings;
            }
            
this.settings.success this.bindPlayer;
            
this.setPlayer();
        },

        
bindPlayer : function (mejs) {
            
this.mejs mejs;
            
this.mejs.addEventListener'ended'this.ended );
        },

        
bindResetPlayer : function (mejs) {
            
this.bindPlayermejs );
            
this.playCurrentSrc();
        },

        
setPlayer: function (force) {
            if ( 
this.player ) {
                
this.player.pause();
                
this.player.remove();
                
this.playerNode this.$( this.data.type );
            }

            if (
force) {
                
this.playerNode.attr'src'this.current.get'src' ) );
                
this.settings.success this.bindResetPlayer;
            }

            
/**
             * This is also our bridge to the outside world
             */
            
this.player = new MediaElementPlayerthis.playerNode.get(0), this.settings );
        },

        
playCurrentSrc : function () {
            
this.renderCurrent();
            
this.mejs.setSrcthis.playerNode.attr'src' ) );
            
this.mejs.load();
            
this.mejs.play();
        },

        
renderCurrent : function () {
            var 
dimensionsdefaultImage 'wp-includes/images/media/video.png';
            if ( 
'video' === this.data.type ) {
                if ( 
this.data.images && this.current.get'image' ) && -=== this.current.get'image' ).src.indexOfdefaultImage ) ) {
                    
this.playerNode.attr'poster'this.current.get'image' ).src );
                }
                
dimensions this.current.get'dimensions' ).resized;
                
this.playerNode.attrdimensions );
            } else {
                if ( ! 
this.data.images ) {
                    
this.current.set'image'false );
                }
                
this.currentNode.htmlthis.currentTemplatethis.current.toJSON() ) );
            }
        },

        
renderTracks : function () {
            var 
self this1tracklist = $( '<div class="wp-playlist-tracks"></div>' );
            
this.tracks.each(function (model) {
                if ( ! 
self.data.images ) {
                    
model.set'image'false );
                }
                
model.set'artists'self.data.artists );
                
model.set'index'self.data.tracknumbers false );
                
tracklist.appendself.itemTemplatemodel.toJSON() ) );
                
+= 1;
            });
            
this.$el.appendtracklist );

            
this.$( '.wp-playlist-item' ).eq(0).addClassthis.playingClass );
        },

        
events : {
            
'click .wp-playlist-item' 'clickTrack',
            
'click .wp-playlist-next' 'next',
            
'click .wp-playlist-prev' 'prev'
        
},

        
clickTrack : function (e) {
            
e.preventDefault();

            
this.index this.$( '.wp-playlist-item' ).indexe.currentTarget );
            
this.setCurrent();
        },

        
ended : function () {
            if ( 
this.index this.tracks.length ) {
                
this.next();
            } else {
                
this.index 0;
                
this.setCurrent();
            }
        },

        
next : function () {
            
this.index this.index >= this.tracks.length this.index 1;
            
this.setCurrent();
        },

        
prev : function () {
            
this.index this.index this.tracks.length this.index 1;
            
this.setCurrent();
        },

        
loadCurrent : function () {
            var 
last this.playerNode.attr'src' ) && this.playerNode.attr'src' ).split('.').pop(),
                
current this.current.get'src' ).split('.').pop();

            
this.mejs && this.mejs.pause();

            if ( 
last !== current ) {
                
this.setPlayertrue );
            } else {
                
this.playerNode.attr'src'this.current.get'src' ) );
                
this.playCurrentSrc();
            }
        },

        
setCurrent : function () {
            
this.current this.tracks.atthis.index );

            if ( 
this.data.tracklist ) {
                
this.$( '.wp-playlist-item' )
                    .
removeClassthis.playingClass )
                    .
eqthis.index )
                        .
addClassthis.playingClass );
            }

            
this.loadCurrent();
        }
    });

    $(
document).ready(function () {
        $(
'.wp-playlist').each( function() {
            return new 
WPPlaylistView({ elthis });
        } );
    });

    
window.WPPlaylistView WPPlaylistView;

}(
jQuery_Backbone));
?>
Онлайн: 1
Реклама