Making the popup from bootstrap stay within the screen - javascript

I am creating popups with popover bootstrap option in creating an interactive html. I first used the following tag:
<a class="btn popoverOption"
data-content="A group of people with a shared characteristic. It is an object of observation in epidemiological studies."
data-original-title="cohort"
data-placement="bottom"
href="#"
rel="popover"
style="font-size: inherit; vertical-align: baseline; padding: 0; font: inherit;">
cohort
</a>
I have purposely made spces to show the syntax. The popup is below the text, so I tried adding data-container='body', but in this way when I zoom in the popup is frequently outside the screen. How can I make the popup always stay within my screen (without fixing the size in any way, if possible)?
Thanks in advance! Please tel me if I need to show more code, I didn't do it for brevity.

Related

Button not directing to the email in react-app

I am building a react app. In that i have a button, i want if someone clicks on that one then it takes him to compose email. But it is not working. This is but i tried to do
<button className="btn_2" > <a href="mailto:my_email#gmail.com" > Say Hello </a> </button>
I just checked and the code is working fine. But one thing I observed is you have to click on the anchor text (a tag) and not the other part of button. To avoid this you can remove button as a wrapper element, use a tag and style it using css.
a{
display: inline-block;
padding:.5rem;
background: lightgrey;
border-radius: 5px;
}
<a href="mailto:my_email#gmail.com" > Say Hello </a>
It doesn't work because is not valid HTML5 according to the spec.
The a element can be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g., buttons or other links).
You probably should replace with:
<a className="btn_2" href="mailto:my_email#gmail.com"> Say Hello </a>

Making a JS toggle div close when another is opened, and change image on click

