* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * chore: apply amnesty on all existing issues * fix: failing xss-lint issues * refactor: apply amnesty on remaining issues * refactor: apply amnesty on new issues * fix: remove file level suppressions * refactor: apply amnesty on new issues
70 lines
2.8 KiB
JavaScript
70 lines
2.8 KiB
JavaScript
// eslint-disable-next-line no-shadow-restricted-names
|
|
(function(define, undefined) {
|
|
'use strict';
|
|
|
|
define(['jquery', 'underscore', 'annotator_1.2.9'], function($, _, Annotator) {
|
|
/**
|
|
* Adds the Scroller Plugin which scrolls to a note with a certain id and
|
|
* opens it.
|
|
* */
|
|
Annotator.Plugin.Scroller = function() {
|
|
// Call the Annotator.Plugin constructor this sets up the element and
|
|
// options properties.
|
|
Annotator.Plugin.apply(this, arguments);
|
|
};
|
|
|
|
$.extend(Annotator.Plugin.Scroller.prototype, new Annotator.Plugin(), {
|
|
getIdFromLocationHash: function() {
|
|
return window.location.hash.substr(1);
|
|
},
|
|
|
|
pluginInit: function() {
|
|
_.bindAll(this, 'onNotesLoaded');
|
|
// If the page URL contains a hash, we could be coming from a click
|
|
// on an anchor in the notes page. In that case, the hash is the id
|
|
// of the note that has to be scrolled to and opened.
|
|
if (this.getIdFromLocationHash()) {
|
|
this.annotator.subscribe('annotationsLoaded', this.onNotesLoaded);
|
|
}
|
|
},
|
|
|
|
destroy: function() {
|
|
this.annotator.unsubscribe('annotationsLoaded', this.onNotesLoaded);
|
|
},
|
|
|
|
onNotesLoaded: function(notes) {
|
|
var hash = this.getIdFromLocationHash();
|
|
this.annotator.logger.log('Scroller', {
|
|
'notes:': notes,
|
|
hash: hash
|
|
});
|
|
_.each(notes, function(note) {
|
|
var $highlight, offset;
|
|
if (note.id === hash && note.highlights.length) {
|
|
// Clear the page URL hash, it won't be needed once we've
|
|
// scrolled and opened the relevant note. And it would
|
|
// unnecessarily repeat the steps below if we come from
|
|
// another sequential.
|
|
window.location.hash = '';
|
|
$highlight = $(note.highlights[0]);
|
|
offset = $highlight.position();
|
|
// Open the note
|
|
this.annotator.showFrozenViewer([note], {
|
|
top: offset.top + 0.5 * $highlight.height(),
|
|
left: offset.left + 0.5 * $highlight.width()
|
|
});
|
|
// Freeze the viewer
|
|
this.annotator.freezeAll();
|
|
// Scroll to highlight
|
|
this.scrollIntoView($highlight);
|
|
}
|
|
}, this);
|
|
},
|
|
|
|
scrollIntoView: function(highlight) {
|
|
highlight.focus();
|
|
}
|
|
});
|
|
});
|
|
}).call(this, define || RequireJS.define);
|