4848 <!-- /.container-fluid -->
4949 </ nav >
5050 < div class ="container ">
51- < div class ="row " id ="needs_margin_top ">
52- < div class ="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12 " id ="bodycontent " style ="border-radius: 10px; ">
51+ < div class ="row " id ="answer_div ">
52+ < div class ="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12 bodycontent " style ="border-radius: 10px; ">
53+ </ div >
54+ </ div >
55+ < div class ="row " id ="course_selection ">
56+ < div class ="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12 bodycontent " style ="border-radius: 10px; ">
5357 < div class ="row ">
5458 < div class ="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-8 col-xs-offset-2 ">
5559 < h1 > Course selection</ h1 >
@@ -85,9 +89,9 @@ <h1>Course selection</h1>
8589 </ div >
8690 </ div >
8791 < footer class ="footer ">
88- < div class ="container ">
89- < p class ="text-muted text-center "> < small > © 2015 SubjectRefresh.info | All Rights Reserved< br > By using this site, you agree to our use of cookies.</ small > </ p >
90- </ div >
92+ < div class ="container ">
93+ < p class ="text-muted text-center "> < small > © 2015 SubjectRefresh.info | All Rights Reserved< br > By using this site, you agree to our use of cookies.</ small > </ p >
94+ </ div >
9195 </ footer >
9296</ body >
9397< script type ="text/javascript ">
@@ -96,6 +100,9 @@ <h1>Course selection</h1>
96100}
97101
98102function updateSubjects ( ) {
103+ $ ( "#selectSubject" ) . find ( 'option' ) . remove ( ) ;
104+ $ ( "#selectSyllabus" ) . find ( 'option' ) . remove ( ) ;
105+
99106 var examBoardBuffer = document . getElementById ( "selectBoard" ) ;
100107 var examBoard = examBoardBuffer . options [ examBoardBuffer . selectedIndex ] . value ;
101108 $ . post ( examBoard ) . success ( function ( data ) {
@@ -114,6 +121,8 @@ <h1>Course selection</h1>
114121}
115122
116123function updateSyllabus ( i_n ) {
124+ $ ( "#selectSyllabus" ) . find ( 'option' ) . remove ( ) ;
125+
117126 var examBoardBuffer = document . getElementById ( "selectBoard" ) ;
118127 var examBoard = examBoardBuffer . options [ examBoardBuffer . selectedIndex ] . value ;
119128 $ . post ( examBoard + "Subject" , {
@@ -131,10 +140,29 @@ <h1>Course selection</h1>
131140 } ) ;
132141}
133142
134- var data = [ ] ;
143+ var not_duplicated = [ ] ;
144+ var answers = [ ] ;
145+
146+ function shuffle ( array ) {
147+ var currentIndex = array . length , temporaryValue , randomIndex ;
148+
149+ // While there remain elements to shuffle...
150+ while ( 0 !== currentIndex ) {
151+
152+ // Pick a remaining element...
153+ randomIndex = Math . floor ( Math . random ( ) * currentIndex ) ;
154+ currentIndex -= 1 ;
155+
156+ // And swap it with the current element.
157+ temporaryValue = array [ currentIndex ] ;
158+ array [ currentIndex ] = array [ randomIndex ] ;
159+ array [ randomIndex ] = temporaryValue ;
160+ }
161+
162+ return array ;
163+ }
135164
136165function goGetQuestion ( i_n ) {
137- console . log ( "Submitting..." ) ;
138166 var examBoardBuffer = document . getElementById ( "selectBoard" ) ;
139167 var examBoard = examBoardBuffer . options [ examBoardBuffer . selectedIndex ] . value ;
140168
@@ -159,11 +187,22 @@ <h1>Course selection</h1>
159187 "syllabus" : syllabus ,
160188 "url" : i_n
161189 } ) . success ( function ( newData ) {
162- data = newData ;
163- console . log ( data ) ;
164- for ( var i = 0 ; i < 5 ; i ++ ) {
165- console . log ( data [ 0 ] [ i ] ) ;
190+ for ( i = 0 ; i < newData [ 0 ] . length - 1 ; i ++ ) {
191+ if ( newData [ 0 ] [ i ] [ 0 ] . split ( ' ' ) . length == 1 ) {
192+ not_duplicated . push ( newData [ 0 ] [ i ] [ 0 ] ) ;
193+ }
194+ }
195+ for ( var i = 1 ; i < 5 ; i ++ ) {
196+ var answer = newData [ 0 ] [ i ] [ 0 ] ;
197+ if ( not_duplicated . indexOf ( answer ) > - 1 ) {
198+ answers . push ( answer ) ;
199+ var replace_with_this = "<input class='form-control' answer='" + answer + "' type='text' size='" + ( answer . length + 2 ) + "' style='display:inline-block;'>"
200+ console . log ( "Replacing answer " + answer + " with " + replace_with_this ) ;
201+ newData [ 1 ] = newData [ 1 ] . replace ( answer , replace_with_this ) ;
202+ }
166203 }
204+ //answers = shuffle(answers); // not sure if this works or not
205+ $ ( "#answer_div" ) . find ( ".bodycontent" ) . html ( answers . join ( ", " ) + "<hr>" + newData [ 1 ] ) ;
167206 } ) ;
168207}
169208
@@ -184,4 +223,5 @@ <h1>Course selection</h1>
184223 return false ;
185224} ) ;
186225</ script >
226+
187227</ html >
0 commit comments