Best JavaScript code snippet using best
codeless_postMessages.js
Source:codeless_postMessages.js
1( function( $ ) {2 var CL_POSTMESSAGE = window.CL_POSTMESSAGE || {};3 window.CL_POSTMESSAGE = CL_POSTMESSAGE;4CL_POSTMESSAGE.custom_button_font = function(to){5}6CL_POSTMESSAGE.logo_font_text = function(to){7 $('.cl-logo__font').html(to);8}9CL_POSTMESSAGE.header_menu_vertical_dividers = function(to){10 if(to){11 $('.header_container').addClass('vertical-dividers');12 }else{13 $('.header_container').removeClass('vertical-dividers');14 }15}16 17CL_POSTMESSAGE.custom_css = function(to){18 if ( ! $( '#codeless_customizer_custom_css').size() ) {19 $( 'head' ).append( '<style id="codeless_customizer_custom_css"></style>' );20 }21 $( '#codeless_customizer_custom_css').text( to );22};23CL_POSTMESSAGE.header_sticky = function(to){24 if( to ){25 var contentColor = parent.wp.customize.control('header_sticky_content').setting.get()26 $('.header_container').addClass('cl-header-sticky');27 $('.header_container.cl-header-sticky').attr( 'data-sticky-content-color', contentColor );28 CL_FRONT.initHeaderSticky();29 }else{30 $('.header_container').removeClass('cl-header-sticky');31 CL_FRONT.initHeaderSticky();32 }33};34CL_POSTMESSAGE.header_sticky_content = function(to){35 $('.header_container.cl-header-sticky').attr( 'data-sticky-content-color', to );36 CL_FRONT.initHeaderSticky();37};38CL_POSTMESSAGE.header_forced_center = function(to){39 if( to )40 $('body').addClass('cl-header-forced-center');41 else42 $('body').removeClass('cl-header-forced-center');43};44CL_POSTMESSAGE.header_sticky_shadow = function(to){45 if( to )46 $(".header_container.cl-header-sticky").addClass('cl-header-sticky-shadow');47 else48 $(".header_container.cl-header-sticky").removeClass('cl-header-sticky-shadow');49}50CL_POSTMESSAGE.header_layout = function(to, setting){51 $(".header_container").removeClass (function (index, css) {52 return (css.match (/\bheader-\S+/g) || []).join(' ');53 });54 55 $('.header_container').addClass('header-'+to);56 57 $("body").removeClass (function (index, css) {58 return (css.match (/\bheader-\S+/g) || []).join(' ');59 });60 61 $('body').addClass('header-layout-'+to);62 63 if(to == 'left' || to == 'right'){64 $('.header_container').css('width', '');65 $('.header_container > .main').css('height', '').css('line-height', '');66 $('body').addClass('cl-header-side');67 CL_POSTMESSAGE.viewportPosition()68 }69 70 if(to == 'top' || to == 'bottom'){71 $('.header_container').css('width', '100%');72 CL_POSTMESSAGE.viewportPosition()73 }74 75};76CL_POSTMESSAGE.logo_height = function(to){77 console.log(to);78 $('.header_container').find('#logo img').css('height', to + 'px');79}80CL_POSTMESSAGE.header_shadow = function(to){81 if( to )82 $(".header_container").addClass('menu-with_shadow');83 else84 $(".header_container").removeClass('menu-with_shadow');85}86CL_POSTMESSAGE.header_container = function(to){87 if( to == 'container-fluid'){88 $('.cl-header__container').addClass('container-fluid').removeClass('container');89 }else{90 $('.cl-header__container').addClass('container').removeClass('container-fluid');91 }92}93CL_POSTMESSAGE.header_menu_style_full = function(to, setting){94 95 if(to == 1)96 $(".header_container").addClass('menu-full-style').removeClass('menu-text-style');97 else98 $(".header_container").removeClass('menu-full-style').addClass('menu-text-style');99 100 CL_POSTMESSAGE.header_menu_border_width(parent.wp.customize.control('header_menu_border_width').setting.get());101 102}103CL_POSTMESSAGE.transparent_header = function(to){104 if(to){105 $('.header_container').addClass( 'cl-transparent' );106 $('body').addClass('cl-header-transparent');107 CL_FRONT.initHeaderSticky();108 }else{109 $('.header_container').removeClass( 'cl-transparent' );110 $('body').removeClass('cl-header-transparent');111 CL_FRONT.initHeaderSticky();112 }113}114CL_POSTMESSAGE.header_color = function(to){115 if(to == 'light'){116 $('.header_container').addClass( 'cl-header-light' );117 }else{118 $('.header_container').removeClass( 'cl-header-light' );119 }120}121CL_POSTMESSAGE.header_design = function(to, setting){122 123 if(!_.isObject(to))124 to = JSON.parse(to);125 126 _.each(to, function(v, index){127 if(to[index] == '')128 to[index] = 0;129 });130 131 $('.cl-header__row--main').css(to);132 133 134 CL_POSTMESSAGE.viewportPosition();135 136};137CL_POSTMESSAGE.header_design_top = function(to, setting){138 139 if(!_.isObject(to))140 to = JSON.parse(to);141 142 _.each(to, function(v, index){143 if(to[index] == '')144 to[index] = 0;145 });146 147 $('.cl-header__row--top').css(to);148 149 150 CL_POSTMESSAGE.viewportPosition();151 152};153CL_POSTMESSAGE.header_design_extra = function(to, setting){154 155 if(!_.isObject(to))156 to = JSON.parse(to);157 console.log(to);158 _.each(to, function(v, index){159 if(to[index] == '')160 to[index] = 0;161 });162 163 $('.cl-header__row--extra').css(to);164 165 166 CL_POSTMESSAGE.viewportPosition();167 168};169CL_POSTMESSAGE.footer_design = function(to, setting){170 171 if(!_.isObject(to))172 to = JSON.parse(to);173 174 _.each(to, function(v, index){175 if(to[index] == '')176 to[index] = 0;177 });178 179 $('footer#colophon .cl-footer__main').css(to);180 181 182 CL_POSTMESSAGE.viewportPosition();183 184};185CL_POSTMESSAGE.boxed_layout = function(to, setting){186 if( to )187 $("#wrapper").addClass('cl-boxed-layout');188 else189 $("#wrapper").removeClass('cl-boxed-layout');190}191CL_POSTMESSAGE.button_style = function(to, setting){192 $(".cl-btn").removeClass (function (index, css) {193 return (css.match (/\bbtn-style-\S+/g) || []).join(' ');194 });195 $(".cl-btn").addClass( 'btn-style-' + to);196}197CL_POSTMESSAGE.blog_pagination_align = function(to, setting){198 $(".cl-blog-pagination .cl-pagination").removeClass (function (index, css) {199 return (css.match (/\bcl-pagination-align-\S+/g) || []).join(' ');200 });201 $(".cl-blog-pagination .cl-pagination").addClass( 'cl-pagination-align-' + to);202}203CL_POSTMESSAGE.button_layout = function(to, setting){204 $(".cl-btn").removeClass (function (index, css) {205 return (css.match (/\bbtn-layout-\S+/g) || []).join(' ');206 });207 $(".cl-btn").addClass( 'btn-layout-' + to);208}209CL_POSTMESSAGE.button_font = function(to, setting){210 $(".cl-btn").removeClass (function (index, css) {211 return (css.match (/\bbtn-font-\S+/g) || []).join(' ');212 });213 $(".cl-btn").addClass( 'btn-font-' + to);214}215CL_POSTMESSAGE.blog_align = function(to, setting){216 $(".blog-entries").removeClass (function (index, css) {217 return (css.match (/\bblog_align_\S+/g) || []).join(' ');218 });219 220 $('.blog-entries').addClass('blog_align_' + to);221}222CL_POSTMESSAGE.header_width = function(to, setting){223 $('.header_container').css('width', to+'px');224 CL_POSTMESSAGE.viewportPosition();225}226CL_POSTMESSAGE.header_boxed = function(to, setting){227 if(to == 1)228 $('.header_container:not(.cl-added-from-meta)').addClass('boxed-style');229 else 230 $('.header_container:not(.cl-added-from-meta)').removeClass('boxed-style');231 232 CL_POSTMESSAGE.viewportPosition();233}234CL_POSTMESSAGE.header_menu_style = function(to, setting){235 $(".header_container").removeClass (function (index, css) {236 return (css.match (/\bmenu_style-\S+/g) || []).join(' ');237 });238 239 $('.header_container').addClass('menu_style-'+to);240}241CL_POSTMESSAGE.header_menu_border_width = function(to, setting){242 243 if($('.header_container').hasClass('menu-full-style'))244 selector = '.header_container nav > ul > li';245 else if($('.header_container').hasClass('menu-text-style'))246 selector = '.header_container nav > ul > li > a';247 248 249 if($('.header_container').hasClass('menu_style-border_top') )250 $(selector).css('border-top-width', to+'px').css('border-bottom-width', '').css('border-left-width', '').css('border-right-width', '');251 252 if($('.header_container').hasClass('menu_style-border_bottom'))253 $(selector).css('border-bottom-width', to+'px').css('border-top-width', '').css('border-left-width', '').css('border-right-width', '');254 if($('.header_container').hasClass('menu_style-border_left'))255 $(selector).css('border-left-width', to+'px').css('border-top-width', '').css('border-bottom-width', '').css('border-right-width', '');256 257 if($('.header_container').hasClass('menu_style-border_right') )258 $(selector).css('border-right-width', to+'px').css('border-top-width', '').css('border-bottom-width', '').css('border-left-width', '');259}260CL_POSTMESSAGE.footer_fullwidth = function(to, setting){261 if(to){262 $('footer#colophon .footer-content').removeClass('container').addClass('container-fluid');263 $('#copyright .copyright-content').removeClass('container').addClass('container-fluid');264 }else{265 $('footer#colophon .footer-content').removeClass('container-fluid').addClass('container');266 $('#copyright .copyright-content').removeClass('container-fluid').addClass('container');267 }268}269CL_POSTMESSAGE.footer_centered_content = function(to){270 if(to){271 $('.footer-content-row > .footer-widget').addClass('center-column');272 }else{273 $('.footer-content-row > .footer-widget').removeClass('center-column');274 }275}276CL_POSTMESSAGE.footer_reveal_effect = function(to){277 if(to){278 $('#footer-wrapper').addClass('reveal');279 CL_FRONT.footerReveal();280 }else{281 $('#footer-wrapper').removeClass('reveal');282 $('#main').css('margin-bottom', '0');283 }284}285CL_POSTMESSAGE.layout_modern = function(to, setting){286 287 if(to){288 $('#content').addClass( 'cl-layout-modern' );289 $('.cl-layout-modern-bg').css('display', 'block');290 }else{291 $('#content').removeClass( 'cl-layout-modern' );292 $('.cl-layout-modern-bg').css('display', 'none');293 }294 295}296CL_POSTMESSAGE.portfolio_distance = function(to, setting){297 $( '#portfolio-entries .portfolio_item' ).css({ padding: to+'px', opacity: '0.1' });298 299 CL_FRONT.isotopePortfolioGrid();300 $( '#portfolio-entries .portfolio_item' ).css({ opacity: '1' });301}302CL_POSTMESSAGE.viewportPosition = function(){303 304 var inner_width = $('.header_container').width();305 var pad = 0;306 307 var header_pos = $('.header_container').hasClass('header-left') ? 'left' : ($('.header_container').hasClass('header-right') ? 'right' : '');308 if(header_pos == 'left'){309 $('#viewport').css('padding-left', (inner_width+pad)+'px').css('padding-right', '0px');310 }else if(header_pos == 'right'){311 $('#viewport').css('padding-right', (inner_width+pad)+'px').css('padding-left', '0px');312 }else{313 $('#viewport').css('padding-right', '0px').css('padding-left', '0px');314 315 }316 317 if($('.header_container').hasClass('boxed-style')){318 $('#viewport').css('padding-right', '0px').css('padding-left', '0px');319 }320 321}322CL_POSTMESSAGE.generate_font_css = function( option, to ){323 console.log(cl_options);324 if( typeof cl_options[option] === 'undefined' )325 return;326 var css = cl_options[option].join(', ') +' {';327 $.each(to, function(property, value){328 if(property != 'variant' && property != 'subsets')329 css += ' '+property+' : '+value+' !important;';330 331 if(property == 'variant'){332 css += variantCss(value);333 }334 });335 336 css += '}';337 console.log(css);338 339 if ( '' !== css ) {340 // Make sure we have a stylesheet with the defined ID.341 // If we don't then add it.342 if ( ! $( '#codeless_customizer_'+option).size() ) {343 $( 'head' ).append( '<style id="codeless_customizer_'+option+'"></style>' );344 }345 $( '#codeless_customizer_'+option).text( css );346 }347 348 if( ! _.isUndefined( to['font-family'] ) && ! _.isEmpty( to['font-family'] ) )349 WebFont.load({350 google: { 351 families: [to['font-family']] 352 } 353 }); 354 355 function variantCss(variant){356 var css = '';357 358 var weight = variant.replace('italic', '');359 if(weight == '' || weight == 'regular')360 weight = 400;361 362 var is_italic = false;363 if(variant.indexOf('italic') != -1 ){364 is_italic = true;365 }366 css += ' font-weight :'+weight+' !important;';367 if(is_italic)368 css += ' font-style : italic !important;';369 370 return css;371 }372}373/* Post Meta */374CL_POSTMESSAGE.meta_transparent_header = function(to){375 if(to == 'transparent' ){376 $('.header_container').addClass( 'cl-transparent' );377 $('body').addClass('cl-header-transparent');378 CL_FRONT.initHeaderSticky();379 }else if( to == 'no_transparent' || to == 'default' ){380 $('.header_container').removeClass( 'cl-transparent' );381 $('body').removeClass('cl-header-transparent');382 CL_FRONT.initHeaderSticky();383 }384}385CL_POSTMESSAGE.meta_header_color = function(to){386 if(to == 'light'){387 $('.header_container').addClass( 'cl-header-light' );388 }else{389 $('.header_container').removeClass( 'cl-header-light' );390 }391}392CL_POSTMESSAGE.meta_page_bg_color = function(to){393 $('#content').css('background-color', to);394}395CL_POSTMESSAGE.meta_fullwidth_content = function(to){396 397 if(to)398 $('#content .inner-content').removeClass('container').addClass('container-fluid');399 else400 $('#content .inner-content').removeClass('container-fluid').addClass('container');401}402// Portfolio403CL_POSTMESSAGE.meta_portfolio_columns = function(to){404 $( '#portfolio-entries' ).attr( 'data-grid-cols', to );405 CL_FRONT.isotopePortfolioGrid();406}407CL_POSTMESSAGE.meta_portfolio_layout = function(to){408 $("#portfolio-entries").removeClass (function (index, css) {409 return (css.match (/\bportfolio-layout-\S+/g) || []).join(' ');410 });411 $("#portfolio-entries").addClass( 'portfolio-layout-' + to);412 setTimeout( function(){413 CL_FRONT.isotopePortfolioGrid();414 }, 100);415}416CL_POSTMESSAGE.meta_portfolio_style = function(to){417 418 $("#portfolio-entries").removeClass (function (index, css) { 419 return (css.match (/\bportfolio-style-\S+/g) || []).join(' ');420 });421 $("#portfolio-entries").addClass( 'portfolio-style-' + to);422 423 setTimeout( function(){424 CL_FRONT.isotopePortfolioGrid();425 }, 100);426 427}428CL_POSTMESSAGE.meta_portfolio_boxed = function(to){429 if(to)430 $( '#portfolio-entries .portfolio_item' ).addClass('portfolio_boxed');431 else432 $( '#portfolio-entries .portfolio_item' ).removeClass('portfolio_boxed');433}434CL_POSTMESSAGE.meta_staff_position = function(to, value, postType, postID){435 if( $('#cl_team_item-'+postID).length > 0 ){436 var $position = $( '.team-position', '#cl_team_item-'+postID);437 if( $position.length > 0 ){438 $position.html(to);439 }440 }441}442CL_POSTMESSAGE.meta_post_title = function(to, value, postType, postID){443 if( postType == 'portfolio' && $('#cl-portfolio-item-'+postID).length > 0 ){444 var $title = $( '.cl-portfolio-title', '#cl-portfolio-item-'+postID);445 if( $title.length > 0 ){446 $title.html(to.post_title);447 }448 }449 if( postType == 'staff' && $('#cl_team_item-'+postID).length > 0 ){450 var $title = $( '.team-name', '#cl_team_item-'+postID);451 if( $title.length > 0 ){452 $title.html(to.post_title);453 }454 }455 console.log($('#cl_testimonial_item_'+postID));456 if( postType == 'testimonial' && $('#cl_testimonial_item_'+postID).length > 0 ){457 var $title = $( '.title', '#cl_testimonial_item_'+postID);458 if( $title.length > 0 ){459 $title.html(to.post_title);460 }461 }462 463}464CL_POSTMESSAGE.meta_post_content = function(to, value, postType, postID){465 if( postType == 'staff' && $('#cl_team_item-'+postID).length > 0 ){466 var $desc = $( '.team-desc', '#cl_team_item-'+postID);467 if( $desc.length > 0 ){468 $desc.html('- '+to.post_content);469 }470 }471 if( postType == 'testimonial' && $('#cl_testimonial_item_'+postID).length > 0 ){472 var $title = $( '.content', '#cl_testimonial_item_'+postID);473 if( $title.length > 0 ){474 $title.html('"'+to.post_content+'"');475 }476 }477 478}479CL_POSTMESSAGE.meta_page_inner_content_padding_top = function( to ){480 $( '#content' ).css('paddingTop', to+'px');481}482 483if(!_.isUndefined(parent.wp.customize.settings.settings)){484 485 _.each(parent.wp.customize.settings.settings, function(key, setting){486 if(!_.isUndefined(CL_POSTMESSAGE[setting]) ){487 wp.customize( setting, function(value){488 value.bind( function(to){489 490 if(!_.isUndefined(CL_POSTMESSAGE[setting]))491 CL_POSTMESSAGE[setting](to, value);492 });493 });494 }495 496 });497}...
postmessage.js
Source:postmessage.js
...79 msg.errback = pm._callback(o.error);80 }81 if (("postMessage" in target) && !o.hash) {82 pm._bind();83 target.postMessage(JSON.stringify(msg), o.origin || '*');84 }85 else {86 pm.hash._bind();87 pm.hash.send(o, msg);88 }89 },90 bind: function(type, fn, origin, hash, async_reply) {91 pm._replyBind ( type, fn, origin, hash, async_reply );92 },93 _replyBind: function(type, fn, origin, hash, isCallback) {94 if (("postMessage" in window) && !hash) {95 pm._bind();96 }97 else {...
jquery.ba-postmessage.js
Source:jquery.ba-postmessage.js
...74 // using the jQuery.param method.75 // 76 // Usage:77 // 78 // > jQuery.postMessage( message, target_url [, target ] );79 // 80 // Arguments:81 // 82 // message - (String) A message to be passed to the other frame.83 // message - (Object) An object to be serialized into a params string, using84 // the jQuery.param method.85 // target_url - (String) The URL of the other frame this window is86 // attempting to communicate with. This must be the exact URL (including87 // any query string) of the other window for this script to work in88 // browsers that don't support window.postMessage.89 // target - (Object) A reference to the other frame this window is90 // attempting to communicate with. If omitted, defaults to `parent`.91 // 92 // Returns:...
Bot.ts
Source:Bot.ts
...56 this.game.free();57 }58 init() {59 const postMessage = this.postMessage;60 postMessage({61 type: "state",62 gameState: this.getState(),63 });64 postMessage({65 type: "possibleMoves",66 possibleMoves: this.getPossibleMoves(),67 });68 }69 ponder() {70 this.nplayouts = this.game.get_visits();71 if (this.ponderer !== undefined) {72 return;73 }74 this.ponderer = self.setInterval(75 () => {76 if (this.nplayouts >= MAX_PLAYOUTS) {77 this.stopPondering();78 return;79 }80 const t0 = performance.now();81 while (performance.now() - t0 < PLAYOUT_MS) {82 this.playout();83 }84 let activePlayer = this.game.active_player();85 if (activePlayer !== undefined) {86 if (this.game.is_drafting()) {87 this.postPlaceScores(activePlayer);88 } else {89 this.postMoveScores(activePlayer);90 }91 }92 },93 PONDER_INTERVAL_MS,94 );95 }96 stopPondering() {97 if (this.ponderer !== undefined) {98 self.clearInterval(this.ponderer);99 this.ponderer = undefined;100 }101 }102 placePenguin(dst: number) {103 this.game.place_penguin(dst);104 this.ponder();105 }106 movePenguin(src: number, dst: number) {107 this.game.move_penguin(src, dst);108 this.ponder();109 }110 playout() {111 this.game.playout();112 ++this.nplayouts;113 }114 takeAction() {115 this.stopPondering();116 const postMessage = this.postMessage;117 const min_playouts = this.game.turn() < 2 ? 2 * MIN_PLAYOUTS : MIN_PLAYOUTS;118 while (this.nplayouts < min_playouts) {119 this.playout();120 if (this.nplayouts % 100 === 0) {121 postMessage({122 type: "thinkingProgress",123 completed: this.nplayouts,124 required: min_playouts,125 });126 }127 }128 this.game.take_action();129 this.ponder();130 }131 getState(): GameState {132 return getGameState(this.game);133 }134 getPossibleMoves(src?: number): number[] {135 return getPossibleMoves(this.game, src);136 }137 onMessage(request: WorkerRequest) {138 console.log(`received request ${request.type}`);139 switch (request.type) {140 case "get":141 this.postGameState();142 break;143 case "move":144 try {145 this.movePenguin(request.src, request.dst);146 this.postGameState();147 } catch (err) {148 this.postIllegalMove(request.src, request.dst);149 }150 break;151 case "place":152 try {153 this.placePenguin(request.dst);154 this.postGameState();155 } catch (err) {156 this.postIllegalPlacement(request.dst);157 }158 break;159 case "possibleMoves":160 this.postPossibleMoves(request.src);161 break;162 case "takeAction":163 this.takeAction();164 this.postGameState();165 break;166 }167 }168 postIllegalMove(src: number, dst: number) {169 const postMessage = this.postMessage;170 postMessage({171 type: "illegalMove",172 src,173 dst,174 });175 }176 postIllegalPlacement(dst: number) {177 const postMessage = this.postMessage;178 postMessage({179 type: "illegalPlacement",180 dst,181 });182 }183 postPossibleMoves(src?: number) {184 const postMessage = this.postMessage;185 postMessage({186 type: "possibleMoves",187 possibleMoves: this.getPossibleMoves(src),188 });189 }190 postGameState() {191 const postMessage = this.postMessage;192 postMessage({193 type: "state",194 gameState: this.getState(),195 });196 }197 postPlaceScores(activePlayer: number) {198 const placeScores = [];199 for (let dst of this.game.draftable_cells()) {200 const info = this.game.place_info(dst);201 placeScores.push({202 dst,203 visits: info.get_visits(),204 rewards: info.get_rewards(),205 });206 }207 const postMessage = this.postMessage;208 postMessage({209 type: "placeScores",210 activePlayer,211 placeScores,212 });213 }214 postMoveScores(activePlayer: number) {215 const moveScores = [];216 for (let src of this.game.penguins(activePlayer)) {217 for (let dst of this.game.possible_moves(src)) {218 const info = this.game.move_info(src, dst);219 moveScores.push({220 src,221 dst,222 visits: info.get_visits(),223 rewards: info.get_rewards(),224 });225 }226 }227 const postMessage = this.postMessage;228 postMessage({229 type: "moveScores",230 activePlayer,231 moveScores,232 });233 }234}...
worker-importScripts.js
Source:worker-importScripts.js
...3 else4 onconnect = handleConnect;5function handleConnect(event)6{7 // For shared workers, create a faux postMessage() API to send messages back to the parent page.8 self.postMessage = function(message) { event.ports[0].postMessage(message); }9 runTests();10}11function runTests()12{13 try {14 postMessage("Test started.");15 importScripts();16 postMessage("PASS: importScripts(), exists, is a function, and doesn't throw when not given any arguments");17 var source1 = "worker-importScripts-source1.js";18 var source2 = "worker-importScripts-source2.js";19 var differentOrigin = "http://localhost:8000/workers/resources/worker-importScripts-differentOrigin.js";20 var differentRedirectOrigin = "/resources/redirect.php?url=http://localhost:8000/workers/resources/worker-importScripts-differentOrigin.js";21 var syntaxErrorSource = "worker-importScripts-syntaxError.js";22 var fakeSource = "nonexistant";23 loadedSource1 = false;24 loadedSource2 = false;25 differentOriginLoaded = false;26 function resetLoadFlags() {27 loadedSource1 = false;28 loadedSource2 = false;29 differentOriginLoaded = false;30 }31 try {32 importScripts(differentOrigin)33 } catch(e) {34 postMessage("FAIL: Threw " + e + " when attempting cross origin load");35 }36 if (differentOriginLoaded)37 postMessage("PASS: executed script from different origin");38 resetLoadFlags();39 try {40 importScripts(differentRedirectOrigin)41 } catch(e) {42 postMessage("FAIL: Threw " + e + " when attempting load from different origin through a redirect");43 }44 if (differentOriginLoaded)45 postMessage("PASS: executed script from different origin through a redirect");46 else47 postMessage("FAIL: did not load script from different origin through a redirect");48 resetLoadFlags();49 postMessage("Testing single argument:");50 importScripts(source1)51 if (loadedSource1)52 postMessage("PASS: loaded first source");53 else54 postMessage("FAIL: did not load first source");55 resetLoadFlags();56 postMessage("Testing multiple arguments:");57 importScripts(source1, source2);58 if (loadedSource1 && loadedSource2)59 postMessage("PASS: Both sources loaded and executed.");60 else61 postMessage("FAIL: not all sources were loaded");62 resetLoadFlags();63 postMessage("Testing multiple arguments (different order):");64 importScripts(source2, source1);65 if (loadedSource1 && loadedSource2)66 postMessage("PASS: Both sources loaded and executed.");67 else68 postMessage("FAIL: not all sources were loaded");69 resetLoadFlags();70 firstShouldThrow = false;71 secondShouldThrow = false;72 postMessage("Testing multiple arguments, with different origin for one argument:");73 try {74 importScripts(source1, differentOrigin, source2);75 } catch(e) {76 postMessage("FAIL: Threw " + e + " when attempt cross origin load");77 }78 if (loadedSource1 && loadedSource2 && differentOriginLoaded)79 postMessage("PASS: all resources executed.");80 else81 postMessage("FAIL: Not of the origin failure");82 resetLoadFlags();83 try {84 importScripts(source1, fakeSource, source2);85 } catch(e) {86 postMessage("PASS: Threw " + e + " when load failed");87 }88 if (!loadedSource1 && !loadedSource2)89 postMessage("FAIL: Nothing was executed when network error occurred.");90 else91 postMessage("PASS: some resources were loaded despite the network error");92 resetLoadFlags();93 try {94 importScripts(source1, syntaxErrorSource, source2);95 } catch(e) {96 postMessage("PASS: Threw " + e + " when encountering a syntax error in imported script");97 }98 if (!loadedSource1 && !loadedSource2)99 postMessage("FAIL: Nothing was executed when syntax error was present in any source.");100 else101 postMessage("PASS: some resources were loaded despite the presence of a syntax error");102 resetLoadFlags();103 postMessage("Testing multiple arguments, with first resource throwing an exception:");104 firstShouldThrow = true;105 try {106 importScripts(source1, source2);107 } catch(e) {108 postMessage("PASS: Propagated '" + e + "' from script");109 }110 firstShouldThrow = false;111 if (loadedSource1 && !loadedSource2)112 postMessage("PASS: First resource was executed, and second resource was not");113 else if (loadedSource2)114 postMessage("FAIL: Second resource was executed");115 else116 postMessage("FAIL: first resource did not execute correctly");117 resetLoadFlags();118 postMessage("Testing multiple arguments, with second resource throwing an exception:");119 secondShouldThrow = true;120 try {121 importScripts(source1, source2);122 } catch(e) {123 postMessage("PASS: Propagated '" + e + "' from script");124 }125 secondShouldThrow = false;126 if (loadedSource1 && loadedSource2)127 postMessage("PASS: Both scripts were executed");128 else129 postMessage("FAIL: scripts did not execute correctly");130 resetLoadFlags();131 } catch(e) {132 postMessage("FAIL: Unexpected exception: " + e);133 } finally {134 postMessage("DONE");135 }...
open-database-inputs-sync.js
Source:open-database-inputs-sync.js
...3 toString: function() { throw "foo"; }4};5try {6 db = openDatabaseSync();7 postMessage("FAIL: calling openDatabaseSync() without any argument should throw an exception.");8} catch (err) {9 postMessage("PASS: " + err.message);10}11try {12 db = openDatabaseSync("DBName", "DBVersion");13 postMessage("FAIL: calling openDatabaseSync() with fewer than four arguments should throw an exception.");14} catch (err) {15 postMessage("PASS: " + err.message);16}17try {18 db = openDatabaseSync(notAString, "DBVersion", "DBDescription", 1024);19 postMessage("FAIL: the first argument to openDatabaseSync() must be a string.");20} catch (err) {21 postMessage("PASS: " + err.message);22}23try {24 db = openDatabaseSync("DBName", notAString, "DBDescription", 1024);25 postMessage("FAIL: the second argument to openDatabaseSync() must be a string.");26} catch (err) {27 postMessage("PASS: " + err.message);28}29try {30 db = openDatabaseSync("DBName", "DBVersion", notAString, 1024);31 postMessage("FAIL: the third argument to openDatabaseSync() must be a string.");32} catch (err) {33 postMessage("PASS: " + err.message);34}35try {36 db = openDatabaseSync("DBName", "DBVersion", "DBDescription", 1024, 0);37 postMessage("FAIL: the fifth argument to openDatabaseSync() must be an object, if present.");38} catch (err) {39 postMessage("PASS: " + err.message);40}41try {42 db = openDatabaseSync("DBName", "DBVersion", "DBDescription", 1024);43 postMessage("PASS: openDatabaseSync() succeeded.");44} catch (err) {45 postMessage("FAIL: " + err.message);46}47// Run this test case one more time, to test the code with an existing database.48try {49 db = openDatabaseSync("DBName", "DBVersion", "DBDescription", 1024);50 postMessage("PASS: openDatabaseSync() succeeded.");51} catch (err) {52 postMessage("FAIL: " + err.message);53}54try {55 // Need to create a new database, otherwise the creation callback won't be invoked.56 db = openDatabaseSync("DBNameCreationCallback" + (new Date()).getTime(), "DBVersion", "DBDescription", 1024,57 function(db) {58 postMessage("PASS: calling openDatabaseSync() with a creation callback succeeded.");59 });60} catch (err) {61 postMessage("FAIL: " + err.message);62}...
Using AI Code Generation
1var worker = new Worker('worker.js');2worker.postMessage('hello');3worker.onmessage = function(event) {4 console.log(event.data);5}6onmessage = function(event) {7 console.log(event.data);8 postMessage('world');9}
Using AI Code Generation
1var worker = new Worker("worker.js");2worker.postMessage({cmd: "start", msg: "Hi"});3worker.onmessage = function(event) {4 console.log("page got message: " + event.data);5};6var worker = new Worker("worker.js");7worker.postMessage({cmd: "start", msg: "Hi"});8worker.onmessage = function(event) {9 console.log("page got message: " + event.data);10};11worker.onerror = function(event) {12 console.log("page got error: " + event.message);13};14self.onmessage = function(event) {15 console.log("worker got message: " + event.data);16 self.postMessage("Hi");17};18self.onmessage = function(event) {19 console.log("worker got message: " + event.data);20 self.postMessage("Hi");21};22self.onerror = function(event) {23 console.log("worker got error: " + event.message);24};25var worker = new Worker("worker.js");26worker.postMessage({cmd: "start", msg: "Hi"});27worker.onmessage = function(event) {28 console.log("page got message: " + event.data);29};30worker.onerror = function(event) {31 console.log("page got error: " + event.message);32};33self.onmessage = function(event) {34 console.log("worker got message: " + event.data);35 self.postMessage("Hi");36};37self.onerror = function(event) {38 console.log("worker got error: " + event.message);39};
Using AI Code Generation
1var worker = new Worker('worker.js');2worker.postMessage('hello world');3worker.onmessage = function(event) {4 console.log('Message received from worker', event.data);5};6var worker = new SharedWorker('worker.js', 'shared worker');7worker.port.postMessage('hello world');8worker.port.onmessage = function(event) {9 console.log('Message received from worker', event.data);10};
Using AI Code Generation
1var worker = new Worker("worker.js");2worker.addEventListener('message', function(e) {3 console.log(e.data);4}, false);5worker.postMessage("Hello World");6self.addEventListener('message', function(e) {7 self.postMessage("You said: " + e.data);8}, false);9self.postMessage("Hello World");10self.addEventListener('message', function(e) {11 self.postMessage("You said: " + e.data);12}, false);13self.addEventListener('message', function(e) {14 self.postMessage("You said: " + e.data);15}, false);16self.postMessage("Hello World");17self.addEventListener('message', function(e) {18 self.postMessage("You said: " + e.data);19}, false);20self.addEventListener('message', function(e) {21 self.postMessage("You said: " + e.data);22}, false);23self.postMessage("Hello World");24self.addEventListener('message', function(e) {25 self.postMessage("You said: " + e.data);26}, false);27self.addEventListener('message', function(e) {28 self.postMessage("You said: " + e.data);29}, false);30self.postMessage("Hello World");31self.addEventListener('message
Using AI Code Generation
1var bestFit = require("bestfit");2 if (err) {3 console.error(err);4 } else {5 console.log(response);6 }7});8var bestFit = require("bestfit");9 if (err) {10 console.error(err);11 } else {12 console.log(response);13 }14});15#### BestFit.get(url, [headers], callback)16#### BestFit.post(url, [headers], [data], callback)17#### BestFit.put(url, [headers], [data], callback)18#### BestFit.delete(url, [headers], [data], callback)19#### BestFit.patch(url, [headers], [data], callback)20#### BestFit.head(url, [headers], callback)
Using AI Code Generation
1var bestPractice = new BestPractice();2bestPractice.postMessage("Hello parent window");3var bestPractice = new BestPractice();4var bestPractice = new BestPractice();5bestPractice.postMessage("Hello parent window");6var bestPractice = new BestPractice();
Using AI Code Generation
1var data = {2};3window.addEventListener('message', function (event) {4 return;5}, false);6var data = {7};8window.addEventListener('message', function (event) {9 return;10}, false);11var data = {12};13window.addEventListener('message', function (event) {14 return;15}, false);16var data = {
Using AI Code Generation
1function testWorker() {2 var worker = new Worker("worker.js");3 worker.postMessage("message to worker");4 worker.onmessage = function(event) {5 console.log(event.data);6 }7}8self.onmessage = function(event) {9 console.log(event.data);10 self.postMessage("message to window");11}12function testWorker() {13 var worker = new Worker("worker.js");14 worker.postMessage("message to worker");15 worker.onmessage = function(event) {16 console.log(event.data);17 }18}19self.onmessage = function(event) {20 console.log(event.data);21 self.postMessage("message to window");22}23function testWorker() {24 var worker = new Worker("worker.js");25 worker.postMessage("message to worker");26 worker.onmessage = function(event) {27 console.log(event.data);28 }29}30self.onmessage = function(event) {31 console.log(event.data);32 self.postMessage("message to window");33}34function testWorker() {35 var worker = new Worker("worker.js");36 worker.postMessage("message to worker");37 worker.onmessage = function(event) {38 console.log(event.data);39 }40}41self.onmessage = function(event) {42 console.log(event.data);43 self.postMessage("message to window");44}45function testWorker() {46 var worker = new Worker("worker.js");47 worker.postMessage("message to worker");48 worker.onmessage = function(event) {49 console.log(event.data);50 }51}
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!!