Skip to content

Commit 659f0c1

Browse files
committed
Fire event
1 parent e887a0b commit 659f0c1

File tree

1 file changed

+58
-57
lines changed

1 file changed

+58
-57
lines changed

javascript/addressfinder.js

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,69 @@
1-
;(function($) {
2-
$(document).ready(function () {
3-
$(".address_finder").each(function (i, elem) {
4-
var widget,
5-
key = $(elem).data('api-key'),
6-
address = $(elem).find('.address_finder_address'),
7-
input = $(elem).find("input").first(),
8-
manual = $(elem).find('.manual_address'),
9-
toggle = $(elem).find('.toggle_manual_address');
1+
;(function ($) {
2+
$(document).ready(function () {
3+
$('.address_finder').each(function (i, elem) {
4+
var widget,
5+
key = $(elem).data('api-key'),
6+
address = $(elem).find('.address_finder_address'),
7+
input = $(elem).find('input').first(),
8+
manual = $(elem).find('.manual_address'),
9+
toggle = $(elem).find('.toggle_manual_address')
1010

11-
var useManual = manual.find("input[name*=ManualAddress]"),
12-
field = address.find('input').get(0);
11+
var useManual = manual.find('input[name*=ManualAddress]'),
12+
field = address.find('input').get(0)
1313

14-
/* update ui with javascript */
15-
toggle.show();
16-
address.show();
14+
/* update ui with javascript */
15+
toggle.show()
16+
address.show()
1717

18-
if(!useManual.val()) {
19-
manual.hide();
20-
}
18+
if (!useManual.val()) {
19+
manual.hide()
20+
}
2121

22-
/* create widget */
23-
widget = new AddressFinder.Widget(field, key, {
24-
show_locations: false
25-
});
22+
/* create widget */
23+
widget = new AddressFinder.Widget(field, key, {
24+
show_locations: false
25+
})
2626

27-
/* updates manual fields and hidden metadata */
28-
widget.on("result:select", function (value, item) {
29-
/* populate postal line fields */
30-
for(var i = 1; i <= 6; i++) {
31-
manual.find("input[name*=PostalLine" + i +"]").val(item["postal_line_"+ i] || '');
32-
}
27+
/* updates manual fields and hidden metadata */
28+
widget.on('result:select', function (value, item) {
29+
/* populate postal line fields */
30+
for (var i = 1; i <= 6; i++) {
31+
manual.find('input[name*=PostalLine' + i + ']').val(item['postal_line_' + i] || '')
32+
}
3333

34-
manual.find("input[name*=Suburb]").val(item.suburb || '');
35-
manual.find("input[name*=City]").val(item.city || '');
36-
manual.find("input[name*=Postcode]").val(item.postcode || '');
37-
manual.find("input[name*=Longitude]").val(item.x || '');
38-
manual.find("input[name*=Latitude]").val(item.y || '');
39-
});
34+
manual.find('input[name*=Suburb]').val(item.suburb || '')
35+
manual.find('input[name*=City]').val(item.city || '')
36+
manual.find('input[name*=Postcode]').val(item.postcode || '')
37+
manual.find('input[name*=Longitude]').val(item.x || '')
38+
manual.find('input[name*=Latitude]').val(item.y || '')
4039

41-
/* click handler to toggle manual div */
42-
toggle.on('click', function(e) {
43-
e.preventDefault();
40+
$('body').trigger(jQuery.Event('addressselected'))
41+
})
4442

45-
manual.toggle('slow');
43+
/* click handler to toggle manual div */
44+
toggle.on('click', function (e) {
45+
e.preventDefault()
4646

47-
// if the manual address is visible then add a hidden flag so
48-
if(manual.is(":visible")) {
49-
useManual.val('1');
50-
}
51-
else {
52-
useManual.val('0');
53-
}
54-
});
47+
manual.toggle('slow')
5548

56-
/* on manually changing of the fields then we have to clear x/y */
57-
manual.on('keydown', 'input', function(e) {
58-
manual.find("input[name*=Longitude]").val('');
59-
manual.find("input[name*=Latitude]").val('');
60-
});
49+
// if the manual address is visible then add a hidden flag so
50+
if (manual.is(':visible')) {
51+
useManual.val('1')
52+
} else {
53+
useManual.val('0')
54+
}
55+
})
6156

62-
/* focusing back on the address dropdown should hide the manual */
63-
input.on('focus', function(e) {
64-
manual.slideUp();
65-
});
66-
});
67-
});
68-
})(jQuery);
57+
/* on manually changing of the fields then we have to clear x/y */
58+
manual.on('keydown', 'input', function (e) {
59+
manual.find('input[name*=Longitude]').val('')
60+
manual.find('input[name*=Latitude]').val('')
61+
})
62+
63+
/* focusing back on the address dropdown should hide the manual */
64+
input.on('focus', function (e) {
65+
manual.slideUp()
66+
})
67+
})
68+
})
69+
})(jQuery)

0 commit comments

Comments
 (0)