Skip to content

Commit

Permalink
fix the hiden bug,update the version to 1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sandywalker committed Nov 18, 2015
1 parent f012a96 commit 7ad027b
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 43 deletions.
8 changes: 8 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

# History

### 1.2.3
* fix the bug which cause the popover hide by click when multi popovers in same page.
* optimize event handling for performance

### 1.2.2
*
* optimize code and clean debug info

### 1.2.1
* now option url can be set with jQuery selector (eg: '#myContent') when type equals 'html'.
* fix the bug which cause the popover content lost event handler.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webui-popover",
"version": "1.2.2",
"version": "1.2.3",
"authors": [
"sandywalker <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion demo/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ <h2 >Input hints</h2>
<a href="#" class="show-pop-backdrop btn btn-default " data-placement="auto">pop with
backdrop</a>
<a href="#" class="show-pop-dropdown btn btn-default " data-placement="auto">pop with bs-dropdown</a>
<div class="webui-popover">
<div class="webui-popover-content">
<ul class="dropdown-menu" >
<li><a href="#">Action</a></li>
<li><a href="#">Another Option</a></li>
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ <h2 >Input hints</h2>
<a href="#" class="show-pop-backdrop btn btn-default " data-placement="auto">pop with backdrop</a>

<a href="#" class="show-pop-dropdown btn btn-default " data-placement="auto">pop with bs-dropdown</a>
<div class="webui-popover">
<div class="webui-popover-content">
<ul class="dropdown-menu" >
<li><a href="#">Action</a></li>
<li><a href="#">Another Option</a></li>
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.webui-popover.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* webui popover plugin - v1.2.1
* webui popover plugin - v1.2.2
* 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!
* https://github.com/sandywalker/webui-popover
*
Expand Down
58 changes: 40 additions & 18 deletions dist/jquery.webui-popover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* webui popover plugin - v1.2.1
* webui popover plugin - v1.2.2
* 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!
* https://github.com/sandywalker/webui-popover
*
Expand Down Expand Up @@ -58,7 +58,7 @@
};


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

var getPopFromElement = function($element) {
return $element.data('plugin_' + pluginName);
};

var hideAllPop = function() {
for (var i = 0; i < _srcElements.length; i++) {
_srcElements[i].webuiPopover('hide');
}
$document.trigger('hiddenAll.' + pluginType);
};




// The actual plugin constructor
Expand All @@ -87,7 +99,7 @@
this._name = pluginName;
this._targetclick = false;
this.init();
popovers.push(this.$element);
_srcElements.push(this.$element);
}

