2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - ButtonGroup
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2013-05-14 07:32:09 +04:00
|
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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
|
2013-06-19 21:33:25 +04:00
|
|
|
* @param {Object} options - a dictionary of settings applied against the entire
|
2012-02-01 00:59:09 +04:00
|
|
|
* group of buttons
|
|
|
|
* @param {Array} options.buttons Array of buttons
|
|
|
|
* @param {Element} [options.group] Element to use as the container,
|
2013-06-19 21:33:25 +04:00
|
|
|
* @param {Object} options.config Object with Viewer settings ( TODO: is
|
2012-02-01 00:59:09 +04:00
|
|
|
* this actually used anywhere? )
|
2013-06-19 21:33:25 +04:00
|
|
|
* @param {Function} [options.enter] Function callback for when the mouse
|
2012-02-01 00:59:09 +04:00
|
|
|
* enters group
|
2013-06-19 21:33:25 +04:00
|
|
|
* @param {Function} [options.exit] Function callback for when mouse leaves
|
2012-02-01 00:59:09 +04:00
|
|
|
* the group
|
2013-06-19 21:33:25 +04:00
|
|
|
* @param {Function} [options.release] Function callback for when mouse is
|
2012-02-01 00:59:09 +04:00
|
|
|
* 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,
|
2012-04-11 01:02:24 +04:00
|
|
|
clickDistThreshold: $.DEFAULT_SETTINGS.clickDistThreshold,
|
|
|
|
labelText: ""
|
2012-02-28 17:07:56 +04:00
|
|
|
}, options );
|
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
// copy the botton elements
|
2013-06-19 21:33:25 +04:00
|
|
|
var buttons = this.buttons.concat([]),
|
2011-12-06 23:48:20 +04:00
|
|
|
_this = this,
|
|
|
|
i;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
this.element = options.element || $.makeNeutralElement( "fieldgroup" );
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
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 );
|
|
|
|
}
|
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({
|
2013-06-19 21:33:25 +04:00
|
|
|
element: this.element,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
2012-02-28 17:07:56 +04:00
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2013-10-11 04:00:15 +04:00
|
|
|
enterHandler: function ( event ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
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
|
|
|
},
|
2013-10-11 04:00:15 +04:00
|
|
|
exitHandler: function ( event ) {
|
2013-09-06 04:20:17 +04:00
|
|
|
var i;
|
2013-10-11 04:00:15 +04:00
|
|
|
if ( !event.insideElementPressed ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-10-11 04:00:15 +04:00
|
|
|
releaseHandler: function ( event ) {
|
2013-09-06 04:20:17 +04:00
|
|
|
var i;
|
2013-10-11 04:00:15 +04:00
|
|
|
if ( !event.insideElementReleased ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
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() {
|
2013-10-11 04:00:15 +04:00
|
|
|
this.tracker.enterHandler( { eventSource: this.tracker } );
|
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() {
|
2013-10-11 04:00:15 +04:00
|
|
|
this.tracker.exitHandler( { eventSource: this.tracker } );
|
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 ));
|