@@ -25,15 +25,15 @@ if (!Module) {
2525 Module = ( typeof Module !== 'undefined' ? Module : null ) || { } ;
2626}
2727
28- // ----------------------------------------------------------------
29- // Download standalone capsule
30- // ----------------------------------------------------------------
31-
3228// Ensure the Module object has a preRun list
3329if ( ! Module [ 'preRun' ] ) {
3430 Module [ 'preRun' ] = [ ] ;
3531}
3632
33+ // ----------------------------------------------------------------
34+ // Download standalone capsule
35+ // ----------------------------------------------------------------
36+
3737// Before the engine is allowed to start, we download the standalone
3838// capsule, which is a zip file containing the root filesystem to be
3939// used by the engine.
@@ -74,6 +74,8 @@ Module['preRun'].push(function() {
7474 standalone = Module [ 'livecodeStandalonePrefixURL' ] + standalone ;
7575 }
7676
77+ Module [ 'livecodeStandaloneUrl' ] = standalone ;
78+
7779 // Download the capsule
7880
7981 // FIXME Can we cache the capsule locally?
@@ -104,3 +106,113 @@ Module['preRun'].push(function() {
104106 Module [ 'livecodeStandaloneRequest' ] = xhr ;
105107 }
106108} ) ;
109+
110+ // ----------------------------------------------------------------
111+ // Add "download this app" overlay
112+ // ----------------------------------------------------------------
113+
114+ // We display an overlay on the canvas that allows users to download
115+ // the stack. Note that we *don't* let the overlay parameters be
116+ // overridden by the web page, unlike the standalone parameters above.
117+
118+ // FIXME Massive amounts of hardcoded styling that can't be customized
119+ // in any way
120+
121+ // Enable the overlay by default.
122+ Module [ 'livecodeOverlay' ] = true ;
123+
124+ // LiveCode community icon, as SVG.
125+ Module [ 'livecodeOverlayIcon' ] = '<?xml version="1.0" encoding="utf-8"?><!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) --><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 579 594" enable-background="new 0 0 579 594" xml:space="preserve"><path fill="#AED036" d="M546.3,40.4c-0.1-0.5-0.3-0.9-0.4-1.4c0-0.1-0.1-0.3-0.1-0.5l0,0c-7.3-21.5-28.3-37.1-53-37.1H87 c-25.2,0-46.5,16.1-53.4,38.3l-0.1-0.1C13.9,101,3.1,170.7,3.1,246c0,73.3,10.7,141.4,29.3,201.4c0.5,2.5,1.3,5,2.2,7.3 c0.1,0.3,0.2,0.6,0.3,0.8l0,0c8,20.3,28.3,34.7,52.1,34.7h108.7l-28,102.9l167.1-102.9h157.9c24,0,44.4-14.6,52.3-35.1l0.1,0 c0.1-0.3,0.2-0.6,0.3-0.9c0.7-1.9,1.3-3.9,1.8-5.9c18.9-60.4,29.3-128.7,29.3-202.6C576.4,171.3,565.5,101.3,546.3,40.4z M351.5,319.6c27.7,27.7,72.6,27.7,100.3,0l46.8,46.8c-50,50.1-129.2,53.3-183,9.7c-53.8,43.6-133,40.3-183-9.7 c-28.3-28.3-41.7-66-40-103.1V94.8h66.3v52.8c0,0.4,0,0.9,0,1.3v114.3c-1.7,20.1,5.1,40.9,20.5,56.3c26.4,26.4,68.4,27.6,96.3,3.7 c-21.3-50-11.6-110,29.1-150.8c53.5-53.5,140.3-53.5,193.8,0l-46.8,46.8c-27.7-27.7-72.6-27.7-100.3,0 C323.8,246.9,323.8,291.9,351.5,319.6z"/></svg>' ;
126+
127+ // Text displayed in the overlay.
128+ Module [ 'livecodeOverlayText' ] = 'Download this app!' ;
129+
130+ // Initial URL that's launched by the overlay (until the standalone
131+ // has been downloaded)
132+ Module [ 'livecodeOverlayUrl' ] = 'https://livecode.com/' ;
133+
134+ // Before the engine starts, insert the overlay on top of the canvas.
135+ Module [ 'preRun' ] . push ( function ( ) {
136+
137+ // Check if the overlay should be installed
138+ var mode = Module [ 'livecodeOverlay' ] ;
139+ if ( mode === false ) {
140+ return ;
141+ }
142+
143+ // If the overlay is already present, don't recreate it
144+ if ( Module [ 'livecodeOverlayContainer' ] ) {
145+ return ;
146+ }
147+
148+ // Get the canvas. If there's no canvas, there's no overlay
149+ // either.
150+ var canvas = Module [ 'canvas' ] ;
151+ if ( ! canvas ) {
152+ return ;
153+ }
154+
155+ // Insert a new <span> around the canvas. This will be used as a
156+ // common parent for the canvas and the overlay. This is needed
157+ // in order to position the overlay correctly relative to the
158+ // canvas, without making the overlay a child element of the
159+ // canvas (unfortunately, the latter isn't permitted by HTML).
160+ //
161+ // The container needs to have 0 padding, 0 border, 0 margin, and
162+ // position relative (i.e. it should pretend to not exist).
163+ var container = document . createElement ( 'div' ) ;
164+ container . classList . add ( 'emscripten' ) ;
165+ container . style . position = 'relative' ;
166+ Module [ 'livecodeOverlayContainer' ] = container ;
167+
168+ // Move the canvas into the container element.
169+ canvas . parentNode . appendChild ( container ) ;
170+ container . appendChild ( canvas ) ;
171+
172+
173+ var svg = document . createElement ( 'div' ) ;
174+ svg . style . height = '1em' ;
175+ svg . style . width = '1em' ;
176+ svg . style . display = 'inline-block' ;
177+ svg . innerHTML = Module [ 'livecodeOverlayIcon' ] ;
178+
179+ // FIXME internationalise this text
180+ var text = document . createElement ( 'span' ) ;
181+ text . appendChild ( document . createTextNode ( Module [ 'livecodeOverlayText' ] ) ) ;
182+ text . style . display = 'none' ; // Initially invisible
183+ text . style . marginLeft = '1ex' ;
184+ text . style . marginRight = '1ex' ;
185+
186+ var overlay = document . createElement ( 'a' ) ;
187+ overlay . appendChild ( text ) ;
188+ overlay . appendChild ( svg ) ;
189+ overlay . style . position = 'absolute' ;
190+ overlay . style . right = '1px' ;
191+ overlay . style . bottom = '1px' ;
192+ overlay . style . backgroundColor = '#FFFFFF' ;
193+ overlay . style . border = '1px solid #AED036' ;
194+ overlay . style . borderRadius = '5px' ;
195+ overlay . style . padding = '2px' ;
196+ overlay . href = Module [ 'livecodeOverlayUrl' ] ;
197+ overlay . target = '_top' ;
198+
199+ container . appendChild ( overlay ) ;
200+
201+ // Show the text whenever the mouse is over the overlay, as long
202+ // as the standalone has finished downloading.
203+ overlay . addEventListener ( 'mouseover' , function ( ) {
204+ // Update the link target with the standalone's URL, if
205+ // available
206+ if ( Module [ 'livecodeStandaloneUrl' ] ) {
207+ overlay . href = Module [ 'livecodeStandaloneUrl' ] ;
208+ }
209+
210+ text . style . display = 'inline' ;
211+ } ) ;
212+
213+ // Hide the text when the mouse leaves the overlay
214+ overlay . addEventListener ( 'mouseout' , function ( ) {
215+ text . style . display = 'none' ;
216+ } ) ;
217+
218+ } ) ;
0 commit comments