How to use isIFrameElement method in wpt

Best JavaScript code snippet using wpt

helper.context-menus.js

Source:helper.context-menus.js Github

copy

Full Screen

1/* CONTEXT MENU FUNCTIONALITY */2 setupContextMenu = function(args) {3 if ( typeof args != 'object' )4 return false;5 var args = $.extend(true, {}, { 6 isIframeElement: true7 }, args);8 /* 9 ### Argument Example setup### 10 {11 id: 'inspector',12 elements: '.wrapper',13 title: function(event) { //Can be string or function14 return 'Example Wrapper';15 },16 contentsCallback: function(contextMenu, event) { },17 onItemClick: function(contextMenu, originalRightClickEvent) { },18 onBeforeShow: function(event) { },19 onHide: function(contextMenu) { },20 isIframeElement: true21 }22 */23 /* Unbind any existing of the same context menu */24 deactivateContextMenu(args.id);25 /* Bind the right click on the element(s) */26 var contextMenuOpenEvent = !Headway.touch ? 'contextmenu.contextMenu' + args.id : 'taphold.contextMenu' + args.id;27 /* Get to binding! */28 if ( args.isIframeElement ) {29 $iDocument().on(contextMenuOpenEvent, args.elements, function(event, eventArgs) {30 event.data = eventArgs;31 contextMenuCreator(args, event, true);32 });33 } else {34 $(document).on(contextMenuOpenEvent, args.elements, function(event, eventArgs) {35 event.data = eventArgs;36 contextMenuCreator(args, event, false);37 });38 }39 /* Bind click on anything else to close */40 var clickToClose = function(event) {41 if ( (event.which !== 0 && event.which !== 1) || $(event.originalEvent.target).parents('#context-menu-' + args.id).length )42 return;43 var contextMenu = $('#context-menu-' + args.id);44 if ( typeof args.onHide == 'function' )45 args.onHide.apply(contextMenu);46 contextMenu.remove();47 }48 /* Bind mouseup to close context menu normally and tap for touch support */49 var contextMenuCloseEvent = !Headway.touch ? 'click' : 'touchstart';50 $('body').on(contextMenuCloseEvent + '.contextMenu' + args.id, clickToClose);51 $i('body').on(contextMenuCloseEvent + '.contextMenu' + args.id, clickToClose);52 /* End binding click on anything to close */53 }54 deactivateContextMenu = function(id) {55 $(document).off('.contextMenu' + id);56 $iDocument().off('.contextMenu' + id);57 $('body').off('.contextMenu' + id);58 $i('body').off('.contextMenu' + id);59 return true;60 }61 contextMenuCreator = function(args, event, iframe) {62 event.stopPropagation(); /* Keep other context menus from opening */63 if ( typeof args != 'object' )64 return false;65 /* Hide any other context menus */66 $('.context-menu').remove();67 /* Create context menu */68 var contextMenuTitle = typeof args.title == 'function' ? args.title.apply(undefined, [event]) : args.title;69 var contextMenu = $('<ul id="context-menu-' + args.id + '" class="context-menu"><h3>' + contextMenuTitle + '</h3></ul>');70 /* Trigger onShow callback */71 if ( typeof args.onShow == 'function' )72 args.onShow.apply(contextMenu, [event]);73 /* Fire contentsCallback to insert items */74 args.contentsCallback.apply(contextMenu, [event]);75 /* Bind click of items */76 var originalRightClickEvent = event;77 var contextMenuItemClick = function(event) {78 if ( typeof args.onItemClick == 'function' )79 args.onItemClick.apply(this, [contextMenu, originalRightClickEvent]);80 if ( typeof args.onHide == 'function' )81 args.onHide.apply(contextMenu);82 contextMenu.remove();83 };84 var contextMenuClickEvent = !Headway.touch ? 'click' : 'tap';85 contextMenu.delegate('span', contextMenuClickEvent, contextMenuItemClick);86 /* Context menu positioning */87 if ( typeof event.originalEvent != 'undefined' && typeof event.originalEvent.clientX != 'undefined' ) {88 var contextMenuX = event.originalEvent.clientX;89 var contextMenuY = event.originalEvent.clientY + 40;90 } else {91 var contextMenuX = event.data.x;92 var contextMenuY = event.data.y + 40;93 }94 contextMenu.css({95 left: contextMenuX,96 top: contextMenuY97 });98 /* Delegate hover event on context menu sub menus for the lovely window right bleeding */99 contextMenu.delegate('li:has(ul) span', 'hover', function() {100 var childMenu = $(this).siblings('ul');101 var childMenuOffset = childMenu.offset();102 if ( !childMenuOffset || ((childMenu.offset().left + childMenu.outerWidth()) < $('iframe.content').width()) )103 return;104 childMenu.css('right', childMenu.css('left'));105 childMenu.css('left', 'auto'); 106 childMenu.css('width', '190px'); 107 childMenu.css('zIndex', '999999'); 108 });109 /* Add context menu to iframe */110 contextMenu.appendTo($('body'));111 /* Context Menu overflow */112 /* X overflow */113 if ( (contextMenuX + contextMenu.outerWidth()) > $(window).width() ) {114 var overflow = $(window).width() - (contextMenuX + contextMenu.outerWidth());115 contextMenu.css('left', contextMenuX + overflow - 20);116 }117 /* Y overflow */118 if ( (contextMenuY + contextMenu.outerHeight()) > $(window).height() ) {119 var overflow = $(window).height() - (contextMenuY + contextMenu.outerHeight());120 contextMenu.css('top', contextMenuY + overflow - 20);121 }122 /* End Context Menu Overflow */123 /* Prevent regular context menu from opening */124 event.preventDefault();125 return false;126 }...

