Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: experimental/webtry/js/webtry.js

Issue 252993003: Add a magnifier lens to the image. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/webtry/js/run.js ('k') | experimental/webtry/templates/content.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/webtry/js/webtry.js
diff --git a/experimental/webtry/js/run.js b/experimental/webtry/js/webtry.js
similarity index 70%
rename from experimental/webtry/js/run.js
rename to experimental/webtry/js/webtry.js
index 9f1e8031f0682560286b5e661d3df8a484ce6679..4493f61f6d69f713fb035f61eb0b9c5f705f8a17 100644
--- a/experimental/webtry/js/run.js
+++ b/experimental/webtry/js/webtry.js
@@ -25,6 +25,85 @@
})();
/**
+ * Enable zooming for any images with a class of 'zoom'.
+ */
+(function () {
+ var clientX = 0;
+ var clientY = 0;
+ var lastClientX = 0;
+ var lastClientY = 0;
+ var ctx = null; // The 2D canvas context of the zoom.
+ var currentImage = null; // The img node we are zooming for, otherwise null.
+
+ function zoomMove(e) {
+ clientX = e.clientX;
+ clientY = e.clientY;
+ }
+
+ function zoomMouseDown(e) {
+ e.preventDefault();
+ // Only do zooming on the primary mouse button.
+ if (e.button != 0) {
+ return
+ }
+ currentImage = e.target;
+ clientX = e.clientX;
+ clientY = e.clientY;
+ lastClientX = clientX-1;
+ lastClientY = clientY-1;
+ document.body.style.cursor = 'crosshair';
+ canvas = document.createElement('canvas');
+ canvas.width=256;
+ canvas.height=256;
+ canvas.classList.add('zoomCanvas');
+ ctx = canvas.getContext('2d');
+ ctx.imageSmoothingEnabled = false;
+ this.parentNode.insertBefore(canvas, this);
+
+ document.body.addEventListener('mousemove', zoomMove, true);
+ document.body.addEventListener('mouseup', zoomFinished);
+ document.body.addEventListener('mouseleave', zoomFinished);
+
+ // Kick off the drawing.
+ setTimeout(drawZoom, 1);
+ }
+
+ function drawZoom() {
+ if (currentImage) {
+ // Only draw if the mouse has moved from the last time we drew.
+ if (lastClientX != clientX || lastClientY != clientY) {
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
+ ctx.drawImage(currentImage,
+ clientX - currentImage.x, clientY - currentImage.y, // src zero
+ 32, 32, // src dimensions
+ 0, 0, // dst zero
+ ctx.canvas.width, ctx.canvas.height); // dst dimensions
+ lastClientX = clientX;
+ lastClientY = clientY;
+ }
+ setTimeout(drawZoom, 1000/30);
+ }
+ }
+
+ function zoomFinished() {
+ currentImage = null;
+ document.body.style.cursor = 'default';
+ ctx.canvas.parentNode.removeChild(ctx.canvas);
+ document.body.removeEventListener('mousemove', zoomMove, true);
+ document.body.removeEventListener('mouseup', zoomFinished);
+ document.body.removeEventListener('mouseleave', zoomFinished);
+ }
+
+ this.addEventListener('DOMContentLoaded', function() {
+ var zoomables = document.body.querySelectorAll('.zoom');
+ for (var i=0; i<zoomables.length; i++) {
+ zoomables[i].addEventListener('mousedown', zoomMouseDown);
+ }
+ });
+})();
+
+
+/**
* All the functionality is wrapped up in this anonymous closure, but we need
* to be told if we are on the workspace page or a normal try page, so the
* workspaceName is passed into the closure, it must be set in the global
« no previous file with comments | « experimental/webtry/js/run.js ('k') | experimental/webtry/templates/content.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698