Best JavaScript code snippet using wpt
FloatListTag.ts
Source:FloatListTag.ts
1namespace OS {2 export namespace GUI {3 export namespace tag {4 /**5 * A float list is a list of items in which each6 * item can be moved (drag and drop) freely7 *8 * @export9 * @class FloatListTag10 * @extends {ListViewTag}11 */12 export class FloatListTag extends ListViewTag {13 /**14 * Update the current tag, do nothing15 *16 * @protected17 * @param {*} [d]18 * @memberof FloatListTag19 */20 protected reload(d?: any): void {}21 /**22 * Variable that hold the onready callback of23 * the tag. This callback will be called after24 * the tag is mounted25 *26 * @private27 * @memberof FloatListTag28 */29 private _onready: (e: FloatListTag) => void;30 /**31 *Creates an instance of FloatListTag.32 * @memberof FloatListTag33 */34 constructor() {35 super();36 }37 /**38 * set the onready callback function to the tag.39 * This callback will be called after40 * the tag is mounted41 *42 * @memberof FloatListTag43 */44 set onready(v: (e: FloatListTag) => void) {45 this._onready = v;46 }47 /**48 * Setter:49 * 50 * Set the direction of the list item layout.51 * Two directions are available:52 * - `vertical`53 * - `horizontal`54 *55 * This setter acts as a DOM attribute56 * 57 * Getter:58 * 59 * Get the currently set direction of list60 * item layout61 *62 * @memberof FloatListTag63 */64 set dir(v: string) {65 $(this).attr("dir", v);66 this.calibrate();67 }68 get dir(): string {69 return $(this).attr("dir");70 }71 /**72 * Disable the dropdown option in this list73 *74 * @memberof FloatListTag75 */76 set dropdown(v: boolean) {}77 /**78 * Disable the list buttons configuration in this79 * list80 *81 * @memberof FloatListTag82 */83 set buttons(v: GenericObject<any>[]) {}84 /**85 * Disable the `showlist` behavior in this list86 *87 * @protected88 * @param {*} e89 * @memberof FloatListTag90 */91 protected showlist(e: any) {}92 /**93 * Disable the `dropoff` behavior in this list94 *95 * @protected96 * @param {*} e97 * @memberof FloatListTag98 */99 protected dropoff(e: any) {}100 /**101 * Function called when the data of the list102 * is changed103 *104 * @protected105 * @memberof FloatListTag106 */107 protected ondatachange(): void {108 this.calibrate();109 }110 /**111 * Mount the list to the DOM tree112 *113 * @protected114 * @returns {void}115 * @memberof FloatListTag116 */117 protected mount(): void {118 $(this.refs.container)119 .css("width", "100%")120 .css("height", "100%");121 $(this.refs.mlist)122 .css("position", "absolute")123 .css("display", "block")124 .css("width", "100%");125 this.observable.on("resize", (e) => this.calibrate());126 if (this._onready) {127 return this._onready(this);128 }129 }130 /**131 * Push an element to the list132 *133 * @param {GenericObject<any>} v an element data134 * @returns135 * @memberof FloatListTag136 */137 push(v: GenericObject<any>) {138 const el = super.push(v);139 this.enable_drag(el);140 return el;141 }142 /**143 * Enable drag and drop on the list144 *145 * @private146 * @param {ListViewItemTag} el the list item DOM element147 * @memberof FloatListTag148 */149 private enable_drag(el: ListViewItemTag): void {150 $(el)151 .css("user-select", "none")152 .css("cursor", "default")153 .css("display", "block")154 .css("position", "absolute")155 .on("mousedown", (evt) => {156 const globalof = $(this.refs.mlist).offset();157 evt.preventDefault();158 const offset = $(el).offset();159 offset.top = evt.clientY - offset.top;160 offset.left = evt.clientX - offset.left;161 const mouse_move = function (162 e: JQuery.MouseEventBase163 ) {164 let top = e.clientY - offset.top - globalof.top;165 let left =166 e.clientX - globalof.left - offset.left;167 left = left < 0 ? 0 : left;168 top = top < 0 ? 0 : top;169 return $(el)170 .css("top", `${top}px`)171 .css("left", `${left}px`);172 };173 var mouse_up = function (e: JQuery.MouseEventBase) {174 $(window).off("mousemove", mouse_move);175 return $(window).off("mouseup", mouse_up);176 };177 $(window).on("mousemove", mouse_move);178 return $(window).on("mouseup", mouse_up);179 });180 }181 /**182 * Calibrate the view of the list183 *184 * @memberof FloatListTag185 */186 calibrate(): void {187 let ctop = 20;188 let cleft = 20;189 $(this.refs.mlist).css(190 "height",191 `${$(this.refs.container).height()}px`192 );193 const gw = $(this.refs.mlist).width();194 const gh = $(this.refs.mlist).height();195 $(this.refs.mlist)196 .children()197 .each((i, e) => {198 $(e)199 .css("top", `${ctop}px`)200 .css("left", `${cleft}px`);201 const w = $(e).width();202 const h = $(e).height();203 if (this.dir === "vertical") {204 ctop += h + 20;205 if (ctop + h > gh) {206 ctop = 20;207 cleft += w + 20;208 }209 } else {210 cleft += w + 20;211 if (cleft + w > gw) {212 cleft = 20;213 ctop += h + 20;214 }215 }216 });217 }218 }219 define("afx-float-list", FloatListTag);220 }221 }...
sketch-lib.d.ts
Source:sketch-lib.d.ts
1export interface RessourceFile {2 kind: string;3 uri: string;4 value: any;5 language: string;6}7export interface ParserFacadeTranformOptions {8 [key: string]: any;9}10export interface ParserFacade {11 transform(12 current: SketchMSLayer,13 data?: SketchMSData,14 opts?: ParserFacadeTranformOptions15 ): RessourceFile[];16 identify(current: SketchMSLayer): boolean;17}18export interface WithLocalContext<T> {19 of(current: SketchMSLayer): T;20 has(current: SketchMSLayer): boolean;21}22export interface WithGlobalContext<T> {23 globalof(current: SketchMSData): T;24 hasGlobalContext(current: SketchMSData): boolean;25}26export interface NavBarButtonSetting {27 stackblitz?: boolean;28}29export interface CodeGenFacadeGenerateOptions {30 [key: string]: any;31}32export interface CodeGenFacade {33 buttons(): NavBarButtonSetting;34 generate(35 data: SketchMSData,36 opts?: CodeGenFacadeGenerateOptions37 ): RessourceFile[];...
Using AI Code Generation
1var wpt = require('./wpt.js');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8### globalOf(url, callback)
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3client.getLocations(function(err, data) {4 if(err) return console.error(err);5 console.log(data);6});7 if(err) return console.error(err);8 console.log(data);9});10client.getTestStatus('140711_4P_4e3', function(err, data) {11 if(err) return console.error(err);12 console.log(data);13});14client.getTestResults('140711_4P_4e3', function(err, data) {15 if(err) return console.error(err);16 console.log(data);17});18client.getHAR('140711_4P_4e3', function(err, data) {19 if(err) return console.error(err);20 console.log(data);21});22client.getWaterfall('140711_4P_4e3', function(err, data) {23 if(err) return console.error(err);24 console.log(data);25});26client.getBreakdown('140711_4P_4e3', function(err, data) {27 if(err) return console.error(err);28 console.log(data);29});30client.getTesters(function(err, data) {31 if(err) return console.error(err);32 console.log(data);33});34client.getTesters('ec2', function(err, data) {35 if(err) return console.error(err);36 console.log(data);37});38client.getTesters('ec2', 'us-west-2', function(err, data) {39 if(err) return console.error(err);40 console.log(data);41});42client.getTesters('ec2', 'us-west-2', 'i-12345678', function(err, data) {43 if(err) return console.error(err);44 console.log(data);45});46client.getTesters('ec2', 'us-west-2', 'i-12345678', 'ami-12345678', function(err, data) {47 if(err) return console.error(err);48 console.log(data);49});50client.getTesters('ec2', 'us-west-2', 'i-12345678', 'ami-12345678
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!!