From 6cfd535f19a784c1116f033649b95a9202efd8ef Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 3 Apr 2012 16:39:20 -0400 Subject: [PATCH] Replace sse event labels --- .../src/kis-js_src_modules_ajax.js.html | 27 +++++++----- kis-all.js | 11 ++++- kis-lite-dom-min.js | 2 +- kis-lite-dom.js | 11 ++++- kis-lite-min.js | 2 +- kis-lite.js | 11 ++++- kis-min.js | 44 +++++++++---------- src/modules/ajax.js | 11 ++++- 8 files changed, 77 insertions(+), 42 deletions(-) diff --git a/docs/symbols/src/kis-js_src_modules_ajax.js.html b/docs/symbols/src/kis-js_src_modules_ajax.js.html index c1fe8b5..61ebb7b 100755 --- a/docs/symbols/src/kis-js_src_modules_ajax.js.html +++ b/docs/symbols/src/kis-js_src_modules_ajax.js.html @@ -136,13 +136,20 @@ 129 source = new EventSource(url); 130 131 // Apply the callback -132 source.onmessage = callback; -133 } -134 else // Ajax polling fallback -135 { -136 poll_rate = poll_rate || 30000; -137 setInterval($_.get, poll_rate, url, {}, callback); -138 } -139 }); -140 -141 }()); \ No newline at end of file +132 source.onmessage = function(event){ +133 callback(event.data); +134 }; +135 } +136 else // Ajax polling fallback +137 { +138 poll_rate = poll_rate || 30000; +139 +140 setInterval($_.get, poll_rate, url, {}, function(res){ +141 res.replace(/data:/gim, ''); +142 res.replace(/^event|id|retry?:(.*)$/gim, ''); +143 callback(res); +144 }); +145 } +146 }); +147 +148 }()); \ No newline at end of file diff --git a/kis-all.js b/kis-all.js index 4b1d2e4..1bd7893 100755 --- a/kis-all.js +++ b/kis-all.js @@ -940,12 +940,19 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" source = new EventSource(url); // Apply the callback - source.onmessage = callback; + source.onmessage = function(event){ + callback(event.data); + }; } else // Ajax polling fallback { poll_rate = poll_rate || 30000; - setInterval($_.get, poll_rate, url, {}, callback); + + setInterval($_.get, poll_rate, url, {}, function(res){ + res.replace(/data:/gim, ''); + res.replace(/^event|id|retry?:(.*)$/gim, ''); + callback(res); + }); } }); diff --git a/kis-lite-dom-min.js b/kis-lite-dom-min.js index 9bc3552..6241baa 100755 --- a/kis-lite-dom-min.js +++ b/kis-lite-dom-min.js @@ -3,7 +3,7 @@ return 1===b.length?b[0]:b};f=function(a){var c;if("undefined"!==typeof a){if("u (typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};g=window.$_=window.$_||g;g.$=e}})(); (function(){"undefined"===typeof window.console&&(window.console={log:function(){}});"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event&&(Event.prototype.preventDefault=function(){window.event.returnValue=false},Event.prototype.stopPropagation=function(){window.event.cancelBubble=true})})(); (function(){if("undefined"!==typeof window.XMLHttpRequest){var g={_do:function(e,f,b,a){var c=new XMLHttpRequest;"undefined"===typeof b&&(b=function(){});a=a?"POST":"GET";e+="GET"===a?"?"+this._serialize(f):"";c.open(a,e);c.onreadystatechange=function(){4===c.readyState&&b(c.responseText)};"POST"===a?(c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.send(this._serialize(f))):c.send(null)},_serialize:function(e){var f,b,a=[];for(f in e)e.hasOwnProperty(f)&&"function"!==typeof e[f]&& -(b=e[f].toString(),f=encodeURIComponent(f),b=encodeURIComponent(b),a.push(f+"="+b));return a.join("&")}};$_.ext("get",function(e,f,b){g._do(e,f,b,!1)});$_.ext("post",function(e,f,b){g._do(e,f,b,!0)});$_.ext("sse",function(e,f,b){"undefined"!==typeof EventSource?(e=new EventSource(e),e.onmessage=f):setInterval($_.get,b||3E4,e,{},f)})}})(); +(b=e[f].toString(),f=encodeURIComponent(f),b=encodeURIComponent(b),a.push(f+"="+b));return a.join("&")}};$_.ext("get",function(e,f,b){g._do(e,f,b,!1)});$_.ext("post",function(e,f,b){g._do(e,f,b,!0)});$_.ext("sse",function(e,f,b){"undefined"!==typeof EventSource?(e=new EventSource(e),e.onmessage=function(a){f(a.data)}):setInterval($_.get,b||3E4,e,{},function(a){a.replace(/data:/gim,"");a.replace(/^event|id|retry?:(.*)$/gim,"");f(a)})})}})(); (function(){var g,e,f,b;"undefined"!==typeof document.addEventListener?(g=function(a,c,b){"undefined"!==typeof a.addEventListener&&a.addEventListener(c,b,!1)},e=function(a,c,b){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(c,b,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(a,c,b){function h(a){b.apply(a)}"undefined"!==typeof a.attachEvent?(e(c,b),a.attachEvent("on"+c,h),a=a.KIS_0_6_0=a.KIS_0_6_0||{},a.listeners=a.listeners||{},a.listeners[c]=a.listeners[c]||[],a.listeners[c].push({callback:b, _listener:h})):console.log("Failed to _attach event:"+c+" on "+a)},e=function(a,b,d){if("undefined"!==typeof a.detachEvent){var h=a.KIS_0_6_0;if(h&&h.listeners&&h.listeners[b])for(var e=h.listeners[b],f=e.length,i=0;id?1:ca?1:bd?1:ca?1:b