PageSourceSearch

https://engage.natureaustralia.org.au/neutrino/crm01/js/crm.js

js natureaustralia.org.au collected 2026-10-02 04:03:38 UTC 11,245 bytes, 314 lines download raw bytes

1var Crm;
2(function() {
3	var settings = {};
4	Crm = {
5		init: function(opts) {
6			$.extend(settings, opts);
7			
8			$(function() {
9				$("form[name=newsletter_signup]").each(function() {
10					var form = $(this);
11					var validation = $(".validation", form);
12					form.bind("submit", function() {
13						// post ajax
14						var action = settings.pathToNeutrino+"neutrino/crm01/ajax.php?CrmRecipient/signUp";
15						$(".prefilled").trigger("clear");
16						var post = form.serialize();
17						$(".prefilled").trigger("repopulate");
18						$.post(action, post, function(data) {
19							if (data.success == 1) {
20								validation.hide();
21								$(".newsletter_hideonconfirm, .validation", form).hide();
22								$(".newsletter_confirm").show();
23							} else {
24								alert(data.messages.join('\n'));
25							}
26							signupActive = false;
27						}, 'json');
28						
29						return false;
30					});
31				});
32			});
33		},
34		
35		suburbValidate: function(opts) {
36			var options = $.extend({
37				postcodeInput: $([]),
38				suburbInput: $([]),
39				stateInput: $([]),
40				countryInput: $([])
41			}, opts);
42			
43			var isAustralia = true;
44			var postcodeInput = options.postcodeInput;
45			var suburbInput = options.suburbInput;
46			var stateInput = options.stateInput;
47			var countryInput = options.countryInput;
48			var suburbSelect = $('<select><option value="">Select Suburb</option></select>');
49			var suburbHidden = $('<input type="hidden" name="'+suburbInput.attr("name")+'" value="'+suburbInput.val()+'" />');
50			var stateHidden = $('<input type="hidden" name="'+stateInput.attr("name")+'" value="'+stateInput.val()+'" />');
51			
52			suburbHidden.data('oldValue',suburbHidden.val());
53			suburbInput.replaceWith(suburbSelect);
54			suburbSelect.after(suburbHidden);
55			stateHidden.insertAfter(stateInput);
56			
57			//if country input is defined
58			if(countryInput.length){
59				var suburbText = suburbInput.clone().removeAttr("name").hide().insertAfter(suburbHidden);
60				var stateText = stateInput.clone().removeAttr("name").hide().insertAfter(stateHidden);
61				//bind change & keydown to update hidden fields
62				suburbText.bind("keydown change",function(){
63					suburbHidden.val($(this).val());
64				});
65				stateText.bind("keydown change",function(){
66					stateHidden.val($(this).val());
67				});
68				var onCountryChange = function(){
69					var country = countryInput.val();
70					isAustralia = (country == 'AU' || country == 'Australia');
71					if(isAustralia){
72						suburbText.add(stateText).hide();	
73						suburbSelect.add(stateInput).show();
74					}else{
75						suburbSelect.add(stateInput).hide();
76						suburbText.add(stateText).show();	
77					}
78				}
79				onCountryChange();
80				countryInput.bind("change",function(){
81					//clear suburb, postcode and state
82					$.each([suburbHidden,suburbText,suburbSelect,stateHidden,stateInput,stateText,postcodeInput],function(i,input){
83						input.val('');
84					});
85					onCountryChange();
86				});
87			}
88			
89			//state input becomes disabled so that user cannot update it
90			stateInput.removeAttr("name").prop("disabled", true);
91			
92			// suburb drop down population
93			if(suburbHidden.val()){
94				var optionField = $("<option></option>")
95					.attr("value", suburbHidden.val())
96					.text(suburbHidden.val());
97				suburbSelect.append(optionField).val(suburbHidden.val());
98			}
99			
100			postcodeInput.bind("change keyup", function() {
101				if (isAustralia && $(this).val().length == 4) {
102					var action = settings.pathToNeutrino+"neutrino/crm01/ajax.php?CrmSuburb/getSuburb";
103					var post = {
104						postcode: postcodeInput.val()
105					}
106					
107					$.post(action, post, function(data) {
108						if (data.success == 1) {
109							// remove previous options
110							stateInput.val("");
111							$("option:gt(0)", suburbSelect).remove();
112							// add option(s) for new post code
113							$.each(data.postcodes, function(suburb, state) {
114								var optionField = $("<option></option>")
115									.attr("value", suburb)
116									.text(suburb)
117									.data("state", state);
118								suburbSelect.append(optionField);
119								if (suburb == suburbHidden.val()) {
120									optionField.attr("selected", true);
121									suburbSelect.change();
122								}
123							});
124						}
125					}, 'json');
126				}
127			});
128			
129			// state field population
130			suburbSelect.bind("change", function() {
131				var suburbOption = $("option:selected", this);
132				// update state fields
133				suburbHidden.val(suburbOption.val());
134				stateHidden.val(suburbOption.data("state"));
135				stateInput.val(suburbOption.data("state"));
136			});
137			
138			//regularly check if suburb has been changed dynamically by the same address checkbox
139			var t = setInterval(function(){
140				if(suburbHidden.val() != suburbHidden.data('oldValue')){
141					suburbHidden.data('oldValue',suburbHidden.val());
142					postcodeInput.change();
143				}
144			},500);
145		}
146	};
147
148    /*
149     * This function ensures coordination between country and state fields
150     * If the country is Australia or USA, the state must be chosen from a select input
151     *
152     * IMPORTANT: The container should be the direct parent of the address field rows
153     */
154    Crm.addressBlock = function (container, options) {
155        var block = $(container);
156        var opts = $.extend({
157            //default options
158        }, options);
159
160        //define the country select input
161        var countryInput = $("select[name*=country]", block);
162
163        //define the main state input - this will become hidden, but its value will be posted with the form
164        var stateInput = $(":input[type=text][name*=state]", block);
165        var state = stateInput.val();
166
167        //country field should be at the top of the address block
168        var countryRow = block.children(":has([name="+countryInput.attr("name")+"])");
169        countryRow.prependTo(block);
170
171        //hide the main state input
172        stateInput.hide();
173
174        //create a state text input for countries that don't need a strict selection, insert before main state input
175        var stateTextInput = $('<input class="medium state-text" type="text" />')
176            .hide().insertBefore(stateInput).attr('name',stateInput.attr('name')+'-text').val(state);
177
178        //create a state select input for countries that need a strict selection, insert before main state input
179        var stateSelectInput = $('<select class="state-select"><option value="">&nbsp;</option></select>')
180            .hide().insertBefore(stateInput).attr('name',stateInput.attr('name')+'-select');
181
182        //group all state inputs into one variable
183        var stateInputs = stateInput.add(stateTextInput).add(stateSelectInput);
184
185        //this function will update the options within the state select and return true if the country has a state list
186        function updateStateOptions(countryCode) {
187            var list = Crm.addressResources['states-' + countryCode.toLowerCase()];
188
189            //remove existing options
190            $('option:gt(0)', stateSelectInput).remove();
191
192            //if no list is defined for this country, return
193            if (!list) return false;
194
195            //loop through the list and add options
196            $.each(list, function(key, value) {
197                $('<option value="'+key+'">'+value+'</option>').appendTo(stateSelectInput);
198            });
199
200            //set value
201            stateSelectInput.val(state);
202            return true;
203        }
204
205        //this function makes sure the correct input type and state list is showing for the selected country
206        function checkCountry() {
207            var country = countryInput.val();
208            var countryHasStateList = updateStateOptions(country);
209
210            stateSelectInput.toggle(countryHasStateList);
211            stateTextInput.toggle(!countryHasStateList);
212        }
213
214        //when the state is changed by the user, populate the main state field accordingly
215        stateSelectInput.add(stateTextInput).bind("change keyup", function() {
216            state = $(this).val();
217            stateInput.val(state);
218        });
219
220        //when the country changes, make sure state input is correctly displayed
221        countryInput.bind("change", function() {
222            //clear state inputs
223            stateInputs.val('');
224            state = '';
225            checkCountry();
226        }).bind("updated", checkCountry);
227
228        //if the main state input (which is hidden) gets updated, triggering the change event will fix display
229        stateInput.bind("updated", function() {
230            state = $(this).val();
231            checkCountry();
232            stateTextInput.val(state);
233            stateSelectInput.val(state);
234        });
235
236        //ensure state input is correctly displayed on load
237        checkCountry();
238    };
239    Crm.addressResources = {
240        'states-au': {
241            'NSW': 'NSW',
242            'VIC': 'VIC',
243            'QLD': 'QLD',
244            'SA': 'SA',
245            'WA': 'WA',
246            'TAS': 'TAS',
247            'NT': 'NT',
248            'ACT': 'ACT'
249        },
250        'states-us': {
251            'AL': 'Alabama',
252            'AK': 'Alaska',
253            'AZ': 'Arizona',
254            'AR': 'Arkansas',
255            'CA': 'California',
256            'CO': 'Colorado',
257            'CT': 'Connecticut',
258            'DE': 'Delaware',
259            'DC': 'District of Columbia',
260            'FL': 'Florida',
261            'GA': 'Georgia',
262            'HI': 'Hawaii',
263            'ID': 'Idaho',
264            'IL': 'Illinois',
265            'IN': 'Indiana',
266            'IA': 'Iowa',
267            'KS': 'Kansas',
268            'KY': 'Kentucky',
269            'LA': 'Louisiana',
270            'ME': 'Maine',
271            'MD': 'Maryland',
272            'MA': 'Massachusetts',
273            'MI': 'Michigan',
274            'MN': 'Minnesota',
275            'MS': 'Mississippi',
276            'MO': 'Missouri',
277            'MT': 'Montana',
278            'NE': 'Nebraska',
279            'NV': 'Nevada',
280            'NH': 'New Hampshire',
281            'NJ': 'New Jersey',
282            'NM': 'New Mexico',
283            'NY': 'New York',
284            'NC': 'North Carolina',
285            'ND': 'North Dakota',
286            'OH': 'Ohio',
287            'OK': 'Oklahoma',
288            'OR': 'Oregon',
289            'PA': 'Pennsylvania',
290            'RI': 'Rhode Island',
291            'SC': 'South Carolina',
292            'SD': 'South Dakota',
293            'TN': 'Tennessee',
294            'TX': 'Texas',
295            'UT': 'Utah',
296            'VT': 'Vermont',
297            'VA': 'Virginia',
298            'WA': 'Washington',
299            'WV': 'West Virginia',
300            'WI': 'Wisconsin',
301            'WY': 'Wyoming'
302        },
303        'states-uk': {
304            'UK'              : 'UK',
305            'Channel Islands' : 'Channel Islands',
306            'Isle of Man'     : 'Isle of Man',
307            'Isle of Wight'   : 'Isle of Wight',
308            'Isles of Scilly' : 'Isles of Scilly',
309            'Northern Ireland': 'Northern Ireland',
310            'Scotland'        : 'Scotland',
311            'UK-Aberdeen'     : 'UK-Aberdeen'
312        }
313    };
314})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.