Skip to content

Commit 224d806

Browse files
Jonas von AndrianJonas von Andrian
authored andcommitted
add serialization example
smaller improvements closes johnny#44
1 parent 271cd2c commit 224d806

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- [ ] last Pointer is NaN in search valid target
55
- [ ] prevent infinite recursion
66
- [ ] bootstrap example jumps up on drop
7+
- (only sometimes. preventDefault() does not work if called inside drop or on containing element. Look up where the on handler attaches itself)
8+
- only firefox, chrome works
79
- [0/5] consider
810
- [ ] better name for searchValidTarget
911
- [ ] shortcut on getNearest()

source/_serialization.html.haml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%h2 Serialization and delay
2+
.row
3+
.span12.example
4+
%pre(lang="js")= example("serialization")
5+
.span4
6+
%ul
7+
%li
8+
Uses the default
9+
%strong serialize
10+
implementation, that reads out the
11+
%strong data attributes
12+
%p= show_code_button
13+
%h3 Serialize result
14+
%pre#serialize_output2
15+
.span4
16+
%ol.serialization.vertical
17+
= iterate(6) do |i,name|
18+
%li(data-id=i data-name=name)
19+
= name
20+
- if i == 3
21+
%ol
22+
= iterate(6) do |j, name|
23+
%li(data-id="#{i}-#{j}" data-name=name)= name
24+
.span4
25+
%ol.serialization.vertical
26+
= iterate(6,"Item") do |i,name|
27+
%li(data-id=i data-name=name)= name

source/index.html.haml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
= partial "limited_drop_targets"
137137
#bootstrap
138138
= partial "nested_bootstrap"
139+
#serialization
140+
= partial "serialization"
139141
#table
140142
= partial "table"
141143
#docs
@@ -239,4 +241,3 @@
239241

240242
Built with [Bootstrap](http://twitter.github.com/bootstrap/).
241243
Icons from [Glyphicons Free](http://glyphicons.com/).
242-
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$(function () {
2+
var group = $("ol.serialization").sortable({
3+
group: 'serialization',
4+
delay: 1000,
5+
onDrop: function (item, container, _super) {
6+
$('#serialize_output2').text(group.sortable("serialize").get().join("\n"))
7+
_super(item, container)
8+
}
9+
})
10+
})

source/js/jquery-sortable.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
* ========================================================== */
2929

30-
!function ( $, window, undefined){
30+
!function ( $, window, pluginName, undefined){
3131
var eventNames,
32-
pluginName = 'sortable',
3332
containerDefaults = {
3433
// If true, items can be dragged from this container
3534
drag: true,
@@ -101,7 +100,7 @@
101100
// Called on mousedown. If falsy value is returned, the dragging will not start.
102101
// If clicked on input element, ignore
103102
onMousedown: function ($item, _super, event) {
104-
if (event.target.nodeName != 'INPUT' && event.target.nodeName != 'SELECT') {
103+
if (!event.target.nodeName.match(/^(input|select)$/i)) {
105104
event.preventDefault()
106105
return true
107106
}
@@ -115,12 +114,11 @@
115114
pullPlaceholder: true,
116115
// Specifies serialization of the container group.
117116
// The pair $parent/$children is either container/items or item/subcontainers.
118-
// Note that this default method only works, if every item only has one subcontainer
119117
serialize: function ($parent, $children, parentIsContainer) {
120118
var result = $.extend({}, $parent.data())
121119

122120
if(parentIsContainer)
123-
return $children
121+
return [$children]
124122
else if ($children[0]){
125123
result.children = $children
126124
delete result.subContainer
@@ -407,7 +405,7 @@
407405
},
408406
scroll: function (e) {
409407
this.clearDimensions()
410-
this.clearOffsetParent()
408+
this.clearOffsetParent() // TODO is this needed?
411409
},
412410
toggleListeners: function (method, events) {
413411
var that = this
@@ -644,4 +642,4 @@
644642
});
645643
};
646644

647-
}(jQuery, window);
645+
}(jQuery, window, 'sortable');

0 commit comments

Comments
 (0)