123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939 |
- import $ from 'jquery';
- import jQuery from 'jquery';
- import { Types } from './types';
- import * as Models from './ivprog_elements';
- import { LocalizedStrings } from './../services/localizedStringsService';
- window.jQuery = jQuery;
- import '../semantic/semantic.min.js';
- var counter_new_globals = 0;
- export function addGlobal(program, is_from_click = false) {
- var new_global = new Models.Variable(Types.INTEGER, LocalizedStrings.getUI('new_global') + '_' + counter_new_globals, 1);
- counter_new_globals++;
- program.addGlobal(new_global);
- var newe = renderGlobal(new_global);
- if (is_from_click) {
- newe.css('display', 'none');
- newe.fadeIn();
- }
- }
- function toggleConstant(global_var) {
- global_var.is_constant = !global_var.is_constant;
- }
- function updateName(global_var, new_name) {
- global_var.name = new_name;
- }
- function updateType(global_var, new_type, new_dimensions = 0) {
- global_var.type = new_type;
- global_var.dimensions = new_dimensions;
- if (new_dimensions > 0) {
- global_var.rows = new_dimensions;
- global_var.columns = 2;
- }
- updateInitialValues(global_var);
- }
- function removeGlobal(global_var, global_container) {
- var index = window.program_obj.globals.indexOf(global_var);
- if (index > -1) {
- window.insertContext = true;
- window.program_obj.globals.splice(index, 1);
- }
- global_container.children().off();
- global_container.off();
- global_container.fadeOut();
- }
- function updateInitialValues(global_var) {
- if (global_var.type == Types.INTEGER) {
- if (global_var.dimensions == 0) {
- global_var.value = 1;
- }
- if (global_var.dimensions == 1) {
- global_var.value = [1, 1];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[1, 1], [1, 1]];
- }
- }
- if (global_var.type == Types.REAL) {
- if (global_var.dimensions == 0) {
- global_var.value = 1.0;
- }
- if (global_var.dimensions == 1) {
- global_var.value = [1.0, 1.0];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[1.0, 1.0], [1.0, 1.0]];
- }
- }
- if (global_var.type == Types.TEXT) {
- if (global_var.dimensions == 0) {
- global_var.value = LocalizedStrings.getUI('text_start');
- }
- if (global_var.dimensions == 1) {
- global_var.value = [LocalizedStrings.getUI('text_start'), LocalizedStrings.getUI('text_start')];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[LocalizedStrings.getUI('text_start'), LocalizedStrings.getUI('text_start')],
- [LocalizedStrings.getUI('text_start'), LocalizedStrings.getUI('text_start')]];
- }
- }
- if (global_var.type == Types.BOOLEAN) {
- if (global_var.dimensions == 0) {
- global_var.value = true;
- }
- if (global_var.dimensions == 1) {
- global_var.value = [true, true];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[true, true], [true, true]];
- }
- }
- }
- function alternateBooleanGlobalValue(global_var, value_container) {
- global_var.value = !global_var.value;
- $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(global_var.value));
- }
- function alternateBooleanGlobalVectorValue(global_var, index, value_container) {
- global_var.value[index] = !global_var.value[index];
- $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(global_var.value[index]));
- }
- function removeGlobalColumnVector(global_var) {
- if (global_var.columns == 0) {
- return;
- }
- global_var.columns--;
- global_var.value.splice(global_var.value.length - 1, 1);
- }
- function addGlobalColumnVector(global_var) {
- global_var.columns++;
- if (global_var.type == Types.INTEGER) {
- global_var.value.push(1);
- }
- if (global_var.type == Types.REAL) {
- global_var.value.push(1.0);
- }
- if (global_var.type == Types.TEXT) {
- global_var.value.push(LocalizedStrings.getUI('text_start'));
- }
- if (global_var.type == Types.BOOLEAN) {
- global_var.value.push(true);
- }
- }
- function removeColumnGlobalMatrix(global_var) {
- if (global_var.columns == 0) {
- return;
- }
- global_var.columns--;
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].splice(global_var.value[i].length - 1, 1);
- }
- }
- function addColumnGlobalMatrix(global_var) {
- global_var.columns++;
- if (global_var.type == Types.INTEGER) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(1);
- }
- }
- if (global_var.type == Types.REAL) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(1.0);
- }
- }
- if (global_var.type == Types.TEXT) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(LocalizedStrings.getUI('text_start'));
- }
- }
- if (global_var.type == Types.BOOLEAN) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(true);
- }
- }
- }
- function removeLineGlobalMatrix(global_var) {
- if (global_var.rows == 0) {
- return;
- }
- global_var.rows--;
- global_var.value.splice(global_var.value.length - 1, 1);
- }
- function addLineGlobalMatrix(global_var) {
- global_var.rows++;
- if (global_var.type == Types.INTEGER) {
- var n_l = [];
- for (var i = 0; i < global_var.columns; i++) {
- n_l.push(1);
- }
- global_var.value.push(n_l);
- }
- if (global_var.type == Types.REAL) {
- var n_l = [];
- for (i = 0; i < global_var.columns; i++) {
- n_l.push(1.0);
- }
- global_var.value.push(n_l);
- }
- if (global_var.type == Types.TEXT) {
- var n_l = [];
- for (i = 0; i < global_var.columns; i++) {
- n_l.push(LocalizedStrings.getUI('text_start'));
- }
- global_var.value.push(n_l);
- }
- if (global_var.type == Types.BOOLEAN) {
- var n_l = [];
- for (i = 0; i < global_var.columns; i++) {
- n_l.push(true);
- }
- global_var.value.push(n_l);
- }
- }
- function alternateBooleanGlobalMatrixValue(global_var, row, index, value_container) {
- global_var.value[row][index] = !global_var.value[row][index];
- $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(global_var.value[row][index]));
- }
- function renderValues(global_var, global_container) {
- var ret = "";
- var j = 0;
- if (global_var.dimensions == 0) {
- if (global_var.type == Types.REAL) {
- ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">' + global_var.value.toFixed(1) + '</span> </div> ';
- } else {
- if (global_var.type == Types.BOOLEAN) {
- ret += '<div class="created_div_valor_var"><span class="span_value_variable boolean_simple_type">' + LocalizedStrings.getUI(global_var.value) + '</span> </div> ';
- } else {
- ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">' + global_var.value + '</span> </div> ';
- }
- }
- } else {
- ret += '<table class="tabela_var">';
- if (global_var.dimensions == 1) {
- ret += '<tr>';
- if (global_var.type == Types.REAL) {
- for (var k = 0; k < global_var.columns; k++) {
- ret += '<td><span class="span_value_variable vector_var" data-index="' + k + '">' + global_var.value[k].toFixed(1) + '</span></td>';
- }
- } else {
- for (var k = 0; k < global_var.columns; k++) {
- if (global_var.type == Types.BOOLEAN) {
- ret += '<td><span class="span_value_variable boolean_vector_var" data-index="' + k + '">' + LocalizedStrings.getUI(global_var.value[k]) + '</span></td>';
- } else {
- ret += '<td><span class="span_value_variable vector_var" data-index="' + k + '">' + global_var.value[k] + '</span>' + '</td>';
- }
- }
- }
- ret += '</tr>';
- ret += '</table>';
- ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline remove_global_vector_column"></i>'
- + ' <i class="ui icon plus square outline add_global_vector_column"></i></div>';
- }
- if (global_var.dimensions == 2) {
- if (global_var.type == Types.REAL) {
- for (var l = 0; l < global_var.rows; l++) {
- ret += '<tr>';
- for (var k = 0; k < global_var.columns; k++) {
- ret += '<td><span class="span_value_variable matrix_var" data-index="' + k + '" data-row="' + l + '">' + global_var.value[l][k].toFixed(1) + '</span>' + '</td>';
- }
- ret += '</tr>';
- }
- } else {
- for (var l = 0; l < global_var.rows; l++) {
- ret += '<tr>';
- for (var k = 0; k < global_var.columns; k++) {
- if (global_var.type == Types.BOOLEAN) {
- ret += '<td><span class="span_value_variable boolean_matrix_var" data-index="' + k + '" data-row="' + l + '">' + LocalizedStrings.getUI(global_var.value[l][k]) + '</span></td>';
- } else {
- ret += '<td><span class="span_value_variable matrix_var" data-index="' + k + '" data-row="' + l + '">' + global_var.value[l][k] + '</span></td>';
- }
- }
- ret += '</tr>';
- }
- }
- if (global_var.rows == 0) {
- ret += '<tr><td></td></tr>';
- }
- ret += '<tr><td colspan="' + global_var.columns + '" class="tr_manage_lines"><i class="ui icon minus square outline remove_global_matrix_line"></i>'
- + ' <i class="ui icon plus square outline add_global_matrix_line"></i></td></tr>';
- ret += '</table>';
- ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline remove_global_matrix_column"></i>'
- + ' <i class="ui icon plus square outline add_global_matrix_column"></i></div>';
- }
- }
- $(global_container).find(".div_valor_var").html('');
- ret = $(ret);
- $(ret).find('.span_value_variable').data('associatedOject', global_var);
- $(ret).find(".boolean_simple_type").on('click', function (e) {
- alternateBooleanGlobalValue(global_var, this.parentNode);
- });
- $(ret).find(".simple_var").on('click', function (e) {
- enableGlobalValueUpdate(global_var, this.parentNode);
- });
- $(ret).find(".boolean_vector_var").on('click', function (e) {
- alternateBooleanGlobalVectorValue(global_var, $(this).data('index'), this.parentNode);
- });
- $(ret).find(".vector_var").on('click', function (e) {
- enableGlobalVectorValueUpdate(global_var, $(this).data('index'), this.parentNode);
- });
- $(ret).find(".remove_global_vector_column").on('click', function (e) {
- removeGlobalColumnVector(global_var);
- $(global_container).find(".div_valor_var").html('');
- renderValues(global_var, global_container);
- });
- $(ret).find(".add_global_vector_column").on('click', function (e) {
- addGlobalColumnVector(global_var);
- $(global_container).find(".div_valor_var").html('');
- renderValues(global_var, global_container);
- });
- $(ret).find(".remove_global_matrix_column").on('click', function (e) {
- removeColumnGlobalMatrix(global_var);
- $(global_container).find(".div_valor_var").html('');
- renderValues(global_var, global_container);
- });
- $(ret).find(".add_global_matrix_column").on('click', function (e) {
- addColumnGlobalMatrix(global_var);
- $(global_container).find(".div_valor_var").html('');
- renderValues(global_var, global_container);
- });
- $(ret).find(".remove_global_matrix_line").on('click', function (e) {
- removeLineGlobalMatrix(global_var);
- $(global_container).find(".div_valor_var").html('');
- renderValues(global_var, global_container);
- });
- $(ret).find(".add_global_matrix_line").on('click', function (e) {
- addLineGlobalMatrix(global_var);
- $(global_container).find(".div_valor_var").html('');
- renderValues(global_var, global_container);
- });
- $(ret).find(".boolean_matrix_var").on('click', function (e) {
- alternateBooleanGlobalMatrixValue(global_var, $(this).data('row'), $(this).data('index'), this.parentNode);
- });
- $(ret).find(".matrix_var").on('click', function (e) {
- enableGlobalMatrixValueUpdate(global_var, $(this).data('row'), $(this).data('index'), this.parentNode);
- });
- $(global_container).find(".div_valor_var").append(ret);
- updateColumnsAndRowsText(global_container, global_var);
- }
- function addHandlers(global_container) {
- var global_var = global_container.data('associatedOject');
- // Manage constant option:
- global_container.find(".alternate_constant").on('click', function (e) {
- toggleConstant(global_var);
- $(this).removeClass("on off");
- if (global_var.is_constant) {
- $(this).addClass("on");
- } else {
- $(this).addClass("off");
- }
- });
- // Manage global name:
- global_container.find(".enable_edit_name_parameter").on('click', function (e) {
- enableNameUpdate(global_container);
- });
- // Menu to change type:
- global_container.find('.ui.dropdown.global_type').dropdown({
- onChange: function (value, text, $selectedItem) {
- if ($($selectedItem).data('dimensions')) {
- updateType(global_var, Types[$($selectedItem).data('type')], $($selectedItem).data('dimensions'));
- } else {
- updateType(global_var, Types[$($selectedItem).data('type')]);
- }
- renderValues(global_var, global_container);
- }
- });
- // Remove global:
- global_container.find(".remove_global").on('click', function (e) {
- removeGlobal(global_var, global_container);
- });
- global_container
- .attr("draggable","true")
- .on('dragstart', function (e) {
- //console.log(document.elementFromPoint(e.clientX, e.clientY));
- //if ( global_container[0] == document.elementFromPoint(e.clientX, e.clientY) )
- program_obj.dataTransfer = { type: "var", content: global_var };
- })
- global_container
- .on('click', function (evt) {
- console.log(this);
- console.log(evt.target);
- if (evt.target === this) {
- $(this).trigger('dragstart');
- if (window.ghostNode) {
- $(window.ghostNode).remove();
- $(document).off('mousemove');
- }
- window.ghostNode = $(this).clone();
- ghostNode.outerWidth($(this).outerWidth());
- ghostNode.draggable().appendTo('body');
- ghostNode.css('position', 'absolute');
- ghostNode.css('left', evt.pageX);
- ghostNode.css('top', evt.pageY);
- evt.type = 'drag';
- evt.target = ghostNode[0];
- ghostNode.trigger(evt);
- $(document).on('mousemove', function (evt) {
- ghostNode.css('left', evt.pageX);
- ghostNode.css('top', evt.pageY);
- });
- $(document).on('mousedown', function (evt) {
- console.log("length ===");
- console.log($(evt.target).closest(".commands_list_div"))
- if ($(evt.target).closest(".commands_list_div").length <= 0) {
- if (window.ghostNode) {
- console.log("drop click");
- $('.div-over').removeClass('div-over');
- $(window.ghostNode).remove();
- delete window.ghostNode;
- $(document).off('mousemove').off('mousedown').off('keyup');
- }
- }
- });
- $(document).keyup(function (e) {
- console.log("KeyUp")
- if (e.key === "Escape") {
- console.log("escape");
- $('.div-over').removeClass('div-over');
- $(window.ghostNode).remove();
- delete window.ghostNode;
- $(document).off('mousemove').off('mousedown').off('keyup');
- }
- });
- }
- });
- }
- function updateColumnsAndRowsText(global_container, global_var) {
- var prev = global_container.find('.text').text().split('[');
- if (prev.length == 2) {
- var ff = prev[0] + '[ ' + global_var.columns + ' ] ';
- global_container.find('.text').empty();
- global_container.find('.text').text(ff);
- }
- if (prev.length == 3) {
- var ff = prev[0] + '[ ' + global_var.columns + ' ] [ ' + global_var.rows + ' ] ';
- global_container.find('.text').empty();
- global_container.find('.text').text(ff);
- }
- }
- export function renderGlobal(global_var) {
- var element = '<div class="fluid ui segment global_container pink inverted"><i class="ui icon ellipsis vertical inverted"></i><div class="global_const">const: ';
- element += '<i class="ui icon toggle ' + (global_var.is_constant ? "on" : "off") + ' alternate_constant"></i></div>';
- element += '<div class="ui dropdown global_type">';
- if (global_var.dimensions > 0) {
- element += '<div class="text">' + LocalizedStrings.getUI('vector') + ':' + LocalizedStrings.getUI(global_var.type);
- for (var i = 0; i < global_var.dimensions; i++) {
- element += ' [ <span class="dimensions_' + i + '"></span> ] ';
- }
- element += '</div>';
- } else {
- element += '<div class="text">' + LocalizedStrings.getUI(global_var.type.toLowerCase()) + '</div>';
- }
- element += '<div class="menu">';
- for (var tm in Types) {
- if (tm == Types.VOID.toUpperCase()) {
- continue;
- }
- element += '<div class="item ' + (global_var.type == tm.toLowerCase() ? ' selected ' : '') + '" data-type="' + tm + '" >' + LocalizedStrings.getUI(tm.toLowerCase()) + '</div>';
- }
- for (var tm in Types) {
- if (tm == Types.VOID.toUpperCase()) {
- continue;
- }
- element += '<div class="item">'
- + '<i class="dropdown icon"></i>'
- + LocalizedStrings.getUI('vector') + ':' + LocalizedStrings.getUI(tm.toLowerCase())
- + '<div class="menu">'
- + '<div class="item" data-text="' + LocalizedStrings.getUI('vector') + ':' + LocalizedStrings.getUI(tm.toLowerCase()) + ' [ ] " data-type="' + tm + '" data-dimensions="1">[ ]</div>'
- + '<div class="item" data-text="' + LocalizedStrings.getUI('vector') + ':' + LocalizedStrings.getUI(tm.toLowerCase()) + ' [ ] [ ] " data-type="' + tm + '" data-dimensions="2">[ ] [ ] </div>'
- + '</div>'
- + '</div>';
- }
- element += '</div></div> <div class="editing_name_var"> <span class="span_name_variable enable_edit_name_parameter">' + global_var.name + '</span> </div> <span class="character_equals"> = </span> ';
- element += '<div class="ui div_valor_var">' + global_var.value + '</div>';
- element += ' <i class="yellow inverted icon times remove_global"></i></div>';
- var complete_element = $(element);
- $(complete_element).data('associatedOject', global_var);
- $('.list_globals').append(complete_element);
- addHandlers(complete_element);
- renderValues(global_var, complete_element);
- if (global_var.dimensions == 1) {
- complete_element.find('.dimensions_0').text(global_var.columns);
- }
- if (global_var.dimensions == 2) {
- complete_element.find('.dimensions_0').text(global_var.columns);
- complete_element.find('.dimensions_1').text(global_var.rows);
- }
- return complete_element;
- }
- var opened_name_value_matrix_global_v = false;
- var opened_input_value_matrix_global_v = null;
- function enableGlobalMatrixValueUpdate(global_var, row, index, parent_node) {
- if (opened_name_value_matrix_global_v) {
- $(opened_input_value_matrix_global_v).focus();
- return;
- }
- parent_node = $(parent_node);
- opened_name_value_matrix_global_v = true;
- parent_node.find('.span_value_variable').text('');
- var input_field;
- if (global_var.type == Types.REAL) {
- input_field = $("<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[row][index].toFixed(1) + "' />");
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- } else {
- input_field = $("<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[row][index] + "' />");
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- }
- input_field.on('input', function () {
- var inputWidth = input_field.textWidth() + 10;
- opened_input_value_matrix_global_v = input_field;
- input_field.focus();
- var tmpStr = input_field.val();
- input_field.val('');
- input_field.val(tmpStr);
- input_field.css({
- width: inputWidth
- })
- }).trigger('input');
- input_field.focusout(function () {
- /// update array:
- if (input_field.val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value[row][index] = parseFloat(input_field.val().trim());
- parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[row][index] = parseInt(input_field.val().trim());
- } else {
- global_var.value[row][index] = input_field.val().trim();
- }
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- } else {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- }
- if (global_var.type == Types.TEXT) {
- global_var.value[row][index] = input_field.val();
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_matrix_global_v = false;
- opened_input_value_matrix_global_v = false;
- });
- $('.width-dynamic').on('keydown', function (e) {
- var code = e.keyCode || e.which;
- if (code == 13) {
- if ($(this).val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value[row][index] = parseFloat($(this).val().trim());
- $(parent_node).find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[row][index] = parseInt($(this).val().trim());
- } else {
- global_var.value[row][index] = $(this).val().trim();
- }
- $(parent_node).find('.span_value_variable').text(global_var.value[row][index]);
- }
- }
- $(this).remove();
- /// update elements:
- opened_name_value_matrix_global_v = false;
- opened_input_value_matrix_global_v = false;
- }
- if (code == 27) {
- if (global_var.type == Types.REAL) {
- $(parent_node).find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- $(parent_node).find('.span_value_variable').text(global_var.value[row][index]);
- }
- $(this).remove();
- /// update elements:
- opened_name_value_matrix_global_v = false;
- opened_input_value_matrix_global_v = false;
- }
- });
- }
- var opened_name_value_global_var = false;
- var opened_input_value_global_ar = null;
- function enableGlobalValueUpdate(global_var, parent_node) {
- if (opened_name_value_global_var) {
- $(opened_input_value_global_ar).focus();
- return;
- }
- opened_name_value_global_var = true;
- $(parent_node).find('.span_value_variable').text('');
- if (global_var.type == Types.REAL) {
- $("<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value.toFixed(1) + "' />").insertBefore($(parent_node).find('.span_value_variable'));
- } else {
- $("<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value + "' />").insertBefore($(parent_node).find('.span_value_variable'));
- }
- $('.width-dynamic').on('input', function () {
- var inputWidth = $(this).textWidth() + 10;
- opened_input_value_global_ar = 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()) {
- if (global_var.type == Types.REAL) {
- global_var.value = parseFloat($(this).val().trim());
- $(parent_node).find('.span_value_variable').text(global_var.value.toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value = parseInt($(this).val().trim());
- } else {
- global_var.value = $(this).val().trim();
- }
- $(parent_node).find('.span_value_variable').text(global_var.value);
- }
- }
- $(this).remove();
- /// update elements:
- opened_name_value_global_var = false;
- opened_input_value_global_ar = false;
- });
- $('.width-dynamic').on('keydown', function (e) {
- var code = e.keyCode || e.which;
- if (code == 13) {
- if ($(this).val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value = parseFloat($(this).val().trim());
- $(parent_node).find('.span_value_variable').text(global_var.value.toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value = parseInt($(this).val().trim());
- } else {
- global_var.value = $(this).val().trim();
- }
- $(parent_node).find('.span_value_variable').text(global_var.value);
- }
- }
- $(this).remove();
- /// update elements:
- opened_name_value_global_var = false;
- opened_input_value_global_ar = false;
- }
- if (code == 27) {
- if (global_var.type == Types.REAL) {
- $(parent_node).find('.span_value_variable').text(global_var.value.toFixed(1));
- } else {
- $(parent_node).find('.span_value_variable').text(global_var.value);
- }
- $(this).remove();
- /// update elements:
- opened_name_value_global_var = false;
- opened_input_value_global_ar = false;
- }
- });
- }
- var opened_name_global = false;
- var opened_input_global = null;
- function enableNameUpdate(global_container) {
- var global_var = global_container.data('associatedOject');
- if (opened_name_global) {
- opened_input_global.focus();
- return;
- }
- opened_name_global = true;
- global_container.find('.span_name_variable').text('');
- $("<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='" + global_var.name + "' />").insertBefore(global_container.find('.span_name_variable'));
- $('.width-dynamic').on('input', function () {
- var inputWidth = $(this).textWidth() + 10;
- opened_input_global = $(this);
- opened_input_global.focus();
- opened_input_global.css({
- width: inputWidth
- })
- }).trigger('input');
- $('.width-dynamic').focusout(function () {
- /// update array:
- if ($(this).val().trim().length > 0) {
- updateName(global_var, $(this).val().trim());
- global_container.find('.span_name_variable').text(global_var.name);
- } else {
- global_container.find('.span_name_variable').text(global_var.name);
- }
- $(this).remove();
- /// update elements:
- opened_name_global = false;
- opened_input_global = false;
- });
- $('.width-dynamic').on('keydown', function (e) {
- var code = e.keyCode || e.which;
- if (code == 13) {
- if ($(this).val().trim()) {
- updateName(global_var, $(this).val().trim());
- global_container.find('.span_name_variable').text(global_var.name);
- } else {
- global_container.find('.span_name_variable').text(global_var.name);
- }
- $(this).remove();
- /// update elements:
- opened_name_global = false;
- opened_input_global = false;
- }
- if (code == 27) {
- global_container.find('.span_name_variable').text(global_var.name);
- $(this).remove();
- /// update elements:
- opened_name_global = false;
- opened_input_global = false;
- }
- });
- $('.width-dynamic').select();
- }
- var opened_name_value_vector_global_ = false;
- var opened_input_value_vector_global_ = null;
- function enableGlobalVectorValueUpdate(global_var, index, parent_node) {
- if (opened_name_value_vector_global_) {
- $(opened_input_value_vector_global_).focus();
- return;
- }
- opened_name_value_vector_global_ = true;
- $(parent_node).find('.span_value_variable').text('');
- if (global_var.type == Types.REAL) {
- $("<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[index].toFixed(1) + "' />").insertBefore($(parent_node).find('.span_value_variable'));
- } else {
- $("<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[index] + "' />").insertBefore($(parent_node).find('.span_value_variable'));
- }
- $('.width-dynamic').on('input', function () {
- var inputWidth = $(this).textWidth() + 10;
- opened_input_value_vector_global_ = 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()) {
- if (global_var.type == Types.REAL) {
- global_var.value[index] = parseFloat($(this).val().trim());
- $(parent_node).find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[index] = parseInt($(this).val().trim());
- } else {
- global_var.value[index] = $(this).val().trim();
- }
- $(parent_node).find('.span_value_variable').text(global_var.value[index]);
- }
- }
- $(this).remove();
- /// update elements:
- opened_name_value_vector_global_ = false;
- opened_input_value_vector_global_ = false;
- });
- $('.width-dynamic').on('keydown', function (e) {
- var code = e.keyCode || e.which;
- if (code == 13) {
- if ($(this).val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value[index] = parseFloat($(this).val().trim());
- $(parent_node).find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[index] = parseInt($(this).val().trim());
- } else {
- global_var.value[index] = $(this).val().trim();
- }
- $(parent_node).find('.span_value_variable').text(global_var.value[index]);
- }
- }
- $(this).remove();
- /// update elements:
- opened_name_value_vector_global_ = false;
- opened_input_value_vector_global_ = false;
- }
- if (code == 27) {
- if (global_var.type == Types.REAL) {
- $(parent_node).find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- $(parent_node).find('.span_value_variable').text(global_var.value[index]);
- }
- $(this).remove();
- /// update elements:
- opened_name_value_vector_global_ = false;
- opened_input_value_vector_global_ = false;
- }
- });
- }
- $.fn.textWidth = function (text, font) {
- if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').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();
- };
|