Skip to content

Add custom buttons support as $option param#16

Open
jojoob wants to merge 2 commits intolucisgit:masterfrom
sudile:dev-custombtn
Open

Add custom buttons support as $option param#16
jojoob wants to merge 2 commits intolucisgit:masterfrom
sudile:dev-custombtn

Conversation

@jojoob
Copy link
Contributor

@jojoob jojoob commented May 4, 2015

Provide an options array entry with "buttons" key and an array of "button arrays" with id, img, text, callback indexes to add custom buttons to the player.
Adapted download button init to this new flexible buttons feature.

Example:

$options['buttons'] = array(array(
    'id'=>'uniqueid',
    'img'=>'http://path/to/img.png',
    'text'=>'label',
    'callback'=>'M.plugin.callback'));

@kabalin
Copy link
Contributor

kabalin commented Jun 17, 2015

Yeah, I see what you mean, but you already have M.filter_jwplayer context, just use it directly!

@kabalin
Copy link
Contributor

kabalin commented Jun 17, 2015

This is how it can be modified, works for me.

diff --git a/filter/jwplayer/lib.php b/filter/jwplayer/lib.php
index 9ef5c70..7564128 100644
--- a/filter/jwplayer/lib.php
+++ b/filter/jwplayer/lib.php
@@ -190,7 +190,7 @@ class filter_jwplayer_media extends core_media_player {
                 $downloadbtn = array(
                     'img' => $CFG->wwwroot.'/filter/jwplayer/img/download.png',
                     'text' => get_string('videodownloadbtntttext', 'filter_jwplayer'),
-                    'callback' => 'M.filter_jwplayer.download',
+                    'callback' => 'download',
                     'id' => 'download'
                 );
                 $buttons[] = $downloadbtn;
diff --git a/filter/jwplayer/module.js b/filter/jwplayer/module.js
index 641927d..443f1bf 100644
--- a/filter/jwplayer/module.js
+++ b/filter/jwplayer/module.js
@@ -3,24 +3,14 @@ M.filter_jwplayer = {};
 M.filter_jwplayer.init = function(Y, playerid, setupdata, buttons) {
     jwplayer(playerid).setup(setupdata);

-    var executenamespacedFunction = 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);
-    };
-
-    function btncallback(i) {
+    function btncallback(callback) {
         return function() {
-            executenamespacedFunction(buttons[i].callback, [playerid]);
+            M.filter_jwplayer[callback](playerid);
         };
     }

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

@jojoob
Copy link
Contributor Author

jojoob commented Jun 17, 2015

But this will not work if you have a button callback outside of M.fitler_jwplayer workspace. And this would be the case if using the jwplayer with a custom button via the options param. For my mod_video plugin I create a button and the callback is declared in the mod_video namespace M.mod_video.

@kabalin kabalin closed this Aug 7, 2015
@kabalin kabalin reopened this Aug 7, 2015
@kabalin
Copy link
Contributor

kabalin commented Aug 7, 2015

Please resubmit pull request to JW7 branch, master branch will be deleted as per #37.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants