Custom style to jQuery UI dialogs - css

I am trying to change jQuery UI dialog's default styles to something similar to this -
I got it to close changing some CSS in jQuery UI.
.ui-widget {
font-family: Verdana,Arial,sans-serif;
font-size: .8em;
}
.ui-widget-content {
background: #F9F9F9;
border: 1px solid #90d93f;
color: #222222;
}
.ui-dialog {
left: 0;
outline: 0 none;
padding: 0 !important;
position: absolute;
top: 0;
}
#success {
padding: 0;
margin: 0;
}
.ui-dialog .ui-dialog-content {
background: none repeat scroll 0 0 transparent;
border: 0 none;
overflow: auto;
position: relative;
padding: 0 !important;
}
.ui-widget-header {
background: #b0de78;
border: 0;
color: #fff;
font-weight: normal;
}
.ui-dialog .ui-dialog-titlebar {
padding: 0.1em .5em;
position: relative;
font-size: 1em;
}
HTML :
<div id="popup-msg">
<div id="loading">
<h2>Loading...</h2>
<h3>Please wait a few seconds.</h3>
</div>
<div id="success" title="Hurray,">
<p>User table is updated.</p>
</div>
</div>
THIS IS FIDDLE
But when I add this style its apply to all my dialogs. Can anybody tell me how can I avoid from this problem.
Thank you.

See https://jsfiddle.net/qP8DY/24/
You can add a class (such as "success-dialog" in my example) to div#success, either directly in your HTML, or in your JavaScript by adding to the dialogClass option, as I've done.
$('#success').dialog({
height: 50,
width: 350,
modal: true,
resizable: true,
dialogClass: 'no-close success-dialog'
});
Then just add the success-dialog class to your CSS rules as appropriate. To indicate an element with two (or more) classes applied to it, just write them all together, with no spaces in between. For example:
.ui-dialog.success-dialog {
font-family: Verdana,Arial,sans-serif;
font-size: .8em;
}

You can specify a custom class to the top element of the dialog via the option dialogClass
$("#success").dialog({
...
dialogClass:"myClass",
...
});
Then you can target this class in CSS via .myClass.ui-dialog.

The solution only solves part of the problem, it may let you style the container and contents but doesn't let you change the titlebar. I developed a workaround of sorts but adding an id to the dialog div, then using jQuery .prev to change the style of the div which is the previous sibling of the dialog's div. This works because when jQueryUI creates the dialog, your original div becomes a sibling of the new container, but the title div is a the immediately previous sibling to your original div but neither the container not the title div has an id to simplify selecting the div.
HTML
<button id="dialog1" class="btn btn-danger">Warning</button>
<div title="Nothing here, really" id="nonmodal1">
Nothing here
</div>
You can use CSS to style the main section of the dialog but not the title
.custom-ui-widget-header-warning {
background: #EBCCCC;
font-size: 1em;
}
You need some JS to style the title
$(function() {
$("#nonmodal1").dialog({
minWidth: 400,
minHeight: 'auto',
autoOpen: false,
dialogClass: 'custom-ui-widget-header-warning',
position: {
my: 'center',
at: 'left'
}
});
$("#dialog1").click(function() {
if ($("#nonmodal1").dialog("isOpen") === true) {
$("#nonmodal1").dialog("close");
} else {
$("#nonmodal1").dialog("open").prev().css('background','#D9534F');
}
});
});
The example only shows simple styling (background) but you can make it as complex as you wish.
You can see it in action here:
https://codepen.io/chris-hore/pen/OVMPay

Related

How to auto animate element every time when it changes position on the screen?

I have vue project.
Every time some elements on the page disappear because of v-if the rest of the page is slightly rearranged. I want it to happen smoothly.
All elements have :key attribute.
Example:
I have centred 2 boxes in one row. When one is gone, the second one is still centred, so changes position.
image
How to handle this?
EDIT 1
I tried:
<div>
<CompoentA :key=345 class="one-line" v-show="showComponentA" />
<transition name="moving">
<CompoentB class="one-line" :key=123 />
</transition>
</div>
.one-line { display: inline-table; }
.moving-move { transition: transform 1s; }
v-if will remove the element from the DOM, so you can't animate your disappearing components.
You should use v-show instead if you want to animate them (they will stay hidden in the DOM).
I think that you need "from" and "to" values to create this animation. When you remove the elemnt from DOM, the other elements will be placed based on a "inline" position, so there is no value reference to create a transition.
There is a similar problem here, where a transition with height:0 and height: auto
How can I transition height: 0; to height: auto; using CSS?
I made a sample to solve this using a width (bigger than content) and width 0 with opacity 0 to hide the inner content. To run this sample, simple click in items, it will be "removed" (opacity:0 and width: 0) and the transition works because there is a initial width set (80px).
new Vue({
el: "#app",
data: () => ({
// yes, there is better ways, but let make this sample "simple"
letters: ['a', 'b', 'c', 'd'],
visible: {
a: true,
b: true,
c: true,
d: true,
}
})
})
#app {
/* decoration, you can remove */
width: 100%;
text-align: center;
background-color: #f4f4f4;
}
.moving {
/* margin and padding 0
because the width content will be set to 0
if this element has a margin, when removed the margin still display the "space"
*/
padding: 0;
margin: 0;
font-size: 0; /* remove white space in DOM element */
display: inline-block;
opacity: 1;
transition: width linear .2s;
/* decoration, you can remove */
width: 80px;
border: 1px dotted #ccc;
cursor: pointer;
}
.moving-content {
font-size: 18px; /* restore font size */
display: inline-block;
/* decoration, you can remove */
background-color: #2af;
color: white;
padding: 20px;
box-sizing: border-box;
}
.moving.hidden {
width: 0px;
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div v-for="letter in letters"
:key="letter"
:class="{ moving: true, hidden: !visible[letter] }" #click="visible[letter] = false">
<span class="moving-content">
{{ letter }}
</span>
</div>
</div>
References:
https://stackoverflow.com/a/40785144/1724128
https://stackoverflow.com/a/53127208/1724128

How to get value text to follow slider input?

I've created a Slider in react.
It looks like this:
import styles from '../Slider.scss';
type Props = {|
maxValue: Number,
minValue: Number,
onChange: Function,
step?: Number,
value: Number
|};
const SliderInput = (props: Props) => {
const ratio = (props.value - props.minValue) / (props.maxValue - props.minValue);
return (
<div className={styles[`slider-container`]}>
<div className={styles.labels}>
<span>${props.minValue}</span>
<span>${props.maxValue}</span>
</div>
<div>
<input
className={styles.slider}
max={props.maxValue}
min={props.minValue}
onChange={props.onChange}
step={props.step}
type="range"
value={props.value}
/>
<div className={styles[`slider-value`]}>
<span>${props.value}</span>
</div>
</div>
</div>
);
};
The styles look like this:
.slider-container {
width: 100%;
}
.slider {
-webkit-appearance: none;
background: transparent;
width: 100%;
height: 25px;
background-image: linear-gradient(to right, #F5F5F5, #A5D8F5);
outline: none;
}
.slider-value {
/* Not sure what goes here yet */
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 30px;
height: 30px;
background: black;
cursor: pointer;
}
.labels {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
What I'm trying to accomplish:
I want the value of the slider to show up right above or below the current position of the slider input. I'm thinking I'll have to give the slider-value a position: absolute, but I'm not sure what to do beyond that.
First we add position relative to .slider-value and we need to match the width of the input[type=range] because we gonna move the span along it using the left property.
.slider-value {
position: relative;
/* it's for because left moves the element relative to it's left not the middle */
width:calc(100% - 30px);
}
.slider-value>span {
position: absolute;
text-align: center;
/* must match the thumb width */
width: 30px;
}
im not going to go over how you update the value, im just going to tell you how to use it,
so we gonna assign the value of the slider to the left property of the span,
should be getting updated and passed as props to the slider something like:
<span style={{left:this.props.value+"%"}} >{this.props.value}</span>
this would work fine the minValue equals 0 and the maxValue equals 100, however this won't be the only case, so we map the value.
The map function should look like this, i just copied from the p5.js lib
map(n, start1, stop1, start2, stop2) {
return ((n-start1)/(stop1-start1))*(stop2-start2)+start2;
}
The span then should look like this
<span style={{this.map(this.props.value,this.props.minValue,this.props.maxValue,0,100)+"%"}} >{this.props.value}</span>
And if you have any question, please don't hesitate, i know i'm good at explaining. :)
EDIT
Live Demo
Code

Images won't display when src defined in External CSS - All Browsers

I'm working on a project for a client that involved using the existing code they have while also transitioning the files into another location. The files being transitioned include images that can't be moved yet, so in an attempt to make the code future proof, I used CSS to define the image src's by embedding them in the "a" tag.
.iconWriting::before { content:url("http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/V3/courseFramework/images/icons/writing_standards_resources.png");
}
iconWriting {
width: 32px;
height: 32px;
margin: 1px;
border: none;
float: right;
}
<a class="iconWriting" href="http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/V3/courseFramework/StartHere/V3_Start_Here-Writing.htm" target="_blank"></a>
Unfortunately, the images will only display correctly when the CSS style defining their location is in the Head of the document. I need to be able to house these styles in an External CSS file, but when I move the previously working CSS to the External file, it breaks. Instead of images, I just get the alt text, in all browsers. I tried adding ":before" to the class specification, but this didn't work, either.
Here's a Fiddle of the working code: JS Fiddle
Thanks to #Mr Lister for his help with this; the solution is to target the "a" tag when specifying the image src using the "content" property.
/*Weekly Activity Styles*/
.activityWrapper {
width: 96%;
overflow-x: hidden;"
}
/*Upper Right Icons*/
.iconExpand::before {
content:url("http://wpc.6FDC.edgecastcdn.net/006FDC/V2/icon/sm_expand.png");
}
.iconAcademic::before {
content:url("http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/V3/courseFramework/images/icons/academic_research_policy.png");
}
.iconWriting::before {
content:url("http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/V3/courseFramework/images/icons/writing_standards_resources.png");
}
.iconExpand, .iconAcademic, .iconWriting {
width: 32px;
height: 32px;
margin: 1px;
border: none;
float: right;
}
/*Dropbox & Waypoint Icons*/
.iconDropbox {
content:url("http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/images/Dropbox_small.png");
border: none;
}
.iconWaypoint {
content:url("http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/images/waypoint_smaller.png");
border: none;
}
.iconWaypointLg {
content:url("http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/images/Waypoint_image1.png");
border: none;
}
padding: 15px 20px 5px 15px;
}
}
<div class="activityWrapper">
<div class="subParaDisc">
<a target="_new" href="javascript://;" class="iconLink iconExpand" onclick="this.href=document.location"></a>
<a class="iconAcademic" target="_new" href="http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/V3/courseFramework/StartHere/V3_Start_Here-Academic.htm"></a>
<a class="iconWriting" href="http://wpc.6FDC.edgecastcdn.net/006FDC/UOR_Curriculum/V3/courseFramework/StartHere/V3_Start_Here-Writing.htm" target="_blank"></a>
<h1>
The Icons above only work when the style defining their img content is in the head of the HTML doc.</h1>
</div>
</div>
Reference this Fiddle for the sample: https://jsfiddle.net/1gxmqnjy/21/

HTML Color selector input

I was working on an HTML form today and needed to create a color selector when I discovered (on accident) that input type 'color' actually creates a color selector in chrome (as well as firefox
http://caniuse.com/#feat=input-color).
<input type="color" value="#333" />
Are there any examples of using the color input type with gracefully fail over to other selectors?
Also it would be nice to show the hex value generated. In chrome it just shows a button box with the background of the selected color.
Is there a way to style an HTML color input to show the selected color's hex value?
Here is what I ended up using:
$("input.color").each(function() {
var that = this;
$(this).parent().prepend($("<i class='fa fa-paint-brush color-icon'></i>").click(function() {
that.type = (that.type == "color") ? "text" : "color";
}));
}).change(function() {
$(this).attr("data-value", this.value);
this.type = "text";
});
label {
font-family: sans-serif;
width: 300px;
display: block;
position: relative;
}
input {
padding: 5px 15px;
font-size: 16px;
width: 100%;
box-sizing: border-box;
}
input[type=color] {
padding: 0;
border: 0;
height: 40px;
}
input[type=color]:after {
content: attr(data-value);
position: absolute;
bottom: 10px;
text-align: center;
color: #fffff5;
display: block;
width: 100%;
}
.color-icon {
position: absolute;
bottom: 10px;
right: 10px;
color: #666;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>
Color:
<br />
<input class="color" placeholder="#XXXXXX" data-value="#xxxxxx" />
</label>
Are there any examples of using the color input type with gracefully fail over to other selectors?
You could find ways to gracefully fallback to another color picker if color input is not available. For example, https://github.com/bgrins/spectrum. (Try searching for "input color polyfill" for other options).
Is there a way to style an HTML color input to show the selected color's hex value?
For my Chrome (45.0.2454.93), it does show the hex value in the color selector while selecting. If you want to show it after selecting, the value of the input appears to be in hex.
document.querySelector('input[type=color]').value
If you want to display that to a user, you could populate another element with that value when onchange is fired for the input element.

Place two font icons one above the other with CSS

I want to place two font icons one above the other. So I can use it as:
<span class="icon1-on-icon2" />
Is it possible to define CSS class(es) to achieve this? It's not permitted to use another elements inside a span i.e. something like that:
<span class="stack">
<span class="icon1"/>
<span class="icon2" />
</span>
Sure, why not use :after and :before pseudo-selectors?
CSS
.font-icon {
height: 40px;
width: 20px;
}
.font-icon:after, .font-icon:before {
color: white;
content: '';
display: block;
font-family: 'your-font-icon';
height: 20px;
position: relative;
width: 20px;
}
.font-icon:before {
background: red;
content: 'h';
}
.font-icon:after {
background: blue;
content: 'g';
}
HTML
<span class='font-icon'></span>
Codepen sketch here: http://cdpn.io/lehzr
UPDATE
To place them on top of each other, simply change the position to absolute, put a relative on the container element, and set top and left to 0 for both the after and before.
Example: http://cdpn.io/lehzr
Hope that helps!

Resources