Skip to content

Commit 1babd2f

Browse files
committed
updated readme, gruntfile, and added maxCollapsedCrumbs
1 parent b742dd8 commit 1babd2f

File tree

7 files changed

+194
-54
lines changed

7 files changed

+194
-54
lines changed

Gruntfile.coffee

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ module.exports = (grunt) ->
55
pkg:
66
grunt.file.readJSON "package.json"
77
clean:
8-
default:
9-
[
8+
default: [
109
"js"
1110
"css"
1211
"index.html"
@@ -65,28 +64,78 @@ module.exports = (grunt) ->
6564
files: "js/breadcrumbs.min.js":"js/breadcrumbs.js"
6665
example:
6766
files: "js/example.min.js":"js/example.js"
67+
watch:
68+
all:
69+
files: [
70+
"coffee/**/*.coffee"
71+
"less/**/*.less"
72+
"jade/**/*.jade"
73+
]
74+
tasks: "build"
75+
coffee:
76+
files: "coffee/**/*.coffee"
77+
tasks: "buildCoffee"
78+
jade:
79+
files: "jade/**/*.jade"
80+
tasks: "buildJade"
81+
less:
82+
files: "less/**/*.less"
83+
tasks: "buildLess"
6884

69-
grunt.loadNpmTasks "grunt-contrib-coffee"
70-
grunt.loadNpmTasks "grunt-contrib-less"
7185
grunt.loadNpmTasks "grunt-contrib-clean"
72-
grunt.loadNpmTasks "grunt-contrib-jade"
73-
grunt.loadNpmTasks "grunt-contrib-connect"
86+
grunt.loadNpmTasks "grunt-contrib-coffee"
7487
grunt.loadNpmTasks "grunt-contrib-concat"
88+
grunt.loadNpmTasks "grunt-contrib-jade"
89+
grunt.loadNpmTasks "grunt-contrib-less"
7590
grunt.loadNpmTasks "grunt-contrib-uglify"
91+
grunt.loadNpmTasks "grunt-contrib-watch"
7692

77-
grunt.registerTask "default", "build"
78-
grunt.registerTask "build", [
79-
"clean"
80-
"concat:jade"
81-
"jade"
82-
"clean:jade"
93+
grunt.registerTask "buildCoffee", [
8394
"coffee"
8495
"uglify:breadcrumbs"
8596
"uglify:example"
8697
"concat:jsMin"
98+
]
99+
100+
grunt.registerTask "buildJade", [
101+
"concat:jade"
102+
"jade"
103+
"clean:jade"
104+
]
105+
106+
grunt.registerTask "buildLess", [
87107
"less:breadcrumbs"
88108
"less:breadcrumbsMin"
89109
"less:template"
90110
"less:templateMin"
91111
"less:combinedMin"
92112
]
113+
114+
grunt.registerTask "build", [
115+
"clean:default"
116+
"buildCoffee"
117+
"buildJade"
118+
"buildLess"
119+
]
120+
121+
grunt.registerTask "devAll", [
122+
"build"
123+
"watch:all"
124+
]
125+
126+
grunt.registerTask "devCoffee", [
127+
"buildCoffee"
128+
"watch:coffee"
129+
]
130+
131+
grunt.registerTask "devLess", [
132+
"buildLess"
133+
"watch:less"
134+
]
135+
136+
grunt.registerTask "devJade", [
137+
"buildJade"
138+
"watch:jade"
139+
]
140+
141+
grunt.registerTask "default", "build"

README.md

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22

33
An easy way to expand or collapse menu items, especially when there are many levels like in folder navigation.
44

5-
## Build
6-
7-
Clone the repo with its submodules ..
8-
9-
git clone https://github.com/infowrap/breadcrumbs.git
10-
cd breadcrumbs
11-
12-
Then to build, run ..
13-
14-
sh install.sh
15-
# after the first time you can simply run `grunt`
5+
## To use
166

17-
To work on the project with a watcher that builds on save, run ..
7+
Add jQuery and then ..
188

19-
grunt dev
9+
$(window).load(function() {
10+
$(".infowrap-breadcrumbs").infowrapBreadcrumbs();
11+
});
2012

2113

2214
## Examples
@@ -28,3 +20,41 @@ Expanded
2820

2921
Collapsed
3022
![](https://raw.github.com/infowrap/breadcrumbs/master/README/collapsed.png)
23+
24+
25+
## Build
26+
27+
To install and build, run ..
28+
29+
sh install.sh
30+
# after the first time you can simply run `grunt`
31+
32+
33+
To watch and compile specific files, run ..
34+
35+
# to watch all and compile all
36+
grunt devAll
37+
38+
# to watch and compile coffee files
39+
grunt devCoffee
40+
41+
# to watch and compile jade files
42+
grunt devJade
43+
44+
# to watch and compile less files
45+
grunt devLess
46+
47+
48+
To build-only specific file types, run ..
49+
50+
# to watch all and compile all
51+
grunt build
52+
53+
# to compile coffee files
54+
grunt buildCoffee
55+
56+
# to compile jade files
57+
grunt buildJade
58+
59+
# to compile less files
60+
grunt buildLess

coffee/breadcrumbs.coffee

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
###
295349
import jquery into the self-invoking anonymous wrapper

less/boilerplate/mixins.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@
1010
clear: both;
1111
}
1212
}
13+
14+
.transition(@transition) {
15+
-webkit-transition: @transition;
16+
-moz-transition: @transition;
17+
-o-transition: @transition;
18+
transition: @transition;
19+
}

less/boilerplate/template.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ html {
1717
}
1818

1919
.container {
20-
padding: 50px;
20+
padding: 100px 30px;
2121
}

0 commit comments

Comments
 (0)