How to apply cufon js to only IE in template.php - drupal

I have some font problem in IE ,so I am trying to apply font-family through js,Its work but js is applied in all browser.How to apply js to only IE.This my code
drupal_add_js('sites/all/themes/blogbuzz/js/cufon-yui.js');
drupal_add_js('sites/all/themes/blogbuzz/js/Helvetica_CE_35_Thin_100.font.js');
drupal_add_js('(function ($){
$(document).ready(function()
{
Cufon.replace("#content-header");
Cufon.replace("#client_tle");
Cufon.replace("#block-block-16");
});
})(jQuery)', "inline");

You can use $.browser.msie variable of jQuery.
Remember to use that with jQuery Migrate if you are using jQuery 1.9+.
$(document).ready(function()
{
if($.browser.msie){
Cufon.replace("#content-header");
Cufon.replace("#client_tle");
Cufon.replace("#block-block-16");
}
});
Regards.

Related

JGrowl set theme from css

I have some code using Jquery Growl function. But I want to customize it to something like that - https://codepen.io/killerek/pen/qqdZJp
I'm using a code:
<script type="text/javascript">
$.jGrowl('{$message}');
</script>
I wanted to use my own css code by editing this line as follows but didn't work for me.
<script type="text/javascript">
$.jGrowl('{$message}','{theme: 'default'});
</script>
Any other ideas? Thanks
The key to using the theme option is the CSS definition, as theme just maps to a CSS class.
In the jGrowl repository there is an example folder that demonstrates this behavior:
Check out the CSS here:
https://github.com/stanlemon/jGrowl/blob/master/examples/jgrowl.html#L16-L19
.jGrowl .manilla {
background-color: #FFF1C2;
color: navy;
}
And the javascript here:
https://github.com/stanlemon/jGrowl/blob/master/examples/jgrowl.html#L95-L120
$.jGrowl("Here is a custom theme.", {
theme: 'manilla'
});
Notice theme of manilla maps to .jGrowl .manilla.
For your situation you would need a similar declaration .jGrowl .default.

Hovering over an image changes HTML background

Basically:
div:hover
{
body{ background-image:(bg.png); }
}
This is logical code, I know it does not work, but its the best how I can show you my problem.
Well what your trying to accomplish cannot be achieved that way using Css only, You can do it using jquery like this
$("#someDiv").hover(function(){
$("body").css("background-image", "url('image_url')")
});
In css ,You can not do this as "body" is parent element to "div" and it should come next to the element hovered to use the for format like
firstelement:hover second_element {/*styles*/}
you can use jquery to achieve it
$("div").hover(function(){
$("body").css("background", "url('url_of_image_here')")
});
or javascript
elem = document.getElementById("ID");
elem.addEventListener("mouseout", function(){
document.getElementsByTagName("body")[0].style.backgroundImage="url()";
});

Use a remote stylesheet inside a template tag (with shadow dom)

I am trying to make a semi-resuseable widget but I am running into a problem. I am trying to encapsulate a some CSS code inside a shadow root so that it does not affect the rest of the webpage but this CSS is used across multiple widgets so I am trying to include a remote stylesheet. None of the examples I have found use a remote style sheet and I was wondering if this was possible.
EX:
<template id="templateContent">
<head>
<link rel="stylesheet" href="css/generalStyle1.css">
</head>
<body>
<div class="affectedByGeneralStyle1"></div>
</body>
</template>
script to include template:
<div id="host"></div>
<script>
var importedData = (html_import_element).import.getElementById("templateContent");
var shadow = document.querySelector('#host').createShadowRoot();
var clone = document.importNode(importedData.content, true);
shadow.appendChild(clone);
</script>
I came across the same problem recently. What I ended up doing was using:
<template id="templateContent">
<style> #import "css/generalStyle.css"; </style>
</template>
Additional info: This worked just fine except that now I'm having some cache issues as Chrome does not seem to reload those resources after a hard reload.
Let add to the answer . Now direct tag is supported in shadow dom.
You can directly use
<link rel="stylesheet" href="yourcss1.css">
<link href="yourcss2.css" rel="stylesheet" type="text/css">
Check they has been update by whatwg and W3C
Useful link for using css in shadow dom.
https://w3c.github.io/webcomponents/spec/shadow/#inertness-of-html-elements-in-a-shadow-tree https://github.com/whatwg/html/commit/43c57866c2bbc20dc0deb15a721a28cbaad2140c
https://github.com/w3c/webcomponents/issues/628
Direct css link can be use in shadow dom
Thanks.
I added the stylesheet's link element directly to the shadow root this way:
let link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('href', 'whatever.css');
this.shadowRoot.appendChild(link);
It seems to work fine. (I called this from the constructor of the component.)
actually polymer has an internal utility to load css links, i have implemented a javascript function that is using polymer internal css processor,so if you want to add css links at runtime you can use it:
Polymer('my-element', {
ready: function () {
this.importCss("path/myfile.css");
},
importCss: function (path) {
var $shadow = $(this.shadowRoot);
var $head = $("<div></div>");
var $link = $("<link rel='stylesheet' type='text/css'>");
$link.attr("href", path);
$head.append($link);
var head = $head[0];
this.copySheetAttributes = Polymer.api.declaration.styles.copySheetAttributes;
Polymer.api.declaration.styles.convertSheetsToStyles.call(this, head);
var styles = Polymer.api.declaration.styles.findLoadableStyles(head);
if (styles.length) {
var templateUrl = this.baseURI;
Polymer.styleResolver.loadStyles(styles, templateUrl, function () {
var $style = $shadow.find("style");
if ($style.length > 0){
$shadow.find("style").append($head.find("style").html());
}else{
$shadow.append($head.html());
}
});
}
}
});
Note: this code needs jquery to run

Disable theming for HTML button

In my web application I've set the CSS style for all the buttons like,
input[type=button], button
{
//
}
If I want to use some other CSS class for a particular button, If its a ASP button I can simply use the property EnableTheming="false".
but I've a html button, for this I need to disable theming. I tried EnableTheming, but its not working. How can I do this, can anyone help me here.
I tried to setting the removeClass using jQuery like,
<script type="text/javascript">
$(document).ready(function () {
$(":button").removeClass("marked");
});
</script>
but, its not working
you can remove the css class using jquery
$(":button").removeClass("marked");
if you want to add class
$(":button").addClass("marked");
If your class has something like this
input[type=button], button
{
border:1px solid #fco;
padding : 0;
margin:0;
}
Do this to make the style default
$(document).ready(function () {
$(":button").css({"border":"", "padding":"", "margin":""});
});

IE select issue with hover

A friend and myself are trying to workaround IE (7/8). We have built a canonical example here:
http://www.mathgladiator.com/share/ie-select-bug-hover-css-menus.htm
Using a CSS menu, we would like to have selects in them. However, in IE, the menu goes away when you interact with the select box. We believe this has to do with a bug in how selects affect events.
Is there a workaround? At least with pure CSS or DOM hacks?
I do not think there is a pure CSS way around this. This is due to a very common bug to the way IE handles events on select elements.
You can however work around it with Javascript:
<script type="text/javascript">
$(document).ready(function () {
$('.nav_element a').mouseover(function() {
$('.submenu').hide();
$(this).parent().find('.submenu').show();
});
$('.submenu').mouseover(function() {
$(this).show();
});
$('.submenu').mouseout(function (e) {
// Do not close if going over to a select element
if (e.target.tagName.toLowerCase() == 'select') return;
$(this).hide();
});
});
</script>
The code above uses jQuery.
Here is a way to improver select behavior in IE7/8, but it does not fix the issue
Change DOCTYPE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Add script
<script>
function ddlOut(e) {
setTimeout(function() { e.className = e.className.replace(' over', ''); }, 1000)
}
</script>
Add css
#nav .over div.submenu
{
display: block;
}
#nav .nav_element{
behavior: expression(
this.onmouseover = new Function("this.className += ' over'"),
this.onmouseout = new Function("ddlOut(this)"),
this.style.behavior = null
);
}
It will work better at least but of course not perfect.
My advice is to change select control to html equivalent. I use OboutDropDown that has a nice view. There are many implementations that can suite you needs.
First you need to expand the :hover surface underneath your menu.
So in your css add width:310px;height:220px to #nav .nav_element a.
(also add a class or an id on the second div styled with top:220px)
Now you just need to simulate a mousedown triggered when you click on the select which will halt when the selection between the options is done - you can probably do the last part if you check for the onfocus state of the select which will stop the mousedown.

Resources