]> 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 a7c596917cefc0697c64426e8efe23411bf0ea88..cf93944e76afe19120c66dbddf124adcd422ebc6 100644 (file)
@@ -363,6 +363,32 @@ class HTMLOutputter extends XMLOutputter
         }
     }
 
+    /**
+     * output a script (almost always javascript) tag with inline
+     * code.
+     *
+     * @param string $code         code to put in the script tag
+     * @param string $type         'type' attribute value of the tag
+     *
+     * @return void
+     */
+
+    function inlineScript($code, $type='text/javascript')
+    {
+        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));
+        }
+    }
+
     /**
      * output a css link
      *
@@ -392,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
      *
@@ -420,7 +467,6 @@ class HTMLOutputter extends XMLOutputter
         }
     }
 
-
     /**
     * Internal script to autofocus the given element on page onload.
     *
@@ -431,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');
+                   ' });');
     }
 }