Hi, i have a script that works fine when i execute it in a page:
[code]
var Drag<?=$id;?> = {
obj : null,
init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
{
o.onmousedown = Drag<?=$id;?>.start;
o.hmode = bSwapHorzRef ? false : true ;
o.vmode = bSwapVertRef ? false : true ;
o.root<?=$id;?> = oRoot && oRoot != null ? oRoot : o ;
if (o.hmode && isNaN(parseInt(o.root<?=$id;?>.style.left ))) o.root<?=$id;?>.style.left = “0px”;
if (o.vmode && isNaN(parseInt(o.root<?=$id;?>.style.top ))) o.root<?=$id;?>.style.top = “0px”;
if (!o.hmode && isNaN(parseInt(o.root<?=$id;?>.style.right ))) o.root<?=$id;?>.style.right = “0px”;
if (!o.vmode && isNaN(parseInt(o.root<?=$id;?>.style.bottom))) o.root<?=$id;?>.style.bottom = “0px”;
o.minX = typeof minX != “undefined” ? minX : null;
o.minY = typeof minY != “undefined” ? minY : null;
o.maxX = typeof maxX != “undefined” ? maxX : null;
o.maxY = typeof maxY != “undefined” ? maxY : null;
o.xMapper = fXMapper ? fXMapper : null;
o.yMapper = fYMapper ? fYMapper : null;
o.root<?=$id;?>.onDragStart = new Function();
o.root<?=$id;?>.onDragEnd = new Function();
o.root<?=$id;?>.onDrag = new Function();
},
start : function(e)
{
var o = Drag<?=$id;?>.obj = this;
e = Drag<?=$id;?>.fixE(e);
var y = parseInt(o.vmode ? o.root<?=$id;?>.style.top : o.root<?=$id;?>.style.bottom);
var x = parseInt(o.hmode ? o.root<?=$id;?>.style.left : o.root<?=$id;?>.style.right );
o.root<?=$id;?>.onDragStart(x, y);
o.lastMouseX = e.clientX;
o.lastMouseY = e.clientY;
if (o.hmode) {
if (o.minX != null) o.minMouseX = e.clientX – x + o.minX;
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX – o.minX;
} else {
if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
}
if (o.vmode) {
if (o.minY != null) o.minMouseY = e.clientY – y + o.minY;
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY – o.minY;
} else {
if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
}
document.onmousemove = Drag<?=$id;?>.drag;
document.onmouseup = Drag<?=$id;?>.end;
return false;
},
drag : function(e)
{
e = Drag<?=$id;?>.fixE(e);
var o = Drag<?=$id;?>.obj;
var ey = e.clientY;
var ex = e.clientX;
var y = parseInt(o.vmode ? o.root<?=$id;?>.style.top : o.root<?=$id;?>.style.bottom);
var x = parseInt(o.hmode ? o.root<?=$id;?>.style.left : o.root<?=$id;?>.style.right );
var nx, ny;
if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
nx = x + ((ex – o.lastMouseX) * (o.hmode ? 1 : -1));
ny = y + ((ey – o.lastMouseY) * (o.vmode ? 1 : -1));
if (o.xMapper) nx = o.xMapper(y)
else if (o.yMapper) ny = o.yMapper(x)
Drag<?=$id;?>.obj.root<?=$id;?>.style[o.hmode ? “left” : “right”] = nx + “px”;
Drag<?=$id;?>.obj.root<?=$id;?>.style[o.vmode ? “top” : “bottom”] = ny + “px”;
Drag<?=$id;?>.obj.lastMouseX = ex;
Drag<?=$id;?>.obj.lastMouseY = ey;
Drag<?=$id;?>.obj.root<?=$id;?>.onDrag(nx, ny);
return false;
},
end : function()
{
document.onmousemove = null;
document.onmouseup = null;
Drag<?=$id;?>.obj.root<?=$id;?>.onDragEnd( parseInt(Drag<?=$id;?>.obj.root<?=$id;?>.style[Drag<?=$id;?>.obj.hmode ? “left” : “right”]),
parseInt(Drag<?=$id;?>.obj.root<?=$id;?>.style[Drag<?=$id;?>.obj.vmode ? “top” : “bottom”]));
Drag<?=$id;?>.obj = null;
},
fixE : function(e)
{
if (typeof e == “undefined”) e = window.event;
if (typeof e.layerX == “undefined”) e.layerX = e.offsetX;
if (typeof e.layerY == “undefined”) e.layerY = e.offsetY;
return e;
}
}
var theHandle<?=$id;?> = document.getElementById(“handle<?=$id;?>”);
var theRoot<?=$id;?> = document.getElementById(“root<?=$id;?>”);
Drag<?=$id;?>.init(theHandle<?=$id;?>, theRoot<?=$id;?>, 0, 1000, 0, 600, 0, 0, 0, 0);
but, when i open it with an ajax function, and try to parse the scripts like this:
[code]
function parseScript(_source) {
var source = _source;
var scripts = new Array();
// Strip out tags
while(source.indexOf(“<script”) > -1 || source.indexOf(“</script”) > -1) {
var s = source.indexOf(“<script”);
var s_e = source.indexOf(“>”, s);
var e = source.indexOf(“</script”, s);
var e_e = source.indexOf(“>”, e);
// Add to scripts array
scripts.push(source.substring(s_e+1, e));
// Strip from source
source = source.substring(0, s) + source.substring(e_e+1);
}
// Loop through every script collected and eval it
for(var i=0; i<scripts.length; i++) {
try {
eval(scripts[i]);
}
catch(ex) {
alert(“Epic fail”);
}
}
// Return the cleaned source
return source;
}
//here is the ajaxstuff
//here ends the ajax stuff
document.getElementById(“ajax”).innerHTML = parseScript(result);
it stops at the
[code]
Drag<?=$id;?>.init(theHandle<?=$id;?>, theRoot<?=$id;?>, 0, 1000, 0, 600, 0, 0, 0, 0);
line. It sais Epic fail.
When i put an alert on top of it it shows, then it sais Epic Fail.
Anybody knows why?