Refactoring quote style in jquery engine

This commit is contained in:
mark_story 2009-03-15 21:44:40 -04:00
parent 87d68e5029
commit eea1fa576c
2 changed files with 19 additions and 20 deletions

View file

@ -47,9 +47,9 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
**/ **/
function get($selector) { function get($selector) {
if ($selector == 'window' || $selector == 'document') { if ($selector == 'window' || $selector == 'document') {
$this->selection = "$(" . $selector .")"; $this->selection = '$(' . $selector .')';
} else { } else {
$this->selection = "$('" . $selector ."')"; $this->selection = '$("' . $selector . '")';
} }
return $this; return $this;
} }
@ -77,8 +77,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
if ($options['wrap']) { if ($options['wrap']) {
$callback = sprintf($function, $callback); $callback = sprintf($function, $callback);
} }
$out = $this->selection . ".bind('{$type}', $callback);"; return sprintf('%s.bind("%s", %s);', $this->selection, $type, $callback);
return $out;
} }
/** /**
* Create a domReady event. This is a special event in many libraries * Create a domReady event. This is a special event in many libraries

View file

@ -48,19 +48,19 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
function testSelector() { function testSelector() {
$result = $this->Jquery->get('#content'); $result = $this->Jquery->get('#content');
$this->assertEqual($result, $this->Jquery); $this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, "$('#content')"); $this->assertEqual($this->Jquery->selection, '$("#content")');
$result = $this->Jquery->get('document'); $result = $this->Jquery->get('document');
$this->assertEqual($result, $this->Jquery); $this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, "$(document)"); $this->assertEqual($this->Jquery->selection, '$(document)');
$result = $this->Jquery->get('window'); $result = $this->Jquery->get('window');
$this->assertEqual($result, $this->Jquery); $this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, "$(window)"); $this->assertEqual($this->Jquery->selection, '$(window)');
$result = $this->Jquery->get('ul'); $result = $this->Jquery->get('ul');
$this->assertEqual($result, $this->Jquery); $this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, "$('ul')"); $this->assertEqual($this->Jquery->selection, '$("ul")');
} }
/** /**
* test event binding * test event binding
@ -69,15 +69,15 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
**/ **/
function testEvent() { function testEvent() {
$result = $this->Jquery->get('#myLink')->event('click', 'doClick', array('wrap' => false)); $result = $this->Jquery->get('#myLink')->event('click', 'doClick', array('wrap' => false));
$expected = "$('#myLink').bind('click', doClick);"; $expected = '$("#myLink").bind("click", doClick);';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->get('#myLink')->event('click', '$(this).show();', array('stop' => false)); $result = $this->Jquery->get('#myLink')->event('click', '$(this).show();', array('stop' => false));
$expected = "$('#myLink').bind('click', function (event) {\$(this).show();});"; $expected = '$("#myLink").bind("click", function (event) {$(this).show();});';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->get('#myLink')->event('click', '$(this).hide();'); $result = $this->Jquery->get('#myLink')->event('click', '$(this).hide();');
$expected = "\$('#myLink').bind('click', function (event) {\$(this).hide();\nreturn false;});"; $expected = '$("#myLink").bind("click", function (event) {$(this).hide();'."\n".'return false;});';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
/** /**
@ -87,7 +87,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
**/ **/
function testDomReady() { function testDomReady() {
$result = $this->Jquery->domReady('foo.name = "bar";'); $result = $this->Jquery->domReady('foo.name = "bar";');
$expected = "\$(document).bind('ready', function (event) {foo.name = \"bar\";});"; $expected = '$(document).bind("ready", function (event) {foo.name = "bar";});';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
/** /**
@ -97,7 +97,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
**/ **/
function testEach() { function testEach() {
$result = $this->Jquery->get('#foo')->each('$(this).hide();'); $result = $this->Jquery->get('#foo')->each('$(this).hide();');
$expected = "\$('#foo').each(function () {\$(this).hide();});"; $expected = '$("#foo").each(function () {$(this).hide();});';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
/** /**
@ -107,31 +107,31 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
**/ **/
function testEffect() { function testEffect() {
$result = $this->Jquery->get('#foo')->effect('show'); $result = $this->Jquery->get('#foo')->effect('show');
$expected = "\$('#foo').show();"; $expected = '$("#foo").show();';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->effect('hide'); $result = $this->Jquery->effect('hide');
$expected = "\$('#foo').hide();"; $expected = '$("#foo").hide();';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->effect('hide', array('speed' => 'fast')); $result = $this->Jquery->effect('hide', array('speed' => 'fast'));
$expected = "\$('#foo').hide(\"fast\");"; $expected = '$("#foo").hide("fast");';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->effect('fadeIn'); $result = $this->Jquery->effect('fadeIn');
$expected = "\$('#foo').fadeIn();"; $expected = '$("#foo").fadeIn();';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->effect('fadeOut'); $result = $this->Jquery->effect('fadeOut');
$expected = "\$('#foo').fadeOut();"; $expected = '$("#foo").fadeOut();';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->effect('slideIn'); $result = $this->Jquery->effect('slideIn');
$expected = "\$('#foo').slideIn();"; $expected = '$("#foo").slideIn();';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Jquery->effect('slideOut'); $result = $this->Jquery->effect('slideOut');
$expected = "\$('#foo').slideOut();"; $expected = '$("#foo").slideOut();';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
/** /**