Skip to content

Instantly share code, notes, and snippets.

@renovatorruler
Created May 5, 2010 21:15
Show Gist options
  • Save renovatorruler/391445 to your computer and use it in GitHub Desktop.
Save renovatorruler/391445 to your computer and use it in GitHub Desktop.
function initialize() {
//Initialize GeoCoder JSON object, initialize Google map, and center it to NYC,
window.map = new google.maps.Map2(document.getElementById("map"));
window.map.setCenter(new google.maps.LatLng(40.7561, -73.9870), 13); // set center to NYC
window.map.setUIToDefault();
ui=new GMapUIOptions();
ui.maptypes = {normal:true}
ui.zoom = {};
ui.controls = {largemapcontrol3d:true, maptypecontrol:false};
ui.keyboard = false;
window.map.setUI(ui);
window.geoCoder=new GClientGeocoder;
window.alphaString="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
function zInd(marker,b){
return 1000000000; // zindex for center marker
}
function addpity(v,m,f){
//Makes an AJAX call to user/newpity function collects JSON response and creates a new
//location\
$.post("/index.php/user/newpity",
{'name':f.prxName,'radius':f.prxRadius,'address':f.prxAddress,'id':f.id},
function(data){
data=$.evalJSON(data);
if(data.status==0){
$('.jqi .error').html(data.error);
} else {
initDate=new Date('m/d/Y');
initDateString=(initDate.getMonth()+1)+"/"+initDate.getDate()+"/"+initDate.getYear()
window.location.reload();
return true;
//If this is a new pity then show notification that it was created
if(data.isNew==1){
$("#yourPities .alertFlat").hide('slow');
if($('.pity').size()>0){
$('.pity:last').after(data.pity)
} else {$("#yourPities > h3").after(data.pity)}
$('.pity:last').hide().show('slow');
//Gives a jGrowl notification to the user
$.jGrowl("Your new prximity was successfully added.")
$('.pity:last .dateField').DatePicker({
flat:true,
mode:'multiple',
format: 'm/d/Y',
date: initDateString,
current: initDateString,
calendars:1,
starts:1,
onChange: function(formated, dates){
var form=$(this).closest('form');
search(form)
}
})
$.prompt.close();
} else {
//If the proixmity existed before then show update notification
$('.idRef[innerHTML="'+data.id+'"]').closest('.pity').replaceWith(data.pity);
$.jGrowl("Update was successful.")
$('.idRef[innerHTML="'+data.id+'"]').closest('.pity').find('.dateField').DatePicker({
flat:true,
mode:'multiple',
format: 'm/d/Y',
date: initDateString,
current: initDateString,
calendars:1,
starts:1,
onChange: function(formated, dates){
var form=$(this).closest('form');
search(form)
}
})
$.prompt.close();
}
}
}
)
return false;
}
function deletepity(prxId){
//Makes a JSON request to user/delpity method to delete a neighborhood
$("#workingNote").show();
$.post('/index.php/user/delpity',{'id':prxId},
function(data)
{
data=$.evalJSON(data);
if(data.error!="")
{
$("#workingNote").hide();
$.prompt(data.error);
} else
{
$("#workingNote").hide();
$('.idRef[innerHTML='+prxId+']').closest('.pity').hide('fast');
}
}
)
}
//.....
function pageTo(pageNum,itemNum){
//Jumps to a specific page(generally next or prev) on Prximity search results.
//Makes no remote requests, and reuses the JSON object, but if a lot of events
//are being displayed then this may need to be changed to fetch the next set of
//events.
$('.zoomout').eq(0).click();
var itemNum = (itemNum == null) ? 0 : itemNum;
resultsJSON=window.resJSON[0];
$("#searchResultsListing").html("");
var first=(pageNum-1)*window.pagesize;
var last=Math.min(first+window.pagesize,resultsJSON.length);
displayFirst = first+1;
displayLast = last;
total = resultsJSON.length;
if(pageNum==1){$("#prevPage").addClass("greyout")} else {$("#prevPage").removeClass("greyout")}
if(displayLast==total){$("#nextPage").addClass("greyout")} else {$("#nextPage").removeClass("greyout")}
report = displayFirst+" - "+displayLast+" of "+total;
$("#resultsPagination .report").html(report);
//Show only those event markers which are being displayed on the search results.
window.currPage=pageNum;
window.currItem=itemNum;
for(j=0;j<window.markerCurr.length;j++){
window.map.removeOverlay(window.markerCurr[j]);
window.map.addOverlay(window.marker[j]);
}
for(i=first;i<last;i++)
{
if(i!=first){style=" style='display:none'"} else {style=''}
letter=window.alphaString.charAt(i);
var info=resultsJSON[i].mapListing;
$("#searchResultsListing").append(info);
window.map.addOverlay(window.markerCurr[i]);
window.map.removeOverlay(window.marker[i]);
}
$("#searchResultsListing .cont").eq(itemNum).show();
form.find('input[name="savedPage"]').val(window.currPage); //Reset default page to 1 until page reload
form.find('input[name="savedItem"]').val(0); //Reset default item to 0 until page reload
if($(".liveSearch").size()>0){
$.post("/index.php/event/saveResultsPagination",{"page":window.currPage,"item":"0"});
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment