-
Notifications
You must be signed in to change notification settings - Fork 538
/
Copy pathutil.js
58 lines (45 loc) · 1.32 KB
/
util.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
"use strict";
var $ = require('jquery');
var Promise = require('es6-promise').Promise;
var ESCAPE_MAP = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"/": "/"
};
// escapeHtml sanitizes special characters in text that could be interpreted as
// HTML.
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (c) {
return ESCAPE_MAP[c];
});
}
// I18N
var gettext = (function () {
if (typeof global.Gettext === 'function') {
var _gettext = new global.Gettext({domain: "annotator"});
return function (msgid) { return _gettext.gettext(msgid); };
}
return function (msgid) { return msgid; };
}());
// Returns the absolute position of the mouse relative to the top-left rendered
// corner of the page (taking into account padding/margin/border on the body
// element as necessary).
function mousePosition(event) {
var body = global.document.body;
var offset = {top: 0, left: 0};
if ($(body).css('position') !== "static") {
offset = $(body).offset();
}
return {
top: event.pageY - offset.top,
left: event.pageX - offset.left
};
}
exports.$ = $;
exports.Promise = Promise;
exports.gettext = gettext;
exports.escapeHtml = escapeHtml;
exports.mousePosition = mousePosition;