2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - Button
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2023-05-26 00:52:20 +03:00
|
|
|
* Copyright (C) 2010-2023 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( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2013-11-22 00:19:07 +04:00
|
|
|
* An enumeration of button states
|
2013-11-16 10:19:53 +04:00
|
|
|
* @member ButtonState
|
|
|
|
* @memberof OpenSeadragon
|
2012-01-25 23:14:02 +04:00
|
|
|
* @static
|
2013-11-22 00:19:07 +04:00
|
|
|
* @type {Object}
|
|
|
|
* @property {Number} REST
|
|
|
|
* @property {Number} GROUP
|
|
|
|
* @property {Number} HOVER
|
|
|
|
* @property {Number} DOWN
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
$.ButtonState = {
|
|
|
|
REST: 0,
|
|
|
|
GROUP: 1,
|
|
|
|
HOVER: 2,
|
|
|
|
DOWN: 3
|
|
|
|
};
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2013-11-25 20:48:44 +04:00
|
|
|
* @class Button
|
|
|
|
* @classdesc Manages events, hover states for individual buttons, tool-tips, as well
|
2013-11-25 22:38:50 +04:00
|
|
|
* as fading the buttons out when the user has not interacted with them
|
2012-01-25 23:14:02 +04:00
|
|
|
* for a specified period.
|
2013-11-25 20:48:44 +04:00
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @memberof OpenSeadragon
|
2013-09-25 00:36:13 +04:00
|
|
|
* @extends OpenSeadragon.EventSource
|
2012-01-25 23:14:02 +04:00
|
|
|
* @param {Object} options
|
2017-02-02 09:24:16 +03:00
|
|
|
* @param {Element} [options.element=null] Element to use as the button. If not specified, an HTML <div> element is created.
|
2013-11-25 20:48:44 +04:00
|
|
|
* @param {String} [options.tooltip=null] Provides context help for the button when the
|
2012-02-01 00:59:09 +04:00
|
|
|
* user hovers over it.
|
2013-11-25 20:48:44 +04:00
|
|
|
* @param {String} [options.srcRest=null] URL of image to use in 'rest' state.
|
|
|
|
* @param {String} [options.srcGroup=null] URL of image to use in 'up' state.
|
|
|
|
* @param {String} [options.srcHover=null] URL of image to use in 'hover' state.
|
|
|
|
* @param {String} [options.srcDown=null] URL of image to use in 'down' state.
|
|
|
|
* @param {Number} [options.fadeDelay=0] How long to wait before fading.
|
|
|
|
* @param {Number} [options.fadeLength=2000] How long should it take to fade the button.
|
|
|
|
* @param {OpenSeadragon.EventHandler} [options.onPress=null] Event handler callback for {@link OpenSeadragon.Button.event:press}.
|
|
|
|
* @param {OpenSeadragon.EventHandler} [options.onRelease=null] Event handler callback for {@link OpenSeadragon.Button.event:release}.
|
|
|
|
* @param {OpenSeadragon.EventHandler} [options.onClick=null] Event handler callback for {@link OpenSeadragon.Button.event:click}.
|
|
|
|
* @param {OpenSeadragon.EventHandler} [options.onEnter=null] Event handler callback for {@link OpenSeadragon.Button.event:enter}.
|
|
|
|
* @param {OpenSeadragon.EventHandler} [options.onExit=null] Event handler callback for {@link OpenSeadragon.Button.event:exit}.
|
|
|
|
* @param {OpenSeadragon.EventHandler} [options.onFocus=null] Event handler callback for {@link OpenSeadragon.Button.event:focus}.
|
|
|
|
* @param {OpenSeadragon.EventHandler} [options.onBlur=null] Event handler callback for {@link OpenSeadragon.Button.event:blur}.
|
2020-07-25 06:05:39 +03:00
|
|
|
* @param {Object} [options.userData=null] Arbitrary object to be passed unchanged to any attached handler methods.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-15 02:40:22 +04:00
|
|
|
$.Button = function( options ) {
|
|
|
|
|
2011-12-20 16:39:02 +04:00
|
|
|
var _this = this;
|
|
|
|
|
2013-09-25 00:36:13 +04:00
|
|
|
$.EventSource.call( this );
|
2011-12-15 03:22:02 +04:00
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
$.extend( true, this, {
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
tooltip: null,
|
|
|
|
srcRest: null,
|
|
|
|
srcGroup: null,
|
|
|
|
srcHover: null,
|
|
|
|
srcDown: null,
|
|
|
|
clickTimeThreshold: $.DEFAULT_SETTINGS.clickTimeThreshold,
|
|
|
|
clickDistThreshold: $.DEFAULT_SETTINGS.clickDistThreshold,
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* How long to wait before fading.
|
|
|
|
* @member {Number} fadeDelay
|
|
|
|
* @memberof OpenSeadragon.Button#
|
|
|
|
*/
|
2013-06-19 21:33:25 +04:00
|
|
|
fadeDelay: 0,
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* How long should it take to fade the button.
|
|
|
|
* @member {Number} fadeLength
|
|
|
|
* @memberof OpenSeadragon.Button#
|
|
|
|
*/
|
2012-02-28 03:29:00 +04:00
|
|
|
fadeLength: 2000,
|
|
|
|
onPress: null,
|
|
|
|
onRelease: null,
|
|
|
|
onClick: null,
|
|
|
|
onEnter: null,
|
2012-03-16 19:36:28 +04:00
|
|
|
onExit: null,
|
|
|
|
onFocus: null,
|
2020-07-25 06:05:39 +03:00
|
|
|
onBlur: null,
|
|
|
|
userData: null
|
2012-02-28 03:29:00 +04:00
|
|
|
|
|
|
|
}, options );
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* The button element.
|
|
|
|
* @member {Element} element
|
|
|
|
* @memberof OpenSeadragon.Button#
|
|
|
|
*/
|
2017-01-08 17:52:57 +03:00
|
|
|
this.element = options.element || $.makeNeutralElement("div");
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
//if the user has specified the element to bind the control to explicitly
|
|
|
|
//then do not add the default control images
|
2014-04-05 00:14:32 +04:00
|
|
|
if ( !options.element ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
this.imgRest = $.makeTransparentImage( this.srcRest );
|
|
|
|
this.imgGroup = $.makeTransparentImage( this.srcGroup );
|
|
|
|
this.imgHover = $.makeTransparentImage( this.srcHover );
|
|
|
|
this.imgDown = $.makeTransparentImage( this.srcDown );
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2014-04-05 00:14:32 +04:00
|
|
|
this.imgRest.alt =
|
|
|
|
this.imgGroup.alt =
|
|
|
|
this.imgHover.alt =
|
|
|
|
this.imgDown.alt =
|
|
|
|
this.tooltip;
|
|
|
|
|
2020-08-13 07:22:48 +03:00
|
|
|
// Allow pointer events to pass through the img elements so implicit
|
|
|
|
// pointer capture works on touch devices
|
|
|
|
$.setElementPointerEventsNone( this.imgRest );
|
|
|
|
$.setElementPointerEventsNone( this.imgGroup );
|
|
|
|
$.setElementPointerEventsNone( this.imgHover );
|
|
|
|
$.setElementPointerEventsNone( this.imgDown );
|
|
|
|
|
2014-04-05 00:14:32 +04:00
|
|
|
this.element.style.position = "relative";
|
2014-08-06 03:57:54 +04:00
|
|
|
$.setElementTouchActionNone( this.element );
|
2012-04-11 01:02:24 +04:00
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
this.imgGroup.style.position =
|
|
|
|
this.imgHover.style.position =
|
|
|
|
this.imgDown.style.position =
|
2012-04-11 01:02:24 +04:00
|
|
|
"absolute";
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
this.imgGroup.style.top =
|
|
|
|
this.imgHover.style.top =
|
|
|
|
this.imgDown.style.top =
|
2012-04-11 01:02:24 +04:00
|
|
|
"0px";
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
this.imgGroup.style.left =
|
|
|
|
this.imgHover.style.left =
|
|
|
|
this.imgDown.style.left =
|
2012-04-11 01:02:24 +04:00
|
|
|
"0px";
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
this.imgHover.style.visibility =
|
|
|
|
this.imgDown.style.visibility =
|
2012-04-11 01:02:24 +04:00
|
|
|
"hidden";
|
|
|
|
|
2020-06-26 02:01:14 +03:00
|
|
|
if ($.Browser.vendor === $.BROWSERS.FIREFOX && $.Browser.version < 3) {
|
2013-06-19 21:33:25 +04:00
|
|
|
this.imgGroup.style.top =
|
|
|
|
this.imgHover.style.top =
|
|
|
|
this.imgDown.style.top =
|
2012-04-11 01:02:24 +04:00
|
|
|
"";
|
|
|
|
}
|
2013-12-07 04:24:52 +04:00
|
|
|
|
2014-04-05 00:14:32 +04:00
|
|
|
this.element.appendChild( this.imgRest );
|
|
|
|
this.element.appendChild( this.imgGroup );
|
|
|
|
this.element.appendChild( this.imgHover );
|
|
|
|
this.element.appendChild( this.imgDown );
|
2012-04-11 01:02:24 +04:00
|
|
|
}
|
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
|
2017-01-08 17:52:57 +03:00
|
|
|
this.addHandler("press", this.onPress);
|
|
|
|
this.addHandler("release", this.onRelease);
|
|
|
|
this.addHandler("click", this.onClick);
|
|
|
|
this.addHandler("enter", this.onEnter);
|
|
|
|
this.addHandler("exit", this.onExit);
|
|
|
|
this.addHandler("focus", this.onFocus);
|
|
|
|
this.addHandler("blur", this.onBlur);
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* The button's current state.
|
|
|
|
* @member {OpenSeadragon.ButtonState} currentState
|
|
|
|
* @memberof OpenSeadragon.Button#
|
|
|
|
*/
|
2011-12-17 03:29:16 +04:00
|
|
|
this.currentState = $.ButtonState.GROUP;
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2013-11-25 20:48:44 +04:00
|
|
|
// When the button last began to fade.
|
2011-12-17 03:29:16 +04:00
|
|
|
this.fadeBeginTime = null;
|
2013-11-25 20:48:44 +04:00
|
|
|
// Whether this button should fade after user stops interacting with the viewport.
|
2011-12-17 03:29:16 +04:00
|
|
|
this.shouldFade = false;
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
this.element.style.display = "inline-block";
|
2011-12-17 02:56:38 +04:00
|
|
|
this.element.style.position = "relative";
|
2011-12-17 03:29:16 +04:00
|
|
|
this.element.title = this.tooltip;
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* Tracks mouse/touch/key events on the button.
|
|
|
|
* @member {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* @memberof OpenSeadragon.Button#
|
|
|
|
*/
|
2012-02-28 03:29:00 +04:00
|
|
|
this.tracker = new $.MouseTracker({
|
|
|
|
|
2020-07-25 06:05:39 +03:00
|
|
|
userData: 'Button.tracker',
|
2013-06-19 21:33:25 +04:00
|
|
|
element: this.element,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
2012-02-28 03:29:00 +04:00
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
enterHandler: function( event ) {
|
|
|
|
if ( event.insideElementPressed ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
inTo( _this, $.ButtonState.DOWN );
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-19 22:08:04 +04:00
|
|
|
* Raised when the cursor enters the Button element.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event enter
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "enter", { originalEvent: event.originalEvent } );
|
2013-10-11 04:00:15 +04:00
|
|
|
} else if ( !event.buttonDownAny ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
inTo( _this, $.ButtonState.HOVER );
|
|
|
|
}
|
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
focusHandler: function ( event ) {
|
2020-07-25 06:05:39 +03:00
|
|
|
_this.tracker.enterHandler( event );
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-19 22:08:04 +04:00
|
|
|
* Raised when the Button element receives focus.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event focus
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "focus", { originalEvent: event.originalEvent } );
|
2012-03-16 19:36:28 +04:00
|
|
|
},
|
|
|
|
|
2020-07-25 06:05:39 +03:00
|
|
|
leaveHandler: function( event ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
outTo( _this, $.ButtonState.GROUP );
|
2013-10-11 04:00:15 +04:00
|
|
|
if ( event.insideElementPressed ) {
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-19 22:08:04 +04:00
|
|
|
* Raised when the cursor leaves the Button element.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event exit
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "exit", { originalEvent: event.originalEvent } );
|
2011-12-20 16:39:02 +04:00
|
|
|
}
|
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
blurHandler: function ( event ) {
|
2020-07-25 06:05:39 +03:00
|
|
|
_this.tracker.leaveHandler( event );
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-19 22:08:04 +04:00
|
|
|
* Raised when the Button element loses focus.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event blur
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "blur", { originalEvent: event.originalEvent } );
|
2012-03-16 19:36:28 +04:00
|
|
|
},
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
pressHandler: function ( event ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
inTo( _this, $.ButtonState.DOWN );
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-19 22:08:04 +04:00
|
|
|
* Raised when a mouse button is pressed or touch occurs in the Button element.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event press
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "press", { originalEvent: event.originalEvent } );
|
2011-12-20 16:39:02 +04:00
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
releaseHandler: function( event ) {
|
|
|
|
if ( event.insideElementPressed && event.insideElementReleased ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
outTo( _this, $.ButtonState.HOVER );
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-19 22:08:04 +04:00
|
|
|
* Raised when the mouse button is released or touch ends in the Button element.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event release
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "release", { originalEvent: event.originalEvent } );
|
2013-10-11 04:00:15 +04:00
|
|
|
} else if ( event.insideElementPressed ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
outTo( _this, $.ButtonState.GROUP );
|
|
|
|
} else {
|
|
|
|
inTo( _this, $.ButtonState.HOVER );
|
|
|
|
}
|
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
clickHandler: function( event ) {
|
|
|
|
if ( event.quick ) {
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
2013-11-19 23:20:45 +04:00
|
|
|
* Raised when a mouse button is pressed and released or touch is initiated and ended in the Button element within the time and distance threshold.
|
2013-11-19 22:08:04 +04:00
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event click
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent("click", { originalEvent: event.originalEvent });
|
2011-12-20 16:39:02 +04:00
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
},
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
keyHandler: function( event ){
|
|
|
|
//console.log( "%s : handling key %s!", _this.tooltip, event.keyCode);
|
|
|
|
if( 13 === event.keyCode ){
|
2013-11-16 10:19:53 +04:00
|
|
|
/***
|
2013-11-19 23:20:45 +04:00
|
|
|
* Raised when a mouse button is pressed and released or touch is initiated and ended in the Button element within the time and distance threshold.
|
2013-11-19 22:08:04 +04:00
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event click
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "click", { originalEvent: event.originalEvent } );
|
2013-11-16 10:19:53 +04:00
|
|
|
/***
|
2013-11-19 22:08:04 +04:00
|
|
|
* Raised when the mouse button is released or touch ends in the Button element.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @event release
|
|
|
|
* @memberof OpenSeadragon.Button
|
|
|
|
* @type {object}
|
|
|
|
* @property {OpenSeadragon.Button} eventSource - A reference to the Button which raised the event.
|
|
|
|
* @property {Object} originalEvent - The original DOM event.
|
2013-11-18 18:56:32 +04:00
|
|
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
2013-11-16 10:19:53 +04:00
|
|
|
*/
|
2020-07-29 06:20:09 +03:00
|
|
|
_this.raiseEvent( "release", { originalEvent: event.originalEvent } );
|
2021-03-17 05:35:22 +03:00
|
|
|
|
|
|
|
event.preventDefault = true;
|
|
|
|
} else{
|
|
|
|
event.preventDefault = false;
|
2012-03-20 23:30:29 +04:00
|
|
|
}
|
2011-12-20 16:39:02 +04:00
|
|
|
}
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2015-01-21 05:35:58 +03:00
|
|
|
});
|
2012-02-28 03:29:00 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
outTo( this, $.ButtonState.REST );
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2013-11-16 10:19:53 +04:00
|
|
|
$.extend( $.Button.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.Button.prototype */{
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
2020-07-25 06:05:39 +03:00
|
|
|
* Used by a button container element (e.g. a ButtonGroup) to transition the button state
|
|
|
|
* to ButtonState.GROUP.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
notifyGroupEnter: function() {
|
2011-12-17 03:29:16 +04:00
|
|
|
inTo( this, $.ButtonState.GROUP );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
2020-07-25 06:05:39 +03:00
|
|
|
* Used by a button container element (e.g. a ButtonGroup) to transition the button state
|
|
|
|
* to ButtonState.REST.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
notifyGroupExit: function() {
|
2011-12-17 03:29:16 +04:00
|
|
|
outTo( this, $.ButtonState.REST );
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
disable: function(){
|
|
|
|
this.notifyGroupExit();
|
|
|
|
this.element.disabled = true;
|
2022-07-29 00:53:49 +03:00
|
|
|
this.tracker.setTracking(false);
|
2012-04-03 11:08:27 +04:00
|
|
|
$.setElementOpacity( this.element, 0.2, true );
|
|
|
|
},
|
|
|
|
|
2013-11-16 10:19:53 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
enable: function(){
|
|
|
|
this.element.disabled = false;
|
2022-07-29 00:55:21 +03:00
|
|
|
this.tracker.setTracking(true);
|
2012-04-03 11:08:27 +04:00
|
|
|
$.setElementOpacity( this.element, 1.0, true );
|
|
|
|
this.notifyGroupEnter();
|
2020-06-05 13:27:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2020-09-11 00:40:30 +03:00
|
|
|
if (this.imgRest) {
|
|
|
|
this.element.removeChild(this.imgRest);
|
|
|
|
this.imgRest = null;
|
|
|
|
}
|
|
|
|
if (this.imgGroup) {
|
|
|
|
this.element.removeChild(this.imgGroup);
|
|
|
|
this.imgGroup = null;
|
|
|
|
}
|
|
|
|
if (this.imgHover) {
|
|
|
|
this.element.removeChild(this.imgHover);
|
|
|
|
this.imgHover = null;
|
|
|
|
}
|
|
|
|
if (this.imgDown) {
|
|
|
|
this.element.removeChild(this.imgDown);
|
|
|
|
this.imgDown = null;
|
|
|
|
}
|
2020-06-05 13:27:00 +03:00
|
|
|
this.removeAllHandlers();
|
|
|
|
this.tracker.destroy();
|
|
|
|
this.element = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
});
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
function scheduleFade( button ) {
|
2013-02-26 19:19:48 +04:00
|
|
|
$.requestAnimationFrame(function(){
|
2011-12-17 03:29:16 +04:00
|
|
|
updateFade( button );
|
2013-02-26 19:19:48 +04:00
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
function updateFade( button ) {
|
|
|
|
var currentTime,
|
|
|
|
deltaTime,
|
|
|
|
opacity;
|
|
|
|
|
|
|
|
if ( button.shouldFade ) {
|
2013-06-21 00:15:04 +04:00
|
|
|
currentTime = $.now();
|
2012-02-28 17:07:56 +04:00
|
|
|
deltaTime = currentTime - button.fadeBeginTime;
|
|
|
|
opacity = 1.0 - deltaTime / button.fadeLength;
|
2011-12-17 03:29:16 +04:00
|
|
|
opacity = Math.min( 1.0, opacity );
|
|
|
|
opacity = Math.max( 0.0, opacity );
|
2012-03-16 19:36:28 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
if( button.imgGroup ){
|
|
|
|
$.setElementOpacity( button.imgGroup, opacity, true );
|
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
if ( opacity > 0 ) {
|
|
|
|
// fade again
|
|
|
|
scheduleFade( button );
|
|
|
|
}
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
function beginFading( button ) {
|
|
|
|
button.shouldFade = true;
|
2013-06-21 00:15:04 +04:00
|
|
|
button.fadeBeginTime = $.now() + button.fadeDelay;
|
2013-06-19 21:33:25 +04:00
|
|
|
window.setTimeout( function(){
|
2011-12-17 03:29:16 +04:00
|
|
|
scheduleFade( button );
|
|
|
|
}, button.fadeDelay );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
function stopFading( button ) {
|
|
|
|
button.shouldFade = false;
|
2012-04-11 01:02:24 +04:00
|
|
|
if( button.imgGroup ){
|
|
|
|
$.setElementOpacity( button.imgGroup, 1.0, true );
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
function inTo( button, newState ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
if( button.element.disabled ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
if ( newState >= $.ButtonState.GROUP &&
|
2020-06-26 02:01:14 +03:00
|
|
|
button.currentState === $.ButtonState.REST ) {
|
2011-12-17 03:29:16 +04:00
|
|
|
stopFading( button );
|
|
|
|
button.currentState = $.ButtonState.GROUP;
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
if ( newState >= $.ButtonState.HOVER &&
|
2020-06-26 02:01:14 +03:00
|
|
|
button.currentState === $.ButtonState.GROUP ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
if( button.imgHover ){
|
|
|
|
button.imgHover.style.visibility = "";
|
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
button.currentState = $.ButtonState.HOVER;
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
if ( newState >= $.ButtonState.DOWN &&
|
2020-06-26 02:01:14 +03:00
|
|
|
button.currentState === $.ButtonState.HOVER ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
if( button.imgDown ){
|
|
|
|
button.imgDown.style.visibility = "";
|
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
button.currentState = $.ButtonState.DOWN;
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
function outTo( button, newState ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
if( button.element.disabled ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
if ( newState <= $.ButtonState.HOVER &&
|
2020-06-26 02:01:14 +03:00
|
|
|
button.currentState === $.ButtonState.DOWN ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
if( button.imgDown ){
|
|
|
|
button.imgDown.style.visibility = "hidden";
|
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
button.currentState = $.ButtonState.HOVER;
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
if ( newState <= $.ButtonState.GROUP &&
|
2020-06-26 02:01:14 +03:00
|
|
|
button.currentState === $.ButtonState.HOVER ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
if( button.imgHover ){
|
|
|
|
button.imgHover.style.visibility = "hidden";
|
|
|
|
}
|
2011-12-20 16:44:33 +04:00
|
|
|
button.currentState = $.ButtonState.GROUP;
|
2011-12-17 03:29:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
if ( newState <= $.ButtonState.REST &&
|
2020-06-26 02:01:14 +03:00
|
|
|
button.currentState === $.ButtonState.GROUP ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
beginFading( button );
|
2011-12-17 03:29:16 +04:00
|
|
|
button.currentState = $.ButtonState.REST;
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|