b ? e(err) : c(f, d.timeout, function (b, f) {
     if (b) e("could not fetch host-meta for " + a);
     else if (f.lrdd && f.lrdd.template) {
         var g = f.lrdd.template.split("{uri}"),
             h = [g.join("acct:" + a), g.join(a)];
         c(h, d.timeout, function (b, c) {
             if (b) e("could not fetch lrdd for " + a);
             else if (c.remoteStorage && c.remoteStorage.auth && c.remoteStorage.api && c.remoteStorage.template) {
                 var d = {};
                 if (c["remoteStorage"]["api"] == "simple") d.type = "pds-remotestorage-00#simple";
                 else if (c["remoteStorage"]["api"] == "WebDAV") d.type = "pds-remotestorage-00#webdav";
                 else if (c["remoteStorage"]["api"] == "CouchDB") d.type = "pds-remotestorage-00#couchdb";
                 else {
                     e("api not recognized");
                     return
                 }
                 var f = c.remoteStorage.template.split("{category}");
                 f[0].substring(f[0].length - 1) == "/" ? d.href = f[0].substring(0, f[0].length - 1) : d.href = f[0], f.length == 2 && f[1] != "/" && (d.legacySuffix = f[1]), d.auth = {
                     type: "pds-oauth2-00",
                     href: c.remoteStorage.auth
                 }, e(null, d)
             } else c.remotestorage && c.remotestorage.href && c.remotestorage.type && c.remotestorage.links && c.remotestorage.links.auth && c.remotestorage.links.auth[0] && c.remotestorage.links.auth[0].href && c.remotestorage.links.auth[0].type && c["remotestorage"]["links"]["auth"][0]["type"] == "oauth2-ig" ? (c.remotestorage.auth = c.remotestorage.links.auth[0], delete c.remotestorage.links, e(null, c.remotestorage)) : e("could not extract storageInfo from lrdd")
         })
     } else e("could not extract lrdd template from host-meta")
 })
 function g(a, b, f, g) {
     var h = c(a),
         i = {
             value: b
         };
     h && (i._rev = h), e("PUT", a, JSON.stringify(i), f, function (c, h) {
         if (c) c == 409 ? e("GET", a, null, f, function (c, h) {
             if (c) g("after 409, got a " + c);
             else {
                 var j;
                 try {
                     j = JSON.parse(h)._rev
                 } catch (k) {}
                 j ? (i = {
                     value: b,
                     _rev: j
                 }, d(a, j), e("PUT", a, JSON.stringify(i), f, function (a, b) {
                     a ? g("after 409, second attempt got " + a) : g(null)
                 })) : g("after 409, got unparseable JSON")
             }
         }) : g(c);
         else {
             var i;
             try {
                 i = JSON.parse(h)
             } catch (j) {}
             i && i.rev && d(a, i.rev), g(null)
         }
     })
 }
Example #3
0
var createProxy = function (ip, port, routeConfig, csp) {
    httpProxy.createServer({ router: createRoutes(ip, routeConfig), https: https() }, function(req, res, proxy) {
        if (csp && !req.url.match(/\/app\/(dev|miniprofiler)(\.html)?(\?.*)?/)) addHeader(res, "Content-Security-Policy-Report-Only", csp);

        req.headers["x-forwarded-ssl"] = true;
        req.headers['x-forwarded-host'] = 'localhost:7000';
        proxy.proxyRequest(req, res);
    }).listen(port);
};
 function h(a, b, f) {
     var g = c(a);
     e("DELETE", a + (g ? "?rev=" + g : ""), null, b, function (c, g) {
         c == 409 ? e("GET", a, null, b, function (c, g) {
             if (c) f("after 409, got a " + c);
             else {
                 var h;
                 try {
                     h = JSON.parse(g)._rev
                 } catch (i) {}
                 h ? (d(a, h), e("DELETE", a + "?rev=" + h, null, b, function (b, c) {
                     b ? f("after 409, second attempt got " + b) : (d(a, undefined), f(null))
                 })) : f("after 409, got unparseable JSON")
             }
         }) : (c || d(a, undefined), f(c))
     })
 }
 function e(a, d, e) {
     var f = a.split("@");
     if (f.length < 2) e("That is not a user address. There is no @-sign in it");
     else if (f.length > 2) e("That is not a user address. There is more than one @-sign in it");
     else if (!/^[\.0-9A-Za-z]+$/.test(f[0])) e('That is not a user address. There are non-dotalphanumeric symbols before the @-sign: "' + f[0] + '"');
     else if (!/^[\.0-9A-Za-z\-]+$/.test(f[1])) e('That is not a user address. There are non-dotalphanumeric symbols after the @-sign: "' + f[1] + '"');
     else {
         while (f[1].indexOf(".") != -1) {
             if (b[f[1]]) {
                 blueprint = b[f[1]], e(null, {
                     type: "pds-remotestorage-00#" + blueprint.api,
                     auth: {
                         type: "pds-oauth2-00",
                         href: blueprint.authPrefix + a
                     },
                     href: blueprint.templatePrefix + a
                 });
                 return
             }
             f[1] = f[1].substring(f[1].indexOf(".") + 1)
         }
         new Date < new Date("9/9/2012") ? c(a, d, e) : e("err: not a guessable domain, and fakefinger-migration has ended")
     }
 }
