From 041597998f21af11eab924050d2d6f70af789c9d Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Thu, 26 Sep 2013 09:50:26 -0700 Subject: [PATCH 01/15] Event Names Normalized All event names lower case with no hyphens --- src/button.js | 32 ++++++++++++++++---------------- src/drawer.js | 16 ++++++++-------- src/strings.js | 2 +- src/tilesource.js | 4 ++-- src/viewer.js | 28 ++++++++++++++-------------- src/viewport.js | 2 +- test/basic.js | 2 +- test/events.js | 20 ++++++++++---------- test/formats.js | 4 ++-- test/strings.js | 2 +- 10 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/button.js b/src/button.js index 86755a72..062abf8a 100644 --- a/src/button.js +++ b/src/button.js @@ -152,13 +152,13 @@ $.Button = function( options ) { } - this.addHandler( "onPress", this.onPress ); - this.addHandler( "onRelease", this.onRelease ); - this.addHandler( "onClick", this.onClick ); - this.addHandler( "onEnter", this.onEnter ); - this.addHandler( "onExit", this.onExit ); - this.addHandler( "onFocus", this.onFocus ); - this.addHandler( "onBlur", this.onBlur ); + 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 ); this.currentState = $.ButtonState.GROUP; @@ -178,7 +178,7 @@ $.Button = function( options ) { enterHandler: function( tracker, eventData ) { if ( eventData.insideElementPressed ) { inTo( _this, $.ButtonState.DOWN ); - _this.raiseEvent( "onEnter", _this ); + _this.raiseEvent( "enter", _this ); } else if ( !eventData.buttonDownAny ) { inTo( _this, $.ButtonState.HOVER ); } @@ -186,30 +186,30 @@ $.Button = function( options ) { focusHandler: function ( tracker, eventData ) { this.enterHandler( tracker, eventData ); - _this.raiseEvent( "onFocus", _this ); + _this.raiseEvent( "focus", _this ); }, exitHandler: function( tracker, eventData ) { outTo( _this, $.ButtonState.GROUP ); if ( eventData.insideElementPressed ) { - _this.raiseEvent( "onExit", _this ); + _this.raiseEvent( "exit", _this ); } }, blurHandler: function ( tracker, eventData ) { this.exitHandler( tracker, eventData ); - _this.raiseEvent( "onBlur", _this ); + _this.raiseEvent( "blur", _this ); }, pressHandler: function ( tracker, eventData ) { inTo( _this, $.ButtonState.DOWN ); - _this.raiseEvent( "onPress", _this ); + _this.raiseEvent( "press", _this ); }, releaseHandler: function( tracker, eventData ) { if ( eventData.insideElementPressed && eventData.insideElementReleased ) { outTo( _this, $.ButtonState.HOVER ); - _this.raiseEvent( "onRelease", _this ); + _this.raiseEvent( "release", _this ); } else if ( eventData.insideElementPressed ) { outTo( _this, $.ButtonState.GROUP ); } else { @@ -219,15 +219,15 @@ $.Button = function( options ) { clickHandler: function( tracker, eventData ) { if ( eventData.quick ) { - _this.raiseEvent("onClick", _this); + _this.raiseEvent("click", _this); } }, keyHandler: function( tracker, eventData ){ //console.log( "%s : handling key %s!", _this.tooltip, eventData.keyCode); if( 13 === eventData.keyCode ){ - _this.raiseEvent( "onClick", _this ); - _this.raiseEvent( "onRelease", _this ); + _this.raiseEvent( "click", _this ); + _this.raiseEvent( "release", _this ); return false; } return true; diff --git a/src/drawer.js b/src/drawer.js index de94356c..c1b3646a 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -204,7 +204,7 @@ $.Drawer.prototype = { }) ); this.updateAgain = true; if( this.viewer ){ - this.viewer.raiseEvent( 'add-overlay', { + this.viewer.raiseEvent( 'addoverlay', { viewer: this.viewer, element: element, location: options.location, @@ -236,7 +236,7 @@ $.Drawer.prototype = { this.updateAgain = true; } if( this.viewer ){ - this.viewer.raiseEvent( 'update-overlay', { + this.viewer.raiseEvent( 'updateoverlay', { viewer: this.viewer, element: element, location: location, @@ -266,7 +266,7 @@ $.Drawer.prototype = { this.updateAgain = true; } if( this.viewer ){ - this.viewer.raiseEvent( 'remove-overlay', { + this.viewer.raiseEvent( 'removeoverlay', { viewer: this.viewer, element: element }); @@ -286,7 +286,7 @@ $.Drawer.prototype = { this.updateAgain = true; } if( this.viewer ){ - this.viewer.raiseEvent( 'clear-overlay', { + this.viewer.raiseEvent( 'clearoverlay', { viewer: this.viewer }); } @@ -481,7 +481,7 @@ function updateViewport( drawer ) { drawer.updateAgain = false; if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'update-viewport', { + drawer.viewer.raiseEvent( 'updateviewport', { viewer: drawer.viewer }); } @@ -657,7 +657,7 @@ function updateLevel( drawer, haveDrawn, drawLevel, level, levelOpacity, levelVi if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'update-level', { + drawer.viewer.raiseEvent( 'updatelevel', { viewer: drawer.viewer, havedrawn: haveDrawn, level: level, @@ -721,7 +721,7 @@ function updateTile( drawer, drawLevel, haveDrawn, x, y, level, levelOpacity, le drawTile = drawLevel; if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'update-tile', { + drawer.viewer.raiseEvent( 'updatetile', { viewer: drawer.viewer, tile: tile }); @@ -1235,7 +1235,7 @@ function drawTiles( drawer, lastDrawn ){ } if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'tile-drawn', { + drawer.viewer.raiseEvent( 'tiledrawn', { viewer: drawer.viewer, tile: tile }); diff --git a/src/strings.js b/src/strings.js index 9616850a..6e375808 100644 --- a/src/strings.js +++ b/src/strings.js @@ -46,7 +46,7 @@ var I18N = { Security: "It looks like a security restriction stopped us from " + "loading this Deep Zoom Image.", Status: "This space unintentionally left blank ({0} {1}).", - "Open-Failed": "Unable to open {0}: {1}" + "OpenFailed": "Unable to open {0}: {1}" }, Tooltips: { diff --git a/src/tilesource.js b/src/tilesource.js index 9352487e..54c01241 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -301,7 +301,7 @@ $.TileSource.prototype = { callback = function( data ){ var $TileSource = $.TileSource.determineType( _this, data, url ); if ( !$TileSource ) { - _this.raiseEvent( 'open-failed', { message: "Unable to load TileSource", source: url } ); + _this.raiseEvent( 'openfailed', { message: "Unable to load TileSource", source: url } ); return; } @@ -351,7 +351,7 @@ $.TileSource.prototype = { msg = formattedExc + " attempting to load TileSource"; } - _this.raiseEvent( 'open-failed', { + _this.raiseEvent( 'openfailed', { message: msg, source: url }); diff --git a/src/viewer.js b/src/viewer.js index 4887d844..8057b717 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -172,8 +172,8 @@ $.Viewer = function( options ) { //Inherit some behaviors and properties $.EventSource.call( this ); - this.addHandler( 'open-failed', function (source, args) { - var msg = $.getString( "Errors.Open-Failed", args.source, args.message); + this.addHandler( 'openfailed', function (source, args) { + var msg = $.getString( "Errors.OpenFailed", args.source, args.message); _this._showMessage( msg ); }); @@ -441,8 +441,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, tileSource = new $.TileSource( tileSource, function( readySource ){ openTileSource( _this, readySource ); }); - tileSource.addHandler( 'open-failed', function ( name, args ) { - _this.raiseEvent( 'open-failed', args ); + tileSource.addHandler( 'openfailed', function ( name, args ) { + _this.raiseEvent( 'openfailed', args ); }); } else if ( $.isPlainObject( tileSource ) || tileSource.nodeType ){ @@ -455,7 +455,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, //inline configuration $TileSource = $.TileSource.determineType( _this, tileSource ); if ( !$TileSource ) { - _this.raiseEvent( 'open-failed', { + _this.raiseEvent( 'openfailed', { message: "Unable to load TileSource", source: tileSource }); @@ -569,7 +569,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, */ setMouseNavEnabled: function( enabled ){ this.innerTracker.setTracking( enabled ); - this.raiseEvent( 'mouse-enabled', { enabled: enabled, viewer: this } ); + this.raiseEvent( 'mouseenabled', { enabled: enabled, viewer: this } ); return this; }, @@ -603,7 +603,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } else { beginControlsAutoHide( this ); } - this.raiseEvent( 'controls-enabled', { enabled: enabled, viewer: this } ); + this.raiseEvent( 'controlsenabled', { enabled: enabled, viewer: this } ); return this; }, @@ -1439,7 +1439,7 @@ function onCanvasClick( tracker, eventData ) { ); this.viewport.applyConstraints(); } - this.raiseEvent( 'canvas-click', { + this.raiseEvent( 'canvasclick', { tracker: tracker, position: eventData.position, quick: eventData.quick, @@ -1464,7 +1464,7 @@ function onCanvasDrag( tracker, eventData ) { this.viewport.applyConstraints(); } } - this.raiseEvent( 'canvas-drag', { + this.raiseEvent( 'canvasdrag', { tracker: tracker, position: eventData.position, delta: eventData.delta, @@ -1476,7 +1476,7 @@ function onCanvasRelease( tracker, eventData ) { if ( eventData.insideElementPressed && this.viewport ) { this.viewport.applyConstraints(); } - this.raiseEvent( 'canvas-release', { + this.raiseEvent( 'canvasrelease', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, @@ -1494,7 +1494,7 @@ function onCanvasScroll( tracker, eventData ) { ); this.viewport.applyConstraints(); } - this.raiseEvent( 'canvas-scroll', { + this.raiseEvent( 'canvasscroll', { tracker: tracker, position: eventData.position, scroll: eventData.scroll, @@ -1511,7 +1511,7 @@ function onContainerExit( tracker, eventData ) { beginControlsAutoHide( this ); } } - this.raiseEvent( 'container-exit', { + this.raiseEvent( 'containerexit', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, @@ -1526,7 +1526,7 @@ function onContainerRelease( tracker, eventData ) { beginControlsAutoHide( this ); } } - this.raiseEvent( 'container-release', { + this.raiseEvent( 'containerrelease', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, @@ -1537,7 +1537,7 @@ function onContainerRelease( tracker, eventData ) { function onContainerEnter( tracker, eventData ) { THIS[ this.hash ].mouseInside = true; abortControlsAutoHide( this ); - this.raiseEvent( 'container-enter', { + this.raiseEvent( 'containerenter', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, diff --git a/src/viewport.js b/src/viewport.js index 691851c4..3ea56afa 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -121,7 +121,7 @@ $.Viewport.prototype = { this.homeBounds = new $.Rect( 0, 0, 1, this.contentAspectY ); if( this.viewer ){ - this.viewer.raiseEvent( 'reset-size', { + this.viewer.raiseEvent( 'resetsize', { contentSize: contentSize, viewer: this.viewer }); diff --git a/test/basic.js b/test/basic.js index 50e51cab..ffab85ad 100644 --- a/test/basic.js +++ b/test/basic.js @@ -51,7 +51,7 @@ start(); }); - viewer.addHandler('open-failed', function(eventSender, eventData) { + viewer.addHandler('openfailed', function(eventSender, eventData) { ok(true, "The open-failed event should be fired when the source 404s"); equal($(".openseadragon-message").length, 1, "Open failures should display a message"); diff --git a/test/events.js b/test/events.js index d99799be..687387f3 100644 --- a/test/events.js +++ b/test/events.js @@ -61,7 +61,7 @@ } ); // ---------- - asyncTest( 'MouseTracker, EventSource canvas-drag canvas-release canvas-click', function () { + asyncTest( 'MouseTracker, EventSource canvasdrag canvasrelease canvasclick', function () { var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ), mouseTracker = null, userData = { item1: 'Test user data', item2: Math.random() }, @@ -78,9 +78,9 @@ var onOpen = function ( eventSender, eventData ) { viewer.removeHandler( 'open', onOpen ); - viewer.addHandler( 'canvas-drag', onEventSourceDrag ); - viewer.addHandler( 'canvas-release', onEventSourceRelease ); - viewer.addHandler( 'canvas-click', onEventSourceClick ); + viewer.addHandler( 'canvasdrag', onEventSourceDrag ); + viewer.addHandler( 'canvasrelease', onEventSourceRelease ); + viewer.addHandler( 'canvasclick', onEventSourceClick ); mouseTracker = new OpenSeadragon.MouseTracker( { element: $canvas[0], @@ -172,13 +172,13 @@ checkOriginalEventReceived( eventData ); mouseTracker.destroy(); - viewer.removeHandler( 'canvas-drag', onEventSourceDrag ); - viewer.removeHandler( 'canvas-release', onEventSourceRelease ); - viewer.removeHandler( 'canvas-click', onEventSourceClick ); + viewer.removeHandler( 'canvasdrag', onEventSourceDrag ); + viewer.removeHandler( 'canvasrelease', onEventSourceRelease ); + viewer.removeHandler( 'canvasclick', onEventSourceClick ); - equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); - equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); - equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" ); + equal( dragsHandledEventSource, dragCount, "'canvasdrag' event count matches 'mousemove' event count (" + dragCount + ")" ); + equal( releasesHandledEventSource, releasesExpected, "'canvasrelease' event count matches expected (" + releasesExpected + ")" ); + equal( clicksHandledEventSource, releasesExpected, "'canvasclick' event count matches expected (" + releasesExpected + ")" ); equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" ); deepEqual( eventData.userData, originalUserData, 'MouseTracker userData was untouched' ); diff --git a/test/formats.js b/test/formats.js index 0c673bcf..085e3712 100644 --- a/test/formats.js +++ b/test/formats.js @@ -29,11 +29,11 @@ var openHandler = function(eventSender, eventData) { viewer.removeHandler('open', openHandler); ok(true, 'Open event was sent'); - viewer.addHandler('tile-drawn', tileDrawnHandler); + viewer.addHandler('tiledrawn', tileDrawnHandler); }; var tileDrawnHandler = function(eventSender, eventData) { - viewer.removeHandler('tile-drawn', tileDrawnHandler); + viewer.removeHandler('tiledrawn', tileDrawnHandler); ok(true, 'A tile has been drawn'); viewer.addHandler('close', closeHandler); viewer.close(); diff --git a/test/strings.js b/test/strings.js index 1c740a8a..0cc0d8d4 100644 --- a/test/strings.js +++ b/test/strings.js @@ -15,7 +15,7 @@ }); test("getStringWithPlaceholders", function() { - equal(OpenSeadragon.getString("Errors.Open-Failed", "foo", "bar"), + equal(OpenSeadragon.getString("Errors.OpenFailed", "foo", "bar"), "Unable to open foo: bar", "String placeholder replacement"); }); From bf0608b4b2dd618349784d0ed8196dfb79229290 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Thu, 26 Sep 2013 10:16:10 -0700 Subject: [PATCH 02/15] string.js quotes/whitespace fix --- src/strings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strings.js b/src/strings.js index 6e375808..8e473dc5 100644 --- a/src/strings.js +++ b/src/strings.js @@ -46,7 +46,7 @@ var I18N = { Security: "It looks like a security restriction stopped us from " + "loading this Deep Zoom Image.", Status: "This space unintentionally left blank ({0} {1}).", - "OpenFailed": "Unable to open {0}: {1}" + OpenFailed: "Unable to open {0}: {1}" }, Tooltips: { From c0a16dacc4db8faf60140e0b73a64a37296c4a96 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Thu, 26 Sep 2013 10:23:00 -0700 Subject: [PATCH 03/15] eventsource.js comment fix --- src/eventsource.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/eventsource.js b/src/eventsource.js index 012ce68f..c5289777 100644 --- a/src/eventsource.js +++ b/src/eventsource.js @@ -36,12 +36,8 @@ /** * For use by classes which want to support custom, non-browser events. - * TODO: This is an awful name! This thing represents an "event source", - * not an "event handler". PLEASE change the to EventSource. Also please - * change 'addHandler', 'removeHandler' and 'raiseEvent' to 'bind', - * 'unbind', and 'trigger' respectively. Finally add a method 'one' which - * automatically unbinds a listener after the first triggered event that - * matches. + * TODO: Add a method 'one' which automatically unbinds a listener after + * the first triggered event that matches. * @class */ $.EventSource = function() { From ec3141a778a8f564cfc6175ddae0fb8d8bca069e Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Mon, 30 Sep 2013 10:22:06 -0700 Subject: [PATCH 04/15] Event Names Normalized Compound event names lower case with hyphen. Button event names removed "on" and made lower case. --- src/drawer.js | 16 ++++++++-------- src/tilesource.js | 4 ++-- src/viewer.js | 30 +++++++++++++++--------------- src/viewport.js | 2 +- test/basic.js | 22 +++++++++++----------- test/events.js | 20 ++++++++++---------- test/formats.js | 4 ++-- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index c1b3646a..de94356c 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -204,7 +204,7 @@ $.Drawer.prototype = { }) ); this.updateAgain = true; if( this.viewer ){ - this.viewer.raiseEvent( 'addoverlay', { + this.viewer.raiseEvent( 'add-overlay', { viewer: this.viewer, element: element, location: options.location, @@ -236,7 +236,7 @@ $.Drawer.prototype = { this.updateAgain = true; } if( this.viewer ){ - this.viewer.raiseEvent( 'updateoverlay', { + this.viewer.raiseEvent( 'update-overlay', { viewer: this.viewer, element: element, location: location, @@ -266,7 +266,7 @@ $.Drawer.prototype = { this.updateAgain = true; } if( this.viewer ){ - this.viewer.raiseEvent( 'removeoverlay', { + this.viewer.raiseEvent( 'remove-overlay', { viewer: this.viewer, element: element }); @@ -286,7 +286,7 @@ $.Drawer.prototype = { this.updateAgain = true; } if( this.viewer ){ - this.viewer.raiseEvent( 'clearoverlay', { + this.viewer.raiseEvent( 'clear-overlay', { viewer: this.viewer }); } @@ -481,7 +481,7 @@ function updateViewport( drawer ) { drawer.updateAgain = false; if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'updateviewport', { + drawer.viewer.raiseEvent( 'update-viewport', { viewer: drawer.viewer }); } @@ -657,7 +657,7 @@ function updateLevel( drawer, haveDrawn, drawLevel, level, levelOpacity, levelVi if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'updatelevel', { + drawer.viewer.raiseEvent( 'update-level', { viewer: drawer.viewer, havedrawn: haveDrawn, level: level, @@ -721,7 +721,7 @@ function updateTile( drawer, drawLevel, haveDrawn, x, y, level, levelOpacity, le drawTile = drawLevel; if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'updatetile', { + drawer.viewer.raiseEvent( 'update-tile', { viewer: drawer.viewer, tile: tile }); @@ -1235,7 +1235,7 @@ function drawTiles( drawer, lastDrawn ){ } if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'tiledrawn', { + drawer.viewer.raiseEvent( 'tile-drawn', { viewer: drawer.viewer, tile: tile }); diff --git a/src/tilesource.js b/src/tilesource.js index 54c01241..9352487e 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -301,7 +301,7 @@ $.TileSource.prototype = { callback = function( data ){ var $TileSource = $.TileSource.determineType( _this, data, url ); if ( !$TileSource ) { - _this.raiseEvent( 'openfailed', { message: "Unable to load TileSource", source: url } ); + _this.raiseEvent( 'open-failed', { message: "Unable to load TileSource", source: url } ); return; } @@ -351,7 +351,7 @@ $.TileSource.prototype = { msg = formattedExc + " attempting to load TileSource"; } - _this.raiseEvent( 'openfailed', { + _this.raiseEvent( 'open-failed', { message: msg, source: url }); diff --git a/src/viewer.js b/src/viewer.js index 8057b717..65199316 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -172,7 +172,7 @@ $.Viewer = function( options ) { //Inherit some behaviors and properties $.EventSource.call( this ); - this.addHandler( 'openfailed', function (source, args) { + this.addHandler( 'open-failed', function (source, args) { var msg = $.getString( "Errors.OpenFailed", args.source, args.message); _this._showMessage( msg ); }); @@ -441,8 +441,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, tileSource = new $.TileSource( tileSource, function( readySource ){ openTileSource( _this, readySource ); }); - tileSource.addHandler( 'openfailed', function ( name, args ) { - _this.raiseEvent( 'openfailed', args ); + tileSource.addHandler( 'open-failed', function ( name, args ) { + _this.raiseEvent( 'open-failed', args ); }); } else if ( $.isPlainObject( tileSource ) || tileSource.nodeType ){ @@ -455,7 +455,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, //inline configuration $TileSource = $.TileSource.determineType( _this, tileSource ); if ( !$TileSource ) { - _this.raiseEvent( 'openfailed', { + _this.raiseEvent( 'open-failed', { message: "Unable to load TileSource", source: tileSource }); @@ -569,7 +569,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, */ setMouseNavEnabled: function( enabled ){ this.innerTracker.setTracking( enabled ); - this.raiseEvent( 'mouseenabled', { enabled: enabled, viewer: this } ); + this.raiseEvent( 'mouse-enabled', { enabled: enabled, viewer: this } ); return this; }, @@ -603,7 +603,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } else { beginControlsAutoHide( this ); } - this.raiseEvent( 'controlsenabled', { enabled: enabled, viewer: this } ); + this.raiseEvent( 'controls-enabled', { enabled: enabled, viewer: this } ); return this; }, @@ -1439,7 +1439,7 @@ function onCanvasClick( tracker, eventData ) { ); this.viewport.applyConstraints(); } - this.raiseEvent( 'canvasclick', { + this.raiseEvent( 'canvas-click', { tracker: tracker, position: eventData.position, quick: eventData.quick, @@ -1464,7 +1464,7 @@ function onCanvasDrag( tracker, eventData ) { this.viewport.applyConstraints(); } } - this.raiseEvent( 'canvasdrag', { + this.raiseEvent( 'canvas-drag', { tracker: tracker, position: eventData.position, delta: eventData.delta, @@ -1476,7 +1476,7 @@ function onCanvasRelease( tracker, eventData ) { if ( eventData.insideElementPressed && this.viewport ) { this.viewport.applyConstraints(); } - this.raiseEvent( 'canvasrelease', { + this.raiseEvent( 'canvas-release', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, @@ -1494,7 +1494,7 @@ function onCanvasScroll( tracker, eventData ) { ); this.viewport.applyConstraints(); } - this.raiseEvent( 'canvasscroll', { + this.raiseEvent( 'canvas-scroll', { tracker: tracker, position: eventData.position, scroll: eventData.scroll, @@ -1511,7 +1511,7 @@ function onContainerExit( tracker, eventData ) { beginControlsAutoHide( this ); } } - this.raiseEvent( 'containerexit', { + this.raiseEvent( 'container-exit', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, @@ -1526,7 +1526,7 @@ function onContainerRelease( tracker, eventData ) { beginControlsAutoHide( this ); } } - this.raiseEvent( 'containerrelease', { + this.raiseEvent( 'container-release', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, @@ -1537,7 +1537,7 @@ function onContainerRelease( tracker, eventData ) { function onContainerEnter( tracker, eventData ) { THIS[ this.hash ].mouseInside = true; abortControlsAutoHide( this ); - this.raiseEvent( 'containerenter', { + this.raiseEvent( 'container-enter', { tracker: tracker, position: eventData.position, insideElementPressed: eventData.insideElementPressed, @@ -1589,7 +1589,7 @@ function updateOnce( viewer ) { } if ( !THIS[ viewer.hash ].animating && animated ) { - viewer.raiseEvent( "animationstart" ); + viewer.raiseEvent( "animation-start" ); abortControlsAutoHide( viewer ); } @@ -1608,7 +1608,7 @@ function updateOnce( viewer ) { } if ( THIS[ viewer.hash ].animating && !animated ) { - viewer.raiseEvent( "animationfinish" ); + viewer.raiseEvent( "animation-finish" ); if ( !THIS[ viewer.hash ].mouseInside ) { beginControlsAutoHide( viewer ); diff --git a/src/viewport.js b/src/viewport.js index 3ea56afa..691851c4 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -121,7 +121,7 @@ $.Viewport.prototype = { this.homeBounds = new $.Rect( 0, 0, 1, this.contentAspectY ); if( this.viewer ){ - this.viewer.raiseEvent( 'resetsize', { + this.viewer.raiseEvent( 'reset-size', { contentSize: contentSize, viewer: this.viewer }); diff --git a/test/basic.js b/test/basic.js index ffab85ad..eb75b947 100644 --- a/test/basic.js +++ b/test/basic.js @@ -51,7 +51,7 @@ start(); }); - viewer.addHandler('openfailed', function(eventSender, eventData) { + viewer.addHandler('open-failed', function(eventSender, eventData) { ok(true, "The open-failed event should be fired when the source 404s"); equal($(".openseadragon-message").length, 1, "Open failures should display a message"); @@ -73,12 +73,12 @@ equal(viewport.getZoom(), 1, 'We start out unzoomed'); var zoomHandler = function() { - viewer.removeHandler('animationfinish', zoomHandler); + viewer.removeHandler('animation-finish', zoomHandler); equal(viewport.getZoom(), 2, 'Zoomed correctly'); start(); }; - viewer.addHandler('animationfinish', zoomHandler); + viewer.addHandler('animation-finish', zoomHandler); viewport.zoomTo(2); }); viewer.open('/test/data/testpattern.dzi'); @@ -93,13 +93,13 @@ ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned'); var panHandler = function() { - viewer.removeHandler('animationfinish', panHandler); + viewer.removeHandler('animation-finish', panHandler); center = viewport.getCenter(); ok(center.x === 0.1 && center.y === 0.1, 'Panned correctly'); start(); }; - viewer.addHandler('animationfinish', panHandler); + viewer.addHandler('animation-finish', panHandler); viewport.panTo(new OpenSeadragon.Point(0.1, 0.1)); }); @@ -119,25 +119,25 @@ var viewport = viewer.viewport, center = viewport.getCenter(); - viewer.removeHandler('animationfinish', stage1); + viewer.removeHandler('animation-finish', stage1); ok(center.x !== 0.5 && center.y !== 0.5, 'We start out panned'); notEqual(viewport.getZoom(), 1, 'We start out zoomed'); var homeHandler = function() { - viewer.removeHandler('animationfinish', homeHandler); + viewer.removeHandler('animation-finish', homeHandler); center = viewport.getCenter(); ok(center.x === 0.5 && center.y === 0.5, 'We end up unpanned'); equal(viewport.getZoom(), 1, 'We end up unzoomed'); start(); }; - viewer.addHandler('animationfinish', homeHandler); + viewer.addHandler('animation-finish', homeHandler); viewport.goHome(true); } viewer.addHandler("open", opener); - viewer.addHandler("animationfinish", stage1); + viewer.addHandler("animation-finish", stage1); viewer.open('/test/data/testpattern.dzi'); }); @@ -152,14 +152,14 @@ equal(viewport.getZoom(), 1, 'We start out unzoomed'); var clickHandler = function() { - viewer.removeHandler('animationfinish', clickHandler); + viewer.removeHandler('animation-finish', clickHandler); center = viewport.getCenter(); ok(center.x > 0.37 && center.x < 0.38 && center.y > 0.37 && center.y < 0.38, 'Panned correctly'); equal(viewport.getZoom(), 2, 'Zoomed correctly'); start(); }; - viewer.addHandler('animationfinish', clickHandler); + viewer.addHandler('animation-finish', clickHandler); Util.simulateViewerClickWithDrag( { viewer: viewer, widthFactor: 0.25, diff --git a/test/events.js b/test/events.js index 687387f3..d99799be 100644 --- a/test/events.js +++ b/test/events.js @@ -61,7 +61,7 @@ } ); // ---------- - asyncTest( 'MouseTracker, EventSource canvasdrag canvasrelease canvasclick', function () { + asyncTest( 'MouseTracker, EventSource canvas-drag canvas-release canvas-click', function () { var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ), mouseTracker = null, userData = { item1: 'Test user data', item2: Math.random() }, @@ -78,9 +78,9 @@ var onOpen = function ( eventSender, eventData ) { viewer.removeHandler( 'open', onOpen ); - viewer.addHandler( 'canvasdrag', onEventSourceDrag ); - viewer.addHandler( 'canvasrelease', onEventSourceRelease ); - viewer.addHandler( 'canvasclick', onEventSourceClick ); + viewer.addHandler( 'canvas-drag', onEventSourceDrag ); + viewer.addHandler( 'canvas-release', onEventSourceRelease ); + viewer.addHandler( 'canvas-click', onEventSourceClick ); mouseTracker = new OpenSeadragon.MouseTracker( { element: $canvas[0], @@ -172,13 +172,13 @@ checkOriginalEventReceived( eventData ); mouseTracker.destroy(); - viewer.removeHandler( 'canvasdrag', onEventSourceDrag ); - viewer.removeHandler( 'canvasrelease', onEventSourceRelease ); - viewer.removeHandler( 'canvasclick', onEventSourceClick ); + viewer.removeHandler( 'canvas-drag', onEventSourceDrag ); + viewer.removeHandler( 'canvas-release', onEventSourceRelease ); + viewer.removeHandler( 'canvas-click', onEventSourceClick ); - equal( dragsHandledEventSource, dragCount, "'canvasdrag' event count matches 'mousemove' event count (" + dragCount + ")" ); - equal( releasesHandledEventSource, releasesExpected, "'canvasrelease' event count matches expected (" + releasesExpected + ")" ); - equal( clicksHandledEventSource, releasesExpected, "'canvasclick' event count matches expected (" + releasesExpected + ")" ); + equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); + equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); + equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" ); equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" ); deepEqual( eventData.userData, originalUserData, 'MouseTracker userData was untouched' ); diff --git a/test/formats.js b/test/formats.js index 085e3712..0c673bcf 100644 --- a/test/formats.js +++ b/test/formats.js @@ -29,11 +29,11 @@ var openHandler = function(eventSender, eventData) { viewer.removeHandler('open', openHandler); ok(true, 'Open event was sent'); - viewer.addHandler('tiledrawn', tileDrawnHandler); + viewer.addHandler('tile-drawn', tileDrawnHandler); }; var tileDrawnHandler = function(eventSender, eventData) { - viewer.removeHandler('tiledrawn', tileDrawnHandler); + viewer.removeHandler('tile-drawn', tileDrawnHandler); ok(true, 'A tile has been drawn'); viewer.addHandler('close', closeHandler); viewer.close(); From c38b7aae4af4ca2c528b80ce8868f70b66e4037e Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Mon, 30 Sep 2013 10:32:34 -0700 Subject: [PATCH 05/15] changelog update for new event names --- changelog.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index 46e84e18..d0770e88 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,11 +3,19 @@ OPENSEADRAGON CHANGELOG 1.0.0: (in progress) +* BREAKING CHANGE: Renamed EventHandler to EventSource (#225) +* BREAKING CHANGE: MouseTracker event handler method signatures changed to 'handlerMethod( tracker, eventData)' (#23) +* BREAKING CHANGE: Button event names changed to lower case, removed "on" prefix (#226): +* "onPress" is now "press" +* "onRelease" is now "release" +* "onClick" is now "click" +* "onEnter" is now "enter" +* "onExit" is now "exit" +* "onFocus" is now "focus" +* "onBlur" is now "blur" * MouseTracker now passes the original event objects to its handler methods (#23) -* Breaking change: MouseTracker event handler method signatures changed to 'handlerMethod( tracker, eventData)' (#23) * MouseTracker now supports an optional 'moveHandler' method for tracking mousemove events (#215) * Fixed: Element-relative mouse coordinates now correct if the element and/or page is scrolled (using new OpenSeadragon.getElementOffset() method) (#131) -* Renamed EventHandler to EventSource (#225) 0.9.131: From 434807a6607f030ea85316156c597d89afca6f01 Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Fri, 30 Aug 2013 16:40:06 -0400 Subject: [PATCH 06/15] added support for iiif 1.1 --- Gruntfile.js | 1 + src/iiif11tilesource.js | 224 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 src/iiif11tilesource.js diff --git a/Gruntfile.js b/Gruntfile.js index 332f49d1..ce91ac8a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -34,6 +34,7 @@ module.exports = function(grunt) { "src/tilesource.js", "src/dzitilesource.js", "src/iiiftilesource.js", + "src/iiif11tilesource.js", "src/osmtilesource.js", "src/tmstilesource.js", "src/legacytilesource.js", diff --git a/src/iiif11tilesource.js b/src/iiif11tilesource.js new file mode 100644 index 00000000..d730b176 --- /dev/null +++ b/src/iiif11tilesource.js @@ -0,0 +1,224 @@ +/* + * OpenSeadragon - IIIF11TileSource + * + * Copyright (C) 2009 CodePlex Foundation + * Copyright (C) 2010-2013 OpenSeadragon contributors + * + * 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. + */ + +/* + * The getTileUrl implementation is based on Jon Stroop's Python version, + * which is released under the New BSD license: + * https://gist.github.com/jpstroop/4624253 + */ + + +(function( $ ){ + +/** + * A client implementation of the International Image Interoperability + * Format: Image API Draft 0.2 - Please read more about the specification + * at + * + * @class + * @extends OpenSeadragon.TileSource + * @see http://library.stanford.edu/iiif/image-api/ + */ +$.IIIF11TileSource = function( options ){ + + $.extend( true, this, options ); + + if( !(this.height && this.width && this['@id'] ) ){ + throw new Error('IIIF required parameters not provided.'); + } + + //TODO: at this point the base tile source implementation assumes + // a tile is a square and so only has one property tileSize + // to store it. It may be possible to make tileSize a vector + // OpenSeadraon.Point but would require careful implementation + // to preserve backward compatibility. + options.tileSize = this.tile_width; + + if (! options.maxLevel ) { + var mf = -1; + var scfs = this.scale_factors || this.scale_factor; + if ( scfs instanceof Array ) { + for ( var i = 0; i < scfs.length; i++ ) { + var cf = Number( scfs[i] ); + if ( !isNaN( cf ) && cf > mf ) { mf = cf; } + } + } + if ( mf < 0 ) { options.maxLevel = Number(Math.ceil(Math.log(Math.max(this.width, this.height), 2))); } + else { options.maxLevel = mf; } + } + + $.TileSource.apply( this, [ options ] ); +}; + +$.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { + /** + * Determine if the data and/or url imply the image service is supported by + * this tile source. + * @function + * @name OpenSeadragon.IIIFTileSource.prototype.supports + * @param {Object|Array} data + * @param {String} optional - url + */ + supports: function( data, url ){ + return data.profile && ( + "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0" == data.profile || + "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1" == data.profile || + "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2" == data.profile || + "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level3" == data.profile || + "http://library.stanford.edu/iiif/image-api/1.1/compliance.html" == data.profile + ); + }, + + /** + * + * @function + * @name OpenSeadragon.IIIF11TileSource.prototype.configure + * @param {Object|XMLDocument} data - the raw configuration + * @param {String} url - the url the data was retreived from if any. + * @return {Object} options - A dictionary of keyword arguments sufficient + * to configure this tile source via it's constructor. + */ + configure: function( data, url ){ + // var service, + // options, + // host; + + + // options = configureFromObject( this, data ); + + // if( url && !options.tilesUrl ){ + // service = url.split('/'); + // service.pop(); //info.json + // service = service.join('/'); + // if( 'http' !== url.substring( 0, 4 ) ){ + // host = location.protocol + '//' + location.host; + // service = host + service; + // } + // options.tilesUrl = service.replace( + // data.identifier, + // '' + // ); + // } + + return configureFromObject( this, data ); + }, + + /** + * Responsible for retreiving the url which will return an image for the + * region speified by the given x, y, and level components. + * @function + * @name OpenSeadragon.IIIFTileSource.prototype.getTileUrl + * @param {Number} level - z index + * @param {Number} x + * @param {Number} y + * @throws {Error} + */ + getTileUrl: function( level, x, y ){ + + //# constants + var IIIF_ROTATION = '0', + IIIF_QUALITY = 'native.jpg', + + //## get the scale (level as a decimal) + scale = Math.pow( 0.5, this.maxLevel - level ), + + //## get iiif size + iiif_size = 'pct:' + ( scale * 100 ), + + //# image dimensions at this level + level_width = Math.ceil( this.width * scale ), + level_height = Math.ceil( this.height * scale ), + + //## iiif region + iiif_tile_size_width = Math.ceil( this.tileSize / scale ), + iiif_tile_size_height = Math.ceil( this.tileSize / scale ), + iiif_region, + iiif_tile_x, + iiif_tile_y, + iiif_tile_w, + iiif_tile_h; + + + if ( level_width < this.tile_width && level_height < this.tile_height ){ + iiif_region = 'full'; + } else { + iiif_tile_x = x * iiif_tile_size_width; + iiif_tile_y = y * iiif_tile_size_height; + iiif_tile_w = Math.min( iiif_tile_size_width, this.width - iiif_tile_x ); + iiif_tile_h = Math.min( iiif_tile_size_height, this.height - iiif_tile_y ); + iiif_region = [ iiif_tile_x, iiif_tile_y, iiif_tile_w, iiif_tile_h ].join(','); + } + + return [ + this['@id'], + iiif_region, + iiif_size, + IIIF_ROTATION, + IIIF_QUALITY + ].join('/'); + } + + +}); + + +/** + * @private + * @inner + * @function + * +{ + "@context" : "http://library.stanford.edu/iiif/image-api/1.1/context.json", + "@id" : "http://iiif.example.com/prefix/1E34750D-38DB-4825-A38A-B60A345E591C", + "width" : 6000, + "height" : 4000, + "scale_factors" : [ 1, 2, 4 ], + "tile_width" : 1024, + "tile_height" : 1024, + "formats" : [ "jpg", "png" ], + "qualities" : [ "native", "grey" ] + "profile" : "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0" +} + */ +function configureFromObject( tileSource, configuration ){ + //the image_host property is not part of the iiif standard but is included here to + //allow the info.json and info.xml specify a different server to load the + //images from so we can test the implementation. + if( configuration.image_host ){ + configuration.tilesUrl = configuration.image_host; + } + return configuration; +} + +}( OpenSeadragon )); From e3c1007ae2e75abd8516f496f89003eff81c32ed Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Wed, 11 Sep 2013 13:19:30 -0400 Subject: [PATCH 07/15] use pixels for size instead of pct --- src/iiif11tilesource.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/iiif11tilesource.js b/src/iiif11tilesource.js index d730b176..fde83d72 100644 --- a/src/iiif11tilesource.js +++ b/src/iiif11tilesource.js @@ -86,7 +86,7 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { * Determine if the data and/or url imply the image service is supported by * this tile source. * @function - * @name OpenSeadragon.IIIFTileSource.prototype.supports + * @name OpenSeadragon.IIIF11TileSource.prototype.supports * @param {Object|Array} data * @param {String} optional - url */ @@ -138,7 +138,7 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { * Responsible for retreiving the url which will return an image for the * region speified by the given x, y, and level components. * @function - * @name OpenSeadragon.IIIFTileSource.prototype.getTileUrl + * @name OpenSeadragon.IIIF11TileSource.prototype.getTileUrl * @param {Number} level - z index * @param {Number} x * @param {Number} y @@ -153,13 +153,18 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { //## get the scale (level as a decimal) scale = Math.pow( 0.5, this.maxLevel - level ), - //## get iiif size - iiif_size = 'pct:' + ( scale * 100 ), - //# image dimensions at this level level_width = Math.ceil( this.width * scale ), level_height = Math.ceil( this.height * scale ), + //## get iiif size + // Note that this uses pixels rather than percents (as in + // IIIF11TileSource), which will be more precise (i.e. the 'right + // 50% of 11px' case') and easier to pre-bake without worring about + // different browsers' decimal precision (if desired). + iiif_size = level_width + "," + level_height, + + //## iiif region iiif_tile_size_width = Math.ceil( this.tileSize / scale ), iiif_tile_size_height = Math.ceil( this.tileSize / scale ), @@ -169,6 +174,7 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { iiif_tile_w, iiif_tile_h; + if ( level_width < this.tile_width && level_height < this.tile_height ){ iiif_region = 'full'; From bccbf5ecf1e646f185e74ca6538e2509a157ab98 Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Wed, 11 Sep 2013 13:40:00 -0400 Subject: [PATCH 08/15] configureFromObject uses @id --- src/iiif11tilesource.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/iiif11tilesource.js b/src/iiif11tilesource.js index fde83d72..bbef643d 100644 --- a/src/iiif11tilesource.js +++ b/src/iiif11tilesource.js @@ -218,12 +218,7 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { } */ function configureFromObject( tileSource, configuration ){ - //the image_host property is not part of the iiif standard but is included here to - //allow the info.json and info.xml specify a different server to load the - //images from so we can test the implementation. - if( configuration.image_host ){ - configuration.tilesUrl = configuration.image_host; - } + configuration.tilesUrl = configuration["@id"]; return configuration; } From 890ec0c848fce0cf9ad3af97de134e82c42c3766 Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Tue, 17 Sep 2013 14:17:01 -0400 Subject: [PATCH 09/15] fixed size param --- src/iiif11tilesource.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/iiif11tilesource.js b/src/iiif11tilesource.js index bbef643d..2fd850fb 100644 --- a/src/iiif11tilesource.js +++ b/src/iiif11tilesource.js @@ -162,8 +162,9 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { // IIIF11TileSource), which will be more precise (i.e. the 'right // 50% of 11px' case') and easier to pre-bake without worring about // different browsers' decimal precision (if desired). - iiif_size = level_width + "," + level_height, + // iiif_size = level_width + "," + level_height, + iiif_size = this.tileSize + "," + this.tileSize, //## iiif region iiif_tile_size_width = Math.ceil( this.tileSize / scale ), @@ -174,7 +175,7 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { iiif_tile_w, iiif_tile_h; - + if ( level_width < this.tile_width && level_height < this.tile_height ){ iiif_region = 'full'; From 1a52656ed672d17bab76a06c3d33a339905964ab Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Wed, 25 Sep 2013 09:45:45 -0400 Subject: [PATCH 10/15] supports IIIF 1.1 syntax --- src/iiif11tilesource.js | 115 +++++++++------------------------------- 1 file changed, 26 insertions(+), 89 deletions(-) diff --git a/src/iiif11tilesource.js b/src/iiif11tilesource.js index 2fd850fb..98fe722b 100644 --- a/src/iiif11tilesource.js +++ b/src/iiif11tilesource.js @@ -32,18 +32,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* - * The getTileUrl implementation is based on Jon Stroop's Python version, - * which is released under the New BSD license: - * https://gist.github.com/jpstroop/4624253 - */ - - (function( $ ){ /** * A client implementation of the International Image Interoperability - * Format: Image API Draft 0.2 - Please read more about the specification + * Format: Image API 1.1 - Please read more about the specification * at * * @class @@ -58,11 +51,6 @@ $.IIIF11TileSource = function( options ){ throw new Error('IIIF required parameters not provided.'); } - //TODO: at this point the base tile source implementation assumes - // a tile is a square and so only has one property tileSize - // to store it. It may be possible to make tileSize a vector - // OpenSeadraon.Point but would require careful implementation - // to preserve backward compatibility. options.tileSize = this.tile_width; if (! options.maxLevel ) { @@ -104,39 +92,27 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { * * @function * @name OpenSeadragon.IIIF11TileSource.prototype.configure - * @param {Object|XMLDocument} data - the raw configuration - * @param {String} url - the url the data was retreived from if any. - * @return {Object} options - A dictionary of keyword arguments sufficient - * to configure this tile source via it's constructor. + * @param {Object} data - the raw configuration */ - configure: function( data, url ){ - // var service, - // options, - // host; - - - // options = configureFromObject( this, data ); - - // if( url && !options.tilesUrl ){ - // service = url.split('/'); - // service.pop(); //info.json - // service = service.join('/'); - // if( 'http' !== url.substring( 0, 4 ) ){ - // host = location.protocol + '//' + location.host; - // service = host + service; - // } - // options.tilesUrl = service.replace( - // data.identifier, - // '' - // ); - // } - - return configureFromObject( this, data ); + // IIIF 1.1 Info Looks like this (XML syntax is no more): + // { + // "@context" : "http://library.stanford.edu/iiif/image-api/1.1/context.json", + // "@id" : "http://iiif.example.com/prefix/1E34750D-38DB-4825-A38A-B60A345E591C", + // "width" : 6000, + // "height" : 4000, + // "scale_factors" : [ 1, 2, 4 ], + // "tile_width" : 1024, + // "tile_height" : 1024, + // "formats" : [ "jpg", "png" ], + // "qualities" : [ "native", "grey" ] + // "profile" : "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0" + // } + configure: function( data ){ + return data; }, - /** * Responsible for retreiving the url which will return an image for the - * region speified by the given x, y, and level components. + * region specified by the given x, y, and level components. * @function * @name OpenSeadragon.IIIF11TileSource.prototype.getTileUrl * @param {Number} level - z index @@ -157,15 +133,6 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { level_width = Math.ceil( this.width * scale ), level_height = Math.ceil( this.height * scale ), - //## get iiif size - // Note that this uses pixels rather than percents (as in - // IIIF11TileSource), which will be more precise (i.e. the 'right - // 50% of 11px' case') and easier to pre-bake without worring about - // different browsers' decimal precision (if desired). - - // iiif_size = level_width + "," + level_height, - iiif_size = this.tileSize + "," + this.tileSize, - //## iiif region iiif_tile_size_width = Math.ceil( this.tileSize / scale ), iiif_tile_size_height = Math.ceil( this.tileSize / scale ), @@ -173,54 +140,24 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { iiif_tile_x, iiif_tile_y, iiif_tile_w, - iiif_tile_h; - - + iiif_tile_h, + iiif_size, + uri; if ( level_width < this.tile_width && level_height < this.tile_height ){ + iiif_size = level_width + "," + level_height; iiif_region = 'full'; } else { iiif_tile_x = x * iiif_tile_size_width; iiif_tile_y = y * iiif_tile_size_height; iiif_tile_w = Math.min( iiif_tile_size_width, this.width - iiif_tile_x ); iiif_tile_h = Math.min( iiif_tile_size_height, this.height - iiif_tile_y ); + iiif_size = Math.ceil(iiif_tile_w * scale) + "," + Math.ceil(iiif_tile_h * scale); iiif_region = [ iiif_tile_x, iiif_tile_y, iiif_tile_w, iiif_tile_h ].join(','); } - - return [ - this['@id'], - iiif_region, - iiif_size, - IIIF_ROTATION, - IIIF_QUALITY - ].join('/'); + uri = [ this['@id'], iiif_region, iiif_size, IIIF_ROTATION, IIIF_QUALITY ].join('/'); + return uri; } - - -}); - - -/** - * @private - * @inner - * @function - * -{ - "@context" : "http://library.stanford.edu/iiif/image-api/1.1/context.json", - "@id" : "http://iiif.example.com/prefix/1E34750D-38DB-4825-A38A-B60A345E591C", - "width" : 6000, - "height" : 4000, - "scale_factors" : [ 1, 2, 4 ], - "tile_width" : 1024, - "tile_height" : 1024, - "formats" : [ "jpg", "png" ], - "qualities" : [ "native", "grey" ] - "profile" : "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0" -} - */ -function configureFromObject( tileSource, configuration ){ - configuration.tilesUrl = configuration["@id"]; - return configuration; -} + }); }( OpenSeadragon )); From e4bd874b03cba1e5419f4e9aee3e4534b02e237c Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Thu, 26 Sep 2013 17:24:02 -0400 Subject: [PATCH 11/15] added test for 1.1; renamed 11 to 1_1 --- Gruntfile.js | 2 +- ...if11tilesource.js => iiif1_1tilesource.js} | 12 ++++----- test/data/iiif1_1.json | 27 +++++++++++++++++++ test/formats.js | 7 +++++ 4 files changed, 41 insertions(+), 7 deletions(-) rename src/{iiif11tilesource.js => iiif1_1tilesource.js} (94%) create mode 100644 test/data/iiif1_1.json diff --git a/Gruntfile.js b/Gruntfile.js index ce91ac8a..419752e4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -34,7 +34,7 @@ module.exports = function(grunt) { "src/tilesource.js", "src/dzitilesource.js", "src/iiiftilesource.js", - "src/iiif11tilesource.js", + "src/iiif1_1tilesource.js", "src/osmtilesource.js", "src/tmstilesource.js", "src/legacytilesource.js", diff --git a/src/iiif11tilesource.js b/src/iiif1_1tilesource.js similarity index 94% rename from src/iiif11tilesource.js rename to src/iiif1_1tilesource.js index 98fe722b..6e022d3b 100644 --- a/src/iiif11tilesource.js +++ b/src/iiif1_1tilesource.js @@ -1,5 +1,5 @@ /* - * OpenSeadragon - IIIF11TileSource + * OpenSeadragon - IIIF1_1TileSource * * Copyright (C) 2009 CodePlex Foundation * Copyright (C) 2010-2013 OpenSeadragon contributors @@ -43,7 +43,7 @@ * @extends OpenSeadragon.TileSource * @see http://library.stanford.edu/iiif/image-api/ */ -$.IIIF11TileSource = function( options ){ +$.IIIF1_1TileSource = function( options ){ $.extend( true, this, options ); @@ -69,12 +69,12 @@ $.IIIF11TileSource = function( options ){ $.TileSource.apply( this, [ options ] ); }; -$.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { +$.extend( $.IIIF1_1TileSource.prototype, $.TileSource.prototype, { /** * Determine if the data and/or url imply the image service is supported by * this tile source. * @function - * @name OpenSeadragon.IIIF11TileSource.prototype.supports + * @name OpenSeadragon.IIIF1_1TileSource.prototype.supports * @param {Object|Array} data * @param {String} optional - url */ @@ -91,7 +91,7 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { /** * * @function - * @name OpenSeadragon.IIIF11TileSource.prototype.configure + * @name OpenSeadragon.IIIF1_1TileSource.prototype.configure * @param {Object} data - the raw configuration */ // IIIF 1.1 Info Looks like this (XML syntax is no more): @@ -114,7 +114,7 @@ $.extend( $.IIIF11TileSource.prototype, $.TileSource.prototype, { * Responsible for retreiving the url which will return an image for the * region specified by the given x, y, and level components. * @function - * @name OpenSeadragon.IIIF11TileSource.prototype.getTileUrl + * @name OpenSeadragon.IIIF1_1TileSource.prototype.getTileUrl * @param {Number} level - z index * @param {Number} x * @param {Number} y diff --git a/test/data/iiif1_1.json b/test/data/iiif1_1.json new file mode 100644 index 00000000..5a33ce73 --- /dev/null +++ b/test/data/iiif1_1.json @@ -0,0 +1,27 @@ +{ + "profile": "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", + "scale_factors": [ + 1, + 2, + 4, + 8, + 16 + ], + "tile_height": 256, + "height": 3600, + "width": 2584, + "tile_width": 256, + "qualities": [ + "native", + "bitonal", + "grey", + "color" + ], + "formats": [ + "jpg", + "png", + "gif" + ], + "@context": "http://library.stanford.edu/iiif/image-api/1.1/context.json", + "@id": "http://libimages.princeton.edu/loris/pudl0071%2F4055459%2F01%2F00000030.jp2" +} \ No newline at end of file diff --git a/test/formats.js b/test/formats.js index 0c673bcf..8258c386 100644 --- a/test/formats.js +++ b/test/formats.js @@ -65,4 +65,11 @@ testOpen('testpattern.xml'); }); + // ---------- + asyncTest('IIIF 1.1 JSON', function() { + testOpen('iiif1_1.json'); + }); + + + })(); From 4a00a62dd850fd006f818307e47765ea3a4491f7 Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Sat, 28 Sep 2013 06:46:41 -0400 Subject: [PATCH 12/15] Adding iiif 1.0 info samples --- test/data/iiif1_0.json | 26 ++++++++++++++++++++++++++ test/data/iiif1_0.xml | 1 + 2 files changed, 27 insertions(+) create mode 100644 test/data/iiif1_0.json create mode 100644 test/data/iiif1_0.xml diff --git a/test/data/iiif1_0.json b/test/data/iiif1_0.json new file mode 100644 index 00000000..9cfe9e54 --- /dev/null +++ b/test/data/iiif1_0.json @@ -0,0 +1,26 @@ +{ + "identifier": "pudl0071/4055459/01/00000030", + "width": 2584, + "height": 3600, + "scale_factors": [ + 1, + 2, + 3, + 4, + 5 + ], + "tile_width": 256, + "tile_height": 256, + "formats": [ + "jpg", + "png" + ], + "qualities": [ + "native", + "bitonal", + "grey", + "color" + ], + "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1", + "image_host": "http://img.princeton.edu/loris +} \ No newline at end of file diff --git a/test/data/iiif1_0.xml b/test/data/iiif1_0.xml new file mode 100644 index 00000000..f6963492 --- /dev/null +++ b/test/data/iiif1_0.xml @@ -0,0 +1 @@ +pudl0071/4055459/01/000000302584360012345256256jpgpngnativebitonalgreycolorhttp://library.stanford.edu/iiif/image-api/compliance.html#level1http://img.princeton.edu/loris \ No newline at end of file From 8099f8a80312f13b5f8552b92f51dfb83089bfca Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Mon, 30 Sep 2013 19:42:16 -0400 Subject: [PATCH 13/15] applied iangilman\'s patch --- test/data/iiif1_0.json | 6 +++--- test/data/iiif1_0.xml | 2 +- test/formats.js | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/test/data/iiif1_0.json b/test/data/iiif1_0.json index 9cfe9e54..2c55544c 100644 --- a/test/data/iiif1_0.json +++ b/test/data/iiif1_0.json @@ -1,5 +1,5 @@ { - "identifier": "pudl0071/4055459/01/00000030", + "identifier": "pudl0001/4609321/s42/00000001", "width": 2584, "height": 3600, "scale_factors": [ @@ -22,5 +22,5 @@ "color" ], "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1", - "image_host": "http://img.princeton.edu/loris -} \ No newline at end of file + "image_host": "http://lorisimg.princeton.edu/loris" +} diff --git a/test/data/iiif1_0.xml b/test/data/iiif1_0.xml index f6963492..3e7f931f 100644 --- a/test/data/iiif1_0.xml +++ b/test/data/iiif1_0.xml @@ -1 +1 @@ -pudl0071/4055459/01/000000302584360012345256256jpgpngnativebitonalgreycolorhttp://library.stanford.edu/iiif/image-api/compliance.html#level1http://img.princeton.edu/loris \ No newline at end of file +pudl0001/4609321/s42/000000012584360012345256256jpgpngnativebitonalgreycolorhttp://library.stanford.edu/iiif/image-api/compliance.html#level1http://lorisimg.princeton.edu/loris diff --git a/test/formats.js b/test/formats.js index 8258c386..7a81c4f7 100644 --- a/test/formats.js +++ b/test/formats.js @@ -65,11 +65,19 @@ testOpen('testpattern.xml'); }); + // ---------- + asyncTest('IIIF 1.0 JSON', function() { + testOpen('iiif1_0.json'); + }); + + // ---------- + asyncTest('IIIF 1.0 XML', function() { + testOpen('iiif1_0.xml'); + }); + // ---------- asyncTest('IIIF 1.1 JSON', function() { testOpen('iiif1_1.json'); }); - - })(); From 33abd1b149b850bc453cb6e590554c589ce9ac06 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Tue, 1 Oct 2013 15:10:21 -0700 Subject: [PATCH 14/15] Revert "changelog update for new event names" This reverts commit c38b7aae4af4ca2c528b80ce8868f70b66e4037e. --- changelog.txt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/changelog.txt b/changelog.txt index d0770e88..46e84e18 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,19 +3,11 @@ OPENSEADRAGON CHANGELOG 1.0.0: (in progress) -* BREAKING CHANGE: Renamed EventHandler to EventSource (#225) -* BREAKING CHANGE: MouseTracker event handler method signatures changed to 'handlerMethod( tracker, eventData)' (#23) -* BREAKING CHANGE: Button event names changed to lower case, removed "on" prefix (#226): -* "onPress" is now "press" -* "onRelease" is now "release" -* "onClick" is now "click" -* "onEnter" is now "enter" -* "onExit" is now "exit" -* "onFocus" is now "focus" -* "onBlur" is now "blur" * MouseTracker now passes the original event objects to its handler methods (#23) +* Breaking change: MouseTracker event handler method signatures changed to 'handlerMethod( tracker, eventData)' (#23) * MouseTracker now supports an optional 'moveHandler' method for tracking mousemove events (#215) * Fixed: Element-relative mouse coordinates now correct if the element and/or page is scrolled (using new OpenSeadragon.getElementOffset() method) (#131) +* Renamed EventHandler to EventSource (#225) 0.9.131: From e49aa5be0b0f53b522905e55efc15402adf1b6dd Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Tue, 1 Oct 2013 15:19:22 -0700 Subject: [PATCH 15/15] changelog.txt update for changed event names --- changelog.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/changelog.txt b/changelog.txt index 6dcb9637..1ea02eb6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,16 @@ OPENSEADRAGON CHANGELOG * BREAKING CHANGE: Renamed EventHandler to EventSource (#225) * BREAKING CHANGE: MouseTracker event handler method signatures changed to 'handlerMethod( tracker, eventData)' (#23) +* BREAKING CHANGE: Event names changed for consistency: changed to lower case, compound names hyphenated, and "on" prefixes removed (#226): +* Viewer "animationstart" changed to "animation-start" +* Viewer "animationfinish" changed to "animation-finish" +* Button "onPress" changed to "press" +* Button "onRelease" changed to "release" +* Button "onClick" changed to "click" +* Button "onEnter" changed to "enter" +* Button "onExit" changed to "exit" +* Button "onFocus" changed to "focus" +* Button "onBlur" changed to "blur" * MouseTracker now passes the original event objects to its handler methods (#23) * MouseTracker now supports an optional 'moveHandler' method for tracking mousemove events (#215) * Fixed: Element-relative mouse coordinates now correct if the element and/or page is scrolled (using new OpenSeadragon.getElementOffset() method) (#131)