blob: 719c8894b5eecc981fca791fd9aaa32b82632d5b [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
Akron151bc872018-02-02 14:04:15 +010036HTMLElement.prototype.addE = function (tag) {
37 return this.appendChild(document.createElement(tag));
38};
39
40HTMLElement.prototype.addT = function (text) {
41 return this.appendChild(document.createTextNode(text));
42};
43
44
Nils Diewald0e6992a2015-04-14 20:13:52 +000045// Utility for removing all children of a node
46function _removeChildren (node) {
47 // Remove everything underneath
48 while (node.firstChild)
49 node.removeChild(node.firstChild);
50};
51
Akron151bc872018-02-02 14:04:15 +010052
Akron6a535d42015-08-26 20:16:58 +020053// Utility to get either the charCode
54// or the keyCode of an event
55function _codeFromEvent (e) {
56 if ((e.charCode) && (e.keyCode==0))
57 return e.charCode
58 return e.keyCode;
59};
60
Nils Diewald0e6992a2015-04-14 20:13:52 +000061
62define(function () {
Akronc1457bf2015-06-11 19:24:00 +020063 // Todo: That's double now!
Nils Diewald0e6992a2015-04-14 20:13:52 +000064 KorAP.API = KorAP.API || {};
Akronc1457bf2015-06-11 19:24:00 +020065 KorAP.Locale = KorAP.Locale || {};
Nils Diewald0e6992a2015-04-14 20:13:52 +000066
Nils Diewald359a72c2015-04-20 17:40:29 +000067 var loc = KorAP.Locale;
68 loc.OR = loc.OR || 'or';
69 loc.AND = loc.AND || 'and';
70
71 // Add new stylesheet object lazily to document
72 KorAP.newStyleSheet = function () {
73 if (KorAP._sheet === undefined) {
74 var sElem = document.createElement('style');
75 document.head.appendChild(sElem);
76 KorAP._sheet = sElem.sheet;
77 };
78 return KorAP._sheet;
79 };
80
81
Nils Diewald0e6992a2015-04-14 20:13:52 +000082 // Default log message
83 KorAP.log = KorAP.log || function (type, msg) {
84 console.log(type + ": " + msg);
85 };
86
87 return KorAP;
88});