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

davidam’s picture

Very 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.

SebCorbin’s picture

Well 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

flowplayer_add();
drupal_add_js(drupal_get_path('module', 'flowplayer') . '/flowplayer.js');

Because flowplayer.js is only included if there are selectors sent to flowplayer_add(), preventing it from being cached on every page.

davidam’s picture

Thanks!,

For now, my problem is only with caching. I've introduced

/**
 * Implements hook_init().
 */
function flowplayer_init() {
      flowplayer_add();
      drupal_add_js(drupal_get_path('module', 'flowplayer') . '/flowplayer.js');
}

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.

SebCorbin’s picture

Hooks 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"!