[Solar-svn] Revision 2871

pmjones at solarphp.com pmjones at solarphp.com
Sat Oct 13 08:46:41 CDT 2007


Solar/App/Base/Helper: "Head" wraps inline script code in a jQuery "when document is ready" call.  "JsHighlight" provides an example helper for jQuery animated highlights.



Added: trunk/Solar/App/Base/Helper/Head.php
===================================================================
--- trunk/Solar/App/Base/Helper/Head.php	                        (rev 0)
+++ trunk/Solar/App/Base/Helper/Head.php	2007-10-13 13:46:41 UTC (rev 2871)
@@ -0,0 +1,44 @@
+<?php
+/**
+ * 
+ * Helper for <head> elements, with specific additions to help jQuery scripts.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_App
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Link.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Helper for <head> elements, with specific additions to help jQuery scripts.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_App
+ * 
+ */
+class Solar_App_Base_Helper_Head extends Solar_View_Helper_Head {
+    
+    /**
+     * 
+     * Returns all inline scripts wrapped in a jQuery "$document.ready()"
+     * call.
+     * 
+     * @return string The code for all inline scripts.
+     * 
+     */
+    protected function _fetchScriptInline()
+    {
+        $code = parent::_fetchScriptInline();
+        $code = str_replace("\n", "\n{$this->_indent}", $code);
+        $code = "\$(document).ready(function() {\n{$this->_indent}$code\n});";
+        return $code;
+    }
+}

Added: trunk/Solar/App/Base/Helper/JsHighlight.php
===================================================================
--- trunk/Solar/App/Base/Helper/JsHighlight.php	                        (rev 0)
+++ trunk/Solar/App/Base/Helper/JsHighlight.php	2007-10-13 13:46:41 UTC (rev 2871)
@@ -0,0 +1,92 @@
+<?php
+/**
+ * 
+ * Helper to call jQuery for highlighting on a CSS-selected element.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_App
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Link.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Helper to call jQuery for highlighting on a CSS-selected element.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_App
+ * 
+ */
+class Solar_App_Base_Helper_JsHighlight extends Solar_View_Helper {
+    
+    /**
+     * 
+     * Constructor.
+     * 
+     * @param array $config User-defined configuration values.
+     * 
+     * @return void
+     * 
+     */
+    public function __construct($config = null)
+    {
+        parent::__construct($config);
+        $this->_setup();
+    }
+    
+    /**
+     * 
+     * Post-construction setup; adds the correct JavaScript files to the
+     * <head> section.
+     * 
+     * @return void
+     * 
+     */
+    protected function _setup()
+    {
+        $this->_view
+             ->head()
+             ->addScript('Solar/scripts/jquery/jquery.js')
+             ->addScript('Solar/scripts/jquery/color.js')
+             ->addScript('Solar/scripts/jquery/highlight.js');
+    }
+    
+    /**
+     * 
+     * Calls "highlight()" on a CSS-selected element.
+     * 
+     * @param string $sel A CSS selector string.
+     * 
+     * @param mixed $speed The number of milliseconds for the highlighting
+     * (1000ms = 1 sec), or one of these words: (slow|medium|fast).
+     * 
+     * @param string $color A color by word (e.g., "red") or RGB hex (e.g.,
+     * "#ff0000").
+     * 
+     * @param string $callback A jQuery callback to execute when the
+     * highlighting is done.
+     * 
+     * @return void
+     * 
+     */
+    public function jsHighlight($sel, $color = "yellow", $speed = "slow",
+        $easing = null, $callback = null)
+    {
+        if (is_numeric($speed)) {
+            $speed = (int) $speed;
+        } else {
+            $speed = "\"$speed\"";
+        }
+        
+        $this->_view
+             ->head()
+             ->addScriptInline("\$(\"$sel\").highlight(\"$color\", $speed, \"$easing\", $callback);");
+    }
+}
\ No newline at end of file




More information about the Solar-svn mailing list