forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.selectable.js
More file actions
48 lines (46 loc) · 1.12 KB
/
grid.selectable.js
File metadata and controls
48 lines (46 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Grid Selectable
*
* Depends on:
* jquery.ui.widget.js
* jquery.ui.selectable.js
*/
(function( $ ) {
$.widget("ui.gridSelectable", {
options: {
selected: []
},
_create: function() {
var that = this,
selected = this.options.selected;
this.element.selectable({
filter: "tbody > tr",
start: function( event, ui ) {
if ( !event.metaKey ) {
$.observable( selected ).remove( 0, selected.length );
}
},
selecting: function( event, ui ) {
var item = $( ui.selecting ).data( "grid-item" );
if ( $.inArray( item, selected ) === -1 ) {
$.observable( selected ).insert( item );
}
},
unselecting: function( event, ui ) {
var item = $( ui.unselecting ).data( "grid-item" );
$.observable( selected ).remove( item );
}
});
this.element.bind( "gridrefresh", function() {
that.element.find( "tbody > tr" ).each(function() {
if ( $.inArray($(this).data("grid-item"), selected) !== -1 ) {
$( this ).addClass( "ui-selected" );
}
});
});
},
destroy: function() {
this.element.selectable( "destroy" );
}
});
}( jQuery ));