2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
2011-12-06 23:48:20 +04:00
|
|
|
/**
|
|
|
|
* Manages events on groups of buttons.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @class
|
|
|
|
* @param {Object} options - a dictionary of settings applied against the entire
|
|
|
|
* group of buttons
|
|
|
|
* @param {Array} options.buttons Array of buttons
|
|
|
|
* @param {Element} [options.group] Element to use as the container,
|
|
|
|
* @param {Object} options.config Object with Viewer settings ( TODO: is
|
|
|
|
* this actually used anywhere? )
|
|
|
|
* @param {Function} [options.enter] Function callback for when the mouse
|
|
|
|
* enters group
|
|
|
|
* @param {Function} [options.exit] Function callback for when mouse leaves
|
|
|
|
* the group
|
|
|
|
* @param {Function} [options.release] Function callback for when mouse is
|
|
|
|
* released
|
|
|
|
* @property {Array} buttons - An array containing the buttons themselves.
|
|
|
|
* @property {Element} element - The shared container for the buttons.
|
|
|
|
* @property {Object} config - Configurable settings for the group of buttons.
|
|
|
|
* @property {OpenSeadragon.MouseTracker} tracker - Tracks mouse events accross
|
|
|
|
* the group of buttons.
|
2011-12-06 23:48:20 +04:00
|
|
|
**/
|
|
|
|
$.ButtonGroup = function( options ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-28 17:07:56 +04:00
|
|
|
$.extend( true, this, {
|
2012-03-09 20:04:28 +04:00
|
|
|
buttons: [],
|
2012-02-28 17:07:56 +04:00
|
|
|
clickTimeThreshold: $.DEFAULT_SETTINGS.clickTimeThreshold,
|
|
|
|
clickDistThreshold: $.DEFAULT_SETTINGS.clickDistThreshold
|
|
|
|
}, options );
|
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
// copy the botton elements
|
|
|
|
var buttons = this.buttons.concat([]),
|
|
|
|
_this = this,
|
|
|
|
i;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-28 17:07:56 +04:00
|
|
|
this.element = options.group || $.makeNeutralElement( "span" );
|
2011-12-06 23:48:20 +04:00
|
|
|
this.element.style.display = "inline-block";
|
|
|
|
for ( i = 0; i < buttons.length; i++ ) {
|
2011-12-17 02:56:38 +04:00
|
|
|
this.element.appendChild( buttons[ i ].element );
|
2011-12-06 23:48:20 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-02-28 17:07:56 +04:00
|
|
|
this.tracker = new $.MouseTracker({
|
|
|
|
element: this.element,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
enterHandler: function() {
|
|
|
|
var i;
|
2011-12-06 23:48:20 +04:00
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
_this.buttons[ i ].notifyGroupEnter();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-28 17:07:56 +04:00
|
|
|
},
|
|
|
|
exitHandler: function() {
|
|
|
|
var i,
|
|
|
|
buttonDownElement = arguments.length > 2 ?
|
|
|
|
arguments[ 2 ] :
|
|
|
|
null;
|
|
|
|
if ( !buttonDownElement ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
releaseHandler: function() {
|
|
|
|
var i,
|
|
|
|
insideElementRelease = arguments.length > 3 ?
|
|
|
|
arguments[ 3 ] :
|
|
|
|
null;
|
|
|
|
if ( !insideElementRelease ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-28 17:07:56 +04:00
|
|
|
}).setTracking( true );
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.ButtonGroup.prototype = {
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* TODO: Figure out why this is used on the public API and if a more useful
|
|
|
|
* api can be created.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.ButtonGroup.prototype.emulateEnter
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
emulateEnter: function() {
|
2012-02-28 17:07:56 +04:00
|
|
|
this.tracker.enterHandler();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* TODO: Figure out why this is used on the public API and if a more useful
|
|
|
|
* api can be created.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.ButtonGroup.prototype.emulateExit
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
emulateExit: function() {
|
2012-02-28 17:07:56 +04:00
|
|
|
this.tracker.exitHandler();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|