Calendar/naptár blokkban lapozás AJAX segítségével

Kategória: 
Snippet

Ez a kis kód segít abban, hogy a blokkba helyezett calendar nézet miatt ne kelljen mindig újra újratölteni az oldalt, ha a naptárban lapoz valaki. A kód akkor fog működni ha nem az eredeti calendar modul által létrehozott nézetet használod (amúgy sem módosítunk bele modul által létrehozott nézetbe), hanem klónozod my_calendar néven, majd az eredetit letiltod.
sajat.js file-ba írandó, majd a sminkben hozzáadandó, lusták a page.tpl.php-be is beszúrhatják.

<script type="text/javascript">
$(document).ready(function() {
$.ajaxSetup ({cache: false});
// Display animated loading gif during the load event. Change the "path-to-loader-pic" text to a real path to the ajax-loader.pic
var loading = "<center><img class='loading' src='path-to-loader-pic/ajax-loader.gif' alt='loading...' /></center>";
function nextLoad(){
 
// Get the nextURL from the pagers next link
	var nextUrl = $(".view-display-id-calendar_block_1 .date-next a")[0].href; 
	// Identify the content/container you wish to replace
	$(".view-display-id-calendar_block_1")
	// Add the loading image
	.html(loading)
	.css({ opacity: 0 }).fadeTo("normal",1)
	// Load the nextUrl + return the specific content by specifing the css class or id + bind the click function tp the newly loaded //content
	.load(nextUrl+ "#block-views-my_calendar-calendar_block_1 .view-display-id-calendar_block_1 .calendar-calendar", bindClick );
};
 
function prevLoad(){
	var prevUrl = $(".view-display-id-calendar_block_1 .date-prev a")[0].href; 
	$(".view-display-id-calendar_block_1")
	.html(loading)
	.css({ opacity: 0 }).fadeTo("normal",1)
	.load(prevUrl+ "#block-views-my_calendar-calendar_block_1 .calendar-calendar", bindClick );
};
function bindClick(){
	$(".view-display-id-calendar_block_1 .date-prev a").click(function(){ 
	prevLoad();
return false;
});
$(".view-display-id-calendar_block_1 .date-next a").click(function(){ 
	nextLoad();
return false;
});
};
// Append the click function to the on the initial page load
	bindClick();
});
</script> 

Az eredeti kód innen van: http://drupal.org/node/339279#comment-2006476 viszont ét kellett alakítani, különben naptár oldalon a naptár blokk nem viselkedett valami jó.

Hozzászólások

Hozzászólás

A mező tartalma nem nyilvános.
  • Internal paths in double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or relative path.
  • Engedélyezett HTML elemek: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <del> <img>
  • A webcímek és email címek automatikusan linkekké alakulnak.
  • A sorokat és bekezdéseket a rendszer automatikusan felismeri.
  • Engedélyezett HTML elemek: <a> <blockquote> <br> <cite> <code> <dd> <del> <div> <dl> <dt> <em> <li> <ol> <p> <span> <strong> <ul>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <sql>. The supported tag styles are: <foo>, [foo].
  • Minden email cím át lesz alakítva ember által olvasható módon, vagy (ha a JavaScript engedélyezett) ki lesz cserélve kattintható, de biztonságos hivatkozásra.
By submitting this form, you accept the Mollom privacy policy.