Best JavaScript code snippet using wpt
facebook.js
Source:facebook.js
1import dom from '@buzzfeed/buzzblocks/js/services/dom';2import storage from '@buzzfeed/buzzblocks/js/services/storage';3import util from '@buzzfeed/buzzblocks/js/services/util';4import client from '@buzzfeed/buzzblocks/js/services/client';5import sharing from './sharing';6//-----------------------------------------------------------7// Private8//-----------------------------------------------------------9var _fbAppId = window.BZFD.Config.facebookApi.appId || null;10var _FB_API_VERSION = window.BZFD.Config.facebookApi.version;11function getDefaultShareParams() {12 /*eslint-disable */13 //Needs to disable linting because app_id and iframe_test are not camelcase14 return {15 method: 'share',16 app_id: _fbAppId,17 href: sharing.getUrl(),18 caption: sharing.getCaption(),19 description: sharing.getDescription(),20 name: sharing.getTitle(),21 picture: sharing.getPicture(),22 ref: "mobile_share",23 iframe_test: true,24 };25 /*eslint-enable */26}27var _fb;28var _initializing;29/**30 * Loads Facebook JS SDK.31 * @memberOf service:facebook32 * @return {Promise} - promise object. Resolved when SDK is ready to use.33 */34function _init() {35 if (!_initializing) {36 _initializing = new Promise(resolve => {37 /**38 * Retrieves global SDK variable and resolves initialization promise.39 * @memberOf service:facebook40 * @return {void}41 */42 window.fbAsyncInit = function() {43 _fb = window.FB;44 _fb.init({45 version: _FB_API_VERSION,46 appId: _fbAppId,47 // check login status48 status: true,49 // enable cookies to allow the server to access the session50 cookie: true,51 // parse XFBML52 xfbml: true,53 });54 resolve(_fb);55 };56 });57 util.createScript('//connect.facebook.net/en_US/sdk.js');58 }59 return _initializing;60}61/**62 * Return to stored offset after share63 * @memberOf service:facebook64 * @return {void}65 */66function _restoreScrollPosition() {67 var shareOffset = storage.sessionGet('offset');68 if (shareOffset) {69 window.scrollTo(0, shareOffset);70 }71}72/**73 * Get scroll offset for returning after share74 * @memberOf service:facebook75 * @return {void}76 */77function _saveScrollPosition() {78 storage.sessionSet({79 key: 'offset',80 value: window.scrollY,81 });82}83//-----------------------------------------------------------84// Public85//-----------------------------------------------------------86/**87 * Service for working with Facebook.88 * @exports service:facebook89 */90var service = {};91/**92 * Parses XFBML markup on a target element.93 * @param {HTMLElement} targetNode - target element.94 * @return {void}95 */96service.parse = function(targetNode) {97 return _init().then((fb) => fb.XFBML.parse(targetNode));98};99/**100 * Subscribes to the Facebook event.101 * @param {String} ev - event name.102 * @param {Function} cb - event handler.103 * @return {void}104 */105service.subscribe = function(ev, cb) {106 return _init().then((fb) => fb.Event.subscribe(ev, cb));107};108/**109 * Unsubscribes from the Facebook event.110 * @param {String} ev - event name.111 * @param {String} cb - event handler.112 * @return {void}113 */114service.unsubscribe = function(ev, cb) {115 return _init().then((fb) => fb.Event.unsubscribe(ev, cb));116};117/**118 * Wrapper for FB.ui method.119 * @param {Object} data - options for FB.ui.120 * @param {Function} callback - callback.121 * @return {void}122 */123service.ui = function(data, callback) {124 _fb.ui(data, callback);125};126/**127 * Opens Facebook Feed Dialog.128 * @param {Object} data - parameters for the dialog.129 * @return {void}130 */131service.openFeedDialog = function(data) {132 var params = util.extend({}, getDefaultShareParams(), data);133 /*eslint-disable camelcase*/134 params.app_id = _fbAppId;135 data.redirect_uri = data.redirectUri || data.url;136 /*eslint-enable camelcase*/137 if (_fb) {138 _saveScrollPosition();139 service.ui(params, _restoreScrollPosition);140 // Prevents hash removal, when loader is closed before modal appears141 const dialogCloseBtn = dom.findOne(document, '#fb_dialog_loader_close');142 if (dialogCloseBtn) {143 dom.one(dialogCloseBtn, 'click', ev => ev.preventDefault());144 }145 } else {146 // Fallback to URL method147 util.openPopup(util.prepareUrl('https://www.facebook.com/dialog/' + params.method + '/?', params));148 }149};150/**151 * Share via Facebook Feed dialog.152 * @param {Object} data - share data.153 * @param {Event} ev - original event.154 * @return {void}155 */156service.share = function(data, ev) {157 /*158 * Temporary change due to bug with FB Feed Dialog SDK159 * TODO: Resolve this situation160 */161 if (client.os === 'android') {162 data.display = 'popup';163 /*eslint-disable */164 data.iframe_test = false;165 /*eslint-enable */166 }167 if (ev) {168 ev.preventDefault();169 }170 service.openFeedDialog(data);171};172service.init = _init;...
index.js
Source:index.js
...63]64Promise.all([65 websocket_test(websocket_test_suits),66 worker_test(worker_test_suits),67 iframe_test(iframe_test_suits),68]).then(function (results) {69 let concat_results = []70 for (let i = 0; i < results.length; ++i) {71 concat_results = concat_results.concat(results[i])72 }73 draw(concat_results)74 document.querySelector("#test_tip").innerHTML = "æµè¯å®æ"75}).catch(function (err) {76 console.error("test error:", err)77})78function draw(results) {79 let series = []80 let xdata = [];81 for (let i = 0; i < CONFIG.TEST_CASES.length; ++i) {...
Using AI Code Generation
1var wptdriver = require('wptdriver');2wptdriver.iframe_test(function() {3 var wptdriver = require('wptdriver');4 wptdriver.log('Hello world');5 wptdriver.done();6});7var wptdriver = require('wptdriver');8wptdriver.iframe_test(function() {9 var wptdriver = require('wptdriver');10 wptdriver.log('Hello world');11 wptdriver.done();12});13var wptdriver = require('wptdriver');14wptdriver.iframe_test(function() {15 var wptdriver = require('wptdriver');16 wptdriver.log('Hello world');17 wptdriver.done();18});19var wptdriver = require('wptdriver');20wptdriver.iframe_test(function() {21 var wptdriver = require('wptdriver');22 wptdriver.log('Hello world');23 wptdriver.done();24});25var wptdriver = require('wptdriver');26wptdriver.iframe_test(function() {27 var wptdriver = require('wptdriver');28 wptdriver.log('Hello world');29 wptdriver.done();30});31var wptdriver = require('wptdriver');32wptdriver.iframe_test(function() {33 var wptdriver = require('wptdriver');34 wptdriver.log('Hello world');35 wptdriver.done();36});37var wptdriver = require('wptdriver');38wptdriver.iframe_test(function() {39 var wptdriver = require('wptdriver');40 wptdriver.log('
Using AI Code Generation
1var wpt = new WebPagetest('www.webpagetest.org');2 console.log(data);3});4var wpt = new WebPagetest('www.webpagetest.org');5 console.log(data);6});7var wpt = new WebPagetest('www.webpagetest.org');8wpt.getLocations(function(data) {9 console.log(data);10});11var wpt = new WebPagetest('www.webpagetest.org');12wpt.getTesters(function(data) {13 console.log(data);14});15var wpt = new WebPagetest('www.webpagetest.org');16wpt.getTestStatus('140617_5S_4e4c3c4f1b4f4b7d1d9e9e9d4b4d4b4', function(data) {17 console.log(data);18});19var wpt = new WebPagetest('www.webpagetest.org');20wpt.getTestResults('140617_5S_4e4c3c4f1b4f4b7d1d9e9e9d4b4d4b4', function(data) {21 console.log(data);22});23var wpt = new WebPagetest('www.webpagetest.org');24wpt.getTestResults('140617_
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!!