Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 2.47 KB

Js.md

File metadata and controls

53 lines (40 loc) · 2.47 KB

Js Factory

The Js factory provides a collection of event objects which allow the introduction of client scripting with JavaScript. These objects are not to be confused with the Js helper available in CakePHP, for this check out the Cake factory.

To use the Js factory in a View include it in the $factories property of the CTK class, for example:

public $factories = array('Ctk.Js');

Once the factory is available you can access the event objects it provides. To bind an event object from the factory simply call the factory, and then the desired event object, for example:

$button->bind('click', $this->Js->Alert(array(
	'text' => __('Click me!')
)));

As shown in the example, an array can be passed to the object with parameters to configure the object's template.

Some event objects expose subsequent APIs, allowing additional configuration, for example:

$button->bind('click', $this->Js->Element(array('node' => $div))->toggle()); // Element wraps the node, then toggle() appends the client code

The event objects available in the Js factory are the following:

  • Ajax - Object interface to the XmlRpcRequest object.
  • Alert - Object representing alert dialogs.
  • Callback - Object for wrapping client code as a callback.
  • Code - Object for wrapping raw client code.
  • Confirm - Object representing confirm dialogs.
  • Cookie - Object interface to browser cookies.
  • Document - Object interface to the document object.
  • Element - Object interface to DOM elements.
  • Event - Base object for all JavaScript events.
  • History - Object interface to the history object.
  • Json - Object representing JSON data.
  • Listener - Object representing an event listener.
  • Location - Object interface to the location object.
  • Navigator - Object interface to the navigator object.
  • Prompt - Object representing prompt dialogs.
  • Redirect - Object representing alert dialogs.
  • Window - Object interface to the window object.

The Js factory provides a layout specific for JavaScript, which can be set from the $layout property of the CTK class, for example:

public $layout = 'Ctk.Js/default';