Active
Project:
Flowplayer API
Version:
7.x-1.0-alpha1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Sep 2011 at 14:42 UTC
Updated:
1 Feb 2012 at 22:55 UTC
Flowplayer don't work effectively with anonymous caching or ajax.
To get this working, the module should include its javascript files for all pages, and do its work whenever settings.flowplayer exists
Also its behavior should use the context parameter to work with ajax.
I resolved all my problems by including flowplayer's JS everywhere, and get flowplayer fired only if settings.flowplayer is present.
Here's an idea :
/**
* @file
* Provides the FlowPlayer Drupal behavior.
*/
/**
* The FlowPlayer Drupal behavior that creates the set of FlowPlayer elements from settings.flowplayer.
*/
(function ($) {
Drupal.behaviors.flowplayer = {
attach: function(context, settings) {
/**
* Called when the Flowplayer is initialized.
* Had to move from Drupal.behaviors.flowplayeradmin as this is different namespace
*/
var flowplayerAdminInit = function () {
// your admin function could also be renamed to Drupal.behaviors.flowplayer.adminInit
}
// onload
if (settings.flowplayer) {
jQuery.each(settings.flowplayer, function(selector, config) {
if($(selector, context) {
// Do config things
// Create the flowplayer element on the non-processed elements.
$(selector + ':not(.flowplayer-processed)', context).addClass('flowplayer-processed').flowplayer(
{src:settings.basePath + settings.flowplayerSwf, wmode: 'transparent'}, config);
}
});
}
}
};
})(jQuery);
What do you think of that ?
Comments
Comment #1
davidam commentedVery interesting. I've this problem. Can you send a full patch? Your solution is not running for me. How can I know if settings.flowplayer is present? Where and how are you including flowplayer js?
Thanks in advance.
Comment #2
SebCorbin commentedWell that's a bit old for me now but I think I added the surrounding
if (settings.flowplayer) {to make sure they are present, and I added the context for$(selector + ':not(.flowplayer-processed)', context)Also I created a template for my video content in which I do
print theme('flowplayer', array('config' => $config, 'id' => 'video_' . $id, 'attributes' => $attr));so it works for every ajax request Views makes.About caching, I include flowpayer in every page using a hook_init() in which I do
Because flowplayer.js is only included if there are selectors sent to flowplayer_add(), preventing it from being cached on every page.
Comment #3
davidam commentedThanks!,
For now, my problem is only with caching. I've introduced
In flowplayer.module but without successfull. I've tried introduce this hook in the template.php of my theme, but it neither doesn't run.
Comment #4
SebCorbin commentedHooks don't go in template.php, they are implemented in modules :)
You shouldn't be changing other modules' files: just try to add the two lines in one of you preprocesses like yourtheme_page()
And remember: "Keep calm and clear cache"!