Best JavaScript code snippet using wpt
jquery.bs_pagination.min.js
Source:jquery.bs_pagination.min.js
1/**2 * @fileOverview bs_pagination: jQuery pagination plugin, based on Twitter Bootstrap.3 * <p>License MIT4 * <br />Copyright Christos Pontikis <a href="http://pontikis.net">http://pontikis.net</a>5 * <br />Project page <a href="http://www.pontikis.net/labs/bs_pagination">http://www.pontikis.net/labs/bs_pagination</a>6 * <br />Minified using Online YUI Compressor http://www.refresh-sf.com/yui/7 * @version 1.0.2 (09 May 2014)8 * @author Christos Pontikis http://www.pontikis.net9 * @requires jquery >= 1.8, twitter bootstrap >= 210 */11"use strict";12(function (e) {13 var d = "bs_pagination";14 var b = {15 init: function (g) {16 var h = this;17 return this.each(function () {18 var C = h.data(d);19 if (typeof C == "undefined") {20 var E = "3";21 if (g.hasOwnProperty("bootstrap_version") && g.bootstrap_version == "2") {22 E = "2"23 }24 var v = b.getDefaults.call(h, E);25 C = e.extend({}, v, g)26 } else {27 C = e.extend({}, C, g)28 }29 if (C.totalRows == 0) {30 C.totalRows = C.totalPages * C.rowsPerPage31 }32 h.data(d, C);33 h.unbind("onChangePage").bind("onChangePage", C.onChangePage);34 h.unbind("onLoad").bind("onLoad", C.onLoad);35 var y = h.attr("id"), r = c(C.nav_list_id_prefix, y), k = c(C.nav_top_id_prefix, y),36 A = c(C.nav_prev_id_prefix, y), q = c(C.nav_item_id_prefix, y) + "_",37 o = c(C.nav_next_id_prefix, y), p = c(C.nav_last_id_prefix, y), x = c(C.nav_goto_page_id_prefix, y),38 B = c(C.nav_rows_per_page_id_prefix, y), m = c(C.nav_rows_info_id_prefix, y), w = "", l, i, u, s, z,39 t, n, j, D;40 if (C.bootstrap_version == "3") {41 w += '<div class="' + C.mainWrapperClass + '">';42 w += '<div class="' + C.navListContainerClass + '">';43 w += '<div class="' + C.navListWrapperClass + '">';44 w += '<ul id="' + r + '" class="' + C.navListClass + '">';45 w += "</ul>";46 w += "</div>";47 w += "</div>";48 if (C.showGoToPage && C.visiblePageLinks < C.totalPages) {49 w += '<div class="' + C.navGoToPageContainerClass + '">';50 w += '<div class="input-group">';51 w += '<span class="input-group-addon" title="' + rsc_bs_pag.go_to_page_title + '"><i class="' + C.navGoToPageIconClass + '"></i></span>';52 w += '<input id="' + x + '" type="text" class="' + C.navGoToPageClass + '" title="' + rsc_bs_pag.go_to_page_title + '">';53 w += "</div>";54 w += "</div>"55 }56 if (C.showRowsPerPage) {57 w += '<div class="' + C.navRowsPerPageContainerClass + '">';58 w += '<div class="input-group">';59 w += '<span class="input-group-addon" title="' + rsc_bs_pag.rows_per_page_title + '"><i class="' + C.navRowsPerPageIconClass + '"></i></span>';60 w += '<input id="' + B + '" value="' + C.rowsPerPage + '" type="text" class="' + C.navRowsPerPageClass + '" title="' + rsc_bs_pag.rows_per_page_title + '">';61 w += "</div>";62 w += "</div>"63 }64 if (C.showRowsInfo) {65 w += '<div class="' + C.navInfoContainerClass + '">';66 w += '<div id="' + m + '" class="' + C.navInfoClass + '"></div>';67 w += "</div>"68 }69 } else {70 w += '<div class="' + C.mainWrapperClass + '">';71 w += '<div class="' + C.navListContainerClass + '">';72 w += '<div class="' + C.navListWrapperClass + '">';73 w += '<ul id="' + r + '" class="' + C.navListClass + '">';74 w += "</ul>";75 w += "</div>";76 w += "</div>";77 if ((C.showGoToPage && C.visiblePageLinks < C.totalPages) || C.showRowsPerPage) {78 w += '<div class="' + C.navInputsContainerClass + '">';79 if (C.showGoToPage && C.visiblePageLinks < C.totalPages) {80 w += '<div class="' + C.navGoToPageWrapperClass + '">';81 w += '<span class="add-on" title="' + rsc_bs_pag.go_to_page_title + '"><i class="' + C.navGoToPageIconClass + '"></i></span>';82 w += '<input id="' + x + '" type="text" class="' + C.navGoToPageClass + '" title="' + rsc_bs_pag.go_to_page_title + '">';83 w += "</div>"84 }85 if (C.showRowsPerPage) {86 w += '<div class="' + C.navRowsPerPageWrapperClass + '">';87 w += '<span class="add-on" title="' + rsc_bs_pag.rows_per_page_title + '"><i class="' + C.navRowsPerPageIconClass + '"></i></span>';88 w += '<input id="' + B + '" value="' + C.rowsPerPage + '" type="text" class="' + C.navRowsPerPageClass + '" title="' + rsc_bs_pag.rows_per_page_title + '">';89 w += "</div>"90 }91 w += "</div>"92 }93 if (C.showRowsInfo) {94 w += '<div class="' + C.navInfoContainerClass + '">';95 w += '<div id="' + m + '" class="' + C.navInfoClass + '"></div>';96 w += "</div>"97 }98 }99 w += "</div>";100 h.html(w);101 l = null;102 i = C.currentPage;103 f(y, l, i, true, false);104 h.removeClass().addClass(C.containerClass);105 if (!C.directURL) {106 u = "#" + k;107 h.off("click", u).on("click", u, function () {108 var G = C.currentPage;109 C.currentPage = 1;110 var F = C.currentPage;111 f(y, G, F, true, true)112 });113 s = "#" + A;114 h.off("click", s).on("click", s, function () {115 if (C.currentPage > 1) {116 var G = C.currentPage;117 C.currentPage = parseInt(C.currentPage) - 1;118 var F = C.currentPage;119 var H = (h.data("nav_start") == G);120 f(y, G, F, H, true)121 }122 });123 t = "#" + o;124 h.off("click", t).on("click", t, function () {125 if (C.currentPage < C.totalPages) {126 var G = C.currentPage;127 C.currentPage = parseInt(C.currentPage) + 1;128 var F = C.currentPage;129 var H = (h.data("nav_end") == G);130 f(y, G, F, H, true)131 }132 });133 n = "#" + p;134 h.off("click", n).on("click", n, function () {135 var G = C.currentPage;136 C.currentPage = parseInt(C.totalPages);137 var F = C.currentPage;138 f(y, G, F, true, true)139 });140 z = '[id^="' + q + '"]';141 h.off("click", z).on("click", z, function (I) {142 var H = C.currentPage;143 var F = q.length;144 C.currentPage = parseInt(e(I.target).attr("id").substr(F));145 var G = C.currentPage;146 f(y, H, G, false, true)147 })148 }149 if (C.showGoToPage) {150 j = "#" + x;151 h.off("keypress", j).on("keypress", j, function (I) {152 if (I.which === 13) {153 var H = parseInt(e(j).val());154 e(j).val("");155 if (!isNaN(H) && H > 0) {156 if (H > C.totalPages) {157 H = C.totalPages158 }159 var G = C.currentPage;160 C.currentPage = H;161 var F = H;162 if (C.directURL) {163 location.href = C.directURL(F)164 } else {165 f(y, G, F, true, true)166 }167 }168 I.preventDefault()169 } else {170 if (!(I.which === 8 || I.which === 0 || (I.shiftKey === false && (I.which > 47 && I.which < 58)))) {171 I.preventDefault()172 }173 }174 })175 }176 if (C.showRowsPerPage) {177 D = "#" + B;178 h.off("keypress", D).on("keypress", D, function (H) {179 if (H.which === 13) {180 var I = parseInt(e(D).val());181 if (!isNaN(I) && I > 0) {182 if (I > C.maxRowsPerPage) {183 I = C.maxRowsPerPage184 }185 e(D).val(I);186 C.rowsPerPage = I;187 C.totalPages = Math.ceil(C.totalRows / C.rowsPerPage);188 var G = C.currentPage;189 C.currentPage = 1;190 var F = 1;191 if (C.directURL) {192 location.href = C.directURL(F)193 } else {194 f(y, G, F, true, true)195 }196 } else {197 D.val(C.rowsPerPage)198 }199 H.preventDefault()200 } else {201 if (!(H.which === 8 || H.which === 0 || (H.shiftKey === false && (H.which > 47 && H.which < 58)))) {202 H.preventDefault()203 }204 }205 })206 }207 })208 }, getVersion: function () {209 return "1.0.2"210 }, getDefaults: function (h) {211 var g = {212 currentPage: 1,213 rowsPerPage: 10,214 maxRowsPerPage: 100,215 totalPages: 100,216 totalRows: 0,217 visiblePageLinks: 5,218 showGoToPage: true,219 showRowsPerPage: true,220 showRowsInfo: true,221 showRowsDefaultInfo: true,222 directURL: false,223 disableTextSelectionInNavPane: true,224 bootstrap_version: "3",225 containerClass: "well",226 mainWrapperClass: "row",227 navListContainerClass: "col-xs-12 col-sm-12 col-md-6",228 navListWrapperClass: "",229 navListClass: "pagination pagination_custom",230 navListActiveItemClass: "active",231 navGoToPageContainerClass: "col-xs-6 col-sm-4 col-md-2 row-space",232 navGoToPageIconClass: "glyphicon glyphicon-arrow-right",233 navGoToPageClass: "form-control small-input",234 navRowsPerPageContainerClass: "col-xs-6 col-sm-4 col-md-2 row-space",235 navRowsPerPageIconClass: "glyphicon glyphicon-th-list",236 navRowsPerPageClass: "form-control small-input",237 navInfoContainerClass: "col-xs-12 col-sm-4 col-md-2 row-space",238 navInfoClass: "",239 nav_list_id_prefix: "nav_list_",240 nav_top_id_prefix: "top_",241 nav_prev_id_prefix: "prev_",242 nav_item_id_prefix: "nav_item_",243 nav_next_id_prefix: "next_",244 nav_last_id_prefix: "last_",245 nav_goto_page_id_prefix: "goto_page_",246 nav_rows_per_page_id_prefix: "rows_per_page_",247 nav_rows_info_id_prefix: "rows_info_",248 onChangePage: function () {249 },250 onLoad: function () {251 }252 };253 if (h == "2") {254 g.bootstrap_version = "2";255 g.containerClass = "well";256 g.mainWrapperClass = "row-fluid";257 g.navListContainerClass = "span6";258 g.navListWrapperClass = "pagination pagination_custom";259 g.navListClass = "";260 g.navListActiveItemClass = "active";261 g.navInputsContainerClass = "span4 row-space";262 g.navGoToPageWrapperClass = "input-prepend goto_page_wrapper";263 g.navGoToPageIconClass = "icon-arrow-right";264 g.navGoToPageClass = "small-input";265 g.navRowsPerPageWrapperClass = "input-prepend rows_per_page_wrapper";266 g.navRowsPerPageIconClass = "icon-th-list";267 g.navRowsPerPageClass = "small-input";268 g.navInfoContainerClass = "span2 row-space";269 g.navInfoClass = ""270 }271 return g272 }, getOption: function (g) {273 var h = this;274 return h.data(d)[g]275 }, getAllOptions: function () {276 var g = this;277 return g.data(d)278 }, destroy: function () {279 var g = this;280 g.removeData()281 }, setRowsInfo: function (g) {282 var h = this, i = c(b.getOption.call(h, "getOption", "nav_rows_info_id_prefix"), h.attr("id"));283 e("#" + i).html(g)284 }285 };286 var c = function (h, g) {287 return h + g288 };289 var f = function (F, k, g, J, u) {290 var I = e("#" + F), B = b.getAllOptions.call(I), t = c(B.nav_item_id_prefix, F) + "_";291 if (J) {292 var l = c(B.nav_list_id_prefix, F), h = c(B.nav_top_id_prefix, F), H = c(B.nav_prev_id_prefix, F),293 m = c(B.nav_next_id_prefix, F), r = c(B.nav_last_id_prefix, F), v = e("#" + l), G = "",294 z = parseInt(B.currentPage), x, E, L, q, C, y = "", w = "javascript:void(0);";295 if (B.totalPages < B.visiblePageLinks) {296 z = 1;297 x = B.totalPages298 } else {299 C = Math.ceil(B.totalPages / B.visiblePageLinks);300 if (z > B.visiblePageLinks * (C - 1)) {301 z = B.totalPages - B.visiblePageLinks + 1302 } else {303 L = z % B.visiblePageLinks;304 q = L == 0 ? -B.visiblePageLinks + 1 : -L + 1;305 z += q306 }307 x = z + B.visiblePageLinks - 1308 }309 I.data("nav_start", z);310 I.data("nav_end", x);311 if (z > 1) {312 y = B.directURL ? B.directURL(1) : w;313 G += '<li><a id="' + h + '" href="' + y + '">' + rsc_bs_pag.go_top_text + "</a></li>";314 y = B.directURL ? B.directURL(z - 1) : w;315 G += '<li><a id="' + H + '" href="' + y + '">' + rsc_bs_pag.go_prev_text + "</a></li>"316 }317 for (E = z; E <= x; E++) {318 y = B.directURL ? B.directURL(E) : w;319 G += '<li><a id="' + t + E + '" href="' + y + '">' + E + "</a></li>"320 }321 if (x < B.totalPages) {322 y = B.directURL ? B.directURL(x + 1) : w;323 G += '<li><a id="' + m + '" href="' + y + '">' + rsc_bs_pag.go_next_text + "</a></li>";324 y = B.directURL ? B.directURL(B.totalPages) : w;325 G += '<li><a id="' + r + '" href="' + y + '">' + rsc_bs_pag.go_last_text + "</a></li>"326 }327 v.html(G);328 if (B.disableTextSelectionInNavPane) {329 a(v)330 }331 }332 var p = e("#" + t + k), K = e("#" + t + g);333 p.closest("li").removeClass(B.navListActiveItemClass);334 K.closest("li").addClass(B.navListActiveItemClass);335 var D = rsc_bs_pag.current_page_label + " " + g + " " + rsc_bs_pag.total_pages_label + " " + B.totalPages;336 p.prop("title", "");337 K.prop("title", D);338 if (B.showRowsInfo && B.showRowsDefaultInfo) {339 var o = ((B.currentPage - 1) * B.rowsPerPage) + 1, n = Math.min(o + B.rowsPerPage - 1, B.totalRows),340 A = o + "-" + n + " " + rsc_bs_pag.total_rows_label + " " + B.totalRows + " " + rsc_bs_pag.rows_info_records + " (" + rsc_bs_pag.current_page_abbr_label + B.currentPage + rsc_bs_pag.total_pages_abbr_label + B.totalPages + ")",341 j = c(B.nav_rows_info_id_prefix, F);342 e("#" + j).html(A)343 }344 if (u) {345 I.triggerHandler("onChangePage", {currentPage: g, rowsPerPage: B.rowsPerPage})346 } else {347 I.triggerHandler("onLoad", {currentPage: g, rowsPerPage: B.rowsPerPage})348 }349 };350 var a = function (g) {351 return g.attr("unselectable", "on").css("user-select", "none").on("selectstart", false)352 };353 e.fn.bs_pagination = function (h) {354 if (this.size() != 1) {355 var g = "You must use this plugin (" + d + ") with a unique element (at once)";356 this.html('<span style="color: red;">ERROR: ' + g + "</span>");357 e.error(g)358 }359 if (b[h]) {360 return b[h].apply(this, Array.prototype.slice.call(arguments, 1))361 } else {362 if (typeof h === "object" || !h) {363 return b.init.apply(this, arguments)364 } else {365 e.error("Method " + h + " does not exist on jQuery." + d)366 }367 }368 }...
utils.js
Source:utils.js
1var currentImage = null;2var currentWindow = null;3function makeUrl(data) {4 var url = 'https://app.trycache.co/items/create?';5 Object.keys(data).forEach(function(key) {6 url += '&' + key + '=' + data[key];7 });8 return url;9}10function openUrl(data) {11 currentWindow = createWindow(12 makeUrl(data), 'Cache | Store this ' + data.type, 75013 );14}15function createWindow(url, title, width, height) {16 height = height || screen.height;17 var top = (screen.height / 2) - (height / 2);18 var left = (screen.width / 2) - (width / 2);19 var options = 'scrollbars=yes';20 options += ', top=' + top;21 options += ', left=' + left;22 options += ', width=' + width;23 options += ', height=' + height;24 var w = window.open(url, title, options);25 if (window.focus) {26 w.focus();27 }28 return w;29}30function removeQueryString(str) {31 return str ? str.replace(/\?.+$/g, '') : '';32}33function getExtension(str) {34 var match = str.match(/\.([0-9a-z]+)(?:[\?#]|$)/i);35 return match ? match[match.length - 1].replace('.', '') : '';36}37function getSelectedText() {38 return window.getSelection().toString().trim();39}40function saveLink(data) {41 var item = {};42 item = {43 type: 'link',44 sourceUrl: encodeURIComponent(data.sourceUrl),45 directUrl: encodeURIComponent(data.directUrl),46 storingMethod: 'extension-chrome'47 };48 openUrl(item);49}50function saveText(data) {51 openUrl({52 type: 'text',53 metaText: encodeURIComponent(data.text),54 sourceUrl: encodeURIComponent(data.sourceUrl),55 directUrl: encodeURIComponent(data.directUrl),56 storingMethod: 'extension-chrome'57 });58}59function saveImage(data) {60 var image = new Image();61 function onImageLoad(w, h) {62 item.metaWidth = w;63 item.metaHeight = h;64 if (w === h) {65 item.metaOrientation = 'square';66 } else if (w > h) {67 item.metaOrientation = 'landscape';68 } else if (w < h) {69 item.metaOrientation = 'portrait';70 }71 currentImage = null;72 openUrl(item);73 }74 var item = {75 type: 'image',76 sourceUrl: encodeURIComponent(data.sourceUrl),77 directUrl: encodeURIComponent(data.directUrl),78 metaExtension: getExtension(data.directUrl),79 storingMethod: 'extension-chrome'80 };81 if (currentImage && currentImage.src === decodeURIComponent(data.directUrl)) {82 onImageLoad(currentImage.width, currentImage.height);83 } else {84 image.src = data.directUrl;85 if (image.complete) {86 onImageLoad(image.width, image.height);87 } else {88 image.addEventListener('load', function() {89 onImageLoad(image.width, image.height);90 });91 }92 }93}94function saveVideo(data) {95 openUrl({96 type: 'video',97 sourceUrl: encodeURIComponent(data.sourceUrl),98 directUrl: encodeURIComponent(data.directUrl),99 storingMethod: 'extension-chrome',100 metaExtension: getExtension(data.directUrl)101 });102}103function saveAudio(data) {104 openUrl({105 type: 'audio',106 sourceUrl: encodeURIComponent(data.sourceUrl),107 directUrl: encodeURIComponent(data.directUrl),108 storingMethod: 'extension-chrome',109 metaExtension: getExtension(data.directUrl)110 });...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3if (err) return console.log(err);4console.log(data);5});6if (err) return console.log(err);7console.log(data);8});9if (err) return console.log(err);10console.log(data);11});12if (err) return console.log(err);13console.log(data);14});15if (err) return console.log(err);16console.log(data);17});18if (err) return console.log(err);19console.log(data);20});21if (err) return console.log(err);22console.log(data);23});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3var options = {4};5test.runTest(options.url, options, function(err, data) {6 if (err) {7 console.log('Error: ' + err);8 } else {9 console.log('Test URL: ' + data.data.userUrl);10 console.log('Test ID: ' + data.data.testId);11 console.log('Test Status: ' + data.data.statusText);12 }13});14var wpt = require('webpagetest');15var test = wpt('www.webpagetest.org');16var options = {17};18test.runTest(options.url, options, function(err, data) {19 if (err) {20 console.log('Error: ' + err);21 } else {22 console.log('Test URL: ' + data.data.userUrl);23 console.log('Test ID: ' + data.data.testId);24 console.log('Test Status: ' + data.data.statusText);25 }26});27var wpt = require('webpagetest');28var test = wpt('www.webpagetest.org');29var options = {30};31test.runTest(options.url, options, function(err, data) {32 if (err) {33 console.log('Error: ' + err);34 } else {35 console.log('Test URL: ' + data.data.userUrl);36 console.log('Test ID: ' + data.data.testId);37 console.log('Test Status: ' + data.data.statusText);38 }39});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3test.runTest(url, { location: 'Dulles:Chrome', pollResults: 5 }, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var test = new wpt('www.webpagetest.org');12test.runTest(url, { location: 'Dulles:Chrome', pollResults: 5 }, function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6 if (err) return console.error(err);7 console.log(data);8});9 if (err) return console.error(err);10 console.log(data);11});12 if (err) return console.error(err);13 console.log(data);14});15 if (err) return console.error(err);16 console.log(data);17});18 if (err) return console.error(err);19 console.log(data);20});21 if (err) return console.error(err);22 console.log(data);23});
Using AI Code Generation
1const wpt = require('webpagetest');2const wptClient = wpt('www.webpagetest.org');3wptClient.getTestStatus('180821_4X_4e4c4b2d6b4c0b8c0c7d6a3e3f0b3a7a', (err, data) => {4 console.log(data);5});6wptClient.runTest(url, {7 videoParams: {8 }9}, (err, data) => {10 console.log(data);11});
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var test = wpt(options);5 if (err) {6 console.error('Error: ' + err);7 } else {8 console.log('Test status: ' + data.statusCode);9 console.log('Test ID: ' + data.data.testId);10 console.log('Test URL: ' + data.data.userUrl);11 }12});
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!!