all.js 260 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802
  1. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/lib/Class.coffee ---- */
  2. (function() {
  3. var Class,
  4. slice = [].slice;
  5. Class = (function() {
  6. function Class() {}
  7. Class.prototype.trace = true;
  8. Class.prototype.log = function() {
  9. var args;
  10. args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  11. if (!this.trace) {
  12. return;
  13. }
  14. if (typeof console === 'undefined') {
  15. return;
  16. }
  17. args.unshift("[" + this.constructor.name + "]");
  18. console.log.apply(console, args);
  19. return this;
  20. };
  21. Class.prototype.logStart = function() {
  22. var args, name;
  23. name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  24. if (!this.trace) {
  25. return;
  26. }
  27. this.logtimers || (this.logtimers = {});
  28. this.logtimers[name] = +(new Date);
  29. if (args.length > 0) {
  30. this.log.apply(this, ["" + name].concat(slice.call(args), ["(started)"]));
  31. }
  32. return this;
  33. };
  34. Class.prototype.logEnd = function() {
  35. var args, ms, name;
  36. name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  37. ms = +(new Date) - this.logtimers[name];
  38. this.log.apply(this, ["" + name].concat(slice.call(args), ["(Done in " + ms + "ms)"]));
  39. return this;
  40. };
  41. return Class;
  42. })();
  43. window.Class = Class;
  44. }).call(this);
  45. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/lib/Promise.coffee ---- */
  46. (function() {
  47. var Promise,
  48. slice = [].slice;
  49. Promise = (function() {
  50. Promise.when = function() {
  51. var args, fn, i, len, num_uncompleted, promise, task, task_id, tasks;
  52. tasks = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  53. num_uncompleted = tasks.length;
  54. args = new Array(num_uncompleted);
  55. promise = new Promise();
  56. fn = function(task_id) {
  57. return task.then(function() {
  58. args[task_id] = Array.prototype.slice.call(arguments);
  59. num_uncompleted--;
  60. if (num_uncompleted === 0) {
  61. return promise.complete.apply(promise, args);
  62. }
  63. });
  64. };
  65. for (task_id = i = 0, len = tasks.length; i < len; task_id = ++i) {
  66. task = tasks[task_id];
  67. fn(task_id);
  68. }
  69. return promise;
  70. };
  71. function Promise() {
  72. this.resolved = false;
  73. this.end_promise = null;
  74. this.result = null;
  75. this.callbacks = [];
  76. }
  77. Promise.prototype.resolve = function() {
  78. var back, callback, i, len, ref;
  79. if (this.resolved) {
  80. return false;
  81. }
  82. this.resolved = true;
  83. this.data = arguments;
  84. if (!arguments.length) {
  85. this.data = [true];
  86. }
  87. this.result = this.data[0];
  88. ref = this.callbacks;
  89. for (i = 0, len = ref.length; i < len; i++) {
  90. callback = ref[i];
  91. back = callback.apply(callback, this.data);
  92. }
  93. if (this.end_promise) {
  94. return this.end_promise.resolve(back);
  95. }
  96. };
  97. Promise.prototype.fail = function() {
  98. return this.resolve(false);
  99. };
  100. Promise.prototype.then = function(callback) {
  101. if (this.resolved === true) {
  102. callback.apply(callback, this.data);
  103. return;
  104. }
  105. this.callbacks.push(callback);
  106. return this.end_promise = new Promise();
  107. };
  108. return Promise;
  109. })();
  110. window.Promise = Promise;
  111. /*
  112. s = Date.now()
  113. log = (text) ->
  114. console.log Date.now()-s, Array.prototype.slice.call(arguments).join(", ")
  115. log "Started"
  116. cmd = (query) ->
  117. p = new Promise()
  118. setTimeout ( ->
  119. p.resolve query+" Result"
  120. ), 100
  121. return p
  122. back = cmd("SELECT * FROM message").then (res) ->
  123. log res
  124. return "Return from query"
  125. .then (res) ->
  126. log "Back then", res
  127. log "Query started", back
  128. */
  129. }).call(this);
  130. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/lib/Property.coffee ---- */
  131. (function() {
  132. Function.prototype.property = function(prop, desc) {
  133. return Object.defineProperty(this.prototype, prop, desc);
  134. };
  135. }).call(this);
  136. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/lib/Prototypes.coffee ---- */
  137. (function() {
  138. String.prototype.startsWith = function(s) {
  139. return this.slice(0, s.length) === s;
  140. };
  141. String.prototype.endsWith = function(s) {
  142. return s === '' || this.slice(-s.length) === s;
  143. };
  144. String.prototype.repeat = function(count) {
  145. return new Array(count + 1).join(this);
  146. };
  147. window.isEmpty = function(obj) {
  148. var key;
  149. for (key in obj) {
  150. return false;
  151. }
  152. return true;
  153. };
  154. }).call(this);
  155. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/lib/maquette.js ---- */
  156. (function (root, factory) {
  157. if (typeof define === 'function' && define.amd) {
  158. // AMD. Register as an anonymous module.
  159. define(['exports'], factory);
  160. } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
  161. // CommonJS
  162. factory(exports);
  163. } else {
  164. // Browser globals
  165. factory(root.maquette = {});
  166. }
  167. }(this, function (exports) {
  168. 'use strict';
  169. ;
  170. ;
  171. ;
  172. ;
  173. var NAMESPACE_W3 = 'http://www.w3.org/';
  174. var NAMESPACE_SVG = NAMESPACE_W3 + '2000/svg';
  175. var NAMESPACE_XLINK = NAMESPACE_W3 + '1999/xlink';
  176. // Utilities
  177. var emptyArray = [];
  178. var extend = function (base, overrides) {
  179. var result = {};
  180. Object.keys(base).forEach(function (key) {
  181. result[key] = base[key];
  182. });
  183. if (overrides) {
  184. Object.keys(overrides).forEach(function (key) {
  185. result[key] = overrides[key];
  186. });
  187. }
  188. return result;
  189. };
  190. // Hyperscript helper functions
  191. var same = function (vnode1, vnode2) {
  192. if (vnode1.vnodeSelector !== vnode2.vnodeSelector) {
  193. return false;
  194. }
  195. if (vnode1.properties && vnode2.properties) {
  196. if (vnode1.properties.key !== vnode2.properties.key) {
  197. return false;
  198. }
  199. return vnode1.properties.bind === vnode2.properties.bind;
  200. }
  201. return !vnode1.properties && !vnode2.properties;
  202. };
  203. var toTextVNode = function (data) {
  204. return {
  205. vnodeSelector: '',
  206. properties: undefined,
  207. children: undefined,
  208. text: data.toString(),
  209. domNode: null
  210. };
  211. };
  212. var appendChildren = function (parentSelector, insertions, main) {
  213. for (var i = 0; i < insertions.length; i++) {
  214. var item = insertions[i];
  215. if (Array.isArray(item)) {
  216. appendChildren(parentSelector, item, main);
  217. } else {
  218. if (item !== null && item !== undefined) {
  219. if (!item.hasOwnProperty('vnodeSelector')) {
  220. item = toTextVNode(item);
  221. }
  222. main.push(item);
  223. }
  224. }
  225. }
  226. };
  227. // Render helper functions
  228. var missingTransition = function () {
  229. throw new Error('Provide a transitions object to the projectionOptions to do animations');
  230. };
  231. var DEFAULT_PROJECTION_OPTIONS = {
  232. namespace: undefined,
  233. eventHandlerInterceptor: undefined,
  234. styleApplyer: function (domNode, styleName, value) {
  235. // Provides a hook to add vendor prefixes for browsers that still need it.
  236. domNode.style[styleName] = value;
  237. },
  238. transitions: {
  239. enter: missingTransition,
  240. exit: missingTransition
  241. }
  242. };
  243. var applyDefaultProjectionOptions = function (projectorOptions) {
  244. return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
  245. };
  246. var checkStyleValue = function (styleValue) {
  247. if (typeof styleValue !== 'string') {
  248. throw new Error('Style values must be strings');
  249. }
  250. };
  251. var setProperties = function (domNode, properties, projectionOptions) {
  252. if (!properties) {
  253. return;
  254. }
  255. var eventHandlerInterceptor = projectionOptions.eventHandlerInterceptor;
  256. var propNames = Object.keys(properties);
  257. var propCount = propNames.length;
  258. for (var i = 0; i < propCount; i++) {
  259. var propName = propNames[i];
  260. /* tslint:disable:no-var-keyword: edge case */
  261. var propValue = properties[propName];
  262. /* tslint:enable:no-var-keyword */
  263. if (propName === 'className') {
  264. throw new Error('Property "className" is not supported, use "class".');
  265. } else if (propName === 'class') {
  266. if (domNode.className) {
  267. // May happen if classes is specified before class
  268. domNode.className += ' ' + propValue;
  269. } else {
  270. domNode.className = propValue;
  271. }
  272. } else if (propName === 'classes') {
  273. // object with string keys and boolean values
  274. var classNames = Object.keys(propValue);
  275. var classNameCount = classNames.length;
  276. for (var j = 0; j < classNameCount; j++) {
  277. var className = classNames[j];
  278. if (propValue[className]) {
  279. domNode.classList.add(className);
  280. }
  281. }
  282. } else if (propName === 'styles') {
  283. // object with string keys and string (!) values
  284. var styleNames = Object.keys(propValue);
  285. var styleCount = styleNames.length;
  286. for (var j = 0; j < styleCount; j++) {
  287. var styleName = styleNames[j];
  288. var styleValue = propValue[styleName];
  289. if (styleValue) {
  290. checkStyleValue(styleValue);
  291. projectionOptions.styleApplyer(domNode, styleName, styleValue);
  292. }
  293. }
  294. } else if (propName === 'key') {
  295. continue;
  296. } else if (propValue === null || propValue === undefined) {
  297. continue;
  298. } else {
  299. var type = typeof propValue;
  300. if (type === 'function') {
  301. if (propName.lastIndexOf('on', 0) === 0) {
  302. if (eventHandlerInterceptor) {
  303. propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
  304. }
  305. if (propName === 'oninput') {
  306. (function () {
  307. // record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
  308. var oldPropValue = propValue;
  309. propValue = function (evt) {
  310. evt.target['oninput-value'] = evt.target.value;
  311. // may be HTMLTextAreaElement as well
  312. oldPropValue.apply(this, [evt]);
  313. };
  314. }());
  315. }
  316. domNode[propName] = propValue;
  317. }
  318. } else if (type === 'string' && propName !== 'value' && propName !== 'innerHTML') {
  319. if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
  320. domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
  321. } else {
  322. domNode.setAttribute(propName, propValue);
  323. }
  324. } else {
  325. domNode[propName] = propValue;
  326. }
  327. }
  328. }
  329. };
  330. var updateProperties = function (domNode, previousProperties, properties, projectionOptions) {
  331. if (!properties) {
  332. return;
  333. }
  334. var propertiesUpdated = false;
  335. var propNames = Object.keys(properties);
  336. var propCount = propNames.length;
  337. for (var i = 0; i < propCount; i++) {
  338. var propName = propNames[i];
  339. // assuming that properties will be nullified instead of missing is by design
  340. var propValue = properties[propName];
  341. var previousValue = previousProperties[propName];
  342. if (propName === 'class') {
  343. if (previousValue !== propValue) {
  344. throw new Error('"class" property may not be updated. Use the "classes" property for conditional css classes.');
  345. }
  346. } else if (propName === 'classes') {
  347. var classList = domNode.classList;
  348. var classNames = Object.keys(propValue);
  349. var classNameCount = classNames.length;
  350. for (var j = 0; j < classNameCount; j++) {
  351. var className = classNames[j];
  352. var on = !!propValue[className];
  353. var previousOn = !!previousValue[className];
  354. if (on === previousOn) {
  355. continue;
  356. }
  357. propertiesUpdated = true;
  358. if (on) {
  359. classList.add(className);
  360. } else {
  361. classList.remove(className);
  362. }
  363. }
  364. } else if (propName === 'styles') {
  365. var styleNames = Object.keys(propValue);
  366. var styleCount = styleNames.length;
  367. for (var j = 0; j < styleCount; j++) {
  368. var styleName = styleNames[j];
  369. var newStyleValue = propValue[styleName];
  370. var oldStyleValue = previousValue[styleName];
  371. if (newStyleValue === oldStyleValue) {
  372. continue;
  373. }
  374. propertiesUpdated = true;
  375. if (newStyleValue) {
  376. checkStyleValue(newStyleValue);
  377. projectionOptions.styleApplyer(domNode, styleName, newStyleValue);
  378. } else {
  379. projectionOptions.styleApplyer(domNode, styleName, '');
  380. }
  381. }
  382. } else {
  383. if (!propValue && typeof previousValue === 'string') {
  384. propValue = '';
  385. }
  386. if (propName === 'value') {
  387. if (domNode[propName] !== propValue && domNode['oninput-value'] !== propValue) {
  388. domNode[propName] = propValue;
  389. // Reset the value, even if the virtual DOM did not change
  390. domNode['oninput-value'] = undefined;
  391. }
  392. // else do not update the domNode, otherwise the cursor position would be changed
  393. if (propValue !== previousValue) {
  394. propertiesUpdated = true;
  395. }
  396. } else if (propValue !== previousValue) {
  397. var type = typeof propValue;
  398. if (type === 'function') {
  399. throw new Error('Functions may not be updated on subsequent renders (property: ' + propName + '). Hint: declare event handler functions outside the render() function.');
  400. }
  401. if (type === 'string' && propName !== 'innerHTML') {
  402. if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
  403. domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
  404. } else {
  405. domNode.setAttribute(propName, propValue);
  406. }
  407. } else {
  408. if (domNode[propName] !== propValue) {
  409. domNode[propName] = propValue;
  410. }
  411. }
  412. propertiesUpdated = true;
  413. }
  414. }
  415. }
  416. return propertiesUpdated;
  417. };
  418. var findIndexOfChild = function (children, sameAs, start) {
  419. if (sameAs.vnodeSelector !== '') {
  420. // Never scan for text-nodes
  421. for (var i = start; i < children.length; i++) {
  422. if (same(children[i], sameAs)) {
  423. return i;
  424. }
  425. }
  426. }
  427. return -1;
  428. };
  429. var nodeAdded = function (vNode, transitions) {
  430. if (vNode.properties) {
  431. var enterAnimation = vNode.properties.enterAnimation;
  432. if (enterAnimation) {
  433. if (typeof enterAnimation === 'function') {
  434. enterAnimation(vNode.domNode, vNode.properties);
  435. } else {
  436. transitions.enter(vNode.domNode, vNode.properties, enterAnimation);
  437. }
  438. }
  439. }
  440. };
  441. var nodeToRemove = function (vNode, transitions) {
  442. var domNode = vNode.domNode;
  443. if (vNode.properties) {
  444. var exitAnimation = vNode.properties.exitAnimation;
  445. if (exitAnimation) {
  446. domNode.style.pointerEvents = 'none';
  447. var removeDomNode = function () {
  448. if (domNode.parentNode) {
  449. domNode.parentNode.removeChild(domNode);
  450. }
  451. };
  452. if (typeof exitAnimation === 'function') {
  453. exitAnimation(domNode, removeDomNode, vNode.properties);
  454. return;
  455. } else {
  456. transitions.exit(vNode.domNode, vNode.properties, exitAnimation, removeDomNode);
  457. return;
  458. }
  459. }
  460. }
  461. if (domNode.parentNode) {
  462. domNode.parentNode.removeChild(domNode);
  463. }
  464. };
  465. var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, operation) {
  466. var childNode = childNodes[indexToCheck];
  467. if (childNode.vnodeSelector === '') {
  468. return; // Text nodes need not be distinguishable
  469. }
  470. var properties = childNode.properties;
  471. var key = properties ? properties.key === undefined ? properties.bind : properties.key : undefined;
  472. if (!key) {
  473. for (var i = 0; i < childNodes.length; i++) {
  474. if (i !== indexToCheck) {
  475. var node = childNodes[i];
  476. if (same(node, childNode)) {
  477. if (operation === 'added') {
  478. 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.');
  479. } else {
  480. 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.');
  481. }
  482. }
  483. }
  484. }
  485. }
  486. };
  487. var createDom;
  488. var updateDom;
  489. var updateChildren = function (vnode, domNode, oldChildren, newChildren, projectionOptions) {
  490. if (oldChildren === newChildren) {
  491. return false;
  492. }
  493. oldChildren = oldChildren || emptyArray;
  494. newChildren = newChildren || emptyArray;
  495. var oldChildrenLength = oldChildren.length;
  496. var newChildrenLength = newChildren.length;
  497. var transitions = projectionOptions.transitions;
  498. var oldIndex = 0;
  499. var newIndex = 0;
  500. var i;
  501. var textUpdated = false;
  502. while (newIndex < newChildrenLength) {
  503. var oldChild = oldIndex < oldChildrenLength ? oldChildren[oldIndex] : undefined;
  504. var newChild = newChildren[newIndex];
  505. if (oldChild !== undefined && same(oldChild, newChild)) {
  506. textUpdated = updateDom(oldChild, newChild, projectionOptions) || textUpdated;
  507. oldIndex++;
  508. } else {
  509. var findOldIndex = findIndexOfChild(oldChildren, newChild, oldIndex + 1);
  510. if (findOldIndex >= 0) {
  511. // Remove preceding missing children
  512. for (i = oldIndex; i < findOldIndex; i++) {
  513. nodeToRemove(oldChildren[i], transitions);
  514. checkDistinguishable(oldChildren, i, vnode, 'removed');
  515. }
  516. textUpdated = updateDom(oldChildren[findOldIndex], newChild, projectionOptions) || textUpdated;
  517. oldIndex = findOldIndex + 1;
  518. } else {
  519. // New child
  520. createDom(newChild, domNode, oldIndex < oldChildrenLength ? oldChildren[oldIndex].domNode : undefined, projectionOptions);
  521. nodeAdded(newChild, transitions);
  522. checkDistinguishable(newChildren, newIndex, vnode, 'added');
  523. }
  524. }
  525. newIndex++;
  526. }
  527. if (oldChildrenLength > oldIndex) {
  528. // Remove child fragments
  529. for (i = oldIndex; i < oldChildrenLength; i++) {
  530. nodeToRemove(oldChildren[i], transitions);
  531. checkDistinguishable(oldChildren, i, vnode, 'removed');
  532. }
  533. }
  534. return textUpdated;
  535. };
  536. var addChildren = function (domNode, children, projectionOptions) {
  537. if (!children) {
  538. return;
  539. }
  540. for (var i = 0; i < children.length; i++) {
  541. createDom(children[i], domNode, undefined, projectionOptions);
  542. }
  543. };
  544. var initPropertiesAndChildren = function (domNode, vnode, projectionOptions) {
  545. addChildren(domNode, vnode.children, projectionOptions);
  546. // children before properties, needed for value property of <select>.
  547. if (vnode.text) {
  548. domNode.textContent = vnode.text;
  549. }
  550. setProperties(domNode, vnode.properties, projectionOptions);
  551. if (vnode.properties && vnode.properties.afterCreate) {
  552. vnode.properties.afterCreate(domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children);
  553. }
  554. };
  555. createDom = function (vnode, parentNode, insertBefore, projectionOptions) {
  556. var domNode, i, c, start = 0, type, found;
  557. var vnodeSelector = vnode.vnodeSelector;
  558. if (vnodeSelector === '') {
  559. domNode = vnode.domNode = document.createTextNode(vnode.text);
  560. if (insertBefore !== undefined) {
  561. parentNode.insertBefore(domNode, insertBefore);
  562. } else {
  563. parentNode.appendChild(domNode);
  564. }
  565. } else {
  566. for (i = 0; i <= vnodeSelector.length; ++i) {
  567. c = vnodeSelector.charAt(i);
  568. if (i === vnodeSelector.length || c === '.' || c === '#') {
  569. type = vnodeSelector.charAt(start - 1);
  570. found = vnodeSelector.slice(start, i);
  571. if (type === '.') {
  572. domNode.classList.add(found);
  573. } else if (type === '#') {
  574. domNode.id = found;
  575. } else {
  576. if (found === 'svg') {
  577. projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
  578. }
  579. if (projectionOptions.namespace !== undefined) {
  580. domNode = vnode.domNode = document.createElementNS(projectionOptions.namespace, found);
  581. } else {
  582. domNode = vnode.domNode = document.createElement(found);
  583. }
  584. if (insertBefore !== undefined) {
  585. parentNode.insertBefore(domNode, insertBefore);
  586. } else {
  587. parentNode.appendChild(domNode);
  588. }
  589. }
  590. start = i + 1;
  591. }
  592. }
  593. initPropertiesAndChildren(domNode, vnode, projectionOptions);
  594. }
  595. };
  596. updateDom = function (previous, vnode, projectionOptions) {
  597. var domNode = previous.domNode;
  598. var textUpdated = false;
  599. if (previous === vnode) {
  600. return false; // By contract, VNode objects may not be modified anymore after passing them to maquette
  601. }
  602. var updated = false;
  603. if (vnode.vnodeSelector === '') {
  604. if (vnode.text !== previous.text) {
  605. var newVNode = document.createTextNode(vnode.text);
  606. domNode.parentNode.replaceChild(newVNode, domNode);
  607. vnode.domNode = newVNode;
  608. textUpdated = true;
  609. return textUpdated;
  610. }
  611. } else {
  612. if (vnode.vnodeSelector.lastIndexOf('svg', 0) === 0) {
  613. projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
  614. }
  615. if (previous.text !== vnode.text) {
  616. updated = true;
  617. if (vnode.text === undefined) {
  618. domNode.removeChild(domNode.firstChild); // the only textnode presumably
  619. } else {
  620. domNode.textContent = vnode.text;
  621. }
  622. }
  623. updated = updateChildren(vnode, domNode, previous.children, vnode.children, projectionOptions) || updated;
  624. updated = updateProperties(domNode, previous.properties, vnode.properties, projectionOptions) || updated;
  625. if (vnode.properties && vnode.properties.afterUpdate) {
  626. vnode.properties.afterUpdate(domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children);
  627. }
  628. }
  629. if (updated && vnode.properties && vnode.properties.updateAnimation) {
  630. vnode.properties.updateAnimation(domNode, vnode.properties, previous.properties);
  631. }
  632. vnode.domNode = previous.domNode;
  633. return textUpdated;
  634. };
  635. var createProjection = function (vnode, projectionOptions) {
  636. return {
  637. update: function (updatedVnode) {
  638. if (vnode.vnodeSelector !== updatedVnode.vnodeSelector) {
  639. 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)');
  640. }
  641. updateDom(vnode, updatedVnode, projectionOptions);
  642. vnode = updatedVnode;
  643. },
  644. domNode: vnode.domNode
  645. };
  646. };
  647. ;
  648. // The other two parameters are not added here, because the Typescript compiler creates surrogate code for desctructuring 'children'.
  649. exports.h = function (selector) {
  650. var properties = arguments[1];
  651. if (typeof selector !== 'string') {
  652. throw new Error();
  653. }
  654. var childIndex = 1;
  655. if (properties && !properties.hasOwnProperty('vnodeSelector') && !Array.isArray(properties) && typeof properties === 'object') {
  656. childIndex = 2;
  657. } else {
  658. // Optional properties argument was omitted
  659. properties = undefined;
  660. }
  661. var text = undefined;
  662. var children = undefined;
  663. var argsLength = arguments.length;
  664. // Recognize a common special case where there is only a single text node
  665. if (argsLength === childIndex + 1) {
  666. var onlyChild = arguments[childIndex];
  667. if (typeof onlyChild === 'string') {
  668. text = onlyChild;
  669. } else if (onlyChild !== undefined && onlyChild.length === 1 && typeof onlyChild[0] === 'string') {
  670. text = onlyChild[0];
  671. }
  672. }
  673. if (text === undefined) {
  674. children = [];
  675. for (; childIndex < arguments.length; childIndex++) {
  676. var child = arguments[childIndex];
  677. if (child === null || child === undefined) {
  678. continue;
  679. } else if (Array.isArray(child)) {
  680. appendChildren(selector, child, children);
  681. } else if (child.hasOwnProperty('vnodeSelector')) {
  682. children.push(child);
  683. } else {
  684. children.push(toTextVNode(child));
  685. }
  686. }
  687. }
  688. return {
  689. vnodeSelector: selector,
  690. properties: properties,
  691. children: children,
  692. text: text === '' ? undefined : text,
  693. domNode: null
  694. };
  695. };
  696. /**
  697. * Contains simple low-level utility functions to manipulate the real DOM.
  698. */
  699. exports.dom = {
  700. /**
  701. * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
  702. * its [[Projection.domNode|domNode]] property.
  703. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  704. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
  705. * objects may only be rendered once.
  706. * @param projectionOptions - Options to be used to create and update the projection.
  707. * @returns The [[Projection]] which also contains the DOM Node that was created.
  708. */
  709. create: function (vnode, projectionOptions) {
  710. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  711. createDom(vnode, document.createElement('div'), undefined, projectionOptions);
  712. return createProjection(vnode, projectionOptions);
  713. },
  714. /**
  715. * Appends a new childnode to the DOM which is generated from a [[VNode]].
  716. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  717. * @param parentNode - The parent node for the new childNode.
  718. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
  719. * objects may only be rendered once.
  720. * @param projectionOptions - Options to be used to create and update the [[Projection]].
  721. * @returns The [[Projection]] that was created.
  722. */
  723. append: function (parentNode, vnode, projectionOptions) {
  724. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  725. createDom(vnode, parentNode, undefined, projectionOptions);
  726. return createProjection(vnode, projectionOptions);
  727. },
  728. /**
  729. * Inserts a new DOM node which is generated from a [[VNode]].
  730. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  731. * @param beforeNode - The node that the DOM Node is inserted before.
  732. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
  733. * NOTE: [[VNode]] objects may only be rendered once.
  734. * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
  735. * @returns The [[Projection]] that was created.
  736. */
  737. insertBefore: function (beforeNode, vnode, projectionOptions) {
  738. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  739. createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
  740. return createProjection(vnode, projectionOptions);
  741. },
  742. /**
  743. * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
  744. * This means that the virtual DOM and the real DOM will have one overlapping element.
  745. * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
  746. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  747. * @param domNode - The existing element to adopt as the root of the new virtual DOM. Existing attributes and childnodes are preserved.
  748. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
  749. * may only be rendered once.
  750. * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
  751. * @returns The [[Projection]] that was created.
  752. */
  753. merge: function (element, vnode, projectionOptions) {
  754. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  755. vnode.domNode = element;
  756. initPropertiesAndChildren(element, vnode, projectionOptions);
  757. return createProjection(vnode, projectionOptions);
  758. }
  759. };
  760. /**
  761. * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
  762. * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
  763. * For more information, see [[CalculationCache]].
  764. *
  765. * @param <Result> The type of the value that is cached.
  766. */
  767. exports.createCache = function () {
  768. var cachedInputs = undefined;
  769. var cachedOutcome = undefined;
  770. var result = {
  771. invalidate: function () {
  772. cachedOutcome = undefined;
  773. cachedInputs = undefined;
  774. },
  775. result: function (inputs, calculation) {
  776. if (cachedInputs) {
  777. for (var i = 0; i < inputs.length; i++) {
  778. if (cachedInputs[i] !== inputs[i]) {
  779. cachedOutcome = undefined;
  780. }
  781. }
  782. }
  783. if (!cachedOutcome) {
  784. cachedOutcome = calculation();
  785. cachedInputs = inputs;
  786. }
  787. return cachedOutcome;
  788. }
  789. };
  790. return result;
  791. };
  792. /**
  793. * Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
  794. * See {@link http://maquettejs.org/docs/arrays.html|Working with arrays}.
  795. *
  796. * @param <Source> The type of source items. A database-record for instance.
  797. * @param <Target> The type of target items. A [[Component]] for instance.
  798. * @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
  799. * @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
  800. * to the `callback` argument in `Array.map(callback)`.
  801. * @param updateResult `function(source, target, index)` that updates a result to an updated source.
  802. */
  803. exports.createMapping = function (getSourceKey, createResult, updateResult) {
  804. var keys = [];
  805. var results = [];
  806. return {
  807. results: results,
  808. map: function (newSources) {
  809. var newKeys = newSources.map(getSourceKey);
  810. var oldTargets = results.slice();
  811. var oldIndex = 0;
  812. for (var i = 0; i < newSources.length; i++) {
  813. var source = newSources[i];
  814. var sourceKey = newKeys[i];
  815. if (sourceKey === keys[oldIndex]) {
  816. results[i] = oldTargets[oldIndex];
  817. updateResult(source, oldTargets[oldIndex], i);
  818. oldIndex++;
  819. } else {
  820. var found = false;
  821. for (var j = 1; j < keys.length; j++) {
  822. var searchIndex = (oldIndex + j) % keys.length;
  823. if (keys[searchIndex] === sourceKey) {
  824. results[i] = oldTargets[searchIndex];
  825. updateResult(newSources[i], oldTargets[searchIndex], i);
  826. oldIndex = searchIndex + 1;
  827. found = true;
  828. break;
  829. }
  830. }
  831. if (!found) {
  832. results[i] = createResult(source, i);
  833. }
  834. }
  835. }
  836. results.length = newSources.length;
  837. keys = newKeys;
  838. }
  839. };
  840. };
  841. /**
  842. * Creates a [[Projector]] instance using the provided projectionOptions.
  843. *
  844. * For more information, see [[Projector]].
  845. *
  846. * @param projectionOptions Options that influence how the DOM is rendered and updated.
  847. */
  848. exports.createProjector = function (projectorOptions) {
  849. var projector;
  850. var projectionOptions = applyDefaultProjectionOptions(projectorOptions);
  851. projectionOptions.eventHandlerInterceptor = function (propertyName, eventHandler, domNode, properties) {
  852. return function () {
  853. // intercept function calls (event handlers) to do a render afterwards.
  854. projector.scheduleRender();
  855. return eventHandler.apply(properties.bind || this, arguments);
  856. };
  857. };
  858. var renderCompleted = true;
  859. var scheduled;
  860. var stopped = false;
  861. var projections = [];
  862. var renderFunctions = [];
  863. // matches the projections array
  864. var doRender = function () {
  865. scheduled = undefined;
  866. if (!renderCompleted) {
  867. return; // The last render threw an error, it should be logged in the browser console.
  868. }
  869. renderCompleted = false;
  870. for (var i = 0; i < projections.length; i++) {
  871. var updatedVnode = renderFunctions[i]();
  872. projections[i].update(updatedVnode);
  873. }
  874. renderCompleted = true;
  875. };
  876. projector = {
  877. scheduleRender: function () {
  878. if (!scheduled && !stopped) {
  879. scheduled = requestAnimationFrame(doRender);
  880. }
  881. },
  882. stop: function () {
  883. if (scheduled) {
  884. cancelAnimationFrame(scheduled);
  885. scheduled = undefined;
  886. }
  887. stopped = true;
  888. },
  889. resume: function () {
  890. stopped = false;
  891. renderCompleted = true;
  892. projector.scheduleRender();
  893. },
  894. append: function (parentNode, renderMaquetteFunction) {
  895. projections.push(exports.dom.append(parentNode, renderMaquetteFunction(), projectionOptions));
  896. renderFunctions.push(renderMaquetteFunction);
  897. },
  898. insertBefore: function (beforeNode, renderMaquetteFunction) {
  899. projections.push(exports.dom.insertBefore(beforeNode, renderMaquetteFunction(), projectionOptions));
  900. renderFunctions.push(renderMaquetteFunction);
  901. },
  902. merge: function (domNode, renderMaquetteFunction) {
  903. projections.push(exports.dom.merge(domNode, renderMaquetteFunction(), projectionOptions));
  904. renderFunctions.push(renderMaquetteFunction);
  905. },
  906. replace: function (domNode, renderMaquetteFunction) {
  907. var vnode = renderMaquetteFunction();
  908. createDom(vnode, domNode.parentNode, domNode, projectionOptions);
  909. domNode.parentNode.removeChild(domNode);
  910. projections.push(createProjection(vnode, projectionOptions));
  911. renderFunctions.push(renderMaquetteFunction);
  912. },
  913. detach: function (renderMaquetteFunction) {
  914. for (var i = 0; i < renderFunctions.length; i++) {
  915. if (renderFunctions[i] === renderMaquetteFunction) {
  916. renderFunctions.splice(i, 1);
  917. return projections.splice(i, 1)[0];
  918. }
  919. }
  920. throw new Error('renderMaquetteFunction was not found');
  921. }
  922. };
  923. return projector;
  924. };
  925. }));
  926. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/lib/marked.min.js ---- */
  927. /**
  928. * marked - a markdown parser
  929. * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
  930. * https://github.com/chjj/marked
  931. */
  932. (function(){var block={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:noop,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:noop,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:noop,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};block.bullet=/(?:[*+-]|\d+\.)/;block.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;block.item=replace(block.item,"gm")(/bull/g,block.bullet)();block.list=replace(block.list)(/bull/g,block.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+block.def.source+")")();block.blockquote=replace(block.blockquote)("def",block.def)();block._tag="(?!(?:"+"a|em|strong|small|s|cite|q|dfn|abbr|data|time|code"+"|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo"+"|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b";block.html=replace(block.html)("comment",/<!--[\s\S]*?-->/)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)(/tag/g,block._tag)();block.paragraph=replace(block.paragraph)("hr",block.hr)("heading",block.heading)("lheading",block.lheading)("blockquote",block.blockquote)("tag","<"+block._tag)("def",block.def)();block.normal=merge({},block);block.gfm=merge({},block.normal,{fences:/^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,paragraph:/^/});block.gfm.paragraph=replace(block.paragraph)("(?!","(?!"+block.gfm.fences.source.replace("\\1","\\2")+"|"+block.list.source.replace("\\1","\\3")+"|")();block.tables=merge({},block.gfm,{nptable:/^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,table:/^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/});function Lexer(options){this.tokens=[];this.tokens.links={};this.options=options||marked.defaults;this.rules=block.normal;if(this.options.gfm){if(this.options.tables){this.rules=block.tables}else{this.rules=block.gfm}}}Lexer.rules=block;Lexer.lex=function(src,options){var lexer=new Lexer(options);return lexer.lex(src)};Lexer.prototype.lex=function(src){src=src.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n");return this.token(src,true)};Lexer.prototype.token=function(src,top,bq){var src=src.replace(/^ +$/gm,""),next,loose,cap,bull,b,item,space,i,l;while(src){if(cap=this.rules.newline.exec(src)){src=src.substring(cap[0].length);if(cap[0].length>1){this.tokens.push({type:"space"})}}if(cap=this.rules.code.exec(src)){src=src.substring(cap[0].length);cap=cap[0].replace(/^ {4}/gm,"");this.tokens.push({type:"code",text:!this.options.pedantic?cap.replace(/\n+$/,""):cap});continue}if(cap=this.rules.fences.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"code",lang:cap[2],text:cap[3]});continue}if(cap=this.rules.heading.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"heading",depth:cap[1].length,text:cap[2]});continue}if(top&&(cap=this.rules.nptable.exec(src))){src=src.substring(cap[0].length);item={type:"table",header:cap[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:cap[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:cap[3].replace(/\n$/,"").split("\n")};for(i=0;i<item.align.length;i++){if(/^ *-+: *$/.test(item.align[i])){item.align[i]="right"}else if(/^ *:-+: *$/.test(item.align[i])){item.align[i]="center"}else if(/^ *:-+ *$/.test(item.align[i])){item.align[i]="left"}else{item.align[i]=null}}for(i=0;i<item.cells.length;i++){item.cells[i]=item.cells[i].split(/ *\| */)}this.tokens.push(item);continue}if(cap=this.rules.lheading.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"heading",depth:cap[2]==="="?1:2,text:cap[1]});continue}if(cap=this.rules.hr.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"hr"});continue}if(cap=this.rules.blockquote.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"blockquote_start"});cap=cap[0].replace(/^ *> ?/gm,"");this.token(cap,top,true);this.tokens.push({type:"blockquote_end"});continue}if(cap=this.rules.list.exec(src)){src=src.substring(cap[0].length);bull=cap[2];this.tokens.push({type:"list_start",ordered:bull.length>1});cap=cap[0].match(this.rules.item);next=false;l=cap.length;i=0;for(;i<l;i++){item=cap[i];space=item.length;item=item.replace(/^ *([*+-]|\d+\.) +/,"");if(~item.indexOf("\n ")){space-=item.length;item=!this.options.pedantic?item.replace(new RegExp("^ {1,"+space+"}","gm"),""):item.replace(/^ {1,4}/gm,"")}if(this.options.smartLists&&i!==l-1){b=block.bullet.exec(cap[i+1])[0];if(bull!==b&&!(bull.length>1&&b.length>1)){src=cap.slice(i+1).join("\n")+src;i=l-1}}loose=next||/\n\n(?!\s*$)/.test(item);if(i!==l-1){next=item.charAt(item.length-1)==="\n";if(!loose)loose=next}this.tokens.push({type:loose?"loose_item_start":"list_item_start"});this.token(item,false,bq);this.tokens.push({type:"list_item_end"})}this.tokens.push({type:"list_end"});continue}if(cap=this.rules.html.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:this.options.sanitize?"paragraph":"html",pre:cap[1]==="pre"||cap[1]==="script"||cap[1]==="style",text:cap[0]});continue}if(!bq&&top&&(cap=this.rules.def.exec(src))){src=src.substring(cap[0].length);this.tokens.links[cap[1].toLowerCase()]={href:cap[2],title:cap[3]};continue}if(top&&(cap=this.rules.table.exec(src))){src=src.substring(cap[0].length);item={type:"table",header:cap[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:cap[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:cap[3].replace(/(?: *\| *)?\n$/,"").split("\n")};for(i=0;i<item.align.length;i++){if(/^ *-+: *$/.test(item.align[i])){item.align[i]="right"}else if(/^ *:-+: *$/.test(item.align[i])){item.align[i]="center"}else if(/^ *:-+ *$/.test(item.align[i])){item.align[i]="left"}else{item.align[i]=null}}for(i=0;i<item.cells.length;i++){item.cells[i]=item.cells[i].replace(/^ *\| *| *\| *$/g,"").split(/ *\| */)}this.tokens.push(item);continue}if(top&&(cap=this.rules.paragraph.exec(src))){src=src.substring(cap[0].length);this.tokens.push({type:"paragraph",text:cap[1].charAt(cap[1].length-1)==="\n"?cap[1].slice(0,-1):cap[1]});continue}if(cap=this.rules.text.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"text",text:cap[0]});continue}if(src){throw new Error("Infinite loop on byte: "+src.charCodeAt(0))}}return this.tokens};var inline={escape:/^\\([\\`*{}\[\]()#+\-.!_>])/,autolink:/^<([^ >]+(@|:\/)[^ >]+)>/,url:noop,tag:/^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,link:/^!?\[(inside)\]\(href\)/,reflink:/^!?\[(inside)\]\s*\[([^\]]*)\]/,nolink:/^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,strong:/^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,em:/^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,code:/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,br:/^ {2,}\n(?!\s*$)/,del:noop,text:/^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/};inline._inside=/(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;inline._href=/\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;inline.link=replace(inline.link)("inside",inline._inside)("href",inline._href)();inline.reflink=replace(inline.reflink)("inside",inline._inside)();inline.normal=merge({},inline);inline.pedantic=merge({},inline.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/});inline.gfm=merge({},inline.normal,{escape:replace(inline.escape)("])","~|])")(),url:/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,del:/^~~(?=\S)([\s\S]*?\S)~~/,text:replace(inline.text)("]|","~]|")("|","|https?://|")()});inline.breaks=merge({},inline.gfm,{br:replace(inline.br)("{2,}","*")(),text:replace(inline.gfm.text)("{2,}","*")()});function InlineLexer(links,options){this.options=options||marked.defaults;this.links=links;this.rules=inline.normal;this.renderer=this.options.renderer||new Renderer;this.renderer.options=this.options;if(!this.links){throw new Error("Tokens array requires a `links` property.")}if(this.options.gfm){if(this.options.breaks){this.rules=inline.breaks}else{this.rules=inline.gfm}}else if(this.options.pedantic){this.rules=inline.pedantic}}InlineLexer.rules=inline;InlineLexer.output=function(src,links,options){var inline=new InlineLexer(links,options);return inline.output(src)};InlineLexer.prototype.output=function(src){var out="",link,text,href,cap;while(src){if(cap=this.rules.escape.exec(src)){src=src.substring(cap[0].length);out+=cap[1];continue}if(cap=this.rules.autolink.exec(src)){src=src.substring(cap[0].length);if(cap[2]==="@"){text=cap[1].charAt(6)===":"?this.mangle(cap[1].substring(7)):this.mangle(cap[1]);href=this.mangle("mailto:")+text}else{text=escape(cap[1]);href=text}out+=this.renderer.link(href,null,text);continue}if(!this.inLink&&(cap=this.rules.url.exec(src))){src=src.substring(cap[0].length);text=escape(cap[1]);href=text;out+=this.renderer.link(href,null,text);continue}if(cap=this.rules.tag.exec(src)){if(!this.inLink&&/^<a /i.test(cap[0])){this.inLink=true}else if(this.inLink&&/^<\/a>/i.test(cap[0])){this.inLink=false}src=src.substring(cap[0].length);out+=this.options.sanitize?escape(cap[0]):cap[0];continue}if(cap=this.rules.link.exec(src)){src=src.substring(cap[0].length);this.inLink=true;out+=this.outputLink(cap,{href:cap[2],title:cap[3]});this.inLink=false;continue}if((cap=this.rules.reflink.exec(src))||(cap=this.rules.nolink.exec(src))){src=src.substring(cap[0].length);link=(cap[2]||cap[1]).replace(/\s+/g," ");link=this.links[link.toLowerCase()];if(!link||!link.href){out+=cap[0].charAt(0);src=cap[0].substring(1)+src;continue}this.inLink=true;out+=this.outputLink(cap,link);this.inLink=false;continue}if(cap=this.rules.strong.exec(src)){src=src.substring(cap[0].length);out+=this.renderer.strong(this.output(cap[2]||cap[1]));continue}if(cap=this.rules.em.exec(src)){src=src.substring(cap[0].length);out+=this.renderer.em(this.output(cap[2]||cap[1]));continue}if(cap=this.rules.code.exec(src)){src=src.substring(cap[0].length);out+=this.renderer.codespan(escape(cap[2],true));continue}if(cap=this.rules.br.exec(src)){src=src.substring(cap[0].length);out+=this.renderer.br();continue}if(cap=this.rules.del.exec(src)){src=src.substring(cap[0].length);out+=this.renderer.del(this.output(cap[1]));continue}if(cap=this.rules.text.exec(src)){src=src.substring(cap[0].length);out+=escape(this.smartypants(cap[0]));continue}if(src){throw new Error("Infinite loop on byte: "+src.charCodeAt(0))}}return out};InlineLexer.prototype.outputLink=function(cap,link){var href=escape(link.href),title=link.title?escape(link.title):null;return cap[0].charAt(0)!=="!"?this.renderer.link(href,title,this.output(cap[1])):this.renderer.image(href,title,escape(cap[1]))};InlineLexer.prototype.smartypants=function(text){if(!this.options.smartypants)return text;return text.replace(/--/g,"—").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")};InlineLexer.prototype.mangle=function(text){var out="",l=text.length,i=0,ch;for(;i<l;i++){ch=text.charCodeAt(i);if(Math.random()>.5){ch="x"+ch.toString(16)}out+="&#"+ch+";"}return out};function Renderer(options){this.options=options||{}}Renderer.prototype.code=function(code,lang,escaped){if(this.options.highlight){var out=this.options.highlight(code,lang);if(out!=null&&out!==code){escaped=true;code=out}}if(!lang){return"<pre><code>"+(escaped?code:escape(code,true))+"\n</code></pre>"}return'<pre><code class="'+this.options.langPrefix+escape(lang,true)+'">'+(escaped?code:escape(code,true))+"\n</code></pre>\n"};Renderer.prototype.blockquote=function(quote){return"<blockquote>\n"+quote+"</blockquote>\n"};Renderer.prototype.html=function(html){return html};Renderer.prototype.heading=function(text,level,raw){return"<h"+level+' id="'+this.options.headerPrefix+raw.toLowerCase().replace(/[^\w]+/g,"-")+'">'+text+"</h"+level+">\n"};Renderer.prototype.hr=function(){return this.options.xhtml?"<hr/>\n":"<hr>\n"};Renderer.prototype.list=function(body,ordered){var type=ordered?"ol":"ul";return"<"+type+">\n"+body+"</"+type+">\n"};Renderer.prototype.listitem=function(text){return"<li>"+text+"</li>\n"};Renderer.prototype.paragraph=function(text){return"<p>"+text+"</p>\n"};Renderer.prototype.table=function(header,body){return"<table>\n"+"<thead>\n"+header+"</thead>\n"+"<tbody>\n"+body+"</tbody>\n"+"</table>\n"};Renderer.prototype.tablerow=function(content){return"<tr>\n"+content+"</tr>\n"};Renderer.prototype.tablecell=function(content,flags){var type=flags.header?"th":"td";var tag=flags.align?"<"+type+' style="text-align:'+flags.align+'">':"<"+type+">";return tag+content+"</"+type+">\n"};Renderer.prototype.strong=function(text){return"<strong>"+text+"</strong>"};Renderer.prototype.em=function(text){return"<em>"+text+"</em>"};Renderer.prototype.codespan=function(text){return"<code>"+text+"</code>"};Renderer.prototype.br=function(){return this.options.xhtml?"<br/>":"<br>"};Renderer.prototype.del=function(text){return"<del>"+text+"</del>"};Renderer.prototype.link=function(href,title,text){if(this.options.sanitize){try{var prot=decodeURIComponent(unescape(href)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return""}if(prot.indexOf("javascript:")===0){return""}}var out='<a href="'+href+'"';if(title){out+=' title="'+title+'"'}out+=">"+text+"</a>";return out};Renderer.prototype.image=function(href,title,text){var out='<img src="'+href+'" alt="'+text+'"';if(title){out+=' title="'+title+'"'}out+=this.options.xhtml?"/>":">";return out};function Parser(options){this.tokens=[];this.token=null;this.options=options||marked.defaults;this.options.renderer=this.options.renderer||new Renderer;this.renderer=this.options.renderer;this.renderer.options=this.options}Parser.parse=function(src,options,renderer){var parser=new Parser(options,renderer);return parser.parse(src)};Parser.prototype.parse=function(src){this.inline=new InlineLexer(src.links,this.options,this.renderer);this.tokens=src.reverse();var out="";while(this.next()){out+=this.tok()}return out};Parser.prototype.next=function(){return this.token=this.tokens.pop()};Parser.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0};Parser.prototype.parseText=function(){var body=this.token.text;while(this.peek().type==="text"){body+="\n"+this.next().text}return this.inline.output(body)};Parser.prototype.tok=function(){switch(this.token.type){case"space":{return""}case"hr":{return this.renderer.hr()}case"heading":{return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,this.token.text)}case"code":{return this.renderer.code(this.token.text,this.token.lang,this.token.escaped)}case"table":{var header="",body="",i,row,cell,flags,j;cell="";for(i=0;i<this.token.header.length;i++){flags={header:true,align:this.token.align[i]};cell+=this.renderer.tablecell(this.inline.output(this.token.header[i]),{header:true,align:this.token.align[i]})}header+=this.renderer.tablerow(cell);for(i=0;i<this.token.cells.length;i++){row=this.token.cells[i];cell="";for(j=0;j<row.length;j++){cell+=this.renderer.tablecell(this.inline.output(row[j]),{header:false,align:this.token.align[j]})}body+=this.renderer.tablerow(cell)}return this.renderer.table(header,body)}case"blockquote_start":{var body="";while(this.next().type!=="blockquote_end"){body+=this.tok()}return this.renderer.blockquote(body)}case"list_start":{var body="",ordered=this.token.ordered;while(this.next().type!=="list_end"){body+=this.tok()}return this.renderer.list(body,ordered)}case"list_item_start":{var body="";while(this.next().type!=="list_item_end"){body+=this.token.type==="text"?this.parseText():this.tok()}return this.renderer.listitem(body)}case"loose_item_start":{var body="";while(this.next().type!=="list_item_end"){body+=this.tok()}return this.renderer.listitem(body)}case"html":{var html=!this.token.pre&&!this.options.pedantic?this.inline.output(this.token.text):this.token.text;return this.renderer.html(html)}case"paragraph":{return this.renderer.paragraph(this.inline.output(this.token.text))}case"text":{return this.renderer.paragraph(this.parseText())}}};function escape(html,encode){return html.replace(!encode?/&(?!#?\w+;)/g:/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function unescape(html){return html.replace(/&([#\w]+);/g,function(_,n){n=n.toLowerCase();if(n==="colon")return":";if(n.charAt(0)==="#"){return n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1))}return""})}function replace(regex,opt){regex=regex.source;opt=opt||"";return function self(name,val){if(!name)return new RegExp(regex,opt);val=val.source||val;val=val.replace(/(^|[^\[])\^/g,"$1");regex=regex.replace(name,val);return self}}function noop(){}noop.exec=noop;function merge(obj){var i=1,target,key;for(;i<arguments.length;i++){target=arguments[i];for(key in target){if(Object.prototype.hasOwnProperty.call(target,key)){obj[key]=target[key]}}}return obj}function marked(src,opt,callback){if(callback||typeof opt==="function"){if(!callback){callback=opt;opt=null}opt=merge({},marked.defaults,opt||{});var highlight=opt.highlight,tokens,pending,i=0;try{tokens=Lexer.lex(src,opt)}catch(e){return callback(e)}pending=tokens.length;var done=function(err){if(err){opt.highlight=highlight;return callback(err)}var out;try{out=Parser.parse(tokens,opt)}catch(e){err=e}opt.highlight=highlight;return err?callback(err):callback(null,out)};if(!highlight||highlight.length<3){return done()}delete opt.highlight;if(!pending)return done();for(;i<tokens.length;i++){(function(token){if(token.type!=="code"){return--pending||done()}return highlight(token.text,token.lang,function(err,code){if(err)return done(err);if(code==null||code===token.text){return--pending||done()}token.text=code;token.escaped=true;--pending||done()})})(tokens[i])}return}try{if(opt)opt=merge({},marked.defaults,opt);return Parser.parse(Lexer.lex(src,opt),opt)}catch(e){e.message+="\nPlease report this to https://github.com/chjj/marked.";if((opt||marked.defaults).silent){return"<p>An error occured:</p><pre>"+escape(e.message+"",true)+"</pre>"}throw e}}marked.options=marked.setOptions=function(opt){merge(marked.defaults,opt);return marked};marked.defaults={gfm:true,tables:true,breaks:false,pedantic:false,sanitize:false,smartLists:false,silent:false,highlight:null,langPrefix:"lang-",smartypants:false,headerPrefix:"",renderer:new Renderer,xhtml:false};marked.Parser=Parser;marked.parser=Parser.parse;marked.Renderer=Renderer;marked.Lexer=Lexer;marked.lexer=Lexer.lex;marked.InlineLexer=InlineLexer;marked.inlineLexer=InlineLexer.output;marked.parse=marked;if(typeof module!=="undefined"&&typeof exports==="object"){module.exports=marked}else if(typeof define==="function"&&define.amd){define(function(){return marked})}else{this.marked=marked}}).call(function(){return this||(typeof window!=="undefined"?window:global)}());
  933. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageFiles/Bigfiles.coffee ---- */
  934. (function() {
  935. var Bigfiles,
  936. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  937. 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; },
  938. hasProp = {}.hasOwnProperty;
  939. Bigfiles = (function(superClass) {
  940. extend(Bigfiles, superClass);
  941. function Bigfiles() {
  942. this.render = bind(this.render, this);
  943. this.getHref = bind(this.getHref, this);
  944. this.updateFiles = bind(this.updateFiles, this);
  945. this.files = new SiteFiles(this);
  946. this.files.mode = "bigfiles";
  947. this.files.limit = 100;
  948. this.files.update = this.updateFiles;
  949. this.row = {
  950. "address": "bigfiles"
  951. };
  952. }
  953. Bigfiles.prototype.updateFiles = function(cb) {
  954. var orderby;
  955. if (Page.server_info.rev < 3090) {
  956. return typeof cb === "function" ? cb() : void 0;
  957. }
  958. orderby = this.files.orderby + (this.files.orderby_desc ? " DESC" : "");
  959. return Page.cmd("optionalFileList", {
  960. address: "all",
  961. filter: "downloaded,bigfile",
  962. limit: this.files.limit + 1,
  963. orderby: orderby
  964. }, (function(_this) {
  965. return function(res) {
  966. var i, len, row;
  967. for (i = 0, len = res.length; i < len; i++) {
  968. row = res[i];
  969. row.site = Page.site_list.sites_byaddress[row.address];
  970. }
  971. _this.files.items = res.slice(0, +(_this.files.limit - 1) + 1 || 9e9);
  972. _this.files.loaded = true;
  973. _this.files.has_more = res.length > _this.files.limit;
  974. Page.projector.scheduleRender();
  975. return typeof cb === "function" ? cb() : void 0;
  976. };
  977. })(this));
  978. };
  979. Bigfiles.prototype.getHref = function(row) {
  980. return row.inner_path;
  981. };
  982. Bigfiles.prototype.render = function() {
  983. if (!this.files.items.length) {
  984. return [];
  985. }
  986. return h("div.Site", [h("div.title", [h("h3.name", "Bigfiles")]), this.files.render()]);
  987. };
  988. return Bigfiles;
  989. })(Class);
  990. window.Bigfiles = Bigfiles;
  991. }).call(this);
  992. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageFiles/PageFiles.coffee ---- */
  993. (function() {
  994. var PageFiles,
  995. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  996. 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; },
  997. hasProp = {}.hasOwnProperty;
  998. PageFiles = (function(superClass) {
  999. extend(PageFiles, superClass);
  1000. function PageFiles() {
  1001. this.onSiteInfo = bind(this.onSiteInfo, this);
  1002. this.render = bind(this.render, this);
  1003. this.updateAllFiles = bind(this.updateAllFiles, this);
  1004. this.updateOptionalStats = bind(this.updateOptionalStats, this);
  1005. this.renderSelectbar = bind(this.renderSelectbar, this);
  1006. this.renderTotalbar = bind(this.renderTotalbar, this);
  1007. this.handleLimitInput = bind(this.handleLimitInput, this);
  1008. this.handleTotalbarMenu = bind(this.handleTotalbarMenu, this);
  1009. this.handleLimitSetClick = bind(this.handleLimitSetClick, this);
  1010. this.handleLimitCancelClick = bind(this.handleLimitCancelClick, this);
  1011. this.handleEditlimitClick = bind(this.handleEditlimitClick, this);
  1012. this.handleTotalbarOut = bind(this.handleTotalbarOut, this);
  1013. this.handleTotalbarOver = bind(this.handleTotalbarOver, this);
  1014. this.handleSelectbarDelete = bind(this.handleSelectbarDelete, this);
  1015. this.handleSelectbarUnpin = bind(this.handleSelectbarUnpin, this);
  1016. this.handleSelectbarPin = bind(this.handleSelectbarPin, this);
  1017. this.handleSelectbarCancel = bind(this.handleSelectbarCancel, this);
  1018. this.checkSelectedFiles = bind(this.checkSelectedFiles, this);
  1019. this.getSites = bind(this.getSites, this);
  1020. this.need_update = true;
  1021. this.updating_files = 0;
  1022. this.optional_stats = {
  1023. limit: "0",
  1024. free: "0",
  1025. used: "0"
  1026. };
  1027. this.updateOptionalStats();
  1028. this.hover_totalbar = false;
  1029. this.menu_totalbar = new Menu();
  1030. this.editing_limit = false;
  1031. this.limit = "";
  1032. this.selected_files_num = 0;
  1033. this.selected_files_size = 0;
  1034. this.selected_files_pinned = 0;
  1035. this.bigfiles = new Bigfiles();
  1036. this.display_limit = 0;
  1037. this;
  1038. }
  1039. PageFiles.prototype.getSites = function() {
  1040. var address, back, bigfile_sites, file, i, len, name, ref, site;
  1041. if (this.bigfiles.files.items.length > 0) {
  1042. back = [];
  1043. bigfile_sites = {};
  1044. ref = this.bigfiles.files.items;
  1045. for (i = 0, len = ref.length; i < len; i++) {
  1046. file = ref[i];
  1047. if (bigfile_sites[name = file.site.row.address] == null) {
  1048. bigfile_sites[name] = {
  1049. row: file.site.row,
  1050. files: {
  1051. items: [],
  1052. selected: this.bigfiles.files.selected,
  1053. update: this.bigfiles.files.update
  1054. }
  1055. };
  1056. }
  1057. bigfile_sites[file.site.row.address].files.items.push(file);
  1058. }
  1059. for (address in bigfile_sites) {
  1060. site = bigfile_sites[address];
  1061. back.push(site);
  1062. }
  1063. back = back.concat(Page.site_list.sites);
  1064. return back;
  1065. } else {
  1066. return Page.site_list.sites;
  1067. }
  1068. };
  1069. PageFiles.prototype.checkSelectedFiles = function() {
  1070. var i, len, ref, results, site, site_file;
  1071. this.selected_files_num = 0;
  1072. this.selected_files_size = 0;
  1073. this.selected_files_pinned = 0;
  1074. ref = this.getSites();
  1075. results = [];
  1076. for (i = 0, len = ref.length; i < len; i++) {
  1077. site = ref[i];
  1078. results.push((function() {
  1079. var j, len1, ref1, results1;
  1080. ref1 = site.files.items;
  1081. results1 = [];
  1082. for (j = 0, len1 = ref1.length; j < len1; j++) {
  1083. site_file = ref1[j];
  1084. if (!site.files.selected[site_file.inner_path]) {
  1085. continue;
  1086. }
  1087. this.selected_files_num += 1;
  1088. this.selected_files_size += site_file.size;
  1089. results1.push(this.selected_files_pinned += site_file.is_pinned);
  1090. }
  1091. return results1;
  1092. }).call(this));
  1093. }
  1094. return results;
  1095. };
  1096. PageFiles.prototype.handleSelectbarCancel = function() {
  1097. var i, j, key, len, len1, ref, ref1, ref2, site, site_file, val;
  1098. ref = this.getSites();
  1099. for (i = 0, len = ref.length; i < len; i++) {
  1100. site = ref[i];
  1101. ref1 = site.files.items;
  1102. for (j = 0, len1 = ref1.length; j < len1; j++) {
  1103. site_file = ref1[j];
  1104. ref2 = site.files.selected;
  1105. for (key in ref2) {
  1106. val = ref2[key];
  1107. delete site.files.selected[key];
  1108. }
  1109. }
  1110. }
  1111. this.checkSelectedFiles();
  1112. Page.projector.scheduleRender();
  1113. return false;
  1114. };
  1115. PageFiles.prototype.handleSelectbarPin = function() {
  1116. var i, inner_paths, len, ref, site, site_file;
  1117. ref = this.getSites();
  1118. for (i = 0, len = ref.length; i < len; i++) {
  1119. site = ref[i];
  1120. inner_paths = (function() {
  1121. var j, len1, ref1, results;
  1122. ref1 = site.files.items;
  1123. results = [];
  1124. for (j = 0, len1 = ref1.length; j < len1; j++) {
  1125. site_file = ref1[j];
  1126. if (site.files.selected[site_file.inner_path]) {
  1127. results.push(site_file.inner_path);
  1128. }
  1129. }
  1130. return results;
  1131. })();
  1132. if (inner_paths.length > 0) {
  1133. (function(site) {
  1134. return Page.cmd("optionalFilePin", [inner_paths, site.row.address], function() {
  1135. return site.files.update();
  1136. });
  1137. })(site);
  1138. }
  1139. }
  1140. return this.handleSelectbarCancel();
  1141. };
  1142. PageFiles.prototype.handleSelectbarUnpin = function() {
  1143. var i, inner_paths, len, ref, site, site_file;
  1144. ref = this.getSites();
  1145. for (i = 0, len = ref.length; i < len; i++) {
  1146. site = ref[i];
  1147. inner_paths = (function() {
  1148. var j, len1, ref1, results;
  1149. ref1 = site.files.items;
  1150. results = [];
  1151. for (j = 0, len1 = ref1.length; j < len1; j++) {
  1152. site_file = ref1[j];
  1153. if (site.files.selected[site_file.inner_path]) {
  1154. results.push(site_file.inner_path);
  1155. }
  1156. }
  1157. return results;
  1158. })();
  1159. if (inner_paths.length > 0) {
  1160. (function(site) {
  1161. return Page.cmd("optionalFileUnpin", [inner_paths, site.row.address], function() {
  1162. return site.files.update();
  1163. });
  1164. })(site);
  1165. }
  1166. }
  1167. return this.handleSelectbarCancel();
  1168. };
  1169. PageFiles.prototype.handleSelectbarDelete = function() {
  1170. var i, inner_path, inner_paths, j, len, len1, ref, site, site_file;
  1171. ref = this.getSites();
  1172. for (i = 0, len = ref.length; i < len; i++) {
  1173. site = ref[i];
  1174. inner_paths = (function() {
  1175. var j, len1, ref1, results;
  1176. ref1 = site.files.items;
  1177. results = [];
  1178. for (j = 0, len1 = ref1.length; j < len1; j++) {
  1179. site_file = ref1[j];
  1180. if (site.files.selected[site_file.inner_path]) {
  1181. results.push(site_file.inner_path);
  1182. }
  1183. }
  1184. return results;
  1185. })();
  1186. if (inner_paths.length > 0) {
  1187. for (j = 0, len1 = inner_paths.length; j < len1; j++) {
  1188. inner_path = inner_paths[j];
  1189. Page.cmd("optionalFileDelete", [inner_path, site.row.address]);
  1190. }
  1191. site.files.update();
  1192. }
  1193. }
  1194. Page.site_list.update();
  1195. return this.handleSelectbarCancel();
  1196. };
  1197. PageFiles.prototype.handleTotalbarOver = function() {
  1198. this.hover_totalbar = true;
  1199. return Page.projector.scheduleRender();
  1200. };
  1201. PageFiles.prototype.handleTotalbarOut = function() {
  1202. this.hover_totalbar = false;
  1203. return Page.projector.scheduleRender();
  1204. };
  1205. PageFiles.prototype.handleEditlimitClick = function() {
  1206. this.editing_limit = true;
  1207. return false;
  1208. };
  1209. PageFiles.prototype.handleLimitCancelClick = function() {
  1210. this.editing_limit = false;
  1211. return false;
  1212. };
  1213. PageFiles.prototype.handleLimitSetClick = function() {
  1214. var limit;
  1215. if (this.limit.indexOf("M") > 0 || this.limit.indexOf("m") > 0) {
  1216. limit = (parseFloat(this.limit) / 1024).toString();
  1217. } else if (this.limit.indexOf("%") > 0) {
  1218. limit = parseFloat(this.limit) + "%";
  1219. } else {
  1220. limit = parseFloat(this.limit).toString();
  1221. }
  1222. this.optional_stats.limit = limit;
  1223. Page.cmd("optionalLimitSet", limit);
  1224. this.editing_limit = false;
  1225. return false;
  1226. };
  1227. PageFiles.prototype.handleTotalbarMenu = function() {
  1228. this.menu_totalbar.items = [];
  1229. this.menu_totalbar.items.push(["Edit optional files limit", this.handleEditlimitClick]);
  1230. if (this.menu_totalbar.visible) {
  1231. this.menu_totalbar.hide();
  1232. } else {
  1233. this.menu_totalbar.show();
  1234. }
  1235. return false;
  1236. };
  1237. PageFiles.prototype.handleLimitInput = function(e) {
  1238. return this.limit = e.target.value;
  1239. };
  1240. PageFiles.prototype.renderTotalbar = function() {
  1241. /*
  1242. size_optional = 0
  1243. optional_downloaded = 0
  1244. for site in Page.site_list.sites
  1245. size_optional += site.row.settings.size_optional
  1246. optional_downloaded += site.row.settings.optional_downloaded
  1247. */
  1248. var limit, percent_limit, percent_optional_downloaded, percent_optional_used, total_space_limited;
  1249. if (this.editing_limit && parseFloat(this.limit) > 0) {
  1250. if (this.limit.indexOf("M") > 0 || this.limit.indexOf("m") > 0) {
  1251. limit = (parseFloat(this.limit) / 1024) + "GB";
  1252. } else {
  1253. limit = this.limit;
  1254. }
  1255. } else {
  1256. limit = this.optional_stats.limit;
  1257. }
  1258. if (limit.endsWith("%")) {
  1259. limit = this.optional_stats.free * (parseFloat(limit) / 100);
  1260. } else {
  1261. limit = parseFloat(limit) * 1024 * 1024 * 1024;
  1262. }
  1263. if (this.optional_stats.free > limit * 1.8 && !this.hover_totalbar) {
  1264. total_space_limited = limit * 1.8;
  1265. } else {
  1266. total_space_limited = this.optional_stats.free;
  1267. }
  1268. percent_optional_downloaded = (this.optional_stats.used / limit) * 100;
  1269. percent_optional_used = percent_optional_downloaded * (limit / total_space_limited);
  1270. percent_limit = (limit / total_space_limited) * 100;
  1271. return h("div#PageFilesDashboard", {
  1272. classes: {
  1273. editing: this.editing_limit
  1274. }
  1275. }, [
  1276. h("div.totalbar-edit", [
  1277. h("span.title", "Optional files limit:"), h("input", {
  1278. type: "text",
  1279. value: this.limit,
  1280. oninput: this.handleLimitInput
  1281. }), h("a.set", {
  1282. href: "#",
  1283. onclick: this.handleLimitSetClick
  1284. }, "Set"), h("a.cancel", {
  1285. href: "#",
  1286. onclick: this.handleLimitCancelClick
  1287. }, "Cancel")
  1288. ]), h("a.totalbar-title", {
  1289. href: "#",
  1290. title: "Space current used by optional files",
  1291. onclick: this.handleTotalbarMenu
  1292. }, "Used: " + (Text.formatSize(this.optional_stats.used)) + " / " + (Text.formatSize(limit)) + " (" + (Math.round(percent_optional_downloaded)) + "%)", h("div.icon-arrow-down")), this.menu_totalbar.render(), h("div.totalbar", {
  1293. onmouseover: this.handleTotalbarOver,
  1294. onmouseout: this.handleTotalbarOut
  1295. }, h("div.totalbar-used", {
  1296. style: "width: " + percent_optional_used + "%"
  1297. }), h("div.totalbar-limitbar", {
  1298. style: "width: " + percent_limit + "%"
  1299. }), h("div.totalbar-limit", {
  1300. style: "margin-left: " + percent_limit + "%"
  1301. }, h("span", {
  1302. title: "Space allowed to used by optional files"
  1303. }, Text.formatSize(limit))), h("div.totalbar-hddfree", h("span", {
  1304. title: "Total free space on your storage"
  1305. }, [
  1306. Text.formatSize(this.optional_stats.free), h("div.arrow", {
  1307. style: this.optional_stats.free > total_space_limited ? "width: 10px" : "width: 0px"
  1308. }, " \u25B6")
  1309. ])))
  1310. ]);
  1311. };
  1312. PageFiles.prototype.renderSelectbar = function() {
  1313. return h("div.selectbar", {
  1314. classes: {
  1315. visible: this.selected_files_num > 0
  1316. }
  1317. }, [
  1318. "Selected:", h("span.info", [h("span.num", this.selected_files_num + " files"), h("span.size", "(" + (Text.formatSize(this.selected_files_size)) + ")")]), h("div.actions", [
  1319. this.selected_files_pinned > this.selected_files_num / 2 ? h("a.action.pin.unpin", {
  1320. href: "#",
  1321. onclick: this.handleSelectbarUnpin
  1322. }, "UnPin") : h("a.action.pin", {
  1323. href: "#",
  1324. title: "Don't delete these files automatically",
  1325. onclick: this.handleSelectbarPin
  1326. }, "Pin"), h("a.action.delete", {
  1327. href: "#",
  1328. onclick: this.handleSelectbarDelete
  1329. }, "Delete")
  1330. ]), h("a.cancel.link", {
  1331. href: "#",
  1332. onclick: this.handleSelectbarCancel
  1333. }, "Cancel")
  1334. ]);
  1335. };
  1336. PageFiles.prototype.updateOptionalStats = function() {
  1337. return Page.cmd("optionalLimitStats", [], (function(_this) {
  1338. return function(res) {
  1339. _this.limit = res.limit;
  1340. if (!_this.limit.endsWith("%")) {
  1341. _this.limit += " GB";
  1342. }
  1343. return _this.optional_stats = res;
  1344. };
  1345. })(this));
  1346. };
  1347. PageFiles.prototype.updateAllFiles = function() {
  1348. var used;
  1349. this.updating_files = 0;
  1350. used = 0;
  1351. Page.site_list.sites.map((function(_this) {
  1352. return function(site) {
  1353. if (!site.row.settings.size_optional) {
  1354. return;
  1355. }
  1356. _this.updating_files += 1;
  1357. used += site.row.settings.optional_downloaded;
  1358. return site.files.update(function() {
  1359. return _this.updating_files -= 1;
  1360. });
  1361. };
  1362. })(this));
  1363. this.updating_files += 1;
  1364. return this.bigfiles.files.update((function(_this) {
  1365. return function() {
  1366. return _this.updating_files -= 1;
  1367. };
  1368. })(this));
  1369. };
  1370. PageFiles.prototype.render = function() {
  1371. var site, sites, sites_connected, sites_favorited;
  1372. if (Page.site_list.sites && !this.need_update && this.updating_files === 0 && document.body.className !== "loaded") {
  1373. document.body.className = "loaded";
  1374. }
  1375. if (this.need_update && Page.site_list.sites.length) {
  1376. this.updateAllFiles();
  1377. this.need_update = false;
  1378. }
  1379. sites = (function() {
  1380. var i, len, ref, results;
  1381. ref = Page.site_list.sites;
  1382. results = [];
  1383. for (i = 0, len = ref.length; i < len; i++) {
  1384. site = ref[i];
  1385. if (site.row.settings.size_optional) {
  1386. results.push(site);
  1387. }
  1388. }
  1389. return results;
  1390. })();
  1391. sites_favorited = (function() {
  1392. var i, len, results;
  1393. results = [];
  1394. for (i = 0, len = sites.length; i < len; i++) {
  1395. site = sites[i];
  1396. if (site.favorite) {
  1397. results.push(site);
  1398. }
  1399. }
  1400. return results;
  1401. })();
  1402. sites_connected = (function() {
  1403. var i, len, results;
  1404. results = [];
  1405. for (i = 0, len = sites.length; i < len; i++) {
  1406. site = sites[i];
  1407. if (!site.favorite) {
  1408. results.push(site);
  1409. }
  1410. }
  1411. return results;
  1412. })();
  1413. if (sites.length > 0 && sites[0].files.loaded === false) {
  1414. if (sites_favorited.length) {
  1415. sites_favorited = [sites_favorited[0]];
  1416. sites_connected = [];
  1417. } else {
  1418. sites_favorited = [];
  1419. sites_connected = [sites_connected[0]];
  1420. }
  1421. }
  1422. if (sites.length === 0) {
  1423. document.body.className = "loaded";
  1424. return h("div#PageFiles", this.renderSelectbar(), this.renderTotalbar(), h("div.empty", [h("h4", "Hello newcomer!"), h("small", "You have not downloaded any optional files yet")]));
  1425. }
  1426. if (this.display_limit < sites.length) {
  1427. setTimeout(((function(_this) {
  1428. return function() {
  1429. _this.display_limit += 1;
  1430. return Page.projector.scheduleRender();
  1431. };
  1432. })(this)), 1000);
  1433. }
  1434. return h("div#PageFiles", [
  1435. this.renderSelectbar(), this.renderTotalbar(), this.bigfiles.render(), sites_favorited.slice(0, +this.display_limit + 1 || 9e9).map((function(_this) {
  1436. return function(site) {
  1437. return site.renderOptionalStats();
  1438. };
  1439. })(this)), sites_connected.slice(0, +this.display_limit + 1 || 9e9).map((function(_this) {
  1440. return function(site) {
  1441. return site.renderOptionalStats();
  1442. };
  1443. })(this))
  1444. ]);
  1445. };
  1446. PageFiles.prototype.onSiteInfo = function(site_info) {
  1447. var rate_limit, ref, ref1;
  1448. if (((ref = site_info.event) != null ? ref[0] : void 0) === "peers_added") {
  1449. return false;
  1450. }
  1451. if (site_info.tasks === 0 && ((ref1 = site_info.event) != null ? ref1[0] : void 0) === "file_done") {
  1452. rate_limit = 1000;
  1453. } else {
  1454. rate_limit = 10000;
  1455. }
  1456. return RateLimit(rate_limit, (function(_this) {
  1457. return function() {
  1458. return _this.need_update = true;
  1459. };
  1460. })(this));
  1461. };
  1462. return PageFiles;
  1463. })(Class);
  1464. window.PageFiles = PageFiles;
  1465. }).call(this);
  1466. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageFiles/SiteFiles.coffee ---- */
  1467. (function() {
  1468. var SiteFiles,
  1469. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1470. 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; },
  1471. hasProp = {}.hasOwnProperty;
  1472. SiteFiles = (function(superClass) {
  1473. extend(SiteFiles, superClass);
  1474. function SiteFiles(site1) {
  1475. this.site = site1;
  1476. this.update = bind(this.update, this);
  1477. this.render = bind(this.render, this);
  1478. this.renderOrderRight = bind(this.renderOrderRight, this);
  1479. this.renderOrder = bind(this.renderOrder, this);
  1480. this.handleMoreClick = bind(this.handleMoreClick, this);
  1481. this.handleOrderbyClick = bind(this.handleOrderbyClick, this);
  1482. this.handleRowMouseenter = bind(this.handleRowMouseenter, this);
  1483. this.handleSelectMousedown = bind(this.handleSelectMousedown, this);
  1484. this.handleSelectEnd = bind(this.handleSelectEnd, this);
  1485. this.handleSelectClick = bind(this.handleSelectClick, this);
  1486. this.limit = 10;
  1487. this.selected = {};
  1488. this.items = [];
  1489. this.loaded = false;
  1490. this.orderby = "time_downloaded";
  1491. this.mode = "site";
  1492. this.mode = "single_site";
  1493. this.orderby_desc = true;
  1494. this.has_more = false;
  1495. }
  1496. SiteFiles.prototype.handleSelectClick = function(e) {
  1497. return false;
  1498. };
  1499. SiteFiles.prototype.handleSelectEnd = function(e) {
  1500. document.body.removeEventListener('mouseup', this.handleSelectEnd);
  1501. return this.select_action = null;
  1502. };
  1503. SiteFiles.prototype.handleSelectMousedown = function(e) {
  1504. var inner_path;
  1505. inner_path = e.target.attributes.inner_path.value;
  1506. if (this.selected[inner_path]) {
  1507. delete this.selected[inner_path];
  1508. this.select_action = "deselect";
  1509. } else {
  1510. this.selected[inner_path] = true;
  1511. this.select_action = "select";
  1512. }
  1513. Page.page_files.checkSelectedFiles();
  1514. document.body.addEventListener('mouseup', this.handleSelectEnd);
  1515. e.stopPropagation();
  1516. Page.projector.scheduleRender();
  1517. return false;
  1518. };
  1519. SiteFiles.prototype.handleRowMouseenter = function(e) {
  1520. var inner_path;
  1521. if (e.buttons && this.select_action) {
  1522. inner_path = e.target.attributes.inner_path.value;
  1523. if (this.select_action === "select") {
  1524. this.selected[inner_path] = true;
  1525. } else {
  1526. delete this.selected[inner_path];
  1527. }
  1528. Page.page_files.checkSelectedFiles();
  1529. Page.projector.scheduleRender();
  1530. }
  1531. return false;
  1532. };
  1533. SiteFiles.prototype.handleOrderbyClick = function(e) {
  1534. var orderby;
  1535. orderby = e.currentTarget.attributes.orderby.value;
  1536. if (this.orderby === orderby) {
  1537. this.orderby_desc = !this.orderby_desc;
  1538. }
  1539. this.orderby = orderby;
  1540. this.update();
  1541. Page.projector.scheduleRender();
  1542. return false;
  1543. };
  1544. SiteFiles.prototype.handleMoreClick = function() {
  1545. this.limit += 15;
  1546. this.update();
  1547. return false;
  1548. };
  1549. SiteFiles.prototype.renderOrder = function(title, orderby) {
  1550. return h("a.title.orderby", {
  1551. href: "#" + orderby,
  1552. orderby: orderby,
  1553. onclick: this.handleOrderbyClick,
  1554. classes: {
  1555. selected: this.orderby === orderby,
  1556. desc: this.orderby_desc
  1557. }
  1558. }, [title, h("div.icon.icon-arrow-down")]);
  1559. };
  1560. SiteFiles.prototype.renderOrderRight = function(title, orderby) {
  1561. return h("a.title.orderby", {
  1562. href: "#" + orderby,
  1563. orderby: orderby,
  1564. onclick: this.handleOrderbyClick,
  1565. classes: {
  1566. selected: this.orderby === orderby,
  1567. desc: this.orderby_desc
  1568. }
  1569. }, [h("div.icon.icon-arrow-down"), title]);
  1570. };
  1571. SiteFiles.prototype.render = function() {
  1572. var ref;
  1573. if (!((ref = this.items) != null ? ref.length : void 0)) {
  1574. return [];
  1575. }
  1576. return [
  1577. h("div.files.files-" + this.mode, {
  1578. exitAnimation: Animation.slideUpInout
  1579. }, [
  1580. h("div.tr.thead", [h("div.td.pre", "."), this.mode === "bigfiles" ? h("div.td.site", this.renderOrder("Site", "address")) : void 0, h("div.td.inner_path", this.renderOrder("Optional file", "is_pinned DESC, inner_path")), this.mode === "bigfiles" ? h("div.td.status", "Status") : void 0, h("div.td.size", this.renderOrderRight("Size", "size")), h("div.td.peer", this.renderOrder("Peers", "peer")), h("div.td.uploaded", this.renderOrder("Uploaded", "uploaded")), h("div.td.added", this.renderOrder("Finished", "time_downloaded"))]), h("div.tbody", this.items.map((function(_this) {
  1581. return function(file) {
  1582. var percent, profile_color, site;
  1583. site = file.site || _this.site;
  1584. if (file.peer >= 10) {
  1585. profile_color = "#47d094";
  1586. } else if (file.peer > 0) {
  1587. profile_color = "#f5b800";
  1588. } else {
  1589. profile_color = "#d1d1d1";
  1590. }
  1591. if (_this.mode === "bigfiles") {
  1592. if (file.pieces == null) {
  1593. file.pieces = 0;
  1594. }
  1595. if (file.pieces_downloaded == null) {
  1596. file.pieces_downloaded = 0;
  1597. }
  1598. if (file.pieces === 0 || file.pieces_downloaded === 0) {
  1599. percent = 0;
  1600. } else {
  1601. percent = parseInt((file.pieces_downloaded / file.pieces) * 100);
  1602. }
  1603. }
  1604. return h("div.tr", {
  1605. key: file.inner_path,
  1606. inner_path: file.inner_path,
  1607. exitAnimation: Animation.slideUpInout,
  1608. enterAnimation: Animation.slideDown,
  1609. classes: {
  1610. selected: _this.selected[file.inner_path]
  1611. },
  1612. onmouseenter: _this.handleRowMouseenter
  1613. }, [
  1614. h("div.td.pre", h("a.checkbox", {
  1615. href: "#Select",
  1616. onmousedown: _this.handleSelectMousedown,
  1617. onclick: _this.handleSelectClick,
  1618. inner_path: file.inner_path
  1619. })), _this.mode === "bigfiles" ? h("div.td.site", h("a.link", {
  1620. href: site.getHref()
  1621. }, site.row.content.title)) : void 0, h("div.td.inner_path", h("a.title.link", {
  1622. href: site.getHref(file),
  1623. target: "_top"
  1624. }, file.inner_path.replace(/.*\//, "")), file.is_pinned ? h("span.pinned", {
  1625. exitAnimation: Animation.slideUpInout,
  1626. enterAnimation: Animation.slideDown
  1627. }, "Pinned") : void 0), _this.mode === "bigfiles" ? h("div.td.status", h("span.percent", {
  1628. title: file.pieces_downloaded + " of " + file.pieces + " pieces downloaded",
  1629. style: "box-shadow: inset " + (percent * 0.8) + "px 0px 0px #9ef5cf;"
  1630. }, percent + "%")) : void 0, h("div.td.size", Text.formatSize(file.size)), h("div.td.peer", [
  1631. h("div.icon.icon-profile", {
  1632. style: "color: " + profile_color
  1633. }), h("span.num", file.peer)
  1634. ]), h("div.td.uploaded", h("div.uploaded-text", Text.formatSize(file.uploaded)), h("div.dots-container", [
  1635. h("span.dots.dots-bg", {
  1636. title: "Ratio: " + ((file.uploaded / file.size).toFixed(1))
  1637. }, "\u2022\u2022\u2022\u2022\u2022"), h("span.dots.dots-fg", {
  1638. title: "Ratio: " + ((file.uploaded / file.size).toFixed(1)),
  1639. style: "width: " + (Math.min(5, file.uploaded / file.size) * 9) + "px"
  1640. }, "\u2022\u2022\u2022\u2022\u2022")
  1641. ])), h("div.td.added", file.time_downloaded ? Time.since(file.time_downloaded) : "n/a")
  1642. ]);
  1643. };
  1644. })(this)))
  1645. ]), this.has_more ? h("div.more-container", h("a.more", {
  1646. href: "#More",
  1647. onclick: this.handleMoreClick
  1648. }, "More files...")) : void 0
  1649. ];
  1650. };
  1651. SiteFiles.prototype.update = function(cb) {
  1652. var orderby;
  1653. orderby = this.orderby + (this.orderby_desc ? " DESC" : "");
  1654. return Page.cmd("optionalFileList", {
  1655. address: this.site.row.address,
  1656. limit: this.limit + 1,
  1657. orderby: orderby
  1658. }, (function(_this) {
  1659. return function(res) {
  1660. _this.items = res.slice(0, +(_this.limit - 1) + 1 || 9e9);
  1661. _this.loaded = true;
  1662. _this.has_more = res.length > _this.limit;
  1663. Page.projector.scheduleRender();
  1664. return typeof cb === "function" ? cb() : void 0;
  1665. };
  1666. })(this));
  1667. };
  1668. return SiteFiles;
  1669. })(Class);
  1670. window.SiteFiles = SiteFiles;
  1671. }).call(this);
  1672. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageSites/Dashboard.coffee ---- */
  1673. (function() {
  1674. var Dashboard,
  1675. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1676. 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; },
  1677. hasProp = {}.hasOwnProperty,
  1678. 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; };
  1679. Dashboard = (function(superClass) {
  1680. extend(Dashboard, superClass);
  1681. function Dashboard() {
  1682. this.render = bind(this.render, this);
  1683. this.handleTorBrowserwarningClick = bind(this.handleTorBrowserwarningClick, this);
  1684. this.handleBrowserwarningClick = bind(this.handleBrowserwarningClick, this);
  1685. this.handleNewversionClick = bind(this.handleNewversionClick, this);
  1686. this.handleLogoutClick = bind(this.handleLogoutClick, this);
  1687. this.handleDonateClick = bind(this.handleDonateClick, this);
  1688. this.handleMultiuserClick = bind(this.handleMultiuserClick, this);
  1689. this.handlePortRecheckClick = bind(this.handlePortRecheckClick, this);
  1690. this.handlePortClick = bind(this.handlePortClick, this);
  1691. this.handleDisableAlwaysTorClick = bind(this.handleDisableAlwaysTorClick, this);
  1692. this.handleEnableAlwaysTorClick = bind(this.handleEnableAlwaysTorClick, this);
  1693. this.handleTorClick = bind(this.handleTorClick, this);
  1694. this.menu_newversion = new Menu();
  1695. this.menu_tor = new Menu();
  1696. this.menu_port = new Menu();
  1697. this.menu_multiuser = new Menu();
  1698. this.menu_donate = new Menu();
  1699. this.menu_browserwarning = new Menu();
  1700. this.menu_torbrowserwarning = new Menu();
  1701. this.port_checking = false;
  1702. this.has_web_gl = null;
  1703. }
  1704. Dashboard.prototype.isTorAlways = function() {
  1705. return Page.server_info.fileserver_ip === "127.0.0.1";
  1706. };
  1707. Dashboard.prototype.hasWebGl = function() {
  1708. var canvas, ctx;
  1709. if (this.has_web_gl === null) {
  1710. canvas = document.createElement('canvas');
  1711. ctx = canvas.getContext("webgl");
  1712. this.has_web_gl = ctx ? true : false;
  1713. this.log("Webgl:", this.has_web_gl);
  1714. }
  1715. return this.has_web_gl;
  1716. };
  1717. Dashboard.prototype.getTorTitle = function() {
  1718. var tor_title;
  1719. tor_title = Page.server_info.tor_status.replace(/\((.*)\)/, "").trim();
  1720. if (tor_title === "Disabled") {
  1721. tor_title = _("Disabled");
  1722. } else if (tor_title === "Error") {
  1723. tor_title = _("Error");
  1724. }
  1725. return tor_title;
  1726. };
  1727. Dashboard.prototype.handleTorClick = function() {
  1728. var ref;
  1729. this.menu_tor.items = [];
  1730. this.menu_tor.items.push(["Status: " + ((ref = Page.server_info) != null ? ref.tor_status : void 0), "http://zeronet.readthedocs.org/en/latest/faq/#how-to-make-zeronet-work-with-tor-under-linux"]);
  1731. if (this.getTorTitle() !== "OK") {
  1732. this.menu_tor.items.push(["How to make Tor connection work?", "http://zeronet.readthedocs.org/en/latest/faq/#how-to-make-zeronet-work-with-tor-under-linux"]);
  1733. }
  1734. this.menu_tor.items.push(["How to use ZeroNet in Tor Browser?", "http://zeronet.readthedocs.org/en/latest/faq/#how-to-use-zeronet-in-tor-browser"]);
  1735. this.menu_tor.items.push(["---"]);
  1736. if (this.isTorAlways()) {
  1737. this.menu_tor.items.push(["Disable always Tor mode", this.handleDisableAlwaysTorClick]);
  1738. } else {
  1739. this.menu_tor.items.push(["Enable Tor for every connection (slower)", this.handleEnableAlwaysTorClick]);
  1740. }
  1741. this.menu_tor.toggle();
  1742. return false;
  1743. };
  1744. Dashboard.prototype.handleEnableAlwaysTorClick = function() {
  1745. return Page.cmd("configSet", ["tor", "always"], (function(_this) {
  1746. return function(res) {
  1747. return Page.cmd("wrapperNotification", ["done", "Tor always mode enabled, please restart your ZeroNet to make it work.<br>For your privacy switch to Tor browser and start a new profile by renaming the data directory."]);
  1748. };
  1749. })(this));
  1750. };
  1751. Dashboard.prototype.handleDisableAlwaysTorClick = function() {
  1752. return Page.cmd("configSet", ["tor", null], (function(_this) {
  1753. return function(res) {
  1754. return Page.cmd("wrapperNotification", ["done", "Tor always mode disabled, please restart your ZeroNet."]);
  1755. };
  1756. })(this));
  1757. };
  1758. Dashboard.prototype.handlePortClick = function() {
  1759. this.menu_port.items = [];
  1760. if (Page.server_info.ip_external) {
  1761. this.menu_port.items.push(["Nice! Your port " + Page.server_info.fileserver_port + " is opened.", "http://zeronet.readthedocs.org/en/latest/faq/#do-i-need-to-have-a-port-opened"]);
  1762. } else if (this.isTorAlways()) {
  1763. this.menu_port.items.push(["Good, your port is always closed when using ZeroNet in Tor always mode.", "http://zeronet.readthedocs.org/en/latest/faq/#do-i-need-to-have-a-port-opened"]);
  1764. } else if (this.getTorTitle() === "OK") {
  1765. this.menu_port.items.push(["Your port " + Page.server_info.fileserver_port + " is closed, but your Tor gateway is running well.", "http://zeronet.readthedocs.org/en/latest/faq/#do-i-need-to-have-a-port-opened"]);
  1766. } else {
  1767. this.menu_port.items.push(["Your port " + Page.server_info.fileserver_port + " is closed. You are still fine, but for faster experience try open it.", "http://zeronet.readthedocs.org/en/latest/faq/#do-i-need-to-have-a-port-opened"]);
  1768. }
  1769. this.menu_port.items.push(["---"]);
  1770. this.menu_port.items.push(["Re-check opened port", this.handlePortRecheckClick]);
  1771. this.menu_port.toggle();
  1772. return false;
  1773. };
  1774. Dashboard.prototype.handlePortRecheckClick = function() {
  1775. this.port_checking = true;
  1776. return Page.cmd("serverPortcheck", [], (function(_this) {
  1777. return function(res) {
  1778. _this.port_checking = false;
  1779. return Page.reloadServerInfo();
  1780. };
  1781. })(this));
  1782. };
  1783. Dashboard.prototype.handleMultiuserClick = function() {
  1784. this.menu_multiuser.items = [];
  1785. this.menu_multiuser.items.push([
  1786. "Show your masterseed", (function() {
  1787. return Page.cmd("userShowMasterSeed");
  1788. })
  1789. ]);
  1790. this.menu_multiuser.items.push([
  1791. "Logout", (function() {
  1792. return Page.cmd("userLogout");
  1793. })
  1794. ]);
  1795. this.menu_multiuser.toggle();
  1796. return false;
  1797. };
  1798. Dashboard.prototype.handleDonateClick = function() {
  1799. this.menu_donate.items = [];
  1800. this.menu_donate.items.push(["Help to keep this project alive", "https://zeronet.readthedocs.org/en/latest/help_zeronet/donate/"]);
  1801. this.menu_donate.toggle();
  1802. return false;
  1803. };
  1804. Dashboard.prototype.handleLogoutClick = function() {
  1805. return Page.cmd("uiLogout");
  1806. };
  1807. Dashboard.prototype.handleNewversionClick = function() {
  1808. this.menu_newversion.items = [];
  1809. this.menu_newversion.items.push([
  1810. "Update and restart ZeroNet", (function() {
  1811. Page.cmd("wrapperNotification", ["info", "Updating to latest version...<br>Please restart ZeroNet manually if it does not come back in the next few minutes.", 8000]);
  1812. return Page.cmd("serverUpdate");
  1813. })
  1814. ]);
  1815. this.menu_newversion.items.push(["Details of the update", Text.getSiteUrl("Blog.ZeroNetwork.bit")]);
  1816. this.menu_newversion.toggle();
  1817. return false;
  1818. };
  1819. Dashboard.prototype.handleBrowserwarningClick = function() {
  1820. this.menu_browserwarning.items = [];
  1821. this.menu_browserwarning.items.push(["Internet Explorer is not fully supported browser by ZeroNet, please consider switching to Chrome or Firefox", "http://browsehappy.com/"]);
  1822. this.menu_browserwarning.toggle();
  1823. return false;
  1824. };
  1825. Dashboard.prototype.handleTorBrowserwarningClick = function() {
  1826. this.menu_torbrowserwarning.items = [];
  1827. this.menu_torbrowserwarning.items.push(["To protect your anonymity you should use ZeroNet in the Tor browser.", "http://zeronet.readthedocs.io/en/latest/faq/#how-to-use-zeronet-in-tor-browser"]);
  1828. this.menu_torbrowserwarning.toggle();
  1829. return false;
  1830. };
  1831. Dashboard.prototype.render = function() {
  1832. var tor_title;
  1833. if (Page.server_info) {
  1834. tor_title = this.getTorTitle();
  1835. return h("div#Dashboard", navigator.userAgent.match(/(\b(MS)?IE\s+|Trident\/7.0)/) ? h("a.port.dashboard-item.browserwarning", {
  1836. href: "http://browsehappy.com/",
  1837. onmousedown: this.handleBrowserwarningClick,
  1838. onclick: Page.returnFalse
  1839. }, [h("span", "Unsupported browser")]) : void 0, this.menu_browserwarning.render(".menu-browserwarning"), this.isTorAlways() && (!navigator.userAgent.match(/(Firefox)/) || this.hasWebGl() || (navigator.serviceWorker != null)) ? h("a.port.dashboard-item.torbrowserwarning", {
  1840. href: "http://zeronet.readthedocs.io/en/latest/faq/#how-to-use-zeronet-in-tor-browser",
  1841. onmousedown: this.handleTorBrowserwarningClick,
  1842. onclick: Page.returnFalse
  1843. }, [h("span", "Your browser is not safe")]) : void 0, this.menu_torbrowserwarning.render(".menu-browserwarning"), parseFloat(Page.server_info.version.replace(".", "0")) < parseFloat(Page.latest_version.replace(".", "0")) ? h("a.newversion.dashboard-item", {
  1844. href: "#Update",
  1845. onmousedown: this.handleNewversionClick,
  1846. onclick: Page.returnFalse
  1847. }, "New ZeroNet version: " + Page.latest_version) : Page.server_info.rev < Page.latest_rev ? h("a.newversion.dashboard-item", {
  1848. href: "#Update",
  1849. onmousedown: this.handleNewversionClick,
  1850. onclick: Page.returnFalse
  1851. }, "New important fix: rev" + Page.latest_rev) : void 0, this.menu_newversion.render(".menu-newversion"), h("a.port.dashboard-item.donate", {
  1852. "href": "#Donate",
  1853. onmousedown: this.handleDonateClick,
  1854. onclick: Page.returnFalse
  1855. }, [h("div.icon-heart")]), this.menu_donate.render(".menu-donate"), Page.server_info.multiuser ? h("a.port.dashboard-item.multiuser", {
  1856. href: "#Multiuser",
  1857. onmousedown: this.handleMultiuserClick,
  1858. onclick: Page.returnFalse
  1859. }, [
  1860. h("span", "User: "), h("span.status", {
  1861. style: "color: " + (Text.toColor(Page.server_info.master_address))
  1862. }, Page.server_info.master_address.slice(0, 5) + ".." + Page.server_info.master_address.slice(-4))
  1863. ]) : void 0, Page.server_info.multiuser ? this.menu_multiuser.render(".menu-multiuser") : void 0, indexOf.call(Page.server_info.plugins, "UiPassword") >= 0 ? h("a.port.dashboard-item.logout", {
  1864. href: "#Logout",
  1865. onmousedown: this.handleLogoutClick,
  1866. onclick: Page.returnFalse
  1867. }, [h("span", "Logout")]) : void 0, h("a.port.dashboard-item.port", {
  1868. href: "#Port",
  1869. classes: {
  1870. bounce: this.port_checking
  1871. },
  1872. onmousedown: this.handlePortClick,
  1873. onclick: Page.returnFalse
  1874. }, [h("span", "Port: "), this.port_checking ? h("span.status", "Checking") : Page.server_info.ip_external === null ? h("span.status", "Checking") : Page.server_info.ip_external === true ? h("span.status.status-ok", "Opened") : this.isTorAlways ? h("span.status.status-ok", "Closed") : tor_title === "OK" ? h("span.status.status-warning", "Closed") : h("span.status.status-bad", "Closed")]), this.menu_port.render(".menu-port"), h("a.tor.dashboard-item.tor", {
  1875. href: "#Tor",
  1876. onmousedown: this.handleTorClick,
  1877. onclick: Page.returnFalse
  1878. }, [h("span", "Tor: "), tor_title === "OK" ? this.isTorAlways() ? h("span.status.status-ok", "Always") : h("span.status.status-ok", "Available") : h("span.status.status-warning", tor_title)]), this.menu_tor.render(".menu-tor"));
  1879. } else {
  1880. return h("div#Dashboard");
  1881. }
  1882. };
  1883. return Dashboard;
  1884. })(Class);
  1885. window.Dashboard = Dashboard;
  1886. }).call(this);
  1887. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageSites/FeedList.coffee ---- */
  1888. (function() {
  1889. var FeedList,
  1890. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1891. 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; },
  1892. hasProp = {}.hasOwnProperty;
  1893. FeedList = (function(superClass) {
  1894. extend(FeedList, superClass);
  1895. function FeedList() {
  1896. this.onSiteInfo = bind(this.onSiteInfo, this);
  1897. this.render = bind(this.render, this);
  1898. this.getClass = bind(this.getClass, this);
  1899. this.renderSearchStat = bind(this.renderSearchStat, this);
  1900. this.renderWelcome = bind(this.renderWelcome, this);
  1901. this.renderFeed = bind(this.renderFeed, this);
  1902. this.exitAnimation = bind(this.exitAnimation, this);
  1903. this.enterAnimation = bind(this.enterAnimation, this);
  1904. this.handleSearchClear = bind(this.handleSearchClear, this);
  1905. this.handleSearchInfoClick = bind(this.handleSearchInfoClick, this);
  1906. this.handleFilterClick = bind(this.handleFilterClick, this);
  1907. this.handleSearchKeyup = bind(this.handleSearchKeyup, this);
  1908. this.handleSearchInput = bind(this.handleSearchInput, this);
  1909. this.storeNodeSearch = bind(this.storeNodeSearch, this);
  1910. this.search = bind(this.search, this);
  1911. this.update = bind(this.update, this);
  1912. this.displayRows = bind(this.displayRows, this);
  1913. this.checkScroll = bind(this.checkScroll, this);
  1914. this.feeds = null;
  1915. this.searching = null;
  1916. this.searching_text = null;
  1917. this.searched = null;
  1918. this.res = null;
  1919. this.loading = false;
  1920. this.filter = null;
  1921. this.feed_types = {};
  1922. this.need_update = false;
  1923. this.updating = false;
  1924. this.limit = 30;
  1925. this.query_limit = 20;
  1926. this.query_day_limit = 3;
  1927. this.show_stats = false;
  1928. this.feed_keys = {};
  1929. Page.on_settings.then((function(_this) {
  1930. return function() {
  1931. _this.need_update = true;
  1932. return document.body.onscroll = function() {
  1933. return RateLimit(300, function() {
  1934. return _this.checkScroll();
  1935. });
  1936. };
  1937. };
  1938. })(this));
  1939. this;
  1940. }
  1941. FeedList.prototype.checkScroll = function() {
  1942. var ref, scroll_top;
  1943. scroll_top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  1944. if (scroll_top + window.innerHeight > document.getElementById("FeedList").clientHeight - 400 && !this.updating && ((ref = this.feeds) != null ? ref.length : void 0) > 5 && Page.mode === "Sites" && this.limit < 300) {
  1945. this.limit += 30;
  1946. this.query_limit += 30;
  1947. this.query_day_limit += 5;
  1948. this.log("checkScroll update");
  1949. this.update();
  1950. return true;
  1951. } else {
  1952. return false;
  1953. }
  1954. };
  1955. FeedList.prototype.displayRows = function(rows, search) {
  1956. var i, last_row, len, row, row_group;
  1957. this.feeds = [];
  1958. this.feed_keys = {};
  1959. if (!rows) {
  1960. return false;
  1961. }
  1962. rows.sort(function(a, b) {
  1963. return a.date_added + (a.type === "mention" ? 1 : 0) - b.date_added - (b.type === "mention" ? 1 : 0);
  1964. });
  1965. row_group = {};
  1966. last_row = {};
  1967. this.feed_types = {};
  1968. rows.reverse();
  1969. for (i = 0, len = rows.length; i < len; i++) {
  1970. row = rows[i];
  1971. if (last_row.body === row.body && last_row.date_added === row.date_added) {
  1972. continue;
  1973. }
  1974. if (row_group.type === row.type && row.url === row_group.url && row.site === row_group.site) {
  1975. if (row_group.body_more == null) {
  1976. row_group.body_more = [];
  1977. row_group.body_more.push(row.body);
  1978. } else if (row_group.body_more.length < 3) {
  1979. row_group.body_more.push(row.body);
  1980. } else {
  1981. if (row_group.more == null) {
  1982. row_group.more = 0;
  1983. }
  1984. row_group.more += 1;
  1985. }
  1986. row_group.feed_id = row.date_added;
  1987. } else {
  1988. if (row.feed_id == null) {
  1989. row.feed_id = row.date_added;
  1990. }
  1991. row.key = row.site + row.type + row.title + row.feed_id;
  1992. if (this.feed_keys[row.key]) {
  1993. this.log("Duplicate feed key: " + row.key);
  1994. } else {
  1995. this.feeds.push(row);
  1996. }
  1997. this.feed_keys[row.key] = true;
  1998. row_group = row;
  1999. }
  2000. this.feed_types[row.type] = true;
  2001. last_row = row;
  2002. }
  2003. return Page.projector.scheduleRender();
  2004. };
  2005. FeedList.prototype.update = function(cb) {
  2006. var params;
  2007. if (this.searching || this.updating) {
  2008. return false;
  2009. }
  2010. if (!Page.server_info || Page.server_info.rev < 1850) {
  2011. params = [];
  2012. } else {
  2013. params = [this.query_limit, this.query_day_limit];
  2014. }
  2015. this.logStart("Updating feed");
  2016. this.updating = true;
  2017. return Page.cmd("feedQuery", params, (function(_this) {
  2018. return function(res) {
  2019. var rows;
  2020. if (res.rows) {
  2021. rows = res.rows;
  2022. } else {
  2023. rows = res;
  2024. }
  2025. _this.res = res;
  2026. if (rows.length < 10 && _this.day_limit !== null) {
  2027. _this.limit = 20;
  2028. _this.day_limit = null;
  2029. _this.updating = false;
  2030. _this.update();
  2031. return false;
  2032. }
  2033. _this.displayRows(rows);
  2034. setTimeout(_this.checkScroll, 100);
  2035. _this.logEnd("Updating feed");
  2036. if (cb) {
  2037. cb();
  2038. }
  2039. return _this.updating = false;
  2040. };
  2041. })(this));
  2042. };
  2043. FeedList.prototype.search = function(search, cb) {
  2044. if (Page.server_info.rev < 1230) {
  2045. this.displayRows([]);
  2046. if (cb) {
  2047. cb();
  2048. }
  2049. return;
  2050. }
  2051. this.log("Searching for", search);
  2052. this.loading = true;
  2053. return Page.cmd("feedSearch", search, (function(_this) {
  2054. return function(res) {
  2055. _this.loading = false;
  2056. _this.displayRows(res["rows"], search);
  2057. delete res["rows"];
  2058. _this.res = res;
  2059. _this.searched = search;
  2060. if (cb) {
  2061. return cb();
  2062. }
  2063. };
  2064. })(this));
  2065. };
  2066. FeedList.prototype.storeNodeSearch = function(node) {
  2067. return document.body.onkeypress = (function(_this) {
  2068. return function(e) {
  2069. var ref, ref1;
  2070. if ((ref = e.charCode) === 0 || ref === 32) {
  2071. return;
  2072. }
  2073. if (((ref1 = document.activeElement) != null ? ref1.tagName : void 0) !== "INPUT") {
  2074. return node.focus();
  2075. }
  2076. };
  2077. })(this);
  2078. };
  2079. FeedList.prototype.handleSearchInput = function(e) {
  2080. var delay;
  2081. if (this.searching && this.searching.length > 3) {
  2082. delay = 100;
  2083. } else if (this.searching) {
  2084. delay = 300;
  2085. } else {
  2086. delay = 600;
  2087. }
  2088. this.searching = e.target.value;
  2089. this.searching_text = this.searching.replace(/[^ ]+:.*$/, "").trim();
  2090. if (Page.server_info.rev < 1230) {
  2091. this.feeds = [];
  2092. this.feed_keys = {};
  2093. }
  2094. if (e.target.value === "") {
  2095. delay = 1;
  2096. }
  2097. clearInterval(this.input_timer);
  2098. setTimeout((function(_this) {
  2099. return function() {
  2100. return _this.loading = true;
  2101. };
  2102. })(this));
  2103. this.input_timer = setTimeout(((function(_this) {
  2104. return function() {
  2105. return RateLimitCb(delay, function(cb_done) {
  2106. _this.loading = false;
  2107. if (_this.searching) {
  2108. return _this.search(_this.searching, function() {
  2109. return cb_done();
  2110. });
  2111. } else {
  2112. return _this.update(function() {
  2113. cb_done();
  2114. if (!_this.searching) {
  2115. _this.searching = null;
  2116. }
  2117. return _this.searched = null;
  2118. });
  2119. }
  2120. });
  2121. };
  2122. })(this)), delay);
  2123. return false;
  2124. };
  2125. FeedList.prototype.handleSearchKeyup = function(e) {
  2126. if (e.keyCode === 27) {
  2127. e.target.value = "";
  2128. this.handleSearchInput(e);
  2129. }
  2130. return false;
  2131. };
  2132. FeedList.prototype.handleFilterClick = function(e) {
  2133. this.filter = e.target.getAttribute("href").replace("#", "");
  2134. if (this.filter === "all") {
  2135. this.filter = null;
  2136. }
  2137. return false;
  2138. };
  2139. FeedList.prototype.handleSearchInfoClick = function(e) {
  2140. this.show_stats = !this.show_stats;
  2141. return false;
  2142. };
  2143. FeedList.prototype.handleSearchClear = function(e) {
  2144. e.target.value = "";
  2145. this.handleSearchInput(e);
  2146. return false;
  2147. };
  2148. FeedList.prototype.formatTitle = function(title) {
  2149. if (this.searching_text && this.searching_text.length > 1) {
  2150. return Text.highlight(title, this.searching_text);
  2151. } else {
  2152. if (title) {
  2153. return title;
  2154. } else {
  2155. return "";
  2156. }
  2157. }
  2158. };
  2159. FeedList.prototype.formatBody = function(body, type) {
  2160. var username_formatted, username_match;
  2161. body = body.replace(/[\n\r]+/, "\n");
  2162. if (type === "comment" || type === "mention") {
  2163. username_match = body.match(/^(([a-zA-Z0-9\.]+)@[a-zA-Z0-9\.]+|@(.*?)):/);
  2164. if (username_match) {
  2165. if (username_match[2]) {
  2166. username_formatted = username_match[2] + " › ";
  2167. } else {
  2168. username_formatted = username_match[3] + " › ";
  2169. }
  2170. body = body.replace(/> \[(.*?)\].*/g, "$1: ");
  2171. body = body.replace(/^[ ]*>.*/gm, "");
  2172. body = body.replace(username_match[0], "");
  2173. } else {
  2174. username_formatted = "";
  2175. }
  2176. body = body.replace(/\n/g, " ");
  2177. body = body.trim();
  2178. if (this.searching_text && this.searching_text.length > 1) {
  2179. body = Text.highlight(body, this.searching_text);
  2180. if (body[0].length > 60 && body.length > 1) {
  2181. body[0] = "..." + body[0].slice(body[0].length - 50, +(body[0].length - 1) + 1 || 9e9);
  2182. }
  2183. return [h("b", Text.highlight(username_formatted, this.searching_text)), body];
  2184. } else {
  2185. body = body.slice(0, 201);
  2186. return [h("b", [username_formatted]), body];
  2187. }
  2188. } else {
  2189. body = body.replace(/\n/g, " ");
  2190. if (this.searching_text && this.searching_text.length > 1) {
  2191. body = Text.highlight(body, this.searching_text);
  2192. if (body[0].length > 60) {
  2193. body[0] = "..." + body[0].slice(body[0].length - 50, +(body[0].length - 1) + 1 || 9e9);
  2194. }
  2195. } else {
  2196. body = body.slice(0, 201);
  2197. }
  2198. return body;
  2199. }
  2200. };
  2201. FeedList.prototype.formatType = function(type, title) {
  2202. if (type === "comment") {
  2203. return "Comment on";
  2204. } else if (type === "mention") {
  2205. if (title) {
  2206. return "You got mentioned in";
  2207. } else {
  2208. return "You got mentioned";
  2209. }
  2210. } else {
  2211. return "";
  2212. }
  2213. };
  2214. FeedList.prototype.enterAnimation = function(elem, props) {
  2215. if (this.searching === null) {
  2216. return Animation.slideDown.apply(this, arguments);
  2217. } else {
  2218. return null;
  2219. }
  2220. };
  2221. FeedList.prototype.exitAnimation = function(elem, remove_func, props) {
  2222. if (this.searching === null) {
  2223. return Animation.slideUp.apply(this, arguments);
  2224. } else {
  2225. return remove_func();
  2226. }
  2227. };
  2228. FeedList.prototype.renderFeed = function(feed) {
  2229. var err, site, type_formatted;
  2230. if (this.filter && feed.type !== this.filter) {
  2231. return null;
  2232. }
  2233. try {
  2234. site = Page.site_list.item_list.items_bykey[feed.site];
  2235. type_formatted = this.formatType(feed.type, feed.title);
  2236. return h("div.feed." + feed.type, {
  2237. key: feed.key,
  2238. enterAnimation: this.enterAnimation,
  2239. exitAnimation: this.exitAnimation
  2240. }, [
  2241. h("div.details", [
  2242. h("a.site", {
  2243. href: site.getHref()
  2244. }, [site.row.content.title]), h("div.added", [Time.since(feed.date_added)])
  2245. ]), h("div.circle", {
  2246. style: "border-color: " + (Text.toColor(feed.type + site.row.address, 60, 60))
  2247. }), type_formatted ? h("span.type", type_formatted) : void 0, h("a.title", {
  2248. href: site.getHref() + feed.url
  2249. }, this.formatTitle(feed.title)), h("div.body", {
  2250. key: feed.body,
  2251. enterAnimation: this.enterAnimation,
  2252. exitAnimation: this.exitAnimation
  2253. }, this.formatBody(feed.body, feed.type)), feed.body_more ? feed.body_more.map((function(_this) {
  2254. return function(body_more) {
  2255. return h("div.body", {
  2256. key: body_more,
  2257. enterAnimation: _this.enterAnimation,
  2258. exitAnimation: _this.exitAnimation
  2259. }, _this.formatBody(body_more, feed.type));
  2260. };
  2261. })(this)) : void 0, feed.more > 0 ? h("a.more", {
  2262. href: site.getHref() + feed.url
  2263. }, ["+" + feed.more + " more"]) : void 0
  2264. ]);
  2265. } catch (error) {
  2266. err = error;
  2267. this.log(err);
  2268. return h("div", {
  2269. key: Time.timestamp()
  2270. });
  2271. }
  2272. };
  2273. FeedList.prototype.renderWelcome = function() {
  2274. return h("div.welcome", [
  2275. h("img", {
  2276. src: "img/logo.svg",
  2277. height: 150,
  2278. onerror: "this.src='img/logo.png'; this.onerror=null;"
  2279. }), h("h1", "Welcome to ZeroNet"), h("h2", "Let's build a decentralized Internet together!"), h("div.served", ["This site currently served by ", h("b.peers", Page.site_info["peers"] || "n/a"), " peers, without any central server."]), h("div.sites", [
  2280. h("h3", "Some sites we created:"), h("a.site.site-zeroboard", {
  2281. href: Text.getSiteUrl("Board.ZeroNetwork.bit")
  2282. }, [h("div.title", ["ZeroBoard"]), h("div.description", ["Simple messaging board"]), h("div.visit", ["Activate \u2501"])]), h("a.site.site-zerotalk", {
  2283. href: Text.getSiteUrl("Talk.ZeroNetwork.bit")
  2284. }, [h("div.title", ["ZeroTalk"]), h("div.description", ["Reddit-like, decentralized forum"]), h("div.visit", ["Activate \u2501"])]), h("a.site.site-zeroblog", {
  2285. href: Text.getSiteUrl("Blog.ZeroNetwork.bit")
  2286. }, [h("div.title", ["ZeroBlog"]), h("div.description", ["Microblogging platform"]), h("div.visit", ["Activate \u2501"])]), h("a.site.site-zeromail", {
  2287. href: Text.getSiteUrl("Mail.ZeroNetwork.bit")
  2288. }, [h("div.title", ["ZeroMail"]), h("div.description", ["End-to-end encrypted mailing"]), h("div.visit", ["Activate \u2501"])]), h("a.site.site-zerome", {
  2289. href: Text.getSiteUrl("Me.ZeroNetwork.bit")
  2290. }, [h("div.title", ["ZeroMe"]), h("div.description", ["P2P social network"]), h("div.visit", ["Activate \u2501"])]), h("a.site.site-zerosites", {
  2291. href: Text.getSiteUrl("Sites.ZeroNetwork.bit")
  2292. }, [h("div.title", ["ZeroSites"]), h("div.description", ["Discover more sites"]), h("div.visit", ["Activate \u2501"])])
  2293. ])
  2294. ]);
  2295. };
  2296. FeedList.prototype.renderSearchStat = function(stat) {
  2297. var site, total_taken;
  2298. if (stat.taken === 0) {
  2299. return null;
  2300. }
  2301. total_taken = this.res.taken;
  2302. site = Page.site_list.item_list.items_bykey[stat.site];
  2303. if (!site) {
  2304. return [];
  2305. }
  2306. return h("tr", {
  2307. key: stat.site + "_" + stat.feed_name,
  2308. classes: {
  2309. "slow": stat.taken > total_taken * 0.1,
  2310. "extra-slow": stat.taken > total_taken * 0.3
  2311. }
  2312. }, [
  2313. h("td.site", h("a.site", {
  2314. href: site.getHref()
  2315. }, [site.row.content.title])), h("td.feed_name", stat.feed_name), h("td.taken", (stat.taken != null ? stat.taken + "s" : "n/a "))
  2316. ]);
  2317. };
  2318. FeedList.prototype.getClass = function() {
  2319. if (this.searching !== null) {
  2320. return "search";
  2321. } else {
  2322. return "newsfeed.limit-" + this.limit;
  2323. }
  2324. };
  2325. FeedList.prototype.render = function() {
  2326. var feed_type, ref;
  2327. if (this.need_update) {
  2328. RateLimitCb(5000, this.update);
  2329. this.need_update = false;
  2330. }
  2331. if (this.feeds && Page.site_list.loaded && document.body.className !== "loaded" && !this.updating) {
  2332. if (document.body.scrollTop > 500) {
  2333. setTimeout((function() {
  2334. return document.body.className = "loaded";
  2335. }), 2000);
  2336. } else {
  2337. document.body.className = "loaded";
  2338. }
  2339. }
  2340. return h("div#FeedList.FeedContainer", {
  2341. classes: {
  2342. faded: Page.mute_list.visible
  2343. }
  2344. }, this.feeds === null || !Page.site_list.loaded ? h("div.loading") : this.feeds.length > 0 || this.searching !== null ? [
  2345. h("div.feeds-filters", [
  2346. h("a.feeds-filter", {
  2347. href: "#all",
  2348. classes: {
  2349. active: this.filter === null
  2350. },
  2351. onclick: this.handleFilterClick
  2352. }, "All"), (function() {
  2353. var results;
  2354. results = [];
  2355. for (feed_type in this.feed_types) {
  2356. results.push(h("a.feeds-filter", {
  2357. key: feed_type,
  2358. href: "#" + feed_type,
  2359. classes: {
  2360. active: this.filter === feed_type
  2361. },
  2362. onclick: this.handleFilterClick
  2363. }, feed_type));
  2364. }
  2365. return results;
  2366. }).call(this)
  2367. ]), h("div.feeds-line"), h("div.feeds-search", {
  2368. classes: {
  2369. "searching": this.searching,
  2370. "searched": this.searched,
  2371. "loading": this.loading
  2372. }
  2373. }, h("div.icon-magnifier"), this.loading ? h("div.loader", {
  2374. enterAnimation: Animation.show,
  2375. exitAnimation: Animation.hide
  2376. }, h("div.arc")) : void 0, h("input", {
  2377. type: "text",
  2378. placeholder: "Search in connected sites",
  2379. value: this.searching,
  2380. onkeyup: this.handleSearchKeyup,
  2381. oninput: this.handleSearchInput,
  2382. afterCreate: this.storeNodeSearch
  2383. }), this.searched && !this.loading ? h("a.search-clear.nolink", {
  2384. href: "#clear",
  2385. onclick: this.handleSearchClear,
  2386. enterAnimation: Animation.show,
  2387. exitAnimation: Animation.hide
  2388. }, "\u00D7") : void 0, ((ref = this.res) != null ? ref.stats : void 0) ? h("a.search-info.nolink", {
  2389. href: "#ShowStats",
  2390. enterAnimation: Animation.show,
  2391. exitAnimation: Animation.hide,
  2392. onclick: this.handleSearchInfoClick
  2393. }, (this.searching ? this.res.num + " results " : "") + ("from " + this.res.sites + " sites in " + (this.res.taken.toFixed(2)) + "s")) : void 0, this.show_stats ? h("div.search-info-stats", {
  2394. enterAnimation: Animation.slideDown,
  2395. exitAnimation: Animation.slideUp
  2396. }, [h("table", [h("tr", h("th", "Site"), h("th", "Feed"), h("th.taken", "Taken")), this.res.stats.map(this.renderSearchStat)])]) : void 0, Page.server_info.rev < 1230 && this.searching ? h("div.search-noresult", {
  2397. enterAnimation: Animation.show
  2398. }, [
  2399. "You need to ", h("a", {
  2400. href: "#Update",
  2401. onclick: Page.head.handleUpdateZeronetClick
  2402. }, "update"), " your ZeroNet client to use the search feature!"
  2403. ]) : this.feeds.length === 0 && this.searched ? h("div.search-noresult", {
  2404. enterAnimation: Animation.show
  2405. }, "No results for " + this.searched) : void 0), h("div.FeedList." + this.getClass(), {
  2406. classes: {
  2407. loading: this.loading
  2408. }
  2409. }, this.feeds.slice(0, +this.limit + 1 || 9e9).map(this.renderFeed))
  2410. ] : this.renderWelcome());
  2411. };
  2412. FeedList.prototype.onSiteInfo = function(site_info) {
  2413. var ref, ref1, ref2;
  2414. if (((ref = site_info.event) != null ? ref[0] : void 0) === "file_done" && ((ref1 = site_info.event) != null ? ref1[1].endsWith(".json") : void 0) && !((ref2 = site_info.event) != null ? ref2[1].endsWith("content.json") : void 0)) {
  2415. if (!this.searching) {
  2416. return this.need_update = true;
  2417. }
  2418. }
  2419. };
  2420. return FeedList;
  2421. })(Class);
  2422. window.FeedList = FeedList;
  2423. }).call(this);
  2424. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageSites/MuteList.coffee ---- */
  2425. (function() {
  2426. var MuteList,
  2427. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2428. 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; },
  2429. hasProp = {}.hasOwnProperty;
  2430. MuteList = (function(superClass) {
  2431. extend(MuteList, superClass);
  2432. function MuteList() {
  2433. this.show = bind(this.show, this);
  2434. this.render = bind(this.render, this);
  2435. this.handleMuteRemoveClick = bind(this.handleMuteRemoveClick, this);
  2436. this.handleHideClick = bind(this.handleHideClick, this);
  2437. this.update = bind(this.update, this);
  2438. this.mutes = null;
  2439. this.visible = false;
  2440. Page.on_settings.then((function(_this) {
  2441. return function() {
  2442. return _this.need_update = true;
  2443. };
  2444. })(this));
  2445. this;
  2446. }
  2447. MuteList.prototype.update = function() {
  2448. this.need_update = false;
  2449. return Page.cmd("MuteList", [], (function(_this) {
  2450. return function(res) {
  2451. var auth_address, mute;
  2452. _this.mutes = [];
  2453. for (auth_address in res) {
  2454. mute = res[auth_address];
  2455. mute.auth_address = auth_address;
  2456. mute.site = Page.site_list.sites_byaddress[mute.source];
  2457. _this.mutes.push(mute);
  2458. }
  2459. _this.mutes.sort(function(a, b) {
  2460. return b.date_added - a.date_added;
  2461. });
  2462. return Page.projector.scheduleRender();
  2463. };
  2464. })(this));
  2465. };
  2466. MuteList.prototype.handleHideClick = function() {
  2467. return this.visible = false;
  2468. };
  2469. MuteList.prototype.handleMuteRemoveClick = function(e) {
  2470. var mute;
  2471. mute = e.target.mute;
  2472. if (mute.removed) {
  2473. Page.cmd("muteAdd", [mute.auth_address, mute.cert_user_id, mute.reason]);
  2474. } else {
  2475. Page.cmd("muteRemove", mute.auth_address);
  2476. }
  2477. mute.removed = !mute.removed;
  2478. return false;
  2479. };
  2480. MuteList.prototype.render = function() {
  2481. var max_height;
  2482. if (this.need_update) {
  2483. this.update();
  2484. }
  2485. if (!this.mutes) {
  2486. return h("div#MuteList", {
  2487. classes: {
  2488. visible: false
  2489. }
  2490. }, "Muted");
  2491. }
  2492. if (this.visible) {
  2493. max_height = 100 + this.mutes.length * 70;
  2494. } else {
  2495. max_height = 0;
  2496. }
  2497. return h("div#MuteList", {
  2498. classes: {
  2499. visible: this.visible
  2500. },
  2501. style: "max-height: " + max_height + "px"
  2502. }, [
  2503. h("a.mute-hide", {
  2504. href: "#Hide",
  2505. onclick: this.handleHideClick
  2506. }, "\u2039 Back to feed"), this.mutes.length === 0 ? h("div.mute-empty", "Your mute list is empty! :)") : [
  2507. h("div.mute.mute-head", [
  2508. h("div.mute-col", "Muted user"), h("div.mute-col", {
  2509. style: "width: 66%"
  2510. }, "Why?")
  2511. ]), this.mutes.map((function(_this) {
  2512. return function(mute) {
  2513. return h("div.mute", {
  2514. key: mute.auth_address,
  2515. classes: {
  2516. removed: mute.removed
  2517. }
  2518. }, [
  2519. h("div.mute-col", [h("div.cert_user_id", mute.cert_user_id), h("div.auth_address", mute.auth_address)]), h("div.mute-col", {
  2520. style: "width: 66%"
  2521. }, [
  2522. h("div.source", mute.site != null ? mute.site.row.content.title : mute.source), h("div.reason", {
  2523. innerHTML: Text.renderMarked(mute.reason)
  2524. }), h("div.date_added", " \u2500 " + Time.since(mute.date_added))
  2525. ]), h("a.action", {
  2526. href: "#Unmute",
  2527. onclick: _this.handleMuteRemoveClick,
  2528. mute: mute
  2529. }, "×")
  2530. ]);
  2531. };
  2532. })(this))
  2533. ]
  2534. ]);
  2535. };
  2536. MuteList.prototype.show = function() {
  2537. this.visible = true;
  2538. this.need_update = true;
  2539. return Page.projector.scheduleRender();
  2540. };
  2541. return MuteList;
  2542. })(Class);
  2543. window.MuteList = MuteList;
  2544. }).call(this);
  2545. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageSites/Site.coffee ---- */
  2546. (function() {
  2547. var Site,
  2548. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2549. 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; },
  2550. hasProp = {}.hasOwnProperty,
  2551. 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; };
  2552. Site = (function(superClass) {
  2553. extend(Site, superClass);
  2554. function Site(row, item_list) {
  2555. this.item_list = item_list;
  2556. this.renderOptionalStats = bind(this.renderOptionalStats, this);
  2557. this.render = bind(this.render, this);
  2558. this.handleLimitIncreaseClick = bind(this.handleLimitIncreaseClick, this);
  2559. this.handleHelpsClick = bind(this.handleHelpsClick, this);
  2560. this.handleHelpAllClick = bind(this.handleHelpAllClick, this);
  2561. this.handleHelpClick = bind(this.handleHelpClick, this);
  2562. this.handleSettingsClick = bind(this.handleSettingsClick, this);
  2563. this.handleDeleteClick = bind(this.handleDeleteClick, this);
  2564. this.handleCloneUpgradeClick = bind(this.handleCloneUpgradeClick, this);
  2565. this.handleCloneClick = bind(this.handleCloneClick, this);
  2566. this.handlePauseClick = bind(this.handlePauseClick, this);
  2567. this.handleResumeClick = bind(this.handleResumeClick, this);
  2568. this.handleCheckfilesClick = bind(this.handleCheckfilesClick, this);
  2569. this.handleUpdateClick = bind(this.handleUpdateClick, this);
  2570. this.handleUnfavoriteClick = bind(this.handleUnfavoriteClick, this);
  2571. this.handleFavoriteClick = bind(this.handleFavoriteClick, this);
  2572. this.deleted = false;
  2573. this.show_errors = false;
  2574. this.message_visible = false;
  2575. this.message = null;
  2576. this.message_class = "";
  2577. this.message_collapsed = false;
  2578. this.message_timer = null;
  2579. this.favorite = Page.settings.favorite_sites[row.address];
  2580. this.key = row.address;
  2581. this.optional_helps = [];
  2582. this.optional_helps_disabled = {};
  2583. this.setRow(row);
  2584. this.files = new SiteFiles(this);
  2585. this.menu = new Menu();
  2586. this.menu_helps = null;
  2587. }
  2588. Site.prototype.setRow = function(row) {
  2589. var key, ref, ref1, ref2, val;
  2590. if (((ref = row.event) != null ? ref[0] : void 0) === "updated" && row.content_updated !== false) {
  2591. this.setMessage("Updated!", "done");
  2592. } else if (((ref1 = row.event) != null ? ref1[0] : void 0) === "updating") {
  2593. this.setMessage("Updating...");
  2594. } else if (row.tasks > 0) {
  2595. this.setMessage("Updating: " + (Math.max(row.tasks, row.bad_files)) + " left");
  2596. } else if (row.bad_files > 0) {
  2597. if (row.peers <= 1) {
  2598. this.setMessage("No peers", "error");
  2599. } else {
  2600. this.setMessage(row.bad_files + " file update failed", "error");
  2601. }
  2602. } else if (row.content_updated === false) {
  2603. if (row.peers <= 1) {
  2604. this.setMessage("No peers", "error");
  2605. } else {
  2606. this.setMessage("Update failed", "error");
  2607. }
  2608. } else if (row.tasks === 0 && ((ref2 = this.row) != null ? ref2.tasks : void 0) > 0) {
  2609. this.setMessage("Updated!", "done");
  2610. }
  2611. if (row.body == null) {
  2612. row.body = "";
  2613. }
  2614. this.optional_helps = (function() {
  2615. var ref3, results;
  2616. ref3 = row.settings.optional_help;
  2617. results = [];
  2618. for (key in ref3) {
  2619. val = ref3[key];
  2620. results.push([key, val]);
  2621. }
  2622. return results;
  2623. })();
  2624. return this.row = row;
  2625. };
  2626. Site.prototype.setMessage = function(message, message_class) {
  2627. this.message_class = message_class != null ? message_class : "";
  2628. if (message) {
  2629. this.message = message;
  2630. this.message_visible = true;
  2631. if (this.message_class === "error" && !this.show_errors) {
  2632. this.message_collapsed = true;
  2633. } else {
  2634. this.message_collapsed = false;
  2635. }
  2636. } else {
  2637. this.message_visible = false;
  2638. }
  2639. clearInterval(this.message_timer);
  2640. if (this.message_class === "done") {
  2641. this.message_timer = setTimeout(((function(_this) {
  2642. return function() {
  2643. return _this.setMessage("");
  2644. };
  2645. })(this)), 5000);
  2646. }
  2647. return Page.projector.scheduleRender();
  2648. };
  2649. Site.prototype.isWorking = function() {
  2650. var ref;
  2651. return this.row.tasks > 0 || ((ref = this.row.event) != null ? ref[0] : void 0) === "updating";
  2652. };
  2653. Site.prototype.handleFavoriteClick = function() {
  2654. this.favorite = true;
  2655. this.menu = new Menu();
  2656. Page.settings.favorite_sites[this.row.address] = true;
  2657. Page.saveSettings();
  2658. Page.site_list.reorder();
  2659. return false;
  2660. };
  2661. Site.prototype.handleUnfavoriteClick = function() {
  2662. this.favorite = false;
  2663. this.menu = new Menu();
  2664. delete Page.settings.favorite_sites[this.row.address];
  2665. Page.saveSettings();
  2666. Page.site_list.reorder();
  2667. return false;
  2668. };
  2669. Site.prototype.handleUpdateClick = function() {
  2670. Page.cmd("siteUpdate", {
  2671. "address": this.row.address
  2672. });
  2673. this.show_errors = true;
  2674. return false;
  2675. };
  2676. Site.prototype.handleCheckfilesClick = function() {
  2677. Page.cmd("siteUpdate", {
  2678. "address": this.row.address,
  2679. "check_files": true,
  2680. since: 0
  2681. });
  2682. this.show_errors = true;
  2683. return false;
  2684. };
  2685. Site.prototype.handleResumeClick = function() {
  2686. Page.cmd("siteResume", {
  2687. "address": this.row.address
  2688. });
  2689. return false;
  2690. };
  2691. Site.prototype.handlePauseClick = function() {
  2692. Page.cmd("sitePause", {
  2693. "address": this.row.address
  2694. });
  2695. return false;
  2696. };
  2697. Site.prototype.handleCloneClick = function() {
  2698. Page.cmd("siteClone", {
  2699. "address": this.row.address
  2700. });
  2701. return false;
  2702. };
  2703. Site.prototype.handleCloneUpgradeClick = function() {
  2704. Page.cmd("wrapperConfirm", ["Are you sure?" + (" Any modifications you made on<br><b>" + this.row.content.title + "</b> site's js/css files will be lost."), "Upgrade"], (function(_this) {
  2705. return function(confirmed) {
  2706. return Page.cmd("siteClone", {
  2707. "address": _this.row.content.cloned_from,
  2708. "root_inner_path": _this.row.content.clone_root,
  2709. "target_address": _this.row.address
  2710. });
  2711. };
  2712. })(this));
  2713. return false;
  2714. };
  2715. Site.prototype.handleDeleteClick = function() {
  2716. if (this.row.settings.own) {
  2717. Page.cmd("wrapperNotification", ["error", "Sorry, you can't delete your own site.<br>Please remove the directory manually."]);
  2718. } else {
  2719. if (Page.server_info.rev > 2060) {
  2720. Page.cmd("wrapperConfirm", ["Are you sure?" + (" <b>" + this.row.content.title + "</b>"), ["Delete", "Blacklist"]], (function(_this) {
  2721. return function(confirmed) {
  2722. if (confirmed === 1) {
  2723. Page.cmd("siteDelete", {
  2724. "address": _this.row.address
  2725. });
  2726. _this.item_list.deleteItem(_this);
  2727. return Page.projector.scheduleRender();
  2728. } else if (confirmed === 2) {
  2729. return Page.cmd("wrapperPrompt", ["Blacklist <b>" + _this.row.content.title + "</b>", "text", "Delete and Blacklist", "Reason"], function(reason) {
  2730. Page.cmd("siteDelete", {
  2731. "address": _this.row.address
  2732. });
  2733. Page.cmd("blacklistAdd", [_this.row.address, reason]);
  2734. _this.item_list.deleteItem(_this);
  2735. return Page.projector.scheduleRender();
  2736. });
  2737. }
  2738. };
  2739. })(this));
  2740. } else {
  2741. Page.cmd("wrapperConfirm", ["Are you sure?" + (" <b>" + this.row.content.title + "</b>"), "Delete"], (function(_this) {
  2742. return function(confirmed) {
  2743. if (confirmed) {
  2744. Page.cmd("siteDelete", {
  2745. "address": _this.row.address
  2746. });
  2747. _this.item_list.deleteItem(_this);
  2748. return Page.projector.scheduleRender();
  2749. }
  2750. };
  2751. })(this));
  2752. }
  2753. }
  2754. return false;
  2755. };
  2756. Site.prototype.handleSettingsClick = function(e) {
  2757. this.menu.items = [];
  2758. if (this.favorite) {
  2759. this.menu.items.push(["Unfavorite", this.handleUnfavoriteClick]);
  2760. } else {
  2761. this.menu.items.push(["Favorite", this.handleFavoriteClick]);
  2762. }
  2763. this.menu.items.push(["Update", this.handleUpdateClick]);
  2764. this.menu.items.push(["Check files", this.handleCheckfilesClick]);
  2765. if (this.row.settings.serving) {
  2766. this.menu.items.push(["Pause", this.handlePauseClick]);
  2767. } else {
  2768. this.menu.items.push(["Resume", this.handleResumeClick]);
  2769. }
  2770. if (this.row.content.cloneable === true) {
  2771. this.menu.items.push(["Clone", this.handleCloneClick]);
  2772. }
  2773. if (this.row.settings.own && this.row.content.cloned_from && Page.server_info.rev >= 2080) {
  2774. this.menu.items.push(["---"]);
  2775. this.menu.items.push(["Upgrade code", this.handleCloneUpgradeClick]);
  2776. }
  2777. this.menu.items.push(["---"]);
  2778. this.menu.items.push(["Delete", this.handleDeleteClick]);
  2779. if (this.menu.visible) {
  2780. this.menu.hide();
  2781. } else {
  2782. this.menu.show();
  2783. }
  2784. return false;
  2785. };
  2786. Site.prototype.handleHelpClick = function(directory, title) {
  2787. if (this.optional_helps_disabled[directory]) {
  2788. Page.cmd("OptionalHelp", [directory, title, this.row.address]);
  2789. delete this.optional_helps_disabled[directory];
  2790. } else {
  2791. Page.cmd("OptionalHelpRemove", [directory, this.row.address]);
  2792. this.optional_helps_disabled[directory] = true;
  2793. }
  2794. return true;
  2795. };
  2796. Site.prototype.handleHelpAllClick = function() {
  2797. if (this.row.settings.autodownloadoptional === true) {
  2798. return Page.cmd("OptionalHelpAll", [false, this.row.address], (function(_this) {
  2799. return function() {
  2800. _this.row.settings.autodownloadoptional = false;
  2801. return Page.projector.scheduleRender();
  2802. };
  2803. })(this));
  2804. } else {
  2805. return Page.cmd("OptionalHelpAll", [true, this.row.address], (function(_this) {
  2806. return function() {
  2807. _this.row.settings.autodownloadoptional = true;
  2808. return Page.projector.scheduleRender();
  2809. };
  2810. })(this));
  2811. }
  2812. };
  2813. Site.prototype.handleHelpsClick = function(e) {
  2814. var directory, i, len, ref, ref1, title;
  2815. if (e.target.classList.contains("menu-item")) {
  2816. return;
  2817. }
  2818. if (!this.menu_helps) {
  2819. this.menu_helps = new Menu();
  2820. }
  2821. this.menu_helps.items = [];
  2822. this.menu_helps.items.push([
  2823. "Help distribute all new files", this.handleHelpAllClick, ((function(_this) {
  2824. return function() {
  2825. return _this.row.settings.autodownloadoptional;
  2826. };
  2827. })(this))
  2828. ]);
  2829. if (this.optional_helps.length > 0) {
  2830. this.menu_helps.items.push(["---"]);
  2831. }
  2832. ref = this.optional_helps;
  2833. for (i = 0, len = ref.length; i < len; i++) {
  2834. ref1 = ref[i], directory = ref1[0], title = ref1[1];
  2835. this.menu_helps.items.push([
  2836. title, ((function(_this) {
  2837. return function() {
  2838. return _this.handleHelpClick(directory, title);
  2839. };
  2840. })(this)), ((function(_this) {
  2841. return function() {
  2842. return !_this.optional_helps_disabled[directory];
  2843. };
  2844. })(this))
  2845. ]);
  2846. }
  2847. this.menu_helps.toggle();
  2848. return true;
  2849. };
  2850. Site.prototype.getHref = function(row) {
  2851. var has_plugin, href, ref, ref1;
  2852. has_plugin = (((ref = Page.server_info) != null ? ref.plugins : void 0) != null) && (indexOf.call(Page.server_info.plugins, "Zeroname") >= 0 || indexOf.call(Page.server_info.plugins, "Dnschain") >= 0 || indexOf.call(Page.server_info.plugins, "Zeroname-local") >= 0);
  2853. if (has_plugin && ((ref1 = this.row.content) != null ? ref1.domain : void 0)) {
  2854. href = Text.getSiteUrl(this.row.content.domain);
  2855. } else {
  2856. href = Text.getSiteUrl(this.row.address);
  2857. }
  2858. if (row != null ? row.inner_path : void 0) {
  2859. return href + row.inner_path;
  2860. } else {
  2861. return href;
  2862. }
  2863. };
  2864. Site.prototype.handleLimitIncreaseClick = function() {
  2865. if (Page.server_info.rev < 3170) {
  2866. return Page.cmd("wrapperNotification", ["info", "You need ZeroNet Rev3170 to use this command"]);
  2867. }
  2868. Page.cmd("as", [this.row.address, "siteSetLimit", this.row.need_limit], (function(_this) {
  2869. return function(res) {
  2870. if (res === "ok") {
  2871. Page.cmd("wrapperNotification", ["done", "Site <b>" + _this.row.content.title + "</b> storage limit modified to <b>" + _this.row.need_limit + "MB</b>", 5000]);
  2872. } else {
  2873. Page.cmd("wrapperNotification", ["error", res.error]);
  2874. }
  2875. return Page.projector.scheduleRender();
  2876. };
  2877. })(this));
  2878. return false;
  2879. };
  2880. Site.prototype.render = function() {
  2881. var now, ref;
  2882. now = Date.now() / 1000;
  2883. return h("div.site", {
  2884. key: this.key,
  2885. "data-key": this.key,
  2886. classes: {
  2887. "modified-lastday": now - this.row.settings.modified < 60 * 60 * 24,
  2888. "disabled": !this.row.settings.serving && !this.row.demo,
  2889. "working": this.isWorking()
  2890. }
  2891. }, h("div.circle", {
  2892. style: "color: " + (Text.toColor(this.row.address, 40, 50))
  2893. }, ["\u2022"]), h("a.inner", {
  2894. href: this.getHref(),
  2895. title: ((ref = this.row.content.title) != null ? ref.length : void 0) > 20 ? this.row.content.title : void 0
  2896. }, [
  2897. h("span.title", [this.row.content.title]), h("div.details", [h("span.modified", [h("div.icon-clock"), Page.settings.sites_orderby === "size" ? h("span.value", [(this.row.settings.size / 1024 / 1024 + (this.row.settings.size_optional != null) / 1024 / 1024).toFixed(1), "MB"]) : h("span.value", [Time.since(this.row.settings.modified)])]), h("span.peers", [h("div.icon-profile"), h("span.value", [Math.max((this.row.settings.peers ? this.row.settings.peers : 0), this.row.peers)])])]), this.row.demo ? h("div.details.demo", "Activate \u00BB") : void 0, this.row.need_limit ? h("a.details.needaction", {
  2898. href: "#Set+limit",
  2899. onclick: this.handleLimitIncreaseClick
  2900. }, "Set limit to " + this.row.need_limit + "MB") : void 0, h("div.message", {
  2901. classes: {
  2902. visible: this.message_visible,
  2903. done: this.message_class === 'done',
  2904. error: this.message_class === 'error',
  2905. collapsed: this.message_collapsed
  2906. }
  2907. }, [this.message])
  2908. ]), h("a.settings", {
  2909. href: "#Settings",
  2910. tabIndex: -1,
  2911. onmousedown: this.handleSettingsClick,
  2912. onclick: Page.returnFalse
  2913. }, ["\u22EE"]), this.menu.render());
  2914. };
  2915. Site.prototype.renderCircle = function(value, max) {
  2916. var dashoffset, stroke;
  2917. if (value < 1) {
  2918. dashoffset = 75 + (1 - value) * 75;
  2919. } else {
  2920. dashoffset = Math.max(0, 75 - ((value - 1) / 9) * 75);
  2921. }
  2922. stroke = "hsl(" + (Math.min(555, value * 50)) + ", 100%, 61%)";
  2923. return h("div.circle", {
  2924. title: "Upload/Download ratio",
  2925. innerHTML: "<svg class=\"circle-svg\" width=\"30\" height=\"30\" viewPort=\"0 0 30 30\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle r=\"12\" cx=\"15\" cy=\"15\" fill=\"transparent\" class='circle-bg'></circle>\n <circle r=\"12\" cx=\"15\" cy=\"15\" fill=\"transparent\" class='circle-fg' style='stroke-dashoffset: " + dashoffset + "; stroke: " + stroke + "'></circle>\n</svg>"
  2926. });
  2927. };
  2928. Site.prototype.renderOptionalStats = function() {
  2929. var ratio, ratio_hue, row;
  2930. row = this.row;
  2931. ratio = (row.settings.bytes_sent / row.settings.bytes_recv).toFixed(1);
  2932. if (ratio >= 100) {
  2933. ratio = "\u221E";
  2934. } else if (ratio >= 10) {
  2935. ratio = (row.settings.bytes_sent / row.settings.bytes_recv).toFixed(0);
  2936. }
  2937. ratio_hue = Math.min(555, (row.settings.bytes_sent / row.settings.bytes_recv) * 50);
  2938. return h("div.site", {
  2939. key: this.key
  2940. }, [
  2941. h("div.title", [
  2942. h("h3.name", h("a", {
  2943. href: this.getHref()
  2944. }, row.content.title)), h("div.size", {
  2945. title: "Site size limit: " + (Text.formatSize(row.size_limit * 1024 * 1024))
  2946. }, [
  2947. "" + (Text.formatSize(row.settings.size)), h("div.bar", h("div.bar-active", {
  2948. style: "width: " + (100 * (row.settings.size / (row.size_limit * 1024 * 1024))) + "%"
  2949. }))
  2950. ]), h("div.plus", "+"), h("div.size.size-optional", {
  2951. title: "Optional files on site: " + (Text.formatSize(row.settings.size_optional))
  2952. }, [
  2953. "" + (Text.formatSize(row.settings.optional_downloaded)), h("span.size-title", "Optional"), h("div.bar", h("div.bar-active", {
  2954. style: "width: " + (100 * (row.settings.optional_downloaded / row.settings.size_optional)) + "%"
  2955. }))
  2956. ]), h("a.helps", {
  2957. href: "#",
  2958. onmousedown: this.handleHelpsClick,
  2959. onclick: Page.returnFalse
  2960. }, h("div.icon-share"), this.row.settings.autodownloadoptional ? "\u2661" : this.optional_helps.length, h("div.icon-arrow-down"), this.menu_helps ? this.menu_helps.render() : void 0), this.renderCircle(parseFloat((row.settings.bytes_sent / row.settings.bytes_recv).toFixed(1)), 10), h("div.circle-value", {
  2961. classes: {
  2962. negative: ratio < 1
  2963. },
  2964. style: "color: hsl(" + ratio_hue + ", 70%, 60%)"
  2965. }, ratio), h("div.transfers", [
  2966. h("div.up", {
  2967. "title": "Uploaded"
  2968. }, "\u22F0 \u00A0" + (Text.formatSize(row.settings.bytes_sent))), h("div.down", {
  2969. "title": "Downloaded"
  2970. }, "\u22F1 \u00A0" + (Text.formatSize(row.settings.bytes_recv)))
  2971. ])
  2972. ]), this.files.render()
  2973. ]);
  2974. };
  2975. return Site;
  2976. })(Class);
  2977. window.Site = Site;
  2978. }).call(this);
  2979. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageSites/SiteList.coffee ---- */
  2980. (function() {
  2981. var SiteList,
  2982. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2983. 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; },
  2984. hasProp = {}.hasOwnProperty;
  2985. SiteList = (function(superClass) {
  2986. extend(SiteList, superClass);
  2987. function SiteList() {
  2988. this.onSiteInfo = bind(this.onSiteInfo, this);
  2989. this.render = bind(this.render, this);
  2990. this.handleFilterClear = bind(this.handleFilterClear, this);
  2991. this.handleFilterKeyup = bind(this.handleFilterKeyup, this);
  2992. this.handleFilterInput = bind(this.handleFilterInput, this);
  2993. this.renderMergedSites = bind(this.renderMergedSites, this);
  2994. this.reorder = bind(this.reorder, this);
  2995. this.sortRows = bind(this.sortRows, this);
  2996. this.reorderTimer = bind(this.reorderTimer, this);
  2997. this.item_list = new ItemList(Site, "address");
  2998. this.sites = this.item_list.items;
  2999. this.sites_byaddress = this.item_list.items_bykey;
  3000. this.inactive_demo_sites = null;
  3001. this.loaded = false;
  3002. this.schedule_reorder = false;
  3003. this.merged_db = {};
  3004. this.filtering = "";
  3005. setInterval(this.reorderTimer, 10000);
  3006. Page.on_settings.then((function(_this) {
  3007. return function() {
  3008. _this.update();
  3009. return Page.cmd("channelJoinAllsite", {
  3010. "channel": "siteChanged"
  3011. });
  3012. };
  3013. })(this));
  3014. }
  3015. SiteList.prototype.reorderTimer = function() {
  3016. if (!this.schedule_reorder) {
  3017. return;
  3018. }
  3019. if (!document.querySelector('.left:hover') && !document.querySelector(".working") && !Page.mode === "Files") {
  3020. this.reorder();
  3021. return this.schedule_reorder = false;
  3022. }
  3023. };
  3024. SiteList.prototype.sortRows = function(rows) {
  3025. if (Page.settings.sites_orderby === "modified") {
  3026. rows.sort(function(a, b) {
  3027. return b.row.settings.modified - a.row.settings.modified;
  3028. });
  3029. } else if (Page.settings.sites_orderby === "addtime") {
  3030. rows.sort(function(a, b) {
  3031. return (b.row.settings.added || 0) - (a.row.settings.added || 0);
  3032. });
  3033. } else if (Page.settings.sites_orderby === "size") {
  3034. rows.sort(function(a, b) {
  3035. return b.row.settings.size - a.row.settings.size;
  3036. });
  3037. } else {
  3038. rows.sort(function(a, b) {
  3039. return Math.max(b.row.peers, b.row.settings.peers) - Math.max(a.row.peers, a.row.settings.peers);
  3040. });
  3041. }
  3042. return rows;
  3043. };
  3044. SiteList.prototype.reorder = function() {
  3045. this.sortRows(this.item_list.items);
  3046. return Page.projector.scheduleRender();
  3047. };
  3048. SiteList.prototype.update = function() {
  3049. Page.cmd("siteList", {}, (function(_this) {
  3050. return function(site_rows) {
  3051. var favorite_sites;
  3052. favorite_sites = Page.settings.favorite_sites;
  3053. _this.item_list.sync(site_rows);
  3054. _this.sortRows(_this.item_list.items);
  3055. if (_this.inactive_demo_sites === null) {
  3056. _this.updateInactiveDemoSites();
  3057. }
  3058. Page.projector.scheduleRender();
  3059. return _this.loaded = true;
  3060. };
  3061. })(this));
  3062. return this;
  3063. };
  3064. SiteList.prototype.updateInactiveDemoSites = function() {
  3065. var demo_site_rows, i, len, results, site_row;
  3066. demo_site_rows = [
  3067. {
  3068. address: "1Gfey7wVXXg1rxk751TBTxLJwhddDNfcdp",
  3069. demo: true,
  3070. content: {
  3071. title: "ZeroBoard",
  3072. domain: "Board.ZeroNetwork.bit"
  3073. },
  3074. settings: {}
  3075. }, {
  3076. address: "1TaLkFrMwvbNsooF4ioKAY9EuxTBTjipT",
  3077. demo: true,
  3078. content: {
  3079. title: "ZeroTalk",
  3080. domain: "Talk.ZeroNetwork.bit"
  3081. },
  3082. settings: {}
  3083. }, {
  3084. address: "1BLogC9LN4oPDcruNz3qo1ysa133E9AGg8",
  3085. demo: true,
  3086. content: {
  3087. title: "ZeroBlog",
  3088. domain: "Blog.ZeroNetwork.bit"
  3089. },
  3090. settings: {}
  3091. }, {
  3092. address: "1MaiL5gfBM1cyb4a8e3iiL8L5gXmoAJu27",
  3093. demo: true,
  3094. content: {
  3095. title: "ZeroMail",
  3096. domain: "Mail.ZeroNetwork.bit"
  3097. },
  3098. settings: {}
  3099. }, {
  3100. address: "1uPLoaDwKzP6MCGoVzw48r4pxawRBdmQc",
  3101. demo: true,
  3102. content: {
  3103. title: "ZeroUp"
  3104. },
  3105. settings: {}
  3106. }, {
  3107. address: "1Gif7PqWTzVWDQ42Mo7np3zXmGAo3DXc7h",
  3108. demo: true,
  3109. content: {
  3110. title: "GIF Time"
  3111. },
  3112. settings: {}
  3113. }, {
  3114. address: "1SiTEs2D3rCBxeMoLHXei2UYqFcxctdwB",
  3115. demo: true,
  3116. content: {
  3117. title: "More @ ZeroSites",
  3118. domain: "Sites.ZeroNetwork.bit"
  3119. },
  3120. settings: {}
  3121. }
  3122. ];
  3123. if (Page.server_info.rev >= 1400) {
  3124. demo_site_rows.push({
  3125. address: "1MeFqFfFFGQfa1J3gJyYYUvb5Lksczq7nH",
  3126. demo: true,
  3127. content: {
  3128. title: "ZeroMe",
  3129. domain: "Me.ZeroNetwork.bit"
  3130. },
  3131. settings: {}
  3132. });
  3133. }
  3134. this.inactive_demo_sites = [];
  3135. results = [];
  3136. for (i = 0, len = demo_site_rows.length; i < len; i++) {
  3137. site_row = demo_site_rows[i];
  3138. if (this.filtering && site.row.content.title.toLowerCase().indexOf(this.filtering.toLowerCase()) === -1) {
  3139. continue;
  3140. }
  3141. if (!this.sites_byaddress[site_row.address]) {
  3142. results.push(this.inactive_demo_sites.push(new Site(site_row)));
  3143. } else {
  3144. results.push(void 0);
  3145. }
  3146. }
  3147. return results;
  3148. };
  3149. SiteList.prototype.renderMergedSites = function() {
  3150. var back, i, len, merged_db, merged_sites, merged_type, name, ref, site;
  3151. merged_db = {};
  3152. ref = this.sites_merged;
  3153. for (i = 0, len = ref.length; i < len; i++) {
  3154. site = ref[i];
  3155. if (!site.row.content.merged_type) {
  3156. continue;
  3157. }
  3158. if (merged_db[name = site.row.content.merged_type] == null) {
  3159. merged_db[name] = [];
  3160. }
  3161. merged_db[site.row.content.merged_type].push(site);
  3162. }
  3163. back = [];
  3164. for (merged_type in merged_db) {
  3165. merged_sites = merged_db[merged_type];
  3166. back.push([
  3167. h("h2.more", {
  3168. key: "Merged: " + merged_type
  3169. }, "Merged: " + merged_type), h("div.SiteList.merged.merged-" + merged_type, merged_sites.map(function(item) {
  3170. return item.render();
  3171. }))
  3172. ]);
  3173. }
  3174. return back;
  3175. };
  3176. SiteList.prototype.handleFilterInput = function(e) {
  3177. return this.filtering = e.target.value;
  3178. };
  3179. SiteList.prototype.handleFilterKeyup = function(e) {
  3180. if (e.keyCode === 27) {
  3181. e.target.value = "";
  3182. this.handleFilterInput(e);
  3183. }
  3184. return false;
  3185. };
  3186. SiteList.prototype.handleFilterClear = function(e) {
  3187. e.target.value = "";
  3188. this.handleFilterInput(e);
  3189. return false;
  3190. };
  3191. SiteList.prototype.render = function() {
  3192. var filter_base, i, len, ref, ref1, site;
  3193. if (!this.loaded) {
  3194. return h("div#SiteList");
  3195. }
  3196. this.sites_needaction = [];
  3197. this.sites_favorited = [];
  3198. this.sites_owned = [];
  3199. this.sites_connected = [];
  3200. this.sites_merged = [];
  3201. ref = this.sites;
  3202. for (i = 0, len = ref.length; i < len; i++) {
  3203. site = ref[i];
  3204. if (this.filtering) {
  3205. filter_base = site.row.content.title + site.row.content.merged_type + site.row.address;
  3206. if (filter_base.toLowerCase().indexOf(this.filtering.toLowerCase()) === -1) {
  3207. continue;
  3208. }
  3209. }
  3210. if (site.row.settings.size * 1.2 > site.row.size_limit * 1024 * 1024) {
  3211. site.row.need_limit = site.row.size_limit * 2;
  3212. this.sites_needaction.push(site);
  3213. } else if (site.favorite) {
  3214. this.sites_favorited.push(site);
  3215. } else if (site.row.content.merged_type) {
  3216. this.sites_merged.push(site);
  3217. } else if ((ref1 = site.row.settings) != null ? ref1.own : void 0) {
  3218. this.sites_owned.push(site);
  3219. } else {
  3220. this.sites_connected.push(site);
  3221. }
  3222. }
  3223. return h("div#SiteList", [
  3224. this.sites.length > 20 ? h("input.site-filter", {
  3225. placeholder: "Filter: Site name",
  3226. spellcheck: false,
  3227. oninput: this.handleFilterInput,
  3228. onkeyup: this.handleFilterKeyup,
  3229. value: this.filtering
  3230. }) : void 0, this.filtering ? h("a.filter-clear", {
  3231. href: "#clear",
  3232. onclick: this.handleFilterClear
  3233. }, "\u00D7") : void 0, this.sites_needaction.length > 0 ? h("h2.needaction", "Running out of size limit:") : void 0, h("div.SiteList.needaction", this.sites_needaction.map(function(item) {
  3234. return item.render();
  3235. })), this.sites_favorited.length > 0 ? h("h2.favorited", "Favorited sites:") : void 0, h("div.SiteList.favorited", this.sites_favorited.map(function(item) {
  3236. return item.render();
  3237. })), this.sites_owned.length > 0 ? h("h2.owned", "Owned sites:") : void 0, h("div.SiteList.owned", this.sites_owned.map(function(item) {
  3238. return item.render();
  3239. })), this.sites_connected.length > 0 ? h("h2.connected", "Connected sites:") : void 0, h("div.SiteList.connected", this.sites_connected.map(function(item) {
  3240. return item.render();
  3241. })), this.renderMergedSites(), this.inactive_demo_sites !== null && this.inactive_demo_sites.length > 0 ? [
  3242. h("h2.more", {
  3243. key: "More"
  3244. }, "More sites:"), h("div.SiteList.more", this.inactive_demo_sites.map(function(item) {
  3245. return item.render();
  3246. }))
  3247. ] : void 0
  3248. ]);
  3249. };
  3250. SiteList.prototype.onSiteInfo = function(site_info) {
  3251. var ref;
  3252. if ((ref = this.item_list.items_bykey[site_info.address]) != null) {
  3253. ref.setRow(site_info);
  3254. }
  3255. this.schedule_reorder = true;
  3256. return Page.projector.scheduleRender();
  3257. };
  3258. return SiteList;
  3259. })(Class);
  3260. window.SiteList = SiteList;
  3261. }).call(this);
  3262. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageSites/Trigger.coffee ---- */
  3263. (function() {
  3264. var Trigger,
  3265. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3266. 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; },
  3267. hasProp = {}.hasOwnProperty;
  3268. Trigger = (function(superClass) {
  3269. extend(Trigger, superClass);
  3270. function Trigger() {
  3271. this.render = bind(this.render, this);
  3272. this.handleTitleClick = bind(this.handleTitleClick, this);
  3273. this.active = false;
  3274. }
  3275. Trigger.prototype.handleTitleClick = function() {
  3276. this.active = !this.active;
  3277. if (this.active) {
  3278. document.getElementById("left").classList.add("trigger-on");
  3279. } else {
  3280. document.getElementById("left").classList.remove("trigger-on");
  3281. }
  3282. return false;
  3283. };
  3284. Trigger.prototype.render = function() {
  3285. return h("div.Trigger", {
  3286. classes: {
  3287. "active": this.active
  3288. }
  3289. }, [
  3290. h("a.icon", {
  3291. "href": "#Trigger",
  3292. onclick: this.handleTitleClick,
  3293. ontouchend: ""
  3294. }, h("div.arrow-right"))
  3295. ]);
  3296. };
  3297. return Trigger;
  3298. })(Class);
  3299. window.Trigger = Trigger;
  3300. }).call(this);
  3301. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/Chart.coffee ---- */
  3302. (function() {
  3303. var Chart,
  3304. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3305. 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; },
  3306. hasProp = {}.hasOwnProperty;
  3307. Chart = (function(superClass) {
  3308. extend(Chart, superClass);
  3309. function Chart() {
  3310. this.render = bind(this.render, this);
  3311. this.updateChart = bind(this.updateChart, this);
  3312. this.update = bind(this.update, this);
  3313. this.getTitle = bind(this.getTitle, this);
  3314. this.initChart = bind(this.initChart, this);
  3315. this.query = "";
  3316. this.title = "";
  3317. this.value = "";
  3318. this.line_data = [];
  3319. this.details = [];
  3320. this.colorize = "cc00ff0a";
  3321. this.chart_ctx = null;
  3322. this.chart_type_name = null;
  3323. this.need_update = false;
  3324. }
  3325. Chart.prototype.initChart = function(node) {
  3326. this.chart_canvas = node;
  3327. return this.chart_ctx = node.getContext("2d");
  3328. };
  3329. Chart.prototype.getTitle = function() {
  3330. return this.title;
  3331. };
  3332. Chart.prototype.update = function() {
  3333. var query_type_data, type_name;
  3334. Page.cmd("chartDbQuery", this.getChartQuery(), (function(_this) {
  3335. return function(res) {
  3336. var j, len, row;
  3337. _this.line_data = [];
  3338. for (j = 0, len = res.length; j < len; j++) {
  3339. row = res[j];
  3340. _this.line_data.push(row.value);
  3341. }
  3342. _this.line_data.reverse();
  3343. return _this.updateChart();
  3344. };
  3345. })(this));
  3346. query_type_data = "SELECT * FROM data\nWHERE\n type_id IN :type_ids AND\n date_added = (SELECT date_added FROM data ORDER BY data_id DESC LIMIT 1)";
  3347. return Page.cmd("chartDbQuery", [
  3348. query_type_data, {
  3349. type_ids: (function() {
  3350. var j, len, ref, results;
  3351. ref = this.type_names;
  3352. results = [];
  3353. for (j = 0, len = ref.length; j < len; j++) {
  3354. type_name = ref[j];
  3355. results.push(Page.page_stats.type_id_db[type_name]);
  3356. }
  3357. return results;
  3358. }).call(this)
  3359. }
  3360. ], (function(_this) {
  3361. return function(res) {
  3362. var j, len, row, type_data;
  3363. type_data = {};
  3364. for (j = 0, len = res.length; j < len; j++) {
  3365. row = res[j];
  3366. type_data[Page.page_stats.type_name_db[row.type_id]] = row.value;
  3367. }
  3368. _this.details = typeof _this.formatDetails === "function" ? _this.formatDetails(type_data) : void 0;
  3369. _this.value = typeof _this.formatValue === "function" ? _this.formatValue(type_data) : void 0;
  3370. return Page.projector.scheduleRender();
  3371. };
  3372. })(this));
  3373. };
  3374. Chart.prototype.updateChart = function() {
  3375. var data, data_max, data_min, gradient, i, j, len, line_y, ref, step, stroke;
  3376. this.chart_ctx.clearRect(0, 0, this.chart_canvas.width, this.chart_canvas.height);
  3377. stroke = this.chart_ctx.createLinearGradient(0, 0, 900, 0);
  3378. stroke.addColorStop(0, this.chart_stroke[0]);
  3379. stroke.addColorStop(1, this.chart_stroke[1]);
  3380. this.chart_ctx.lineWidth = 4;
  3381. this.chart_ctx.strokeStyle = stroke;
  3382. this.chart_ctx.fillStyle = '#66666611';
  3383. gradient = this.chart_ctx.createLinearGradient(0, 200, 0, 400);
  3384. gradient.addColorStop(0, "#42324599");
  3385. gradient.addColorStop(1, "#2C2E3700");
  3386. this.chart_ctx.fillStyle = gradient;
  3387. this.chart_ctx.beginPath();
  3388. this.chart_ctx.moveTo(-10, 0);
  3389. step = 900 / (this.line_data.length - 2);
  3390. data_max = Math.max.apply(null, this.line_data);
  3391. data_min = Math.min.apply(null, this.line_data);
  3392. ref = this.line_data;
  3393. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  3394. data = ref[i];
  3395. line_y = 250 - ((data - data_min) / (data_max - data_min)) * 120;
  3396. this.chart_ctx.lineTo((i - 1) * step, line_y);
  3397. }
  3398. this.chart_ctx.lineTo((i + 1) * step, line_y);
  3399. this.chart_ctx.lineTo(i * step, 450);
  3400. this.chart_ctx.lineTo(0, 450);
  3401. this.chart_ctx.fill();
  3402. this.chart_ctx.stroke();
  3403. return this.chart_ctx.shadowBlur = 0;
  3404. };
  3405. Chart.prototype.render = function() {
  3406. if (this.need_update) {
  3407. this.update();
  3408. this.need_update = false;
  3409. }
  3410. return h("div.Chart", {
  3411. style: "background-image: radial-gradient(at 29% top, #eaaeda05, " + this.colorize + ")"
  3412. }, [
  3413. h("div.titles", [
  3414. h("div.title", this.getTitle()), h("div.value", this.value), h("div.details", this.details.map((function(_this) {
  3415. return function(detail) {
  3416. return [
  3417. detail, h("br", {
  3418. key: detail
  3419. })
  3420. ];
  3421. };
  3422. })(this)))
  3423. ]), h("canvas.canvas", {
  3424. afterCreate: this.initChart,
  3425. width: 900,
  3426. height: 400
  3427. })
  3428. ]);
  3429. };
  3430. return Chart;
  3431. })(Class);
  3432. window.Chart = Chart;
  3433. }).call(this);
  3434. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/ChartBig.coffee ---- */
  3435. (function() {
  3436. var ChartBig,
  3437. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3438. 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; },
  3439. hasProp = {}.hasOwnProperty;
  3440. ChartBig = (function(superClass) {
  3441. extend(ChartBig, superClass);
  3442. function ChartBig() {
  3443. this.render = bind(this.render, this);
  3444. this.initChart = bind(this.initChart, this);
  3445. this.storeCanvasNode = bind(this.storeCanvasNode, this);
  3446. this.update = bind(this.update, this);
  3447. var types;
  3448. this.need_update = false;
  3449. this.data = {};
  3450. this.data_max = {};
  3451. this.data_total = {};
  3452. types = {};
  3453. }
  3454. ChartBig.prototype.update = function(cb) {
  3455. var date_added_from, date_added_to, interval, query, query_group, query_select, step, type, type_ids;
  3456. if (Page.params.interval === "1w") {
  3457. interval = 60 * 60 * 24 * 7;
  3458. step = 60 * 60;
  3459. query_select = "MAX(date_added) AS date_added, type_id, SUM(value) AS value";
  3460. query_group = "GROUP BY type_id, strftime('%Y-%m-%d %H', date_added, 'unixepoch', 'localtime')";
  3461. } else {
  3462. interval = 60 * 60 * 24;
  3463. step = 60 * 5;
  3464. query_select = "*";
  3465. query_group = "";
  3466. }
  3467. if (Page.params.date_added_to) {
  3468. date_added_to = (new Date(Page.params.date_added_to + " 23:59")).getTime() / 1000;
  3469. date_added_from = date_added_to - interval;
  3470. } else {
  3471. date_added_to = Time.timestamp();
  3472. date_added_from = Time.timestamp() - interval;
  3473. }
  3474. query = "SELECT " + query_select + " FROM data\nWHERE type_id IN :type_ids AND date_added >= :date_added_from AND date_added <= :date_added_to\n" + query_group + "\nORDER BY date_added";
  3475. type_ids = (function() {
  3476. var j, len, ref, results;
  3477. ref = this.types;
  3478. results = [];
  3479. for (j = 0, len = ref.length; j < len; j++) {
  3480. type = ref[j];
  3481. results.push(Page.page_stats.type_id_db[type.name]);
  3482. }
  3483. return results;
  3484. }).call(this);
  3485. return Page.cmd("chartDbQuery", [
  3486. query, {
  3487. type_ids: type_ids,
  3488. date_added_from: date_added_from,
  3489. date_added_to: date_added_to
  3490. }
  3491. ], (function(_this) {
  3492. return function(res) {
  3493. var data_date_added, data_found, data_value, dataset, i, j, k, l, len, len1, len2, len3, len4, m, n, row, type_id, type_name;
  3494. _this.logStart("Parse result");
  3495. _this.data = {
  3496. labels: []
  3497. };
  3498. _this.data_max = {};
  3499. _this.data_total = {};
  3500. for (j = 0, len = type_ids.length; j < len; j++) {
  3501. type_id = type_ids[j];
  3502. _this.data[type_id] = {};
  3503. _this.data_max[Page.page_stats.type_name_db[type_id]] = 0;
  3504. _this.data_total[Page.page_stats.type_name_db[type_id]] = 0;
  3505. }
  3506. for (k = 0, len1 = res.length; k < len1; k++) {
  3507. row = res[k];
  3508. type_name = Page.page_stats.type_name_db[row.type_id];
  3509. _this.data[row.type_id][Math.ceil(row.date_added / step) * step] = row.value;
  3510. _this.data_max[type_name] = Math.max(row.value, _this.data_max[type_name]);
  3511. _this.data_total[type_name] += row.value;
  3512. }
  3513. _this.configuration.options.scales.yAxes[0].ticks.suggestedMax = Math.max(_this.data_max["file_bytes_sent"], _this.data_max["file_bytes_recv"]);
  3514. _this.configuration.options.scales.yAxes[0].ticks.suggestedMin = 0 - _this.configuration.options.scales.yAxes[0].ticks.suggestedMax;
  3515. _this.configuration.options.scales.yAxes[1].ticks.suggestedMax = Math.max(_this.data_max["request_num_sent"], _this.data_max["request_num_recv"]);
  3516. _this.configuration.options.scales.yAxes[1].ticks.suggestedMin = 0 - _this.configuration.options.scales.yAxes[1].ticks.suggestedMax;
  3517. for (i = l = 0, len2 = type_ids.length; l < len2; i = ++l) {
  3518. type_id = type_ids[i];
  3519. dataset = _this.configuration.data.datasets[_this.types[i].dataset_id];
  3520. dataset.data.length = 0;
  3521. dataset.data_i = 0;
  3522. }
  3523. _this.configuration.data.labels.length = 0;
  3524. _this.configuration.data.labels_i = 0;
  3525. data_date_added = Math.ceil(date_added_from / step) * step;
  3526. while (data_date_added <= date_added_to) {
  3527. if (!data_found) {
  3528. for (i = m = 0, len3 = type_ids.length; m < len3; i = ++m) {
  3529. type_id = type_ids[i];
  3530. if (_this.data[type_id][data_date_added]) {
  3531. data_found = true;
  3532. break;
  3533. }
  3534. }
  3535. if (!data_found) {
  3536. data_date_added += step;
  3537. continue;
  3538. }
  3539. }
  3540. for (i = n = 0, len4 = type_ids.length; n < len4; i = ++n) {
  3541. type_id = type_ids[i];
  3542. data_value = _this.data[type_id][data_date_added];
  3543. dataset = _this.configuration.data.datasets[_this.types[i].dataset_id];
  3544. type = _this.types[i];
  3545. if (type.negative) {
  3546. data_value = 0 - data_value;
  3547. }
  3548. dataset.data[dataset.data_i] = data_value;
  3549. dataset.data_i += 1;
  3550. }
  3551. _this.configuration.data.labels.push(data_date_added * 1000);
  3552. _this.configuration.data.labels_i += 1;
  3553. data_date_added += step;
  3554. }
  3555. _this.logEnd("Parse result", "labels: " + _this.configuration.data.labels.length);
  3556. if (_this.chart) {
  3557. _this.chart.update();
  3558. } else {
  3559. _this.initChart();
  3560. }
  3561. if (typeof cb === "function") {
  3562. cb();
  3563. }
  3564. return Page.projector.scheduleRender();
  3565. };
  3566. })(this));
  3567. };
  3568. ChartBig.prototype.storeCanvasNode = function(node) {
  3569. if (this.chart) {
  3570. this.chart.clear();
  3571. this.chart.destroy();
  3572. this.chart = null;
  3573. }
  3574. node.parentNode.style.height = node.getBoundingClientRect().height + "px";
  3575. this.ctx = node.getContext("2d");
  3576. this.chart_node = node;
  3577. return this.configuration != null ? this.configuration : this.configuration = this.getChartConfiguration();
  3578. };
  3579. ChartBig.prototype.initChart = function() {
  3580. var timer_resize;
  3581. this.log("initChart");
  3582. this.chart = new Chart(this.ctx, this.configuration);
  3583. setTimeout(((function(_this) {
  3584. return function() {
  3585. return _this.chart_node.parentNode.style.height = "";
  3586. };
  3587. })(this)), 100);
  3588. timer_resize = null;
  3589. return window.addEventListener("resize", (function(_this) {
  3590. return function() {
  3591. clearInterval(timer_resize);
  3592. return setTimeout((function() {
  3593. return _this.chart.resize();
  3594. }), 300);
  3595. };
  3596. })(this));
  3597. };
  3598. ChartBig.prototype.testDataAddition = function() {
  3599. var timer_i;
  3600. timer_i = 0;
  3601. return setInterval(((function(_this) {
  3602. return function() {
  3603. var data, dataset, i, j, k, len, len1, new_data, new_labels, type_id;
  3604. new_labels = _this.configuration.data.labels.slice();
  3605. new_data = _this.configuration.data.datasets[_this.types[0].dataset_id].data.slice();
  3606. _this.configuration.data.labels = [];
  3607. timer_i += 1;
  3608. for (i = j = 0, len = type_ids.length; j < len; i = ++j) {
  3609. type_id = type_ids[i];
  3610. dataset = _this.configuration.data.datasets[_this.types[i].dataset_id];
  3611. dataset.data.push(Math.round(Math.random() * 10));
  3612. dataset.data.shift();
  3613. }
  3614. for (k = 0, len1 = new_data.length; k < len1; k++) {
  3615. data = new_data[k];
  3616. _this.configuration.data.datasets[_this.types[0].dataset_id].data.push(data);
  3617. }
  3618. _this.configuration.data.labels = new_labels;
  3619. _this.configuration.data.labels.push(1000 * (Time.timestamp() + (timer_i * 60 * 5)));
  3620. _this.configuration.data.labels.shift();
  3621. return _this.chart.update();
  3622. };
  3623. })(this)), 5000);
  3624. };
  3625. ChartBig.prototype.createGradientStroke = function(stops) {
  3626. var color, gradient, i, j, len;
  3627. gradient = this.ctx.createLinearGradient(0, 0, 900, 0);
  3628. for (i = j = 0, len = stops.length; j < len; i = ++j) {
  3629. color = stops[i];
  3630. gradient.addColorStop(i * (1 / (stops.length - 1)), color);
  3631. }
  3632. return gradient;
  3633. };
  3634. ChartBig.prototype.createGradientFill = function(stops, mode) {
  3635. var color, gradient, i, j, len;
  3636. if (mode == null) {
  3637. mode = "normal";
  3638. }
  3639. if (mode === "lower") {
  3640. gradient = this.ctx.createLinearGradient(0, 0, 0, 300);
  3641. } else {
  3642. gradient = this.ctx.createLinearGradient(0, 50, 0, 200);
  3643. }
  3644. for (i = j = 0, len = stops.length; j < len; i = ++j) {
  3645. color = stops[i];
  3646. gradient.addColorStop(i * (1 / (stops.length - 1)), color);
  3647. }
  3648. return gradient;
  3649. };
  3650. ChartBig.prototype.getChartConfiguration = function() {
  3651. var configuration, gradient_fill, gradient_fill_down, gradient_fill_up, gradient_stroke, gradient_stroke_bgline_down, gradient_stroke_bgline_up, gradient_stroke_down, gradient_stroke_up;
  3652. gradient_stroke = this.createGradientStroke(["#5A46DF", "#8F49AA", "#D64C57"]);
  3653. gradient_stroke_bgline_up = this.createGradientStroke(["#EEAAFF11", "#EEAAFF33", "#2da3b366"]);
  3654. gradient_stroke_bgline_down = this.createGradientStroke(["#EEAAFF11", "#EEAAFF33", "#80623f88"]);
  3655. gradient_stroke_up = this.createGradientStroke(["#2b68d9", "#2f99be", "#1dfc59"]);
  3656. gradient_stroke_down = this.createGradientStroke(["#bac735", "#c2a548", "#f1294b"]);
  3657. gradient_fill = this.createGradientFill(["#50455DEE", "#26262C33"]);
  3658. gradient_fill_up = this.createGradientFill(["#1dfc5922", "#2f373333"]);
  3659. gradient_fill_down = this.createGradientFill(["#45353533", "#f1294b22"], "lower");
  3660. configuration = {
  3661. type: 'line',
  3662. data: {
  3663. labels: [],
  3664. datasets: [
  3665. {
  3666. type: 'line',
  3667. label: "Upload",
  3668. borderColor: gradient_stroke_up,
  3669. pointBorderColor: gradient_stroke_up,
  3670. pointBackgroundColor: gradient_stroke_up,
  3671. pointHoverBackgroundColor: gradient_stroke_up,
  3672. pointHoverBorderColor: gradient_stroke_up,
  3673. pointHoverRadius: 2,
  3674. pointRadius: 0,
  3675. steppedLine: true,
  3676. fill: true,
  3677. backgroundColor: gradient_fill_up,
  3678. borderWidth: 1,
  3679. lineTension: 0,
  3680. data: []
  3681. }, {
  3682. type: 'line',
  3683. label: "Download",
  3684. borderColor: gradient_stroke_down,
  3685. pointBorderColor: gradient_stroke_down,
  3686. pointBackgroundColor: gradient_stroke_down,
  3687. pointHoverBackgroundColor: gradient_stroke_down,
  3688. pointHoverBorderColor: gradient_stroke_down,
  3689. pointHoverRadius: 2,
  3690. pointRadius: 0,
  3691. steppedLine: true,
  3692. fill: true,
  3693. backgroundColor: gradient_fill_down,
  3694. borderWidth: 1,
  3695. lineTension: 0,
  3696. data: []
  3697. }, {
  3698. type: 'line',
  3699. label: 'Sent',
  3700. borderColor: gradient_stroke_bgline_up,
  3701. backgroundColor: "rgba(255,255,255,0.0)",
  3702. pointRadius: 0,
  3703. borderWidth: 1,
  3704. pointHoverRadius: 2,
  3705. pointHoverBackgroundColor: gradient_stroke_bgline_up,
  3706. pointHoverBorderColor: gradient_stroke_bgline_up,
  3707. fill: true,
  3708. yAxisID: 'Request',
  3709. steppedLine: true,
  3710. lineTension: 0,
  3711. data: []
  3712. }, {
  3713. type: 'line',
  3714. label: 'Received',
  3715. borderColor: gradient_stroke_bgline_down,
  3716. backgroundColor: "rgba(255,255,255,0.0)",
  3717. pointRadius: 0,
  3718. borderWidth: 1,
  3719. pointHoverRadius: 2,
  3720. pointHoverBackgroundColor: gradient_stroke_bgline_down,
  3721. pointHoverBorderColor: gradient_stroke_bgline_down,
  3722. fill: true,
  3723. yAxisID: 'Request',
  3724. steppedLine: true,
  3725. lineTension: 0,
  3726. data: []
  3727. }
  3728. ]
  3729. },
  3730. options: {
  3731. animation: {
  3732. easing: "easeOutExpo",
  3733. duration: 2000
  3734. },
  3735. legend: {
  3736. display: false,
  3737. position: "top",
  3738. labels: {
  3739. fontColor: 'white'
  3740. }
  3741. },
  3742. title: {
  3743. display: false
  3744. },
  3745. tooltips: {
  3746. mode: "index",
  3747. intersect: false,
  3748. displayColors: false,
  3749. xPadding: 10,
  3750. yPadding: 10,
  3751. cornerRadius: 0,
  3752. caretPadding: 10,
  3753. bodyFontColor: "rgba(255,255,255,0.6)",
  3754. callbacks: {
  3755. title: function(tootlip_items, data) {
  3756. return Time.date(tootlip_items[0].xLabel, "long").replace(/:00$/, "");
  3757. },
  3758. label: function(tootlip_items, data) {
  3759. if (data.datasets[tootlip_items.datasetIndex].yAxisID === "Request") {
  3760. return data.datasets[tootlip_items.datasetIndex].label + ": " + Math.abs(tootlip_items.yLabel) + " requests";
  3761. } else {
  3762. return data.datasets[tootlip_items.datasetIndex].label + ": " + Text.formatSize(Math.abs(tootlip_items.yLabel));
  3763. }
  3764. }
  3765. }
  3766. },
  3767. hover: {
  3768. mode: "index",
  3769. intersect: false
  3770. },
  3771. scales: {
  3772. yAxes: [
  3773. {
  3774. id: 'Transfer',
  3775. ticks: {
  3776. fontColor: "rgba(100,110,132,1)",
  3777. fontStyle: "bold",
  3778. beginAtZero: true,
  3779. suggestedMax: 30000000,
  3780. suggestedMin: -30000000,
  3781. display: true,
  3782. padding: 30,
  3783. callback: function(value) {
  3784. return Text.formatSize(Math.abs(value));
  3785. }
  3786. },
  3787. gridLines: {
  3788. drawTicks: true,
  3789. drawBorder: false,
  3790. display: true,
  3791. zeroLineColor: "rgba(255,255,255,0.1)",
  3792. tickMarkLength: 20,
  3793. zeroLineBorderDashOffset: 100,
  3794. color: "rgba(255,255,255,0.05)"
  3795. }
  3796. }, {
  3797. id: 'Request',
  3798. position: "right",
  3799. ticks: {
  3800. beginAtZero: true,
  3801. maxTicksLimit: 5,
  3802. suggestedMax: 180,
  3803. suggestedMin: -180,
  3804. display: false
  3805. },
  3806. gridLines: {
  3807. display: false,
  3808. zeroLineColor: "rgba(255,255,255,0)",
  3809. drawBorder: false
  3810. }
  3811. }
  3812. ],
  3813. xAxes: [
  3814. {
  3815. type: "time",
  3816. gridLines: {
  3817. color: "rgba(255,255,255,0.1)",
  3818. display: false,
  3819. offsetGridLines: true,
  3820. drawBorder: false
  3821. },
  3822. ticks: {
  3823. padding: 15,
  3824. fontColor: "rgba(100,110,132,1)",
  3825. fontStyle: "bold",
  3826. callback: (function(_this) {
  3827. return function(data_label, index) {
  3828. var back, parts;
  3829. if (_this.last_data_label == null) {
  3830. _this.last_data_label = "None 00 00:00";
  3831. }
  3832. if (_this.last_data_label.match(/.* /)[0] === data_label.match(/.* /)[0]) {
  3833. back = ["", data_label.replace(/.* /, "")];
  3834. } else {
  3835. parts = data_label.split(" ");
  3836. if (parts.length !== 3) {
  3837. return data_label;
  3838. }
  3839. back = [parts[0] + " " + parts[1], parts[2]];
  3840. }
  3841. _this.last_data_label = data_label;
  3842. return back;
  3843. };
  3844. })(this)
  3845. },
  3846. time: {
  3847. displayFormats: {
  3848. 'second': 'MMM DD HH:mm',
  3849. 'minute': 'MMM DD HH:mm',
  3850. 'hour': 'MMM DD HH:mm',
  3851. 'day': 'MMM DD HH:mm',
  3852. 'week': 'MMM DD HH:mm',
  3853. 'month': 'MMM DD HH:mm',
  3854. 'quarter': 'MMM DD HH:mm',
  3855. 'year': 'MMM DD HH:mm'
  3856. }
  3857. }
  3858. }
  3859. ]
  3860. }
  3861. }
  3862. };
  3863. return configuration;
  3864. };
  3865. ChartBig.prototype.render = function() {
  3866. if (this.need_update) {
  3867. this.update();
  3868. this.need_update = false;
  3869. }
  3870. return h("div.ChartBig", [
  3871. h("canvas." + Page.params.interval, {
  3872. width: 1350,
  3873. height: 450,
  3874. afterCreate: this.storeCanvasNode,
  3875. updateAnimation: Animation.show,
  3876. mode: Page.params.interval
  3877. })
  3878. ]);
  3879. };
  3880. return ChartBig;
  3881. })(Class);
  3882. window.ChartBig = ChartBig;
  3883. }).call(this);
  3884. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/ChartLegend.coffee ---- */
  3885. (function() {
  3886. var ChartLegend,
  3887. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3888. 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; },
  3889. hasProp = {}.hasOwnProperty;
  3890. ChartLegend = (function(superClass) {
  3891. extend(ChartLegend, superClass);
  3892. function ChartLegend() {
  3893. this.renderItem = bind(this.renderItem, this);
  3894. this.items_left = [];
  3895. this.items_right = [];
  3896. }
  3897. ChartLegend.prototype.renderItem = function(item) {
  3898. var hidden, value;
  3899. this.i += 1;
  3900. if (item.dot == null) {
  3901. item.dot = "\u25CF";
  3902. }
  3903. value = item.getValue();
  3904. hidden = !value;
  3905. if (item.post) {
  3906. value += " " + item.post;
  3907. }
  3908. if (item.type === "ratio") {
  3909. return h("div.legend-item", {
  3910. classes: {
  3911. hidden: hidden
  3912. }
  3913. }, [
  3914. h("div.title", item.title), h("div.value", [
  3915. h("span", {
  3916. updateAnimation: Animation.show,
  3917. delay: this.i * 0.1
  3918. }, Math.round(value * 10) / 10), h("div.dots-container", [
  3919. h("span.dots.dots-fg", {
  3920. style: "width: " + (Math.min(value, 5) * 11.5) + "px; color: " + item.color
  3921. }, item.dot.repeat(5)), h("span.dots.dots-bg", item.dot.repeat(5))
  3922. ])
  3923. ])
  3924. ]);
  3925. } else {
  3926. return h("div.legend-item", {
  3927. classes: {
  3928. hidden: hidden
  3929. }
  3930. }, [
  3931. h("div.title", [
  3932. h("span.dot", {
  3933. style: "color: " + item.color
  3934. }, item.dot + " "), item.title
  3935. ]), h("div.value", {
  3936. updateAnimation: Animation.show,
  3937. delay: this.i * 0.1
  3938. }, value)
  3939. ]);
  3940. }
  3941. };
  3942. ChartLegend.prototype.render = function() {
  3943. this.i = 0;
  3944. return h("div.ChartLegend", h("div.legend-items.align-left", this.items_left.map(this.renderItem)), h("div.legend-items.align-right", this.items_right.map(this.renderItem)));
  3945. };
  3946. return ChartLegend;
  3947. })(Class);
  3948. window.ChartLegend = ChartLegend;
  3949. }).call(this);
  3950. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/ChartRadar.coffee ---- */
  3951. (function() {
  3952. var ChartRadar,
  3953. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3954. 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; },
  3955. hasProp = {}.hasOwnProperty;
  3956. ChartRadar = (function(superClass) {
  3957. extend(ChartRadar, superClass);
  3958. function ChartRadar(id) {
  3959. this.id = id;
  3960. this.render = bind(this.render, this);
  3961. this.renderLabel = bind(this.renderLabel, this);
  3962. this.handleLegendClick = bind(this.handleLegendClick, this);
  3963. this.initChart = bind(this.initChart, this);
  3964. this.formatLabel = bind(this.formatLabel, this);
  3965. this.getChartConfiguration = bind(this.getChartConfiguration, this);
  3966. this.initCanvas = bind(this.initCanvas, this);
  3967. this.update = bind(this.update, this);
  3968. this.configuration = {};
  3969. this.site_stats = [];
  3970. this.need_update = false;
  3971. this.order_by = "site_bw";
  3972. this.legends = [
  3973. {
  3974. id: "site_bw",
  3975. title: "Transferred data (last 7 days)",
  3976. color: "#608DECDD"
  3977. }, {
  3978. id: "site_size",
  3979. title: "Site size",
  3980. color: "#9C27B0DD"
  3981. }
  3982. ];
  3983. }
  3984. ChartRadar.prototype.update = function() {
  3985. var query, type_ids, type_name;
  3986. query = "SELECT type_id, site_id, SUM(value) AS sum, value\nFROM data\nWHERE type_id IN :type_ids AND date_added > " + (Time.timestamp() - 60 * 60 * 24 * 7) + "\nGROUP BY type_id, site_id";
  3987. type_ids = (function() {
  3988. var j, len, ref, results;
  3989. ref = ["site_bytes_sent", "site_bytes_recv", "site_size"];
  3990. results = [];
  3991. for (j = 0, len = ref.length; j < len; j++) {
  3992. type_name = ref[j];
  3993. results.push(Page.page_stats.type_id_db[type_name]);
  3994. }
  3995. return results;
  3996. })();
  3997. return Page.cmd("chartDbQuery", [
  3998. query, {
  3999. type_ids: type_ids
  4000. }
  4001. ], (function(_this) {
  4002. return function(res) {
  4003. var address, data, i, j, k, len, len1, max_site_bw, max_site_size, ref, row, stat;
  4004. _this.logStart("Parse result");
  4005. data = {};
  4006. for (j = 0, len = res.length; j < len; j++) {
  4007. row = res[j];
  4008. address = Page.page_stats.site_address_db[row.site_id];
  4009. type_name = Page.page_stats.type_name_db[row.type_id];
  4010. if (data[address] == null) {
  4011. data[address] = {
  4012. address: address,
  4013. site: Page.site_list.sites_byaddress[address]
  4014. };
  4015. }
  4016. if (type_name === "site_size") {
  4017. data[address][type_name] = row.value;
  4018. } else {
  4019. data[address][type_name] = row.sum || 0;
  4020. }
  4021. }
  4022. _this.site_stats = [];
  4023. for (address in data) {
  4024. stat = data[address];
  4025. stat.site_bw = stat.site_bytes_sent + stat.site_bytes_recv;
  4026. _this.site_stats.push(stat);
  4027. }
  4028. _this.site_stats.sort(function(a, b) {
  4029. return b[_this.order_by] - a[_this.order_by];
  4030. });
  4031. if (_this.site_stats.length > 8) {
  4032. _this.site_stats.length = 8;
  4033. }
  4034. max_site_bw = Math.max.apply(null, (function() {
  4035. var k, len1, ref, results;
  4036. ref = this.site_stats;
  4037. results = [];
  4038. for (k = 0, len1 = ref.length; k < len1; k++) {
  4039. stat = ref[k];
  4040. results.push(stat.site_bw);
  4041. }
  4042. return results;
  4043. }).call(_this));
  4044. max_site_size = Math.max.apply(null, (function() {
  4045. var k, len1, ref, results;
  4046. ref = this.site_stats;
  4047. results = [];
  4048. for (k = 0, len1 = ref.length; k < len1; k++) {
  4049. stat = ref[k];
  4050. results.push(stat.site_size);
  4051. }
  4052. return results;
  4053. }).call(_this));
  4054. ref = _this.site_stats;
  4055. for (i = k = 0, len1 = ref.length; k < len1; i = ++k) {
  4056. stat = ref[i];
  4057. _this.configuration.data.labels[i] = stat.site.row.content.title;
  4058. _this.configuration.data.datasets[0].data[i] = Math.log(1 + (stat.site_bw / max_site_bw) * 100);
  4059. _this.configuration.data.datasets[1].data[i] = Math.log(1 + (stat.site_size / max_site_size) * 100);
  4060. }
  4061. _this.logEnd("Parse result", "sites: " + _this.site_stats.length);
  4062. Page.projector.scheduleRender();
  4063. if (_this.chart) {
  4064. return _this.chart.update();
  4065. } else {
  4066. return _this.initChart();
  4067. }
  4068. };
  4069. })(this));
  4070. };
  4071. ChartRadar.prototype.initCanvas = function(node) {
  4072. if (this.chart) {
  4073. this.chart.clear();
  4074. this.chart.destroy();
  4075. this.chart = null;
  4076. }
  4077. this.ctx = node.getContext("2d");
  4078. return this.configuration = this.getChartConfiguration();
  4079. };
  4080. ChartRadar.prototype.getChartConfiguration = function() {
  4081. var fill, fill2, shadowed;
  4082. fill = this.ctx.createLinearGradient(0, 0, 900, 0);
  4083. fill.addColorStop(0, "#608DECCC");
  4084. fill.addColorStop(1, "#9C27B0CC");
  4085. fill2 = this.ctx.createLinearGradient(0, 0, 900, 0);
  4086. fill2.addColorStop(0, "#9C27B0DD");
  4087. fill2.addColorStop(1, "#608DECDD");
  4088. shadowed = {
  4089. beforeDatasetsDraw: function(chart, options) {
  4090. chart.ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
  4091. return chart.ctx.shadowBlur = 40;
  4092. },
  4093. afterDatasetsDraw: function(chart, options) {
  4094. chart.ctx.shadowColor = 'rgba(0, 0, 0, 0)';
  4095. return chart.ctx.shadowBlur = 0;
  4096. }
  4097. };
  4098. return {
  4099. type: 'radar',
  4100. data: {
  4101. labels: [],
  4102. datasets: [
  4103. {
  4104. label: "Transferred data",
  4105. backgroundColor: fill,
  4106. borderColor: "transparent",
  4107. borderWidth: 0,
  4108. pointBorderWidth: 0,
  4109. pointRadius: 0,
  4110. data: []
  4111. }, {
  4112. label: "Site size",
  4113. backgroundColor: fill2,
  4114. borderColor: "transparent",
  4115. borderWidth: 0,
  4116. pointBorderWidth: 0,
  4117. pointRadius: 0,
  4118. data: []
  4119. }
  4120. ]
  4121. },
  4122. options: {
  4123. legend: {
  4124. display: false,
  4125. position: "bottom",
  4126. labels: {
  4127. padding: 5
  4128. }
  4129. },
  4130. scale: {
  4131. ticks: {
  4132. display: false,
  4133. maxTicksLimit: 5,
  4134. beginAtZero: true
  4135. },
  4136. angleLines: {
  4137. color: "#99999911"
  4138. },
  4139. gridLines: {
  4140. color: "#99999911",
  4141. tickMarkLength: 1
  4142. },
  4143. tooltips: {
  4144. enabled: true
  4145. },
  4146. pointLabels: {
  4147. fontColor: "rgba(200,210,232,1)",
  4148. fontSize: 14,
  4149. fontFamily: "Roboto",
  4150. fontStyle: "lighter",
  4151. padding: 10,
  4152. callback: this.formatLabel
  4153. }
  4154. }
  4155. },
  4156. plugins: [shadowed]
  4157. };
  4158. };
  4159. ChartRadar.prototype.formatLabel = function() {
  4160. return [""];
  4161. };
  4162. ChartRadar.prototype.initChart = function() {
  4163. var timer_resize;
  4164. this.chart = new Chart(this.ctx, this.configuration);
  4165. timer_resize = null;
  4166. return window.addEventListener("resize", (function(_this) {
  4167. return function() {
  4168. _this.log("resize");
  4169. clearInterval(timer_resize);
  4170. return setTimeout((function() {
  4171. return _this.chart.resize();
  4172. }), 300);
  4173. };
  4174. })(this));
  4175. };
  4176. ChartRadar.prototype.handleLegendClick = function(e) {
  4177. this.order_by = e.currentTarget.getAttribute("href").replace("#", "");
  4178. this.update();
  4179. return false;
  4180. };
  4181. ChartRadar.prototype.renderLabel = function(stat, i) {
  4182. var left, r, top;
  4183. if (i % (this.site_stats.length / 2) === 0) {
  4184. r = 37;
  4185. } else {
  4186. r = 40;
  4187. }
  4188. left = 50 + r * Math.sin(2 * Math.PI * i / this.site_stats.length);
  4189. top = 50 - r * Math.cos(2 * Math.PI * i / this.site_stats.length);
  4190. return h("div.radar-label", {
  4191. key: stat.address + i,
  4192. style: "left: " + left + "%; top: " + top + "%",
  4193. enterAnimation: Animation.show,
  4194. exitAnimation: Animation.hide,
  4195. delay: i * 0.05
  4196. }, h("a.title", {
  4197. href: stat.site.getHref()
  4198. }, stat.site.row.content.title), " ", h("span.value", " (" + (Text.formatSize(stat[this.order_by]) || 'No data yet') + ")"));
  4199. };
  4200. ChartRadar.prototype.render = function() {
  4201. var label_i;
  4202. if (this.need_update) {
  4203. this.update();
  4204. this.need_update = false;
  4205. }
  4206. label_i = 0;
  4207. return h("div.ChartRadar", [
  4208. h("div.radar-container", [
  4209. h("div.radar-labels", this.site_stats.map((function(_this) {
  4210. return function(stat) {
  4211. var label;
  4212. label = _this.renderLabel(stat, label_i);
  4213. label_i += 1;
  4214. return label;
  4215. };
  4216. })(this))), h("div.canvas-container", h("canvas", {
  4217. width: 600,
  4218. height: 600,
  4219. afterCreate: this.initCanvas
  4220. }))
  4221. ]), h("div.radar-legends", this.legends.map((function(_this) {
  4222. return function(legend) {
  4223. return h("a.radar-legend", {
  4224. id: legend.id,
  4225. classes: {
  4226. active: _this.order_by === legend.id
  4227. },
  4228. onclick: _this.handleLegendClick,
  4229. href: "#" + legend.id
  4230. }, [
  4231. h("div.legend-box", {
  4232. style: "background-color: " + legend.color
  4233. }), h("span.title", legend.title)
  4234. ]);
  4235. };
  4236. })(this)))
  4237. ]);
  4238. };
  4239. return ChartRadar;
  4240. })(Class);
  4241. window.ChartRadar = ChartRadar;
  4242. }).call(this);
  4243. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/ChartTimeline.coffee ---- */
  4244. (function() {
  4245. var ChartTimeline,
  4246. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  4247. 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; },
  4248. hasProp = {}.hasOwnProperty;
  4249. ChartTimeline = (function(superClass) {
  4250. extend(ChartTimeline, superClass);
  4251. function ChartTimeline() {
  4252. this.render = bind(this.render, this);
  4253. this.update = bind(this.update, this);
  4254. this.updateChart = bind(this.updateChart, this);
  4255. this.initChart = bind(this.initChart, this);
  4256. var i, j;
  4257. this.items = [];
  4258. for (i = j = 6; j >= 0; i = --j) {
  4259. this.items.push({
  4260. id: i,
  4261. title: "\u200B",
  4262. data: "\u200B",
  4263. value: i,
  4264. active: false
  4265. });
  4266. }
  4267. this.active_id = 0;
  4268. this.chart_ctx = null;
  4269. this.need_update = false;
  4270. this.line_data = null;
  4271. }
  4272. ChartTimeline.prototype.initChart = function(node) {
  4273. this.chart_canvas = node;
  4274. this.chart_ctx = node.getContext("2d");
  4275. if (this.line_data) {
  4276. return this.updateChart();
  4277. }
  4278. };
  4279. ChartTimeline.prototype.updateChart = function() {
  4280. var data, data_last_i, data_max, i, j, len, line_width, line_x, line_y, ref, val;
  4281. this.chart_ctx.clearRect(0, 0, this.chart_canvas.width, this.chart_canvas.height);
  4282. this.chart_ctx.lineWidth = 0;
  4283. this.chart_ctx.fillStyle = '#EDC54B';
  4284. this.chart_ctx.beginPath();
  4285. this.chart_ctx.moveTo(-10, 0);
  4286. data_max = Math.max.apply(null, this.line_data);
  4287. data_last_i = ((function() {
  4288. var j, len, ref, results;
  4289. ref = this.line_data;
  4290. results = [];
  4291. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  4292. val = ref[i];
  4293. if (val > 0) {
  4294. results.push(i);
  4295. }
  4296. }
  4297. return results;
  4298. }).call(this)).pop();
  4299. line_width = 1400 / this.line_data.length;
  4300. ref = this.line_data;
  4301. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  4302. data = ref[i];
  4303. line_x = i * line_width;
  4304. line_y = parseInt(101 - (data / data_max) * 100);
  4305. this.chart_ctx.lineTo(line_x, line_y);
  4306. if (i === data_last_i) {
  4307. break;
  4308. }
  4309. }
  4310. this.chart_ctx.lineTo(line_x, 120);
  4311. this.chart_ctx.lineTo(0, 120);
  4312. this.chart_ctx.fill();
  4313. if (data_last_i > 36) {
  4314. this.chart_ctx.beginPath();
  4315. this.chart_ctx.lineWidth = 0;
  4316. this.chart_ctx.strokeStyle = '#EDC54B';
  4317. this.chart_ctx.setLineDash([0, 1, 1]);
  4318. this.chart_ctx.moveTo(line_x, line_y);
  4319. this.chart_ctx.lineTo(1500, line_y);
  4320. return this.chart_ctx.stroke();
  4321. }
  4322. };
  4323. ChartTimeline.prototype.update = function() {
  4324. var c, data, date_added_from, date_added_to, day_total, group_steps, interval_step, query, step, type_id;
  4325. query = "SELECT\nMAX(date_added) AS date_added, AVG(value) AS avg, SUM(value) AS sum\nFROM data\nWHERE type_id = :type_id AND date_added >= :date_added_from AND date_added <= :date_added_to\nGROUP BY strftime('%Y-%m-%d %H', date_added, 'unixepoch', 'localtime')\nORDER BY date_added DESC";
  4326. if (Page.params.interval === "1w") {
  4327. c = new Date();
  4328. c.setDate(c.getDate() - (c.getDay() || 7) + 7);
  4329. date_added_to = c.setHours(23, 59, 59, 0) / 1000;
  4330. interval_step = 60 * 60 * 24 * 7;
  4331. date_added_from = date_added_to - interval_step * 7;
  4332. group_steps = 6;
  4333. } else if (Page.params.interval === "1m") {
  4334. c = new Date();
  4335. c.setDate(30);
  4336. date_added_to = c.setHours(23, 59, 59, 0) / 1000;
  4337. interval_step = 60 * 60 * 24 * 30;
  4338. date_added_from = date_added_to - interval_step * 30;
  4339. group_steps = 24 * 3;
  4340. } else {
  4341. date_added_to = (new Date()).setHours(23, 59, 59, 0) / 1000;
  4342. interval_step = 60 * 60 * 24;
  4343. date_added_from = date_added_to - interval_step * 7;
  4344. group_steps = 2;
  4345. }
  4346. step = 60 * 60;
  4347. type_id = Page.page_stats.type_id_db["file_bytes_sent"];
  4348. data = {};
  4349. day_total = {};
  4350. return Page.cmd("chartDbQuery", [
  4351. query, {
  4352. type_id: type_id,
  4353. date_added_from: date_added_from,
  4354. date_added_to: date_added_to
  4355. }
  4356. ], (function(_this) {
  4357. return function(res) {
  4358. var data_date_added, data_from, data_to, day_data, day_from, day_name, day_string, day_to, group_step_data, i, j, k, l, len, m, n, ref, row, x;
  4359. _this.logStart("Parse result");
  4360. _this.line_data = [];
  4361. for (j = 0, len = res.length; j < len; j++) {
  4362. row = res[j];
  4363. data[Math.ceil(row.date_added / step) * step] = row.sum;
  4364. day_string = Time.dateIso(row.date_added * 1000);
  4365. if (day_total[day_string] == null) {
  4366. day_total[day_string] = 0;
  4367. }
  4368. day_total[day_string] += row.sum;
  4369. }
  4370. data_date_added = Math.ceil(date_added_from / step) * step;
  4371. while (data_date_added <= date_added_to) {
  4372. group_step_data = 0;
  4373. for (i = k = 0, ref = group_steps; 0 <= ref ? k <= ref : k >= ref; i = 0 <= ref ? ++k : --k) {
  4374. group_step_data += data[data_date_added] || 0;
  4375. data_date_added += step;
  4376. }
  4377. _this.line_data.push(group_step_data);
  4378. }
  4379. _this.items = [];
  4380. for (i = l = 7; l >= 1; i = --l) {
  4381. data_from = date_added_to - i * interval_step + 1;
  4382. data_to = data_from + interval_step - 1;
  4383. if (Page.params.interval === "1w") {
  4384. day_data = 0;
  4385. for (x = m = 0; m <= 6; x = ++m) {
  4386. day_data += day_total[Time.dateIso(data_from + (60 * 60 * 24 * x))] || 0;
  4387. }
  4388. day_from = Time.date(data_from, "day");
  4389. day_to = Time.date(data_from + interval_step - 1, "day");
  4390. day_to = day_to.replace(day_from.split(" ")[0], "");
  4391. day_name = day_from + " - " + day_to;
  4392. } else if (Page.params.interval === "1m") {
  4393. day_data = 0;
  4394. for (x = n = 0; n <= 30; x = ++n) {
  4395. day_data += day_total[Time.dateIso(data_from + (60 * 60 * 24 * x))] || 0;
  4396. }
  4397. day_name = Time.date(data_from, "month");
  4398. } else {
  4399. day_data = day_total[Time.dateIso(data_from)];
  4400. day_name = Time.weekDay(data_from);
  4401. }
  4402. _this.items.push({
  4403. id: i,
  4404. title: day_name,
  4405. data: day_data,
  4406. value: data_to
  4407. });
  4408. }
  4409. _this.logEnd("Parse result", "data: " + _this.line_data.length);
  4410. Page.projector.scheduleRender();
  4411. return _this.updateChart();
  4412. };
  4413. })(this));
  4414. };
  4415. ChartTimeline.prototype.renderItem = function(item) {
  4416. var classes, date_added_to;
  4417. date_added_to = Time.dateIso(item.value);
  4418. if (item.value >= Time.timestamp()) {
  4419. date_added_to = "";
  4420. }
  4421. classes = {
  4422. active: (Page.params.date_added_to || "") === date_added_to
  4423. };
  4424. return h("a.timeline-item", {
  4425. key: item.title,
  4426. enterAnimation: Animation.show,
  4427. delay: item.id * 0.05,
  4428. href: Page.createUrl("date_added_to", date_added_to),
  4429. onclick: Page.handleLinkClick,
  4430. classes: classes
  4431. }, h("span.title", item.title), h("span.data", Text.formatSize(item.data) || "0 MB"));
  4432. };
  4433. ChartTimeline.prototype.render = function() {
  4434. var ref;
  4435. if (this.need_update) {
  4436. this.update();
  4437. this.need_update = false;
  4438. }
  4439. return h("div.ChartTimeline", [
  4440. h("div.timeline-borders", this.items.map((function(_this) {
  4441. return function(item) {
  4442. var date_added_to;
  4443. date_added_to = Time.dateIso(item.value);
  4444. if (item.value >= Time.timestamp()) {
  4445. date_added_to = "";
  4446. }
  4447. return h("div.timeline-border", {
  4448. key: item.id,
  4449. classes: {
  4450. active: (Page.params.date_added_to || "") === date_added_to
  4451. }
  4452. });
  4453. };
  4454. })(this))), h("canvas.chart", {
  4455. afterCreate: this.initChart,
  4456. width: 1400,
  4457. height: 100,
  4458. data: (ref = this.line_data) != null ? ref.length : void 0,
  4459. delay: 0.3,
  4460. updateAnimation: Animation.show
  4461. }), h("div.timeline-items", this.items.map((function(_this) {
  4462. return function(item) {
  4463. return _this.renderItem(item);
  4464. };
  4465. })(this)))
  4466. ]);
  4467. };
  4468. return ChartTimeline;
  4469. })(Class);
  4470. window.ChartTimeline = ChartTimeline;
  4471. }).call(this);
  4472. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/ChartWorld.coffee ---- */
  4473. (function() {
  4474. var ChartWorld,
  4475. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  4476. 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; },
  4477. hasProp = {}.hasOwnProperty;
  4478. ChartWorld = (function(superClass) {
  4479. extend(ChartWorld, superClass);
  4480. function ChartWorld() {
  4481. this.render = bind(this.render, this);
  4482. this.initCanvas = bind(this.initCanvas, this);
  4483. this.drawPoints = bind(this.drawPoints, this);
  4484. this.update = bind(this.update, this);
  4485. this.points = [];
  4486. this.need_update = false;
  4487. }
  4488. ChartWorld.prototype.update = function() {
  4489. /*
  4490. @points = [
  4491. {lat: 0, lon: 0},
  4492. {lat: 30, lon: 30},
  4493. {lat: 33.137551, lon: 129.902344},
  4494. {lat: 0.351560, lon: 115.136719},
  4495. {lat: 40.178873, lon: -8.261719},
  4496. {lat: 52.482780, lon: -0.878906},
  4497. {lat: 47.040182, lon: 19.511719},
  4498. {lat: 38.548165, lon: -76.113281},
  4499. {lat: 40.446947, lon: -122.871094}
  4500. {lat: -16.972741, lon: 46.582031}
  4501. {lat: -35.173808, lon: 19.511719}
  4502. {lat: -33.431441, lon: 116.542969}
  4503. {lat: -45.336702, lon: 168.222656}
  4504. {lat: -54.977614, lon: -67.412109}
  4505. {lat: 8.928487, lon: -62.314453}
  4506. {lat: 65.20515, lon: -14.670696}
  4507. {lat: 64.90863, lon: -21.70194625}
  4508. ]
  4509. return false
  4510. */
  4511. return Page.cmd("chartGetPeerLocations", [], (function(_this) {
  4512. return function(res) {
  4513. var country, country_db, i, item, items, j, len, len1, name, num, num_others, point, ref, ref1;
  4514. _this.points = res;
  4515. country_db = {};
  4516. items = Page.page_stats.country_list.items;
  4517. items.length = 0;
  4518. ref = _this.points;
  4519. for (i = 0, len = ref.length; i < len; i++) {
  4520. point = ref[i];
  4521. if (country_db[name = point.country] == null) {
  4522. country_db[name] = 0;
  4523. }
  4524. country_db[point.country] += 1;
  4525. }
  4526. for (country in country_db) {
  4527. num = country_db[country];
  4528. items.push({
  4529. title: country,
  4530. value: num
  4531. });
  4532. }
  4533. items.sort(function(a, b) {
  4534. return b.value - a.value;
  4535. });
  4536. if (items.length > 15) {
  4537. num_others = 0;
  4538. ref1 = items.slice(14);
  4539. for (j = 0, len1 = ref1.length; j < len1; j++) {
  4540. item = ref1[j];
  4541. num_others += item.value;
  4542. }
  4543. items.length = 14;
  4544. items.push({
  4545. title: "Other",
  4546. value: num_others,
  4547. type: "other"
  4548. });
  4549. }
  4550. _this.drawPoints();
  4551. return Page.projector.scheduleRender();
  4552. };
  4553. })(this));
  4554. };
  4555. ChartWorld.prototype.drawPoints = function() {
  4556. var i, left, len, point, ref, results, top;
  4557. this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
  4558. ref = this.points;
  4559. results = [];
  4560. for (i = 0, len = ref.length; i < len; i++) {
  4561. point = ref[i];
  4562. left = (47 + (point.lon / 3.65)) * this.canvas.width / 100;
  4563. top = (59 - (point.lat / 1.52)) * this.canvas.height / 100;
  4564. results.push(this.ctx.fillRect(left, top, 2, 2));
  4565. }
  4566. return results;
  4567. };
  4568. ChartWorld.prototype.initCanvas = function(node) {
  4569. this.canvas = node;
  4570. this.ctx = node.getContext("2d");
  4571. this.ctx.globalCompositeOperation = 'screen';
  4572. this.ctx.fillStyle = '#30758e';
  4573. return this.drawPoints();
  4574. };
  4575. ChartWorld.prototype.render = function() {
  4576. if (this.need_update) {
  4577. this.update();
  4578. this.need_update = false;
  4579. }
  4580. return h("div.ChartWorld", [
  4581. h("canvas.map-points", {
  4582. width: 878,
  4583. height: 371,
  4584. afterCreate: this.initCanvas
  4585. }), h("img.map", {
  4586. src: "img/world.png"
  4587. })
  4588. ]);
  4589. };
  4590. return ChartWorld;
  4591. })(Class);
  4592. window.ChartWorld = ChartWorld;
  4593. }).call(this);
  4594. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/PageStats.coffee ---- */
  4595. (function() {
  4596. var PageStats,
  4597. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  4598. 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; },
  4599. hasProp = {}.hasOwnProperty;
  4600. PageStats = (function(superClass) {
  4601. extend(PageStats, superClass);
  4602. function PageStats() {
  4603. this.render = bind(this.render, this);
  4604. this.loadChartjs = bind(this.loadChartjs, this);
  4605. this.update = bind(this.update, this);
  4606. this.handleChartjsLoad = bind(this.handleChartjsLoad, this);
  4607. this.need_update = false;
  4608. this.need_load_chartjs = true;
  4609. this.chartjs_loaded = false;
  4610. this.chart_timeline = new ChartTimeline();
  4611. this.chart_big = new ChartBig();
  4612. this.chart_big.types = [
  4613. {
  4614. name: "file_bytes_sent",
  4615. dataset_id: 0
  4616. }, {
  4617. name: "file_bytes_recv",
  4618. dataset_id: 1,
  4619. negative: true
  4620. }, {
  4621. name: "request_num_sent",
  4622. dataset_id: 2,
  4623. negative: true
  4624. }, {
  4625. name: "request_num_recv",
  4626. dataset_id: 3
  4627. }
  4628. ];
  4629. this.chart_legend = new ChartLegend();
  4630. this.chart_legend.items_left = [
  4631. {
  4632. title: "Upload",
  4633. getValue: ((function(_this) {
  4634. return function() {
  4635. return Text.formatSize(_this.chart_big.data_total.file_bytes_sent);
  4636. };
  4637. })(this)),
  4638. color: "#1dfc59"
  4639. }, {
  4640. title: "Download",
  4641. getValue: ((function(_this) {
  4642. return function() {
  4643. return Text.formatSize(_this.chart_big.data_total.file_bytes_recv);
  4644. };
  4645. })(this)),
  4646. color: "#c94d47"
  4647. }, {
  4648. title: "Ratio",
  4649. getValue: ((function(_this) {
  4650. return function() {
  4651. return _this.chart_big.data_total.file_bytes_sent / _this.chart_big.data_total.file_bytes_recv;
  4652. };
  4653. })(this)),
  4654. type: "ratio",
  4655. color: "#16ffe9"
  4656. }
  4657. ];
  4658. this.chart_legend.items_right = [
  4659. {
  4660. title: "Sent",
  4661. getValue: ((function(_this) {
  4662. return function() {
  4663. return _this.chart_big.data_total.request_num_sent;
  4664. };
  4665. })(this)),
  4666. post: "requests",
  4667. dot: "\u2500",
  4668. color: "#2da3b3"
  4669. }, {
  4670. title: "Received",
  4671. getValue: ((function(_this) {
  4672. return function() {
  4673. return _this.chart_big.data_total.request_num_recv;
  4674. };
  4675. })(this)),
  4676. post: "requests",
  4677. dot: "\u2500",
  4678. color: "#80623f"
  4679. }
  4680. ];
  4681. this.chart_radar = new ChartRadar();
  4682. this.chart_connections = new Chart();
  4683. this.chart_connections.title = "Connections";
  4684. this.chart_connections.type_names = ["peer", "peer_onion", "connection", "connection_onion", "connection_in", "connection_ping_avg", "connection_ping_min"];
  4685. this.chart_connections.formatValue = function(type_data) {
  4686. return type_data.connection + " of " + type_data.peer + " peers";
  4687. };
  4688. this.chart_connections.formatDetails = function(type_data) {
  4689. var back;
  4690. back = [];
  4691. back.push("Onion: " + type_data.peer_onion + " peers (" + (type_data.connection_onion || 0) + " connections)");
  4692. back.push("Incoming: " + (Math.round(type_data.connection_in / type_data.connection * 100)) + "%");
  4693. back.push("Ping avg: " + type_data.connection_ping_avg + "ms (min: " + type_data.connection_ping_min + "ms)");
  4694. return back;
  4695. };
  4696. this.chart_connections.chart_stroke = ["#608DECAA", "#D74C58FF"];
  4697. this.chart_connections.getChartQuery = function() {
  4698. return "SELECT * FROM data WHERE type_id = " + Page.page_stats.type_id_db['connection'] + " ORDER BY date_added DESC LIMIT 50";
  4699. };
  4700. this.chart_size = new Chart();
  4701. this.chart_size.getTitle = function() {
  4702. return h("a", {
  4703. href: Page.createUrl("bigchart", "size"),
  4704. onclick: Page.handleLinkClick
  4705. }, "Total size");
  4706. };
  4707. this.chart_size.chart_stroke = ["#F99739AA", "#51B8F2"];
  4708. this.chart_size.type_names = ["size", "size_optional", "optional_limit", "optional_used", "content"];
  4709. this.chart_size.formatValue = function(type_data) {
  4710. return Text.formatSize(type_data.size);
  4711. };
  4712. this.chart_size.formatDetails = function(type_data) {
  4713. var back;
  4714. back = [];
  4715. back.push("Content sources: " + type_data.content + " files");
  4716. back.push("Optional downloaded: " + (Text.formatSize(type_data.optional_used) || '0 MB') + " of " + (Text.formatSize(type_data.size_optional) || '0 MB') + " (limit: " + (Text.formatSize(type_data.optional_limit)) + ")");
  4717. return back;
  4718. };
  4719. this.chart_size.getChartQuery = function() {
  4720. return "SELECT CAST(value AS FLOAT) / 1024 / 1024 AS value FROM data WHERE type_id = " + Page.page_stats.type_id_db['size'] + " GROUP BY ROUND(date_added / 10000) ORDER BY date_added DESC LIMIT 50";
  4721. };
  4722. this.chart_world = new ChartWorld();
  4723. this.country_list = new StatList();
  4724. this.type_name_db = {};
  4725. this.type_id_db = {};
  4726. this.site_address_db = {};
  4727. this.site_id_db = {};
  4728. setInterval(((function(_this) {
  4729. return function() {
  4730. _this.need_update = true;
  4731. return Page.projector.scheduleRender();
  4732. };
  4733. })(this)), 5 * 60 * 1000);
  4734. }
  4735. PageStats.prototype.handleChartjsLoad = function() {
  4736. this.chartjs_loaded = true;
  4737. return Page.projector.scheduleRender();
  4738. };
  4739. PageStats.prototype.update = function() {
  4740. Page.cmd("chartDbQuery", "SELECT * FROM type", (function(_this) {
  4741. return function(res) {
  4742. var i, len, results, row;
  4743. _this.type_id_db = {};
  4744. _this.type_name_db = {};
  4745. results = [];
  4746. for (i = 0, len = res.length; i < len; i++) {
  4747. row = res[i];
  4748. _this.type_id_db[row.name] = row.type_id;
  4749. results.push(_this.type_name_db[row.type_id] = row.name);
  4750. }
  4751. return results;
  4752. };
  4753. })(this));
  4754. return Page.cmd("chartDbQuery", "SELECT * FROM site", (function(_this) {
  4755. return function(res) {
  4756. var i, len, row, sites;
  4757. sites = {};
  4758. _this.sites_by_id = {};
  4759. for (i = 0, len = res.length; i < len; i++) {
  4760. row = res[i];
  4761. _this.site_id_db[row.address] = row.site_id;
  4762. _this.site_address_db[row.site_id] = row.address;
  4763. }
  4764. _this.chart_big.need_update = true;
  4765. _this.chart_timeline.need_update = true;
  4766. _this.chart_connections.need_update = true;
  4767. _this.chart_size.need_update = true;
  4768. _this.chart_radar.need_update = true;
  4769. _this.chart_world.need_update = true;
  4770. return Page.projector.scheduleRender();
  4771. };
  4772. })(this));
  4773. };
  4774. PageStats.prototype.loadChartjs = function() {
  4775. var e;
  4776. e = document.createElement("script");
  4777. e.type = "text/javascript";
  4778. e.src = "chartjs/chart.bundle.min.js";
  4779. e.onload = this.handleChartjsLoad;
  4780. return document.body.appendChild(e);
  4781. };
  4782. PageStats.prototype.render = function() {
  4783. var intervals, ref;
  4784. if (((ref = Page.server_info) != null ? ref.rev : void 0) < 3220) {
  4785. return h("div#PageStats", h("div.empty", [h("h4", "Need update"), h("small", "You have to update to ZeroNet version 0.6.1 to use this feature.")]));
  4786. }
  4787. if (this.need_update) {
  4788. this.update();
  4789. this.need_update = false;
  4790. }
  4791. if (!this.need_update && document.body.className !== "loaded") {
  4792. setTimeout((function() {
  4793. return document.body.className = "loaded";
  4794. }), 1000);
  4795. }
  4796. if (this.need_load_chartjs) {
  4797. setTimeout(this.loadChartjs, 500);
  4798. this.need_load_chartjs = false;
  4799. }
  4800. intervals = ["1w", "1d"];
  4801. return h("div#PageStats", [
  4802. h("div.intervals", intervals.map((function(_this) {
  4803. return function(interval) {
  4804. var interval_param;
  4805. if (interval === "1d") {
  4806. interval_param = void 0;
  4807. } else {
  4808. interval_param = interval;
  4809. }
  4810. return h("a.interval", {
  4811. href: Page.createUrl("interval", interval_param),
  4812. onclick: Page.handleLinkClick,
  4813. classes: {
  4814. active: interval_param === Page.params.interval
  4815. }
  4816. }, interval);
  4817. };
  4818. })(this))), this.chart_timeline.render(), this.chartjs_loaded ? [this.chart_big.render(), this.chart_legend.render(), this.chart_radar.render(), h("div.Charts", [this.chart_connections.render(), this.chart_size.render()]), this.chart_world.render(), this.country_list.render()] : void 0
  4819. ]);
  4820. };
  4821. return PageStats;
  4822. })(Class);
  4823. window.PageStats = PageStats;
  4824. }).call(this);
  4825. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/PageStats/StatList.coffee ---- */
  4826. (function() {
  4827. var StatList,
  4828. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  4829. 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; },
  4830. hasProp = {}.hasOwnProperty;
  4831. StatList = (function(superClass) {
  4832. extend(StatList, superClass);
  4833. function StatList() {
  4834. this.render = bind(this.render, this);
  4835. this.renderItem = bind(this.renderItem, this);
  4836. this.items = [];
  4837. }
  4838. StatList.prototype.renderItem = function(item) {
  4839. return h("div.stat-list-item", {
  4840. key: item.title,
  4841. classes: {
  4842. other: item.type === "other"
  4843. }
  4844. }, h("div.title", item.title), h("div.value", item.value + " peers"));
  4845. };
  4846. StatList.prototype.render = function() {
  4847. return h("div.StatList", [h("h4", "Top country"), h("div.stat-list-items", this.items.map(this.renderItem))]);
  4848. };
  4849. return StatList;
  4850. })(Class);
  4851. window.StatList = StatList;
  4852. }).call(this);
  4853. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/Animation.coffee ---- */
  4854. (function() {
  4855. var Animation;
  4856. Animation = (function() {
  4857. function Animation() {}
  4858. Animation.prototype.slideDown = function(elem, props) {
  4859. var cstyle, h, margin_bottom, margin_top, padding_bottom, padding_top, transition;
  4860. if (elem.offsetTop > 1000) {
  4861. return;
  4862. }
  4863. h = elem.offsetHeight;
  4864. cstyle = window.getComputedStyle(elem);
  4865. margin_top = cstyle.marginTop;
  4866. margin_bottom = cstyle.marginBottom;
  4867. padding_top = cstyle.paddingTop;
  4868. padding_bottom = cstyle.paddingBottom;
  4869. transition = cstyle.transition;
  4870. elem.style.boxSizing = "border-box";
  4871. elem.style.overflow = "hidden";
  4872. elem.style.transform = "scale(0.6)";
  4873. elem.style.opacity = "0";
  4874. elem.style.height = "0px";
  4875. elem.style.marginTop = "0px";
  4876. elem.style.marginBottom = "0px";
  4877. elem.style.paddingTop = "0px";
  4878. elem.style.paddingBottom = "0px";
  4879. elem.style.transition = "none";
  4880. setTimeout((function() {
  4881. elem.className += " animate-inout";
  4882. elem.style.height = h + "px";
  4883. elem.style.transform = "scale(1)";
  4884. elem.style.opacity = "1";
  4885. elem.style.marginTop = margin_top;
  4886. elem.style.marginBottom = margin_bottom;
  4887. elem.style.paddingTop = padding_top;
  4888. return elem.style.paddingBottom = padding_bottom;
  4889. }), 1);
  4890. return elem.addEventListener("transitionend", function() {
  4891. elem.classList.remove("animate-inout");
  4892. elem.style.transition = elem.style.transform = elem.style.opacity = elem.style.height = null;
  4893. elem.style.boxSizing = elem.style.marginTop = elem.style.marginBottom = null;
  4894. elem.style.paddingTop = elem.style.paddingBottom = elem.style.overflow = null;
  4895. return elem.removeEventListener("transitionend", arguments.callee, false);
  4896. });
  4897. };
  4898. Animation.prototype.slideUp = function(elem, remove_func, props) {
  4899. if (elem.offsetTop > 1000) {
  4900. return remove_func();
  4901. }
  4902. elem.className += " animate-back";
  4903. elem.style.boxSizing = "border-box";
  4904. elem.style.height = elem.offsetHeight + "px";
  4905. elem.style.overflow = "hidden";
  4906. elem.style.transform = "scale(1)";
  4907. elem.style.opacity = "1";
  4908. elem.style.pointerEvents = "none";
  4909. setTimeout((function() {
  4910. elem.style.height = "0px";
  4911. elem.style.marginTop = "0px";
  4912. elem.style.marginBottom = "0px";
  4913. elem.style.paddingTop = "0px";
  4914. elem.style.paddingBottom = "0px";
  4915. elem.style.transform = "scale(0.8)";
  4916. elem.style.borderTopWidth = "0px";
  4917. elem.style.borderBottomWidth = "0px";
  4918. return elem.style.opacity = "0";
  4919. }), 1);
  4920. return elem.addEventListener("transitionend", function(e) {
  4921. if (e.propertyName === "opacity" || e.elapsedTime >= 0.6) {
  4922. elem.removeEventListener("transitionend", arguments.callee, false);
  4923. return remove_func();
  4924. }
  4925. });
  4926. };
  4927. Animation.prototype.slideUpInout = function(elem, remove_func, props) {
  4928. elem.className += " animate-inout";
  4929. elem.style.boxSizing = "border-box";
  4930. elem.style.height = elem.offsetHeight + "px";
  4931. elem.style.overflow = "hidden";
  4932. elem.style.transform = "scale(1)";
  4933. elem.style.opacity = "1";
  4934. elem.style.pointerEvents = "none";
  4935. setTimeout((function() {
  4936. elem.style.height = "0px";
  4937. elem.style.marginTop = "0px";
  4938. elem.style.marginBottom = "0px";
  4939. elem.style.paddingTop = "0px";
  4940. elem.style.paddingBottom = "0px";
  4941. elem.style.transform = "scale(0.8)";
  4942. elem.style.borderTopWidth = "0px";
  4943. elem.style.borderBottomWidth = "0px";
  4944. return elem.style.opacity = "0";
  4945. }), 1);
  4946. return elem.addEventListener("transitionend", function(e) {
  4947. if (e.propertyName === "opacity" || e.elapsedTime >= 0.6) {
  4948. elem.removeEventListener("transitionend", arguments.callee, false);
  4949. return remove_func();
  4950. }
  4951. });
  4952. };
  4953. Animation.prototype.showRight = function(elem, props) {
  4954. elem.className += " animate";
  4955. elem.style.opacity = 0;
  4956. elem.style.transform = "TranslateX(-20px) Scale(1.01)";
  4957. setTimeout((function() {
  4958. elem.style.opacity = 1;
  4959. return elem.style.transform = "TranslateX(0px) Scale(1)";
  4960. }), 1);
  4961. return elem.addEventListener("transitionend", function() {
  4962. elem.classList.remove("animate");
  4963. return elem.style.transform = elem.style.opacity = null;
  4964. });
  4965. };
  4966. Animation.prototype.show = function(elem, props) {
  4967. var delay, ref;
  4968. delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
  4969. elem.style.opacity = 0;
  4970. setTimeout((function() {
  4971. return elem.className += " animate";
  4972. }), 1);
  4973. setTimeout((function() {
  4974. return elem.style.opacity = 1;
  4975. }), delay);
  4976. return elem.addEventListener("transitionend", function() {
  4977. elem.classList.remove("animate");
  4978. elem.style.opacity = null;
  4979. return elem.removeEventListener("transitionend", arguments.callee, false);
  4980. });
  4981. };
  4982. Animation.prototype.hide = function(elem, remove_func, props) {
  4983. var delay, ref;
  4984. delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
  4985. elem.className += " animate";
  4986. setTimeout((function() {
  4987. return elem.style.opacity = 0;
  4988. }), delay);
  4989. return elem.addEventListener("transitionend", function(e) {
  4990. if (e.propertyName === "opacity") {
  4991. return remove_func();
  4992. }
  4993. });
  4994. };
  4995. Animation.prototype.addVisibleClass = function(elem, props) {
  4996. return setTimeout(function() {
  4997. return elem.classList.add("visible");
  4998. });
  4999. };
  5000. return Animation;
  5001. })();
  5002. window.Animation = new Animation();
  5003. }).call(this);
  5004. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/Dollar.coffee ---- */
  5005. (function() {
  5006. window.$ = function(selector) {
  5007. if (selector.startsWith("#")) {
  5008. return document.getElementById(selector.replace("#", ""));
  5009. }
  5010. };
  5011. }).call(this);
  5012. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/ItemList.coffee ---- */
  5013. (function() {
  5014. var ItemList;
  5015. ItemList = (function() {
  5016. function ItemList(item_class1, key1) {
  5017. this.item_class = item_class1;
  5018. this.key = key1;
  5019. this.items = [];
  5020. this.items_bykey = {};
  5021. }
  5022. ItemList.prototype.sync = function(rows, item_class, key) {
  5023. var current_obj, i, item, len, results, row;
  5024. this.items.splice(0, this.items.length);
  5025. results = [];
  5026. for (i = 0, len = rows.length; i < len; i++) {
  5027. row = rows[i];
  5028. current_obj = this.items_bykey[row[this.key]];
  5029. if (current_obj) {
  5030. current_obj.row = row;
  5031. results.push(this.items.push(current_obj));
  5032. } else {
  5033. item = new this.item_class(row, this);
  5034. this.items_bykey[row[this.key]] = item;
  5035. results.push(this.items.push(item));
  5036. }
  5037. }
  5038. return results;
  5039. };
  5040. ItemList.prototype.deleteItem = function(item) {
  5041. var index;
  5042. index = this.items.indexOf(item);
  5043. if (index > -1) {
  5044. this.items.splice(index, 1);
  5045. } else {
  5046. console.log("Can't delete item", item);
  5047. }
  5048. return delete this.items_bykey[item.row[this.key]];
  5049. };
  5050. return ItemList;
  5051. })();
  5052. window.ItemList = ItemList;
  5053. }).call(this);
  5054. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/Menu.coffee ---- */
  5055. (function() {
  5056. var Menu,
  5057. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  5058. Menu = (function() {
  5059. function Menu() {
  5060. this.render = bind(this.render, this);
  5061. this.renderItem = bind(this.renderItem, this);
  5062. this.handleClick = bind(this.handleClick, this);
  5063. this.storeNode = bind(this.storeNode, this);
  5064. this.toggle = bind(this.toggle, this);
  5065. this.hide = bind(this.hide, this);
  5066. this.show = bind(this.show, this);
  5067. this.visible = false;
  5068. this.items = [];
  5069. this.node = null;
  5070. this.height = 0;
  5071. }
  5072. Menu.prototype.show = function() {
  5073. var ref;
  5074. if ((ref = window.visible_menu) != null) {
  5075. ref.hide();
  5076. }
  5077. this.visible = true;
  5078. return window.visible_menu = this;
  5079. };
  5080. Menu.prototype.hide = function() {
  5081. return this.visible = false;
  5082. };
  5083. Menu.prototype.toggle = function() {
  5084. if (this.visible) {
  5085. this.hide();
  5086. } else {
  5087. this.show();
  5088. }
  5089. return Page.projector.scheduleRender();
  5090. };
  5091. Menu.prototype.addItem = function(title, cb, selected) {
  5092. if (selected == null) {
  5093. selected = false;
  5094. }
  5095. return this.items.push([title, cb, selected]);
  5096. };
  5097. Menu.prototype.storeNode = function(node) {
  5098. this.node = node;
  5099. if (this.visible) {
  5100. node.className = node.className.replace("visible", "");
  5101. setTimeout(((function(_this) {
  5102. return function() {
  5103. node.className += " visible";
  5104. return node.style.maxHeight = _this.height + "px";
  5105. };
  5106. })(this)), 20);
  5107. node.style.maxHeight = "none";
  5108. this.height = node.offsetHeight;
  5109. return node.style.maxHeight = "0px";
  5110. }
  5111. };
  5112. Menu.prototype.handleClick = function(e) {
  5113. var cb, i, item, keep_menu, len, ref, selected, title;
  5114. keep_menu = false;
  5115. ref = this.items;
  5116. for (i = 0, len = ref.length; i < len; i++) {
  5117. item = ref[i];
  5118. title = item[0], cb = item[1], selected = item[2];
  5119. if (title === e.target.textContent || e.target["data-title"] === title) {
  5120. keep_menu = cb(item);
  5121. break;
  5122. }
  5123. }
  5124. if (keep_menu !== true && cb !== null) {
  5125. this.hide();
  5126. }
  5127. return false;
  5128. };
  5129. Menu.prototype.renderItem = function(item) {
  5130. var cb, href, onclick, selected, title;
  5131. title = item[0], cb = item[1], selected = item[2];
  5132. if (typeof selected === "function") {
  5133. selected = selected();
  5134. }
  5135. if (title === "---") {
  5136. return h("div.menu-item-separator");
  5137. } else {
  5138. if (typeof cb === "string") {
  5139. href = cb;
  5140. onclick = true;
  5141. } else {
  5142. href = "#" + title;
  5143. onclick = this.handleClick;
  5144. }
  5145. return h("a.menu-item", {
  5146. href: href,
  5147. onclick: onclick,
  5148. "data-title": title,
  5149. key: title,
  5150. classes: {
  5151. "selected": selected,
  5152. "noaction": cb === null
  5153. }
  5154. }, title);
  5155. }
  5156. };
  5157. Menu.prototype.render = function(class_name) {
  5158. var max_height;
  5159. if (class_name == null) {
  5160. class_name = "";
  5161. }
  5162. if (this.visible || this.node) {
  5163. if (this.visible) {
  5164. max_height = this.height;
  5165. } else {
  5166. max_height = 0;
  5167. }
  5168. return h("div.menu" + class_name, {
  5169. classes: {
  5170. "visible": this.visible
  5171. },
  5172. style: "max-height: " + max_height + "px",
  5173. afterCreate: this.storeNode
  5174. }, this.items.map(this.renderItem));
  5175. }
  5176. };
  5177. return Menu;
  5178. })();
  5179. window.Menu = Menu;
  5180. document.body.addEventListener("mouseup", function(e) {
  5181. if (!window.visible_menu || !window.visible_menu.node) {
  5182. return false;
  5183. }
  5184. if (e.target !== window.visible_menu.node.parentNode && e.target.parentNode !== window.visible_menu.node && e.target.parentNode !== window.visible_menu.node.parentNode && e.target.parentNode !== window.visible_menu.node && e.target.parentNode.parentNode !== window.visible_menu.node.parentNode) {
  5185. window.visible_menu.hide();
  5186. return Page.projector.scheduleRender();
  5187. }
  5188. });
  5189. }).call(this);
  5190. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/Prototypes.coffee ---- */
  5191. (function() {
  5192. String.prototype.startsWith = function(s) {
  5193. return this.slice(0, s.length) === s;
  5194. };
  5195. String.prototype.endsWith = function(s) {
  5196. return s === '' || this.slice(-s.length) === s;
  5197. };
  5198. String.prototype.repeat = function(count) {
  5199. return new Array(count + 1).join(this);
  5200. };
  5201. window.isEmpty = function(obj) {
  5202. var key;
  5203. for (key in obj) {
  5204. return false;
  5205. }
  5206. return true;
  5207. };
  5208. }).call(this);
  5209. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/RateLimit.coffee ---- */
  5210. (function() {
  5211. var call_after_interval, limits;
  5212. limits = {};
  5213. call_after_interval = {};
  5214. window.RateLimit = function(interval, fn) {
  5215. if (!limits[fn]) {
  5216. call_after_interval[fn] = false;
  5217. fn();
  5218. return limits[fn] = setTimeout((function() {
  5219. if (call_after_interval[fn]) {
  5220. fn();
  5221. }
  5222. delete limits[fn];
  5223. return delete call_after_interval[fn];
  5224. }), interval);
  5225. } else {
  5226. return call_after_interval[fn] = true;
  5227. }
  5228. };
  5229. }).call(this);
  5230. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/RateLimitCb.coffee ---- */
  5231. (function() {
  5232. var call_after_interval, calling, calling_iterval, last_time,
  5233. slice = [].slice;
  5234. last_time = {};
  5235. calling = {};
  5236. calling_iterval = {};
  5237. call_after_interval = {};
  5238. window.RateLimitCb = function(interval, fn, args) {
  5239. var cb;
  5240. if (args == null) {
  5241. args = [];
  5242. }
  5243. cb = function() {
  5244. var left;
  5245. left = interval - (Date.now() - last_time[fn]);
  5246. if (left <= 0) {
  5247. delete last_time[fn];
  5248. if (calling[fn]) {
  5249. RateLimitCb(interval, fn, calling[fn]);
  5250. }
  5251. return delete calling[fn];
  5252. } else {
  5253. return setTimeout((function() {
  5254. delete last_time[fn];
  5255. if (calling[fn]) {
  5256. RateLimitCb(interval, fn, calling[fn]);
  5257. }
  5258. return delete calling[fn];
  5259. }), left);
  5260. }
  5261. };
  5262. if (last_time[fn]) {
  5263. return calling[fn] = args;
  5264. } else {
  5265. last_time[fn] = Date.now();
  5266. return fn.apply(this, [cb].concat(slice.call(args)));
  5267. }
  5268. };
  5269. window.RateLimit = function(interval, fn) {
  5270. if (calling_iterval[fn] > interval) {
  5271. clearInterval(calling[fn]);
  5272. delete calling[fn];
  5273. }
  5274. if (!calling[fn]) {
  5275. call_after_interval[fn] = false;
  5276. fn();
  5277. calling_iterval[fn] = interval;
  5278. return calling[fn] = setTimeout((function() {
  5279. if (call_after_interval[fn]) {
  5280. fn();
  5281. }
  5282. delete calling[fn];
  5283. return delete call_after_interval[fn];
  5284. }), interval);
  5285. } else {
  5286. return call_after_interval[fn] = true;
  5287. }
  5288. };
  5289. /*
  5290. window.s = Date.now()
  5291. window.load = (done, num) ->
  5292. console.log "Loading #{num}...", Date.now()-window.s
  5293. setTimeout (-> done()), 1000
  5294. RateLimit 500, window.load, [0] # Called instantly
  5295. RateLimit 500, window.load, [1]
  5296. setTimeout (-> RateLimit 500, window.load, [300]), 300
  5297. setTimeout (-> RateLimit 500, window.load, [600]), 600 # Called after 1000ms
  5298. setTimeout (-> RateLimit 500, window.load, [1000]), 1000
  5299. setTimeout (-> RateLimit 500, window.load, [1200]), 1200 # Called after 2000ms
  5300. setTimeout (-> RateLimit 500, window.load, [3000]), 3000 # Called after 3000ms
  5301. */
  5302. }).call(this);
  5303. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/Text.coffee ---- */
  5304. (function() {
  5305. var MarkedRenderer, Text,
  5306. 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; },
  5307. hasProp = {}.hasOwnProperty,
  5308. 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; };
  5309. MarkedRenderer = (function(superClass) {
  5310. extend(MarkedRenderer, superClass);
  5311. function MarkedRenderer() {
  5312. return MarkedRenderer.__super__.constructor.apply(this, arguments);
  5313. }
  5314. MarkedRenderer.prototype.image = function(href, title, text) {
  5315. return "<code>![" + text + "](" + href + ")</code>";
  5316. };
  5317. return MarkedRenderer;
  5318. })(marked.Renderer);
  5319. Text = (function() {
  5320. function Text() {}
  5321. Text.prototype.toColor = function(text, saturation, lightness) {
  5322. var hash, i, j, ref;
  5323. if (saturation == null) {
  5324. saturation = 30;
  5325. }
  5326. if (lightness == null) {
  5327. lightness = 50;
  5328. }
  5329. hash = 0;
  5330. for (i = j = 0, ref = text.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
  5331. hash += text.charCodeAt(i) * i;
  5332. hash = hash % 1777;
  5333. }
  5334. return "hsl(" + (hash % 360) + ("," + saturation + "%," + lightness + "%)");
  5335. };
  5336. Text.prototype.renderMarked = function(text, options) {
  5337. if (options == null) {
  5338. options = {};
  5339. }
  5340. options["gfm"] = true;
  5341. options["breaks"] = true;
  5342. options["sanitize"] = true;
  5343. options["renderer"] = marked_renderer;
  5344. text = marked(text, options);
  5345. return this.fixHtmlLinks(text);
  5346. };
  5347. Text.prototype.emailLinks = function(text) {
  5348. 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>");
  5349. };
  5350. Text.prototype.fixHtmlLinks = function(text) {
  5351. if (window.is_proxy) {
  5352. return text.replace(/href="http:\/\/(127.0.0.1|localhost):43110/g, 'href="http://zero');
  5353. } else {
  5354. return text.replace(/href="http:\/\/(127.0.0.1|localhost):43110/g, 'href="');
  5355. }
  5356. };
  5357. Text.prototype.fixLink = function(link) {
  5358. var back;
  5359. if (window.is_proxy) {
  5360. back = link.replace(/http:\/\/(127.0.0.1|localhost):43110/, 'http://zero');
  5361. return back.replace(/http:\/\/zero\/([^\/]+\.bit)/, "http://$1");
  5362. } else {
  5363. return link.replace(/http:\/\/(127.0.0.1|localhost):43110/, '');
  5364. }
  5365. };
  5366. Text.prototype.toUrl = function(text) {
  5367. return text.replace(/[^A-Za-z0-9]/g, "+").replace(/[+]+/g, "+").replace(/[+]+$/, "");
  5368. };
  5369. Text.prototype.getSiteUrl = function(address) {
  5370. if (window.is_proxy) {
  5371. if (indexOf.call(address, ".") >= 0) {
  5372. return "http://" + address + "/";
  5373. } else {
  5374. return "http://zero/" + address + "/";
  5375. }
  5376. } else {
  5377. return "/" + address + "/";
  5378. }
  5379. };
  5380. Text.prototype.fixReply = function(text) {
  5381. return text.replace(/(>.*\n)([^\n>])/gm, "$1\n$2");
  5382. };
  5383. Text.prototype.toBitcoinAddress = function(text) {
  5384. return text.replace(/[^A-Za-z0-9]/g, "");
  5385. };
  5386. Text.prototype.jsonEncode = function(obj) {
  5387. return unescape(encodeURIComponent(JSON.stringify(obj)));
  5388. };
  5389. Text.prototype.jsonDecode = function(obj) {
  5390. return JSON.parse(decodeURIComponent(escape(obj)));
  5391. };
  5392. Text.prototype.fileEncode = function(obj) {
  5393. if (typeof obj === "string") {
  5394. return btoa(unescape(encodeURIComponent(obj)));
  5395. } else {
  5396. return btoa(unescape(encodeURIComponent(JSON.stringify(obj, void 0, '\t'))));
  5397. }
  5398. };
  5399. Text.prototype.utf8Encode = function(s) {
  5400. return unescape(encodeURIComponent(s));
  5401. };
  5402. Text.prototype.utf8Decode = function(s) {
  5403. return decodeURIComponent(escape(s));
  5404. };
  5405. Text.prototype.distance = function(s1, s2) {
  5406. var char, extra_parts, j, key, len, match, next_find, next_find_i, val;
  5407. s1 = s1.toLocaleLowerCase();
  5408. s2 = s2.toLocaleLowerCase();
  5409. next_find_i = 0;
  5410. next_find = s2[0];
  5411. match = true;
  5412. extra_parts = {};
  5413. for (j = 0, len = s1.length; j < len; j++) {
  5414. char = s1[j];
  5415. if (char !== next_find) {
  5416. if (extra_parts[next_find_i]) {
  5417. extra_parts[next_find_i] += char;
  5418. } else {
  5419. extra_parts[next_find_i] = char;
  5420. }
  5421. } else {
  5422. next_find_i++;
  5423. next_find = s2[next_find_i];
  5424. }
  5425. }
  5426. if (extra_parts[next_find_i]) {
  5427. extra_parts[next_find_i] = "";
  5428. }
  5429. extra_parts = (function() {
  5430. var results;
  5431. results = [];
  5432. for (key in extra_parts) {
  5433. val = extra_parts[key];
  5434. results.push(val);
  5435. }
  5436. return results;
  5437. })();
  5438. if (next_find_i >= s2.length) {
  5439. return extra_parts.length + extra_parts.join("").length;
  5440. } else {
  5441. return false;
  5442. }
  5443. };
  5444. Text.prototype.parseQuery = function(query) {
  5445. var j, key, len, params, part, parts, ref, val;
  5446. params = {};
  5447. parts = query.split('&');
  5448. for (j = 0, len = parts.length; j < len; j++) {
  5449. part = parts[j];
  5450. ref = part.split("="), key = ref[0], val = ref[1];
  5451. if (val) {
  5452. params[decodeURIComponent(key)] = decodeURIComponent(val);
  5453. } else {
  5454. params["url"] = decodeURIComponent(key);
  5455. }
  5456. }
  5457. return params;
  5458. };
  5459. Text.prototype.encodeQuery = function(params) {
  5460. var back, key, val;
  5461. back = [];
  5462. if (params.url) {
  5463. back.push(params.url);
  5464. }
  5465. for (key in params) {
  5466. val = params[key];
  5467. if (!val || key === "url") {
  5468. continue;
  5469. }
  5470. back.push((encodeURIComponent(key)) + "=" + (encodeURIComponent(val)));
  5471. }
  5472. return back.join("&");
  5473. };
  5474. Text.prototype.highlight = function(text, search) {
  5475. var back, i, j, len, part, parts;
  5476. if (!text) {
  5477. return [""];
  5478. }
  5479. parts = text.split(RegExp(search, "i"));
  5480. back = [];
  5481. for (i = j = 0, len = parts.length; j < len; i = ++j) {
  5482. part = parts[i];
  5483. back.push(part);
  5484. if (i < parts.length - 1) {
  5485. back.push(h("span.highlight", {
  5486. key: i
  5487. }, search));
  5488. }
  5489. }
  5490. return back;
  5491. };
  5492. Text.prototype.formatSize = function(size) {
  5493. var size_mb;
  5494. if (!parseInt(size)) {
  5495. return "";
  5496. }
  5497. size_mb = size / 1024 / 1024;
  5498. if (size_mb >= 1000) {
  5499. return (size_mb / 1024).toFixed(1) + " GB";
  5500. } else if (size_mb >= 100) {
  5501. return size_mb.toFixed(0) + " MB";
  5502. } else if (size / 1024 >= 1000) {
  5503. return size_mb.toFixed(2) + " MB";
  5504. } else {
  5505. return (size / 1024).toFixed(2) + " KB";
  5506. }
  5507. };
  5508. return Text;
  5509. })();
  5510. window.marked_renderer = new MarkedRenderer();
  5511. window.is_proxy = document.location.host === "zero" || window.location.pathname === "/";
  5512. window.Text = new Text();
  5513. }).call(this);
  5514. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/Time.coffee ---- */
  5515. (function() {
  5516. var Time;
  5517. Time = (function() {
  5518. function Time() {}
  5519. Time.prototype.since = function(timestamp) {
  5520. var back, minutes, now, secs;
  5521. now = +(new Date) / 1000;
  5522. if (timestamp > 1000000000000) {
  5523. timestamp = timestamp / 1000;
  5524. }
  5525. secs = now - timestamp;
  5526. if (secs < 60) {
  5527. back = "Just now";
  5528. } else if (secs < 60 * 60) {
  5529. minutes = Math.round(secs / 60);
  5530. back = "" + minutes + " minutes ago";
  5531. } else if (secs < 60 * 60 * 24) {
  5532. back = (Math.round(secs / 60 / 60)) + " hours ago";
  5533. } else if (secs < 60 * 60 * 24 * 3) {
  5534. back = (Math.round(secs / 60 / 60 / 24)) + " days ago";
  5535. } else {
  5536. back = "on " + this.date(timestamp);
  5537. }
  5538. back = back.replace(/^1 ([a-z]+)s/, "1 $1");
  5539. return back;
  5540. };
  5541. Time.prototype.dateIso = function(timestamp) {
  5542. var tzoffset;
  5543. if (timestamp == null) {
  5544. timestamp = null;
  5545. }
  5546. if (!timestamp) {
  5547. timestamp = window.Time.timestamp();
  5548. }
  5549. if (timestamp > 1000000000000) {
  5550. timestamp = timestamp / 1000;
  5551. }
  5552. tzoffset = (new Date()).getTimezoneOffset() * 60;
  5553. return (new Date((timestamp - tzoffset) * 1000)).toISOString().split("T")[0];
  5554. };
  5555. Time.prototype.date = function(timestamp, format) {
  5556. var display, parts;
  5557. if (timestamp == null) {
  5558. timestamp = null;
  5559. }
  5560. if (format == null) {
  5561. format = "short";
  5562. }
  5563. if (!timestamp) {
  5564. timestamp = window.Time.timestamp();
  5565. }
  5566. if (timestamp > 1000000000000) {
  5567. timestamp = timestamp / 1000;
  5568. }
  5569. parts = (new Date(timestamp * 1000)).toString().split(" ");
  5570. if (format === "short") {
  5571. display = parts.slice(1, 4);
  5572. } else if (format === "day") {
  5573. display = parts.slice(1, 3);
  5574. } else if (format === "month") {
  5575. display = [parts[1], parts[3]];
  5576. } else if (format === "long") {
  5577. display = parts.slice(1, 5);
  5578. }
  5579. return display.join(" ").replace(/( [0-9]{4})/, ",$1");
  5580. };
  5581. Time.prototype.weekDay = function(timestamp) {
  5582. if (timestamp > 1000000000000) {
  5583. timestamp = timestamp / 1000;
  5584. }
  5585. return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][(new Date(timestamp * 1000)).getDay()];
  5586. };
  5587. Time.prototype.timestamp = function(date) {
  5588. if (date == null) {
  5589. date = "";
  5590. }
  5591. if (date === "now" || date === "") {
  5592. return parseInt(+(new Date) / 1000);
  5593. } else {
  5594. return parseInt(Date.parse(date) / 1000);
  5595. }
  5596. };
  5597. return Time;
  5598. })();
  5599. window.Time = new Time;
  5600. }).call(this);
  5601. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/Translate.coffee ---- */
  5602. (function() {
  5603. window._ = function(s) {
  5604. return s;
  5605. };
  5606. }).call(this);
  5607. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/utils/ZeroFrame.coffee ---- */
  5608. (function() {
  5609. var ZeroFrame,
  5610. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  5611. 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; },
  5612. hasProp = {}.hasOwnProperty;
  5613. ZeroFrame = (function(superClass) {
  5614. extend(ZeroFrame, superClass);
  5615. function ZeroFrame(url) {
  5616. this.onCloseWebsocket = bind(this.onCloseWebsocket, this);
  5617. this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
  5618. this.onRequest = bind(this.onRequest, this);
  5619. this.onMessage = bind(this.onMessage, this);
  5620. this.url = url;
  5621. this.waiting_cb = {};
  5622. this.wrapper_nonce = document.location.href.replace(/.*wrapper_nonce=([A-Za-z0-9]+).*/, "$1");
  5623. this.connect();
  5624. this.next_message_id = 1;
  5625. this.history_state = {};
  5626. this.init();
  5627. }
  5628. ZeroFrame.prototype.init = function() {
  5629. return this;
  5630. };
  5631. ZeroFrame.prototype.connect = function() {
  5632. this.target = window.parent;
  5633. window.addEventListener("message", this.onMessage, false);
  5634. this.cmd("innerReady");
  5635. window.addEventListener("beforeunload", (function(_this) {
  5636. return function(e) {
  5637. _this.log("save scrollTop", window.pageYOffset);
  5638. _this.history_state["scrollTop"] = window.pageYOffset;
  5639. return _this.cmd("wrapperReplaceState", [_this.history_state, null]);
  5640. };
  5641. })(this));
  5642. return this.cmd("wrapperGetState", [], (function(_this) {
  5643. return function(state) {
  5644. if (state != null) {
  5645. _this.history_state = state;
  5646. }
  5647. _this.log("restore scrollTop", state, window.pageYOffset);
  5648. if (window.pageYOffset === 0 && state) {
  5649. return window.scroll(window.pageXOffset, state.scrollTop);
  5650. }
  5651. };
  5652. })(this));
  5653. };
  5654. ZeroFrame.prototype.onMessage = function(e) {
  5655. var cmd, message;
  5656. message = e.data;
  5657. cmd = message.cmd;
  5658. if (cmd === "response") {
  5659. if (this.waiting_cb[message.to] != null) {
  5660. return this.waiting_cb[message.to](message.result);
  5661. } else {
  5662. return this.log("Websocket callback not found:", message);
  5663. }
  5664. } else if (cmd === "wrapperReady") {
  5665. return this.cmd("innerReady");
  5666. } else if (cmd === "ping") {
  5667. return this.response(message.id, "pong");
  5668. } else if (cmd === "wrapperOpenedWebsocket") {
  5669. return this.onOpenWebsocket();
  5670. } else if (cmd === "wrapperClosedWebsocket") {
  5671. return this.onCloseWebsocket();
  5672. } else {
  5673. return this.onRequest(cmd, message.params);
  5674. }
  5675. };
  5676. ZeroFrame.prototype.onRequest = function(cmd, message) {
  5677. return this.log("Unknown request", message);
  5678. };
  5679. ZeroFrame.prototype.response = function(to, result) {
  5680. return this.send({
  5681. "cmd": "response",
  5682. "to": to,
  5683. "result": result
  5684. });
  5685. };
  5686. ZeroFrame.prototype.cmd = function(cmd, params, cb) {
  5687. if (params == null) {
  5688. params = {};
  5689. }
  5690. if (cb == null) {
  5691. cb = null;
  5692. }
  5693. return this.send({
  5694. "cmd": cmd,
  5695. "params": params
  5696. }, cb);
  5697. };
  5698. ZeroFrame.prototype.send = function(message, cb) {
  5699. if (cb == null) {
  5700. cb = null;
  5701. }
  5702. message.wrapper_nonce = this.wrapper_nonce;
  5703. message.id = this.next_message_id;
  5704. this.next_message_id += 1;
  5705. this.target.postMessage(message, "*");
  5706. if (cb) {
  5707. return this.waiting_cb[message.id] = cb;
  5708. }
  5709. };
  5710. ZeroFrame.prototype.onOpenWebsocket = function() {
  5711. return this.log("Websocket open");
  5712. };
  5713. ZeroFrame.prototype.onCloseWebsocket = function() {
  5714. return this.log("Websocket close");
  5715. };
  5716. return ZeroFrame;
  5717. })(Class);
  5718. window.ZeroFrame = ZeroFrame;
  5719. }).call(this);
  5720. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/Head.coffee ---- */
  5721. (function() {
  5722. var Head,
  5723. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  5724. 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; },
  5725. hasProp = {}.hasOwnProperty,
  5726. 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; };
  5727. Head = (function(superClass) {
  5728. extend(Head, superClass);
  5729. function Head() {
  5730. this.render = bind(this.render, this);
  5731. this.handleModeClick = bind(this.handleModeClick, this);
  5732. this.handleShutdownZeronetClick = bind(this.handleShutdownZeronetClick, this);
  5733. this.handleUpdateZeronetClick = bind(this.handleUpdateZeronetClick, this);
  5734. this.handleManageMutesClick = bind(this.handleManageMutesClick, this);
  5735. this.handleTorClick = bind(this.handleTorClick, this);
  5736. this.handleOrderbyClick = bind(this.handleOrderbyClick, this);
  5737. this.handleUpdateAllClick = bind(this.handleUpdateAllClick, this);
  5738. this.handleSettingsClick = bind(this.handleSettingsClick, this);
  5739. this.handleBackupClick = bind(this.handleBackupClick, this);
  5740. this.handleCreateSiteClick = bind(this.handleCreateSiteClick, this);
  5741. this.renderMenuLanguage = bind(this.renderMenuLanguage, this);
  5742. this.handleLanguageClick = bind(this.handleLanguageClick, this);
  5743. this.menu_settings = new Menu();
  5744. }
  5745. Head.prototype.formatUpdateInfo = function() {
  5746. if (parseFloat(Page.server_info.version.replace(".", "0")) < parseFloat(Page.latest_version.replace(".", "0"))) {
  5747. return "New version available!";
  5748. } else {
  5749. return "Up to date!";
  5750. }
  5751. };
  5752. Head.prototype.handleLanguageClick = function(e) {
  5753. var lang;
  5754. if (Page.server_info.rev < 1750) {
  5755. return Page.cmd("wrapperNotification", ["info", "You need ZeroNet 0.5.1 to change the interface's language"]);
  5756. }
  5757. lang = e.target.hash.replace("#", "");
  5758. Page.cmd("configSet", ["language", lang], function() {
  5759. Page.server_info.language = lang;
  5760. return top.location = "?Home";
  5761. });
  5762. return false;
  5763. };
  5764. Head.prototype.renderMenuLanguage = function() {
  5765. var lang, langs, ref;
  5766. langs = ["da", "de", "en", "es", "fr", "hu", "it", "nl", "pl", "pt", "pt-br", "ru", "sk", "tr", "uk", "zh", "zh-tw"];
  5767. if (Page.server_info.language && (ref = Page.server_info.language, indexOf.call(langs, ref) < 0)) {
  5768. langs.push(Page.server_info.language);
  5769. }
  5770. return h("div.menu-radio", h("div", "Language: "), (function() {
  5771. var i, len, results;
  5772. results = [];
  5773. for (i = 0, len = langs.length; i < len; i++) {
  5774. lang = langs[i];
  5775. results.push([
  5776. h("a", {
  5777. href: "#" + lang,
  5778. onclick: this.handleLanguageClick,
  5779. classes: {
  5780. selected: Page.server_info.language === lang,
  5781. long: lang.length > 2
  5782. }
  5783. }, lang), " "
  5784. ]);
  5785. }
  5786. return results;
  5787. }).call(this));
  5788. };
  5789. Head.prototype.handleCreateSiteClick = function() {
  5790. if (Page.server_info.rev < 1770) {
  5791. return Page.cmd("wrapperNotification", ["info", "You need to update your ZeroNet client to use this feature"]);
  5792. }
  5793. return Page.cmd("siteClone", [Page.site_info.address, "template-new"]);
  5794. };
  5795. Head.prototype.handleBackupClick = function() {
  5796. if (Page.server_info.rev < 2165) {
  5797. return Page.cmd("wrapperNotification", ["info", "You need to update your ZeroNet client to use this feature"]);
  5798. }
  5799. Page.cmd("serverShowdirectory", "backup");
  5800. return Page.cmd("wrapperNotification", ["info", "Backup <b>users.json</b> file to keep your identity safe."]);
  5801. };
  5802. Head.prototype.handleSettingsClick = function() {
  5803. var base, orderby;
  5804. if ((base = Page.settings).sites_orderby == null) {
  5805. base.sites_orderby = "peers";
  5806. }
  5807. orderby = Page.settings.sites_orderby;
  5808. this.menu_settings.items = [];
  5809. this.menu_settings.items.push(["Update all sites", this.handleUpdateAllClick]);
  5810. this.menu_settings.items.push(["---"]);
  5811. this.menu_settings.items.push([
  5812. "Order sites by peers", ((function(_this) {
  5813. return function() {
  5814. return _this.handleOrderbyClick("peers");
  5815. };
  5816. })(this)), orderby === "peers"
  5817. ]);
  5818. this.menu_settings.items.push([
  5819. "Order sites by update time", ((function(_this) {
  5820. return function() {
  5821. return _this.handleOrderbyClick("modified");
  5822. };
  5823. })(this)), orderby === "modified"
  5824. ]);
  5825. this.menu_settings.items.push([
  5826. "Order sites by add time", ((function(_this) {
  5827. return function() {
  5828. return _this.handleOrderbyClick("addtime");
  5829. };
  5830. })(this)), orderby === "addtime"
  5831. ]);
  5832. this.menu_settings.items.push([
  5833. "Order sites by size", ((function(_this) {
  5834. return function() {
  5835. return _this.handleOrderbyClick("size");
  5836. };
  5837. })(this)), orderby === "size"
  5838. ]);
  5839. this.menu_settings.items.push(["---"]);
  5840. this.menu_settings.items.push([this.renderMenuLanguage(), null]);
  5841. this.menu_settings.items.push(["---"]);
  5842. this.menu_settings.items.push(["Create new, empty site", this.handleCreateSiteClick]);
  5843. this.menu_settings.items.push(["---"]);
  5844. this.menu_settings.items.push([[h("span.emoji", "\uD83D\uDD07 "), "Manage muted users"], this.handleManageMutesClick]);
  5845. this.menu_settings.items.push(["Show data directory", this.handleBackupClick]);
  5846. this.menu_settings.items.push(["Version " + Page.server_info.version + " (rev" + Page.server_info.rev + "): " + (this.formatUpdateInfo()), this.handleUpdateZeronetClick]);
  5847. this.menu_settings.items.push(["Shut down ZeroNet", this.handleShutdownZeronetClick]);
  5848. if (this.menu_settings.visible) {
  5849. this.menu_settings.hide();
  5850. } else {
  5851. this.menu_settings.show();
  5852. }
  5853. return false;
  5854. };
  5855. Head.prototype.handleUpdateAllClick = function() {
  5856. var i, len, ref, results, site;
  5857. ref = Page.site_list.sites;
  5858. results = [];
  5859. for (i = 0, len = ref.length; i < len; i++) {
  5860. site = ref[i];
  5861. if (site.row.settings.serving) {
  5862. results.push(Page.cmd("siteUpdate", {
  5863. "address": site.row.address
  5864. }));
  5865. } else {
  5866. results.push(void 0);
  5867. }
  5868. }
  5869. return results;
  5870. };
  5871. Head.prototype.handleOrderbyClick = function(orderby) {
  5872. Page.settings.sites_orderby = orderby;
  5873. Page.site_list.reorder();
  5874. return Page.saveSettings();
  5875. };
  5876. Head.prototype.handleTorClick = function() {
  5877. return true;
  5878. };
  5879. Head.prototype.handleManageMutesClick = function() {
  5880. if (Page.server_info.rev < 1880) {
  5881. return Page.cmd("wrapperNotification", ["info", "You need ZeroNet 0.5.2 to use this feature."]);
  5882. }
  5883. Page.projector.replace($("#MuteList"), Page.mute_list.render);
  5884. return Page.mute_list.show();
  5885. };
  5886. Head.prototype.handleUpdateZeronetClick = function() {
  5887. Page.cmd("wrapperConfirm", ["Update to latest development version?", "Update ZeroNet " + Page.latest_version], (function(_this) {
  5888. return function() {
  5889. Page.cmd("wrapperNotification", ["info", "Updating to latest version...<br>Please restart ZeroNet manually if it does not come back in the next few minutes.", 8000]);
  5890. Page.cmd("serverUpdate");
  5891. return _this.log("Updating...");
  5892. };
  5893. })(this));
  5894. return false;
  5895. };
  5896. Head.prototype.handleShutdownZeronetClick = function() {
  5897. return Page.cmd("wrapperConfirm", ["Are you sure?", "Shut down ZeroNet"], (function(_this) {
  5898. return function() {
  5899. return Page.cmd("serverShutdown");
  5900. };
  5901. })(this));
  5902. };
  5903. Head.prototype.handleModeClick = function(e) {
  5904. if (Page.server_info.rev < 1700) {
  5905. Page.cmd("wrapperNotification", ["info", "This feature requires ZeroNet version 0.5.0"]);
  5906. } else {
  5907. Page.handleLinkClick(e);
  5908. }
  5909. return false;
  5910. };
  5911. Head.prototype.render = function() {
  5912. return h("div#Head", h("a.settings", {
  5913. href: "#Settings",
  5914. onmousedown: this.handleSettingsClick,
  5915. onclick: Page.returnFalse
  5916. }, ["\u22EE"]), this.menu_settings.render(), h("a.logo", {
  5917. href: "?Home"
  5918. }, [
  5919. h("img", {
  5920. src: 'img/logo.svg',
  5921. width: 40,
  5922. height: 40,
  5923. onerror: "this.src='img/logo.png'; this.onerror=null;"
  5924. }), h("span", ["Hello ZeroNet_"])
  5925. ]), h("div.modes", [
  5926. h("a.mode.sites", {
  5927. href: "?",
  5928. classes: {
  5929. active: Page.mode === "Sites"
  5930. },
  5931. onclick: Page.handleLinkClick
  5932. }, _("Sites")), h("a.mode.files", {
  5933. href: "?Files",
  5934. classes: {
  5935. active: Page.mode === "Files"
  5936. },
  5937. onclick: Page.handleLinkClick
  5938. }, _("Files")), h("a.mode.stats", {
  5939. href: "?Stats",
  5940. classes: {
  5941. active: Page.mode === "Stats"
  5942. },
  5943. onclick: Page.handleLinkClick
  5944. }, _("Stats"))
  5945. ]));
  5946. };
  5947. return Head;
  5948. })(Class);
  5949. window.Head = Head;
  5950. }).call(this);
  5951. /* ---- /1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/js/ZeroHello.coffee ---- */
  5952. (function() {
  5953. var ZeroHello,
  5954. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  5955. 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; },
  5956. hasProp = {}.hasOwnProperty;
  5957. window.h = maquette.h;
  5958. ZeroHello = (function(superClass) {
  5959. extend(ZeroHello, superClass);
  5960. function ZeroHello() {
  5961. this.reloadServerInfo = bind(this.reloadServerInfo, this);
  5962. this.reloadSiteInfo = bind(this.reloadSiteInfo, this);
  5963. this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
  5964. this.handleLinkClick = bind(this.handleLinkClick, this);
  5965. return ZeroHello.__super__.constructor.apply(this, arguments);
  5966. }
  5967. ZeroHello.prototype.init = function() {
  5968. this.params = {};
  5969. this.site_info = null;
  5970. this.server_info = null;
  5971. this.address = null;
  5972. this.on_site_info = new Promise();
  5973. this.on_settings = new Promise();
  5974. this.on_loaded = new Promise();
  5975. this.settings = null;
  5976. this.latest_version = "0.6.2";
  5977. this.latest_rev = 3351;
  5978. this.mode = "Sites";
  5979. this.change_timer = null;
  5980. return document.body.id = "Body" + this.mode;
  5981. };
  5982. ZeroHello.prototype.addRenderer = function(node, renderer) {
  5983. this.projector.replace(node, renderer);
  5984. return this.renderers.push(renderer);
  5985. };
  5986. ZeroHello.prototype.detachRenderers = function() {
  5987. var i, len, ref, renderer;
  5988. ref = this.renderers;
  5989. for (i = 0, len = ref.length; i < len; i++) {
  5990. renderer = ref[i];
  5991. this.projector.detach(renderer);
  5992. }
  5993. return this.renderers = [];
  5994. };
  5995. ZeroHello.prototype.setProjectorMode = function(mode) {
  5996. this.log("setProjectorMode", mode);
  5997. if (this.mode === mode) {
  5998. return;
  5999. }
  6000. this.detachRenderers();
  6001. if (mode === "Files") {
  6002. this.addRenderer($("#PageFiles"), this.page_files.render);
  6003. this.page_files.need_update = true;
  6004. } else if (mode === "Stats") {
  6005. this.addRenderer($("#PageStats"), this.page_stats.render);
  6006. this.page_stats.need_update = true;
  6007. } else {
  6008. mode = "Sites";
  6009. this.addRenderer($("#FeedList"), this.feed_list.render);
  6010. this.addRenderer($("#SiteList"), this.site_list.render);
  6011. }
  6012. this.mode = mode;
  6013. return setTimeout((function() {
  6014. document.body.id = "Body" + mode;
  6015. if (this.change_timer) {
  6016. clearInterval(this.change_timer);
  6017. }
  6018. document.body.classList.add("changing");
  6019. return this.change_timer = setTimeout((function() {
  6020. return document.body.classList.remove("changing");
  6021. }), 400);
  6022. }), 60);
  6023. };
  6024. ZeroHello.prototype.createProjector = function() {
  6025. var url;
  6026. this.projector = maquette.createProjector();
  6027. this.projectors = {};
  6028. this.renderers = [];
  6029. this.site_list = new SiteList();
  6030. this.feed_list = new FeedList();
  6031. this.page_files = new PageFiles();
  6032. this.page_stats = new PageStats();
  6033. this.head = new Head();
  6034. this.dashboard = new Dashboard();
  6035. this.mute_list = new MuteList();
  6036. this.trigger = new Trigger();
  6037. if (base.href.indexOf("?") === -1) {
  6038. this.route("");
  6039. } else {
  6040. url = base.href.replace(/.*?\?/, "");
  6041. this.route(url);
  6042. this.history_state["url"] = url;
  6043. }
  6044. this.loadSettings();
  6045. this.on_site_info.then((function(_this) {
  6046. return function() {
  6047. _this.projector.replace($("#Head"), _this.head.render);
  6048. _this.projector.replace($("#Dashboard"), _this.dashboard.render);
  6049. _this.projector.merge($("#Trigger"), _this.trigger.render);
  6050. return _this.setProjectorMode(_this.mode);
  6051. };
  6052. })(this));
  6053. return setInterval((function() {
  6054. return Page.projector.scheduleRender();
  6055. }), 60 * 1000);
  6056. };
  6057. ZeroHello.prototype.route = function(query) {
  6058. this.params = Text.parseQuery(query);
  6059. this.log("Route", this.params);
  6060. this.setProjectorMode(this.params.url);
  6061. if (this.mode === "Stats") {
  6062. this.page_stats.need_update = true;
  6063. } else if (this.mode === "Files") {
  6064. this.page_files.need_update = true;
  6065. }
  6066. return this.projector.scheduleRender();
  6067. };
  6068. ZeroHello.prototype.createUrl = function(key, val) {
  6069. var params, vals;
  6070. params = JSON.parse(JSON.stringify(this.params));
  6071. if (typeof key === "Object") {
  6072. vals = key;
  6073. for (key in keys) {
  6074. val = keys[key];
  6075. params[key] = val;
  6076. }
  6077. } else {
  6078. params[key] = val;
  6079. }
  6080. return "?" + Text.encodeQuery(params);
  6081. };
  6082. ZeroHello.prototype.setUrl = function(url, mode) {
  6083. if (mode == null) {
  6084. mode = "replace";
  6085. }
  6086. url = url.replace(/.*?\?/, "");
  6087. this.log("setUrl", this.history_state["url"], "->", url);
  6088. if (this.history_state["url"] === url) {
  6089. return false;
  6090. }
  6091. this.history_state["url"] = url;
  6092. if (mode === "replace") {
  6093. this.cmd("wrapperReplaceState", [this.history_state, "", url]);
  6094. } else {
  6095. this.cmd("wrapperPushState", [this.history_state, "", url]);
  6096. }
  6097. this.route(url);
  6098. return false;
  6099. };
  6100. ZeroHello.prototype.handleLinkClick = function(e) {
  6101. if (e.which === 2) {
  6102. return true;
  6103. } else {
  6104. this.log("save scrollTop", window.pageYOffset);
  6105. this.history_state["scrollTop"] = window.pageYOffset;
  6106. this.cmd("wrapperReplaceState", [this.history_state, null]);
  6107. window.scroll(window.pageXOffset, 0);
  6108. this.history_state["scrollTop"] = 0;
  6109. this.setUrl(e.currentTarget.search);
  6110. return false;
  6111. }
  6112. };
  6113. ZeroHello.prototype.loadSettings = function() {
  6114. return this.on_site_info.then((function(_this) {
  6115. return function() {
  6116. return _this.cmd("userGetSettings", [], function(res) {
  6117. var base1, base2;
  6118. if (!res || res.error) {
  6119. return _this.loadLocalStorage();
  6120. } else {
  6121. _this.settings = res;
  6122. if ((base1 = _this.settings).sites_orderby == null) {
  6123. base1.sites_orderby = "peers";
  6124. }
  6125. if ((base2 = _this.settings).favorite_sites == null) {
  6126. base2.favorite_sites = {};
  6127. }
  6128. return _this.on_settings.resolve(_this.settings);
  6129. }
  6130. });
  6131. };
  6132. })(this));
  6133. };
  6134. ZeroHello.prototype.loadLocalStorage = function() {
  6135. return this.cmd("wrapperGetLocalStorage", [], (function(_this) {
  6136. return function(settings) {
  6137. var base1, base2;
  6138. _this.settings = settings;
  6139. _this.log("Loaded localstorage");
  6140. if (_this.settings == null) {
  6141. _this.settings = {};
  6142. }
  6143. if ((base1 = _this.settings).sites_orderby == null) {
  6144. base1.sites_orderby = "peers";
  6145. }
  6146. if ((base2 = _this.settings).favorite_sites == null) {
  6147. base2.favorite_sites = {};
  6148. }
  6149. return _this.on_settings.resolve(_this.settings);
  6150. };
  6151. })(this));
  6152. };
  6153. ZeroHello.prototype.saveSettings = function(cb) {
  6154. if (this.settings) {
  6155. if (Page.server_info.rev > 2140) {
  6156. return this.cmd("userSetSettings", [this.settings], (function(_this) {
  6157. return function(res) {
  6158. if (cb) {
  6159. return cb(res);
  6160. }
  6161. };
  6162. })(this));
  6163. } else {
  6164. return this.cmd("wrapperSetLocalStorage", this.settings, (function(_this) {
  6165. return function(res) {
  6166. if (cb) {
  6167. return cb(res);
  6168. }
  6169. };
  6170. })(this));
  6171. }
  6172. }
  6173. };
  6174. ZeroHello.prototype.onOpenWebsocket = function(e) {
  6175. this.reloadSiteInfo();
  6176. return this.reloadServerInfo();
  6177. };
  6178. ZeroHello.prototype.reloadSiteInfo = function() {
  6179. return this.cmd("siteInfo", {}, (function(_this) {
  6180. return function(site_info) {
  6181. _this.address = site_info.address;
  6182. return _this.setSiteInfo(site_info);
  6183. };
  6184. })(this));
  6185. };
  6186. ZeroHello.prototype.reloadServerInfo = function() {
  6187. return this.cmd("serverInfo", {}, (function(_this) {
  6188. return function(server_info) {
  6189. return _this.setServerInfo(server_info);
  6190. };
  6191. })(this));
  6192. };
  6193. ZeroHello.prototype.onRequest = function(cmd, params) {
  6194. if (cmd === "setSiteInfo") {
  6195. return this.setSiteInfo(params);
  6196. } else if (cmd === "setServerInfo") {
  6197. return this.setServerInfo(params);
  6198. } else {
  6199. return this.log("Unknown command", params);
  6200. }
  6201. };
  6202. ZeroHello.prototype.setSiteInfo = function(site_info) {
  6203. if (site_info.address === this.address) {
  6204. this.site_info = site_info;
  6205. }
  6206. this.site_list.onSiteInfo(site_info);
  6207. this.feed_list.onSiteInfo(site_info);
  6208. this.page_files.onSiteInfo(site_info);
  6209. return this.on_site_info.resolve();
  6210. };
  6211. ZeroHello.prototype.setServerInfo = function(server_info) {
  6212. this.server_info = server_info;
  6213. return this.projector.scheduleRender();
  6214. };
  6215. ZeroHello.prototype.returnFalse = function() {
  6216. return false;
  6217. };
  6218. return ZeroHello;
  6219. })(ZeroFrame);
  6220. window.Page = new ZeroHello();
  6221. window.Page.createProjector();
  6222. }).call(this);