$('#some-content-area').ace_ajax({ //options });
.page-content-area[data-ajax-content=true]
element inside .page-content
and its content is updated via ajax because
the following code is available by default in Ace:
$('[data-ajax-content=true]').ace_ajax({ //options });
New Title
html/ajax/ajax.html
file.
data-ajax-content="true"
attribute will have ajax enabled.
assets/js/ace/ace.js
or assets/js/ace.js
or dist/js/ace.min.js
.page-content-area
element with data-ajax-content="true"
attribute.
$('#some-content-area').ace_ajax({ content_url: function(hash) { //hash is the value from document url hash //take "url" param and return the relevant url to load return "path/to/content/"+hash+".html"; }, default_url: 'homepage.html'//default url , loading_icon: "fa-cog fa-2x blue" });
href
attribute should be like "#mypage1", "#mypage2" so that window hash changes and new ajax content is loaded.
content_url
: is the most important part.
A function that returns a url to retrieve.
default_url
: default url (hash) to loadloading_overlay
: specify the element to put the transparent layer over.loading_icon
: the icon to show when loading new content. Default is "fa fa-spin fa-spinner fa-2x orange"loading_text
: the text to show when loading new content. Default is "" (empty string)update_active
: a function or boolean value indicating whether to update "active" state of newly selected link and its parents. Default is trueupdate_breadcrumbs
a function or boolean value indicating whether to update breadcrumbs. Default is trueupdate_title
: a function or boolean value indicating whether to update window title. Default is trueclose_active
: whether to close submenu of previously active items or not. Default is falsemax_load_wait
: time to wait in seconds before stopping ajax content retrieval if it takes too long for content to arrive. Default is falsetitle
tag and update_title
option is true (which is the default),
window title will be updated.
$('#some-content-area').ace_ajax({ content_url: function(hash) { //hash is the value from document url hash //take "hash" param and return the relevant url to load return "content/"+hash+".html"; }, default_url: 'homepage.html'//default url , loading_icon: "fa-cog fa-2x blue" });
content_url
option to return
the correct url.
update_active:true
to work,
the sidebar link element should have data-url
attribute equal to window hash:
update_active
option, to mark the active item:
update_active: function(hash, url) { //do something for example mark selected elements as active //and return the active element to be used in updating breadcrumbs //return active_link_element; }
update_breadcrumbs
option, to update breadcrumbs:
update_breadcrumbs: function(hash, url, active_link_element) { //do something and update breadcrumbs //and return some text to be used in updating window title //return some_text; }
update_title
option, to update window title:
update_title: function(hash, url, some_text) { //do something and update title }Or just insert a
title
tag inside your ajax content.
stopLoading
: call this for ajax loader to stop
$('#some-content-area').ace_ajax('stopLoading', true);
startLoading
is called to start loader:
$('#some-content-area').ace_ajax('startLoading');
loadScripts
is used to load scripts for new ajax page and described in next section.
loadUrl
is used to load a new url based on a hash:
$('#some-content-area').ace_ajax('loadUrl', hash, /* cache or not */);
loadAddr
is used to load a url:
$('#some-content-area').ace_ajax('loadAddr', 'path/to/file.html', null /* optional hash */, /* cache or not */);
working
returns whether ajax loading is in progress or not:
var is_working = $('#some-content-area').ace_ajax('working');
New Title
var scripts = ['path/to/plugin1.js', 'path/to/other-plugin.js'] $('#some-content-area').ace_ajax('loadScripts', scripts, function() { //put inline scripts related to this page here //and clean up some plugin remainings before leaving to another page $('#some-content-area').one('ajaxloadstart', function(e, params) { //cleanup plugin1 //for example for jqGrid: $('#grid_selector').jqGrid('GridUnload'); $('.ui-jqdialog').remove(); //or for some datepicker, etc elements: $('.daterangepicker.dropdown-menu').remove(); //or inline editable $('.editable').editable('destroy'); }) })Note that we need
ajaxloadstart
event only once, thus using "one" instead of "on".
mustache/app/views/assets/scripts/
for more examples.
ajaxloadstart
triggered when new content is requested.
ajaxloaddone
is triggered when ajax content is loadedajaxloadcomplete
is triggered when ajax content is loaded and inserted into domajaxloaderror
is triggered when loading ajax content has failedajaxloadlong
if max_load_wait is specified, this event is triggered when loading ajax has taken too longajaxscriptsloaded
is triggered when loading scripts is finished$('#some-content-area') //or //$(document) .on('ajaxloadstart', function(e, params) { //params.url and params.hash are available if(params.url == 'something') e.preventDefault(); if(params.hash == 'something') e.preventDefault(); //you can also return "false" from "content_url" function to prevent loading })
head
along with its options:
IE8 is a little slow in completing progress so we exclude it.
loading_overlay
option to 'body', so that opaque overlay covers document body
assets/js/ace/ace.js
and look for enableDemoAjax
function
for an example