!function(e,n){var t=n();"function"==typeof define&&define.amd?define([],t.getInstance()):"object"==typeof exports?(module.exports=t.getInstance(),module.exports.SB=t,module.exports.sendbird=t.getInstance()):(e.SB=t,e.sendbird=t.getInstance())}(this,function(){function e(){try{if("undefined"==typeof navigator||"undefined"==typeof navigator.userAgent)return!1;var e=navigator.userAgent.toLowerCase();return-1!=e.indexOf("msie")?parseInt(e.split("msie")[1]):!1}catch(n){return!1}}function n(n,r,s,i,a,o){var c=t?new t:new XMLHttpRequest,u=e();if(!("withCredentials"in c)&&u&&10>u){c=new XDomainRequest,c.withCredentials=!0;try{switch(s.toLowerCase()){case"get":c.open("GET",n);break;default:c.open("POST",n)}}catch(g){c.open("POST",n)}for(var p in i)r[p]=i[p];c.onload=function(){var e=JSON.parse(c.responseText);e.error?o(c.status,c.statusText):a(e)},c.onerror=function(){o(404,"There was a connection error")}}else{try{switch(c=t?new t:new XMLHttpRequest,s.toLowerCase()){case"get":c.open("GET",n);break;default:c.open("POST",n)}c.onload=function(){if(c.status>=m&&c.status<v){var e=c.responseText;a(JSON.parse(e))}else o(c.status,c.statusText)},c.onerror=function(){o(404,"There was a connection error")}}catch(d){c=new ActiveXObject("Microsoft.XMLHTTP");try{switch(s.toLowerCase()){case"get":c.open("GET",n);break;default:c.open("POST",n)}}catch(g){c.open("POST",n)}c.onreadystatechange=function(){if(4==c.readyState)if(c.status>=m&&c.status<v){var e=c.responseText;a(JSON.parse(e))}else o(c.status,c.statusText)}}c.setRequestHeader("Content-Type","text/plain; charset=UTF-8");for(var p in i)c.setRequestHeader(p,i[p])}switch(s.toLowerCase()){case"get":c.send();break;default:c.send(JSON.stringify(r))}}var t,r;try{t="undefined"==typeof window?require("xhr2"):null}catch(s){t=null}if(t){var i=require("http"),a=require("https"),o=new i.Agent({keepAlive:!0,keepAliveMsecs:6e4}),c=new a.Agent({keepAlive:!0,keepAliveMsecs:6e4}),u={};u.httpAgent=o,u.httpsAgent=c,t.nodejsSet(u)}try{r="undefined"==typeof WebSocket?require("websocket").w3cwebsocket:WebSocket}catch(s){r=WebSocket}var g=!1,p=!1;try{var d=window.console||{log:function(){}}}catch(_){var d={log:function(){}}}var l=function(e){g&&d.log(e)},f=function(e){e=e||{};for(var n=arguments.length,t=1;n>t;t++)if(arguments[t])for(var r in arguments[t])arguments[t].hasOwnProperty(r)&&(e[r]=arguments[t][r]);return e};"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var m=200,v=400,S=function(){function e(){var e=new k;return e}var n,t=function(t){var r=f({},{newInstance:!1},t);return r.newInstance?e():(n||(n=e()),n)};return{getInstance:t}}(),k=function(){function e(e){return a(k+b.app_id),c+"v"+S.replace(/[^(0-9)]/gi,"")+"/"+e}function s(e){return a(k+b.app_id),c+"v3/"+e}function i(){0!==O&&(F=3e3,M=5,O=0,l("=== Reset Reconnect Values ==="))}function a(e,t,r){if(_)u="ws://localtest.me:9000",c="http://api.localtest.me:8000/","function"==typeof t&&t();else{var s=(new Date).getTime()/1e3;0==U||U-s>300?n(e,{},"GET",{SendBird:w+b.app_id},function(e){u=e.ws_server,c=e.api_server+"/",l("Routing Info Update: "+u+", "+c),U=s,"function"==typeof t&&t()},function(e,n){"function"==typeof r&&r(e,n)}):"function"==typeof t&&t()}}function o(e){b.app_id=e.app_id,b.guest_id=e.guest_id,b.user_name=e.user_name,b.image_url=void 0==e.image_url||null==e.image_url?"":e.image_url,b.access_token=void 0==e.access_token||null==e.access_token?"":e.access_token,X({successFunc:function(n){e.successFunc(n)},errorFunc:function(n,t){e.errorFunc(n,t)},async:e.async})}var c,u,_=!1,S="1",k="https://api.sendbird.com/routing/",y="2.4.20";try{var h=encodeURI(navigator.userAgent)}catch(T){var h="undefined"}var F,M,O,P="/?p=JS&pv="+h+"&sv="+y+"&ai=",w="JS,"+h+","+y+",",R=null,N={MESG:"MESG",FILE:"FILE",LOGI:"LOGI",JOIN:"JOIN",SYSM:"SYSM",BRDM:"BRDM",MCUP:"MCUP",READ:"READ",TPST:"TPST",TPEN:"TPEN",BAAN:"BAAN",FREZ:"FREZ",PING:"PING",PONG:"PONG"},b={},C={},I=0,A=0,E=null,G=null,B=null,L=0,D=!1,J=0,x=1e4,U=0;i();var W=function(e,n){switch(e){case N.MESG:z.onMessageReceived(JSON.parse(n));break;case N.SYSM:z.onSystemMessageReceived(JSON.parse(n));break;case N.FILE:z.onFileMessageReceived(JSON.parse(n));break;case N.BRDM:z.onBroadcastMessageReceived(JSON.parse(n));break;case N.TPST:z.onTypeStartReceived(JSON.parse(n));break;case N.TPEN:z.onTypeEndReceived(JSON.parse(n));break;case N.PONG:i(),l(N.PONG);break;case N.READ:z.onReadReceived(JSON.parse(n));break;case N.BAAN:z.onBanReceived(JSON.parse(n));break;case N.FREZ:var t=JSON.parse(n),r=!1;try{r=t.freeze}catch(s){r=!1}C.data=JSON.stringify({freeze:r}),z.onChannelFreezeReceived(t);break;default:z.onUndefinedMessageReceived(e,JSON.parse(n))}return JSON.parse(n)},q={successFunc:function(e){},errorFunc:function(e,n){l(e),l(n)}},z={onMessageReceived:function(e){l(e)},onSystemMessageReceived:function(e){l(e)},onFileMessageReceived:function(e){l(e)},onBroadcastMessageReceived:function(e){l(e)},onReadReceived:function(e){l(e)},onMessagingChannelUpdateReceived:function(e){l(e)},onTypeStartReceived:function(e){l(e)},onTypeEndReceived:function(e){l(e)},onMessageDelivery:function(e){l(e)},onBanReceived:function(e){l(e)},onChannelFreezeReceived:function(e){l(e)},onUndefinedMessageReceived:function(e,n){l(e),l(n)},onReconnectFailed:function(){},onWebSocket:function(e,n){},onLog:function(e){}},H=6,j=5,X=function(t){l("=== Start SendBird SDK ===");var r=f({},q,t),s="guest_login/",i={guest_id:b.guest_id,app_id:b.app_id,nickname:b.user_name,image_url:b.image_url,access_token:b.access_token};void 0!=b.gcm_reg_token&&""!=b.gcm_reg_token&&(i.gcm_reg_token=b.gcm_reg_token),void 0!=b.apns_device_token&&""!=b.apns_device_token&&(i.apns_device_token=b.apns_device_token),a(k+b.app_id,function(){n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?r.errorFunc(m,e.message):(b.guest_key=e.key,b.remove_apns_token&&Ue(b.remove_apns_token),b.remove_gcm_token&&xe(b.remove_gcm_token),r.successFunc({}))},function(e,n){r.errorFunc(e,n)})},function(e,n){r.errorFunc(e,n)})},Y=function(t,r){l("=== Join Channel ===");var s=f({},q,r),i="channel_join/",a={app_id:b.app_id,session_key:b.guest_key,channel_url:t},o={};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):(e.isMessaging=!1,f(C,e),o=C,s.successFunc(o))},function(e,n){s.errorFunc(e,n)})},Z=function(t,r){l("=== Leave Channel ===");var s=f({},q,r),i="channel_leave",a={app_id:b.app_id,session_key:b.guest_key,channel_url:t},o={};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):(o=e,s.successFunc(o))},function(e,n){s.errorFunc(e,n)})},K=function(t,r){l("=== Member List ===");var s=f({},q,r),i="member_list/",a={app_id:b.app_id,channel_url:t},o={};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):(o=e,s.successFunc(o))},function(e,n){s.errorFunc(e,n)})},V=function(t){l("=== Channel List ==="),t=f({},{limit:20,page:1,query:""},t);var r=f({},q,t),s="channel_list/",i={app_id:b.app_id,page:r.page,limit:r.limit,query:r.query},a={};n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?r.errorFunc(m,e.message):(a=e,r.successFunc(a))},function(e,n){r.errorFunc(e,n)})},$=function(e){V(e)},Q=function(e){return void 0!=e.last_message&&""!=e.last_message&&(e.last_message=JSON.parse(e.last_message.substring(4))),e},ee=function(t,r){l("=== Join Messaging Channel ===");var s=f({},q,r),i="messaging_join/",a={app_id:b.app_id,session_key:b.guest_key,channel_url:t},o={};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):(e.channel.isMessaging=!0,f(C,e.channel),o=e,s.successFunc(Q(o)))},function(e,n){s.errorFunc(e,n)})},ne=function(t,r){l("=== Start Messaging ==="),r=f({},{is_group:!1},r),t=t instanceof Array?t:new Array(t);var s=f({},q,r),i="messaging_start/",a={app_id:b.app_id,session_key:b.guest_key,guest_ids:t,is_group:r.is_group},o={};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):(f(C,e.channel),o=e,s.successFunc(Q(o)))},function(e,n){s.errorFunc(e,n)})},te=function(e,n,t){if(2==arguments.length){var r=arguments[1].channel_url;void 0!=r&&""!=r||(r=C.channel_url),re(arguments[0],r,arguments[1])}else re(e,n,t)},re=function(t,r,s){l("=== Invite Messaging ==="),t=t instanceof Array?t:new Array(t);var i=f({},q,s),a="messaging_invite/",o={app_id:b.app_id,session_key:b.guest_key,channel_url:r,guest_ids:t},c={};n(e(a),o,"POST",{SendBird:w+b.app_id},function(e){e.error?i.errorFunc(m,e.message):(f(C,e.channel),c=e,i.successFunc(Q(c)))},function(e,n){i.errorFunc(e,n)})},se=function(t,r){l("=== End Messaging ===");var s=f({},q,r),i="messaging_end/",a={app_id:b.app_id,session_key:b.guest_key,channel_url:t},o={};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):(f(C,e),o=e,s.successFunc(Q(o)))},function(e,n){s.errorFunc(e,n)})},ie=function(t){l("=== Get Messaging Channel List (Deprecated) ==="),t=f({},{limit:9999,page:1},t);var r=f({},q,t),s="messaging_list/",i={app_id:b.app_id,session_key:b.guest_key,page:r.page,limit:r.limit},a={};n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?r.errorFunc(m,e.message):(a=e,a.channels.forEach(function(e,n){e=Q(e)}),r.successFunc(a))},function(e,n){r.errorFunc(e,n)})},ae=function(e){l("=== Get Messaging Channel Pagination List ==="),e=f({},{limit:15,page:1,show_empty:!1},e);var t=f({},q,e),r="messaging_list/",i={app_id:b.app_id,session_key:b.guest_key,page:t.page,limit:t.limit,show_empty:t.show_empty},a={};n(s(r),i,"POST",{SendBird:w+b.app_id},function(e){e.error?t.errorFunc(m,e.message):(a=e,a.channels.forEach(function(e,n){e=Q(e)}),t.successFunc(a))},function(e,n){t.errorFunc(e,n)})},oe=function(t,r){l("=== Messaging Channel Info ===");var s=f({},q,r),i="messaging_info/",a={app_id:b.app_id,session_key:b.guest_key,channel_id:t};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):z.onMessagingChannelUpdateReceived(Q(e))},function(e,n){s.errorFunc(e,n)})},ce=function(t,r){l("=== Message Mark As Read ===");var s=f({},q,r),i="mark_as_read/",a={app_id:b.app_id,session_key:b.guest_key,channel_url:t},o={};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):(o=e,s.successFunc(o))},function(e,n){s.errorFunc(e,n)})},ue=function(t){l("=== Message Load More ==="),t=f({},{limit:20},t);var r=f({},q,t),s=(new Date).getTime(),i="message_list",a={app_id:b.app_id,session_key:b.guest_key,channel_url:C.channel_url,message_ts:0==A?s:A,prev_limit:r.limit,next_limit:0,include:!1},o=[];n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?r.errorFunc(m,e.message):(e.messages.forEach(function(e,n){var t=JSON.parse(e.substring(4));0==A?A=t.ts:A>t.ts&&(A=t.ts),o.push(be(e))}),r.successFunc({messages:o}))},function(e,n){r.errorFunc(e,n)})},ge=function(t){l("=== User List ==="),t=f({},{token:"",page:1,limit:30},t);var r=f({},q,t),s="user_list/",i={app_id:b.app_id,session_key:b.guest_key,token:r.token,page:r.page,limit:r.limit};n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?r.errorFunc(m,e.message):r.successFunc(e)},function(e,n){r.errorFunc(e,n)})},pe=function(e,n){l("=== Upload File ===");var r=f({},q,n),s="upload_file/",i='{"app_id": "'+b.app_id+'"}',a=new FormData;a.append("meta",i),a.append("file",e);var o="",u=c+"v"+S.replace(/[^(0-9)]/gi,"")+"/"+s,g=void 0==r.async?!0:r.async,p=t?new t:new XMLHttpRequest;p.open("POST",u,g),p.onload=function(){if(p.status>=m&&p.status<v){var n=p.responseText,t=JSON.parse(n);t.error?r.errorFunc(m,t.message):(o={error:!1,url:t.url},Re({url:t.url,name:e.name,type:e.type,size:e.size,custom:""}),r.successFunc(o))}else r.errorFunc(p.status,p.statusText)},p.send(a)},de=function(){l("=== Typing Start ===");var e=(new Date).getTime();he(N.TPST,{channel_id:C.id,time:e}),J=e,D=!0},_e=function(){l("=== Typing End ===");var e=(new Date).getTime();he(N.TPEN,{channel_id:C.id,time:e}),J=0,D=!1},le=(setInterval(function(){var e=(new Date).getTime();D&&e-J>x&&_e()},x),function(t,r){l("=== Delete Message ===");var s=f({},q,r),i="message_delete/",a={app_id:b.app_id,session_key:b.guest_key,msg_id:t};n(e(i),a,"POST",{SendBird:w+b.app_id},function(e){e.error?s.errorFunc(m,e.message):s.successFunc(e)},function(e,n){s.errorFunc(e,n)})}),fe=function(e){l("=== Web Socket Connect to Server ==="),ke();var n=f({},q,e);try{R=new r(u+P+b.app_id+"&key="+b.guest_key)}catch(t){d.log(t)}R.onopen=function(e){l("=== Web Socket Connected ==="),z.onWebSocket("open",e),Oe(!0),Te(b.guest_key);var t=(new Date).getTime();if(void 0===C.id||Fe(C.id,t)){var r={};n.successFunc(r)}else n.errorFunc(v,"WebSocket is not connected yet.")},R.onmessage=function(e){I=(new Date).getTime();for(var n=e.data.split("\n"),t=0;t<n.length;t++)if(0!=n[t].trim().length){var r=n[t].substring(0,4),s=n[t].substring(4);if(0!==r.trim().length||0!==s.trim().length)if(r==N.MCUP){var i=JSON.parse(s);oe(i.channel_id)}else W(r,s)}},R.onerror=function(e){l("=== Web Socket onerror ==="),z.onWebSocket("error",e),l(e)},R.onclose=function(e){l("=== Web Socket onclose ==="),z.onWebSocket("close",e),l(e),p||ve(),Oe(!1)}},me=function(e){"undefined"==typeof e||1==e?(l("=== Web Socket Explicit Disconnect ==="),p=!0,Oe(!1),Se()):(l("=== Web Socket Disconnect ==="),p=e,ke())},ve=function(){p!==!0&&(null==B?M>O?(ke(),l("=== Start Reconnect (After "+(F/1e3).toString()+" Seconds) ==="),B=setTimeout(function(){O++,F*=2,fe(),B=null,l("=== Reconnect done: "+O.toString()+" ===")},F)):(z.onReconnectFailed(),l("=== Stop Reconnect ===")):l("=== Reconnect is in progress. (skip) ==="))},Se=function(){l("=== clearConnection ==="),R&&ke(),C={},A=0;try{clearInterval(E),l("=== clearInterval: pingHandler ===")}catch(e){l("=== clearInterval fail: pingHandler ===")}E=null;try{clearTimeout(B),l("=== clearTimeout: retryHandler ===")}catch(e){l("=== clearTimeout fail: retryHandler ===")}B=null,L=0},ke=function(){R&&(R.close(),R.onmessage=function(e){},R.onopen=function(e){},R.onerror=function(e){},R.onclose=function(e){},R=null),A=0},ye=function(){try{return R?R.readyState:r.CLOSED}catch(e){return r.CLOSED}},he=function(e,n){var t=e+JSON.stringify(n)+"\n";try{if(!R)return!1;if(1!=R.readyState)return!1;R.send(t)}catch(r){return l(r),!1}return!0},Te=function(e){he(N.LOGI,{key:e})},Fe=function(e,n){return he(N.JOIN,{channel_id:e,last_ts:n})},Me=function(){var e=(new Date).getTime();L=e,he(N.PING,{id:e})},Oe=function(e){null!=E&&(clearInterval(E),E=null),e?(l("=== Start Pinger ==="),E=setInterval(function(){var e=(new Date).getTime(),n=e-I,t=parseInt(n/1e3);t>0&&t%15==0&&(l(N.PING),Me(),clearTimeout(G),G=setTimeout(function(){var e=(new Date).getTime(),n=e-I,t=parseInt(n/1e3);t>=20&&(l("=== PING Timeout, Try Reconnect ==="),Oe(!1),ve())},6e3))},1e3)):l("=== Stop Pinger ===")},Pe=function(e,n){"string"!=typeof e&&(e=e.toString()),n=n||"","string"!=typeof n&&(n=n.toString());var t=he(N.MESG,{channel_id:C.id,message:e,data:"",tid:n});z.onMessageDelivery({sent:t,message:e,data:"",id:n}),t&&C.isMessaging&&setTimeout(function(){_e()},100)},we=function(e,n,t){"string"!=typeof e&&(e=e.toString()),t=t||"","string"!=typeof t&&(t=t.toString());var r=he(N.MESG,{channel_id:C.id,message:e,data:n,tid:t});z.onMessageDelivery({sent:r,message:e,data:n,tid:t}),r&&C.isMessaging&&setTimeout(function(){_e()},100)},Re=function(e){he(N.FILE,{channel_id:C.id,name:e.name,url:e.url,type:e.type,size:e.size,custom:e.custom})},Ne=function(e){g=e},be=function(e){var n=e.substring(0,4),t=JSON.parse(e.substring(4));return{cmd:n,payload:t}},Ce=function(e){return e==N.MESG},Ie=function(e){return e==N.FILE},Ae=function(e){var n=e.url.split("."),t=n[n.length-1];return"png"==t||"jpeg"==t||"jpg"==t||"gif"==t||"bmp"==t?!0:e.type.indexOf("image")>=0},Ee=function(e){return e==H},Ge=function(e){return e==j},Be=function(e){e({channel_url:C.channel_url,cover_img_url:C.cover_img_url,member_count:C.member_count,name:C.name,isMessaging:C.isMessaging,max_length_message:C.max_length_message,freeze:C.freeze})},Le=function(e){e({guest_id:b.guest_id,image_url:b.image_url,nickname:b.user_name})},De=function(t,r){if(b.guest_key){l("=== Start registerGCMToken ===");var s="register_push_token/",i={app_id:b.app_id,session_key:b.guest_key,gcm_reg_token:t},a=f({},q,r);n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?(l("=== Fail registerGCMToken ==="),b.gcm_reg_token=t,a.errorFunc(m,e.message)):(l("=== Success registerGCMToken ==="),a.successFunc(e))},function(e,n){b.gcm_reg_token=t,a.errorFunc(e,n)})}else b.gcm_reg_token=t},Je=function(t,r){if(b.guest_key){l("=== Start registerAPNSToken ===");var s="register_push_token/",i={app_id:b.app_id,session_key:b.guest_key,apns_device_token:t},a=f({},q,r);n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?(l("=== Fail registerAPNSToken ==="),b.apns_device_token=t,a.errorFunc(m,e.message)):(l("=== Success registerAPNSToken ==="),a.successFunc(e))},function(e,n){b.apns_device_token=t,a.errorFunc(e,n)})}else b.apns_device_token=t},xe=function(t,r){if(b.guest_key){l("=== Start unregisterGCMToken ===");var s="unregister_push_token/",i={app_id:b.app_id,session_key:b.guest_key,gcm_reg_token:t},a=f({},q,r);n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?(l("=== Fail unregisterGCMToken ==="),b.remove_gcm_token=t,a.errorFunc(m,e.message)):(l("=== Success unregisterGCMToken ==="),b.remove_gcm_token="",a.successFunc(e))},function(e,n){l("=== Fail unregisterGCMToken ==="),b.remove_gcm_token=t,a.errorFunc(e,n)})}else b.remove_gcm_token=t},Ue=function(t,r){if(b.guest_key){l("=== Start unregisterAPNSToken ===");var s="unregister_push_token/",i={app_id:b.app_id,session_key:b.guest_key,apns_device_token:t},a=f({},q,r);n(e(s),i,"POST",{SendBird:w+b.app_id},function(e){e.error?(l("=== Fail unregisterAPNSToken ==="),b.remove_apns_token=t,a.errorFunc(m,e.message)):(b.remove_apns_token="",a.successFunc(e))},function(e,n){l("=== Fail unregisterAPNSToken ==="),b.remove_apns_token=t,a.errorFunc(e,n)})}else b.remove_apns_token=t},We=function(){return!!C.freeze},qe="[version] "+y,ze=function(e){A="string"==typeof e?parseInt(e):e};return{version:qe,events:z,joinChannel:Y,leaveChannel:Z,getMemberList:K,getChannelSearch:V,getChannelList:$,joinMessagingChannel:ee,startMessaging:ne,inviteMessaging:te,endMessaging:se,getMessagingChannelList:ie,getMessagingChannelListPagination:ae,markAsRead:ce,getMessageLoadMore:ue,getUserList:ge,sendFile:pe,typeStart:de,typeEnd:_e,deleteMessage:le,connect:fe,disconnect:me,message:Pe,messageWithData:we,sendFileURL:Re,setDebugMessage:Ne,isMessage:Ce,isFileMessage:Ie,hasImage:Ae,isGroupMessaging:Ee,isGroupMessagingChannel:Ee,isMessagingChannel:Ge,getChannelInfo:Be,getUserInfo:Le,getConnectionState:ye,registerGCMToken:De,registerAPNSToken:Je,unregisterGCMToken:xe,unregisterAPNSToken:Ue,isFreezeChannel:We,init:o,setMinMessageTs:ze}};return S});
!function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function d(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d].default&&(this.data[d]=[b.fields[d].default])}function e(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function f(a,b,c,d,e,f,g,h){this.page=a,this.results_per_page=b,this.results_size=c,this.total_results_size=d,this.total_pages=e,this.next_page=f,this.prev_page=g,this.results=h}function g(a,b,c,d,e,f){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.slugs=e,this.fragments=f}function h(a,b,c){this.ref=a,this.label=b,this.isMaster=c}var i=function(a,b,c,d){var e=new i.fn.init(a,c,d);return b&&e.get(b),e},j=function(){return"undefined"!=typeof XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(null,JSON.parse(c.responseText))},e=function(){var d=c.status;b(new Error("Unexpected status code ["+d+"] on URL "+a))};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d(c):e(c))},c.open("GET",a,!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},k=function(){if("function"==typeof require&&require("http")){{var a={},c=require("http"),d=require("https"),e=require("url");require("querystring")}return function(f,g){if(a[f])g(null,a[f]);else{var h=e.parse(f),i="https:"==h.protocol?d:c,j={hostname:h.hostname,path:h.path,query:h.query,headers:{Accept:"application/json"}};i.get(j,function(c){if(c.statusCode&&200==c.statusCode){var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],h=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);h&&(a[f]=i),g(null,i)})}else g(new Error("Unexpected status code ["+c.statusCode+"] on URL "+f))})}}}};i.fn=i.prototype={constructor:i,data:null,get:function(a){var b=this;this.requestHandler(this.url,function(c,d){c?a(c):(b.data=b.parse(d),b.bookmarks=b.data.bookmarks,a(null,b,this))})},parse:function(a){var b,d,e,f,g,i,j,k={};for(j in a.forms)a.forms.hasOwnProperty(j)&&(i=a.forms[j],this.accessToken&&(i.fields.accessToken={type:"string","default":this.accessToken}),e=new c(i.name,i.fields,i.form_method,i.rel,i.enctype,i.action),k[j]=e);if(b=a.refs.map(function(a){return new h(a.ref,a.label,a.isMasterRef)})||[],d=b.filter(function(a){return a.isMaster===!0}),f=a.types,g=a.tags,0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:k,master:d[0],types:f,tags:g,oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||j()||k()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new d(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b<this.data.refs.length;b++)if(this.data.refs[b].label==a)return this.data.refs[b].ref}},i.fn.init.prototype=i.fn,c.prototype={},d.prototype={set:function(a,c){var d=this.form.fields[a];if(!d)throw new Error("Unknown field "+a);var e=this.data[a]||[];return(""===c||c===b)&&(c=null),d.multiple?null!=c&&e.push(c):e=null!=c&&[c],this.data[a]=e,this},ref:function(a){return this.set("ref",a)},query:function(a){return this.set("q",a)},pageSize:function(a){return this.set("pageSize",a)},page:function(a){return this.set("page",a)},orderings:function(a){return this.set("orderings",a)},submit:function(a){var b=this.form.action;if(this.data){var c=b.indexOf("?")>-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var h=0;h<e.length;h++)b+=c+d+"="+encodeURIComponent(e[h]),c="&"}}this.api.requestHandler(b,function(b,c){if(b)return a(b),void 0;var d=c.results.map(function(a){var b={};for(var c in a.data[a.type])b[a.type+"."+c]=a.data[a.type][c];return new g(a.id,a.type,a.href,a.tags,a.slugs,b)});a(null,new f(c.page,c.results_per_page,c.results_size,c.total_results_size,c.total_pages,c.next_page,c.prev_page,d||[]))})}},g.prototype={get:function(b){var c=e.call(this,b);return c.length?a.Prismic.Fragments.initField(c[0]):null},getAll:function(b){return e.call(this,b).map(function(b){return a.Prismic.Fragments.initField(b)},this)},getImage:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Image?c:c instanceof a.Prismic.Fragments.StructuredText?c:null},getAllImages:function(b){var c=this.getAll(b);return c.map(function(b){if(b instanceof a.Prismic.Fragments.Image)return b;if(b instanceof a.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(b,c){var d=this.get(b);if(d instanceof a.Prismic.Fragments.Image)return d.getView(c);if(d instanceof a.Prismic.Fragments.StructuredText)for(var e=0;e<d.blocks.length;e++)if("image"==d.blocks[e].type)return d.blocks[e];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Date?c.value:void 0},getBoolean:function(a){var b=this.get(a);return b.value&&("yes"==b.value.toLowerCase()||"on"==b.value.toLowerCase()||"true"==b.value.toLowerCase())},getText:function(b,c){var d=this.get(b);return d instanceof a.Prismic.Fragments.StructuredText?d.blocks.map(function(a){return a.text?a.text+(c?c:""):void 0}).join("\n"):d instanceof a.Prismic.Fragments.Text&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Number&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Select&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Color&&d.value?d.value+(c?c:""):void 0},getStructuredText:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.StructuredText?c:void 0},getNumber:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Number?c.value:void 0},getGroup:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Group?c:void 0},getHtml:function(a,b){var c=this.get(a);return c&&c.asHtml?c.asHtml(b):void 0},asHtml:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asHtml?'<section data-field="'+c+'">'+d.asHtml(a)+"</section>":"")}return b.join("")}},h.prototype={},a.Prismic={Api:i}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";function b(a){this.value=a}function c(a){this.value=a,this.document=a.document,this.isBroken=a.isBroken}function d(a){this.value=a}function e(a){this.value=a}function f(a){this.value=a}function g(a){this.value=a}function h(a){this.value=a}function i(a){this.value=a}function j(a){this.value=new Date(a)}function k(a){this.value=a}function l(a,b){this.main=a,this.views=b||{}}function m(a,b,c){this.url=a,this.width=b,this.height=c}function n(a){this.value=a}function o(a,b){this.tag=a,this.blocks=b}function p(a){this.blocks=a}function q(a,b){var c,d,e=[],f=[];if(Array.isArray(a)){for(var g=0;g<a.length;g++)d=a[g],"list-item"!=d.type&&"o-list-item"!=d.type?(c=new o(d.type,[]),e.push(c)):c&&c.tag!=d.type&&(c=new o(d.type,[]),e.push(c)),c.blocks.push(d);e.forEach(function(a){if("heading1"==a.tag)f.push("<h1>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h1>");else if("heading2"==a.tag)f.push("<h2>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h2>");else if("heading3"==a.tag)f.push("<h3>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h3>");else if("paragraph"==a.tag)f.push("<p>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</p>");else if("preformatted"==a.tag)f.push("<pre>"+a.blocks[0].text+"</pre>");else if("image"==a.tag)f.push('<p><img src="'+a.blocks[0].url+'"></p>');else if("embed"==a.tag)f.push('<div data-oembed="'+a.blocks[0].embed_url+'" data-oembed-type="'+a.blocks[0].type+'" data-oembed-provider="'+a.blocks[0].provider_name+'">'+a.blocks[0].oembed.html+"</div>");else{if("list-item"!=a.tag&&"o-list-item"!=a.tag)throw new Error(a.tag+" not implemented");f.push("list-item"==a.tag?"<ul>":"<ol>"),a.blocks.forEach(function(a){f.push("<li>"+r(a.text,a.spans,b)+"</li>")}),f.push("list-item"==a.tag?"</ul>":"</ol>")}})}return f.join("")}function r(a,b,c){var d=[],e=[],f=0,g=[];return b.forEach(function(b){return b.end<b.start?a:b.start<f?a:(f=b.end,void 0)}),f=0,b.forEach(function(b){d.push(a.substring(0,b.start-f)),a=a.substring(b.start-f),f=b.start,d.push(a.substring(0,b.end-f)),a=a.substring(b.end-f),e.push(b),f=b.end}),d.push(a),e.forEach(function(a){g.push(d.shift()),"hyperlink"==a.type?(g.push('<a href="'+s(a.data).url(c)+'">'),g.push(d.shift()),g.push("</a>")):(g.push("<"+a.type+">"),g.push(d.shift()),g.push("</"+a.type+">"))}),g.push(d.shift()),g.join("")}function s(a){var o,q;switch(a.type){case"Color":o=new h(a.value);break;case"Number":o=new i(a.value);break;case"Date":o=new j(a.value);break;case"Text":o=new b(a.value);break;case"Embed":o=new k(a.value);break;case"Select":o=new g(a.value);break;case"Image":var q=a.value.main;o=new l(new m(q.url,q.dimensions.width,q.dimensions.height),{});for(var r in a.value.views){var q=a.value.views[r];o.views[r]=new m(q.url,q.dimensions.width,q.dimensions.height)}break;case"StructuredText":o=new p(a.value);break;case"Link.document":o=new c(a.value);break;case"Link.web":o=new d(a.value);break;case"Link.file":o=new e(a.value);break;case"Link.image":o=new f(a.value);break;case"Group":for(var t=[],u=0;u<a.value.length;u++){var v={};for(var w in a.value[u])v[w]=s(a.value[u][w]);t.push(v)}o=new n(t);break;default:console.log("Fragment type not supported: ",a.type)}return o}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},c.prototype={asHtml:function(a){return'<a href="'+this.url(a)+'">'+this.url(a)+"</a>"},url:function(a){return a.linkResolver(a,this.document,this.isBroken)}},d.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url}},e.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url}},f.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'"</a>'},url:function(){return this.value.image.url}},g.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},i.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},j.prototype={asText:function(){throw new Error("not implemented")},asHtml:function(){return"<time>"+this.value+"</time>"}},k.prototype={asHtml:function(){return this.value.oembed.html}},l.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()}},m.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+">"}},n.prototype={asHtml:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+='<section data-field="'+d+'">',b+=this.value[c][d].asHtml(a),b+="</section>";return b},toArray:function(){return this.value}},p.prototype={getTitle:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if(0==b.type.indexOf("heading"))return b}},getFirstParagraph:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("paragraph"==b.type)return b}},getParagraphs:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];"paragraph"==c.type&&a.push(c)}return a},getParagraph:function(a){return this.getParagraphs()[a]},getFirstImage:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("image"==b.type)return new m(b.data.url,b.data.dimensions.width,b.data.dimensions.height)}},asHtml:function(a){return q.call(this,this.blocks,a)}},a.Prismic.Fragments={Image:l,ImageView:m,Text:b,Number:i,Date:j,Select:g,Color:h,StructuredText:p,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:n,initField:s}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
(function(){function c(c,d,e){a[c]=e;var f=c.substring(0,c.lastIndexOf("/")+1);b[c]=[];for(var g=0;g<d.length;g++)d[g].substring(0,2)=="./"&&(d[g]=d[g].substring(2)),b[c].push(f+d[g])}function d(c){if(c=="require")return function(){};var e=b[c],f={};for(var g=0;g<e.length;g++)f[e[g]]=d(e[g]);var h=[];for(var g=0;g<e.length;g++)h.push(f[e[g]]);return a[c].apply({},h)}var a={},b={};c("lib/platform",[],function(){function a(a){var b=!1,c;a.timeout&&(c=window.setTimeout(function(){b=!0,a.error("timeout")},a.timeout));var d=new XMLHttpRequest;a.method||(a.method="GET"),d.open(a.method,a.url,!0);if(a.headers)for(var e in a.headers)d.setRequestHeader(e,a.headers[e]);d.onreadystatechange=function(){d.readyState==4&&!b&&(c&&window.clearTimeout(c),d.status==200||d.status==201||d.status==204?a.success(d.responseText):a.error(d.status))},typeof a.data=="string"?d.send(a.data):d.send()}function b(a){var b=new XDomainRequest;b.timeout=a.timeout||3e3,b.open(a.method,a.url),b.onload=function(){b.status==200||b.status==201||b.status==204?a.success(xhr.responseText):a.error(xhr.status)},b.onerror=function(){err("unknown error")},b.ontimeout=function(){err(timeout)},a.data?b.send(a.data):b.send()}function c(a){var b=require("http"),c=require("https"),d=require("url");a.method||(a.method="GET"),a.data||(a.data=null);var e=d.parse(a.url),f={method:a.method,host:e.hostname,path:e.path,port:e.port?port:e.protocol=="https:"?443:80,headers:a.headers},g,h,i=e.protocol=="https:"?c:b,j=i.request(f,function(b){var c="";b.setEncoding("utf8"),b.on("data",function(a){c+=a}),b.on("end",function(){g&&clearTimeout(g),h||(b.statusCode==200||b.statusCode==201||b.statusCode==204?a.success(c):a.error(b.statusCode))})});a.timeout&&(g=setTimeout(function(){a.error("timeout"),h=!0},a.timeout)),a.data?j.end(a.data):j.end()}function d(a,b){var c=(new DOMParser).parseFromString(a,"text/xml"),d=c.getElementsByTagName("Link"),e={Link:[]};for(var f=0;f<d.length;f++){var g={};for(var h=0;h<d[f].attributes.length;h++)g[d[f].attributes[h].name]=d[f].attributes[h].value;g.rel&&e.Link.push({"@":g})}b(null,e)}function e(a,b){var c=require("xml2js");(new c.Parser).parseString(a,b)}return typeof window=="undefined"?{ajax:c,parseXml:e}:window.XDomainRequest?{ajax:b,parseXml:d}:{ajax:a,parseXml:d}}),c("lib/couch",["./platform"],function(a){function c(a){if(!b){try{b=JSON.parse(localStorage.getItem("_shadowCouchRev"))}catch(c){}b||(b={})}return b[a]}function d(a,c){if(!b)try{b=JSON.parse(localStorage.getItem("_shadowCouchRev"))}catch(d){}b||(b={}),b[a]=c,localStorage.setItem("_shadowCouchRev",JSON.stringify(b))}function e(a){var b=0;while(b<a.length&&a[b]=="u")b++;return b<a.length&&a[b]=="_"&&(a="u"+a),a}function f(b,c,d,e,f){var g={url:c,method:b,error:function(a){a==404?f(null,undefined):f(a,null)},success:function(a){f(null,a)},timeout:3e3};e&&(g.headers={Authorization:"Bearer "+e}),g.fields={withCredentials:"true"},b!="GET"&&(g.data=d),a.ajax(g)}function g(a,b,c,g){f("GET",a+e(c),null,b,function(a,b){if(a)g(a,b);else{var e;try{e=JSON.parse(b)}catch(f){}e&&e._rev?(d(c,e._rev),g(null,e.value)):typeof b=="undefined"?g(null,undefined):g("unparsable data from couch")}})}function h(a,b,g,h,i){var j=c(g),k={value:h};j&&(k._rev=j),f("PUT",a+e(g),JSON.stringify(k),b,function(c,j){if(c)c==409?f("GET",a+e(g),null,b,function(c,j){if(c)i("after 409, got a "+c);else{var l;try{l=JSON.parse(j)._rev}catch(m){}l?(k={value:h,_rev:l},d(g,l),f("PUT",a+e(g),JSON.stringify(k),b,function(a,b){a?i("after 409, second attempt got "+a):i(null)})):i("after 409, got unparseable JSON")}}):i(c);else{var k;try{k=JSON.parse(j)}catch(l){}k&&k.rev&&d(g,k.rev),i(null)}})}function i(a,b,g,h){var i=c(g);f("DELETE",a+e(g)+(i?"?rev="+i:""),null,b,function(c,i){c==409?f("GET",a+e(g),null,b,function(c,i){if(c)h("after 409, got a "+c);else{var j;try{j=JSON.parse(i)._rev}catch(k){}j?(d(g,j),f("DELETE",a+e(g)+"?rev="+j,null,b,function(a,b){a?h("after 409, second attempt got "+a):(d(g,undefined),h(null))})):h("after 409, got unparseable JSON")}}):(c||d(g,undefined),h(c))})}var b=null;return{get:g,put:h,"delete":i}}),c("lib/dav",["./platform"],function(a){function b(a){var b=0;while(b<a.length&&a[b]=="u")b++;return b<a.length&&a[b]=="_"&&(a="u"+a),a}function c(b,c,d,e,f,g){var h={url:c,method:b,error:function(a){a==404?f(null,undefined):f(a,null)},success:function(a){f(null,a)},timeout:3e3};h.headers={Authorization:"Bearer "+e,"Content-Type":"text/plain;charset=UTF-8"},h.fields={withCredentials:"true"},b!="GET"&&(h.data=d),a.ajax(h)}function d(a,d,e,f){c("GET",a+b(e),null,d,f)}function e(a,d,e,f,g){c("PUT",a+b(e),f,d,g)}function f(a,d,e,f){c("DELETE",a+b(e),null,d,f)}return{get:d,put:e,"delete":f}}),c("lib/webfinger",["./platform"],function(a){function b(a,b){var c=a.split("@");c.length<2?b("That is not a user address. There is no @-sign in it"):c.length>2?b("That is not a user address. There is more than one @-sign in it"):/^[\.0-9A-Za-z]+$/.test(c[0])?/^[\.0-9A-Za-z\-]+$/.test(c[1])?b(null,["https://"+c[1]+"/.well-known/host-meta","http://"+c[1]+"/.well-known/host-meta"]):b('That is not a user address. There are non-dotalphanumeric symbols after the @-sign: "'+c[1]+'"'):b('That is not a user address. There are non-dotalphanumeric symbols before the @-sign: "'+c[0]+'"')}function c(b,f,g){var h=b.shift();h?a.ajax({url:h,success:function(a){e(a,function(e,h){e?d(a,function(a,d){a?c(b,f,g):g(null,d)}):g(null,h)})},error:function(a){c(b,f,g)},timeout:f}):g("could not fetch xrd")}function d(b,c){a.parseXml(b,function(a,b){if(a)c(a);else if(b&&b.Link){var d={};if(b.Link&&b.Link["@"])b.Link["@"].rel&&(d[b.Link["@"].rel]=b.Link["@"]);else for(var e=0;e<b.Link.length;e++)b.Link[e]["@"]&&b.Link[e]["@"].rel&&(d[b.Link[e]["@"].rel]=b.Link[e]["@"]);c(null,d)}else c("found valid xml but with no Link elements in there")})}function e(a,b){var c;try{c=JSON.parse(a)}catch(d){b("not valid JSON");return}var e={};if(c&&c.links)for(var f=0;f<c.links.length;f++)e[c.links[f].rel]=c.links[f];b(null,e)}function f(a,d,e){b(a,function(b,f){b?e(err):c(f,d.timeout,function(b,f){if(b)e("could not fetch host-meta for "+a);else if(f.lrdd&&f.lrdd.template){var g=f.lrdd.template.split("{uri}"),h=[g.join("acct:"+a),g.join(a)];c(h,d.timeout,function(b,c){b?e("could not fetch lrdd for "+a):c.remoteStorage?e(null,c.remoteStorage):e("could not extract storageInfo from lrdd")})}else e("could not extract lrdd template from host-meta")})})}function g(a,b){var c=a.split("{category}");return c.length!=2?"cannot-resolve-template:"+a:c[0]+b+c[1]}return{getStorageInfo:f,resolveTemplate:g}}),c("lib/hardcoded",["./platform"],function(a){function c(b,c,d){a.ajax({url:"http://proxy.unhosted.org/lookup?q=acct:"+b,success:function(a){var b;try{b=JSON.parse(a)}catch(c){}b?d(null,b):d("err: unparsable response from IrisCouch check")},error:function(a){d("err: during IrisCouch test:"+a)},timeout:c.timeout})}function d(a){var b=a.split("@");return["libredocs","mail","browserid","me"].indexOf(b[0])==-1?b[0]+"@iriscouch.com":b[2].substring(0,b[2].indexOf("."))+"@iriscouch.com"}function e(a,d,e){var f=a.split("@");if(f.length<2)e("That is not a user address. There is no @-sign in it");else if(f.length>2)e("That is not a user address. There is more than one @-sign in it");else if(!/^[\.0-9A-Za-z]+$/.test(f[0]))e('That is not a user address. There are non-dotalphanumeric symbols before the @-sign: "'+f[0]+'"');else if(!/^[\.0-9A-Za-z\-]+$/.test(f[1]))e('That is not a user address. There are non-dotalphanumeric symbols after the @-sign: "'+f[1]+'"');else{while(f[1].indexOf(".")!=-1){if(b[f[1]]){blueprint=b[f[1]],e(null,{api:blueprint.api,auth:blueprint.authPrefix+a+blueprint.authSuffix,template:blueprint.templatePrefix+a+blueprint.templateSuffix});return}f[1]=f[1].substring(f[1].indexOf(".")+1)}new Date<new Date("9/9/2012")?c(a,d,e):e("err: not a guessable domain, and fakefinger-migration has ended")}}var b={"iriscouch.com":{api:"CouchDB",authPrefix:"http://proxy.unhosted.org/OAuth.html?userAddress=",authSuffix:"",templatePrefix:"http://proxy.unhosted.org/IrisCouch/",templateSuffix:"/{category}/"}};return function(){var a={api:"simple",authPrefix:"http://surf.unhosted.org:4000/_oauth/",authSuffix:"",templatePrefix:"http://surf.unhosted.org:4000/",templateSuffix:"/{category}/"},c=["leidenuniv.nl","leiden.edu","uva.nl","vu.nl","eur.nl","maastrichtuniversity.nl","ru.nl","rug.nl","uu.nl","tudelft.nl","utwente.nl","tue.nl","tilburguniversity.edu","wur.nl","wageningenuniversity.nl","ou.nl","lumc.nl","amc.nl"];for(var d=0;d<c.length;d++)b[c[d]]=a}(),{guessStorageInfo:e}}),c("remoteStorage",["require","./lib/platform","./lib/couch","./lib/dav","./lib/webfinger","./lib/hardcoded"],function(a,b,c,d,e,f){var g=function(a,b){e.getStorageInfo(a,{timeout:3e3},function(c,d){c?f.guessStorageInfo(a,{timeout:3e3},function(a,c){b(a,c)}):b(c,d)})},h=function(a,b,c){var d=["redirect_uri="+encodeURIComponent(c),"scope="+encodeURIComponent(b.join(",")),"response_type=token","client_id="+encodeURIComponent(c)];return a.auth+(a.auth.indexOf("?")===-1?"?":"&")+d.join("&")},i=function(a,b){b(a==="CouchDB"?c:d)},j=function(a,b,c){var d=e.resolveTemplate(a.template,b);return{get:function(b,e){typeof b!="string"?e('argument "key" should be a string'):i(a.api,function(a){a.get(d,c,b,e)})},put:function(b,e,f){typeof b!="string"?f('argument "key" should be a string'):typeof e!="string"?f('argument "value" should be a string'):i(a.api,function(a){a.put(d,c,b,e,f)})},"delete":function(b,e){typeof b!="string"?e('argument "key" should be a string'):i(a.api,function(a){a["delete"](d,c,b,e)})}}},k=function(){var a,b;if(location.hash.length>0){a=location.hash.split("&");for(var c=0;c<a.length;c++){a[c][0]=="#"&&(a[c]=a[c].substring(1));if(a[c].substring(0,"access_token=".length)=="access_token=")return a[c].substring("access_token=".length)}}return null};return{getStorageInfo:g,createOAuthAddress:h,createClient:j,receiveToken:k}}),remoteStorage=d("remoteStorage")})()
!function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function d(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d].default&&(this.data[d]=[b.fields[d].default])}function e(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function f(a,b,c,d,e,f){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.fragments=f}function g(a,b,c){this.ref=a,this.label=b,this.isMaster=c}var h=function(a,b,c,d){var e=new h.fn.init(a,c,d);return b&&e.get(b),e},i=function(){return"undefined"!=typeof XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(JSON.parse(c.responseText))},e=function(){var a=c.status;throw new Error("Unexpected status code ["+a+"]")};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d(c):e(c))},c.open("GET",a+"#json",!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},j=function(){if("function"==typeof require&&require("http")){var a={},c=require("http"),d=require("https"),e=require("url");return require("querystring"),function(f,g){if(a[f])g(a[f]);else{var h=e.parse(f),i="https:"==h.protocol?d:c,j={hostname:h.hostname,path:h.path,query:h.query,headers:{Accept:"application/json"}};i.get(j,function(c){if(!c.statusCode||200!=c.statusCode)throw new Error("Unexpected status code ["+c.statusCode+"]");var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],h=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);h&&(a[f]=i),g(i)})})}}}};h.fn=h.prototype={constructor:h,data:null,get:function(a){var b=this;this.requestHandler(this.url,function(c){b.data=b.parse(c),b.bookmarks=b.data.bookmarks,a&&a(b,this)})},parse:function(a){var b,d,e,f,h,i={};for(h in a.forms)a.forms.hasOwnProperty(h)&&(f=a.forms[h],this.accessToken&&(f.fields.accessToken={type:"string","default":this.accessToken}),e=new c(f.name,f.fields,f.form_method,f.rel,f.enctype,f.action),i[h]=e);if(b=a.refs.map(function(a){return new g(a.ref,a.label,a.isMasterRef)})||[],d=b.filter(function(a){return a.isMaster===!0}),0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:i,master:d[0],oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||i()||j()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new d(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b<this.data.refs.length;b++)if(this.data.refs[b].label==a)return this.data.refs[b].ref}},h.fn.init.prototype=h.fn,c.prototype={},d.prototype={set:function(a,b){var c=this.form.fields[a];if(!c)throw new Error("Unknown field "+a);var d=this.data[a]||[];return c.multiple?d.push(b):d=[b],this.data[a]=d,this},ref:function(a){return this.set("ref",a)},query:function(a){return this.form.fields.q.multiple?this.set("q",a):(this.data.q=this.data.q||[],this.data.q.push(a),this)},submit:function(a){var b=this.form.action;if(this.data){var c=b.indexOf("?")>-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var g=0;g<e.length;g++)b+=c+d+"="+encodeURIComponent(e[g]),c="&"}}this.api.requestHandler(b,function(b){var c=b.results||b,d=c.map(function(a){var b={};for(var c in a.data[a.type])b[a.type+"."+c]=a.data[a.type][c];return new f(a.id,a.type,a.href,a.tags,a.slugs,b)});a&&a(d||[])})}},f.prototype={get:function(b){var c=e.call(this,b);return c.length?a.Prismic.Fragments.initField(c[0]):null},getAll:function(b){return e.call(this,b).map(function(b){return a.Prismic.Fragments.initField(b)},this)},getImage:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Image?c:c instanceof a.Prismic.Fragments.StructuredText?c:null},getAllImages:function(b){var c=this.getAll(b);return c.map(function(b){if(b instanceof a.Prismic.Fragments.Image)return b;if(b instanceof a.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(b,c){var d=this.get(b);if(d instanceof a.Prismic.Fragments.Image)return d.getView(c);if(d instanceof a.Prismic.Fragments.StructuredText)for(var e=0;e<d.blocks.length;e++)if("image"==d.blocks[e].type)return d.blocks[e];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Date?c.value:void 0},getBoolean:function(a){var b=this.get(a);return b.value&&("yes"==b.value.toLowerCase()||"on"==b.value.toLowerCase()||"true"==b.value.toLowerCase())},getText:function(b,c){var d=this.get(b);return d instanceof a.Prismic.Fragments.StructuredText?d.blocks.map(function(a){return a.text?a.text+(c?c:""):void 0}).join("\n"):d instanceof a.Prismic.Fragments.Text&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Number&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Select&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Color&&d.value?d.value+(c?c:""):void 0},getStructuredText:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.StructuredText?c:void 0},getNumber:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Number?c.value:void 0},getHtml:function(a,b){var c=this.get(a);return c&&c.asHtml?c.asHtml(b):void 0},asHtml:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asHtml?'<section data-field="'+c+'">'+d.asHtml(a)+"</section>":"")}return b.join("")}},g.prototype={},a.Prismic={Api:h}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";function b(a){this.value=a}function c(a){this.value=a,this.document=a.document,this.isBroken=a.isBroken}function d(a){this.value=a}function e(a){this.value=a}function f(a){this.value=a}function g(a){this.value=new Date(a)}function h(a){this.value=a}function i(a,b){this.main=a,this.views=b||{}}function j(a,b,c){this.url=a,this.width=b,this.height=c}function k(a,b){this.tag=a,this.blocks=b}function l(a){this.blocks=a}function m(a){var b,c=[],d=[];return Array.isArray(a)?(a.forEach(function(a){c.length>0?(c[c.length-1],b=new k(null,[]),b.blocks.push(a),c.push(b)):(b=new k(null,[]),b.blocks.push(a),c.push(b))}),c.forEach(function(a){a.tag?(d.push("<"+a.tag+">"),a.blocks.forEach(function(a){d.push(m(a))}),d.push("</"+a.tag+">")):a.blocks.forEach(function(a){d.push(m(a))})})):("heading1"==a.type&&d.push("<h1>"+a.text+"</h1>"),"heading2"==a.type&&d.push("<h2>"+a.text+"</h2>"),"heading3"==a.type&&d.push("<h3>"+a.text+"</h3>"),"paragraph"==a.type&&d.push("<p>"+a.text+"</p>"),"image"==a.type&&d.push('<p><img src="'+a.url+'"></p>')),d.join("")}function n(a){var h,k;switch(a.type){case"Color":h=new e(a.value);break;case"Number":h=new f(a.value);break;case"Date":h=new g(a.value);break;case"Text":h=new b(a.value);break;case"Embed":throw new Error("not implemented");case"Select":h=new d(a.value);break;case"Image":var k=a.value.main;h=new i(new j(k.url,k.dimensions.width,k.dimensions.height),a.value.views);break;case"StructuredText":h=new l(a.value);break;case"Link.document":h=new c(a.value);break;case"Link.web":throw new Error("not implemented");default:console.log("Type not found:",a.type)}return h}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},c.prototype={asHtml:function(){return"<a></a>"}},d.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},e.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},f.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},g.prototype={asText:function(){throw new Error("not implemented")},asHtml:function(){return"<time>"+this.value+"</time>"}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},i.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()}},j.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+">"}},l.prototype={getTitle:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if(0==b.type.indexOf("heading"))return b}},getFirstParagraph:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("paragraph"==b.type)return b}},getParagraphs:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];"paragraph"==c.type&&a.push(c)}return a},getParagraph:function(a){return this.getParagraphs()[a]},getFirstImage:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("image"==b.type)return new j(b.data.url,b.data.dimensions.width,b.data.dimensions.height)}},asHtml:function(){return m.call(this,this.blocks)}},a.Prismic.Fragments={Image:i,ImageView:j,Text:b,Number:f,Date:g,Select:d,Color:e,StructuredText:l,initField:n}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
Example #10
0
12|(63&a.charCodeAt(1))<<6|63&a.charCodeAt(2));default:return b((31&a.charCodeAt(0))<<6|63&a.charCodeAt(1))}},s=function(a){return a.replace(t,u)},p=function(a){var e=a.length,h=e%4;a=(0<e?c[a.charAt(0)]<<18:0)|(1<e?c[a.charAt(1)]<<12:0)|(2<e?c[a.charAt(2)]<<6:0)|(3<e?c[a.charAt(3)]:0);a=[b(a>>>16),b(a>>>8&255),b(a&255)];a.length-=[0,0,2,1][h];return a.join("")},w=a.atob||function(a){return a.replace(/[\s\S]{1,4}/g,p)},y=function(a){return s(w(a))},k=function(a){return y(a.replace(/[-_]/g,function(a){return"-"==
!function(){Object.create||(Object.create=function(){function t(){}return function(e){if(1!=arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return t.prototype=e,new t}}())}(),function(t,e){"use strict";function n(t,e,n,r,i,o){this.name=t,this.fields=e,this.form_method=n,this.rel=r,this.enctype=i,this.action=o}function r(t,e,n){this.api=t,this.form=e,this.data=n||{};for(var r in e.fields)e.fields[r]["default"]&&(this.data[r]=[e.fields[r]["default"]])}function i(t,e,n,r,i,o,s,a){this.page=t,this.results_per_page=e,this.results_size=n,this.total_results_size=r,this.total_pages=i,this.next_page=o,this.prev_page=s,this.results=a}function o(t,e,n,r){this.id=t,this.slug=e,this.type=n,this.tags=r}function s(t,e,n,r,i){this.ref=t,this.label=e,this.isMaster=n,this.scheduledAt=r,this.id=i}function a(){this.cache={},this.states={}}var u=function(e,n,r,i,o,s){var a=new u.fn.init(e,r,i,o,s);return a.get(function(e,r){return n&&e?n(e):(r&&(a.data=r,a.bookmarks=r.bookmarks,a.experiments=new t.Prismic.Experiments(r.experiments)),n?n(null,a):void 0)}),a};u.fn=u.prototype={AT:"at",ANY:"any",SIMILAR:"similar",FULLTEXT:"fulltext",NUMBER:{GT:"number.gt",LT:"number.lt"},DATE:{AFTER:"date.after",BEFORE:"date.before",BETWEEN:"date.between"},DOCUMENT:{ID:"document.id",TYPE:"document.type",TAGS:"document.tags"},constructor:u,data:null,get:function(t){var e=this,n=this.apiCacheKey;this.apiCache.get(n,function(r,i){return r?t(r):i?t(null,i):void e.requestHandler(e.url,function(r,i,o,s){if(r)return t(r,null,o);var a=e.parse(i);s|=e.apiDataTTL,e.apiCache.set(n,a,s,function(e){return e?t(e,null,o):t(null,a,o)})})})},refresh:function(e){var n=this,r=this.apiCacheKey;this.apiCache.remove(r,function(r){if(e&&r)return e(r);if(!e&&r)throw r;n.get(function(r,i){if(e&&r)return e(r);if(!e&&r)throw r;return n.data=i,n.bookmarks=i.bookmarks,n.experiments=new t.Prismic.Experiments(i.experiments),e?e():void 0})})},parse:function(t){var e,r,i,o,a,u,c,l={};for(c in t.forms)t.forms.hasOwnProperty(c)&&(u=t.forms[c],this.accessToken&&(u.fields.access_token={},u.fields.access_token.type="string",u.fields.access_token["default"]=this.accessToken),i=new n(u.name,u.fields,u.form_method,u.rel,u.enctype,u.action),l[c]=i);if(e=t.refs.map(function(t){return new s(t.ref,t.label,t.isMasterRef,t.scheduledAt,t.id)})||[],r=e.filter(function(t){return t.isMaster===!0}),o=t.types,a=t.tags,0===r.length)throw"No master ref.";return{bookmarks:t.bookmarks||{},refs:e,forms:l,master:r[0],types:o,tags:a,experiments:t.experiments,oauthInitiate:t.oauth_initiate,oauthToken:t.oauth_token}},init:function(e,n,r,i,o){return this.url=e+(n?(e.indexOf("?")>-1?"&":"?")+"access_token="+n:""),this.accessToken=n,this.requestHandler=r||t.Prismic.Utils.request(),this.apiCache=i||new a,this.apiCacheKey=this.url+(this.accessToken?"#"+this.accessToken:""),this.apiDataTTL=o||5,this},forms:function(t){return this.form(t)},form:function(t){var e=this.data.forms[t];return e?new r(this,e,{}):void 0},master:function(){return this.data.master.ref},ref:function(t){for(var e=0;e<this.data.refs.length;e++)if(this.data.refs[e].label==t)return this.data.refs[e].ref},currentExperiment:function(){return this.experiments.current()},parseDoc:function(n){var r=[];n.linked_documents&&(r=n.linked_documents.map(function(t){return new o(t.id,t.slug,t.type,t.tags)}));var i={};for(var s in n.data[n.type])i[n.type+"."+s]=n.data[n.type][s];var a=[];if(n.slugs!==e)for(var u=0;u<n.slugs.length;u++)a.push(decodeURIComponent(n.slugs[u]));return new t.Prismic.Document(n.id,n.type,n.href,n.tags,a,r,i)},previewSession:function(e,n,r,i){var o=this,s=t.Prismic.Predicates;this.requestHandler(e,function(t,a,u){if(t)return console.log("Error from the request"),void i(t,r,u);try{var c=a.mainDocument;c?o.form("everything").query(s.at("document.id",c)).ref(e).submit(function(t,e){0===e.results.length?i(null,r,u):i(null,n(e.results[0]),u)}):i(null,r,u)}catch(l){console.log("Caught e ",l),i(l,r,u)}})}},u.fn.init.prototype=u.fn,n.prototype={},r.prototype={set:function(t,n){var r=this.form.fields[t];if(!r)throw new Error("Unknown field "+t);var i=this.data[t]||[];return(""===n||n===e)&&(n=null),r.multiple?n&&i.push(n):i=n&&[n],this.data[t]=i,this},ref:function(t){return this.set("ref",t)},query:function(t){if("string"==typeof t)return this.set("q",t);var e=[].slice.apply(arguments),n=[];return e.forEach(function(t){var e=0===t[1].indexOf("my.")||0===t[1].indexOf("document.")?t[1]:'"'+t[1]+'"';n.push("[:d = "+t[0]+"("+e+", "+function(){return t.slice(2).map(function(t){return"string"==typeof t?'"'+t+'"':Array.isArray(t)?"["+t.map(function(t){return'"'+t+'"'}).join(",")+"]":t instanceof Date?t.getTime():t}).join(",")}()+")]")}),this.query("["+n.join("")+"]")},pageSize:function(t){return this.set("pageSize",t)},page:function(t){return this.set("page",t)},orderings:function(t){return this.set("orderings",t)},submit:function(t){var e=this.form.action;if(this.data){var n=e.indexOf("?")>-1?"&":"?";for(var r in this.data)if(this.data.hasOwnProperty(r)){var o=this.data[r];if(o)for(var s=0;s<o.length;s++)e+=n+r+"="+encodeURIComponent(o[s]),n="&"}}var a=e+(this.api.accessToken?"#"+this.api.accessToken:""),c=this.api.apiCache,l=this;c.get(a,function(n,r){return n?t(n):r?t(null,r):void l.api.requestHandler(e,function(e,n,r,o){if(e)return void t(e,null,r);var s=n.results.map(u.fn.parseDoc),l=new i(n.page,n.results_per_page,n.results_size,n.total_results_size,n.total_pages,n.next_page,n.prev_page,s||[]);return o?void c.set(a,l,o,function(e){return e?t(e):t(null,l)}):t(null,l)})})}},s.prototype={},a.prototype={get:function(t,e){var n=this.cache[t];return n&&!this.isExpired(t)?e(null,n.data):e()},set:function(t,e,n,r){return this.cache[t]={data:e,expiredIn:n?Date.now()+1e3*n:0},r()},isExpired:function(t){var e=this.cache[t];return e?0!==e.expiredIn&&e.expiredIn<Date.now():!1},remove:function(t,e){return delete this.cache[t],e()},clear:function(t,e){return this.cache={},e()}},t.Prismic={experimentCookie:"io.prismic.experiment",previewCookie:"io.prismic.preview",Api:u}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t,e){"use strict";var n=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(t,e){var n=new XMLHttpRequest,r=function(){var t,r=/max-age\s*=\s*(\d+)/.exec(n.getResponseHeader("Cache-Control"));r&&r.length>1&&(t=parseInt(r[1],10)),e(null,JSON.parse(n.responseText),n,t)},i=function(){var r=n.status;e(new Error("Unexpected status code ["+r+"] on URL "+t),null,n)};n.onreadystatechange=function(){4===n.readyState&&(n.status&&200==n.status?r():i())},n.open("GET",t,!0),n.setRequestHeader("Accept","application/json"),n.send()}:void 0},r=function(){return"undefined"!=typeof XDomainRequest?function(t,e){var n=new XDomainRequest,r=function(){var t,r=/max-age\s*=\s*(\d+)/.exec(xhr.getResponseHeader("Cache-Control"));r&&r.length>1&&(t=parseInt(r[1],10)),e(null,JSON.parse(n.responseText),n,t)},i=function(t){e(new Error(t),null,n)};n.onload=function(){r(n)},n.onerror=function(){i("Unexpected status code on URL "+t)},n.open("GET",t,!0),n.ontimeout=function(){i("Request timeout")},n.onprogress=function(){},n.send()}:void 0},i=function(){if("function"==typeof require&&require("http")){var t=require("http"),n=require("https"),r=require("url"),i=(require("querystring"),require("../package.json"));return function(o,s){var a=r.parse(o),u="https:"==a.protocol?n:t,c={hostname:a.hostname,path:a.path,query:a.query,headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+i.version+" NodeJS/"+process.version}};u.get(c,function(t){if(t.statusCode&&200==t.statusCode){var n="";t.setEncoding("utf8"),t.on("data",function(t){n+=t}),t.on("end",function(){var r=JSON.parse(n),i=t.headers["cache-control"],o=i&&/max-age=(\d+)/.test(i)?parseInt(/max-age=(\d+)/.exec(i)[1],10):e;s(null,r,t,o)})}else s(new Error("Unexpected status code ["+t.statusCode+"] on URL "+o),null,t)})}}},o=0,s=[],a=function(){if(!(0===s.length||o>=t.Prismic.Utils.MAX_CONNECTIONS)){o++;var e=s.shift(),u=n()||r()||i()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}();u.call(this,e.url,function(t,n,r,i){o--,e.callback(t,n,r,i),a()})}},u=function(){return function(t,e){s.push({url:t,callback:e}),a()}};t.Prismic.Utils={MAX_CONNECTIONS:20,request:u}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";function e(){}function n(t,e,n,r,i,o,s){this.id=t,this.type=e,this.href=n,this.tags=r,this.slug=i?i[0]:"-",this.slugs=i,this.linkedDocuments=o,this.fragments=s}function r(t){this.fragments=t}function i(t){var e={};return t&&"[object Function]"===e.toString.call(t)}e.prototype={get:function(e){var n=this._getFragments(e);return n.length?t.Prismic.Fragments.initField(n[0]):null},getAll:function(e){return this._getFragments(e).map(function(e){return t.Prismic.Fragments.initField(e)},this)},getImage:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Image?n:n instanceof t.Prismic.Fragments.StructuredText?n:null},getAllImages:function(e){var n=this.getAll(e);return n.map(function(e){if(e instanceof t.Prismic.Fragments.Image)return e;if(e instanceof t.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(e,n){var r=this.get(e);if(r instanceof t.Prismic.Fragments.Image)return r.getView(n);if(r instanceof t.Prismic.Fragments.StructuredText)for(var i=0;i<r.blocks.length;i++)if("image"==r.blocks[i].type)return r.blocks[i];return null},getAllImageViews:function(t,e){return this.getAllImages(t).map(function(t){return t.getView(e)})},getTimestamp:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Timestamp?n.value:void 0},getDate:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Date?n.value:void 0},getBoolean:function(t){var e=this.get(t);return e.value&&("yes"==e.value.toLowerCase()||"on"==e.value.toLowerCase()||"true"==e.value.toLowerCase())},getText:function(e,n){var r=this.get(e);return r instanceof t.Prismic.Fragments.StructuredText?r.blocks.map(function(t){return t.text?t.text+(n?n:""):void 0}).join("\n"):r instanceof t.Prismic.Fragments.Text&&r.value?r.value+(n?n:""):r instanceof t.Prismic.Fragments.Number&&r.value?r.value+(n?n:""):r instanceof t.Prismic.Fragments.Select&&r.value?r.value+(n?n:""):r instanceof t.Prismic.Fragments.Color&&r.value?r.value+(n?n:""):void 0},getStructuredText:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.StructuredText?n:null},getLink:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.WebLink||n instanceof t.Prismic.Fragments.DocumentLink||n instanceof t.Prismic.Fragments.ImageLink?n:null},getNumber:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Number?n.value:null},getColor:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Color?n.value:null},getGeoPoint:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.GeoPoint?n:null},getGroup:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Group?n:null},getHtml:function(t,e){if(!i(e)){var n=e;e=function(t,e){return n.linkResolver(n,t,e)}}var r=this.get(t);return r&&r.asHtml?r.asHtml(e):null},asHtml:function(t){if(!i(t)){var e=t;t=function(t,n){return e.linkResolver(e,t,n)}}var n=[];for(var r in this.fragments){var o=this.get(r);n.push(o&&o.asHtml?'<section data-field="'+r+'">'+o.asHtml(t)+"</section>":"")}return n.join("")},asText:function(t){if(!i(t)){var e=t;t=function(t,n){return e.linkResolver(e,t,n)}}var n=[];for(var r in this.fragments){var o=this.get(r);n.push(o&&o.asText?o.asText(t):"")}return n.join("")},_getFragments:function(t){return this.fragments&&this.fragments[t]?Array.isArray(this.fragments[t])?this.fragments[t]:[this.fragments[t]]:[]}},n.prototype=Object.create(e.prototype,{}),r.prototype=Object.create(e.prototype,{}),t.Prismic.Document=n,t.Prismic.GroupDoc=r}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";function e(t){this.value=t}function n(t){this.value=t,this.document=t.document,this.isBroken=t.isBroken}function r(t){this.value=t}function i(t){this.value=t}function o(t){this.value=t}function s(t){this.value=t}function a(t){this.value=t}function u(t){this.latitude=t.latitude,this.longitude=t.longitude}function c(t){this.value=t}function l(t){this.value=new Date(t)}function f(t){var e=24==t.length?t.substring(0,22)+":"+t.substring(22,24):t;this.value=new Date(e)}function h(t){this.value=t}function p(t,e){this.main=t,this.views=e||{}}function m(t,e,n,r){this.url=t,this.width=e,this.height=n,this.alt=r}function d(e){this.value=[];for(var n=0;n<e.length;n++)this.value.push(new t.Prismic.GroupDoc(e[n]))}function g(t){this.blocks=t}function v(t){return t&&t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>")}function y(t,e,n,r){if(!e||!e.length)return v(t);var i={},o={};e.forEach(function(t){i[t.start]||(i[t.start]=[]),o[t.end]||(o[t.end]=[]),i[t.start].push(t),o[t.end].unshift(t)});for(var s,a="",u=[],c=0,l=t.length+1;l>c;c++)o[c]&&o[c].forEach(function(){var t=u.pop(),e=k(t.span,t.text,r);0===u.length?a+=e:u[u.length-1].text+=e}),i[c]&&(i[c].sort(function(t,e){return e.end-e.start-(t.end-t.start)}),i[c].forEach(function(t){var e=null;if("hyperlink"==t.type){var r=x(t.data);if(!r)return console&&console.error&&console.error("Impossible to convert span.data as a Fragment",t),"";e=r.url(n),t.url=e}var i={span:t,text:""};u.push(i)})),c<t.length&&(s=t[c],0===u.length?a+=v(s):u[u.length-1].text+=v(s));return a}function x(t){var v={Color:a,Number:c,Date:l,Timestamp:f,Text:e,Embed:h,GeoPoint:u,Select:s,StructuredText:g,"Link.document":n,"Link.web":r,"Link.file":i,"Link.image":o,Group:d};if(v[t.type])return new v[t.type](t.value);if("Image"===t.type){var y=t.value.main,x=new p(new m(y.url,y.dimensions.width,y.dimensions.height,y.alt),{});for(var b in t.value.views)y=t.value.views[b],x.views[b]=new m(y.url,y.dimensions.width,y.dimensions.height,y.alt);return x}console&&console.log&&console.log("Fragment type not supported: ",t.type)}function b(t){var e={};return t&&"[object Function]"===e.toString.call(t)}function k(t,e,n){if(n){var r=n(t,e);if(r)return r}var i={heading1:"h1",heading2:"h2",heading3:"h3",heading4:"h4",heading5:"h5",heading6:"h6",paragraph:"p",preformatted:"pre","list-item":"li","o-list-item":"li","group-list-item":"ul","group-o-list-item":"ol",strong:"strong",em:"em"};if(i[t.type]){var o=i[t.type],s=t.label?' class="'+t.label+'"':"";return"<"+o+s+">"+e+"</"+o+">"}if("image"==t.type){var a=t.label?" "+t.label:"",u='<img src="'+t.url+'" alt="'+t.alt+'">';return'<p class="block-img'+a+'">'+(t.linkUrl?'<a href="'+t.linkUrl+'">'+u+"</a>":u)+"</p>"}return"embed"==t.type?'<div data-oembed="'+t.embed_url+'" data-oembed-type="'+t.type+'" data-oembed-provider="'+t.provider_name+(t.label?'" class="'+t.label:"")+'">'+t.oembed.html+"</div>":"hyperlink"===t.type?'<a href="'+t.url+'">'+e+"</a>":"label"===t.type?'<span class="'+t.data.label+'">'+e+"</span>":"<!-- Warning: "+t.type+" not implemented. Upgrade the Developer Kit. -->"+e}e.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},n.prototype={asHtml:function(t){return'<a href="'+this.url(t)+'">'+this.url(t)+"</a>"},url:function(t){return t(this.document,this.isBroken)},asText:function(t){return this.url(t)}},r.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},i.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},o.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+this.alt+'"></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},s.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},a.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},u.prototype={asHtml:function(){return'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},c.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},l.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},f.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},h.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},p.prototype={getView:function(t){return"main"===t?this.main:this.views[t]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},m.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return'<img src="'+this.url+'" width="'+this.width+'" height="'+this.height+'" alt="'+this.alt+'">'},asText:function(){return""}},d.prototype={asHtml:function(t){for(var e="",n=0;n<this.value.length;n++)e+=this.value[n].asHtml(t);return e},toArray:function(){return this.value},asText:function(t){for(var e="",n=0;n<this.value.length;n++)for(var r in this.value[n])e+=this.value[n][r].asText(t);return e}},g.prototype={getTitle:function(){for(var t=0;t<this.blocks.length;t++){var e=this.blocks[t];if(0===e.type.indexOf("heading"))return e}},getFirstParagraph:function(){for(var t=0;t<this.blocks.length;t++){var e=this.blocks[t];if("paragraph"==e.type)return e}},getParagraphs:function(){for(var t=[],e=0;e<this.blocks.length;e++){var n=this.blocks[e];"paragraph"==n.type&&t.push(n)}return t},getParagraph:function(t){return this.getParagraphs()[t]},getFirstImage:function(){for(var t=0;t<this.blocks.length;t++){var e=this.blocks[t];if("image"==e.type)return new m(e.url,e.dimensions.width,e.dimensions.height,e.alt)}},asHtml:function(t,e){var n,r,i=[],o=[];if(!b(t)){var s=t;t=function(t,e){return s.linkResolver(s,t,e)}}if(Array.isArray(this.blocks)){for(var a=0;a<this.blocks.length;a++){if(r=this.blocks[a],"image"==r.type&&r.linkTo){var u=x(r.linkTo);r.linkUrl=u.url(t)}"list-item"!==r.type&&"o-list-item"!==r.type?(i.push(r),n=null):n&&n.type=="group-"+r.type?n.blocks.push(r):(n={type:"group-"+r.type,blocks:[r]},i.push(n))}var c=function(n){var r="";return n.blocks?n.blocks.forEach(function(t){r+=k(t,c(t),e)}):r=y(n.text,n.spans,t,e),r};i.forEach(function(t){o.push(k(t,c(t),e))})}return o.join("")},asText:function(){for(var t=[],e=0;e<this.blocks.length;e++){var n=this.blocks[e];n.text&&t.push(n.text)}return t.join(" ")}},t.Prismic.Fragments={Image:p,ImageView:m,Text:e,Number:c,Date:l,Timestamp:f,Select:s,Color:a,StructuredText:g,WebLink:r,DocumentLink:n,ImageLink:o,FileLink:i,Group:d,GeoPoint:u,initField:x,insertSpans:y}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";var e={at:function(t,e){return["at",t,e]},any:function(t,e){return["any",t,e]},fulltext:function(t,e){return["fulltext",t,e]},similar:function(t,e){return["similar",t,e]},gt:function(t,e){return["number.gt",t,e]},lt:function(t,e){return["number.lt",t,e]},inRange:function(t,e,n){return["number.inRange",t,e,n]},dateBefore:function(t,e){return["date.before",t,e]},dateAfter:function(t,e){return["date.after",t,e]},dateBetween:function(t,e,n){return["date.between",t,e,n]},dayOfMonth:function(t,e){return["date.day-of-month",t,e]},dayOfMonthAfter:function(t,e){return["date.day-of-month-after",t,e]},dayOfMonthBefore:function(t,e){return["date.day-of-month-before",t,e]},dayOfWeek:function(t,e){return["date.day-of-week",t,e]},dayOfWeekAfter:function(t,e){return["date.day-of-week-after",t,e]},dayOfWeekBefore:function(t,e){return["date.day-of-week-before",t,e]},month:function(t,e){return["date.month",t,e]},monthBefore:function(t,e){return["date.month-before",t,e]},monthAfter:function(t,e){return["date.month-after",t,e]},year:function(t,e){return["date.year",t,e]},hour:function(t,e){return["date.hour",t,e]},hourBefore:function(t,e){return["date.hour-before",t,e]},hourAfter:function(t,e){return["date.hour-after",t,e]},near:function(t,e,n,r){return["geopoint.near",t,e,n,r]}};t.Prismic.Predicates=e}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";function e(t){var e=[],r=[];t&&(t.drafts&&t.drafts.forEach(function(t){e.push(new n(t))}),t.running&&t.running.forEach(function(t){r.push(new n(t))})),this.drafts=e,this.running=r}function n(t){this.data=t;var e=[];t.variations&&t.variations.forEach(function(t){e.push(new r(t))}),this.variations=e}function r(t){this.data=t}e.prototype.current=function(){return this.running.length>0?this.running[0]:null},e.prototype.currentGoogleId=function(){return this.current()?this.current().googleId():null},e.prototype.refFromCookie=function(t){if(!t||""===t.trim())return null;var e=t.trim().split(" ");if(e.length<2)return null;var n=e[0],r=parseInt(e[1],10),i=this.running.filter(function(t){return t.googleId()==n&&t.variations.length>r})[0];return i?i.variations[r].ref():null},n.prototype.id=function(){return this.data.id},n.prototype.googleId=function(){return this.data.googleId},n.prototype.name=function(){return this.data.name},r.prototype.id=function(){return this.data.id},r.prototype.ref=function(){return this.data.ref},r.prototype.label=function(){return this.data.label},t.Prismic.Experiments=e,t.Prismic.Experiment=n,t.Prismic.Variation=r}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){t.Prismic.version="1.0.26"}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
!function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function d(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d]["default"]&&(this.data[d]=[b.fields[d]["default"]])}function e(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function f(a,b,c,d,e,f,g,h){this.page=a,this.results_per_page=b,this.results_size=c,this.total_results_size=d,this.total_pages=e,this.next_page=f,this.prev_page=g,this.results=h}function g(a,b,c,d){this.id=a,this.slug=b,this.type=c,this.tags=d}function h(a,b,c,d,e,f,g){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.slugs=e,this.linkedDocuments=f,this.fragments=g}function i(a,b,c,d,e){this.ref=a,this.label=b,this.isMaster=c,this.scheduledAt=d,this.id=e}function j(){this.cache={},this.states={}}var k=function(a,b,c,d,e){var f=new k.fn.init(a,c,d,e);return b&&f.get(b),f},l=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(){var d=c.status;b(new Error("Unexpected status code ["+d+"] on URL "+a),null,c)};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d():e())},c.open("GET",a,!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},m=function(){return"undefined"!=typeof XDomainRequest?function(a,b){var c=new XDomainRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(a){b(new Error(a),null,c)};c.onload=function(){d(c)},c.onerror=function(){e("Unexpected status code on URL "+a)},c.open("GET",a,!0),c.ontimeout=function(){e("Request timeout")},c.onprogress=function(){},c.send()}:void 0},n=function(){if("function"==typeof require&&require("http")){var a={},c=require("http"),d=require("https"),e=require("url"),f=(require("querystring"),require("../package.json"));return function(g,h){if(a[g])h(null,a[g]);else{var i=e.parse(g),j="https:"==i.protocol?d:c,k={hostname:i.hostname,path:i.path,query:i.query,headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+f.version+" NodeJS/"+process.version}};j.get(k,function(c){if(c.statusCode&&200==c.statusCode){var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],f=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);f&&(a[g]=i),h(null,i,c)})}else h(new Error("Unexpected status code ["+c.statusCode+"] on URL "+g),null,c)})}}}};k.fn=k.prototype={AT:"at",ANY:"any",EVERYTHING:"everything",SIMILAR:"similar",FULLTEXT:"fulltext",NUMBER:{GT:"number.gt",LT:"number.lt"},DATE:{AFTER:"date.after",BEFORE:"date.before",BETWEEN:"date.between"},DOCUMENT:{ID:"document.id",TYPE:"document.type",TAGS:"document.tags"},constructor:k,data:null,get:function(a){var b=this,c=this.url+(this.accessToken?"#"+this.accessToken:"");this.apiCache.getOrSet(c,5,function(a){b.requestHandler(b.url,function(c,d,e){c?a&&a(c,null,e):a&&a(null,b.parse(d),e)})},function(c,d,e){c?a&&a(c,null,e):(b.data=d,b.bookmarks=d.bookmarks,a&&a(null,b,e))})},parse:function(a){var b,d,e,f,g,h,j,k={};for(j in a.forms)a.forms.hasOwnProperty(j)&&(h=a.forms[j],this.accessToken&&(h.fields.access_token={},h.fields.access_token.type="string",h.fields.access_token["default"]=this.accessToken),e=new c(h.name,h.fields,h.form_method,h.rel,h.enctype,h.action),k[j]=e);if(b=a.refs.map(function(a){return new i(a.ref,a.label,a.isMasterRef,a.scheduledAt,a.id)})||[],d=b.filter(function(a){return a.isMaster===!0}),f=a.types,g=a.tags,0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:k,master:d[0],types:f,tags:g,oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c,d){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||l()||m()||n()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this.apiCache=d||new j,this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new d(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b<this.data.refs.length;b++)if(this.data.refs[b].label==a)return this.data.refs[b].ref}},k.fn.init.prototype=k.fn,c.prototype={},d.prototype={set:function(a,c){var d=this.form.fields[a];if(!d)throw new Error("Unknown field "+a);var e=this.data[a]||[];return(""===c||c===b)&&(c=null),d.multiple?null!=c&&e.push(c):e=null!=c&&[c],this.data[a]=e,this},ref:function(a){return this.set("ref",a)},query:function(a){if("string"==typeof a)return this.set("q",a);var b="string"==typeof a[0]?[a]:a,c=[];return b.forEach(function(a){var b=0==a[1].indexOf("my.")||0==a[1].indexOf("document.")?a[1]:'"'+a[1]+'"';c.push("[:d = "+a[0]+"("+b+", "+function(){return a.slice(2).map(function(a){return"string"==typeof a?'"'+a+'"':Array.isArray(a)?"["+a.map(function(a){return'"'+a+'"'}).join(",")+"]":a}).join(",")}()+")]")}),this.query("["+c.join("")+"]")},pageSize:function(a){return this.set("pageSize",a)},page:function(a){return this.set("page",a)},orderings:function(a){return this.set("orderings",a)},submit:function(a){var b=this.form.action;if(this.data){var c=b.indexOf("?")>-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var i=0;i<e.length;i++)b+=c+d+"="+encodeURIComponent(e[i]),c="&"}}this.api.requestHandler(b,function(b,c,d){if(b)return void a(b,null,d);var e=c.results.map(function(a){var b=[];a.linked_documents&&(b=a.linked_documents.map(function(a){return new g(a.id,a.slug,a.type,a.tags)}));var c={};for(var d in a.data[a.type])c[a.type+"."+d]=a.data[a.type][d];for(var e in c){var f=c[e];if("StructuredText"===f.type)for(var i in f.value){var j=f.value[i],k=[];for(var l in j.spans){var m=j.spans[l];m.start<m.end&&k.push(m)}j.spans=k}}return new h(a.id,a.type,a.href,a.tags,a.slugs,b,c)});a(null,new f(c.page,c.results_per_page,c.results_size,c.total_results_size,c.total_pages,c.next_page,c.prev_page,e||[]),d)})}},h.prototype={get:function(b){var c=e.call(this,b);return c.length?a.Prismic.Fragments.initField(c[0]):null},getAll:function(b){return e.call(this,b).map(function(b){return a.Prismic.Fragments.initField(b)},this)},getImage:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Image?c:c instanceof a.Prismic.Fragments.StructuredText?c:null},getAllImages:function(b){var c=this.getAll(b);return c.map(function(b){if(b instanceof a.Prismic.Fragments.Image)return b;if(b instanceof a.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(b,c){var d=this.get(b);if(d instanceof a.Prismic.Fragments.Image)return d.getView(c);if(d instanceof a.Prismic.Fragments.StructuredText)for(var e=0;e<d.blocks.length;e++)if("image"==d.blocks[e].type)return d.blocks[e];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Date?c.value:void 0},getBoolean:function(a){var b=this.get(a);return b.value&&("yes"==b.value.toLowerCase()||"on"==b.value.toLowerCase()||"true"==b.value.toLowerCase())},getText:function(b,c){var d=this.get(b);return d instanceof a.Prismic.Fragments.StructuredText?d.blocks.map(function(a){return a.text?a.text+(c?c:""):void 0}).join("\n"):d instanceof a.Prismic.Fragments.Text&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Number&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Select&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Color&&d.value?d.value+(c?c:""):void 0},getStructuredText:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.StructuredText?c:void 0},getNumber:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Number?c.value:void 0},getColor:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Color?c.value:void 0},getGeoPoint:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.GeoPoint?c:void 0},getGroup:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Group?c:void 0},getHtml:function(a,b){var c=this.get(a);return c&&c.asHtml?c.asHtml(b):void 0},asHtml:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asHtml?'<section data-field="'+c+'">'+d.asHtml(a)+"</section>":"")}return b.join("")},asText:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asText?d.asText(a):"")}return b.join("")}},i.prototype={},j.prototype={get:function(a){var b=this.cache[a];return b&&(!this.isExpired(a)||this.isExpired(a)&&this.isInProgress(a))?b.data:null},set:function(a,b,c){this.cache[a]={data:b,expiredIn:c?Date.now()+1e3*c:0}},getOrSet:function(a,b,c,d){var e=this.get(a),f=this;if(e)d&&d(null,e);else{this.states[a]="progress";{c(function(c,e,g){f.set(a,e,b),delete f.states[a],d&&d(c,e,g)})}}},isExpired:function(a){var b=this.cache[a];return b?0!=b.expiredIn&&b.expiredIn<Date.now():!1},isInProgress:function(a){return"progress"==this.states[a]},exists:function(a){return!!this.cache[a]},remove:function(a){return delete this.cache[a]},clear:function(){this.cache={}}},a.Prismic={Api:k}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";function b(a){this.value=a}function c(a){this.value=a,this.document=a.document,this.isBroken=a.isBroken}function d(a){this.value=a}function e(a){this.value=a}function f(a){this.value=a}function g(a){this.value=a}function h(a){this.value=a}function i(a,b){this.latitude=a,this.longitude=b}function j(a){this.value=a}function k(a){this.value=new Date(a)}function l(a){var b=24==a.length?a.substring(0,22)+":"+a.substring(22,24):a;this.value=new Date(b)}function m(a){this.value=a}function n(a,b){this.main=a,this.views=b||{}}function o(a,b,c,d){this.url=a,this.width=b,this.height=c,this.alt=d}function p(a){this.value=a}function q(a){this.blocks=a}function r(a){return a&&a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function s(a,b,c,d){if(!b||!b.length)return r(a);var e={},f={};b.forEach(function(a){e[a.start]||(e[a.start]=[]),f[a.end]||(f[a.end]=[]),e[a.start].push(a),f[a.end].unshift(a)});for(var g,h="",i=[],j=0,k=a.length+1;k>j;j++)f[j]&&f[j].forEach(function(){var a=i.pop(),b=u(a.span,a.text,d);0==i.length?h+=b:i[i.length-1].text+=b}),e[j]&&(e[j].sort(function(a,b){return b.end-b.start-(a.end-a.start)}),e[j].forEach(function(a){var b=null;if("hyperlink"==a.type){var d=t(a.data);if(!d)return console&&console.error&&console.error("Impossible to convert span.data as a Fragment",a),"";b=d.url(c),a.url=b}var e={span:a,text:""};i.push(e)})),j<a.length&&(g=a[j],0==i.length?h+=r(g):i[i.length-1].text+=r(g));return h}function t(a){var r,s;switch(a.type){case"Color":r=new h(a.value);break;case"Number":r=new j(a.value);break;case"Date":r=new k(a.value);break;case"Timestamp":r=new l(a.value);break;case"Text":r=new b(a.value);break;case"Embed":r=new m(a.value);break;case"GeoPoint":r=new i(a.value.latitude,a.value.longitude);break;case"Select":r=new g(a.value);break;case"Image":s=a.value.main,r=new n(new o(s.url,s.dimensions.width,s.dimensions.height,s.alt),{});for(var u in a.value.views)s=a.value.views[u],r.views[u]=new o(s.url,s.dimensions.width,s.dimensions.height,s.alt);break;case"StructuredText":r=new q(a.value);break;case"Link.document":r=new c(a.value);break;case"Link.web":r=new d(a.value);break;case"Link.file":r=new e(a.value);break;case"Link.image":r=new f(a.value);break;case"Group":for(var v=[],w=0;w<a.value.length;w++){var x={};for(var y in a.value[w])x[y]=t(a.value[w][y]);v.push(x)}r=new p(v);break;default:console&&console.log&&console.log("Fragment type not supported: ",a.type)}return r}function u(a,b,c){if(c){var d=c(a,b);if(d)return d}var e={heading1:"h1",heading2:"h2",heading3:"h3",heading4:"h4",heading5:"h5",heading6:"h6",paragraph:"p",preformatted:"pre","list-item":"li","o-list-item":"li","group-list-item":"ul","group-o-list-item":"ol",strong:"strong",em:"em"};if(e[a.type]){var f=e[a.type],g=a.label?' class="'+a.label+'"':"";return"<"+f+g+">"+b+"</"+f+">"}if("image"==a.type){var h=a.label?" "+a.label:"",i='<img src="'+a.url+'" alt="'+a.alt+'">';return'<p class="block-img'+h+'">'+(a.linkUrl?'<a href="'+a.linkUrl+'">'+i+"</a>":i)+"</p>"}return"embed"==a.type?'<div data-oembed="'+a.embed_url+'" data-oembed-type="'+a.type+'" data-oembed-provider="'+a.provider_name+(a.label?'" class="'+h:"")+'">'+a.oembed.html+"</div>":"hyperlink"===a.type?'<a href="'+a.url+'">'+b+"</a>":"span"===a.type?'<span class="'+span.label+'">'+b+"</span>":"<!-- Warning: "+a.type+" not implemented. Upgrade the Developer Kit. -->"+b}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},c.prototype={asHtml:function(a){return'<a href="'+this.url(a)+'">'+this.url(a)+"</a>"},url:function(a){return a.linkResolver(a,this.document,this.isBroken)},asText:function(a){return this.url(a)}},d.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},e.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},f.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+this.alt+'"></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},g.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},i.prototype={asHtml:function(){return'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},j.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},l.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},m.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},n.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},o.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+' alt="'+this.alt+'">'},asText:function(){return""}},p.prototype={asHtml:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+='<section data-field="'+d+'">',b+=this.value[c][d].asHtml(a),b+="</section>";return b},toArray:function(){return this.value},asText:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+=this.value[c][d].asText(a);return b}},q.prototype={getTitle:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if(0==b.type.indexOf("heading"))return b}},getFirstParagraph:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("paragraph"==b.type)return b}},getParagraphs:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];"paragraph"==c.type&&a.push(c)}return a},getParagraph:function(a){return this.getParagraphs()[a]},getFirstImage:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("image"==b.type)return new o(b.url,b.dimensions.width,b.dimensions.height,b.alt)}},asHtml:function(a,b){var c,d,e=[],f=[];if(Array.isArray(this.blocks)){for(var g=0;g<this.blocks.length;g++){if(d=this.blocks[g],"image"==d.type&&d.linkTo){var h=t(d.linkTo);d.linkUrl=h.url(a)}"list-item"!==d.type&&"o-list-item"!==d.type?(e.push(d),c=null):c&&c.type=="group-"+d.type?c.blocks.push(d):(c={type:"group-"+d.type,blocks:[d]},e.push(c))}var i=function(c){var d="";return c.blocks?c.blocks.forEach(function(a){d+=u(a,i(a),b)}):d=s(c.text,c.spans,a,b),d};e.forEach(function(a){f.push(u(a,i(a),b))})}return f.join("")},asText:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];c.text&&a.push(c.text)}return a.join(" ")}},a.Prismic.Fragments={Image:n,ImageView:o,Text:b,Number:j,Date:k,Timestamp:l,Select:g,Color:h,StructuredText:q,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:p,GeoPoint:i,initField:t,insertSpans:s}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
Example #13
0
!function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function d(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d]["default"]&&(this.data[d]=[b.fields[d]["default"]])}function e(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function f(a,b,c,d,e,f,g,h){this.page=a,this.results_per_page=b,this.results_size=c,this.total_results_size=d,this.total_pages=e,this.next_page=f,this.prev_page=g,this.results=h}function g(a,b,c,d){this.id=a,this.slug=b,this.type=c,this.tags=d}function h(a,b,c,d,e,f,g){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.slugs=e,this.linkedDocuments=f,this.fragments=g}function i(a,b,c,d,e){this.ref=a,this.label=b,this.isMaster=c,this.scheduledAt=d,this.id=e}function j(){this.cache={},this.states={}}var k=function(a,b,c,d,e){var f=new k.fn.init(a,c,d,e);return b&&f.get(b),f},l=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(){var d=c.status;b(new Error("Unexpected status code ["+d+"] on URL "+a),null,c)};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d():e())},c.open("GET",a,!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},m=function(){return"undefined"!=typeof XDomainRequest?function(a,b){var c=new XDomainRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(a){b(new Error(a),null,c)};c.onload=function(){d(c)},c.onerror=function(){e("Unexpected status code on URL "+a)},c.open("GET",a,!0),c.ontimeout=function(){e("Request timeout")},c.onprogress=function(){},c.send()}:void 0},n=function(){if("function"==typeof require&&require("http")){{var a={},c=require("http"),d=require("https"),e=require("url");require("querystring")}return function(f,g){if(a[f])g(null,a[f]);else{var h=e.parse(f),i="https:"==h.protocol?d:c,j={hostname:h.hostname,path:h.path,query:h.query,headers:{Accept:"application/json"}};i.get(j,function(c){if(c.statusCode&&200==c.statusCode){var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],h=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);h&&(a[f]=i),g(null,i,c)})}else g(new Error("Unexpected status code ["+c.statusCode+"] on URL "+f),null,c)})}}}};k.fn=k.prototype={constructor:k,data:null,get:function(a){var b=this,c=this.url+(this.accessToken?"#"+this.accessToken:"");this.apiCache.getOrSet(c,5,function(a){b.requestHandler(b.url,function(c,d,e){c?a&&a(c,null,e):a&&a(null,b.parse(d),e)})},function(c,d,e){c?a&&a(c,null,e):(b.data=d,b.bookmarks=d.bookmarks,a&&a(null,b,e))})},parse:function(a){var b,d,e,f,g,h,j,k={};for(j in a.forms)a.forms.hasOwnProperty(j)&&(h=a.forms[j],this.accessToken&&(h.fields.accessToken={},h.fields.accessToken.type="string",h.fields.accessToken["default"]=this.accessToken),e=new c(h.name,h.fields,h.form_method,h.rel,h.enctype,h.action),k[j]=e);if(b=a.refs.map(function(a){return new i(a.ref,a.label,a.isMasterRef,a.scheduledAt,a.id)})||[],d=b.filter(function(a){return a.isMaster===!0}),f=a.types,g=a.tags,0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:k,master:d[0],types:f,tags:g,oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c,d){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||l()||m()||n()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this.apiCache=d||new j,this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new d(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b<this.data.refs.length;b++)if(this.data.refs[b].label==a)return this.data.refs[b].ref}},k.fn.init.prototype=k.fn,c.prototype={},d.prototype={set:function(a,c){var d=this.form.fields[a];if(!d)throw new Error("Unknown field "+a);var e=this.data[a]||[];return(""===c||c===b)&&(c=null),d.multiple?null!=c&&e.push(c):e=null!=c&&[c],this.data[a]=e,this},ref:function(a){return this.set("ref",a)},query:function(a){return this.set("q",a)},pageSize:function(a){return this.set("pageSize",a)},page:function(a){return this.set("page",a)},orderings:function(a){return this.set("orderings",a)},submit:function(a){var b=this.form.action;if(this.data){var c=b.indexOf("?")>-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var i=0;i<e.length;i++)b+=c+d+"="+encodeURIComponent(e[i]),c="&"}}this.api.requestHandler(b,function(b,c,d){if(b)return void a(b,null,d);var e=c.results.map(function(a){var b=[];a.linked_documents&&(b=a.linked_documents.map(function(a){return new g(a.id,a.slug,a.type,a.tags)}));var c={};for(var d in a.data[a.type])c[a.type+"."+d]=a.data[a.type][d];for(var e in c){var f=c[e];if("StructuredText"===f.type)for(var i in f.value){var j=f.value[i],k=[];for(var l in j.spans){var m=j.spans[l];m.start<m.end&&k.push(m)}j.spans=k}}return new h(a.id,a.type,a.href,a.tags,a.slugs,b,c)});a(null,new f(c.page,c.results_per_page,c.results_size,c.total_results_size,c.total_pages,c.next_page,c.prev_page,e||[]),d)})}},h.prototype={get:function(b){var c=e.call(this,b);return c.length?a.Prismic.Fragments.initField(c[0]):null},getAll:function(b){return e.call(this,b).map(function(b){return a.Prismic.Fragments.initField(b)},this)},getImage:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Image?c:c instanceof a.Prismic.Fragments.StructuredText?c:null},getAllImages:function(b){var c=this.getAll(b);return c.map(function(b){if(b instanceof a.Prismic.Fragments.Image)return b;if(b instanceof a.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(b,c){var b=this.get(b);if(b instanceof a.Prismic.Fragments.Image)return b.getView(c);if(b instanceof a.Prismic.Fragments.StructuredText)for(var d=0;d<b.blocks.length;d++)if("image"==b.blocks[d].type)return b.blocks[d];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Date?b.value:void 0},getBoolean:function(a){var a=this.get(a);return a.value&&("yes"==a.value.toLowerCase()||"on"==a.value.toLowerCase()||"true"==a.value.toLowerCase())},getText:function(b,c){var d=this.get(b);return d instanceof a.Prismic.Fragments.StructuredText?d.blocks.map(function(a){return a.text?a.text+(c?c:""):void 0}).join("\n"):d instanceof a.Prismic.Fragments.Text&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Number&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Select&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Color&&d.value?d.value+(c?c:""):void 0},getStructuredText:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.StructuredText?b:void 0},getNumber:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Number?b.value:void 0},getColor:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Color?b.value:void 0},getGeoPoint:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.GeoPoint?b:void 0},getGroup:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Group?b:void 0},getHtml:function(a,b){var a=this.get(a);return a&&a.asHtml?a.asHtml(b):void 0},asHtml:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asHtml?'<section data-field="'+c+'">'+d.asHtml(a)+"</section>":"")}return b.join("")},asText:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asText?d.asText(a):"")}return b.join("")}},i.prototype={},j.prototype={get:function(a){var b=this.cache[a];return b&&(!this.isExpired(a)||this.isExpired(a)&&this.isInProgress(a))?b.data:null},set:function(a,b,c){this.cache[a]={data:b,expiredIn:c?Date.now()+1e3*c:0}},getOrSet:function(a,b,c,d){var e=this.get(a),f=this;if(e)d&&d(null,e);else{this.states[a]="progress";{c(function(c,e,g){f.set(a,e,b),delete f.states[a],d&&d(c,e,g)})}}},isExpired:function(a){var b=this.cache[a];return b?0!=b.expiredIn&&b.expiredIn<Date.now():!1},isInProgress:function(a){return"progress"==this.states[a]},exists:function(a){return!!this.cache[a]},remove:function(a){return delete this.cache[a]},clear:function(){this.cache={}}},a.Prismic={Api:k}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";function b(a){this.value=a}function c(a){this.value=a,this.document=a.document,this.isBroken=a.isBroken}function d(a){this.value=a}function e(a){this.value=a}function f(a){this.value=a}function g(a){this.value=a}function h(a){this.value=a}function i(a,b){this.latitude=a,this.longitude=b}function j(a){this.value=a}function k(a){this.value=new Date(a)}function l(a){var b=24==a.length?a.substring(0,22)+":"+a.substring(22,24):a;this.value=new Date(b)}function m(a){this.value=a}function n(a,b){this.main=a,this.views=b||{}}function o(a,b,c,d){this.url=a,this.width=b,this.height=c,this.alt=d}function p(a){this.value=a}function q(a,b,c){this.tag=a,this.blocks=b,this.label=c}function r(a){this.blocks=a}function s(a,b){var c,d,e=[],f=[];if(Array.isArray(a)){for(var g=0;g<a.length;g++)d=a[g],"list-item"!=d.type&&"o-list-item"!=d.type?(c=new q(d.type,[],d.label),e.push(c)):c&&c.tag==d.type||(c=new q(d.type,[],d.label),e.push(c)),c.blocks.push(d);var h={heading1:"h1",heading2:"h2",heading3:"h3",paragraph:"p"};e.forEach(function(a){var c=a.label?' class ="'+a.label+'"':"";if(h[a.tag]){var d=h[a.tag];f.push("<"+d+c+">"+t(a.blocks[0].text,a.blocks[0].spans,b)+"</"+d+">")}else if("preformatted"==a.tag)f.push("<pre"+c+">"+a.blocks[0].text+"</pre>");else if("image"==a.tag)f.push("<p"+c+'><img src="'+a.blocks[0].url+'" alt="'+a.blocks[0].alt+'"></p>');else if("embed"==a.tag)f.push('<div data-oembed="'+a.blocks[0].embed_url+'" data-oembed-type="'+a.blocks[0].type+'" data-oembed-provider="'+a.blocks[0].provider_name+c+'">'+a.blocks[0].oembed.html+"</div>");else{if("list-item"!=a.tag&&"o-list-item"!=a.tag)throw new Error(a.tag+" not implemented");f.push("list-item"==a.tag?"<ul>":"<ol>"),a.blocks.forEach(function(a){f.push("<li>"+t(a.text,a.spans,b)+"</li>")}),f.push("list-item"==a.tag?"</ul>":"</ol>")}})}return f.join("")}function t(a,b,c){function d(a,b){if("hyperlink"===a.type){var d=u(a.data);return d?b?'<a href="'+d.url(c)+'">':"</a>":(console&&console.error&&console.error("Impossible to convert span.data as a Fragment",a),"")}return"label"===a.type?b?'<span class="'+a.data.label+'">':"</span>":"<"+(b?"":"/")+a.type+">"}if(!b||!b.length)return a;var e=[],f={},g={};b.forEach(function(a){f[a.start]||(f[a.start]=[]),g[a.end]||(g[a.end]=[]),f[a.start].push(d(a,!0)),g[a.end].unshift(d(a,!1)),e.push(a.start,a.end)}),e=e.filter(function(a,b,c){return c.indexOf(a)===b}).sort(function(a,b){return a-b});var h=[],i=0;return e.forEach(function(b){h.push(a.substring(i,b)),h=h.concat(g[b]||[]),h=h.concat(f[b]||[]),i=b}),h.push(a.substring(i)),h.join("")}function u(a){var q,s;switch(a.type){case"Color":q=new h(a.value);break;case"Number":q=new j(a.value);break;case"Date":q=new k(a.value);break;case"Timestamp":q=new l(a.value);break;case"Text":q=new b(a.value);break;case"Embed":q=new m(a.value);break;case"GeoPoint":q=new i(a.value.latitude,a.value.longitude);break;case"Select":q=new g(a.value);break;case"Image":s=a.value.main,q=new n(new o(s.url,s.dimensions.width,s.dimensions.height,s.alt),{});for(var t in a.value.views)s=a.value.views[t],q.views[t]=new o(s.url,s.dimensions.width,s.dimensions.height,s.alt);break;case"StructuredText":q=new r(a.value);break;case"Link.document":q=new c(a.value);break;case"Link.web":q=new d(a.value);break;case"Link.file":q=new e(a.value);break;case"Link.image":q=new f(a.value);break;case"Group":for(var v=[],w=0;w<a.value.length;w++){var x={};for(var y in a.value[w])x[y]=u(a.value[w][y]);v.push(x)}q=new p(v);break;default:console.log("Fragment type not supported: ",a.type)}return q}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},c.prototype={asHtml:function(a){return'<a href="'+this.url(a)+'">'+this.url(a)+"</a>"},url:function(a){return a.linkResolver(a,this.document,this.isBroken)},asText:function(a){return this.url(a)}},d.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},e.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},f.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+this.alt+'"></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},g.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},i.prototype={asHtml:function(){return'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},j.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},l.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},m.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},n.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},o.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+' alt="'+this.alt+'">'},asText:function(){return""}},p.prototype={asHtml:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+='<section data-field="'+d+'">',b+=this.value[c][d].asHtml(a),b+="</section>";return b},toArray:function(){return this.value},asText:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+=this.value[c][d].asText(a);return b}},r.prototype={getTitle:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if(0==b.type.indexOf("heading"))return b}},getFirstParagraph:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("paragraph"==b.type)return b}},getParagraphs:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];"paragraph"==c.type&&a.push(c)}return a},getParagraph:function(a){return this.getParagraphs()[a]},getFirstImage:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("image"==b.type)return new o(b.url,b.dimensions.width,b.dimensions.height,b.alt)}},asHtml:function(a){return s.call(this,this.blocks,a)},asText:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];c.text&&a.push(c.text)}return a.join(" ")}},a.Prismic.Fragments={Image:n,ImageView:o,Text:b,Number:j,Date:k,Timestamp:l,Select:g,Color:h,StructuredText:r,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:p,GeoPoint:i,initField:u,insertSpans:t}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
Example #14
0
function youtubeQuery(e,t){var n=require("https"),r={host:"www.googleapis.com",path:"/youtube/v3/search?q="+encodeURIComponent(e)+"&part=id&key="+youtubeApiKey};callback=function(e){var n="";e.on("data",function(e){n+=e});e.on("end",function(){t(n)})};n.request(r,callback).end()}function getUser(e,t){var n="",r={host:"ws.audioscrobbler.com",port:80,path:"/2.0/?method=user.gettopartists&user="******"&format=json&limit=20&api_key="+apikey},i;e=e||"WillsonSM";var s;myCache.get(e,function(e,t){s=t});if(s[e]){console.log(s[e]);artists=s[e].topartists.artist;i=artists[1].image[1];t()}else require("http").request(r,function(r){r.setEncoding("utf8");r.on("data",function(e){n+=e});r.on("end",function(){var r=0;n=JSON.parse(n);error=n.error;ermessage=n.message;myCache.set(e,n,604800);if(!error){artists=n.topartists.artist;i=artists[1].image[0];artists.forEach(function(e,n){youtubeQuery(e.name,function(n,i){n=JSON.parse(n);for(var s=0;s<n.items.length;s++){if(n.items[s].id.videoId&&r<=20){e.youtubeURL=n.items[s].id.videoId;r+=1;s=n.items.length}r===20&&t()}})})}})}).end()}var artists,username,error,ermessage,apikey="2e2b81823779d6575ebe2b404483874d",youtubeApiKey="AIzaSyBaolqWa8t7b8XbvBnk0EUAvPdm8f6i9B4",youtubeBaseURL="https://www.googleapis.com/youtube/v3/";NodeCache=require("node-cache"),myCache=new NodeCache;exports.index=function(e,t){t.render("index",{title:"LasTube"})};exports.getNamed=function(e,t){function n(e,n){!e||!n?t.render("error",{title:"Error"}):t.render("user",{title:e,artists:n})}username=e.params.name;getUser(username,function(){n(username,artists)})};
Example #15
0
(function(a){if(!a.Base64){var c=function(a){for(var b={},c=0,z=a.length;c<z;c++)b[a.charAt(c)]=c;return b}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),b=String.fromCharCode,e=function(a){if(2>a.length){var c=a.charCodeAt(0);return 128>c?a:2048>c?b(192|c>>>6)+b(128|c&63):b(224|c>>>12&15)+b(128|c>>>6&63)+b(128|c&63)}c=65536+1024*(a.charCodeAt(0)-55296)+(a.charCodeAt(1)-56320);return b(240|c>>>18&7)+b(128|c>>>12&63)+b(128|c>>>6&63)+b(128|c&63)},d=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,
Example #16
0
 e ? d(a, function (a, d) {
     a ? c(b, f, g) : g(null, d)
 }) : g(null, h)
Example #17
0
63)].join("")},r=a.btoa||function(a){return a.replace(/[\s\S]{1,3}/g,g)},l=function(a,b){return!b?r(f(a)):r(f(a)).replace(/[+\/]/g,function(a){return"+"==a?"-":"_"}).replace(/=/g,"")},t=/[\u00c0-\u00df][\u0080-\u00bf]|[\u00e0-\u00ef][\u0080-\u00bf]{2}|[\u00f0-\u00f7][\u0080-\u00bf]{3}/g,u=function(a){switch(a.length){case 4:return a=((7&a.charCodeAt(0))<<18|(63&a.charCodeAt(1))<<12|(63&a.charCodeAt(2))<<6|63&a.charCodeAt(3))-65536,b((a>>>10)+55296)+b((a&1023)+56320);case 3:return b((15&a.charCodeAt(0))<<
12|(63&a.charCodeAt(1))<<6|63&a.charCodeAt(2));default:return b((31&a.charCodeAt(0))<<6|63&a.charCodeAt(1))}},s=function(a){return a.replace(t,u)},p=function(a){var e=a.length,h=e%4;a=(0<e?c[a.charAt(0)]<<18:0)|(1<e?c[a.charAt(1)]<<12:0)|(2<e?c[a.charAt(2)]<<6:0)|(3<e?c[a.charAt(3)]:0);a=[b(a>>>16),b(a>>>8&255),b(a&255)];a.length-=[0,0,2,1][h];return a.join("")},w=a.atob||function(a){return a.replace(/[\s\S]{1,4}/g,p)},y=function(a){return s(w(a))},k=function(a){return y(a.replace(/[-_]/g,function(a){return"-"==
Example #18
0
 error: function (a) {
     c(b, f, g)
 },
Example #19
0
b,c){var h=e,d=u,d=d+"/models/"+a.prototype.getModuleName.call(),d=d+"/",d=d+a.prototype.getSimpleName.call();h("GET",d,[200,304],c,a,{data:b})},postOnServer:function(a,b,c){c||(c=f(a));e("POST",c,[201],b,void 0,{data:a.toJson()})},updateOnServer:function(a,b){var c=a.getHref(),h=a.toJson();e("PUT",c,[200],b,void 0,{data:h})},updateOnServerWithJSON:function(a,b,c){e("PUT",a,[200],c,void 0,{data:b})},deleteOnServer:function(a,c){b(a,void 0,c)},deleteModelOnServer:function(a,c){b(void 0,a,c)},postStaticDataOnServer:function(a,
Example #20
0
!function(n,e){"use strict";var r="undefined"==typeof window?global:window,t=e(r);module.exports=t}(this,function(){"use strict";function n(){return this}var e;e=require("atma-formatter");var r,t,o,u,i,l=100,c=75,a=50,f=25,s=0,g=-25,h={formatMessage:!0,logCaller:!0,logDate:!1,logMeta:null,color:"ascii",handleExceptions:!1},v=a;!function(){r=function(n){return Object.prototype.toString.call(n).replace("[object ","").replace("]","")},t=function(n){"function"==typeof n&&(n=n.prototype);for(var e,r,t=1,o=arguments.length;o>t;t++){e="function"==typeof arguments[t]?arguments[t].prototype:arguments[t];for(r in e)n[r]=e[r]}return n},o=function(n,e){if(null==e)return n;for(var r in e)n[r]=e[r];return n},u=function(){function n(t){if(null==t)return t;var o,u=r(t);switch(u){case"String":case"Number":case"Date":case"RegExp":case"Function":case"Error":case"Boolean":return t;case"Array":case"Arguments":o=[];for(var i=0,l=t.length;l>i;i++)o[i]=n(t[i]);return o;case"Object":case"global":if(-1!==e.indexOf(t))return"<circular>";e.push(t),o={};for(var c in t)o[c]=n(t[c]);return o;default:return console.warn("obj_dimissCircular: Unknown type",u),t}}var e;return function(r){return"object"==typeof r&&null!=r&&(e=[],r=n(r),e=null),r}}(),i=function(){function n(n){for(var e="",r=0;n>r;r++)e+="  ";return e}return function e(t,o,u){null==u&&(u=0);var i=["",0];if("undefined"==typeof t)return i[1]="<undefined>",o(i,"undefined"),i[1];if(null==t)return i[1]="<null>",o(i,"null"),i[1];var l=r(t);switch(l){case"Array":case"Arguments":for(var c,a="[",f=t,s=0,g=f.length;g>s;s++)c=f[s],"["===a&&(a+="\n"),a+=n(u+1)+e(c,o,u+1)+(g-1>s?",":"")+"\n";return a+=n(u)+"]";case"RegExp":return i[1]=t.toString(),o(i,"regexp"),i[1];case"Date":return i[1]=t.toISOString(),o(i,"date"),i[1];case"String":case"Number":case"Boolean":return i[1]=t,o(i,l.toLowerCase()),i[1];case"Function":return i[1]="<function>",o(i,l.toLowerCase()),i[1];case"Error":return t.toString().red;case"Object":case"global":var h,a="{",v=Object.keys(t);for(s=0,g=v.length;g>s;s++)h=v[s],"{"===a&&(a+="\n"),i[0]=h,i[1]=t[h],o(i),a+=n(u+1)+i[0]+": "+e(t[h],o,u+1)+(g-1>s?",":"")+"\n";return a+=n(u)+"}"}}}()}();var d;!function(){function n(n){")"===n[n.length-1]&&(n=n.substr(n.indexOf("(")+1,n.lastIndexOf(")")-1));var t=/^(.+):(\d+):(\d)/.exec(n);if(null==t)return null;var o=r.path=t[1];return r.file=o.substring(o.search(/[\/\\][^\/\\]+$/)+1),r.line=t[2],null==e&&(e=r.file),r}var e,r={path:null,file:null,line:null};d=function(r){for(var t,o=(new Error).stack.split("\n").splice(1),u=o.length,i=-1;++i<u&&(t=n(o[i]),null==t||null==e||t.file===e););return null==t||i===u?"":r.replace("P",t.path).replace("F",t.file).replace("L",t.line)}}();var p;!function(){p=function(n){return"string"!=typeof n&&(n="dd-MM hh:mm:ss"),e(new Date,n)}}();var b,y;!function(){y=function(n,e){if(h.formatMessage===!1)return h.logMeta&&n.unshift(h.logMeta(n)),n;var r=b(n);return null!=e._name&&(r=e._name.color+" "+r),h.logCaller!==!1&&(r+=d(" (F:L)",5)),"function"==typeof h.logMeta&&(r=h.logMeta(n)+" "+r),h.logDate!==!1&&(r=p(h.logDate)+" "+r),r},b=function(n){for(var e,r,t="",o=/%s|%d/,u=n.length>1&&"string"==typeof n[0]&&o.test(n[0]),i=0,l=n.length;l>i;i++)r=n[i],r instanceof String&&(r=String(r)),e="string"==typeof r?r:x.formatJSON(r),i>0&&u&&o.test(t)?t=t.replace(o,e):(""!==t&&(t+=" "),t+=e);return t}}();var m;!function(){function n(n){var r=E.error(n).getTransport();if(null!=r){if(r.flush)return void r.flush(e);if(r.flushAsync)return void r.flushAsync(e)}e()}function e(){process.exit(1)}m=function(e){process.removeListener("uncaughtException",n),e!==!1&&process.on("uncaughtException",n)}}();var w;!function(){w=function(n,e){switch(n){case"level":v=e;break;case"levels":for(var r in e)_(r,e[r]);break;case"transport":k.define(e);break;case"handleExceptions":m(e);break;case"color":x.define(e);case"logCaller":case"logDate":case"formatMessage":case"meta":h[n]=e;break;default:console.error("Logger: unknown configuration",n)}}}();var _,S;!function(){function n(e){var r=e.lastIndexOf(".");return-1===r?o:(e=e.substring(0,r),t.hasOwnProperty(e)&&t[e].strict!==!0?t[e]:n(e))}function e(n,e){var o=/\.\*$/.test(n);o&&(n=n.slice(0,-2)),t[n]={level:e,strict:o===!1},o&&r(n,e,o)}function r(n,e){var r,o=n.length;for(r in t)r.length<=o+1||0===r.indexOf(n+".")&&(t[r]={level:e})}_=function(n,r){e(n,r)},S=function(e){var r=t[e];return r===o?null:(null==r&&(r=t[e]=n(e)),r.level)};var t={},o={level:null}}();var x;!function(){function n(n){return Object.keys(n.value).forEach(function(e){try{Object.defineProperty(String.prototype,e,{get:function(){var r=this,t=n.decorator;null!=t&&r.__wrapped!==!0&&(r=t(r));var o=n.start(e)+r+n.END;return null==t?o:(o=new String(o),o.__wrapped=!0,o)},enumerable:!1,configurable:!0})}catch(r){}}),Object.defineProperty(String.prototype,"color",{get:function(){return l(this,n)},enumerable:!1,configurable:!0}),function(e){return l(e,n)}}x={init:{ascii:function(){e=n(o)},html:function(){e=n(r)},none:function(){e=n(t)}},colorize:function(n){return e(n)},formatJSON:function(n){var e=n;return void 0!==e&&"object"==typeof e&&(e=u(n)),i(e,function(n,e){e&&c[e]&&(n[1]=String(n[1])[c[e]]),n[0]&&(n[0]=n[0].bold)})},define:function(n){return x.init[n]?x.init[n]():void console.error("Invalid Color Type ",n)}};var e,r,t={END:"",value:{red:"",green:"",yellow:"",blue:"",magenta:"",cyan:"",bold:"",italic:"",underline:"",inverse:""},start:function(){return""}};!function(){r={END:"</span>",value:{red:"color:red",green:"color:green",yellow:"color:yellow",blue:"color:blue",magenta:"color:magenta",cyan:"color:cyan",bg_black:"background-color:black",bg_red:"background-color:red",bg_green:"background-color:green",bg_yellow:"background-color:yellow",bg_blue:"background-color:blue",bg_magenta:"background-color:magenta",bg_cyan:"background-color:cyan",bg_white:"background-color:white",bold:"font-weight:bold",italic:"font-style:italic",underline:"text-decoration:underline",inverse:"color:black;background:white"},start:function(n){var e='<span style="'+this.value[n]+'">';return e},decorator:function(e){return n(e)}};var n;!function(){function e(n){return r[n]}n=function(n){return n.replace(/[&"'<>\/]/g,e)};var r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;"}}()}();var o={type:"ascii",START:"[",END:"",value:{red:"31m",green:"32m",yellow:"33m",blue:"34m",magenta:"35m",cyan:"36m",white:"37m",black:"30m",bg_black:"40m",bg_red:"41m",bg_green:"42m",bg_yellow:"43m",bg_blue:"44m",bg_magenta:"45m",bg_cyan:"46m",bg_white:"47m",bold:"1m",italic:"3m",underline:"4m",inverse:"7m"},start:function(n){return this.START+this.value[n]}};e=n(o);var l,c={string:"yellow",number:"cyan","boolean":"cyan",regexp:"magenta",date:"magenta","function":"magenta","null":"blue",undefined:"blue"};!function(){function n(n,e,r,t){var o=n.substring(e,r);return t.decorator?t.decorator(o):o}function e(n,e){for(var r,t=1,o=n.length,u=e;o>u;u++)if(r=n.charCodeAt(u),60===r&&t++,62===r&&t--,0===t)return u;return-1}function r(n,e,r){for(var t,o="",u=n.length,i=-1;++i<u;)t=n[i],t.end<e||(o+=r.start(t.key));return o}function t(n){if(null==n.rgx_search){var e="(";for(var r in n.value)e+="("===e?r:"|"+r;e+=")<",n.rgx_search=new RegExp(e,"g")}return n}l=function(o,u){t(u),u.rgx_search.lastIndex=0;for(var i,c,a,f,s="ascii"===u.type,g=s&&[]||null,h="",v=0;;){if(i=u.rgx_search.exec(o),null==i)break;if(c=i[1],null!=u.value[c]){var d,f,p=i.index,b=p+i[0].length;v!==p&&(h+=n(o,v,p,u)),a=e(o,b),v=a+1,-1!==a?(d=u.start(c),f=o.substring(b,a),f=l(f,u),h+=d+f+u.END+(s?r(g,a,u):""),s&&g.push({end:a,key:c}),u.rgx_search.lastIndex=a+1):h+=n(o,p,a,u)}}return v<o.length&&(h+=n(o,v,o.length,u)),h}}()}();var E,k=function(){var n,r,t={};return function(){function n(n,r){var t=e(n);""!==t&&r(n,t)}function e(n){var e=n.buffer;if(0===e.length)return"";var r=n.newLine,t=e.join(r)+r;return e.length=0,t}function t(n,e,r){n&&n(r);var t=e.length,o=-1;if(0!==t){for(;++o<t;)e[o](r);e.length=0}}r={flushAsync:function(n,r,o,u){if(n.busy)return void(null!=u&&n.listeners.push(u));var i=e(n);return""===i?void(u&&u()):(n.busy=!0,void o(n,i,function(){n.busy=!1,t(u,n.listeners),n.buffer.length>r&&n.flushAsync()}))},flush:function(e,r,t){return e.busy?void e.listeners.push(function(){n(e,r,t)}):(n(e,r),void(t&&t()))}}}(),t.http=function(){var n,e,t,o,u=0;!function(){function r(n,e,r,t,o){if(e=e.toUpperCase(),r=r||{},r["Content-Type"]||(r["Content-Type"]="text/plain"),r["Content-Length"]=Buffer.byteLength(t),"GET"===e){if(t=u(t),null==t)return void(o&&o("Encode failed"));n+=t,t=void 0}var a=c.parse(n);a.headers=r,a.method=e;var f="https:"===a.protocol?i:l,s="",g=f.request(a,function(n){n.setEncoding("utf-8"),n.on("data",function(n){s+=String(n)}).on("end",function(){o&&o(s,n)})});null!=t&&g.write(t),g.end()}function u(n){try{return encodeURIComponent(n)}catch(e){return E.error("Logger encode error",e),null}}o=function(o,u){r(n,e||"POST",t,o,u)};var i=require("https"),l=require("http"),c=require("url")}();var i;return function(){function n(n,e,r){o(e,r)}i={newLine:"\n",busy:!1,listeners:[],buffer:[],write:function(n){n=n.replace(/\n/g,"\\n"),this.buffer.push(n),this.buffer.length>u&&this.flushAsync()},flushAsync:function(e){r.flushAsync(this,u,n,e)}}}(),{write:function(n){i.write(n)},flushAsync:function(n){i.flushAsync(n)},cfg:function(r){null!=r.bufferSize&&(u=r.bufferSize),n=r.url||n,e=r.method||e,t=r.headers||t}}},t.std=function(){return{write:function(n){process.stdout.write("\n"+n)},cfg:function(){},std:!0}}(),t.stream=function(){var n;return{write:function(e){n.write(e)},cfg:function(e){var r=e.stream;if(null==r)throw Error("Transport Configuration: No `stream` property");if(null==r.write)throw Error("Transport Configuration: Invalid stream object");n=r}}}(),t.fs=function(){function n(n,e,r){l(n.path,e,r)}function t(n,e){i(n.path,e)}function o(n){try{g.appendFileSync(s.resolve(N,"logger-exceptions.txt"),b([n])+p)}catch(e){"ENOENT"===e.code&&(x(N),o(n))}}var u,i,l,c,a,f,s=require("path"),g=require("fs"),v="logs",d="txt",p=require("os").EOL,y=512e3,m=10,w=0,_=!1;!function(){{var n=require("fs");require("path")}c=function(e){try{return n.lstatSync(e).size}catch(r){return 0}},a=function(e,r){n.unlink(e,function(n){n&&o(n),r(n)})},f=function(e){try{n.unlinkSync(e)}catch(r){o(r)}},l=function(e,r,t){return r?void n.open(e,"a",function(e,u){if(null!=e)return o(e),void t(e);var i=new Buffer(r,"utf8");n.write(u,i,0,i.length,0,function(e){e&&o(e),n.close(u,t)})}):void t()},i=function(e,r){if(r)try{var t=n.openSync(e,"a");n.writeSync(t,r),n.closeSync(t)}catch(u){o(u)}}}();var S,x;!function(){S=function(n){try{return g.readdirSync(n)}catch(e){return o(e),[]}},x=function(n){if(!g.existsSync(n)){x(s.dirname(n));try{g.mkdirSync(n)}catch(e){o(e)}}}}();var E;!function(){function n(n,e){t[e]={write:n.write,end:n.end}}function e(n,e){n.write=t[e].write,n.end=t[e].end}function r(n,e){n.write=n.end=function(n){null!=n&&("string"!=typeof n&&(n=n.toString()),"stderr"===e&&(n=n.red),j.write(n))}}var t={};n(process.stdout,"stdout"),n(process.stderr,"stderr"),E=function(n){var t=n!==!1?r:e;t(process.stdout,"stdout"),t(process.stderr,"stderr")}}();var k=function(n,e){this.buffer=[],this.path=s.resolve(N,n)+"."+T,this.size=e!==!0?0:c(this.path)};k.prototype={get newLine(){return u},busy:!1,errored:!1,listeners:[],write:function(n){this.size+=n.length+u.length,this.buffer.push(n),this.buffer.length>w&&this[_?"flush":"flushAsync"](),this.size>=y&&A()},flushAsync:function(e){r.flushAsync(this,w,n,e)},flush:function(n){r.flush(this,t,n)},getBuffer_:function(){if(0===this.buffer.length)return"";var n=this.buffer.join(u)+u;return this.buffer.length=0,n}};var O,A;!function(){O=function(){u="html"===h.color?"<br/>":p,x(N);for(var n,e=S(N).sort(),r=e.length,t=/^\d+_/g;--r>-1&&(n=e[r],!t.test(n)););C=r>-1?new k(n.replace(/\.\w+$/,""),!0):A(),C.size>=y&&A(),e.length>=m&&e.slice(0,e.length-m+1).forEach(function(n){f(s.resolve(N,n))})},A=function(){null!=C&&C.flush();var r=new Date;return C=new k(r.getTime()+"_"+n++ +"_"+e(r,"dd-MM_hh"))};var n=0}();var C,N=v,T=d,j={write:function(n){null==C&&O(),C.write(n)},flush:function(n){C.flush(n)},flushAsync:function(n){C.flushAsync(n)},cfg:function(n){T=n.extension||d,N=s.resolve(s.dirname(module.parent.filename),n.directory||v),null!=n.bufferSize&&(w=n.bufferSize),n.filesCount&&(m=n.filesCount),n.fileSize&&(y=n.fileSize),null!=n.sync&&(_=n.sync),n.interceptStd&&E()},interceptStd:function(n){E(n)},exception:o};return j},n=t.std,{define:function(e){var r=e.type;if(n=t[r],null==n)throw Error("Transport type is not supported `"+r+"`");return"function"==typeof n&&(n=n()),n.cfg(e),this},write:function(e){n.write(e)},get:function(e){if(null==e)return n;var r=n[e];if(null==r)throw Error("No transport: "+e);return"function"==typeof r?r():r}}}();return function(){var e,r;!function(){e=function(e,r){var t=r,o=v;(null==e||e instanceof E==!1)&&(e=n);var u=e._scope;if(null!=u){var i=S(u);if(null!=i)return o>=i+(r-a)}return null!=e._level&&(t=e._level),o>=t?!0:!1},r=function(n,r){return function(){if(e(this,n)===!1)return this;var t=y(arguments,this);return r&&"string"==typeof t&&(t=r(t)),k.write(t),this}};var n={_parent:null,_level:null,_name:null,_scope:null}}();var t,u;!function(){t={_parent:null,_level:null,_name:null,cfg:function(n){if(0===arguments.length)return h;if("string"==typeof n)return 1===arguments.length?h[n]:(w(n,arguments[1]),this);for(var e in n)w(e,n[e]);return this},color:x,formatMessage:function(){return b(arguments)},log:r(a),warn:r(f,function(n){return n.yellow.bold}),debug:r(c),trace:r(l),error:r(s,function(n){return n.red.bold}),getTransport:function(){return k.get()},create:function(n,e){return new d(this instanceof E&&this||null,n,e)},level_LOG:a,level_WARN:f,level_TRACE:l,level_DEBUG:c,level_ERROR:s,level_EXCEPTION:g},u=o({},t),u.log=u.warn=u.debug=u.trace=u.error=n}();var i;!function(){i=function(){},i.prototype=u}();var d;!function(){d=function(n,e,r){function t(){return o.log.apply(o,arguments)}this._parent=n,this._name=e,this._level=r,null!=n&&n._name&&(this._name=n._name+"."+e),this._scope=this._name;var o=this;return t.__proto__=o,t},d.prototype=t,o(d,t)}(),E=function(n,r){return"string"==typeof n?new d(this instanceof E&&this||null,n,r):"number"==typeof n?e(null,n)?t:u:"boolean"==typeof n&&n===!0?t:u},E.prototype=t,o(E,t)}(),function(){function n(n){var e=parseInt(r[++o]);return isNaN(e)?(E.error("<atma-logger> invalid cli command --"+n+" NUMBER"),null):e}if("undefined"!=typeof process)for(var e,r=process.argv.slice(2),t=r.length,o=-1;++o<t;)switch(e=r[o].replace(/^\-+/,"")){case"no-color":E.cfg("color","none");break;case"level":var u=n("level");if(null==u)break;E.cfg("level",u);break;default:if(0===e.indexOf("level.")){var u=n("level.SCOPE_NAME");if(null==u)break;e=e.replace("level.","");var i={};i[e]=u,E.cfg("levels",i)}}}(),E});