Permalink
Browse files

added util.js that will later become usefull.

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_AJAX/trunk@197114 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent a6638a6 commit 55eeaa5c705cb154bf7a21ea70d91c306e24b697 David Coallier committed Sep 28, 2005
Showing with 35 additions and 0 deletions.
  1. +35 −0 js/util.js
View
@@ -0,0 +1,35 @@
+/**
+ * Utility methods
+ *
+ * @category HTML
+ * @package Ajax
+ * @author David Coallier <davidc@php.net>
+ * @copyright 2005 David Coallier
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ */
+// {{{ HTML_AJAX_Util
+/**
+ * All the utilities we will be using thorough the classes
+ */
+var HTML_AJAX_Util = {
+ // Set the element event
+ setElementEvent: function(id, event, handler) {
+ var element = document.getElementById(id);
+ if (typeof element.addEventListener != "undefined") { //Dom2
+ element.addEventListener(event, handler, false);
+ } else if (typeof element.attachEvent != "undefined") { //IE 5+
+ element.attachEvent("on" + event, handler);
+ } else {
+ if (element["on" + event] != null) {
+ var oldHandler = element["on" + event];
+ element["on" + event] = function(e) {
+ oldHander(e);
+ handler(e);
+ };
+ } else {
+ element["on" + event] = handler;
+ }
+ }
+ }
+}
+// }}}

0 comments on commit 55eeaa5

Please sign in to comment.