Iframe.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. MWF.xApplication.cms.FormDesigner.Module = MWF.xApplication.cms.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("cms.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.cms.FormDesigner.Module.Iframe = MWF.CMSFCIframe = new Class({
  4. Extends: MWF.CMSFC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_cms_FormDesigner/Module/Iframe/iframe.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "/x_component_cms_FormDesigner/Module/Iframe/";
  13. this.cssPath = "/x_component_cms_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. },
  36. _createMoveNode: function(){
  37. this.moveNode = new Element("div", {
  38. "MWFType": "iframe",
  39. "id": this.json.id,
  40. "styles": this.css.moduleNodeMove,
  41. "events": {
  42. "selectstart": function(){
  43. return false;
  44. }
  45. }
  46. }).inject(this.form.container);
  47. },
  48. _createNode: function(){
  49. this.node = this.moveNode.clone(true, true);
  50. this.node.setStyles(this.css.moduleNode);
  51. this.node.set("id", this.json.id);
  52. this.node.addEvent("selectstart", function(){
  53. return false;
  54. });
  55. this.iconNode = new Element("div", {
  56. "styles": this.css.iconNode
  57. }).inject(this.node);
  58. new Element("div", {
  59. "styles": this.css.iconNodeIcon
  60. }).inject(this.iconNode);
  61. new Element("div", {
  62. "styles": this.css.iconNodeText,
  63. "text": "iframe"
  64. }).inject(this.iconNode);
  65. this.iconNode.addEvent("click", function(){
  66. this.loadIframe();
  67. }.bind(this));
  68. },
  69. _loadNodeStyles: function(){
  70. this.iconNode = this.node.getElement("div").setStyles(this.css.iconNode);
  71. this.iconNode.getFirst("div").setStyles(this.css.iconNodeIcon);
  72. this.iconNode.getLast("div").setStyles(this.css.iconNodeText);
  73. this.iconNode.addEvent("click", function(){
  74. this.loadIframe();
  75. }.bind(this));
  76. },
  77. getIconPosition: function(){
  78. var p = this.node.getPosition(this.node.getOffsetParent());
  79. var size = this.node.getSize();
  80. var iconSize = this.iconNode.getSize();
  81. return {"x": p.x+size.x-iconSize.x-1, "y": p.y+1};
  82. },
  83. loadIframe: function(){
  84. if (this.iframe){
  85. this.closeSrc();
  86. }else{
  87. this.loadSrc();
  88. }
  89. },
  90. closeSrc: function(){
  91. this.iframe.destroy();
  92. this.iframe = null;
  93. this.iconNode.setStyles(this.css.iconNode);
  94. this.iconNode.getFirst().setStyles(this.css.iconNodeIcon);
  95. },
  96. loadSrc: function(){
  97. if (this.json.valueType!="script"){
  98. if (this.json.src){
  99. var p = this.getIconPosition();
  100. this.iconNode.setStyles({
  101. "float": "right",
  102. "margin-top": "0px",
  103. "position": "absolute",
  104. "top": p.y,
  105. "left": p.x-18
  106. });
  107. this.iconNode.getFirst().setStyles({
  108. "background": "url("+MWF.defaultPath+"/cms/FormCustom/Module/Iframe/default/icon/close.png) 5px center no-repeat"
  109. });
  110. this.iframe = new Element("iframe", {
  111. "styles": this.css.iframe,
  112. "border": "0",
  113. "src": this.json.src
  114. });
  115. this.iframe.inject(this.node, "top");
  116. }
  117. }
  118. }
  119. });