jquery-address
jquery-address copied to clipboard
.change event fired twice when value has "http://"
Greetings,
For some reason, in Firefox and IE (but not Chrome), the address change event is firing twice when one of the parameters is a url (starts with "http://").
Here's a fiddle with an example: http://jsfiddle.net/5L6Ur/
Clicking on the "foo" link demonstrates my problem. Any help is greatly appreciated.
+1
Its kinda, in the documentation, altho I don't understand it fully yet (but think I can still help a little):
http://www.asual.com/jquery/address/docs/
The author states you should do something depending on the value of the event returned, if you check the event, you'll see you get something different on the two times it is being called on page load.
The first time the change event is fired it seems to pass a function, which you might want to do something with...
The second time the change event is fired, it doesn't have a function... so a simple if statement would allow it to work in the way you would like it to:
$.address.change = function(e){
// console.log('change', e);
if(typeof e !== 'function'){
// do something
}
};
I think if we understood it better, we would know :`) I've had about 30 mins on it so far, on a big project I have come onto half way through... unfortunately this is all I have picked up.
Hope it helps! Loque
ps. I opened my account today, woohoo! :`D
Loque, thanks for replying. For some reason that code didn't work for me. I updated the fiddle here: http://jsfiddle.net/5L6Ur/8/
From what I can tell, e is always an object. I did however, modify the address library a little to make it work. I don't know if it's a good fix or not, but I changed line #93 from this:
diff = _value != hash;
to this:
diff = $.address.decode(_value) != hash;
I did this because I noticed that _value was encoded and hash wasn't causing diff to be true allowing the change event to fire again.
sorry didn't notice the fiddle link (was a bit tired yesterday), and I can see the problem your having now, definitely different to the one I was seeing on the project I am working on (change event was firing twice on page load for us here). Apologies for my poor suggestion.
Edit: deleted my rambling non-sense. I need to read more.
I wasn't able to reproduce the issue with the current 1.4 dev version. Please, let me know if the issue persists.
I have a similar issue where the change event fires once in Safari and Chrome but twice in Firefox. In my case I construct a link based on three parameters (which can be empty strings).
var link = '/' + param1 + '/' + param2 + '/' + param3 + '/'; if( link == '////' ) link = ''; $.address.value(link);
When the link is empty (i.e home page) the change event fires twice in FF, otherwise it works as expected.
My original issue was resolved by upgrading to 1.4