RE: Encoding a template as a valid JSON String

2013-09-23 Thread Ben Titmarsh
This looks like an ideal solution. Thanks! > Date: Mon, 23 Sep 2013 09:54:34 +0100 > Subject: Re: Encoding a template as a valid JSON String > From: lance.j...@googlemail.com > To: users@tapestry.apache.org > > Since colorbox supports 'inline' option you can solve

Re: Encoding a template as a valid JSON String

2013-09-23 Thread Lance Java
Since colorbox supports 'inline' option you can solve this problem without ever needing the HTML of the element you want to display. Just render the colorbox content in a hidden div and use $("#link").colorbox({inline:true, href:$("#showMe")}

Re: Encoding a template as a valid JSON String

2013-09-22 Thread Martin Kersten
I understand. But there was a way to create a place holder id. I am not quite remembering correctly but it was either injecting a component version that is actually not rendered. So we can use the id of this dummy component for the javascript to write this component. 2013/9/22 Lance Java > > Al

Re: Encoding a template as a valid JSON String

2013-09-22 Thread Lance Java
> Also if I remember correctly doesnt Tapestry always create unique ids for > elements by adding $number to the components name? Whilst it's true that most tapestry components will avoid an id conflict when rendering, in this case it's not tapestry rendering the second instance. A javascript is us

Re: Encoding a template as a valid JSON String

2013-09-21 Thread Martin Kersten
If you can prevent Tapestry from removing your comments, you can just use comments to transfer your data. Walking the dom isnt that costly in java script and if you have a certain div (like the content div etc) you can use it as a starting point. Inside the comment you can write any payload you wan

Re: Encoding a template as a valid JSON String

2013-09-20 Thread Thiago H de Paula Figueiredo
On Fri, 20 Sep 2013 18:48:57 -0300, Dmitry Gusev wrote: And yes, strictly speaking, this will make the document invalid, because it violates specification. But in practice things won't stop working if you put multiple elements with the same ID on a page. You won't see any errors, etc. It

Re: Encoding a template as a valid JSON String

2013-09-20 Thread Thiago H de Paula Figueiredo
On Thu, 19 Sep 2013 08:15:18 -0300, Dmitry Gusev wrote: And by the way, this is not illegal to have multiple elements with the same id Both HTML and XML forbid more than one element having the same id [1]. Otherwise, it wouldn't be called an id. ;) If you need to find more than one ele

Re: Encoding a template as a valid JSON String

2013-09-20 Thread Dmitry Gusev
Probably I wasn't clear here. Of course, having multiple elements with the same ID brakes the meaning of the ID, as you pointed. And yes, strictly speaking, this will make the document invalid, because it violates specification. But in practice things won't stop working if you put multiple elements

Re: Encoding a template as a valid JSON String

2013-09-20 Thread Dmitry Gusev
Below is a working example that illustrates what I was trying to say. Note that colorbox html is a jQuery element with initialized handlers, so no need to convert it to string here. Since we're detaching this element, we don't have any elements copies in dom. http://tapestry.apache.org/schema/tape

Re: Encoding a template as a valid JSON String

2013-09-20 Thread Thiago H de Paula Figueiredo
On Thu, 19 Sep 2013 06:47:20 -0300, Ben Titmarsh wrote: Hi All, Hi! I am using the colorbox JS library for lightboxes in my app. All you do is pass some markup in as a JSON field 'html' and it pops the markup up in a lightbox. So I'm doing this: $.colorbox({html:""}); I'm sorry,

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Lance Java
I don't think you can guarantee that id based css selectors will work on all browsers. And document.getElementById() would also not be guaranteed. It would be simple to develop a component which converts it's body to a string and updates a parameter binding. This component can then be included in

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Dmitry Gusev
Oh, I understand what you mean. In this case you may want to detach dom element before passing it to colorbox. What bad with the server-side JSON string approach, is if you have some ajax functionality in your template (like ajax event links, etc.) -- it won't work,

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Lance Java
Well... In this case, if the cardLightbox generates an id you will start with one hidden element with the id when you render the page. Then, when the colorbox pops up the HTML will be used to create another with exactly the same id. On 19 Sep 2013 11:55, "Dmitry Gusev" wrote: > > You will get 2

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Dmitry Gusev
You will get 2 elements with the same id in dom only if you do this intentionally in code. Tapestry will never do this for you. I use this approach heavily in my code and don't have any problems with it. On Thu, Sep 19, 2013 at 2:47 PM, Lance Java wrote: > Whilst that might work, it will likely

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Lance Java
Whilst that might work, it will likely produce invalid dom. If the element has an id, there's a good chance you will have 2 elements on your page with the same id which us illegal.

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Dmitry Gusev
I think you can do this on client side without any server-side processing, like this: list$.colorbox({ html: $("your client-side selector for t:cardLightbox html").html() }); Just render your component inside of HTML as usual. One thing you will want to do is, probably, to make your html invisibl

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Lance Java
Actually, that should be void beforeRenderTemplate(MarkupWriter writer) { Element container = writer.getElement(); writer.end(); myBlockBodyAsString = container.getChildMarkup(); container.remove(); }

Re: Encoding a template as a valid JSON String

2013-09-19 Thread Lance Java
Unfortunately this is a bit tricky but it can be done TML --- Java --- @InjectComponent Block myBlock; @Property myBlockBodyAsString; Block beginRender(MarkupWriter writer) { writer.element("container"); return myBlock; } void beforeRenderTempl