Iframe.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Iframe = MWF.FCIframe = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_process_FormDesigner/Module/Iframe/iframe.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "../x_component_process_FormDesigner/Module/Iframe/";
  13. this.cssPath = "../x_component_process_FormDesigner/Module/Iframe/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.moduleType = "element";
  16. this.moduleName = "iframe";
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. },
  21. load : function(json, node, parent){
  22. this.json = json;
  23. this.node= node;
  24. this.node.store("module", this);
  25. var iframe = this.node.getElement("iframe");
  26. if (iframe) iframe.destroy();
  27. this.node.setStyles(this.css.moduleNode);
  28. this._loadNodeStyles();
  29. this._initModule();
  30. this._loadTreeNode(parent);
  31. this.setCustomStyles();
  32. this.parentContainer = this.treeNode.parentNode.module;
  33. this._setEditStyle_custom("id");
  34. this.parseModules();
  35. this.json.moduleName = this.moduleName;
  36. },
  37. _createMoveNode: function(){
  38. this.moveNode = new Element("div", {
  39. "MWFType": "iframe",
  40. "id": this.json.id,
  41. "styles": this.css.moduleNodeMove,
  42. "events": {
  43. "selectstart": function(){
  44. return false;
  45. }
  46. }
  47. }).inject(this.form.container);
  48. },
  49. _createNode: function(){
  50. this.node = this.moveNode.clone(true, true);
  51. this.node.setStyles(this.css.moduleNode);
  52. this.node.set("id", this.json.id);
  53. this.node.addEvent("selectstart", function(){
  54. return false;
  55. });
  56. this.iconNode = new Element("div", {
  57. "styles": this.css.iconNode
  58. }).inject(this.node);
  59. new Element("div", {
  60. "styles": this.css.iconNodeIcon
  61. }).inject(this.iconNode);
  62. new Element("div", {
  63. "styles": this.css.iconNodeText,
  64. "text": "iframe"
  65. }).inject(this.iconNode);
  66. this.iconNode.addEvent("click", function(){
  67. this.loadIframe();
  68. }.bind(this));
  69. },
  70. _loadNodeStyles: function(){
  71. this.iconNode = this.node.getElement("div");
  72. if (!this.iconNode) this.iconNode = new Element("div").inject(this.node, "top");
  73. this.iconNode.setStyles(this.css.iconNode);
  74. var icon = this.iconNode.getFirst("div");
  75. var text = this.iconNode.getLast("div");
  76. icon.setStyles(this.css.iconNodeIcon);
  77. text.setStyles(this.css.iconNodeText);
  78. this.iconNode.addEvent("click", function(){
  79. this.loadIframe();
  80. }.bind(this));
  81. },
  82. getIconPosition: function(){
  83. var p = this.node.getPosition(this.node.getOffsetParent());
  84. var size = this.node.getSize();
  85. var iconSize = this.iconNode.getSize();
  86. return {"x": p.x+size.x-iconSize.x-1, "y": p.y+1};
  87. },
  88. loadIframe: function(){
  89. if (this.iframe){
  90. this.closeSrc();
  91. }else{
  92. this.loadSrc();
  93. }
  94. },
  95. closeSrc: function(){
  96. this.iframe.destroy();
  97. this.iframe = null;
  98. this.iconNode.setStyles(this.css.iconNode);
  99. this.iconNode.getFirst().setStyles(this.css.iconNodeIcon);
  100. },
  101. loadSrc: function(){
  102. if (this.json.valueType!="script"){
  103. if (this.json.src){
  104. var p = this.getIconPosition();
  105. this.iconNode.setStyles({
  106. "float": "right",
  107. "margin-top": "0px",
  108. "position": "absolute",
  109. "top": p.y,
  110. "left": p.x-18
  111. });
  112. this.iconNode.getFirst().setStyles({
  113. "background": "url("+this.path+this.options.style+"/icon/close.png) 5px center no-repeat"
  114. });
  115. this.iframe = new Element("iframe", {
  116. "styles": this.css.iframe,
  117. "border": "0",
  118. "src": this.json.src
  119. });
  120. this.iframe.inject(this.node, "top");
  121. }
  122. }
  123. }
  124. });