1 /**
  2  * resize functionality
  3  * @author yiminghe@gmail.com
  4  */
  5 KISSY.add("editor/plugin/resize/index", function (S, Editor, DD) {
  6     var Node = S.Node;
  7 
  8     function Resize(config) {
  9 this.config=config||{};
 10     }
 11 
 12     S.augment(Resize, {
 13         renderUI:function (editor) {
 14             var Draggable = DD['Draggable'],
 15                 statusBarEl = editor.get("statusBarEl"),
 16                 textarea = editor.get("textarea"),
 17                 cfg = this.config,
 18                 direction = cfg["direction"] || ["x", "y"];
 19 
 20             var cursor = 'se-resize';
 21 
 22             if (direction.length == 1) {
 23                 if (direction[0] == "x") {
 24                     cursor = "e-resize"
 25                 } else {
 26                     cursor = "s-resize"
 27                 }
 28             }
 29 
 30             var resizer = new Node("<div class='ks-editor-resizer' style='cursor: "
 31                 + cursor +
 32                 "'></div>").appendTo(statusBarEl);
 33 
 34             //最大化时就不能缩放了
 35             editor.on("maximizeWindow", function () {
 36                 resizer.css("display", "none");
 37             });
 38 
 39             editor.on("restoreWindow", function () {
 40                 resizer.css("display", "");
 41             });
 42 
 43             var d = new Draggable({
 44                     node:resizer
 45                 }),
 46                 height = 0,
 47                 width = 0,
 48                 heightEl = editor.get("el"),
 49                 widthEl = editor.get("el");
 50 
 51             d.on("dragstart", function () {
 52                 height = heightEl.height();
 53                 width = widthEl.width();
 54                 editor.fire("resizeStart");
 55             });
 56 
 57             d.on("drag", function (ev) {
 58                 var self = this,
 59                     diffX = ev.left - self['startNodePos'].left,
 60                     diffY = ev.top - self['startNodePos'].top;
 61                 if (S.inArray("y", direction)) {
 62                     editor.set("height", height + diffY);
 63                 }
 64                 if (S.inArray("x", direction)) {
 65                     editor.set("width", width + diffX);
 66                 }
 67                 editor.fire("resize");
 68             });
 69 
 70             editor.on("destroy", function () {
 71                 d.destroy();
 72                 resizer.remove();
 73             });
 74         }
 75     });
 76 
 77     return Resize;
 78 }, {
 79     requires:['editor', 'dd']
 80 });