How to use cancelCallback method in Playwright Internal

Best JavaScript code snippet using playwright-internal

HostSdk.js

Source:HostSdk.js Github

copy

Full Screen

1/**2 * 与客户端交互的SDK3 */4(function() {5 // 判断平台的工具方法6 var ua = navigator.userAgent;7 var clientTool = {8 // 是否是Android9 isAndroid: ua.toLowerCase().indexOf("android") > -1 || ua.toLowerCase().indexOf("linux") > -1,10 // 是否是iPad11 isIpad: ua.indexOf("iPad") > -1,12 // 是否是iPhone13 isIphone: ua.indexOf("iPhone") > -1,14 // 是否在苹果设备15 isApple: false16 };17 clientTool.isApple = (clientTool.isIphone === true || clientTool.isIpad === true);18 // 客户端回调19 window.host_sdk = {20 // 已经初始化过21 initialized: false,22 // 生命周期方法,初始化23 onInit: function() {24 window.host_sdk.initialized = true;25 if (hostsdk && hostsdk.onInit) hostsdk.onInit();26 },27 // 生命周期方法,暂停执行28 onPause: function() {29 if (hostsdk && hostsdk.onPause) hostsdk.onPause();30 },31 // 生命周期方法,恢复执行32 onResume: function() {33 if (hostsdk && hostsdk.onResume) hostsdk.onResume();34 },35 // 生命周期方法,结束执行36 onStop: function() {37 if (hostsdk && hostsdk.onStop) hostsdk.onStop();38 },39 // 发生错误的回调40 errorCallback: function(errorMsg) {},41 // 取消操作后的回调42 cancelCallback: function() {},43 // 操作成功后回调44 successCallback: function() {}45 };46 // 苹果客户端jbridge47 window.setupWebViewJavascriptBridge = function(callback) {48 if (window.WebViewJavascriptBridge) {49 return callback(WebViewJavascriptBridge);50 }51 if (window.WVJBCallbacks) {52 return window.WVJBCallbacks.push(callback);53 }54 window.WVJBCallbacks = [callback];55 var WVJBIframe = document.createElement('iframe');56 WVJBIframe.style.display = 'none';57 WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';58 document.documentElement.appendChild(WVJBIframe);59 setTimeout(function() {60 document.documentElement.removeChild(WVJBIframe)61 }, 0);62 };63 if (clientTool.isApple) {64 setupWebViewJavascriptBridge(function(bridge) {65 window.ios_hostsdk = bridge;66 });67 }68 // 封装SDK69 var hostsdk = {70 // 初始化时要执行的回调队列71 initCallbacks: [],72 init: function(callback) {73 if (window.host_sdk.initialized) {74 callback();75 }76 window.hostsdk.initCallbacks.push(callback);77 },78 onInit: function() {79 for (var i = 0; i < window.hostsdk.initCallbacks.length; i++) {80 window.hostsdk.initCallbacks[i]();81 }82 },83 share: function(options) {84 if (!window.host_sdk.initialized) {85 location.href = "protocol://share?jsondata=" + JSON.stringify({86 desc: options.description,87 url: options.url,88 title: options.title,89 icon: options.icon,90 productid: "",91 coin: "0"92 });93 return;94 }95 if (options.successCallback) window.host_sdk.successCallback = options.successCallback;96 if (options.errorCallback) window.host_sdk.errorCallback = options.errorCallback;97 if (options.cancelCallback) window.host_sdk.cancelCallback = options.cancelCallback;98 if (clientTool.isApple) {99 ios_hostsdk.callHandler("share", {100 "title": options.title,101 "desc": options.description,102 "url": options.url,103 "icon": options.icon,104 "platforms": options.platforms105 });106 } else {107 android_hostsdk.share(options.title, options.url, options.description, options.icon, options.platforms);108 }109 },110 login: function(options) {111 if (!window.host_sdk.initialized) {112 location.href = "protocol://login";113 return;114 }115 if (options.successCallback) window.host_sdk.successCallback = options.successCallback;116 if (options.errorCallback) window.host_sdk.errorCallback = options.errorCallback;117 if (options.cancelCallback) window.host_sdk.cancelCallback = options.cancelCallback;118 if (clientTool.isApple) {119 ios_hostsdk.callHandler("login");120 } else {121 android_hostsdk.login();122 }123 },124 recharge: function(options) {125 if (!window.host_sdk.initialized) {126 location.href = "protocol://recharge?jsondata=" + JSON.stringify({127 payway: "other"128 });129 return;130 }131 if (options.successCallback) window.host_sdk.successCallback = options.successCallback;132 if (options.errorCallback) window.host_sdk.errorCallback = options.errorCallback;133 if (options.cancelCallback) window.host_sdk.cancelCallback = options.cancelCallback;134 if (clientTool.isApple) {135 ios_hostsdk.callHandler("recharge");136 } else {137 android_hostsdk.recharge();138 }139 },140 downloadBook: function(options) {141 if (!window.host_sdk.initialized) {142 var ids = options.bookId.split(",");143 location.href = "protocol://downloadbook?jsondata=" + JSON.stringify(ids);144 return;145 }146 if (options.successCallback) window.host_sdk.successCallback = options.successCallback;147 if (options.errorCallback) window.host_sdk.errorCallback = options.errorCallback;148 if (clientTool.isApple) {149 ios_hostsdk.callHandler("downloadBook", options.bookId);150 } else {151 android_hostsdk.downloadBook(options.bookId);152 }153 },154 getVip: function(options) {155 if (!window.host_sdk.initialized) {156 location.href = "protocol://getvip";157 return;158 }159 if (options.successCallback) window.host_sdk.successCallback = options.successCallback;160 if (options.cancelCallback) window.host_sdk.cancelCallback = options.cancelCallback;161 if (options.errorCallback) window.host_sdk.errorCallback = options.errorCallback;162 if (clientTool.isApple) {163 ios_hostsdk.callHandler("getVip");164 } else {165 android_hostsdk.getVip();166 }167 },168 openUserCategory: function(options) {169 if (options.successCallback) window.host_sdk.successCallback = options.successCallback;170 if (options.cancelCallback) window.host_sdk.cancelCallback = options.cancelCallback;171 if (options.errorCallback) window.host_sdk.errorCallback = options.errorCallback;172 if (clientTool.isApple) {173 ios_hostsdk.callHandler("openUserCategory");174 } else {175 android_hostsdk.openUserCategory();176 }177 },178 getInfo: function(options) {179 if (!window.host_sdk.initialized) {180 var search = location.href.split("?").length > 1 ? href.split("?")[1] : "";181 if (search.indexOf("#")) {182 search = search.split("#")[0];183 }184 var params = {};185 var i, p;186 if (search && search.trim().length >= 0) {187 var strs = search.split("&");188 for (i = 0; i < strs.length; i++) {189 p = strs[i].split("=");190 if (p.length > 1) {191 params[p[0].toLowerCase()] = p[1];192 } else {193 params[p[0].toLowerCase()] = p[0];194 }195 }196 }197 params.userId = params.uid;198 if (options.successCallback) options.successCallback(params);199 return;200 }201 if (options.successCallback) window.host_sdk.successCallback = options.successCallback;202 if (options.errorCallback) window.host_sdk.errorCallback = options.errorCallback;203 if (clientTool.isApple) {204 ios_hostsdk.callHandler("getInfo");205 } else {206 android_hostsdk.getInfo();207 }208 },209 openBook: function(bookId, errorCallback) {210 if (!window.host_sdk.initialized) {211 location.href = "protocol://openbook?jsondata=" + JSON.stringify({212 bookid: bookId213 });214 return;215 }216 if (errorCallback) window.host_sdk.errorCallback = errorCallback;217 if (clientTool.isApple) {218 ios_hostsdk.callHandler("openBook", bookId);219 } else {220 android_hostsdk.openBook(bookId);221 }222 },223 showBookDetail: function(bookId, errorCallback) {224 if (errorCallback) window.host_sdk.errorCallback = errorCallback;225 if (clientTool.isApple) {226 ios_hostsdk.callHandler("showBookDetail", bookId);227 } else {228 android_hostsdk.showBookDetail(bookId);229 }230 },231 openBookList: function(bookListId, errorCallback) {232 if (!window.host_sdk.initialized) {233 location.href = "protocol://seriesbook?jsondata=" + JSON.stringify({234 seriesid: bookListId235 });236 return;237 }238 if (errorCallback) window.host_sdk.errorCallback = errorCallback;239 if (clientTool.isApple) {240 ios_hostsdk.callHandler("openBookList", bookListId);241 } else {242 android_hostsdk.openBookList(bookListId);243 }244 },245 searchBook: function(keyword, errorCallback) {246 if (!window.host_sdk.initialized) {247 location.href = "protocol://searchbook?jsondata=" + JSON.stringify({248 keywords: keyword249 });250 return;251 }252 if (errorCallback) window.host_sdk.errorCallback = errorCallback;253 if (clientTool.isApple) {254 ios_hostsdk.callHandler("searchBook", keyword);255 } else {256 android_hostsdk.searchBook(keyword);257 }258 },259 exit: function(errorCallback) {260 if (!window.host_sdk.initialized) {261 location.href = "protocol://exit";262 return;263 }264 if (errorCallback) window.host_sdk.errorCallback = errorCallback;265 if (clientTool.isApple) {266 ios_hostsdk.callHandler("exit");267 } else {268 android_hostsdk.exit();269 }270 },271 setCloseable: function(closable, errorCallback) {272 if (errorCallback) window.host_sdk.errorCallback = errorCallback;273 if (clientTool.isApple) {274 ios_hostsdk.callHandler("setCloseable", closable);275 } else {276 android_hostsdk.setCloseable(closable);277 }278 }279 };280 window.hostsdk = hostsdk;281})();282if (typeof exports !== "undefined") {283 if (typeof module !== "undefined" && module.exports) {284 exports = module.exports = hostsdk;285 }286 exports.hostsdk = hostsdk;287} else if (typeof define === "function" && define.amd) {288 define([], hostsdk);...

Full Screen

Full Screen

PickerManager.js

Source:PickerManager.js Github

copy

Full Screen

...83 },84 onPickerCancel: (pickedValue) => {85 console.log('num', pickedValue);86 if (!!cancelCallback) {87 cancelCallback();88 }89 },90 onPickerSelect: (pickedValue) => {91 console.log('num', pickedValue);92 }93 });94 Picker.show();95 }96 _showDatePicker(selectedValue, confirmCallback, cancelCallback) {97 Picker.init({98 pickerData: this._createDateData(),99 pickerToolBarFontSize: 16,100 pickerFontSize: 16,101 pickerFontColor: [255, 0 ,0, 1],102 selectedValue:selectedValue,103 pickerTitleText:'选择日期',104 pickerCancelBtnText:'取消',105 pickerConfirmBtnText:'确定',106 onPickerConfirm: (pickedValue, pickedIndex) => {107 console.log('date', pickedValue, pickedIndex);108 if (!!confirmCallback) {109 confirmCallback(pickedValue, pickedIndex);110 }111 },112 onPickerCancel: (pickedValue, pickedIndex) => {113 console.log('date', pickedValue, pickedIndex);114 if (!!cancelCallback) {115 cancelCallback();116 }117 },118 onPickerSelect: (pickedValue, pickedIndex) => {119 console.log('date', pickedValue, pickedIndex);120 }121 });122 Picker.show();123 }124 _showAreaPicker(confirmCallback, cancelCallback) {125 Picker.init({126 pickerData: this._createAreaData(),127 selectedValue: ['河北', '唐山', '古冶区'],128 onPickerConfirm: pickedValue => {129 console.log('area', pickedValue);130 if (!!confirmCallback) {131 confirmCallback(pickedValue);132 }133 },134 onPickerCancel: pickedValue => {135 console.log('area', pickedValue);136 if (!!cancelCallback) {137 cancelCallback();138 }139 },140 onPickerSelect: pickedValue => {141 //Picker.select(['山东', '青岛', '黄岛区'])142 console.log('area', pickedValue);143 }144 });145 Picker.show();146 }147 _showCitiesPicker(selectedValue, confirmCallback, cancelCallback) {148 Picker.init({149 pickerData: ImportantCity.cities,150 selectedValue: [selectedValue],151 pickerTitleText:'选择城市',152 pickerCancelBtnText:'取消',153 pickerConfirmBtnText:'确定',154 onPickerConfirm: pickedValue => {155 console.log('area', pickedValue);156 if (!!confirmCallback) {157 confirmCallback(pickedValue);158 }159 },160 onPickerCancel: pickedValue => {161 console.log('area', pickedValue);162 if (!!cancelCallback) {163 cancelCallback();164 }165 },166 onPickerSelect: pickedValue => {167 console.log('area', pickedValue);168 }169 });170 Picker.show();171 }172 _showTimePicker(confirmCallback, cancelCallback) {173 let years = [],174 months = [],175 days = [],176 hours = [],177 minutes = [];178 for(let i=1;i<51;i++){179 years.push(i+1980);180 }181 for(let i=1;i<13;i++){182 months.push(i);183 hours.push(i);184 }185 for(let i=1;i<32;i++){186 days.push(i);187 }188 for(let i=1;i<61;i++){189 minutes.push(i);190 }191 let pickerData = [years, months, days, ['am', 'pm'], hours, minutes];192 let date = new Date();193 let selectedValue = [194 [date.getFullYear()],195 [date.getMonth()+1],196 [date.getDate()],197 [date.getHours() > 11 ? 'pm' : 'am'],198 [date.getHours() === 12 ? 12 : date.getHours()%12],199 [date.getMinutes()]200 ];201 Picker.init({202 pickerData,203 selectedValue,204 pickerTitleText: 'Select Date and Time',205 wheelFlex: [2, 1, 1, 2, 1, 1],206 onPickerConfirm: pickedValue => {207 console.log('area', pickedValue);208 if (!!confirmCallback) {209 confirmCallback(pickedValue);210 }211 },212 onPickerCancel: pickedValue => {213 console.log('area', pickedValue);214 if (!!cancelCallback) {215 cancelCallback();216 }217 },218 onPickerSelect: pickedValue => {219 let targetValue = [...pickedValue];220 if(parseInt(targetValue[1]) === 2){221 if(targetValue[0]%4 === 0 && targetValue[2] > 29){222 targetValue[2] = 29;223 }224 else if(targetValue[0]%4 !== 0 && targetValue[2] > 28){225 targetValue[2] = 28;226 }227 }228 else if(targetValue[1] in {4:1, 6:1, 9:1, 11:1} && targetValue[2] > 30){229 targetValue[2] = 30;...

Full Screen

Full Screen

mylayer.js

Source:mylayer.js Github

copy

Full Screen

...17 btn: ["确定"],18 cancel: function(index){19 $layer.close(index);20 if(typeof cancelCallback == 'function'){21 cancelCallback();22 }23 }24 });25 }else{26 var ops = $.extend({27 title: "提示",28 shade: 0.6,29 icon: 1,30 closeBtn: 0,31 btn: ["返回列表","继续添加"],32 yes: function(index, layero){33 $layer.close(index);34 if(typeof yesCallback == 'function'){35 yesCallback();36 }37 },38 cancel: function(index){39 $layer.close(index);40 if(typeof cancelCallback == 'function'){41 cancelCallback();42 }43 }44 },option);45 updateOptionIcon(option, ops);46 $layer.alert(option.msg, ops);47 }48}49/**50 * 弹出消息提示,点击确定执行函数51 * layer.alert 弹窗52 * btn: ["返回列表","继续添加"]53 * @param option 显示的内容54 * @param yesCallback 点击[返回列表]是否需要回调的方法55 */56window.alert = function(option, yesCallback){57 if(typeof(option) == 'string'){58 $layer.alert(option, {59 title: "提示",60 shade: 0.6,61 //icon: 1,62 closeBtn: 0,63 btn: ["确定"],64 cancel: function(index){65 $layer.close(index);66 if(typeof cancelCallback == 'function'){67 cancelCallback();68 }69 }70 });71 }else{72 var ops = $.extend({73 title: "提示",74 shade: 0.6,75 icon: 1,76 closeBtn: 0,77 btn: ["确定"],78 yes: function(index, layero){79 $layer.close(index);80 if(typeof yesCallback == 'function'){81 yesCallback();82 }83 }84 },option);85 updateOptionIcon(option, ops);86 $layer.alert(option.msg, ops);87 }88}89/**90 * 只提示消息用91 * @param content92 */93function alertMsg(content){94// alert({msg:content,btn:["确定"]});95 $layer.alert(content,{96 title: "提示",97 shade: 0.6,98 icon: 2,99 closeBtn: 0,100 btn: ["确定"],101 yes: function(index, layero){102 $layer.close(index);103 }104 });105}106/**107 * 保存 提示消息108 * layer.msg 提示消息109 * @param option 提示消息内容110 * @param cancelCallback 2秒钟后的回调方法111 */112function toast(option,cancelCallback){113 if(typeof option == 'string'){114 $layer.msg(option,{icon: 1, shade:0.6, time: 1500 }, function(){115 if(typeof cancelCallback=='function'){116 cancelCallback();117 }118 });119 }else{120 var ops = $.extend({icon: 1, shade:0.6, time: 1500 },option);121 updateOptionIcon(option, ops);122 if(ops.icon==2){123 $layer.alert(option.msg,{124 title: "提示",125 shade: ops.shade,126 icon: ops.icon,127 closeBtn: 0,128 btn: ["确定"],129 yes: function(index, layero){130 $layer.close(index);131 if(typeof cancelCallback=='function'){132 cancelCallback();133 }134 }135 });136 }else{137 $layer.msg(option.msg,ops,function(){138 if(typeof cancelCallback=='function'){139 cancelCallback();140 }141 });142 }143 }144}145/**146 * 删除 提示消息147 * layer.confirm 提示148 * @param option 需要提示的消息内容149 * @param yesCallback 点击确定的回调函数150 */151window.confirm = function(option, yesCallback, cancelCallback){152 if(typeof option == 'string'){153 $layer.confirm(option,{icon: 3,title:'提示'}, function(index){154 $layer.close(index);155 if(typeof yesCallback=='function'){156 yesCallback();157 }158 }, function(index){159 $layer.close(index);160 if(typeof cancelCallback=='function'){161 cancelCallback();162 }163 });164 }else{165 var ops = $.extend({icon: 3,title:'提示'}, option);166 updateOptionIcon(option, ops);167 $layer.confirm(option.msg, ops, function(index){168 $layer.close(index);169 if(typeof yesCallback=='function'){170 yesCallback();171 }172 }, function(index){173 $layer.close(index);174 if(typeof cancelCallback=='function'){175 cancelCallback();176 }177 });178 }179}180window.prompt = function(option, yesCallback){181 var ops = $.extend({formType: 2,value: '',title: '请输入'}, option);182 $layer.prompt(ops, function(value, index, elem){183 $layer.close(index);184 if(typeof yesCallback=='function'){185 yesCallback(value);186 }187 });188}189/**190 * 系统内部错误 提示消息191 * layer.alert提示192 * btn: ["取消"]193 * @param cancelCallback 点击[取消]回调函数194 */195function error(option, cancelCallback){196 if(typeof option == 'undefined'){197 $layer.alert("系统内部错误!",{198 title: "提示",199 shade: 0.6, //遮罩透明度200 icon: 2,201 closeBtn: 0,202 btn: ["取消"],203 yes: function(index){204 $layer.close(index);205 if(typeof cancelCallback=='function'){206 cancelCallback();207 }208 }209 });210 }else{211 var ops = $.extend({212 title: "错误提示",213 shade: 0.6, //遮罩透明度214 icon: 2,215 closeBtn: 0,216 btn: ["取消"],217 yes: function(index){218 $layer.close(index);219 if(typeof cancelCallback=='function'){220 cancelCallback();221 }222 }223 },option);224 if(option.code==403 || option.code=='403' ){225 $layer.alert(option.msg, ops);226 }else if(option.code== 504 || option.code=='504' ){227 $layer.alert(option.msg, ops);228 top.location = webRoot + "/login.do";229 }else{230 if(option.code == 1){231 $layer.alert(option.msg, ops);232 }else{233 $layer.alert("系统内部错误!", ops);234 }...

Full Screen

Full Screen

vuefire.js

Source:vuefire.js Github

copy

Full Screen

1var Vue // late binding2/**3 * Returns the key of a Firebase snapshot across SDK versions.4 *5 * @param {FirebaseSnapshot} snapshot6 * @return {string|null}7 */8function _getKey (snapshot) {9 return typeof snapshot.key === 'function'10 ? snapshot.key()11 : snapshot.key12}13/**14 * Returns the original reference of a Firebase reference or query across SDK versions.15 *16 * @param {FirebaseReference|FirebaseQuery} refOrQuery17 * @return {FirebaseReference}18 */19function _getRef (refOrQuery) {20 if (typeof refOrQuery.ref === 'function') {21 refOrQuery = refOrQuery.ref()22 } else if (typeof refOrQuery.ref === 'object') {23 refOrQuery = refOrQuery.ref24 }25 return refOrQuery26}27/**28 * Check if a value is an object.29 *30 * @param {*} val31 * @return {boolean}32 */33function isObject (val) {34 return Object.prototype.toString.call(val) === '[object Object]'35}36/**37 * Convert firebase snapshot into a bindable data record.38 *39 * @param {FirebaseSnapshot} snapshot40 * @return {Object}41 */42function createRecord (snapshot) {43 var value = snapshot.val()44 var res45 if (isObject(value)) {46 res = value47 } else {48 res = {}49 Object.defineProperty(res, '.value', {50 value: value51 })52 }53 Object.defineProperty(res, '.key', {54 value: _getKey(snapshot)55 })56 return res57}58/**59 * Find the index for an object with given key.60 *61 * @param {array} array62 * @param {string} key63 * @return {number}64 */65function indexForKey (array, key) {66 for (var i = 0; i < array.length; i++) {67 if (array[i]['.key'] === key) {68 return i69 }70 }71 /* istanbul ignore next */72 return -173}74/**75 * Bind a firebase data source to a key on a vm.76 *77 * @param {Vue} vm78 * @param {string} key79 * @param {object} source80 */81function bind (vm, key, source) {82 var asObject = false83 var cancelCallback = null84 var readyCallback = null85 // check { source, asArray, cancelCallback } syntax86 if (isObject(source) && source.hasOwnProperty('source')) {87 asObject = source.asObject88 cancelCallback = source.cancelCallback89 readyCallback = source.readyCallback90 source = source.source91 }92 if (!isObject(source)) {93 throw new Error('VueFire: invalid Firebase binding source.')94 }95 var ref = _getRef(source)96 vm.$firebaseRefs[key] = ref97 vm._firebaseSources[key] = source98 if (cancelCallback) {99 cancelCallback = cancelCallback.bind(vm)100 }101 // bind based on initial value type102 if (asObject) {103 bindAsObject(vm, key, source, cancelCallback)104 } else {105 bindAsArray(vm, key, source, cancelCallback)106 }107 if (readyCallback) {108 source.once('value', readyCallback.bind(vm))109 }110}111/**112 * Define a reactive property in a given vm if it's not defined113 * yet114 *115 * @param {Vue} vm116 * @param {string} key117 * @param {*} val118 */119function defineReactive (vm, key, val) {120 if (key in vm) {121 vm[key] = val122 } else {123 Vue.util.defineReactive(vm, key, val)124 }125}126/**127 * Bind a firebase data source to a key on a vm as an Array.128 *129 * @param {Vue} vm130 * @param {string} key131 * @param {object} source132 * @param {function|null} cancelCallback133 */134function bindAsArray (vm, key, source, cancelCallback) {135 var array = []136 defineReactive(vm, key, array)137 var onAdd = source.on('child_added', function (snapshot, prevKey) {138 var index = prevKey ? indexForKey(array, prevKey) + 1 : 0139 array.splice(index, 0, createRecord(snapshot))140 }, cancelCallback)141 var onRemove = source.on('child_removed', function (snapshot) {142 var index = indexForKey(array, _getKey(snapshot))143 array.splice(index, 1)144 }, cancelCallback)145 var onChange = source.on('child_changed', function (snapshot) {146 var index = indexForKey(array, _getKey(snapshot))147 array.splice(index, 1, createRecord(snapshot))148 }, cancelCallback)149 var onMove = source.on('child_moved', function (snapshot, prevKey) {150 var index = indexForKey(array, _getKey(snapshot))151 var record = array.splice(index, 1)[0]152 var newIndex = prevKey ? indexForKey(array, prevKey) + 1 : 0153 array.splice(newIndex, 0, record)154 }, cancelCallback)155 vm._firebaseListeners[key] = {156 child_added: onAdd,157 child_removed: onRemove,158 child_changed: onChange,159 child_moved: onMove160 }161}162/**163 * Bind a firebase data source to a key on a vm as an Object.164 *165 * @param {Vue} vm166 * @param {string} key167 * @param {Object} source168 * @param {function|null} cancelCallback169 */170function bindAsObject (vm, key, source, cancelCallback) {171 defineReactive(vm, key, {})172 var cb = source.on('value', function (snapshot) {173 vm[key] = createRecord(snapshot)174 }, cancelCallback)175 vm._firebaseListeners[key] = { value: cb }176}177/**178 * Unbind a firebase-bound key from a vm.179 *180 * @param {Vue} vm181 * @param {string} key182 */183function unbind (vm, key) {184 var source = vm._firebaseSources && vm._firebaseSources[key]185 if (!source) {186 throw new Error(187 'VueFire: unbind failed: "' + key + '" is not bound to ' +188 'a Firebase reference.'189 )190 }191 var listeners = vm._firebaseListeners[key]192 for (var event in listeners) {193 source.off(event, listeners[event])194 }195 vm[key] = null196 vm.$firebaseRefs[key] = null197 vm._firebaseSources[key] = null198 vm._firebaseListeners[key] = null199}200/**201 * Ensure the related bookkeeping variables on an instance.202 *203 * @param {Vue} vm204 */205function ensureRefs (vm) {206 if (!vm.$firebaseRefs) {207 vm.$firebaseRefs = Object.create(null)208 vm._firebaseSources = Object.create(null)209 vm._firebaseListeners = Object.create(null)210 }211}212var init = function () {213 var bindings = this.$options.firebase214 if (typeof bindings === 'function') bindings = bindings.call(this)215 if (!bindings) return216 ensureRefs(this)217 for (var key in bindings) {218 bind(this, key, bindings[key])219 }220}221var VueFireMixin = {222 created: init, // 1.x and 2.x223 beforeDestroy: function () {224 if (!this.$firebaseRefs) return225 for (var key in this.$firebaseRefs) {226 if (this.$firebaseRefs[key]) {227 this.$unbind(key)228 }229 }230 this.$firebaseRefs = null231 this._firebaseSources = null232 this._firebaseListeners = null233 }234}235/**236 * Install function passed to Vue.use() in manual installation.237 *238 * @param {function} _Vue239 */240function install (_Vue) {241 Vue = _Vue242 Vue.mixin(VueFireMixin)243 var mergeStrats = Vue.config.optionMergeStrategies244 mergeStrats.firebase = mergeStrats.provide245 // extend instance methods246 Vue.prototype.$bindAsObject = function (key, source, cancelCallback, readyCallback) {247 ensureRefs(this)248 bind(this, key, {249 source: source,250 asObject: true,251 cancelCallback: cancelCallback,252 readyCallback: readyCallback253 })254 }255 Vue.prototype.$bindAsArray = function (key, source, cancelCallback, readyCallback) {256 ensureRefs(this)257 bind(this, key, {258 source: source,259 cancelCallback: cancelCallback,260 readyCallback: readyCallback261 })262 }263 Vue.prototype.$unbind = function (key) {264 unbind(this, key)265 }266}267// auto install268/* istanbul ignore if */269if (typeof window !== 'undefined' && window.Vue) {270 install(window.Vue)271}...

Full Screen

Full Screen

api.js

Source:api.js Github

copy

Full Screen

1/*2 * This file is part of the IoT Management Service3 * Copyright 2019 Canonical Ltd.4 *5 * This program is free software: you can redistribute it and/or modify it6 * under the terms of the GNU Affero General Public License version 3, as7 * published by the Free Software Foundation.8 *9 * This program is distributed in the hope that it will be useful, but WITHOUT10 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,11 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.12 * See the GNU Affero General Public License for more details.13 *14 * You should have received a copy of the GNU Affero General Public License15 * along with this program. If not, see <http://www.gnu.org/licenses/>.16 */17import axios from 'axios'18import constants from './constants'19var service = {20 version: (query, cancelCallback) => {21 return axios.get(constants.baseUrl + 'version');22 },23 getToken: () => {24 return axios.get(constants.baseUrl + 'token')25 },26 getAuthToken: () => {27 return axios.get(constants.baseUrl + 'authtoken')28 },29 accountsList: (query, cancelCallback) => {30 return axios.get(constants.baseUrl + 'organizations');31 },32 accountsNew: (query, cancelCallback) => {33 return axios.post(constants.baseUrl + 'organizations', query);34 },35 accountsGet: (id, cancelCallback) => {36 return axios.get(constants.baseUrl + 'organizations/' + id);37 },38 accountsUpdate: (id, query, cancelCallback) => {39 return axios.put(constants.baseUrl + 'organizations/' + id, query);40 },41 accountsForUsers: (username, cancelCallback) => {42 return axios.get(constants.baseUrl + 'users/' + username + '/organizations');43 },44 accountsUpdateForUser: (userId, accountId, cancelCallback) => {45 return axios.post(constants.baseUrl + 'users/' + userId + '/organizations/' + accountId);46 },47 groupsList: (account, cancelCallback) => {48 return axios.get(constants.baseUrl + account + '/groups');49 },50 groupsGet: (account, name, cancelCallback) => {51 return axios.get(constants.baseUrl + account + '/groups/' + name);52 },53 groupsGetDevices: (account, name, cancelCallback) => {54 return axios.get(constants.baseUrl + account + '/groups/' + name + '/devices');55 },56 groupsGetDevicesExcluded: (account, name, cancelCallback) => {57 return axios.get(constants.baseUrl + account + '/groups/' + name + '/devices/excluded');58 },59 groupsCreate: (account, name, cancelCallback) => {60 return axios.post(constants.baseUrl + account + '/groups', {orgid: account, name: name});61 },62 groupsUpdate: (account, nameFrom, nameTo, cancelCallback) => {63 return axios.put(constants.baseUrl + account + '/groups', {orgid: account, nameFrom: nameFrom, nameTo: nameTo});64 },65 groupsDeviceLink: (account, name, deviceId, cancelCallback) => {66 return axios.post(constants.baseUrl + account + '/groups/' + name + '/' + deviceId);67 },68 groupsDeviceUnlink: (account, name, deviceId, cancelCallback) => {69 return axios.delete(constants.baseUrl + account + '/groups/' + name + '/' + deviceId);70 },71 snapsList: (account, device, cancelCallback) => {72 return axios.get(constants.baseUrl + 'device/' + account + '/' + device + '/snaps');73 },74 75 snapsInstallRefresh: (account, device, cancelCallback) => {76 return axios.post(constants.baseUrl + 'snaps/' + account + '/' + device.device.deviceId + '/list');77 },78 snapsRemove: (account,device, snap, cancelCallback) => {79 return axios.delete(constants.baseUrl + 'snaps/' + account + '/' + device.device.deviceId + '/' + snap);80 },81 snapsInstall: (account, device, snap, cancelCallback) => {82 return axios.post(constants.baseUrl + 'snaps/' + account + '/' + device.device.deviceId + '/' + snap);83 },84 snapsUpdate: (account, device, snap, action, cancelCallback) => {85 return axios.put(constants.baseUrl + 'snaps/' + account + '/' + device.device.deviceId + '/' + snap + '/' + action);86 },87 snapsSettings: (account, device, snap, cancelCallback) => {88 return axios.get(constants.baseUrl + 'snaps/' + account + '/' + device.device.deviceId + '/' + snap + '/settings');89 },90 snapsSettingsUpdate: (account, device, snap, settings, cancelCallback) => {91 return axios.put(constants.baseUrl + 'snaps/' + account + '/' + device.device.deviceId + '/' + snap + '/settings', settings);92 },93 storeSearch: (snapName,cancelCallback) => {94 return axios.get(constants.baseUrl + 'store/snaps/' + snapName);95 },96 clientsList: (account, query, cancelCallback) => {97 return axios.get(constants.baseUrl + account + '/register/devices');98 },99 clientsGet: (account, device, cancelCallback) => {100 return axios.get(constants.baseUrl + account + '/register/devices/' + device);101 },102 clientsGetDownloadHREF: (account, device) => {103 return constants.baseUrl + account + '/register/devices/' + device + '/download';104 },105 clientsNew: (account, device, cancelCallback) => {106 return axios.post(constants.baseUrl + account + '/register/devices', device);107 },108 clientsDeviceObject: (account, query, cancelCallback) => {109 return axios.get(constants.baseUrl + account + '/clients/' + query + '/device');110 },111 clientsUpdate: (account, deviceId, status, deviceData, cancelCallback) => {112 return axios.put(constants.baseUrl + account + '/register/devices/' + deviceId, {status: status, deviceData: deviceData});113 },114 devicesUpdate: (account, device, cancelCallback) => {115 return axios.put(constants.baseUrl + device.accountCode + '/devices/' + device.id, device);116 },117 devicesList: (account, cancelCallback) => {118 return axios.get(constants.baseUrl + account + '/devices');119 },120 devicesGet: (account, id, cancelCallback) => {121 return axios.get(constants.baseUrl + account + '/devices/' + id);122 },123 actionsList: (account, id, cancelCallback) => {124 return axios.get(constants.baseUrl + account + '/devices/' + id + '/actions');125 },126 usersList: (query, cancelCallback) => {127 return axios.get(constants.baseUrl + 'users');128 },129 usersNew: (query, cancelCallback) => {130 return axios.post(constants.baseUrl + 'users', query);131 },132 usersGet: (username, cancelCallback) => {133 return axios.get(constants.baseUrl + 'users/' + username);134 },135 usersUpdate: (id, query, cancelCallback) => {136 return axios.put(constants.baseUrl + 'users/' + id, query);137 },138 usersDelete: (username, cancelCallback) => {139 return axios.delete(constants.baseUrl + 'users/' + username);140 }141}...

Full Screen

Full Screen

notie-js.js

Source:notie-js.js Github

copy

Full Screen

...54 time: 1.555 });56 }57 },58 cancelCallback: function cancelCallback() {59 if (options.cancelCallback && typeof window[options.cancelCallback] === 'function') {60 window[options.cancelCallback]();61 } else {62 notie.alert({63 type: 3,64 text: options.cancelMsg,65 time: 1.566 });67 }68 }69 }));70 break;71 case 'input':72 notie.input(babelHelpers.objectSpread({}, options, {73 submitCallback: function submitCallback(value) {74 if (options.submitCallback && typeof window[options.submitCallback] === 'function') {75 window[options.submitCallback](value);76 } else {77 notie.alert({78 type: 1,79 text: "you entered: ".concat(value),80 time: 1.581 });82 }83 },84 cancelCallback: function cancelCallback(value) {85 if (options.cancelCallback && typeof window[options.cancelCallback] === 'function') {86 window[options.cancelCallback](value);87 } else {88 notie.alert({89 type: 1,90 text: "You cancelled with this value: ".concat(value),91 time: 1.592 });93 }94 }95 }));96 break;97 case 'select':98 notie.select(options);...

