Related: No Javascript, jQuery
These notes are currently being updated (July 2010).
Features benefiting from AJAX
- Toolbars (formerly known as Quicktags)
- Menus administration
- Modules administration
- Inter-User Messages
- Calendar
- wiki
- Editing pages
- tiki-listpages.php
- save draft feature
- auto save
- File Gallery
- Trackers
- Webmail / GroupMail
Wishlist
[-]Using AJAX in Tiki
[+]
THIS SECTION IS MOSTLY OR COMPLETELY OUTDATED.
The AJAX infrastructure is mostly implemented in tiki-jquery.js ( $.fn.loadService, $.fn.tikiModal and functions ajaxLoadingShow() and ajaxLoadingHide()). The backend part is in tiki-ajax_services.php and the Service_Broker class. db/config/controllers.xml maps AJAX controller names to the classes implementing them.
Old notes - needs updating
Getting started
To use ajax in tiki:
In php file, after including tiki-setup.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"):
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.on
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"> {include file=$includeFile} </div>
2- Change your tpl to use {ajax_href} block in links
Now, edit your template and change links like this:
to
where $includeFile is the template to be loaded, and $elementId is the id of element in which template will be loaded.
./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:
and at end, before $smarty->display() or any output, register the templates you want to be loaded dynamically and process requests:
that's all!
Todo
-
remove lib/cpaint and ajax/ after community approval
- reimplement
tiki-admin_quicktags.phpand tiki-listpages.php without splitting files
- configure a frequence for each module to be dynamically updated
- Rewrite this page's Using AJAX section