Best JavaScript code snippet using wpt
sh404sefsocial.js
Source:sh404sefsocial.js
1/**2 * sh404SEF - SEO extension for Joomla!3 *4 * @author Yannick Gaultier5 * @copyright (c) Yannick Gaultier - Weeblr llc - 20156 * @package sh404SEF7 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL8 * @version 4.7.2.31809 * @date 2015-12-2310 */11// get Google Analytics queue12var _gaq = _gaq || [];13// our own tracker14var _sh404sefSocialTrack = _sh404sefSocialTrack || [];15// which analytics type is in use?16var sh404SEFAnalyticsType = sh404SEFAnalyticsType || [];17_sh404sefSocialTrack.setup = function () {18 FB.init({19 appId: _sh404sefSocialTrack.options.FBAppId ? _sh404sefSocialTrack.options.FBAppId : "",20 version: "v2.3",21 status: true, // check login status22 cookie: true, // enable cookies to allow the server to access the session23 oauth: true, // enable OAuth 2.024 xfbml: true // parse XFBML25 });26 if (_sh404sefSocialTrack.options.enableAnalytics) {27 // compute tracker name28 _sh404sefSocialTrack.trackerName = _sh404sefSocialTrack.options.trackerName ? _sh404sefSocialTrack.options.trackerName29 : "sh404SEF_social_tracker";30 // enable tracking, either sync. or async.31 _sh404sefSocialTrack.setupFBTracking();32 _sh404sefSocialTrack.setupTweeterTracking();33 }34};35/*36 * Facebook tracking : Call directly if SDK loaded synchroneously or assign to37 * window.fbAsyncInit if using asynchronous loading38 */39_sh404sefSocialTrack.setupFBTracking = function () {40 try {41 if (FB && FB.Event && FB.Event.subscribe) {42 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.classic) {43 FB.Event.subscribe('edge.create', function (targetUrl) {44 _gaq.push([ '_trackEvent', _sh404sefSocialTrack.trackerName + '_facebook', 'like', targetUrl, 1, true ]);45 // Google tracking46 if (_sh404sefSocialTrack.options.enableGoogleTracking) {47 _gaq.push([ '_trackSocial', 'facebook', 'like', targetUrl ]);48 }49 });50 FB.Event.subscribe('edge.remove', function (targetUrl) {51 _gaq.push([ '_trackEvent', _sh404sefSocialTrack.trackerName + '_facebook', 'unlike', targetUrl, 1, true ]);52 // Google tracking53 if (_sh404sefSocialTrack.options.enableGoogleTracking) {54 _gaq.push([ '_trackSocial', 'facebook', 'unlike', targetUrl ]);55 }56 });57 FB.Event.subscribe('message.send', function (targetUrl) {58 _gaq.push([ '_trackEvent', _sh404sefSocialTrack.trackerName + '_facebook', 'send', targetUrl, 1, true ]);59 // Google tracking60 if (_sh404sefSocialTrack.options.enableGoogleTracking) {61 _gaq.push([ '_trackSocial', 'facebook', 'send', targetUrl ]);62 }63 });64 }65 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.universal) {66 FB.Event.subscribe('edge.create', function (targetUrl) {67 ga('send', 'event', _sh404sefSocialTrack.trackerName + '_facebook', 'like', targetUrl, 1);68 // Google tracking69 if (_sh404sefSocialTrack.options.enableGoogleTracking) {70 ga('send', 'social', 'facebook', 'like', targetUrl);71 }72 });73 FB.Event.subscribe('edge.remove', function (targetUrl) {74 ga('send', 'event', _sh404sefSocialTrack.trackerName + '_facebook', 'unlike', targetUrl, 1);75 // Google tracking76 if (_sh404sefSocialTrack.options.enableGoogleTracking) {77 ga('send', 'social', 'facebook', 'unlike', targetUrl);78 }79 });80 FB.Event.subscribe('message.send', function (targetUrl) {81 ga('send', 'event', _sh404sefSocialTrack.trackerName + '_facebook', 'send', targetUrl, 1);82 // Google tracking83 if (_sh404sefSocialTrack.options.enableGoogleTracking) {84 ga('send', 'social', 'facebook', 'send', targetUrl);85 }86 });87 }88 }89 } catch (e) {90 console.log(e.message);91 }92};93// Tweeter tracking94_sh404sefSocialTrack.setupTweeterTracking = function () {95 try {96 if (twttr && twttr.events && twttr.events.bind) {97 twttr.events.bind('tweet', function (event) {98 if (event) {99 var targetUrl; // Default value is undefined.100 if (event.target && event.target.nodeName == 'IFRAME') {101 targetUrl = _sh404sefSocialTrack.extractParamFromUri(event.target.src, 'url');102 }103 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.classic) {104 _gaq.push([ '_trackEvent', _sh404sefSocialTrack.trackerName + '_tweeter', 'tweet', targetUrl, 1, true ]);105 // Google tracking106 if (_sh404sefSocialTrack.options.enableGoogleTracking) {107 _gaq.push([ '_trackSocial', 'twitter', 'tweet', targetUrl ]);108 }109 }110 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.universal) {111 ga('send', 'event', _sh404sefSocialTrack.trackerName + '_tweeter', 'tweet', targetUrl, 1);112 // Google tracking113 if (_sh404sefSocialTrack.options.enableGoogleTracking) {114 ga('send', 'social', 'tweeter', 'tweet', targetUrl);115 }116 }117 }118 });119 }120 } catch (e) {121 console.log(e.message);122 }123};124/*125 * Pinterest tracking, through a callback126 */127_sh404sefSocialTrackPinterestTracking = function (msg, url) {128 try {129 if (msg == "pinned") {130 var targetMedia = _sh404sefSocialTrack.extractParamFromUri(url, 'url') + ' ('131 + _sh404sefSocialTrack.extractParamFromUri(url, 'media') + ')';132 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.classic) {133 _gaq.push([ '_trackEvent', _sh404sefSocialTrack.trackerName + '_pinterest', msg, targetMedia, 1, true ]);134 }135 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.universal) {136 ga('send', 'event', _sh404sefSocialTrack.trackerName + '_pinterest', msg, targetUrl, 1);137 }138 }139 } catch (e) {140 console.log(e.message);141 }142};143/*144 * G+ requires a callback function for each click145 */146_sh404sefSocialTrackGPlusTracking = function (data) {147 try {148 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.classic) {149 if (data.state == "on" || data.state == "off") {150 _gaq.push([ '_trackEvent', _sh404sefSocialTrack.trackerName + '_gplus', data.state, data.href, 1, true ]);151 }152 }153 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.universal) {154 if (data.state == "on" || data.state == "off") {155 ga('send', 'event', _sh404sefSocialTrack.trackerName + '_gplus', data.state, data.href, 1);156 }157 }158 } catch (e) {159 console.log(e.message);160 }161};162// Google page click tracking163_sh404sefSocialTrack.GPageTracking = function (target, source) {164 try {165 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.classic) {166 _gaq.push([ '_trackEvent', _sh404sefSocialTrack.trackerName + '_gplus_page', target, source, 1, true ]);167 }168 if (sh404SEFAnalyticsType && sh404SEFAnalyticsType.universal) {169 ga('send', 'event', _sh404sefSocialTrack.trackerName + '_gplus_page', target, source, 1);170 }171 } catch (e) {172 console.log(e.message);173 }174};175/**176 * Extracts a query parameter value from a URI. (c) Google - 2011177 *178 * @param {string}179 * uri The URI from which to extract the parameter.180 * @param {string}181 * paramName The name of the query paramater to extract.182 * @return {string} The un-encoded value of the query paramater. underfined if183 * there is no URI parameter.184 * @private185 */186_sh404sefSocialTrack.extractParamFromUri = function (uri, paramName) {187 if (!uri || !uri.indexOf('#')) {188 return;189 }190 var uri = uri.indexOf('#') > 0 ? uri.split('#')[1] : uri; // Remove anchor.191 // Find url param.192 paramName += '=';193 uri = uri.split('?');194 uri = uri[1] ? uri[1] : uri[0];195 var params = uri.split('&');196 for (var i = 0, param; param = params[i]; ++i) {197 if (param.indexOf(paramName) === 0) {198 return unescape(decodeURI(param.split('=')[1]));199 }200 }201 return;...
ajax.js
Source:ajax.js
1/*2 $RCSfile: ajax.js,v $3 $Revision: 1.0 $4 $Date: 2007/11/08 11:45 $5*/6var Ajaxs = new Array();7function Ajax(recvType, statusId) {8 var aj = new Object();9 aj.statusId = statusId ? document.getElementById(statusId) : null;10 aj.targetUrl = '';11 aj.sendString = '';12 aj.recvType = recvType ? recvType : 'XML';13 aj.resultHandle = null;1415 aj.createXMLHttpRequest = function() {16 var request = false;17 if(window.XMLHttpRequest) {18 request = new XMLHttpRequest();19 if(request.overrideMimeType) {20 request.overrideMimeType('text/xml');21 }22 } else if(window.ActiveXObject) {23 var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];24 for(var i=0; i<versions.length; i++) {25 try {26 request = new ActiveXObject(versions[i]);27 if(request) {28 return request;29 }30 } catch(e) {31 //alert(e.message);32 }33 }34 }35 return request;36 }3738 aj.XMLHttpRequest = aj.createXMLHttpRequest();3940 aj.processHandle = function() {41 if(aj.statusId) {42 aj.statusId.style.display = '';43 }44 if(aj.XMLHttpRequest.readyState == 1 && aj.statusId) {45 aj.statusId.innerHTML = xml_http_building_link;46 } else if(aj.XMLHttpRequest.readyState == 2 && aj.statusId) {47 aj.statusId.innerHTML = xml_http_sending;48 } else if(aj.XMLHttpRequest.readyState == 3 && aj.statusId) {49 aj.statusId.innerHTML = xml_http_loading;50 } else if(aj.XMLHttpRequest.readyState == 4) {51 if(aj.XMLHttpRequest.status == 200) {52 for(k in Ajaxs) {53 if(Ajaxs[k] == aj.targetUrl) {54 Ajaxs[k] = null;55 }56 }5758 if(aj.statusId) {59 aj.statusId.innerHTML = xml_http_data_in_processed;60 aj.statusId.style.display = 'none';61 }62 if(aj.recvType == 'HTML') {63 aj.resultHandle(aj.XMLHttpRequest.responseText, aj);64 } else if(aj.recvType == 'XML') {65 aj.resultHandle(aj.XMLHttpRequest.responseXML.lastChild.firstChild.nodeValue, aj);66 }67 } else {68 if(aj.statusId) {69 aj.statusId.innerHTML = xml_http_load_failed;70 }71 }72 }73 }7475 aj.get = function(targetUrl, resultHandle) {76 if(in_array(targetUrl, Ajaxs)) {77 return false;78 } else {79 arraypush(Ajaxs, targetUrl);80 }81 aj.targetUrl = targetUrl;82 aj.XMLHttpRequest.onreadystatechange = aj.processHandle;83 aj.resultHandle = resultHandle;84 if(window.XMLHttpRequest) {85 aj.XMLHttpRequest.open('GET', aj.targetUrl);86 aj.XMLHttpRequest.send(null);87 } else {88 aj.XMLHttpRequest.open("GET", targetUrl, true);89 aj.XMLHttpRequest.send();90 }91 }9293 aj.post = function(targetUrl, sendString, resultHandle) {94 if(in_array(targetUrl, Ajaxs)) {95 return false;96 } else {97 arraypush(Ajaxs, targetUrl);98 }99 aj.targetUrl = targetUrl;100 aj.sendString = sendString;101 aj.XMLHttpRequest.onreadystatechange = aj.processHandle;102 aj.resultHandle = resultHandle;103 aj.XMLHttpRequest.open('POST', targetUrl);104 aj.XMLHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');105 aj.XMLHttpRequest.send(aj.sendString);106 }107 return aj;
...
Using AI Code Generation
1var wpt = require('webpagetest');2var api = wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var api = wpt('www.webpagetest.org');8api.getLocations(function(err, data) {9 if (err) return console.error(err);10 console.log(data);11});12var wpt = require('webpagetest');13var api = wpt('www.webpagetest.org');14api.getTesters(function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('webpagetest');19var api = wpt('www.webpagetest.org');20api.getTestStatus('140115_9Y_1a7', function(err, data) {21 if (err) return console.error(err);22 console.log(data);23});24var wpt = require('webpagetest');25var api = wpt('www.webpagetest.org');26api.getTestResults('140115_9Y_1a7', function(err, data) {27 if (err) return console.error(err);28 console.log(data);29});30var wpt = require('webpagetest');31var api = wpt('www.webpagetest.org');32 if (err) return
Using AI Code Generation
1var wptApi = require('wpt-api');2var options = {3};4wptApi.runTest(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wptApi = require('wpt-api');12var options = {13};14wptApi.runTest(options, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wptApi = require('wpt-api');22var options = {
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!!