6705e48f by Chris Boden

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

1 parent bc190ca2
1 <?php
2 Interface iSingleton {
3 public static function make();
4 }
5
6 abstract class Singleton implements iSingleton {
7 public function __construct() {
8 $ref = new ReflectionClass($this);
9 throw new Exception($ref->getName() . ' is a singleton and can not be instantiated');
10 }
11 }
12 ?>
1 function fireEvent(element,event){
2 if (document.createEventObject){
3 // dispatch for IE
4 var evt = document.createEventObject();
5 return element.fireEvent('on'+event,evt)
6 }
7 else{
8 // dispatch for firefox + others
9 var evt = document.createEvent("HTMLEvents");
10 evt.initEvent(event, true, true ); // event type,bubbling,cancelable
11 return !element.dispatchEvent(evt);
12 }
13 }
...@@ -21,15 +21,28 @@ class TzTools { ...@@ -21,15 +21,28 @@ class TzTools {
21 21
22 _register_script('addEvent', plugins_url('addEvent.js', __FILE__)); 22 _register_script('addEvent', plugins_url('addEvent.js', __FILE__));
23 _register_script('xmlhttpHandler', plugins_url('xmlhttpHandler.js', __FILE__)); 23 _register_script('xmlhttpHandler', plugins_url('xmlhttpHandler.js', __FILE__));
24 _register_script('fireEvent', plugins_url('fireEvent.js', __FILE__));
24 25
25 add_action('widgets_init', Array('MenuWidget', 'init')); 26 add_action('widgets_init', Array('MenuWidget', 'init'));
26 } 27 }
27 28
28 public static function autoloader($class) { 29 public static function autoloader($class) {
29 $file = dirname(__FILE__) . '/' . $class . '.php'; 30 $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $class . '.php';
30 if (is_file($file)) { 31 if (is_file($file)) {
31 require($file); 32 include($file);
32 } 33 }
33 } 34 }
34 } 35 }
36
37 function add_actions($class) {
38 if (!class_exists($class)) {
39 throw new Exception("$class does not exist");
40 }
41
42 $ref = new ReflectionClass($class);
43 $actions = $ref->getMethods(ReflectionMethod::IS_STATIC);
44 foreach ($actions as $action) {
45 add_action($action->name, Array($class, $action->name));
46 }
47 }
35 ?> 48 ?>
......
...@@ -13,6 +13,11 @@ function _register_script() { ...@@ -13,6 +13,11 @@ function _register_script() {
13 return call_user_func_array('wp_register_script', $params); 13 return call_user_func_array('wp_register_script', $params);
14 } 14 }
15 15
16 function _deregister_script() {
17 $params = func_get_args();
18 return call_user_func_array('wp_deregister_script', $params);
19 }
20
16 function _localize_script() { 21 function _localize_script() {
17 $params = func_get_args(); 22 $params = func_get_args();
18 return call_user_func_array('wp_localize_script', $params); 23 return call_user_func_array('wp_localize_script', $params);
......