Skip to content

Commit 47657d8

Browse files
author
zzzprojects
committed
Update try it
Update try it
1 parent d9f80fc commit 47657d8

File tree

3 files changed

+136
-2
lines changed

3 files changed

+136
-2
lines changed

docs/_includes/component-try-it.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a href="{{ include.href }}" target="_blank">Try it online</a>
1+
<button href="#" class="btn btn-lg btn-dark" target="_blank" onclick="sqlFiddle.openConsole({url: '{{ include.href }}'});">Run</button>

docs/_layouts/default.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
102102
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
103103
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
104-
104+
<script src="/js/fiddle-client.js"></script>
105+
105106
<script type="text/javascript">
106107
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
107108
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

docs/js/fiddle-client.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
function SqlFiddle() {
2+
3+
////////////
4+
// constructors
5+
////////////
6+
initializeMessage();
7+
createConsole();
8+
9+
////////////
10+
// variable
11+
////////////
12+
var defaultOptions = null;
13+
14+
////////////
15+
// console - public API
16+
////////////
17+
this.closeConsole = function () {
18+
hideConsole();
19+
}
20+
this.openConsole = function (options) {
21+
showConsole(options);
22+
}
23+
this.toggleConsole = function (options) {
24+
if(getConsole().style.display == "") {
25+
showConsole(options);
26+
} else {
27+
hideConsole();
28+
}
29+
}
30+
31+
////////////
32+
// console - private API
33+
////////////
34+
function createConsole() {
35+
createConsoleCss();
36+
37+
document.addEventListener('DOMContentLoaded', function () {
38+
// create div
39+
var div = document.createElement("DIV");
40+
div.id = "sqlfiddle-console";
41+
div.style.display = "none";
42+
43+
// create iframe
44+
var iframe = document.createElement("IFRAME");
45+
iframe.id = "sqlfiddle-console-iframe";
46+
//iframe.setAttribute("src", "http://localhost:8001/Fiddle/FiddleConsole");
47+
iframe.setAttribute("src", "http://nugetmusthaves.com/Fiddle/FiddleConsole");
48+
49+
// append element
50+
div.appendChild(iframe);
51+
document.body.appendChild(div);
52+
});
53+
}
54+
function createConsoleCss() {
55+
document.write("\
56+
<style>\
57+
#sqlfiddle-console {\
58+
background: #333;\
59+
background: -webkit-radial-gradient(circle, #333, #111);\
60+
background: -o-radial-gradient(circle, #333, #111);\
61+
background: -moz-radial-gradient(circle, #333, #111);\
62+
background: radial-gradient(circle, #333, #111);\
63+
height: 400px;\
64+
width: 100%;\
65+
position: fixed;\
66+
bottom: 0;\
67+
left: 0;\
68+
z-index: 199999;\
69+
}\
70+
#sqlfiddle-console #sqlfiddle-console-iframe {\
71+
height: 100%;\
72+
width: 100%;\
73+
border:0;\
74+
}\
75+
</style>\
76+
");
77+
}
78+
function getConsole() {
79+
return document.getElementById("sqlfiddle-console");
80+
}
81+
function getConsoleWindow() {
82+
return document.getElementById("sqlfiddle-console-iframe").contentWindow;
83+
}
84+
function showConsole(options) {
85+
// show console
86+
getConsole().style.display = "";
87+
88+
// send message
89+
data = {
90+
action: 'console-initialize',
91+
defaultOptions: defaultOptions,
92+
options: options
93+
};
94+
sendMessageConsole(data);
95+
}
96+
function hideConsole() {
97+
getConsole().style.display = "none";
98+
}
99+
100+
////////////
101+
// options - public API
102+
////////////
103+
this.setDefaultOptions = function (options) {
104+
defaultOptions = options;
105+
}
106+
107+
////////////
108+
// message - private API
109+
////////////
110+
function initializeMessage() {
111+
if (window.addEventListener) {
112+
window.addEventListener("message", receiveMessage, false);
113+
}
114+
else {
115+
window.attachEvent("onmessage", receiveMessage);
116+
}
117+
}
118+
function sendMessageConsole(msg) {
119+
getConsoleWindow().postMessage(msg,'*');
120+
}
121+
function sendMessageFiddle(id, msg) {
122+
var console = document.getElementsByTagName("fiddle-" + id).contentWindow;
123+
console.postMessage(msg,'*');
124+
}
125+
function receiveMessage(event) {
126+
// console
127+
if(event.data.action == "console.hide") {
128+
hideConsole();
129+
}
130+
}
131+
}
132+
133+
var sqlFiddle = new SqlFiddle();

0 commit comments

Comments
 (0)