document.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. define( [ "module", "vwf/view", "vwf/utility"], function( module, view, utility) {
  8. return view.load( module, {
  9. // == Module Definition ====================================================================
  10. initialize: function() {
  11. window.vwf_view = this;
  12. },
  13. // == Model API ============================================================================
  14. createdNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  15. childSource, childType, childURI, childName, callback /* ( ready ) */ ) {
  16. var self = this;
  17. // At the root node of the application, load the UI chrome if available.
  18. let setInnerHtml = function(elm, html) {
  19. elm.innerHTML = html;
  20. Array.from(elm.querySelectorAll("script")).forEach(function(el) {
  21. let newEl = document.createElement("script");
  22. Array.from(el.attributes).forEach(function(el) {
  23. newEl.setAttribute(el.name, el.value)
  24. });
  25. newEl.appendChild(document.createTextNode(el.innerHTML));
  26. el.parentNode.replaceChild(newEl, el);
  27. })
  28. }
  29. if ( childID == this.kernel.application() &&
  30. ( window.location.protocol == "http:" || window.location.protocol == "https:" ) ) {
  31. // Suspend the queue.
  32. callback( false );
  33. // Load the file and insert it into the main page.
  34. // var container = jQuery( "body" ).append( "<div />" ).children( ":last" );
  35. let container = document.createElement("div");
  36. document.querySelector("body").appendChild(container);
  37. //var container = document.querySelector("body").append( "<div />" ).children( ":last" );
  38. let path = JSON.parse(localStorage.getItem('lcs_app')).path.public_path;
  39. let appName = JSON.parse(localStorage.getItem('lcs_app')).path.application.split(".").join("_");
  40. let dbPath = appName + '_html';
  41. let worldName = path.slice(1);
  42. _LCS_WORLD_USER.get('worlds').get(worldName).get(dbPath).once().then(res => {
  43. var responseText = "";
  44. if (res) {
  45. responseText = res.file;
  46. }
  47. // If the overlay attached a `createdNode` handler, forward this first call
  48. // since the overlay will have missed it.
  49. setInnerHtml(container, responseText);
  50. if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  51. self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  52. childSource, childType, childURI, childName );
  53. }
  54. // Remove the container div if an error occurred or if we received an empty
  55. // result. The server sends an empty document when the application doesn't
  56. // provide a chrome file.
  57. if ( responseText == "" ) {
  58. container.remove();
  59. }
  60. // Resume the queue.
  61. callback( true );
  62. })
  63. // fetch("admin/chrome", {
  64. // method: 'get'
  65. // }).then(function(response) {
  66. // return response.text();
  67. // }).catch(function(err) {
  68. // container.remove();
  69. // // Resume the queue.
  70. // callback( true );
  71. // }).then(function(responseText) {
  72. // // If the overlay attached a `createdNode` handler, forward this first call
  73. // // since the overlay will have missed it.
  74. // // setInnerHtml(container, responseText);
  75. // if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  76. // self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  77. // childSource, childType, childURI, childName );
  78. // }
  79. // // Remove the container div if an error occurred or if we received an empty
  80. // // result. The server sends an empty document when the application doesn't
  81. // // provide a chrome file.
  82. // if ( responseText == "" ) {
  83. // container.remove();
  84. // }
  85. // // Resume the queue.
  86. // callback( true );
  87. // });
  88. // container.load( "admin/chrome", function( responseText, textStatus ) {
  89. // // If the overlay attached a `createdNode` handler, forward this first call
  90. // // since the overlay will have missed it.
  91. // if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  92. // self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  93. // childSource, childType, childURI, childName );
  94. // }
  95. // // Remove the container div if an error occurred or if we received an empty
  96. // // result. The server sends an empty document when the application doesn't
  97. // // provide a chrome file.
  98. // if ( ! ( textStatus == "success" || textStatus == "notmodified" ) || responseText == "" ) {
  99. // container.remove();
  100. // }
  101. // // Resume the queue.
  102. // callback( true );
  103. // } );
  104. }
  105. },
  106. }, function( viewFunctionName ) {
  107. // == View API =============================================================================
  108. } );
  109. } );