Best JavaScript code snippet using wpt
AboutMain.js
Source:AboutMain.js
1Ext.define('DevCycleMobile.view.AboutMain', {2 extend: 'Ext.tab.Panel',3 xtype: 'aboutMain',4 requires: [5 'Ext.TitleBar',6 'Ext.SegmentedButton',7 'Ext.ux.AccordionList',8 'Ext.plugin.ListPaging',9 'Ext.plugin.PullRefresh'10 ],11 config: {12 tabBarPosition: 'top',13 tabBar: {14 scrollable : 'horizontal'15 },16 items: [17 {18 xtype: 'titlebar',19 title: 'TourTrak TD Five Boro Bike Tour',20 docked: 'top',21 style: {22 backgroundImage: 'url(resources/images/carbon_fibre.png)'23 }24 },25 {26 title: 'Credits',27 layout: 'vbox',28 items: [29 {30 xtype: 'accordionlist',31 store: Ext.create('DevCycleMobile.store.Credits'),32 flex: 1,33 itemId: 'paging',34 listeners: {35 initialize: function() {36 this.load();37 }38 }39 }40 ],41 control: {42 'button[action=expand]': {43 tap: function() {44 this.down('accordionlist').doAllExpand();45 }46 },47 'button[action=collapse]': {48 tap: function() {49 this.down('accordionlist').doAllCollapse();50 }51 }52 }53 },54 {55 title: 'Tracking',56 layout: 'vbox',57 items: [58 {59 xtype: 'accordionlist',60 store: Ext.create('DevCycleMobile.store.AboutTracking'),61 flex: 1,62 itemId: 'basic',63 listeners: {64 initialize: function() {65 this.load();66 }67 }68 },69 {70 xtype: 'button',71 hidden: 'true',72 ui: 'confirm',73 text: 'Resume Tracking',74 id: 'btnResume',75 handler: function() {76 // call resumeTracking on the cordova abstraction layer77 cordova.exec(78 function() {79 // do nothing on success80 },81 function(message) {82 alert( "Error: " + message );83 },84 'CDVInterface',85 'resumeTracking',86 []87 );88 // show pause button89 Ext.get('btnPause').show();90 // hide this button91 Ext.get('btnResume').hide();92 }93 },94 {95 xtype: 'button',96 ui: 'decline',97 text: 'Pause Tracking',98 id: 'btnPause',99 handler: function() {100 // call pauseTracking on the cordova abstraction layer101 cordova.exec(102 function() {103 // do nothing on success104 },105 function(message) {106 alert( "Error: " + message );107 },108 'CDVInterface',109 'pauseTracking',110 []111 );112 // show resume button113 Ext.get('btnResume').show();114 //hide this button115 Ext.get('btnPause').hide();116 }117 }118 ],119 control: {}120 },121 {122 title: 'TourTrak',123 layout: 'vbox',124 items: [125 {126 xtype: 'accordionlist',127 store: Ext.create('DevCycleMobile.store.AboutTourTrak'),128 flex: 1,129 itemId: 'paging',130 listeners: {131 initialize: function() {132 this.load();133 }134 }135 }136 ],137 control: {138 'button[action=expand]': {139 tap: function() {140 this.down('accordionlist').doAllExpand();141 }142 },143 'button[action=collapse]': {144 tap: function() {145 this.down('accordionlist').doAllCollapse();146 }147 }148 }149 }150 ],151 listeners: {152 // XXX: For grouped accordionList153 activeitemchange: function(self, newItem) {154 var me = this,155 list = newItem.down('accordionlist'),156 store = list.getStore();157 if (store.getCount() === 0) {158 me.setMasked({159 xtype: 'loadmask'160 });161 store.on('load', function() {162 me.setMasked(false);163 }, me, { single: true });164 store.load({165 callback: function() {166 list.getList().refresh();167 }168 });169 }170 }171 }172 }173});174// If you use index bar, it might be better to override175// Ext.dataview.List scroolToRecord in case of record is empty.176Ext.define('Override.dataview.List', {177 override : 'Ext.dataview.List',178 scrollToRecord: function(record, animate, overscroll) {179 var me = this,180 store = me.getStore(),181 index = store.indexOf(record);182 item = me.listItems[index];183 if (item) {184 me.callParent(arguments);185 }186 }...
communication.js
Source:communication.js
...26 }27 startTracking() {28 window.ipcRenderer.send('start-tracking');29 }30 pauseTracking() {31 window.ipcRenderer.send('pause-tracking');32 }33 startPreview() {34 window.ipcRenderer.send('start-preview');35 }36 stopPreview() {37 window.ipcRenderer.send('stop-preview');38 }39 openUserData() {40 window.ipcRenderer.send('open-user-data');41 }42 removeTouch(timestamp) {43 window.ipcRenderer.send('remove-touch', timestamp);44 }...
effect.js
Source:effect.js
1const { isArray, isObject, isMap, isSet } = require('./utils')2let shouldTrack = true3let activeEffect4const effectStack = []5const trackStack = []6const targetMap = new WeakMap()7const ITERATE_KEY = Symbol('')8const MAP_KEY_ITERATE_KEY = Symbol('')9const pauseTracking = () => {10 trackStack.push(shouldTrack)11 shouldTrack = false12}13const enableTracking = () => {14 trackStack.push(shouldTrack)15 shouldTrack = true16}17const resetTracking = () => {18 const last = trackStack.pop()19 shouldTrack = last === undefined ? true : last20}21const effect = (fn, options = {}) => {22 const effectIns = function reactiveEffect() {23 if (!effectIns.active) {24 return fn()25 }26 if (!effectStack.includes(effectIns)) {27 clearEffect(effectIns)28 try {29 enableTracking()30 effectStack.push(effectIns)31 activeEffect = effectIns32 return fn()33 } catch (e) {34 console.log(e)35 } finally {36 effectStack.pop()37 resetTracking()38 activeEffect = effectStack[effectStack.length - 1]39 }40 }41 }42 effectIns.active = true43 effectIns.deps = []44 effectIns.options = options45 return effectIns46}47const clearEffect = (effect) => {48 const { deps } = effect49 if (deps.length) {50 for (let i = 0; i < deps.length; i++) {51 deps[i].delete(effect)52 }53 deps.length = 054 }55}56const stopEffect = (effect) => {57 if (effect.active) {58 clearEffect(effect)59 if (effect.options.onStop) {60 effect.options.onStop()61 }62 effect.active = false63 }64}65const track = (target, key) => {66 if (!shouldTrack || activeEffect === undefined) {67 return68 }69 let depsMap = targetMap.get(target)70 if (!depsMap) {71 targetMap.set(target, (depsMap = new Map()))72 }73 let dep = depsMap.get(key)74 if (!dep) {75 depsMap.set(key, (dep = new Set()))76 }77 if (!dep.has(activeEffect)) {78 dep.add(activeEffect)79 activeEffect.deps.push(dep)80 }81}82const trigger = (target, type, key, newValue, oldValue) => {83 const depsMap = targetMap.get(target)84 if (!depsMap) {85 return86 }87 const effects = new Set()88 const add = (dep = []) => dep.forEach((effect) => effects.add(effect))89 if (type == 'clear') {90 depsMap.forEach(add)91 } else if (key === 'length' && isArray(target)) {92 depsMap.forEach((dep, key) => {93 if (key === 'length' || key >= newValue) {94 add(dep)95 }96 })97 } else {98 if (key) {99 add(depsMap.get(key))100 }101 switch (type) {102 case 'add':103 if (!isArray(target)) {104 //触åèªèº«105 add(depsMap.get(ITERATE_KEY))106 if (isMap(target)) {107 add(depsMap.get(MAP_KEY_ITERATE_KEY))108 }109 } else if (isIntegerKey(key)) {110 // new index added to array -> length changes111 add(depsMap.get('length'))112 }113 break114 case 'delete':115 if (!isArray(target)) {116 add(depsMap.get(ITERATE_KEY))117 if (isMap(target)) {118 add(depsMap.get(MAP_KEY_ITERATE_KEY))119 }120 }121 break122 case 'set':123 if (isMap(target)) {124 add(depsMap.get(ITERATE_KEY))125 }126 break127 }128 }129 effects.forEach((effect) => {130 if (effect !== activeEffect) {131 if (effect.options.scheduler) {132 effect.options.scheduler(effect)133 } else {134 effect()135 }136 }137 })138}139exports.effect = effect140exports.track = track141exports.trigger = trigger142exports.pauseTracking = pauseTracking143exports.enableTracking = enableTracking...
Container(1).js
Source:Container(1).js
1Ext.Loader.setConfig({2 enabled:true,3 paths:{'Ext.ux.touch':'touch/src'}}4);5Ext.require(['Ext.Leaflet']);6/**7* Defines the custom map container component for holding8* everything necessary in the map tab view.9**/10Ext.define('DevCycleMobile.view.map.Container', {11 extend: 'Ext.Container',12 xtype: 'mapContainer',13 id: 'mapContainer',14 config: {15 title: 'Map',16 iconCls: 'maps',17 layout: 'fit',18 items: [19 {20 xtype: 'toolbar',21 docked: 'top',22 id: 'mapTitleBar',23 title: 'Tour Trak',24 cls: 'my-toolbar'25 },26 {27 xtype: 'leaflet',28 useCurrentLocation: true29 },30 {31 xtype: 'button',32 docked: 'bottom',33 hidden: 'true',34 ui: 'confirm',35 height: '60',36 text: 'Resume Tracking',37 id: 'btnResume',38 handler: function() {39 // call resumeTracking on the cordova abstraction layer40 cordova.exec(41 function() {42 // do nothing on success43 },44 function(message) {45 alert( "Error: " + message );46 },47 'CDVInterface',48 'resumeTracking',49 []50 );51 // show pause button52 Ext.get('btnPause').show();53 // hide this button54 Ext.get('btnResume').hide();55 }56 },57 {58 xtype: 'button',59 docked: 'bottom',60 ui: 'decline',61 height: '60',62 text: 'Pause Tracking',63 id: 'btnPause',64 handler: function() {65 // call pauseTracking on the cordova abstraction layer66 cordova.exec(67 function() {68 // do nothing on success69 },70 function(message) {71 alert( "Error: " + message );72 },73 'CDVInterface',74 'pauseTracking',75 []76 );77 // show resume button78 Ext.get('btnResume').show();79 //hide this button80 Ext.get('btnPause').hide();81 }82 }83 ], // End items84 } // End config...
power-manager.js
Source:power-manager.js
...8 this._suspendDetected = false;9 this._powerSaveBlockedId = -1;10 powerMonitor.on('suspend', () => {11 log.debug('System going to sleep.');12 this.pauseTracking();13 });14 powerMonitor.on('resume', () => {15 log.debug('System resumed from sleep state.');16 this.resumeTracking();17 });18 powerMonitor.on('lock-screen', () => {19 log.debug('System locked.');20 this.pauseTracking();21 });22 powerMonitor.on('unlock-screen', () => {23 log.debug('System unlocked.');24 this.resumeTracking();25 });26 powerMonitor.on('shutdown', () => osIntegration.gracefullExit());27 tracker.on('started', () => {28 this._powerSaveBlockedId = powerSaveBlocker.start('prevent-display-sleep');29 if (powerSaveBlocker.isStarted(this._powerSaveBlockedId))30 log.debug('Prevent display sleep while tracking!');31 else32 log.warning('Can\'t setup Power Save Blocker!');33 });34 tracker.on('stopped', () => {35 if (this._powerSaveBlockedId > -1 && powerSaveBlocker.isStarted(this._powerSaveBlockedId)) {36 log.debug('Now display can sleep!');37 powerSaveBlocker.stop(this._powerSaveBlockedId);38 }39 });40 log.debug('Loaded');41 }42 pauseTracking() {43 if (tracker.active && !this._suspendDetected) {44 this._suspendDetected = true;45 tracker.pauseTicker();46 log.debug('Tracker paused.');47 }48 }49 resumeTracking() {50 if (this._suspendDetected) {51 this._suspendDetected = false;52 tracker.resumeTicker();53 log.debug('Tracker resumed.');54 }55 }56}...
lifecycle.js
Source:lifecycle.js
...17}18export function injectHook(type, hook, target) {19 if (target) {20 (target[type] || (target[type] = [])).push((...args) => {21 pauseTracking();22 setCurrentInstance(target);23 const res = hook(...args);24 setCurrentInstance(null);25 resumeTracking();26 return res;27 });28 }29}30export function callHook(target, type, ...args) {31 if (target && isArray(target[type])) {32 target[type].forEach(hook => {33 hook(...args);34 });35 }...
plugin.js
Source:plugin.js
1import videojs from 'video.js';2import {version as VERSION} from '../package.json';3import BufferTracking from './tracking/buffering';4import PauseTracking from './tracking/pause';5import PositionTracking from './tracking/percentile';6import PerformanceTracking from './tracking/performance';7import PlayTracking from './tracking/play';8import SeekTracking from './tracking/seek';9// Cross-compatibility for Video.js 5 and 6.10const registerPlugin = videojs.registerPlugin || videojs.plugin;11const getPlugin = videojs.getPlugin || videojs.plugin;12/**13 * Event Tracking for VideoJS14 *15 * @function eventTracking16 * @param {Object} [options={}]17 * An object of options left to the plugin author to define.18 */19const eventTracking = function(options) {20 PauseTracking.apply(this, arguments);21 BufferTracking.apply(this, arguments);22 PositionTracking.apply(this, arguments);23 PlayTracking.apply(this, arguments);24 SeekTracking.apply(this, arguments);25 PerformanceTracking.apply(this, arguments);26};27// Register the plugin with video.js, avoid double registration28if (typeof getPlugin('eventTracking') === 'undefined') {29 registerPlugin('eventTracking', eventTracking);30}31// Include the version number.32eventTracking.VERSION = VERSION;...
pause.js
Source:pause.js
1/**2 * Tracks when users pause the video.3 *4 * Example Usage:5 * player.on('tracking:pause', (e, data) => console.log(data))6 *7 * Data Attributes:8 * => pauseCount: Total number of Pause events triggered9 *10 * @function PauseTracking11 * @param {Object} [config={}]12 * An object of config left to the plugin author to define.13 */14const PauseTracking = function(config) {15 const player = this;16 let pauseCount = 0;17 let timer = null;18 let locked = false;19 const reset = function(e) {20 if (timer) {21 clearTimeout(timer);22 }23 pauseCount = 0;24 locked = false;25 };26 player.on('dispose', reset);27 player.on('loadstart', reset);28 player.on('ended', reset);29 player.on('pause', function() {30 if (player.scrubbing() || locked) {31 return;32 }33 timer = setTimeout(function() {34 pauseCount++;35 player.trigger('tracking:pause', {pauseCount});36 }, 300);37 });38};...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});
Using AI Code Generation
1var wpt = require('wpt-api');2var wpt = new wpt('API_KEY');3wpt.pauseTracking(testId, function(err, data) {4 if(err) {5 console.log(err);6 }7 else {8 console.log(data);9 }10});11var wpt = require('wpt-api');12var wpt = new wpt('API_KEY');13wpt.resumeTracking(testId, function(err, data) {14 if(err) {15 console.log(err);16 }17 else {18 console.log(data);19 }20});21var wpt = require('wpt-api');22var wpt = new wpt('API_KEY');23wpt.getTestResults(testId, function(err, data) {24 if(err) {25 console.log(err);26 }27 else {28 console.log(data);29 }30});
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!!