X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=gallery%2Fgallery.js;h=b735693455828e7f196df0449e1ea804c21ea77b;hb=38dbac3e0b3c24486d3f548ae63dabd6e1d73bc3;hp=dc508130b9463e1f880300ae74bf13cee463227e;hpb=795b16307db2a673ba7aa3452f6f6b0e93baeb3a;p=dygraphs.git diff --git a/gallery/gallery.js b/gallery/gallery.js index dc50813..b735693 100644 --- a/gallery/gallery.js +++ b/gallery/gallery.js @@ -17,11 +17,17 @@ Gallery.create = function(type, parent, className) { }; Gallery.start = function() { - google.load('visualization', '1', {'packages':['annotatedtimeline']}); Gallery.toc = document.getElementById("toc"); Gallery.workarea = document.getElementById("workarea"); + Gallery.subtitle = Gallery.create("div", Gallery.workarea); + Gallery.subtitle.id = "subtitle"; Gallery.workareaChild = Gallery.create("div", Gallery.workarea); - Gallery.workarea.style.visibility = "hidden"; + Gallery.demotitle = document.getElementById("demotitle"); + Gallery.textarea = new TextArea(); + Gallery.textarea.cancel.style.display = "none"; + Gallery.textarea.width = 600; + Gallery.textarea.height = 400; + for (var idx in Gallery.entryOrder) { var id = Gallery.entryOrder[idx]; var demo = Gallery.entries[id]; @@ -42,15 +48,52 @@ Gallery.start = function() { Gallery.runningDemo.clean(Gallery.workareaChild); } } - Gallery.workarea.style.visibility = "visible"; - document.getElementById("title").textContent = demo.title ? demo.title : ""; + Gallery.subtitle.innerHTML = ""; + + Gallery.demotitle.textContent = demo.title ? demo.title : ""; demo.innerDiv.className = "selected"; + + var htmlLink = Gallery.create("a", Gallery.subtitle); + htmlLink.textContent = "HTML"; + htmlLink.href = "#"; + + Gallery.subtitle.appendChild(document.createTextNode(" ")); + + var javascriptLink = Gallery.create("a", Gallery.subtitle); + javascriptLink.textContent = "Javascript"; + javascriptLink.href = "#"; + + Gallery.subtitle.appendChild(document.createTextNode(" ")); + + var css = getCss(id); + if (css) { + var cssLink = Gallery.create("a", Gallery.subtitle); + cssLink.textContent = "CSS"; + cssLink.href = "#"; + } + Gallery.workareaChild.id = id; - location.hash = id; + location.hash = "g/" + id; + Gallery.workareaChild.innerHTML=''; if (demo.setup) { demo.setup(Gallery.workareaChild); } + + var html = Gallery.workareaChild.innerHTML; + + htmlLink.onclick = function() { + Gallery.textarea.show("HTML", html); + }; + + javascriptLink.onclick = function() { + Gallery.textarea.show("Javascript", demo.run.toString()); + }; + + cssLink.onclick = function() { + Gallery.textarea.show("CSS", css); + }; + demo.run(Gallery.workareaChild); Gallery.runningDemo = demo; }; }(demo, id); @@ -61,6 +104,32 @@ Gallery.start = function() { window.onhashchange = Gallery.setHash;("hashchange", Gallery.hashChange, false); }; +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) { if (Gallery.entries[id]) { throw id + " already registered"; @@ -70,7 +139,13 @@ Gallery.register = function(id, demo) { }; Gallery.hashChange = function(event) { - var id = location.hash.substring(1) + "-toc"; - var elem = document.getElementById(id); - elem.onclick(); -}; \ No newline at end of file + if (location.hash) { + if (location.hash.indexOf("#g/") == 0) { + var id = location.hash.substring(3) + "-toc"; + var elem = document.getElementById(id); + elem.onclick(); + return; + } + } + Gallery.workareaChild.innerHTML = "

Select a demo from the gallery on the left

" +};