1 /** 2 * @fileOverview close extension for kissy dialog 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("component/uibase/close", function () { 6 7 /** 8 * @name Close 9 * @class 10 * Close extension class. 11 * Represent a close button. 12 * @memberOf Component.UIBase 13 */ 14 function Close() { 15 } 16 17 var HIDE = "hide"; 18 Close.ATTRS = 19 /** 20 * @lends Component.UIBase.Close.prototype 21 */ 22 { 23 /** 24 * Whether close button is visible. 25 * Default: true. 26 * @type Boolean 27 */ 28 closable:{ 29 view:1 30 }, 31 32 /** 33 * Close button. 34 */ 35 closeBtn:{ 36 view:1 37 }, 38 39 /** 40 * Whether to destroy or hide current element when click close button. 41 * Default: "hide". Can set "destroy" to destroy it when click close button. 42 * @type String 43 */ 44 closeAction:{ 45 value:HIDE 46 } 47 }; 48 49 var actions = { 50 hide:HIDE, 51 destroy:"destroy" 52 }; 53 54 Close.prototype = { 55 _uiSetClosable:function (v) { 56 var self = this; 57 if (v && !self.__bindCloseEvent) { 58 self.__bindCloseEvent = 1; 59 self.get("closeBtn").on("click", function (ev) { 60 self[actions[self.get("closeAction")] || HIDE](); 61 ev.preventDefault(); 62 }); 63 } 64 }, 65 __destructor:function () { 66 var btn = this.get("closeBtn"); 67 btn && btn.detach(); 68 } 69 }; 70 return Close; 71 72 });