Button text color in Extjs 4 - css

I'm using Exjts 4 and i want to change the button text color. Here is my code:
{
xtype: 'button',
text: 'My Button',
style:{
color: 'red'
}
}

In case someone needs it. I do not know if it's a dirty solution but it works
{
xtype: 'button',
text: '<div style="color: red">My Button</div>',
}

Davor Zubak shed light on a solution although it failed in my complex application. I achieved what I want by this:
Button's cls: 'myButton'
In my css file, define:
.myButton .x-btn-inner {
color: red;
font-family: Georgia;
font-size: large;
font-weight: bold;
}
This way it only overrides the ExtJS theme for the particular buttons who have 'myButton' cls.

There is some strange behavior in Extjs 4.2.0, but there is an override possible. Give your button a class using cls:'yourClassName' property and then in CSS make a full path to span holding the text, like so: .yourClassName div a span. Also give your css property a !important value to successfuly override base class.
Ext.create('Ext.Button', {
text: 'Click me',
renderTo: Ext.getBody(),
handler: function() {
alert('You clicked the button!');
},
cls: 'foo'
});
and in css simply:
.foo div a span
{
color:#ff0000 !important;
}
Here is a example.

Related

jQuery UI widget CSS inhertiance issues

I have a couple different types of UI widgets on my page. There is a class that is common between all of them .ui-widget-content. I need to style this class differently for each one, so I have assigned unique ids or classes to the HTML elements. This worked ok for one type of widget (dialog where I can use the dialogClass option in the JS to assign classes), but the other type of widget (slider) will still only inherit styles from .ui-widget-content even when I specify a style for #id .ui-widget-content to get at the specific element of interest. I'm kind of at a loss on how to override the original style at this point.
HTML:
<div id="opacitySlide" class="slider">
<div id="opacityVal" class="ui-slider-handle"></div>
</div>
<div id="habClassify-dialog" title="Habitat Classification">
<div id="HabClassifyGPService">
//whole bunch of stuff
</div>
</div>
<div id="error-dialog" title="ERROR"></div>
<div id="success-dialog" title="SUCCESS">
<p>Habitat classification completed successfully! Your results will be viewable in 10 minutes.</p>
</div>
CSS:
//This one doesn't work and get overridden by the default style .ui-widget-content
#opacitySlide .ui-widget-content {
border: 1px solid black;
}
//This one does work, these classes are assigned in the JS, NOT the HTML
.habClassify-dialog .ui-widget-content,
.error-dialog .ui-widget-content,
.success-dialog .ui-widget-content {
border: none;
}
I've also attempted to use the custom class I assigned in the HTML instead of the id for the non-working CSS as well, but no luck.
.slider .ui-widget-content {
border: 1px solid black;
}
Here's the JS code:
//Creates the popup dialog for the habitat classification button
var habClassifyDialog = $("#habClassify-dialog").dialog({
autoOpen: false,
height: "auto",
width: 400,
modal: true,
dialogClass: 'habClassify-dialog',
buttons: [{
id: "classify",
text: "Classify habitat",
click: upload
}],
close: function () {
$('#uploadForm')[0].reset();
$('#validation-text').empty();
}
});
$('#classifyHab').click(function() {
habClassifyDialog.dialog("open");
});
//Creates the popup dialog that contains error messages
var errorDialog = $("#error-dialog").dialog({
autoOpen: false,
height: "auto",
width: 1000,
modal: true,
dialogClass: 'error-dialog',
buttons: [{
id: "error-ok",
text: "Ok",
click: function () {
errorDialog.dialog("close");
}
}]
});
//Creates the popup dialog that shows the success message
var successDialog = $('#success-dialog').dialog({
autoOpen: false,
height: "auto",
width: 400,
modal: true,
dialogClass: 'success-dialog',
buttons: [{
id: "success-ok",
text: "Ok",
click: function () {
successDialog.dialog("close");
if (habClassifyDialog.dialog('isOpen')) {
habClassifyDialog.dialog("close");
}
}
}],
close: function () {
if (habClassifyDialog.dialog('isOpen')) {
habClassifyDialog.dialog("close");
}
}
});
//Create the opacity slider
var handle = $("#opacityVal");
$("#opacitySlide").slider({
range: "min",
value: 100,
min: 0,
max: 100,
create: function () {
handle.text($(this).slider("value") + "%");
},
slide: changeOpacity,
change: changeOpacity
});
If you haven't used jQuery UI before, it automatically adds a whole bunch of default styles to the widgets upon load, that's why you don't see class="ui-widget-content" in my HTML anywhere, it's not necessary to declare it.
Alright, I have officially made the stupidest mistake ever. Considering the HTML was generating with the correct custom ID I assigned, I figured there had to be a way to access the ui-widget-content class using that ID. It was as simple as chaining them together, before when I was testing this I had left a space in between.
Problem CSS (won't work):
#opacitySlide .ui-widget-content {
border: 1px solid black;
}
Simple fix (remove space between id and class):
#opacitySlide.ui-widget-content{
border: 1px solid black;
}
For the sake of completeness, the explanation is that if you leave a space between these items, it thinks the HTML is structured like this:
<div id="opacitySlide">
<div class="ui-widget-content"></div>
</div>
when really my HTML was structured like this:
<div id="opacitySlide" class="ui-widget-content"></div>

How to change the "text"on the kendo grid button?

