Commit 7ec94fab authored by Robert Knight's avatar Robert Knight

Separate out sidebar, annotation layer/bootstrap, and shared code into separate directories

Separate out the code for:

 - The sidebar application (now in src/sidebar)
 - The annotation layer and client bootstrap (now in src/annotator)
 - Code shared between the two (now in src/shared)
parent 376decb0
...@@ -94,15 +94,15 @@ var appBundleBaseConfig = { ...@@ -94,15 +94,15 @@ var appBundleBaseConfig = {
}; };
var appBundles = [{ var appBundles = [{
// The sidebar application for displaying and editing annotations // The sidebar application for displaying and editing annotations.
name: 'app', name: 'app',
transforms: ['coffee'], transforms: ['coffee'],
entry: './src/scripts/app', entry: './src/sidebar/app',
},{ },{
// The Annotator library which provides annotation controls on // The annotation layer which handles displaying highlights, presenting
// the page and sets up the sidebar // annotation tools on the page and instantiating the sidebar application.
name: 'injector', name: 'injector',
entry: './src/scripts/annotator/main', entry: './src/annotator/main',
transforms: ['coffee'], transforms: ['coffee'],
}]; }];
...@@ -305,11 +305,11 @@ function runKarma(baseConfig, opts, done) { ...@@ -305,11 +305,11 @@ function runKarma(baseConfig, opts, done) {
} }
gulp.task('test', function (callback) { gulp.task('test', function (callback) {
runKarma('./src/scripts/karma.config.js', {singleRun:true}, callback); runKarma('./src/karma.config.js', {singleRun:true}, callback);
}); });
gulp.task('test-watch', function (callback) { gulp.task('test-watch', function (callback) {
runKarma('./src/scripts/karma.config.js', {}, callback); runKarma('./src/karma.config.js', {}, callback);
}); });
gulp.task('upload-sourcemaps', ['build-js'], function () { gulp.task('upload-sourcemaps', ['build-js'], function () {
......
...@@ -117,9 +117,9 @@ ...@@ -117,9 +117,9 @@
] ]
}, },
"browser": { "browser": {
"annotator": "./src/scripts/vendor/annotator.js", "annotator": "./src/annotator/vendor/annotator.js",
"hammerjs": "./node_modules/hammerjs/hammer.js", "hammerjs": "./node_modules/hammerjs/hammer.js",
"katex": "./src/scripts/vendor/katex.js" "katex": "./src/sidebar/vendor/katex.js"
}, },
"browserify-shim": { "browserify-shim": {
"annotator": { "annotator": {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
module.exports = { module.exports = {
bundles: { bundles: {
jquery: ['jquery'], jquery: ['jquery'],
polyfills: [require.resolve('../../src/scripts/polyfills')], polyfills: [require.resolve('../../src/shared/polyfills')],
angular: [ angular: [
'angular', 'angular',
'angular-jwt', 'angular-jwt',
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
var html = require('../html'); var html = require('../html');
var toResult = require('../../../test/promise-util').toResult; var toResult = require('../../../shared/test/promise-util').toResult;
var unroll = require('../../../test/util').unroll; var unroll = require('../../../shared/test/util').unroll;
var fixture = require('./html-anchoring-fixture.html'); var fixture = require('./html-anchoring-fixture.html');
/** Return all text node children of `container`. */ /** Return all text node children of `container`. */
......
'use strict'; 'use strict';
var annotationIDs = require('../util/annotation-ids'); var annotationIDs = require('./util/annotation-ids');
var settings = require('../settings'); var settings = require('../shared/settings');
var docs = 'https://h.readthedocs.io/en/latest/embedding.html'; var docs = 'https://h.readthedocs.io/en/latest/embedding.html';
......
'use strict'; 'use strict';
require('../polyfills'); require('../shared/polyfills');
var Annotator = require('annotator'); var Annotator = require('annotator');
// Polyfills // Polyfills
// document.evaluate() implementation,
// required by IE 10, 11
//
// This sets `window.wgxpath`
if (!window.document.evaluate) {
require('./vendor/wgxpath.install');
}
var g = Annotator.Util.getGlobal(); var g = Annotator.Util.getGlobal();
if (g.wgxpath) { if (g.wgxpath) {
g.wgxpath.install(); g.wgxpath.install();
...@@ -22,13 +30,13 @@ Annotator.Plugin.Toolbar = require('./plugin/toolbar'); ...@@ -22,13 +30,13 @@ Annotator.Plugin.Toolbar = require('./plugin/toolbar');
// Document type plugins // Document type plugins
Annotator.Plugin.PDF = require('./plugin/pdf'); Annotator.Plugin.PDF = require('./plugin/pdf');
require('../vendor/annotator.document'); // Does not export the plugin :( require('./vendor/annotator.document'); // Does not export the plugin :(
// Cross-frame communication // Cross-frame communication
Annotator.Plugin.CrossFrame = require('./plugin/cross-frame'); Annotator.Plugin.CrossFrame = require('./plugin/cross-frame');
Annotator.Plugin.CrossFrame.AnnotationSync = require('./annotation-sync'); Annotator.Plugin.CrossFrame.AnnotationSync = require('./annotation-sync');
Annotator.Plugin.CrossFrame.Bridge = require('../bridge'); Annotator.Plugin.CrossFrame.Bridge = require('../shared/bridge');
Annotator.Plugin.CrossFrame.Discovery = require('../discovery'); Annotator.Plugin.CrossFrame.Discovery = require('../shared/discovery');
var appLinkEl = var appLinkEl =
document.querySelector('link[type="application/annotator+html"]'); document.querySelector('link[type="application/annotator+html"]');
......
'use strict'; 'use strict';
var observable = require('../util/observable'); var observable = require('./util/observable');
/** Returns the selected `DOMRange` in `document`. */ /** Returns the selected `DOMRange` in `document`. */
function selectedRange(document) { function selectedRange(document) {
......
'use strict'; 'use strict';
var adder = require('../adder'); var adder = require('../adder');
var unroll = require('../../test/util').unroll; var unroll = require('../../shared/test/util').unroll;
function rect(left, top, width, height) { function rect(left, top, width, height) {
return {left: left, top: top, width: width, height: height}; return {left: left, top: top, width: width, height: height};
......
...@@ -2,7 +2,7 @@ Annotator = require('annotator') ...@@ -2,7 +2,7 @@ Annotator = require('annotator')
proxyquire = require('proxyquire') proxyquire = require('proxyquire')
adder = require('../adder') adder = require('../adder')
Observable = require('../../util/observable').Observable Observable = require('../util/observable').Observable
$ = Annotator.$ $ = Annotator.$
Annotator['@noCallThru'] = true; Annotator['@noCallThru'] = true;
......
...@@ -11,7 +11,7 @@ describe 'Host', -> ...@@ -11,7 +11,7 @@ describe 'Host', ->
fakeCrossFrame = null fakeCrossFrame = null
createHost = (options={}, element=null) -> createHost = (options={}, element=null) ->
options = Object.assign({app: '/base/test/empty.html'}, options) options = Object.assign({app: '/base/annotator/test/empty.html'}, options)
if !element if !element
element = document.createElement('div') element = document.createElement('div')
return new Host(element, options) return new Host(element, options)
...@@ -87,7 +87,7 @@ describe 'Host', -> ...@@ -87,7 +87,7 @@ describe 'Host', ->
host.publish('panelReady') host.publish('panelReady')
it 'passes options to the sidebar iframe', -> it 'passes options to the sidebar iframe', ->
appURL = new URL('/base/test/empty.html', window.location.href) appURL = new URL('/base/annotator/test/empty.html', window.location.href)
host = createHost({annotations: '1234'}) host = createHost({annotations: '1234'})
configStr = encodeURIComponent(JSON.stringify({annotations: '1234'})) configStr = encodeURIComponent(JSON.stringify({annotations: '1234'}))
assert.equal(host.frame[0].children[0].src, appURL + '?config=' + configStr) assert.equal(host.frame[0].children[0].src, appURL + '?config=' + configStr)
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
var Annotator = require('annotator'); var Annotator = require('annotator');
var unroll = require('../../../test/util').unroll; var unroll = require('../../../shared/test/util').unroll;
var Guest = require('../../guest'); var Guest = require('../../guest');
function quoteSelector(quote) { function quoteSelector(quote) {
......
'use strict'; 'use strict';
var unroll = require('../../test/util').unroll; var unroll = require('../../shared/test/util').unroll;
var observable = require('../../util/observable'); var observable = require('../util/observable');
var selections = require('../selections'); var selections = require('../selections');
function FakeDocument() { function FakeDocument() {
......
...@@ -20,13 +20,13 @@ module.exports = function(config) { ...@@ -20,13 +20,13 @@ module.exports = function(config) {
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
// Polyfills for PhantomJS // Polyfills for PhantomJS
'./polyfills.js', './shared/polyfills.js',
// Test setup // Test setup
'./test/bootstrap.js', './sidebar/test/bootstrap.js',
// Empty HTML file to assist with some tests // Empty HTML file to assist with some tests
{ pattern: './test/empty.html', watched: false }, { pattern: './annotator/test/empty.html', watched: false },
// Karma watching is disabled for these files because they are // Karma watching is disabled for these files because they are
// bundled with karma-browserify which handles watching itself via // bundled with karma-browserify which handles watching itself via
...@@ -47,8 +47,8 @@ module.exports = function(config) { ...@@ -47,8 +47,8 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser // preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { preprocessors: {
'./polyfills.js': ['browserify'], './shared/polyfills.js': ['browserify'],
'./test/bootstrap.js': ['browserify'], './sidebar/test/bootstrap.js': ['browserify'],
'**/*-test.js': ['browserify'], '**/*-test.js': ['browserify'],
'**/*-test.coffee': ['browserify'], '**/*-test.coffee': ['browserify'],
'**/*-it.js': ['browserify'], '**/*-it.js': ['browserify'],
...@@ -57,7 +57,7 @@ module.exports = function(config) { ...@@ -57,7 +57,7 @@ module.exports = function(config) {
browserify: { browserify: {
debug: true, debug: true,
extensions: ['.coffee'], extensions: ['.coffee'],
noParse: [require.resolve('./vendor/katex')], noParse: [require.resolve('./sidebar/vendor/katex')],
configure: function (bundle) { configure: function (bundle) {
bundle.plugin('proxyquire-universal'); bundle.plugin('proxyquire-universal');
}, },
......
...@@ -24,11 +24,3 @@ try { ...@@ -24,11 +24,3 @@ try {
} catch (err) { } catch (err) {
require('js-polyfills/url'); require('js-polyfills/url');
} }
// document.evaluate() implementation,
// required by IE 10, 11
//
// This sets `window.wgxpath`
if (!window.document.evaluate) {
require('./vendor/wgxpath.install');
}
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
var queryString = require('query-string'); var queryString = require('query-string');
require('./polyfills'); require('../shared/polyfills');
var raven; var raven;
// Initialize Raven. This is required at the top of this file // Initialize Raven. This is required at the top of this file
// so that it happens early in the app's startup flow // so that it happens early in the app's startup flow
var configParam = queryString.parse(window.location.search).config || 'null'; var configParam = queryString.parse(window.location.search).config || 'null';
var settings = require('./settings')(document); var settings = require('../shared/settings')(document);
Object.assign(settings, JSON.parse(configParam)); Object.assign(settings, JSON.parse(configParam));
if (settings.raven) { if (settings.raven) {
raven = require('./raven'); raven = require('./raven');
...@@ -162,7 +162,7 @@ module.exports = angular.module('h', [ ...@@ -162,7 +162,7 @@ module.exports = angular.module('h', [
.service('annotationMapper', require('./annotation-mapper')) .service('annotationMapper', require('./annotation-mapper'))
.service('annotationUI', require('./annotation-ui')) .service('annotationUI', require('./annotation-ui'))
.service('auth', require('./auth').service) .service('auth', require('./auth').service)
.service('bridge', require('./bridge')) .service('bridge', require('../shared/bridge'))
.service('drafts', require('./drafts')) .service('drafts', require('./drafts'))
.service('features', require('./features')) .service('features', require('./features'))
.service('flash', require('./flash')) .service('flash', require('./flash'))
...@@ -185,7 +185,7 @@ module.exports = angular.module('h', [ ...@@ -185,7 +185,7 @@ module.exports = angular.module('h', [
.factory('store', require('./store')) .factory('store', require('./store'))
.value('Discovery', require('./discovery')) .value('Discovery', require('../shared/discovery'))
.value('ExcerptOverflowMonitor', require('./directive/excerpt-overflow-monitor')) .value('ExcerptOverflowMonitor', require('./directive/excerpt-overflow-monitor'))
.value('VirtualThreadList', require('./virtual-thread-list')) .value('VirtualThreadList', require('./virtual-thread-list'))
.value('raven', require('./raven')) .value('raven', require('./raven'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment