Great Daniel,

thanks for sharing! That's great! -- Just a side note: It should be
possible to include the jQuery library with
jsimport("jquery-1.7.2.min.js"). Check the "examplejs" Pyjs examle for
details.

Can you do the project a favour? Please add your example use of
embedding external JavaScript libs to the FAQ article on GitHub:
https://github.com/pyjs/pyjs.org/wiki/FAQ -- If you think there is a
better place on the website (note: that wiki is the content of the
website) put it there, and update the Menu wiki article if needed.

On the other hand, what do you think about added your example as an
example the the Pyjs examples? For example! ;-)
I think we had a wiki article, or an example that showed off including
3rd-party JS libraries in Pyjs, but I can't find any traces of it
anymore. Strange.

Cheers, Peter


2012/7/3 Daniel Gonzalez <gonva...@gmail.com>:
> I got this to work and I wanted to share it in case it is helpful, or in
> case you have comments. First some explanation:
>
> loading jquery in the .html puts the jquery library in the top context, that
> is why it was not working out of the box for me
> pyjs is creating the components in the top document too
> so now we have jquery in the top context, and the created component in the
> top context. Since jQuery uses by the default the context in which it was
> loaded to look for components, we just need to use the top jQuery. To do
> that, we need the top. prefix.
>
> The resulting code looks like this:
>
> import pyjd # this is dummy in pyjs
>
>
> from pyjamas.ui.HTML import HTML
> from pyjamas.ui.RootPanel import RootPanel
> from __pyjamas__ import JS
>
>
> class jQueryTest:
>
>
>     def onModuleLoad(self):
>         html = HTML('<p><input type="hidden" id="aa10" style="width:300px"
> value="brown, red, green"/></p>')
>         RootPanel().add(html)
>         JS("""top.jQuery("#aa10").select2({tags:["red", "green",
> "blue"]});""")
>
>
> if __name__ == '__main__':
>     pyjd.setup("./public/jQueryTest.html")
>     app = jQueryTest()
>     app.onModuleLoad()
>     pyjd.run()
>
> And the related .html:
>
> <html>
>     <head>
>         <script src="jquery-1.7.2.min.js"></script>
>
>         <link rel="stylesheet" href="select2.css" />
>         <script src="select2.js"></script>
>
>         <meta name="pygwt:module" content="jQueryTest">
>         <title>Test jQuery!</title>
>     </head>
>     <body bgcolor="white">
>         <script language="javascript" src="bootstrap.js"></script>
>
>
>     <iframe id='__pygwt_historyFrame'
> style='width:0;height:0;border:0'></iframe>
>     </body>
> </html>
>
> This is working with pyjs as standalone application. Now I have pyjs
> embedded in a web2py container. Let's see if I get this to work.
>
> Regards,
> Daniel

Reply via email to