WebuiPopover.prototype = {
Expand Down Expand Up @@ -119,14 +131,14 @@
destroy: function() {
var index = -1;

for (var i = 0; i < popovers.length; i++) {
if (popovers[i] === this.$element) {
for (var i = 0; i < _srcElements.length; i++) {
if (_srcElements[i] === this.$element) {
index = i;
break;
}
}

popovers.splice(index, 1);
_srcElements.splice(index, 1);


this.hide();
Expand Down Expand Up @@ -203,11 +215,7 @@
this[this.getTarget().hasClass('in') ? 'hide' : 'show']();
},
hideAll: function() {
for (var i = 0; i < popovers.length; i++) {
popovers[i].webuiPopover('hide');
}

$document.trigger('hiddenAll.' + pluginType);
hideAllPop();
},
/*core method ,show popover */
show: function() {
Expand Down Expand Up @@ -552,20 +560,34 @@
this.hideAll();
}
},
bodyClickHandler: function() {

bodyClickHandler: function(e) {
_isBodyEventHandled = true;
if (this.getTrigger() === 'click') {
if (this._targetclick) {
this._targetclick = false;
} else {
this.hideAll();
var canHide = true;
for (var i = 0; i < _srcElements.length; i++) {
var pop = getPopFromElement(_srcElements[i]);
if (pop._opened) {
var popX1 = pop.getTarget().offset().left;
var popY1 = pop.getTarget().offset().top;
var popX2 = pop.getTarget().offset().left + pop.getTarget().width();
var popY2 = pop.getTarget().offset().top + pop.getTarget().height();
var inPop = e.pageX >= popX1 && e.pageX <= popX2 && e.pageY >= popY1 && e.pageY <= popY2;
if (inPop) {
canHide = false;
break;
}
}
}
if (canHide) {
hideAllPop();
}
},

/*
targetClickHandler: function() {
this._targetclick = true;
},
*/

//reset and init the target events;
initTargetEvents: function() {
Expand All @@ -576,7 +598,7 @@
.on('mouseleave', $.proxy(this.mouseleaveHandler, this));
}
this.$target.find('.close').off('click').on('click', $.proxy(this.hide, this, true));
this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
//this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
},
/* utils methods */
//caculate placement of the popover
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.webui-popover.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A enhancement popover plugin for Bootstrap ,but you can use it stand-alone without Bootstrap!",
"author": "Sandy Duan <[email protected]>",
"homepage": "https://github.com/sandywalker/webui-popover",
"version": "1.2.2",
"version": "1.2.3",
"license":"MIT",
"devDependencies": {
"grunt": "~0.4.1",
Expand Down
56 changes: 39 additions & 17 deletions src/jquery.webui-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
};


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

var getPopFromElement = function($element) {
return $element.data('plugin_' + pluginName);
};

var hideAllPop = function() {
for (var i = 0; i < _srcElements.length; i++) {
_srcElements[i].webuiPopover('hide');
}
$document.trigger('hiddenAll.' + pluginType);
};




// The actual plugin constructor
Expand All @@ -79,7 +91,7 @@
this._name = pluginName;
this._targetclick = false;
this.init();
popovers.push(this.$element);
_srcElements.push(this.$element);
}

WebuiPopover.prototype = {
Expand Down Expand Up @@ -111,14 +123,14 @@
destroy: function() {
var index = -1;

for (var i = 0; i < popovers.length; i++) {
if (popovers[i] === this.$element) {
for (var i = 0; i < _srcElements.length; i++) {
if (_srcElements[i] === this.$element) {
index = i;
break;
}
}

popovers.splice(index, 1);
_srcElements.splice(index, 1);


this.hide();
Expand Down Expand Up @@ -195,11 +207,7 @@
this[this.getTarget().hasClass('in') ? 'hide' : 'show']();
},
hideAll: function() {
for (var i = 0; i < popovers.length; i++) {
popovers[i].webuiPopover('hide');
}

$document.trigger('hiddenAll.' + pluginType);
hideAllPop();
},
/*core method ,show popover */
show: function() {
Expand Down Expand Up @@ -544,20 +552,34 @@
this.hideAll();
}
},
bodyClickHandler: function() {

bodyClickHandler: function(e) {
_isBodyEventHandled = true;
if (this.getTrigger() === 'click') {
if (this._targetclick) {
this._targetclick = false;
} else {
this.hideAll();
var canHide = true;
for (var i = 0; i < _srcElements.length; i++) {
var pop = getPopFromElement(_srcElements[i]);
if (pop._opened) {
var popX1 = pop.getTarget().offset().left;
var popY1 = pop.getTarget().offset().top;
var popX2 = pop.getTarget().offset().left + pop.getTarget().width();
var popY2 = pop.getTarget().offset().top + pop.getTarget().height();
var inPop = e.pageX >= popX1 && e.pageX <= popX2 && e.pageY >= popY1 && e.pageY <= popY2;
if (inPop) {
canHide = false;
break;
}
}
}
if (canHide) {
hideAllPop();
}
},

/*
targetClickHandler: function() {
this._targetclick = true;
},
*/

//reset and init the target events;
initTargetEvents: function() {
Expand All @@ -568,7 +590,7 @@
.on('mouseleave', $.proxy(this.mouseleaveHandler, this));
}
this.$target.find('.close').off('click').on('click', $.proxy(this.hide, this, true));
this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
//this.$target.off('click.webui-popover').on('click.webui-popover', $.proxy(this.targetClickHandler, this));
},
/* utils methods */
//caculate placement of the popover
Expand Down
2 changes: 1 addition & 1 deletion webui-popover.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"webui",
"pop"
],
"version":"1.2.2",
"version":"1.2.3",
"author": {
"name": "Sandy Duan",
"email": "[email protected]",
Expand Down

0 comments on commit 7ad027b

Please sign in to comment.