PhiBase class

From PhiWiki
Revision as of 14:48, 6 March 2014 by Schumi (talk | contribs) (Properties)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

The global PhiBase class offers convenience global functions for AJAX, sessions and URLs for Javascript.pngJavaScript. This class is instantiated as phi and is usable in any browser independent of running a Phi native client or HTML.

Properties
Object ajax
String lang
String session
Number xAxis
Number yAxis
Number zAxis
Functions
.alert() This function has been removed in v2.0.0 and is not longer supported.
.createAjax() Creates a cross browser compatible AJAX object
.fadeIn() This function has been removed in v2.0.0 and is not longer supported.
.fadeOut() This function has been removed in v2.0.0 and is not longer supported.
.getElementById() gets the item object
.href() opens an URL with appended Phi variables
.isHtml() returns true if running in HTML mode
.isNative() returns true if running in native Phi mode
.move() This function has been removed in v2.0.0 and is not longer supported.
.onload() handler if the document is ready
.onsubmit() handler if the document wants to submit a form
.rotateIn() This function has been removed in v2.0.0 and is not longer supported.
.rotateOut() This function has been removed in v2.0.0 and is not longer supported.
.setData() This function has been removed in v2.0.0 and is not longer supported.
.setOpacity() This function has been removed in v2.0.0 and is not longer supported.
.setVisible() This function has been removed in v2.0.0 and is not longer supported.

Usage

The special object phi is a global instance of the PhiBase class in the client (browser) scripting environment.

 if ( phi.isNative() ) {
  // running a phi client
 } else {
  // running in HTML mode
 }

Attention: the phi object is not available in Serverscript.pngServerScript.

Properties

  • Object ajax [read]
  • String lang [read]
  • String session [read]
  • Number xAxis [read]
  • Number yAxis [read]
  • Number zAxis [read]

Object ajax

Contains the default AJAX object useable for asynchronous HTML requests.

var a=phi.ajax;

See also: Ajax class.

String lang

Returns the currently set language which will be used for links in the current page or the default language if none is set.

var lang=phi.lang;

See also: $PHISERVER[lang].

String session

Returns the current session id phisid or an empty string if none is set.

var sid=phi.session;

See also: document.session, Session management.

Number xAxis

Returns the x-axis number (0x1).

Number yAxis

Returns the y-axis number (0x2).

Number zAxis

Returns the z-axis number (0x4).

Functions

.alert()


Synopsis

.alert(s)
Returns (read): Void
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Opens a message box.
Attribute Type Default Note
s String displays message 's'

Overview

Description

Opens a message box with string as text and an Ok button. Since v1.3.0 you can simply use alert().

Read: this is a write-only function.

Write: displays message s.

Note: This function has been removed in v2.0.0 and is not longer supported.

See also: window.alert().

Example

phi.alert( string );

.createAjax()


Synopsis

.createAjax()
Returns (read): Object
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.3.0
Brief description: Creates an AJAX object.
Attribute Type Default Note

Overview

Description

Read: creates a cross browser compatible AJAX object.

Write: this is a read-only function.

Note:

See also: Ajax class.

Example

var ajax=phi.createAjax();

.fadeIn()


Synopsis

.fadeIn(id,s,d,opac)
Returns (read): Void
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Fades an item in.
Attribute Type Default Note
id String item id
s Number start after s msec
d Number lasts d msec
opac Float fades to opacity opac

Overview

Description

Read: this is a write-only function.

Write: Fades the item with id in and starts fading after s msec with duration d msec until the opacity opac is reached.

Note: This function has been removed in v2.0.0 and is not longer supported. Use .fadeIn() instead.

See also: .fadeIn().

Example

phi.fadeIn( 'myitem', 0, 1000, 1 );

.fadeOut()


Synopsis

.fadeOut(id,s,d,opac)
Returns (read): Void
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Fades an item out.
Attribute Type Default Note
id String item id
s Number start after s msec
d Number lasts d msec
opac Float fades to opacity opac

Overview

Description

Read: this is a write-only function.

Write: Fades the item with id out and starts fading after s msec with duration d msec until the opacity opac is reached.

Note: This function has been removed in v2.0.0 and is not longer supported. Use .fadeOut() instead.

See also: .fadeOut().

Example

phi.fadeOut( 'myitem', 10000, 3000, 0.1 );

.getElementById()


Synopsis

.getElementById(id)
Returns (read): Object
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Gets the DOM object.
Attribute Type Default Note
id String get object for id

Overview

Description

Read: returns the DOM object for the provided id or undefined if no such item with id is found.

Write: this is a read-only function.

Note: same as document.getElementById(). Usually you only will use the item API to manipulate items.

See also: Phi item API, Phi DOM item, document.getElementById().

Example

 var item=phi.getElmentById( 'id' );
 if ( item ) item.style.color='#ffaacc';

.href()


Synopsis

.href(url)
Returns (read): Void
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Opens url.
Attribute Type Default Note
url String opens url

Overview

Description

Opens an external link. If you want to use a link without session and language set, use window.location.href.

Read: this is a write-only function.

