Best JavaScript code snippet using cypress
realUsers.js
Source:realUsers.js
1exports.realUsers = [2 {3 budget: 3,4 newMatch: false,5 personalityVector: [6 1,7 1,8 1,9 0,10 0,11 1,12 1,13 -1,14 0,15 1,16 -2,17 -1,18 -1,19 -1,20 -1,21 -1,22 2,23 1,24 0,25 226 ],27 gettingCloudMatched: false,28 uid: "0M01ZrNAJ7X8fuCXMXSifoMLju72",29 propertyVector: [30 3,31 3,32 3,33 3,34 335 ],36 phone: "",37 newness: 3,38 currentMatches: { },39 gender: "Male",40 tos: true,41 email: "jomarn64@gmail.com",42 workplace: "Martin Linges Vei 33",43 fieldOfStudy: "Computer science",44 matchLocation: "Oslo",45 photoURL: "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",46 readyToMatch: false,47 propertySize: 3,48 university: "NTNU",49 displayName: "johan johnsen",50 age: "20",51 studyProgramme: "Computer science"52 },53 {54 displayName: "Ãyvind Maraak",55 age: "24",56 studyProgramme: "Ãk.Adm",57 budget: 3,58 newMatch: true,59 personalityVector: [60 1,61 1,62 1,63 -1,64 1,65 0,66 -1,67 2,68 1,69 1,70 0,71 -1,72 -2,73 -1,74 -2,75 1,76 2,77 0,78 2,79 180 ],81 gettingCloudMatched: false,82 uid: "2GJ58Ne2fGRFytAHKzmwI5wzJBd2",83 propertyVector: [84 3,85 3,86 3,87 3,88 389 ],90 phone: "",91 newness: 3,92 currentMatches: { },93 gender: "Male",94 tos: true,95 email: "oemaraak@gmail.com",96 workplace: "Stovner Senter, Oslo, Norway",97 workplaceLatLng: {98 lat: 59.9610862,99 lng: 10.92491280000002100 },101 fieldOfStudy: "Ãk.Adm",102 matchLocation: "Oslo",103 photoURL: "https://lh3.googleusercontent.com/-tvRVb9yYhKU/AAAAAAAAAAI/AAAAAAAAASo/5WhRZVJzLDk/photo.jpg",104 readyToMatch: false,105 propertySize: 3,106 university: "NTNU"107 },108 {109 gender: "Male",110 email: "hello@yaps.life",111 workplace: "StartupLab, Gaustadalléen, Oslo, Norway",112 fieldOfStudy: "Computer Science",113 photoURL: "https://lh4.googleusercontent.com/-yt5DP6I9IDA/AAAAAAAAAAI/AAAAAAAAABQ/Ai8ugMzz9iQ/photo.jpg",114 readyToMatch: false,115 university: "NTNU",116 displayName: "Kristian Elset Bø",117 studyProgramme: "Datateknologi",118 rentFrom: "2018-06-01T07:00:00.000Z",119 budget: 2,120 personalityVector: [121 1,122 1,123 1,124 -1,125 1,126 2,127 -1,128 -1,129 1,130 -1,131 1,132 -1,133 0,134 1,135 1,136 1,137 1,138 1,139 -1,140 1141 ],142 uid: "3neRxD0eNheokKQbeN9ozlIsorJ2",143 gettingCloudMatched: false,144 newness: 3,145 phone: "",146 currentMatches: { },147 tos: true,148 workplaceLatLng: {149 lng: 10.716285299999981,150 lat: 59.94195629999999151 },152 matchLocation: "Oslo",153 size: 3,154 rentTo: "2018-08-31T07:00:00.000Z",155 age: "25",156 newMatch: true,157 propertyVector: [158 3,159 3,160 3,161 3162 ]163 },164 {165 newMatch: false,166 propertyVector: [167 3,168 5,169 1,170 3171 ],172 gender: "Male",173 email: "casp.feng@gmail.com",174 workplace: "Blindern High School, Sognsveien, Oslo, Norway",175 fieldOfStudy: "Computer Science",176 photoURL: "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",177 readyToMatch: true,178 university: "NTNU",179 displayName: "Casperf",180 newMatches: true,181 studyProgramme: "Computer Science",182 budget: 3,183 personalityVector: [184 1,185 -1,186 -1,187 -2,188 0,189 -1,190 2,191 0,192 1,193 0,194 1,195 -2,196 -2,197 -2,198 0,199 2,200 2,201 0,202 2,203 1204 ],205 gettingCloudMatched: false,206 uid: "8LhfxDrSJ4Qd2RHQ7bHCSIbkijL2",207 newness: 1,208 phone: "",209 currentMatches: { },210 tos: true,211 workplaceLatLng: {212 lat: 59.94982570000001,213 lng: 10.72752760000003214 },215 matchLocation: "Oslo",216 propertySize: 5,217 age: "22"218 },219 {220 propertyVector: [221 3,222 1,223 3,224 3225 ],226 gettingettingCloudMatched: 0,227 phone: "",228 currentMatches: {229 5f94dcb9-b69c-4ba0-bff3-426e1d2e106a: {230 matchId: "5f94dcb9-b69c-4ba0-bff3-426e1d2e106a",231 timeStamp: 1526985900063232 }233 },234 gender: "Male",235 tos: true,236 email: "lindsaymillar33@gmail.com",237 workplace: "OSLO - PSYKOLOG DE LANGE, Torggata, Oslo, Norway",238 workplaceLatLng: {239 lat: 59.9158796,240 lng: 10.750738100000035241 },242 fieldOfStudy: "Finance",243 matchLocation: "Oslo",244 photoURL: "",245 readyToMatch: true,246 rentTo: "2018-08-30T14:00:00.000Z",247 university: "BI",248 displayName: "Lindsay",249 age: "22",250 newMatches: false,251 loginProvider: "email",252 rentFrom: "2018-05-31T14:00:00.000Z",253 personalityVector: [254 3,255 3,256 3,257 3,258 3,259 3,260 3,261 3,262 3,263 3,264 3,265 3,266 3,267 3,268 3,269 3,270 3,271 3,272 3,273 3274 ],275 gettingCloudMatched: 90,276 uid: "8YDeOADNeleJMYq63x3Pp9bZ1SI2"277 },278 {279 rentFrom: "2018-06-09T22:00:00.000Z",280 personalityVector: [281 2,282 0,283 -1,284 0,285 1,286 1,287 1,288 -1,289 1,290 -1,291 0,292 0,293 -2,294 -2,295 -2,296 2,297 2,298 2,299 2,300 2301 ],302 uid: "B7ppzALFiMR8QIUgEcxhK69vGm62",303 propertyVector: [304 1,305 3,306 3,307 3308 ],309 phone: "",310 currentMatches: { },311 gender: "Male",312 tos: true,313 email: "okke55@hotmail.com",314 workplace: "Oslo City, Stenersgata, Oslo, Norway",315 workplaceLatLng: {316 lat: 59.9126918,317 lng: 10.752917000000025318 },319 fieldOfStudy: "Computer Science",320 matchLocation: "Oslo",321 photoURL: "https://graph.facebook.com/10155133054666673/picture?type=large&width=720&height=720",322 readyToMatch: true,323 rentTo: "2018-07-05T22:00:00.000Z",324 university: "NTNU",325 displayName: "Oskar Svendsen",326 age: "23",327 loginProvider: "facebook"328 },329 {330 rentTo: "2018-08-30T14:00:00.000Z",331 university: "NTNU",332 displayName: "Brage West Mothes",333 age: "22",334 newMatches: false,335 loginProvider: "facebook",336 rentFrom: "2018-06-30T14:00:00.000Z",337 personalityVector: [338 0,339 1,340 0,341 0,342 1,343 1,344 1,345 0,346 2,347 1,348 -1,349 -2,350 -2,351 -1,352 -1,353 1,354 2,355 1,356 2,357 2358 ],359 gettingCloudMatched: false,360 uid: "DFZiUp7o3eftrr6O8QDVoLcp5Xk1",361 propertyVector: [362 1,363 3,364 3,365 3366 ],367 phone: "",368 currentMatches: { },369 gender: "Male",370 tos: true,371 email: "brage.elias@online.no",372 workplace: "Aker BioMarine, Oksenøyveien, Lysaker, Norge",373 workplaceLatLng: {374 lat: 59.9052282,375 lng: 10.62539930000003376 },377 fieldOfStudy: "Marine Engineering",378 matchLocation: "Oslo",379 photoURL: "https://graph.facebook.com/10216901332350728/picture?type=large&width=720&height=720",380 readyToMatch: true381 },382 {383 tos: true,384 email: "bakristiansen@me.com",385 workplace: "Sentralstasjonen fysioterapi og Manuellterapi AS, Storgata 10B, Oslo, Norge",386 workplaceLatLng: {387 lat: 59.9130807,388 lng: 10.749425900000006389 },390 fieldOfStudy: "Design",391 matchLocation: "Oslo",392 photoURL: "",393 readyToMatch: false,394 rentTo: "2018-07-28T22:00:00.000Z",395 university: "UIO",396 displayName: "Sa",397 age: "65",398 newMatches: false,399 loginProvider: "email",400 rentFrom: "2018-05-27T22:00:00.000Z",401 personalityVector: [402 -2,403 -2,404 -2,405 -2,406 1,407 0,408 1,409 0,410 1,411 1,412 2,413 0,414 2,415 1,416 1,417 0,418 1,419 0,420 2,421 0422 ],423 gettingCloudMatched: false,424 uid: "ETVOtpXjsGgvO0wpFDJh5HWD88v2",425 propertyVector: [426 1,427 1,428 3,429 3430 ],431 phone: "",432 currentMatches: { },433 gender: "Male"434 },435 {436 loginProvider: "facebook",437 rentFrom: "2018-05-31T22:00:00.000Z",438 personalityVector: [439 1,440 1,441 0,442 0,443 1,444 1,445 0,446 0,447 1,448 0,449 0,450 -1,451 -1,452 0,453 0,454 0,455 0,456 0,457 0,458 0459 ],460 gettingCloudMatched: false,461 uid: "HyazvztrJ8aBYiAkoGN4XuZ0Rhn1",462 propertyVector: [463 3,464 3,465 3,466 3467 ],468 phone: "",469 currentMatches: { },470 gender: "Male",471 tos: true,472 email: "jens.lillethun@gmail.com",473 workplace: "Akershusstranda 21, 0150 Oslo",474 workplaceLatLng: {475 lat: 59.90796340000001,476 lng: 10.734351699999934477 },478 fieldOfStudy: "Finance",479 matchLocation: "oslo",480 photoURL: "https://graph.facebook.com/10157533547234762/picture?type=large&width=720&height=720",481 readyToMatch: true,482 rentTo: "2018-08-30T22:00:00.000Z",483 university: "NTNU",484 displayName: "Jens Lillethun",485 age: "23",486 newMatches: false487 },488 {489 rentTo: "2018-08-30T22:00:00.000Z",490 university: "NTNU",491 displayName: "Marius Engan Kran",492 age: "22",493 newMatches: true,494 loginProvider: "google",495 rentFrom: "2018-05-31T22:00:00.000Z",496 personalityVector: [497 3,498 3,499 3,500 3,501 3,502 3,503 3,504 3,505 3,506 3,507 3,508 3,509 3,510 3,511 3,512 3,513 3,514 3,515 3,516 3517 ],518 gettingCloudMatched: 0,519 uid: "I42aqsst0kY6NDYboj2TmRQi9k13",520 propertyVector: [521 1,522 3,523 3,524 5525 ],526 phone: "",527 currentMatches: { },528 gender: "Male",529 tos: true,530 email: "mariuskran@gmail.com",531 workplace: "Aker Brygge Marina, Stranden, Oslo, Norge",532 workplaceLatLng: {533 lat: 59.9084141,534 lng: 10.7259775535 },536 fieldOfStudy: "Computer Science",537 matchLocation: "Oslo",538 photoURL: "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",539 readyToMatch: true540 },541 {542 readyToMatch: false,543 propertySize: 3,544 university: "NTNU",545 displayName: "William âcEnseâ Kvaale",546 age: "22",547 studyProgramme: "Computer Science",548 budget: 3,549 newMatch: true,550 personalityVector: [551 2,552 1,553 0,554 2,555 1,556 0,557 2,558 0,559 2,560 2,561 -1,562 0,563 0,564 -2,565 -1,566 2,567 2,568 2,569 2,570 2571 ],572 gettingCloudMatched: true,573 uid: "Is0H5IQ5GBM3ntyJmFqpOAOfGmS2",574 propertyVector: [575 3,576 3,577 3,578 3579 ],580 phone: "",581 newness: 3,582 currentMatches: {583 310730a2-43bb-41b3-9895-b7f57ec660ce: {584 matchId: "310730a2-43bb-41b3-9895-b7f57ec660ce",585 timeStamp: "2018-05-31T08:54:09.537Z"586 }587 },588 gender: "Male",589 tos: true,590 email: "wgkvaale@gmail.com",591 workplace: "Mesh, Tordenskiolds gate, Oslo, Norge",592 workplaceLatLng: {593 lat: 59.91314159999999,594 lng: 10.736358300000006595 },596 fieldOfStudy: "Computer Science",597 matchLocation: "Oslo",598 photoURL: "https://lh4.googleusercontent.com/-A1CrAewMDvA/AAAAAAAAAAI/AAAAAAAABaM/0YjTLogOPXI/photo.jpg"599 },600 {601 uid: "L264JmLMZaYiFH5vqJnFL1ufRnJ2",602 propertyVector: [603 3,604 3,605 5,606 3607 ],608 phone: "",609 gender: "Male",610 tos: true,611 email: "matshenrik8@hotmail.com",612 workplace: "Norges Bank, Bankplassen, Oslo, Norge",613 workplaceLatLng: {614 lng: 10.742357399999946,615 lat: 59.9086222616 },617 fieldOfStudy: "Computer Science",618 matchLocation: "Oslo",619 photoURL: "",620 readyToMatch: true,621 rentTo: "2018-08-30T22:00:00.000Z",622 university: "NTNU",623 displayName: "Mats Egedal",624 age: "24",625 loginProvider: "email",626 rentFrom: "2018-05-31T22:00:00.000Z",627 personalityVector: [628 -1,629 0,630 0,631 0,632 -1,633 -1,634 2,635 2,636 2,637 2,638 0,639 0,640 0,641 -3,642 -1,643 1,644 2,645 -1,646 1,647 2648 ]649 },650 {651 workplace: "Arkwright X, Grundingen, Oslo, Norge",652 workplaceLatLng: {653 lng: 10.72781140000006,654 lat: 59.9103539655 },656 fieldOfStudy: "Computer Science",657 matchLocation: "Oslo",658 photoURL: "https://graph.facebook.com/10160290874250463/picture?type=large&width=720&height=720",659 readyToMatch: true,660 rentTo: "2018-07-18T22:00:00.000Z",661 university: "NTNU",662 displayName: "PÃ¥l Bergerskogen",663 age: "24",664 newMatches: false,665 loginProvider: "facebook",666 rentFrom: "2018-06-08T22:00:00.000Z",667 personalityVector: [668 -1,669 -1,670 2,671 0,672 1,673 1,674 0,675 0,676 2,677 0,678 -1,679 0,680 0,681 0,682 -1,683 2,684 2,685 2,686 2,687 1688 ],689 gettingCloudMatched: false,690 uid: "Leerh3Br7yfK52u8VIJAspsTV003",691 propertyVector: [692 1,693 3,694 3,695 3696 ],697 phone: "",698 currentMatches: { },699 gender: "Male",700 tos: true,701 email: "pal.bergerskogen@gmail.com"702 },703 {704 matchLocation: "Oslo",705 photoURL: "https://graph.facebook.com/10214533581709153/picture?type=large&width=720&height=720",706 readyToMatch: true,707 rentTo: "2018-08-09T22:00:00.000Z",708 university: "NTNU",709 displayName: "Morten Stulen",710 age: "24",711 newMatches: true,712 loginProvider: "facebook",713 rentFrom: "2018-06-09T22:00:00.000Z",714 personalityVector: [715 1,716 1,717 -1,718 0,719 0,720 0,721 0,722 -2,723 0,724 1,725 0,726 0,727 2,728 -1,729 0,730 1,731 1,732 0,733 1,734 2735 ],736 gettingCloudMatched: false,737 uid: "LgJbqxzJTJQJbIi36W6b7oWEsp93",738 propertyVector: [739 3,740 3,741 3,742 3743 ],744 phone: "",745 currentMatches: { },746 gender: "Male",747 tos: true,748 email: "stulenmorten@gmail.com",749 workplace: "Capra Consulting AS, Stenersgata, Oslo, Norge",750 workplaceLatLng: {751 lat: 59.9130579,752 lng: 10.751287199999979753 },754 fieldOfStudy: "Computer Science"755 },756 {757 loginProvider: "facebook",758 rentFrom: "2018-07-30T22:00:00.000Z",759 personalityVector: [760 -1,761 -3,762 -3,763 -1,764 -3,765 -3,766 1,767 1,768 1,769 1,770 2,771 -3,772 0,773 -3,774 1,775 1,776 1,777 1,778 1,779 1780 ],781 gettingCloudMatched: 0,782 uid: "Mjao1ljyWjb9MOcVSTnxCN21zix2",783 propertyVector: [784 3,785 3,786 3,787 3788 ],789 phone: "",790 currentMatches: {791 3e9294a0-321b-42e6-8d56-b14b6c09f425: {792 matchId: "3e9294a0-321b-42e6-8d56-b14b6c09f425",793 timeStamp: "2018-05-31T10:21:33.449Z"794 },795 bc417588-8bb5-45f5-95cf-e294ffbd65ff: {796 matchId: "bc417588-8bb5-45f5-95cf-e294ffbd65ff",797 timeStamp: "2018-05-31T10:21:43.561Z"798 },799 b8bd7505-1acc-480d-a257-7fa8e379e1b4: {800 matchId: "b8bd7505-1acc-480d-a257-7fa8e379e1b4",801 timeStamp: "2018-05-31T10:15:22.557Z"802 }803 },804 gender: "Male",805 tos: true,806 email: "mathiasiden@me.com",807 workplace: "Netlight AS, Karl Johans gate, Oslo, Norge",808 workplaceLatLng: {809 lng: 10.741938699999992,810 lat: 59.9131672811 },812 fieldOfStudy: "Computer Science",813 matchLocation: "Oslo",814 photoURL: "https://graph.facebook.com/10156159016841955/picture?type=large&width=720&height=720",815 readyToMatch: true,816 rentTo: "2018-08-31T22:00:00.000Z",817 university: "NTNU",818 displayName: "Mathias Iden",819 age: "24",820 newMatches: true821 },822 {823 currentMatches: { },824 gender: "Gutt",825 tos: true,826 email: "mnch.moritz6@gmail.com",827 workplace: "Oslo, Noruega",828 workplaceLatLng: {829 lat: 59.9138688,830 lng: 10.752245399999993831 },832 fieldOfStudy: "Data",833 matchLocation: "Oslo",834 photoURL: "https://lh5.googleusercontent.com/-mHjWN0WPeec/AAAAAAAAAAI/AAAAAAAAHA0/hVsUEpMOiGM/photo.jpg",835 readyToMatch: false,836 propertySize: 3,837 university: "NTNU",838 displayName: "Moritz M",839 age: "23",840 studyProgramme: "Data",841 budget: 3,842 newMatch: true,843 personalityVector: [844 1,845 0,846 0,847 2,848 1,849 2,850 1,851 1,852 0,853 1,854 1,855 0,856 1,857 0,858 1,859 0,860 1,861 1,862 1,863 1864 ],865 gettingCloudMatched: false,866 uid: "UBavdmnoNnhIN4CFeNnTdAVlkh42",867 propertyVector: [868 3,869 3,870 3,871 3872 ],873 phone: "",874 newness: 3875 },876 {877 uid: "WaIVUhvQBkUZ0OdxllmroNh9u222",878 propertyVector: [879 3,880 3,881 3,882 3883 ],884 phone: "",885 currentMatches: { },886 gender: "Male",887 tos: true,888 email: "sprekasus@gmail.com",889 workplace: "",890 fieldOfStudy: "Computer Science",891 matchLocation: "Oslo",892 photoURL: "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",893 readyToMatch: false,894 propertySize: 3,895 university: "NTNU",896 displayName: "Jostein Brevik",897 standard: 3,898 age: "22",899 studyProgramme: "Computer Science",900 budget: 3,901 personalityVector: [902 0,903 -1,904 0,905 1,906 1,907 -1,908 1,909 2,910 2,911 1,912 0,913 -1,914 -1,915 1,916 1,917 2,918 2,919 0,920 2,921 1922 ]923 },924 {925 gettingCloudMatched: false,926 uid: "WwplzRwnRUfoMWiFyHYdgTzkV7i2",927 propertyVector: [928 1,929 3,930 3,931 3932 ],933 phone: "",934 newness: 3,935 currentMatches: { },936 gender: "Male",937 tos: true,938 email: "edvard.schreiner.sjoeblom@gmail.com",939 workplace: "Lakkegata 53, 0187 Oslo",940 fieldOfStudy: "master in AI",941 matchLocation: "Oslo",942 photoURL: "https://lh5.googleusercontent.com/-NiLw8FCo2-Y/AAAAAAAAAAI/AAAAAAAAD78/qXkE3B2ZvU4/photo.jpg",943 readyToMatch: false,944 propertySize: 3,945 university: "NTNU",946 displayName: "Edvard Schreiner Sjøblom",947 age: "24",948 studyProgramme: "master in AI",949 budget: 1,950 newMatch: false,951 personalityVector: [952 2,953 0,954 -1,955 0,956 1,957 1,958 1,959 0,960 1,961 1,962 0,963 -1,964 -1,965 0,966 0,967 2,968 2,969 1,970 2,971 2972 ]973 },974 {975 uid: "Yfxqlh9rA5VhUg5UAHN95lS0cDW2",976 propertyVector: [977 3,978 3,979 3,980 3981 ],982 phone: "",983 currentMatches: { },984 gender: "Male",985 tos: true,986 email: "martinvee@hotmail.com",987 workplace: "Vestfjordgaten 7 Garage, Sandvika, Norge",988 workplaceLatLng: {989 lng: 10.521969799999965,990 lat: 59.8901841991 },992 fieldOfStudy: "construction",993 matchLocation: "oslo",994 photoURL: null,995 readyToMatch: true,996 rentTo: "2018-08-30T22:00:00.000Z",997 university: "NTNU",998 displayName: "Martin Vee Akselsen",999 age: "23",1000 rentFrom: "2018-05-31T22:00:00.000Z",1001 personalityVector: [1002 2,1003 2,1004 0,1005 1,1006 1,1007 1,1008 -1,1009 -1,1010 0,1011 1,1012 -2,1013 -2,1014 -1,1015 -2,1016 -1,1017 2,1018 2,1019 2,1020 2,1021 21022 ]1023 },1024 {1025 rentTo: "2018-08-30T22:00:00.000Z",1026 university: "NTNU",1027 displayName: "Fredrik Moger",1028 age: "22",1029 newMatches: false,1030 loginProvider: "facebook",1031 rentFrom: "2018-05-31T22:00:00.000Z",1032 personalityVector: [1033 3,1034 3,1035 3,1036 3,1037 3,1038 3,1039 3,1040 3,1041 3,1042 3,1043 3,1044 3,1045 3,1046 3,1047 3,1048 3,1049 3,1050 3,1051 3,1052 31053 ],1054 gettingCloudMatched: 0,1055 uid: "ZHpHneH8kLhR2Zv3nTwq30VjEVv1",1056 propertyVector: [1057 3,1058 3,1059 3,1060 31061 ],1062 phone: "",1063 currentMatches: {1064 398433da-8614-44a0-9509-a97de809d70b: {1065 matchId: "398433da-8614-44a0-9509-a97de809d70b",1066 timeStamp: "2018-05-26T15:50:11.921Z"1067 },1068 310730a2-43bb-41b3-9895-b7f57ec660ce: {1069 matchId: "310730a2-43bb-41b3-9895-b7f57ec660ce",1070 timeStamp: "2018-05-31T09:07:18.640Z"1071 },1072 158f85f2-7706-4b77-bb0c-2dae9860b7aa: {1073 matchId: "158f85f2-7706-4b77-bb0c-2dae9860b7aa",1074 timeStamp: "2018-05-26T15:49:27.912Z"1075 }1076 },1077 gender: "Male",1078 tos: true,1079 email: "fredrikhockey95@hotmail.com",1080 workplace: "Rema 1000, Christian Krohgs gate, Oslo, Norge",1081 workplaceLatLng: {1082 lat: 59.9140393,1083 lng: 10.756723100000041084 },1085 fieldOfStudy: "Construction",1086 matchLocation: "Oslo",1087 photoURL: "https://graph.facebook.com/1734164020000418/picture?type=large&width=720&height=720",1088 readyToMatch: true1089 },1090 {1091 loginProvider: "google",1092 rentFrom: "2018-06-13T22:00:00.000Z",1093 personalityVector: [1094 3,1095 3,1096 3,1097 3,1098 3,1099 3,1100 3,1101 3,1102 3,1103 3,1104 3,1105 3,1106 3,1107 3,1108 3,1109 3,1110 3,1111 3,1112 3,1113 31114 ],1115 gettingCloudMatched: 0,1116 uid: "aryd6Y8ZSHMYfnJQF1oWoAta0T33",1117 propertyVector: [1118 3,1119 3,1120 3,1121 31122 ],1123 phone: "",1124 currentMatches: {1125 aaf0bb7d-edd3-449a-8d6b-c55ca595f9f0: {1126 matchId: "aaf0bb7d-edd3-449a-8d6b-c55ca595f9f0",1127 timeStamp: "2018-05-26T05:07:41.958Z"1128 }1129 },1130 gender: "Female",1131 tos: true,1132 email: "emijosberge@gmail.com",1133 workplace: "Statsbygg, Grubbegata, Oslo, Norge",1134 workplaceLatLng: {1135 lat: 59.91420350000001,1136 lng: 10.7452286999999841137 },1138 fieldOfStudy: "Architecture",1139 matchLocation: "Oslo",1140 photoURL: "https://lh3.googleusercontent.com/-B5Vrv7BExI0/AAAAAAAAAAI/AAAAAAAAA-w/94nNc3Rdz_8/photo.jpg",1141 readyToMatch: true,1142 rentTo: "2018-08-13T22:00:00.000Z",1143 university: "NTNU",1144 displayName: "Emijo Berge",1145 age: "27",1146 newMatches: true1147 },1148 {1149 matchLocation: "Oslo",1150 photoURL: null,1151 readyToMatch: false,1152 propertySize: 5,1153 university: "NTNU",1154 displayName: "Amalie Damsgaard Jensen ",1155 age: "22",1156 studyProgramme: "Industriell Design ",1157 budget: 5,1158 newMatch: false,1159 personalityVector: [1160 0,1161 1,1162 -1,1163 0,1164 1,1165 -2,1166 2,1167 -1,1168 1,1169 2,1170 0,1171 -1,1172 -1,1173 -1,1174 -1,1175 1,1176 1,1177 2,1178 0,1179 21180 ],1181 gettingCloudMatched: false,1182 uid: "b22j42juxOZdedoC4jzhXXkpM3H2",1183 propertyVector: [1184 5,1185 5,1186 3,1187 31188 ],1189 phone: "",1190 newness: 3,1191 currentMatches: { },1192 gender: "Female",1193 tos: true,1194 email: "amalie.d.jensen@gmail.com",1195 workplace: "storebrand, Professor Kohts Vei, Lysaker, Norway",1196 workplaceLatLng: {1197 lat: 59.9114316,1198 lng: 10.629816600000031199 },1200 fieldOfStudy: "Industriell Design "1201 },1202 {1203 newness: 3,1204 phone: "",1205 currentMatches: { },1206 tos: true,1207 workplaceLatLng: {1208 lat: 59.94195629999999,1209 lng: 10.7162852999999811210 },1211 matchLocation: "Oslo",1212 propertySize: 3,1213 age: "19",1214 newMatch: false,1215 propertyVector: [1216 1,1217 3,1218 3,1219 31220 ],1221 gender: "Male",1222 email: "martinegeli9@gmail.com",1223 workplace: "StartupLab, Gaustadalléen, Oslo, Norge",1224 fieldOfStudy: "Indøk",1225 photoURL: "https://lh3.googleusercontent.com/-t3v6RjtvStw/AAAAAAAAAAI/AAAAAAAAAHM/OnEtnGkfIO0/photo.jpg",1226 readyToMatch: false,1227 university: "NTNU",1228 displayName: "Martin Egeli",1229 newMatches: false,1230 studyProgramme: "Indøk",1231 budget: 1,1232 personalityVector: [1233 1,1234 1,1235 -1,1236 1,1237 -1,1238 -1,1239 0,1240 -1,1241 1,1242 1,1243 0,1244 -1,1245 -1,1246 -2,1247 -1,1248 1,1249 0,1250 1,1251 1,1252 11253 ],1254 gettingCloudMatched: false,1255 uid: "c4Z3JyPZgyRZRy8Y8CP7M8NBdk53"1256 },1257 {1258 newMatch: false,1259 personalityVector: [1260 1,1261 -1,1262 -2,1263 0,1264 0,1265 -2,1266 2,1267 1,1268 2,1269 2,1270 1,1271 0,1272 2,1273 0,1274 0,1275 0,1276 0,1277 -2,1278 0,1279 -11280 ],1281 gettingCloudMatched: false,1282 uid: "fwepwMGggoZPt1DhLrFOa1K7HJ42",1283 propertyVector: [1284 3,1285 3,1286 3,1287 31288 ],1289 phone: "",1290 newness: 3,1291 currentMatches: { },1292 gender: "Male",1293 tos: true,1294 email: "jon.langorgen@startntnu.no",1295 workplace: "Sørkedalsveien 8",1296 fieldOfStudy: "Energy and environmental engineering",1297 matchLocation: "Oslo",1298 photoURL: "https://lh3.googleusercontent.com/-zBFrb1bLObc/AAAAAAAAAAI/AAAAAAAAAAo/OUeMwphP8ng/photo.jpg",1299 readyToMatch: false,1300 propertySize: 3,1301 university: "NTNU",1302 displayName: "Jon Langørgen",1303 age: "22",1304 studyProgramme: "Energy and environmental engineering",1305 budget: 31306 },1307 {1308 tos: true,1309 email: "halvor98@outlook.com",1310 workplace: "The Tiger, Jernbanetorget, Oslo, Norway",1311 workplaceLatLng: {1312 lng: 10.75006380000002,1313 lat: 59.91111831314 },1315 fieldOfStudy: "Computer Science",1316 matchLocation: "Oslo",1317 photoURL: "https://graph.facebook.com/1800648543290891/picture?type=large&width=720&height=720",1318 readyToMatch: true,1319 rentTo: "2018-08-30T22:00:00.000Z",1320 university: "NTNU",1321 displayName: "Halvor Fladsrud Bø",1322 age: "19",1323 newMatches: true,1324 loginProvider: "facebook",1325 rentFrom: "2018-05-31T22:00:00.000Z",1326 personalityVector: [1327 3,1328 3,1329 3,1330 3,1331 3,1332 3,1333 3,1334 3,1335 3,1336 3,1337 3,1338 3,1339 3,1340 3,1341 3,1342 3,1343 3,1344 3,1345 3,1346 31347 ],1348 gettingCloudMatched: 0,1349 uid: "gpDesEjSkQYT4KhCwiLVIHjGiLQ2",1350 propertyVector: [1351 3,1352 3,1353 3,1354 31355 ],1356 phone: "",1357 currentMatches: {1358 eca70fb4-2135-4c4f-9bd4-a53e48087799: {1359 matchId: "eca70fb4-2135-4c4f-9bd4-a53e48087799",1360 timeStamp: "2018-05-29T17:36:34.458Z"1361 }1362 },1363 gender: "Male"1364 },1365 {1366 displayName: "Christian Ringstad Schultz",1367 age: "24",1368 newMatches: true,1369 loginProvider: "facebook",1370 rentFrom: "2018-05-31T22:00:00.000Z",1371 personalityVector: [1372 -1,1373 2,1374 -1,1375 0,1376 -1,1377 2,1378 -1,1379 0,1380 0,1381 0,1382 0,1383 0,1384 -1,1385 -1,1386 0,1387 0,1388 0,1389 0,1390 0,1391 01392 ],1393 gettingCloudMatched: 0,1394 uid: "hzEUa11uoJVX5Gy49VpXuIlwo5a2",1395 propertyVector: [1396 3,1397 3,1398 3,1399 51400 ],1401 phone: "",1402 currentMatches: {1403 fe4826d7-a50b-4ab8-87ac-dcb7e83b7941: {1404 matchId: "fe4826d7-a50b-4ab8-87ac-dcb7e83b7941",1405 timeStamp: "2018-05-31T09:41:38.774Z"1406 }1407 },1408 gender: "Male",1409 tos: true,1410 email: "bio_freaks@msn.com",1411 workplace: "Bjørvika Apartments, Schweigaards gate, Oslo, Norge",1412 workplaceLatLng: {1413 lat: 59.9109063,1414 lng: 10.759456300000011415 },1416 fieldOfStudy: "Finance",1417 matchLocation: "Oslo",1418 photoURL: "https://graph.facebook.com/10156240520820729/picture?type=large&width=720&height=720",1419 readyToMatch: true,1420 rentTo: "2018-08-30T22:00:00.000Z",1421 university: "NTNU"1422 },1423 {1424 tos: true,1425 email: "markjosephltan@gmail.com",1426 workplace: "Lubin Olson & Niewiadomski LLP, Montgomery Street, San Francisco, CA, USA",1427 workplaceLatLng: {1428 lat: 37.7952125,1429 lng: -122.402835699999971430 },1431 fieldOfStudy: "Computer Science",1432 matchLocation: "Oslo",1433 photoURL: "https://graph.facebook.com/10155581901806818/picture?type=large&width=720&height=720",1434 readyToMatch: true,1435 rentTo: "2018-08-31T07:00:00.000Z",1436 university: "Cmu",1437 displayName: "Mark Tan",1438 age: "30",1439 newMatches: true,1440 loginProvider: "facebook",1441 rentFrom: "2018-06-01T07:00:00.000Z",1442 personalityVector: [1443 0,1444 0,1445 -1,1446 0,1447 0,1448 0,1449 0,1450 0,1451 0,1452 0,1453 0,1454 0,1455 0,1456 0,1457 0,1458 0,1459 0,1460 0,1461 0,1462 01463 ],1464 gettingCloudMatched: false,1465 uid: "i0nr5JLmvwUEmPpBOdjMNigTtwG3",1466 propertyVector: [1467 0,1468 5,1469 5,1470 51471 ],1472 phone: "",1473 currentMatches: { },1474 gender: "Male"1475 },1476 {1477 propertyVector: [1478 3,1479 5,1480 5,1481 31482 ],1483 phone: "",1484 newness: 5,1485 currentMatches: { },1486 gender: "Male",1487 tos: true,1488 email: "espen.meidell@gmail.com",1489 workplace: "Akershusstranda 10 Parking, Akershusstranda, Oslo, Norway",1490 workplaceLatLng: {1491 lat: 59.90796340000001,1492 lng: 10.7343516999999341493 },1494 fieldOfStudy: "Master in AI",1495 matchLocation: "Oslo",1496 photoURL: "https://lh5.googleusercontent.com/-2JKaEKv_GS4/AAAAAAAAAAI/AAAAAAAAEo0/izZQECf6A74/photo.jpg",1497 readyToMatch: false,1498 propertySize: 5,1499 university: "NTNU",1500 displayName: "Espen Meidell",1501 age: "23",1502 studyProgramme: "Master in AI",1503 budget: 3,1504 newMatch: false,1505 personalityVector: [1506 1,1507 0,1508 -1,1509 0,1510 1,1511 0,1512 2,1513 0,1514 1,1515 1,1516 0,1517 0,1518 2,1519 0,1520 0,1521 2,1522 2,1523 1,1524 0,1525 01526 ],1527 gettingCloudMatched: false,1528 uid: "jjv13jCsPjbIMYKFzTavaijguWt2"1529 },1530 {1531 currentMatches: {1532 3d5c3cf3-8186-4339-8d82-8f7c96aae3a5: 15271652599171533 },1534 gender: "Male",1535 tos: true,1536 email: "markus2740@gmail.com",1537 workplace: "Oslofjord Kayak, 0277 Oslo, Norway",1538 workplaceLatLng: {1539 lat: 59.92031410000001,1540 lng: 10.6755239999999961541 },1542 fieldOfStudy: "economics",1543 matchLocation: "Oslo",1544 photoURL: "",1545 readyToMatch: true,1546 rentTo: "2018-09-07T22:00:00.000Z",1547 university: "NTNU",1548 displayName: "Markus",1549 age: "23",1550 loginProvider: "email",1551 rentFrom: "2018-06-16T22:00:00.000Z",1552 personalityVector: [1553 3,1554 3,1555 3,1556 3,1557 3,1558 3,1559 3,1560 3,1561 3,1562 3,1563 3,1564 3,1565 3,1566 3,1567 3,1568 3,1569 3,1570 3,1571 3,1572 31573 ],1574 uid: "oH0Jx0p2oyg6qtDBW3ERyuY93s33",1575 propertyVector: [1576 3,1577 3,1578 3,1579 31580 ],1581 phone: ""1582 },1583 {1584 displayName: "Prabriti Tiwari",1585 age: "22",1586 loginProvider: "facebook",1587 rentFrom: "2018-05-31T22:00:00.000Z",1588 personalityVector: [1589 0,1590 1,1591 1,1592 -1,1593 0,1594 -1,1595 0,1596 0,1597 0,1598 0,1599 0,1600 -1,1601 -1,1602 0,1603 0,1604 0,1605 0,1606 0,1607 0,1608 01609 ],1610 uid: "qZYQqvhRXdfWBZbhqCTI9so6sD52",1611 propertyVector: [1612 1,1613 3,1614 3,1615 31616 ],1617 phone: "",1618 currentMatches: { },1619 gender: "Female",1620 tos: true,1621 email: "prabriti.26@gmail.com",1622 workplace: "Blindern High School, Sognsveien, Oslo, Norway",1623 workplaceLatLng: {1624 lat: 59.94982570000001,1625 lng: 10.727527600000031626 },1627 fieldOfStudy: "Architecture",1628 matchLocation: "Oslo",1629 photoURL: "https://graph.facebook.com/1065603120256051/picture?type=large&width=720&height=720",1630 readyToMatch: true,1631 rentTo: "2018-08-30T22:00:00.000Z",1632 university: "UIO"1633 },1634 {1635 rentFrom: "2018-06-10T22:00:00.000Z",1636 personalityVector: [1637 1,1638 -1,1639 -2,1640 0,1641 -1,1642 -2,1643 1,1644 -1,1645 1,1646 1,1647 -1,1648 -1,1649 -2,1650 -2,1651 -1,1652 1,1653 2,1654 0,1655 2,1656 21657 ],1658 gettingCloudMatched: false,1659 uid: "rfJdsdxmTWctCoOCfkeEZ6XzTa42",1660 propertyVector: [1661 1,1662 1,1663 1,1664 31665 ],1666 phone: "",1667 currentMatches: { },1668 gender: "Male",1669 tos: true,1670 email: "trebor292@gmail.com",1671 workplace: "Schweigaards gate 28 Garage, Platous gate, Oslo, Norway",1672 workplaceLatLng: {1673 lat: 59.910373,1674 lng: 10.7638160999999851675 },1676 fieldOfStudy: "Computer Science",1677 matchLocation: "Oslo",1678 photoURL: "https://lh5.googleusercontent.com/-y7a7Gps0fiI/AAAAAAAAAAI/AAAAAAAAXyU/njPfTYE5sQY/photo.jpg",1679 readyToMatch: true,1680 rentTo: "2018-07-19T22:00:00.000Z",1681 university: "NTNU",1682 displayName: "Robert Einarson",1683 age: "22",1684 newMatches: true,1685 loginProvider: "google"1686 },1687 {1688 gender: "Male",1689 email: "kristian.e.boe@gmail.com",1690 workplace: "Netlight AS, Karl Johans gate, Oslo, Norway",1691 fieldOfStudy: "Computer Science",1692 photoURL: "https://graph.facebook.com/1855420214468245/picture?type=large&width=720&height=720",1693 readyToMatch: true,1694 university: "NTNU",1695 displayName: "Kristian Elset Bø",1696 newMatches: false,1697 rentFrom: "2018-06-01T07:00:00.000Z",1698 landlord: true,1699 personalityVector: [1700 1,1701 0,1702 -1,1703 -1,1704 -1,1705 -1,1706 1,1707 2,1708 1,1709 2,1710 0,1711 0,1712 -6,1713 -1,1714 -1,1715 2,1716 2,1717 1,1718 2,1719 01720 ],1721 uid: "uwUbPIgqAudqPDItgfOkEqVgl122",1722 gettingCloudMatched: 0,1723 phone: "+4791127607",1724 currentMatches: {1725 bc417588-8bb5-45f5-95cf-e294ffbd65ff: {1726 matchId: "bc417588-8bb5-45f5-95cf-e294ffbd65ff",1727 timeStamp: "2018-05-31T10:21:58.250Z"1728 },1729 fab81425-3f64-414c-9b25-f0fab6bb5e09: {1730 matchId: "fab81425-3f64-414c-9b25-f0fab6bb5e09",1731 timeStamp: "2018-05-28T10:56:25.766Z"1732 },1733 fd95bb08-1807-4301-8c54-7aa2a34903b0: {1734 matchId: "fd95bb08-1807-4301-8c54-7aa2a34903b0",1735 timeStamp: "2018-05-22T13:05:34.439Z"1736 },1737 310730a2-43bb-41b3-9895-b7f57ec660ce: {1738 matchId: "310730a2-43bb-41b3-9895-b7f57ec660ce",1739 timeStamp: "2018-05-31T08:41:34.168Z"1740 },1741 134b5f10-a700-4410-8eac-a10fd3d205d3: {1742 matchId: "134b5f10-a700-4410-8eac-a10fd3d205d3",1743 timeStamp: "2018-05-30T18:10:23.769Z"1744 },1745 6a2a9024-c68b-4656-b791-ab157157ef22: {1746 matchId: "6a2a9024-c68b-4656-b791-ab157157ef22",1747 timeStamp: "2018-05-28T10:53:38.779Z"1748 },1749 223972ae-d940-461b-a31c-9b64db896964: {1750 matchId: "223972ae-d940-461b-a31c-9b64db896964",1751 timeStamp: "2018-05-31T09:55:32.959Z"1752 },1753 5fb3c6fd-5e91-43b1-8272-3c47d69aaeac: {1754 matchId: "5fb3c6fd-5e91-43b1-8272-3c47d69aaeac",1755 timeStamp: "2018-05-29T07:14:22.678Z"1756 },1757 a362ba1c-01d8-4b1a-bf74-9919e60a3635: {1758 matchId: "a362ba1c-01d8-4b1a-bf74-9919e60a3635",1759 timeStamp: "2018-05-27T12:45:49.613Z"1760 }1761 },1762 tos: true,1763 workplaceLatLng: {1764 lat: 59.9131672,1765 lng: 10.741938699999991766 },1767 matchLocation: "Oslo",1768 rentTo: "2018-08-31T07:00:00.000Z",1769 age: "25",1770 loginProvider: "facebook",1771 propertyVector: [1772 3,1773 3,1774 5,1775 51776 ],1777 gettingettingCloudMatched: 01778 }...
findAndReplaceDOMText.js
Source:findAndReplaceDOMText.js
1/**2 * findAndReplaceDOMText v 0.23 * @author James Padolsey http://james.padolsey.com4 * @license http://unlicense.org/UNLICENSE5 *6 * Matches the text of a DOM node against a regular expression7 * and replaces each match (or node-separated portions of the match)8 * in the specified element.9 *10 * Example: Wrap 'test' in <em>:11 * <p id="target">This is a test</p>12 * <script>13 * findAndReplaceDOMText(14 * /test/,15 * document.getElementById('target'),16 * 'em'17 * );18 * </script>19 */20window.findAndReplaceDOMText = (function() {21 /** 22 * findAndReplaceDOMText23 * 24 * Locates matches and replaces with replacementNode25 *26 * @param {RegExp} regex The regular expression to match27 * @param {Node} node Element or Text node to search within28 * @param {String|Element|Function} replacementNode A NodeName,29 * Node to clone, or a function which returns a node to use30 * as the replacement node.31 * @param {Number} captureGroup A number specifiying which capture32 * group to use in the match. (optional)33 */34 function findAndReplaceDOMText(regex, node, replacementNode, captureGroup, indexes) { 35 var m, matches = [], text = _getText(node);36 var replaceFn = _genReplacer(replacementNode);37 if (!text) { return; }38 if(!regex) {39 matches.push(indexes);40 _stepThroughMatches(node, matches, replaceFn, replacementNode);41 } else {42 if (regex.global) {43 while (m = regex.exec(text)) {44 matches.push(_getMatchIndexes(m, captureGroup));45 }46 } else {47 m = text.match(regex);48 matches.push(_getMatchIndexes(m, captureGroup));49 }50 51 if (matches.length) {52 _stepThroughMatches(node, matches, replaceFn, replacementNode);53 }54 }55 }56 /**57 * Gets the start and end indexes of a match58 */59 function _getMatchIndexes(m, captureGroup) {60 captureGroup = captureGroup || 0;61 62 if (!m[0]) throw 'findAndReplaceDOMText cannot handle zero-length matches';63 64 var index = m.index;65 if (captureGroup > 0) {66 var cg = m[captureGroup];67 if (!cg) throw 'Invalid capture group';68 index += m[0].indexOf(cg);69 m[0] = cg;70 } 71 return [ index, index + m[0].length, [ m[0] ] ];72 };73 /**74 * Gets aggregate text of a node without resorting75 * to broken innerText/textContent76 */77 function _getText(node) {78 if (node.nodeType === 3) {79 return node.data;80 }81 var txt = '';82 if (node = node.firstChild) do {83 txt += _getText(node);84 } while (node = node.nextSibling);85 return txt;86 }87 /** 88 * Steps through the target node, looking for matches, and89 * calling replaceFn when a match is found.90 */91 function _stepThroughMatches(node, matches, replaceFn, replacementNode) {92 var after, before,93 startNode,94 endNode,95 startNodeIndex,96 endNodeIndex,97 innerNodes = [],98 atIndex = 0,99 curNode = node,100 matchLocation = matches.shift(),101 matchIndex = 0;102 out: while (true) {103 if (curNode.nodeType === 3){ //&& !($(curNode).parents('math') && /^\s*$/.test($(curNode).text()))) {104 if (!endNode && curNode.length + atIndex >= matchLocation[1]) {105 // We've found the ending106 endNode = curNode;107 endNodeIndex = matchLocation[1] - atIndex;108 } else if (startNode) {109 // Intersecting node110 if(!(($(curNode).parents('math') || $(curNode).parents('table')) && /^\s*$/.test($(curNode).text()))) { //dlm-add: exclude interior blank mathml interior nodes111 innerNodes.push(curNode);112 }113 }114 if (!startNode && curNode.length + atIndex > matchLocation[0]) {115 // We've found the match start116 startNode = curNode;117 startNodeIndex = matchLocation[0] - atIndex;118 }119 atIndex += curNode.length;120 } else if (curNode.nodeName.toLowerCase() == 'math') { // dlm-added : if mathml then just wrap the node with span121 var nodeTextLength = curNode.textContent.length;122 123 if(matchLocation[2][0] == curNode.textContent) {124 // full mathml node matches125 $(curNode).parent().contents().wrap(replacementNode);126 } else {127 if (!endNode && nodeTextLength + atIndex >= matchLocation[1]) {128 // We've found the ending129 130 //1. handle cases like <span>abc</span><math> -- because of highlighting etc131 //2. abc<math>132 if(curNode.parentNode.previousSibling && curNode.parentNode.previousSibling.nodeType != 3) {133 endNode = $(curNode.parentNode.previousSibling).contents().filter(function() {134 return this.nodeType == 3; 135 }).get(0);136 } else if(curNode.parentNode.previousSibling && curNode.parentNode.previousSibling.nodeType == 3) {137 endNode = curNode.parentNode.previousSibling;138 }139 140 if(!endNode) {141 endNode = curNode.parentNode;142 }143 144 //endNode = curNode.parentNode.previousSibling || curNode.parentNode;145 endNodeIndex = endNode.textContent.length;//matchLocation[1] - atIndex; //curNode.parentNode.previousSibling.length146 147 matchLocation[2][0] = matchLocation[2][0].substring(0, matchLocation[2][0].lastIndexOf(curNode.textContent));148 }149 150 if (!startNode && nodeTextLength + atIndex > matchLocation[0]) {151 // We've found the match start152 153 if(curNode.parentNode.nextSibling && curNode.parentNode.nextSibling.nodeType != 3) {154 startNode = $(curNode.parentNode.nextSibling).contents().filter(function() {155 return this.nodeType == 3; 156 }).get(0);157 } else if(curNode.parentNode.nextSibling && curNode.parentNode.nextSibling.nodeType == 3) {158 startNode = curNode.parentNode.nextSibling;159 }160 161 if(!startNode) {162 startNode = curNode.parentNode;163 }164 //startNode = curNode.parentNode.nextSibling || curNode.parentNode;165 startNodeIndex = 0;//curNode.parentNode.previousSibling.length;//matchLocation[0] - atIndex;166 167 matchLocation[2][0] = matchLocation[2][0].substring(matchLocation[2][0].indexOf(curNode.textContent) + nodeTextLength,matchLocation[2][0].length);168 }169 170 if(startNode) {171 $(curNode).parent().contents().wrap(replacementNode);172 }173 }174 175 atIndex += nodeTextLength;176 }177 if (startNode && endNode && matchLocation[2] != "") {178 curNode = replaceFn({179 startNode: startNode,180 startNodeIndex: startNodeIndex,181 endNode: endNode,182 endNodeIndex: endNodeIndex,183 innerNodes: innerNodes,184 match: matchLocation[2],185 matchIndex: matchIndex186 });187 // replaceFn has to return the node that replaced the endNode188 // and then we step back so we can continue from the end of the 189 // match:190 atIndex -= (endNode.length - endNodeIndex);191 startNode = null;192 endNode = null;193 innerNodes = [];194 matchLocation = matches.shift();195 matchIndex++;196 if (!matchLocation) {197 break; // no more matches198 }199 } else if (curNode.nodeName.toLowerCase() == 'math') {200 // do nothing201 } else if (curNode.firstChild || curNode.nextSibling) {202 // Move down or forward:203 curNode = curNode.firstChild || curNode.nextSibling;204 continue;205 }206 // Move forward or up:207 while (true) {208 if (curNode.nextSibling) {209 curNode = curNode.nextSibling;210 break;211 } else if (curNode.parentNode !== node && !$(curNode).parent().hasClass('taghighlight')) {212 curNode = curNode.parentNode;213 } else {214 break out;215 }216 }217 }218 }219 var reverts;220 /**221 * Reverts the last findAndReplaceDOMText process222 */223 findAndReplaceDOMText.revert = function revert() {224 for (var i = 0, l = reverts.length; i < l; ++i) {225 reverts[i]();226 }227 reverts = [];228 };229 /** 230 * Generates the actual replaceFn which splits up text nodes231 * and inserts the replacement element.232 */233 function _genReplacer(nodeName) {234 reverts = [];235 var makeReplacementNode;236 if (typeof nodeName != 'function') {237 var stencilNode = nodeName.nodeType ? nodeName : document.createElement(nodeName);238 makeReplacementNode = function(fill) {239 var clone = document.createElement('div'),240 el;241 clone.innerHTML = stencilNode.outerHTML || new XMLSerializer().serializeToString(stencilNode);242 el = clone.firstChild;243 if (fill) {244 el.appendChild(document.createTextNode(fill));245 }246 return el;247 };248 } else {249 makeReplacementNode = nodeName;250 }251 return function replace(range) {252 var startNode = range.startNode,253 endNode = range.endNode,254 matchIndex = range.matchIndex;255 if (startNode === endNode) {256 var node = startNode;257 if (range.startNodeIndex > 0) {258 // Add `before` text node (before the match)259 var before = document.createTextNode(node.data.substring(0, range.startNodeIndex));260 node.parentNode.insertBefore(before, node);261 }262 // Create the replacement node:263 var el = makeReplacementNode(range.match[0], matchIndex, range.match[0]);264 node.parentNode.insertBefore(el, node);265 if (range.endNodeIndex < node.length) {266 // Add `after` text node (after the match)267 var after = document.createTextNode(node.data.substring(range.endNodeIndex));268 node.parentNode.insertBefore(after, node);269 }270 271 node.parentNode.removeChild(node);272 reverts.push(function() {273 var pnode = el.parentNode;274 pnode.insertBefore(el.firstChild, el);275 pnode.removeChild(el);276 pnode.normalize();277 });278 return el;279 } else {280 // Replace startNode -> [innerNodes...] -> endNode (in that order)281 var before = document.createTextNode(startNode.data.substring(0, range.startNodeIndex));282 var after = document.createTextNode(endNode.data.substring(range.endNodeIndex));283 var elA = makeReplacementNode(startNode.data.substring(range.startNodeIndex), matchIndex, range.match[0]);284 var innerEls = [];285 for (var i = 0, l = range.innerNodes.length; i < l; ++i) {286 var innerNode = range.innerNodes[i];287 var innerEl = makeReplacementNode(innerNode.data, matchIndex, range.match[0]);288 innerNode.parentNode.replaceChild(innerEl, innerNode);289 innerEls.push(innerEl);290 }291 var elB = makeReplacementNode(endNode.data.substring(0, range.endNodeIndex), matchIndex, range.match[0]);292 if(startNode.parentNode) {293 startNode.parentNode.insertBefore(before, startNode);294 startNode.parentNode.insertBefore(elA, startNode);295 startNode.parentNode.removeChild(startNode);296 }297 if(endNode.parentNode) {298 endNode.parentNode.insertBefore(elB, endNode);299 endNode.parentNode.insertBefore(after, endNode);300 endNode.parentNode.removeChild(endNode);301 }302 reverts.push(function() {303 innerEls.unshift(elA);304 innerEls.push(elB);305 for (var i = 0, l = innerEls.length; i < l; ++i) {306 var el = innerEls[i];307 var pnode = el.parentNode;308 pnode.insertBefore(el.firstChild, el);309 pnode.removeChild(el);310 pnode.normalize();311 }312 });313 return elB;314 }315 };316 }317 return findAndReplaceDOMText;...
ProductSkuInCartClassifier(1).js
Source:ProductSkuInCartClassifier(1).js
1define('classification/ProductSkuInCartClassifier',2 ['classification/KeywordClassifier', 'util/TextUtil', 'util/Distance'],3 function(KeywordClassifier, TextUtil, DistanceUtil){4 //matches an element from the scan to a single attribute5 const RelaxLevel = { STRICT:0, RELAXED:1, LOOSE:2};6 class ProductSkuInCartClassifier extends KeywordClassifier {7 constructor(definition, product){8 super(definition);9 if(typeof product === 'string') {10 this.product = JSON.parse(product);11 } else {12 this.product = product;13 }14 15 this.attributeExceptions = ['one size', '1 size', 'one color', '1 color'];16 this.nameMatches = [];17 this.attributeMatches = {};18 19 //Average Distance to Geometric Median of classified text20 this.proximity = 100;21 //Relaxation Level22 this.relaxation = RelaxLevel.STRICT;23 this.initializeAttributes(this.product);24 this.resetAttrMatches();25 }26 getProductName() {27 let name = '';28 try29 {30 name = (new DOMParser).parseFromString(this.product.name, 'text/html').body.innerText;31 } catch(err) {32 name = this.product.name;33 }34 return TextUtil.cleanText(name);35 }36 hasAttributes() {37 return Array.isArray(this.attributeKeys) && this.attributeKeys.length > 0;38 }39 reset() {40 super.reset();41 this.nameMatches = [];42 this.resetAttrMatches();43 }44 resetAttrMatches() {45 if(!this.hasAttributes()) return;46 this.attributeKeys.forEach(function(att) {47 this.attributeMatches[att] = [];48 }, this);49 }50 initializeAttributes(product) {51 let allKeys = Object.keys(product.attributes);52 this.attributeKeys = [];53 this.attributes = {};54 allKeys.forEach(function(attrKey){55 let attr = product.attributes[attrKey], attrLabel;56 attrLabel = TextUtil.cleanText(attr.label);57 if(this.attributeExceptions.indexOf(attrLabel) === -1) {58 this.attributes[attrKey] = Object.assign({}, attr);59 this.attributeKeys.push(attrKey);60 }61 }, this);62 }63 matchesKeywords(element, scannedTextList){64 65 let humanText = this.getVisibleText(element),66 matchFound = false,67 matchLocation='',68 matchType='',69 nameMatchTest=false,70 titleMatch = false,71 keywordMatch = false;72 nameMatchTest = this.matchesName(element, humanText);73 if(nameMatchTest) {74 this.nameMatches.push({element:element, matchLocation:KeywordClassifier.Matching.MatchLocation.HUMAN, matchType:KeywordClassifier.Matching.MatchType.EXACT});75 return true;76 }77 if(TextUtil.containsMatch(humanText, [this.getProductName()])) {78 this.nameMatches.push({element:element, matchLocation:KeywordClassifier.Matching.MatchLocation.HUMAN, matchType:KeywordClassifier.Matching.MatchType.CONTAINS});79 if(this.hasAttributes()) {80 this.matchAttributes(element, humanText);81 }82 return true;83 }84 else if(this.hasAttributes()) {85 return this.matchAttributes(element, humanText);86 }87 /*88 if(productHasIcon && element.imageSource && element.imageSource.length > 0) {89 var containsSrcMatch = TextUtil.containsMatch([element.imageSource],[this.getIcon()]);90 if(containsSrcMatch){91 this.keywordMatches.push({element:element, matchLocation:KeywordClassifier.Matching.MatchLocation.IMAGE, matchType:KeywordClassifier.Matching.MatchType.EXACT});92 return true;93 }94 } else {95 //Look inside the options to see if there is an option that matches the one we want to select96 if(element.tagName === 'SELECT') {97 if(this.matchElementOptions(element)) {98 this.keywordMatches.push({element:element, matchLocation:KeywordClassifier.Matching.MatchLocation.HUMAN, matchType:KeywordClassifier.Matching.MatchType.EXACT});99 return true;100 } 101 }102 if(this.attributeTitle.length > 0) {103 if(TextUtil.exactMatch(humanText, [this.attributeTitle, this.attributeTitle.toLowerCase()])) {104 matchFound = true;105 matchLocation = KeywordClassifier.Matching.MatchLocation.HUMAN;106 matchType = KeywordClassifier.Matching.MatchType.EXACT;107 negativeMatch = this.negativeWordMatch(humanText);108 } else if(TextUtil.containsMatch(humanText, [this.attributeTitle])) {109 matchFound = true;110 matchLocation = KeywordClassifier.Matching.MatchLocation.HUMAN;111 matchType = KeywordClassifier.Matching.MatchType.CONTAINS;112 negativeMatch = this.negativeWordMatch(humanText);113 }114 if(negativeMatch) { matchFound = false; }115 if(matchFound) {116 this.titleMatches.push({element:element, matchLocation:matchLocation, matchType:matchType});117 titleMatch = true;118 }119 }120 keywordMatch = super.matchesKeywords(element, scannedTextList);121 return (titleMatch || keywordMatch);122 }123 */124 125 }126 matchesName(element, elementText) {127 let replaceRegex = /[^\s\w]+/g, productText = this.getProductName().replace(replaceRegex,'');128 switch(this.relaxation) {129 130 case RelaxLevel.RELAXED:131 elementText = elementText.map(function(t) {132 return t.replace(replaceRegex,'');133 });134 return TextUtil.exactMatch(elementText, [productText]);135 break;136 case RelaxLevel.LOOSE:137 elementText = elementText.map(function(t) {138 return t.replace(replaceRegex,'');139 });140 let productParts = productText.split(' ').filter(function(text) { return text !== '';}), exactOrderScore=0, matchingWordScore=0;141 exactOrderScore = TextUtil.exactOrderScore(elementText, productParts);142 143 matchingWordScore = TextUtil.wordMatchScore(elementText, productParts);144 return exactOrderScore > .5 || matchingWordScore > .5;145 break;146 case RelaxLevel.STRICT:147 return TextUtil.exactMatch(elementText, [this.getProductName()]);148 break;149 default: 150 return false;151 break;152 153 }154 155 }156 matchAttributes(element, extractedElementText) {157 if(!this.hasAttributes()) return false;158 let attr, attrMatch = false, nodeValue;159 this.attributeKeys.forEach(function(key){160 attr = this.attributes[key];161 if(TextUtil.exactMatch(extractedElementText, [TextUtil.cleanText(attr.label)])) {162 this.attributeMatches[key].push({element:element, matchLocation:KeywordClassifier.Matching.MatchLocation.HUMAN, matchType:KeywordClassifier.Matching.MatchType.EXACT});163 attrMatch = true;164 } else if(TextUtil.containsMatch(extractedElementText, [TextUtil.cleanText(attr.label)])) {165 this.attributeMatches[key].push({element:element, matchLocation:KeywordClassifier.Matching.MatchLocation.HUMAN, matchType:KeywordClassifier.Matching.MatchType.CONTAINS});166 attrMatch = true;167 } else {168 //Look at just node value and see if a portion of it matches the attribute169 nodeValue = element.nodeValue;170 if(nodeValue) {171 if(TextUtil.containsMatch([TextUtil.cleanText(attr.label)], [nodeValue])) {172 //Calculate the percentage match by using word count173 var labelCount = attr.label.split(' ').length;174 var nodeValueCount = nodeValue.split(' ').length;175 if(labelCount > 0 && ((nodeValueCount/labelCount) > .32)) {176 this.attributeMatches[key].push({element:element, matchLocation:KeywordClassifier.Matching.MatchLocation.HUMAN, matchType:KeywordClassifier.Matching.MatchType.CONTAINS});177 }178 }179 }180 }181 }, this);182 return attrMatch;183 }184 getVisibleText(element) {185 let textArray = [];186 if(element.buttontext) {187 this.sanitize(element.buttontext, textArray);188 }189 if(element.nodeValue) {190 this.sanitize(element.nodeValue, textArray);191 }192 if(element.innerText){193 this.sanitize(element.innerText, textArray);194 }195 196 if(element.ariaLabel){197 this.sanitize(element.ariaLabel,textArray);198 } 199 if(element.dataTitle){200 this.sanitize(element.dataTitle,textArray);201 } 202 if(element.value){203 this.sanitize(element.value, textArray);204 }205 if(element.title){206 this.sanitize(element.title, textArray);207 }208 return textArray;209 }210 postMatchUpdate() {211 let nameFound = false, attrsFound = true, elementClusters, attrMatchCount=0;212 if(this.nameMatches.length > 0) {213 nameFound = true;214 }215 if(this.hasAttributes()) {216 attrMatchCount = this.attributeKeys.filter(function(attrKey) {217 return this.attributeMatches[attrKey].length > 0;218 }, this).length;219 if(this.relaxation === RelaxLevel.STRICT) {220 //All must match221 attrsFound = attrMatchCount === this.attributeKeys.length; 222 } else {223 224 attrsFound = (attrMatchCount / this.attributeKeys.length) >= .5;225 }226 227 }228 if( nameFound && attrsFound) {229 elementClusters = this.findNearestClusters();230 elementClusters = elementClusters.filter(function(c){231 return c.distanceSummary.mean <= this.proximity;232 }, this);233 elementClusters.sort(function(c1, c2) {234 let c1Mean = c1.distanceSummary.mean, c2Mean = c2.distanceSummary.mean;235 if(c1Mean < c2Mean) {236 return -1;237 }238 else if(c1Mean > c2Mean) {239 return 1;240 }241 else {242 return 0;243 }244 });245 if(elementClusters.length > 0) {246 this.matchingElement = elementClusters[0].referenceElement;247 }248 }249 }250 findNearestClusters() {251 let clusters = [], attrLists = [];252 253 this.attributeKeys.forEach(function(attrKey) {254 if(this.attributeMatches[attrKey].length > 0) {255 attrLists.push([]);256 this.attributeMatches[attrKey].forEach(function(attrMatch) {257 this[this.length-1].push(attrMatch.element);258 }, attrLists); 259 }260 261 }, this);262 this.nameMatches.forEach(function(match) {263 var elements = DistanceUtil.findNearestClusterTo(match.element, attrLists, 0, 0, []);264 var gMedian = DistanceUtil.findGeometricMedian(elements);265 var distanceSummary = DistanceUtil.getDistanceSummary(gMedian, elements);266 var clusterData = {referenceElement:match.element, elements:elements, distanceSummary: distanceSummary};267 clusters.push(clusterData);268 }, this);269 return clusters;270 }271 relax() {272 if(this.relaxation < RelaxLevel.LOOSE) {273 this.relaxation += 1;274 }275 }276 } 277 return ProductSkuInCartClassifier;...
plugin.js
Source:plugin.js
1tinymce.PluginManager.add('smileys', function (editor, url) {2 var defaultSmileys = [3 [4 { shortcut: '(^^^)', url: url + '/img/shark.gif', title: 'shark' },5 { shortcut: 'O:)', url: url + '/img/angel.png', title: 'angel' },6 { shortcut: 'o.O', url: url + '/img/confused.png', title: 'confused' },7 { shortcut: '3:)', url: url + '/img/devil.png', title: 'devil' },8 { shortcut: ':-O', url: url + '/img/gasp.png', title: 'gasp' },9 { shortcut: '8-)', url: url + '/img/glasses.png', title: 'glasses' },10 { shortcut: ':-D', url: url + '/img/grin.png', title: 'grin' }11 ],12 [13 { shortcut: ':-)', url: url + '/img/smile.png', title: 'smile' },14 { shortcut: ":'(", url: url + '/img/cry.png', title: 'cry' },15 { shortcut: '<3', url: url + '/img/heart.png', title: 'heart' },16 { shortcut: '^_^', url: url + '/img/kiki.png', title: 'kiki' },17 { shortcut: ':-*', url: url + '/img/kiss.png', title: 'kiss' },18 { shortcut: ':v', url: url + '/img/pacman.png', title: 'pacman' },19 { shortcut: '<(�)', url: url + '/img/penguin.gif', title: 'penguin' }20 ],21 [22 { shortcut: ':|]', url: url + '/img/robot.gif', title: 'robot' },23 { shortcut: '-_-', url: url + '/img/squint.png', title: 'squint' },24 { shortcut: '8-|', url: url + '/img/sunglasses.png', title: 'sunglasses' },25 { shortcut: ':-P', url: url + '/img/tongue.png', title: 'tongue' },26 { shortcut: ':/', url: url + '/img/unsure.png', title: 'unsure' },27 { shortcut: '>:O', url: url + '/img/upset.png', title: 'upset' },28 { shortcut: '>:(', url: url + '/img/grumpy.png', title: 'grumpy' }29 ]30 ]3132 var smileys = editor.settings.smileys || defaultSmileys, fullSmileysList = editor.settings.extended_smileys ? smileys.concat(editor.settings.extended_smileys) : smileys3334 function getHtml () {35 var smileysHtml3637 smileysHtml = '<table role="presentation" class="mce-grid">'3839 tinymce.each(fullSmileysList, function (row) {40 smileysHtml += '<tr>'4142 tinymce.each(row, function (icon) {43 smileysHtml += '<td><a href="#" data-mce-url="' + icon.url + '" tabindex="-1" title="' + icon.title + '"><img src="' +44 icon.url + '" style="width: 16px; height: 16px"></a></td>'45 })4647 smileysHtml += '</tr>'48 })4950 smileysHtml += '</table>'5152 return smileysHtml53 }5455 function concatArray (array) {56 var each = tinymce.each, result = []57 each(array, function (item) {58 result = result.concat(item)59 })60 return result.length > 0 ? result : array61 }6263 function findAndReplaceDOMText (regex, node, replacementNode, captureGroup, schema) {64 var m, matches = [], text, count = 0, doc65 var blockElementsMap, hiddenTextElementsMap, shortEndedElementsMap6667 doc = node.ownerDocument68 blockElementsMap = schema.getBlockElements() // H1-H6, P, TD etc69 hiddenTextElementsMap = schema.getWhiteSpaceElements() // TEXTAREA, PRE, STYLE, SCRIPT70 shortEndedElementsMap = schema.getShortEndedElements() // BR, IMG, INPUT7172 function getMatchIndexes (m, captureGroup) {73 captureGroup = captureGroup || 07475 var index = m.index7677 if (captureGroup > 0) {78 var cg = m[captureGroup]79 index += m[0].indexOf(cg)80 m[0] = cg81 }8283 return [index, index + m[0].length, [m[0]]]84 }8586 function getText (node) {87 var txt8889 if (node.nodeType === 3) {90 return node.data91 }9293 if (hiddenTextElementsMap[node.nodeName] && !blockElementsMap[node.nodeName]) {94 return ''95 }9697 txt = ''9899 if (blockElementsMap[node.nodeName] || shortEndedElementsMap[node.nodeName]) {100 txt += '\n'101 }102103 if ((node = node.firstChild)) {104 do {105 txt += getText(node)106 } while ((node = node.nextSibling))107 }108109 return txt110 }111112 function stepThroughMatches (node, matches, replaceFn) {113 var startNode, endNode, startNodeIndex,114 endNodeIndex, innerNodes = [], atIndex = 0, curNode = node,115 matchLocation = matches.shift(), matchIndex = 0116117 out: while (true) {118 if (blockElementsMap[curNode.nodeName] || shortEndedElementsMap[curNode.nodeName]) {119 atIndex++120 }121122 if (curNode.nodeType === 3) {123 if (!endNode && curNode.length + atIndex >= matchLocation[1]) {124 // We've found the ending125 endNode = curNode126 endNodeIndex = matchLocation[1] - atIndex127 } else if (startNode) {128 // Intersecting node129 innerNodes.push(curNode)130 }131132 if (!startNode && curNode.length + atIndex > matchLocation[0]) {133 // We've found the match start134 startNode = curNode135 startNodeIndex = matchLocation[0] - atIndex136 }137138 atIndex += curNode.length139 }140141 if (startNode && endNode) {142 curNode = replaceFn({143 startNode: startNode,144 startNodeIndex: startNodeIndex,145 endNode: endNode,146 endNodeIndex: endNodeIndex,147 innerNodes: innerNodes,148 match: matchLocation[2],149 matchIndex: matchIndex150 })151152 // replaceFn has to return the node that replaced the endNode153 // and then we step back so we can continue from the end of the154 // match:155 atIndex -= (endNode.length - endNodeIndex)156 startNode = null157 endNode = null158 innerNodes = []159 matchLocation = matches.shift()160 matchIndex++161162 if (!matchLocation) {163 break // no more matches164 }165 } else if ((!hiddenTextElementsMap[curNode.nodeName] || blockElementsMap[curNode.nodeName]) && curNode.firstChild) {166 // Move down167 curNode = curNode.firstChild168 continue169 } else if (curNode.nextSibling) {170 // Move forward:171 curNode = curNode.nextSibling172 continue173 }174175 // Move forward or up:176 while (true) {177 if (curNode.nextSibling) {178 curNode = curNode.nextSibling179 break180 } else if (curNode.parentNode !== node) {181 curNode = curNode.parentNode182 } else {183 break out184 }185 }186 }187 }188189 /**190 * Generates the actual replaceFn which splits up text nodes191 * and inserts the replacement element.192 */193 function genReplacer (nodeName) {194 var makeReplacementNode195196 if (typeof nodeName !== 'function') {197 var stencilNode = nodeName.nodeType ? nodeName : doc.createElement(nodeName)198199 makeReplacementNode = function () {200 var clone = stencilNode.cloneNode(false)201 return clone202 }203 } else {204 makeReplacementNode = nodeName205 }206207 return function replace (range) {208 var before, after, parentNode, startNode = range.startNode,209 endNode = range.endNode210211 if (startNode === endNode) {212 var node = startNode213214 parentNode = node.parentNode215 if (range.startNodeIndex > 0) {216 // Add `before` text node (before the match)217 before = doc.createTextNode(node.data.substring(0, range.startNodeIndex))218 parentNode.insertBefore(before, node)219 }220221 // Create the replacement node:222 var el = makeReplacementNode()223 parentNode.insertBefore(el, node)224 if (range.endNodeIndex < node.length) {225 // Add `after` text node (after the match)226 after = doc.createTextNode(node.data.substring(range.endNodeIndex))227 parentNode.insertBefore(after, node)228 }229230 node.parentNode.removeChild(node)231232 return el233 }234 }235 }236237 text = getText(node)238 if (!text) {239 return240 }241 while ((m = regex.exec(text))) {242 matches.push(getMatchIndexes(m, captureGroup))243 }244245 if (matches.length) {246 count = matches.length247 stepThroughMatches(node, matches, genReplacer(replacementNode))248 }249250 return count251 }252253 function replaceAllMatches (smiley) {254 var each = tinymce.each, node = editor.selection.getNode(), marker, text255 if (typeof (smiley.shortcut) === 'string') {256 text = smiley.shortcut.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')257258 marker = editor.dom.create('img', { 'src': smiley.url, 'title': smiley.title })259260 return findAndReplaceDOMText(new RegExp(text, 'gi'), node, marker, false, editor.schema)261 } else if (Array.isArray(smiley.shortcut)) {262 each(smiley.shortcut, function (item) {263 marker = editor.dom.create('img', { 'src': smiley.url, 'title': smiley.title })264265 return findAndReplaceDOMText(new RegExp(item.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'), 'gi'), node, marker, false, editor.schema)266 })267 }268 }269270 editor.on('keyup', function (e) {271 if (editor.settings.auto_convert_smileys) {272 var each = tinymce.each, selection = editor.selection, node = selection.getNode()273 if (node) {274 each(concatArray(fullSmileysList), function (smiley) {275 replaceAllMatches(smiley)276 })277 }278 }279 })280281 editor.addButton('smileys', {282 type: 'panelbutton',283 icon: 'emoticons',284 panel: {285 autohide: true,286 html: getHtml,287 onclick: function (e) {288 var linkElm = editor.dom.getParent(e.target, 'a')289290 if (linkElm) {291 editor.insertContent('<img src="' + linkElm.getAttribute('data-mce-url') + '" title="' + linkElm.getAttribute('title') + '" />')292 this.hide()293 }294 }295 },296 tooltip: 'Smileys'297 })
...
SelectOneClassifier(1).js
Source:SelectOneClassifier(1).js
1define('classification/SelectOneClassifier', ['util/TextUtil'], function(TextUtil) {2 let Matching = {3 MatchLocation: {4 SELECT_OPTION: 'SELECT_OPTION',5 TARGET_OPTION: 'TARGET_OPTION',6 KEYWORD: 'KEYWORD'7 }8 };9 class SelectOneClassifier {10 constructor(definition, keywords, targetOption, negativeWords, contextKeywords, priority) {11 this.definition = definition;12 this.targetOption = targetOption;13 this.keywords = keywords;14 this.negativeWords = negativeWords;15 this.elementMatches = [];16 this.contextMatches = [];17 this.matchingElement = null;18 this.timesResolved = 0;19 this.priority = priority;20 this.contextKeywords = contextKeywords;21 this.keywordScoreDistance = 100;22 this.useTargetOption = false;23 24 if (typeof this.priority === 'undefined') {25 this.priority = '';26 }27 this._scanOnComplete = false;28 29 if (typeof this.targetOption === 'string') {30 31 this.targetOptionRegex = new RegExp('^[\\s\\W]*' + this.targetOption + '[\\s\\W]*$', 'i');32 33 } else if (typeof this.targetOption === 'object' && this.targetOption.expression && this.targetOption.flags) {34 35 this.targetOptionRegex = new RegExp(this.targetOption.expression, this.targetOption.flags);36 37 } else {38 39 throw Error('targetOption should be a string or object with \'expression\' and \'flags\' values');40 41 }42 }43 toggleTargetOption(val) {44 this.useTargetOption = val;45 }46 resolved() {47 this.timesResolved += 1;48 }49 50 getElement() {51 return this.matchingElement;52 }53 hasElement() {54 return this.matchingElement !== null;55 }56 getPriority() {57 return this.priority;58 }59 alwaysClassify() {60 return false;61 }62 getScanOnComplete() {63 return this._scanOnComplete;64 }65 setScanOnComplete(value) {66 this._scanOnComplete = value;67 }68 69 removeMatch(element) {70 this.elementMatches = this.elementMatches.filter(item => {71 return this.element !== item;72 }, this);73 }74 sanitize(text, textList) {75 TextUtil.appendText(TextUtil.cleanText(text), textList);76 }77 reset() {78 this.elementMatches = [];79 this.contextMatches = [];80 this.matchLocation = '';81 this.matchingElement = null;82 }83 matchesTags(element) {84 let humanText = this.getVisibleText(element),85 matchFound = false;86 if (this.contextKeywords && this.contextKeywords.length > 0) {87 matchFound = TextUtil.exactMatch(this.contextKeywords, humanText);88 } 89 if (matchFound) {90 this.contextMatches.push(element);91 }92 93 return matchFound;94 }95 matchesKeywords(element, scannedTextList) {96 return this.matches(element, scannedTextList);97 }98 matches(element, scannedTextList) {99 let humanText = this.getVisibleText(element, false),100 elementOnlyText = this.getVisibleText(element, true),101 matchFound = false,102 matchLocation = '',103 matchType = '',104 keywordMatch = false,105 optionMatch = false;106 107 if (element.tagName === 'SELECT') {108 if (this.matchElementOptions(element)) {109 110 //matchType = KeywordClassifier.Matching.MatchType.EXACT;111 matchLocation = Matching.MatchLocation.SELECT_OPTION;112 matchFound = true;113 114 } 115 } else if (this.matchesTargetOption(element, elementOnlyText) && this.useTargetOption) {116 117 matchLocation = Matching.MatchLocation.TARGET_OPTION;118 matchFound = true;119 120 } else if (TextUtil.exactMatch(humanText, this.keywords)) {121 122 matchLocation = Matching.MatchLocation.KEYWORD;123 matchFound = true;124 125 }126 if (matchFound) {127 matchFound = !this.negativeWordMatch(humanText);128 }129 130 if (matchFound) {131 this.elementMatches.push({132 element: element,133 matchLocation:matchLocation134 });135 }136 return matchFound;137 }138 // TS returns bool139 matchElementOptions(element) {140 return element.options.some(opt => {141 return this.targetOptionRegex.test(opt.humanText);142 }, this);143 }144 negativeWordMatch(textList) {145 return (this.negativeWords && this.negativeWords.length > 0) ? (TextUtil.exactMatch(textList, this.negativeWords)) : false;146 }147 matchesTargetOption(element, humanText) {148 return TextUtil.regexMatch(humanText, this.targetOptionRegex);149 }150 getVisibleText(element, elementOnly) {151 let textArray = [];152 153 if (element.buttontext) {154 this.sanitize(element.buttontext, textArray);155 }156 157 if (element.nodeValue) {158 this.sanitize(element.nodeValue, textArray);159 }160 161 if (element.innerText) {162 this.sanitize(element.innerText, textArray);163 }164 165 if (element.ariaLabel) {166 this.sanitize(element.ariaLabel,textArray);167 } 168 if (element.dataTitle) {169 this.sanitize(element.dataTitle,textArray);170 } 171 if (element.value) {172 this.sanitize(element.value, textArray);173 }174 if (element.title) {175 this.sanitize(element.title, textArray);176 }177 if (element.name) {178 this.sanitize(element.name, textArray);179 }180 if (element.textNeighbors && element.textNeighbors.length > 0) {181 let foundFirstNotInside = false,182 txtIndex = 0,183 nearText;184 185 while (!foundFirstNotInside && txtIndex < element.textNeighbors.length) {186 nearText = element.textNeighbors[txtIndex];187 foundFirstNotInside = nearText.location !== 'INSIDE';188 if (elementOnly) {189 if (nearText.location === 'INSIDE') {190 this.sanitize(nearText.text, textArray); 191 }192 } else {193 this.sanitize(nearText.text, textArray);194 }195 196 txtIndex += 1;197 }198 }199 return textArray;200 }201 postMatchUpdate(matchFilter) {202 // only match on specific types203 if (typeof matchFilter === 'string') {204 this.elementMatches = this.elementMatches.filter(match => {205 return match.matchLocation === matchFilter;206 });207 }208 // search keyword matches first it would contain elements that match the attribute label or value209 let match;210 211 if (this.elementMatches.length == 1) {212 213 this.matchType = this.elementMatches[0].matchLocation;214 this.matchingElement = this.elementMatches[0].element;215 216 } else if (this.elementMatches.length > 1) {217 218 match = this.handleMultipleMatches(this.elementMatches);219 this.matchType = match.matchLocation;220 this.matchingElement = match.element;221 222 }223 }224 getMatchData() {225 return this.matchType;226 }227 handleMultipleMatches(results) {228 // score each match result229 // NOTE [ARC] you could probably map this instead, not sure if the match scores and sort need to be saved beyond this method230 results.forEach(match => {231 match.score = this.scoreMatch(match);232 }, this);233 // return the single highest-scored match item from the results (result at scored index 0)234 return results.sort((a, b) => { 235 const scoreDiff = b.score - a.score;236 // if scores are the same, then pick the one closer to the top237 return (scoreDiff === 0) ? (a.element.segmentScrollY - b.element.segmentScrollY) : scoreDiff;238 })[0];239 }240 scoreMatch(match) {241 let score = 0;242 switch (match.matchLocation) {243 case Matching.MatchLocation.SELECT_OPTION:244 score += 2;245 score += this.getKeywordScore(match.element);246 break;247 case Matching.MatchLocation.TARGET_OPTION:248 score += 2;249 score += this.getKeywordScore(match.element);250 break;251 case Matching.MatchLocation.KEYWORD:252 score += 1;253 score += this.getKeywordScore(match.element);254 break;255 }256 switch (match.element.tagName) {257 case 'INPUT':258 switch (match.element.type) {259 case 'radio':260 case 'checkbox':261 score += .5;262 break;263 }264 break;265 }266 if (match.element.isNonStandardDropDown) {267 score += .5;268 }269 score += this.getContextScore(match.element);270 return score;271 }272 273 getKeywordScore(element) {274 let nearText,275 geoDistScore = 0,276 i = 0,277 keywordScore = 0;278 if (element.textNeighbors) {279 while (i < element.textNeighbors.length) {280 nearText = element.textNeighbors[i];281 if (nearText.distance < this.keywordScoreDistance) {282 geoDistScore = Math.abs(this.keywordScoreDistance - nearText.distance) / this.keywordScoreDistance * ((element.textNeighbors.length-i)/element.textNeighbors.length);283 if (TextUtil.exactMatch(this.keywords, [TextUtil.cleanText(nearText.text)])) { 284 keywordScore += geoDistScore;285 } else if (TextUtil.containsMatch(this.keywords, [TextUtil.cleanText(nearText.text)])) {286 keywordScore += (geoDistScore / 2);287 }288 }289 i++;290 }291 }292 return keywordScore;293 }294 getContextScore(element) {295 const score = this.contextMatches.reduce((aggregator, contextMatch) => {296 return (element.ymin > contextMatch.ymin) ? aggregator + 1 : aggregator;297 }, 0);298 return Math.min(1, score);299 }300 }301 SelectOneClassifier.MatchType = Matching.MatchLocation;302 return SelectOneClassifier;...
GameBoard.jsx
Source:GameBoard.jsx
...71 selectedPlayer.movement72 );73 const onCellClick = (location, cell) => {74 if (cell.type === 'player') {75 if (matchLocation(cell.data.location, selectedPlayer.location)) {76 setSelectedPlayer(defaultStart);77 } else {78 setSelectedPlayer(cell.data);79 }80 } else if (locationInList(location, candidates)) {81 setSelectedPlayer((prevState) => {82 return { ...prevState, location: location };83 });84 setPlayers((prevState) => {85 return {86 ...prevState,87 [selectedPlayer.id]: {88 ...prevState[selectedPlayer.id],89 location: location,90 },91 };92 });93 setSelectedPlayer(defaultStart);94 } else {95 setSelectedPlayer(defaultStart);96 }97 };98 for (let i = 0; i < field.height; i++) {99 const row = [];100 for (let j = 0; j < field.width; j++) {101 const cellLocation = { x: j, y: i };102 const cellContent = determineCellType(cellLocation, players, field);103 row.push(104 <GridBlock105 key={`r${i}_c${j}`}106 position={cellLocation}107 onCellClick={onCellClick}108 active={matchLocation(cellLocation, selectedPlayer.location)}109 highlight={locationInList(cellLocation, candidates)}110 cellType={cellContent}111 />112 );113 }114 grid.push(115 <div key={`row${i}`} className="gridRow">116 {row}117 </div>118 );119 }120 return (121 <div className="gameBoard" key={'gameboard'}>122 {grid}123 </div>124 );125}126function findOpenPositions(origin, field, range) {127 let candidates = [origin];128 for (let i = 0; i < range; i++) {129 candidates.forEach((candidate) => {130 candidates = candidates.concat(checkNear(candidate, field));131 });132 }133 const shortList = [];134 candidates.forEach((item) => {135 if (136 !locationInList(item, shortList) &&137 !matchLocation(origin, item) &&138 !locationInList(item, getAllPlayerLocations(field.players))139 ) {140 shortList.push(item);141 }142 });143 return shortList;144}145function checkNear(location, field) {146 const candidates = [];147 for (let x_inc = -1; x_inc <= 1; x_inc++) {148 if (location.x + x_inc >= 0 && location.x + x_inc < field.width) {149 const point = { x: location.x + x_inc, y: location.y };150 if (151 !locationInList(point, field.barriers) &&152 !matchLocation(location, point)153 ) {154 candidates.push(point);155 }156 }157 }158 for (let y_inc = -1; y_inc <= 1; y_inc++) {159 if (location.y + y_inc >= 0 && location.y + y_inc < field.height) {160 const point = { x: location.x, y: location.y + y_inc };161 if (162 !locationInList(point, field.barriers) &&163 !matchLocation(location, point)164 ) {165 candidates.push(point);166 }167 }168 }169 return candidates;170}171function matchLocation(locationA, locationB) {172 return locationA.x === locationB.x && locationA.y === locationB.y;173}174function locationInList(location, locationList) {175 for (let i = 0; i < locationList.length; i++) {176 if (matchLocation(location, locationList[i])) {177 return true;178 }179 }180 return false;181}182function determineCellType(location, players, field) {183 const playerList = Object.keys(players);184 let cellContent = { type: 'cell' };185 if (locationInList(location, field.barriers)) {186 cellContent = { type: 'barrier', data: '' };187 }188 for (let i = 0; i < playerList.length; i++) {189 const player = players[playerList[i]];190 if (matchLocation(location, player.location)) {191 cellContent = { type: 'player', data: player };192 }193 }194 return cellContent;195}196function getAllPlayerLocations(players) {197 const keys = Object.keys(players);198 const locations = [];199 keys.forEach((key) => {200 locations.push(players[key].location);201 });202 return locations;...
match.js
Source:match.js
1angular2 .module('livein')3 .controller('match', match)4 .controller('matchDetail', matchDetail)5 // .controller('teamDetail', teamDetail)6function match($scope, $stateParams, $ionicLoading, $filter, $state, $location, $rootScope) {7 // vm = $scope;8 $scope.detail = function(matchId) {9 $state.go("app.matchDetail", { matchId });10 // $location.path('/match/detail');11 }12 // $ionicLoading.show({ template: $filter('transla1te')('loading') + "...", duration: 2000 });13 // $scope.cat = [14 // { 'categoryValue': 'freeteam', 'categoryName': 'Free team' },15 // { 'categoryValue': 'premiumteam', 'categoryName': 'Premium team' }16 // ];17 $rootScope.matchData = [18 { 'matchId': 1, 'matchDate': 'August 7, 2017 at 7pm', 'matchLocation': 'Futsal Court Malang', 'matchName': 'Lets Futsal', 'sportCategory': 'Futsal', 'teamHost': 'Team A' },19 { 'matchId': 2, 'matchDate': 'August 7, 2017 at 7pm', 'matchLocation': 'Basket Court Malang', 'matchName': 'Lets Badminton', 'sportCategory': 'Badminton', 'teamHost': 'Team B' },20 { 'matchId': 3, 'matchDate': 'August 7, 2017 at 7pm', 'matchLocation': 'Badminton Court Malang', 'matchName': 'Lets Basketball', 'sportCategory': 'Basketball', 'teamHost': 'Team C' },21 { 'matchId': 4, 'matchDate': 'August 7, 2017 at 7pm', 'matchLocation': 'Volley Court Malang', 'matchName': 'Lets Volleyball', 'sportCategory': 'Volleyball', 'teamHost': 'Team D' },22 ];23}24function matchDetail($scope, $state, $ionicPopup, $stateParams, $rootScope) {25 $rootScope.matchData.forEach(function(val) {26 if (val.matchId == $stateParams.matchId) {27 $scope.matchName = val.matchName;28 $scope.matchDate = val.matchDate;29 $scope.matchLocation = val.matchLocation;30 $scope.teamHost = val.teamHost;31 }32 });33 $scope.lala = function() {34 var alertPopup = $ionicPopup.alert({35 title: 'Information',36 template: 'Your team joined this match, see you!',37 cssClass: 'alertPopup'38 });39 alertPopup.then(function(res) {40 console.log('abc');41 });42 };...
solution.js
Source:solution.js
1function solve() {2 let code = document.getElementById('string').value;3 //let code = '4ds';4 let input = document.getElementById('text').value;5 //let input = 'eaSt 19,432567noRt north east 53,123456north 43,3213454dsNot all those who wander are lost.4dsnorth 47,874532';6 let result = document.getElementById('result');7 let patternMessage = new RegExp(`${code}(.*)${code}`, 'g');8 let message = patternMessage.exec(input)[1];9 let east = '';10 let north = '';11 let location = /(north|east).*?(\d{2})[^,]*?,[^,]*?(\d{6})/gmi;12 let matchLocation = location.exec(input);13 while (matchLocation !== null) {14 if (matchLocation[1].toLocaleUpperCase() === 'NORTH') {15 north = matchLocation;16 } else {17 east = matchLocation;18 }19 matchLocation = location.exec(input);20 }21 let p1 = document.createElement('p');22 p1.textContent = `${north[2]}.${north[3]} N`;23 let p2 = document.createElement('p');24 p2.textContent = `${east[2]}.${east[3]} E`;25 let p3 = document.createElement('p');26 p3.textContent = `Message: ${message}`;27 result.appendChild(p1);28 result.appendChild(p2);29 result.appendChild(p3);...
Using AI Code Generation
1cy.matchLocation('/home');2Cypress.Commands.add('matchLocation', (location) => {3 cy.location().should((loc) => {4 expect(loc.pathname).to.eq(location);5 });6});7Cypress.Commands.add('matchLocation', (location) => {8 cy.location().should((loc) => {9 expect(loc.pathname).to.eq(location);10 });11});12cy.matchLocation('/home');13Cypress.Commands.add('matchLocation', (location) => {14 cy.location().should((loc) => {15 expect(loc.pathname).to.eq(location);16 });17});18cy.matchLocation('/home');
Using AI Code Generation
1describe('Google', () => {2 it('should be able to search', () => {3 cy.get('[name="q"]').type('hello world')4 cy.get('[name="btnK"]').click()5 })6})7describe('Google', () => {8 it('should be able to search', () => {9 cy.get('[name="q"]').type('hello world')10 cy.get('[name="btnK"]').click()11 })12})13describe('Google', () => {14 it('should be able to search', () => {15 cy.get('[name="q"]').type('hello world')16 cy.get('[name="btnK"]').click()17 })18})19describe('Google', () => {20 it('should be able to search', () => {21 cy.get('[name="q"]').type('hello world')22 cy.get('[name="btnK"]').click()23 })24})
Using AI Code Generation
1describe('My First Test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5})6describe('My First Test', () => {7 it('Does not do much!', () => {8 expect(true).to.equal(true)9 })10})11Cypress has a built-in command called cy.visit() which is used to
Using AI Code Generation
1describe('Test', () => {2 it('Test', () => {3 });4});5describe('Test', () => {6 it('Test', () => {7 });8});9describe('Test', () => {10 it('Test', () => {11 });12});13describe('Test', () => {14 it('Test', () => {15 });16});17describe('Test', () => {18 it('Test', () => {19 });20});21describe('Test', () => {22 it('Test', () => {23 });24});25describe('Test', () => {26 it('Test', () => {
Using AI Code Generation
1describe('Test', () => {2 it('should match location', () => {3 cy.location('pathname').should('matchLocation', /\/example/);4 });5});6Cypress.Commands.add('matchLocation', (subject, regex) => {7 expect(subject).to.match(regex);8});9Cypress.Commands.add("matchLocation", (subject, regex) => {10 expect(subject).to.match(regex);11});
Using AI Code Generation
1describe('Match Location', () => {2 it('check if the location is correct', () => {3 })4})5Cypress.Commands.add('matchLocation', (url) => {6 cy.location('href').should('eq', url)7})
Using AI Code Generation
1describe('Test to check if location is matched', function() {2 it('The location should be matched', function() {3 })4})5Cypress.Commands.add('matchLocation', (url) => {6 cy.location().should((loc) => {7 expect(loc.href).to.eq(url)8 })9})10Cypress has a method called title() which returns the title of the current page. We can use this method in our custom command to check if the title of the current page is matched. Here is the code to add a custom command to check if the title is matched:11describe('Test to check if title is matched', function() {12 it('The title should be matched', function() {13 cy.matchTitle('Google')14 })15})16Cypress.Commands.add('matchTitle', (title) => {17 cy.title().should('eq', title)18})19Cypress has a method called should() which takes a callback function as a parameter. We can use this method in our custom command to check if an element is visible. Here is the code to add a custom command to check if the element is visible:20describe('Test to check if element is visible', function() {21 it('The element should be visible', function() {22 cy.get('input[name="q"]').matchVisibility()23 })24})
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!