[jQuery] Re: Intercept "Back" button click on browser

2008-10-10 Thread David Durham, Jr.

On 9/30/08, Leanan <[EMAIL PROTECTED]> wrote:
>  How can I make it so that when the user clicks the back button in
>  their browser, this same thing happens, as I'll likely have people
>  trying to click the back button instead of the back link on the "page"
>  and then tell me it's broken.  Is it even possible?

In addition to the history stuff that has been discussed, there's also
a browser hook like:

window.onbeforeunload = some_func() {
 // to prevent unload, return a string message
 // otherwise don't explicitly return or I think return void
}

HTH,
Dave


[jQuery] Re: Intercept "Back" button click on browser

2008-10-10 Thread Leanan

Via more investigation, I think I've come across the issue.  The
question is whether this is a bug / needed feature.

It appears that when you use $.history, the click happens twice --
once when you click on whatever you want to click that triggers some
jquery and secondly when the history plugin does it's $.click.

This means, that if you were to add a simple

$('div#my_div').history(function() {
  $('div#hide').hide();
  $('div#show').show();
});

That the .hide() and .show() will get executed twice.  This in itself
isn't particularly harmful as far as display goes --
calling .hide() / .show() on elements that are already hidden/shown
won't unhide / unshow them.  The question I have is, should adding a
toggle to the history be done via $.remote or $.history?  If it's
$.history, then I see a potential problem... if I had the following:

$('div#my_div').history(function() {
  $('div#toggle').toggle(function() {
$('div#hide_show').hide();
  }, function() {
$('div#hide_show').show();
  });
});

It would seem that what would happen is that the toggle would appear
to not work.  I haven't tested this yet, but based on the behavior I
am seeing this is the behavior I would expect to see in the test.

Part of this is brought about by the fact that I am, admittedly,
trying to do something that I don't think any of the history plugins
intended -- I want to log a function that will either do an ajax call
or a simple DOM manipulation depending on some condition.  I myself am
split on whether or not this is something the plugin should handle,
though I do feel that the $.history method should prevent the second
"click" like the $.remote function does for firefox.

On Oct 10, 9:01 am, Leanan <[EMAIL PROTECTED]> wrote:
> Well, originally I had thought that the duplication went away.
>
> It appears now that the duplication only happens when I load datasets
> that are longer than (some yet to be determined) length / time.  I was
> browsing through the code of the plugin and I noticed there was some
> timer stuff added for Opera (I think, haven't looked again and am
> operating on memory).  Perhaps I need to add something similar to
> Firefox and / or IE?  Ideas?
>


[jQuery] Re: Intercept "Back" button click on browser

2008-10-10 Thread Leanan

Well, originally I had thought that the duplication went away.

It appears now that the duplication only happens when I load datasets
that are longer than (some yet to be determined) length / time.  I was
browsing through the code of the plugin and I noticed there was some
timer stuff added for Opera (I think, haven't looked again and am
operating on memory).  Perhaps I need to add something similar to
Firefox and / or IE?  Ideas?

On Oct 9, 4:36 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> On 8 Okt., 18:57, Leanan <[EMAIL PROTECTED]> wrote:
>
> > The duplication is something else.
>
> > However the fix you made works.
>
> That means you still have that duplication? Or not?
>
> --Klaus


[jQuery] Re: Intercept "Back" button click on browser

2008-10-09 Thread Klaus Hartl

On 8 Okt., 18:57, Leanan <[EMAIL PROTECTED]> wrote:
> The duplication is something else.
>
> However the fix you made works.

That means you still have that duplication? Or not?

--Klaus


[jQuery] Re: Intercept "Back" button click on browser

2008-10-08 Thread Leanan

The duplication is something else.

However the fix you made works.


[jQuery] Re: Intercept "Back" button click on browser

2008-10-08 Thread Leanan

Fantastic, thank you.

Where might I be able to get this?

Also, it seems sometimes that even though I'm using

$('a#myidxxx').history(function() {
  $.get(myurl,function(data) {
 $(myappenddiv).append(data);
  });
});

that the data is still getting appended twice.

This doesn't happen all the time though.  I'll try using your fix if I
can find it and see if that might take care of the issue.  Right now
this is only in firefox, as I haven't been able to get my stuff to
work to the point of calling the .history in IE.  (I hate how IE just
fails silently sometimes).


[jQuery] Re: Intercept "Back" button click on browser

2008-10-08 Thread Klaus Hartl

On 7 Okt., 17:50, Leanan <[EMAIL PROTECTED]> wrote:
> All right...
>
> I've found a solution to the problem, though it is not the solution I
> had hoped for.
>
> I basically had to do a $.getscript and generate script that had a $
> (selector).history() for each link.  Not ideal, but it works.  I
> do wonder though if I was doing something wrong in my calls to make it
> so that
>
> $('a.stuff').history(function() {
>   console.info(this);
> )};
>
> was returning this as Window index.html instead of the object for the
> link.  Is this a bug or just user error?

