Created
February 13, 2014 21:30
-
-
Save oaleynik/8984251 to your computer and use it in GitHub Desktop.
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
directivesModule | |
.directive('colorSource', [ | |
function () { | |
var linkFn = function colorPickerLinkFn(scope, element, attrs, ctrl) { | |
element.colorpicker({ | |
format: 'rgba' | |
}).on("changeColor", function cpChangeColorEventHandler(event) { | |
scope.$apply(function () { | |
var newColor = event.color.toRGB(); | |
// to rgba(255, 255, 255, 0.8) | |
// todo: replace this mokey code | |
newColor = 'rgba(_r_, _g_, _b_, _a_)' | |
.replace('_r_', newColor.r) | |
.replace('_g_', newColor.g) | |
.replace('_b_', newColor.b) | |
.replace('_a_', newColor.a); | |
ctrl.$setViewValue(newColor); | |
}); | |
}); | |
ctrl.$render = function cpRenderFn() { | |
element.data({ | |
"color": ctrl.$viewValue | |
}); | |
element.colorpicker('update'); | |
}; | |
}; | |
return { | |
require: "ngModel", | |
restrict: "A", | |
replace: true, | |
template: "<div class=\"colorSelector color\">" + "<input type=\"hidden\">" + "<span class=\"add-on\"><i style=\"\"></i></span>" + "</div>", | |
link: linkFn | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment