forked from gjb2048/moodle-theme_essential
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjBreadCrumb_1_1.js
184 lines (153 loc) · 5.79 KB
/
jBreadCrumb_1_1.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* @author Jason Roy for CompareNetworks Inc.
* Thanks to mikejbond for suggested udaptes
*
* Version 1.1
* Copyright (c) 2009 CompareNetworks Inc.
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
(function($)
{
// Private variables
var _options = {};
var _container = {};
var _breadCrumbElements = {};
var _autoIntervalArray = [];
var _easingEquation;
// Public functions
jQuery.fn.jBreadCrumb = function(options)
{
_options = $.extend({}, $.fn.jBreadCrumb.defaults, options);
return this.each(function()
{
_container = $(this);
setupBreadCrumb();
});
};
// Private functions
function setupBreadCrumb()
{
//Check if easing plugin exists. If it doesn't, use "swing"
if(typeof(jQuery.easing) == 'object')
{
_easingEquation = 'easeOutQuad'
}
else
{
_easingEquation = 'swing'
}
//The reference object containing all of the breadcrumb elements
_breadCrumbElements = jQuery(_container).find('li');
//Keep it from overflowing in ie6 & 7
jQuery(_container).find('ul').wrap('<div style="overflow:hidden; position:relative; width: ' + jQuery(_container).css("width") + ';"><div>');
//If the breadcrumb contains nothing, don't do anything
if (_breadCrumbElements.length > 0)
{
jQuery(_breadCrumbElements[_breadCrumbElements.length - 1]).addClass('last');
jQuery(_breadCrumbElements[0]).addClass('first');
//If the breadcrumb object length is long enough, compress.
if (_breadCrumbElements.length > _options.minimumCompressionElements)
{
compressBreadCrumb();
};
};
};
function compressBreadCrumb()
{
// Factor to determine if we should compress the element at all
var finalElement = jQuery(_breadCrumbElements[_breadCrumbElements.length - 1]);
// If the final element is really long, compress more elements
if (jQuery(finalElement).width() > _options.maxFinalElementLength)
{
if (_options.beginningElementsToLeaveOpen > 0)
{
_options.beginningElementsToLeaveOpen--;
}
if (_options.endElementsToLeaveOpen > 0)
{
_options.endElementsToLeaveOpen--;
}
}
// If the final element is within the short and long range, compress to the default end elements and 1 less beginning elements
if (jQuery(finalElement).width() < _options.maxFinalElementLength && jQuery(finalElement).width() > _options.minFinalElementLength)
{
if (_options.beginningElementsToLeaveOpen > 0)
{
_options.beginningElementsToLeaveOpen--;
}
}
var itemsToRemove = _breadCrumbElements.length - 1 - _options.endElementsToLeaveOpen;
// We compress only elements determined by the formula setting below
$(_breadCrumbElements).each(function(i, listElement)
{
if (i > _options.beginningElementsToLeaveOpen && i < itemsToRemove)
{
jQuery(listElement).find('a').wrap('<span></span>').width(jQuery(listElement).find('a').width() + _options.previewWidth);
var options =
{
id: i,
width: jQuery(listElement).width(),
listElement: jQuery(listElement).find('span'),
isAnimating: false,
element: jQuery(listElement).find('span')
};
jQuery(listElement).bind('mouseover', options, expandBreadCrumb).bind('mouseout', options, shrinkBreadCrumb);
jQuery(listElement).find('a').unbind('mouseover', expandBreadCrumb).unbind('mouseout', shrinkBreadCrumb);
listElement.autoInterval = setInterval(function()
{
clearInterval(listElement.autoInterval);
jQuery(listElement).find('span').animate(
{
width: _options.previewWidth
}, _options.timeInitialCollapse, _options.easing);
}, (150 * (i - 2)));
}
});
};
function expandBreadCrumb(e)
{
var originalWidth = e.data.width;
jQuery(e.data.element).stop();
jQuery(e.data.element).animate(
{
width: originalWidth + (_options.previewWidth / 2)
},
{
duration: _options.timeExpansionAnimation,
easing: _options.easing,
queue: false
});
return false;
};
function shrinkBreadCrumb(e)
{
jQuery(e.data.element).stop();
jQuery(e.data.element).animate(
{
width: _options.previewWidth
},
{
duration: _options.timeCompressionAnimation,
easing: _options.easing,
queue: false
});
return false;
};
// Public global variables
jQuery.fn.jBreadCrumb.defaults =
{
maxFinalElementLength: Math.round($(window).width() * .05),
minFinalElementLength: Math.round($(window).width() *.02),
minimumCompressionElements: 1,
endElementsToLeaveOpen: 0,
beginningElementsToLeaveOpen: 0,
timeExpansionAnimation: 500,
timeCompressionAnimation: 400,
timeInitialCollapse: 500,
easing: 'swing',
previewWidth: Math.round($(window).width() * .015)
};
})(jQuery);