How to use formatOptions method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

format-test.js

Source: format-test.js Github

copy
1var assert = require('assert');
2
3var vows = require('vows');
4
5var formatFrom = require('../../lib/options/format').formatFrom;
6
7vows.describe(formatFrom)
8  .addBatch({
9    'undefined': {
10      'topic': function () {
11        return formatFrom(undefined);
12      },
13      'is false': function (formatOptions) {
14        assert.deepEqual(formatOptions, false);
15      }
16    },
17    'false': {
18      'topic': function () {
19        return formatFrom(false);
20      },
21      'is false': function (formatOptions) {
22        assert.deepEqual(formatOptions, false);
23      }
24    },
25    'true': {
26      'topic': function () {
27        return formatFrom(true);
28      },
29      'is default': function (formatOptions) {
30        assert.deepEqual(formatOptions, {
31          breaks: {
32            afterAtRule: false,
33            afterBlockBegins: false,
34            afterBlockEnds: false,
35            afterComment: false,
36            afterProperty: false,
37            afterRuleBegins: false,
38            afterRuleEnds: false,
39            beforeBlockEnds: false,
40            betweenSelectors: false
41          },
42          indentBy: 0,
43          indentWith: ' ',
44          spaces: {
45            aroundSelectorRelation: false,
46            beforeBlockBegins: false,
47            beforeValue: false
48          },
49          wrapAt: false,
50          semicolonAfterLastProperty: false
51        });
52      }
53    },
54    'hash': {
55      'topic': function () {
56        return formatFrom({ breaks: { afterProperty: true }, indentBy: 1 });
57      },
58      'is merged with default': function (formatOptions) {
59        assert.deepEqual(formatOptions, {
60          breaks: {
61            afterAtRule: false,
62            afterBlockBegins: false,
63            afterBlockEnds: false,
64            afterComment: false,
65            afterProperty: true,
66            afterRuleBegins: false,
67            afterRuleEnds: false,
68            beforeBlockEnds: false,
69            betweenSelectors: false
70          },
71          indentBy: 1,
72          indentWith: ' ',
73          spaces: {
74            aroundSelectorRelation: false,
75            beforeBlockBegins: false,
76            beforeValue: false
77          },
78          wrapAt: false,
79          semicolonAfterLastProperty: false
80        });
81      }
82    },
83    'hash with indentBy as string': {
84      'topic': function () {
85        return formatFrom({ indentBy: '2' });
86      },
87      'is merged with default': function (formatOptions) {
88        assert.deepEqual(formatOptions, {
89          breaks: {
90            afterAtRule: false,
91            afterBlockBegins: false,
92            afterBlockEnds: false,
93            afterComment: false,
94            afterProperty: false,
95            afterRuleBegins: false,
96            afterRuleEnds: false,
97            beforeBlockEnds: false,
98            betweenSelectors: false
99          },
100          indentBy: 2,
101          indentWith: ' ',
102          spaces: {
103            aroundSelectorRelation: false,
104            beforeBlockBegins: false,
105            beforeValue: false
106          },
107          wrapAt: false,
108          semicolonAfterLastProperty: false
109        });
110      }
111    },
112    'hash with explicit indentWith': {
113      'topic': function () {
114        return formatFrom({ indentWith: '\t' });
115      },
116      'is merged with default': function (formatOptions) {
117        assert.deepEqual(formatOptions, {
118          breaks: {
119            afterAtRule: false,
120            afterBlockBegins: false,
121            afterBlockEnds: false,
122            afterComment: false,
123            afterProperty: false,
124            afterRuleBegins: false,
125            afterRuleEnds: false,
126            beforeBlockEnds: false,
127            betweenSelectors: false
128          },
129          indentBy: 0,
130          indentWith: '\t',
131          spaces: {
132            aroundSelectorRelation: false,
133            beforeBlockBegins: false,
134            beforeValue: false
135          },
136          wrapAt: false,
137          semicolonAfterLastProperty: false
138        });
139      }
140    },
141    'hash with implicit indentWith': {
142      'topic': function () {
143        return formatFrom({ indentWith: 'tab' });
144      },
145      'is merged with default': function (formatOptions) {
146        assert.deepEqual(formatOptions, {
147          breaks: {
148            afterAtRule: false,
149            afterBlockBegins: false,
150            afterBlockEnds: false,
151            afterComment: false,
152            afterProperty: false,
153            afterRuleBegins: false,
154            afterRuleEnds: false,
155            beforeBlockEnds: false,
156            betweenSelectors: false
157          },
158          indentBy: 0,
159          indentWith: '\t',
160          spaces: {
161            aroundSelectorRelation: false,
162            beforeBlockBegins: false,
163            beforeValue: false
164          },
165          wrapAt: false,
166          semicolonAfterLastProperty: false
167        });
168      }
169    },
170    'string': {
171      'topic': function () {
172        return formatFrom('breaks:afterProperty=on;indentBy:3;wrapAt:25');
173      },
174      'is merged with default': function (formatOptions) {
175        assert.deepEqual(formatOptions, {
176          breaks: {
177            afterAtRule: false,
178            afterBlockBegins: false,
179            afterBlockEnds: false,
180            afterComment: false,
181            afterProperty: true,
182            afterRuleBegins: false,
183            afterRuleEnds: false,
184            beforeBlockEnds: false,
185            betweenSelectors: false
186          },
187          indentBy: 3,
188          indentWith: ' ',
189          spaces: {
190            aroundSelectorRelation: false,
191            beforeBlockBegins: false,
192            beforeValue: false
193          },
194          wrapAt: 25,
195          semicolonAfterLastProperty: false
196        });
197      }
198    },
199    'string with indentWith': {
200      'topic': function () {
201        return formatFrom('indentWith:tab');
202      },
203      'is merged with default': function (formatOptions) {
204        assert.deepEqual(formatOptions, {
205          breaks: {
206            afterAtRule: false,
207            afterBlockBegins: false,
208            afterBlockEnds: false,
209            afterComment: false,
210            afterProperty: false,
211            afterRuleBegins: false,
212            afterRuleEnds: false,
213            beforeBlockEnds: false,
214            betweenSelectors: false
215          },
216          indentBy: 0,
217          indentWith: '\t',
218          spaces: {
219            aroundSelectorRelation: false,
220            beforeBlockBegins: false,
221            beforeValue: false
222          },
223          wrapAt: false,
224          semicolonAfterLastProperty: false
225        });
226      }
227    },
228    'beautify keyword': {
229      'topic': function () {
230        return formatFrom('beautify');
231      },
232      'resolves correctly': function (formatOptions) {
233        assert.deepEqual(formatOptions, {
234          breaks: {
235            afterAtRule: true,
236            afterBlockBegins: true,
237            afterBlockEnds: true,
238            afterComment: true,
239            afterProperty: true,
240            afterRuleBegins: true,
241            afterRuleEnds: true,
242            beforeBlockEnds: true,
243            betweenSelectors: true
244          },
245          indentBy: 2,
246          indentWith: ' ',
247          spaces: {
248            aroundSelectorRelation: true,
249            beforeBlockBegins: true,
250            beforeValue: true
251          },
252          wrapAt: false,
253          semicolonAfterLastProperty: false
254        });
255      }
256    },
257    'keep-breaks keyword': {
258      'topic': function () {
259        return formatFrom('keep-breaks');
260      },
261      'resolves correctly': function (formatOptions) {
262        assert.deepEqual(formatOptions, {
263          breaks: {
264            afterAtRule: true,
265            afterBlockBegins: true,
266            afterBlockEnds: true,
267            afterComment: true,
268            afterProperty: false,
269            afterRuleBegins: false,
270            afterRuleEnds: true,
271            beforeBlockEnds: true,
272            betweenSelectors: false
273          },
274          indentBy: 0,
275          indentWith: ' ',
276          spaces: {
277            aroundSelectorRelation: false,
278            beforeBlockBegins: false,
279            beforeValue: false
280          },
281          wrapAt: false,
282          semicolonAfterLastProperty: false
283        });
284      }
285    }
286  })
287  .export(module);
288
Full Screen

