|
52 | 52 | .on('mouseenter',$.proxy(this.mouseenterHandler,this)) |
53 | 53 | .on('mouseleave',$.proxy(this.mouseleaveHandler,this)); |
54 | 54 | } |
55 | | - $('body').off('keyup.webui-popover').on('keyup.webui-popover',$.proxy(this.escapeHandler,this)); |
56 | 55 | this._poped = false; |
57 | 56 | this._inited = true; |
58 | 57 | }, |
|
66 | 65 | } |
67 | 66 | }, |
68 | 67 | hide:function(event){ |
69 | | - if (event){event.preventDefault();} |
| 68 | + if (event){ |
| 69 | + event.preventDefault(); |
| 70 | + event.stopPropagation(); |
| 71 | + } |
70 | 72 | var e = $.Event('hide.' + pluginType); |
71 | 73 | this.$element.trigger(e); |
72 | | - |
73 | 74 | if (this.$target){this.$target.removeClass('in').hide();} |
74 | 75 | this.$element.trigger('hidden.'+pluginType); |
75 | 76 | }, |
76 | 77 | toggle:function(e){ |
77 | | - if (e) {e.preventDefault();} |
| 78 | + if (e) { |
| 79 | + e.preventDefault(); |
| 80 | + e.stopPropagation(); |
| 81 | + } |
78 | 82 | this[this.getTarget().hasClass('in') ? 'hide' : 'show'](); |
79 | 83 | }, |
80 | 84 | hideAll:function(){ |
81 | | - $('div.webui-popover').removeClass('in').hide(); |
| 85 | + $('div.webui-popover').not('.webui-popover-fixed').removeClass('in').hide(); |
82 | 86 | }, |
83 | 87 | /*core method ,show popover */ |
84 | 88 | show:function(){ |
|
103 | 107 | $target.show(); |
104 | 108 | } |
105 | 109 | this.displayContent(); |
| 110 | + this.bindBodyEvents(); |
106 | 111 | }, |
107 | 112 | displayContent:function(){ |
108 | 113 | var |
|
239 | 244 | } |
240 | 245 | }); |
241 | 246 | }, |
| 247 | + |
| 248 | + bindBodyEvents:function(){ |
| 249 | + $('body').off('keyup.webui-popover').on('keyup.webui-popover',$.proxy(this.escapeHandler,this)); |
| 250 | + $('body').off('click.webui-popover').on('click.webui-popover',$.proxy(this.bodyClickHandler,this)); |
| 251 | + }, |
| 252 | + |
242 | 253 | /* event handlers */ |
243 | 254 | mouseenterHandler:function(){ |
244 | 255 | var self = this; |
|
254 | 265 | }, |
255 | 266 | escapeHandler:function(e){ |
256 | 267 | if (e.keyCode===27){ |
257 | | - this.hide(); |
258 | 268 | this.hideAll(); |
259 | 269 | } |
260 | 270 | }, |
| 271 | + bodyClickHandler:function(){ |
| 272 | + this.hideAll(); |
| 273 | + }, |
| 274 | + |
| 275 | + targetClickHandler:function(e){ |
| 276 | + e.stopPropagation(); |
| 277 | + }, |
261 | 278 |
|
262 | 279 | //reset and init the target events; |
263 | 280 | initTargetEvents:function(){ |
|
267 | 284 | .on('mouseleave',$.proxy(this.mouseleaveHandler,this)); |
268 | 285 | } |
269 | 286 | this.$target.find('.close').off('click').on('click', $.proxy(this.hide,this)); |
| 287 | + this.$target.off('click.webui-popover').on('click.webui-popover',$.proxy(this.targetClickHandler,this)); |
270 | 288 | }, |
271 | 289 | /* utils methods */ |
272 | 290 | //caculate placement of the popover |
|
337 | 355 | arrowSize = this.options.arrow?28:0, |
338 | 356 | fixedW = elementW<arrowSize+10?arrowSize:0, |
339 | 357 | fixedH = elementH<arrowSize+10?arrowSize:0; |
340 | | - console.log(elementW,arrowSize); |
341 | 358 | switch (placement) { |
342 | 359 | case 'bottom': |
343 | 360 | position = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - targetWidth / 2}; |
|
0 commit comments