forked from nlplab/brat
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
146 lines (132 loc) · 5.92 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
window.$ = require('./client/lib/node-jquery-1.7.1'); //require('jquery-node-browserify'); // @1.7.2 ++
LONG_ANNOTATION_CONST = "LongAnnotation";
window.BratFrontendEditor = function(element, collData, docData, options) {
if (!(element instanceof Element)) {
throw new Error('element should be an instance of Element');
}
collData = collData || {};
docData = docData || {};
options = options || {};
//DEFAULT OPTIONS
newOptions = {
activateEdition: true,
overWriteModals: false,
showTooltip: false,
assetsPath: "static/",
maxFragmentLength: 40,
showTooltip: true,
overWriteModals: false,
webFontURLs: [
'fonts/Astloch-Bold.ttf',
'fonts/PT_Sans-Caption-Web-Regular.ttf',
'fonts/Liberation_Sans-Regular.ttf'
],
ajax: 'local' // 'local', 'external' or 'normal'
};
// If option defined, over-write newOptions
for(var opt in options){
if(options.hasOwnProperty(opt)){
newOptions[opt] = options[opt];
}
}
this.element = element;
this.collData = collData;
this.docData = docData;
this.options = newOptions;
this.init();
};
BratFrontendEditor.prototype = {
constructor: BratFrontendEditor,
init: function() {
var self = this;
var html = require('./brat.html');
self.element.innerHTML = html;
self.setHtmlImgSrc();
window.jQuery = $;
(function($){
// require('./index.css'); //TODO: If possible, include css in min.js (browserify-css)
require('./client/lib/jquery-ui.min');
require('./client/lib/jquery.svg.min');
require('./client/lib/jquery.svgdom.min');
require('jquery-bbq');
require('./client/lib/jquery.sprintf');
require('./client/lib/jquery.json.min');
//TODO Fix this error
window.WebFont = require('./client/lib/webfont.js').WebFont; //Uncaught TypeError: Cannot set property 'WebFont' of undefined
//brat global helpers
var Config= require('./client/src/configuration');
window.Configuration = new Config();
window.Util = require('./client/src/util');
// brat modules
window.Dispatcher = require('./client/src/dispatcher');
window.URLHash = require('./client/src/url_hash'); //TODO Figure out
window.LocalAjax = require('./client/src/local_ajax');
window.Ajax = require('./client/src/ajax.js');
window.Visualizer = require('./client/src/visualizer');
window.VisualizerUI = require('./client/src/visualizer_ui');
window.AnnotatorUI = require('./client/src/annotator_ui');
window.Spinner = require('./client/src/spinner');
$(document).ready(function(){
self.dispatcher = new Dispatcher();
switch(self.options.ajax) {
case 'local':
self.ajax = new LocalAjax(self.dispatcher, self.options.maxFragmentLength);
break;
case 'normal':
self.ajax = new Ajax(self.dispatcher);
break;
case 'external':
break;
default:
self.ajax = new LocalAjax(self.dispatcher, self.options.maxFragmentLength);
break;
}
var absoluteWebFontsURLS = [
self.options.assetsPath + self.options.webFontURLs[0],
self.options.assetsPath + self.options.webFontURLs[1],
self.options.assetsPath + self.options.webFontURLs[2],
];
self.visualizer = new Visualizer(self.dispatcher, 'svg', absoluteWebFontsURLS);
self.svg = self.visualizer.svg;
if(self.options.activateEdition === true){
self.visualizerUI = new VisualizerUI(self.dispatcher, self.svg, self.options.showTooltip, self.options.overWriteModals);
self.annotatorUI = new AnnotatorUI(self.dispatcher, self.svg);
// self.spinner = new Spinner(self.dispatcher, '#spinner');
}
self.dispatcher.post('init');
if(self.options.maxFragmentLength > 0){
self.addLongAnnotationEntityAttribute();
}
self.docData.collection = null;
self.dispatcher.post('collectionLoaded', [self.collData]);
self.dispatcher.post('requestRenderData', [self.docData]);
self.dispatcher.post('current', [self.collData, self.docData, {}]);
});
})($);
},
addLongAnnotationEntityAttribute: function(){
// Special symbol for splitted long annotations
this.collData.entity_attribute_types.push( {
"name": LONG_ANNOTATION_CONST,
"type" : LONG_ANNOTATION_CONST,
"values": { LONG_ANNOTATION_CONST: { "glyph": "↹" } }
});
this.collData.entity_types.forEach(function(type){
type.attributes.push(LONG_ANNOTATION_CONST);
});
},
setHtmlImgSrc: function(){
var spinners = this.element.getElementsByClassName("brat-spinner");
var magnifiers = this.element.getElementsByClassName("brat-fugue-shadowless-magnifier");
var externals = this.element.getElementsByClassName("brat-fugue-shadowless-external");
if(spinners && spinners.length){
spinners[0].src = this.options.assetsPath + 'img/spinner.gif';
}
if(magnifiers && magnifiers.length){
magnifiers[0].src = this.options.assetsPath + 'img/Fugue-shadowless-magnifier.png';
}
if(externals && externals.length){
externals[0].src = this.options.assetsPath + 'img/Fugue-shadowless-external.png';
}
}
};