2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - Control
|
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( $ ){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2013-11-25 20:48:44 +04:00
|
|
|
* An enumeration of supported locations where controls can be anchored.
|
|
|
|
* The anchoring is always relative to the container.
|
|
|
|
* @member ControlAnchor
|
|
|
|
* @memberof OpenSeadragon
|
2012-01-25 23:14:02 +04:00
|
|
|
* @static
|
2013-11-25 20:48:44 +04:00
|
|
|
* @type {Object}
|
|
|
|
* @property {Number} NONE
|
|
|
|
* @property {Number} TOP_LEFT
|
|
|
|
* @property {Number} TOP_RIGHT
|
|
|
|
* @property {Number} BOTTOM_LEFT
|
|
|
|
* @property {Number} BOTTOM_RIGHT
|
Enhanced Navigator Resizability (#280, #296)
New navigator options:
* @property {Boolean} [showNavigator=false]
* Set to true to make the navigator minimap appear.
*
* @property {Boolean} [navigatorId=navigator-GENERATED DATE]
* The ID of a div to hold the navigator minimap.
* If an ID is specified, the navigatorPosition, navigatorSizeRatio,
navigatorMaintainSizeRatio, and navigatorTop|Left|Height|Width options
will be ignored.
* If an ID is not specified, a div element will be generated and
placed on top of the main image.
*
* @property {String} [navigatorPosition='TOP_RIGHT']
* Valid values are 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT',
'BOTTOM_RIGHT', or 'ABSOLUTE'.<br>
* If 'ABSOLUTE' is specified, then navigatorTop|Left|Height|Width
determines the size and position of the navigator minimap in the viewer,
and navigatorSizeRatio and navigatorMaintainSizeRatio are ignored.<br>
* For 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT', and 'BOTTOM_RIGHT',
the navigatorSizeRatio or navigatorHeight|Width values determine the
size of the navigator minimap.
*
* @property {Number} [navigatorSizeRatio=0.2]
* Ratio of navigator size to viewer size. Ignored if
navigatorHeight|Width are specified.
*
* @property {Boolean} [navigatorMaintainSizeRatio=false]
* If true, the navigator minimap is resized (using
navigatorSizeRatio) when the viewer size changes.
*
* @property {Number|String} [navigatorTop=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorLeft=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorHeight=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
*
* @property {Number|String} [navigatorWidth=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
Fixes #280 and #296
2013-12-13 21:23:56 +04:00
|
|
|
* @property {Number} ABSOLUTE
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-14 02:57:40 +04:00
|
|
|
$.ControlAnchor = {
|
|
|
|
NONE: 0,
|
|
|
|
TOP_LEFT: 1,
|
|
|
|
TOP_RIGHT: 2,
|
|
|
|
BOTTOM_RIGHT: 3,
|
Enhanced Navigator Resizability (#280, #296)
New navigator options:
* @property {Boolean} [showNavigator=false]
* Set to true to make the navigator minimap appear.
*
* @property {Boolean} [navigatorId=navigator-GENERATED DATE]
* The ID of a div to hold the navigator minimap.
* If an ID is specified, the navigatorPosition, navigatorSizeRatio,
navigatorMaintainSizeRatio, and navigatorTop|Left|Height|Width options
will be ignored.
* If an ID is not specified, a div element will be generated and
placed on top of the main image.
*
* @property {String} [navigatorPosition='TOP_RIGHT']
* Valid values are 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT',
'BOTTOM_RIGHT', or 'ABSOLUTE'.<br>
* If 'ABSOLUTE' is specified, then navigatorTop|Left|Height|Width
determines the size and position of the navigator minimap in the viewer,
and navigatorSizeRatio and navigatorMaintainSizeRatio are ignored.<br>
* For 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT', and 'BOTTOM_RIGHT',
the navigatorSizeRatio or navigatorHeight|Width values determine the
size of the navigator minimap.
*
* @property {Number} [navigatorSizeRatio=0.2]
* Ratio of navigator size to viewer size. Ignored if
navigatorHeight|Width are specified.
*
* @property {Boolean} [navigatorMaintainSizeRatio=false]
* If true, the navigator minimap is resized (using
navigatorSizeRatio) when the viewer size changes.
*
* @property {Number|String} [navigatorTop=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorLeft=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorHeight=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
*
* @property {Number|String} [navigatorWidth=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
Fixes #280 and #296
2013-12-13 21:23:56 +04:00
|
|
|
BOTTOM_LEFT: 4,
|
|
|
|
ABSOLUTE: 5
|
2011-12-14 02:57:40 +04:00
|
|
|
};
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2013-11-25 20:48:44 +04:00
|
|
|
* @class Control
|
|
|
|
* @classdesc A Control represents any interface element which is meant to allow the user
|
2013-06-19 21:33:25 +04:00
|
|
|
* to interact with the zoomable interface. Any control can be anchored to any
|
2012-01-25 23:14:02 +04:00
|
|
|
* element.
|
2013-11-25 20:48:44 +04:00
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @memberof OpenSeadragon
|
2013-06-02 00:09:04 +04:00
|
|
|
* @param {Element} element - the control element to be anchored in the container.
|
2013-06-11 22:35:45 +04:00
|
|
|
* @param {Object } options - All required and optional settings for configuring a control element.
|
2013-06-02 00:09:04 +04:00
|
|
|
* @param {OpenSeadragon.ControlAnchor} [options.anchor=OpenSeadragon.ControlAnchor.NONE] - the position of the control
|
|
|
|
* relative to the container.
|
|
|
|
* @param {Boolean} [options.attachToViewer=true] - Whether the control should be added directly to the viewer, or
|
|
|
|
* directly to the container
|
|
|
|
* @param {Boolean} [options.autoFade=true] - Whether the control should have the autofade behavior
|
2012-01-25 23:14:02 +04:00
|
|
|
* @param {Element} container - the element to control will be anchored too.
|
|
|
|
*/
|
2013-03-15 18:59:47 +04:00
|
|
|
$.Control = function ( element, options, container ) {
|
|
|
|
var parent = element.parentNode;
|
2013-06-07 18:24:12 +04:00
|
|
|
if (typeof options === 'number')
|
|
|
|
{
|
2013-06-11 22:35:45 +04:00
|
|
|
$.console.error("Passing an anchor directly into the OpenSeadragon.Control constructor is deprecated; " +
|
|
|
|
"please use an options object instead. " +
|
|
|
|
"Support for this deprecated variant is scheduled for removal in December 2013");
|
2013-06-07 18:24:12 +04:00
|
|
|
options = {anchor: options};
|
|
|
|
}
|
2013-03-15 18:59:47 +04:00
|
|
|
options.attachToViewer = (typeof options.attachToViewer === 'undefined') ? true : options.attachToViewer;
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* True if the control should have autofade behavior.
|
|
|
|
* @member {Boolean} autoFade
|
|
|
|
* @memberof OpenSeadragon.Control#
|
|
|
|
*/
|
2013-03-15 18:59:47 +04:00
|
|
|
this.autoFade = (typeof options.autoFade === 'undefined') ? true : options.autoFade;
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* The element providing the user interface with some type of control (e.g. a zoom-in button).
|
|
|
|
* @member {Element} element
|
|
|
|
* @memberof OpenSeadragon.Control#
|
|
|
|
*/
|
2012-02-01 06:01:37 +04:00
|
|
|
this.element = element;
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* The position of the Control relative to its container.
|
|
|
|
* @member {OpenSeadragon.ControlAnchor} anchor
|
|
|
|
* @memberof OpenSeadragon.Control#
|
|
|
|
*/
|
2013-03-15 18:59:47 +04:00
|
|
|
this.anchor = options.anchor;
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* The Control's containing element.
|
|
|
|
* @member {Element} container
|
|
|
|
* @memberof OpenSeadragon.Control#
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
this.container = container;
|
2013-11-25 20:48:44 +04:00
|
|
|
/**
|
|
|
|
* A neutral element surrounding the control element.
|
|
|
|
* @member {Element} wrapper
|
|
|
|
* @memberof OpenSeadragon.Control#
|
|
|
|
*/
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( this.anchor === $.ControlAnchor.ABSOLUTE ) {
|
2013-12-13 23:55:36 +04:00
|
|
|
this.wrapper = $.makeNeutralElement( "div" );
|
|
|
|
this.wrapper.style.position = "absolute";
|
2020-06-26 02:01:14 +03:00
|
|
|
this.wrapper.style.top = typeof (options.top) === "number" ? (options.top + 'px') : options.top;
|
|
|
|
this.wrapper.style.left = typeof (options.left) === "number" ? (options.left + 'px') : options.left;
|
|
|
|
this.wrapper.style.height = typeof (options.height) === "number" ? (options.height + 'px') : options.height;
|
|
|
|
this.wrapper.style.width = typeof (options.width) === "number" ? (options.width + 'px') : options.width;
|
2013-12-13 23:55:36 +04:00
|
|
|
this.wrapper.style.margin = "0px";
|
|
|
|
this.wrapper.style.padding = "0px";
|
|
|
|
|
|
|
|
this.element.style.position = "relative";
|
|
|
|
this.element.style.top = "0px";
|
|
|
|
this.element.style.left = "0px";
|
|
|
|
this.element.style.height = "100%";
|
|
|
|
this.element.style.width = "100%";
|
|
|
|
} else {
|
2014-04-05 00:14:32 +04:00
|
|
|
this.wrapper = $.makeNeutralElement( "div" );
|
Enhanced Navigator Resizability (#280, #296)
New navigator options:
* @property {Boolean} [showNavigator=false]
* Set to true to make the navigator minimap appear.
*
* @property {Boolean} [navigatorId=navigator-GENERATED DATE]
* The ID of a div to hold the navigator minimap.
* If an ID is specified, the navigatorPosition, navigatorSizeRatio,
navigatorMaintainSizeRatio, and navigatorTop|Left|Height|Width options
will be ignored.
* If an ID is not specified, a div element will be generated and
placed on top of the main image.
*
* @property {String} [navigatorPosition='TOP_RIGHT']
* Valid values are 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT',
'BOTTOM_RIGHT', or 'ABSOLUTE'.<br>
* If 'ABSOLUTE' is specified, then navigatorTop|Left|Height|Width
determines the size and position of the navigator minimap in the viewer,
and navigatorSizeRatio and navigatorMaintainSizeRatio are ignored.<br>
* For 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT', and 'BOTTOM_RIGHT',
the navigatorSizeRatio or navigatorHeight|Width values determine the
size of the navigator minimap.
*
* @property {Number} [navigatorSizeRatio=0.2]
* Ratio of navigator size to viewer size. Ignored if
navigatorHeight|Width are specified.
*
* @property {Boolean} [navigatorMaintainSizeRatio=false]
* If true, the navigator minimap is resized (using
navigatorSizeRatio) when the viewer size changes.
*
* @property {Number|String} [navigatorTop=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorLeft=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorHeight=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
*
* @property {Number|String} [navigatorWidth=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
Fixes #280 and #296
2013-12-13 21:23:56 +04:00
|
|
|
this.wrapper.style.display = "inline-block";
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( this.anchor === $.ControlAnchor.NONE ) {
|
Enhanced Navigator Resizability (#280, #296)
New navigator options:
* @property {Boolean} [showNavigator=false]
* Set to true to make the navigator minimap appear.
*
* @property {Boolean} [navigatorId=navigator-GENERATED DATE]
* The ID of a div to hold the navigator minimap.
* If an ID is specified, the navigatorPosition, navigatorSizeRatio,
navigatorMaintainSizeRatio, and navigatorTop|Left|Height|Width options
will be ignored.
* If an ID is not specified, a div element will be generated and
placed on top of the main image.
*
* @property {String} [navigatorPosition='TOP_RIGHT']
* Valid values are 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT',
'BOTTOM_RIGHT', or 'ABSOLUTE'.<br>
* If 'ABSOLUTE' is specified, then navigatorTop|Left|Height|Width
determines the size and position of the navigator minimap in the viewer,
and navigatorSizeRatio and navigatorMaintainSizeRatio are ignored.<br>
* For 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT', and 'BOTTOM_RIGHT',
the navigatorSizeRatio or navigatorHeight|Width values determine the
size of the navigator minimap.
*
* @property {Number} [navigatorSizeRatio=0.2]
* Ratio of navigator size to viewer size. Ignored if
navigatorHeight|Width are specified.
*
* @property {Boolean} [navigatorMaintainSizeRatio=false]
* If true, the navigator minimap is resized (using
navigatorSizeRatio) when the viewer size changes.
*
* @property {Number|String} [navigatorTop=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorLeft=null]
* Specifies the location of the navigator minimap (see
navigatorPosition).
*
* @property {Number|String} [navigatorHeight=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
*
* @property {Number|String} [navigatorWidth=null]
* Specifies the size of the navigator minimap (see
navigatorPosition).
* If specified, navigatorSizeRatio and navigatorMaintainSizeRatio
are ignored.
Fixes #280 and #296
2013-12-13 21:23:56 +04:00
|
|
|
// IE6 fix
|
|
|
|
this.wrapper.style.width = this.wrapper.style.height = "100%";
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2013-12-13 23:55:36 +04:00
|
|
|
this.wrapper.appendChild( this.element );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2013-03-15 18:59:47 +04:00
|
|
|
if (options.attachToViewer ) {
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( this.anchor === $.ControlAnchor.TOP_RIGHT ||
|
|
|
|
this.anchor === $.ControlAnchor.BOTTOM_RIGHT ) {
|
2013-03-15 18:59:47 +04:00
|
|
|
this.container.insertBefore(
|
|
|
|
this.wrapper,
|
|
|
|
this.container.firstChild
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.container.appendChild( this.wrapper );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2013-12-13 23:55:36 +04:00
|
|
|
parent.appendChild( this.wrapper );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-25 00:09:18 +03:00
|
|
|
/** @lends OpenSeadragon.Control.prototype */
|
|
|
|
$.Control.prototype = {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Removes the control from the container.
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
destroy: function() {
|
2013-12-13 23:55:36 +04:00
|
|
|
this.wrapper.removeChild( this.element );
|
2020-09-11 00:40:30 +03:00
|
|
|
if (this.anchor !== $.ControlAnchor.NONE) {
|
|
|
|
this.container.removeChild(this.wrapper);
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Determines if the control is currently visible.
|
|
|
|
* @function
|
2018-09-01 11:59:20 +03:00
|
|
|
* @return {Boolean} true if currently visible, false otherwise.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
isVisible: function() {
|
2020-06-26 02:01:14 +03:00
|
|
|
return this.wrapper.style.display !== "none";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Toggles the visibility of the control.
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} visible - true to make visible, false to hide.
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
setVisible: function( visible ) {
|
2013-12-13 23:55:36 +04:00
|
|
|
this.wrapper.style.display = visible ?
|
2020-06-26 02:01:14 +03:00
|
|
|
( this.anchor === $.ControlAnchor.ABSOLUTE ? 'block' : 'inline-block' ) :
|
2013-12-13 23:55:36 +04:00
|
|
|
"none";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Sets the opacity level for the control.
|
|
|
|
* @function
|
|
|
|
* @param {Number} opactiy - a value between 1 and 0 inclusively.
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
setOpacity: function( opacity ) {
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( this.element[ $.SIGNAL ] && $.Browser.vendor === $.BROWSERS.IE ) {
|
2012-02-01 06:01:37 +04:00
|
|
|
$.setElementOpacity( this.element, opacity, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-24 07:48:45 +04:00
|
|
|
$.setElementOpacity( this.wrapper, opacity, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|