Skip to content

Instantly share code, notes, and snippets.

@tarnus
Created June 5, 2014 16:35
Show Gist options
  • Save tarnus/c46545ccded3520a62b3 to your computer and use it in GitHub Desktop.
Save tarnus/c46545ccded3520a62b3 to your computer and use it in GitHub Desktop.
Jquery to populate link locations
(function ($) {
Drupal.behaviors.appointment = {
attach: function(context, settings) {
//Begin my code
function arrayContains(needle, arrhaystack)
{
return (arrhaystack.indexOf(needle) > -1);
}
var statelist=new Array();
/*
var statlistapi = "http://rnetwork.snethosting.com/property_calls/state_json";
$.getJSON(statlistapi, function(json) {
$.each(json.states, function(i, field){
//statelist[i]=field;
});
});
*/
var data= new Array();
$.ajax({
dataType: "json",
cache: true,
url: 'http://rnetwork.snethosting.com/property_calls/state_json',
data: data,
success: function(data){ // do something here
$.each(data.states, function(i, field){
statelist[i]=field;
//console.log(statelist[i]);
});
}
});
$('#map').usmap({
stateStyles: {fill: '#0AA629'},
stateHoverStyles: {fill: '#C7F464'},
showLabels: true,
// The click action
click: function(event, data) {
// console.log(data.name);
if (arrayContains(data.name,statelist)){
window.location = "/list_properties/"+data.name;
}else{
alert("States are un-available");
}
/*$('#clicked-state')
.text('You clicked: '+data.name)
.parent().effect('highlight', {color: '#C7F464'}, 2000);
*/
}
});
// End my code
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment