CssArea.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.widget.ScriptArea", null, false);
  3. //o2.require("o2.widget.CssEditor", null, false);
  4. o2.widget.CssArea = new Class({
  5. Implements: [Options, Events],
  6. Extends: o2.widget.ScriptArea,
  7. options: {
  8. "title": "CssArea",
  9. "style": "default",
  10. "helpStyle" : "default",
  11. "maxObj": document.body,
  12. "isload": false,
  13. "key": "code"
  14. },
  15. initialize: function(node, options){
  16. this.setOptions(options);
  17. this.node = $(node);
  18. this.container = new Element("div");
  19. this.path = o2.session.path+"/widget/$CssArea/";
  20. this.cssPath = o2.session.path+"/widget/$CssArea/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. },
  23. toJson: function(){
  24. return (this.editor) ? {"code": this.editor.getValue(), "html": this.editor.getValue()} : this.contentCode;
  25. },
  26. createContent: function(content){
  27. this.contentNode = new Element("div", {
  28. "styles": this.css.contentNode
  29. }).inject(this.container);
  30. this.resizeContentNodeSize();
  31. this.contentCode = content;
  32. if (!content || !content.code){
  33. this.referenceNode.setStyle("background", "url("+o2.session.path+"/widget/$ScriptArea/"+this.options.style+"/icon/reference_empty.png) center center no-repeat")
  34. }
  35. if (this.options.isload){
  36. this.loadEditor(content);
  37. }else{
  38. var inforNode = new Element("div", {"styles": this.css.inforNode, "text": o2.LP.widget.clickToEditCss }).inject(this.contentNode);
  39. var _self = this;
  40. inforNode.addEvent("click", function(){
  41. this.destroy();
  42. _self.loadEditor(content);
  43. });
  44. }
  45. },
  46. loadEditor: function(content){
  47. var value=(content) ? content.code : "";
  48. value = (value) ? value : "";
  49. this.jsEditor = new o2.widget.JavascriptEditor(this.contentNode,{
  50. "option": {
  51. "mode": "css",
  52. "value": value,
  53. "lineNumbers": false
  54. },
  55. "onPostLoad": function(){
  56. this.editor = this.jsEditor.editor;
  57. this.editor.id = "2";
  58. this.jsEditor.addEditorEvent("change", function() {
  59. this.fireEvent("change");
  60. }.bind(this));
  61. this.jsEditor.addEditorEvent("blur", function() {
  62. this.fireEvent("blur");
  63. }.bind(this));
  64. // this.editor.on("change", function() {
  65. // this.fireEvent("change");
  66. // }.bind(this));
  67. // this.editor.on("blur", function() {
  68. // this.fireEvent("blur");
  69. // }.bind(this));
  70. this.jsEditor.resize();
  71. this.fireEvent("postLoad");
  72. }.bind(this),
  73. "onSave": function(){
  74. this.fireEvent("change");
  75. this.fireEvent("save");
  76. }.bind(this)
  77. });
  78. this.jsEditor.load();
  79. //this.bind(content);
  80. this.createScriptReferenceMenu();
  81. this.jsEditor.addEvent("reference", function(editor, e, e1){
  82. if (!this.scriptReferenceMenu){
  83. this.createScriptReferenceMenu(this.showReferenceMenu.bind(this));
  84. }else{
  85. this.showReferenceMenu();
  86. }
  87. }.bind(this));
  88. this.referenceNode.setStyle("background", "url("+o2.session.path+"/widget/$ScriptArea/"+this.options.style+"/icon/reference.png) center center no-repeat")
  89. }
  90. });