Added ..sse method for server-sent events
This commit is contained in:
parent
9aa6a96b88
commit
5ef4e7f837
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
File diff suppressed because one or more lines are too long
@ -115,4 +115,34 @@
|
||||
<span class='line'>108</span> </span><span class="WHIT"> </span><span class="NAME">ajax._do</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
|
||||
<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="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>
|
||||
<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="NAME">callback</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="KEYW">else</span><span class="WHIT"> </span><span class="COMM">// Ajax polling fallback</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="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'>137</span> </span><span class="WHIT"> </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="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
|
||||
<span class='line'>138</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
|
||||
<span class='line'>139</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
|
||||
<span class='line'>140</span> </span><span class="WHIT">
|
||||
<span class='line'>141</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>
|
30
kis-all.js
30
kis-all.js
@ -919,6 +919,36 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
|
||||
ajax._do(url, data, callback, true);
|
||||
});
|
||||
|
||||
/**
|
||||
* Watches for server-sent events, or falls back to ajax polling
|
||||
* - defaults to 30 second intervals
|
||||
*
|
||||
* @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
|
||||
if (typeof EventSource !== 'undefined')
|
||||
{
|
||||
source = new EventSource(url);
|
||||
|
||||
// Apply the callback
|
||||
source.onmessage = callback;
|
||||
}
|
||||
else // Ajax polling fallback
|
||||
{
|
||||
poll_rate = poll_rate || 30000;
|
||||
setInterval($_.get, poll_rate, url, {}, callback);
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
30
kis-lite-dom-min.js
vendored
30
kis-lite-dom-min.js
vendored
@ -376,6 +376,36 @@
|
||||
ajax._do(url, data, callback, true);
|
||||
});
|
||||
|
||||
/**
|
||||
* Watches for server-sent events, or falls back to ajax polling
|
||||
* - defaults to 30 second intervals
|
||||
*
|
||||
* @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
|
||||
if (typeof EventSource !== 'undefined')
|
||||
{
|
||||
source = new EventSource(url);
|
||||
|
||||
// Apply the callback
|
||||
source.onmessage = callback;
|
||||
}
|
||||
else // Ajax polling fallback
|
||||
{
|
||||
poll_rate = poll_rate || 30000;
|
||||
setInterval($_.get, poll_rate, url, {}, callback);
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
@ -376,6 +376,36 @@
|
||||
ajax._do(url, data, callback, true);
|
||||
});
|
||||
|
||||
/**
|
||||
* Watches for server-sent events, or falls back to ajax polling
|
||||
* - defaults to 30 second intervals
|
||||
*
|
||||
* @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
|
||||
if (typeof EventSource !== 'undefined')
|
||||
{
|
||||
source = new EventSource(url);
|
||||
|
||||
// Apply the callback
|
||||
source.onmessage = callback;
|
||||
}
|
||||
else // Ajax polling fallback
|
||||
{
|
||||
poll_rate = poll_rate || 30000;
|
||||
setInterval($_.get, poll_rate, url, {}, callback);
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
16
kis-lite-min.js
vendored
16
kis-lite-min.js
vendored
@ -1,9 +1,9 @@
|
||||
(function(){if("undefined"!==typeof document.querySelector){var e,f,d,c;e=function(a){c="undefined"===typeof a?"undefined"!==typeof e.el?e.el:document.documentElement:"object"!==typeof a?f(a):a;e.prototype.el=c;var a=d(e),b;for(b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};f=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};d=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}};e.ext=function(a,b){b.el=c;e[a]=b};e.ext("each",function(a){if("undefined"!==typeof c.length&&c!==window){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)});e.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()};e=window.$_=window.$_||e;e.$=f}})();
|
||||
(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){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}})();
|
||||
(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 e={_do:function(f,d,c,a){var b=new XMLHttpRequest;"undefined"===typeof c&&(c=function(){});a=a?"POST":"GET";f+="GET"===a?"?"+this._serialize(d):"";b.open(a,f);b.onreadystatechange=function(){4===b.readyState&&c(b.responseText)};"POST"===a?(b.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),b.send(this._serialize(d))):b.send(null)},_serialize:function(f){var d,c,a=[];for(d in f)f.hasOwnProperty(d)&&"function"!==typeof f[d]&&
|
||||
(c=f[d].toString(),d=encodeURIComponent(d),c=encodeURIComponent(c),a.push(d+"="+c));return a.join("&")}};$_.ext("get",function(f,d,c){e._do(f,d,c,!1)});$_.ext("post",function(f,d,c){e._do(f,d,c,!0)})}})();
|
||||
(function(){var e,f,d,c;"undefined"!==typeof document.addEventListener?(e=function(a,b,g){"undefined"!==typeof a.addEventListener&&a.addEventListener(b,g,!1)},f=function(a,b,g){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(b,g,!1)}):"undefined"!==typeof document.attachEvent&&(e=function(a,b,g){function c(a){g.apply(a)}"undefined"!==typeof a.attachEvent?(f(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})):console.log("Failed to _attach event:"+b+" on "+a)},f=function(a,b,g){if("undefined"!==typeof a.detachEvent){var c=a.KIS_0_6_0;if(c&&c.listeners&&c.listeners[b])for(var d=c.listeners[b],f=d.length,e=0;e<f;e++)if(d[e].callback===g){a.detachEvent("on"+b,d[e]._listener);d.splice(e,1);0===d.length&&delete c.listeners[b];break}}});d=function(a,b,c,i){var h,j;if(typeof a==="undefined"){console.log(arguments);console.log(b);return false}if(b.match(/^([\w\-]+)$/))i===true?e(a,b,c):f(a,b,c);
|
||||
else{b=b.split(" ");j=b.length;for(h=0;h<j;h++)d(a,b[h],c,i)}};c=function(a,b,c,e){d(a,c,function(c){var d,g,f,c=c||window.event;g=$_.$(b,a);for(d in g){f=c.target||c.srcElement;if(f==g[d]){e.call(g[d],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(c){d(c,a,b,true)})},remove:function(a,b){$_.each(function(c){d(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("undefined"!==typeof window.XMLHttpRequest){var f={_do:function(d,e,c,a){var b=new XMLHttpRequest;"undefined"===typeof c&&(c=function(){});a=a?"POST":"GET";d+="GET"===a?"?"+this._serialize(e):"";b.open(a,d);b.onreadystatechange=function(){4===b.readyState&&c(b.responseText)};"POST"===a?(b.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),b.send(this._serialize(e))):b.send(null)},_serialize:function(d){var e,c,a=[];for(e in d)d.hasOwnProperty(e)&&"function"!==typeof d[e]&&
|
||||
(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,!1)});$_.ext("post",function(d,e,c){f._do(d,e,c,!0)});$_.ext("sse",function(d,e,c){"undefined"!==typeof EventSource?(d=new EventSource(d),d.onmessage=e):setInterval($_.get,c||3E4,d,{},e)})}})();
|
||||
(function(){var f,d,e,c;"undefined"!==typeof document.addEventListener?(f=function(a,b,g){"undefined"!==typeof a.addEventListener&&a.addEventListener(b,g,!1)},d=function(a,b,g){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(b,g,!1)}):"undefined"!==typeof document.attachEvent&&(f=function(a,b,g){function c(a){g.apply(a)}"undefined"!==typeof a.attachEvent?(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})):console.log("Failed to _attach event:"+b+" on "+a)},d=function(a,b,c){if("undefined"!==typeof a.detachEvent){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);0===e.length&&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)})}})})();
|
||||
|
30
kis-lite.js
30
kis-lite.js
@ -376,6 +376,36 @@
|
||||
ajax._do(url, data, callback, true);
|
||||
});
|
||||
|
||||
/**
|
||||
* Watches for server-sent events, or falls back to ajax polling
|
||||
* - defaults to 30 second intervals
|
||||
*
|
||||
* @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
|
||||
if (typeof EventSource !== 'undefined')
|
||||
{
|
||||
source = new EventSource(url);
|
||||
|
||||
// Apply the callback
|
||||
source.onmessage = callback;
|
||||
}
|
||||
else // Ajax polling fallback
|
||||
{
|
||||
poll_rate = poll_rate || 30000;
|
||||
setInterval($_.get, poll_rate, url, {}, callback);
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
44
kis-min.js
vendored
44
kis-min.js
vendored
@ -1,24 +1,24 @@
|
||||
(function(){if("undefined"!==typeof document.querySelector){var f,g,d,a;f=function(b){a="undefined"===typeof b?"undefined"!==typeof f.el?f.el:document.documentElement:"object"!==typeof b?g(b):b;f.prototype.el=a;var b=d(f),c;for(c in b)"object"===typeof b[c]&&(b[c].el=a);b.el=a;return b};g=function(b,c){var a;if("string"!=typeof b||"undefined"===typeof b)return b;a=null!=c&&1===c.nodeType?c:document;if(b.match(/^#([\w\-]+$)/))return document.getElementById(b.split("#")[1]);a=a.querySelectorAll(b);
|
||||
return 1===a.length?a[0]:a};d=function(b){var a;if("undefined"!==typeof b){if("undefined"!==typeof Object.create)return Object.create(b);a=typeof b;if(!("object"!==a&&"function"!==a))return a=function(){},a.prototype=b,new a}};f.ext=function(b,c){c.el=a;f[b]=c};f.ext("each",function(b){if("undefined"!==typeof a.length&&a!==window){var c=a.length;if(0!==c)for(var e,d=0;d<c;d++)e=a.item(d)?a.item(d):a[d],b.call(e,e)}else b.call(a,a)});f.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()};f=window.$_=window.$_||f;f.$=g}})();
|
||||
(function(){if("undefined"!==typeof document.querySelector){var g,f,c,a;g=function(b){a="undefined"===typeof b?"undefined"!==typeof g.el?g.el:document.documentElement:"object"!==typeof b?f(b):b;g.prototype.el=a;var b=c(g),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};c=function(b){var a;if("undefined"!==typeof b){if("undefined"!==typeof Object.create)return Object.create(b);a=typeof b;if(!("object"!==a&&"function"!==a))return a=function(){},a.prototype=b,new a}};g.ext=function(b,d){d.el=a;g[b]=d};g.ext("each",function(b){if("undefined"!==typeof a.length&&a!==window){var d=a.length;if(0!==d)for(var e,c=0;c<d;c++)e=a.item(c)?a.item(c):a[c],b.call(e,e)}else b.call(a,a)});g.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()};g=window.$_=window.$_||g;g.$=f}})();
|
||||
(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})})();
|
||||
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(f){var f=(f.HTMLElement||f.Element).prototype,g=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},a=Array.prototype.indexOf||function(b){for(var a=0,c=this.length;a<c;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},c=function(c,e){if(""===e)throw new b("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new b("INVALID_CHARACTER_ERR",
|
||||
"String contains an invalid character");return a.call(c,e)},e=function(b){for(var a=d.call(b.className),a=a?a.split(/\s+/):[],c=0,e=a.length;c<e;c++)this.push(a[c]);this._updateClassName=function(){b.className=this.toString()}},i=e.prototype=[],h=function(){return new e(this)};b.prototype=Error.prototype;i.item=function(b){return this[b]||null};i.contains=function(b){return-1!==c(this,b+"")};i.add=function(b){b+="";-1===c(this,b)&&(this.push(b),this._updateClassName())};i.remove=function(b){b=c(this,
|
||||
b+"");-1!==b&&(this.splice(b,1),this._updateClassName())};i.toggle=function(b){b+="";-1===c(this,b)?this.add(b):this.remove(b)};i.toString=function(){return this.join(" ")};if(g.defineProperty){i={get:h,enumerable:!0,configurable:!0};try{g.defineProperty(f,"classList",i)}catch(j){-2146823252===j.number&&(i.enumerable=!1,g.defineProperty(f,"classList",i))}}else g.prototype.__defineGetter__&&f.__defineGetter__("classList",h)}(self);
|
||||
(function(){function f(a,b,c){var e,d;"undefined"!==typeof a.hasAttribute?(a.hasAttribute(b)&&(e=a.getAttribute(b)),d=!0):"undefined"!==typeof a[b]?(e=a[b],d=!1):"class"===b&&"undefined"!==typeof a.className&&(b="className",e=a.className,d=!1);if("undefined"===typeof e&&("undefined"===typeof c||null===c))return console.log(c),console.log(a),console.log("Element does not have the selected attribute"),null;if("undefined"===typeof c)return e;"undefined"!==typeof c&&null!==c?!0===d?a.setAttribute(b,c):
|
||||
a[b]=c:null===c&&(!0===d?a.removeAttribute(b):delete a[b]);return"undefined"!==typeof c?c:e}function g(a){return a.replace(/(\-[a-z])/g,function(b){return b.toUpperCase().replace("-","")})}function d(a,b,c){var e,b=g(b);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof c&&"undefined"!==a.style[b])return a.style[b];if("undefined"===typeof c&&"undefined"!==a.style[e[b]])return a.style[e[b]];if("undefined"!==typeof a.style[b])return a.style[b]=c,null;if(a.style[e[b]])return a.style[e[b]]=
|
||||
c,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){"undefined"===typeof a&&(a="block");this.css("display",a)},attr:function(a,b){var c=this.el;if(1<c.length&&"undefined"===typeof b)console.log(c),console.log("Must be a singular element");else if(1<c.length&&"undefined"!==typeof b)$_.each(function(c){return f(c,
|
||||
a,b)});else return f(c,a,b)},text:function(a){var b,c,e;e=this.el;c="undefined"!==typeof e.textContent?"textContent":"undefined"!==typeof e.innerText?"innerText":"innerHTML";b=e[c];return"undefined"!==typeof a?e[c]=a:b},css:function(a,b){if("undefined"===typeof b)return d(this.el,a);$_.each(function(c){d(c,a,b)})},append:function(a){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("beforeend",a):this.el.innerHTML+=a},prepend:function(a){"undefined"!==typeof document.insertAdjacentHTML?
|
||||
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(g){var g=(g.HTMLElement||g.Element).prototype,f=Object,c=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,e){if(""===e)throw new b("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new b("INVALID_CHARACTER_ERR",
|
||||
"String contains an invalid character");return a.call(d,e)},e=function(b){for(var a=c.call(b.className),a=a?a.split(/\s+/):[],d=0,e=a.length;d<e;d++)this.push(a[d]);this._updateClassName=function(){b.className=this.toString()}},h=e.prototype=[],i=function(){return new e(this)};b.prototype=Error.prototype;h.item=function(b){return this[b]||null};h.contains=function(b){return-1!==d(this,b+"")};h.add=function(b){b+="";-1===d(this,b)&&(this.push(b),this._updateClassName())};h.remove=function(b){b=d(this,
|
||||
b+"");-1!==b&&(this.splice(b,1),this._updateClassName())};h.toggle=function(b){b+="";-1===d(this,b)?this.add(b):this.remove(b)};h.toString=function(){return this.join(" ")};if(f.defineProperty){h={get:i,enumerable:!0,configurable:!0};try{f.defineProperty(g,"classList",h)}catch(j){-2146823252===j.number&&(h.enumerable=!1,f.defineProperty(g,"classList",h))}}else f.prototype.__defineGetter__&&g.__defineGetter__("classList",i)}(self);
|
||||
(function(){function g(a,b,d){var e,c;"undefined"!==typeof a.hasAttribute?(a.hasAttribute(b)&&(e=a.getAttribute(b)),c=!0):"undefined"!==typeof a[b]?(e=a[b],c=!1):"class"===b&&"undefined"!==typeof a.className&&(b="className",e=a.className,c=!1);if("undefined"===typeof e&&("undefined"===typeof d||null===d))return console.log(d),console.log(a),console.log("Element does not have the selected attribute"),null;if("undefined"===typeof d)return e;"undefined"!==typeof d&&null!==d?!0===c?a.setAttribute(b,d):
|
||||
a[b]=d:null===d&&(!0===c?a.removeAttribute(b):delete a[b]);return"undefined"!==typeof d?d:e}function f(a){return a.replace(/(\-[a-z])/g,function(b){return b.toUpperCase().replace("-","")})}function c(a,b,d){var e,b=f(b);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof d&&"undefined"!==a.style[b])return a.style[b];if("undefined"===typeof d&&"undefined"!==a.style[e[b]])return a.style[e[b]];if("undefined"!==typeof a.style[b])return a.style[b]=d,null;if(a.style[e[b]])return a.style[e[b]]=
|
||||
d,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){"undefined"===typeof a&&(a="block");this.css("display",a)},attr:function(a,b){var d=this.el;if(1<d.length&&"undefined"===typeof b)console.log(d),console.log("Must be a singular element");else if(1<d.length&&"undefined"!==typeof b)$_.each(function(d){return g(d,
|
||||
a,b)});else return g(d,a,b)},text:function(a){var b,d,c;c=this.el;d="undefined"!==typeof c.textContent?"textContent":"undefined"!==typeof c.innerText?"innerText":"innerHTML";b=c[d];return"undefined"!==typeof a?c[d]=a:b},css:function(a,b){if("undefined"===typeof b)return c(this.el,a);$_.each(function(d){c(d,a,b)})},append:function(a){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("beforeend",a):this.el.innerHTML+=a},prepend:function(a){"undefined"!==typeof document.insertAdjacentHTML?
|
||||
this.el.insertAdjacentHTML("afterbegin",a):this.el.innerHTML=a+this.el.innerHTML},html:function(a){"undefined"!==typeof a&&(this.el.innerHTML=a);return this.el.innerHTML}})})();
|
||||
(function(){if("undefined"!==typeof window.XMLHttpRequest){var f={_do:function(f,d,a,b){var c=new XMLHttpRequest;"undefined"===typeof a&&(a=function(){});b=b?"POST":"GET";f+="GET"===b?"?"+this._serialize(d):"";c.open(b,f);c.onreadystatechange=function(){4===c.readyState&&a(c.responseText)};"POST"===b?(c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.send(this._serialize(d))):c.send(null)},_serialize:function(f){var d,a,b=[];for(d in f)f.hasOwnProperty(d)&&"function"!==typeof f[d]&&
|
||||
(a=f[d].toString(),d=encodeURIComponent(d),a=encodeURIComponent(a),b.push(d+"="+a));return b.join("&")}};$_.ext("get",function(g,d,a){f._do(g,d,a,!1)});$_.ext("post",function(g,d,a){f._do(g,d,a,!0)})}})();
|
||||
(function(){var f,g,d,a;"undefined"!==typeof document.addEventListener?(f=function(b,a,e){"undefined"!==typeof b.addEventListener&&b.addEventListener(a,e,!1)},g=function(b,a,e){"undefined"!==typeof b.removeEventListener&&b.removeEventListener(a,e,!1)}):"undefined"!==typeof document.attachEvent&&(f=function(b,a,e){function d(b){e.apply(b)}"undefined"!==typeof b.attachEvent?(g(a,e),b.attachEvent("on"+a,d),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:e,
|
||||
_listener:d})):console.log("Failed to _attach event:"+a+" on "+b)},g=function(b,a,d){if("undefined"!==typeof b.detachEvent){var f=b.KIS_0_6_0;if(f&&f.listeners&&f.listeners[a])for(var h=f.listeners[a],g=h.length,k=0;k<g;k++)if(h[k].callback===d){b.detachEvent("on"+a,h[k]._listener);h.splice(k,1);0===h.length&&delete f.listeners[a];break}}});d=function(b,a,e,i){var h,j;if(typeof b==="undefined"){console.log(arguments);console.log(a);return false}if(a.match(/^([\w\-]+)$/))i===true?f(b,a,e):g(b,a,e);
|
||||
else{a=a.split(" ");j=a.length;for(h=0;h<j;h++)d(b,a[h],e,i)}};a=function(b,a,e,f){d(b,e,function(d){var e,g,l,d=d||window.event;g=$_.$(a,b);for(e in g){l=d.target||d.srcElement;if(l==g[e]){f.call(g[e],d);d.stopPropagation()}}},true)};$_.ext("event",{add:function(b,a){$_.each(function(e){d(e,b,a,true)})},remove:function(b,a){$_.each(function(e){d(e,b,a,false)})},live:function(b,c,d){a(document.documentElement,b,c,d)},delegate:function(b,c,d){$_.each(function(f){a(f,b,c,d)})}})})();
|
||||
(function(){var f=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.msIndexedDB,g={};"undefined"!==typeof f&&(g={current_db:null,connect:function(d,a,b){var c={},c=f.open(d,a||1);"undefined"!==typeof b&&(c.onupgradeneeded=b);c.onerror=function(){console.log("IndexedDB disallowed.")};c.onsuccess=function(){g.current_db=c.result}},create_store:function(d,a,b){var c={};"undefined"!==typeof a&&(c.keyPath=a);"undefined"!==typeof b&&(c.autoIncrement=!!b);return f.createObjectStore(d,
|
||||
c)},delete_store:function(){f.deleteObjectStore().onerror=f.onerror}},$_.ext("indexedDB",g))})();
|
||||
(function(){if("undefined"===typeof localStorage||"undefined"===typeof JSON)return null;var f=localStorage,g=sessionStorage;$_.ext("store",{get:function(d,a){var b=a?g.getItem(d):f.getItem(d);return JSON.parse(b)},set:function(d,a,b){a=JSON.stringify(a);b?g.setItem(d,a):f.setItem(d,a)},remove:function(d,a){a?g.removeItem(d):f.removeItem(d)},getAll:function(d){var a,b={},c,e;e=d?f:g;a=e.length;for(d=0;d<a;d++)c=e.key(d),b[c]=e.getItem(c);return b},clear:function(d){d?g.clear():f.clear()}})})();
|
||||
(function(){var f=function(d){var a=[],b=0,c={},e,a=g.object_keys(d);a.sort(function(a,b){var c=parseFloat(b),d=parseFloat(a),e=c+""===b,f=d+""===a;return e&&f?c>d?1:c<d?-1:0:e&&!f?1:!e&&f?-1:b>a?1:b<a?-1:0});b=a.length;for(e=0;e<b;e++)c[a[e]]=d[a[e]];return c},g={object_keys:function(d){var a=[],b;for(b in d)d.hasOwnProperty(b)&&a.push(b);return a},object_values:function(d){var a=[],b;for(b in d)a.push(d[b]);return a},array_combine:function(d,a){var b={},c,e=0;"array"!==$_.type(d)&&(d=this.object_values(d));
|
||||
"array"!==$_.type(a)&&(a=this.object_values(a));c=d.length;if(c!==a.length)return console.log("Object combine requires two arrays of the same size"),!1;for(e=0;e<c;e++)b[d[e]]=a[e];return b},object_merge:function(){var d=Array.prototype.slice.call(arguments),a=d.length,b={},c,e=0,f,g,j;c=!0;for(f=0;f<a;f++)if("array"!==$_.type(d[f])){c=!1;break}if(c){b=[];for(f=0;f<a;f++)b=b.contact(d[f]);return b}for(j=f=0;f<a;f++)if(c=d[f],"array"==$_.type(c)){g=0;for(e=c.length;g<e;g++)b[j++]=c[g]}else for(g in c)c.hasOwnProperty(g)&&
|
||||
(parseInt(g,10)+""===g?b[j++]=c[g]:b[g]=c[g]);return b},str_trans:function(d,a,b){var c=[],e=[],g=!1,h=0,j=0,k="",l="",o="",m="",n;if("object"===typeof a){a=f(a);for(n in a)a.hasOwnProperty(n)&&(c.push(n),e.push(a[n]));a=c;b=e}j=d.length;h=a.length;k="string"===typeof b;l="string"===typeof a;for(c=0;c<j;c++){g=!1;if(l){d.charAt(c-1);o=d.charAt(c);d.charAt(c+1);for(e=0;e<h;e++)if(o==a.charAt(e)){g=!0;break}}else for(e=0;e<h;e++)if(d.substr(c,a[e].length)==a[e]){g=!0;c=c+a[e].length-1;break}m=g?m+(k?
|
||||
b.charAt(e):b[e]):m+d.charAt(c)}return m}};$_.ext("util",g)})();
|
||||
(function(){if("undefined"!==typeof window.XMLHttpRequest){var g={_do:function(f,c,a,b){var d=new XMLHttpRequest;"undefined"===typeof a&&(a=function(){});b=b?"POST":"GET";f+="GET"===b?"?"+this._serialize(c):"";d.open(b,f);d.onreadystatechange=function(){4===d.readyState&&a(d.responseText)};"POST"===b?(d.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),d.send(this._serialize(c))):d.send(null)},_serialize:function(f){var c,a,b=[];for(c in f)f.hasOwnProperty(c)&&"function"!==typeof f[c]&&
|
||||
(a=f[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),b.push(c+"="+a));return b.join("&")}};$_.ext("get",function(f,c,a){g._do(f,c,a,!1)});$_.ext("post",function(f,c,a){g._do(f,c,a,!0)});$_.ext("sse",function(f,c,a){"undefined"!==typeof EventSource?(f=new EventSource(f),f.onmessage=c):setInterval($_.get,a||3E4,f,{},c)})}})();
|
||||
(function(){var g,f,c,a;"undefined"!==typeof document.addEventListener?(g=function(b,a,c){"undefined"!==typeof b.addEventListener&&b.addEventListener(a,c,!1)},f=function(b,a,c){"undefined"!==typeof b.removeEventListener&&b.removeEventListener(a,c,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(b,a,c){function h(b){c.apply(b)}"undefined"!==typeof b.attachEvent?(f(a,c),b.attachEvent("on"+a,h),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:c,
|
||||
_listener:h})):console.log("Failed to _attach event:"+a+" on "+b)},f=function(b,a,c){if("undefined"!==typeof b.detachEvent){var h=b.KIS_0_6_0;if(h&&h.listeners&&h.listeners[a])for(var f=h.listeners[a],g=f.length,k=0;k<g;k++)if(f[k].callback===c){b.detachEvent("on"+a,f[k]._listener);f.splice(k,1);0===f.length&&delete h.listeners[a];break}}});c=function(b,a,e,h){var i,j;if(typeof b==="undefined"){console.log(arguments);console.log(a);return false}if(a.match(/^([\w\-]+)$/))h===true?g(b,a,e):f(b,a,e);
|
||||
else{a=a.split(" ");j=a.length;for(i=0;i<j;i++)c(b,a[i],e,h)}};a=function(b,a,e,f){c(b,e,function(c){var e,g,l,c=c||window.event;g=$_.$(a,b);for(e in g){l=c.target||c.srcElement;if(l==g[e]){f.call(g[e],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(b,a){$_.each(function(e){c(e,b,a,true)})},remove:function(a,d){$_.each(function(e){c(e,a,d,false)})},live:function(b,d,c){a(document.documentElement,b,d,c)},delegate:function(b,c,e){$_.each(function(f){a(f,b,c,e)})}})})();
|
||||
(function(){var g=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.msIndexedDB,f={};"undefined"!==typeof g&&(f={current_db:null,connect:function(c,a,b){var d={},d=g.open(c,a||1);"undefined"!==typeof b&&(d.onupgradeneeded=b);d.onerror=function(){console.log("IndexedDB disallowed.")};d.onsuccess=function(){f.current_db=d.result}},create_store:function(c,a,b){var d={};"undefined"!==typeof a&&(d.keyPath=a);"undefined"!==typeof b&&(d.autoIncrement=!!b);return g.createObjectStore(c,
|
||||
d)},delete_store:function(){g.deleteObjectStore().onerror=g.onerror}},$_.ext("indexedDB",f))})();
|
||||
(function(){if("undefined"===typeof localStorage||"undefined"===typeof JSON)return null;var g=localStorage,f=sessionStorage;$_.ext("store",{get:function(c,a){var b=a?f.getItem(c):g.getItem(c);return JSON.parse(b)},set:function(c,a,b){a=JSON.stringify(a);b?f.setItem(c,a):g.setItem(c,a)},remove:function(c,a){a?f.removeItem(c):g.removeItem(c)},getAll:function(c){var a,b={},d,e;e=c?g:f;a=e.length;for(c=0;c<a;c++)d=e.key(c),b[d]=e.getItem(d);return b},clear:function(c){c?f.clear():g.clear()}})})();
|
||||
(function(){var g=function(c){var a=[],b=0,d={},e,a=f.object_keys(c);a.sort(function(a,b){var c=parseFloat(b),d=parseFloat(a),e=c+""===b,f=d+""===a;return e&&f?c>d?1:c<d?-1:0:e&&!f?1:!e&&f?-1:b>a?1:b<a?-1:0});b=a.length;for(e=0;e<b;e++)d[a[e]]=c[a[e]];return d},f={object_keys:function(c){var a=[],b;for(b in c)c.hasOwnProperty(b)&&a.push(b);return a},object_values:function(c){var a=[],b;for(b in c)a.push(c[b]);return a},array_combine:function(c,a){var b={},d,e=0;"array"!==$_.type(c)&&(c=this.object_values(c));
|
||||
"array"!==$_.type(a)&&(a=this.object_values(a));d=c.length;if(d!==a.length)return console.log("Object combine requires two arrays of the same size"),!1;for(e=0;e<d;e++)b[c[e]]=a[e];return b},object_merge:function(){var c=Array.prototype.slice.call(arguments),a=c.length,b={},d,e=0,f,g,j;d=!0;for(f=0;f<a;f++)if("array"!==$_.type(c[f])){d=!1;break}if(d){b=[];for(f=0;f<a;f++)b=b.contact(c[f]);return b}for(j=f=0;f<a;f++)if(d=c[f],"array"==$_.type(d)){g=0;for(e=d.length;g<e;g++)b[j++]=d[g]}else for(g in d)d.hasOwnProperty(g)&&
|
||||
(parseInt(g,10)+""===g?b[j++]=d[g]:b[g]=d[g]);return b},str_trans:function(c,a,b){var d=[],e=[],f=!1,i=0,j=0,k="",l="",o="",m="",n;if("object"===typeof a){a=g(a);for(n in a)a.hasOwnProperty(n)&&(d.push(n),e.push(a[n]));a=d;b=e}j=c.length;i=a.length;k="string"===typeof b;l="string"===typeof a;for(d=0;d<j;d++){f=!1;if(l){c.charAt(d-1);o=c.charAt(d);c.charAt(d+1);for(e=0;e<i;e++)if(o==a.charAt(e)){f=!0;break}}else for(e=0;e<i;e++)if(c.substr(d,a[e].length)==a[e]){f=!0;d=d+a[e].length-1;break}m=f?m+(k?
|
||||
b.charAt(e):b[e]):m+c.charAt(d)}return m}};$_.ext("util",f)})();
|
||||
|
@ -108,4 +108,34 @@
|
||||
ajax._do(url, data, callback, true);
|
||||
});
|
||||
|
||||
/**
|
||||
* Watches for server-sent events, or falls back to ajax polling
|
||||
* - defaults to 30 second intervals
|
||||
*
|
||||
* @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
|
||||
if (typeof EventSource !== 'undefined')
|
||||
{
|
||||
source = new EventSource(url);
|
||||
|
||||
// Apply the callback
|
||||
source.onmessage = callback;
|
||||
}
|
||||
else // Ajax polling fallback
|
||||
{
|
||||
poll_rate = poll_rate || 30000;
|
||||
setInterval($_.get, poll_rate, url, {}, callback);
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
Loading…
Reference in New Issue
Block a user