all.js 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424
  1. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/lib/Promise.coffee ---- */
  2. (function() {
  3. var Promise,
  4. slice = [].slice;
  5. Promise = (function() {
  6. Promise.when = function() {
  7. var args, fn, i, len, num_uncompleted, promise, task, task_id, tasks;
  8. tasks = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  9. num_uncompleted = tasks.length;
  10. args = new Array(num_uncompleted);
  11. promise = new Promise();
  12. fn = function(task_id) {
  13. return task.then(function() {
  14. args[task_id] = Array.prototype.slice.call(arguments);
  15. num_uncompleted--;
  16. if (num_uncompleted === 0) {
  17. return promise.complete.apply(promise, args);
  18. }
  19. });
  20. };
  21. for (task_id = i = 0, len = tasks.length; i < len; task_id = ++i) {
  22. task = tasks[task_id];
  23. fn(task_id);
  24. }
  25. return promise;
  26. };
  27. function Promise() {
  28. this.resolved = false;
  29. this.end_promise = null;
  30. this.result = null;
  31. this.callbacks = [];
  32. }
  33. Promise.prototype.resolve = function() {
  34. var back, callback, i, len, ref;
  35. if (this.resolved) {
  36. return false;
  37. }
  38. this.resolved = true;
  39. this.data = arguments;
  40. if (!arguments.length) {
  41. this.data = [true];
  42. }
  43. this.result = this.data[0];
  44. ref = this.callbacks;
  45. for (i = 0, len = ref.length; i < len; i++) {
  46. callback = ref[i];
  47. back = callback.apply(callback, this.data);
  48. }
  49. if (this.end_promise) {
  50. return this.end_promise.resolve(back);
  51. }
  52. };
  53. Promise.prototype.fail = function() {
  54. return this.resolve(false);
  55. };
  56. Promise.prototype.then = function(callback) {
  57. if (this.resolved === true) {
  58. callback.apply(callback, this.data);
  59. return;
  60. }
  61. this.callbacks.push(callback);
  62. return this.end_promise = new Promise();
  63. };
  64. return Promise;
  65. })();
  66. window.Promise = Promise;
  67. /*
  68. s = Date.now()
  69. log = (text) ->
  70. console.log Date.now()-s, Array.prototype.slice.call(arguments).join(", ")
  71. log "Started"
  72. cmd = (query) ->
  73. p = new Promise()
  74. setTimeout ( ->
  75. p.resolve query+" Result"
  76. ), 100
  77. return p
  78. back = cmd("SELECT * FROM message").then (res) ->
  79. log res
  80. return "Return from query"
  81. .then (res) ->
  82. log "Back then", res
  83. log "Query started", back */
  84. }).call(this);
  85. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/lib/Property.coffee ---- */
  86. (function() {
  87. Function.prototype.property = function(prop, desc) {
  88. return Object.defineProperty(this.prototype, prop, desc);
  89. };
  90. }).call(this);
  91. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/lib/anime.min.js ---- */
  92. /*
  93. * Anime v1.0.0
  94. * http://anime-js.com
  95. * JavaScript animation engine
  96. * Copyright (c) 2016 Julian Garnier
  97. * http://juliangarnier.com
  98. * Released under the MIT license
  99. */
  100. (function(r,n){"function"===typeof define&&define.amd?define([],n):"object"===typeof module&&module.exports?module.exports=n():r.anime=n()})(this,function(){var r={duration:1E3,delay:0,loop:!1,autoplay:!0,direction:"normal",easing:"easeOutElastic",elasticity:400,round:!1,begin:void 0,update:void 0,complete:void 0},n="translateX translateY translateZ rotate rotateX rotateY rotateZ scale scaleX scaleY scaleZ skewX skewY".split(" "),e=function(){return{array:function(a){return Array.isArray(a)},object:function(a){return-1<
  101. Object.prototype.toString.call(a).indexOf("Object")},html:function(a){return a instanceof NodeList||a instanceof HTMLCollection},node:function(a){return a.nodeType},svg:function(a){return a instanceof SVGElement},number:function(a){return!isNaN(parseInt(a))},string:function(a){return"string"===typeof a},func:function(a){return"function"===typeof a},undef:function(a){return"undefined"===typeof a},"null":function(a){return"null"===typeof a},hex:function(a){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a)},
  102. rgb:function(a){return/^rgb/.test(a)},rgba:function(a){return/^rgba/.test(a)},hsl:function(a){return/^hsl/.test(a)},color:function(a){return e.hex(a)||e.rgb(a)||e.rgba(a)||e.hsl(a)}}}(),z=function(){var a={},b={Sine:function(a){return 1-Math.cos(a*Math.PI/2)},Circ:function(a){return 1-Math.sqrt(1-a*a)},Elastic:function(a,b){if(0===a||1===a)return a;var f=1-Math.min(b,998)/1E3,h=a/1-1;return-(Math.pow(2,10*h)*Math.sin(2*(h-f/(2*Math.PI)*Math.asin(1))*Math.PI/f))},Back:function(a){return a*a*(3*a-2)},
  103. Bounce:function(a){for(var b,f=4;a<((b=Math.pow(2,--f))-1)/11;);return 1/Math.pow(4,3-f)-7.5625*Math.pow((3*b-2)/22-a,2)}};["Quad","Cubic","Quart","Quint","Expo"].forEach(function(a,d){b[a]=function(a){return Math.pow(a,d+2)}});Object.keys(b).forEach(function(c){var d=b[c];a["easeIn"+c]=d;a["easeOut"+c]=function(a,b){return 1-d(1-a,b)};a["easeInOut"+c]=function(a,b){return.5>a?d(2*a,b)/2:1-d(-2*a+2,b)/2}});a.linear=function(a){return a};return a}(),u=function(a){return e.string(a)?a:a+""},A=function(a){return a.replace(/([a-z])([A-Z])/g,
  104. "$1-$2").toLowerCase()},B=function(a){if(e.color(a))return!1;try{return document.querySelectorAll(a)}catch(b){return!1}},v=function(a){return a.reduce(function(a,c){return a.concat(e.array(c)?v(c):c)},[])},p=function(a){if(e.array(a))return a;e.string(a)&&(a=B(a)||a);return e.html(a)?[].slice.call(a):[a]},C=function(a,b){return a.some(function(a){return a===b})},N=function(a,b){var c={};a.forEach(function(a){var f=JSON.stringify(b.map(function(b){return a[b]}));c[f]=c[f]||[];c[f].push(a)});return Object.keys(c).map(function(a){return c[a]})},
  105. D=function(a){return a.filter(function(a,c,d){return d.indexOf(a)===c})},w=function(a){var b={},c;for(c in a)b[c]=a[c];return b},t=function(a,b){for(var c in b)a[c]=e.undef(a[c])?b[c]:a[c];return a},O=function(a){a=a.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(a,b,c,e){return b+b+c+c+e+e});var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);a=parseInt(b[1],16);var c=parseInt(b[2],16),b=parseInt(b[3],16);return"rgb("+a+","+c+","+b+")"},P=function(a){a=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(a);
  106. var b=parseInt(a[1])/360,c=parseInt(a[2])/100,d=parseInt(a[3])/100;a=function(a,b,c){0>c&&(c+=1);1<c&&--c;return c<1/6?a+6*(b-a)*c:.5>c?b:c<2/3?a+(b-a)*(2/3-c)*6:a};if(0==c)c=d=b=d;else var f=.5>d?d*(1+c):d+c-d*c,h=2*d-f,c=a(h,f,b+1/3),d=a(h,f,b),b=a(h,f,b-1/3);return"rgb("+255*c+","+255*d+","+255*b+")"},k=function(a){return/([\+\-]?[0-9|auto\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg)?/.exec(a)[2]},E=function(a,b,c){return k(b)?b:-1<a.indexOf("translate")?k(c)?b+k(c):b+"px":-1<a.indexOf("rotate")||
  107. -1<a.indexOf("skew")?b+"deg":b},F=function(a,b){if((e.node(a)||e.svg(a))&&C(n,b))return"transform";if((e.node(a)||e.svg(a))&&"transform"!==b&&x(a,b))return"css";if((e.node(a)||e.svg(a))&&(a.getAttribute(b)||e.svg(a)&&a[b]))return"attribute";if(!e["null"](a[b])&&!e.undef(a[b]))return"object"},x=function(a,b){if(b in a.style)return getComputedStyle(a).getPropertyValue(A(b))||"0"},Q=function(a,b){var c=-1<b.indexOf("scale")?1:0,d=a.style.transform;if(!d)return c;for(var f=/(\w+)\((.+?)\)/g,h=[],e=[],
  108. q=[];h=f.exec(d);)e.push(h[1]),q.push(h[2]);d=q.filter(function(a,c){return e[c]===b});return d.length?d[0]:c},G=function(a,b){switch(F(a,b)){case "transform":return Q(a,b);case "css":return x(a,b);case "attribute":return a.getAttribute(b)}return a[b]||0},H=function(a,b,c){if(e.color(b))return b=e.rgb(b)||e.rgba(b)?b:e.hex(b)?O(b):e.hsl(b)?P(b):void 0,b;if(k(b))return b;a=k(a.to)?k(a.to):k(a.from);!a&&c&&(a=k(c));return a?b+a:b},I=function(a){var b=/-?\d*\.?\d+/g;return{original:a,numbers:u(a).match(b)?
  109. u(a).match(b).map(Number):[0],strings:u(a).split(b)}},R=function(a,b,c){return b.reduce(function(b,f,e){f=f?f:c[e-1];return b+a[e-1]+f})},S=function(a){a=a?v(e.array(a)?a.map(p):p(a)):[];return a.map(function(a,c){return{target:a,id:c}})},T=function(a,b){var c=[],d;for(d in a)if(!r.hasOwnProperty(d)&&"targets"!==d){var f=e.object(a[d])?w(a[d]):{value:a[d]};f.name=d;c.push(t(f,b))}return c},J=function(a,b,c,d){"transform"===c?(c=a+"("+E(a,b.from,b.to)+")",b=a+"("+E(a,b.to)+")"):(a="css"===c?x(d,a):
  110. void 0,c=H(b,b.from,a),b=H(b,b.to,a));return{from:I(c),to:I(b)}},U=function(a,b){var c=[];a.forEach(function(d,f){var h=d.target;return b.forEach(function(b){var q=F(h,b.name);if(q){var k;k=b.name;var g=b.value,g=p(e.func(g)?g(h,f):g);k={from:1<g.length?g[0]:G(h,k),to:1<g.length?g[1]:g[0]};g=w(b);g.animatables=d;g.type=q;g.from=J(b.name,k,g.type,h).from;g.to=J(b.name,k,g.type,h).to;g.round=e.color(k.from)||g.round?1:0;g.delay=(e.func(g.delay)?g.delay(h,f,a.length):g.delay)/l.speed;g.duration=(e.func(g.duration)?
  111. g.duration(h,f,a.length):g.duration)/l.speed;c.push(g)}})});return c},V=function(a,b){var c=U(a,b);return N(c,["name","from","to","delay","duration"]).map(function(a){var b=w(a[0]);b.animatables=a.map(function(a){return a.animatables});b.totalDuration=b.delay+b.duration;return b})},y=function(a,b){a.tweens.forEach(function(c){var d=c.from,f=a.duration-(c.delay+c.duration);c.from=c.to;c.to=d;b&&(c.delay=f)});a.reversed=a.reversed?!1:!0},K=function(a){var b=[],c=[];a.tweens.forEach(function(a){if("css"===
  112. a.type||"transform"===a.type)b.push("css"===a.type?A(a.name):"transform"),a.animatables.forEach(function(a){c.push(a.target)})});return{properties:D(b).join(", "),elements:D(c)}},W=function(a){var b=K(a);b.elements.forEach(function(a){a.style.willChange=b.properties})},X=function(a){K(a).elements.forEach(function(a){a.style.removeProperty("will-change")})},Y=function(a,b){var c=a.path,d=a.value*b,f=function(f){f=f||0;return c.getPointAtLength(1<b?a.value+f:d+f)},e=f(),k=f(-1),f=f(1);switch(a.name){case "translateX":return e.x;
  113. case "translateY":return e.y;case "rotate":return 180*Math.atan2(f.y-k.y,f.x-k.x)/Math.PI}},Z=function(a,b){var c=Math.min(Math.max(b-a.delay,0),a.duration)/a.duration,d=a.to.numbers.map(function(b,d){var e=a.from.numbers[d],k=z[a.easing](c,a.elasticity),e=a.path?Y(a,k):e+k*(b-e);return e=a.round?Math.round(e*a.round)/a.round:e});return R(d,a.to.strings,a.from.strings)},L=function(a,b){var c=void 0;a.time=Math.min(b,a.duration);a.progress=a.time/a.duration*100;a.tweens.forEach(function(a){a.currentValue=
  114. Z(a,b);var d=a.currentValue;a.animatables.forEach(function(b){var e=b.id;switch(a.type){case "css":b.target.style[a.name]=d;break;case "attribute":b.target.setAttribute(a.name,d);break;case "object":b.target[a.name]=d;break;case "transform":c||(c={}),c[e]||(c[e]=[]),c[e].push(d)}})});if(c)for(var d in c)a.animatables[d].target.style.transform=c[d].join(" ");a.settings.update&&a.settings.update(a)},M=function(a){var b={};b.animatables=S(a.targets);b.settings=t(a,r);b.properties=T(a,b.settings);b.tweens=
  115. V(b.animatables,b.properties);b.duration=b.tweens.length?Math.max.apply(Math,b.tweens.map(function(a){return a.totalDuration})):a.duration/l.speed;b.time=0;b.progress=0;b.running=!1;b.ended=!1;return b},m=[],l=function(a){var b=M(a),c={tick:function(){if(b.running){b.ended=!1;c.now=+new Date;c.current=c.last+c.now-c.start;L(b,c.current);var a=b.settings;a.begin&&c.current>=a.delay&&(a.begin(b),a.begin=void 0);c.current>=b.duration?(a.loop?(c.start=+new Date,"alternate"===a.direction&&y(b,!0),e.number(a.loop)&&
  116. a.loop--,c.raf=requestAnimationFrame(c.tick)):(b.ended=!0,a.complete&&a.complete(b),b.pause()),c.last=0):c.raf=requestAnimationFrame(c.tick)}}};b.seek=function(a){L(b,a/100*b.duration)};b.pause=function(){b.running=!1;cancelAnimationFrame(c.raf);X(b);var a=m.indexOf(b);-1<a&&m.splice(a,1)};b.play=function(a){a&&(b=t(M(t(a,b.settings)),b));b.pause();b.running=!0;c.start=+new Date;c.last=b.ended?0:b.time;a=b.settings;"reverse"===a.direction&&y(b);"alternate"!==a.direction||a.loop||(a.loop=1);W(b);m.push(b);
  117. c.raf=requestAnimationFrame(c.tick)};b.restart=function(){b.reversed&&y(b);b.pause();b.seek(0);b.play()};b.settings.autoplay&&b.play();return b};l.speed=1;l.list=m;l.remove=function(a){a=v(e.array(a)?a.map(p):p(a));for(var b=m.length-1;0<=b;b--)for(var c=m[b],d=c.tweens.length-1;0<=d;d--)for(var f=c.tweens[d],h=f.animatables.length-1;0<=h;h--)C(a,f.animatables[h].target)&&(f.animatables.splice(h,1),f.animatables.length||c.tweens.splice(d,1),c.tweens.length||c.pause())};l.easings=z;l.getValue=G;l.path=
  118. function(a){a=e.string(a)?B(a)[0]:a;return{path:a,value:a.getTotalLength()}};l.random=function(a,b){return Math.floor(Math.random()*(b-a+1))+a};return l});
  119. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/lib/maquette.js ---- */
  120. (function (root, factory) {
  121. if (typeof define === 'function' && define.amd) {
  122. // AMD. Register as an anonymous module.
  123. define(['exports'], factory);
  124. } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
  125. // CommonJS
  126. factory(exports);
  127. } else {
  128. // Browser globals
  129. factory(root.maquette = {});
  130. }
  131. }(this, function (exports) {
  132. 'use strict';
  133. ;
  134. ;
  135. ;
  136. ;
  137. var NAMESPACE_W3 = 'http://www.w3.org/';
  138. var NAMESPACE_SVG = NAMESPACE_W3 + '2000/svg';
  139. var NAMESPACE_XLINK = NAMESPACE_W3 + '1999/xlink';
  140. // Utilities
  141. var emptyArray = [];
  142. var extend = function (base, overrides) {
  143. var result = {};
  144. Object.keys(base).forEach(function (key) {
  145. result[key] = base[key];
  146. });
  147. if (overrides) {
  148. Object.keys(overrides).forEach(function (key) {
  149. result[key] = overrides[key];
  150. });
  151. }
  152. return result;
  153. };
  154. // Hyperscript helper functions
  155. var same = function (vnode1, vnode2) {
  156. if (vnode1.vnodeSelector !== vnode2.vnodeSelector) {
  157. return false;
  158. }
  159. if (vnode1.properties && vnode2.properties) {
  160. if (vnode1.properties.key !== vnode2.properties.key) {
  161. return false;
  162. }
  163. return vnode1.properties.bind === vnode2.properties.bind;
  164. }
  165. return !vnode1.properties && !vnode2.properties;
  166. };
  167. var toTextVNode = function (data) {
  168. return {
  169. vnodeSelector: '',
  170. properties: undefined,
  171. children: undefined,
  172. text: data.toString(),
  173. domNode: null
  174. };
  175. };
  176. var appendChildren = function (parentSelector, insertions, main) {
  177. for (var i = 0; i < insertions.length; i++) {
  178. var item = insertions[i];
  179. if (Array.isArray(item)) {
  180. appendChildren(parentSelector, item, main);
  181. } else {
  182. if (item !== null && item !== undefined) {
  183. if (!item.hasOwnProperty('vnodeSelector')) {
  184. item = toTextVNode(item);
  185. }
  186. main.push(item);
  187. }
  188. }
  189. }
  190. };
  191. // Render helper functions
  192. var missingTransition = function () {
  193. throw new Error('Provide a transitions object to the projectionOptions to do animations');
  194. };
  195. var DEFAULT_PROJECTION_OPTIONS = {
  196. namespace: undefined,
  197. eventHandlerInterceptor: undefined,
  198. styleApplyer: function (domNode, styleName, value) {
  199. // Provides a hook to add vendor prefixes for browsers that still need it.
  200. domNode.style[styleName] = value;
  201. },
  202. transitions: {
  203. enter: missingTransition,
  204. exit: missingTransition
  205. }
  206. };
  207. var applyDefaultProjectionOptions = function (projectorOptions) {
  208. return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
  209. };
  210. var checkStyleValue = function (styleValue) {
  211. if (typeof styleValue !== 'string') {
  212. throw new Error('Style values must be strings');
  213. }
  214. };
  215. var setProperties = function (domNode, properties, projectionOptions) {
  216. if (!properties) {
  217. return;
  218. }
  219. var eventHandlerInterceptor = projectionOptions.eventHandlerInterceptor;
  220. var propNames = Object.keys(properties);
  221. var propCount = propNames.length;
  222. for (var i = 0; i < propCount; i++) {
  223. var propName = propNames[i];
  224. /* tslint:disable:no-var-keyword: edge case */
  225. var propValue = properties[propName];
  226. /* tslint:enable:no-var-keyword */
  227. if (propName === 'className') {
  228. throw new Error('Property "className" is not supported, use "class".');
  229. } else if (propName === 'class') {
  230. if (domNode.className) {
  231. // May happen if classes is specified before class
  232. domNode.className += ' ' + propValue;
  233. } else {
  234. domNode.className = propValue;
  235. }
  236. } else if (propName === 'classes') {
  237. // object with string keys and boolean values
  238. var classNames = Object.keys(propValue);
  239. var classNameCount = classNames.length;
  240. for (var j = 0; j < classNameCount; j++) {
  241. var className = classNames[j];
  242. if (propValue[className]) {
  243. domNode.classList.add(className);
  244. }
  245. }
  246. } else if (propName === 'styles') {
  247. // object with string keys and string (!) values
  248. var styleNames = Object.keys(propValue);
  249. var styleCount = styleNames.length;
  250. for (var j = 0; j < styleCount; j++) {
  251. var styleName = styleNames[j];
  252. var styleValue = propValue[styleName];
  253. if (styleValue) {
  254. checkStyleValue(styleValue);
  255. projectionOptions.styleApplyer(domNode, styleName, styleValue);
  256. }
  257. }
  258. } else if (propName === 'key') {
  259. continue;
  260. } else if (propValue === null || propValue === undefined) {
  261. continue;
  262. } else {
  263. var type = typeof propValue;
  264. if (type === 'function') {
  265. if (propName.lastIndexOf('on', 0) === 0) {
  266. if (eventHandlerInterceptor) {
  267. propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
  268. }
  269. if (propName === 'oninput') {
  270. (function () {
  271. // record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
  272. var oldPropValue = propValue;
  273. propValue = function (evt) {
  274. evt.target['oninput-value'] = evt.target.value;
  275. // may be HTMLTextAreaElement as well
  276. oldPropValue.apply(this, [evt]);
  277. };
  278. }());
  279. }
  280. domNode[propName] = propValue;
  281. }
  282. } else if (type === 'string' && propName !== 'value' && propName !== 'innerHTML') {
  283. if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
  284. domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
  285. } else {
  286. domNode.setAttribute(propName, propValue);
  287. }
  288. } else {
  289. domNode[propName] = propValue;
  290. }
  291. }
  292. }
  293. };
  294. var updateProperties = function (domNode, previousProperties, properties, projectionOptions) {
  295. if (!properties) {
  296. return;
  297. }
  298. var propertiesUpdated = false;
  299. var propNames = Object.keys(properties);
  300. var propCount = propNames.length;
  301. for (var i = 0; i < propCount; i++) {
  302. var propName = propNames[i];
  303. // assuming that properties will be nullified instead of missing is by design
  304. var propValue = properties[propName];
  305. var previousValue = previousProperties[propName];
  306. if (propName === 'class') {
  307. if (previousValue !== propValue) {
  308. throw new Error('"class" property may not be updated. Use the "classes" property for conditional css classes.');
  309. }
  310. } else if (propName === 'classes') {
  311. var classList = domNode.classList;
  312. var classNames = Object.keys(propValue);
  313. var classNameCount = classNames.length;
  314. for (var j = 0; j < classNameCount; j++) {
  315. var className = classNames[j];
  316. var on = !!propValue[className];
  317. var previousOn = !!previousValue[className];
  318. if (on === previousOn) {
  319. continue;
  320. }
  321. propertiesUpdated = true;
  322. if (on) {
  323. classList.add(className);
  324. } else {
  325. classList.remove(className);
  326. }
  327. }
  328. } else if (propName === 'styles') {
  329. var styleNames = Object.keys(propValue);
  330. var styleCount = styleNames.length;
  331. for (var j = 0; j < styleCount; j++) {
  332. var styleName = styleNames[j];
  333. var newStyleValue = propValue[styleName];
  334. var oldStyleValue = previousValue[styleName];
  335. if (newStyleValue === oldStyleValue) {
  336. continue;
  337. }
  338. propertiesUpdated = true;
  339. if (newStyleValue) {
  340. checkStyleValue(newStyleValue);
  341. projectionOptions.styleApplyer(domNode, styleName, newStyleValue);
  342. } else {
  343. projectionOptions.styleApplyer(domNode, styleName, '');
  344. }
  345. }
  346. } else {
  347. if (!propValue && typeof previousValue === 'string') {
  348. propValue = '';
  349. }
  350. if (propName === 'value') {
  351. if (domNode[propName] !== propValue && domNode['oninput-value'] !== propValue) {
  352. domNode[propName] = propValue;
  353. // Reset the value, even if the virtual DOM did not change
  354. domNode['oninput-value'] = undefined;
  355. }
  356. // else do not update the domNode, otherwise the cursor position would be changed
  357. if (propValue !== previousValue) {
  358. propertiesUpdated = true;
  359. }
  360. } else if (propValue !== previousValue) {
  361. var type = typeof propValue;
  362. if (type === 'function') {
  363. throw new Error('Functions may not be updated on subsequent renders (property: ' + propName + '). Hint: declare event handler functions outside the render() function.');
  364. }
  365. if (type === 'string' && propName !== 'innerHTML') {
  366. if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
  367. domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
  368. } else {
  369. domNode.setAttribute(propName, propValue);
  370. }
  371. } else {
  372. if (domNode[propName] !== propValue) {
  373. domNode[propName] = propValue;
  374. }
  375. }
  376. propertiesUpdated = true;
  377. }
  378. }
  379. }
  380. return propertiesUpdated;
  381. };
  382. var findIndexOfChild = function (children, sameAs, start) {
  383. if (sameAs.vnodeSelector !== '') {
  384. // Never scan for text-nodes
  385. for (var i = start; i < children.length; i++) {
  386. if (same(children[i], sameAs)) {
  387. return i;
  388. }
  389. }
  390. }
  391. return -1;
  392. };
  393. var nodeAdded = function (vNode, transitions) {
  394. if (vNode.properties) {
  395. var enterAnimation = vNode.properties.enterAnimation;
  396. if (enterAnimation) {
  397. if (typeof enterAnimation === 'function') {
  398. enterAnimation(vNode.domNode, vNode.properties);
  399. } else {
  400. transitions.enter(vNode.domNode, vNode.properties, enterAnimation);
  401. }
  402. }
  403. }
  404. };
  405. var nodeToRemove = function (vNode, transitions) {
  406. var domNode = vNode.domNode;
  407. if (vNode.properties) {
  408. var exitAnimation = vNode.properties.exitAnimation;
  409. if (exitAnimation) {
  410. domNode.style.pointerEvents = 'none';
  411. var removeDomNode = function () {
  412. if (domNode.parentNode) {
  413. domNode.parentNode.removeChild(domNode);
  414. }
  415. };
  416. if (typeof exitAnimation === 'function') {
  417. exitAnimation(domNode, removeDomNode, vNode.properties);
  418. return;
  419. } else {
  420. transitions.exit(vNode.domNode, vNode.properties, exitAnimation, removeDomNode);
  421. return;
  422. }
  423. }
  424. }
  425. if (domNode.parentNode) {
  426. domNode.parentNode.removeChild(domNode);
  427. }
  428. };
  429. var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, operation) {
  430. var childNode = childNodes[indexToCheck];
  431. if (childNode.vnodeSelector === '') {
  432. return; // Text nodes need not be distinguishable
  433. }
  434. var properties = childNode.properties;
  435. var key = properties ? properties.key === undefined ? properties.bind : properties.key : undefined;
  436. if (!key) {
  437. for (var i = 0; i < childNodes.length; i++) {
  438. if (i !== indexToCheck) {
  439. var node = childNodes[i];
  440. if (same(node, childNode)) {
  441. if (operation === 'added') {
  442. throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' + 'added, but there is now more than one. You must add unique key properties to make them distinguishable.');
  443. } else {
  444. throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' + 'removed, but there were more than one. You must add unique key properties to make them distinguishable.');
  445. }
  446. }
  447. }
  448. }
  449. }
  450. };
  451. var createDom;
  452. var updateDom;
  453. var updateChildren = function (vnode, domNode, oldChildren, newChildren, projectionOptions) {
  454. if (oldChildren === newChildren) {
  455. return false;
  456. }
  457. oldChildren = oldChildren || emptyArray;
  458. newChildren = newChildren || emptyArray;
  459. var oldChildrenLength = oldChildren.length;
  460. var newChildrenLength = newChildren.length;
  461. var transitions = projectionOptions.transitions;
  462. var oldIndex = 0;
  463. var newIndex = 0;
  464. var i;
  465. var textUpdated = false;
  466. while (newIndex < newChildrenLength) {
  467. var oldChild = oldIndex < oldChildrenLength ? oldChildren[oldIndex] : undefined;
  468. var newChild = newChildren[newIndex];
  469. if (oldChild !== undefined && same(oldChild, newChild)) {
  470. textUpdated = updateDom(oldChild, newChild, projectionOptions) || textUpdated;
  471. oldIndex++;
  472. } else {
  473. var findOldIndex = findIndexOfChild(oldChildren, newChild, oldIndex + 1);
  474. if (findOldIndex >= 0) {
  475. // Remove preceding missing children
  476. for (i = oldIndex; i < findOldIndex; i++) {
  477. nodeToRemove(oldChildren[i], transitions);
  478. checkDistinguishable(oldChildren, i, vnode, 'removed');
  479. }
  480. textUpdated = updateDom(oldChildren[findOldIndex], newChild, projectionOptions) || textUpdated;
  481. oldIndex = findOldIndex + 1;
  482. } else {
  483. // New child
  484. createDom(newChild, domNode, oldIndex < oldChildrenLength ? oldChildren[oldIndex].domNode : undefined, projectionOptions);
  485. nodeAdded(newChild, transitions);
  486. checkDistinguishable(newChildren, newIndex, vnode, 'added');
  487. }
  488. }
  489. newIndex++;
  490. }
  491. if (oldChildrenLength > oldIndex) {
  492. // Remove child fragments
  493. for (i = oldIndex; i < oldChildrenLength; i++) {
  494. nodeToRemove(oldChildren[i], transitions);
  495. checkDistinguishable(oldChildren, i, vnode, 'removed');
  496. }
  497. }
  498. return textUpdated;
  499. };
  500. var addChildren = function (domNode, children, projectionOptions) {
  501. if (!children) {
  502. return;
  503. }
  504. for (var i = 0; i < children.length; i++) {
  505. createDom(children[i], domNode, undefined, projectionOptions);
  506. }
  507. };
  508. var initPropertiesAndChildren = function (domNode, vnode, projectionOptions) {
  509. addChildren(domNode, vnode.children, projectionOptions);
  510. // children before properties, needed for value property of <select>.
  511. if (vnode.text) {
  512. domNode.textContent = vnode.text;
  513. }
  514. setProperties(domNode, vnode.properties, projectionOptions);
  515. if (vnode.properties && vnode.properties.afterCreate) {
  516. vnode.properties.afterCreate(domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children);
  517. }
  518. };
  519. createDom = function (vnode, parentNode, insertBefore, projectionOptions) {
  520. var domNode, i, c, start = 0, type, found;
  521. var vnodeSelector = vnode.vnodeSelector;
  522. if (vnodeSelector === '') {
  523. domNode = vnode.domNode = document.createTextNode(vnode.text);
  524. if (insertBefore !== undefined) {
  525. parentNode.insertBefore(domNode, insertBefore);
  526. } else {
  527. parentNode.appendChild(domNode);
  528. }
  529. } else {
  530. for (i = 0; i <= vnodeSelector.length; ++i) {
  531. c = vnodeSelector.charAt(i);
  532. if (i === vnodeSelector.length || c === '.' || c === '#') {
  533. type = vnodeSelector.charAt(start - 1);
  534. found = vnodeSelector.slice(start, i);
  535. if (type === '.') {
  536. domNode.classList.add(found);
  537. } else if (type === '#') {
  538. domNode.id = found;
  539. } else {
  540. if (found === 'svg') {
  541. projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
  542. }
  543. if (projectionOptions.namespace !== undefined) {
  544. domNode = vnode.domNode = document.createElementNS(projectionOptions.namespace, found);
  545. } else {
  546. domNode = vnode.domNode = document.createElement(found);
  547. }
  548. if (insertBefore !== undefined) {
  549. parentNode.insertBefore(domNode, insertBefore);
  550. } else {
  551. parentNode.appendChild(domNode);
  552. }
  553. }
  554. start = i + 1;
  555. }
  556. }
  557. initPropertiesAndChildren(domNode, vnode, projectionOptions);
  558. }
  559. };
  560. updateDom = function (previous, vnode, projectionOptions) {
  561. var domNode = previous.domNode;
  562. var textUpdated = false;
  563. if (previous === vnode) {
  564. return false; // By contract, VNode objects may not be modified anymore after passing them to maquette
  565. }
  566. var updated = false;
  567. if (vnode.vnodeSelector === '') {
  568. if (vnode.text !== previous.text) {
  569. var newVNode = document.createTextNode(vnode.text);
  570. domNode.parentNode.replaceChild(newVNode, domNode);
  571. vnode.domNode = newVNode;
  572. textUpdated = true;
  573. return textUpdated;
  574. }
  575. } else {
  576. if (vnode.vnodeSelector.lastIndexOf('svg', 0) === 0) {
  577. projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
  578. }
  579. if (previous.text !== vnode.text) {
  580. updated = true;
  581. if (vnode.text === undefined) {
  582. domNode.removeChild(domNode.firstChild); // the only textnode presumably
  583. } else {
  584. domNode.textContent = vnode.text;
  585. }
  586. }
  587. updated = updateChildren(vnode, domNode, previous.children, vnode.children, projectionOptions) || updated;
  588. updated = updateProperties(domNode, previous.properties, vnode.properties, projectionOptions) || updated;
  589. if (vnode.properties && vnode.properties.afterUpdate) {
  590. vnode.properties.afterUpdate(domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children);
  591. }
  592. }
  593. if (updated && vnode.properties && vnode.properties.updateAnimation) {
  594. vnode.properties.updateAnimation(domNode, vnode.properties, previous.properties);
  595. }
  596. vnode.domNode = previous.domNode;
  597. return textUpdated;
  598. };
  599. var createProjection = function (vnode, projectionOptions) {
  600. return {
  601. update: function (updatedVnode) {
  602. if (vnode.vnodeSelector !== updatedVnode.vnodeSelector) {
  603. throw new Error('The selector for the root VNode may not be changed. (consider using dom.merge and add one extra level to the virtual DOM)');
  604. }
  605. updateDom(vnode, updatedVnode, projectionOptions);
  606. vnode = updatedVnode;
  607. },
  608. domNode: vnode.domNode
  609. };
  610. };
  611. ;
  612. // The other two parameters are not added here, because the Typescript compiler creates surrogate code for desctructuring 'children'.
  613. exports.h = function (selector) {
  614. var properties = arguments[1];
  615. if (typeof selector !== 'string') {
  616. throw new Error();
  617. }
  618. var childIndex = 1;
  619. if (properties && !properties.hasOwnProperty('vnodeSelector') && !Array.isArray(properties) && typeof properties === 'object') {
  620. childIndex = 2;
  621. } else {
  622. // Optional properties argument was omitted
  623. properties = undefined;
  624. }
  625. var text = undefined;
  626. var children = undefined;
  627. var argsLength = arguments.length;
  628. // Recognize a common special case where there is only a single text node
  629. if (argsLength === childIndex + 1) {
  630. var onlyChild = arguments[childIndex];
  631. if (typeof onlyChild === 'string') {
  632. text = onlyChild;
  633. } else if (onlyChild !== undefined && onlyChild !== null && onlyChild.length === 1 && typeof onlyChild[0] === 'string') {
  634. text = onlyChild[0];
  635. }
  636. }
  637. if (text === undefined) {
  638. children = [];
  639. for (; childIndex < arguments.length; childIndex++) {
  640. var child = arguments[childIndex];
  641. if (child === null || child === undefined) {
  642. continue;
  643. } else if (Array.isArray(child)) {
  644. appendChildren(selector, child, children);
  645. } else if (child.hasOwnProperty('vnodeSelector')) {
  646. children.push(child);
  647. } else {
  648. children.push(toTextVNode(child));
  649. }
  650. }
  651. }
  652. return {
  653. vnodeSelector: selector,
  654. properties: properties,
  655. children: children,
  656. text: text === '' ? undefined : text,
  657. domNode: null
  658. };
  659. };
  660. /**
  661. * Contains simple low-level utility functions to manipulate the real DOM.
  662. */
  663. exports.dom = {
  664. /**
  665. * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
  666. * its [[Projection.domNode|domNode]] property.
  667. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  668. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
  669. * objects may only be rendered once.
  670. * @param projectionOptions - Options to be used to create and update the projection.
  671. * @returns The [[Projection]] which also contains the DOM Node that was created.
  672. */
  673. create: function (vnode, projectionOptions) {
  674. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  675. createDom(vnode, document.createElement('div'), undefined, projectionOptions);
  676. return createProjection(vnode, projectionOptions);
  677. },
  678. /**
  679. * Appends a new childnode to the DOM which is generated from a [[VNode]].
  680. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  681. * @param parentNode - The parent node for the new childNode.
  682. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
  683. * objects may only be rendered once.
  684. * @param projectionOptions - Options to be used to create and update the [[Projection]].
  685. * @returns The [[Projection]] that was created.
  686. */
  687. append: function (parentNode, vnode, projectionOptions) {
  688. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  689. createDom(vnode, parentNode, undefined, projectionOptions);
  690. return createProjection(vnode, projectionOptions);
  691. },
  692. /**
  693. * Inserts a new DOM node which is generated from a [[VNode]].
  694. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  695. * @param beforeNode - The node that the DOM Node is inserted before.
  696. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
  697. * NOTE: [[VNode]] objects may only be rendered once.
  698. * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
  699. * @returns The [[Projection]] that was created.
  700. */
  701. insertBefore: function (beforeNode, vnode, projectionOptions) {
  702. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  703. createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
  704. return createProjection(vnode, projectionOptions);
  705. },
  706. /**
  707. * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
  708. * This means that the virtual DOM and the real DOM will have one overlapping element.
  709. * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
  710. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  711. * @param domNode - The existing element to adopt as the root of the new virtual DOM. Existing attributes and childnodes are preserved.
  712. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
  713. * may only be rendered once.
  714. * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
  715. * @returns The [[Projection]] that was created.
  716. */
  717. merge: function (element, vnode, projectionOptions) {
  718. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  719. vnode.domNode = element;
  720. initPropertiesAndChildren(element, vnode, projectionOptions);
  721. return createProjection(vnode, projectionOptions);
  722. }
  723. };
  724. /**
  725. * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
  726. * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
  727. * For more information, see [[CalculationCache]].
  728. *
  729. * @param <Result> The type of the value that is cached.
  730. */
  731. exports.createCache = function () {
  732. var cachedInputs = undefined;
  733. var cachedOutcome = undefined;
  734. var result = {
  735. invalidate: function () {
  736. cachedOutcome = undefined;
  737. cachedInputs = undefined;
  738. },
  739. result: function (inputs, calculation) {
  740. if (cachedInputs) {
  741. for (var i = 0; i < inputs.length; i++) {
  742. if (cachedInputs[i] !== inputs[i]) {
  743. cachedOutcome = undefined;
  744. }
  745. }
  746. }
  747. if (!cachedOutcome) {
  748. cachedOutcome = calculation();
  749. cachedInputs = inputs;
  750. }
  751. return cachedOutcome;
  752. }
  753. };
  754. return result;
  755. };
  756. /**
  757. * Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
  758. * See {@link http://maquettejs.org/docs/arrays.html|Working with arrays}.
  759. *
  760. * @param <Source> The type of source items. A database-record for instance.
  761. * @param <Target> The type of target items. A [[Component]] for instance.
  762. * @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
  763. * @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
  764. * to the `callback` argument in `Array.map(callback)`.
  765. * @param updateResult `function(source, target, index)` that updates a result to an updated source.
  766. */
  767. exports.createMapping = function (getSourceKey, createResult, updateResult) {
  768. var keys = [];
  769. var results = [];
  770. return {
  771. results: results,
  772. map: function (newSources) {
  773. var newKeys = newSources.map(getSourceKey);
  774. var oldTargets = results.slice();
  775. var oldIndex = 0;
  776. for (var i = 0; i < newSources.length; i++) {
  777. var source = newSources[i];
  778. var sourceKey = newKeys[i];
  779. if (sourceKey === keys[oldIndex]) {
  780. results[i] = oldTargets[oldIndex];
  781. updateResult(source, oldTargets[oldIndex], i);
  782. oldIndex++;
  783. } else {
  784. var found = false;
  785. for (var j = 1; j < keys.length; j++) {
  786. var searchIndex = (oldIndex + j) % keys.length;
  787. if (keys[searchIndex] === sourceKey) {
  788. results[i] = oldTargets[searchIndex];
  789. updateResult(newSources[i], oldTargets[searchIndex], i);
  790. oldIndex = searchIndex + 1;
  791. found = true;
  792. break;
  793. }
  794. }
  795. if (!found) {
  796. results[i] = createResult(source, i);
  797. }
  798. }
  799. }
  800. results.length = newSources.length;
  801. keys = newKeys;
  802. }
  803. };
  804. };
  805. /**
  806. * Creates a [[Projector]] instance using the provided projectionOptions.
  807. *
  808. * For more information, see [[Projector]].
  809. *
  810. * @param projectionOptions Options that influence how the DOM is rendered and updated.
  811. */
  812. exports.createProjector = function (projectorOptions) {
  813. var projector;
  814. var projectionOptions = applyDefaultProjectionOptions(projectorOptions);
  815. projectionOptions.eventHandlerInterceptor = function (propertyName, eventHandler, domNode, properties) {
  816. return function () {
  817. // intercept function calls (event handlers) to do a render afterwards.
  818. projector.scheduleRender();
  819. return eventHandler.apply(properties.bind || this, arguments);
  820. };
  821. };
  822. var renderCompleted = true;
  823. var scheduled;
  824. var stopped = false;
  825. var projections = [];
  826. var renderFunctions = [];
  827. // matches the projections array
  828. var doRender = function () {
  829. scheduled = undefined;
  830. if (!renderCompleted) {
  831. return; // The last render threw an error, it should be logged in the browser console.
  832. }
  833. var s = Date.now()
  834. renderCompleted = false;
  835. for (var i = 0; i < projections.length; i++) {
  836. var updatedVnode = renderFunctions[i]();
  837. projections[i].update(updatedVnode);
  838. }
  839. if (Date.now()-s > 15)
  840. console.log("Render time:", Date.now()-s, "ms")
  841. renderCompleted = true;
  842. };
  843. projector = {
  844. scheduleRender: function () {
  845. if (!scheduled && !stopped) {
  846. scheduled = requestAnimationFrame(doRender);
  847. }
  848. },
  849. stop: function () {
  850. if (scheduled) {
  851. cancelAnimationFrame(scheduled);
  852. scheduled = undefined;
  853. }
  854. stopped = true;
  855. },
  856. resume: function () {
  857. stopped = false;
  858. renderCompleted = true;
  859. projector.scheduleRender();
  860. },
  861. append: function (parentNode, renderMaquetteFunction) {
  862. projections.push(exports.dom.append(parentNode, renderMaquetteFunction(), projectionOptions));
  863. renderFunctions.push(renderMaquetteFunction);
  864. },
  865. insertBefore: function (beforeNode, renderMaquetteFunction) {
  866. projections.push(exports.dom.insertBefore(beforeNode, renderMaquetteFunction(), projectionOptions));
  867. renderFunctions.push(renderMaquetteFunction);
  868. },
  869. merge: function (domNode, renderMaquetteFunction) {
  870. projections.push(exports.dom.merge(domNode, renderMaquetteFunction(), projectionOptions));
  871. renderFunctions.push(renderMaquetteFunction);
  872. },
  873. replace: function (domNode, renderMaquetteFunction) {
  874. var vnode = renderMaquetteFunction();
  875. createDom(vnode, domNode.parentNode, domNode, projectionOptions);
  876. domNode.parentNode.removeChild(domNode);
  877. projections.push(createProjection(vnode, projectionOptions));
  878. renderFunctions.push(renderMaquetteFunction);
  879. },
  880. detach: function (renderMaquetteFunction) {
  881. for (var i = 0; i < renderFunctions.length; i++) {
  882. if (renderFunctions[i] === renderMaquetteFunction) {
  883. renderFunctions.splice(i, 1);
  884. return projections.splice(i, 1)[0];
  885. }
  886. }
  887. throw new Error('renderMaquetteFunction was not found');
  888. }
  889. };
  890. return projector;
  891. };
  892. }));
  893. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Animation.coffee ---- */
  894. (function() {
  895. var Animation,
  896. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  897. Animation = (function() {
  898. function Animation() {
  899. this.height = bind(this.height, this);
  900. }
  901. Animation.prototype.slideDown = function(elem, props) {
  902. var cstyle, h, margin_bottom, margin_top, padding_bottom, padding_top, transition;
  903. h = elem.offsetHeight;
  904. cstyle = window.getComputedStyle(elem);
  905. margin_top = cstyle.marginTop;
  906. margin_bottom = cstyle.marginBottom;
  907. padding_top = cstyle.paddingTop;
  908. padding_bottom = cstyle.paddingBottom;
  909. transition = cstyle.transition;
  910. if (elem.getBoundingClientRect().top > 1600) {
  911. return;
  912. }
  913. elem.style.boxSizing = "border-box";
  914. elem.style.overflow = "hidden";
  915. elem.style.transform = "scale(0.6)";
  916. elem.style.opacity = "0";
  917. elem.style.height = "0px";
  918. elem.style.marginTop = "0px";
  919. elem.style.marginBottom = "0px";
  920. elem.style.paddingTop = "0px";
  921. elem.style.paddingBottom = "0px";
  922. elem.style.transition = "none";
  923. setTimeout((function() {
  924. elem.className += " animate-inout";
  925. elem.style.height = h + "px";
  926. elem.style.transform = "scale(1)";
  927. elem.style.opacity = "1";
  928. elem.style.marginTop = margin_top;
  929. elem.style.marginBottom = margin_bottom;
  930. elem.style.paddingTop = padding_top;
  931. return elem.style.paddingBottom = padding_bottom;
  932. }), 50);
  933. return elem.addEventListener("transitionend", function() {
  934. if (elem.style.pointerEvents === "none") {
  935. return;
  936. }
  937. elem.classList.remove("animate-inout");
  938. elem.style.transition = elem.style.transform = elem.style.opacity = elem.style.height = null;
  939. elem.style.boxSizing = elem.style.marginTop = elem.style.marginBottom = null;
  940. elem.style.paddingTop = elem.style.paddingBottom = elem.style.overflow = null;
  941. return elem.removeEventListener("transitionend", arguments.callee, false);
  942. });
  943. };
  944. Animation.prototype.slideUp = function(elem, remove_func, props) {
  945. if (elem.getBoundingClientRect().top > 1600) {
  946. remove_func();
  947. return;
  948. }
  949. elem.className += " animate-back";
  950. elem.style.boxSizing = "border-box";
  951. elem.style.height = elem.offsetHeight + "px";
  952. elem.style.overflow = "hidden";
  953. elem.style.transform = "scale(1)";
  954. elem.style.opacity = "1";
  955. elem.style.pointerEvents = "none";
  956. setTimeout((function() {
  957. elem.style.height = "0px";
  958. elem.style.marginTop = "0px";
  959. elem.style.marginBottom = "0px";
  960. elem.style.paddingTop = "0px";
  961. elem.style.paddingBottom = "0px";
  962. elem.style.transform = "scale(0.8)";
  963. elem.style.borderTopWidth = "0px";
  964. elem.style.borderBottomWidth = "0px";
  965. return elem.style.opacity = "0";
  966. }), 1);
  967. return elem.addEventListener("transitionend", function(e) {
  968. if (e.propertyName === "opacity" || e.elapsedTime >= 0.6) {
  969. elem.removeEventListener("transitionend", arguments.callee, false);
  970. return setTimeout((function() {
  971. return typeof remove_func === "function" ? remove_func() : void 0;
  972. }), 2000);
  973. }
  974. });
  975. };
  976. Animation.prototype.showRight = function(elem, props) {
  977. elem.className += " animate";
  978. elem.style.opacity = 0;
  979. elem.style.transform = "TranslateX(-20px) Scale(1.01)";
  980. setTimeout((function() {
  981. elem.style.opacity = 1;
  982. return elem.style.transform = "TranslateX(0px) Scale(1)";
  983. }), 1);
  984. return elem.addEventListener("transitionend", function() {
  985. elem.classList.remove("animate");
  986. return elem.style.transform = elem.style.opacity = null;
  987. });
  988. };
  989. Animation.prototype.show = function(elem, props) {
  990. var delay, ref;
  991. delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
  992. elem.style.transition = "none";
  993. elem.style.opacity = 0;
  994. setTimeout((function() {
  995. elem.className += " animate";
  996. return elem.style.opacity = 1;
  997. }), 50);
  998. return elem.addEventListener("transitionend", function(e) {
  999. if (e.propertyName === "opacity" || e.elapsedTime >= 0.3) {
  1000. elem.classList.remove("animate");
  1001. elem.style.opacity = null;
  1002. elem.style.transition = null;
  1003. return elem.removeEventListener("transitionend", arguments.callee, false);
  1004. }
  1005. });
  1006. };
  1007. Animation.prototype.hide = function(elem, remove_func, props) {
  1008. var delay, ref;
  1009. delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
  1010. elem.className += " animate";
  1011. setTimeout((function() {
  1012. return elem.style.opacity = 0;
  1013. }), delay);
  1014. return elem.addEventListener("transitionend", function(e) {
  1015. if (e.propertyName === "opacity") {
  1016. remove_func();
  1017. return elem.removeEventListener("transitionend", arguments.callee, false);
  1018. }
  1019. });
  1020. };
  1021. Animation.prototype.addVisibleClass = function(elem, props) {
  1022. return setTimeout(function() {
  1023. return elem.classList.add("visible");
  1024. });
  1025. };
  1026. Animation.prototype.shake = function(elem) {
  1027. elem.classList.remove("shake");
  1028. return setTimeout((function() {
  1029. return elem.classList.add("shake");
  1030. }), 50);
  1031. };
  1032. Animation.prototype.height = function(elem, props_old, props_new) {
  1033. var h;
  1034. if (props_old.classes.hidden === props_new.classes.hidden) {
  1035. return;
  1036. }
  1037. if (elem.className.indexOf("hidden") === -1) {
  1038. elem.style.height = "auto";
  1039. elem.style.transition = "none";
  1040. elem.style.paddingTop = elem.style.paddingBottom = null;
  1041. h = elem.offsetHeight;
  1042. elem.style.paddingTop = elem.style.paddingBottom = "0px";
  1043. elem.style.height = "0px";
  1044. setTimeout((function() {
  1045. return elem.style.transition = null;
  1046. }), 1);
  1047. return setTimeout((function() {
  1048. elem.style.height = h + "px";
  1049. elem.style.paddingTop = elem.style.paddingBottom = null;
  1050. return elem.addEventListener("transitionend", function(e) {
  1051. if (e.propertyName === "height" || e.elapsedTime >= 0.6) {
  1052. elem.removeEventListener("transitionend", arguments.callee, false);
  1053. }
  1054. if (elem.style.height === h + "px") {
  1055. return elem.style.height = "auto";
  1056. }
  1057. });
  1058. }), 10);
  1059. } else {
  1060. elem.style.height = elem.offsetHeight + "px";
  1061. return setTimeout((function() {
  1062. elem.style.height = "0px";
  1063. return elem.style.paddingTop = elem.style.paddingBottom = "0px";
  1064. }));
  1065. }
  1066. };
  1067. return Animation;
  1068. })();
  1069. window.Animation = new Animation();
  1070. }).call(this);
  1071. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Class.coffee ---- */
  1072. (function() {
  1073. var Class,
  1074. slice = [].slice;
  1075. Class = (function() {
  1076. function Class() {}
  1077. Class.prototype.trace = true;
  1078. Class.prototype.log = function() {
  1079. var args;
  1080. args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  1081. if (!this.trace) {
  1082. return;
  1083. }
  1084. if (typeof console === 'undefined') {
  1085. return;
  1086. }
  1087. args.unshift("[" + this.constructor.name + "]");
  1088. console.log.apply(console, args);
  1089. return this;
  1090. };
  1091. Class.prototype.logStart = function() {
  1092. var args, name;
  1093. name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  1094. if (!this.trace) {
  1095. return;
  1096. }
  1097. this.logtimers || (this.logtimers = {});
  1098. this.logtimers[name] = +(new Date);
  1099. if (args.length > 0) {
  1100. this.log.apply(this, ["" + name].concat(slice.call(args), ["(started)"]));
  1101. }
  1102. return this;
  1103. };
  1104. Class.prototype.logEnd = function() {
  1105. var args, ms, name;
  1106. name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  1107. ms = +(new Date) - this.logtimers[name];
  1108. this.log.apply(this, ["" + name].concat(slice.call(args), ["(Done in " + ms + "ms)"]));
  1109. return this;
  1110. };
  1111. return Class;
  1112. })();
  1113. window.Class = Class;
  1114. }).call(this);
  1115. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Dollar.coffee ---- */
  1116. (function() {
  1117. window.$ = function(selector) {
  1118. if (selector.startsWith("#")) {
  1119. return document.getElementById(selector.replace("#", ""));
  1120. }
  1121. };
  1122. }).call(this);
  1123. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Form.coffee ---- */
  1124. (function() {
  1125. var Form,
  1126. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1127. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  1128. hasProp = {}.hasOwnProperty;
  1129. Form = (function(superClass) {
  1130. extend(Form, superClass);
  1131. function Form() {
  1132. this.render = bind(this.render, this);
  1133. this.renderField = bind(this.renderField, this);
  1134. this.handleRadioClick = bind(this.handleRadioClick, this);
  1135. this.handleDeleteClick = bind(this.handleDeleteClick, this);
  1136. this.handleSubmitClick = bind(this.handleSubmitClick, this);
  1137. this.handleCancelClick = bind(this.handleCancelClick, this);
  1138. this.validate = bind(this.validate, this);
  1139. this.shouldBeZite = bind(this.shouldBeZite, this);
  1140. this.h = bind(this.h, this);
  1141. this.addField = bind(this.addField, this);
  1142. this.storeNode = bind(this.storeNode, this);
  1143. this.handleInput = bind(this.handleInput, this);
  1144. this.setData = bind(this.setData, this);
  1145. this.reset = bind(this.reset, this);
  1146. this.hidden = false;
  1147. this.attached = false;
  1148. this.reset();
  1149. return this;
  1150. }
  1151. Form.prototype.reset = function() {
  1152. this.data = {};
  1153. this.data_original = {};
  1154. this.inputs = {};
  1155. this.invalid = {};
  1156. this.nodes = {};
  1157. return this.fields = [];
  1158. };
  1159. Form.prototype.setData = function(data) {
  1160. this.data = data;
  1161. return this.data_original = JSON.parse(JSON.stringify(data));
  1162. };
  1163. Form.prototype.handleInput = function(e) {
  1164. this.data[e.target.name] = e.target.value;
  1165. this.invalid[e.target.name] = false;
  1166. return false;
  1167. };
  1168. Form.prototype.storeNode = function(node) {
  1169. var ref;
  1170. if ((ref = node.attributes["for"]) != null ? ref.value : void 0) {
  1171. return this.nodes[node.attributes["for"].value + "-label"] = node;
  1172. } else {
  1173. return this.nodes[node.attributes.name.value] = node;
  1174. }
  1175. };
  1176. Form.prototype.addField = function(type, id, title, props) {
  1177. var key, val;
  1178. if (props.values && props.values.constructor === Array) {
  1179. if (props.values.length && props.values[0].constructor !== Array) {
  1180. props.values = (function() {
  1181. var i, len, ref, results;
  1182. ref = props.values;
  1183. results = [];
  1184. for (i = 0, len = ref.length; i < len; i++) {
  1185. key = ref[i];
  1186. results.push([key, key]);
  1187. }
  1188. return results;
  1189. })();
  1190. }
  1191. }
  1192. if (props.values && props.values.constructor === Object) {
  1193. props.values = (function() {
  1194. var ref, results;
  1195. ref = props.values;
  1196. results = [];
  1197. for (key in ref) {
  1198. val = ref[key];
  1199. results.push([key, val]);
  1200. }
  1201. return results;
  1202. })();
  1203. }
  1204. return this.fields.push({
  1205. type: type,
  1206. id: id,
  1207. title: title,
  1208. props: props
  1209. });
  1210. };
  1211. Form.prototype.h = function(tag, props, childs) {
  1212. var ref, ref1, ref2, ref3;
  1213. this.inputs[props.name] = [tag, props, childs];
  1214. if ((ref = props.value) != null) {
  1215. ref;
  1216. } else {
  1217. props.value = this.data[props.name];
  1218. };
  1219. if ((ref1 = props.id) != null) {
  1220. ref1;
  1221. } else {
  1222. props.id = props.name;
  1223. };
  1224. if ((ref2 = props.oninput) != null) {
  1225. ref2;
  1226. } else {
  1227. props.oninput = this.handleInput;
  1228. };
  1229. props.afterCreate = this.storeNode;
  1230. if ((ref3 = props.classes) != null) {
  1231. ref3;
  1232. } else {
  1233. props.classes = {};
  1234. };
  1235. if (this.invalid[props.name] || this.invalid[props["for"]]) {
  1236. props.classes.invalid = true;
  1237. } else {
  1238. props.classes.invalid = false;
  1239. }
  1240. if (this.invalid[props.name]) {
  1241. return [
  1242. h(tag, props, childs), h("div.invalid-reason", {
  1243. key: "reason-" + props.name,
  1244. enterAnimation: Animation.slideDown,
  1245. exitAnimation: Animation.slideUp
  1246. }, this.invalid[props.name])
  1247. ];
  1248. } else {
  1249. return h(tag, props, childs);
  1250. }
  1251. };
  1252. Form.prototype.shouldBeZite = function(value) {
  1253. if (!value.match(/([A-Za-z0-9]{26,35}|[A-Za-z0-9\.-]{2,99}\.bit)/)) {
  1254. return "Invalid site address: only ZeroNet addresses supported";
  1255. }
  1256. };
  1257. Form.prototype.validate = function() {
  1258. var childs, field_error, i, len, name, props, ref, ref1, ref2, tag, valid, validate;
  1259. valid = true;
  1260. this.invalid = {};
  1261. ref = this.inputs;
  1262. for (name in ref) {
  1263. ref1 = ref[name], tag = ref1[0], props = ref1[1], childs = ref1[2];
  1264. if (props.required && !props.value) {
  1265. this.invalid[name] = "This field is required";
  1266. Animation.shake(this.nodes[props.name]);
  1267. valid = false;
  1268. } else if (props.validate) {
  1269. if (props.validate.constructor === Array) {
  1270. ref2 = props.validate;
  1271. for (i = 0, len = ref2.length; i < len; i++) {
  1272. validate = ref2[i];
  1273. field_error = validate(props.value);
  1274. if (field_error) {
  1275. break;
  1276. }
  1277. }
  1278. } else {
  1279. field_error = props.validate(props.value);
  1280. }
  1281. if (field_error) {
  1282. valid = false;
  1283. this.invalid[name] = field_error;
  1284. }
  1285. } else {
  1286. this.invalid[name] = false;
  1287. }
  1288. }
  1289. Page.projector.scheduleRender();
  1290. return valid;
  1291. };
  1292. Form.prototype.handleCancelClick = function() {
  1293. var key, ref, val;
  1294. this.hidden = true;
  1295. ref = this.data_original;
  1296. for (key in ref) {
  1297. val = ref[key];
  1298. this.data[key] = val;
  1299. }
  1300. Page.projector.scheduleRender();
  1301. return false;
  1302. };
  1303. Form.prototype.handleSubmitClick = function() {
  1304. if (!this.validate()) {
  1305. return false;
  1306. }
  1307. this.saveRow((function(_this) {
  1308. return function(res) {
  1309. if (res === "ok") {
  1310. _this.hidden = true;
  1311. return Page.projector.scheduleRender();
  1312. }
  1313. };
  1314. })(this));
  1315. return false;
  1316. };
  1317. Form.prototype.handleDeleteClick = function() {
  1318. Page.cmd("wrapperConfirm", ["Are you sure you want to delete this item?", "Delete"], (function(_this) {
  1319. return function() {
  1320. return _this.deleteRow(function(res) {
  1321. if (res === "ok") {
  1322. _this.hidden = true;
  1323. return Page.projector.scheduleRender();
  1324. }
  1325. });
  1326. };
  1327. })(this));
  1328. return false;
  1329. };
  1330. Form.prototype.handleRadioClick = function(e) {
  1331. var id;
  1332. id = e.currentTarget.attributes["for"].value;
  1333. this.data[id] = e.currentTarget.value;
  1334. this.invalid[id] = false;
  1335. Page.projector.scheduleRender();
  1336. return false;
  1337. };
  1338. Form.prototype.renderField = function(field) {
  1339. var props, values;
  1340. props = field.props;
  1341. props.value = this.data[field.id];
  1342. props.name = field.id;
  1343. values = props.values;
  1344. if (field.type === "radio") {
  1345. return h("div.formfield", this.h("label.title", {
  1346. "for": field.id
  1347. }, field.title), this.h("div.radiogroup", props, [
  1348. values.map((function(_this) {
  1349. return function(arg) {
  1350. var key, value;
  1351. key = arg[0], value = arg[1];
  1352. return [
  1353. h("a.radio", {
  1354. "for": props.id,
  1355. key: key,
  1356. href: "#" + key,
  1357. onclick: _this.handleRadioClick,
  1358. value: key,
  1359. classes: {
  1360. active: _this.data[field.id] === key
  1361. }
  1362. }, value), " "
  1363. ];
  1364. };
  1365. })(this))
  1366. ]));
  1367. } else {
  1368. return h("div.formfield", this.h("label.title", {
  1369. "for": field.id
  1370. }, field.title), this.h("input.text", props));
  1371. }
  1372. };
  1373. Form.prototype.render = function(classname) {
  1374. if (classname == null) {
  1375. classname = "";
  1376. }
  1377. return h("div.form-takeover-container#FormEdit", {
  1378. afterCreate: Animation.show,
  1379. classes: {
  1380. hidden: this.hidden
  1381. }
  1382. }, [
  1383. h("div.form.form-takeover" + classname, {
  1384. afterCreate: Animation.slideDown,
  1385. exitAnimation: Animation.slideUp
  1386. }, this.fields.map(this.renderField), h("a.cancel.link", {
  1387. href: "#Cancel",
  1388. onclick: this.handleCancelClick
  1389. }, "Cancel"), this.deleteRow ? h("a.button.button-submit.button-outline", {
  1390. href: "#Delete",
  1391. onclick: this.handleDeleteClick
  1392. }, "Delete") : void 0, h("a.button.button-submit", {
  1393. href: "#Modify",
  1394. onclick: this.handleSubmitClick
  1395. }, "Modify"))
  1396. ]);
  1397. };
  1398. return Form;
  1399. })(Class);
  1400. window.Form = Form;
  1401. }).call(this);
  1402. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/ItemList.coffee ---- */
  1403. (function() {
  1404. var ItemList;
  1405. ItemList = (function() {
  1406. function ItemList(item_class1, key1) {
  1407. this.item_class = item_class1;
  1408. this.key = key1;
  1409. this.items = [];
  1410. this.items_bykey = {};
  1411. }
  1412. ItemList.prototype.sync = function(rows, item_class, key) {
  1413. var current_obj, i, item, len, results, row;
  1414. this.items.splice(0, this.items.length);
  1415. results = [];
  1416. for (i = 0, len = rows.length; i < len; i++) {
  1417. row = rows[i];
  1418. current_obj = this.items_bykey[row[this.key]];
  1419. if (current_obj) {
  1420. current_obj.row = row;
  1421. results.push(this.items.push(current_obj));
  1422. } else {
  1423. item = new this.item_class(row, this);
  1424. this.items_bykey[row[this.key]] = item;
  1425. results.push(this.items.push(item));
  1426. }
  1427. }
  1428. return results;
  1429. };
  1430. ItemList.prototype.deleteItem = function(item) {
  1431. var index;
  1432. index = this.items.indexOf(item);
  1433. if (index > -1) {
  1434. this.items.splice(index, 1);
  1435. } else {
  1436. console.log("Can't delete item", item);
  1437. }
  1438. return delete this.items_bykey[item.row[this.key]];
  1439. };
  1440. return ItemList;
  1441. })();
  1442. window.ItemList = ItemList;
  1443. }).call(this);
  1444. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Menu.coffee ---- */
  1445. (function() {
  1446. var Menu,
  1447. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  1448. Menu = (function() {
  1449. function Menu() {
  1450. this.render = bind(this.render, this);
  1451. this.renderItem = bind(this.renderItem, this);
  1452. this.handleClick = bind(this.handleClick, this);
  1453. this.storeNode = bind(this.storeNode, this);
  1454. this.toggle = bind(this.toggle, this);
  1455. this.hide = bind(this.hide, this);
  1456. this.show = bind(this.show, this);
  1457. this.visible = false;
  1458. this.items = [];
  1459. this.node = null;
  1460. }
  1461. Menu.prototype.show = function() {
  1462. var ref;
  1463. if ((ref = window.visible_menu) != null) {
  1464. ref.hide();
  1465. }
  1466. this.visible = true;
  1467. return window.visible_menu = this;
  1468. };
  1469. Menu.prototype.hide = function() {
  1470. return this.visible = false;
  1471. };
  1472. Menu.prototype.toggle = function() {
  1473. if (this.visible) {
  1474. this.hide();
  1475. } else {
  1476. this.show();
  1477. }
  1478. return Page.projector.scheduleRender();
  1479. };
  1480. Menu.prototype.addItem = function(title, cb, selected) {
  1481. if (selected == null) {
  1482. selected = false;
  1483. }
  1484. return this.items.push([title, cb, selected]);
  1485. };
  1486. Menu.prototype.storeNode = function(node) {
  1487. this.node = node;
  1488. if (this.visible) {
  1489. node.className = node.className.replace("visible", "");
  1490. return setTimeout((function() {
  1491. return node.className += " visible";
  1492. }), 20);
  1493. }
  1494. };
  1495. Menu.prototype.handleClick = function(e) {
  1496. var cb, i, item, keep_menu, len, ref, selected, title;
  1497. keep_menu = true;
  1498. ref = this.items;
  1499. for (i = 0, len = ref.length; i < len; i++) {
  1500. item = ref[i];
  1501. title = item[0], cb = item[1], selected = item[2];
  1502. if (title === e.target.textContent || e.target["data-title"] === title) {
  1503. keep_menu = cb(item);
  1504. break;
  1505. }
  1506. }
  1507. if (keep_menu !== true) {
  1508. this.hide();
  1509. }
  1510. return false;
  1511. };
  1512. Menu.prototype.renderItem = function(item) {
  1513. var cb, href, key, onclick, selected, title;
  1514. title = item[0], cb = item[1], selected = item[2];
  1515. if (typeof selected === "function") {
  1516. selected = selected();
  1517. }
  1518. if (title === "---") {
  1519. return h("div.menu-item-separator");
  1520. } else {
  1521. if (typeof cb === "string") {
  1522. href = cb;
  1523. onclick = true;
  1524. } else {
  1525. href = "#" + title;
  1526. onclick = this.handleClick;
  1527. }
  1528. if (typeof title === "function") {
  1529. title = title();
  1530. key = "#";
  1531. } else {
  1532. key = title;
  1533. }
  1534. return h("a.menu-item", {
  1535. href: href,
  1536. onclick: onclick,
  1537. "data-title": title,
  1538. key: key,
  1539. classes: {
  1540. "selected": selected,
  1541. "noaction": cb === null
  1542. }
  1543. }, title);
  1544. }
  1545. };
  1546. Menu.prototype.render = function(class_name) {
  1547. if (class_name == null) {
  1548. class_name = "";
  1549. }
  1550. if (this.visible || this.node) {
  1551. return h("div.menu" + class_name, {
  1552. classes: {
  1553. "visible": this.visible
  1554. },
  1555. afterCreate: this.storeNode
  1556. }, this.items.map(this.renderItem));
  1557. }
  1558. };
  1559. return Menu;
  1560. })();
  1561. window.Menu = Menu;
  1562. document.body.addEventListener("mouseup", function(e) {
  1563. var isChildOf;
  1564. if (!window.visible_menu || !window.visible_menu.node) {
  1565. return false;
  1566. }
  1567. isChildOf = function(child, parent) {
  1568. var node;
  1569. node = child.parentNode;
  1570. while (node !== null) {
  1571. if (node === parent) {
  1572. return true;
  1573. } else {
  1574. node = node.parentNode;
  1575. }
  1576. }
  1577. return false;
  1578. };
  1579. if (!isChildOf(e.target, window.visible_menu.node.parentNode) && !isChildOf(e.target, window.visible_menu.node)) {
  1580. window.visible_menu.hide();
  1581. return Page.projector.scheduleRender();
  1582. }
  1583. });
  1584. }).call(this);
  1585. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Prototypes.coffee ---- */
  1586. (function() {
  1587. String.prototype.startsWith = function(s) {
  1588. return this.slice(0, s.length) === s;
  1589. };
  1590. String.prototype.endsWith = function(s) {
  1591. return s === '' || this.slice(-s.length) === s;
  1592. };
  1593. String.prototype.repeat = function(count) {
  1594. return new Array(count + 1).join(this);
  1595. };
  1596. window.isEmpty = function(obj) {
  1597. var key;
  1598. for (key in obj) {
  1599. return false;
  1600. }
  1601. return true;
  1602. };
  1603. }).call(this);
  1604. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/RateLimit.coffee ---- */
  1605. (function() {
  1606. var call_after_interval, limits;
  1607. limits = {};
  1608. call_after_interval = {};
  1609. window.RateLimit = function(interval, fn) {
  1610. if (!limits[fn]) {
  1611. call_after_interval[fn] = false;
  1612. fn();
  1613. return limits[fn] = setTimeout((function() {
  1614. if (call_after_interval[fn]) {
  1615. fn();
  1616. }
  1617. delete limits[fn];
  1618. return delete call_after_interval[fn];
  1619. }), interval);
  1620. } else {
  1621. return call_after_interval[fn] = true;
  1622. }
  1623. };
  1624. }).call(this);
  1625. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Text.coffee ---- */
  1626. (function() {
  1627. var Text,
  1628. indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  1629. Text = (function() {
  1630. function Text() {}
  1631. Text.prototype.toColor = function(text, saturation, lightness) {
  1632. var hash, i, j, ref;
  1633. if (saturation == null) {
  1634. saturation = 30;
  1635. }
  1636. if (lightness == null) {
  1637. lightness = 50;
  1638. }
  1639. hash = 0;
  1640. for (i = j = 0, ref = text.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
  1641. hash += text.charCodeAt(i) * i;
  1642. hash = hash % 1777;
  1643. }
  1644. return "hsl(" + (hash % 360) + ("," + saturation + "%," + lightness + "%)");
  1645. };
  1646. Text.prototype.renderMarked = function(text, options) {
  1647. if (options == null) {
  1648. options = {};
  1649. }
  1650. options["gfm"] = true;
  1651. options["breaks"] = true;
  1652. options["renderer"] = marked_renderer;
  1653. text = this.fixReply(text);
  1654. text = marked(text, options);
  1655. text = this.emailLinks(text);
  1656. return this.fixHtmlLinks(text);
  1657. };
  1658. Text.prototype.emailLinks = function(text) {
  1659. return text.replace(/([a-zA-Z0-9]+)@zeroid.bit/g, "<a href='?to=$1' onclick='return Page.message_create.show(\"$1\")'>$1@zeroid.bit</a>");
  1660. };
  1661. Text.prototype.fixHtmlLinks = function(text) {
  1662. if (window.is_proxy) {
  1663. return text.replace(/href="http:\/\/(127.0.0.1|localhost):43110/g, 'href="http://zero');
  1664. } else {
  1665. return text.replace(/href="http:\/\/(127.0.0.1|localhost):43110/g, 'href="');
  1666. }
  1667. };
  1668. Text.prototype.fixLink = function(link) {
  1669. var back;
  1670. if (window.is_proxy) {
  1671. back = link.replace(/http:\/\/(127.0.0.1|localhost):43110/, 'http://zero');
  1672. return back.replace(/http:\/\/zero\/([^\/]+\.bit)/, "http://$1");
  1673. } else {
  1674. return link.replace(/http:\/\/(127.0.0.1|localhost):43110/, '');
  1675. }
  1676. };
  1677. Text.prototype.toUrl = function(text) {
  1678. return text.replace(/[^A-Za-z0-9]/g, "+").replace(/[+]+/g, "+").replace(/[+]+$/, "");
  1679. };
  1680. Text.prototype.getSiteUrl = function(address) {
  1681. if (window.is_proxy) {
  1682. if (indexOf.call(address, ".") >= 0) {
  1683. return "http://" + address;
  1684. } else {
  1685. return "http://zero/" + address;
  1686. }
  1687. } else {
  1688. return "/" + address;
  1689. }
  1690. };
  1691. Text.prototype.fixReply = function(text) {
  1692. return text.replace(/(>.*\n)([^\n>])/gm, "$1\n$2");
  1693. };
  1694. Text.prototype.toBitcoinAddress = function(text) {
  1695. return text.replace(/[^A-Za-z0-9]/g, "");
  1696. };
  1697. Text.prototype.jsonEncode = function(obj) {
  1698. return unescape(encodeURIComponent(JSON.stringify(obj)));
  1699. };
  1700. Text.prototype.jsonDecode = function(obj) {
  1701. return JSON.parse(decodeURIComponent(escape(obj)));
  1702. };
  1703. Text.prototype.fileEncode = function(obj) {
  1704. if (typeof obj === "string") {
  1705. return btoa(unescape(encodeURIComponent(obj)));
  1706. } else {
  1707. return btoa(unescape(encodeURIComponent(JSON.stringify(obj, void 0, '\t'))));
  1708. }
  1709. };
  1710. Text.prototype.utf8Encode = function(s) {
  1711. return unescape(encodeURIComponent(s));
  1712. };
  1713. Text.prototype.utf8Decode = function(s) {
  1714. return decodeURIComponent(escape(s));
  1715. };
  1716. Text.prototype.distance = function(s1, s2) {
  1717. var char, extra_parts, j, key, len, match, next_find, next_find_i, val;
  1718. s1 = s1.toLocaleLowerCase();
  1719. s2 = s2.toLocaleLowerCase();
  1720. next_find_i = 0;
  1721. next_find = s2[0];
  1722. match = true;
  1723. extra_parts = {};
  1724. for (j = 0, len = s1.length; j < len; j++) {
  1725. char = s1[j];
  1726. if (char !== next_find) {
  1727. if (extra_parts[next_find_i]) {
  1728. extra_parts[next_find_i] += char;
  1729. } else {
  1730. extra_parts[next_find_i] = char;
  1731. }
  1732. } else {
  1733. next_find_i++;
  1734. next_find = s2[next_find_i];
  1735. }
  1736. }
  1737. if (extra_parts[next_find_i]) {
  1738. extra_parts[next_find_i] = "";
  1739. }
  1740. extra_parts = (function() {
  1741. var results;
  1742. results = [];
  1743. for (key in extra_parts) {
  1744. val = extra_parts[key];
  1745. results.push(val);
  1746. }
  1747. return results;
  1748. })();
  1749. if (next_find_i >= s2.length) {
  1750. return extra_parts.length + extra_parts.join("").length;
  1751. } else {
  1752. return false;
  1753. }
  1754. };
  1755. Text.prototype.parseQuery = function(query) {
  1756. var j, key, len, params, part, parts, ref, val;
  1757. params = {};
  1758. parts = query.split('&');
  1759. for (j = 0, len = parts.length; j < len; j++) {
  1760. part = parts[j];
  1761. ref = part.split("="), key = ref[0], val = ref[1];
  1762. if (val) {
  1763. params[decodeURIComponent(key)] = decodeURIComponent(val);
  1764. } else {
  1765. params["url"] = decodeURIComponent(key);
  1766. }
  1767. }
  1768. return params;
  1769. };
  1770. Text.prototype.encodeQuery = function(params) {
  1771. var back, key, val;
  1772. back = [];
  1773. if (params.url) {
  1774. back.push(params.url);
  1775. }
  1776. for (key in params) {
  1777. val = params[key];
  1778. if (!val || key === "url") {
  1779. continue;
  1780. }
  1781. back.push((encodeURIComponent(key)) + "=" + (encodeURIComponent(val)));
  1782. }
  1783. return back.join("&");
  1784. };
  1785. Text.prototype.sqlIn = function(values) {
  1786. var value;
  1787. return "(" + ((function() {
  1788. var j, len, results;
  1789. results = [];
  1790. for (j = 0, len = values.length; j < len; j++) {
  1791. value = values[j];
  1792. results.push("'" + value + "'");
  1793. }
  1794. return results;
  1795. })()).join(',') + ")";
  1796. };
  1797. return Text;
  1798. })();
  1799. window.is_proxy = document.location.host === "zero" || window.location.pathname === "/";
  1800. window.Text = new Text();
  1801. }).call(this);
  1802. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/Time.coffee ---- */
  1803. (function() {
  1804. var Time;
  1805. Time = (function() {
  1806. function Time() {}
  1807. Time.prototype.since = function(timestamp) {
  1808. var back, now, secs;
  1809. now = +(new Date) / 1000;
  1810. if (timestamp > 1000000000000) {
  1811. timestamp = timestamp / 1000;
  1812. }
  1813. secs = now - timestamp;
  1814. if (secs < 60) {
  1815. back = "Just now";
  1816. } else if (secs < 60 * 60) {
  1817. back = (Math.round(secs / 60)) + " minutes ago";
  1818. } else if (secs < 60 * 60 * 24) {
  1819. back = (Math.round(secs / 60 / 60)) + " hours ago";
  1820. } else if (secs < 60 * 60 * 24 * 3) {
  1821. back = (Math.round(secs / 60 / 60 / 24)) + " days ago";
  1822. } else {
  1823. back = "on " + this.date(timestamp);
  1824. }
  1825. back = back.replace(/1 ([a-z]+)s/, "1 $1");
  1826. return back;
  1827. };
  1828. Time.prototype.date = function(timestamp, format) {
  1829. var display, parts;
  1830. if (format == null) {
  1831. format = "short";
  1832. }
  1833. if (timestamp > 1000000000000) {
  1834. timestamp = timestamp / 1000;
  1835. }
  1836. parts = (new Date(timestamp * 1000)).toString().split(" ");
  1837. if (format === "short") {
  1838. display = parts.slice(1, 4);
  1839. } else {
  1840. display = parts.slice(1, 5);
  1841. }
  1842. return display.join(" ").replace(/( [0-9]{4})/, ",$1");
  1843. };
  1844. Time.prototype.timestamp = function(date) {
  1845. if (date == null) {
  1846. date = "";
  1847. }
  1848. if (date === "now" || date === "") {
  1849. return parseInt(+(new Date) / 1000);
  1850. } else {
  1851. return parseInt(Date.parse(date) / 1000);
  1852. }
  1853. };
  1854. return Time;
  1855. })();
  1856. window.Time = new Time;
  1857. }).call(this);
  1858. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/utils/ZeroFrame.coffee ---- */
  1859. (function() {
  1860. var ZeroFrame,
  1861. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1862. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  1863. hasProp = {}.hasOwnProperty;
  1864. ZeroFrame = (function(superClass) {
  1865. extend(ZeroFrame, superClass);
  1866. function ZeroFrame(url) {
  1867. this.onCloseWebsocket = bind(this.onCloseWebsocket, this);
  1868. this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
  1869. this.onRequest = bind(this.onRequest, this);
  1870. this.onMessage = bind(this.onMessage, this);
  1871. this.url = url;
  1872. this.waiting_cb = {};
  1873. this.history_state = {};
  1874. this.wrapper_nonce = document.location.href.replace(/.*wrapper_nonce=([A-Za-z0-9]+).*/, "$1");
  1875. this.connect();
  1876. this.next_message_id = 1;
  1877. this.init();
  1878. }
  1879. ZeroFrame.prototype.init = function() {
  1880. return this;
  1881. };
  1882. ZeroFrame.prototype.connect = function() {
  1883. this.target = window.parent;
  1884. window.addEventListener("message", this.onMessage, false);
  1885. this.cmd("innerReady");
  1886. window.addEventListener("beforeunload", (function(_this) {
  1887. return function(e) {
  1888. _this.log("Save scrollTop", window.pageYOffset);
  1889. _this.history_state["scrollTop"] = window.pageYOffset;
  1890. return _this.cmd("wrapperReplaceState", [_this.history_state, null]);
  1891. };
  1892. })(this));
  1893. return this.cmd("wrapperGetState", [], (function(_this) {
  1894. return function(state) {
  1895. return _this.handleState(state);
  1896. };
  1897. })(this));
  1898. };
  1899. ZeroFrame.prototype.handleState = function(state) {
  1900. if (state != null) {
  1901. this.history_state = state;
  1902. }
  1903. this.log("Restore scrollTop", state, window.pageYOffset);
  1904. if (window.pageYOffset === 0 && state) {
  1905. return window.scroll(window.pageXOffset, state.scrollTop);
  1906. }
  1907. };
  1908. ZeroFrame.prototype.onMessage = function(e) {
  1909. var cmd, message;
  1910. message = e.data;
  1911. cmd = message.cmd;
  1912. if (cmd === "response") {
  1913. if (this.waiting_cb[message.to] != null) {
  1914. return this.waiting_cb[message.to](message.result);
  1915. } else {
  1916. return this.log("Websocket callback not found:", message);
  1917. }
  1918. } else if (cmd === "wrapperReady") {
  1919. return this.cmd("innerReady");
  1920. } else if (cmd === "ping") {
  1921. return this.response(message.id, "pong");
  1922. } else if (cmd === "wrapperOpenedWebsocket") {
  1923. return this.onOpenWebsocket();
  1924. } else if (cmd === "wrapperClosedWebsocket") {
  1925. return this.onCloseWebsocket();
  1926. } else if (cmd === "wrapperPopState") {
  1927. this.handleState(message.params.state);
  1928. return this.onRequest(cmd, message.params);
  1929. } else {
  1930. return this.onRequest(cmd, message.params);
  1931. }
  1932. };
  1933. ZeroFrame.prototype.onRequest = function(cmd, message) {
  1934. return this.log("Unknown request", message);
  1935. };
  1936. ZeroFrame.prototype.response = function(to, result) {
  1937. return this.send({
  1938. "cmd": "response",
  1939. "to": to,
  1940. "result": result
  1941. });
  1942. };
  1943. ZeroFrame.prototype.cmd = function(cmd, params, cb) {
  1944. if (params == null) {
  1945. params = {};
  1946. }
  1947. if (cb == null) {
  1948. cb = null;
  1949. }
  1950. return this.send({
  1951. "cmd": cmd,
  1952. "params": params
  1953. }, cb);
  1954. };
  1955. ZeroFrame.prototype.cmdp = function(cmd, params) {
  1956. var p;
  1957. if (params == null) {
  1958. params = {};
  1959. }
  1960. p = new Promise();
  1961. this.send({
  1962. "cmd": cmd,
  1963. "params": params
  1964. }, function(res) {
  1965. return p.resolve(res);
  1966. });
  1967. return p;
  1968. };
  1969. ZeroFrame.prototype.send = function(message, cb) {
  1970. if (cb == null) {
  1971. cb = null;
  1972. }
  1973. message.wrapper_nonce = this.wrapper_nonce;
  1974. message.id = this.next_message_id;
  1975. this.next_message_id += 1;
  1976. this.target.postMessage(message, "*");
  1977. if (cb) {
  1978. return this.waiting_cb[message.id] = cb;
  1979. }
  1980. };
  1981. ZeroFrame.prototype.onOpenWebsocket = function() {
  1982. return this.log("Websocket open");
  1983. };
  1984. ZeroFrame.prototype.onCloseWebsocket = function() {
  1985. return this.log("Websocket close");
  1986. };
  1987. return ZeroFrame;
  1988. })(Class);
  1989. window.ZeroFrame = ZeroFrame;
  1990. }).call(this);
  1991. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/Head.coffee ---- */
  1992. (function() {
  1993. var Head,
  1994. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  1995. Head = (function() {
  1996. function Head() {
  1997. this.render = bind(this.render, this);
  1998. this.handleMenuClick = bind(this.handleMenuClick, this);
  1999. this.active = "popular";
  2000. }
  2001. Head.prototype.handleMenuClick = function(e) {
  2002. this.active = e.currentTarget.attributes.name.value;
  2003. Page.site_lists.update();
  2004. return false;
  2005. };
  2006. Head.prototype.render = function() {
  2007. return h("div#Head", [
  2008. h("a.logo", {
  2009. href: "?Home",
  2010. onclick: Page.handleLinkClick
  2011. }, [
  2012. h("img", {
  2013. "src": "img/logo.png",
  2014. "width": 58,
  2015. "height": 64
  2016. }), h("h1", "ZeroSites")
  2017. ]), h("div.order", [
  2018. h("a.order-item.popular", {
  2019. href: "#",
  2020. name: "popular",
  2021. classes: {
  2022. active: this.active === "popular"
  2023. },
  2024. onclick: this.handleMenuClick
  2025. }, "Popular"), h("a.order-item.new", {
  2026. href: "#",
  2027. name: "new",
  2028. classes: {
  2029. active: this.active === "new"
  2030. },
  2031. onclick: this.handleMenuClick
  2032. }, "New")
  2033. ])
  2034. ]);
  2035. };
  2036. return Head;
  2037. })();
  2038. window.Head = Head;
  2039. }).call(this);
  2040. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/Site.coffee ---- */
  2041. (function() {
  2042. var Site,
  2043. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  2044. Site = (function() {
  2045. function Site(row1) {
  2046. this.row = row1;
  2047. this.render = bind(this.render, this);
  2048. this.handleEditClick = bind(this.handleEditClick, this);
  2049. this.deleteRow = bind(this.deleteRow, this);
  2050. this.saveRow = bind(this.saveRow, this);
  2051. this.getClasses = bind(this.getClasses, this);
  2052. this.handleStarClick = bind(this.handleStarClick, this);
  2053. this.isNew = bind(this.isNew, this);
  2054. this.getUri = bind(this.getUri, this);
  2055. this.form_edit = null;
  2056. this;
  2057. }
  2058. Site.prototype.getUri = function() {
  2059. return this.row.directory + "_" + this.row.site_id;
  2060. };
  2061. Site.prototype.isNew = function() {
  2062. return Time.timestamp() - this.row.date_added < 60 * 60 * 24;
  2063. };
  2064. Site.prototype.handleStarClick = function() {
  2065. var action;
  2066. if (!Page.site_info.cert_user_id) {
  2067. Page.user.certSelect((function(_this) {
  2068. return function() {
  2069. return _this.handleStarClick();
  2070. };
  2071. })(this));
  2072. return false;
  2073. }
  2074. if (Page.user.starred[this.getUri()]) {
  2075. action = "removing";
  2076. } else {
  2077. action = "adding";
  2078. }
  2079. Page.user.starred[this.getUri()] = !Page.user.starred[this.getUri()];
  2080. Page.projector.scheduleRender();
  2081. Page.user.getData((function(_this) {
  2082. return function(data) {
  2083. if (action === "adding") {
  2084. data.site_star[_this.getUri()] = 1;
  2085. } else {
  2086. delete data.site_star[_this.getUri()];
  2087. }
  2088. return Page.user.save(data, function(res) {
  2089. return Page.site_lists.update();
  2090. });
  2091. };
  2092. })(this));
  2093. return false;
  2094. };
  2095. Site.prototype.getClasses = function() {
  2096. return {
  2097. my: this.row.cert_user_id === Page.site_info.cert_user_id || Page.site_info.settings.own,
  2098. starred: Page.user.starred[this.getUri()]
  2099. };
  2100. };
  2101. Site.prototype.saveRow = function(cb) {
  2102. var user;
  2103. user = new User(this.row.directory);
  2104. return user.getData((function(_this) {
  2105. return function(data) {
  2106. var data_row, j, key, len, ref, ref1, row, val;
  2107. ref = data.site;
  2108. for (j = 0, len = ref.length; j < len; j++) {
  2109. row = ref[j];
  2110. if (row.site_id === _this.row.site_id) {
  2111. data_row = row;
  2112. }
  2113. }
  2114. ref1 = _this.row;
  2115. for (key in ref1) {
  2116. val = ref1[key];
  2117. if (data_row[key]) {
  2118. data_row[key] = val;
  2119. }
  2120. }
  2121. return user.save(data, function(res) {
  2122. Page.site_lists.update();
  2123. return typeof cb === "function" ? cb(res) : void 0;
  2124. });
  2125. };
  2126. })(this));
  2127. };
  2128. Site.prototype.deleteRow = function(cb) {
  2129. return Page.user.getData((function(_this) {
  2130. return function(data) {
  2131. var data_row_i, i, j, len, ref, row;
  2132. ref = data.site;
  2133. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  2134. row = ref[i];
  2135. if (row.site_id === _this.row.site_id) {
  2136. data_row_i = i;
  2137. }
  2138. }
  2139. data.site.splice(data_row_i, 1);
  2140. return Page.user.save(data, function(res) {
  2141. Page.site_lists.update();
  2142. return typeof cb === "function" ? cb(res) : void 0;
  2143. });
  2144. };
  2145. })(this));
  2146. };
  2147. Site.prototype.handleEditClick = function() {
  2148. if (!this.form_edit) {
  2149. this.form_edit = new Form();
  2150. this.form_edit.addField("text", "address", "Address", {
  2151. placeholder: "e.g. http://127.0.0.1:43110/1BLogC9LN4oPDcruNz3qo1ysa133E9AGg8",
  2152. required: true,
  2153. validate: this.form_edit.shouldBeZite
  2154. });
  2155. this.form_edit.addField("text", "title", "Title", {
  2156. placeholder: "e.g. ZeroBlog",
  2157. required: true
  2158. });
  2159. this.form_edit.addField("radio", "language", "Language", {
  2160. required: true,
  2161. values: Page.languages,
  2162. classes: {
  2163. "radiogroup-lang": true
  2164. }
  2165. });
  2166. this.form_edit.addField("radio", "category", "Category", {
  2167. required: true,
  2168. values: Page.categories
  2169. });
  2170. this.form_edit.addField("text", "description", "Description", {
  2171. placeholder: "e.g. ZeroNet changelog and related informations",
  2172. required: true
  2173. });
  2174. }
  2175. this.form_edit.setData(this.row);
  2176. this.form_edit.saveRow = this.saveRow;
  2177. this.form_edit.deleteRow = this.deleteRow;
  2178. Page.setFormEdit(this.form_edit);
  2179. return false;
  2180. };
  2181. Site.prototype.render = function() {
  2182. var my, ref;
  2183. my = this.row.cert_user_id === Page.site_info.cert_user_id || Page.site_info.settings.own;
  2184. return h("a.site.nocomment", {
  2185. href: Text.fixLink("http://127.0.0.1:43110/" + this.row.address),
  2186. key: this.row.site_id,
  2187. enterAnimation: Animation.slideDown,
  2188. exitAnimation: Animation.slideUp,
  2189. classes: this.getClasses()
  2190. }, [
  2191. h("div.right", [
  2192. h("a.star", {
  2193. href: "#Star",
  2194. onclick: this.handleStarClick
  2195. }, h("span.num", this.row.star || ""), h("span.icon.icon-star", "")), h("a.comments", {
  2196. href: "#"
  2197. }, h("span.num", "soon"), h("span.icon.icon-comment", "")), this.row.peers ? h("div.peers", h("span.num", this.row.peers), h("span.icon.icon-profile", "")) : void 0
  2198. ]), h("div.title", this.row.title), this.isNew() ? h("div.tag.tag-new", "New") : void 0, ((ref = this.row.tags) != null ? ref.indexOf("popular") : void 0) >= 0 ? h("div.tag.tag-popular", "Popular") : void 0, my ? h("a.tag.tag-my", {
  2199. href: "#Edit:" + this.row.site_uri,
  2200. onclick: this.handleEditClick
  2201. }, "Edit") : void 0, h("div.description", this.row.description)
  2202. ]);
  2203. };
  2204. return Site;
  2205. })();
  2206. window.Site = Site;
  2207. }).call(this);
  2208. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/SiteAdd.coffee ---- */
  2209. (function() {
  2210. var SiteAdd,
  2211. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2212. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2213. hasProp = {}.hasOwnProperty;
  2214. SiteAdd = (function(superClass) {
  2215. extend(SiteAdd, superClass);
  2216. function SiteAdd() {
  2217. this.close = bind(this.close, this);
  2218. this.shouldBeUniqueSite = bind(this.shouldBeUniqueSite, this);
  2219. this.updateDb = bind(this.updateDb, this);
  2220. this.handleSubmit = bind(this.handleSubmit, this);
  2221. this.handleRadioCategoryClick = bind(this.handleRadioCategoryClick, this);
  2222. this.handleRadioLangClick = bind(this.handleRadioLangClick, this);
  2223. this.form = new Form();
  2224. this.db = {};
  2225. this.submitting = false;
  2226. return this;
  2227. }
  2228. SiteAdd.prototype.handleRadioLangClick = function(e) {
  2229. this.form.data["language"] = e.currentTarget.value;
  2230. this.form.invalid["language"] = false;
  2231. Page.projector.scheduleRender();
  2232. return false;
  2233. };
  2234. SiteAdd.prototype.handleRadioCategoryClick = function(e) {
  2235. this.form.data["category"] = e.currentTarget.value;
  2236. this.form.invalid["category"] = false;
  2237. Page.projector.scheduleRender();
  2238. return false;
  2239. };
  2240. SiteAdd.prototype.handleSubmit = function() {
  2241. if (!Page.site_info.cert_user_id) {
  2242. Page.user.certSelect((function(_this) {
  2243. return function() {
  2244. return _this.handleSubmit();
  2245. };
  2246. })(this));
  2247. return false;
  2248. }
  2249. if (!this.form.validate()) {
  2250. return false;
  2251. }
  2252. this.form.data["address"] = this.form.data["address"].match(/([A-Za-z0-9]{26,35}|[A-Za-z0-9\.-]{2,99}\.bit)(.*)/)[0];
  2253. this.submitting = true;
  2254. Page.user.getData((function(_this) {
  2255. return function(data) {
  2256. var row_site;
  2257. row_site = _this.form.data;
  2258. row_site.date_added = Time.timestamp();
  2259. row_site.site_id = row_site.date_added;
  2260. data.site.push(row_site);
  2261. return Page.user.save(data, function(res) {
  2262. if (res === "ok") {
  2263. _this.close();
  2264. Page.head.active = "new";
  2265. Page.setUrl("?Category:" + row_site.category);
  2266. return setTimeout((function() {
  2267. _this.submitting = false;
  2268. _this.form.reset();
  2269. return Page.site_lists.update();
  2270. }), 1000);
  2271. } else {
  2272. return _this.submitting = false;
  2273. }
  2274. });
  2275. };
  2276. })(this));
  2277. return false;
  2278. };
  2279. SiteAdd.prototype.updateDb = function() {
  2280. this.site_db = {};
  2281. return Page.cmd("dbQuery", "SELECT * FROM site", (function(_this) {
  2282. return function(res) {
  2283. var address, i, len, ref, results, row;
  2284. results = [];
  2285. for (i = 0, len = res.length; i < len; i++) {
  2286. row = res[i];
  2287. address = (ref = row.address.match(/([A-Za-z0-9]{26,35}|[A-Za-z0-9\.-]{2,99}\.bit)(.*)/)) != null ? ref[0] : void 0;
  2288. address = address.replace(/\/.*/, "");
  2289. results.push(_this.site_db[address.toLowerCase()] = row);
  2290. }
  2291. return results;
  2292. };
  2293. })(this));
  2294. };
  2295. SiteAdd.prototype.shouldBeUniqueSite = function(value) {
  2296. var address, site;
  2297. address = value.match(/([A-Za-z0-9]{26,35}|[A-Za-z0-9\.-]{2,99}\.bit)(.*)/)[0];
  2298. address = address.replace(/\/.*/, "");
  2299. site = this.site_db[address.toLowerCase()];
  2300. this.log(address, this.site_db);
  2301. if (site) {
  2302. return "This site is already submitted as " + site.title + "!";
  2303. } else {
  2304. return null;
  2305. }
  2306. };
  2307. SiteAdd.prototype.close = function() {
  2308. Page.site_lists.state = null;
  2309. return Page.projector.scheduleRender();
  2310. };
  2311. SiteAdd.prototype.render = function() {
  2312. return h("div.form.form-siteadd", {
  2313. updateAnimation: Animation.height,
  2314. classes: {
  2315. hidden: Page.site_lists.state !== "siteadd"
  2316. }
  2317. }, [
  2318. h("div.formfield", this.form.h("label.title", {
  2319. "for": "address"
  2320. }, "Address"), this.form.h("input.text", {
  2321. type: "text",
  2322. name: "address",
  2323. placeholder: "e.g. http://127.0.0.1:43110/1BLogC9LN4oPDcruNz3qo1ysa133E9AGg8",
  2324. required: true,
  2325. validate: [this.form.shouldBeZite, this.shouldBeUniqueSite]
  2326. })), h("div.formfield", this.form.h("label.title", {
  2327. "for": "title"
  2328. }, "Title"), this.form.h("input.text", {
  2329. type: "text",
  2330. name: "title",
  2331. placeholder: "e.g. ZeroBlog",
  2332. required: true
  2333. })), h("div.formfield", this.form.h("label.title", {
  2334. "for": "language"
  2335. }, "Language"), this.form.h("div.radiogroup.radiogroup-lang", {
  2336. name: "language",
  2337. value: this.form.data.language,
  2338. required: true
  2339. }, [
  2340. Page.languages.map((function(_this) {
  2341. return function(lang) {
  2342. return [
  2343. h("a.radio", {
  2344. key: lang,
  2345. href: "#" + lang,
  2346. onclick: _this.handleRadioLangClick,
  2347. value: lang,
  2348. classes: {
  2349. active: _this.form.data.language === lang
  2350. }
  2351. }, lang), " "
  2352. ];
  2353. };
  2354. })(this))
  2355. ])), h("div.formfield", this.form.h("label.title", {
  2356. "for": "category"
  2357. }, "Category"), this.form.h("div.radiogroup", {
  2358. name: "category",
  2359. value: this.form.data.category,
  2360. required: true
  2361. }, Page.categories.map((function(_this) {
  2362. return function(arg) {
  2363. var category, id;
  2364. id = arg[0], category = arg[1];
  2365. return [
  2366. h("a.radio", {
  2367. key: id,
  2368. href: "#" + id,
  2369. onclick: _this.handleRadioCategoryClick,
  2370. value: id,
  2371. classes: {
  2372. active: _this.form.data.category === id
  2373. }
  2374. }, category), " "
  2375. ];
  2376. };
  2377. })(this)))), h("div.formfield", this.form.h("label.title", {
  2378. "for": "description"
  2379. }, "Description"), this.form.h("input.text", {
  2380. type: "text",
  2381. name: "description",
  2382. placeholder: "e.g. ZeroNet changelog and related informations",
  2383. required: true
  2384. })), h("a.button.button-submit", {
  2385. href: "#Submit",
  2386. onclick: this.handleSubmit
  2387. }, "Submit")
  2388. ]);
  2389. };
  2390. return SiteAdd;
  2391. })(Class);
  2392. window.SiteAdd = SiteAdd;
  2393. }).call(this);
  2394. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/SiteList.coffee ---- */
  2395. (function() {
  2396. var SiteList,
  2397. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2398. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2399. hasProp = {}.hasOwnProperty;
  2400. SiteList = (function(superClass) {
  2401. extend(SiteList, superClass);
  2402. function SiteList(row) {
  2403. this.row = row;
  2404. this.handleMoreClick = bind(this.handleMoreClick, this);
  2405. this.item_list = new ItemList(Site, "site_id");
  2406. this.sites = this.item_list.items;
  2407. this.item_list.sync(this.row.sites);
  2408. this.limit = 10;
  2409. }
  2410. SiteList.prototype.isHidden = function() {
  2411. if (Page.site_lists.filter_category === null) {
  2412. return false;
  2413. } else {
  2414. return Page.site_lists.filter_category !== this.row.id;
  2415. }
  2416. };
  2417. SiteList.prototype.handleMoreClick = function() {
  2418. this.limit += 20;
  2419. this.nolimit = true;
  2420. return false;
  2421. };
  2422. SiteList.prototype.render = function(i) {
  2423. var clear, limit;
  2424. if (this.row.title === "Other" && Page.site_lists.filter_category !== this.row.id && Page.site_lists.cols === 3) {
  2425. return this.renderWide(i);
  2426. }
  2427. if (Page.site_lists.filter_category === this.row.id) {
  2428. limit = 100;
  2429. } else {
  2430. limit = this.limit;
  2431. }
  2432. if (this.sites.length === 0) {
  2433. clear = false;
  2434. } else {
  2435. clear = i % Page.site_lists.cols === 1;
  2436. }
  2437. return h("div.sitelist", {
  2438. key: this.row.id,
  2439. classes: {
  2440. empty: this.sites.length === 0,
  2441. hidden: this.isHidden(),
  2442. selected: Page.site_lists.filter_category === this.row.id,
  2443. nolimit: this.nolimit,
  2444. clear: clear
  2445. }
  2446. }, [
  2447. h("a.categoryname", {
  2448. href: "?Category:" + this.row.id + ":" + (Text.toUrl(this.row.title)),
  2449. onclick: Page.handleLinkClick
  2450. }, this.row.title), h("div.sites", [
  2451. this.sites.slice(0, +(limit - 1) + 1 || 9e9).map(function(item) {
  2452. return item.render();
  2453. }), this.sites.length > limit ? h("a.more", {
  2454. href: "?Category:" + this.row.id + ":" + (Text.toUrl(this.row.title)),
  2455. onclick: this.handleMoreClick,
  2456. enterAnimation: Animation.slideDown,
  2457. exitAnimation: Animation.slideUp
  2458. }, "Show more...") : void 0
  2459. ])
  2460. ]);
  2461. };
  2462. SiteList.prototype.renderWide = function(i) {
  2463. var clear, cols, limit;
  2464. cols = [0, 1, 2];
  2465. clear = false;
  2466. limit = this.limit;
  2467. if (this.sites.length < limit * 3) {
  2468. limit = Math.ceil(this.sites.length / 3);
  2469. }
  2470. return h("div.sitelist-wide", [
  2471. cols.map((function(_this) {
  2472. return function(col) {
  2473. return h("div.sitelist.col-" + col, {
  2474. key: _this.row.id,
  2475. classes: {
  2476. empty: _this.sites.length === 0,
  2477. hidden: _this.isHidden(),
  2478. selected: Page.site_lists.filter_category === _this.row.id,
  2479. clear: clear
  2480. }
  2481. }, [
  2482. h("a.categoryname", {
  2483. href: "?Category:" + _this.row.id + ":" + (Text.toUrl(_this.row.title)),
  2484. onclick: Page.handleLinkClick
  2485. }, _this.row.title), h("div.sites", [
  2486. _this.sites.slice(0 + col * limit, +(col * limit + limit - 1) + 1 || 9e9).map(function(item) {
  2487. return item.render();
  2488. })
  2489. ])
  2490. ]);
  2491. };
  2492. })(this)), this.sites.length > limit * cols.length ? h("a.more", {
  2493. href: "?Category:" + this.row.id + ":" + (Text.toUrl(this.row.title)),
  2494. onclick: this.handleMoreClick,
  2495. enterAnimation: Animation.slideDown
  2496. }, "Show more...") : void 0
  2497. ]);
  2498. };
  2499. return SiteList;
  2500. })(Class);
  2501. window.SiteList = SiteList;
  2502. }).call(this);
  2503. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/SiteLists.coffee ---- */
  2504. (function() {
  2505. var SiteLists,
  2506. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2507. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2508. hasProp = {}.hasOwnProperty;
  2509. SiteLists = (function(superClass) {
  2510. extend(SiteLists, superClass);
  2511. function SiteLists() {
  2512. this.render = bind(this.render, this);
  2513. this.getVisibleSiteLists = bind(this.getVisibleSiteLists, this);
  2514. this.setFilterCategory = bind(this.setFilterCategory, this);
  2515. this.formatFilterTitle = bind(this.formatFilterTitle, this);
  2516. this.handleSiteAddClick = bind(this.handleSiteAddClick, this);
  2517. this.handleFiltersClick = bind(this.handleFiltersClick, this);
  2518. this.renderFilterLanguage = bind(this.renderFilterLanguage, this);
  2519. this.handleFilterLanguageClick = bind(this.handleFilterLanguageClick, this);
  2520. this.menu_filters = new Menu();
  2521. this.state = null;
  2522. this.filter_lang = {};
  2523. this.site_add = new SiteAdd();
  2524. this.site_lists = [];
  2525. this.site_lists_db = {};
  2526. this.need_update = false;
  2527. this.loaded = false;
  2528. this.num_total = null;
  2529. Page.on_site_info.then((function(_this) {
  2530. return function() {
  2531. return Page.on_local_storage.then(function() {
  2532. var id, j, len, ref, ref1, site_list, title;
  2533. _this.filter_lang = Page.local_storage.filter_lang;
  2534. ref = Page.site_info.content.settings.categories;
  2535. for (j = 0, len = ref.length; j < len; j++) {
  2536. ref1 = ref[j], id = ref1[0], title = ref1[1];
  2537. site_list = new SiteList({
  2538. id: id,
  2539. title: title,
  2540. sites: []
  2541. });
  2542. _this.site_lists_db[id] = site_list;
  2543. _this.site_lists.push(site_list);
  2544. }
  2545. return _this.update();
  2546. });
  2547. };
  2548. })(this));
  2549. window.onresize = (function(_this) {
  2550. return function() {
  2551. if (window.innerWidth < 720) {
  2552. _this.cols = 1;
  2553. } else if (window.innerWidth < 1200) {
  2554. _this.cols = 2;
  2555. } else {
  2556. _this.cols = 3;
  2557. }
  2558. _this.log("Cols: " + _this.cols);
  2559. return Page.projector.scheduleRender();
  2560. };
  2561. })(this);
  2562. window.onresize();
  2563. }
  2564. SiteLists.prototype.update = function() {
  2565. var filters, lang, order, query;
  2566. if (Page.head.active === "new") {
  2567. order = "date_added DESC";
  2568. } else {
  2569. order = "MIN(200, peers) + star * 20 DESC, title";
  2570. }
  2571. filters = [];
  2572. if (!isEmpty(this.filter_lang)) {
  2573. filters.push("language IN " + Text.sqlIn((function() {
  2574. var results;
  2575. results = [];
  2576. for (lang in this.filter_lang) {
  2577. results.push(lang);
  2578. }
  2579. return results;
  2580. }).call(this)));
  2581. }
  2582. query = "SELECT site.*, json.*, COUNT(site_star.site_uri) AS star, site_stat.*\nFROM site\nLEFT JOIN json USING (json_id)\nLEFT JOIN site_star ON (site_star.site_uri = json.directory || \"_\" || site.site_id)\nLEFT JOIN site_stat ON (site_stat.site_uri = json.directory || \"_\" || site.site_id)\n" + (filters.length ? "WHERE " + filters.join(" AND ") : "") + "\nGROUP BY site.json_id, site_id\nORDER BY " + order;
  2583. this.logStart("Sites");
  2584. return Page.cmd("dbQuery", query, (function(_this) {
  2585. return function(rows) {
  2586. var category, j, len, name, ref, row, site_list, sites_db;
  2587. sites_db = {};
  2588. for (j = 0, len = rows.length; j < len; j++) {
  2589. row = rows[j];
  2590. if (sites_db[name = row["category"]] == null) {
  2591. sites_db[name] = [];
  2592. }
  2593. sites_db[row["category"]].push(row);
  2594. }
  2595. ref = _this.site_lists_db;
  2596. for (category in ref) {
  2597. site_list = ref[category];
  2598. site_list.item_list.sync(sites_db[category] || []);
  2599. }
  2600. _this.loaded = true;
  2601. _this.num_total = rows.length;
  2602. _this.logEnd("Sites", "found: " + _this.num_total);
  2603. Page.on_loaded.resolve();
  2604. return Page.projector.scheduleRender();
  2605. };
  2606. })(this));
  2607. };
  2608. SiteLists.prototype.handleFilterLanguageClick = function(e) {
  2609. var key, value;
  2610. value = e.currentTarget.value;
  2611. if (value === "all") {
  2612. for (key in this.filter_lang) {
  2613. delete this.filter_lang[key];
  2614. }
  2615. } else if (this.filter_lang[value]) {
  2616. delete this.filter_lang[value];
  2617. } else {
  2618. this.filter_lang[value] = true;
  2619. }
  2620. Page.saveLocalStorage();
  2621. Page.projector.scheduleRender();
  2622. this.update();
  2623. return false;
  2624. };
  2625. SiteLists.prototype.renderFilterLanguage = function() {
  2626. var lang;
  2627. return h("div.menu-radio", h("div", "Site languages: "), h("a.all", {
  2628. href: "#all",
  2629. onclick: this.handleFilterLanguageClick,
  2630. value: "all",
  2631. classes: {
  2632. selected: isEmpty(this.filter_lang)
  2633. }
  2634. }, "Show all"), (function() {
  2635. var j, len, ref, results;
  2636. ref = Page.languages;
  2637. results = [];
  2638. for (j = 0, len = ref.length; j < len; j++) {
  2639. lang = ref[j];
  2640. results.push([
  2641. h("a", {
  2642. href: "#" + lang,
  2643. onclick: this.handleFilterLanguageClick,
  2644. value: lang,
  2645. classes: {
  2646. selected: this.filter_lang[lang],
  2647. long: lang.length > 2
  2648. }
  2649. }, lang), " "
  2650. ]);
  2651. }
  2652. return results;
  2653. }).call(this));
  2654. };
  2655. SiteLists.prototype.handleFiltersClick = function() {
  2656. this.menu_filters.items = [];
  2657. this.menu_filters.items.push([this.renderFilterLanguage, null]);
  2658. if (this.menu_filters.visible) {
  2659. this.menu_filters.hide();
  2660. } else {
  2661. this.menu_filters.show();
  2662. }
  2663. return false;
  2664. };
  2665. SiteLists.prototype.handleSiteAddClick = function() {
  2666. if (this.state === "siteadd") {
  2667. this.state = null;
  2668. } else {
  2669. this.state = "siteadd";
  2670. }
  2671. this.site_add.updateDb();
  2672. return false;
  2673. };
  2674. SiteLists.prototype.formatFilterTitle = function() {
  2675. var _, lang;
  2676. if (isEmpty(this.filter_lang)) {
  2677. return "None";
  2678. } else {
  2679. return ((function() {
  2680. var ref, results;
  2681. ref = this.filter_lang;
  2682. results = [];
  2683. for (lang in ref) {
  2684. _ = ref[lang];
  2685. results.push(lang);
  2686. }
  2687. return results;
  2688. }).call(this)).join(", ");
  2689. }
  2690. };
  2691. SiteLists.prototype.setFilterCategory = function(filter_category) {
  2692. this.filter_category = filter_category;
  2693. if (this.loaded) {
  2694. return setTimeout(((function(_this) {
  2695. return function() {
  2696. return Page.on_loaded.resolve();
  2697. };
  2698. })(this)), 600);
  2699. }
  2700. };
  2701. SiteLists.prototype.getVisibleSiteLists = function() {
  2702. if (this.filter_category) {
  2703. return [this.site_lists_db[this.filter_category]];
  2704. } else {
  2705. return this.site_lists;
  2706. }
  2707. };
  2708. SiteLists.prototype.render = function() {
  2709. var i, j, lang, len, num_found, ref, ref1, site_list;
  2710. if (this.need_update) {
  2711. this.need_update = false;
  2712. this.update();
  2713. }
  2714. i = 0;
  2715. num_found = 0;
  2716. ref = this.site_lists;
  2717. for (j = 0, len = ref.length; j < len; j++) {
  2718. site_list = ref[j];
  2719. if (!site_list.isHidden()) {
  2720. num_found += site_list.sites.length;
  2721. }
  2722. }
  2723. return h("div#SiteLists", {
  2724. classes: {
  2725. "state-siteadd": this.state === "siteadd"
  2726. }
  2727. }, this.loaded ? h("div.sitelists-right", [
  2728. ((ref1 = Page.site_info) != null ? ref1.cert_user_id : void 0) ? h("a.certselect.right-link", {
  2729. href: "#Select",
  2730. onclick: Page.user.certSelect
  2731. }, [h("span.symbol", "⎔"), h("span.title", "User: " + Page.site_info.cert_user_id)]) : void 0, h("a.filter.right-link", {
  2732. href: "#Filters",
  2733. onmousedown: this.handleFiltersClick,
  2734. onclick: Page.returnFalse
  2735. }, [h("span.symbol", "◇"), h("span.title", "Filter: " + this.formatFilterTitle())]), this.menu_filters.render(".filter"), h("a.siteadd.right-link", {
  2736. href: "#",
  2737. onclick: this.handleSiteAddClick
  2738. }, [h("span.symbol", "+"), h("span.title", "Submit new site")])
  2739. ]) : void 0, this.site_add.render(), num_found === 0 && !isEmpty(this.filter_lang) ? h("h1.empty", {
  2740. enterAnimation: Animation.slideDown,
  2741. exitAnimation: Animation.slideUp
  2742. }, "No sites found for languages: " + (((function() {
  2743. var results;
  2744. results = [];
  2745. for (lang in this.filter_lang) {
  2746. results.push(lang);
  2747. }
  2748. return results;
  2749. }).call(this)).join(', '))) : void 0, this.loaded ? h("div.sitelists", this.site_lists.map(function(site_list) {
  2750. if (site_list.sites.length) {
  2751. i++;
  2752. num_found += site_list.sites.length;
  2753. }
  2754. return site_list.render(i);
  2755. })) : void 0, h("div.clear", " "));
  2756. };
  2757. SiteLists.prototype.onSiteInfo = function(site_info) {
  2758. var action, inner_path, ref;
  2759. if (site_info.event) {
  2760. ref = site_info.event, action = ref[0], inner_path = ref[1];
  2761. if (action === "file_done" && inner_path.endsWith("json")) {
  2762. return RateLimit(1000, (function(_this) {
  2763. return function() {
  2764. _this.need_update = true;
  2765. return Page.projector.scheduleRender();
  2766. };
  2767. })(this));
  2768. }
  2769. }
  2770. };
  2771. return SiteLists;
  2772. })(Class);
  2773. window.SiteLists = SiteLists;
  2774. }).call(this);
  2775. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/User.coffee ---- */
  2776. (function() {
  2777. var User,
  2778. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2779. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2780. hasProp = {}.hasOwnProperty;
  2781. User = (function(superClass) {
  2782. extend(User, superClass);
  2783. function User(auth_address) {
  2784. this.onSiteInfo = bind(this.onSiteInfo, this);
  2785. this.certSelect = bind(this.certSelect, this);
  2786. this.starred = {};
  2787. if (auth_address) {
  2788. this.setAuthAddress(auth_address);
  2789. }
  2790. }
  2791. User.prototype.setAuthAddress = function(auth_address) {
  2792. this.auth_address = auth_address;
  2793. if (Page.site_info.auth_address === auth_address) {
  2794. return this.updateStarred();
  2795. }
  2796. };
  2797. User.prototype.updateStarred = function(cb) {
  2798. this.starred = {};
  2799. return Page.cmd("dbQuery", [
  2800. "SELECT site_star.* FROM json LEFT JOIN site_star USING (json_id) WHERE ?", {
  2801. directory: "" + this.auth_address
  2802. }
  2803. ], (function(_this) {
  2804. return function(res) {
  2805. var i, len, row;
  2806. for (i = 0, len = res.length; i < len; i++) {
  2807. row = res[i];
  2808. _this.starred[row["site_uri"]] = true;
  2809. }
  2810. if (typeof cb === "function") {
  2811. cb();
  2812. }
  2813. return Page.projector.scheduleRender();
  2814. };
  2815. })(this));
  2816. };
  2817. User.prototype.getPath = function() {
  2818. return "data/users/" + this.auth_address;
  2819. };
  2820. User.prototype.getDefaultData = function() {
  2821. return {
  2822. "site": [],
  2823. "site_star": {},
  2824. "site_comment": []
  2825. };
  2826. };
  2827. User.prototype.getData = function(cb) {
  2828. return Page.cmd("fileGet", [this.getPath() + "/data.json", false], (function(_this) {
  2829. return function(data) {
  2830. data = JSON.parse(data);
  2831. if (data == null) {
  2832. data = _this.getDefaultData();
  2833. }
  2834. return cb(data);
  2835. };
  2836. })(this));
  2837. };
  2838. User.prototype.certSelect = function(cb) {
  2839. return Page.cmd("certSelect", {
  2840. "accepted_domains": ["zeroid.bit"]
  2841. }, (function(_this) {
  2842. return function(res) {
  2843. _this.log("certSelected");
  2844. return typeof cb === "function" ? cb(res) : void 0;
  2845. };
  2846. })(this));
  2847. };
  2848. User.prototype.onSiteInfo = function(site_info) {
  2849. var ref;
  2850. if (((ref = site_info.event) != null ? ref[0] : void 0) === "cert_changed") {
  2851. this.setAuthAddress(site_info.auth_address);
  2852. return Page.projector.scheduleRender();
  2853. }
  2854. };
  2855. User.prototype.save = function(data, cb) {
  2856. return Page.cmd("fileWrite", [this.getPath() + "/data.json", Text.fileEncode(data)], (function(_this) {
  2857. return function(res_write) {
  2858. return Page.cmd("siteSign", {
  2859. "inner_path": _this.getPath() + "/data.json"
  2860. }, function(res_sign) {
  2861. if (typeof cb === "function") {
  2862. cb(res_sign);
  2863. }
  2864. return Page.cmd("sitePublish", {
  2865. "inner_path": _this.getPath() + "/content.json",
  2866. sign: false
  2867. }, function(res_publish) {
  2868. return _this.log("Save result", res_write, res_sign, res_publish);
  2869. });
  2870. });
  2871. };
  2872. })(this));
  2873. };
  2874. return User;
  2875. })(Class);
  2876. window.User = User;
  2877. }).call(this);
  2878. /* ---- /1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB/js/ZeroSites.coffee ---- */
  2879. (function() {
  2880. var ZeroSites,
  2881. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2882. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  2883. hasProp = {}.hasOwnProperty;
  2884. window.h = maquette.h;
  2885. ZeroSites = (function(superClass) {
  2886. extend(ZeroSites, superClass);
  2887. function ZeroSites() {
  2888. this.reloadServerInfo = bind(this.reloadServerInfo, this);
  2889. this.reloadSiteInfo = bind(this.reloadSiteInfo, this);
  2890. this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
  2891. this.handleLinkClick = bind(this.handleLinkClick, this);
  2892. return ZeroSites.__super__.constructor.apply(this, arguments);
  2893. }
  2894. ZeroSites.prototype.init = function() {
  2895. this.params = {};
  2896. this.site_info = null;
  2897. this.server_info = null;
  2898. this.history_state = {};
  2899. this.on_site_info = new Promise();
  2900. this.on_local_storage = new Promise();
  2901. this.on_loaded = new Promise();
  2902. this.user = new User();
  2903. this.on_site_info.then((function(_this) {
  2904. return function() {
  2905. return _this.user.setAuthAddress(_this.site_info.auth_address);
  2906. };
  2907. })(this));
  2908. this.local_storage = null;
  2909. this.languages = [];
  2910. this.categories = [];
  2911. return this.on_site_info.then((function(_this) {
  2912. return function() {
  2913. _this.languages = _this.site_info.content.settings.languages;
  2914. return _this.categories = _this.site_info.content.settings.categories;
  2915. };
  2916. })(this));
  2917. };
  2918. ZeroSites.prototype.createProjector = function() {
  2919. var url;
  2920. this.projector = maquette.createProjector();
  2921. this.head = new Head();
  2922. this.site_lists = new SiteLists();
  2923. if (base.href.indexOf("?") === -1) {
  2924. this.route("");
  2925. } else {
  2926. url = base.href.replace(/.*?\?/, "");
  2927. this.route(url);
  2928. this.history_state["url"] = url;
  2929. }
  2930. this.on_loaded.then((function(_this) {
  2931. return function() {
  2932. _this.log("onloaded");
  2933. return window.requestAnimationFrame(function() {
  2934. return document.body.className = "loaded";
  2935. });
  2936. };
  2937. })(this));
  2938. this.projector.replace($("#Head"), this.head.render);
  2939. this.projector.replace($("#SiteLists"), this.site_lists.render);
  2940. this.loadLocalStorage();
  2941. return setInterval((function() {
  2942. return Page.projector.scheduleRender();
  2943. }), 60 * 1000);
  2944. };
  2945. ZeroSites.prototype.setFormEdit = function(form_edit) {
  2946. form_edit.hidden = false;
  2947. return this.projector.replace($("#FormEdit"), form_edit.render);
  2948. };
  2949. ZeroSites.prototype.route = function(query) {
  2950. var page, param, ref;
  2951. this.params = Text.parseQuery(query);
  2952. ref = this.params.url.split(":"), page = ref[0], param = ref[1];
  2953. this.content = this.site_lists;
  2954. if (page === "Category") {
  2955. this.site_lists.setFilterCategory(parseInt(param));
  2956. } else {
  2957. this.site_lists.setFilterCategory(null);
  2958. }
  2959. Page.projector.scheduleRender();
  2960. return this.log("Route", page, param);
  2961. };
  2962. ZeroSites.prototype.setUrl = function(url, mode) {
  2963. if (mode == null) {
  2964. mode = "push";
  2965. }
  2966. url = url.replace(/.*?\?/, "");
  2967. this.log("setUrl", this.history_state["url"], "->", url);
  2968. if (this.history_state["url"] === url) {
  2969. this.content.update();
  2970. return false;
  2971. }
  2972. this.history_state["url"] = url;
  2973. if (mode === "replace") {
  2974. this.cmd("wrapperReplaceState", [this.history_state, "", url]);
  2975. } else {
  2976. this.cmd("wrapperPushState", [this.history_state, "", url]);
  2977. }
  2978. this.route(url);
  2979. return false;
  2980. };
  2981. ZeroSites.prototype.handleLinkClick = function(e) {
  2982. if (e.which === 2) {
  2983. return true;
  2984. } else {
  2985. this.log("save scrollTop", window.pageYOffset);
  2986. this.history_state["scrollTop"] = window.pageYOffset;
  2987. this.cmd("wrapperReplaceState", [this.history_state, null]);
  2988. if (document.body.scrollTop > 100) {
  2989. anime({
  2990. targets: document.body,
  2991. scrollTop: 0,
  2992. easing: "easeOutCubic",
  2993. duration: 300
  2994. });
  2995. }
  2996. this.history_state["scrollTop"] = 0;
  2997. this.on_loaded.resolved = false;
  2998. document.body.className = "";
  2999. this.setUrl(e.currentTarget.search);
  3000. return false;
  3001. }
  3002. };
  3003. ZeroSites.prototype.createUrl = function(key, val) {
  3004. var params, vals;
  3005. params = JSON.parse(JSON.stringify(this.params));
  3006. if (typeof key === "Object") {
  3007. vals = key;
  3008. for (key in keys) {
  3009. val = keys[key];
  3010. params[key] = val;
  3011. }
  3012. } else {
  3013. params[key] = val;
  3014. }
  3015. return "?" + Text.queryEncode(params);
  3016. };
  3017. ZeroSites.prototype.loadLocalStorage = function() {
  3018. return this.on_site_info.then((function(_this) {
  3019. return function() {
  3020. _this.log("Loading localstorage");
  3021. return _this.cmd("wrapperGetLocalStorage", [], function(local_storage) {
  3022. var base1;
  3023. _this.local_storage = local_storage;
  3024. _this.log("Loaded localstorage");
  3025. if (_this.local_storage == null) {
  3026. _this.local_storage = {};
  3027. }
  3028. if ((base1 = _this.local_storage).filter_lang == null) {
  3029. base1.filter_lang = {};
  3030. }
  3031. return _this.on_local_storage.resolve();
  3032. });
  3033. };
  3034. })(this));
  3035. };
  3036. ZeroSites.prototype.saveLocalStorage = function(cb) {
  3037. if (this.local_storage) {
  3038. return this.cmd("wrapperSetLocalStorage", this.local_storage, (function(_this) {
  3039. return function(res) {
  3040. if (cb) {
  3041. return cb(res);
  3042. }
  3043. };
  3044. })(this));
  3045. }
  3046. };
  3047. ZeroSites.prototype.onOpenWebsocket = function(e) {
  3048. this.reloadSiteInfo();
  3049. return this.reloadServerInfo();
  3050. };
  3051. ZeroSites.prototype.reloadSiteInfo = function() {
  3052. return this.cmd("siteInfo", {}, (function(_this) {
  3053. return function(site_info) {
  3054. return _this.setSiteInfo(site_info);
  3055. };
  3056. })(this));
  3057. };
  3058. ZeroSites.prototype.reloadServerInfo = function() {
  3059. return this.cmd("serverInfo", {}, (function(_this) {
  3060. return function(server_info) {
  3061. return _this.setServerInfo(server_info);
  3062. };
  3063. })(this));
  3064. };
  3065. ZeroSites.prototype.onRequest = function(cmd, params) {
  3066. if (cmd === "setSiteInfo") {
  3067. return this.setSiteInfo(params);
  3068. } else if (cmd === "wrapperPopState") {
  3069. this.log("wrapperPopState", params);
  3070. if (params.state) {
  3071. if (!params.state.url) {
  3072. params.state.url = params.href.replace(/.*\?/, "");
  3073. }
  3074. this.on_loaded.resolved = false;
  3075. document.body.className = "";
  3076. window.scroll(window.pageXOffset, params.state.scrollTop || 0);
  3077. return this.route(params.state.url || "");
  3078. }
  3079. } else {
  3080. return this.log("Unknown command", cmd, params);
  3081. }
  3082. };
  3083. ZeroSites.prototype.setSiteInfo = function(site_info) {
  3084. this.site_info = site_info;
  3085. this.on_site_info.resolve();
  3086. this.site_lists.onSiteInfo(site_info);
  3087. this.user.onSiteInfo(site_info);
  3088. return this.projector.scheduleRender();
  3089. };
  3090. ZeroSites.prototype.setServerInfo = function(server_info) {
  3091. this.server_info = server_info;
  3092. return this.projector.scheduleRender();
  3093. };
  3094. ZeroSites.prototype.returnFalse = function() {
  3095. return false;
  3096. };
  3097. return ZeroSites;
  3098. })(ZeroFrame);
  3099. window.Page = new ZeroSites();
  3100. window.Page.createProjector();
  3101. }).call(this);