Documentation
Review of binding options
AjaxCore support the following binding methods divided in two categories. Whatever the method you choose you may output Javascript code, or return HTML.
Attached bindingsThis type of bindings are attached to the page. As are processed by the browser on page load time.
bind: is the easiest way to bind an HTML object to a PHP function, the Ajax request will be made when the JavaScript event is triggered.
Live example: http://www.ajaxcore.org/helpdocs/bind.php
Parameter list
id: is the HTML element ID
event: is the event that will cause the Ajax Request, supports all JavaScript standards events.
bindto: is the name of the PHP function what will be called.
params: optional - ID of the HTML elements that needs to be send within the request, static values (not html elements ) should be sent as _XXX=YYY , whether XXX represents variable name, and YYY value
bindTimer: bind an Html object to a PHP function, the Ajax request will be made when appropriate JavaScript event occurs and timer expires. If subsequent events are produced, the timer restarts and no Ajax request is made until the timer expires.
Live example: http://www.ajaxcore.org/helpdocs/bindTimer.php
Parameter list
id: is the HTML element ID
event: is the event that will cause the Ajax Request, supports all JavaScript standards events.
bindto: is the name of the PHP function what will be called.
timername: is the name of the timer, multiple binds may share the same timer.
tiemerms: is the milliseconds the timer must waits until it expires.
params: optional - ID of the HTML elements that needs to be send within the request, static values (not html elements ) should be sent as _XXX=YYY , whether XXX represents variable name, and YYY value
bindPeriodicalTimer: bind an Html object to a PHP function, the Ajax request will be made when appropriate JavaScript event occurs and will keep repeating when timer expires. If subsequent events are produced, the timer restarts and no Ajax request is made until the timer expires.
Live example: http://www.ajaxcore.org/helpdocs/bindPe ... lTimer.php
Parameter list
id: is the HTML element ID
event: is the event that will cause the Ajax Request, supports all JavaScript standards events.
bindto: is the name of the PHP function what will be called.
timername: is the name of the timer, multiple binds may share the same timer.
tiemerms: is the milliseconds the timer must waits until it expires.
params: optional - ID of the HTML elements that needs to be send within the request, static values (not html elements ) should be sent as _XXX=YYY , whether XXX represents variable name, and YYY value
onLoad: Does a request to a PHP function, request will be made when onLoad JavaScript event occurs.
Live example: http://www.ajaxcore.org/helpdocs/onLoadBind.php
http://www.ajaxcore.org/helpdocs/onLoadBindTimer.php
http://www.ajaxcore.org/helpdocs/onLoad ... lTimer.php
Parameter list
bindto: is the name of the PHP function what will be called.
params: optional - ID of the HTML elements that needs to be send within the request, static values (not html elements ) should be sent as _XXX=YYY , whether XXX represents variable name, and YYY value
request: optional - support all previous bindings options, bind, bindTimer, bindPeriodicalTimer. Default bind
timerms: optional timer expiration time in milliseconds (only for timer requests). Default 300 ms
Inline bindings.
This type of bindings are not attached to the page and no event is required as the code generated is placed on <element onclick="javscript: INLINEBINDING"> wherever onclick could be any JavaScript event given. This bindings are processed by the browser in a different way as the attached ones. Its provides maximum of flexibility to the developer as new content may be placed into the page, with Ajax bindings attached to them.
bindInline: Does the bind between an Html object and PHP function
Live example: http://www.ajaxcore.org/helpdocs/bindInline.php
Parameter list
bindto: is the name of the PHP function what will be called.
params: optional - ID of the HTML elements that needs to be send within the request, static values (not html elements ) should be sent as _XXX=YYY , whether XXX represents variable name, and YYY value
id: optional - is the Javascript reference ID for specific behavior defined in setJSCode.
bindTimerInline: Does the bind between an Html object and PHP function, request will be made when JavaScript event occurs and timer expires.
Live example: http://www.ajaxcore.org/helpdocs/bindTimerInline.php
Parameter list
bindto: is the name of the PHP function what will be called.
timername: is the name of the timer, multiple binds may share the same timer.
tiemerms: is the milliseconds the timer must waits until it expires.
params: optional - ID of the HTML elements that needs to be send within the request, static values (not html elements ) should be sent as _XXX=YYY , whether XXX represents variable name, and YYY value
id: optional - is the Javascript reference ID for specific behavior defined in setJSCode.
bindPeriodicalTimerInline: Does the bind between an Html object and PHP function, request will be made when JavaScript event occurs and will keep repeating when timer expires.
Live example: http://www.ajaxcore.org/helpdocs/bindPe ... Inline.php
Parameter list
bindto: is the name of the PHP function what will be called.
timername: is the name of the timer, multiple binds may share the same timer.
tiemerms: is the milliseconds the timer must waits until it expires.
params: optional - ID of the HTML elements that needs to be send within the request, static values (not html elements ) should be sent as _XXX=YYY , whether XXX represents variable name, and YYY value
id: optional - is the Javascript reference ID for specific behavior defined in setJSCode.
Javascript::AjaxCoreBreadcrumb
AjaxCoreBreadcrumb
Function that allows to keep a track of the AJAX request on the URL, formally named Breadcrumb.
- Code: Select all
AjaxCoreBreadcrumb.prototype.start = function()
{
var url=location.href;
var url=url.replace(new RegExp(/%20/g),' ')
var urlTrails=url.split('#');
if(urlTrails.length>1)
{
urlTrails[1]=decode64(urlTrails[1]);
this.trails=urlTrails[1].toString().split(',');
var requests=Array();
for(var i=0;i<this.trails.length;i++)
{
var trail=String(this.trails[i]).substring(0,this.trails[i].length).split("%");
requests[i]=trail;
}
requestsSerialized=new AjaxCoreSerialized(requests);
requestsSerialized.request();
}
}
AjaxCoreBreadcrumb.prototype.addMultipleTrail = function(url,method,pars,jsbefore,response,jsafter)
{
// Support for multiple levels of trails, working but not tested
this.trails[this.trails.length]=url+"%"+method+"%"+pars+"%"+jsbefore+"%"+response+"%"+jsafter;
}
AjaxCoreBreadcrumb.prototype.addSingleTrail = function(url,method,pars,jsbefore,response,jsafter)
{
this.trails[0]=url+"%"+method+"%"+pars+"%"+jsbefore+"%"+response+"%"+jsafter;
}
AjaxCoreBreadcrumb.prototype.updateURL = function()
{
var url=location.href;
var notrail=url.split("#");
var local_address;
var request="";
if(notrail.length>0)
{
local_address=notrail[0];
}
else
{
local_address=notrail;
}
local_address+="#";
for(var i=0;i<this.trails.length;i++)
{
if(i>0)
{
request+=",";
}
request+=this.trails[i];
}
local_address+=encode64(request);
local_address+="";
location.href=local_address;
address=local_address;
}
Javascript::AjaxCoreTimer
AjaxCoreTimer
Function that allows the creation of timers
- Code: Select all
function AjaxCoreTimer(handle, ms)
{
this.handle = handle;
this.ms = ms;
this.timer = 0;
}
AjaxCoreTimer.prototype.start = function()
{
if (this.timer > 0)
{
this.reset();
}
this.timer = window.setTimeout(this.handle, this.ms);
}
AjaxCoreTimer.prototype.reset = function()
{
if (this.timer > 0)
{
window.clearTimeout(this.timer);
}
this.timer = 0;
}
function AjaxCoreBreadcrumb()
{
this.trails= new Array();
}
Javascript::AjaxCoreWatcher
AjaxCoreWatcher
function that keep a track of the URL, in case of mismatch forces a reload, useful for back button
- Code: Select all
function AjaxCoreWatcher()
{
if(address!=location.href)
{
window.location.reload();
}
watcher.start();
}
Javascript::function encode64/decode64
Encode decode functions that allows to hide the vars in the breadcrumb, useful for bookmarking and back button
- Code: Select all
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var address = location.href;
var requestsSerialized;
function encode64(input)
{
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
keyStr.charAt(enc3) + keyStr.charAt(enc4);
} while (i < input.length);
return output;
}
function decode64(input)
{
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
} while (i < input.length);
return output;
}
Javascript::function AjaxCoreSerialized
Javascript::AjaxCoreSerialized
Function that allows to keep a track of AJAX calls and then retrieve them later ( after a bookmark or back button ) without user intervention- Code: Select all
function AjaxCoreSerialized(requests)
{
this.request_index=0;
this.requests=requests;
}
AjaxCoreSerialized.prototype.request = function ()
{
if(this.request_index<this.requests.length)
{
var data=this.requests[this.request_index];
eval(data[3]); // js before
var Request = new Ajax.Request(
data[0],
{
method: data[1],
parameters: data[2],
onComplete: this.callBack
});
}
}
AjaxCoreSerialized.prototype.callBack = function (originalRequest)
{
var data=requestsSerialized.requests[requestsSerialized.request_index];
eval(data[4])(originalRequest); // callback
eval(data[5]); // js after
requestsSerialized.request_index++;
requestsSerialized.request();
}
Javascript::function AjaxCore
Javascript::AjaxCore
function that creates the AJAX call using prototype standard method.
- Code: Select all
function AjaxCore(url,method,pars,response)
{
var Request = new Ajax.Request(
url,
{
method: method,
parameters: pars,
onComplete: response
});
}
protected function AjaxCore
AjaxCore
Class constructor.@access protected
php5
- Code: Select all
protected function AjaxCore ( )
{
$this->lookForAction();
}
php4
- Code: Select all
function AjaxCore ( )
{
$this->lookForAction();
}
public function addTrail
addTrail
Adds a trail to the url for bookmarking and backbutton@access public
php5
- Code: Select all
public function addTrail($id)
{
$this->trails[$id]=true;
}
php4
- Code: Select all
function addTrail($id)
{
$this->trails[$id]=true;
}
public function alert
alert
Return JavaScript Alert Message@access public
@param string $message message to alert
@return string JavaScript alert, if die is not set, otherwise outputs die(alert)
php5
- Code: Select all
public function alert ($message, $die = true)
{
$message=$this->escapeJS($message);
$alert ="alert('$message');";
if ($die)
{
die($alert);
}
else
{
return $alert;
}
}
php4
- Code: Select all
function alert ($message, $die = true)
{
$message=$this->escapeJS($message);
$alert ="alert('$message');";
if ($die)
{
die($alert);
}
else
{
return $alert;
}
}