Best JavaScript code snippet using devicefarmer-stf
editicalGSL.js
Source:editicalGSL.js
1/**2 * JEvents Component for Joomla! 3.x3 *4 * @version $Id: editicalJQ.js 3576 2012-05-01 14:11:04Z geraintedwards $5 * @package JEvents6 * @copyright Copyright (C) 2008--2020 GWESystems Ltd, 2006-2008 JEvents Project Group7 * @license GNU/GPLv2, see http://www.gnu.org/licenses/gpl-2.0.html8 * @link http://www.jevents.net9 */10document.addEventListener('DOMContentLoaded', function () {11 if (document.querySelectorAll) {12 let elems = document.querySelectorAll('#gslc .btn-group, #gslc .btn-group-ysts');13 for (let e = 0; e < elems.length; e++) {14 elems[e].classList.remove('btn-group');15 elems[e].classList.remove('radio');16 elems[e].classList.add('gsl-button-group');17 let inputs = elems[e].querySelectorAll('.radio');18 for (let i = 0; i < inputs.length; i++) {19 inputs[i].classList.remove('radio');20 }21 inputs = elems[e].querySelectorAll("input[type='checkbox'], input[type='radio']");22 for (let i = 0; i < inputs.length; i++) {23 inputs[i].classList.add('gsl-hidden');24 }25 let labels = elems[e].querySelectorAll("label.btn");26 for (let l = 0; l < labels.length; l++) {27 let label = labels[l];28 label.classList.remove('btn');29 label.classList.add('gsl-button');30 label.classList.add('gsl-button-default');31 label.classList.add('gsl-button-small');32 let activeClass = false;33 let input = document.getElementById(label.getAttribute('for'));34 if (input) {35 if (label.classList.contains('btn-danger')) {36 label.classList.remove('btn-danger');37 input.setAttribute('data-activeclass', 'danger');38 }39 if (label.classList.contains('btn-success')) {40 label.classList.remove('btn-success');41 input.setAttribute('data-activeclass', 'primary');42 }43 if (label.classList.contains('btn-warning')) {44 label.classList.remove('btn-warning');45 input.setAttribute('data-activeclass', 'warning');46 }47 if (input.checked || label.classList.contains('active')) {48 activeClass = input.getAttribute('data-activeclass');49 if (input.checked || label.classList.contains('active')) {50 if (activeClass) {51 label.classList.add('gsl-button-' + activeClass);52 } else if (this.value == 0) {53 label.classList.add('gsl-button-danger');54 } else {55 label.classList.add('gsl-button-primary');56 }57 } else {58 if (activeClass) {59 label.classList.remove('gsl-button-' + activeClass);60 }61 label.classList.remove('gsl-button-success');62 label.classList.remove('gsl-button-primary');63 label.classList.remove('gsl-button-danger');64 }65 }66 }67 label.classList.remove('active');68 }69 }70 elems = document.querySelectorAll('#gslc .checkbox-group');71 for (let e = 0; e < elems.length; e++) {72 elems[e].classList.remove('checkbox-group');73 elems[e].classList.remove('checkbox');74 elems[e].classList.add('gsl-button-group');75 let inputs = elems[e].querySelectorAll('.checkbox');76 for (let i = 0; i < inputs.length; i++) {77 inputs[i].classList.remove('checkbox');78 }79 inputs = elems[e].querySelectorAll("input[type='checkbox'], input[type='radio']");80 for (let i = 0; i < inputs.length; i++) {81 inputs[i].classList.add('gsl-hidden');82 }83 let labels = elems[e].querySelectorAll("label.btn");84 for (let l = 0; l < labels.length; l++) {85 let label = labels[l];86 label.classList.remove('btn');87 label.classList.add('gsl-button');88 label.classList.add('gsl-button-default');89 label.classList.add('gsl-button-small');90 let activeClass = false;91 let input = document.getElementById(label.getAttribute('for'));92 if (input) {93 activeClass = input.getAttribute('data-activeclass');94 if (input.checked || label.classList.contains('active')) {95 if (activeClass) {96 label.classList.add('gsl-button-' + activeClass);97 } else if (this.value == 0) {98 label.classList.add('gsl-button-danger');99 } else {100 label.classList.add('gsl-button-primary');101 }102 } else {103 if (activeClass) {104 label.classList.remove('gsl-button-' + activeClass);105 }106 label.classList.remove('gsl-button-primary');107 label.classList.remove('gsl-button-danger');108 }109 }110 label.classList.remove('active');111 }112 }113/*114 elems = document.querySelectorAll("#gslc i[class^='icon-']");115 for (let e = 0; e < elems.length; e++) {116 if (elems[e].classList.contains('icon-globe'))117 {118 alert (elems[e].classList);119 elems[e].classList.remove('icon-globe');120 elems[e].classList.add('gsl-icon');121 elems[e].setAttribute('data-gsl-icon' , 'icon:location');122 }123 }124 */125 }126});127/* Make core showon trigger fields work on keyup events as well as change events */128window.addEventListener('load', function() {129 if (document.querySelectorAll) {130 let showonFields = document.getElementById('jevents').querySelectorAll('[data-showon-gsl]');131 // Setup each 'showon' field onkeypress to mimic onchange132 for (let is = 0; is < showonFields.length; is++) {133 let target = showonFields[is];134 let jsondata = JSON.parse(target.getAttribute('data-showon-gsl')) || [],135 fields = [];136 if (typeof jsondata['AND'] !== 'undefined') {137 jsondata = jsondata['AND'];138 } else if (typeof jsondata['OR'] !== 'undefined') {139 jsondata = jsondata['OR'];140 } else {141 jsondata = jsondata;142 }143 // Collect an all referenced elements144 for (let ij = 0; ij < jsondata.length; ij++) {145 let field = jsondata[ij]['field'];146 let namefields = document.getElementById('jevents').querySelectorAll('[name="' + field + '"], [name="' + field + '[]"]');147 for (nf = 0; nf < namefields.length; nf++) {148 fields.push(namefields[nf]);149 }150 }151 for (let f = 0; f < fields.length; f++) {152 let type = fields[f].getAttribute('type');153 if (type == 'text' || type == 'radio' || type == 'checkbox') {154 if (fields[f].value.length > 0) {155 fields[f].setAttribute('data-keyuplistener', 1);156 }157 fields[f].addEventListener('keyup', function (event) {158 let keyuplistener = this.getAttribute('data-keyuplistener') || -1;159 if (keyuplistener > 0 && this.value.length == 0) {160 keyuplistener = -1;161 }162 if (keyuplistener == 0 && this.value.length > 0) {163 keyuplistener = -1;164 }165 if (keyuplistener > -1) {166 return;167 }168 this.setAttribute('data-keyuplistener', this.value.length);169 // Can't use new Event() because of MSIE :(170 // Create the event.171 let changeEvent = document.createEvent('Event');172 // Define that the event name is 'build'.173 changeEvent.initEvent('change', false, false);174 // target can be any Element or other EventTarget.175 this.dispatchEvent(changeEvent);176 });177 }178 }179 }180 }...
useKeyboard.ts
Source:useKeyboard.ts
1import React, { KeyboardEventHandler, useCallback, useEffect } from "react";2// utils3import { eventKeys } from "utils/constants";4type TargetType = { element: HTMLElement } & ({ keyDown: boolean } | { keyUp: boolean });5export type UseKeyboardType = (props: {6 target?: TargetType;7 keyDownListener?: KeyboardEventHandler | Record<string, KeyboardEventHandler>;8 keyUpListener?: KeyboardEventHandler | Record<string, KeyboardEventHandler>;9}) => {10 handleKeyDown: KeyboardEventHandler;11 handleKeyUp: KeyboardEventHandler;12};13const useKeyboard: UseKeyboardType = ({ target, keyDownListener, keyUpListener }) => {14 const handleKeyDown = useCallback<KeyboardEventHandler>(15 (event) => {16 if (keyDownListener) {17 if (typeof keyDownListener === "function") {18 keyDownListener(event);19 } else {20 if (keyDownListener[event.keyCode]) {21 if (keyDownListener[eventKeys.BEFORE_ALL]) {22 keyDownListener[eventKeys.BEFORE_ALL](event);23 }24 keyDownListener[event.keyCode](event);25 if (keyDownListener[eventKeys.AFTER_ALL]) {26 keyDownListener[eventKeys.AFTER_ALL](event);27 }28 }29 }30 }31 },32 [keyDownListener]33 );34 const handleKeyUp = useCallback<KeyboardEventHandler>(35 (event) => {36 if (keyUpListener) {37 if (typeof keyUpListener === "function") {38 keyUpListener(event);39 } else {40 if (keyUpListener[event.keyCode]) {41 if (keyUpListener[eventKeys.BEFORE_ALL]) {42 keyUpListener[eventKeys.BEFORE_ALL](event);43 }44 keyUpListener[event.keyCode](event);45 if (keyUpListener[eventKeys.AFTER_ALL]) {46 keyUpListener[eventKeys.AFTER_ALL](event);47 }48 }49 }50 }51 },52 [keyUpListener]53 );54 // add [keydown] listener to [target.element]55 useEffect(() => {56 const onKeyDown = (event: KeyboardEvent) => {57 handleKeyDown(event as unknown as React.KeyboardEvent);58 };59 if (target && "keyDown" in target) {60 if (target?.element && target?.keyDown) {61 target.element.addEventListener("keydown", onKeyDown);62 }63 }64 return () => target?.element?.removeEventListener("keydown", onKeyDown);65 }, [target, handleKeyDown]);66 // add [keyup] listener to [target.element]67 useEffect(() => {68 const onKeyUp = (event: KeyboardEvent) => {69 handleKeyUp(event as unknown as React.KeyboardEvent);70 };71 if (target && "keyUp" in target) {72 if (target?.element && target?.keyUp) {73 target.element.addEventListener("keyup", onKeyUp);74 }75 }76 return () => target?.element?.removeEventListener("keyup", onKeyUp);77 }, [target, handleKeyUp]);78 return { handleKeyDown, handleKeyUp };79};...
useNavigationEvents.js
Source:useNavigationEvents.js
1export default function useNavigationEvents() {2 let keyupListener;3 let clickListener;4 const onNextStep = (callback) => {5 window.addEventListener('keyup', keyupListener = (e) => {6 if (e.key === " " ||7 e.code === "Space" ||8 e.keyCode === 329 ) {10 e.preventDefault();11 callback();12 }13 });14 window.addEventListener('click', clickListener = (e) => {15 e.preventDefault();16 callback();17 }, false)18 }19 const clearListeners = () => {20 if (keyupListener) {21 window.removeEventListener('keyup', keyupListener);22 }23 if (clickListener) {24 window.removeEventListener('click', clickListener);25 }26 }27 return {28 onNextStep,29 clearListeners30 };...
Using AI Code Generation
1var keyupListener = require('devicefarmer-stf').keyupListener;2var keyup = keyupListener();3keyup.on('keyup', function(data) {4 console.log(data);5});6var keydownListener = require('devicefarmer-stf').keydownListener;7var keydown = keydownListener();8keydown.on('keydown', function(data) {9 console.log(data);10});11var keypressListener = require('devicefarmer-stf').keypressListener;12var keypress = keypressListener();13keypress.on('keypress', function(data) {14 console.log(data);15});16var keypressListener = require('devicefarmer-stf').keypressListener;17var keypress = keypressListener();18keypress.on('keypress', function(data) {19 console.log(data);20});21var keypressListener = require('devicefarmer-stf').keypressListener;22var keypress = keypressListener();23keypress.on('keypress', function(data) {24 console.log(data);25});26var keypressListener = require('devicefarmer-stf').keypressListener;27var keypress = keypressListener();28keypress.on('keypress', function(data) {29 console.log(data);30});31var keypressListener = require('devicefarmer-stf').keypressListener;32var keypress = keypressListener();33keypress.on('keypress', function(data) {34 console.log(data);35});36var keypressListener = require('devicefarmer-stf').keypressListener;37var keypress = keypressListener();38keypress.on('keypress', function(data) {39 console.log(data);40});41var keypressListener = require('devicefarmer-stf').keypressListener;
Using AI Code Generation
1var keyupListener = require('devicefarmer-stf').keyupListener;2keyupListener.listen(function(keyCode) {3 console.log('Key up: ' + keyCode);4});5var keydownListener = require('devicefarmer-stf').keydownListener;6keydownListener.listen(function(keyCode) {7 console.log('Key down: ' + keyCode);8});9var keypressListener = require('devicefarmer-stf').keypressListener;10keypressListener.listen(function(keyCode) {11 console.log('Key press: ' + keyCode);12});13var touchListener = require('devicefarmer-stf').touchListener;14touchListener.listen(function(touch) {15 console.log('Touch: ' + touch);16});17var touchListener = require('devicefarmer-stf').touchListener;18touchListener.listen(function(touch) {19 console.log('Touch: ' + touch);20});21var touchListener = require('devicefarmer-stf').touchListener;22touchListener.listen(function(touch) {23 console.log('Touch: ' + touch);24});25var touchListener = require('devicefarmer-stf').touchListener;26touchListener.listen(function(touch) {27 console.log('Touch: ' + touch);28});29var touchListener = require('devicefarmer-stf').touchListener;30touchListener.listen(function(touch) {31 console.log('Touch: ' + touch);32});33var touchListener = require('devicefarmer-stf').touchListener;34touchListener.listen(function(touch) {35 console.log('Touch: ' + touch);36});37var touchListener = require('devicefarmer-st
Using AI Code Generation
1var stf = require('stf');2stf.keyupListener(25, function() {3 console.log('keyup event');4});5stf.keydownListener(25, function() {6 console.log('keydown event');7});8stf.keypressListener(25, function() {9 console.log('keypress event');10});11stf.keyupListener(25, function() {12 console.log('keyup event');13});14stf.keydownListener(25, function() {15 console.log('keydown event');16});17stf.keypressListener(25, function() {18 console.log('keypress event');19});20stf.keyupListener(25, function() {21 console.log('keyup event');22});23stf.keydownListener(25, function() {24 console.log('keydown event');25});26stf.keypressListener(25, function() {27 console.log('keypress event');28});29stf.keyupListener(25, function() {30 console.log('keyup event');31});32stf.keydownListener(25, function() {33 console.log('keydown event');34});35stf.keypressListener(25, function() {36 console.log('keypress event');37});38stf.keyupListener(25, function() {39 console.log('keyup event');40});41stf.keydownListener(25, function() {42 console.log('keydown event');43});44stf.keypressListener(25, function() {
Using AI Code Generation
1var stf = require('stf-client');2client.keyupListener(function (err, data) {3 console.log(data);4});5{ serial: 'emulator-5554',6 scanCode: 0 }7var stf = require('stf-client');8client.keyupListener(function (err, data) {9 if (err) {10 console.log(err);11 }12 else {13 console.log(data);14 }15});
Using AI Code Generation
1var keyupListener = require('devicefarmer-stf-client/lib/keyevent/keyupListener.js');2keyupListener.keyupListener(10000, 5000, 10000);3var keydownListener = require('devicefarmer-stf-client/lib/keyevent/keydownListener.js');4keydownListener.keydownListener(10000, 5000, 10000);5var keypressListener = require('devicefarmer-stf-client/lib/keyevent/keypressListener.js');6keypressListener.keypressListener(10000, 5000, 10000);7var keyeventListener = require('devicefarmer-stf-client/lib/keyevent/keyeventListener.js');8keyeventListener.keyeventListener(10000, 5000, 10000);9var keyevent = require('devicefarmer-stf-client/lib/keyevent/keyevent.js');10keyevent.keyevent(10000, 5000, 10000);11var keyevent = require('devicefarmer-stf-client/lib/keyevent/keyevent.js');12keyevent.keyevent(10000, 5000, 10000);13var keyevent = require('devicefarmer-stf-client/lib/keyevent/keyevent.js');14keyevent.keyevent(10000, 5000, 10000);15var keyevent = require('devicefarmer-stf-client/lib/keyevent/keyevent.js');16keyevent.keyevent(10000, 5000, 10000);17var keyevent = require('devicefarmer-stf-client/lib/keyevent/keyevent.js');18keyevent.keyevent(10000, 5000, 10000);19var keyevent = require('devicefarmer-stf-client/lib/keyevent/keyevent.js');20keyevent.keyevent(10000, 5000,
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!!