Full Screen

Full Screen

Confirm.js

Source:Confirm.js Github

copy

Full Screen

1var alertify = require('alertifyjs');23class Confirm {45 /**6 * Construct7 * @param title8 * @param message9 * @param okCallback10 * @param cancelCallback11 */12 constructor(title, message, okCallback, cancelCallback = function(){}){13 this.title = title;14 this.message = message;15 this.okCallback = okCallback;16 this.cancelCallback = cancelCallback;17 }1819 /**20 * Show the notification21 */22 show(){23 alertify.confirm(this.title, this.message, this.okCallback, this.cancelCallback).set({transition:'zoom'});24 }2526 /**27 * Spawn a confirm window28 * @param title29 * @param message30 * @param okCallback31 * @param cancelCallback32 */33 static spawn(title, message, okCallback, cancelCallback = function(){}){34 alertify.confirm(title, message, okCallback, cancelCallback).set({transition:'zoom'});35 }3637}38 ...

Full Screen

Full Screen

spinner.js

Source:spinner.js Github

copy

Full Screen

1var exec = require('cordova/exec');2module.exports = {3 show : function(title, message, cancelCallback) {4 if (cancelCallback == true && typeof cancelCallback !== "function") {5 cancelCallback = function () {}; 6 }7 cordova.exec(cancelCallback, null, 'SpinnerDialog', 'show', [ title, message, !!cancelCallback ]);8 },9 hide : function(success, fail) {10 cordova.exec(success, fail, 'SpinnerDialog', 'hide', [ "","" ]);11 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { cancelCallback } = require('playwright/lib/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const [response] = await Promise.all([8 page.waitForResponse('**/*'),9 ]);10 cancelCallback(response);11 await page.close();12 await context.close();13 await browser.close();14})();15const { cancelCallback } = require('playwright/lib/utils/utils');16const { chromium } = require('playwright');17(async () => {18 const browser = await chromium.launch();19 const context = await browser.newContext();20 const page = await context.newPage();21 const [response] = await Promise.all([22 page.waitForResponse('**/*'),23 ]);24 cancelCallback(response);25 await page.close();26 await context.close();27 await browser.close();28})();29const { cancelCallback } = require('playwright/lib/utils/utils');30const { chromium } = require('playwright');31(async () => {32 const browser = await chromium.launch();33 const context = await browser.newContext();34 const page = await context.newPage();35 const [response] = await Promise.all([36 page.waitForResponse('**/*'),37 ]);38 cancelCallback(response);39 await page.close();40 await context.close();41 await browser.close();42})();43const { cancelCallback } = require('playwright/lib/utils/utils');44const { chromium } = require('playwright');45(async () => {46 const browser = await chromium.launch();47 const context = await browser.newContext();48 const page = await context.newPage();49 const [response] = await Promise.all([50 page.waitForResponse('**/*'),51 ]);52 cancelCallback(response);53 await page.close();54 await context.close();55 await browser.close();56})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { cancelCallback } = require('playwright/lib/server/frames');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const handle = page.on('request', () => {});8 cancelCallback(handle);9 await browser.close();10})();11const { cancelCallback } = require('playwright/lib/server/frames');12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const handle = page.on('request', () => {});18 cancelCallback(handle);19 await browser.close();20})();21const { cancelCallback } = require('playwright/lib/server/frames');22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const context = await browser.newContext();26 const page = await context.newPage();27 const handle = page.on('request', () => {});28 cancelCallback(handle);29 await browser.close();30})();31const { cancelCallback } = require('playwright/lib/server/frames');32const { chromium } = require('playwright');33(async () => {34 const browser = await chromium.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 const handle = page.on('request', () => {});38 cancelCallback(handle);39 await browser.close();40})();41const { cancelCallback } = require('playwright/lib/server/frames');42const { chromium } = require('playwright');43(async () => {44 const browser = await chromium.launch();45 const context = await browser.newContext();46 const page = await context.newPage();47 await page.goto('https

Full Screen

Using AI Code Generation

copy

Full Screen

1const { cancelCallback } = require('playwright/lib/internal/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const callback = () => {8 console.log('Hello World');9 };10 const cancel = await cancelCallback(callback, 1000);11 cancel();12 await browser.close();13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 let request = null;7 page.route('**/*', route => {8 request = route.request();9 route.continue();10 });11 await request.cancelCallback();12 await browser.close();13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { cancelCallback } = require('playwright/lib/internal/utils/stackTrace');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: `example.png` });8 await browser.close();9 cancelCallback();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { cancelCallback } = require('playwright/lib/internal/inspectorInstrumentation');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.fill('input[title="Search"]', 'playwright');7 await page.keyboard.press('Enter');8 await page.waitForNavigation();9 await page.click('text=Playwright - Node.js library to automate Chromium, Firefox and WebKit with a single API');10 await page.waitForLoadState();11 await page.click('text=Get started');12 await page.waitForLoadState();13 cancelCallback();14 await page.screenshot({ path: 'example.png' });15 await browser.close();16})();17 at Page._onLoadingFailed (C:\Users\hp\Desktop\playwright\playwright\lib\server\page.js:172:31)18 at CDPSession.Page._client.on.event (C:\Users\hp\Desktop\playwright\playwright\lib\server\page.js:98:59)19 at CDPSession.emit (events.js:315:20)20 at CDPSession._onMessage (C:\Users\hp\Desktop\playwright\playwright\lib\server\cdp.js:131:12)21 at Connection._onMessage (C:\Users\hp\Desktop\playwright\playwright\lib\server\connection.js:200:19)22 at WebSocketTransport._ws.addEventListener.event (C:\Users\hp\Desktop\playwright\playwright\lib\server\connection.js:30:24)23 at WebSocketTransport.emit (events.js:315:20)24 at WebSocketTransport._ws.onmessage (C:\Users\hp\Desktop\playwright\playwright\lib\server\webSocketTransport.js:32:10)25 at WebSocket.onMessage (C:\Users\hp\Desktop\playwright\playwright\lib\server\webSocket.js:101:22)26 at WebSocket.emit (events.js:315:20)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { cancelCallback } = require('playwright/lib/internal/cancelablePromise');2const { chromium } = require('playwright-chromium');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 let timeout = setTimeout(async () => {8 await browser.close();9 console.log('Browser closed');10 }, 10000);11 console.log('Page loaded');12 cancelCallback(timeout);13 await page.screenshot({ path: `example.png` });14 await browser.close();15})();16#### 3. Use the `page.on('close')` event17const { chromium } = require('playwright-chromium');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 page.on('close', async () => {23 await browser.close();24 console.log('Browser closed');25 });26 console.log('Page loaded');27 await page.screenshot({ path: `example.png` });28 await page.close();29})();30const { chromium } = require('playwright-chromium');31(async () => {32 const browser = await chromium.launch();33 const context = await browser.newContext();34 const page = await context.newPage();35 console.log('Page loaded');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = require('playwright');2const { BrowserContext } = require('playwright');3const browser = await Playwright.chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const controller = new AbortController();7const { signal } = controller;8controller.abort();9await browser.close();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');2const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');3const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');4const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');5const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');6const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');7const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');8const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');9const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');10const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');11const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');12const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');13const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');14const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');15const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');16const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');17const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');18const { cancelCallback } = require('playwright/lib/internal/timeoutSettings');

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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