Skip to content

Commit

Permalink
Merge pull request #174 from scythianfuego/patch-1
Browse files Browse the repository at this point in the history
fix bug with some of links already bound
  • Loading branch information
asual committed Sep 28, 2013
2 parents 60007ac + 0df4483 commit 1a8c17c
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/jquery.address.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,32 +566,34 @@
})();

$.fn.address = function(fn) {
if (!this.data('address')) {
this.on('click', function(e) {
if (e.shiftKey || e.ctrlKey || e.metaKey || e.which == 2) {
return true;
}
var target = e.currentTarget;
if ($(target).is('a')) {
e.preventDefault();
var value = fn ? fn.call(target) :
/address:/.test($(target).attr('rel')) ? $(target).attr('rel').split('address:')[1].split(' ')[0] :
$.address.state() !== undefined && !/^\/?$/.test($.address.state()) ?
$(target).attr('href').replace(new RegExp('^(.*' + $.address.state() + '|\\.)'), '') :
$(target).attr('href').replace(/^(#\!?|\.)/, '');
$.address.value(value);
}
}).on('submit', function(e) {
var target = e.currentTarget;
if ($(target).is('form')) {
e.preventDefault();
var action = $(target).attr('action'),
value = fn ? fn.call(target) : (action.indexOf('?') != -1 ? action.replace(/&$/, '') : action + '?') +
$(target).serialize();
$.address.value(value);
}
}).data('address', true);
}
$(this).each(function(index) {
if (!$(this).data('address')) {
$(this).on('click', function(e) {
if (e.shiftKey || e.ctrlKey || e.metaKey || e.which == 2) {
return true;
}
var target = e.currentTarget;
if ($(target).is('a')) {
e.preventDefault();
var value = fn ? fn.call(target) :
/address:/.test($(target).attr('rel')) ? $(target).attr('rel').split('address:')[1].split(' ')[0] :
$.address.state() !== undefined && !/^\/?$/.test($.address.state()) ?
$(target).attr('href').replace(new RegExp('^(.*' + $.address.state() + '|\\.)'), '') :
$(target).attr('href').replace(/^(#\!?|\.)/, '');
$.address.value(value);
}
}).on('submit', function(e) {
var target = e.currentTarget;
if ($(target).is('form')) {
e.preventDefault();
var action = $(target).attr('action'),
value = fn ? fn.call(target) : (action.indexOf('?') != -1 ? action.replace(/&$/, '') : action + '?') +
$(target).serialize();
$.address.value(value);
}
}).data('address', true);
}
});
return this;
};

Expand Down

0 comments on commit 1a8c17c

Please sign in to comment.