That was a bug, which is fixed now.

--Klaus


[jQuery] Re: Intercept "Back" button click on browser

2008-10-07 Thread Leanan

All right...

I've found a solution to the problem, though it is not the solution I
had hoped for.

I basically had to do a $.getscript and generate script that had a $
(selector).history() for each link.  Not ideal, but it works.  I
do wonder though if I was doing something wrong in my calls to make it
so that

$('a.stuff').history(function() {
  console.info(this);
)};

was returning this as Window index.html instead of the object for the
link.  Is this a bug or just user error?

On Oct 7, 9:59 am, Leanan <[EMAIL PROTECTED]> wrote:
> I forgot to note that when I do a console.info(this) inside that
> function, I get the following in firebug:
>
> Window index.html


[jQuery] Re: Intercept "Back" button click on browser

2008-10-07 Thread Leanan

I forgot to note that when I do a console.info(this) inside that
function, I get the following in firebug:

Window index.html



[jQuery] Re: Intercept "Back" button click on browser

2008-10-07 Thread Leanan

In that situation, 'this' does not appear to be a reference to the
link we've clicked, and when I use firebug and do some console output,
this is what I get:

this.id = undef
/\d/.exec(this.id) is null

I had actually tried something along those lines before, changing my
click handler on the links I wanted added to the history to $
(selector).history.  I can't figure out what I need to query in order
to get at the clicked link's info.

On Oct 7, 9:37 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> Nevertheless you are using the plugin in a way it isn't supposed to be
> used, this is what I wanted to point out and this is where the double
> loading comes from. One from the click handler itself and a second
> time because that click event is triggered again by the plugin.
> Besides if you're not using remote() or history() it will not work in
> IE (doesn't work in Safari 3 anyway as it stands).
>
> What is wrong with the following much less redundant code using the
> history() method:
>
> $('a.testing').history(function() {
>     var i = /\d/.exec(this.id)[0];
>     $.get('chapter-' + i + '.html', function(data) {
>         $('#div1').hide();
>         $('#div2').append(data).show();
>     });
>
> });
>
> --Klaus
>
> On 7 Okt., 14:26, Leanan <[EMAIL PROTECTED]> wrote:
>
> > Not having a test for Chap3 was a typo.  That last if should be
> > adjusted accordingly.
>
> > Klaus-
>
> > I don't want to use .remote, because I only want to make the ajax call
> > once.  If the content we expect to be there isn't there, then I want
> > to load it.  If, however, we've already loaded it, I just want to re-
> > show the div that contains it, not hit the server again (the data I'm
> > getting is large and takes some time to generate.  As the content is
> > not something likely to change in a few minutes, the solution I've
> > come up with is sufficient in that regard).  I already have this
> > functionality working flawlessly.  All I really need to do is that
> > when the back button is hit, div#2 gets hidden and div#1 is shown,
> > and, if someone hits forward from that point, then div#1 is hidden and
> > div#2 is shown.  This is working, too, except for what appears to be a
> > double call to $.get.
>
> > When I do something similar to the demo, the links with the #something
> > get added.  I don't want to log every single link that gets clicked
> > (they expand tables, adjust which divs get shown, etc).  This is why I
> > just have the call to initialize, to add the ability to swap the
> > visibility of the divs when they go back to the base url.
>
> > I don't understand though why it is appearing to call my $.get twice.
> > Is it because when the link with the # is clicked and put in the
> > history the plugin is executing the $.get as well?  This seems odd,
> > since I have neither any $.history or $.remote calls in my script.  I
> > would change my .click to a .history, except that I have a table of
> > links that could be selected, and I need to know which link was
> > clicked, because I need to grab info from the link for the resulting
> > call.
>
> > There must be a way to do this?
>
> > On Oct 7, 2:36 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
>
> > > History/Remote is not supposed to work that way. Although the hash is
> > > changing correctly it will not work in IE for example. You need to
> > > explicitly tell the history manager which links add to history. Just
> > > have a look at the demo. For pure Ajax loading links that is the
> > > remote method. In your case
>
> > > $('a.testing').remote('#div2', function() {
> > >     //callback
>
> > > });
>
> > > $.ajaxHistory.initialize();
>
> > > The show/hide of div1/div2 looks to me like a workaround you don't
> > > need but I'm not sure.
>
> > > --Klaus
>
> > > On 6 Okt., 22:52, Leanan <[EMAIL PROTECTED]> wrote:
>
> > > > Klaus,
>
> > > > I've created a demo that exhibits this behavior.  I modified your demo
> > > > that is included with the script 
> > > > athttp://www.stilbuero.de/jquery/history/
>
> > > > All you should have to do is change your index.html to be the
> > > > following:
>
> > > > 
> > > >   
> > > >       
> > > >       
> > > >       
> > > >       jQuery history/remote - solution for hijaxing links > > > title>
> > > >        > > > script>
> > > >