X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=inline;f=gallery%2Fgallery.js;h=f8b4ceea1ae284ab931b62beafb2d0dcd04adc8c;hb=80be397c6428c0015c21f4a4ac96e222eb51f67e;hp=e854a7a4ac0bd0b1b13abe2ce7b7cdb234060ad1;hpb=304c1fbb055ba5159ba8730ceddbbd2b676a3c13;p=dygraphs.git diff --git a/gallery/gallery.js b/gallery/gallery.js index e854a7a..f8b4cee 100644 --- a/gallery/gallery.js +++ b/gallery/gallery.js @@ -1,3 +1,5 @@ +/*jshint loopfunc:true */ +/*global Dygraph,$,TextArea,jQuery */ var Gallery = {}; Gallery.entries = {}; @@ -42,14 +44,22 @@ Gallery.start = function() { innerDiv.textContent = demo.name; div.onclick = function(demo, id) { return function() { - if (Gallery.runningDemo != null) { + if (Gallery.runningDemo !== null) { Gallery.runningDemo.innerDiv.className = ""; - if (Gallery.runningDemo.clean != null) { + if (Gallery.runningDemo.clean) { Gallery.runningDemo.clean(Gallery.workareaChild); } } Gallery.subtitle.innerHTML = ""; + Gallery.workareaChild.id = id; + location.hash = "g/" + id; + + Gallery.workareaChild.innerHTML=''; + if (demo.setup) { + demo.setup(Gallery.workareaChild); + } + Gallery.demotitle.textContent = demo.title ? demo.title : ""; demo.innerDiv.className = "selected"; @@ -59,35 +69,71 @@ Gallery.start = function() { var htmlLink = Gallery.create("a", codeSpan); htmlLink.textContent = "HTML"; - codeSpan.appendChild(document.createTextNode(" ")); + Gallery.create("span", codeSpan).textContent = " | "; var javascriptLink = Gallery.create("a", codeSpan); javascriptLink.textContent = "Javascript"; - codeSpan.appendChild(document.createTextNode(" ")); - var css = getCss(id); + var cssLink; if (css) { - var cssLink = Gallery.create("a", codeSpan); + Gallery.create("span", codeSpan).textContent = " | "; + cssLink = Gallery.create("a", codeSpan); cssLink.textContent = "CSS"; } - Gallery.workareaChild.id = id; - location.hash = "g/" + id; + var jsFiddleForm = Gallery.create("form", codeSpan); + var jsfs = $(jsFiddleForm); + jsFiddleForm.method = "post"; + jsFiddleForm.action = "http://jsfiddle.net/api/post/jquery/1.4/"; - Gallery.workareaChild.innerHTML=''; - if (demo.setup) { - demo.setup(Gallery.workareaChild); - } + jsfs.html("\n" + + "
\n"); + var javascript = demo.run.toString(); var html = Gallery.workareaChild.innerHTML; + // tweak for use in jsfiddle + javascript = " $(document).ready(" + javascript + "\n);"; + jQuery('', { name: 'html' }) + .val(html) + .hide() + .appendTo(jsfs); + + jQuery('', { name: 'js' }) + .val(javascript) + .hide() + .appendTo(jsfs); + + if (css) { + jQuery('', { name: 'css' }) + .val(css) + .hide() + .appendTo(jsfs); + } + jQuery('', { + type: 'text', + name: 'title', + value: 'title tbd' + }) + .hide() + .appendTo(jsfs); + jQuery('', { + type: 'text', + name: 'description', + value: 'desc tbd' + }) + .hide() + .appendTo(jsfs); + htmlLink.onclick = function() { Gallery.textarea.show("HTML", html); }; javascriptLink.onclick = function() { - Gallery.textarea.show("Javascript", demo.run.toString()); + Gallery.textarea.show("Javascript", javascript); }; if (css) { @@ -103,7 +149,7 @@ Gallery.start = function() { Gallery.hashChange(); - window.onhashchange = Gallery.setHash;("hashchange", Gallery.hashChange, false); + window.onhashchange = Gallery.setHash; }; var getCss = function(id) { @@ -118,7 +164,7 @@ var getCss = function(id) { var rule = rules[j]; var cssText = rule.cssText; var key = "#workarea #" + id + " "; - if (cssText.indexOf(key) == 0) { + if (cssText.indexOf(key) === 0) { arry.push(cssText.substr(key.length)); } } @@ -130,7 +176,7 @@ var getCss = function(id) { } } return "not found"; -} +}; Gallery.register = function(id, demo) { if (Gallery.entries[id]) { @@ -142,12 +188,12 @@ Gallery.register = function(id, demo) { Gallery.hashChange = function(event) { if (location.hash) { - if (location.hash.indexOf("#g/") == 0) { + if (location.hash.indexOf("#g/") === 0) { var id = location.hash.substring(3) + "-toc"; var elem = document.getElementById(id); elem.onclick(); return; } } - Gallery.workareaChild.innerHTML = "