From bd6223c952601b12dd19dcf127b098df4014336d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 14 Feb 2013 22:38:50 +0000 Subject: [PATCH] added onUpdate for sortable --- lam/lib/html.inc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lam/lib/html.inc b/lam/lib/html.inc index 4f773b87..aca1d41a 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -2755,6 +2755,8 @@ class htmlSortableList extends htmlElement { private $id = ''; /** element width */ private $elementWidth = ''; + /** on update event */ + private $onUpdate = null; /** * Constructor. @@ -2792,9 +2794,19 @@ class htmlSortableList extends htmlElement { echo ''; } echo ''; + $onUpdate = ''; + if ($this->onUpdate != null) { + $onUpdate = '{ + update: function(event, ui) {' . $this->onUpdate . '}, + start: function(event, ui) { + var posOrig = ui.item.index(); + ui.item.data(\'posOrig\', posOrig); + } + }'; + } $scriptContent = ' jQuery(function() { - $("#' . $this->id . '").sortable(); + $("#' . $this->id . '").sortable(' . $onUpdate . '); $("#' . $this->id . '").disableSelection(); });'; $script = new htmlJavaScript($scriptContent); @@ -2802,6 +2814,17 @@ class htmlSortableList extends htmlElement { return $return; } + /** + * Sets the JS code that is executed when the element order was changed. + * The code can access the variables event and ui. See JQueryUI docs for details. + * ui.item.data('posOrig') will contain the original position of the moved element. + * + * @param String $onUpdate JS code + */ + public function setOnUpdate($onUpdate) { + $this->onUpdate = $onUpdate; + } + } ?>