Skip to content
Browse files

Fixes #2265 - Using .set('text', '…') on <style> elements failed in o…

…ldIE

The feature detection tests actually tries to set the CSS, this is done
because IE9 does not fail, but supports the styleSheet property.
So this way IE9 behaves like other browsers.
  • Loading branch information...
1 parent 0664977 commit d09b487fee4fcb623b98be6ae0034ad2a7f76208 @arian committed Feb 5, 2012
Showing with 59 additions and 5 deletions.
  1. +33 −5 Source/Element/Element.js
  2. +26 −0 Specs/1.4client/Element/Element.js
View
38 Source/Element/Element.js
@@ -593,14 +593,42 @@ el = null;
var input = document.createElement('input');
input.value = 't';
input.type = 'submit';
-if (input.value != 't') propertySetters.type = function(node, type){
- var value = node.value;
- node.type = type;
- node.value = value;
-};
+if (input.value != 't') (function(set){
+ propertySetters.type = function(node, type){
+ var tag = node.get('tag');
+ if (tag == 'input' || tag == 'button'){
+ var value = node.value;
+ node.type = type;
+ node.value = value;
+ } else set(node, type);
+ };
+})(propertySetters.type);
input = null;
+
/*</IE>*/
+/* <ltIE9> */
+// oldIE can't set the CSS text to a <style> element: #2265
+var style = document.createElement('style');
+style.type = 'text/css';
+try {
+ propertySetters.text(node, 'a{left:0}');
+ style = propertyGetters.text(node).indexOf('left') == -1;
+} catch(e){}
+if (style) (function(set, get){
+ propertySetters.text = function(node, value){
+ if (node.get('tag') == 'style' && node.styleSheet) node.styleSheet.cssText = value;
+ else set(node, value);
+ };
+ propertyGetters.text = function(node){
+ if (node.get('tag') == 'style' && node.styleSheet) return node.styleSheet.cssText;
+ return get(node);
+ };
+})(propertySetters.text, propertyGetters.text);
+style = null;
+
+/* </ltIE9> */
+
/* getProperty, setProperty */
/* <ltIE9> */
View
26 Specs/1.4client/Element/Element.js
@@ -219,6 +219,32 @@ describe('Element', function(){
});
+ describe('Element.set/get text of style element', function(){
+
+ it('should set and get the CSS of a <style> element', function(){
+ // new Element('style', {type: 'text/css'}); does not work
+ var style = document.createElement('style');
+ style.type = 'text/css';
+ var definition = [
+ '.pos-abs-left {',
+ 'position: absolute;',
+ 'width: 200px;',
+ 'height: 200px;',
+ 'left: 10%;',
+ 'background: red;',
+ '}'
+ ].join('');
+ style.set('text', definition);
+ var returned = style.get('text').toLowerCase();
+ expect(returned.indexOf('position: absolute')).not.toEqual(-1);
+ expect(returned.indexOf('width: 200px')).not.toEqual(-1);
+ expect(returned.indexOf('height: 200px')).not.toEqual(-1);
+ expect(returned.indexOf('left: 10%')).not.toEqual(-1);
+ expect(returned.indexOf('background: red')).not.toEqual(-1);
+ });
+
+ });
+
describe("Element.erase('html')", function(){
it('should empty the html inside an element', function(){

0 comments on commit d09b487

Please sign in to comment.
Something went wrong with that request. Please try again.