From 71a6f3d53961a3dd3164613cdb515321addc9b87 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Mar 2014 13:32:48 -0300 Subject: This fixes issue #3 --- bower.json | 2 +- example/index.css | 6 +++--- example/index.html | 1 - example/nsPopover.js | 23 ++++++++++++++++++++--- package.json | 2 +- src/nsPopover.js | 23 ++++++++++++++++++++--- 6 files changed, 45 insertions(+), 12 deletions(-) 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 @@ - \ 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('
'); var $triangle; var placement_; var align_; + globalId += 1; + + var $popover = $el('
'); + $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..b3c9ab5 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 { @@ -54,11 +56,15 @@ $container = $document.find('body'); } - var $popover = $el('
'); var $triangle; var placement_; var align_; + globalId += 1; + + var $popover = $el('
'); + $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; } -- cgit v1.2.3 From c101e6b7b939822f29e237e60bf0a2896d5c3831 Mon Sep 17 00:00:00 2001 From: Ben Paddock Date: Mon, 21 Apr 2014 20:30:46 +0100 Subject: Add hide-on-click option (defaults to true) --- README.md | 4 ++++ src/nsPopover.js | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6179ed6..ce385d7 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,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/src/nsPopover.js b/src/nsPopover.js index b3c9ab5..96a1652 100644 --- a/src/nsPopover.js +++ b/src/nsPopover.js @@ -19,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_ = { @@ -140,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 -- cgit v1.2.3