aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeylor Ohmaly2014-04-21 20:26:02 -0300
committerNeylor Ohmaly2014-04-21 20:26:02 -0300
commit9c198f813302a481001ad8f28379ded53dafb058 (patch)
tree128fdaa3feab250dfe00c7685118b3aa725d192b
parentdf33f037a0353da75cc34695b91ab16dc5c5da81 (diff)
parentc1755b785708ba023c484e305d05c28c5640115a (diff)
downloadnsPopover-9c198f813302a481001ad8f28379ded53dafb058.tar.bz2
Merge branch 'master' of https://github.com/nohros/nsPopover
-rw-r--r--README.md4
-rw-r--r--bower.json2
-rw-r--r--example/index.css6
-rw-r--r--example/index.html1
-rw-r--r--example/nsPopover.js23
-rw-r--r--package.json2
-rw-r--r--src/nsPopover.js36
7 files changed, 57 insertions, 17 deletions
diff --git a/README.md b/README.md
index 77da997..46e9ed7 100644
--- a/README.md
+++ b/README.md
@@ -123,6 +123,10 @@ the possible combinations of [position] and [alignment].
* right|bottom - The popover will be positioned on the right side of the triggering element and its bottom will be
aligned with the bottom of the triggering element.
+### ``ns-popover-hide-on-click {Boolean}``
+
+Whether or not to hide the popover when it is clicked on, default: ``true``.
+
### Themes
diff --git a/bower.json b/bower.json
index 55c91de..31d3f01 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "nsPopover",
- "version": "0.5.7",
+ "version": "0.5.8",
"homepage": "https://github.com/nohros/nsPopover",
"description": "Popover for angularjs library",
"authors": [
diff --git a/example/index.css b/example/index.css
index d641f03..58add65 100644
--- a/example/index.css
+++ b/example/index.css
@@ -37,11 +37,11 @@ body > section {
article {
position: relative;
margin: 0 auto;
- float: left;
}
-article:after {
- clear: both;
+article + h1 {
+ clear: left;
+ display: block;
}
h1 {
diff --git a/example/index.html b/example/index.html
index 28ff4fe..034f630 100644
--- a/example/index.html
+++ b/example/index.html
@@ -77,6 +77,5 @@
</a>
</article>
</section>
-
</body>
</html> \ No newline at end of file
diff --git a/example/nsPopover.js b/example/nsPopover.js
index 505fbba..b3c9ab5 100644
--- a/example/nsPopover.js
+++ b/example/nsPopover.js
@@ -5,6 +5,8 @@
var $el = angular.element;
var isDef = angular.isDefined;
var forEach = angular.forEach;
+ var $popovers = [];
+ var globalId = 0;
module.directive('nsPopover', function($timeout, $templateCache, $q, $http, $compile, $document) {
return {
@@ -54,11 +56,15 @@
$container = $document.find('body');
}
- var $popover = $el('<div></div>');
var $triangle;
var placement_;
var align_;
+ globalId += 1;
+
+ var $popover = $el('<div id="nspopover-' + globalId +'"></div>');
+ $popovers.push($popover);
+
var match = options.placement
.match(/^(top|bottom|left|right)$|((top|bottom)\|(center|left|right)+)|((left|right)\|(center|top|bottom)+)/);
@@ -222,8 +228,19 @@
var x = (isDef(w.pageXOffset)) ? w.pageXOffset : doc.scrollLeft;
var y = (isDef(w.pageYOffset)) ? w.pageYOffset : doc.scrollTop;
var rect = elm.getBoundingClientRect();
- rect.top += y;
- rect.left += x;
+
+ // ClientRect class is immutable, so we need to return a modified copy
+ // of it when the window has been scrolled.
+ if (x || y) {
+ return {
+ bottom:rect.bottom+y,
+ left:rect.left + x,
+ right:rect.right + x,
+ top:rect.top + y,
+ height:rect.height,
+ width:rect.width
+ };
+ }
return rect;
}
diff --git a/package.json b/package.json
index fa49190..5459cbe 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"author": "Neylor Ohmaly",
"name": "nsPopover",
- "version": "0.5.7",
+ "version": "0.5.8",
"homepage": "http://nohros.com/nsPopover",
"licenses": {
"type": "MIT",
diff --git a/src/nsPopover.js b/src/nsPopover.js
index 505fbba..96a1652 100644
--- a/src/nsPopover.js
+++ b/src/nsPopover.js
@@ -5,6 +5,8 @@
var $el = angular.element;
var isDef = angular.isDefined;
var forEach = angular.forEach;
+ var $popovers = [];
+ var globalId = 0;
module.directive('nsPopover', function($timeout, $templateCache, $q, $http, $compile, $document) {
return {
@@ -17,7 +19,8 @@
trigger: attrs.nsPopoverTrigger || 'click',
container: attrs.nsPopoverContainer,
placement: attrs.nsPopoverPlacement || 'bottom|left',
- timeout: attrs.nsPopoverTimeout || 1.5
+ timeout: attrs.nsPopoverTimeout || 1.5,
+ hideOnClick: attrs.nsPopoverHideOnClick === 'true' || attrs.nsPopoverHideOnClick === undefined
};
var hider_ = {
@@ -54,11 +57,15 @@
$container = $document.find('body');
}
- var $popover = $el('<div></div>');
var $triangle;
var placement_;
var align_;
+ globalId += 1;
+
+ var $popover = $el('<div id="nspopover-' + globalId +'"></div>');
+ $popovers.push($popover);
+
var match = options.placement
.match(/^(top|bottom|left|right)$|((top|bottom)\|(center|left|right)+)|((left|right)\|(center|top|bottom)+)/);
@@ -134,10 +141,12 @@
// |elm|.
move($popover, placement_, align_, getBoundingClientRect(elm[0]), $triangle);
- // Hide the popover without delay on click events.
- $popover.on('click', function() {
- hider_.hide($popover, 0);
- });
+ if (options.hideOnClick) {
+ // Hide the popover without delay on click events.
+ $popover.on('click', function () {
+ hider_.hide($popover, 0);
+ });
+ }
});
elm
@@ -222,8 +231,19 @@
var x = (isDef(w.pageXOffset)) ? w.pageXOffset : doc.scrollLeft;
var y = (isDef(w.pageYOffset)) ? w.pageYOffset : doc.scrollTop;
var rect = elm.getBoundingClientRect();
- rect.top += y;
- rect.left += x;
+
+ // ClientRect class is immutable, so we need to return a modified copy
+ // of it when the window has been scrolled.
+ if (x || y) {
+ return {
+ bottom:rect.bottom+y,
+ left:rect.left + x,
+ right:rect.right + x,
+ top:rect.top + y,
+ height:rect.height,
+ width:rect.width
+ };
+ }
return rect;
}