Skip to content
This repository
Browse code

note bubbled click

  • Loading branch information...
commit 1e97a6ec902a5ce1f264252b7f2a200ab87f7f2c 1 parent 0c69156
yiminghe yiminghe authored
36 build/combobox-min.js
... ... @@ -1,22 +1,22 @@
1 1 /*
2 2 Copyright 2012, KISSY UI Library v1.40dev
3 3 MIT Licensed
4   -build time: Jul 30 19:00
  4 +build time: Aug 7 18:59
5 5 */
6   -KISSY.add("combobox/base",function(f,h,a,g,j,C,m){function d(b,e){var c=b.get("menu");if(c&&c.xclass)if(e)c=a.create(c,b),b.__set("menu",c);else return null;return c}function k(){var b=d(this);if(b&&b.get("visible"))if(this.get("multiple")&&this.get("alignWithCursor")){var e=t(this),c=e.tokens,b=this.get("menu"),i=e.cursorPosition,a=e.tokenIndex,e=this.get("input"),c=c.slice(0,a).join("").length;0<c&&++c;e.prop("selectionStart",c);e.prop("selectionEnd",c);c=e.prop("KsCursorOffset");e.prop("selectionStart",
7   -i);e.prop("selectionEnd",i);b.set("xy",[c.left,c.top])}else b=this.get("menu"),i=f.clone(b.get("align")),i.node=this.get("el"),f.mix(i,z,!1),b.set("align",i)}function s(){var b=this;b._focusoutDismissTimer=setTimeout(function(){b.set("collapsed",!0)},30)}function o(){var b;if(b=this._focusoutDismissTimer)clearTimeout(b),this._focusoutDismissTimer=null}function p(b,e){var c=b.get("input");if(b.get("multiple")){var i=t(b),a=i.tokens,i=Math.max(0,i.tokenIndex),d=b.get("separator"),g=b.get("separatorType"),
8   -f=a[i];a[i]=f&&-1!=d.indexOf(f.charAt(0))?f.charAt(0):"";a[i]+=e;f=a[i+1];if(g==r&&(!f||-1==d.indexOf(f.charAt(0))))a[i]+=d.charAt(0);i=a.slice(0,i+1).join("").length;c.val(a.join(""));c.prop("selectionStart",i);c.prop("selectionEnd",i)}else c.val(e)}function q(b){var e=b.get("input").val();if(b.get("multiple")){var c=t(b),e=c.tokens,c=c.tokenIndex,a=b.get("separator"),b=b.get("separatorType");return(e=e[c]||"")&&-1!=a.indexOf(e.charAt(0))?e.substring(1):b==r&&(0==c||-1==c)?e:m}return e}function A(){if(!this._stopNotify){var b=
9   -q(this);b===m?this.set("collapsed",!0):(this._savedInputValue=b,this.sendRequest(b))}}function B(b){var e,c=[],a,g,l,j=d(this,1);j.removeChildren(!0);if(b&&b.length){b=b.slice(0,this.get("maxItemCount"));a=this.get("format")?this.get("format").call(this,q(this),b):[];for(l=0;l<b.length;l++)e=b[l],c.push(j.addChild(f.mix({xclass:"menuitem",content:e,textContent:e,value:e},a[l])));b=q(this);for(l=0;l<c.length;l++)if(c[l].get("textContent")==b){j.set("highlightedItem",c[l]);g=!0;break}if(!g&&this.get("autoHighlightFirst"))for(l=
10   -0;l<c.length;l++)if(!c[l].get("disabled")){j.set("highlightedItem",c[l]);break}this.set("collapsed",!1)}else this.set("collapsed",!0)}function u(){var b=this.get("input");this.get("collapsed")?(b[0].focus(),this.sendRequest("")):this.set("collapsed",!0)}function v(b){b.preventDefault()}function t(b){for(var e=b.get("input"),c=e.val(),a=[],d=[],f=b.get("literal"),g=b.get("separator"),j=!1,b=b.get("whitespace"),e=e.prop("selectionStart"),h=-1,k=0;k<c.length;k++){var m=c.charAt(k);k==e&&(h=a.length);
11   -if(!j&&(!b&&/\s|\xa0/.test(m)&&(a.push(d.join("")),d=[]),-1!=g.indexOf(m)))a.push(d.join("")),d=[];f&&m==f&&(j=!j);d.push(m)}d.length&&a.push(d.join(""));-1==h&&(h=a.length-1);return{tokens:a,cursorPosition:e,tokenIndex:h}}var w,j=h.all,n=h.KeyCodes,z={points:["bl","tl"],overflow:{adjustX:1,adjustY:1}},x=j(f.Env.host),r="suffix",y=f.buffer(k,50);return w=a.Controller.extend({_savedInputValue:null,_stopNotify:0,bindUI:function(){this.get("input").on("valuechange",A,this)},bindMenu:function(){var b=
12   -this,e,a;a=b.get("menu");a.on("click",function(a){a=a.target;b._stopNotify=1;b._selectItem(a);b.set("collapsed",!0);setTimeout(function(){b._stopNotify=0},50)});x.on("resize",y,b);e=a.get("el");a=a.get("contentEl");e.on("focusout",s,b);e.on("focusin",o,b);a.on("mouseover",function(){b.get("input")[0].focus();o.call(b)});b.bindMenu=f.noop},_uiSetHasTrigger:function(b){var a=this.get("trigger");b?(a.on("click",u,this),a.on("mousedown",v)):(a.detach("click",u,this),a.detach("mousedown",v))},sendRequest:function(b){this.get("dataSource").fetchData(b,
13   -B,this)},_uiSetCollapsed:function(b){if(b)(b=d(this))&&b.hide();else{var b=this.get("el"),a=d(this,1);o.call(this);a&&!a.get("visible")&&(a.render(),this.bindMenu(),this.get("matchElWidth")&&a.set("width",b.innerWidth()),a.show(),k.call(this),this.get("input").attr("aria-owns",a.get("el")[0].id))}},handleBlur:function(){w.superclass.handleBlur.apply(this,arguments);s.call(this)},handleKeyEventInternal:function(b){this.get("input");var a=d(this);if(a){var c=this.get("updateInputOnDownUp");c&&(this._stopNotify=
14   -f.inArray(b.keyCode,[n.UP,n.DOWN,n.ESC])?1:0);var g;if(a.get("visible")){var j=a.handleKeydown(b);c&&f.inArray(b.keyCode,[n.DOWN,n.UP])&&p(this,a.get("activeItem").get("textContent"));if(b.keyCode==n.ESC)return this.set("collapsed",!0),c&&p(this,this._savedInputValue),!0;if(b.keyCode==n.TAB&&(g=a.get("activeItem")))if(g.performActionInternal(),this.get("multiple"))return!0;return j}if(b.keyCode==n.DOWN||b.keyCode==n.UP)return this.sendRequest(q(this)),!0}},_selectItem:function(b){if(b){var a=b.get("textContent"),
15   -c=this.get("separatorType");p(this,a+(c==r?"":" "));this._savedInputValue=a;this.fire("click",{target:b})}},destructor:function(){x.detach("resize",y,this)}},{ATTRS:{input:{view:1},trigger:{view:1},allowTextSelection:{value:!0},hasTrigger:{view:1},menu:{value:{xclass:"popupmenu"},setter:function(b){b instanceof a.Controller&&b.__set("parent",this)}},collapsed:{view:1},dataSource:{setter:function(b){return a.create(b)}},maxItemCount:{value:99999},matchElWidth:{value:!0},format:{},multiple:{},separator:{value:",;"},
16   -separatorType:{value:r},whitespace:{valueFn:function(){return this.get("separatorType")==r}},updateInputOnDownUp:{value:!0},literal:{value:'"'},alignWithCursor:{},autoHighlightFirst:{},xrender:{value:g}}},{xclass:"combobox",priority:10})},{requires:["node","component","./baseRender","input-selection","menu"]});
17   -KISSY.add("combobox/baseRender",function(f,h){return h.Render.extend({createDom:function(){var a,g;a=this.get("el");var j=this.get("trigger");this.get("srcNode")||(a.append('<div class="ks-combobox-input-wrap"></div>'),a=a.one(".ks-combobox-input-wrap"),g=this.get("input")||f.all('<input aria-haspopup="true" aria-autocomplete="list" aria-haspopup="true" role="autocomplete" autocomplete="off" class="ks-combobox-input" />'),a.append(g),this.__set("input",g));j||this.__set("trigger",f.all('<div class="ks-combobox-trigger"><div class="ks-combobox-trigger-inner">&#x25BC;</div></div>'));
18   -this.get("trigger").unselectable()},getKeyEventTarget:function(){return this.get("input")},_uiSetCollapsed:function(a){this.get("input").attr("aria-expanded",a)},_uiSetHasTrigger:function(a){var g=this.get("trigger");a?this.get("el").prepend(g):g.remove()}},{ATTRS:{collapsed:{value:!0},hasTrigger:{value:!0},input:{},trigger:{}},HTML_PARSER:{input:function(a){return a.one(".ks-combobox-input")},trigger:function(a){return a.one(".ks-combobox-trigger")}}})},{requires:["component"]});
19   -KISSY.add("combobox",function(f,h,a,g){h.LocalDataSource=a;h.RemoteDataSource=g;return h},{requires:["combobox/base","combobox/LocalDataSource","combobox/RemoteDataSource"]});
20   -KISSY.add("combobox/LocalDataSource",function(f,h){function a(){a.superclass.constructor.apply(this,arguments)}a.ATTRS={data:{value:[]},parse:{value:function(a,j){var h=[],m=0;if(!a)return j;f.each(j,function(d){-1!=d.indexOf(a)&&h.push(d);m++});return h}}};f.extend(a,f.Base,{fetchData:function(a,f,h){var m=this.get("parse"),d=this.get("data"),d=m(a,d);f.call(h,d)}});h.Manager.setConstructorByXClass("combobox-LocalDataSource",a);return a},{requires:["component"]});
21   -KISSY.add("combobox/RemoteDataSource",function(f,h,a){function g(){g.superclass.constructor.apply(this,arguments);this.io=null;this.caches={}}g.ATTRS={paramName:{value:"q"},allowEmpty:{},cache:{},parse:{},xhrCfg:{value:{}}};f.extend(g,f.Base,{fetchData:function(a,f,g){var d=this,k,s=d.get("paramName"),o=d.get("parse"),p=d.get("cache"),q=d.get("allowEmpty");d.io&&(d.io.abort(),d.io=null);if(!a&&!0!==q)return f.call(g,[]);if(p&&(k=d.caches[a]))return f.call(g,k);k=d.get("xhrCfg");k.data=k.data||{};
22   -k.data[s]=a;k.success=function(h){o&&(h=o(a,h));d.__set("data",h);p&&(d.caches[a]=h);f.call(g,h)};d.io=h(k)}});a.Manager.setConstructorByXClass("combobox-RemoteDataSource",g);return g},{requires:["ajax","component"]});
  6 +KISSY.add("combobox/base",function(f,h,b,g,j,C,m){function d(a,e){var c=a.get("menu");if(c&&c.xclass)if(e)c=b.create(c,a),a.__set("menu",c);else return null;return c}function k(){var a=d(this);if(a&&a.get("visible"))if(this.get("multiple")&&this.get("alignWithCursor")){var e=t(this),c=e.tokens,a=this.get("menu"),i=e.cursorPosition,b=e.tokenIndex,e=this.get("input"),c=c.slice(0,b).join("").length;0<c&&++c;e.prop("selectionStart",c);e.prop("selectionEnd",c);c=e.prop("KsCursorOffset");e.prop("selectionStart",
  7 +i);e.prop("selectionEnd",i);a.set("xy",[c.left,c.top])}else a=this.get("menu"),i=f.clone(a.get("align")),i.node=this.get("el"),f.mix(i,z,!1),a.set("align",i)}function s(){var a=this;a._focusoutDismissTimer=setTimeout(function(){a.set("collapsed",!0)},30)}function o(){var a;if(a=this._focusoutDismissTimer)clearTimeout(a),this._focusoutDismissTimer=null}function p(a,e){var c=a.get("input");if(a.get("multiple")){var i=t(a),b=i.tokens,i=Math.max(0,i.tokenIndex),d=a.get("separator"),g=a.get("separatorType"),
  8 +f=b[i];b[i]=f&&-1!=d.indexOf(f.charAt(0))?f.charAt(0):"";b[i]+=e;f=b[i+1];if(g==r&&(!f||-1==d.indexOf(f.charAt(0))))b[i]+=d.charAt(0);i=b.slice(0,i+1).join("").length;c.val(b.join(""));c.prop("selectionStart",i);c.prop("selectionEnd",i)}else c.val(e)}function q(a){var e=a.get("input").val();if(a.get("multiple")){var c=t(a),e=c.tokens,c=c.tokenIndex,b=a.get("separator"),a=a.get("separatorType");return(e=e[c]||"")&&-1!=b.indexOf(e.charAt(0))?e.substring(1):a==r&&(0==c||-1==c)?e:m}return e}function A(){if(!this._stopNotify){var a=
  9 +q(this);a===m?this.set("collapsed",!0):(this._savedInputValue=a,this.sendRequest(a))}}function B(a){var e,c=[],b,g,l,j=d(this,1);j.removeChildren(!0);if(a&&a.length){a=a.slice(0,this.get("maxItemCount"));b=this.get("format")?this.get("format").call(this,q(this),a):[];for(l=0;l<a.length;l++)e=a[l],c.push(j.addChild(f.mix({xclass:"menuitem",content:e,textContent:e,value:e},b[l])));a=q(this);for(l=0;l<c.length;l++)if(c[l].get("textContent")==a){j.set("highlightedItem",c[l]);g=!0;break}if(!g&&this.get("autoHighlightFirst"))for(l=
  10 +0;l<c.length;l++)if(!c[l].get("disabled")){j.set("highlightedItem",c[l]);break}this.set("collapsed",!1)}else this.set("collapsed",!0)}function u(){var a=this.get("input");this.get("collapsed")?(a[0].focus(),this.sendRequest("")):this.set("collapsed",!0)}function v(a){a.preventDefault()}function t(a){for(var e=a.get("input"),c=e.val(),b=[],d=[],f=a.get("literal"),g=a.get("separator"),j=!1,a=a.get("whitespace"),e=e.prop("selectionStart"),h=-1,k=0;k<c.length;k++){var m=c.charAt(k);k==e&&(h=b.length);
  11 +if(!j&&(!a&&/\s|\xa0/.test(m)&&(b.push(d.join("")),d=[]),-1!=g.indexOf(m)))b.push(d.join("")),d=[];f&&m==f&&(j=!j);d.push(m)}d.length&&b.push(d.join(""));-1==h&&(h=b.length-1);return{tokens:b,cursorPosition:e,tokenIndex:h}}var w,j=h.all,n=h.KeyCodes,z={points:["bl","tl"],overflow:{adjustX:1,adjustY:1}},x=j(f.Env.host),r="suffix",y=f.buffer(k,50);return w=b.Controller.extend({_savedInputValue:null,_stopNotify:0,bindUI:function(){this.get("input").on("valuechange",A,this)},bindMenu:function(){var a=
  12 +this,e,b;b=a.get("menu");b.on("click",function(b){b=b.target;a._stopNotify=1;a._selectItem(b);a.set("collapsed",!0);setTimeout(function(){a._stopNotify=0},50)});x.on("resize",y,a);e=b.get("el");b=b.get("contentEl");e.on("focusout",s,a);e.on("focusin",o,a);b.on("mouseover",function(){a.get("input")[0].focus();o.call(a)});a.bindMenu=f.noop},_uiSetHasTrigger:function(a){var b=this.get("trigger");a?(b.on("click",u,this),b.on("mousedown",v)):(b.detach("click",u,this),b.detach("mousedown",v))},sendRequest:function(a){this.get("dataSource").fetchData(a,
  13 +B,this)},_uiSetCollapsed:function(a){if(a)(a=d(this))&&a.hide();else{var a=this.get("el"),b=d(this,1);o.call(this);b&&!b.get("visible")&&(b.render(),this.bindMenu(),this.get("matchElWidth")&&b.set("width",a.innerWidth()),b.show(),k.call(this),this.get("input").attr("aria-owns",b.get("el")[0].id))}},handleBlur:function(){w.superclass.handleBlur.apply(this,arguments);s.call(this)},handleKeyEventInternal:function(a){this.get("input");var b=d(this);if(b){var c=this.get("updateInputOnDownUp");c&&(this._stopNotify=
  14 +f.inArray(a.keyCode,[n.UP,n.DOWN,n.ESC])?1:0);var g;if(b.get("visible")){var j=b.handleKeydown(a);c&&f.inArray(a.keyCode,[n.DOWN,n.UP])&&p(this,b.get("activeItem").get("textContent"));if(a.keyCode==n.ESC)return this.set("collapsed",!0),c&&p(this,this._savedInputValue),!0;if(a.keyCode==n.TAB&&(g=b.get("activeItem")))if(g.performActionInternal(),this.get("multiple"))return!0;return j}if(a.keyCode==n.DOWN||a.keyCode==n.UP)return this.sendRequest(q(this)),!0}},_selectItem:function(a){if(a){var a=a.get("textContent"),
  15 +b=this.get("separatorType");p(this,a+(b==r?"":" "));this._savedInputValue=a}},destructor:function(){x.detach("resize",y,this)}},{ATTRS:{input:{view:1},trigger:{view:1},allowTextSelection:{value:!0},hasTrigger:{view:1},menu:{value:{xclass:"popupmenu"},setter:function(a){a instanceof b.Controller&&a.__set("parent",this)}},collapsed:{view:1},dataSource:{setter:function(a){return b.create(a)}},maxItemCount:{value:99999},matchElWidth:{value:!0},format:{},multiple:{},separator:{value:",;"},separatorType:{value:r},
  16 +whitespace:{valueFn:function(){return this.get("separatorType")==r}},updateInputOnDownUp:{value:!0},literal:{value:'"'},alignWithCursor:{},autoHighlightFirst:{},xrender:{value:g}}},{xclass:"combobox",priority:10})},{requires:["node","component","./baseRender","input-selection","menu"]});
  17 +KISSY.add("combobox/baseRender",function(f,h){return h.Render.extend({createDom:function(){var b,g;b=this.get("el");var j=this.get("trigger");this.get("srcNode")||(b.append('<div class="ks-combobox-input-wrap"></div>'),b=b.one(".ks-combobox-input-wrap"),g=this.get("input")||f.all('<input aria-haspopup="true" aria-autocomplete="list" aria-haspopup="true" role="autocomplete" autocomplete="off" class="ks-combobox-input" />'),b.append(g),this.__set("input",g));j||this.__set("trigger",f.all('<div class="ks-combobox-trigger"><div class="ks-combobox-trigger-inner">&#x25BC;</div></div>'));
  18 +this.get("trigger").unselectable()},getKeyEventTarget:function(){return this.get("input")},_uiSetCollapsed:function(b){this.get("input").attr("aria-expanded",b)},_uiSetHasTrigger:function(b){var g=this.get("trigger");b?this.get("el").prepend(g):g.remove()}},{ATTRS:{collapsed:{value:!0},hasTrigger:{value:!0},input:{},trigger:{}},HTML_PARSER:{input:function(b){return b.one(".ks-combobox-input")},trigger:function(b){return b.one(".ks-combobox-trigger")}}})},{requires:["component"]});
  19 +KISSY.add("combobox",function(f,h,b,g){h.LocalDataSource=b;h.RemoteDataSource=g;return h},{requires:["combobox/base","combobox/LocalDataSource","combobox/RemoteDataSource"]});
  20 +KISSY.add("combobox/LocalDataSource",function(f,h){function b(){b.superclass.constructor.apply(this,arguments)}b.ATTRS={data:{value:[]},parse:{value:function(b,j){var h=[],m=0;if(!b)return j;f.each(j,function(d){-1!=d.indexOf(b)&&h.push(d);m++});return h}}};f.extend(b,f.Base,{fetchData:function(b,f,h){var m=this.get("parse"),d=this.get("data"),d=m(b,d);f.call(h,d)}});h.Manager.setConstructorByXClass("combobox-LocalDataSource",b);return b},{requires:["component"]});
  21 +KISSY.add("combobox/RemoteDataSource",function(f,h,b){function g(){g.superclass.constructor.apply(this,arguments);this.io=null;this.caches={}}g.ATTRS={paramName:{value:"q"},allowEmpty:{},cache:{},parse:{},xhrCfg:{value:{}}};f.extend(g,f.Base,{fetchData:function(b,f,g){var d=this,k,s=d.get("paramName"),o=d.get("parse"),p=d.get("cache"),q=d.get("allowEmpty");d.io&&(d.io.abort(),d.io=null);if(!b&&!0!==q)return f.call(g,[]);if(p&&(k=d.caches[b]))return f.call(g,k);k=d.get("xhrCfg");k.data=k.data||{};
  22 +k.data[s]=b;k.success=function(h){o&&(h=o(b,h));d.__set("data",h);p&&(d.caches[b]=h);f.call(g,h)};d.io=h(k)}});b.Manager.setConstructorByXClass("combobox-RemoteDataSource",g);return g},{requires:["ajax","component"]});
