X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=gallery%2Fgallery.js;h=bdf238650c3dfeb20fc3c1e983f05eee0ed979ce;hb=6ced60865e23c1fd1c87f176b9b9ad3c6bf3b92a;hp=dc508130b9463e1f880300ae74bf13cee463227e;hpb=c1f22b5a5d4ffbf25a75fc567232e65381c1938b;p=dygraphs.git diff --git a/gallery/gallery.js b/gallery/gallery.js index dc50813..bdf2386 100644 --- a/gallery/gallery.js +++ b/gallery/gallery.js @@ -17,11 +17,13 @@ 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.workareaChild = Gallery.create("div", Gallery.workarea); - Gallery.workarea.style.visibility = "hidden"; + Gallery.title = document.getElementById("title"); + Gallery.textarea = new TextArea(); + for (var idx in Gallery.entryOrder) { var id = Gallery.entryOrder[idx]; var demo = Gallery.entries[id]; @@ -42,15 +44,23 @@ Gallery.start = function() { Gallery.runningDemo.clean(Gallery.workareaChild); } } - Gallery.workarea.style.visibility = "visible"; - document.getElementById("title").textContent = demo.title ? demo.title : ""; + Gallery.subtitle.innerHTML = ""; + var codeLink = Gallery.create("a", Gallery.subtitle); + codeLink.textContent = "code"; + codeLink.href = "#"; + Gallery.title.textContent = demo.title ? demo.title : ""; demo.innerDiv.className = "selected"; 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; + codeLink.onclick = function() { + var javascript = demo.run.toString(); + Gallery.textarea.show("Code", "HTML\n\n" + html + "\n\njavascript\n\n" + javascript); + }; demo.run(Gallery.workareaChild); Gallery.runningDemo = demo; }; }(demo, id); @@ -70,7 +80,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

" +};