On my kendo grid there is a button, by default it's add new record. I want to change it. I used the following tag but does not work :
#turbinegrid .k-icon.k-add::after {
content: "ADD";
}
You can set template for the button like below,
$("#myGrid").kendoGrid({
toolbar: [{
template: '<div><div style="float:left;"><h2>Tech Documents</h2></div><div style="float:right;margin: 2% 1% 1% 1%;"><a title="add new" class="k-button k-button-icontext k-grid-add" href="\\#"><span class="k-icon k-i-plus-outline"></span>**Create One**</a></div></div>'
}]
});
Use Your Text for the button in place of Create One.
When using MVC you can set the text like this:
#(Html.Kendo().Grid<GridViewModel>()
.ToolBar(tools =>
{
tools.Create().Text("ADD");
})
)
When using jQuery use this:
$("#grid").kendoGrid({
toolbar: [{ name: "create", text: "ADD" }]
});
#turbinegrid .k-icon.k-add {
font-size: 0px !important;
}
#turbinegrid .k-icon.k-add::after {
content: "New Text" !important;
font-size: 18px !important;
}

Tinymce: Adding custom HTML to the toolbar

I'm wanting to extend the tinymce toolbar with a font family selector that displays the font family names styled with that font-family. To do this I need to wrap each font name markup with a class or inline css. I've scoured the tinymce API documentation and am struggling to find a way to add custom HTML in an menu item.
The closest I've gotten is an un-styled button that opens a panel with a custom HTML selector, but it's not ideal. I'd really like to add an select directly to the toolbar that is styled with the font families.
This might help you. It doesn't use the toolbar, but instead adds an extra menubar item with custom menuitems.
HTML
<form>
<textarea></textarea>
</form>
JavaScript
It works by adding menuItems to the menu. We can then provide the classes option to the menuitem. This allows us to target each menu item separately via css class selectors. E.g. If we supply classes: "monospace". TinyMCE converts this into .mce-monospace as the class selector. However tinymces css rules will override unless you select a bigger css precedence.
tinymce.init({
selector: "textarea",
menu: {
mynewmenu: {
title: 'Select Font Family',
items: 'arial | monospace | timesnew'
}
},
menubar: 'mynewmenu',
setup: function(editor) {
editor.addMenuItem('arial', {
text: 'Arial',
classes: "arial",
context: 'mynewmenu',
onclick: function() {
alert('yey!');
}
});
editor.addMenuItem('monospace', {
text: 'Monospace',
classes: "monospace",
context: 'mynewmenu',
onclick: function() {
alert('yey!');
}
});
editor.addMenuItem('timesnew', {
text: 'Times New Roman',
classes: "timesnew",
context: 'mynewmenu',
onclick: function() {
alert('yey!');
}
});
}
});
CSS
This is how I got the style to override via css.
.mce-menu-item.mce-monospace > span {
font-family: monospace;
color: olive;
}
.mce-menu-item.mce-arial > span{
font-family: Arial;
color: red;
}
.mce-menu-item.mce-timesnew > span{
font-family: Times New Roman;
color: green;
}
Notice if you just use .mce-monospace > span The precedence value is not big enough, while with .mce-menu-item.mce-monospace > span has a bigger precedence value and overrides tinymces css.
Have a look at this example Demo

How to retain the format ,when Drag and drop of a object from one div to another div

When a object is dragged and dropped from one div to another, the format in li gets changes to text only. I want it in the same format and style i.e 'li' after droping it.
$(function() {
$("#catalog ul").sortable({
zIndex: 10000,
revert: true
});
$("#catalog").accordion();
$("#catalog ul").draggable({
appendTo: "body",
helper: "clone",
zIndex: 10000
});
$("#dialogIteration ol").droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).find(".placeholder").remove();
$("<li></li>").text(ui.draggable.text()).appendTo(this);
}
}).sortable({
items: "li:not(.placeholder)",
sort: function() {
// gets added unintentionally by droppable interacting with sortable
// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
$(this).removeClass("ui-state-default");
}
});
$("ul, li").disableSelection();
$("#dialogIteration").dialog();
});
Sample Code here
The style of item <li class="ui-state-default"/> in original list is defined by CSS rules:
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default {
border: 1px solid lightGrey;
background: #E6E6E6 url(images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;
font-weight: normal;
color: #555;
}
...
After you dragged it to new container, and drop it, you created another element to hold the content $("<li></li>").text(ui.draggable.text()) which doesn't have the same className as the original element, so the style is ripped off.
You can either fix it by changing it to
$('<li class="ui-state-default" />').text(ui.draggable.text()).appendTo( this )

Button background color in sencha

I am new to sencha touch.
How do we change the background color of a button to white? I have a button with two images in each corner. I want the button to be plain white.
I tried using css like this:
.quest {
background: url(../images/quest.jpg) no-repeat left,
url(../images/rightarrow.jpg) no-repeat right;
background-color: white;
border: none;
border-color:white;
padding-left: 50px;
text-align: left;
}
My button is here:
{
xtype: 'button',
text: '<div class="quest">Info</div>',
labelWidth: '100%',
name: '',
handler: function() {
}
}
My button has grey borders (Grey default button color in sencha) with white color in mid. How do i make it completely white? Please help.
I have even tried:
style: "background-color: white"
Using 'cls' attribute solved my problem.
{
xtype: 'button',
cls: 'btn',
text: '<div class="person">People</div>',
labelWidth: '100%',
},
In my app.css define
.btn
{
background-color: white !important;
background-image: none;
}
We have to redefine both background-color and background-image properties so that the default sencha-touch.css properties are overridden. Thank you Thiem Nguyen for your help.
This should render your desired button :)
config: {
ui: 'plain',
text: 'Your Text',
style: 'background-color:white;'
}
Just like Thiem Nguyen said, this will work
{
xtype:'button',
text:'text',
ui:'plain',
style:'background-color:white'
}

Resources