6705e48f by Chris Boden

Added new wp function, Singleton class, fireEvent (maybe?)

1 parent bc190ca2
<?php
Interface iSingleton {
public static function make();
}
abstract class Singleton implements iSingleton {
public function __construct() {
$ref = new ReflectionClass($this);
throw new Exception($ref->getName() . ' is a singleton and can not be instantiated');
}
}
?>
function fireEvent(element,event){
if (document.createEventObject){
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !element.dispatchEvent(evt);
}
}
......@@ -21,15 +21,28 @@ class TzTools {
_register_script('addEvent', plugins_url('addEvent.js', __FILE__));
_register_script('xmlhttpHandler', plugins_url('xmlhttpHandler.js', __FILE__));
_register_script('fireEvent', plugins_url('fireEvent.js', __FILE__));
add_action('widgets_init', Array('MenuWidget', 'init'));
}
public static function autoloader($class) {
$file = dirname(__FILE__) . '/' . $class . '.php';
$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $class . '.php';
if (is_file($file)) {
require($file);
include($file);
}
}
}
function add_actions($class) {
if (!class_exists($class)) {
throw new Exception("$class does not exist");
}
$ref = new ReflectionClass($class);
$actions = $ref->getMethods(ReflectionMethod::IS_STATIC);
foreach ($actions as $action) {
add_action($action->name, Array($class, $action->name));
}
}
?>
......
......@@ -13,6 +13,11 @@ function _register_script() {
return call_user_func_array('wp_register_script', $params);
}
function _deregister_script() {
$params = func_get_args();
return call_user_func_array('wp_deregister_script', $params);
}
function _localize_script() {
$params = func_get_args();
return call_user_func_array('wp_localize_script', $params);
......