blob: d803a9d62fc7686250ec85e7b95b2f20fe344d7f [file] [log] [blame]
Akronc1457bf2015-06-11 19:24:00 +02001window.KorAP = window.KorAP || {};
2
Nils Diewald0e6992a2015-04-14 20:13:52 +00003// Don't let events bubble up
4if (Event.halt === undefined) {
5 // Don't let events bubble up
6 Event.prototype.halt = function () {
7 this.stopPropagation();
8 this.preventDefault();
9 };
10};
11
Nils Diewald7c8ced22015-04-15 19:21:00 +000012var _quoteRE = new RegExp("([\"\\\\])", 'g');
13String.prototype.quote = function () {
14 return this.replace(_quoteRE, '\\$1');
15};
16
Akron8778f5d2017-06-30 21:25:55 +020017var _escapeRE = new RegExp("([\/\\\\])", 'g');
18String.prototype.escapeRegex = function () {
19 return this.replace(_escapeRE, '\\$1');
20};
21
Nils Diewald0e6992a2015-04-14 20:13:52 +000022// Add toggleClass method similar to jquery
23HTMLElement.prototype.toggleClass = function (c1, c2) {
24 var cl = this.classList;
25 if (cl.contains(c1)) {
26 cl.add(c2);
27 cl.remove(c1);
28 }
29 else {
30 cl.remove(c2);
31 cl.add(c1);
32 };
33};
34
35
36// Utility for removing all children of a node
37function _removeChildren (node) {
38 // Remove everything underneath
39 while (node.firstChild)
40 node.removeChild(node.firstChild);
41};
42
Akron6a535d42015-08-26 20:16:58 +020043// Utility to get either the charCode
44// or the keyCode of an event
45function _codeFromEvent (e) {
46 if ((e.charCode) && (e.keyCode==0))
47 return e.charCode
48 return e.keyCode;
49};
50
Nils Diewald0e6992a2015-04-14 20:13:52 +000051
52define(function () {
Akronc1457bf2015-06-11 19:24:00 +020053 // Todo: That's double now!
Nils Diewald0e6992a2015-04-14 20:13:52 +000054 KorAP.API = KorAP.API || {};
Akronc1457bf2015-06-11 19:24:00 +020055 KorAP.Locale = KorAP.Locale || {};
Nils Diewald0e6992a2015-04-14 20:13:52 +000056
Nils Diewald359a72c2015-04-20 17:40:29 +000057 var loc = KorAP.Locale;
58 loc.OR = loc.OR || 'or';
59 loc.AND = loc.AND || 'and';
60
61 // Add new stylesheet object lazily to document
62 KorAP.newStyleSheet = function () {
63 if (KorAP._sheet === undefined) {
64 var sElem = document.createElement('style');
65 document.head.appendChild(sElem);
66 KorAP._sheet = sElem.sheet;
67 };
68 return KorAP._sheet;
69 };
70
71
Nils Diewald0e6992a2015-04-14 20:13:52 +000072 // Default log message
73 KorAP.log = KorAP.log || function (type, msg) {
74 console.log(type + ": " + msg);
75 };
76
77 return KorAP;
78});