editor-new.js 156 KB

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