padmaEssay/padma.playlist.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2011-01-02 09:22:15 +00:00
/*
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);