Best JavaScript code snippet using wpt
MForm.js
Source:MForm.js
1/**2 * ä¸è¡¨åç¸å
³çæ¹æ³3 * 4 * @author å§åç¶5 */678//å
¬ç¨çform对象9var MForm = function() {10 "use strict";// ä¸¥æ ¼æ¨¡å¼1112 return {1314 /**15 * 表åæ交åï¼åå§åä¸äºå¿
è¦çäºæ
16 */17 initForm : function(_initParam) {1819 var option = {20 beforeSubmit : null,// 表åæ交ä¹åè°ç¨å½æ°21 afterSubmit : null,// å·æ°æ°æ®åè°å½æ°22 formSelecter : "#dataform",// 表åé»è®¤éæ©å¨23 isvalid : true,// æ¯å¦å¯¹è¡¨åè¿è¡éªè¯24 validform : null,// éªè¯è¡¨å25 extendParam : {},// éè¦æ·»å å°è¡¨åä¸çé¢å¤åæ°ä¼ä¸èµ·æ交å°æå¡å¨26 invokeUrl : "",// æ°æ®æ交å°å27 layerIndex : "",// layerå½åçªå£çindexå¼ï¼ç¨æ¥å
³éiframï¼28 isAutoClose : true,// æ¯å¦èªå¨å
³é29 }30 option = $.extend(option, _initParam);31 var mForm = new mform(option);32 return mForm;33 },3435 /**36 * form表åæ°æ®è½¬json37 */38 toJson : function(form) {39 var result = {};40 var fieldArray = $(form).serializeArray();41 for (var i = 0; i < fieldArray.length; i++) {42 var field = fieldArray[i];43 if (field.name in result) {44 result[field.name] += "," + field.value;45 } else {46 result[field.name] = field.value;47 }48 }49 return result;50 },51 /**52 * é置表å53 */54 reset:function clear_form(formId){55 $(':input',formId) 56 .not(':button, :submit, :reset, :hidden') 57 .val('') 58 .removeAttr('value')59 .removeAttr('checked') 60 .removeAttr('selected');61 $(".select2",formId).val("").trigger("change"); 62 }6364 }65}();6667//ç§æform表å对象68function mform(option) {6970 this.initParam = option;71 // 对表åè¿éªè¯72 if (this.initParam.isvalid) {73 this.initParam.validform = MValidform74 .validform(this.initParam.formSelecter);75 }76 if (parent.layer.getFrameIndex) {77 this.initParam.layerIndex = parent.layer.getFrameIndex(window.name);78 }7980 // æ交表åæ°æ®81 this.submit = function() {8283 var _this = this;8485 // éªè¯è¡¨å86 if (this.initParam.isvalid) {87 if (!this.initParam.validform.check()) {88 return false;89 }90 }91 // è°ç¨beforesubmit92 if (this.initParam.beforeSubmit) {93 if (this.initParam.beforeSubmit() == false) {94 return;95 }96 }97 98 // æ交表åæ°æ®99 $.AjaxProxy(100 {101 p : $.extend(MForm.toJson(_this.initParam.formSelecter),102 _this.initParam.extendParam)103104 }).invoke(105 _this.initParam.invokeUrl,106 function(loj) {107 if (layer.alert) {108 // æ§è¡æåå¼¹åºæ示å±109 layer.msg(loj.getValue("info"), {110 icon : 1,time: 1000111 }, function(inindex) {112 // å
³éæ示å±113 layer.close(inindex);114 // èªå®ä¹å·æ°åè°115 if (_this.initParam.afterSubmit) {116 _this.initParam.afterSubmit();117 }118 // å
³éiframeå±119 if (_this.initParam.isAutoClose120 && _this.initParam.layerIndex) {121 parent.layer.close(_this.initParam.layerIndex);122 }123 });124 return;125 } else {126 // èªå®ä¹å·æ°åè°127 if (_this.initParam.afterSubmit) {128 _this.initParam.afterSubmit(loj);129 }130 }131 });132 };133 return this;
...
Pagination.js
Source:Pagination.js
1/**2 * å页工å
· by å§åç¶ 2016-07-203 */4var Pagination = function() {56 return {7 initParam:{8 pageNow : 1,9 pageSize : 10,10 url:"",11 pagingBoxSelect:"#pagingBox",12 showdataBoxSelect:"#showdataBox",13 offsetSelect:"#_offset",//æ°æ®è§æ 14 builderDate:null,//å建æ°æ®å½æ°15 },16 17 init:function(param){18 initParam=$.extend(this.initParam,param);19 console.log(param)20 console.log(initParam)21 return this;22 },2324 /**25 * æ¹å页æ°26 */27 changePage : function(_pageNow) {28 initParam.pageNow = _pageNow;29 $(initParam.offsetSelect).val((initParam.pageNow - 1) * initParam.pageSize);30 this.serchDate();31 },32 33 //æç´¢æ°æ®34 serchDate:function(){35 36 $.AjaxProxy({c:false,p:MForm.toJson("#dataform")}).invoke(initParam.url , function(loj){37 $(initParam.showdataBoxSelect).empty().html(Pagination.initParam.builderDate(loj));38 //æ建å页信æ¯39 Pagination.paging(loj.getValue("total"));40 });41 42 },43 /**44 * 计ç®å页45 */46 paging:function(rowCount){47 console.log( initParam.pageNow);48 if(rowCount%initParam.pageSize==0){49 initParam.pageCount=parseInt(rowCount/initParam.pageSize);50 }else{51 initParam.pageCount=parseInt(rowCount/initParam.pageSize+1);52 }53// var html = '<span><span>å
± ' + rowCount + ' æ¡è®°å½ </span>   å
±'54// + initParam.pageCount + '页/å½å第' + initParam.pageNow + '页</span>  ';55 var html="";56 if (initParam.pageNow == 1) {57 html += '<a class="size-S mr-5" onclick="javascript:void(0)" ><</a>';58 } else {59 html += '<a class="size-S mr-5" onclick="Pagination.changePage(' + (initParam.pageNow - 1) + ')" ><</a>';60 }61 var begin = 0;62 var end = 0;6364 if (initParam.pageCount <= 6) {65 begin = 1;66 end = initParam.pageCount;67 } else {68 begin = initParam.pageNow - 2;69 end = initParam.pageNow + 3 >initParam.pageCount?initParam.pageCount:initParam.pageNow + 3 ;70 if (begin < 1) {71 begin = 1;72 end = 6;73 }74 if (end > initParam.pageCount) {75 begin = pageCount - 5;76 end = pageCount;77 }78 }79 if (initParam.pageNow > 3) {80 html += '<a class="size-S mr-5" onclick="Pagination.changePage(' + 1 + ')" >é¦é¡µ</a>';81 }82 for (var i = begin; i <= end; i++) {8384 if (initParam.pageNow == i) {85 html += '<a class="active size-S mr-5" onclick="javascript:void(0)" >'86 + i + '</a>';87 } else {88 html += '<a class=" size-S mr-5" onclick="Pagination.changePage(' + i + ')">' + i + '</a>';89 }9091 }92 if (end < initParam.pageCount) {93 html += '<a class=" size-S mr-5" onclick="Pagination.changePage(' + pageCount + ')">尾页</a>';94 }95 if (initParam.pageNow == initParam.pageCount) {96 html += '<a class="size-S mr-5" onclick="javascript:void(0)">></a>';97 } else {9899 html += '<a class="size-S mr-5" onclick="Pagination.changePage(' + (initParam.pageNow + 1) + ')" >></a>';100 }101 $(initParam.pagingBoxSelect).empty().html(html);102 }103 }
...
transaction.js
Source:transaction.js
...8 'api' : 'transaction',9 'do' : 'types'10 };11 if ( userId != null )12 initParam(params, 'user', userId);13 if ( start != null )14 initParam(params, 'start', start);15 if ( end != null )16 initParam(params, 'end', end);17 if ( includeDeleted != null )18 initParam(params, 'deleted', ( includeDeleted ? 1 : 0 ));19 gui.request(params, callback, 'array');20 },21 list: function (filter, callback) {22 var params = {23 'api' : 'transaction',24 'do' : 'list'25 };26 if ( filter != null ) {27 initParam(params, 'user', filter.user);28 initParam(params, 'start', filter.start);29 initParam(params, 'end', filter.end);30 initParam(params, 'showdeleted', filter.showdeleted);31 initParam(params, 'ordermode', filter.mode);32 initParam(params, 'orderby', filter.id);33 }34 gui.request(params, callback, 'array');35 },36 details: function (id, callback) {37 gui.request({38 'api' : 'transaction',39 'do' : 'details',40 'id' : id41 }, callback, 'object');42 },43 add: function (clockingIds, commit, callback) {44 var params = {45 'api' : 'transaction',46 'do' : 'add'47 };48 initParam(params, 'clockings', clockingIds);49 initParam(params, 'commit', commit);50 gui.request(params, callback, ( commit ? 'array' : 'object' ));51 },52 create: function (transaction, bookings, clockings, callback) {53 var clockingIds = [];54 for (var i = 0; i < clockings.length; i++)55 clockingIds.push( clockings[i] && (typeof(clockings[i]) === 'object') ? clockings[i].Id : clockings[i] );56 var params = {57 'api' : 'transaction',58 'do' : 'create'59 };60 initParam(params, 'transaction', {61 'UserId' : transaction.UserId,62 'Start' : transaction.Start,63 'End' : transaction.End,64 'Comment': transaction.Comment65 });66 initParam(params, 'bookings', bookings);67 initParam(params, 'clockings', clockingIds);68 gui.request(params, callback);69 },70 remove: function (id, callback) {71 gui.request({72 'api' : 'transaction',73 'do' : 'remove',74 'id' : id75 }, callback, 'boolean');76 },77 restore: function (id, callback) {78 gui.request({79 'api' : 'transaction',80 'do' : 'restore',81 'id' : id82 }, callback, 'boolean');83 },84 listBookings: function (filter, callback) {85 var params = {86 'api' : 'transaction',87 'do' : 'list_bookings'88 };89 if ( filter != null ) {90 initParam(params, 'user', filter.user);91 initParam(params, 'start', filter.start);92 initParam(params, 'end', filter.end);93 initParam(params, 'types', filter.types);94 initParam(params, 'showdeleted', filter.showdeleted);95 initParam(params, 'ordermode', filter.mode);96 initParam(params, 'orderby', filter.id);97 }98 gui.request(params, callback, 'array');99 }100 };...
Using AI Code Generation
1wpt.initParam("runs", 3);2wpt.initParam("location", "Dulles_IE10");3wpt.initParam("k", "A.1234567890abcdef1234567890abcdef");4wpt.initParam("f", "json");5wpt.initParam("video", 1);6wpt.initParam("timeline", 1);7wpt.initParam("pollResults", 10);8wpt.initParam("type", "repeatView");9wpt.initParam("mobile", 1);10wpt.initParam("mobileDevice", "Motorola Droid 3");11wpt.initParam("mobileCarrier", "Verizon Wireless");12wpt.initParam("mobileLocation", "Dulles_MotoDroid3");13wpt.initParam("mobileEmulation", 1);14wpt.initParam("mobileEmulationUserAgent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g");15wpt.initParam("mobileEmulationWidth", 320);16wpt.initParam("mobileEmulationHeight", 480);17wpt.initParam("mobileEmulationPixelRatio", 2);18wpt.initParam("mobileEmulationUserAgent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g");19wpt.initParam("mobileEmulationWidth", 320);20wpt.initParam("mobileEmulationHeight", 480);21wpt.initParam("mobileEmulationPixelRatio", 2);22wpt.initParam("connectivity", "Cable");23wpt.initParam("bwIn", 1000);24wpt.initParam("bwOut", 1000);25wpt.initParam("latency", 50);26wpt.initParam("plr", 0);
Using AI Code Generation
1var wpt = require('wpt');2var WPT = new wpt('API_KEY');3WPT.initParam('runs', '3');4var wpt = require('wpt');5var WPT = new wpt('API_KEY');6WPT.initParam('runs', '3');7WPT.initParam('location', 'Dulles:Chrome');8WPT.runTest(function(err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15### wpt(apiKey, options)16### wpt.initParam(key, value)17### wpt.runTest(callback
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!!