Full Screen

Full Screen

shadow-dom.js

Source:shadow-dom.js Github

copy

Full Screen

1function createShadowRoot()2{3 var children = Array.prototype.slice.call(arguments);4 if ((children[0] instanceof Object) && !(children[0] instanceof Node))5 return {'isShadowRoot': true,6 'attributes': children[0],7 'children': children.slice(1)};8 return {'isShadowRoot': true,9 'children': children};10}11// This function can take optional child elements, which might be a result of createShadowRoot(), as arguments[2:].12function createDOM(tagName, attributes)13{14 var element = document.createElement(tagName);15 for (var name in attributes)16 element.setAttribute(name, attributes[name]);17 var childElements = Array.prototype.slice.call(arguments, 2);18 for (var i = 0; i < childElements.length; ++i) {19 var child = childElements[i];20 if (child.isShadowRoot) {21 var shadowRoot = element.createShadowRoot();22 if (child.attributes) {23 for (var attribute in child.attributes) {24 // Shadow Root does not have setAttribute.25 shadowRoot[attribute] = child.attributes[attribute];26 }27 }28 for (var j = 0; j < child.children.length; ++j)29 shadowRoot.appendChild(child.children[j]);30 } else31 element.appendChild(child);32 }33 return element;34}35function isShadowHost(node)36{37 return window.internals.oldestShadowRoot(node);38}39function isShadowRoot(node)40{41 return node instanceof window.WebKitShadowRoot;42}43function isIframeElement(element)44{45 return element && element.nodeName == 'IFRAME';46}47// You can spefify youngerShadowRoot by consecutive slashes.48// See LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-root.html for actual usages.49function getNodeInShadowTreeStack(path)50{51 var ids = path.split('/');52 var node = document.getElementById(ids[0]);53 for (var i = 1; node != null && i < ids.length; ++i) {54 if (isIframeElement(node)) {55 node = node.contentDocument.getElementById(ids[i]);56 continue;57 }58 if (isShadowRoot(node))59 node = internals.youngerShadowRoot(node);60 else if (internals.oldestShadowRoot(node))61 node = internals.oldestShadowRoot(node);62 else63 return null;64 if (ids[i] != '')65 node = node.getElementById(ids[i]);66 }67 return node;68}69function dumpNode(node)70{71 if (!node)72 return 'null';73 if (node.id)74 return '#' + node.id;75 return '' + node;76}77function dumpNodeList(nodeList) {78 var result = "";79 var length = nodeList.length;80 for (var i = 0; i < length; i++)81 result += dumpNode(nodeList[i]) + ", ";82 result += "length: " + length;83 return result;84}85function innermostActiveElement(element)86{87 element = element || document.activeElement;88 if (isIframeElement(element)) {89 if (element.contentDocument.activeElement)90 return innermostActiveElement(element.contentDocument.activeElement);91 return element;92 }93 if (isShadowHost(element)) {94 var shadowRoot = window.internals.oldestShadowRoot(element);95 while (shadowRoot) {96 if (shadowRoot.activeElement)97 return innermostActiveElement(shadowRoot.activeElement);98 shadowRoot = window.internals.youngerShadowRoot(shadowRoot);99 }100 }101 return element;102}103function isInnermostActiveElement(id)104{105 var element = getNodeInShadowTreeStack(id);106 if (!element) {107 debug('FAIL: There is no such element with id: '+ from);108 return false;109 }110 if (element == innermostActiveElement())111 return true;112 debug('Expected innermost activeElement is ' + id + ', but actual innermost activeElement is ' + dumpNode(innermostActiveElement()));113 return false;114}115function shouldNavigateFocus(from, to, direction)116{117 debug('Should move from ' + from + ' to ' + to + ' in ' + direction);118 var fromElement = getNodeInShadowTreeStack(from);119 if (!fromElement) {120 debug('FAIL: There is no such element with id: '+ from);121 return;122 }123 fromElement.focus();124 if (!isInnermostActiveElement(from)) {125 debug('FAIL: Can not be focused: '+ from);126 return;127 }128 if (direction == 'forward')129 navigateFocusForward();130 else131 navigateFocusBackward();132 if (isInnermostActiveElement(to))133 debug('PASS');134 else135 debug('FAIL');136}137function navigateFocusForward()138{139 eventSender.keyDown('\t');140}141function navigateFocusBackward()142{143 eventSender.keyDown('\t', ['shiftKey']);144}145function testFocusNavigationFowrad(elements)146{147 for (var i = 0; i + 1 < elements.length; ++i)148 shouldNavigateFocus(elements[i], elements[i + 1], 'forward');149}150function testFocusNavigationBackward(elements)151{152 for (var i = 0; i + 1 < elements.length; ++i)153 shouldNavigateFocus(elements[i], elements[i + 1], 'backward');...

