editor-new.js 157 KB

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