How to use zoom method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

zoom-test.js

Source:zoom-test.js Github

copy

Full Screen

...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);...

Full Screen

Full Screen

mui.zoom.js

Source:mui.zoom.js Github

copy

Full Screen

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 };...

Full Screen

Full Screen

c3ext.js

Source:c3ext.js Github

copy

Full Screen

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 }...

Full Screen

Full Screen

zoom_manager.js

Source:zoom_manager.js Github

copy

Full Screen

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 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

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

Run robotframework-appiumlibrary 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