Best JavaScript code snippet using backstopjs
jeasyui.extensions.js
Source:jeasyui.extensions.js
1/**2* jQuery EasyUI 1.3.33* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.4*5* Licensed under the GPL or commercial licenses6* To use it on other terms please contact us: jeasyui@gmail.com7* http://www.gnu.org/licenses/gpl.txt8* http://www.jeasyui.com/license_commercial.php9*10* jQuery EasyUI Generic Plugins Basic Library 1.0 beta11* jQuery EasyUI éç¨æ件åºç¡åº12* jeasyui.extensions.js13* äºæ¬¡å¼å é建ä¼14* æè¿æ´æ°ï¼2013-07-2515*16* ä¾èµé¡¹ï¼jquery.jdirk.js v1.0 beta late17*18* Copyright (c) 2013 ChenJianwei personal All rights reserved.19* http://www.chenjianwei.org20*/21(function ($, undefined) {22 var coreEasyui = {};23 var coreJquery = function () { return $.apply(this, arguments); };24 coreJquery.fn = coreJquery.prototype = {};25 coreJquery.easyui = coreEasyui;26 coreEasyui.getTopEasyuiMessager = function () {27 if ($.util.isTopMost) { return $.messager; }28 return $.util.$ && $.util.$.messager ? $.util.$.messager : $.messager;29 };30 coreEasyui.messager = coreEasyui.getTopEasyuiMessager();31 coreEasyui.getTopEasyuiTooltip = function () {32 if ($.util.isTopMost) { return $.fn.tooltip; }33 return $.util.$ && $.util.$.fn && $.util.$.fn.tooltip ? $.util.$.fn.tooltip : $.fn.tooltip;34 };35 coreEasyui.tooltip = $.fn.tooltip;36 coreEasyui.tooltip.init = function (target, options) {37 var t = $.util.parseJquery(target);38 t.mouseover(function () {39 t.tooltip($.extend({ trackMouse: true }, options, { onHide: function () {40 if ($.isFunction(options.onHide)) { options.onHide.apply(this, arguments); }41 t.tooltip("destroy");42 }43 })).tooltip("show");44 });45 };46 var icons = { "error": "messager-error", "info": "messager-info", "question": "messager-question", "warning": "messager-warning" },47 _show = $.messager.show, _alert = $.messager.alert, _confirm = $.messager.confirm, _prompt = $.messager.prompt,48 defaults = { title: "æä½æé", confirm: "æ¨ç¡®è®¤è¦è¿è¡è¯¥æä½ï¼", prompt: "请è¾å
¥ç¸åºå
容ï¼", icon: "info", loading: "æ£å¨åªå为æ¨å è½½ï¼è¯·ç¨å¾
..." };49 // éå $.messager.show æ¹æ³ï¼ä½¿å
¶æ¯æå¾æ 以åé»è®¤çå个å符串åæ°çéè½½ï¼è¯¥æ¹æ³å®ä¹å¦ä¸åæ°ï¼50 // options: 表示éè¦å¼¹åºæ¶æ¯çå
容ãå¾æ åæ¹å¼çä¿¡æ¯ï¼è¯¥åæ°ç±»åå¯ä»¥ä¸ºå¦ä¸ï¼51 // JSON Object: å
¼å®¹ $.messager.show å®æ¹é»è®¤ API çææå±æ§ï¼å¹¶å¨æ¤åºç¡ä¸å¢å å¦ä¸åæ°ï¼52 // icon: 表示弹åºæ¶æ¯çå¾æ ï¼ä¸ºä¸ä¸ª String ç±»åå¼ï¼è¯¥å¼å¯éçå
å®¹ä¸ $.messager.alert æ¹æ³ç第ä¸ä¸ªåæ°å¯éå
容ç¸åï¼53 // å
æ¬ï¼"error", "info", "question", "warning"ï¼54 // å
·ä½å
容åè§ $.messager.alert 该æ¹æ³çå®æ¹é»è®¤ API ä¸ç¬¬ä¸ä¸ªåæ°å¯éå
容ã55 // position: 表示弹åºæ¶æ¯çä½ç½®ï¼ä¸ºä¸ä¸ª String ç±»åå¼ï¼è¯¥å¼å¯éçå
容å®ä¹å¦ä¸ï¼56 // topLeft: å±å¹å·¦ä¸è§, topCenter: å±å¹ä¸æ¹ä¸é´ï¼topRight: å±å¹å³ä¸è§57 // centerLeft: å±å¹å·¦ä¾§ä¸é´ï¼center: å±å¹æ£ä¸é´ï¼centerRight: å±å¹å³ä¾§ä¸é´58 // bottomLeft: å±å¹å·¦ä¸è§ï¼bottomCenter: å±å¹ä¸æ¹ä¸é´ï¼bottomRight: å±å¹å³ä¸è§59 // String: 以 icon: "info"ãtitle: "æä½æé"ãmsg: options 为é»è®¤çæ¹å¼è°ç¨ä¸ä¸éè½½ã60 $.messager.show = function (options) {61 var isString = $.util.isString(options) || $.util.isBoolean(options) || $.isNumeric(options);62 if (isString) {63 arguments.length == 1 ? $.messager.show({ msg: String(options) }) : $.messager.show({ title: options, msg: arguments[1], icon: arguments[2], position: arguments[3] });64 return;65 }66 var defaults = $.extend({}, $.messager.defaults, { title: "æä½æé", timeout: 3000, showType: "slide" });67 var position = {68 topLeft: { right: "", left: 0, top: document.body.scrollTop + document.documentElement.scrollTop, bottom: "" },69 topCenter: { right: "", top: document.body.scrollTop + document.documentElement.scrollTop, bottom: "" },70 topRight: { left: "", right: 0, top: document.body.scrollTop + document.documentElement.scrollTop, bottom: "" },71 centerLeft: { left: 0, right: "", bottom: "" },72 center: { right: "", bottom: "" },73 centerRight: { left: "", right: 0, bottom: "" },74 bottomLeft: { left: 0, right: "", top: "", bottom: -document.body.scrollTop - document.documentElement.scrollTop },75 bottomCenter: { right: "", top: "", bottom: -document.body.scrollTop - document.documentElement.scrollTop },76 bottomRight: null77 };78 var opts = $.extend({}, defaults, options);79 opts.style = position[options.position] ? position[options.position] : position.topCenter;80 var iconCls = icons[opts.icon] ? icons[opts.icon] : icons.info;81 opts.msg = "<div class='messager-icon " + iconCls + "'></div>" + "<div>" + opts.msg + "</div>";82 return _show(opts);83 };84 $.union($.messager.show, _show);85 $.messager.alert = function (title, msg, icon, fn) {86 if (arguments.length == 1) { return _alert(defaults.title, arguments[0], defaults.icon); }87 if (arguments.length == 2) {88 if ($.isFunction(arguments[1])) { return _alert(defaults.title, arguments[0], defaults.icon, arguments[1]); }89 if (arguments[1] in icons) { return _alert(defaults.title, arguments[0], arguments[1]); }90 return _alert.apply(this, arguments);91 }92 if (arguments.length == 3) {93 if ($.isFunction(arguments[2])) {94 return (arguments[1] in icons) ? _alert(defaults.title, arguments[0], arguments[1], arguments[2])95 : _alert(arguments[0], arguments[1], defaults.icon, arguments[2]);96 }97 return _alert.apply(this, arguments);98 }99 return _alert.apply(this, arguments);100 };101 $.messager.confirm = function (title, msg, fn) {102 if (arguments.length == 1) {103 return $.isFunction(arguments[0]) ? _confirm(defaults.title, defaults.confirm, arguments[0]) : _confirm(defaults.title, arguments[0]);104 }105 if (arguments.length == 2) {106 return $.isFunction(arguments[1]) ? _confirm(defaults.title, arguments[0], arguments[1]) : _confirm(arguments[0], arguments[1]);107 }108 return _confirm.apply(this, arguments);109 };110 $.messager.prompt = function (title, msg, fn) {111 if (arguments.length == 1) {112 return $.isFunction(arguments[0]) ? _prompt(defaults.title, defaults.prompt, arguments[0]) : _prompt(defaults.title, defaults.prompt);113 }114 if (arguments.length == 2) {115 return $.isFunction(arguments[0]) ? _prompt(defaults.title, arguments[0], arguments[1]) : _prompt(arguments[0], arguments[1]);116 }117 return _prompt.apply(this, arguments);118 };119 // å¤æ³¨ï¼ $.messager 表示å½å页é¢ç easyui-messager 对象ï¼120 // $.easyui.messager 表示å¯æ§é¡¶çº§é¡µé¢ç easyui-messager 对象ï¼121 // æ´æ¹ jQuery EasyUI ä¸é¨åæ§ä»¶çå½é
åè¯è¨æ¾ç¤ºã122 $.extend($.fn.panel.defaults, { loadingMessage: defaults.loading });123 $.extend($.fn.window.defaults, { loadingMessage: defaults.loading });124 $.extend($.fn.dialog.defaults, { loadingMessage: defaults.loading });125 // æ´æ¹ jeasyui-combo ç»ä»¶çé空éªè¯æéæ¶æ¯è¯è¨ã126 $.extend($.fn.combo.defaults, { missingMessage: $.fn.validatebox.defaults.missingMessage });127 // æ´æ¹ jQuery EasyUI é¨åç»ä»¶çéç¨é误æ示ã128 var onLoadError = function (XMLHttpRequest, textStatus, errorThrown) {129 $.messager.progress("close");130 if (coreEasyui.messager != $.messager) { coreEasyui.messager.progress("close"); }131 var msg = (XMLHttpRequest && !$.string.isNullOrWhiteSpace(XMLHttpRequest.responseText) ?132 "å¦æ该é®é¢éå¤åºç°ï¼è¯·èç³»æ¨çç³»ç»ç®¡çå并åé¦è¯¥æ
éã<br />" +133 "é误å·ï¼" + XMLHttpRequest.status + "(" + XMLHttpRequest.statusText + ")ï¼<hr />" + XMLHttpRequest.responseText :134 "ç³»ç»åºç°äºä¸ä¸ªæªææçé误ï¼å¦æ该é®é¢éå¤åºç°ï¼è¯·èç³»æ¨çç³»ç»ç®¡çå并åé¦è¯¥æ
éã");135 coreEasyui.messager.alert("é误æé", msg, "error");136 var win = $.util.$("div.panel.window.messager-window:last").children("div.messager-body.panel-body.window-body"),137 opts = win.window("options"), panel = win.window("panel"), width = panel.outerWidth(), height = panel.outerHeight();138 if (width > 800 || height > 800) { win.window("resize", { width: width > 800 ? 800 : width, height: height > 800 ? 800 : height }); }139 win.window("center");140 };141 $.fn.form.defaults.onLoadError = onLoadError;142 $.fn.combobox.defaults.onLoadError = onLoadError;143 $.fn.combotree.defaults.onLoadError = onLoadError;144 $.fn.combogrid.defaults.onLoadError = onLoadError;145 $.fn.datagrid.defaults.onLoadError = onLoadError;146 $.fn.propertygrid.defaults.onLoadError = onLoadError;147 $.fn.tree.defaults.onLoadError = onLoadError;148 $.fn.treegrid.defaults.onLoadError = onLoadError;149 // æ´æ¹ jQuery.ajax å½æ°çé¨åé»è®¤å±æ§ã150 $.ajaxSetup({151 dataFilter: function (data, type) {152 return $.util.isString(type) && type.toLowerCase(type) == "json" ? $.string.toJSONString(data) : data;153 },154 error: onLoadError155 });156 $.union(coreJquery);157 $.fn.union(coreJquery.fn);...
Loadable.js
Source:Loadable.js
1new hope.Operation.subclass({2 name : "Loader",3 prototype : {4 callbackName : "onLoaded",5 errbackName : "onLoadError"6 }7});8/** Loadable mixin. 9 Specify loadOptions for customization, or create an Operation called <mixeeType>Loader for full custom loader.10 TODO: different semantics for the constructor?11*/12new hope.Mixin({13 name : "Loadable",14 /** Don't overwrite properties already set on the mixee. */15 overwrite : hope.MERGE,16 prototype : {17 /** Loader for this instance, created automatically and stored in the cache. */18 'get:loader' : function() {19 if (!this._loader) {20 // create a new loader, setting this as the callbackTarget21 var options = this.loadOptions || {};22 options.callbackTarget = this;23 this._loader = new (this.constructor.loader)(options);24 }25 return this._loader;26 },27 /** Has this thing been loaded successfully? */28 'get:loaded' : function(){return this.loader.state == hope.LOADED},29 'set:loaded' : function(flag){return this.loader.state = (flag == true ? hope.LOADED : hope.UNLOADED)},30 31 /** Aliases for the load url. */32 'get:src' : function(){return this.loader.url},33 'set:src' : function(url){return this.loader.set("url", url)},34 /** Alias for the load output. */35 'get:data' : function(){return this.loader.output},36 'get:dataType' : function(){return this.loader.outputType},37 'set:dataType' : function(type){return this.loader.set("outputType", type)},38 39 /** Aliases for load/load error messages. */40 'get:loadMessage' : function(){return this.loader.message},41 'set:loadMessage' : function(msg){return this.loader.set("loadMessage", msg)},42 'get:loadErrorMessage' : function(){return this.loader.errorMessage},43 'set:loadErrorMessage' : function(url){this.loader.set("errorMessage", errorMessage)},44 45 /** Load command. Pass a url (string) or object of options to load. */46 load : function(options, onLoaded, onLoadError) {47 options = (typeof options == "string" ? {url:options} : options||{});48 if (onLoaded) options.onLoaded = onLoaded;49 if (onLoadError) options.onLoadError = onLoadError;50 this.loader.execute(options);51 return this;52 },53 // onLoaded and onLoadError handlers, called as: (event, [data|error], key, target)54 onLoaded : undefined,55 onLoadError : undefined56 },57 58 statics : {59 load : function(options, onLoaded, onLoadError) {60 // if options is an array of strings, make an OperationQueue and load them all one at a time61 if (hope.isListLike(options)) {62 var operations = options, i = -1, url;63 while (url = operations[++i]) {64 operations[i] = new (this.loader)({url:url});65 }66 var options = {operations:operations};67 if (onLoaded) options.onCompleted = onLoaded;68 if (onLoadError) options.onError = onLoadError;69 return (new hope.OperationQueue(options)).execute();70 } else {71 options = (typeof options == "string" ? {url:options} : options||{});72 if (onLoaded) options.onLoaded = onLoaded;73 if (onLoadError) options.onLoadError = onLoadError;74 return (new (this.loader)(options)).execute();75 }76 }77 },78 79 /** Create a custom loader for the Loadable thing. 80 If an operation named <classType>Loader is already defined, we'll use that.81 Otherwise we'll create one.82 */83 onMixin : function(it) {84 var loaderName = it.Class.name + "Loader", operation;85 try {86 operation = hope.getThing(loaderName); // will throw if not found87 } catch (e) {88 // create an operation if not already defined89 operation = new hope.Loader.subclass({ name : loaderName });90 }91 // assign to the element (and its prototype, if applicable)92 it.loader = operation;93 }...
zUtil.js
Source:zUtil.js
1var zzw = zzw || {};2/**3 * 4 */5$.fn.tree.defaults.loadFilter = function(data, parent) {6 var opt = $(this).data().tree.options;7 var idFiled, textFiled, parentField;8 if (opt.parentField) {9 idFiled = opt.idFiled || 'id';10 textFiled = opt.textFiled || 'text';11 parentField = opt.parentField;12 var i, l, treeData = [], tmpMap = [];13 for (i = 0, l = data.length; i < l; i++) {14 tmpMap[data[i][idFiled]] = data[i];15 }16 for (i = 0, l = data.length; i < l; i++) {17 if (tmpMap[data[i][parentField]] && data[i][idFiled] != data[i][parentField]) {18 if (!tmpMap[data[i][parentField]]['children'])19 tmpMap[data[i][parentField]]['children'] = [];20 data[i]['text'] = data[i][textFiled];21 tmpMap[data[i][parentField]]['children'].push(data[i]);22 } else {23 data[i]['text'] = data[i][textFiled];24 treeData.push(data[i]);25 }26 }27 return treeData;28 }29 return data;30};31/**32 * 33 * @requires jQuery,EasyUI34 * 35 * é²æ¢panel/window/dialogç»ä»¶è¶
åºæµè§å¨è¾¹ç36 * @param left37 * @param top38 */39zzw.onMove = {40 onMove : function(left, top) {41 var l = left;42 var t = top;43 if (l < 1) {44 l = 1;45 }46 if (t < 1) {47 t = 1;48 }49 var width = parseInt($(this).parent().css('width')) + 14;50 var height = parseInt($(this).parent().css('height')) + 14;51 var right = l + width;52 var buttom = t + height;53 var browserWidth = $(window).width();54 var browserHeight = $(window).height();55 if (right > browserWidth) {56 l = browserWidth - width;57 }58 if (buttom > browserHeight) {59 t = browserHeight - height;60 }61 $(this).parent().css({/* ä¿®æ£é¢æ¿ä½ç½® */62 left : l,63 top : t64 });65 }66};67$.extend($.fn.dialog.defaults, zzw.onMove);68$.extend($.fn.window.defaults, zzw.onMove);69$.extend($.fn.panel.defaults, zzw.onMove);70/**71 * éç¨å è¼é¯èª¤æ示72 */73zzw.onLoadError = {74 onLoadError : function(XMLHttpRequest) {75 $.messager.show({76 msg : XMLHttpRequest.statusText + ' ' + XMLHttpRequest.status + '[' + XMLHttpRequest.responseText + ']',77 title : 'é¯èª¤',78 timeout : 079 });80 }81};82$.extend($.fn.datagrid.defaults, zzw.onLoadError);83$.extend($.fn.treegrid.defaults, zzw.onLoadError);84$.extend($.fn.tree.defaults, zzw.onLoadError);85$.extend($.fn.combogrid.defaults, zzw.onLoadError);86$.extend($.fn.combobox.defaults, zzw.onLoadError);87$.extend($.fn.form.defaults, zzw.onLoadError);88$.extend($.fn.datagrid.defaults.editors, {89 combogrid : {90 init : function(container, options) {91 var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);92 input.combogrid(options);93 return input;94 },95 destroy : function(target) {96 $(target).combogrid('destroy');97 },98 getValue : function(target) {99 return $(target).combogrid('getValue');100 },101 setValue : function(target, value) {102 $(target).combogrid('setValue', value);103 },104 resize : function(target, width) {105 $(target).combogrid('resize', width);106 }107 }...
Using AI Code Generation
1module.exports = {2 {3 },4 {5 },6 {7 },8 {9 }10 "onLoadError": {},11 {12 }13 "paths": {14 },15 "engineOptions": {16 },17}18module.exports = async function (chromy, scenario) {19 const clearCookies = true;20 if (clearCookies) {21 await chromy.clearCookies();22 }23 {24 },25 {26 },27 ];
Using AI Code Generation
1module.exports = {2 {3 },4 {5 }6 {7 "onLoadError": {8 "options": {9 }10 }11 }12 "paths": {13 },14 "engineOptions": {15 },16}17module.exports = {18 onLoadError: function (page, scenario, vp, options, err) {19 console.log('onLoadError', err);20 }21};
Using AI Code Generation
1module.exports = async (page, scenario, vp) => {2 console.log('SCENARIO > ' + scenario.label);3 await require('./loadCookies')(page, scenario);4 page.on('error', msg => {5 console.log('page error > ' + msg);6 });7 page.on('pageerror', msg => {8 console.log('page error > ' + msg);9 });10 page.on('requestfailed', request => {11 console.log(request.failure().errorText);12 });13};
Using AI Code Generation
1module.exports = {2 {3 }4 "paths": {5 },6 "engineOptions": {7 },8}9module.exports = async function (chromy, scenario) {10 console.log('onBefore.js: Adding cookie.');11 await chromy.setCookie({ name: 'cookieName1', value: 'cookieValue1', domain: 'localhost' });12 await chromy.setCookie({ name: 'cookieName2', value: 'cookieValue2', domain: 'localhost' });13 await chromy.setCookie({ name: 'cookieName3', value: 'cookieValue3', domain: 'localhost' });14};15module.exports = async function (chromy, scenario) {16 console.log('onReady.js: Clicking cookie consent button.');
Using AI Code Generation
1module.exports = async (page, scenario, vp) => {2 console.log('SCENARIO > ' + scenario.label);3 await require('./loadCookies')(page, scenario);4 await page.waitFor(500);5};6{7 {8 },9 {10 }11}12{13 {14 },15 {16 }17}
Using AI Code Generation
1casper.on('load.failed', function (resourceError) {2 casper.test.fail(resourceError.errorString);3});4casper.on('resource.error', function (resourceError) {5 casper.test.fail(resourceError.errorString);6});7casper.on('resource.timeout', function (resourceError) {8 casper.test.fail(resourceError.errorString);9});10casper.on('url.changed', function (targetUrl) {11 casper.test.info('New URL: ' + targetUrl);12});13casper.on('page.error', function (msg, trace) {14 casper.test.fail('Error: ' + msg);15});16casper.on('remote.message', function (msg) {17 casper.test.info('remote message caught: ' + msg);18});19casper.on('page.initialized', function () {20 casper.test.info('page.initialized');21});22casper.on('page.resource.requested', function (requestData, networkRequest) {23 casper.test.info('page.resource.requested');24});25casper.on('page.resource.received', function (response) {26 casper.test.info('page.resource.received');27});28casper.on('page.resource.error', function (resourceError) {29 casper.test.fail('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');30});31casper.on('page.resource.timeout', function (requestData) {32 casper.test.fail('Resource request timed out: ' + JSON.stringify(requestData));33});
Using AI Code Generation
1module.exports = {2 "onLoadError": function(page, scenario, vp) {3 console.log(page, scenario, vp);4 }5};6module.exports = {7};8module.exports = {9};10module.exports = {11};12module.exports = {13};14module.exports = {15};16module.exports = {17};18module.exports = {19};20module.exports = {21};22module.exports = {23};24module.exports = {
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!!