Project

General

Profile

Actions

Support #341

closed

How can I use wt with another Javascript library

Added by takashi yamamoto about 14 years ago. Updated almost 14 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
04/03/2010
Due date:
% Done:

0%

Estimated time:

Description

I use jQuery, YUI and MOOTools (in decreasing order of preference), quite extensively in my projects. I would like to use wt with one of these libraries, and attempt to write my own widgets.

I have two questions regarding this:

1. Can you offer any tips on how I can use another JS library (say jQuery or YUI) to wrap around the existing wt widget (and not bother with extJS altogether) ?

2. I would like to write a simple widget (as an initial test). I would like to use jQuery to wrap around the jS generated for the widget display. Can you offer any tips on doing this (i.e. guidelines on the main steps involved) in creating such a widget?

If there is no di

Actions #1

Updated by Koen Deforche almost 14 years ago

  • Status changed from New to Resolved

Hey Takashi,

You invoke custom javascript using WApplication::instance()->doJavaScript() or . You may also want to read the blog post: http://www.webtoolkit.eu/wt/blog/2010/03/02/javascript_that_is_c for a small hint at how to do this without completely uglyfying your C.

You can get the the DOM element that corresponds to using WWidget::id(). Wt actually comes with a recent version of jQuery built-in, so you can use $('#id') and get going.

How to create a widget that wraps a JavaScript library widget will depend a bit on how that JavaScript library relates its widget to a HTML node. If it simply needs a

placeholder, you can start from a WText with setInline(false). One more thing to pay attention to is that you can only reference a widget's DOM element when the widget is actually rendered: sometimes a widget is created but not yet rendered (inserted in the widget tree). The method WWidget::isRendered() will tell you if the widget is currently rendered. To catch the moment on which a widget gets rendered, you should specialize the (currently undocumented) WWidget::render(WFlags flags) method (do not forget to call the base implementation). This method is called each time the widget is rendered initially or updated subsequently.

Care to share what widgets you are planning to wrap ?

Regards,

koen

Actions #2

Updated by takashi yamamoto almost 14 years ago

Hi Koen,

Thanks for the answer, and apologies for the delay in getting back to you. I do not have a specific widget in mind as yet (still very early stages of using wt). But it is likely to be buttons, tables and menus.

HTH

Actions #3

Updated by Koen Deforche almost 14 years ago

  • Status changed from Resolved to Closed

Fixed in 3.1.3

Actions

Also available in: Atom PDF