2012-03-07 07:20:00 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.viewerId
|
|
|
|
*/
|
|
|
|
$.Navigator = function( options ){
|
|
|
|
|
|
|
|
var _this = this,
|
2012-03-16 19:36:28 +04:00
|
|
|
viewer = options.viewer,
|
|
|
|
viewerSize = $.getElementSize( viewer.element );
|
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 ){
|
2012-03-16 19:36:28 +04:00
|
|
|
options.id = 'navigator-' + (+new Date());
|
|
|
|
this.element = $.makeNeutralElement( "div" );
|
|
|
|
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, {
|
2012-03-20 03:03:58 +04:00
|
|
|
navigatorSizeRatio: $.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-03-09 20:04:28 +04:00
|
|
|
showNavigationControl: false
|
2012-03-07 07:20:00 +04:00
|
|
|
});
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
options.minPixelRatio = Math.min(
|
|
|
|
options.navigatorSizeRatio * $.DEFAULT_SETTINGS.minPixelRatio,
|
|
|
|
$.DEFAULT_SETTINGS.minPixelRatio
|
|
|
|
);
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
(function( style ){
|
|
|
|
style.marginTop = '0px';
|
|
|
|
style.marginRight = '0px';
|
|
|
|
style.marginBottom = '0px';
|
|
|
|
style.marginLeft = '0px';
|
|
|
|
style.border = '2px solid #555';
|
|
|
|
style.background = '#000';
|
|
|
|
style.opacity = 0.8;
|
|
|
|
style.overflow = 'hidden';
|
|
|
|
}( this.element.style ));
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
this.displayRegion = $.makeNeutralElement( "textarea" );
|
|
|
|
this.displayRegion.id = this.element.id + '-displayregion';
|
|
|
|
this.displayRegion.className = 'displayregion';
|
2012-03-07 07:20:00 +04:00
|
|
|
|
|
|
|
(function( style ){
|
|
|
|
style.position = 'relative';
|
|
|
|
style.top = '0px';
|
|
|
|
style.left = '0px';
|
2012-03-16 19:36:28 +04:00
|
|
|
style.border = '1px solid #900';
|
|
|
|
style.outline = '2px auto #900';
|
2012-03-07 07:20:00 +04:00
|
|
|
style.background = 'transparent';
|
2012-03-20 10:26:34 +04:00
|
|
|
style.float = 'left'; //Webkit
|
|
|
|
style.cssFloat = 'left'; //Firefox
|
|
|
|
style.floatStyle = 'left'; //IE
|
2012-03-07 07:20:00 +04:00
|
|
|
style.zIndex = 999999999;
|
|
|
|
}( this.displayRegion.style ));
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
this.displayRegion.innerTracker = new $.MouseTracker({
|
|
|
|
element: this.displayRegion,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
focusHandler: function(){
|
|
|
|
_this.viewer.setControlsEnabled( true );
|
|
|
|
(function( style ){
|
|
|
|
style.border = '1px solid #437AB2';
|
|
|
|
style.outline = '2px auto #437AB2';
|
|
|
|
}( this.element.style ));
|
|
|
|
|
|
|
|
},
|
|
|
|
blurHandler: function(){
|
|
|
|
_this.viewer.setControlsEnabled( false );
|
|
|
|
(function( style ){
|
|
|
|
style.border = '1px solid #900';
|
|
|
|
style.outline = '2px auto #900';
|
|
|
|
}( this.element.style ));
|
|
|
|
},
|
|
|
|
keyHandler: function(tracker, keyCode){
|
|
|
|
//console.log( keyCode );
|
|
|
|
switch( keyCode ){
|
|
|
|
case 119://w
|
|
|
|
_this.viewer.viewport.panBy(new $.Point(0, -0.1));
|
|
|
|
break;
|
|
|
|
case 115://s
|
|
|
|
_this.viewer.viewport.panBy(new $.Point(0, 0.1));
|
|
|
|
break;
|
|
|
|
case 97://a
|
|
|
|
_this.viewer.viewport.panBy(new $.Point(-0.1, 0));
|
|
|
|
break;
|
|
|
|
case 100://d
|
|
|
|
_this.viewer.viewport.panBy(new $.Point(0.1, 0));
|
|
|
|
break;
|
|
|
|
case 61://=|+
|
|
|
|
_this.viewer.viewport.zoomBy(1.1);
|
|
|
|
break;
|
|
|
|
case 45://-|_
|
|
|
|
_this.viewer.viewport.zoomBy(0.9);
|
|
|
|
break;
|
|
|
|
case 48://0|)
|
|
|
|
_this.viewer.viewport.goHome();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//console.log( 'navigator keycode %s', keyCode );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).setTracking( true ); // default state
|
|
|
|
|
|
|
|
/*this.displayRegion.outerTracker = new $.MouseTracker({
|
|
|
|
element: this.container,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
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
|
|
|
this.element.appendChild( this.displayRegion );
|
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
viewer.addControl(
|
|
|
|
this.element,
|
|
|
|
$.ControlAnchor.TOP_RIGHT
|
|
|
|
);
|
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 {
|
2012-03-20 03:03:58 +04:00
|
|
|
this.element.style.width = ( viewerSize.x * options.navigatorSizeRatio ) + 'px';
|
|
|
|
this.element.style.height = ( viewerSize.y * options.navigatorSizeRatio ) + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
}
|
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
$.Viewer.apply( this, [ options ] );
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, {
|
|
|
|
|
|
|
|
update: function( viewport ){
|
|
|
|
|
|
|
|
var bounds = viewport.getBounds( true ),
|
|
|
|
topleft = this.viewport.pixelFromPoint( bounds.getTopLeft() )
|
|
|
|
bottomright = this.viewport.pixelFromPoint( bounds.getBottomRight() );
|
|
|
|
|
|
|
|
//update style for navigator-box
|
|
|
|
(function(style){
|
|
|
|
|
|
|
|
style.top = topleft.y + 'px';
|
|
|
|
style.left = topleft.x + 'px';
|
2012-03-09 20:04:28 +04:00
|
|
|
style.width = ( Math.abs( topleft.x - bottomright.x ) - 3 ) + 'px';
|
|
|
|
style.height = ( Math.abs( topleft.y - bottomright.y ) - 3 ) + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
|
|
|
|
}( this.displayRegion.style ));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|