@@ -11,6 +11,8 @@ function addLine(type){
1111 $ ( "#" + type + nbrLine ) . attr ( "id" , type + newNbrLine )
1212 if ( type == "output" ) {
1313 $ ( "#" + type + newNbrLine + " .swicher" ) . attr ( "onchange" , "swichOutputMode(" + newNbrLine + ")" )
14+ } else if ( type == "process" ) {
15+ $ ( "#" + type + newNbrLine + " .element-adder" ) . attr ( "onclick" , "addProcessElement(" + newNbrLine + ")" )
1416 }
1517 $ ( "#" + type + newNbrLine ) . append ( '<button onclick="delLastLine(\'' + type + '\')" class="button-control remove-button">×</button>' )
1618 if ( type == 'var' ) {
@@ -82,9 +84,16 @@ function writeCode(){
8284 }
8385 //Process
8486 for ( var i = getLinesNumber ( "process" ) ; i >= 1 ; i -- ) { //Foreach process element
85- if ( $ ( "#process" + i + " input" ) . val ( ) && $ ( "#process" + i + " input" ) . val ( ) != '' && $ ( "#process" + i + " select" ) . val ( ) != null ) {
87+ if ( $ ( "#process" + i + " input" ) . val ( ) && $ ( "#process" + i + " input" ) . val ( ) != '' ) {
8688 CodeMirrorInstance . setValue (
87- CodeMirrorInstance . getValue ( ) + $ ( '#process' + i + ' select' ) . val ( ) + " = " + $ ( '#process' + i + ' input' ) . val ( ) + " \n" ) // To improve
89+ CodeMirrorInstance . getValue ( ) + $ ( '#process' + i + ' select' ) . val ( ) + " = " ) // To improve
90+ for ( var j = 0 ; j < $ ( "#process" + i + " .process-element" ) . length ; j ++ ) {
91+ $ ( $ ( "#process" + i + " .process-element" ) [ j ] )
92+ CodeMirrorInstance . setValue (
93+ CodeMirrorInstance . getValue ( ) + $ ( $ ( "#process" + i + " .process-element" ) [ j ] ) . val ( ) )
94+ }
95+ CodeMirrorInstance . setValue (
96+ CodeMirrorInstance . getValue ( ) + "\n" )
8897 }
8998 }
9099 //Output
@@ -112,6 +121,39 @@ function toggleMenu(){
112121 left : parseInt ( $ ( "nav" ) . css ( 'left' ) , 10 ) == 0 ? - $ ( "nav" ) . outerWidth ( ) : 0
113122 } ) ;
114123}
124+ function deleteIfNull ( list ) {
125+ console . log ( list . val ( ) )
126+ if ( list . val ( ) == "" ) {
127+ if ( list . next ( ) . is ( "input" ) ) {
128+ list . next ( ) . remove ( )
129+ }
130+ list . remove ( )
131+ }
132+ }
133+ function checkVariable ( input ) {
134+ if ( ! ( getValues ( "var" , "input" ) . includes ( input . val ( ) ) ) && isNaN ( input . val ( ) ) && input . val ( ) != "" ) {
135+ input . css ( {
136+ color :"red" ,
137+ fontWeight : "bold"
138+ } ) ;
139+ }
140+ else {
141+ input . css ( {
142+ color :"black" ,
143+ fontWeight : "normal"
144+ } ) ;
145+ }
146+
147+ }
148+ function addProcessElement ( id ) {
149+ var lastElement = $ ( last_of_array ( $ ( ".process-element" ) ) )
150+ if ( lastElement . is ( "select" ) ) {
151+ $ ( '<input type="text" name="calculus" class="form-control short process-element" onchange="writeCode(); checkVariable($(this))">' ) . insertBefore ( "#process" + id + " .element-adder" ) ;
152+ } else {
153+ $ ( '<select class="form-control process-element" onchange="writeCode(); deleteIfNull($(this))"><option value=""></option><option value="+">+</option><option value="-">-</option><option value="*">×</option><option value="/">÷</option></select>'
154+ ) . insertBefore ( "#process" + id + " .element-adder" ) ;
155+ }
156+ }
115157$ ( function ( ) {
116158 setVariableLists ( ) ;
117159 writeCode ( ) ;
@@ -133,4 +175,6 @@ $( window ).scroll(function() {
133175 top : $ ( "header" ) . outerHeight ( ) - $ ( window ) . scrollTop ( ) //Makes the menu stick the header
134176 } )
135177 }
136- } ) ;
178+ } ) ;
179+
180+ function last_of_array ( array ) { return array [ array . length - 1 ] }
0 commit comments