Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | // Don't let events bubble up |
| 2 | if (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 Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 10 | var _quoteRE = new RegExp("([\"\\\\])", 'g'); |
| 11 | String.prototype.quote = function () { |
| 12 | return this.replace(_quoteRE, '\\$1'); |
| 13 | }; |
| 14 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 15 | // Add toggleClass method similar to jquery |
| 16 | HTMLElement.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 |
| 30 | function _removeChildren (node) { |
| 31 | // Remove everything underneath |
| 32 | while (node.firstChild) |
| 33 | node.removeChild(node.firstChild); |
| 34 | }; |
| 35 | |
| 36 | |
| 37 | define(function () { |
| 38 | KorAP.API = KorAP.API || {}; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 39 | |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 40 | 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 Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 55 | // Default log message |
| 56 | KorAP.log = KorAP.log || function (type, msg) { |
| 57 | console.log(type + ": " + msg); |
| 58 | }; |
| 59 | |
| 60 | return KorAP; |
| 61 | }); |