blob: 9a1f884e54e8b1c0ab2a78b424fabab6383f901b [file] [log] [blame]
Nils Diewald19402142015-04-30 15:44:52 +00001window.KorAP = window.KorAP || {};
Nils Diewald0e6992a2015-04-14 20:13:52 +00002
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
Nils Diewald0e6992a2015-04-14 20:13:52 +000017// Add toggleClass method similar to jquery
18HTMLElement.prototype.toggleClass = function (c1, c2) {
19 var cl = this.classList;
20 if (cl.contains(c1)) {
21 cl.add(c2);
22 cl.remove(c1);
23 }
24 else {
25 cl.remove(c2);
26 cl.add(c1);
27 };
28};
29
30
31// Utility for removing all children of a node
32function _removeChildren (node) {
33 // Remove everything underneath
34 while (node.firstChild)
35 node.removeChild(node.firstChild);
36};
37
38
39define(function () {
40 KorAP.API = KorAP.API || {};
41 KorAP.Locale = KorAP.Locale || {};
42
Nils Diewald359a72c2015-04-20 17:40:29 +000043 var loc = KorAP.Locale;
44 loc.OR = loc.OR || 'or';
45 loc.AND = loc.AND || 'and';
46
47 // Add new stylesheet object lazily to document
48 KorAP.newStyleSheet = function () {
49 if (KorAP._sheet === undefined) {
50 var sElem = document.createElement('style');
51 document.head.appendChild(sElem);
52 KorAP._sheet = sElem.sheet;
53 };
54 return KorAP._sheet;
55 };
56
57
Nils Diewald0e6992a2015-04-14 20:13:52 +000058 // Default log message
59 KorAP.log = KorAP.log || function (type, msg) {
60 console.log(type + ": " + msg);
61 };
62
63 return KorAP;
64});