Skip to content

Commit a18452f

Browse files
committed
Merge branch 'beta'
2 parents 07355ab + 8b26917 commit a18452f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/jquery.webui-popover.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
.on('mouseenter',$.proxy(this.mouseenterHandler,this))
5353
.on('mouseleave',$.proxy(this.mouseleaveHandler,this));
5454
}
55-
$('body').off('keyup.webui-popover').on('keyup.webui-popover',$.proxy(this.escapeHandler,this));
5655
this._poped = false;
5756
this._inited = true;
5857
},
@@ -66,19 +65,24 @@
6665
}
6766
},
6867
hide:function(event){
69-
if (event){event.preventDefault();}
68+
if (event){
69+
event.preventDefault();
70+
event.stopPropagation();
71+
}
7072
var e = $.Event('hide.' + pluginType);
7173
this.$element.trigger(e);
72-
7374
if (this.$target){this.$target.removeClass('in').hide();}
7475
this.$element.trigger('hidden.'+pluginType);
7576
},
7677
toggle:function(e){
77-
if (e) {e.preventDefault();}
78+
if (e) {
79+
e.preventDefault();
80+
e.stopPropagation();
81+
}
7882
this[this.getTarget().hasClass('in') ? 'hide' : 'show']();
7983
},
8084
hideAll:function(){
81-
$('div.webui-popover').removeClass('in').hide();
85+
$('div.webui-popover').not('.webui-popover-fixed').removeClass('in').hide();
8286
},
8387
/*core method ,show popover */
8488
show:function(){
@@ -103,6 +107,7 @@
103107
$target.show();
104108
}
105109
this.displayContent();
110+
this.bindBodyEvents();
106111
},
107112
displayContent:function(){
108113
var
@@ -239,6 +244,12 @@
239244
}
240245
});
241246
},
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+
242253
/* event handlers */
243254
mouseenterHandler:function(){
244255
var self = this;
@@ -254,10 +265,16 @@
254265
},
255266
escapeHandler:function(e){
256267
if (e.keyCode===27){
257-
this.hide();
258268
this.hideAll();
259269
}
260270
},
271+
bodyClickHandler:function(){
272+
this.hideAll();
273+
},
274+
275+
targetClickHandler:function(e){
276+
e.stopPropagation();
277+
},
261278

262279
//reset and init the target events;
263280
initTargetEvents:function(){
@@ -267,6 +284,7 @@
267284
.on('mouseleave',$.proxy(this.mouseleaveHandler,this));
268285
}
269286
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));
270288
},
271289
/* utils methods */
272290
//caculate placement of the popover
@@ -337,7 +355,6 @@
337355
arrowSize = this.options.arrow?28:0,
338356
fixedW = elementW<arrowSize+10?arrowSize:0,
339357
fixedH = elementH<arrowSize+10?arrowSize:0;
340-
console.log(elementW,arrowSize);
341358
switch (placement) {
342359
case 'bottom':
343360
position = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - targetWidth / 2};

0 commit comments

Comments
 (0)