@@ -49,23 +49,9 @@ function buildPath(level) {
4949 * @return {string }
5050 */
5151function stringifyObjectKey ( key ) {
52- return / ^ [ a - z A - Z _ $ ] [ A - Z a - z 0 - 9 _ $ ] * $ / . test ( key ) ?
52+ return / ^ [ a - z 0 - 9 _ $ ] + $ / i . test ( key ) ?
5353 key :
54- '"' + escapeDoubleQuotes ( key ) + '"' ;
55- }
56-
57-
58- /**
59- * @param {string } string
60- * @return {string }
61- * @see http://stackoverflow.com/questions/7382115/escape-quotes-in-a-string-with-backslash
62- */
63- function escapeDoubleQuotes ( string ) {
64- return string . replace ( / ( \\ * ) ( " ) / g, function ( all , backslashes , quote ) {
65- return backslashes . length % 2 ?
66- all :
67- backslashes + '\\' + quote ;
68- } ) ;
54+ JSON . stringify ( key ) ;
6955}
7056
7157
@@ -106,7 +92,6 @@ function inspect(object, depth, stack) {
10692}
10793
10894
109-
11095var errors = [ ] ;
11196if ( ! ( "__defineGetter__" in { } ) ) {
11297 errors . push ( "Object.prototype.__defineGetter__ isn’t supported" ) ;
@@ -121,39 +106,48 @@ var style = document.getElementById("style");
121106var output = document . getElementById ( "output" ) ;
122107var serialized = document . getElementById ( "serialized" ) ;
123108
124- function outputUpdated ( ) {
109+ function outputUpdated ( ) {
125110 var value = style . value ;
126111 if ( value != style . prevValue ) {
112+ style . prevValue = value ;
127113 var css = CSSOM . parse ( value ) ;
128114 output . innerHTML = inspect ( css ) ;
129115 serialized . innerHTML = css . toString ( ) ;
130- style . prevValue = value ;
131116 }
132117}
133118
134- function hashChanged ( ) {
119+ /**
120+ * @return {boolean } update happend or not
121+ */
122+ function hashChanged ( ) {
135123 var hash = location . hash ;
136124 var splitted = hash . split ( "=" ) ;
137125 if ( splitted . length < 2 ) {
138- return ;
126+ return false ;
139127 }
140128 var name = splitted [ 0 ] ;
141129 var value = splitted [ 1 ] ;
142130 if ( name == "#css" ) {
143131 style . value = decodeURIComponent ( value ) ;
144132 outputUpdated ( ) ;
133+ return true ;
145134 }
135+ return false ;
146136}
147137
148138window . onload = function ( ) {
149- hashChanged ( ) ;
150- outputUpdated ( ) ;
139+ hashChanged ( ) || outputUpdated ( ) ;
151140} ;
152141
153142window . onhashchange = hashChanged ;
154143style . onkeyup = style . onpaste = function changed ( ) {
155144 outputUpdated ( ) ;
156145} ;
157- style . onchange = function updateLocation ( ) {
158- location . hash = "css=" + encodeURIComponent ( style . value ) ;
146+ style . onchange = function updateLocation ( ) {
147+ if ( style . value . length < 1024 ) {
148+ location . hash = "css=" + encodeURIComponent ( style . value ) ;
149+ } else {
150+ // Huge location.hash slows down the browser :(
151+ location . hash = 'css_is_too_big' ;
152+ }
159153} ;
0 commit comments