From df86a3312f4d50a5ffde5aa2f95f975bd6623d46 Mon Sep 17 00:00:00 2001 From: polesye Date: Mon, 19 Jan 2015 15:40:55 +0200 Subject: [PATCH] TNL-1132: Fix viewer behaviour on hover. --- lms/static/js/edxnotes/views/shim.js | 18 ++++++++++++++++++ lms/static/js/spec/edxnotes/views/shim_spec.js | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/lms/static/js/edxnotes/views/shim.js b/lms/static/js/edxnotes/views/shim.js index 3f7e3f861f..3c318c97e3 100644 --- a/lms/static/js/edxnotes/views/shim.js +++ b/lms/static/js/edxnotes/views/shim.js @@ -125,6 +125,24 @@ define(['jquery', 'underscore', 'annotator'], function ($, _, Annotator) { Annotator.prototype._setupViewer ); + Annotator.Editor.prototype.isShown = Annotator.Viewer.prototype.isShown; + + /** + * Modifies Annotator.onHighlightMouseover to avoid showing the viewer if the + * editor is opened. + **/ + Annotator.prototype.onHighlightMouseover = _.wrap( + Annotator.prototype.onHighlightMouseover, + function (func, event) { + // Do nothing if the editor is opened. + if (this.editor.isShown()) { + return false; + } + return func.call(this, event); + }, + Annotator.prototype._setupViewer + ); + $.extend(true, Annotator.prototype, { events: { '.annotator-hl click': 'onHighlightClick', diff --git a/lms/static/js/spec/edxnotes/views/shim_spec.js b/lms/static/js/spec/edxnotes/views/shim_spec.js index 3e6208b2e8..25cf191da3 100644 --- a/lms/static/js/spec/edxnotes/views/shim_spec.js +++ b/lms/static/js/spec/edxnotes/views/shim_spec.js @@ -49,6 +49,13 @@ define([ _.invoke(Annotator._instances, 'destroy'); }); + it('does not show the viewer if the editor is opened', function() { + annotators[0].showEditor({}, {}); + highlights[0].mouseover(); + expect($('#edx-notes-wrapper-123 .annotator-editor')).not.toHaveClass('annotator-hide'); + expect($('#edx-notes-wrapper-123 .annotator-viewer')).toHaveClass('annotator-hide'); + }); + it('clicking a highlight freezes mouseover and mouseout in all highlighted text', function() { _.each(annotators, function(annotator) { expect(annotator.isFrozen).toBe(false);