1 /**
  2  * @fileOverview event-focusin
  3  * @author yiminghe@gmail.com
  4  */
  5 KISSY.add('event/focusin', function (S, UA, Event, special) {
  6     // 让非 IE 浏览器支持 focusin/focusout
  7     if (!UA['ie']) {
  8         S.each([
  9             { name:'focusin', fix:'focus' },
 10             { name:'focusout', fix:'blur' }
 11         ], function (o) {
 12             var key = S.guid("attaches_" + S.now() + "_")
 13             special[o.name] = {
 14                 // 统一在 document 上 capture focus/blur 事件,然后模拟冒泡 fire 出来
 15                 // 达到和 focusin 一样的效果 focusin -> focus
 16                 // refer: http://yiminghe.iteye.com/blog/813255
 17                 setup:function () {
 18                     // this maybe document
 19                     var doc = this.ownerDocument || this;
 20                     if (!(key in doc)) {
 21                         doc[key] = 0;
 22                     }
 23                     doc[key] += 1;
 24                     if (doc[key] === 1) {
 25                         doc.addEventListener(o.fix, handler, true);
 26                     }
 27                 },
 28 
 29                 tearDown:function () {
 30                     var doc = this.ownerDocument || this;
 31                     doc[key] -= 1;
 32                     if (doc[key] === 0) {
 33                         doc.removeEventListener(o.fix, handler, true);
 34                     }
 35                 }
 36             };
 37 
 38             function handler(event) {
 39                 var target = event.target;
 40                 return Event.fire(target, o.name);
 41             }
 42 
 43         });
 44     }
 45 
 46     special["focus"] = {
 47         delegateFix:"focusin"
 48     };
 49 
 50     special["blur"] = {
 51         delegateFix:"focusout"
 52     };
 53 
 54     return Event;
 55 }, {
 56     requires:["ua", "./base", './special']
 57 });
 58 
 59 /**
 60  * 承玉:2011-06-07
 61  * - refactor to jquery , 更加合理的模拟冒泡顺序,子元素先出触发,父元素后触发
 62  *
 63  * NOTES:
 64  *  - webkit 和 opera 已支持 DOMFocusIn/DOMFocusOut 事件,但上面的写法已经能达到预期效果,暂时不考虑原生支持。
 65  */
 66