<commit_before>function EvDa(a){function H(a){return a.match(/[?*]/)}function I(a,b){return H(a)?p(m(b?b:B),function(b){return b.match(a)}):a}function J(a,b){var c={};return d(a)?(j(a,function(a){c[a]=b(a)}),c):b(a)}function K(a){if(a in B)return B[a];var b=a.split("."),c=b.pop(),d=b.join(".");if(d){var e=K(d);if(h(e)&&c in e)return e[c]}}function L(a,c,f,g){if(0===arguments.length)return{data:B,events:G,globs:F};if(d(a)){var i=b.call(arguments,1);return r(a,function(a){return L.apply(L.context,[a].concat(i))})}if(h(a)){var k={};return g=f||{},f=c,g.noexec=1,j(a,function(a,b){k[a]=L(a,b,f,g)}),g.bypass||j(k,function(b){e(k[b])&&!e(a[b])&&(a[b]=k[b]())}),P(m(k)[0]),a}return 1==arguments.length?J(a,K):L[e(c)||d(c)&&e(c[0])?v:"set"].apply(this,arguments)}function M(a){j(a.$,function(b){var c=H(b)?F:G;c[b]=n(c[b],a)})}function N(a,b,c){if(d(a)){var e=a.pop();return N(I(e),function(c,d){var e=1==a.length?a[0]:a;return N(e,b,d)},c)}if(h(a))return j(a,function(b,d){H(b)?t(b,J(b,function(){return N(b,d,c)})):a[b]=N(b,d,c)}),a;var f="set"+a;return G[f]&&(G[f](function(b){L.set.call(L.context,a,b,c)}),delete G[f]),b?a in B?b.call(L.context,B[a],c):L(a,b,t(c||{},y)):a in B}function O(a,b,c,d){a.S||(a.call(b,c,d),a.once&&M(a))}function P(a){var c=a.split("."),d=c.pop();parts_obj=[],parts_obj[d]=B[a],L.extend.apply(L.context,[c.join("."),parts_obj].concat(b.call(arguments,1)))}var b=Array.prototype.slice,c=Object.prototype.toString,d=[].isArray||function(a){return"[object Array]"===c.call(a)},e=function(a){return!!(a&&a.constructor&&a.call&&a.apply)},f=function(a){return!!(""===a||a&&a.charCodeAt&&a.substr)},g=function(a){return"[object Number]"===c.call(a)},h=function(a){return e(a)||f(a)||g(a)||d(a)?!1:null==a?"object"==String(a):"[object Object]"===c.call(a)||!0},i=function(a){return b.call(a)},j=[].forEach?function(a,b){if(d(a)||a.length)i(a).forEach(b);else for(var c in a)b(c,a[c])}:function(a,b){if(d(a))for(var c=0,e=a.length;e>c;c++)b(a[c],c);else for(var f in a)b(f,a[f])},k=function(a){return a.length?a[a.length-1]:void 0},l=function(a){var b=[];for(var c in a)b.push(a[c]);return b},m={}.keys||function(a){if(d(a))return a;var b=[];for(var c in a)b.push(c);return b},n=function(a,b){var c=[];return j(a,function(a){a!==b&&c.push(a)}),c},o=function(a){var b,c=[];return j(m(a).sort(),function(a){a!=b&&(b=a,c.push(a))}),c},p=function(a,b){var c=[];return j(a,function(a){b(a)&&c.push(a)}),c},q=function(a){return a&&"length"in a?a.length:0},r=[].map?function(a,b){return a.map(b)}:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)c.push(b(a[d],d));return c},s=function(a){return d(a)?b.call(a):h(a)?t(a,{}):a},t=function(a){return j(b.call(arguments,1),function(b){for(var c in b)void 0!==b[c]&&(a[c]=b[c])}),a},u="first",v="on",w="after",x=[u,v,w,"test","or"],y={once:1},z={},A={},B=a||{},C={},E=[],F={},G={};return j(x,function(a){L[a]=function(c,e,f){if(d(e)){var g=b.call(arguments,2);return r(e,function(b){return L[a].apply(L.context,[c,b].concat(g))})}var h=G;return e?((e.$||(e.$=[])).push(a+c),H(c)&&(h=F),(h[a+c]||(h[a+c]=[])).push(e),t(e,f)):h[a+c]}}),t(L,{_:{},context:this,list:{},isPaused:!1,db:B,events:function(a,b){return b?G[b+a]:a?J(x.concat(["set"]),function(b){return G[b+a]}):G},del:M,whenSet:N,isset:N,pause:function(){return L.isPaused?!1:(L.isPaused=!0,L._.set=L.set,L.set=function(){E.push(["set",arguments])},!0)},play:function(){if(L.isPaused){L.isPaused=!1;var a=EvDa();return L.set=L._.set,j(E,function(b){a[b[0]].apply(a,b[1])}),E=[],L(a.db),!0}return!1},setter:function(a,b){return G["set"+a]=b,G[v+a]?N(a):void 0},when:function(a,c,g){if(h(a)){var i={},k={},m=function(a,b){k[b.key]=!1,b()},n=function(a,d){k[d.key]=!0,-1==l(k).indexOf(!1)&&c.apply(L.context,b.call(arguments))};return j(a,function(a,b){i[a+"-test"]=L.test(a,m),i[a]=L.when(a,b,n),k[a]=!1}),i}if(f(c))try{var o=new Function("x","return x"+c);o(),c=o}catch(p){}else if(2==arguments.length)return L.isset(a,c);return L(a,function(a){(d(c)&&c.sort().join("")===a.sort().join("")||e(c)&&c(a)||a===c)&&g.apply(L.context,b.call(arguments))})},empty:function(){for(var a in B)delete B[a]},incr:function(a,b,c){return b=b||1,L.set(a,g(B[a])?B[a]+b:b,c)},decr:function(a,b,c){return b=b||1,L.set(a,B[a]-b||0,c)},push:function(a,b,c){return L.set(a,[].concat(B[a]||[],[b]),c)},pop:function(a,b){return L.set(a,B[a].slice(0,-1),b)},traceList:[],group:function(a){var b=i(arguments),a=b.shift(),c=L.apply(0,b);return L.list[a]||(L.list[a]=[]),e(c)?L.list[a].push(c):j(c,function(b){L.list[a].push(b)}),function(){return L.group.apply(0,[a].concat(i(arguments)))}},extend:function(a,c){return L.set.apply(L.context,[a,t({},B[a]||{},c)].concat(b.call(arguments,2)))},count:function(a){return 0===arguments.length?Math.max.apply(this,l(C)):C[a]},set:function(a,c,d,e){e=e||{};var f,g=e.bypass,h=e.coroutine||function(){return!0},i="value"in e,k=e.noexec;if(1==arguments.length){var l=function(){L.set.apply(L.context,[a].concat(b.call(arguments)))};return L.set.call(L.context,a,void 0),l}if(z[a]>0)return B[a];z[a]=(z[a]||0)+1;var n,y,m="test"+a,o=b.call(arguments),p=q(G[m]),r=0,x=p&&!g,D=function(){j(G["or"+a]||[],function(a){O(a,L.context,i?e.value:E.value,E,E.meta)})},E=x?function(b){return y|=b===!1,--p?(r++,h(E,!1)?(f=G[m][r].call(L.context,i?e.value:E.value,E,E.meta),(f===!0||f===!1)&&E(f)):D()):y?D():h(E,!0)?L.set(a,E.value,E.meta,{bypass:1}):D(),b}:{};if(E.old=s(B[a]),t(E,{meta:d||{},done:E,result:E,key:a,value:c}),x)z[a]--,A[a]!==!0&&(A[a]=!0,h(E,!1)?(f=G[m][r].call(L.context,i?e.value:E.value,E,E.meta),(f===!0||f===!1)&&E(f)):D(),A[a]=!1),n=B[a];else if(j(L.traceList,function(a){a.call(L.context,o)}),h(E,!0)&&(c=E.value,!e.onlychange||c!==B[a])){e.noset||(B[a]=c,""!=a&&(C[a]=(C[a]||0)+1));var F=arguments,H=function(){return j((G[u+a]||[]).concat(G[v+a]||[]),function(a){E.last=O(a,L.context,c,E)}),a.length>0&&(delete e.coroutine,P.apply(L.context,[a].concat(b.call(F,2)))),j(G[w+a]||[],function(a){E.last=O(a,L.context,c,E)}),c};n=k?H:H.call(L.context)}return z[a]=0,n},fire:function(a,b){L.set(a,B[a],b,{noset:!0})},once:function(a,b,c){return h(a)&&(a=l(a)),d(a)?r(a,function(a){L.once.call(L.context,a,b,c)}):b?L.once(L(a,b,c)):t(a,y)},enable:function(a){return j(L.list[a],function(b){b.S&&b.S[a]&&delete b.S[a],0==q(b.S)&&delete b.S}),L.list[a]},osetadd:function(a,b,c){var e=B[a]||[];return L(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=s(e),j(c,function(b){-1==a.set.indexOf(b)&&a.set.push(b)}),b&&(a.value=a.set),e.length!=a.set.length}})},setadd:function(a,b,c){var e=B[a]||[];return L(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=o(e.concat(c)),b&&(a.value=a.set),e.length!=a.set.length}})},settoggle:function(a,b,c){var d=-1===(B[a]||[]).indexOf(b)?"add":"del";return L["set"+d](a,b,c)},setdel:function(a,b,c){var d=B[a]||[],e=n(d,b);return d.length!=e.length?L(a,e,c,{value:b}):e},disable:function(a){return j(L.list[a],function(b){(b.S||(b.S={}))[a]=!0}),L.list[a]},unset:function(){var a=!0;return j(arguments,function(b){a&=b in B;var g,h,i,c=b.split("."),d="",e=c.length,f=c[e-1];for(g=0;e>g;g++)if(d=c.slice(0,g).join("."),i=B[d]){for(h=g;e-1>h;h++)i=i[c[h]];delete i[f]}delete B[b]}),a},find:function(a){return p(m(B),function(b){return b.match(a)})},changed:function(a,b){return L.on(a,function(a,c){var d=q(a),e=q(c.old);1==d-e?b.call(L.context,k(a)):d>e&&b.call(L.context,i(a).slice(e))})},sniff:function(){var a={},b=+new Date,c=function(c){a[c[0]]||console.log(+new Date-b,c)},d=function(){},e=c;L.traceList.unshift(function(a){e(a)}),L.sniff=function(b){return arguments.length>0?f(b)?(a[b]=!a[b],"[Un]ignoring "+b):(e=b?c:d,b):m(a)}}}),L.setAdd=L.setadd,L.setToggle=L.settoggle,L.osetAdd=L.osetadd,L.setDel=L.setdel,L.isSet=L.isset,L.get=L,L.change=L.on,L.add=L.push,L.isArray=d,L}<commit_msg>minified version<commit_after>function EvDa(a){function I(a){return a.match(/[?*]/)}function J(a,b){return I(a)?q(n(b?b:C),function(b){return b.match(a)}):a}function K(a,b){var c={};return d(a)?(k(a,function(a){c[a]=b(a)}),c):b(a)}function L(a){if(a in C)return C[a];var b=a.split("."),c=b.pop(),d=b.join(".");if(d){var e=L(d);if(i(e)&&c in e)return e[c]}}function M(a,c,f,g){if(0===arguments.length)return{data:C,events:H,globs:G};if(d(a)){var h=b.call(arguments,1);return s(a,function(a){return M.apply(M.context,[a].concat(h))})}if(i(a)){var j={};return g=f||{},f=c,g.noexec=1,k(a,function(a,b){j[a]=M(a,b,f,g)}),g.bypass||k(j,function(b){e(j[b])&&!e(a[b])&&(a[b]=j[b]())}),Q(n(j)[0]),a}return 1==arguments.length?K(a,L):M[e(c)||d(c)&&e(c[0])?w:"set"].apply(this,arguments)}function N(a){k(a.$,function(b){var c=I(b)?G:H;c[b]=o(c[b],a)})}function O(a,b,c){if(d(a)){var e=a.pop();return O(J(e),function(c,d){var e=1==a.length?a[0]:a;return O(e,b,d)},c)}if(i(a))return k(a,function(b,d){I(b)?u(b,K(b,function(){return O(b,d,c)})):a[b]=O(b,d,c)}),a;var f="set"+a;return H[f]&&(H[f](function(b){M.set.call(M.context,a,b,c)}),delete H[f]),b?a in C?b.call(M.context,C[a],c):M(a,b,u(c||{},z)):a in C}function P(a,b,c,d){a.S||(a.call(b,c,d),a.once&&N(a))}function Q(a){var c=a.split("."),d=c.pop();parts_obj=[],parts_obj[d]=C[a],M.extend.apply(M.context,[c.join("."),parts_obj].concat(b.call(arguments,1)))}var b=Array.prototype.slice,c=Object.prototype.toString,d=[].isArray||function(a){return"[object Array]"===c.call(a)},e=function(a){return!!(a&&a.constructor&&a.call&&a.apply)},f=function(a){return!!(""===a||a&&a.charCodeAt&&a.substr)},g=function(a){return"[object Number]"===c.call(a)},h=function(a){return f(a)||g(a)},i=function(a){return e(a)||f(a)||g(a)||d(a)?!1:null==a?"object"==String(a):"[object Object]"===c.call(a)||!0},j=function(a){return b.call(a)},k=[].forEach?function(a,b){if(h(a))return k([a],b);if(d(a)||a.length)j(a).forEach(b);else for(var c in a)b(c,a[c])}:function(a,b){if(h(a))return k([a],b);if(d(a))for(var c=0,e=a.length;e>c;c++)b(a[c],c);else for(var f in a)b(f,a[f])},l=function(a){return a.length?a[a.length-1]:void 0},m=function(a){var b=[];for(var c in a)b.push(a[c]);return b},n={}.keys||function(a){if(d(a))return a;var b=[];for(var c in a)b.push(c);return b},o=function(a,b){var c=[];return k(a,function(a){a!==b&&c.push(a)}),c},p=function(a){var b,c=[];return k(n(a).sort(),function(a){a!=b&&(b=a,c.push(a))}),c},q=function(a,b){var c=[];return k(a,function(a){b(a)&&c.push(a)}),c},r=function(a){return a&&"length"in a?a.length:0},s=[].map?function(a,b){return a.map(b)}:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)c.push(b(a[d],d));return c},t=function(a){return d(a)?b.call(a):i(a)?u(a,{}):a},u=function(a){return k(b.call(arguments,1),function(b){for(var c in b)void 0!==b[c]&&(a[c]=b[c])}),a},v="first",w="on",x="after",y=[v,w,x,"test","or"],z={once:1},A={},B={},C=a||{},D={},F=[],G={},H={};return k(y,function(a){M[a]=function(c,e,f){if(d(e)){var g=b.call(arguments,2);return s(e,function(b){return M[a].apply(M.context,[c,b].concat(g))})}var h=H;return e?((e.$||(e.$=[])).push(a+c),I(c)&&(h=G),(h[a+c]||(h[a+c]=[])).push(e),u(e,f)):h[a+c]}}),u(M,{_:{},context:this,list:{},isPaused:!1,db:C,events:function(a,b){return b?H[b+a]:a?K(y.concat(["set"]),function(b){return H[b+a]}):H},del:N,whenSet:O,isset:O,pause:function(){return M.isPaused?!1:(M.isPaused=!0,M._.set=M.set,M.set=function(){F.push(["set",arguments])},!0)},play:function(){if(M.isPaused){M.isPaused=!1;var a=EvDa();return M.set=M._.set,k(F,function(b){a[b[0]].apply(a,b[1])}),F=[],M(a.db),!0}return!1},setter:function(a,b){return H["set"+a]=b,H[w+a]?O(a):void 0},when:function(a,c,g){if(i(a)){var h={},j={},l=function(a,b){j[b.key]=!1,b()},n=function(a,d){j[d.key]=!0,-1==m(j).indexOf(!1)&&c.apply(M.context,b.call(arguments))};return k(a,function(a,b){h[a+"-test"]=M.test(a,l),h[a]=M.when(a,b,n),j[a]=!1}),h}if(f(c))try{var o=new Function("x","return x"+c);o(),c=o}catch(p){}else if(2==arguments.length)return M.isset(a,c);return M(a,function(a){(d(c)&&c.sort().join("")===a.sort().join("")||e(c)&&c(a)||a===c)&&g.apply(M.context,b.call(arguments))})},empty:function(){for(var a in C)delete C[a]},incr:function(a,b,c){return b=b||1,M.set(a,g(C[a])?C[a]+b:b,c)},decr:function(a,b,c){return b=b||1,M.set(a,C[a]-b||0,c)},push:function(a,b,c){return M.set(a,[].concat(C[a]||[],[b]),c)},pop:function(a,b){return M.set(a,C[a].slice(0,-1),b)},traceList:[],group:function(a){var b=j(arguments),a=b.shift(),c=M.apply(0,b);return M.list[a]||(M.list[a]=[]),e(c)?M.list[a].push(c):k(c,function(b){M.list[a].push(b)}),function(){return M.group.apply(0,[a].concat(j(arguments)))}},extend:function(a,c){return M.set.apply(M.context,[a,u({},C[a]||{},c)].concat(b.call(arguments,2)))},count:function(a){return 0===arguments.length?Math.max.apply(this,m(D)):D[a]},set:function(a,c,d,e){e=e||{};var f,g=e.bypass,h=e.coroutine||function(){return!0},i="value"in e,j=e.noexec;if(1==arguments.length){var l=function(){M.set.apply(M.context,[a].concat(b.call(arguments)))};return M.set.call(M.context,a,void 0),l}if(A[a]>0)return C[a];A[a]=(A[a]||0)+1;var n,y,m="test"+a,o=b.call(arguments),p=r(H[m]),q=0,s=p&&!g,z=function(){k(H["or"+a]||[],function(a){P(a,M.context,i?e.value:E.value,E,E.meta)})},E=s?function(b){return y|=b===!1,--p?(q++,h(E,!1)?(f=H[m][q].call(M.context,i?e.value:E.value,E,E.meta),(f===!0||f===!1)&&E(f)):z()):y?z():h(E,!0)?M.set(a,E.value,E.meta,{bypass:1}):z(),b}:{};if(E.old=t(C[a]),u(E,{meta:d||{},done:E,result:E,key:a,value:c}),s)A[a]--,B[a]!==!0&&(B[a]=!0,h(E,!1)?(f=H[m][q].call(M.context,i?e.value:E.value,E,E.meta),(f===!0||f===!1)&&E(f)):z(),B[a]=!1),n=C[a];else if(k(M.traceList,function(a){a.call(M.context,o)}),h(E,!0)&&(c=E.value,!e.onlychange||c!==C[a])){e.noset||(C[a]=c,""!=a&&(D[a]=(D[a]||0)+1));var F=arguments,G=function(){return k((H[v+a]||[]).concat(H[w+a]||[]),function(a){E.last=P(a,M.context,c,E)}),a.length>0&&(delete e.coroutine,Q.apply(M.context,[a].concat(b.call(F,2)))),k(H[x+a]||[],function(a){E.last=P(a,M.context,c,E)}),c};n=j?G:G.call(M.context)}return A[a]=0,n},fire:function(a,b){k(a,function(a){M.set(a,C[a],b,{noset:!0})})},once:function(a,b,c){return i(a)&&(a=m(a)),d(a)?s(a,function(a){M.once.call(M.context,a,b,c)}):b?M.once(M(a,b,c)):u(a,z)},enable:function(a){return k(M.list[a],function(b){b.S&&b.S[a]&&delete b.S[a],0==r(b.S)&&delete b.S}),M.list[a]},osetadd:function(a,b,c){var e=C[a]||[];return M(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=t(e),k(c,function(b){-1==a.set.indexOf(b)&&a.set.push(b)}),b&&(a.value=a.set),e.length!=a.set.length}})},setadd:function(a,b,c){var e=C[a]||[];return M(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=p(e.concat(c)),b&&(a.value=a.set),e.length!=a.set.length}})},settoggle:function(a,b,c){var d=-1===(C[a]||[]).indexOf(b)?"add":"del";return M["set"+d](a,b,c)},setdel:function(a,b,c){var d=C[a]||[],e=o(d,b);return d.length!=e.length?M(a,e,c,{value:b}):e},disable:function(a){return k(M.list[a],function(b){(b.S||(b.S={}))[a]=!0}),M.list[a]},unset:function(){var a=!0;return k(arguments,function(b){a&=b in C;var g,h,i,c=b.split("."),d="",e=c.length,f=c[e-1];for(g=0;e>g;g++)if(d=c.slice(0,g).join("."),i=C[d]){for(h=g;e-1>h;h++)i=i[c[h]];delete i[f]}delete C[b]}),a},find:function(a){return q(n(C),function(b){return b.match(a)})},changed:function(a,b){return M.on(a,function(a,c){var d=r(a),e=r(c.old);1==d-e?b.call(M.context,l(a)):d>e&&b.call(M.context,j(a).slice(e))})},sniff:function(){var a={},b=+new Date,c=function(c){a[c[0]]||console.log(+new Date-b,c)},d=function(){},e=c;M.traceList.unshift(function(a){e(a)}),M.sniff=function(b){return arguments.length>0?f(b)?(a[b]=!a[b],"[Un]ignoring "+b):(e=b?c:d,b):n(a)}}}),M.setAdd=M.setadd,M.setToggle=M.settoggle,M.osetAdd=M.osetadd,M.setDel=M.setdel,M.isSet=M.isset,M.get=M,M.change=M.on,M.add=M.push,M.isArray=d,M}<|endoftext|>


