~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to lib/jquery/jquery.ui-1.6rc2/ui/ui.selectable.js

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * jQuery UI Selectable @VERSION
3
 
 *
4
 
 * Copyright (c) 2008 Richard D. Worth (rdworth.org)
5
 
 * Dual licensed under the MIT (MIT-LICENSE.txt)
6
 
 * and GPL (GPL-LICENSE.txt) licenses.
7
 
 * 
8
 
 * http://docs.jquery.com/UI/Selectables
9
 
 *
10
 
 * Depends:
11
 
 *      ui.core.js
12
 
 */
13
 
(function($) {
14
 
 
15
 
$.widget("ui.selectable", $.extend({}, $.ui.mouse, {
16
 
        _init: function() {
17
 
                var self = this;
18
 
                
19
 
                this.element.addClass("ui-selectable");
20
 
                
21
 
                this.dragged = false;
22
 
 
23
 
                // cache selectee children based on filter
24
 
                var selectees;
25
 
                this.refresh = function() {
26
 
                        selectees = $(self.options.filter, self.element[0]);
27
 
                        selectees.each(function() {
28
 
                                var $this = $(this);
29
 
                                var pos = $this.offset();
30
 
                                $.data(this, "selectable-item", {
31
 
                                        element: this,
32
 
                                        $element: $this,
33
 
                                        left: pos.left,
34
 
                                        top: pos.top,
35
 
                                        right: pos.left + $this.width(),
36
 
                                        bottom: pos.top + $this.height(),
37
 
                                        startselected: false,
38
 
                                        selected: $this.hasClass('ui-selected'),
39
 
                                        selecting: $this.hasClass('ui-selecting'),
40
 
                                        unselecting: $this.hasClass('ui-unselecting')
41
 
                                });
42
 
                        });
43
 
                };
44
 
                this.refresh();
45
 
 
46
 
                this.selectees = selectees.addClass("ui-selectee");
47
 
                
48
 
                this._mouseInit();
49
 
                
50
 
                this.helper = $(document.createElement('div'))
51
 
                        .css({border:'1px dotted black'})
52
 
                        .addClass("ui-selectable-helper");
53
 
        },
54
 
        toggle: function() {
55
 
                if(this.options.disabled){
56
 
                        this.enable();
57
 
                } else {
58
 
                        this.disable();
59
 
                }
60
 
        },
61
 
        destroy: function() {
62
 
                this.element
63
 
                        .removeClass("ui-selectable ui-selectable-disabled")
64
 
                        .removeData("selectable")
65
 
                        .unbind(".selectable");
66
 
                this._mouseDestroy();
67
 
        },
68
 
        _mouseStart: function(e) {
69
 
                var self = this;
70
 
                
71
 
                this.opos = [e.pageX, e.pageY];
72
 
                
73
 
                if (this.options.disabled)
74
 
                        return;
75
 
 
76
 
                var options = this.options;
77
 
 
78
 
                this.selectees = $(options.filter, this.element[0]);
79
 
 
80
 
                // selectable START callback
81
 
                this.element.triggerHandler("selectablestart", [e, {
82
 
                        "selectable": this.element[0],
83
 
                        "options": options
84
 
                }], options.start);
85
 
 
86
 
                $('body').append(this.helper);
87
 
                // position helper (lasso)
88
 
                this.helper.css({
89
 
                        "z-index": 100,
90
 
                        "position": "absolute",
91
 
                        "left": e.clientX,
92
 
                        "top": e.clientY,
93
 
                        "width": 0,
94
 
                        "height": 0
95
 
                });
96
 
 
97
 
                if (options.autoRefresh) {
98
 
                        this.refresh();
99
 
                }
100
 
 
101
 
                this.selectees.filter('.ui-selected').each(function() {
102
 
                        var selectee = $.data(this, "selectable-item");
103
 
                        selectee.startselected = true;
104
 
                        if (!e.metaKey) {
105
 
                                selectee.$element.removeClass('ui-selected');
106
 
                                selectee.selected = false;
107
 
                                selectee.$element.addClass('ui-unselecting');
108
 
                                selectee.unselecting = true;
109
 
                                // selectable UNSELECTING callback
110
 
                                self.element.triggerHandler("selectableunselecting", [e, {
111
 
                                        selectable: self.element[0],
112
 
                                        unselecting: selectee.element,
113
 
                                        options: options
114
 
                                }], options.unselecting);
115
 
                        }
116
 
                });
117
 
                
118
 
                var isSelectee = false;
119
 
                $(e.target).parents().andSelf().each(function() {
120
 
                        if($.data(this, "selectable-item")) isSelectee = true;
121
 
                });
122
 
                return this.options.keyboard ? !isSelectee : true;
123
 
        },
124
 
        _mouseDrag: function(e) {
125
 
                var self = this;
126
 
                this.dragged = true;
127
 
                
128
 
                if (this.options.disabled)
129
 
                        return;
130
 
 
131
 
                var options = this.options;
132
 
 
133
 
                var x1 = this.opos[0], y1 = this.opos[1], x2 = e.pageX, y2 = e.pageY;
134
 
                if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
135
 
                if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
136
 
                this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
137
 
 
138
 
                this.selectees.each(function() {
139
 
                        var selectee = $.data(this, "selectable-item");
140
 
                        //prevent helper from being selected if appendTo: selectable
141
 
                        if (!selectee || selectee.element == self.element[0])
142
 
                                return;
143
 
                        var hit = false;
144
 
                        if (options.tolerance == 'touch') {
145
 
                                hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
146
 
                        } else if (options.tolerance == 'fit') {
147
 
                                hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
148
 
                        }
149
 
 
150
 
                        if (hit) {
151
 
                                // SELECT
152
 
                                if (selectee.selected) {
153
 
                                        selectee.$element.removeClass('ui-selected');
154
 
                                        selectee.selected = false;
155
 
                                }
156
 
                                if (selectee.unselecting) {
157
 
                                        selectee.$element.removeClass('ui-unselecting');
158
 
                                        selectee.unselecting = false;
159
 
                                }
160
 
                                if (!selectee.selecting) {
161
 
                                        selectee.$element.addClass('ui-selecting');
162
 
                                        selectee.selecting = true;
163
 
                                        // selectable SELECTING callback
164
 
                                        self.element.triggerHandler("selectableselecting", [e, {
165
 
                                                selectable: self.element[0],
166
 
                                                selecting: selectee.element,
167
 
                                                options: options
168
 
                                        }], options.selecting);
169
 
                                }
170
 
                        } else {
171
 
                                // UNSELECT
172
 
                                if (selectee.selecting) {
173
 
                                        if (e.metaKey && selectee.startselected) {
174
 
                                                selectee.$element.removeClass('ui-selecting');
175
 
                                                selectee.selecting = false;
176
 
                                                selectee.$element.addClass('ui-selected');
177
 
                                                selectee.selected = true;
178
 
                                        } else {
179
 
                                                selectee.$element.removeClass('ui-selecting');
180
 
                                                selectee.selecting = false;
181
 
                                                if (selectee.startselected) {
182
 
                                                        selectee.$element.addClass('ui-unselecting');
183
 
                                                        selectee.unselecting = true;
184
 
                                                }
185
 
                                                // selectable UNSELECTING callback
186
 
                                                self.element.triggerHandler("selectableunselecting", [e, {
187
 
                                                        selectable: self.element[0],
188
 
                                                        unselecting: selectee.element,
189
 
                                                        options: options
190
 
                                                }], options.unselecting);
191
 
                                        }
192
 
                                }
193
 
                                if (selectee.selected) {
194
 
                                        if (!e.metaKey && !selectee.startselected) {
195
 
                                                selectee.$element.removeClass('ui-selected');
196
 
                                                selectee.selected = false;
197
 
 
198
 
                                                selectee.$element.addClass('ui-unselecting');
199
 
                                                selectee.unselecting = true;
200
 
                                                // selectable UNSELECTING callback
201
 
                                                self.element.triggerHandler("selectableunselecting", [e, {
202
 
                                                        selectable: self.element[0],
203
 
                                                        unselecting: selectee.element,
204
 
                                                        options: options
205
 
                                                }], options.unselecting);
206
 
                                        }
207
 
                                }
208
 
                        }
209
 
                });
210
 
                
211
 
                return false;
212
 
        },
213
 
        _mouseStop: function(e) {
214
 
                var self = this;
215
 
                
216
 
                this.dragged = false;
217
 
                
218
 
                var options = this.options;
219
 
 
220
 
                $('.ui-unselecting', this.element[0]).each(function() {
221
 
                        var selectee = $.data(this, "selectable-item");
222
 
                        selectee.$element.removeClass('ui-unselecting');
223
 
                        selectee.unselecting = false;
224
 
                        selectee.startselected = false;
225
 
                        self.element.triggerHandler("selectableunselected", [e, {
226
 
                                selectable: self.element[0],
227
 
                                unselected: selectee.element,
228
 
                                options: options
229
 
                        }], options.unselected);
230
 
                });
231
 
                $('.ui-selecting', this.element[0]).each(function() {
232
 
                        var selectee = $.data(this, "selectable-item");
233
 
                        selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
234
 
                        selectee.selecting = false;
235
 
                        selectee.selected = true;
236
 
                        selectee.startselected = true;
237
 
                        self.element.triggerHandler("selectableselected", [e, {
238
 
                                selectable: self.element[0],
239
 
                                selected: selectee.element,
240
 
                                options: options
241
 
                        }], options.selected);
242
 
                });
243
 
                this.element.triggerHandler("selectablestop", [e, {
244
 
                        selectable: self.element[0],
245
 
                        options: this.options
246
 
                }], this.options.stop);
247
 
                
248
 
                this.helper.remove();
249
 
                
250
 
                return false;
251
 
        }
252
 
}));
253
 
 
254
 
$.extend($.ui.selectable, {
255
 
        defaults: {
256
 
                distance: 1,
257
 
                delay: 0,
258
 
                cancel: ":input",
259
 
                appendTo: 'body',
260
 
                autoRefresh: true,
261
 
                filter: '*',
262
 
                tolerance: 'touch'
263
 
        }
264
 
});
265
 
 
266
 
})(jQuery);