From 76979b60b03d71098980ab0dcfffe3e28b02929a Mon Sep 17 00:00:00 2001 From: sanj Date: Sun, 2 Jan 2011 14:52:15 +0530 Subject: [PATCH] playlist --- padma.links.js | 9 +++++++- padma.playlist.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 padma.playlist.js diff --git a/padma.links.js b/padma.links.js index 83f0457..b5161fa 100644 --- a/padma.links.js +++ b/padma.links.js @@ -20,6 +20,7 @@ if (linkData && $.inArray(linkData.type, ['info', 'tcRange', 'editor', 'tc', 'layer'])) { //Don't fetch data twice if video id already exists $(that).addClass('padmaLink'); + var videoId = linkData.videoId; /* var cacheVideo = padmaVideo.getFromCache(videoId); @@ -30,7 +31,9 @@ } */ var videoObj = new padmaVideo(videoId); - + $(this).data({ + 'videoObj': videoObj + }); // console.log(linkData); videoObj.getAllData(setupPadmaLink, {'linkData': linkData, 'jq': that}); @@ -39,6 +42,10 @@ } } }); + if ($('#leftBar').length > 0) { + var playlist = new PadmaPlaylist($('#leftBar')); + } +// FOO = new PadmaPlaylist($('#essay')); }); // D = parsePadmaUrl; })(jQuery); diff --git a/padma.playlist.js b/padma.playlist.js new file mode 100644 index 0000000..91ca486 --- /dev/null +++ b/padma.playlist.js @@ -0,0 +1,54 @@ +/* +Padma Playlist - +Pass it a jquery object - it will find all a elements within it which are padma links and make them a playlist +eg. var playlist = new PadmaPlaylist($(' +*/ + +(function($) { + var PadmaPlaylist = window.PadmaPlaylist = function(jq) { + this.videos = []; + this.elements = []; + this.position = 0; + this.len = function() { return this.elements.length }; + this.jq = jq; + this.init(); + }; + + PadmaPlaylist.prototype.init = function() { + var that = this; + var i = 0; + $('a', that.jq).each(function() { + var t = $(this); + var href = t.attr("href"); + if (href.indexOf(padmaConfig.links_url) != -1) { + that.elements.push(t); + t.data("playlist", that); + t.data("inPlaylist", true); + t.data("playlistPosition", i); + t.click(function() { + var playlist = $(this).data("playlist"); + var position = $(this).data("playlistPosition"); + playlist.position = position; + }); + i++; + } + }); + }; + + PadmaPlaylist.prototype.next = function() { + var pos = this.position; + if (pos < (this.len() - 1)) { + var nextElem = this.elements[pos + 1]; + nextElem.click(); + } + }; + + PadmaPlaylist.prototype.previous = function() { + var pos = this.position; + if (pos > 0) { + var prevElem = this.elements[pos - 1]; + prevElem.click(); + } + }; + +})(jQuery);