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.
Videos that are added to the page in the body via the WYSIWYG editor load once by JW Player, then as the page is cached, load the rest of the times via the HTML5 mode. This is due to the JW Player JavaScript being added in theme preprocess.
A solution would be to move the JW Player embed code into the template so that it (and it's custom values that relate to each video) are cached with the page.
Comment | File | Size | Author |
---|---|---|---|
#13 | jw_player_add_js-1312316-13.patch | 588 bytes | jethro |
#10 | inline_player_code-1312316-10.patch | 5.46 KB | girishmuraly |
#8 | inline_player_code-1312316-8.patch | 4.22 KB | girishmuraly |
#7 | inline_player_code-1312316-7.patch | 3.45 KB | girishmuraly |
#5 | jw_player_inline_code-1312316-5.patch | 3.75 KB | rickvug |
Comments
Comment #1
jarrodirwin CreditAttribution: jarrodirwin commentedI have created a rough patch that inserts the JW Player code into the template if a inline_js variable is set.
@todo
-Create UI to set/unset the inline variable.
-Only add jwplayer.js if the page contains a video
Comment #2
jarrodirwin CreditAttribution: jarrodirwin commentedChanging to needs review
Comment #3
rickvug CreditAttribution: rickvug commented@Jarrod Thanks for the patch! I think the approach is right but there could be a few changes:
Comment #4
jarrodirwin CreditAttribution: jarrodirwin commentedAttached new patch.
-Now uses hook_init
-Variables are added to the js by looping through $variables['config']
-Removed drupal_html_id()
-Tidied up code to conform to drupal standards
As for using drupal_add_js() to insert the js, this doesn't look possible as the inline scope is only header or footer, both of which do not get cached and the same issue arises. You are meant to be able to add it to specific regions but looks like that was never implemented. See http://drupal.org/node/812388
It is a shame as that would be the cleaner way to add the inline js.
Comment #5
rickvug CreditAttribution: rickvug commented@Jarrod Thanks for the updated patch. Sorry about my delay in responding. Attached is a slightly modified version to fix a few (minor) white space and capitalisation errors. An "interdiff" is attached as well to make it easy to see the changes since last time. To finish this off I'd like to see a few things:
Aside from these clean up issues things are looking good. Depending on time I may end up taking on some of this work.
Comment #6
rickvug CreditAttribution: rickvug commentedComment #7
girishmuraly CreditAttribution: girishmuraly commentedHere's the patch applied to the latest commit
json_encode()
Comment #8
girishmuraly CreditAttribution: girishmuraly commentedI had forgotten to attach theme/jw_player.tpl.php.
Comment #9
girishmuraly CreditAttribution: girishmuraly commentedJust noticed a bug with patch #8:
If a preset plugin is being used and then later turned off at a later date, the preset would still have the settings of the disabled plugin and would continue to output their setttings to the player in the javascript.
Comment #10
girishmuraly CreditAttribution: girishmuraly commentedAttached patch with better checking of loading preset plugin settings based on only the available (module enabled) plugins.
Comment #11
rickvug CreditAttribution: rickvug commentedCommitted! Thanks Girish and Jarrod. I made a few small changes to the documentation but otherwise this is your guy's work.
The plugin issue that Girish raised in comment #9 has been split off into its own bug report: #1348518: Presets can reference plugins that are no longer available. I agree with the solution but I don't think it is appropriate to send along all variables.
Comment #13
jethro CreditAttribution: jethro commentedIt appears this issue has resurfaced in the 7.x-2.x branch of the module.
I it better to open a new issue or revive this ticket?
When a player is inserted through a wysiwyg player, like with the media module, the page is cached and subsequent page loads are missing
drupal_add_js(libraries_get_path('jwplayer') . '/jwplayer.js');
drupal_add_js(drupal_get_path('module', 'jw_player') . '/jw_player_seek.js');
The player is unable to load.
I don't see a better way than to add these in hook_init. Would it be preferable if this was a setting as not all sites may encounter this issue?
Comment #14
pbuyle CreditAttribution: pbuyle commentedWhich cache is actually causing the issue?
Instead of using
drupal_add_js()
, could#attached
be used somewhere in a cached renderable array?Comment #15
pbuyle CreditAttribution: pbuyle commentedPage cache does include the JS added with
drupal_add_js()
. So the page being cached is not the issue. Could there be some other cache involved? How is the embed code inserted in the WYSIWYG created? Is the embedding done through a filter?Comment #16
pbuyle CreditAttribution: pbuyle commentedComment #18
ron_s CreditAttribution: ron_s commentedMarking this as duplicate since the refactor theming patch removes all inline JavaScript and renders players using
#attached
andDrupal.behaviors
.Please review: https://www.drupal.org/node/2713725
Comment #19
ron_s CreditAttribution: ron_s commentedSorry, forgot to change the status.