/    Sign up×
Community /Pin to ProfileBookmark

Does normally work, doesnt work when i use eval()

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);

[/code]

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);

[/code]

it stops at the

[code]
Drag<?=$id;?>.init(theHandle<?=$id;?>, theRoot<?=$id;?>, 0, 1000, 0, 600, 0, 0, 0, 0);
[/code]

line. It sais Epic fail.
When i put an alert on top of it it shows, then it sais Epic Fail.

Anybody knows why?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JunkMaleJan 15.2009 — Ajax is fetching the information and it is not being parsed by the server-side interpreter.
Copy linkTweet thisAlerts:
@blackhawkrobboauthorJan 16.2009 — Ofcourse i know that. The code i put here is the source from the php file. Not the source of the PHP Parsed code.

Parsed it looks like this:

$id is something like "testmodule889374"

Dragtestmodule889374.init(theHandletestmodule889374,theRoottestmodule889374,0, 1000, 0, 600, 0, 0, 0, 0);

But i think i have the solution.

Im changing the PHP to JavaScript so that i only need 1 script that i can include and run by using arguments.

The arguments can be changed by PHP. So thanks for the help, but i think this one can be closed.
Copy linkTweet thisAlerts:
@JunkMaleJan 16.2009 — Your missing the point.

PHP isn't parsed because the AJAX request is bypassing the script interpreter in the server.
Copy linkTweet thisAlerts:
@blackhawkrobboauthorJan 16.2009 — huh? So when i request a PHP page, the PHP parser isn't parsing the PHP? Thats wierd.

If thats true people can request a PHP page of my server and view the source code. I think you're wrong..
×

Success!

Help @blackhawkrobbo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...