Best JavaScript code snippet using wpt
annotation_layer.js
Source:annotation_layer.js
...54 return new RadioButtonWidgetAnnotationElement(parameters);55 } else if (parameters.data.checkBox) {56 return new CheckboxWidgetAnnotationElement(parameters);57 }58 return new PushButtonWidgetAnnotationElement(parameters);59 case 'Ch':60 return new ChoiceWidgetAnnotationElement(parameters);61 }62 return new WidgetAnnotationElement(parameters);63 case _util.AnnotationType.POPUP:64 return new PopupAnnotationElement(parameters);65 case _util.AnnotationType.LINE:66 return new LineAnnotationElement(parameters);67 case _util.AnnotationType.SQUARE:68 return new SquareAnnotationElement(parameters);69 case _util.AnnotationType.CIRCLE:70 return new CircleAnnotationElement(parameters);71 case _util.AnnotationType.POLYLINE:72 return new PolylineAnnotationElement(parameters);73 case _util.AnnotationType.POLYGON:74 return new PolygonAnnotationElement(parameters);75 case _util.AnnotationType.HIGHLIGHT:76 return new HighlightAnnotationElement(parameters);77 case _util.AnnotationType.UNDERLINE:78 return new UnderlineAnnotationElement(parameters);79 case _util.AnnotationType.SQUIGGLY:80 return new SquigglyAnnotationElement(parameters);81 case _util.AnnotationType.STRIKEOUT:82 return new StrikeOutAnnotationElement(parameters);83 case _util.AnnotationType.STAMP:84 return new StampAnnotationElement(parameters);85 case _util.AnnotationType.FILEATTACHMENT:86 return new FileAttachmentAnnotationElement(parameters);87 default:88 return new AnnotationElement(parameters);89 }90 }91 }]);92 return AnnotationElementFactory;93}();94var AnnotationElement = function () {95 function AnnotationElement(parameters) {96 var isRenderable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;97 var ignoreBorder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;98 _classCallCheck(this, AnnotationElement);99 this.isRenderable = isRenderable;100 this.data = parameters.data;101 this.layer = parameters.layer;102 this.page = parameters.page;103 this.viewport = parameters.viewport;104 this.linkService = parameters.linkService;105 this.downloadManager = parameters.downloadManager;106 this.imageResourcesPath = parameters.imageResourcesPath;107 this.renderInteractiveForms = parameters.renderInteractiveForms;108 this.svgFactory = parameters.svgFactory;109 if (isRenderable) {110 this.container = this._createContainer(ignoreBorder);111 }112 }113 _createClass(AnnotationElement, [{114 key: '_createContainer',115 value: function _createContainer() {116 var ignoreBorder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;117 var data = this.data,118 page = this.page,119 viewport = this.viewport;120 var container = document.createElement('section');121 var width = data.rect[2] - data.rect[0];122 var height = data.rect[3] - data.rect[1];123 container.setAttribute('data-annotation-id', data.id);124 var rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);125 container.style.transform = 'matrix(' + viewport.transform.join(',') + ')';126 container.style.transformOrigin = -rect[0] + 'px ' + -rect[1] + 'px';127 if (!ignoreBorder && data.borderStyle.width > 0) {128 container.style.borderWidth = data.borderStyle.width + 'px';129 if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {130 width = width - 2 * data.borderStyle.width;131 height = height - 2 * data.borderStyle.width;132 }133 var horizontalRadius = data.borderStyle.horizontalCornerRadius;134 var verticalRadius = data.borderStyle.verticalCornerRadius;135 if (horizontalRadius > 0 || verticalRadius > 0) {136 var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';137 container.style.borderRadius = radius;138 }139 switch (data.borderStyle.style) {140 case _util.AnnotationBorderStyleType.SOLID:141 container.style.borderStyle = 'solid';142 break;143 case _util.AnnotationBorderStyleType.DASHED:144 container.style.borderStyle = 'dashed';145 break;146 case _util.AnnotationBorderStyleType.BEVELED:147 (0, _util.warn)('Unimplemented border style: beveled');148 break;149 case _util.AnnotationBorderStyleType.INSET:150 (0, _util.warn)('Unimplemented border style: inset');151 break;152 case _util.AnnotationBorderStyleType.UNDERLINE:153 container.style.borderBottomStyle = 'solid';154 break;155 default:156 break;157 }158 if (data.color) {159 container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);160 } else {161 container.style.borderWidth = 0;162 }163 }164 container.style.left = rect[0] + 'px';165 container.style.top = rect[1] + 'px';166 container.style.width = width + 'px';167 container.style.height = height + 'px';168 return container;169 }170 }, {171 key: '_createPopup',172 value: function _createPopup(container, trigger, data) {173 if (!trigger) {174 trigger = document.createElement('div');175 trigger.style.height = container.style.height;176 trigger.style.width = container.style.width;177 container.appendChild(trigger);178 }179 var popupElement = new PopupElement({180 container: container,181 trigger: trigger,182 color: data.color,183 title: data.title,184 contents: data.contents,185 hideWrapper: true186 });187 var popup = popupElement.render();188 popup.style.left = container.style.width;189 container.appendChild(popup);190 }191 }, {192 key: 'render',193 value: function render() {194 (0, _util.unreachable)('Abstract method `AnnotationElement.render` called');195 }196 }]);197 return AnnotationElement;198}();199var LinkAnnotationElement = function (_AnnotationElement) {200 _inherits(LinkAnnotationElement, _AnnotationElement);201 function LinkAnnotationElement(parameters) {202 _classCallCheck(this, LinkAnnotationElement);203 var isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action);204 return _possibleConstructorReturn(this, (LinkAnnotationElement.__proto__ || Object.getPrototypeOf(LinkAnnotationElement)).call(this, parameters, isRenderable));205 }206 _createClass(LinkAnnotationElement, [{207 key: 'render',208 value: function render() {209 this.container.className = 'linkAnnotation';210 var link = document.createElement('a');211 (0, _dom_utils.addLinkAttributes)(link, {212 url: this.data.url,213 target: this.data.newWindow ? _dom_utils.LinkTarget.BLANK : undefined214 });215 if (!this.data.url) {216 if (this.data.action) {217 this._bindNamedAction(link, this.data.action);218 } else {219 this._bindLink(link, this.data.dest);220 }221 }222 this.container.appendChild(link);223 return this.container;224 }225 }, {226 key: '_bindLink',227 value: function _bindLink(link, destination) {228 var _this2 = this;229 link.href = this.linkService.getDestinationHash(destination);230 link.onclick = function () {231 if (destination) {232 _this2.linkService.navigateTo(destination);233 }234 return false;235 };236 if (destination) {237 link.className = 'internalLink';238 }239 }240 }, {241 key: '_bindNamedAction',242 value: function _bindNamedAction(link, action) {243 var _this3 = this;244 link.href = this.linkService.getAnchorUrl('');245 link.onclick = function () {246 _this3.linkService.executeNamedAction(action);247 return false;248 };249 link.className = 'internalLink';250 }251 }]);252 return LinkAnnotationElement;253}(AnnotationElement);254var TextAnnotationElement = function (_AnnotationElement2) {255 _inherits(TextAnnotationElement, _AnnotationElement2);256 function TextAnnotationElement(parameters) {257 _classCallCheck(this, TextAnnotationElement);258 var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);259 return _possibleConstructorReturn(this, (TextAnnotationElement.__proto__ || Object.getPrototypeOf(TextAnnotationElement)).call(this, parameters, isRenderable));260 }261 _createClass(TextAnnotationElement, [{262 key: 'render',263 value: function render() {264 this.container.className = 'textAnnotation';265 var image = document.createElement('img');266 image.style.height = this.container.style.height;267 image.style.width = this.container.style.width;268 image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';269 image.alt = '[{{type}} Annotation]';270 image.dataset.l10nId = 'text_annotation_type';271 image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });272 if (!this.data.hasPopup) {273 this._createPopup(this.container, image, this.data);274 }275 this.container.appendChild(image);276 return this.container;277 }278 }]);279 return TextAnnotationElement;280}(AnnotationElement);281var WidgetAnnotationElement = function (_AnnotationElement3) {282 _inherits(WidgetAnnotationElement, _AnnotationElement3);283 function WidgetAnnotationElement() {284 _classCallCheck(this, WidgetAnnotationElement);285 return _possibleConstructorReturn(this, (WidgetAnnotationElement.__proto__ || Object.getPrototypeOf(WidgetAnnotationElement)).apply(this, arguments));286 }287 _createClass(WidgetAnnotationElement, [{288 key: 'render',289 value: function render() {290 return this.container;291 }292 }]);293 return WidgetAnnotationElement;294}(AnnotationElement);295var TextWidgetAnnotationElement = function (_WidgetAnnotationElem) {296 _inherits(TextWidgetAnnotationElement, _WidgetAnnotationElem);297 function TextWidgetAnnotationElement(parameters) {298 _classCallCheck(this, TextWidgetAnnotationElement);299 var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;300 return _possibleConstructorReturn(this, (TextWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(TextWidgetAnnotationElement)).call(this, parameters, isRenderable));301 }302 _createClass(TextWidgetAnnotationElement, [{303 key: 'render',304 value: function render() {305 var TEXT_ALIGNMENT = ['left', 'center', 'right'];306 this.container.className = 'textWidgetAnnotation';307 var element = null;308 if (this.renderInteractiveForms) {309 if (this.data.multiLine) {310 element = document.createElement('textarea');311 element.textContent = this.data.fieldValue;312 } else {313 element = document.createElement('input');314 element.type = 'text';315 element.setAttribute('value', this.data.fieldValue);316 }317 element.disabled = this.data.readOnly;318 if (this.data.maxLen !== null) {319 element.maxLength = this.data.maxLen;320 }321 if (this.data.comb) {322 var fieldWidth = this.data.rect[2] - this.data.rect[0];323 var combWidth = fieldWidth / this.data.maxLen;324 element.classList.add('comb');325 element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';326 }327 } else {328 element = document.createElement('div');329 element.textContent = this.data.fieldValue;330 element.style.verticalAlign = 'middle';331 element.style.display = 'table-cell';332 var font = null;333 if (this.data.fontRefName) {334 font = this.page.commonObjs.getData(this.data.fontRefName);335 }336 this._setTextStyle(element, font);337 }338 if (this.data.textAlignment !== null) {339 element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];340 }341 this.container.appendChild(element);342 return this.container;343 }344 }, {345 key: '_setTextStyle',346 value: function _setTextStyle(element, font) {347 var style = element.style;348 style.fontSize = this.data.fontSize + 'px';349 style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';350 if (!font) {351 return;352 }353 style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';354 style.fontStyle = font.italic ? 'italic' : 'normal';355 var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';356 var fallbackName = font.fallbackName || 'Helvetica, sans-serif';357 style.fontFamily = fontFamily + fallbackName;358 }359 }]);360 return TextWidgetAnnotationElement;361}(WidgetAnnotationElement);362var CheckboxWidgetAnnotationElement = function (_WidgetAnnotationElem2) {363 _inherits(CheckboxWidgetAnnotationElement, _WidgetAnnotationElem2);364 function CheckboxWidgetAnnotationElement(parameters) {365 _classCallCheck(this, CheckboxWidgetAnnotationElement);366 return _possibleConstructorReturn(this, (CheckboxWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(CheckboxWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms));367 }368 _createClass(CheckboxWidgetAnnotationElement, [{369 key: 'render',370 value: function render() {371 this.container.className = 'buttonWidgetAnnotation checkBox';372 var element = document.createElement('input');373 element.disabled = this.data.readOnly;374 element.type = 'checkbox';375 if (this.data.fieldValue && this.data.fieldValue !== 'Off') {376 element.setAttribute('checked', true);377 }378 this.container.appendChild(element);379 return this.container;380 }381 }]);382 return CheckboxWidgetAnnotationElement;383}(WidgetAnnotationElement);384var RadioButtonWidgetAnnotationElement = function (_WidgetAnnotationElem3) {385 _inherits(RadioButtonWidgetAnnotationElement, _WidgetAnnotationElem3);386 function RadioButtonWidgetAnnotationElement(parameters) {387 _classCallCheck(this, RadioButtonWidgetAnnotationElement);388 return _possibleConstructorReturn(this, (RadioButtonWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(RadioButtonWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms));389 }390 _createClass(RadioButtonWidgetAnnotationElement, [{391 key: 'render',392 value: function render() {393 this.container.className = 'buttonWidgetAnnotation radioButton';394 var element = document.createElement('input');395 element.disabled = this.data.readOnly;396 element.type = 'radio';397 element.name = this.data.fieldName;398 if (this.data.fieldValue === this.data.buttonValue) {399 element.setAttribute('checked', true);400 }401 this.container.appendChild(element);402 return this.container;403 }404 }]);405 return RadioButtonWidgetAnnotationElement;406}(WidgetAnnotationElement);407var PushButtonWidgetAnnotationElement = function (_LinkAnnotationElemen) {408 _inherits(PushButtonWidgetAnnotationElement, _LinkAnnotationElemen);409 function PushButtonWidgetAnnotationElement() {410 _classCallCheck(this, PushButtonWidgetAnnotationElement);411 return _possibleConstructorReturn(this, (PushButtonWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(PushButtonWidgetAnnotationElement)).apply(this, arguments));412 }413 _createClass(PushButtonWidgetAnnotationElement, [{414 key: 'render',415 value: function render() {416 var container = _get(PushButtonWidgetAnnotationElement.prototype.__proto__ || Object.getPrototypeOf(PushButtonWidgetAnnotationElement.prototype), 'render', this).call(this);417 container.className = 'buttonWidgetAnnotation pushButton';418 return container;419 }420 }]);421 return PushButtonWidgetAnnotationElement;422}(LinkAnnotationElement);423var ChoiceWidgetAnnotationElement = function (_WidgetAnnotationElem4) {...
Using AI Code Generation
1var wptools = require('wptools');2var options = {3};4wptools.page(options).then(function(page) {5 var infobox = page.infobox();6 console.log(infobox);7 var infobox = page.infobox('PushButtonWidgetAnnotationElement');8 console.log(infobox);9});
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4 if (err) {5 console.log(err);6 } else {7 console.log('Test Results: ' + data.data.summary);8 }9});10var wpt = require('webpagetest');11var options = {12};13 if (err) {14 console.log(err);15 } else {16 console.log('Test Results: ' + data.data.summary);17 var testId = data.data.testId;18 wpt.getTestResults(testId, function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log('Test Results: ' + data.data.summary);23 }24 });25 }26});27var wpt = require('webpagetest
Using AI Code Generation
1var PushButtonWidgetAnnotationElement = require('wptext.js').PushButtonWidgetAnnotationElement;2var pushButtonWidget = new PushButtonWidgetAnnotationElement();3pushButtonWidget.update();4pushButtonWidget.reset();5function PushButtonWidgetAnnotationElement() {6 this.update = function () {7 console.log("update");8 };9 this.reset = function () {10 console.log("reset");11 };12}13module.exports = {14};15module.exports = {16};17exports.PushButtonWidgetAnnotationElement = PushButtonWidgetAnnotationElement;18module.exports.PushButtonWidgetAnnotationElement = PushButtonWidgetAnnotationElement;19module.exports = PushButtonWidgetAnnotationElement;20exports.PushButtonWidgetAnnotationElement = PushButtonWidgetAnnotationElement;21module.exports.PushButtonWidgetAnnotationElement = PushButtonWidgetAnnotationElement;22module.exports = PushButtonWidgetAnnotationElement;23module.exports = PushButtonWidgetAnnotationElement;24exports.PushButtonWidgetAnnotationElement = PushButtonWidgetAnnotationElement;
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4wpt.runTest(options, function(err, data) {5 console.log(data);6 var testId = data.data.testId;7 var options = {8 };9 wpt.getTestResults(options, function(err, data) {10 console.log(data);11 });12});13var wpt = require('webpagetest');14var options = {15};16wpt.runTest(options, function(err, data) {17 console.log(data);18 var testId = data.data.testId;19 var options = {20 };21 wpt.getTestResults(options, function(err, data) {22 console.log(data);23 });24});25var wpt = require('webpagetest');26var options = {
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('TestPage');3page.on('ready', function() {4 var button = page.addPushButtonWidgetAnnotationElement({5 });6 var button2 = page.addPushButtonWidgetAnnotationElement({7 });8 var button3 = page.addPushButtonWidgetAnnotationElement({9 });10 var button4 = page.addPushButtonWidgetAnnotationElement({11 });12 var button5 = page.addPushButtonWidgetAnnotationElement({13 });14 var button6 = page.addPushButtonWidgetAnnotationElement({15 });16 var button7 = page.addPushButtonWidgetAnnotationElement({17 });
Using AI Code Generation
1function test() {2 var wptd = new PushButtonWidgetAnnotationElement();3 if (wptd.getPushButtonWidgetAnnotationElement) {4 postMessage("PushButtonWidgetAnnotationElement method exists");5 }6}7test();8function test() {9 var wptd = new PushButtonWidgetAnnotationElement();10 if (wptd.getPushButtonWidgetAnnotationElement) {11 postMessage("PushButtonWidgetAnnotationElement method exists");12 }13}14test();15function test() {16 var wptd = new PushButtonWidgetAnnotationElement();17 if (wptd.getPushButtonWidgetAnnotationElement) {18 postMessage("PushButtonWidgetAnnotationElement method exists");19 }20}21test();22function test() {23 var wptd = new PushButtonWidgetAnnotationElement();24 if (wptd.getPushButtonWidgetAnnotationElement) {25 postMessage("PushButtonWidgetAnnotationElement method exists");26 }27}28test();29function test() {30 var wptd = new PushButtonWidgetAnnotationElement();31 if (wptd.getPushButtonWidgetAnnotationElement) {32 postMessage("PushButtonWidgetAnnotationElement method exists");33 }34}35test();36function test() {37 var wptd = new PushButtonWidgetAnnotationElement();38 if (wptd.getPushButtonWidgetAnnotationElement) {39 postMessage("PushButtonWidgetAnnotationElement method exists");40 }41}42test();43function test() {44 var wptd = new PushButtonWidgetAnnotationElement();45 if (wptd.getPushButtonWidgetAnnotationElement) {46 postMessage("PushButtonWidgetAnnotationElement method
Using AI Code Generation
1var doc = this;2var page = doc.getPageBox("0");3var widget = page.getWidget("Pushbutton");4widget.setValue("Pushbutton");5widget.setCaption("Pushbutton");6widget.setHighlightingMode("Push");7widget.setDown(true);8widget.setDown(false);9widget.setDown(true);10widget.setDown(false);11var doc = this;12var page = doc.getPageBox("0");13var widget = page.getWidget("Radio");14widget.setValue("Radio");15widget.setCaption("Radio");16widget.setHighlightingMode("Push");17widget.setDown(true);18widget.setDown(false);19widget.setDown(true);20widget.setDown(false);21var doc = this;22var page = doc.getPageBox("0");23var widget = page.getWidget("Checkbox");24widget.setValue("Checkbox");25widget.setCaption("Checkbox");26widget.setHighlightingMode("Push");27widget.setDown(true);28widget.setDown(false);29widget.setDown(true);30widget.setDown(false);31var doc = this;32var page = doc.getPageBox("0");33var widget = page.getWidget("Combobox");34widget.setValue("Combobox");35widget.setCaption("Combobox");36widget.setHighlightingMode("Push");37widget.setDown(true);38widget.setDown(false);39widget.setDown(true);40widget.setDown(false);41var doc = this;42var page = doc.getPageBox("0");43var widget = page.getWidget("Listbox");44widget.setValue("Listbox");45widget.setCaption("Listbox");46widget.setHighlightingMode("Push");47widget.setDown(true);48widget.setDown(false);49widget.setDown(true);50widget.setDown(false);51var doc = this;52var page = doc.getPageBox("0");53var widget = page.getWidget("Textfield");54widget.setValue("Textfield");55widget.setCaption("Textfield");56widget.setHighlightingMode("Push");57widget.setDown(true);58widget.setDown(false);59widget.setDown(true);
Using AI Code Generation
1var page = this.getPageBox(0);2var button = new PushButtonWidgetAnnotationElement();3button.init(page, 100, 100, 200, 200);4page.addAnnotation(button);5page.draw();6var page = this.getPageBox(0);7var button = new PushButtonWidgetAnnotationElement();8button.init(page, 100, 100, 200, 200);9page.addAnnotation(button);10page.draw();11var page = this.getPageBox(0);12var button = new PushButtonWidgetAnnotationElement();13button.init(page, 100, 100, 200, 200);14page.addAnnotation(button);15page.draw();16var page = this.getPageBox(0);17var button = new PushButtonWidgetAnnotationElement();18button.init(page, 100, 100, 200, 200);19page.addAnnotation(button);20page.draw();21var page = this.getPageBox(0);22var button = new PushButtonWidgetAnnotationElement();
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!!