@@ -59,10 +59,9 @@ export function saveAsTemplate(stage: Stage) {
59
59
*/
60
60
confirm ( name : string , createdFor : string ) {
61
61
return new Promise ( ( resolve , reject ) => {
62
- // Retrieve the rendering lock from the stage
62
+ // Wait for the screenshot and the rendering lock to complete before making the request
63
63
const renderingLock = stage . renderingLocks [ stage . renderingLocks . length - 1 ] ;
64
64
65
- // Wait for the screenshot and the rendering lock to complete before making the request
66
65
$ . when ( capture , renderingLock ) . then ( ( imageSrc : string , content : string ) => {
67
66
$ . ajax ( {
68
67
url : Config . getConfig ( "template_save_url" ) ,
@@ -134,43 +133,48 @@ function createCapture(stage: Stage) {
134
133
const stageElement = document . querySelector ( "#" + stage . id ) as HTMLElement ;
135
134
const deferred = $ . Deferred ( ) ;
136
135
137
- // Resolve issues with Parallax
138
- const parallaxRestore = disableParallax ( stageElement ) ;
139
-
140
- stageElement . style . height = $ ( stageElement ) . outerHeight ( false ) + "px" ;
141
- stageElement . classList . add ( "capture" ) ;
142
- stageElement . classList . add ( "interacting" ) ;
136
+ // Wait for the stage to complete rendering before taking the capture
137
+ const renderingLock = stage . renderingLocks [ stage . renderingLocks . length - 1 ] ;
138
+ renderingLock . then ( ( ) => {
139
+ // Resolve issues with Parallax
140
+ const parallaxRestore = disableParallax ( stageElement ) ;
141
+
142
+ stageElement . style . height = $ ( stageElement ) . outerHeight ( false ) + "px" ;
143
+ stageElement . classList . add ( "capture" ) ;
144
+ stageElement . classList . add ( "interacting" ) ;
145
+
146
+ if ( stage . pageBuilder . isFullScreen ( ) ) {
147
+ window . scrollTo ( {
148
+ top : 0 ,
149
+ } ) ;
150
+ }
151
+
152
+ _ . defer ( ( ) => {
153
+ html2canvas (
154
+ document . querySelector ( "#" + stage . id + " .pagebuilder-canvas" ) ,
155
+ {
156
+ scale : 1 ,
157
+ useCORS : true ,
158
+ scrollY : ( window . pageYOffset * - 1 ) ,
159
+ } ,
160
+ ) . then ( ( canvas : HTMLCanvasElement ) => {
161
+ const imageSrc = canvas . toDataURL ( "image/jpeg" , 0.85 ) ;
162
+
163
+ deferred . resolve ( imageSrc ) ;
164
+
165
+ if ( stage . pageBuilder . isFullScreen ( ) ) {
166
+ window . scrollTo ( {
167
+ top : scrollY ,
168
+ } ) ;
169
+ }
143
170
144
- if ( stage . pageBuilder . isFullScreen ( ) ) {
145
- window . scrollTo ( {
146
- top : 0 ,
171
+ stageElement . style . height = null ;
172
+ stageElement . classList . remove ( "capture" ) ;
173
+ stageElement . classList . remove ( "interacting" ) ;
174
+ restoreParallax ( parallaxRestore ) ;
175
+ } ) ;
147
176
} ) ;
148
- }
149
177
150
- _ . defer ( ( ) => {
151
- html2canvas (
152
- document . querySelector ( "#" + stage . id + " .pagebuilder-canvas" ) ,
153
- {
154
- scale : 1 ,
155
- useCORS : true ,
156
- scrollY : ( window . pageYOffset * - 1 ) ,
157
- } ,
158
- ) . then ( ( canvas : HTMLCanvasElement ) => {
159
- const imageSrc = canvas . toDataURL ( "image/jpeg" , 0.85 ) ;
160
-
161
- deferred . resolve ( imageSrc ) ;
162
-
163
- if ( stage . pageBuilder . isFullScreen ( ) ) {
164
- window . scrollTo ( {
165
- top : scrollY ,
166
- } ) ;
167
- }
168
-
169
- stageElement . style . height = null ;
170
- stageElement . classList . remove ( "capture" ) ;
171
- stageElement . classList . remove ( "interacting" ) ;
172
- restoreParallax ( parallaxRestore ) ;
173
- } ) ;
174
178
} ) ;
175
179
176
180
return deferred ;
0 commit comments