Skip to content
Permalink
Browse files

Adding optional param to remove colon on methods. Allows use inside

object literals.
  • Loading branch information...
markstory committed Apr 27, 2009
1 parent 9754926 commit e990c5ba3752188a74988c88a28073e70eff4522
Showing with 40 additions and 14 deletions.
  1. +25 −11 cake/libs/view/helpers/js.php
  2. +15 −3 cake/tests/cases/libs/view/helpers/js.test.php
@@ -77,7 +77,7 @@ class JsHelper extends AppHelper {
* @return void
**/
function __construct($settings = array()) {
$className = 'jquery';
$className = 'Jquery';
if (is_array($settings) && isset($settings[0])) {
$className = $settings[0];
} elseif (is_string($settings)) {
@@ -241,7 +241,7 @@ class JsBaseEngineHelper extends AppHelper {
*
* @var array
**/
var $bufferedMethods = array('event', 'sortable', 'drag', 'drop');
var $bufferedMethods = array('event', 'sortable', 'drag', 'drop', 'slider');
/**
* Constructor.
*
@@ -254,11 +254,16 @@ function __construct() {
* Create an alert message in Javascript
*
* @param string $message Message you want to alter.
* @param boolean $colon Whether you want a colon or not.
* @access public
* @return void
* @return string Completed alert() call.
**/
function alert($message) {
return 'alert("' . $this->escape($message) . '");';
function alert($message, $colon = true) {
$out = 'alert("' . $this->escape($message) . '")';
if ($colon) {
$out .= ';';
}
return $out;
}
/**
* Redirects to a URL
@@ -274,22 +279,31 @@ function redirect($url = null) {
* Create a confirm() message
*
* @param string $message Message you want confirmed.
* @param boolean $colon Whether you want a colon or not.
* @access public
* @return void
* @return string Completed confirm() call
**/
function confirm($message) {
return 'confirm("' . $this->escape($message) . '");';
function confirm($message, $colon = true) {
$out = 'confirm("' . $this->escape($message) . '")';
if ($colon) {
$out .= ';';
}
return $out;
}
/**
* Create a prompt() Javascript function
*
* @param string $message Message you want to prompt.
* @param string $default Default message
* @access public
* @return void
* @return string completed prompt() call
**/
function prompt($message, $default = '') {
return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");';
function prompt($message, $default = '', $colon = true) {
$out = 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '")';
if ($colon) {
$out .= ';';
}
return $out;
}
/**
* Generates a JavaScript object in JavaScript Object Notation (JSON)
@@ -106,7 +106,7 @@ function endTest() {
**/
function testConstruction() {
$js =& new JsHelper();
$this->assertEqual($js->helpers, array('Html', 'jqueryEngine'));
$this->assertEqual($js->helpers, array('Html', 'JqueryEngine'));
$js =& new JsHelper(array('mootools'));
$this->assertEqual($js->helpers, array('Html', 'mootoolsEngine'));
@@ -302,6 +302,10 @@ function testPrompt() {
$expected = 'prompt("Hey, hey you", "hi!");';
$this->assertEqual($result, $expected);
$result = $this->JsEngine->prompt('Hey, hey you', 'hi!', false);
$expected = 'prompt("Hey, hey you", "hi!")';
$this->assertEqual($result, $expected);
$result = $this->JsEngine->prompt('"Hey"', '"hi"');
$expected = 'prompt("\"Hey\"", "\"hi\"");';
$this->assertEqual($result, $expected);
@@ -318,7 +322,11 @@ function testAlert() {
$result = $this->JsEngine->alert('"Hey"');
$expected = 'alert("\"Hey\"");';
$this->assertEqual($result, $expected);
$this->assertEqual($result, $expected);
$result = $this->JsEngine->alert('Hey there', false);
$expected = 'alert("Hey there")';
$this->assertEqual($result, $expected);
}
/**
* test confirm generation
@@ -332,7 +340,11 @@ function testConfirm() {
$result = $this->JsEngine->confirm('"Are you sure?"');
$expected = 'confirm("\"Are you sure?\"");';
$this->assertEqual($result, $expected);
$this->assertEqual($result, $expected);
$result = $this->JsEngine->confirm('"Are you sure?"', false);
$expected = 'confirm("\"Are you sure?\"")';
$this->assertEqual($result, $expected);
}
/**
* test Redirect

0 comments on commit e990c5b

Please sign in to comment.
You can’t perform that action at this time.