//
// This mixin is an easy way to set the position of an element.
// Example: @include absolute(top 100% left 0);
//

@mixin position($position, $arguments) {
	@each $object in top right bottom left {
		$index: index($arguments, $object);
		@if $index and $index + 1 <= length($arguments) and type-of(nth($arguments, $index + 1)) == number {
			#{$object}: nth($arguments, $index + 1);
		}
	}
	position: $position;
}

//
// Absolute positioning helper mixin.
// Example: @include absolute(top 100% left 0);
//

@mixin absolute($arguments: '') {
	@include position(absolute, $arguments);
}

//
// Fixed positioning helper mixin.
// Example: @include fixed(top 0 left 0);
//

@mixin fixed($arguments: '') {
	@include position(fixed, $arguments);
}

//
// Relative positioning helper mixin.
// Example: @include relative;
//

@mixin relative($arguments: '') {
	@include position(relative, $arguments);
}

//
// Pseudo element mixin.
// Sets up the default properties of a pseudo element.
//

@mixin pseudo($display: block, $position: absolute, $content: '') {
	content: $content;
	display: $display;
	position: $position;
}

//
// Triangle mixin.
// This mixin generates a triangle.
//

@mixin triangle($color, $direction, $size: 6px, $position: absolute, $display: block, $round: false) {
	@include pseudo($display, $position);
	width: 0;
	height: 0;
	@if $round {
		border-radius: 3px;
	}
	@if $direction == down {
		border-left: $size solid transparent;
		border-right: $size solid transparent;
		border-top: $size solid $color;
		margin-top: 0 - round( $size / 2.5 );
	} @else if $direction == up {
		border-left: $size solid transparent;
		border-right: $size solid transparent;
		border-bottom: $size solid $color;
		margin-bottom: 0 - round( $size / 2.5 );
	} @else if $direction == right {
		border-top: $size solid transparent;
		border-bottom: $size solid transparent;
		border-left: $size solid $color;
		margin-right: -$size;
	} @else if $direction == left {
		border-top: $size solid transparent;
		border-bottom: $size solid transparent;
		border-right: $size solid $color;
		margin-left: -$size;
	}
}

//
// Device media query mixin.
// This generates a media query for a breakpoint.
//

@mixin device($width, $type: min) {
	@if map_has_key($breakpoints, $width) {
		$width: map_get($breakpoints, $width);
		@if $type == max {
			$width: $width - 1px;
		}
		@media only screen and (#{$type}-width: $width) {
			@content;
		}
	} @else {
		@error 'There is no item "#{$width}" in this list;';
	}
}

//
// Truncate a string based on a boundary.
//

@mixin truncate($boundary) {
	max-width: $boundary;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

@mixin placeholder($color) {
	&::-webkit-input-placeholder {
		color: $color;
	}
	&::-moz-placeholder {
		color: $color;
	}
	&:-ms-input-placeholder {
		color: $color;
	}
	&:-moz-placeholder {
		color: $color;
	}
}