Skip to content

Instantly share code, notes, and snippets.

@larryprice
Created July 14, 2014 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larryprice/1e67ddcd53c686fbc1de to your computer and use it in GitHub Desktop.
Save larryprice/1e67ddcd53c686fbc1de to your computer and use it in GitHub Desktop.
Modified Trello client.js for use on Ollert
!function(){var b,c,d,e,f,g,a={version:1,apiEndpoint:"https://api.trello.com",authEndpoint:"https://trello.com"},h=[].slice;g=function(a,b,g){var i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;for(n=g.key,s=g.token,j=g.apiEndpoint,k=g.authEndpoint,t=g.version,m=""+j+"/"+t+"/",p=a.location,i={clearReady:function(){e={}},version:function(){return t},key:function(){return n},setKey:function(a){n=a},token:function(){return s},setToken:function(a){s=a},rest:function(){var a,c,d,e;return c=arguments[0],a=2<=arguments.length?h.call(arguments,1):[],e=q(a),d=e[0],a=e[1],g={url:""+m+d,type:c,data:{},dataType:"json",success:e[2],error:e[3]},b.support.cors||(g.dataType="jsonp","GET"!==c&&(g.type="GET",b.extend(g.data,{_method:c}))),n&&(g.data.key=n),s&&(g.data.token=s),null!=a&&b.extend(g.data,a),b.ajax(g)},authorized:function(){return null!=s},deauthorize:function(){s=null,u("token",s)},authorize:function(c){var d,e,h,i,j;if(g=b.extend(!0,{type:"redirect",persist:!0,interactive:!0,scope:{read:!0,write:!1,account:!1},expiration:"30days"},c),c=/[&#]?token=([0-9a-f]{64})/,e=function(){return g.persist&&null!=s?u("token",s):void 0},g.persist&&null==s&&(s=r("token")),null==s&&(s=null!=(j=c.exec(p.hash))?j[1]:void 0),this.authorized())return e(),p.hash=p.hash.replace(c,""),"function"==typeof g.success?g.success():void 0;if(!g.interactive)return"function"==typeof g.error?g.error():void 0;switch(h=function(){var a,b;a=g.scope,b=[];for(d in a)(i=a[d])&&b.push(d);return b}().join(","),g.type){case"popup":!function(){var b,c,d,i;return f("authorized",function(){return function(a){return a?(e(),"function"==typeof g.success?g.success():void 0):"function"==typeof g.error?g.error():void 0}}(this)),b=a.screenX+(a.innerWidth-420)/2,d=a.screenY+(a.innerHeight-470)/2,c=null!=(i=/^[a-z]+:\/\/[^\/]*/.exec(p))?i[0]:void 0,a.open(l({return_url:c,callback_method:"postMessage",scope:h,expiration:g.expiration,name:g.name}),"trello","width=420,height=470,left="+b+",top="+d)}();break;default:a.location=l({redirect_uri:p.href,callback_method:"fragment",scope:h,expiration:g.expiration,name:g.name})}}},y=["GET","PUT","POST","DELETE"],v=function(a){return i[a.toLowerCase()]=function(){return this.rest.apply(this,[a].concat(h.call(arguments)))}},w=0,x=y.length;x>w;w++)j=y[w],v(j);for(i.del=i["delete"],y="actions cards checklists boards lists members organizations lists".split(" "),v=function(a){return i[a]={get:function(b,c,d,e){return i.get(""+a+"/"+b,c,d,e)}}},w=0,x=y.length;x>w;w++)j=y[w],v(j);a.Trello=i,l=function(a){return k+"/"+t+"/authorize?"+b.param(b.extend({response_type:"token",key:n},a))},q=function(a){var b,d,e;return d=a[0],b=a[1],e=a[2],a=a[3],c(b)&&(a=e,e=b,b={}),d=d.replace(/^\/*/,""),[d,b,e,a]},j=function(a){var b;a.origin===k&&(null!=(b=a.source)&&b.close(),s=null!=a.data&&4<a.data.length?a.data:null,d("authorized",i.authorized()))},o=a.localStorage,null!=o?(r=function(a){return o["trello_"+a]},u=function(a,b){return null===b?delete o["trello_"+a]:o["trello_"+a]=b}):r=u=function(){},"function"==typeof a.addEventListener&&a.addEventListener("message",j,!1)},b={},e={},f=function(a,c){return null!=e[a]?c(e[a]):(null!=b[a]?b[a]:b[a]=[]).push(c)},d=function(a,c){var d,f,g,h;if(e[a]=c,b[a])for(f=b[a],delete b[a],g=0,h=f.length;h>g;g++)d=f[g],d(c)},c=function(a){return"function"==typeof a},g(window,jQuery,a)}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment