CSS riddle, can't figure how to modify piece of code - javascript

http://fiddle.jshell.net/ycc7anhy/1/show/
Here is live code. Its CSS dialog box.
Problem is, its beign show by:
Modal!
By a href element, and I can't figure out how to change it to for example javascript onclick or any other method (couple would be appreciated).
Probably this css have to do smth with it:
.modal:target:before {
display: block;
}
.modal:target {
position: absolute;
top: 0;
}

First, your HTML code should look like this
<a onclick="toggle-modal('#mymodal')" > OPEN MODAL </a>
<div Id="mymodal" > your modal content </div>
By default, your modal is hidden ( display none, or opacity 0) . Then with a JavaScript function you show the modal.
I prefer use JQuery with JavaScript but you can do it with pure JavaScript.
Function toggle-modal(modalID){
$('#mymodal').classList.toggle('active'); }
The CSS class active displays the modal ( display:block ) or set its opacity to 1.

Related

Why is IE ignoring width, height on inline link tag?

Pre-req:
<a href="#a"
onClick="MyWindow=window.open(\'https://<Server IP>/ClickHereNotes.html#<Div Name AAA>\',\'MyWindow\',width=600, height=300); return false;">Click Here.</a>
By clicking on the link above, the embedded html page is opened but only the target div name AAA is displayed.
Below is the toggle like function I have used in the html script tag:
div {
display: none;
}
div:target {
display: block;
}
Problem: When the link above is clicked in Chrome it opens a popup window, while displaying the whole div html content
When I try to open the link in IE 11, the pop up window appears but the window size does not wrap around the html content of the div in concern. There is also no scroll bar.
Things I have tried so far, but did not work:
Adding scrollbar=yes
Adding min-height
Adding % in width and height.
removing width and height.
Adding a char after href=#.
What property should I use to display the pop up window with complete div HTML content?
Try this instead
add this attribute Overflow:scroll to your div
You are trying to show a new page with bookmark .
which is possible by Just create CONTENT Will come on top when url with #BookMark1 will
but still another content will show while scrolling .
to make hide this u need to code for java script.
remove
div { display: none; }
div:target { display: block; }
and add:
html, body{ overflow: auto; }
and add
scrollbar=yes
in tag

color, insert link and insert image popup not showing in wysihtml5

Hey every one I have following issues color, insert link and insert image popup not showing in wysihtml5. when i check the inspect element the div insert image button after update and in inspect element
<div class="bootstrap-wysihtml5-insert-image-modal modal fade in" style="display: none;">
and this is automatically add when i click the button style="display: none;"
this have modal class and modal class inherit from bootstrap. modal class have two properties
overflow: 'hidden';
display : none;
when i remove this property from inspect element popup is showing other wise popup not showing what should i do please help me..
The overflow: 'hidden'; part is wrong. Also remove display: none; as it is already done programmatically. Finally your code should be:
overflow: hidden;
The reason that the modal does not show is because display: none will make it invisible. overflow: hidden may also hide the content if the width and height of the modal are now set accordingly.
To show the modal you should apply display: block or something similar to it.
Try replacing this..
overflow: hidden;
and remove the display:none

How to highlight bootstrap modal with intro.js

I have a button, once I click on that button bootstrap modal will appear and then intro.js should highlight that modal. This is my requirement. But it's not working like that.
Once I click on that button modal is appearing but intro.js is not highlighting, if I press F12 it's highlighting.
This is the code I've written:
var introInstance=introJs();
introInstance.onbeforechange(function(targetObj) {
switch(targetElementIndex){
case 1:
$('#productPlanDiv').modal();
break;
};
});
How can I fix this? Thanks.
The answer here and the answer #Victor gave could help you to solve this problem. But these two answers didn't solve my problem so I merged them.
But there are several issues for these answer to mention that I think is important;
As #Victor mentioned, introJs and DOM have to use same div. But you should use assing introJs to modal div only when you actually want to show modal. Let's think you have 4 steps and and 3rd and 4th steps show your modal's elements as follow:
HTML code:
<html>
<style>
.modal {
z-index: 999999997 !important;
}
.modal .introjs-fixedTooltip {
z-index: 99999998 !important; /*I give less value to this one. The other way introJs always blocks my modals*/
}
.modal .introjs-showElement {
z-index: 999999999 !important;
}
</style>
<body>
<div id="some-div" data-step="1" data-intro="Let's do this!">
<p>some meaningful workk</p>
</div>
<div id="some-other-div" data-step="2" data-intro="You can do it!">
<p>this is very important text</p>
</div>
<div id="yourmodal" class="modal fade" role="dialog" aria-hidden="true">ü
<form id="valuable-info" data-step="3" data-intro="use here to give info">
important labels, textboxs, lists etc...
<button id="click-here" data-step="4" data-intro="click here to click">
click
<button>
</form>
</div>
<button id="introJs-button">IntroJS</button>
</body>
JS code:
$('#introJs-button').on('click', function() {
var intro = introJs();
intro.onchange(function (targetElement){
if (targetElement.attributes["data-step"].value === "3" && targetElement.attributes["data-step"].value === "4") {
var closestContainer = $(targetElement).closest('div.modal').prop('id');
$('.introjs-overlay, .introjs-helperLayer, .introjs-tooltipReferenceLayer, .introjs-fixedTooltip').appendTo('#' + closestContainer);
}
else {
$('.introjs-overlay, .introjs-helperLayer, .introjs-tooltipReferenceLayer, .introjs-fixedTooltip').appendTo('body');
}
});
})
Like I tried to show in my JavaScript code, you should only append introJs to modal when your data-steps are defined at your modal's div. The other way, introJs will always tries to append itself to the closest container and when find nothing, it will cause error/bugs.
The other important thing I encounter is when you give your modal a high z-index value you should also give your modal's item such as select2-dropdownlist higher z-index value. Or you should reset modal's z-index value. Some of the items in select2-dropdownlist like select2-search__field, select2-results__options etc. will not understand what z-index value you give to modal. And because their z-index value will be lower than the modal itself these items never be shown on modal. My suggestion is resetting modal z-index value to prevent this.
Since all JavaScript plugins in bootstrap require jQuery you can use an event listener to trigger it automatically when the modal is shown:
$('#my-modal').on('shown', function(){
introJs().start();
});
None of the solutions on the web have fixed the problem for me.
But I came up with this solution:
/*fix interactions with modal BS3, take this on CSS file*/
.modal { z-index:999999997 !important; }
.modal .introjs-fixedTooltip { z-index: 999999998 !important; }
.modal .introjs-showElement { z-index: 999999999 !important; }
//Use this class and make sure that the modal has an ID
//introJs-Bs3-modal
//The introJs have a problem with DOM positioning and reading. It is mandatory for DIVs to work within the same element as modal.
$('.introJs-Bs3-modal').on('click', function() {
var containerClosest = $(this).closest('div.modal').prop('id');
setTimeout(function(){
$('.introjs-overlay, .introjs-helperLayer, .introjs-tooltipReferenceLayer').appendTo('#'+containerClosest);
}, 0);
});

Apply new CSS rules when on click of <a> element

I'm currently trying to design and develop my own lightweight lightbox. The idea is when someone clicks <a href="#tab1"> it will change the properties of the <div id="tab1"> from display: none to display: block. Once the lightbox pops up it will have another link like <a href="#tab1_close"> to reverse the CSS properties back to display: none.
I've used input[name='name'] ~ #id for a lot of other sections on my site, I'm wondering if it's possible to change it so the input recognizes the <a> as the input and applies the CSS changes on the click.
Ideally, I could add id="tab_1" to the <a>, then the code would be something like a#tab_1:active ~ #tab1 { display: block } but that code doesn't seem to do anything.
Here's my Code Pen
If you want CSS only try the :target selector:
#tab1:target {
display: block;
}
http://codepen.io/anon/pen/okEqr
jQuery's toggleClass() will dow hat you want: https://api.jquery.com/toggleClass/

How to resize Twitter Bootstrap modal dynamically based on the content

I have database content which has different types of data, such as Youtube videos, Vimeo videos, text, Imgur pictures, etc. All of them have different heights and widths. All I have found while searching the Internet is changing the size to only one parameter. It has to be same as the content in the popup.
This is my HTML code. I also use Ajax to call the content.
<div id="modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="ModalLabel"></h3>
</div>
<div class="modal-body">
</div>
</div>
This worked for me, none of the above worked.
.modal-dialog{
position: relative;
display: table; /* This is important */
overflow-y: auto;
overflow-x: auto;
width: auto;
min-width: 300px;
}
Since your content must be dynamic you can set the css properties of the modal dynamically on show event of the modal which will re-size the modal overriding its default specs. Reason being bootstrap applies a max-height to the modal body with the css rule as below:
.modal-body {
position: relative;
overflow-y: auto;
max-height: 400px;
padding: 15px;
}
So you can add inline styles dynamically using jquery css method:
For newer versions of bootstrap use show.bs.modal
$('#modal').on('show.bs.modal', function () {
$(this).find('.modal-body').css({
width:'auto', //probably not needed
height:'auto', //probably not needed
'max-height':'100%'
});
});
For older versions of bootstrap use show
$('#modal').on('show', function () {
$(this).find('.modal-body').css({
width:'auto', //probably not needed
height:'auto', //probably not needed
'max-height':'100%'
});
});
or use a css rule to override:
.autoModal.modal .modal-body{
max-height: 100%;
}
and add this class autoModal to your target modals.
Change the content dynamically in the fiddle, you will see the modal getting resized accordingly. Demo
Newer version of bootstrap see the available event names.
show.bs.modal This event fires immediately when the show instance method is called. If caused by a click, the clicked element is available as the relatedTarget property of the event.
shown.bs.modal This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the relatedTarget property of the event.
hide.bs.modal This event is fired immediately when the hide instance method has been called.
hidden.bs.modal This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).
loaded.bs.modal This event is fired when the modal has loaded content using the remote option.
Older version of bootstrap modal events supported.
Show - This event fires immediately when the show instance method is called.
shown - This event is fired when the modal has been made visible to the user (will wait for css transitions to complete).
hide - This event is fired immediately when the hide instance method has been called.
hidden - This event is fired when the modal has finished being hidden from the user (will wait for css transitions to complete).
I couldn't get PSL's answer working for me so I found all I have to do is set the div holding the modal content with style="display: table;". The modal content itself says how big it wants to be and the modal accommodates it.
There are many ways to do this if you want to write css then add following
.modal-dialog{
display: table
}
In case if you want to add inline
<div class="modal-dialog" style="display:table;">
//enter code here
</div>
Don't add display:table; to modal-content class. it done your job but disposition your modal for large size see following screenshots.
first image is if you add style to modal-dialog
if you add style to modal-content. it looks dispositioned.
for bootstrap 3 use like
$('#myModal').on('hidden.bs.modal', function () {
// do something…
})
Simple Css work for me
.modal-dialog {
max-width : 100% ;
}
I simply override the css:
.modal-dialog {
max-width: 1000px;
}
set width:fit-content on the modal div.
You can do that if you use jquery dialog plugin from gijgo.com and set the width to auto.
$("#dialog").dialog({
uiLibrary: 'bootstrap',
width: 'auto'
});
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<link href="http://code.gijgo.com/1.0.0/css/gijgo.css" rel="stylesheet" type="text/css">
<script src="http://code.gijgo.com/1.0.0/js/gijgo.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="dialog" title="Wikipedia">
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1122px-Wikipedia-logo-v2.svg.png" width="320"/>
</div>
</body>
</html>
You can also allow the users to control the size if you set resizable to true. You can see a demo about this at http://gijgo.com/Dialog/Demos/bootstrap-modal-resizable
A simple CSS solution that will vertically and horizontally center the modal:
.modal.show {
display: flex !important;
justify-content: center;
}
.modal-dialog {
align-self: center;
}
For Bootstrap 2 Auto adjust model height dynamically
//Auto adjust modal height on open
$('#modal').on('shown',function(){
var offset = 0;
$(this).find('.modal-body').attr('style','max-height:'+($(window).height()-offset)+'px !important;');
});
I had the same problem with bootstrap 3 and the modal-body div's height not wanting to be greater than 442px. This was all the css needed to fix it in my case:
.modal-body {
overflow-y: auto;
}
Mine Solution was just to add below style.
<div class="modal-body" style="clear: both;overflow: hidden;">
As of Bootstrap 4 - it has a style of:
#media (min-width: 576px)
.modal-dialog {
max-width: 500px;
}
so if you are looking to resize the modal width to some-width larger, I would suggest using this in your css for example:
.modal-dialog { max-width: 87vw; }
Note that setting width: 87vw; will not override bootstrap's max-width: 500px;.
My search led me here so might as well add my two cents worth of idea. If you are using Monkey friendly Twitter Bootstrap modal then you can do something like this:
var dialog = new BootstrapDialog({
id: 'myDialog',
title: 'Title',
closable: false,
// whatever you like configuration here...
});
dialog.realize();
if (isContentAYoutubeVideo()) {
dialog.getModalDialog().css('width', '80%'); // set the width to whatever you like
}
dialog.open();
Hope this helps.
If you only want your modal box to resize when the content overflow, otherwise keep original size.
Use
<div class="modal-dialog" style="display:grid;">
instead of
<div class="modal-dialog" style="display:table;">

Categories