2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Selectable @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Selectable
|
|
|
|
//>>group: Interactions
|
|
|
|
//>>description: Allows groups of elements to be selected with the mouse.
|
|
|
|
//>>docs: http://api.jqueryui.com/selectable/
|
|
|
|
//>>demos: http://jqueryui.com/selectable/
|
2015-10-21 23:08:44 +00:00
|
|
|
//>>css.structure: ../../themes/base/selectable.css
|
2014-10-30 19:55:08 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-08-24 12:58:20 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2015-07-15 02:05:54 +00:00
|
|
|
"./mouse",
|
|
|
|
"../version",
|
|
|
|
"../widget"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
return $.widget( "ui.selectable", $.ui.mouse, {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2012-12-25 17:01:09 +00:00
|
|
|
appendTo: "body",
|
2010-01-07 03:19:50 +00:00
|
|
|
autoRefresh: true,
|
|
|
|
distance: 0,
|
2012-12-25 17:01:09 +00:00
|
|
|
filter: "*",
|
2013-01-02 23:27:22 +00:00
|
|
|
tolerance: "touch",
|
|
|
|
|
2015-08-21 04:07:08 +00:00
|
|
|
// Callbacks
|
2013-01-02 23:27:22 +00:00
|
|
|
selected: null,
|
|
|
|
selecting: null,
|
|
|
|
start: null,
|
|
|
|
stop: null,
|
|
|
|
unselected: null,
|
|
|
|
unselecting: null
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2015-02-27 23:01:21 +00:00
|
|
|
var that = this;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-02-27 23:01:21 +00:00
|
|
|
this._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
|
|
|
|
2015-08-21 04:07:08 +00:00
|
|
|
// Cache selectee children based on filter
|
2008-06-04 02:34:33 +00:00
|
|
|
this.refresh = function() {
|
2015-07-01 18:45:54 +00:00
|
|
|
that.elementPos = $( that.element[ 0 ] ).offset();
|
2015-08-24 12:58:20 +00:00
|
|
|
that.selectees = $( that.options.filter, that.element[ 0 ] );
|
2015-02-27 23:01:21 +00:00
|
|
|
that._addClass( that.selectees, "ui-selectee" );
|
2015-08-24 12:58:20 +00:00
|
|
|
that.selectees.each( function() {
|
|
|
|
var $this = $( this ),
|
2015-07-01 18:45:54 +00:00
|
|
|
selecteeOffset = $this.offset(),
|
|
|
|
pos = {
|
|
|
|
left: selecteeOffset.left - that.elementPos.left,
|
|
|
|
top: selecteeOffset.top - that.elementPos.top
|
|
|
|
};
|
2015-08-24 12:58:20 +00:00
|
|
|
$.data( this, "selectable-item", {
|
2008-06-04 02:34:33 +00:00
|
|
|
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,
|
2015-08-24 12:58:20 +00:00
|
|
|
selected: $this.hasClass( "ui-selected" ),
|
|
|
|
selecting: $this.hasClass( "ui-selecting" ),
|
|
|
|
unselecting: $this.hasClass( "ui-unselecting" )
|
|
|
|
} );
|
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
};
|
|
|
|
this.refresh();
|
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
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
this.helper = $( "<div>" );
|
2015-02-27 23:01:21 +00:00
|
|
|
this._addClass( this.helper, "ui-selectable-helper" );
|
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() {
|
2015-08-24 12:58:20 +00:00
|
|
|
this.selectees.removeData( "selectable-item" );
|
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
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
_mouseStart: function( event ) {
|
2012-10-31 01:50:08 +00:00
|
|
|
var that = this,
|
|
|
|
options = this.options;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-10-16 18:43:09 +00:00
|
|
|
this.opos = [ event.pageX, event.pageY ];
|
2015-07-01 18:45:54 +00:00
|
|
|
this.elementPos = $( this.element[ 0 ] ).offset();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( this.options.disabled ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
return;
|
2012-10-31 01:50:08 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
this.selectees = $( options.filter, this.element[ 0 ] );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
this._trigger( "start", event );
|
|
|
|
|
|
|
|
$( options.appendTo ).append( this.helper );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// position helper (lasso)
|
2015-08-24 12:58:20 +00:00
|
|
|
this.helper.css( {
|
2012-12-29 03:17:50 +00:00
|
|
|
"left": event.pageX,
|
|
|
|
"top": event.pageY,
|
2008-06-04 02:34:33 +00:00
|
|
|
"width": 0,
|
|
|
|
"height": 0
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( options.autoRefresh ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
this.refresh();
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
this.selectees.filter( ".ui-selected" ).each( function() {
|
|
|
|
var selectee = $.data( this, "selectable-item" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.startselected = true;
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( !event.metaKey && !event.ctrlKey ) {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-selected" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selected = false;
|
2015-02-27 23:01:21 +00:00
|
|
|
that._addClass( selectee.$element, "ui-unselecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.unselecting = true;
|
2015-08-24 12:58:20 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// selectable UNSELECTING callback
|
2015-08-24 12:58:20 +00:00
|
|
|
that._trigger( "unselecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselecting: selectee.element
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
$( event.target ).parents().addBack().each( function() {
|
2012-10-31 01:50:08 +00:00
|
|
|
var doSelect,
|
2015-08-24 12:58:20 +00:00
|
|
|
selectee = $.data( this, "selectable-item" );
|
|
|
|
if ( selectee ) {
|
2016-03-31 02:31:17 +00:00
|
|
|
doSelect = ( !event.metaKey && !event.ctrlKey ) ||
|
|
|
|
!selectee.$element.hasClass( "ui-selected" );
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, doSelect ? "ui-unselecting" : "ui-selected" )
|
|
|
|
._addClass( selectee.$element, doSelect ? "ui-selecting" : "ui-unselecting" );
|
2010-05-12 14:51:13 +00:00
|
|
|
selectee.unselecting = !doSelect;
|
|
|
|
selectee.selecting = doSelect;
|
|
|
|
selectee.selected = doSelect;
|
2015-08-24 12:58:20 +00:00
|
|
|
|
2010-05-12 15:31:16 +00:00
|
|
|
// selectable (UN)SELECTING callback
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( doSelect ) {
|
|
|
|
that._trigger( "selecting", event, {
|
2010-05-12 15:31:16 +00:00
|
|
|
selecting: selectee.element
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2010-05-12 15:31:16 +00:00
|
|
|
} else {
|
2015-08-24 12:58:20 +00:00
|
|
|
that._trigger( "unselecting", event, {
|
2010-05-12 15:31:16 +00:00
|
|
|
unselecting: selectee.element
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2010-05-12 15:31:16 +00:00
|
|
|
}
|
2009-01-16 04:06:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-24 12:58:20 +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
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
_mouseDrag: function( event ) {
|
2012-10-31 01:50:08 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
this.dragged = true;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( this.options.disabled ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
return;
|
2012-10-31 01:50:08 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2012-10-31 01:50:08 +00:00
|
|
|
var tmp,
|
|
|
|
that = this,
|
|
|
|
options = this.options,
|
2015-08-24 12:58:20 +00:00
|
|
|
x1 = this.opos[ 0 ],
|
|
|
|
y1 = this.opos[ 1 ],
|
2012-10-31 01:50:08 +00:00
|
|
|
x2 = event.pageX,
|
|
|
|
y2 = event.pageY;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
if ( x1 > x2 ) {
|
|
|
|
tmp = x2; x2 = x1; x1 = tmp;
|
|
|
|
}
|
|
|
|
if ( y1 > y2 ) {
|
|
|
|
tmp = y2; y2 = y1; y1 = tmp;
|
|
|
|
}
|
2015-08-24 12:58:20 +00:00
|
|
|
this.helper.css( { left: x1, top: y1, width: x2 - x1, height: y2 - y1 } );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
this.selectees.each( function() {
|
|
|
|
var selectee = $.data( this, "selectable-item" ),
|
2015-07-01 18:45:54 +00:00
|
|
|
hit = false,
|
|
|
|
offset = {};
|
2012-10-31 01:50:08 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
//prevent helper from being selected if appendTo: selectable
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( !selectee || selectee.element === that.element[ 0 ] ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
return;
|
2012-10-31 01:50:08 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 18:45:54 +00:00
|
|
|
offset.left = selectee.left + that.elementPos.left;
|
|
|
|
offset.right = selectee.right + that.elementPos.left;
|
|
|
|
offset.top = selectee.top + that.elementPos.top;
|
|
|
|
offset.bottom = selectee.bottom + that.elementPos.top;
|
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( options.tolerance === "touch" ) {
|
2015-07-01 18:45:54 +00:00
|
|
|
hit = ( !( offset.left > x2 || offset.right < x1 || offset.top > y2 ||
|
|
|
|
offset.bottom < y1 ) );
|
2015-08-24 12:58:20 +00:00
|
|
|
} else if ( options.tolerance === "fit" ) {
|
2015-07-01 18:45:54 +00:00
|
|
|
hit = ( offset.left > x1 && offset.right < x2 && offset.top > y1 &&
|
|
|
|
offset.bottom < y2 );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( hit ) {
|
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// SELECT
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( selectee.selected ) {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-selected" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selected = false;
|
|
|
|
}
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( selectee.unselecting ) {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-unselecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.unselecting = false;
|
|
|
|
}
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( !selectee.selecting ) {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._addClass( selectee.$element, "ui-selecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selecting = true;
|
2015-08-24 12:58:20 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// selectable SELECTING callback
|
2015-08-24 12:58:20 +00:00
|
|
|
that._trigger( "selecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
selecting: selectee.element
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-08-24 12:58:20 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// UNSELECT
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( selectee.selecting ) {
|
|
|
|
if ( ( event.metaKey || event.ctrlKey ) && selectee.startselected ) {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-selecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selecting = false;
|
2015-02-27 23:01:21 +00:00
|
|
|
that._addClass( selectee.$element, "ui-selected" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selected = true;
|
|
|
|
} else {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-selecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selecting = false;
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( selectee.startselected ) {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._addClass( selectee.$element, "ui-unselecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.unselecting = true;
|
|
|
|
}
|
2015-08-24 12:58:20 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// selectable UNSELECTING callback
|
2015-08-24 12:58:20 +00:00
|
|
|
that._trigger( "unselecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselecting: selectee.element
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-24 12:58:20 +00:00
|
|
|
if ( selectee.selected ) {
|
|
|
|
if ( !event.metaKey && !event.ctrlKey && !selectee.startselected ) {
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-selected" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selected = false;
|
|
|
|
|
2015-02-27 23:01:21 +00:00
|
|
|
that._addClass( selectee.$element, "ui-unselecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.unselecting = true;
|
2015-08-24 12:58:20 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// selectable UNSELECTING callback
|
2015-08-24 12:58:20 +00:00
|
|
|
that._trigger( "unselecting", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselecting: selectee.element
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-24 12:58:20 +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
|
|
|
|
2015-08-24 12:58:20 +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
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
$( ".ui-unselecting", this.element[ 0 ] ).each( function() {
|
|
|
|
var selectee = $.data( this, "selectable-item" );
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-unselecting" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.unselecting = false;
|
|
|
|
selectee.startselected = false;
|
2015-08-24 12:58:20 +00:00
|
|
|
that._trigger( "unselected", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
unselected: selectee.element
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
$( ".ui-selecting", this.element[ 0 ] ).each( function() {
|
|
|
|
var selectee = $.data( this, "selectable-item" );
|
2015-02-27 23:01:21 +00:00
|
|
|
that._removeClass( selectee.$element, "ui-selecting" )
|
|
|
|
._addClass( selectee.$element, "ui-selected" );
|
2008-06-04 02:34:33 +00:00
|
|
|
selectee.selecting = false;
|
|
|
|
selectee.selected = true;
|
|
|
|
selectee.startselected = true;
|
2015-08-24 12:58:20 +00:00
|
|
|
that._trigger( "selected", event, {
|
2009-01-03 05:52:26 +00:00
|
|
|
selected: selectee.element
|
2015-08-24 12:58:20 +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
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|