How to use noError method in wpt

Best JavaScript code snippet using wpt

pw_register.js

Source:pw_register.js Github

copy

Full Screen

1var extracheck = [];2function Element(evtobj,info,infobox,relObj,required){3 this.o = evtobj;4 this.m = info;5 this.i = infobox;6 if(relObj) this.r = relObj;7 if(required) this.d = required;8}9var ajaxclearhistory=false; //fixed for tt browser10var regGdTimer;11/*12 * initialize the inputs13 */14(function (){15 var e = document.getElementsByTagName("input");16 for (var i=0;i<e.length;i++) {17 if (typeof(e[i].onfocus) == 'function') continue;18 if(e[i].name == 'authmobile' || e[i].name == 'authverify') continue;19 if (e[i].type == 'text' || e[i].type == 'password' || e[i].type == 'email') {20 e[i].noerror = 0;21 e[i].onfocus = onFocus;22 e[i].onblur = onBlur;23 } else if (e[i].type == 'checkbox' && e[i].id != 'registerclause') {24 e[i].onclick = clickCheckbox;25 } else if (e[i].type == 'radio') {26 e[i].onclick = clickRadio;27 }28 }29 var textareaElement = document.getElementsByTagName("textarea");30 for (var j=0;j<textareaElement.length;j++) {31 textareaElement[j].noerror = 0;32 textareaElement[j].onfocus = onFocus;33 textareaElement[j].onblur = onBlur;34 }35 onReady(function(){36 for(var z=0;z<extracheck.length;z++){37 extracheck[z].onclick = changeArea;38 }39 });40})();41/*fix lh*/42function onFocus(event){43 var obj;44 if (is_ie){45 obj = window.event.srcElement;46 } else {47 obj = event.target;48 }49 if (obj.id == 'gdcode') showgd('menu_gd');50 if (getInfoBox(obj)) {51 var lastid = eval(obj.id).m.length - 1;52 if(eval(obj.id).m[lastid] == '') {53 getInfoBox(obj).style.display = 'none';54 return;55 }56 getInfoBox(obj).innerHTML = eval(obj.id).m[lastid];57 getInfoBox(obj).className = inticlass;58 }59}60function onBlur(evnt){61 var obj;62 if (is_ie) {63 obj = event.srcElement;64 } else {65 obj = evnt.target;66 }67 if (obj.id == 'invcode') {68 setTimeout(function(){analyseData(obj);}, 100);69 } else if(obj.id == 'gdcode') {70 regGdTimer = setTimeout(function(){analyseData(obj);}, 500);71 } else {72 analyseData(obj);73 }74}75function changeArea(obj) {76 if (typeof(obj) != 'undefined') {77 analyseData(obj);78 }79}80function clickCheckbox(event) {81 var obj;82 if (is_ie){83 obj = window.event.srcElement;84 } else {85 obj = event.target;86 }87 var name = obj.name.replace('[]','');88 checkCheckbox(name);89}90function clickRadio(event) {91 var obj;92 if (is_ie){93 obj = window.event.srcElement;94 } else {95 obj = event.target;96 }97 checkRadio(obj.name);98}99var ajaxCheckArray = new Array();100function checkAll(e){101 var e = window.event || e;102 if(e.preventDefault){e.preventDefault();}else{e.returnValue = false;}103 var result = 1;104 //校验input105 var e = document.getElementsByTagName("input");106 for(var i=0;i<e.length;i++){107 if(e[i].id == 'authmobile' && !/^1\d{10}$/.test(e[i].value) && getObj('mobileBox').style.display != 'none'){108 getObj('mobileauth_info').innerHTML = authInfo[1];109 getObj('mobileauth_info').style.display = '';110 e[i].onfocus = function(){getObj('mobileauth_info').style.display = 'none';}111 }else if(e[i].id == 'authverify' && e[i].value =='' && getObj('verifyBox').style.display != 'none'){112 getObj('authTips').className = 'wrong';113 getObj('authTips').innerHTML = authInfo[7];114 getObj('authTips').style.display = '';115 e[i].onfocus = function(){getObj('authTips').style.display = 'none';}116 }117 if (e[i].id != 'pwuser' && e[i].id != 'customquest_l' && e[i].id != 'keyword') {118 if(e[i].type == 'text' && e[i].id != 'regpwd' && e[i].id != 'regpwdrepeat' && e[i].id != 'registerclause'){119 try{120 eval(e[i].id);121 }catch(err) {122 continue;123 }124 if(e[i].id && Element.prototype.isPrototypeOf(eval(e[i].id))){125 var tmpresult = analyseData(e[i],true);126 if (typeof (tmpresult) != 'undefined' ) {127 result &= tmpresult;128 }129 }130 }131 }132 }133 134 //校验textarea135 var textareaElement = document.getElementsByTagName("textarea");136 for (var j=0;j<textareaElement.length;j++) {137 try{138 eval(textareaElement[j].id);139 }catch(err) {140 continue;141 }142 if(textareaElement[j].id && Element.prototype.isPrototypeOf(eval(textareaElement[j].id))){143 var textarearesult = analyseData(textareaElement[j],true);144 if (typeof (textarearesult) != 'undefined' ) {145 result &= textarearesult;146 }147 }148 }149 150 //校验地区151 for(var i=0;i<extracheck.length;i++){152 var extraresult = analyseData(extracheck[i],true);153 if (typeof (extraresult) != 'undefined' ) {154 result &= extraresult;155 }156 }157 158 ajaxCheck(result);159}160function ajaxCheck(result) {161 var postData = '[';162 for(var i in ajaxCheckArray) {163 if (ajaxCheckArray[i].noerror) continue;164 postData += '["' + i +'","' + ajaxCheckArray[i].type + '","' + ajaxCheckArray[i].value + '"],';165 }166 postData = postData.replace(/,$/,'');167 postData += ']';168 if (postData == '[]') {169 var otherCheck;170 otherCheck = checkWithoutAjax();171 otherCheck &= result;172 if (otherCheck == 1) {173 document.register.submit();174 return true;175 }176 } else {177 var url = getRegAjaxCheckUrl();178 var data = "action=regcheck&type=all&data=" + postData;179 read.guide();180 ajax.send(url,data,function() {181 var response = ajax.request.responseText;182 if (response == 'success') {183 var otherResult;184 otherResult = checkWithoutAjax();185 otherResult &= result;186 if (otherResult == 1) {187 document.register.submit();188 }189 } else {190 response = JSONParse(response);191 for (var i in response) {192 //analyseData(getObj(i),false);193 showResult(response[i],getObj(i));194 }195 checkWithoutAjax();196 }197 read.close();198 });199 }200}201function checkWithoutAjax() {202 var tempResult = 1;203 204 //校验不需要ajax的非自定义字段205 if (getObj('regpwd')) {206 var pwdResult = checkPwd(getObj('regpwd'));207 showResult(pwdResult, getObj('regpwd'));208 pwdResult = pwdResult > 0 ? 0 : 1;209 tempResult &= pwdResult;210 }211 if (getObj('regpwdrepeat')) {212 var pwdrpResult = checkPwdRepeat(getObj('regpwdrepeat'));213 showResult(pwdrpResult, getObj('regpwdrepeat'));214 pwdrpResult = pwdrpResult > 0 ? 0 : 1;215 tempResult &= pwdrpResult;216 }217 if (getObj('registerclause')) {218 var clauseResult = checkRegisterClause(getObj('registerclause'));219 showResult(clauseResult, getObj('registerclause'));220 clauseResult = clauseResult > 0 ? 0 : 1;221 tempResult &= clauseResult;222 }223 224 //校验checkbox225 for(var j=0;j<checkboxArray.length;j++) {226 var checkResult = checkCheckbox(checkboxArray[j]);227 if(typeof(checkResult) != 'undefined'){228 tempResult &= checkResult;229 }230 }231 //校验radio232 for (var i=0;i<radioArray.length;i++) {233 var radioResult = checkRadio(radioArray[i]);234 if(typeof(radioResult) != 'undefined'){235 tempResult &= radioResult;236 }237 }238 return tempResult;239}240function analyseData(obj,isSubmit,isAsyc,asyc){241 if(isAsyc){242 return showResult(asyc,obj);243 }else{244 if(!isSubmit){245 if (getInfoBox(obj)) {246 getInfoBox(obj).className = inticlass;247 }248 //if(!obj.value) return null;249 }250 if(obj.id){251 var type = obj.id;252 var result = -1;253 switch(type){254 case "regname":255 result = checkRegName(obj,isSubmit);256 break;257 case "regemail":258 result = checkEmail(obj,isSubmit);259 break;260 case "regpwd":261 result = checkPwd(obj);262 break;263 case "regpwdrepeat":264 result = checkPwdRepeat(obj);265 break;266 case "qanswer":267 result = checkAnswer(obj,isSubmit);268 break;269 case "gdcode":270 result = checkGDCode(obj,isSubmit);271 break;272 case "invcode":273 result = checkInvcode(obj,isSubmit);274 break;275 case "registerclause":276 result = checkRegisterClause(obj);277 break;278 default:279 result = checkField(obj,isSubmit);280 if (isSubmit) return result;281 break;282 }283 return showResult(result,obj);284 }285 }286}287function getRegAjaxCheckUrl() {288 //NEED GLOBAL VAR: regAjaxCheckUrl289 if (typeof(regAjaxCheckUrl) == "undefined" || '' == regAjaxCheckUrl) {290 return location.href;291 }292 return regAjaxCheckUrl;293}294function getInfoBox(obj){295 if (typeof(obj) == 'object') {296 if(obj.id){297 try {298 if (typeof(eval(obj.id)) != 'object') return;299 } catch(err) {300 return;301 }302 if(eval(obj.id).i && getObj(eval(obj.id).i)) {303 return getObj(eval(obj.id).i);304 } else {305 return;306 }307 }308 } else {309 if(eval(obj).i && getObj(eval(obj).i)) {310 return getObj(eval(obj).i);311 } else {312 return;313 }314 }315 return;316}317/*318 * result:0 true ,1 false319 */320function showResult(result,obj){321 if(obj){322 result = parseInt(result);323 if(result > 0){324 getInfoBox(obj).className = falseclass;325 getInfoBox(obj).style.display = '';326 getInfoBox(obj).innerHTML = typeof(obj) == 'object' ? eval(obj.id).m[result] : eval(obj).m[result];327 if (obj.id == 'gdcode') changeAllKindsGdCode('sitegdcheck', getObj('menu_gd'));328 return false;329 }330 if(result == 0 ){331 getInfoBox(obj).innerHTML = typeof(obj) == 'object' ? eval(obj.id).m[result] : eval(obj).m[result];332 if (obj.id == 'invcode' && getObj('buy_invitecode')) getObj('buy_invitecode').style.display = 'none';333 getInfoBox(obj).className = rightclass;334 getInfoBox(obj).style.display = '';335 if (obj.id == 'gdcode' && typeof(obj.onblur) == 'function') {336 obj.readOnly = true;337 obj.onblur = obj.onfocus = null;338 removeGdcodeClickEvt(getObj('menu_gd')); 339 }340 return true;341 }342 }343}344function checkRegName(obj,isSubmit){345 var username = obj.value;346 if (isSubmit == true) {347 ajaxCheckArray[obj.id] = {'noerror':obj.noerror,'type':'regname','value':obj.value};348 return;349 }350 if(username == ""){351 obj.noerror = 0;352 return 5;353 }354 if(strlen(username)<retminname || strlen(username)>regmaxname){355 obj.noerror = 0;356 return 1;357 }358 var url = getRegAjaxCheckUrl();359 var data = "action=regcheck&type=regname&username="+username;360 getInfoBox(obj).innerHTML = "&nbsp;检测中,请稍等...";361 ajax.send(url,data,function(){362 var response = parseInt(ajax.request.responseText);363 switch (response){364 case 0:365 obj.noerror = 1;366 return showResult(0,obj);367 break;368 case 1:369 obj.noerror = 0;370 return showResult(1,obj);371 break;372 case 2:373 obj.noerror = 0;374 return showResult(2,obj);375 break;376 case 3:377 obj.noerror = 0;378 return showResult(3,obj);379 break;380 case 4:381 obj.noerror = 0;382 return showResult(4,obj);383 break;384 default:385 obj.noerror = 0;386 return showResult(1,obj);387 }388 });389}390function checkEmail(obj,isSubmit){391 var email = obj.value;392 if (isSubmit == true) {393 ajaxCheckArray[obj.id] = {'noerror':obj.noerror,'type':'regemail','value':obj.value};394 return;395 }396 var myReg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;397 if(!myReg.test(email)){398 obj.noerror = 0;399 return 1;400 } else{401 var url = getRegAjaxCheckUrl();402 var data = "action=regcheck&type=regemail&email="+email;403 getInfoBox(obj).innerHTML = "&nbsp;检测中,请稍等...";404 ajax.send(url,data,function(){405 var response = parseInt(ajax.request.responseText);406 switch (response){407 case 0:408 obj.noerror = 1;409 return showResult(0,obj);410 break;411 case 1:412 obj.noerror = 0;413 return showResult(1,obj);414 break;415 case 2:416 obj.noerror = 0;417 return showResult(2,obj);418 break;419 case 4:420 obj.noerror = 0;421 return showResult(4,obj);422 break;423 case 5:424 obj.noerror = 0;425 return showResult(5,obj);426 break;427 default:428 obj.noerror = 0;429 return showResult(1,obj);430 }431 });432 }433}434function checkPwd(obj){435 var pwd = obj.value;436 if(pwd.length<regminpwd){437 obj.noerror = 0;438 return 5;439 }else if(regmaxpwd>0 && pwd.length>regmaxpwd) {440 obj.noerror = 0;441 return 6;442 }else if(regnpdifferf>0 && getObj('regname').value==pwd) {443 obj.noerror = 0;444 return 7;445 }446 if(/[\\\/\&\'\"\*\,\.\.<>#\?%!。 ]/.test(pwd)){447 obj.noerror = 0;448 return 8;449 }450 var rule = pwdcomplex.split(',');451 var pwdReg;452 for(var i=0;i<rule.length;i++){453 switch(Number(rule[i])){454 case 1:455 pwdReg = /[a-z]/;456 if(!pwdReg.test(pwd)) {457 obj.noerror = 0;458 return 1;459 }460 break;461 case 2:462 pwdReg = /[A-Z]/;463 if(!pwdReg.test(pwd)) {464 obj.noerror = 0;465 return 2;466 }467 break;468 case 3:469 pwdReg = /[0-9]/;470 if(!pwdReg.test(pwd)) {471 obj.noerror = 0;472 return 3;473 }474 break;475 case 4:476 pwdReg = /[^a-zA-Z0-9]/;477 if(!pwdReg.test(pwd)) {478 obj.noerror = 0;479 return 4;480 }481 break;482 default:483 continue;484 break;485 }486 }487 var pwdRepeat = getObj('regpwdrepeat');488 if(pwdRepeat.value && checkPwdRepeat(pwdRepeat)){489 getInfoBox(pwdRepeat).className = falseclass;490 getInfoBox(pwdRepeat).innerHTML = eval(pwdRepeat.id).m[1];491 }492 obj.noerror = 1;493 return 0;494}495function checkPwdRepeat(obj){496 if (obj.value==getObj('regpwd').value && obj.value.length > 0) {497 obj.noerror = 1;498 return 0;499 } else {500 obj.noerror = 0;501 return 1;502 }503}504function checkGDCode(obj,isSubmit){505 var gdcode = obj.value;506 if (isSubmit == true) {507 if (regGdTimer) {508 clearTimeout(regGdTimer);509 }510 var tmpValue = encodeURIComponent(obj.value);511 ajaxCheckArray[obj.id] = {'noerror':obj.noerror,'type':'reggdcode','value':tmpValue};512 return;513 }514 if(gdcode==""){515 obj.noerror = 0;516 return 3;517 }else{518 var url = getRegAjaxCheckUrl();519 var data = "action=regcheck&type=reggdcode&gdcode="+encodeURIComponent(gdcode);520 getInfoBox(obj).innerHTML = "&nbsp;检测中,请稍等...";521 ajax.send(url,data,function(){522 var response = parseInt(ajax.request.responseText);523 switch (response){524 case 0:525 obj.noerror = 1;526 return showResult(0,obj);527 break;528 case 1:529 obj.noerror = 0;530 return showResult(1,obj);531 break;532 default:533 obj.noerror = 0;534 return showResult(1,obj);535 }536 });537 }538}539function removeGdcodeClickEvt(obj) {540 var elements = obj.getElementsByTagName("*");541 for (var i = 0, j = elements.length; i < j; i++) {542 if (typeof elements[i].onclick == 'function') elements[i].onclick = null;543 }544 return true;545}546function checkAnswer(obj,isSubmit){547 var question= parseInt(getObj('regqkey').value);548 var answer = obj.value;549 if (isSubmit == true) {550 ajaxCheckArray[obj.id] = {'noerror':obj.noerror,'type':'regcheck','value':question + '|' + answer};551 return;552 }553 if(answer==""){554 return 2;555 }else{556 var url = getRegAjaxCheckUrl();557 var data = "action=regcheck&type=qanswer&answer="+answer+"&question="+question;558 getInfoBox(obj).innerHTML = "&nbsp;检测中,请稍等...";559 ajax.send(url,data,function(){560 var response = parseInt(ajax.request.responseText);561 if(response > 0){562 obj.noerror = 0;563 try{regInfo[5][2] = regInfo[5][2].replace(/t=\d+/,'t='+new Date().getTime()); }catch(e){alert(e);}564 showResult(response,obj);565 }else{566 obj.noerror = 1;567 return showResult(0,obj);568 }569 });570 }571}572function checkInvcode(obj,isSubmit){573 var invcode = obj.value;574 if (isSubmit == true) {575 ajaxCheckArray[obj.id] = {'noerror':obj.noerror,'type':'invcode','value':invcode};576 return;577 }578 if(invcode){579 var url = getRegAjaxCheckUrl();580 var data = "action=regcheck&type=invcode&invcode="+invcode;581 getInfoBox(obj).innerHTML = "&nbsp;检测中,请稍等...";582 ajax.send(url,data,function(){583 var response = parseInt(ajax.request.responseText);584 switch (response){585 case 0:586 obj.noerror = 1;587 return showResult(0,obj);588 break;589 case 1:590 obj.noerror = 0;591 return showResult(1,obj);592 break;593 case 2:594 obj.noerror = 0;595 return showResult(2,obj);596 break;597 default:598 obj.noerror = 0;599 return showResult(2,obj);600 }601 });602 }else{603 obj.noerror = 0;604 return 1;605 }606}607function checkRegisterClause(obj){608 if(obj.checked == false) {609 obj.noerror = 0;610 return 1;611 } else {612 obj.noerror = 1;613 return 0;614 }615}616function checkField(obj,isSubmit){617 var field = obj.value;618 if (typeof(obj.id) != 'undefined' && obj.id == 'answered') {619 var safeQuestion = getObj('safequestion').value;620 if (safeQuestion > 0 && field == '') {621 obj.noerror = 0;622 showResult(1,obj);623 return isSubmit ? 0 : 1;624 } else {625 obj.noerror = 1;626 showResult(0,obj);627 return isSubmit ? 1 : 0;628 }629 }630 var isAreaType = obj.tagName == 'SELECT' && /^area_/.test(obj.id);631 if (isSubmit == true) {632 if (typeof(obj.id) == 'undefined') obj.id = obj.name.replace('[]','');633 if ((!isAreaType && field != '') || (isAreaType && field > 0)) {634 //field = field.replace(/&/g,'%26');635 //field = field.replace(/"/g,'%22');636 field = escape(field);637 ajaxCheckArray[obj.id] = {'noerror':obj.noerror,'type':'customerfield','value':obj.name.replace('[]','') + '|' + field};638 } else {639 if (eval(obj.id).d == 1) {640 obj.noerror = 0;641 showResult(1,obj);642 return 0;643 } else {644 obj.noerror = 1;645 showResult(0,obj);646 return 1;647 }648 }649 return;650 }651 var isCompanyType = obj.tagName == 'INPUT' && /^companyname_/.test(obj.id);652 if(field=="" || (isAreaType && field == -1)){653 var elementName;654 if(isAreaType || isCompanyType){655 var el = eval(obj.id);656 } else {657 var el = eval(obj.name);658 }659 if(el.d == 1) {660 obj.noerror = 0;661 showResult(1,obj);662 return 1;663 } else {664 obj.noerror = 1;665 showResult(1,obj);666 return false;667 }668 }else{669 var regx = /^(schoolname|companyname)/i;670 if (regx.test(obj.name) || isAreaType || isCompanyType) {671 obj.noerror = 1;672 showResult(0,obj);673 return 0;674 }675 var url = getRegAjaxCheckUrl();676 field = field.replace(/&/g,'%26');677 var data = "action=regcheck&type=customerfield&fieldname="+obj.name+"&value="+field;678 getInfoBox(obj).innerHTML = "&nbsp;检测中,请稍等...";679 getInfoBox(obj).style.display = '';680 ajax.send(url,data,function(){681 result = parseInt(ajax.request.responseText);682 if (result == 0) {683 obj.noerror = 1;684 } else {685 obj.noerror = 0;686 }687 showResult(result,obj);688 });689 }690}691function checkCheckbox(name) {692 var obj = eval(name);693 if (obj.d == 1) {694 var allElements = document.getElementsByName(name + '[]');695 var isChecked = 0;696 for (var i=0;i<allElements.length;i++) {697 if (allElements[i].checked == true) isChecked = 1;698 }699 var result = isChecked > 0 ? 0 : 1;700 showResult(result, name);701 return isChecked;702 } else {703 showResult(0, name);704 return 1;705 }706}707function checkRadio(name) {708 var obj = eval(name);709 if (obj.d == 1) {710 var allElements = document.getElementsByName(name);711 var isChecked = 0;712 for (var i=0;i<allElements.length;i++) {713 if (allElements[i].checked == true) isChecked = 1;714 }715 var result = isChecked > 0 ? 0 : 1;716 showResult(result, name);717 return isChecked;718 } else {719 showResult(0, name);720 return 1;721 }722}723function strlen(str){724 var len = 0;725 var s_len = str.length = (is_ie && str.indexOf('\n')!=-1) ? str.replace(/\r?\n/g, '_').length : str.length;726 var c_len = charset == 'utf-8' ? 3 : 2;727 for(var i=0;i<s_len;i++){728 len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? c_len : 1;729 }730 return len;...

