I have the following problem:
In my application every link has a tooltip (from bootstrap-ui). If the link is clicked, a alert dialog appears and the tooltip disappears. But in firefox the tooltip is still shown!
Here is a plunker:
plunkr
And thats how I want to use it with tooltip:
<a tooltip="do something" tooltip-popup-delay="300" tooltip-placement="bottom" ng-click="doSomething()">do Something</a>
the function:
$scope.doSomething = function()
{
alert("do Something");
}
After the alert window is confirmed, the tooltip is still shown in firefox.
Can someone help me, how to hide this tooltip in firefox? This is really stupid!
Thank you!
You can manually hide your tooltips by using jQuery like this:
jQuery('.tooltip').hide();
This will hide all instances of the tooltip. In your case, you could call this right after your alert like so:
$scope.doSomething = function()
{
alert("do Something");
jQuery('.tooltip').hide();
}
Make sure you add the jQuery library if you go with this approach.
Related
I have a calendar element on my ionic app. When user swipe left or right on it, it goes to a different month. One problem/challenge is that when I swipe to the right the side bar is showing.
I did use drag-content="false" and that disabled the swipe menu function everywhere but I want it only on that calendar element.
I found this Stackoverflow post with a answer but I did not understand how it worked because I can't find any difference between the content elements. In that post they also included a codepen link to an answer CODEPEN
UPDATE:
Here a link to the calendar plugin
Maybe you could bind drag-content directive to a scope variable (boolean) and then change its value when mouse is over the calendar component:
<ion-side-menu-content drag-content="drag">
So register the listeners for mouseover/mouseleave events on calendar:
<flex-calendar on-touch="mouseoverCalendar()" on-release="mouseleaveCalendar()" drag-content="toggledrag" options="options" events="events"></flex-calendar>
and insert in your controller:
$scope.drag = true;
$scope.mouseoverCalendar = function() {
$scope.drag = false;
};
$scope.mouseleaveCalendar = function() {
$scope.drag = true;
};
Here is an example using Flex Calendar: http://codepen.io/beaver71/pen/bEmaJZ
Put this into the controller of your calendar-view and it will the menu as you enter the calendar and re-enable it as you leave the view:
$scope.$on('$ionicView.enter', function(){
$ionicSideMenuDelegate.canDragContent(false);
});
$scope.$on('$ionicView.leave', function(){
$ionicSideMenuDelegate.canDragContent(true);
});
Answer from this post
This is the link of the the example I am talking about.
Go to the link
https://angular-ui.github.io/bootstrap/
then check the datepicker example in plunker.
If we look in the code, I don't see any magic code there to do the closing part.
All I see is
$scope.open = function($event) {
$scope.status.opened = true;
};
which only opens the calendar.
My questions is how does it close on a click event that is outside of the calendar. This is a pretty good feature that I want to have on my other directives too.
---------------------Temp Solution----------------
Since no1 have provided an answer yet. For any1 who wants to know how to do this. I have a temp solution for you guys.
1. Add ng-click on the outter most tag.
2. Add ng-mouseleave and ng-mouseenter event on your custom tag.
Here is the flow:
When user mouse out/in of your custom tag. You set a flag to true/false.
Then when user clicks, close the div when mouse is outside the custom tag (You will use the flag to check ).
I found it myself.
It is because of the following code.
var documentClickBind = function(event) {
if (scope.isOpen && event.target !== element[0]) {
scope.$apply(function() {
scope.isOpen = false;
});
}
};
Can you please tell me how to get click event of button? Actually button click event does not fire.
Here is plunker
http://plnkr.co/edit/cqmwJc5dpoDWvai4xeNX?p=preview
var loginCntrl=function($scope){
$scope.testClick =function(){
alert('sss');
}
}
You are making a simple mistake by not including ng-controller. Change it as follows. It will work.
<div ng-app="firstApp" ng-controller="loginCntrl">
<ui-view name="test"></ui-view>
When I click a button, it appears a popover which can be closed if you click the button inside the popover. However, if you click another button to open a popover, you will see two popovers at the same time and I want to keep just one.
I have tried with the trigger 'focus', but it closes the popover if I click in the textarea inside the popover, I expected that this trigger was called when you click outside of the popover.
Any idea for this? Can the methods $hide, $show be called from the controller?
Try to add ng-click="$hide()" on the dismissable element of the popover. I.E.:
<a class="btn btn-primary" ng-click="$hide()">Close</a>
It's not included in the documentation but it works for me, iff you use data-template for popover content, haven't tried with other opened popover yet.
This should be an old question, in latest version of angular-strap, a new attribute could be used in this case:
auto-close='1'
OK, I am pretty sure this is a terrible hack, but here goes. Assuming your popover templates all use the popover class (if you aren't using a custom template with the data-template attribute, they should), and they're siblings of the button that triggers them (if you haven't mucked with the container attribute, they are), you can apply the following directive to your popover buttons. Note: this assumes that the parent elements of your popovers and popover buttons have unique ids.
angular.module('yourApp.directives', []).directive('rmPopovers',
function($document,$rootScope,$timeout,$popover) {
return {
restrict: 'EA',
link : function(scope, element, attrs) {
var $element = $(element);
$element.click(function() {
$('.popover').each(function(){
var $this = $(this);
if($this.parent().attr('id') != $element.parent().attr('id'))
{
$this.scope().$hide();
}
}
);
});
}
}
}
);
And then
<button type="button" bs-popover rm-popovers [your data attribs here]>Button!</button
There is an issue in the angular-strap github project which asks exactly the feature you want.
Nevertheless, at the moment I'm writing this answer, it's still open.
trigger : 'focus' ,
worked for me on the same issue
I've been looking around and trying out different things but can't figure it out. Is it possible to hide an angular-ui tooltip with a certain event?
What I want to do is to show a tooltip when someone hovers over a div and close it when a users clicks on it because I will show another popup. I tried it with custom trigger events but can't seem to get it working. I made this:
<div ng-app="someApp" ng-controller="MainCtrl" class="likes" tooltip="show favorites" tooltip-trigger="{{{true: 'mouseenter', false: 'hideonclick'}[showTooltip]}}" ng-click="doSomething()">{{likes}}</div>
var app = angular.module('someApp', ['ui.bootstrap']);
app.config(['$tooltipProvider', function($tooltipProvider){
$tooltipProvider.setTriggers({
'mouseenter': 'mouseleave',
'click': 'click',
'focus': 'blur',
'hideonclick': 'click'
});
}]);
app.controller('MainCtrl', function ($scope) {
$scope.showTooltip = true;
$scope.likes = 999;
$scope.doSomething = function(){
//hide the tooltip
$scope.showTooltip = false;
};
})
http://jsfiddle.net/3ywMd/
The tooltip has to close on first click and not the 2nd. Any idea how to close the tooltip if user clicks on div?
I tried #shidhin-cr's suggestion of setting $scope.tt_isOpen = false but it had the rather significant issue that, while the tooltip does fade out, it is still present in the DOM (and handling pointer events!). So even though they can't see it, the tooltip can prevent users from interacting with content that was previously behind the tooltip.
A better way that I found was to simply trigger the event used as tooltip-trigger on the tooltip target. So, for example, if you've got a button that's a tooltip target, and triggers on click...
<button id="myButton"
tooltip="hi"
tooltip-trigger="click">
</button>
Then in your JavaScript, at any point, you can trigger the 'click' event to dismiss your tooltip. Make sure that the tooltip is actually open before you trigger the event.
// ... meanwhile, in JavaScript land, in your custom event handler...
if (angular.element('#myButton').scope().tt_isOpen) {
angular.element('#myButton').trigger('click');
}
Since this triggers the actual internals of AngularUI's Tooltip directive, you don't have the nasty side-effects of the previous solution.
Basically you cannot play with the tooltip-trigger to make this work. After digging through the ToolTip directive code, I found that the ToolTip attribute exposes a scope attribute called tt_isOpen.
So in your ng-click function, if you set this attribute to false, that will make the tooltip hide.
See the updated demo here
http://jsfiddle.net/3ywMd/10/
Like this
app.controller('MainCtrl', function ($scope) {
$scope.likes = 999;
$scope.doSomething = function(){
//hide the tooltip
$scope.tt_isOpen = false;
};
})
Michael's solution got me 90% of the way there but when I executed the code, angular responded with "$digest already in progress". I simply wrapped the trigger in a timeout. Probably not the best solution, but required minimal code
// ... meanwhile, in JavaScript land, in your custom event handler...
if (angular.element('#myButton').scope().tt_isOpen) {
$timeout( function(){
angular.element('#myButton').trigger('click');
}, 100);
}
For future reference, the accepted answer angular.element('.yourTooltip').scope().tt_isOpen will not work in new versions as tooltip has been made unobservable. Therefore, the entire tootlip is removed from DOM. Simple solution is to just check if tooltip is present in DOM or not.
Borrowing from #liteflier's answer,
// ... meanwhile, in JavaScript land, in your custom event handler...
if (angular.element('.yourTooltip').length) { //if element is present in DOM
setTimeout( function(){
//Trigger click on tooltip container
angular.element('.yourTooltipParent').trigger('click');
}, 100);
}