From ad20429c64c779a990df50fffbfe96d0d69b6157 Mon Sep 17 00:00:00 2001 From: aeschylus Date: Mon, 7 Nov 2016 14:15:43 -0800 Subject: [PATCH] Revert "Fix mistake in french locale" --- js/src/annotations/annotationTooltip.js | 10 +- js/src/annotations/osd-region-draw-tool.js | 30 ++-- js/src/annotations/osd-svg-overlay.js | 7 - js/src/utils/jsonLd.js | 68 ++------- js/src/widgets/annotationsLayer.js | 2 - js/src/widgets/imageView.js | 3 +- js/src/widgets/sidePanel.js | 7 + js/src/workspace.js | 1 - js/src/workspaces/slot.js | 139 +++++++++---------- js/src/workspaces/window.js | 81 +++++------ locales/fr/translation.json | 4 +- spec/{ => annotations}/event-emitter.stub.js | 0 spec/utils/jsonLd.test.js | 46 ------ spec/widgets/sidePanel.test.js | 42 +----- spec/workspaces/slot.test.js | 28 ++-- spec/workspaces/window.test.js | 28 +--- 16 files changed, 152 insertions(+), 344 deletions(-) rename spec/{ => annotations}/event-emitter.stub.js (100%) diff --git a/js/src/annotations/annotationTooltip.js b/js/src/annotations/annotationTooltip.js index 94903797b1..19b1c469e9 100644 --- a/js/src/annotations/annotationTooltip.js +++ b/js/src/annotations/annotationTooltip.js @@ -153,19 +153,19 @@ event: false }, events: { - shown: function(event, api) { + show: function(event, api) { if (params.onTooltipShown) { params.onTooltipShown(event, api); } }, hidden: function(event, api) { if (params.onTooltipHidden) { params.onTooltipHidden(event, api); } - _this.removeAllEvents(api, params); }, visible: function (event, api) { + _this.removeAllEvents(api, params); _this.addViewerEvents(api, params); }, move: function (event, api) { - // _this.removeAllEvents(api, params); - // _this.addViewerEvents(api, params); + _this.removeAllEvents(api, params); + _this.addViewerEvents(api, params); } } }); @@ -232,8 +232,6 @@ _this.addEditorEvents(api, viewerParams); } else { _this.eventEmitter.publish('annotationInEditMode.' + _this.windowId,[oaAnno]); - api.destroy(); - jQuery(api.tooltip).remove(); } _this.eventEmitter.publish('SET_ANNOTATION_EDITING.' + _this.windowId, { diff --git a/js/src/annotations/osd-region-draw-tool.js b/js/src/annotations/osd-region-draw-tool.js index de1d38db43..64755502a5 100644 --- a/js/src/annotations/osd-region-draw-tool.js +++ b/js/src/annotations/osd-region-draw-tool.js @@ -76,38 +76,37 @@ } }, - render: function () { - - if(this.parent.mode !== $.AnnotationsLayer.DISPLAY_ANNOTATIONS){ - return ; - } + render: function() { this.svgOverlay.restoreEditedShapes(); this.svgOverlay.paperScope.activate(); this.svgOverlay.paperScope.project.clear(); var _this = this; _this.annotationsToShapesMap = {}; - - for (var i = 0; i < this.list.length; i++) { - var shapeArray; - var annotation = this.list[i]; + var deferreds = jQuery.map(this.list, function(annotation) { + var deferred = jQuery.Deferred(), + shapeArray; if (annotation.on && typeof annotation.on === 'object') { if (!annotation.on.selector) { - continue; + return deferred; } else if (annotation.on.selector.value.indexOf(' 0) { _this.annotationsList.pop(); @@ -231,21 +229,6 @@ this.bottomPanelVisibility(this.bottomPanelVisible); } this.sidePanelVisibility(this.sidePanelVisible, '0s'); - - this.events.push(this.eventEmitter.subscribe('windowRemoved',function(event,id){ - if(_this.id === id){ - _this.destroy(); - } - })); - }, - - destroy:function(){ - var _this = this; - this.events.forEach(function(event){ - _this.eventEmitter.unsubscribe(event.name,event.handler); - }); - - this.element.remove(); }, update: function(options) { @@ -283,15 +266,15 @@ } }); - _this.events.push(_this.eventEmitter.subscribe('HIDE_REMOVE_OBJECT.' + _this.id, function(event) { + _this.eventEmitter.subscribe('HIDE_REMOVE_OBJECT.' + _this.id, function(event) { _this.element.find('.remove-object-option').hide(); - })); + }); - _this.events.push(this.eventEmitter.subscribe('SHOW_REMOVE_OBJECT.' + _this.id, function(event) { + _this.eventEmitter.subscribe('SHOW_REMOVE_OBJECT.' + _this.id, function(event) { _this.element.find('.remove-object-option').show(); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('sidePanelStateUpdated.' + this.id, function(event, state) { + _this.eventEmitter.subscribe('sidePanelStateUpdated.' + this.id, function(event, state) { if (state.open) { _this.element.find('.mirador-icon-toc').addClass('selected'); _this.element.find('.view-container').removeClass('maximised'); @@ -299,57 +282,57 @@ _this.element.find('.mirador-icon-toc').removeClass('selected'); _this.element.find('.view-container').addClass('maximised'); } - })); + }); // TODO: temporary logic to minimize side panel if only tab is toc and toc is empty - _this.events.push(_this.eventEmitter.subscribe('sidePanelVisibilityByTab.' + this.id, function(event, visible) { + _this.eventEmitter.subscribe('sidePanelVisibilityByTab.' + this.id, function(event, visible) { _this.sidePanelVisibility(visible, '0s'); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('SET_CURRENT_CANVAS_ID.' + this.id, function(event, canvasID) { + _this.eventEmitter.subscribe('SET_CURRENT_CANVAS_ID.' + this.id, function(event, canvasID) { _this.setCurrentCanvasID(canvasID); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('REMOVE_CLASS.' + this.id, function(event, className) { + _this.eventEmitter.subscribe('REMOVE_CLASS.' + this.id, function(event, className) { _this.element.find('.view-container').removeClass(className); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('ADD_CLASS.' + this.id, function(event, className) { + _this.eventEmitter.subscribe('ADD_CLASS.' + this.id, function(event, className) { _this.element.find('.view-container').addClass(className); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('UPDATE_FOCUS_IMAGES.' + this.id, function(event, images) { + _this.eventEmitter.subscribe('UPDATE_FOCUS_IMAGES.' + this.id, function(event, images) { _this.updateFocusImages(images.array); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('HIDE_ICON_TOC.' + this.id, function(event) { + _this.eventEmitter.subscribe('HIDE_ICON_TOC.' + this.id, function(event) { _this.element.find('.mirador-icon-toc').hide(); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('SHOW_ICON_TOC.' + this.id, function(event) { + _this.eventEmitter.subscribe('SHOW_ICON_TOC.' + this.id, function(event) { _this.element.find('.mirador-icon-toc').show(); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('SET_BOTTOM_PANEL_VISIBILITY.' + this.id, function(event, visibility) { + _this.eventEmitter.subscribe('SET_BOTTOM_PANEL_VISIBILITY.' + this.id, function(event, visibility) { if (typeof visibility !== 'undefined' && visibility !== null) { _this.bottomPanelVisibility(visibility); } else { _this.bottomPanelVisibility(_this.bottomPanelVisible); } - })); + }); - _this.events.push(_this.eventEmitter.subscribe('TOGGLE_BOTTOM_PANEL_VISIBILITY.' + this.id, function(event) { + _this.eventEmitter.subscribe('TOGGLE_BOTTOM_PANEL_VISIBILITY.' + this.id, function(event) { var visible = !_this.bottomPanelVisible; _this.bottomPanelVisibility(visible); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('DISABLE_WINDOW_FULLSCREEN', function(event) { + _this.eventEmitter.subscribe('DISABLE_WINDOW_FULLSCREEN', function(event) { _this.element.find('.mirador-osd-fullscreen').hide(); - })); + }); - _this.events.push(_this.eventEmitter.subscribe('ENABLE_WINDOW_FULLSCREEN', function(event) { + _this.eventEmitter.subscribe('ENABLE_WINDOW_FULLSCREEN', function(event) { _this.element.find('.mirador-osd-fullscreen').show(); - })); + }); }, bindEvents: function() { @@ -402,10 +385,10 @@ _this.eventEmitter.subscribe('annotationUpdated.'+_this.id, function(event, oaAnno) { //first function is success callback, second is error callback - _this.endpoint.update(oaAnno, function(data) { + _this.endpoint.update(oaAnno, function() { jQuery.each(_this.annotationsList, function(index, value) { - if (value['@id'] === data['@id']) { - _this.annotationsList[index] = data; + if (value['@id'] === oaAnno['@id']) { + _this.annotationsList[index] = oaAnno; return false; } }); @@ -823,7 +806,7 @@ _this.endpoint.set('dfd', dfd); } else { options.dfd = dfd; - options.windowIDwindowID = _this.id; + options.windowID = _this.id; options.imagesList = _this.imagesList; options.eventEmitter = _this.eventEmitter; _this.endpoint = new $[module](options); diff --git a/locales/fr/translation.json b/locales/fr/translation.json index 4fab836ebb..a87aa43a25 100644 --- a/locales/fr/translation.json +++ b/locales/fr/translation.json @@ -1,8 +1,8 @@ { "addItem": "Ajouter un objet", "addNewObject": "Ajouter un objet à partir de son URL", - "addSlotAbove": "Ajouter une fenêtre au-dessus", - "addSlotBelow": "Ajouter une fenêtre en dessous", + "addSlotAbove": "Ajouter une fenêtre en dessous", + "addSlotBelow": "Ajouter une fenêtre au-dessus", "addSlotLeft": "Ajouter une fenêtre à gauche", "addSlotRight": "Ajouter une fenêtre à droite", "addTagsHere": "Ajouter des mots-clés", diff --git a/spec/event-emitter.stub.js b/spec/annotations/event-emitter.stub.js similarity index 100% rename from spec/event-emitter.stub.js rename to spec/annotations/event-emitter.stub.js diff --git a/spec/utils/jsonLd.test.js b/spec/utils/jsonLd.test.js index bd4348c5a8..90aee401ff 100644 --- a/spec/utils/jsonLd.test.js +++ b/spec/utils/jsonLd.test.js @@ -41,51 +41,5 @@ describe('JsonLd', function () { expect(Mirador.JsonLd.getTextValue(sample, 'en')).toEqual("Super waahoo"); expect(Mirador.JsonLd.getTextValue(sample)).toEqual("Super waahoo"); }); - - it('should return all values when no value has a langue associated', function() { - var sample = ['First value', - 'Second value']; - expect(Mirador.JsonLd.getTextValue(sample)).toEqual('First value
Second value'); - }); - - it('should return all values that best match the language preference', function() { - var sample = [ - 'This is a value without a language.', - {'@value': "This is an American value.", - '@language': "en-US"}, - {'@value': "This ia a British value.", - '@language': "en-UK"}, - 'This is another value without a language.', - {'@value': "C'est une valeur française.", - '@language': "fr"}]; - window.navigator.languages = ['en-US', 'en'] - expect(Mirador.JsonLd.getTextValue(sample)).toEqual("This is an American value."); - }); - - it('should pick a language if all values have a language but none match the preference', function() { - var sample = [ - {'@value': "This is an American value.", - '@language': "en-US"}, - {'@value': "This is another American value.", - '@language': "en-US"}, - {'@value': "C'est une valeur française.", - '@language': "fr"}]; - window.navigator.languages = ['de-DE', 'de']; - expect(Mirador.JsonLd.getTextValue(sample)) - .toEqual('This is an American value.
' + - 'This is another American value.'); - }); - - it('should return all values without an associated language if some have one, but none match the preference', function() { - var sample = [ - {'@value': "C'est une valeur française.", - '@language': "fr"}, - 'This is a value without a language.', - 'This is another value without a language.']; - window.navigator.languages = ['en-US', 'en']; - expect(Mirador.JsonLd.getTextValue(sample)) - .toEqual('This is a value without a language.
' + - 'This is another value without a language.'); - }) }); }); diff --git a/spec/widgets/sidePanel.test.js b/spec/widgets/sidePanel.test.js index 0dbaa19f06..1f463c82f8 100644 --- a/spec/widgets/sidePanel.test.js +++ b/spec/widgets/sidePanel.test.js @@ -1,46 +1,16 @@ describe('SidePanel', function() { - - function createSidePanel(sidePanelOptions) { - sidePanelOptions = sidePanelOptions || {}; - - var eventEmitter = new Mirador.EventEmitter(); - var state = new Mirador.SaveController(jQuery.extend( - true, {}, Mirador.DEFAULT_SETTINGS, {eventEmitter: eventEmitter} - )); - var fixture = getJSONFixture('BNF-condorcet-florus-dispersus-manifest.json'); - var manifest = new Mirador.Manifest(fixture['@id'], 'IIIF', fixture); - var canvasID = manifest.getCanvases()[0]['@id']; - var appendTo = jQuery('
'); - - var config = jQuery.extend(true, { - windowId: '380c9e54-7561-4010-a99f-f132f5dc13fd', - state: state, - eventEmitter: eventEmitter, - appendTo: appendTo, - manifest: manifest, - canvasID: canvasID, - layersTabAvailable: false, - tocTabAvailable: false, - annotationsTabAvailable: false, - hasStructures: false - }, sidePanelOptions); - - return new Mirador.SidePanel(config); - } beforeEach(function() { - jasmine.getJSONFixtures().fixturesPath = 'spec/fixtures'; - this.sidePanel = createSidePanel(); + }); afterEach(function() { }); - describe('Initialization', function() { + xdescribe('Initialization', function() { it('should initialize', function() { - expect(this.sidePanel instanceof Mirador.SidePanel).toBeTruthy(); - expect(this.sidePanel.appendTo).toBeTruthy(); + }); }); @@ -64,10 +34,8 @@ describe('SidePanel', function() { }); - describe('render', function() { - it('should render on initialization', function() { - expect(this.sidePanel.appendTo.html()).toBeTruthy(); - }); + xdescribe('render', function() { + }); xdescribe('toggle', function() { diff --git a/spec/workspaces/slot.test.js b/spec/workspaces/slot.test.js index 0755b4c100..baae4f8e74 100644 --- a/spec/workspaces/slot.test.js +++ b/spec/workspaces/slot.test.js @@ -2,13 +2,17 @@ describe('Slot', function () { beforeEach(function () { var windowElement = jQuery('
'); this.appendTo = jQuery('
').append(windowElement); - this.eventEmitter = new MockEventEmitter(new Mirador.EventEmitter()); + this.eventEmitter = new Mirador.EventEmitter(); var mockWindow = { id: 'MOCK_WINDOW_1', element: windowElement }; + var windowConfig = { + state: new Mirador.SaveController(jQuery.extend(true, {}, Mirador.DEFAULT_SETTINGS, {eventEmitter:this.eventEmitter})) + }; + this.slot = new Mirador.Slot({ window: mockWindow, eventEmitter: this.eventEmitter @@ -16,23 +20,13 @@ describe('Slot', function () { }); describe('listenForActions', function () { - it('should respond to slotRemoved event', function () { - spyOn(this.slot, 'clearSlot'); - this.eventEmitter.publish('slotRemoved', { - slotID: this.slot.slotID - }); - expect(this.slot.clearSlot).toHaveBeenCalled(); - }); - }); - - describe('destroyEvents', function () { - it('should unsubscribe from all eventEmitter subscriptions', function () { - this.slot.window = {}; - this.slot.clearSlot(); - for(var key in this.slot.eventEmitter.events){ - expect(this.slot.eventEmitter.events[key]).toBe(0); - } + it('should respond to windowRemoved', function () { + var window = this.slot.window; + expect(this.appendTo.find('#MOCK_WINDOW_1').length).toBe(1); + expect(window.element.attr('id')).toEqual('MOCK_WINDOW_1'); + this.eventEmitter.publish('windowRemoved', 'MOCK_WINDOW_1'); expect(this.slot.window).toBe(undefined); + expect(this.appendTo.find('#MOCK_WINDOW_1').length).toBe(0); }); }); diff --git a/spec/workspaces/window.test.js b/spec/workspaces/window.test.js index f742a94760..198ce95b57 100644 --- a/spec/workspaces/window.test.js +++ b/spec/workspaces/window.test.js @@ -2,12 +2,11 @@ describe('Window', function() { describe('Basic Operation', function() { beforeEach(function() { this.eventEmitter = new Mirador.EventEmitter(); - this.mockedEventEmitter = new MockEventEmitter(this.eventEmitter); this.appendTo = jQuery('
'); Mirador.viewer = { // all of this global state should be // removed as soon as possible. - eventEmitter: this.mockedEventEmitter, + eventEmitter: this.eventEmitter, annotationEndpoints: [], workspace: { slots: [] @@ -91,32 +90,9 @@ describe('Window', function() { expect(bottomPanelCalls.count()).toBe(1); }); }); - - describe('Destroying', function () { - - it('should respond to windowRemoved', function () { - spyOn(this.window,'destroy'); - this.eventEmitter.publish('windowRemoved', this.window.id); - expect(this.window.destroy).toHaveBeenCalled(); - }); - - it('should unsubscribe from all events', function () { - this.window.destroy(); - for(var key in this.window.eventEmitter.events){ - expect(this.window.eventEmitter.events[key]).toBe(0); - } - }); - - it('should remove dom element',function(){ - this.window.destroy(); - expect(this.appendTo.find('.window').length).toBe(0); - }) - - }); - }); describe('Configuration', function() { }); -}); +})