Best Python code snippet using fMBT_python
mDialog.js
Source:mDialog.js  
1;(function (root, factory) {2	if (typeof define === 'function' && define.amd){3		define(['zepto', 'mHistory', 'popup'],factory);4	}else{5		factory(Zepto, root.mHistory);6	}7}(window, function($, mHistory) {8	$.showTip = function(msg) {9		var pop = $('#commonTipBox');10//                var y = window.scrollY;11//                window.scroll(0,y);12		if(pop.length > 0){13			pop.html(msg).css('display','block');14		}else{15			pop = $('<div id="commonTipBox" class="common-tip-shadow">'+msg+'</div>');16			$('body').append(pop);17		}18		$.popPosition(pop);19		setTimeout(function(){20			pop.css('display','none');21		},2000);22	}23	$.showWrapper = function(callback){24		var wrapper = $('#transWrapper');25		var _H = $(document).height();26		var winH = window.screen.height;27		//var winH = $(window).height();28		//alert(window.screen.height+','+window.screen.availHeight+','+$(window).height()+','+window.innerHeight+','+document.documentElement.clientHeight+','+document.body.clientHeight)29		if(_H < winH) _H = winH;30		if(!wrapper.length){31			wrapper = $('<div id="transWrapper" class="normal-pop-wrapper"></div>');32			$('body').append(wrapper);33		}else{34			wrapper.css('display','block');35		}36		wrapper.css('height',_H + 'px');37		wrapper.on('click',function(){38			$.hidePopUp();39			history.go(-1);40			if (callback && typeof callback == 'function'){ callback()}41		});42	}43	//åºé¨éæ©å表44	$.bottomSelect = function(){45		if(!arguments.length) return false;46		var obj = arguments[0];47		var til,btn,html = '',48			option = obj.option || '',49			val = obj.value || option,50			type = obj.type || 1,51			popClass = obj.popClass || '',52			pop = $('.common-bottom-popup');53		obj.title == 0 ? til = obj.title : til = obj.title || 'è¯·éæ©';54		obj.btn == 0 ? btn = obj.btn : btn = obj.btn || 'åæ¶';55		til == 0 ? html = '<ul>' : html = '<ul><li class="common-bottom-popup-title">'+til+'</li>';56		for(var i = 0;i < option.length;i++){57			html += '<li class="common-bottom-popup-option" data-value="'+ val[i] +'">' + option[i] + '</li>';58		}59		til == 0 ? html += '</ul>' : html += '</ul><div class="common-bottom-popup-cancel-btn">'+ btn +'</div>';60		if(pop.length > 0){61			pop.html(html).attr('id','bottomSelectListPop').addClass(popClass);62		}else{63			pop = $('<div id="bottomSelectListPop" class="common-bottom-popup '+ popClass +'">'+html+'</div>');64			$('body').append(pop);65		}66		$.showWrapper(obj.finish);67		pop.css('bottom','0');68		mHistory.addState({pop:1});69		history.pushState({pop:1},null,null);70		$('#bottomSelectListPop .common-bottom-popup-option').on('click',function(){71			var $this = $(this);72			var val = $this.attr('data-value'),73				option = $this.html();74			$.hidePopUp();75			history.go(-1);76			if(val === 'openAlbum'){77				if (typeof window.MomoBridge == 'object')  {78					MomoBridge.ready(function(BRG){79						BRG.invoke('readImage', {80							//id: 'imgPreview_0',81							id:$this.attr('_imgid'),82							method:1,83							type:'base64'84						},function(id,data,size,type){85							if(!data) return false;86							$('#'+id)[0].src="data:image/jpeg;base64,"+data;87							var src = $('#'+id)[0].src;88							if(window.setImageCallback) setImageCallback(id,src,data);89						})90					})91				} else {92					momo_btn_controller.controller_init_callback=function(){93						momo_btn_controller.readImage(JSON.stringify({94							//id: 'imgPreview_0',95							id:$this.attr('_imgid'),96							method:1,97							type:'base64'98						}));99					};100					momo_btn_controller.momo_btn_controller_init();101				}102			}else if(val === 'openCamera'){103				if (typeof window.MomoBridge == 'object')  {104					MomoBridge.ready(function(BRG){105						BRG.invoke('readImage', {106							//id: 'imgPreview_0',107							id:$this.attr('_imgid'),108							method:2,109							type:'base64'110						},function(id,data,size,type){111							if(!data) return false;112							$('#'+id)[0].src="data:image/jpeg;base64,"+data;113							var src = $('#'+id)[0].src;114							if(window.setImageCallback) setImageCallback(id,src,data);115						})116					})117				} else {118					momo_btn_controller.controller_init_callback=function(){119						momo_btn_controller.readImage(JSON.stringify({120							//id: 'imgPreview_0',121							id:$this.attr('_imgid'),122							method:2,123							type:'base64'124						}));125					};126					momo_btn_controller.momo_btn_controller_init();127				}128			} else {129				if(typeof obj.callback === 'function'){130					switch(type){131						case 1:132							obj.callback(val);133							break;134						case 2:135							obj.callback(option);136							break;137						case 3:138							obj.callback(val,option);139							break;140					}141				}142			}143			if(typeof obj.finish === 'function'){obj.finish();}144		})145		pop.find('.common-bottom-popup-cancel-btn').on('click',function(){146			$.hidePopUp();147			history.go(-1);148			if(typeof obj.cancel === 'function'){obj.cancel();}149		})150		return pop.find('.common-bottom-popup-option');151	}152	//ç±»confirmå¼¹çª153	$.confirm = function(){154		if(!arguments.length) return false;155		var obj = arguments[0];156		var b1 = obj.btn1 || 'åæ¶';157		var b2 = obj.btn2 || 'ç¡®å®';158		var tit = obj.title || 'æç¤º';159		var popClass = obj.popClass || '';160		var pop = $('.common-popup');161		var html = '<div class="title">'+tit+'</div><div class="content">'+obj.content+'</div>';162		html += '<div class="btns mt55 clearfix"><div class="panel-col-50"><a class="btn metrobtn btn1 confirm-btn-left">'+b1+'</a></div><div class="panel-col-50"><a class="btn metrobtn last btn2 confirm-btn-right" ">'+b2+'</a></div></div>';163		setTimeout(function(){164			if(pop.length > 0){165				pop.html(html).attr('id','confirmPop').css('display','block');166			}else{167				pop = $('<div id="confirmPop" class="common-popup '+ popClass +'">'+html+'</div>');168				$('body').append(pop);169			}170			$.showWrapper(obj.finish);171			$.popPosition(pop);172			console.log('add')173			console.log(mHistory.state)174			mHistory.addState({pop:1});175			history.pushState({pop:1},null,null);176			$('#confirmPop .confirm-btn-right').on('click',function(){177				var $this = $(this);178				history.go(-1);179				if(typeof obj.callback === 'function'){obj.callback.call($this);}180				if(typeof obj.success === 'function'){obj.success.call($this);}181				if(typeof obj.finish === 'function'){obj.finish();}182				$.hidePopUp();183			});184			$('#confirmPop .confirm-btn-left').on('click',function(){185				var $this = $(this);186				history.go(-1);187				if(typeof obj.callback2 === 'function'){obj.callback2.call($this);}188				if(typeof obj.fail === 'function'){obj.fail.call($this);}189				if(typeof obj.finish === 'function'){obj.finish();}190				$.hidePopUp();191			});192		},200)193	}194	//ç±»alertå¼¹çª195	$.alert = function(){196		if(!arguments.length) return false;197		var obj = arguments[0];198		var b = obj.btn || 'ç¡®å®';199		var til = obj.title || 'æç¤º';200		var popClass = obj.popClass || '';201		var pop = $('.common-popup');202		var html = '<div class="title">'+til+'</div><div class="content">'+obj.content+'</div>';203		html+= '<div class="btns mt55"><a href="javascript:;" class="btn metrobtn only close-alert-pop">'+b+'</a></div>';204		setTimeout(function(){205			if(pop.length > 0){206				pop.html(html).attr('id','alertPop').css('display','block');207			}else{208				pop = $('<div id="alertPop" class="common-popup '+ popClass +'">'+html+'</div>');209				$('body').append(pop);210			}211			$.showWrapper(obj.finish);212			$.popPosition(pop);213			mHistory.addState({pop:1});214			history.pushState({pop:1},null,null);215			$('#alertPop .close-alert-pop').on('click',function(){216				var $this = $(this);217				history.go(-1);218				if(typeof obj.callback === 'function'){obj.callback.call($this);}219				if(typeof obj.finish === 'function'){obj.finish();}220				$.hidePopUp();221			});222		},200)223	}224	$.showOptions = function(){225		if(!arguments.length) return false;226		var obj = arguments[0];227		var til = obj.title || 'è¯·éæ©',228			option = obj.option || '',229			val = obj.value || option,230			type = obj.type || 1,231			pop = $('.common-popup');232		var html = '<div class="title">'+til+'</div><div class="options-pop-list">';233		for(var i = 0;i < option.length;i++){234			html += '<div class="option-pop-content" data-value="'+ val[i] +'">' + option[i] + '</div>';235		}236		html+= '</div>';237		if(pop.length > 0){238			pop.html(html).attr('id','selectListPop').css('display','block');239		}else{240			pop = $('<div id="selectListPop" class="common-popup">'+html+'</div>');241			$('body').append(pop);242		}243		$.showWrapper(obj.finish);244		$.popPosition(pop);245		mHistory.addState({pop:1});246		history.pushState({pop:1},null,null);247		$('#selectListPop .option-pop-content').on('click',function(){248			var $this = $(this);249			var val = $this.attr('data-value'),250				option = $this.html();251			$.hidePopUp();252			history.go(-1);253			if(val === 'openAlbum'){254				if (typeof window.MomoBridge == 'object')  {255					MomoBridge.ready(function(BRG){256						BRG.invoke('readImage', {257							//id: 'imgPreview_0',258							id:$this.attr('_imgid'),259							method:1,260							type:'base64'261						},function(id,data,size,type){262							if(!data) return false;263							$('#'+id)[0].src="data:image/jpeg;base64,"+data;264							var src = $('#'+id)[0].src;265							if(window.setImageCallback) setImageCallback(id,src,data);266						})267					})268				} else {269					momo_btn_controller.controller_init_callback=function(){270						momo_btn_controller.readImage(JSON.stringify({271							//id: 'imgPreview_0',272							id:$this.attr('_imgid'),273							method:1,274							type:'base64'275						}));276					};277					momo_btn_controller.momo_btn_controller_init();278				}279			}else if(val === 'openCamera'){280				if (typeof window.MomoBridge == 'object')  {281					MomoBridge.ready(function(BRG){282						BRG.invoke('readImage', {283							//id: 'imgPreview_0',284							id:$this.attr('_imgid'),285							method:2,286							type:'base64'287						},function(id,data,size,type){288							if(!data) return false;289							$('#'+id)[0].src="data:image/jpeg;base64,"+data;290							var src = $('#'+id)[0].src;291							if(window.setImageCallback) setImageCallback(id,src,data);292						})293					})294				} else {295					momo_btn_controller.controller_init_callback=function(){296						momo_btn_controller.readImage(JSON.stringify({297							//id: 'imgPreview_0',298							id:$this.attr('_imgid'),299							method:2,300							type:'base64'301						}));302					};303					momo_btn_controller.momo_btn_controller_init();304				}305			} else {306				if(typeof obj.callback === 'function'){307					if(type == 1){308						obj.callback(val);309					}else if(type == 2){310						obj.callback(option);311					}else{312						obj.callback(val,option);313					}314				}315			}316			if(typeof obj.finish === 'function'){obj.finish();}317		})318		return pop.find('.option-pop-content');319	}...pop.js
Source:pop.js  
...272    };273    //注å$æä»¶274    $.fn.pop = function (opts) {275        opts = $.extend(opts, { ref : this[0] });276        return new pop(opts);277    };278    module.exports = function(opts){279        return new pop(opts);280    };...NotyPopLoadTemplate.js
Source:NotyPopLoadTemplate.js  
1// ç¹å»éç¥å¼¹çªä¸è½½æ¨¡æ¿2'use strict';3var util = require('util');4var GtReq = require('../GtReq');5var BaseTemplate = require('./BaseTemplate');6function NotPopLoadTemplate(options) {7    BaseTemplate.call(this, options);8    options = util._extend({9        notyIcon: '',           //éç¥æ å¾æ 10        logoUrl: '',            //ä»ç½ç»è·å徿 11        notyTitle: '',          //éç¥æ æ é¢12        notyContent: '',        //éç¥æ å
容13        isVibrate: true,14        isClearable: true,      //éç¥æ¯å¦å¯æ¸
é¤15        isRing: true,16        popTitle: '',           //å¼¹æ¡æ é¢17        popContent: '',         //å¼¹æ¡å
容18        popImage: '',           //å¼¹æ¡å¾ç19        popButton1: '',         //左边æé®åç§°20        popButton2: '',         //å³è¾¹æé®åç§°21        loadIcon: '',           //ä¸è½½å¾æ 22        loadTitle: '',          //ä¸è½½æ é¢23        loadUrl: '',            //ä¸è½½å°å24        isAutoInstall: false,   //æ¯å¦èªå¨å®è£
25        isActived: false,       //æ¯å¦æ¿æ´»26        androidMark: '',        //å®åæ è¯27        symbianMark: '',        //å¡çæ è¯28        iphoneMark: ''          //è¹ææ è¯29    }, options);30    util._extend(this, options);31}32util.inherits(NotPopLoadTemplate, BaseTemplate);33NotPopLoadTemplate.prototype.getActionChain = function() {34    // 设置actionChain35    // Set actionChain36    var actionChain = new GtReq.ActionChain({37        actionId: 1,38        type: GtReq.ActionChain.Type.Goto,39        next: 1000040    });41    var actionChain1 = new GtReq.ActionChain({42        actionId: 10000,43        type: GtReq.ActionChain.Type.notification,44        title: this.notyTitle,45        text: this.notyContent,46        logo: this.notyIcon,47        logoURL: this.logoUrl,48        ring: this.isRing,49        clearable: this.isClearable,50        buzz: this.isVibrate,51        next: 1001052    });53    // éç¥54    // Notification55    var actionChain2 = new GtReq.ActionChain({56        actionId: 10001,57        type: GtReq.ActionChain.Type.notification,58        title: this.notyTitle,59        text: this.notyContent,60        logo: this.notyIcon,61        ring: this.isRing,62        clearable: true,63        buzz: true,64        next: 1001065    });66    var actionChain3 = new GtReq.ActionChain({67        actionId: 10010,68        type: GtReq.ActionChain.Type.Goto,69        next: 1002070    });71    //å¼¹æ¡æé®72    var button1 = new GtReq.Button({73        text: this.popButton1,74        next: 1004075    });76    var button2 = new GtReq.Button({77        text: this.popButton2,78        next: 10079    });80    //å¼¹æ¡81    var actionChain4 = new GtReq.ActionChain({82        actionId: 10020,83        type: GtReq.ActionChain.Type.popup,84        title: this.popTitle,85        text: this.popContent,86        img: this.popImage,87        buttons: [button1, button2],88        next: 689    });90    //appstartupid91    var appStartUp = new GtReq.AppStartUp({92        android: this.androidMark,93        ios: this.iphoneMark,94        symbia: this.symbianMark95    });96    var actionChain5 = new GtReq.ActionChain({97        actionId: 10040,98        type: GtReq.ActionChain.Type.appdownload,99        name: this.loadTitle,100        url: this.loadUrl,101        logo: this.loadIcon,102        autoInstall: this.isAutoInstall,103        autostart: this.isActived,104        appstartupid: appStartUp,105        next: 100106    });107    var actionChain6 = new GtReq.ActionChain({108        actionId: 100,109        type: GtReq.ActionChain.Type.eoa110    });111    var actionChains = [actionChain, actionChain1, actionChain2, actionChain3, actionChain4, actionChain5, actionChain6];112    return actionChains;113};114NotPopLoadTemplate.prototype.getPushType = function() {115    return 'NotyPopLoad';116};117/**118 * 设置éç¥æ å¾æ 119 *120 * @param notyIcon121 */122NotPopLoadTemplate.prototype.setNotyIcon = function(notyIcon) {123    this.notyIcon = notyIcon;124    return this;125};126NotPopLoadTemplate.prototype.setLogoUrl = function(logoUrl) {127    this.logoUrl = logoUrl;128    return this;129};130/**131 * 设置éç¥æ æ é¢132 *133 * @param notyTitle134 */135NotPopLoadTemplate.prototype.setNotyTitle = function(notyTitle) {136    this.notyTitle = notyTitle;137    return this;138};139/**140 * 设置éç¥æ å
容141 *142 * @param notyContent143 */144NotPopLoadTemplate.prototype.setNotyContent = function(notyContent) {145    this.notyContent = notyContent;146    return this;147};148/**149 * éç¥æ¯å¦å¯æ¸
é¤150 *151 * @param isClearable152 */153NotPopLoadTemplate.prototype.setIsClearable = function(isClearable) {154    this.isClearable = isClearable;155    return this;156};157/**158 * æ¯å¦åé159 *160 * @param isRing161 */162NotPopLoadTemplate.prototype.setIsRing = function(isRing) {163    this.isRing = isRing;164    return this;165};166/**167 * æ¯å¦éå¨168 *169 * @param isVibrate170 */171NotPopLoadTemplate.prototype.setIsVibrate = function(isVibrate) {172    this.isVibrate = isVibrate;173    return this;174};175/**176 * è®¾ç½®å¼¹æ¡æ é¢177 *178 * @param popTitle179 */180NotPopLoadTemplate.prototype.setPopTitle = function(popTitle) {181    this.popTitle = popTitle;182    return this;183};184/**185 * 设置弹æ¡å
容186 *187 * @param popContent188 */189NotPopLoadTemplate.prototype.setPopContent = function(popContent) {190    this.popContent = popContent;191    return this;192};193/**194 * 设置弹æ¡å¾ç195 *196 * @param popImage197 */198NotPopLoadTemplate.prototype.setPopImage = function(popImage) {199    this.popImage = popImage;200    return this;201};202/**203 * 设置左边æé®åç§°204 *205 * @param popButton1206 */207NotPopLoadTemplate.prototype.setPopButton1 = function(popButton1) {208    this.popButton1 = popButton1;209    return this;210};211/**212 * 设置å³è¾¹æé®åç§°213 *214 * @param popButton2215 */216NotPopLoadTemplate.prototype.setPopButton2 = function(popButton2) {217    this.popButton2 = popButton2;218    return this;219};220/**221 * 设置ä¸è½½å¾æ 222 *223 * @param loadIcon224 */225NotPopLoadTemplate.prototype.setLoadIcon = function(loadIcon) {226    this.loadIcon = loadIcon;227    return this;228};229/**230 * 设置ä¸è½½æ é¢231 *232 * @param loadTitle233 */234NotPopLoadTemplate.prototype.setLoadTitle = function(loadTitle) {235    this.loadTitle = loadTitle;236    return this;237};238/**239 * 设置ä¸è½½å°å240 *241 * @param loadUrl242 */243NotPopLoadTemplate.prototype.setLoadUrl = function(loadUrl) {244    this.loadUrl = loadUrl;245    return this;246};247/**248 * 设置æ¯å¦èªå¨å®è£
249 *250 * @param isAutoInstall251 */252NotPopLoadTemplate.prototype.setAutoInstall = function(isAutoInstall) {253    this.isAutoInstall = isAutoInstall;254    return this;255};256/**257 * 设置æ¯å¦æ¿æ´»258 *259 * @param isActived260 */261NotPopLoadTemplate.prototype.setActived = function(isActived) {262    this.isActived = isActived;263    return this;264};265/**266 * 设置å®åæ è¯267 *268 * @param androidMark269 */270NotPopLoadTemplate.prototype.setAndroidMark = function(androidMark) {271    this.androidMark = androidMark;272    return this;273};274/**275 * 设置å¡çæ è¯276 *277 * @param symbianMark278 */279NotPopLoadTemplate.prototype.setSymbianMark = function(symbianMark) {280    this.symbianMark = symbianMark;281    return this;282};283/**284 * è®¾ç½®è¹ææ è¯285 *286 * @param iphoneMark287 */288NotPopLoadTemplate.prototype.setIphoneMark = function(iphoneMark) {289    this.iphoneMark = iphoneMark;290    return this;291};...myscript.js
Source:myscript.js  
1// shim layer with setTimeout fallback2window.requestAnimFrame = (function(){3  return  window.requestAnimationFrame       ||  4          function( callback ){5            window.setTimeout(callback, );6          };7})();8// namespace our game9var POP = {10    // set up some inital values11    m: true,12    WIDTH: 360, 13    HEIGHT:  540, 14    scale:  1,15    // the position of the canvas16    // in relation to the screen17    offset: {top: 0, left: 0},18    // store all bubble, touches, particles etc.19	colorArray:null,20	grid: new Array(8),21    // the amount of game ticks until22    // we spawn a bubble23    // for tracking player's progress24    // we'll set the rest of these25    // in the init function26    currentWidth:  null,27    currentHeight:  null,28    canvas: null,29    ctx:  null,30	numPlayers:2,31	currentPlayer:null,32	myTurn:true,33	temp:null,34	ifFinished:false,35	firstMove: new Array(),36    init: function() {37		POP.colorArray=["#ff0000","#0000ff","#976","#abff00","#c71585","#008080"];38		POP.currentPlayer=0;39		var i;40		POP.firstMove[POP.numPlayers];41		for (i=0;i<POP.numPlayers;i++){42			POP.firstMove[i]=false;43		}44		for (i=0;i<8;i=i+1){45			POP.grid[i] = [[0,7],[0,7],[0,7],[0,7],[0,7],[0,7],[0,7],[0,7]];46		};47		48        // the proportion of width to height49        POP.RATIO = POP.WIDTH / POP.HEIGHT;50        // these will change when the screen is resize51        52        // this is our canvas element53        POP.canvas = document.getElementsByTagName('canvas')[0];54        // it's important to set this55        // otherwise the browser will56        // default to 320x20057        58        // the canvas context allows us to 59        // interact with the canvas api60        POP.ctx = POP.canvas.getContext('2d');61        62		window.addEventListener('click', function(e) {63            e.preventDefault();64            POP.Input.set(e);65        },);66        // listen for touches67        68        // we're ready to resize69        POP.resize();70        POP.loop();71    },72	73	update: function() {74		var i;75		if (POP.Input.tapped) {76            // keep track of taps; 77            // set tapped back to false78            // to avoid spawning a new touch79            // in the next cycle80            POP.Input.tapped = false;81			if(POP.myTurn&&(ifValidMove(Math.floor(POP.Input.x/45),Math.floor(POP.Input.y/45)))){82				goToNextState(Math.floor(POP.Input.x/45),Math.floor(POP.Input.y/45),POP.currentPlayer,false);83				POP.currentPlayer = (POP.currentPlayer + 1)%POP.numPlayers;84			}85        }86	},87	88	render: function() {89        var i;90		POP.Draw.rect(0, 0, POP.WIDTH, POP.HEIGHT, '#000');91		POP.ctx.strokeStyle=POP.colorArray[(POP.currentPlayer)%POP.numPlayers]; 92		POP.ctx.lineWidth=2;93		for (i=0;i<=360;i=i+360/8){94			POP.ctx.moveTo(i,0);95			POP.ctx.lineTo(i,360);96			POP.ctx.stroke();97		}98		for(i=0;i<=360;i=i+360/8){99			POP.ctx.moveTo(0,i);100			POP.ctx.lineTo(360,i);101			POP.ctx.stroke();102		}103		104		for(var i=0;i<8;i++){105			for(var j=0;j<8;j++){106				if(POP.grid[i][j][0]==1){107					POP.Draw.circle(i*45+15,j*45+15,7,POP.colorArray[POP.grid[i][j][1]]);108				}109				else if(POP.grid[i][j][0]==2){110					POP.Draw.circle(i*45+10,j*45+10,7,POP.colorArray[POP.grid[i][j][1]]);111					POP.Draw.circle(i*45+15,j*45+15,7,POP.colorArray[POP.grid[i][j][1]]);112				}113				else if(POP.grid[i][j][0]==3){114					POP.Draw.circle(i*45+15,j*45+15,7,POP.colorArray[POP.grid[i][j][1]]);115					POP.Draw.circle(i*45+20,j*45+20,7,POP.colorArray[POP.grid[i][j][1]]);116					POP.Draw.circle(i*45+30,j*45+30,7,POP.colorArray[POP.grid[i][j][1]]);117				}118			}119		}120		if(POP.ifFinished){121            if(POP.m==true){122                document.getElementById('clap').play();123                POP.m=false;124            }125			POP.Draw.rect(0, 0, POP.WIDTH, POP.HEIGHT, '#000');126			POP.Draw.text("Player " + POP.currentPlayer +" Won!", 90,270,30,"#fff");127		}128		},129	130	loop: function() {131        requestAnimFrame( POP.loop );132        POP.update();133        POP.render();134    },135	resize: function() {136    137        POP.currentHeight = window.innerHeight;138        // resize the width in proportion139        // to the new height140        POP.currentWidth = POP.currentHeight * POP.RATIO;141        // set the new canvas style width & height142        // note: our canvas is still 320x480 but143        // we're essentially scaling it with CSS144        POP.canvas.style.width = POP.currentWidth + 'px';145        POP.canvas.style.height = POP.currentHeight + 'px';146        // the amount by which the css resized canvas147        // is different to the actual (480x320) size.148        POP.scale = POP.currentWidth / POP.WIDTH;149        // position of canvas in relation to150        // the screen151        POP.offset.top = POP.canvas.offsetTop;152        POP.offset.left = POP.canvas.offsetLeft;153    },154	155};	156POP.Draw = {157    clear: function() {158        POP.ctx.clearRect(0, 0, POP.WIDTH, POP.HEIGHT);159    },160    rect: function(x, y, w, h, col) {161        POP.ctx.fillStyle = col;162        POP.ctx.fillRect(x, y, w, h);163    },164    circle: function(x, y, r, col) {165        POP.ctx.fillStyle = col;166        POP.ctx.beginPath();167        POP.ctx.arc(x + 5, y + 5, r, 0,  Math.PI * 2, true);168        POP.ctx.fill();169    },170    text: function(string, x, y, size, col) {171        POP.ctx.font = 'bold '+size+'px Monospace';172        POP.ctx.fillStyle = col;173        POP.ctx.fillText(string, x, y);174    }175};176var ifCorner = function(a,b){177	if((a==0)&&(b==0)){178		return true;}179	else if((a==0)&&(b==7)){180		return true;}181	else if((a==7)&&(b==0)){182		return true;}183	else if((a==7)&&(b==7)){184		return true;}185	else{186		return false;};187	}188var ifEdge = function(a,b){189	if(!ifCorner(a,b)&&((a==0)||(b==0)||(a==7)||(b==7))){190		return true;191	}192	else{193		return false;194	}195	}196	197var ifTerminate = function(currentPlayer){198	if(POP.firstMove[currentPlayer]==false){199		POP.firstMove[currentPlayer]=true;200		return false;201	}202	else{203		var result = true;204		for(var i=0;i<8;i++){205			for(var j=0;j<8;j++){206				if(POP.grid[i][j][1]!=currentPlayer&&(!(POP.grid[i][j][0]==0))){207					result = false;208				}209			}210		}211	return result;212	}213}	214	215var ifValidMove = function(x,y){216	if((POP.grid[x][y][0]==0)||(POP.grid[x][y][1]==POP.currentPlayer)){217		return true;218	}219	else{220		return false;221	};222	223}224	225var goToNextState = function(x,y,currentPlayer,ifNuclear){226        document.getElementById('split').play();227        POP.grid[x][y][1]=currentPlayer;228		POP.grid[x][y][0]+=1;229			var ifFull = false;230			if (ifCorner(x,y)&&POP.grid[x][y][0]>1){231				ifFull = true;232			}233			else if((ifEdge(x,y))&&(POP.grid[x][y][0]>2)){234				ifFull = true;235			}236			else if(POP.grid[x][y][0]>3){237				ifFull = true;238			}239			var possible = [[x,y+1],[x,y-1],[x+1,y],[x-1,y]];240			if(ifFull){241				for(var i=0;i<4;i++){242					if((possible[i][0]>=0)&&(possible[i][0]<=7)&&(possible[i][1]>=0)&&(possible[i][1]<=7)){243						POP.grid[x][y][0] -= 1;244						goToNextState(possible[i][0],possible[i][1],currentPlayer,true);245						246					}247				}248			}249			if (ifTerminate(currentPlayer)){250			POP.render();251			POP.ifFinished=true;252			}253};254POP.Input = {255    x: 0,256    y: 0,257    tapped :false,258    set: function(data) {259        this.x = (data.pageX - POP.offset.left) / POP.scale;260        this.y = (data.pageY - POP.offset.top) / POP.scale;261        this.tapped = true;262    }263};...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!!
