Removed base64-encoding from egw_instant_load.html, added code to egw_json which inserts script tags seperately when content is assigned to the innerHTML property

This commit is contained in:
Andreas Stöckel 2011-03-17 18:00:24 +00:00
parent 6a58d3c612
commit e19cc44fcb
3 changed files with 58 additions and 54 deletions

View File

@ -1,9 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<!--
Open this file from inside egroupware in a popup/iframe and call the egw_instant_load
function in its "onload" event.
-->
<head>
<title>EGroupware [Loading Data]</title>
<meta http-equiv="Cache-control" content="public" />
@ -11,57 +7,8 @@ function in its "onload" event.
</head>
<body style="background-color: #F0F0F0">
<script type="text/javascript">
/*
* base64.js - Base64 encoding and decoding functions
*
* See: http://developer.mozilla.org/en/docs/DOM:window.btoa
* http://developer.mozilla.org/en/docs/DOM:window.atob
*
* Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
* Released under the MIT license
*/
if (typeof atob == 'undefined') {
function atob(str) {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var invalid = {
strlen: (str.length % 4 != 0),
chars: new RegExp('[^' + chars + ']').test(str),
equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
};
if (invalid.strlen || invalid.chars || invalid.equals)
throw new Error('Invalid base64 data');
var decoded = [];
var c = 0;
while (c < str.length) {
var i0 = chars.indexOf(str.charAt(c++));
var i1 = chars.indexOf(str.charAt(c++));
var i2 = chars.indexOf(str.charAt(c++));
var i3 = chars.indexOf(str.charAt(c++));
var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
var b0 = (buf & (255 << 16)) >> 16;
var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
var b2 = (i3 == 64) ? -1 : (buf & 255);
decoded[decoded.length] = String.fromCharCode(b0);
if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
}
return decoded.join('');
}
}
window.egw_instant_load = function(_data, _base64Encoded)
window.egw_instant_load = function(_data)
{
if (typeof _base64Encoded == "undefined")
{
_base64Encoded = false;
}
if (_base64Encoded)
{
_data = atob(_data);
}
// Empty the document tree
while (document.childNodes.length > 0)
{

View File

@ -338,6 +338,12 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
if (obj)
{
obj[res.data.key] = res.data.value;
if (res.data.key == "innerHTML")
{
egw_insertJS(res.data.value);
}
hasResponse = true;
}
} else

View File

@ -86,6 +86,57 @@ egw_seperateJavaScript = function(_html)
_html.html = html;
}
/**
* Inserts the script tags inside the given html into the dom tree
*/
function egw_insertJS(_html)
{
// Insert each script element seperately
if (_html)
{
var in_pos = -1;
var out_pos = -1;
do {
// Search in and out position
var in_pos = _html.search(/<script/im);
var out_pos = _html.search(/<\/script>/im);
// Copy the text inside the script tags...
if (in_pos > -1 && out_pos > -1)
{
if (out_pos > in_pos)
{
var scriptStart = _html.indexOf("\>", in_pos);
if (scriptStart > in_pos)
{
var script = _html.substring(scriptStart + 1,
out_pos);
try
{
// And insert them as real script tags
var tag = document.createElement("script");
tag.setAttribute("type", "text/javascript");
tag.text = script;
document.getElementsByTagName("head")[0].appendChild(tag);
}
catch (e)
{
if (typeof console != "undefined" && typeof console.log != "undefined")
{
console.log('Error while inserting JS code:', _e);
}
}
}
}
_html = _html.substr(out_pos + 9);
}
} while (in_pos > -1 && out_pos > -1)
}
}
/**
* Returns the top window which contains the current egw_instance, even for popup windows