$(document).ready(function() {
$('head').append(
$("<style>")
.attr('id','styleTween')
.html($('#style1').html())
);
$('#buttons button').click( function() {
switch_styles( $($(this).data("style")).html(), ($(this).data("wrapper"))?$(this).data("wrapper"):'' );
});
});
//pull selectors from a JSCSSP parser result
function get_selectors(foo) {
if (typeof foo == "object" && foo.hasOwnProperty("cssRules") ) {
var selectors = [];
for (var h=0;h<foo.cssRules.length;h++) {
var r = foo.cssRules[h];
selectors.push(r.mSelectorText);
}
selectors.sort();
return selectors;
} else return [];
}
function switch_styles(new_style_css,wrapper) {
var parser = new CSSParser();
var current_style = parser.parse($('#styleTween').html());
var new_style = parser.parse(new_style_css);
var old_style_selectors = [];
var new_style_selectors = [];
var common_selectors = [];
var to_be_animated = [];
var selectors_affected = [];
console.log(new_style);
if (current_style.cssRules[0].error == "INVALID") { return; }
if (new_style.cssRules[0].error == "INVALID") { return; }
if (current_style && new_style) {
old_style_selectors = get_selectors(current_style);
new_style_selectors = get_selectors(new_style);
//find declarations (#foo, #bar, .wamp) that we need to deal with
common_selectors = intersection(old_style_selectors, new_style_selectors);
//find style rules in the NEW style that we need to change, from this list of common declarations
var declarations_to_be_animated = new_style.cssRules.filter(function(val) {
return 0 != in_array(val.mSelectorText, common_selectors);
});
for (var h=0;h<declarations_to_be_animated.length;h++) {
var s = declarations_to_be_animated[h];
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.