Last active
December 21, 2015 17:38
-
-
Save cocopon/6341356 to your computer and use it in GitHub Desktop.
Sass transparent color function for legacy IE (<= 8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sass::Script::Functions | |
def ms_filter_rgba(*args) | |
if args.size == 4 | |
red, green, blue, alpha = args | |
return ms_rgba(rgb(red, green, blue), alpha) | |
end | |
if args.size != 2 | |
raise ArgumentError.new("wrong number of arguments (#{args.size} for 2 or 4") | |
end | |
color, alpha = args | |
assert_type color, :Color, :color | |
assert_type alpha, :Number, :alpha | |
Sass::Util.check_range('Alpha channel', 0..1, alpha) | |
hex = '#%02x%02x%02x%02x' % [ | |
alpha.value * 255, | |
color.red, | |
color.green, | |
color.blue] | |
retval = "progid:DXImageTransform.Microsoft.gradient(startColorStr='#{hex}', endColorStr='#{hex}')" | |
return Sass::Script::String.new(retval) | |
end | |
declare :ms_filter_rgba, [:red, :green, :blue, :alpha] | |
declare :ms_filter_rgba, [:color, :alpha] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment