[email protected] | 7721902f | 2012-08-24 23:58:43 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>CSSOM - CSSStyleDeclaration - Text - Serialization - Delimiters</title> |
| 5 | <link rel="author" title="Glenn Adams" href="mailto:[email protected]"/> |
| 6 | <link rel="help" href="http://www.w3.org/TR/cssom/#the-cssstyledeclaration-interface"/> |
| 7 | <meta name="flags" content="dom"/> |
| 8 | <script src="../resources/testharness.js"></script> |
| 9 | <script src="../resources/testharnessreport.js"></script> |
| 10 | </head> |
| 11 | <body> |
| 12 | <div id="log"></div> |
| 13 | <div id="box"></div> |
| 14 | <script> |
| 15 | var style = document.getElementById('box').style; |
| 16 | var delim = new RegExp ( /(\s*\;\s*)/ ); |
| 17 | |
| 18 | function countDelimiters(s) { |
| 19 | var k = ( s.split(delim).length - 1 ) / 2; |
| 20 | return k; |
| 21 | } |
| 22 | |
| 23 | function getNthDelimiter(s,n) { |
| 24 | if ( n > 0 ) { |
| 25 | var sa = s.split(delim); |
| 26 | var k = 1; |
| 27 | for ( var i in sa ) { |
| 28 | var s = sa[i]; |
| 29 | var m = delim.exec(s); |
| 30 | if ( m && ( m.length > 1 ) ) { |
| 31 | if ( k++ == n ) { |
| 32 | return s; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | return ''; |
| 38 | } |
| 39 | |
| 40 | test(function(){ |
| 41 | |
| 42 | style.cssText = ""; |
| 43 | assert_equals(countDelimiters(style.cssText), 0); |
| 44 | assert_equals(getNthDelimiter(style.cssText,0), ""); |
| 45 | assert_equals(style.cssText, ""); |
| 46 | |
| 47 | }, 'inline style - text - delimiters - zero declarations'); |
| 48 | |
| 49 | test(function(){ |
| 50 | |
| 51 | style.cssText = "left: 10px"; |
| 52 | assert_equals(countDelimiters(style.cssText), 1); |
| 53 | assert_equals(getNthDelimiter(style.cssText,1), ";"); |
| 54 | assert_equals(style.cssText, "left: 10px;"); |
| 55 | |
| 56 | }, 'inline style - text - delimiters - one declaration'); |
| 57 | |
| 58 | test(function(){ |
| 59 | |
| 60 | style.cssText = "left: 10px; right: 20px"; |
| 61 | assert_equals(countDelimiters(style.cssText), 2); |
| 62 | assert_equals(getNthDelimiter(style.cssText,1), "; "); |
| 63 | assert_equals(getNthDelimiter(style.cssText,2), ";"); |
| 64 | assert_equals(style.cssText, "left: 10px; right: 20px;"); |
| 65 | |
| 66 | }, 'inline style - text - delimiters - two declarations'); |
| 67 | </script> |
| 68 | </body> |
| 69 | </html> |