How to use optimization method in storybook-root

Best JavaScript code snippet using storybook-root

wpoadmin.js

Source:wpoadmin.js Github

copy

Full Screen

...525 * @param {string} id - The optimization ID526 *527 * @return void528 */529 function do_optimization(id) {530 var $optimization_row = $('#wp-optimize-nav-tab-contents-optimize .wp-optimize-settings-' + id);531 if (!$optimization_row) {532 console.log("do_optimization: row corresponding to this optimization (" + id + ") not found");533 }534 // check if there any additional inputs checkboxes.535 var additional_data = {},536 additional_data_length = 0;537 $('input[type="checkbox"]', $('#optimization_info_' + id)).each(function() {538 var checkbox = $(this);539 if (checkbox.is(':checked')) {540 additional_data[checkbox.attr('name')] = checkbox.val();541 additional_data_length++;542 }543 });544 // don't run optimization if optimization active.545 if (true == $('.optimization_button_' + id).prop('disabled')) return;546 $('#optimization_checkbox_' + id).hide();547 $('#optimization_spinner_' + id).show();548 $('.optimization_button_' + id).prop('disabled', true);549 $('#optimization_info_' + id).html('...');550 // Check if it is DB optimize.551 if ('optimizetables' == id) {552 var optimization_tables = $('#wpoptimize_table_list #the-list tr');553 // Check if there are any tables to be optimized.554 $(optimization_tables).each(function (index) {555 // Get information from each td.556 var $table_information = $(this).find('td');557 // Get table type information.558 var table_type = $(this).data('type');559 var table = $(this).data('tablename');560 var optimizable = $(this).data('optimizable');561 // Make sure the table isnt blank.562 if ('' != table) {563 // Check if table is optimizable or optimization forced by user.564 if (1 == parseInt(optimizable) || optimization_force) {565 var data = {566 optimization_id: id,567 optimization_table: table,568 optimization_table_type: table_type,569 optimization_force: optimization_force570 };571 queue.enqueue(data);572 }573 }574 });575 } else if (additional_data_length > 0) {576 // check if additional data passed for optimization.577 data = {578 optimization_id: id579 };580 for (var i in additional_data) {581 if (!additional_data.hasOwnProperty(i)) continue;582 data[i] = additional_data[i];583 }584 queue.enqueue(data);585 } else {586 queue.enqueue(id);587 }588 process_queue();589 }590 /**591 * Run action and save selected sites list options.592 *593 * @param {function} action - action to do after save.594 *595 * @return void596 */597 function save_sites_list_and_do_action(action) {598 // if multisite mode then save sites list before action.599 if ($('#wpo_settings_sites_list').length) {600 // save wpo-sites settings.601 send_command('save_site_settings', {'wpo-sites': get_selected_sites_list()}, function () {602 // do action.603 if (action) action();604 });605 } else {606 // do action.607 if (action) action();608 }609 }610 /**611 * Returns list of selected sites list.612 *613 * @return {Array}614 */615 function get_selected_sites_list() {616 var wpo_sites = [];617 $('#wpo_settings_sites_list input[type="checkbox"]').each(function () {618 var checkbox = $(this);619 if (checkbox.is(':checked')) {620 wpo_sites.push(checkbox.attr('value'));621 }622 });623 return wpo_sites;624 }625 /**626 * Run single optimization click.627 */628 $('#wp-optimize-nav-tab-WP-Optimize-optimize-contents').on('click', 'button.wp-optimize-settings-optimization-run-button', function () {629 var optimization_id = $(this).closest('.wp-optimize-settings').data('optimization_id');630 if (!optimization_id) {631 console.log("Optimization ID corresponding to pressed button not found");632 return;633 }634 // if run button disabled then don't run this optimization.635 if (true == $('.optimization_button_' + optimization_id).prop('disabled')) return;636 // disable run button before save sites list.637 $('.optimization_button_' + optimization_id).prop('disabled', true);638 save_sites_list_and_do_action(function() {639 $('.optimization_button_' + optimization_id).prop('disabled', false);640 do_optimization(optimization_id);641 });642 });643 /**644 * Run all optimizations click.645 */646 $('#wp-optimize-nav-tab-WP-Optimize-optimize-contents').on('click', '#wp-optimize', function (e) {647 var run_btn = $(this);648 e.preventDefault();649 // disable run button to avoid double click.650 run_btn.prop('disabled', true);651 save_sites_list_and_do_action(function() {652 run_btn.prop('disabled', false);653 run_optimizations();654 });655 });656 /**657 * Sent command to run selected optimizations and auto backup if selected658 *659 * @return void660 */661 function run_optimizations() {662 var auto_backup = false;663 if ($('#enable-auto-backup').is(":checked")) {664 auto_backup = true;665 }666 // Save the click option.667 save_auto_backup_options();668 // Only run the backup if tick box is checked.669 if (auto_backup == true) {670 take_a_backup_with_updraftplus(run_optimization);671 } else {672 // Run optimizations.673 run_optimization();674 }675 }676 /**677 * Take a backup with UpdraftPlus if possible.678 *679 * @param {Function} callback680 * @param {String} file_entities681 *682 * @return void683 */684 function take_a_backup_with_updraftplus(callback, file_entities) {685 // Set default for file_entities to empty string686 if ('undefined' == typeof file_entities) file_entities = '';687 var exclude_files = file_entities ? 0 : 1;688 if (typeof updraft_backupnow_inpage_go === 'function') {689 updraft_backupnow_inpage_go(function () {690 // Close the backup dialogue.691 $('#updraft-backupnow-inpage-modal').dialog('close');692 if (callback) callback();693 }, file_entities, 'autobackup', 0, exclude_files, 0, wpoptimize.automatic_backup_before_optimizations);694 } else {695 if (callback) callback();696 }697 }698 /**699 * Save all auto backup options.700 *701 * @return void702 */703 function save_auto_backup_options() {704 var options = gather_settings('object');705 options['auto_backup'] = $('#enable-auto-backup').is(":checked");706 send_command('save_auto_backup_option', options);707 }708 // Show/hide sites list for multi-site settings.709 var wpo_settings_sites_list = $('#wpo_settings_sites_list'),710 wpo_settings_sites_list_ul = wpo_settings_sites_list.find('ul').first(),711 wpo_settings_sites_list_items = $('input[type="checkbox"]', wpo_settings_sites_list_ul),712 wpo_settings_all_sites_checkbox = wpo_settings_sites_list.find('#wpo_all_sites'),713 wpo_sitelist_show_moreoptions_link = $('#wpo_sitelist_show_moreoptions'),714 wpo_sitelist_moreoptions_div = $('#wpo_sitelist_moreoptions'),715 wpo_settings_sites_list_cron = $('#wpo_settings_sites_list_cron'),716 wpo_settings_sites_list_cron_ul = wpo_settings_sites_list_cron.find('ul').first(),717 wpo_settings_sites_list_cron_items = $('input[type="checkbox"]', wpo_settings_sites_list_cron_ul),718 wpo_settings_all_sites_cron_checkbox = wpo_settings_sites_list_cron.find('#wpo_all_sites_cron'),719 wpo_sitelist_show_moreoptions_cron_link = $('#wpo_sitelist_show_moreoptions_cron'),720 wpo_sitelist_moreoptions_cron_div = $('#wpo_sitelist_moreoptions_cron');721 // sites list for manual run.722 define_moreoptions_settings(723 wpo_sitelist_show_moreoptions_link,724 wpo_sitelist_moreoptions_div,725 wpo_settings_all_sites_checkbox,726 wpo_settings_sites_list_items727 );728 var sites_list_clicked_count = 0;729 $([wpo_settings_all_sites_checkbox, wpo_settings_sites_list_items]).each(function() {730 $(this).on('change', function() {731 sites_list_clicked_count++;732 setTimeout(function() {733 sites_list_clicked_count--;734 if (sites_list_clicked_count == 0) update_optimizations_info();735 }, 1000);736 });737 });738 // sites list for cron run.739 define_moreoptions_settings(740 wpo_sitelist_show_moreoptions_cron_link,741 wpo_sitelist_moreoptions_cron_div,742 wpo_settings_all_sites_cron_checkbox,743 wpo_settings_sites_list_cron_items744 );745 /**746 * Attach event handlers for more options list showed by clicking on show_moreoptions_link.747 *748 * @param show_moreoptions_link749 * @param more_options_div750 * @param all_items_checkbox751 * @param items_list752 *753 * @return boolean754 */755 function define_moreoptions_settings(show_moreoptions_link, more_options_div, all_items_checkbox, items_list) {756 // toggle show options on click.757 show_moreoptions_link.on('click', function () {758 if (!more_options_div.hasClass('wpo_always_visible')) more_options_div.toggleClass('wpo_hidden');759 return false;760 });761 // if "all items" checked/unchecked then check/uncheck items in the list.762 define_select_all_checkbox(all_items_checkbox, items_list);763 }764 /**765 * Defines "select all" check box, where all_items_checkbox is a select all check box jQuery object766 * and items_list is a list of checkboxes assigned with all_items_checkbox.767 *768 * @param {Object} all_items_checkbox769 * @param {Object} items_list770 *771 * @return void772 */773 function define_select_all_checkbox(all_items_checkbox, items_list) {774 // if "all items" checked/unchecked then check/uncheck items in the list.775 all_items_checkbox.on('change', function () {776 if (all_items_checkbox.is(':checked')) {777 items_list.prop('checked', true);778 } else {779 items_list.prop('checked', false);780 }781 update_wpo_all_items_checkbox_state(all_items_checkbox, items_list);782 });783 items_list.on('change', function () {784 update_wpo_all_items_checkbox_state(all_items_checkbox, items_list);785 });786 update_wpo_all_items_checkbox_state(all_items_checkbox, items_list);787 }788 /**789 * Update state of "all items" checkbox depends on state all items in the list.790 *791 * @param all_items_checkbox792 * @param all_items793 *794 * @return void795 */796 function update_wpo_all_items_checkbox_state(all_items_checkbox, all_items) {797 var all_items_count = 0, checked_items_count = 0;798 all_items.each(function () {799 if ($(this).is(':checked')) {800 checked_items_count++;801 }802 all_items_count++;803 });804 // update label text if need.805 if (all_items_checkbox.next().is('label') && all_items_checkbox.next().data('label')) {806 var label = all_items_checkbox.next(),807 label_mask = label.data('label');808 if (all_items_count == checked_items_count) {809 label.text(label_mask);810 } else {811 label.text(label_mask.replace('all', [checked_items_count, ' of ', all_items_count].join('')));812 }813 }814 if (all_items_count == checked_items_count) {815 all_items_checkbox.prop('checked', true);816 } else {817 all_items_checkbox.prop('checked', false);818 }819 }820 /**821 * Running the optimizations for the selected options822 *823 * @return {[type]} optimizations824 */825 function run_optimization() {826 $optimizations = $('#optimizations_list .optimization_checkbox:checked');827 $optimizations.sort(function (a, b) {828 // Convert to IDs.829 a = $(a).closest('.wp-optimize-settings').data('optimization_run_sort_order');830 b = $(b).closest('.wp-optimize-settings').data('optimization_run_sort_order');831 if (a > b) {832 return 1;833 } else if (a < b) {834 return -1;835 } else {836 return 0;837 }838 });839 var optimization_options = {};840 $optimizations.each(function (index) {841 var optimization_id = $(this).closest('.wp-optimize-settings').data('optimization_id');842 if (!optimization_id) {843 console.log("Optimization ID corresponding to pressed button not found");844 return;845 }846 // An empty object - in future, options may be implemented.847 optimization_options[optimization_id] = { active: 1 };848 do_optimization(optimization_id);849 });850 send_command('save_manual_run_optimization_options', optimization_options);851 }852 /**853 * Uptate the tables list854 *855 * @param {object} response856 */857 function update_tables_list(response) {858 if (response.hasOwnProperty('table_list')) {859 var resort = true,860 // add a callback, as desired861 callback = function(table) {862 $('#wpoptimize_table_list tbody').css('opacity', '1');863 };864 // update body with new content.865 $("#wpoptimize_table_list tbody").remove();866 $("#wpoptimize_table_list thead").after(response.table_list);867 $("#wpoptimize_table_list").trigger("updateAll", [resort, callback]);868 }869 if (response.hasOwnProperty('total_size')) {870 $('#optimize_current_db_size').html(response.total_size);871 }872 if (response.hasOwnProperty('show_innodb_force_optimize')) {873 $('.innodb_force_optimize--container').toggleClass('hidden', !response.show_innodb_force_optimize);874 }875 change_actions_column_visibility();876 update_single_table_optimization_buttons(force_single_table_optimization);877 }878 $('#wp_optimize_table_list_refresh').on('click', function (e) {879 880 e.preventDefault();881 var shade = $(this).closest('.wpo-tab-postbox').find('.wpo_shade');882 shade.removeClass('hidden');883 $('#wpoptimize_table_list tbody').css('opacity', '0.5');884 send_command('get_table_list', {refresh_plugin_json: true}, update_tables_list).always(function() {885 shade.addClass('hidden');886 });887 });888 $('#database_settings_form, #settings_form').on('click', '.wpo-save-settings', function (e) {889 e.preventDefault();890 var form = $(this).closest('form');891 var spinner = form.find('.wpo-saving-settings');892 var form_data = gather_settings();893 form.trigger('wpo-saving-form-data');894 if (form.form_errors.has_errors()) return;895 spinner.show();896 // when optimizations list in the document - send information about selected optimizations.897 if ($('#optimizations_list').length) {898 $('#optimizations_list .optimization_checkbox:checked').each(function() {899 var optimization_id = $(this).closest('.wp-optimize-settings').data('optimization_id');900 if (optimization_id) {901 form_data += '&optimization-options['+optimization_id+'][active]=1';902 }903 });904 }905 if ($('#purge_cache_permissions').length) {906 if (!$('#purge_cache_permissions').val()) {907 form_data += '&purge_cache_permissions[]';908 }909 }910 send_command('save_settings', form_data, function (resp) {911 spinner.closest('div').find('.save-done').show().delay(5000).fadeOut();912 if (resp && resp.hasOwnProperty('save_results') && resp.save_results && resp.save_results.hasOwnProperty('errors')) {913 for (var i = 0, len = resp.save_results.errors.length; i < len; i++) {914 var new_html = '<div class="error">' + resp.errors[i] + '</div>';915 temporarily_display_notice(new_html, '#wp-optimize-settings-save-results');916 }917 console.log(resp.save_results.messages);918 }919 if (resp && resp.hasOwnProperty('status_box_contents')) {920 $(resp.status_box_contents).each(function(index, el) {921 if ($(el).is('#wp_optimize_status_box')) {922 $('#wp_optimize_status_box').replaceWith($(el));923 }924 });925 }926 if (resp && resp.hasOwnProperty('optimizations_table')) {927 $('#optimizations_list').replaceWith(resp.optimizations_table);928 }929 // Need to refresh the page if enable-admin-menu tick state has changed.930 if (resp.save_results.refresh) {931 location.reload();932 }933 }).always(function() {934 spinner.hide();935 });936 });937 /**938 * Handle Wipe Settings click.939 */940 $('#settings_form').on('click', '.wpo-wipe-settings', function() {941 var spinner = $(this).parent().find('.wpo_spinner');942 spinner.show();943 send_command('wipe_settings', {}, function() {944 spinner.next().removeClass('display-none').delay(5000).fadeOut();945 alert(wpoptimize.settings_have_been_deleted_successfully);946 location.replace(wpoptimize.settings_page_url);947 }).always(function() {948 spinner.hide();949 });950 });951 $('#wp-optimize-wrap').on('click', '#wp_optimize_status_box_refresh', function (e) {952 e.preventDefault();953 $('#wp_optimize_status_box').css('opacity', '0.5');954 send_command('get_status_box_contents', null, function (resp) {955 $('#wp_optimize_status_box').css('opacity', '1');956 $(resp).each(function(index, el) {957 if ($(el).is('#wp_optimize_status_box')) {958 $('#wp_optimize_status_box').replaceWith($(el));959 }960 });961 });962 });963 /**964 * Run single table optimization. Handle click on Optimize button.965 *966 * @param {Object} btn jQuery object clicked Optimize button967 *968 * @return {void}969 */970 function run_single_table_optimization(btn) {971 var spinner = btn.next(),972 action_done_icon = spinner.next(),973 table_name = btn.data('table'),974 table_type = btn.data('type'),975 data = {976 optimization_id: 'optimizetables',977 optimization_table: table_name,978 optimization_table_type: table_type979 };980 btn.hide();981 // if checked force button then send force value.982 if (force_single_table_optimization) {983 data['optimization_force'] = true;984 }985 spinner.removeClass('visibility-hidden');986 send_command('do_optimization', { optimization_id: 'optimizetables', data: data }, function (response) {987 if (response.result.meta.tableinfo) {988 var row = btn.closest('tr'),989 meta = response.result.meta,990 tableinfo = meta.tableinfo;991 update_single_table_information(row, tableinfo);992 // update total overhead.993 $('#wpoptimize_table_list > tbody:last th:eq(6)').html(['<span style="color:', meta.overhead > 0 ? '#0000FF' : '#004600', '">', meta.overhead_formatted,'</span>'].join(''));994 }995 btn.prop('disabled', false);996 spinner.addClass('visibility-hidden');997 action_done_icon.show().removeClass('visibility-hidden').delay(2500).fadeOut('fast', function() {998 btn.show();999 });1000 });1001 }1002 /**1003 * Update information about single table in the database tables list.1004 *1005 * @param {Object} row jQuery object for TR html tag.1006 * @param {Object} tableinfo1007 *1008 * @return {void}1009 */1010 function update_single_table_information(row, tableinfo) {1011 // update table information in row.1012 $('td:eq(2)', row).text(tableinfo.rows);1013 $('td:eq(3)', row).text(tableinfo.data_size);1014 $('td:eq(4)', row).text(tableinfo.index_size);1015 $('td:eq(5)', row).text(tableinfo.type);1016 if (tableinfo.is_optimizable) {1017 $('td:eq(6)', row).html(['<span style="color:', tableinfo.overhead > 0 ? '#0000FF' : '#004600', '">', tableinfo.overhead,'</span>'].join(''));1018 } else {1019 $('td:eq(6)', row).html('<span color="#0000FF">-</span>');1020 }1021 }1022 /**1023 * Update single table optimization buttons state depends on force_optimization value.1024 *1025 * @param {boolean} force_optimization See if we need to force optimization1026 *1027 * @return {void}1028 */1029 function update_single_table_optimization_buttons(force_optimization) {1030 $('.run-single-table-optimization').each(function() {1031 var btn = $(this);1032 if (btn.data('disabled')) {1033 if (force_optimization) {1034 btn.prop('disabled', false);1035 } else {1036 btn.prop('disabled', true);1037 }1038 }1039 });1040 }1041 /**1042 * Returns true if single site mode or multisite and at least one site selected;1043 *1044 * @return {boolean}1045 */1046 function is_sites_selected() {1047 return (0 == wpo_settings_sites_list.length || 0 != $('input[type="checkbox"]:checked', wpo_settings_sites_list).length);1048 }1049 /**1050 * Update optimizations info texts.1051 *1052 * @param {Object} response object returned by command get_optimizations_info.1053 *1054 * @return {void}1055 */1056 function update_optimizations_info_view(response) {1057 var i, dom_id, info;1058 // @codingStandardsIgnoreLine1059 if (!response) return;1060 for (i in response) {1061 if (!response.hasOwnProperty(i)) continue;1062 dom_id = ['#wp-optimize-settings-', response[i].dom_id].join('');1063 info = response[i].info ? response[i].info.join('<br>') : '';1064 $(dom_id + ' .wp-optimize-settings-optimization-info').html(info);1065 }1066 }1067 var get_optimizations_info_cache = {};1068 /**1069 * Send command for get optimizations info and update view.1070 *1071 * @return {void}1072 */1073 function update_optimizations_info() {1074 var cache_key = ['', get_selected_sites_list().join('_')].join('');1075 // if information saved in cache show it.1076 if (get_optimizations_info_cache.hasOwnProperty(cache_key)) {1077 update_optimizations_info_view(get_optimizations_info_cache[cache_key]);1078 } else {1079 // else send command update cache and update view.1080 send_command('get_optimizations_info', {'wpo-sites':get_selected_sites_list()}, function(response) {1081 // @codingStandardsIgnoreLine1082 if (!response) return;1083 get_optimizations_info_cache[cache_key] = response;1084 update_optimizations_info_view(response);1085 });1086 }1087 }1088 /**1089 * Check if settings file selected for import.1090 */1091 $('#wpo_import_settings_btn').on('click', function(e) {1092 var file_input = $('#wpo_import_settings_file'),1093 filename = file_input.val(),1094 wpo_import_file_file = file_input[0].files[0],1095 wpo_import_file_reader = new FileReader();1096 $('#wpo_import_settings_btn').prop('disabled', true);1097 if (!/\.json$/.test(filename)) {1098 e.preventDefault();1099 $('#wpo_import_settings_btn').prop('disabled', false);1100 $('#wpo_import_error_message').text(wpoptimize.please_select_settings_file).slideDown();1101 return false;1102 }1103 wpo_import_file_reader.onload = function() {1104 import_settings(this.result);1105 };1106 wpo_import_file_reader.readAsText(wpo_import_file_file);1107 return false;1108 });1109 /**1110 * Send import settings command.1111 *1112 * @param {string} settings encoded settings in json string.1113 *1114 * @return {void}1115 */1116 function import_settings(settings) {1117 var loader = $('#wpo_import_spinner'),1118 success_message = $('#wpo_import_success_message'),1119 error_message = $('#wpo_import_error_message');1120 loader.show();1121 send_command('import_settings', {'settings': settings}, function(response) {1122 loader.hide();1123 if (response && response.errors && response.errors.length) {1124 error_message.text(response.errors.join('<br>'));1125 error_message.slideDown();1126 } else if (response && response.messages && response.messages.length) {1127 success_message.text(response.messages.join('<br>'));1128 success_message.slideDown();1129 setTimeout(function() {1130 window.location.reload();1131 }, 500);1132 }1133 $('#wpo_import_settings_btn').prop('disabled', false);1134 });1135 }1136 /**1137 * Hide file validation message on change file field value.1138 */1139 $('#wpo_import_settings_file').on('change', function() {1140 $('#wpo_import_error_message').slideUp();1141 });1142 /**1143 * Save settings to hidden form field, used for export.1144 */1145 $('#wpo_export_settings_btn').on('click', function(e) {1146 wpo_download_json_file(gather_settings('object'));1147 return false;1148 });1149 /**1150 * Force download json file with posted data.1151 *1152 * @param {Object} data data to put in a file.1153 * @param {string} filename1154 *1155 * @return {void}1156 */1157 function wpo_download_json_file(data ,filename) {1158 // Attach this data to an anchor on page1159 var link = document.body.appendChild(document.createElement('a')),1160 date = new Date(),1161 year = date.getFullYear(),1162 month = date.getMonth() < 10 ? ['0', date.getMonth()].join('') : date.getMonth(),1163 day = date.getDay() < 10 ? ['0', date.getDay()].join('') : date.getDay();1164 filename = filename ? filename : ['wpo-settings-',year,'-',month,'-',day,'.json'].join('');1165 link.setAttribute('download', filename);1166 link.setAttribute('style', "display:none;");1167 link.setAttribute('href', 'data:text/json' + ';charset=UTF-8,' + encodeURIComponent(JSON.stringify(data)));1168 link.click();1169 }1170 /**1171 * Make ajax request to get optimization info.1172 *1173 * @param {Object} optimization_info_container - jquery object obtimization info container.1174 * @param {string} optimization_id - optimization id.1175 * @param {Object} params - custom params posted to optimization get info.1176 *1177 * @return void1178 */1179 var optimization_get_info = function(optimization_info_container, optimization_id, params) {1180 return send_command('get_optimization_info', {optimization_id: optimization_id, data: params}, function(resp) {1181 var meta = (resp && resp.result && resp.result.meta) ? resp.result.meta : {},1182 message = (resp && resp.result && resp.result.output) ? resp.result.output.join('<br>') : '...';1183 // trigger event about optimization get info in process.1184 $(document).trigger(['optimization_get_info_', optimization_id].join(''), [message, meta]);1185 // update status message in optimizations list.1186 optimization_info_container.html(message);1187 if (!meta.finished) {1188 setTimeout(function() {1189 var xhr = optimization_get_info(optimization_info_container, optimization_id, meta);1190 $(document).trigger(['optimization_get_info_xhr_', optimization_id].join(''), [xhr, meta]);1191 }, 1);1192 } else {1193 // trigger event about optimization get info action done.1194 $(document).trigger(['optimization_get_info_', optimization_id, '_done'].join(''), resp);1195 }1196 });1197 };1198 /**1199 * Handle ajax information for optimizations.1200 *1201 * @return void1202 */1203 jQuery(function() {1204 $('.wp-optimize-optimization-info-ajax').each(function () {1205 var optimization_info = $(this),1206 optimization_info_container = optimization_info.parent(),1207 optimization_id = optimization_info.data('id');1208 // trigger event about optimization get info action started.1209 $(document).trigger(['optimization_get_info_', optimization_id, '_start'].join(''));1210 optimization_get_info(optimization_info_container, optimization_id, {support_ajax_get_info: true});1211 });1212 });1213 // attach event handlers after database tables template loaded.1214 // Handle single optimization click.1215 $('#wpoptimize_table_list').on('click', '.run-single-table-optimization', function () {1216 var take_backup_checkbox = $('#enable-auto-backup-1'),1217 button = $(this);1218 // check if backup checkbox is checked for db tables1219 if (take_backup_checkbox.is(':checked')) {1220 take_a_backup_with_updraftplus(1221 function () {1222 run_single_table_optimization(button);1223 }1224 );1225 } else {1226 run_single_table_optimization(button);1227 }1228 });1229 // Handle repair table click1230 $('#wpoptimize_table_list').on('click', '.run-single-table-repair', function () {1231 var btn = $(this),1232 spinner = btn.next(),1233 action_done_icon = spinner.next(),1234 table_name = btn.data('table'),1235 data = {1236 optimization_id: 'repairtables',1237 optimization_table: table_name1238 };1239 spinner.removeClass('visibility-hidden');1240 send_command('do_optimization', {optimization_id: 'repairtables', data: data}, function (response) {...

Full Screen

Full Screen

wpadmin.js

Source:wpadmin.js Github

copy

Full Screen

...333 * @param {string} id - The optimization ID334 *335 * @return void336 */337 function do_optimization(id) {338 var $optimization_row = $('#wp-optimize-nav-tab-contents-optimize .wp-optimize-settings-' + id);339 if (!$optimization_row) {340 console.log("do_optimization: row corresponding to this optimization (" + id + ") not found");341 }342 // don't run optimization if optimization active.343 if (true == $('.optimization_button_' + id).prop('disabled')) return;344 $('#optimization_checkbox_' + id).hide();345 $('#optimization_spinner_' + id).show();346 $('.optimization_button_' + id).prop('disabled', true);347 $('#optimization_info_' + id).html('...');348 // Check if it is DB optimize.349 if ('optimizetables' == id) {350 var optimization_tables = $('#wpoptimize_table_list #the-list tr');351 // Check if there are any tables to be optimized.352 $(optimization_tables).each(function (index) {353 // Get information from each td.354 var $table_information = $(this).find('td');355 // Get table type information.356 table_type = $table_information.eq(5).text();357 table = $table_information.eq(1).text();358 optimizable = $table_information.eq(5).data('optimizable');359 // Make sure the table isnt blank.360 if ('' != table) {361 // Check if table is optimizable or optimization forced by user.362 if ('1' == optimizable || optimization_force) {363 var data = {364 optimization_id: id,365 optimization_table: $table_information.eq(1).text(),366 optimization_table_type: table_type,367 optimization_force: optimization_force368 };369 queue.enqueue(data);370 }371 }372 });373 } else {374 queue.enqueue(id);375 }376 process_queue();377 }378 /**379 * Run action and save selected sites list options.380 *381 * @param {function} action - action to do after save.382 *383 * @return void384 */385 function save_sites_list_and_do_action(action) {386 // if multisite mode then save sites list before action.387 if ($('#wpo_settings_sites_list').length) {388 // save wpo-sites settings.389 send_command('save_site_settings', {'wpo-sites': get_selected_sites_list()}, function () {390 // do action.391 if (action) action();392 });393 } else {394 // do action.395 if (action) action();396 }397 }398 /**399 * Returns list of selected sites list.400 *401 * @return {Array}402 */403 function get_selected_sites_list() {404 var wpo_sites = [];405 $('#wpo_settings_sites_list input[type="checkbox"]').each(function () {406 var checkbox = $(this);407 if (checkbox.is(':checked')) {408 wpo_sites.push(checkbox.attr('value'));409 }410 });411 return wpo_sites;412 }413 /**414 * Run single optimization click.415 */416 $('#wp-optimize-nav-tab-contents-optimize').on('click', 'button.wp-optimize-settings-optimization-run-button', function () {417 var optimization_id = $(this).closest('.wp-optimize-settings').data('optimization_id');418 if (!optimization_id) {419 console.log("Optimization ID corresponding to pressed button not found");420 return;421 }422 // if run button disabled then don't run this optimization.423 if (true == $('.optimization_button_' + optimization_id).prop('disabled')) return;424 // disable run button before save sites list.425 $('.optimization_button_' + optimization_id).prop('disabled', true);426 save_sites_list_and_do_action(function() {427 $('.optimization_button_' + optimization_id).prop('disabled', false);428 do_optimization(optimization_id);429 });430 });431 /**432 * Run all optimizations click.433 */434 $('#wp-optimize-nav-tab-contents-optimize').on('click', '#wp-optimize', function (e) {435 var run_btn = $(this);436 e.preventDefault();437 // disable run button to avoid double click.438 run_btn.prop('disabled', true);439 save_sites_list_and_do_action(function() {440 run_btn.prop('disabled', false);441 run_optimizations();442 });443 });444 /**445 * Sent command to run selected optimizations and auto backup if selected446 *447 * @return void448 */449 function run_optimizations() {450 var auto_backup = false;451 if ($('#enable-auto-backup').is(":checked")) {452 auto_backup = true;453 }454 // Save the click option.455 save_auto_backup_options();456 // Only run the backup if tick box is checked.457 if (auto_backup == true) {458 take_a_backup_with_updraftplus(run_optimization);459 } else {460 // Run optimizations.461 run_optimization();462 }463 }464 /**465 * Take a backup with UpdraftPlus if possible.466 *467 * @param {Function} callback468 *469 * @return void470 */471 function take_a_backup_with_updraftplus(callback) {472 // Only run the backup if tick box is checked.473 if (typeof updraft_backupnow_inpage_go === 'function') {474 updraft_backupnow_inpage_go(function () {475 // Close the backup dialogue.476 $('#updraft-backupnow-inpage-modal').dialog('close');477 if (callback) callback();478 }, '', 'autobackup', 0, 1, 0, wpoptimize.automatic_backup_before_optimizations);479 } else {480 if (callback) callback();481 }482 }483 /**484 * Save all auto backup options.485 *486 * @return void487 */488 function save_auto_backup_options() {489 var options = gather_settings('object');490 options['auto_backup'] = $('#enable-auto-backup').is(":checked");491 send_command('save_auto_backup_option', options);492 }493 // Show/hide sites list for multi-site settings.494 var wpo_settings_sites_list = $('#wpo_settings_sites_list'),495 wpo_settings_sites_list_ul = wpo_settings_sites_list.find('ul').first(),496 wpo_settings_sites_list_items = $('input[type="checkbox"]', wpo_settings_sites_list_ul),497 wpo_settings_all_sites_checkbox = wpo_settings_sites_list.find('#wpo_all_sites'),498 wpo_sitelist_show_moreoptions_link = $('#wpo_sitelist_show_moreoptions'),499 wpo_sitelist_moreoptions_div = $('#wpo_sitelist_moreoptions'),500 wpo_settings_sites_list_cron = $('#wpo_settings_sites_list_cron'),501 wpo_settings_sites_list_cron_ul = wpo_settings_sites_list_cron.find('ul').first(),502 wpo_settings_sites_list_cron_items = $('input[type="checkbox"]', wpo_settings_sites_list_cron_ul),503 wpo_settings_all_sites_cron_checkbox = wpo_settings_sites_list_cron.find('#wpo_all_sites_cron'),504 wpo_sitelist_show_moreoptions_cron_link = $('#wpo_sitelist_show_moreoptions_cron'),505 wpo_sitelist_moreoptions_cron_div = $('#wpo_sitelist_moreoptions_cron');506 // sites list for manual run.507 define_moreoptions_settings(508 wpo_sitelist_show_moreoptions_link,509 wpo_sitelist_moreoptions_div,510 wpo_settings_all_sites_checkbox,511 wpo_settings_sites_list_items512 );513 var sites_list_clicked_count = 0;514 $([wpo_settings_all_sites_checkbox, wpo_settings_sites_list_items]).each(function() {515 $(this).on('change', function() {516 sites_list_clicked_count++;517 setTimeout(function() {518 sites_list_clicked_count--;519 if (sites_list_clicked_count == 0) update_optimizations_info();520 }, 1000);521 });522 });523 // sites list for cron run.524 define_moreoptions_settings(525 wpo_sitelist_show_moreoptions_cron_link,526 wpo_sitelist_moreoptions_cron_div,527 wpo_settings_all_sites_cron_checkbox,528 wpo_settings_sites_list_cron_items529 );530 /**531 * Attach event handlers for more options list showed by clicking on show_moreoptions_link.532 *533 * @param show_moreoptions_link534 * @param more_options_div535 * @param all_items_checkbox536 * @param items_list537 *538 * @return boolean539 */540 function define_moreoptions_settings(show_moreoptions_link, more_options_div, all_items_checkbox, items_list) {541 // toggle show options on click.542 show_moreoptions_link.on('click', function () {543 if (!more_options_div.hasClass('wpo_always_visible')) more_options_div.toggleClass('wpo_hidden');544 return false;545 });546 // if "all items" checked/unchecked then check/uncheck items in the list.547 all_items_checkbox.on('change', function () {548 if (all_items_checkbox.is(':checked')) {549 items_list.prop('checked', true);550 } else {551 items_list.prop('checked', false);552 }553 update_wpo_all_items_checkbox_state(all_items_checkbox, items_list);554 });555 items_list.on('change', function () {556 update_wpo_all_items_checkbox_state(all_items_checkbox, items_list);557 });558 update_wpo_all_items_checkbox_state(all_items_checkbox, items_list);559 }560 /**561 * Update state of "all items" checkbox depends on state all items in the list.562 *563 * @param all_items_checkbox564 * @param all_items565 *566 * @return void567 */568 function update_wpo_all_items_checkbox_state(all_items_checkbox, all_items) {569 var all_items_count = 0, checked_items_count = 0;570 all_items.each(function () {571 if ($(this).is(':checked')) {572 checked_items_count++;573 }574 all_items_count++;575 });576 // update label text if need.577 if (all_items_checkbox.next().is('label') && all_items_checkbox.next().data('label')) {578 var label = all_items_checkbox.next(),579 label_mask = label.data('label');580 if (all_items_count == checked_items_count) {581 label.text(label_mask);582 } else {583 label.text(label_mask.replace('all', [checked_items_count, ' of ', all_items_count].join('')));584 }585 }586 if (all_items_count == checked_items_count) {587 all_items_checkbox.prop('checked', true);588 } else {589 all_items_checkbox.prop('checked', false);590 }591 }592 /**593 * Running the optimizations for the selected options594 *595 * @return {[type]} optimizations596 */597 function run_optimization() {598 $optimizations = $('#optimizations_list .optimization_checkbox:checked');599 $optimizations.sort(function (a, b) {600 // Convert to IDs.601 a = $(a).closest('.wp-optimize-settings').data('optimization_run_sort_order');602 b = $(b).closest('.wp-optimize-settings').data('optimization_run_sort_order');603 if (a > b) {604 return 1;605 } else if (a < b) {606 return -1;607 } else {608 return 0;609 }610 });611 var optimization_options = {};612 $optimizations.each(function (index) {613 var optimization_id = $(this).closest('.wp-optimize-settings').data('optimization_id');614 if (!optimization_id) {615 console.log("Optimization ID corresponding to pressed button not found");616 return;617 }618 // An empty object - in future, options may be implemented.619 optimization_options[optimization_id] = { active: 1 };620 do_optimization(optimization_id);621 });622 send_command('save_manual_run_optimization_options', optimization_options);623 }624 625 $('#wp_optimize_table_list_refresh').click(function () {626 627 $('#wpoptimize_table_list tbody').css('opacity', '0.5');628 send_command('get_table_list', false, function (response) {629 630 if (response.hasOwnProperty('table_list')) {631 var resort = true,632 // add a callback, as desired633 callback = function(table) {634 $('#wpoptimize_table_list tbody').css('opacity', '1');...

Full Screen

Full Screen

normalize-optimization.js

Source:normalize-optimization.js Github

copy

Full Screen

1"use strict";2/**3 * @license4 * Copyright Google LLC All Rights Reserved.5 *6 * Use of this source code is governed by an MIT-style license that can be7 * found in the LICENSE file at https://angular.io/license8 */9Object.defineProperty(exports, "__esModule", { value: true });10exports.normalizeOptimization = void 0;11function normalizeOptimization(optimization = true) {12 if (typeof optimization === 'object') {13 return {14 scripts: !!optimization.scripts,15 styles: typeof optimization.styles === 'object'16 ? optimization.styles17 : {18 minify: !!optimization.styles,19 inlineCritical: !!optimization.styles,20 },21 fonts: typeof optimization.fonts === 'object'22 ? optimization.fonts23 : {24 inline: !!optimization.fonts,25 },26 };27 }28 return {29 scripts: optimization,30 styles: {31 minify: optimization,32 inlineCritical: optimization,33 },34 fonts: {35 inline: optimization,36 },37 };38}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getStorybookUI, configure } from '@storybook/react-native';2import { loadStories } from './storyLoader';3configure(() => {4 loadStories();5}, module);6const StorybookUIRoot = getStorybookUI({ port: 7007, host: 'localhost' });7export default StorybookUIRoot;8import { configure } from '@storybook/react-native';9configure(() => {10 require('./stories');11}, module);12import { storiesOf } from '@storybook/react-native';13import React from 'react';14import { Text, View } from 'react-native';15storiesOf('Welcome', module).add('to Storybook', () => (16 <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>17));

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withRootDecorator } from 'storybook-root-decorator';2import { addDecorator, addParameters } from '@storybook/react';3import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';4addDecorator(withRootDecorator);5addParameters({6 viewport: {7 },8});9storiesOf('Storybook', module)10 .add('with root decorator', () => <div>Story with root decorator</div>);11import { configure } from '@storybook/react';12import 'storybook-root-decorator/register';13configure(require.context('../src', true, /\.stories\.js$/), module);14const path = require('path');15module.exports = (baseConfig, env, config) => {16 config.module.rules.push({17 test: /\.(ts|tsx)$/,18 {19 loader: require.resolve('awesome-typescript-loader'),20 options: {21 configFileName: path.resolve(__dirname, '../tsconfig.json'),22 },23 },24 {25 loader: require.resolve('react-docgen-typescript-loader'),26 },27 });28 config.resolve.extensions.push('.ts', '.tsx');29 return config;30};31import { addDecorator } from '@storybook/react';32import { withRootDecorator } from 'storybook-root-decorator';33addDecorator(withRootDecorator);34{35 "scripts": {36 },37 "devDependencies": {38 "@babel/plugin-syntax-dynamic-import": "^7.2.0",

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withPerformance } from 'storybook-addon-performance';2export default {3};4export const MyStory = () => (5);6MyStory.story = {7 parameters: {8 performance: {9 },10 },11};12import { addDecorator } from '@storybook/react';13import { withPerformance } from 'storybook-addon-performance';14addDecorator(withPerformance);15import { addons } from '@storybook/addons';16import { register } from 'storybook-addon-performance';17addons.register('storybook-addon-performance', register);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addDecorator } from '@storybook/react'2import { withOptimizedResize } from 'storybook-root'3addDecorator(withOptimizedResize)4import { addDecorator } from '@storybook/react'5import { withOptimizedResize } from 'storybook-root'6addDecorator(withOptimizedResize)7const withOptimizedResize = require('storybook-root').withOptimizedResize8module.exports = {9 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],10 webpackFinal: async (config) => {11 config.module.rules.push({12 loaders: [require.resolve('@storybook/source-loader')],13 })14 config.module.rules.push({15 })16 },17}18const withOptimizedResize = require('storybook-root').withOptimizedResize19module.exports = {20 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],21 webpackFinal: async (config) => {22 config.module.rules.push({23 loaders: [require.resolve('@storybook/source-loader')],24 })25 config.module.rules.push({26 })27 },28}29const withOptimizedResize = require('storybook-root').withOptimizedResize30module.exports = {31 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],

