Streamlined sse method

This commit is contained in:
Timothy Warren 2012-04-12 13:12:11 -04:00
parent da02feb2d2
commit 3ed6b229f6
16 changed files with 78 additions and 138 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -116,40 +116,28 @@
<span class='line'>109</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">
<span class='line'>111</span> </span><span class="COMM">/**
<span class='line'>112</span> * Watches for server-sent events, or falls back to ajax polling
<span class='line'>113</span> * - defaults to 30 second intervals
<span class='line'>114</span> *
<span class='line'>115</span> * @name sse
<span class='line'>116</span> * @function
<span class='line'>117</span> * @memberOf $_
<span class='line'>118</span> * @param string url
<span class='line'>119</span> * @param function callback
<span class='line'>120</span> * @param [int] 30000
<span class='line'>121</span> */</span><span class="WHIT">
<span class='line'>122</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'sse'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">poll_rate</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">
<span class='line'>124</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">source</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT">
<span class='line'>126</span> </span><span class="COMM">//Check for server-sent event support</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">EventSource</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'undefined'</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>129</span> </span><span class="WHIT"> </span><span class="NAME">source</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">EventSource</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">
<span class='line'>131</span> </span><span class="COMM">// Apply the callback</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT"> </span><span class="NAME">source.onmessage</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">(</span><span class="NAME">event.data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>134</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="COMM">// Ajax polling fallback</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT"> </span><span class="NAME">poll_rate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">poll_rate</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">30000</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">
<span class='line'>140</span> </span><span class="NAME">setInterval</span><span class="PUNC">(</span><span class="NAME">$_.get</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">poll_rate</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">res</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT"> </span><span class="NAME">res.trim</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="REGX">/data:/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT"> </span><span class="NAME">res.replace</span><span class="PUNC">(</span><span class="REGX">/^(event|id|retry)?\:(.*)$/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT"> </span><span class="NAME">callback.call</span><span class="PUNC">(</span><span class="NAME">res</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">res</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">
<span class='line'>148</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>
<span class='line'>112</span> * Watches for server-sent events and applies a callback on message
<span class='line'>113</span> *
<span class='line'>114</span> * @name sse
<span class='line'>115</span> * @function
<span class='line'>116</span> * @memberOf $_
<span class='line'>117</span> * @param string url
<span class='line'>118</span> * @param function callback
<span class='line'>119</span> */</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'sse'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">poll_rate</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">
<span class='line'>122</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">source</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">
<span class='line'>124</span> </span><span class="COMM">// Check for server-sent event support</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">EventSource</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'undefined'</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT"> </span><span class="NAME">source</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">EventSource</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">
<span class='line'>129</span> </span><span class="COMM">// Apply the callback</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT"> </span><span class="NAME">source.onmessage</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT"> </span><span class="NAME">callback.call</span><span class="PUNC">(</span><span class="NAME">event.data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event.data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>132</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT">
<span class='line'>136</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>

View File

@ -939,40 +939,28 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
});
/**
* Watches for server-sent events, or falls back to ajax polling
* - defaults to 30 second intervals
* Watches for server-sent events and applies a callback on message
*
* @name sse
* @function
* @memberOf $_
* @param string url
* @param function callback
* @param [int] 30000
*/
$_.ext('sse', function(url, callback, poll_rate){
var source;
//Check for server-sent event support
// Check for server-sent event support
if (typeof EventSource !== 'undefined')
{
source = new EventSource(url);
// Apply the callback
source.onmessage = function(event){
callback(event.data);
callback.call(event.data, event.data);
};
}
else // Ajax polling fallback
{
poll_rate = poll_rate || 30000;
setInterval($_.get, poll_rate, url, {}, function(res){
res.trim().replace(/data:/gim, '');
res.replace(/^(event|id|retry)?\:(.*)$/gim, '');
callback.call(res, res);
});
}
});

32
kis-lite-dom-min.js vendored
View File

