Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ class filter_jwplayer_media extends core_media_player {
* @param int $width Optional width; 0 to use default
* @param int $height Optional height; 0 to use default
* @param array $options Options array
* buttons
* use 'buttons' key with an array of arrays with id, img, text, callback indexes
* id: unique id across all buttons assigned to this player
* img: an icon used for the button
* text: a label displayed while mouse over the button
* callback: a JavaScript function name used as callback, playerid provided as first parameter
* Example: $options['buttons'] = array(array(
* 'id'=>'uniqueid',
* 'img'=>http://path/to/img.png,
* 'text'=>'label',
* 'callback'=>'M.plugin.callback'))
* for more details see http://support.jwplayer.com/customer/portal/articles/1413089-javascript-api-reference#controls
* @return string HTML code for embed
*/
public function embed($urls, $name, $width, $height, $options) {
Expand Down Expand Up @@ -172,18 +184,26 @@ public function embed($urls, $name, $width, $height, $options) {
$playersetupdata['skin'] = $skin;
}

$downloadbtn = null;
$buttons = array();

if (get_config('filter_jwplayer', 'downloadbutton')) {
$downloadbtn = array(
'img' => $CFG->wwwroot.'/filter/jwplayer/img/download.png',
'tttext' => get_string('videodownloadbtntttext', 'filter_jwplayer')
'text' => get_string('videodownloadbtntttext', 'filter_jwplayer'),
'callback' => 'M.filter_jwplayer.download',
'id' => 'download'
);
$buttons[] = $downloadbtn;
}

if (isset($options['buttons']) && is_array($options['buttons'])) {
$buttons = array_merge($buttons, $options['buttons']);
}

$playersetup = array(
'playerid' => $playerid,
'setupdata' => $playersetupdata,
'downloadbtn' => $downloadbtn,
'buttons' => $buttons,
);

// Set up the player.
Expand Down
29 changes: 23 additions & 6 deletions module.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
M.filter_jwplayer = {};

M.filter_jwplayer.init = function(Y, playerid, setupdata, downloadbtn) {
M.filter_jwplayer.init = function(Y, playerid, setupdata, buttons) {
jwplayer(playerid).setup(setupdata);

if (downloadbtn != undefined) {
jwplayer(playerid).addButton(downloadbtn.img, downloadbtn.tttext, function() {
// Grab the file that's currently playing.
window.location.href = jwplayer(playerid).getPlaylistItem().file + '?forcedownload=true';
}, "download");
function btncallback(i) {
return function() {
M.filter_jwplayer.execute_namespaced_function(buttons[i].callback, [playerid]);
};
}

for (var i = 0; i < buttons.length; i++) {
jwplayer(playerid).addButton(buttons[i].img, buttons[i].text, btncallback(i), buttons[i].id);
}
};

M.filter_jwplayer.download = function(playerid) {
window.location.href = jwplayer(playerid).getPlaylistItem().file + '?forcedownload=true';
};

M.filter_jwplayer.execute_namespaced_function = function(namespacedfunctionname, args) {
var namespaces = namespacedfunctionname.split(".");
var fn = namespaces.pop();
var context = window;
for (var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
context[fn].apply(context, args);
};