Best JavaScript code snippet using wpt
admin-notifications.js
Source:admin-notifications.js
1/* global wpforms_admin, WPFormsAdmin */2/**3 * WPForms Admin Notifications.4 *5 * @since 1.6.06 */7'use strict';8var WPFormsAdminNotifications = window.WPFormsAdminNotifications || ( function( document, window, $ ) {9 /**10 * Elements holder.11 *12 * @since 1.6.013 *14 * @type {object}15 */16 var el = {17 $notifications: $( '#wpforms-notifications' ),18 $nextButton: $( '#wpforms-notifications .navigation .next' ),19 $prevButton: $( '#wpforms-notifications .navigation .prev' ),20 $adminBarCounter: $( '#wp-admin-bar-wpforms-menu .wpforms-menu-notification-counter' ),21 $adminBarMenuItem: $( '#wp-admin-bar-wpforms-notifications' ),22 };23 /**24 * Public functions and properties.25 *26 * @since 1.6.027 *28 * @type {object}29 */30 var app = {31 /**32 * Start the engine.33 *34 * @since 1.6.035 */36 init: function() {37 $( app.ready );38 },39 /**40 * Document ready.41 *42 * @since 1.6.043 */44 ready: function() {45 app.updateNavigation();46 app.events();47 },48 /**49 * Register JS events.50 *51 * @since 1.6.052 */53 events: function() {54 el.$notifications55 .on( 'click', '.dismiss', app.dismiss )56 .on( 'click', '.next', app.navNext )57 .on( 'click', '.prev', app.navPrev );58 },59 /**60 * Click on the Dismiss notification button.61 *62 * @since 1.6.063 *64 * @param {object} event Event object.65 */66 dismiss: function( event ) {67 if ( el.$currentMessage.length === 0 ) {68 return;69 }70 // Update counter.71 var count = parseInt( el.$adminBarCounter.text(), 10 );72 if ( count > 1 ) {73 --count;74 el.$adminBarCounter.html( count );75 } else {76 el.$adminBarCounter.remove();77 el.$adminBarMenuItem.remove();78 }79 // Remove notification.80 var $nextMessage = el.$nextMessage.length < 1 ? el.$prevMessage : el.$nextMessage,81 messageId = el.$currentMessage.data( 'message-id' );82 if ( $nextMessage.length === 0 ) {83 el.$notifications.remove();84 } else {85 el.$currentMessage.remove();86 $nextMessage.addClass( 'current' );87 app.updateNavigation();88 }89 // AJAX call - update option.90 var data = {91 action: 'wpforms_notification_dismiss',92 nonce: wpforms_admin.nonce,93 id: messageId,94 };95 $.post( wpforms_admin.ajax_url, data, function( res ) {96 if ( ! res.success ) {97 WPFormsAdmin.debug( res );98 }99 } ).fail( function( xhr, textStatus, e ) {100 WPFormsAdmin.debug( xhr.responseText );101 } );102 },103 /**104 * Click on the Next notification button.105 *106 * @since 1.6.0107 *108 * @param {object} event Event object.109 */110 navNext: function( event ) {111 if ( el.$nextButton.hasClass( 'disabled' ) ) {112 return;113 }114 el.$currentMessage.removeClass( 'current' );115 el.$nextMessage.addClass( 'current' );116 app.updateNavigation();117 },118 /**119 * Click on the Previous notification button.120 *121 * @since 1.6.0122 *123 * @param {object} event Event object.124 */125 navPrev: function( event ) {126 if ( el.$prevButton.hasClass( 'disabled' ) ) {127 return;128 }129 el.$currentMessage.removeClass( 'current' );130 el.$prevMessage.addClass( 'current' );131 app.updateNavigation();132 },133 /**134 * Update navigation buttons.135 *136 * @since 1.6.0137 */138 updateNavigation: function() {139 el.$currentMessage = el.$notifications.find( '.wpforms-notifications-message.current' );140 el.$nextMessage = el.$currentMessage.next( '.wpforms-notifications-message' );141 el.$prevMessage = el.$currentMessage.prev( '.wpforms-notifications-message' );142 if ( el.$nextMessage.length === 0 ) {143 el.$nextButton.addClass( 'disabled' );144 } else {145 el.$nextButton.removeClass( 'disabled' );146 }147 if ( el.$prevMessage.length === 0 ) {148 el.$prevButton.addClass( 'disabled' );149 } else {150 el.$prevButton.removeClass( 'disabled' );151 }152 },153 };154 return app;155}( document, window, jQuery ) );156// Initialize....
smtp-notifications.js
Source:smtp-notifications.js
1/* global wp_mail_smtp, ajaxurl */2/**3 * WP Mail SMTP Admin Notifications.4 *5 * @since 2.3.06 */7'use strict';8var WPMailSMTPAdminNotifications = window.WPMailSMTPAdminNotifications || ( function( document, window, $ ) {9 /**10 * Elements holder.11 *12 * @since 2.3.013 *14 * @type {object}15 */16 var el = {17 $notifications: $( '#wp-mail-smtp-notifications' ),18 $nextButton: $( '#wp-mail-smtp-notifications .navigation .next' ),19 $prevButton: $( '#wp-mail-smtp-notifications .navigation .prev' ),20 $adminBarCounter: $( '#wp-admin-bar-wp-mail-smtp-menu .wp-mail-smtp-admin-bar-menu-notification-counter' ),21 };22 /**23 * Public functions and properties.24 *25 * @since 2.3.026 *27 * @type {object}28 */29 var app = {30 /**31 * Start the engine.32 *33 * @since 2.3.034 */35 init: function() {36 $( document ).ready( app.ready );37 },38 /**39 * Document ready.40 *41 * @since 2.3.042 */43 ready: function() {44 app.updateNavigation();45 app.events();46 },47 /**48 * Register JS events.49 *50 * @since 2.3.051 */52 events: function() {53 el.$notifications54 .on( 'click', '.dismiss', app.dismiss )55 .on( 'click', '.next', app.navNext )56 .on( 'click', '.prev', app.navPrev );57 },58 /**59 * Click on the Dismiss notification button.60 *61 * @since 2.3.062 *63 * @param {object} event Event object.64 */65 dismiss: function( event ) {66 if ( el.$currentMessage.length === 0 ) {67 return;68 }69 // AJAX call - update option.70 var data = {71 action: 'wp_mail_smtp_notification_dismiss',72 nonce: wp_mail_smtp.nonce,73 id: el.$currentMessage.data( 'message-id' ),74 };75 $.post( ajaxurl, data, function( response ) {76 if ( ! response.success ) {77 return;78 }79 // Update counter.80 var count = parseInt( el.$adminBarCounter.text(), 10 );81 if ( count > 1 ) {82 --count;83 el.$adminBarCounter.html( '<span>' + count + '</span>' );84 } else {85 el.$adminBarCounter.remove();86 }87 // Remove notification.88 var $nextMessage = el.$nextMessage.length < 1 ? el.$prevMessage : el.$nextMessage;89 if ( $nextMessage.length === 0 ) {90 el.$notifications.remove();91 } else {92 el.$currentMessage.remove();93 $nextMessage.addClass( 'current' );94 app.updateNavigation();95 }96 } );97 },98 /**99 * Click on the Next notification button.100 *101 * @since 2.3.0102 *103 * @param {object} event Event object.104 */105 navNext: function( event ) {106 if ( el.$nextButton.hasClass( 'disabled' ) ) {107 return;108 }109 el.$currentMessage.removeClass( 'current' );110 el.$nextMessage.addClass( 'current' );111 app.updateNavigation();112 },113 /**114 * Click on the Previous notification button.115 *116 * @since 2.3.0117 *118 * @param {object} event Event object.119 */120 navPrev: function( event ) {121 if ( el.$prevButton.hasClass( 'disabled' ) ) {122 return;123 }124 el.$currentMessage.removeClass( 'current' );125 el.$prevMessage.addClass( 'current' );126 app.updateNavigation();127 },128 /**129 * Update navigation buttons.130 *131 * @since 2.3.0132 */133 updateNavigation: function() {134 el.$currentMessage = el.$notifications.find( '.message.current' );135 el.$nextMessage = el.$currentMessage.next( '.message' );136 el.$prevMessage = el.$currentMessage.prev( '.message' );137 if ( el.$nextMessage.length === 0 ) {138 el.$nextButton.addClass( 'disabled' );139 } else {140 el.$nextButton.removeClass( 'disabled' );141 }142 if ( el.$prevMessage.length === 0 ) {143 el.$prevButton.addClass( 'disabled' );144 } else {145 el.$prevButton.removeClass( 'disabled' );146 }147 },148 };149 return app;150}( document, window, jQuery ) );151// Initialize....
groupMessages.ts
Source:groupMessages.ts
1import { ApiMessage } from '../../../api/types';2import { IAlbum } from '../../../types';3import { getDayStart } from '../../../util/dateFormat';4import { isActionMessage } from '../../../modules/helpers';5type SenderGroup = (ApiMessage | IAlbum)[];6export type MessageDateGroup = {7 datetime: number;8 senderGroups: SenderGroup[];9};10export function isAlbum(messageOrAlbum: ApiMessage | IAlbum): messageOrAlbum is IAlbum {11 return 'albumId' in messageOrAlbum;12}13export function groupMessages(messages: ApiMessage[], firstUnreadId: number) {14 let currentSenderGroup: SenderGroup = [];15 let currentDateGroup = {16 datetime: Number(getDayStart(messages[0].date * 1000)),17 senderGroups: [currentSenderGroup],18 };19 let currentAlbum: IAlbum | undefined;20 const dateGroups: MessageDateGroup[] = [currentDateGroup];21 messages.forEach((message, index) => {22 if (message.groupedId) {23 if (!currentAlbum) {24 currentAlbum = {25 albumId: message.groupedId,26 messages: [message],27 };28 } else {29 currentAlbum.messages.push(message);30 }31 } else {32 currentSenderGroup.push(message);33 }34 const nextMessage = messages[index + 1];35 if (36 currentAlbum37 && (!nextMessage || !nextMessage.groupedId || nextMessage.groupedId !== currentAlbum.albumId)38 ) {39 currentSenderGroup.push(currentAlbum);40 currentAlbum = undefined;41 }42 if (nextMessage) {43 const nextMessageDatetime = Number(getDayStart(nextMessage.date * 1000));44 if (currentDateGroup.datetime !== nextMessageDatetime) {45 currentDateGroup = {46 datetime: nextMessageDatetime,47 senderGroups: [],48 };49 dateGroups.push(currentDateGroup);50 currentSenderGroup = [];51 currentDateGroup.senderGroups.push(currentSenderGroup);52 } else if (53 nextMessage.id === firstUnreadId54 || message.senderUserId !== nextMessage.senderUserId55 || message.isOutgoing !== nextMessage.isOutgoing56 || isActionMessage(message)57 || isActionMessage(nextMessage)58 ) {59 currentSenderGroup = [];60 currentDateGroup.senderGroups.push(currentSenderGroup);61 }62 }63 });64 return dateGroups;...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.nextMessage(data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});9{ statusCode: 200,10 { testId: '150311_6K_1',11 median: { firstView: {}, repeatView: {} },12 standardDeviation: { firstView: {}, repeatView: {} },13 [ { firstView: 14 { loadTime: 0,
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.log(err);4 console.log(data);5 wpt.nextMessage(data.data.testId, function(err, data) {6 console.log(data);7 });8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) return console.log(err);12 console.log(data);13 wpt.nextMessage(data.data.testId, function(err, data) {14 console.log(data);15 });16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) return console.log(err);20 console.log(data);21 wpt.nextMessage(data.data.testId, function(err, data) {22 console.log(data);23 });24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27 if (err) return console.log(err);28 console.log(data);29 wpt.nextMessage(data.data.testId, function(err, data) {30 console.log(data);31 });32});33var wpt = require('webpagetest');34var wpt = new WebPageTest('www.webpagetest.org');35 if (err) return console.log(err);36 console.log(data);37 wpt.nextMessage(data.data.testId, function(err, data) {38 console.log(data);39 });40});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3 if (err) return console.error(err);4 var testId = data.data.testId;5 test.nextMessage(testId, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8 });9});10{ statusCode: 200,11 data: { statusCode: 200, statusText: 'Ok', data: 'Test Started' } }
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 wpt.nextMessage(data.data.testId, function(err, data) {6 console.log(data);7 });8});9wpt.nextMessage(testId, callback);10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12var options = {13};14 wpt.nextMessage(data.data.testId, function(err, data) {15 console.log(data);16 });17});18wpt.getStatus(testId, callback);19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21var options = {22};
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var webpagetest = new wpt('www.webpagetest.org', options);5 if (err) return console.error(err);6 var testId = data.data.testId;7 console.log('Test ID: ' + testId);8 webpagetest.nextMessage(testId, function (err, data) {9 if (err) return console.error(err);10 console.log(data);11 });12});13#### new WebPageTest(host, [options])
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.nextMessage("test", function(err, message){3 if(err){4 console.log(err);5 }else{6 console.log(message);7 }8});9var wptoolkit = require('wptoolkit');10wptoolkit.nextMessage("test", function(err, message){11 if(err){12 console.log(err);13 }else{14 console.log(message);15 }16});17var wptoolkit = require('wptoolkit');18wptoolkit.nextMessage("test", function(err, message){19 if(err){20 console.log(err);21 }else{22 console.log(message);23 }24});25var wptoolkit = require('wptoolkit');26wptoolkit.nextMessage("test", function(err, message){27 if(err){28 console.log(err);29 }else{30 console.log(message);31 }32});33var wptoolkit = require('wptoolkit');34wptoolkit.nextMessage("test", function(err, message){35 if(err){36 console.log(err);37 }else{38 console.log(message);39 }40});41var wptoolkit = require('wptoolkit');42wptoolkit.nextMessage("test", function(err, message){43 if(err){44 console.log(err);45 }else{46 console.log(message);47 }48});49var wptoolkit = require('wptoolkit');50wptoolkit.nextMessage("test", function(err, message){51 if(err){52 console.log(err);53 }else{54 console.log(message);55 }56});57var wptoolkit = require('wptoolkit');58wptoolkit.nextMessage("test", function(err, message){
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt();3wpt.nextMessage(function (err, data) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(data);9 }10});11var wpt = require('wpt');12var wpt = new wpt();13 if (err) {14 console.log(err);15 }16 else {17 console.log(data);18 }19});20var wpt = require('wpt');21var wpt = new wpt();22wpt.getLocations(function (err, data) {23 if (err) {24 console.log(err);25 }26 else {27 console.log(data);28 }29});30var wpt = require('wpt');31var wpt = new wpt();32wpt.getTesters(function (err, data) {33 if (err) {34 console.log(err);35 }36 else {37 console.log(data);38 }39});40var wpt = require('wpt');41var wpt = new wpt();42wpt.getTestStatus('141229_5H_1e6', function (err, data) {43 if (err) {44 console.log(err);45 }46 else {47 console.log(data);48 }49});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var testId = '130915_3F_3b3f3e0f1a1a1c9f2a0e0a0e0d0f0f0f';4wpt.getTestResults(testId, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = new WebPageTest('www.webpagetest.org');12var testId = '130915_3F_3b3f3e0f1a1a1c9f2a0e0a0e0d0f0f0f';13wpt.getTestResults(testId, function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19});20var wpt = new WebPageTest('www.webpagetest.org');21var testId = '130915_3F_3b3f3e0f1a1a1c9f2a0e0a0e0d0f0f0f';22wpt.getTestResults(testId, function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var wpt = new WebPageTest('www.webpagetest.org');30var testId = '130915_3F_3b3f3e0f1a1a1c9f2a0e0a0e0d0f0f0f';31wpt.getTestResults(testId, function(err, data) {32 if (err) {33 console.log(err);34 } else {35 console.log(data);36 }37});38var wpt = new WebPageTest('www.webpagetest.org');39var testId = '130915_3F_3b3f3e0f1a1a1c9f2a0e0a0e0d0f0f0f';40wpt.getTestResults(testId, function(err, data) {41 if (err) {42 console.log(err);43 } else
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!!