2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Selectable @VERSION
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2012-03-08 15:53:08 +00:00
|
|
|
* Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-11-20 04:10:34 +00:00
|
|
|
*
|
2008-06-04 02:34:33 +00:00
|
|
|
* http://docs.jquery.com/UI/Selectables
|
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.ui.core.js
|
2009-12-22 19:51:24 +00:00
|
|
|
* jquery.ui.mouse.js
|
|
|
|
* jquery.ui.widget.js
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
$.widget("ui.selectable", $.ui.mouse, {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
|
|
|
appendTo: 'body',
|
|
|
|
autoRefresh: true,
|
|
|
|
distance: 0,
|
|
|
|
filter: '*',
|
|
|
|
tolerance: 'touch'
|
|
|
|
},
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2012-05-09 20:07:49 +00:00
|
|
|
var that = this;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.element.addClass("ui-selectable");
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.dragged = false;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// cache selectee children based on filter
|
|
|
|
var selectees;
|
|
|
|
this.refresh = function() {
|
2012-05-09 20:07:49 +00:00
|
|
|
selectees = $(that.options.filter, that.element[0]);
|
2011-11-16 15:52:12 +00:00
|
|
|
selectees.addClass("ui-selectee");
|
2008-06-04 02:34:33 +00:00
|
|
|
selectees.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
var pos = $this.offset();
|
|
|
|
$.data(this, "selectable-item", {
|
|
|
|
element: this,
|
|
|
|
$element: $this,
|
|
|
|
left: pos.left,
|
|
|
|
top: pos.top,
|
2009-01-16 04:06:51 +00:00
|
|
|
right: pos.left + $this.outerWidth(),
|
|
|
|
bottom: pos.top + $this.outerHeight(),
|
2008-06-04 02:34:33 +00:00
|
|
|
startselected: false,
|
|
|
|
selected: $this.hasClass('ui-selected'),
|
|
|
|
selecting: $this.hasClass('ui-selecting'),
|
|
|
|
unselecting: $this.hasClass('ui-unselecting')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
this.refresh();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.selectees = selectees.addClass("ui-selectee");
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-08-17 08:15:49 +00:00
|
|
|
this._mouseInit();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-05-13 14:40:35 +00:00
|
|
|
this.helper = $("<div class='ui-selectable-helper'></div>");
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2012-05-24 19:18:04 +00:00
|
|
|
_destroy: function() {
|
2010-01-24 20:47:06 +00:00
|
|
|
this.selectees
|
|
|
|
.removeClass("ui-selectee")
|
|
|
|
.removeData("selectable-item");
|
2008-06-04 02:34:33 +00:00
|
|
|
this.element
|
2012-05-24 19:18:04 +00:00
|
|
|
.removeClass("ui-selectable ui-selectable-disabled");
|
2008-08-17 08:15:49 +00:00
|
|
|
this._mouseDestroy();
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
_mouseStart: function(event) {
|
2012-05-09 20:07:49 +00:00
|
|
|
var that = this;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
this.opos = [event.pageX, event.pageY];
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
if (this.options.disabled)
|
|
|
|
return;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var options = this.options;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.selectees = $(options.filter, this.element[0]);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-01-03 05:52:26 +00:00
|
|
|
this._trigger("start", event);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-03-18 12:22:08 +00:00
|
|
|
$(options.appendTo).append(this.helper);
|
2008-06-04 02:34:33 +00:00
|
|
|
// position helper (lasso)
|
|
|
|
this.helper.css({
|
2008-11-14 03:00:16 +00:00
|
|
|
"left": event.clientX,
|
|
|
|
"top": event.clientY,
|
2008-06-04 02:34:33 +00:00
|
|
|
"width": 0,
|
|
|
|
"height": 0
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
if (options.autoRefresh) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.selectees.filter('.ui-selected').each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
selectee.startselected = true;
|
2011-11-22 13:31:11 +00:00
|
|
|
if (!event.metaKey && !event.ctrlKey) {
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.$element.removeClass('ui-selected');
|
|
|
|
selectee.selected = false;
|
|
|
|
selectee.$element.addClass('ui-unselecting');
|
|
|
|
selectee.unselecting = true;
|
|
|
|
// selectable UNSELECTING callback
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("unselecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselecting: selectee.element
|
2009-01-03 05:48:46 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
$(event.target).parents().andSelf().each(function() {
|
2009-01-16 04:06:51 +00:00
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
if (selectee) {
|
2011-11-22 13:31:11 +00:00
|
|
|
var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
|
2010-05-12 14:51:13 +00:00
|
|
|
selectee.$element
|
|
|
|
.removeClass(doSelect ? "ui-unselecting" : "ui-selected")
|
|
|
|
.addClass(doSelect ? "ui-selecting" : "ui-unselecting");
|
|
|
|
selectee.unselecting = !doSelect;
|
|
|
|
selectee.selecting = doSelect;
|
|
|
|
selectee.selected = doSelect;
|
2010-05-12 15:31:16 +00:00
|
|
|
// selectable (UN)SELECTING callback
|
|
|
|
if (doSelect) {
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("selecting", event, {
|
2010-05-12 15:31:16 +00:00
|
|
|
selecting: selectee.element
|
|
|
|
});
|
|
|
|
} else {
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("unselecting", event, {
|
2010-05-12 15:31:16 +00:00
|
|
|
unselecting: selectee.element
|
|
|
|
});
|
|
|
|
}
|
2009-01-16 04:06:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2009-01-16 04:06:51 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
_mouseDrag: function(event) {
|
2012-05-09 20:07:49 +00:00
|
|
|
var that = this;
|
2008-06-04 02:34:33 +00:00
|
|
|
this.dragged = true;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
if (this.options.disabled)
|
|
|
|
return;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var options = this.options;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
|
2008-06-04 02:34:33 +00: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});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.selectees.each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
//prevent helper from being selected if appendTo: selectable
|
2012-05-09 20:07:49 +00:00
|
|
|
if (!selectee || selectee.element == that.element[0])
|
2008-06-04 02:34:33 +00:00
|
|
|
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);
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
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
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("selecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
selecting: selectee.element
|
2009-01-03 05:48:46 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// UNSELECT
|
|
|
|
if (selectee.selecting) {
|
2011-11-22 13:31:11 +00:00
|
|
|
if ((event.metaKey || event.ctrlKey) && selectee.startselected) {
|
2008-06-04 02:34:33 +00: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
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("unselecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselecting: selectee.element
|
2009-01-03 05:48:46 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (selectee.selected) {
|
2011-11-22 13:31:11 +00:00
|
|
|
if (!event.metaKey && !event.ctrlKey && !selectee.startselected) {
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.$element.removeClass('ui-selected');
|
|
|
|
selectee.selected = false;
|
|
|
|
|
|
|
|
selectee.$element.addClass('ui-unselecting');
|
|
|
|
selectee.unselecting = true;
|
|
|
|
// selectable UNSELECTING callback
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("unselecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselecting: selectee.element
|
2009-01-03 05:48:46 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
return false;
|
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
_mouseStop: function(event) {
|
2012-05-09 20:07:49 +00:00
|
|
|
var that = this;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.dragged = false;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var options = this.options;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
$('.ui-unselecting', this.element[0]).each(function() {
|
|
|
|
var selectee = $.data(this, "selectable-item");
|
|
|
|
selectee.$element.removeClass('ui-unselecting');
|
|
|
|
selectee.unselecting = false;
|
|
|
|
selectee.startselected = false;
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("unselected", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselected: selectee.element
|
2009-01-03 05:48:46 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00: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;
|
2012-05-09 20:07:49 +00:00
|
|
|
that._trigger("selected", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
selected: selectee.element
|
2009-01-03 05:48:46 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2009-01-03 05:52:26 +00:00
|
|
|
this._trigger("stop", event);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.helper.remove();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
|
|
|
|
})(jQuery);
|