-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.trace.js
More file actions
136 lines (125 loc) · 4.05 KB
/
jquery.trace.js
File metadata and controls
136 lines (125 loc) · 4.05 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*!
* trace v@VERSION - Yet another menu tracer for jQuery
*
* Copyright 2012, Alexander (SASh) Alexiev @ Edge Soft Ltd.
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* or GPL Version 2 (http://www.opensource.org/licenses/gpl-2.0.php) licenses.
*
* Date: @DATE
*/
/**
* HTML Structure:
* .frame
* .carousel
* #slider_X (the element must be emidiate child of the .carousel - .carousel>#slider_X)
* a.prev
* a.slide[href=#slider_X] (a.slide.selected[href=#slider_X])
* a.next
* */
(function($){
var methods = {
init : function( options ) {
return this.each(function(){
var $this = $(this);
if (!$this.data('trace')){
var default_settings = {
'animate' : 0.5,
'animateEasing' : 'swing',
'selected' : '.selected',
'tracer': '<li class="tracer"></li>',
'elements': 'li:not([class~="tracer"])'
}
var settings = $.extend( default_settings, options);
settings.id = 'app-slider-'+parseInt(Math.random()*10000000000000000);
$this.data('trace', settings);
$this.css({'position': 'relative'});
var revert = $this.find(settings.selected);
var tracer = $(settings.tracer).attr('id', settings.id).css({'position':'absolute', 'left':'0px', 'width': '0px', 'top': '0px', 'padding': '0', 'margin': '0', 'opacity':0});
if (revert.size()){
tracer.css({
'opacity': 1,
'top':revert.position().top,
'left':revert.position().left,
'width': revert.outerWidth(true),
'height': revert.outerHeight(true)
})
}
$this.append(tracer);
$this.trigger('traceInit', [$this, tracer])
$this.on('mouseenter.trace', settings.elements, function(){
$this.trace('highlight', this);
return false;
});
$this.on('mouseleave.trace', settings.elements, function(){
var revert = $this.find(settings.selected);
$this.trace('highlight', revert.size()?revert : false);
return false;
});
}
});
},
highlight: function(element, skipanimation){
return this.each(function(){
var $this = $(this), settings = $this.data('trace');
var tracer = $this.find('#'+settings.id);
if (settings.hover){settings.hover.trigger('traceBlur', [$this]);}
if (element){
element = $(element);
if (tracer.width() == 0){
tracer.css({
'width':element.outerWidth(true),
'height':element.outerHeight(true),
'top':element.position().top,
'left':element.position().left
});
}
settings.hover = element;
$this.data('trace', settings);
element.trigger('traceFocus', [$this, tracer]);
if (skipanimation){
tracer.stop().css({
'opacity':1,
'top':element.position().top,
'left':element.position().left,
'width': element.outerWidth(true),
'height': element.outerHeight(true)
})
}
else{
tracer.stop().animate({
'opacity':1,
'top':element.position().top,
'left':element.position().left,
'width': element.outerWidth(true),
'height': element.outerHeight(true)
}, settings.animate*1000, settings.animateEasing)
}
$this.trigger('traceHighlight', [element]);
}
else{
settings.hover = false;
$this.data('trace', settings);
tracer.stop().animate({
'opacity':0
}, settings.animate*1000, settings.animateEasing)
$this.trigger('traceHighlight', []);
}
})
},
destroy: function(){
return this.each(function(){
$(this).off('.trace').removeData('trace');
})
}
};
$.fn.trace = function(method){
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.trace' );
}
};
})(jQuery);