CssArea.js 3.2 KB

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