Alternate images (m2)

This commit is contained in:
Ian Gilman 2015-02-10 14:02:41 -08:00
parent 5443eedebc
commit ae7adad5cf
4 changed files with 103 additions and 7 deletions

View File

@ -10,11 +10,12 @@ http://showcase.iiif.io/viewer/mirador/
## To Do ## To Do
* Choosing between multiple versions of a page
* Detail images overlaid on the page * Detail images overlaid on the page
* Cropped images * Cropped images
### Maybe ### Maybe
* Alternates: align with default image
* Alternates: wait until tiles have loaded before switching
* Show/hide pages? * Show/hide pages?
* Lazyloading tilesources? * Lazyloading tilesources?

View File

@ -6,6 +6,7 @@
<script type="text/javascript" src='../../lib/jquery-1.9.1.min.js'></script> <script type="text/javascript" src='../../lib/jquery-1.9.1.min.js'></script>
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="js/main.js"></script> <script src="js/main.js"></script>
<script src="js/page.js"></script>
<!-- <script src="js/harvard-tilesources.js"></script> --> <!-- <script src="js/harvard-tilesources.js"></script> -->
<script src="js/openseadragon-svg-overlay.js"></script> <script src="js/openseadragon-svg-overlay.js"></script>
<style type="text/css"> <style type="text/css">

View File

@ -19,16 +19,27 @@
'page' 'page'
]; ];
this.pages = this.createPages();
var tileSources = $.map(this.pages, function(v, i) {
return v.tileSource;
});
this.viewer = OpenSeadragon({ this.viewer = OpenSeadragon({
id: "contentDiv", id: "contentDiv",
prefixUrl: "../../../build/openseadragon/images/", prefixUrl: "../../../build/openseadragon/images/",
autoResize: false, autoResize: false,
showHomeControl: false, showHomeControl: false,
tileSources: this.getTileSources() tileSources: tileSources
}); });
this.viewer.addHandler('open', function() { this.viewer.addHandler('open', function() {
self.$el = $(self.viewer.element); self.$el = $(self.viewer.element);
$.each(self.pages, function(i, v) {
v.tiledImage = self.viewer.world.getItemAt(i);
});
self.setMode({ self.setMode({
mode: 'thumbs', mode: 'thumbs',
immediately: true immediately: true
@ -40,6 +51,7 @@
var result = self.hitTest(self.viewer.viewport.getCenter()); var result = self.hitTest(self.viewer.viewport.getCenter());
if (result) { if (result) {
self.page = result.index; self.page = result.index;
self.update();
} }
} }
}); });
@ -216,6 +228,37 @@
$.each(this.modeNames, function(i, v) { $.each(this.modeNames, function(i, v) {
$('.' + v).toggleClass('active', v === self.mode); $('.' + v).toggleClass('active', v === self.mode);
}); });
// alternates menu
if (this.$alternates) {
this.$alternates.remove();
this.$alternates = null;
}
var page = this.pages[this.page];
if (page && page.alternates && page.alternates.length) {
this.$alternates = $('<select>')
.change(function() {
page.selectAlternate(parseInt(self.$alternates.val(), 10));
})
.appendTo('.nav');
$('<option>')
.attr('value', -1)
.text(page.label || 'Default')
.appendTo(self.$alternates);
$.each(page.alternates, function(i, v) {
if (v.label) {
$('<option>')
.attr('value', i)
.text(v.label)
.appendTo(self.$alternates);
}
});
this.$alternates.val(page.alternateIndex);
}
}, },
// ---------- // ----------
@ -585,10 +628,14 @@
}, },
// ---------- // ----------
getTileSources: function() { createPages: function() {
var self = this;
if (this.tileSources) { if (this.tileSources) {
return $.map(this.tileSources.slice(0, this.maxImages), function(v, i) { return $.map(this.tileSources.slice(0, this.maxImages), function(v, i) {
return new OpenSeadragon.IIIFTileSource(v); return new self.Page($.extend({
pageIndex: i
}, v));
}); });
} }
@ -656,12 +703,15 @@
} }
]; ];
var outputs = []; var pages = [];
for (var i = 0; i < this.maxImages; i++) { for (var i = 0; i < this.maxImages; i++) {
outputs.push(inputs[Math.floor(Math.random() * inputs.length)]); pages.push(new this.Page({
pageIndex: i,
tileSource: inputs[Math.floor(Math.random() * inputs.length)]
}));
} }
return outputs; return pages;
} }
}; };

44
test/demo/m2/js/page.js Normal file
View File

@ -0,0 +1,44 @@
/* global App */
(function() {
// ----------
var component = App.Page = function(config) {
this.label = config.label;
this.tileSource = config.tileSource;
this.alternates = config.alternates;
this.pageIndex = config.pageIndex;
this.alternateIndex = -1;
};
// ----------
component.prototype = {
// ----------
selectAlternate: function(index) {
var self = this;
if (index === this.alternateIndex) {
return;
}
var tileSource = (index === -1 ? this.tileSource : this.alternates[index].tileSource);
var tiledImage = App.viewer.world.getItemAt(this.pageIndex);
var bounds = tiledImage.getBounds();
App.viewer.world.removeItem(tiledImage);
App.viewer.addTiledImage({
tileSource: tileSource,
x: bounds.x,
y: bounds.y,
height: bounds.height,
index: this.pageIndex,
success: function(event) {
self.tiledImage = event.item;
}
});
this.alternateIndex = index;
}
};
})();