Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2005-05-17 08:06:56

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

eval and functions

i tried to improve the loadback-function (see http://xinha.gogo.co.nz/punbb/viewtopic.php?id=218) and ran into a problem:
within the _loadback-function i can't eval the plugin-code as it must be defined as global functions!

i wrote a little example to show the problem:

  function loadFullScreen()
  {
    var str = "function FullScreen() { }";
    eval(str);
    alert(FullScreen); //works, as FullScreen is defined here
  }
  loadFullScreen();
  alert(FullScreen); //does not work, as FullScreen is only avaliable in _loadback

a solution to the problem would be to use another namespace, so that plugins are not global functions, instead HTMLArea.PluginName
(whis is in general a good solution to avoid problems - for example one could easyly have a function "CSS" allready defined in the cms)

  function HTMLArea() { }
  HTMLArea.loadFullScreen = function()
  {
    var str = "HTMLArea.FullScreen = function() { }";
    eval(str);
    alert(HTMLArea.FullScreen); //works
  }
  HTMLArea.loadFullScreen();
  alert(HTMLArea.FullScreen); //works too!!

or does anybody have another solution to my problem?


Niko

Offline

#2 2005-05-17 12:15:28

gogo
Xinha Leader
From: New Zealand
Registered: 2005-02-11
Posts: 1,015
Website

Re: eval and functions

Exactly.  That was why I didn't go with XMLHTTPRequest to load plugins.  I couldn't come up with any way of getting the code to be evaluated in the global scope (technically the scope of window).

I'm pretty sure I mentioned that somewhere in the past?

Did you have a look at the code that the dude who was working on the Safari stuff did?  How did he do it?


James Sleeman

Offline

#3 2005-05-17 12:56:32

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: eval and functions

I'm pretty sure I mentioned that somewhere in the past?

i can't remember or didn't read it.


i didn't find any code, the latest commit was 4 weeks ago.

and he says:

I had to modify dialog.js, popupwin.js and the main script of each plugin to use the declaration syntax: functionName = function(args) { .... rather than function functionName(args) { ... Otherwise the eval function on the request response did not seem to work in Safari (it worked in all other browsers)

so he might got it working big_smile


...but anyway, what is your opinion of
HTMLArea.PluginName instead of PluginName?

because with that we would not have any problem big_smile


Niko

Offline

#4 2005-05-17 13:20:42

gogo
Xinha Leader
From: New Zealand
Registered: 2005-02-11
Posts: 1,015
Website

Re: eval and functions

because with that we would not have any problem

But would have a lot of changes :-(

What is the reason we should try and use XMLHTTPRequest anyway when just inserting a script into the dom seems to work fine?


James Sleeman

Offline

#5 2005-05-17 14:33:35

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: eval and functions

because
1. no callback-functions would be needed anymore (like in newbie guide, and it will be more compatible to the old htmlarea)
2. i do have a xinha installation where i get in infinite-loop where xinha trying to load dialog.js... i don't know why or what happens there, but this would solve it
3. errors in the plugins would not cause loading the files again and again (yes, there are other solutions too for that - but this is the easiest and fastest)
4. performance(?) when waiting for the syncron xmlhttprequest no JS is executed
5. see my last comment in http://xinha.python-hosting.com/ticket/226 - the current solution doesn't quite work right(?) i might do some debugging in here... if it is really a problem...


Niko

Offline

#6 2005-05-17 22:52:41

gogo
Xinha Leader
From: New Zealand
Registered: 2005-02-11
Posts: 1,015
Website

Re: eval and functions

Hmmmm.

There is something else to consider - debugging, and error messages in general.  If we use XMLHTTPRequest and then eval then the browser can't tie the code to a filename, which makes debugging much harder.

I think we need to stick with inserting script tags in this case.  I'll rewrite loadplugin and loadplugins to solve the problem in 226 .


James Sleeman

Offline

#7 2005-05-18 01:47:31

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: eval and functions

ok, debugging is a good point. however if you activate "pretty print" in venkman debugging works again! (not that nice, but it works) (i'm sure the Microsoft Debugger is not that good)

and the reason why stanislas used eval and xmlhttprequest is that safari doesn't work with the inserting-script-tag:
http://lists.apple.com/archives/webcore … 00009.html
(currently we have no safari support, but sooner or later we might get it... and we will have the problem then again...)

I think we need to stick with inserting script tags in this case.  I'll rewrite loadplugin and loadplugins to solve the problem in 226 .

that would be nice big_smile
...you could rewrite _loadback - so that it loads every file only once (and the plugins that way too...)
and when will you have time for such a rewrite? or should i give it a try big_smile


Niko

Offline

#8 2005-05-18 03:42:56

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: eval and functions

2. i do have a xinha installation where i get in infinite-loop where xinha trying to load dialog.js... i don't know why or what happens there, but this would solve it

...problem solved... eval and xmlhttprequest would not have helped, although it might made debugging easier big_smile


Niko

Offline

Board footer

Powered by FluxBB