Location: PHPKode > projects > So Easy PHP > SoEasy/EasyHtml/HtmlMaker/JavaScript/functions/JavaScriptCatchEvent.class.php
<?php
include_once "HtmlMaker/JavaScript/JavaScriptConcrete.class.php";

/**
 * JavaScriptAlert
 * alert.class.php
 * @author	Ricardo <hide@address.com>
 * @since	22/10/2006
 * @package EasyHtml
 * @subpackage JavaScript
 */
class JavaScriptCatchEvent extends JavaScriptConcrete {

	/**
	 * Construtor
	 * @param string frase para o alert
	 */
	function JavaScriptCatchEvent() {
		
		$addEvent = null;
		$addEvent .= "function addEvent(obj, evType, fn)\n";
		$addEvent .= "{\n";
		$addEvent .= "	if (obj.addEventListener)\n";
		$addEvent .= "	{\n";
		$addEvent .= "		obj.addEventListener(evType, fn, false);\n";
		$addEvent .= "	    return true;\n";
		$addEvent .= "	}\n";
		$addEvent .= "	else if (obj.attachEvent)\n";
		$addEvent .= "	{\n";
		$addEvent .= "		var r = obj.attachEvent(\"on\" + evType, fn);\n";
		$addEvent .= "	    return r;\n";
		$addEvent .= "	}\n";
		$addEvent .= "	else\n";
		$addEvent .= "	{\n";
		$addEvent .= "		alert(\"handler could not be attached\");\n";
		$addEvent .= "	}\n";
		$addEvent .= "}\n";
		
		$catchEvent = null;
		$catchEvent .= "function catchEvent(evt)\n";
		$catchEvent .= "{\n";
		$catchEvent .= "    target = evt.target || evt.srcElement;\n";
		$catchEvent .= "    targtype = target.type;\n";
		$catchEvent .= "    eventUsesFn;\n";
		$catchEvent .= "	if ( eventUsesFn == undefined )\n";
		$catchEvent .= "	{\n";
		$catchEvent .= "		alert(\"Defina uma função para tratar o evento \\n [var eventUsesFn(target, targtype, event) ]\");\n";
		$catchEvent .= "	}\n";
		$catchEvent .= "	else\n";
		$catchEvent .= "	{\n";
		$catchEvent .= "		eventUsesFn(target, targtype, evt);\n";
		$catchEvent .= "	}\n";
		$catchEvent .= "}\n";
		
		$defineEvent = null;
		$defineEvent .= "function defineEvent(evFirefox, evIe)\n";
		$defineEvent .= "{\n";
		$defineEvent .= "	if ( evFirefox == undefined )\n";
		$defineEvent .= "	{\n";
		$defineEvent .= "		evFirefox = \"keypress\";\n";
		$defineEvent .= "	}\n";
		$defineEvent .= "	else if (evIe == undefined)\n";
		$defineEvent .= "	{\n";
		$defineEvent .= "		evIe = evFirefox;\n";
		$defineEvent .= "	}\n";
		$defineEvent .= "	if ( evIe == undefined)\n";
		$defineEvent .= "	{\n";
		$defineEvent .= "		evIe = \"keydown\";\n";
		$defineEvent .= "	}\n";
		$defineEvent .= "    var ev = (document.addEventListener) ? evFirefox : evIe;\n";
		$defineEvent .= "    addEvent(document, ev, catchEvent);\n";
		$defineEvent .= "}\n";
		
		$this->addExecutable($addEvent);
		$this->addExecutable($catchEvent);
		$this->addExecutable($defineEvent);
	}
}// JavaScriptAlert
?>
Return current item: So Easy PHP