| 1 | 1 | simandl | /* |
| 2 | | | fix-ie5.js, version 1.0 (pre-release) (2005/05/15) x3 |
| 3 | | | Copyright 2005, Dean Edwards |
| 4 | | | Web: http://dean.edwards.name/ |
| 5 | | | |
| 6 | | | This software is licensed under the CC-GNU LGPL |
| 7 | | | Web: http://creativecommons.org/licenses/LGPL/2.1/ |
| 8 | | | */ |
| 9 | | | |
| 10 | | | if (/MSIE 5.0/.test(navigator.userAgent)) new function() { |
| 11 | | | |
| 12 | | | var $$apply = function($function, $object, $arguments) { |
| 13 | | | $function.apply($object, $arguments); |
| 14 | | | }; |
| 15 | | | |
| 16 | | | // fix String.replace |
| 17 | | | if (''.replace(/^/, String)) { |
| 18 | | | // preserve String.replace |
| 19 | | | var _stringReplace = String.prototype.replace; |
| 20 | | | // create String.replace for handling functions |
| 21 | | | var _functionReplace = function($expression, $replacement) { |
| 22 | | | var $match, $newString = "", $string = this; |
| 23 | | | while ($string && ($match = $expression.exec($string))) { |
| 24 | | | $newString += $string.slice(0, $match.index) + $$apply($replacement, this, $match); |
| 25 | | | $string = $string.slice($match.lastIndex); |
| 26 | | | } |
| 27 | | | return $newString + $string; |
| 28 | | | }; |
| 29 | | | // replace String.replace |
| 30 | | | String.prototype.replace = function ($expression, $replacement) { |
| 31 | | | this.replace = (typeof $replacement == "function") ? _functionReplace : _stringReplace; |
| 32 | | | return this.replace($expression, $replacement); |
| 33 | | | }; |
| 34 | | | } |
| 35 | | | |
| 36 | | | // fix Function.apply |
| 37 | | | if (!Function.apply) { |
| 38 | | | var APPLY = "apply-" + Number(new Date); |
| 39 | | | $$apply = function(f, o, a) { |
| 40 | | | var r; |
| 41 | | | o[APPLY] = f; |
| 42 | | | switch (a.length) { // deconstruct for speed |
| 43 | | | case 0: r = o[APPLY](); break; |
| 44 | | | case 1: r = o[APPLY](a[0]); break; |
| 45 | | | case 2: r = o[APPLY](a[0], a[1]); break; |
| 46 | | | case 3: r = o[APPLY](a[0], a[1], a[2]); break; |
| 47 | | | case 4: r = o[APPLY](a[0], a[1], a[2], a[3]); break; |
| 48 | | | default: |
| 49 | | | var aa = [], i = a.length - 1; |
| 50 | | | do aa[i] = "a[" + i + "]"; while (i--); |
| 51 | | | eval("r=o[APPLY](" + aa + ")"); |
| 52 | | | } |
| 53 | | | delete o[APPLY]; |
| 54 | | | return r; |
| 55 | | | }; |
| 56 | | | // fix ICommon |
| 57 | | | ICommon.valueOf.prototype.inherit = function() { |
| 58 | | | return $$apply(arguments.callee.caller.ancestor, this, arguments); |
| 59 | | | }; |
| 60 | | | } |
| 61 | | | |
| 62 | | | // array fixes |
| 63 | | | if (![].push) Array.prototype.push = function() { |
| 64 | | | for (var i = 0; i < arguments.length; i++) { |
| 65 | | | this[this.length] = arguments[i]; |
| 66 | | | } |
| 67 | | | return this.length; |
| 68 | | | }; |
| 69 | | | if (![].pop) Array.prototype.pop = function() { |
| 70 | | | var $item = this[this.length - 1]; |
| 71 | | | this.length--; |
| 72 | | | return $item; |
| 73 | | | }; |
| 74 | | | }; |