Best JavaScript code snippet using wpt
poem_advance.js
Source:poem_advance.js
1// the translate button2gmodel="";3gtopic="";4previous_topic="";5previous_id=-1;6previous_nline = -1;7previous_lang = -1;8api_host = window.location.hostname910function to_disable_adjust(){11 var nline = $("input[name=nline]:checked").val();12 var lang = $("input[name=model]:checked").val();13 if ((nline != previous_nline) || (lang != previous_lang)){14 $("#adjust-button").prop('disabled',true);15 } else {16 $("#adjust-button").prop('disabled',false);17 }18 if (lang == 1){19 $("#adjust-button").prop('disabled',true);20 }21}2223function remove_empty(l){24 new_l = [];25 26 for (i = 0; i<l.length; i ++){27 if (l[i] != ""){28 new_l.push(l[i]);29 }30 }31 return new_l;32}3334function highlight_rhyme(poem, rhyme){35 lines = remove_empty(poem.split("<br//>"));36 rhymes = remove_empty(rhyme.split("<br//>"));37 new_poem = "";38 console.log(rhymes)39 for (i = 0; i < rhymes.length; i += 1){40 line = lines[i].trim()41 words = rhymes[i]42 nrhyme = words.split("_").length43 ll = line.split(" ")44 new_line = ll.slice(0,ll.length-nrhyme).join(" ") + " " + "<span class=\"rhyme_span\">" + ll.slice(ll.length-nrhyme,ll.length).join(" ") + "</span><br//>"45 new_poem+=new_line46 if (i % 4 == 3) {new_poem +="<br//>";}47 }48 return new_poem49}505152function onselect_language(n){53 // n = 1 English54 // n = 2 Spanish55 to_disable_adjust()56 if (n == 2){57 $("input[name=nline][value=14]").prop("checked",true);58 $("input[name=nline][value!=14]").parent().css('color','lightgrey');59 $("input[name=nline]").prop("disabled",true);6061 $("input[name=genre][value=lyrical]").prop("checked",true);62 $("input[name=genre][value!=lyrical]").parent().css('color','lightgrey');63 $("input[name=genre]").prop("disabled",true);6465 $("input[name=meter][value=iambic]").prop("checked",true);66 $("input[name=meter][value!=iambic]").parent().css('color','lightgrey');67 $("input[name=meter]").prop("disabled",true);68 69 $("input[name=format][value=ss]").prop("checked",true);70 $("input[name=format][value!=ss]").parent().css('color','lightgrey');71 $("input[name=format]").prop("disabled",true);7273 $("input[name=encourage_words]").prop("disabled",true);74 $("input[name=disencourage_words]").prop("disabled",true);75 76 $("#enc").slider().slider("disable");77 $("#cwords").slider().slider("disable");78 $("#reps").slider().slider("disable");79 $("#allit").slider().slider("disable");80 $("#wordlen").slider().slider("disable");8182 $("#topical").slider().slider("disable");83 $("#mono").slider().slider("disable");84 $("#sentiment").slider().slider("disable");85 $("#concrete").slider().slider("disable");8687 $("#enc_weight").prop('disabled',true);88 $("#cword_weight").prop('disabled',true);89 $("#reps_weight").prop('disabled',true);90 $("#allit_weight").prop('disabled',true);91 $("#wordlen_weight").prop('disabled',true);9293 $("#topical_weight").prop('disabled',true);94 $("#mono_weight").prop('disabled',true);95 $("#sentiment_weight").prop('disabled',true);96 $("#concrete_weight").prop('disabled',true);97 9899 } else if (n == 1){100 $("input[name=nline]").prop("disabled",false);101 $("input[name=nline][value=4]").prop("checked",true);102 $("input[name=nline]").parent().css('color','black');103104 $("input[name=genre][value=lyrical]").prop("checked",true);105 $("input[name=genre][value!=lyrical]").parent().css('color','lightgrey');106 $("input[name=genre]").prop("disabled",true);107108 $("input[name=meter][value=iambic]").prop("checked",true);109 $("input[name=meter][value!=iambic]").parent().css('color','lightgrey');110 $("input[name=meter]").prop("disabled",true);111 112 $("input[name=format][value=ss]").prop("checked",true);113 $("input[name=format][value!=ss]").parent().css('color','lightgrey');114 $("input[name=format]").prop("disabled",true);115116 $("input[name=encourage_words]").prop("disabled",false);117 $("input[name=disencourage_words]").prop("disabled",false);118 119 $("#enc").slider().slider("enable"); 120 $("#cwords").slider().slider("enable");121 $("#reps").slider().slider("enable");122 $("#allit").slider().slider("enable");123 $("#wordlen").slider().slider("enable");124125 $("#topical").slider().slider("enable");126 $("#mono").slider().slider("enable");127 $("#sentiment").slider().slider("enable");128 $("#concrete").slider().slider("enable");129130 $("#enc_weight").prop('disabled',false);131 $("#cword_weight").prop('disabled',false);132 $("#reps_weight").prop('disabled',false);133 $("#allit_weight").prop('disabled',false);134 $("#wordlen_weight").prop('disabled',false);135136 $("#topical_weight").prop('disabled',false);137 $("#mono_weight").prop('disabled',false);138 $("#sentiment_weight").prop('disabled',false);139 $("#concrete_weight").prop('disabled',false);140141 142 }143}144145146$('#adjust-button').click(function() {147148 before_translate();149150 var btn = $(this);151 $("#translate-button").prop('disabled',true);152 btn.button('loading');153 $("#poem").html("");154155 lang = previous_lang;156 nline = previous_nline;157 id = previous_id;158 159 //style160 var encourage_words = $('input[name=encourage_words]').val();161 var disencourage_words = $('input[name=disencourage_words]').val();162 var enc_weight = $('input[name=enc_weight]').val();163 var cword = $('input[name=cword_weight]').val();164 var reps = $('input[name=reps_weight]').val();165 var allit = $('input[name=allit_weight]').val();166 var wordlen = $('input[name=wordlen_weight]').val();167168 var topical = $('input[name=topical_weight]').val();169 var mono = $('input[name=mono_weight]').val();170 var sentiment = $('input[name=sentiment_weight]').val();171 var concrete = $('input[name=concrete_weight]').val();172 var is_default = is_default_setting();173 var source = "advance";174175176 eng_data = {177 topic:gtopic,178 k:1,179 model:"0",180 id:id,181 nline:nline,182 encourage_words:encourage_words,183 disencourage_words:disencourage_words,184 enc_weight:enc_weight,185 cword:cword,186 reps:reps,187 allit:allit,188 wordlen:wordlen,189 topical:topical,190 mono:mono,191 sentiment:sentiment,192 concrete:concrete,193 no_fsa:1,194 is_default:is_default,195 source:source196 };197198 data = eng_data;199200 left_time = 6;201202 if (nline == "2"){203 left_time = 1;204 } else if (nline == "4") {205 left_time = 2;206 }207 208 estimation = ""209 var timer = setInterval( function() {210 estimation = "["+left_time + "s] "211 $.ajax(212 {213 url : "http://"+api_host+":"+port+"/api/poem_status",214 data: {id:id},215 type:"GET",216 xhrFields:{withCredentials:false},217 success: function (response_data) {218 left_time = left_time - 1219 $("#status").html(estimation + response_data);220 }221 }222 );223 },1000)224225 $.ajax({226 url: "http://"+api_host+":"+port+"/api/poem_check",227 data: data,228 type:"GET",229 xhrFields: {230 // The 'xhrFields' property sets additional fields on the XMLHttpRequest.231 // This can be used to set the 'withCredentials' property.232 // Set the value to 'true' if you'd like to pass cookies to the server.233 // If this is enabled, your server must respond with the header234 // 'Access-Control-Allow-Credentials: true'.235 withCredentials: false236 },237 success: function(response_data) {238 $("#translate-button").prop('disabled',false);239 jd = $.parseJSON(response_data);240241 $("#npoem").html(jd.n_poem);242 $("#poem_id").html(jd.poem_id);243 244245 //$("#poem").html(highlight_rhyme(jd.poem,jd.rhyme_words));246 $("#poem").html(jd.poem);247 $("#config").html(jd.config);248 $("#rhyme-info").html(jd.rhyme_info);249 $("#rhyme-words").html(jd.rhyme_words);250 $("#exact-rhyme-candidates").html(jd.exact_rhyme_candidates);251 $("#pc").html(jd.pc);252 $("#status").html("Ready");253 254 init_star();255 }256 }).always(function (){257 $("#translate-button").prop('disabled',false);258 btn.button('reset');259 clearInterval(timer);260 });261262});263264265266$('#translate-button').click(function() {267268 before_translate();269270 var btn = $(this);271 $("#adjust-button").prop('disabled',true);272 btn.button('loading');273 $("#poem").html("");274 $("#config").html("");275 $("#rhyme-info").html("");276 $("#rhyme-words").html("");277 $("#pc").html("");278 $("#exact-rhyme-candidates").html("");279280281 var lang = $("input[name=model]:checked").val();282283 var nline = $("input[name=nline]:checked").val();284285 port = 8080;286 if (lang == 1){287 port = 8081;288 }289290 var model = "0";291 var topic = $('#input-topic').val();292 topic = topic.replace(/ /g, "_");293 if (topic == ""){294 if (lang == 0){295 topic = "civil_war";296 } else {297 topic = "guerra_civil";298 }299 }300301 id = Math.round(Math.random()*10000) + 1302 gmodel = model;303 gtopic = topic;304305306307308309310 //style311 var encourage_words = $('input[name=encourage_words]').val();312 var disencourage_words = $('input[name=disencourage_words]').val();313 var enc_weight = $('input[name=enc_weight]').val();314 var cword = $('input[name=cword_weight]').val();315 var reps = $('input[name=reps_weight]').val();316 var allit = $('input[name=allit_weight]').val();317 var wordlen = $('input[name=wordlen_weight]').val();318319 var topical = $('input[name=topical_weight]').val();320 var mono = $('input[name=mono_weight]').val();321 var sentiment = $('input[name=sentiment_weight]').val();322 var concrete = $('input[name=concrete_weight]').val();323 var is_default = is_default_setting();324 var source = "advance";325326 eng_data = {327 topic:topic,328 k:1,329 model:model,330 id:id,331 nline:nline,332 encourage_words:encourage_words,333 disencourage_words:disencourage_words,334 enc_weight:enc_weight,335 cword:cword,336 reps:reps,337 allit:allit,338 wordlen:wordlen,339 topical:topical,340 mono:mono,341 sentiment:sentiment,342 concrete:concrete,343 is_default:is_default,344 source:source345 };346 spa_data = {347 topic:topic,348 k:1,349 model:model,350 id:id,351 nline:nline,352 };353 data = eng_data;354 if (lang ==1 ) // spanish355 {356 data = spa_data;357 }358359 left_time = 6;360 if (lang == 1){361 left_time = 60;362 } else {363 if (nline == "2"){364 left_time = 1;365 } else if (nline == "4") {366 left_time = 2;367 }368 }369 estimation = ""370 var timer = setInterval( function() {371 estimation = "["+left_time + "s] "372 $.ajax(373 {374 url : "http://"+api_host+":"+port+"/api/poem_status",375 data: {id:id},376 type:"GET",377 xhrFields:{withCredentials:false},378 success: function (response_data) {379 left_time = left_time - 1380 $("#status").html(estimation + response_data);381 }382 }383 );384 },1000)385386 $.ajax({387 url: "http://"+api_host+":"+port+"/api/poem_check",388 data: data,389 type:"GET",390 xhrFields: {391 // The 'xhrFields' property sets additional fields on the XMLHttpRequest.392 // This can be used to set the 'withCredentials' property.393 // Set the value to 'true' if you'd like to pass cookies to the server.394 // If this is enabled, your server must respond with the header395 // 'Access-Control-Allow-Credentials: true'.396 withCredentials: false397 },398 success: function(response_data) {399 previous_id = id;400 previous_nline = nline;401 previous_lang = lang;402 $("#adjust-button").prop('disabled',false);403404 jd = $.parseJSON(response_data);405 $("#npoem").html(jd.n_poem);406 $("#npoem_alexa").html(jd.n_poem_alexa);407 $("#poem_id").html(jd.poem_id);408 //$("#poem").html(highlight_rhyme(jd.poem,jd.rhyme_words));409 $("#poem").html(jd.poem);410 $("#config").html(jd.config);411 $("#rhyme-info").html(jd.rhyme_info);412 $("#rhyme-words").html(jd.rhyme_words);413 $("#exact-rhyme-candidates").html(jd.exact_rhyme_candidates);414 $("#pc").html(jd.pc);415 $("#status").html("Ready");416417 init_star();418 }419 }).always(function (){420 btn.button('reset');421 clearInterval(timer);422 });423424425});426427onselect_language(1);
...
poem_experiment.js
Source:poem_experiment.js
1// the translate button2gmodel="";3gtopic="";4previous_topic="";5previous_id=-1;6previous_nline = -1;7previous_lang = -1;8api_host = window.location.hostname;9n_regen = 0;10ticket = 0;11scored = 0;12poem_history = {};13function generate_ticket(){14 if (ticket != 0){15 return ticket;16 }17 else {18 r = Math.round(Math.random()*1000) + 2;19 ticket = 821 * r - 1;20 return ticket;21 }22}23function to_disable_adjust(){24 var nline = $("input[name=nline]:checked").val();25 var lang = $("input[name=model]:checked").val();26 if ((nline != previous_nline) || (lang != previous_lang)){27 $("#adjust-button").prop('disabled',true);28 } else {29 $("#adjust-button").prop('disabled',false);30 }31 if (lang == 1){32 $("#adjust-button").prop('disabled',true);33 }34}35function onselect_language(n){36 // n = 1 English37 // n = 2 Spanish38 to_disable_adjust()39 if (n == 2){40 $("input[name=nline][value=14]").prop("checked",true);41 $("input[name=nline][value!=14]").parent().css('color','lightgrey');42 $("input[name=nline]").prop("disabled",true);43 $("input[name=genre][value=lyrical]").prop("checked",true);44 $("input[name=genre][value!=lyrical]").parent().css('color','lightgrey');45 $("input[name=genre]").prop("disabled",true);46 $("input[name=meter][value=iambic]").prop("checked",true);47 $("input[name=meter][value!=iambic]").parent().css('color','lightgrey');48 $("input[name=meter]").prop("disabled",true);49 50 $("input[name=format][value=ss]").prop("checked",true);51 $("input[name=format][value!=ss]").parent().css('color','lightgrey');52 $("input[name=format]").prop("disabled",true);53 $("input[name=encourage_words]").prop("disabled",true);54 $("input[name=disencourage_words]").prop("disabled",true);55 56 $("#enc").slider().slider("disable");57 $("#cwords").slider().slider("disable");58 $("#reps").slider().slider("disable");59 $("#allit").slider().slider("disable");60 $("#wordlen").slider().slider("disable");61 $("#topical").slider().slider("disable");62 $("#mono").slider().slider("disable");63 $("#sentiment").slider().slider("disable");64 $("#concrete").slider().slider("disable");65 $("#enc_weight").prop('disabled',true);66 $("#cword_weight").prop('disabled',true);67 $("#reps_weight").prop('disabled',true);68 $("#allit_weight").prop('disabled',true);69 $("#wordlen_weight").prop('disabled',true);70 $("#topical_weight").prop('disabled',true);71 $("#mono_weight").prop('disabled',true);72 $("#sentiment_weight").prop('disabled',true);73 $("#concrete_weight").prop('disabled',true);74 75 } else if (n == 1){76 $("input[name=nline]").prop("disabled",false);77 $("input[name=nline][value=4]").prop("checked",true);78 $("input[name=nline]").parent().css('color','black');79 $("input[name=genre][value=lyrical]").prop("checked",true);80 $("input[name=genre][value!=lyrical]").parent().css('color','lightgrey');81 $("input[name=genre]").prop("disabled",true);82 $("input[name=meter][value=iambic]").prop("checked",true);83 $("input[name=meter][value!=iambic]").parent().css('color','lightgrey');84 $("input[name=meter]").prop("disabled",true);85 86 $("input[name=format][value=ss]").prop("checked",true);87 $("input[name=format][value!=ss]").parent().css('color','lightgrey');88 $("input[name=format]").prop("disabled",true);89 $("input[name=encourage_words]").prop("disabled",false);90 $("input[name=disencourage_words]").prop("disabled",false);91 92 $("#enc").slider().slider("enable"); 93 $("#cwords").slider().slider("enable");94 $("#reps").slider().slider("enable");95 $("#allit").slider().slider("enable");96 $("#wordlen").slider().slider("enable");97 $("#topical").slider().slider("enable");98 $("#mono").slider().slider("enable");99 $("#sentiment").slider().slider("enable");100 $("#concrete").slider().slider("enable");101 $("#enc_weight").prop('disabled',false);102 $("#cword_weight").prop('disabled',false);103 $("#reps_weight").prop('disabled',false);104 $("#allit_weight").prop('disabled',false);105 $("#wordlen_weight").prop('disabled',false);106 $("#topical_weight").prop('disabled',false);107 $("#mono_weight").prop('disabled',false);108 $("#sentiment_weight").prop('disabled',false);109 $("#concrete_weight").prop('disabled',false);110 111 }112}113$('#adjust-button').click(function() {114 before_translate();115 var btn = $(this);116 $("#translate-button").prop('disabled',true);117 btn.button('loading');118 $("#poem").html("");119 lang = previous_lang;120 nline = previous_nline;121 id = previous_id;122 123 //style124 var encourage_words = $('input[name=encourage_words]').val();125 var disencourage_words = $('input[name=disencourage_words]').val();126 var enc_weight = $('input[name=enc_weight]').val();127 var cword = $('input[name=cword_weight]').val();128 var reps = $('input[name=reps_weight]').val();129 var allit = $('input[name=allit_weight]').val();130 var wordlen = $('input[name=wordlen_weight]').val();131 var topical = $('input[name=topical_weight]').val();132 var mono = $('input[name=mono_weight]').val();133 var sentiment = $('input[name=sentiment_weight]').val();134 var concrete = $('input[name=concrete_weight]').val();135 var is_default = is_default_setting();136 var source = "experiment";137 eng_data = {138 topic:gtopic,139 k:1,140 model:"0",141 id:id,142 nline:nline,143 encourage_words:encourage_words,144 disencourage_words:disencourage_words,145 enc_weight:enc_weight,146 cword:cword,147 reps:reps,148 allit:allit,149 wordlen:wordlen,150 topical:topical,151 mono:mono,152 sentiment:sentiment,153 concrete:concrete,154 no_fsa:1,155 is_default:is_default,156 source:source157 };158 data = eng_data;159 left_time = 6;160 if (nline == "2"){161 left_time = 1;162 } else if (nline == "4") {163 left_time = 2;164 }165 166 estimation = ""167 var timer = setInterval( function() {168 estimation = "["+left_time + "s] "169 $.ajax(170 {171 url : "http://"+api_host+":"+port+"/api/poem_status",172 data: {id:id},173 type:"GET",174 xhrFields:{withCredentials:false},175 success: function (response_data) {176 left_time = left_time - 1177 $("#status").html(estimation + response_data);178 }179 }180 );181 },1000)182 $.ajax({183 url: "http://"+api_host+":"+port+"/api/poem_check",184 data: data,185 type:"GET",186 xhrFields: {187 // The 'xhrFields' property sets additional fields on the XMLHttpRequest.188 // This can be used to set the 'withCredentials' property.189 // Set the value to 'true' if you'd like to pass cookies to the server.190 // If this is enabled, your server must respond with the header191 // 'Access-Control-Allow-Credentials: true'.192 withCredentials: false193 },194 success: function(response_data) {195 $("#translate-button").prop('disabled',false);196 jd = $.parseJSON(response_data);197 $("#npoem").html(jd.n_poem);198 $("#poem_id").html(jd.poem_id);199 $("#poem_id_show").html(jd.poem_id);200 scored = 0;201 $("#poem").html(jd.poem);202 $("#config").html(jd.config);203 $("#rhyme-info").html(jd.rhyme_info);204 $("#rhyme-words").html(jd.rhyme_words);205 $("#exact-rhyme-candidates").html(jd.exact_rhyme_candidates);206 $("#pc").html(jd.pc);207 $("#status").html("Ready");208 209 if ($('#poem').html() in poem_history){210 same_poem();211 } else {212 init_star();213 }214 }215 }).always(function (){216 $("#translate-button").prop('disabled',false);217 btn.button('reset');218 clearInterval(timer);219 });220});221$('#translate-button').click(function() {222 reset_style();223 before_translate();224 var btn = $(this);225 $("#adjust-button").prop('disabled',true);226 btn.button('loading');227 $("#poem").html("");228 $("#config").html("");229 $("#rhyme-info").html("");230 $("#rhyme-words").html("");231 $("#pc").html("");232 $("#exact-rhyme-candidates").html("");233 var lang = $("input[name=model]:checked").val();234 var nline = $("input[name=nline]:checked").val();235 port = 8080;236 if (lang == 1){237 port = 8081;238 }239 var model = "0";240 var topic = $('#input-topic').val();241 topic = topic.replace(/ /g, "_");242 if (topic == ""){243 if (lang == 0){244 topic = "civil_war";245 } else {246 topic = "guerra_civil";247 }248 }249 id = Math.round(Math.random()*10000) + 1250 gmodel = model;251 gtopic = topic;252 //style253 var encourage_words = $('input[name=encourage_words]').val();254 var disencourage_words = $('input[name=disencourage_words]').val();255 var enc_weight = $('input[name=enc_weight]').val();256 var cword = $('input[name=cword_weight]').val();257 var reps = $('input[name=reps_weight]').val();258 var allit = $('input[name=allit_weight]').val();259 var wordlen = $('input[name=wordlen_weight]').val();260 var topical = $('input[name=topical_weight]').val();261 var mono = $('input[name=mono_weight]').val();262 var sentiment = $('input[name=sentiment_weight]').val();263 var concrete = $('input[name=concrete_weight]').val();264 var is_default = is_default_setting();265 var source = "experiment";266 eng_data = {267 topic:topic,268 k:1,269 model:model,270 id:id,271 nline:nline,272 encourage_words:encourage_words,273 disencourage_words:disencourage_words,274 enc_weight:enc_weight,275 cword:cword,276 reps:reps,277 allit:allit,278 wordlen:wordlen,279 topical:topical,280 mono:mono,281 sentiment:sentiment,282 concrete:concrete,283 is_default:is_default,284 source:source285 };286 spa_data = {287 topic:topic,288 k:1,289 model:model,290 id:id,291 nline:nline,292 };293 data = eng_data;294 if (lang ==1 ) // spanish295 {296 data = spa_data;297 }298 left_time = 6;299 if (lang == 1){300 left_time = 60;301 } else {302 if (nline == "2"){303 left_time = 1;304 } else if (nline == "4") {305 left_time = 2;306 }307 }308 estimation = ""309 var timer = setInterval( function() {310 estimation = "["+left_time + "s] "311 $.ajax(312 {313 url : "http://"+api_host+":"+port+"/api/poem_status",314 data: {id:id},315 type:"GET",316 xhrFields:{withCredentials:false},317 success: function (response_data) {318 left_time = left_time - 1319 $("#status").html(estimation + response_data);320 }321 }322 );323 },1000)324 $.ajax({325 url: "http://"+api_host+":"+port+"/api/poem_check",326 data: data,327 type:"GET",328 xhrFields: {329 // The 'xhrFields' property sets additional fields on the XMLHttpRequest.330 // This can be used to set the 'withCredentials' property.331 // Set the value to 'true' if you'd like to pass cookies to the server.332 // If this is enabled, your server must respond with the header333 // 'Access-Control-Allow-Credentials: true'.334 withCredentials: false335 },336 success: function(response_data) {337 previous_id = id;338 previous_nline = nline;339 previous_lang = lang;340 $("#adjust-button").prop('disabled',false);341 jd = $.parseJSON(response_data);342 $("#npoem").html(jd.n_poem);343 $("#poem_id").html(jd.poem_id);344 $("#poem_id_show").html(jd.poem_id);345 n_regen = 0;346 ticket = 0;347 $("#regen_time").html(n_regen);348 $("#exp_ticket").html("");349 scored = 0;350 poem_history = {};351 $("#poem").html(jd.poem);352 $("#npoem_alexa").html(jd.n_poem_alexa);353 $("#config").html(jd.config);354 $("#rhyme-info").html(jd.rhyme_info);355 $("#rhyme-words").html(jd.rhyme_words);356 $("#exact-rhyme-candidates").html(jd.exact_rhyme_candidates);357 $("#pc").html(jd.pc);358 $("#status").html("Ready");359 init_star();360 }361 }).always(function (){362 btn.button('reset');363 clearInterval(timer);364 });365});366onselect_language(1);...
description.js
Source:description.js
1import React, { Component } from 'react';2import VisibilitySensor from 'react-visibility-sensor';3import TranslatableLabel from '../translatable_label/translatable_label';4import { description_text } from './description_texts';5import { connect } from 'react-redux';6import change_visibility from '../../redux/actions/change_description_visibility';7import './description.css';8const pensativo_on_img = require('./imgs/pensativo_on.png');9const pensativo_off_img = require('./imgs/pensativo_off.png');10class Description extends Component {11 state = {}12 constructor(props) {13 super(props);14 this.state = {15 description_texts_object: {16 spa: "", eng: "", ger: ""17 }18 }19 this.previous_lang = props.lang;20 this.first_time_render = true;21 console.log(props);22 if (props.is_visible) {23 this.description_texts_object = description_text;24 this.state.description_texts_object = description_text;25 } else {26 this.description_texts_object = {27 spa: "", eng: "", ger: ""28 }29 this.state.description_texts_object = {30 spa: "", eng: "", ger: ""31 }32 }33 }34 handle_visibility_change(is_visible) {35 console.log("is_visible:", is_visible);36 if (is_visible) {37 this.description_texts_object = description_text;38 this.props.show();39 document.getElementById('pensativo-on').classList.add('on');40 // this.setState({41 // description_texts_object: description_text42 // });43 } else {44 document.getElementById('pensativo-on').classList.remove('on');45 }46 }47 componentDidMount() {48 // console.log("on mount");49 }50 componentDidUpdate(prevProps, prevState) {51 console.log("updating description");52 }53 render() {54 var is_typed = true;55 if (this.props.lang == this.previous_lang) {56 is_typed = false;57 console.log("setting is_typed to false ", this.props.lang, this.previous_lang);58 } else {59 // alert("lang changed"); 60 this.previous_lang = this.props.lang;61 }62 return (63 <VisibilitySensor64 onChange={this.handle_visibility_change.bind(this)}65 >66 <div>67 <div id="description-photo-container" className="show-on-bulb-on">68 <img className="description-photo" id="pensativo-off" src={pensativo_off_img}></img>69 <img className="description-photo" id="pensativo-on" src={pensativo_on_img}></img>70 </div>71 <h3>72 <TranslatableLabel is_typed={false} spa="¿Quién Soy?" eng="Who am I?" ger="Wer bin Ich?"></TranslatableLabel>73 </h3>74 <div ref="description">75 <TranslatableLabel76 type_speed={30}77 start_delay={1000}78 is_typed={is_typed}79 spa={this.description_texts_object.spa}80 eng={this.description_texts_object.eng}81 ger={this.description_texts_object.ger}>82 </TranslatableLabel>83 </div>84 </div>85 </VisibilitySensor>86 );87 }88}89const mapStateToProps = (state) => ({90 is_visible: state.globals_reducer.is_description_visible,91 lang: state.globals_reducer.language92})93const mapDispatchToProps = (dispatch) => (94 {95 hide: () => {96 alert("visible");97 dispatch(change_visibility(false));98 },99 show: () => { dispatch(change_visibility(true)); }100 });...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6MIT © [Sandeep Kumar](
Using AI Code Generation
1var editor = CKEDITOR.instances['editor1'];2editor.execCommand('previous_lang');3CKEDITOR.plugins.add('wptextpattern', {4 init: function(editor) {5 editor.addCommand('next_lang', {6 exec: function(editor) {7 var lang = editor.config.language;8 if (lang == 'en-us') {9 lang = 'zh-cn';10 } else {11 lang = 'en-us';12 }13 editor.config.language = lang;14 editor.destroy();15 CKEDITOR.replace('editor1');16 }17 });18 editor.addCommand('previous_lang', {19 exec: function(editor) {20 var lang = editor.config.language;21 if (lang == 'en-us') {22 lang = 'zh-cn';23 } else {24 lang = 'en-us';25 }26 editor.config.language = lang;27 editor.destroy();28 CKEDITOR.replace('editor1');29 }30 });31 editor.ui.addButton('NextLang', {32 });33 editor.ui.addButton('PreviousLang', {34 });35 }36});
Using AI Code Generation
1var wptoolkit = require('./wptoolkit');2var lang = wptoolkit.previous_lang("en");3console.log(lang);4var wptoolkit = require('./wptoolkit');5var lang = wptoolkit.next_lang("es");6console.log(lang);7var wptoolkit = require('./wptoolkit');8var langs = wptoolkit.get_langs();9console.log(langs);10var wptoolkit = require('./wptoolkit');11var langs = wptoolkit.get_langs();12console.log(langs);13var wptoolkit = require('./wptoolkit');14var langs = wptoolkit.get_langs();15console.log(langs);16var wptoolkit = require('./wptoolkit');17var langs = wptoolkit.get_langs();18console.log(langs);19var wptoolkit = require('./wptoolkit');20var langs = wptoolkit.get_langs();21console.log(langs);22var wptoolkit = require('./wptoolkit');23var langs = wptoolkit.get_langs();24console.log(langs);25var wptoolkit = require('./wptoolkit');26var langs = wptoolkit.get_langs();27console.log(langs);
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5 if (err) {6 console.log(err);7 return;8 }9 var testId = data.data.testId;10 wpt.getTestResults(testId, function(err, data) {11 if (err) {12 console.log(err);13 return;14 }15 var lang = data.data.median.firstView.I18N;16 wpt.previousLang(lang, function(err, data) {17 if (err) {18 console.log(err);19 return;20 }21 console.log(data);22 });23 });24});
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!!