Write: opens a new document in the same directory with url or an external page. Additional GET variables for language philang and session phisid are automatically appended.

Note: if you use HTML code in a rich text element and you want the link extended with the appropriate Phi variables, use:

<a href="javascript: phi.href( 'link' );">link text</a>

Attention: keep in mind phi.href() is a function and not a property like window.location.href.

See also: window.location.href.

Example

phi.href( '/tutorial/myfirst.phis' );

.isHtml()


Synopsis

.isHtml()
Returns (read): Boolean
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Check if running in HTML mode.
Attribute Type Default Note

Overview

Description

Read: returns true if the browser is running in HTML mode, else false is returned.

Write: this is a read-only function.

Note: used to distinguish if additional features are available, i.e. if this function returns true it is safe to use jQuery.

See also: .isNative().

Example

if ( phi.isHtml() ) doSomethingWhichIsOnlySupportedByHtml();

.isNative()


Synopsis

.isNative()
Returns (read): Boolean
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Check if running in Phi mode.
Attribute Type Default Note

Overview

Description

Read: returns true if the browser is running natively in Phi mode (e.g. using PhiApp), else false is returned.

Write: this is a read-only function.

Note: used to distinguish if additional features are available, i.e. if this function returns true it is safe to use extensions offered by Phi like native menus.

See also: .isHtml().

Example

if ( phi.isNative() ) doSomethingPhiSpecific();

.move()


Synopsis

.move(id,x,y,start,duartion)
Returns (read): Void
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.1.0
Brief description: Moves an item.
Attribute Type Default Note
id String item id
x Number x-coordinate
y Number ly-coordinate
start Number starts after start msec
duration Number lasts duration msec

Overview

Description

Read: this is a write-only function.

Write: animated move of an item to a new position in a specific time.

Note: This function has been removed in v2.0.0 and is not longer supported. Use .moveTo() instead.

See also: .moveTo().

Example

phi.move( 'myid', 100, 200, 0, 3000 ); // moves myid immediately to the pos left:100 top:200  in 3sec

.onload()


Synopsis

.onload()
Returns (read): Void
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Execute code on complete load.
Attribute Type Default Note

Overview

Description

Reimplement this function if you want to setup settings after the page is fully loaded and all elements are ready.

Read: this is a handler and should return Void.

Write: n/a

Note: The default implementation does nothing.

See also: .onsubmit().

Example

phi.onload=function() {
    // stuff to do after the page is completely loaded
}

.onsubmit()


Synopsis

.onsubmit()
Returns (read): Boolean
Environment: ServerScriptNa.png JavaScriptOk.png
Available since: v1.0.0
Brief description: Submit form handler.
Attribute Type Default Note

Overview

Description

Reimplement this function if you want to check settings before sending form data to the server. You must return true if the data should be sent or false otherwise.

Read: this is a handler and must return true if the form should be sent or false if the submission should be rejected.

Write: n/a

Note: The default implementation does nothing and returns true.

See also: Submit button, window.document.phiform.submit().

Example

phi.onsubmit=function() {
    // check formular elements
    return true;
}

Void rotateIn()

This function is deprecated. Do not use it in new code. The function is provided to keep old code working. Use .rotateIn() instead.

Rotates the element in.

phi.rotateIn( id, axis, start, duration );
phi.rotateIn( 'item_id', phi.xAxis+phi.yAxis, 0, 1000 ); // rotates item with ID item_id immediately through the x-axis and y-axis in 1sec in

Note: In HTML mode a rotation of an element is currently not possible, so phi.fadeIn() is used instead.

Void rotateOut()

This function is deprecated. Do not use it in new code. The function is provided to keep old code working. Use .rotateOut() instead.

Rotates the element out.

phi.rotateOut( id, axis, start, duration );
phi.rotateOut( 'item_id', phi.xAxis, 3000, 2000 ); // rotates item with ID item_id after 3sec through the x-Axis in 2sec out

Note: In HTML mode a rotation of an element is currently not possible, so phi.fadeOut() is used instead.

Void setData()

v1.2.0 This function is deprecated. Do not use it in new code. The function is provided to keep old code working. Use .selectOptions() instead.

Sets the data of a List box item or Selection box item.

phi.setData( id, data, delimiter='\n' );
phi.setData( 'select', 'row 1[1]:row 2[2]:row 3[3]', ':' );

Void setOpacity()

This function is deprecated. Do not use it in new code. The function is provided to keep old code working. Use .opacity() instead.

Sets the opacity of item id to opac. The range for opac is between '0' (fully transparent) and '1' (opaque). You can even set the opacity of input items.

phi.setOpacity( 'id', 0.5 ) // sets the opacity to 50%

Note: You should avoid using item.style.opacity directly - not all browser support this or using it differently.

Void setVisible()

This function is deprecated. Do not use it in new code. The function is provided to keep old code working. Use .visible() instead.

Sets the visiblity of item id to true or false.

phi.setVisible( 'id', false ); // hides the item

See also: item.style.visibility.

Additional notes

We will provide additional usefull functions in future releases.