Best Python code snippet using autotest_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
1define('pop',['zepto'],function(require, exports, module) {2 var $ = require("zepto");3 //pop4 var pop = function(opts){5 //é»è®¤åæ°6 var defOpts = {7 /**8 * å¼¹åºæ¡æ é¢9 * @property {String} [title=null]10 */11 title : null,12 /**13 * åç
§å¯¹è±¡14 * @property {String} [ref=null]15 */16 ref : null, //åç
§ç®æ 17 /**18 * åç
§å¯¹è±¡é«åº¦19 * @property {Number} [refTop=0]20 */21 refTop : 0,22 /**23 * å®ä½æ¹å24 * @property {string} [pos='']25 */26 pos : '',27 /**28 * æ¯å¦æ¾ç¤ºå
³éæé®29 * @property {Boolean} [isClose=true]30 */31 isClose : true,32 /**33 * æ¯å¦å¨å¼¹åºçæ¶åç¦ç¨scroll34 * @property {Boolean} [scrollMove=false]35 */36 scrollMove : false,37 /**38 * å¼¹åºæ¡å
容39 * @property {String} [con=null]40 */41 con : '',42 /**43 * å¼¹åºæ¡ä¸çæé®44 * @property {Array} [btns=[{text : 'å
³é', handler : 'close'}]]45 */46 btns : [{ //æé®47 text : 'å
³é',48 handler : 'close'49 }],50 /**51 * å¼¹åºæ¡æ¾ç¤ºå®åçåè°å½æ°52 * @type {function}53 */54 onShow : function(){},55 /**56 * å¼¹åºæ¡å
³éåçåè°å½æ°57 * @type {function}58 */59 onClose : function(){}60 };61 this.opts = $.extend(defOpts, opts); 62 this.init();63 };64 //åå§å65 pop.prototype.init = function(){66 var _ts = this, 67 opts = this.opts;68 //åºç¡å±æ§69 _ts.id = opts.id || 'pop-'+uuid(); //èªå¨è®¾ç½®id70 _ts.body = $('body'); //body71 _ts.bodyH = _ts.body.get(0).scrollHeight; //body height72 _ts.win = $(window); //window73 _ts.winH = _ts.win.height(); //window height74 _ts.winS = _ts.body.get(0).scrollTop; //scrollTop75 _ts.render(); //渲æ76 };77 //å®ä½78 pop.prototype.position = function(){79 var _ts = this, 80 opts = _ts.opts, 81 winH = _ts.winH, 82 winS = _ts.winS, 83 popH = _ts.popH,84 bodyH = _ts.bodyH,85 scrTop = 0, //æ»å¨ä½ç½®86 popTop = 0; //pop top87 if(opts.pos === 'center'){88 //å±
ä¸89 if(popH > winH){ //å¼¹å±é«åº¦å¤§äºçªå£é«åº¦90 popTop = winS + 40;91 }else{92 popTop = winS + (winH-popH)/2;93 }94 }else{95 //å移åèç®æ 96 if (typeof opts.ref === "string" || opts.ref instanceof String) {97 opts.ref = $(opts.ref);98 }99 var refOffset = opts.ref.offset();100 popTop = refOffset.top + refOffset.height + opts.refTop;101 var popAllH = popTop + popH;102 //window scrollTop103 if(popAllH > bodyH){ //bodyçé«åº¦ä¸è½å¼¹åºå±çé«åº¦æ¶104 popTop = bodyH - popH - 40;105 }106 }107 //popå®ä½108 _ts.pop.css({'top':popTop});109 //scrollTop110 if(popH > winH ){111 //å½çªå£å°äºå¼¹çªé«åº¦ï¼å¼¹çªä¸ç40px112 scrTop = popTop - 40 - winS;113 popToTop(scrTop, winS);114 }else{115 if(winS > popTop){116 scrTop = popTop - 40 - winS;117 popToTop(scrTop, winS);118 }else if((popH + popTop - winH - winS) > 0){119 //å½å¼¹çªæ¾ç¤ºä¸å®æ¶ï¼çªå£æ»å¨è®©å¼¹çªå±
ä¸æ¾ç¤º120 var scrtop = popTop + popH/2 - winH/2 - winS;121 popToTop(scrtop, winS);122 }123 } 124 };125 //渲ææé®126 pop.prototype.renderBtn = function(btns, _ts){127 var btnHtml = '',128 len = btns.length>2 ? 2 : btns.length, //æå¤æ¾ç¤º2个æé®129 close = function(){130 _ts.remove();131 };132 if(len > 0){133 for(var i=0, l=len; i<l; i++){134 var ret = btns[i];135 if(typeof ret === 'object' && typeof ret.text !=='undefined'){136 //æé®137 var btn = '';138 if(typeof ret.href !== 'undefined'){139 btn = '<span data-i="'+i+'"><a href="'+ret.href+'">'+ret.text+'</a></span>';140 }else{141 btn = '<span data-i="'+i+'">'+ret.text+'</span>';142 }143 btnHtml += btn;144 //åè°æ¹æ³145 btns[i].handler = (typeof btns[i].handler !== 'undefined' && btns[i].handler === 'close') ? close : btns[i].handler;146 }147 }148 return '<div class="pop-ft">'+btnHtml+'</div>';149 }else{150 return '';151 }152 };153 //渲æ154 pop.prototype.render = function(){155 var _ts = this,156 opts = _ts.opts,157 titleEl = opts.title ? '<div class="pop-hd">'+opts.ti+'</div>' : '',158 closeEl = opts.isClose ? '<span class="pop-close"><i>å
³é</i></span>' : '',159 btnsEl = _ts.renderBtn(opts.btns, _ts),160 conEl = '';161 //æ¶æ¯162 if(typeof opts.msg !== 'undefined'){163 conEl = '<div class="pop-msg">'+opts.msg+'</div>';164 }else if(typeof opts.con !== 'undefined'){165 if($.isFunction(opts.con)){ //fun166 conEl = opts.con(_ts);167 }else{ //string168 conEl = opts.con;169 }170 }171 //ç»è£
172 var html = '<div id="'+_ts.id+'" class="pop-mod" style="visibility:hidden;">'+titleEl+'<div class="pop-bd">'+conEl+'</div>'+btnsEl+closeEl+'</div>',173 $popWrap = $('#pop-dialogs'),174 $popOver = $('#pop-overlay');175 if($popWrap.size() === 0 && $popOver.size() === 0){176 _ts.body.append('<div id="pop-dialogs">'+html+'</div><div id="pop-overlay" style="height:'+_ts.bodyH+'px;display:none;"></div>');177 $popOver = $('#pop-overlay');178 }else{179 $popWrap.html(html);180 }181 var $pop = _ts.pop = $('#'+_ts.id);182 _ts.popOver = $popOver;183 _ts.popH = $pop.offset().height;184 opts.pos = (opts.ref === null)? 'center' : opts.pos;185 //å®ä½186 _ts.position();187 188 //æ¾ç¤º189 $popOver.show();190 $pop.css('visibility','visible');191 //ç»å®äºä»¶192 //é²æ¢ç¹å»æé®ç¬é´çç¹éé®é¢ï¼æ
åäº400ms延è¿193 setTimeout(function(){194 _ts.bind();195 }, 400);196 };197 //ç»å®äºä»¶198 pop.prototype.bind = function(){199 var _ts = this, opts = _ts.opts;200 //æ§è¡onShow201 opts.onShow(_ts.pop, _ts);202 //btns203 var btns = opts.btns;204 _ts.pop.on('click', '.pop-ft span', function(){205 var i = $(this).attr('data-i'); 206 if($.isFunction(btns[i].handler)){207 btns[i].handler(_ts.pop, _ts);208 }209 });210 //close211 if(opts.isClose){212 _ts.pop.on('click', '.pop-close', $.proxy(this.remove, _ts));213 }214 _ts.pop.on('click', 'a', $.proxy(this.remove, _ts));215 //æ转å±å¹216 _ts.win.bind('orientationchange',function(e){217 _ts.body.css('height','auto');218 _ts.bodyH = _ts.body.get(0).scrollHeight;219 //_ts.body.height(_ts.bodyH);220 _ts.popOver.height(_ts.bodyH);221 _ts.winH = _ts.win.height(); 222 _ts.winS = _ts.body.get(0).scrollTop; 223 _ts.position();224 });225 $(window).on('touchmove', function(e){226 opts.scrollMove && e.preventDefault();227 })228 };229 //é设230 pop.prototype.reset = function(){231 var _ts = this;232 _ts.popH = _ts.pop.offset().height;233 _ts.position();234 };235 //移é¤236 pop.prototype.remove = function(){237 var _ts = this;238 //æ§è¡onClose239 if($.isFunction(_ts.opts.onClose)){240 _ts.opts.onClose(_ts.pop, _ts);241 }242 _ts.pop.remove();243 _ts.popOver.hide().height(_ts.bodyH);244 //_ts.body.height(_ts.bodyH);245 _ts.win.unbind('orientationchange');246 _ts = null;247 };248 //uuid249 var uuid = function(){250 var S4 = function() {251 return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);252 };253 return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());254 };255 //页é¢æ»å¨256 var popToTop = function(h,s){257 var nav_t = 0;258 var nav_d = 30; //é度259 var nav_c = h; //é«åº¦260 var nac = $('body').get(0);261 var popSc = function(t,b,c,d){262 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;263 };264 function down(){265 if(nav_t<nav_d){266 nav_t++;267 nac.scrollTop = Math.ceil(popSc(nav_t,0,nav_c,nav_d))+s;268 setTimeout(down, 20);269 }270 }271 down();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!!