Skip to content

Commit 4a660ce

Browse files
committed
moved the call to jquery.noConflict() to the head rather than when calling render() (fixed php-debugbar#127)
1 parent 1b813f5 commit 4a660ce

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/DebugBar/JavascriptRenderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,10 @@ public function renderHead()
712712
$html .= sprintf('<script type="text/javascript" src="%s"></script>' . "\n", $file);
713713
}
714714

715+
if ($this->enableJqueryNoConflict) {
716+
$html .= '<script type="text/javascript">jQuery.noConflict(true);</script>' . "\n";
717+
}
718+
715719
return $html;
716720
}
717721

@@ -803,10 +807,6 @@ protected function getJsInitializationCode()
803807
{
804808
$js = '';
805809

806-
if ($this->enableJqueryNoConflict) {
807-
$js .= "jQuery.noConflict(true);\n";
808-
}
809-
810810
if (($this->initialization & self::INITIALIZE_CONSTRUCTOR) === self::INITIALIZE_CONSTRUCTOR) {
811811
$js .= sprintf("var %s = new %s();\n", $this->variableName, $this->javascriptClass);
812812
}

tests/DebugBar/Tests/JavascriptRendererTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public function testRenderHead()
8989
{
9090
$html = $this->r->renderHead();
9191
$this->assertTag(array('tag' => 'script', 'attributes' => array('src' => '/burl/debugbar.js')), $html);
92+
$this->assertTrue(strpos($html, "jQuery.noConflict(true);") > -1);
93+
94+
$this->r->setEnableJqueryNoConflict(false);
95+
$html = $this->r->renderHead();
96+
$this->assertFalse(strpos($html, "jQuery.noConflict(true);"));
9297
}
9398

9499
public function testRenderFullInitialization()
@@ -105,8 +110,7 @@ public function testRenderConstructorOnly()
105110
$this->r->setJavascriptClass('Foobar');
106111
$this->r->setVariableName('foovar');
107112
$this->r->setAjaxHandlerClass(false);
108-
$this->r->setEnableJqueryNoConflict(true);
109-
$this->assertStringStartsWith("<script type=\"text/javascript\">\njQuery.noConflict(true);\nvar foovar = new Foobar();\nfoovar.addDataSet(", $this->r->render());
113+
$this->assertStringStartsWith("<script type=\"text/javascript\">\nvar foovar = new Foobar();\nfoovar.addDataSet(", $this->r->render());
110114
}
111115

112116
public function testJQueryNoConflictAutoDisabling()

tests/DebugBar/Tests/full_init.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script type="text/javascript">
2-
jQuery.noConflict(true);
32
var phpdebugbar = new PhpDebugBar.DebugBar();
43
phpdebugbar.addTab("messages", new PhpDebugBar.DebugBar.Tab({"icon":"list-alt","title":"Messages", "widget": new PhpDebugBar.Widgets.MessagesWidget()}));
54
phpdebugbar.addIndicator("time", new PhpDebugBar.DebugBar.Indicator({"icon":"time"}), "right");

0 commit comments

Comments
 (0)