@@ -28,7 +28,12 @@ self-invoking anonymous wrapper, which imports jquery on last line
2828 ###
2929 save this as a variable so it isn't lost or confused with another this
3030 ###
31- crumbsObj = this
31+ infowrapBreadcrumbsObj = this
32+
33+ ###
34+ cache the .crumbs to an object for later use
35+ ###
36+ crumbsObj = infowrapBreadcrumbsObj .find " .crumbs"
3237
3338 ###
3439 allowing formal options overrides to be respected
@@ -43,18 +48,27 @@ self-invoking anonymous wrapper, which imports jquery on last line
4348 $.fn.infowrapBreadcrumbs.defaultOptions.minWidth = 50;
4449 $('#helloWorld').infowrapBreadcrumbs();
4550 $('#goodbyeWorld').infowrapBreadcrumbs();
46-
4751 ###
4852 options = $ .extend {}, $ .fn .infowrapBreadcrumbs .defaultOptions , options
4953
5054 ###
5155 globalizing the variables for the method, so if we have to make a change to
5256 the varable on its way in, we have a place to address that potential
5357 ###
58+ maxCollapsedCrumbs = options .maxCollapsedCrumbs - 1
5459 minWidth = options .minWidth
5560 shaderWidth = options .shaderWidth
5661 shaderAntumbra = options .shaderAntumbra
5762
63+ ###
64+ the nth crumb that is collapsed counting from the left, and the nth crumb
65+ that is expanded counting from the left. the expanded crumb is only detected
66+ if no collapsed crumb is found. this prevents an error when on a small
67+ screen and all are collapsed
68+ ###
69+ collapsedCrumb = 0
70+ expandedCrumb = 0
71+
5872 ###
5973 the total number of crumbs
6074 if 3, then it should be 3
@@ -88,10 +102,10 @@ self-invoking anonymous wrapper, which imports jquery on last line
88102 ###
89103 define the crumb object as its used more than once
90104 ###
91- crumbObj = $ ( this )
105+ crumbObj = $ this
92106
93107 ###
94- cache the crumb to an object for later use
108+ cache the crumb to an objects for later use
95109 ###
96110 crumbObjs[index + 1 ] = crumbObj
97111
@@ -150,8 +164,7 @@ self-invoking anonymous wrapper, which imports jquery on last line
150164 over all the crumbs following the currenct crumb
151165 ###
152166 afterCrumb = 0
153- for i in [crumb + 1 .. totalCrumbs] by 1
154- afterCrumb += crumbWidths[i]
167+ afterCrumb += crumbWidths[i] for i in [crumb + 1 .. totalCrumbs] by 1
155168
156169 ###
157170 this is the magic, the current crumb width is simlpy the difference
@@ -191,21 +204,54 @@ self-invoking anonymous wrapper, which imports jquery on last line
191204 crumbObj .outerWidth crumbWidthDiff
192205
193206 ###
194- the shader moves with the window resize to simulate a growing overlap
195- as the objects get tighter.
207+ if the maxCollapsedCrumbs is set, then lets make it happen
196208 ###
197- shaderX = - shaderWidth - shaderAntumbra + crumbWidth - crumbWidthDiff
209+ if maxCollapsedCrumbs
210+
211+ ###
212+ when a crumb diff width is equal to or less than the minimum crumb
213+ width, then is collapsed, then flag it with a data attribute otherwise
214+ set it to false
215+ ###
216+ if crumbWidthDiff < minWidth
217+ crumbObj .attr " data-collapsed" , true
218+ else
219+ crumbObj .attr " data-collapsed" , false
220+
221+ ###
222+ look for the first instance of false, in other words the first
223+ uncollapsed crumb. todo: optimize this to run once
224+ ###
225+ collapsedCrumb = crumbsObj .find (""" .crumb[data-collapsed="false"]:first""" ).index ()
226+
227+ if collapsedCrumb < 0
228+ collapsedCrumb = totalCrumbs - 1
229+ expandedCrumb = crumbsObj .find (""" .crumb[data-collapsed="true"]:first""" ).index ()
230+
231+ ###
232+ if the collapsed crumb index is greater than or equal to the
233+ maxCollapsedCrumbs option, then there are too many crumbs visible,
234+ and the .crumbs container needs to go left and be hidden by the
235+ overflow:hidden of the parent, .infowrap-breadcrumbs. the crumbs
236+ can go too far right, because of the loose if conditional, so a
237+ protection maxes out at 0
238+ ###
239+ if collapsedCrumb >= maxCollapsedCrumbs or expandedCrumb >= 0
240+ crumbsLeft = - minWidth * (collapsedCrumb - maxCollapsedCrumbs)
241+ if crumbsLeft > 0 then crumbsLeft = 0
242+ crumbsObj .css " left" , crumbsLeft
198243
199244 ###
200- the `right` css attribute should not be less than 0
245+ the shader moves with the window resize to simulate a growing overlap
246+ as the objects get tighter.
201247 ###
202- if shaderX > 0 then shaderX = 0
248+ shaderX = - shaderWidth - shaderAntumbra + crumbWidth - crumbWidthDiff
203249
204250 ###
205251 the div that creates the shadow should not enter the visible space, it
206252 should always be cropped out of view by overflow:hidden
207253 ###
208- if shaderX < shaderWidth then shaderX = - shaderWidth
254+ if shaderX > - shaderWidth then shaderX = - shaderWidth
209255
210256 ###
211257 set the shader x position off the right with position absolute
@@ -245,10 +291,13 @@ self-invoking anonymous wrapper, which imports jquery on last line
245291 ###
246292 windowResize is a set of operations used in a couple of places, it has been
247293 added as a method to call on load and on resize. when the user resizes the
248- page, run the updateCrumb method on each crumb
294+ page, run the updateCrumb method on each crumb. One is subtracted from
295+ totalCrumbs, because there's no need to adjust the last crumb width as the
296+ overflow:hidden will handle it
249297 ###
250298 windowResize = ->
251- updateCrumb crumb, crumbsObj .width () for crumb in [1 .. totalCrumbs] by 1
299+ for crumb in [1 .. totalCrumbs - 1 ] by 1
300+ updateCrumb crumb, infowrapBreadcrumbsObj .width ()
252301
253302 ###
254303 run the above method on every fire of window resize
@@ -275,6 +324,11 @@ self-invoking anonymous wrapper, which imports jquery on last line
275324 ###
276325 $ .fn .infowrapBreadcrumbs .defaultOptions =
277326
327+ ###
328+ the maximum number of visible collapsed crumbs counting from the left
329+ ###
330+ maxCollapsedCrumbs : 3
331+
278332 ###
279333 the minimum width of a crumb when collapsed
280334 ###
@@ -289,7 +343,7 @@ self-invoking anonymous wrapper, which imports jquery on last line
289343 ###
290344 the distance of your css shadow antumbra in pixels
291345 ###
292- shaderAntumbra : 20
346+ shaderAntumbra : 25
293347
294348###
295349import jquery into the self-invoking anonymous wrapper
0 commit comments