summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2013-10-03 22:33:09 +0200
committerFabio Bas <ctrlaltca@gmail.com>2013-10-03 22:33:09 +0200
commitbbeb1b968f5234a62c32681c2ed9e4a7a189bd34 (patch)
tree1b4103c885fd1bfc555fb93313c1dd2c3a20a603 /framework/Web
parenta5d1b481a09c14d2e1459648efdeae4b8371ed01 (diff)
During callback, separate loading of stylesheet files and code snippets; fixes #480
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/source/prado/activecontrols/ajax3.js31
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php9
-rw-r--r--framework/Web/UI/TClientScriptManager.php20
3 files changed, 53 insertions, 7 deletions
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
index 55ef64cb..e19f5d49 100644
--- a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
@@ -176,6 +176,10 @@ Object.extend(Prado.CallbackRequest,
*/
SCRIPTLIST_HEADER : 'X-PRADO-SCRIPTLIST',
/**
+ * Stylesheet code header name.
+ */
+ STYLESHEET_HEADER : 'X-PRADO-STYLESHEET',
+ /**
* Stylesheet list header name.
*/
STYLESHEETLIST_HEADER : 'X-PRADO-STYLESHEETLIST',
@@ -431,6 +435,22 @@ Object.extend(Prado.CallbackRequest,
}
},
+ loadStyleSheetsCode : function(request, transport)
+ {
+ var self = Prado.CallbackRequest;
+ var data = request.getBodyContentPart(self.STYLESHEET_HEADER);
+ if (typeof(data) == "string" && data.length > 0)
+ {
+ json = Prado.CallbackRequest.decode(data);
+ if(typeof(json) != "object")
+ Logger.warn("Invalid stylesheet list:"+data);
+ else
+ for(var key in json)
+ if (/^\d+$/.test(key))
+ Prado.StyleSheetManager.createStyleSheetCode(json[key],null);
+ }
+ },
+
loadStyleSheetsAsync : function(request, transport)
{
var self = Prado.CallbackRequest;
@@ -520,6 +540,8 @@ Object.extend(Prado.CallbackRequest,
*/
+ this.loadStyleSheetsCode(request,transport);
+
this.loadStyleSheetsAsync(request,transport);
this.loadScripts(request,transport,callback);
@@ -1127,6 +1149,15 @@ if (typeof(Prado.AssetManagerClass)=="undefined") {
asset.href = url;
// asset.async = false; // HTML5 only
return asset;
+ },
+
+ createStyleSheetCode: function(code) {
+ var asset = document.createElement('style');
+ asset.setAttribute('type', 'text/css');
+ asset.innerText = code;
+
+ var head = document.getElementsByTagName('head')[0];
+ head.appendChild(asset);
}
});
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index d90d0997..03fe2f16 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -56,6 +56,10 @@ class TActivePageAdapter extends TControlAdapter
*/
const CALLBACK_STYLESHEETLIST_HEADER = 'X-PRADO-STYLESHEETLIST';
/**
+ * Stylesheet header name.
+ */
+ const CALLBACK_STYLESHEET_HEADER = 'X-PRADO-STYLESHEET';
+ /**
* Hidden field list header name.
*/
const CALLBACK_HIDDENFIELDLIST_HEADER = 'X-PRADO-HIDDENFIELDLIST';
@@ -212,6 +216,11 @@ class TActivePageAdapter extends TControlAdapter
if (count($stylesheets)>0)
$this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets));
+ // collect all stylesheet snippets references
+ $stylesheets = $cs->getStyleSheetCodes();
+ if (count($stylesheets)>0)
+ $this->appendContentPart($response, self::CALLBACK_STYLESHEET_HEADER, TJavaScript::jsonEncode($stylesheets));
+
// collect all script file references
$scripts = $cs->getScriptUrls();
if (count($scripts)>0)
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 0cdf3e32..ea828187 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -402,17 +402,14 @@ 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
+ * @return array List of all stylesheet urls used in the page
*/
public function getStyleSheetUrls()
{
$stylesheets = array_values(
- array_merge(
- array_map(
- create_function('$e', 'return is_array($e) ? $e[0] : $e;'),
- $this->_styleSheetFiles),
- $this->_styleSheets
- )
+ array_map(
+ create_function('$e', 'return is_array($e) ? $e[0] : $e;'),
+ $this->_styleSheetFiles)
);
foreach(Prado::getApplication()->getAssetManager()->getPublished() as $path=>$url)
@@ -425,6 +422,15 @@ class TClientScriptManager extends TApplicationComponent
}
/**
+ * Returns all the stylesheet code snippets referenced on the page
+ * @return array List of all stylesheet snippets used in the page
+ */
+ public function getStyleSheetCodes()
+ {
+ return array_unique(array_values($this->_styleSheets));
+ }
+
+ /**
* Registers a javascript file in the page head
* @param string a unique key identifying the file
* @param string URL to the javascript file