Full Screen

Using AI Code Generation

copy

Full Screen

1const rootAlias = require('storybook-root-alias');2rootAlias();3const absolutePath = require('storybook-absolute-path');4absolutePath();5const path = require('path');6module.exports = {7 stories: ['../src/**/*.stories.(js|mdx)'],8 {9 options: {10 },11 },12 webpackFinal: async config => {13 config.resolve = {14 alias: {15 '@components': path.resolve(__dirname, '../src/components'),16 '@pages': path.resolve(__dirname, '../src/pages'),17 '@hooks': path.resolve(__dirname, '../src/hooks'),18 '@utils': path.resolve(__dirname, '../src/utils'),19 '@styles': path.resolve(__dirname, '../src/styles'),20 '@constants': path.resolve(__dirname, '../src/constants'),21 '@services': path.resolve(__dirname, '../src/services'),22 '@store': path.resolve(__dirname, '../src/store'),23 '@assets': path.resolve(__dirname, '../src/assets'),24 '@api': path.resolve(__dirname, '../src/api'),25 '@containers': path.resolve(__dirname, '../src/containers'),26 '@routes': path.resolve(__dirname,

Full Screen

Using AI Code Generation

copy

Full Screen

1const {optimize} = require('storybook-root');2const storybook = require('./storybook.json');3const optimizedStorybook = optimize(storybook);4console.log(optimizedStorybook);5const {optimize} = require('storybook-root');6const storybook = require('./storybook.json');7const optimizedStorybook = optimize(storybook, {8});9console.log(optimizedStorybook);10const {optimize} = require('storybook-root');11const storybook = require('./storybook.json');12const optimizedStorybook = optimize(storybook, {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful