Best JavaScript code snippet using best
examples.wizard.js
Source:examples.wizard.js
1(function( $ ) {2 'use strict';3 /*4 Wizard #15 */6 var $w1finish = $('#w1').find('ul.pager li.finish'),7 $w1validator = $("#w1 form").validate({8 highlight: function(element) {9 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');10 },11 success: function(element) {12 $(element).closest('.form-group').removeClass('has-error');13 $(element).remove();14 },15 errorPlacement: function( error, element ) {16 element.parent().append( error );17 }18 });19 $w1finish.on('click', function( ev ) {20 ev.preventDefault();21 var validated = $('#w1 form').valid();22 if ( validated ) {23 new PNotify({24 title: 'Congratulations',25 text: 'You completed the wizard form.',26 type: 'custom',27 addclass: 'notification-success',28 icon: 'fa fa-check'29 });30 }31 });32 $('#w1').bootstrapWizard({33 tabClass: 'wizard-steps',34 nextSelector: 'ul.pager li.next',35 previousSelector: 'ul.pager li.previous',36 firstSelector: null,37 lastSelector: null,38 onNext: function( tab, navigation, index, newindex ) {39 var validated = $('#w1 form').valid();40 if( !validated ) {41 $w1validator.focusInvalid();42 return false;43 }44 },45 onTabClick: function( tab, navigation, index, newindex ) {46 if ( newindex == index + 1 ) {47 return this.onNext( tab, navigation, index, newindex);48 } else if ( newindex > index + 1 ) {49 return false;50 } else {51 return true;52 }53 },54 onTabChange: function( tab, navigation, index, newindex ) {55 var totalTabs = navigation.find('li').size() - 1;56 $w1finish[ newindex != totalTabs ? 'addClass' : 'removeClass' ]( 'hidden' );57 $('#w1').find(this.nextSelector)[ newindex == totalTabs ? 'addClass' : 'removeClass' ]( 'hidden' );58 }59 });60 /*61 Wizard #262 */63 var $w2finish = $('#w2').find('ul.pager li.finish'),64 $w2validator = $("#w2 form").validate({65 highlight: function(element) {66 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');67 },68 success: function(element) {69 $(element).closest('.form-group').removeClass('has-error');70 $(element).remove();71 },72 errorPlacement: function( error, element ) {73 element.parent().append( error );74 }75 });76 $w2finish.on('click', function( ev ) {77 ev.preventDefault();78 var validated = $('#w2 form').valid();79 if ( validated ) {80 new PNotify({81 title: 'Congratulations',82 text: 'You completed the wizard form.',83 type: 'custom',84 addclass: 'notification-success',85 icon: 'fa fa-check'86 });87 }88 });89 $('#w2').bootstrapWizard({90 tabClass: 'wizard-steps',91 nextSelector: 'ul.pager li.next',92 previousSelector: 'ul.pager li.previous',93 firstSelector: null,94 lastSelector: null,95 onNext: function( tab, navigation, index, newindex ) {96 var validated = $('#w2 form').valid();97 if( !validated ) {98 $w2validator.focusInvalid();99 return false;100 }101 },102 onTabClick: function( tab, navigation, index, newindex ) {103 if ( newindex == index + 1 ) {104 return this.onNext( tab, navigation, index, newindex);105 } else if ( newindex > index + 1 ) {106 return false;107 } else {108 return true;109 }110 },111 onTabChange: function( tab, navigation, index, newindex ) {112 var totalTabs = navigation.find('li').size() - 1;113 $w2finish[ newindex != totalTabs ? 'addClass' : 'removeClass' ]( 'hidden' );114 $('#w2').find(this.nextSelector)[ newindex == totalTabs ? 'addClass' : 'removeClass' ]( 'hidden' );115 }116 });117 /*118 Wizard #3119 */120 var $w3finish = $('#w3').find('ul.pager li.finish'),121 $w3validator = $("#w3 form").validate({122 highlight: function(element) {123 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');124 },125 success: function(element) {126 $(element).closest('.form-group').removeClass('has-error');127 $(element).remove();128 },129 errorPlacement: function( error, element ) {130 element.parent().append( error );131 }132 });133 $w3finish.on('click', function( ev ) {134 ev.preventDefault();135 var validated = $('#w3 form').valid();136 if ( validated ) {137 new PNotify({138 title: 'Congratulations',139 text: 'You completed the wizard form.',140 type: 'custom',141 addclass: 'notification-success',142 icon: 'fa fa-check'143 });144 }145 });146 $('#w3').bootstrapWizard({147 tabClass: 'wizard-steps',148 nextSelector: 'ul.pager li.next',149 previousSelector: 'ul.pager li.previous',150 firstSelector: null,151 lastSelector: null,152 onNext: function( tab, navigation, index, newindex ) {153 var validated = $('#w3 form').valid();154 if( !validated ) {155 $w3validator.focusInvalid();156 return false;157 }158 },159 onTabClick: function( tab, navigation, index, newindex ) {160 if ( newindex == index + 1 ) {161 return this.onNext( tab, navigation, index, newindex);162 } else if ( newindex > index + 1 ) {163 return false;164 } else {165 return true;166 }167 },168 onTabChange: function( tab, navigation, index, newindex ) {169 var $total = navigation.find('li').size() - 1;170 $w3finish[ newindex != $total ? 'addClass' : 'removeClass' ]( 'hidden' );171 $('#w3').find(this.nextSelector)[ newindex == $total ? 'addClass' : 'removeClass' ]( 'hidden' );172 },173 onTabShow: function( tab, navigation, index ) {174 var $total = navigation.find('li').length - 1;175 var $current = index;176 var $percent = Math.floor(( $current / $total ) * 100);177 $('#w3').find('.progress-indicator').css({ 'width': $percent + '%' });178 tab.prevAll().addClass('completed');179 tab.nextAll().removeClass('completed');180 }181 });182 /*183 Wizard #4184 */185 var $w4finish = $('#w4').find('ul.pager li.finish'),186 $w4validator = $("#w4 form").validate({187 highlight: function(element) {188 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');189 },190 success: function(element) {191 $(element).closest('.form-group').removeClass('has-error');192 $(element).remove();193 },194 errorPlacement: function( error, element ) {195 element.parent().append( error );196 }197 });198 $w4finish.on('click', function( ev ) {199 ev.preventDefault();200 var validated = $('#w4 form').valid();201 if ( validated ) {202 new PNotify({203 title: 'Congratulations',204 text: 'You completed the wizard form.',205 type: 'custom',206 addclass: 'notification-success',207 icon: 'fa fa-check'208 });209 }210 });211 $('#w4').bootstrapWizard({212 tabClass: 'wizard-steps',213 nextSelector: 'ul.pager li.next',214 previousSelector: 'ul.pager li.previous',215 firstSelector: null,216 lastSelector: null,217 onNext: function( tab, navigation, index, newindex ) {218 var validated = $('#w4 form').valid();219 if( !validated ) {220 $w4validator.focusInvalid();221 return false;222 }223 },224 onTabClick: function( tab, navigation, index, newindex ) {225 if ( newindex == index + 1 ) {226 return this.onNext( tab, navigation, index, newindex);227 } else if ( newindex > index + 1 ) {228 return false;229 } else {230 return true;231 }232 },233 onTabChange: function( tab, navigation, index, newindex ) {234 var $total = navigation.find('li').size() - 1;235 $w4finish[ newindex != $total ? 'addClass' : 'removeClass' ]( 'hidden' );236 $('#w4').find(this.nextSelector)[ newindex == $total ? 'addClass' : 'removeClass' ]( 'hidden' );237 },238 onTabShow: function( tab, navigation, index ) {239 var $total = navigation.find('li').length - 1;240 var $current = index;241 var $percent = Math.floor(( $current / $total ) * 100);242 $('#w4').find('.progress-indicator').css({ 'width': $percent + '%' });243 tab.prevAll().addClass('completed');244 tab.nextAll().removeClass('completed');245 }246 });247 /*248 Wizard #5249 */250 var $w5finish = $('#w5').find('ul.pager li.finish'),251 $w5validator = $("#w5 form").validate({252 highlight: function(element) {253 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');254 },255 success: function(element) {256 $(element).closest('.form-group').removeClass('has-error');257 $(element).remove();258 },259 errorPlacement: function( error, element ) {260 element.parent().append( error );261 }262 });263 $w5finish.on('click', function( ev ) {264 ev.preventDefault();265 var validated = $('#w5 form').valid();266 if ( validated ) {267 new PNotify({268 title: 'Congratulations',269 text: 'You completed the wizard form.',270 type: 'custom',271 addclass: 'notification-success',272 icon: 'fa fa-check'273 });274 }275 });276 $('#w5').bootstrapWizard({277 tabClass: 'wizard-steps',278 nextSelector: 'ul.pager li.next',279 previousSelector: 'ul.pager li.previous',280 firstSelector: null,281 lastSelector: null,282 onNext: function( tab, navigation, index, newindex ) {283 var validated = $('#w5 form').valid();284 if( !validated ) {285 $w5validator.focusInvalid();286 return false;287 }288 },289 onTabChange: function( tab, navigation, index, newindex ) {290 var $total = navigation.find('li').size() - 1;291 $w5finish[ newindex != $total ? 'addClass' : 'removeClass' ]( 'hidden' );292 $('#w5').find(this.nextSelector)[ newindex == $total ? 'addClass' : 'removeClass' ]( 'hidden' );293 },294 onTabShow: function( tab, navigation, index ) {295 var $total = navigation.find('li').length;296 var $current = index + 1;297 var $percent = ( $current / $total ) * 100;298 $('#w5').find('.progress-bar').css({ 'width': $percent + '%' });299 }300 });...
index.js
Source:index.js
1import Ember from 'ember';2export default Ember.Controller.extend({3 draggableList: Ember.A(['ð¥ Fire!', 'ð¨ð¦ Canada!', 'ð» Ooooohhh!!!', 'ð© Aww crap!', 'ð Fist bump', 'ð Smooch']),4 draggableItem: 'â¥ï¸ Be still by beating heart',5 connectedListOne: Ember.A(['ð² Plant', 'ðµ Cactus', 'ð Four-leaf clover', 'ð Leaves', 'ð³ Coniferous', 'ð´ Palm tree']),6 connectedListTwo: Ember.A(['ð Green apple', 'ð Red apple', 'ð Pear', 'ð Orange', 'ð Lemon', 'ð Banana']),7 actions: {8 draggableMoved(item, oldIndex, newIndex) {9 console.log(`Content Moved! Item: ${item}, oldIndex: ${oldIndex}, "newIndex: ${newIndex}`);10 const content = this.get('draggableList');11 content.removeAt(oldIndex);12 content.insertAt(newIndex, item);13 console.log(`Updated content array: ${content}`);14 },15 addToDraggableList(item, newIndex){16 console.log(`Element added to content! Item: ${item.text().trim()} newIndex: ${newIndex}`);17 this.get('draggableList').insertAt(newIndex, item.text().trim());18 this.set('draggableItem', null);19 },20 contentMovedToOne(item, oldIndex, newIndex) {21 console.log(`Content Moved! Item: ${item}, oldIndex: ${oldIndex}, "newIndex: ${newIndex}`);22 const contentOne = this.get('connectedListOne');23 const contentTwo = this.get('connectedListTwo');24 contentOne.removeObject(item);25 contentTwo.removeObject(item);26 contentOne.insertAt(newIndex, item);27 console.log(`Updated content arrays: ${contentOne} & ${contentTwo}`);28 },29 contentMovedToTwo(item, oldIndex, newIndex) {30 console.log(`Content Moved! Item: ${item}, oldIndex: ${oldIndex}, "newIndex: ${newIndex}`);31 const contentOne = this.get('connectedListOne');32 const contentTwo = this.get('connectedListTwo');33 contentOne.removeObject(item);34 contentTwo.removeObject(item);35 contentTwo.insertAt(newIndex, item);36 console.log(`Updated content arrays: ${contentOne} & ${contentTwo}`);37 }38 }...
caesar.js
Source:caesar.js
1// Please refrain from tampering with the setup code provided here,2// as the index.html and test files rely on this setup to work properly.3// Only add code (e.g., helper methods, variables, etc.) within the scope4// of the anonymous function on line 65const caesarModule = (function () {6 // you can add any code you want within this function scope7 function caesar(input, shift, encode = true) {8 if (!shift || shift === 0 || shift < -25 || shift > 25) { return false };9 const alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];10 const result = [];11 input = input.toLowerCase().split(''); 12 13 if (encode === true) {14 input.forEach((char, index) => {15 if (alphabet.includes(char)) {16 alphabet.find((letter, index) => {17 if (char === letter) {18 let newIndex = index + shift;19 if( newIndex < 0) { newIndex = newIndex + 26};20 if( newIndex > 25) { newIndex = newIndex - 26};21 newChar = alphabet[newIndex];22 result.push(newChar);23 }24 })25 } else {26 result.push(char);27 }28 });29 } else {30 input.forEach((char, index) => {31 if (alphabet.includes(char)) {32 alphabet.find((letter, index) => {33 if (char === letter) {34 let newIndex = index - shift;35 if( newIndex < 0) { newIndex = newIndex + 26};36 if( newIndex > 25) { newIndex = newIndex - 26};37 newChar = alphabet[newIndex];38 result.push(newChar);39 }40 })41 } else {42 result.push(char);43 }44 });45 }46 return result.join('');47 }48 return {49 caesar,50 };51})();...
Using AI Code Generation
1var BestMatch = require('best-match');2var bestMatch = new BestMatch();3bestMatch.newIndex('test');4bestMatch.newIndex('test1');5bestMatch.newIndex('test2');6bestMatch.newIndex('test3');7bestMatch.newIndex('test4');8bestMatch.newIndex('test5');9bestMatch.newIndex('test6');10bestMatch.newIndex('test7');11bestMatch.newIndex('test8');12bestMatch.newIndex('test9');13bestMatch.newIndex('test10');14bestMatch.newIndex('test11');15bestMatch.newIndex('test12');16bestMatch.newIndex('test13');17bestMatch.newIndex('test14');18bestMatch.newIndex('test15');19bestMatch.newIndex('test16');20bestMatch.newIndex('test17');21bestMatch.newIndex('test18');22bestMatch.newIndex('test19');23bestMatch.newIndex('test20');24bestMatch.newIndex('test21');25bestMatch.newIndex('test22');26bestMatch.newIndex('test23');27bestMatch.newIndex('test24');28bestMatch.newIndex('test25');29bestMatch.newIndex('test26');30bestMatch.newIndex('test27');31bestMatch.newIndex('test28');32bestMatch.newIndex('test29');33bestMatch.newIndex('test30');34bestMatch.newIndex('test31');35bestMatch.newIndex('test32');36bestMatch.newIndex('test33');37bestMatch.newIndex('test34');38bestMatch.newIndex('test35');39bestMatch.newIndex('test36');40bestMatch.newIndex('test37');41bestMatch.newIndex('test38');42bestMatch.newIndex('test39');43bestMatch.newIndex('test40');44bestMatch.newIndex('test41');45bestMatch.newIndex('test42');46bestMatch.newIndex('test43');47bestMatch.newIndex('test44');48bestMatch.newIndex('test45');49bestMatch.newIndex('test46');50bestMatch.newIndex('test47');51bestMatch.newIndex('test48');52bestMatch.newIndex('test49');53bestMatch.newIndex('test50');54bestMatch.newIndex('test51');55bestMatch.newIndex('test52');56bestMatch.newIndex('test53');57bestMatch.newIndex('test54');58bestMatch.newIndex('test55');59bestMatch.newIndex('test56');60bestMatch.newIndex('test57');61bestMatch.newIndex('test58');62bestMatch.newIndex('test59');
Using AI Code Generation
1var BestMatchIndex = require('best-match-index');2var index = BestMatchIndex.newIndex({3});4### BestMatchIndex.newIndex(dictionary)5var BestMatchIndex = require('best-match-index');6var index = BestMatchIndex.newIndex({7});8### BestMatchIndex#setDictionary(dictionary)9var BestMatchIndex = require('best-match-index');10var index = BestMatchIndex.newIndex({11});12index.setDictionary({13});14### BestMatchIndex#getBestMatch(key)15var BestMatchIndex = require('best-match-index');
Using AI Code Generation
1var BestMatch = require('best-match');2var bestMatch = new BestMatch();3var data = ["a","b","c","d","e","f","g","h","i","j","k","l","m"];4var index = bestMatch.newIndex(data);5console.log(index);6var BestMatch = require('best-match');7var bestMatch = new BestMatch();8var data = ["a","b","c","d","e","f","g","h","i","j","k","l","m"];9var index = bestMatch.newIndex(data);10var result = bestMatch.bestMatch("a",index);11console.log(result);12var BestMatch = require('best-match');13var bestMatch = new BestMatch();14var data = ["a","b","c","d","e","f","g","h","i","j","k","l","m"];15var index = bestMatch.newIndex(data);16var result = bestMatch.bestMatch("a",index);17console.log(result);18var BestMatch = require('best-match');19var bestMatch = new BestMatch();20var data = ["a","b","c","d","e","f","g","h","i","j","k","l","m"];21var index = bestMatch.newIndex(data);22var result = bestMatch.bestMatch("a",index);23console.log(result);24var BestMatch = require('best-match');25var bestMatch = new BestMatch();26var data = ["a","b","c","d","e","f","g","h","i","j","k","l","m"];27var index = bestMatch.newIndex(data);28var result = bestMatch.bestMatch("a",index);29console.log(result);30var BestMatch = require('best-match');31var bestMatch = new BestMatch();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!