Rev 1231 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 969 | runge | 1 | |
| 971 | runge | 2 | |
| 969 | runge | 3 | function extend(descendant, parent) |
| 4 | { |
||
| 5 | var sConstructor = parent.toString(); |
||
| 6 | var aMatch = sConstructor.match(/\s*function (.*)\(/); |
||
| 7 | |||
| 8 | if (aMatch != null) |
||
| 9 | { |
||
| 10 | descendant.prototype[aMatch[1]] = parent; |
||
| 11 | } |
||
| 12 | |||
| 13 | for (var m in parent.prototype) |
||
| 14 | { |
||
| 15 | descendant.prototype[m] = parent.prototype[m]; |
||
| 16 | } |
||
| 17 | } |
||
| 18 | |||
| 971 | runge | 19 | /* |
| 20 | String.pad(length: Integer, [substring: String = " "], [type: Integer = 0]): String |
||
| 21 | Returns the string with a substring padded on the left, right or both sides. |
||
| 22 | length |
||
| 23 | amount of characters that the string must have |
||
| 24 | substring |
||
| 25 | string that will be concatenated |
||
| 26 | type |
||
| 27 | specifies the side where the concatenation will happen, where: 0 = left, 1 = right and 2 = both sides |
||
| 28 | */ |
||
| 29 | String.prototype.pad = function(l, s, t) |
||
| 969 | runge | 30 | { |
| 971 | runge | 31 | return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length) |
| 32 | + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2)) |
||
| 33 | + this + s.substr(0, l - t) : this; |
||
| 969 | runge | 34 | } |
| 35 | |||
| 971 | runge | 36 | String.prototype.ltrim = function(charlist) |
| 969 | runge | 37 | { |
| 971 | runge | 38 | charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1'); |
| 39 | var re = new RegExp('^[' + charlist + ']+', 'g'); |
||
| 40 | return this.replace(re, ''); |
||
| 969 | runge | 41 | } |
| 42 | |||
| 971 | runge | 43 | String.prototype.rtrim = function(charlist) |
| 969 | runge | 44 | { |
| 971 | runge | 45 | charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1'); |
| 46 | var re = new RegExp('[' + charlist + ']+$', 'g'); |
||
| 47 | return this.replace(re, ''); |
||
| 969 | runge | 48 | } |
| 49 | |||
| 971 | runge | 50 | String.prototype.trim = function(charlist) |
| 969 | runge | 51 | { |
| 971 | runge | 52 | var str = this.ltrim(charlist); |
| 53 | return str.rtrim(charlist); |
||
| 969 | runge | 54 | } |
| 55 | |||
| 984 | runge | 56 | String.prototype.html_entity_decode = function() |
| 57 | { |
||
| 58 | var str = this.replace(/Å/g, "Ä"); |
||
| 59 | str = str.replace(/Ä/g, "Ä"); |
||
| 60 | |||
| 61 | str = str.replace(/Ä/g, "Å"); |
||
| 62 | str = str.replace(/Å/g, "Å"); |
||
| 63 | |||
| 64 | str = str.replace(/Ö/g, "Ö"); |
||
| 65 | str = str.replace(/Ö/g, "Ö"); |
||
| 66 | |||
| 67 | str = str.replace(/ä/g, "ä"); |
||
| 68 | str = str.replace(/ä/g, "ä"); |
||
| 69 | |||
| 70 | str = str.replace(/å/g, "å"); |
||
| 71 | str = str.replace(/å/g, "å"); |
||
| 72 | |||
| 73 | str = str.replace(/ö/g, "ö"); |
||
| 74 | str = str.replace(/ö/g, "ö"); |
||
| 75 | |||
| 76 | //FIXME: Add more characters |
||
| 77 | |||
| 78 | return str; |
||
| 79 | } |
||
| 971 | runge | 80 | |
| 81 | Date.prototype.getTimestamp = function() |
||
| 969 | runge | 82 | { |
| 971 | runge | 83 | return this.getTime()/1000; |
| 969 | runge | 84 | } |
| 85 | |||
| 971 | runge | 86 | Date.prototype.getDateFormated = function() |
| 969 | runge | 87 | { |
| 971 | runge | 88 | return this.getFullYear() + "-" + (this.getMonth()+1).toString().pad(2, "0", 0) + "-" + this.getDate().toString().pad(2, "0", 0); |
| 969 | runge | 89 | } |
| 90 | |||
| 971 | runge | 91 | Date.prototype.getTimeFormated = function() |
| 969 | runge | 92 | { |
| 1231 | arune | 93 | return this.getHours().toString().pad(2, "0", 0) + ":" + this.getMinutes().toString().pad(2, "0", 0) + ":" + this.getSeconds().toString().pad(2, "0", 0); |
| 969 | runge | 94 | } |
| 971 | runge | 95 | |
| 1189 | arune | 96 | Date.prototype.getTimeShortFormated = function() |
| 97 | { |
||
| 1232 | arune | 98 | return this.getHours().toString().pad(2, "0", 0) + ":" + this.getMinutes().toString().pad(2, "0", 0); |
| 1189 | arune | 99 | } |
| 100 | |||
| 971 | runge | 101 | Date.prototype.getDateTimeFormated = function() |
| 102 | { |
||
| 103 | return this.getDateFormated() + " " + this.getTimeFormated(); |
||
| 104 | } |
||
| 999 | runge | 105 | |
| 106 | var ClientId = 0; |
||
| 107 | |||
| 108 | function setClientId(clientId) |
||
| 109 | { |
||
| 110 | ClientId = clientId; |
||
| 111 | } |