# HG changeset patch # User Thierry Florac # Date 1537444043 -7200 # Node ID f2cf11a82a79fbcd7a68d5c1ae624f3390ede758 # Parent 7cad9017361b315126b1a8b7ce2bb5b85a2b576e Updated PyAMS plug-in declaration diff -r 7cad9017361b -r f2cf11a82a79 src/pyams_media/skin/resources/js/pyams_media.js --- a/src/pyams_media/skin/resources/js/pyams_media.js Thu Sep 20 13:42:05 2018 +0200 +++ b/src/pyams_media/skin/resources/js/pyams_media.js Thu Sep 20 13:47:23 2018 +0200 @@ -6,20 +6,26 @@ var PyAMS_media = { - initPlayer: function() { - var player = $(this); - MyAMS.dialog.registerShownCallback(PyAMS_media.initPlayerDialog, player); - var flowplayer = player.flowplayer(); - var events = player.data('ams-flowplayer-events'); - if (events) { - for (var event in events) { - if (!events.hasOwnProperty(event)) { - continue; - } - flowplayer.on(event, MyAMS.getFunctionByName(events[event])); - } - } - MyAMS.dialog.registerHideCallback(PyAMS_media.shutdownPlayerDialog, player); + initPlayer: function(element) { + MyAMS.ajax.check($.fn.flowplayer, + '/--static--/pyams_media/flowplayer/flowplayer' + MyAMS.devext + '.js', + function(first_load) { + if (first_load) { + MyAMS.dialog.registerShownCallback(PyAMS_media.initPlayerDialog, player); + MyAMS.dialog.registerHideCallback(PyAMS_media.shutdownPlayerDialog, player); + } + var player = $(element); + var flowplayer = player.flowplayer(); + var events = player.data('ams-flowplayer-events'); + if (events) { + for (var event in events) { + if (!events.hasOwnProperty(event)) { + continue; + } + flowplayer.on(event, MyAMS.getFunctionByName(events[event])); + } + } + }); }, initPlayerDialog: function() { @@ -28,12 +34,18 @@ .removeClass('modal-viewport'); }, - getPlayerTime: function(e, api) { + shutdownPlayerDialog: function() { + var dialog = $(this); + var player = $('.flowplayer', dialog).data('flowplayer'); + player.shutdown(); + }, + + getPlayerTime: function(/* e, api */) { var parent = $(this); + if (!parent.hasClass('flowplayer')) { + parent = $('.flowplayer', parent); + } var player = parent.data('flowplayer'); - if (player.playing) { - return; - } var video = player.video; if (!video.time && player.conf.flowplayer) { video = player.conf.flowplayer.video; @@ -45,10 +57,14 @@ } }, - shutdownPlayerDialog: function() { - var dialog = $(this); - var player = $('.flowplayer', dialog).data('flowplayer'); - player.shutdown(); + pausePlayer: function() { + var form = $(this); + var player = $('.flowplayer', form).data('flowplayer'); + if (player.playing) { + player.pause(); + } + PyAMS_media.getPlayerTime.call(form); + return {}; } }; globals.PyAMS_media = PyAMS_media; diff -r 7cad9017361b -r f2cf11a82a79 src/pyams_media/skin/resources/js/pyams_media.min.js --- a/src/pyams_media/skin/resources/js/pyams_media.min.js Thu Sep 20 13:42:05 2018 +0200 +++ b/src/pyams_media/skin/resources/js/pyams_media.min.js Thu Sep 20 13:47:23 2018 +0200 @@ -1,1 +1,1 @@ -!function(a,e){"use strict";var i=e.MyAMS,t={initPlayer:function(){var e=a(this);i.dialog.registerShownCallback(t.initPlayerDialog,e);var r=e.flowplayer(),o=e.data("ams-flowplayer-events");if(o)for(var l in o)o.hasOwnProperty(l)&&r.on(l,i.getFunctionByName(o[l]));i.dialog.registerHideCallback(t.shutdownPlayerDialog,e)},initPlayerDialog:function(){var e=a(this);a(".modal-viewport",e).removeAttr("style").removeClass("modal-viewport")},getPlayerTime:function(e,i){var t=a(this),r=t.data("flowplayer");if(!r.playing){var o=r.video;if(!o.time&&r.conf.flowplayer&&(o=r.conf.flowplayer.video),o&&o.time){var l=o.time,n=t.parents("form");a('INPUT[name="thumbnail_form.widgets.time"]',n).val(l)}}},shutdownPlayerDialog:function(){var e=a(this);a(".flowplayer",e).data("flowplayer").shutdown()}};e.PyAMS_media=t}(jQuery,this); +!function(a,e){"use strict";var l=e.MyAMS,r={initPlayer:function(e){l.ajax.check(a.fn.flowplayer,"/--static--/pyams_media/flowplayer/flowplayer"+l.devext+".js",function(i){i&&(l.dialog.registerShownCallback(r.initPlayerDialog,t),l.dialog.registerHideCallback(r.shutdownPlayerDialog,t));var t=a(e),o=t.flowplayer(),n=t.data("ams-flowplayer-events");if(n)for(var y in n)n.hasOwnProperty(y)&&o.on(y,l.getFunctionByName(n[y]))})},initPlayerDialog:function(){var e=a(this);a(".modal-viewport",e).removeAttr("style").removeClass("modal-viewport")},shutdownPlayerDialog:function(){var e=a(this);a(".flowplayer",e).data("flowplayer").shutdown()},getPlayerTime:function(){var e=a(this);e.hasClass("flowplayer")||(e=a(".flowplayer",e));var l=e.data("flowplayer"),r=l.video;if(!r.time&&l.conf.flowplayer&&(r=l.conf.flowplayer.video),r&&r.time){var i=r.time,t=e.parents("form");a('INPUT[name="thumbnail_form.widgets.time"]',t).val(i)}},pausePlayer:function(){var e=a(this),l=a(".flowplayer",e).data("flowplayer");return l.playing&&l.pause(),r.getPlayerTime.call(e),{}}};e.PyAMS_media=r}(jQuery,this); diff -r 7cad9017361b -r f2cf11a82a79 src/pyams_media/zmi/templates/video-preview.pt --- a/src/pyams_media/zmi/templates/video-preview.pt Thu Sep 20 13:42:05 2018 +0200 +++ b/src/pyams_media/zmi/templates/video-preview.pt Thu Sep 20 13:47:23 2018 +0200 @@ -1,10 +1,8 @@
+ data-ams-plugins="pyams_media" + data-ams-plugin-pyams_media-callback="PyAMS_media.initPlayer" + tal:attributes="data-ams-plugin-pyams_media-src tales:resource_path('pyams_media.skin:pyams_media'); + data-ams-plugin-pyams_media-css tales:resource_path('pyams_media.skin:functional_css');">