Full Screen

Full Screen

video.js

Source:video.js Github

copy

Full Screen

1import { CHANNEL_VIDEO_FAILED, CHANNEL_VIDEO_REQUEST, CHANNEL_VIDEO_SUCCESS, LIKE_VIDEOS_FAILED, LIKE_VIDEOS_REQUEST, LIKE_VIDEOS_SUCCESS, RECOMMENDED_VIDEO_FAILED, RECOMMENDED_VIDEO_REQUEST, RECOMMENDED_VIDEO_SUCCESS, VIDEOS_FAILED, VIDEOS_REQUEST, VIDEOS_SUCCESS, VIDEO_SELECTED_FAILED, VIDEO_SELECTED_REQUEST, VIDEO_SELECTED_SUCCESS } from "../videoActions.js";2export const videoReducer=(3 prevState={4 videos:[],5 loading:false,6 nextPageToken:null,7 category:'All',8 error:'',9 noError:true10 },action)=>{11 const {type,payload}=action;12 switch(type){13 case VIDEOS_FAILED:14 return{15 ...prevState,16 loading:false,17 error:payload,18 noError:false19 }20 case VIDEOS_SUCCESS:21 return{22 ...prevState,23 videos:prevState.category===payload.category?[...prevState.videos,...payload.videos]:payload.videos,24 loading:false,25 nextPageToken:payload.nextPageToken,26 category:payload.category,27 error:'',28 noError:true29 }30 case VIDEOS_REQUEST:31 return{32 ...prevState,33 loading:true,34 error:'',35 noError:true36 }37 case 'RESET_STATE':38 return{39 videos:[],40 loading:false,41 nextPageToken:null,42 category:'All',43 error:'',44 noError:true45 }46 default:47 return prevState;48 }49}50export const _metaReducer=(51 prevState={52 _meta:[],53 commentCount:null,54 loading:false,55 id:null,56 error:'',57 noError:true58 },action)=>{59 const {type,payload}=action;60 switch(type){61 case VIDEO_SELECTED_REQUEST:62 return {63 ...prevState,64 loading:true,65 _meta:payload.id===prevState.id?prevState._meta:[],66 commentCount:payload.id===prevState.id?prevState.commentCount:null,67 error:'',68 noError:true69 }70 case VIDEO_SELECTED_SUCCESS:71 return{72 ...prevState,73 _meta:payload.meta_,74 commentCount:payload.meta_.statistics.commentCount,75 loading:false,76 error:'',77 noError:true78 }79 case VIDEO_SELECTED_FAILED:80 return{81 ...prevState,82 loading:false,83 error:payload,84 noError:false85 }86 default:87 return prevState88 }89}90export const recommendationReducer=(91 prevState={92 Recommend:[],93 loading:false,94 videoId:null,95 error:'',96 noError:true97 },action) =>{98 const {type,payload}=action;99 switch(type){100 case RECOMMENDED_VIDEO_FAILED:101 return {102 ...prevState,103 loading:false,104 error:payload,105 noError:false106 }107 case RECOMMENDED_VIDEO_REQUEST:108 return {109 ...prevState,110 Recommend:payload.videoId===prevState.videoId?prevState.Recommend:[],111 loading:true,112 videoId:payload.videoId,113 error:'',114 noError:true115 }116 case RECOMMENDED_VIDEO_SUCCESS:117 return{118 ...prevState,119 Recommend:[...prevState.Recommend,...payload.Recommend],120 loading:false,121 error:'',122 noError:true123 }124 default:125 return prevState126 }127}128export const likeVideoReducer=(129 prevState={130 videos:[],131 loading:false,132 nextPageToken:null,133 totalResults:-1,134 error:'',135 noError:true136 },action)=>{137 const {type,payload}=action;138 switch(type){139 case LIKE_VIDEOS_REQUEST:140 return {141 ...prevState,142 loading:true,143 error:'',144 noError:true145 }146 case LIKE_VIDEOS_SUCCESS:147 return{148 ...prevState,149 videos:[...prevState.videos,...payload.videos],150 nextPageToken:payload.nextPageToken,151 totalResults:payload.totalResults,152 loading:false,153 error:'',154 noError:true155 }156 case LIKE_VIDEOS_FAILED:157 return{158 ...prevState,159 error:payload,160 noError:false161 }162 case 'RESET_LIKE_STATE':163 return {164 ...prevState,165 videos:[],166 loading:false,167 nextPageToken:null,168 totalResults:-1,169 error:'',170 noError:true171 }172 default:173 return prevState174 }175}176export const channelVideoReducer=(177 prevState={178 videos:[],179 loading:false,180 error:'',181 noError:true,182 nextPageToken:null,183 channelId:null184 },action)=>{185 const {type,payload}=action;186 switch(type){187 case CHANNEL_VIDEO_REQUEST:188 return {189 ...prevState,190 loading:true,191 error:'',192 noError:true193 }194 case CHANNEL_VIDEO_SUCCESS:195 return{196 ...prevState,197 videos:[...prevState.videos,...payload.videos],198 nextPageToken:payload.nextPageToken,199 loading:false,200 error:'',201 noError:true202 }203 case CHANNEL_VIDEO_FAILED:204 return{205 ...prevState,206 error:payload,207 noError:false208 }209 case 'RESET_CHANNEL_VIDEO_STATE':210 return {211 ...prevState,212 videos:[],213 loading:false,214 nextPageToken:null,215 error:'',216 noError:true217 }218 default:219 return prevState220 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var page = require('webpage').create(),2 system = require('system'),3 t, address;4if (system.args.length === 1) {5 console.log('Usage: test.js <some URL>');6 phantom.exit(1);7} else {8 t = Date.now();9 address = system.args[1];10 page.open(address, function (status) {11 if (status !== 'success') {12 console.log('FAIL to load the address');13 } else {14 t = Date.now() - t;15 console.log('Loading time ' + t + ' msec');16 page.evaluate(function () {17 return wpt.noError();18 });19 }20 phantom.exit();21 });22}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) throw err;4 wpt.noError(data.data.testId, function(err, data) {5 if (err) throw err;6 console.log(data);7 });8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) throw err;12 wpt.getLocations(function(err, data) {13 if (err) throw err;14 console.log(data);15 });16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) throw err;20 wpt.getTesters(function(err, data) {21 if (err) throw err;22 console.log(data);23 });24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27 if (err) throw err;28 wpt.getTestStatus(data.data.testId, function(err, data) {29 if (err) throw err;30 console.log(data);31 });32});33var wpt = require('webpagetest');34var wpt = new WebPageTest('www.webpagetest.org');35 if (err) throw err;36 wpt.getTestResults(data.data.testId, function(err, data) {37 if (err) throw err;38 console.log(data);39 });40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 var testId = data.data.testId;7 test.noError(testId, function(err, data) {8 if (err) return console.error(err);9 console.log(data);10 });11});12### getLocations(callback)13var wpt = require('webpagetest');14var test = new wpt('www.webpagetest.org');15test.getLocations(function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19### getLocations(callback)20var wpt = require('webpagetest');21var test = new wpt('www.webpagetest.org');22test.getLocations(function(err, data) {23 if (err) return console.error(err);24 console.log(data);25});26### getTesters(callback)27var wpt = require('webpagetest');28var test = new wpt('www.webpagetest.org');29test.getTesters(function(err, data) {30 if (err) return console.error(err);31 console.log(data);32});33### getTesters(callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');3var options = {4};5wpt.runTest(url, options, function(err, data) {6 wpt.noError(err, data);7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'APIKEY');11var options = {12};13wpt.runTest(url, options, function(err, data) {14 wpt.noError(err, data);15 console.log(data);16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt')2var options = {3}4wpt.runTest(options, function(err, data) {5 if(err) {6 console.log(err);7 } else {8 wpt.noError(data, function(err, data) {9 if(err) {10 console.log(err);11 } else {12 console.log(data);13 }14 });15 }16});17var wpt = require('wpt')18var options = {19}20wpt.runTest(options, function(err, data) {21 if(err) {22 console.log(err);23 } else {24 wpt.getTestStatus(data.data.testId, function(err, data) {25 if(err) {26 console.log(err);27 } else {28 console.log(data);29 }30 });31 }32});33var wpt = require('wpt')34var options = {35}36wpt.runTest(options, function(err, data) {37 if(err) {38 console.log(err);39 } else {40 wpt.getTestResults(data.data.testId, function(err, data) {41 if(err) {42 console.log(err);43 } else {44 console.log(data);45 }46 });47 }48});49var wpt = require('wpt')50var options = {51}52wpt.runTest(options, function(err, data) {53 if(err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19wpt.getTestResults('160814_7T_2C3', function(err, data) {20 if (err) {21 console.log(err);22 } else {23 console.log(data);24 }25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28wpt.getLocations(function(err, data) {29 if (err) {30 console.log(err);31 } else {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3var options = {4};5client.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status: ' + data.statusText);8 console.log('Test ID: ' + data.data.testId);9 client.noError(data.data.testId, 'document.querySelector("#hplogo")', function(err, data) {10 if (err) return console.error(err);11 console.log('Element is visible');12 client.clickElement(data.data.testId, 'document.querySelector("#hplogo")', function(err, data) {13 if (err) return console.error(err);14 console.log('Element clicked');15 });16 });17});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful