diff --git a/js/src/mirador.js b/js/src/mirador.js index 3f110096f4..ad6c0a576d 100644 --- a/js/src/mirador.js +++ b/js/src/mirador.js @@ -1,5 +1,5 @@ // This file defines the global Mirador constructor function. -// This is the entry point to Miraodr and is intentionally sparse. +// This is the entry point to Mirador and is intentionally sparse. (function(global) { function Mirador(config) { if (this instanceof Mirador) { diff --git a/js/src/settings.js b/js/src/settings.js index 58ac4eb961..fa783ab1d6 100644 --- a/js/src/settings.js +++ b/js/src/settings.js @@ -31,6 +31,7 @@ }, 'manifests' : [], + 'data' : [], 'layout': '1x1', @@ -38,6 +39,9 @@ //only valid if no windowObjects have been initialized //if there are multiple slots, it will be bound to the first slot and the selected manifest will open in that slot + // whether or not to preserve the order of the manifests, as provided in the configuration, in the manifest listing page + 'preserveManifestOrder' : false, + //default window settings, but can be changed in Mirador configuration on initialization 'windowSettings' : { "availableViews" : ['ThumbnailsView', 'ImageView', 'ScrollView', 'BookView'], //any subset removes others diff --git a/js/src/utils/saveController.js b/js/src/utils/saveController.js index c97afb578d..fd090260a5 100755 --- a/js/src/utils/saveController.js +++ b/js/src/utils/saveController.js @@ -34,7 +34,7 @@ this.eventEmitter = config.eventEmitter; - // Don't want to save session, therefore don't set up save controller + // Don't want to save session if (config.saveSession === false) { this.currentConfig = config; this.bindEvents(); @@ -131,6 +131,17 @@ return this.get(prop, 'currentConfig'); }, + getManifestIndex: function(manifestUri) { + var manifestIndex = -1; + jQuery.each(this.currentConfig.data, function(index, dataObj) { + if (dataObj.manifestUri === manifestUri) { + manifestIndex = index; + return false; + } + }); + return manifestIndex; + }, + get: function(prop, parent) { if (parent) { return this[parent][prop]; diff --git a/js/src/viewer/manifestListItem.js b/js/src/viewer/manifestListItem.js index 98a8d82875..f68168a67c 100644 --- a/js/src/viewer/manifestListItem.js +++ b/js/src/viewer/manifestListItem.js @@ -45,7 +45,28 @@ }); this.fetchTplData(this.manifestId); - this.element = jQuery(this.template(this.tplData)).prependTo(this.appendTo).hide().fadeIn('slow'); + + if (_this.state.getStateProperty('preserveManifestOrder')) { + if (this.appendTo.children().length === 0) { + this.element = jQuery(this.template(this.tplData)).prependTo(this.appendTo).hide().fadeIn('slow'); + } else { + var liList = _this.appendTo.find('li'); + jQuery.each(liList, function(index, item) { + var prev = parseFloat(jQuery(item).attr('data-index-number')); + var next = parseFloat(jQuery(liList[index+1]).attr('data-index-number')); + var current = _this.tplData.index; + if (current <= prev && (next > current || isNaN(next)) ) { + _this.element = jQuery(_this.template(_this.tplData)).insertBefore(jQuery(item)).hide().fadeIn('slow'); + return false; + } else if (current > prev && (current < next || isNaN(next))) { + _this.element = jQuery(_this.template(_this.tplData)).insertAfter(jQuery(item)).hide().fadeIn('slow'); + return false; + } + }); + } + } else { + this.element = jQuery(this.template(this.tplData)).prependTo(this.appendTo).hide().fadeIn('slow'); + } this.bindEvents(); this.listenForActions(); @@ -60,7 +81,8 @@ label: $.JsonLd.getTextValue(manifest.label), repository: location, canvasCount: manifest.sequences[0].canvases.length, - images: [] + images: [], + index: _this.state.getManifestIndex(manifest['@id']) }; this.tplData.repoImage = (function() { @@ -224,7 +246,7 @@ }, template: Handlebars.compile([ - '
  • ', + '
  • ', '
    ', 'repoImg', '
    ', diff --git a/spec/viewer/manifestListItem.test.js b/spec/viewer/manifestListItem.test.js index a88ca15931..68ed5f6918 100644 --- a/spec/viewer/manifestListItem.test.js +++ b/spec/viewer/manifestListItem.test.js @@ -1,4 +1,211 @@ describe('ManifestListItem', function () { + + beforeEach(function() { + this.eventEmitter = new Mirador.EventEmitter(); + jasmine.getJSONFixtures().fixturesPath = 'spec/fixtures'; + this.dummyManifestContent = getJSONFixture('dummyManifest.json'); + this.manifest = new Mirador.Manifest(null, 'Dummy Location', this.dummyManifestContent); + this.appendTo = jQuery(''); + }); + + it('insert index 0', function() { + var listItem = new Mirador.ManifestListItem({ + appendTo: this.appendTo, + state: new Mirador.SaveController({ + eventEmitter:this.eventEmitter, + preserveManifestOrder: true, + data: [ + { "manifestUri": "http://www.example.org/iiif/book1/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book2/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book3/manifest"} + ] + }), + eventEmitter: this.eventEmitter, + resultsWidth: 500, + manifest: this.manifest + }); + + var expectedHTML = ''; + + expect(this.appendTo[0].outerHTML).toBe(expectedHTML); + }); + + it('insert index 2', function() { + var listItem = new Mirador.ManifestListItem({ + appendTo: this.appendTo, + state: new Mirador.SaveController({ + eventEmitter:this.eventEmitter, + preserveManifestOrder: true, + data: [ + { "manifestUri": "http://www.example.org/iiif/book2/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book3/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book1/manifest"} + ] + }), + eventEmitter: this.eventEmitter, + resultsWidth: 500, + manifest: this.manifest + }); + + var expectedHTML = ''; + + expect(this.appendTo[0].outerHTML).toBe(expectedHTML); + }); + + it('insert index 6', function() { + var listItem = new Mirador.ManifestListItem({ + appendTo: this.appendTo, + state: new Mirador.SaveController({ + eventEmitter:this.eventEmitter, + preserveManifestOrder: true, + data: [ + { "manifestUri": "http://www.example.org/iiif/book2/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book3/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book4/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book5/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book6/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book7/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book1/manifest"} + ] + }), + eventEmitter: this.eventEmitter, + resultsWidth: 500, + manifest: this.manifest + }); + + var expectedHTML = ''; + + expect(this.appendTo[0].outerHTML).toBe(expectedHTML); + }); + + it('insert index 17', function() { + var listItem = new Mirador.ManifestListItem({ + appendTo: this.appendTo, + state: new Mirador.SaveController({ + eventEmitter:this.eventEmitter, + preserveManifestOrder: true, + data: [ + { "manifestUri": "http://www.example.org/iiif/book2/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book3/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book4/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book5/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book6/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book7/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book8/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book9/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book10/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book11/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book12/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book13/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book14/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book15/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book16/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book17/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book18/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book1/manifest"} + ] + }), + eventEmitter: this.eventEmitter, + resultsWidth: 500, + manifest: this.manifest + }); + + var expectedHTML = ''; + + expect(this.appendTo[0].outerHTML).toBe(expectedHTML); + }); + + it('insert another at index -1', function() { + var listItem = new Mirador.ManifestListItem({ + appendTo: this.appendTo, + state: new Mirador.SaveController({ + eventEmitter:this.eventEmitter, + preserveManifestOrder: true, + data: [ + { "manifestUri": "http://www.example.org/iiif/book2/manifest"}, + { "manifestUri": "http://www.example.org/iiif/book3/manifest"} + ] + }), + eventEmitter: this.eventEmitter, + resultsWidth: 500, + manifest: this.manifest + }); + + var expectedHTML = ''; + + expect(this.appendTo[0].outerHTML).toBe(expectedHTML); + }); + xit('fetchTplData', function () { }); xit('render', function () {