2009-11-26 04:02:39 +01:00
|
|
|
/*
|
2010-03-11 03:29:07 +01:00
|
|
|
* jQuery UI Selectable 1.8rc3
|
2009-11-26 04:02:39 +01:00
|
|
|
*
|
2010-03-11 03:29:07 +01:00
|
|
|
* Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
|
2009-11-26 04:02:39 +01:00
|
|
|
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
|
|
|
* and GPL (GPL-LICENSE.txt) licenses.
|
2010-03-11 03:29:07 +01:00
|
|
|
*
|
2009-11-26 04:02:39 +01:00
|
|
|
* http://docs.jquery.com/UI/Selectables
|
|
|
|
*
|
|
|
|
* Depends:
|
2010-03-11 03:29:07 +01:00
|
|
|
* jquery.ui.core.js
|
|
|
|
* jquery.ui.mouse.js
|
|
|
|
* jquery.ui.widget.js
|
2009-11-26 04:02:39 +01:00
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2010-03-11 03:29:07 +01:00
|
|
|
$.widget("ui.selectable", $.ui.mouse, {
|
|
|
|
options: {
|
|
|
|
appendTo: 'body',
|
|
|
|
autoRefresh: true,
|
|
|
|
distance: 0,
|
|
|
|
filter: '*',
|
|
|
|
tolerance: 'touch'
|
|
|
|
},
|
|
|
|
_create: function() {
|
2009-11-26 04:02:39 +01:00
|
|
|
var self = this;
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
this.element.addClass("ui-selectable");
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
this.dragged = false;
|
|
|
|
|
|
|
|
// cache selectee children based on filter
|
|
|
|
var selectees;
|
|
|
|
this.refresh = function() {
|
|
|
|
selectees = $(self.options.filter, self.element[0]);
|
|
|
|
selectees.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
var pos = $this.offset();
|
|
|
|
$.data(this, "selectable-item", {
|
|
|
|
element: this,
|
|
|
|
$element: $this,
|
|
|
|
left: pos.left,
|
|
|
|
top: pos.top,
|
2010-03-11 03:29:07 +01:00
|
|
|
right: pos.left + $this.outerWidth(),
|
|
|
|
bottom: pos.top + $this.outerHeight(),
|
2009-11-26 04:02:39 +01:00
|
|
|
startselected: false,
|
|
|
|
selected: $this.hasClass('ui-selected'),
|
|
|
|
selecting: $this.hasClass('ui-selecting'),
|
|
|
|
unselecting: $this.hasClass('ui-unselecting')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
this.refresh();
|
|
|
|
|
|
|
|
this.selectees = selectees.addClass("ui-selectee");
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
this._mouseInit();
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
this.helper = $(document.createElement('div'))
|
|
|
|
.css({border:'1px dotted black'})
|
|
|
|
.addClass("ui-selectable-helper");
|
|
|
|
},
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
destroy: function() {
|
2010-03-11 03:29:07 +01:00
|
|
|
this.selectees
|
|
|
|
.removeClass("ui-selectee")
|
|
|
|
.removeData("selectable-item");
|
2009-11-26 04:02:39 +01:00
|
|
|
this.element
|
|
|
|
.removeClass("ui-selectable ui-selectable-disabled")
|
|
|
|
.removeData("selectable")
|
|
|
|
.unbind(".selectable");
|
|
|
|
this._mouseDestroy();
|
2010-03-11 03:29:07 +01:00
|
|
|
|
|
|
|
return this;
|
2009-11-26 04:02:39 +01:00
|
|
|
},
|
2010-03-11 03:29:07 +01:00
|
|
|
|
|
|
|
_mouseStart: function(event) {
|
2009-11-26 04:02:39 +01:00
|
|
|
var self = this;
|
2010-03-11 03:29:07 +01:00
|
|
|
|
|
|
|
this.opos = [event.pageX, event.pageY];
|
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
if (this.options.disabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var options = this.options;
|
|
|
|
|
|
|
|
this.selectees = $(options.filter, this.element[0]);
|
|
|
|
|
2010-03-11 03:29:07 +01:00
|
|
|
this._trigger("start", event);
|
2009-11-26 04:02:39 +01:00
|
|
|
|
2010-03-11 03:29:07 +01:00
|
|
|
$(options.appendTo).append(this.helper);
|
2009-11-26 04:02:39 +01:00
|
|
|
// position helper (lasso)
|
|
|
|
this.helper.css({
|
|
|
|
"z-index": 100,
|
|
|
|
"position": "absolute",
|
2010-03-11 03:29:07 +01:00
|
|
|
"left": event.clientX,
|
|
|
|
"top": event.clientY,
|
2009-11-26 04:02:39 +01:00
|
|
|
"width": 0,
|
|
|
|
"height": 0
|
|
|
|
});
|
|
|
|
|
|
|
|
if (options.autoRefresh) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.selectees.filter('.ui-selected').each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
selectee.startselected = true;
|
2010-03-11 03:29:07 +01:00
|
|
|
if (!event.metaKey) {
|
2009-11-26 04:02:39 +01:00
|
|
|
selectee.$element.removeClass('ui-selected');
|
|
|
|
selectee.selected = false;
|
|
|
|
selectee.$element.addClass('ui-unselecting');
|
|
|
|
selectee.unselecting = true;
|
|
|
|
// selectable UNSELECTING callback
|
2010-03-11 03:29:07 +01:00
|
|
|
self._trigger("unselecting", event, {
|
|
|
|
unselecting: selectee.element
|
|
|
|
});
|
2009-11-26 04:02:39 +01:00
|
|
|
}
|
|
|
|
});
|
2010-03-11 03:29:07 +01:00
|
|
|
|
|
|
|
$(event.target).parents().andSelf().each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
if (selectee) {
|
|
|
|
selectee.$element.removeClass("ui-unselecting").addClass('ui-selecting');
|
|
|
|
selectee.unselecting = false;
|
|
|
|
selectee.selecting = true;
|
|
|
|
selectee.selected = true;
|
|
|
|
// selectable SELECTING callback
|
|
|
|
self._trigger("selecting", event, {
|
|
|
|
selecting: selectee.element
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-26 04:02:39 +01:00
|
|
|
});
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
},
|
2010-03-11 03:29:07 +01:00
|
|
|
|
|
|
|
_mouseDrag: function(event) {
|
2009-11-26 04:02:39 +01:00
|
|
|
var self = this;
|
|
|
|
this.dragged = true;
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
if (this.options.disabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var options = this.options;
|
|
|
|
|
2010-03-11 03:29:07 +01:00
|
|
|
var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
|
2009-11-26 04:02:39 +01:00
|
|
|
if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
|
|
|
|
if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
|
|
|
|
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
|
|
|
|
|
|
|
|
this.selectees.each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
//prevent helper from being selected if appendTo: selectable
|
|
|
|
if (!selectee || selectee.element == self.element[0])
|
|
|
|
return;
|
|
|
|
var hit = false;
|
|
|
|
if (options.tolerance == 'touch') {
|
|
|
|
hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
|
|
|
|
} else if (options.tolerance == 'fit') {
|
|
|
|
hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hit) {
|
|
|
|
// SELECT
|
|
|
|
if (selectee.selected) {
|
|
|
|
selectee.$element.removeClass('ui-selected');
|
|
|
|
selectee.selected = false;
|
|
|
|
}
|
|
|
|
if (selectee.unselecting) {
|
|
|
|
selectee.$element.removeClass('ui-unselecting');
|
|
|
|
selectee.unselecting = false;
|
|
|
|
}
|
|
|
|
if (!selectee.selecting) {
|
|
|
|
selectee.$element.addClass('ui-selecting');
|
|
|
|
selectee.selecting = true;
|
|
|
|
// selectable SELECTING callback
|
2010-03-11 03:29:07 +01:00
|
|
|
self._trigger("selecting", event, {
|
|
|
|
selecting: selectee.element
|
|
|
|
});
|
2009-11-26 04:02:39 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// UNSELECT
|
|
|
|
if (selectee.selecting) {
|
2010-03-11 03:29:07 +01:00
|
|
|
if (event.metaKey && selectee.startselected) {
|
2009-11-26 04:02:39 +01:00
|
|
|
selectee.$element.removeClass('ui-selecting');
|
|
|
|
selectee.selecting = false;
|
|
|
|
selectee.$element.addClass('ui-selected');
|
|
|
|
selectee.selected = true;
|
|
|
|
} else {
|
|
|
|
selectee.$element.removeClass('ui-selecting');
|
|
|
|
selectee.selecting = false;
|
|
|
|
if (selectee.startselected) {
|
|
|
|
selectee.$element.addClass('ui-unselecting');
|
|
|
|
selectee.unselecting = true;
|
|
|
|
}
|
|
|
|
// selectable UNSELECTING callback
|
2010-03-11 03:29:07 +01:00
|
|
|
self._trigger("unselecting", event, {
|
|
|
|
unselecting: selectee.element
|
|
|
|
});
|
2009-11-26 04:02:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (selectee.selected) {
|
2010-03-11 03:29:07 +01:00
|
|
|
if (!event.metaKey && !selectee.startselected) {
|
2009-11-26 04:02:39 +01:00
|
|
|
selectee.$element.removeClass('ui-selected');
|
|
|
|
selectee.selected = false;
|
|
|
|
|
|
|
|
selectee.$element.addClass('ui-unselecting');
|
|
|
|
selectee.unselecting = true;
|
|
|
|
// selectable UNSELECTING callback
|
2010-03-11 03:29:07 +01:00
|
|
|
self._trigger("unselecting", event, {
|
|
|
|
unselecting: selectee.element
|
|
|
|
});
|
2009-11-26 04:02:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
return false;
|
|
|
|
},
|
2010-03-11 03:29:07 +01:00
|
|
|
|
|
|
|
_mouseStop: function(event) {
|
2009-11-26 04:02:39 +01:00
|
|
|
var self = this;
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
this.dragged = false;
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
var options = this.options;
|
|
|
|
|
|
|
|
$('.ui-unselecting', this.element[0]).each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
selectee.$element.removeClass('ui-unselecting');
|
|
|
|
selectee.unselecting = false;
|
|
|
|
selectee.startselected = false;
|
2010-03-11 03:29:07 +01:00
|
|
|
self._trigger("unselected", event, {
|
|
|
|
unselected: selectee.element
|
|
|
|
});
|
2009-11-26 04:02:39 +01:00
|
|
|
});
|
|
|
|
$('.ui-selecting', this.element[0]).each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
|
|
|
|
selectee.selecting = false;
|
|
|
|
selectee.selected = true;
|
|
|
|
selectee.startselected = true;
|
2010-03-11 03:29:07 +01:00
|
|
|
self._trigger("selected", event, {
|
|
|
|
selected: selectee.element
|
|
|
|
});
|
2009-11-26 04:02:39 +01:00
|
|
|
});
|
2010-03-11 03:29:07 +01:00
|
|
|
this._trigger("stop", event);
|
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
this.helper.remove();
|
2010-03-11 03:29:07 +01:00
|
|
|
|
2009-11-26 04:02:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-03-11 03:29:07 +01:00
|
|
|
|
|
|
|
});
|
2009-11-26 04:02:39 +01:00
|
|
|
|
|
|
|
$.extend($.ui.selectable, {
|
2010-03-11 03:29:07 +01:00
|
|
|
version: "1.8rc3"
|
2009-11-26 04:02:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|