X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=inline;f=gallery%2Fgallery.js;h=f4b6e704facd0d728a8f251438528e7ed483dc2c;hb=a12a78ae06c196aa0d3211ab57b584367504b9a0;hp=dec3cb37236cc96284665e35352c46261c04400d;hpb=26e931301c0e8086a409f940acf4cf601736c6da;p=dygraphs.git
diff --git a/gallery/gallery.js b/gallery/gallery.js
index dec3cb3..f4b6e70 100644
--- a/gallery/gallery.js
+++ b/gallery/gallery.js
@@ -22,8 +22,9 @@ Gallery.start = function() {
Gallery.subtitle = Gallery.create("div", Gallery.workarea);
Gallery.subtitle.id = "subtitle";
Gallery.workareaChild = Gallery.create("div", Gallery.workarea);
- Gallery.title = document.getElementById("title");
+ Gallery.demotitle = document.getElementById("demotitle");
Gallery.textarea = new TextArea();
+ Gallery.textarea.cancel.style.display = "none";
Gallery.textarea.width = 600;
Gallery.textarea.height = 400;
@@ -48,22 +49,96 @@ Gallery.start = function() {
}
}
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 = "g/" + id;
+
Gallery.workareaChild.innerHTML='';
if (demo.setup) {
demo.setup(Gallery.workareaChild);
}
+
+ Gallery.demotitle.textContent = demo.title ? demo.title : "";
+ demo.innerDiv.className = "selected";
+
+ var codeSpan = Gallery.create("span", Gallery.subtitle);
+ codeSpan.id = "code";
+
+ var htmlLink = Gallery.create("a", codeSpan);
+ htmlLink.textContent = "HTML";
+
+ Gallery.create("span", codeSpan).textContent = " | ";
+
+ var javascriptLink = Gallery.create("a", codeSpan);
+ javascriptLink.textContent = "Javascript";
+
+ var css = getCss(id);
+ if (css) {
+ Gallery.create("span", codeSpan).textContent = " | ";
+ var cssLink = Gallery.create("a", codeSpan);
+ cssLink.textContent = "CSS";
+ }
+
+ var jsFiddleForm = Gallery.create("form", codeSpan);
+ var jsfs = $(jsFiddleForm);
+ jsFiddleForm.method = "post";
+ jsFiddleForm.action = "http://jsfiddle.net/api/post/jquery/1.4/";
+
+ jsfs.html("\n" +
+ "\n" +
+ "\n" +
+ "\n");
+
+ var javascript = demo.run.toString();
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);
+
+ // 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", javascript);
+ };
+
+ if (css) {
+ cssLink.onclick = function() {
+ Gallery.textarea.show("CSS", css);
+ };
+ }
+
demo.run(Gallery.workareaChild);
Gallery.runningDemo = demo;
}; }(demo, id);
@@ -74,6 +149,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";