Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm having player inside a views_slideshow so when I start player I need to pause a slideshow.
so I add own preprocess function in custom module
$vars['config']['events'] = array(
'onPlay' => 'function () {$("#views_slideshow_cycle_main_front_slideshow-default").cycle("pause"); alert("onPlay");}',
'onPause' => 'function() {$("#views_slideshow_cycle_main_front_slideshow-default").cycle("resume"); alert("onPause")}',
'onComplete' => 'function() {$("#views_slideshow_cycle_main_front_slideshow-default").cycle("resume"); alert("onComplete")',
);
This code does not works in inline mode because events are passed as strings.
In none-inline mode behaviour throws error
Comment | File | Size | Author |
---|---|---|---|
#1 | 1447592-events.patch | 651 bytes | andypost |
jw-events.png | 5.58 KB | andypost |
Comments
Comment #1
andypostThis cause by that setup happens before events are added to config (config contains event handlers as strings not functions)
Patch suggests to add event handlers to config and then call to setup player
Comment #2
rickvug CreditAttribution: rickvug commentedMy javascript isn't any good so I'll trust your judgment on this one. I did test to confirm that that player is loading and working fine after the patch is applied. Committed, thanks!
Comment #4
julianmancera CreditAttribution: julianmancera commentedHi Andy,
Would you mind to post the module code function , I'm not sure how to send the variables to the Drupal behaviour.
Thank you
Julian
Comment #5
julianmancera CreditAttribution: julianmancera commentedNevermind this is the preprocess function you should use for sending the events
Julian Mancera
Comment #6
El Alemaño CreditAttribution: El Alemaño commentedI try to use this function but i am getting an error, because events are passed as strings.
How can i do that? I already use the patch for jw_player.js...
Comment #7
mysticbovine CreditAttribution: mysticbovine commentedWhen I use the following:
I get the following outputted. And it causes an error:
What am I doing wrong?
Thanks
Comment #8
pbuyle CreditAttribution: pbuyle commentedIMHO, there is no changes needed in the JW Player module. The patch in #1 uses JavaScript
eval()
of inline code in order to allow JavaScript callbacks to be written in PHP strings. Writing inline JavaScript in PHP string is ugly and error prone, it should be avoided. But the proposed patch actually encourage it. eval() is also incompatible with strict and secure JavaScript, as enforceable using the Content Security Policy HTTP header.The proper solution would be to include an additional JavaScript file that uses the JW Player JavaScript API on the page containing the view. If the file is added by a theme, it will be included after the
jwplayer.js
andjw_player.js
files. If the file is included by a module, a weight should be set in order to ensure proper ordering of the.js
files.Something like this should do for the additional JavaScript files.
Comment #9
pbuyle CreditAttribution: pbuyle commentedI'm closing this a 'work as designed' for the reasons explained in #8 (ie. JavaScript code belongs in .js file, not in PHP).