Iframe.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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").setStyles(this.css.iconNode);
  72. this.iconNode.getFirst("div").setStyles(this.css.iconNodeIcon);
  73. this.iconNode.getLast("div").setStyles(this.css.iconNodeText);
  74. this.iconNode.addEvent("click", function(){
  75. this.loadIframe();
  76. }.bind(this));
  77. },
  78. getIconPosition: function(){
  79. var p = this.node.getPosition(this.node.getOffsetParent());
  80. var size = this.node.getSize();
  81. var iconSize = this.iconNode.getSize();
  82. return {"x": p.x+size.x-iconSize.x-1, "y": p.y+1};
  83. },
  84. loadIframe: function(){
  85. if (this.iframe){
  86. this.closeSrc();
  87. }else{
  88. this.loadSrc();
  89. }
  90. },
  91. closeSrc: function(){
  92. this.iframe.destroy();
  93. this.iframe = null;
  94. this.iconNode.setStyles(this.css.iconNode);
  95. this.iconNode.getFirst().setStyles(this.css.iconNodeIcon);
  96. },
  97. loadSrc: function(){
  98. if (this.json.valueType!="script"){
  99. if (this.json.src){
  100. var p = this.getIconPosition();
  101. this.iconNode.setStyles({
  102. "float": "right",
  103. "margin-top": "0px",
  104. "position": "absolute",
  105. "top": p.y,
  106. "left": p.x-18
  107. });
  108. this.iconNode.getFirst().setStyles({
  109. "background": "url("+this.path+this.options.style+"/icon/close.png) 5px center no-repeat"
  110. });
  111. this.iframe = new Element("iframe", {
  112. "styles": this.css.iframe,
  113. "border": "0",
  114. "src": this.json.src
  115. });
  116. this.iframe.inject(this.node, "top");
  117. }
  118. }
  119. }
  120. });