Created
February 17, 2010 07:41
-
-
Save karlbright/306404 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
// Create our evolve homes object to store ajax values inside of | |
$.evolve = { currentPage: 'home', loadingPage: null }; | |
// Function to handle set current page actions | |
$.setCurrentPage = function() { | |
$.evolve.currentPage = $.evolve.loadingPage; | |
$("body").attr('id',$.evolve.currentPage); | |
$.evolve.loadingPage = null; | |
}; | |
// Set ajax logger event handlers | |
$("#ajaxlog").ajaxStart(function(){ | |
$(this).text("Loading..."); | |
}).ajaxSuccess(function(){ | |
$(this).text("Success!"); | |
}).ajaxError(function(){ | |
$(this).text("Error!"); | |
}); | |
// Set default AJAX options | |
$.ajaxSetup({ cache: true, dataType: 'html', type: 'GET' }); | |
// Function to create the link that will handle the AJAX request | |
$.fn.createAjaxLink = function() { | |
this.each(function(){ | |
$(this).bind('click',onAjaxClick); | |
}); | |
} | |
// Actions taken when ajax link is clicked | |
onAjaxClick = function() { | |
$.evolve.loadingPage = $(this).attr('rel'); | |
$.setCurrentPage(); | |
$.ajax({ success: onAjaxSuccess, url: $(this).attr('href') }); | |
return false; | |
} | |
// Actions taken when ajax is loaded successfully | |
onAjaxSuccess = function(data,textStatus,xmlHTTPRequest) { | |
// Get the page content for target page and replace currently page content in DOM | |
successHTML = $(data).find("div#page_content").html(); | |
$("div#page_content").html(successHTML); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
// Create object to store our functions in | |
$.evolve.pages = {}; | |
// Development page | |
$.evolve.pages.developments = function() { | |
console.log("Welcome to the developments page"); | |
} | |
$("body").ajaxSuccess(function(event,xmlHTTPRequest){ | |
// Set our page ID | |
pageID = $(this).attr('id'); | |
// Call related page actions function | |
new Function("$.evolve.pages."+pageID+"()")(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment