1
1
<!DOCTYPE html>
2
2
< html lang ="en ">
3
-
4
3
< head >
5
4
< meta charset ="utf-8 " />
6
5
< meta name ="viewport " content ="width=device-width, initial-scale=1 " />
9
8
< script src ="./survey.core.js "> </ script >
10
9
< script src ="./survey.i18n.js "> </ script >
11
10
< script src ="./survey-js-ui.js "> </ script >
12
-
13
11
< script src ="./themes/index.js "> </ script >
14
12
< script src ="./creator-themes/index.js "> </ script >
15
-
16
13
< script src ="./survey-creator-core.js "> </ script >
17
14
< script src ="./survey-creator-core.i18n.js "> </ script >
18
15
< script src ="./survey-creator-js.js "> </ script >
19
16
20
-
21
- < link rel ="stylesheet " type ="text/css " href ="./survey-core.css " />
22
- < link rel ="stylesheet " type ="text/css " href ="./survey-creator-core.css " />
23
-
17
+ < link rel ="stylesheet " href ="./survey-core.css " />
18
+ < link rel ="stylesheet " href ="./survey-creator-core.css " />
24
19
</ head >
25
20
26
21
< body >
27
22
< div id ="surveyCreatorContainer " style ="position: fixed; top: 0; left: 0; right: 0; bottom: 0; "> </ div >
23
+
24
+ < script >
25
+ const LOCAL_STORAGE_KEY = "localSurveyJSON" ;
26
+ const SYNCED_FLAG_KEY = "localSurveySynced" ;
27
+
28
+ SurveyCreatorCore . registerCreatorTheme ( SurveyCreatorTheme ) ;
29
+
30
+ const creator = new SurveyCreator . SurveyCreator ( ) ;
31
+
32
+ creator . autoSaveEnabled = true ;
33
+
34
+ const savedJSON = localStorage . getItem ( LOCAL_STORAGE_KEY ) ;
35
+ if ( savedJSON ) {
36
+ try {
37
+ creator . JSON = JSON . parse ( savedJSON ) ;
38
+ } catch ( e ) {
39
+ console . warn ( "Failed to parse saved JSON from localStorage:" , e ) ;
40
+ }
41
+ }
42
+
43
+ creator . saveSurveyFunc = ( saveNo , callback ) => {
44
+ const currentJSON = creator . JSON ;
45
+ localStorage . setItem ( LOCAL_STORAGE_KEY , JSON . stringify ( currentJSON ) ) ;
46
+ localStorage . setItem ( SYNCED_FLAG_KEY , "false" ) ;
47
+ console . log ( "Survey auto-saved locally." ) ;
48
+ callback ( saveNo , true ) ;
49
+ } ;
50
+
51
+ window . addEventListener ( "online" , ( ) => {
52
+ const json = localStorage . getItem ( LOCAL_STORAGE_KEY ) ;
53
+ const isSynced = localStorage . getItem ( SYNCED_FLAG_KEY ) ;
54
+
55
+ if ( json && isSynced !== "true" ) {
56
+ sendToServer ( JSON . parse ( json ) ) ;
57
+ }
58
+ } ) ;
59
+
60
+ function sendToServer ( data ) {
61
+ console . log ( "Syncing with server..." , data ) ;
62
+
63
+ setTimeout ( ( ) => {
64
+ console . log ( "Sync complete." ) ;
65
+ localStorage . setItem ( SYNCED_FLAG_KEY , "true" ) ;
66
+ } , 1000 ) ;
67
+ }
68
+
69
+ creator . render ( "surveyCreatorContainer" ) ;
70
+ </ script >
28
71
</ body >
29
- < script >
30
- SurveyCreatorCore . registerCreatorTheme ( SurveyCreatorTheme ) ; // Add predefined Survey Creator UI themes
31
- var surveyJSON = { } ;
32
- var options = {
33
- showThemeTab : true ,
34
- showTranslationTab : true
35
- } ;
36
- var creator = new SurveyCreator . SurveyCreator ( options ) ;
37
- creator . JSON = surveyJSON ;
38
- creator . render ( "surveyCreatorContainer" ) ;
39
- </ script >
40
-
41
- </ html >
72
+ </ html >
0 commit comments