1 /**
  2  * undo button
  3  * @author yiminghe@gmail.com
  4  */
  5 KISSY.add("editor/plugin/undo/btn", function (S, Editor, Button) {
  6 
  7     var UndoBtn = Button.extend({
  8 
  9         bindUI:function () {
 10             var self = this,
 11                 editor = self.get("editor");
 12             self.on("click", function () {
 13                 editor.execCommand("undo");
 14             });
 15             editor.on("afterUndo afterRedo afterSave", function (ev) {
 16                 var index = ev.index;
 17                 //有状态可后退
 18                 if (index > 0) {
 19                     self.set("disabled", false);
 20                 } else {
 21                     self.set("disabled", true);
 22                 }
 23             });
 24         }
 25     }, {
 26         ATTRS:{
 27             mode:{
 28                 value:Editor.WYSIWYG_MODE
 29             },
 30             disabled:{
 31                 // 默认 disabled
 32                 value:true
 33             }
 34         }
 35     });
 36 
 37 
 38     var RedoBtn = Button.extend({
 39 
 40         bindUI:function () {
 41             var self = this,
 42                 editor = self.get("editor");
 43             self.on("click", function () {
 44                 editor.execCommand("redo");
 45             });
 46             editor.on("afterUndo afterRedo afterSave", function (ev) {
 47                 var history = ev.history,
 48                     index = ev.index;
 49                 //有状态可前进
 50                 if (index < history.length - 1) {
 51                     self.set("disabled", false);
 52                 } else {
 53                     self.set("disabled", true);
 54                 }
 55             });
 56         }
 57     }, {
 58         mode:{
 59             value:Editor.WYSIWYG_MODE
 60         },
 61         ATTRS:{
 62             disabled:{
 63                 // 默认 disabled
 64                 value:true
 65             }
 66         }
 67     });
 68 
 69 
 70     return {
 71         RedoBtn:RedoBtn,
 72         UndoBtn:UndoBtn
 73     };
 74 
 75 }, {
 76     requires:['editor', '../button/']
 77 });