@ -1,17 +1,17 @@
(function(){if("undefined"!==typeof document.querySelector){var c,g,e,b;c=function(a){b="undefined"===typeof a?"undefined"!==typeof c.el?c.el:document.documentElement:"object"!==typeof a?g(a):a;c.prototype.el=b;var a=e(c),d;for(d in a)"object"===typeof a[d]&&(a[d].el=b);a.el=b;return a};g=function(a,d){var b;if("string"!=typeof a||"undefined"===typeof a)return a;b=null!=d&&1===d.nodeType?d:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a);
return 1===b.length?b[0]:b};e=function(a){var d;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);d=typeof a;if(!("object"!==d&&"function"!==d))return d=function(){},d.prototype=a,new d}};c.ext=function(a,d){d.el=b;c[a]=d};c.ext("each",function(a){if("undefined"!==typeof b.length&&b!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(b,a);else{var d=b.length;if(0!==d)for(var h,f=0;f<d;f++)h=b.item(f)?b.item(f):b[f],a.call(h,h)}else a.call(b,
b)});c.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};c=window.$_=window.$_||c;c.$=g}})();"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,"")});
(function(){if("undefined"!==typeof document.querySelector){var c,f,e,a;c=function(b){a="undefined"===typeof b?"undefined"!==typeof c.el?c.el:document.documentElement:"object"!==typeof b?f(b):b;c.prototype.el=a;var b=e(c),d;for(d in b)"object"===typeof b[d]&&(b[d].el=a);b.el=a;return b};f=function(b,d){var a;if("string"!=typeof b||"undefined"===typeof b)return b;a=null!=d&&1===d.nodeType?d:document;if(b.match(/^#([\w\-]+$)/))return document.getElementById(b.split("#")[1]);a=a.querySelectorAll(b);
return 1===a.length?a[0]:a};e=function(b){var d;if("undefined"!==typeof b){if("undefined"!==typeof Object.create)return Object.create(b);d=typeof b;if(!("object"!==d&&"function"!==d))return d=function(){},d.prototype=b,new d}};c.ext=function(b,d){d.el=a;c[b]=d};c.ext("each",function(b){if("undefined"!==typeof a.length&&a!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(a,b);else{var d=a.length;if(0!==d)for(var h,g=0;g<d;g++)h=a.item(g)?a.item(g):a[g],b.call(h,h)}else b.call(a,
a)});c.type=function(b){return function(){return b&&b!==this}.call(b)?(typeof b).toLowerCase():{}.toString.call(b).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};c=window.$_=window.$_||c;c.$=f}})();"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});"undefined"===typeof Array.isArray&&(Array.isArray=function(c){return Object.prototype.toString.apply(c)==="[object Array]"});
(function(){if(typeof window.XMLHttpRequest!=="undefined"){var c={_do:function(g,c,b,a){var d=new XMLHttpRequest;typeof b==="undefined"&&(b=function(){});a=a?"POST":"GET";g=g+(a==="GET"?"?"+this._serialize(c):"");d.open(a,g);d.onreadystatechange=function(){d.readyState===4&&b(d.responseText)};if(a==="POST"){d.setRequestHeader("Content-Type","application/x-www-form-urlencoded");d.send(this._serialize(c))}else d.send(null)},_serialize:function(c){var e,b,a=[];for(e in c)if(c.hasOwnProperty(e)&&typeof c[e]!==
"function"){b=c[e].toString();e=encodeURIComponent(e);b=encodeURIComponent(b);a.push(e+"="+b)}return a.join("&")}};$_.ext("get",function(g,e,b){c._do(g,e,b,false)});$_.ext("post",function(g,e,b){c._do(g,e,b,true)});$_.ext("sse",function(c,e,b){if(typeof EventSource!=="undefined"){c=new EventSource(c);c.onmessage=function(a){e(a.data)}}else setInterval($_.get,b||3E4,c,{},function(a){a.trim().replace(/data:/gim,"");a.replace(/^(event|id|retry)?\:(.*)$/gim,"");e.call(a,a)})})}})();
(function(){var c,g,e,b;if(typeof document.addEventListener!=="undefined"){c=function(a,d,b){typeof a.addEventListener!=="undefined"&&a.addEventListener(d,b,false)};g=function(a,d,b){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(d,b,false)}}else if(typeof document.attachEvent!=="undefined"){c=function(a,b,h){function c(a){h.apply(a)}if(typeof a.attachEvent!=="undefined"){g(b,h);a.attachEvent("on"+b,c);a=a.KIS_0_6_0=a.KIS_0_6_0||{};a.listeners=a.listeners||{};a.listeners[b]=a.listeners[b]||
[];a.listeners[b].push({callback:h,_listener:c})}else console.log("Failed to _attach event:"+b+" on "+a)};g=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var f=a.KIS_0_6_0;if(f&&f.listeners&&f.listeners[b])for(var e=f.listeners[b],g=e.length,i=0;i<g;i++)if(e[i].callback===c){a.detachEvent("on"+b,e[i]._listener);e.splice(i,1);e.length===0&&delete f.listeners[b];break}}}}e=function(a,b,h,f){var j,k;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))f===
true?c(a,b,h):g(a,b,h);else{b=b.split(" ");k=b.length;for(j=0;j<k;j++)e(a,b[j],h,f)}};b=function(a,b,c,f){e(a,c,function(c){var h,i,e,c=c||window.event;i=$_.$(b,a);for(h in i){e=c.target||c.srcElement;if(e==i[h]){f.call(i[h],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(c){e(c,a,b,true)})},remove:function(a,b){$_.each(function(c){e(c,a,b,false)})},live:function(a,d,c){b(document.documentElement,a,d,c)},delegate:function(a,d,c){$_.each(function(e){b(e,a,d,c)})}})})();
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(c){var c=(c.HTMLElement||c.Element).prototype,g=Object,e=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},b=Array.prototype.indexOf||function(a){for(var b=0,d=this.length;b<d;b++)if(b in this&&this[b]===a)return b;return-1},a=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},d=function(d,c){if(c==="")throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(c))throw new a("INVALID_CHARACTER_ERR",
"String contains an invalid character");return b.call(d,c)},h=function(a){for(var b=e.call(a.className),b=b?b.split(/\s+/):[],d=0,c=b.length;d<c;d++)this.push(b[d]);this._updateClassName=function(){a.className=this.toString()}},f=h.prototype=[],j=function(){return new h(this)};a.prototype=Error.prototype;f.item=function(a){return this[a]||null};f.contains=function(a){return d(this,a+"")!==-1};f.add=function(a){a=a+"";if(d(this,a)===-1){this.push(a);this._updateClassName()}};f.remove=function(a){a=
d(this,a+"");if(a!==-1){this.splice(a,1);this._updateClassName()}};f.toggle=function(a){a=a+"";d(this,a)===-1?this.add(a):this.remove(a)};f.toString=function(){return this.join(" ")};if(g.defineProperty){f={get:j,enumerable:true,configurable:true};try{g.defineProperty(c,"classList",f)}catch(k){if(k.number===-2146823252){f.enumerable=false;g.defineProperty(c,"classList",f)}}}else g.prototype.__defineGetter__&&c.__defineGetter__("classList",j)}(self);
(function(){function c(b,a,d){var c,e;if(typeof b.hasAttribute!=="undefined"){b.hasAttribute(a)&&(c=b.getAttribute(a));e=true}else if(typeof b[a]!=="undefined"){c=b[a];e=false}else if(a==="class"&&typeof b.className!=="undefined"){a="className";c=b.className;e=false}if(typeof c==="undefined"&&(typeof d==="undefined"||d===null)){console.log(d);console.log(b);console.log("Element does not have the selected attribute");return null}if(typeof d==="undefined")return c;typeof d!=="undefined"&&d!==null?e===
true?b.setAttribute(a,d):b[a]=d:d===null&&(e===true?b.removeAttribute(a):delete b[a]);return typeof d!=="undefined"?d:c}function g(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function e(b,a,c){var e,a=g(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof c==="undefined"&&b.style[a]!=="undefined")return b.style[a];if(typeof c==="undefined"&&b.style[e[a]]!=="undefined")return b.style[e[a]];if(typeof b.style[a]!=="undefined"){b.style[a]=
c;return null}if(b.style[e[a]]){b.style[e[a]]=c;return null}console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(b){$_.each(function(a){a.classList.add(b)})},removeClass:function(b){$_.each(function(a){a.classList.remove(b)})},hide:function(){this.css("display","none")},show:function(b){typeof b==="undefined"&&(b="block");this.css("display",b)},attr:function(b,a){var d=this.el;if(d.length>1&&typeof a==="undefined"){console.log(d);console.log("Must be a singular element")}else if(d.length>
1&&typeof a!=="undefined")$_.each(function(d){return c(d,b,a)});else return c(d,b,a)},text:function(b){var a,c,e;e=this.el;c=typeof e.textContent!=="undefined"?"textContent":typeof e.innerText!=="undefined"?"innerText":"innerHTML";a=e[c];if(typeof b!=="undefined")return e[c]=b;return a},css:function(b,a){if(typeof a==="undefined")return e(this.el,b);$_.each(function(c){e(c,b,a)})},append:function(b){typeof document.insertAdjacentHTML!=="undefined"?this.el.insertAdjacentHTML("beforeend",b):this.el.innerHTML=
this.el.innerHTML+b},prepend:function(b){typeof document.insertAdjacentHTML!=="undefined"?this.el.insertAdjacentHTML("afterbegin",b):this.el.innerHTML=b+this.el.innerHTML},html:function(b){if(typeof b!=="undefined")this.el.innerHTML=b;return this.el.innerHTML}})})();
(function(){if(typeof window.XMLHttpRequest!=="undefined"){var c={_do:function(c,e,a,b){var d=new XMLHttpRequest;typeof a==="undefined"&&(a=function(){});b=b?"POST":"GET";c=c+(b==="GET"?"?"+this._serialize(e):"");d.open(b,c);d.onreadystatechange=function(){d.readyState===4&&a(d.responseText)};if(b==="POST"){d.setRequestHeader("Content-Type","application/x-www-form-urlencoded");d.send(this._serialize(e))}else d.send(null)},_serialize:function(c){var e,a,b=[];for(e in c)if(c.hasOwnProperty(e)&&typeof c[e]!==
"function"){a=c[e].toString();e=encodeURIComponent(e);a=encodeURIComponent(a);b.push(e+"="+a)}return b.join("&")}};$_.ext("get",function(f,e,a){c._do(f,e,a,false)});$_.ext("post",function(f,e,a){c._do(f,e,a,true)});$_.ext("sse",function(c,e){var a;if(typeof EventSource!=="undefined"){a=new EventSource(c);a.onmessage=function(b){e.call(b.data,b.data)}}})}})();
(function(){var c,f,e,a;if(typeof document.addEventListener!=="undefined"){c=function(b,d,a){typeof b.addEventListener!=="undefined"&&b.addEventListener(d,a,false)};f=function(b,d,a){typeof b.removeEventListener!=="undefined"&&b.removeEventListener(d,a,false)}}else if(typeof document.attachEvent!=="undefined"){c=function(b,a,h){function c(b){h.apply(b)}if(typeof b.attachEvent!=="undefined"){f(a,h);b.attachEvent("on"+a,c);b=b.KIS_0_6_0=b.KIS_0_6_0||{};b.listeners=b.listeners||{};b.listeners[a]=b.listeners[a]||
[];b.listeners[a].push({callback:h,_listener:c})}else console.log("Failed to _attach event:"+a+" on "+b)};f=function(b,a,h){if(typeof b.detachEvent!=="undefined"){var c=b.KIS_0_6_0;if(c&&c.listeners&&c.listeners[a])for(var e=c.listeners[a],f=e.length,i=0;i<f;i++)if(e[i].callback===h){b.detachEvent("on"+a,e[i]._listener);e.splice(i,1);e.length===0&&delete c.listeners[a];break}}}}e=function(b,a,h,g){var j,k;if(typeof b==="undefined"){console.log(arguments);console.log(a);return false}if(a.match(/^([\w\-]+)$/))g===
true?c(b,a,h):f(b,a,h);else{a=a.split(" ");k=a.length;for(j=0;j<k;j++)e(b,a[j],h,g)}};a=function(b,a,c,g){e(b,c,function(c){var h,i,e,c=c||window.event;i=$_.$(a,b);for(h in i){e=c.target||c.srcElement;if(e==i[h]){g.call(i[h],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(b,a){$_.each(function(c){e(c,b,a,true)})},remove:function(b,a){$_.each(function(c){e(c,b,a,false)})},live:function(b,d,c){a(document.documentElement,b,d,c)},delegate:function(b,d,c){$_.each(function(e){a(e,b,d,c)})}})})();
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(c){var c=(c.HTMLElement||c.Element).prototype,f=Object,e=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},a=Array.prototype.indexOf||function(b){for(var a=0,d=this.length;a<d;a++)if(a in this&&this[a]===b)return a;return-1},b=function(b,a){this.name=b;this.code=DOMException[b];this.message=a},d=function(d,c){if(c==="")throw new b("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(c))throw new b("INVALID_CHARACTER_ERR",
"String contains an invalid character");return a.call(d,c)},h=function(b){for(var a=e.call(b.className),a=a?a.split(/\s+/):[],d=0,c=a.length;d<c;d++)this.push(a[d]);this._updateClassName=function(){b.className=this.toString()}},g=h.prototype=[],j=function(){return new h(this)};b.prototype=Error.prototype;g.item=function(a){return this[a]||null};g.contains=function(a){return d(this,a+"")!==-1};g.add=function(a){a=a+"";if(d(this,a)===-1){this.push(a);this._updateClassName()}};g.remove=function(a){a=
d(this,a+"");if(a!==-1){this.splice(a,1);this._updateClassName()}};g.toggle=function(a){a=a+"";d(this,a)===-1?this.add(a):this.remove(a)};g.toString=function(){return this.join(" ")};if(f.defineProperty){g={get:j,enumerable:true,configurable:true};try{f.defineProperty(c,"classList",g)}catch(k){if(k.number===-2146823252){g.enumerable=false;f.defineProperty(c,"classList",g)}}}else f.prototype.__defineGetter__&&c.__defineGetter__("classList",j)}(self);
(function(){function c(a,b,d){var c,e;if(typeof a.hasAttribute!=="undefined"){a.hasAttribute(b)&&(c=a.getAttribute(b));e=true}else if(typeof a[b]!=="undefined"){c=a[b];e=false}else if(b==="class"&&typeof a.className!=="undefined"){b="className";c=a.className;e=false}if(typeof c==="undefined"&&(typeof d==="undefined"||d===null)){console.log(d);console.log(a);console.log("Element does not have the selected attribute");return null}if(typeof d==="undefined")return c;typeof d!=="undefined"&&d!==null?e===
true?a.setAttribute(b,d):a[b]=d:d===null&&(e===true?a.removeAttribute(b):delete a[b]);return typeof d!=="undefined"?d:c}function f(a){return a.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function e(a,b,c){var e,b=f(b);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof c==="undefined"&&a.style[b]!=="undefined")return a.style[b];if(typeof c==="undefined"&&a.style[e[b]]!=="undefined")return a.style[e[b]];if(typeof a.style[b]!=="undefined"){a.style[b]=
c;return null}if(a.style[e[b]]){a.style[e[b]]=c;return null}console.log("Property "+b+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(a){$_.each(function(b){b.classList.add(a)})},removeClass:function(a){$_.each(function(b){b.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){typeof a==="undefined"&&(a="block");this.css("display",a)},attr:function(a,b){var d=this.el;if(d.length>1&&typeof b==="undefined"){console.log(d);console.log("Must be a singular element")}else if(d.length>
1&&typeof b!=="undefined")$_.each(function(d){return c(d,a,b)});else return c(d,a,b)},text:function(a){var b,c,e;e=this.el;c=typeof e.textContent!=="undefined"?"textContent":typeof e.innerText!=="undefined"?"innerText":"innerHTML";b=e[c];if(typeof a!=="undefined")return e[c]=a;return b},css:function(a,b){if(typeof b==="undefined")return e(this.el,a);$_.each(function(c){e(c,a,b)})},append:function(a){typeof document.insertAdjacentHTML!=="undefined"?this.el.insertAdjacentHTML("beforeend",a):this.el.innerHTML=
this.el.innerHTML+a},prepend:function(a){typeof document.insertAdjacentHTML!=="undefined"?this.el.insertAdjacentHTML("afterbegin",a):this.el.innerHTML=a+this.el.innerHTML},html:function(a){if(typeof a!=="undefined")this.el.innerHTML=a;return this.el.innerHTML}})})();

View File

@ -392,40 +392,28 @@ if (typeof Array.isArray === "undefined")
});
/**
* Watches for server-sent events, or falls back to ajax polling
* - defaults to 30 second intervals
* Watches for server-sent events and applies a callback on message
*
* @name sse
* @function
* @memberOf $_
* @param string url
* @param function callback
* @param [int] 30000
*/
$_.ext('sse', function(url, callback, poll_rate){
var source;
//Check for server-sent event support
// Check for server-sent event support
if (typeof EventSource !== 'undefined')
{
source = new EventSource(url);
// Apply the callback
source.onmessage = function(event){
callback(event.data);
callback.call(event.data, event.data);
};
}
else // Ajax polling fallback
{
poll_rate = poll_rate || 30000;
setInterval($_.get, poll_rate, url, {}, function(res){
res.trim().replace(/data:/gim, '');
res.replace(/^(event|id|retry)?\:(.*)$/gim, '');
callback.call(res, res);
});
}
});
}());

16
kis-lite-min.js vendored
View File

@ -1,9 +1,9 @@
(function(){if("undefined"!==typeof document.querySelector){var f,d,e,c;f=function(a){c="undefined"===typeof a?"undefined"!==typeof f.el?f.el:document.documentElement:"object"!==typeof a?d(a):a;f.prototype.el=c;var a=e(f),b;for(b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};d=function(a,b){var g;if("string"!=typeof a||"undefined"===typeof a)return a;g=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);g=g.querySelectorAll(a);
return 1===g.length?g[0]:g};e=function(a){var b;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);b=typeof a;if(!("object"!==b&&"function"!==b))return b=function(){},b.prototype=a,new b}};f.ext=function(a,b){b.el=c;f[a]=b};f.ext("each",function(a){if("undefined"!==typeof c.length&&c!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(c,a);else{var b=c.length;if(0!==b)for(var g,d=0;d<b;d++)g=c.item(d)?c.item(d):c[d],a.call(g,g)}else a.call(c,
c)});f.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};f=window.$_=window.$_||f;f.$=d}})();"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,"")});
(function(){if("undefined"!==typeof document.querySelector){var f,e,d,b;f=function(a){b="undefined"===typeof a?"undefined"!==typeof f.el?f.el:document.documentElement:"object"!==typeof a?e(a):a;f.prototype.el=b;var a=d(f),c;for(c in a)"object"===typeof a[c]&&(a[c].el=b);a.el=b;return a};e=function(a,c){var b;if("string"!=typeof a||"undefined"===typeof a)return a;b=null!=c&&1===c.nodeType?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a);
return 1===b.length?b[0]:b};d=function(a){var c;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);c=typeof a;if(!("object"!==c&&"function"!==c))return c=function(){},c.prototype=a,new c}};f.ext=function(a,c){c.el=b;f[a]=c};f.ext("each",function(a){if("undefined"!==typeof b.length&&b!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(b,a);else{var c=b.length;if(0!==c)for(var g,d=0;d<c;d++)g=b.item(d)?b.item(d):b[d],a.call(g,g)}else a.call(b,
b)});f.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};f=window.$_=window.$_||f;f.$=e}})();"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});"undefined"===typeof Array.isArray&&(Array.isArray=function(f){return Object.prototype.toString.apply(f)==="[object Array]"});
(function(){if(typeof window.XMLHttpRequest!=="undefined"){var f={_do:function(d,e,c,a){var b=new XMLHttpRequest;typeof c==="undefined"&&(c=function(){});a=a?"POST":"GET";d=d+(a==="GET"?"?"+this._serialize(e):"");b.open(a,d);b.onreadystatechange=function(){b.readyState===4&&c(b.responseText)};if(a==="POST"){b.setRequestHeader("Content-Type","application/x-www-form-urlencoded");b.send(this._serialize(e))}else b.send(null)},_serialize:function(d){var e,c,a=[];for(e in d)if(d.hasOwnProperty(e)&&typeof d[e]!==
"function"){c=d[e].toString();e=encodeURIComponent(e);c=encodeURIComponent(c);a.push(e+"="+c)}return a.join("&")}};$_.ext("get",function(d,e,c){f._do(d,e,c,false)});$_.ext("post",function(d,e,c){f._do(d,e,c,true)});$_.ext("sse",function(d,e,c){if(typeof EventSource!=="undefined"){d=new EventSource(d);d.onmessage=function(a){e(a.data)}}else setInterval($_.get,c||3E4,d,{},function(a){a.trim().replace(/data:/gim,"");a.replace(/^(event|id|retry)?\:(.*)$/gim,"");e.call(a,a)})})}})();
(function(){var f,d,e,c;if(typeof document.addEventListener!=="undefined"){f=function(a,b,g){typeof a.addEventListener!=="undefined"&&a.addEventListener(b,g,false)};d=function(a,b,g){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(b,g,false)}}else if(typeof document.attachEvent!=="undefined"){f=function(a,b,g){function c(a){g.apply(a)}if(typeof a.attachEvent!=="undefined"){d(b,g);a.attachEvent("on"+b,c);a=a.KIS_0_6_0=a.KIS_0_6_0||{};a.listeners=a.listeners||{};a.listeners[b]=a.listeners[b]||
[];a.listeners[b].push({callback:g,_listener:c})}else console.log("Failed to _attach event:"+b+" on "+a)};d=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var d=a.KIS_0_6_0;if(d&&d.listeners&&d.listeners[b])for(var e=d.listeners[b],f=e.length,h=0;h<f;h++)if(e[h].callback===c){a.detachEvent("on"+b,e[h]._listener);e.splice(h,1);e.length===0&&delete d.listeners[b];break}}}}e=function(a,b,c,j){var i,k;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))j===
true?f(a,b,c):d(a,b,c);else{b=b.split(" ");k=b.length;for(i=0;i<k;i++)e(a,b[i],c,j)}};c=function(a,b,c,d){e(a,c,function(c){var e,g,f,c=c||window.event;g=$_.$(b,a);for(e in g){f=c.target||c.srcElement;if(f==g[e]){d.call(g[e],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(c){e(c,a,b,true)})},remove:function(a,b){$_.each(function(c){e(c,a,b,false)})},live:function(a,b,d){c(document.documentElement,a,b,d)},delegate:function(a,b,d){$_.each(function(e){c(e,a,b,d)})}})})();
(function(){if(typeof window.XMLHttpRequest!=="undefined"){var f={_do:function(e,d,b,a){var c=new XMLHttpRequest;typeof b==="undefined"&&(b=function(){});a=a?"POST":"GET";e=e+(a==="GET"?"?"+this._serialize(d):"");c.open(a,e);c.onreadystatechange=function(){c.readyState===4&&b(c.responseText)};if(a==="POST"){c.setRequestHeader("Content-Type","application/x-www-form-urlencoded");c.send(this._serialize(d))}else c.send(null)},_serialize:function(e){var d,b,a=[];for(d in e)if(e.hasOwnProperty(d)&&typeof e[d]!==
"function"){b=e[d].toString();d=encodeURIComponent(d);b=encodeURIComponent(b);a.push(d+"="+b)}return a.join("&")}};$_.ext("get",function(e,d,b){f._do(e,d,b,false)});$_.ext("post",function(e,d,b){f._do(e,d,b,true)});$_.ext("sse",function(e,d){var b;if(typeof EventSource!=="undefined"){b=new EventSource(e);b.onmessage=function(a){d.call(a.data,a.data)}}})}})();
(function(){var f,e,d,b;if(typeof document.addEventListener!=="undefined"){f=function(a,c,b){typeof a.addEventListener!=="undefined"&&a.addEventListener(c,b,false)};e=function(a,c,b){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(c,b,false)}}else if(typeof document.attachEvent!=="undefined"){f=function(a,c,b){function d(a){b.apply(a)}if(typeof a.attachEvent!=="undefined"){e(c,b);a.attachEvent("on"+c,d);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:d})}else console.log("Failed to _attach event:"+c+" on "+a)};e=function(a,c,b){if(typeof a.detachEvent!=="undefined"){var d=a.KIS_0_6_0;if(d&&d.listeners&&d.listeners[c])for(var e=d.listeners[c],f=e.length,h=0;h<f;h++)if(e[h].callback===b){a.detachEvent("on"+c,e[h]._listener);e.splice(h,1);e.length===0&&delete d.listeners[c];break}}}}d=function(a,c,b,j){var i,k;if(typeof a==="undefined"){console.log(arguments);console.log(c);return false}if(c.match(/^([\w\-]+)$/))j===
true?f(a,c,b):e(a,c,b);else{c=c.split(" ");k=c.length;for(i=0;i<k;i++)d(a,c[i],b,j)}};b=function(a,c,b,e){d(a,b,function(b){var d,f,g,b=b||window.event;f=$_.$(c,a);for(d in f){g=b.target||b.srcElement;if(g==f[d]){e.call(f[d],b);b.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(e){d(e,a,b,true)})},remove:function(a,b){$_.each(function(e){d(e,a,b,false)})},live:function(a,c,d){b(document.documentElement,a,c,d)},delegate:function(a,c,d){$_.each(function(e){b(e,a,c,d)})}})})();

