From: Robert Konigsberg Date: Sat, 25 Feb 2012 21:45:10 +0000 (-0500) Subject: Display CSS. This doesn't work in Chrome, locally (http://code.google.com/p/chromium... X-Git-Tag: v1.0.0~320^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=fa20d2efe4660d5c79efd91faa34aeb52d0f0c28;p=dygraphs.git Display CSS. This doesn't work in Chrome, locally (code.google.com/p/chromium/issues/detail?id=45786). Well it works with FF, and also should work when published. --- diff --git a/gallery/gallery.css b/gallery/gallery.css index e7a343e..7bd3510 100644 --- a/gallery/gallery.css +++ b/gallery/gallery.css @@ -1,5 +1,3 @@ -@import url("../common/textarea.css"); - body { font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: 90%; diff --git a/gallery/gallery.js b/gallery/gallery.js index 8e0aa71..b735693 100644 --- a/gallery/gallery.js +++ b/gallery/gallery.js @@ -65,9 +65,12 @@ Gallery.start = function() { Gallery.subtitle.appendChild(document.createTextNode(" ")); - var cssLink = Gallery.create("a", Gallery.subtitle); - cssLink.textContent = "CSS"; - cssLink.href = "#"; + var css = getCss(id); + if (css) { + var cssLink = Gallery.create("a", Gallery.subtitle); + cssLink.textContent = "CSS"; + cssLink.href = "#"; + } Gallery.workareaChild.id = id; location.hash = "g/" + id; @@ -88,7 +91,6 @@ Gallery.start = function() { }; cssLink.onclick = function() { - var css = getCss(demo.title); Gallery.textarea.show("CSS", css); }; @@ -102,11 +104,30 @@ Gallery.start = function() { window.onhashchange = Gallery.setHash;("hashchange", Gallery.hashChange, false); }; -var getCss = function(section) { - // Pretty presumptive of me to assume the first style sheet is the correct one. - // TODO(konigsberg): find the right style sheet by searching. - var ss = document.styleSheets[0]; - return ss.toString(); +var getCss = function(id) { + for (var i = 0; i < document.styleSheets.length; i++) { + var ss = document.styleSheets[i]; + if (ss.title == "gallery") { + try { + var rules = ss.rules || ss.cssRules; + if (rules) { + var arry = []; + for (var j = 0; j < rules.length; j++) { + var rule = rules[j]; + var cssText = rule.cssText; + var key = "#workarea #" + id + " "; + if (cssText.indexOf(key) == 0) { + arry.push(cssText.substr(key.length)); + } + } + return arry.join("\n\n"); + } + } catch(e) { // security error + console.log(e); + } + } + } + return "not found"; } Gallery.register = function(id, demo) { diff --git a/gallery/index.html b/gallery/index.html index 0f573e8..311427e 100644 --- a/gallery/index.html +++ b/gallery/index.html @@ -47,7 +47,8 @@ --> - + +