OLD | NEW |
| 1 var MAX_SWAP_IMG_SIZE = 400; |
| 2 |
1 angular.module('diff_viewer', []). | 3 angular.module('diff_viewer', []). |
2 config(['$routeProvider', function($routeProvider) { | 4 config(['$routeProvider', function($routeProvider) { |
3 // Show the list of differences by default | 5 // Show the list of differences by default |
4 $routeProvider. | 6 $routeProvider. |
5 otherwise({ templateUrl: '/diff_list.html', controller: DiffListController})
; | 7 otherwise({ templateUrl: '/diff_list.html', controller: DiffListController})
; |
6 }]). | 8 }]). |
7 directive('swapImg', function() { | 9 directive('swapImg', function() { |
8 // Custom directive for showing an image that gets swapped my mouseover. | 10 // Custom directive for showing an image that gets swapped my mouseover. |
9 return { | 11 return { |
10 restrict: 'E', // The directive can be used as an element name | 12 restrict: 'E', // The directive can be used as an element name |
(...skipping 10 matching lines...) Expand all Loading... |
21 var ctx = elm[0].getContext('2d'); | 23 var ctx = elm[0].getContext('2d'); |
22 | 24 |
23 scope.render = function() { | 25 scope.render = function() { |
24 var image; | 26 var image; |
25 if (scope.side == "left") { | 27 if (scope.side == "left") { |
26 image = leftImage; | 28 image = leftImage; |
27 } else { | 29 } else { |
28 image = rightImage; | 30 image = rightImage; |
29 } | 31 } |
30 | 32 |
31 // Make it so the maximum size of an image is 500, and the image
s are scaled | 33 // Make it so the maximum size of an image is MAX_SWAP_IMG_SIZE,
and the images are |
32 // down in halves. | 34 // scaled down in halves. |
33 var divisor = 1; | 35 var divisor = 1; |
34 while ((image.width / divisor) > 500) { | 36 while ((image.width / divisor) > MAX_SWAP_IMG_SIZE) { |
35 divisor *= 2; | 37 divisor *= 2; |
36 } | 38 } |
37 | 39 |
38 // Set canvas to correct size and draw the image into it | 40 // Set canvas to correct size and draw the image into it |
39 elm[0].width = image.width / divisor; | 41 elm[0].width = image.width / divisor; |
40 elm[0].height = image.height / divisor; | 42 elm[0].height = image.height / divisor; |
41 ctx.drawImage(image, 0, 0, elm[0].width, elm[0].height); | 43 ctx.drawImage(image, 0, 0, elm[0].width, elm[0].height); |
42 }; | 44 }; |
43 | 45 |
44 // When the leftSrc attribute changes, load the image and then reren
der | 46 // When the leftSrc attribute changes, load the image and then reren
der |
(...skipping 22 matching lines...) Expand all Loading... |
67 scope.side = "right"; | 69 scope.side = "right"; |
68 } else { | 70 } else { |
69 scope.side = "left"; | 71 scope.side = "left"; |
70 } | 72 } |
71 scope.render(); | 73 scope.render(); |
72 }; | 74 }; |
73 } | 75 } |
74 }; | 76 }; |
75 }); | 77 }); |
76 | 78 |
77 function DiffListController($scope) { | 79 function DiffListController($scope, $http, $timeout) { |
78 // Label each kind of differ for the sort buttons. | 80 // Label each kind of differ for the sort buttons. |
79 $scope.differs = [ | 81 $scope.differs = [ |
80 { | 82 { |
81 "title": "Different Pixels" | 83 "title": "Different Pixels" |
82 }, | 84 }, |
83 { | 85 { |
84 "title": "Perceptual Difference" | 86 "title": "Perceptual Difference" |
85 } | 87 } |
86 ]; | 88 ]; |
87 | 89 |
88 // Puts the records within AngularJS scope | 90 // Puts the records within AngularJS scope |
89 $scope.records = SkPDiffRecords.records; | 91 $scope.records = SkPDiffRecords.records; |
90 | 92 |
91 // Indicates which diff metric is used for sorting | 93 // Indicates which diff metric is used for sorting |
92 $scope.sortIndex = 1; | 94 $scope.sortIndex = 1; |
93 | 95 |
94 // Called by the sort buttons to adjust the metric used for sorting | 96 // Called by the sort buttons to adjust the metric used for sorting |
95 $scope.setSortIndex = function(idx) { | 97 $scope.setSortIndex = function(idx) { |
96 $scope.sortIndex = idx; | 98 $scope.sortIndex = idx; |
97 }; | 99 }; |
98 | 100 |
99 // A predicate for pulling out the number used for sorting | 101 // A predicate for pulling out the number used for sorting |
100 $scope.sortingDiffer = function(record) { | 102 $scope.sortingDiffer = function(record) { |
101 return record.diffs[$scope.sortIndex].result; | 103 return record.diffs[$scope.sortIndex].result; |
102 }; | 104 }; |
| 105 |
| 106 // Flash status indicators on the rows, and then remove them so the style ca
n potentially be |
| 107 // reapplied later. |
| 108 $scope.flashRowStatus = function(success, record) { |
| 109 var flashStyle = success ? "success-flash" : "failure-flash"; |
| 110 var flashDurationMillis = success ? 500 : 800; |
| 111 |
| 112 // Store the style in the record. The row will pick up the style this wa
y instead of through |
| 113 // index because index can change with sort order. |
| 114 record.cssClasses = flashStyle; |
| 115 |
| 116 // The animation cannot be repeated unless the class is removed the elem
ent. |
| 117 $timeout(function() { |
| 118 record.cssClasses = ""; |
| 119 }, flashDurationMillis); |
| 120 } |
| 121 |
| 122 $scope.setHashOf = function(imagePath, record) { |
| 123 $http.post("/set_hash", { |
| 124 "path": imagePath |
| 125 }).success(function(data) { |
| 126 $scope.flashRowStatus(data.success, record); |
| 127 }).error(function() { |
| 128 $scope.flashRowStatus(false, record); |
| 129 }); |
| 130 |
| 131 }; |
103 } | 132 } |
OLD | NEW |