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 | |
Akron | 8778f5d | 2017-06-30 21:25:55 +0200 | [diff] [blame] | 17 | var _escapeRE = new RegExp("([\/\\\\])", 'g'); |
| 18 | String.prototype.escapeRegex = function () { |
| 19 | return this.replace(_escapeRE, '\\$1'); |
| 20 | }; |
| 21 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 22 | // Add toggleClass method similar to jquery |
| 23 | HTMLElement.prototype.toggleClass = function (c1, c2) { |
| 24 | var cl = this.classList; |
| 25 | if (cl.contains(c1)) { |
| 26 | cl.add(c2); |
| 27 | cl.remove(c1); |
| 28 | } |
| 29 | else { |
| 30 | cl.remove(c2); |
| 31 | cl.add(c1); |
| 32 | }; |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | // Utility for removing all children of a node |
| 37 | function _removeChildren (node) { |
| 38 | // Remove everything underneath |
| 39 | while (node.firstChild) |
| 40 | node.removeChild(node.firstChild); |
| 41 | }; |
| 42 | |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 43 | // Utility to get either the charCode |
| 44 | // or the keyCode of an event |
| 45 | function _codeFromEvent (e) { |
| 46 | if ((e.charCode) && (e.keyCode==0)) |
| 47 | return e.charCode |
| 48 | return e.keyCode; |
| 49 | }; |
| 50 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 51 | |
| 52 | define(function () { |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 53 | // Todo: That's double now! |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 54 | KorAP.API = KorAP.API || {}; |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 55 | KorAP.Locale = KorAP.Locale || {}; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 56 | |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 57 | var loc = KorAP.Locale; |
| 58 | loc.OR = loc.OR || 'or'; |
| 59 | loc.AND = loc.AND || 'and'; |
| 60 | |
| 61 | // Add new stylesheet object lazily to document |
| 62 | KorAP.newStyleSheet = function () { |
| 63 | if (KorAP._sheet === undefined) { |
| 64 | var sElem = document.createElement('style'); |
| 65 | document.head.appendChild(sElem); |
| 66 | KorAP._sheet = sElem.sheet; |
| 67 | }; |
| 68 | return KorAP._sheet; |
| 69 | }; |
| 70 | |
| 71 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 72 | // Default log message |
| 73 | KorAP.log = KorAP.log || function (type, msg) { |
| 74 | console.log(type + ": " + msg); |
| 75 | }; |
| 76 | |
| 77 | return KorAP; |
| 78 | }); |