2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - ControlDock
|
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.
|
|
|
|
*/
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
(function( $ ){
|
|
|
|
/**
|
2013-11-16 10:19:53 +04:00
|
|
|
* @class ControlDock
|
2013-11-25 20:48:44 +04:00
|
|
|
* @classdesc Provides a container element (a <form> element) with support for the layout of control elements.
|
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @memberof OpenSeadragon
|
2012-03-09 20:04:28 +04:00
|
|
|
*/
|
|
|
|
$.ControlDock = function( options ){
|
|
|
|
var layouts = [ 'topleft', 'topright', 'bottomright', 'bottomleft'],
|
|
|
|
layout,
|
|
|
|
i;
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
$.extend( true, this, {
|
2017-01-08 17:52:57 +03:00
|
|
|
id: 'controldock-' + $.now() + '-' + Math.floor(Math.random() * 1000000),
|
2014-04-05 00:14:32 +04:00
|
|
|
container: $.makeNeutralElement( 'div' ),
|
2012-03-09 20:04:28 +04:00
|
|
|
controls: []
|
|
|
|
}, options );
|
|
|
|
|
2013-08-14 21:39:39 +04:00
|
|
|
// Disable the form's submit; otherwise button clicks and return keys
|
|
|
|
// can trigger it.
|
|
|
|
this.container.onsubmit = function() {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
if( this.element ){
|
|
|
|
this.element = $.getElement( this.element );
|
2013-06-19 21:33:25 +04:00
|
|
|
this.element.appendChild( this.container );
|
|
|
|
this.element.style.position = 'relative';
|
2012-03-09 20:04:28 +04:00
|
|
|
this.container.style.width = '100%';
|
|
|
|
this.container.style.height = '100%';
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 0; i < layouts.length; i++ ){
|
|
|
|
layout = layouts[ i ];
|
|
|
|
this.controls[ layout ] = $.makeNeutralElement( "div" );
|
|
|
|
this.controls[ layout ].style.position = 'absolute';
|
|
|
|
if ( layout.match( 'left' ) ){
|
|
|
|
this.controls[ layout ].style.left = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'right' ) ){
|
|
|
|
this.controls[ layout ].style.right = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'top' ) ){
|
|
|
|
this.controls[ layout ].style.top = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'bottom' ) ){
|
|
|
|
this.controls[ layout ].style.bottom = '0px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.container.appendChild( this.controls.topleft );
|
|
|
|
this.container.appendChild( this.controls.topright );
|
|
|
|
this.container.appendChild( this.controls.bottomright );
|
|
|
|
this.container.appendChild( this.controls.bottomleft );
|
|
|
|
};
|
|
|
|
|
2016-01-25 00:09:18 +03:00
|
|
|
/** @lends OpenSeadragon.ControlDock.prototype */
|
|
|
|
$.ControlDock.prototype = {
|
2012-03-09 20:04:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2013-03-15 18:59:47 +04:00
|
|
|
addControl: function ( element, controlOptions ) {
|
2013-01-29 21:32:58 +04:00
|
|
|
element = $.getElement( element );
|
|
|
|
var div = null;
|
2012-03-09 20:04:28 +04:00
|
|
|
|
|
|
|
if ( getControlIndex( this, element ) >= 0 ) {
|
|
|
|
return; // they're trying to add a duplicate control
|
|
|
|
}
|
|
|
|
|
2013-03-15 18:59:47 +04:00
|
|
|
switch ( controlOptions.anchor ) {
|
2012-03-09 20:04:28 +04:00
|
|
|
case $.ControlAnchor.TOP_RIGHT:
|
|
|
|
div = this.controls.topright;
|
|
|
|
element.style.position = "relative";
|
2012-08-29 22:46:34 +04:00
|
|
|
element.style.paddingRight = "0px";
|
|
|
|
element.style.paddingTop = "0px";
|
2012-03-09 20:04:28 +04:00
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_RIGHT:
|
|
|
|
div = this.controls.bottomright;
|
|
|
|
element.style.position = "relative";
|
2012-08-29 22:46:34 +04:00
|
|
|
element.style.paddingRight = "0px";
|
|
|
|
element.style.paddingBottom = "0px";
|
2012-03-09 20:04:28 +04:00
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_LEFT:
|
|
|
|
div = this.controls.bottomleft;
|
|
|
|
element.style.position = "relative";
|
2012-08-29 22:46:34 +04:00
|
|
|
element.style.paddingLeft = "0px";
|
|
|
|
element.style.paddingBottom = "0px";
|
2012-03-09 20:04:28 +04:00
|
|
|
break;
|
|
|
|
case $.ControlAnchor.TOP_LEFT:
|
|
|
|
div = this.controls.topleft;
|
|
|
|
element.style.position = "relative";
|
2012-08-29 22:46:34 +04:00
|
|
|
element.style.paddingLeft = "0px";
|
|
|
|
element.style.paddingTop = "0px";
|
2012-03-09 20:04:28 +04:00
|
|
|
break;
|
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
|
|
|
case $.ControlAnchor.ABSOLUTE:
|
|
|
|
div = this.container;
|
|
|
|
element.style.margin = "0px";
|
|
|
|
element.style.padding = "0px";
|
|
|
|
break;
|
2012-03-09 20:04:28 +04:00
|
|
|
default:
|
2013-01-29 21:32:58 +04:00
|
|
|
case $.ControlAnchor.NONE:
|
2012-03-09 20:04:28 +04:00
|
|
|
div = this.container;
|
|
|
|
element.style.margin = "0px";
|
|
|
|
element.style.padding = "0px";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.controls.push(
|
2013-03-15 18:59:47 +04:00
|
|
|
new $.Control( element, controlOptions, div )
|
2012-03-09 20:04:28 +04:00
|
|
|
);
|
|
|
|
element.style.display = "inline-block";
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
2012-04-11 01:02:24 +04:00
|
|
|
* @return {OpenSeadragon.ControlDock} Chainable.
|
2012-03-09 20:04:28 +04:00
|
|
|
*/
|
|
|
|
removeControl: function ( element ) {
|
2013-01-29 21:32:58 +04:00
|
|
|
element = $.getElement( element );
|
|
|
|
var i = getControlIndex( this, element );
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
if ( i >= 0 ) {
|
|
|
|
this.controls[ i ].destroy();
|
|
|
|
this.controls.splice( i, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
2012-04-11 01:02:24 +04:00
|
|
|
* @return {OpenSeadragon.ControlDock} Chainable.
|
2012-03-09 20:04:28 +04:00
|
|
|
*/
|
|
|
|
clearControls: function () {
|
|
|
|
while ( this.controls.length > 0 ) {
|
|
|
|
this.controls.pop().destroy();
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
|
|
|
areControlsEnabled: function () {
|
|
|
|
var i;
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
|
|
|
if ( this.controls[ i ].isVisible() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
2012-04-11 01:02:24 +04:00
|
|
|
* @return {OpenSeadragon.ControlDock} Chainable.
|
2012-03-09 20:04:28 +04:00
|
|
|
*/
|
|
|
|
setControlsEnabled: function( enabled ) {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
|
|
|
this.controls[ i ].setVisible( enabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utility methods
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function getControlIndex( dock, element ) {
|
|
|
|
var controls = dock.controls,
|
|
|
|
i;
|
|
|
|
|
|
|
|
for ( i = controls.length - 1; i >= 0; i-- ) {
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( controls[ i ].element === element ) {
|
2012-03-09 20:04:28 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2013-05-01 08:46:16 +04:00
|
|
|
}( OpenSeadragon ));
|