Best JavaScript code snippet using wpt
omniva_manifest.js
Source:omniva_manifest.js
1(function($) {2 /* Checkbox events */3 $(document).on('click', '.check-all', function() {4 var checked = $(this).prop('checked');5 $(this).parents('table').find('.manifest-item').each(function() {6 $(this).prop('checked', checked);7 omniva_update_checked_list(this);8 });9 });10 $(document).on('change','input.manifest-item', function() {11 $("#call_quantity").val($('input.manifest-item:checkbox:checked').length);12 $("#call_quantity").trigger("change");13 omniva_update_checked_list(this);14 });15 $(document).on('change','input.check-all', function() {16 $("#call_quantity").val($('input.manifest-item:checkbox:checked').length);17 $("#call_quantity").trigger("change");18 });19 /* Selected list */20 $(document).on('click', '#selected-orders .item', function() {21 var value = $(this).attr("data-id");22 if (value) {23 var checkbox = $('input.manifest-item[value="' + value + '"]');24 if (checkbox.length) {25 $(checkbox).prop('checked', false);26 $(checkbox).trigger('change');27 } else {28 omniva_remove_from_checked_list(value);29 }30 omniva_remove_selected_item(this);31 }32 });33 /* Call courier */34 $(document).on('click', '#omniva-courier-modal', function(e) {35 if (e.target === this) {36 $('#omniva-courier-modal').removeClass('open');37 }38 });39 $(document).on('click', '#omniva-call-btn', function(e) {40 e.preventDefault();41 $('#omniva-courier-modal').addClass('open');42 $("#call_quantity").trigger("change");43 });44 $(document).on('click', '#omniva-call-cancel-btn', function(e) {45 e.preventDefault();46 $('#omniva-courier-modal').removeClass('open');47 });48 $(document).on('change', '#call_quantity', function(e){49 var min=parseFloat($(this).attr('min'));50 var max=parseFloat($(this).attr('max'));51 var curr=parseFloat($(this).val());52 if (curr > max) { $(this).val(max); }53 if (curr < min) { $(this).val(min); }54 if (curr <= 0) {55 $('#omniva-call-confirm-btn').prop('disabled', true);56 } else {57 $('#omniva-call-confirm-btn').prop('disabled', false);58 }59 });60 /* Submit buttons */61 $(document).on('click', '#submit_manifest_labels_1, #submit_manifest_labels_2', function() {62 omniva_submit_bulk_action('#labels-print-form');63 });64 $(document).on('click', '#submit_manifest_items_1, #submit_manifest_items_2', function() {65 omniva_submit_bulk_action('#manifest-print-form');66 });67 /* Functions */68 function omniva_update_checked_list(checkbox) {69 var value = $(checkbox).val();70 var cookie_value = [];71 if ($(checkbox).is(':checked')) {72 omniva_add_to_checked_list(value);73 } else {74 omniva_remove_from_checked_list(value);75 }76 }77 function omniva_add_to_checked_list(value) {78 var cookie_value = [];79 if (omniva_getCookie(omnivaglobals.cookie_checked_list) == null) {80 $('#selected-orders').show();81 cookie_value = [value];82 omniva_add_selected_item(value);83 } else {84 var current_cookie = omniva_getCookie(omnivaglobals.cookie_checked_list);85 cookie_value = JSON.parse(current_cookie);86 if (!cookie_value.includes(value)) {87 cookie_value.push(value);88 omniva_add_selected_item(value);89 }90 }91 omniva_setCookie(omnivaglobals.cookie_checked_list, JSON.stringify(cookie_value), 12*60);92 }93 function omniva_remove_from_checked_list(value) {94 var cookie_value = [];95 if (omniva_getCookie(omnivaglobals.cookie_checked_list) != null) {96 var current_cookie = omniva_getCookie(omnivaglobals.cookie_checked_list);97 cookie_value = JSON.parse(current_cookie);98 for (var i=0;i<cookie_value.length;i++) {99 if (cookie_value[i] == value) {100 cookie_value.splice(i, 1);101 }102 }103 if (cookie_value.length == 0) {104 omniva_eraseCookie(omnivaglobals.cookie_checked_list);105 setTimeout(function() {106 $('#selected-orders').hide();107 }, 600);108 } else {109 omniva_setCookie(omnivaglobals.cookie_checked_list, JSON.stringify(cookie_value), 12*60);110 }111 omniva_remove_selected_item($('#selected-orders .item[data-id="' + value + '"]'));112 }113 }114 function omniva_add_selected_item(value) {115 var element = $('<span class="item" data-id="' + value + '">#' + value + '<span class="dashicons dashicons-no"></span></span>');116 element.appendTo('#selected-orders');117 element.addClass('adding');118 setTimeout(function() {119 $(element).removeClass('adding');120 }, 600);121 }122 function omniva_remove_selected_item(element) {123 $(element).addClass('removing');124 setTimeout(function() {125 $(element).remove();126 }, 600);127 }128 function omniva_submit_bulk_action(form_selector) {129 var ids = [];130 $(form_selector + ' .post_id').remove();131 if (omniva_getCookie(omnivaglobals.cookie_checked_list) != null) {132 var current_cookie = omniva_getCookie(omnivaglobals.cookie_checked_list);133 ids = JSON.parse(current_cookie);134 }135 $('.manifest-item:checked').each(function() {136 var id = $(this).val();137 if (!ids.includes(id)) {138 ids.push(id);139 }140 });141 for (var i=0; i<ids.length; i++) {142 $(form_selector).append('<input type="hidden" class = "post_id" name="post[]" value = "' + ids[i] + '" />');143 }144 if (!ids.length) {145 alert(omnivatext.alert_select_orders);146 } else {147 omniva_eraseCookie(omnivaglobals.cookie_checked_list);148 $('#selected-orders .item').remove();149 $('#selected-orders').hide();150 $('.manifest-item').prop('checked', false);151 $('.check-all').prop('checked', false);152 $(form_selector).submit();153 }154 }...
skin.js
Source:skin.js
1// *** TO BE CUSTOMISED ***2var style_cookie_name = "glpi_skin" ;3var style_cookie_duration = 30 ;4// *** END OF CUSTOMISABLE SECTION ***5// You do not need to customise anything below this line6function switch_style ( css_title )7{8// You may use this script on your site free of charge provided9// you do not remove this notice or the URL below. Script from10// http://www.thesitewizard.com/javascripts/change-style-sheets.shtml11 var i, link_tag ;12 13 for (i = 0, link_tag = document.getElementsByTagName("link") ; i < link_tag.length ; i++ ) 14 {15 if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) && link_tag[i].title) {16 link_tag[i].disabled = true ;17 if (link_tag[i].title == css_title) {18 link_tag[i].disabled = false ;19 }20 }21 set_cookie( style_cookie_name, css_title, style_cookie_duration );22 }23}24function set_style_from_cookie()25{26 var css_title = get_cookie( style_cookie_name );27 28// if (css_title == 'undefined' || css_title.length > 13) {29 if (css_title.substr(0,5) !== 'skin-' ) {30 //alert(css_title);31 switch_style( 'skin-default' );32 } 33 34 else {35 if (css_title.length) {36 switch_style( css_title );37 } 38 }39}40function set_cookie ( cookie_name, cookie_value, lifespan_in_days, valid_domain )41{42 // http://www.thesitewizard.com/javascripts/cookies.shtml43 var domain_string = valid_domain ? ("; domain=" + valid_domain) : '' ;44 document.cookie = cookie_name +45 "=" + encodeURIComponent( cookie_value ) +46 "; max-age=" + 60 * 60 *47 24 * lifespan_in_days +48 "; path=/" + domain_string ;49}50function get_cookie ( cookie_name )51{52 // http://www.thesitewizard.com/javascripts/cookies.shtml53 var cookie_string = document.cookie; 54 var quebra_de_linha = cookie_string.split("="); 55 56 if (cookie_string.length != 0) {57 var cookie_value = quebra_de_linha[2]; 58 var cookie_value = unescape(cookie_value); 59 return ( cookie_value ) ;60 } 61 return '' ;62}63function get_skin()64{65var setskin = document.getElementById("skin").value;66//alert(setskin);67switch_style(setskin);68return false;69}70/*71function ler_cookie()72{73 var o_cookie = document.cookie; 74 var quebra_de_linha = o_cookie.split("="); 75 var cookie_value = quebra_de_linha[2]; 76 var cookie_value = unescape(cookie_value ); 77alert("Seu nome é: "+ cookie_value );78} 79function get_cookie ( cookie_name )80{81 // http://www.thesitewizard.com/javascripts/cookies.shtml82 var cookie_string = document.cookie ;83 if (cookie_string.length != 0) {84 var cookie_value = cookie_string.match ('(^|;)[\s]*' + cookie_name + '=([^;]*)' );85 return decodeURIComponent ( cookie_value[2] ) ;86 }87 return '' ;88}...
cookie-manager.js
Source:cookie-manager.js
1let head = document.getElementsByTagName("head")[0];2let cookie_script = document.createElement("script");3cookie_script.src = "https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js";4head.appendChild(cookie_script);5function get_cookie(cookie_name) {6 var cookie_value = Cookies.get(cookie_name);7 if (cookie_value == "" || cookie_value === undefined) {8 cookie_value = window.localStorage.getItem(cookie_name);9 try {10 var parsed_value = JSON.parse(cookie_value);11 cookie_value = parsed_value;12 } catch (err) {13 14 }15 }16 return cookie_value;17}18function set_cookie(cookie_name, cookie_value) {19 20 Cookies.set(cookie_name, cookie_value, { expires: 120, path: '' });21 if (typeof cookie_value == "object") {22 var cookie_value = JSON.stringify(cookie_value);23 }24 25 window.localStorage.setItem(cookie_name, cookie_value);...
Using AI Code Generation
1var cookie_value = wpt.cookie_value('cookie_name');2var cookie_value = wpt.cookie_value('cookie_name');3var cookie_value = wpt.cookie_value('cookie_name');4var cookie_value = wpt.cookie_value('cookie_name');5var cookie_value = wpt.cookie_value('cookie_name');6var cookie_value = wpt.cookie_value('cookie_name');7var cookie_value = wpt.cookie_value('cookie_name');8var cookie_value = wpt.cookie_value('cookie_name');9var cookie_value = wpt.cookie_value('cookie_name');10var cookie_value = wpt.cookie_value('cookie_name');11var cookie_value = wpt.cookie_value('cookie_name');12var cookie_value = wpt.cookie_value('cookie_name');13var cookie_value = wpt.cookie_value('cookie_name');14var cookie_value = wpt.cookie_value('cookie_name');15var cookie_value = wpt.cookie_value('cookie_name');16var cookie_value = wpt.cookie_value('cookie_name');17var cookie_value = wpt.cookie_value('cookie_name');18var cookie_value = wpt.cookie_value('cookie_name');19var cookie_value = wpt.cookie_value('cookie_name');20var cookie_value = wpt.cookie_value('cookie_name');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {runs: 3, location: 'Dulles:Chrome'};4wpt.runTest(url, options, function(err, data) {5 if (err) return console.error(err);6 console.log('Test status: ' + data.statusText);7 wpt.getTestStatus(data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log('Test status: ' + data.statusText);10 wpt.getTestResults(data.testId, function(err, data) {11 if (err) return console.error(err);12 console.log('Test status: ' + data.statusText);13 console.log('Test results: ' + data.data.median.firstView.SpeedIndex);14 });15 });16});173. [WebPageTest npm package github repo](
Using AI Code Generation
1var cookie_value = wpt.cookie_value("my_cookie_name");2var request_header = wpt.get_request_header("my_request_header_name");3var response_header = wpt.get_response_header("my_response_header_name");4var response_headers = wpt.get_response_headers();5var response_body = wpt.get_response_body();6var response_body_size = wpt.get_response_body_size();7var response_status = wpt.get_response_status();8var response_status_text = wpt.get_response_status_text();9var response_time = wpt.get_response_time();10var response_time_seconds = wpt.get_response_time_seconds();11var response_time_ms = wpt.get_response_time_ms();12var response_time_us = wpt.get_response_time_us();
Using AI Code Generation
1var cookie_value = wpt.cookie_value("cookie_name");2var cookie_value = wpt.cookie_value("cookie_name");3wpt.cookie_set("cookie_name", "cookie_value");4wpt.cookie_set("cookie_name", "cookie_value");5wpt.cookie_clear("cookie_name");6wpt.cookie_clear("cookie_name");7wpt.cookie_clear_all();8wpt.cookie_clear_all();9wpt.cookie_jar("cookie_jar_file_path");10wpt.cookie_jar("cookie_jar_file_path");11wpt.cache_clear();12wpt.cache_clear();13wpt.set_header("header_name", "header_value");14wpt.set_header("header_name", "header_value");15wpt.set_headers({16});17wpt.set_headers({18});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!