1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036 |
- "use strict";
- ( function( window ) {
- window.console && console.debug && console.debug( "loading vwf" );
- window.vwf = new function() {
- window.console && console.debug && console.debug( "creating vwf" );
-
-
-
-
-
-
-
- this.configuration = undefined;
-
-
-
-
-
- this.kutility = undefined;
-
-
-
-
-
- this.logger = undefined;
-
-
-
-
-
- this.modules = [];
-
-
-
-
-
-
- this.models = [];
-
-
-
-
-
-
- this.views = [];
-
-
-
-
-
- Object.defineProperty( this.models, "actual", {
- get: function() {
-
- var actual = this.map( function( model ) {
- return last( model );
- } );
-
- for ( var propertyName in this ) {
- if ( isNaN( Number( propertyName ) ) ) {
- actual[propertyName] = last( this[propertyName] );
- }
- }
-
- function last( model ) {
- while ( model.model ) model = model.model;
- return model;
- }
- return actual;
- }
- } );
-
-
-
-
-
- Object.defineProperty( this.views, "actual", {
- get: function() {
-
- var actual = this.map( function( model ) {
- return last( model );
- } );
-
- for ( var propertyName in this ) {
- if ( isNaN( Number( propertyName ) ) ) {
- actual[propertyName] = last( this[propertyName] );
- }
- }
-
- function last( model ) {
- while ( model.model ) model = model.model;
- return model;
- }
- return actual;
- }
- } );
-
-
-
-
-
-
- this.now = 0;
-
-
-
-
-
-
-
-
-
-
-
- this.sequence_ = undefined;
-
-
-
-
-
-
- this.client_ = undefined;
-
-
-
-
-
- this.moniker_ = undefined;
-
-
-
-
-
- this.tickable = {
-
-
- nodeIDs: [],
- };
-
-
-
-
- this.private = {};
-
-
-
-
-
-
-
- var components = this.private.components = {};
-
-
-
-
-
- var socket = this.private.socket = undefined;
-
-
-
-
-
-
-
-
- var vwf = this;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.loadConfiguration = function(/* [ componentURI|componentObject ] { modelInitializers }
- { viewInitializers } */) {
- var args = Array.prototype.slice.call( arguments );
- if ( typeof args[0] != "object" || ! ( args[0] instanceof Array ) ) {
- application = args.shift();
- }
- var userLibraries = args.shift() || {};
- var applicationConfig = {};
- var callback = args.shift();
- var requireConfig = {
- shim: {
-
- "vwf/model/aframe/addon/aframe-interpolation": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/extras/aframe-extras.loaders": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/addon/aframe-sun-sky": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/addon/aframe-gamepad-controls.min": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/addon/SkyShader": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/addon/BVHLoader": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/addon/TransformControls": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/addon/THREE.MeshLine": {
- deps: [ "vwf/model/aframe/aframe-master" ]
- },
- "vwf/model/aframe/addon/aframe-components": {
- deps: [ "vwf/model/aframe/aframe-master",
- "vwf/model/aframe/extras/aframe-extras.loaders",
- "vwf/model/aframe/addon/aframe-sun-sky",
- "vwf/model/aframe/addon/SkyShader",
- "vwf/model/aframe/addon/BVHLoader",
- "vwf/model/aframe/addon/TransformControls",
- "vwf/model/aframe/addon/THREE.MeshLine"
- ]
- }
-
- }
- };
-
- var requireArray = [
- { library: "domReady", active: true },
- { library: "vwf/configuration", active: true },
- { library: "vwf/kernel/model", active: true },
- { library: "vwf/model/javascript", active: true },
- { library: "vwf/model/object", active: true },
- { library: "vwf/model/stage/log", active: true },
- { library: "vwf/model/ohm", active: true },
- { library: "vwf/model/osc", active: true },
-
- { library: "vwf/model/aframe/addon/aframe-components",
- linkedLibraries: [ "vwf/model/aframe/addon/SkyShader" ],
- active: false
- },
- { library: "vwf/model/aframe",
- linkedLibraries: [ "vwf/model/aframe/aframe-master",
- "vwf/model/aframe/extras/aframe-extras.loaders",
- "vwf/model/aframe/addon/aframe-interpolation",
- "vwf/model/aframe/addon/aframe-sun-sky",
- "vwf/model/aframe/addon/aframe-components",
- "vwf/model/aframe/addon/SkyShader",
- "vwf/model/aframe/addon/aframe-gamepad-controls.min",
- "vwf/model/aframe/addon/BVHLoader",
- "vwf/model/aframe/addon/TransformControls",
- "vwf/model/aframe/addon/THREE.MeshLine"
-
- ],
- active: false
- },
- { library: "vwf/model/aframeComponent", active: true },
- { library: "vwf/kernel/view", active: true },
- { library: "vwf/view/document", active: true },
- { library: "vwf/view/editor-new", active: false },
- { library: "vwf/view/webrtc",
-
- active: true
- },
- { library: "vwf/view/ohm", active: true },
- { library: "vwf/view/osc", active: true },
-
- { library: "vwf/view/aframe", active: true },
- { library: "vwf/model/aframe/aframe-master", active: false },
- { library: "vwf/model/aframe/extras/aframe-extras.loaders", active: false },
- { library: "vwf/model/aframe/addon/aframe-interpolation", active: false },
- { library: "vwf/model/aframe/addon/aframe-sun-sky", active: false },
- { library: "vwf/model/aframe/addon/aframe-components", active: false },
- { library: "vwf/model/aframe/addon/BVHLoader", active: false },
- { library: "vwf/model/aframe/addon/TransformControls", active: false },
- { library: "vwf/model/aframe/addon/THREE.MeshLine", active: false },
-
-
- { library: "vwf/model/aframe/addon/SkyShader", active: false },
- { library: "vwf/model/aframe/addon/aframe-gamepad-controls.min", active: false },
- { library: "vwf/view/aframeComponent", active: true },
- { library: "vwf/kernel/utility", active: true },
- { library: "vwf/utility", active: true },
-
-
- { library: "vwf/admin", active: true }
-
- ];
- var initializers = {
- model: [
- { library: "vwf/model/javascript", active: true },
- { library: "vwf/model/ohm", active: true },
- { library: "vwf/model/osc", active: true },
-
- { library: "vwf/model/aframe", active: true },
- { library: "vwf/model/aframeComponent", active: true },
- { library: "vwf/model/object", active: true }
- ],
- view: [
- { library: "vwf/view/document", active: true },
- { library: "vwf/view/editor-new", active: false },
- { library: "vwf/view/ohm", active: true },
- { library: "vwf/view/osc", active: true },
-
- { library: "vwf/view/aframe", active: true },
- { library: "vwf/view/aframeComponent", active: true },
- { library: "vwf/view/webrtc", active: true}
-
- ]
- };
- mapLibraryName(requireArray);
- mapLibraryName(initializers["model"]);
- mapLibraryName(initializers["view"]);
- function mapLibraryName(array) {
- for(var i=0;i<array.length;i++) {
- array[array[i].library] = array[i];
- }
- }
- function getActiveLibraries(libraryList, includeParameters) {
- var activeLibraryList = [];
- for(var i=0; i<libraryList.length; i++) {
- if(libraryList[i].active) {
- if(includeParameters) {
- var activeLibrary = {};
- activeLibrary[libraryList[i].library] = libraryList[i].parameters;
- activeLibraryList.push(activeLibrary);
- }
- else {
- activeLibraryList.push(libraryList[i].library);
- }
- }
- }
- return activeLibraryList;
- }
- fetch('admin/config', {
- method: 'get'
- }).then(function(response) {
- return response.json();
- }).catch(function(err) {
-
- }).then(function(configLibraries) {
- if(configLibraries && typeof configLibraries == "object") {
- if (typeof configLibraries.configuration == "object") {
- applicationConfig = configLibraries.configuration;
- }
- Object.keys(configLibraries).forEach(function(libraryType) {
- if(libraryType == 'info' && configLibraries[libraryType]["title"])
- {
-
- document.querySelector('title').innerHTML = configLibraries[libraryType]["title"]
- }
- if(!userLibraries[libraryType]) {
- userLibraries[libraryType] = {};
- }
-
-
- Object.keys(configLibraries[libraryType]).forEach(function(libraryName) {
- var disabled = false;
- if(requireArray[libraryName] && requireArray[libraryName].disabledBy) {
- for(var i=0; i<requireArray[libraryName].disabledBy.length; i++) {
- Object.keys(userLibraries).forEach(function(userLibraryType) {
- Object.keys(userLibraries[userLibraryType]).forEach(function(userLibraryName) {
- if(requireArray[libraryName].disabledBy[i] == userLibraryName) {
- disabled = true;
- }
- })
- })
- }
- }
- if(!disabled) {
- if(userLibraries[libraryType][libraryName] == undefined) {
- userLibraries[libraryType][libraryName] = configLibraries[libraryType][libraryName];
- }
- else if(typeof userLibraries[libraryType][libraryName] == "object" && typeof configLibraries[libraryType][libraryName] == "object") {
- userLibraries[libraryType][libraryName] = Object.assign({}, configLibraries[libraryType][libraryName], userLibraries[libraryType][libraryName]);
-
- }
- }
- });
- });
- }
- }).then(function(){
- Object.keys(userLibraries).forEach(function(libraryType) {
- if(initializers[libraryType]) {
- Object.keys(userLibraries[libraryType]).forEach(function(libraryName) {
- if(requireArray[libraryName]) {
- requireArray[libraryName].active = true;
- initializers[libraryType][libraryName].active = true;
- if(userLibraries[libraryType][libraryName] && userLibraries[libraryType][libraryName] != "") {
- if(typeof initializers[libraryType][libraryName].parameters == "object") {
-
- initializers[libraryType][libraryName].parameters = Object.assign({}, initializers[libraryType][libraryName].parameters, userLibraries[libraryType][libraryName]);
-
-
- }
- else {
- initializers[libraryType][libraryName].parameters = userLibraries[libraryType][libraryName];
- }
- }
- if(requireArray[libraryName].linkedLibraries) {
- for(var i=0; i<requireArray[libraryName].linkedLibraries.length; i++) {
- requireArray[requireArray[libraryName].linkedLibraries[i]].active = true;
- }
- }
- }
- });
- }
- });
-
- if(Object.keys(userLibraries["model"]).length == 0 && Object.keys(userLibraries["view"]).length == 0) {
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- require( requireConfig, getActiveLibraries(requireArray, false), function( ready ) {
- ready( function() {
-
-
- require( "vwf/configuration" ).instance = require( "vwf/utility" ).merge(
- {}, require( "vwf/configuration" ).instance, applicationConfig );
-
-
-
- vwf.initialize(application, getActiveLibraries(initializers["model"], true), getActiveLibraries(initializers["view"], true), callback);
- } );
- } );
- })
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.initialize = function( /* [ componentURI|componentObject ] [ modelInitializers ]
- [ viewInitializers ] */ ) {
- var args = Array.prototype.slice.call( arguments );
- var application;
-
-
- this.configuration = require( "vwf/configuration" ).active;
-
- this.kutility = require( "vwf/kernel/utility" );
-
- this.logger = require( "logger" ).for( "vwf", this );
-
-
-
-
-
-
- if ( typeof args[0] != "object" || ! ( args[0] instanceof Array ) ) {
- application = args.shift();
- }
-
- var modelInitializers = args.shift() || [];
-
- var viewInitializers = args.shift() || [];
- var callback = args.shift();
- var compatibilityStatus = { compatible: true, errors: {} };
-
-
- this.models.kernel = require( "vwf/kernel/model" ).create( vwf );
-
- modelInitializers.forEach( function( modelInitializer ) {
-
-
- if ( modelInitializer ) {
-
- if ( typeof modelInitializer == "object" && modelInitializer != null ) {
- var modelName = Object.keys( modelInitializer )[0];
- var modelArguments = modelInitializer[modelName];
- } else {
- var modelName = modelInitializer;
- var modelArguments = undefined;
- }
- var model = require( modelName ).create(
- this.models.kernel,
- [ require( "vwf/model/stage/log" ) ],
- {},
- [].concat( modelArguments || [] )
- );
- if ( model ) {
- this.models.push( model );
- this.models[modelName] = model;
- if ( modelName == "vwf/model/javascript" ) {
- this.models.javascript = model;
- while ( this.models.javascript.model ) this.models.javascript = this.models.javascript.model;
- }
- if ( modelName == "vwf/model/object" ) {
- this.models.object = model;
- while ( this.models.object.model ) this.models.object = this.models.object.model;
- }
-
- if(model.model.compatibilityStatus) {
- if(!model.model.compatibilityStatus.compatible) {
- compatibilityStatus.compatible = false;
- Object.assign(compatibilityStatus.errors, model.model.compatibilityStatus.errors);
-
- }
- }
- }
- }
- }, this );
-
-
-
- this.views.kernel = require( "vwf/kernel/view" ).create( vwf );
-
- viewInitializers.forEach( function( viewInitializer ) {
-
-
- if ( viewInitializer ) {
-
- if ( typeof viewInitializer == "object" && viewInitializer != null ) {
- var viewName = Object.keys( viewInitializer )[0];
- var viewArguments = viewInitializer[viewName];
- } else {
- var viewName = viewInitializer;
- var viewArguments = undefined;
- }
- if ( ! viewName.match( "^vwf/view/" ) ) {
- var view = this.modules[viewName];
- if ( view ) {
- var instance = new view();
- instance.state = this.models.actual["vwf/model/"+viewName] && this.models.actual["vwf/model/"+viewName].state || {};
- view.apply( instance, [ vwf ].concat( viewArguments || [] ) );
- this.views.push( instance );
- this.views[viewName] = instance;
- if(view.compatibilityStatus) {
- if(!view.compatibilityStatus.compatible) {
- compatibilityStatus.compatible = false;
- Object.assign(compatibilityStatus.errors, view.compatibilityStatus.errors);
-
- }
- }
- }
- } else {
- var modelPeer = this.models.actual[ viewName.replace( "vwf/view/", "vwf/model/" ) ];
- var view = require( viewName ).create(
- this.views.kernel,
- [],
- modelPeer && modelPeer.state || {},
- [].concat( viewArguments || [] )
- );
- if ( view ) {
- this.views.push( view );
- this.views[viewName] = view;
- if(view.compatibilityStatus) {
- if(!view.compatibilityStatus.compatible) {
- compatibilityStatus.compatible = false;
- Object.assign(compatibilityStatus.errors, view.compatibilityStatus.errors);
-
- }
- }
- }
- }
- }
- }, this );
-
- if(!(function() { return !this })()) {
- compatibilityStatus.compatible = false;
- Object.assign(compatibilityStatus.errors, {"ES5": "This browser is not compatible. VWF requires ECMAScript 5."});
-
- }
-
-
-
-
-
-
- if(callback) {
- callback(compatibilityStatus);
- }
-
- this.ready( application );
- };
-
-
- this.ready = function( component_uri_or_json_or_object ) {
-
-
- try {
- var options = {
-
-
-
- query: 'pathname=' + window.location.pathname.slice( 1,
- window.location.pathname.lastIndexOf("/") ),
-
- secure: window.location.protocol === "https:",
-
-
-
- reconnection: false,
- transports: ['websocket']
- };
- if ( isSocketIO07() ) {
- socket = io.connect( window.location.protocol + "//" + window.location.host,options );
-
- } else {
- io.util.merge( options, {
-
-
- port: window.location.port ||
- ( window.location.protocol === "https:" ? 443 : 80 ),
-
- transports: [
- 'websocket',
- ],
-
-
-
- transportOptions: {
- "websocket": { timeout: 90000 },
- },
- } );
- socket = io.connect( undefined, options );
- }
- } catch ( e ) {
-
-
-
-
- this.dispatch();
- setInterval( function() {
- var fields = {
- time: vwf.now + 0.010,
- origin: "reflector",
- };
- queue.insert( fields, true );
- }, 10 );
- }
- if ( socket ) {
- socket.on( "connect", function() {
- vwf.logger.infox( "-socket", "connected" );
- if ( isSocketIO07() ) {
- vwf.moniker_ = this.id;
- } else {
- vwf.moniker_ = this.transport.sessionid;
- }
- } );
-
-
-
-
-
-
-
- socket.on( "message", function( message ) {
-
- try {
- if ( isSocketIO07() ) {
- var fields = message;
- } else {
- var fields = JSON.parse( message );
- }
- fields.time = Number( fields.time );
-
- fields.origin = "reflector";
-
-
- queue.insert( fields, !fields.action );
-
-
-
-
-
-
-
- } catch ( e ) {
- vwf.logger.warn( fields.action, fields.node, fields.member, fields.parameters,
- "exception performing action:", require( "vwf/utility" ).exceptionMessage( e ) );
- }
- } );
- socket.on( "disconnect", function() {
- vwf.logger.infox( "-socket", "disconnected" );
-
- window.location = window.location.href;
- } );
- socket.on( "error", function() {
-
- document.querySelector('body').innerHTML = "<div class='vwf-err'>WebSockets connections are currently being blocked. Please check your proxy server settings.</div>";
-
- } );
- if ( !isSocketIO07() ) {
-
- socket.connect();
- }
- } else if ( component_uri_or_json_or_object ) {
-
-
-
-
-
-
- this.createNode( component_uri_or_json_or_object, "application" );
- } else {
-
- }
- };
-
-
- this.plan = function( nodeID, actionName, memberName, parameters, when, callback_async /* ( result ) */ ) {
- this.logger.debuggx( "plan", nodeID, actionName, memberName,
- parameters && parameters.length, when, callback_async && "callback" );
- var time = when > 0 ?
- Math.max( this.now, when ) :
- this.now + ( -when );
- var fields = {
- time: time,
- node: nodeID,
- action: actionName,
- member: memberName,
- parameters: parameters,
- client: this.client_,
- origin: "future",
-
- };
- queue.insert( fields );
- this.logger.debugu();
- };
-
-
-
-
-
- this.send = function( nodeID, actionName, memberName, parameters, when, callback_async /* ( result ) */ ) {
- this.logger.debuggx( "send", nodeID, actionName, memberName,
- parameters && parameters.length, when, callback_async && "callback" );
- var time = when > 0 ?
- Math.max( this.now, when ) :
- this.now + ( -when );
-
- var fields = {
- time: time,
- node: nodeID,
- action: actionName,
- member: memberName,
- parameters: require( "vwf/utility" ).transform( parameters, require( "vwf/utility" ).transforms.transit ),
-
- };
- if ( socket ) {
-
-
- var message = JSON.stringify( fields );
- socket.send( message );
-
- } else {
-
-
- fields.client = this.moniker_;
- fields.origin = "reflector";
- queue.insert( fields );
-
- }
- this.logger.debugu();
- };
-
-
-
-
- this.respond = function( nodeID, actionName, memberName, parameters, result ) {
- this.logger.debuggx( "respond", nodeID, actionName, memberName,
- parameters && parameters.length, "..." );
-
- var fields = {
-
- time: this.now,
- node: nodeID,
- action: actionName,
- member: memberName,
- parameters: require( "vwf/utility" ).transform( parameters, require( "vwf/utility" ).transforms.transit ),
- result: require( "vwf/utility" ).transform( result, require( "vwf/utility" ).transforms.transit ),
- };
- if ( socket ) {
-
- var message = JSON.stringify( fields );
- socket.send( message );
- } else {
-
- }
- this.logger.debugu();
- };
-
-
-
-
- this.receive = function( nodeID, actionName, memberName, parameters, respond, origin ) {
-
-
-
-
-
-
-
-
- var args = [], result;
- if ( nodeID || nodeID === 0 ) args.push( nodeID );
- if ( memberName ) args.push( memberName );
- if ( parameters ) args = args.concat( parameters );
- if(actionName == 'createChild')
- {
- console.log("create child!");
-
-
-
-
-
-
-
-
-
-
- }
-
- if ( environment( actionName, parameters ) ) {
- require( "vwf/configuration" ).environment = environment( actionName, parameters );
- } else if ( origin !== "reflector" || ! nodeID || nodes.existing[ nodeID ] ) {
- result = this[ actionName ] && this[ actionName ].apply( this, args );
- } else {
- this.logger.debugx( "receive", "ignoring reflector action on non-existent node", nodeID );
- result = undefined;
- }
-
- respond && this.respond( nodeID, actionName, memberName, parameters, result );
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function environment( actionName, parameters ) {
- if ( actionName === "setState" && ! vwf.application() ) {
- var applicationState = parameters && parameters[0];
- if ( applicationState && Object.keys( applicationState ).length === 1 &&
- applicationState.configuration && Object.keys( applicationState.configuration ).length === 1 ) {
- return applicationState.configuration.environment;
- }
- }
- return undefined;
- }
- };
-
-
-
-
-
-
- this.dispatch = function() {
- var fields;
-
-
- while ( fields = queue.pull() ) {
-
- if ( this.now != fields.time ) {
- this.sequence_ = undefined;
- this.client_ = undefined;
- this.now = fields.time;
- this.tock();
- }
-
- if ( fields.action ) {
- this.sequence_ = fields.sequence;
- this.client_ = fields.client;
- this.receive( fields.node, fields.action, fields.member, fields.parameters, fields.respond, fields.origin );
- }
- else {
- this.tick();
- }
- }
-
-
- if ( queue.ready() && this.now != queue.time ) {
- this.sequence_ = undefined;
- this.client_ = undefined;
- this.now = queue.time;
- this.tock();
- }
-
- };
-
-
-
-
- this.log = function() {
- this.respond( undefined, "log", undefined, undefined, arguments );
- }
-
-
-
-
-
-
- this.tick = function() {
-
- this.models.forEach( function( model ) {
- model.ticking && model.ticking( this.now );
- }, this );
-
- this.views.forEach( function( view ) {
- view.ticked && view.ticked( this.now );
- }, this );
-
- this.tickable.nodeIDs.forEach( function( nodeID ) {
- this.callMethod( nodeID, "tick", [ this.now ] );
- }, this );
- };
-
-
-
-
-
-
- this.tock = function() {
-
- this.views.forEach( function( view ) {
- view.tocked && view.tocked( this.now );
- }, this );
- };
-
-
-
-
-
-
-
-
-
- this.setState = function( applicationState, callback_async /* () */ ) {
- this.logger.debuggx( "setState" );
-
- if ( applicationState.configuration ) {
- require( "vwf/configuration" ).instance = applicationState.configuration;
- }
-
- if ( applicationState.kernel ) {
- if ( applicationState.kernel.time !== undefined ) vwf.now = applicationState.kernel.time;
- }
-
- var nodes = applicationState.nodes || [];
- var annotations = applicationState.annotations || {};
- var nodeIndex = 0;
- async.forEachSeries( nodes, function( nodeComponent, each_callback_async /* ( err ) */ ) {
-
-
-
- var nodeAnnotation = nodes.length > 1 || applicationState.annotations ?
- annotations[nodeIndex] : "application";
- vwf.createNode( nodeComponent, nodeAnnotation, function( nodeID ) /* async */ {
- each_callback_async( undefined );
- } );
- nodeIndex++;
- }, function( err ) /* async */ {
-
-
- queue.filter( function( fields ) {
- if ( fields.origin === "reflector" && fields.sequence > vwf.sequence_ ) {
- return true;
- } else {
- vwf.logger.debugx( "setState", function() {
- return [ "removing", JSON.stringify( loggableFields( fields ) ), "from queue" ];
- } );
- }
- } );
-
- if ( applicationState.queue ) {
- queue.time = applicationState.queue.time;
- queue.insert( applicationState.queue.queue || [] );
- }
- callback_async && callback_async();
- } );
- this.logger.debugu();
- };
-
-
-
-
- this.getState = function( full, normalize ) {
- this.logger.debuggx( "getState", full, normalize );
-
- var applicationState = {
-
- configuration:
- require( "vwf/configuration" ).active,
-
- kernel: {
- time: vwf.now,
- },
-
- nodes: [
- this.getNode( "http://vwf.example.com/clients.vwf", full ),
- this.getNode( this.application(), full ),
- ],
-
- annotations: {
- 1: "application",
- },
-
- queue: {
- time: queue.time,
- queue: require( "vwf/utility" ).transform( queue.queue, queueTransitTransformation ),
- },
- };
-
- if ( normalize ) {
- applicationState = require( "vwf/utility" ).transform(
- applicationState, require( "vwf/utility" ).transforms.hash );
- }
-
- this.logger.debugu();
- return applicationState;
- };
-
-
-
-
- this.hashState = function() {
- this.logger.debuggx( "hashState" );
- var applicationState = this.getState( true, true );
-
- var hashn = this.hashNode( applicationState.nodes[0] );
-
- var hashq = "q" + Crypto.MD5( JSON.stringify( applicationState.queue ) ).toString().substring( 0, 16 );
-
- var hashk = "k" + Crypto.MD5( JSON.stringify( applicationState.kernel ) ).toString().substring( 0, 16 );
- this.logger.debugu();
-
- return hashn + ":" + hashq + ":" + hashk;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.createNode = function( nodeComponent, nodeAnnotation, baseURI, callback_async /* ( nodeID ) */ ) {
-
-
-
-
-
- if ( typeof nodeAnnotation == "function" || nodeAnnotation instanceof Function ) {
- callback_async = nodeAnnotation;
- baseURI = undefined;
- nodeAnnotation = undefined;
- } else if ( typeof baseURI == "function" || baseURI instanceof Function ) {
- callback_async = baseURI;
- baseURI = undefined;
- }
- this.logger.debuggx( "createNode", function() {
- return [ JSON.stringify( loggableComponent( nodeComponent ) ), nodeAnnotation ];
- } );
- var nodePatch;
- if ( componentIsDescriptor( nodeComponent ) && nodeComponent.patches ) {
- nodePatch = nodeComponent;
- nodeComponent = nodeComponent.patches;
- }
-
-
-
- var nodeURI, nodeDescriptor, nodeID;
- async.series( [
-
-
- function( series_callback_async /* ( err, results ) */ ) {
- if ( componentIsURI( nodeComponent ) ) {
-
-
- nodeURI = nodeComponent[0] == "/" ?
- nodeComponent : require( "vwf/utility" ).resolveURI( nodeComponent, baseURI );
-
-
- if ( ! components[nodeURI] ) {
- components[nodeURI] = [];
- loadComponent( nodeURI, undefined, function( nodeDescriptor ) /* async */ {
- nodeComponent = nodeDescriptor;
- series_callback_async( undefined, undefined );
- }, function( errorMessage ) {
- nodeComponent = undefined;
- series_callback_async( errorMessage, undefined );
- } );
-
-
- } else if ( components[nodeURI] instanceof Array ) {
-
- callback_async && components[nodeURI].push( callback_async );
-
-
- } else {
- if ( nodePatch ) {
- vwf.setNode( components[nodeURI], nodePatch, function( nodeID ) /* async */ {
- callback_async && callback_async( components[nodeURI] );
- } );
- } else {
- callback_async && callback_async( components[nodeURI] );
- }
- }
- } else {
- series_callback_async( undefined, undefined );
- }
- },
-
-
-
-
-
-
-
-
-
-
-
-
- function( series_callback_async /* ( err, results ) */ ) {
- if ( componentIsDescriptor( nodeComponent ) && nodeComponent.includes && componentIsURI( nodeComponent.includes ) ) {
- var prototypeURI = require( "vwf/utility" ).resolveURI( nodeComponent.includes, nodeURI || baseURI );
- loadComponent( prototypeURI, undefined, function( prototypeDescriptor ) /* async */ {
- prototypeDescriptor = resolvedDescriptor( prototypeDescriptor, prototypeURI );
- nodeComponent = mergeDescriptors( nodeComponent, prototypeDescriptor );
- series_callback_async( undefined, undefined );
- }, function( errorMessage ) {
- nodeComponent = undefined;
- series_callback_async( errorMessage, undefined );
- } );
- } else {
- series_callback_async( undefined, undefined );
- }
- },
-
-
- function( series_callback_async /* ( err, results ) */ ) {
- if ( componentIsDescriptor( nodeComponent ) ) {
- nodeDescriptor = nodeComponent;
-
- vwf.createChild( 0, nodeAnnotation, nodeDescriptor, nodeURI, function( nodeID ) /* async */ {
- nodeComponent = nodeID;
- series_callback_async( undefined, undefined );
- } );
-
- } else {
- series_callback_async( undefined, undefined );
- }
- },
-
- function( series_callback_async /* ( err, results ) */ ) {
- if ( componentIsID( nodeComponent ) || components[ nodeComponent ] instanceof Array ) {
- nodeID = nodeComponent;
- if ( nodePatch ) {
- vwf.setNode( nodeID, nodePatch, function( nodeID ) /* async */ {
- series_callback_async( undefined, undefined );
- } );
- } else {
- series_callback_async( undefined, undefined );
- }
- } else {
- series_callback_async( undefined, undefined );
- }
- },
- ], function( err, results ) /* async */ {
-
-
- if ( nodeURI ) {
- var callbacks_async = components[nodeURI];
- components[nodeURI] = nodeID;
- }
-
- callback_async && callback_async( nodeID );
-
- if ( nodeURI ) {
- callbacks_async.forEach( function( callback_async ) {
- callback_async && callback_async( nodeID );
- } );
- }
- } );
- this.logger.debugu();
- };
-
-
-
-
- this.deleteNode = function( nodeID ) {
- this.logger.debuggx( "deleteNode", nodeID );
-
-
- var parentID = this.parent( nodeID );
- if ( parentID !== 0 ) {
- var nodeIndex = this.children( parentID ).indexOf( nodeID );
- if ( nodeIndex < 0 ) {
- nodeIndex = undefined;
- }
- if ( this.models.kernel.enabled() ) {
- this.fireEvent( parentID, [ "children", "removed" ],
- [ nodeIndex, this.kutility.nodeReference( nodeID ) ] );
- }
- }
-
-
- Object.keys( components ).some( function( nodeURI ) {
- if ( components[nodeURI] == nodeID ) {
- delete components[nodeURI];
- return true;
- }
- } );
-
-
- this.models.forEach( function( model ) {
- model.deletingNode && model.deletingNode( nodeID );
- } );
-
- nodes.delete( nodeID );
-
-
- this.views.forEach( function( view ) {
- view.deletedNode && view.deletedNode( nodeID );
- } );
- this.logger.debugu();
- };
-
-
-
-
-
-
-
-
-
- this.setNode = function( nodeID, nodeComponent, callback_async /* ( nodeID ) */ ) {
- this.logger.debuggx( "setNode", function() {
- return [ nodeID, JSON.stringify( loggableComponent( nodeComponent ) ) ];
- } );
- var node = nodes.existing[nodeID];
-
- vwf.models.object.internals( nodeID, nodeComponent );
-
-
- vwf.models.kernel.disable();
-
-
-
-
- nodeComponent.properties && Object.keys( nodeComponent.properties ).forEach( function( propertyName ) {
- var propertyValue = nodeComponent.properties[ propertyName ];
-
-
-
-
- var creating = ! node.properties.has( propertyName );
-
-
- if ( valueHasAccessors( propertyValue ) && propertyValue.node ) {
- propertyValue = vwf.kutility.nodeReference( propertyValue.node );
- }
-
- if ( creating ) {
- vwf.createProperty( nodeID, propertyName, propertyValue );
- } else {
- vwf.setProperty( nodeID, propertyName, propertyValue );
- }
- } );
-
- nodeComponent.methods && Object.keys( nodeComponent.methods ).forEach( function( methodName ) {
- var methodHandler = nodeComponent.methods[ methodName ];
- var creating = ! node.methods.has( methodName );
-
- if ( creating ) {
- vwf.createMethod( nodeID, methodName, methodHandler.parameters, methodHandler.body );
- } else {
- vwf.setMethod( nodeID, methodName, methodHandler );
- }
- } );
-
- nodeComponent.events && Object.keys( nodeComponent.events ).forEach( function( eventName ) {
- var eventDescriptor = nodeComponent.events[ eventName ];
- var creating = ! node.events.has( eventName );
-
- if ( creating ) {
- vwf.createEvent( nodeID, eventName, eventDescriptor.parameters );
- vwf.setEvent( nodeID, eventName, eventDescriptor );
- } else {
- vwf.setEvent( nodeID, eventName, eventDescriptor );
- }
- } );
-
- vwf.models.kernel.enable();
- async.series( [
- function( series_callback_async /* ( err, results ) */ ) {
-
-
-
- async.forEach( Object.keys( nodeComponent.children || {} ), function( childName, each_callback_async /* ( err ) */ ) {
- var creating = ! nodeHasOwnChild.call( vwf, nodeID, childName );
- if ( creating ) {
- vwf.createChild( nodeID, childName, nodeComponent.children[childName], undefined, function( childID ) /* async */ {
- each_callback_async( undefined );
- } );
- } else {
- vwf.setNode( nodeComponent.children[childName].id || nodeComponent.children[childName].patches,
- nodeComponent.children[childName], function( childID ) /* async */ {
- each_callback_async( undefined );
- } );
- }
- }, function( err ) /* async */ {
- series_callback_async( err, undefined );
- } );
- },
- function( series_callback_async /* ( err, results ) */ ) {
-
-
-
-
-
- var scripts = nodeComponent.scripts ?
- [].concat( nodeComponent.scripts ) : [];
- var baseURI = vwf.uri( nodeID, true );
- async.map( scripts, function( script, map_callback_async /* ( err, result ) */ ) {
- if ( valueHasType( script ) ) {
- if ( script.source ) {
- loadScript( script.source, baseURI, function( scriptText ) /* async */ {
- map_callback_async( undefined, { text: scriptText, type: script.type } );
- }, function( errorMessage ) {
- map_callback_async( errorMessage, undefined );
- } );
- } else {
- map_callback_async( undefined, { text: script.text, type: script.type } );
- }
- } else {
- map_callback_async( undefined, { text: script, type: undefined } );
- }
- }, function( err, scripts ) /* async */ {
-
-
- vwf.models.kernel.disable();
-
- scripts.forEach( function( script ) {
- vwf.execute( nodeID, script.text, script.type );
- } );
-
- vwf.models.kernel.enable();
- series_callback_async( err, undefined );
- } );
- },
- ], function( err, results ) /* async */ {
- callback_async && callback_async( nodeID );
- } );
- this.logger.debugu();
- return nodeComponent;
- };
-
-
-
-
- this.getNode = function( nodeID, full, normalize ) {
- this.logger.debuggx( "getNode", nodeID, full );
- var node = nodes.existing[nodeID];
-
- var nodeComponent = {};
-
-
-
- var patches = this.models.object.patches( nodeID ),
- patched = false;
- if ( node.patchable ) {
- nodeComponent.patches = node.uri || nodeID;
- } else {
- nodeComponent.id = nodeID;
- }
-
-
- if ( full || ! node.patchable ) {
- var intrinsics = this.intrinsics( nodeID );
- var prototypeID = this.prototype( nodeID );
- if ( prototypeID === undefined ) {
- nodeComponent.extends = null;
- } else if ( prototypeID !== this.kutility.protoNodeURI ) {
- nodeComponent.extends = this.getNode( prototypeID );
- }
- nodeComponent.implements = this.behaviors( nodeID ).map( function( behaviorID ) {
- return this.getNode( behaviorID );
- }, this );
- nodeComponent.implements.length || delete nodeComponent.implements;
- if ( intrinsics.source !== undefined ) nodeComponent.source = intrinsics.source;
- if ( intrinsics.type !== undefined ) nodeComponent.type = intrinsics.type;
- }
-
- if ( full || ! node.patchable || patches.internals ) {
- var internals = this.models.object.internals( nodeID );
- nodeComponent.sequence = internals.sequence;
- nodeComponent.random = internals.random;
- }
-
-
- vwf.models.kernel.disable();
-
- if ( full || ! node.patchable ) {
-
- nodeComponent.properties = this.getProperties( nodeID );
- for ( var propertyName in nodeComponent.properties ) {
- var propertyValue = nodeComponent.properties[propertyName];
- if ( propertyValue === undefined ) {
- delete nodeComponent.properties[propertyName];
- } else if ( this.kutility.valueIsNodeReference( propertyValue ) ) {
-
- nodeComponent.properties[propertyName] = { node: propertyValue.id };
- }
- }
- } else if ( node.properties.changes ) {
-
- nodeComponent.properties = {};
- Object.keys( node.properties.changes ).forEach( function( propertyName ) {
- if ( node.properties.changes[ propertyName ] !== "removed" ) {
- var propertyValue = this.getProperty( nodeID, propertyName );
- if ( this.kutility.valueIsNodeReference( propertyValue ) ) {
-
- nodeComponent.properties[propertyName] = { node: propertyValue.id };
- } else {
- nodeComponent.properties[propertyName] = propertyValue;
- }
- }
- }, this );
- }
- if ( Object.keys( nodeComponent.properties ).length == 0 ) {
- delete nodeComponent.properties;
- } else {
- patched = true;
- }
-
- if ( full || ! node.patchable ) {
- Object.keys( node.methods.existing ).forEach( function( methodName ) {
- nodeComponent.methods = nodeComponent.methods || {};
- nodeComponent.methods[ methodName ] = this.getMethod( nodeID, methodName );
- patched = true;
- }, this );
- } else if ( node.methods.changes ) {
- Object.keys( node.methods.changes ).forEach( function( methodName ) {
- if ( node.methods.changes[ methodName ] !== "removed" ) {
- nodeComponent.methods = nodeComponent.methods || {};
- nodeComponent.methods[ methodName ] = this.getMethod( nodeID, methodName );
- patched = true;
- }
- }, this );
- }
-
- var events = full || ! node.patchable ?
- node.events.existing : node.events.changes;
- if ( events ) {
- Object.keys( events ).forEach( function( eventName ) {
- nodeComponent.events = nodeComponent.events || {};
- nodeComponent.events[ eventName ] = this.getEvent( nodeID, eventName );
- patched = true;
- }, this );
- }
-
- vwf.models.kernel.enable();
-
- nodeComponent.children = {};
- this.children( nodeID ).forEach( function( childID ) {
- nodeComponent.children[ this.name( childID ) ] = this.getNode( childID, full );
- }, this );
- for ( var childName in nodeComponent.children ) {
- if ( nodeComponent.children[childName] === undefined ) {
- delete nodeComponent.children[childName];
- }
- }
- if ( Object.keys( nodeComponent.children ).length == 0 ) {
- delete nodeComponent.children;
- } else {
- patched = true;
- }
-
-
-
- if ( normalize ) {
- nodeComponent = require( "vwf/utility" ).transform(
- nodeComponent, require( "vwf/utility" ).transforms.hash );
- }
- this.logger.debugu();
-
-
- if ( full || ! node.patchable || patched ) {
- return nodeComponent;
- } else if ( node.uri ) {
- return node.uri;
- } else {
- return undefined;
- }
- };
-
-
-
-
- this.hashNode = function( nodeID ) {
- this.logger.debuggx( "hashNode", typeof nodeID == "object" ? nodeID.id : nodeID );
- var nodeComponent = typeof nodeID == "object" ? nodeID : this.getNode( nodeID, true, true );
-
- var internal = { id: nodeComponent.id, source: nodeComponent.source, type: nodeComponent.type };
- internal.source === undefined && delete internal.source;
- internal.type === undefined && delete internal.type;
- var hashi = "i" + Crypto.MD5( JSON.stringify( internal ) ).toString().substring( 0, 16 );
-
- var properties = nodeComponent.properties || {};
- var hashp = Object.keys( properties ).length ?
- "p" + Crypto.MD5( JSON.stringify( properties ) ).toString().substring( 0, 16 ) : undefined;
-
- var children = nodeComponent.children || {};
- var hashc = Object.keys( children ).length ?
- "c" + Crypto.MD5( JSON.stringify( children ) ).toString().substring( 0, 16 ) : undefined;
- this.logger.debugu();
-
- return hashi + ( hashp ? "." + hashp : "" ) + ( hashc ? "/" + hashc : "" );
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.createChild = function( nodeID, childName, childComponent, childURI, callback_async /* ( childID ) */ ) {
- this.logger.debuggx( "createChild", function() {
- return [ nodeID, childName, JSON.stringify( loggableComponent( childComponent ) ), childURI ];
- } );
- childComponent = normalizedComponent( childComponent );
- var child, childID, childIndex, childPrototypeID, childBehaviorIDs = [], deferredInitializations = {};
- var resolvedSource;
-
- var replicating = !! childComponent.id;
-
-
-
-
-
-
- if ( childComponent.id ) {
- childID = childComponent.id;
- childIndex = this.children( nodeID ).length;
- } else if ( nodeID === 0 ) {
- childID = childURI ||
- Crypto.MD5( JSON.stringify( childComponent ) ).toString();
- childIndex = childURI;
- } else {
- childID = nodeID + ":" + this.sequence( nodeID ) +
- ( this.configuration["randomize-ids"] ? "-" + ( "0" + Math.floor( this.random( nodeID ) * 100 ) ).slice( -2 ) : "" ) +
- ( this.configuration["humanize-ids"] ? "-" + childName.replace( /[^0-9A-Za-z_-]+/g, "-" ) : "" );
- childIndex = this.children( nodeID ).length;
- }
-
- child = nodes.create( childID, childPrototypeID, childBehaviorIDs, childURI, childName, nodeID );
-
-
-
-
-
- vwf.models.object.creatingNode( nodeID, childID, childPrototypeID, childBehaviorIDs,
- childComponent.source, childComponent.type, childIndex, childName );
-
- var baseURI = vwf.uri( childID, true );
-
- async.series( [
- function( series_callback_async /* ( err, results ) */ ) {
-
-
-
-
-
-
-
- if ( componentIsDescriptor( childComponent ) && childComponent.includes && componentIsURI( childComponent.includes ) ) {
- var prototypeURI = require( "vwf/utility" ).resolveURI( childComponent.includes, baseURI );
- var sync = true;
- loadComponent( prototypeURI, undefined, function( prototypeDescriptor ) /* async */ {
-
- prototypeDescriptor = resolvedDescriptor( prototypeDescriptor, prototypeURI );
-
- childComponent = mergeDescriptors( childComponent, prototypeDescriptor );
- if ( sync ) {
- queue.suspend( "before beginning " + childID );
- async.nextTick( function() {
- series_callback_async( undefined, undefined );
- queue.resume( "after beginning " + childID );
- } );
- } else {
- series_callback_async( undefined, undefined );
- }
- }, function( errorMessage ) {
- childComponent = undefined;
- series_callback_async( errorMessage, undefined );
- } );
- sync = false;
- } else {
- queue.suspend( "before beginning " + childID );
- async.nextTick( function() {
- series_callback_async( undefined, undefined );
- queue.resume( "after beginning " + childID );
- } );
- }
- },
- function( series_callback_async /* ( err, results ) */ ) {
-
-
- async.parallel( [
- function( parallel_callback_async /* ( err, results ) */ ) {
-
- if ( childComponent.extends !== null ) {
- var prototypeComponent = childComponent.extends || vwf.kutility.protoNodeURI;
- vwf.createNode( prototypeComponent, undefined, baseURI, function( prototypeID ) /* async */ {
- childPrototypeID = prototypeID;
- if ( ! childComponent.source ) {
- var prototype_intrinsics = vwf.intrinsics( prototypeID );
- if ( prototype_intrinsics.source ) {
- var prototype_uri = vwf.uri( prototypeID );
- var prototype_properties = vwf.getProperties( prototypeID );
- childComponent.source = require( "vwf/utility" ).resolveURI( prototype_intrinsics.source, prototype_uri );
- childComponent.type = prototype_intrinsics.type;
- childComponent.properties = childComponent.properties || {};
- Object.keys( prototype_properties ).forEach( function( prototype_property_name ) {
- if ( childComponent.properties[prototype_property_name] === undefined && prototype_property_name != "transform" ) {
- childComponent.properties[prototype_property_name] = prototype_properties[prototype_property_name];
- }
- } );
- }
- }
- parallel_callback_async( undefined, undefined );
- } );
- } else {
- childPrototypeID = undefined;
- parallel_callback_async( undefined, undefined );
- }
- },
- function( parallel_callback_async /* ( err, results ) */ ) {
-
- var behaviorComponents = childComponent.implements ?
- [].concat( childComponent.implements ) : [];
- async.map( behaviorComponents, function( behaviorComponent, map_callback_async /* ( err, result ) */ ) {
- vwf.createNode( behaviorComponent, undefined, baseURI, function( behaviorID ) /* async */ {
- map_callback_async( undefined, behaviorID );
- } );
- }, function( err, behaviorIDs ) /* async */ {
- childBehaviorIDs = behaviorIDs;
- parallel_callback_async( err, undefined );
- } );
- },
- ], function( err, results ) /* async */ {
- series_callback_async( err, undefined );
- } );
- },
- function( series_callback_async /* ( err, results ) */ ) {
-
- child = nodes.create( childID, childPrototypeID, childBehaviorIDs, childURI, childName, nodeID );
-
- if ( childID === vwf.kutility.protoNodeURI ) {
- child.events.create( namespaceEncodedName( [ "properties", "created" ] ) );
- child.events.create( namespaceEncodedName( [ "properties", "initialized" ] ) );
- child.events.create( namespaceEncodedName( [ "properties", "deleted" ] ) );
- child.events.create( namespaceEncodedName( [ "methods", "created" ] ) );
- child.events.create( namespaceEncodedName( [ "methods", "deleted" ] ) );
- child.events.create( namespaceEncodedName( [ "events", "created" ] ) );
- child.events.create( namespaceEncodedName( [ "events", "deleted" ] ) );
- child.events.create( namespaceEncodedName( [ "children", "added" ] ) );
- child.events.create( namespaceEncodedName( [ "children", "removed" ] ) );
- }
-
-
-
- vwf.models.object.creatingNode( nodeID, childID, childPrototypeID, childBehaviorIDs,
- childComponent.source, childComponent.type, childIndex, childName );
-
- resolvedSource = childComponent.source &&
- require( "vwf/utility" ).resolveURI( childComponent.source, baseURI );
-
-
- async.forEachSeries( vwf.models, function( model, each_callback_async /* ( err ) */ ) {
- var driver_ready = true;
- var timeoutID;
-
- model.creatingNode && model.creatingNode( nodeID, childID, childPrototypeID, childBehaviorIDs,
- resolvedSource, childComponent.type, childIndex, childName, function( ready ) /* async */ {
- if ( driver_ready && ! ready ) {
- suspend();
- } else if ( ! driver_ready && ready ) {
- resume();
- }
- function suspend() {
- queue.suspend( "while loading " + childComponent.source + " for " + childID + " in creatingNode" );
- timeoutID = window.setTimeout( function() { resume( "timeout loading " + childComponent.source ) }, vwf.configuration[ "load-timeout" ] * 1000 );
- driver_ready = false;
- }
- function resume( err ) {
- window.clearTimeout( timeoutID );
- driver_ready = true;
- err && vwf.logger.warnx( "createChild", nodeID, childName + ":", err );
- each_callback_async( err );
- queue.resume( "after loading " + childComponent.source + " for " + childID + " in creatingNode" );
- }
- } );
-
- driver_ready && each_callback_async( undefined );
- }, function( err ) /* async */ {
- series_callback_async( err, undefined );
- } );
- },
- function( series_callback_async /* ( err, results ) */ ) {
-
-
- async.forEach( vwf.views, function( view, each_callback_async /* ( err ) */ ) {
- var driver_ready = true;
- var timeoutID;
- view.createdNode && view.createdNode( nodeID, childID, childPrototypeID, childBehaviorIDs,
- resolvedSource, childComponent.type, childIndex, childName, function( ready ) /* async */ {
- if ( driver_ready && ! ready ) {
- suspend();
- } else if ( ! driver_ready && ready ) {
- resume();
- }
- function suspend() {
- queue.suspend( "while loading " + childComponent.source + " for " + childID + " in createdNode" );
- timeoutID = window.setTimeout( function() { resume( "timeout loading " + childComponent.source ) }, vwf.configuration[ "load-timeout" ] * 1000 );
- driver_ready = false;
- }
- function resume( err ) {
- window.clearTimeout( timeoutID );
- driver_ready = true;
- err && vwf.logger.warnx( "createChild", nodeID, childName + ":", err );
- each_callback_async( err );
- queue.resume( "after loading " + childComponent.source + " for " + childID + " in createdNode" );
- }
- } );
- driver_ready && each_callback_async( undefined );
- }, function( err ) /* async */ {
- series_callback_async( err, undefined );
- } );
- },
- function( series_callback_async /* ( err, results ) */ ) {
-
- vwf.models.object.internals( childID, childComponent );
-
-
- replicating && vwf.models.kernel.disable();
-
-
-
- childComponent.properties && Object.keys( childComponent.properties ).forEach( function( propertyName ) {
- var propertyValue = childComponent.properties[ propertyName ];
- var value = propertyValue, get, set, create;
- if ( valueHasAccessors( propertyValue ) ) {
- value = propertyValue.node ? vwf.kutility.nodeReference( propertyValue.node ) : propertyValue.value;
- get = propertyValue.get;
- set = propertyValue.set;
- create = propertyValue.create;
- }
- // Is the property specification directing us to create a new property, or
- // initialize a property already defined on a prototype?
- // Create a new property if an explicit getter or setter are provided or if
- // the property is not defined on a prototype. Initialize the property when
- // the property is already defined on a prototype and no explicit getter or
- // setter are provided.
- var creating = create || // explicit create directive, or
- get !== undefined || set !== undefined || // explicit accessor, or
- ! child.properties.has( propertyName ); // not defined on prototype
- // Are we assigning the value here, or deferring assignment until the node
- // is constructed because setters will run?
- var assigning = value === undefined || // no value, or
- set === undefined && ( creating || ! nodePropertyHasSetter.call( vwf, childID, propertyName ) ) || // no setter, or
- replicating; // replicating previously-saved state (setters never run during replication)
- if ( ! assigning ) {
- deferredInitializations[propertyName] = value;
- value = undefined;
- }
-
- if ( creating ) {
- vwf.createProperty( childID, propertyName, value, get, set );
- } else {
- vwf.setProperty( childID, propertyName, value );
- }
- } );
- childComponent.methods && Object.keys( childComponent.methods ).forEach( function( methodName ) {
- var methodValue = childComponent.methods[ methodName ];
- if ( valueHasBody( methodValue ) ) {
- vwf.createMethod( childID, methodName, methodValue.parameters, methodValue.body );
- } else {
- vwf.createMethod( childID, methodName, undefined, methodValue );
- }
- } );
- childComponent.events && Object.keys( childComponent.events ).forEach( function( eventName ) {
- var eventValue = childComponent.events[ eventName ];
- if ( valueHasBody( eventValue ) ) {
- vwf.createEvent( childID, eventName, eventValue.parameters );
- vwf.setEvent( childID, eventName, eventValue );
- } else {
- vwf.createEvent( childID, eventName, undefined );
- }
- } );
-
- replicating && vwf.models.kernel.enable();
-
-
-
- async.forEach( Object.keys( childComponent.children || {} ), function( childName, each_callback_async /* ( err ) */ ) {
- var childValue = childComponent.children[childName];
- vwf.createChild( childID, childName, childValue, undefined, function( childID ) /* async */ {
- each_callback_async( undefined );
- } );
- }, function( err ) /* async */ {
- series_callback_async( err, undefined );
- } );
- },
- function( series_callback_async /* ( err, results ) */ ) {
-
-
-
-
-
- var scripts = childComponent.scripts ?
- [].concat( childComponent.scripts ) : [];
- async.map( scripts, function( script, map_callback_async /* ( err, result ) */ ) {
- if ( valueHasType( script ) ) {
- if ( script.source ) {
- loadScript( script.source, baseURI, function( scriptText ) /* async */ {
- map_callback_async( undefined, { text: scriptText, type: script.type } );
- }, function( errorMessage ) {
- map_callback_async( errorMessage, undefined );
- } );
- } else {
- map_callback_async( undefined, { text: script.text, type: script.type } );
- }
- } else {
- map_callback_async( undefined, { text: script, type: undefined } );
- }
- }, function( err, scripts ) /* async */ {
-
-
- vwf.models.kernel.capturingAsyncs( function() {
-
-
- replicating && vwf.models.kernel.disable();
-
- scripts.forEach( function( script ) {
- vwf.execute( childID, script.text, script.type );
- } );
-
-
- Object.keys( deferredInitializations ).forEach( function( propertyName ) {
- vwf.setProperty( childID, propertyName, deferredInitializations[propertyName] );
- } );
-
- if ( vwf.execute( childID, "Boolean( this.tick )" ) ) {
- vwf.tickable.nodeIDs.push( childID );
- }
-
- replicating && vwf.models.kernel.enable();
- }, function() {
-
-
-
-
-
-
-
- async.forEachSeries( vwf.prototypes( childID, true ).reverse().concat( childID ),
- function( childInitializingNodeID, each_callback_async /* err */ ) {
-
- vwf.models.kernel.capturingAsyncs( function() {
- vwf.models.forEach( function( model ) {
-
-
- replicating && vwf.models.kernel.disable();
-
-
-
-
-
-
-
-
-
-
-
- if ( childInitializingNodeID !== childID ) {
- model.initializingNodeFromPrototype &&
- model.initializingNodeFromPrototype( nodeID, childID, childInitializingNodeID );
- } else {
- model.initializingNode &&
- model.initializingNode( nodeID, childID, childPrototypeID, childBehaviorIDs,
- resolvedSource, childComponent.type, childIndex, childName );
- }
-
- replicating && vwf.models.kernel.enable();
- } );
- }, function() {
- each_callback_async( undefined );
- } );
- }, function( err ) /* async */ {
-
- vwf.views.forEach( function( view ) {
- view.initializedNode && view.initializedNode( nodeID, childID, childPrototypeID, childBehaviorIDs,
- resolvedSource, childComponent.type, childIndex, childName );
- } );
-
- nodes.initialize( childID );
-
- if ( ! replicating && nodeID !== 0 ) {
- vwf.fireEvent( nodeID, [ "children", "added" ],
- [ childIndex, vwf.kutility.nodeReference( childID ) ] );
- }
-
- if ( childID === vwf.application() ) {
- var spinner = document.getElementById( "vwf-loading-spinner" );
- spinner && spinner.classList.remove( "pace-active" );
- }
- series_callback_async( err, undefined );
- } );
- } );
- } );
- },
- ], function( err, results ) /* async */ {
-
-
-
-
-
- if ( callback_async ) {
- queue.suspend( "before completing " + childID );
- async.nextTick( function() {
- callback_async( childID );
- queue.resume( "after completing " + childID );
- } );
- }
- } );
- this.logger.debugu();
- };
-
-
-
-
- this.deleteChild = function( nodeID, childName ) {
- var childID = this.children( nodeID ).filter( function( childID ) {
- return this.name( childID ) === childName;
- }, this )[0];
- if ( childID !== undefined ) {
- return this.deleteNode( childID );
- }
- }
-
-
-
-
- this.addChild = function( nodeID, childID, childName ) {
- this.logger.debuggx( "addChild", nodeID, childID, childName );
-
-
- this.models.forEach( function( model ) {
- model.addingChild && model.addingChild( nodeID, childID, childName );
- } );
-
-
- this.views.forEach( function( view ) {
- view.addedChild && view.addedChild( nodeID, childID, childName );
- } );
- this.logger.debugu();
- };
-
-
-
-
- this.removeChild = function( nodeID, childID ) {
- this.logger.debuggx( "removeChild", nodeID, childID );
-
-
- this.models.forEach( function( model ) {
- model.removingChild && model.removingChild( nodeID, childID );
- } );
-
-
- this.views.forEach( function( view ) {
- view.removedChild && view.removedChild( nodeID, childID );
- } );
- this.logger.debugu();
- };
-
-
-
-
-
-
- this.setProperties = function( nodeID, properties ) {
- this.logger.debuggx( "setProperties", nodeID, properties );
- var node = nodes.existing[nodeID];
- var entrants = this.setProperty.entrants;
-
- properties = this.models.reduceRight( function( intermediate_properties, model, index ) {
- var model_properties = {};
- if ( model.settingProperties ) {
- model_properties = model.settingProperties( nodeID, properties );
- } else if ( model.settingProperty ) {
- Object.keys( node.properties.existing ).forEach( function( propertyName ) {
- if ( properties[propertyName] !== undefined ) {
- var reentry = entrants[nodeID+'-'+propertyName] = { index: index };
- model_properties[propertyName] =
- model.settingProperty( nodeID, propertyName, properties[propertyName] );
- if ( vwf.models.kernel.blocked() ) {
- model_properties[propertyName] = undefined;
- }
- delete entrants[nodeID+'-'+propertyName];
- }
- } );
- }
- Object.keys( node.properties.existing ).forEach( function( propertyName ) {
- if ( model_properties[propertyName] !== undefined ) {
- intermediate_properties[propertyName] = model_properties[propertyName];
- } else if ( intermediate_properties[propertyName] === undefined ) {
- intermediate_properties[propertyName] = undefined;
- }
- } );
- return intermediate_properties;
- }, {} );
-
- if ( node.initialized && node.patchable ) {
- Object.keys( properties ).forEach( function( propertyName ) {
- node.properties.change( propertyName );
- } );
- }
-
- this.views.forEach( function( view ) {
- if ( view.satProperties ) {
- view.satProperties( nodeID, properties );
- } else if ( view.satProperty ) {
- for ( var propertyName in properties ) {
- view.satProperty( nodeID, propertyName, properties[propertyName] );
- }
- }
- } );
- this.logger.debugu();
- return properties;
- };
-
-
-
-
-
-
- this.getProperties = function( nodeID ) {
- this.logger.debuggx( "getProperties", nodeID );
- var node = nodes.existing[nodeID];
- var entrants = this.getProperty.entrants;
-
- var properties = this.models.reduceRight( function( intermediate_properties, model, index ) {
- var model_properties = {};
- if ( model.gettingProperties ) {
- model_properties = model.gettingProperties( nodeID, properties );
- } else if ( model.gettingProperty ) {
- Object.keys( node.properties.existing ).forEach( function( propertyName ) {
- var reentry = entrants[nodeID+'-'+propertyName] = { index: index };
- model_properties[propertyName] =
- model.gettingProperty( nodeID, propertyName, intermediate_properties[propertyName] );
- if ( vwf.models.kernel.blocked() ) {
- model_properties[propertyName] = undefined;
- }
- delete entrants[nodeID+'-'+propertyName];
- } );
- }
- Object.keys( node.properties.existing ).forEach( function( propertyName ) {
- if ( model_properties[propertyName] !== undefined ) {
- intermediate_properties[propertyName] = model_properties[propertyName];
- } else if ( intermediate_properties[propertyName] === undefined ) {
- intermediate_properties[propertyName] = undefined;
- }
- } );
- return intermediate_properties;
- }, {} );
-
- this.views.forEach( function( view ) {
- if ( view.gotProperties ) {
- view.gotProperties( nodeID, properties );
- } else if ( view.gotProperty ) {
- for ( var propertyName in properties ) {
- view.gotProperty( nodeID, propertyName, properties[propertyName] );
- }
- }
- } );
- this.logger.debugu();
- return properties;
- };
-
-
-
-
-
-
- this.createProperty = function( nodeID, propertyName, propertyValue, propertyGet, propertySet ) {
- this.logger.debuggx( "createProperty", function() {
- return [ nodeID, propertyName, JSON.stringify( loggableValue( propertyValue ) ),
- loggableScript( propertyGet ), loggableScript( propertySet ) ];
- } );
- var node = nodes.existing[nodeID];
-
- node.properties.create( propertyName, node.initialized && node.patchable );
-
-
- this.models.forEach( function( model ) {
- model.creatingProperty && model.creatingProperty( nodeID, propertyName, propertyValue,
- propertyGet, propertySet );
- } );
-
-
- this.views.forEach( function( view ) {
- view.createdProperty && view.createdProperty( nodeID, propertyName, propertyValue,
- propertyGet, propertySet );
- } );
-
- if ( this.models.kernel.enabled() ) {
- this.fireEvent( nodeID, [ "properties", "created" ], [ propertyName ] );
- }
- this.logger.debugu();
- return propertyValue;
- };
-
-
-
-
-
-
- this.setProperty = function( nodeID, propertyName, propertyValue ) {
- this.logger.debuggx( "setProperty", function() {
- return [ nodeID, propertyName, JSON.stringify( loggableValue( propertyValue ) ) ];
- } );
- var node = nodes.existing[nodeID];
-
-
-
- var entrants = this.setProperty.entrants;
- var entry = entrants[nodeID+'-'+propertyName] || {};
- var reentry = entrants[nodeID+'-'+propertyName] = {};
-
-
-
- if ( ! node.properties.has( propertyName ) || entry.creating ) {
- reentry.creating = true;
- var settingPropertyEtc = "creatingProperty";
- var satPropertyEtc = "createdProperty";
- node.properties.create( propertyName, node.initialized && node.patchable );
- } else if ( ! node.properties.hasOwn( propertyName ) || entry.initializing ) {
- reentry.initializing = true;
- var settingPropertyEtc = "initializingProperty";
- var satPropertyEtc = "initializedProperty";
- node.properties.create( propertyName, node.initialized && node.patchable );
- } else {
- var settingPropertyEtc = "settingProperty";
- var satPropertyEtc = "satProperty";
- }
-
-
- var outermost = entrants.assignments === undefined;
- if ( outermost ) {
- entrants.assignments = 0;
- }
-
-
-
-
-
- var reentered = ( entry.index !== undefined );
-
-
- var delegated = false, assigned = false;
-
-
-
- this.models.some( function( model, index ) {
-
-
-
- if ( ( ! reentered || index > entry.index ) && ! reentry.completed ) {
-
-
- reentry.index = index;
-
-
-
- var assignments = entrants.assignments;
-
- if ( ! delegated && ! assigned ) {
- var value = model[settingPropertyEtc] && model[settingPropertyEtc]( nodeID, propertyName, propertyValue );
- } else {
- model[settingPropertyEtc] && model[settingPropertyEtc]( nodeID, propertyName, undefined );
- }
-
-
-
- if ( this.models.kernel.blocked() ) {
- value = undefined;
- }
-
- if ( entrants.assignments !== assignments ) {
- delegated = true;
- }
-
- else if ( value !== undefined ) {
- entrants.assignments++;
- assigned = true;
- }
-
-
-
- if ( value !== undefined ) {
- propertyValue = value;
- }
-
-
-
- return settingPropertyEtc == "settingProperty" && ( delegated || assigned );
- }
- }, this );
-
- if ( assigned && node.initialized && node.patchable ) {
- node.properties.change( propertyName );
- }
-
-
-
-
-
-
- if ( assigned ) {
- this.views.forEach( function( view ) {
- view[satPropertyEtc] && view[satPropertyEtc]( nodeID, propertyName, propertyValue );
- } );
- }
- if ( reentered ) {
-
-
- entrants[nodeID+'-'+propertyName] = entry;
- entry.completed = true;
- } else {
-
-
- delete entrants[nodeID+'-'+propertyName];
-
-
- if ( this.models.kernel.enabled() ) {
- if ( settingPropertyEtc === "creatingProperty" ) {
- this.fireEvent( nodeID, [ "properties", "created" ], [ propertyName ] );
- } else if ( settingPropertyEtc === "initializingProperty" ) {
- this.fireEvent( nodeID, [ "properties", "initialized" ], [ propertyName ] );
- }
- }
- }
-
- if ( outermost ) {
- delete entrants.assignments;
- }
- this.logger.debugu();
- return propertyValue;
- };
- this.setProperty.entrants = {};
-
-
-
-
-
-
- this.getProperty = function( nodeID, propertyName, ignorePrototype ) {
- this.logger.debuggx( "getProperty", nodeID, propertyName );
- var propertyValue = undefined;
-
-
-
- var entrants = this.getProperty.entrants;
- var entry = entrants[nodeID+'-'+propertyName] || {};
- var reentry = entrants[nodeID+'-'+propertyName] = {};
-
-
- var outermost = entrants.retrievals === undefined;
- if ( outermost ) {
- entrants.retrievals = 0;
- }
-
-
-
-
-
- var reentered = ( entry.index !== undefined );
-
-
- var delegated = false, retrieved = false;
-
-
- this.models.some( function( model, index ) {
-
-
-
- if ( ( ! reentered || index > entry.index ) && ! reentry.completed ) {
-
-
- reentry.index = index;
-
-
-
- var retrievals = entrants.retrievals;
-
- var value = model.gettingProperty &&
- model.gettingProperty( nodeID, propertyName, propertyValue );
-
-
-
- if ( this.models.kernel.blocked() ) {
- value = undefined;
- }
-
- if ( entrants.retrievals !== retrievals ) {
- delegated = true;
- }
-
- else if ( value !== undefined ) {
- entrants.retrievals++;
- retrieved = true;
- }
-
- if ( value !== undefined ) {
- propertyValue = value;
- }
-
- return delegated || retrieved;
- }
- }, this );
- if ( reentered ) {
-
-
- entrants[nodeID+'-'+propertyName] = entry;
- entry.completed = true;
- } else {
-
-
- delete entrants[nodeID+'-'+propertyName];
-
-
- if ( propertyValue === undefined && ! ignorePrototype ) {
- this.behaviors( nodeID ).reverse().concat( this.prototype( nodeID ) ).
- some( function( prototypeID, prototypeIndex, prototypeArray ) {
- if ( prototypeIndex < prototypeArray.length - 1 ) {
- propertyValue = this.getProperty( prototypeID, propertyName, true );
- } else if ( prototypeID !== this.kutility.protoNodeURI ) {
- propertyValue = this.getProperty( prototypeID, propertyName );
- }
- return propertyValue !== undefined;
- }, this );
- }
-
- this.views.forEach( function( view ) {
- view.gotProperty && view.gotProperty( nodeID, propertyName, propertyValue );
- } );
- }
-
- if ( outermost ) {
- delete entrants.retrievals;
- }
- this.logger.debugu();
- return propertyValue;
- };
- this.getProperty.entrants = {};
-
-
-
-
- this.createMethod = function( nodeID, methodName, methodParameters, methodBody ) {
- this.logger.debuggx( "createMethod", function() {
- return [ nodeID, methodName, methodParameters, loggableScript( methodBody ) ];
- } );
- var node = nodes.existing[nodeID];
-
- node.methods.create( methodName, node.initialized && node.patchable );
-
-
- this.models.forEach( function( model ) {
- model.creatingMethod && model.creatingMethod( nodeID, methodName, methodParameters,
- methodBody );
- } );
-
-
- this.views.forEach( function( view ) {
- view.createdMethod && view.createdMethod( nodeID, methodName, methodParameters,
- methodBody );
- } );
-
- if ( this.models.kernel.enabled() ) {
- this.fireEvent( nodeID, [ "methods", "created" ], [ methodName ] );
- }
- this.logger.debugu();
- };
-
-
-
-
- this.setMethod = function( nodeID, methodName, methodHandler ) {
- this.logger.debuggx( "setMethod", function() {
- return [ nodeID, methodName ];
- } );
- var node = nodes.existing[nodeID];
- methodHandler = normalizedHandler( methodHandler );
- if ( ! node.methods.hasOwn( methodName ) ) {
-
-
- this.createMethod( nodeID, methodName, methodHandler.parameters, methodHandler.body );
- } else {
-
-
- this.models.some( function( model ) {
-
- var handler = model.settingMethod && model.settingMethod( nodeID, methodName, methodHandler );
-
- if ( handler !== undefined ) {
- methodHandler = require( "vwf/utility" ).merge( {}, handler );
- }
-
- return handler !== undefined;
- } );
-
- if ( node.initialized && node.patchable ) {
- node.methods.change( methodName );
- }
-
- this.views.forEach( function( view ) {
- view.satMethod && view.satMethod( nodeID, methodName, methodHandler );
- } );
- }
- this.logger.debugu();
- return methodHandler;
- };
-
-
-
-
- this.getMethod = function( nodeID, methodName ) {
- this.logger.debuggx( "getMethod", function() {
- return [ nodeID, methodName ];
- } );
- var node = nodes.existing[nodeID];
-
-
- var methodHandler = {};
- this.models.some( function( model ) {
-
- var handler = model.gettingMethod && model.gettingMethod( nodeID, methodName );
-
- if ( handler !== undefined ) {
- methodHandler = require( "vwf/utility" ).merge( {}, handler );
- }
-
- return handler !== undefined;
- } );
-
- this.views.forEach( function( view ) {
- view.gotMethod && view.gotMethod( nodeID, methodName, methodHandler );
- } );
- this.logger.debugu();
- return methodHandler;
- };
-
-
-
-
- this.callMethod = function( nodeID, methodName, methodParameters ) {
- this.logger.debuggx( "callMethod", function() {
- return [ nodeID, methodName, JSON.stringify( loggableValues( methodParameters ) ) ];
- } );
-
-
- var methodValue = undefined;
- this.models.some( function( model ) {
- methodValue = model.callingMethod && model.callingMethod( nodeID, methodName, methodParameters );
- return methodValue !== undefined;
- } );
-
- this.views.forEach( function( view ) {
- view.calledMethod && view.calledMethod( nodeID, methodName, methodParameters, methodValue );
- } );
- this.logger.debugu();
- return methodValue;
- };
-
-
-
-
- this.createEvent = function( nodeID, eventName, eventParameters ) {
- this.logger.debuggx( "createEvent", nodeID, eventName, eventParameters );
- var node = nodes.existing[nodeID];
-
- var encodedEventName = namespaceEncodedName( eventName );
-
- node.events.create( encodedEventName, node.initialized && node.patchable, eventParameters );
-
-
- this.models.forEach( function( model ) {
- model.creatingEvent && model.creatingEvent( nodeID, encodedEventName, eventParameters );
- } );
-
-
- this.views.forEach( function( view ) {
- view.createdEvent && view.createdEvent( nodeID, encodedEventName, eventParameters );
- } );
-
- if ( this.models.kernel.enabled() ) {
- this.fireEvent( nodeID, [ "events", "created" ], [ eventName ] );
- }
- this.logger.debugu();
- };
-
-
-
-
- this.setEvent = function( nodeID, eventName, eventDescriptor ) {
- this.logger.debuggx( "setEvent", function() {
- return [ nodeID, eventName ];
- } );
- var node = nodes.existing[nodeID];
-
-
- var encodedEventName = namespaceEncodedName( eventName );
- if ( ! node.events.hasOwn( encodedEventName ) ) {
-
-
- this.createEvent( nodeID, eventName, eventDescriptor.parameters );
- ( eventDescriptor.listeners || [] ).forEach( function( listener ) {
- return this.addEventListener( nodeID, eventName, listener, listener.context, listener.phases );
- }, this );
- } else {
-
- var event = node.events.existing[ encodedEventName ];
-
- eventDescriptor = {
- parameters: event.parameters ?
- event.parameters.slice() : [],
- listeners: ( eventDescriptor.listeners || [] ).map( function( listener ) {
- if ( event.listeners.hasOwn( listener.id ) ) {
- return this.setEventListener( nodeID, eventName, listener.id, listener );
- } else {
- return this.addEventListener( nodeID, eventName, listener, listener.context, listener.phases );
- }
- }, this ),
- };
- }
- this.logger.debugu();
- return eventDescriptor;
- };
-
-
-
-
- this.getEvent = function( nodeID, eventName ) {
- this.logger.debuggx( "getEvent", function() {
- return [ nodeID, eventName ];
- } );
- var node = nodes.existing[nodeID];
-
- var encodedEventName = namespaceEncodedName( eventName );
-
- var event = node.events.existing[ encodedEventName ];
-
-
- var eventDescriptor = {};
- if ( event.parameters ) {
- eventDescriptor.parameters = event.parameters.slice();
- }
- if ( event.listeners.existing.length ) {
- eventDescriptor.listeners = event.listeners.existing.map( function( eventListenerID ) {
- var listener = this.getEventListener( nodeID, eventName, eventListenerID );
- listener.id = eventListenerID;
- return listener;
- }, this );
- }
- this.logger.debugu();
- return eventDescriptor;
- };
-
-
-
-
- this.addEventListener = function( nodeID, eventName, eventHandler, eventContextID, eventPhases ) {
- this.logger.debuggx( "addEventListener", function() {
- return [ nodeID, eventName, loggableScript( eventHandler ),
- eventContextID, eventPhases ];
- } );
- var node = nodes.existing[nodeID];
-
- var encodedEventName = namespaceEncodedName( eventName );
-
- if ( ! node.events.hasOwn( encodedEventName ) ) {
- node.events.create( encodedEventName, node.initialized && node.patchable );
- }
-
- var event = node.events.existing[ encodedEventName ];
-
- eventHandler = normalizedHandler( eventHandler, event.parameters );
-
- var eventListenerID = eventHandler.id || this.sequence( nodeID );
- event.listeners.create( eventListenerID, node.initialized && node.patchable );
-
- this.models.forEach( function( model ) {
- model.addingEventListener &&
- model.addingEventListener( nodeID, encodedEventName, eventListenerID,
- eventHandler, eventContextID, eventPhases );
- } );
-
- this.views.forEach( function( view ) {
- view.addedEventListener &&
- view.addedEventListener( nodeID, encodedEventName, eventListenerID,
- eventHandler, eventContextID, eventPhases );
- } );
- this.logger.debugu();
- return eventListenerID;
- };
-
-
-
-
- this.removeEventListener = function( nodeID, eventName, eventListenerID ) {
- this.logger.debuggx( "removeEventListener", function() {
- return [ nodeID, eventName, loggableScript( eventListenerID ) ];
- } );
- var node = nodes.existing[nodeID];
-
- var encodedEventName = namespaceEncodedName( eventName );
-
- var event = node.events.existing[ encodedEventName ];
-
- event.listeners.delete( eventListenerID, node.initialized && node.patchable );
-
- this.models.forEach( function( model ) {
- model.removingEventListener &&
- model.removingEventListener( nodeID, encodedEventName, eventListenerID );
- } );
-
- this.views.forEach( function( view ) {
- view.removedEventListener &&
- view.removedEventListener( nodeID, encodedEventName, eventListenerID );
- } );
- this.logger.debugu();
- return eventListenerID;
- };
-
-
-
-
- this.setEventListener = function( nodeID, eventName, eventListenerID, eventListener ) {
- this.logger.debuggx( "setEventListener", function() {
- return [ nodeID, eventName, eventListenerID ];
- } );
- var node = nodes.existing[nodeID];
-
- var encodedEventName = namespaceEncodedName( eventName );
-
- var event = node.events.existing[ encodedEventName ];
-
- eventListener = normalizedHandler( eventListener, event.parameters );
-
- if ( node.initialized && node.patchable ) {
- event.listeners.change( eventListenerID );
- }
-
-
- this.models.some( function( model ) {
-
- var listener = model.settingEventListener &&
- model.settingEventListener( nodeID, encodedEventName, eventListenerID, eventListener );
-
- if ( listener !== undefined ) {
- eventListener = require( "vwf/utility" ).merge( {}, listener );
- }
-
- return listener !== undefined;
- } );
-
- this.views.forEach( function( view ) {
- view.satEventListener &&
- view.satEventListener( nodeID, encodedEventName, eventListenerID, eventListener );
- } );
- this.logger.debugu();
- return eventListener;
- };
-
-
-
-
- this.getEventListener = function( nodeID, eventName, eventListenerID ) {
- this.logger.debuggx( "getEventListener", function() {
- return [ nodeID, eventName, eventListenerID ];
- } );
-
- var encodedEventName = namespaceEncodedName( eventName );
-
-
- var eventListener = {};
- this.models.some( function( model ) {
-
- var listener = model.gettingEventListener &&
- model.gettingEventListener( nodeID, encodedEventName, eventListenerID );
-
- if ( listener !== undefined ) {
- eventListener = require( "vwf/utility" ).merge( {}, listener );
- }
-
- return listener !== undefined;
- } );
-
- this.views.forEach( function( view ) {
- view.gotEventListener &&
- view.gotEventListener( nodeID, encodedEventName, eventListenerID, eventListener );
- } );
- this.logger.debugu();
- return eventListener;
- };
-
-
-
-
- this.flushEventListeners = function( nodeID, eventName, eventContextID ) {
- this.logger.debuggx( "flushEventListeners", nodeID, eventName, eventContextID );
-
- var encodedEventName = namespaceEncodedName( eventName );
-
- var node = nodes.existing[ nodeID ];
- var event = node.events.existing[ encodedEventName ];
-
- this.models.forEach( function( model ) {
- var removedIds = model.flushingEventListeners &&
- model.flushingEventListeners( nodeID, encodedEventName, eventContextID );
-
-
-
- if ( removedIds && removedIds.length ) {
-
- removedIds.forEach( function( removedId ) {
- event.listeners.delete( removedId, node.initialized && node.patchable );
- } );
- }
- } );
-
- this.views.forEach( function( view ) {
- view.flushedEventListeners &&
- view.flushedEventListeners( nodeID, encodedEventName, eventContextID );
- } );
-
-
-
- this.logger.debugu();
- };
-
-
-
-
- this.fireEvent = function( nodeID, eventName, eventParameters ) {
- this.logger.debuggx( "fireEvent", function() {
- return [ nodeID, eventName, JSON.stringify( loggableValues( eventParameters ) ) ];
- } );
-
- var encodedEventName = namespaceEncodedName( eventName );
-
- var handled = this.models.reduce( function( handled, model ) {
- return model.firingEvent && model.firingEvent( nodeID, encodedEventName, eventParameters ) || handled;
- }, false );
-
- this.views.forEach( function( view ) {
- view.firedEvent && view.firedEvent( nodeID, encodedEventName, eventParameters );
- } );
- this.logger.debugu();
-
-
- return handled;
- };
-
-
-
-
-
-
-
-
- this.dispatchEvent = function( nodeID, eventName, eventParameters, eventNodeParameters ) {
- this.logger.debuggx( "dispatchEvent", function() {
- return [ nodeID, eventName, JSON.stringify( loggableValues( eventParameters ) ),
- JSON.stringify( loggableIndexedValues( eventNodeParameters ) ) ];
- } );
-
-
-
- eventParameters = eventParameters || [];
- eventNodeParameters = eventNodeParameters || {};
-
- var ancestorIDs = this.ancestors( nodeID );
- var lastAncestorID = "";
-
-
-
- var cascadedEventNodeParameters = {
- "": eventNodeParameters[""] || []
- };
-
-
- var targetEventParameters = undefined;
- var phase = undefined;
- var handled = false;
-
- phase = "capture";
- handled = handled || ancestorIDs.reverse().some( function( ancestorID ) {
- cascadedEventNodeParameters[ancestorID] = eventNodeParameters[ancestorID] ||
- cascadedEventNodeParameters[lastAncestorID];
- lastAncestorID = ancestorID;
- targetEventParameters =
- eventParameters.concat( cascadedEventNodeParameters[ancestorID], phase );
-
- targetEventParameters.phase = phase;
- return this.fireEvent( ancestorID, eventName, targetEventParameters );
- }, this );
-
- phase = undefined;
- cascadedEventNodeParameters[nodeID] = eventNodeParameters[nodeID] ||
- cascadedEventNodeParameters[lastAncestorID];
- targetEventParameters =
- eventParameters.concat( cascadedEventNodeParameters[nodeID], phase );
- handled = handled || this.fireEvent( nodeID, eventName, targetEventParameters );
-
- phase = undefined;
- handled = handled || ancestorIDs.reverse().some( function( ancestorID ) {
- targetEventParameters =
- eventParameters.concat( cascadedEventNodeParameters[ancestorID], phase );
- return this.fireEvent( ancestorID, eventName, targetEventParameters );
- }, this );
- this.logger.debugu();
- };
-
-
-
-
- this.execute = function( nodeID, scriptText, scriptType, callback_async /* result */ ) {
- this.logger.debuggx( "execute", function() {
- return [ nodeID, loggableScript( scriptText ), scriptType ];
- } );
-
- if ( ! scriptType && ( typeof scriptText == "string" || scriptText instanceof String ) ) {
- scriptType = "application/javascript";
- }
-
-
- var scriptValue = undefined;
-
-
- vwf.models.kernel.capturingAsyncs( function() {
- vwf.models.some( function( model ) {
- scriptValue = model.executing &&
- model.executing( nodeID, scriptText, scriptType );
- return scriptValue !== undefined;
- } );
-
- vwf.views.forEach( function( view ) {
- view.executed && view.executed( nodeID, scriptText, scriptType );
- } );
- }, function() {
- callback_async && callback_async( scriptValue );
- } );
- this.logger.debugu();
- return scriptValue;
- };
-
-
-
-
- this.random = function( nodeID ) {
- return this.models.object.random( nodeID );
- };
-
-
-
-
- this.seed = function( nodeID, seed ) {
- return this.models.object.seed( nodeID, seed );
- };
-
-
-
-
-
-
- this.time = function() {
- return this.now;
- };
-
-
-
-
-
-
-
- this.client = function() {
- return this.client_;
- };
-
-
-
-
-
-
- this.moniker = function() {
- return this.moniker_;
- };
-
-
-
-
- this.application = function( initializedOnly ) {
- var applicationID;
- Object.keys( nodes.globals ).forEach( function( globalID ) {
- var global = nodes.existing[ globalID ];
- if ( ( ! initializedOnly || global.initialized ) && global.name === "application" ) {
- applicationID = globalID;
- }
- }, this );
- return applicationID;
- };
-
-
-
-
- this.intrinsics = function( nodeID, result ) {
- return this.models.object.intrinsics( nodeID, result );
- };
-
-
-
-
- this.uri = function( nodeID, searchAncestors, initializedOnly ) {
- var uri = this.models.object.uri( nodeID );
- if ( searchAncestors ) {
- while ( ! uri && ( nodeID = this.parent( nodeID, initializedOnly ) ) ) {
- uri = this.models.object.uri( nodeID );
- }
- }
- return uri;
- };
-
-
-
-
- this.name = function( nodeID ) {
- return this.models.object.name( nodeID );
- };
-
-
-
-
- this.prototype = function( nodeID ) {
- return this.models.object.prototype( nodeID );
- };
-
-
-
-
- this.prototypes = function( nodeID, includeBehaviors ) {
- var prototypes = [];
- do {
-
- if ( includeBehaviors ) {
- var b = [].concat( this.behaviors( nodeID ) );
- Array.prototype.push.apply( prototypes, b.reverse() );
- }
-
- nodeID = this.prototype( nodeID );
-
- if ( nodeID ) {
- prototypes.push( nodeID );
- }
- } while ( nodeID );
- return prototypes;
- };
-
-
-
-
- this.behaviors = function( nodeID ) {
- return this.models.object.behaviors( nodeID );
- };
-
-
-
-
- this.globals = function( initializedOnly ) {
- var globals = {};
- Object.keys( nodes.globals ).forEach( function( globalID ) {
- if ( ! initializedOnly || nodes.existing[ globalID ].initialized ) {
- globals[ globalID ] = undefined;
- }
- }, this );
- return globals;
- };
-
-
-
-
- this.global = function( globalReference, initializedOnly ) {
- var globals = this.globals( initializedOnly );
-
-
- return matches( "uri" ) || matches( "name" );
-
- function matches( field ) {
- var matchingID;
- Object.keys( globals ).some( function( globalID ) {
- if ( nodes.existing[ globalID ][ field ] === globalReference ) {
- matchingID = globalID;
- return true;
- }
- } );
- return matchingID;
- }
- };
-
-
-
-
- this.root = function( nodeID, initializedOnly ) {
- var rootID;
-
-
-
-
- do {
- rootID = nodeID;
- nodeID = this.parent( nodeID, initializedOnly );
- } while ( nodeID );
-
-
- return nodeID === undefined ? undefined : rootID;
- };
-
-
-
-
- this.ancestors = function( nodeID, initializedOnly ) {
- var ancestors = [];
- nodeID = this.parent( nodeID, initializedOnly );
- while ( nodeID ) {
- ancestors.push( nodeID );
- nodeID = this.parent( nodeID, initializedOnly );
- }
- return ancestors;
- };
-
-
-
-
- this.parent = function( nodeID, initializedOnly ) {
- return this.models.object.parent( nodeID, initializedOnly );
- };
-
-
-
-
- this.children = function( nodeID, initializedOnly ) {
- if ( nodeID === undefined ) {
- this.logger.errorx( "children", "cannot retrieve children of nonexistent node" );
- return;
- }
- return this.models.object.children( nodeID, initializedOnly );
- };
-
-
-
-
- this.child = function( nodeID, childReference, initializedOnly ) {
- var children = this.children( nodeID, initializedOnly );
- if ( typeof childReference === "number" || childReference instanceof Number ) {
- return children[ childReference ];
- } else {
- return children.filter( function( childID ) {
- return childID && this.name( childID ) === childReference;
- }, this )[ 0 ];
- }
- };
-
-
-
-
- this.descendants = function( nodeID, initializedOnly ) {
- if ( nodeID === undefined ) {
- this.logger.errorx( "descendants", "cannot retrieve children of nonexistent node" );
- return;
- }
- var descendants = [];
- this.children( nodeID, initializedOnly ).forEach( function( childID ) {
- descendants.push( childID );
- childID && Array.prototype.push.apply( descendants, this.descendants( childID, initializedOnly ) );
- }, this );
- return descendants;
- };
-
-
-
-
- this.sequence = function( nodeID ) {
- return this.models.object.sequence( nodeID );
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.find = function( nodeID, matchPattern, initializedOnly, callback /* ( matchID ) */ ) {
-
-
-
- if ( typeof initializedOnly == "function" || initializedOnly instanceof Function ) {
- callback = initializedOnly;
- initializedOnly = undefined;
- }
-
- var matchIDs = find.call( this, nodeID, matchPattern, initializedOnly );
-
-
- if ( callback ) {
- matchIDs.forEach( function( matchID ) {
- callback( matchID );
- } );
- } else {
- return matchIDs;
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.findClients = function( nodeID, matchPattern, callback /* ( matchID ) */ ) {
- this.logger.warn( "`kernel.findClients` is deprecated. Use " +
- "`kernel.find( nodeID, \"doc('http://vwf.example.com/clients.vwf')/pattern\" )`" +
- " instead." );
- var clientsMatchPattern = "doc('http://vwf.example.com/clients.vwf')" +
- ( matchPattern[0] === "/" ? "" : "/" ) + matchPattern;
- return this.find( nodeID || this.application(), clientsMatchPattern, callback );
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.test = function( nodeID, matchPattern, testID, initializedOnly ) {
-
- var matchIDs = find.call( this, nodeID, matchPattern, initializedOnly );
-
- return matchIDs.some( function( matchID ) {
- return matchID == testID;
- } );
- };
-
- var isSocketIO07 = function() {
-
- return true
- }
-
-
- var loadComponent = function( nodeURI, baseURI, callback_async /* nodeDescriptor */, errback_async /* errorMessage */ ) {
- if ( nodeURI == vwf.kutility.protoNodeURI ) {
- callback_async( vwf.kutility.protoNodeDescriptor );
- } else if ( nodeURI.match( RegExp( "^data:application/json;base64," ) ) ) {
-
-
-
- callback_async( JSON.parse( atob( nodeURI.substring( 29 ) ) ) );
- } else {
- queue.suspend( "while loading " + nodeURI );
- let fetchUrl = remappedURI( require( "vwf/utility" ).resolveURI( nodeURI, baseURI ) );
- fetch(fetchUrl, {
- method: 'get'
- }).then(function(response) {
- return response.json();
- }).catch(function(err) {
-
- }).then(function(nodeDescriptor) {
- callback_async( nodeDescriptor );
- queue.resume( "after loading " + nodeURI );
- }).catch(function(error) {
- vwf.logger.warnx( "loadComponent", "error loading", nodeURI + ":", error );
- errback_async( error );
- queue.resume( "after loading " + nodeURI );
- })
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- };
-
-
- var loadScript = function( scriptURI, baseURI, callback_async /* scriptText */, errback_async /* errorMessage */ ) {
- if ( scriptURI.match( RegExp( "^data:application/javascript;base64," ) ) ) {
-
-
-
- callback_async( atob( scriptURI.substring( 35 ) ) );
- } else {
- queue.suspend( "while loading " + scriptURI );
- let fetchUrl = remappedURI( require( "vwf/utility" ).resolveURI( scriptURI, baseURI ) );
- fetch(fetchUrl, {
- method: 'get'
- }).then(function(response) {
- return response.text();
- }).catch(function(err) {
-
- }).then(function(scriptText) {
- callback_async( scriptText );
- queue.resume( "after loading " + scriptURI );
- }).catch(function(error) {
- vwf.logger.warnx( "loadScript", "error loading", scriptURI + ":", error );
- errback_async( error );
- queue.resume( "after loading " + scriptURI );
- })
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
- var nodePropertyHasSetter = function( nodeID, propertyName ) {
- var node = this.models.javascript.nodes[nodeID];
- var setter = node.private.setters && node.private.setters[propertyName];
- return typeof setter == "function" || setter instanceof Function;
- };
-
-
-
-
-
-
-
-
-
-
-
-
- var nodePropertyHasOwnSetter = function( nodeID, propertyName ) {
- var node = this.models.javascript.nodes[nodeID];
- var setter = node.private.setters && node.private.setters.hasOwnProperty( propertyName ) && node.private.setters[propertyName];
- return typeof setter == "function" || setter instanceof Function;
- };
-
-
-
-
-
-
-
-
-
-
-
-
- var nodeHasChild = function( nodeID, childName ) {
- var node = this.models.javascript.nodes[nodeID];
- return childName in node.children;
- };
-
-
-
-
-
-
-
-
-
-
-
-
- var nodeHasOwnChild = function( nodeID, childName ) {
- var node = this.models.javascript.nodes[nodeID];
- var hasChild = false;
- if ( parseInt( childName ).toString() !== childName ) {
- hasChild = node.children.hasOwnProperty( childName );
- }
- else {
-
-
- for(var i=0, il=node.children.length; i<il;i++) {
- if(childName === node.children[i].name) {
- hasChild = true;
- }
- }
- }
- return hasChild;
- };
-
-
-
-
-
-
-
-
-
-
- var componentIsURI = function( candidate ) {
- return ( typeof candidate == "string" || candidate instanceof String ) && ! componentIsID( candidate );
- };
-
-
-
-
-
-
-
-
-
-
- var componentIsDescriptor = function( candidate ) {
- return typeof candidate == "object" && candidate != null && ! isPrimitive( candidate );
- };
-
-
-
-
-
-
-
-
-
-
- var componentIsID = function( candidate ) {
- return isPrimitive( candidate ) && vwf.models.object.exists( candidate ) &&
- ! ( components[candidate] instanceof Array );
- };
-
-
-
-
-
-
-
-
-
-
-
- var isPrimitive = function( candidate ) {
- switch ( typeof candidate ) {
- case "string":
- case "number":
- case "boolean":
- return true;
- case "object":
- return candidate instanceof String || candidate instanceof Number ||
- candidate instanceof Boolean;
- default:
- return false;
- }
- };
-
-
-
-
-
-
-
-
- var objectIsComponent = function( candidate ) {
- var componentAttributes = [
- "extends",
- "implements",
- "source",
- "type",
- "properties",
- "methods",
- "events",
- "children",
- "scripts",
- ];
- var isComponent = false;
- if ( typeof candidate == "object" && candidate != null ) {
- isComponent = componentAttributes.some( function( attributeName ) {
- return candidate.hasOwnProperty( attributeName );
- } );
- }
-
- return isComponent;
- };
-
-
-
-
-
-
-
-
-
- var valueHasAccessors = function( candidate ) {
- var accessorAttributes = [
- "get",
- "set",
- "value",
- "node",
- "create",
- "undefined",
- ];
- var hasAccessors = false;
- if ( typeof candidate == "object" && candidate != null ) {
- hasAccessors = accessorAttributes.some( function( attributeName ) {
- return candidate.hasOwnProperty( attributeName );
- } );
- }
-
- return hasAccessors;
- };
-
-
-
-
-
-
-
-
-
- var valueHasBody = function( candidate ) {
- var bodyAttributes = [
- "parameters",
- "body",
- "listeners",
- ];
- var hasBody = false;
- if ( typeof candidate == "object" && candidate != null ) {
- hasBody = bodyAttributes.some( function( attributeName ) {
- return candidate.hasOwnProperty( attributeName );
- } );
- }
-
- return hasBody;
- };
-
-
-
-
-
-
-
-
-
- var valueHasType = function( candidate ) {
- var typeAttributes = [
- "source",
- "text",
- "type",
- ];
- var hasType = false;
- if ( typeof candidate == "object" && candidate != null ) {
- hasType = typeAttributes.some( function( attributeName ) {
- return candidate.hasOwnProperty( attributeName );
- } );
- }
-
- return hasType;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var namespaceEncodedName = function( memberName ) {
- if ( typeof memberName === "object" && memberName instanceof Array ) {
- return ( memberName.length !== 1 ) ? "vwf$" + memberName.join( "$" ) : memberName[0];
- } else {
- return memberName;
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var normalizedComponent = function( component ) {
-
-
-
- if ( componentIsURI( component ) ) {
- if ( component.match( /\.vwf$/ ) ) {
- component = { extends: component };
- } else {
- component = { source: component };
- }
- } else if ( componentIsID( component ) ) {
- component = { extends: component };
- }
-
- if ( component.source && ! component.type ) {
- var match = component.source.match( /\.([^.]*)$/ );
- if ( match ) {
- switch ( match[1] ) {
- case "unity3d":
- component.type = "application/vnd.unity";
- break;
- case "dae":
- component.type = "model/vnd.collada+xml";
- break;
- }
- }
- }
-
- if ( component.type && ! component.extends ) {
- switch ( component.type ) {
- case "application/vnd.unity":
- component.extends = "http://vwf.example.com/scene.vwf";
- break;
- case "model/vnd.collada+xml":
- component.extends = "http://vwf.example.com/navscene.vwf";
- break;
- }
- }
- return component;
- };
-
-
-
-
-
-
-
-
-
- var normalizedHandler = function( handler, defaultParameters ) {
-
- if ( typeof handler !== "object" || handler instanceof Array ) {
- handler = { body: handler };
- } else if ( require( "vwf/configuration" ).active[ "preserve-script-closures" ] && ( typeof handler == "function" || handler instanceof Function ) ) {
- handler = { body: handler };
- }
-
-
- if ( ! handler.parameters && defaultParameters ) {
- handler.parameters = defaultParameters;
- }
-
-
- if ( handler.type === undefined ) {
- if ( typeof handler.body === "string" || handler.body instanceof String ) {
- handler.type = "application/javascript";
- }
- }
- return handler;
- };
-
-
-
-
-
-
-
-
- var loggableFields = function( fields ) {
- return require( "vwf/utility" ).transform( fields, require( "vwf/utility" ).transforms.transit );
- };
-
-
-
-
-
-
-
- var loggableComponent = function( component ) {
- return require( "vwf/utility" ).transform( component, loggableComponentTransformation );
- };
-
-
-
-
-
-
-
- var loggableValue = function( value ) {
- return require( "vwf/utility" ).transform( value, function( object, names, depth ) {
- object = require( "vwf/utility" ).transforms.transit( object, names, depth );
- return typeof object == "number" ? Number( object.toPrecision(5) ) : object;
- } );
- };
-
-
-
-
-
-
-
-
- var loggableValues = function( values ) {
- return loggableValue( values );
- };
-
-
-
-
-
-
-
-
- var loggableIndexedValues = function( values ) {
- return loggableValue( values );
- };
-
-
-
-
-
-
-
- var loggableScript = function( script ) {
- return ( script || "" ).replace( /\s+/g, " " ).substring( 0, 100 );
- };
-
-
-
-
-
-
- var remappedURI = function( uri ) {
- var match = uri.match( RegExp( "http://(vwf.example.com)/(.*)" ) );
- if ( match ) {
- uri = window.location.protocol + "//" + window.location.host +
- "/proxy/" + match[1] + "/" + match[2];
- }
- return uri;
- };
-
-
-
-
- var resolvedDescriptor = function( component, baseURI ) {
- return require( "vwf/utility" ).transform( component, resolvedDescriptorTransformationWithBaseURI );
- function resolvedDescriptorTransformationWithBaseURI( object, names, depth ) {
- return resolvedDescriptorTransformation.call( this, object, names, depth, baseURI );
- }
- };
-
-
-
-
-
-
-
- var queueTransitTransformation = function( object, names, depth ) {
- if ( depth == 0 ) {
-
-
-
- return object.filter( function( fields ) {
- return ! ( fields.origin === "reflector" && fields.sequence > vwf.sequence_ ) && fields.action;
- } ).sort( function( fieldsA, fieldsB ) {
- return fieldsA.sequence - fieldsB.sequence;
- } );
- } else if ( depth == 1 ) {
-
-
-
- var filtered = {};
- Object.keys( object ).filter( function( key ) {
- return key != "sequence";
- } ).forEach( function( key ) {
- filtered[key] = object[key];
- } );
- return filtered;
- }
- return object;
- };
-
-
-
-
-
- var loggableComponentTransformation = function( object, names, depth ) {
-
- var markers = descriptorMarkers( object, names, depth );
-
- switch ( markers.containerName ) {
- case "extends":
-
- if ( markers.memberIndex == 0 && componentIsDescriptor( object ) ) {
- return {};
- }
- break;
- case "implements":
-
- if ( markers.memberIndex == 0 && componentIsDescriptor( object ) ) {
- return {};
- }
- break;
- case "properties":
-
-
- if ( markers.memberIndex == 0 && ! valueHasAccessors( object ) ||
- markers.memberIndex == 1 && names[0] == "value" ) {
- return loggableValue( object );
- } else if ( markers.memberIndex == 1 && ( names[0] == "get" || names[0] == "set" ) ) {
- return "...";
- }
- break;
- case "methods":
-
- if ( markers.memberIndex == 0 && ! valueHasBody( object ) ||
- markers.memberIndex == 1 && names[0] == "body" ) {
- return "...";
- }
- break;
- case "events":
-
- break;
- case "children":
-
- if ( markers.memberIndex == 0 && componentIsDescriptor( object ) ) {
- return {};
- }
- break;
- case "scripts":
-
- if ( markers.memberIndex == 0 && ! valueHasType( object ) ||
- markers.memberIndex == 1 && names[0] == "text" ) {
- return "...";
- }
- break;
- }
- return object;
- };
-
-
-
-
-
- var resolvedDescriptorTransformation = function( object, names, depth, baseURI ) {
-
- var markers = descriptorMarkers( object, names, depth );
-
- switch ( markers.containerName ) {
- case "extends":
- case "implements":
- case "source":
- case "children":
- if ( markers.memberIndex == 0 && componentIsURI( object ) ) {
- return require( "vwf/utility" ).resolveURI( object, baseURI );
- }
- break;
- case "scripts":
- if ( markers.memberIndex == 1 && names[0] == "source" ) {
- return require( "vwf/utility" ).resolveURI( object, baseURI );
- }
- break;
- }
- return object;
- };
-
-
-
-
-
- var descriptorMarkers = function( object, names, depth ) {
-
- var componentIndex = names.length;
- while ( componentIndex > 2 && names[componentIndex-1] == "children" ) {
- componentIndex -= 2;
- }
-
-
-
-
-
-
-
-
-
- if ( componentIndex > 0 ) {
-
-
- var containerIndex = componentIndex - 1;
- var containerName = names[containerIndex];
-
- if ( containerName == "extends" ) {
- var memberIndex = containerIndex;
- var memberName = names[memberIndex];
- } else if ( containerName == "implements" ) {
- if ( containerIndex > 0 ) {
- if ( typeof names[containerIndex-1] == "number" ) {
- var memberIndex = containerIndex - 1;
- var memberName = names[memberIndex];
- } else {
- var memberIndex = containerIndex;
- var memberName = undefined;
- }
- } else if ( typeof object != "object" || ! ( object instanceof Array ) ) {
- var memberIndex = containerIndex;
- var memberName = undefined;
- }
- } else if ( containerName == "source" || containerName == "type" ) {
- var memberIndex = containerIndex;
- var memberName = names[memberIndex];
- } else if ( containerName == "properties" || containerName == "methods" || containerName == "events" ||
- containerName == "children" ) {
- if ( containerIndex > 0 ) {
- var memberIndex = containerIndex - 1;
- var memberName = names[memberIndex];
- }
-
- } else if ( containerName == "scripts" ) {
- if ( containerIndex > 0 ) {
- if ( typeof names[containerIndex-1] == "number" ) {
- var memberIndex = containerIndex - 1;
- var memberName = names[memberIndex];
- } else {
- var memberIndex = containerIndex;
- var memberName = undefined;
- }
- } else if ( typeof object != "object" || ! ( object instanceof Array ) ) {
- var memberIndex = containerIndex;
- var memberName = undefined;
- }
- } else {
- containerIndex = undefined;
- containerName = undefined;
- }
- }
- return {
- containerIndex: containerIndex,
- containerName: containerName,
- memberIndex: memberIndex,
- memberName: memberName,
- };
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var find = function( nodeID, matchPattern, initializedOnly ) {
-
-
-
- var rootID = nodeID ? this.root( nodeID, initializedOnly ) :
- this.application( initializedOnly );
- return require( "vwf/utility" ).xpath.resolve( matchPattern, rootID, nodeID,
- resolverWithInitializedOnly, this );
-
- function resolverWithInitializedOnly( step, contextID, resolveAttributes ) {
- return xpathResolver.call( this, step, contextID, resolveAttributes, initializedOnly );
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var xpathResolver = function( step, contextID, resolveAttributes, initializedOnly ) {
- var resultIDs = [];
- switch ( step.axis ) {
-
-
- case "ancestor-or-self":
- resultIDs.push( contextID );
- Array.prototype.push.apply( resultIDs, this.ancestors( contextID, initializedOnly ) );
- break;
- case "ancestor":
- Array.prototype.push.apply( resultIDs, this.ancestors( contextID, initializedOnly ) );
- break;
- case "parent":
- var parentID = this.parent( contextID, initializedOnly );
- parentID && resultIDs.push( parentID );
- break;
- case "self":
- resultIDs.push( contextID );
- break;
- case "child":
- Array.prototype.push.apply( resultIDs,
- this.children( contextID, initializedOnly ).filter( function( childID ) {
- return childID;
- }, this )
- );
- break;
- case "descendant":
- Array.prototype.push.apply( resultIDs,
- this.descendants( contextID, initializedOnly ).filter( function( descendantID ) {
- return descendantID;
- }, this )
- );
- break;
- case "descendant-or-self":
- resultIDs.push( contextID );
- Array.prototype.push.apply( resultIDs,
- this.descendants( contextID, initializedOnly ).filter( function( descendantID ) {
- return descendantID;
- }, this )
- );
- break;
-
-
- case "attribute":
- if ( resolveAttributes ) {
- resultIDs.push( "@" + contextID );
- }
- break;
-
-
- }
- switch ( step.kind ) {
-
- case undefined:
- resultIDs = resultIDs.filter( function( resultID ) {
- if ( resultID[0] != "@" ) {
- return xpathNodeMatchesStep.call( this, resultID, step.name );
- } else {
- return xpathPropertyMatchesStep.call( this, resultID.slice( 1 ), step.name );
- }
- }, this );
- break;
-
- case "element":
-
-
-
-
-
- resultIDs = resultIDs.filter( function( resultID ) {
- return resultID[0] != "@" && xpathNodeMatchesStep.call( this, resultID, step.name, step.type );
- }, this );
- break;
-
- case "attribute":
- resultIDs = resultIDs.filter( function( resultID ) {
- return resultID[0] == "@" && xpathPropertyMatchesStep.call( this, resultID.slice( 1 ), step.name );
- }, this );
- break;
-
-
- case "doc":
- if ( this.root( contextID, initializedOnly ) ) {
- var globalID = this.global( step.name, initializedOnly );
- resultIDs = globalID ? [ globalID ] : [];
- } else {
- resultIDs = [];
- }
- break;
-
- case "node":
- break;
-
- default:
- resultIDs = [];
- break;
- }
- return resultIDs;
- }
-
-
-
-
-
-
-
-
-
-
- var xpathNodeMatchesStep = function( nodeID, name, type ) {
- if ( name && this.name( nodeID ) != name ) {
- return false;
- }
- var matches_type = ! type || this.uri( nodeID ) == type ||
- this.prototypes( nodeID, true ).some( function( prototypeID ) {
- return this.uri( prototypeID ) == type;
- }, this );
- return matches_type;
- }
-
-
-
-
-
-
-
-
-
- var xpathPropertyMatchesStep = function( nodeID, name ) {
- var properties = this.models.object.properties( nodeID );
- if ( name ) {
- return properties[name];
- } else {
- return Object.keys( properties ).some( function( propertyName ) {
- return properties[propertyName];
- }, this );
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var mergeDescriptors = function( nodeDescriptor, prototypeDescriptor ) {
- if ( nodeDescriptor.implements ) {
- prototypeDescriptor.implements = ( prototypeDescriptor.implements || [] ).
- concat( nodeDescriptor.implements );
- }
- if ( nodeDescriptor.source ) {
- prototypeDescriptor.source = nodeDescriptor.source;
- prototypeDescriptor.type = nodeDescriptor.type;
- }
- if ( nodeDescriptor.properties ) {
- prototypeDescriptor.properties = prototypeDescriptor.properties || {};
- for ( var propertyName in nodeDescriptor.properties ) {
- prototypeDescriptor.properties[propertyName] = nodeDescriptor.properties[propertyName];
- }
- }
- if ( nodeDescriptor.methods ) {
- prototypeDescriptor.methods = prototypeDescriptor.methods || {};
- for ( var methodName in nodeDescriptor.methods ) {
- prototypeDescriptor.methods[methodName] = nodeDescriptor.methods[methodName];
- }
- }
- if ( nodeDescriptor.events ) {
- prototypeDescriptor.events = prototypeDescriptor.events || {};
- for ( var eventName in nodeDescriptor.events ) {
- prototypeDescriptor.events[eventName] = nodeDescriptor.events[eventName];
- }
- }
- if ( nodeDescriptor.children ) {
- prototypeDescriptor.children = prototypeDescriptor.children || {};
- for ( var childName in nodeDescriptor.children ) {
- prototypeDescriptor.children[childName] = nodeDescriptor.children[childName];
- }
- }
- if ( nodeDescriptor.scripts ) {
- prototypeDescriptor.scripts = ( prototypeDescriptor.scripts || [] ).
- concat( nodeDescriptor.scripts );
- }
- return prototypeDescriptor;
- };
-
-
-
-
-
-
-
-
- var enumerable = function( value ) {
- return {
- value: value,
- enumerable: true,
- writable: false,
- configurable: false,
- };
- };
-
-
-
-
-
-
-
-
- var writable = function( value ) {
- return {
- value: value,
- enumerable: true,
- writable: true,
- configurable: false,
- };
- };
-
-
-
-
-
-
-
-
- var configurable = function( value ) {
- return {
- value: value,
- enumerable: true,
- writable: true,
- configurable: true,
- };
- };
-
-
-
- var keyedCollectionPrototype = {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- create: function( name, changes, value ) {
- if ( ! this.hasOwn( name ) ) {
- this.makeOwn( "existing" );
-
-
-
- Object.defineProperty( this.existing, name,
- configurable( value ? value : undefined ) );
- if ( changes ) {
- this.makeOwn( "changes" );
- if ( this.changes[ name ] !== "removed" ) {
- this.changes[ name ] = "added";
- } else {
- this.changes[ name ] = "changed";
- }
- if ( this.container && this.containerMember ) {
- this.container.change( this.containerMember );
- }
- }
- return true;
- }
- return false;
- },
-
-
-
-
-
-
-
-
- delete: function( name, changes ) {
- if ( this.hasOwn( name ) ) {
- delete this.existing[ name ];
- if ( changes ) {
- this.makeOwn( "changes" );
- if ( this.changes[ name ] !== "added" ) {
- this.changes[ name ] = "removed";
- } else {
- delete this.changes[ name ];
- }
- if ( this.container && this.containerMember ) {
- this.container.change( this.containerMember );
- }
- }
- return true;
- }
- return false;
- },
-
-
-
-
-
-
-
-
- change: function( name, value ) {
- if ( this.hasOwn( name ) ) {
- this.makeOwn( "changes" );
- if ( this.changes[ name ] !== "added" ) {
- this.changes[ name ] = value ?
- value : this.changes[ name ] || "changed";
- }
- if ( this.container && this.containerMember ) {
- this.container.change( this.containerMember );
- }
- return true;
- }
- return false;
- },
-
-
-
-
-
-
-
- has: function( name ) {
- return name in this.existing;
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
- hasOwn: function( name ) {
- return Object.prototype.hasOwnProperty.call( this.existing, name );
- },
-
-
-
-
-
-
-
-
-
-
- makeOwn: function( fieldName ) {
- if ( ! this.hasOwnProperty( fieldName ) ) {
- if ( this[ fieldName ] instanceof Array ) {
- this[ fieldName ] = this[ fieldName ].slice();
- } else if ( typeof this[ fieldName ] === "object" && this[ fieldName ] !== null ) {
- this[ fieldName ] = Object.create( this[ fieldName ] );
- } else {
- this[ fieldName ] = this[ fieldName ];
- }
- }
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- existing: Object.create( null
-
-
-
- ),
-
-
-
-
-
-
- changes: {
-
-
-
-
-
- },
-
-
-
-
-
-
-
-
- container: undefined,
-
-
-
- containerMember: undefined,
- };
-
-
- var indexedCollectionPrototype = {
-
-
-
-
-
-
-
-
-
-
-
- create: function( id, changes ) {
- if ( ! this.hasOwn( id ) ) {
- this.makeOwn( "existing" );
- this.existing.push( id );
- if ( changes ) {
- this.makeOwn( "changes" );
- var removedIndex = this.changes.removed ?
- this.changes.removed.indexOf( id ) : -1;
- if ( removedIndex < 0 ) {
- this.changes.added = this.changes.added || [];
- this.changes.added.push( id );
- } else {
- this.changes.removed.splice( removedIndex, 1 );
- this.changes.changed = this.changes.changed || [];
- this.changes.changed.push( id );
- }
- if ( this.container && this.containerMember ) {
- this.container.change( this.containerMember );
- }
- }
- return true;
- }
- return false;
- },
-
-
-
-
-
-
-
-
- delete: function( id, changes ) {
- if ( this.hasOwn( id ) ) {
- this.existing.splice( this.existing.indexOf( id ), 1 );
- if ( changes ) {
- this.makeOwn( "changes" );
- var addedIndex = this.changes.added ?
- this.changes.added.indexOf( id ) : -1;
- if ( addedIndex < 0 ) {
- this.changes.removed = this.changes.removed || [];
- this.changes.removed.push( id );
- } else {
- this.changes.added.splice( addedIndex, 1 );
- }
- if ( this.container && this.containerMember ) {
- this.container.change( this.containerMember );
- }
- }
- return true;
- }
- return false;
- },
-
-
-
-
-
-
-
-
- change: function( id ) {
- if ( this.hasOwn( id ) ) {
- this.makeOwn( "changes" );
- var addedIndex = this.changes.added ?
- this.changes.added.indexOf( id ) : -1;
- var changedIndex = this.changes.changed ?
- this.changes.changed.indexOf( id ) : -1;
- if ( addedIndex < 0 && changedIndex < 0 ) {
- this.changes.changed = this.changes.changed || [];
- this.changes.changed.push( id );
- }
- if ( this.container && this.containerMember ) {
- this.container.change( this.containerMember );
- }
- return true;
- }
- return false;
- },
-
-
-
-
-
-
-
-
-
- has: function( id ) {
- return this.hasOwn( id );
- },
-
-
-
-
-
-
-
- hasOwn: function( id ) {
- return this.existing ? this.existing.indexOf( id ) >= 0 : false;
- },
-
-
-
-
-
-
-
-
-
-
- makeOwn: function( fieldName ) {
- if ( ! this.hasOwnProperty( fieldName ) ) {
- if ( this[ fieldName ] instanceof Array ) {
- this[ fieldName ] = this[ fieldName ].slice();
- } else if ( typeof this[ fieldName ] === "object" && this[ fieldName ] !== null ) {
- this[ fieldName ] = Object.create( this[ fieldName ] );
- } else {
- this[ fieldName ] = this[ fieldName ];
- }
- }
- },
-
-
-
-
-
-
-
-
-
-
- existing: [
-
-
-
- ],
-
-
-
-
-
-
-
-
-
-
-
- changes: {
-
-
-
- },
-
-
-
-
-
-
-
-
- container: undefined,
-
-
-
- containerMember: undefined,
- };
-
- var eventCollectionPrototype = Object.create( keyedCollectionPrototype, {
- create: {
- value: function( name, changes, parameters ) {
- var value = parameters ? {
- parameters: parameters.slice(),
- } : {};
- value.listeners = Object.create( indexedCollectionPrototype, {
- container: enumerable( this ),
- containerMember: enumerable( name ),
- } );
- return keyedCollectionPrototype.create.call( this, name, changes, value );
- }
- },
- } );
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var nodes = {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- create: function( nodeID, prototypeID, behaviorIDs, nodeURI, nodeName, parentID ) {
-
- var self = this;
- var prototypeNode = behaviorIDs.reduce( function( prototypeNode, behaviorID ) {
- return self.proxy( prototypeNode, self.existing[behaviorID] );
- }, this.existing[prototypeID] );
-
- var parentNode = this.existing[parentID];
-
- if ( ! parentNode ) {
- this.globals[nodeID] = undefined;
- }
-
- return this.existing[nodeID] = {
-
-
-
-
-
-
-
- uri: nodeURI,
- name: nodeName,
-
-
-
-
-
-
-
-
-
- properties: Object.create( keyedCollectionPrototype, {
- existing: enumerable( Object.create( prototypeNode ?
- prototypeNode.properties.existing : null ) ),
- } ),
- methods: Object.create( keyedCollectionPrototype, {
- existing: enumerable( Object.create( prototypeNode ?
- prototypeNode.methods.existing : null ) ),
- } ),
- events: Object.create( eventCollectionPrototype, {
- existing: enumerable( Object.create( prototypeNode ?
- prototypeNode.events.existing : null ) ),
- } ),
-
-
- patchable: !! ( nodeURI ||
- parentNode && ! parentNode.initialized && parentNode.patchable ),
-
-
-
- initialized: false,
- };
-
-
-
- },
-
- initialize: function( nodeID ) {
- if ( this.existing[nodeID] ) {
- this.existing[nodeID].initialized = true;
- return true;
- }
- return false;
- },
-
- delete: function( nodeID ) {
- if ( this.existing[nodeID] ) {
- delete this.existing[nodeID];
- delete this.globals[nodeID];
- return true;
- }
- return false;
- },
-
-
-
-
-
- proxy: function( prototypeNode, behaviorNode ) {
- return {
- properties: {
- existing: Object.create(
- prototypeNode ? prototypeNode.properties.existing : null,
- propertyDescriptorsFor( behaviorNode.properties.existing )
- ),
- },
- methods: {
- existing: Object.create(
- prototypeNode ? prototypeNode.methods.existing : null,
- propertyDescriptorsFor( behaviorNode.methods.existing )
- ),
- },
- events: {
- existing: Object.create(
- prototypeNode ? prototypeNode.events.existing : null,
- propertyDescriptorsFor( behaviorNode.events.existing )
- ),
- },
- };
-
-
- function propertyDescriptorsFor( collectionExisting ) {
- return Object.keys( collectionExisting ).reduce(
- function( propertiesObject, memberName ) {
- propertiesObject[memberName] = {
- get: function() { return collectionExisting[memberName] },
- enumerable: true,
- };
- return propertiesObject;
- },
- {}
- );
- }
- },
-
- existing: {
-
-
-
-
-
-
- },
-
-
-
-
- globals: {
-
- },
- };
-
-
-
-
- var queue = this.private.queue = {
-
-
-
-
-
-
-
-
-
-
-
-
- insert: function( fields, chronic ) {
- var messages = fields instanceof Array ? fields : [ fields ];
- messages.forEach( function( fields ) {
-
- fields.sequence = ++this.sequence;
- this.queue.push( fields );
-
- if ( chronic ) {
- this.time = Math.max( this.time, fields.time );
- }
- }, this );
-
-
-
-
-
-
-
-
- this.queue.sort( function( a, b ) {
- if ( a.time != b.time ) {
- return a.time - b.time;
- } else if ( a.origin != "reflector" && b.origin == "reflector" ) {
- return -1;
- } else if ( a.origin == "reflector" && b.origin != "reflector" ) {
- return 1;
- } else {
- return a.sequence - b.sequence;
- }
- } );
-
-
-
- if ( chronic ) {
- vwf.dispatch();
- }
- },
-
-
-
-
-
- pull: function() {
- if ( this.suspension == 0 && this.queue.length > 0 && this.queue[0].time <= this.time ) {
- return this.queue.shift();
- }
- },
-
-
-
-
-
-
-
-
- filter: function( callback /* fields */ ) {
- this.queue = this.queue.filter( callback );
- },
-
-
-
-
-
- suspend: function( why ) {
- if ( this.suspension++ == 0 ) {
- vwf.logger.infox( "-queue#suspend", "suspending queue at time", vwf.now, why ? why : "" );
- return true;
- } else {
- vwf.logger.debugx( "-queue#suspend", "further suspending queue at time", vwf.now, why ? why : "" );
- return false;
- }
- },
-
-
-
-
-
-
-
-
-
- resume: function( why ) {
- if ( --this.suspension == 0 ) {
- vwf.logger.infox( "-queue#resume", "resuming queue at time", vwf.now, why ? why : "" );
- vwf.dispatch();
- return true;
- } else {
- vwf.logger.debugx( "-queue#resume", "partially resuming queue at time", vwf.now, why ? why : "" );
- return false;
- }
- },
-
-
-
-
-
- ready: function() {
- return this.suspension == 0;
- },
-
-
-
-
- time: 0,
-
-
-
- suspension: 0,
-
-
-
-
- sequence: 0,
-
-
-
- queue: [],
- };
- };
- } ) ( window );
|