Full Screen

Full Screen

existing-iframe.service.ts

Source:existing-iframe.service.ts Github

copy

Full Screen

...5export class IFrameService {6 constructor(@Inject(DOCUMENT) private readonly doc: any, private loggerService: LoggerService) {}7 getExistingIFrame(identifier: string): HTMLIFrameElement | null {8 const iFrameOnParent = this.getIFrameFromParentWindow(identifier);9 if (this.isIFrameElement(iFrameOnParent)) {10 return iFrameOnParent;11 }12 const iFrameOnSelf = this.getIFrameFromWindow(identifier);13 if (this.isIFrameElement(iFrameOnSelf)) {14 return iFrameOnSelf;15 }16 return null;17 }18 addIFrameToWindowBody(identifier: string, configId: string): HTMLIFrameElement {19 const sessionIframe = this.doc.createElement('iframe');20 sessionIframe.id = identifier;21 sessionIframe.title = identifier;22 this.loggerService.logDebug(configId, sessionIframe);23 sessionIframe.style.display = 'none';24 this.doc.body.appendChild(sessionIframe);25 return sessionIframe;26 }27 private getIFrameFromParentWindow(identifier: string): HTMLIFrameElement | null {28 try {29 const iFrameElement = this.doc.defaultView.parent.document.getElementById(identifier);30 if (this.isIFrameElement(iFrameElement)) {31 return iFrameElement;32 }33 return null;34 } catch (e) {35 return null;36 }37 }38 private getIFrameFromWindow(identifier: string): HTMLIFrameElement | null {39 const iFrameElement = this.doc.getElementById(identifier);40 if (this.isIFrameElement(iFrameElement)) {41 return iFrameElement;42 }43 return null;44 }45 private isIFrameElement(element: HTMLElement | null): element is HTMLIFrameElement {46 return !!element && element instanceof HTMLIFrameElement;47 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptUtils = require('wptUtils');2if (wptUtils.isIFrameElement()) {3 console.log("This is an iframe element");4} else {5 console.log("This is not an iframe element");6}7module.exports = {8 isIFrameElement: function() {9 return window.self !== window.top;10 }11}

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful