Best JavaScript code snippet using wpt
hall.js
Source:hall.js
1var HallPage = function () {2 var _self = this;3 var pageA, pageB;4 var pages = [];5 var pagePos = [{ x: 0, y: 0 }, { x: 0, y: 0 }];6 var gyeBindFlag = false;7 var showFlag = false;8 var controlFlag = false;9 var clickFlag = false;10 var centerX = 2545;11 var bgWidth = 6494;12 var nowIndex = 0;13 var moveViewFlag = false;14 var MoveData;15 var startData;16 var GyeData;17 var ParallaxTimer;18 /**19 * åå§å20 */21 _self.init = function () {22 uiInit();23 eventInit();24 setTimeout(function () {25 _self.open();26 }, 4500);27 }28 /**29 * æå¼30 */31 _self.open = function () {32 controlFlag = true;33 showFlag = true;34 document.getElementById("gyeBtn").style.display = "none";35 }36 /**37 * å
³é38 */39 _self.close = function () {40 controlFlag = false;41 }42 /**43 * éæ¯44 */45 _self.distroy = function () {46 showFlag = false;47 controlFlag = false;48 pageA.removeSelf();49 pageB.removeSelf();50 }51 /**52 * éèºä»ªææ53 */54 _self.gyeAuto = function () {55 if (!gyeBindFlag) {56 Laya.Browser.window.addEventListener("deviceorientation", (e) => {57 if (controlFlag) dealGyeData(e);58 }, false);59 }60 }61 /**62 * äºä»¶åå§å63 */64 function eventInit() {65 pageA.on(Laya.Event.MOUSE_DOWN, this, recordMoveData);66 pageA.on(Laya.Event.MOUSE_MOVE, this, changeMoveData);67 pageA.on(Laya.Event.MOUSE_UP, this, clearMoveData);68 pageB.on(Laya.Event.MOUSE_DOWN, this, recordMoveData);69 pageB.on(Laya.Event.MOUSE_MOVE, this, changeMoveData);70 pageB.on(Laya.Event.MOUSE_UP, this, clearMoveData);71 pageA.nextBtn.on(Laya.Event.CLICK, this, showPerfectionPage);72 pageB.nextBtn.on(Laya.Event.CLICK, this, showPerfectionPage);73 pageA.shipBtn.on(Laya.Event.CLICK, this, showIntro, ["ship"]);74 pageA.bellBtn.on(Laya.Event.CLICK, this, showIntro, ["bell"]);75 pageA.conch1Btn.on(Laya.Event.CLICK, this, showIntro, ["conch2"]);76 pageA.conch2Btn.on(Laya.Event.CLICK, this, showIntro, ["conch1"]);77 pageA.conch3Btn.on(Laya.Event.CLICK, this, showIntro, ["conch4"]);78 pageA.conch4Btn.on(Laya.Event.CLICK, this, showIntro, ["conch5"]);79 pageA.conch5Btn.on(Laya.Event.CLICK, this, showIntro, ["conch3"]);80 pageB.shipBtn.on(Laya.Event.CLICK, this, showIntro, ["ship"]);81 pageB.bellBtn.on(Laya.Event.CLICK, this, showIntro, ["bell"]);82 pageB.conch1Btn.on(Laya.Event.CLICK, this, showIntro, ["conch2"]);83 pageB.conch2Btn.on(Laya.Event.CLICK, this, showIntro, ["conch1"]);84 pageB.conch3Btn.on(Laya.Event.CLICK, this, showIntro, ["conch4"]);85 pageB.conch4Btn.on(Laya.Event.CLICK, this, showIntro, ["conch5"]);86 pageB.conch5Btn.on(Laya.Event.CLICK, this, showIntro, ["conch3"]);87 }88 /**89 * æ¾ç¤ºä»ç»é¡µé¢90 */91 function showIntro(name) {92 if (clickFlag) iIntro.show("intro", dialogData[name]);93 }94 /**95 * æ¾ç¤ºè»èé¦é¡µé¢96 */97 function showPerfectionPage() {98 if (showFlag && clickFlag) {99 showFlag = false;100 controlFlag = false;101 pageA.zOrder = 99;102 pageB.zOrder = 99;103 iPerfectionPage.init();104 Laya.Tween.to(pageA, {105 x: pageA.x - 300106 }, 1000, Laya.Ease.linearIn, null);107 Laya.Tween.to(pageB, {108 x: pageA.x - 300109 }, 1000, Laya.Ease.linearIn, null);110 Laya.Tween.to(pageA, {111 alpha: 0112 }, 700, Laya.Ease.linearIn, null, 1000);113 Laya.Tween.to(pageB, {114 alpha: 0115 }, 700, Laya.Ease.linearIn, null, 1000);116 setTimeout(function () {117 _self.distroy();118 }, 1700);119 }120 }121 /**122 * å¤çéèºä»ªæ°æ®123 * @param e 124 */125 function dealGyeData(e) {126 if (GyeData) {127 var diffX = e.alpha - GyeData.alpha;128 var diffY = e.gamma - GyeData.gamma;129 diffX = diffX < -20 || diffX > 20 ? 0 : diffX;130 diffY = diffY < -20 || diffY > 20 ? 0 : diffY;131 if (Math.abs(diffX) > 0.1) {132 pagePos[0].x += diffX * GYE_SENSITIVITY_X;133 pagePos[1].x += diffX * GYE_SENSITIVITY_X;134 GyeData.alpha = e.alpha;135 }136 if (Math.abs(diffY) > 0.05) {137 pagePos[0].y -= diffY * GYE_SENSITIVITY_Y;138 pagePos[1].y -= diffY * GYE_SENSITIVITY_Y;139 GyeData.gamma = e.gamma;140 }141 if (Math.abs(diffX) > 0.1 || Math.abs(diffY) > 0.05) {142 updatePagePos();143 updateParallax(diffX * 5, diffY * 5);144 }145 }146 GyeData = e;147 hideTips();148 gyeBindFlag = true;149 document.getElementById("gyeBtn").style.display = "none";150 }151 /**152 * è®°å½ææè®°å½çå¼153 */154 function recordMoveData(e) {155 if (controlFlag) {156 moveViewFlag = true;157 MoveData = {};158 MoveData.x = e.stageX;159 MoveData.y = e.stageY;160 startData = {};161 startData.x = e.stageX;162 hideTips();163 clickFlag = true;164 }165 }166 /**167 * æ¹åææè®°å½çå¼168 */169 function changeMoveData(e) {170 if (controlFlag && MoveData && moveViewFlag) {171 var diffX = (e.stageX - MoveData.x) * MOVE_SENSITIVITY;172 var diffY = (e.stageY - MoveData.y) * MOVE_SENSITIVITY;173 pagePos[0].x += diffX;174 pagePos[1].x += diffX;175 pagePos[0].y += diffY;176 pagePos[1].y += diffY;177 updatePagePos();178 updateParallax(diffX, diffY);179 MoveData.x = e.stageX;180 MoveData.y = e.stageY;181 if (Math.abs(startData.x - e.stageX) > 15) clickFlag = false;182 }183 }184 /**185 * æ¸
é¤ææè®°å½çå¼186 */187 function clearMoveData() {188 MoveData = null;189 startData = null;190 moveViewFlag = false;191 }192 /**193 * æ´æ°é¡µé¢çä½ç½®194 */195 function updatePagePos() {196 correctData();197 pages[0].x = pagePos[0].x;198 pages[1].x = pagePos[1].x;199 pages[0].y = pagePos[0].y;200 pages[1].y = pagePos[1].y;201 }202 /**203 * æ´æ°è§å·®204 */205 function updateParallax(x, y) {206 ClearResumeParallax();207 // updateParallaxBg(x,y);208 updateParallaxPart(x, y, "part1", 10, PARALLAX_SENSITIVITY_PART1);209 updateParallaxPart(x, y, "part2", 20, PARALLAX_SENSITIVITY_PART2);210 updateParallaxPart(x, y, "part3", 40, PARALLAX_SENSITIVITY_PART3);211 clearTimeout(ParallaxTimer);212 ParallaxTimer = setTimeout(function () {213 resumeParallax();214 }, 200);215 }216 /**217 * æ´æ°èæ¯è§å·®218 */219 function updateParallaxBg(x, y) {220 var diffS = Math.abs(x + y);221 var scale = pageA.bg.scaleY;222 scale -= diffS * SCALE_SENSITIVITY_BG;223 scale = scale < 0.98 ? 0.98 : scale;224 pageA.bg.scaleY = scale;225 pageB.bg.scaleY = scale;226 }227 /**228 * æ´æ°è§å·®229 * @param {*} x 230 * @param {*} y 231 */232 function updateParallaxPart(x, y, name, max, sens) {233 var lastx = pageA[name].x;234 var lasty = pageA[name].y;235 lastx -= x * sens;236 lastx = lastx > max ? max : lastx;237 lastx = lastx < -max ? -max : lastx;238 lasty -= y * sens;239 lasty = lasty > max ? max : lasty;240 lasty = lasty < -max ? -max : lasty;241 pageA[name].x = lastx;242 pageA[name].y = lasty;243 pageB[name].x = lastx;244 pageB[name].y = lasty;245 }246 /**247 * æ¸
é¤æ¢å¤è§å·®248 */249 function ClearResumeParallax() {250 // Laya.Tween.clearAll(pageA.bg);251 Laya.Tween.clearAll(pageA.part1);252 Laya.Tween.clearAll(pageA.part2);253 Laya.Tween.clearAll(pageA.part3);254 // Laya.Tween.clearAll(pageB.bg);255 Laya.Tween.clearAll(pageB.part1);256 Laya.Tween.clearAll(pageB.part2);257 Laya.Tween.clearAll(pageB.part3);258 }259 /**260 * æ¢å¤è§å·®261 */262 function resumeParallax() {263 // Laya.Tween.to(pageA.bg,{264 // scaleY:1265 // },1000)266 // Laya.Tween.to(pageB.bg,{267 // scaleY:1268 // },1000)269 Laya.Tween.to(pageA.part1, {270 x: 0,271 y: 0272 }, 1300)273 Laya.Tween.to(pageA.part2, {274 x: 0,275 y: 0276 }, 1200)277 Laya.Tween.to(pageA.part3, {278 x: 0,279 y: 0280 }, 700)281 Laya.Tween.to(pageB.part1, {282 x: 0,283 y: 0284 }, 1300)285 Laya.Tween.to(pageB.part2, {286 x: 0,287 y: 0288 }, 1200)289 Laya.Tween.to(pageB.part3, {290 x: 0,291 y: 0292 }, 700)293 }294 /**295 * éèæ示296 */297 function hideTips() {298 if (pageB.tips.visible) {299 Laya.Tween.to(pageA.tips, {300 alpha: 0301 }, 500);302 pageB.tips.visible = false;303 setTimeout(function () {304 pageA.tips.visible = false;305 }, 500)306 }307 }308 /**309 * ä¿®æ£æ°æ®310 */311 function correctData() {312 var next = nowIndex == 1 ? 0 : 1;313 if (pagePos[nowIndex].x < -bgWidth + WindowW + 100 && pagePos[next].x < 0) pagePos[next].x += (bgWidth * 2);314 if (pagePos[nowIndex].x > -100 && pagePos[next].x > 0) pagePos[next].x -= (bgWidth * 2);315 if (pagePos[nowIndex].x < -bgWidth + WindowW / 2 || pagePos[nowIndex].x > WindowW / 2) {316 nowIndex = next;317 if (nowIndex == 1) {318 pageA.zOrder = 98;319 pageB.zOrder = 99;320 }321 else {322 pageA.zOrder = 99;323 pageB.zOrder = 98;324 }325 }326 pagePos[0].y = pagePos[0].y > 0 ? 0 : pagePos[0].y;327 pagePos[0].y = pagePos[0].y < -375 ? -375 : pagePos[0].y;328 pagePos[1].y = pagePos[1].y > 0 ? 0 : pagePos[1].y;329 pagePos[1].y = pagePos[1].y < -375 ? -375 : pagePos[1].y;330 }331 /**332 * uiåå§å333 */334 function uiInit() {335 pageA = new hallUI();336 pageB = new hallUI();337 Laya.stage.addChild(pageB);338 Laya.stage.addChild(pageA);339 pages[0] = pageA.cont;340 pages[1] = pageB.cont;341 iClickTips.init(pageA.clickTips);342 iClickTips.init(pageB.clickTips);343 pagePos[0].x = -(centerX - 1624 / 2 - BgPageX);344 pagePos[1].x = -(bgWidth - pagePos[0].x);345 pagePos[0].y = -187;346 pagePos[1].y = -187;347 updatePagePos();348 }349}...
index.ts
Source:index.ts
1import {path} from '@vuepress/utils'2import {blogPlugin} from 'vuepress-plugin-blog2'3import type {Theme} from '@vuepress/core'4import {generatePosts} from './plugins/generatePosts'5const {shikiPlugin} = require('@vuepress/plugin-shiki')6const {activeHeaderLinksPlugin} = require('@vuepress/plugin-active-header-links')7const {tocPlugin} = require('@vuepress/plugin-toc')8// @ts-ignore9export const customTheme = (options): Theme => ({10 name: 'custom-theme',11 // å®ä¹åç§é¡µé¢çå¸å±12 layouts: {13 Article: path.resolve(__dirname, './layouts/Article.vue'),14 Category: path.resolve(__dirname, './layouts/Category.vue'),15 Tag: path.resolve(__dirname, './layouts/Tag.vue'),16 Timeline: path.resolve(__dirname, './layouts/Timeline.vue'),17 Layout: path.resolve(__dirname, './layouts/Layout.vue'),18 },19 plugins: [20 generatePosts(),21 shikiPlugin({22 theme: 'slack-dark'23 }),24 activeHeaderLinksPlugin({25 // é
置项26 }),27 tocPlugin({28 // é
置项29 }),30 blogPlugin({31 // only files under posts are articles32 // @ts-ignore33 filter: ({filePathRelative}) =>34 filePathRelative && filePathRelative.startsWith('posts/'),35 // getting article info36 // getInfo: ({frontmatter, title}) => ({37 // title,38 // author: frontmatter.author || '',39 // date: frontmatter.date || null,40 // category: frontmatter.category || [],41 // tag: frontmatter.tag || [],42 // }),43 category: [44 {45 key: 'categories',46 getter: (page) => <string[]>page.frontmatter.categories || [],47 layout: 'Category',48 itemLayout: 'Category',49 frontmatter: () => ({title: 'Categories', sidebar: false}),50 itemFrontmatter: (name) => ({51 title: `Category ${name}`,52 sidebar: false,53 }),54 },55 {56 key: 'tag',57 getter: (page) => <string[]>page.frontmatter.tags || [],58 layout: 'Tag',59 itemLayout: 'Tag',60 frontmatter: () => ({title: 'Tags', sidebar: false}),61 itemFrontmatter: (name) => ({62 title: `Tag ${name}`,63 sidebar: false,64 }),65 },66 ],67 type: [68 {69 key: 'posts',70 // è¿åææ页é¢71 filter: page => {72 return page.path.startsWith('posts/')73 },74 // layout: 'Article',75 frontmatter: () => ({title: 'Home'}),76 // sort pages with time and sticky77 sorter: (pageA, pageB) => {78 if (pageA.frontmatter.sticky && pageB.frontmatter.sticky) { // @ts-ignore79 return pageB.frontmatter.sticky - pageA.frontmatter.sticky80 }81 if (pageA.frontmatter.sticky && !pageB.frontmatter.sticky)82 return -183 if (!pageA.frontmatter.sticky && pageB.frontmatter.sticky) return 184 if (!pageB.frontmatter.date) return 185 if (!pageA.frontmatter.date) return -186 return (87 new Date(pageB.frontmatter.date).getTime() -88 new Date(pageA.frontmatter.date).getTime()89 )90 },91 },92 {93 key: 'article',94 // remove archive articles95 filter: (page) => !page.frontmatter.archive,96 path: '/article/',97 layout: 'Article',98 frontmatter: () => ({title: 'Articles'}),99 // sort pages with time and sticky100 sorter: (pageA, pageB) => {101 if (pageA.frontmatter.sticky && pageB.frontmatter.sticky) { // @ts-ignore102 return pageB.frontmatter.sticky - pageA.frontmatter.sticky103 }104 if (pageA.frontmatter.sticky && !pageB.frontmatter.sticky)105 return -1106 if (!pageA.frontmatter.sticky && pageB.frontmatter.sticky) return 1107 if (!pageB.frontmatter.date) return 1108 if (!pageA.frontmatter.date) return -1109 return (110 new Date(pageB.frontmatter.date).getTime() -111 new Date(pageA.frontmatter.date).getTime()112 )113 },114 },115 {116 key: 'timeline',117 // only article with date should be added to timeline118 // @ts-ignore119 filter: (page) => page.frontmatter.date,120 // sort pages with time121 // sorter: (pageA, pageB) =>122 // new Date(pageB.frontmatter.date).getTime() -123 // new Date(pageA.frontmatter.date).getTime(),124 path: '/timeline/',125 layout: 'Timeline',126 frontmatter: () => ({title: 'Timeline', sidebar: false}),127 },128 ],129 // hotReload: true,130 }),131 ]...
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test submitted to WebPageTest! Check back later for results.');5 console.log('Test ID: ' + data.data.testId);6 client.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log('Got test results for ' + data.data.testId);9 console.log('First View (i.e. Load Time): ' + data.data.average.firstView.loadTime);10 console.log('Repeat Vieww(i.e. Load Time): ' + data.data.average.repeatView.loadTime);11 });12});
Using AI Code Generation
1var wpt = require('wpt');2wpt.pageB(function (err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.pageC(function (err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = r= require(t');18wpt.pageD(function (err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.pageE(function (err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.pageF(function (err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.pageG(function (err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.pageH(function (err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var wpt = require('wpt');58wpt.pageI(function (err, data) {59 if (err) {60 console.log(err);61 } else {62 console.log(data);63 }64});65var wpt = require('wpt');
Using AI Code Generation
1var wpt = require('webpagetest')bpagetest');2/ var WebPageTest = require('webpagetest');3return/ebPageTeerrtr= require('webpagetest');4 / else console.log(data);5 / });6 to use pageB 'Test;submiWbPTs!Viey Pteshtess.lcs epB%s'hodata.d of.us= Ur/oogle.com', function(err, data) {7} c});8var wpt = require('webpagetest');9wpt.wpt('hnet WebP/weTwst.'www.web cleath.org');t = require('wpt');10w.(.runT t'hod of www.gptgcom', e(c:i n:t'Delles_MG4't}, require(wpt');11t.pageB('horeturnle.log(daerrar;12var wpt = require('wpt');13 console.log(data);14});15var wpt = require('wpt');16 console.log(data);17});18var wpt = require('wpt');19 console.log(data);20});
Using AI Code Generation
1var pageB = require('webpagetest');2}, function(err, data) {3 if (err) {4 } else {5 }6});
Using AI Code Generation
1pageB = require('wpt').createPage();2 console.log('Status: ' + status);3 if(status === "success") {4 pageB.render('google.png');5 }6 phantom..xit();7});
Using AI Code Generation
1var wpt = require('wpt');2 console.log(data);3});4varwpt=requre('wpt');5 console.log(data);6});7var wpt = require('wpt');8 og(data);9});10var wpt = require('wpt');11 console.log(data)12});
Using AI Code Generation
1var wpt require('wpt');2 console.log(data);3});4var wpt require('wpt');5 console.log(data);6});7var wpt require('wpt');8 console.log(data);9});10var wpt require('wpt');11 console.log(data);12});13var wpt require('wpt');14 console.log(data);15});16var wpt require('wpt');17 console.log(data);18});19var pageB = require('./pageB');20pageB.method();
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!!