]> git.0d.be Git - panikweb.git/commitdiff
give play capacity to resume
authorlaron <simon@surlaterre.org>
Sat, 31 Aug 2013 09:09:55 +0000 (11:09 +0200)
committerlaron <simon@surlaterre.org>
Sat, 31 Aug 2013 09:09:55 +0000 (11:09 +0200)
panikweb_templates/static/js/audioPlayer.js
panikweb_templates/static/js/specifics.js
panikweb_templates/templates/includes/audio.html

index 07f2509e9f4bc3e1428acd1b247482c34dcb7798..751801bd5edec695ecefdcc067981dcd85631eaf 100644 (file)
                },
                // Transform JSON sound object to HTML container for playlist.
                _htmlifyJsonSound: function(sound) {
-                       var container = $('<li>');
+                       var container = $('<li>').attr('data-origin',sound.id);
                        var audio = $('<audio>',this.options.html5audioOptions).hide();
                        $.each(sound.source,function(k,v){
                                var source = $('<source>',{src:v,type:k});
                                audio.append(source);
                        });
                        audio.attr('title',sound.title)
-                       .attr('data-origin',sound.id)
+                       
                        .on('play',function(){
                                thePlaylist.setFocus(container);
                                container.addClass('playing');
                },
                // Create a public method.
                registerAudio: function(audio,success) {
-                       var htmlAudio = this._htmlifyJsonSound(this.jsonifyAudio(audio));
+                       var audioObj = this.jsonifyAudio(audio);
+                       var htmlAudio = this._htmlifyJsonSound(audioObj);
                        this.playlistContainer.append(htmlAudio);
                        this.isLastAdd = htmlAudio;
                        if(!this.isActive){this.setFocus(this.isLastAdd);}
                        this._update();
                },
                // Play next sound
+               bindControl: function(control,audio,element,options) {
+                       element.addClass('loading');
+                       audioID = audio.attr('id');                     
+                       //TODO for controls in page content
+               },
+               // Play next sound
                registerControl: function(name,options) {
                        this.controlButtons[name] = $('<button>',options);
                        this.controlContainer.append(this.controlButtons[name]);
                        this.isActive.next().find('audio').trigger('beforePlay').trigger('play');
                        return true;
                },
+               // Play next sound
+               playLast: function() {
+                       this.playlistContainer.find('audio').last().trigger('beforePlay').trigger('play');
+                       return true;
+               },
                // Pause all sounds.
                pauseSounds: function(selector) {
                        this.playlistContainer.find('audio').each(function(){$(this).trigger('pause');});       
index 2e499124ca06faa499bc352a3e57925b798b78e9..4974fecc268df585f5600de052b792f455865e93 100644 (file)
@@ -15,6 +15,7 @@ $(function() {
                        self.registerControl('showList',{class:"icon-list",click:       function(){ 
                                self.playlistContainer.toggleClass('deploy');
                        }});
+                       self.controlButtons['showList'].appendTo($('#localList .label'));
                },
                onPlay:function(self){
                        $('#DirectStreamPanik')[0].pause();
@@ -41,9 +42,9 @@ $(function() {
                }
        });
 
-/****************************************************/
-/**** AUDIOPLAYER ****/
-/****************************************************/
+       /****************************************************/
+       /**** AUDIOPLAYER ****/
+       /****************************************************/
        if($('#player-container').offset()){
                var topPosition = 0;
                topPosition = $('#player-container').offset().top;
@@ -59,9 +60,9 @@ $(function() {
                        }
                });
        }
-/****************************************************/
-/**** AJAX REQUESTS ****/
-/****************************************************/
+       /****************************************************/
+       /**** AJAX REQUESTS ****/
+       /****************************************************/
        String.prototype.decodeHTML = function() {
                return $("<div>", {html: "" + this}).html();
        };
@@ -114,7 +115,7 @@ $(function() {
                loadPage_request = $.get(href, null, afterLoad);
        };
        init = function() {
-               $("#All a, #All area, #All form").removeClass('loading');
+               $("#All a, #All area").removeClass('loading');
                $("#All a, #All area").unbind('click').on('click',function() {
                        $(this).addClass('loading');
                        var href = $(this).attr("href");
@@ -123,15 +124,16 @@ $(function() {
                         * part points to the same domain */
                        if (!href) {
                                doLog('No href attributes, unable to load content','error');
-                               $("#All a, #All area, #All form").removeClass('loading');
+                               $("#All a, #All area").removeClass('loading');
                                return false;
-                       }else if (href.indexOf(document.domain) > -1 ||
-                               href.indexOf(':') === -1 || href.indexOf(':') > 5) {
+                       }else if (!$(this).attr('target') && (
+                                       href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
+                               )) {
                                loadPage(href);
                                return false;
                        }else{
                                $(this).attr('target','_blanck');
-                               $("#All a, #All area, #All form").removeClass('loading');
+                               $("#All a, #All area").removeClass('loading');
                                return true;
                        }
                });
@@ -158,10 +160,22 @@ $(function() {
                        });  
                        activeTab.trigger('load');
                });
-               $('[data-player-audio]').on('click',function(){
-                       var audio = $($(this).attr('data-player-audio'));
-                       $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
+               $('[data-player-action]').on('click',function(){
+                       var audio = $('#'+$(this).attr('data-player-audio'));
+                       if($(this).attr('data-player-action') == "registerAudio"){
+                               $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
+                       }else if($(this).attr('data-player-action') == "playAudio"){
+                               $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
+                               $localList.playlist("playLast");
+                       }else{
+                               $localList.playlist($(this).attr('data-player-action'));
+                       }
+               });
+               $('[data-player-control]').each(function(){
+                       var audio = $('#'+$(this).attr('data-player-audio'));
+                       $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
                });
+
                $('[data-highlight]').on('check',function(){
                        $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
                }).on('uncheck',function(){
@@ -186,47 +200,6 @@ $(function() {
                $('[data-toggle].icon-check-empty').each(function(){
                        $(this).trigger('uncheck');
                });
-               /*
-               $('[data-highlight].icon-check').each(function(){
-                       $(this).trigger('check');
-               });
-               */
-               /*
-               $("[data-audio-control]").each(function() {
-                       var audio = $('#'+$(this).attr('data-audio-control'));
-                       var audioElement = audio[0];
-                       if(audioElement){
-                               var addToPlaylist = $(this).find('.add');
-                               addToPlaylist.on('click',function(e){
-                                       audio.clone().appendTo('#Playlist');
-                                       $('#Playlist').parent().show();
-                               });
-                               var playPauseButton = $(this).find('.playpause');
-                               //alert($(this).attr('data-audio'));
-                               playPauseButton.on('click',function(e){
-                                         if (audioElement.paused == false) {
-                                             audioElement.pause();
-                                         } else {
-                                             audioElement.play();
-                                         }
-                               });
-                               //alert($(this).attr('data-audio'));
-                               playPauseButton.on('click',function(e){
-                                         if (audioElement.paused == false) {
-                                             audioElement.pause();
-                                         } else {
-                                             audioElement.play();
-                                         }
-                               });
-                               // Bind back event in case of direct control
-                               audio.on('play',function(){
-                                       playPauseButton.addClass('icon-pause').removeClass('icon-play');
-                               }).on('pause',function(){
-                                       playPauseButton.addClass('icon-play').removeClass('icon-pause');
-                               });
-                       }
-               });
-               */
        }
        init();
 });
index 04ebe5b7765c5e86f112ce83cd92591da308bc45..8d4f7831fc9406aaec795e8b9a9df0cd547ceed7 100644 (file)
@@ -4,14 +4,14 @@
        <div class="controls huge">
                <button class="icon-plus-sign"
                        title="Add to playlist" 
-                       data-player-audio="#Audio-{{ sound.file.url|slugify }}" 
-                       data-player-method="add
+                       data-player-audio="Audio-{{ sound.file.url|slugify }}" 
+                       data-player-action="registerAudio
                        id="addToPlaylist-{{ sound.file.url|slugify }}"
                        ></button>
                <button class="icon-play-circle"
                        title="Play" 
-                       data-player-audio="#Audio-{{ sound.file.url|slugify }}" 
-                       data-player-method="play
+                       data-player-audio="Audio-{{ sound.file.url|slugify }}" 
+                       data-player-action="playAudio
                        ></button>
                {% if sound|is_format_available:'ogg' %}
                        <a target="_blanck" class="icon-download button" href="{{ sound|format_url:'ogg' }}"