Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed script ordering when in debug mode

  • Loading branch information...
commit 3360d9c1c300c3f7a828ff0758b8d9679e50907d 1 parent 90b84aa
Matt Curry authored
Showing with 28 additions and 15 deletions.
  1. +15 −0 tests/cases/helpers/asset.test.php
  2. +13 −15 views/helpers/asset.php
View
15 tests/cases/helpers/asset.test.php
@@ -383,4 +383,19 @@ function testLangGetFileContents() {
$content = $this->Asset->__getFileContents($asset, 'js');
$this->assertEqual('alert("Hello World");', $content);
}
+
+ function testDebugMode() {
+ Configure::write('debug', 2);
+
+ $this->View->__scripts = array ('<script type="text/javascript" src="/js/view.js"></script>',
+ '<script type="text/javascript" src="/js/layout.js"></script>'
+ );
+
+ $this->Asset->viewScriptCount = 1;
+ $scripts = $this->Asset->scripts_for_layout();
+ $expected = '<script type="text/javascript" src="/js/layout.js"></script>' . "\n\t" . '<script type="text/javascript" src="/js/view.js"></script>';
+ $this->assertEqual($scripts, $expected);
+
+ Configure::write('debug', 0);
+ }
}
View
28 views/helpers/asset.php
@@ -73,13 +73,13 @@ function scripts_for_layout($types=array('js', 'css', 'codeblock')) {
$types = array($types);
}
- if (Configure::read('debug') && $this->debug == false) {
- return join("\n\t", $this->view->__scripts);
- }
-
if (!$this->initialized) {
$this->__init();
}
+
+ if (Configure::read('debug') && $this->debug == false) {
+ return join("\n\t", $this->view->__scripts);
+ }
$scripts_for_layout = array();
foreach($this->assets as $asset) {
@@ -105,29 +105,27 @@ function scripts_for_layout($types=array('js', 'css', 'codeblock')) {
}
function __init() {
- $this->assets = array();
$this->initialized = true;
-
- if (App::import('Model', 'Js.JsLang')) {
- $this->Lang = ClassRegistry::init('Js.JsLang');
- $this->Lang->init();
- }
+ $this->assets = array();
//nothing to do
if (!$this->view->__scripts) {
return;
}
- //compatible with DebugKit
- if (!empty($this->view->viewVars['debugToolbarPanels'])) {
- $this->view->viewScriptCount += 1 + count($this->view->viewVars['debugToolbarJavascript']);
- }
-
//move the layout scripts to the front
$this->view->__scripts = array_merge(
array_slice($this->view->__scripts, $this->viewScriptCount),
array_slice($this->view->__scripts, 0, $this->viewScriptCount)
);
+ if (Configure::read('debug') && $this->debug == false) {
+ return;
+ }
+
+ if (App::import('Model', 'Js.JsLang')) {
+ $this->Lang = ClassRegistry::init('Js.JsLang');
+ $this->Lang->init();
+ }
if (Configure::read('Asset.jsPath')) {
$this->cachePaths['js'] = Configure::read('Asset.jsPath');
Please sign in to comment.
Something went wrong with that request. Please try again.