Script reference

From PhiWiki
Jump to: navigation, search

Overview

Here you can find the JavaScript reference used for server and client side scripting. Phi provides additionial functions for manipulating items easily. Phi uses a full featured ECMA-262 script engine on server side.

Since v1.3.0 Phi offers a new item API (application programming interface) for Javascript.pngJavaScript based on jQuery through a wrapper which is also usable in Phi native mode. The same item API for Serverscript.pngServerScript is available since v1.5.0.

Since v1.5.0 Phi introduces a module programming API in C++/Qt which can create JavaScript objects for Serverscript.pngServerScript. This allows module programmer to provide objects e.g. for LDAP, Websphere MQ or whatever your business needs are (and it is much easier to handle than Apache modules).

ServerScript

The following built-in classes can be used in the Serverscript.pngServerScript of the Phis server and Apache module which are then processed by the Phi engine:

  • Document class (global object document) - the well known document object.
  • Item API ($('id')) v1.5.0 - item wrapper API (versions prior v2.0.0 need a loadModule('wrapper'); directive).
  • Item class (var item=document.getElementById('myid');) - DOM item (obsolete: use the item API instead).
  • Style class (item.style) - Phi supports a subset of the style object (obsolete: use the item API instead).
  • Effect class (item.effect) - Phi effects extension (obsolete: use the item API instead).

Server modules offer a powerful control mechanism to store e.g. the values of a form in a database or file, perform network requests and/or gives a better control of database and file handling. Currently distributed plug-ins for Serverscript.pngServerScript are:

  • System class (global object system) - system related functions.
  • Reply class (global object reply) - create your own content.
  • Request class (global object request) - access form variables from a POST request or parse the GET variable string.
  • Server class (global object server) - server related functions.
  • File class (global object file) - local file manipulation.
  • Sql class (global object sql) - database access functions.
  • Email class (global object email) - SMTP client (deceptive name - but has historical reasons).

All global objects need to be referenced with lower case:

document.title='my title';
// Be aware of the missing 'Window' class - it does not exist in ServerScript
// Wrong: window.document.title='my title';

// SQL example:
var cid=12;
loadModule('sql');
sql.prepare( 'SELECT lastname, firstname FROM address WHERE id=?' );
sql.bind( 0, cid );
sql.exec();
if ( sql.next ) { server.log( sql.value( 0 )+', '+sql.value( 1 ) ); }

JavaScript

Javascript.pngJavaScript classes provided in the client (browser) environment (all documented functions and properties should also be accessible in Phi native mode):

Built-in classes

Standard classes available in Serverscript.pngServerScript and Javascript.pngJavaScript:

Notes

Phi tries to be standard conform as much as possible. However it extends some classes to add special functionality like transformations, native applications and menus, etc. You can check if a client runs in native mode (see PhiApp) or HTML with:

if ( phi.isNative() ) {
  // Phi extended code (i.e. using native application menus)
} else {
  // Standard browser code (i.e. jQuery is safely usable)
}
  // or you may want to use
if ( phi.isHtml() ) {
  // Standard browser code
}

Please do not use JavaScript functions and properties which are not listed in this documentation. They will probably not work in native Phi mode. We try to be as much as possible JavaScript compliant. If you think you found an inconsistency please let us know and write to mailto:bugs@phisketeer.org.