<commit_before>// Github.js 0.6.0
// (c) 2012 Michael Aufreiter, Development Seed
// Github.js is freely distributable under the MIT license.
// For all details and documentation:
// http://substance.io/michael/github

(function() {
  var Github;
  var API_URL = 'https://api.github.com';

  Github = window.Github = function(options) {

    // Util
    // =======

    function headers() {
      var headers = {}
      if (options.auth === 'oauth' && !options.token) return { Accept: 'application/vnd.github.raw' };
      if (options.auth === 'basic' && (!options.username || !options.password)) return { Accept: 'application/vnd.github.raw' };
      return options.auth == 'oauth'
             ? { Authorization: 'token '+ options.token, Accept: 'application/vnd.github.raw' }
             : { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password), Accept: 'application/vnd.github.raw' }
    }

    function _request(method, path, data, cb) {
      $.ajax({
        type: method,
        url: API_URL + path,
        data: JSON.stringify(data),
        dataType: 'json',
        contentType: 'application/x-www-form-urlencoded',
        success: function(res) { cb(null, res); },
        error: function(err) { cb(err); },
        headers : headers()
      });
    }

    function _raw_request(method, path, data, cb) {
      $.ajax({
        type: method,
        url: API_URL + path,
        data: JSON.stringify(data),
        contentType: 'application/x-www-form-urlencoded',
        success: function(res) { cb(null, res); },
        error: function(err) { cb(err); },
        headers : headers()
      });
    }

    // User API
    // =======

    Github.User = function() {
      this.repos = function(cb) {
        _request("GET", "/user/repos?type=all&per_page=100", null, function(err, res) {
          cb(err, res);
        });
      };

      // List user organizations
      // -------

      this.orgs = function(cb) {
        _request("GET", "/user/orgs", null, function(err, res) {
          cb(err, res);
        });
      };

      // Show user information
      // -------

      this.show = function(username, cb) {
        _request("GET", "/users/"+username, null, function(err, res) {
          cb(err, res);
        });
      }

      // List user repositories
      // -------

      this.userRepos = function(username, cb) {
        _request("GET", "/users/"+username+"/repos?type=all&per_page=100", null, function(err, res) {
          cb(err, res);
        });
      };

      // List organization repositories
      // -------

      this.orgRepos = function(orgname, cb) {
        _request("GET", "/orgs/"+orgname+"/repos?type=all&per_page=100", null, function(err, res) {
          cb(err, res);
        });
      };
    };

    // Repository API
    // =======

    Github.Repository = function(options) {
      var repo = options.name;
      var user = options.user;

      var that = this;
      var repoPath = "/repos/" + user + "/" + repo;

      var currentTree = {
        "branch": null,
        "sha": null
      };

      // Uses the cache if branch has not been changed
      // -------

      function updateTree(branch, cb) {
        if (branch === currentTree.branch && currentTree.sha) return cb(null, currentTree.sha);
        that.getRef(branch, function(err, sha) {
          currentTree.branch = branch;
          currentTree.sha = sha;
          cb(err, sha);
        });
      }

      // Get a particular reference
      // -------

      this.getRef = function(ref, cb) {
        _request("GET", repoPath + "/git/refs/heads/" + ref, null, function(err, res) {
          if (err) return cb(err);
          cb(null, res.object.sha);
        });
      };

      // List all branches of a repository
      // -------

      this.listBranches = function(cb) {
        _request("GET", repoPath + "/git/refs/heads", null, function(err, heads) {
          if (err) return cb(err);
          cb(null, _.map(heads, function(head) { return _.last(head.ref.split('/')); }));
        });
      };

      // Retrieve the contents of a blob
      // -------

      this.getBlob = function(sha, cb) {
        _raw_request("GET", repoPath + "/git/blobs/" + sha, null, cb);
      };

      // For a given file path, get the corresponding sha (blob for files, tree for dirs)
      // -------

      this.getSha = function(branch, path, cb) {
        // Just use head if path is empty
        if (path === "") return that.getRef(branch, cb);
        that.getTree(branch+"?recursive=true", function(err, tree) {
          var file = _.select(tree, function(file) {
            return file.path === path;
          })[0];
          cb(null, file ? file.sha : null);
        });
      };

      // Retrieve the tree a commit points to
      // -------

      this.getTree = function(tree, cb) {
        _request("GET", repoPath + "/git/trees/"+tree, null, function(err, res) {
          if (err) return cb(err);
          cb(null, res.tree);
        });
      };

      // Post a new blob object, getting a blob SHA back
      // -------

      this.postBlob = function(content, cb) {
        var data = {
          "content": content,
          "encoding": "utf-8"
        };
        _request("POST", repoPath + "/git/blobs", data, function(err, res) {
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Update an existing tree adding a new blob object getting a tree SHA back
      // -------

      this.updateTree = function(baseTree, path, blob, cb) {
        var data = {
          "base_tree": baseTree,
          "tree": [
            {
              "path": path,
              "mode": "100644",
              "type": "blob",
              "sha": blob
            }
          ]
        };
        _request("POST", repoPath + "/git/trees", data, function(err, res) {
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Post a new tree object having a file path pointer replaced
      // with a new blob SHA getting a tree SHA back
      // -------

      this.postTree = function(tree, cb) {
        _request("POST", repoPath + "/git/trees", { "tree": tree }, function(err, res) {
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Create a new commit object with the current commit SHA as the parent
      // and the new tree SHA, getting a commit SHA back
      // -------

      this.commit = function(parent, tree, message, cb) {
        var data = {
          "message": message,
          "author": {
            "name": options.username
          },
          "parents": [
            parent
          ],
          "tree": tree
        };

        _request("POST", repoPath + "/git/commits", data, function(err, res) {
          currentTree.sha = res.sha; // update latest commit
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Update the reference of your head to point to the new commit SHA
      // -------

      this.updateHead = function(head, commit, cb) {
        _request("PATCH", repoPath + "/git/refs/heads/" + head, { "sha": commit }, function(err, res) {
          cb(err);
        });
      };

      // Show repository information
      // -------

      this.show = function(cb) {
        _request("GET", repoPath, null, function(err, info) {
          cb(null, info);
        });
      };

      // Read file at given path
      // -------

      this.read = function(branch, path, cb) {
        that.getSha(branch, path, function(err, sha) {
          if (!sha) return cb("not found", null);
          that.getBlob(sha, cb);
        });
      };

      // Remove a file from the tree
      // -------

      this.remove = function(branch, path, cb) {
        updateTree(branch, function(err, latestCommit) {
          that.getTree(latestCommit+"?recursive=true", function(err, tree) {
            // Update Tree
            var newTree = _.reject(tree, function(ref) { return ref.path === path });
            _.each(newTree, function(ref) {
              if (ref.type === "tree") delete ref.sha;
            });

            that.postTree(newTree, function(err, rootTree) {
              that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) {
                that.updateHead(branch, commit, function(err) {
                  cb(err);
                });
              });
            });
          });
        });
      };

      // Move a file to a new location
      // -------

      this.move = function(branch, path, newPath, cb) {
        updateTree(branch, function(err, latestCommit) {
          that.getTree(latestCommit+"?recursive=true", function(err, tree) {
            // Update Tree
            _.each(tree, function(ref) {
              if (ref.path === path) ref.path = newPath;
              if (ref.type === "tree") delete ref.sha;
            });

            that.postTree(tree, function(err, rootTree) {
              that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) {
                that.updateHead(branch, commit, function(err) {
                  cb(err);
                });
              });
            });
          });
        });
      };

      // Write file contents to a given branch and path
      // -------

      this.write = function(branch, path, content, message, cb) {
        updateTree(branch, function(err, latestCommit) {
          that.postBlob(content, function(err, blob) {
            that.updateTree(latestCommit, path, blob, function(err, tree) {
              that.commit(latestCommit, tree, message, function(err, commit) {
                that.updateHead(branch, commit, cb);
              });
            });
          });
        });
      };
    };

    // Top Level API
    // -------

    this.getRepo = function(user, repo) {
      return new Github.Repository({user: user, name: repo});
    };

    this.getUser = function() {
      return new Github.User();
    };
  };
}).call(this);<commit_msg>Sort by updated timestamp.<commit_after>// Github.js 0.6.0
// (c) 2012 Michael Aufreiter, Development Seed
// Github.js is freely distributable under the MIT license.
// For all details and documentation:
// http://substance.io/michael/github

(function() {
  var Github;
  var API_URL = 'https://api.github.com';

  Github = window.Github = function(options) {

    // Util
    // =======

    function headers() {
      var headers = {}
      if (options.auth === 'oauth' && !options.token) return { Accept: 'application/vnd.github.raw' };
      if (options.auth === 'basic' && (!options.username || !options.password)) return { Accept: 'application/vnd.github.raw' };
      return options.auth == 'oauth'
             ? { Authorization: 'token '+ options.token, Accept: 'application/vnd.github.raw' }
             : { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password), Accept: 'application/vnd.github.raw' }
    }

    function _request(method, path, data, cb) {
      $.ajax({
        type: method,
        url: API_URL + path,
        data: JSON.stringify(data),
        dataType: 'json',
        contentType: 'application/x-www-form-urlencoded',
        success: function(res) { cb(null, res); },
        error: function(err) { cb(err); },
        headers : headers()
      });
    }

    function _raw_request(method, path, data, cb) {
      $.ajax({
        type: method,
        url: API_URL + path,
        data: JSON.stringify(data),
        contentType: 'application/x-www-form-urlencoded',
        success: function(res) { cb(null, res); },
        error: function(err) { cb(err); },
        headers : headers()
      });
    }

    // User API
    // =======

    Github.User = function() {
      this.repos = function(cb) {
        _request("GET", "/user/repos?type=all&per_page=1000&sort=updated", null, function(err, res) {
          cb(err, res);
        });
      };

      // List user organizations
      // -------

      this.orgs = function(cb) {
        _request("GET", "/user/orgs", null, function(err, res) {
          cb(err, res);
        });
      };

      // Show user information
      // -------

      this.show = function(username, cb) {
        _request("GET", "/users/"+username, null, function(err, res) {
          cb(err, res);
        });
      }

      // List user repositories
      // -------

      this.userRepos = function(username, cb) {
        _request("GET", "/users/"+username+"/repos?type=all&per_page=1000&sort=updated", null, function(err, res) {
          cb(err, res);
        });
      };

      // List organization repositories
      // -------

      this.orgRepos = function(orgname, cb) {
        _request("GET", "/orgs/"+orgname+"/repos?type=all&per_page=1000&sort=updated&direction=desc", null, function(err, res) {
          cb(err, res);
        });
      };
    };

    // Repository API
    // =======

    Github.Repository = function(options) {
      var repo = options.name;
      var user = options.user;

      var that = this;
      var repoPath = "/repos/" + user + "/" + repo;

      var currentTree = {
        "branch": null,
        "sha": null
      };

      // Uses the cache if branch has not been changed
      // -------

      function updateTree(branch, cb) {
        if (branch === currentTree.branch && currentTree.sha) return cb(null, currentTree.sha);
        that.getRef(branch, function(err, sha) {
          currentTree.branch = branch;
          currentTree.sha = sha;
          cb(err, sha);
        });
      }

      // Get a particular reference
      // -------

      this.getRef = function(ref, cb) {
        _request("GET", repoPath + "/git/refs/heads/" + ref, null, function(err, res) {
          if (err) return cb(err);
          cb(null, res.object.sha);
        });
      };

      // List all branches of a repository
      // -------

      this.listBranches = function(cb) {
        _request("GET", repoPath + "/git/refs/heads", null, function(err, heads) {
          if (err) return cb(err);
          cb(null, _.map(heads, function(head) { return _.last(head.ref.split('/')); }));
        });
      };

      // Retrieve the contents of a blob
      // -------

      this.getBlob = function(sha, cb) {
        _raw_request("GET", repoPath + "/git/blobs/" + sha, null, cb);
      };

      // For a given file path, get the corresponding sha (blob for files, tree for dirs)
      // -------

      this.getSha = function(branch, path, cb) {
        // Just use head if path is empty
        if (path === "") return that.getRef(branch, cb);
        that.getTree(branch+"?recursive=true", function(err, tree) {
          var file = _.select(tree, function(file) {
            return file.path === path;
          })[0];
          cb(null, file ? file.sha : null);
        });
      };

      // Retrieve the tree a commit points to
      // -------

      this.getTree = function(tree, cb) {
        _request("GET", repoPath + "/git/trees/"+tree, null, function(err, res) {
          if (err) return cb(err);
          cb(null, res.tree);
        });
      };

      // Post a new blob object, getting a blob SHA back
      // -------

      this.postBlob = function(content, cb) {
        var data = {
          "content": content,
          "encoding": "utf-8"
        };
        _request("POST", repoPath + "/git/blobs", data, function(err, res) {
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Update an existing tree adding a new blob object getting a tree SHA back
      // -------

      this.updateTree = function(baseTree, path, blob, cb) {
        var data = {
          "base_tree": baseTree,
          "tree": [
            {
              "path": path,
              "mode": "100644",
              "type": "blob",
              "sha": blob
            }
          ]
        };
        _request("POST", repoPath + "/git/trees", data, function(err, res) {
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Post a new tree object having a file path pointer replaced
      // with a new blob SHA getting a tree SHA back
      // -------

      this.postTree = function(tree, cb) {
        _request("POST", repoPath + "/git/trees", { "tree": tree }, function(err, res) {
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Create a new commit object with the current commit SHA as the parent
      // and the new tree SHA, getting a commit SHA back
      // -------

      this.commit = function(parent, tree, message, cb) {
        var data = {
          "message": message,
          "author": {
            "name": options.username
          },
          "parents": [
            parent
          ],
          "tree": tree
        };

        _request("POST", repoPath + "/git/commits", data, function(err, res) {
          currentTree.sha = res.sha; // update latest commit
          if (err) return cb(err);
          cb(null, res.sha);
        });
      };

      // Update the reference of your head to point to the new commit SHA
      // -------

      this.updateHead = function(head, commit, cb) {
        _request("PATCH", repoPath + "/git/refs/heads/" + head, { "sha": commit }, function(err, res) {
          cb(err);
        });
      };

      // Show repository information
      // -------

      this.show = function(cb) {
        _request("GET", repoPath, null, function(err, info) {
          cb(null, info);
        });
      };

      // Read file at given path
      // -------

      this.read = function(branch, path, cb) {
        that.getSha(branch, path, function(err, sha) {
          if (!sha) return cb("not found", null);
          that.getBlob(sha, cb);
        });
      };

      // Remove a file from the tree
      // -------

      this.remove = function(branch, path, cb) {
        updateTree(branch, function(err, latestCommit) {
          that.getTree(latestCommit+"?recursive=true", function(err, tree) {
            // Update Tree
            var newTree = _.reject(tree, function(ref) { return ref.path === path });
            _.each(newTree, function(ref) {
              if (ref.type === "tree") delete ref.sha;
            });

            that.postTree(newTree, function(err, rootTree) {
              that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) {
                that.updateHead(branch, commit, function(err) {
                  cb(err);
                });
              });
            });
          });
        });
      };

      // Move a file to a new location
      // -------

      this.move = function(branch, path, newPath, cb) {
        updateTree(branch, function(err, latestCommit) {
          that.getTree(latestCommit+"?recursive=true", function(err, tree) {
            // Update Tree
            _.each(tree, function(ref) {
              if (ref.path === path) ref.path = newPath;
              if (ref.type === "tree") delete ref.sha;
            });

            that.postTree(tree, function(err, rootTree) {
              that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) {
                that.updateHead(branch, commit, function(err) {
                  cb(err);
                });
              });
            });
          });
        });
      };

      // Write file contents to a given branch and path
      // -------

      this.write = function(branch, path, content, message, cb) {
        updateTree(branch, function(err, latestCommit) {
          that.postBlob(content, function(err, blob) {
            that.updateTree(latestCommit, path, blob, function(err, tree) {
              that.commit(latestCommit, tree, message, function(err, commit) {
                that.updateHead(branch, commit, cb);
              });
            });
          });
        });
      };
    };

    // Top Level API
    // -------

    this.getRepo = function(user, repo) {
      return new Github.Repository({user: user, name: repo});
    };

    this.getUser = function() {
      return new Github.User();
    };
  };
}).call(this);<|endoftext|>


<commit_before>function EvDa(a){function J(a){return a.match(/[?*]/)}function K(a,b){return J(a)?q(n(b?b:D),function(b){return b.match(a)}):a}function L(a,b){var c={};return d(a)?(k(a,function(a){c[a]=b(a)}),c):b(a)}function M(a){if(a in D)return D[a];var b=a.split("."),c=b.pop(),d=b.join(".");if(d){var e=M(d);if(i(e)&&c in e)return e[c]}}function N(a,c,f,g){if(0===arguments.length)return{data:D,events:I,lockMap:B,globs:H};if(d(a)){var h=b.call(arguments,1);return s(a,function(a){return N.apply(N.context,[a].concat(h))})}if(i(a)){var j={};return g=f||{},f=c,g.noexec=1,k(a,function(a,b){j[a]=N(a,b,f,g)}),g.bypass||k(j,function(b,c){e(j[b])&&!e(a[b])&&(a[b]=j[b]())}),R(n(j)[0]),a}return 1==arguments.length?L(a,M):N[e(c)||d(c)&&e(c[0])?w:"set"].apply(this,arguments)}function O(a){k(a.$,function(b){var c=J(b)?H:I;c[b]=o(c[b],a)})}function P(a,b,c){if(d(a)){var e=a.pop();return P(K(e),function(c,d){var e=1==a.length?a[0]:a;return P(e,b,d)},c)}if(i(a))return k(a,function(b,d){J(b)?u(b,L(b,function(a){return P(b,d,c)})):a[b]=P(b,d,c)}),a;var f="set"+a;return I[f]&&(I[f](function(b){N.set.call(N.context,a,b,c)}),delete I[f]),b?a in D?b.call(N.context,D[a],c):N(a,b,u(c||{},A)):a in D}function Q(a,b,c,d){a.S||(a.call(b,c,d),a.once&&O(a))}function R(a){var c=a.split("."),d=c.pop();parts_obj=[],parts_obj[d]=D[a],N.extend.apply(N.context,[c.join("."),parts_obj].concat(b.call(arguments,1)))}var b=Array.prototype.slice,c=Object.prototype.toString,d=[].isArray||function(a){return"[object Array]"===c.call(a)},e=function(a){return!!(a&&a.constructor&&a.call&&a.apply)},f=function(a){return!!(""===a||a&&a.charCodeAt&&a.substr)},g=function(a){return"[object Number]"===c.call(a)},h=function(a){return f(a)||g(a)},i=function(a){return e(a)||f(a)||g(a)||d(a)?!1:null==a?"object"==String(a):"[object Object]"===c.call(a)||!0},j=function(a){return b.call(a)},k=[].forEach?function(a,b){if(h(a))return k([a],b);if(d(a)||a.length)j(a).forEach(b);else for(var c in a)b(c,a[c])}:function(a,b){if(h(a))return k([a],b);if(d(a))for(var c=0,e=a.length;e>c;c++)b(a[c],c);else for(var f in a)b(f,a[f])},l=function(a){return a.length?a[a.length-1]:void 0},m=function(a){var b=[];for(var c in a)b.push(a[c]);return b},n={}.keys||function(a){if(d(a))return a;var b=[];for(var c in a)b.push(c);return b},o=function(a,b){var c=[];return k(a,function(a){a!==b&&c.push(a)}),c},p=function(a){var b,c=[];return k(n(a).sort(),function(a){a!=b&&(b=a,c.push(a))}),c},q=function(a,b){var c=[];return k(a,function(a){b(a)&&c.push(a)}),c},r=function(a){return a&&"length"in a?a.length:0},s=[].map?function(a,b){return a.map(b)}:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)c.push(b(a[d],d));return c},t=function(a){return d(a)?b.call(a):i(a)?u(a,{}):a},u=function(a){return k(b.call(arguments,1),function(b){for(var c in b)void 0!==b[c]&&(a[c]=b[c])}),a},v="first",w="on",x="after",y="or",z=[v,w,x,"test",y],A={once:1},B={},C={},D={},E={},G=[],H={},I={};return k(z,function(a){N[a]=function(c,f,g){if(d(f)){var h=b.call(arguments,2);return s(f,function(b){return N[a].apply(N.context,[c,b].concat(h))})}var i=I;return f?((f.$||(f.$=[])).push(a+c),J(c)&&(i=H),(i[a+c]||(i[a+c]=[])).push(f),k(z,function(a){a in f||(f[a]=function(d){var g=b.call(arguments);return e(d)&&(g=[c].concat(g)),"len"in f||(f[0]=f,f.len=0),f.len++,f[f.len]=N[a].apply(N.context,g),f})}),u(f,g)):i[a+c]}}),u(N,{_:{},context:this,list:{},isPaused:!1,db:D,events:function(a,b){return b?I[b+a]:a?L(z.concat(["set"]),function(b){return I[b+a]}):I},del:O,whenSet:P,isset:P,pause:function(){return N.isPaused?!1:(N.isPaused=!0,N._.set=N.set,N.set=function(){G.push(["set",arguments])},!0)},play:function(){if(N.isPaused){N.isPaused=!1;var a=EvDa();return N.set=N._.set,k(G,function(b){a[b[0]].apply(a,b[1])}),G=[],N(a.db),!0}return!1},setter:function(a,b){return I["set"+a]=b,I[w+a]?P(a):void 0},when:function(a,c,g){if(i(a)){var h={},j={},l=function(a,b){j[b.key]=!1,b()},n=function(a,d){j[d.key]=!0,-1==m(j).indexOf(!1)&&c.apply(N.context,b.call(arguments))};return k(a,function(a,b){h[a+"-test"]=N.test(a,l),h[a]=N.when(a,b,n),j[a]=!1}),h}if(f(c))try{var o=new Function("x","return x"+c);o(),c=o}catch(p){}else if(2==arguments.length)return N.isset(a,c);return N(a,function(a){(d(c)&&c.sort().join("")===a.sort().join("")||e(c)&&c(a)||a===c)&&g.apply(N.context,b.call(arguments))})},empty:function(){for(var a in D)delete D[a]},incr:function(a,b,c){return b=b||1,N.set(a,g(D[a])?D[a]+b:b,c)},decr:function(a,b,c){return b=b||1,N.set(a,D[a]-b||0,c)},push:function(a,b,c){return N.set(a,[].concat(D[a]||[],[b]),c)},pop:function(a,b){return N.set(a,D[a].slice(0,-1),b)},traceList:[],group:function(a){var b=j(arguments),a=b.shift(),c=N.apply(0,b);return N.list[a]||(N.list[a]=[]),e(c)?N.list[a].push(c):k(c,function(b,c){N.list[a].push(b)}),function(){return N.group.apply(0,[a].concat(j(arguments)))}},extend:function(a,c){return N.set.apply(N.context,[a,u({},D[a]||{},c)].concat(b.call(arguments,2)))},count:function(a){return 0===arguments.length?Math.max.apply(this,m(E)):E[a]},set:function(a,c,d,e){e=e||{};var f,g=e.bypass,h=e.coroutine||function(){return!0},i="value"in e,j=e.noexec;if(1==arguments.length){var l=function(){N.set.apply(N.context,[a].concat(b.call(arguments)))};return N.set.call(N.context,a,void 0),l}if(B[a]>0)return D[a];B[a]=(B[a]||0)+1;var n,z,m="test"+a,o=b.call(arguments),p=r(I[m]),q=0,s=p&&!g,A=function(){k(I[y+a]||[],function(a){Q(a,N.context,i?e.value:F.value,F,F.meta)})},F=s?function(b){return z|=b===!1,--p?(q++,h(F,!1)?(f=I[m][q].call(N.context,i?e.value:F.value,F,F.meta),(f===!0||f===!1)&&F(f)):A()):z?A():h(F,!0)?N.set(a,F.value,F.meta,{bypass:1}):A(),b}:{};if(F.old=t(D[a]),u(F,{meta:d||{},done:F,result:F,key:a,value:c}),s)B[a]--,C[a]!==!0&&(C[a]=!0,h(F,!1)?(f=I[m][q].call(N.context,i?e.value:F.value,F,F.meta),(f===!0||f===!1)&&F(f)):A(),C[a]=!1),n=D[a];else if(k(N.traceList,function(a){a.call(N.context,o)}),h(F,!0)&&(c=F.value,!e.onlychange||c!==D[a])){e.noset||(D[a]=c,""!=a&&(E[a]=(E[a]||0)+1));var G=arguments,H=function(){return k((I[v+a]||[]).concat(I[w+a]||[]),function(a){F.last=Q(a,N.context,c,F)}),a.length>0&&(delete e.coroutine,R.apply(N.context,[a].concat(b.call(G,2)))),k(I[x+a]||[],function(a){F.last=Q(a,N.context,c,F)}),c};n=j?H:H.call(N.context)}return B[a]=0,n},fire:function(a,b){k(a,function(a){N.set(a,D[a],b,{noset:!0})})},once:function(a,b,c){return i(a)&&(a=m(a)),d(a)?s(a,function(a){N.once.call(N.context,a,b,c)}):b?N.once(N(a,b,c)):u(a,A)},enable:function(a){return k(N.list[a],function(b){b.S&&b.S[a]&&delete b.S[a],0==r(b.S)&&delete b.S}),N.list[a]},osetadd:function(a,b,c){var e=D[a]||[];return N(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=t(e),k(c,function(b){-1==a.set.indexOf(b)&&a.set.push(b)}),b&&(a.value=a.set),e.length!=a.set.length}})},setadd:function(a,b,c){var e=D[a]||[];return N(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=p(e.concat(c)),b&&(a.value=a.set),e.length!=a.set.length}})},settoggle:function(a,b,c){var d=-1===(D[a]||[]).indexOf(b)?"add":"del";return N["set"+d](a,b,c)},setdel:function(a,b,c){var d=D[a]||[],e=o(d,b);return d.length!=e.length?N(a,e,c,{value:b}):e},disable:function(a){return k(N.list[a],function(b){(b.S||(b.S={}))[a]=!0}),N.list[a]},unset:function(){var a=!0;return k(arguments,function(b){a&=b in D;var g,h,i,c=b.split("."),d="",e=c.length,f=c[e-1];for(g=0;e>g;g++)if(d=c.slice(0,g).join("."),i=D[d]){for(h=g;e-1>h;h++)i=i[c[h]];delete i[f]}delete D[b]}),a},find:function(a){return q(n(D),function(b){return b.match(a)})},changed:function(a,b){return N.on(a,function(a,c){var d=r(a),e=r(c.old);d-e==1?b.call(N.context,l(a)):d>e&&b.call(N.context,j(a).slice(e))})},sniff:function(){var a={},b=+new Date,c=function(c){a[c[0]]||console.log(+new Date-b,c)},d=function(){},e=c;N.traceList.unshift(function(a){e(a)}),N.sniff=function(b){return arguments.length>0?f(b)?(a[b]=!a[b],"[Un]ignoring "+b):(e=b?c:d,b):n(a)}}}),N.setAdd=N.setadd,N.setToggle=N.settoggle,N.osetAdd=N.osetadd,N.setDel=N.setdel,N.isSet=N.isset,N.get=N,N.change=N.on,N.add=N.push,N.isArray=d,arguments.length>0&&N(a),N}<commit_msg>minified<commit_after>function EvDa(a){function J(a){return a.match(/[?*]/)}function K(a,b){return J(a)?q(n(b?b:D),function(b){return b.match(a)}):a}function L(a,b){var c={};return d(a)?(k(a,function(a){c[a]=b(a)}),c):b(a)}function M(a){if(a in D)return D[a];var b=a.split("."),c=b.pop(),d=b.join(".");if(d){var e=M(d);if(i(e)&&c in e)return e[c]}}function N(a,c,f,g){if(0===arguments.length)return{data:D,events:I,lockMap:B,globs:H};if(d(a)){var h=b.call(arguments,1);return s(a,function(a){return N.apply(N.context,[a].concat(h))})}if(i(a)){var j={};return g=f||{},f=c,g.noexec=1,k(a,function(a,b){j[a]=N(a,b,f,g)}),g.bypass||k(j,function(b,c){e(j[b])&&!e(a[b])&&(a[b]=j[b]())}),R(n(j)[0]),a}return 1==arguments.length?L(a,M):N[e(c)||d(c)&&e(c[0])?w:"set"].apply(this,arguments)}function O(a){k(a.$,function(b){var c=J(b)?H:I;c[b]=o(c[b],a)})}function P(a,b,c){if(d(a)){var e=a.pop();return P(K(e),function(c,d){var e=1==a.length?a[0]:a;return P(e,b,d)},c)}if(i(a))return k(a,function(b,d){J(b)?u(b,L(b,function(a){return P(b,d,c)})):a[b]=P(b,d,c)}),a;var f="set"+a;return I[f]&&(I[f](function(b){N.set.call(N.context,a,b,c)}),delete I[f]),b?a in D?b.call(N.context,D[a],c):N(a,b,u(c||{},A)):a in D}function Q(a,b,c,d){a.S||(a.call(b,c,d),a.once&&O(a))}function R(a){var c=a.split("."),d=c.pop();parts_obj=[],parts_obj[d]=D[a],N.extend.apply(N.context,[c.join("."),parts_obj].concat(b.call(arguments,1)))}var b=Array.prototype.slice,c=Object.prototype.toString,d=[].isArray||function(a){return"[object Array]"===c.call(a)},e=function(a){return!!(a&&a.constructor&&a.call&&a.apply)},f=function(a){return!!(""===a||a&&a.charCodeAt&&a.substr)},g=function(a){return"[object Number]"===c.call(a)},h=function(a){return f(a)||g(a)},i=function(a){return e(a)||f(a)||g(a)||d(a)?!1:null==a?"object"==String(a):"[object Object]"===c.call(a)||!0},j=function(a){return b.call(a)},k=[].forEach?function(a,b){if(h(a))return k([a],b);if(d(a)||a.length)j(a).forEach(b);else for(var c in a)b(c,a[c])}:function(a,b){if(h(a))return k([a],b);if(d(a))for(var c=0,e=a.length;e>c;c++)b(a[c],c);else for(var f in a)b(f,a[f])},l=function(a){return a.length?a[a.length-1]:void 0},m=function(a){var b=[];for(var c in a)b.push(a[c]);return b},n={}.keys||function(a){if(d(a))return a;var b=[];for(var c in a)b.push(c);return b},o=function(a,b){var c=[];return k(a,function(a){a!==b&&c.push(a)}),c},p=function(a){var b,c=[];return k(n(a).sort(),function(a){a!=b&&(b=a,c.push(a))}),c},q=function(a,b){var c=[];return k(a,function(a){b(a)&&c.push(a)}),c},r=function(a){return a&&"length"in a?a.length:0},s=[].map?function(a,b){return a.map(b)}:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)c.push(b(a[d],d));return c},t=function(a){return d(a)?b.call(a):i(a)?u(a,{}):a},u=function(a){return k(b.call(arguments,1),function(b){for(var c in b)void 0!==b[c]&&(a[c]=b[c])}),a},v="first",w="on",x="after",y="or",z=[v,w,x,"test",y],A={once:1},B={},C={},D={},E={},G=[],H={},I={};return k(z,function(a){N[a]=function(c,f,g){if(d(f)){var h=b.call(arguments,2);return s(f,function(b){return N[a].apply(N.context,[c,b].concat(h))})}var i=I;return f?((f.$||(f.$=[])).push(a+c),J(c)&&(i=H),(i[a+c]||(i[a+c]=[])).push(f),k(z,function(a){a in f||(f[a]=function(d){var g=b.call(arguments);return e(d)&&(g=[c].concat(g)),"len"in f||(f[0]=f,f.len=0),f.len++,f[f.len]=N[a].apply(N.context,g),f})}),u(f,g)):i[a+c]}}),u(N,{_:{},context:this,list:{},isPaused:!1,db:D,events:function(a,b){return b?I[b+a]:a?L(z.concat(["set"]),function(b){return I[b+a]}):I},del:O,whenSet:P,isset:P,pause:function(){return N.isPaused?!1:(N.isPaused=!0,N._.set=N.set,N.set=function(){G.push(["set",arguments])},!0)},play:function(){if(N.isPaused){N.isPaused=!1;var a=EvDa();return N.set=N._.set,k(G,function(b){a[b[0]].apply(a,b[1])}),G=[],N(a.db),!0}return!1},setter:function(a,b){return I["set"+a]=b,I[w+a]?P(a):void 0},when:function(a,c,g){if(i(a)){var h={},j={},l=function(a,b){j[b.key]=!1,b()},n=function(a,d){j[d.key]=!0,-1==m(j).indexOf(!1)&&c.apply(N.context,b.call(arguments))};return k(a,function(a,b){h[a+"-test"]=N.test(a,l),h[a]=N.when(a,b,n),j[a]=!1}),h}if(f(c))try{var o=new Function("x","return x"+c);o(),c=o}catch(p){}else if(2==arguments.length)return N.isset(a,c);return N(a,function(a){(d(c)&&c.sort().join("")===a.sort().join("")||e(c)&&c(a)||a===c)&&g.apply(N.context,b.call(arguments))})},empty:function(){for(var a in D)delete D[a]},incr:function(a,b,c){return b=b||1,N.set(a,g(D[a])?D[a]+b:b,c)},decr:function(a,b,c){return b=b||1,N.set(a,D[a]-b||0,c)},push:function(a,b,c){return N.set(a,[].concat(D[a]||[],[b]),c)},pop:function(a,b){return N.set(a,D[a].slice(0,-1),b)},traceList:[],group:function(a){var b=j(arguments),a=b.shift(),c=N.apply(0,b);return N.list[a]||(N.list[a]=[]),e(c)?N.list[a].push(c):k(c,function(b,c){N.list[a].push(b)}),function(){return N.group.apply(0,[a].concat(j(arguments)))}},extend:function(a,c){return N.set.apply(N.context,[a,u({},D[a]||{},c)].concat(b.call(arguments,2)))},count:function(a){return 0===arguments.length?Math.max.apply(this,m(E)):E[a]},set:function(a,c,d,e){e=e||{};var f,g=e.bypass,h=e.coroutine||function(){return!0},i="value"in e,j=e.noexec;if(1==arguments.length){var l=function(){N.set.apply(N.context,[a].concat(b.call(arguments)))};return N.set.call(N.context,a,void 0),l}if(B[a]>0)return k(N.traceList,function(a){a.call(N.context,u({locked:!0},o))}),D[a];B[a]=(B[a]||0)+1;var n,z,m="test"+a,o=b.call(arguments),p=r(I[m]),q=0,s=p&&!g,A=function(){k(I[y+a]||[],function(a){Q(a,N.context,i?e.value:F.value,F,F.meta)})},F=s?function(b){return z|=b===!1,--p?(q++,h(F,!1)?(f=I[m][q].call(N.context,i?e.value:F.value,F,F.meta),(f===!0||f===!1)&&F(f)):A()):z?A():h(F,!0)?N.set(a,F.value,F.meta,{bypass:1}):A(),b}:{};if(F.old=t(D[a]),u(F,{meta:d||{},done:F,result:F,key:a,value:c}),s)B[a]--,C[a]!==!0&&(C[a]=!0,h(F,!1)?(f=I[m][q].call(N.context,i?e.value:F.value,F,F.meta),(f===!0||f===!1)&&F(f)):A(),C[a]=!1),n=D[a];else if(k(N.traceList,function(a){a.call(N.context,o)}),h(F,!0)&&(c=F.value,!e.onlychange||c!==D[a])){e.noset||(D[a]=c,""!=a&&(E[a]=(E[a]||0)+1));var G=arguments,H=function(){return k((I[v+a]||[]).concat(I[w+a]||[]),function(a){F.last=Q(a,N.context,c,F)}),a.length>0&&(delete e.coroutine,R.apply(N.context,[a].concat(b.call(G,2)))),k(I[x+a]||[],function(a){F.last=Q(a,N.context,c,F)}),c};n=j?H:H.call(N.context)}return B[a]=0,n},fire:function(a,b){k(a,function(a){N.set(a,D[a],b,{noset:!0})})},once:function(a,b,c){return i(a)&&(a=m(a)),d(a)?s(a,function(a){N.once.call(N.context,a,b,c)}):b?N.once(N(a,b,c)):u(a,A)},enable:function(a){return k(N.list[a],function(b){b.S&&b.S[a]&&delete b.S[a],0==r(b.S)&&delete b.S}),N.list[a]},osetadd:function(a,b,c){var e=D[a]||[];return N(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=t(e),k(c,function(b){-1==a.set.indexOf(b)&&a.set.push(b)}),b&&(a.value=a.set),e.length!=a.set.length}})},setadd:function(a,b,c){var e=D[a]||[];return N(a,b,c,{coroutine:function(a,b){var c=d(a.value)?a.value:[a.value];return a.set=p(e.concat(c)),b&&(a.value=a.set),e.length!=a.set.length}})},settoggle:function(a,b,c){var d=-1===(D[a]||[]).indexOf(b)?"add":"del";return N["set"+d](a,b,c)},setdel:function(a,b,c){var d=D[a]||[],e=o(d,b);return d.length!=e.length?N(a,e,c,{value:b}):e},disable:function(a){return k(N.list[a],function(b){(b.S||(b.S={}))[a]=!0}),N.list[a]},unset:function(){var a=!0;return k(arguments,function(b){a&=b in D;var g,h,i,c=b.split("."),d="",e=c.length,f=c[e-1];for(g=0;e>g;g++)if(d=c.slice(0,g).join("."),i=D[d]){for(h=g;e-1>h;h++)i=i[c[h]];delete i[f]}delete D[b]}),a},find:function(a){return q(n(D),function(b){return b.match(a)})},changed:function(a,b){return N.on(a,function(a,c){var d=r(a),e=r(c.old);d-e==1?b.call(N.context,l(a)):d>e&&b.call(N.context,j(a).slice(e))})},sniff:function(){var a={},b=+new Date,c=function(c){a[c[0]]||console.log(+new Date-b,c)},d=function(){},e=c;N.traceList.unshift(function(a){e(a)}),N.sniff=function(b){return arguments.length>0?f(b)?(a[b]=!a[b],"[Un]ignoring "+b):(e=b?c:d,b):n(a)}}}),N.setAdd=N.setadd,N.setToggle=N.settoggle,N.osetAdd=N.osetadd,N.setDel=N.setdel,N.isSet=N.isset,N.get=N,N.change=N.on,N.add=N.push,N.isArray=d,arguments.length>0&&N(a),N}<|endoftext|>


<commit_before>/**
 * ===============================================================
 * eventize.js v0.0.11 -- https://github.com/spearwolf/eventize
 * ===============================================================
 *
 * Copyright 2015-16 Wolfger Schramm <wolfger@spearwolf.de>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.eventize=n()}}(function(){return function n(e,t,i){function f(r,c){if(!t[r]){if(!e[r]){var u="function"==typeof require&&require;if(!c&&u)return u(r,!0);if(o)return o(r,!0);var l=Error("Cannot find module '"+r+"'");throw l.code="MODULE_NOT_FOUND",l}var a=t[r]={exports:{}};e[r][0].call(a.exports,function(n){var t=e[r][1][n];return f(t?t:n)},a,a.exports,n,e,t,i)}return t[r].exports}for(var o="function"==typeof require&&require,r=0;r<i.length;r++)f(i[r]);return f}({1:[function(n,e,t){"use strict";function i(n){function e(){return++d.lastCallbackId}function t(n,e){return n.prio!==e.prio?e.prio-n.prio:n.id-e.id}function a(n){if(n){var e=d.boundObjects.indexOf(n);return e===-1&&d.boundObjects.push(n),n}}function s(n,e,t){var f,o,r,c;for(o in t)t.hasOwnProperty(o)&&(r=e[o],"function"==typeof r&&(f=t[o],Array.isArray(f)?(c=f[0],f=f[1]):c=i.PRIO_DEFAULT,n.on(f,c,r)));return n}function p(n,e,t){function f(){var e,i,f;if(p)for(e=0;e<p;e++)i=d.boundObjects[e],f=i[n],"function"==typeof f?t(f,i):i[c]&&t(null,i)}if(!(v.silenced||v.off.indexOf(n)>=0)){var o,r,l,a=d.callbacks[n],s=d.callbacks[u],p=d.boundObjects.length,y=!1;if(a||s.length)for(a=a?a.concat(s):s,r=a.length,o=0;o<r;o++)l=a[o],!y&&l&&l.prio<i.PRIO_DEFAULT&&(f(),y=!0),e(l);y||f()}}if(n[c])return n;var d={lastCallbackId:0,callbacks:{},boundObjects:[]};d.callbacks[u]=[];var v=o({},{silenced:!1,off:[]});return r(n,c,v),void 0===i.PRIO_DEFAULT&&o(i,{PRIO_MAX:Number.POSITIVE_INFINITY,PRIO_A:1e9,PRIO_B:1e7,PRIO_C:1e5,PRIO_DEFAULT:0,PRIO_LOW:-1e5,PRIO_MIN:Number.NEGATIVE_INFINITY}),n.on=function(n,r,c){var a=arguments.length;if(0===a)return void(v.silenced&&(f(v,"silenced",!1),v.off.length=0));var s;if(1===a){if("string"==typeof n)return s=v.off.indexOf(n),void(s>=0&&v.off.splice(s,1));if("object"!=typeof n&&"function"!=typeof n)return void console.warn(l,".on() called with insufficient arguments!",arguments);c=n,n=u,r=i.PRIO_DEFAULT}2===a&&(c=r,r=i.PRIO_DEFAULT);var p=d.callbacks,y=p[n]||(p[n]=[]),b=e(),h=o({},{id:b,fn:c,prio:"number"!=typeof r?i.PRIO_DEFAULT:r,isFunction:"function"==typeof c});return y.push(h),y.sort(t),b},n.once=function(e,t,f){var o=arguments.length;if(!o||o>3)return void console.warn(l,".once() called with insufficient arguments!",arguments);1===o?(f=e,e=u,t=i.PRIO_DEFAULT):2===o&&(f=t,t=i.PRIO_DEFAULT);var r=n.on(e,t,function(){var e=f.apply(this,arguments);return n.off(r),e});return r},n.off=function(n){if(0===arguments.length)return void(v.silenced||(f(v,"silenced",!0),v.off.length=0));if("string"==typeof n)return void(v.off.indexOf(n)===-1&&v.off.push(n));var e,t,i,o,r,c=d.callbacks,u="object"==typeof n;if("number"==typeof n||"function"==typeof n||u)for(r=Object.keys(c),i=0;i<r.length;i++)for(o=c[r[i]],t=0;t<o.length;t++)if(e=o[t],(e.id===n||e.fn===n)&&(o.splice(t,1),!u))return;u&&(t=d.boundObjects.indexOf(n),t>=0&&d.boundObjects.splice(t,1))},n.connect=function(n,e){var t=arguments.length;return 1===t?a(n):2===t?s(this,n,e):void console.warn(l,".connect() called with insufficient arguments!",arguments)},n.emit=function(){for(var n=Array(arguments.length),e=0;e<n.length;++e)n[e]=arguments[e];var t,i,f,o=this;n.length>1&&"string"!=typeof n[0]&&"string"==typeof n[1]?(i=n.shift(),t=n.shift(),n[n.length-1]=i,f=n):(t=n.shift(),f=n.concat([o])),p(t,function(e){if(e.isFunction)e.fn.apply(o,n);else{var i=e.fn[t];"function"==typeof i?i.apply(e.fn,f):e.fn[c]&&e.fn.emit.apply(e.fn,[t].concat(n))}},function(n,e){n?n.apply(e,f):e.emit.apply(e,[o,t].concat(f))})},n.emitReduce=function(){function n(n){void 0!==n&&(i=n)}for(var e=Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];var i,f=e.shift();0===e.length?(i={},e.push(i)):n(e[0]);var o=this,r=[f].concat(e),u=e.concat([o]);return p(f,function(t){if(t.isFunction)e[0]=i,n(t.fn.apply(o,e));else{var l=t.fn[f];"function"==typeof l?(u[0]=i,n(l.apply(t.fn,u))):t.fn[c]&&(r[1]=i,n(t.fn.emitReduce.apply(t.fn,r)))}},function(e,t){e&&(u[0]=i,n(e.apply(t,u)))}),i},n}function f(n,e,t){return Object.defineProperty(n,e,{value:t,configurable:!0,enumerable:!0}),n}function o(n,e){var t,i=Object.keys(e);for(t=i.length;t--;)f(n,i[t],e[i[t]]);return n}function r(n,e,t){return Object.defineProperty(n,e,{value:t,configurable:!0}),n}var c=void 0!==typeof Symbol?Symbol("eventize"):"_eventize",u="*",l="[eventize.js]";i.is=function(n){return!(!n||!n[c])},i.EventizeNamespace=c,e.exports=i},{}]},{},[1])(1)});<commit_msg>0.0.12 build<commit_after>/**
 * ===============================================================
 * eventize.js v0.0.12 -- https://github.com/spearwolf/eventize
 * ===============================================================
 *
 * Copyright 2015-16 Wolfger Schramm <wolfger@spearwolf.de>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.eventize=n()}}(function(){return function n(e,t,i){function f(r,c){if(!t[r]){if(!e[r]){var u="function"==typeof require&&require;if(!c&&u)return u(r,!0);if(o)return o(r,!0);var l=Error("Cannot find module '"+r+"'");throw l.code="MODULE_NOT_FOUND",l}var a=t[r]={exports:{}};e[r][0].call(a.exports,function(n){var t=e[r][1][n];return f(t?t:n)},a,a.exports,n,e,t,i)}return t[r].exports}for(var o="function"==typeof require&&require,r=0;r<i.length;r++)f(i[r]);return f}({1:[function(n,e,t){"use strict";function i(n){function e(){return++d.lastCallbackId}function t(n,e){return n.prio!==e.prio?e.prio-n.prio:n.id-e.id}function a(n){if(n){var e=d.boundObjects.indexOf(n);return e===-1&&d.boundObjects.push(n),n}}function s(n,e,t){var f,o,r,c;for(o in t)t.hasOwnProperty(o)&&(r=e[o],"function"==typeof r&&(f=t[o],Array.isArray(f)?(c=f[0],f=f[1]):c=i.PRIO_DEFAULT,n.on(f,c,r)));return n}function p(n,e,t){function f(){var e,i,f;if(p)for(e=0;e<p;e++)i=d.boundObjects[e],f=i[n],"function"==typeof f?t(f,i):i[c]&&t(null,i)}if(!(v.silenced||v.off.indexOf(n)>=0)){var o,r,l,a=d.callbacks[n],s=d.callbacks[u],p=d.boundObjects.length,y=!1;if(a||s.length)for(a=a?a.concat(s):s,r=a.length,o=0;o<r;o++)l=a[o],!y&&l&&l.prio<i.PRIO_DEFAULT&&(f(),y=!0),e(l);y||f()}}if(n[c])return n;var d={lastCallbackId:0,callbacks:{},boundObjects:[]};d.callbacks[u]=[];var v=o({},{silenced:!1,off:[]});return r(n,c,v),void 0===i.PRIO_DEFAULT&&o(i,{PRIO_MAX:Number.POSITIVE_INFINITY,PRIO_A:1e9,PRIO_B:1e7,PRIO_C:1e5,PRIO_DEFAULT:0,PRIO_LOW:-1e5,PRIO_MIN:Number.NEGATIVE_INFINITY}),n.on=function(n,r,c){var a=arguments.length;if(0===a)return void(v.silenced&&(f(v,"silenced",!1),v.off.length=0));var s;if(1===a){if("string"==typeof n)return s=v.off.indexOf(n),void(s>=0&&v.off.splice(s,1));if("object"!=typeof n&&"function"!=typeof n)return void console.warn(l,".on() called with insufficient arguments!",arguments);c=n,n=u,r=i.PRIO_DEFAULT}2===a&&(c=r,r=i.PRIO_DEFAULT);var p=d.callbacks,y=p[n]||(p[n]=[]),b=e(),h=o({},{id:b,fn:c,prio:"number"!=typeof r?i.PRIO_DEFAULT:r,isFunction:"function"==typeof c});return y.push(h),y.sort(t),b},n.once=function(e,t,f){var o=arguments.length;if(!o||o>3)return void console.warn(l,".once() called with insufficient arguments!",arguments);1===o?(f=e,e=u,t=i.PRIO_DEFAULT):2===o&&(f=t,t=i.PRIO_DEFAULT);var r=n.on(e,t,function(){var e=f.apply(this,arguments);return n.off(r),e});return r},n.off=function(n){if(0===arguments.length)return void(v.silenced||(f(v,"silenced",!0),v.off.length=0));if("string"==typeof n)return void(v.off.indexOf(n)===-1&&v.off.push(n));var e,t,i,o,r,c=d.callbacks,u="object"==typeof n;if("number"==typeof n||"function"==typeof n||u)for(r=Object.keys(c),i=0;i<r.length;i++)for(o=c[r[i]],t=0;t<o.length;t++)if(e=o[t],(e.id===n||e.fn===n)&&(o.splice(t,1),!u))return;u&&(t=d.boundObjects.indexOf(n),t>=0&&d.boundObjects.splice(t,1))},n.connect=function(n,e){var t=arguments.length;return 1===t?a(n):2===t?s(this,n,e):void console.warn(l,".connect() called with insufficient arguments!",arguments)},n.emit=function(){for(var n=Array(arguments.length),e=0;e<n.length;++e)n[e]=arguments[e];var t,i,f,o=this;n.length>1&&"string"!=typeof n[0]&&"string"==typeof n[1]?(i=n.shift(),t=n.shift(),n[n.length-1]=i,f=n):(t=n.shift(),f=n.concat([o])),p(t,function(e){if(e.isFunction)e.fn.apply(o,n);else{var i=e.fn[t];"function"==typeof i?i.apply(e.fn,f):e.fn[c]&&e.fn.emit.apply(e.fn,[t].concat(n))}},function(n,e){n?n.apply(e,f):e.emit.apply(e,[o,t].concat(f))})},n.emitReduce=function(){function n(n){void 0!==n&&(i=n)}for(var e=Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];var i,f=e.shift();0===e.length?(i={},e.push(i)):n(e[0]);var o=this,r=[f].concat(e),u=e.concat([o]);return p(f,function(t){if(t.isFunction)e[0]=i,n(t.fn.apply(o,e));else{var l=t.fn[f];"function"==typeof l?(u[0]=i,n(l.apply(t.fn,u))):t.fn[c]&&(r[1]=i,n(t.fn.emitReduce.apply(t.fn,r)))}},function(e,t){e&&(u[0]=i,n(e.apply(t,u)))}),i},n}function f(n,e,t){return Object.defineProperty(n,e,{value:t,configurable:!0,enumerable:!0}),n}function o(n,e){var t,i=Object.keys(e);for(t=i.length;t--;)f(n,i[t],e[i[t]]);return n}function r(n,e,t){return Object.defineProperty(n,e,{value:t,configurable:!0}),n}var c=void 0!==typeof Symbol?Symbol("eventize"):"_eventize",u="*",l="[eventize.js]";i.is=function(n){return!(!n||!n[c])},i.EventizeNamespace=c,e.exports=i},{}]},{},[1])(1)});<|endoftext|>


<commit_before>
// dev hostname
global.CDEF("DNS_NAME", "dev2.skool51.com");

// db
global.CDEF("DB_WRAPPER", "/lib/db/shredis.js");<commit_msg>add the DB_OPTIONS setting;<commit_after>
// dev hostname
global.CDEF("DNS_NAME", "dev2.skool51.com");

// db
global.CDEF("DB_WRAPPER", "/lib/db/shredis.js");
global.CDEF("DB_OPTIONS", {});
<|endoftext|>


<commit_before>/* eslint-disable react/no-unused-state */

import { h, Component } from 'preact';
import linkState from 'linkstate';

import './style.css';
import { Input, Checkbox } from './components';
import * as storage from './index';

const githubTokenDescription = () => (

    Get the most out of OctoLinker by providing a GitHub access token.

);

export default class Form extends Component {
  async componentWillMount() {
    this.setState({ ...(await storage.load()) });
  }

  componentWillUpdate(
    nextProps,
    { tokenLoaded, githubToken, errorMessage, ...rest },
  ) {
    storage.save(rest);
  }

  onBlur(event) {
    if (event.target.name === 'githubToken') {
      this.validateToken();
    }
  }

  async validateToken() {
    const { githubToken } = this.state;

    if (!githubToken) {
      this.setState({
        errorMessage: undefined,
        tokenLoaded: false,
      });

      storage.save({
        githubToken: null,
      });
      return;
    }

    const response = await fetch('https://api.github.com/user', {
      headers: { Authorization: `token ${githubToken}` },
    }).then(res => res.json());

    if (!response.login) {
      this.setState({
        tokenLoaded: false,
        errorMessage: response.message || 'Something went wrong',
      });
      return;
    }

    this.setState({
      errorMessage: undefined,
      tokenLoaded: true,
    });

    storage.save({
      githubToken,
    });
  }

  tokenMessage() {
    return
Token successfully added
;
  }

  render(props, state) {
    const { errorMessage, tokenLoaded } = this.state;

    return (
      <form
        onChange={this.onBlur.bind(this)}
        onSubmit={event => event.preventDefault()}
      >
        {tokenLoaded && this.tokenMessage()}
        <Input
          type="password"
          name="githubToken"
          label="Access token"
          description={githubTokenDescription()}
          value={state.githubToken}
          error={errorMessage}
          onInput={linkState(this, 'githubToken')}
        />

          For public repositories,{' '}

            create a token
          {' '}
          with the{' '}

            public_repo
          {' '}
          permission. If you want OctoLinker for private repositories,
          you'll need to{' '}

            create a token
          {' '}
          with the{' '}

            repo
          {' '}
          permissions. Then copy and paste it into the input field above.

            Why is a GitHub token needed?

              OctoLinker uses the{' '}

                GitHub API
              {' '}
              to retrieve repository metadata. By default, it makes
              unauthenticated requests to the GitHub API. However, there are two
              situations when requests must be authenticated:

You access a private repository

                  You exceed{' '}

                    the rate limit for unauthenticated requests

              When that happens, OctoLinker needs an GitHub access token in
              order to continue to work.

        <Checkbox
          name="enablePrivateRepositories"
          label="Private repositories"
          description="Enable support for private repositories (requires a GitHub token)"
          checked={state.enablePrivateRepositories}
          onClick={linkState(this, 'enablePrivateRepositories')}
        />
        <Checkbox
          name="showUpdateNotification"
          label="Update notification"
          description="Show a notification if a new version is available."
          checked={state.showUpdateNotification}
          onClick={linkState(this, 'showUpdateNotification')}
        />
      </form>
    );
  }
}
<commit_msg>Auto store token after pasting (#698)<commit_after>/* eslint-disable react/no-unused-state */

import { h, Component } from 'preact';
import linkState from 'linkstate';

import './style.css';
import { Input, Checkbox } from './components';
import * as storage from './index';

const githubTokenDescription = () => (

    Get the most out of OctoLinker by providing a GitHub access token.

);

export default class Form extends Component {
  async componentWillMount() {
    this.setState({ ...(await storage.load()) });
  }

  componentWillUpdate(
    nextProps,
    { tokenLoaded, githubToken, errorMessage, ...rest },
  ) {
    storage.save(rest);
  }

  onBlur(event) {
    if (event.target.name === 'githubToken') {
      this.validateToken();
    }
  }

  async validateToken() {
    const { githubToken } = this.state;

    if (!githubToken) {
      this.setState({
        errorMessage: undefined,
        tokenLoaded: false,
      });

      storage.save({
        githubToken: null,
      });
      return;
    }

    const response = await fetch('https://api.github.com/user', {
      headers: { Authorization: `token ${githubToken}` },
    }).then(res => res.json());

    if (!response.login) {
      this.setState({
        tokenLoaded: false,
        errorMessage: response.message || 'Something went wrong',
      });
      return;
    }

    this.setState({
      errorMessage: undefined,
      tokenLoaded: true,
    });

    storage.save({
      githubToken,
    });
  }

  tokenMessage() {
    return
Token successfully added
;
  }

  render(props, state) {
    const { errorMessage, tokenLoaded } = this.state;

    return (
      <form
        onChange={this.onBlur.bind(this)}
        onSubmit={event => event.preventDefault()}
      >
        {tokenLoaded && this.tokenMessage()}
        <Input
          type="password"
          name="githubToken"
          label="Access token"
          description={githubTokenDescription()}
          value={state.githubToken}
          error={errorMessage}
          onInput={event => {
            linkState(this, 'githubToken')(event);
            this.validateToken();
          }}
        />

          For public repositories,{' '}

            create a token
          {' '}
          with the{' '}

            public_repo
          {' '}
          permission. If you want OctoLinker for private repositories,
          you'll need to{' '}

            create a token
          {' '}
          with the{' '}

            repo
          {' '}
          permissions. Then copy and paste it into the input field above.

            Why is a GitHub token needed?

              OctoLinker uses the{' '}

                GitHub API
              {' '}
              to retrieve repository metadata. By default, it makes
              unauthenticated requests to the GitHub API. However, there are two
              situations when requests must be authenticated:

You access a private repository

                  You exceed{' '}

                    the rate limit for unauthenticated requests

              When that happens, OctoLinker needs an GitHub access token in
              order to continue to work.

        <Checkbox
          name="enablePrivateRepositories"
          label="Private repositories"
          description="Enable support for private repositories (requires a GitHub token)"
          checked={state.enablePrivateRepositories}
          onClick={linkState(this, 'enablePrivateRepositories')}
        />
        <Checkbox
          name="showUpdateNotification"
          label="Update notification"
          description="Show a notification if a new version is available."
          checked={state.showUpdateNotification}
          onClick={linkState(this, 'showUpdateNotification')}
        />
      </form>
    );
  }
}
<|endoftext|>


<commit_before>
function checkSession( req, res, next ) {
  if ( req.isAuthenticated() ) {
    return next();
  }
  res.redirect( '/auth/signin' );
}

function checkAuthorization( req, res, next ) {
  if ( req.isAuthenticated() && req.user.group === 'admin' ) {
    return next();
  }
  res.status( 401 ).send( { message: 'Usuário não autorizado' } );
}

module.exports = {
  checkSession,
  checkAuthorization
};
<commit_msg>[UPDATE]: O nome das funções foram renomeadas.<commit_after>
function isAuthenticated( req, res, next ) {
  if ( req.isAuthenticated() || req.originalUrl === '/auth/signin' ) {
    return next();
  }
  res.redirect( '/auth/signin' );
}

function isAuthorized( req, res, next ) {
  if ( req.isAuthenticated() && req.user.group === 'admin' ) {
    return next();
  }
  res.status( 401 ).send( { message: 'Usuário não autorizado' } );
}

module.exports = {
  isAuthenticated,
  isAuthorized
};
<|endoftext|>


<commit_before>var fs = require('fs');
var libxml = require('libxmljs');
var appVersion = require('../../../package').version;
var filterOsm = require('./filter-osm');

var CHUNK_SIZE = 500;

/**
 * aggregate-osm.js
 *
 * Aggregates a list of JSOM formatted OSM edit files into a single OSM XML.
 * A filter can be applied to get a subset of the OSM edits in question.
 * The resultant single OSM is fed to the callback.
 *
 * @param files   - OSM Files to aggregate
 * @param filter  - Object that specifies elements to include - no filter if null
 * @param cb      - Final aggregated OSM XML.
 */
module.exports = function (files, filter, cb) {
    var numFiles = files.length;

    // Empty OSM XML if no files.
    if (numFiles === 0) {
        cb('<?xml version="1.0" encoding="UTF-8" ?><osm version="0.6" generator="OpenMapKit Server ' + appVersion + '"></osm>');
    }

    // This is the number of files read so far.
    // This includes files that have been filtered out of the result.
    var filesCompleted = 0;

    // This is the number of files that have made it to the final main
    // OSM element and passed the filters. We use this for the limit filter.
    var filesUsed = 0;

    var limitReached = false;
    var filesLimit = Number.POSITIVE_INFINITY;
    if (typeof filter.limit === 'string') {
        var limit = parseInt(filter.limit);
        if (limit >= 0) {
            filesLimit = limit;
        }
    }

    var mainXmlDoc = new libxml.Document();
    mainXmlDoc.node('osm').attr({
        version: '0.6',
        generator: 'OpenMapKit Server ' + appVersion
    });
    var mainOsmElement = mainXmlDoc.root();

    var negIdRewriteHash = {
        counter: -1
    };

    /**
     * We don't want to process all of the files in parallel at once,
     * because we will eventually reach the limit of number of files
     * that can be simultaneously read by the system. We chunk it out
     * into smaller concurrent batches.
     *
     * @param chunkOfFiles - a slice of the files fed to this module
     * @param remainingFiles - a slice of the files that should be read in subsequent recursive calls
     */
    function processChunksOfFiles(chunkOfFiles, remainingFiles) {
        if (limitReached) return;
        var chunkLen = chunkOfFiles.length;
        var filesInChunkCompleted = 0;

        chunkOfFiles.forEach(function (f) {

            /**
             * The file filter checks the birthtime timestamp.
             * If we want the file, we get a bool of true in
             * the callback.
             */
            filterOsm.file(f, filter, function (filePath, bool) {

                function checkToFireCallbacks() {
                    ++filesCompleted;
                    ++filesInChunkCompleted;
                    // if every single file is done
                    if (filesUsed === filesLimit || filesCompleted === numFiles) {
                        if (!limitReached) {
                            cb(null, mainXmlDoc.toString());
                            limitReached = true;
                        }
                    }
                    // if every file in chunk is done
                    else if (filesInChunkCompleted === chunkLen && remainingFiles.length > 0) {
                        processChunksOfFiles(remainingFiles.slice(0, CHUNK_SIZE), remainingFiles.slice(CHUNK_SIZE));
                    }
                }

                if (!bool) {
                    checkToFireCallbacks();
                    return;
                }
                fs.readFile(filePath, 'utf-8', function (err, xml) {
                    if (limitReached) return;
                    if (err) {
                        cb(err);
                        return;
                    }
                    if (typeof xml !== 'string' || xml.length === 0) {
                        checkToFireCallbacks();
                        return;
                    }
                    try {
                        var doc = libxml.parseXmlString(xml);
                        var rootEl = doc.root();
                        filterOsm.user(rootEl, filter, function (rootEl, bool) {
                            if (!bool) {
                                checkToFireCallbacks();
                                return;
                            }
                            var osmElements = rootEl.childNodes();
                            for (var j = 0, len = osmElements.length; j < len; j++) {
                                var osmElement = osmElements[j];
                                // Check that the element is a node, way, or relation.
                                var elementName = osmElement.name();
                                if (elementName === 'node') {
                                    rewriteNegativeId(negIdRewriteHash, osmElement);
                                } else if (elementName === 'way' || elementName === 'relation') {
                                    rewriteNegativeId(negIdRewriteHash, osmElement);
                                    // Ways and relations might need their negative refs rewritten too.
                                    rewriteNegativeRef(negIdRewriteHash, osmElement);
                                }
                                mainOsmElement.addChild(osmElement);
                            }
                            ++filesUsed;
                            checkToFireCallbacks();
                        });
                    } catch (err) {
                        cb(err);
                        return;
                    }

                });
            });

        });
    }

    processChunksOfFiles(files.slice(0, CHUNK_SIZE), files.slice(CHUNK_SIZE));

};

/**
 * Rewrites the id attribute with a fresh negative ID for
 * OSM Elements with a negative ID.
 *
 * @param negIdRewriteHash - lookup table where key is old ID, and value is new ID
 * @param osmElement - the OSM XML Element we are processing
 */
function rewriteNegativeId(negIdRewriteHash, osmElement) {
    var idAttr = osmElement.attr('id');
    if (!idAttr) return;
    var id = parseInt(idAttr.value());
    if (id >= 0) return;
    negIdRewriteHash[id] = negIdRewriteHash.counter;
    idAttr.value(negIdRewriteHash.counter--);
}

/**
 * Ways and relation members may have references to negative
 * IDs that have just been rewritten to assure uniqueness.
 * We look at the negIdRewriteHash and reassign the ref
 * value so that it contains a reference to the new ID value.
 *
 * @param negIdRewriteHash - lookup table where key is old ID, and value is new ID
 * @param osmElement - the OSM XML Element we are processing
 */
function rewriteNegativeRef(negIdRewriteHash, osmElement) {
    var children = osmElement.childNodes();
    for (var i = 0, len = children.length; i < len; i++) {
        // A child can be a nd, member, or tag.
        var child = children[i];
        var refAttr = child.attr('ref');
        if (!refAttr) continue;
        var ref = parseInt(refAttr.value());
        if (ref >= 0) continue;
        var rewriteRef = negIdRewriteHash[ref];
        if (typeof rewriteRef !== 'undefined' && rewriteRef !== null) {
            refAttr.value(rewriteRef);
        }
    }
}
<commit_msg>0 OSM Files should not respond with an error condition.<commit_after>var fs = require('fs');
var libxml = require('libxmljs');
var appVersion = require('../../../package').version;
var filterOsm = require('./filter-osm');

var CHUNK_SIZE = 500;

/**
 * aggregate-osm.js
 *
 * Aggregates a list of JSOM formatted OSM edit files into a single OSM XML.
 * A filter can be applied to get a subset of the OSM edits in question.
 * The resultant single OSM is fed to the callback.
 *
 * @param files   - OSM Files to aggregate
 * @param filter  - Object that specifies elements to include - no filter if null
 * @param cb      - Final aggregated OSM XML.
 */
module.exports = function (files, filter, cb) {
    var numFiles = files.length;

    // Empty OSM XML if no files.
    if (numFiles === 0) {
        cb(null, '<?xml version="1.0" encoding="UTF-8" ?><osm version="0.6" generator="OpenMapKit Server ' + appVersion + '"></osm>');
    }

    // This is the number of files read so far.
    // This includes files that have been filtered out of the result.
    var filesCompleted = 0;

    // This is the number of files that have made it to the final main
    // OSM element and passed the filters. We use this for the limit filter.
    var filesUsed = 0;

    var limitReached = false;
    var filesLimit = Number.POSITIVE_INFINITY;
    if (typeof filter.limit === 'string') {
        var limit = parseInt(filter.limit);
        if (limit >= 0) {
            filesLimit = limit;
        }
    }

    var mainXmlDoc = new libxml.Document();
    mainXmlDoc.node('osm').attr({
        version: '0.6',
        generator: 'OpenMapKit Server ' + appVersion
    });
    var mainOsmElement = mainXmlDoc.root();

    var negIdRewriteHash = {
        counter: -1
    };

    /**
     * We don't want to process all of the files in parallel at once,
     * because we will eventually reach the limit of number of files
     * that can be simultaneously read by the system. We chunk it out
     * into smaller concurrent batches.
     *
     * @param chunkOfFiles - a slice of the files fed to this module
     * @param remainingFiles - a slice of the files that should be read in subsequent recursive calls
     */
    function processChunksOfFiles(chunkOfFiles, remainingFiles) {
        if (limitReached) return;
        var chunkLen = chunkOfFiles.length;
        var filesInChunkCompleted = 0;

        chunkOfFiles.forEach(function (f) {

            /**
             * The file filter checks the birthtime timestamp.
             * If we want the file, we get a bool of true in
             * the callback.
             */
            filterOsm.file(f, filter, function (filePath, bool) {

                function checkToFireCallbacks() {
                    ++filesCompleted;
                    ++filesInChunkCompleted;
                    // if every single file is done
                    if (filesUsed === filesLimit || filesCompleted === numFiles) {
                        if (!limitReached) {
                            cb(null, mainXmlDoc.toString());
                            limitReached = true;
                        }
                    }
                    // if every file in chunk is done
                    else if (filesInChunkCompleted === chunkLen && remainingFiles.length > 0) {
                        processChunksOfFiles(remainingFiles.slice(0, CHUNK_SIZE), remainingFiles.slice(CHUNK_SIZE));
                    }
                }

                if (!bool) {
                    checkToFireCallbacks();
                    return;
                }
                fs.readFile(filePath, 'utf-8', function (err, xml) {
                    if (limitReached) return;
                    if (err) {
                        cb(err);
                        return;
                    }
                    if (typeof xml !== 'string' || xml.length === 0) {
                        checkToFireCallbacks();
                        return;
                    }
                    try {
                        var doc = libxml.parseXmlString(xml);
                        var rootEl = doc.root();
                        filterOsm.user(rootEl, filter, function (rootEl, bool) {
                            if (!bool) {
                                checkToFireCallbacks();
                                return;
                            }
                            var osmElements = rootEl.childNodes();
                            for (var j = 0, len = osmElements.length; j < len; j++) {
                                var osmElement = osmElements[j];
                                // Check that the element is a node, way, or relation.
                                var elementName = osmElement.name();
                                if (elementName === 'node') {
                                    rewriteNegativeId(negIdRewriteHash, osmElement);
                                } else if (elementName === 'way' || elementName === 'relation') {
                                    rewriteNegativeId(negIdRewriteHash, osmElement);
                                    // Ways and relations might need their negative refs rewritten too.
                                    rewriteNegativeRef(negIdRewriteHash, osmElement);
                                }
                                mainOsmElement.addChild(osmElement);
                            }
                            ++filesUsed;
                            checkToFireCallbacks();
                        });
                    } catch (err) {
                        cb(err);
                        return;
                    }

                });
            });

        });
    }

    processChunksOfFiles(files.slice(0, CHUNK_SIZE), files.slice(CHUNK_SIZE));

};

/**
 * Rewrites the id attribute with a fresh negative ID for
 * OSM Elements with a negative ID.
 *
 * @param negIdRewriteHash - lookup table where key is old ID, and value is new ID
 * @param osmElement - the OSM XML Element we are processing
 */
function rewriteNegativeId(negIdRewriteHash, osmElement) {
    var idAttr = osmElement.attr('id');
    if (!idAttr) return;
    var id = parseInt(idAttr.value());
    if (id >= 0) return;
    negIdRewriteHash[id] = negIdRewriteHash.counter;
    idAttr.value(negIdRewriteHash.counter--);
}

/**
 * Ways and relation members may have references to negative
 * IDs that have just been rewritten to assure uniqueness.
 * We look at the negIdRewriteHash and reassign the ref
 * value so that it contains a reference to the new ID value.
 *
 * @param negIdRewriteHash - lookup table where key is old ID, and value is new ID
 * @param osmElement - the OSM XML Element we are processing
 */
function rewriteNegativeRef(negIdRewriteHash, osmElement) {
    var children = osmElement.childNodes();
    for (var i = 0, len = children.length; i < len; i++) {
        // A child can be a nd, member, or tag.
        var child = children[i];
        var refAttr = child.attr('ref');
        if (!refAttr) continue;
        var ref = parseInt(refAttr.value());
        if (ref >= 0) continue;
        var rewriteRef = negIdRewriteHash[ref];
        if (typeof rewriteRef !== 'undefined' && rewriteRef !== null) {
            refAttr.value(rewriteRef);
        }
    }
}
<|endoftext|>