summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
authorctrlaltca@gmail.com <>2011-07-16 09:28:55 +0000
committerctrlaltca@gmail.com <>2011-07-16 09:28:55 +0000
commitfedddfd60edb9cfe5bb5a90745ad7d8b963661ac (patch)
tree184efa20737fe468b64c77356612488c6ccab2d7 /framework/Web/UI
parent07a205ffd62910c79e09c5fd5247868c4b163ec5 (diff)
applied prado-lazyload-in-callbacks-patch (ticket #348)
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php32
-rw-r--r--framework/Web/UI/TClientScriptManager.php65
-rw-r--r--framework/Web/UI/WebControls/THtmlArea.php4
3 files changed, 100 insertions, 1 deletions
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index f8abd3ed..c5008dfe 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -3,6 +3,7 @@
* TActivePageAdapter, TCallbackErrorHandler and TInvalidCallbackException class file.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
* @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2011 PradoSoft
* @license http://www.pradosoft.com/license/
@@ -23,6 +24,7 @@ Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
* Callback request handler.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
* @version $Id$
* @package System.Web.UI.ActiveControls
* @since 3.1
@@ -45,6 +47,18 @@ class TActivePageAdapter extends TControlAdapter
* Callback page state header name.
*/
const CALLBACK_PAGESTATE_HEADER = 'X-PRADO-PAGESTATE';
+ /**
+ * Script list header name.
+ */
+ const CALLBACK_SCRIPTLIST_HEADER = 'X-PRADO-SCRIPTLIST';
+ /**
+ * Stylesheet list header name.
+ */
+ const CALLBACK_STYLESHEETLIST_HEADER = 'X-PRADO-STYLESHEETLIST';
+ /**
+ * Hidden field list header name.
+ */
+ const CALLBACK_HIDDENFIELDLIST_HEADER = 'X-PRADO-HIDDENFIELDLIST';
/**
* Callback redirect url header name.
@@ -189,6 +203,24 @@ class TActivePageAdapter extends TControlAdapter
$actions = TJavaScript::jsonEncode($executeJavascript);
$this->appendContentPart($response, self::CALLBACK_ACTION_HEADER, $actions);
//$response->appendHeader(self::CALLBACK_ACTION_HEADER.': '.$actions);
+
+
+ $cs = $this->Page->getClientScript();
+
+ // collect all stylesheet file references
+ $stylesheets = $cs->getStyleSheetUrls();
+ if (count($stylesheets)>0)
+ $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets));
+
+ // collect all script file references
+ $scripts = $cs->getScriptUrls();
+ if (count($scripts)>0)
+ $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts));
+
+ // collect all hidden field references
+ $fields = $cs->getHiddenFields();
+ if (count($fields)>0)
+ $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields));
}
/**
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index eec347eb..677daa9b 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -3,6 +3,7 @@
* TClientScriptManager and TClientSideOptions class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
* @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2011 PradoSoft
* @license http://www.pradosoft.com/license/
@@ -16,6 +17,7 @@
* TClientScriptManager manages javascript and CSS stylesheets for a page.
*
* @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
* @version $Id$
* @package System.Web.UI
* @since 3.0
@@ -107,6 +109,16 @@ class TClientScriptManager extends TApplicationComponent
|| count($this->_headScriptFiles) || count($this->_headScripts);
}
+ public static function getPradoPackages()
+ {
+ return self::$_pradoPackages;
+ }
+
+ public static function getPradoScripts()
+ {
+ return self::$_pradoScripts;
+ }
+
/**
* Registers Prado javascript by library name. See "Web/Javascripts/source/packages.php"
* for library names.
@@ -192,6 +204,37 @@ class TClientScriptManager extends TApplicationComponent
}
/**
+ * Returns the URLs of all script files referenced on the page
+ * @return array Combined list of all script urls used in the page
+ */
+ public function getScriptUrls()
+ {
+ $scripts = array();
+
+ $packages=array_keys($this->_registeredPradoScripts);
+ $base = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::SCRIPT_PATH;
+ list($path,$baseUrl)=$this->getPackagePathUrl($base);
+ foreach ($packages as $p)
+ {
+ foreach (self::$_pradoScripts[$p] as $dep)
+ {
+ foreach (self::$_pradoPackages[$dep] as $script)
+ {
+ if (!in_array($url=$baseUrl.'/'.$script,$scripts))
+ $scripts[]=$url;
+ }
+ }
+ }
+
+ $scripts = array_merge($scripts, array_values($this->_headScriptFiles));
+ $scripts = array_merge($scripts, array_values($this->_scriptFiles));
+
+ $scripts = array_unique($scripts);
+
+ return $scripts;
+ }
+
+ /**
* Publishes a javascript library path and register packages to be loaded.
* See TClientScriptLoader for component that enables users to register custom javascript libraries.
* @param string javascript library base path
@@ -424,6 +467,23 @@ class TClientScriptManager extends TApplicationComponent
}
/**
+ * Returns the URLs of all stylesheet files referenced on the page
+ * @return array Combined list of all stylesheet urls used in the page
+ */
+ public function getStyleSheetUrls()
+ {
+ $stylesheets = array_values($this->_styleSheets);
+
+ foreach(Prado::getApplication()->getAssetManager()->getPublished() as $path=>$url)
+ if (substr($url,strlen($url)-4)=='.css')
+ $stylesheets[] = $url;
+
+ $stylesheets = array_unique($stylesheets);
+
+ return $stylesheets;
+ }
+
+ /**
* Registers a javascript file in the page head
* @param string a unique key identifying the file
* @param string URL to the javascript file
@@ -714,6 +774,11 @@ class TClientScriptManager extends TApplicationComponent
$writer->write("<div style=\"visibility:hidden;\">\n".$str."</div>\n");
}
+ public function getHiddenFields()
+ {
+ return $this->_hiddenFields;
+ }
+
/**
* Checks whether page rendering has not begun yet
*/
diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php
index 2411f8f3..383411c5 100644
--- a/framework/Web/UI/WebControls/THtmlArea.php
+++ b/framework/Web/UI/WebControls/THtmlArea.php
@@ -402,6 +402,8 @@ class THtmlArea extends TTextBox
$options['debug'] = false;
$js = TJavaScript::encode($options,true,true);
$script = "if(typeof(tinyMCE_GZ)!='undefined'){ tinyMCE_GZ.init({$js}); }";
+ if ($this->getPage()->getIsCallback())
+ $script.= 'tinymce.dom.Event._pageInit();';
$scripts->registerEndScript($key, $script);
}
}
@@ -420,7 +422,7 @@ class THtmlArea extends TTextBox
{
$scripts = $this->getPage()->getClientScript();
$options = TJavaScript::encode($this->getEditorOptions(),true,true); // Force encoding of empty strings
- $script = "if(typeof(tinyMCE)!='undefined'){ tinyMCE.init($options); }";
+ $script = "if(typeof(tinyMCE)!='undefined')\r\n{ tinyMCE.init($options); }";
$scripts->registerEndScript('prado:THtmlArea'.$this->ClientID,$script);
}