Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1 from ogunden/master

Added on_update
  • Loading branch information...
commit 5cdc95afdd42bae9d977e423250725b393a51bf7 2 parents f5ce475 + 255bdfd
Adam Koprowski authored March 03, 2012
31  jquery-ui-demo.opa
@@ -9,6 +9,7 @@ module Sortable {
9 9
     { name: "Sortable"
10 10
     , pages:
11 11
         [ {name: "Default functionality", show: default_functionality }
  12
+         ,{name: "on_update"            , show: on_update_demo }
12 13
         ]
13 14
     }
14 15
 
@@ -20,9 +21,33 @@ module Sortable {
20 21
       jQueryUI.Sortable.mk_sortable(#sortable)
21 22
       jQueryUI.Sortable.disable_selection(#sortable)
22 23
     }
23  
-    <ul id=sortable onready={mk_sortable}>
24  
-      {List.init(mk_entry, 7)}
25  
-    </ul>
  24
+    <div>
  25
+      <ul id=sortable onready={mk_sortable}>
  26
+        {List.init(mk_entry, 7)}
  27
+      </ul>
  28
+    </div>
  29
+  }
  30
+
  31
+  client function on_update_demo() {
  32
+    function mk_entry(i) {
  33
+      <li id={i}><div class="alert alert-info">Item #{i}</></>
  34
+    }
  35
+    function on_update() {
  36
+      children = Dom.split(Dom.select_children(#sortable))
  37
+      l = List.map( function(d) { Dom.get_id(d) }, children)
  38
+      #sorting = "sorting is: " ^ String.concat(", ", l)
  39
+    }
  40
+    function mk_sortable(_) {
  41
+      jQueryUI.Sortable.mk_sortable(#sortable)
  42
+      jQueryUI.Sortable.disable_selection(#sortable)
  43
+      jQueryUI.Sortable.on_update(#sortable, on_update)
  44
+    }
  45
+    <div>
  46
+      <span id=sorting/>
  47
+      <ul id=sortable onready={mk_sortable}>
  48
+        {List.init(mk_entry, 7)}
  49
+      </ul>
  50
+    </div>
26 51
   }
27 52
 
28 53
 }
5  packages/jQueryUI/jQueryUI.opa
@@ -14,6 +14,11 @@ module jQueryUI {
14 14
       %%JQueryUI.disable_selection%%(elt)
15 15
     }
16 16
 
  17
+    function void on_update(dom, f) {
  18
+      elt = Dom.of_selection(dom)
  19
+      %%JQueryUI.sortable_on_update%%(elt,f)
  20
+    }
  21
+
17 22
   }
18 23
 
19 24
 }
7  packages/jQueryUI/jQueryUI/jQueryUI.js
@@ -13,3 +13,10 @@
13 13
     dom.disableSelection();
14 14
     return js_void;
15 15
 }
  16
+
  17
+##register sortable_on_update : Dom.private.element, ( -> void) -> void
  18
+##args(dom, on_update)
  19
+{
  20
+return dom.bind( "sortupdate", function(event, ui) { on_update(); } );
  21
+}
  22
+

0 notes on commit 5cdc95a

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