Skip to content

Commit 7ad027b

Browse files
committed
fix the hiden bug,update the version to 1.2.3
1 parent f012a96 commit 7ad027b

File tree

10 files changed

+95
-43
lines changed

10 files changed

+95
-43
lines changed

HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
# History
55

6+
### 1.2.3
7+
* fix the bug which cause the popover hide by click when multi popovers in same page.
8+
* optimize event handling for performance
9+
10+
### 1.2.2
11+
*
12+
* optimize code and clean debug info
13+
614
### 1.2.1
715
* now option url can be set with jQuery selector (eg: '#myContent') when type equals 'html'.
816
* fix the bug which cause the popover content lost event handler.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webui-popover",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"authors": [
55
"sandywalker <sanddywalker@gmail.com>"
66
],

demo/index-dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ <h2 >Input hints</h2>
347347
<a href="#" class="show-pop-backdrop btn btn-default " data-placement="auto">pop with
348348
backdrop</a>
349349
<a href="#" class="show-pop-dropdown btn btn-default " data-placement="auto">pop with bs-dropdown</a>
350-
<div class="webui-popover">
350+
<div class="webui-popover-content">
351351
<ul class="dropdown-menu" >
352352
<li><a href="#">Action</a></li>
353353
<li><a href="#">Another Option</a></li>

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ <h2 >Input hints</h2>
348348
<a href="#" class="show-pop-backdrop btn btn-default " data-placement="auto">pop with backdrop</a>
349349

350350
<a href="#" class="show-pop-dropdown btn btn-default " data-placement="auto">pop with bs-dropdown</a>
351-
<div class="webui-popover">
351+
<div class="webui-popover-content">
352352
<ul class="dropdown-menu" >
353353
<li><a href="#">Action</a></li>
354354
<li><a href="#">Another Option</a></li>

dist/jquery.webui-popover.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* webui popover plugin - v1.2.1
2+
* webui popover plugin - v1.2.2
33
* A lightWeight popover plugin with jquery ,enchance the popover plugin of bootstrap with some awesome new features. It works well with bootstrap ,but bootstrap is not necessary!
44
* https://github.com/sandywalker/webui-popover
55
*

dist/jquery.webui-popover.js

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* webui popover plugin - v1.2.1
2+
* webui popover plugin - v1.2.2
33
* A lightWeight popover plugin with jquery ,enchance the popover plugin of bootstrap with some awesome new features. It works well with bootstrap ,but bootstrap is not necessary!
44
* https://github.com/sandywalker/webui-popover
55
*
@@ -58,7 +58,7 @@
5858
};
5959

6060

61-
var popovers = [];
61+
var _srcElements = [];
6262
var backdrop = $('<div class="webui-popover-backdrop"></div>');
6363
var _globalIdSeed = 0;
6464
var _isBodyEventHandled = false;
@@ -69,6 +69,18 @@
6969
return isNaN(numeric) ? (fallback || 0) : Number(numeric);
7070
};
7171

72+
var getPopFromElement = function($element) {
73+
return $element.data('plugin_' + pluginName);
74+
};
75+
76+
var hideAllPop = function() {
77+
for (var i = 0; i < _srcElements.length; i++) {
78+
_srcElements[i].webuiPopover('hide');
79+
}
80+
$document.trigger('hiddenAll.' + pluginType);
81+
};
82+
83+
7284

7385

7486
// The actual plugin constructor
@@ -87,7 +99,7 @@
8799
this._name = pluginName;
88100
this._targetclick = false;
89101
this.init();
90-
popovers.push(this.$element);
102+
_srcElements.push(this.$element);
91103
}
92104

93105
WebuiPopover.prototype = {
@@ -119,14 +131,14 @@
119131
destroy: function() {
120132
var index = -1;
121133

122-
for (var i = 0; i < popovers.length; i++) {
123-
if (popovers[i] === this.$element) {
134+
for (var i = 0; i < _srcElements.length; i++) {
135+
if (_srcElements[i] === this.$element) {
124136
index = i;
125137
break;
126138
}
127139
}
128140

129-
popovers.splice(index, 1);
141+
_srcElements.splice(index, 1);
130142

131143

132144
this.hide();
@@ -203,11 +215,7 @@
203215
this[this.getTarget().hasClass('in') ? 'hide' : 'show']();
204216
},
205217
hideAll: function() {
206-
for (var i = 0; i < popovers.length; i++) {
207-
popovers[i].webuiPopover('hide');
208-
}
209-
210-
$document.trigger('hiddenAll.' + pluginType);
218+
hideAllPop();
211219
},
212220
/*core method ,show popover */
213221
show: function() {
@@ -552,20 +560,34 @@
552560
this.hideAll();
553561
}
554562
},
555-
bodyClickHandler: function() {
563+
564+
bodyClickHandler: function(e) {
556565
_isBodyEventHandled = true;
557-
if (this.getTrigger() === 'click') {
558-
if (this._targetclick) {
559-
this._targetclick = false;
560-
} else {
561-
this.hideAll();
566+
var canHide = true;
567+
for (var i = 0; i < _srcElements.length; i++) {
568+
var pop = getPopFromElement(_srcElements[i]);
569+
if (pop._opened) {
570+
var popX1 = pop.getTarget().offset().left;
571+
var popY1 = pop.getTarget().offset().top;
572+
var popX2 = pop.getTarget().offset().left + pop.getTarget().width();
573+
var popY2 = pop.getTarget().offset().top + pop.getTarget().height();
574+
var inPop = e.pageX >= popX1 && e.pageX <= popX2 && e.pageY >= popY1 && e.pageY <= popY2;
575+
if (inPop) {
576+
canHide = false;
577+
break;
578+
}
562579
}
563580
}
581+
if (canHide) {
582+
hideAllPop();
583+
}
564584
},
565585

586+
/*
566587
targetClickHandler: function() {
567588
this._targetclick = true;
568589
},
590+
*/
569591

570592
//reset and init the target events;
571593
initTargetEvents: function() {
@@ -576,7 +598,7 @@
576598
.on('mouseleave', $.proxy(this.mouseleaveHandler, this));
577599
}
578600
this.$target.find('.close').off('click').on('click', $.proxy(this.hide, this, true));
579-
this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
601+
//this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
580602
},
581603
/* utils methods */
582604
//caculate placement of the popover

dist/jquery.webui-popover.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A enhancement popover plugin for Bootstrap ,but you can use it stand-alone without Bootstrap!",
55
"author": "Sandy Duan <sanddywalker@gmail.com>",
66
"homepage": "https://github.com/sandywalker/webui-popover",
7-
"version": "1.2.2",
7+
"version": "1.2.3",
88
"license":"MIT",
99
"devDependencies": {
1010
"grunt": "~0.4.1",

src/jquery.webui-popover.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
};
5151

5252

53-
var popovers = [];
53+
var _srcElements = [];
5454
var backdrop = $('<div class="webui-popover-backdrop"></div>');
5555
var _globalIdSeed = 0;
5656
var _isBodyEventHandled = false;
@@ -61,6 +61,18 @@
6161
return isNaN(numeric) ? (fallback || 0) : Number(numeric);
6262
};
6363

64+
var getPopFromElement = function($element) {
65+
return $element.data('plugin_' + pluginName);
66+
};
67+
68+
var hideAllPop = function() {
69+
for (var i = 0; i < _srcElements.length; i++) {
70+
_srcElements[i].webuiPopover('hide');
71+
}
72+
$document.trigger('hiddenAll.' + pluginType);
73+
};
74+
75+
6476

6577

6678
// The actual plugin constructor
@@ -79,7 +91,7 @@
7991
this._name = pluginName;
8092
this._targetclick = false;
8193
this.init();
82-
popovers.push(this.$element);
94+
_srcElements.push(this.$element);
8395
}
8496

8597
WebuiPopover.prototype = {
@@ -111,14 +123,14 @@
111123
destroy: function() {
112124
var index = -1;
113125

114-
for (var i = 0; i < popovers.length; i++) {
115-
if (popovers[i] === this.$element) {
126+
for (var i = 0; i < _srcElements.length; i++) {
127+
if (_srcElements[i] === this.$element) {
116128
index = i;
117129
break;
118130
}
119131
}
120132

121-
popovers.splice(index, 1);
133+
_srcElements.splice(index, 1);
122134

123135

124136
this.hide();
@@ -195,11 +207,7 @@
195207
this[this.getTarget().hasClass('in') ? 'hide' : 'show']();
196208
},
197209
hideAll: function() {
198-
for (var i = 0; i < popovers.length; i++) {
199-
popovers[i].webuiPopover('hide');
200-
}
201-
202-
$document.trigger('hiddenAll.' + pluginType);
210+
hideAllPop();
203211
},
204212
/*core method ,show popover */
205213
show: function() {
@@ -544,20 +552,34 @@
544552
this.hideAll();
545553
}
546554
},
547-
bodyClickHandler: function() {
555+
556+
bodyClickHandler: function(e) {
548557
_isBodyEventHandled = true;
549-
if (this.getTrigger() === 'click') {
550-
if (this._targetclick) {
551-
this._targetclick = false;
552-
} else {
553-
this.hideAll();
558+
var canHide = true;
559+
for (var i = 0; i < _srcElements.length; i++) {
560+
var pop = getPopFromElement(_srcElements[i]);
561+
if (pop._opened) {
562+
var popX1 = pop.getTarget().offset().left;
563+
var popY1 = pop.getTarget().offset().top;
564+
var popX2 = pop.getTarget().offset().left + pop.getTarget().width();
565+
var popY2 = pop.getTarget().offset().top + pop.getTarget().height();
566+
var inPop = e.pageX >= popX1 && e.pageX <= popX2 && e.pageY >= popY1 && e.pageY <= popY2;
567+
if (inPop) {
568+
canHide = false;
569+
break;
570+
}
554571
}
555572
}
573+
if (canHide) {
574+
hideAllPop();
575+
}
556576
},
557577

578+
/*
558579
targetClickHandler: function() {
559580
this._targetclick = true;
560581
},
582+
*/
561583

562584
//reset and init the target events;
563585
initTargetEvents: function() {
@@ -568,7 +590,7 @@
568590
.on('mouseleave', $.proxy(this.mouseleaveHandler, this));
569591
}
570592
this.$target.find('.close').off('click').on('click', $.proxy(this.hide, this, true));
571-
this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
593+
//this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
572594
},
573595
/* utils methods */
574596
//caculate placement of the popover

webui-popover.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"webui",
99
"pop"
1010
],
11-
"version":"1.2.2",
11+
"version":"1.2.3",
1212
"author": {
1313
"name": "Sandy Duan",
1414
"email": "sanddywalker@gmail.com",

0 commit comments

Comments
 (0)