@@ -51,8 +51,7 @@ var View = /** @class */ (function () {
5151 } ( index ) ;
5252 manager . addEvent ( new FrontendEvent ( forward , forward , this . animSpeed ) ) ;
5353 } ;
54- View . prototype . setValueAtThisIndex = function ( i , bValue ) {
55- var val = $ ( "#arrayElem" + i ) . text ( ) ;
54+ View . prototype . setValueAtThisIndex = function ( i , bValue , oldVal ) {
5655 var forwardSteps = function ( i , bValue ) {
5756 return function ( ) {
5857 setValueAtIndex ( i , bValue ) ;
@@ -62,7 +61,7 @@ var View = /** @class */ (function () {
6261 return function ( ) {
6362 setValueAtIndex ( i , oldVal ) ;
6463 } ;
65- } ( i , val ) ;
64+ } ( i , oldVal ) ;
6665 manager . addEvent ( new FrontendEvent ( forwardSteps , backwardSteps , this . animSpeed ) ) ;
6766 } ;
6867 View . prototype . setValueAtThisSortIndex = function ( i , bValue ) {
@@ -73,7 +72,7 @@ var View = /** @class */ (function () {
7372 } ( i , bValue ) ;
7473 var backwardSteps = function ( i , bValue ) {
7574 return function ( ) {
76- setValueAtSortIndex ( i , i ) ;
75+ setValueAtSortIndex ( i , "" ) ;
7776 } ;
7877 } ( i , bValue ) ;
7978 manager . addEvent ( new FrontendEvent ( forwardSteps , backwardSteps , this . animSpeed ) ) ;
@@ -97,22 +96,45 @@ var View = /** @class */ (function () {
9796 highlightNode ( index , color ) ;
9897 } ;
9998 } ( index , color ) ;
100- manager . addEvent ( new FrontendEvent ( forward , forward , this . animSpeed ) ) ;
99+ var backward = function ( index ) {
100+ return function ( ) {
101+ removeHighlight ( index ) ;
102+ } ;
103+ } ( index ) ;
104+ manager . addEvent ( new FrontendEvent ( forward , backward , this . animSpeed ) ) ;
101105 } ;
102106 View . prototype . highlightThisSortElem = function ( index , color ) {
103107 var forward = function ( index , color ) {
104108 return function ( ) {
105109 sortHighlightElem ( index , color ) ;
106110 } ;
107111 } ( index , color ) ;
108- manager . addEvent ( new FrontendEvent ( forward , forward , this . animSpeed ) ) ;
112+ var backward = function ( index ) {
113+ return function ( ) {
114+ removeSortHighlight ( index ) ;
115+ } ;
116+ } ( index ) ;
117+ manager . addEvent ( new FrontendEvent ( forward , backward , this . animSpeed ) ) ;
109118 } ;
110119 View . prototype . removeThisHighlight = function ( index ) {
120+ // Find the current color
121+ var color = "" ;
122+ var classList = document . getElementById ( 'arrayElem' + index ) . className . split ( / \s + / ) ;
123+ for ( var i = 0 ; i < classList . length ; i ++ ) {
124+ if ( classList [ i ] === 'orange' || classList [ i ] === 'green' ) {
125+ color = classList [ i ] ;
126+ }
127+ }
111128 var forward = function ( index ) {
112129 return function ( ) {
113130 removeHighlight ( index ) ;
114131 } ;
115132 } ( index ) ;
133+ var backward = function ( index , color ) {
134+ return function ( ) {
135+ highlightNode ( index , color ) ;
136+ } ;
137+ } ( index , color ) ;
116138 manager . addEvent ( new FrontendEvent ( forward , forward , this . animSpeed ) ) ;
117139 } ;
118140 View . prototype . setThisState = function ( relationships , backendArray ) {
@@ -122,7 +144,10 @@ var View = /** @class */ (function () {
122144 this . step ( "backward" , twoDimRelationshipsJSON , backendArray ) ;
123145 } ;
124146 View . prototype . stepForward = function ( twoDimRelationshipsJSON , backendArray ) {
125- this . step ( "forward" , twoDimRelationshipsJSON , backendArray ) ;
147+ //this.step("forward", twoDimRelationshipsJSON, backendArray);
148+ manager . next ( ) ;
149+ if ( manager . nextEvents . length <= 0 )
150+ manager . start ( ) ;
126151 } ;
127152 View . prototype . step = function ( dir , twoDimRelationshipsJSON , backendArray ) {
128153 var relationships = JSON . parse ( twoDimRelationshipsJSON ) ;
@@ -161,7 +186,12 @@ var View = /** @class */ (function () {
161186 screenLock ( lock ) ;
162187 } ;
163188 } ( locked ) ;
164- manager . addEvent ( new FrontendEvent ( lck , lck , this . animSpeed ) ) ;
189+ var notLck = function ( lock ) {
190+ return function ( ) {
191+ screenLock ( ! lock ) ;
192+ } ;
193+ } ( locked ) ;
194+ manager . addEvent ( new FrontendEvent ( lck , notLck , this . animSpeed ) ) ;
165195 } ;
166196 View . prototype . setSlow = function ( ) {
167197 this . animSpeed = 250 ;
@@ -257,11 +287,16 @@ var View = /** @class */ (function () {
257287 removeElem ( index , removeArr ) ;
258288 } ;
259289 } ( i , removeArr ) ;
260- var backward = function ( index , val ) {
290+ var backward = function ( index , value , parent ) {
261291 return function ( ) {
262- insertNewElem ( index , val ) ;
292+ setValueAtIndex ( index , value ) ;
293+ insertNewNode ( index , value ) ;
294+ insertNewElemConnect ( index , parent ) ;
295+ // If first node -> Position with a nice animation
296+ if ( control . getAlgorithm ( ) . getArrayLength ( ) == 1 )
297+ positioningNodes ( 1500 ) ;
263298 } ;
264- } ( i , val ) ;
299+ } ( i , val , Math . floor ( ( i - 1 ) / 2 ) ) ;
265300 manager . addEvent ( new FrontendEvent ( forward , backward , manager . delayTime ) ) ;
266301 } ;
267302 View . prototype . play = function ( ) {
@@ -271,37 +306,63 @@ var View = /** @class */ (function () {
271306 this . paused = true ;
272307 this . playing = true ;
273308 $ ( "#play" ) . text ( "Pause" ) ;
309+ lockBackForward ( true ) ;
274310 }
275311 else if ( algo === "HeapSort" && ! this . paused && ! this . playing ) {
276312 control . getAlgorithm ( ) . sort ( ) ;
277313 this . paused = true ;
278314 this . playing = true ;
279315 $ ( "#play" ) . text ( "Pause" ) ;
316+ lockBackForward ( true ) ;
280317 }
281318 else {
282319 if ( this . playing ) {
283320 manager . pause ( ) ;
284321 $ ( "#play" ) . text ( "Resume" ) ;
285322 this . playing = false ;
323+ lockBackForward ( false ) ;
286324 }
287325 else {
288326 this . playing = true ;
289327 manager . start ( ) ;
290328 $ ( "#play" ) . text ( "Pause" ) ;
329+ lockBackForward ( true ) ;
291330 }
292331 }
293332 } ;
333+ // Used in eventmanager for freemode and predefined
334+ View . prototype . playButtonState = function ( ) {
335+ var algo = control . getAlgorithm ( ) . getName ( ) ;
336+ if ( ! ( algo === "MaxHeap" || algo === "MaxHeapFree" || this . playing ) )
337+ return ;
338+ if ( manager . nextEvents . length > 0 ) {
339+ this . playing = true ;
340+ lockPlay ( false ) ;
341+ lockBackForward ( true ) ;
342+ $ ( "#play" ) . text ( "Pause" ) ;
343+ }
344+ else {
345+ lockPlay ( true ) ;
346+ lockBackForward ( false ) ;
347+ }
348+ } ;
294349 View . prototype . insertNewElemThis = function ( child , value , parent ) {
295350 var forward = function ( index , value , parent ) {
296351 return function ( ) {
297- insertNewElem ( index , value ) ;
352+ setValueAtIndex ( index , value ) ;
353+ insertNewNode ( index , value ) ;
298354 insertNewElemConnect ( index , parent ) ;
355+ // If first node -> Position with a nice animation
356+ if ( control . getAlgorithm ( ) . getArrayLength ( ) == 1 )
357+ positioningNodes ( 1500 ) ;
299358 } ;
300359 } ( child , value , parent ) ;
301360 var backward = function ( index , parent ) {
302361 return function ( ) {
303362 allNodes [ parent ] . removeChild ( allNodes [ index ] ) ;
304- removeElem ( index , true ) ;
363+ //removeElem(index, true);
364+ setValueAtIndex ( index , "" ) ;
365+ removeNode ( index ) ;
305366 } ;
306367 } ( child , parent ) ;
307368 manager . addEvent ( new FrontendEvent ( forward , backward , manager . delayTime ) ) ;
0 commit comments