How to wire to window.onhashchange

53 views
Skip to first unread message

Alexander Beniaminov

unread,
Oct 31, 2012, 10:55:18 AM10/31/12
to nitro...@googlegroups.com
Hi!

How to wire to window.onhashchange event?
 I was trying to ware by
wf:wire(window , #event{ type=hashchange, postback=hashchanged } )
On client side we can see
Nitrogen.$observe_event('page', '.wfid_window', 'hashchange', function anonymous(event) {Nitrogen.$anchor('page', '.wfid_window');
It does not work.
Summing up the question, how to get in touch with any event of the window object?

Alexander Beniaminov

Jesse Gumm

unread,
Nov 2, 2012, 3:46:24 AM11/2/12
to nitrogenweb
Hi Alexander,

Sorry for not responding sooner here.

If you hadn't noticed, the problem with attempting to wire to the window object via wf:wire(window,...) is that 'window' gets treated as a Nitrogen ID path and attempts to wire to that (hence the .wfid_window).

At current, the best way I can think of to wire an event in such a way would be to manually attach an event with jquery, an then use the #api{} functionality to receive the triggers. (http://nitrogenproject.com/demos/api)

The trick would be then, to do something like this, which would even be able to pass the hash value with the postback

wf:wire(#api { name=hashchange, tag=hashchange }),
wf:wire("$(window).bind('hashchange',function(){ page.hashchange(location.hash) })");

...

api_event(hashchange, hashchange, [Hash]) ->
    wf:wire(#alert{text=["The hash is now: ",Hash]}).


As far as I can tell, that's the current best solution for trying to wire directly to the window object for the hashchange event.

Give that a shot and see how it works,

-Jesse




Alexander Beniaminov

--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nitrogenweb/-/y8kwSc-_nfIJ.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitrogenweb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitrogenweb?hl=en.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Alexandre Beniaminov

unread,
Nov 2, 2012, 7:25:49 AM11/2/12
to nitro...@googlegroups.com
Thank you, Jesse.

I've noticed. And even I did try to rewrite nitrogen.js  and couple of modules: wf_render_actions.erl and wf_render_elements.erl. The tree files I've added case for window that is like for page, and it began work as I expected. But I didn't go further. I do not understand how to get location.hash.

Your code allows more freedom

Alexander
 



2012/11/2 Jesse Gumm <gu...@sigma-star.com>



--
С уважением,
Александр Бениаминов

Reply all
Reply to author
Forward
0 new messages