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