Skip to content

Commit

Permalink
Fixes issue asual#171 at the expense of regressing asual#174
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Novakowski committed Aug 1, 2014
1 parent 870ed7a commit e715213
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/jquery.address.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,34 +578,34 @@
})();

$.fn.address = function(fn) {
$(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);
}
});
// Changes to this method fix issue #171 at the expense of regressing https://github.com/asual/jquery-address/pull/174
// But this is okay for our site since we never call $().address(fn) again once the site is initialized.
if (!$(this).data('address')) {
$(document).on('click', this.selector, 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', this.selector, 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 e715213

Please sign in to comment.