Best JavaScript code snippet using wpt
marker.js
Source:marker.js
1/* ***** BEGIN LICENSE BLOCK *****2 * Distributed under the BSD license:3 *4 * Copyright (c) 2010, Ajax.org B.V.5 * All rights reserved.6 * 7 * Redistribution and use in source and binary forms, with or without8 * modification, are permitted provided that the following conditions are met:9 * * Redistributions of source code must retain the above copyright10 * notice, this list of conditions and the following disclaimer.11 * * Redistributions in binary form must reproduce the above copyright12 * notice, this list of conditions and the following disclaimer in the13 * documentation and/or other materials provided with the distribution.14 * * Neither the name of Ajax.org B.V. nor the15 * names of its contributors may be used to endorse or promote products16 * derived from this software without specific prior written permission.17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE21 * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 *29 * ***** END LICENSE BLOCK ***** */30define(function(require, exports, module) {31"use strict";32var Range = require("../range").Range;33var dom = require("../lib/dom");34var Marker = function(parentEl) {35 this.element = dom.createElement("div");36 this.element.className = "ace_layer ace_marker-layer";37 parentEl.appendChild(this.element);38};39(function() {40 this.$padding = 0;41 this.setPadding = function(padding) {42 this.$padding = padding;43 };44 this.setSession = function(session) {45 this.session = session;46 };47 48 this.setMarkers = function(markers) {49 this.markers = markers;50 };51 this.update = function(config) {52 var config = config || this.config;53 if (!config)54 return;55 this.config = config;56 var html = [];57 for (var key in this.markers) {58 var marker = this.markers[key];59 if (!marker.range) {60 marker.update(html, this, this.session, config);61 continue;62 }63 var range = marker.range.clipRows(config.firstRow, config.lastRow);64 if (range.isEmpty()) continue;65 range = range.toScreenRange(this.session);66 if (marker.renderer) {67 var top = this.$getTop(range.start.row, config);68 var left = this.$padding + range.start.column * config.characterWidth;69 marker.renderer(html, range, left, top, config);70 } else if (marker.type == "fullLine") {71 this.drawFullLineMarker(html, range, marker.clazz, config);72 } else if (marker.type == "screenLine") {73 this.drawScreenLineMarker(html, range, marker.clazz, config);74 } else if (range.isMultiLine()) {75 if (marker.type == "text")76 this.drawTextMarker(html, range, marker.clazz, config);77 else78 this.drawMultiLineMarker(html, range, marker.clazz, config);79 } else {80 this.drawSingleLineMarker(html, range, marker.clazz + " ace_start", config);81 }82 }83 this.element.innerHTML = html.join("");84 };85 this.$getTop = function(row, layerConfig) {86 return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;87 };88 // Draws a marker, which spans a range of text on multiple lines 89 this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {90 // selection start91 var row = range.start.row;92 var session = this.session;93 var lineRange = new Range(94 row, range.start.column,95 row, session.getScreenLastRowColumn(row)96 );97 this.drawSingleLineMarker(stringBuilder, lineRange, clazz + " ace_start", layerConfig, 1, extraStyle);98 // selection end99 row = range.end.row;100 lineRange = new Range(row, session.getRowWrapIndent(row), row, range.end.column);101 this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, extraStyle);102 for (row = range.start.row + 1; row < range.end.row; row++) {103 lineRange.start.row = row;104 lineRange.start.column = session.getRowWrapIndent(row);105 lineRange.end.row = row;106 lineRange.end.column = session.getScreenLastRowColumn(row);107 this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, extraStyle);108 }109 };110 // Draws a multi line marker, where lines span the full width111 this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {112 // from selection start to the end of the line113 var padding = this.$padding;114 var height = config.lineHeight;115 var top = this.$getTop(range.start.row, config);116 var left = padding + range.start.column * config.characterWidth;117 extraStyle = extraStyle || "";118 stringBuilder.push(119 "<div class='", clazz, " ace_start' style='",120 "height:", height, "px;",121 "right:0;",122 "top:", top, "px;",123 "left:", left, "px;", extraStyle, "'></div>"124 );125 // from start of the last line to the selection end126 top = this.$getTop(range.end.row, config);127 var width = range.end.column * config.characterWidth;128 stringBuilder.push(129 "<div class='", clazz, "' style='",130 "height:", height, "px;",131 "width:", width, "px;",132 "top:", top, "px;",133 "left:", padding, "px;", extraStyle, "'></div>"134 );135 // all the complete lines136 height = (range.end.row - range.start.row - 1) * config.lineHeight;137 if (height <= 0)138 return;139 top = this.$getTop(range.start.row + 1, config);140 stringBuilder.push(141 "<div class='", clazz, "' style='",142 "height:", height, "px;",143 "right:0;",144 "top:", top, "px;",145 "left:", padding, "px;", extraStyle, "'></div>"146 );147 };148 // Draws a marker which covers part or whole width of a single screen line149 this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {150 var height = config.lineHeight;151 var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;152 var top = this.$getTop(range.start.row, config);153 var left = this.$padding + range.start.column * config.characterWidth;154 stringBuilder.push(155 "<div class='", clazz, "' style='",156 "height:", height, "px;",157 "width:", width, "px;",158 "top:", top, "px;",159 "left:", left, "px;", extraStyle || "", "'></div>"160 );161 };162 this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {163 var top = this.$getTop(range.start.row, config);164 var height = config.lineHeight;165 if (range.start.row != range.end.row)166 height += this.$getTop(range.end.row, config) - top;167 stringBuilder.push(168 "<div class='", clazz, "' style='",169 "height:", height, "px;",170 "top:", top, "px;",171 "left:0;right:0;", extraStyle || "", "'></div>"172 );173 };174 175 this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {176 var top = this.$getTop(range.start.row, config);177 var height = config.lineHeight;178 stringBuilder.push(179 "<div class='", clazz, "' style='",180 "height:", height, "px;",181 "top:", top, "px;",182 "left:0;right:0;", extraStyle || "", "'></div>"183 );184 };185}).call(Marker.prototype);186exports.Marker = Marker;...
Using AI Code Generation
1var editor = CKEDITOR.replace('editor1');2editor.on('instanceReady', function (ev) {3 ev.editor.dataProcessor.writer.setRules('p', {4 });5 ev.editor.dataProcessor.writer.setRules('div', {6 });7 ev.editor.dataProcessor.writer.setRules('li', {8 });9 ev.editor.dataProcessor.writer.setRules('ul', {10 });11 ev.editor.dataProcessor.writer.setRules('ol', {12 });13 ev.editor.dataProcessor.writer.setRules('blockquote', {14 });15 ev.editor.dataProcessor.writer.setRules('h1', {16 });17 ev.editor.dataProcessor.writer.setRules('h2', {18 });19 ev.editor.dataProcessor.writer.setRules('h3', {20 });21 ev.editor.dataProcessor.writer.setRules('h4', {22 });
Using AI Code Generation
1CKEDITOR.plugins.add('extraStyle', {2 init: function(editor) {3 editor.on('instanceReady', function() {4 editor.document.appendStyleSheet(CKEDITOR.getUrl('test.css'));5 });6 }7});8.wpview-wrap {9 border: 1px solid red;10}11CKEDITOR.plugins.add('extraStyle', {12 init: function(editor) {13 editor.on('instanceReady', function() {14 editor.document.appendStyleSheet(CKEDITOR.getUrl('test.css'));15 });16 }17});18.wpview-wrap {19 border: 1px solid red;20}21CKEDITOR.plugins.add('myplugin', {22 init: function(editor) {23 editor.on('instanceReady', function() {24 editor.wp.addInlineViewType('myview', {25 init: function() {26 this.element.setHtml('Hello world!');27 }28 });29 });30 }31});32wp.addInlineViewType( name, viewDefinition );33* **toData** (function) - A function that is called when the view is converted to data. The function is passed a single
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3var extraStyle = {4};5}, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});
Using AI Code Generation
1var text = 'this is a test';2wp.texturize.extraStyle(text, function(err, result) {3 if (err) {4 console.log(err);5 } else {6 console.log(result);7 }8});
Using AI Code Generation
1var wptbTableSetup = wptbTableSetup || {};2wptbTableSetup.extraStyle = function (table, element) {3 if (element.classList.contains('wptb-element-datasource') && element.classList.contains('wptb-preview-table')) {4 var wptbTableStateSaveManager = new WPTB_TableStateSaveManager();5 wptbTableStateSaveManager.tableStateSet();6 var wptbTableState = wptbTableStateSaveManager.tableStateGet();7 var wptbDsTable = element.querySelector('.wptb-preview-table');8 var wptbDsTableBody = wptbDsTable.querySelector('tbody');9 var wptbDsTableRows = wptbDsTableBody.querySelectorAll('tr');10 var wptbDsTableRowsCount = wptbDsTableRows.length;11 var wptbDsTableColumnsCount = 0;12 var wptbDsTableColumnsCountArr = [];13 for (var i = 0; i < wptbDsTableRowsCount; i++) {14 var wptbDsTableColumns = wptbDsTableRows[i].querySelectorAll('td');15 var wptbDsTableColumnsCount = wptbDsTableColumns.length;16 wptbDsTableColumnsCountArr.push(wptbDsTableColumnsCount);17 }18 var wptbDsTableColumnsCountMax = Math.max.apply(null, wptbDsTableColumnsCountArr);19 var wptbDsTableColumnsCountMin = Math.min.apply(null, wptbDsTableColumnsCountArr);20 var wptbDsTableColumnsCountMaxIndex = wptbDsTableColumnsCountArr.indexOf(wptbDsTableColumnsCountMax);21 var wptbDsTableColumnsCountMinIndex = wptbDsTableColumnsCountArr.indexOf(wptbDsTableColumnsCountMin);22 if (wptbDsTableColumnsCountMaxIndex == wptbDsTableColumnsCountMinIndex) {23 wptbDsTableColumnsCountMinIndex = -1;24 }25 var wptbDsTableRowsArr = [];26 var wptbDsTableRowsArrMin = [];27 for (var i = 0; i < wptbDsTableRowsCount; i++) {
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!!