From fa20d2efe4660d5c79efd91faa34aeb52d0f0c28 Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Sat, 25 Feb 2012 16:45:10 -0500 Subject: [PATCH] Display CSS. This doesn't work in Chrome, locally (http://code.google.com/p/chromium/issues/detail?id=45786). Well it works with FF, and also should work when published. --- gallery/gallery.css | 2 -- gallery/gallery.js | 39 ++++++++++++++++++++++++++++++--------- gallery/index.html | 3 ++- 3 files changed, 32 insertions(+), 12 deletions(-) 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 @@ --> - + + -- 2.7.4