summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/wicket/pages/scripts/imgdiff.js
blob: bfde435d787833dc14070cc84e32b2bdac7008d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * Copyright 2014 Tom <tw201207@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
jQuery(function () {
	// Runs on jQuery's document.ready and sets up the scroll event handlers for all image diffs.
	jQuery(".imgdiff-slider-resizeable").each(function () {
		var $el = jQuery(this);
		var $img = jQuery('#' + this.id.substr(this.id.indexOf('-') + 1));
		function fade() {
			var w = Math.max(0, $el.width() - 18); // Must correspond to CSS: 18 px is handle width, 400 px is slider width
			w = Math.max(0, 1.0 - w / 400.0);
			$img.css("opacity", w);
		}
		// Unfortunately, not even jQuery triggers resize events for our resizeable... so let's track the mouse.
		$el.on('mousedown', function() { $el.on('mousemove', fade); });
		$el.on('mouseup', function() { $el.off('mousemove', fade); fade(); });
	});
});