forked from wissenbach/oaclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plaintext.js
119 lines (101 loc) · 3.2 KB
/
plaintext.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
YUI().use('node-base', 'node', 'node-load', 'async-queue', 'stylesheet', 'overlay', function(Y) {
OAClient.PlaintextHandle = function(start, end) {
console.log("start: " + start + " end " + end);
this.start = start;
this.end = end;
this.destroy = function() {};
var startSel = '#charnum' + start;
var startElement = Y.one(startSel);
var endSel = '#charnum' + end;
var endElement = Y.one(endSel);
// FIXME don't be silent if the target cannot be found
if (startElement && endElement) {
startElement.setStyles({
'borderLeft' : '1px solid black',
'borderTop' : '1px solid black',
'borderBottom' : '1px solid black',
'backgroundColor' : 'yellow'
});
endElement.setStyles({
'borderRight' : '1px solid black',
'borderTop' : '1px solid black',
'borderBottom' : '1px solid black',
'backgroundColor' : 'yellow'
});
var x = startElement.getX();
var y = startElement.getY();
var width = endElement.getX() + endElement.get('width') - x;
var height = endElement.getY() + endElement.get('height') - y;
this.overlay = new Y.Overlay({
x: x,
y: y,
width: width,
height: height,
headerContent: '',
bodyContent:'<div class="handleOverlay">|</div>',
footerContent: '',
plugins: [{fn:Y.Plugin.WidgetAnim, duration: 0.5}],
visible: false
});
this.overlay.render();
this.overlay.show();
this.destroy = function() {
this.overlay.destroy();
};
}
};
OAClient.Plaintext = function(callback, targetUri){
// store a list of active handles
this.handles = [];
this.clearHandles = function() {
Y.each(this.handles, function(h){
h.destroy();
});
this.handles = [];
};
OAClient.annotationTarget =
new OAClient.AnnotationTarget(location.href, callback);
// /* This function fetches the resource again, which is useful for seeing
// the actual offsets*/
// ajaxReplaceDocument = function() {
// var new_container = Y.Node.create('<div id="text-container"></div>');
// var text_container = Y.one('body *');
// text_container.replace(new_container);
// };
//
// /* This function works with what's already in the DOM */
// wrapPlainText = function(content) {
// Y.StyleSheet('pre {display: inline;}');
//
// var new_container = Y.Node.create('<div id="text-container"></div>');
// var text_container = Y.one('body *');
// text_container.replace(new_container);
//
// var insertQueue = new Y.AsyncQueue();
// for (var i = 0; i < 2000; i++) {
// function insert(){
// var insert_index = i;
// insertQueue.add(function(){
//
// var char_container = new Y.Node.create('<pre id="charnum' + insert_index + '"></pre>');
// new_container.append(char_container);
// char_container.set('text', content.charAt(insert_index));
// });
// };
// insert();
// }
// if (callback)
// insertQueue.add(callback);
// insertQueue.run();
// };
//
// var text_container = Y.one('body *');
// var content = text_container.getDOMNode().textContent;
// wrapPlainText(content);
};
OAClient.Plaintext.prototype.getHandle = function(start, end) {
var result = new OAClient.PlaintextHandle(start, end);
this.handles.push(result);
return result;
};
});