Best JavaScript code snippet using wpt
jquery.menu.slider.js
Source:jquery.menu.slider.js
1(function($){2 $.fn.extend({3 showMenu: function(options) {4 var defaults = {5 csswrap: ".wrap-in",6 csswrapa: ".wrap-a",7 csslinka: ".link-a",8 cssrev: ".btn-prev",9 cssnext: ".btn-next",10 csscurrent: "current",11 showm: false,12 minw: 10 //khoang canh it mhat13 };14 var options = $.extend(defaults, options);15 return this.each(function() {16 var opts =options;17 var obj = $(this); 18 var items = $(opts.csslinka, obj);19 var wrapbox = $(opts.csswrap, obj);20 var wrapboxa = $(opts.csswrapa, obj);21 var btnprev = $(opts.cssrev, obj);22 var btnnext = $(opts.cssnext, obj);23 /*==============*/24 var i = 0;25 var countlink = items.size();26 var wa = opts.minw;27 var wlis = 0;28 items.each(function (e) {29 $(this).width($(this).width());30 wlis += ($(this).width() + wa) ;31 });32 wrapboxa.width(wlis);33 btnnext.addClass(".btn-a");34 btnprev.addClass(".btn-a");35 var clearmy;36 myprev(i);37 btnnext.click(function () {38 i++;39 var ia = i;40 myreauto();41 i = mynext(ia);42 return false;43 });44 btnprev.click(function () {45 i--;46 var ia = i;47 if (i < 0) {48 ia = 0;49 }50 myreauto();51 i = myprev(ia);52 return false;53 });54 $(window).resize(function () {55 myreauto();56 clearTimeout(clearmy);57 clearmy = setTimeout(function () {58 var currenti = obj.find("." + opts.csscurrent).index();59 i = myprev(currenti);60 }, 0);61 });62 /*====================*/63 function myprev(batdau) {64 //items.show();65 //items.width("auto");66 //wrapbox.width("auto");67 //wrapboxa.width("auto");68 var totalsum = 0;69 var totalw = 0;70 if (batdau == 0) {71 btnprev.hide();72 var wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth());73 } else {74 btnprev.show();75 var wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth() * 2);76 }77 var stepstart = batdau;78 var stepend = 0;79 var enda = 0;80 var btna = 0;81 var countlink = items.size();82 var numc = 0;83 for (var k = stepstart; k < countlink; k++) {84 if (totalsum >= wrapwidth) {85 totalw = totalsum - (items.filter(":eq(" + (k - 1) + ")").width() + wa);86 stepend = k - 1;87 break;88 } else {89 totalsum += (items.filter(":eq(" + k + ")").outerWidth() + wa);90 }91 }92 items.removeClass(opts.csscurrent);93 items.filter(":eq(" + stepstart + ")").addClass(opts.csscurrent);9495 var sumwi = 0;96 var wlink = 0;97 var totalad = 0;98 for (var kj = 0; kj < countlink; kj++) {99 totalad += (items.filter(":eq(" + kj + ")").outerWidth() + wa);100 numc++;101 }102 if (totalsum < wrapwidth && obj.width() >= totalad) {103 stepend = countlink;104 wrapwidth = obj.width();105 btna = obj.find(".btn-a").outerWidth();106 obj.find(".btn-a").hide();107 if (opts.showm) {108 wlink = parseInt((wrapwidth - totalad) / stepend);109 } else {110 if (wrapwidth - totalad >= btna) {111 wlink = Math.round(btna / stepend);112 } else {113 wlink = 0;114 }115 }116 for (var j = 0; j < stepend; j++) {117 var wj = items.filter(":eq(" + j + ")").width() + wlink + wa;118 items.filter(":eq(" + j + ")").width(wj);119 }120 //alert("aaa");121 wrapbox.width(wrapwidth);122 wrapboxa.width(wrapwidth);123 } else {124 items.filter(":lt(" + stepstart + ")").hide();125 if (stepend == 0) {126 for (var j = stepstart; j < countlink; j++) {127 totalw += (items.filter(":eq(" + j + ")").width() + wa);128 stepend = countlink;129 }130131 if (totalw > wrapwidth) {132 totalw = totalw - (items.filter(":eq(" + (stepend - 1) + ")").width() + wa);133 //wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth());134 stepend = countlink - 1;135 items.filter(":gt(" + (stepend - 1) + ")").hide();136 btnnext.show();137 //alert("bbb" + totalw + " - " + wrapwidth);138 } else {139 wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth());140 btnnext.hide();141 stepend = countlink;142 //alert("ccc");143 }144 } else {145 //alert("ddd");146 btnnext.show();147 items.filter(":gt(" + (stepend - 1) + ")").hide();148 }149 wlink = parseInt((wrapwidth - totalw) / (stepend - stepstart));150 if (wlink < 0) {151 wlink = 0;152 }153 for (var j = stepstart; j < stepend; j++) {154 var wj = items.filter(":eq(" + j + ")").width() + wlink + wa;155 sumwi += wj;156 items.filter(":eq(" + j + ")").width(wj);157 }158 if (sumwi + 1 >= wrapwidth) {159 wrapbox.width(sumwi - 1);160 } else {161 wrapbox.width(sumwi);162 }163 wrapboxa.width(sumwi);164 }165 return stepstart;166 }167168 function mynext(batdau) {169 //items.show();170 //items.width("auto");171 //wrapbox.width("auto");172 //wrapboxa.width("auto");173 var totalsum = 0;174 var totalw = 0;175 var wp = wa;176 if (batdau == 0) {177 btnprev.hide();178 var wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth());179 } else {180 btnprev.show();181 var wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth() * 2);182 }183 obj.attr("data-wid", wrapwidth);184 var stepstart = batdau - 1;185 var stepend = 0;186 var enda = 0;187 var countlink = items.size();188 for (var k = stepstart; k < countlink; k++) {189 if (totalsum >= wrapwidth) {190 totalw = totalsum;191 stepend = k;192 break;193 } else {194 totalsum += (items.filter(":eq(" + k + ")").outerWidth() + wa);195 }196 }197 var totali = 0;198 for (var ji = stepstart; ji < stepend; ji++) {199 if (totalw < wrapwidth) {200 totali = totalw;201 stepstart = ji;202 break;203 } else {204 totalw = totalw - (items.filter(":eq(" + ji + ")").outerWidth() + wa);205 }206 }207208 items.removeClass(opts.csscurrent);209 210 //if (totalsum < wrapwidth) {211 //} else {212 //}213 if (stepend == 0) {214 items.width("auto");215 for (var ja = stepstart; ja < countlink; ja++) {216 totalw += (items.filter(":eq(" + ja + ")").width() + wa);217 stepend = countlink;218 }219220 if (totalw > wrapwidth) {221 totali = totalw - (items.filter(":eq(" + stepstart + ")").width() + wa);222 wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth());223 stepstart = stepstart + 1;224 stepend = countlink;225 if (totali > wrapwidth) {226 wp = wa - parseInt((totali - wrapwidth) / 2);227 totali = 0;228 wrapwidth = 0;229 }230 btnnext.hide();231 //alert("aa" + stepstart + " - " + stepend + " - " + totali);232 } else {233 wrapwidth = obj.width() - (obj.find(".btn-a").outerWidth() * 2);234 totali = totalw;235 btnnext.show();236 wp = wa;237 //alert("ab");238 }239 } else {240 //alert("ac");241 btnnext.show();242 items.filter(":gt(" + (stepend - 1) + ")").hide();243 wp = wa;244 }245 //alert(wp);246 items.filter(":eq(" + stepstart + ")").addClass(opts.csscurrent);247 items.filter(":lt(" + stepstart + ")").hide();248 var sumwi = 0;249 var wlink = parseInt((wrapwidth - totali) / (stepend - stepstart));250 if (wlink < 0) {251 wlink = 0;252 }253254 for (var j = stepstart; j < stepend; j++) {255 var wj = items.filter(":eq(" + j + ")").width() + wlink + wp;256 sumwi += wj;257 items.filter(":eq(" + j + ")").width(wj);258 }259 260 if (sumwi + 1 >= wrapwidth) {261 wrapbox.width(sumwi - 1);262 } else {263 wrapbox.width(sumwi);264 }265 wrapboxa.width(sumwi);266 //alert(stepstart);267 return stepstart;268 }269 /*===============*/270 function myreauto() {271 items.show();272 items.width("auto");273 wrapbox.width("auto");274 wrapboxa.width("auto");275 }276 });277278 }279 });
...
Messages.js
Source:Messages.js
1import React, { Component } from 'react'2import MessageService from '../../views/Messages/services/MessageService';3import { toastr } from "react-redux-toastr";4const messageService = new MessageService()5const card = {6 width: "20rem",7 height: "7rem"8}9export default class Messages extends Component {10 constructor(props) {11 super(props)12 this.state = {13 jsonMessages: [],14 stepStart: 0,15 stepEnd: 216 }17 }18 loadData() {19 console.log("loadData")20 messageService21 .listMessagesPublic()22 .then(response => response.json())23 .then((response) => {24 this.setState({ jsonMessages: response })25 })26 .catch(error => {27 console.log('Errore nel recupero dei dati');28 toastr.error(messages.label.errore, error.message);29 });30 }31 componentDidMount() {32 this.loadData()33 }34 nextPrevSteps(isNextStep) {35 if (isNextStep) {36 this.setState({37 stepStart: this.state.stepStart + 3,38 stepEnd: this.state.stepEnd + 339 })40 } else {41 this.setState({42 stepStart: this.state.stepStart - 3,43 stepEnd: this.state.stepEnd - 344 })45 }46 }47 render() {48 return (49 <div>50 {this.state.jsonMessages.length > 0 &&51 <div className="mt-0 py-3 container">52 <div className="container">53 <div className="row">54 <div className="col-lg-12 col-md-7 col-12">55 <div className="row">56 <div className="col-lg-12 col-md-7 col-12">57 <h1 className="text-gray-600 font-weight-bold" style={{ fontSize: '1.5rem' }}>Comunicazioni</h1>58 </div>59 </div>60 <div className="row mx-auto m-0">61 {this.state.stepStart > 0 && <i title="Indietro" className="fas fa-chevron-left" style={{ cursor: "pointer", fontSize: "35px", marginTop: "30px" }} onClick={() => this.nextPrevSteps(false)}></i>}62 {63 this.state.jsonMessages.map((message, index) => {64 return (65 (index >= this.state.stepStart && index <= this.state.stepEnd) &&66 <div key={index} className="mx-auto">67 <div className="card" style={card}>68 <div className="card-header">69 {message.info.title}70 </div>71 <div className="card-body" style={{ height: "100px", overflow: "auto" }}>72 <p className="card-text">{message.info.description}</p>73 </div>74 </div>75 </div>76 )77 })78 }79 {this.state.stepEnd < this.state.jsonMessages.length - 1 && <i className="fas fa-chevron-right" title="Avanti" style={{ cursor: "pointer", fontSize: "35px", marginTop: "30px" }} onClick={() => this.nextPrevSteps(true)}></i>}80 </div>81 </div>82 </div>83 </div>84 </div>85 }86 </div>87 )88 }...
stepEnd.ts
Source:stepEnd.ts
1import { almostEqual } from '../assertions';2import { stepEnd } from '../../src/curves';3describe('stepEnd()', () => {4 it('stepEnd(0) is about 0', () => {5 almostEqual(stepEnd(0), 0, .0001);6 });7 it('stepEnd(.250000) is about 0', () => {8 almostEqual(stepEnd(.250000), 0, .0001);9 });10 it('stepEnd(.333333) is about 0', () => {11 almostEqual(stepEnd(.333333), 0, .0001);12 });13 it('stepEnd(.500000) is about 0', () => {14 almostEqual(stepEnd(.500000), 0, .0001);15 });16 it('stepEnd(.666667) is about 0', () => {17 almostEqual(stepEnd(.666667), 0, .0001);18 });19 it('stepEnd(.750000) is about 0', () => {20 almostEqual(stepEnd(.750000), 0, .0001);21 });22 it('stepEnd(1) is about 1', () => {23 almostEqual(stepEnd(1), 1, .0001);24 });...
Using AI Code Generation
1var wpt = require('wptdriver');2wpt.stepEnd('step1');3wpt.stepEnd('step2');4wpt.stepEnd('step3');5wpt.stepEnd('step4');6wpt.stepEnd('step5');7wpt.stepEnd('step6');8wpt.stepEnd('step7');9wpt.stepEnd('step8');10wpt.stepEnd('step9');11wpt.stepEnd('step10');12wpt.stepEnd('step11');13wpt.stepEnd('step12');14wpt.stepEnd('step13');15wpt.stepEnd('step14');16wpt.stepEnd('step15');17wpt.stepEnd('step16');18wpt.stepEnd('step17');19wpt.stepEnd('step18');20wpt.stepEnd('step19');21wpt.stepEnd('step20');22wpt.stepEnd('step21');23wpt.stepEnd('step22');24wpt.stepEnd('step23');25wpt.stepEnd('step24');26wpt.stepEnd('step25');27wpt.stepEnd('step26');28wpt.stepEnd('step27');29wpt.stepEnd('step28');30wpt.stepEnd('step29');31wpt.stepEnd('step30');32wpt.stepEnd('step31');33wpt.stepEnd('step32');34wpt.stepEnd('step33');35wpt.stepEnd('step34');36wpt.stepEnd('step35');37wpt.stepEnd('step36');38wpt.stepEnd('step37');39wpt.stepEnd('step38');40wpt.stepEnd('step39');41wpt.stepEnd('step40');42wpt.stepEnd('step41');43wpt.stepEnd('step42');44wpt.stepEnd('step43');45wpt.stepEnd('step44');46wpt.stepEnd('step45');47wpt.stepEnd('step46');48wpt.stepEnd('step47');49wpt.stepEnd('step48');50wpt.stepEnd('step49');51wpt.stepEnd('step50');52wpt.stepEnd('step51');53wpt.stepEnd('step52');54wpt.stepEnd('step53');55wpt.stepEnd('step54');56wpt.stepEnd('step55');57wpt.stepEnd('step56');58wpt.stepEnd('step57');59wpt.stepEnd('step58');60wpt.stepEnd('step59');61wpt.stepEnd('step60');62wpt.stepEnd('step61
Using AI Code Generation
1var wpt = require('webpagetest');2var server = wpt('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log(data);7 server.stepEnd(data.data.testId, function(err, data) {8 if (err) {9 console.log('Error: ' + err);10 } else {11 console.log(data);12 }13 });14 }15});
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options);5 if (err) return console.log(err);6 var testId = data.data.testId;7 var testStatus = data.data.statusText;8 var testComplete = data.data.completeTime;9 var testStart = data.data.startTime;10 var testLocation = data.data.location;11 var testFrom = data.data.from;12 var testConnectivity = data.data.connectivity;13 var testURL = data.data.url;14 var testID = data.data.id;15 var testRuns = data.data.runs;16 var testSuccessfulFVRuns = data.data.successfulFVRuns;17 var testSuccessfulRVRuns = data.data.successfulRVRuns;18 var testAverage = data.data.average;19 var testMedian = data.data.median;20 var testStandardDeviation = data.data.standardDeviation;21 var testStandardDeviation = data.data.standardDeviation;22 var testRuns = data.data.runs;23 var testSuccessfulFVRuns = data.data.successfulFVRuns;24 var testSuccessfulRVRuns = data.data.successfulRVRuns;25 var testAverage = data.data.average;26 var testMedian = data.data.median;27 var testStandardDeviation = data.data.standardDeviation;28 var testStandardDeviation = data.data.standardDeviation;
Using AI Code Generation
1var wptdriver = require('wptdriver');2 console.log('stepEnd called');3});4var wptdriver = require('wptdriver');5 console.log('stepStart called');6});7var wptdriver = require('wptdriver');8 console.log('stepTimeout called');9});10var wptdriver = require('wptdriver');11 console.log('stepUserAction called');12});13var wptdriver = require('wptdriver');14 console.log('stepWait called');15});16var wptdriver = require('wptdriver');17 console.log('testComplete called');18});19var wptdriver = require('wptdriver');20 console.log('testError called');21});22var wptdriver = require('wpt
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var testId = '140803_0G_1Y';4wpt.stepEnd(testId, 1, function (err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});
Using AI Code Generation
1window.wpt.stepEnd();2### stepStart()3window.wpt.stepStart();4### stepData()5window.wpt.stepData('some data');6### stepResult()7window.wpt.stepResult('some result');8### stepName()9window.wpt.stepName('some name');10### stepStatus()11window.wpt.stepStatus('some status');12### getScript()13### getScriptAsync()14### getScriptAsyncCallback()15 console.log('script loaded');16});17### getScriptAsyncPromise()
Using AI Code Generation
1function stepEnd(stepName) {2 if (stepName == "step1") {3 } else if (stepName == "step2") {4 }5}6function stepEnd(stepName) {7 if (stepName == "step1") {8 } else if (stepName == "step2") {9 }10}11function stepEnd(stepName) {12 if (stepName == "step1") {13 } else if (stepName == "step2") {14 }15}16function stepEnd(stepName) {17 if (stepName == "step1") {18 } else if (stepName == "step2") {19 }20}21function stepEnd(stepName) {22 if (stepName == "step1") {23 } else if (stepName == "step2") {24 }25}
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = WebPageTest('www.webpagetest.org', 'A.2d4e7c2f2e8f7e9e9a9c7e7e7e7e7e7e7');3 wpt.stepEnd(data.data.runs[1].firstView.steps[0].number, function(err, data) {4 console.log(data);5 });6});7{ statusCode: 200,8 { statusCode: 200,9 data: { responseCode: 200, statusText: 'Ok' } } }10var wpt = require('webpagetest');11var wpt = WebPageTest('www.webpagetest.org', 'A.2d4e7c2f2e8f7e9e9a9c7e7e7e7e7e7e7');12 wpt.stepRun(data.data.runs[1].firstView.steps[0].number, function(err, data) {13 console.log(data);14 });15});16{ statusCode: 200,17 { statusCode: 200,18 data: { responseCode: 200, statusText: 'Ok' } } }19var wpt = require('webpagetest');20var wpt = WebPageTest('www.webpagetest.org', 'A.2d4e7c2f2e8f7e9e9a9c7e7e7e7e7e7e7');21 wpt.stepStart(data.data.runs[1].firstView.steps[0].number, function(err, data) {22 console.log(data);23 });24});25{ statusCode:
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org','A.1e7a8e8c0b7e0c9a9b7e8c9a7e8c9a7e');3 if (!err) {4 var testId = data.data.testId;5 client.stepEnd(testId, 1, function(err, data) {6 if (!err) {7 console.log('The test was stopped at step 1');8 } else {9 console.log('The test was not stopped');10 }11 });12 } else {13 console.log('The test was not started');14 }15});16`stepData(testId, step, callback)`17var wpt = require('webpagetest');18var client = wpt('www.webpagetest.org','A.1e7a8e8c0b7e0c9a9b7e8c9a7e8c9a7e');19 if (!err) {20 var testId = data.data.testId;21 client.stepData(testId, 1, function(err, data) {22 if (!err) {23 console.log('The test data was retrieved');24 } else {25 console.log('The test data was not retrieved');26 }27 });28 } else {29 console.log('The test was not started');30 }31});32`stepScreenshot(testId, step, callback)`33var wpt = require('webpagetest');34var client = wpt('www.webpagetest.org','A.1e7a8e8c0b7e0c9a9b7e8c9a7e8c9a7e');35 if (!err) {
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!!