Skip to content

Commit

Permalink
Separate out sidebar, annotation layer/bootstrap, and shared code int…
Browse files Browse the repository at this point in the history
…o 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)
  • Loading branch information
robertknight committed Jan 16, 2017
1 parent 376decb commit 7ec94fa
Show file tree
Hide file tree
Showing 242 changed files with 59 additions and 59 deletions.
14 changes: 7 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ var appBundleBaseConfig = {
};

var appBundles = [{
// The sidebar application for displaying and editing annotations
// The sidebar application for displaying and editing annotations.
name: 'app',
transforms: ['coffee'],
entry: './src/scripts/app',
entry: './src/sidebar/app',
},{
// The Annotator library which provides annotation controls on
// the page and sets up the sidebar
// The annotation layer which handles displaying highlights, presenting
// annotation tools on the page and instantiating the sidebar application.
name: 'injector',
entry: './src/scripts/annotator/main',
entry: './src/annotator/main',
transforms: ['coffee'],
}];

Expand Down Expand Up @@ -305,11 +305,11 @@ function runKarma(baseConfig, opts, done) {
}

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) {
runKarma('./src/scripts/karma.config.js', {}, callback);
runKarma('./src/karma.config.js', {}, callback);
});

gulp.task('upload-sourcemaps', ['build-js'], function () {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
]
},
"browser": {
"annotator": "./src/scripts/vendor/annotator.js",
"annotator": "./src/annotator/vendor/annotator.js",
"hammerjs": "./node_modules/hammerjs/hammer.js",
"katex": "./src/scripts/vendor/katex.js"
"katex": "./src/sidebar/vendor/katex.js"
},
"browserify-shim": {
"annotator": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/gulp/vendor-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module.exports = {
bundles: {
jquery: ['jquery'],
polyfills: [require.resolve('../../src/scripts/polyfills')],
polyfills: [require.resolve('../../src/shared/polyfills')],
angular: [
'angular',
'angular-jwt',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

var html = require('../html');

var toResult = require('../../../test/promise-util').toResult;
var unroll = require('../../../test/util').unroll;
var toResult = require('../../../shared/test/promise-util').toResult;
var unroll = require('../../../shared/test/util').unroll;
var fixture = require('./html-anchoring-fixture.html');

/** Return all text node children of `container`. */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/scripts/annotator/config.js → src/annotator/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var annotationIDs = require('../util/annotation-ids');
var settings = require('../settings');
var annotationIDs = require('./util/annotation-ids');
var settings = require('../shared/settings');

var docs = 'https://h.readthedocs.io/en/latest/embedding.html';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 12 additions & 4 deletions src/scripts/annotator/main.js → src/annotator/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
'use strict';

require('../polyfills');
require('../shared/polyfills');

var Annotator = require('annotator');

// 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();
if (g.wgxpath) {
g.wgxpath.install();
Expand All @@ -22,13 +30,13 @@ Annotator.Plugin.Toolbar = require('./plugin/toolbar');

// Document type plugins
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
Annotator.Plugin.CrossFrame = require('./plugin/cross-frame');
Annotator.Plugin.CrossFrame.AnnotationSync = require('./annotation-sync');
Annotator.Plugin.CrossFrame.Bridge = require('../bridge');
Annotator.Plugin.CrossFrame.Discovery = require('../discovery');
Annotator.Plugin.CrossFrame.Bridge = require('../shared/bridge');
Annotator.Plugin.CrossFrame.Discovery = require('../shared/discovery');

var appLinkEl =
document.querySelector('link[type="application/annotator+html"]');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var observable = require('../util/observable');
var observable = require('./util/observable');

/** Returns the selected `DOMRange` in `document`. */
function selectedRange(document) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var adder = require('../adder');
var unroll = require('../../test/util').unroll;
var unroll = require('../../shared/test/util').unroll;

function rect(left, top, width, height) {
return {left: left, top: top, width: width, height: height};
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Annotator = require('annotator')
proxyquire = require('proxyquire')

adder = require('../adder')
Observable = require('../../util/observable').Observable
Observable = require('../util/observable').Observable

$ = Annotator.$
Annotator['@noCallThru'] = true;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe 'Host', ->
fakeCrossFrame = 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
element = document.createElement('div')
return new Host(element, options)
Expand Down Expand Up @@ -87,7 +87,7 @@ describe 'Host', ->
host.publish('panelReady')

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'})
configStr = encodeURIComponent(JSON.stringify({annotations: '1234'}))
assert.equal(host.frame[0].children[0].src, appURL + '?config=' + configStr)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

var Annotator = require('annotator');

var unroll = require('../../../test/util').unroll;
var unroll = require('../../../shared/test/util').unroll;
var Guest = require('../../guest');

function quoteSelector(quote) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'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');

function FakeDocument() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/scripts/karma.config.js → src/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
// Polyfills for PhantomJS
'./polyfills.js',
'./shared/polyfills.js',

// Test setup
'./test/bootstrap.js',
'./sidebar/test/bootstrap.js',

// 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
// bundled with karma-browserify which handles watching itself via
Expand All @@ -47,8 +47,8 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./polyfills.js': ['browserify'],
'./test/bootstrap.js': ['browserify'],
'./shared/polyfills.js': ['browserify'],
'./sidebar/test/bootstrap.js': ['browserify'],
'**/*-test.js': ['browserify'],
'**/*-test.coffee': ['browserify'],
'**/*-it.js': ['browserify'],
Expand All @@ -57,7 +57,7 @@ module.exports = function(config) {
browserify: {
debug: true,
extensions: ['.coffee'],
noParse: [require.resolve('./vendor/katex')],
noParse: [require.resolve('./sidebar/vendor/katex')],
configure: function (bundle) {
bundle.plugin('proxyquire-universal');
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 0 additions & 8 deletions src/scripts/polyfills.js → src/shared/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,3 @@ try {
} catch (err) {
require('js-polyfills/url');
}

// document.evaluate() implementation,
// required by IE 10, 11
//
// This sets `window.wgxpath`
if (!window.document.evaluate) {
require('./vendor/wgxpath.install');
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/scripts/app.js → src/sidebar/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

var queryString = require('query-string');

require('./polyfills');
require('../shared/polyfills');

var raven;

// Initialize Raven. This is required at the top of this file
// so that it happens early in the app's startup flow
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));
if (settings.raven) {
raven = require('./raven');
Expand Down Expand Up @@ -162,7 +162,7 @@ module.exports = angular.module('h', [
.service('annotationMapper', require('./annotation-mapper'))
.service('annotationUI', require('./annotation-ui'))
.service('auth', require('./auth').service)
.service('bridge', require('./bridge'))
.service('bridge', require('../shared/bridge'))
.service('drafts', require('./drafts'))
.service('features', require('./features'))
.service('flash', require('./flash'))
Expand All @@ -185,7 +185,7 @@ module.exports = angular.module('h', [

.factory('store', require('./store'))

.value('Discovery', require('./discovery'))
.value('Discovery', require('../shared/discovery'))
.value('ExcerptOverflowMonitor', require('./directive/excerpt-overflow-monitor'))
.value('VirtualThreadList', require('./virtual-thread-list'))
.value('raven', require('./raven'))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var proxyquire = require('proxyquire');

var events = require('../../events');
var fixtures = require('../../test/annotation-fixtures');
var testUtil = require('../../test/util');
var testUtil = require('../../../shared/test/util');
var util = require('./util');

var inject = angular.mock.inject;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var angular = require('angular');

var unroll = require('../../test/util').unroll;
var unroll = require('../../../shared/test/util').unroll;
var util = require('./util');

function testComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var angular = require('angular');
var proxyquire = require('proxyquire');

var util = require('./util');
var noCallThru = require('../../test/util').noCallThru;
var noCallThru = require('../../../shared/test/util').noCallThru;

describe('markdown', function () {
function isHidden(element) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var immutable = require('seamless-immutable');
var annotationUIFactory = require('../annotation-ui');
var annotationFixtures = require('./annotation-fixtures');
var metadata = require('../annotation-metadata');
var unroll = require('./util').unroll;
var unroll = require('../../shared/test/util').unroll;
var uiConstants = require('../ui-constants');

var defaultAnnotation = annotationFixtures.defaultAnnotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var angular = require('angular');
var proxyquire = require('proxyquire');

var events = require('../events');
var util = require('./util');
var util = require('../../shared/test/util');

describe('AppController', function () {
var $controller = null;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var angular = require('angular');
var immutable = require('seamless-immutable');

var unroll = require('../util').unroll;
var unroll = require('../../../shared/test/util').unroll;

var fixtures = immutable({
annotations: [{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var commands = require('../markdown-commands');
var unroll = require('./util').unroll;
var unroll = require('../../shared/test/util').unroll;

/**
* Convert a string containing '<sel>' and '</sel>' markers
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var proxyquire = require('proxyquire');
var noCallThru = require('./util').noCallThru;
var noCallThru = require('../../shared/test/util').noCallThru;

function fakeExceptionData(scriptURL) {
return {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var retryUtil = require('../retry-util');
var toResult = require('./promise-util').toResult;
var toResult = require('../../shared/test/promise-util').toResult;

describe('retry-util', function () {
describe('.retryPromiseOperation', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var immutable = require('seamless-immutable');
var annotationFixtures = require('./annotation-fixtures');
var events = require('../events');
var uiConstants = require('../ui-constants');
var util = require('./util');
var util = require('../../shared/test/util');

var unroll = util.unroll;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var angular = require('angular');
var proxyquire = require('proxyquire');

var util = require('./util');
var util = require('../../shared/test/util');

describe('store', function () {
var $httpBackend = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var inherits = require('inherits');
var proxyquire = require('proxyquire');

var events = require('../events');
var unroll = require('./util').unroll;
var unroll = require('../../shared/test/util').unroll;

var fixtures = {
createNotification: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var fixtures = require('./annotation-fixtures');
var uiConstants = require('../ui-constants');
var tabs = require('../tabs');
var unroll = require('./util').unroll;
var unroll = require('../../shared/test/util').unroll;

describe('tabs', function () {
describe('shouldSeparateOrphans', function () {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var VirtualThreadList = proxyquire('../virtual-thread-list', {
return fn;
},
});
var util = require('./util');
var util = require('../../shared/test/util');
var unroll = util.unroll;

describe('VirtualThreadList', function () {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var proxyquire = require('proxyquire');
var EventEmitter = require('tiny-emitter');

var events = require('../events');
var noCallThru = require('./util').noCallThru;
var noCallThru = require('../../shared/test/util').noCallThru;

var searchClients;
function FakeSearchClient(searchFn, opts) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7ec94fa

Please sign in to comment.