Best JavaScript code snippet using devicefarmer-stf
term.js
Source:term.js
...54 // TODO(mack): remove duplicate with similar logic in CourseView55 toggleTermVisibility: function(evt) {56 var termVisible = this.$('.course-collection').is(':visible');57 if (termVisible) {58 this.collapseTerm(evt);59 } else {60 this.expandTerm(evt);61 }62 _util.storeLocalData(this.getTermExpandedKey(), !termVisible);63 },64 expandTerm: function(evt) {65 if (!this.hasBeenExpanded) {66 this.expand = true;67 this.render();68 }69 this.$('.course-collection').fancySlide('down')70 .end().find('.term-name .arrow')71 .removeClass('icon-caret-right')72 .addClass('icon-caret-down');73 // TODO(david): Make this fn automatically called on show of courses74 this.courseCollectionView.onShow();75 },76 collapseTerm: function(evt) {77 this.expand = false;78 this.$('.course-collection').fancySlide('up')79 .end().find('.term-name .arrow')80 .removeClass('icon-caret-down')81 .addClass('icon-caret-right');82 }83 });84 var TermCollection = RmcBackbone.Collection.extend({85 model: TermModel86 });87 var TermCollectionView = RmcBackbone.View.extend({88 tagName: 'ol',89 className: 'term-collection',90 initialize: function(attributes) {91 this.termCollection = attributes.termCollection;92 this.termViews = [];93 },94 render: function() {95 this.$el.empty();96 this.termCollection.each(function(termModel, idx) {97 var expand = idx < 3;98 var termView = new TermView({99 tagName: 'li',100 termModel: termModel,101 expand: expand102 });103 this.$el.append(termView.render().el);104 this.termViews.push(termView);105 }, this);106 return this;107 },108 addTerm: function(term) {109 var termView = new TermView({110 termModel: term,111 tagName: 'li',112 expand: true113 });114 this.$el.prepend(termView.render().el);115 this.termViews.push(termView);116 },117 get: function(term_id) {118 return this.termViews.find(function(term) {119 return term.termModel.id === term_id;120 });121 }122 });123 var AddTermBtnView = RmcBackbone.View.extend({124 className: 'add-term-btn',125 initialize: function() {126 this.template = _.template($('#add-term-btn-tpl').html());127 },128 render: function() {129 this.$el.html(this.template({}));130 return this;131 },132 events: {133 'click': 'onAddTermBtnClick'134 },135 onAddTermBtnClick: function() {136 $('.schedule-input-modal').modal(); // TODO(david): This is a hack137 }138 });139 var ProfileTermsView = RmcBackbone.View.extend({140 className: 'profile-terms',141 initialize: function(options) {142 this.termCollection = options.termCollection;143 this.termCollectionView = new TermCollectionView({144 termCollection: this.termCollection145 });146 if (options.showAddTerm) {147 this.addTermBtnView = new AddTermBtnView();148 }149 this.template = _.template($('#profile-terms-tpl').html());150 },151 addToShortlist: function(course) {152 var term = this.termCollectionView.get('9999_99');153 if (!term) {154 // make shortlist if it does not exist155 var shortlistModel = new TermModel({156 'course_ids': [],157 'program_year_id': 'None',158 'id': '9999_99',159 'name': 'Shortlist'160 });161 this.termCollectionView.addTerm(shortlistModel);162 term = this.termCollectionView.get('9999_99');163 }164 term.addCourse(course, '9999_99');165 },166 events: {167 'autoScroll': 'scrollToNextCourseDelayed'168 },169 scrollToNextCourseDelayed: function(event, course) {170 setTimeout(_.bind(this.scrollToNextCourse, this, event, course), 400);171 },172 scrollToNextCourse: function(event, course) {173 // Get the list of courses, in displayed order, after the current course174 var courses = this.termCollection.reduce(function(list, term) {175 return list.concat(term.get('courses').models);...
updateWeight.js
Source:updateWeight.js
1/**2 * @file js for changing weights of terms with Up and Down arrows3 */4(function ($) {5//object to store weights (tid => weight)6var termWeightsData = new Object();7Drupal.behaviors.TaxonomyManagerWeights = {8 attach: function(context, settings) {9 var weightSettings = settings.updateWeight || [];10 if (!$('#edit-toolbar.tm-weights-processed').length) {11 $('#edit-toolbar').addClass('tm-weights-processed');12 termWeightsData['form_token'] = $('input[name=form_token]').val();13 termWeightsData['form_id'] = $('input[name=form_id]').val();14 termWeightsData['weights'] = new Object();15 Drupal.attachUpdateWeightToolbar(weightSettings['up'], weightSettings['down']);16 Drupal.attachUpdateWeightTerms();17 }18 }19}20/**21 * adds click events for Up and Down buttons in the toolbar, which22 * allow the moving of selected (can be more) terms23 */24Drupal.attachUpdateWeightToolbar = function(upButton, downButton) {25 var selected;26 var url = Drupal.settings.updateWeight['url'];27 $('#'+ upButton).click(function() {28 selected = Drupal.getSelectedTerms();29 for (var i=0; i < selected.length; i++) {30 var upTerm = selected[i];31 var downTerm = $(upTerm).prev();32 Drupal.orderTerms(upTerm, downTerm);33 }34 if (selected.length > 0) {35 $.post(url, termWeightsData);36 }37 });38 $('#'+ downButton).click(function() {39 selected = Drupal.getSelectedTerms();40 for (var i=selected.length-1; i >= 0; i--) {41 var downTerm = selected[i];42 var upTerm = $(downTerm).next();43 Drupal.orderTerms(upTerm, downTerm);44 }45 if (selected.length > 0) {46 $.post(url, termWeightsData);47 }48 });49}50/**51 * adds small up and down arrows to each term52 * arrows get displayed on mouseover53 */54Drupal.attachUpdateWeightTerms = function(parent, currentIndex) {55 var settings = Drupal.settings.updateWeight || [];56 var disable = settings['disable_mouseover'];57 if (!disable) {58 var url = Drupal.settings.updateWeight['url'];59 var termLineClass = 'div.term-line';60 var termUpClass = 'img.term-up';61 var termDownClass = 'img.term-down';62 if (parent && currentIndex) {63 parent = $(parent).slice(currentIndex);64 }65 if (parent) {66 termLineClass = $(parent).find(termLineClass);67 termUpClass = $(parent).find(termUpClass);68 termDownClass = $(parent).find(termDownClass);69 }70 $(termLineClass).mouseover(function() {71 $(this).find('div.term-operations').show();72 });73 $(termLineClass).mouseout(function() {74 $(this).find('div.term-operations').hide();75 });76 $(termUpClass).click(function() {77 var upTerm = $(this).parents("li").eq(0);78 var downTerm = $(upTerm).prev();79 Drupal.orderTerms(upTerm, downTerm);80 $.post(url, termWeightsData);81 $(downTerm).find(termLineClass).unbind('mouseover');82 setTimeout(function() {83 $(upTerm).find('div.term-operations').hide();84 $(downTerm).find(termLineClass).mouseover(function() {85 $(this).find('div.term-operations').show();86 });87 }, 1500);88 });89 $(termDownClass).click(function() {90 var downTerm = $(this).parents("li").eq(0);91 var upTerm = $(downTerm).next();92 Drupal.orderTerms(upTerm, downTerm);93 $.post(url, termWeightsData);94 $(upTerm).find(termLineClass).unbind('mouseover');95 setTimeout(function() {96 $(downTerm).find('div.term-operations').hide();97 $(upTerm).find(termLineClass).mouseover(function() {98 $(this).find('div.term-operations').show();99 });100 }, 1500);101 });102 }103}104/**105 * return array of selected terms106 */107Drupal.getSelectedTerms = function() {108 var terms = new Array();109 $('.treeview').find("input:checked").each(function() {110 var term = $(this).parents("li").eq(0);111 terms.push(term);112 });113 return terms;114}115/**116 * reorders terms117 * - swap list elements in DOM118 * - post updated weights to callback in php119 * - update classes of tree view120 */121Drupal.orderTerms = function(upTerm, downTerm) {122 try {123 Drupal.getTermId(upTerm);124 Drupal.swapTerms(upTerm, downTerm);125 Drupal.swapWeights(upTerm, downTerm);126 Drupal.updateTree(upTerm, downTerm);127 } catch(e) {128 //no next item, because term to update is last child, continue129 }130}131/**132 * simple swap of two elements133 */134Drupal.swapTerms = function(upTerm, downTerm) {135 $(upTerm).after(downTerm);136 $(downTerm).before(upTerm);137}138/**139 * updating weights of swaped terms140 * if two terms have different weights, then weights are being swapped141 * else, if both have same weights, upTerm gets decreased142 *143 * if prev/next siblings of up/down terms have same weights as current144 * swapped, they have to be updated by de/increasing weight (by 1) to ensure145 * unique position of swapped terms146 */147Drupal.swapWeights = function(upTerm, downTerm) {148 var upWeight = Drupal.getWeight(upTerm);149 var downWeight = Drupal.getWeight(downTerm);150 var downTid = Drupal.getTermId(downTerm);151 var upTid = Drupal.getTermId(upTerm);152 //same weight, decrease upTerm153 if (upWeight == downWeight) {154 termWeightsData['weights'][upTid] = --upWeight;155 }156 //different weights, swap157 else {158 termWeightsData['weights'][upTid] = downWeight;159 termWeightsData['weights'][downTid] = upWeight;160 }161 //update prev siblings if necessary162 try {163 if (Drupal.getWeight($(upTerm).prev()) >= upWeight) {164 $(upTerm).prevAll().each(function() {165 var id = Drupal.getTermId(this);166 var weight = Drupal.getWeight(this);167 termWeightsData['weights'][id] = --weight;168 });169 }170 } catch(e) {171 //no prev172 }173 //update next siblings if necessary174 try {175 if (Drupal.getWeight($(downTerm).next()) <= downWeight) {176 $(downTerm).nextAll().each(function() {177 var id = Drupal.getTermId(this);178 var weight = Drupal.getWeight(this);179 termWeightsData['weights'][id] = ++weight;180 });181 }182 } catch(e) {183 //no next184 }185}186/**187 * helper to return weight of a term188 */189Drupal.getWeight = function(li) {190 var id = Drupal.getTermId(li);191 var weight;192 if (termWeightsData['weights'][id] != null) {193 weight = termWeightsData['weights'][id];194 }195 else {196 weight = $(li).find("input:hidden[class=weight-form]").attr("value");197 }198 return weight;199}...
SeismoMeta.js
Source:SeismoMeta.js
1var meta = [2 {"term": "--Metadata--"},3 {"term":"_event_id"},4 {"term":"calib" },5 {"term":"channel"},6 {"term":" delta"},7 {"term":"depth_in_km"}, 8 {"term":"description"}, 9 {"term":"endtime"}, 10 {"term":"latitude"}, 11 {"term":"location"}, 12 {"term":"longitude"}, 13 {"term":"m_pp"}, 14 {"term":"m_rp"}, 15 {"term":"m_rr"}, 16 {"term":"m_rt"}, 17 {"term":"m_tp"}, 18 {"term":"m_tt"}, 19 {"term":"magnitude"},20 {"term":"mime-type"},21 {"term":" network"}, 22 {"term":"npts"}, 23 {"term":"origin_time"},24 {"term":" path"}, 25 {"term":"sampling_rate"},26 {"term":" starttime"}, 27 {"term":"station"}, 28 {"term":"type"},29 {"term": "--Parameters--"},30 {"term": "ABSORB_INSTEAD_OF_FREE_SURFACE"},31 {"term": "ANISOTROPY"},32 {"term": "ATTENUATION"},33 {"term": "CREATE_SHAKEMAP"}, 34 {"term": "DT"},35 {"term": "f0_FOR_PML"},36 {"term": "GPU_MODE"},37 {"term": "GRAVITY"},38 {"term": "HDUR_MOVIE"}, 39 {"term": "LOCAL_PATH"},40 {"term": "mesh"},41 {"term": "MODEL"},42 {"term": "MOVIE_SURFACE"},43 {"term": "MOVIE_TYPE"},44 {"term": "MOVIE_VOLUME"},45 {"term": "NGNOD"},46 {"term": "NOISE_TOMOGRAPHY"},47 {"term": "NPROC"},48 {"term": "NTSTEP_BETWEEN_FRAMES"},49 {"term": "NTSTEP_BETWEEN_OUTPUT_INFO"}, 50 {"term": "NTSTEP_BETWEEN_OUTPUT_SEISMOS"}, 51 {"term": "NTSTEP_BETWEEN_READ_ADJSRC"}, 52 {"term": "OLSEN_ATTENUATION_RATIO"}, 53 {"term": "PML_CONDITIONS"}, 54 {"term": "PML_INSTEAD_OF_FREE_SURFACE"}, 55 {"term": "PML_WIDTH_MAX"}, 56 {"term": "PML_WIDTH_MIN"}, 57 {"term": "PRINT_SOURCE_TIME_FUNCTION"}, 58 {"term": "ROTATE_PML_ACTIVATE"}, 59 {"term": "ROTATE_PML_ANGLE"}, 60 {"term": "SAVE_DISPLACEMENT"}, 61 {"term": "SAVE_FORWARD"}, 62 {"term": "SAVE_MESH_FILES"}, 63 {"term": "OCEANS"}, 64 {"term": "NSTEP"}, 65 {"term": "SIMULATION_TYPE"},66 {"term": "SUPPRESS_UTM_PROJECTION"},67 {"term": "TOMOGRAPHY_PATH"},68 {"term": "TOPOGRAPHY"},69 {"term": "USE_FORCE_POINT_SOURCE"}, 70 {"term": "USE_HIGHRES_FOR_MOVIES"}, 71 {"term": "USE_OLSEN_ATTENUATION"}, 72 {"term": "USE_RICKER_TIME_FUNCTION"}, 73 {"term": "UTM_PROJECTION_ZONE"},74 {"term": "velocity_model"}75 76 77 ];78Ext.define('RS.store.SeismoMeta', {79 extend: 'Ext.data.Store',80 model: 'RS.model.SeismoMeta',81 data: meta...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var term = new stf.Term();3term.on('data', function(data){4 console.log(data);5});6term.on('error', function(err){7 console.log(err);8});9term.on('close', function(code){10 console.log(code);11});12term.write('ls -la');13var stf = require('devicefarmer-stf');14var term = new stf.Term();15term.on('data', function(data){16 console.log(data);17});18term.on('error', function(err){19 console.log(err);20});21term.on('close', function(code){22 console.log(code);23});24term.write('ls -la');25var stf = require('devicefarmer-stf');26var term = new stf.Term();27term.on('data', function(data){28 console.log(data);29});30term.on('error', function(err){31 console.log(err);32});33term.on('close', function(code){34 console.log(code);35});36term.write('ls -la');37var stf = require('devicefarmer-stf');38var term = new stf.Term();39term.on('data', function(data){40 console.log(data);41});42term.on('error', function(err){43 console.log(err);44});45term.on('close', function(code){46 console.log(code);47});48term.write('ls -la');49var stf = require('devicefarmer-stf');50var term = new stf.Term();51term.on('data', function(data){52 console.log(data);53});54term.on('error', function(err){55 console.log(err);56});57term.on('close', function(code){58 console.log(code);59});60term.write('ls -la');61var stf = require('devicefarmer-stf');62var term = new stf.Term();63term.on('data', function(data){64 console.log(data);65});66term.on('error', function(err){67 console.log(err);68});69term.on('close', function(code){70 console.log(code);71});72term.write('ls -la');
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2client.getDevices().then(function (devices) {3 var device = devices[0];4 var term = device.term();5 term.write('ls -l');6 term.write('pwd');7 term.write('cd /');8 term.write('pwd');9 term.on('data', function (data) {10 console.log(data);11 });12});
Using AI Code Generation
1var Client = require('devicefarmer-stf-client').Client;2var term = client.term('device-id');3term.on('data', function(data) {4 console.log(data);5});6term.write('ls -la');7term.end();
Using AI Code Generation
1var Term = require('devicefarmer-stf').Term;2var term = new Term();3term.Term('adb devices', function(err, data) {4 if (err) {5 console.log(err);6 }7 console.log(data);8});9var Term = require('devicefarmer-stf').Term;10var term = new Term();11term.Term('adb devices', function(err, data) {12 if (err) {13 console.log(err);14 }15 console.log(data);16});17var Term = require('devicefarmer-stf').Term;18var term = new Term();19term.Term('adb devices', function(err, data) {20 if (err) {21 console.log(err);22 }23 console.log(data);24});25var Term = require('devicefarmer-stf').Term;26var term = new Term();27term.Term('adb devices', function(err, data) {28 if (err) {29 console.log(err);30 }31 console.log(data);32});33var Term = require('devicefarmer-stf').Term;34var term = new Term();35term.Term('adb devices', function(err, data) {36 if (err) {37 console.log(err);38 }39 console.log(data);40});41var Term = require('devicefarmer-stf').Term;42var term = new Term();43term.Term('adb devices', function(err, data) {44 if (err) {45 console.log(err);46 }47 console.log(data);48});
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2device.connect(function(err) {3 if (err) throw err;4 device.term('ls', function(err, stream) {5 if (err) throw err;6 stream.pipe(process.stdout);7 });8});9var devicefarmer = require('devicefarmer-stf');10device.connect(function(err) {11 if (err) throw err;12 device.term('ls', function(err, stream) {13 if (err) throw err;14 stream.pipe(process.stdout);15 });16});17var devicefarmer = require('devicefarmer-stf');18device.connect(function(err) {19 if (err) throw err;20 device.term('ls', function(err, stream) {21 if (err) throw err;22 stream.pipe(process.stdout);23 });24});25var devicefarmer = require('devicefarmer-stf');26device.connect(function(err) {27 if (err) throw err;28 device.term('ls', function(err, stream) {29 if (err) throw err;30 stream.pipe(process.stdout);31 });32});33var devicefarmer = require('devicefarmer-stf');34device.connect(function(err) {35 if (err) throw err;36 device.term('ls', function(err, stream) {37 if (err) throw err;38 stream.pipe(process.stdout);39 });40});41var devicefarmer = require('devicefarmer-stf');42device.connect(function(err) {43 if (err) throw err;
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2device.term("ls -l");3var devicefarmer = require('devicefarmer-stf');4device.term("ls -l");5var devicefarmer = require('devicefarmer-stf');6device.term("ls -l");7var devicefarmer = require('devicefarmer-stf');8device.term("ls -l");9var devicefarmer = require('devicefarmer-stf');10device.term("ls -l");11var devicefarmer = require('devicefarmer-stf');12device.term("ls -l");13var devicefarmer = require('devicefarmer-stf');14device.term("ls -l");15var devicefarmer = require('devicefarmer-stf');16device.term("ls -l");17var devicefarmer = require('devicefarmer-stf');18device.term("ls -l");
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf-api');2var device = new devicefarmer.Device("localhost", 7100);3device.Term("5555", "ls -l");4var devicefarmer = require('devicefarmer-stf-api');5var device = new devicefarmer.Device("localhost", 7100);6device.Term("5555", "ls -l");7var devicefarmer = require('devicefarmer-stf-api');8var device = new devicefarmer.Device("localhost", 7100);9device.Term("5555", "ls -l");10var devicefarmer = require('devicefarmer-stf-api');11var device = new devicefarmer.Device("localhost", 7100);12device.Term("5555", "ls -l");13var devicefarmer = require('devicefarmer-stf-api');14var device = new devicefarmer.Device("localhost", 7100);15device.Term("5555", "ls -l");16var devicefarmer = require('devicefarmer-stf-api');17var device = new devicefarmer.Device("localhost", 7100);18device.Term("5555", "ls -l");19var devicefarmer = require('devicefarmer-stf-api');20var device = new devicefarmer.Device("localhost", 7100);21device.Term("5555", "ls -l");22var devicefarmer = require('devicefarmer-stf-api');23var device = new devicefarmer.Device("localhost", 7100);24device.Term("5555", "ls -l");25var devicefarmer = require('devicefarmer-stf-api');
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2var device = new devicefarmer.Device({3});4device.term('ls -la');5var devicefarmer = require('devicefarmer-stf');6var device = new devicefarmer.Device({7});8device.term('ls -la');9var devicefarmer = require('devicefarmer-stf');10var device = new devicefarmer.Device({11});12device.term('ls -la')13.then(function(result) {14 console.log(result);15});16var devicefarmer = require('devicefarmer-stf');17var device = new devicefarmer.Device({18});19device.install('path/to/apk');20var devicefarmer = require('devicefarmer-stf');21var device = new devicefarmer.Device({22});23device.install('path/to/apk')24.then(function(result) {25 console.log(result);26});
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!!