@@ -145,70 +145,58 @@ var showAlgorithm = function (category, algorithm) {
145145 $ ( '#category' ) . html ( category_name ) ;
146146 $ ( '#algorithm' ) . html ( algorithm_name ) ;
147147 $ ( '#tab_desc > .wrapper' ) . empty ( ) ;
148- $ ( '.files_bar' ) . empty ( ) ;
148+ $ ( '.files_bar > .wrapper ' ) . empty ( ) ;
149149 $ ( '#explanation' ) . html ( '' ) ;
150150 lastFile = null ;
151151 dataEditor . setValue ( '' ) ;
152152 codeEditor . setValue ( '' ) ;
153153} ;
154154var showFiles = function ( category , algorithm , files ) {
155- var maxButtonCount = 3 , fileNames = Object . keys ( files ) , lastFile = - 1 ;
155+ $ ( '.files_bar > .wrapper' ) . empty ( ) ;
156156 var init = false ;
157- var currentFileBarButtons = [ ] ;
158-
159- function addFileButton ( file , explanation ) {
160- var $file = $ ( '<button>' ) . append ( file ) . click ( function ( ) {
161- loadFile ( category , algorithm , file , explanation ) ;
162- $ ( '.files_bar > button' ) . removeClass ( 'active' ) ;
163- $ ( this ) . addClass ( 'active' ) ;
164- } ) ;
165- $ ( '.files_bar' ) . append ( $file ) ;
166- currentFileBarButtons . push ( $file ) ;
167-
168- if ( ! init ) {
169- init = true ;
170- $file . click ( ) ;
171- }
172- }
173-
174- function clearFileBar ( ) {
175- currentFileBarButtons . forEach ( function ( f ) {
176- f . remove ( ) ;
177- } ) ;
157+ for ( var file in files ) {
158+ ( function ( file , explanation ) {
159+ var $file = $ ( '<button>' ) . append ( file ) . click ( function ( ) {
160+ loadFile ( category , algorithm , file , explanation ) ;
161+ $ ( '.files_bar > .wrapper > button' ) . removeClass ( 'active' ) ;
162+ $ ( this ) . addClass ( 'active' ) ;
163+ } ) ;
164+ $ ( '.files_bar > .wrapper' ) . append ( $file ) ;
165+ if ( ! init ) {
166+ init = true ;
167+ $file . click ( ) ;
168+ }
169+ } ) ( file , files [ file ] ) ;
178170 }
179-
180- $ ( '.files_bar' ) . empty ( ) ;
181-
182- var $nextButton = $ ( '<button>' ) . append ( '<b>></b>' ) . addClass ( 'files_bar_right_button' ) . click ( function ( ) {
183- if ( lastFile >= fileNames . length ) {
184- return ;
171+ } ;
172+ $ ( '.files_bar > .button-left' ) . click ( function ( ) {
173+ var $parent = $ ( '.files_bar > .wrapper' ) ;
174+ var clipWidth = $parent . width ( ) ;
175+ var scrollLeft = $parent . scrollLeft ( ) ;
176+ $ ( $parent . children ( 'button' ) . get ( ) . reverse ( ) ) . each ( function ( ) {
177+ var left = $ ( this ) . position ( ) . left ;
178+ var right = left + $ ( this ) . outerWidth ( ) ;
179+ if ( 0 > left ) {
180+ $parent . scrollLeft ( scrollLeft + right - clipWidth ) ;
181+ return false ;
185182 }
186- clearFileBar ( ) ; //first, remove the previously visible buttons
187-
188- init = false ;
189- fileNames . slice ( lastFile + 1 , lastFile + 1 + maxButtonCount ) . forEach ( function ( file ) {
190- file && addFileButton ( file , files [ file ] ) ;
191- } ) ;
192- lastFile += maxButtonCount ;
193183 } ) ;
194- $ ( '.files_bar' ) . append ( $nextButton ) ;
195-
196- var $prevButton = $ ( '<button>' ) . append ( '<b><</b>' ) . addClass ( 'files_bar_left_button' ) . click ( function ( ) {
197- if ( lastFile === maxButtonCount - 1 ) {
198- return ;
184+ } ) ;
185+ $ ( '.files_bar > .button-right' ) . click ( function ( ) {
186+ var $parent = $ ( '.files_bar > .wrapper' ) ;
187+ var clipWidth = $parent . width ( ) ;
188+ var scrollLeft = $parent . scrollLeft ( ) ;
189+ $parent . children ( 'button' ) . each ( function ( ) {
190+ var left = $ ( this ) . position ( ) . left ;
191+ var right = left + $ ( this ) . outerWidth ( ) ;
192+ console . log ( left ) ;
193+ console . log ( right ) ;
194+ if ( clipWidth < right ) {
195+ $parent . scrollLeft ( scrollLeft + left ) ;
196+ return false ;
199197 }
200-
201- clearFileBar ( ) ; //first, remove the previously visible buttons
202- lastFile -= maxButtonCount ;
203- init = false ;
204- fileNames . slice ( lastFile + 1 - maxButtonCount , lastFile + 1 ) . forEach ( function ( file ) {
205- addFileButton ( file , files [ file ] ) ;
206- } ) ;
207198 } ) ;
208- $ ( '.files_bar' ) . append ( $prevButton ) ;
209-
210- $nextButton . click ( ) ; //initialize the file bar with the First 3 Buttons
211- } ;
199+ } ) ;
212200var loadAlgorithm = function ( category , algorithm ) {
213201 if ( checkLoading ( ) ) return ;
214202 showAlgorithm ( category , algorithm ) ;
@@ -497,7 +485,6 @@ var loadScratchPaper = function (gistID) {
497485
498486var gistID = getParameterByName ( 'scratch-paper' ) ;
499487if ( gistID ) {
500- console . log ( gistID ) ;
501488 loadScratchPaper ( gistID ) ;
502489}
503490
0 commit comments