document.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //"use strict";
  2. /*
  3. The MIT License (MIT)
  4. Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
  5. Virtual World Framework Apache 2.0 license (https://github.com/NikolaySuslov/livecodingspace/blob/master/licenses/LICENSE_VWF.md)
  6. */
  7. import {Fabric} from '/core/vwf/fabric.js';
  8. class VWFDocument extends Fabric {
  9. constructor(module) {
  10. console.log("Document constructor");
  11. super(module, 'View');
  12. }
  13. factory() {
  14. let _self_ = this;
  15. return this.load(this.module, {
  16. // == Module Definition ====================================================================
  17. initialize: function () {
  18. window.vwf_view = this;
  19. this.fabric = _self_;
  20. },
  21. // == Model API ============================================================================
  22. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  23. childSource, childType, childURI, childName, callback /* ( ready ) */ ) {
  24. let self = this;
  25. // At the root node of the application, load the UI chrome if available.
  26. if (childID == this.kernel.application() &&
  27. (window.location.protocol == "http:" || window.location.protocol == "https:")) {
  28. // Suspend the queue.
  29. callback(false);
  30. let moduleData = vwf.doc;
  31. if (moduleData) {
  32. var source;
  33. if(moduleData.startsWith('{')){ //EXAMPLE: {"url": "/defaults/worlds/pure/driver.js"}
  34. source = JSON.parse(moduleData).url;
  35. } else { //LOAD MODULE from string
  36. let data = _self_.helpers.replaceSubStringALL(moduleData, '$host', window.location.origin);
  37. source = "data:text/javascript;base64," + btoa(data);
  38. }
  39. import(source).then(res => {
  40. if (self.createdNode !== Object.getPrototypeOf(self).createdNode) {
  41. self.createdNode(nodeID, childID, childExtendsID, childImplementsIDs,
  42. childSource, childType, childURI, childName);
  43. }
  44. this.doc = new res.default;
  45. callback(true);
  46. })
  47. } else {
  48. setTimeout(() => {
  49. callback(true);
  50. }, 0);
  51. }
  52. }
  53. },
  54. }, function (viewFunctionName) {
  55. // == View API =============================================================================
  56. });
  57. }
  58. }
  59. export { VWFDocument as default}