Debian Codegraph @

lib/compass/utilities/sprites/_base.scss

raw
1 // Determines those states for which you want to enable magic sprite selectors
2 $sprite-selectors: hover, target, active !default;
3
4 // Set the width and height of an element to the original
5 // dimensions of an image before it was included in the sprite.
6 @mixin sprite-dimensions($map, $sprite) {
7 height: image-height(sprite-file($map, $sprite));
8 width: image-width(sprite-file($map, $sprite));
9 }
10
11 // Set the background position of the given sprite `$map` to display the
12 // sprite of the given `$sprite` name. You can move the image relative to its
13 // natural position by passing `$offset-x` and `$offset-y`.
14 @mixin sprite-background-position($map, $sprite, $offset-x: 0, $offset-y: 0) {
15 background-position: sprite-position($map, $sprite, $offset-x, $offset-y);
16 }
17
18
19 // Determines if you want to include magic selectors in your sprites
20 $disable-magic-sprite-selectors:false !default;
21
22 // Include the position and (optionally) dimensions of this `$sprite`
23 // in the given sprite `$map`. The sprite url should come from either a base
24 // class or you can specify the `sprite-url` explicitly like this:
25 //
26 // background: $map no-repeat;
27 @mixin sprite($map, $sprite, $dimensions: false, $offset-x: 0, $offset-y: 0) {
28 @include sprite-background-position($map, $sprite, $offset-x, $offset-y);
29 @if $dimensions {
30 @include sprite-dimensions($map, $sprite);
31 }
32 @if not($disable-magic-sprite-selectors) {
33 @include sprite-selectors($map, $sprite, $sprite, $offset-x, $offset-y);
34 }
35 }
36
37 // Include the selectors for the `$sprite` given the `$map` and the
38 // `$full-sprite-name`
39 // @private
40 @mixin sprite-selectors($map, $sprite-name, $full-sprite-name, $offset-x: 0, $offset-y: 0) {
41 @each $selector in $sprite-selectors {
42 @if sprite_has_selector($map, $sprite-name, $selector) {
43 &:#{$selector}, &.#{$full-sprite-name}_#{$selector}, &.#{$full-sprite-name}-#{$selector} {
44 @include sprite-background-position($map, "#{$sprite-name}_#{$selector}", $offset-x, $offset-y);
45 }
46 }
47 }
48 }
49
50 // Generates a class for each space separated name in `$sprite-names`.
51 // The class will be of the form .<map-name>-<sprite-name>.
52 //
53 // If a base class is provided, then each class will extend it.
54 //
55 // If `$dimensions` is `true`, the sprite dimensions will specified.
56 @mixin sprites($map, $sprite-names, $base-class: false, $dimensions: false, $prefix: sprite-map-name($map), $offset-x: 0, $offset-y: 0) {
57 @each $sprite-name in $sprite-names {
58 @if sprite_does_not_have_parent($map, $sprite-name) {
59 $full-sprite-name: "#{$prefix}-#{$sprite-name}";
60 .#{$full-sprite-name} {
61 @if $base-class { @extend #{$base-class}; }
62 @include sprite($map, $sprite-name, $dimensions, $offset-x, $offset-y);
63 }
64 }
65 }
66 }