1 /** 2 * @namespace 3 * @name window 4 * @description supplimental window methods. 5 */ 6 7 if (!window.myfaces) { 8 /** 9 * @namespace 10 * @name myfaces 11 */ 12 var myfaces = new function() { 13 }; 14 window.myfaces = myfaces; 15 } 16 17 /** 18 * @memberOf myfaces 19 * @namespace 20 * @name _impl 21 */ 22 myfaces._impl = (myfaces._impl) ? myfaces._impl : {}; 23 /** 24 * @memberOf myfaces._impl 25 * @namespace 26 * @name core 27 */ 28 myfaces._impl.core = (myfaces._impl.core) ? myfaces._impl.core :{}; 29 30 if (!myfaces._impl.core._EvalHandlers) { 31 /** 32 * @memberOf myfaces._impl.core 33 * @namespace 34 * @name _EvalHandlers 35 */ 36 myfaces._impl.core._EvalHandlers = new function() { 37 //the rest of the namespaces can be handled by our namespace feature 38 //helper to avoid unneeded hitches 39 /** 40 * @borrows myfaces._impl.core._Runtime as _T 41 */ 42 var _T = this; 43 44 /*cascaded eval methods depending upon the browser*/ 45 46 /** 47 * @function 48 * @param code 49 50 * 51 * evals a script globally using exec script (ie6 fallback) 52 * @param {String} code the code which has to be evaluated 53 * @borrows myfaces._impl.core._Runtime as _T 54 */ 55 _T._evalExecScript = function(code) { 56 //execScript definitely only for IE otherwise we might have a custom 57 //window extension with undefined behavior on our necks 58 //window.execScript does not return anything 59 //on htmlunit it return "null object" 60 //_r == ret 61 var _r = window.execScript(code); 62 if ('undefined' != typeof _r && _r == "null" /*htmlunit bug*/) { 63 return null; 64 } 65 return _r; 66 }; 67 68 /** 69 * flakey head appendix method which does not work in the correct 70 * order or at all for all modern browsers 71 * but seems to be the only method which works on blackberry correctly 72 * hence we are going to use it as fallback 73 * 74 * @param {String} code the code part to be evaled 75 * @borrows myfaces._impl.core._Runtime as _T 76 */ 77 _T._evalBBOld = function(code) { 78 //_l == location 79 var _l = document.getElementsByTagName("head")[0] || document.documentElement; 80 //_p == placeHolder 81 var _p = document.createElement("script"); 82 _p.type = "text/javascript"; 83 _p.text = code; 84 _l.insertBefore(_p, _l.firstChild); 85 _l.removeChild(_p); 86 return null; 87 }; 88 89 /** 90 * @name myfaces._impl.core._Runtime._standardGlobalEval 91 * @private 92 * @param {String} code 93 */ 94 _T._standardGlobalEval = function(code) { 95 //fix which works in a cross browser way 96 //we used to scope an anonymous function 97 //but I think this is better 98 //the reason is firefox applies a wrong scope 99 //if we call eval by not scoping 100 //_U == "undefined" 101 var _U = "undefined"; 102 var gEval = function () { 103 //_r == retVal; 104 var _r = window.eval.call(window, code); 105 if (_U == typeof _r) return null; 106 return _r; 107 }; 108 var _r = gEval(); 109 if (_U == typeof _r) return null; 110 return _r; 111 }; 112 113 /** 114 * global eval on scripts 115 * @param {String} c (code abbreviated since the compression does not work here) 116 * @name myfaces._impl.core._Runtime.globalEval 117 * @function 118 */ 119 _T.globalEval = function(c) { 120 //TODO add a config param which allows to evaluate global scripts even if the call 121 //is embedded in an iframe 122 //We lazy init the eval type upon the browsers 123 //capabilities 124 var _e = "_evalType"; 125 var _w = window; 126 var _b = myfaces._impl.core._Runtime.browser; 127 if (!_T[_e]) { 128 _T[_e] = _w.execScript ? "_evalExecScript" : null; 129 _T[_e] = _T[_e] ||(( _w.eval && (!_b.isBlackBerry ||_b.isBlackBerry >= 6)) ? "_standardGlobalEval" : null); 130 _T[_e] = _T[_e] ||((_w.eval ) ? "_evalBBOld" : null); 131 } 132 if (_T[_e]) { 133 return _T[_T[_e]](c); 134 } 135 //we probably have covered all browsers, but this is a safety net which might be triggered 136 //by some foreign browser which is not covered by the above cases 137 eval.call(window, c); 138 return null; 139 }; 140 141 }; 142 }