@@ -27,18 +27,19 @@ function get_challenge(id){
27
27
28
28
29
29
function load_challenge_preview ( id ) {
30
- var chal = get_challenge ( id ) ;
31
- var modal_template = chal . type_data . templates . modal ;
32
- var modal_script = chal . type_data . scripts . modal ;
30
+ loadchal ( id , function ( ) {
31
+ var chal = get_challenge ( id ) ;
32
+ var modal_template = chal . type_data . templates . modal ;
33
+ var modal_script = chal . type_data . scripts . modal ;
33
34
34
- render_challenge_preview ( chal , modal_template , modal_script )
35
+ render_challenge_preview ( chal , modal_template , modal_script ) ;
36
+ } ) ;
35
37
}
36
38
37
39
function render_challenge_preview ( chal , modal_template , modal_script ) {
38
40
var preview_window = $ ( '#challenge-preview' ) ;
39
41
$ . get ( script_root + modal_template , function ( template_data ) {
40
42
preview_window . empty ( ) ;
41
- console . log ( chal . description ) ;
42
43
var template = nunjucks . compile ( template_data ) ;
43
44
var data = {
44
45
id : chal . id ,
@@ -47,7 +48,8 @@ function render_challenge_preview(chal, modal_template, modal_script){
47
48
tags : chal . tags ,
48
49
desc : chal . description ,
49
50
files : chal . files ,
50
- hints : chal . hints
51
+ hints : chal . hints ,
52
+ script_root : script_root
51
53
} ;
52
54
53
55
var challenge = template . render ( data ) ;
@@ -61,14 +63,31 @@ function render_challenge_preview(chal, modal_template, modal_script){
61
63
}
62
64
63
65
66
+ function loadchal ( chalid , cb ) {
67
+ $ . get ( script_root + "/admin/chal/" + chalid , {
68
+ } , function ( data ) {
69
+ var categories = [ ] ;
70
+ var challenge = $ . parseJSON ( JSON . stringify ( data ) ) ;
71
+
72
+ for ( var i = challenges [ 'game' ] . length - 1 ; i >= 0 ; i -- ) {
73
+ if ( challenges [ 'game' ] [ i ] [ 'id' ] == challenge . id ) {
74
+ challenges [ 'game' ] [ i ] = challenge
75
+ }
76
+ }
77
+
78
+ if ( cb ) {
79
+ cb ( ) ;
80
+ }
81
+ } ) ;
82
+ }
83
+
64
84
function loadchals ( cb ) {
65
85
$ . post ( script_root + "/admin/chals" , {
66
86
'nonce' : $ ( '#nonce' ) . val ( )
67
87
} , function ( data ) {
68
88
var categories = [ ] ;
69
89
challenges = $ . parseJSON ( JSON . stringify ( data ) ) ;
70
90
71
-
72
91
for ( var i = challenges [ 'game' ] . length - 1 ; i >= 0 ; i -- ) {
73
92
if ( $ . inArray ( challenges [ 'game' ] [ i ] . category , categories ) == - 1 ) {
74
93
categories . push ( challenges [ 'game' ] [ i ] . category )
@@ -90,6 +109,29 @@ loadchals(function(){
90
109
} ) ;
91
110
} ) ;
92
111
112
+ function loadhint ( hintid ) {
113
+ ezq ( {
114
+ title : "Unlock Hint?" ,
115
+ body : "Are you sure you want to open this hint?" ,
116
+ success : function ( ) {
117
+ $ . post ( script_root + "/hints/" + hintid , { 'nonce' : $ ( '#nonce' ) . val ( ) } , function ( data ) {
118
+ if ( data . errors ) {
119
+ ezal ( {
120
+ title : "Error!" ,
121
+ body : data . errors ,
122
+ button : "Okay"
123
+ } ) ;
124
+ } else {
125
+ ezal ( {
126
+ title : "Hint" ,
127
+ body : marked ( data . hint , { 'gfm' : true , 'breaks' : true } ) ,
128
+ button : "Got it!"
129
+ } ) ;
130
+ }
131
+ } ) ;
132
+ }
133
+ } ) ;
134
+ }
93
135
94
136
function submitkey ( chal , key , nonce ) {
95
137
$ . post ( script_root + "/admin/chal/" + chal , {
0 commit comments