Browse Source

implemented custom event polyfill for ie

Vladimir Bykov 11 years ago
parent
commit
e7fdeeecfd

+ 1 - 1
apps/web/priv/static/app/js/okey/okey_protocol.js

@@ -6,7 +6,7 @@ function OkeyApiProviderScope(scope) {
         options = options || {};
         this.url = options.url;
         this.gameId = options.gameId;
-        this.proxies = [ "init", "handleMessage", "actionTake" ], 
+        this.proxies = [ "init", "handleMessage", "actionTake" ];
         this.proxyAll();
         this.socket = new WebSocket(this.url);
         ws = this.socket;

+ 15 - 1
apps/web/priv/static/app/js/selector.js

@@ -10,6 +10,8 @@ var scope = {
 
 var $ = function(_undefind)
 {
+    var isIE = window.navigator.msPointerEnabled
+
     function Selector(elements) {
         this.length = elements.length;
         for (var i = 0, l = this.length; l > i; i++) this[i] = elements[i];
@@ -33,7 +35,19 @@ var $ = function(_undefind)
     fn.each = function(callback) { for (var i = 0, l = this.length; l > i; i++) callback(this[i], i); return this; },
     fn.on = function(eventName, eventHandler) { return this.each(function(el) { el.addEventListener(eventName, eventHandler); }); },
     fn.off = function(eventName, eventHandler) { return this.each(function(el) { el.removeEventListener(eventName, eventHandler); }); },
-    fn.trigger = function(eventName, data, raw) { return this.each(function(el) { event = new CustomEvent(eventName, data), el.dispatchEvent(event); }); },
+    fn.trigger = function(eventName, data, raw) { 
+        return this.each(function(el) {
+            if(isIE){
+                var event = document.createEvent("CustomEvent");
+                event.initCustomEvent(eventName, false, false, data);
+                el.dispatchEvent(event)
+            }
+            else {
+                var event = new CustomEvent(eventName, data) 
+                el.dispatchEvent(event)
+            }
+        }); 
+    },
     fn.show = function() { return this.css("display", "block"); },
     fn.hide = function() { return this.css("display", "none"); },
     fn.text = function(text) { return null != text ? this.each(function(el) { el.textContent = text; }) : this.length ? this[0].textContent : _undefind; },