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