Skip to content

Commit

Permalink
Styles will be added to separate stylesheet. Fixes bitovi#5
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jun 6, 2012
1 parent a3c8966 commit 5896c02
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions dom/animate/animate.js
@@ -1,32 +1,23 @@
steal('jquery', 'jquery/dom/styles').then(function ($) {

var animationNum = 0,
//Animation events implies animations right?
//gets the last editable stylesheet or creates one
styleSheet = null,
// Create a new stylesheet where we store our animations
getLastStyleSheet = function () {
var sheets = document.styleSheets,
x = sheets.length - 1,
foundSheet = null,
style;

while (x >= 0 && !foundSheet) {
if (sheets[x].cssRules || sheets[x].rules) {
//any stylesheet which we can access cssRules is good
foundSheet = sheets[x];
}
x -= 1;
}
if(!styleSheet) {
var style = document.createElement('style');
style.setAttribute("type", "text/css");
style.setAttribute("media", "screen");

if (!foundSheet) {
style = document.createElement('style');
document.getElementsByTagName('head')[0].appendChild(style);
if (!window.createPopup) { /* For Safari */
style.appendChild(document.createTextNode(''));
}
foundSheet = sheets[sheets.length - 1];

styleSheet = style.sheet;
}

return foundSheet;
return styleSheet;
},

//removes an animation rule from a sheet
Expand Down Expand Up @@ -54,9 +45,6 @@ steal('jquery', 'jquery/dom/styles').then(function ($) {
|| jQuery.isArray(props[name]) // Arrays for individual easing
|| props[name] < 0 // Negative values not handled the same
|| name == 'zIndex' || name == 'z-index'
// Firefox doesn't animate 'auto' properties
// https://bugzilla.mozilla.org/show_bug.cgi?id=571344
// || (browser.prefix == '-moz-' && (name == 'font-size' || name == 'fontSize'))
) { // unit-less value
return true;
}
Expand All @@ -79,9 +67,7 @@ steal('jquery', 'jquery/dom/styles').then(function ($) {
return value;
},

/**
* Feature detection borrowed by Modernizr
*/
// Feature detection borrowed by http://modernizr.com/
getBrowserProperties = function(){
var t,
el = document.createElement('fakeelement'),
Expand All @@ -90,16 +76,14 @@ steal('jquery', 'jquery/dom/styles').then(function ($) {
transitionEnd : 'transitionEnd',
prefix : ''
},
/*
'OTransition': {
transitionEnd : 'oTransitionEnd',
prefix : '-o-'
},
'MSTransition': {
transitionEnd : 'msTransitionEnd',
prefix : '-ms-'
},
*/
// 'MSTransition': {
// transitionEnd : 'msTransitionEnd',
// prefix : '-ms-'
// },
'MozTransition': {
transitionEnd : 'animationend',
prefix : '-moz-'
Expand Down Expand Up @@ -174,11 +158,11 @@ steal('jquery', 'jquery/dom/styles').then(function ($) {
});

if(!name) { // Add a new style
lastSheet = getLastStyleSheet()
lastSheet = getLastStyleSheet();
name = "animate" + (animationNum++);
// get the last sheet and insert this rule into it
lastSheet.insertRule("@" + browser.prefix + "keyframes " + name + ' ' + style,
lastSheet.cssRules.length);
(lastSheet.cssRules && lastSheet.cssRules.length) || 0);

cache.push({
name : name,
Expand Down

0 comments on commit 5896c02

Please sign in to comment.