-
Notifications
You must be signed in to change notification settings - Fork 0
/
diffWidget.js
executable file
·65 lines (47 loc) · 1.33 KB
/
diffWidget.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*global jQuery */
/*!
* DiffWidget.js 1.0
* Copyright 2014, Manyahin Ilya
*/
(function( $ ){
$.fn.diffWidget = function( options ) {
var defaults = {
width: '900px',
height: '300px',
top: 'black',
bottom: 'orange',
position: '50%'
};
var options = $.extend({}, defaults, options);
// Template for widget
//
// <div class="diffWidget">
// <div class="wrapper">
// <div class="first"></div>
// <div class="second"></div>
// </div>
// </div>
var tpl = $('<div class="diffWidget"><div class="wrapper"><div class="first"></div><div class="second"></div></div></div>');
var wrap = tpl.find('.wrapper'),
topLayer = wrap.find('.first'),
bottomLayer = wrap.find('.second');
function selectMethod(element, option)
{
if(option.indexOf('.') != -1)
{
element.css('background-image', 'url(' + option + ')');
} else {
element.css('background-color', option);
}
}
selectMethod(topLayer, options.top);
selectMethod(bottomLayer, options.bottom);
tpl.css('width', options.width);
tpl.css('height', options.height);
topLayer.width(options.position);
wrap.on('mousemove', function(e) {
topLayer.width(e.offsetX);
})
$(this).append(tpl);
};
})( jQuery );