Best JavaScript code snippet using playwright-internal
jquery-converter-plugin.js
Source:jquery-converter-plugin.js
1(function ($) {2 var methods = {34 uiDemo: function () {5 $("#refreshBtn").click(function () {6 methods.converterUI();7 });8 $("#MainHeading").append("<div id='TestDemo'></div>")9 },1011 converterUI: function () {12 if ($("#converterBody")) {13 $("#converterBody").remove();14 }15 if ($("#SectionBody")) {16 $("#SectionBody").remove();17 }181920 var converterBody = $("<div/>", {21 id: "converterBody",22 class: "form-group"23 }).append(24 $("<select/>", {25 id: "conversionParam",26 class: "form-control",27 }).append(28 $("<option/>", {29 text: "Length", value: "Length",30 })31 ).append(32 $("<option/>", {33 text: "Tempreture", value: "Tempreture",34 })35 ).append(36 $("<option/>", {37 text: "Speed", value: "Speed",38 })39 ).change(function () {40 methods.SectionBody();41 })42 );43 $("#MainPanel").append(converterBody);44 methods.selectionBody();45 },4647 selectionBody: function () {48 if ($("#SectionBody")) {49 $("#SectionBody").remove();50 }51 var selectedConversionParam = $("#conversionParam")[0].value;52 switch (selectedConversionParam) {53 case "Length":54 $("#MainPanel").append(methods.SectionBody());55 break;56 }57 },5859 UnitBody: function () {60 var selectedConversionParam = $("#conversionParam")[0].value;6162 var selectListForUnits = $("<select/>", {63 id: "ddUnits",64 class: "clUnits form-control",65 css: { "width": "auto" }66 }).change(67 function () {68 methods.ConversionComparision();69 }70 );7172 var UnitsOptions = [];7374 if (selectedConversionParam == "Length") {75 UnitsOptions = [76 { text: "cm", value: "cm" },77 { text: "mm", value: "mm" },78 { text: "m", value: "m" },79 { text: "km", value: "km" },80 { text: "mc", value: "mc" },81 { text: "nm", value: "nm" },82 { text: "mile", value: "mile" },83 { text: "yard", value: "yard" },84 { text: "foot", value: "foot" },85 { text: "inch", value: "inch" },86 { text: "ncm", value: "ncm" },87 ]8889 }9091 if (selectedConversionParam == "Tempreture") {92 UnitsOptions = [93 { text: "Celsius", value: "cl" },94 { text: "Fahrenheit", value: "ft" },95 { text: "Kelvin", value: "kl" },96 ]97 }9899 if (selectedConversionParam == "Speed") {100 UnitsOptions = [101 { text: "Miles per hour", value: "MPH" },102 { text: "Foot per second", value: "FPS" },103 { text: "Metre per second", value: "MPS" },104 { text: "Kilometre per hour", value: "KPH" },105 { text: "Knot", value: "knot" },106 ]107 }108109 if (UnitsOptions != undefined && UnitsOptions != null && UnitsOptions.length > 0)110 for (var i = 0; i < UnitsOptions.length; i++) {111 var lengthUnitRow = $("<option/>", {112 text: UnitsOptions[i].text,113 value: UnitsOptions[i].value114 });115116 selectListForUnits.append(lengthUnitRow);117 }118119 return selectListForUnits;120 },121122 SectionBody: function () {123 if ($("#SectionBody")) {124 $("#SectionBody").remove();125 }126 var SectionBodyHtml = $("<div/>", {127 id: "SectionBody",128 class: "row",129 css: { "margin-left": "20px", "margin-right": "20px" }130 }).append(131 $("<div/>", {132 class: "form-control col-md-5"133 }).append(134 $("<div/>").append(135 $("<input />", {136 id: "inputValue",137 class: "form-control",138 placeholder: "Enter Value",139 type: "number",140 }).keyup(141 function () {142 methods.ConversionComparision();143 }144 )145 )146 ).append(147 $("<div/>").append(148 methods.UnitBody()149 )150 )151 ).append(152 $("<div/>", {153 class: "col-md-2",154 css: { "text-align": "center", "padding-top": "26px", "font-size": "35px" }155 }).html("=")156 ).append(157 $("<div/>", {158 class: "form-control col-md-5"159 }).append(160 $("<div/>").append(161 $("<input />", {162 id: "outputValue",163 class: "form-control",164 placeholder: "0",165 type: "number",166 readonly: "true"167 })168 )169 ).append(170 $("<div/>").append(171 methods.UnitBody()172 )173 )174 );175 $("#MainPanel").append(SectionBodyHtml);176 return SectionBodyHtml;177 },178179 ConversionComparision: function () {180 if ($("#inputValue")[0].value != undefined && $("#inputValue")[0].value.trim() != "") {181182 var selectedConversionParam = $("#conversionParam")[0].value;183184 switch (selectedConversionParam) {185 case "Length":186 methods.lengthConversionComparision();187 break;188 case "Tempreture":189 methods.tempretureConversionComparision();190 break;191 case "Speed":192 methods.speedConversionComparision();193 break;194 }195 }196 else {197 $("#outputValue")[0].value = "0";198 }199 },200201 lengthConversionComparision: function () {202 var inputValue = parseInt($("#inputValue")[0].value);203 var inputUnit = $(".clUnits")[0].value;204 var outputUnit = $(".clUnits")[1].value;205 var outputValue = "";206207 if (inputUnit.trim() == "cm") {208 switch (outputUnit) {209 case "cm":210 outputValue = (inputValue).toString();211 break;212213 case "mm":214 outputValue = (inputValue * 10).toString();215 break;216217 case "m":218 outputValue = (inputValue / 100).toString();219 break;220221 case "km":222 outputValue = (inputValue / 100000).toString();223 break;224225 case "mc":226 outputValue = (inputValue * 10000).toString();227 break;228229 case "nm":230 outputValue = (inputValue * 10000000000).toString();231 break;232233 case "mile":234 outputValue = (inputValue / 160934.4).toString();235 break;236237 case "yard":238 outputValue = (inputValue / 91.44).toString();239 break;240241 case "foot":242 outputValue = (inputValue / 30.48).toString();243 break;244245 case "inch":246 outputValue = (inputValue / 2.54).toString();247 break;248249 case "ncm":250 outputValue = (inputValue / 185200).toString();251 break;252 }253 }254255 if (inputUnit.trim() == "m") {256 switch (outputUnit) {257 case "cm":258 outputValue = (inputValue * 100).toString();259 break;260261 case "mm":262 outputValue = (inputValue * 1000).toString();263 break;264265 case "m":266 outputValue = (inputValue).toString();267 break;268269 case "km":270 outputValue = (inputValue / 1000).toString();271 break;272273 case "mc":274 outputValue = (inputValue * 1000000).toString();275 break;276277 case "nm":278 outputValue = (inputValue * 1000000000).toString();279 break;280281 case "mile":282 outputValue = (inputValue / 1609.344).toString();283 break;284285 case "yard":286 outputValue = (inputValue * 1.094).toString();287 break;288289 case "foot":290 outputValue = (inputValue * 3.281291 ).toString();292 break;293294 case "inch":295 outputValue = (inputValue * 39.37).toString();296 break;297298 case "ncm":299 outputValue = (inputValue / 1852).toString();300 break;301302 }303 }304305 if (inputUnit.trim() == "km") {306 switch (outputUnit) {307 case "cm":308 outputValue = (inputValue * 100000).toString();309 break;310311 case "m":312 outputValue = (inputValue * 1000).toString();313 break;314315 case "km":316 outputValue = (inputValue).toString();317 break;318 case "mm":319 outputValue = (inputValue * 1000000).toString();320 break;321322 case "mc":323 outputValue = (inputValue * 1000000000).toString();324 break;325326 case "nm":327 outputValue = (inputValue * 1000000000000).toString();328 break;329330 case "mile":331 outputValue = (inputValue / 1.609).toString();332 break;333334 case "yard":335 outputValue = (inputValue * 1093.613).toString();336 break;337338 case "foot":339 outputValue = (inputValue * 3280.84).toString();340 break;341342 case "inch":343 outputValue = (inputValue * 39370.079).toString();344 break;345346 case "ncm":347 outputValue = (inputValue / 1.852).toString();348 break;349 }350 }351352 if (inputUnit.trim() == "mm") {353 switch (outputUnit) {354 case "cm":355 outputValue = (inputValue / 10).toString();356 break;357358 case "m":359 outputValue = (inputValue / 1000).toString();360 break;361362 case "km":363 outputValue = (inputValue / 1000000).toString();364 break;365366 case "mm":367 outputValue = (inputValue).toString();368 break;369370 case "mc":371 outputValue = (inputValue * 1000).toString();372 break;373374 case "nm":375 outputValue = (inputValue * 1000000).toString();376 break;377378 case "mile":379 outputValue = (inputValue / 1.609000000).toString();380 break;381382 case "yard":383 outputValue = (inputValue / 914.4).toString();384 break;385386 case "foot":387 outputValue = (inputValue / 304.8).toString();388 break;389390 case "inch":391 outputValue = (inputValue / 25.4).toString();392 break;393394 case "ncm":395 outputValue = (inputValue / 1.852000000).toString();396 break;397 }398 }399400 if (inputUnit.trim() == "mc") {401 switch (outputUnit) {402 case "cm":403 outputValue = (inputValue / 10000).toString();404 break;405406 case "m":407 outputValue = (inputValue / 1000000).toString();408 break;409410 case "km":411 outputValue = (inputValue / 1000000000).toString();412 break;413414 case "mm":415 outputValue = (inputValue / 1000).toString();416 break;417418 case "mc":419 outputValue = (inputValue).toString();420 break;421422 case "nm":423 outputValue = (inputValue * 1000).toString();424 break;425426 case "mile":427 outputValue = (inputValue / 1.609000000000).toString();428 break;429430 case "yard":431 outputValue = (inputValue / 914400).toString();432 break;433434 case "foot":435 outputValue = (inputValue / 304800).toString();436 break;437438 case "inch":439 outputValue = (inputValue / 25400).toString();440 break;441442 case "ncm":443 outputValue = (inputValue / 1.852000000000).toString();444 break;445 }446 }447448 if (inputUnit.trim() == "nm") {449 switch (outputUnit) {450 case "cm":451 outputValue = (inputValue / 10000000).toString();452 break;453454 case "m":455 outputValue = (inputValue / 1000000000).toString();456 break;457458 case "km":459 outputValue = (inputValue / 1000000000000).toString();460 break;461462 case "mm":463 outputValue = (inputValue / 1000000).toString();464 break;465466 case "mc":467 outputValue = (inputValue / 1000).toString();468 break;469470 case "nm":471 outputValue = (inputValue).toString();472 break;473474 case "mile":475 outputValue = (inputValue / 1.609000000000000).toString();476 break;477478 case "yard":479 outputValue = (inputValue / 9.14400000000).toString();480 break;481482 case "foot":483 outputValue = (inputValue / 3.04800000000).toString();484 break;485486 case "inch":487 outputValue = (inputValue / 2.540000000).toString();488 break;489490 case "ncm":491 outputValue = (inputValue / 1.852000000000000).toString();492 break;493 }494 }495496 if (inputUnit.trim() == "mile") {497 switch (outputUnit) {498 case "cm":499 outputValue = (inputValue * 160934.4).toString();500 break;501502 case "m":503 outputValue = (inputValue * 1609.344).toString();504 break;505506 case "km":507 outputValue = (inputValue * 1.609).toString();508 break;509510 case "mm":511 outputValue = (inputValue * 1.609000000).toString();512 break;513514 case "mc":515 outputValue = (inputValue * 1.609000000000).toString();516 break;517518 case "nm":519 outputValue = (inputValue * 1.609000000000000).toString();520 break;521522 case "mile":523 outputValue = (inputValue).toString();524 break;525526 case "yard":527 outputValue = (inputValue * 1760).toString();528 break;529530 case "foot":531 outputValue = (inputValue * 5280).toString();532 break;533534 case "inch":535 outputValue = (inputValue * 63360).toString();536 break;537538 case "ncm":539 outputValue = (inputValue / 1.151).toString();540 break;541 }542 }543544 if (inputUnit.trim() == "yard") {545 switch (outputUnit) {546 case "cm":547 outputValue = (inputValue * 91.44).toString();548 break;549550 case "m":551 outputValue = (inputValue / 1.094).toString();552 break;553554 case "km":555 outputValue = (inputValue / 1093.613).toString();556 break;557558 case "mm":559 outputValue = (inputValue * 914.4).toString();560 break;561562 case "mc":563 outputValue = (inputValue * 914400).toString();564 break;565566 case "nm":567 outputValue = (inputValue * 9.14400000000).toString();568 break;569570 case "mile":571 outputValue = (inputValue / 1760).toString();572 break;573574 case "yard":575 outputValue = (inputValue).toString();576 break;577578 case "foot":579 outputValue = (inputValue * 3).toString();580 break;581582 case "inch":583 outputValue = (inputValue * 36).toString();584 break;585586 case "ncm":587 outputValue = (inputValue / 2025.372).toString();588 break;589 }590 }591592 if (inputUnit.trim() == "foot") {593 switch (outputUnit) {594 case "cm":595 outputValue = (inputValue * 30.48).toString();596 break;597598 case "m":599 outputValue = (inputValue / 3.281).toString();600 break;601602 case "km":603 outputValue = (inputValue / 3280.84).toString();604 break;605606 case "mm":607 outputValue = (inputValue * 304.8).toString();608 break;609610 case "mc":611 outputValue = (inputValue * 304800).toString();612 break;613614 case "nm":615 outputValue = (inputValue * 3.04800000000).toString();616 break;617618 case "mile":619 outputValue = (inputValue / 5280).toString();620 break;621622 case "yard":623 outputValue = (inputValue / 3).toString();624 break;625626 case "foot":627 outputValue = (inputValue).toString();628 break;629630 case "inch":631 outputValue = (inputValue * 12).toString();632 break;633634 case "ncm":635 outputValue = (inputValue / 6076.115).toString();636 break;637 }638 }639640 if (inputUnit.trim() == "inch") {641 switch (outputUnit) {642 case "cm":643 outputValue = (inputValue * 2.54).toString();644 break;645646 case "m":647 outputValue = (inputValue / 39.37).toString();648 break;649650 case "km":651 outputValue = (inputValue / 39370.079).toString();652 break;653654 case "mm":655 outputValue = (inputValue * 25.4).toString();656 break;657658 case "mc":659 outputValue = (inputValue * 25400).toString();660 break;661662 case "nm":663 outputValue = (inputValue * 2.540000000).toString();664 break;665666 case "mile":667 outputValue = (inputValue / 63360).toString();668 break;669670 case "yard":671 outputValue = (inputValue / 36).toString();672 break;673674 case "foot":675 outputValue = (inputValue / 12).toString();676 break;677678 case "inch":679 outputValue = (inputValue).toString();680 break;681682 case "ncm":683 outputValue = (inputValue / 72913.386).toString();684 break;685 }686 }687688 if (inputUnit.trim() == "ncm") {689 switch (outputUnit) {690 case "cm":691 outputValue = (inputValue * 185200).toString();692 break;693694 case "m":695 outputValue = (inputValue * 1852).toString();696 break;697698 case "km":699 outputValue = (inputValue * 1.852).toString();700 break;701702 case "mm":703 outputValue = (inputValue * 1.852000000).toString();704 break;705706 case "mc":707 outputValue = (inputValue * 1.852000000000).toString();708 break;709710 case "nm":711 outputValue = (inputValue * 1.852000000000).toString();712 break;713714 case "mile":715 outputValue = (inputValue * 1.151).toString();716 break;717718 case "yard":719 outputValue = (inputValue * 2025.372).toString();720 break;721722 case "foot":723 outputValue = (inputValue * 6076.115).toString();724 break;725726 case "inch":727 outputValue = (inputValue * 72913.386).toString();728 break;729730 case "ncm":731 outputValue = (inputValue).toString();732 break;733 }734 }735736 $("#outputValue")[0].value = outputValue.toString();737738 },739740 tempretureConversionComparision: function () {741 var inputValue = parseInt($("#inputValue")[0].value);742 var inputUnit = $(".clUnits")[0].value;743 var outputUnit = $(".clUnits")[1].value;744 var outputValue = "";745746 if (inputUnit.trim() == "cl") {747 switch (outputUnit) {748 case "cl":749 outputValue = (inputValue).toString();750 break;751 case "ft":752 outputValue = ((inputValue * (9 / 5) + 32)).toString();753 break;754 case "kl":755 outputValue = (inputValue + 273.15).toString();756 break;757 }758 }759760 if (inputUnit.trim() == "ft") {761 switch (outputUnit) {762 case "cl":763 outputValue = ((inputValue - 32) * (5 / 9)).toString();764 break;765 case "ft":766 outputValue = (inputValue).toString();767 break;768 case "kl":769 outputValue = (((inputValue - 32) * (5 / 9)) + 273.15).toString();770 break;771 }772 }773774 if (inputUnit.trim() == "kl") {775 switch (outputUnit) {776 case "cl":777 outputValue = (inputValue - 273.15).toString();778 break;779 case "ft":780 outputValue = (((inputValue - 273.15) * (9 / 5) + 32)).toString();781 break;782 case "kl":783 outputValue = (inputValue).toString();784 break;785 }786 }787788 $("#outputValue")[0].value = outputValue.toString();789 },790791 speedConversionComparision: function () {792 var inputValue = parseInt($("#inputValue")[0].value);793 var inputUnit = $(".clUnits")[0].value;794 var outputUnit = $(".clUnits")[1].value;795 var outputValue = "";796797 if (inputUnit == "MPH") {798 switch (outputUnit) {799 case "MPH":800 outputValue = inputValue.toString();801 break;802803 case "FPS":804 outputValue = (inputValue * 1.467).toString();805 break;806807 case "MPS":808 outputValue = (inputValue / 2.237).toString();809 break;810811 case "KPH":812 outputValue = (inputValue * 1.609).toString();813 break;814815 case "knot":816 outputValue = (inputValue / 1.151).toString();817 break;818819 }820 }821822 if (inputUnit == "FPS") {823 switch (outputUnit) {824 case "MPH":825 outputValue = (inputValue / 1.467).toString();826 break;827828 case "FPS":829 outputValue = (inputValue).toString();830 break;831832 case "MPS":833 outputValue = (inputValue / 3.281).toString();834 break;835836 case "KPH":837 outputValue = (inputValue * 1.097).toString();838 break;839840 case "knot":841 outputValue = (inputValue / 1.688).toString();842 break;843844 }845 }846847 if (inputUnit == "MPS") {848 switch (outputUnit) {849 case "MPH":850 outputValue = (inputValue * 2.237).toString();851 break;852853 case "FPS":854 outputValue = (inputValue * 3.281).toString();855 break;856857 case "MPS":858 outputValue = (inputValue).toString();859 break;860861 case "KPH":862 outputValue = (inputValue * 3.6).toString();863 break;864865 case "knot":866 outputValue = (inputValue * 1.944).toString();867 break;868869 }870 }871872 if (inputUnit == "KPH") {873 switch (outputUnit) {874 case "MPH":875 outputValue = (inputValue / 1.609).toString();876 break;877878 case "FPS":879 outputValue = (inputValue / 1.097).toString();880 break;881882 case "MPS":883 outputValue = (inputValue / 3.6).toString();884 break;885886 case "KPH":887 outputValue = (inputValue).toString();888 break;889890 case "knot":891 outputValue = (inputValue / 1.852).toString();892 break;893894 }895 }896897 if (inputUnit == "knot") {898 switch (outputUnit) {899 case "MPH":900 outputValue = (inputValue * 1.151).toString();901 break;902903 case "FPS":904 outputValue = (inputValue * 1.688).toString();905 break;906907 case "MPS":908 outputValue = (inputValue / 1.944).toString();909 break;910911 case "KPH":912 outputValue = (inputValue * 1.852).toString();913 break;914915 case "knot":916 outputValue = (inputValue).toString();917 break;918919 }920 }921922923 $("#outputValue")[0].value = outputValue.toString();924 }925926927 }928929930 $.fn.hello = function (method) {931 if (methods[method]) {932 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));933 } else if (typeof method === 'object' || !method) {934 return methods.uiDemo.apply(this, arguments);935 } else {936 $.error('Method ' + method + ' does not exist on jQuery.Editor');937 }938 // return methods.test.apply(options);939 }
...
calculator.js
Source:calculator.js
1var isCalculating = false;2var formerNumer = 0;3var latterNumber = 0;4var action = ''5var isEnd = false6// var pageData = {7// data:{8// inputValue:"0"9// },10// /*11// ç®æ°æä½12// */13// onPlus:function(){14// console.log("+")15// if(!isCalculating){16// isCalculating = true;17// isEnd = false18// action = '+'19// formerNumer = Number(this.data.inputValue);20// this.setData({21// inputValue:"+"22// })23// }24// },25// onMinus:function(){26// console.log(parseInt(this.data.inputValue)+ 10 + 12)27// if(!isCalculating){28// isCalculating = true;29// isEnd = false30// action = '-'31// formerNumer = Number(this.data.inputValue);32// this.setData({33// inputValue:"-"34// })35// }36// },37// onMultiply:function(){38// console.log("*")39// if(!isCalculating){40// isCalculating = true;41// isEnd = false42// action = '*'43// formerNumer = Number(this.data.inputValue);44// this.setData({45// inputValue:"*"46// })47// }48// },49// onDivide:function(){50// console.log("/")51// if(!isCalculating){52// isCalculating = true;53// isEnd = false54// action = '/'55// formerNumer = Number(this.data.inputValue);56// this.setData({57// inputValue:"/"58// })59// }60// },61// /*62// æ°åæä½63// */64// onSeven:function(){65// console.log("7")66// if(this.data.inputValue === '0' || !(action === '') || isEnd )67// this.data.inputValue = ''68// var temp = this.data.inputValue69// this.setData({70// inputValue:temp + '7'71// })//è¿ç§setteræ¹æ³å¯ä»¥å·æ°UI72// console.log(this.data.inputValue) 73// },74// onEight:function(){75// if(this.data.inputValue === '0' || !(action === '') || isEnd)76// this.data.inputValue = ''77// var temp = this.data.inputValue78// this.setData({79// inputValue:temp + '8'80// })81 82// },83// onNine:function(){84// if(this.data.inputValue === '0' || !(action === '') || isEnd)85// this.data.inputValue = ''86// var temp = this.data.inputValue87// this.setData({88// inputValue:temp + '9'89// })90// },91// onDel:function(){92// console.log("Del")93// this.setData({94// inputValue:'0'95// })96// },97// onFour:function(){98// if(this.data.inputValue === '0' || !(action === '') || isEnd)99// this.data.inputValue = ''100// var temp = this.data.inputValue101// this.setData({102// inputValue:temp + '4'103// })104// },105// onFive:function(){106// if(this.data.inputValue === '0' || !(action === '') || isEnd)107// this.data.inputValue = ''108// var temp = this.data.inputValue109// this.setData({110// inputValue:temp + '5'111// })112// },113// onSix:function(){114// if(this.data.inputValue === '0' || !(action === '') || isEnd)115// this.data.inputValue = ''116// var temp = this.data.inputValue117// this.setData({118// inputValue:temp + '6'119// })120// },121// onClear:function(){122// this.setData({123// inputValue:'0'124// })125// },126// onOne:function(){127// if(this.data.inputValue === '0' || !(action === '') || isEnd)128// this.data.inputValue = ''129// var temp = this.data.inputValue130// this.setData({131// inputValue:temp + '1'132// })133// },134// onTwo:function(){135// if(this.data.inputValue === '0' || !(action === '') || isEnd)136// this.data.inputValue = ''137// var temp = this.data.inputValue138// this.setData({139// inputValue:temp + '2'140// })141// },142// onThree:function(){143// if(this.data.inputValue === '0' || !(action === '') || isEnd)144// this.data.inputValue = ''145// var temp = this.data.inputValue146// this.setData({147// inputValue:temp + '3'148// })149// },150// onPoint:function(){151// if(this.data.inputValue != '0'){152// var temp = this.data.inputValue153// this.setData({154// inputValue:temp + '.'155// })156// }157// },158// onZero:function(){159// if(this.data.inputValue === '0' || !(action === '') || isEnd)160// this.data.inputValue = ''161// //if(this.data.inputValue != '0'){162// var temp = this.data.inputValue163// this.setData({164// inputValue:temp + '0'165// })166// //}167// },168// onEquality:function(){169// latterNumber = Number(this.data.inputValue);170// if(isCalculating && formerNumer > 0 && latterNumber > 0){171// var total172// switch(action){173// case '+':{174// total = formerNumer + latterNumber175// }176// break;177// case '-':{178// total = formerNumer - latterNumber179// }180// break;181// case '*':{182// total = formerNumer * latterNumber183// }184// break;185// case '/':{186// total = formerNumer / latterNumber187// }188// break;189// }190// this.setData({191// inputValue:total.toFixed(0)192// })193// isCalculating = false194// action = ''195// isEnd = true196// }197// }198// }199//æ°æç»´200var pageData = {201 onReady:function(){202 this.animation = wx.createAnimation()203 },204 data:{205 inputValue:"0"206 },207 /*208 ç®æ°æä½209 */210 onPlus:function(){211 console.log("+")212 var str = "hello world"213 console.log(str.length)214 console.log(str.charAt(1))215 console.log(str.substring(1,4))216 console.log(str.slice(-3))217 console.log(str.indexOf('l'))218 console.log(str.split(' '))219 console.log(str.replace('h','H'))220 console.log(str.toUpperCase())221 222 if(!isCalculating){223 isCalculating = true;224 isEnd = false225 action = '+'226 this.setData({227 inputValue:this.data.inputValue + action228 })229 }230 //this.onRotate()231 },232 onMinus:function(){233 console.log(parseInt(this.data.inputValue)+ 10 + 12)234 if(!isCalculating){235 isCalculating = true;236 isEnd = false237 action = '-'238 this.setData({239 inputValue:this.data.inputValue + action240 })241 }242 },243 onMultiply:function(){244 console.log("*")245 if(!isCalculating){246 isCalculating = true;247 isEnd = false248 action = '*'249 this.setData({250 inputValue:this.data.inputValue + action251 })252 }253 },254 onDivide:function(){255 console.log("/")256 if(!isCalculating){257 isCalculating = true;258 isEnd = false259 action = '/'260 this.setData({261 inputValue:this.data.inputValue + action262 })263 }264 },265/*266æ°åæä½267*/268 onSeven:function(){269 console.log("7")270 if(this.data.inputValue === '0' || isEnd)271 this.data.inputValue = ''272 isEnd = false273 var temp = this.data.inputValue274 this.setData({275 inputValue:temp + '7'276 })//è¿ç§setteræ¹æ³å¯ä»¥å·æ°UI277 console.log(this.data.inputValue) 278 },279 onEight:function(){280 if(this.data.inputValue === '0' || isEnd)281 this.data.inputValue = ''282 isEnd = false283 var temp = this.data.inputValue284 this.setData({285 inputValue:temp + '8'286 }) 287 },288 onNine:function(){289 if(this.data.inputValue === '0' || isEnd)290 this.data.inputValue = ''291 isEnd = false292 var temp = this.data.inputValue293 this.setData({294 inputValue:temp + '9'295 })296 },297 onDel:function(){298 console.log("Del")299 this.setData({300 inputValue:'0'301 })302 },303 onFour:function(){304 if(this.data.inputValue === '0')305 this.data.inputValue = ''306 isEnd = false307 var temp = this.data.inputValue308 this.setData({309 inputValue:temp + '4'310 })311 },312 onFive:function(){313 if(this.data.inputValue === '0' || isEnd)314 this.data.inputValue = ''315 isEnd = false316 var temp = this.data.inputValue317 this.setData({318 inputValue:temp + '5'319 })320 },321 onSix:function(){322 if(this.data.inputValue === '0' || isEnd)323 this.data.inputValue = ''324 isEnd = false325 var temp = this.data.inputValue326 this.setData({327 inputValue:temp + '6'328 })329 },330 onClear:function(){331 this.setData({332 inputValue:'0'333 })334 },335 onOne:function(){336 if(this.data.inputValue === '0' || isEnd)337 this.data.inputValue = ''338 isEnd = false339 var temp = this.data.inputValue340 this.setData({341 inputValue:temp + '1'342 })343 },344 onTwo:function(){345 if(this.data.inputValue === '0' || isEnd)346 this.data.inputValue = ''347 isEnd = false348 var temp = this.data.inputValue349 this.setData({350 inputValue:temp + '2'351 })352 },353 onThree:function(){354 if(this.data.inputValue === '0' || isEnd)355 this.data.inputValue = ''356 isEnd = false357 var temp = this.data.inputValue358 this.setData({359 inputValue:temp + '3'360 })361},362 onPoint:function(){363 if(this.data.inputValue != '0'){364 var temp = this.data.inputValue365 this.setData({366 inputValue:temp + '.'367 })368 }369 },370 onZero:function(){371 if(this.data.inputValue === '0' || isEnd)372 this.data.inputValue = ''373 isEnd = false374 //if(this.data.inputValue != '0'){375 var temp = this.data.inputValue376 this.setData({377 inputValue:temp + '0'378 })379 //}380},381 onEquality:function(){382 var temp = this.data.inputValue.split(action)383 formerNumer = Number(temp[0])384 latterNumber = Number(temp[1])385 if(isCalculating && formerNumer > 0 && latterNumber > 0){386 var total387 switch(action){388 case '+':{389 total = formerNumer + latterNumber390 }391 break;392 case '-':{393 total = formerNumer - latterNumber394 }395 break;396 case '*':{397 total = formerNumer * latterNumber398 }399 break;400 case '/':{401 total = formerNumer / latterNumber402 }403 break;404 }405 this.setData({406 inputValue:total.toFixed(0)407 })408 isCalculating = false409 action = ''410 isEnd = true411 this.animation.rotate(Math.random() * 720 - 360).step()412 .scale(Math.random() * 2).step()413 .translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()414 .skew(Math.random() * 90, Math.random() * 90).step()415 this.setData({ animation: this.animation.export() })416 }417 },418 /*419 å¤çå¨ç»ç¸å
³æä½420 */421 onRotate:function(){422 this.animation.rotate(Math.random() * 720 - 360).step()423 this.setData({424 animation:this.animation.export()425 })426 },427 onScale:function(){428 this.animation.scale(Math.random() * 2).step()429 this.setData({430 animation:this.animation.export()431 })432 },433 onTranslate:function(){434 this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()435 this.setData({436 animation:this.animation.export()437 })438 },439 onSkim:function(){440 this.animation.skew(Math.random() * 90, Math.random() * 90).step()441 this.setData({442 animation:this.animation.export()443 })444 },445 onRotateAndScale:function(){446 this.animation.rotate(Math.random() * 720 - 360)447 .scale(Math.random() * 2).step()448 this.setData({449 animation:this.animation.export()450 })451 },452 onTranslateAndSkim:function(){453 this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50)454 .skew(Math.random() * 90, Math.random() * 90).step()455 this.setData({456 animation:this.animation.export()457 })458 }459}...
RadioGroupForm.js
Source:RadioGroupForm.js
1/**2 * This example demonstrates the flexible layout capabilities of the RadioGroup class.3 * It also shows that you can validate radios as a group - try submitting the form before4 * changing any values to see this.5 */6Ext.define('KitchenSink.view.form.RadioGroupForm', {7 extend: 'Ext.form.Panel',8 xtype: 'form-radiogroup',9 10 // This example shares its ViewController with Checkbox Group Form11 controller: 'form-checkboxgroup',12 13 //<example>14 exampleTitle: 'Radio Groups',15 otherContent: [{16 type: 'ViewController',17 path: 'classic/samples/view/form/CheckboxGroupFormController.js'18 }],19 //</example>20 21 title: 'Radio Group Example',22 frame: true,23 width: 650,24 bodyPadding: 10,25 26 fieldDefaults: {27 labelWidth: 12028 },29 30 items: [{31 /*====================================================================32 * Individual checkbox/radio examples33 *====================================================================*/34 // Using checkbox/radio groups will generally be more convenient and flexible than35 // using individual checkbox and radio controls, but this shows that you can36 // certainly do so if you only have a single control at a time.37 xtype: 'container',38 layout: 'hbox',39 margin: '0 0 10',40 items: [{41 xtype: 'fieldset',42 flex: 1,43 title: 'Individual Checkboxes',44 checkboxToggle: true,45 defaultType: 'checkbox', // each item will be a checkbox46 layout: 'anchor',47 defaults: {48 anchor: '100%',49 hideEmptyLabel: false50 },51 items: [{52 xtype: 'textfield',53 name: 'txt-test1',54 fieldLabel: 'Alignment Test'55 }, {56 fieldLabel: 'Favorite Animals',57 boxLabel: 'Dog',58 name: 'fav-animal-dog',59 inputValue: 'dog'60 }, {61 boxLabel: 'Cat',62 name: 'fav-animal-cat',63 inputValue: 'cat'64 }, {65 checked: true,66 boxLabel: 'Monkey',67 name: 'fav-animal-monkey',68 inputValue: 'monkey'69 }]70 }, {71 xtype: 'component',72 width: 1073 }, {74 xtype: 'fieldset',75 flex: 1,76 title: 'Individual Radios',77 checkboxToggle: true,78 defaultType: 'radio', // each item will be a radio button79 layout: 'anchor',80 defaults: {81 anchor: '100%',82 hideEmptyLabel: false83 },84 items: [{85 xtype: 'textfield',86 name: 'txt-test2',87 fieldLabel: 'Alignment Test'88 }, {89 checked: true,90 fieldLabel: 'Favorite Color',91 boxLabel: 'Red',92 name: 'fav-color',93 inputValue: 'red'94 }, {95 boxLabel: 'Blue',96 name: 'fav-color',97 inputValue: 'blue'98 }, {99 boxLabel: 'Green',100 name: 'fav-color',101 inputValue: 'green'102 }]103 }]104 }, {105 /*====================================================================106 * RadioGroup examples107 *====================================================================*/108 // NOTE: These radio examples use the exact same options as the checkbox ones109 // above, so the comments will not be repeated. Please see comments above for110 // additional explanation on some config options.111 xtype: 'fieldset',112 title: 'Radio Groups',113 // in this section we use the form layout that will aggregate all of the fields114 // into a single table, rather than one table per field.115 layout: 'anchor',116 collapsible: true,117 defaults: {118 anchor: '100%'119 },120 items: [{121 xtype: 'textfield',122 name: 'txt-test4',123 fieldLabel: 'Alignment Test'124 },{125 xtype: 'radiogroup',126 fieldLabel: 'Auto Layout',127 cls: 'x-check-group-alt',128 name: 'rb-auto',129 items: [130 {boxLabel: 'Item 1', inputValue: 1},131 {boxLabel: 'Item 2', inputValue: 2, checked: true},132 {boxLabel: 'Item 3', inputValue: 3},133 {boxLabel: 'Item 4', inputValue: 4},134 {boxLabel: 'Item 5', inputValue: 5}135 ]136 },{137 xtype: 'radiogroup',138 fieldLabel: 'Single Column',139 columns: 1,140 name: 'rb-col',141 items: [142 {boxLabel: 'Item 1', inputValue: 1},143 {boxLabel: 'Item 2', inputValue: 2, checked: true},144 {boxLabel: 'Item 3', inputValue: 3}145 ]146 },{147 xtype: 'radiogroup',148 fieldLabel: 'Multi-Column (horizontal)',149 cls: 'x-check-group-alt',150 name: 'rb-horiz-1',151 columns: 3,152 items: [153 {boxLabel: 'Item 1', inputValue: 1},154 {boxLabel: 'Item 2', inputValue: 2, checked: true},155 {boxLabel: 'Item 3', inputValue: 3},156 {boxLabel: 'Item 4', inputValue: 4},157 {boxLabel: 'Item 5', inputValue: 5}158 ]159 },{160 xtype: 'radiogroup',161 fieldLabel: 'Multi-Column (vertical)',162 name: 'rb-vert',163 columns: 3,164 vertical: true,165 items: [166 {boxLabel: 'Item 1', inputValue: 1},167 {boxLabel: 'Item 2', inputValue: 2, checked: true},168 {boxLabel: 'Item 3', inputValue: 3},169 {boxLabel: 'Item 4', inputValue: 4},170 {boxLabel: 'Item 5', inputValue: 5}171 ]172 },{173 xtype: 'radiogroup',174 fieldLabel: 'Multi-Column<br />(custom widths)',175 cls: 'x-check-group-alt',176 columns: [100, 100],177 name: 'rb-custwidth',178 vertical: true,179 items: [180 {boxLabel: 'Item 1', inputValue: 1},181 {boxLabel: 'Item 2', inputValue: 2, checked: true},182 {boxLabel: 'Item 3', inputValue: 3},183 {boxLabel: 'Item 4', inputValue: 4},184 {boxLabel: 'Item 5', inputValue: 5}185 ]186 },{187 xtype: 'radiogroup',188 fieldLabel: 'Custom Layout<br />(w/ validation)',189 allowBlank: false,190 msgTarget: 'side',191 autoFitErrors: false,192 anchor: '-18',193 layout: 'column',194 defaultType: 'container',195 items: [{196 columnWidth: .25,197 items: [198 {xtype: 'component', html: 'Heading 1', cls:'x-form-check-group-label'},199 {xtype: 'radiofield', boxLabel: 'Item 1', name: 'rb-cust', inputValue: 1},200 {xtype: 'radiofield', boxLabel: 'Item 2', name: 'rb-cust', inputValue: 2}201 ]202 },{203 columnWidth: .4,204 items: [205 {xtype: 'component', html: 'Heading 2', cls:'x-form-check-group-label'},206 {xtype: 'radiofield', boxLabel: 'A long item just for fun', name: 'rb-cust', inputValue: 3}207 ]208 },{209 columnWidth: .25,210 items: [211 {xtype: 'component', html: 'Heading 3', cls:'x-form-check-group-label'},212 {xtype: 'radiofield', boxLabel: 'Item 4', name: 'rb-cust', inputValue: 4},213 {xtype: 'radiofield', boxLabel: 'Item 5', name: 'rb-cust', inputValue: 5}214 ]215 }]216 }]217 }],218 219 buttons: [{220 text: 'Save',221 handler: 'onSaveFormClick'222 }, {223 text: 'Reset',224 handler: 'onResetFormClick'225 }]...
wxmlto.js
Source:wxmlto.js
1$(function(){2 if($(".px-input")){3 $(".px-input").on("input propertychange",function(){4 var num=parseInt($(this).val()*2)+"rpx";5 $(".rpx-input").val(num);6 })7 $(".px-input-rem").on("input propertychange",function(){8 var num=Math.round($(this).val()/50*100)/100+"rem";9 $(".rem-input").val(num);10 })11 $(".rem-input-rpx").on("input propertychange",function(){12 var num=parseInt($(this).val()*100)+"rpx";13 $(".torpx-input").val(num);14 })15 $(".return_page").click(function(){16 history.go(-1);17 })18 changeKey();19 }20 21 function changeKey(){22 $('meta[name="keywords"]').attr("content",$("title").html());23 $('meta[name="description"]').attr("content",$("title").html());24 }25 // wxmlto26 $(".topBtn button").on("click",function(){27 $(this).addClass("active").siblings().removeClass("active")28 $(".change-result").html("");29 $(".change-infor").html("");30 })31 $(".inputText").on("input propertychange focus",function(e){32 var inputValue=$(this).val(); 33 34 if($(".active").attr("id")=="htmlToWxml"){35 console.log("æhtml转åæWXML")36 inputValue = inputValue.replace(/<div |<p |<table |<tr |<ul |<dl |<h1 |<h2 |<h3 |<h4 |<h5 |<h6 |<nav |<head |<header |<footer |<article |<aside /ig, '<view ')37 inputValue = inputValue.replace(/<div>|<p>|<table>|<tr>|<ul>|<dl>|<h1>|<h2>|<h3>|<h4>|<h5>|<h6>|<nav>|<head>|<header>|<footer>|<article>|<aside>/ig, '<view>')38 inputValue = inputValue.replace(/<\/div>|<\/p>|<\/table>|<\/tr>|<\/ul>|<\/dl>|<\/h1>|<\/h2>|<\/h3>|<\/h4>|<\/h6>|<\/h6>|<\/nav>|<\/head>|<\/header>|<\/footer>|<\/article>|<\/aside>/ig, '</view>')39 inputValue = inputValue.replace(/textarea/ig, 'rich-text')40 inputValue = inputValue.replace(/<span |<th |<td |<li |<dt /ig, '<text ')41 inputValue = inputValue.replace(/<span>|<\/span>|<th>|<td>|<li>|<dt>/ig, '<text>')42 inputValue = inputValue.replace(/<\/span>|<\/th>|<\/td>|<\/li>|<\/dt>/ig, '</text>')43 inputValue = inputValue.replace(/<img /ig, '<image ')44 inputValue = inputValue.replace(/<img>/ig, '<image>')45 inputValue = inputValue.replace(/<\/img>/ig, '</image>')46 inputValue = inputValue.replace(/onclick/ig, 'bindsubmit')47 // æ ç¾éé¢å«ææ ·å¼rpx48 var reg1=/-?\d+(\.\d+)?px/ig;49 var reg2=/-?\d+px/ig;50 var reg3=/-?\d+(\.\d+)?rem/ig;51 var reg4=/-?\d+rem/ig;52 inputValue=replaceAll(reg1,inputValue,2,"rpx")53 inputValue=replaceAll(reg2,inputValue,2,"rpx")54 inputValue=replaceAll(reg3,inputValue,100,"rpx")55 inputValue=replaceAll(reg4,inputValue,100,"rpx")56 57 $(".change-infor").html("html转å为WXMLæ¶ï¼é¡µé¢ä¸å¯è½å«æè¶
é¾æ¥åswiperè½®æå¾çæ ç¾ï¼è¯·æå¨ä¿®æ¹")58 }59 if($(".active").attr("id")=="wxmlToHtml"){60 console.log("æWXML转åæhtml")61 inputValue = inputValue.replace(/<view |<scroll-view |<cover-view |<swiper |<swiper-item |<checkbox-group |<radio-group /ig, '<div ')62 inputValue = inputValue.replace(/<view>|<scroll-view>|<cover-view>|<swiper>|<swiper-item>|<checkbox-group>|<radio-group>/ig, '<div>')63 inputValue = inputValue.replace(/<\/view>|<\/scroll-view>|<\/cover-view>|<\/swiper>|<\/swiper-item>|<\/checkbox-group>|<\/radio-group>/ig, '</div>')64 inputValue = inputValue.replace(/<text /ig, '<span ')65 inputValue = inputValue.replace(/<text>/ig, '<span>')66 inputValue = inputValue.replace(/<\/text>/ig, '</span>')67 inputValue = inputValue.replace(/<checkbox /ig, '<input type="checkbox" ')68 inputValue = inputValue.replace(/<checkbox>/ig, '<input type="checkbox"> ')69 inputValue = inputValue.replace(/<\/checkbox>/ig, '')70 inputValue = inputValue.replace(/<radio /ig, '<input type="radio" ')71 inputValue = inputValue.replace(/<radio>/ig, '<input type="radio"> ')72 inputValue = inputValue.replace(/<\/radio>/ig, '')73 inputValue = inputValue.replace(/<image |<cover-image /ig, '<img ')74 inputValue = inputValue.replace(/<image>|<cover-image>/ig, '<img>')75 inputValue = inputValue.replace(/<\/image>|<\/cover-image>/ig, '')76 inputValue = inputValue.replace(/bindsubmit/ig, 'onclick')77 inputValue = inputValue.replace(/rich-text/ig, 'textarea')78 // æ ç¾éé¢å«ææ ·å¼px79 var reg1=/-?\d+(\.\d+)?rpx/ig;80 var reg2=/-?\d+rpx/ig;81 inputValue=replaceAll(reg1,inputValue,0.5,"px")82 inputValue=replaceAll(reg2,inputValue,0.5,"px")83 $(".change-infor").html("WXML转å为htmlæ¶ï¼é¡µé¢ä¸å¯è½å«æwx-forç类似å°ç¨åºè¯æ³åæ°æ®ç±»ï¼{{}}ï¼è¿æä¸äºæ æ³æ¿æ¢çæ ç¾ï¼å¦iconï¼ï¼è¯·æå¨ä¿®æ¹")84 }85 if($(".active").attr("id")=="wxssToCss"){86 $(".change-infor").html("Wxss转å为cssè§åæ¯rpx->px")87 var reg1=/-?\d+(\.\d+)?rpx/ig;88 var reg2=/-?\d+rpx/ig;89 inputValue=replaceAll(reg1,inputValue,0.5,"px")90 inputValue=replaceAll(reg2,inputValue,0.5,"px")91 }92 if($(".active").attr("id")=="cssToWxss"){93 $(".change-infor").html("css转å为Wxssè§åæ¯px->rpxï¼rem->rpx")94 var reg1=/-?\d+(\.\d+)?px/ig;95 var reg2=/-?\d+px/ig;96 var reg3=/-?\d+(\.\d+)?rem/ig;97 var reg4=/-?\d+rem/ig;98 inputValue=replaceAll(reg1,inputValue,2,"rpx")99 inputValue=replaceAll(reg2,inputValue,2,"rpx")100 inputValue=replaceAll(reg3,inputValue,100,"rpx")101 inputValue=replaceAll(reg4,inputValue,100,"rpx")102 }103 if($(".active").attr("id")=="pxToRem"){104 $(".change-infor").html("")105 var reg1=/-?\d+(\.\d+)?px/ig;106 var reg2=/-?\d+px/ig;107 inputValue=replaceAll(reg1,inputValue,0.02,"rem")108 inputValue=replaceAll(reg2,inputValue,0.02,"rem")109 }110 $(".change-result").html(inputValue); 111 })112 $(".return_page").click(function(){113 history.go(-1);114 })115 // æç
§æ£åregætargetæ¾åºå¹¶ç¨replaceæç
§scaleï¼åunitåä½ï¼æ¹éæ¿æ¢æ116 function replaceAll(reg,target,scale,unit){117 var result = target.match(reg);118 for(var i in result){119 target = target.replace(result[i],parseFloat(result[i])*scale+unit)120 console.log(result[i],parseFloat(result[i])*scale+unit)121 console.log(target)122 }123 return target; 124 }...
fixtures.js
Source:fixtures.js
1var fixtures = {};2//fixtures for takeTopRow tests3fixtures.takeTopRow = {};4fixtures.takeTopRow.emptyMatrix = {5 inputValue: [[]],6 outputExpected: []7};8fixtures.takeTopRow.oneByOne = {9 inputValue: [[1]],10 outputExpected: [1]11};12fixtures.takeTopRow.oneRow = {13 inputValue: [[1,2,3]],14 outputExpected: [1,2,3]15};16fixtures.takeTopRow.oneColumn = {17 inputValue: [[1],[2],[3]],18 outputExpected: [1]19};20fixtures.takeTopRow.manyRows = {21 inputValue: [22 [1,2,3],23 [4,5,6],24 [7,8,9]25 ],26 outputExpected: [1,2,3]27};28//fixtures for removeTopRow tests29fixtures.removeTopRow = {};30fixtures.removeTopRow.emptyMatrix = {31 inputValue: [[]],32 outputExpected: []33};34fixtures.removeTopRow.oneByOne = {35 inputValue: [[1]],36 outputExpected: []37};38fixtures.removeTopRow.oneRow = {39 inputValue: [[1,2,3]],40 outputExpected: []41};42fixtures.removeTopRow.oneColumn = {43 inputValue: [[1],[2],[3]],44 outputExpected: [[2],[3]]45};46fixtures.removeTopRow.manyRows = {47 inputValue: [48 [1,2,3],49 [4,5,6],50 [7,8,9]51 ],52 outputExpected: [53 [4,5,6],54 [7,8,9]55 ]56};57//fixtures for takeRightColumn tests58fixtures.takeRightColumn = {};59fixtures.takeRightColumn.emptyMatrix = {60 inputValue: [[]],61 outputExpected: []62};63fixtures.takeRightColumn.oneByOne = {64 inputValue: [[1]],65 outputExpected: [1]66};67fixtures.takeRightColumn.oneRow = {68 inputValue: [[1,2,3]],69 outputExpected: [3]70};71fixtures.takeRightColumn.oneColumn = {72 inputValue: [[1],[2],[3]],73 outputExpected: [1,2,3]74};75fixtures.takeRightColumn.manyRows = {76 inputValue: [77 [1,2,3],78 [4,5,6],79 [7,8,9]80 ],81 outputExpected: [3,6,9]82};83//fixtures for removeRightColumn tests84fixtures.removeRightColumn = {};85fixtures.removeRightColumn.emptyMatrix = {86 inputValue: [[]],87 outputExpected: []88};89fixtures.removeRightColumn.oneByOne = {90 inputValue: [[1]],91 outputExpected: []92};93fixtures.removeRightColumn.oneRow = {94 inputValue: [[1,2,3]],95 outputExpected: [[1,2]]96};97fixtures.removeRightColumn.oneColumn = {98 inputValue: [[1],[2],[3]],99 outputExpected: []100};101fixtures.removeRightColumn.manyRows = {102 inputValue: [103 [1,2,3],104 [4,5,6],105 [7,8,9]106 ],107 outputExpected: [108 [1,2],109 [4,5],110 [7,8]111 ]112};113//fixtures for takeBottomRow tests114fixtures.takeBottomRow = {};115fixtures.takeBottomRow.emptyMatrix = {116 inputValue: [[]],117 outputExpected: []118};119fixtures.takeBottomRow.oneByOne = {120 inputValue: [[1]],121 outputExpected: [1]122};123fixtures.takeBottomRow.oneRow = {124 inputValue: [[1,2,3]],125 outputExpected: [1,2,3]126};127fixtures.takeBottomRow.oneColumn = {128 inputValue: [[1],[2],[3]],129 outputExpected: [3]130};131fixtures.takeBottomRow.manyRows = {132 inputValue: [133 [1,2,3],134 [4,5,6],135 [7,8,9]136 ],137 outputExpected: [7,8,9]138};139//fixtures for removeBottomRow tests140fixtures.removeBottomRow = {};141fixtures.removeBottomRow.emptyMatrix = {142 inputValue: [[]],143 outputExpected: []144};145fixtures.removeBottomRow.oneByOne = {146 inputValue: [[1]],147 outputExpected: []148};149fixtures.removeBottomRow.oneRow = {150 inputValue: [[1,2,3]],151 outputExpected: []152};153fixtures.removeBottomRow.oneColumn = {154 inputValue: [[1],[2],[3]],155 outputExpected: [[1],[2]]156};157fixtures.removeBottomRow.manyRows = {158 inputValue: [159 [1,2,3],160 [4,5,6],161 [7,8,9]162 ],163 outputExpected: [164 [1,2,3],165 [4,5,6]166 ]167};168//fixtures for takeLeftColumn tests169fixtures.takeLeftColumn = {};170fixtures.takeLeftColumn.emptyMatrix = {171 inputValue: [[]],172 outputExpected: []173};174fixtures.takeLeftColumn.oneByOne = {175 inputValue: [[1]],176 outputExpected: [1]177};178fixtures.takeLeftColumn.oneRow = {179 inputValue: [[1,2,3]],180 outputExpected: [1]181};182fixtures.takeLeftColumn.oneColumn = {183 inputValue: [[1],[2],[3]],184 outputExpected: [1,2,3]185};186fixtures.takeLeftColumn.manyRows = {187 inputValue: [188 [1,2,3],189 [4,5,6],190 [7,8,9]191 ],192 outputExpected: [1,4,7]193};194//fixtures for removeLeftColumn tests195fixtures.removeLeftColumn = {};196fixtures.removeLeftColumn.emptyMatrix = {197 inputValue: [[]],198 outputExpected: []199};200fixtures.removeLeftColumn.oneByOne = {201 inputValue: [[1]],202 outputExpected: []203};204fixtures.removeLeftColumn.oneRow = {205 inputValue: [[1,2,3]],206 outputExpected: [[2,3]]207};208fixtures.removeLeftColumn.oneColumn = {209 inputValue: [[1],[2],[3]],210 outputExpected: []211};212fixtures.removeLeftColumn.manyRows = {213 inputValue: [214 [1,2,3],215 [4,5,6],216 [7,8,9]217 ],218 outputExpected: [219 [2,3],220 [5,6],221 [8,9]222 ]223};224//fixtures for traverseClockwise tests225fixtures.traverseClockwise = {};226fixtures.traverseClockwise.emptyMatrix = {227 inputValue: [[]],228 outputExpected: []229};230fixtures.traverseClockwise.oneByOne = {231 inputValue: [[1]],232 outputExpected: [1]233};234fixtures.traverseClockwise.oneRow = {235 inputValue: [[1,2,3]],236 outputExpected: [1,2,3]237};238fixtures.traverseClockwise.oneColumn = {239 inputValue: [[1],[2],[3]],240 outputExpected: [1,2,3]241};242fixtures.traverseClockwise.twoByTwo = {243 inputValue: [244 [1,2],245 [3,4]246 ],247 outputExpected: [1,2,4,3]248};249fixtures.traverseClockwise.threeByThree = {250 inputValue: [251 [1,2,3],252 [4,5,6],253 [7,8,9]254 ],255 outputExpected: [1,2,3,6,9,8,7,4,5]256};257fixtures.traverseClockwise.threeByFour = {258 inputValue: [259 [1 ,2 ,3 ,4],260 [5 ,6 ,7 ,8],261 [9 ,10 ,11 ,12]262 ],263 outputExpected: [1,2,3,4,8,12,11,10,9,5,6,7]264};265fixtures.traverseClockwise.fourByFour = {266 inputValue: [267 [1 ,2 ,3 ,4],268 [5 ,6 ,7 ,8],269 [9 ,10 ,11 ,12],270 [13 ,14 ,15 ,16]271 ],272 outputExpected: [1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10]273};274fixtures.traverseClockwise.fourByFive = {275 inputValue: [276 [1 ,2 ,3 ,4 ,5],277 [6 ,7 ,8 ,9 ,10],278 [11 ,12 ,13 ,14 ,15],279 [16 ,17 ,18 ,19 ,20],280 ],281 outputExpected: [1,2,3,4,5,10,15,20,19,18,17,16,11,6,7,8,9,14,13,12]282};283//fixtures for traverseCounterClockwise tests284fixtures.traverseCounterClockwise = {};285fixtures.traverseCounterClockwise.emptyMatrix = {286 inputValue: [[]],287 outputExpected: []288};289fixtures.traverseCounterClockwise.oneByOne = {290 inputValue: [[1]],291 outputExpected: [1]292};293fixtures.traverseCounterClockwise.oneRow = {294 inputValue: [[1,2,3]],295 outputExpected: [1,2,3]296};297fixtures.traverseCounterClockwise.oneColumn = {298 inputValue: [[1],[2],[3]],299 outputExpected: [1,2,3]300};301fixtures.traverseCounterClockwise.twoByTwo = {302 inputValue: [303 [1,2],304 [3,4]305 ],306 outputExpected: [1,3,4,2]307};308fixtures.traverseCounterClockwise.threeByThree = {309 inputValue: [310 [1,2,3],311 [4,5,6],312 [7,8,9]313 ],314 outputExpected: [1,4,7,8,9,6,3,2,5]315};316fixtures.traverseCounterClockwise.threeByFour = {317 inputValue: [318 [1 ,2 ,3 ,4],319 [5 ,6 ,7 ,8],320 [9 ,10 ,11 ,12]321 ],322 outputExpected: [1,5,9,10,11,12,8,4,3,2,6,7]323};324fixtures.traverseCounterClockwise.fourByFour = {325 inputValue: [326 [1 ,2 ,3 ,4],327 [5 ,6 ,7 ,8],328 [9 ,10 ,11 ,12],329 [13 ,14 ,15 ,16]330 ],331 outputExpected: [1,5,9,13,14,15,16,12,8,4,3,2,6,10,11,7]332};333fixtures.traverseCounterClockwise.fourByFive = {334 inputValue: [335 [1 ,2 ,3 ,4 ,5],336 [6 ,7 ,8 ,9 ,10],337 [11 ,12 ,13 ,14 ,15],338 [16 ,17 ,18 ,19 ,20],339 ],340 outputExpected: [1,6,11,16,17,18,19,20,15,10,5,4,3,2,7,12,13,14,9,8]341};...
main.js
Source:main.js
1//...............................................mon resultat2let resultStyle = document.querySelector('.resultStyle');3//...............................................mes nombres4let nb1 = document.querySelector('#nb1');5let nb2 = document.querySelector('#nb2');6let nb3 = document.querySelector('#nb3');7let nb4 = document.querySelector('#nb4');8let nb5 = document.querySelector('#nb5');9let nb6 = document.querySelector('#nb6');10let nb7 = document.querySelector('#nb7');11let nb8 = document.querySelector('#nb8');12let nb9 = document.querySelector('#nb9');13let nb0 = document.querySelector('#nb0');14let pt = document.querySelector('#pt');15let check = document.querySelector('#check');16//.............................................mes operateurs17let add = document.querySelector('#add');18let substr = document.querySelector('#substr');19let multi = document.querySelector('#multi');20let divi = document.querySelector('#divi');21let cor = document.querySelector('#correction');22let egal = document.querySelector('#egal') 23//............................................mon input24let inputValue = document.querySelector("input");25//............................................mes values nombre26// nbA = Number(inputValue.value)27// console.log(nbA);28let nbA 29let nbB30let nbV = []31nb1.addEventListener("click",function() {32 nb1.value = "1"33 inputValue.value = inputValue.value + "1"34 resultStyle.innerHTML = inputValue.value35 console.log(inputValue.value);36})37nb2.addEventListener("click",function() {38 nb2.value = "2"39 inputValue.value = inputValue.value + "2"40 resultStyle.innerHTML = inputValue.value41 console.log(inputValue.value);42})43nb3.addEventListener("click",function() {44 nb3.value = "3"45 inputValue.value = inputValue.value + "3"46 resultStyle.innerHTML = inputValue.value47 console.log(inputValue.value);48})49nb4.addEventListener("click",function() {50 nb4.value = "4"51 inputValue.value = inputValue.value + "4"52 resultStyle.innerHTML = inputValue.value53 console.log(inputValue.value);54})55nb5.addEventListener("click",function() {56 nb5.value = "5"57 inputValue.value = inputValue.value + "5"58 resultStyle.innerHTML = inputValue.value59 console.log(inputValue.value);60})61nb6.addEventListener("click",function() {62 nb6.value = "6"63 inputValue.value = inputValue.value + "6"64 resultStyle.innerHTML = inputValue.value65 console.log(inputValue.value);66})67nb7.addEventListener("click",function() {68 nb7.value = "7"69 inputValue.value = inputValue.value + "7"70 resultStyle.innerHTML = inputValue.value71 console.log(inputValue.value);72})73nb8.addEventListener("click",function() {74 nb8.value = "8"75 inputValue.value = inputValue.value + "8"76 resultStyle.innerHTML = inputValue.value77 console.log(inputValue.value);78})79nb9.addEventListener("click",function() {80 nb9.value = "9"81 inputValue.value = inputValue.value + "9"82 resultStyle.innerHTML = inputValue.value83 console.log(inputValue.value);84})85nb0.addEventListener("click",function() {86 nb0.value = "0"87 inputValue.value = inputValue.value + "0"88 resultStyle.innerHTML = inputValue.value89 console.log(inputValue.value);90})91pt.addEventListener("click",function() {92 nb0.value = "."93 inputValue.value = inputValue.value + "."94 console.log(inputValue.value);95})96//..................................................mes operateur 97let op98add.addEventListener("click",function() {99 op = "+"100 nbA = Number(inputValue.value)101 nbV.push(nbA);102 inputValue.value = ''103 console.log(nbV);104})105substr.addEventListener("click",function() {106 op = "-"107 nbA = Number(inputValue.value)108 nbV.push(nbA);109 inputValue.value = ''110 console.log(nbV);111})112multi.addEventListener("click",function() {113 op = "*"114 nbA = Number(inputValue.value)115 nbV.push(nbA);116 inputValue.value = ''117 console.log(nbV);118})119divi.addEventListener("click",function() {120 op = "/"121 nbA = Number(inputValue.value)122 nbV.push(nbA);123 inputValue.value = ''124 console.log(nbV);125})126cor.addEventListener("click",function() {127 inputValue.value = ''128})129//............................................130egal.addEventListener("click",function () {131 switch (op) {132 case "+":133 nbB = Number(inputValue.value);134 nbV.push(nbB);135 resultStyle.innerHTML = Number(nbV[0]) + Number(nbV[1]) ;136 console.log(Number(nbV[0]) + Number(nbV[1]) );137 inputValue.value = ''138 nbV = []; 139 break;140 case "-":141 nbB = Number(inputValue.value);142 nbV.push(nbB);143 resultStyle.innerHTML = Number(nbV[0]) - Number(nbV[1]) ;144 console.log(Number(nbV[0]) - Number(nbV[1]) );145 inputValue.value = ''146 nbV = []; 147 break;148 case "*":149 nbB = Number(inputValue.value);150 nbV.push(nbB);151 resultStyle.innerHTML = Number(nbV[0]) * Number(nbV[1]) ;152 console.log(Number(nbV[0]) * Number(nbV[1]) );153 inputValue.value = ''154 nbV = []; 155 break;156 case "/":157 nbB = Number(inputValue.value);158 nbV.push(nbB);159 resultStyle.innerHTML = Number(nbV[0]) / Number(nbV[1]) ;160 console.log(Number(nbV[0]) / Number(nbV[1]) );161 inputValue.value = ''162 nbV = []; 163 break;164 165 }166})167//............................................................168check.onchange = function () {169 if(check.checked){170 inputValue.disabled = true;171 }else{172 inputValue.disabled = false;173 }174}175//...........................................style des boutons176let buttonStyle = document.querySelectorAll('button');177buttonStyle.forEach((e)=>{178 e.style.borderRadius = "50%"179 e.style.borderStyle = "none"180 e.style.backgroundColor = "pink"181 e.style.height = "20px"182 e.style.width = "20px"183 e.style.margin = "5px"184 e.style.boxShadow = "2px 2px 2px black"185 e.style.backgroundColor = "white"186 e.style.color = "pink"187 e.style.alignItems188})189//...................................................style de ma calculatrice190let calculStyle = document.querySelector(".colors");191calculStyle.style.backgroundColor = "pink"192calculStyle.style.width = "170px"193calculStyle.style.height = "160px"194calculStyle.style.borderRadius = "0 0 0 10px"195//.................................................196let result = document.querySelector("#result");197result.style.width = "170px"198result.style.height = "140px"199result.style.backgroundColor = "white"200result.style.border = "pink solid 10px"201result.style.borderRadius = "0 10px 10px 0"202result.style.textAlign = "center"203result.style.display = "flex"204result.style.justifyContent = "center"205result.style.alignItems = "center"206//.................................................207let contenu = document.querySelector('#contenu');208contenu.style.display = "flex"...
morse.js
Source:morse.js
1// --- Morse Code Translator --- //2// this is not a codewars.com kata //3// when sending morse code to the translator function, you must add an extra space between words to recieve readable text, otherwise the recieved text will only be one word.4const morseTranslator = (str) => {5 morseStrArr = str.split(' ')6 charStrArr = str.split('')7 var strArr = (morseStrArr[0] != '-' || morseStrArr[0] === '.' ? charStrArr : morseStrArr)8 var newString = ''9 strArr.forEach(inputValue => {10 // Alphabet characters11 if(inputValue === 'a' || inputValue === '.-') {(inputValue === 'a' ? newString += '.-' : newString += 'a')}12 if(inputValue === 'b' || inputValue === '-...') {(inputValue === 'b' ? newString += '-...' : newString += 'b')}13 if(inputValue === 'c' || inputValue === '-.-.') {(inputValue === 'c' ? newString += '-.-.' : newString += 'c')}14 if(inputValue === 'd' || inputValue === '-..') {(inputValue === 'd' ? newString += '-..' : newString += 'd')}15 if(inputValue === 'e' || inputValue === '.') {(inputValue === 'e' ? newString += '.' : newString += 'e')}16 if(inputValue === 'f' || inputValue === '.-..') {(inputValue === 'f' ? newString += '.-..' : newString += 'f')}17 if(inputValue === 'g' || inputValue === '--.') {(inputValue === 'g' ? newString += '--.' : newString += 'g')}18 if(inputValue === 'h' || inputValue === '....') {(inputValue === 'h' ? newString += '....' : newString += 'h')}19 if(inputValue === 'i' || inputValue === '..') {(inputValue === 'i' ? newString += '..' : newString += 'i')}20 if(inputValue === 'j' || inputValue === '.---') {(inputValue === 'j' ? newString += '.---' : newString += 'j')}21 if(inputValue === 'k' || inputValue === '-.-') {(inputValue === 'k' ? newString += '-.-' : newString += 'k')}22 if(inputValue === 'l' || inputValue === '.-..') {(inputValue === 'l' ? newString += '.-..' : newString += 'l')}23 if(inputValue === 'm' || inputValue === '--') {(inputValue === 'm' ? newString += '--' : newString += 'm')}24 if(inputValue === 'n' || inputValue === '-.') {(inputValue === 'n' ? newString += '-.' : newString += 'n')}25 if(inputValue === 'o' || inputValue === '---') {(inputValue === 'o' ? newString += '---' : newString += 'o')}26 if(inputValue === 'p' || inputValue === '.--.') {(inputValue === 'p' ? newString += '.--.' : newString += 'p')}27 if(inputValue === 'q' || inputValue === '--.-') {(inputValue === 'q' ? newString += '--.-' : newString += 'q')}28 if(inputValue === 'r' || inputValue === '.-.') {(inputValue === 'r' ? newString += '.-.' : newString += 'r')}29 if(inputValue === 's' || inputValue === '...') {(inputValue === 's' ? newString += '...' : newString += 's')}30 if(inputValue === 't' || inputValue === '-') {(inputValue === 't' ? newString += '-' : newString += 't')}31 if(inputValue === 'u' || inputValue === '..-') {(inputValue === 'u' ? newString += '..-' : newString += 'u')}32 if(inputValue === 'v' || inputValue === '...-') {(inputValue === 'v' ? newString += '...-' : newString += 'v')}33 if(inputValue === 'w' || inputValue === '.--') {(inputValue === 'w' ? newString += '.--' : newString += 'w')}34 if(inputValue === 'x' || inputValue === '-..-') {(inputValue === 'x' ? newString += '-..-' : newString += 'x')}35 if(inputValue === 'y' || inputValue === '-.--') {(inputValue === 'y' ? newString += '-.--' : newString += 'y')}36 if(inputValue === 'z' || inputValue === '--..') {(inputValue === 'z' ? newString += '--..' : newString += 'z')}37 // Numerical characters38 if(inputValue === '1' || inputValue === '.----') {(inputValue === '1' ? newString += '.----' : newString += '1')}39 if(inputValue === '2' || inputValue === '..---') {(inputValue === '2' ? newString += '..---' : newString += '2')}40 if(inputValue === '3' || inputValue === '...--') {(inputValue === '3' ? newString += '...--' : newString += '3')}41 if(inputValue === '4' || inputValue === '....-') {(inputValue === '4' ? newString += '....-' : newString += '4')}42 if(inputValue === '5' || inputValue === '.....') {(inputValue === '5' ? newString += '.....' : newString += '5')}43 if(inputValue === '6' || inputValue === '-....') {(inputValue === '6' ? newString += '-....' : newString += '6')}44 if(inputValue === '7' || inputValue === '--...') {(inputValue === '7' ? newString += '--...' : newString += '7')}45 if(inputValue === '8' || inputValue === '---..') {(inputValue === '8' ? newString += '---..' : newString += '8')}46 if(inputValue === '9' || inputValue === '----.') {(inputValue === '9' ? newString += '----.' : newString += '9')}47 if(inputValue === '0' || inputValue === '-----') {(inputValue === '0' ? newString += '-----' : newString += '0')}48 // Spacing according to conversion type49 if(strArr != morseStrArr){newString += ' '} // adds space between characters if translating to Morse50 if(inputValue === '') {newString += ' '} // adds space between words if translating to human readable words51 })52 return('newString',newString)53}54const morseString = '- .... .. ... .. ... .- ... - .-. .. -. --. -.... ..--- ----- ..... --...'55const wordString = 'this is a string 798654'56// morseTranslator(morseString)...
App.js
Source:App.js
1import React, { Component } from 'react';2import { View, Text, AppRegistry } from 'react-native';3import Style from './src/Style';4import InputButton from './src/InputButton';5const inputButtons = [6 ['C', 'CE', "", ""],7 [1, 2, 3, '/'],8 [4, 5, 6, '*'],9 [7, 8, 9, '-'],10 [0, '.', '=', '+'],11];12class ReactCalculator extends Component {13 constructor(props) {14 super(props);15 this.state = {16 inputValue: 0,17 previousInputValue: 0,18 selectedSymbol: null,19 displayValue: 0,20 isFloating: false21 }22 }23 render() {24 return (25 <View style={Style.rootContainer}>26 <View style={Style.displayContainer}>27 <Text style={Style.displayText}>{this.state.displayValue}</Text>28 </View>29 <View style={Style.inputContainer}>30 {this._renderInputButtons()}31 </View>32 </View>33 );34 }35 _renderInputButtons() {36 let views = [];37 for (var r = 0; r < inputButtons.length; r++) {38 let row = inputButtons[r];39 let inputRow = [];40 for (var i = 0; i < row.length; i++) {41 let input = row[i];42 inputRow.push(43 <InputButton 44 value={input} 45 key={r + '-' + i}46 onPress={this._onInputButtonPressed.bind(this, input)}/>47 );48 }49 views.push(50 <View style={Style.inputRow} key={'row-' + r}>51 {inputRow}52 </View>53 );54 }55 return views;56 }57 _onInputButtonPressed(input) {58 switch(typeof input) {59 case 'number':60 return this._handleNumberInput(input);61 case 'string':62 return this._handleStringInput(input);63 }64 }65 _handleNumberInput(num) {66 let splitInputValue = this.state.inputValue.toString().split('.');67 let floatingDigitCount = splitInputValue.length > 1 ? splitInputValue[1].length : 0;68 let inputValue = this.state.isFloating ? parseFloat((this.state.inputValue + (num * Math.pow(0.1, floatingDigitCount + 1))).toFixed(floatingDigitCount + 1)) : (this.state.inputValue * 10) + num;69 this.setState({70 inputValue,71 displayValue: inputValue72 })73 }74 _handleStringInput(str) {75 switch(str) {76 case '/':77 case '*':78 case '+':79 case '-':80 this.setState({81 inputValue: 0,82 previousInputValue: this.state.inputValue,83 selectedSymbol: str,84 displayValue: str,85 isFloating: false86 });87 break;88 case '.':89 this.setState({90 isFloating: true91 });92 break;93 case 'C':94 if(this.state.isFloating) {95 let floatingDigitsCount = this.state.inputValue.toString().split('.')[1].length;96 let inputValue = this.state.inputValue.toString();97 inputValue = parseFloat(inputValue.substr(0, inputValue.length - 1))98 this.setState({99 inputValue,100 displayValue: inputValue101 });102 if(floatingDigitsCount == 1) {103 this.setState({104 isFloating: false105 });106 }107 } else {108 this.setState({109 inputValue: Math.floor(this.state.inputValue / 10),110 displayValue: Math.floor(this.state.inputValue / 10)111 });112 }113 break;114 case 'CE':115 this.setState({116 inputValue: 0,117 previousInputValue: 0,118 selectedSymbol: null,119 displayValue: 0,120 isFloating: false121 });122 break;123 case '=':124 let symbol = this.state.selectedSymbol,125 inputValue = this.state.inputValue,126 previousInputValue = this.state.previousInputValue;127 if(!symbol) {128 return;129 }130 if(symbol == '/' && inputValue == 0) {131 this.setState({132 inputValue: 0,133 previousInputValue: 0,134 selectedSymbol: null,135 displayValue: "ERROR",136 isFloating: false137 });138 return;139 }140 this.setState({141 inputValue: 0,142 previousInputValue: 0,143 selectedSymbol: null,144 displayValue: eval(previousInputValue + symbol + inputValue),145 isFloating: false146 });147 148 break;149 }150 }151}...
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 await page.fill('input[title="Search"]', 'Playwright');7 await page.click('text=Google Search');8 await page.waitForNavigation();9 await page.screenshot({ path: `example.png` });10 await browser.close();11})();
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 await page.type('input[name="q"]', 'Playwright');7 await page.click('text=Google Search');8 await page.screenshot({ path: `example.png` });9 await browser.close();10})();
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 await page.click('input[placeholder="What needs to be done?"]');7 await page.keyboard.type('Use Playwright');8 await page.keyboard.press('Enter');9 await page.screenshot({ path: `example.png` });10 await browser.close();11})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=Docs');7 await page.click('input[name="q"]');8 await page.fill('input[name="q"]', 'api');9 await page.press('input[name="q"]', 'Enter');10 await context.close();11 await browser.close();12})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false }{ headless: false });4 const page = await browser.newPage();5 await page.waitForSelector('text="Get started"');6 await page.click('text="Get started"');7 await page.waitForSeleatwr('text="API"');8 await page.click('text="API"');9 await page.waitForSelector('text="inputValue"');10 await page.click('text="inputValue"');11 await page.waitForSelector('text="inputValue"');12 await page.click('text="inputValue"');13 await page.waitForSelector('text="inputValue"');14 await page.click('text="inputValue"');15 await page.waitForSelector('text="inputValue"');16 await page.click('text="inputValue"');17 await page.waitForSelector('text="inputValue"');18 await page.click('text="inputValue"');19 await page.waitForSelector('text="inputValue"');20 await page.click('text="inputValue"');21 await page.waitForSelector('text="inputValue"');22 await page.click('text="inputValue"');23 await page.waitForSelector('text="inputValue"');24 await page.click('text="inputValue"');25})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 coait page.waitForSelector('text="Get started"');6 await page.click('text="Get started"');7 await page.waitForSelector('text="API"');8 await page.click('text="API"');9 await page.waitForSelector('text="inputValue"');10 await page.click('text="inputValue"');11 await page.waitForSelector('text="inputValue"');12 await page.click('text="inputValue"');13 await page.waitForSelector('text="inputValue"');14 await page.click('text="inputValue"');15 await page.waitForSelector('text="inputValue"');16 await page.click('text="inputValue"');17 await page.waitForSelector('text="inputValue"');18 await page.click('text="inputValue"');19 await page.waitForSelector('text="inputValue"');20 await page.click('text="inputValue"');21 await page.waitForSelector('text="inputValue"');22 await page.click('text="inputValue"');23 await page.waitForSelector('text="inputValue"');24 await page.click('text="inputValue"');25})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const search = await page.$('input[placeholder="Search"]');6 await search.inputValue('inputValue');7 await browser.close();8})();
Using AI Code Generation
1const { inputValue } = require('@playwright/test');2inputValue('input', 'Hello, World!');3### `inputValue(selector, value)`4const elementHandle = await page.$(selector);5await elementHandle.setInputFiles(value);6[MIT](./LICENSE) async ({ page }) => {7 const title = page.locator('text=Get started');8 await expect(title).toBeVisible();9 await expect(title).toHaveText('Get started');10});
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=Docs');7 await page.click('input[name="q"]');8 await page.fill('input[name="q"]', 'api');9 await page.press('input[name="q"]', 'Enter');10 await context.close();11 await browser.close();12})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const search = await page.$('input[placeholder="Search"]');6 await search.inputValue('inputValue');7 await browser.close();8})();
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!!