documentation, bugs, feature requests and ideas for ajax framework in tiki
(Cached)
Ajax
Related: Mootools, No Javascript, jQueryWishlist
Developing Ajax
Ajax framework is under development in v1.10. There are two branches of proposals for this framework, one based in xajax
Table of contents
Getting started
First of all, read xajax 10 minutes tutorial
To use ajax in tiki:
In php file, after including tiki-setup.php:
require_once("lib/ajax/ajaxlib.php");
this will import xajax and declare in global scope $ajaxlib, an instance of TikiAjax, that's an extension of xajax class.
Before calling $smarty->display("tiki.tpl"):
$ajaxlib->processRequests();
you don't need to worry about assigning getJavaScript() to smarty or any client-side declaration, everything is already handled by tiki.
To declare and register ajax functions in server, create a php file in lib/feature called feature-ajax.php. In this file, declare the functions and register them with $ajaxlib->registerFunction(). If you need a javascript file, create file lib/feature/feature-ajax.js to hold these functions.
Ajax development guidelines
Ajax applications don't work for everybody. It breaks accessibility, don't work with some alternative or old browsers. Considering that, tiki ajax development guidelines aim to:
- keep it simple to preserve tiki funcionality and layout with and without ajax
- avoid forking code
1 - Template-based common layout
The look & feel of a page must always be the same with or without ajax, and defined by template. Changing the template should change both modes at once as long as html element ids are preserved.
2 - Load content statically first time
If you are delivering empty containers with smarty and then have a document.onLoad() to load data, then you're likely to be breaking directive #1. Load content as if there was no ajax, and then when user request more content you update html element's properties.
Tutorial - make a region dynamic
1- Identify template component
find in your template the block of code that you want to be dynamic.
cut that code, paste in a new template ($includeFile in this example) and include inside an html element:
<div id="elementId">
missing page for plugin INCLUDE
</div>
missing page for plugin INCLUDE
</div>
2- Change your tpl to use {ajax_href} block in links
Now, edit your template and change links like this:
<a href="tiki-feature.php?param=value..">
to
<a {ajax_href template=$includeFile
htmlelement=$elementId}tiki-feature.php?...{/ajax_href}>
htmlelement=$elementId}tiki-feature.php?...{/ajax_href}>
where $includeFile is the template to be loaded, and $elementId is the id of element in which template will be loaded.
tip: use doc/devtools/make_ajax_template.pl to apply a regular expression to the template. edit the file and set correct parameters, then make a backup and call
./doc/devtools/make_ajax_template.pl templates/tiki-something.tpl
./doc/devtools/make_ajax_template.pl templates/tiki-something.tpl
3- Modify php file to process requests
in beginning of php file, after tiki-setup.php, put:
require_once("lib/ajax/ajaxlib.php");
and at end, before $smarty->display() or any output, register the templates you want to be loaded dynamically and process requests:
$ajaxlib->registerTemplate($template);
$ajaxlib->processRequests();
$ajaxlib->processRequests();
that's all!
<a rel="dofollow" href="http://www.all-auto.ro/piese-auto" title="piese auto ieftine"><img src="http://www.all-auto.ro/images/piese auto" alt="piese auto ieftine" hspace="2" vspace="2" border="0" /></a>
Features benefiting from ajax
- tiki-admin_quicktags.php
- tiki-listpages.php
- Modules
- Messages
- Calendar
- wiki
- save draft feature
Todo
- remove lib/cpaint and ajax/ after community approval
- reimplement tiki-admin_quicktags.php and tiki-listpages.php without splitting files
- configure a frequence for each module to be dynamically updated
Contributors to this page: masini
,
point01
,
Torpedro
,
marclaporte
,
luci
and
lfagundes
.
Page last modified on Monday 22 February, 2010 12:54:24 UTC by masini
.
Sidebar
Sidebar
To register
To have an account at this site, please register at Tikiwiki.org
, and then use that user name and password to log in here.

Last Comments