On 6 mai, 17:47, Alyxandor <[email protected]> wrote:
> George's hack with the boolean for "don't do history stuff" is
> actually a surprisingly good way to deal with History Events.
>
> In order to achieve History events from multiple sources with multiple
> targets, some validation on HistoryToken is needed, and using a
> boolean variable will let you change this functionality
> programmatically. This might not seem like a big deal until you
> notice how you can't click a history-link after it's been clicked
> once. Say, you open an iframe on a history event, and once it's
> closed, you want to let the user click on it again without having to
> click on anything else. The only way is to inject a useless
> HistoryToken with History.newItem("do nothing",false);, but now you
> will lose directionality {as forward to "do nothing" looks like
> backward to "do nothing"}, which means you now need to inject ("go
> forward",false); AND ("go backward",false), and when a REAL history
> event is fired, do History.goBack();History.goBack(); or
> History.goForward();History.goForward();
>
> It may seem like a gross hack, but it DOES help you to make your
> application more static and bookmarkable.
I find it much easier/better to just use an Anchor with a ClickHandler
that mimics the Hyperlink (Hyperlink would be equivalent to wrap the
Anchor in a SimplePanel and set the panel's primary style name to gwt-
Hyperlink).
final String TARGET_HISTORY_TOKEN = "targetHistorytoken";
Anchor anchor = new Anchor("text", "#" + TARGET_HISTORY_TOKEN);
anchor.addClickHandler(new ClickHandler() {
static final HyperlinkImpl impl = GWT.create(HyperlinkImpl.class);
public void onClick(ClickEvent event) {
if (impl.handleAsClick(Event.as(event.getNativeEvent()))) {
// do your stuff here and choose whether to call the
following History.newItem
History.newItem("targetHistoryToken");
// ...though always prevent default (a priori), unless that's
not what you want...
event.preventDefault();
}
}
});
> Using anchor overrides and doing it all in javascript means you lose
> state when the user actually presses back or forward, AND when power-
> users view your site, they might want to open a few windows at the
> same time by Ctrl+clicking links. We all do it, and if every link
> opens "javascript:void(0);", the only way to have multiple tabs of
> content is to open each to the home page and manually navigate the to
> the application state you want to test / experience.
>
> Taking the time to hack with History support will be worth it when
> your users start bookmarking your content, and that bookmark actually
> points to the content they want to see next time.
In your "iframe" sample use case above, though, you're mis-using the
history/hyperlink, as the history state is not "stable" (you can
"close the iframe", whatever it means to you), and you're expecting
the hyperlink to take an action (re-open the "closed iframe"), not
only navigate to a given history state. It would be quite easy to
solve (hack!) by testing the current history getToken() and then call
newItem(x) or fireCurrentHistoryState(). I'm using such a "hack" (in
response to async requests though; instead of rewriting my app) and it
works pretty well.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---