Best JavaScript code snippet using istanbul
tableheader.es6.js
Source:tableheader.es6.js
1/**2 * @file3 * Sticky table headers.4 */5(function ($, Drupal, displace) {6 /**7 * Attaches sticky table headers.8 *9 * @type {Drupal~behavior}10 *11 * @prop {Drupal~behaviorAttach} attach12 * Attaches the sticky table header behavior.13 */14 Drupal.behaviors.tableHeader = {15 attach(context) {16 $(window).one('scroll.TableHeaderInit', { context }, tableHeaderInitHandler);17 },18 };19 function scrollValue(position) {20 return document.documentElement[position] || document.body[position];21 }22 // Select and initialize sticky table headers.23 function tableHeaderInitHandler(e) {24 const $tables = $(e.data.context).find('table.sticky-enabled').once('tableheader');25 const il = $tables.length;26 for (let i = 0; i < il; i++) {27 TableHeader.tables.push(new TableHeader($tables[i]));28 }29 forTables('onScroll');30 }31 // Helper method to loop through tables and execute a method.32 function forTables(method, arg) {33 const tables = TableHeader.tables;34 const il = tables.length;35 for (let i = 0; i < il; i++) {36 tables[i][method](arg);37 }38 }39 function tableHeaderResizeHandler(e) {40 forTables('recalculateSticky');41 }42 function tableHeaderOnScrollHandler(e) {43 forTables('onScroll');44 }45 function tableHeaderOffsetChangeHandler(e, offsets) {46 forTables('stickyPosition', offsets.top);47 }48 // Bind event that need to change all tables.49 $(window).on({50 /**51 * When resizing table width can change, recalculate everything.52 *53 * @ignore54 */55 'resize.TableHeader': tableHeaderResizeHandler,56 /**57 * Bind only one event to take care of calling all scroll callbacks.58 *59 * @ignore60 */61 'scroll.TableHeader': tableHeaderOnScrollHandler,62 });63 // Bind to custom Drupal events.64 $(document).on({65 /**66 * Recalculate columns width when window is resized and when show/hide67 * weight is triggered.68 *69 * @ignore70 */71 'columnschange.TableHeader': tableHeaderResizeHandler,72 /**73 * Recalculate TableHeader.topOffset when viewport is resized.74 *75 * @ignore76 */77 'drupalViewportOffsetChange.TableHeader': tableHeaderOffsetChangeHandler,78 });79 /**80 * Constructor for the tableHeader object. Provides sticky table headers.81 *82 * TableHeader will make the current table header stick to the top of the page83 * if the table is very long.84 *85 * @constructor Drupal.TableHeader86 *87 * @param {HTMLElement} table88 * DOM object for the table to add a sticky header to.89 *90 * @listens event:columnschange91 */92 function TableHeader(table) {93 const $table = $(table);94 /**95 * @name Drupal.TableHeader#$originalTable96 *97 * @type {HTMLElement}98 */99 this.$originalTable = $table;100 /**101 * @type {jQuery}102 */103 this.$originalHeader = $table.children('thead');104 /**105 * @type {jQuery}106 */107 this.$originalHeaderCells = this.$originalHeader.find('> tr > th');108 /**109 * @type {null|bool}110 */111 this.displayWeight = null;112 this.$originalTable.addClass('sticky-table');113 this.tableHeight = $table[0].clientHeight;114 this.tableOffset = this.$originalTable.offset();115 // React to columns change to avoid making checks in the scroll callback.116 this.$originalTable.on('columnschange', { tableHeader: this }, (e, display) => {117 const tableHeader = e.data.tableHeader;118 if (tableHeader.displayWeight === null || tableHeader.displayWeight !== display) {119 tableHeader.recalculateSticky();120 }121 tableHeader.displayWeight = display;122 });123 // Create and display sticky header.124 this.createSticky();125 }126 /**127 * Store the state of TableHeader.128 */129 $.extend(TableHeader, /** @lends Drupal.TableHeader */{130 /**131 * This will store the state of all processed tables.132 *133 * @type {Array.<Drupal.TableHeader>}134 */135 tables: [],136 });137 /**138 * Extend TableHeader prototype.139 */140 $.extend(TableHeader.prototype, /** @lends Drupal.TableHeader# */{141 /**142 * Minimum height in pixels for the table to have a sticky header.143 *144 * @type {number}145 */146 minHeight: 100,147 /**148 * Absolute position of the table on the page.149 *150 * @type {?Drupal~displaceOffset}151 */152 tableOffset: null,153 /**154 * Absolute position of the table on the page.155 *156 * @type {?number}157 */158 tableHeight: null,159 /**160 * Boolean storing the sticky header visibility state.161 *162 * @type {bool}163 */164 stickyVisible: false,165 /**166 * Create the duplicate header.167 */168 createSticky() {169 // Clone the table header so it inherits original jQuery properties.170 const $stickyHeader = this.$originalHeader.clone(true);171 // Hide the table to avoid a flash of the header clone upon page load.172 this.$stickyTable = $('<table class="sticky-header"/>')173 .css({174 visibility: 'hidden',175 position: 'fixed',176 top: '0px',177 })178 .append($stickyHeader)179 .insertBefore(this.$originalTable);180 this.$stickyHeaderCells = $stickyHeader.find('> tr > th');181 // Initialize all computations.182 this.recalculateSticky();183 },184 /**185 * Set absolute position of sticky.186 *187 * @param {number} offsetTop188 * The top offset for the sticky header.189 * @param {number} offsetLeft190 * The left offset for the sticky header.191 *192 * @return {jQuery}193 * The sticky table as a jQuery collection.194 */195 stickyPosition(offsetTop, offsetLeft) {196 const css = {};197 if (typeof offsetTop === 'number') {198 css.top = `${offsetTop}px`;199 }200 if (typeof offsetLeft === 'number') {201 css.left = `${this.tableOffset.left - offsetLeft}px`;202 }203 return this.$stickyTable.css(css);204 },205 /**206 * Returns true if sticky is currently visible.207 *208 * @return {bool}209 * The visibility status.210 */211 checkStickyVisible() {212 const scrollTop = scrollValue('scrollTop');213 const tableTop = this.tableOffset.top - displace.offsets.top;214 const tableBottom = tableTop + this.tableHeight;215 let visible = false;216 if (tableTop < scrollTop && scrollTop < (tableBottom - this.minHeight)) {217 visible = true;218 }219 this.stickyVisible = visible;220 return visible;221 },222 /**223 * Check if sticky header should be displayed.224 *225 * This function is throttled to once every 250ms to avoid unnecessary226 * calls.227 *228 * @param {jQuery.Event} e229 * The scroll event.230 */231 onScroll(e) {232 this.checkStickyVisible();233 // Track horizontal positioning relative to the viewport.234 this.stickyPosition(null, scrollValue('scrollLeft'));235 this.$stickyTable.css('visibility', this.stickyVisible ? 'visible' : 'hidden');236 },237 /**238 * Event handler: recalculates position of the sticky table header.239 *240 * @param {jQuery.Event} event241 * Event being triggered.242 */243 recalculateSticky(event) {244 // Update table size.245 this.tableHeight = this.$originalTable[0].clientHeight;246 // Update offset top.247 displace.offsets.top = displace.calculateOffset('top');248 this.tableOffset = this.$originalTable.offset();249 this.stickyPosition(displace.offsets.top, scrollValue('scrollLeft'));250 // Update columns width.251 let $that = null;252 let $stickyCell = null;253 let display = null;254 // Resize header and its cell widths.255 // Only apply width to visible table cells. This prevents the header from256 // displaying incorrectly when the sticky header is no longer visible.257 const il = this.$originalHeaderCells.length;258 for (let i = 0; i < il; i++) {259 $that = $(this.$originalHeaderCells[i]);260 $stickyCell = this.$stickyHeaderCells.eq($that.index());261 display = $that.css('display');262 if (display !== 'none') {263 $stickyCell.css({ width: $that.css('width'), display });264 }265 else {266 $stickyCell.css('display', 'none');267 }268 }269 this.$stickyTable.css('width', this.$originalTable.outerWidth());270 },271 });272 // Expose constructor in the public space.273 Drupal.TableHeader = TableHeader;...
sticky-table.js
Source:sticky-table.js
1import React from 'react';2import styled from '@emotion/styled';3const Table = styled.table`4 max-width: 568px;5 height: 320px;6 margin-bottom: 0.5rem;7 display: block;8 overflow: scroll;9 table-layout: fixed;10 border-collapse: collapse;11 border: 1px solid var(--gold);12`;13const TableHeader = styled.th`14 padding: 20px;15 position: sticky;16 background: #666666;17 color: #ffffff;18 text-align: center;19 &[scope='col'] {20 top: 0;21 }22 &[scope='row'] {23 left: 0;24 }25`;26const TableCell = styled.td`27 padding: 20px;28 border: 1px solid;29 text-align: center;30`;31export default function StickyTable() {32 return (33 <Table>34 <thead>35 <tr>36 <TableHeader scope="row"></TableHeader>37 <TableHeader scope="col">Wednesday</TableHeader>38 <TableHeader scope="col">Thursday</TableHeader>39 <TableHeader scope="col">Friday</TableHeader>40 <TableHeader scope="col">Saturday</TableHeader>41 <TableHeader scope="col">Sunday</TableHeader>42 </tr>43 </thead>44 <tbody>45 <tr>46 <TableHeader scope="row">8:00 AM</TableHeader>47 <TableCell>Wake up</TableCell>48 <TableCell>Wake up</TableCell>49 <TableCell>Wake up</TableCell>50 <TableCell>Sleep in</TableCell>51 <TableCell>Sleep in</TableCell>52 </tr>53 <tr>54 <TableHeader scope="row">8:30 AM</TableHeader>55 <TableCell>Brush teeth</TableCell>56 <TableCell>Brush teeth</TableCell>57 <TableCell>Brush teeth</TableCell>58 <TableCell>Sleep in more</TableCell>59 <TableCell>Wake up</TableCell>60 </tr>61 <tr>62 <TableHeader scope="row">9:00 AM</TableHeader>63 <TableCell>Eat breakfast</TableCell>64 <TableCell>Eat breakfast</TableCell>65 <TableCell>Read</TableCell>66 <TableCell>Sleep in more</TableCell>67 <TableCell>Brush teeth</TableCell>68 </tr>69 <tr>70 <TableHeader scope="row">9:30 AM</TableHeader>71 <TableCell>Get coffee</TableCell>72 <TableCell>Get coffee</TableCell>73 <TableCell>Eat breakfast</TableCell>74 <TableCell>Wake up</TableCell>75 <TableCell>Eat breakfast</TableCell>76 </tr>77 <tr>78 <TableHeader scope="row">10:00 AM</TableHeader>79 <TableCell>Code</TableCell>80 <TableCell>Code</TableCell>81 <TableCell>Code</TableCell>82 <TableCell>Eat breakfast</TableCell>83 <TableCell>Get coffee</TableCell>84 </tr>85 <tr>86 <TableHeader scope="row">10:30 AM</TableHeader>87 <TableCell>Code</TableCell>88 <TableCell>Code</TableCell>89 <TableCell>Code</TableCell>90 <TableCell>Code</TableCell>91 <TableCell>Chill</TableCell>92 </tr>93 </tbody>94 </Table>95 );...
Using AI Code Generation
1var istanbul = require('istanbul');2var table = istanbul.Table.create();3table.add({ id: 'foo', foo: 1, bar: 2 });4table.add({ id: 'bar', foo: 3, bar: 4 });5console.log(table.getHeader());6console.log(table.getRows());7var http = require('http');8var server = http.createServer(function(req, res){9 res.writeHead(200, {'Content-Type': 'text/plain'});10 res.end('Hello World');11});12server.listen(3000, '
Using AI Code Generation
1const tableHeader = require('istanbul-reporter-gherkin').tableHeader;2const tableRow = require('istanbul-reporter-gherkin').tableRow;3const tableFooter = require('istanbul-reporter-gherkin').tableFooter;4const table = require('istanbul-reporter-gherkin').table;5const { Given, When, Then } = require('cucumber');6Given('I have entered {int} into the calculator', function (int) {7 return 'pending';8});9When('I press add', function () {10 return 'pending';11});12Then('the result should be {int} on the screen', function (int) {13 return 'pending';14});15Then('I should see {string} in the console', function (string) {16 return 'pending';17});18Then('I should see the following table in the console', function (dataTable) {19 return 'pending';20});21Then('I should see the following table in the console', function (dataTable) {22 const header = tableHeader(dataTable);23 const rows = dataTable.raw().slice(1).map(tableRow);24 const footer = tableFooter(dataTable);25 console.log(table(header, rows, footer));26 return 'pending';27});28const { Given, When, Then } = require('cucumber');29const tableHeader = require('istanbul-reporter-gherkin').tableHeader;30const tableRow = require('istan
Using AI Code Generation
1var istanbul = require('istanbul');2var report = istanbul.Report.create('html', { dir: 'coverage' });3report.writeReport(collector, true);4var istanbul = require('istanbul');5var table = istanbul.Table.create();6var tableHeader = table.getHeader();7console.log(tableHeader);8var istanbul = require('istanbul');9var table = istanbul.Table.create();10var tableHeader = table.getHeader();11console.log(tableHeader);12var istanbul = require('istanbul');13var table = istanbul.Table.create();14var tableHeader = table.getHeader();15console.log(tableHeader);16var istanbul = require('istanbul');17var table = istanbul.Table.create();18var tableHeader = table.getHeader();19console.log(tableHeader);20var istanbul = require('istanbul');21var table = istanbul.Table.create();22var tableHeader = table.getHeader();23console.log(tableHeader);24var istanbul = require('istanbul');25var table = istanbul.Table.create();26var tableHeader = table.getHeader();27console.log(tableHeader);28var istanbul = require('istanbul');29var table = istanbul.Table.create();30var tableHeader = table.getHeader();31console.log(tableHeader);32var istanbul = require('istanbul');33var table = istanbul.Table.create();34var tableHeader = table.getHeader();35console.log(tableHeader);36var istanbul = require('istanbul');37var table = istanbul.Table.create();38var tableHeader = table.getHeader();39console.log(tableHeader);40var istanbul = require('istanbul');41var table = istanbul.Table.create();42var tableHeader = table.getHeader();43console.log(tableHeader);44var istanbul = require('istan
Using AI Code Generation
1var tableHeader = require('istanbul').Table.prototype.header;2var table = new (require('istanbul').Table)();3tableHeader.call(table, ['col1', 'col2', 'col3']);4console.log(table.toString());5Table.prototype.header = function (headers) {6 var tr = this.el.createChild('tr'),7 len;8 for (i = 0, len = headers.length; i < len; i += 1) {9 tr.createChild('th')._text(headers[i]);10 }11};12Table.prototype.header = function (headers) {13 var tr = this.el.createChild('tr'),14 len;15 for (i = 0, len = headers.length; i < len; i += 1) {16 tr.createChild('th').attr('width', '4')._text(headers[i]);17 }18};19Table.prototype.header = function (headers) {20 var tr = this.el.createChild('tr'),21 len;22 for (i = 0
Using AI Code Generation
1var tableHeader = require('istanbul').Table.prototype.header;2var tableRow = require('istanbul').Table.prototype.row;3var writeReport = require('istanbul').Report.prototype.writeReport;4var writeReport = require('istanbul').Report.prototype.writeReport;5var writeReport = require('istanbul').Report.prototype.writeReport;6var writeReport = require('istanbul').Report.prototype.writeReport;7var writeReport = require('istanbul').Report.prototype.writeReport;8var writeReport = require('istanbul').Report.prototype.writeReport;9var writeReport = require('istanbul').Report.prototype.writeReport;10var writeReport = require('istanbul').Report.prototype.writeReport;11var writeReport = require('istanbul').Report.prototype.writeReport;12var writeReport = require('istanbul').Report.prototype.writeReport;13var writeReport = require('istanbul').Report.prototype.writeReport;14var writeReport = require('istanbul').Report.prototype.writeReport;
Using AI Code Generation
1var tableHeader = istanbul.tableHeader();2var tableBody = istanbul.tableBody();3var tableFooter = istanbul.tableFooter();4var table = istanbul.table();5istanbul.table(res);6istanbul.table(res, 200);7The tableHeader() method8var header = '<table><tr><th>City</th><th>Population</th></tr>';9return header;10The tableBody() method11var body = '';12for(var i = 0; i < cities.length; i++){
Using AI Code Generation
1var istanbulTable = require('./istanbulTable.js');2var tableHeader = istanbulTable.tableHeader;3var table = tableHeader(['one', 'two', 'three']);4console.log(table);5module.exports = {6 tableHeader: function (headers) {7 var table = '| ';8 for (var i = 0; i < headers.length; i++) {9 table = table + headers[i] + ' | ';10 }11| ';12 for (var j = 0; j < headers.length; j++) {13 table = table + '--- | ';14 }15';16 return table;17 }18};19var istanbulTable = require('./istanbulTable.js');20var tableHeader = istanbulTable.tableHeader;21var table = tableHeader(['one', 'two', 'three']);22console.log(table);
Using AI Code Generation
1var istanbul = require('istanbul');2var istanbulObject = new istanbul();3istanbulObject.tableHeader();4var istanbul = require('istanbul');5var istanbulObject = new istanbul();6istanbulObject.tableHeader();
Using AI Code Generation
1var table = require('istanbul').Table;2var table = new Table();3table.addRows({4});5var header = table.getHeader();6console.log(header);7var table = require('istanbul').Table;8var table = new Table();9table.addRows({10});11var header = table.getHeader();12console.log(header);
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!!