/* * Project Name : Visual Python * Description : GUI-based Python code generator * File Name : com_makeDom.js * Author : Black Logic * Note : Make DOM data * License : GPLv3 (GNU General Public License v3.0) * Date : 2021. 08. 14 * Change Date : */ //============================================================================ // Make DOM data //============================================================================ define([ 'vp_base/js/com/com_Const', 'vp_base/js/com/com_util' ], function (com_Const, com_util) { 'use strict' //======================================================================== // External call function //======================================================================== /** * Parse attributes * @param {object} attribute */ var parseAttributes = function( attribute ) { var attributeStr = ``; var attributes = Object.entries(attribute); var text = ``; for ( var i = 0; i < attributes.length; i++ ) { // validation // attribute(key): style, class, id, text, value, type, placeholder, data_ if ( attributes[i][0] !== 'style' || attributes[i][0] !== 'class' || attributes[i][0] !== 'id' || attributes[i][0] !== 'text' || attributes[i][0] !== 'type' || attributes[i][0] !== 'placeholder' || attributes[i][0] !== 'value' || attributes[i][0].indexOf('data') === -1) { } else { continue; } // text if (attributes[i][0] === 'text') { text = attributes[i][1]; continue; } // style if ( attributes[i][0] === 'style') { /** color: black ì ê²½ì° ì²ë¼ * styleì ì§ì íê³ ë¤ì ;ì ë¶ì´ì§ ìë ê²½ì°, * ìëì¼ë¡ ;ì ë¶ì¬ì£¼ë ë¡ì§ */ var cursor = 0; /** * style í ì¤í¸ë¥¼ cursorê° 0ë¶í° styleText.lengthê¹ì§ ë°ë³µë¬¸ì ë * attributes[i][1] ì´í styleTextë¡ ì¤ëª */ while (cursor++ < attributes[i][1].length) { /** styleTextì í 문ìê° ' '(ëì´ì°ê¸°)를 ë§ë ê²½ì° */ if (attributes[i][1].indexOf(' ') !== -1 || attributes[i][1].indexOf(' ') !== 0 || attributes[i][1].indexOf(' ') !== attributes[i][1].length - 1) { /** styleTextì ê° ë¬¸ìë¤ì ë°ë³µë¬¸ ëë¤ê° í 문ìê° ':' 를 ë§ë ê²½ì° * ì를 ë¤ë©´ `color: black` ìì :를 ë§ë ê²½ì°, * : black ë¤ìì `;`íìê° ìì¼ë©´ ';'ì ë£ì´ì¤ë¤ * `;' íìê° ìì¼ë©´ ëì´ê°ë¤ */ if ( attributes[i][1].indexOf(':', cursor) !== -1 ) { var leftCursor = attributes[i][1].indexOf(':', cursor); while ( leftCursor-- ) { if (attributes[i][1][leftCursor].indexOf(' ') !== -1 ) { if (attributes[i][1][leftCursor - 1].indexOf(' ') !== -1) { continue; } if( attributes[i][1][leftCursor - 2].indexOf(';') === -1) { attributes[i][1] = attributes[i][1].slice(0, leftCursor) .concat(';') .concat(attributes[i][1].slice(leftCursor+1, attributes[i][1].length)); } break; } } cursor = (attributes[i][1].indexOf(':', cursor) ); } cursor ++; } } attributeStr += ' ' + attributes[i][0] + '='; attributeStr += `'${attributes[i][1]}'`; continue; } /** attributesê° data_ì¼ ê²½ì° * 'data_' ë 'data-' ë¡ íì±ëë¤ */ if (attributes[i][0].indexOf('_') !== -1) { var cursor = 0; while (attributes[i][0][cursor] !== undefined ) { if(attributes[i][0][cursor] === '_') { attributes[i][0] = attributes[i][0].slice(0,cursor) + '-' + attributes[i][0].slice(cursor + 1,attributes[i][0].length); } cursor++; } // attributes[i][0] = attributes[i][0].replaceAll('_', '-'); } attributeStr += ' ' + attributes[i][0] + '='; attributeStr += `'${attributes[i][1]}'`; } return { attributeStr, text } } /** * ì´í attribute를 íë¼ë¯¸í°ë¡ ë°ë í¨ì ì¬ì© ìì * var input = renderInput({ * class: `vp vp-label` * , id: `vp_label` * , style: `width: 90%; * min-width: 50px; max-width: 100px; * margin: 8px; position: relative; display: block; font-size: 12px; * overflow: hidden; border-width: 0; outline: none; border-radius: 2px; * box-shadow: 0 1px 4px rgba(0, 0, 0, .6); * color: black; transition: background-color .3s`; * , text:"Lavel" * , placeholder:"ì ë ¥ ë°ëëë¤" * , type: "text" * , data_input_id:"3" * , data_capations_id: "lang" * }); */ /** * Rendering input * @param {object} attribute */ var renderInput = function(attribute) { var { attributeStr } = parseAttributes(attribute); return $(` `); } /** * Renderig button * @param {object} attribute */ var renderButton = function(attribute) { var { attributeStr, text } = parseAttributes(attribute); return $(``); } /** * Renderig select box * @param {object} attribute */ var renderSelectBox = function(attribute) { var { attributeStr } = parseAttributes(attribute); return $(``); } /** * Rendering option * @param {Document} selectBox * @param {Object} attribute * @param {Array} optionDataList */ var renderOption = function(selectBox, attribute, optionDataList, optionTextList = []) { for( var a = 0; a < optionDataList.length; a++ ) { var { attributeStr } = parseAttributes(attribute); var value = optionDataList[a]; var text = optionTextList.length > a ? optionTextList[a] : value; var option = $(``); $(selectBox).append(option); } // select option í´ë¦ì í´ë¦ ë option íê·¸ë selectedë trueê° ëê³ ëë¨¸ì§ false $(selectBox).change(function() { var index = $(':selected', this).index(); var value = $(':selected', this).val(); for(var i = 0; i < $(selectBox).children().length; i++ ) { ((j) => { $(this).find(`option:eq(${j})`).attr('selected', false); })(i); } $(this).find(`option:eq(${index})`).attr('selected', true); $(this).val(value); }); return $(selectBox); } /** * Rendering span * @param {object} attribute */ var renderSpan = function(attribute) { var { attributeStr, text } = parseAttributes(attribute); return $(` ${text} `); } /** * Rendering label * @param {object} attribute */ var renderLabel = function(attribute) { var { attributeStr, text } = parseAttributes(attribute); return $(``); } /** * Rendering div * @param {object} attribute */ var renderDiv = function(attribute) { var { attributeStr, text } = parseAttributes(attribute); return $(`