diff --git a/src/jquery.address.js b/src/jquery.address.js index 8e17f18..a008daf 100644 --- a/src/jquery.address.js +++ b/src/jquery.address.js @@ -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; };