Best JavaScript code snippet using appium
zoom-test.js
Source:zoom-test.js
...32 this.zoomDestroy();33};34ZoomTest.prototype.zoomDestroy = function() {35 if(this.zoomElement.data('zoom')) {36 this.zoomElement.zoom('destroy');37 }38};39ZoomTest.prototype.zoomCreate = function(options, element) {40 return (element || this.zoomElement).zoom(options || {} ).data('zoom');41};42ZoomTest.prototype.testInit = function() {43 this.zoomElement.zoom();44 assertTrue(this.zoomElement.is(':mage-zoom'));45};46ZoomTest.prototype.testCreate = function() {47 var zoomInstance = this.zoomCreate(),48 _setZoomData = jsunit.stub(zoomInstance, '_setZoomData'),49 _render = jsunit.stub(zoomInstance, '_render'),50 _bind = jsunit.stub(zoomInstance, '_bind'),51 _hide = jsunit.stub(zoomInstance, '_hide'),52 _largeImageLoaded = jsunit.stub(zoomInstance, '_largeImageLoaded');53 zoomInstance.largeImage = [{54 complete: false55 }];56 zoomInstance._create();57 assertTrue(_setZoomData.callCount === 1);...
mui.zoom.js
Source:mui.zoom.js
1(function($, window) {2 var CLASS_ZOOM = $.className('zoom');3 var CLASS_ZOOM_SCROLLER = $.className('zoom-scroller');4 var SELECTOR_ZOOM = '.' + CLASS_ZOOM;5 var SELECTOR_ZOOM_SCROLLER = '.' + CLASS_ZOOM_SCROLLER;6 var EVENT_PINCH_START = 'pinchstart';7 var EVENT_PINCH = 'pinch';8 var EVENT_PINCH_END = 'pinchend';9 if ('ongesturestart' in window) {10 EVENT_PINCH_START = 'gesturestart';11 EVENT_PINCH = 'gesturechange';12 EVENT_PINCH_END = 'gestureend';13 }14 $.Zoom = function(element, options) {15 var zoom = this;16 zoom.options = $.extend($.Zoom.defaults, options);17 zoom.wrapper = zoom.element = element;18 zoom.scroller = element.querySelector(SELECTOR_ZOOM_SCROLLER);19 zoom.scrollerStyle = zoom.scroller && zoom.scroller.style;20 zoom.zoomer = element.querySelector(SELECTOR_ZOOM);21 zoom.zoomerStyle = zoom.zoomer && zoom.zoomer.style;22 zoom.init = function() {23 //èªå¨å¯ç¨24 $.options.gestureConfig.pinch = true;25 $.options.gestureConfig.doubletap = true;26 zoom.initEvents();27 };28 zoom.initEvents = function(detach) {29 var action = detach ? 'removeEventListener' : 'addEventListener';30 var target = zoom.scroller;31 target[action](EVENT_PINCH_START, zoom.onPinchstart);32 target[action](EVENT_PINCH, zoom.onPinch);33 target[action](EVENT_PINCH_END, zoom.onPinchend);34 target[action]($.EVENT_START, zoom.onTouchstart);35 target[action]($.EVENT_MOVE, zoom.onTouchMove);36 target[action]($.EVENT_CANCEL, zoom.onTouchEnd);37 target[action]($.EVENT_END, zoom.onTouchEnd);38 target[action]('drag', zoom.dragEvent);39 target[action]('doubletap', zoom.doubleTapEvent);40 };41 zoom.dragEvent = function(e) {42 if (imageIsMoved || isGesturing) {43 e.stopPropagation();44 }45 };46 zoom.doubleTapEvent = function(e) {47 zoom.toggleZoom(e.detail.center);48 };49 zoom.transition = function(style, time) {50 time = time || 0;51 style['webkitTransitionDuration'] = time + 'ms';52 return zoom;53 };54 zoom.translate = function(style, x, y) {55 x = x || 0;56 y = y || 0;57 style['webkitTransform'] = 'translate3d(' + x + 'px,' + y + 'px,0px)';58 return zoom;59 };60 zoom.scale = function(style, scale) {61 scale = scale || 1;62 style['webkitTransform'] = 'translate3d(0,0,0) scale(' + scale + ')';63 return zoom;64 };65 zoom.scrollerTransition = function(time) {66 return zoom.transition(zoom.scrollerStyle, time);67 };68 zoom.scrollerTransform = function(x, y) {69 return zoom.translate(zoom.scrollerStyle, x, y);70 };71 zoom.zoomerTransition = function(time) {72 return zoom.transition(zoom.zoomerStyle, time);73 };74 zoom.zoomerTransform = function(scale) {75 return zoom.scale(zoom.zoomerStyle, scale);76 };77 // Gestures78 var scale = 1,79 currentScale = 1,80 isScaling = false,81 isGesturing = false;82 zoom.onPinchstart = function(e) {83 isGesturing = true;84 };85 zoom.onPinch = function(e) {86 if (!isScaling) {87 zoom.zoomerTransition(0);88 isScaling = true;89 }90 scale = (e.detail ? e.detail.scale : e.scale) * currentScale;91 if (scale > zoom.options.maxZoom) {92 scale = zoom.options.maxZoom - 1 + Math.pow((scale - zoom.options.maxZoom + 1), 0.5);93 }94 if (scale < zoom.options.minZoom) {95 scale = zoom.options.minZoom + 1 - Math.pow((zoom.options.minZoom - scale + 1), 0.5);96 }97 zoom.zoomerTransform(scale);98 };99 zoom.onPinchend = function(e) {100 scale = Math.max(Math.min(scale, zoom.options.maxZoom), zoom.options.minZoom);101 zoom.zoomerTransition(zoom.options.speed).zoomerTransform(scale);102 currentScale = scale;103 isScaling = false;104 };105 zoom.setZoom = function(newScale) {106 scale = currentScale = newScale;107 zoom.scrollerTransition(zoom.options.speed).scrollerTransform(0, 0);108 zoom.zoomerTransition(zoom.options.speed).zoomerTransform(scale);109 };110 zoom.toggleZoom = function(position, speed) {111 if (typeof position === 'number') {112 speed = position;113 position = undefined;114 }115 speed = typeof speed === 'undefined' ? zoom.options.speed : speed;116 if (scale && scale !== 1) {117 scale = currentScale = 1;118 zoom.scrollerTransition(speed).scrollerTransform(0, 0);119 } else {120 scale = currentScale = zoom.options.maxZoom;121 if (position) {122 var offset = $.offset(zoom.zoomer);123 var top = offset.top;124 var left = offset.left;125 var offsetX = (position.x - left) * scale;126 var offsetY = (position.y - top) * scale;127 this._cal();128 if (offsetX >= imageMaxX && offsetX <= (imageMaxX + wrapperWidth)) { //center129 offsetX = imageMaxX - offsetX + wrapperWidth / 2;130 } else if (offsetX < imageMaxX) { //left131 offsetX = imageMaxX - offsetX + wrapperWidth / 2;132 } else if (offsetX > (imageMaxX + wrapperWidth)) { //right133 offsetX = imageMaxX + wrapperWidth - offsetX - wrapperWidth / 2;134 }135 if (offsetY >= imageMaxY && offsetY <= (imageMaxY + wrapperHeight)) { //middle136 offsetY = imageMaxY - offsetY + wrapperHeight / 2;137 } else if (offsetY < imageMaxY) { //top138 offsetY = imageMaxY - offsetY + wrapperHeight / 2;139 } else if (offsetY > (imageMaxY + wrapperHeight)) { //bottom140 offsetY = imageMaxY + wrapperHeight - offsetY - wrapperHeight / 2;141 }142 offsetX = Math.min(Math.max(offsetX, imageMinX), imageMaxX);143 offsetY = Math.min(Math.max(offsetY, imageMinY), imageMaxY);144 zoom.scrollerTransition(speed).scrollerTransform(offsetX, offsetY);145 } else {146 zoom.scrollerTransition(speed).scrollerTransform(0, 0);147 }148 }149 zoom.zoomerTransition(speed).zoomerTransform(scale);150 };151 zoom._cal = function() {152 wrapperWidth = zoom.wrapper.offsetWidth;153 wrapperHeight = zoom.wrapper.offsetHeight;154 imageWidth = zoom.zoomer.offsetWidth;155 imageHeight = zoom.zoomer.offsetHeight;156 var scaledWidth = imageWidth * scale;157 var scaledHeight = imageHeight * scale;158 imageMinX = Math.min((wrapperWidth / 2 - scaledWidth / 2), 0);159 imageMaxX = -imageMinX;160 imageMinY = Math.min((wrapperHeight / 2 - scaledHeight / 2), 0);161 imageMaxY = -imageMinY;162 };163 var wrapperWidth, wrapperHeight, imageIsTouched, imageIsMoved, imageCurrentX, imageCurrentY, imageMinX, imageMinY, imageMaxX, imageMaxY, imageWidth, imageHeight, imageTouchesStart = {},164 imageTouchesCurrent = {},165 imageStartX, imageStartY, velocityPrevPositionX, velocityPrevTime, velocityX, velocityPrevPositionY, velocityY;166 zoom.onTouchstart = function(e) {167 e.preventDefault();168 imageIsTouched = true;169 imageTouchesStart.x = e.type === $.EVENT_START ? e.targetTouches[0].pageX : e.pageX;170 imageTouchesStart.y = e.type === $.EVENT_START ? e.targetTouches[0].pageY : e.pageY;171 };172 zoom.onTouchMove = function(e) {173 e.preventDefault();174 if (!imageIsTouched) return;175 if (!imageIsMoved) {176 wrapperWidth = zoom.wrapper.offsetWidth;177 wrapperHeight = zoom.wrapper.offsetHeight;178 imageWidth = zoom.zoomer.offsetWidth;179 imageHeight = zoom.zoomer.offsetHeight;180 var translate = $.parseTranslateMatrix($.getStyles(zoom.scroller, 'webkitTransform'));181 imageStartX = translate.x || 0;182 imageStartY = translate.y || 0;183 zoom.scrollerTransition(0);184 }185 var scaledWidth = imageWidth * scale;186 var scaledHeight = imageHeight * scale;187 if (scaledWidth < wrapperWidth && scaledHeight < wrapperHeight) return;188 imageMinX = Math.min((wrapperWidth / 2 - scaledWidth / 2), 0);189 imageMaxX = -imageMinX;190 imageMinY = Math.min((wrapperHeight / 2 - scaledHeight / 2), 0);191 imageMaxY = -imageMinY;192 imageTouchesCurrent.x = e.type === $.EVENT_MOVE ? e.targetTouches[0].pageX : e.pageX;193 imageTouchesCurrent.y = e.type === $.EVENT_MOVE ? e.targetTouches[0].pageY : e.pageY;194 if (!imageIsMoved && !isScaling) {195 // if (Math.abs(imageTouchesCurrent.y - imageTouchesStart.y) < Math.abs(imageTouchesCurrent.x - imageTouchesStart.x)) {196 //TODO æ¤å¤éè¦ä¼åï¼å½éå°é¿å¾ï¼éè¦ä¸ä¸æ»å¨æ¶ï¼ä¸åå¤æä¼å¯¼è´æ»å¨ä¸æµç
197 if (198 (Math.floor(imageMinX) === Math.floor(imageStartX) && imageTouchesCurrent.x < imageTouchesStart.x) ||199 (Math.floor(imageMaxX) === Math.floor(imageStartX) && imageTouchesCurrent.x > imageTouchesStart.x)200 ) {201 imageIsTouched = false;202 return;203 }204 // }205 }206 imageIsMoved = true;207 imageCurrentX = imageTouchesCurrent.x - imageTouchesStart.x + imageStartX;208 imageCurrentY = imageTouchesCurrent.y - imageTouchesStart.y + imageStartY;209 if (imageCurrentX < imageMinX) {210 imageCurrentX = imageMinX + 1 - Math.pow((imageMinX - imageCurrentX + 1), 0.8);211 }212 if (imageCurrentX > imageMaxX) {213 imageCurrentX = imageMaxX - 1 + Math.pow((imageCurrentX - imageMaxX + 1), 0.8);214 }215 if (imageCurrentY < imageMinY) {216 imageCurrentY = imageMinY + 1 - Math.pow((imageMinY - imageCurrentY + 1), 0.8);217 }218 if (imageCurrentY > imageMaxY) {219 imageCurrentY = imageMaxY - 1 + Math.pow((imageCurrentY - imageMaxY + 1), 0.8);220 }221 //Velocity222 if (!velocityPrevPositionX) velocityPrevPositionX = imageTouchesCurrent.x;223 if (!velocityPrevPositionY) velocityPrevPositionY = imageTouchesCurrent.y;224 if (!velocityPrevTime) velocityPrevTime = $.now();225 velocityX = (imageTouchesCurrent.x - velocityPrevPositionX) / ($.now() - velocityPrevTime) / 2;226 velocityY = (imageTouchesCurrent.y - velocityPrevPositionY) / ($.now() - velocityPrevTime) / 2;227 if (Math.abs(imageTouchesCurrent.x - velocityPrevPositionX) < 2) velocityX = 0;228 if (Math.abs(imageTouchesCurrent.y - velocityPrevPositionY) < 2) velocityY = 0;229 velocityPrevPositionX = imageTouchesCurrent.x;230 velocityPrevPositionY = imageTouchesCurrent.y;231 velocityPrevTime = $.now();232 zoom.scrollerTransform(imageCurrentX, imageCurrentY);233 };234 zoom.onTouchEnd = function(e) {235 if (!e.touches.length) {236 isGesturing = false;237 }238 if (!imageIsTouched || !imageIsMoved) {239 imageIsTouched = false;240 imageIsMoved = false;241 return;242 }243 imageIsTouched = false;244 imageIsMoved = false;245 var momentumDurationX = 300;246 var momentumDurationY = 300;247 var momentumDistanceX = velocityX * momentumDurationX;248 var newPositionX = imageCurrentX + momentumDistanceX;249 var momentumDistanceY = velocityY * momentumDurationY;250 var newPositionY = imageCurrentY + momentumDistanceY;251 if (velocityX !== 0) momentumDurationX = Math.abs((newPositionX - imageCurrentX) / velocityX);252 if (velocityY !== 0) momentumDurationY = Math.abs((newPositionY - imageCurrentY) / velocityY);253 var momentumDuration = Math.max(momentumDurationX, momentumDurationY);254 imageCurrentX = newPositionX;255 imageCurrentY = newPositionY;256 var scaledWidth = imageWidth * scale;257 var scaledHeight = imageHeight * scale;258 imageMinX = Math.min((wrapperWidth / 2 - scaledWidth / 2), 0);259 imageMaxX = -imageMinX;260 imageMinY = Math.min((wrapperHeight / 2 - scaledHeight / 2), 0);261 imageMaxY = -imageMinY;262 imageCurrentX = Math.max(Math.min(imageCurrentX, imageMaxX), imageMinX);263 imageCurrentY = Math.max(Math.min(imageCurrentY, imageMaxY), imageMinY);264 zoom.scrollerTransition(momentumDuration).scrollerTransform(imageCurrentX, imageCurrentY);265 };266 zoom.destroy = function() {267 zoom.initEvents(true); //detach268 delete $.data[zoom.wrapper.getAttribute('data-zoomer')];269 zoom.wrapper.setAttribute('data-zoomer', '');270 }271 zoom.init();272 return zoom;273 };274 $.Zoom.defaults = {275 speed: 300,276 maxZoom: 3,277 minZoom: 1,278 };279 $.fn.zoom = function(options) {280 var zoomApis = [];281 this.each(function() {282 var zoomApi = null;283 var self = this;284 var id = self.getAttribute('data-zoomer');285 if (!id) {286 id = ++$.uuid;287 $.data[id] = zoomApi = new $.Zoom(self, options);288 self.setAttribute('data-zoomer', id);289 } else {290 zoomApi = $.data[id];291 }292 zoomApis.push(zoomApi);293 });294 return zoomApis.length === 1 ? zoomApis[0] : zoomApis;295 };...
c3ext.js
Source:c3ext.js
1var c3ext = {};2c3ext.generate = function (options) {3 if (options.zoom2 != null) {4 zoom2_reducers = options.zoom2.reducers || {};5 zoom2_enabled = options.zoom2.enabled;6 _zoom2_factor = options.zoom2.factor || 1;7 _zoom2_maxItems = options.zoom2.maxItems;8 }9 if (!zoom2_enabled) {10 return c3.generate(options);11 }12 var originalData = Q.copy(options.data);13 var zoom2_reducers;14 var zoom2_enabled;15 var _zoom2_maxItems;16 if (_zoom2_maxItems == null) {17 var el = d3.select(options.bindto)[0][0];18 if (el != null) {19 var availWidth = el.clientWidth;20 var pointSize = 20;21 _zoom2_maxItems = Math.ceil(availWidth / pointSize);22 }23 if (_zoom2_maxItems == null || _zoom2_maxItems < 10) {24 _zoom2_maxItems = 10;25 }26 }27 function onZoomChanged(e) {28 refresh();29 }30 var zoom2 = c3ext.ZoomBehavior({ changed: onZoomChanged, bindto: options.bindto });31 zoom2.enhance = function () {32 _zoom2_maxItems *= 2;33 var totalItems = zoom2.getZoom().totalItems;34 if (_zoom2_maxItems > totalItems)35 _zoom2_maxItems = totalItems;36 refresh();37 }38 zoom2.dehance = function () {39 _zoom2_maxItems = Math.ceil(_zoom2_maxItems / 2) + 1;40 refresh();41 }42 zoom2.maxItems = function () { return _zoom2_maxItems; };43 function zoomAndReduceData(list, zoomRange, func, maxItems) {44 //var maxItems = 10;//Math.ceil(10 * zoomFactor);45 var list2 = list.slice(zoomRange[0], zoomRange[1]);46 var chunkSize = 1;47 var list3 = list2;48 if (list3.length > maxItems) {49 var chunkSize = Math.ceil(list2.length / maxItems);50 list3 = list3.splitIntoChunksOf(chunkSize).map(func);51 }52 //console.log("x" + getCurrentZoomLevel() + ", maxItems=" + maxItems + " chunkSize=" + chunkSize + " totalBefore=" + list2.length + ", totalAfter=" + list3.length);53 return list3;54 }55 function first(t) { return t[0]; }56 var getDataForZoom = function (data) {57 if (data.columns == null || data.columns.length == 0)58 return;59 var zoomInfo = zoom2.getZoom();60 if (zoomInfo.totalItems != data.columns[0].length - 1) {61 zoom2.setOptions({ totalItems: data.columns[0].length - 1 });62 zoomInfo = zoom2.getZoom();63 }64 data.columns = originalData.columns.map(function (column) {65 var name = column[0];66 var reducer = zoom2_reducers[name] || first; //by default take the first67 var values = column.slice(1);68 var newValues = zoomAndReduceData(values, zoomInfo.currentZoom, reducer, _zoom2_maxItems);69 return [name].concat(newValues);70 });71 return data;72 };73 getDataForZoom(options.data);74 var chart = c3.generate(options);75 var _chart_load_org = chart.load.bind(chart);76 chart.zoom2 = zoom2;77 chart.load = function (data) {78 if (data.unload) {79 unload(data.unload);80 delete data.unload;81 }82 Q.copy(data, originalData);83 refresh();84 }85 chart.unload = function (names) {86 unload(names);87 refresh();88 }89 function unload(names) {90 originalData.columns.removeAll(function (t) { names.contains(t); });91 }92 function refresh() {93 var data = Q.copy(originalData)94 getDataForZoom(data);95 _chart_load_org(data);96 };97 return chart;98}99c3ext.ZoomBehavior = function (options) {100 var zoom = { __type: "ZoomBehavior" };101 var _zoom2_factor;102 var _left;103 var totalItems;104 var currentZoom;105 var bindto = options.bindto;106 var _zoomChanged = options.changed || function () { };107 var element;108 var mousewheelTimer;109 var deltaY = 0;110 var leftRatio = 0;111 zoom.setOptions = function (options) {112 if (options == null)113 options = {};114 _zoom2_factor = options.factor || 1;115 _left = 0;116 totalItems = options.totalItems || 0;117 currentZoom = [0, totalItems];118 _zoomChanged = options.changed || _zoomChanged;119 }120 zoom.setOptions(options);121 function verifyZoom(newZoom) {122 //newZoom.sort();123 if (newZoom[1] > totalItems) {124 var diff = newZoom[1] - totalItems;125 newZoom[0] -= diff;126 newZoom[1] -= diff;127 }128 if (newZoom[0] < 0) {129 var diff = newZoom[0] * -1;130 newZoom[0] += diff;131 newZoom[1] += diff;132 }133 if (newZoom[1] > totalItems)134 newZoom[1] = totalItems;135 if (newZoom[0] < 0)136 newZoom[0] = 0;137 }138 function zoomAndPan(zoomFactor, left) {139 var itemsToShow = Math.ceil(totalItems / zoomFactor);140 var newZoom = [left, left + itemsToShow];141 verifyZoom(newZoom);142 currentZoom = newZoom;143 onZoomChanged();144 }145 function onZoomChanged() {146 if (_zoomChanged != null)147 _zoomChanged(zoom.getZoom());148 }149 function applyZoomAndPan() {150 zoomAndPan(_zoom2_factor, _left);151 }152 function getItemsToShow() {153 var itemsToShow = Math.ceil(totalItems / _zoom2_factor);154 return itemsToShow;155 }156 zoom.getZoom = function () {157 return { totalItems: totalItems, currentZoom: currentZoom.slice() };158 }159 zoom.factor = function (factor, skipDraw) {160 if (arguments.length == 0)161 return _zoom2_factor;162 _zoom2_factor = factor;163 if (_zoom2_factor < 1)164 _zoom2_factor = 1;165 if (skipDraw)166 return;167 applyZoomAndPan();168 }169 zoom.left = function (left, skipDraw) {170 if (arguments.length == 0)171 return _left;172 _left = left;173 if (_left < 0)174 _left = 0;175 var pageSize = getItemsToShow();176 //_left += pageSize;177 if (_left + pageSize > totalItems)178 _left = totalItems - pageSize;179 console.log({ left: _left, pageSize: pageSize });180 if (skipDraw)181 return;182 applyZoomAndPan();183 }184 zoom.zoomAndPanByRatio = function (zoomRatio, panRatio) {185 var pageSize = getItemsToShow();186 var leftOffset = Math.round(pageSize * panRatio);187 var mouseLeft = _left + leftOffset;188 zoom.factor(zoom.factor() * zoomRatio, true);189 var finalLeft = mouseLeft;190 if (zoomRatio != 1) {191 var pageSize2 = getItemsToShow();192 var leftOffset2 = Math.round(pageSize2 * panRatio);193 finalLeft = mouseLeft - leftOffset2;194 }195 zoom.left(finalLeft, true);196 applyZoomAndPan();197 }198 zoom.zoomIn = function () {199 zoom.zoomAndPanByRatio(2, 0);200 }201 zoom.zoomOut = function () {202 zoom.zoomAndPanByRatio(0.5, 0);203 }204 zoom.panLeft = function () {205 zoom.zoomAndPanByRatio(1, -1);206 }207 zoom.panRight = function () {208 zoom.zoomAndPanByRatio(1, 1);209 }210 zoom.reset = function () {211 _left = 0;212 _zoom2_factor = 1;213 applyZoomAndPan();214 }215 function doZoom() {216 if (deltaY != 0) {217 var maxDelta = 10;218 var multiply = (maxDelta + deltaY) / maxDelta;219 //var factor = chart.zoom2.factor()*multiply;220 //factor= Math.ceil(factor*100) / 100;221 console.log({ deltaY: deltaY, multiply: multiply });222 zoom.zoomAndPanByRatio(multiply, leftRatio);//0.5);//leftRatio);223 deltaY = 0;224 }225 }226 function element_mousewheel(e) {227 deltaY += e.deltaY;228 leftRatio = (e.offsetX - 70) / (e.currentTarget.offsetWidth - 70);229 //console.log({ "e.offsetX": e.offsetX, "e.currentTarget.offsetWidth": e.currentTarget.offsetWidth, leftRatio: leftRatio });230 mousewheelTimer.set(150);231 e.preventDefault();232 }233 if (bindto != null) {234 element = $(options.bindto);235 if (element.mousewheel) {236 mousewheelTimer = new Timer(doZoom);237 element.mousewheel(element_mousewheel);238 }239 }240 return zoom;241}242if (typeof (Q) == "undefined") {243 var Q = function () {244 };245 Q.copy = function (src, target, options, depth) {246 ///<summary>Copies an object into a target object, recursively cloning any object or array in the way, overwrite=true will overwrite a primitive field value even if exists</summary>247 ///<param name="src" />248 ///<param name="target" />249 ///<param name="options" type="Object">{ overwrite:false }</param>250 ///<returns type="Object">The copied object</returns>251 if (depth == null)252 depth = 0;253 if (depth == 100) {254 console.warn("Q.copy is in depth of 100 - possible circular reference")255 }256 options = options || { overwrite: false };257 if (src == target || src == null)258 return target;259 if (typeof (src) != "object") {260 if (options.overwrite || target == null)261 return src;262 return target;263 }264 if (typeof (src.clone) == "function") {265 if (options.overwrite || target == null)266 return src.clone();267 return target;268 }269 if (target == null) {270 if (src instanceof Array)271 target = [];272 else273 target = {};274 }275 if (src instanceof Array) {276 for (var i = 0; i < src.length; i++) {277 var item = src[i];278 var item2 = target[i];279 item2 = Q.copy(item, item2, options, depth + 1);280 target[i] = item2;281 }282 target.splice(src.length, target.length - src.length);283 return target;284 }285 for (var p in src) {286 var value = src[p];287 var value2 = target[p];288 value2 = Q.copy(value, value2, options, depth + 1);289 target[p] = value2;290 }291 return target;292 }293}294if (typeof (Timer) == "undefined") {295 var Timer = function (action, ms) {296 this.action = action;297 if (ms != null)298 this.set(ms);299 }300 Timer.prototype.set = function (ms) {301 if (ms == null)302 ms = this._ms;303 else304 this._ms = ms;305 this.clear();306 if (ms == null)307 return;308 this.timeout = window.setTimeout(this.onTick.bind(this), ms);309 }310 Timer.prototype.onTick = function () {311 this.clear();312 this.action();313 }314 Timer.prototype.clear = function (ms) {315 if (this.timeout == null)316 return;317 window.clearTimeout(this.timeout);318 this.timeout = null;319 }320}321if (typeof(Array.prototype.splitIntoChunksOf)=="undefined") {322 Array.prototype.splitIntoChunksOf = function (countInEachChunk) {323 var chunks = Math.ceil(this.length / countInEachChunk);324 var list = [];325 for (var i = 0; i < this.length; i += countInEachChunk) {326 list.push(this.slice(i, i + countInEachChunk));327 }328 return list;329 }...
zoom_manager.js
Source:zoom_manager.js
1// Copyright 2015 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4import {NativeEventTarget as EventTarget} from 'chrome://resources/js/cr/event_target.m.js';5import {BrowserApi} from './browser_api.js';6// Abstract parent of classes that manage updating the browser with zoom changes7// and/or updating the viewer's zoom when the browser zoom changes.8export class ZoomManager {9 /**10 * @param {function():number} getViewportZoom Callback to get the viewport's11 * current zoom level.12 * @param {number} initialZoom The initial browser zoom level.13 */14 constructor(getViewportZoom, initialZoom) {15 if (this.constructor === ZoomManager) {16 throw new TypeError('Instantiated abstract class: ZoomManager');17 }18 /** @private {number} */19 this.browserZoom_ = initialZoom;20 /** @private {function():number} */21 this.getViewportZoom_ = getViewportZoom;22 /** @private {!EventTarget} */23 this.eventTarget_ = new EventTarget();24 }25 /** @return {!EventTarget} */26 getEventTarget() {27 return this.eventTarget_;28 }29 /**30 * Creates the appropriate kind of zoom manager given the zoom behavior.31 * @param {BrowserApi.ZoomBehavior} zoomBehavior How to manage zoom.32 * @param {function():number} getViewportZoom A function that gets the current33 * viewport zoom.34 * @param {function(number):Promise} setBrowserZoomFunction A function that35 * sets the browser zoom to the provided value.36 * @param {number} initialZoom The initial browser zoom level.37 */38 static create(39 zoomBehavior, getViewportZoom, setBrowserZoomFunction, initialZoom) {40 switch (zoomBehavior) {41 case BrowserApi.ZoomBehavior.MANAGE:42 return new ActiveZoomManager(43 getViewportZoom, setBrowserZoomFunction, initialZoom);44 case BrowserApi.ZoomBehavior.PROPAGATE_PARENT:45 return new EmbeddedZoomManager(getViewportZoom, initialZoom);46 default:47 return new InactiveZoomManager(getViewportZoom, initialZoom);48 }49 }50 /**51 * Invoked when a browser-initiated zoom-level change occurs.52 * @param {number} newZoom the zoom level to zoom to.53 */54 onBrowserZoomChange(newZoom) {}55 /** Invoked when an extension-initiated zoom-level change occurs. */56 onPdfZoomChange() {}57 /**58 * Combines the internal pdf zoom and the browser zoom to59 * produce the total zoom level for the viewer.60 * @param {number} internalZoom the zoom level internal to the viewer.61 * @return {number} the total zoom level.62 */63 applyBrowserZoom(internalZoom) {64 return this.browserZoom_ * internalZoom;65 }66 /**67 * Given a zoom level, return the internal zoom level needed to68 * produce that zoom level.69 * @param {number} totalZoom the total zoom level.70 * @return {number} the zoom level internal to the viewer.71 */72 internalZoomComponent(totalZoom) {73 return totalZoom / this.browserZoom_;74 }75 /**76 * Returns whether two numbers are approximately equal.77 * @param {number} a The first number.78 * @param {number} b The second number.79 */80 floatingPointEquals(a, b) {81 const MIN_ZOOM_DELTA = 0.01;82 // If the zoom level is close enough to the current zoom level, don't83 // change it. This avoids us getting into an infinite loop of zoom changes84 // due to floating point error.85 return Math.abs(a - b) <= MIN_ZOOM_DELTA;86 }87}88// Has no control over the browser's zoom and does not respond to browser zoom89// changes.90export class InactiveZoomManager extends ZoomManager {}91// ActiveZoomManager controls the browser's zoom.92class ActiveZoomManager extends ZoomManager {93 /**94 * Constructs a ActiveZoomManager.95 * @param {function():number} getViewportZoom A function that gets the current96 * viewport zoom level97 * @param {function(number):Promise} setBrowserZoomFunction A function that98 * sets the browser zoom to the provided value.99 * @param {number} initialZoom The initial browser zoom level.100 */101 constructor(getViewportZoom, setBrowserZoomFunction, initialZoom) {102 super(getViewportZoom, initialZoom);103 /** @private {function(number):Promise} */104 this.setBrowserZoomFunction_ = setBrowserZoomFunction;105 /** @private {?Promise} */106 this.changingBrowserZoom_ = null;107 }108 /**109 * Invoked when a browser-initiated zoom-level change occurs.110 * @param {number} newZoom the zoom level to zoom to.111 */112 onBrowserZoomChange(newZoom) {113 // If we are changing the browser zoom level, ignore any browser zoom level114 // change events. Either, the change occurred before our update and will be115 // overwritten, or the change being reported is the change we are making,116 // which we have already handled.117 if (this.changingBrowserZoom_) {118 return;119 }120 if (this.floatingPointEquals(this.browserZoom_, newZoom)) {121 return;122 }123 this.browserZoom_ = newZoom;124 this.eventTarget_.dispatchEvent(125 new CustomEvent('set-zoom', {detail: newZoom}));126 }127 /**128 * Invoked when an extension-initiated zoom-level change occurs.129 * @override130 */131 onPdfZoomChange() {132 // If we are already changing the browser zoom level in response to a133 // previous extension-initiated zoom-level change, ignore this zoom change.134 // Once the browser zoom level is changed, we check whether the extension's135 // zoom level matches the most recently sent zoom level.136 if (this.changingBrowserZoom_) {137 return;138 }139 const viewportZoom = this.getViewportZoom_();140 if (this.floatingPointEquals(this.browserZoom_, viewportZoom)) {141 return;142 }143 this.changingBrowserZoom_ =144 this.setBrowserZoomFunction_(viewportZoom).then(() => {145 this.browserZoom_ = viewportZoom;146 this.changingBrowserZoom_ = null;147 // The extension's zoom level may have changed while the browser zoom148 // change was in progress. We call back into onPdfZoomChange to ensure149 // the browser zoom is up to date.150 this.onPdfZoomChange();151 });152 }153 /**154 * Combines the internal pdf zoom and the browser zoom to155 * produce the total zoom level for the viewer.156 * @param {number} internalZoom the zoom level internal to the viewer.157 * @return {number} the total zoom level.158 */159 applyBrowserZoom(internalZoom) {160 // The internal zoom and browser zoom are changed together, so the161 // browser zoom is already applied.162 return internalZoom;163 }164 /**165 * Given a zoom level, return the internal zoom level needed to166 * produce that zoom level.167 * @param {number} totalZoom the total zoom level.168 * @return {number} the zoom level internal to the viewer.169 */170 internalZoomComponent(totalZoom) {171 // The internal zoom and browser zoom are changed together, so the172 // internal zoom is the total zoom.173 return totalZoom;174 }175}176// Responds to changes in the browser zoom, but does not control the browser177// zoom.178class EmbeddedZoomManager extends ZoomManager {179 /**180 * Invoked when a browser-initiated zoom-level change occurs.181 * @param {number} newZoom the new browser zoom level.182 */183 onBrowserZoomChange(newZoom) {184 const oldZoom = this.browserZoom_;185 this.browserZoom_ = newZoom;186 this.eventTarget_.dispatchEvent(187 new CustomEvent('update-zoom-from-browser', {detail: oldZoom}));188 }...
browser_api.js
Source:browser_api.js
1// Copyright 2015 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4import {assert} from 'chrome://resources/js/assert.m.js';5/**6 * @param {!Object} streamInfo The stream object pointing to the data contained7 * in the PDF.8 * @return {Promise<number>} A promise that will resolve to the default zoom9 * factor.10 */11function lookupDefaultZoom(streamInfo) {12 // Webviews don't run in tabs so |streamInfo.tabId| is -1 when running within13 // a webview.14 if (!chrome.tabs || streamInfo.tabId < 0) {15 return Promise.resolve(1);16 }17 return new Promise(function(resolve, reject) {18 chrome.tabs.getZoomSettings(streamInfo.tabId, function(zoomSettings) {19 resolve(zoomSettings.defaultZoomFactor);20 });21 });22}23/**24 * Returns a promise that will resolve to the initial zoom factor25 * upon starting the plugin. This may differ from the default zoom26 * if, for example, the page is zoomed before the plugin is run.27 * @param {!Object} streamInfo The stream object pointing to the data contained28 * in the PDF.29 * @return {Promise<number>} A promise that will resolve to the initial zoom30 * factor.31 */32function lookupInitialZoom(streamInfo) {33 // Webviews don't run in tabs so |streamInfo.tabId| is -1 when running within34 // a webview.35 if (!chrome.tabs || streamInfo.tabId < 0) {36 return Promise.resolve(1);37 }38 return new Promise(function(resolve, reject) {39 chrome.tabs.getZoom(streamInfo.tabId, resolve);40 });41}42// A class providing an interface to the browser.43export class BrowserApi {44 /**45 * @param {!Object} streamInfo The stream object which points to the data46 * contained in the PDF.47 * @param {number} defaultZoom The default browser zoom.48 * @param {number} initialZoom The initial browser zoom49 * upon starting the plugin.50 * @param {BrowserApi.ZoomBehavior} zoomBehavior How to manage zoom.51 */52 constructor(streamInfo, defaultZoom, initialZoom, zoomBehavior) {53 this.streamInfo_ = streamInfo;54 this.defaultZoom_ = defaultZoom;55 this.initialZoom_ = initialZoom;56 this.zoomBehavior_ = zoomBehavior;57 }58 /**59 * @param {!Object} streamInfo The stream object pointing to the data60 * contained in the PDF.61 * @param {BrowserApi.ZoomBehavior} zoomBehavior How to manage zoom.62 * @return {Promise<BrowserApi>} A promise to a BrowserApi.63 */64 static create(streamInfo, zoomBehavior) {65 return Promise66 .all([lookupDefaultZoom(streamInfo), lookupInitialZoom(streamInfo)])67 .then(function(zoomFactors) {68 return new BrowserApi(69 streamInfo, zoomFactors[0], zoomFactors[1], zoomBehavior);70 });71 }72 /**73 * @return {Object} The stream info object pointing to the data contained in74 * the PDF.75 */76 getStreamInfo() {77 return this.streamInfo_;78 }79 /**80 * Sets the browser zoom.81 * @param {number} zoom The zoom factor to send to the browser.82 * @return {Promise} A promise that will be resolved when the browser zoom83 * has been updated.84 */85 setZoom(zoom) {86 assert(87 this.zoomBehavior_ === BrowserApi.ZoomBehavior.MANAGE,88 'Viewer does not manage browser zoom.');89 return new Promise((resolve, reject) => {90 chrome.tabs.setZoom(this.streamInfo_.tabId, zoom, resolve);91 });92 }93 /** @return {number} The default browser zoom factor. */94 getDefaultZoom() {95 return this.defaultZoom_;96 }97 /** @return {number} The initial browser zoom factor. */98 getInitialZoom() {99 return this.initialZoom_;100 }101 /** @return {BrowserApi.ZoomBehavior} How to manage zoom. */102 getZoomBehavior() {103 return this.zoomBehavior_;104 }105 /**106 * Adds an event listener to be notified when the browser zoom changes.107 *108 * @param {!Function} listener The listener to be called with the new zoom109 * factor.110 */111 addZoomEventListener(listener) {112 if (!(this.zoomBehavior_ === BrowserApi.ZoomBehavior.MANAGE ||113 this.zoomBehavior_ === BrowserApi.ZoomBehavior.PROPAGATE_PARENT)) {114 return;115 }116 chrome.tabs.onZoomChange.addListener(info => {117 const zoomChangeInfo =118 /** @type {{tabId: number, newZoomFactor: number}} */ (info);119 if (zoomChangeInfo.tabId !== this.streamInfo_.tabId) {120 return;121 }122 listener(zoomChangeInfo.newZoomFactor);123 });124 }125}126/**127 * Enumeration of ways to manage zoom changes.128 * @enum {number}129 */130BrowserApi.ZoomBehavior = {131 NONE: 0,132 MANAGE: 1,133 PROPAGATE_PARENT: 2134};135/**136 * Creates a BrowserApi for an extension running as a mime handler.137 * @return {!Promise<!BrowserApi>} A promise to a BrowserApi instance138 * constructed using the mimeHandlerPrivate API.139 */140function createBrowserApiForMimeHandlerView() {141 return new Promise(function(resolve, reject) {142 chrome.mimeHandlerPrivate.getStreamInfo(resolve);143 })144 .then(function(streamInfo) {145 const promises = [];146 let zoomBehavior = BrowserApi.ZoomBehavior.NONE;147 if (streamInfo.tabId !== -1) {148 zoomBehavior = streamInfo.embedded ?149 BrowserApi.ZoomBehavior.PROPAGATE_PARENT :150 BrowserApi.ZoomBehavior.MANAGE;151 promises.push(new Promise(function(resolve) {152 chrome.tabs.get(streamInfo.tabId, resolve);153 }).then(function(tab) {154 if (tab) {155 streamInfo.tabUrl = tab.url;156 }157 }));158 }159 if (zoomBehavior === BrowserApi.ZoomBehavior.MANAGE) {160 promises.push(new Promise(function(resolve) {161 chrome.tabs.setZoomSettings(162 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve);163 }));164 }165 return Promise.all(promises).then(function() {166 return BrowserApi.create(streamInfo, zoomBehavior);167 });168 });169}170/**171 * Creates a BrowserApi instance for an extension not running as a mime handler.172 * @return {!Promise<!BrowserApi>} A promise to a BrowserApi instance173 * constructed from the URL.174 */175function createBrowserApiForPrintPreview() {176 const url = window.location.search.substring(1);177 const streamInfo = {178 streamUrl: url,179 originalUrl: url,180 responseHeaders: {},181 embedded: window.parent !== window,182 tabId: -1,183 };184 return new Promise(function(resolve, reject) {185 if (!chrome.tabs) {186 resolve();187 return;188 }189 chrome.tabs.getCurrent(function(tab) {190 streamInfo.tabId = tab.id;191 streamInfo.tabUrl = tab.url;192 resolve();193 });194 })195 .then(function() {196 return BrowserApi.create(streamInfo, BrowserApi.ZoomBehavior.NONE);197 });198}199/**200 * @return {!Promise<!BrowserApi>} A promise to a BrowserApi instance for the201 * current environment.202 */203export function createBrowserApi() {204 if (location.origin === 'chrome://print') {205 return createBrowserApiForPrintPreview();206 }207 return createBrowserApiForMimeHandlerView();...
Zoom.js
Source:Zoom.js
1/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for2 * full list of contributors). Published under the 2-clause BSD license.3 * See license.txt in the OpenLayers distribution or repository for the4 * full text of the license. */5/**6 * @requires OpenLayers/Control.js7 * @requires OpenLayers/Events/buttonclick.js8 */9/**10 * Class: OpenLayers.Control.Zoom11 * The Zoom control is a pair of +/- links for zooming in and out.12 *13 * Inherits from:14 * - <OpenLayers.Control>15 */16OpenLayers.Control.Zoom = OpenLayers.Class(OpenLayers.Control, {17 18 /**19 * APIProperty: zoomInText20 * {String}21 * Text for zoom-in link. Default is "+".22 */23 zoomInText: "+",24 /**25 * APIProperty: zoomInId26 * {String}27 * Instead of having the control create a zoom in link, you can provide 28 * the identifier for an anchor element already added to the document.29 * By default, an element with id "olZoomInLink" will be searched for30 * and used if it exists.31 */32 zoomInId: "olZoomInLink",33 /**34 * APIProperty: zoomOutText35 * {String}36 * Text for zoom-out link. Default is "\u2212".37 */38 zoomOutText: "\u2212",39 /**40 * APIProperty: zoomOutId41 * {String}42 * Instead of having the control create a zoom out link, you can provide 43 * the identifier for an anchor element already added to the document.44 * By default, an element with id "olZoomOutLink" will be searched for45 * and used if it exists.46 */47 zoomOutId: "olZoomOutLink",48 /**49 * Method: draw50 *51 * Returns:52 * {DOMElement} A reference to the DOMElement containing the zoom links.53 */54 draw: function() {55 var div = OpenLayers.Control.prototype.draw.apply(this),56 links = this.getOrCreateLinks(div),57 zoomIn = links.zoomIn,58 zoomOut = links.zoomOut,59 eventsInstance = this.map.events;60 61 if (zoomOut.parentNode !== div) {62 eventsInstance = this.events;63 eventsInstance.attachToElement(zoomOut.parentNode);64 }65 eventsInstance.register("buttonclick", this, this.onZoomClick);66 67 this.zoomInLink = zoomIn;68 this.zoomOutLink = zoomOut;69 return div;70 },71 72 /**73 * Method: getOrCreateLinks74 * 75 * Parameters:76 * el - {DOMElement}77 *78 * Return: 79 * {Object} Object with zoomIn and zoomOut properties referencing links.80 */81 getOrCreateLinks: function(el) {82 var zoomIn = document.getElementById(this.zoomInId),83 zoomOut = document.getElementById(this.zoomOutId);84 if (!zoomIn) {85 zoomIn = document.createElement("a");86 zoomIn.href = "#zoomIn";87 zoomIn.appendChild(document.createTextNode(this.zoomInText));88 zoomIn.className = "olControlZoomIn";89 el.appendChild(zoomIn);90 }91 OpenLayers.Element.addClass(zoomIn, "olButton");92 if (!zoomOut) {93 zoomOut = document.createElement("a");94 zoomOut.href = "#zoomOut";95 zoomOut.appendChild(document.createTextNode(this.zoomOutText));96 zoomOut.className = "olControlZoomOut";97 el.appendChild(zoomOut);98 }99 OpenLayers.Element.addClass(zoomOut, "olButton");100 return {101 zoomIn: zoomIn, zoomOut: zoomOut102 };103 },104 105 /**106 * Method: onZoomClick107 * Called when zoomin/out link is clicked.108 */109 onZoomClick: function(evt) {110 var button = evt.buttonElement;111 if (button === this.zoomInLink) {112 this.map.zoomIn();113 } else if (button === this.zoomOutLink) {114 this.map.zoomOut();115 }116 },117 /** 118 * Method: destroy119 * Clean up.120 */121 destroy: function() {122 if (this.map) {123 this.map.events.unregister("buttonclick", this, this.onZoomClick);124 }125 delete this.zoomInLink;126 delete this.zoomOutLink;127 OpenLayers.Control.prototype.destroy.apply(this);128 },129 CLASS_NAME: "OpenLayers.Control.Zoom"...
Control.Zoom.js
Source:Control.Zoom.js
...101 this.addControl(this.zoomControl);102 }103});104// @namespace Control.Zoom105// @factory L.control.zoom(options: Control.Zoom options)106// Creates a zoom control107L.control.zoom = function (options) {108 return new L.Control.Zoom(options);...
Zoom.js.uncompressed.js
Source:Zoom.js.uncompressed.js
1define("dojox/drawing/plugins/tools/Zoom", ["dojo/_base/lang", "../../util/oo", "../_Plugin", "../../manager/_registry"],2function(lang, oo, Plugin, registry){3 // zoomInc: Float4 // The amount of zoom that will occur upon each click.5 var zoomInc = Math.pow(2.0,0.25),6 // maxZoom: Number7 // The maximum the canvas can be zoomed in. 10 = 1000%8 maxZoom = 10,9 // minZoom: Float10 // The most the canvas can be zoomed out. .1 = 10%11 minZoom = 0.1,12 // zoomFactor: [readonly] Float13 // The current zoom amount14 zoomFactor = 1, 15 dt;16 17 if(!lang.getObject('dojox.drawing.plugins.tools')){18 lang.setObject('dojox.drawing.plugins.tools', {});19 }20 dt = dojox.drawing.plugins.tools;21 22 dt.ZoomIn = oo.declare(23 // summary:24 Plugin,25 function(options){26 27 },28 {29 type:"dojox.drawing.plugins.tools.ZoomIn",30 onZoomIn: function(){31 // summary:32 // Handles zoom in.33 zoomFactor *= zoomInc;34 zoomFactor = Math.min(zoomFactor, maxZoom);35 this.canvas.setZoom(zoomFactor);36 this.mouse.setZoom(zoomFactor);37 },38 onClick: function(){39 this.onZoomIn();40 }41 }42 );43 44 dt.Zoom100 = oo.declare(45 // summary:46 Plugin,47 function(options){48 49 },50 {51 type:"dojox.drawing.plugins.tools.Zoom100",52 onZoom100: function(){53 // summary:54 // Zooms to 100%55 zoomFactor = 1;56 this.canvas.setZoom(zoomFactor);57 this.mouse.setZoom(zoomFactor);58 },59 onClick: function(){60 this.onZoom100();61 }62 }63 );64 65 dt.ZoomOut = oo.declare(66 // summary:67 Plugin,68 function(options){69 70 },71 {72 type:"dojox.drawing.plugins.tools.ZoomOut",73 onZoomOut: function(){74 // summary:75 // Handles zoom out.76 zoomFactor /= zoomInc;77 zoomFactor = Math.max(zoomFactor, minZoom);78 this.canvas.setZoom(zoomFactor);79 this.mouse.setZoom(zoomFactor);80 },81 onClick: function(){82 this.onZoomOut();83 }84 }85 );86 87 dt.ZoomIn.setup = {88 name:"dojox.drawing.plugins.tools.ZoomIn",89 tooltip:"Zoom In"90 };91 registry.register(dt.ZoomIn.setup, "plugin");92 93 dt.Zoom100.setup = {94 name:"dojox.drawing.plugins.tools.Zoom100",95 tooltip:"Zoom to 100%"96 };97 registry.register(dt.Zoom100.setup, "plugin");98 99 dt.ZoomOut.setup = {100 name:"dojox.drawing.plugins.tools.ZoomOut",101 tooltip:"Zoom In"102 };103 registry.register(dt.ZoomOut.setup, "plugin");104 return dt;...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var browser = wd.promiseChainRemote("localhost", 4723);6 .init(desired)7 .sleep(10000)8 .execute("mobile: pinchOpen", [{ scale: 2, velocity: 1 }])9 .sleep(10000)10 .execute("mobile: pinchClose", [{ scale: 2, velocity: 1 }])11 .sleep(10000)12 .quit();13Your name to display (optional):14Your name to display (optional):15var wd = require('wd');16var assert = require('assert');17var desired = {18};19var browser = wd.promiseChainRemote("localhost", 4723);20 .init(desired)21 .sleep(10000)22 .execute("mobile: pinchOpen", [{ scale: 2, velocity: 1 }])23 .sleep(10000)24 .execute("mobile: pinchClose", [{ scale: 2, velocity: 1 }])25 .sleep(10000)26 .quit();27Your name to display (optional):
Using AI Code Generation
1var wd = require('wd'),2 assert = require('assert'),3 serverConfigs = require('./helpers/appium-servers');4var desired = {5};6var driver = wd.promiseChainRemote(serverConfigs.local);7 .init(desired)8 .then(function() { return driver.setImplicitWaitTimeout(5000); })9 .then(function() { return driver.elementById("com.example.myapp:id/myButton"); })10 .then(function(el) { return el.click(); })11 .then(function() { return driver.elementById("com.example.myapp:id/myEditText"); })12 .then(function(el) { return el.sendKeys("Hello World"); })13 .then(function() { return driver.elementById("com.example.myapp:id/myButton"); })14 .then(function(el) { return el.click(); })15 .then(function() { return driver.elementById("com.example.myapp:id/myTextView"); })16 .then(function(el) { return el.text(); })17 .then(function(txt) { assert.equal(txt, "Hello World"); })18 .fin(function() { return driver.quit(); })19 .done();20var wd = require('wd'),21 assert = require('assert'),22 serverConfigs = require('./helpers/appium-servers');23var desired = {24};25var driver = wd.promiseChainRemote(serverConfigs.local);26 .init(desired)27 .then(function() { return driver.setImplicitWaitTimeout(5000); })28 .then(function() { return driver.elementById("com.example.myapp:id/myButton"); })29 .then(function(el) { return el
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var browser = wd.promiseChainRemote("localhost", 4723);6 .init(desired)7 .sleep(10000)8 .elementByClassName("android.widget.EditText").sendKeys("Appium")9 .elementByClassName("android.widget.ImageButton").click()10 .sleep(10000)11 .elementById("com.android.chrome:id/url_bar").text().then(function(text) {12 assert.ok(text.indexOf("Appium") !== -1);13 })14 .elementById("com.android.chrome:id/url_bar").sendKeys(wd.SPECIAL_KEYS["Enter"])15 .sleep(10000)16 .elementById("com.android.chrome:id/url_bar").text().then(function(text) {17 assert.ok(text.indexOf("Appium") !== -1);18 })19 .sleep(10000)20 .zoom({element: null, x: 0, y: 0, scale: 2, velocity: 1})21 .sleep(10000)22 .quit();23info: --> POST /wd/hub/session/8c0b9f9c-5b5f-4bfb-9c0b-9c5b5f2bfb8b/touch/perform {"actions":[{"action":"press","options":{"x":0,"y":0}},{"action":"moveTo","options":{"x":0,"y":0}},{"action":"release","options":{}}]}
Using AI Code Generation
1driver.zoom({x: 200, y: 200, duration: 5000});2driver.pinch({x: 200, y: 200, duration: 5000});3driver.swipe({startX: 200, startY: 200, endX: 400, endY: 400, duration: 5000});4driver.dragAndDrop({startX: 200, startY: 200, endX: 400, endY: 400});5driver.dragAndDropBy({startX: 200, startY: 200, endX: 400, endY: 400});6driver.rotate({x: 200, y: 200, duration: 5000, radius: 100, rotation: 90, touchCount: 2});7driver.touchAction({action: 'press', x: 200, y: 200, duration: 5000});8driver.performTouch({action: 'press', x: 200, y: 200, duration: 5000});9driver.performMultiAction({action: 'press', x: 200, y: 200, duration: 5000});10driver.performGesture({action: 'press', x: 200, y: 200, duration: 5000});11driver.updateSettings({action: 'press', x: 200, y: 200, duration: 5000});12driver.logEvent({action: 'press', x: 200, y: 200, duration:
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!!