DOM Events - examples

XMS extends DOMDocument with it's own interface, XmsDomElement to provide Dom Events.

Example that shows how it works on the Dom Elements
$content = file_get_contents("sourceCode.xml");

$doc = new Xml($content);

$doc("//tr") -> each(function() {
	$this -> on("someEvent", function($evt) {
		//this is the object instance of XmsDomElement
		//$evt is the event instance of XmsDomEvent
		//do something

	});
	$this -> on("before", "someEvent", function($evt) {
		//$evt and $this instance of XmsDomEvent
		//do something

	});

	$this -> on("after", "someEvent", function($evt) {
		//$evt and $this instance of XmsDomEvent
//do something }); }); $doc -> q("//tr") -> each(function() { $this -> trigger("someEvent"); //OR $this -> trigger("someEvent", array( "USER", "DATA" )); //OR $this -> trigger("someEvent", array( "USER", "DATA" ), XMS_DOM_EVENT::BUBBLE_CANCEL); //OR $this -> trigger("someEvent", array( "USER", "DATA" ), XMS_DOM_EVENT::BUBBLE_CHILDS); });

Above example only directly in Xml instance chain
$content = file_get_contents("sourceCode.xml");

$doc = new Xml($content);

$doc("//tr") -> elements("on", array(
	"someEvent",
	function($evt) {
		//this is the object instance of XmsDomElement
//$evt is the event instance of XmsDomEvent
//do something } )) -> elements("on", array( "before", "someEvent", function($evt) { //$evt and $this instance of XmsDomEvent
//do something } )) -> elements("on", array( "after", "someEvent", function($evt) { //$evt and $this instance of XmsDomEvent
//do something } )) -> elements("on", array( "after", "someEvent", function($evt) { //$evt and $this instance of XmsDomEvent
//do something else } )); $doc -> q("//tr") -> elements("trigger", array("someEvent")) -> elements("trigger", array( "someEvent", array( "USER", "DATA" ) )) -> elements("trigger", array( "someEvent", array( "USER", "DATA" ), XMS_DOM_EVENT::BUBBLE_CANCEL )) -> elements("trigger", array( "someEvent", array( "USER", "DATA" ), XMS_DOM_EVENT::BUBBLE_CHILDS ));

Showing 5 from 0 out of

No comments
Showing 5 from 0 out of