7 build/combobox.js
... ... @@ -1,7 +1,7 @@
1 1 /*
2 2 Copyright 2012, KISSY UI Library v1.40dev
3 3 MIT Licensed
4   -build time: Jul 30 19:00
  4 +build time: Aug 7 18:59
5 5 */
6 6 /**
7 7 * @fileOverview Input wrapper for ComboBox component.
@@ -310,14 +310,11 @@ KISSY.add("combobox/base", function (S, Node, Component, ComboBoxRender, _, Menu
310 310 self._savedInputValue = textContent;
311 311 /**
312 312 * @name ComboBox#click
313   - * @description fired when user select from suggestion list
  313 + * @description fired when user select from suggestion list (bubbled from menuItem)
314 314 * @event
315 315 * @param e
316 316 * @param e.target Selected menuItem
317 317 */
318   - self.fire("click", {
319   - target:item
320   - });
321 318 }
322 319 },
323 320
5 src/combobox/src/base.js
@@ -305,14 +305,11 @@ KISSY.add("combobox/base", function (S, Node, Component, ComboBoxRender, _, Menu
305 305 self._savedInputValue = textContent;
306 306 /**
307 307 * @name ComboBox#click
308   - * @description fired when user select from suggestion list
  308 + * @description fired when user select from suggestion list (bubbled from menuItem)
309 309 * @event
310 310 * @param e
311 311 * @param e.target Selected menuItem
312 312 */
313   - self.fire("click", {
314   - target:item
315   - });
316 313 }
317 314 },
318 315

0 comments on commit 1e97a6e

Please sign in to comment.
Something went wrong with that request. Please try again.