document.js 6.3 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. let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
  43. userDB.get('worlds').get(worldName).get(dbPath).get('file').once(function(res) {
  44. var responseText = "";
  45. if (res) {
  46. responseText = res//.file;
  47. }
  48. // If the overlay attached a `createdNode` handler, forward this first call
  49. // since the overlay will have missed it.
  50. setInnerHtml(container, responseText);
  51. if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  52. self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  53. childSource, childType, childURI, childName );
  54. }
  55. // Remove the container div if an error occurred or if we received an empty
  56. // result. The server sends an empty document when the application doesn't
  57. // provide a chrome file.
  58. if ( responseText == "" ) {
  59. container.remove();
  60. }
  61. // Resume the queue.
  62. callback( true );
  63. })
  64. // fetch("admin/chrome", {
  65. // method: 'get'
  66. // }).then(function(response) {
  67. // return response.text();
  68. // }).catch(function(err) {
  69. // container.remove();
  70. // // Resume the queue.
  71. // callback( true );
  72. // }).then(function(responseText) {
  73. // // If the overlay attached a `createdNode` handler, forward this first call
  74. // // since the overlay will have missed it.
  75. // // setInnerHtml(container, responseText);
  76. // if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  77. // self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  78. // childSource, childType, childURI, childName );
  79. // }
  80. // // Remove the container div if an error occurred or if we received an empty
  81. // // result. The server sends an empty document when the application doesn't
  82. // // provide a chrome file.
  83. // if ( responseText == "" ) {
  84. // container.remove();
  85. // }
  86. // // Resume the queue.
  87. // callback( true );
  88. // });
  89. // container.load( "admin/chrome", function( responseText, textStatus ) {
  90. // // If the overlay attached a `createdNode` handler, forward this first call
  91. // // since the overlay will have missed it.
  92. // if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  93. // self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  94. // childSource, childType, childURI, childName );
  95. // }
  96. // // Remove the container div if an error occurred or if we received an empty
  97. // // result. The server sends an empty document when the application doesn't
  98. // // provide a chrome file.
  99. // if ( ! ( textStatus == "success" || textStatus == "notmodified" ) || responseText == "" ) {
  100. // container.remove();
  101. // }
  102. // // Resume the queue.
  103. // callback( true );
  104. // } );
  105. }
  106. },
  107. }, function( viewFunctionName ) {
  108. // == View API =============================================================================
  109. } );
  110. } );