var counter_new_functions = 0; function addFunctionHandler() { new_function = new Funcao("new_function_" + counter_new_functions); adicionarFuncao(new_function); counter_new_functions ++; renderAlgorithm(); } function updateSequenceFunctionHandler(index_from, index_to) { programa.funcoes.splice(index_to, 0, programa.funcoes.splice(index_from, 1)[0]); renderAlgorithm(); } function removeFunctionHandler(div_function, sequence) { programa.funcoes.splice(sequence, 1); $(div_function).slideUp(400, function(){ renderAlgorithm(); }); } function minimizeFunctionHandler(div_function, sequence) { $(div_function).find(".function_area").toggle(); programa.funcoes[sequence].esta_oculta = !programa.funcoes[sequence].esta_oculta; } function renderAlgorithm() { $('.all_functions').empty(); for (i = 0; i < programa.funcoes.length; i++) { appendFunction(programa.funcoes[i], i); } $('.data_types_dropdown').dropdown(); } function updateFunctionReturn(sequence, new_value) { programa.funcoes[sequence].tipo_retorno = new_value; } var opened_name_function = false; var opened_input = null; var sequence_name_opened; function enableNameFunctionUpdate(div_el, sequence) { if (opened_name_function) { $(opened_input).focus(); return; } opened_name_function = true; sequence_name_opened = sequence; $(div_el).find('.span_name_function').text(''); $( "" ).insertBefore($(div_el).find('.span_name_function')); $('.width-dynamic').on('input', function() { var inputWidth = $(this).textWidth()+10; opened_input = this; $(this).focus(); var tmpStr = $(this).val(); $(this).val(''); $(this).val(tmpStr); $(this).css({ width: inputWidth }) }).trigger('input'); $('.width-dynamic').focusout(function() { /// update array: if ($(this).val().trim()) { programa.funcoes[sequence_name_opened].nome = $(this).val().trim(); } $(this).remove(); /// update elements: opened_name_function = false; opened_input = false; renderAlgorithm(); }); $('.width-dynamic').on('keydown', function(e) { var code = e.keyCode || e.which; if(code == 13) { if ($(this).val().trim()) { programa.funcoes[sequence_name_opened].nome = $(this).val().trim(); } $(this).remove(); /// update elements: opened_name_function = false; opened_input = false; renderAlgorithm(); } }); } function appendFunction(function_obj, sequence) { $('.all_functions').append('
' + '' + (!function_obj.eh_principal ? '' : '') + '' + '
function ' + '' + '
'+function_obj.nome+'
( ) {
' + (function_obj.esta_oculta ? ''); } $.fn.textWidth = function(text, font) { if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('').hide().appendTo(document.body); $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font')); return $.fn.textWidth.fakeEl.width(); };