Skip to content

Instantly share code, notes, and snippets.

@ericz
Created May 28, 2014 22:11
Show Gist options
  • Select an option

  • Save ericz/a937db66ce29d02e5703 to your computer and use it in GitHub Desktop.

Select an option

Save ericz/a937db66ce29d02e5703 to your computer and use it in GitHub Desktop.
#
# colorPicker
#
# Allows the user to select a color from available `colors`, and emits the selected color.
#
# Attributes:
# currColor: The currently selected color, as a hex string e.g. '#ffffff'
# colors: An array of available colors, as hex strings
# visible: true | false Show or hide the color selector
#
# Events:
# color-change ({color: '#ffffff'}) -> emits an object containing the `currColor` hex string when the currColor changes
#
# Example:
###
<color-picker
colors="colors"
curr-color="currColor"
visible="showColorPicker">
</color-picker>
###
module.exports = (app) ->
app.directive('colorPicker', ($rootScope) ->
component =
restrict: 'E'
scope:
colors: '='
currColor: '='
visible: '='
templateUrl: '/views/colorPicker.html'
controller: ($rootScope, $scope) ->
$scope.changeColor = (color) ->
$scope.currColor = color
$rootScope.$emit('color-change', {color: $scope.currColor})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment