Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 1 | window.KorAP = window.KorAP || {}; |
| 2 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 3 | // Don't let events bubble up |
| 4 | if (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 Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 12 | var _quoteRE = new RegExp("([\"\\\\])", 'g'); |
| 13 | String.prototype.quote = function () { |
| 14 | return this.replace(_quoteRE, '\\$1'); |
| 15 | }; |
| 16 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 17 | // Add toggleClass method similar to jquery |
| 18 | HTMLElement.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 |
| 32 | function _removeChildren (node) { |
| 33 | // Remove everything underneath |
| 34 | while (node.firstChild) |
| 35 | node.removeChild(node.firstChild); |
| 36 | }; |
| 37 | |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 38 | // Utility to get either the charCode |
| 39 | // or the keyCode of an event |
| 40 | function _codeFromEvent (e) { |
| 41 | if ((e.charCode) && (e.keyCode==0)) |
| 42 | return e.charCode |
| 43 | return e.keyCode; |
| 44 | }; |
| 45 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 46 | |
| 47 | define(function () { |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 48 | // Todo: That's double now! |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 49 | KorAP.API = KorAP.API || {}; |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 50 | KorAP.Locale = KorAP.Locale || {}; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 51 | |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 52 | var loc = KorAP.Locale; |
| 53 | loc.OR = loc.OR || 'or'; |
| 54 | loc.AND = loc.AND || 'and'; |
| 55 | |
| 56 | // Add new stylesheet object lazily to document |
| 57 | KorAP.newStyleSheet = function () { |
| 58 | if (KorAP._sheet === undefined) { |
| 59 | var sElem = document.createElement('style'); |
| 60 | document.head.appendChild(sElem); |
| 61 | KorAP._sheet = sElem.sheet; |
| 62 | }; |
| 63 | return KorAP._sheet; |
| 64 | }; |
| 65 | |
| 66 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 67 | // Default log message |
| 68 | KorAP.log = KorAP.log || function (type, msg) { |
| 69 | console.log(type + ": " + msg); |
| 70 | }; |
| 71 | |
| 72 | return KorAP; |
| 73 | }); |