Skip to content
Browse files

Updated jquery-cookie

  • Loading branch information...
1 parent 4801179 commit aca96884e6ab905d80435f2df24268fb447ef730 @swook committed Feb 25, 2012
Showing with 192 additions and 2 deletions.
  1. +42 −0 cfInval.js
  2. +2 −2 cfInval.min.js
  3. BIN cfInval.min.js.gz
  4. +147 −0 jquery.timeago.js
  5. +1 −0 jquery.timeago.min.js
View
42 cfInval.js
@@ -729,6 +729,48 @@ var cfInvalUI = {
* Third Party Scripts
*/
+
+// From Klaus Hartl
+// ref. https://github.com/carhartl/jquery-cookie
+$.cookie = function(key, value, options) {
+
+ // key and at least value given, set cookie...
+ if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
+ options = $.extend({}, options);
+
+ if (value === null || value === undefined) {
+ options.expires = -1;
+ }
+
+ if (typeof options.expires === 'number') {
+ var days = options.expires, t = options.expires = new Date();
+ t.setDate(t.getDate() + days);
+ }
+
+ value = String(value);
+
+ return (document.cookie = [
+ encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+ options.path ? '; path=' + options.path : '',
+ options.domain ? '; domain=' + options.domain : '',
+ options.secure ? '; secure' : ''
+ ].join(''));
+ }
+
+ // key and possibly options given, get cookie...
+ options = value || {};
+ var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
+
+ var pairs = document.cookie.split('; ');
+ for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
+ if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
+ }
+ return null;
+};
+
+
+
// From James Padolsey
// ref. http://james.padolsey.com/javascript/sorting-elements-with-jquery/
jQuery.fn.sortElements = (function(){
View
4 cfInval.min.js 100755 → 100644
@@ -1,8 +1,8 @@
-if(typeof Crypto=="undefined"||!Crypto.util){(function(){var b=window.Crypto={},c=b.util={rotl:function(d,e){return d<<e|d>>>32-e},rotr:function(d,e){return d<<32-e|d>>>e},endian:function(d){if(d.constructor==Number){return c.rotl(d,8)&16711935|c.rotl(d,24)&4278255360}for(var e=0;e<d.length;e++){d[e]=c.endian(d[e])}return d},randomBytes:function(d){for(var e=[];d>0;d--){e.push(Math.floor(Math.random()*256))}return e},bytesToWords:function(f){for(var h=[],e=0,g=0;e<f.length;e++,g+=8){h[g>>>5]|=f[e]<<24-g%32}return h},wordsToBytes:function(e){for(var f=[],d=0;d<e.length*32;d+=8){f.push(e[d>>>5]>>>24-d%32&255)}return f},bytesToHex:function(e){for(var f=[],d=0;d<e.length;d++){f.push((e[d]>>>4).toString(16));f.push((e[d]&15).toString(16))}return f.join("")},hexToBytes:function(e){for(var f=[],d=0;d<e.length;d+=2){f.push(parseInt(e.substr(d,2),16))}return f},bytesToBase64:function(g){if(typeof btoa=="function"){return btoa(a.bytesToString(g))}for(var j=[],f=0;f<g.length;f+=3){for(var i=g[f]<<16|g[f+1]<<8|g[f+2],h=0;h<4;h++){f*8+h*6<=g.length*8?j.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-h)&63)):j.push("=")}}return j.join("")},base64ToBytes:function(f){if(typeof atob=="function"){return a.stringToBytes(atob(f))}f=f.replace(/[^A-Z0-9+\/]/ig,"");for(var h=[],e=0,g=0;e<f.length;g=++e%4){g!=0&&h.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(f.charAt(e-1))&Math.pow(2,-2*g+8)-1)<<g*2|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(f.charAt(e))>>>6-g*2)}return h}};b=b.charenc={};b.UTF8={stringToBytes:function(d){return a.stringToBytes(unescape(encodeURIComponent(d)))},bytesToString:function(d){return decodeURIComponent(escape(a.bytesToString(d)))}};var a=b.Binary={stringToBytes:function(e){for(var f=[],d=0;d<e.length;d++){f.push(e.charCodeAt(d)&255)}return f},bytesToString:function(e){for(var f=[],d=0;d<e.length;d++){f.push(String.fromCharCode(e[d]))}return f.join("")}}})()}(function(){var g=Crypto,k=g.util,f=g.charenc,e=f.UTF8,h=f.Binary,d=g.SHA1=function(c,b){var a=k.wordsToBytes(d._sha1(c));return b&&b.asBytes?a:b&&b.asString?h.bytesToString(a):k.bytesToHex(a)};d._sha1=function(A){if(A.constructor==String){A=e.stringToBytes(A)}var z=k.bytesToWords(A),y=A.length*8;A=[];var v=1732584193,x=-271733879,n=-1732584194,j=271733878,i=-1009589776;z[y>>5]|=128<<24-y%32;z[(y+64>>>9<<4)+15]=y;for(y=0;y<z.length;y+=16){for(var b=v,a=x,D=n,C=j,B=i,w=0;w<80;w++){if(w<16){A[w]=z[y+w]}else{var c=A[w-3]^A[w-8]^A[w-14]^A[w-16];A[w]=c<<1|c>>>31}c=(v<<5|v>>>27)+i+(A[w]>>>0)+(w<20?(x&n|~x&j)+1518500249:w<40?(x^n^j)+1859775393:w<60?(x&n|x&j|n&j)-1894007588:(x^n^j)-899497514);i=j;j=n;n=x<<30|x>>>2;x=v;v=c}v+=b;x+=a;n+=D;j+=C;i+=B}return[v,x,n,j,i]};d._blocksize=16;d._digestsize=20})();(function(){var e=Crypto,g=e.util,d=e.charenc,b=d.UTF8,f=d.Binary;e.HMAC=function(a,l,j,i){if(l.constructor==String){l=b.stringToBytes(l)}if(j.constructor==String){j=b.stringToBytes(j)}if(j.length>a._blocksize*4){j=a(j,{asBytes:true})}var c=j.slice(0);j=j.slice(0);for(var h=0;h<a._blocksize*4;h++){c[h]^=92;j[h]^=54}a=a(c.concat(a(j.concat(l),{asBytes:true})),{asBytes:true});return i&&i.asBytes?a:i&&i.asString?f.bytesToString(a):g.bytesToHex(a)}})();(function(a){a.queryYQL=function(e,d,g,h){if(a.isFunction(d)){h=d;d="json"}else{if(!d.match(/(json|xml)/)){h=g;g=d;d="json"}else{if(a.isFunction(g)){h=g;g=undefined}}}var b=("https:"==document.location.protocol?"https":"http");if(g==="all"){g=b+"://datatables.org/alltables.env"}var c="https://query.yahooapis.com/v1/public/yql?callback=?";var f={format:d,q:e};if(g){f.env=g}return a.get(c,f,h,"json")}})(jQuery);(function(e){e.json2xml=function(j,i){c={};c=e.extend(true,c,d,i||{});return b(j,c.rootTagName,"",0)};var d={formatOutput:false,formatTextNodes:false,indentString:" ",rootTagName:"root",ignore:[],replace:[],nodes:[],exceptions:[]};var c={};var b=function(s,k,l,n){var r=(c.formatOutput)?"\r\n":"";var m=(c.formatOutput)?h(n):"";var i=m+"<"+k;var j="";for(var q in s){if(s.hasOwnProperty(q)){var o=l+q;var p=a(l,q);if(e.inArray(o,c.ignore)==-1){if(e.isArray(s[q])){j+=g(s[q],p,o+".",n+1,r)}else{if(typeof(s[q])==="object"){j+=b(s[q],p,o+".",n+1)}else{if(e.inArray(o,c.nodes)!=-1){j+=f(p,s[q],n,r)}else{i+=" "+p+'="'+s[q]+'"'}}}}}}if(j!==""){i+=">"+r+j+m+"</"+k+">"+r}else{i+="/>"+r}return i};var h=function(l){var j="";for(var k=0;k<l;k++){j+=c.indentString}return j};var a=function(j,l){var k=c.replace.length;var i=j+l;while(k--){if(c.replace[k].hasOwnProperty(i)){return c.replace[k][i]}}return l};var g=function(i,j,q,l,p){var o="";if(i.length>0){for(var m in i){if(typeof(i[m])!=="object"){if(i[m]===""){o+=h(l)+"<"+j+"/>"+p}else{var k=(c.formatTextNodes)?p+h(l+1):"";var n=(c.formatTextNodes)?p+h(l):"";o+=h(l)+"<"+j+">"+k+i[m]+n+"</"+j+">"+p}}else{o+=b(i[m],j,q,l)}}}else{o+=h(l)+"<"+j+"/>"+p}return o};var f=function(i,o,n,m){var k=(c.formatTextNodes)?m+h(n+2):"";var l=(c.formatTextNodes)?m+h(n+1):"";var j=h(n+1)+"<"+i+">"+k+o+l+"</"+i+">"+m;return j}})(jQuery);/*!
+if(typeof Crypto=="undefined"||!Crypto.util){(function(){var b=window.Crypto={},c=b.util={rotl:function(d,e){return d<<e|d>>>32-e},rotr:function(d,e){return d<<32-e|d>>>e},endian:function(d){if(d.constructor==Number){return c.rotl(d,8)&16711935|c.rotl(d,24)&4278255360}for(var e=0;e<d.length;e++){d[e]=c.endian(d[e])}return d},randomBytes:function(d){for(var e=[];d>0;d--){e.push(Math.floor(Math.random()*256))}return e},bytesToWords:function(f){for(var h=[],e=0,g=0;e<f.length;e++,g+=8){h[g>>>5]|=f[e]<<24-g%32}return h},wordsToBytes:function(e){for(var f=[],d=0;d<e.length*32;d+=8){f.push(e[d>>>5]>>>24-d%32&255)}return f},bytesToHex:function(e){for(var f=[],d=0;d<e.length;d++){f.push((e[d]>>>4).toString(16));f.push((e[d]&15).toString(16))}return f.join("")},hexToBytes:function(e){for(var f=[],d=0;d<e.length;d+=2){f.push(parseInt(e.substr(d,2),16))}return f},bytesToBase64:function(g){if(typeof btoa=="function"){return btoa(a.bytesToString(g))}for(var j=[],f=0;f<g.length;f+=3){for(var i=g[f]<<16|g[f+1]<<8|g[f+2],h=0;h<4;h++){f*8+h*6<=g.length*8?j.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-h)&63)):j.push("=")}}return j.join("")},base64ToBytes:function(f){if(typeof atob=="function"){return a.stringToBytes(atob(f))}f=f.replace(/[^A-Z0-9+\/]/ig,"");for(var h=[],e=0,g=0;e<f.length;g=++e%4){g!=0&&h.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(f.charAt(e-1))&Math.pow(2,-2*g+8)-1)<<g*2|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(f.charAt(e))>>>6-g*2)}return h}};b=b.charenc={};b.UTF8={stringToBytes:function(d){return a.stringToBytes(unescape(encodeURIComponent(d)))},bytesToString:function(d){return decodeURIComponent(escape(a.bytesToString(d)))}};var a=b.Binary={stringToBytes:function(e){for(var f=[],d=0;d<e.length;d++){f.push(e.charCodeAt(d)&255)}return f},bytesToString:function(e){for(var f=[],d=0;d<e.length;d++){f.push(String.fromCharCode(e[d]))}return f.join("")}}})()}(function(){var g=Crypto,k=g.util,f=g.charenc,e=f.UTF8,h=f.Binary,d=g.SHA1=function(c,b){var a=k.wordsToBytes(d._sha1(c));return b&&b.asBytes?a:b&&b.asString?h.bytesToString(a):k.bytesToHex(a)};d._sha1=function(A){if(A.constructor==String){A=e.stringToBytes(A)}var z=k.bytesToWords(A),y=A.length*8;A=[];var v=1732584193,x=-271733879,n=-1732584194,j=271733878,i=-1009589776;z[y>>5]|=128<<24-y%32;z[(y+64>>>9<<4)+15]=y;for(y=0;y<z.length;y+=16){for(var b=v,a=x,D=n,C=j,B=i,w=0;w<80;w++){if(w<16){A[w]=z[y+w]}else{var c=A[w-3]^A[w-8]^A[w-14]^A[w-16];A[w]=c<<1|c>>>31}c=(v<<5|v>>>27)+i+(A[w]>>>0)+(w<20?(x&n|~x&j)+1518500249:w<40?(x^n^j)+1859775393:w<60?(x&n|x&j|n&j)-1894007588:(x^n^j)-899497514);i=j;j=n;n=x<<30|x>>>2;x=v;v=c}v+=b;x+=a;n+=D;j+=C;i+=B}return[v,x,n,j,i]};d._blocksize=16;d._digestsize=20})();(function(){var e=Crypto,g=e.util,d=e.charenc,b=d.UTF8,f=d.Binary;e.HMAC=function(a,l,j,i){if(l.constructor==String){l=b.stringToBytes(l)}if(j.constructor==String){j=b.stringToBytes(j)}if(j.length>a._blocksize*4){j=a(j,{asBytes:true})}var c=j.slice(0);j=j.slice(0);for(var h=0;h<a._blocksize*4;h++){c[h]^=92;j[h]^=54}a=a(c.concat(a(j.concat(l),{asBytes:true})),{asBytes:true});return i&&i.asBytes?a:i&&i.asString?f.bytesToString(a):g.bytesToHex(a)}})();(function(a){a.queryYQL=function(e,d,g,h){if(a.isFunction(d)){h=d;d="json"}else{if(!d.match(/(json|xml)/)){h=g;g=d;d="json"}else{if(a.isFunction(g)){h=g;g=undefined}}}var b=("https:"==document.location.protocol?"https":"http");if(g==="all"){g=b+"://datatables.org/alltables.env"}var c="https://query.yahooapis.com/v1/public/yql?callback=?";var f={format:d,q:e};if(g){f.env=g}return a.get(c,f,h,"json")}})(jQuery);(function(d){d.timeago=function(g){if(g instanceof Date){return a(g)}else{if(typeof g==="string"){return a(d.timeago.parse(g))}else{return a(d.timeago.datetime(g))}}};var f=d.timeago;d.extend(d.timeago,{settings:{refreshMillis:60000,allowFuture:false,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years",numbers:[]}},inWords:function(l){var m=this.settings.strings;var i=m.prefixAgo;var q=m.suffixAgo;if(this.settings.allowFuture){if(l<0){i=m.prefixFromNow;q=m.suffixFromNow}l=Math.abs(l)}var o=l/1000;var g=o/60;var n=g/60;var p=n/24;var j=p/365;function h(r,t){var s=d.isFunction(r)?r(t,l):r;var u=(m.numbers&&m.numbers[t])||t;return s.replace(/%d/i,u)}var k=o<45&&h(m.seconds,Math.round(o))||o<90&&h(m.minute,1)||g<45&&h(m.minutes,Math.round(g))||g<90&&h(m.hour,1)||n<24&&h(m.hours,Math.round(n))||n<48&&h(m.day,1)||p<30&&h(m.days,Math.floor(p))||p<60&&h(m.month,1)||p<365&&h(m.months,Math.floor(p/30))||j<2&&h(m.year,1)||h(m.years,Math.floor(j));return d.trim([i,k,q].join(" "))},parse:function(h){var g=d.trim(h);g=g.replace(/\.\d\d\d+/,"");g=g.replace(/-/,"/").replace(/-/,"/");g=g.replace(/T/," ").replace(/Z/," UTC");g=g.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2");return new Date(g)},datetime:function(h){var i=d(h).get(0).tagName.toLowerCase()==="time";var g=i?d(h).attr("datetime"):d(h).attr("title");return f.parse(g)}});d.fn.timeago=function(){var h=this;h.each(c);var g=f.settings;if(g.refreshMillis>0){setInterval(function(){h.each(c)},g.refreshMillis)}return h};function c(){var g=b(this);if(!isNaN(g.datetime)){d(this).text(a(g.datetime))}return this}function b(g){g=d(g);if(!g.data("timeago")){g.data("timeago",{datetime:f.datetime(g)});var h=d.trim(g.text());if(h.length>0){g.attr("title",h)}}return g.data("timeago")}function a(g){return f.inWords(e(g))}function e(g){return(new Date().getTime()-g.getTime())}document.createElement("abbr");document.createElement("time")}(jQuery));(function(e){e.json2xml=function(j,i){c={};c=e.extend(true,c,d,i||{});return b(j,c.rootTagName,"",0)};var d={formatOutput:false,formatTextNodes:false,indentString:" ",rootTagName:"root",ignore:[],replace:[],nodes:[],exceptions:[]};var c={};var b=function(s,k,l,n){var r=(c.formatOutput)?"\r\n":"";var m=(c.formatOutput)?h(n):"";var i=m+"<"+k;var j="";for(var q in s){if(s.hasOwnProperty(q)){var o=l+q;var p=a(l,q);if(e.inArray(o,c.ignore)==-1){if(e.isArray(s[q])){j+=g(s[q],p,o+".",n+1,r)}else{if(typeof(s[q])==="object"){j+=b(s[q],p,o+".",n+1)}else{if(e.inArray(o,c.nodes)!=-1){j+=f(p,s[q],n,r)}else{i+=" "+p+'="'+s[q]+'"'}}}}}}if(j!==""){i+=">"+r+j+m+"</"+k+">"+r}else{i+="/>"+r}return i};var h=function(l){var j="";for(var k=0;k<l;k++){j+=c.indentString}return j};var a=function(j,l){var k=c.replace.length;var i=j+l;while(k--){if(c.replace[k].hasOwnProperty(i)){return c.replace[k][i]}}return l};var g=function(i,j,q,l,p){var o="";if(i.length>0){for(var m in i){if(typeof(i[m])!=="object"){if(i[m]===""){o+=h(l)+"<"+j+"/>"+p}else{var k=(c.formatTextNodes)?p+h(l+1):"";var n=(c.formatTextNodes)?p+h(l):"";o+=h(l)+"<"+j+">"+k+i[m]+n+"</"+j+">"+p}}else{o+=b(i[m],j,q,l)}}}else{o+=h(l)+"<"+j+"/>"+p}return o};var f=function(i,o,n,m){var k=(c.formatTextNodes)?m+h(n+2):"";var l=(c.formatTextNodes)?m+h(n+1):"";var j=h(n+1)+"<"+i+">"+k+o+l+"</"+i+">"+m;return j}})(jQuery);/*!
Online CloudFront Invalidator
Author: Seon-Wook Park
Site: http://www.swook.net/
License: http://creativecommons.org/licenses/by-nc-sa/3.0/
*/
-var cfInval={checker:{init:function(){clearInterval(cfInval.checker.Timeout);if($("#cf-invalidator .get .inprogress").length==0){return}cfInval.checker.Timeout=setInterval(function(){if($("#cf-invalidator .get .inprogress").length>0){cfInval.getInvalidationList()}},30000)},stop:function(){clearInterval(cfInval.checker.Timeout)}},invalidations:{},log:function(a){cfInvalUI.hermes.html(a);cfInvalUI.hermes.css("color","green");cfInvalUI.hermes.css("background-image","url(http://cdn.swook.net/css/info.png)");cfInvalUI.showHermes()},error:function(a){cfInvalUI.hermes.html(a);cfInvalUI.hermes.css("color","red");cfInvalUI.hermes.css("background-image","url(http://cdn.swook.net/css/alert.png)");cfInvalUI.showHermes()},loadAuth:function(){var b={};b.enablesave=$.cookie("cfi_privacy");b.enablesave=(b.enablesave)?true:false;b.accesskey=$.cookie("cfi_accesskey");b.secretkey=$.cookie("cfi_secretkey");b.cache=JSON.parse($.cookie("cfi_cache"));cfInval.auth=b;$("#cf-access > input").val(b.accesskey);$("#cf-secret > input").val(b.secretkey);if(b.cache==null){cfInval.auth.cache={}}else{var a;$.each(b.cache,function(c,d){if(!a){a=d}else{if(a.lastTime<d.lastTime){a=d}}});if(a){$("#cf-distro > input").val(a.ID)}cfInval.populateDistroAutoComplete()}},saveAuth:function(){var a=cfInval.auth;if(!a.enablesave){return}$.cookie("cfi_privacy","",{expires:-1,path:"/"});$.cookie("cfi_privacy",true,{expires:1000,path:"/"});$.cookie("cfi_accesskey","",{expires:-1,path:"/"});$.cookie("cfi_accesskey",a.accesskey,{expires:1000,path:"/"});$.cookie("cfi_secretkey","",{expires:-1,path:"/"});$.cookie("cfi_secretkey",a.secretkey,{expires:1000,path:"/"});$.cookie("cfi_cache","",{expires:-1,path:"/"});$.cookie("cfi_cache",JSON.stringify(a.cache),{expires:1000,path:"/"})},wipeAuth:function(){$.cookie("cfi_privacy","",{expires:-1,path:"/"});$.cookie("cfi_accesskey","",{expires:-1,path:"/"});$.cookie("cfi_secretkey","",{expires:-1,path:"/"});$.cookie("cfi_cache","",{expires:-1,path:"/"})},updateDistroInfo:function(){var a=$("#cf-distro > input").val();if(!a||a==""){return}if(!cfInval.auth.cache[a]){cfInval.auth.cache[a]={ID:a,paths:[],pathsLastTime:[]}}if(cfInval.auth.cache[a].paths.length!=cfInval.auth.cache[a].pathsLastTime.length){cfInval.auth.cache[a].paths=[];cfInval.auth.cache[a].pathsLastTime=[]}cfInval.auth.cache[a].lastTime=new Date().getTime();cfInval.populateDistroAutoComplete()},populateDistroAutoComplete:function(){var b=$("#distroid > select");b.html("");$.each(cfInval.auth.cache,function(c,d){if(c=="undefined"){delete cfInval.auth.cache[c]}else{b.append("<option>"+d.ID+"</option>")}});b.off("change");b.change(function(){$("#cf-distro > input").val($(this).val());if(cfInvalUI.currentPage==1){cfInval.getInvalidationList()}else{if(cfInvalUI.currentPage==2){cfInvalUI.submit.populatePastPaths()}}});var a=$("#cf-distro > input").val();if(a>""){$("option",b).each(function(c,d){if($(d).html()==a){$(d).attr("selected",true)}})}},dbDig:function(a){if(a>9){return a}else{return"0"+a}},request:function(f,i){var e=$("#cf-access > input").val(),d=$("#cf-secret > input").val(),h=$("#cf-distro > input").val();if(e==""||d==""||h==""){cfInval.error("Please fill in all details");return}var g={};g.url="https://cloudfront.amazonaws.com/2010-11-01/distribution/"+h+"/invalidation";if(i&&i.urlTail){g.url+=i.urlTail}g.date=new Date().toGMTString();g.auth="AWS "+e+":"+btoa(hex2a(Crypto.HMAC(Crypto.SHA1,utf8Encode(g.date),utf8Encode(d))));g.method=(i&&i.method)?i.method:"GET";g.yql="USE 'http://cdn.swook.net/js/cfInval.xml' AS remote; SELECT * FROM remote WHERE url='"+g.url+"' AND meth='"+g.method+"' AND auth='"+g.auth+"' AND date='"+g.date+"'";if(g.method=="POST"){g.yql+=" AND content='"+$.json2xml(i.post,{rootTagName:"InvalidationBatch"})+"'"}cfInval.query(g,f)},query:function(b,a){if(cfInval.querying){return}cfInval.querying=true;cfInval.log("Querying... Wait for this query to finish.");cfInvalUI.clicktrap.show();cfInvalUI.hermes.css("background-image","url(http://cdn.swook.net/css/loading.gif)");cfInvalUI.UI.css("cursor","progress");$.queryYQL(b.yql,"json",function(c){cfInval.querying=false;cfInval.log("Query Complete!");cfInvalUI.clicktrap.hide();cfInvalUI.UI.css("cursor","auto");console.log(c);if(!c||!c.query.results){cfInval.error("No Response. Try again in a moment.");a(null);return}c=c.query.results;if(c.result.status=="200"||c.result.status=="201"){cfInval.auth.accesskey=$("#cf-access > input").val();cfInval.auth.secretkey=$("#cf-secret > input").val();cfInval.updateDistroInfo();cfInval.saveAuth();a(c.result)}else{if(c.result.status=="400"&&c.result.html.TooManyInvalidationsInProgress){cfInval.error("Too Many Invalidations. Try later.")}else{if(c.result.status=="403"&&c.result.html.InvalidSignatureException){cfInval.error("Invalid Signature. Check your access and secret key.")}else{if(c.result.status=="404"&&c.result.html.NoSuchDistribution){cfInval.error("Invalid Distribution. Check your <a href='https://console.aws.amazon.com/cloudfront/home' target='_blank'>CloudFront Distribution ID</a>.")}else{if(c.result.status=="503"&&c.result.html.ServiceUnavailableException){cfInval.error("CloudFront Invalidation Service Unavailable. Try again later.")}else{if(c.result.status=="999"){cfInval.error("Error contacting YQL Server. Try again later.")}else{cfInval.error("Status Code: "+c.result.status+". Unknown Error: "+JSON.stringify(c.result.html)+".")}}}}}}})},querying:false,get:function(a,b){cfInval.request(a,b)},post:function(b,a){cfInval.request(b,{method:"POST",post:a})},getInvalidationList:function(a){var b="";if(a){b="?Marker="+a}clearTimeout(cfInval.getInvalidationListTimeout);cfInval.get(function(d){if(!d){cfInval.error("No response. Re-trying in 10 seconds...");cfInval.getInvalidationListTimeout=setTimeout(function(){if(cfInvalUI.currentPage==1){cfInval.getInvalidationList(a)}},10000);return}d=d.html.InvalidationList;if(!d.InvalidationSummary){return}if(typeof d.InvalidationSummary=="object"){d.InvalidationSummary=[d.InvalidationSummary]}$(".inval",cfInvalUI.page).remove();var c=function(g,f){if(f instanceof Array){$.each(f,c)}else{if(typeof f=="object"){cfInvalUI.get.addEntry(f)}}};c(0,d.InvalidationSummary);var e=$(".get .inval:first").attr("inval-id");if(cfInval.invalidations[e]&&((new Date().getTime())-cfInval.invalidations[e].lastTime<10000)){cfInvalUI.get.showInvalidation(e)}cfInval.checker.init()},{urlTail:b})},postInvalidation:function(e,d){if(!d||d==""){d=new Date().toGMTString()}var c={Path:[],CallerReference:[d]};for(var b=0,a=e.length;b<a;b++){c.Path.push(e[b])}cfInval.post(function(j){if(!j){cfInval.error("There was no reply but it might have worked. Try refreshing the list.");return}var i=cfInval.parseInvalidation(j),g=$("#cf-distro > input").val(),h=new Date(cfInval.invalidations[i].createTime).getTime(),f;$.each(cfInval.invalidations[i].paths,function(k,l){f=cfInval.auth.cache[g].paths.indexOf(l);if(f==-1){cfInval.auth.cache[g].paths.push(l);cfInval.auth.cache[g].pathsLastTime.push(h)}else{cfInval.auth.cache[g].pathsLastTime[f]=h}});if(cfInvalUI.currentPage==2){cfInvalUI.initPage(1)}else{cfInval.getInvalidationList()}$("#cf-pages").scrollTop(0)},c)},getInvalidation:function(a){if(cfInval.invalidations[a]&&((new Date().getTime())-cfInval.invalidations[a].lastTime<10000)){cfInval.error("Information was pulled less than 10 seconds ago.");return cfInvalUI.get.showInvalidation(a)}cfInval.get(function(b){if(!b){return}cfInvalUI.get.showInvalidation(cfInval.parseInvalidation(b))},{urlTail:"/"+a})},parseInvalidation:function(c){c=c.html.Invalidation;if(typeof c.InvalidationBatch.Path=="string"){c.InvalidationBatch.Path=[c.InvalidationBatch.Path]}cfInval.invalidations[c.Id]={ID:c.Id,status:c.Status,callerReference:c.InvalidationBatch.CallerReference,paths:c.InvalidationBatch.Path,createTime:c.CreateTime,lastTime:new Date().getTime()};if(c.Status=="Completed"){var d=$("#cf-distro > input").val(),a,b=new Date(cfInval.invalidations[c.Id].createTime).getTime();$.each(c.InvalidationBatch.Path,function(e,f){if(!cfInval.checkPath(f).error){a=cfInval.auth.cache[d].paths.indexOf(f);if(a==-1){cfInval.auth.cache[d].paths.push(f);cfInval.auth.cache[d].pathsLastTime.push(b)}else{if(b>cfInval.auth.cache[d].pathsLastTime[a]){cfInval.auth.cache[d].pathsLastTime[a]=b}}}});cfInval.saveAuth()}return c.Id},checkPath:function(c){var b=cfInval.parseURL(c),a;if(b.file==""){a="Directory"}if(b.relative=="/p"+cfInval.parseURL("/"+c).relative){b.path=b.path.slice(2)}if(b.path=="/p/cloudfront-invalidator.html"){a="Invalid Entry"}if($('.currentpaths .path[path="'+b.path+'"]',cfInvalUI.page).length>0){a="Duplicate Entry"}return{path:(a)?c:b.path,error:a}},parseURL:function(c){var b=document.createElement("a");b.href=c;return{source:c,protocol:b.protocol.replace(":",""),host:b.hostname,port:b.port,query:b.search,params:(function(){var e={},d=b.search.replace(/^\?/,"").split("&"),a=d.length,f=0,g;for(;f<a;f++){if(!d[f]){continue}g=d[f].split("=");e[g[0]]=g[1]}return e})(),file:(b.pathname.match(/\/([^\/?#]+)$/i)||[,""])[1],hash:b.hash.replace("#",""),path:b.pathname.replace(/^([^\/])/,"/$1"),relative:(b.href.match(/tps?:\/\/[^\/]+(.+)/)||[,""])[1],segments:b.pathname.replace(/^\//,"").split("/")}}};var cfInvalUI={init:function(){cfInvalUI.UI=$("#cf-invalidator");var a=cfInvalUI.UI;a.html("");cfInvalUI.initHermes(a);cfInvalUI.initMessages(a);cfInvalUI.initForm(a);cfInvalUI.initPrivacy(a);cfInvalUI.initTabs(a)},stop:function(){cfInval.checker.stop();clearTimeout(cfInval.getInvalidationListTimeout);clearTimeout(cfInvalUI.messageTimeout);clearTimeout(cfInvalUI.hermesTimeout)},initHermes:function(a){a.append($('<div id="cf-clicktrap"/><div id="hermes">Ready</div>'));cfInvalUI.clicktrap=$("#cf-clicktrap",a);cfInvalUI.hermes=$("#hermes",a);cfInvalUI.showHermes()},initMessages:function(a){a.append($('<div id="cf-messages"><span class="title"/><span class="desc"/></div>'));cfInvalUI.messages=$("#cf-messages",a);cfInvalUI.loadMessage()},initForm:function(a){a.append($('<div id="cf-form"><div id="cf-access"><span>Access Key ID</span><a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key#cred_block" target="_blank">Get It</a><input type="text" placeholder="Example: 0PN5J17HBGZHT7JJ3X82"/></div><div id="cf-secret"><span>Secret Access Key</span><a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key#cred_block" target="_blank">Get It</a><input type="password" placeholder="Example: /Ml61L9VxlzloZ091/lkqVV5X1/YvaJtI9hW4Wr9"/></div><div id="cf-distro"><span>Distribution ID</span><a href="https://console.aws.amazon.com/cloudfront/home" target="_blank">Get It</a><input list="distroid" type="text" placeholder="Example: E3GBU28YOG99FR" /><datalist id="distroid"><select></select></datalist></div></div>'));cfInvalUI.form=$("#cf-form",a)},initPrivacy:function(a){a.append('<div id="cf-privacy"><b>Save credentials</b> <small><em>(Is this your PC?)</em></small><input type="checkbox"></div>');cfInvalUI.cbox=$("#cf-privacy input[type=checkbox]");cfInval.loadAuth();cfInvalUI.cbox[0].checked=cfInval.auth.enablesave;if(!cfInval.auth.enablesave){cfInval.wipeAuth()}cfInvalUI.cbox.change(function(){if(!this.checked){cfInval.auth.enablesave=false;cfInval.wipeAuth()}else{cfInval.auth.enablesave=true;cfInval.saveAuth()}})},initTabs:function(a){a.append($('<div id="cf-tabs"></div>'));cfInvalUI.tabs=$("#cf-tabs",a);cfInvalUI.tabs.append($('<span class="get">Get Invalidations</span>'));cfInvalUI.tabs.append($('<span class="submit">Submit Invalidation</span>'));$(".get",cfInvalUI.tabs).on("click",function(){cfInvalUI.initPage(1)});$(".submit",cfInvalUI.tabs).on("click",function(){cfInvalUI.initPage(2)});a.append($('<div id="cf-pages"/>'));cfInvalUI.page=$("#cf-pages");cfInvalUI.initPage()},initPage:function(a){if(!a){a=1}else{if(cfInvalUI.currentPage==a){return}}cfInvalUI.clicktrap.css("cursor","progress");$("span",cfInvalUI.tabs).css("background-color","#F1F1F1");if(a==1){cfInvalUI.page.html("");cfInvalUI.page.html('<div class="instruction">Select an entry for more information.</div><div class="refresh">Refresh List</div><div class="get"/>');$(".refresh",cfInvalUI.page).on("click",function(){cfInval.getInvalidationList()});$(".get",cfInvalUI.tabs).css("background-color","white");if($("#cf-access > input").val()!=""&&$("#cf-secret > input").val()!=""&&$("#cf-distro > input").val()!=""){cfInval.getInvalidationList()}}else{if(a==2){clearTimeout(cfInval.getInvalidationListTimeout);cfInval.checker.stop();cfInvalUI.page.html("");cfInvalUI.page.html('<div class="post"><div class="toolbar"><div class="addall">Add All</div><div class="removeall">Remove All</div><div class="submit">Submit</div></div><div class="pastpaths"><h2>Paths you used before</h2></div><div class="currentpaths"><h2>Paths To Invalidate</h2></div></div>');$(".submit",cfInvalUI.tabs).css("background-color","white");cfInvalUI.submit.initToolbar();cfInvalUI.submit.populatePastPaths();cfInvalUI.submit.newEntry()}}cfInvalUI.currentPage=a;cfInvalUI.UI.css("cursor","auto")},get:{addEntry:function(d){var a=d.Status.toLowerCase();if(d.Status=="InProgress"){d.Status="In Progress"}$(".get",cfInvalUI.page).append($('<div class="inval '+a+'" inval-id="'+d.Id+'"><span class="inval-ID" title="Invalidation ID">'+d.Id+'</span><span class="inval-Status" title="Invalidation Status">'+d.Status+"</span></div>"));var b=$('.inval[inval-id="'+d.Id+'"]',cfInvalUI.page),c=$("span.inval-Status",b);switch(d.Status){case"In Progress":c.css("color","red");break;case"Completed":c.css("color","green");break}b.on("click",function(){var f=$(this),e=$("table",f);if(e.length>0){e.remove();$(".refresh",f).remove();$(".resubmit",f).remove()}else{cfInval.getInvalidation(f.attr("inval-id"))}})},showInvalidation:function(d){var a=$(".inval[inval-id="+d+"]",cfInvalUI.page),c=cfInval.invalidations[d],b=$("span.inval-Status",a);$(".inval .refresh",cfInvalUI.page).remove();$(".inval table",cfInvalUI.page).remove();$(".inval .resubmit",cfInvalUI.page).remove();a.addClass(c.status);switch(c.status){case"InProgress":b.html("In Progress");b.css("color","red");break;case"Completed":b.html("Completed");b.css("color","green");break}a.append('<div class="refresh" title="Refresh Information"/><table><tr><td><b>Paths</b></td><td><ul></ul></td></tr><tr><td><b>Created</b></td><td title="'+c.createTime+'"></td></tr><tr><td><b>Reference</b></td><td>'+c.callerReference+'</td></tr></table><div class="resubmit">Submit this Invalidation again</div></div>');$('td[title="'+c.createTime+'"]',a).timeago();$("table",a).on("click",function(f){f.stopPropagation()});$(".refresh",a).on("click",function(f){f.stopPropagation();cfInval.getInvalidation(d)});$("div.resubmit",a).on("click",function(g){g.stopPropagation();var f=[];$("li",a).each(function(e,h){f.push(h.innerHTML)});cfInval.postInvalidation(f)});a=$("ul",a);$.each(c.paths,function(e,f){if(e<4){a.append("<li>"+f+"</li>")}else{if(e==4){a.append('<li class="showmore">Show More</li>');$("li.showmore",a).on("click",function(){var g=$(this);$("li.hidden",g.parent()).removeClass("hidden");g.remove()});a.append('<li class="hidden">'+f+"</li>")}else{a.append('<li class="hidden">'+f+"</li>")}}})}},submit:{initToolbar:function(){var a=$(".post .toolbar",cfInvalUI.page);$(".addall",a).on("click",function(){$(".pastpaths .entry").trigger("click");cfInvalUI.submit.populatePastPaths()});$(".removeall",a).on("click",function(){$(".currentpaths .path:not(.new-entry)").remove();cfInvalUI.submit.populatePastPaths()});$(".submit",a).on("click",function(){var b=[];$(".currentpaths .path:not(.invalid, .new-entry)").each(function(c,d){b.push($(d).attr("path"))});if(b.length==0){return cfInval.error("Please add paths to invalidate")}else{cfInval.postInvalidation(b)}})},populatePastPaths:function(){var b=$("#cf-distro > input").val(),a=$(".pastpaths",cfInvalUI.page);$("div",a).remove();if(b==""||!(b in cfInval.auth.cache)||cfInval.auth.cache[b].paths.length==0){$("h2",a).hide();return}$.each(cfInval.auth.cache[b].paths,function(c,d){if($('.currentpaths .path[path="'+d+'"]',cfInvalUI.page).length>0){return}a.append($('<div class="entry" path="'+d+'" lastTime="'+cfInval.auth.cache[b].pathsLastTime[c]+'">'+d+'<span class="timeago">'+$.timeago(new Date(cfInval.auth.cache[b].pathsLastTime[c]))+"</span></div>"))});if($("div",a).length==0){$("h2",a).hide()}else{$("h2",a).show();$(".entry",a).sortElements(function(d,c){return parseInt($(c).attr("lastTime"))-parseInt($(d).attr("lastTime"))}).each(function(c,d){$(d).on("click",cfInvalUI.submit.addEntryFromPast)})}},newEntry:function(){$(".currentpaths .new-entry",cfInvalUI.page).removeClass("new-entry");var a=$(".new-entry",$(".currentpaths",cfInvalUI.page).append($('<div class="path new-entry"><input type="text" placeholder="Enter Path"/><span class="add">Add Path</span><span class="error"/></div>')));$("input",a).on("paste",function(){var b=$(this);setTimeout(function(){var c=b.val().split(/\r\n|\n/);$.each(c,function(d,e){if(d==c.length-1){$(".currentpaths input:enabled",cfInvalUI.page).val(e)}else{$(".currentpaths input:enabled",cfInvalUI.page).val(e);cfInvalUI.submit.addEntry()}})},100)}).keydown(function(b){if(b.keyCode!=13&&b.keyCode!=9){return}b.preventDefault();cfInvalUI.submit.addEntry()}).focus();$("span.add",a).on("click",function(b){b.stopPropagation();cfInvalUI.submit.addEntry()})},addEntry:function(){var e=$(".currentpaths input:enabled",cfInvalUI.page),d=e.parent(),f=e.val();if(f==""){return}var c=cfInval.checkPath(f);if(f.indexOf("*")>-1){var b=0,a=new RegExp("^"+f.replace(/\./g,".").replace(/\*/g,".*")+"$");$(".pastpaths .entry",cfInvalUI.page).each(function(h,j){var g=$(j);if(g.attr("path").match(a)){g.click();b++}});if(b>0){return $(".currentpaths input:enabled").val("")}else{c.error="No matches from history"}}cfInvalUI.submit.disableEntry(e,d,c.path);if(c.error>""){$("span.error",d).html(c.error);d.addClass("invalid")}else{$('.pastpaths .entry[path="'+c.path+'"]',cfInvalUI.page).remove()}cfInvalUI.submit.newEntry()},disableEntry:function(a,b,c){a.attr("disabled","disabled").val(c);b.prepend($('<img class ="delete" title="Remove Path" src="http://cdn.swook.net/css/delete.png"/>'));$(".delete",b).on("click",function(d){$(this).parent().remove();cfInvalUI.submit.populatePastPaths()});b.attr("path",c)},addEntryFromPast:function(){var d=$(this).attr("path"),c=$(".currentpaths input:enabled",cfInvalUI.page),b=c.parent(),a=c.val();cfInvalUI.submit.disableEntry(c,b,d);$('.pastpaths .entry[path="'+d+'"]',cfInvalUI.page).remove();cfInvalUI.submit.newEntry();if(a>""){$(".currentpaths input:enabled").val(a)}}},showHermes:function(){if(cfInvalUI.hermesTimeout){clearTimeout(cfInvalUI.hermesTimeout)}cfInvalUI.hermesTimeout=setTimeout(function(){if(cfInval.querying){return cfInvalUI.showHermes()}cfInvalUI.hermes.html('<b>Online CloudFront Invalidator</b> <i><small>by <a href="/p/about.html"">Seon-Wook Park</a></small></i>');cfInvalUI.hermes.css("color","black");cfInvalUI.hermes.css("background-image","none");$("a",cfInvalUI.hermes).each($.Ajaxify.applyTo)},6000)},messageList:[{title:"Welcome",desc:"I hope you enjoy using the Online CloudFront Invalidator. This app is a safe and easy way of invalidating your CloudFront files."},{title:"Secure",desc:"This is probably the most secure invalidator. Your access and secret key are not leaked anywhere and all requests are done via HTTPS."},{title:"Invalidations",desc:"Note that invalidations take around 15-20 minutes to complete. Check if you have requested one before requesting a new one!"},{title:"JavaScript = Fast &amp; Secure",desc:"This app will never slow down because of the number of users. I will also never receive any AWS data from you."},{title:"Any Problems?",desc:"If you experienced any issues with this app, comment below or <a href='mailto:seon.wook@swook.net'>send me an e-mail</a>!"},{title:"Support Me",desc:"If you liked my app, please share this page with your friends and co-workers. It would really be appreciated!"}],loadMessage:function(){if(cfInvalUI.messageCurrent==null||cfInvalUI.messageCurrent>=(cfInvalUI.messageList.length-1)){cfInvalUI.messageCurrent=0}else{cfInvalUI.messageCurrent++}$("span.title",cfInvalUI.messages).html(cfInvalUI.messageList[cfInvalUI.messageCurrent].title);$("span.desc",cfInvalUI.messages).html(cfInvalUI.messageList[cfInvalUI.messageCurrent].desc);$("a[target!=blank_]",cfInvalUI.messages).each($.Ajaxify.applyTo);cfInvalUI.messageTimeout=setTimeout(cfInvalUI.loadMessage,25000)},};jQuery.fn.sortElements=(function(){var a=[].sort;return function(c,d){d=d||function(){return this};var b=this.map(function(){var f=d.call(this),e=f.parentNode,g=e.insertBefore(document.createTextNode(""),f.nextSibling);return function(){if(e===this){throw new Error("You can't sort elements if any one is a descendant of another.")}e.insertBefore(this,g);e.removeChild(g)}});return a.call(this,c).each(function(e){b[e].call(d.call(this))})}})();chr=function(a){return String.fromCharCode(a)};code2utf=function(a){if(a<128){return chr(a)}if(a<2048){return chr(192+(a>>6))+chr(128+(a&63))}if(a<65536){return chr(224+(a>>12))+chr(128+((a>>6)&63))+chr(128+(a&63))}if(a<2097152){return chr(240+(a>>18))+chr(128+((a>>12)&63))+chr(128+((a>>6)&63))+chr(128+(a&63))}};_utf8Encode=function(c){var b=new Array();for(var a=0;a<c.length;a++){b[a]=code2utf(c.charCodeAt(a))}return b.join("")};utf8Encode=function(d){var c=new Array();var e,b=0;var a="";while((e=d.search(/[^\x00-\x7F]/))!=-1){a=d.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0];c[b++]=d.substr(0,e);c[b++]=_utf8Encode(a);d=d.substr(e+a.length)}c[b++]=d;return c.join("")};function hex2a(b){var c="";for(var a=0;a<b.length;a+=2){c+=String.fromCharCode(parseInt(b.substr(a,2),16))}return c}cfInvalUI.init();
+var cfInval={checker:{init:function(){clearInterval(cfInval.checker.Timeout);if($("#cf-invalidator .get .inprogress").length==0){return}cfInval.checker.Timeout=setInterval(function(){if($("#cf-invalidator .get .inprogress").length>0){cfInval.getInvalidationList()}},30000)},stop:function(){clearInterval(cfInval.checker.Timeout)}},invalidations:{},log:function(a){cfInvalUI.hermes.html(a);cfInvalUI.hermes.css("color","green");cfInvalUI.hermes.css("background-image","url(http://cdn.swook.net/css/info.png)");cfInvalUI.showHermes()},error:function(a){cfInvalUI.hermes.html(a);cfInvalUI.hermes.css("color","red");cfInvalUI.hermes.css("background-image","url(http://cdn.swook.net/css/alert.png)");cfInvalUI.showHermes()},loadAuth:function(){var b={};b.enablesave=$.cookie("cfi_privacy");b.enablesave=(b.enablesave)?true:false;b.accesskey=$.cookie("cfi_accesskey");b.secretkey=$.cookie("cfi_secretkey");b.cache=JSON.parse($.cookie("cfi_cache"));cfInval.auth=b;$("#cf-access > input").val(b.accesskey);$("#cf-secret > input").val(b.secretkey);if(b.cache==null){cfInval.auth.cache={}}else{var a;$.each(b.cache,function(c,d){if(!a){a=d}else{if(a.lastTime<d.lastTime){a=d}}});if(a){$("#cf-distro > input").val(a.ID)}cfInval.populateDistroAutoComplete()}},saveAuth:function(){var a=cfInval.auth;if(!a.enablesave){return}$.cookie("cfi_privacy","",{expires:-1,path:"/"});$.cookie("cfi_privacy",true,{expires:1000,path:"/"});$.cookie("cfi_accesskey","",{expires:-1,path:"/"});$.cookie("cfi_accesskey",a.accesskey,{expires:1000,path:"/"});$.cookie("cfi_secretkey","",{expires:-1,path:"/"});$.cookie("cfi_secretkey",a.secretkey,{expires:1000,path:"/"});$.cookie("cfi_cache","",{expires:-1,path:"/"});$.cookie("cfi_cache",JSON.stringify(a.cache),{expires:1000,path:"/"})},wipeAuth:function(){$.cookie("cfi_privacy","",{expires:-1,path:"/"});$.cookie("cfi_accesskey","",{expires:-1,path:"/"});$.cookie("cfi_secretkey","",{expires:-1,path:"/"});$.cookie("cfi_cache","",{expires:-1,path:"/"})},updateDistroInfo:function(){var a=$("#cf-distro > input").val();if(!a||a==""){return}if(!cfInval.auth.cache[a]){cfInval.auth.cache[a]={ID:a,paths:[],pathsLastTime:[]}}if(cfInval.auth.cache[a].paths.length!=cfInval.auth.cache[a].pathsLastTime.length){cfInval.auth.cache[a].paths=[];cfInval.auth.cache[a].pathsLastTime=[]}cfInval.auth.cache[a].lastTime=new Date().getTime();cfInval.populateDistroAutoComplete()},populateDistroAutoComplete:function(){var b=$("#distroid > select");b.html("");$.each(cfInval.auth.cache,function(c,d){if(c=="undefined"){delete cfInval.auth.cache[c]}else{b.append("<option>"+d.ID+"</option>")}});b.off("change");b.change(function(){$("#cf-distro > input").val($(this).val());if(cfInvalUI.currentPage==1){cfInval.getInvalidationList()}else{if(cfInvalUI.currentPage==2){cfInvalUI.submit.populatePastPaths()}}});var a=$("#cf-distro > input").val();if(a>""){$("option",b).each(function(c,d){if($(d).html()==a){$(d).attr("selected",true)}})}},dbDig:function(a){if(a>9){return a}else{return"0"+a}},request:function(f,i){var e=$("#cf-access > input").val(),d=$("#cf-secret > input").val(),h=$("#cf-distro > input").val();if(e==""||d==""||h==""){cfInval.error("Please fill in all details");return}var g={};g.url="https://cloudfront.amazonaws.com/2010-11-01/distribution/"+h+"/invalidation";if(i&&i.urlTail){g.url+=i.urlTail}g.date=new Date().toGMTString();g.auth="AWS "+e+":"+btoa(hex2a(Crypto.HMAC(Crypto.SHA1,utf8Encode(g.date),utf8Encode(d))));g.method=(i&&i.method)?i.method:"GET";g.yql="USE 'http://cdn.swook.net/js/cfInval.xml' AS remote; SELECT * FROM remote WHERE url='"+g.url+"' AND meth='"+g.method+"' AND auth='"+g.auth+"' AND date='"+g.date+"'";if(g.method=="POST"){g.yql+=" AND content='"+$.json2xml(i.post,{rootTagName:"InvalidationBatch"})+"'"}cfInval.query(g,f)},query:function(b,a){if(cfInval.querying){return}cfInval.querying=true;cfInval.log("Querying... Wait for this query to finish.");cfInvalUI.clicktrap.show();cfInvalUI.hermes.css("background-image","url(http://cdn.swook.net/css/loading.gif)");cfInvalUI.UI.css("cursor","progress");$.queryYQL(b.yql,"json",function(c){cfInval.querying=false;cfInval.log("Query Complete!");cfInvalUI.clicktrap.hide();cfInvalUI.UI.css("cursor","auto");console.log(c);if(!c||!c.query.results){cfInval.error("No Response. Try again in a moment.");a(null);return}c=c.query.results;if(c.result.status=="200"||c.result.status=="201"){cfInval.auth.accesskey=$("#cf-access > input").val();cfInval.auth.secretkey=$("#cf-secret > input").val();cfInval.updateDistroInfo();cfInval.saveAuth();a(c.result)}else{if(c.result.status=="400"&&c.result.html.TooManyInvalidationsInProgress){cfInval.error("Too Many Invalidations. Try later.")}else{if(c.result.status=="403"&&c.result.html.InvalidSignatureException){cfInval.error("Invalid Signature. Check your access and secret key.")}else{if(c.result.status=="404"&&c.result.html.NoSuchDistribution){cfInval.error("Invalid Distribution. Check your <a href='https://console.aws.amazon.com/cloudfront/home' target='_blank'>CloudFront Distribution ID</a>.")}else{if(c.result.status=="503"&&c.result.html.ServiceUnavailableException){cfInval.error("CloudFront Invalidation Service Unavailable. Try again later.")}else{if(c.result.status=="999"){cfInval.error("Error contacting YQL Server. Try again later.")}else{cfInval.error("Status Code: "+c.result.status+". Unknown Error: "+JSON.stringify(c.result.html)+".")}}}}}}})},querying:false,get:function(a,b){cfInval.request(a,b)},post:function(b,a){cfInval.request(b,{method:"POST",post:a})},getInvalidationList:function(a){var b="";if(a){b="?Marker="+a}clearTimeout(cfInval.getInvalidationListTimeout);cfInval.get(function(d){if(!d){cfInval.error("No response. Re-trying in 10 seconds...");cfInval.getInvalidationListTimeout=setTimeout(function(){if(cfInvalUI.currentPage==1){cfInval.getInvalidationList(a)}},10000);return}d=d.html.InvalidationList;if(!d.InvalidationSummary){return}if(typeof d.InvalidationSummary=="object"){d.InvalidationSummary=[d.InvalidationSummary]}$(".inval",cfInvalUI.page).remove();var c=function(g,f){if(f instanceof Array){$.each(f,c)}else{if(typeof f=="object"){cfInvalUI.get.addEntry(f)}}};c(0,d.InvalidationSummary);var e=$(".get .inval:first").attr("inval-id");if(cfInval.invalidations[e]&&((new Date().getTime())-cfInval.invalidations[e].lastTime<10000)){cfInvalUI.get.showInvalidation(e)}cfInval.checker.init()},{urlTail:b})},postInvalidation:function(e,d){if(!d||d==""){d=new Date().toGMTString()}var c={Path:[],CallerReference:[d]};for(var b=0,a=e.length;b<a;b++){c.Path.push(e[b])}cfInval.post(function(j){if(!j){cfInval.error("There was no reply but it might have worked. Try refreshing the list.");return}var i=cfInval.parseInvalidation(j),g=$("#cf-distro > input").val(),h=new Date(cfInval.invalidations[i].createTime).getTime(),f;$.each(cfInval.invalidations[i].paths,function(k,l){f=cfInval.auth.cache[g].paths.indexOf(l);if(f==-1){cfInval.auth.cache[g].paths.push(l);cfInval.auth.cache[g].pathsLastTime.push(h)}else{cfInval.auth.cache[g].pathsLastTime[f]=h}});if(cfInvalUI.currentPage==2){cfInvalUI.initPage(1)}else{cfInval.getInvalidationList()}$("#cf-pages").scrollTop(0)},c)},getInvalidation:function(a){if(cfInval.invalidations[a]&&((new Date().getTime())-cfInval.invalidations[a].lastTime<10000)){cfInval.error("Information was pulled less than 10 seconds ago.");return cfInvalUI.get.showInvalidation(a)}cfInval.get(function(b){if(!b){return}cfInvalUI.get.showInvalidation(cfInval.parseInvalidation(b))},{urlTail:"/"+a})},parseInvalidation:function(c){c=c.html.Invalidation;if(typeof c.InvalidationBatch.Path=="string"){c.InvalidationBatch.Path=[c.InvalidationBatch.Path]}cfInval.invalidations[c.Id]={ID:c.Id,status:c.Status,callerReference:c.InvalidationBatch.CallerReference,paths:c.InvalidationBatch.Path,createTime:c.CreateTime,lastTime:new Date().getTime()};if(c.Status=="Completed"){var d=$("#cf-distro > input").val(),a,b=new Date(cfInval.invalidations[c.Id].createTime).getTime();$.each(c.InvalidationBatch.Path,function(e,f){if(!cfInval.checkPath(f).error){a=cfInval.auth.cache[d].paths.indexOf(f);if(a==-1){cfInval.auth.cache[d].paths.push(f);cfInval.auth.cache[d].pathsLastTime.push(b)}else{if(b>cfInval.auth.cache[d].pathsLastTime[a]){cfInval.auth.cache[d].pathsLastTime[a]=b}}}});cfInval.saveAuth()}return c.Id},checkPath:function(c){var b=cfInval.parseURL(c),a;if(b.file==""){a="Directory"}if(b.relative=="/p"+cfInval.parseURL("/"+c).relative){b.path=b.path.slice(2)}if(b.path=="/p/cloudfront-invalidator.html"){a="Invalid Entry"}if($('.currentpaths .path[path="'+b.path+'"]',cfInvalUI.page).length>0){a="Duplicate Entry"}return{path:(a)?c:b.path,error:a}},parseURL:function(c){var b=document.createElement("a");b.href=c;return{source:c,protocol:b.protocol.replace(":",""),host:b.hostname,port:b.port,query:b.search,params:(function(){var e={},d=b.search.replace(/^\?/,"").split("&"),a=d.length,f=0,g;for(;f<a;f++){if(!d[f]){continue}g=d[f].split("=");e[g[0]]=g[1]}return e})(),file:(b.pathname.match(/\/([^\/?#]+)$/i)||[,""])[1],hash:b.hash.replace("#",""),path:b.pathname.replace(/^([^\/])/,"/$1"),relative:(b.href.match(/tps?:\/\/[^\/]+(.+)/)||[,""])[1],segments:b.pathname.replace(/^\//,"").split("/")}}};var cfInvalUI={init:function(){cfInvalUI.UI=$("#cf-invalidator");var a=cfInvalUI.UI;a.html("");cfInvalUI.initHermes(a);cfInvalUI.initMessages(a);cfInvalUI.initForm(a);cfInvalUI.initPrivacy(a);cfInvalUI.initTabs(a)},stop:function(){cfInval.checker.stop();clearTimeout(cfInval.getInvalidationListTimeout);clearTimeout(cfInvalUI.messageTimeout);clearTimeout(cfInvalUI.hermesTimeout)},initHermes:function(a){a.append($('<div id="cf-clicktrap"/><div id="hermes">Ready</div>'));cfInvalUI.clicktrap=$("#cf-clicktrap",a);cfInvalUI.hermes=$("#hermes",a);cfInvalUI.showHermes()},initMessages:function(a){a.append($('<div id="cf-messages"><span class="title"/><span class="desc"/></div>'));cfInvalUI.messages=$("#cf-messages",a);cfInvalUI.loadMessage()},initForm:function(a){a.append($('<div id="cf-form"><div id="cf-access"><span>Access Key ID</span><a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key#cred_block" target="_blank">Get It</a><input type="text" placeholder="Example: 0PN5J17HBGZHT7JJ3X82"/></div><div id="cf-secret"><span>Secret Access Key</span><a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key#cred_block" target="_blank">Get It</a><input type="password" placeholder="Example: /Ml61L9VxlzloZ091/lkqVV5X1/YvaJtI9hW4Wr9"/></div><div id="cf-distro"><span>Distribution ID</span><a href="https://console.aws.amazon.com/cloudfront/home" target="_blank">Get It</a><input list="distroid" type="text" placeholder="Example: E3GBU28YOG99FR" /><datalist id="distroid"><select></select></datalist></div></div>'));cfInvalUI.form=$("#cf-form",a)},initPrivacy:function(a){a.append('<div id="cf-privacy"><b>Save credentials</b> <small><em>(Is this your PC?)</em></small><input type="checkbox"></div>');cfInvalUI.cbox=$("#cf-privacy input[type=checkbox]");cfInval.loadAuth();cfInvalUI.cbox[0].checked=cfInval.auth.enablesave;if(!cfInval.auth.enablesave){cfInval.wipeAuth()}cfInvalUI.cbox.change(function(){if(!this.checked){cfInval.auth.enablesave=false;cfInval.wipeAuth()}else{cfInval.auth.enablesave=true;cfInval.saveAuth()}})},initTabs:function(a){a.append($('<div id="cf-tabs"></div>'));cfInvalUI.tabs=$("#cf-tabs",a);cfInvalUI.tabs.append($('<span class="get">Get Invalidations</span>'));cfInvalUI.tabs.append($('<span class="submit">Submit Invalidation</span>'));$(".get",cfInvalUI.tabs).on("click",function(){cfInvalUI.initPage(1)});$(".submit",cfInvalUI.tabs).on("click",function(){cfInvalUI.initPage(2)});a.append($('<div id="cf-pages"/>'));cfInvalUI.page=$("#cf-pages");cfInvalUI.initPage()},initPage:function(a){if(!a){a=1}else{if(cfInvalUI.currentPage==a){return}}cfInvalUI.clicktrap.css("cursor","progress");$("span",cfInvalUI.tabs).css("background-color","#F1F1F1");if(a==1){cfInvalUI.page.html("");cfInvalUI.page.html('<div class="instruction">Select an entry for more information.</div><div class="refresh">Refresh List</div><div class="get"/>');$(".refresh",cfInvalUI.page).on("click",function(){cfInval.getInvalidationList()});$(".get",cfInvalUI.tabs).css("background-color","white");if($("#cf-access > input").val()!=""&&$("#cf-secret > input").val()!=""&&$("#cf-distro > input").val()!=""){cfInval.getInvalidationList()}}else{if(a==2){clearTimeout(cfInval.getInvalidationListTimeout);cfInval.checker.stop();cfInvalUI.page.html("");cfInvalUI.page.html('<div class="post"><div class="toolbar"><div class="addall">Add All</div><div class="removeall">Remove All</div><div class="submit">Submit</div></div><div class="pastpaths"><h2>Paths you used before</h2></div><div class="currentpaths"><h2>Paths To Invalidate</h2></div></div>');$(".submit",cfInvalUI.tabs).css("background-color","white");cfInvalUI.submit.initToolbar();cfInvalUI.submit.populatePastPaths();cfInvalUI.submit.newEntry()}}cfInvalUI.currentPage=a;cfInvalUI.UI.css("cursor","auto")},get:{addEntry:function(d){var a=d.Status.toLowerCase();if(d.Status=="InProgress"){d.Status="In Progress"}$(".get",cfInvalUI.page).append($('<div class="inval '+a+'" inval-id="'+d.Id+'"><span class="inval-ID" title="Invalidation ID">'+d.Id+'</span><span class="inval-Status" title="Invalidation Status">'+d.Status+"</span></div>"));var b=$('.inval[inval-id="'+d.Id+'"]',cfInvalUI.page),c=$("span.inval-Status",b);switch(d.Status){case"In Progress":c.css("color","red");break;case"Completed":c.css("color","green");break}b.on("click",function(){var f=$(this),e=$("table",f);if(e.length>0){e.remove();$(".refresh",f).remove();$(".resubmit",f).remove()}else{cfInval.getInvalidation(f.attr("inval-id"))}})},showInvalidation:function(d){var a=$(".inval[inval-id="+d+"]",cfInvalUI.page),c=cfInval.invalidations[d],b=$("span.inval-Status",a);$(".inval .refresh",cfInvalUI.page).remove();$(".inval table",cfInvalUI.page).remove();$(".inval .resubmit",cfInvalUI.page).remove();a.addClass(c.status);switch(c.status){case"InProgress":b.html("In Progress");b.css("color","red");break;case"Completed":b.html("Completed");b.css("color","green");break}a.append('<div class="refresh" title="Refresh Information"/><table><tr><td><b>Paths</b></td><td><ul></ul></td></tr><tr><td><b>Created</b></td><td title="'+c.createTime+'"></td></tr><tr><td><b>Reference</b></td><td>'+c.callerReference+'</td></tr></table><div class="resubmit">Submit this Invalidation again</div></div>');$('td[title="'+c.createTime+'"]',a).timeago();$("table",a).on("click",function(f){f.stopPropagation()});$(".refresh",a).on("click",function(f){f.stopPropagation();cfInval.getInvalidation(d)});$("div.resubmit",a).on("click",function(g){g.stopPropagation();var f=[];$("li",a).each(function(e,h){f.push(h.innerHTML)});cfInval.postInvalidation(f)});a=$("ul",a);$.each(c.paths,function(e,f){if(e<4){a.append("<li>"+f+"</li>")}else{if(e==4){a.append('<li class="showmore">Show More</li>');$("li.showmore",a).on("click",function(){var g=$(this);$("li.hidden",g.parent()).removeClass("hidden");g.remove()});a.append('<li class="hidden">'+f+"</li>")}else{a.append('<li class="hidden">'+f+"</li>")}}})}},submit:{initToolbar:function(){var a=$(".post .toolbar",cfInvalUI.page);$(".addall",a).on("click",function(){$(".pastpaths .entry").trigger("click");cfInvalUI.submit.populatePastPaths()});$(".removeall",a).on("click",function(){$(".currentpaths .path:not(.new-entry)").remove();cfInvalUI.submit.populatePastPaths()});$(".submit",a).on("click",function(){var b=[];$(".currentpaths .path:not(.invalid, .new-entry)").each(function(c,d){b.push($(d).attr("path"))});if(b.length==0){return cfInval.error("Please add paths to invalidate")}else{cfInval.postInvalidation(b)}})},populatePastPaths:function(){var b=$("#cf-distro > input").val(),a=$(".pastpaths",cfInvalUI.page);$("div",a).remove();if(b==""||!(b in cfInval.auth.cache)||cfInval.auth.cache[b].paths.length==0){$("h2",a).hide();return}$.each(cfInval.auth.cache[b].paths,function(c,d){if($('.currentpaths .path[path="'+d+'"]',cfInvalUI.page).length>0){return}a.append($('<div class="entry" path="'+d+'" lastTime="'+cfInval.auth.cache[b].pathsLastTime[c]+'">'+d+'<span class="timeago">'+$.timeago(new Date(cfInval.auth.cache[b].pathsLastTime[c]))+"</span></div>"))});if($("div",a).length==0){$("h2",a).hide()}else{$("h2",a).show();$(".entry",a).sortElements(function(d,c){return parseInt($(c).attr("lastTime"))-parseInt($(d).attr("lastTime"))}).each(function(c,d){$(d).on("click",cfInvalUI.submit.addEntryFromPast)})}},newEntry:function(){$(".currentpaths .new-entry",cfInvalUI.page).removeClass("new-entry");var a=$(".new-entry",$(".currentpaths",cfInvalUI.page).append($('<div class="path new-entry"><input type="text" placeholder="Enter Path"/><span class="add">Add Path</span><span class="error"/></div>')));$("input",a).on("paste",function(){var b=$(this);setTimeout(function(){var c=b.val().split(/\r\n|\n/);$.each(c,function(d,e){if(d==c.length-1){$(".currentpaths input:enabled",cfInvalUI.page).val(e)}else{$(".currentpaths input:enabled",cfInvalUI.page).val(e);cfInvalUI.submit.addEntry()}})},100)}).keydown(function(b){if(b.keyCode!=13&&b.keyCode!=9){return}b.preventDefault();cfInvalUI.submit.addEntry()}).focus();$("span.add",a).on("click",function(b){b.stopPropagation();cfInvalUI.submit.addEntry()})},addEntry:function(){var e=$(".currentpaths input:enabled",cfInvalUI.page),d=e.parent(),f=e.val();if(f==""){return}var c=cfInval.checkPath(f);if(f.indexOf("*")>-1){var b=0,a=new RegExp("^"+f.replace(/\./g,".").replace(/\*/g,".*")+"$");$(".pastpaths .entry",cfInvalUI.page).each(function(h,j){var g=$(j);if(g.attr("path").match(a)){g.click();b++}});if(b>0){return $(".currentpaths input:enabled").val("")}else{c.error="No matches from history"}}cfInvalUI.submit.disableEntry(e,d,c.path);if(c.error>""){$("span.error",d).html(c.error);d.addClass("invalid")}else{$('.pastpaths .entry[path="'+c.path+'"]',cfInvalUI.page).remove()}cfInvalUI.submit.newEntry()},disableEntry:function(a,b,c){a.attr("disabled","disabled").val(c);b.prepend($('<img class ="delete" title="Remove Path" src="http://cdn.swook.net/css/delete.png"/>'));$(".delete",b).on("click",function(d){$(this).parent().remove();cfInvalUI.submit.populatePastPaths()});b.attr("path",c)},addEntryFromPast:function(){var d=$(this).attr("path"),c=$(".currentpaths input:enabled",cfInvalUI.page),b=c.parent(),a=c.val();cfInvalUI.submit.disableEntry(c,b,d);$('.pastpaths .entry[path="'+d+'"]',cfInvalUI.page).remove();cfInvalUI.submit.newEntry();if(a>""){$(".currentpaths input:enabled").val(a)}}},showHermes:function(){if(cfInvalUI.hermesTimeout){clearTimeout(cfInvalUI.hermesTimeout)}cfInvalUI.hermesTimeout=setTimeout(function(){if(cfInval.querying){return cfInvalUI.showHermes()}cfInvalUI.hermes.html('<b>Online CloudFront Invalidator</b> <i><small>by <a href="/p/about.html"">Seon-Wook Park</a></small></i>');cfInvalUI.hermes.css("color","black");cfInvalUI.hermes.css("background-image","none");$("a",cfInvalUI.hermes).each($.Ajaxify.applyTo)},6000)},messageList:[{title:"Welcome",desc:"I hope you enjoy using the Online CloudFront Invalidator. This app is a safe and easy way of invalidating your CloudFront files."},{title:"Secure",desc:"This is probably the most secure invalidator. Your access and secret key are not leaked anywhere and all requests are done via HTTPS."},{title:"Invalidations",desc:"Note that invalidations take around 15-20 minutes to complete. Check if you have requested one before requesting a new one!"},{title:"JavaScript = Fast &amp; Secure",desc:"This app will never slow down because of the number of users. I will also never receive any AWS data from you."},{title:"Any Problems?",desc:"If you experienced any issues with this app, comment below or <a href='mailto:seon.wook@swook.net'>send me an e-mail</a>!"},{title:"Support Me",desc:"If you liked my app, please share this page with your friends and co-workers. It would really be appreciated!"}],loadMessage:function(){if(cfInvalUI.messageCurrent==null||cfInvalUI.messageCurrent>=(cfInvalUI.messageList.length-1)){cfInvalUI.messageCurrent=0}else{cfInvalUI.messageCurrent++}$("span.title",cfInvalUI.messages).html(cfInvalUI.messageList[cfInvalUI.messageCurrent].title);$("span.desc",cfInvalUI.messages).html(cfInvalUI.messageList[cfInvalUI.messageCurrent].desc);$("a[target!=blank_]",cfInvalUI.messages).each($.Ajaxify.applyTo);cfInvalUI.messageTimeout=setTimeout(cfInvalUI.loadMessage,25000)},};$.cookie=function(f,e,j){if(arguments.length>1&&(!/Object/.test(Object.prototype.toString.call(e))||e===null||e===undefined)){j=$.extend({},j);if(e===null||e===undefined){j.expires=-1}if(typeof j.expires==="number"){var g=j.expires,h=j.expires=new Date();h.setDate(h.getDate()+g)}e=String(e);return(document.cookie=[encodeURIComponent(f),"=",j.raw?e:encodeURIComponent(e),j.expires?"; expires="+j.expires.toUTCString():"",j.path?"; path="+j.path:"",j.domain?"; domain="+j.domain:"",j.secure?"; secure":""].join(""))}j=e||{};var a=j.raw?function(i){return i}:decodeURIComponent;var b=document.cookie.split("; ");for(var d=0,c;c=b[d]&&b[d].split("=");d++){if(a(c[0])===f){return a(c[1]||"")}}return null};jQuery.fn.sortElements=(function(){var a=[].sort;return function(c,d){d=d||function(){return this};var b=this.map(function(){var f=d.call(this),e=f.parentNode,g=e.insertBefore(document.createTextNode(""),f.nextSibling);return function(){if(e===this){throw new Error("You can't sort elements if any one is a descendant of another.")}e.insertBefore(this,g);e.removeChild(g)}});return a.call(this,c).each(function(e){b[e].call(d.call(this))})}})();chr=function(a){return String.fromCharCode(a)};code2utf=function(a){if(a<128){return chr(a)}if(a<2048){return chr(192+(a>>6))+chr(128+(a&63))}if(a<65536){return chr(224+(a>>12))+chr(128+((a>>6)&63))+chr(128+(a&63))}if(a<2097152){return chr(240+(a>>18))+chr(128+((a>>12)&63))+chr(128+((a>>6)&63))+chr(128+(a&63))}};_utf8Encode=function(c){var b=new Array();for(var a=0;a<c.length;a++){b[a]=code2utf(c.charCodeAt(a))}return b.join("")};utf8Encode=function(d){var c=new Array();var e,b=0;var a="";while((e=d.search(/[^\x00-\x7F]/))!=-1){a=d.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0];c[b++]=d.substr(0,e);c[b++]=_utf8Encode(a);d=d.substr(e+a.length)}c[b++]=d;return c.join("")};function hex2a(b){var c="";for(var a=0;a<b.length;a+=2){c+=String.fromCharCode(parseInt(b.substr(a,2),16))}return c}cfInvalUI.init();
View
BIN cfInval.min.js.gz
Binary file not shown.
View
147 jquery.timeago.js
@@ -0,0 +1,147 @@
+/*
+ * timeago: a jQuery plugin, version: 0.9.3 (2011-01-21)
+ * @requires jQuery v1.2.3 or later
+ *
+ * Timeago is a jQuery plugin that makes it easy to support automatically
+ * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
+ *
+ * For usage and examples, visit:
+ * http://timeago.yarp.com/
+ *
+ * Licensed under the MIT:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright (c) 2008-2011, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
+ */
+(function($) {
+ $.timeago = function(timestamp) {
+ if (timestamp instanceof Date) {
+ return inWords(timestamp);
+ } else if (typeof timestamp === "string") {
+ return inWords($.timeago.parse(timestamp));
+ } else {
+ return inWords($.timeago.datetime(timestamp));
+ }
+ };
+ var $t = $.timeago;
+
+ $.extend($.timeago, {
+ settings: {
+ refreshMillis: 60000,
+ allowFuture: false,
+ strings: {
+ prefixAgo: null,
+ prefixFromNow: null,
+ suffixAgo: "ago",
+ suffixFromNow: "from now",
+ seconds: "less than a minute",
+ minute: "about a minute",
+ minutes: "%d minutes",
+ hour: "about an hour",
+ hours: "about %d hours",
+ day: "a day",
+ days: "%d days",
+ month: "about a month",
+ months: "%d months",
+ year: "about a year",
+ years: "%d years",
+ numbers: []
+ }
+ },
+ inWords: function(distanceMillis) {
+ var $l = this.settings.strings;
+ var prefix = $l.prefixAgo;
+ var suffix = $l.suffixAgo;
+ if (this.settings.allowFuture) {
+ if (distanceMillis < 0) {
+ prefix = $l.prefixFromNow;
+ suffix = $l.suffixFromNow;
+ }
+ distanceMillis = Math.abs(distanceMillis);
+ }
+
+ var seconds = distanceMillis / 1000;
+ var minutes = seconds / 60;
+ var hours = minutes / 60;
+ var days = hours / 24;
+ var years = days / 365;
+
+ function substitute(stringOrFunction, number) {
+ var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
+ var value = ($l.numbers && $l.numbers[number]) || number;
+ return string.replace(/%d/i, value);
+ }
+
+ var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
+ seconds < 90 && substitute($l.minute, 1) ||
+ minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
+ minutes < 90 && substitute($l.hour, 1) ||
+ hours < 24 && substitute($l.hours, Math.round(hours)) ||
+ hours < 48 && substitute($l.day, 1) ||
+ days < 30 && substitute($l.days, Math.floor(days)) ||
+ days < 60 && substitute($l.month, 1) ||
+ days < 365 && substitute($l.months, Math.floor(days / 30)) ||
+ years < 2 && substitute($l.year, 1) ||
+ substitute($l.years, Math.floor(years));
+
+ return $.trim([prefix, words, suffix].join(" "));
+ },
+ parse: function(iso8601) {
+ var s = $.trim(iso8601);
+ s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
+ s = s.replace(/-/,"/").replace(/-/,"/");
+ s = s.replace(/T/," ").replace(/Z/," UTC");
+ s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
+ return new Date(s);
+ },
+ datetime: function(elem) {
+ // jQuery's `is()` doesn't play well with HTML5 in IE
+ var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
+ var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
+ return $t.parse(iso8601);
+ }
+ });
+
+ $.fn.timeago = function() {
+ var self = this;
+ self.each(refresh);
+
+ var $s = $t.settings;
+ if ($s.refreshMillis > 0) {
+ setInterval(function() { self.each(refresh); }, $s.refreshMillis);
+ }
+ return self;
+ };
+
+ function refresh() {
+ var data = prepareData(this);
+ if (!isNaN(data.datetime)) {
+ $(this).text(inWords(data.datetime));
+ }
+ return this;
+ }
+
+ function prepareData(element) {
+ element = $(element);
+ if (!element.data("timeago")) {
+ element.data("timeago", { datetime: $t.datetime(element) });
+ var text = $.trim(element.text());
+ if (text.length > 0) {
+ element.attr("title", text);
+ }
+ }
+ return element.data("timeago");
+ }
+
+ function inWords(date) {
+ return $t.inWords(distance(date));
+ }
+
+ function distance(date) {
+ return (new Date().getTime() - date.getTime());
+ }
+
+ // fix for IE6 suckage
+ document.createElement("abbr");
+ document.createElement("time");
+}(jQuery));
View
1 jquery.timeago.min.js
@@ -0,0 +1 @@
+(function(d){d.timeago=function(g){if(g instanceof Date){return a(g)}else{if(typeof g==="string"){return a(d.timeago.parse(g))}else{return a(d.timeago.datetime(g))}}};var f=d.timeago;d.extend(d.timeago,{settings:{refreshMillis:60000,allowFuture:false,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years",numbers:[]}},inWords:function(l){var m=this.settings.strings;var i=m.prefixAgo;var q=m.suffixAgo;if(this.settings.allowFuture){if(l<0){i=m.prefixFromNow;q=m.suffixFromNow}l=Math.abs(l)}var o=l/1000;var g=o/60;var n=g/60;var p=n/24;var j=p/365;function h(r,t){var s=d.isFunction(r)?r(t,l):r;var u=(m.numbers&&m.numbers[t])||t;return s.replace(/%d/i,u)}var k=o<45&&h(m.seconds,Math.round(o))||o<90&&h(m.minute,1)||g<45&&h(m.minutes,Math.round(g))||g<90&&h(m.hour,1)||n<24&&h(m.hours,Math.round(n))||n<48&&h(m.day,1)||p<30&&h(m.days,Math.floor(p))||p<60&&h(m.month,1)||p<365&&h(m.months,Math.floor(p/30))||j<2&&h(m.year,1)||h(m.years,Math.floor(j));return d.trim([i,k,q].join(" "))},parse:function(h){var g=d.trim(h);g=g.replace(/\.\d\d\d+/,"");g=g.replace(/-/,"/").replace(/-/,"/");g=g.replace(/T/," ").replace(/Z/," UTC");g=g.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2");return new Date(g)},datetime:function(h){var i=d(h).get(0).tagName.toLowerCase()==="time";var g=i?d(h).attr("datetime"):d(h).attr("title");return f.parse(g)}});d.fn.timeago=function(){var h=this;h.each(c);var g=f.settings;if(g.refreshMillis>0){setInterval(function(){h.each(c)},g.refreshMillis)}return h};function c(){var g=b(this);if(!isNaN(g.datetime)){d(this).text(a(g.datetime))}return this}function b(g){g=d(g);if(!g.data("timeago")){g.data("timeago",{datetime:f.datetime(g)});var h=d.trim(g.text());if(h.length>0){g.attr("title",h)}}return g.data("timeago")}function a(g){return f.inWords(e(g))}function e(g){return(new Date().getTime()-g.getTime())}document.createElement("abbr");document.createElement("time")}(jQuery));

0 comments on commit aca9688

Please sign in to comment.
Something went wrong with that request. Please try again.