mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 21:26:10 +03:00
af078f8f19
Renamed insideElementRelease to insideElementReleased.
138 lines
5.1 KiB
JavaScript
138 lines
5.1 KiB
JavaScript
/*
|
|
* OpenSeadragon - ButtonGroup
|
|
*
|
|
* Copyright (C) 2009 CodePlex Foundation
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are
|
|
* met:
|
|
*
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* - Neither the name of CodePlex Foundation nor the names of its
|
|
* contributors may be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
(function( $ ){
|
|
/**
|
|
* Manages events on groups of buttons.
|
|
* @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.
|
|
**/
|
|
$.ButtonGroup = function( options ) {
|
|
|
|
$.extend( true, this, {
|
|
buttons: [],
|
|
clickTimeThreshold: $.DEFAULT_SETTINGS.clickTimeThreshold,
|
|
clickDistThreshold: $.DEFAULT_SETTINGS.clickDistThreshold,
|
|
labelText: ""
|
|
}, options );
|
|
|
|
// copy the botton elements
|
|
var buttons = this.buttons.concat([]),
|
|
_this = this,
|
|
i;
|
|
|
|
this.element = options.element || $.makeNeutralElement( "fieldgroup" );
|
|
|
|
if( !options.group ){
|
|
this.label = $.makeNeutralElement( "label" );
|
|
//TODO: support labels for ButtonGroups
|
|
//this.label.innerHTML = this.labelText;
|
|
this.element.style.display = "inline-block";
|
|
this.element.appendChild( this.label );
|
|
for ( i = 0; i < buttons.length; i++ ) {
|
|
this.element.appendChild( buttons[ i ].element );
|
|
}
|
|
}
|
|
|
|
this.tracker = new $.MouseTracker({
|
|
element: this.element,
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
enterHandler: function ( tracker, eventData ) {
|
|
var i;
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
_this.buttons[ i ].notifyGroupEnter();
|
|
}
|
|
},
|
|
exitHandler: function ( tracker, eventData ) {
|
|
var i;
|
|
if ( !eventData.insideElementPressed ) {
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
_this.buttons[ i ].notifyGroupExit();
|
|
}
|
|
}
|
|
},
|
|
releaseHandler: function ( tracker, eventData ) {
|
|
var i;
|
|
if ( !eventData.insideElementReleased ) {
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
_this.buttons[ i ].notifyGroupExit();
|
|
}
|
|
}
|
|
}
|
|
}).setTracking( true );
|
|
};
|
|
|
|
$.ButtonGroup.prototype = {
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
emulateEnter: function() {
|
|
this.tracker.enterHandler( this.tracker, {} );
|
|
},
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
emulateExit: function() {
|
|
this.tracker.exitHandler( this.tracker, {} );
|
|
}
|
|
};
|
|
|
|
|
|
}( OpenSeadragon ));
|