Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added some events and streamlined stuff

  • Loading branch information...
commit 1b27857bf5e29722bceb484f824a510699001031 1 parent 1b1e768
@ojii ojii authored
View
11 README
@@ -1 +1,10 @@
-To be written
+##################
+django-cms-jplayer
+##################
+
+============
+Dependencies
+============
+
+* jPlayer
+* django-cms (optional)
View
2  jplayer/__init__.py
@@ -1 +1 @@
-__version__ = '0.1.5'
+__version__ = '0.1.6'
View
43 jplayer/media/jplayer/js/cmsplayer.js
@@ -1,5 +1,11 @@
-function cmsplayer_ready (element, playlist, autoplay, playerid)
+function dbg(msg){window.console && console.log && console.log(msg);}
+
+function cmsplayer_ready (element, options)
{
+ var playerid = options.playerid;
+ var autoplay = options.autoplay;
+ var autonext = options.autonext;
+ var playlist = options.playlist;
var playItem = 0;
var playtime = $("#play_time_"+playerid);
var totaltime = $("#total_time_"+playerid);
@@ -23,7 +29,10 @@ function cmsplayer_ready (element, playlist, autoplay, playerid)
var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
totaltime.text(ttMin+":"+ttSec);
}).jPlayer("onSoundComplete", function() {
- playListNext();
+ element.trigger('cmsplayer_songcomplete', [playlist[playItem]]);
+ if(autonext){
+ playListNext();
+ }
});
$("#ctrl_prev_"+playerid).click( function() {
@@ -56,6 +65,7 @@ function cmsplayer_ready (element, playlist, autoplay, playerid)
}
function playListInit(autoplay) {
+ element.trigger('cmsplayer_init', [playlist[playItem]]);
if(autoplay) {
playListChange( playItem );
} else {
@@ -75,11 +85,13 @@ function cmsplayer_ready (element, playlist, autoplay, playerid)
{
element.jPlayer("setFile", playlist[playItem].mp3);
}
+ element.trigger('cmsplayer_config', [playlist[playItem]]);
}
function playListChange( index ) {
playListConfig( index );
element.jPlayer("play");
+ element.trigger('cmsplayer_change', [playlist[playItem]]);
}
function playListNext() {
@@ -94,4 +106,29 @@ function cmsplayer_ready (element, playlist, autoplay, playerid)
displayPlayList();
playListInit(autoplay);
-}
+}
+
+(function($) {
+ $.fn.cmsPlayer = function(options) {
+ if (!options){
+ var options = {};
+ }
+ $.extend(options, {
+ ready: cmsplayer_ready(this, options)
+ })
+ var fulloptions = {
+ autoplay: true,
+ autonext: true
+ };
+ $.extend(fulloptions, options);
+ if (!fulloptions.playerid || !fulloptions.playlist)
+ {
+ dbg("[CMSPLAYER] ERROR: playerid and playlist *must* be defined!");
+ return this;
+ }
+ this.jPlayer(fulloptions);
+ return this;
+ };
+})(jQuery);
+
+document.cmsPlayerLoaded = true;
View
20 jplayer/templates/jplayer/player.html
@@ -31,18 +31,16 @@
</div>
<script type="text/javascript">
$(document).ready(function(){
- $("head").append('<scr' + 'ipt type="text/javascript" src="{{ MEDIA_URL }}jplayer/js/cmsplayer.js"></scr' + 'ipt>');
+ if (!document.cmsPlayerLoaded){
+ $("head").append('<scr' + 'ipt type="text/javascript" src="{{ MEDIA_URL }}jplayer/js/cmsplayer.js"></scr' + 'ipt>');
+ }
var player = $('#jquery_jplayer_{{ player.id }}');
- player.jPlayer(
- {
- ready:function(){
- cmsplayer_ready(
- player,
- {{ player.get_json_playlist }},
- {{ player.get_json_autoplay }},
- "{{ player.id }}"
- );
- },
+ player.cmsPlayer(
+ {
+ playlist: {{ player.get_json_playlist }},
+ autoplay: {{ player.get_json_autoplay }},
+ playerid: "{{ player.id }}",
+ autonext: true,
cssPrefix: 'jqjp_{{ player.id }}',
swfPath: 'http://' + window.location.host + {{ player.get_base_path }},
oggSupport: {{ player.get_json_ogg_support }},
Please sign in to comment.
Something went wrong with that request. Please try again.