Changeset 3274766
- Timestamp:
- 04/16/2025 01:27:18 PM (10 months ago)
- Location:
- codeart-units-converter/trunk
- Files:
-
- 6 edited
-
codeart-units-converter.php (modified) (1 diff)
-
include/common.php (modified) (1 diff)
-
include/converter/convert.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
templates/user/units/list/container.htm (modified) (2 diffs)
-
templates/user/units/list/item.htm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
codeart-units-converter/trunk/codeart-units-converter.php
r3273696 r3274766 11 11 * Domain Path: /i18n/languages/ 12 12 * Version: 2.3.0 13 * Tested up to: 6. 7.213 * Tested up to: 6.8.0 14 14 */ 15 15 -
codeart-units-converter/trunk/include/common.php
r3272469 r3274766 62 62 //////////////////////////////////////////////////////////////////////////////////// 63 63 64 //////////////////////////////////////////////////////////////////////////////////// 65 function codeart_render_template_content($template_content, $content_array) 66 { 67 $content = $template_content; 68 69 foreach ($content_array as $key => $value) { 70 //print_r($array); 71 $content = str_replace($key, $value, $content); 72 } 73 74 return $content; 75 } 76 //////////////////////////////////////////////////////////////////////////////////// 77 78 //////////////////////////////////////////////////////////////////////////////////// 79 function codeart_load_template($file_path) 80 { 81 $content = file_get_contents(codeart_units_converter_plugin_path() . "/templates/" . $file_path); 82 83 return $content; 84 } 85 //////////////////////////////////////////////////////////////////////////////////// -
codeart-units-converter/trunk/include/converter/convert.php
r3273696 r3274766 6 6 // print_r($units); 7 7 8 $item_template = ""; 9 $container_template = ""; 10 if ($style == 'table') { 11 $item_template = codeart_load_template("user/units/table/item.htm"); 12 $container_template = codeart_load_template("user/units/table/container.htm"); 13 } elseif ($style == 'list') { 14 $item_template = codeart_load_template("user/units/list/item.htm"); 15 $container_template = codeart_load_template("user/units/list/container.htm"); 16 } else { 17 18 } 19 8 20 $items = ""; 9 21 10 22 foreach ($units as $unit) { 11 23 12 if ($style == 'table') { 13 $content_array = [ 14 "{{name}}" => $unit->name, 15 "{{code_name}}" => $unit->code_name, 16 "{{type}}" => $unit->type, 17 "__type__" => $unit->type, 18 "{{abbreviation}}" => $unit->abbreviation, 19 ]; 20 $items .= codeart_render_template("user/units/table/item.htm", $content_array); 21 } elseif ($style == 'list') { 22 $content_array = []; 23 $items .= codeart_render_template("user/units/list/item.htm", $content_array); 24 } else { 25 26 } 27 } 28 29 if ($style == 'table') { 30 $container_array = [ 31 "{{items}}" => $items, 32 "__type__" => $converter_type, 24 $content_array = [ 25 "{{name}}" => $unit->name, 26 "{{code_name}}" => $unit->code_name, 27 "{{type}}" => $unit->type, 28 "__type__" => $unit->type, 29 "{{abbreviation}}" => $unit->abbreviation, 33 30 ]; 34 $container = codeart_render_template("user/units/table/container.htm", $container_array); 35 } elseif ($style == 'list') { 36 $container_array = []; 37 $container = codeart_render_template("user/units/list/container.htm", $container_array); 38 } else { 31 $items .= codeart_render_template_content($item_template, $content_array); 39 32 40 33 } 41 34 35 $container_array = [ 36 "{{items}}" => $items, 37 "__type__" => $converter_type, 38 ]; 39 $container = codeart_render_template_content($container_template, $container_array); 40 42 41 return $container; 43 42 } -
codeart-units-converter/trunk/readme.txt
r3273137 r3274766 5 5 Requires at least: 4.7 6 6 Requires PHP: 7.0 7 Tested up to: 6. 7.27 Tested up to: 6.8.0 8 8 Stable tag: 2.3.0 9 9 License: GPLv3 -
codeart-units-converter/trunk/templates/user/units/list/container.htm
r3273696 r3274766 66 66 <div class="unit-row"> 67 67 <div class="unit-group"> 68 <input type="number" id=" input1" placeholder="0" step="any" oninput="onInputChange('__type__', 'input1', 'input2', 'unit1', 'unit2')">69 <select id=" unit1" onchange="onInputChange('__type__', 'input1', 'input2', 'unit1', 'unit2')">70 {{ options}}68 <input type="number" id="left-text" placeholder="0" step="any" oninput="codeart_units_converter___type___get_data('__type__', document.getElementById('left-select').value, document.getElementById('left-text').value)"> 69 <select id="left-select" onchange="codeart_units_converter___type___get_data('__type__', document.getElementById('left-select').value, document.getElementById('left-text').value)"> 70 {{items}} 71 71 </select> 72 72 </div> 73 73 74 74 <div class="unit-group"> 75 <input type="number" id=" input2" placeholder="0" step="any" oninput="onInputChange('__type__', 'input2', 'input1', 'unit2', 'unit1')">76 <select id=" unit2" onchange="onInputChange('__type__', 'input2', 'input1', 'unit2', 'unit1')">77 {{ options}}75 <input type="number" id="right-text" placeholder="0" step="any" oninput="codeart_units_converter___type___get_data('__type__', document.getElementById('right-select').value, document.getElementById('right-text').value)"> 76 <select id="right-select" onchange="codeart_units_converter___type___get_data('__type__', document.getElementById('right-select').value, document.getElementById('right-text').value)"> 77 {{items}} 78 78 </select> 79 79 </div> … … 88 88 89 89 <script> 90 function codeart_units_converter___type___get_data(type, fromUnit, toUnit, value, targetInputId) {91 var url = CodeArtUnitsConverter.homeUrl + "/wp-json/CodeArtUnitsConverter/v1/" + type + "/? from=" + fromUnit + "&to=" + toUnit + "&v=" + value;90 function codeart_units_converter___type___get_data(type, unit, value) { 91 var url = CodeArtUnitsConverter.homeUrl + "/wp-json/CodeArtUnitsConverter/v1/" + type + "/?u=" + unit + "&v=" + value; 92 92 93 var request = new XMLHttpRequest(); 93 var request; 94 if (window.XMLHttpRequest) { 95 request = new XMLHttpRequest(); 96 } else if (window.ActiveXObject) { 97 request = new ActiveXObject("Microsoft.XMLHTTP"); 98 } 99 94 100 request.onreadystatechange = function() { 95 if (this.readyState == = 4 && this.status === 200) {101 if (this.readyState == 4 && this.status == 200) { 96 102 var jsonObj = JSON.parse(this.responseText); 97 if (jsonObj.result !== undefined) { 98 document.getElementById(targetInputId).value = jsonObj.result; 103 104 if (jsonObj.results) { 105 for (var key in jsonObj.results) { 106 if (jsonObj.results.hasOwnProperty(key)) { 107 // var element = document.getElementById(key); 108 // if (element) { 109 // element.value = jsonObj.results[key]; 110 // } 111 if (document.getElementById('left-select').value == key) { 112 document.getElementById('left-text').value = jsonObj.results[key]; 113 } 114 if (document.getElementById('right-select').value == key) { 115 document.getElementById('right-text').value = jsonObj.results[key]; 116 } 117 } 118 } 99 119 } 100 120 } 101 } ;121 } 102 122 103 123 request.open("GET", url, true); 104 124 request.send(); 105 125 } 106 107 function onInputChange(type, sourceId, targetId, sourceUnitId, targetUnitId) {108 var value = document.getElementById(sourceId).value;109 var fromUnit = document.getElementById(sourceUnitId).value;110 var toUnit = document.getElementById(targetUnitId).value;111 112 if (value !== '') {113 codeart_units_converter___type___get_data(type, fromUnit, toUnit, value, targetId);114 }115 }116 126 </script> -
codeart-units-converter/trunk/templates/user/units/list/item.htm
r3273696 r3274766 1 <option value="{{ value}}">{{name}}</option>1 <option value="{{code_name}}">{{name}}</option>
Note: See TracChangeset
for help on using the changeset viewer.