1 // Copyright 2014 Jason Woofenden -- Public Domain (CC0)
3 // This file contains helpers for using stylus in your project.
5 // Put something like this in your styl.styl:
6 // @require 'inc/wfpl/stylus-helpers.styl'
9 // set units to px if it doesn't have a unit already
11 unit(i) == '' ? unit(i, px) : i
13 // transparently support vender-specific tags
15 -webkit-border-radius: arguments
16 border-radius: arguments
18 -webkit-box-shadow: arguments
21 -webkit-box-sizing: arguments
22 -moz-box-sizing: arguments
25 -webkit-user-select: arguments
26 -moz-user-select: arguments
27 -ms-user-select: arguments
28 user-select: arguments
30 // map "whitespace:" to "white-space:"
32 white-space: arguments
36 position: unquote(type)
37 for i in (0...length(args))
38 if not args[i] is a 'unit'
39 {args[i]}: args[i + 1] is a 'unit' ? args[i + 1] : 0
41 // you can pass directions and units, or just directions. Examples:
42 // absolute: top 20px left 0
46 _pos('absolute', arguments)
48 _pos('fixed', arguments)
50 _pos('relative', arguments)
52 // Specify width and height on the same line
57 // Make children of this element inline-blocks that are spaced evenly accross.
59 // To create a minimum distance between: don't use word-spacing, it's broken in
60 // firefox. Instead, try padding on the children and negative margin on the
62 space_evenly(line_height = 1.2em)
66 relative: top line_height
71 margin-bottom: -(line_height)
77 // image layout: left column has normal, right column hover versions
79 // arguments: width/height are pixel dimensions of a single sprite
81 // markup: put classes n1, n2, etc on the items.
88 // <li class="n0">home</li>
89 // <li class="n1">contact</li>
94 // sprites_rollover "images/nav.png" 150 35 2
95 sprites_rollover(image, width, height, count, v_offset = 0, h_offset = 0)
96 width: unit(width, px)
97 height: unit(height, px)
98 background-image: url(image)
99 background-position: top left
100 background-repeat: no-repeat;
103 y = - (@height * n) - unit(v_offset, px)
104 background-position: (0 - unit(h_offset, px)) y
106 background-position: (0 - unit(h_offset, px) - @width) y
107 sprite_rollover(image, width, height, v_offset = 0, h_offset = 0)
108 sprites_rollover(image, width, height, 1, v_offset, h_offset)
110 // see sprites_rollover
111 sprites(image, height, count, v_offset = 0, h_offset = 0)
112 height: unit(height, px)
113 background-image: url(image)
114 background-position: top left
115 background-repeat: no-repeat;
118 y = - (@height * n) - unit(v_offset, px)
119 background-position: (0 - unit(h_offset, px)) y
120 sprite(image, height, v_offset = 0, h_offset = 0)
121 sprites(image, height, 1, v_offset, h_offset)
123 // Styling for a variable height element with an image background where the
124 // middle repeats vertically. You must split your image into three images, and
125 // name them with "-top", "-mid" and "-bot" suffixes (right before the file
126 // extension.) then pass a filepath as the first argument to this function
127 // which does not have a suffix.
132 // i/foo-top.png (900x20)
133 // i/foo-mid.png (900xwhatever)
134 // i/foo-bot.png (900x30)
136 // dom layout: <div id="expando"><div><div><div>...</div></div></div></div>
141 // mangin: 10px auto;
143 // background_vertical_stretch("i/foo.png", 20, 30)
147 // You can (optionally) pass 1-4 additional arguments which
148 // (effectively) add padding to the inner most div. The default is to
149 // have the height and width of the inner div match exactly the outer
150 // one. Parameters you specify are relative to that (not the section
151 // filled with the "-mid" image).
152 background_vertical_stretch(image, top_height, bottom_height, top_pad = 0, right_pad = top_pad, bottom_pad = top_pad, left_pad = right_pad)
153 top_height = _px(top_height)
154 bottom_height = _px(bottom_height)
155 top_pad = _px(top_pad)
156 right_pad = _px(right_pad)
157 bottom_pad = _px(bottom_pad)
158 left_pad = _px(left_pad)
160 path = pathjoin(dirname(image), basename(image, ext))
162 // bottom image (outermost block)
163 background: transparent url(path + '-bot' + ext)
164 padding-bottom: bottom_height + 1 // +1 to prevent margin collapsing
166 background: transparent url(path + '-top' + ext) 0 0 no-repeat
167 padding-top: top_height + 1 // +1 to prevent margin collapsing
169 background: transparent url(path + '-mid' + ext) 0 0 repeat-y;
170 margin-top: -1px; // correct for above +1 from top
171 margin-bottom: -1px; // correct for above +1 from bottom
172 padding: 1px; // to prevent margin collapsing
174 // all "2px" below are to correct for 1px above padding and below
176 margin-top: 2px - top_height + top_pad
177 margin-left: left_pad - 2px
178 margin-right: right_pad - 2px
179 margin-bottom: 2px - bottom_height + bottom_pad
180 background: transparent;
192 &::-webkit-input-placeholder
194 &:-moz-placeholder // firefox 4-18
196 &::-moz-placeholder // firefox 19+
198 &:-ms-input-placeholder // ie
205 -webkit-touch-callout: none
206 -webkit-user-select: none
207 -khtml-user-select: none
208 -moz-user-select: none
209 -ms-user-select: none