Allow implementation of code via the theme layer.

Comments

lkacenja’s picture

Included theme layer implementation that suports any spritely class being loaded:

/**
 * Theme function for creating a sprite.
 * @params $params array of parameters neccesary for creating an animation instnace.
 *           $params['params'] options for the plugin
 *           $params['content'] wrapper element with ID to be animated
 *           $params['class'] behavior to use ie spritely_js_behavior_sprite or spritely_js_behavior_pan
 * @returns $params['content'] the original content
 */

function spritely_theme_instance($variables) {
  if (empty($variables['params']) || empty($variables['content']) || empty($variables['class'])) {
    return;
  }
  $matches = array();
  $pattern = '/=["\'][^\']*["\']/';
  $regex = preg_match($pattern, $variables['content'], $matches);
  if (empty($matches[0])) {
    return;
  }
  $selector = '#' . str_replace(array('"', '\'', '='), array("", "", ""), $matches[0]);
  $behaviors = spritely_js_get_behaviors();
  $behavior_name = $variables['class'];
  foreach ($behaviors AS $behavior) {
    if ($behavior['behavior']['class'] == $behavior_name) {
      $instance = new stdClass();
      $instance->iid = spritely_js_behavior :: instance_count();
      $instance->behavior = $behavior_name;
      $instance->options = serialize($variables['params']);
      $instance->selector = $selector;
      include_once($behavior['path'] . '/' . $behavior['file']);
      new $behavior['behavior']['class']($instance);
    }
  }
  return $variables['content'];
}
lkacenja’s picture

Status: Active » Closed (fixed)

Unfortunately theme layer does not currently work with interface built implementations at this point. I think It's still ok to proceed and I'll try and combine them if need be later. Closing for now.