Skip to content

Commit f920354

Browse files
committed
enable click page to hide popover
1 parent a18452f commit f920354

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

demo/index-dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ <h1> <i class="glyphicon glyphicon-comment"></i> WebUI Popover Dev</h1>
139139
<div class="row row-middle">
140140
<div class="col-md-4"><a href="#" class="show-pop btn btn-danger" data-placement="right">pop right</a></div>
141141
<div class="col-md-4">
142-
<div class="webui-popover webui-popover-demo top in" style=" display: block;"><div class="arrow"></div><div class="webui-popover-inner"><h3 class="webui-popover-title">Welcome to WebUI Popover</h3><div class="webui-popover-content"><p>This is webui popover demo.</p><p>just enjoy it and have fun !</p><p>email : sanddywalker@gmail.com</p></div></div></div>
142+
<div class="webui-popover webui-popover-demo top in webui-popover-fixed" style=" display: block;"><div class="arrow"></div><div class="webui-popover-inner"><h3 class="webui-popover-title">Welcome to WebUI Popover</h3><div class="webui-popover-content"><p>This is webui popover demo.</p><p>just enjoy it and have fun !</p><p>email : sanddywalker@gmail.com</p></div></div></div>
143143

144144
</div>
145145
<div class="col-md-4"><a href="#" class="show-pop btn btn-danger pull-right" data-placement="left">pop left</a></div>

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ <h1> <i class="glyphicon glyphicon-comment"></i> WebUI Popover Demo</h1>
139139
<div class="row row-middle">
140140
<div class="col-md-4"><a href="#" class="show-pop btn btn-danger" data-placement="right">pop right</a></div>
141141
<div class="col-md-4">
142-
<div class="webui-popover webui-popover-demo top in" style=" display: block;"><div class="arrow"></div><div class="webui-popover-inner"><h3 class="webui-popover-title">Welcome to WebUI Popover</h3><div class="webui-popover-content"><p>This is webui popover demo.</p><p>just enjoy it and have fun !</p><p>email : sanddywalker@gmail.com</p></div></div></div>
142+
<div class="webui-popover webui-popover-demo top in webui-popover-fixed" style=" display: block;"><div class="arrow"></div><div class="webui-popover-inner"><h3 class="webui-popover-title">Welcome to WebUI Popover</h3><div class="webui-popover-content"><p>This is webui popover demo.</p><p>just enjoy it and have fun !</p><p>email : sanddywalker@gmail.com</p></div></div></div>
143143

144144
</div>
145145
<div class="col-md-4"><a href="#" class="show-pop btn btn-danger pull-right" data-placement="left">pop left</a></div>

dist/jquery.webui-popover.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
.on('mouseenter',$.proxy(this.mouseenterHandler,this))
6161
.on('mouseleave',$.proxy(this.mouseleaveHandler,this));
6262
}
63-
$('body').off('keyup.webui-popover').on('keyup.webui-popover',$.proxy(this.escapeHandler,this));
6463
this._poped = false;
6564
this._inited = true;
6665
},
@@ -74,19 +73,24 @@
7473
}
7574
},
7675
hide:function(event){
77-
if (event){event.preventDefault();}
76+
if (event){
77+
event.preventDefault();
78+
event.stopPropagation();
79+
}
7880
var e = $.Event('hide.' + pluginType);
7981
this.$element.trigger(e);
80-
8182
if (this.$target){this.$target.removeClass('in').hide();}
8283
this.$element.trigger('hidden.'+pluginType);
8384
},
8485
toggle:function(e){
85-
if (e) {e.preventDefault();}
86+
if (e) {
87+
e.preventDefault();
88+
e.stopPropagation();
89+
}
8690
this[this.getTarget().hasClass('in') ? 'hide' : 'show']();
8791
},
8892
hideAll:function(){
89-
$('div.webui-popover').removeClass('in').hide();
93+
$('div.webui-popover').not('.webui-popover-fixed').removeClass('in').hide();
9094
},
9195
/*core method ,show popover */
9296
show:function(){
@@ -111,6 +115,7 @@
111115
$target.show();
112116
}
113117
this.displayContent();
118+
this.bindBodyEvents();
114119
},
115120
displayContent:function(){
116121
var
@@ -247,6 +252,12 @@
247252
}
248253
});
249254
},
255+
256+
bindBodyEvents:function(){
257+
$('body').off('keyup.webui-popover').on('keyup.webui-popover',$.proxy(this.escapeHandler,this));
258+
$('body').off('click.webui-popover').on('click.webui-popover',$.proxy(this.bodyClickHandler,this));
259+
},
260+
250261
/* event handlers */
251262
mouseenterHandler:function(){
252263
var self = this;
@@ -262,10 +273,16 @@
262273
},
263274
escapeHandler:function(e){
264275
if (e.keyCode===27){
265-
this.hide();
266276
this.hideAll();
267277
}
268278
},
279+
bodyClickHandler:function(){
280+
this.hideAll();
281+
},
282+
283+
targetClickHandler:function(e){
284+
e.stopPropagation();
285+
},
269286

270287
//reset and init the target events;
271288
initTargetEvents:function(){
@@ -275,6 +292,7 @@
275292
.on('mouseleave',$.proxy(this.mouseleaveHandler,this));
276293
}
277294
this.$target.find('.close').off('click').on('click', $.proxy(this.hide,this));
295+
this.$target.off('click.webui-popover').on('click.webui-popover',$.proxy(this.targetClickHandler,this));
278296
},
279297
/* utils methods */
280298
//caculate placement of the popover
@@ -345,7 +363,6 @@
345363
arrowSize = this.options.arrow?28:0,
346364
fixedW = elementW<arrowSize+10?arrowSize:0,
347365
fixedH = elementH<arrowSize+10?arrowSize:0;
348-
console.log(elementW,arrowSize);
349366
switch (placement) {
350367
case 'bottom':
351368
position = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - targetWidth / 2};

dist/jquery.webui-popover.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)