2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - Navigator
|
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-07 07:20:00 +04:00
|
|
|
(function( $ ){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
/**
|
2012-04-11 01:02:24 +04:00
|
|
|
* The Navigator provides a small view of the current image as fixed
|
|
|
|
* while representing the viewport as a moving box serving as a frame
|
|
|
|
* of reference in the larger viewport as to which portion of the image
|
2013-01-31 22:18:32 +04:00
|
|
|
* is currently being examined. The navigator's viewport can be interacted
|
2012-04-11 01:02:24 +04:00
|
|
|
* with using the keyboard or the mouse.
|
2013-06-19 21:33:25 +04:00
|
|
|
* @class
|
2012-04-11 01:02:24 +04:00
|
|
|
* @name OpenSeadragon.Navigator
|
|
|
|
* @extends OpenSeadragon.Viewer
|
|
|
|
* @extends OpenSeadragon.EventHandler
|
2012-03-07 07:20:00 +04:00
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.viewerId
|
|
|
|
*/
|
|
|
|
$.Navigator = function( options ){
|
|
|
|
|
|
|
|
var _this = this,
|
2012-03-16 19:36:28 +04:00
|
|
|
viewer = options.viewer,
|
2013-04-05 06:30:59 +04:00
|
|
|
viewerSize = $.getElementSize( viewer.element),
|
|
|
|
unneededElement;
|
2013-03-16 06:29:27 +04:00
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
//We may need to create a new element and id if they did not
|
|
|
|
//provide the id for the existing element
|
|
|
|
if( !options.id ){
|
2013-06-21 00:15:04 +04:00
|
|
|
options.id = 'navigator-' + ($.now());
|
2012-03-16 19:36:28 +04:00
|
|
|
this.element = $.makeNeutralElement( "div" );
|
2013-03-15 18:59:47 +04:00
|
|
|
options.controlOptions = {anchor: $.ControlAnchor.TOP_RIGHT,
|
|
|
|
attachToViewer: true,
|
|
|
|
autoFade: true};
|
2012-03-07 07:20:00 +04:00
|
|
|
}
|
2013-04-03 05:07:10 +04:00
|
|
|
else {
|
2013-03-15 18:59:47 +04:00
|
|
|
this.element = document.getElementById( options.id );
|
|
|
|
options.controlOptions = {anchor: $.ControlAnchor.NONE,
|
|
|
|
attachToViewer: false,
|
|
|
|
autoFade: false};
|
|
|
|
}
|
|
|
|
this.element.id = options.id;
|
|
|
|
this.element.className += ' navigator';
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
options = $.extend( true, {
|
2013-01-31 01:51:37 +04:00
|
|
|
sizeRatio: $.DEFAULT_SETTINGS.navigatorSizeRatio
|
2012-03-09 20:04:28 +04:00
|
|
|
}, options, {
|
2012-03-07 07:20:00 +04:00
|
|
|
element: this.element,
|
|
|
|
//These need to be overridden to prevent recursion since
|
|
|
|
//the navigator is a viewer and a viewer has a navigator
|
|
|
|
showNavigator: false,
|
|
|
|
mouseNavEnabled: false,
|
2012-04-11 01:02:24 +04:00
|
|
|
showNavigationControl: false,
|
2013-03-06 14:51:31 +04:00
|
|
|
showSequenceControl: false,
|
|
|
|
immediateRender: true,
|
|
|
|
blendTime: 0,
|
|
|
|
animationTime: 0
|
2012-03-07 07:20:00 +04:00
|
|
|
});
|
|
|
|
|
2012-09-07 16:55:19 +04:00
|
|
|
options.minPixelRatio = this.minPixelRatio = viewer.minPixelRatio;
|
2012-03-20 03:03:58 +04:00
|
|
|
|
2013-04-03 19:51:24 +04:00
|
|
|
this.viewerSizeInPoints = viewer.viewport.deltaPointsFromPixels(viewerSize);
|
2013-03-16 06:29:27 +04:00
|
|
|
this.borderWidth = 2;
|
2013-03-24 07:06:34 +04:00
|
|
|
//At some browser magnification levels the display regions lines up correctly, but at some there appears to
|
|
|
|
//be a one pixel gap.
|
|
|
|
this.fudge = new $.Point(1, 1);
|
|
|
|
this.totalBorderWidths = new $.Point(this.borderWidth*2, this.borderWidth*2).minus(this.fudge);
|
|
|
|
|
2013-03-16 06:29:27 +04:00
|
|
|
|
|
|
|
(function( style, borderWidth ){
|
|
|
|
style.margin = '0px';
|
2013-04-03 05:07:10 +04:00
|
|
|
style.border = borderWidth + 'px solid #555';
|
2013-03-16 06:29:27 +04:00
|
|
|
style.padding = '0px';
|
2012-03-07 07:20:00 +04:00
|
|
|
style.background = '#000';
|
|
|
|
style.opacity = 0.8;
|
|
|
|
style.overflow = 'hidden';
|
2013-03-16 06:29:27 +04:00
|
|
|
}( this.element.style, this.borderWidth));
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2013-03-16 06:29:27 +04:00
|
|
|
this.displayRegion = $.makeNeutralElement( "div" );
|
2012-03-20 03:03:58 +04:00
|
|
|
this.displayRegion.id = this.element.id + '-displayregion';
|
|
|
|
this.displayRegion.className = 'displayregion';
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2013-03-16 06:29:27 +04:00
|
|
|
(function( style, borderWidth ){
|
2012-03-07 07:20:00 +04:00
|
|
|
style.position = 'relative';
|
|
|
|
style.top = '0px';
|
|
|
|
style.left = '0px';
|
2012-03-21 05:58:23 +04:00
|
|
|
style.fontSize = '0px';
|
2012-09-11 20:31:42 +04:00
|
|
|
style.overflow = 'hidden';
|
2013-03-16 06:29:27 +04:00
|
|
|
style.border = borderWidth + 'px solid #900';
|
|
|
|
style.margin = '0px';
|
|
|
|
style.padding = '0px';
|
2012-03-20 23:00:25 +04:00
|
|
|
//TODO: IE doesnt like this property being set
|
2013-01-24 08:00:11 +04:00
|
|
|
//try{ style.outline = '2px auto #909'; }catch(e){/*ignore*/}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
style.background = 'transparent';
|
2013-01-29 22:06:39 +04:00
|
|
|
|
|
|
|
// We use square bracket notation on the statement below, because float is a keyword.
|
2013-01-31 22:18:32 +04:00
|
|
|
// This is important for the Google Closure compiler, if nothing else.
|
2013-06-19 21:33:25 +04:00
|
|
|
/*jshint sub:true */
|
2013-01-29 22:06:39 +04:00
|
|
|
style['float'] = 'left'; //Webkit
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-20 10:26:34 +04:00
|
|
|
style.cssFloat = 'left'; //Firefox
|
2012-03-20 23:30:29 +04:00
|
|
|
style.styleFloat = 'left'; //IE
|
2012-03-07 07:20:00 +04:00
|
|
|
style.zIndex = 999999999;
|
2012-04-03 11:08:27 +04:00
|
|
|
style.cursor = 'default';
|
2013-03-16 06:29:27 +04:00
|
|
|
}( this.displayRegion.style, this.borderWidth ));
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.element.innerTracker = new $.MouseTracker({
|
|
|
|
element: this.element,
|
2013-06-03 06:32:29 +04:00
|
|
|
dragHandler: $.delegate( this, onCanvasDrag ),
|
2013-03-16 06:29:27 +04:00
|
|
|
clickHandler: $.delegate( this, onCanvasClick ),
|
|
|
|
releaseHandler: $.delegate( this, onCanvasRelease ),
|
2012-04-03 11:08:27 +04:00
|
|
|
scrollHandler: function(){
|
|
|
|
//dont scroll the page up and down if the user is scrolling
|
|
|
|
//in the navigator
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}).setTracking( true );
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
/*this.displayRegion.outerTracker = new $.MouseTracker({
|
2013-06-19 21:33:25 +04:00
|
|
|
element: this.container,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
2012-03-20 03:03:58 +04:00
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
enterHandler: $.delegate( this, onContainerEnter ),
|
|
|
|
exitHandler: $.delegate( this, onContainerExit ),
|
|
|
|
releaseHandler: $.delegate( this, onContainerRelease )
|
|
|
|
}).setTracking( this.mouseNavEnabled ? true : false ); // always tracking*/
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
viewer.addControl(
|
|
|
|
this.element,
|
2013-03-15 18:59:47 +04:00
|
|
|
options.controlOptions
|
2012-03-16 19:36:28 +04:00
|
|
|
);
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
if( options.width && options.height ){
|
|
|
|
this.element.style.width = options.width + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
this.element.style.height = options.height + 'px';
|
|
|
|
} else {
|
2013-01-31 01:51:37 +04:00
|
|
|
this.element.style.width = ( viewerSize.x * options.sizeRatio ) + 'px';
|
|
|
|
this.element.style.height = ( viewerSize.y * options.sizeRatio ) + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
$.Viewer.apply( this, [ options ] );
|
2012-03-16 19:36:28 +04:00
|
|
|
|
2012-08-29 22:46:34 +04:00
|
|
|
this.element.getElementsByTagName('form')[0].appendChild( this.displayRegion );
|
2013-04-05 06:30:59 +04:00
|
|
|
unneededElement = this.element.getElementsByTagName('textarea')[0];
|
|
|
|
if (unneededElement) {
|
|
|
|
unneededElement.parentNode.removeChild(unneededElement);
|
|
|
|
}
|
2012-08-29 22:46:34 +04:00
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, {
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Navigator.prototype.update
|
|
|
|
*/
|
2012-03-07 07:20:00 +04:00
|
|
|
update: function( viewport ){
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
var bounds,
|
|
|
|
topleft,
|
|
|
|
bottomright;
|
|
|
|
|
|
|
|
if( viewport && this.viewport ){
|
|
|
|
bounds = viewport.getBounds( true );
|
2013-03-24 05:11:30 +04:00
|
|
|
topleft = this.viewport.pixelFromPoint( bounds.getTopLeft());
|
2013-03-24 07:06:34 +04:00
|
|
|
bottomright = this.viewport.pixelFromPoint( bounds.getBottomRight()).minus(this.totalBorderWidths);
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
//update style for navigator-box
|
2013-03-16 06:29:27 +04:00
|
|
|
(function(style, borderWidth){
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
style.top = topleft.y + 'px';
|
|
|
|
style.left = topleft.x + 'px';
|
2013-01-28 22:11:14 +04:00
|
|
|
|
2013-03-24 05:11:30 +04:00
|
|
|
var width = Math.abs( topleft.x - bottomright.x );
|
|
|
|
var height = Math.abs( topleft.y - bottomright.y );
|
2013-01-25 17:17:35 +04:00
|
|
|
// make sure width and height are non-negative so IE doesn't throw
|
|
|
|
style.width = Math.max( width, 0 ) + 'px';
|
|
|
|
style.height = Math.max( height, 0 ) + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2013-03-16 06:29:27 +04:00
|
|
|
}( this.displayRegion.style, this.borderWidth));
|
2013-06-19 21:33:25 +04:00
|
|
|
}
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2013-03-06 14:51:31 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
open: function( source ){
|
|
|
|
var containerSize = this.viewer.viewport.containerSize.times( this.sizeRatio );
|
2013-06-19 21:33:25 +04:00
|
|
|
if( source.tileSize > containerSize.x ||
|
2013-03-06 14:51:31 +04:00
|
|
|
source.tileSize > containerSize.y ){
|
2013-06-19 21:33:25 +04:00
|
|
|
this.minPixelRatio = Math.min(
|
|
|
|
containerSize.x,
|
|
|
|
containerSize.y
|
2013-03-06 14:51:31 +04:00
|
|
|
) / source.tileSize;
|
|
|
|
} else {
|
2013-03-26 17:02:34 +04:00
|
|
|
this.minPixelRatio = this.viewer.minPixelRatio;
|
2013-03-06 14:51:31 +04:00
|
|
|
}
|
|
|
|
return $.Viewer.prototype.open.apply( this, [ source ] );
|
2012-03-07 07:20:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
function onCanvasClick( tracker, position, quick, shift ) {
|
2013-04-03 05:07:10 +04:00
|
|
|
var newBounds,
|
2013-04-03 19:51:24 +04:00
|
|
|
viewerPosition,
|
|
|
|
dimensions;
|
2013-04-03 05:07:10 +04:00
|
|
|
if (! this.drag) {
|
2013-03-16 06:29:27 +04:00
|
|
|
if ( this.viewer.viewport ) {
|
2013-04-03 19:51:24 +04:00
|
|
|
viewerPosition = this.viewport.deltaPointsFromPixels(position);
|
|
|
|
dimensions = this.viewer.viewport.getBounds().getSize();
|
2013-04-03 05:07:10 +04:00
|
|
|
newBounds = new $.Rect(
|
2013-04-03 19:51:24 +04:00
|
|
|
viewerPosition.x - dimensions.x/2,
|
|
|
|
viewerPosition.y - dimensions.y/2,
|
|
|
|
dimensions.x,
|
|
|
|
dimensions.y
|
2013-03-16 06:29:27 +04:00
|
|
|
);
|
2013-04-03 19:51:24 +04:00
|
|
|
if (this.viewer.source.aspectRatio > this.viewer.viewport.getAspectRatio()) {
|
|
|
|
newBounds.y = newBounds.y - ((this.viewerSizeInPoints.y - (1/this.viewer.source.aspectRatio)) /2 );
|
2013-03-16 06:29:27 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-04-03 19:51:24 +04:00
|
|
|
newBounds.x = newBounds.x - ((this.viewerSizeInPoints.x -1) /2 );
|
2013-03-16 06:29:27 +04:00
|
|
|
}
|
2013-04-03 05:07:10 +04:00
|
|
|
this.viewer.viewport.fitBounds(newBounds);
|
2013-04-02 06:33:58 +04:00
|
|
|
this.viewer.viewport.applyConstraints();
|
2013-03-16 06:29:27 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-03 05:07:10 +04:00
|
|
|
else {
|
2013-03-16 06:29:27 +04:00
|
|
|
this.drag = false;
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
function onCanvasDrag( tracker, position, delta, shift ) {
|
|
|
|
if ( this.viewer.viewport ) {
|
2013-03-16 06:29:27 +04:00
|
|
|
this.drag = true;
|
2012-04-03 11:08:27 +04:00
|
|
|
if( !this.panHorizontal ){
|
|
|
|
delta.x = 0;
|
|
|
|
}
|
|
|
|
if( !this.panVertical ){
|
|
|
|
delta.y = 0;
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.viewport.panBy(
|
|
|
|
this.viewport.deltaPointsFromPixels(
|
2012-04-03 11:08:27 +04:00
|
|
|
delta
|
2013-06-19 21:33:25 +04:00
|
|
|
)
|
2012-04-03 11:08:27 +04:00
|
|
|
);
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) {
|
|
|
|
if ( insideElementPress && this.viewer.viewport ) {
|
|
|
|
this.viewer.viewport.applyConstraints();
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
function onCanvasScroll( tracker, position, scroll, shift ) {
|
|
|
|
var factor;
|
|
|
|
if ( this.viewer.viewport ) {
|
|
|
|
factor = Math.pow( this.zoomPerScroll, scroll );
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewer.viewport.zoomBy(
|
|
|
|
factor,
|
2012-04-03 11:08:27 +04:00
|
|
|
this.viewport.getCenter()
|
|
|
|
);
|
|
|
|
this.viewer.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
//cancels event
|
|
|
|
return false;
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
2013-01-25 17:17:35 +04:00
|
|
|
}( OpenSeadragon ));
|