Skip to content

Commit

Permalink
Added a new configuration option to allow the specification of the de…
Browse files Browse the repository at this point in the history
…lay used to close the popover.
  • Loading branch information
nohros committed Feb 26, 2014
1 parent f62db56 commit 96838f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nsPopover",
"version": "0.5.5",
"version": "0.5.6",
"homepage": "https://github.com/nohros/nsPopover",
"description": "Popover for angularjs library",
"authors": [
Expand Down
3 changes: 2 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ <h1> Menus </h1>
<button ns-popover
ns-popover-template="menu"
ns-popover-trigger="click"
ns-popover-theme="ns-popover-list-theme">
ns-popover-theme="ns-popover-list-theme"
ns-popover-timeout="5">
Click me
</button>

Expand Down
33 changes: 7 additions & 26 deletions example/nsPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@
var isDef = angular.isDefined;
var forEach = angular.forEach;

/**
* Extends the destination objec 'dst' by copying all of the properties from the 'src' object(s)
* to 'dst'. Multiple src objects could be specified. 'undefined' values are not copied.
*
* @param {Object} dst The destination object.
* @param {Object} src The spurce object.
* @returns {Object} Reference to 'dst'.
*/
var extend_ = function extend(dst, src) {
forEach(arguments, function(obj) {
if (obj !== src) {
forEach(obj, function(value, key) {
if (isDef(value)) {
dst[key] = value;
}
});
}
});
};

module.directive('nsPopover', function($timeout, $templateCache, $q, $http, $compile, $document) {
return {
restrict: 'A',
Expand All @@ -36,7 +16,8 @@
plain: attrs.nsPopoverPlain,
trigger: attrs.nsPopoverTrigger || 'click',
container: attrs.nsPopoverContainer,
placement: attrs.nsPopoverPlacement || 'bottom|left'
placement: attrs.nsPopoverPlacement || 'bottom|left',
timeout: attrs.nsPopoverTimeout || 1.5
};

var hider_ = {
Expand All @@ -46,7 +27,7 @@
* Set the display property of the popover to 'none' after |delay| milliseconds.
*
* @param popover {Object} The popover to set the display property.
* @param delay {Number} The time (in milliseconds) to wait before set the display property.
* @param delay {Number} The time (in seconds) to wait before set the display property.
* @returns {Object|promise} A promise returned from the $timeout service that can be used
* to cancel the hiding operation.
*/
Expand All @@ -55,12 +36,12 @@

// delay the hiding operation for 1.5s by default.
if (!isDef(delay)) {
delay = 1500;
delay = 1.5;
}

hider_.id_ = $timeout(function() {
popover.css('display', 'none');
}, delay);
}, delay*1000);
},

cancel: function() {
Expand Down Expand Up @@ -160,12 +141,12 @@
});

elm.on('mouseout', function() {
hider_.hide($popover);
hider_.hide($popover, options.timeout);
});

$popover
.on('mouseout', function(e) {
hider_.hide($popover);
hider_.hide($popover, options.timeout);
})
.on('mouseover', function() {
hider_.cancel();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Neylor Ohmaly",
"name": "nsPopover",
"version": "0.5.5",
"version": "0.5.6",
"homepage": "http://nohros.com/nsPopover",
"licenses": {
"type": "MIT",
Expand Down
33 changes: 7 additions & 26 deletions src/nsPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@
var isDef = angular.isDefined;
var forEach = angular.forEach;

/**
* Extends the destination objec 'dst' by copying all of the properties from the 'src' object(s)
* to 'dst'. Multiple src objects could be specified. 'undefined' values are not copied.
*
* @param {Object} dst The destination object.
* @param {Object} src The spurce object.
* @returns {Object} Reference to 'dst'.
*/
var extend_ = function extend(dst, src) {
forEach(arguments, function(obj) {
if (obj !== src) {
forEach(obj, function(value, key) {
if (isDef(value)) {
dst[key] = value;
}
});
}
});
};

module.directive('nsPopover', function($timeout, $templateCache, $q, $http, $compile, $document) {
return {
restrict: 'A',
Expand All @@ -36,7 +16,8 @@
plain: attrs.nsPopoverPlain,
trigger: attrs.nsPopoverTrigger || 'click',
container: attrs.nsPopoverContainer,
placement: attrs.nsPopoverPlacement || 'bottom|left'
placement: attrs.nsPopoverPlacement || 'bottom|left',
timeout: attrs.nsPopoverTimeout || 1.5
};

var hider_ = {
Expand All @@ -46,7 +27,7 @@
* Set the display property of the popover to 'none' after |delay| milliseconds.
*
* @param popover {Object} The popover to set the display property.
* @param delay {Number} The time (in milliseconds) to wait before set the display property.
* @param delay {Number} The time (in seconds) to wait before set the display property.
* @returns {Object|promise} A promise returned from the $timeout service that can be used
* to cancel the hiding operation.
*/
Expand All @@ -55,12 +36,12 @@

// delay the hiding operation for 1.5s by default.
if (!isDef(delay)) {
delay = 1500;
delay = 1.5;
}

hider_.id_ = $timeout(function() {
popover.css('display', 'none');
}, delay);
}, delay*1000);
},

cancel: function() {
Expand Down Expand Up @@ -160,12 +141,12 @@
});

elm.on('mouseout', function() {
hider_.hide($popover);
hider_.hide($popover, options.timeout);
});

$popover
.on('mouseout', function(e) {
hider_.hide($popover);
hider_.hide($popover, options.timeout);
})
.on('mouseover', function() {
hider_.cancel();
Expand Down

0 comments on commit 96838f8

Please sign in to comment.