You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.6 KiB

7 years ago
  1. /*
  2. Copyright (C) NAVER corp.
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with this library; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  14. */
  15. if(typeof window.nhn=='undefined') window.nhn = {};
  16. if (!nhn.husky) nhn.husky = {};
  17. /**
  18. * @fileOverview This file contains application creation helper function, which would load up an HTML(Skin) file and then execute a specified create function.
  19. * @name HuskyEZCreator.js
  20. */
  21. nhn.husky.EZCreator = new (function(){
  22. this.nBlockerCount = 0;
  23. this.createInIFrame = function(htOptions){
  24. if(arguments.length == 1){
  25. var oAppRef = htOptions.oAppRef;
  26. var elPlaceHolder = htOptions.elPlaceHolder;
  27. var sSkinURI = htOptions.sSkinURI;
  28. var fCreator = htOptions.fCreator;
  29. var fOnAppLoad = htOptions.fOnAppLoad;
  30. var bUseBlocker = htOptions.bUseBlocker;
  31. var htParams = htOptions.htParams || null;
  32. }else{
  33. // for backward compatibility only
  34. var oAppRef = arguments[0];
  35. var elPlaceHolder = arguments[1];
  36. var sSkinURI = arguments[2];
  37. var fCreator = arguments[3];
  38. var fOnAppLoad = arguments[4];
  39. var bUseBlocker = arguments[5];
  40. var htParams = arguments[6];
  41. }
  42. if(bUseBlocker) nhn.husky.EZCreator.showBlocker();
  43. var attachEvent = function(elNode, sEvent, fHandler){
  44. if(elNode.addEventListener){
  45. elNode.addEventListener(sEvent, fHandler, false);
  46. }else{
  47. elNode.attachEvent("on"+sEvent, fHandler);
  48. }
  49. }
  50. if(!elPlaceHolder){
  51. alert("Placeholder is required!");
  52. return;
  53. }
  54. if(typeof(elPlaceHolder) != "object")
  55. elPlaceHolder = document.getElementById(elPlaceHolder);
  56. var elIFrame, nEditorWidth, nEditorHeight;
  57. try{
  58. elIFrame = document.createElement("<IFRAME frameborder=0 scrolling=no>");
  59. }catch(e){
  60. elIFrame = document.createElement("IFRAME");
  61. elIFrame.setAttribute("frameborder", "0");
  62. elIFrame.setAttribute("scrolling", "no");
  63. }
  64. elIFrame.style.width = "1px";
  65. elIFrame.style.height = "1px";
  66. elPlaceHolder.parentNode.insertBefore(elIFrame, elPlaceHolder.nextSibling);
  67. attachEvent(elIFrame, "load", function(){
  68. fCreator = elIFrame.contentWindow[fCreator] || elIFrame.contentWindow.createSEditor2;
  69. // top.document.title = ((new Date())-window.STime);
  70. // window.STime = new Date();
  71. try{
  72. nEditorWidth = elIFrame.contentWindow.document.body.scrollWidth || "500px";
  73. nEditorHeight = elIFrame.contentWindow.document.body.scrollHeight + 12;
  74. elIFrame.style.width = "100%";
  75. elIFrame.style.height = nEditorHeight+ "px";
  76. elIFrame.contentWindow.document.body.style.margin = "0";
  77. }catch(e){
  78. nhn.husky.EZCreator.hideBlocker(true);
  79. elIFrame.style.border = "5px solid red";
  80. elIFrame.style.width = "500px";
  81. elIFrame.style.height = "500px";
  82. alert("Failed to access "+sSkinURI);
  83. return;
  84. }
  85. var oApp = fCreator(elPlaceHolder, htParams); // oEditor
  86. oApp.elPlaceHolder = elPlaceHolder;
  87. oAppRef[oAppRef.length] = oApp;
  88. if(!oAppRef.getById) oAppRef.getById = {};
  89. if(elPlaceHolder.id) oAppRef.getById[elPlaceHolder.id] = oApp;
  90. oApp.run({fnOnAppReady:fOnAppLoad});
  91. // top.document.title += ", "+((new Date())-window.STime);
  92. nhn.husky.EZCreator.hideBlocker();
  93. });
  94. // window.STime = new Date();
  95. elIFrame.src = sSkinURI;
  96. this.elIFrame = elIFrame;
  97. };
  98. this.showBlocker = function(){
  99. if(this.nBlockerCount<1){
  100. var elBlocker = document.createElement("DIV");
  101. elBlocker.style.position = "absolute";
  102. elBlocker.style.top = 0;
  103. elBlocker.style.left = 0;
  104. elBlocker.style.backgroundColor = "#FFFFFF";
  105. elBlocker.style.width = "100%";
  106. document.body.appendChild(elBlocker);
  107. nhn.husky.EZCreator.elBlocker = elBlocker;
  108. }
  109. nhn.husky.EZCreator.elBlocker.style.height = Math.max(document.body.scrollHeight, document.body.clientHeight)+"px";
  110. this.nBlockerCount++;
  111. };
  112. this.hideBlocker = function(bForce){
  113. if(!bForce){
  114. if(--this.nBlockerCount > 0) return;
  115. }
  116. this.nBlockerCount = 0;
  117. if(nhn.husky.EZCreator.elBlocker) nhn.husky.EZCreator.elBlocker.style.display = "none";
  118. }
  119. })();