jquery.fmatter.js

Source: jquery.fmatter.js Github

copy
1/*
2**
3 * formatter for values but most of the values if for jqGrid
4 * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
5 * we are trying to keep it as light as possible
6 * Joshua Burnett [email protected]	
7 * http://www.greenbill.com
8 *
9 * Changes from Tony Tomov [email protected]
10 * Dual licensed under the MIT and GPL licenses:
11 * http://www.opensource.org/licenses/mit-license.php
12 * http://www.gnu.org/licenses/gpl-2.0.html
13 * 
14**/
15/*jshint eqeqeq:false */
16/*global jQuery, define */
17
18(function( factory ) {
19	"use strict";
20	if ( typeof define === "function" && define.amd ) {
21		// AMD. Register as an anonymous module.
22		define([
23			"jquery",
24			"./grid.base"
25		], factory );
26	} else {
27		// Browser globals
28		factory( jQuery );
29	}
30}(function( $ ) {
31"use strict";
32//module begin
33	$.fmatter = {};
34	//opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
35	//example {id:1234,}
36	$.extend($.fmatter,{
37		isBoolean : function(o) {
38			return typeof o === 'boolean';
39		},
40		isObject : function(o) {
41			return (o && (typeof o === 'object' || $.isFunction(o))) || false;
42		},
43		isString : function(o) {
44			return typeof o === 'string';
45		},
46		isNumber : function(o) {
47			return typeof o === 'number' && isFinite(o);
48		},
49		isValue : function (o) {
50			return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
51		},
52		isEmpty : function(o) {
53			if(!this.isString(o) && this.isValue(o)) {
54				return false;
55			}
56			if (!this.isValue(o)){
57				return true;
58			}
59			o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
60			return o==="";	
61		}
62	});
63	$.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
64		// build main options before element iteration
65		var v=cellval;
66		opts = $.extend({}, $.jgrid.getRegional(this, 'formatter') , opts);
67
68		try {
69			v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
70		} catch(fe){}
71		return v;
72	};
73	$.fmatter.util = {
74		// Taken from YAHOO utils
75		NumberFormat : function(nData,opts) {
76			if(!$.fmatter.isNumber(nData)) {
77				nData *= 1;
78			}
79			if($.fmatter.isNumber(nData)) {
80				var bNegative = (nData < 0);
81				var sOutput = String(nData);
82				var sDecimalSeparator = opts.decimalSeparator || ".";
83				var nDotIndex;
84				if($.fmatter.isNumber(opts.decimalPlaces)) {
85					// Round to the correct decimal place
86					var nDecimalPlaces = opts.decimalPlaces;
87					var nDecimal = Math.pow(10, nDecimalPlaces);
88					sOutput = String(Math.round(nData*nDecimal)/nDecimal);
89					nDotIndex = sOutput.lastIndexOf(".");
90					if(nDecimalPlaces > 0) {
91					// Add the decimal separator
92						if(nDotIndex < 0) {
93							sOutput += sDecimalSeparator;
94							nDotIndex = sOutput.length-1;
95						}
96						// Replace the "."
97						else if(sDecimalSeparator !== "."){
98							sOutput = sOutput.replace(".",sDecimalSeparator);
99						}
100					// Add missing zeros
101						while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
102							sOutput += "0";
103						}
104					}
105				}
106				if(opts.thousandsSeparator) {
107					var sThousandsSeparator = opts.thousandsSeparator;
108					nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
109					nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
110					var sNewOutput = sOutput.substring(nDotIndex);
111					var nCount = -1, i;
112					for (i=nDotIndex; i>0; i--) {
113						nCount++;
114						if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
115							sNewOutput = sThousandsSeparator + sNewOutput;
116						}
117						sNewOutput = sOutput.charAt(i-1) + sNewOutput;
118					}
119					sOutput = sNewOutput;
120				}
121				// Prepend prefix
122				sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
123				// Append suffix
124				sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
125				return sOutput;
126				
127			}
128			return nData;
129		}
130	};
131	$.fn.fmatter.defaultFormat = function(cellval, opts) {
132		return ($.fmatter.isValue(cellval) && cellval!=="" ) ?  cellval : opts.defaultValue || "&#160;";
133	};
134	$.fn.fmatter.email = function(cellval, opts) {
135		if(!$.fmatter.isEmpty(cellval)) {
136			return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
137		}
138		return $.fn.fmatter.defaultFormat(cellval,opts );
139	};
140	$.fn.fmatter.checkbox =function(cval, opts) {
141		var op = $.extend({},opts.checkbox), ds;
142		if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
143			op = $.extend({},op,opts.colModel.formatoptions);
144		}
145		if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
146		if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
147		cval=String(cval);
148		cval=(cval+"").toLowerCase();
149		var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : "";
150		return "<input type=\"checkbox\" " + bchk  + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
151	};
152	$.fn.fmatter.link = function(cellval, opts) {
153		var op = {target:opts.target};
154		var target = "";
155		if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
156			op = $.extend({},op,opts.colModel.formatoptions);
157		}
158		if(op.target) {target = 'target=' + op.target;}
159		if(!$.fmatter.isEmpty(cellval)) {
160			return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
161		}
162		return $.fn.fmatter.defaultFormat(cellval,opts);
163	};
164	$.fn.fmatter.showlink = function(cellval, opts) {
165		var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
166		target = "", idUrl;
167		if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
168			op = $.extend({},op,opts.colModel.formatoptions);
169		}
170		if(op.target) {target = 'target=' + op.target;}
171		idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
172		if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) {	//add this one even if its blank string
173			return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
174		}
175		return $.fn.fmatter.defaultFormat(cellval,opts);
176	};
177	$.fn.fmatter.integer = function(cellval, opts) {
178		var op = $.extend({},opts.integer);
179		if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
180			op = $.extend({},op,opts.colModel.formatoptions);
181		}
182		if($.fmatter.isEmpty(cellval)) {
183			return op.defaultValue;
184		}
185		return $.fmatter.util.NumberFormat(cellval,op);
186	};
187	$.fn.fmatter.number = function (cellval, opts) {
188		var op = $.extend({},opts.number);
189		if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
190			op = $.extend({},op,opts.colModel.formatoptions);
191		}
192		if($.fmatter.isEmpty(cellval)) {
193			return op.defaultValue;
194		}
195		return $.fmatter.util.NumberFormat(cellval,op);
196	};
197	$.fn.fmatter.currency = function (cellval, opts) {
198		var op = $.extend({},opts.currency);
199		if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
200			op = $.extend({},op,opts.colModel.formatoptions);
201		}
202		if($.fmatter.isEmpty(cellval)) {
203			return op.defaultValue;
204		}
205		return $.fmatter.util.NumberFormat(cellval,op);
206	};
207	$.fn.fmatter.date = function (cellval, opts, rwd, act) {
208		var op = $.extend({},opts.date);
209		if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
210			op = $.extend({},op,opts.colModel.formatoptions);
211		}
212		if(!op.reformatAfterEdit && act === 'edit'){
213			return $.fn.fmatter.defaultFormat(cellval, opts);
214		}
215		if(!$.fmatter.isEmpty(cellval)) {
216			return $.jgrid.parseDate.call(this, op.srcformat,cellval,op.newformat,op);
217		}
218		return $.fn.fmatter.defaultFormat(cellval, opts);
219	};
220	$.fn.fmatter.select = function (cellval,opts) {
221		// jqGrid specific
222		cellval = String(cellval);
223		var oSelect = false, ret=[], sep, delim;
224		if(opts.colModel.formatoptions !== undefined){
225			oSelect= opts.colModel.formatoptions.value;
226			sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator;
227			delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter;
228		} else if(opts.colModel.editoptions !== undefined){
229			oSelect= opts.colModel.editoptions.value;
230			sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator;
231			delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter;
232		}
233		if (oSelect) {
234			var	msl =  (opts.colModel.editoptions != null && opts.colModel.editoptions.multiple === true) === true ? true : false,
235			scell = [], sv;
236			if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
237			if ($.fmatter.isString(oSelect)) {
238				// mybe here we can use some caching with care ????
239				var so = oSelect.split(delim), j=0, i;
240				for(i=0; i<so.length;i++){
241					sv = so[i].split(sep);
242					if(sv.length > 2 ) {
243						sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
244					}
245					if(msl) {
246						if($.inArray(sv[0],scell)>-1) {
247							ret[j] = sv[1];
248							j++;
249						}
250					} else if($.trim(sv[0]) === $.trim(cellval)) {
251						ret[0] = sv[1];
252						break;
253					}
254				}
255			} else if($.fmatter.isObject(oSelect)) {
256				// this is quicker
257				if(msl) {
258					ret = $.map(scell, function(n){
259						return oSelect[n];
260					});
261				} else {
262					ret[0] = oSelect[cellval] || "";
263				}
264			}
265		}
266		cellval = ret.join(", ");
267		return  cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
268	};
269	$.fn.fmatter.rowactions = function(act) {
270		var $tr = $(this).closest("tr.jqgrow"),
271			rid = $tr.attr("id"),
272			$id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'),
273			$grid = $("#"+$id),
274			$t = $grid[0],
275			p = $t.p,
276			cm = p.colModel[$.jgrid.getCellIndex(this)],
277			$actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(),
278			op = {
279				extraparam: {}
280			},
281			saverow = function(rowid, res) {
282				if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); }
283				$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
284				$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
285			},
286			restorerow = function(rowid) {
287				if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); }
288				$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
289				$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
290			};
291
292		if (cm.formatoptions !== undefined) {
293			op = $.extend(op,cm.formatoptions);
294		}
295		if (p.editOptions !== undefined) {
296			op.editOptions = p.editOptions;
297		}
298		if (p.delOptions !== undefined) {
299			op.delOptions = p.delOptions;
300		}
301		if ($tr.hasClass("jqgrid-new-row")){
302			op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
303		}
304		var actop = {
305			keys: op.keys,
306			oneditfunc: op.onEdit,
307			successfunc: op.onSuccess,
308			url: op.url,
309			extraparam: op.extraparam,
310			aftersavefunc: saverow,
311			errorfunc: op.onError,
312			afterrestorefunc: restorerow,
313			restoreAfterError: op.restoreAfterError,
314			mtype: op.mtype
315		};
316		switch(act)
317		{
318			case 'edit':
319				$grid.jqGrid('editRow', rid, actop);
320				$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
321				$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
322				$grid.triggerHandler("jqGridAfterGridComplete");
323				break;
324			case 'save':
325				if ($grid.jqGrid('saveRow', rid, actop)) {
326					$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
327					$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
328					$grid.triggerHandler("jqGridAfterGridComplete");
329				}
330				break;
331			case 'cancel' :
332				$grid.jqGrid('restoreRow', rid, restorerow);
333				$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
334				$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
335				$grid.triggerHandler("jqGridAfterGridComplete");
336				break;
337			case 'del':
338				$grid.jqGrid('delGridRow', rid, op.delOptions);
339				break;
340			case 'formedit':
341				$grid.jqGrid('setSelection', rid);
342				$grid.jqGrid('editGridRow', rid, op.editOptions);
343				break;
344		}
345	};
346	$.fn.fmatter.actions = function(cellval,opts) {
347		var op={keys:false, editbutton:true, delbutton:true, editformbutton: false},
348			rowid=opts.rowId, str="",ocl,
349			nav = $.jgrid.getRegional(this, 'nav'),
350			classes = $.jgrid.styleUI[(opts.styleUI || 'jQueryUI')].fmatter,
351			common = $.jgrid.styleUI[(opts.styleUI || 'jQueryUI')].common;
352		if(opts.colModel.formatoptions !== undefined) {
353			op = $.extend(op,opts.colModel.formatoptions);
354		}
355		if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";}
356		var hover = "onmouseover=jQuery(this).addClass('" + common.hover +"'); onmouseout=jQuery(this).removeClass('" + common.hover +"');  ";
357		if(op.editformbutton){ 
358			ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'formedit'); " + hover;
359			str += "<div title='"+nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_edit +"'></span></div>";
360		} else if(op.editbutton){
361			ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'edit'); " + hover;
362			str += "<div title='"+nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_edit +"'></span></div>";
363		}
364		if(op.delbutton) {
365			ocl = "id='jDeleteButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'del'); " + hover;
366			str += "<div title='"+nav.deltitle+"' style='float:left;' class='ui-pg-div ui-inline-del' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_del +"'></span></div>";
367		}
368		ocl = "id='jSaveButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'save'); " + hover;
369		str += "<div title='"+nav.savetitle+"' style='float:left;display:none' class='ui-pg-div ui-inline-save' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_save +"'></span></div>";
370		ocl = "id='jCancelButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'cancel'); " + hover;
371		str += "<div title='"+nav.canceltitle+"' style='float:left;display:none;' class='ui-pg-div ui-inline-cancel' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_cancel +"'></span></div>";
372		return "<div style='margin-left:8px;'>" + str + "</div>";
373	};
374	$.unformat = function (cellval,options,pos,cnt) {
375		// specific for jqGrid only
376		var ret, formatType = options.colModel.formatter,
377		op =options.colModel.formatoptions || {}, sep,
378		re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
379		unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
380		if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) {
381			ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
382		} else if(formatType !== undefined && $.fmatter.isString(formatType) ) {
383			var opts = $.jgrid.getRegional(this, 'formatter') || {}, stripTag;
384			switch(formatType) {
385				case 'integer' :
386					op = $.extend({},opts.integer,op);
387					sep = op.thousandsSeparator.replace(re,"\\$1");
388					stripTag = new RegExp(sep, "g");
389					ret = $(cellval).text().replace(stripTag,'');
390					break;
391				case 'number' :
392					op = $.extend({},opts.number,op);
393					sep = op.thousandsSeparator.replace(re,"\\$1");
394					stripTag = new RegExp(sep, "g");
395					ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
396					break;
397				case 'currency':
398					op = $.extend({},opts.currency,op);
399					sep = op.thousandsSeparator.replace(re,"\\$1");
400					stripTag = new RegExp(sep, "g");
401					ret = $(cellval).text();
402					if (op.prefix && op.prefix.length) {
403						ret = ret.substr(op.prefix.length);
404					}
405					if (op.suffix && op.suffix.length) {
406						ret = ret.substr(0, ret.length - op.suffix.length);
407					}
408					ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.');
409					break;
410				case 'checkbox':
411					var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
412					ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
413					break;
414				case 'select' :
415					ret = $.unformat.select(cellval,options,pos,cnt);
416					break;
417				case 'actions':
418					return "";
419				default:
420					ret= $(cellval).text();
421			}
422		}
423		return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
424	};
425	$.unformat.select = function (cellval,options,pos,cnt) {
426		// Spacial case when we have local data and perform a sort
427		// cnt is set to true only in sortDataArray
428		var ret = [];
429		var cell = $(cellval).text();
430		if(cnt===true) {return cell;}
431		var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions),
432		sep = op.separator === undefined ? ":" : op.separator,
433		delim = op.delimiter === undefined ? ";" : op.delimiter;
434		
435		if(op.value){
436			var oSelect = op.value,
437			msl =  op.multiple === true ? true : false,
438			scell = [], sv;
439			if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
440			if ($.fmatter.isString(oSelect)) {
441				var so = oSelect.split(delim), j=0, i;
442				for(i=0; i<so.length;i++){
443					sv = so[i].split(sep);
444					if(sv.length > 2 ) {
445						sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
446					}					
447					if(msl) {
448						if($.inArray($.trim(sv[1]),scell)>-1) {
449							ret[j] = sv[0];
450							j++;
451						}
452					} else if($.trim(sv[1]) === $.trim(cell)) {
453						ret[0] = sv[0];
454						break;
455					}
456				}
457			} else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
458				if(!msl) {scell[0] =  cell;}
459				ret = $.map(scell, function(n){
460					var rv;
461					$.each(oSelect, function(i,val){
462						if (val === n) {
463							rv = i;
464							return false;
465						}
466					});
467					if( rv !== undefined ) {return rv;}
468				});
469			}
470			return ret.join(", ");
471		}
472		return cell || "";
473	};
474	$.unformat.date = function (cellval, opts) {
475		var op = $.jgrid.getRegional(this, 'formatter.date') || {};
476		if(opts.formatoptions !== undefined) {
477			op = $.extend({},op,opts.formatoptions);
478		}		
479		if(!$.fmatter.isEmpty(cellval)) {
480			return $.jgrid.parseDate.call(this, op.newformat,cellval,op.srcformat,op);
481		}
482		return $.fn.fmatter.defaultFormat(cellval, opts);
483	};
484//module end
485}));
486
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)