Skip to content

Commit

Permalink
make it buildable for both js and flash
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhick committed Nov 13, 2015
1 parent ed7e26f commit b0e4cf3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tools/cheers/src/Cheers.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class Cheers
static function main()
{
self = new Cheers();
js.Browser.window.onload = self.init;
#if !build_for_flash
js.Browser.window.onload = self.init;
#end
}

/**
Expand All @@ -45,7 +47,7 @@ class Cheers
var htmlCodeMirror:Dynamic;

/**
* cs editor
* css editor
*/
var cssCodeMirror:Dynamic;

Expand All @@ -69,6 +71,7 @@ class Cheers
*/
static function cocktailBrowserReady()
{
self.init();
}

/**
Expand Down Expand Up @@ -123,13 +126,19 @@ class Cheers
*/
function update()
{
#if build_for_flash
var object:Dynamic = Browser.document.getElementById("cocktail");
var updateDoc = object.updateDocument;
var getContent = object.getContent;
#else
var updateDoc = untyped __js__ ("cocktailBrowser.updateDocument");
var getContent = untyped __js__ ("cocktailBrowser.getContent");
#end
updateDoc(htmlCodeMirror.getValue(), cssCodeMirror.getValue(), Browser.window.location.href);

//strangely, the easiest way I found to mix html and css content for iframe is
//using cocktail content
var iframe:Dynamic = Browser.document.getElementById("browser");
var getContent = untyped __js__ ("cocktailBrowser.getContent");
iframe.src = "data:text/html;charset=utf-8," + StringTools.urlEncode(getContent());
}
}

0 comments on commit b0e4cf3

Please sign in to comment.