X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=gallery%2Fgallery.js;h=f4b6e704facd0d728a8f251438528e7ed483dc2c;hb=406714e12102ee6714774e2801622577ca0daa16;hp=8e0aa71a812fb590d91406f15c95fcfa078309aa;hpb=e2f62472d7b3205f4e6aa2a7be4338a72961dc65;p=dygraphs.git
diff --git a/gallery/gallery.js b/gallery/gallery.js
index 8e0aa71..f4b6e70 100644
--- a/gallery/gallery.js
+++ b/gallery/gallery.js
@@ -50,47 +50,94 @@ Gallery.start = function() {
}
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";
- var htmlLink = Gallery.create("a", Gallery.subtitle);
+ var codeSpan = Gallery.create("span", Gallery.subtitle);
+ codeSpan.id = "code";
+
+ var htmlLink = Gallery.create("a", codeSpan);
htmlLink.textContent = "HTML";
- htmlLink.href = "#";
- Gallery.subtitle.appendChild(document.createTextNode(" "));
+ Gallery.create("span", codeSpan).textContent = " | ";
- var javascriptLink = Gallery.create("a", Gallery.subtitle);
+ var javascriptLink = Gallery.create("a", codeSpan);
javascriptLink.textContent = "Javascript";
- javascriptLink.href = "#";
- Gallery.subtitle.appendChild(document.createTextNode(" "));
-
- var cssLink = Gallery.create("a", Gallery.subtitle);
- cssLink.textContent = "CSS";
- cssLink.href = "#";
+ var css = getCss(id);
+ if (css) {
+ Gallery.create("span", codeSpan).textContent = " | ";
+ var 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" +
+ "\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);
};
- cssLink.onclick = function() {
- var css = getCss(demo.title);
- Gallery.textarea.show("CSS", css);
- };
+ if (css) {
+ cssLink.onclick = function() {
+ Gallery.textarea.show("CSS", css);
+ };
+ }
demo.run(Gallery.workareaChild);
Gallery.runningDemo = demo;
@@ -102,11 +149,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) {