Added feature #11819: Added inline Javascript rendering type for TYPO3AJAX
authorJeff Segars <jsegars@alumni.rice.edu>
Wed, 16 Sep 2009 14:33:09 +0000 (14:33 +0000)
committerJeff Segars <jsegars@alumni.rice.edu>
Wed, 16 Sep 2009 14:33:09 +0000 (14:33 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5945 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/classes/class.typo3ajax.php

index e513e72..2059af2 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-09-16  Jeff Segars  <jeff@webempoweredchurch.org>
+
+       * Added feature #11819: Added inline Javascript rendering type for TYPO3AJAX
+
 2009-09-16  Rupert Germann  <rupi@gmx.li>
 
        * Fixed bug #11905: Extension Manager is not translatable (part 3) (thanks to Christopher Stelmaszyk)
index 9ce2eed..1414567 100644 (file)
@@ -142,7 +142,7 @@ class TYPO3AJAX {
         * @return      void
         */
        public function setContentFormat($format) {
-               if (t3lib_div::inArray(array('plain', 'xml', 'json', 'jsonhead', 'jsonbody'), $format)) {
+               if (t3lib_div::inArray(array('plain', 'xml', 'json', 'jsonhead', 'jsonbody', 'javascript'), $format)) {
                        $this->contentFormat = $format;
                }
        }
@@ -186,6 +186,9 @@ class TYPO3AJAX {
                        case 'json':
                                $this->renderAsJSON();
                                break;
+                       case 'javascript':
+                               $this->renderAsJavascript();
+                               break;
                        case 'xml':
                                $this->renderAsXML();
                                break;
@@ -259,6 +262,25 @@ class TYPO3AJAX {
                        echo $content;
                }
        }
+
+       /**
+        * Renders the AJAX call as inline JSON inside a script tag. This is useful
+        * when an iframe is used as the AJAX transport.
+        *
+        * @return       void
+        */
+       protected function renderAsJavascript() {
+               $content = '<script type="text/javascript">
+                                       /*<![CDATA[*/
+
+                                       response = ' . json_encode($this->content) . ';
+
+                                       /*]]>*/
+                                       </script>';
+
+               header('Content-type: text/html; charset=' . $this->charset);
+               echo $content;
+       }
 }