Skip to content
This repository
Browse code

Removing multiple param for JsBaseEngine::get() it is not needed.

Adding get() to Mootools engine
  • Loading branch information...
commit a9da171e8c326a838c1839097585d468d9a63db5 1 parent 6b00583
Mark Story authored March 15, 2009
3  cake/libs/view/helpers/jquery_engine.php
@@ -43,10 +43,9 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
43 43
  * Create javascript selector for a CSS rule
44 44
  *
45 45
  * @param string $selector The selector that is targeted
46  
- * @param boolean $multiple Whether or not the selector could target more than one element.
47 46
  * @return object instance of $this. Allows chained methods.
48 47
  **/
49  
-	function get($selector, $multiple = false) {
  48
+	function get($selector) {
50 49
 		if ($selector == 'window' || $selector == 'document') {
51 50
 			$this->selection = "$(" . $selector .")";
52 51
 		} else {
3  cake/libs/view/helpers/js.php
@@ -487,10 +487,9 @@ function getCache($clear = true) {
487 487
  * Create javascript selector for a CSS rule
488 488
  *
489 489
  * @param string $selector The selector that is targeted
490  
- * @param boolean $multiple Whether or not the selector could target more than one element.
491 490
  * @return object instance of $this. Allows chained methods.
492 491
  **/
493  
-	function get($selector, $multiple = false) {
  492
+	function get($selector) {
494 493
 		trigger_error(sprintf(__('%s does not have get() implemented', true), get_class($this)), E_USER_WARNING);
495 494
 		return $this;
496 495
 	}
14  cake/libs/view/helpers/mootools_engine.php
@@ -47,11 +47,19 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
47 47
  * Create javascript selector for a CSS rule
48 48
  *
49 49
  * @param string $selector The selector that is targeted
50  
- * @param boolean $multiple Whether or not the selector could target more than one element.
51 50
  * @return object instance of $this. Allows chained methods.
52 51
  **/
53  
-	function get($selector, $multiple = false) {
54  
-
  52
+	function get($selector) {
  53
+		if ($selector == 'window' || $selector == 'document') {
  54
+			$this->selection = "$(" . $selector .")";
  55
+			return $this;
  56
+		}
  57
+		if (preg_match('/^#[^\s.]+$/', $selector)) {
  58
+			$this->selection = "$('" . substr($selector, 1) . "')";
  59
+			return $this;
  60
+		}
  61
+		$this->selection = "$$('" . $selector ."')";
  62
+		return $this;
55 63
 	}
56 64
 /**
57 65
  * Add an event to the script cache. Operates on the currently selected elements.
28  cake/tests/cases/libs/view/helpers/mootools_engine.test.php
... ...
@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 /**
3  
- * JqueryEngineTestCase
  3
+ * MooEngineTestCase
4 4
  *
5 5
  *
6 6
  *
@@ -23,7 +23,7 @@
23 23
  */
24 24
 App::import('Helper', array('Html', 'Js', 'MootoolsEngine'));
25 25
 
26  
-class JqueryEngineHelperTestCase extends CakeTestCase {
  26
+class MooEngineHelperTestCase extends CakeTestCase {
27 27
 /**
28 28
  * startTest
29 29
  *
@@ -46,7 +46,29 @@ function endTest() {
46 46
  * @return void
47 47
  **/
48 48
 	function testSelector() {
49  
-
  49
+		$result = $this->Moo->get('#content');
  50
+		$this->assertEqual($result, $this->Moo);
  51
+		$this->assertEqual($this->Moo->selection, "$('content')");
  52
+		
  53
+		$result = $this->Moo->get('a .remove');
  54
+		$this->assertEqual($result, $this->Moo);
  55
+		$this->assertEqual($this->Moo->selection, "$$('a .remove')");
  56
+		
  57
+		$result = $this->Moo->get('document');
  58
+		$this->assertEqual($result, $this->Moo);
  59
+		$this->assertEqual($this->Moo->selection, "$(document)");
  60
+		
  61
+		$result = $this->Moo->get('window');
  62
+		$this->assertEqual($result, $this->Moo);
  63
+		$this->assertEqual($this->Moo->selection, "$(window)");
  64
+		
  65
+		$result = $this->Moo->get('ul');
  66
+		$this->assertEqual($result, $this->Moo);
  67
+		$this->assertEqual($this->Moo->selection, "$$('ul')");
  68
+		
  69
+		$result = $this->Moo->get('#some_long-id.class');
  70
+		$this->assertEqual($result, $this->Moo);
  71
+		$this->assertEqual($this->Moo->selection, "$$('#some_long-id.class')");
50 72
 	}
51 73
 /**
52 74
  * test event binding

0 notes on commit a9da171

Please sign in to comment.
Something went wrong with that request. Please try again.