I am new to JavaScript. Currently, I am working on a small toggle for my website.
The goal is to have three buttons that open up different sections with information. I have this working on my website. Now, what I want to achieve is to make other divs close when the others are opened up. Furthermore, I would like the first div to be open when the page is loaded, including an indicator (for example orange image) on the button. Can you please help me with this?
For some reason, the script works on my website, but not on the JSfiddle:
https://jsfiddle.net/q7evaLsn/1/
Current code:
$('.button1').click(function(){
$('.product').slideToggle('slow');
});
$('.button2').click(function(){
$('.lockedin').slideToggle('slow');
});
$('.button3').click(function(){
$('.developers').slideToggle('slow');
});
.button2
{
padding-top: 10px;
}
.button3
{
padding-top: 15px;
}
<h3>
<img src="http://www.mindaffect.nl/wp-content/uploads/2017/12/product-holder.png" class="button1" alt="Expand"/>
</h3>
<h3>
<img src="http://www.mindaffect.nl/wp-content/uploads/2017/12/lockedin-holder.png" class="button2" alt="Expand"/>
</h3>
<h3>
<img src="http://www.mindaffect.nl/wp-content/uploads/2017/12/developers-holder.png" class="button3" alt="Expand"/>
</h3>
<div class="product">
Testdiv1
</div>
<div class="lockedin">
Testdiv2
</div>
<div class="developers">
Testdiv3
</div>
Your help is greatly appreciated!
You can simply slide up everything before you start toggling.
For ex
$('.button3').click(function(){
$('.product').slideUp();
$('.lockedin').slideUp();
$('.developers').slideToggle('slow');
});
Your JSfiddle isn't working because you haven't included the jQuery library required for some of your functions. For future reference, jQuery is a popular javascript library which simplifies and extends some basic javascript functions, you can use both interchangeably however if you do want the extra features of jQuery then you'll have to include it like so in your HTML:
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
As mentioned by #SURESH you'll likely want to slide the other areas up where you are toggling the target area:
$('.example-button').click(function(){
$('.section-to-hide-1').slideUp();
$('.section-to-hide-2').slideUp();
$('.section-to-toggle-1').slideToggle();
});
Just as further formatting advice, you have your images (that are acting as buttons) within header tags.
It's generally bad practice to use these header tags for anything
other than headings/titles
I'd recommend using A tags or even BUTTON tags to do the same job
I'd try not to use IMG tags as essentially text buttons, you will be able to style a button similarly like so:
<button class="button1">Products</button>
<style>
.button1 { text-align: center; padding: 10px; text-transform: uppercase: border-radius: 100%; border: 3px solid orange; background: white; color: #000; }
</style>
This will allow search engines/screen readers to read your button element, and you can make hover effects etc.

Tooltip not coming on bottom

I made a navbar and there is a green button. When the cursor hovers on it, I want a tooltip (at the bottom) to appear. However that is not happening. I used the following script:
$("[data-toggle="tooltip"]").tooltip();
A very strange thing happens. The tooltip is getting hidden underneath the navbar. Or so it seems. Can anybody help me with this? The following is the HTML code for the button (it is enclosed within the header tag):
<a id="ID" style="margin-right: 20px" class="btn btn-success"
data-placement="bottom" data-toggle="tooltip" href="#"
data-original-title="Tooltip on bottom">Has hover state</a>
Fix your JavaScript quotes:
$("a[data-toggle='tooltip']").tooltip();
See this Plunker as reference, it has your markup and the fixed JavaScript.
Note that the .tooltip() is running after the DOM is ready with the relevant markup.
EDIT: After a long discussion in the comments, the solution was to add this to the CSS:
.tooltip{ position: fixed;}

How to ignore anchor if button is clicked within the anchor element

I have a situation where clicking on an image will direct the user to a certain link, but pressing a button that is shown within an image will run a javascript method instead. However, I cannot prevent the page from redirecting to the certain link when the button is pressed (the javascript method is also run when the button is clicked).
I have found out that button cannot be nested within an anchor element, and tried to wrap the button within a form as well, but no luck.
Does anyone know a way around such problem?
the basic logic in code looks like this
<a href="an item description link">
<img src="an item image"/>
<form style="display: inline" action="html_form_action.asp" method="get">
<button type="button" id="add-btn" class="add-cart" onclick="quick_add()">+</button>
</form>
</a>
Thanks in advance for any help!
A straightforward way that validates would be just superimposing the button over the link. This requires the link and the button to be in the same containing element, and for both of them to use position: absolute:
HTML
<div class="box">
<a href="http://example.com">
<img src="http://placehold.it/300x200">
</a>
<button>AAAAA</button>
</div>
CSS
.box {
box-sizing: content-box;
width: 300px;
height: 200px;
border: thin solid black;
}
.box > a {
display: block;
position: absolute;
}
.box > button {
position: absolute;
}
See it in action on CodePen: http://codepen.io/millimoose/pen/avYLjQ
The button will automatically be stacked over the preceding link. (This is specified behaviour.) And it will handle clicks before they can be passed to elements underneath is.
That said, this solution has a few downsides. You'll have to give a fixed size to the container; it can't be sized automatically to fit its contents, because its contents are outside of the rendering flow. This also means they won't automatically fill their parent box unless you set their size explicitly again.

how to use Colorbox popup without disabling the parent screen

I have been asked to look after a web application. The previous developer has used colorbox to display popup window. When the popup is open it disables the parent screen.
Is it possible to have another popup in the same page using colorbox which will not disable the parent screen. i.e click in the parent window without closing the colorbox window.
The web app is built with asp.net and vb.net.
Its a online portal for employers. The code for opening the colorbox popup is given below.
<span class="pull-right">
<a class="hover-glow colorbox"
data-placement="bottom" rel="tooltip"
title="view cv"
data-bind="attr: { 'href': 'cv-preview.aspx?c=' + CvId }">
<i class=" icon icon-file "></i></a>
<a class="hover-glow"
data-placement="bottom" rel="tooltip"
title="change status"
data-bind="attr: { 'href': 'update-status_popup.aspx?i=' + Id + '&c=' + StatusId }">
<i class="icon icon-random"></i></a>
</span>
currently the 1st link which uses colorbox (view cv) opens candidates cv in a popup window. and the 2nd link (change status) opens in another page to change candidates application status.
the requirement is to open the the 2nd link in similar type of popup but without disabling the parent screen. the user wants to work on both screen at the same time.
i don't want to use ajax.
i would appreciate any help and suggestion.
the css for the color box has been given below
#cboxOverlay,#cboxWrapper,#colorbox{position:absolute;top:0;left:0;z-index:9999;overflow:hidden}
#cboxOverlay{position:fixed;width:100%;height:100%}
#cboxBottomLeft,#cboxMiddleLeft{clear:left}
#cboxContent{position:relative}
#cboxLoadedContent{overflow:auto}
#cboxTitle{margin:0}
#cboxLoadingGraphic,#cboxLoadingOverlay{position:absolute;top:0;left:0;width:100%}
#cboxClose,#cboxNext,#cboxPrevious,#cboxSlideshow{cursor:pointer}
.cboxPhoto{float:left;margin:auto;border:0;display:block}
.cboxIframe{width:100%;height:100%;display:block;border:0}
#cboxOverlay{background:#777}
#cboxContent{margin-top:20px}
#cboxError{padding:50px;border:1px solid #ccc}
#cboxLoadedContent{background:#fff}
#cboxTitle{position:absolute;top:-20px;left:0;color:#ccc}
#cboxCurrent{position:absolute;top:-20px;right:0;color:#ccc;display:none!important}
#cboxSlideshow{position:absolute;top:-20px;right:90px;color:#fff}
#cboxPrevious{position:absolute;top:50%;left:5px;margin-top:-32px;background:url(../images/controls.png) no-repeat top left;width:28px;height:65px;text-indent:-9999px;display:none!important}
#cboxPrevious.hover{background-position:bottom left}
#cboxNext{position:absolute;top:50%;right:5px;margin-top:-32px;background:url(../images/controls.png) no-repeat top right;width:28px;height:65px;text-indent:-9999px;display:none!important}
#cboxNext.hover{background-position:bottom right}
#cboxLoadingOverlay{background:#000}
#cboxLoadingGraphic{background:url(../images/loading.gif) no-repeat center center}
#cboxClose{position:absolute;top:5px;right:5px;display:block;background:url(../images/controls.png) no-repeat top center;width:38px;height:19px;text-indent:-9999px;z-index:-1}
#cboxClose.hover{background-position:bottom center}
#newPriv,#newTerm{display:none}
#exPriv,#exTerm{padding:10px;border:1px solid #dedede}
if it is not possible to have two different popup with color box, please suggest an alternate way.
Thanks
The answer to this question is yes. To see proof of this, just visit the Colorbox Examples page: http://www.jacklmoore.com/colorbox/example1/
To understand how to implement this functionality, refer to the Colorbox documentation and the Colorbox beginners guide:
http://www.jacklmoore.com/colorbox/
http://www.jacklmoore.com/colorbox/guide/

Categories