nedich / delphi-javascript

Automatically exported from code.google.com/p/delphi-javascript
1 stars 2 forks source link

JQuery? #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello!

Can i execute JQuery with it? And other librarys?

Thanks

Original issue reported on code.google.com by david.lo...@gmail.com on 18 Dec 2012 at 11:38

GoogleCodeExporter commented 9 years ago
NO, jquery needs a browser implementation

Original comment by n.ame...@gmail.com on 18 Dec 2012 at 12:29

GoogleCodeExporter commented 9 years ago
NO! Its possible with this http://www.envjs.com/

Please test... 

Original comment by david.lo...@gmail.com on 18 Dec 2012 at 12:55

GoogleCodeExporter commented 9 years ago
If you implement browser functionality that is needed from jquery 
yes...otherwise the way it is NO

Original comment by n.ame...@gmail.com on 18 Dec 2012 at 12:56

GoogleCodeExporter commented 9 years ago
Well how to do it? Please make an example how to do it :)

Original comment by david.lo...@gmail.com on 18 Dec 2012 at 12:58

GoogleCodeExporter commented 9 years ago
This is not a simple example....you need to expose from your code ALL API used 
from browsers in javascript....in other words almost impossible ..

Original comment by n.ame...@gmail.com on 18 Dec 2012 at 12:59

GoogleCodeExporter commented 9 years ago
See the following url
http://powerman.name/doc/jquery_in_spidermonkey.html#_run

download env.js and then write some code like, then u should be able running 
jquery

  FJSEngine := TJSEngine.Create;
  FJSEngine.registerGlobalFunctions(TJSGlobalFunctions);
  FJSEngine.EvaluateFile('env.js');
// print([expression ...])
  FJSEngine.Evaluate('Envjs.log=print;');

type
  TJSGlobalFunctions = class
    class procedure  print(s: string); static;
  end;

class procedure TJSGlobalFunctions.print(s: string);
begin
  writeln(s);
end;

Original comment by n.ame...@gmail.com on 18 Dec 2012 at 1:28

GoogleCodeExporter commented 9 years ago
So it is possible in theory?

Original comment by david.lo...@gmail.com on 18 Dec 2012 at 1:52

GoogleCodeExporter commented 9 years ago
Yes...but you are on your own ... :-)
Bellow full console sample

program js;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  js15decl in '..\js15decl.pas',
  jsDbgServer in '..\jsDbgServer.pas',
  jsintf in '..\jsintf.pas',
  NamedPipesImpl in '..\NamedPipesImpl.pas';

Type
  TJSGlobalFunctions = class
    class procedure  print(s: string); static;
  end;

var
  Engine: TJSEngine;

{ TJSGlobalFunctions }

class procedure TJSGlobalFunctions.print(s: string);
begin
  writeln(s);

end;

begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
    Engine := TJSEngine.Create;
    Engine.registerGlobalFunctions(TJSGlobalFunctions);
    Engine.EvaluateFile('env.js');
    Engine.Evaluate('Envjs.log=print;');
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Original comment by n.ame...@gmail.com on 18 Dec 2012 at 1:59

GoogleCodeExporter commented 9 years ago
Amazing! :) 

I knew it is possible now i test, thanks! :)

Original comment by david.lo...@gmail.com on 18 Dec 2012 at 2:04

GoogleCodeExporter commented 9 years ago
Note that you will still need ti  implement Envjs.XXXXXXX functions like the 
one i assign to print Envjs.log, look @ the begining of env.js and see 
functions like

Envjs.eval = function(context, source, name){};

Such function need to be defined in your delphi code.

Original comment by n.ame...@gmail.com on 18 Dec 2012 at 2:45

GoogleCodeExporter commented 9 years ago
How will this work.. If i extract <script> from a given website and run it 
inside the TJSEngine? For example a script from Google.com or other website. 
Just an example. 

Do i need to implement my functions aswell?

Original comment by david.lo...@gmail.com on 20 Dec 2012 at 2:31