Best JavaScript code snippet using playwright-internal
jquery.jOrgChart.js
Source:jquery.jOrgChart.js
...145 chartClass : "clicface-jOrgChart",146 dragAndDrop: false147 };148 149 function countChildren($node) {150 var $childNodes = $node.children("ul:first").children("li.s, li.o, li.d");151 var $childAssistantsDroite = $node.children("ul:first").children("li.a");152 var $childAssistantsGauche = $node.children("ul:first").children("li.b");153 var $childServicesDroite = $node.children("ul:first").children("li.e");154 var $childServicesGauche = $node.children("ul:first").children("li.f");155 var $childHomologue = $node.children("ul:first").children("li.h");156 var $childOrganigrammes = $node.children("ul:first").children("li.o");157 return $childNodes.length;158 };159 160 function Recurse($item, depth) {161 $item.each(function() {162 depth.count++;163 if (depth.count > depth.max) {164 depth.max = depth.count;165 }166 Recurse($(this).children(), depth);167 });168 depth.count--;169 return depth.max;170 };171 172 // Method that recursively builds the tree173 function buildNode($node, $appendTo, level, opts) {174 var $table = $("<table cellpadding='0' cellspacing='0' border='0'/>");175 var $tbody = $("<tbody/>");176 // Construct the node container(s)177 var $nodeRow = $("<tr/>").addClass("node-cells");178 var $nodeCell = $("<td/>").addClass("node-cell").attr("colspan", 2);179 var $childNodes = $node.children("ul:first").children("li.s, li.o, li.d");180 var $childAssistantsDroite = $node.children("ul:first").children("li.a");181 var $childAssistantsGauche = $node.children("ul:first").children("li.b");182 var $childServicesDroite = $node.children("ul:first").children("li.e");183 var $childServicesGauche = $node.children("ul:first").children("li.f");184 var $childHomologue = $node.children("ul:first").children("li.h");185 var $childOrganigrammes = $node.children("ul:first").children("li.o");186 var $nodeDiv;187 if($childNodes.length > 1) {188 $nodeCell.attr("colspan", $childNodes.length * 2);189 }190 191 // Draw the node192 // Get the contents - any markup except li and ul allowed193 var $nodeContent = $node.clone()194 .children("ul,li")195 .remove()196 .end()197 .html();198 var new_node_id = $node.attr("id");199 if (typeof new_node_id !== 'undefined' && new_node_id !== false) {200 $nodeDiv = $("<div>").addClass("node").attr("id", 'cellule_' + $node.attr("id")).append($nodeContent);201 }else{202 $nodeDiv = $("<div>").addClass("node").append($nodeContent);203 }204 // Expand and contract nodes205 if ($childNodes.length > 0) {206 $nodeDiv.dblclick(function() {207 var $this = $(this);208 var $tr = $this.closest("tr");209 $tr.nextAll("tr").fadeToggle("fast");210 if($tr.hasClass('contracted')){211 $this.css('cursor','n-resize');212 $tr.removeClass('contracted');213 $tr.addClass('expanded');214 }else{215 $this.css('cursor','s-resize');216 $tr.removeClass('expanded');217 $tr.addClass('contracted');218 }219 });220 }221 $nodeCell.append($nodeDiv);222 $nodeRow.append($nodeCell);223 $tbody.append($nodeRow);224 if($childNodes.length > 0) {225 // if it can be expanded then change the cursor226 $nodeDiv.css('cursor','n-resize').addClass('expanded');227 // recurse until leaves found (-1) or to the level specified228 if(opts.depth == -1 || (level+1 < opts.depth)) {229 var $downLineRow = $("<tr/>");230 var $downLineCell = $("<td/>").attr("colspan", $childNodes.length*2);231 $downLineRow.append($downLineCell);232 // draw the connecting line from the parent node to the horizontal line233 $downLine = $("<div></div>").addClass("clicface-line clicface-down");234 $downLineCell.append($downLine);235 $tbody.append($downLineRow);236 // Draw the horizontal lines237 var $linesRow = $("<tr/>");238 $childNodes.each(function() {239 var $left = $("<td> </td>").addClass("clicface-line clicface-left clicface-top");240 var $right = $("<td> </td>").addClass("clicface-line clicface-right clicface-top");241 $linesRow.append($left).append($right);242 });243 // horizontal line shouldn't extend beyond the first and last child branches244 $linesRow.find("td:first")245 .removeClass("clicface-top")246 .end()247 .find("td:last")248 .removeClass("clicface-top");249 $tbody.append($linesRow);250 var $childNodesRow = $("<tr/>");251 $childNodes.each(function() {252 var $td = $("<td class='node-container'/>");253 $td.attr("colspan", 2);254 // recurse through children lists and items255 buildNode($(this), $td, level+1, opts);256 $childNodesRow.append($td);257 });258 259 if ( $childAssistantsDroite.length > 0 && $childAssistantsGauche.length == 0 && ($childServicesDroite.length > 0 || ($childServicesDroite.length == 0 && $childServicesGauche.length == 0)) ) {260 var myRegExp = /wktemp/;261 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {262 var level = (( Recurse($childAssistantsDroite.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;263 } else {264 var level = (( Recurse($childAssistantsDroite.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;265 }266 //$nodeDiv.append('<b><font color="purple">j\'ai ' + $childAssistantsDroite.length + ' assistant(s) qui a ' + countChildren( $childAssistantsDroite.first() ) + ' subalternes sur ' + Recurse($childAssistantsDroite.first(), { count: 0, max:0 }) + ' niveaux</font></b><br />');267 268 $containerAssistants = $("<div style='width: " + (400 + 200 * countChildren( $childAssistantsDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");269 $downLineCell.append($containerAssistants);270 271 $childAssistantsDroite.each(function() {272 var $div = $("<div class='node-container' style='float:right;' />");273 // recurse through children lists and items274 buildNode($(this), $div, level+1, opts);275 $containerAssistants.append($div);276 });277 278 // draw a longer connecting line from the parent node to the horizontal line279 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);280 if ( clicface_organi_zoom == '50' ) {281 $leftPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childAssistantsDroite.first() ) );282 } else {283 $leftPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childAssistantsDroite.first() ) );284 }285 $containerAssistants.append($downLine);286 $downLine.append($leftPatte);287 }288 289 if ( $childAssistantsDroite.length > 0 && $childAssistantsGauche.length == 0 && $childServicesDroite.length == 0 && $childServicesGauche.length > 0 ) {290 var myRegExp = /wktemp/;291 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {292 var level_droite = (( Recurse($childAssistantsDroite.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;293 var level_gauche = (( Recurse($childServicesGauche.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;294 } else {295 var level_droite = (( Recurse($childAssistantsDroite.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;296 var level_gauche = (( Recurse($childServicesGauche.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;297 }298 if ( level_droite <= level_gauche ) {299 var level = level_gauche;300 } else {301 var level = level_droite;302 }303 304 if ( countChildren( $childAssistantsDroite.first() ) > 1 ) {305 $containerAssistantsDroite = $("<div style='width: " + (200 + 200 * countChildren( $childAssistantsDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");306 } else if ( countChildren( $childAssistantsDroite.first() ) > 0 ) {307 $containerAssistantsDroite = $("<div style='width: " + (300 + 200 * countChildren( $childAssistantsDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");308 } else {309 $containerAssistantsDroite = $("<div style='width: " + (400 + 200 * countChildren( $childAssistantsDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");310 }311 if ( countChildren( $childServicesGauche.first() ) > 1 ) {312 $containerServicesGauche = $("<div style='width: " + (400 + 200 * countChildren( $childServicesGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");313 } else if ( countChildren( $childServicesGauche.first() ) > 0 ) {314 $containerServicesGauche = $("<div style='width: " + (300 + 200 * countChildren( $childServicesGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");315 } else {316 $containerServicesGauche = $("<div style='width: " + (400 + 200 * countChildren( $childServicesGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");317 }318 $downLineCell.append($containerServicesGauche);319 $containerServicesGauche.append($containerAssistantsDroite);320 321 $childAssistantsDroite.each(function() {322 var $div = $("<div class='node-container' style='float:right;' />");323 // recurse through children lists and items324 buildNode($(this), $div, level+1, opts);325 $containerAssistantsDroite.append($div);326 });327 328 $childServicesGauche.each(function() {329 var $div = $("<div class='node-container' style='float:left;' />");330 // recurse through children lists and items331 buildNode($(this), $div, level+1, opts);332 $containerServicesGauche.append($div);333 });334 335 // draw a longer connecting line from the parent node to the horizontal line336 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);337 if ( clicface_organi_zoom == '50' ) {338 $rightPatte = $("<div class='clicface-side-fin' style='position: relative; top: 104px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childServicesGauche.first() ) ).css( "margin-left", -1*(180 + 50 * countChildren( $childServicesGauche.first() )) );339 $leftPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childAssistantsDroite.first() ) );340 } else {341 $rightPatte = $("<div class='clicface-side-epais' style='position: relative; top: 104px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childServicesGauche.first() ) ).css( "margin-left", -1*(150 + 50 * countChildren( $childServicesGauche.first() )) );342 $leftPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childAssistantsDroite.first() ) );343 }344 $containerAssistantsDroite.append($downLine);345 $containerServicesGauche.append($downLine);346 $downLine.append($rightPatte);347 $downLine.append($leftPatte);348 }349 350 if ( $childAssistantsGauche.length > 0 && $childAssistantsDroite.length == 0 && ($childServicesGauche.length > 0 || ($childServicesGauche.length == 0 && $childServicesDroite.length == 0)) ) {351 var myRegExp = /wktemp/;352 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {353 var level = (( Recurse($childAssistantsGauche.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;354 } else {355 var level = (( Recurse($childAssistantsGauche.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;356 }357 358 $containerAssistants = $("<div style='width: " + (400 + 200 * countChildren( $childAssistantsGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");359 $downLineCell.append($containerAssistants);360 361 $childAssistantsGauche.each(function() {362 var $div = $("<div class='node-container' style='float:left;' />");363 // recurse through children lists and items364 buildNode($(this), $div, level+1, opts);365 $containerAssistants.append($div);366 });367 368 // draw a longer connecting line from the parent node to the horizontal line369 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);370 if ( clicface_organi_zoom == '50' ) {371 $rightPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childAssistantsGauche.first() ) ).css( "margin-left", -1*(180 + 50 * countChildren( $childAssistantsGauche.first() )) );372 } else {373 $rightPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childAssistantsGauche.first() ) ).css( "margin-left", -1*(150 + 50 * countChildren( $childAssistantsGauche.first() )) );374 }375 $containerAssistants.append($downLine);376 $downLine.append($rightPatte);377 }378 379 if ( $childAssistantsGauche.length > 0 && $childAssistantsDroite.length == 0 && $childServicesGauche.length == 0 && $childServicesDroite.length > 0 ) {380 var myRegExp = /wktemp/;381 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {382 var level_droite = (( Recurse($childServicesDroite.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;383 var level_gauche = (( Recurse($childAssistantsGauche.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;384 } else {385 var level_droite = (( Recurse($childServicesDroite.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;386 var level_gauche = (( Recurse($childAssistantsGauche.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;387 }388 if ( level_droite <= level_gauche ) {389 var level = level_gauche;390 } else {391 var level = level_droite;392 }393 394 if ( countChildren( $childServicesDroite.first() ) > 1 ) {395 $containerServicesDroite = $("<div style='width: " + (200 + 200 * countChildren( $childServicesDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");396 } else if ( countChildren( $childServicesDroite.first() ) > 0 ) {397 $containerServicesDroite = $("<div style='width: " + (300 + 200 * countChildren( $childServicesDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");398 } else {399 $containerServicesDroite = $("<div style='width: " + (400 + 200 * countChildren( $childServicesDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");400 }401 if ( countChildren( $childAssistantsGauche.first() ) > 1 ) {402 $containerAssistantsGauche = $("<div style='width: " + (200 + 200 * countChildren( $childAssistantsGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");403 } else if ( countChildren( $childAssistantsGauche.first() ) > 0 ) {404 $containerAssistantsGauche = $("<div style='width: " + (300 + 200 * countChildren( $childAssistantsGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");405 } else {406 $containerAssistantsGauche = $("<div style='width: " + (400 + 200 * countChildren( $childAssistantsGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");407 }408 $downLineCell.append($containerAssistantsGauche);409 $containerAssistantsGauche.append($containerServicesDroite);410 411 $childServicesDroite.each(function() {412 var $div = $("<div class='node-container' style='float:right;' />");413 // recurse through children lists and items414 buildNode($(this), $div, level+1, opts);415 $containerServicesDroite.append($div);416 });417 418 $childAssistantsGauche.each(function() {419 var $div = $("<div class='node-container' style='float:left;' />");420 // recurse through children lists and items421 buildNode($(this), $div, level+1, opts);422 $containerAssistantsGauche.append($div);423 });424 425 // draw a longer connecting line from the parent node to the horizontal line426 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);427 if ( clicface_organi_zoom == '50' ) {428 $rightPatte = $("<div class='clicface-side-fin' style='position: relative; top: 104px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childAssistantsGauche.first() ) ).css( "margin-left", -1*(180 + 50 * countChildren( $childAssistantsGauche.first() )) );429 $leftPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childServicesDroite.first() ) );430 } else {431 $rightPatte = $("<div class='clicface-side-epais' style='position: relative; top: 104px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childAssistantsGauche.first() ) ).css( "margin-left", -1*(150 + 50 * countChildren( $childAssistantsGauche.first() )) );432 $leftPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childServicesDroite.first() ) );433 }434 $containerServicesDroite.append($downLine);435 $containerAssistantsGauche.append($downLine);436 $downLine.append($rightPatte);437 $downLine.append($leftPatte);438 }439 440 if ( $childAssistantsGauche.length > 0 && $childAssistantsDroite.length > 0 ) {441 var myRegExp = /wktemp/;442 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {443 var level_droite = (( Recurse($childAssistantsDroite.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;444 var level_gauche = (( Recurse($childAssistantsGauche.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;445 } else {446 var level_droite = (( Recurse($childAssistantsDroite.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;447 var level_gauche = (( Recurse($childAssistantsGauche.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;448 }449 if ( level_droite <= level_gauche ) {450 var level = level_gauche;451 } else {452 var level = level_droite;453 }454 455 if ( countChildren( $childAssistantsDroite.first() ) > 1 ) {456 $containerAssistantsDroite = $("<div style='width: " + (200 + 200 * countChildren( $childAssistantsDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");457 } else if ( countChildren( $childAssistantsDroite.first() ) > 0 ) {458 $containerAssistantsDroite = $("<div style='width: " + (300 + 200 * countChildren( $childAssistantsDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");459 } else {460 $containerAssistantsDroite = $("<div style='width: " + (400 + 200 * countChildren( $childAssistantsDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");461 }462 if ( countChildren( $childAssistantsGauche.first() ) > 1 ) {463 $containerAssistantsGauche = $("<div style='width: " + (200 + 200 * countChildren( $childAssistantsGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");464 } else if ( countChildren( $childAssistantsGauche.first() ) > 0 ) {465 $containerAssistantsGauche = $("<div style='width: " + (300 + 200 * countChildren( $childAssistantsGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");466 } else {467 $containerAssistantsGauche = $("<div style='width: " + (400 + 200 * countChildren( $childAssistantsGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");468 }469 $downLineCell.append($containerAssistantsGauche);470 $containerAssistantsGauche.append($containerAssistantsDroite);471 472 $childAssistantsDroite.each(function() {473 var $div = $("<div class='node-container' style='float:right;' />");474 // recurse through children lists and items475 buildNode($(this), $div, level+1, opts);476 $containerAssistantsDroite.append($div);477 });478 479 $childAssistantsGauche.each(function() {480 var $div = $("<div class='node-container' style='float:left;' />");481 // recurse through children lists and items482 buildNode($(this), $div, level+1, opts);483 $containerAssistantsGauche.append($div);484 });485 486 // draw a longer connecting line from the parent node to the horizontal line487 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);488 if ( clicface_organi_zoom == '50' ) {489 $rightPatte = $("<div class='clicface-side-fin' style='position: relative; top: 104px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childAssistantsGauche.first() ) ).css( "margin-left", -1*(180 + 50 * countChildren( $childAssistantsGauche.first() )) );490 $leftPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childAssistantsDroite.first() ) );491 } else {492 $rightPatte = $("<div class='clicface-side-epais' style='position: relative; top: 104px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childAssistantsGauche.first() ) ).css( "margin-left", -1*(150 + 50 * countChildren( $childAssistantsGauche.first() )) );493 $leftPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childAssistantsDroite.first() ) );494 }495 $containerAssistantsDroite.append($downLine);496 $containerAssistantsGauche.append($downLine);497 $downLine.append($rightPatte);498 $downLine.append($leftPatte);499 }500 501 if ( $childServicesDroite.length > 0 && $childServicesGauche.length == 0 && ($childAssistantsDroite.length > 0 || ($childAssistantsDroite.length == 0 && $childAssistantsGauche.length == 0)) ) {502 var myRegExp = /wktemp/;503 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {504 var level = (( Recurse($childServicesDroite.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;505 } else {506 var level = (( Recurse($childServicesDroite.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;507 }508 //$nodeDiv.append('<b><font color="purple">j\'ai ' + $childServicesDroite.length + ' assistant(s) qui a ' + countChildren( $childServicesDroite.first() ) + ' subalternes sur ' + Recurse($childServicesDroite.first(), { count: 0, max:0 }) + ' niveaux</font></b><br />');509 510 $containerServices = $("<div style='width: " + (400 + 200 * countChildren( $childServicesDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");511 $downLineCell.append($containerServices);512 513 $childServicesDroite.each(function() {514 var $div = $("<div class='node-container' style='float:right;' />");515 // recurse through children lists and items516 buildNode($(this), $div, level+1, opts);517 $containerServices.append($div);518 });519 520 // draw a longer connecting line from the parent node to the horizontal line521 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);522 if ( clicface_organi_zoom == '50' ) {523 $leftPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childServicesDroite.first() ) );524 } else {525 $leftPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childServicesDroite.first() ) );526 }527 $containerServices.append($downLine);528 $downLine.append($leftPatte);529 }530 531 if ( $childServicesGauche.length > 0 && $childServicesDroite.length == 0 && ($childAssistantsGauche.length > 0 || ($childAssistantsGauche.length == 0 && $childAssistantsDroite.length == 0 )) ) {532 var myRegExp = /wktemp/;533 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {534 var level = (( Recurse($childServicesGauche.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;535 } else {536 var level = (( Recurse($childServicesGauche.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;537 }538 539 $containerServices = $("<div style='width: " + (400 + 200 * countChildren( $childServicesGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");540 $downLineCell.append($containerServices);541 542 $childServicesGauche.each(function() {543 var $div = $("<div class='node-container' style='float:left;' />");544 // recurse through children lists and items545 buildNode($(this), $div, level+1, opts);546 $containerServices.append($div);547 });548 549 // draw a longer connecting line from the parent node to the horizontal line550 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);551 if ( clicface_organi_zoom == '50' ) {552 $rightPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childServicesGauche.first() ) ).css( "margin-left", -1*(180 + 50 * countChildren( $childServicesGauche.first() )) );553 } else {554 $rightPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childServicesGauche.first() ) ).css( "margin-left", -1*(150 + 50 * countChildren( $childServicesGauche.first() )) );555 }556 $containerServices.append($downLine);557 $downLine.append($rightPatte);558 }559 560 if ( $childServicesGauche.length > 0 && $childServicesDroite.length > 0 ) {561 var myRegExp = /wktemp/;562 if ( clicface_user == 'gestionnaire' && !myRegExp.test( document.URL ) ) {563 var level_droite = (( Recurse($childServicesDroite.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;564 var level_gauche = (( Recurse($childServicesGauche.first(), { count: 0, max:0 }) - 5 ) / 2) + 1;565 } else {566 var level_droite = (( Recurse($childServicesDroite.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;567 var level_gauche = (( Recurse($childServicesGauche.first(), { count: 0, max:0 }) - 3 ) / 2) + 1;568 }569 if ( level_droite <= level_gauche ) {570 var level = level_gauche;571 } else {572 var level = level_droite;573 }574 575 if ( countChildren( $childServicesDroite.first() ) > 1 ) {576 $containerServicesDroite = $("<div style='width: " + (200 + 200 * countChildren( $childServicesDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");577 } else if ( countChildren( $childServicesDroite.first() ) > 0 ) {578 $containerServicesDroite = $("<div style='width: " + (300 + 200 * countChildren( $childServicesDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");579 } else {580 $containerServicesDroite = $("<div style='width: " + (400 + 200 * countChildren( $childServicesDroite.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");581 }582 if ( countChildren( $childServicesGauche.first() ) > 1 ) {583 $containerServicesGauche = $("<div style='width: " + (200 + 200 * countChildren( $childServicesGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");584 } else if ( countChildren( $childServicesGauche.first() ) > 0 ) {585 $containerServicesGauche = $("<div style='width: " + (300 + 200 * countChildren( $childServicesGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");586 } else {587 $containerServicesGauche = $("<div style='width: " + (400 + 200 * countChildren( $childServicesGauche.first() ) + 200 * countChildren( $childOrganigrammes.first() )) + "px; margin-left: auto; margin-right: auto;' />");588 }589 $downLineCell.append($containerServicesGauche);590 $containerServicesGauche.append($containerServicesDroite);591 592 $childServicesDroite.each(function() {593 var $div = $("<div class='node-container' style='float:right;' />");594 // recurse through children lists and items595 buildNode($(this), $div, level+1, opts);596 $containerServicesDroite.append($div);597 });598 599 $childServicesGauche.each(function() {600 var $div = $("<div class='node-container' style='float:left;' />");601 // recurse through children lists and items602 buildNode($(this), $div, level+1, opts);603 $containerServicesGauche.append($div);604 });605 606 // draw a longer connecting line from the parent node to the horizontal line607 $downLine = $("<div></div>").addClass("clicface-tree clicface-down").height(level * 250);608 if ( clicface_organi_zoom == '50' ) {609 $rightPatte = $("<div class='clicface-side-fin' style='position: relative; top: 104px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childServicesGauche.first() ) ).css( "margin-left", -1*(180 + 50 * countChildren( $childServicesGauche.first() )) );610 $leftPatte = $("<div class='clicface-side-fin' style='position: relative; top: 100px; left: 2px;'></div>").width( 180 + 50 * countChildren( $childServicesDroite.first() ) );611 } else {612 $rightPatte = $("<div class='clicface-side-epais' style='position: relative; top: 104px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childServicesGauche.first() ) ).css( "margin-left", -1*(150 + 50 * countChildren( $childServicesGauche.first() )) );613 $leftPatte = $("<div class='clicface-side-epais' style='position: relative; top: 100px; left: 2px;'></div>").width( 150 + 50 * countChildren( $childServicesDroite.first() ) );614 }615 $containerServicesDroite.append($downLine);616 $containerServicesGauche.append($downLine);617 $downLine.append($rightPatte);618 $downLine.append($leftPatte);619 }620 621 var nombre_colonnes = $nodeCell.attr("colspan") / 2;622 var largeur_colonne = (100 / nombre_colonnes) + '%';623 624 if ($childHomologue.length > 0) {625 var $HomologueRow = $("<td/>").addClass("node-cell").attr("colspan", nombre_colonnes);626 $containerHomologue = $("<div/>");627 ...
dataManager.spec.js
Source:dataManager.spec.js
...75 data: this.complexData(),76 nestedRows: true77 });78 var plugin = hot.getPlugin('nestedRows');79 expect(plugin.dataManager.countChildren(-5)).toEqual(0);80 expect(plugin.dataManager.countChildren(0)).toEqual(5);81 expect(plugin.dataManager.countChildren(2)).toEqual(2);82 expect(plugin.dataManager.countChildren(3)).toEqual(1);83 expect(plugin.dataManager.countChildren(5)).toEqual(0);84 expect(plugin.dataManager.countChildren(10)).toEqual(0);85 expect(plugin.dataManager.countChildren(15)).toEqual(0);86 });87 it('should return a number of children (and children\'s children) of the row provided as a row object from the data source', function() {88 var hot = handsontable({89 data: this.complexData(),90 nestedRows: true91 });92 var plugin = hot.getPlugin('nestedRows');93 var sourceData = hot.getSourceData();94 expect(plugin.dataManager.countChildren(sourceData[0])).toEqual(5);95 expect(plugin.dataManager.countChildren(sourceData[0].__children[1])).toEqual(2);96 expect(plugin.dataManager.countChildren(sourceData[0].__children[1].__children[0])).toEqual(1);97 expect(plugin.dataManager.countChildren(sourceData[0].__children[2])).toEqual(0);98 expect(plugin.dataManager.countChildren(sourceData[2].__children[1].__children[0])).toEqual(0);99 });100 });101 describe('getRowParent', function() {102 it('should return a row object from the data source, being the parent node for the provided row index', function() {103 var hot = handsontable({104 data: this.complexData(),105 nestedRows: true106 });107 var plugin = hot.getPlugin('nestedRows');108 var sourceData = hot.getSourceData();109 expect(plugin.dataManager.getRowParent(-5)).toEqual(null);110 expect(plugin.dataManager.getRowParent(0)).toEqual(null);111 expect(plugin.dataManager.getRowParent(2)).toEqual(sourceData[0]);112 expect(plugin.dataManager.getRowParent(3)).toEqual(sourceData[0].__children[1]);113 expect(plugin.dataManager.getRowParent(5)).toEqual(sourceData[0]);114 expect(plugin.dataManager.getRowParent(10)).toEqual(sourceData[2].__children[1]);115 expect(plugin.dataManager.getRowParent(15)).toEqual(null);116 });117 it('should return a row object from the data source, being the parent node for the provided row object', function() {118 var hot = handsontable({119 data: this.complexData(),120 nestedRows: true121 });122 var plugin = hot.getPlugin('nestedRows');123 var sourceData = hot.getSourceData();124 expect(plugin.dataManager.getRowParent(sourceData[0])).toEqual(null);125 expect(plugin.dataManager.getRowParent(sourceData[0].__children[1])).toEqual(sourceData[0]);126 expect(plugin.dataManager.getRowParent(sourceData[0].__children[1].__children[0])).toEqual(sourceData[0].__children[1]);127 expect(plugin.dataManager.getRowParent(sourceData[0].__children[2])).toEqual(sourceData[0]);128 expect(plugin.dataManager.getRowParent(sourceData[2].__children[1].__children[0])).toEqual(sourceData[2].__children[1]);129 });130 });131 describe('getRowLevel', function() {132 it('should return the nesting level of the row, provided as an index', function() {133 var hot = handsontable({134 data: this.complexData(),135 nestedRows: true136 });137 var plugin = hot.getPlugin('nestedRows');138 expect(plugin.dataManager.getRowLevel(-5)).toEqual(null);139 expect(plugin.dataManager.getRowLevel(0)).toEqual(0);140 expect(plugin.dataManager.getRowLevel(2)).toEqual(1);141 expect(plugin.dataManager.getRowLevel(3)).toEqual(2);142 expect(plugin.dataManager.getRowLevel(5)).toEqual(1);143 expect(plugin.dataManager.getRowLevel(10)).toEqual(2);144 expect(plugin.dataManager.getRowLevel(15)).toEqual(null);145 });146 it('should return a row object from the data source, being the parent node for the provided row object', function() {147 var hot = handsontable({148 data: this.complexData(),149 nestedRows: true150 });151 var plugin = hot.getPlugin('nestedRows');152 var sourceData = hot.getSourceData();153 expect(plugin.dataManager.getRowLevel(sourceData[0])).toEqual(0);154 expect(plugin.dataManager.getRowLevel(sourceData[0].__children[1])).toEqual(1);155 expect(plugin.dataManager.getRowLevel(sourceData[0].__children[1].__children[0])).toEqual(2);156 expect(plugin.dataManager.getRowLevel(sourceData[0].__children[2])).toEqual(1);157 expect(plugin.dataManager.getRowLevel(sourceData[2].__children[1].__children[0])).toEqual(2);158 });159 });160 describe('hasChildren', function() {161 it('should return whether the element at the provided row index has children', function() {162 var hot = handsontable({163 data: this.complexData(),164 nestedRows: true165 });166 var plugin = hot.getPlugin('nestedRows');167 var sourceData = hot.getSourceData();168 expect(plugin.dataManager.hasChildren(0)).toEqual(true);169 expect(plugin.dataManager.hasChildren(1)).toEqual(false);170 expect(plugin.dataManager.hasChildren(2)).toEqual(true);171 expect(plugin.dataManager.hasChildren(3)).toEqual(true);172 expect(plugin.dataManager.hasChildren(4)).toEqual(false);173 expect(plugin.dataManager.hasChildren(5)).toEqual(false);174 expect(plugin.dataManager.hasChildren(6)).toEqual(false);175 expect(plugin.dataManager.hasChildren(7)).toEqual(true);176 expect(plugin.dataManager.hasChildren(8)).toEqual(false);177 expect(plugin.dataManager.hasChildren(9)).toEqual(true);178 expect(plugin.dataManager.hasChildren(10)).toEqual(false);179 expect(plugin.dataManager.hasChildren(11)).toEqual(false);180 });181 });182 describe('addChild', function() {183 it('should add an empty child to the provided parent, when the second method arguments is not declared', function() {184 var hot = handsontable({185 data: this.complexData(),186 nestedRows: true187 });188 var plugin = hot.getPlugin('nestedRows');189 var sourceData = hot.getSourceData();190 var parentElement = sourceData[0].__children[1];191 expect(plugin.dataManager.countChildren(2)).toEqual(2);192 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');193 expect(parentElement.__children[1]).toBeUndefined();194 plugin.dataManager.addChild(parentElement);195 expect(plugin.dataManager.countChildren(2)).toEqual(3);196 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');197 expect(parentElement.__children[1].a).toEqual(null);198 });199 it('should add a provided row element as a child to the provided parent', function() {200 var hot = handsontable({201 data: this.complexData(),202 nestedRows: true203 });204 var plugin = hot.getPlugin('nestedRows');205 var sourceData = hot.getSourceData();206 var parentElement = sourceData[0].__children[1];207 var newElement = {208 a: 'test-a',209 b: 'test-b'210 };211 expect(plugin.dataManager.countChildren(2)).toEqual(2);212 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');213 expect(parentElement.__children[1]).toBeUndefined();214 plugin.dataManager.addChild(parentElement, newElement);215 expect(plugin.dataManager.countChildren(2)).toEqual(3);216 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');217 expect(parentElement.__children[1].a).toEqual('test-a');218 expect(parentElement.__children[1].b).toEqual('test-b');219 });220 });221 describe('detachFromParent', function() {222 it('should detach a child node from it\'s parent and re-attach it to the parent of it\'s parent', function() {223 var hot = handsontable({224 data: this.complexData(),225 nestedRows: true226 });227 var plugin = hot.getPlugin('nestedRows');228 var sourceData = hot.getSourceData();229 var parentElement = sourceData[0].__children[1];...
dataManager.e2e.js
Source:dataManager.e2e.js
...74 data: getDataForNestedRows(),75 nestedRows: true76 });77 const plugin = hot.getPlugin('nestedRows');78 expect(plugin.dataManager.countChildren(-5)).toEqual(0);79 expect(plugin.dataManager.countChildren(0)).toEqual(5);80 expect(plugin.dataManager.countChildren(2)).toEqual(2);81 expect(plugin.dataManager.countChildren(3)).toEqual(1);82 expect(plugin.dataManager.countChildren(5)).toEqual(0);83 expect(plugin.dataManager.countChildren(10)).toEqual(0);84 expect(plugin.dataManager.countChildren(15)).toEqual(0);85 });86 it('should return a number of children (and children\'s children) of the row provided as a row object from the data source', () => {87 const hot = handsontable({88 data: getDataForNestedRows(),89 nestedRows: true90 });91 const plugin = hot.getPlugin('nestedRows');92 const sourceData = hot.getSourceData();93 expect(plugin.dataManager.countChildren(sourceData[0])).toEqual(5);94 expect(plugin.dataManager.countChildren(sourceData[0].__children[1])).toEqual(2);95 expect(plugin.dataManager.countChildren(sourceData[0].__children[1].__children[0])).toEqual(1);96 expect(plugin.dataManager.countChildren(sourceData[0].__children[2])).toEqual(0);97 expect(plugin.dataManager.countChildren(sourceData[2].__children[1].__children[0])).toEqual(0);98 });99 });100 describe('getRowParent', () => {101 it('should return a row object from the data source, being the parent node for the provided row index', () => {102 const hot = handsontable({103 data: getDataForNestedRows(),104 nestedRows: true105 });106 const plugin = hot.getPlugin('nestedRows');107 const sourceData = hot.getSourceData();108 expect(plugin.dataManager.getRowParent(-5)).toEqual(null);109 expect(plugin.dataManager.getRowParent(0)).toEqual(null);110 expect(plugin.dataManager.getRowParent(2)).toEqual(sourceData[0]);111 expect(plugin.dataManager.getRowParent(3)).toEqual(sourceData[0].__children[1]);112 expect(plugin.dataManager.getRowParent(5)).toEqual(sourceData[0]);113 expect(plugin.dataManager.getRowParent(10)).toEqual(sourceData[2].__children[1]);114 expect(plugin.dataManager.getRowParent(15)).toEqual(null);115 });116 it('should return a row object from the data source, being the parent node for the provided row object', () => {117 const hot = handsontable({118 data: getDataForNestedRows(),119 nestedRows: true120 });121 const plugin = hot.getPlugin('nestedRows');122 const sourceData = hot.getSourceData();123 expect(plugin.dataManager.getRowParent(sourceData[0])).toEqual(null);124 expect(plugin.dataManager.getRowParent(sourceData[0].__children[1])).toEqual(sourceData[0]);125 expect(plugin.dataManager.getRowParent(sourceData[0].__children[1].__children[0])).toEqual(sourceData[0].__children[1]);126 expect(plugin.dataManager.getRowParent(sourceData[0].__children[2])).toEqual(sourceData[0]);127 expect(plugin.dataManager.getRowParent(sourceData[2].__children[1].__children[0])).toEqual(sourceData[2].__children[1]);128 });129 });130 describe('getRowLevel', () => {131 it('should return the nesting level of the row, provided as an index', () => {132 const hot = handsontable({133 data: getDataForNestedRows(),134 nestedRows: true135 });136 const plugin = hot.getPlugin('nestedRows');137 expect(plugin.dataManager.getRowLevel(-5)).toEqual(null);138 expect(plugin.dataManager.getRowLevel(0)).toEqual(0);139 expect(plugin.dataManager.getRowLevel(2)).toEqual(1);140 expect(plugin.dataManager.getRowLevel(3)).toEqual(2);141 expect(plugin.dataManager.getRowLevel(5)).toEqual(1);142 expect(plugin.dataManager.getRowLevel(10)).toEqual(2);143 expect(plugin.dataManager.getRowLevel(15)).toEqual(null);144 });145 it('should return a row object from the data source, being the parent node for the provided row object', () => {146 const hot = handsontable({147 data: getDataForNestedRows(),148 nestedRows: true149 });150 const plugin = hot.getPlugin('nestedRows');151 const sourceData = hot.getSourceData();152 expect(plugin.dataManager.getRowLevel(sourceData[0])).toEqual(0);153 expect(plugin.dataManager.getRowLevel(sourceData[0].__children[1])).toEqual(1);154 expect(plugin.dataManager.getRowLevel(sourceData[0].__children[1].__children[0])).toEqual(2);155 expect(plugin.dataManager.getRowLevel(sourceData[0].__children[2])).toEqual(1);156 expect(plugin.dataManager.getRowLevel(sourceData[2].__children[1].__children[0])).toEqual(2);157 });158 });159 describe('hasChildren', () => {160 it('should return whether the element at the provided row index has children', () => {161 const hot = handsontable({162 data: getDataForNestedRows(),163 nestedRows: true164 });165 const plugin = hot.getPlugin('nestedRows');166 expect(plugin.dataManager.hasChildren(0)).toEqual(true);167 expect(plugin.dataManager.hasChildren(1)).toEqual(false);168 expect(plugin.dataManager.hasChildren(2)).toEqual(true);169 expect(plugin.dataManager.hasChildren(3)).toEqual(true);170 expect(plugin.dataManager.hasChildren(4)).toEqual(false);171 expect(plugin.dataManager.hasChildren(5)).toEqual(false);172 expect(plugin.dataManager.hasChildren(6)).toEqual(false);173 expect(plugin.dataManager.hasChildren(7)).toEqual(true);174 expect(plugin.dataManager.hasChildren(8)).toEqual(false);175 expect(plugin.dataManager.hasChildren(9)).toEqual(true);176 expect(plugin.dataManager.hasChildren(10)).toEqual(false);177 expect(plugin.dataManager.hasChildren(11)).toEqual(false);178 });179 });180 describe('addChild', () => {181 it('should add an empty child to the provided parent, when the second method arguments is not declared', () => {182 const hot = handsontable({183 data: getDataForNestedRows(),184 nestedRows: true185 });186 const plugin = hot.getPlugin('nestedRows');187 const sourceData = hot.getSourceData();188 const parentElement = sourceData[0].__children[1];189 expect(plugin.dataManager.countChildren(2)).toEqual(2);190 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');191 expect(parentElement.__children[1]).toBeUndefined();192 plugin.dataManager.addChild(parentElement);193 expect(plugin.dataManager.countChildren(2)).toEqual(3);194 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');195 expect(parentElement.__children[1].a).toEqual(null);196 });197 it('should add a provided row element as a child to the provided parent', () => {198 const hot = handsontable({199 data: getDataForNestedRows(),200 nestedRows: true201 });202 const plugin = hot.getPlugin('nestedRows');203 const sourceData = hot.getSourceData();204 const parentElement = sourceData[0].__children[1];205 const newElement = {206 a: 'test-a',207 b: 'test-b'208 };209 expect(plugin.dataManager.countChildren(2)).toEqual(2);210 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');211 expect(parentElement.__children[1]).toBeUndefined();212 plugin.dataManager.addChild(parentElement, newElement);213 expect(plugin.dataManager.countChildren(2)).toEqual(3);214 expect(parentElement.__children[0].a).toEqual('a0-a1-a0');215 expect(parentElement.__children[1].a).toEqual('test-a');216 expect(parentElement.__children[1].b).toEqual('test-b');217 });218 });219 describe('detachFromParent', () => {220 it('should detach a child node from it\'s parent and re-attach it to the parent of it\'s parent', () => {221 const hot = handsontable({222 data: getDataForNestedRows(),223 nestedRows: true224 });225 const plugin = hot.getPlugin('nestedRows');226 const sourceData = hot.getSourceData();227 let parentElement = sourceData[0].__children[1];...
uiKit.test.js
Source:uiKit.test.js
...27describe('<CallToAction />', () => {28 const props = {}29 beforeEach(() => (props.text = 'Click me meow'))30 it('renders a <IconButton /> when CTA type is button', () => {31 countChildren(<CallToAction type="button" {...props} />, IconButton, 1)32 countChildren(<CallToAction type="button" {...props} />, 'a', 0)33 })34 it('renders an <a /> when CTA type is link', () => {35 countChildren(<CallToAction type="link" {...props} />, 'a', 1)36 countChildren(<CallToAction type="link" {...props} />, IconButton, 0)37 })38})39describe('<Card />', () => {40 it('renders the right number of <LinkWrappers /> when <Card /> has CTAs', () => {41 const props = {42 title: "Ceci n'est pas un carte",43 content: 'foo',44 image: placeholder,45 callToActions: [46 {47 text: 'foo',48 to: '#'49 }50 ]51 }52 countChildren(<Card {...props} />, LinkWrapper, props.callToActions.length)53 })54})55describe('<ConnectingTo />', () => {56 const props = {}57 beforeEach(() => {58 props.title = 'foo'59 props.content = 'bar'60 })61 it('renders an image if there is one', () => {62 countChildren(<ConnectingTo image={placeholder} {...props} />, 'img', 1)63 countChildren(<ConnectingTo {...props} />, 'img', 0)64 })65 it('renders a spinner if there is one', () => {66 countChildren(67 <ConnectingTo spinner={placeholder} {...props} />,68 'div.spinner',69 170 )71 countChildren(<ConnectingTo {...props} />, 'div.spinner', 0)72 })73})74describe('<ContentBar />', () => {75 const props = {}76 beforeEach(() => {77 props.title = 'foo'78 props.image = placeholder79 })80 it('renders an <a /> if it has a titleTo', () => {81 countChildren(<ContentBar titleTo="#" {...props} />, 'a', 1)82 })83 it('renders and <h3 /> if it has no titleTo', () => {84 countChildren(<ContentBar {...props} />, 'h3', 1)85 countChildren(<ContentBar {...props} />, 'a', 0)86 })87})88describe('<ContentBarDefault />', () => {89 const props = {}90 beforeEach(() => {91 props.title = 'foo'92 props.content = 'bar'93 props.image = placeholder94 })95 it('renders a <ContentBar />', () => {96 countChildren(<ContentBarDefault {...props} />, ContentBar, 1)97 })98 it('renders the status if there is one', () => {99 const status = {100 type: 'done',101 text: 'status is done'102 }103 countChildren(104 <ContentBarDefault {...props} status={status} />,105 `.${status.type}`,106 1107 )108 })109 it('renders an <a /> if there is a CTA', () => {110 const callToAction = {111 type: 'button',112 text: 'foo',113 to: '#'114 }115 countChildren(116 <ContentBarDefault {...props} callToAction={callToAction} />,117 'a',118 1119 )120 countChildren(<ContentBarDefault {...props} />, 'a', 0)121 })122})123describe('<ContentBox />', () => {124 const props = {}125 beforeEach(() => {126 props.title = 'foo'127 props.content = 'bar'128 })129 it('renders an <h2 />', () => {130 countChildren(<ContentBox {...props} />, 'h2', 1)131 })132 it('renders a <Markdown />', () => {133 countChildren(<ContentBox {...props} />, Markdown, 1)134 })135 it('renders a <CallToAction /> if there is one', () => {136 const callToAction = {137 text: 'foo'138 }139 countChildren(140 <ContentBox callToAction={callToAction} {...props} />,141 CallToAction,142 1143 )144 countChildren(<ContentBox {...props} />, CallToAction, 0)145 })146})147describe('<IconButton />', () => {148 const props = {}149 beforeEach(() => {150 props.text = 'foo'151 })152 it('renders an <img /> if there is one', () => {153 countChildren(<IconButton image={placeholder} {...props} />, 'img', 1)154 countChildren(<IconButton {...props} />, 'img', 0)155 })156 it('passes href prop to <Button /> only if clickHandler is undefined', () => {157 const mockFn = jest.fn()158 const wrapperWithHandler = shallow(159 <IconButton clickHandler={mockFn} {...props} />160 )161 expect(wrapperWithHandler.find(Button).prop('href')).toBe(undefined)162 })163})164describe('<LaunchPad />', () => {165 const props = {}166 beforeEach(() => {167 props.title = 'foo'168 props.text = 'bar'169 props.image = placeholder170 })171 it('renders a <LinkWrapper />', () => {172 countChildren(<LaunchPad {...props} />, LinkWrapper, 1)173 })174 it('renders an <img />', () => {175 countChildren(<LaunchPad {...props} />, 'img', 1)176 })177 it('renders an <h3 />', () => {178 countChildren(<LaunchPad {...props} />, 'h3', 1)179 })180})181describe('<LaunchPadRow />', () => {182 it('renders 2 <LaunchPad />s', () => {183 const buttonLink = {184 title: 'foo',185 text: 'bar',186 image: placeholder187 }188 const buttonLinks = []189 for (let i = 0; i < 2; i += 1) {190 buttonLinks.push(buttonLink)191 }192 countChildren(<LaunchPadRow buttonLinks={buttonLinks} />, LaunchPad, 2)193 })194})195describe('<LinkBar />', () => {196 const props = {}197 beforeEach(() => {198 props.title = 'foo'199 props.content = 'bar'200 })201 it('renders an <a /> for external links and mailtos', () => {202 countChildren(<LinkBar {...props} to="https://interbit.io" />, 'a', 1)203 countChildren(<LinkBar {...props} to="https://interbit.io" />, Link, 0)204 })205 it('renders a <Link /> for internal links', () => {206 countChildren(<LinkBar {...props} to="/foo" />, Link, 1)207 countChildren(<LinkBar {...props} to="/foo" />, 'a', 0)208 })209})210describe('<LinkWrapper />', () => {211 const externalTo = 'https://interbit.io'212 const internalTo = '/foo'213 const mockFn = jest.fn()214 it('renders an <a /> for external links', () => {215 countChildren(<LinkWrapper to={externalTo} />, 'a', 1)216 countChildren(<LinkWrapper to={externalTo} />, Link, 0)217 })218 it('renders a <Link /> for internal links', () => {219 countChildren(<LinkWrapper to={internalTo} />, Link, 1)220 countChildren(<LinkWrapper to={internalTo} />, 'a', 0)221 })222 it('passes clickHandler to <a/>', () => {223 const wrapper = shallow(224 <LinkWrapper to={externalTo} clickHandler={mockFn} />225 )226 expect(wrapper.find('a').prop('onClick')).toBeDefined()227 })228 it('passes clickHandler to <Link />', () => {229 const wrapper = shallow(230 <LinkWrapper to={internalTo} clickHandler={mockFn} />231 )232 expect(wrapper.find(Link).prop('onClick')).toBeDefined()233 })234})235describe('<ModalWrapper />', () => {236 const props = {}237 beforeEach(() => {238 props.body = <div>foo</div>239 })240 it('renders a <Modal.Header /> if header prop is provided', () => {241 countChildren(242 <ModalWrapper header={<div>header</div>} {...props} />,243 Modal.Header,244 1245 )246 countChildren(<ModalWrapper {...props} />, Modal.Header, 0)247 })248 it('renders a <Modal.Footer /> if footer prop is provided', () => {249 countChildren(250 <ModalWrapper footer={<div>footer</div>} {...props} />,251 Modal.Footer,252 1253 )254 countChildren(<ModalWrapper {...props} />, Modal.Footer, 0)255 })256})257describe('<Quote />', () => {258 const props = {}259 beforeEach(() => {260 props.content = 'foo'261 props.image = placeholder262 })263 it('renders an <h4/> when an author is provided', () => {264 countChildren(<Quote author="John Donne" {...props} />, 'h4', 1)265 countChildren(<Quote {...props} />, 'h4', 0)266 })267 it('renders an <a /> for each callToAction', () => {268 const ctas = [{ text: 'foo', to: '/bar' }]269 countChildren(<Quote {...props} callToActions={ctas} />, 'p a', ctas.length)270 })271 it('renders publication info when publication prop is provided', () => {272 countChildren(<Quote {...props} publication="baz" />, 'p.publication', 1)273 countChildren(<Quote {...props} />, 'p.publication', 0)274 })275})276describe('<TitledList />', () => {277 it('renders a <li /> for each item', () => {278 const props = {279 title: 'foo',280 items: [{ text: 'meow', to: '/woof' }]281 }282 countChildren(<TitledList {...props} />, 'li', props.items.length)283 })...
home_reservations.js
Source:home_reservations.js
1$(window).load(function (){2 if(document.URL.match("homes/" + "[0-9ï¼-ï¼]")) {3 var $adultUp = $(".count-up-adult"),4 $adultDown = $(".count-down-adult"),5 $childrenUp = $(".count-up-children")6 $childrenDown = $(".count-down-children"),7 $babiesUp = $(".count-up-babies"),8 $babiesDown = $(".count-down-babies"),9 $adultForm = $('.form-text-adult'),10 $adultHtml = $('.number-of-adult-html'),11 $childrenHtml = $('.number-of-children-html'),12 $babiesHtml = $('.number-of-babies-html'),13 $adultHidden = $('input:hidden[class="number-of-adult-sa"]'),14 $childrenHidden = $('input:hidden[class="number-of-children-sa"]'),15 $babiesHidden = $('input:hidden[class="number-of-babies-sa"]'),16 $maxGuestsNum = parseInt($('#max_guests_num').text()),17 $rotate = $('#rotate'),18 $adultId = 0,19 $childrenId = 1,20 $babiesId = 2,21 homeId = getId();22 function calc_prices(){23 var checkin = Date.parse($('.reservation-checkin').val()),24 checkout = Date.parse($('.reservation-checkout').val()),25 days = (checkout - checkin)/1000/60/60/24,26 countAdult = parseInt($adultHidden.val()),27 countChildren = parseInt($childrenHidden.val()),28 guestsSum = countAdult + countChildren;29 if (days > 0) {30 $.ajax({31 type: 'GET',32 url: '/home_reservations/new',33 data: { days: days, guests_sum: guestsSum, id: homeId },34 dataType: 'json'35 })36 .done(function(data) {37 $('#default_price').text(currency(data.per_day));38 $('#total_price').text(currency(data.total));39 $('.per_day').text(currency(data.per_day));40 $('.stay_day').text(currency(data.per_day)+" à "+staydays(days));41 $('.variable_sum').text(currency(data.variable));42 $('input:hidden[class="total_fee"]').val(data.total);43 $('input:hidden[class="per_day_fee"]').val(data.per_day);44 $('.reservation_new__result').removeClass('removed');45 close_select_guests();46 })47 .fail(function() {48 alert('æéè¨ç®ã«å¤±æãã¾ãã');49 })50 }51 else {52 $('.reservation-checkout').val("");53 return false54 }55 return false56 }57 function close_select_guests(){58 $rotate.removeClass('fa-angle-up');59 $rotate.addClass('fa-angle-down');60 $('#select-guests-num').css('visibility','hidden');61 }62 $('#guests-num-btn').on('click',63 function(){64 $rotate.removeClass('fa-angle-down');65 $rotate.addClass('fa-angle-up');66 $('#select-guests-num').css('visibility','visible');67 });68 $('.close-button').on('click',function(e){69 e.preventDefault();70 calc_prices();71 close_select_guests()72 });73 $('.calc-listner').on('change',function(){74 calc_prices();75 });76 function upCount(countNum,hiddenVal,numText,formText,id){77 countNum += 1;78 hiddenVal.val(countNum);79 numText.text(countNum);80 if(formText.length){81 formText.text(buildGuestsNum(id, countNum));82 }else{83 $('.form-texts').append(buildNewGuestsNum(id, countNum));84 }85 }86 function downCount(countNum,hiddenVal,numText,formText,id){87 countNum -= 1;88 hiddenVal.val(countNum);89 numText.text(countNum);90 formText.text(buildGuestsNum(id, countNum));91 }92 //大人93 $adultUp.on('click',function(e) {94 e.preventDefault();95 $adultDown.prop("disabled", false);96 var countAdult = parseInt($adultHidden.val());97 var countChildren = parseInt($childrenHidden.val());98 var guestsSum = countAdult + countChildren99 upCount(countAdult,$adultHidden,$adultHtml,$adultForm,$adultId);100 if (guestsSum >= $maxGuestsNum - 1){101 $(this).prop("disabled", true);102 $childrenUp.prop("disabled", true);103 }104 });105 $adultDown.on('click',function(e) {106 e.preventDefault();107 $adultUp.prop("disabled", false);108 $childrenUp.prop("disabled", false);109 var countAdult = parseInt($adultHidden.val());110 downCount(countAdult,$adultHidden,$adultHtml,$adultForm,$adultId);111 if (countAdult <= 2){112 $(this).prop("disabled", true);113 }114 });115 //åä¾116 $childrenUp.on('click',function(e) {117 e.preventDefault();118 $childrenDown.prop("disabled", false);119 var $childrenForm = $('.form-text-children');120 var countAdult = parseInt($adultHidden.val());121 var countChildren = parseInt($childrenHidden.val());122 var guestsSum = countAdult + countChildren123 upCount(countChildren,$childrenHidden,$childrenHtml,$childrenForm,$childrenId);124 if (guestsSum >= $maxGuestsNum - 1){125 $(this).prop("disabled", true);126 $adultUp.prop("disabled", true);127 }128 });129 $childrenDown.on('click',function(e) {130 e.preventDefault();131 $adultUp.prop("disabled", false);132 $childrenUp.prop("disabled", false);133 var $childrenForm = $('.form-text-children');134 var countChildren = parseInt($childrenHidden.val());135 if (countChildren > 1){136 downCount(countChildren,$childrenHidden,$childrenHtml,$childrenForm,$childrenId);137 }else{138 countChildren -= 1;139 $childrenHidden.val(countChildren);140 $childrenHtml.text(countChildren);141 $childrenForm.remove();142 $(this).prop("disabled", true);143 }144 });145 //乳幼å
146 $babiesUp.on('click',function(e) {147 e.preventDefault();148 $babiesDown.prop("disabled", false);149 var $babiesForm = $('.form-text-babies');150 var countBabies = parseInt($babiesHidden.val());151 upCount(countBabies,$babiesHidden,$babiesHtml,$babiesForm,$babiesId);152 if (countBabies >= 4){153 $(this).prop("disabled", true);154 }155 });156 $babiesDown.on('click',function(e) {157 e.preventDefault();158 $babiesUp.prop("disabled", false);159 var $babiesForm = $('.form-text-babies');160 var countBabies = parseInt($babiesHidden.val());161 if (countBabies > 1){162 downCount(countBabies,$babiesHidden,$babiesHtml,$babiesForm,$babiesId);163 }else{164 countBabies -= 1;165 $babiesHidden.val(countBabies);166 $babiesHtml.text(countBabies);167 $babiesForm.remove();168 $(this).prop("disabled", true);169 }170 });171 }...
main.js
Source:main.js
1//lesson-112let clickFilter = document.querySelector('#information_about_order');3let windowForSelection = document.querySelector('.window_for_choose_room');4clickFilter.addEventListener('click', () => {5 windowForSelection.style.cssText = `visibility : visible`;6});7//на плÑÑ Ð¼Ð¸Ð½ÑÑ increase // decrease8let countAdults = 0;9let countChildren = 0;10let countRooms = 0;11let decreaseAdults = document.querySelector('.decrease_adults');12decreaseAdults.addEventListener('click', () => (changeAdults(-1)));13let increaseAdults = document.querySelector('.increase_adults');14increaseAdults.addEventListener('click', () => (changeAdults(1)));15let decreaseChildren = document.querySelector('.decrease_children');16decreaseChildren.addEventListener('click', () => (changeChildren(-1)));17let increaseChildren = document.querySelector('.increase_children');18increaseChildren.addEventListener('click', () => (changeChildren(1)));19let decreaseRooms = document.querySelector('.decrease_rooms');20decreaseRooms.addEventListener('click', () => (changeRooms(-1)));21let increaseRooms = document.querySelector('.increase_rooms');22increaseRooms.addEventListener('click', () => (changeRooms(1)));23function updateLabels() {24 document.querySelector('#information_about_order').value =25 ` ${countAdults} Adults - ${countChildren} Children - ${countRooms} Rooms`26 document.querySelector('#counter_adults').innerHTML = `${countAdults}`27 document.querySelector('#counter_children').innerHTML = `${countChildren}`28 document.querySelector('#counter_rooms').innerHTML = `${countRooms}`29 if (countAdults === 0) {30 decreaseAdults.style.cssText = "color: #CECECE; border-color: #CECECE;";31 increaseAdults.style.cssText = "color: #3077C6; border-color: #3077C6;";32 } else if (countAdults < 30) {33 decreaseAdults.style.cssText = "color: #3077C6; border-color: #3077C6;";34 increaseAdults.style.cssText = "color: #3077C6; border-color: #3077C6;";35 } else if (countAdults === 30) {36 decreaseAdults.style.cssText = "color: #3077C6; border-color: #3077C6;"37 increaseAdults.style.cssText = "color: #CECECE; border-color: #CECECE;";38 }39 if (countChildren === 0) {40 decreaseChildren.style.cssText = "color: #CECECE; border-color: #CECECE;";41 increaseChildren.style.cssText = "color: #3077C6; border-color: #3077C6;";42 } else if (countChildren < 10) {43 decreaseChildren.style.cssText = "color: #3077C6; border-color: #3077C6;";44 increaseChildren.style.cssText = "color: #3077C6; border-color: #3077C6;";45 } else if (countChildren === 10) {46 decreaseChildren.style.cssText = "color: #3077C6; border-color: #3077C6;"47 increaseChildren.style.cssText = "color: #CECECE; border-color: #CECECE;";48 }49 if (countRooms === 0) {50 decreaseRooms.style.cssText = "color: #CECECE; border-color: #CECECE;";51 increaseRooms.style.cssText = "color: #3077C6; border-color: #3077C6;";52 } else if (countRooms < 30) {53 decreaseRooms.style.cssText = "color: #3077C6; border-color: #3077C6;";54 increaseRooms.style.cssText = "color: #3077C6; border-color: #3077C6;";55 } else if (countRooms === 30) {56 decreaseRooms.style.cssText = "color: #3077C6; border-color: #3077C6;"57 increaseRooms.style.cssText = "color: #CECECE; border-color: #CECECE;";58 }59}60let selectChildrenText = document.querySelector('.children_age');61function updateChildrenList() {62 if (countChildren === 0) {63 selectChildrenText.style.display = "none";64 } else {65 selectChildrenText.style.display = "";66 }67 let list = '';68 for (let i = 0; i < countChildren; i++) {69 list += `<select class = "select_children">70 <option>0 years old</option>71 <option>1 years old</option>72 <option>2 years old</option>73 <option>3 years old</option>74 <option>4 years old</option>75 <option>5 years old</option>76 <option>6 years old</option>77 <option>7 years old</option>78 <option>8 years old</option>79 <option>9 years old</option>80 <option>10 years old</option>81 <option>11 years old</option>82 <option>12 years old</option>83 <option>13 years old</option>84 <option>14 years old</option>85 <option>15 years old</option>86 <option>16 years old</option>87 <option>17 years old</option>88 </select>`;89 }90 document.querySelector("#children_list").innerHTML = list;91}92function changeAdults(value) {93 countAdults += value;94 if (countAdults < 0) countAdults = 0;95 if (countAdults >= 30) countAdults = 30;96 updateLabels();97}98function changeChildren(value) {99 countChildren += value;100 if (countChildren < 0) countChildren = 0;101 if (countChildren >= 10) countChildren = 10;102 updateLabels();103 updateChildrenList();104}105function changeRooms(value) {106 countRooms += value;107 if (countRooms < 0) countRooms = 0;108 if (countRooms >= 30) countRooms = 30;109 updateLabels();110}...
main-view.spec.js
Source:main-view.spec.js
...54 done();55 });56}57function shouldDisplayNoResultsWhenEmpty() {58 expect(component.countChildren('no-results')).toBe(1);59}60function shouldHideNoResultsWhenNotEmpty() {61 component.componentScope((scope) => scope.searchResults = results);62 expect(component.countChildren('no-results')).toBe(0);63}64function shouldPassSearchResults() {65 component.componentScope((scope) => scope.searchResults = results);66 expect(searchResults.bindings.results).toBe(results);67}68function shouldDisplayArtist(done) {69 expect(component.countChildren('artist-details'))70 .toBe(0);71 searchResults.bindings.onSelect({$result: results[0] });72 component.digest();73 setTimeout(() => {74 expect(component.countChildren('album-details'))75 .toBe(0);76 expect(component.countChildren('artist-details'))77 .toBe(1);78 expect(artistDetails.bindings.artist).toBe(results[0]);79 done();80 }, 0);81}82function shouldDisplayAlbum(done) {83 expect(component.countChildren('album-details'))84 .toBe(0);85 const album = albumsData.albums.items[0];86 searchResults.bindings.onSelect({ $result: album });87 component.digest();88 setTimeout(() => {89 expect(component.countChildren('album-details'))90 .toBe(1);91 expect(component.countChildren('artist-details'))92 .toBe(0);93 expect(albumDetails.bindings.album).toBe(album);94 done();95 }, 0);96}97function shouldDisplayAlbumFromArtistDetails() {98 expect(component.countChildren('album-details'))99 .toBe(0);100 component.componentScope((scope) => scope.selectedResult = results[0]);101 const album = albumsData.albums.items[0];102 artistDetails.bindings.onAlbumSelect({ $album: album });103 component.digest();104 expect(component.countChildren('album-details'))105 .toBe(1);106 expect(component.countChildren('artist-details'))107 .toBe(0);108 expect(albumDetails.bindings).toBeDefined();109 expect(albumDetails.bindings.album).toBe(album);...
area_header.js
Source:area_header.js
1// 表示/é表示å¶å¾¡2$(function(){3 $('.area__header__ppl__num').on('click', function(){4 $('#menuItemComponent-guest_picker').removeClass('hide');5 $('.contents').css({6 'position': 'relative',7 'height': '100vh',8 'width': '100%',9 'z-index': '100',10 'background': 'rgba(255, 255, 255, 0.85)'11 });12 })13 $('.area__header__btn, .area__header__ppl__num').click(function(){14 $(this).css({15 'background-color': 'rgb(0, 132, 137)',16 'color': 'white'17 });18 });19 $(document).on('click', function(e){20 if (!$(e.target).closest('.select-capacity').length && !$(e.target).closest('.area__header__ppl__num').length){21 $('#menuItemComponent-guest_picker').hide();22 }else if($(e.target).closest('.area__header__ppl__num').length){23 if($('#menuItemComponent-guest_picker').is(':hidden')){24 $('#menuItemComponent-guest_picker').show();25 }26 };27 });28 //æ°å¤åå¾+è¨ç®29 $(function(){30 var countAdult = $('.number-of-adult').attr('value');31 var countChildren = $('.number-of-children').attr('value');32 var countBabies = $('.number-of-babies').attr('value');33 //大人34 $(".count-up-adult").click(function(e) {35 e.preventDefault();36 if (countAdult < 17){37 countAdult++;38 };39 $(".number-of-adult-html").html(countAdult+"+");40 $('.number-of-adult').attr('value', countAdult);41 })42 $(".count-down-adult").click(function(e) {43 e.preventDefault();44 if (countAdult > 1){45 countAdult = countAdult - 146 $(".number-of-adult-html").html(countAdult+"+")47 $('.number-of-adult').attr('value', countAdult);48 };49 });50 //åã©ã51 $(".count-up-children").click(function(e) {52 e.preventDefault();53 if (countChildren < 5){54 countChildren++;55 };56 $(".number-of-children-html").html(countChildren+"+");57 $('.number-of-children').attr('value', countChildren);58 })59 $(".count-down-children").click(function(e) {60 e.preventDefault();61 if (countChildren > 0){62 countChildren = countChildren - 163 $(".number-of-children-html").html(countChildren+"+");64 $('.number-of-children').attr('value', countChildren);65 };66 });67 //å¹¼å
68 $(".count-up-babies").click(function(e) {69 e.preventDefault();70 if (countBabies < 5){71 countBabies++;72 };73 $(".number-of-babies-html").html(countBabies+"+");74 $('.number-of-babies').attr('value', countBabies);75 })76 $(".count-down-babies").click(function(e) {77 e.preventDefault();78 if (countBabies > 0){79 countBabies = countBabies - 180 $(".number-of-babies-html").html(countBabies+"+");81 $('.number-of-babies').attr('value', countBabies);82 };83 });84 });...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const count = await page.evaluate(() => {7 return window.playwright.countChildren(document.body);8 });9 console.log(count);10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const count = await page.evaluate(() => {18 return window.playwright.countChildren(document.body);19 });20 console.log(count);21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 const count = await page.evaluate(() => {29 return window.playwright.countChildren(document.body);30 });31 console.log(count);32 await browser.close();33})();34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const context = await browser.newContext();38 const page = await context.newPage();39 const count = await page.evaluate(() => {40 return window.playwright.countChildren(document.body);41 });42 console.log(count);43 await browser.close();44})();45const { chromium } = require('playwright');46(async () => {47 const browser = await chromium.launch();48 const context = await browser.newContext();49 const page = await context.newPage();50 const count = await page.evaluate(() => {51 return window.playwright.countChildren(document.body);52 });53 console.log(count);54 await browser.close();55})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const count = await page.evaluate(() => {7 return window.playwright.countChildren(document.body);8 });9 console.log(count);10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const count = await page.evaluate(() => {18 return window.playwright.countChildren(document.body);19 });20 console.log(count);21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 const count = await page.evaluate(() => {29 return window.playwright.countChildren(document.body);30 });31 console.log(count);32 await browser.close();33})();34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const context = await browser.newContext();38 const page = await context.newPage();39 const count = await page.evaluate(() => {40 return window.playwright.countChildren(document.body);41 });42 console.log(count);43 await browser.close();44})();45const { chromium } = require('playwright');46(async () => {47 const browser = await chromium.launch();48 const context = await browser.newContext();49 const page = await context.newPage();50 const count = await page.evaluate(() => {51 return window.playwright.countChildren(document.body);52 });53 console.log(count);54 await browser.close();55})();
Using AI Code Generation
1const { countChildren } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('text=Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API');8 const childCount = countChildren(element);9 console.log(childCount);10 await browser.close();11})();
Using AI Code Generation
1const { chromium, webkit, firefox } = require('playwright');2const { countChildren } = require('playwright/lib/server/dom.js');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const count = await countChildren(page, 'body');7 await browser.close();8})();
Using AI Code Generation
1const { countChildren } = require('playwright/lib/utils/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const count = await page.evaluate(countChildren, document.querySelector('header'));8 console.log(`Header has ${count} children`);9 await browser.close();10})();11const{ InternalAPI } = require('playwright-cre/lib/server/rames');12const { Frame,age } = require('pht-core/lib/server/cromium/crPage');13constinternal = new InternalAPI();14const frame = new Frame();15conspage = ew Page();16const countChildren = internalAPI.countChildren.call(frame, page);17console.log(countChildren);
Using AI Code Generation
1const { _electron } = require('playwright');2const { BrowserContext } = _electron;3const { Page } = _electron;4const { ElementHandle } = _electron;5const { chromium } = require('playwright');6(async () => {7 const browser = await chromium.launch();8 const context = await browser.newContext();9 const page = await context.newPage();10 const elementHandle = await page.$('text=Get started');11 console.log(await elementHandle.countChildren());12 await browser.close();13})();
Using AI Code Generation
1const { Playwright } = require('playwright-core');2const { countChildren } = Playwright.Internal;3const { ElementHandle } = require('playwright-core');4const { ElementHandleChannel } = require('playwright-core/lib/channels');5const { JSHandle } = require('playwright-core');6const { JSHandleChannel } = require('playwright-core/lib/channels');7const { Page } = require('playwright-core');8const { PageChannel } = require('playwright-core/lib/channels');9const { Frame } = require('playwright-core');10const { FrameChannel } = require('playwright-core/lib/channels');11const { Worker } = require('playwright-core');12const { WorkerChannel } = require('playwright-core/lib/channels');13const { BrowserContext } = require('playwright-core');14const { BrowserContextChannel } = require('playwright-core/lib/channels');15const { Browser } = require('playwright-core');16const { BrowserChannel } = require('playwright-core/lib/channels');17const { chromium } = require('playwright-core');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 const count = await countChildren(page, 'div');23 console.log('count: ', count);24 await browser.close();25})();26const { ElementHandleChannel } = require('playwright-core/lib/channels');27const { JSHandleChannel } = require('playwright-core/lib/channels');28const { PageChannel } = require('playwright-core/lib/channels');29const { FrameChannel } = require('playwright-core/lib/channels');30const { WorkerChannel } = require('playwright-core/lib/channels');31const { BrowserContextChannel } = require('playwright-core/lib/channels');32const { BrowserChannel } = require('playwright-core/lib/channels');33const { ElementHandleInitializer } = require('playwright-core/lib/channels/serializers'); of
Using AI Code Generation
1const { countChildren } = require('playwright/lib/utils/locatorHelper');2const childrenCount = countChildren(elementHandle);3console.log(childrenCount);4const { ElementHandleDispatcher } = require('playwright-core/lib/channels/dispatchers');5const { DispatcherScope } = require('playwright-core/lib/channels/dispatchers/dispatcher');6const { DispatcherConnection }
Using AI Code Generation
1const { countChildren } = require('playwright/lib/protocol/protocol-helpers');2(async () => {3 const { chromium } = require('playwright');4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('#content');8 const childrenCount = await countChildren(element);9 console.log('Number of children: ', childrenCount);10 await browser.close();11})();
Using AI Code Generation
1const { InternalAPI } = require('playwright/lib/server/chromium/crPage');2const internalAPI = new InternalAPI();3const childCount = internalAPI.countChildren(document.body);4console.log(childCount);5const childCount = document.body.childElementCount;6console.log(childCount);7const childCount = document.body.countChildren();8console.log(childCount);9const children = document.body.childNodes;10console.log(children.length);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!