editor-new.js 172 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861
  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. "vwf/view/lib/colorpicker/colorpicker.min",
  27. "vwf/view/widgets"
  28. ], function (module, version, view, utility, ace, colorpicker, widgets) {
  29. var self;
  30. return view.load(module, {
  31. // == Module Definition ====================================================================
  32. initialize: function () {
  33. self = this;
  34. this.ace = window.ace;
  35. this.widgets = widgets;
  36. this.nodes = {};
  37. this.scenes = {};
  38. this.allScripts = {};
  39. //$(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  40. document.querySelector('head').innerHTML += '<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>';
  41. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  42. //document.querySelector('head').innerHTML += '<script type="text/javascript" src="vwf/view/lib/colorpicker/colorpicker.min.js">';
  43. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/colorpicker/themes.css">';
  44. //$(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  45. document.querySelector('head').innerHTML += '<meta name="viewport" content="width=device-width, initial-scale=1">';
  46. // $('body').append('<script>mdc.autoInit()</script>');
  47. this.removeProps = (obj) => {
  48. Object.keys(obj).forEach(key =>
  49. (key === 'id' || key === 'patches' || key === 'random' || key === 'sequence') && delete obj[key] ||
  50. (obj[key] && typeof obj[key] === 'object') && this.removeProps(obj[key])
  51. );
  52. return obj;
  53. };
  54. this.getNodeDef = function (nodeID) {
  55. let node = vwf.getNode(nodeID, true);
  56. let nodeDef = self.removeProps(node);
  57. return nodeDef
  58. }
  59. this.GUID = function () {
  60. var S4 = function () {
  61. return Math.floor(
  62. Math.random() * 0x10000 /* 65536 */
  63. ).toString(16);
  64. };
  65. return (
  66. S4() + S4() + "-" +
  67. S4() + "-" +
  68. S4() + "-" +
  69. S4() + "-" +
  70. S4() + S4() + S4()
  71. );
  72. }
  73. this.getRoot = function () {
  74. var app = window.location.pathname;
  75. var pathSplit = app.split('/');
  76. if (pathSplit[0] == "") {
  77. pathSplit.shift();
  78. }
  79. if (pathSplit[pathSplit.length - 1] == "") {
  80. pathSplit.pop();
  81. }
  82. var instIndex = pathSplit.length - 1;
  83. if (pathSplit.length > 2) {
  84. if (pathSplit[pathSplit.length - 2] == "load") {
  85. instIndex = pathSplit.length - 3;
  86. }
  87. }
  88. if (pathSplit.length > 3) {
  89. if (pathSplit[pathSplit.length - 3] == "load") {
  90. instIndex = pathSplit.length - 4;
  91. }
  92. }
  93. var root = "";
  94. for (var i = 0; i < instIndex; i++) {
  95. if (root != "") {
  96. root = root + "/";
  97. }
  98. root = root + pathSplit[i];
  99. }
  100. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  101. return root
  102. };
  103. this.getRandomInt = function (min, max) {
  104. min = Math.ceil(min);
  105. max = Math.floor(max);
  106. return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
  107. };
  108. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  109. let el = document.createElement("div");
  110. el.setAttribute("id", item);
  111. document.body.appendChild(el);
  112. }
  113. );
  114. this.avatarCardDef = function (src, desc, onclickfunc) {
  115. return {
  116. $cell: true,
  117. $type: "div",
  118. class: "mdc-card avatar-card",
  119. $init: function () {
  120. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  121. },
  122. onclick: onclickfunc,
  123. $components: [
  124. {
  125. $type: "section",
  126. class: "mdc-card__primary",
  127. $components: [
  128. {
  129. $type: "h1",
  130. class: "mdc-card__title mdc-card__title--large",
  131. $text: desc.subtitle
  132. },
  133. {
  134. $type: "h2",
  135. class: "mdc-card__subtitle",
  136. $text: desc.title
  137. }
  138. ]
  139. },
  140. {
  141. $type: "section",
  142. class: "mdc-card__actions",
  143. $components: [
  144. {
  145. $type: "button",
  146. class: "mdc-button mdc-button--compact mdc-card__action",
  147. //$text: "Use it",
  148. onclick: onclickfunc
  149. }
  150. ]
  151. }
  152. ]
  153. }
  154. }
  155. let createSettings =
  156. {
  157. $cell: true,
  158. $type: "div",
  159. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  160. $components: [
  161. {
  162. $cell: true,
  163. $type: "div",
  164. class: "mdc-layout-grid__inner",
  165. $components: [
  166. {
  167. $cell: true,
  168. $type: "div",
  169. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  170. $components: [
  171. {
  172. $cell: true,
  173. $type: "h3",
  174. class: "mdc-typography--headline",
  175. $text: "Primitives"
  176. }
  177. ]
  178. },
  179. {
  180. $cell: true,
  181. $type: "div",
  182. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  183. $components: [
  184. widgets.simpleCard(
  185. {
  186. "imgSrc": "vwf/view/lib/images/ui/cube_normal.png",
  187. "imgHeight": "100px",
  188. "addonClass": "create-card",
  189. "text": "Cube",
  190. "onclickfunc": function(){
  191. let avatarID = 'avatar-' + vwf.moniker_;
  192. //let cubeName = self.GUID();
  193. vwf_view.kernel.callMethod(vwf.application(), "createPrimitive", ["cube", avatarID])
  194. }
  195. }
  196. )
  197. ]
  198. },
  199. {
  200. $cell: true,
  201. $type: "div",
  202. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  203. $components: [
  204. widgets.simpleCard(
  205. {
  206. "imgSrc": "vwf/view/lib/images/ui/sphere_normal.png",
  207. "imgHeight": "100px",
  208. "addonClass": "create-card",
  209. "text": "Sphere",
  210. "onclickfunc": function(){
  211. let avatarID = 'avatar-' + vwf.moniker_;
  212. //let cubeName = self.GUID();
  213. vwf_view.kernel.callMethod(vwf.application(), "createPrimitive", ["sphere", avatarID])
  214. }
  215. }
  216. )
  217. ]
  218. },
  219. // {
  220. // $cell: true,
  221. // $type: "div",
  222. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  223. // $components: [
  224. // widgets.simpleCard(
  225. // {
  226. // "imgSrc": "vwf/view/lib/images/ui/cylinder_normal.png",
  227. // "imgHeight": "100px",
  228. // "text": "Cylinder"
  229. // }
  230. // )
  231. // ]
  232. // }
  233. ]
  234. },
  235. {
  236. $cell: true,
  237. $type: "div",
  238. class: "mdc-layout-grid__inner",
  239. $components: [
  240. {
  241. $cell: true,
  242. $type: "div",
  243. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  244. $components: [
  245. {
  246. $cell: true,
  247. $type: "h3",
  248. class: "mdc-typography--headline",
  249. $text: "Assets"
  250. }
  251. ]
  252. },
  253. {
  254. $cell: true,
  255. $type: "div",
  256. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  257. $components: [
  258. widgets.simpleCard(
  259. {
  260. "imgSrc": "vwf/view/lib/images/ui/standard.png",
  261. "imgHeight": "100px",
  262. "addonClass": "create-card",
  263. "text": "2D Image",
  264. "onclickfunc": function(){
  265. //let cubeName = self.GUID();
  266. vwf_view.kernel.callMethod(vwf.application(), "createAssetItemImg")
  267. }
  268. }
  269. )
  270. ]
  271. }
  272. ]
  273. }
  274. ]
  275. }
  276. let avatarSettings =
  277. {
  278. $cell: true,
  279. $type: "div",
  280. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  281. $components: [
  282. {
  283. $cell: true,
  284. $type: "div",
  285. class: "mdc-layout-grid__inner",
  286. $components: [
  287. {
  288. $cell: true,
  289. $type: "div",
  290. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  291. $components: [
  292. widgets.buttonStroked(
  293. {
  294. "label": "Go forward",
  295. "onclick": function (e) {
  296. function getMovementVector(el) {
  297. var directionVector = new THREE.Vector3(0, 0, 0);
  298. var rotationEuler = new THREE.Euler(0, 0, 0, 'YXZ');
  299. var rotation = el.getAttribute('rotation');
  300. var velocity = new THREE.Vector3(0, 0, -0.5);
  301. var xRotation;
  302. directionVector.copy(velocity);
  303. directionVector.multiplyScalar(1.0);
  304. // Absolute.
  305. if (!rotation) { return directionVector; }
  306. xRotation = 0;
  307. // Transform direction relative to heading.
  308. rotationEuler.set(THREE.Math.degToRad(xRotation), THREE.Math.degToRad(rotation.y), 0);
  309. directionVector.applyEuler(rotationEuler);
  310. return directionVector;
  311. }
  312. let el = document.querySelector('#avatarControl');
  313. let currentPosition = el.getAttribute('position');
  314. let movementVector = getMovementVector(el);
  315. let position = {};
  316. position.x = currentPosition.x + movementVector.x;
  317. position.y = currentPosition.y + movementVector.y;
  318. position.z = currentPosition.z + movementVector.z;
  319. el.setAttribute('position', position);
  320. }
  321. })
  322. ]
  323. },
  324. {
  325. $cell: true,
  326. $type: "div",
  327. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  328. $components: [
  329. widgets.buttonStroked(
  330. {
  331. "label": "Reset camera view",
  332. "onclick": function (e) {
  333. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  334. let controlEl = document.querySelector('#avatarControl');
  335. controlEl.setAttribute('camera', 'active', true);
  336. }
  337. }),
  338. widgets.buttonStroked(
  339. {
  340. "label": "Hide cursor",
  341. "onclick": function (e) {
  342. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  343. let avatarID = 'avatar-' + self.kernel.moniker();
  344. let cursorID = 'myCursor-' + avatarID;
  345. let controlEl = document.querySelector("[id='" + cursorID + "']");
  346. let vis = controlEl.getAttribute('visible');
  347. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  348. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  349. //controlEl.setAttribute('visible', !vis);
  350. }
  351. }),
  352. widgets.buttonStroked(
  353. {
  354. "label": "Hide Avatar",
  355. "onclick": function (e) {
  356. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  357. let avatarID = 'avatar-' + self.kernel.moniker();
  358. //let cursorID = 'myCursor-' + avatarID;
  359. let controlEl = document.querySelector("[id='" + avatarID + "']");
  360. let vis = controlEl.getAttribute('visible');
  361. this.$text = vis ? 'Show Avatar' : 'Show Avatar';
  362. vwf_view.kernel.callMethod(avatarID, "showHideAvatar", [!vis]);
  363. //controlEl.setAttribute('visible', !vis);
  364. }
  365. }
  366. )
  367. ]
  368. },
  369. {
  370. $cell: true,
  371. $type: "div",
  372. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  373. $components: [
  374. {
  375. $type: "div",
  376. class: "mdc-layout-grid",
  377. $components: [
  378. {
  379. $type: "div",
  380. class: "mdc-layout-grid__inner",
  381. $components: [
  382. {
  383. $cell: true,
  384. $type: "div",
  385. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  386. $components: [
  387. self.avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  388. function (e) {
  389. let avatarID = 'avatar-' + self.kernel.moniker();
  390. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  391. }
  392. )
  393. ]
  394. },
  395. {
  396. $cell: true,
  397. $type: "div",
  398. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  399. $components: [
  400. self.avatarCardDef("/assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  401. function (e) {
  402. let avatarID = 'avatar-' + self.kernel.moniker();
  403. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/assets/avatars/female/avatar1.gltf"]);
  404. }
  405. )]
  406. },
  407. {
  408. $cell: true,
  409. $type: "div",
  410. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  411. $components: [
  412. self.avatarCardDef("/assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  413. function (e) {
  414. let avatarID = 'avatar-' + self.kernel.moniker();
  415. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/assets/avatars/male/avatar1.gltf"]);
  416. }
  417. )]
  418. }
  419. ]
  420. }
  421. ]
  422. }
  423. ]
  424. },
  425. {
  426. $cell: true,
  427. $type: "div",
  428. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  429. $components: [
  430. widgets.buttonStroked(
  431. {
  432. "label": "Wide",
  433. "onclick": function (e) {
  434. let avatarID = 'avatar-'+vwf.moniker_;
  435. vwf_view.kernel.callMethod(avatarID, "setBigVideoHead", []);
  436. }
  437. }),
  438. widgets.buttonStroked(
  439. {
  440. "label": "Small",
  441. "onclick": function (e) {
  442. let avatarID = 'avatar-'+vwf.moniker_;
  443. vwf_view.kernel.callMethod(avatarID, "setSmallVideoHead", []);
  444. }
  445. })
  446. ]
  447. }
  448. ]
  449. }
  450. ]
  451. }
  452. let viewSettings =
  453. {
  454. $cell: true,
  455. $type: "div",
  456. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  457. $components: [
  458. {
  459. $cell: true,
  460. $type: "div",
  461. class: "mdc-layout-grid__inner",
  462. $components: [
  463. {
  464. $cell: true,
  465. $type: "div",
  466. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  467. $components: [
  468. widgets.buttonStroked(
  469. {
  470. "label": "OSC Settings",
  471. "onclick": function (e) {
  472. let sideBar = document.querySelector('#sideBar');
  473. sideBar._sideBarComponent = oscSettings;
  474. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  475. }
  476. })
  477. ]
  478. }
  479. ]
  480. }
  481. ]
  482. }
  483. let savedStateEl = function (item) {
  484. return {
  485. $type: "li",
  486. class: "mdc-list-item",
  487. role: "option",
  488. $components: [
  489. {
  490. $text: "Saved world"
  491. }
  492. ]
  493. }
  494. }
  495. let stateListElement = function (item) {
  496. let liEl = {
  497. $type: "li",
  498. class: "mdc-list-item",
  499. role: "option",
  500. id: "",
  501. tabindex: "0",
  502. applicationpath: "",
  503. $components: [
  504. {
  505. $text: "no saves"
  506. }
  507. ]
  508. }
  509. let applicationName = item.applicationpath.split("/");
  510. if (applicationName == "") {
  511. return liEl
  512. }
  513. if (applicationName.length > 0) {
  514. applicationName = applicationName[applicationName.length - 1];
  515. }
  516. if (applicationName.length > 0) {
  517. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  518. }
  519. if (item.latestsave) {
  520. liEl = {
  521. $type: "li",
  522. class: "mdc-list-item",
  523. role: "option",
  524. tabindex: "0",
  525. id: item.savename,
  526. applicationpath: item.applicationpath,
  527. $components: [
  528. {
  529. $text: applicationName + ": " + item.savename
  530. }
  531. ]
  532. }
  533. }
  534. else {
  535. liEl = {
  536. $type: "li",
  537. class: "mdc-list-item",
  538. role: "option",
  539. tabindex: "0",
  540. id: item.savename,
  541. revision: item.revision,
  542. applicationpath: item.applicationpath,
  543. $components: [
  544. {
  545. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  546. }
  547. ]
  548. }
  549. }
  550. return liEl
  551. }
  552. let oscSettings =
  553. {
  554. $cell: true,
  555. $type: "div",
  556. id: "oscSettings",
  557. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  558. _oscHost: '',
  559. _oscPort: '',
  560. _oscStatus: '',
  561. _updateStatus: function () {
  562. this._oscStatus = window._OSCManager.getStatus()
  563. },
  564. $init: function () {
  565. if (window._OSCManager) {
  566. this._oscHost = window._OSCManager.hostValue;
  567. this._oscPort = window._OSCManager.portValue;
  568. this._oscStatus = window._OSCManager.getStatus();
  569. // var t = this;
  570. // setInterval(function () {
  571. // t._updateStatus();
  572. // }, 1000);
  573. }
  574. },
  575. $update: function () {
  576. let that = this
  577. var buttonText = "Connect";
  578. var buttonFunc = function (e) {
  579. }
  580. if (this._oscStatus == 1) {
  581. buttonText = "Disconnect";
  582. buttonFunc = function (e) {
  583. window._OSCManager.disconnect();
  584. }
  585. } else {
  586. var buttonFunc = function (e) {
  587. window._OSCManager.connect();
  588. window._OSCManager.port.on("open", function () {
  589. that._oscStatus = window._OSCManager.getStatus();
  590. console.log("connected");
  591. });
  592. window._OSCManager.port.on("close", function () {
  593. that._oscStatus = window._OSCManager.getStatus();
  594. console.log("disconnected");
  595. });
  596. }
  597. }
  598. this.$components = [
  599. {
  600. $cell: true,
  601. $type: "div",
  602. class: "mdc-layout-grid__inner",
  603. $components: [
  604. {
  605. $cell: true,
  606. $type: "div",
  607. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  608. $components: [
  609. {
  610. $type: "span",
  611. $text: "Host: "
  612. },
  613. {
  614. class: "mdc-text-field",
  615. $cell: true,
  616. $type: "span",
  617. $components: [
  618. {
  619. class: "mdc-text-field__input prop-text-field-input",
  620. id: "oscHost",
  621. $cell: true,
  622. $type: "input",
  623. type: "text",
  624. value: this._oscHost,
  625. onchange: function (e) {
  626. this._oscHost = this.value;
  627. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  628. }
  629. }
  630. ]
  631. }
  632. ]
  633. },
  634. {
  635. $cell: true,
  636. $type: "div",
  637. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  638. $components: [
  639. {
  640. $type: "span",
  641. $text: "Port: "
  642. },
  643. {
  644. class: "mdc-text-field",
  645. $cell: true,
  646. $type: "span",
  647. $components: [
  648. {
  649. class: "mdc-text-field__input prop-text-field-input",
  650. id: "oscPort",
  651. $cell: true,
  652. $type: "input",
  653. type: "text",
  654. value: this._oscPort,
  655. onchange: function (e) {
  656. this._oscPort = this.value;
  657. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  658. }
  659. }
  660. ]
  661. }
  662. ]
  663. },
  664. {
  665. $cell: true,
  666. $type: "div",
  667. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  668. $components: [
  669. widgets.buttonStroked(
  670. {
  671. "label": buttonText,
  672. "onclick": buttonFunc
  673. })
  674. ]
  675. }
  676. ]
  677. }
  678. ]
  679. }
  680. }
  681. let loadSaveSettings =
  682. {
  683. $cell: true,
  684. $type: "div",
  685. id: "loadSaveSettings",
  686. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  687. _saveStates: [],
  688. _getStates: async function () {
  689. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  690. let data = await response.json();
  691. //this._saveStates = data;
  692. //let appName = self.getRoot();
  693. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  694. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  695. if (filterData.length !== 0) {
  696. this._saveStates = filterData
  697. //return filterData
  698. } else {
  699. this._saveStates = [{
  700. savename: "",
  701. latestsave: "",
  702. revision: "",
  703. applicationpath: "",
  704. url: ""
  705. }]
  706. }
  707. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  708. //return data
  709. //console.log(data);
  710. return this._saveStates
  711. },
  712. $init: function () {
  713. this._getStates();
  714. },
  715. $update: function () {
  716. this.$components =
  717. [
  718. {
  719. $cell: true,
  720. $type: "div",
  721. class: "mdc-layout-grid__inner",
  722. $components: [
  723. {
  724. $cell: true,
  725. $type: "div",
  726. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  727. $components: [
  728. {
  729. class: "mdc-text-field",
  730. $cell: true,
  731. $type: "span",
  732. $components: [
  733. {
  734. class: "mdc-text-field__input prop-text-field-input",
  735. id: "fileName",
  736. $cell: true,
  737. $type: "input",
  738. type: "text",
  739. value: self.getRoot()
  740. }]
  741. }
  742. ]
  743. },
  744. {
  745. $cell: true,
  746. $type: "div",
  747. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  748. $components: [
  749. widgets.buttonStroked(
  750. {
  751. "label": "Save",
  752. "onclick": function (e) {
  753. let fileName = document.querySelector('#fileName')
  754. saveStateAsFile.call(self, fileName.value);
  755. document.querySelector("#fileName").value = '';
  756. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  757. }
  758. })
  759. ]
  760. },
  761. {
  762. $cell: true,
  763. $type: "div",
  764. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  765. $components: [
  766. {
  767. $cell: true,
  768. $type: "div",
  769. class: "mdc-select",
  770. tabindex: "0",
  771. role: "listbox",
  772. id: "loadselect",
  773. $init: function () {
  774. setTimeout(function() {
  775. var MDCSelect = mdc.select.MDCSelect;
  776. let selector = document.querySelector('#loadselect');
  777. let select = new MDCSelect(selector);
  778. selector.addEventListener('MDCSelect:change', () => {
  779. //this._selectedState = select.value;
  780. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  781. //console.log(select.value);
  782. //.selectedOptions[0]
  783. });
  784. }, 300);
  785. },
  786. $components: [
  787. {
  788. $type: "div",
  789. class: "mdc-select__surface mdc-ripple-upgraded",
  790. $components: [
  791. {
  792. $type: "div",
  793. class: "mdc-select__label",
  794. $text: "Select..."
  795. },
  796. {
  797. $type: "div",
  798. class: "mdc-select__selected-text"
  799. },
  800. {
  801. $type: "div",
  802. class: "mdc-select__bottom-line"
  803. }
  804. ]
  805. },
  806. {
  807. $type: "div",
  808. class: "mdc-simple-menu mdc-select__menu",
  809. $components: [
  810. {
  811. $type: "ul",
  812. class: "mdc-list mdc-simple-menu__items",
  813. $components: this._saveStates.map(stateListElement)
  814. }
  815. ]
  816. }
  817. ]
  818. }
  819. ]
  820. },
  821. {
  822. $cell: true,
  823. $type: "div",
  824. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  825. $components: [
  826. {
  827. $cell: true,
  828. $type: "button",
  829. _selectedState: {},
  830. id: "loadStateButton",
  831. class: "mdc-button mdc-button--raised",
  832. $text: "Load",
  833. onclick: function (e) {
  834. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  835. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  836. }
  837. }
  838. ]
  839. }
  840. ]
  841. }
  842. ]
  843. }
  844. }
  845. let protoPropertiesCell = function (m) {
  846. return {
  847. $type: "div",
  848. class: "mdc-layout-grid__inner",
  849. _prop: {},
  850. $init: function () {
  851. let prop = m[1].prop;
  852. if (prop.value == undefined && this._currentNode !== undefined) {
  853. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  854. }
  855. this._prop = prop
  856. },
  857. $update: function () {
  858. this.$components = [
  859. {
  860. $type: "div",
  861. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  862. $components: [
  863. { $text: this._prop.name }
  864. ]
  865. },
  866. {
  867. $type: "div",
  868. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  869. },
  870. {
  871. $type: "div",
  872. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  873. $components: [
  874. {
  875. class: "mdc-text-field",
  876. $cell: true,
  877. $type: "div",
  878. $components: [{
  879. class: "mdc-text-field__input prop-text-field-input",
  880. $cell: true,
  881. $type: "input",
  882. type: "text",
  883. value: this._prop.getValue(),
  884. onchange: function (e) {
  885. let propValue = this.value;
  886. try {
  887. propValue = JSON.parse(propValue);
  888. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  889. } catch (e) {
  890. // restore the original value on error
  891. this.value = propValue;
  892. }
  893. }
  894. }]
  895. }
  896. ]
  897. }
  898. ]
  899. }
  900. }
  901. }
  902. let propertiesCell = function (m) {
  903. var editComponents = [{}, {}];
  904. // fullWidth:
  905. // fullHeight:
  906. // xoffset:
  907. // yoffset:
  908. // width:
  909. // height:
  910. let sliderPropNames = ['width', 'height', 'depth', 'fullWidth', 'fullHeight', 'xoffset', 'yoffset', 'subcamWidth', 'subcamHeight'];
  911. let sliderProps = {
  912. 'width': {
  913. min: 0,
  914. max: 30
  915. },
  916. 'height': {
  917. min: 0,
  918. max: 30
  919. },
  920. 'depth': {
  921. min: 0,
  922. max: 30
  923. },
  924. 'fullWidth': {
  925. min: 0,
  926. max: 5000,
  927. step:10
  928. },
  929. 'fullHeight': {
  930. min: 0,
  931. max: 5000,
  932. step:10
  933. },
  934. 'xoffset': {
  935. min: -10000,
  936. max: 10000,
  937. step: 10
  938. },
  939. 'yoffset': {
  940. min: -10000,
  941. max: 10000,
  942. step: 10
  943. },
  944. 'subcamWidth': {
  945. min: 0,
  946. max: 5000,
  947. step:10
  948. },
  949. 'subcamHeight': {
  950. min: 0,
  951. max: 5000,
  952. step:10
  953. }
  954. }
  955. if (sliderPropNames.includes(m.name)){
  956. let currenValue = JSON.parse(m.getValue());
  957. var sliderComponent = widgets.sliderContinuous({
  958. 'id': 'prop-slider-' + m.name,
  959. 'label': 'Slider',
  960. 'min': sliderProps[m.name].min,
  961. 'max': sliderProps[m.name].max,
  962. 'step': sliderProps[m.name].step ? sliderProps[m.name].step: 0.1,
  963. 'value': currenValue,
  964. 'init': function(){
  965. const myEl = this;
  966. var continuousSlider = new mdc.slider.MDCSlider(myEl);
  967. this._comp = continuousSlider;
  968. continuousSlider.listen('MDCSlider:input', function(e) {
  969. console.log(continuousSlider.value)
  970. let myEl = e.currentTarget;
  971. // let prop = myEl._prop.body;
  972. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  973. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  974. //continuousValue.textContent = continuousSlider.value;
  975. });
  976. continuousSlider.listen('MDCSlider:change', function(e) {
  977. console.log(continuousSlider.value);
  978. let myEl = e.currentTarget;
  979. // let prop = myEl._prop.body;
  980. //document.querySelector('#propAceEditor').env.editor.setValue(prop);
  981. self.kernel.setProperty(myEl._currentNode, m.name, continuousSlider.value);
  982. //continuousCommittedValue.textContent = continuousSlider.value;
  983. })
  984. }
  985. })
  986. } else {
  987. sliderComponent = {}
  988. }
  989. if (m.name.indexOf("semantics") > -1) { }
  990. else if (m.name.indexOf("grammar") > -1) { }
  991. else if (m.name.indexOf("ohm") > -1) {
  992. editComponents = [
  993. {
  994. $type: "div",
  995. $cell: true,
  996. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  997. $components: [
  998. {
  999. $cell: true,
  1000. $type: "button",
  1001. class: "mdc-button",
  1002. $text: "Edit", //edit grammar
  1003. onclick: function (e) {
  1004. var currentNode = document.querySelector('#currentNode')._currentNode;
  1005. if (currentNode == '') {
  1006. currentNode = vwf_view.kernel.find("", "/")[0];
  1007. }
  1008. let editor = document.querySelector('#livePropEditor');
  1009. editor._setNode(currentNode);
  1010. editor._propName = m.name;
  1011. editor._prop = { body: m.rawValue, type: 'complex' }
  1012. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1013. }
  1014. }
  1015. ]
  1016. },
  1017. {
  1018. $type: "div",
  1019. $cell: true,
  1020. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1021. $components: []
  1022. }
  1023. ]
  1024. } else {
  1025. editComponents = [
  1026. {
  1027. $type: "div",
  1028. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  1029. $components: [
  1030. sliderComponent,
  1031. {
  1032. class: "mdc-text-field prop-mdc-text-field mdc-ripple-upgraded",
  1033. $cell: true,
  1034. $type: "div",
  1035. $components: [
  1036. {
  1037. class: "mdc-text-field__input prop-text-field-input",
  1038. id: "prop-" + m.name,
  1039. $cell: true,
  1040. $type: "input",
  1041. type: "text",
  1042. value: m.getValue(),
  1043. onchange: function (e) {
  1044. let propValue = this.value;
  1045. try {
  1046. propValue = JSON.parse(propValue);
  1047. self.kernel.setProperty(this._currentNode, m.name, propValue);
  1048. } catch (e) {
  1049. // restore the original value on error
  1050. this.value = propValue;
  1051. }
  1052. }
  1053. }
  1054. ]
  1055. }
  1056. ]
  1057. },
  1058. {
  1059. $type: "div",
  1060. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1061. $components: [
  1062. {
  1063. $cell: true,
  1064. $type: "button",
  1065. class: "mdc-button mdc-button--compact",
  1066. $text: "^", //edit grammar
  1067. onclick: function (e) {
  1068. var currentNode = document.querySelector('#currentNode')._currentNode;
  1069. if (currentNode == '') {
  1070. currentNode = vwf_view.kernel.find("", "/")[0];
  1071. }
  1072. let editor = document.querySelector('#livePropEditor');
  1073. editor._setNode(currentNode);
  1074. editor._propName = m.name;
  1075. editor._prop = { body: m.getValue(), type: 'simple' }
  1076. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  1077. }
  1078. }
  1079. ]
  1080. }
  1081. ];
  1082. }
  1083. return {
  1084. $type: "div",
  1085. class: "mdc-layout-grid__inner",
  1086. $components: [
  1087. {
  1088. $type: "div",
  1089. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1090. $components: [
  1091. { $text: m.name }
  1092. ]
  1093. },
  1094. {
  1095. $type: "div",
  1096. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1097. },
  1098. editComponents[0],
  1099. editComponents[1]
  1100. ]
  1101. }
  1102. }
  1103. let nodeLink = function (m) {
  1104. var myClass = "nodeItem";
  1105. let myAvatarName = 'avatar-' + self.kernel.moniker();
  1106. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  1107. myClass = "nodeItem"
  1108. var nodeName = m.name;
  1109. let displayName = vwf.getProperty(m.ID, 'displayName');
  1110. if (displayName)
  1111. {
  1112. nodeName = displayName
  1113. }
  1114. return {
  1115. $type: "li",
  1116. class: "mdc-list-item",
  1117. $components: [{
  1118. $type: "a",
  1119. class: "mdc-list-item",
  1120. $href: "#",
  1121. $components: [{
  1122. $type: 'span',
  1123. class: myClass,
  1124. $text: nodeName
  1125. }
  1126. ],
  1127. onclick: function (e) {
  1128. //self.currentNodeID = m.ID;
  1129. document.querySelector('#currentNode')._setNode(m.ID);
  1130. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  1131. // createAceEditor(self, m.ID);
  1132. }
  1133. }]
  1134. }
  1135. };
  1136. let listDivider = {
  1137. $cell: true,
  1138. $type: "hr",
  1139. class: "mdc-list-divider",
  1140. }
  1141. let webrtcGUI = {
  1142. $type: "div",
  1143. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1144. $components: [
  1145. {
  1146. $type: "div",
  1147. class: "mdc-layout-grid__inner",
  1148. $components: [
  1149. {
  1150. $type: "div",
  1151. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1152. $components: [
  1153. {
  1154. $type: "span",
  1155. $text: "Chat"
  1156. }
  1157. ]
  1158. },
  1159. {
  1160. $type: "div",
  1161. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1162. $components: [
  1163. widgets.icontoggle({
  1164. 'id': "webrtcswitch",
  1165. 'label': 'visibility',
  1166. 'on': JSON.stringify({"content": "visibility", "label": "Turn On Mic"}),
  1167. 'off': JSON.stringify({"content": "visibility_off", "label": "Turn Off Mic"}),
  1168. 'state': false,
  1169. 'init': function(){
  1170. this._driver = vwf.views["vwf/view/webrtc"];
  1171. if (!this._driver) {
  1172. this.classList.add('mdc-icon-toggle--disabled');
  1173. }
  1174. this.addEventListener('MDCIconToggle:change', (e) => {
  1175. let driver = e.target._driver;
  1176. let chkAttr = e.detail.isOn;
  1177. let avatarID = 'avatar-' + self.kernel.moniker();
  1178. let micToggle = document.querySelector('#webrtcaudio');
  1179. let camToggle = document.querySelector('#webrtcvideo');
  1180. if (chkAttr) {
  1181. driver.startWebRTC(avatarID);
  1182. micToggle.classList.remove('mdc-icon-toggle--disabled');
  1183. camToggle.classList.remove('mdc-icon-toggle--disabled');
  1184. console.log("on")
  1185. } else {
  1186. driver.stopWebRTC(avatarID);
  1187. micToggle.classList.add('mdc-icon-toggle--disabled');
  1188. camToggle.classList.add('mdc-icon-toggle--disabled');
  1189. console.log("off")
  1190. }
  1191. //console.log(e, detail)
  1192. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1193. });
  1194. }
  1195. })
  1196. ]
  1197. },
  1198. {
  1199. $type: "div",
  1200. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1201. $components: [
  1202. widgets.icontoggle({
  1203. 'id': "webrtcaudio",
  1204. 'label': 'mic',
  1205. 'on': JSON.stringify({"content": "mic", "label": "Turn On Mic"}),
  1206. 'off': JSON.stringify({"content": "mic_off", "label": "Turn Off Mic"}),
  1207. 'state': false,
  1208. 'init': function(){
  1209. this._driver = vwf.views["vwf/view/webrtc"];
  1210. let webrtcswitch = document.querySelector('#webrtcswitch');
  1211. if (!this._driver) {
  1212. this.classList.add('mdc-icon-toggle--disabled');
  1213. }
  1214. this.classList.add('mdc-icon-toggle--disabled');
  1215. this.addEventListener('MDCIconToggle:change', (e) => {
  1216. let driver = e.target._driver;
  1217. let chkAttr = e.detail.isOn;
  1218. if (chkAttr) {
  1219. driver.muteAudio(chkAttr);
  1220. console.log("on")
  1221. } else {
  1222. driver.muteAudio(chkAttr);
  1223. console.log("off")
  1224. }
  1225. //console.log(e, detail)
  1226. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1227. });
  1228. }
  1229. })
  1230. ]
  1231. },
  1232. {
  1233. $type: "div",
  1234. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1235. $components: [
  1236. widgets.icontoggle({
  1237. 'id': "webrtcvideo",
  1238. 'label': 'videocam',
  1239. 'on': JSON.stringify({"content": "videocam", "label": "Turn On Video"}),
  1240. 'off': JSON.stringify({"content": "videocam_off", "label": "Turn Off Video"}),
  1241. 'state': false,
  1242. 'init': function(){
  1243. this._driver = vwf.views["vwf/view/webrtc"];
  1244. if (!this._driver) {
  1245. this.classList.add('mdc-icon-toggle--disabled');
  1246. }
  1247. this.classList.add('mdc-icon-toggle--disabled');
  1248. this.addEventListener('MDCIconToggle:change', (e) => {
  1249. let driver = e.target._driver;
  1250. let chkAttr = e.detail.isOn;
  1251. if (chkAttr) {
  1252. driver.muteVideo(chkAttr);
  1253. console.log("on")
  1254. } else {
  1255. driver.muteVideo(chkAttr);
  1256. console.log("off")
  1257. }
  1258. //console.log(e, detail)
  1259. //status.textContent = `Icon Toggle is ${detail.isOn ? 'on' : 'off'}`;
  1260. });
  1261. }
  1262. })
  1263. ]
  1264. }
  1265. ]
  1266. }
  1267. ]
  1268. }
  1269. let gizmoEdit = {
  1270. $type: "div",
  1271. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1272. $components: [
  1273. {
  1274. $type: "div",
  1275. class: "mdc-layout-grid__inner",
  1276. $components: [
  1277. {
  1278. $type: "div",
  1279. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1280. $components: [
  1281. {
  1282. $cell: true,
  1283. $type: "span",
  1284. $text: "Edit: ",
  1285. }
  1286. ]
  1287. },
  1288. {
  1289. $type: "div",
  1290. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  1291. $components: [
  1292. widgets.switch({
  1293. 'id': 'editnode',
  1294. 'init': function(){
  1295. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  1296. },
  1297. 'onchange': function(e){
  1298. var nodeID = document.querySelector('#currentNode')._currentNode;
  1299. let chkAttr = this.getAttribute('checked');
  1300. if (chkAttr == "") {
  1301. self.kernel.setProperty(this._currentNode, 'edit', false);
  1302. } else {
  1303. self.kernel.setProperty(this._currentNode, 'edit', true);
  1304. }
  1305. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  1306. }
  1307. }
  1308. )
  1309. ]
  1310. },
  1311. {
  1312. $type: "div",
  1313. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1314. $components: [
  1315. {
  1316. $cell: true,
  1317. $type: "a",
  1318. class: "gizmomode",
  1319. $text: "T",
  1320. onclick: function (e) {
  1321. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  1322. }
  1323. }
  1324. ]
  1325. },
  1326. {
  1327. $type: "div",
  1328. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1329. $components: [
  1330. {
  1331. $cell: true,
  1332. $type: "a",
  1333. class: "gizmomode",
  1334. $text: "R",
  1335. onclick: function (e) {
  1336. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  1337. }
  1338. }
  1339. ]
  1340. },
  1341. {
  1342. $type: "div",
  1343. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  1344. $components: [
  1345. {
  1346. $cell: true,
  1347. $type: "a",
  1348. class: "gizmomode",
  1349. $text: "S",
  1350. onclick: function (e) {
  1351. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  1352. }
  1353. }
  1354. ]
  1355. }
  1356. ]
  1357. }
  1358. ]
  1359. }
  1360. let nodesCell = {
  1361. $cell: true,
  1362. $type: "div",
  1363. id: "currentNode",
  1364. _childNodes: [],
  1365. _currentNode: '',
  1366. _displayedProperties: {},
  1367. _setNode: function (aNode) {
  1368. this._currentNode = aNode;
  1369. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  1370. },
  1371. $init: function () {
  1372. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1373. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1374. //this._currentNode = '3333';
  1375. },
  1376. _getChildNodes: function () {
  1377. this._childNodes = self.nodes[this._currentNode];
  1378. if (this._childNodes !== undefined) {
  1379. return this._childNodes.children
  1380. } else {
  1381. return []
  1382. }
  1383. //let nodeIDAlpha = he.encode(this._currentNode);
  1384. },
  1385. // _getNodeComplexProperties: function () {
  1386. // let node = self.nodes[this._currentNode];
  1387. // let props = this._getNodeProperties();
  1388. // let filterFunction = function (prop) {
  1389. // return (prop.name == 'ohmLang')
  1390. // };
  1391. // let complexProps = props.filter(filterFunction.bind(this));
  1392. // return complexProps
  1393. // },
  1394. _getNodeProperties: function () {
  1395. let node = self.nodes[this._currentNode];
  1396. this._displayedProperties = {};
  1397. let filterFunction = function (prop) {
  1398. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1399. };
  1400. let props = node.properties.filter(filterFunction.bind(this));
  1401. return props
  1402. },
  1403. _getNodeProtoProperties: function () {
  1404. let node = self.nodes[this._currentNode];
  1405. let filterFunction = function (prop) {
  1406. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1407. };
  1408. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1409. return props
  1410. },
  1411. $update: function () {
  1412. //this.$text = this._currentNode;
  1413. let node = self.nodes[this._currentNode];
  1414. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1415. var viewerProps = {};
  1416. var viewerPropsCell = {};
  1417. var gizmoCell = {};
  1418. if (this._currentNode !== self.kernel.application()) {
  1419. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1420. //gizmoCell = {};
  1421. } else {
  1422. gizmoCell = gizmoEdit
  1423. }
  1424. }
  1425. if (node !== undefined) {
  1426. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1427. viewerProps = {
  1428. $type: "li",
  1429. class: "mdc-list-item",
  1430. $components: [
  1431. {
  1432. $text: "Viewer properties",
  1433. $type: "span",
  1434. class: "mdc-list-item__text mdc-typography--button"
  1435. }
  1436. ]
  1437. }
  1438. viewerPropsCell = {
  1439. $cell: true,
  1440. $type: "div",
  1441. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1442. $components: [
  1443. {
  1444. $cell: true,
  1445. $type: "div",
  1446. class: "mdc-layout-grid__inner",
  1447. $components: [
  1448. {
  1449. $cell: true,
  1450. $type: "div",
  1451. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1452. $components: [
  1453. widgets.buttonStroked(
  1454. {
  1455. "label": "Active",
  1456. "onclick": function (e) {
  1457. //let camera = document.querySelector('#' + this._currentNode);
  1458. vwf_view.kernel.callMethod(this._currentNode, "setCameraToActive", [vwf.moniker_]);
  1459. //camera.setAttribute('camera', 'active', true);
  1460. }
  1461. })
  1462. ]
  1463. }
  1464. ]
  1465. }
  1466. ]
  1467. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1468. }
  1469. } else {
  1470. viewerProps = {};
  1471. viewerPropsCell = {};
  1472. }
  1473. }
  1474. this.$components = [
  1475. {
  1476. $cell: true,
  1477. $type: "ul",
  1478. class: "mdc-list",
  1479. $components: [
  1480. widgets.buttonStroked(
  1481. {
  1482. "label": "<--",
  1483. "onclick": function (e) {
  1484. let node = self.nodes[this._currentNode];
  1485. if (node.parentID !== 0) {
  1486. //self.currentNodeID = node.parentID,
  1487. document.querySelector('#currentNode')._setNode(node.parentID)
  1488. }
  1489. }
  1490. }),
  1491. {
  1492. $type: "li",
  1493. class: "mdc-list-item",
  1494. $components: [
  1495. {
  1496. $text: "name",
  1497. $type: "span",
  1498. $init: function () {
  1499. let node = self.nodes[this._currentNode];
  1500. if (node) {
  1501. let displayName = vwf.getProperty(node.ID, 'displayName');
  1502. if (displayName)
  1503. {
  1504. this.$text = displayName
  1505. } else {
  1506. this.$text = node.name;
  1507. }
  1508. }
  1509. //console.log(node.properties.displayName)
  1510. },
  1511. class: "mdc-list-item__text mdc-typography--headline"
  1512. //<h1 class="mdc-typography--display4">Big header</h1>
  1513. }]
  1514. }, listDivider,
  1515. {
  1516. // $cell: true,
  1517. // $type: "ul",
  1518. // class: "mdc-list",
  1519. $type: "div",
  1520. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1521. $components: [
  1522. {
  1523. $type: "div",
  1524. class: "mdc-layout-grid__inner",
  1525. $components: [
  1526. {
  1527. $type: "div",
  1528. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1529. $components: [
  1530. widgets.buttonStroked(
  1531. {
  1532. "label": "Methods browser",
  1533. "onclick": function (e) {
  1534. var currentNode = document.querySelector('#currentNode')._currentNode;
  1535. if (currentNode == '') {
  1536. currentNode = vwf_view.kernel.find("", "/")[0];
  1537. }
  1538. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1539. //createAceEditor(self, currentNode);
  1540. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1541. }
  1542. })
  1543. ]
  1544. }
  1545. ]
  1546. }
  1547. ]
  1548. },
  1549. gizmoCell,
  1550. listDivider,
  1551. {
  1552. $type: "li",
  1553. class: "mdc-list-item",
  1554. $components: [
  1555. {
  1556. $text: "Children",
  1557. $type: "span",
  1558. class: "mdc-list-item__text mdc-typography--button"
  1559. }]
  1560. },
  1561. {
  1562. $cell: true,
  1563. $type: "ul",
  1564. class: "mdc-list",
  1565. $components: this._getChildNodes().map(nodeLink)
  1566. }, listDivider, {
  1567. $type: "li",
  1568. class: "mdc-list-item",
  1569. $components: [
  1570. {
  1571. $text: "Properties",
  1572. $type: "span",
  1573. class: "mdc-list-item__text mdc-typography--button"
  1574. //<h1 class="mdc-typography--display4">Big header</h1>
  1575. }]
  1576. },
  1577. {
  1578. // $cell: true,
  1579. // $type: "ul",
  1580. // class: "mdc-list",
  1581. $type: "div",
  1582. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1583. $components: this._getNodeProperties().map(propertiesCell)
  1584. },
  1585. listDivider,
  1586. {
  1587. $type: "li",
  1588. class: "mdc-list-item",
  1589. $components: [
  1590. {
  1591. $text: "Proto properties",
  1592. $type: "span",
  1593. class: "mdc-list-item__text mdc-typography--button"
  1594. }]
  1595. },
  1596. {
  1597. $cell: true,
  1598. $type: "div",
  1599. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1600. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1601. }, listDivider,
  1602. viewerProps,
  1603. viewerPropsCell
  1604. ]
  1605. }
  1606. ]
  1607. }
  1608. }
  1609. let numberSliderComponent = {
  1610. $cell: true,
  1611. $type: "div",
  1612. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1613. $init: function () {
  1614. },
  1615. $components: [
  1616. {
  1617. $cell: true,
  1618. $type: "div",
  1619. style: "padding: 0 16px;",
  1620. $components:[
  1621. {}
  1622. ]
  1623. }
  1624. ]
  1625. }
  1626. let colorPickerComponent = {
  1627. $cell: true,
  1628. $type: "div",
  1629. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1630. $init: function () {
  1631. let myEl = this;
  1632. let cp = ColorPicker(
  1633. document.getElementById('slide'),
  1634. document.getElementById('picker'),
  1635. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1636. ColorPicker.positionIndicators(
  1637. document.getElementById('slide-indicator'),
  1638. document.getElementById('picker-indicator'),
  1639. mouseSlide, mousePicker
  1640. );
  1641. if (myEl._propName.toLowerCase().includes('color')) {
  1642. // console.log(hex);
  1643. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1644. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1645. }
  1646. });
  1647. if (myEl._propName.toLowerCase().includes('color')) {
  1648. cp.setHex(JSON.parse(myEl._prop.body));
  1649. }
  1650. },
  1651. $components: [
  1652. {
  1653. $cell: true,
  1654. $type: "div",
  1655. id: "color-picker",
  1656. class: "cp-default",
  1657. $components: [
  1658. {
  1659. $cell: true,
  1660. $type: "div",
  1661. class: "picker-wrapper",
  1662. $components: [
  1663. {
  1664. $cell: true,
  1665. $type: "div",
  1666. id: "picker",
  1667. class: "picker",
  1668. style: "width: 130px; height: 130px"
  1669. },
  1670. {
  1671. $cell: true,
  1672. $type: "div",
  1673. id: "picker-indicator",
  1674. class: "picker-indicator"
  1675. }
  1676. ]
  1677. },
  1678. {
  1679. $cell: true,
  1680. $type: "div",
  1681. class: "slide-wrapper",
  1682. $components: [
  1683. {
  1684. $cell: true,
  1685. $type: "div",
  1686. id: "slide",
  1687. class: "slide",
  1688. style: "width: 30px; height: 130px"
  1689. },
  1690. {
  1691. $cell: true,
  1692. $type: "div",
  1693. id: "slide-indicator",
  1694. class: "slide-indicator"
  1695. }
  1696. ]
  1697. }
  1698. ]
  1699. }
  1700. // {
  1701. // $cell: true,
  1702. // $type: "div",
  1703. // id: "color-picker",
  1704. // $init: function () {
  1705. // }
  1706. // }
  1707. ]
  1708. }
  1709. let propEditorWindow = {
  1710. $cell: true,
  1711. $type: "div",
  1712. _editorNode: '',
  1713. _prop: { body: '', type: 'simple' },
  1714. _propName: '',
  1715. id: "livePropEditor",
  1716. _setNode: function (node) {
  1717. this._editorNode = node;
  1718. this._prop.body = ''
  1719. },
  1720. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1721. $update: function () {
  1722. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  1723. var livePropertyComponent = {}
  1724. if (this._prop.type == 'simple') {
  1725. if (this._propName.toLowerCase().includes('color')) {
  1726. livePropertyComponent = colorPickerComponent
  1727. }
  1728. } else {
  1729. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  1730. }
  1731. this.$components = [
  1732. {
  1733. $cell: true,
  1734. $type: "div",
  1735. class: "mdc-layout-grid__inner",
  1736. $components: [
  1737. {
  1738. $cell: true,
  1739. $type: "div",
  1740. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1741. $components: [
  1742. widgets.buttonStroked(
  1743. {
  1744. "label": "Update",
  1745. "onclick": function (e) {
  1746. let editor = document.querySelector("#propAceEditor").env.editor;
  1747. let value = editor.getValue();
  1748. try {
  1749. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  1750. //propValue = JSON.parse(value);
  1751. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  1752. } catch (e) {
  1753. // restore the original value on error
  1754. this.value = propValue;
  1755. }
  1756. }
  1757. }
  1758. )]
  1759. },
  1760. {
  1761. $cell: true,
  1762. $type: "div",
  1763. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1764. $components: [
  1765. {
  1766. $type: "h3",
  1767. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1768. $text: this._editorNode
  1769. }
  1770. ]
  1771. },
  1772. {
  1773. $cell: true,
  1774. $type: "div",
  1775. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1776. $components: [
  1777. {
  1778. $type: "h3",
  1779. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1780. $text: this._propName
  1781. }
  1782. ]
  1783. }
  1784. ]
  1785. },
  1786. {
  1787. $cell: true,
  1788. $type: "div",
  1789. class: "mdc-layout-grid__inner",
  1790. $components: [
  1791. {
  1792. $cell: true,
  1793. $type: "div",
  1794. class: editorClass,
  1795. $components: [
  1796. {
  1797. $cell: true,
  1798. class: "aceEditor",
  1799. id: "propAceEditor",
  1800. $type: "div",
  1801. $text: this._prop.body,
  1802. $init: function () {
  1803. createAceEditor(self, this._editorNode, "propAceEditor");
  1804. this.env.editor.$blockScrolling = Infinity
  1805. }
  1806. }
  1807. ]
  1808. }, livePropertyComponent
  1809. // {
  1810. // $cell: true,
  1811. // $type: "div",
  1812. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1813. // $components: []
  1814. // },
  1815. ]
  1816. }
  1817. ]
  1818. //$components:
  1819. }
  1820. }
  1821. let codeEditorWindow = {
  1822. $cell: true,
  1823. $type: "div",
  1824. _editorNode: '',
  1825. _method: { body: '' },
  1826. _methodName: '',
  1827. _getNodeMethods: function () {
  1828. let node = self.nodes[this._editorNode];
  1829. return node.methods
  1830. },
  1831. _getProtoNodeMethods: function () {
  1832. let node = self.nodes[this._editorNode];
  1833. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  1834. return prototypeMethods
  1835. },
  1836. id: "liveCodeEditor",
  1837. _setNode: function (node) {
  1838. this._editorNode = node;
  1839. this._method.body = ''
  1840. },
  1841. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1842. // _getComplexProps: function(){
  1843. // let node = self.nodes[this._editorNode];
  1844. // let currentNode = document.querySelector('#currentNode');
  1845. // var props = {}
  1846. // if (currentNode !== null) {
  1847. // props = currentNode._getNodeComplexProperties();
  1848. // }
  1849. // return props
  1850. // },
  1851. // _listPropertyElement: function (m) {
  1852. // return {
  1853. // $type: "li",
  1854. // class: "mdc-list-item",
  1855. // $components: [{
  1856. // $type: "a",
  1857. // class: "mdc-list-item",
  1858. // $href: "#",
  1859. // $text: m[1].name,
  1860. // onclick: function (e) {
  1861. // this._method = {};
  1862. // this._methodName = m[1].name;
  1863. // this._method.body = m[1].rawValue
  1864. // this._method.type = "complexProperty"
  1865. // }
  1866. // }]
  1867. // }
  1868. // },
  1869. _listElement: function (m) {
  1870. return {
  1871. $type: "li",
  1872. class: "mdc-list-item",
  1873. $components: [{
  1874. $type: "a",
  1875. class: "mdc-list-item",
  1876. $href: "#",
  1877. $text: m[0],
  1878. onclick: function (e) {
  1879. let method = vwf.getMethod(this._editorNode, m[0]);
  1880. //document.querySelector('#aceEditor').
  1881. this._method = method;
  1882. this._methodName = m[0];
  1883. //self.currentNodeID = m.ID;
  1884. //document.querySelector('#currentNode')._setNode(m.ID);
  1885. }
  1886. }]
  1887. }
  1888. },
  1889. $update: function () {
  1890. this.$components = [
  1891. {
  1892. $cell: true,
  1893. $type: "div",
  1894. class: "mdc-layout-grid__inner",
  1895. $components: [
  1896. {
  1897. $cell: true,
  1898. $type: "div",
  1899. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1900. $components: [
  1901. {
  1902. $type: "h3",
  1903. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1904. $text: this._editorNode
  1905. }
  1906. ]
  1907. },
  1908. {
  1909. $cell: true,
  1910. $type: "div",
  1911. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1912. $components: [
  1913. widgets.buttonStroked(
  1914. {
  1915. "label": "Update",
  1916. "onclick": function (e) {
  1917. let editor = document.querySelector("#aceEditor").env.editor;
  1918. let evalText = editor.getValue();
  1919. // if (this._method.type == 'complexProperty') {
  1920. // let propValue = evalText;
  1921. // try {
  1922. // //propValue = JSON.parse(propValue);
  1923. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  1924. // } catch (e) {
  1925. // // restore the original value on error
  1926. // this.value = propValue;
  1927. // }
  1928. // } else {
  1929. // }
  1930. self.kernel.setMethod(this._editorNode, this._methodName,
  1931. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  1932. }
  1933. }
  1934. )]
  1935. },
  1936. {
  1937. $cell: true,
  1938. $type: "div",
  1939. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1940. $components: [
  1941. widgets.buttonStroked(
  1942. {
  1943. "label": "Call",
  1944. "onclick": function (e) {
  1945. var params = [];
  1946. if (this._method.parameters) {
  1947. let paramsLength = this._method.parameters.length
  1948. if (paramsLength >= 1) {
  1949. let paramsVal = document.querySelector("#methodParams").value;
  1950. try {
  1951. params = JSON.parse(paramsVal);
  1952. //params.push(prmtr);
  1953. } catch (e) {
  1954. self.logger.error('Invalid Value');
  1955. }
  1956. }
  1957. };
  1958. self.kernel.callMethod(this._editorNode, this._methodName, params);
  1959. }
  1960. })
  1961. ]
  1962. },
  1963. {
  1964. $cell: true,
  1965. $type: "div",
  1966. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1967. $components: [
  1968. widgets.buttonStroked(
  1969. {
  1970. "label": "Do It",
  1971. "onclick": function (e) {
  1972. let editor = document.querySelector("#aceEditor").env.editor;
  1973. codeEditorDoit.call(self, editor, this._editorNode);
  1974. }
  1975. })
  1976. ]
  1977. },
  1978. {
  1979. $cell: true,
  1980. $type: "div",
  1981. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1982. $components: [
  1983. widgets.buttonStroked(
  1984. {
  1985. "label": "Print It",
  1986. "onclick": function (e) {
  1987. let editor = document.querySelector("#aceEditor").env.editor;
  1988. codeEditorPrintit.call(self, editor, this._editorNode);
  1989. }
  1990. })
  1991. ]
  1992. }
  1993. ]
  1994. },
  1995. {
  1996. $cell: true,
  1997. $type: "div",
  1998. class: "mdc-layout-grid__inner",
  1999. $components: [
  2000. {
  2001. $cell: true,
  2002. $type: "div",
  2003. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2004. style: "overflow-y: scroll; max-height: 400px;",
  2005. $components: [
  2006. {
  2007. $cell: true,
  2008. $type: "div",
  2009. class: "mdc-list-group",
  2010. $components: [
  2011. {
  2012. $type: "h3",
  2013. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2014. $text: "Node methods"
  2015. },
  2016. {
  2017. $cell: true,
  2018. $type: "ul",
  2019. class: "mdc-list",
  2020. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  2021. }, listDivider,
  2022. {
  2023. $type: "h3",
  2024. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2025. $text: "Proto methods"
  2026. },
  2027. {
  2028. $cell: true,
  2029. $type: "ul",
  2030. class: "mdc-list",
  2031. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  2032. }, listDivider,
  2033. {
  2034. $type: "h3",
  2035. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  2036. $text: "Events"
  2037. }
  2038. // {
  2039. // $cell: true,
  2040. // $type: "ul",
  2041. // class: "mdc-list",
  2042. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  2043. // }
  2044. ]
  2045. }
  2046. ]
  2047. },
  2048. {
  2049. $cell: true,
  2050. $type: "div",
  2051. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  2052. $components: [
  2053. {
  2054. $cell: true,
  2055. class: "aceEditor",
  2056. id: "aceEditor",
  2057. $type: "div",
  2058. $text: this._method.body,
  2059. $init: function () {
  2060. createAceEditor(self, this._editorNode, "aceEditor");
  2061. }
  2062. }
  2063. ]
  2064. }
  2065. ]
  2066. },
  2067. {
  2068. $cell: true,
  2069. $type: "div",
  2070. class: "mdc-layout-grid__inner",
  2071. $components: [
  2072. {
  2073. $cell: true,
  2074. $type: "div",
  2075. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2076. $components: [
  2077. {
  2078. $type: "span",
  2079. $text: "*"
  2080. }
  2081. ]
  2082. }
  2083. ]
  2084. },
  2085. { //params input
  2086. $cell: true,
  2087. $type: "div",
  2088. class: "mdc-layout-grid__inner",
  2089. $components: [
  2090. {
  2091. $cell: true,
  2092. $type: "div",
  2093. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  2094. $components: [
  2095. {
  2096. class: "mdc-text-field",
  2097. $cell: true,
  2098. $type: "div",
  2099. $components: [{
  2100. class: "mdc-text-field__input prop-text-field-input",
  2101. id: "methodName",
  2102. $cell: true,
  2103. $type: "input",
  2104. type: "text",
  2105. value: "newMethodName",
  2106. onchange: function (e) {
  2107. let propValue = this.value;
  2108. try {
  2109. } catch (e) {
  2110. // restore the original value on error
  2111. }
  2112. }
  2113. }]
  2114. }
  2115. ]
  2116. },
  2117. {
  2118. $cell: true,
  2119. $type: "div",
  2120. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  2121. $components: [
  2122. {
  2123. class: "mdc-text-field params-text-field-input",
  2124. $cell: true,
  2125. $type: "div",
  2126. $components: [{
  2127. class: "mdc-text-field__input prop-text-field-input",
  2128. id: "methodParams",
  2129. $cell: true,
  2130. $type: "input",
  2131. type: "text",
  2132. value: JSON.stringify(this._method.parameters),
  2133. onchange: function (e) {
  2134. let propValue = this.value;
  2135. try {
  2136. } catch (e) {
  2137. // restore the original value on error
  2138. }
  2139. }
  2140. }]
  2141. }
  2142. ]
  2143. },
  2144. {
  2145. $cell: true,
  2146. $type: "div",
  2147. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  2148. $components: [
  2149. widgets.buttonStroked(
  2150. {
  2151. "label": "Create",
  2152. "onclick": function (e) {
  2153. let methodName = document.querySelector('#methodName').value;
  2154. //let methodParams = document.querySelector('#methodParams');
  2155. var params = [];
  2156. let body = '';
  2157. let paramsVal = document.querySelector("#methodParams").value;
  2158. if (paramsVal !== '') {
  2159. try {
  2160. params = JSON.parse(paramsVal);
  2161. //params.push(prmtr);
  2162. } catch (e) {
  2163. self.logger.error('Invalid Value');
  2164. }
  2165. }
  2166. self.kernel.createMethod(this._editorNode, methodName, params, body);
  2167. this._setNode(this._editorNode);
  2168. // let editor = document.querySelector("#aceEditor").env.editor;
  2169. // codeEditorDoit.call(self, editor, this._editorNode);
  2170. }
  2171. })
  2172. ]
  2173. }
  2174. ]
  2175. }
  2176. ]
  2177. //$components:
  2178. }
  2179. }
  2180. let propWindow = {
  2181. $cell: true,
  2182. $type: "div",
  2183. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  2184. style: "overflow-y: scroll; max-height: 800px;",
  2185. $components: [
  2186. {
  2187. $type: "div",
  2188. class: "mdc-layout-grid__inner",
  2189. $components: [
  2190. {
  2191. $cell: true,
  2192. $type: "div",
  2193. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2194. $components: [
  2195. nodesCell
  2196. ]
  2197. }
  2198. ]
  2199. }
  2200. // <button class="mdc-button">
  2201. // Flat button
  2202. // </button>
  2203. ]
  2204. }
  2205. let clientListCell = {
  2206. $cell: true,
  2207. $type: "div",
  2208. class: "mdc-list",
  2209. id: "clientsList",
  2210. _watchNodes: [],
  2211. _listElement: function (m) {
  2212. return {
  2213. $type: "a",
  2214. class: "mdc-list-item",
  2215. $href: "#",
  2216. $text: m.name,
  2217. onclick: function (e) {
  2218. //self.currentNodeID = m.ID;
  2219. //document.querySelector('#currentNode')._setNode(m.ID);
  2220. }
  2221. }
  2222. },
  2223. $init: function () {
  2224. var t = this;
  2225. setInterval(function () {
  2226. t._updateMe();
  2227. }, 1000);
  2228. },
  2229. _updateMe: function () {
  2230. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  2231. },
  2232. $update: function () {
  2233. //this._clientNodes
  2234. this.$components = this._watchNodes.map(this._listElement)
  2235. }
  2236. }
  2237. //createCellWindow("clientsWindow", clientListCell, "Clients");
  2238. //createCellWindow("propWindow", propWindow, "Scene");
  2239. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  2240. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  2241. let viewSceneProps = {
  2242. $cell: true,
  2243. $type: "div",
  2244. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  2245. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  2246. $components: [
  2247. {
  2248. $type: "div",
  2249. class: "mdc-layout-grid__inner",
  2250. $components: [
  2251. {
  2252. $cell: true,
  2253. $type: "div",
  2254. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2255. $components: [
  2256. nodesCell
  2257. ]
  2258. }
  2259. ]
  2260. }
  2261. ]
  2262. }
  2263. let sideBar = {
  2264. $cell: true,
  2265. $type: "div",
  2266. id: 'sideBar',
  2267. class: "sideBar mdc-toolbar-fixed-adjust",
  2268. _sideBarComponent: {},
  2269. _sideCurrentNode: '',
  2270. $init: function () {
  2271. this.style.visibility = 'hidden';
  2272. this._importScript("/" + self.getRoot() + "/appui.js");
  2273. },
  2274. _importScript: function (sSrc, fOnload) {
  2275. var oScript = document.createElement("script");
  2276. oScript.type = "text\/javascript";
  2277. oScript.async = false;
  2278. //oScript.onerror = loadError;
  2279. if (fOnload) { oScript.onload = fOnload; }
  2280. oScript.src = sSrc;
  2281. //let sideBar = document.querySelector('#sideBar');
  2282. this.appendChild(oScript);
  2283. },
  2284. _getAppDef: async function () {
  2285. let response = await fetch("/" + self.getRoot() + "/appui.js");
  2286. let data = await response.text();
  2287. //console.log(data)
  2288. return data
  2289. },
  2290. $update: function () {
  2291. this.$components = [
  2292. {
  2293. $cell: true,
  2294. $type: "button",
  2295. class: "mdc-button mdc-button--compact",
  2296. $text: "X",
  2297. onclick: function (e) {
  2298. document.querySelector('#sideBar').style.visibility = 'hidden';
  2299. }
  2300. },
  2301. this._sideBarComponent
  2302. ]
  2303. }
  2304. //$components: [this._sideComponents]
  2305. }
  2306. document.querySelector('#' + 'sideBar').$cell(sideBar)
  2307. let defaultApp = function () {
  2308. return {
  2309. $cell: true,
  2310. $type: "div",
  2311. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  2312. $components: [
  2313. {
  2314. $cell: true,
  2315. $type: "div",
  2316. class: "mdc-layout-grid__inner",
  2317. $components: [
  2318. {
  2319. $cell: true,
  2320. $type: "div",
  2321. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  2322. $components: [
  2323. {
  2324. $cell: true,
  2325. $type: "h3",
  2326. class: "mdc-typography--headline",
  2327. $text: "Application",
  2328. }
  2329. ]
  2330. }
  2331. ]
  2332. }
  2333. ]
  2334. }
  2335. }
  2336. let drawerCell = {
  2337. $cell: true,
  2338. $type: "nav",
  2339. class: "mdc-temporary-drawer__drawer",
  2340. $components: [
  2341. {
  2342. $cell: true,
  2343. $type: "header",
  2344. class: "mdc-temporary-drawer__header",
  2345. $components: [
  2346. {
  2347. $cell: true,
  2348. $type: "div",
  2349. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  2350. $text: "Home"
  2351. }
  2352. ]
  2353. },
  2354. {
  2355. $cell: true,
  2356. $type: "nav",
  2357. class: "mdc-temporary-drawer__content mdc-list-group",
  2358. $components: [
  2359. {
  2360. $cell: true,
  2361. $type: "div",
  2362. class: "mdc-list",
  2363. $components: [
  2364. {
  2365. $cell: true,
  2366. $type: "a",
  2367. class: "mdc-list-item",
  2368. $href: "#",
  2369. onclick: function (e) {
  2370. let sideBar = document.querySelector('#sideBar');
  2371. try {
  2372. sideBar._sideBarComponent = createApp.call(self);
  2373. } catch (e) {
  2374. sideBar._sideBarComponent = defaultApp();
  2375. }
  2376. drawer.open = !drawer.open
  2377. document.querySelector('#sideBar').style.visibility = 'visible';
  2378. },
  2379. $components: [{
  2380. $type: "i",
  2381. class: "material-icons mdc-list-item__start-detail",
  2382. 'aria-hidden': "true",
  2383. $text: "play_arrow"
  2384. },
  2385. {
  2386. $text: "App"
  2387. }]
  2388. },
  2389. {
  2390. $cell: true,
  2391. $type: "a",
  2392. class: "mdc-list-item",
  2393. $href: "#",
  2394. onclick: function (e) {
  2395. let sideBar = document.querySelector('#sideBar');
  2396. sideBar._sideBarComponent = viewSceneProps;
  2397. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  2398. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  2399. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  2400. document.querySelector('#sideBar').style.visibility = 'visible';
  2401. drawer.open = !drawer.open
  2402. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2403. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2404. // document.querySelector('#currentNode')._setNode(currentNode);
  2405. },
  2406. $components: [{
  2407. $cell: true,
  2408. $type: "i",
  2409. class: "material-icons mdc-list-item__start-detail",
  2410. $text: "description"
  2411. },
  2412. {
  2413. $text: "Scene"
  2414. }
  2415. ]
  2416. },
  2417. {
  2418. $cell: true,
  2419. $type: "a",
  2420. class: "mdc-list-item",
  2421. $href: "#",
  2422. onclick: function (e) {
  2423. //self.currentNodeID = m.ID;
  2424. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2425. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2426. let sideBar = document.querySelector('#sideBar');
  2427. sideBar._sideBarComponent = createSettings;
  2428. drawer.open = !drawer.open
  2429. document.querySelector('#sideBar').style.visibility = 'visible';
  2430. },
  2431. $components: [{
  2432. $type: "i",
  2433. class: "material-icons mdc-list-item__start-detail",
  2434. 'aria-hidden': "true",
  2435. $text: "create"
  2436. },
  2437. {
  2438. $text: "Create"
  2439. }]
  2440. },
  2441. {
  2442. $cell: true,
  2443. $type: "a",
  2444. class: "mdc-list-item",
  2445. $href: "#",
  2446. onclick: function (e) {
  2447. // var currentNode = document.querySelector('#currentNode')._currentNode;
  2448. // if (currentNode == '') {
  2449. // currentNode = vwf_view.kernel.find("", "/")[0];
  2450. // }
  2451. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  2452. //createAceEditor(self, currentNode);
  2453. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2454. },
  2455. $components: [{
  2456. $type: "i",
  2457. class: "material-icons mdc-list-item__start-detail",
  2458. 'aria-hidden': "true",
  2459. $text: "code"
  2460. },
  2461. {
  2462. $text: "Code editor"
  2463. }]
  2464. },
  2465. {
  2466. $cell: true,
  2467. $type: "a",
  2468. class: "mdc-list-item",
  2469. $href: "#",
  2470. onclick: function (e) {
  2471. //self.currentNodeID = m.ID;
  2472. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2473. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2474. let sideBar = document.querySelector('#sideBar');
  2475. sideBar._sideBarComponent = avatarSettings;
  2476. drawer.open = !drawer.open
  2477. document.querySelector('#sideBar').style.visibility = 'visible';
  2478. },
  2479. $components: [{
  2480. $type: "i",
  2481. class: "material-icons mdc-list-item__start-detail",
  2482. 'aria-hidden': "true",
  2483. $text: "account_circle"
  2484. },
  2485. {
  2486. $text: "My Avatar"
  2487. }]
  2488. },
  2489. {
  2490. $cell: true,
  2491. $type: "a",
  2492. class: "mdc-list-item",
  2493. $href: "#",
  2494. onclick: function (e) {
  2495. //self.currentNodeID = m.ID;
  2496. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2497. let sideBar = document.querySelector('#sideBar');
  2498. sideBar._sideBarComponent = viewSettings;
  2499. drawer.open = !drawer.open
  2500. document.querySelector('#sideBar').style.visibility = 'visible';
  2501. },
  2502. $components: [{
  2503. $type: "i",
  2504. class: "material-icons mdc-list-item__start-detail",
  2505. 'aria-hidden': "true",
  2506. $text: "settings"
  2507. },
  2508. {
  2509. $text: "Settings"
  2510. }]
  2511. },
  2512. {
  2513. $cell: true,
  2514. $type: "a",
  2515. class: "mdc-list-item",
  2516. $href: "#",
  2517. onclick: function (e) {
  2518. //self.currentNodeID = m.ID;
  2519. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2520. let sideBar = document.querySelector('#sideBar');
  2521. sideBar._sideBarComponent = loadSaveSettings;
  2522. if (document.querySelector('#loadSaveSettings')) {
  2523. document.querySelector('#loadSaveSettings')._getStates();
  2524. }
  2525. //sideBar._sideBarComponent._getStates();
  2526. drawer.open = !drawer.open
  2527. document.querySelector('#sideBar').style.visibility = 'visible';
  2528. },
  2529. $components: [{
  2530. $type: "i",
  2531. class: "material-icons mdc-list-item__start-detail",
  2532. 'aria-hidden': "true",
  2533. $text: "save"
  2534. },
  2535. {
  2536. $text: "Load/Save"
  2537. }]
  2538. }
  2539. ]
  2540. },
  2541. widgets.divider,
  2542. webrtcGUI,
  2543. widgets.divider,
  2544. widgets.headerH3("h3", "Users online", "userList mdc-list-group__subheader"),
  2545. clientListCell
  2546. //widgets.headerH3("h3", "WebRTC", "userList mdc-list-group__subheader"),
  2547. ]
  2548. }
  2549. // {
  2550. // $cell: true,
  2551. // $type: "div",
  2552. // class: "mdc-persistent-drawer__toolbar-spacer",
  2553. // },
  2554. // {
  2555. // $cell: true,
  2556. // $type: "div",
  2557. // class: "mdc-list-group",
  2558. // $components: [{
  2559. // $cell: true,
  2560. // $type: "nav",
  2561. // class: "mdc-list",
  2562. // $components: [
  2563. // ]
  2564. // }]
  2565. // }
  2566. ]
  2567. };
  2568. // <div class="mdc-form-field">
  2569. // <input type="checkbox" id="input">
  2570. // <label for="input">Input Label</label>
  2571. // </div>
  2572. document.querySelector("#drawer").$cell({
  2573. $cell: true,
  2574. $type: "aside",
  2575. class: "mdc-temporary-drawer",
  2576. $components: [drawerCell]
  2577. }
  2578. );
  2579. let toolbar = {
  2580. $cell: true,
  2581. $type: "div",
  2582. class: "mdc-toolbar__row",
  2583. $components: [{
  2584. $type: "section",
  2585. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  2586. $components: [
  2587. {
  2588. $type: "button",
  2589. class: "demo-menu material-icons mdc-toolbar__menu-icon",
  2590. $text: "menu"
  2591. },
  2592. {
  2593. $type: "span",
  2594. class: "mdc-toolbar__title catalog-title",
  2595. $text: "LiveCoding.space"
  2596. },
  2597. {
  2598. $type: "a",
  2599. href: "#",
  2600. class: "material-icons mdc-toolbar__icon toggleCreate",
  2601. $text: "apps",
  2602. 'aria-label': "More"
  2603. },
  2604. {
  2605. $type: "div",
  2606. class: "mdc-menu-anchor",
  2607. $components: [
  2608. {
  2609. $type: "div",
  2610. class: "mdc-simple-menu",
  2611. "tabindex": "-1",
  2612. id: "create-menu",
  2613. $init: function(){
  2614. //var menuEl = document.querySelector('#demo-menu');
  2615. var menu = new mdc.menu.MDCSimpleMenu(this);
  2616. var toggle = document.querySelector('.toggleCreate');
  2617. toggle.addEventListener('click', function() {
  2618. menu.open = !menu.open;
  2619. });
  2620. },
  2621. style: "transform-origin: right top 0px; right: 0px; top: 0px; transform: scale(0, 0);",
  2622. $components: [
  2623. {
  2624. $type: "ul",
  2625. class: "mdc-simple-menu__items mdc-list",
  2626. role: "menu",
  2627. 'aria-hidden': "true",
  2628. style: "transform: scale(1, 1);",
  2629. $components: [
  2630. {
  2631. $type: "li",
  2632. class: "mdc-list-item",
  2633. role: "menuitem",
  2634. tabindex: "0",
  2635. $text: "Apps"
  2636. }
  2637. ]
  2638. }
  2639. ]
  2640. }
  2641. ]
  2642. },
  2643. widgets.icontoggle({
  2644. 'styleClass': "mdc-toolbar__icon",
  2645. 'id': "selectNodeSwitch",
  2646. 'label': 'select',
  2647. 'on': JSON.stringify({"content": "radio_button_checked", "label": "Select"}),
  2648. 'off': JSON.stringify({"content": "radio_button_unchecked", "label": "Unselect"}),
  2649. 'state': false,
  2650. 'init': function(){
  2651. this.addEventListener('MDCIconToggle:change', (e) => {
  2652. let avatarID = 'avatar-'+ vwf.moniker_;
  2653. let avatarNode = self.nodes['avatar-'+ vwf.moniker_];
  2654. let mode = JSON.parse(avatarNode.properties.selectMode.getValue());
  2655. if (mode) {
  2656. console.log("unselect");
  2657. vwf_view.kernel.setProperty(avatarID, "selectMode", false);
  2658. } else {
  2659. console.log("select")
  2660. vwf_view.kernel.setProperty(avatarID, "selectMode", true);
  2661. }
  2662. });
  2663. }
  2664. })
  2665. ]
  2666. },
  2667. {
  2668. $type: "section",
  2669. class: "mdc-toolbar__section mdc-toolbar__section--align-end",
  2670. $components: [
  2671. {
  2672. $type: "a",
  2673. href: "#",
  2674. class: "material-icons mdc-toolbar__icon toggle",
  2675. $text: "help",
  2676. 'aria-label': "Help"
  2677. }
  2678. ]
  2679. }
  2680. ]
  2681. };
  2682. document.querySelector("#toolbar").$cell({
  2683. $cell: true,
  2684. $type: "div",
  2685. class: "mdc-toolbar mdc-toolbar--fixed",
  2686. $components: [toolbar]
  2687. }
  2688. );
  2689. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  2690. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  2691. var toggleNodes = document.querySelectorAll('.mdc-icon-toggle');
  2692. toggleNodes.forEach( el => {
  2693. mdc.iconToggle.MDCIconToggle.attachTo(el);
  2694. });
  2695. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  2696. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  2697. var drawer = new MDCTemporaryDrawer(drawerEl);
  2698. document.querySelector('.demo-menu').addEventListener('click', function () {
  2699. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  2700. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2701. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2702. // document.querySelector('#currentNode')._setNode(currentNode);
  2703. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  2704. drawer.open = !drawer.open;
  2705. });
  2706. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  2707. //console.log('Received MDCPersistentDrawer:open');
  2708. });
  2709. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  2710. //console.log('Received MDCPersistentDrawer:close');
  2711. });
  2712. //==============
  2713. },
  2714. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  2715. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  2716. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2717. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  2718. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  2719. var kernel = this.kernel;
  2720. var self = this;
  2721. var parent = this.nodes[nodeID];
  2722. var node = this.nodes[childID] = {
  2723. children: [],
  2724. properties: [],
  2725. events: {},
  2726. methods: {},
  2727. parent: parent,
  2728. parentID: nodeID,
  2729. ID: childID,
  2730. extendsID: childExtendsID,
  2731. implementsIDs: childImplementsIDs,
  2732. source: childSource,
  2733. name: childName,
  2734. };
  2735. if (parent) {
  2736. parent.children.push(node);
  2737. }
  2738. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  2739. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  2740. this.scenes[childID] = node;
  2741. }
  2742. let nodeCell = document.querySelector("#currentNode");
  2743. if (nodeCell !== null) {
  2744. if (nodeCell._currentNode === nodeID) {
  2745. nodeCell._getChildNodes();
  2746. }
  2747. }
  2748. if (nodeID === this.kernel.application()) {
  2749. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  2750. document.querySelector('body').classList.add("editor-body");
  2751. }
  2752. },
  2753. createdProperty: function (nodeID, propertyName, propertyValue) {
  2754. return this.initializedProperty(nodeID, propertyName, propertyValue);
  2755. },
  2756. initializedProperty: function (nodeID, propertyName, propertyValue) {
  2757. var node = this.nodes[nodeID];
  2758. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2759. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2760. node.properties.push(property);
  2761. },
  2762. deletedNode: function (nodeID) {
  2763. var node = this.nodes[nodeID];
  2764. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  2765. delete this.nodes[nodeID];
  2766. let nodeCell = document.querySelector("#currentNode");
  2767. if (nodeCell) {
  2768. if (nodeCell._currentNode !== "") {
  2769. if (nodeCell._currentNode !== nodeID) {
  2770. //&& (this.nodes[nodeID] !== undefined)
  2771. nodeCell._getChildNodes();
  2772. } else {
  2773. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  2774. nodeCell._getChildNodes();
  2775. }
  2776. }
  2777. }
  2778. },
  2779. //addedChild: [ /* nodeID, childID, childName */ ],
  2780. //removedChild: [ /* nodeID, childID */ ],
  2781. satProperty: function (nodeID, propertyName, propertyValue) {
  2782. var node = this.nodes[nodeID];
  2783. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2784. // It is possible for a property to have satProperty called for it without ever getting an
  2785. // initializedProperty (if that property delegated to itself or another on replication)
  2786. // Catch that case here and create the property
  2787. if (!node.properties[propertyName]) {
  2788. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2789. node.properties.push(property);
  2790. }
  2791. try {
  2792. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  2793. node.properties[propertyName].value = JSON.stringify(propertyValue);
  2794. node.properties[propertyName].rawValue = propertyValue;
  2795. } catch (e) {
  2796. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  2797. "stringify error:", e.message);
  2798. node.properties[propertyName].value = propertyValue;
  2799. }
  2800. let nodeCell = document.querySelector('#currentNode');
  2801. if (nodeCell !== null) {
  2802. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2803. console.log('EDIT !!!')
  2804. }
  2805. }
  2806. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  2807. let propSlider = document.querySelector("#currentNode #prop-slider-" + propertyName);
  2808. if (propCell !== null) {
  2809. if (propCell._currentNode == nodeID) {
  2810. propCell.value = node.properties[propertyName].getValue();
  2811. }
  2812. }
  2813. if (propSlider !== null) {
  2814. if (propSlider._currentNode == nodeID) {
  2815. //const propSliderComp = new new mdc.slider.MDCSlider(propSlider);
  2816. propSlider._comp.value = node.properties[propertyName].getValue();
  2817. }
  2818. }
  2819. },
  2820. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  2821. gotProperty: function (nodeID, propertyName, propertyValue) {
  2822. var node = this.nodes[nodeID];
  2823. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2824. let nodeCell = document.querySelector('#currentNode');
  2825. if (nodeCell !== null) {
  2826. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2827. let editCheckBox = document.querySelector("#currentNode #editnode");
  2828. if (editCheckBox) {
  2829. if (propertyValue) {
  2830. editCheckBox.setAttribute('checked', '');
  2831. } else {
  2832. let checkAttr = editCheckBox.getAttribute('checked');
  2833. if (checkAttr) editCheckBox.removeAttribute('checked');
  2834. }
  2835. }
  2836. console.log('EDIT !!! is ' + propertyValue)
  2837. }
  2838. }
  2839. },
  2840. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  2841. var node = this.nodes[nodeID];
  2842. if (node) {
  2843. node.methods[methodName] = methodParameters;
  2844. }
  2845. },
  2846. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  2847. //},
  2848. createdEvent: function (nodeID, eventName, eventParameters) {
  2849. var node = this.nodes[nodeID];
  2850. if (node) {
  2851. node.events[eventName] = eventParameters;
  2852. }
  2853. },
  2854. firedEvent: function (nodeID, eventName, eventParameters) {
  2855. },
  2856. executed: function (nodeID, scriptText, scriptType) {
  2857. // var nodeScript = {
  2858. // text: scriptText,
  2859. // type: scriptType,
  2860. // };
  2861. // if ( !this.allScripts[ nodeID ] ) {
  2862. // var nodeScripts = new Array();
  2863. // nodeScripts.push(nodeScript);
  2864. // this.allScripts[ nodeID ] = nodeScripts;
  2865. // }
  2866. // else {
  2867. // this.allScripts[ nodeID ].push(nodeScript);
  2868. // }
  2869. },
  2870. //ticked: [ /* time */ ],
  2871. });
  2872. function createCellWindow(elementID, cellNode, title) {
  2873. document.querySelector('#' + elementID).$cell({
  2874. $cell: true,
  2875. $type: "div",
  2876. id: elementID,
  2877. class: 'draggable',
  2878. $init: function () {
  2879. // let draggie = new Draggabilly('.draggable', {
  2880. // handle: '.handle',
  2881. // containment: true
  2882. // });
  2883. // get all draggie elements
  2884. var draggableElems = document.querySelectorAll('.draggable');
  2885. // array of Draggabillies
  2886. var draggies = []
  2887. // init Draggabillies
  2888. for (var i = 0, len = draggableElems.length; i < len; i++) {
  2889. var draggableElem = draggableElems[i];
  2890. var draggie = new Draggabilly(draggableElem, {
  2891. handle: '.handle',
  2892. containment: true
  2893. });
  2894. draggies.push(draggie);
  2895. }
  2896. this.style.visibility = 'hidden';
  2897. },
  2898. $components: [
  2899. {
  2900. $cell: true,
  2901. $type: "div",
  2902. class: "handle"
  2903. },
  2904. {
  2905. $cell: true,
  2906. $type: "button",
  2907. class: "mdc-button mdc-button--compact",
  2908. $text: "X",
  2909. onclick: function (e) {
  2910. //self.currentNodeID = m.ID;
  2911. document.querySelector('#' + elementID).style.visibility = 'hidden';
  2912. }
  2913. },
  2914. {
  2915. $cell: true,
  2916. $type: "span",
  2917. class: "mdc-typography--button",
  2918. $text: title
  2919. },
  2920. cellNode,
  2921. {
  2922. $cell: true,
  2923. $type: "div",
  2924. class: "handle",
  2925. style: "height: 10px; width: inherit;",
  2926. //$text: "sdfsdf"
  2927. }
  2928. // { $text: "23423"}
  2929. ]
  2930. }
  2931. );
  2932. }
  2933. // -- getChildByName --------------------------------------------------------------------
  2934. function getChildByName(node, childName) {
  2935. var childNode = undefined;
  2936. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  2937. if (node.children[i].name == childName) {
  2938. childNode = node.children[i];
  2939. }
  2940. }
  2941. return childNode;
  2942. };
  2943. // -- viewScript ------------------------------------------------------------------------
  2944. function createAceEditor(view, nodeID, elID) {
  2945. var editor = view.ace.edit(elID);
  2946. editor.setTheme("ace/theme/monokai");
  2947. editor.setFontSize(16);
  2948. editor.getSession().setMode("ace/mode/javascript");
  2949. editor.commands.addCommand({
  2950. name: "doit",
  2951. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  2952. exec: function () {
  2953. codeEditorDoit(editor, nodeID);
  2954. }
  2955. });
  2956. editor.commands.addCommand({
  2957. name: "printit",
  2958. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  2959. exec: function () {
  2960. codeEditorPrintit(editor, nodeID);
  2961. }
  2962. });
  2963. return editor;
  2964. }
  2965. function getPrototypes(kernel, extendsID) {
  2966. var prototypes = [];
  2967. var id = extendsID;
  2968. while (id !== undefined) {
  2969. prototypes.push(id);
  2970. id = kernel.prototype(id);
  2971. }
  2972. return prototypes;
  2973. }
  2974. function getPrototypes(kernel, extendsID) {
  2975. var prototypes = [];
  2976. var id = extendsID;
  2977. while (id !== undefined) {
  2978. prototypes.push(id);
  2979. id = kernel.prototype(id);
  2980. }
  2981. return prototypes;
  2982. }
  2983. function createProperty(node, propertyName, propertyValue) {
  2984. var property = {
  2985. name: propertyName,
  2986. rawValue: propertyValue,
  2987. value: undefined,
  2988. getValue: function () {
  2989. var propertyValue;
  2990. if (this.value == undefined) {
  2991. try {
  2992. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  2993. this.value = JSON.stringify(propertyValue);
  2994. } catch (e) {
  2995. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  2996. "stringify error:", e.message);
  2997. this.value = this.rawValue;
  2998. }
  2999. }
  3000. return this.value;
  3001. }
  3002. };
  3003. return property;
  3004. }
  3005. function getProperties(kernel, extendsID) {
  3006. var pTypes = getPrototypes(kernel, extendsID);
  3007. var pProperties = {};
  3008. if (pTypes) {
  3009. for (var i = 0; i < pTypes.length; i++) {
  3010. var nd = this.nodes[pTypes[i]];
  3011. if (nd && nd.properties) {
  3012. for (var key in nd.properties) {
  3013. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  3014. }
  3015. }
  3016. }
  3017. }
  3018. return pProperties;
  3019. }
  3020. function getChildren(kernel, extendsID) {
  3021. var pTypes = getPrototypes(kernel, extendsID);
  3022. var pChildren = {};
  3023. if (pTypes) {
  3024. for (var i = 0; i < pTypes.length; i++) {
  3025. var nd = this.nodes[pTypes[i]];
  3026. if (nd && nd.children) {
  3027. for (var key in nd.children) {
  3028. pChildren[key] = nd.children[key];
  3029. }
  3030. }
  3031. }
  3032. }
  3033. return pChildren;
  3034. }
  3035. function getEvents(kernel, extendsID) {
  3036. var pTypes = getPrototypes(kernel, extendsID);
  3037. var events = {};
  3038. if (pTypes) {
  3039. for (var i = 0; i < pTypes.length; i++) {
  3040. var nd = this.nodes[pTypes[i]];
  3041. if (nd && nd.events) {
  3042. for (var key in nd.events) {
  3043. events[key] = nd.events[key];
  3044. }
  3045. }
  3046. }
  3047. }
  3048. return events;
  3049. }
  3050. function getMethods(kernel, extendsID) {
  3051. var pTypes = getPrototypes(kernel, extendsID);
  3052. var methods = {};
  3053. if (pTypes) {
  3054. for (var i = 0; i < pTypes.length; i++) {
  3055. var nd = this.nodes[pTypes[i]];
  3056. if (nd && nd.methods) {
  3057. for (var key in nd.methods) {
  3058. methods[key] = nd.methods[key];
  3059. }
  3060. }
  3061. }
  3062. }
  3063. return methods;
  3064. }
  3065. // -- Show Code Editor tab
  3066. function codeEditorDoit(editor, nodeID) {
  3067. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3068. if (selectedText == "") {
  3069. var currline = editor.getSelectionRange().start.row;
  3070. var selectedText = editor.session.getLine(currline);
  3071. }
  3072. //console.log(selectedText);
  3073. //var sceneID = self.kernel.application();
  3074. vwf_view.kernel.execute(nodeID, selectedText);
  3075. }
  3076. function codeEditorPrintit(editor, nodeID) {
  3077. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3078. if (selectedText == "") {
  3079. var currline = editor.getSelectionRange().start.row;
  3080. var selectedText = editor.session.getLine(currline);
  3081. }
  3082. //console.log(selectedText);
  3083. //var sceneID = self.kernel.application();
  3084. let scriptText = 'console.log(' + selectedText + ');'
  3085. self.kernel.execute(nodeID, scriptText);
  3086. }
  3087. function saveStateAsFile(filename) // invoke with the view as "this"
  3088. {
  3089. this.logger.info("Saving: " + filename);
  3090. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  3091. if (supportAjaxUploadWithProgress.call(this)) {
  3092. var xhr = new XMLHttpRequest();
  3093. // Save State Information
  3094. var state = vwf.getState();
  3095. state.nodes[0].children = {};
  3096. var timestamp = state["queue"].time;
  3097. timestamp = Math.round(timestamp * 1000);
  3098. var objectIsTypedArray = function (candidate) {
  3099. var typedArrayTypes = [
  3100. Int8Array,
  3101. Uint8Array,
  3102. // Uint8ClampedArray,
  3103. Int16Array,
  3104. Uint16Array,
  3105. Int32Array,
  3106. Uint32Array,
  3107. Float32Array,
  3108. Float64Array
  3109. ];
  3110. var isTypedArray = false;
  3111. if (typeof candidate == "object" && candidate != null) {
  3112. typedArrayTypes.forEach(function (typedArrayType) {
  3113. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  3114. });
  3115. }
  3116. return isTypedArray;
  3117. };
  3118. var transitTransformation = function (object) {
  3119. return objectIsTypedArray(object) ?
  3120. Array.prototype.slice.call(object) : object;
  3121. };
  3122. var json = JSON.stringify(
  3123. require("vwf/utility").transform(
  3124. state, transitTransformation
  3125. )
  3126. );
  3127. json = $.encoder.encodeForURL(json);
  3128. var path = window.location.pathname;
  3129. var pathSplit = path.split('/');
  3130. if (pathSplit[0] == "") {
  3131. pathSplit.shift();
  3132. }
  3133. if (pathSplit[pathSplit.length - 1] == "") {
  3134. pathSplit.pop();
  3135. }
  3136. var inst = undefined;
  3137. var instIndex = pathSplit.length - 1;
  3138. if (pathSplit.length > 2) {
  3139. if (pathSplit[pathSplit.length - 2] == "load") {
  3140. instIndex = pathSplit.length - 3;
  3141. }
  3142. }
  3143. if (pathSplit.length > 3) {
  3144. if (pathSplit[pathSplit.length - 3] == "load") {
  3145. instIndex = pathSplit.length - 4;
  3146. }
  3147. }
  3148. inst = pathSplit[instIndex];
  3149. var root = "";
  3150. for (var i = 0; i < instIndex; i++) {
  3151. if (root != "") {
  3152. root = root + "/";
  3153. }
  3154. root = root + pathSplit[i];
  3155. }
  3156. if (filename == '') filename = inst;
  3157. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  3158. xhr.open("POST", "/" + root + "/save/" + filename, true);
  3159. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3160. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  3161. // Save Config Information
  3162. var config = { "info": {}, "model": {}, "view": {} };
  3163. // Save browser title
  3164. config["info"]["title"] = document.title//$('title').html();
  3165. // Save model drivers
  3166. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  3167. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  3168. });
  3169. // If neither glge or threejs model drivers are defined, specify nodriver
  3170. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  3171. // Save view drivers and associated parameters, if any
  3172. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  3173. if (viewDriver.indexOf('vwf/view/') != -1) {
  3174. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  3175. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  3176. }
  3177. else config["view"][viewDriver] = "";
  3178. }
  3179. });
  3180. var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  3181. // Save config file to server
  3182. var xhrConfig = new XMLHttpRequest();
  3183. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  3184. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3185. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  3186. }
  3187. else {
  3188. console.error("Unable to save state.");
  3189. }
  3190. }
  3191. // -- LoadSavedState --------------------------------------------------------------------------
  3192. function loadSavedState(filename, applicationpath, revision) {
  3193. this.logger.info("Loading: " + filename);
  3194. // Redirect until setState ID conflict is resolved
  3195. var path = window.location.pathname;
  3196. var inst = path.substring(path.length - 17, path.length - 1);
  3197. var pathSplit = path.split('/');
  3198. if (pathSplit[0] == "") {
  3199. pathSplit.shift();
  3200. }
  3201. if (pathSplit[pathSplit.length - 1] == "") {
  3202. pathSplit.pop();
  3203. }
  3204. var inst = undefined;
  3205. var instIndex = pathSplit.length - 1;
  3206. if (pathSplit.length > 2) {
  3207. if (pathSplit[pathSplit.length - 2] == "load") {
  3208. instIndex = pathSplit.length - 3;
  3209. }
  3210. }
  3211. if (pathSplit.length > 3) {
  3212. if (pathSplit[pathSplit.length - 3] == "load") {
  3213. instIndex = pathSplit.length - 4;
  3214. }
  3215. }
  3216. inst = pathSplit[instIndex];
  3217. if (revision) {
  3218. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  3219. }
  3220. else {
  3221. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  3222. }
  3223. // $.get(filename,function(data,status){
  3224. // vwf.setState(data);
  3225. // });
  3226. }
  3227. // -- SupportAjax -----------------------------------------------------------------------------
  3228. function supportAjaxUploadWithProgress() {
  3229. return supportAjaxUploadProgressEvents();
  3230. function supportAjaxUploadProgressEvents() {
  3231. var xhr = new XMLHttpRequest();
  3232. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  3233. }
  3234. }
  3235. });