blob: 7c2f4740669611dd27779ae624158070f73e88c3 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001// Don't let events bubble up
2if (Event.halt === undefined) {
3 // Don't let events bubble up
4 Event.prototype.halt = function () {
5 this.stopPropagation();
6 this.preventDefault();
7 };
8};
9
Nils Diewald7c8ced22015-04-15 19:21:00 +000010var _quoteRE = new RegExp("([\"\\\\])", 'g');
11String.prototype.quote = function () {
12 return this.replace(_quoteRE, '\\$1');
13};
14
Nils Diewald0e6992a2015-04-14 20:13:52 +000015// Add toggleClass method similar to jquery
16HTMLElement.prototype.toggleClass = function (c1, c2) {
17 var cl = this.classList;
18 if (cl.contains(c1)) {
19 cl.add(c2);
20 cl.remove(c1);
21 }
22 else {
23 cl.remove(c2);
24 cl.add(c1);
25 };
26};
27
28
29// Utility for removing all children of a node
30function _removeChildren (node) {
31 // Remove everything underneath
32 while (node.firstChild)
33 node.removeChild(node.firstChild);
34};
35
36
37define(function () {
38 KorAP.API = KorAP.API || {};
Nils Diewald0e6992a2015-04-14 20:13:52 +000039
Nils Diewald359a72c2015-04-20 17:40:29 +000040 var loc = KorAP.Locale;
41 loc.OR = loc.OR || 'or';
42 loc.AND = loc.AND || 'and';
43
44 // Add new stylesheet object lazily to document
45 KorAP.newStyleSheet = function () {
46 if (KorAP._sheet === undefined) {
47 var sElem = document.createElement('style');
48 document.head.appendChild(sElem);
49 KorAP._sheet = sElem.sheet;
50 };
51 return KorAP._sheet;
52 };
53
54
Nils Diewald0e6992a2015-04-14 20:13:52 +000055 // Default log message
56 KorAP.log = KorAP.log || function (type, msg) {
57 console.log(type + ": " + msg);
58 };
59
60 return KorAP;
61});