editor-new.js 193 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// vwf/view/editor creates a view interface for editor functions.
  15. ///
  16. /// @module vwf/view/editor
  17. /// @requires version
  18. /// @requires vwf/view
  19. /// @requires vwf/utility
  20. define([
  21. "module",
  22. "version",
  23. "vwf/view",
  24. "vwf/utility",
  25. "vwf/view/lib/ace/ace",
  26. "jquery",
  27. "jquery-ui",
  28. "jquery-encoder-0.1.0"
  29. ], function (module, version, view, utility, ace, $) {
  30. var self;
  31. return view.load(module, {
  32. // == Module Definition ====================================================================
  33. initialize: function () {
  34. self = this;
  35. this.ace = window.ace;
  36. this.nodes = {};
  37. this.scenes = {};
  38. this.allScripts = {};
  39. // EDITOR CLOSED --> 0
  40. // HIERARCHY OPEN --> 1
  41. // USER LIST OPEN --> 2
  42. // TIMELINE OPEN --> 3
  43. // ABOUT OPEN --> 4
  44. this.editorView = 0;
  45. this.editorOpen = false;
  46. this.timelineInit = false;
  47. this.aboutInit = false;
  48. this.codeEditorInit = false;
  49. this.modelsInit = false;
  50. this.editingScript = false;
  51. this.topdownName = '#topdown_a';
  52. this.topdownTemp = '#topdown_b';
  53. this.clientList = '#client_list';
  54. this.timeline = '#time_control';
  55. this.about = '#about_tab';
  56. this.codeEditor = '#codeEditor_tab';
  57. this.models = '#model_a';
  58. this.modelsTemp = '#model_b';
  59. this.currentNodeID = '';
  60. this.currentModelID = '';
  61. this.currentModelURL = '';
  62. this.highlightedChild = '';
  63. this.intervalTimer = 0;
  64. this.activeCameraID = undefined;
  65. $(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  66. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  67. $(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  68. // $('body').append('<script>mdc.autoInit()</script>');
  69. this.getRoot = function () {
  70. var app = window.location.pathname;
  71. var pathSplit = app.split('/');
  72. if (pathSplit[0] == "") {
  73. pathSplit.shift();
  74. }
  75. if (pathSplit[pathSplit.length - 1] == "") {
  76. pathSplit.pop();
  77. }
  78. var instIndex = pathSplit.length - 1;
  79. if (pathSplit.length > 2) {
  80. if (pathSplit[pathSplit.length - 2] == "load") {
  81. instIndex = pathSplit.length - 3;
  82. }
  83. }
  84. if (pathSplit.length > 3) {
  85. if (pathSplit[pathSplit.length - 3] == "load") {
  86. instIndex = pathSplit.length - 4;
  87. }
  88. }
  89. var root = "";
  90. for (var i = 0; i < instIndex; i++) {
  91. if (root != "") {
  92. root = root + "/";
  93. }
  94. root = root + pathSplit[i];
  95. }
  96. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  97. return root
  98. }
  99. $('body').append(
  100. "<div id='editor' class='relClass'>\n" +
  101. " <div class='uiContainer'>\n" +
  102. " <div class='editor-tabs' id='tabs'>\n" +
  103. " <img id='x' style='display:none' src='images/tab_X.png' alt='x' />\n" +
  104. " <img id='hierarchy' src='images/tab_Application.png' alt='application' />\n" +
  105. " <img id='userlist' src='images/tab_Users.png' alt='users' />\n" +
  106. " <img id='timeline' src='images/tab_Time.png' alt='time' />\n" +
  107. " <img id='models' src='images/tab_Models.png' alt='models' />\n" +
  108. " <img id='about' src='images/tab_About.png' alt='about' />\n" +
  109. " <img id='codeEditor' src='images/tab_CodeEditor.png' alt='code' />\n" +
  110. " </div>\n" +
  111. " </div>\n" +
  112. "</div>" +
  113. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='topdown_a'></div></div></div>" +
  114. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='topdown_b'></div></div></div>" +
  115. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='client_list'></div></div></div>" +
  116. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='time_control'></div></div></div>" +
  117. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='about_tab'></div></div></div>" +
  118. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='codeEditor_tab'></div></div></div>" +
  119. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='model_a'></div></div></div>" +
  120. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='model_b'></div></div></div>"
  121. );
  122. //style: "position: absolute; top: 0; left: 0; z-index: 2",
  123. // let draggie = new Draggabilly('.draggable');
  124. // let dragDiv = document.querySelector("#dragDiv").style.visibility = 'hidden';
  125. // let propDiv = document.createElement("div");
  126. // var newContent = document.createTextNode("Hi there and greetings!");
  127. // newDiv.appendChild(newContent); //add the text node to the newly created div.
  128. //<div id='drawer'></div><div id='toolbar'></div><div id='clientsList'></div>
  129. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow","viewSceneProps"].forEach(item => {
  130. let el = document.createElement("div");
  131. el.setAttribute("id", item);
  132. document.body.appendChild(el);
  133. }
  134. );
  135. function avatarCardDef(src, desc, onclickfunc) {
  136. return {
  137. $cell: true,
  138. $type: "div",
  139. class: "mdc-card avatar-card",
  140. $init: function () {
  141. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  142. },
  143. onclick: onclickfunc,
  144. $components: [
  145. {
  146. $type: "section",
  147. class: "mdc-card__primary",
  148. $components: [
  149. {
  150. $type: "h1",
  151. class: "mdc-card__title mdc-card__title--large",
  152. $text: desc.subtitle
  153. },
  154. {
  155. $type: "h2",
  156. class: "mdc-card__subtitle",
  157. $text: desc.title
  158. }
  159. ]
  160. },
  161. {
  162. $type: "section",
  163. class: "mdc-card__actions",
  164. $components: [
  165. {
  166. $type: "button",
  167. class: "mdc-button mdc-button--compact mdc-card__action",
  168. //$text: "Use it",
  169. onclick: onclickfunc
  170. }
  171. ]
  172. }
  173. ]
  174. }
  175. }
  176. let avatarSettings =
  177. {
  178. $cell: true,
  179. $type: "div",
  180. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  181. $components: [
  182. {
  183. $cell: true,
  184. $type: "div",
  185. class: "mdc-layout-grid__inner",
  186. $components: [
  187. {
  188. $cell: true,
  189. $type: "div",
  190. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  191. $components: [
  192. {
  193. $cell: true,
  194. $type: "button",
  195. class: "mdc-button mdc-button--raised",
  196. $text: "Reset camera view",
  197. onclick: function (e) {
  198. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  199. let controlEl = document.querySelector('#avatarControl');
  200. controlEl.setAttribute('camera', 'active', true);
  201. }
  202. },
  203. {
  204. $cell: true,
  205. $type: "button",
  206. class: "mdc-button mdc-button--raised",
  207. $text: "Hide cursor",
  208. onclick: function (e) {
  209. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  210. let avatarID = 'avatar-' + self.kernel.moniker();
  211. let cursorID = 'myCursor-' + avatarID;
  212. let controlEl = document.querySelector("[id='" + cursorID + "']");
  213. let vis = controlEl.getAttribute('visible');
  214. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  215. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  216. //controlEl.setAttribute('visible', !vis);
  217. }
  218. }
  219. ]
  220. },
  221. {
  222. $cell: true,
  223. $type: "div",
  224. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  225. $components: [
  226. {
  227. $type: "div",
  228. class: "mdc-layout-grid",
  229. $components: [
  230. {
  231. $type: "div",
  232. class: "mdc-layout-grid__inner",
  233. $components: [
  234. {
  235. $cell: true,
  236. $type: "div",
  237. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  238. $components: [
  239. avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  240. function (e) {
  241. let avatarID = 'avatar-' + self.kernel.moniker();
  242. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  243. }
  244. )
  245. ]
  246. },
  247. {
  248. $cell: true,
  249. $type: "div",
  250. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  251. $components: [
  252. avatarCardDef("/../assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  253. function (e) {
  254. let avatarID = 'avatar-' + self.kernel.moniker();
  255. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  256. }
  257. )]
  258. },
  259. {
  260. $cell: true,
  261. $type: "div",
  262. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  263. $components: [
  264. avatarCardDef("/../assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  265. function (e) {
  266. let avatarID = 'avatar-' + self.kernel.moniker();
  267. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  268. }
  269. )]
  270. }
  271. ]
  272. }
  273. ]
  274. },
  275. // {
  276. // $cell: true,
  277. // $type: "button",
  278. // class: "mdc-button mdc-button--raised",
  279. // $text: "Simple Avatar",
  280. // onclick: function (e) {
  281. // let avatarID = 'avatar-' + self.kernel.moniker();
  282. // vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  283. // }
  284. // },
  285. // {
  286. // $cell: true,
  287. // $type: "button",
  288. // class: "mdc-button mdc-button--raised",
  289. // $text: "Male Avatar",
  290. // onclick: function (e) {
  291. // let avatarID = 'avatar-' + self.kernel.moniker();
  292. // vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  293. // }
  294. // },
  295. // {
  296. // $cell: true,
  297. // $type: "button",
  298. // class: "mdc-button mdc-button--raised",
  299. // $text: "Female Avatar",
  300. // onclick: function (e) {
  301. // let avatarID = 'avatar-' + self.kernel.moniker();
  302. // vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  303. // }
  304. // },
  305. ]
  306. }
  307. ]
  308. }
  309. ]
  310. }
  311. let viewSettings =
  312. {
  313. $cell: true,
  314. $type: "div",
  315. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  316. $components: [
  317. {
  318. $cell: true,
  319. $type: "div",
  320. class: "mdc-layout-grid__inner",
  321. $components: [
  322. {
  323. $cell: true,
  324. $type: "div",
  325. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  326. $components: [
  327. {
  328. $cell: true,
  329. $type: "button",
  330. class: "mdc-button mdc-button--raised",
  331. $text: "Settings",
  332. onclick: function (e) {
  333. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  334. }
  335. }
  336. ]
  337. }
  338. ]
  339. }
  340. ]
  341. }
  342. let savedStateEl = function (item) {
  343. return {
  344. $type: "li",
  345. class: "mdc-list-item",
  346. role: "option",
  347. $components: [
  348. {
  349. $text: "Saved world"
  350. }
  351. ]
  352. }
  353. }
  354. let stateListElement = function (item) {
  355. let liEl = {
  356. $type: "li",
  357. class: "mdc-list-item",
  358. role: "option",
  359. id: "",
  360. applicationpath: "",
  361. $components: [
  362. {
  363. $text: "no saves"
  364. }
  365. ]
  366. }
  367. let applicationName = item.applicationpath.split("/");
  368. if (applicationName == "") {
  369. return liEl
  370. }
  371. if (applicationName.length > 0) {
  372. applicationName = applicationName[applicationName.length - 1];
  373. }
  374. if (applicationName.length > 0) {
  375. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  376. }
  377. if (item.latestsave) {
  378. liEl = {
  379. $type: "li",
  380. class: "mdc-list-item",
  381. role: "option",
  382. id: item.savename,
  383. applicationpath: item.applicationpath,
  384. $components: [
  385. {
  386. $text: applicationName + ": " + item.savename
  387. }
  388. ]
  389. }
  390. }
  391. else {
  392. liEl = {
  393. $type: "li",
  394. class: "mdc-list-item",
  395. role: "option",
  396. id: item.savename,
  397. revision: item.revision,
  398. applicationpath: item.applicationpath,
  399. $components: [
  400. {
  401. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  402. }
  403. ]
  404. }
  405. }
  406. return liEl
  407. }
  408. let loadSaveSettings =
  409. {
  410. $cell: true,
  411. $type: "div",
  412. id: "loadSaveSettings",
  413. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  414. _saveStates: [],
  415. _getStates: async function () {
  416. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  417. let data = await response.json();
  418. //this._saveStates = data;
  419. //let appName = self.getRoot();
  420. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  421. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  422. if (filterData.length !== 0) {
  423. this._saveStates = filterData
  424. //return filterData
  425. } else {
  426. this._saveStates = [{
  427. savename: "",
  428. latestsave: "",
  429. revision: "",
  430. applicationpath: "",
  431. url: ""
  432. }]
  433. }
  434. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  435. //return data
  436. //console.log(data);
  437. return this._saveStates
  438. },
  439. $init: function () {
  440. this._getStates();
  441. },
  442. $update: function () {
  443. this.$components =
  444. [
  445. {
  446. $cell: true,
  447. $type: "div",
  448. class: "mdc-layout-grid__inner",
  449. $components: [
  450. {
  451. $cell: true,
  452. $type: "div",
  453. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  454. $components: [
  455. {
  456. class: "mdc-textfield",
  457. $cell: true,
  458. $type: "span",
  459. $components: [
  460. {
  461. class: "mdc-textfield__input",
  462. id: "fileName",
  463. $cell: true,
  464. $type: "input",
  465. type: "text",
  466. value: self.getRoot()
  467. }]
  468. }
  469. ]
  470. },
  471. {
  472. $cell: true,
  473. $type: "div",
  474. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  475. $components: [
  476. {
  477. $cell: true,
  478. $type: "button",
  479. class: "mdc-button mdc-button--raised",
  480. $text: "Save",
  481. onclick: function (e) {
  482. let fileName = document.querySelector('#fileName')
  483. saveStateAsFile.call(self, fileName.value);
  484. document.querySelector("#fileName").value = '';
  485. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  486. }
  487. }
  488. ]
  489. },
  490. {
  491. $cell: true,
  492. $type: "div",
  493. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  494. $components: [
  495. {
  496. $cell: true,
  497. $type: "div",
  498. class: "mdc-select",
  499. $init: function () {
  500. var MDCSelect = mdc.select.MDCSelect;
  501. const select = new MDCSelect(document.querySelector('.mdc-select'));
  502. select.listen('MDCSelect:change', () => {
  503. //this._selectedState = select.value;
  504. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  505. //console.log(select.value);
  506. //.selectedOptions[0]
  507. });
  508. },
  509. role: "listbox",
  510. $components: [
  511. {
  512. $type: "span",
  513. class: "mdc-select__selected-text",
  514. $text: "Select saved state"
  515. },
  516. {
  517. $type: "div",
  518. class: "mdc-simple-menu mdc-select__menu",
  519. $components: [
  520. {
  521. $type: "ul",
  522. class: "mdc-list mdc-simple-menu__items",
  523. $components: this._saveStates.map(stateListElement)
  524. }
  525. ]
  526. }
  527. ]
  528. }
  529. ]
  530. },
  531. {
  532. $cell: true,
  533. $type: "div",
  534. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  535. $components: [
  536. {
  537. $cell: true,
  538. $type: "button",
  539. _selectedState: {},
  540. id: "loadStateButton",
  541. class: "mdc-button mdc-button--raised",
  542. $text: "Load",
  543. onclick: function (e) {
  544. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  545. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  546. }
  547. }
  548. ]
  549. }
  550. ]
  551. }
  552. ]
  553. }
  554. }
  555. // document.querySelector('#' + 'viewSettings').$cell({
  556. // $cell: true,
  557. // $type: "div",
  558. // id: 'viewSettings',
  559. // //style:'z-index: 10; position: absolute; margin-left: 240px;',
  560. // class: "settingsDiv mdc-toolbar-fixed-adjust",
  561. // $init: function(){
  562. // this.style.visibility = 'hidden';
  563. // },
  564. // $components: [viewSettings]
  565. // })
  566. // document.querySelector('#' + 'viewSettings').$cell({
  567. // $cell: true,
  568. // $type: "div",
  569. // id: 'viewSettings',
  570. // style:'z-index: 10; position: absolute; margin-left: 240px;',
  571. // class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left mdc-toolbar-fixed-adjust",
  572. // $init: function(){
  573. // this.style.visibility = 'hidden';
  574. // },
  575. // $components: [viewSettings]
  576. // })
  577. let protoPropertiesCell = function (m) {
  578. return {
  579. $type: "div",
  580. class: "mdc-layout-grid__inner",
  581. _prop: {},
  582. $init: function () {
  583. let prop = m[1].prop;
  584. if (prop.value == undefined) {
  585. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  586. }
  587. this._prop = prop
  588. },
  589. $update: function () {
  590. this.$components = [
  591. {
  592. $type: "div",
  593. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  594. $components: [
  595. { $text: this._prop.name }
  596. ]
  597. },
  598. {
  599. $type: "div",
  600. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  601. },
  602. {
  603. $type: "div",
  604. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  605. $components: [
  606. {
  607. class: "mdc-textfield",
  608. $cell: true,
  609. $type: "div",
  610. $components: [{
  611. class: "mdc-textfield__input",
  612. $cell: true,
  613. $type: "input",
  614. type: "text",
  615. value: this._prop.value,
  616. onchange: function (e) {
  617. let propValue = this.value;
  618. try {
  619. propValue = JSON.parse(propValue);
  620. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  621. } catch (e) {
  622. // restore the original value on error
  623. this.value = propValue;
  624. }
  625. }
  626. }]
  627. }
  628. ]
  629. }
  630. ]
  631. }
  632. }
  633. }
  634. let propertiesCell = function (m) {
  635. var editComponents = [{},{}]
  636. if (m.name.indexOf("semantics") > -1) { }
  637. else if (m.name.indexOf("grammar") > -1) { }
  638. else if (m.name.indexOf("ohm") > -1) {
  639. editComponents = [
  640. {
  641. $type: "div",
  642. $cell: true,
  643. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  644. $components: [
  645. {
  646. $cell: true,
  647. $type: "button",
  648. class: "mdc-button",
  649. $text: "Edit", //edit grammar
  650. onclick: function (e) {
  651. var currentNode = document.querySelector('#currentNode')._currentNode;
  652. if (currentNode == '') {
  653. currentNode = vwf_view.kernel.find("", "/")[0];
  654. }
  655. let editor = document.querySelector('#livePropEditor');
  656. editor._setNode(currentNode);
  657. editor._propName = m.name;
  658. editor._prop = {body: m.rawValue, type: 'complex' }
  659. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  660. }
  661. }
  662. ]
  663. },
  664. {
  665. $type: "div",
  666. $cell: true,
  667. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  668. $components: []
  669. }
  670. ]
  671. } else {
  672. editComponents = [
  673. {
  674. $type: "div",
  675. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  676. $components: [
  677. {
  678. class: "mdc-textfield",
  679. $cell: true,
  680. $type: "span",
  681. $components: [
  682. {
  683. class: "mdc-textfield__input",
  684. id: "prop-" + m.name,
  685. $cell: true,
  686. $type: "input",
  687. type: "text",
  688. value: m.getValue(),
  689. onchange: function (e) {
  690. let propValue = this.value;
  691. try {
  692. propValue = JSON.parse(propValue);
  693. self.kernel.setProperty(this._currentNode, m.name, propValue);
  694. } catch (e) {
  695. // restore the original value on error
  696. this.value = propValue;
  697. }
  698. }
  699. }
  700. ]
  701. }
  702. ]
  703. },
  704. {
  705. $type: "div",
  706. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  707. $components: [
  708. {
  709. $cell: true,
  710. $type: "button",
  711. class: "mdc-button",
  712. $text: "^", //edit grammar
  713. onclick: function (e) {
  714. var currentNode = document.querySelector('#currentNode')._currentNode;
  715. if (currentNode == '') {
  716. currentNode = vwf_view.kernel.find("", "/")[0];
  717. }
  718. let editor = document.querySelector('#livePropEditor');
  719. editor._setNode(currentNode);
  720. editor._propName = m.name;
  721. editor._prop = {body: m.getValue(), type: 'simple' }
  722. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  723. }
  724. }
  725. ]
  726. }
  727. ];
  728. }
  729. return {
  730. $type: "div",
  731. class: "mdc-layout-grid__inner",
  732. $components: [
  733. {
  734. $type: "div",
  735. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  736. $components: [
  737. { $text: m.name }
  738. ]
  739. },
  740. {
  741. $type: "div",
  742. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  743. },
  744. editComponents[0],
  745. editComponents[1]
  746. ]
  747. }
  748. }
  749. let nodeLink = function (m) {
  750. var myClass = "nodeItem";
  751. let myAvatarName = 'avatar-' + self.kernel.moniker();
  752. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  753. myClass = "nodeItem"
  754. return {
  755. $type: "li",
  756. class: "mdc-list-item",
  757. $components: [{
  758. $type: "a",
  759. class: "mdc-list-item",
  760. $href: "#",
  761. $components: [{
  762. $type: 'span',
  763. class: myClass,
  764. $text: m.name
  765. }
  766. ],
  767. onclick: function (e) {
  768. //self.currentNodeID = m.ID;
  769. document.querySelector('#currentNode')._setNode(m.ID);
  770. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  771. // createAceEditor(self, m.ID);
  772. }
  773. }]
  774. }
  775. };
  776. let listDivider = {
  777. $cell: true,
  778. $type: "hr",
  779. class: "mdc-list-divider",
  780. }
  781. let nodesCell = {
  782. $cell: true,
  783. $type: "div",
  784. id: "currentNode",
  785. _childNodes: [],
  786. _currentNode: '',
  787. _displayedProperties: {},
  788. _setNode: function (aNode) {
  789. this._currentNode = aNode;
  790. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  791. },
  792. $init: function () {
  793. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  794. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  795. //this._currentNode = '3333';
  796. },
  797. _getChildNodes: function () {
  798. this._childNodes = self.nodes[this._currentNode];
  799. if (this._childNodes !== undefined) {
  800. return this._childNodes.children
  801. } else {
  802. return []
  803. }
  804. //let nodeIDAlpha = he.encode(this._currentNode);
  805. },
  806. // _getNodeComplexProperties: function () {
  807. // let node = self.nodes[this._currentNode];
  808. // let props = this._getNodeProperties();
  809. // let filterFunction = function (prop) {
  810. // return (prop.name == 'ohmLang')
  811. // };
  812. // let complexProps = props.filter(filterFunction.bind(this));
  813. // return complexProps
  814. // },
  815. _getNodeProperties: function () {
  816. let node = self.nodes[this._currentNode];
  817. this._displayedProperties = {};
  818. let filterFunction = function (prop) {
  819. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  820. };
  821. let props = node.properties.filter(filterFunction.bind(this));
  822. return props
  823. },
  824. _getNodeProtoProperties: function () {
  825. let node = self.nodes[this._currentNode];
  826. let filterFunction = function (prop) {
  827. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  828. };
  829. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  830. return props
  831. },
  832. $update: function () {
  833. //this.$text = this._currentNode;
  834. var viewerProps = {};
  835. var viewerPropsCell = {};
  836. let node = self.nodes[this._currentNode];
  837. if (node !== undefined) {
  838. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  839. viewerProps = {
  840. $type: "li",
  841. class: "mdc-list-item",
  842. $components: [
  843. {
  844. $text: "Viewer properties",
  845. $type: "span",
  846. class: "mdc-list-item__text mdc-typography--button"
  847. }
  848. ]
  849. }
  850. viewerPropsCell = {
  851. $cell: true,
  852. $type: "div",
  853. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  854. $components: [
  855. {
  856. $cell: true,
  857. $type: "div",
  858. class: "mdc-layout-grid__inner",
  859. $components: [
  860. {
  861. $cell: true,
  862. $type: "div",
  863. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  864. $components: [
  865. {
  866. $cell: true,
  867. $type: "button",
  868. class: "mdc-button mdc-button--raised",
  869. $text: "Active",
  870. onclick: function (e) {
  871. let camera = document.querySelector('#' + this._currentNode);
  872. camera.setAttribute('active', true);
  873. }
  874. }
  875. ]
  876. }
  877. ]
  878. }
  879. ]
  880. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  881. }
  882. } else {
  883. viewerProps = {};
  884. viewerPropsCell = {};
  885. }
  886. }
  887. this.$components = [
  888. {
  889. $cell: true,
  890. $type: "ul",
  891. class: "mdc-list",
  892. $components: [
  893. {
  894. $cell: true,
  895. $type: "button",
  896. class: "mdc-list-item mdc-button mdc-button--raised",
  897. $text: "<--",
  898. onclick: function (e) {
  899. let node = self.nodes[this._currentNode];
  900. if (node.parentID !== 0) {
  901. //self.currentNodeID = node.parentID,
  902. document.querySelector('#currentNode')._setNode(node.parentID)
  903. }
  904. }
  905. },
  906. {
  907. $type: "li",
  908. class: "mdc-list-item",
  909. $components: [
  910. {
  911. $text: "name",
  912. $type: "span",
  913. $init: function () {
  914. let node = self.nodes[this._currentNode];
  915. this.$text = node.name
  916. },
  917. class: "mdc-list-item__text mdc-typography--headline"
  918. //<h1 class="mdc-typography--display4">Big header</h1>
  919. }]
  920. }, listDivider,
  921. {
  922. // $cell: true,
  923. // $type: "ul",
  924. // class: "mdc-list",
  925. $type: "div",
  926. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  927. $components: [
  928. {
  929. $type: "div",
  930. class: "mdc-layout-grid__inner",
  931. $components: [
  932. {
  933. $type: "div",
  934. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  935. $components: [
  936. {
  937. $cell: true,
  938. $type: "button",
  939. class: "mdc-button mdc-button--raised",
  940. $text: "Open in code editor",
  941. onclick: function (e) {
  942. var currentNode = document.querySelector('#currentNode')._currentNode;
  943. if (currentNode == '') {
  944. currentNode = vwf_view.kernel.find("", "/")[0];
  945. }
  946. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  947. //createAceEditor(self, currentNode);
  948. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  949. }
  950. }
  951. ]
  952. }
  953. ]
  954. }
  955. ]
  956. },
  957. listDivider,
  958. {
  959. $type: "li",
  960. class: "mdc-list-item",
  961. $components: [
  962. {
  963. $text: "Children",
  964. $type: "span",
  965. class: "mdc-list-item__text mdc-typography--button"
  966. }]
  967. },
  968. {
  969. $cell: true,
  970. $type: "ul",
  971. class: "mdc-list",
  972. $components: this._getChildNodes().map(nodeLink)
  973. }, listDivider, {
  974. $type: "li",
  975. class: "mdc-list-item",
  976. $components: [
  977. {
  978. $text: "Properties",
  979. $type: "span",
  980. class: "mdc-list-item__text mdc-typography--button"
  981. //<h1 class="mdc-typography--display4">Big header</h1>
  982. }]
  983. },
  984. {
  985. // $cell: true,
  986. // $type: "ul",
  987. // class: "mdc-list",
  988. $type: "div",
  989. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  990. $components: this._getNodeProperties().map(propertiesCell)
  991. },
  992. listDivider,
  993. {
  994. $type: "li",
  995. class: "mdc-list-item",
  996. $components: [
  997. {
  998. $text: "Proto properties",
  999. $type: "span",
  1000. class: "mdc-list-item__text mdc-typography--button"
  1001. }]
  1002. },
  1003. {
  1004. $cell: true,
  1005. $type: "div",
  1006. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1007. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1008. }, listDivider,
  1009. viewerProps,
  1010. viewerPropsCell
  1011. ]
  1012. }
  1013. ]
  1014. }
  1015. }
  1016. let propEditorWindow = {
  1017. $cell: true,
  1018. $type: "div",
  1019. _editorNode: '',
  1020. _prop: { body: '', type: 'simple'},
  1021. _propName: '',
  1022. id: "livePropEditor",
  1023. _setNode: function (node) {
  1024. this._editorNode = node;
  1025. this._prop.body = ''
  1026. },
  1027. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1028. $update: function () {
  1029. this.$components = [
  1030. {
  1031. $cell: true,
  1032. $type: "div",
  1033. class: "mdc-layout-grid__inner",
  1034. $components: [
  1035. {
  1036. $cell: true,
  1037. $type: "div",
  1038. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1039. $components: [
  1040. {
  1041. $cell: true,
  1042. $type: "button",
  1043. class: "mdc-button mdc-button--raised",
  1044. $text: "Update",
  1045. onclick: function (e) {
  1046. let editor = document.querySelector("#propAceEditor").env.editor;
  1047. let value = editor.getValue();
  1048. try {
  1049. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)): (value)
  1050. //propValue = JSON.parse(value);
  1051. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  1052. } catch (e) {
  1053. // restore the original value on error
  1054. this.value = propValue;
  1055. }
  1056. }
  1057. }]
  1058. },
  1059. {
  1060. $cell: true,
  1061. $type: "div",
  1062. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1063. $components: [
  1064. {
  1065. $type: "h3",
  1066. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1067. $text: this._editorNode
  1068. }
  1069. ]
  1070. },
  1071. {
  1072. $cell: true,
  1073. $type: "div",
  1074. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1075. $components: [
  1076. {
  1077. $type: "h3",
  1078. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1079. $text: this._propName
  1080. }
  1081. ]
  1082. }
  1083. ]
  1084. },
  1085. {
  1086. $cell: true,
  1087. $type: "div",
  1088. class: "mdc-layout-grid__inner",
  1089. $components: [
  1090. {
  1091. $cell: true,
  1092. $type: "div",
  1093. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1094. $components: [
  1095. {
  1096. $cell: true,
  1097. class: "aceEditor",
  1098. id: "propAceEditor",
  1099. $type: "div",
  1100. $text: this._prop.body,
  1101. $init: function () {
  1102. createAceEditor(self, this._editorNode, "propAceEditor");
  1103. }
  1104. }
  1105. ]
  1106. }
  1107. ]
  1108. }
  1109. ]
  1110. //$components:
  1111. }
  1112. }
  1113. let codeEditorWindow = {
  1114. $cell: true,
  1115. $type: "div",
  1116. _editorNode: '',
  1117. _method: { body: '' },
  1118. _methodName: '',
  1119. _getNodeMethods: function () {
  1120. let node = self.nodes[this._editorNode];
  1121. return node.methods
  1122. },
  1123. _getProtoNodeMethods: function () {
  1124. let node = self.nodes[this._editorNode];
  1125. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  1126. return prototypeMethods
  1127. },
  1128. id: "liveCodeEditor",
  1129. _setNode: function (node) {
  1130. this._editorNode = node;
  1131. this._method.body = ''
  1132. },
  1133. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1134. // _getComplexProps: function(){
  1135. // let node = self.nodes[this._editorNode];
  1136. // let currentNode = document.querySelector('#currentNode');
  1137. // var props = {}
  1138. // if (currentNode !== null) {
  1139. // props = currentNode._getNodeComplexProperties();
  1140. // }
  1141. // return props
  1142. // },
  1143. // _listPropertyElement: function (m) {
  1144. // return {
  1145. // $type: "li",
  1146. // class: "mdc-list-item",
  1147. // $components: [{
  1148. // $type: "a",
  1149. // class: "mdc-list-item",
  1150. // $href: "#",
  1151. // $text: m[1].name,
  1152. // onclick: function (e) {
  1153. // this._method = {};
  1154. // this._methodName = m[1].name;
  1155. // this._method.body = m[1].rawValue
  1156. // this._method.type = "complexProperty"
  1157. // }
  1158. // }]
  1159. // }
  1160. // },
  1161. _listElement: function (m) {
  1162. return {
  1163. $type: "li",
  1164. class: "mdc-list-item",
  1165. $components: [{
  1166. $type: "a",
  1167. class: "mdc-list-item",
  1168. $href: "#",
  1169. $text: m[0],
  1170. onclick: function (e) {
  1171. let method = vwf.getMethod(this._editorNode, m[0]);
  1172. //document.querySelector('#aceEditor').
  1173. this._method = method;
  1174. this._methodName = m[0];
  1175. //self.currentNodeID = m.ID;
  1176. //document.querySelector('#currentNode')._setNode(m.ID);
  1177. }
  1178. }]
  1179. }
  1180. },
  1181. $update: function () {
  1182. this.$components = [
  1183. {
  1184. $cell: true,
  1185. $type: "div",
  1186. class: "mdc-layout-grid__inner",
  1187. $components: [
  1188. {
  1189. $cell: true,
  1190. $type: "div",
  1191. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1192. $components: [
  1193. {
  1194. $type: "h3",
  1195. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1196. $text: this._editorNode
  1197. }
  1198. ]
  1199. },
  1200. {
  1201. $cell: true,
  1202. $type: "div",
  1203. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1204. $components: [
  1205. {
  1206. $cell: true,
  1207. $type: "button",
  1208. class: "mdc-button mdc-button--raised",
  1209. $text: "Update",
  1210. onclick: function (e) {
  1211. let editor = document.querySelector("#aceEditor").env.editor;
  1212. let evalText = editor.getValue();
  1213. // if (this._method.type == 'complexProperty') {
  1214. // let propValue = evalText;
  1215. // try {
  1216. // //propValue = JSON.parse(propValue);
  1217. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  1218. // } catch (e) {
  1219. // // restore the original value on error
  1220. // this.value = propValue;
  1221. // }
  1222. // } else {
  1223. // }
  1224. self.kernel.setMethod(this._editorNode, this._methodName,
  1225. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  1226. }
  1227. }]
  1228. },
  1229. {
  1230. $cell: true,
  1231. $type: "div",
  1232. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1233. $components: [
  1234. {
  1235. $cell: true,
  1236. $type: "button",
  1237. class: "mdc-button mdc-button--raised",
  1238. $text: "Call",
  1239. onclick: function (e) {
  1240. let params = [];
  1241. if (this._method.parameters) {
  1242. params = this._method.parameters.length
  1243. };
  1244. if (params >= 1) { }
  1245. self.kernel.callMethod(this._editorNode, this._methodName, this._method.parameters);
  1246. }
  1247. }]
  1248. },
  1249. {
  1250. $cell: true,
  1251. $type: "div",
  1252. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1253. $components: [
  1254. {
  1255. $cell: true,
  1256. $type: "button",
  1257. class: "mdc-button mdc-button--raised",
  1258. $text: "Do It",
  1259. onclick: function (e) {
  1260. let editor = document.querySelector("#aceEditor").env.editor;
  1261. codeEditorDoit.call(self, editor, this._editorNode);
  1262. }
  1263. }]
  1264. },
  1265. {
  1266. $cell: true,
  1267. $type: "div",
  1268. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1269. $components: [
  1270. {
  1271. $cell: true,
  1272. $type: "button",
  1273. class: "mdc-button mdc-button--raised",
  1274. $text: "Print It",
  1275. onclick: function (e) {
  1276. let editor = document.querySelector("#aceEditor").env.editor;
  1277. codeEditorPrintit.call(self, editor, this._editorNode);
  1278. }
  1279. }]
  1280. }
  1281. ]
  1282. },
  1283. {
  1284. $cell: true,
  1285. $type: "div",
  1286. class: "mdc-layout-grid__inner",
  1287. $components: [
  1288. {
  1289. $cell: true,
  1290. $type: "div",
  1291. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1292. style: "overflow-y: scroll; max-height: 400px;",
  1293. $components: [
  1294. {
  1295. $cell: true,
  1296. $type: "div",
  1297. class: "mdc-list-group",
  1298. $components: [
  1299. {
  1300. $type: "h3",
  1301. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1302. $text: "Node methods"
  1303. },
  1304. {
  1305. $cell: true,
  1306. $type: "ul",
  1307. class: "mdc-list",
  1308. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  1309. }, listDivider,
  1310. {
  1311. $type: "h3",
  1312. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1313. $text: "Proto methods"
  1314. },
  1315. {
  1316. $cell: true,
  1317. $type: "ul",
  1318. class: "mdc-list",
  1319. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  1320. },listDivider,
  1321. {
  1322. $type: "h3",
  1323. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1324. $text: "Events"
  1325. }
  1326. // {
  1327. // $cell: true,
  1328. // $type: "ul",
  1329. // class: "mdc-list",
  1330. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  1331. // }
  1332. ]
  1333. }
  1334. ]
  1335. },
  1336. {
  1337. $cell: true,
  1338. $type: "div",
  1339. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  1340. $components: [
  1341. {
  1342. $cell: true,
  1343. class: "aceEditor",
  1344. id: "aceEditor",
  1345. $type: "div",
  1346. $text: this._method.body,
  1347. $init: function () {
  1348. createAceEditor(self, this._editorNode, "aceEditor");
  1349. }
  1350. }
  1351. ]
  1352. }
  1353. ]
  1354. }
  1355. ]
  1356. //$components:
  1357. }
  1358. }
  1359. let propWindow = {
  1360. $cell: true,
  1361. $type: "div",
  1362. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1363. style: "overflow-y: scroll; max-height: 800px;",
  1364. $components: [
  1365. {
  1366. $type: "div",
  1367. class: "mdc-layout-grid__inner",
  1368. $components: [
  1369. {
  1370. $cell: true,
  1371. $type: "div",
  1372. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1373. $components: [
  1374. nodesCell
  1375. ]
  1376. }
  1377. ]
  1378. }
  1379. // <button class="mdc-button">
  1380. // Flat button
  1381. // </button>
  1382. ]
  1383. }
  1384. let clientListCell = {
  1385. $cell: true,
  1386. $type: "div",
  1387. class: "mdc-list",
  1388. id: "clientsList",
  1389. _watchNodes: [],
  1390. _listElement: function (m) {
  1391. return {
  1392. $type: "a",
  1393. class: "mdc-list-item",
  1394. $href: "#",
  1395. $text: m.name,
  1396. onclick: function (e) {
  1397. //self.currentNodeID = m.ID;
  1398. //document.querySelector('#currentNode')._setNode(m.ID);
  1399. }
  1400. }
  1401. },
  1402. $init: function () {
  1403. var t = this;
  1404. setInterval(function () {
  1405. t._updateMe();
  1406. }, 1000);
  1407. },
  1408. _updateMe: function () {
  1409. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  1410. },
  1411. $update: function () {
  1412. //this._clientNodes
  1413. this.$components = this._watchNodes.map(this._listElement)
  1414. }
  1415. }
  1416. //createCellWindow("clientsWindow", clientListCell, "Clients");
  1417. //createCellWindow("propWindow", propWindow, "Scene");
  1418. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  1419. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  1420. let viewSceneProps = {
  1421. $cell: true,
  1422. $type: "div",
  1423. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  1424. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  1425. $components: [
  1426. {
  1427. $type: "div",
  1428. class: "mdc-layout-grid__inner",
  1429. $components: [
  1430. {
  1431. $cell: true,
  1432. $type: "div",
  1433. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1434. $components: [
  1435. nodesCell
  1436. ]
  1437. }
  1438. ]
  1439. }
  1440. ]
  1441. }
  1442. let sideBar = {
  1443. $cell: true,
  1444. $type: "div",
  1445. id: 'sideBar',
  1446. class: "sideBar mdc-toolbar-fixed-adjust",
  1447. _sideBarComponent: {},
  1448. _sideCurrentNode: '',
  1449. $init: function () {
  1450. this.style.visibility = 'hidden';
  1451. },
  1452. $update: function () {
  1453. this.$components = [
  1454. {
  1455. $cell: true,
  1456. $type: "button",
  1457. class: "mdc-button mdc-button--compact",
  1458. $text: "X",
  1459. onclick: function (e) {
  1460. document.querySelector('#sideBar').style.visibility = 'hidden';
  1461. }
  1462. },
  1463. this._sideBarComponent
  1464. ]
  1465. }
  1466. //$components: [this._sideComponents]
  1467. }
  1468. document.querySelector('#' + 'sideBar').$cell(sideBar)
  1469. let drawerCell = {
  1470. $cell: true,
  1471. $type: "nav",
  1472. class: "mdc-temporary-drawer__drawer",
  1473. $components: [
  1474. {
  1475. $cell: true,
  1476. $type: "header",
  1477. class: "mdc-temporary-drawer__header",
  1478. $components: [
  1479. {
  1480. $cell: true,
  1481. $type: "div",
  1482. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  1483. $text: "Home"
  1484. }
  1485. ]
  1486. },
  1487. {
  1488. $cell: true,
  1489. $type: "nav",
  1490. class: "mdc-temporary-drawer__content mdc-list-group",
  1491. $components: [
  1492. {
  1493. $cell: true,
  1494. $type: "div",
  1495. class: "mdc-list",
  1496. $components: [
  1497. {
  1498. $cell: true,
  1499. $type: "a",
  1500. class: "mdc-list-item",
  1501. $href: "#",
  1502. onclick: function (e) {
  1503. let sideBar = document.querySelector('#sideBar');
  1504. sideBar._sideBarComponent = viewSceneProps;
  1505. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  1506. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  1507. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  1508. document.querySelector('#sideBar').style.visibility = 'visible';
  1509. drawer.open = !drawer.open
  1510. // let currentNode = document.querySelector('#currentNode')._currentNode;
  1511. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  1512. // document.querySelector('#currentNode')._setNode(currentNode);
  1513. },
  1514. $components: [{
  1515. $cell: true,
  1516. $type: "i",
  1517. class: "material-icons mdc-list-item__start-detail",
  1518. $text: "description"
  1519. },
  1520. {
  1521. $text: "Scene"
  1522. }
  1523. ]
  1524. },
  1525. {
  1526. $cell: true,
  1527. $type: "a",
  1528. class: "mdc-list-item",
  1529. $href: "#",
  1530. onclick: function (e) {
  1531. //self.currentNodeID = m.ID;
  1532. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  1533. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  1534. let sideBar = document.querySelector('#sideBar');
  1535. sideBar._sideBarComponent = avatarSettings;
  1536. drawer.open = !drawer.open
  1537. document.querySelector('#sideBar').style.visibility = 'visible';
  1538. },
  1539. $components: [{
  1540. $type: "i",
  1541. class: "material-icons mdc-list-item__start-detail",
  1542. 'aria-hidden': "true",
  1543. $text: "account_circle"
  1544. },
  1545. {
  1546. $text: "My Avatar"
  1547. }]
  1548. },
  1549. {
  1550. $cell: true,
  1551. $type: "a",
  1552. class: "mdc-list-item",
  1553. $href: "#",
  1554. onclick: function (e) {
  1555. //self.currentNodeID = m.ID;
  1556. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  1557. let sideBar = document.querySelector('#sideBar');
  1558. sideBar._sideBarComponent = viewSettings;
  1559. drawer.open = !drawer.open
  1560. document.querySelector('#sideBar').style.visibility = 'visible';
  1561. },
  1562. $components: [{
  1563. $type: "i",
  1564. class: "material-icons mdc-list-item__start-detail",
  1565. 'aria-hidden': "true",
  1566. $text: "settings"
  1567. },
  1568. {
  1569. $text: "Settings"
  1570. }]
  1571. },
  1572. {
  1573. $cell: true,
  1574. $type: "a",
  1575. class: "mdc-list-item",
  1576. $href: "#",
  1577. onclick: function (e) {
  1578. //self.currentNodeID = m.ID;
  1579. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  1580. let sideBar = document.querySelector('#sideBar');
  1581. sideBar._sideBarComponent = loadSaveSettings;
  1582. if (document.querySelector('#loadSaveSettings')) {
  1583. document.querySelector('#loadSaveSettings')._getStates();
  1584. }
  1585. //sideBar._sideBarComponent._getStates();
  1586. drawer.open = !drawer.open
  1587. document.querySelector('#sideBar').style.visibility = 'visible';
  1588. },
  1589. $components: [{
  1590. $type: "i",
  1591. class: "material-icons mdc-list-item__start-detail",
  1592. 'aria-hidden': "true",
  1593. $text: "save"
  1594. },
  1595. {
  1596. $text: "Load/Save"
  1597. }]
  1598. },
  1599. {
  1600. $cell: true,
  1601. $type: "a",
  1602. class: "mdc-list-item",
  1603. $href: "#",
  1604. onclick: function (e) {
  1605. // var currentNode = document.querySelector('#currentNode')._currentNode;
  1606. // if (currentNode == '') {
  1607. // currentNode = vwf_view.kernel.find("", "/")[0];
  1608. // }
  1609. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  1610. //createAceEditor(self, currentNode);
  1611. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1612. },
  1613. $components: [{
  1614. $type: "i",
  1615. class: "material-icons mdc-list-item__start-detail",
  1616. 'aria-hidden': "true",
  1617. $text: "code"
  1618. },
  1619. {
  1620. $text: "Code editor"
  1621. }]
  1622. }
  1623. ]
  1624. },
  1625. {
  1626. $cell: true,
  1627. $type: "hr",
  1628. class: "mdc-list-divider",
  1629. },
  1630. {
  1631. $cell: true,
  1632. $type: "h3",
  1633. class: "userList mdc-list-group__subheader",
  1634. $text: "Users online"
  1635. },
  1636. clientListCell
  1637. ]
  1638. }
  1639. // {
  1640. // $cell: true,
  1641. // $type: "div",
  1642. // class: "mdc-persistent-drawer__toolbar-spacer",
  1643. // },
  1644. // {
  1645. // $cell: true,
  1646. // $type: "div",
  1647. // class: "mdc-list-group",
  1648. // $components: [{
  1649. // $cell: true,
  1650. // $type: "nav",
  1651. // class: "mdc-list",
  1652. // $components: [
  1653. // ]
  1654. // }]
  1655. // }
  1656. ]
  1657. };
  1658. // <div class="mdc-form-field">
  1659. // <input type="checkbox" id="input">
  1660. // <label for="input">Input Label</label>
  1661. // </div>
  1662. document.querySelector("#drawer").$cell({
  1663. $cell: true,
  1664. $type: "aside",
  1665. class: "mdc-temporary-drawer",
  1666. $components: [drawerCell]
  1667. }
  1668. );
  1669. let toolbar = {
  1670. $cell: true,
  1671. $type: "div",
  1672. class: "mdc-toolbar__row",
  1673. $components: [{
  1674. $type: "section",
  1675. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  1676. $components: [
  1677. {
  1678. $type: "button",
  1679. class: "demo-menu material-icons mdc-toolbar__icon--menu",
  1680. $text: "menu"
  1681. },
  1682. {
  1683. $type: "span",
  1684. class: "mdc-toolbar__title catalog-title",
  1685. $text: "LiveCoding.space"
  1686. }
  1687. ]
  1688. }]
  1689. };
  1690. document.querySelector("#toolbar").$cell({
  1691. $cell: true,
  1692. $type: "div",
  1693. class: "mdc-toolbar mdc-toolbar--fixed",
  1694. $components: [toolbar]
  1695. }
  1696. );
  1697. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  1698. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  1699. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  1700. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  1701. var drawer = new MDCTemporaryDrawer(drawerEl);
  1702. document.querySelector('.demo-menu').addEventListener('click', function () {
  1703. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  1704. // let currentNode = document.querySelector('#currentNode')._currentNode;
  1705. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  1706. // document.querySelector('#currentNode')._setNode(currentNode);
  1707. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  1708. drawer.open = !drawer.open;
  1709. });
  1710. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  1711. //console.log('Received MDCPersistentDrawer:open');
  1712. });
  1713. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  1714. //console.log('Received MDCPersistentDrawer:close');
  1715. });
  1716. //==============
  1717. $('#tabs').stop().animate({ opacity: 0.0 }, 0);
  1718. $('#tabs').mouseenter(function (evt) {
  1719. evt.stopPropagation();
  1720. $('#tabs').stop().animate({ opacity: 1.0 }, 175);
  1721. return false;
  1722. });
  1723. $('#tabs').mouseleave(function (evt) {
  1724. evt.stopPropagation();
  1725. $('#tabs').stop().animate({ opacity: 0.0 }, 175);
  1726. return false;
  1727. });
  1728. $('#hierarchy').click(function (evt) {
  1729. openEditor.call(self, 1);
  1730. });
  1731. $('#userlist').click(function (evt) {
  1732. openEditor.call(self, 2);
  1733. });
  1734. $('#timeline').click(function (evt) {
  1735. openEditor.call(self, 3);
  1736. });
  1737. $('#about').click(function (evt) {
  1738. openEditor.call(self, 4);
  1739. });
  1740. $('#models').click(function (evt) {
  1741. openEditor.call(self, 5);
  1742. });
  1743. $('#codeEditor').click(function (evt) {
  1744. openEditor.call(self, 6);
  1745. });
  1746. $('#x').click(function (evt) {
  1747. closeEditor.call(self);
  1748. });
  1749. $('#topdown_a').hide();
  1750. $('#topdown_b').hide();
  1751. $('#client_list').hide();
  1752. $('#time_control').hide();
  1753. $('#about_tab').hide();
  1754. $('#codeEditor_tab').hide();
  1755. $('#model_a').hide();
  1756. $('#model_b').hide();
  1757. var canvas = document.getElementById(vwf_view.kernel.find("", "/")[0]);
  1758. if (canvas) {
  1759. $('#topdown_a').height(canvas.height);
  1760. $('#topdown_b').height(canvas.height);
  1761. $('#client_list').height(canvas.height);
  1762. $('#time_control').height(canvas.height);
  1763. $('#about_tab').height(canvas.height);
  1764. $('#codeEditor_tab').height(canvas.height);
  1765. $('#model_a').height(canvas.height);
  1766. $('#model_b').height(canvas.height);
  1767. }
  1768. else {
  1769. $('#topdown_a').height(window.innerHeight - 20);
  1770. $('#topdown_b').height(window.innerHeight - 20);
  1771. $('#client_list').height(window.innerHeight - 20);
  1772. $('#time_control').height(window.innerHeight - 20);
  1773. $('#about_tab').height(window.innerHeight - 20);
  1774. $('#codeEditor_tab').height(window.innerHeight - 20);
  1775. $('#model_a').height(window.innerHeight - 20);
  1776. $('#model_b').height(window.innerHeight - 20);
  1777. }
  1778. },
  1779. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  1780. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  1781. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  1782. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  1783. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  1784. var kernel = this.kernel;
  1785. var self = this;
  1786. var parent = this.nodes[nodeID];
  1787. var node = this.nodes[childID] = {
  1788. children: [],
  1789. properties: [],
  1790. events: {},
  1791. methods: {},
  1792. parent: parent,
  1793. parentID: nodeID,
  1794. ID: childID,
  1795. extendsID: childExtendsID,
  1796. implementsIDs: childImplementsIDs,
  1797. source: childSource,
  1798. name: childName,
  1799. };
  1800. if (parent) {
  1801. parent.children.push(node);
  1802. }
  1803. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  1804. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  1805. this.scenes[childID] = node;
  1806. }
  1807. if (nodeID === this.currentNodeID && this.editingScript == false) {
  1808. $('#children > div:last').css('border-bottom-width', '1px');
  1809. $("#children").append("<div id='" + childIDAlpha + "' data-nodeID='" + childIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(childName) + "</b></div></div>");
  1810. $('#' + childIDAlpha).click(function (evt) {
  1811. drillDown.call(self, $(this).attr("data-nodeID"), nodeIDAttribute);
  1812. });
  1813. $('#children > div:last').css('border-bottom-width', '3px');
  1814. }
  1815. if (nodeID === this.kernel.application() && childName === 'camera') {
  1816. this.activeCameraID = childID;
  1817. }
  1818. let nodeCell = document.querySelector("#currentNode");
  1819. if (nodeCell !== null) {
  1820. if (nodeCell._currentNode === nodeID) {
  1821. nodeCell._getChildNodes();
  1822. }
  1823. }
  1824. if (nodeID === this.kernel.application()) {
  1825. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  1826. document.querySelector('body').classList.add("editor-body");
  1827. }
  1828. },
  1829. createdProperty: function (nodeID, propertyName, propertyValue) {
  1830. return this.initializedProperty(nodeID, propertyName, propertyValue);
  1831. },
  1832. initializedProperty: function (nodeID, propertyName, propertyValue) {
  1833. var node = this.nodes[nodeID];
  1834. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  1835. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  1836. node.properties.push(property);
  1837. },
  1838. deletedNode: function (nodeID) {
  1839. var node = this.nodes[nodeID];
  1840. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  1841. delete this.nodes[nodeID];
  1842. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID); // $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  1843. $('#' + nodeIDAttribute).remove();
  1844. $('#children > div:last').css('border-bottom-width', '3px');
  1845. let nodeCell = document.querySelector("#currentNode");
  1846. if (nodeCell) {
  1847. if (nodeCell._currentNode !== "") {
  1848. if (nodeCell._currentNode !== nodeID && (this.nodes[nodeID] !== undefined)) {
  1849. nodeCell._getChildNodes();
  1850. } else {
  1851. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  1852. nodeCell._getChildNodes();
  1853. }
  1854. }
  1855. }
  1856. },
  1857. //addedChild: [ /* nodeID, childID, childName */ ],
  1858. //removedChild: [ /* nodeID, childID */ ],
  1859. satProperty: function (nodeID, propertyName, propertyValue) {
  1860. var node = this.nodes[nodeID];
  1861. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  1862. // It is possible for a property to have satProperty called for it without ever getting an
  1863. // initializedProperty (if that property delegated to itself or another on replication)
  1864. // Catch that case here and create the property
  1865. if (!node.properties[propertyName]) {
  1866. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  1867. node.properties.push(property);
  1868. }
  1869. if (propertyName === "activeCamera") {
  1870. if (this.nodes[propertyValue] !== undefined) {
  1871. this.activeCameraID = propertyValue;
  1872. }
  1873. }
  1874. try {
  1875. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  1876. node.properties[propertyName].value = JSON.stringify(propertyValue);
  1877. node.properties[propertyName].rawValue = propertyValue;
  1878. } catch (e) {
  1879. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  1880. "stringify error:", e.message);
  1881. node.properties[propertyName].value = propertyValue;
  1882. }
  1883. if ((this.editorView == 1) && (this.currentNodeID == nodeID)) {
  1884. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID); // $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  1885. var propertyNameAttribute = $.encoder.encodeForAlphaNumeric("id", propertyName, true);
  1886. // No need to escape propertyValue, because .val does its own escaping
  1887. $('#input-' + nodeIDAttribute + '-' + propertyNameAttribute).val(node.properties[propertyName].getValue());
  1888. }
  1889. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  1890. if (propCell !== null) {
  1891. if (propCell._currentNode == nodeID) {
  1892. propCell.value = node.properties[propertyName].getValue();
  1893. }
  1894. }
  1895. },
  1896. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  1897. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  1898. var node = this.nodes[nodeID];
  1899. if (node) {
  1900. node.methods[methodName] = methodParameters;
  1901. }
  1902. },
  1903. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  1904. //},
  1905. createdEvent: function (nodeID, eventName, eventParameters) {
  1906. var node = this.nodes[nodeID];
  1907. if (node) {
  1908. node.events[eventName] = eventParameters;
  1909. }
  1910. },
  1911. firedEvent: function (nodeID, eventName, eventParameters) {
  1912. if (eventName == "pointerHover") {
  1913. highlightChildInHierarchy.call(this, nodeID);
  1914. }
  1915. },
  1916. executed: function (nodeID, scriptText, scriptType) {
  1917. // var nodeScript = {
  1918. // text: scriptText,
  1919. // type: scriptType,
  1920. // };
  1921. // if ( !this.allScripts[ nodeID ] ) {
  1922. // var nodeScripts = new Array();
  1923. // nodeScripts.push(nodeScript);
  1924. // this.allScripts[ nodeID ] = nodeScripts;
  1925. // }
  1926. // else {
  1927. // this.allScripts[ nodeID ].push(nodeScript);
  1928. // }
  1929. },
  1930. //ticked: [ /* time */ ],
  1931. });
  1932. function createCellWindow(elementID, cellNode, title) {
  1933. document.querySelector('#' + elementID).$cell({
  1934. $cell: true,
  1935. $type: "div",
  1936. id: elementID,
  1937. class: 'draggable',
  1938. $init: function () {
  1939. // let draggie = new Draggabilly('.draggable', {
  1940. // handle: '.handle',
  1941. // containment: true
  1942. // });
  1943. // get all draggie elements
  1944. var draggableElems = document.querySelectorAll('.draggable');
  1945. // array of Draggabillies
  1946. var draggies = []
  1947. // init Draggabillies
  1948. for (var i = 0, len = draggableElems.length; i < len; i++) {
  1949. var draggableElem = draggableElems[i];
  1950. var draggie = new Draggabilly(draggableElem, {
  1951. handle: '.handle',
  1952. containment: true
  1953. });
  1954. draggies.push(draggie);
  1955. }
  1956. this.style.visibility = 'hidden';
  1957. },
  1958. $components: [
  1959. {
  1960. $cell: true,
  1961. $type: "div",
  1962. class: "handle",
  1963. $components: [
  1964. {
  1965. $cell: true,
  1966. $type: "button",
  1967. class: "mdc-button mdc-button--compact",
  1968. $text: "X",
  1969. onclick: function (e) {
  1970. //self.currentNodeID = m.ID;
  1971. document.querySelector('#' + elementID).style.visibility = 'hidden';
  1972. }
  1973. },
  1974. {
  1975. $cell: true,
  1976. $type: "span",
  1977. class: "mdc-typography--button",
  1978. $text: title
  1979. }
  1980. ]
  1981. },
  1982. cellNode,
  1983. {
  1984. $cell: true,
  1985. $type: "div",
  1986. class: "handle",
  1987. style: "height: 10px; width: inherit;",
  1988. //$text: "sdfsdf"
  1989. }
  1990. // { $text: "23423"}
  1991. ]
  1992. }
  1993. );
  1994. }
  1995. // -- getChildByName --------------------------------------------------------------------
  1996. function getChildByName(node, childName) {
  1997. var childNode = undefined;
  1998. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  1999. if (node.children[i].name == childName) {
  2000. childNode = node.children[i];
  2001. }
  2002. }
  2003. return childNode;
  2004. };
  2005. function updateCameraProperties() {
  2006. if (this.currentNodeID == this.activeCameraID) {
  2007. if (!this.intervalTimer) {
  2008. var self = this;
  2009. this.intervalTimer = setInterval(function () { updateProperties.call(self, self.activeCameraID) }, 200);
  2010. }
  2011. }
  2012. else {
  2013. if (this.intervalTimer) {
  2014. clearInterval(this.intervalTimer);
  2015. this.intervalTimer = 0;
  2016. }
  2017. }
  2018. }
  2019. function updateProperties(nodeName) {
  2020. var nodeID = nodeName;
  2021. var properties = getProperties.call(this, this.kernel, nodeID);
  2022. for (var i in properties) {
  2023. try {
  2024. var propertyName = properties[i].prop.name;
  2025. var propertyValue = JSON.stringify(utility.transform(vwf.getProperty(nodeID, propertyName, []), utility.transforms.transit));
  2026. } catch (e) {
  2027. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue, "stringify error:", e.message);
  2028. }
  2029. if (propertyValue) {
  2030. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID);
  2031. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", propertyName, true);
  2032. var inputElement$ = $('#input-' + nodeIDAttribute + '-' + propertyNameAttribute);
  2033. // Only update if property value input is not in focus
  2034. // If in focus, change font style to italic
  2035. if (!inputElement$.is(":focus")) {
  2036. inputElement$.val(propertyValue);
  2037. inputElement$.css("font-style", "normal");
  2038. } else {
  2039. inputElement$.css("font-style", "italic");
  2040. }
  2041. }
  2042. }
  2043. }
  2044. // -- openEditor ------------------------------------------------------------------------
  2045. function openEditor(eView) // invoke with the view as "this"
  2046. {
  2047. if (eView == 0) {
  2048. closeEditor.call(this);
  2049. }
  2050. if (this.editorView != eView) {
  2051. // Hierarchy
  2052. if (eView == 1) {
  2053. var topdownName = this.topdownName;
  2054. var topdownTemp = this.topdownTemp;
  2055. if (!this.currentNodeID) {
  2056. this.currentNodeID = vwf_view.kernel.find("", "/")[0];
  2057. }
  2058. drill.call(this, this.currentNodeID, undefined);
  2059. $(this.clientList).hide();
  2060. $(this.timeline).hide();
  2061. $(this.about).hide();
  2062. $(this.codeEditor).hide();
  2063. $(this.models).hide();
  2064. if (this.editorOpen) {
  2065. $(topdownName).hide();
  2066. $(topdownTemp).show();
  2067. }
  2068. else {
  2069. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  2070. }
  2071. this.topdownName = topdownTemp;
  2072. this.topdownTemp = topdownName;
  2073. }
  2074. else if (this.editingScript) {
  2075. // Reset width if on script
  2076. this.editingScript = false;
  2077. $('#editor').animate({ 'left': "-260px" }, 175);
  2078. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2079. }
  2080. // User List
  2081. if (eView == 2) {
  2082. $(this.topdownName).hide();
  2083. $(this.topdownTemp).hide();
  2084. $(this.timeline).hide();
  2085. $(this.about).hide();
  2086. $(this.codeEditor).hide();
  2087. $(this.models).hide();
  2088. $(this.modelsTemp).hide();
  2089. showUserList.call(this);
  2090. }
  2091. // Timeline
  2092. else if (eView == 3) {
  2093. $(this.topdownName).hide();
  2094. $(this.topdownTemp).hide();
  2095. $(this.clientList).hide();
  2096. $(this.about).hide();
  2097. $(this.codeEditor).hide();
  2098. $(this.models).hide();
  2099. $(this.modelsTemp).hide();
  2100. showTimeline.call(this);
  2101. }
  2102. // About
  2103. else if (eView == 4) {
  2104. $(this.topdownName).hide();
  2105. $(this.topdownTemp).hide();
  2106. $(this.clientList).hide();
  2107. $(this.timeline).hide();
  2108. $(this.models).hide();
  2109. $(this.modelsTemp).hide();
  2110. $(this.codeEditor).hide();
  2111. showAboutTab.call(this);
  2112. }
  2113. // Models
  2114. else if (eView == 5) {
  2115. var models = this.models;
  2116. var modelsTemp = this.modelsTemp;
  2117. showModelsTab.call(this, this.currentModelID, this.currentModelURL);
  2118. $(this.topdownName).hide();
  2119. $(this.topdownTemp).hide();
  2120. $(this.clientList).hide();
  2121. $(this.timeline).hide();
  2122. $(this.about).hide();
  2123. $(this.codeEditor).hide();
  2124. if (this.editorOpen) {
  2125. $(models).hide();
  2126. $(modelsTemp).show();
  2127. }
  2128. else {
  2129. $(modelsTemp).show('slide', { direction: 'right' }, 175);
  2130. }
  2131. this.models = modelsTemp;
  2132. this.modelsTemp = models;
  2133. }
  2134. // Code Editor
  2135. else if (eView == 6) {
  2136. $(this.topdownName).hide();
  2137. $(this.topdownTemp).hide();
  2138. $(this.clientList).hide();
  2139. $(this.timeline).hide();
  2140. $(this.models).hide();
  2141. $(this.modelsTemp).hide();
  2142. $(this.about).hide();
  2143. showCodeEditorTab.call(this);
  2144. }
  2145. if (this.editorView == 0) {
  2146. $('#vwf-root').animate({ 'left': "-=260px" }, 175);
  2147. $('#editor').animate({ 'left': "-260px" }, 175);
  2148. $('#x').delay(1000).css({ 'display': 'inline' });
  2149. }
  2150. this.editorView = eView;
  2151. this.editorOpen = true;
  2152. }
  2153. }
  2154. // -- closeEditor -----------------------------------------------------------------------
  2155. function closeEditor() // invoke with the view as "this"
  2156. {
  2157. var topdownName = this.topdownName;
  2158. if (this.editorOpen && this.editorView == 1) // Hierarchy view open
  2159. {
  2160. $(topdownName).hide('slide', { direction: 'right' }, 175);
  2161. $(topdownName).empty();
  2162. $(this.clientList).hide();
  2163. $(this.timeline).hide();
  2164. $(this.about).hide();
  2165. $(this.codeEditor).hide();
  2166. $(this.models).hide();
  2167. }
  2168. else if (this.editorOpen && this.editorView == 2) // Client list open
  2169. {
  2170. $(this.clientList).hide('slide', { direction: 'right' }, 175);
  2171. $(topdownName).hide();
  2172. $(this.timeline).hide();
  2173. $(this.about).hide();
  2174. $(this.codeEditor).hide();
  2175. $(this.models).hide();
  2176. }
  2177. else if (this.editorOpen && this.editorView == 3) // Timeline open
  2178. {
  2179. $(this.timeline).hide('slide', { direction: 'right' }, 175);
  2180. $(topdownName).hide();
  2181. $(this.clientList).hide();
  2182. $(this.about).hide();
  2183. $(this.models).hide();
  2184. }
  2185. else if (this.editorOpen && this.editorView == 4) // About open
  2186. {
  2187. $(this.about).hide('slide', { direction: 'right' }, 175);
  2188. $(this.codeEditor).hide();
  2189. $(topdownName).hide();
  2190. $(this.clientList).hide();
  2191. $(this.timeline).hide();
  2192. $(this.models).hide();
  2193. }
  2194. else if (this.editorOpen && this.editorView == 5) // Models open
  2195. {
  2196. $(this.models).hide('slide', { direction: 'right' }, 175);
  2197. $(topdownName).hide();
  2198. $(this.clientList).hide();
  2199. $(this.timeline).hide();
  2200. $(this.about).hide();
  2201. $(this.codeEditor).hide();
  2202. }
  2203. else if (this.editorOpen && this.editorView == 6) // Code Editor open
  2204. {
  2205. $(this.codeEditor).hide('slide', { direction: 'right' }, 175);
  2206. $(this.about).hide();
  2207. $(topdownName).hide();
  2208. $(this.clientList).hide();
  2209. $(this.timeline).hide();
  2210. $(this.models).hide();
  2211. }
  2212. $('#vwf-root').animate({ 'left': "+=260px" }, 175);
  2213. $('#editor').animate({ 'left': "0px" }, 175);
  2214. $('#x').css({ 'display': 'none' });
  2215. this.editorView = 0;
  2216. this.editorOpen = false;
  2217. }
  2218. // -- showUserList ----------------------------------------------------------------------
  2219. function showUserList() // invoke with the view as "this"
  2220. {
  2221. var clientList = this.clientList;
  2222. viewClients.call(this);
  2223. if (!this.editorOpen) {
  2224. $(clientList).show('slide', { direction: 'right' }, 175);
  2225. }
  2226. else {
  2227. $(clientList).show();
  2228. }
  2229. }
  2230. // -- viewClients -----------------------------------------------------------------------
  2231. function viewClients() {
  2232. var self = this;
  2233. var app = window.location.pathname;
  2234. var pathSplit = app.split('/');
  2235. if (pathSplit[0] == "") {
  2236. pathSplit.shift();
  2237. }
  2238. if (pathSplit[pathSplit.length - 1] == "") {
  2239. pathSplit.pop();
  2240. }
  2241. var instIndex = pathSplit.length - 1;
  2242. if (pathSplit.length > 2) {
  2243. if (pathSplit[pathSplit.length - 2] == "load") {
  2244. instIndex = pathSplit.length - 3;
  2245. }
  2246. }
  2247. if (pathSplit.length > 3) {
  2248. if (pathSplit[pathSplit.length - 3] == "load") {
  2249. instIndex = pathSplit.length - 4;
  2250. }
  2251. }
  2252. var root = "";
  2253. for (var i = 0; i < instIndex; i++) {
  2254. if (root != "") {
  2255. root = root + "/";
  2256. }
  2257. root = root + pathSplit[i];
  2258. }
  2259. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  2260. var clients$ = $(this.clientList);
  2261. var node = this.nodes["http://vwf.example.com/clients.vwf"];
  2262. clients$.html("<div class='header'>Connected Clients</div>");
  2263. // Add node children
  2264. clients$.append("<div id='clientsChildren'></div>");
  2265. for (var i = 0; i < node.children.length; i++) {
  2266. var nodeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.children[i].ID, true);
  2267. var nodeChildIDAlpha = $.encoder.encodeForAlphaNumeric(node.children[i].ID);
  2268. var nodeChildNameHTML = $.encoder.encodeForHTML(node.children[i].name);
  2269. $('#clientsChildren').append("<div id='" + nodeChildIDAlpha + "' data-nodeID='" + nodeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + nodeChildNameHTML + "</b></div></div>");
  2270. $('#' + nodeChildIDAlpha).click(function (evt) {
  2271. viewClient.call(self, $(this).attr("data-nodeID"));
  2272. });
  2273. }
  2274. // Login Information
  2275. clients$.append("<div style='padding:6px'><input class='filename_entry' type='text' id='userName' placeholder='Username' /><!-- <input class='filename_entry' type='password' id='password' placeholder='Password'/> --><input class='update_button' type='button' id='login' value='Login' /></div>");
  2276. clients$.append("<hr/>");
  2277. $('#userName').keydown(function (evt) {
  2278. evt.stopPropagation();
  2279. });
  2280. $('#userName').keypress(function (evt) {
  2281. evt.stopPropagation();
  2282. });
  2283. $('#userName').keyup(function (evt) {
  2284. evt.stopPropagation();
  2285. });
  2286. $('#password').keydown(function (evt) {
  2287. evt.stopPropagation();
  2288. });
  2289. $('#password').keypress(function (evt) {
  2290. evt.stopPropagation();
  2291. });
  2292. $('#password').keyup(function (evt) {
  2293. evt.stopPropagation();
  2294. });
  2295. $('#login').click(function (evt) {
  2296. // Future call to validate username and password
  2297. //login.call(self, $('#userName').val(), $('#password').val());
  2298. var moniker = vwf_view.kernel.moniker();
  2299. var clients = vwf_view.kernel.findClients("", "/*");
  2300. var client = undefined;
  2301. for (var i = 0; i < clients.length; i++) {
  2302. if (clients[i].indexOf(moniker) != -1) {
  2303. client = clients[i];
  2304. break;
  2305. }
  2306. }
  2307. // var client = vwf_view.kernel.findClients("", "/" + moniker)[0];
  2308. if (client) {
  2309. vwf_view.kernel.setProperty(client, "displayName", $('#userName').val());
  2310. }
  2311. });
  2312. // clients$.append("<div style='padding:6px'><input class='live_button' type='button' id='liveeditor' value='Open Code Editor' /></div>");
  2313. // $('#liveeditor').click(function(evt) {
  2314. // openLiveEditor.call(self);
  2315. // });
  2316. // Save / Load
  2317. clients$.append("<div style='padding:6px'><input class='filename_entry' type='text' id='fileName' /><input class='update_button' type='button' id='save' value='Save' /></div>");
  2318. $('#fileName').keydown(function (evt) {
  2319. evt.stopPropagation();
  2320. });
  2321. $('#fileName').keypress(function (evt) {
  2322. evt.stopPropagation();
  2323. });
  2324. $('#fileName').keyup(function (evt) {
  2325. evt.stopPropagation();
  2326. });
  2327. $('#save').click(function (evt) {
  2328. saveStateAsFile.call(self, $('#fileName').val());
  2329. });
  2330. clients$.append("<div style='padding:6px'><select class='filename_select' id='fileToLoad' /></select></div>");
  2331. $('#fileToLoad').append("<option value='none'></option>");
  2332. $.getJSON("/" + root + "/listallsaves", function (data) {
  2333. $.each(data, function (key, value) {
  2334. var applicationName = value['applicationpath'].split("/");
  2335. if (applicationName.length > 0) {
  2336. applicationName = applicationName[applicationName.length - 1];
  2337. }
  2338. if (applicationName.length > 0) {
  2339. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  2340. }
  2341. if (value['latestsave']) {
  2342. $('#fileToLoad').append("<option value='" + value['savename'] + "' applicationpath='" + value['applicationpath'] + "'>" + applicationName + ": " + value['savename'] + "</option>");
  2343. }
  2344. else {
  2345. $('#fileToLoad').append("<option value='" + value['savename'] + "' applicationpath='" + value['applicationpath'] + "' revision='" + value['revision'] + "'>" + applicationName + ": " + value['savename'] + " Rev(" + value['revision'] + ")</option>");
  2346. }
  2347. });
  2348. });
  2349. clients$.append("<div style='padding:6px'><input class='update_button' type='button' id='load' value='Load' /></div>");
  2350. $('#load').click(function (evt) {
  2351. loadSavedState.call(self, $('#fileToLoad').val(), $('#fileToLoad').find(':selected').attr('applicationpath'), $('#fileToLoad').find(':selected').attr('revision'));
  2352. });
  2353. }
  2354. // -- editor ---
  2355. function openLiveEditor(value) {
  2356. //this.liveditor = document.createElement('div');
  2357. //this.liveditor.setAttribute('id', "editorlive");
  2358. // $('body').append(this.liveditor);
  2359. var editor = this.ace.edit("editorlive");
  2360. editor.setTheme("ace/theme/monokai");
  2361. editor.getSession().setMode("ace/mode/javascript");
  2362. }
  2363. // -- viewClient ------------------------------------------------------------------------
  2364. function viewClient(clientID) {
  2365. var self = this;
  2366. var clients$ = $(this.clientList);
  2367. var node = this.nodes[clientID];
  2368. clients$.html("<div class='header'><img src='images/back.png' id='back' alt='back'/> " + $.encoder.encodeForHTML(node.name) + "</div>");
  2369. $('#back').click(function (evt) {
  2370. viewClients.call(self);
  2371. });
  2372. // Add node properties
  2373. clients$.append("<div id='clientProperties'></div>");
  2374. var displayedProperties = {};
  2375. for (var i = 0; i < node.properties.length; i++) {
  2376. if (!displayedProperties[node.properties[i].name]) {
  2377. displayedProperties[node.properties[i].name] = "instance";
  2378. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(clientID);
  2379. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", node.properties[i].name, true);
  2380. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(node.properties[i].name);
  2381. var propertyNameHTML = $.encoder.encodeForHTML(node.properties[i].name);
  2382. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", node.properties[i].getValue(), true);
  2383. $('#clientProperties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "' readonly></td></tr></table></div>");
  2384. }
  2385. }
  2386. }
  2387. // -- drillDown -------------------------------------------------------------------------
  2388. function drillDown(nodeID, drillBackID) // invoke with the view as "this"
  2389. {
  2390. var topdownName = this.topdownName;
  2391. var topdownTemp = this.topdownTemp;
  2392. drill.call(this, nodeID, drillBackID);
  2393. if (nodeID != vwf_view.kernel.find("", "/")[0]) $(topdownName).hide('slide', { direction: 'left' }, 175);
  2394. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  2395. this.topdownName = topdownTemp;
  2396. this.topdownTemp = topdownName;
  2397. }
  2398. // -- drillUp ---------------------------------------------------------------------------
  2399. function drillUp(nodeID) // invoke with the view as "this"
  2400. {
  2401. var topdownName = this.topdownName;
  2402. var topdownTemp = this.topdownTemp;
  2403. drill.call(this, nodeID, undefined);
  2404. $(topdownName).hide('slide', { direction: 'right' }, 175);
  2405. $(topdownTemp).show('slide', { direction: 'left' }, 175);
  2406. this.topdownName = topdownTemp;
  2407. this.topdownTemp = topdownName;
  2408. }
  2409. // -- drillBack---------------------------------------------------------------------------
  2410. function drillBack(nodeID) // invoke with the view as "this"
  2411. {
  2412. var topdownName = this.topdownName;
  2413. var topdownTemp = this.topdownTemp;
  2414. drill.call(this, nodeID, undefined);
  2415. // No slide motion, when resizing script window back to normal
  2416. $(topdownName).hide();
  2417. $(topdownTemp).show();
  2418. this.topdownName = topdownTemp;
  2419. this.topdownTemp = topdownName;
  2420. }
  2421. // -- drill -----------------------------------------------------------------------------
  2422. function drill(nodeID, drillBackID) // invoke with the view as "this"
  2423. {
  2424. var node = this.nodes[nodeID];
  2425. if (!node) {
  2426. this.logger.errorx("drill: Cannot find node '" + nodeID + "'");
  2427. return;
  2428. }
  2429. var self = this;
  2430. var topdownName = this.topdownName;
  2431. var topdownTemp = this.topdownTemp;
  2432. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2433. $(topdownName).html(''); // Clear alternate div first to ensure content is added correctly
  2434. this.currentNodeID = nodeID;
  2435. if (!drillBackID) drillBackID = node.parentID;
  2436. if (nodeID == vwf_view.kernel.find("", "/")[0]) {
  2437. $(topdownTemp).html("<div class='header'>index</div>");
  2438. }
  2439. else {
  2440. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + nodeIDAlpha + "-back' alt='back'/> " + $.encoder.encodeForHTML(node.name) + "</div>");
  2441. $('#' + nodeIDAlpha + '-back').click(function (evt) {
  2442. drillUp.call(self, drillBackID);
  2443. });
  2444. }
  2445. // Add node children
  2446. $(topdownTemp).append("<div id='children'></div>");
  2447. for (var i = 0; i < node.children.length; i++) {
  2448. var nodeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.children[i].ID, true);
  2449. var nodeChildIDAlpha = $.encoder.encodeForAlphaNumeric(node.children[i].ID);
  2450. $('#children').append("<div id='" + nodeChildIDAlpha + "' data-nodeID='" + nodeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(node.children[i].name) + "</b></div></div>");
  2451. $('#' + nodeChildIDAlpha).click(function (evt) {
  2452. drillDown.call(self, $(this).attr("data-nodeID"), nodeID);
  2453. });
  2454. }
  2455. $('#children > div:last').css('border-bottom-width', '3px');
  2456. // Add prototype children
  2457. // TODO: Commented out until prototype children inherit from prototypes
  2458. /*
  2459. $(topdownTemp).append("<div id='prototypeChildren'></div>");
  2460. var prototypeChildren = getChildren.call( this, this.kernel, node.extendsID );
  2461. for ( var key in prototypeChildren)
  2462. {
  2463. var child = prototypeChildren[key];
  2464. var prototypeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", child.ID, true);
  2465. var prototypeChildIDAlpha = $.encoder.encodeForAlphaNumeric(child.ID);
  2466. $('#prototypeChildren').append("<div id='" + prototypeChildIDAlpha + "' data-nodeID='" + prototypeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(child.name) + "</b></div></div>");
  2467. $('#' + prototypeChildIDAlpha).click( function(evt) {
  2468. drillDown.call(self, $(this).attr("data-nodeID"), nodeID);
  2469. });
  2470. }
  2471. */ // END TODO:
  2472. $('#prototypeChildren > div:last').css('border-bottom-width', '3px');
  2473. // Add node properties
  2474. $(topdownTemp).append("<div id='properties'></div>");
  2475. var displayedProperties = {};
  2476. for (var i = 0; i < node.properties.length; i++) {
  2477. if (!displayedProperties[node.properties[i].name] && node.properties[i].name.indexOf('$') === -1) {
  2478. displayedProperties[node.properties[i].name] = "instance";
  2479. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", node.properties[i].name, true);
  2480. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(node.properties[i].name);
  2481. var propertyNameHTML = $.encoder.encodeForHTML(node.properties[i].name);
  2482. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", node.properties[i].getValue(), true);
  2483. if (propertyNameAlpha.indexOf("semantics") > -1) {
  2484. } else if (propertyNameAlpha.indexOf("grammar") > -1) {
  2485. } else if (propertyNameAlpha.indexOf("ohm") > -1) {
  2486. let propName = propertyNameAlpha;
  2487. let propValue = node.properties[i].rawValue;
  2488. $(topdownTemp).append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "'></div>");
  2489. $('#' + nodeIDAlpha + '-' + propertyNameAlpha).append("<div class='childContainer'><div class='childEntry'><b>" + propertyNameHTML + "</div></div>");
  2490. $('#' + nodeIDAlpha + '-' + propertyNameAlpha).click(function (evt) {
  2491. editOhmLang.call(self, nodeID, propName, propValue);
  2492. });
  2493. // $('#properties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "'></td></tr></table></div>");
  2494. } else {
  2495. $('#properties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "'></td></tr></table></div>");
  2496. }
  2497. $('#input-' + nodeIDAlpha + '-' + propertyNameAttribute).change(function (evt) {
  2498. var propName = $.encoder.canonicalize($(this).attr("data-propertyName"));
  2499. var propValue = $(this).val();
  2500. try {
  2501. propValue = JSON.parse($.encoder.canonicalize(propValue));
  2502. self.kernel.setProperty(nodeID, propName, propValue);
  2503. } catch (e) {
  2504. // restore the original value on error
  2505. $(this).val(propValue);
  2506. }
  2507. });
  2508. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keydown(function (evt) {
  2509. evt.stopPropagation();
  2510. });
  2511. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keypress(function (evt) {
  2512. evt.stopPropagation();
  2513. });
  2514. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keyup(function (evt) {
  2515. evt.stopPropagation();
  2516. });
  2517. }
  2518. }
  2519. $('#properties > div:last').css('border-bottom-width', '3px');
  2520. this.logger.info(self + " " + nodeID);
  2521. // Add prototype properties
  2522. $(topdownTemp).append("<div id='prototypeProperties'></div>");
  2523. var prototypeProperties = getProperties.call(this, this.kernel, node.extendsID);
  2524. for (var key in prototypeProperties) {
  2525. var prop = prototypeProperties[key].prop;
  2526. if (!displayedProperties[prop.name]) {
  2527. displayedProperties[prop.name] = prototypeProperties[key].prototype;
  2528. if (prop.value == undefined) {
  2529. prop.value = JSON.stringify(utility.transform(vwf.getProperty(nodeID, prop.name, []), utility.transforms.transit));
  2530. }
  2531. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", prop.name, true);
  2532. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(prop.name);
  2533. var propertyNameHTML = $.encoder.encodeForHTML(prop.name);
  2534. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", prop.value, true);
  2535. $('#prototypeProperties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "'></td></tr></table></div>");
  2536. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).change(function (evt) {
  2537. var propName = $.encoder.canonicalize($(this).attr("data-propertyName"));
  2538. var propValue = $(this).val();
  2539. try {
  2540. propValue = JSON.parse($.encoder.canonicalize(propValue));
  2541. self.kernel.setProperty(nodeID, propName, propValue);
  2542. } catch (e) {
  2543. // restore the original value on error
  2544. $(this).val(propValue);
  2545. }
  2546. });
  2547. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keydown(function (evt) {
  2548. evt.stopPropagation();
  2549. });
  2550. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keypress(function (evt) {
  2551. evt.stopPropagation();
  2552. });
  2553. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keyup(function (evt) {
  2554. evt.stopPropagation();
  2555. });
  2556. }
  2557. }
  2558. $('#prototypeProperties > div:last').css('border-bottom-width', '3px');
  2559. // Add node methods
  2560. $(topdownTemp).append("<div id='methods'></div>");
  2561. for (var key in node.methods) {
  2562. var method = node.methods[key];
  2563. var methodNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2564. var methodNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2565. var methodNameHTML = $.encoder.encodeForHTML(key);
  2566. $('#methods').append("<div id='" + methodNameAlpha + "' class='methodEntry'><table><tr><td><b>" + methodNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + methodNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='call-" + methodNameAlpha + "' value='Call' data-methodName='" + methodNameAttribute + "'><img id='param-" + methodNameAlpha + "' data-methodName='" + methodNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2567. $('#rollover-' + methodNameAlpha).mouseover(function (evt) {
  2568. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2569. });
  2570. $('#rollover-' + methodNameAlpha).mouseleave(function (evt) {
  2571. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2572. });
  2573. $('#call-' + methodNameAlpha).click(function (evt) {
  2574. self.kernel.callMethod(nodeID, $.encoder.canonicalize($(this).attr("data-methodName")));
  2575. });
  2576. $('#param-' + methodNameAlpha).click(function (evt) {
  2577. setParams.call(self, $.encoder.canonicalize($(this).attr("data-methodName")), method, nodeID);
  2578. });
  2579. }
  2580. $('#methods > div:last').css('border-bottom-width', '3px');
  2581. // Add prototype methods
  2582. $(topdownTemp).append("<div id='prototypeMethods'></div>");
  2583. var prototypeMethods = getMethods.call(this, this.kernel, node.extendsID);
  2584. for (var key in prototypeMethods) {
  2585. var method = prototypeMethods[key];
  2586. var prototypeMethodNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2587. var prototypeMethodNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2588. var prototypeMethodNameHTML = $.encoder.encodeForHTML(key);
  2589. $('#prototypeMethods').append("<div id='" + prototypeMethodNameAlpha + "' class='methodEntry'><table><tr><td><b>" + prototypeMethodNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + prototypeMethodNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='call-" + prototypeMethodNameAlpha + "' value='Call' data-methodName='" + prototypeMethodNameAttribute + "'><img id='param-" + prototypeMethodNameAlpha + "' data-methodName='" + prototypeMethodNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2590. $('#rollover-' + prototypeMethodNameAlpha).mouseover(function (evt) {
  2591. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2592. });
  2593. $('#rollover-' + prototypeMethodNameAlpha).mouseleave(function (evt) {
  2594. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2595. });
  2596. $('#call-' + prototypeMethodNameAlpha).click(function (evt) {
  2597. self.kernel.callMethod(nodeID, $.encoder.canonicalize($(this).attr("data-methodName")));
  2598. });
  2599. $('#param-' + prototypeMethodNameAlpha).click(function (evt) {
  2600. setParams.call(self, $.encoder.canonicalize($(this).attr("data-methodName")), method, nodeID);
  2601. });
  2602. }
  2603. $('#prototypeMethods > div:last').css('border-bottom-width', '3px');
  2604. // Add node events
  2605. $(topdownTemp).append("<div id='events'></div>");
  2606. for (var key in node.events) {
  2607. var nodeEvent = node.events[key];
  2608. var eventNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2609. var eventNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2610. var eventNameHTML = $.encoder.encodeForHTML(key);
  2611. $('#events').append("<div id='" + eventNameAlpha + "' class='methodEntry'><table><tr><td><b>" + eventNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + eventNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='fire-" + eventNameAlpha + "' value='Fire' data-eventName='" + eventNameAttribute + "'><img id='arg-" + eventNameAlpha + "' data-eventName='" + eventNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2612. $('#rollover-' + eventNameAlpha).mouseover(function (evt) {
  2613. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2614. });
  2615. $('#rollover-' + eventNameAlpha).mouseleave(function (evt) {
  2616. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2617. });
  2618. $('#fire-' + eventNameAlpha).click(function (evt) {
  2619. self.kernel.fireEvent(nodeID, $.encoder.canonicalize($(this).attr("data-eventName")));
  2620. });
  2621. $('#arg-' + eventNameAlpha).click(function (evt) {
  2622. setArgs.call(self, $.encoder.canonicalize($(this).attr("data-eventName")), nodeEvent, nodeID);
  2623. });
  2624. }
  2625. $('#events > div:last').css('border-bottom-width', '3px');
  2626. // Add prototype events
  2627. $(topdownTemp).append("<div id='prototypeEvents'></div>");
  2628. var prototypeEvents = getEvents.call(this, this.kernel, node.extendsID);
  2629. for (var key in prototypeEvents) {
  2630. var nodeEvent = prototypeEvents[key];
  2631. var prototypeEventNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2632. var prototypeEventNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2633. var prototypeEventNameHTML = $.encoder.encodeForHTML(key);
  2634. $('#prototypeEvents').append("<div id='" + prototypeEventNameAlpha + "' class='methodEntry'><table><tr><td><b>" + prototypeEventNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + prototypeEventNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='fire-" + prototypeEventNameAlpha + "' value='Fire' data-eventName='" + prototypeEventNameAttribute + "'><img id='arg-" + prototypeEventNameAlpha + "' data-eventName='" + prototypeEventNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2635. $('#rollover-' + prototypeEventNameAlpha).mouseover(function (evt) {
  2636. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2637. });
  2638. $('#rollover-' + prototypeEventNameAlpha).mouseleave(function (evt) {
  2639. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2640. });
  2641. $('#fire-' + prototypeEventNameAlpha).click(function (evt) {
  2642. self.kernel.fireEvent(nodeID, $.encoder.canonicalize($(this).attr("data-eventName")));
  2643. });
  2644. $('#arg-' + prototypeEventNameAlpha).click(function (evt) {
  2645. setArgs.call(self, $.encoder.canonicalize($(this).attr("data-eventName")), nodeEvent, nodeID);
  2646. });
  2647. }
  2648. $('#prototypeEvents > div:last').css('border-bottom-width', '3px');
  2649. // Add node behaviors
  2650. $(topdownTemp).append("<div id='behaviors'></div>");
  2651. for (var i = 0; i < node.implementsIDs.length; i++) {
  2652. var nodeImplementsIDAlpha = $.encoder.encodeForAlphaNumeric(node.implementsIDs[i]);
  2653. var nodeImplementsIDHTML = $.encoder.encodeForHTML(node.implementsIDs[i]);
  2654. $('#behaviors').append("<div class='propEntry'><table><tr><td style='width:92%'><b>" + nodeImplementsIDHTML + "</b></td><td><input id='" + nodeImplementsIDAlpha + "-enable' type='checkbox' checked='checked' disabled='disabled' /></td></tr></table></div>");
  2655. /*
  2656. //Placeholder to Enable/Disable behaviors
  2657. $('#' + node.implementsID[i] + '-enable').change( function(evt) {
  2658. });
  2659. */
  2660. }
  2661. $('#behaviors > div:last').css('border-bottom-width', '3px');
  2662. // Add prototype behaviors
  2663. $(topdownTemp).append("<div id='prototypeBehaviors'></div>");
  2664. var prototypeNode = this.nodes[node.extendsID];
  2665. for (var i = 0; i < prototypeNode.implementsIDs.length; i++) {
  2666. var prototypeImplementsIDAlpha = $.encoder.encodeForAlphaNumeric(prototypeNode.implementsIDs[i]);
  2667. var prototypeImplementsIDHTML = $.encoder.encodeForHTML(prototypeNode.implementsIDs[i]);
  2668. $('#prototypeBehaviors').append("<div class='propEntry'><table><tr><td style='width:92%'><b>" + prototypeImplementsIDHTML + "</b></td><td><input id='" + prototypeImplementsIDAlpha + "-enable' type='checkbox' checked='checked' disabled='disabled' /></td></tr></table></div>");
  2669. }
  2670. $('#prototypeBehaviors > div:last').css('border-bottom-width', '3px');
  2671. // Create new method
  2672. $(topdownTemp).append("<div id='createMethodID'></div>");
  2673. $('#createMethodID').append("<div class='childContainer'><div class='childEntry'><b>New Method</div></div>");
  2674. $('#createMethodID').click(function (evt) {
  2675. createMethod.call(self, nodeID);
  2676. });
  2677. // Create new Event
  2678. $(topdownTemp).append("<div id='createEventID'></div>");
  2679. $('#createEventID').append("<div class='childContainer'><div class='childEntry'><b>New Event</div></div>");
  2680. $('#createEventID').click(function (evt) {
  2681. createEvent.call(self, nodeID);
  2682. });
  2683. // Create new script
  2684. $(topdownTemp).append("<div id='createScript'></div>");
  2685. $('#createScript').append("<div class='childContainer'><div class='childEntry'><b>New Script</div></div>");
  2686. $('#createScript').click(function (evt) {
  2687. createScript.call(self, nodeID);
  2688. });
  2689. $('#createScript > div:last').css('border-bottom-width', '3px');
  2690. if (this.allScripts[nodeID] !== undefined) {
  2691. // Add node scripts
  2692. $(topdownTemp).append("<div id='scripts'></div>");
  2693. for (var i = 0; i < this.allScripts[nodeID].length; i++) {
  2694. var scriptFull = this.allScripts[nodeID][i].text;
  2695. if (scriptFull != undefined) {
  2696. var scriptName = scriptFull.substring(0, scriptFull.indexOf('='));
  2697. $('#scripts').append("<div id='script-" + nodeIDAlpha + "-" + i + "' class='childContainer'><div class='childEntry'><b>script </b>" + scriptName + "</div></div>");
  2698. $('#script-' + nodeIDAlpha + "-" + i).click(function (evt) {
  2699. var scriptID = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  2700. viewScript.call(self, nodeID, scriptID, undefined);
  2701. });
  2702. }
  2703. }
  2704. $('#scripts > div:last').css('border-bottom-width', '3px');
  2705. }
  2706. if (this.allScripts[node.extendsID] !== undefined) {
  2707. // Add prototype scripts
  2708. $(topdownTemp).append("<div id='prototypeScripts'></div>");
  2709. for (var i = 0; i < this.allScripts[node.extendsID].length; i++) {
  2710. var scriptFull = this.allScripts[node.extendsID][i].text;
  2711. if (scriptFull != undefined) {
  2712. var nodeExtendsIDAlpha = $.encoder.encodeForAlphaNumeric(node.extendsID);
  2713. var nodeExtendsIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.extendsID, true);
  2714. var scriptName = scriptFull.substring(0, scriptFull.indexOf('='));
  2715. $('#prototypeScripts').append("<div id='script-" + nodeExtendsIDAlpha + "-" + i + "' class='childContainer' data-nodeExtendsID='" + nodeExtendsIDAttribute + "'><div class='childEntry'><b>script </b>" + scriptName + "</div></div>");
  2716. $('#script-' + nodeExtendsIDAlpha + "-" + i).click(function (evt) {
  2717. var extendsId = $.encoder.canonicalize($(this).attr("data-nodeExtendsID"));
  2718. var scriptID = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  2719. viewScript.call(self, nodeID, scriptID, extendsId);
  2720. });
  2721. }
  2722. }
  2723. $('#prototypeScripts > div:last').css('border-bottom-width', '3px');
  2724. }
  2725. updateCameraProperties.call(self);
  2726. }
  2727. // createEvent
  2728. function createEvent(nodeID) // invoke with the view as "this"
  2729. {
  2730. var self = this;
  2731. var topdownName = this.topdownName;
  2732. var topdownTemp = this.topdownTemp;
  2733. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2734. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> New event</div>");
  2735. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  2736. self.editingScript = false;
  2737. drillBack.call(self, nodeID);
  2738. // Return editor to normal width
  2739. $('#editor').animate({ 'left': "-260px" }, 175);
  2740. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2741. });
  2742. $(topdownTemp).append("<div id='cm'>Name:<br/><input type='text' class='input_text' id='eventName'/><br/>Parameters:<br/><input type='text' class='input_text' id='eventParams'/></div><hr><input class='update_button' type='button' id='createEvent' value='Create' />");
  2743. $("#createEvent").click(function (evt) {
  2744. console.log("not yet created");
  2745. if ($('#eventName').val()) {
  2746. var eventName = $('#eventName').val();
  2747. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  2748. console.log(eventName);
  2749. if ($('#eventParams').val()) {
  2750. var params = $('#eventParams').val();
  2751. params = params.split(',');
  2752. var cleanParams = [];
  2753. for (var i = 0; i < params.length; i++) {
  2754. params[i] = $.trim(params[i]);
  2755. if (params[i] != '' && params[i] != null && params[i] !== undefined)
  2756. cleanParams.push(params[i]);
  2757. }
  2758. console.log(cleanParams);
  2759. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  2760. }
  2761. let body = '';
  2762. self.kernel.createEvent(nodeID, eventName, cleanParams);
  2763. }
  2764. //self.kernel.execute( nodeID, editor.getValue() );
  2765. // self.kernel.execute( nodeID, $("#newScriptArea").val() );
  2766. });
  2767. $(topdownName).hide();
  2768. $(topdownTemp).show();
  2769. this.topdownName = topdownTemp;
  2770. this.topdownTemp = topdownName;
  2771. }
  2772. // -- createMethod
  2773. function createMethod(nodeID) // invoke with the view as "this"
  2774. {
  2775. var self = this;
  2776. var topdownName = this.topdownName;
  2777. var topdownTemp = this.topdownTemp;
  2778. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2779. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> New method</div>");
  2780. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  2781. self.editingScript = false;
  2782. drillBack.call(self, nodeID);
  2783. // Return editor to normal width
  2784. $('#editor').animate({ 'left': "-260px" }, 175);
  2785. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2786. });
  2787. $(topdownTemp).append("<div id='cm'>Name:<br/><input type='text' class='input_text' id='methodName'/><br/>Parameters:<br/><input type='text' class='input_text' id='methodParams'/></div><hr><input class='update_button' type='button' id='createMethod' value='Create' />");
  2788. $("#createMethod").click(function (evt) {
  2789. console.log("not yet created");
  2790. if ($('#methodName').val()) {
  2791. var methodName = $('#methodName').val();
  2792. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  2793. console.log(methodName);
  2794. if ($('#methodParams').val()) {
  2795. var params = $('#methodParams').val();
  2796. params = params.split(',');
  2797. var cleanParams = [];
  2798. for (var i = 0; i < params.length; i++) {
  2799. params[i] = $.trim(params[i]);
  2800. if (params[i] != '' && params[i] != null && params[i] !== undefined)
  2801. cleanParams.push(params[i]);
  2802. }
  2803. console.log(cleanParams);
  2804. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  2805. }
  2806. let body = '';
  2807. self.kernel.createMethod(nodeID, methodName, cleanParams, body);
  2808. }
  2809. //self.kernel.execute( nodeID, editor.getValue() );
  2810. // self.kernel.execute( nodeID, $("#newScriptArea").val() );
  2811. });
  2812. $(topdownName).hide();
  2813. $(topdownTemp).show();
  2814. this.topdownName = topdownTemp;
  2815. this.topdownTemp = topdownName;
  2816. }
  2817. // -- createScript ----------------------------------------------------------------------
  2818. function createScript(nodeID) // invoke with the view as "this"
  2819. {
  2820. var self = this;
  2821. var topdownName = this.topdownName;
  2822. var topdownTemp = this.topdownTemp;
  2823. var allScripts = this.allScripts;
  2824. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2825. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  2826. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  2827. self.editingScript = false;
  2828. drillBack.call(self, nodeID);
  2829. // Return editor to normal width
  2830. $('#editor').animate({ 'left': "-260px" }, 175);
  2831. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2832. });
  2833. // $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'><textarea id='newScriptArea' class='scriptEdit' spellcheck='false' wrap='off'></textarea></pre><input class='update_button' type='button' id='create-" + nodeIDAlpha + "' value='Create' /></div><hr>");
  2834. $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'> <div id='editorlive'></div></pre><input class='update_button' type='button' id='create-" + nodeIDAlpha + "' value='Create' /></div><hr>");
  2835. var editor = createAceEditor(self, nodeID);
  2836. $("#create-" + nodeIDAlpha).click(function (evt) {
  2837. self.kernel.execute(nodeID, editor.getValue());
  2838. // self.kernel.execute( nodeID, $("#newScriptArea").val() );
  2839. });
  2840. // $('#newScriptArea').focus( function(evt) {
  2841. // // Expand the script editor
  2842. // self.editingScript = true;
  2843. // $('#editor').animate({ 'left' : "-500px" }, 175);
  2844. // $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  2845. // });
  2846. $('#editorlive').keydown(function (evt) {
  2847. evt.stopPropagation();
  2848. });
  2849. $(topdownName).hide();
  2850. $(topdownTemp).show();
  2851. this.topdownName = topdownTemp;
  2852. this.topdownTemp = topdownName;
  2853. }
  2854. // -- viewScript ------------------------------------------------------------------------
  2855. function createAceEditor(view, nodeID, elID) {
  2856. var editor = view.ace.edit(elID);
  2857. editor.setTheme("ace/theme/monokai");
  2858. editor.setFontSize(16);
  2859. editor.getSession().setMode("ace/mode/javascript");
  2860. editor.commands.addCommand({
  2861. name: "doit",
  2862. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  2863. exec: function () {
  2864. codeEditorDoit(editor, nodeID);
  2865. }
  2866. });
  2867. editor.commands.addCommand({
  2868. name: "printit",
  2869. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  2870. exec: function () {
  2871. codeEditorPrintit(editor, nodeID);
  2872. }
  2873. });
  2874. return editor;
  2875. }
  2876. function editOhmLang(nodeID, propertyName, propertyValue) {
  2877. var self = this;
  2878. var topdownName = this.topdownName;
  2879. var topdownTemp = this.topdownTemp;
  2880. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2881. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  2882. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  2883. self.editingScript = false;
  2884. drillBack.call(self, nodeID);
  2885. // Return editor to normal width
  2886. $('#editor').animate({ 'left': "-260px" }, 175);
  2887. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2888. });
  2889. if (propertyValue != undefined) {
  2890. var propText = propertyValue;
  2891. // var propText = propertyValue.split("\n").map($.trim).filter(function(line) { return line != "" }).join("\n");
  2892. $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='update-" + nodeIDAlpha + "-" + propertyName + "' value='Update' /></div>");
  2893. $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'> <div id='editorlive'> </div></pre></div><hr>");
  2894. var editor = createAceEditor(self, nodeID);
  2895. editor.setValue(propText);
  2896. $("#update-" + nodeIDAlpha + "-" + propertyName).click(function (evt) {
  2897. var evalText = editor.getValue();
  2898. self.kernel.setProperty(nodeID, propertyName, evalText);
  2899. });
  2900. $('#editorlive').keydown(function (evt) {
  2901. evt.stopPropagation();
  2902. });
  2903. }
  2904. $(topdownName).hide();
  2905. $(topdownTemp).show();
  2906. this.topdownName = topdownTemp;
  2907. this.topdownTemp = topdownName;
  2908. }
  2909. function viewScript(nodeID, scriptID, extendsID) // invoke with the view as "this"
  2910. {
  2911. var self = this;
  2912. var topdownName = this.topdownName;
  2913. var topdownTemp = this.topdownTemp;
  2914. var allScripts = this.allScripts;
  2915. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2916. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  2917. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  2918. self.editingScript = false;
  2919. drillBack.call(self, nodeID);
  2920. // Return editor to normal width
  2921. $('#editor').animate({ 'left': "-260px" }, 175);
  2922. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2923. });
  2924. if (extendsID) {
  2925. nodeID = extendsID;
  2926. nodeIDAlpha = $.encoder.encodeForAlphaNumeric(extendsID);
  2927. }
  2928. var scriptText = self.allScripts[nodeID][scriptID].text;
  2929. if (scriptText != undefined) {
  2930. // $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'><textarea id='scriptTextArea' class='scriptEdit' spellcheck='false' wrap='off'>" + scriptText + "</textarea></pre><input class='update_button' type='button' id='update-" + nodeIDAlpha + "-" + scriptID + "' value='Update' /></div><hr>");
  2931. //Open Live Editor
  2932. $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='printit' value='Print It' /><span> </span><input class='live_button' type='button' id='doit-" + nodeIDAlpha + "-" + scriptID + "' value='DoIt' /><span> </span><input class='live_button' type='button' id='update-" + nodeIDAlpha + "-" + scriptID + "' value='Update' /></div>");
  2933. $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'> <div id='editorlive'>" + scriptText + "</div></pre></div><hr>");
  2934. var editor = createAceEditor(self, nodeID);
  2935. // $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='doit' value='DoIt' /></div>");
  2936. $("#doit-" + nodeIDAlpha + "-" + scriptID).click(function (evt) {
  2937. var s_id = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  2938. self.allScripts[nodeID][s_id].text = undefined;;
  2939. codeEditorDoit.call(self, editor, nodeID);
  2940. });
  2941. $("#printit").click(function (evt) {
  2942. codeEditorPrintit.call(self, editor, nodeID);
  2943. });
  2944. $("#update-" + nodeIDAlpha + "-" + scriptID).click(function (evt) {
  2945. var s_id = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  2946. self.allScripts[nodeID][s_id].text = undefined;
  2947. var evalText = editor.getValue();
  2948. self.kernel.execute(nodeID, evalText);
  2949. });
  2950. // $('#editorlive').focus( function(evt) {
  2951. // // Expand the script editor
  2952. // self.editingScript = true;
  2953. // $('#editor').animate({ 'left' : "-500px" }, 175);
  2954. // $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  2955. // });
  2956. $('#editorlive').keydown(function (evt) {
  2957. evt.stopPropagation();
  2958. });
  2959. }
  2960. $(topdownName).hide();
  2961. $(topdownTemp).show();
  2962. this.topdownName = topdownTemp;
  2963. this.topdownTemp = topdownName;
  2964. }
  2965. // -- setParams -------------------------------------------------------------------------
  2966. function setParams(methodName, methodParams, nodeID) // invoke with the view as "this"
  2967. {
  2968. var self = this;
  2969. var topdownName = this.topdownName;
  2970. var topdownTemp = this.topdownTemp;
  2971. var methodNameAlpha = $.encoder.encodeForAlphaNumeric(methodName);
  2972. var methodNameHTML = $.encoder.encodeForHTML(methodName);
  2973. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + methodNameAlpha + "-back' alt='back'/> " + methodNameHTML + "</div>");
  2974. $('#' + methodNameAlpha + '-back').click(function (evt) {
  2975. self.editingScript = false;
  2976. drillUp.call(self, nodeID);
  2977. // Return editor to normal width
  2978. $('#editor').animate({ 'left': "-260px" }, 175);
  2979. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2980. });
  2981. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2982. var method = vwf.getMethod(nodeID, methodNameAlpha);
  2983. $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='printit' value='Print It' /><span> </span><input class='live_button' type='button' id='doit' value='Do It' /><span> </span><input class='live_button' type='button' id='update-" + nodeIDAlpha + "-" + methodNameAlpha + "' value='Update' /><span> </span> <input class='live_button' type='button' id='call' value='Call' /></div>");
  2984. //$(topdownTemp).append("<input class='update_button' type='button' id='call' value='Call' />");
  2985. $(topdownTemp).append("<div id='editorlive'>" + method.body + "</div>");
  2986. var editor = createAceEditor(self, nodeID);
  2987. $("#printit").click(function (evt) {
  2988. codeEditorPrintit.call(self, editor, nodeID);
  2989. });
  2990. $("#doit").click(function (evt) {
  2991. codeEditorDoit.call(self, editor, nodeID);
  2992. });
  2993. $("#update-" + nodeIDAlpha + "-" + methodNameAlpha).click(function (evt) {
  2994. var evalText = editor.getValue();
  2995. self.kernel.setMethod(nodeID, methodNameAlpha,
  2996. { body: evalText, type: "application/javascript", parameters: method.parameters });
  2997. });
  2998. var params = [];
  2999. if (method.parameters) {
  3000. params = method.parameters.length
  3001. };
  3002. if (params >= 1) {
  3003. for (var i = 1; i <= params; i++) {
  3004. $(topdownTemp).append("<div id='param" + i + "' class='propEntry'><table><tr><td><b>" + method.parameters[i - 1] + ": " + i + ": </b></td><td><input type='text' class='input_text' id='input-param" + i + "'></td></tr></table></div>");
  3005. $('#input-param' + i).keydown(function (evt) {
  3006. evt.stopPropagation();
  3007. });
  3008. $('#input-param' + i).keypress(function (evt) {
  3009. evt.stopPropagation();
  3010. });
  3011. $('#input-param' + i).keyup(function (evt) {
  3012. evt.stopPropagation();
  3013. });
  3014. }
  3015. }
  3016. $('#call').click(function (evt) {
  3017. if (params >= 1) {
  3018. var parameters = new Array();
  3019. for (var i = 1; i <= params; i++) {
  3020. if ($('#input-param' + i).val()) {
  3021. var prmtr = $('#input-param' + i).val();
  3022. try {
  3023. prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  3024. parameters.push(prmtr);
  3025. } catch (e) {
  3026. self.logger.error('Invalid Value');
  3027. }
  3028. }
  3029. }
  3030. }
  3031. self.kernel.callMethod(nodeID, methodName, parameters);
  3032. });
  3033. $(topdownName).hide('slide', { direction: 'left' }, 175);
  3034. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  3035. this.topdownName = topdownTemp;
  3036. this.topdownTemp = topdownName;
  3037. }
  3038. // -- setArgs ---------------------------------------------------------------------------
  3039. function setArgs(eventName, eventArgs, nodeID) // invoke with the view as "this"
  3040. {
  3041. var self = this;
  3042. var topdownName = this.topdownName;
  3043. var topdownTemp = this.topdownTemp;
  3044. var eventNameAlpha = $.encoder.encodeForAlphaNumeric(eventName);
  3045. var eventNameHTML = $.encoder.encodeForHTML(eventName);
  3046. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + eventNameAlpha + "-back' alt='back'/> " + eventNameHTML + "<input type='button' class='input_button_call' id='fire' value='Fire' style='float:right;position:relative;top:5px;right:33px'></input></div>");
  3047. $('#' + eventNameAlpha + '-back').click(function (evt) {
  3048. drillUp.call(self, nodeID);
  3049. });
  3050. for (var i = 1; i <= 8; i++) {
  3051. $(topdownTemp).append("<div id='arg" + i + "' class='propEntry'><table><tr><td><b>Argument " + i + ": </b></td><td><input type='text' class='input_text' id='input-arg" + i + "'></td></tr></table></div>");
  3052. $('#input-arg' + i).keydown(function (evt) {
  3053. evt.stopPropagation();
  3054. });
  3055. $('#input-arg' + i).keypress(function (evt) {
  3056. evt.stopPropagation();
  3057. });
  3058. $('#input-arg' + i).keyup(function (evt) {
  3059. evt.stopPropagation();
  3060. });
  3061. }
  3062. $(topdownTemp).append("<div style='font-weight:bold;text-align:right;padding-right:10px'></div>");
  3063. $('#fire').click(function (evt) {
  3064. var args = new Array();
  3065. for (var i = 1; i <= 8; i++) {
  3066. if ($('#input-arg' + i).val()) {
  3067. var arg = $('#input-arg' + i).val();
  3068. try {
  3069. arg = JSON.parse($.encoder.canonicalize(arg));
  3070. args.push(arg);
  3071. } catch (e) {
  3072. self.logger.error('Invalid Value');
  3073. }
  3074. }
  3075. }
  3076. self.kernel.fireEvent(nodeID, eventName, args);
  3077. });
  3078. $(topdownName).hide('slide', { direction: 'left' }, 175);
  3079. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  3080. this.topdownName = topdownTemp;
  3081. this.topdownTemp = topdownName;
  3082. }
  3083. function getPrototypes(kernel, extendsID) {
  3084. var prototypes = [];
  3085. var id = extendsID;
  3086. while (id !== undefined) {
  3087. prototypes.push(id);
  3088. id = kernel.prototype(id);
  3089. }
  3090. return prototypes;
  3091. }
  3092. function getPrototypes(kernel, extendsID) {
  3093. var prototypes = [];
  3094. var id = extendsID;
  3095. while (id !== undefined) {
  3096. prototypes.push(id);
  3097. id = kernel.prototype(id);
  3098. }
  3099. return prototypes;
  3100. }
  3101. function createProperty(node, propertyName, propertyValue) {
  3102. var property = {
  3103. name: propertyName,
  3104. rawValue: propertyValue,
  3105. value: undefined,
  3106. getValue: function () {
  3107. var propertyValue;
  3108. if (this.value == undefined) {
  3109. try {
  3110. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  3111. this.value = JSON.stringify(propertyValue);
  3112. } catch (e) {
  3113. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  3114. "stringify error:", e.message);
  3115. this.value = this.rawValue;
  3116. }
  3117. }
  3118. return this.value;
  3119. }
  3120. };
  3121. return property;
  3122. }
  3123. function getProperties(kernel, extendsID) {
  3124. var pTypes = getPrototypes(kernel, extendsID);
  3125. var pProperties = {};
  3126. if (pTypes) {
  3127. for (var i = 0; i < pTypes.length; i++) {
  3128. var nd = this.nodes[pTypes[i]];
  3129. if (nd && nd.properties) {
  3130. for (var key in nd.properties) {
  3131. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  3132. }
  3133. }
  3134. }
  3135. }
  3136. return pProperties;
  3137. }
  3138. function getChildren(kernel, extendsID) {
  3139. var pTypes = getPrototypes(kernel, extendsID);
  3140. var pChildren = {};
  3141. if (pTypes) {
  3142. for (var i = 0; i < pTypes.length; i++) {
  3143. var nd = this.nodes[pTypes[i]];
  3144. if (nd && nd.children) {
  3145. for (var key in nd.children) {
  3146. pChildren[key] = nd.children[key];
  3147. }
  3148. }
  3149. }
  3150. }
  3151. return pChildren;
  3152. }
  3153. function getEvents(kernel, extendsID) {
  3154. var pTypes = getPrototypes(kernel, extendsID);
  3155. var events = {};
  3156. if (pTypes) {
  3157. for (var i = 0; i < pTypes.length; i++) {
  3158. var nd = this.nodes[pTypes[i]];
  3159. if (nd && nd.events) {
  3160. for (var key in nd.events) {
  3161. events[key] = nd.events[key];
  3162. }
  3163. }
  3164. }
  3165. }
  3166. return events;
  3167. }
  3168. function getMethods(kernel, extendsID) {
  3169. var pTypes = getPrototypes(kernel, extendsID);
  3170. var methods = {};
  3171. if (pTypes) {
  3172. for (var i = 0; i < pTypes.length; i++) {
  3173. var nd = this.nodes[pTypes[i]];
  3174. if (nd && nd.methods) {
  3175. for (var key in nd.methods) {
  3176. methods[key] = nd.methods[key];
  3177. }
  3178. }
  3179. }
  3180. }
  3181. return methods;
  3182. }
  3183. function highlightChildInHierarchy(nodeID) {
  3184. if (this.editorOpen && this.editorView == 1) // Hierarchy view open
  3185. {
  3186. var childDiv = $("div[id='" + nodeID + "']");
  3187. if (childDiv.length > 0) {
  3188. var previousChild = $("div[id='" + this.highlightedChild + "']");
  3189. if (previousChild.length > 0) {
  3190. previousChild.removeClass('childContainerHighlight');
  3191. }
  3192. childDiv.addClass('childContainerHighlight');
  3193. this.highlightedChild = nodeID;
  3194. }
  3195. }
  3196. }
  3197. // -- showTimeline ----------------------------------------------------------------------
  3198. function showTimeline() // invoke with the view as "this"
  3199. {
  3200. var timeline = this.timeline;
  3201. if (!this.timelineInit) {
  3202. $('#time_control').append("<div class='header'>Timeline</div>" +
  3203. "<div style='text-align:center;padding-top:10px'><span><button id='play'></button><button id='stop'></button></span>" +
  3204. "<span><span class='rate slider'></span>&nbsp;" +
  3205. "<span class='rate vwf-label' style='display: inline-block; width:8ex'></span></span></div>");
  3206. var options = {};
  3207. ["play", "pause", "stop"].forEach(function (state) {
  3208. options[state] = { icons: { primary: "ui-icon-" + state }, label: state, text: false };
  3209. });
  3210. options.rate = { value: 0, min: -2, max: 2, step: 0.1, };
  3211. var state = {};
  3212. $.get(
  3213. "admin/state",
  3214. undefined,
  3215. function (data) {
  3216. state = data;
  3217. $("button#play").button("option", state.playing ? options.pause : options.play);
  3218. $("button#stop").button("option", "disabled", state.stopped);
  3219. $(".rate.slider").slider("value", Math.log(state.rate) / Math.LN10);
  3220. if (state.rate < 1.0) {
  3221. var label_rate = 1.0 / state.rate;
  3222. }
  3223. else {
  3224. var label_rate = state.rate;
  3225. }
  3226. var label = label_rate.toFixed(2).toString().replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
  3227. if (state.rate < 1.0) {
  3228. label = "&#x2215; " + label;
  3229. } else {
  3230. label = label + " &times;";
  3231. }
  3232. $(".rate.vwf-label").html(label);
  3233. },
  3234. "json"
  3235. );
  3236. $("button#play").button(
  3237. options.pause
  3238. ).click(function () {
  3239. $.post(
  3240. state.playing ? "admin/pause" : "admin/play",
  3241. undefined,
  3242. function (data) {
  3243. state = data;
  3244. $("button#play").button("option", state.playing ? options.pause : options.play);
  3245. $("button#stop").button("option", "disabled", state.stopped);
  3246. },
  3247. "json"
  3248. );
  3249. });
  3250. $("button#stop").button(
  3251. options.stop
  3252. ).click(function () {
  3253. $.post(
  3254. "admin/stop",
  3255. undefined,
  3256. function (data) {
  3257. state = data;
  3258. $("button#play").button("option", state.playing ? options.pause : options.play);
  3259. $("button#stop").button("option", "disabled", state.stopped);
  3260. },
  3261. "json"
  3262. );
  3263. });
  3264. $(".rate.slider").slider(
  3265. options.rate
  3266. ).bind("slide", function (event, ui) {
  3267. $.get(
  3268. "admin/state",
  3269. { "rate": Math.pow(10, Number(ui.value)) },
  3270. function (data) {
  3271. state = data;
  3272. $(".rate.slider").slider("value", Math.log(state.rate) / Math.LN10);
  3273. if (state.rate < 1.0) {
  3274. var label_rate = 1.0 / state.rate;
  3275. }
  3276. else {
  3277. var label_rate = state.rate;
  3278. }
  3279. var label = label_rate.toFixed(2).toString().replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
  3280. if (state.rate < 1.0) {
  3281. label = "&#x2215; " + label;
  3282. } else {
  3283. label = label + " &times;";
  3284. }
  3285. $(".rate.vwf-label").html(label);
  3286. },
  3287. "json"
  3288. );
  3289. });
  3290. this.timelineInit = true;
  3291. }
  3292. if (!this.editorOpen) {
  3293. $(timeline).show('slide', { direction: 'right' }, 175);
  3294. }
  3295. else {
  3296. $(timeline).show();
  3297. }
  3298. }
  3299. // -- Show Code Editor tab
  3300. function showCodeEditorTab() // invoke with the view as "this"
  3301. {
  3302. var self = this;
  3303. var codeEditor = this.codeEditor;
  3304. if (!this.codeEditorInit) {
  3305. $('#codeEditor_tab').append("<div class='header'>Live Code Editor</div>");
  3306. $('#codeEditor_tab').append("<div style='padding:6px'><input type='button' id='min' value='Min Window' /><span> </span><input class='live_button' type='button' id='printit' value='Print It' /><span> </span><input class='live_button' type='button' id='doit' value='Do It' /></div>");
  3307. $("#doit").click(function (evt) {
  3308. codeEditorDoit.call(self, editor, sceneID);
  3309. });
  3310. $("#printit").click(function (evt) {
  3311. codeEditorPrintit.call(self, editor, sceneID);
  3312. });
  3313. // $('#codeEditor_tab').append("<div style='padding:6px'></div>");
  3314. $('#min').click(function (evt) {
  3315. $('#editor').animate({ 'left': "-260px" }, 175);
  3316. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3317. });
  3318. //Open Live Editor
  3319. $('#codeEditor_tab').append('<div id="editorlive">console.log("test")</div>');
  3320. var sceneID = self.kernel.application();
  3321. var editor = createAceEditor(self, sceneID);
  3322. editor.on('blur', function (event, editor) {
  3323. // $('#editor').animate({ 'left' : "-260px" }, 175);
  3324. // $('.vwf-tree').animate({ 'width' : "260px" }, 175);
  3325. });
  3326. this.codeEditorInit = true;
  3327. }
  3328. if (!this.editorOpen) {
  3329. $(codeEditor).show('slide', { direction: 'right' }, 175);
  3330. }
  3331. else {
  3332. $(codeEditor).show();
  3333. // $('#editor').animate({ 'left' : "-500px" }, 175);
  3334. // $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  3335. }
  3336. }
  3337. function codeEditorDoit(editor, nodeID) {
  3338. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3339. if (selectedText == "") {
  3340. var currline = editor.getSelectionRange().start.row;
  3341. var selectedText = editor.session.getLine(currline);
  3342. }
  3343. //console.log(selectedText);
  3344. //var sceneID = self.kernel.application();
  3345. vwf_view.kernel.execute(nodeID, selectedText);
  3346. }
  3347. function codeEditorPrintit(editor, nodeID) {
  3348. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3349. if (selectedText == "") {
  3350. var currline = editor.getSelectionRange().start.row;
  3351. var selectedText = editor.session.getLine(currline);
  3352. }
  3353. //console.log(selectedText);
  3354. //var sceneID = self.kernel.application();
  3355. let scriptText = 'console.log(' + selectedText + ');'
  3356. self.kernel.execute(nodeID, scriptText);
  3357. }
  3358. // -- showAboutTab ----------------------------------------------------------------------
  3359. function showAboutTab() // invoke with the view as "this"
  3360. {
  3361. var about = this.about;
  3362. if (!this.aboutInit) {
  3363. $('#about_tab').append("<div id='aboutHeader' class='header'>About</div>" +
  3364. "<div class='about'><p style='font:bold 12pt Arial'>Virtual World Framework & LiveCode editor</p>" +
  3365. "<p><b>Version: </b> 0.1 <b>VWF version: </b>" + version.toString() + "</p>" +
  3366. "<p><b>This project site: </b><a href='http://demo.krestianstvo.org' target='_blank'>http://demo.krestianstvo.org</a></p>" +
  3367. "<p><b>Site VWF: </b><a href='http://virtualworldframework.com' target='_blank'>http://virtualworldframework.com</a></p>" +
  3368. "<p><b>Project source: </b><a href='https://github.com/NikolaySuslov/vwf/tree/aframe' target='_blank'>https://github.com/NikolaySuslov/vwf/tree/aframe</a></p></div>");
  3369. let anotherCell =
  3370. {
  3371. $cell: true,
  3372. $text: "About: ",
  3373. class: "mdc-typography--display2",
  3374. $type: "h2"
  3375. }
  3376. let andAnotherCell =
  3377. {
  3378. $cell: true,
  3379. $text: "hello world"
  3380. }
  3381. document.querySelector("#aboutHeader").$cell({
  3382. $cell: true,
  3383. class: 'header',
  3384. $components: [anotherCell, andAnotherCell]
  3385. });
  3386. // document.querySelector("body").$cell({
  3387. // $cell: true,
  3388. // $components: [toolbarCell]
  3389. // });
  3390. this.aboutInit = true;
  3391. }
  3392. if (!this.editorOpen) {
  3393. $(about).show('slide', { direction: 'right' }, 175);
  3394. }
  3395. else {
  3396. $(about).show();
  3397. }
  3398. }
  3399. // -- showModelsTab ----------------------------------------------------------------------
  3400. function showModelsTab(modelID, modelURL) // invoke with the view as "this"
  3401. {
  3402. var self = this;
  3403. var models = this.models;
  3404. var modelsTemp = this.modelsTemp;
  3405. this.currentModelID = modelID;
  3406. this.currentModelURL = modelURL;
  3407. $(models).html("");
  3408. if (modelID == "") {
  3409. $(modelsTemp).html("<div class='header'>Models</div>");
  3410. $.getJSON("admin/models", function (data) {
  3411. if (data.length > 0) {
  3412. $.each(data, function (key, value) {
  3413. var fileName = encodeURIComponent(value['basename']);
  3414. var divId = fileName;
  3415. if (divId.indexOf('.') != -1) {
  3416. divId = divId.replace(/\./g, "_");
  3417. }
  3418. var url = value['url'];
  3419. $(modelsTemp).append("<div class='childContainer'><div id='" + divId + "' class='modelEntry' data-url='" + url + "'>"
  3420. + fileName + "</div></div>");
  3421. $("#" + divId).click(function (e) {
  3422. modelDrillDown.call(self, e.target.textContent, e.target.getAttribute("data-url"));
  3423. })
  3424. });
  3425. }
  3426. else {
  3427. $(modelsTemp).append("<div class='childEntry'><p style='font:bold 12pt Arial'>No Models Found</p></div>");
  3428. }
  3429. });
  3430. }
  3431. else {
  3432. var divId = modelID;
  3433. if (divId.indexOf('.') != -1) {
  3434. divId = divId.replace(/\./g, "_");
  3435. }
  3436. $(modelsTemp).html("<div id='" + divId + "-backDiv' class='header'><img src='images/back.png' id='" + divId + "-back' alt='back'/>" + modelID + "</div>");
  3437. $("#" + divId + "-back").click(function (e) {
  3438. modelDrillUp.call(self, '');
  3439. });
  3440. $(modelsTemp).append("<div id='" + divId + "-rotation' class='propEntry'><table><tr><td><b>Rotation</b></td><td>" +
  3441. "<input type='text' class='input_text' id='input-" + divId + "-rotation' value='[1,0,0,0]'></td></tr></table></div>");
  3442. $('#input-' + divId + '-rotation').keydown(function (evt) {
  3443. evt.stopPropagation();
  3444. });
  3445. $('#input-' + divId + '-rotation').keypress(function (evt) {
  3446. evt.stopPropagation();
  3447. });
  3448. $('#input-' + divId + '-rotation').keyup(function (evt) {
  3449. evt.stopPropagation();
  3450. });
  3451. $(modelsTemp).append("<div id='" + divId + "-scale' class='propEntry'><table><tr><td><b>Scale</b></td><td>" +
  3452. "<input type='text' class='input_text' id='input-" + divId + "-scale' value='[1,1,1]'></td></tr></table></div>");
  3453. $('#input-' + divId + '-scale').keydown(function (evt) {
  3454. evt.stopPropagation();
  3455. });
  3456. $('#input-' + divId + '-scale').keypress(function (evt) {
  3457. evt.stopPropagation();
  3458. });
  3459. $('#input-' + divId + '-scale').keyup(function (evt) {
  3460. evt.stopPropagation();
  3461. });
  3462. $(modelsTemp).append("<div id='" + divId + "-translation' class='propEntry'><table><tr><td><b>Translation Offset</b></td><td>" +
  3463. "<input type='text' class='input_text' id='input-" + divId + "-translation' value='[0,0,0]'></td></tr></table></div>");
  3464. $('#input-' + divId + '-translation').keydown(function (evt) {
  3465. evt.stopPropagation();
  3466. });
  3467. $('#input-' + divId + '-translation').keypress(function (evt) {
  3468. evt.stopPropagation();
  3469. });
  3470. $('#input-' + divId + '-translation').keyup(function (evt) {
  3471. evt.stopPropagation();
  3472. });
  3473. $(modelsTemp).append("<div class='drag'><div id='" + divId + "-drag' class='modelEntry' draggable='true' data-escaped-name='" + divId + "' data-url='" + modelURL + "'>Drag To Create</div></div>");
  3474. $("#" + divId + "-drag").on("dragstart", function (e) {
  3475. var fileName = $("#" + e.target.getAttribute("data-escaped-name") + "-backDiv").text();
  3476. var rotation = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-rotation").val());
  3477. var scale = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-scale").val());
  3478. var translation = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-translation").val());
  3479. var fileData = "{\"fileName\":\"" + fileName + "\", \"fileUrl\":\"" + e.target.getAttribute("data-url") + "\", " +
  3480. "\"rotation\":\"" + rotation + "\", \"scale\":\"" + scale + "\", \"translation\":\"" + translation + "\"}";
  3481. e.originalEvent.dataTransfer.setData('text/plain', fileData);
  3482. e.originalEvent.dataTransfer.setDragImage(e.target, 0, 0);
  3483. return true;
  3484. });
  3485. }
  3486. }
  3487. // -- Model drillDown -------------------------------------------------------------------------
  3488. function modelDrillDown(modelID, modelURL) // invoke with the view as "this"
  3489. {
  3490. var models = this.models;
  3491. var modelsTemp = this.modelsTemp;
  3492. showModelsTab.call(this, modelID, modelURL);
  3493. if (modelID != "") $(models).hide('slide', { direction: 'left' }, 175);
  3494. $(modelsTemp).show('slide', { direction: 'right' }, 175);
  3495. this.models = modelsTemp;
  3496. this.modelsTemp = models;
  3497. }
  3498. // -- Model drillUp ---------------------------------------------------------------------------
  3499. function modelDrillUp(modelID) // invoke with the view as "this"
  3500. {
  3501. var models = this.models;
  3502. var modelsTemp = this.modelsTemp;
  3503. showModelsTab.call(this, modelID);
  3504. $(models).hide('slide', { direction: 'right' }, 175);
  3505. $(modelsTemp).show('slide', { direction: 'left' }, 175);
  3506. this.models = modelsTemp;
  3507. this.modelsTemp = models;
  3508. }
  3509. // -- SaveStateAsFile -------------------------------------------------------------------------
  3510. function saveStateAsFile(filename) // invoke with the view as "this"
  3511. {
  3512. this.logger.info("Saving: " + filename);
  3513. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  3514. if (supportAjaxUploadWithProgress.call(this)) {
  3515. var xhr = new XMLHttpRequest();
  3516. // Save State Information
  3517. var state = vwf.getState();
  3518. state.nodes[0].children = {};
  3519. var timestamp = state["queue"].time;
  3520. timestamp = Math.round(timestamp * 1000);
  3521. var objectIsTypedArray = function (candidate) {
  3522. var typedArrayTypes = [
  3523. Int8Array,
  3524. Uint8Array,
  3525. // Uint8ClampedArray,
  3526. Int16Array,
  3527. Uint16Array,
  3528. Int32Array,
  3529. Uint32Array,
  3530. Float32Array,
  3531. Float64Array
  3532. ];
  3533. var isTypedArray = false;
  3534. if (typeof candidate == "object" && candidate != null) {
  3535. typedArrayTypes.forEach(function (typedArrayType) {
  3536. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  3537. });
  3538. }
  3539. return isTypedArray;
  3540. };
  3541. var transitTransformation = function (object) {
  3542. return objectIsTypedArray(object) ?
  3543. Array.prototype.slice.call(object) : object;
  3544. };
  3545. var json = JSON.stringify(
  3546. require("vwf/utility").transform(
  3547. state, transitTransformation
  3548. )
  3549. );
  3550. json = $.encoder.encodeForURL(json);
  3551. var path = window.location.pathname;
  3552. var pathSplit = path.split('/');
  3553. if (pathSplit[0] == "") {
  3554. pathSplit.shift();
  3555. }
  3556. if (pathSplit[pathSplit.length - 1] == "") {
  3557. pathSplit.pop();
  3558. }
  3559. var inst = undefined;
  3560. var instIndex = pathSplit.length - 1;
  3561. if (pathSplit.length > 2) {
  3562. if (pathSplit[pathSplit.length - 2] == "load") {
  3563. instIndex = pathSplit.length - 3;
  3564. }
  3565. }
  3566. if (pathSplit.length > 3) {
  3567. if (pathSplit[pathSplit.length - 3] == "load") {
  3568. instIndex = pathSplit.length - 4;
  3569. }
  3570. }
  3571. inst = pathSplit[instIndex];
  3572. var root = "";
  3573. for (var i = 0; i < instIndex; i++) {
  3574. if (root != "") {
  3575. root = root + "/";
  3576. }
  3577. root = root + pathSplit[i];
  3578. }
  3579. if (filename == '') filename = inst;
  3580. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  3581. xhr.open("POST", "/" + root + "/save/" + filename, true);
  3582. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3583. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  3584. // Save Config Information
  3585. var config = { "info": {}, "model": {}, "view": {} };
  3586. // Save browser title
  3587. config["info"]["title"] = $('title').html();
  3588. // Save model drivers
  3589. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  3590. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  3591. });
  3592. // If neither glge or threejs model drivers are defined, specify nodriver
  3593. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  3594. // Save view drivers and associated parameters, if any
  3595. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  3596. if (viewDriver.indexOf('vwf/view/') != -1) {
  3597. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  3598. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  3599. }
  3600. else config["view"][viewDriver] = "";
  3601. }
  3602. });
  3603. var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  3604. // Save config file to server
  3605. var xhrConfig = new XMLHttpRequest();
  3606. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  3607. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3608. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  3609. }
  3610. else {
  3611. console.error("Unable to save state.");
  3612. }
  3613. }
  3614. // -- LoadSavedState --------------------------------------------------------------------------
  3615. function loadSavedState(filename, applicationpath, revision) {
  3616. this.logger.info("Loading: " + filename);
  3617. // Redirect until setState ID conflict is resolved
  3618. var path = window.location.pathname;
  3619. var inst = path.substring(path.length - 17, path.length - 1);
  3620. var pathSplit = path.split('/');
  3621. if (pathSplit[0] == "") {
  3622. pathSplit.shift();
  3623. }
  3624. if (pathSplit[pathSplit.length - 1] == "") {
  3625. pathSplit.pop();
  3626. }
  3627. var inst = undefined;
  3628. var instIndex = pathSplit.length - 1;
  3629. if (pathSplit.length > 2) {
  3630. if (pathSplit[pathSplit.length - 2] == "load") {
  3631. instIndex = pathSplit.length - 3;
  3632. }
  3633. }
  3634. if (pathSplit.length > 3) {
  3635. if (pathSplit[pathSplit.length - 3] == "load") {
  3636. instIndex = pathSplit.length - 4;
  3637. }
  3638. }
  3639. inst = pathSplit[instIndex];
  3640. if (revision) {
  3641. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  3642. }
  3643. else {
  3644. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  3645. }
  3646. // $.get(filename,function(data,status){
  3647. // vwf.setState(data);
  3648. // });
  3649. }
  3650. // -- SupportAjax -----------------------------------------------------------------------------
  3651. function supportAjaxUploadWithProgress() {
  3652. return supportAjaxUploadProgressEvents();
  3653. function supportAjaxUploadProgressEvents() {
  3654. var xhr = new XMLHttpRequest();
  3655. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  3656. }
  3657. }
  3658. });