2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
2011-12-06 23:48:20 +04:00
|
|
|
/**
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
2011-12-06 23:48:20 +04:00
|
|
|
*
|
|
|
|
* Manages events on groups of buttons.
|
|
|
|
*
|
2011-12-07 05:26:06 +04:00
|
|
|
* options: {
|
|
|
|
* buttons: Array of buttons * required,
|
|
|
|
* group: Element to use as the container,
|
|
|
|
* config: Object with Viewer settings ( TODO: is this actually used anywhere? )
|
|
|
|
* enter: Function callback for when the mouse enters group
|
|
|
|
* exit: Function callback for when mouse leaves the group
|
|
|
|
* release: Function callback for when mouse is released
|
|
|
|
* }
|
2011-12-06 23:48:20 +04:00
|
|
|
**/
|
|
|
|
$.ButtonGroup = function( options ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.buttons = options.buttons;
|
2012-01-24 07:48:45 +04:00
|
|
|
this.element = options.group || $.makeNeutralElement( "span" );
|
2011-12-06 23:48:20 +04:00
|
|
|
this.config = options.config;
|
|
|
|
this.tracker = new $.MouseTracker(
|
|
|
|
this.element,
|
|
|
|
this.config.clickTimeThreshold,
|
|
|
|
this.config.clickDistThreshold
|
|
|
|
);
|
|
|
|
|
|
|
|
// copy the botton elements
|
|
|
|
var buttons = this.buttons.concat([]),
|
|
|
|
_this = this,
|
|
|
|
i;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.enter = options.enter || function() {
|
|
|
|
var i;
|
2012-01-24 07:48:45 +04:00
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
2011-12-06 23:48:20 +04:00
|
|
|
_this.buttons[ i ].notifyGroupEnter();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.exit = options.exit || function() {
|
|
|
|
var i,
|
2012-01-24 07:48:45 +04:00
|
|
|
buttonDownElmt = arguments.length > 2 ? arguments[ 2 ] : null;
|
2011-12-06 23:48:20 +04:00
|
|
|
if ( !buttonDownElmt ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.release = options.release || function() {
|
|
|
|
var i,
|
2012-01-24 07:48:45 +04:00
|
|
|
insideElmtRelease = arguments.length > 3 ? arguments[ 3 ] : null;
|
2011-12-06 23:48:20 +04:00
|
|
|
if ( !insideElmtRelease ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
this.tracker.setTracking( true );
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ButtonGroup.prototype = {
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
emulateEnter: function() {
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.enter();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
emulateExit: function() {
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.exit();
|
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 ));
|