]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/htmloutputter.php
Use inlineScript() instead of element() to write inline javascript
[quix0rs-gnu-social.git] / lib / htmloutputter.php
index a0066594f24acda8c41c2aec2c974e3cdb4876d9..cf93944e76afe19120c66dbddf124adcd422ebc6 100644 (file)
@@ -367,7 +367,7 @@ class HTMLOutputter extends XMLOutputter
      * output a script (almost always javascript) tag with inline
      * code.
      *
-     * @param string $code          relative or absolute script path
+     * @param string $code         code to put in the script tag
      * @param string $type         'type' attribute value of the tag
      *
      * @return void
@@ -375,11 +375,18 @@ class HTMLOutputter extends XMLOutputter
 
     function inlineScript($code, $type='text/javascript')
     {
-        $this->elementStart('script', array('type' => $type));
-        $this->raw('/*<![CDATA[*/ '); // XHTML compat for Safari
-        $this->raw($code);
-        $this->raw(' /*]]>*/'); // XHTML compat for Safari
-        $this->elementEnd('script');
+        if(Event::handle('StartInlineScriptElement', array($this,&$code,&$type))) {
+            $this->elementStart('script', array('type' => $type));
+            if($type == 'text/javascript') {
+                $this->raw('/*<![CDATA[*/ '); // XHTML compat
+            }
+            $this->raw($code);
+            if($type == 'text/javascript') {
+                $this->raw(' /*]]>*/'); // XHTML compat
+            }
+            $this->elementEnd('script');
+            Event::handle('EndInlineScriptElement', array($this,$code,$type));
+        }
     }
 
     /**
@@ -411,6 +418,27 @@ class HTMLOutputter extends XMLOutputter
         }
     }
 
+    /**
+     * output a style (almost always css) tag with inline
+     * code.
+     *
+     * @param string $code         code to put in the style tag
+     * @param string $type         'type' attribute value of the tag
+     * @param string $media        'media' attribute value of the tag
+     *
+     * @return void
+     */
+
+    function style($code, $type = 'text/css', $media = null)
+    {
+        if(Event::handle('StartStyleElement', array($this,&$code,&$type,&$media))) {
+            $this->elementStart('style', array('type' => $type, 'media' => $media));
+            $this->raw($code);
+            $this->elementEnd('style');
+            Event::handle('EndStyleElement', array($this,$code,$type,$media));
+        }
+    }
+
     /**
      * output an HTML textarea and associated elements
      *
@@ -449,13 +477,10 @@ class HTMLOutputter extends XMLOutputter
     */
     function autofocus($id)
     {
-        $this->elementStart('script', array('type' => 'text/javascript'));
-        $this->raw('/*<![CDATA[*/'.
+        $this->inlineScript(
                    ' $(document).ready(function() {'.
                    ' var el = $("#' . $id . '");'.
                    ' if (el.length) { el.focus(); }'.
-                   ' });'.
-                   ' /*]]>*/');
-        $this->elementEnd('script');
+                   ' });');
     }
 }