OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 return null; | 57 return null; |
58 } | 58 } |
59 | 59 |
60 function zoomImageContainer(url) | 60 function zoomImageContainer(url) |
61 { | 61 { |
62 var container = document.createElement('div'); | 62 var container = document.createElement('div'); |
63 container.className = 'zoom-image-container'; | 63 container.className = 'zoom-image-container'; |
64 | 64 |
65 var title = url.match(/\-([^\-]*)\.png/)[1]; | 65 var title = url.match(/\-([^\-]*)\.png/)[1]; |
66 | 66 |
67 var label = document.createElement('div'); | 67 var label = document.createElement('div'); |
68 label.className = 'label'; | 68 label.className = 'label'; |
69 label.appendChild(document.createTextNode(title)); | 69 label.appendChild(document.createTextNode(title)); |
70 container.appendChild(label); | 70 container.appendChild(label); |
71 | 71 |
72 var imageContainer = document.createElement('div'); | 72 var imageContainer = document.createElement('div'); |
73 imageContainer.className = 'scaled-image-container'; | 73 imageContainer.className = 'scaled-image-container'; |
74 | 74 |
75 var image = new Image(); | 75 var image = new Image(); |
76 image.src = url; | 76 image.src = url; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 { | 130 { |
131 Array.prototype.forEach.call(document.querySelectorAll('.pixel-zoom-containe
r .scaled-image-container'), draw); | 131 Array.prototype.forEach.call(document.querySelectorAll('.pixel-zoom-containe
r .scaled-image-container'), draw); |
132 } | 132 } |
133 | 133 |
134 function handleMouseOut(e) | 134 function handleMouseOut(e) |
135 { | 135 { |
136 if (e.relatedTarget && e.relatedTarget.tagName != 'IFRAME') | 136 if (e.relatedTarget && e.relatedTarget.tagName != 'IFRAME') |
137 return; | 137 return; |
138 | 138 |
139 // If e.relatedTarget is null, we've moused out of the document. | 139 // If e.relatedTarget is null, we've moused out of the document. |
140 $('pixel-zoom-container').detach(); | 140 var container = document.querySelector('.pixel-zoom-container'); |
| 141 if (container) |
| 142 container.remove(); |
141 } | 143 } |
142 | 144 |
143 function handleMouseMove(e) | 145 function handleMouseMove(e) |
144 { | 146 { |
145 if (pixelzoomer._mouseMoveTimeout) | 147 if (pixelzoomer._mouseMoveTimeout) |
146 clearTimeout(pixelzoomer._mouseMoveTimeout); | 148 clearTimeout(pixelzoomer._mouseMoveTimeout); |
147 | 149 |
148 if (parentOfType(e.target, '.pixel-zoom-container')) | 150 if (parentOfType(e.target, '.pixel-zoom-container')) |
149 return; | 151 return; |
150 | 152 |
151 var container = document.querySelector('.pixel-zoom-container'); | 153 var container = document.querySelector('.pixel-zoom-container'); |
152 | 154 |
153 var resultContainer = (e.target.className == 'result-container') ? | 155 var resultContainer = (e.target.className == 'result-container') ? |
154 e.target : parentOfType(e.target, '.result-container'); | 156 e.target : parentOfType(e.target, '.result-container'); |
155 if (!resultContainer || !resultContainer.querySelector('img')) { | 157 if (!resultContainer || !resultContainer.querySelector('img')) { |
156 $(container).detach(); | 158 if (container) |
| 159 container.remove(); |
157 return; | 160 return; |
158 } | 161 } |
159 | 162 |
160 var targetLocation = e.target.getBoundingClientRect(); | 163 var targetLocation = e.target.getBoundingClientRect(); |
161 pixelzoomer._percentX = (e.clientX - targetLocation.left) / targetLocation.w
idth; | 164 pixelzoomer._percentX = (e.clientX - targetLocation.left) / targetLocation.w
idth; |
162 pixelzoomer._percentY = (e.clientY - targetLocation.top) / targetLocation.he
ight; | 165 pixelzoomer._percentY = (e.clientY - targetLocation.top) / targetLocation.he
ight; |
163 | 166 |
164 if (!container) { | 167 if (!container) { |
165 if (pixelzoomer.showOnDelay) { | 168 if (pixelzoomer.showOnDelay) { |
166 pixelzoomer._mouseMoveTimeout = setTimeout(function() { | 169 pixelzoomer._mouseMoveTimeout = setTimeout(function() { |
(...skipping 11 matching lines...) Expand all Loading... |
178 | 181 |
179 pixelzoomer.showOnDelay = true; | 182 pixelzoomer.showOnDelay = true; |
180 | 183 |
181 pixelzoomer.installEventListeners = function() | 184 pixelzoomer.installEventListeners = function() |
182 { | 185 { |
183 document.addEventListener('mousemove', handleMouseMove, false); | 186 document.addEventListener('mousemove', handleMouseMove, false); |
184 document.addEventListener('mouseout', handleMouseOut, false); | 187 document.addEventListener('mouseout', handleMouseOut, false); |
185 }; | 188 }; |
186 | 189 |
187 })(); | 190 })(); |
OLD | NEW |