View File

@ -392,40 +392,28 @@ if (typeof Array.isArray === "undefined")
});
/**
* Watches for server-sent events, or falls back to ajax polling
* - defaults to 30 second intervals
* Watches for server-sent events and applies a callback on message
*
* @name sse
* @function
* @memberOf $_
* @param string url
* @param function callback
* @param [int] 30000
*/
$_.ext('sse', function(url, callback, poll_rate){
var source;
//Check for server-sent event support
// Check for server-sent event support
if (typeof EventSource !== 'undefined')
{
source = new EventSource(url);
// Apply the callback
source.onmessage = function(event){
callback(event.data);
callback.call(event.data, event.data);
};
}
else // Ajax polling fallback
{
poll_rate = poll_rate || 30000;
setInterval($_.get, poll_rate, url, {}, function(res){
res.trim().replace(/data:/gim, '');
res.replace(/^(event|id|retry)?\:(.*)$/gim, '');
callback.call(res, res);
});
}
});
}());

18
kis-min.js vendored
View File

@ -10,12 +10,12 @@ null};f.contains=function(a){return e(this,a+"")!==-1};f.add=function(a){a=a+"";
b.defineProperty(a,"classList",f)}}}else b.prototype.__defineGetter__&&a.__defineGetter__("classList",h)}(self);e.ext("dom",{addClass:function(a){e.each(function(b){b.classList.add(a)})},removeClass:function(a){e.each(function(b){b.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){typeof a==="undefined"&&(a="block");this.css("display",a)},attr:function(a,b){var c=this.el;if(c.length>1&&typeof b==="undefined"){console.log(c);console.log("Must be a singular element")}else if(c.length>
1&&typeof b!=="undefined")e.each(function(c){return k(c,a,b)});else return k(c,a,b)},text:function(a){var b,c,d;d=this.el;c=typeof d.textContent!=="undefined"?"textContent":typeof d.innerText!=="undefined"?"innerText":"innerHTML";b=d[c];if(typeof a!=="undefined")return d[c]=a;return b},css:function(a,b){if(typeof b==="undefined")return f(this.el,a);e.each(function(c){f(c,a,b)})},append:function(a){typeof document.insertAdjacentHTML!=="undefined"?this.el.insertAdjacentHTML("beforeend",a):this.el.innerHTML=
this.el.innerHTML+a},prepend:function(a){typeof document.insertAdjacentHTML!=="undefined"?this.el.insertAdjacentHTML("afterbegin",a):this.el.innerHTML=a+this.el.innerHTML},html:function(a){if(typeof a!=="undefined")this.el.innerHTML=a;return this.el.innerHTML}});if(typeof window.XMLHttpRequest!=="undefined"){var h={_do:function(a,b,c,d){var g=new XMLHttpRequest;typeof c==="undefined"&&(c=function(){});d=d?"POST":"GET";a=a+(d==="GET"?"?"+this._serialize(b):"");g.open(d,a);g.onreadystatechange=function(){g.readyState===
4&&c(g.responseText)};if(d==="POST"){g.setRequestHeader("Content-Type","application/x-www-form-urlencoded");g.send(this._serialize(b))}else g.send(null)},_serialize:function(a){var b,c,d=[];for(b in a)if(a.hasOwnProperty(b)&&typeof a[b]!=="function"){c=a[b].toString();b=encodeURIComponent(b);c=encodeURIComponent(c);d.push(b+"="+c)}return d.join("&")}};e.ext("get",function(a,b,c){h._do(a,b,c,false)});e.ext("post",function(a,b,c){h._do(a,b,c,true)});e.ext("sse",function(a,b,c){if(typeof EventSource!==
"undefined"){a=new EventSource(a);a.onmessage=function(a){b(a.data)}}else setInterval(e.get,c||3E4,a,{},function(a){a.trim().replace(/data:/gim,"");a.replace(/^(event|id|retry)?\:(.*)$/gim,"");b.call(a,a)})});var i,l,j,q;if(typeof document.addEventListener!=="undefined"){i=function(a,b,c){typeof a.addEventListener!=="undefined"&&a.addEventListener(b,c,false)};l=function(a,b,c){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(b,c,false)}}else if(typeof document.attachEvent!=="undefined"){i=
function(a,b,c){function d(a){c.apply(a)}if(typeof a.attachEvent!=="undefined"){l(b,c);a.attachEvent("on"+b,d);a=a.KIS_0_6_0=a.KIS_0_6_0||{};a.listeners=a.listeners||{};a.listeners[b]=a.listeners[b]||[];a.listeners[b].push({callback:c,_listener:d})}else console.log("Failed to _attach event:"+b+" on "+a)};l=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var d=a.KIS_0_6_0;if(d&&d.listeners&&d.listeners[b])for(var g=d.listeners[b],e=g.length,f=0;f<e;f++)if(g[f].callback===c){a.detachEvent("on"+
b,g[f]._listener);g.splice(f,1);g.length===0&&delete d.listeners[b];break}}}}j=function(a,b,c,d){var g,e;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))d===true?i(a,b,c):l(a,b,c);else{b=b.split(" ");e=b.length;for(g=0;g<e;g++)j(a,b[g],c,d)}};q=function(a,b,c,d){j(a,c,function(c){var f,n,h,c=c||window.event;n=e.$(b,a);for(f in n){h=c.target||c.srcElement;if(h==n[f]){d.call(n[f],c);c.stopPropagation()}}},true)};e.ext("event",{add:function(a,b){e.each(function(c){j(c,
a,b,true)})},remove:function(a,b){e.each(function(c){j(c,a,b,false)})},live:function(a,b,c){q(document.documentElement,a,b,c)},delegate:function(a,b,c){e.each(function(d){q(d,a,b,c)})}});if(typeof localStorage==="undefined"||typeof JSON==="undefined")return null;var m=localStorage,o=sessionStorage;e.ext("store",{get:function(a,b){var c=b?o.getItem(a):m.getItem(a);return JSON.parse(c)},set:function(a,b,c){b=JSON.stringify(b);c?o.setItem(a,b):m.setItem(a,b)},remove:function(a,b){b?o.removeItem(a):m.removeItem(a)},
getAll:function(a){var b,c={},d,g;g=a?m:o;b=g.length;for(a=0;a<b;a++){d=g.key(a);c[d]=g.getItem(d)}return c},clear:function(a){a?o.clear():m.clear()}});var s=function(a){var b=[],c=0,d={},g,b=r.object_keys(a);b.sort(function(a,b){var c=parseFloat(b),d=parseFloat(a),g=c+""===b,e=d+""===a;return g&&e?c>d?1:c<d?-1:0:g&&!e?1:!g&&e?-1:b>a?1:b<a?-1:0});c=b.length;for(g=0;g<c;g++)d[b[g]]=a[b[g]];return d},r={object_keys:function(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},object_values:function(a){var b=
[],c;for(c in a)b.push(a[c]);return b},array_combine:function(a,b){var c={},d,g=0;e.type(a)!=="array"&&(a=this.object_values(a));e.type(b)!=="array"&&(b=this.object_values(b));d=a.length;if(d!==b.length){console.log("Object combine requires two arrays of the same size");return false}for(g=0;g<d;g++)c[a[g]]=b[g];return c},object_merge:function(){var a=Array.prototype.slice.call(arguments),b=a.length,c={},d,g=0,f,h,i;d=true;for(f=0;f<b;f++)if(e.type(a[f])!=="array"){d=false;break}if(d){c=[];for(f=0;f<
b;f++)c=c.contact(a[f]);return c}for(i=f=0;f<b;f++){d=a[f];if(e.type(d)=="array"){h=0;for(g=d.length;h<g;h++)c[i++]=d[h]}else for(h in d)d.hasOwnProperty(h)&&(parseInt(h,10)+""===h?c[i++]=d[h]:c[h]=d[h])}return c},str_trans:function(a,b,c){var d=[],g=[],e=false,f=0,h=0,i="",j="",l="",k="",m;if(typeof b==="object"){b=s(b);for(m in b)if(b.hasOwnProperty(m)){d.push(m);g.push(b[m])}b=d;c=g}h=a.length;f=b.length;i=typeof c==="string";j=typeof b==="string";for(d=0;d<h;d++){e=false;if(j){a.charAt(d-1);l=
a.charAt(d);a.charAt(d+1);for(g=0;g<f;g++)if(l==b.charAt(g)){e=true;break}}else for(g=0;g<f;g++)if(a.substr(d,b[g].length)==b[g]){e=true;d=d+b[g].length-1;break}k=e?k+(i?c.charAt(g):c[g]):k+a.charAt(d)}return k}};e.ext("util",r)}})($_);
4&&c(g.responseText)};if(d==="POST"){g.setRequestHeader("Content-Type","application/x-www-form-urlencoded");g.send(this._serialize(b))}else g.send(null)},_serialize:function(a){var b,c,d=[];for(b in a)if(a.hasOwnProperty(b)&&typeof a[b]!=="function"){c=a[b].toString();b=encodeURIComponent(b);c=encodeURIComponent(c);d.push(b+"="+c)}return d.join("&")}};e.ext("get",function(a,b,c){h._do(a,b,c,false)});e.ext("post",function(a,b,c){h._do(a,b,c,true)});e.ext("sse",function(a,b){var c;if(typeof EventSource!==
"undefined"){c=new EventSource(a);c.onmessage=function(a){b.call(a.data,a.data)}}});var i,l,j,q;if(typeof document.addEventListener!=="undefined"){i=function(a,b,c){typeof a.addEventListener!=="undefined"&&a.addEventListener(b,c,false)};l=function(a,b,c){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(b,c,false)}}else if(typeof document.attachEvent!=="undefined"){i=function(a,b,c){function d(a){c.apply(a)}if(typeof a.attachEvent!=="undefined"){l(b,c);a.attachEvent("on"+b,d);a=a.KIS_0_6_0=
a.KIS_0_6_0||{};a.listeners=a.listeners||{};a.listeners[b]=a.listeners[b]||[];a.listeners[b].push({callback:c,_listener:d})}else console.log("Failed to _attach event:"+b+" on "+a)};l=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var d=a.KIS_0_6_0;if(d&&d.listeners&&d.listeners[b])for(var g=d.listeners[b],e=g.length,f=0;f<e;f++)if(g[f].callback===c){a.detachEvent("on"+b,g[f]._listener);g.splice(f,1);g.length===0&&delete d.listeners[b];break}}}}j=function(a,b,c,d){var g,e;if(typeof a==="undefined"){console.log(arguments);
console.log(b);return false}if(b.match(/^([\w\-]+)$/))d===true?i(a,b,c):l(a,b,c);else{b=b.split(" ");e=b.length;for(g=0;g<e;g++)j(a,b[g],c,d)}};q=function(a,b,c,d){j(a,c,function(c){var f,n,h,c=c||window.event;n=e.$(b,a);for(f in n){h=c.target||c.srcElement;if(h==n[f]){d.call(n[f],c);c.stopPropagation()}}},true)};e.ext("event",{add:function(a,b){e.each(function(c){j(c,a,b,true)})},remove:function(a,b){e.each(function(c){j(c,a,b,false)})},live:function(a,b,c){q(document.documentElement,a,b,c)},delegate:function(a,
b,c){e.each(function(d){q(d,a,b,c)})}});if(typeof localStorage==="undefined"||typeof JSON==="undefined")return null;var m=localStorage,o=sessionStorage;e.ext("store",{get:function(a,b){var c=b?o.getItem(a):m.getItem(a);return JSON.parse(c)},set:function(a,b,c){b=JSON.stringify(b);c?o.setItem(a,b):m.setItem(a,b)},remove:function(a,b){b?o.removeItem(a):m.removeItem(a)},getAll:function(a){var b,c={},d,g;g=a?m:o;b=g.length;for(a=0;a<b;a++){d=g.key(a);c[d]=g.getItem(d)}return c},clear:function(a){a?o.clear():
m.clear()}});var s=function(a){var b=[],c=0,d={},g,b=r.object_keys(a);b.sort(function(a,b){var c=parseFloat(b),d=parseFloat(a),g=c+""===b,e=d+""===a;return g&&e?c>d?1:c<d?-1:0:g&&!e?1:!g&&e?-1:b>a?1:b<a?-1:0});c=b.length;for(g=0;g<c;g++)d[b[g]]=a[b[g]];return d},r={object_keys:function(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},object_values:function(a){var b=[],c;for(c in a)b.push(a[c]);return b},array_combine:function(a,b){var c={},d,g=0;e.type(a)!=="array"&&(a=this.object_values(a));
e.type(b)!=="array"&&(b=this.object_values(b));d=a.length;if(d!==b.length){console.log("Object combine requires two arrays of the same size");return false}for(g=0;g<d;g++)c[a[g]]=b[g];return c},object_merge:function(){var a=Array.prototype.slice.call(arguments),b=a.length,c={},d,g=0,f,h,i;d=true;for(f=0;f<b;f++)if(e.type(a[f])!=="array"){d=false;break}if(d){c=[];for(f=0;f<b;f++)c=c.contact(a[f]);return c}for(i=f=0;f<b;f++){d=a[f];if(e.type(d)=="array"){h=0;for(g=d.length;h<g;h++)c[i++]=d[h]}else for(h in d)d.hasOwnProperty(h)&&
(parseInt(h,10)+""===h?c[i++]=d[h]:c[h]=d[h])}return c},str_trans:function(a,b,c){var d=[],g=[],e=false,f=0,h=0,i="",j="",l="",k="",m;if(typeof b==="object"){b=s(b);for(m in b)if(b.hasOwnProperty(m)){d.push(m);g.push(b[m])}b=d;c=g}h=a.length;f=b.length;i=typeof c==="string";j=typeof b==="string";for(d=0;d<h;d++){e=false;if(j){a.charAt(d-1);l=a.charAt(d);a.charAt(d+1);for(g=0;g<f;g++)if(l==b.charAt(g)){e=true;break}}else for(g=0;g<f;g++)if(a.substr(d,b[g].length)==b[g]){e=true;d=d+b[g].length-1;break}k=
e?k+(i?c.charAt(g):c[g]):k+a.charAt(d)}return k}};e.ext("util",r)}})($_);

View File

@ -109,40 +109,28 @@
});
/**
* Watches for server-sent events, or falls back to ajax polling
* - defaults to 30 second intervals
* Watches for server-sent events and applies a callback on message
*
* @name sse
* @function
* @memberOf $_
* @param string url
* @param function callback
* @param [int] 30000
*/
$_.ext('sse', function(url, callback, poll_rate){
var source;
//Check for server-sent event support
// Check for server-sent event support
if (typeof EventSource !== 'undefined')
{
source = new EventSource(url);
// Apply the callback
source.onmessage = function(event){
callback(event.data);
callback.call(event.data, event.data);
};
}
else // Ajax polling fallback
{
poll_rate = poll_rate || 30000;
setInterval($_.get, poll_rate, url, {}, function(res){
res.trim().replace(/data:/gim, '');
res.replace(/^(event|id|retry)?\:(.*)$/gim, '');
callback.call(res, res);
});
}
});
}());