mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Adding drag and drop() methods to prototype.
Adding test for option pass through on _mapOptions(). Ensures that correctly named options do not get munged.
This commit is contained in:
parent
646cfd7a83
commit
02bb4e71f3
4 changed files with 89 additions and 2 deletions
|
@ -295,7 +295,9 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
**/
|
||||
var $selection;
|
||||
/**
|
||||
* Collection of option maps.
|
||||
* Collection of option maps. Option maps allow other helpers to use generic names for engine
|
||||
* callbacks and options. Allowing uniform code access for all engine types. Their use is optional
|
||||
* for end user use though.
|
||||
*
|
||||
* @var array
|
||||
**/
|
||||
|
|
|
@ -47,6 +47,18 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
'sort' => 'onDrag',
|
||||
'complete' => 'onDrop',
|
||||
'distance' => 'snap',
|
||||
),
|
||||
'drag' => array(
|
||||
'snapGrid' => 'snap',
|
||||
'container' => 'constraint',
|
||||
'stop' => 'onEnd',
|
||||
'start' => 'onStart',
|
||||
'drag' => 'onDrag',
|
||||
),
|
||||
'drop' => array(
|
||||
'hover' => 'onHover',
|
||||
'drop' => 'onDrop',
|
||||
'hoverClass' => 'hoverclass',
|
||||
)
|
||||
);
|
||||
/**
|
||||
|
@ -198,7 +210,46 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
$options = $this->_mapOptions('sortable', $options);
|
||||
$callbacks = array('onStart', 'change', 'onDrag', 'onDrop');
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
return 'var jsSortable = Sortable.create(' . $this->selection . ', {' . $options . '});';
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
return 'var jsSortable = Sortable.create(' . $this->selection . $options . ');';
|
||||
}
|
||||
/**
|
||||
* Create a Draggable element.
|
||||
*
|
||||
* #### Note: Requires scriptaculous to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the draggable.
|
||||
* @return string Completed draggable script.
|
||||
* @see JsHelper::draggable() for options list.
|
||||
**/
|
||||
function drag($options = array()) {
|
||||
$options = $this->_mapOptions('drag', $options);
|
||||
$callbacks = array('onStart', 'change', 'onDrag', 'onEnd');
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
return 'var jsDrag = new Draggable(' . $this->selection . $options . ');';
|
||||
}
|
||||
/**
|
||||
* Create a Droppable element.
|
||||
*
|
||||
* #### Note: Requires scriptaculous to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the droppable.
|
||||
* @return string Completed draggable script.
|
||||
* @see JsHelper::droppable() for options list.
|
||||
**/
|
||||
function drop($options = array()) {
|
||||
$options = $this->_mapOptions('drop', $options);
|
||||
$callbacks = array('onHover', 'onDrop');
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
return 'Droppables.add(' . $this->selection . $options . ');';
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -402,6 +402,9 @@ class JsBaseEngineTestCase extends CakeTestCase {
|
|||
|
||||
$result = $JsEngine->testMap(array('complete' => 'myFunc', 'type' => 'json', 'update' => '#element'));
|
||||
$this->assertEqual($result, array('success' => 'myFunc', 'dataType' => 'json', 'update' => '#element'));
|
||||
|
||||
$result = $JsEngine->testMap(array('success' => 'myFunc', 'dataType' => 'json', 'update' => '#element'));
|
||||
$this->assertEqual($result, array('success' => 'myFunc', 'dataType' => 'json', 'update' => '#element'));
|
||||
}
|
||||
/**
|
||||
* test that option parsing escapes strings and saves what is supposed to be saved.
|
||||
|
|
|
@ -225,5 +225,36 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
|||
$expected = 'var jsSortable = Sortable.create($("myList"), {onDrag:onSort, onDrop:onComplete, onStart:onStart, snap:5});';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* test drag() method
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testDrag() {
|
||||
$this->Proto->get('#element');
|
||||
$result = $this->Proto->drag(array(
|
||||
'start' => 'onStart',
|
||||
'drag' => 'onDrag',
|
||||
'stop' => 'onStop',
|
||||
'snapGrid' => array(10, 10),
|
||||
));
|
||||
$expected = 'var jsDrag = new Draggable($("element"), {onDrag:onDrag, onEnd:onStop, onStart:onStart, snap:[10,10]});';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* test drop() method
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testDrop() {
|
||||
$this->Proto->get('#element');
|
||||
$result = $this->Proto->drop(array(
|
||||
'hover' => 'onHover',
|
||||
'drop' => 'onDrop',
|
||||
'accept' => '.drag-me'
|
||||
));
|
||||
$expected = 'Droppables.add($("element"), {accept:".drag-me", onDrop:onDrop, onHover:onHover});';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue