Changeset 3305298
- Timestamp:
- 06/02/2025 08:35:18 PM (10 months ago)
- Location:
- aa-health-calculator
- Files:
-
- 2 added
- 8 edited
-
tags/1.0.1/aa-health-calculator.php (modified) (6 diffs)
-
tags/1.0.1/assets/css/aa-health-style.css (modified) (3 diffs)
-
tags/1.0.1/assets/js/aa-health-script.js (modified) (3 diffs)
-
tags/1.0.1/readme.txt (modified) (2 diffs)
-
trunk/aa-health-calculator.php (modified) (6 diffs)
-
trunk/assets/aa-health-script.js (added)
-
trunk/assets/aa-health-style.css (added)
-
trunk/assets/css/aa-health-style.css (modified) (3 diffs)
-
trunk/assets/js/aa-health-script.js (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
aa-health-calculator/tags/1.0.1/aa-health-calculator.php
r3305210 r3305298 13 13 */ 14 14 15 15 16 if (!defined('ABSPATH')) { 16 17 exit; // Exit if accessed directly … … 22 23 23 24 public function __construct() { 24 // Load plugin text domain25 25 add_action('plugins_loaded', [$this, 'load_textdomain']); 26 27 // Enqueue frontend scripts and styles28 26 add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']); 29 30 // Register shortcode 31 add_shortcode('aa-health', [$this, 'render_shortcode']); 32 33 // Add admin menu 27 add_shortcode('aa-health-calculator', [$this, 'render_shortcode']); // shortcode fixed here 34 28 add_action('admin_menu', [$this, 'add_admin_menu']); 35 36 // Register settings37 29 add_action('admin_init', [$this, 'register_settings']); 38 30 } … … 43 35 44 36 public function enqueue_scripts() { 37 // Enqueue plugin CSS and JS 45 38 wp_enqueue_style('aa-health-style', plugin_dir_url(__FILE__) . 'assets/css/aa-health-style.css', [], '1.0'); 46 wp_enqueue_script('aa-health-script', plugin_dir_url(__FILE__) . 'assets/js/aa-health-script.js', ['jquery'], '1.0', true); 47 48 // Pass localized strings and premium options to JS 49 $options = get_option('aa_health_calculator_options', []); 39 40 // Enqueue SweetAlert2 from CDN 41 wp_enqueue_script('sweetalert2', 'https://cdn.jsdelivr.net/npm/sweetalert2@11', [], '11', true); 42 43 // Enqueue plugin JS (ensure it loads after SweetAlert2) 44 wp_enqueue_script('aa-health-script', plugin_dir_url(__FILE__) . 'assets/js/aa-health-script.js', ['jquery', 'sweetalert2'], '1.0', true); 45 46 47 // Load options with defaults 50 48 $defaults = [ 51 'show_categories' => 'yes',52 'show_ideal_weight' => 'yes',53 'show_health_tips' => 'yes',54 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'),55 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'),56 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'),57 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'),58 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'),59 'text_too_thin' => __('That you are too thin.', 'aa-health-calculator'),60 'text_healthy' => __('That you are healthy.', 'aa-health-calculator'),61 'text_overweight' => __('That you have overweight.', 'aa-health-calculator'),49 'show_categories' => 'yes', 50 'show_ideal_weight' => 'yes', 51 'show_health_tips' => 'yes', 52 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'), 53 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'), 54 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'), 55 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'), 56 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'), 57 'text_too_thin' => __('You are underweight.', 'aa-health-calculator'), 58 'text_healthy' => __('You have a healthy weight.', 'aa-health-calculator'), 59 'text_overweight' => __('You are overweight.', 'aa-health-calculator'), 62 60 'alert_invalid_input' => __('Please fill in everything correctly.', 'aa-health-calculator'), 63 61 ]; 64 $options = wp_parse_args($options, $defaults); 65 66 wp_localize_script('aa-health-script', 'aaHealthOptions', $options); 62 63 $this->options = get_option('aa_health_calculator_options', []); 64 $this->options = wp_parse_args($this->options, $defaults); 65 66 wp_localize_script('aa-health-script', 'aaHealthOptions', $this->options); 67 67 } 68 68 69 69 public function render_shortcode() { 70 ob_start(); 71 ?> 72 <form id="aa-health-form" class="aa-health-calculator" novalidate> 73 <label for="aa-health-weight"><?php esc_html_e('Your Weight (kg):', 'aa-health-calculator'); ?></label> 74 <input type="number" name="weight" id="aa-health-weight" required min="1" step="any" /> 75 76 <label for="aa-health-height"><?php esc_html_e('Your Height (cm):', 'aa-health-calculator'); ?></label> 77 <input type="number" name="height" id="aa-health-height" required min="1" step="any" /> 70 ob_start(); 71 ?> 72 <div class="aa-health-calculator"> 73 <form id="aa-health-form" novalidate> 74 <label for="aa-health-unit"><?php esc_html_e('Select Unit System:', 'aa-health-calculator'); ?></label> 75 <select id="aa-health-unit" name="unit" aria-label="<?php esc_attr_e('Select units', 'aa-health-calculator'); ?>"> 76 <option value="metric"><?php esc_html_e('Metric (kg, cm)', 'aa-health-calculator'); ?></option> 77 <option value="imperial"><?php esc_html_e('Imperial (lbs, inches)', 'aa-health-calculator'); ?></option> 78 </select> 79 80 <div id="aa-health-metric-inputs"> 81 <label for="aa-health-weight"><?php esc_html_e('Your Weight (kg):', 'aa-health-calculator'); ?></label> 82 <input type="number" name="weight" id="aa-health-weight" required min="1" step="any" aria-required="true" placeholder="e.g. 70" /> 83 84 <label for="aa-health-height"><?php esc_html_e('Your Height (cm):', 'aa-health-calculator'); ?></label> 85 <input type="number" name="height" id="aa-health-height" required min="1" step="any" aria-required="true" placeholder="e.g. 170" /> 86 </div> 87 88 <div id="aa-health-imperial-inputs" style="display:none;"> 89 <label for="aa-health-weight-imp"><?php esc_html_e('Your Weight (lbs):', 'aa-health-calculator'); ?></label> 90 <input type="number" name="weight_imp" id="aa-health-weight-imp" required min="1" step="any" aria-required="true" placeholder="e.g. 154" /> 91 92 <label for="aa-health-height-imp"><?php esc_html_e('Your Height (inches):', 'aa-health-calculator'); ?></label> 93 <input type="number" name="height_imp" id="aa-health-height-imp" required min="1" step="any" aria-required="true" placeholder="e.g. 65" /> 94 </div> 78 95 79 96 <button type="submit"><?php esc_html_e('Calculate BMI', 'aa-health-calculator'); ?></button> 80 97 81 <div class="aa-health-result" style="display:none;" >98 <div class="aa-health-result" style="display:none;" aria-live="polite" role="region" aria-atomic="true"> 82 99 <p><strong><?php esc_html_e('Your BMI:', 'aa-health-calculator'); ?></strong> <span id="aa-health-bmi-value"></span></p> 83 <p><strong><?php esc_html_e(' This Means:', 'aa-health-calculator'); ?></strong> <span id="aa-health-bmi-meaning"></span></p>84 < div id="aa-health-bmi-category" style="display:none;"></div>85 < div id="aa-health-ideal-weight-range" style="display:none;"></div>86 < div id="aa-health-health-tip" style="display:none;"></div>100 <p><strong><?php esc_html_e('Meaning:', 'aa-health-calculator'); ?></strong> <span id="aa-health-bmi-meaning"></span></p> 101 <p id="aa-health-bmi-category" style="display:none;"></p> 102 <p id="aa-health-ideal-weight-range" style="display:none;"></p> 103 <p id="aa-health-health-tip" style="display:none;"></p> 87 104 88 105 <div class="aa-health-actions"> … … 93 110 </div> 94 111 </form> 95 <?php 96 return ob_get_clean(); 97 } 112 </div> 113 114 <script> 115 (function($){ 116 $(document).ready(function(){ 117 // Unit toggle switch 118 $('#aa-health-unit').on('change', function(){ 119 if ($(this).val() === 'metric') { 120 $('#aa-health-metric-inputs').show(); 121 $('#aa-health-imperial-inputs').hide(); 122 } else { 123 $('#aa-health-metric-inputs').hide(); 124 $('#aa-health-imperial-inputs').show(); 125 } 126 }); 127 }); 128 })(jQuery); 129 </script> 130 <?php 131 return ob_get_clean(); 132 } 98 133 99 134 public function add_admin_menu() { … … 153 188 $output['show_health_tips'] = (isset($input['show_health_tips']) && $input['show_health_tips'] === 'yes') ? 'yes' : 'no'; 154 189 155 // Health tips localized, you can add textareas if you want to customize in admin later 156 $output['tip_drink_water'] = __('Drink plenty of water every day.', 'aa-health-calculator'); 157 $output['tip_exercise'] = __('Exercise regularly to stay healthy.', 'aa-health-calculator'); 158 $output['tip_vegetables'] = __('Include vegetables in your diet.', 'aa-health-calculator'); 159 $output['tip_limit_sugar'] = __('Limit sugar intake.', 'aa-health-calculator'); 160 $output['tip_sleep'] = __('Get enough sleep.', 'aa-health-calculator'); 161 162 $output['text_too_thin'] = __('That you are too thin.', 'aa-health-calculator'); 163 $output['text_healthy'] = __('That you are healthy.', 'aa-health-calculator'); 164 $output['text_overweight'] = __('That you have overweight.', 'aa-health-calculator'); 165 $output['alert_invalid_input'] = __('Please fill in everything correctly.', 'aa-health-calculator'); 190 // Preserve tips and texts, or set defaults if not present 191 $defaults = [ 192 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'), 193 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'), 194 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'), 195 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'), 196 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'), 197 'text_too_thin' => __('You are underweight.', 'aa-health-calculator'), 198 'text_healthy' => __('You have a healthy weight.', 'aa-health-calculator'), 199 'text_overweight' => __('You are overweight.', 'aa-health-calculator'), 200 'alert_invalid_input' => __('Please fill in everything correctly.', 'aa-health-calculator'), 201 ]; 202 203 foreach ($defaults as $key => $default) { 204 $output[$key] = isset($input[$key]) ? sanitize_text_field($input[$key]) : $default; 205 } 166 206 167 207 return $output; … … 190 230 <h2><?php esc_html_e('Shortcode Generator', 'aa-health-calculator'); ?></h2> 191 231 <p><?php esc_html_e('Use the shortcode below to display the BMI calculator anywhere:', 'aa-health-calculator'); ?></p> 192 <pre style="background:#f1f1f1;padding:10px;">[aa-health]</pre> 232 233 <div style="position: relative; max-width: 320px;"> 234 <input 235 type="text" 236 readonly 237 value="[aa-health-calculator]" 238 id="aa-health-shortcode" 239 style="width: 100%; padding: 8px 40px 8px 10px; font-size: 16px;" 240 aria-label="<?php esc_attr_e('Shortcode to copy', 'aa-health-calculator'); ?>" 241 /> 242 <button 243 type="button" 244 id="aa-health-copy-btn" 245 style="position: absolute; right: 5px; top: 50%; transform: translateY(-50%); padding: 6px 10px; cursor: pointer;" 246 aria-label="<?php esc_attr_e('Copy shortcode', 'aa-health-calculator'); ?>" 247 ><?php esc_html_e('Copy', 'aa-health-calculator'); ?></button> 248 </div> 249 250 <script> 251 (function(){ 252 const btn = document.getElementById('aa-health-copy-btn'); 253 const input = document.getElementById('aa-health-shortcode'); 254 btn.addEventListener('click', function() { 255 input.select(); 256 input.setSelectionRange(0, 99999); // For mobile devices 257 navigator.clipboard.writeText(input.value).then(function() { 258 btn.textContent = '<?php echo esc_js(__('Copied!', 'aa-health-calculator')); ?>'; 259 setTimeout(() => { btn.textContent = '<?php echo esc_js(__('Copy', 'aa-health-calculator')); ?>'; }, 2000); 260 }); 261 }); 262 })(); 263 </script> 193 264 </div> 194 265 <?php -
aa-health-calculator/tags/1.0.1/assets/css/aa-health-style.css
r3305217 r3305298 1 /*2 Plugin Name: AA Health Calculator3 Plugin URI: https://wordpress.org/plugins/aa-health-calculator/4 Description: AA Health Calculator is a fast, easy-to-use tool that helps you track and improve your health with accurate insights.5 Version: 1.0.16 Author: Syed Ashik Mahmud7 Author URI: https://aaextensions.com8 License: GPL29 License URI: https://www.gnu.org/licenses/gpl-2.0.html10 Text Domain: aa-condition11 Domain Path: /languages12 */13 14 1 .aa-health-calculator { 15 2 max-width: 400px; … … 24 11 .aa-health-calculator label { 25 12 display: block; 26 margin-bottom: 6px;13 margin-bottom: 4px; 27 14 font-weight: 600; 28 15 color: #333; 29 16 } 30 17 31 .aa-health-calculator input[type="number"] { 18 .aa-health-calculator input[type="number"], 19 .aa-health-calculator select { 32 20 width: 100%; 33 padding: 8px 10px; 34 margin-bottom: 15px; 35 border: 1px solid #ccc; 36 border-radius: 4px; 21 padding: 12px 40px 12px 14px; 22 margin-bottom: 16px; 23 border: 2px solid #ccc; 24 border-radius: 8px; 25 font-size: 15px; 26 transition: border-color 0.3s ease, box-shadow 0.3s ease; 37 27 box-sizing: border-box; 28 background-color: #fafafa; 29 appearance: none; 30 cursor: pointer; 31 font-family: inherit; 32 } 33 34 /* Custom select arrow using SVG background */ 35 .aa-health-calculator select { 36 background-image: url("data:image/svg+xml;charset=US-ASCII,%3csvg width='14' height='10' viewBox='0 0 14 10' fill='none' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M1 1L7 7L13 1' stroke='%230073aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e"); 37 background-repeat: no-repeat; 38 background-position: right 14px center; 39 background-size: 14px 10px; 40 } 41 42 .aa-health-calculator input[type="number"]:focus, 43 .aa-health-calculator select:focus { 44 border-color: #0073aa; 45 box-shadow: 0 0 8px rgba(0, 115, 170, 0.3); 46 outline: none; 47 background-color: #fff; 38 48 } 39 49 … … 42 52 color: #fff; 43 53 border: none; 44 padding: 1 0px 15px;45 border-radius: 4px;54 padding: 12px 15px; 55 border-radius: 8px; 46 56 cursor: pointer; 47 57 width: 100%; 48 58 font-size: 16px; 49 transition: background-color 0.3s ease; 59 font-weight: 600; 60 transition: background-color 0.3s ease, box-shadow 0.3s ease; 50 61 } 51 62 52 .aa-health-calculator button:hover { 63 .aa-health-calculator button:hover, 64 .aa-health-calculator button:focus { 53 65 background-color: #005177; 66 box-shadow: 0 0 8px rgba(0, 81, 119, 0.6); 67 outline: none; 68 } 69 70 71 /* Result */ 72 73 .aa-health-result { 74 background-color: #e8f4f8; 75 border: 1px solid #a7d0e8; 76 border-radius: 8px; 77 padding: 20px 25px; 78 color: #134e6f; 79 font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 80 max-width: 400px; 81 box-shadow: 0 2px 8px rgba(19, 78, 111, 0.15); 82 margin-top: 1rem; 54 83 } 55 84 56 85 .aa-health-result p { 57 font-size: 16px; 58 margin: 8px 0; 86 margin: 0.6rem 0; 87 font-size: 1.1rem; /* slightly bigger for readability */ 88 } 89 90 .bmi-category { 91 font-weight: 600; 92 color: #1c6e8c; 93 font-size: 1.05rem; 94 } 95 96 .ideal-weight { 97 font-style: italic; 98 color: #0e4d6a; 99 font-size: 1rem; 100 } 101 102 .health-tip { 103 font-style: italic; 104 color: #0a3a51; 105 margin-bottom: 1.2rem; 106 font-size: 1rem; 59 107 } 60 108 61 109 .aa-health-actions { 110 display: flex; 111 justify-content: center; 112 gap: 12px; 113 flex-wrap: wrap; 62 114 margin-top: 15px; 63 display: flex;64 gap: 10px;65 flex-wrap: wrap;66 115 } 67 116 68 117 .aa-health-actions a { 69 background : #eee;70 padding: 8px 12px;71 border-radius: 4px;118 background-color: #137aaf; 119 color: #fff; 120 padding: 10px 16px; /* slightly bigger clickable area */ 72 121 text-decoration: none; 73 color: #0073aa;74 font- weight: 600;75 font-size: 14px;76 flex-grow: 1;122 border-radius: 5px; 123 font-size: 1rem; 124 transition: background-color 0.25s ease; 125 min-width: 80px; 77 126 text-align: center; 78 transition: background-color 0.3s ease;79 127 } 80 128 81 .aa-health-actions a:hover { 82 background-color: #dbeafc; 129 .aa-health-actions a:hover, 130 .aa-health-actions a:focus { 131 background-color: #0f6791; 132 outline: none; 83 133 } 84 134 -
aa-health-calculator/tags/1.0.1/assets/js/aa-health-script.js
r3305217 r3305298 1 /*2 Plugin Name: AA Health Calculator3 Plugin URI: https://wordpress.org/plugins/aa-health-calculator/4 Description: AA Health Calculator is a fast, easy-to-use tool that helps you track and improve your health with accurate insights.5 Version: 1.0.16 Author: Syed Ashik Mahmud7 Author URI: https://aaextensions.com8 License: GPL29 License URI: https://www.gnu.org/licenses/gpl-2.0.html10 Text Domain: aa-condition11 Domain Path: /languages12 */13 14 1 (function(window, document) { 15 2 'use strict'; … … 20 7 21 8 var resultBlock = form.querySelector('.aa-health-result'); 9 if (!resultBlock) return; 10 22 11 var bmiValue = document.getElementById('aa-health-bmi-value'); 23 12 var bmiMeaning = document.getElementById('aa-health-bmi-meaning'); … … 40 29 e.preventDefault(); 41 30 42 var weight = parseFloat(form.weight.value); 43 var height = parseFloat(form.height.value); 31 var unit = form.querySelector('#aa-health-unit').value; 44 32 45 if (weight > 0 && height > 0) { 46 var bmi = weight / Math.pow(height / 100, 2); 47 var meaning = ''; 33 var weight, height, bmi, meaning; 48 34 49 if (bmi < 18.5) { 50 meaning = aaHealthOptions.text_too_thin; 51 } else if (bmi < 25) { 52 meaning = aaHealthOptions.text_healthy; 35 if (unit === 'metric') { 36 weight = parseFloat(form.weight.value); 37 height = parseFloat(form.height.value); 38 if (!(weight > 0 && height > 0)) { 39 Swal.fire({ 40 icon: 'warning', 41 title: 'Invalid Input', 42 text: aaHealthOptions.alert_invalid_input 43 }); 44 return; 45 } 46 bmi = weight / Math.pow(height / 100, 2); 47 } else if (unit === 'imperial') { 48 weight = parseFloat(form.weight_imp.value); 49 height = parseFloat(form.height_imp.value); 50 if (!(weight > 0 && height > 0)) { 51 Swal.fire({ 52 icon: 'warning', 53 title: 'Invalid Input', 54 text: aaHealthOptions.alert_invalid_input 55 }); 56 return; 57 } 58 bmi = 703 * weight / Math.pow(height, 2); 59 } else { 60 Swal.fire({ 61 icon: 'error', 62 title: 'Unknown Unit', 63 text: aaHealthOptions.alert_invalid_input 64 }); 65 return; 66 } 67 68 if (bmi < 18.5) { 69 meaning = aaHealthOptions.text_too_thin; 70 } else if (bmi < 25) { 71 meaning = aaHealthOptions.text_healthy; 72 } else { 73 meaning = aaHealthOptions.text_overweight; 74 } 75 76 bmiValue.textContent = bmi.toFixed(2); 77 bmiMeaning.textContent = meaning; 78 resultBlock.style.display = 'block'; 79 80 if (aaHealthOptions.show_categories === 'yes') { 81 var category = ''; 82 if (bmi < 16) category = 'Severe Thinness'; 83 else if (bmi < 17) category = 'Moderate Thinness'; 84 else if (bmi < 18.5) category = 'Mild Thinness'; 85 else if (bmi < 25) category = 'Normal'; 86 else if (bmi < 30) category = 'Overweight'; 87 else if (bmi < 35) category = 'Obese Class I'; 88 else if (bmi < 40) category = 'Obese Class II'; 89 else category = 'Obese Class III'; 90 91 categoryDiv.textContent = 'Category: ' + category; 92 categoryDiv.style.display = 'block'; 93 } else { 94 categoryDiv.style.display = 'none'; 95 } 96 97 if (aaHealthOptions.show_ideal_weight === 'yes') { 98 var minWeight, maxWeight; 99 if (unit === 'metric') { 100 minWeight = (18.5 * Math.pow(height / 100, 2)).toFixed(1); 101 maxWeight = (24.9 * Math.pow(height / 100, 2)).toFixed(1); 102 idealWeightDiv.textContent = 'Ideal Weight: ' + minWeight + ' kg - ' + maxWeight + ' kg'; 53 103 } else { 54 meaning = aaHealthOptions.text_overweight; 104 var heightMeters = height * 0.0254; 105 var minKg = 18.5 * heightMeters * heightMeters; 106 var maxKg = 24.9 * heightMeters * heightMeters; 107 minWeight = (minKg * 2.20462).toFixed(1); 108 maxWeight = (maxKg * 2.20462).toFixed(1); 109 idealWeightDiv.textContent = 'Ideal Weight: ' + minWeight + ' lbs - ' + maxWeight + ' lbs'; 55 110 } 111 idealWeightDiv.style.display = 'block'; 112 } else { 113 idealWeightDiv.style.display = 'none'; 114 } 56 115 57 bmiValue.textContent = bmi.toFixed(2); 58 bmiMeaning.textContent = meaning; 59 resultBlock.style.display = 'block'; 116 if (aaHealthOptions.show_health_tips === 'yes') { 117 var tip = tips[Math.floor(Math.random() * tips.length)]; 118 tipDiv.textContent = 'Tip: ' + tip; 119 tipDiv.style.display = 'block'; 120 } else { 121 tipDiv.style.display = 'none'; 122 } 60 123 61 if (aaHealthOptions.show_categories === 'yes') { 62 var category = ''; 63 if (bmi < 16) category = 'Severe Thinness'; 64 else if (bmi < 17) category = 'Moderate Thinness'; 65 else if (bmi < 18.5) category = 'Mild Thinness'; 66 else if (bmi < 25) category = 'Normal'; 67 else if (bmi < 30) category = 'Overweight'; 68 else if (bmi < 35) category = 'Obese Class I'; 69 else if (bmi < 40) category = 'Obese Class II'; 70 else category = 'Obese Class III'; 124 shareBtn.href = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent('My BMI is ' + bmi.toFixed(2) + ' - ' + meaning); 71 125 72 categoryDiv.textContent = 'Category: ' + category; 73 categoryDiv.style.display = 'block'; 126 downloadBtn.onclick = function(ev) { 127 ev.preventDefault(); 128 var content = 'BMI Report\n\n'; 129 if(unit === 'metric'){ 130 content += 'Weight: ' + weight + ' kg\nHeight: ' + height + ' cm\n'; 74 131 } else { 75 c ategoryDiv.style.display = 'none';132 content += 'Weight: ' + weight + ' lbs\nHeight: ' + height + ' inches\n'; 76 133 } 134 content += 'BMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning; 135 var blob = new Blob([content], { type: 'application/pdf' }); 136 var link = document.createElement('a'); 137 link.href = URL.createObjectURL(blob); 138 link.download = 'bmi-report.pdf'; 139 link.click(); 140 }; 77 141 78 if (aaHealthOptions.show_ideal_weight === 'yes') {79 var minWeight = (18.5 * Math.pow(height / 100, 2)).toFixed(1);80 var maxWeight = (24.9 * Math.pow(height / 100, 2)).toFixed(1);81 idealWeightDiv.textContent = 'Ideal Weight: ' + minWeight + ' kg - ' + maxWeight + ' kg';82 idealWeightDiv.style.display = 'block';142 emailBtn.onclick = function(ev) { 143 ev.preventDefault(); 144 var body = ''; 145 if(unit === 'metric'){ 146 body = 'Weight: ' + weight + ' kg\nHeight: ' + height + ' cm\n'; 83 147 } else { 84 idealWeightDiv.style.display = 'none';148 body = 'Weight: ' + weight + ' lbs\nHeight: ' + height + ' inches\n'; 85 149 } 86 87 if (aaHealthOptions.show_health_tips === 'yes') { 88 var tip = tips[Math.floor(Math.random() * tips.length)]; 89 tipDiv.textContent = 'Tip: ' + tip; 90 tipDiv.style.display = 'block'; 91 } else { 92 tipDiv.style.display = 'none'; 93 } 94 95 // Share on Twitter 96 shareBtn.href = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent('My BMI is ' + bmi.toFixed(2) + ' - ' + meaning); 97 98 // Download PDF (text-based) 99 downloadBtn.onclick = function(ev) { 100 ev.preventDefault(); 101 var content = 'BMI Report\n\nWeight: ' + weight + ' kg\nHeight: ' + height + ' cm\nBMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning; 102 var blob = new Blob([content], { type: 'application/pdf' }); 103 var link = document.createElement('a'); 104 link.href = URL.createObjectURL(blob); 105 link.download = 'bmi-report.pdf'; 106 link.click(); 107 }; 108 109 // Email report 110 emailBtn.onclick = function(ev) { 111 ev.preventDefault(); 112 window.location.href = 'mailto:?subject=' + encodeURIComponent('BMI Report') + '&body=' + encodeURIComponent('Weight: ' + weight + ' kg\nHeight: ' + height + ' cm\nBMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning); 113 }; 114 115 } else { 116 alert(aaHealthOptions.alert_invalid_input); 117 } 150 body += 'BMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning; 151 window.location.href = 'mailto:?subject=' + encodeURIComponent('BMI Report') + '&body=' + encodeURIComponent(body); 152 }; 118 153 }); 119 154 }); -
aa-health-calculator/tags/1.0.1/readme.txt
r3305050 r3305298 19 19 <li>Lightweight and mobile-friendly Best BMI calculator</li> 20 20 <li>Multilingual support with translation-ready text domain</li> 21 <li>Easy shortcode: <code>[aa-health ]</code> to embed calculator anywhere</li>21 <li>Easy shortcode: <code>[aa-health-calculator]</code> to embed calculator anywhere</li> 22 22 <li>Premium options configurable from admin panel</li> 23 23 <li>Display BMI categories, ideal weight range, and health tips</li> … … 34 34 <li>Install and activate the <strong>AA Health Calculator</strong> plugin in WordPress.</li> 35 35 <li>Go to the admin panel to configure premium options if needed.</li> 36 <li>Insert the shortcode <code>[aa-health ]</code> into any post, page, or widget.</li>36 <li>Insert the shortcode <code>[aa-health-calculator]</code> into any post, page, or widget.</li> 37 37 <li>Visitors enter their weight (kg) and height (cm) in the calculator form.</li> 38 38 <li>Click the "Calculate BMI" button to see their BMI and health info.</li> -
aa-health-calculator/trunk/aa-health-calculator.php
r3305210 r3305298 13 13 */ 14 14 15 15 16 if (!defined('ABSPATH')) { 16 17 exit; // Exit if accessed directly … … 22 23 23 24 public function __construct() { 24 // Load plugin text domain25 25 add_action('plugins_loaded', [$this, 'load_textdomain']); 26 27 // Enqueue frontend scripts and styles28 26 add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']); 29 30 // Register shortcode 31 add_shortcode('aa-health', [$this, 'render_shortcode']); 32 33 // Add admin menu 27 add_shortcode('aa-health-calculator', [$this, 'render_shortcode']); // shortcode fixed here 34 28 add_action('admin_menu', [$this, 'add_admin_menu']); 35 36 // Register settings37 29 add_action('admin_init', [$this, 'register_settings']); 38 30 } … … 43 35 44 36 public function enqueue_scripts() { 37 // Enqueue plugin CSS and JS 45 38 wp_enqueue_style('aa-health-style', plugin_dir_url(__FILE__) . 'assets/css/aa-health-style.css', [], '1.0'); 46 wp_enqueue_script('aa-health-script', plugin_dir_url(__FILE__) . 'assets/js/aa-health-script.js', ['jquery'], '1.0', true); 47 48 // Pass localized strings and premium options to JS 49 $options = get_option('aa_health_calculator_options', []); 39 40 // Enqueue SweetAlert2 from CDN 41 wp_enqueue_script('sweetalert2', 'https://cdn.jsdelivr.net/npm/sweetalert2@11', [], '11', true); 42 43 // Enqueue plugin JS (ensure it loads after SweetAlert2) 44 wp_enqueue_script('aa-health-script', plugin_dir_url(__FILE__) . 'assets/js/aa-health-script.js', ['jquery', 'sweetalert2'], '1.0', true); 45 46 47 // Load options with defaults 50 48 $defaults = [ 51 'show_categories' => 'yes',52 'show_ideal_weight' => 'yes',53 'show_health_tips' => 'yes',54 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'),55 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'),56 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'),57 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'),58 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'),59 'text_too_thin' => __('That you are too thin.', 'aa-health-calculator'),60 'text_healthy' => __('That you are healthy.', 'aa-health-calculator'),61 'text_overweight' => __('That you have overweight.', 'aa-health-calculator'),49 'show_categories' => 'yes', 50 'show_ideal_weight' => 'yes', 51 'show_health_tips' => 'yes', 52 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'), 53 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'), 54 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'), 55 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'), 56 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'), 57 'text_too_thin' => __('You are underweight.', 'aa-health-calculator'), 58 'text_healthy' => __('You have a healthy weight.', 'aa-health-calculator'), 59 'text_overweight' => __('You are overweight.', 'aa-health-calculator'), 62 60 'alert_invalid_input' => __('Please fill in everything correctly.', 'aa-health-calculator'), 63 61 ]; 64 $options = wp_parse_args($options, $defaults); 65 66 wp_localize_script('aa-health-script', 'aaHealthOptions', $options); 62 63 $this->options = get_option('aa_health_calculator_options', []); 64 $this->options = wp_parse_args($this->options, $defaults); 65 66 wp_localize_script('aa-health-script', 'aaHealthOptions', $this->options); 67 67 } 68 68 69 69 public function render_shortcode() { 70 ob_start(); 71 ?> 72 <form id="aa-health-form" class="aa-health-calculator" novalidate> 73 <label for="aa-health-weight"><?php esc_html_e('Your Weight (kg):', 'aa-health-calculator'); ?></label> 74 <input type="number" name="weight" id="aa-health-weight" required min="1" step="any" /> 75 76 <label for="aa-health-height"><?php esc_html_e('Your Height (cm):', 'aa-health-calculator'); ?></label> 77 <input type="number" name="height" id="aa-health-height" required min="1" step="any" /> 70 ob_start(); 71 ?> 72 <div class="aa-health-calculator"> 73 <form id="aa-health-form" novalidate> 74 <label for="aa-health-unit"><?php esc_html_e('Select Unit System:', 'aa-health-calculator'); ?></label> 75 <select id="aa-health-unit" name="unit" aria-label="<?php esc_attr_e('Select units', 'aa-health-calculator'); ?>"> 76 <option value="metric"><?php esc_html_e('Metric (kg, cm)', 'aa-health-calculator'); ?></option> 77 <option value="imperial"><?php esc_html_e('Imperial (lbs, inches)', 'aa-health-calculator'); ?></option> 78 </select> 79 80 <div id="aa-health-metric-inputs"> 81 <label for="aa-health-weight"><?php esc_html_e('Your Weight (kg):', 'aa-health-calculator'); ?></label> 82 <input type="number" name="weight" id="aa-health-weight" required min="1" step="any" aria-required="true" placeholder="e.g. 70" /> 83 84 <label for="aa-health-height"><?php esc_html_e('Your Height (cm):', 'aa-health-calculator'); ?></label> 85 <input type="number" name="height" id="aa-health-height" required min="1" step="any" aria-required="true" placeholder="e.g. 170" /> 86 </div> 87 88 <div id="aa-health-imperial-inputs" style="display:none;"> 89 <label for="aa-health-weight-imp"><?php esc_html_e('Your Weight (lbs):', 'aa-health-calculator'); ?></label> 90 <input type="number" name="weight_imp" id="aa-health-weight-imp" required min="1" step="any" aria-required="true" placeholder="e.g. 154" /> 91 92 <label for="aa-health-height-imp"><?php esc_html_e('Your Height (inches):', 'aa-health-calculator'); ?></label> 93 <input type="number" name="height_imp" id="aa-health-height-imp" required min="1" step="any" aria-required="true" placeholder="e.g. 65" /> 94 </div> 78 95 79 96 <button type="submit"><?php esc_html_e('Calculate BMI', 'aa-health-calculator'); ?></button> 80 97 81 <div class="aa-health-result" style="display:none;" >98 <div class="aa-health-result" style="display:none;" aria-live="polite" role="region" aria-atomic="true"> 82 99 <p><strong><?php esc_html_e('Your BMI:', 'aa-health-calculator'); ?></strong> <span id="aa-health-bmi-value"></span></p> 83 <p><strong><?php esc_html_e(' This Means:', 'aa-health-calculator'); ?></strong> <span id="aa-health-bmi-meaning"></span></p>84 < div id="aa-health-bmi-category" style="display:none;"></div>85 < div id="aa-health-ideal-weight-range" style="display:none;"></div>86 < div id="aa-health-health-tip" style="display:none;"></div>100 <p><strong><?php esc_html_e('Meaning:', 'aa-health-calculator'); ?></strong> <span id="aa-health-bmi-meaning"></span></p> 101 <p id="aa-health-bmi-category" style="display:none;"></p> 102 <p id="aa-health-ideal-weight-range" style="display:none;"></p> 103 <p id="aa-health-health-tip" style="display:none;"></p> 87 104 88 105 <div class="aa-health-actions"> … … 93 110 </div> 94 111 </form> 95 <?php 96 return ob_get_clean(); 97 } 112 </div> 113 114 <script> 115 (function($){ 116 $(document).ready(function(){ 117 // Unit toggle switch 118 $('#aa-health-unit').on('change', function(){ 119 if ($(this).val() === 'metric') { 120 $('#aa-health-metric-inputs').show(); 121 $('#aa-health-imperial-inputs').hide(); 122 } else { 123 $('#aa-health-metric-inputs').hide(); 124 $('#aa-health-imperial-inputs').show(); 125 } 126 }); 127 }); 128 })(jQuery); 129 </script> 130 <?php 131 return ob_get_clean(); 132 } 98 133 99 134 public function add_admin_menu() { … … 153 188 $output['show_health_tips'] = (isset($input['show_health_tips']) && $input['show_health_tips'] === 'yes') ? 'yes' : 'no'; 154 189 155 // Health tips localized, you can add textareas if you want to customize in admin later 156 $output['tip_drink_water'] = __('Drink plenty of water every day.', 'aa-health-calculator'); 157 $output['tip_exercise'] = __('Exercise regularly to stay healthy.', 'aa-health-calculator'); 158 $output['tip_vegetables'] = __('Include vegetables in your diet.', 'aa-health-calculator'); 159 $output['tip_limit_sugar'] = __('Limit sugar intake.', 'aa-health-calculator'); 160 $output['tip_sleep'] = __('Get enough sleep.', 'aa-health-calculator'); 161 162 $output['text_too_thin'] = __('That you are too thin.', 'aa-health-calculator'); 163 $output['text_healthy'] = __('That you are healthy.', 'aa-health-calculator'); 164 $output['text_overweight'] = __('That you have overweight.', 'aa-health-calculator'); 165 $output['alert_invalid_input'] = __('Please fill in everything correctly.', 'aa-health-calculator'); 190 // Preserve tips and texts, or set defaults if not present 191 $defaults = [ 192 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'), 193 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'), 194 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'), 195 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'), 196 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'), 197 'text_too_thin' => __('You are underweight.', 'aa-health-calculator'), 198 'text_healthy' => __('You have a healthy weight.', 'aa-health-calculator'), 199 'text_overweight' => __('You are overweight.', 'aa-health-calculator'), 200 'alert_invalid_input' => __('Please fill in everything correctly.', 'aa-health-calculator'), 201 ]; 202 203 foreach ($defaults as $key => $default) { 204 $output[$key] = isset($input[$key]) ? sanitize_text_field($input[$key]) : $default; 205 } 166 206 167 207 return $output; … … 190 230 <h2><?php esc_html_e('Shortcode Generator', 'aa-health-calculator'); ?></h2> 191 231 <p><?php esc_html_e('Use the shortcode below to display the BMI calculator anywhere:', 'aa-health-calculator'); ?></p> 192 <pre style="background:#f1f1f1;padding:10px;">[aa-health]</pre> 232 233 <div style="position: relative; max-width: 320px;"> 234 <input 235 type="text" 236 readonly 237 value="[aa-health-calculator]" 238 id="aa-health-shortcode" 239 style="width: 100%; padding: 8px 40px 8px 10px; font-size: 16px;" 240 aria-label="<?php esc_attr_e('Shortcode to copy', 'aa-health-calculator'); ?>" 241 /> 242 <button 243 type="button" 244 id="aa-health-copy-btn" 245 style="position: absolute; right: 5px; top: 50%; transform: translateY(-50%); padding: 6px 10px; cursor: pointer;" 246 aria-label="<?php esc_attr_e('Copy shortcode', 'aa-health-calculator'); ?>" 247 ><?php esc_html_e('Copy', 'aa-health-calculator'); ?></button> 248 </div> 249 250 <script> 251 (function(){ 252 const btn = document.getElementById('aa-health-copy-btn'); 253 const input = document.getElementById('aa-health-shortcode'); 254 btn.addEventListener('click', function() { 255 input.select(); 256 input.setSelectionRange(0, 99999); // For mobile devices 257 navigator.clipboard.writeText(input.value).then(function() { 258 btn.textContent = '<?php echo esc_js(__('Copied!', 'aa-health-calculator')); ?>'; 259 setTimeout(() => { btn.textContent = '<?php echo esc_js(__('Copy', 'aa-health-calculator')); ?>'; }, 2000); 260 }); 261 }); 262 })(); 263 </script> 193 264 </div> 194 265 <?php -
aa-health-calculator/trunk/assets/css/aa-health-style.css
r3305217 r3305298 1 /*2 Plugin Name: AA Health Calculator3 Plugin URI: https://wordpress.org/plugins/aa-health-calculator/4 Description: AA Health Calculator is a fast, easy-to-use tool that helps you track and improve your health with accurate insights.5 Version: 1.0.16 Author: Syed Ashik Mahmud7 Author URI: https://aaextensions.com8 License: GPL29 License URI: https://www.gnu.org/licenses/gpl-2.0.html10 Text Domain: aa-condition11 Domain Path: /languages12 */13 14 1 .aa-health-calculator { 15 2 max-width: 400px; … … 24 11 .aa-health-calculator label { 25 12 display: block; 26 margin-bottom: 6px;13 margin-bottom: 4px; 27 14 font-weight: 600; 28 15 color: #333; 29 16 } 30 17 31 .aa-health-calculator input[type="number"] { 18 .aa-health-calculator input[type="number"], 19 .aa-health-calculator select { 32 20 width: 100%; 33 padding: 8px 10px; 34 margin-bottom: 15px; 35 border: 1px solid #ccc; 36 border-radius: 4px; 21 padding: 12px 40px 12px 14px; 22 margin-bottom: 16px; 23 border: 2px solid #ccc; 24 border-radius: 8px; 25 font-size: 15px; 26 transition: border-color 0.3s ease, box-shadow 0.3s ease; 37 27 box-sizing: border-box; 28 background-color: #fafafa; 29 appearance: none; 30 cursor: pointer; 31 font-family: inherit; 32 } 33 34 /* Custom select arrow using SVG background */ 35 .aa-health-calculator select { 36 background-image: url("data:image/svg+xml;charset=US-ASCII,%3csvg width='14' height='10' viewBox='0 0 14 10' fill='none' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M1 1L7 7L13 1' stroke='%230073aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e"); 37 background-repeat: no-repeat; 38 background-position: right 14px center; 39 background-size: 14px 10px; 40 } 41 42 .aa-health-calculator input[type="number"]:focus, 43 .aa-health-calculator select:focus { 44 border-color: #0073aa; 45 box-shadow: 0 0 8px rgba(0, 115, 170, 0.3); 46 outline: none; 47 background-color: #fff; 38 48 } 39 49 … … 42 52 color: #fff; 43 53 border: none; 44 padding: 1 0px 15px;45 border-radius: 4px;54 padding: 12px 15px; 55 border-radius: 8px; 46 56 cursor: pointer; 47 57 width: 100%; 48 58 font-size: 16px; 49 transition: background-color 0.3s ease; 59 font-weight: 600; 60 transition: background-color 0.3s ease, box-shadow 0.3s ease; 50 61 } 51 62 52 .aa-health-calculator button:hover { 63 .aa-health-calculator button:hover, 64 .aa-health-calculator button:focus { 53 65 background-color: #005177; 66 box-shadow: 0 0 8px rgba(0, 81, 119, 0.6); 67 outline: none; 68 } 69 70 71 /* Result */ 72 73 .aa-health-result { 74 background-color: #e8f4f8; 75 border: 1px solid #a7d0e8; 76 border-radius: 8px; 77 padding: 20px 25px; 78 color: #134e6f; 79 font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 80 max-width: 400px; 81 box-shadow: 0 2px 8px rgba(19, 78, 111, 0.15); 82 margin-top: 1rem; 54 83 } 55 84 56 85 .aa-health-result p { 57 font-size: 16px; 58 margin: 8px 0; 86 margin: 0.6rem 0; 87 font-size: 1.1rem; /* slightly bigger for readability */ 88 } 89 90 .bmi-category { 91 font-weight: 600; 92 color: #1c6e8c; 93 font-size: 1.05rem; 94 } 95 96 .ideal-weight { 97 font-style: italic; 98 color: #0e4d6a; 99 font-size: 1rem; 100 } 101 102 .health-tip { 103 font-style: italic; 104 color: #0a3a51; 105 margin-bottom: 1.2rem; 106 font-size: 1rem; 59 107 } 60 108 61 109 .aa-health-actions { 110 display: flex; 111 justify-content: center; 112 gap: 12px; 113 flex-wrap: wrap; 62 114 margin-top: 15px; 63 display: flex;64 gap: 10px;65 flex-wrap: wrap;66 115 } 67 116 68 117 .aa-health-actions a { 69 background : #eee;70 padding: 8px 12px;71 border-radius: 4px;118 background-color: #137aaf; 119 color: #fff; 120 padding: 10px 16px; /* slightly bigger clickable area */ 72 121 text-decoration: none; 73 color: #0073aa;74 font- weight: 600;75 font-size: 14px;76 flex-grow: 1;122 border-radius: 5px; 123 font-size: 1rem; 124 transition: background-color 0.25s ease; 125 min-width: 80px; 77 126 text-align: center; 78 transition: background-color 0.3s ease;79 127 } 80 128 81 .aa-health-actions a:hover { 82 background-color: #dbeafc; 129 .aa-health-actions a:hover, 130 .aa-health-actions a:focus { 131 background-color: #0f6791; 132 outline: none; 83 133 } 84 134 -
aa-health-calculator/trunk/assets/js/aa-health-script.js
r3305217 r3305298 1 /*2 Plugin Name: AA Health Calculator3 Plugin URI: https://wordpress.org/plugins/aa-health-calculator/4 Description: AA Health Calculator is a fast, easy-to-use tool that helps you track and improve your health with accurate insights.5 Version: 1.0.16 Author: Syed Ashik Mahmud7 Author URI: https://aaextensions.com8 License: GPL29 License URI: https://www.gnu.org/licenses/gpl-2.0.html10 Text Domain: aa-condition11 Domain Path: /languages12 */13 14 1 (function(window, document) { 15 2 'use strict'; … … 20 7 21 8 var resultBlock = form.querySelector('.aa-health-result'); 9 if (!resultBlock) return; 10 22 11 var bmiValue = document.getElementById('aa-health-bmi-value'); 23 12 var bmiMeaning = document.getElementById('aa-health-bmi-meaning'); … … 40 29 e.preventDefault(); 41 30 42 var weight = parseFloat(form.weight.value); 43 var height = parseFloat(form.height.value); 31 var unit = form.querySelector('#aa-health-unit').value; 44 32 45 if (weight > 0 && height > 0) { 46 var bmi = weight / Math.pow(height / 100, 2); 47 var meaning = ''; 33 var weight, height, bmi, meaning; 48 34 49 if (bmi < 18.5) { 50 meaning = aaHealthOptions.text_too_thin; 51 } else if (bmi < 25) { 52 meaning = aaHealthOptions.text_healthy; 35 if (unit === 'metric') { 36 weight = parseFloat(form.weight.value); 37 height = parseFloat(form.height.value); 38 if (!(weight > 0 && height > 0)) { 39 Swal.fire({ 40 icon: 'warning', 41 title: 'Invalid Input', 42 text: aaHealthOptions.alert_invalid_input 43 }); 44 return; 45 } 46 bmi = weight / Math.pow(height / 100, 2); 47 } else if (unit === 'imperial') { 48 weight = parseFloat(form.weight_imp.value); 49 height = parseFloat(form.height_imp.value); 50 if (!(weight > 0 && height > 0)) { 51 Swal.fire({ 52 icon: 'warning', 53 title: 'Invalid Input', 54 text: aaHealthOptions.alert_invalid_input 55 }); 56 return; 57 } 58 bmi = 703 * weight / Math.pow(height, 2); 59 } else { 60 Swal.fire({ 61 icon: 'error', 62 title: 'Unknown Unit', 63 text: aaHealthOptions.alert_invalid_input 64 }); 65 return; 66 } 67 68 if (bmi < 18.5) { 69 meaning = aaHealthOptions.text_too_thin; 70 } else if (bmi < 25) { 71 meaning = aaHealthOptions.text_healthy; 72 } else { 73 meaning = aaHealthOptions.text_overweight; 74 } 75 76 bmiValue.textContent = bmi.toFixed(2); 77 bmiMeaning.textContent = meaning; 78 resultBlock.style.display = 'block'; 79 80 if (aaHealthOptions.show_categories === 'yes') { 81 var category = ''; 82 if (bmi < 16) category = 'Severe Thinness'; 83 else if (bmi < 17) category = 'Moderate Thinness'; 84 else if (bmi < 18.5) category = 'Mild Thinness'; 85 else if (bmi < 25) category = 'Normal'; 86 else if (bmi < 30) category = 'Overweight'; 87 else if (bmi < 35) category = 'Obese Class I'; 88 else if (bmi < 40) category = 'Obese Class II'; 89 else category = 'Obese Class III'; 90 91 categoryDiv.textContent = 'Category: ' + category; 92 categoryDiv.style.display = 'block'; 93 } else { 94 categoryDiv.style.display = 'none'; 95 } 96 97 if (aaHealthOptions.show_ideal_weight === 'yes') { 98 var minWeight, maxWeight; 99 if (unit === 'metric') { 100 minWeight = (18.5 * Math.pow(height / 100, 2)).toFixed(1); 101 maxWeight = (24.9 * Math.pow(height / 100, 2)).toFixed(1); 102 idealWeightDiv.textContent = 'Ideal Weight: ' + minWeight + ' kg - ' + maxWeight + ' kg'; 53 103 } else { 54 meaning = aaHealthOptions.text_overweight; 104 var heightMeters = height * 0.0254; 105 var minKg = 18.5 * heightMeters * heightMeters; 106 var maxKg = 24.9 * heightMeters * heightMeters; 107 minWeight = (minKg * 2.20462).toFixed(1); 108 maxWeight = (maxKg * 2.20462).toFixed(1); 109 idealWeightDiv.textContent = 'Ideal Weight: ' + minWeight + ' lbs - ' + maxWeight + ' lbs'; 55 110 } 111 idealWeightDiv.style.display = 'block'; 112 } else { 113 idealWeightDiv.style.display = 'none'; 114 } 56 115 57 bmiValue.textContent = bmi.toFixed(2); 58 bmiMeaning.textContent = meaning; 59 resultBlock.style.display = 'block'; 116 if (aaHealthOptions.show_health_tips === 'yes') { 117 var tip = tips[Math.floor(Math.random() * tips.length)]; 118 tipDiv.textContent = 'Tip: ' + tip; 119 tipDiv.style.display = 'block'; 120 } else { 121 tipDiv.style.display = 'none'; 122 } 60 123 61 if (aaHealthOptions.show_categories === 'yes') { 62 var category = ''; 63 if (bmi < 16) category = 'Severe Thinness'; 64 else if (bmi < 17) category = 'Moderate Thinness'; 65 else if (bmi < 18.5) category = 'Mild Thinness'; 66 else if (bmi < 25) category = 'Normal'; 67 else if (bmi < 30) category = 'Overweight'; 68 else if (bmi < 35) category = 'Obese Class I'; 69 else if (bmi < 40) category = 'Obese Class II'; 70 else category = 'Obese Class III'; 124 shareBtn.href = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent('My BMI is ' + bmi.toFixed(2) + ' - ' + meaning); 71 125 72 categoryDiv.textContent = 'Category: ' + category; 73 categoryDiv.style.display = 'block'; 126 downloadBtn.onclick = function(ev) { 127 ev.preventDefault(); 128 var content = 'BMI Report\n\n'; 129 if(unit === 'metric'){ 130 content += 'Weight: ' + weight + ' kg\nHeight: ' + height + ' cm\n'; 74 131 } else { 75 c ategoryDiv.style.display = 'none';132 content += 'Weight: ' + weight + ' lbs\nHeight: ' + height + ' inches\n'; 76 133 } 134 content += 'BMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning; 135 var blob = new Blob([content], { type: 'application/pdf' }); 136 var link = document.createElement('a'); 137 link.href = URL.createObjectURL(blob); 138 link.download = 'bmi-report.pdf'; 139 link.click(); 140 }; 77 141 78 if (aaHealthOptions.show_ideal_weight === 'yes') {79 var minWeight = (18.5 * Math.pow(height / 100, 2)).toFixed(1);80 var maxWeight = (24.9 * Math.pow(height / 100, 2)).toFixed(1);81 idealWeightDiv.textContent = 'Ideal Weight: ' + minWeight + ' kg - ' + maxWeight + ' kg';82 idealWeightDiv.style.display = 'block';142 emailBtn.onclick = function(ev) { 143 ev.preventDefault(); 144 var body = ''; 145 if(unit === 'metric'){ 146 body = 'Weight: ' + weight + ' kg\nHeight: ' + height + ' cm\n'; 83 147 } else { 84 idealWeightDiv.style.display = 'none';148 body = 'Weight: ' + weight + ' lbs\nHeight: ' + height + ' inches\n'; 85 149 } 86 87 if (aaHealthOptions.show_health_tips === 'yes') { 88 var tip = tips[Math.floor(Math.random() * tips.length)]; 89 tipDiv.textContent = 'Tip: ' + tip; 90 tipDiv.style.display = 'block'; 91 } else { 92 tipDiv.style.display = 'none'; 93 } 94 95 // Share on Twitter 96 shareBtn.href = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent('My BMI is ' + bmi.toFixed(2) + ' - ' + meaning); 97 98 // Download PDF (text-based) 99 downloadBtn.onclick = function(ev) { 100 ev.preventDefault(); 101 var content = 'BMI Report\n\nWeight: ' + weight + ' kg\nHeight: ' + height + ' cm\nBMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning; 102 var blob = new Blob([content], { type: 'application/pdf' }); 103 var link = document.createElement('a'); 104 link.href = URL.createObjectURL(blob); 105 link.download = 'bmi-report.pdf'; 106 link.click(); 107 }; 108 109 // Email report 110 emailBtn.onclick = function(ev) { 111 ev.preventDefault(); 112 window.location.href = 'mailto:?subject=' + encodeURIComponent('BMI Report') + '&body=' + encodeURIComponent('Weight: ' + weight + ' kg\nHeight: ' + height + ' cm\nBMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning); 113 }; 114 115 } else { 116 alert(aaHealthOptions.alert_invalid_input); 117 } 150 body += 'BMI: ' + bmi.toFixed(2) + '\nMeaning: ' + meaning; 151 window.location.href = 'mailto:?subject=' + encodeURIComponent('BMI Report') + '&body=' + encodeURIComponent(body); 152 }; 118 153 }); 119 154 }); -
aa-health-calculator/trunk/readme.txt
r3305050 r3305298 19 19 <li>Lightweight and mobile-friendly Best BMI calculator</li> 20 20 <li>Multilingual support with translation-ready text domain</li> 21 <li>Easy shortcode: <code>[aa-health ]</code> to embed calculator anywhere</li>21 <li>Easy shortcode: <code>[aa-health-calculator]</code> to embed calculator anywhere</li> 22 22 <li>Premium options configurable from admin panel</li> 23 23 <li>Display BMI categories, ideal weight range, and health tips</li> … … 34 34 <li>Install and activate the <strong>AA Health Calculator</strong> plugin in WordPress.</li> 35 35 <li>Go to the admin panel to configure premium options if needed.</li> 36 <li>Insert the shortcode <code>[aa-health ]</code> into any post, page, or widget.</li>36 <li>Insert the shortcode <code>[aa-health-calculator]</code> into any post, page, or widget.</li> 37 37 <li>Visitors enter their weight (kg) and height (cm) in the calculator form.</li> 38 38 <li>Click the "Calculate BMI" button to see their BMI and health info.</li>
Note: See TracChangeset
for help on using the changeset viewer.