├── LICENSE
├── README.md
├── angular-colorpicker-dr.css
├── angular-colorpicker-dr.js
├── bower.json
├── example.html
└── package.json
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Daniel Reznick
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Angular Color Picker
2 | =====
3 |
4 | Description:
5 | =====
6 |
7 | The color picker for AngularJS - Native / Simple / Cool. No other dependencies are needed at all.
8 |
9 |
10 | Features:
11 | =====
12 |
13 | - Can extend simple input
14 | - Can replace a div (or any other container) with an inline color picker
15 | - Can replace any HTML element with a cool tiny trigger
16 | - Can color the extended input
17 |
18 | Examples:
19 | =====
20 |
21 | 
22 |
23 |
24 |
25 |
26 |
',
38 | templateInline = '
',
39 | template =
40 | '
' +
41 | '
' +
42 | '' +
43 | ' ' +
44 | '' +
45 | ' ' +
46 | '' +
47 | ' ' +
48 | '' +
49 | ' ' +
50 | '
' +
51 | '
' +
52 | '
' +
53 | '
' +
54 | '' +
55 | ' ' +
56 | '' +
57 | ' ' +
58 | '' +
59 | ' ' +
60 | '' +
61 | ' ' +
62 | '
' +
63 | '
' +
64 | '
' +
65 | '
' +
66 | '' +
67 | ' ' +
68 | '' +
69 | ' ' +
70 | '' +
71 | ' ' +
72 | '' +
73 | ' ' +
74 | '
' +
75 | '
' +
76 | '
' +
77 | '
' +
78 | '' +
79 | ' ' +
80 | '' +
81 | ' ' +
82 | '' +
83 | ' ' +
84 | '' +
85 | ' ' +
86 | '
' +
87 | '
' +
88 | '
',
89 | templateTinyTrigger =
90 | '
' +
91 | '
' +
92 | '
' +
93 | '' +
94 | ' ' +
95 | '' +
96 | ' ' +
97 | '' +
98 | ' ' +
99 | '' +
100 | ' ' +
101 | '
' +
102 | '
' +
103 | '
' +
104 | '
' +
105 | '' +
106 | ' ' +
107 | '' +
108 | ' ' +
109 | '' +
110 | ' ' +
111 | '' +
112 | ' ' +
113 | '
' +
114 | '
' +
115 | '
' +
116 | '
' +
117 | '' +
118 | ' ' +
119 | '' +
120 | ' ' +
121 | '' +
122 | ' ' +
123 | '' +
124 | ' ' +
125 | '
' +
126 | '
' +
127 | '
' +
128 | '
' +
129 | '' +
130 | ' ' +
131 | '' +
132 | ' ' +
133 | '' +
134 | ' ' +
135 | '' +
136 | ' ' +
137 | '
' +
138 | '
' +
139 | '
',
140 | elementTinyTrigger,
141 | elementColorPicker,
142 | closestFunc,
143 | prevFunc;
144 | prevFunc = function (elem) {
145 | if (elem.previousElementSibling) {
146 | return elem.previousElementSibling;
147 | }
148 | while (elem = elem.previousSibling) {
149 | if (elem.nodeType === 1) {
150 | return elem;
151 | }
152 | }
153 | };
154 | closestFunc = function (elem, cls) {
155 | var found = false;
156 | while (elem.parent() !== undefined && found === false) {
157 | if (elem.parent().hasClass(cls)) {
158 | found = true;
159 | }
160 | elem = elem.parent();
161 | }
162 | return elem;
163 | };
164 | if (scope.tinyTrigger !== undefined && scope.tinyTrigger === 'true') {
165 | templateTinyTrigger = templateTinyTrigger.replace('picker-icon', 'picker-icon trigger');
166 | elementTinyTrigger = $compile(templateTinyTrigger)(scope);
167 | element.replaceWith(elementTinyTrigger);
168 |
169 | template = templateHidden + template;
170 | elementColorPicker = angular.element(template);
171 | elementColorPicker.find('cp-color').on('click', function (ev) {
172 | ngModel.$setViewValue(angular.element(ev.target).attr('color'));
173 | });
174 | angular.element(document.body).append(elementColorPicker);
175 |
176 | elementTinyTrigger.bind("click", function (ev) {
177 | var wrapper = closestFunc(angular.element(ev.target), 'color-picker-wrapper'),
178 | top = wrapper[0].getBoundingClientRect().top,
179 | height = wrapper[0].getBoundingClientRect().height;
180 | top = top + $window.pageYOffset;
181 |
182 | elementColorPicker.removeClass('hide');
183 | elementColorPicker[0].style.top = top + height + 'px';
184 | elementColorPicker[0].style.left = wrapper[0].getBoundingClientRect().left + 'px';
185 | ev.stopPropagation();
186 | });
187 |
188 | } else {
189 | if (element[0].tagName === 'INPUT') {
190 |
191 | template = templateHidden + template;
192 | elementColorPicker = angular.element(template);
193 | elementColorPicker.find('cp-color').on('click', function (ev) {
194 | var color = angular.element(ev.target).attr('color');
195 | ngModel.$setViewValue(color);
196 | if (scope.colorMe !== undefined && scope.colorMe === 'true') {
197 | element[0].style.backgroundColor = color;
198 | } else {
199 | element.val(color);
200 | }
201 | });
202 | angular.element(document.body).append(elementColorPicker);
203 |
204 | element.bind("click", function (ev) {
205 | //show color picker beneath the input
206 | var top = ev.target.getBoundingClientRect().top,
207 | height = ev.target.getBoundingClientRect().height;
208 | top = top + $window.pageYOffset;
209 |
210 | elementColorPicker.removeClass('hide');
211 | elementColorPicker[0].style.top = top + height + 'px';
212 | elementColorPicker[0].style.left = ev.target.getBoundingClientRect().left + 'px';
213 | ev.stopPropagation();
214 | });
215 |
216 | elementTinyTrigger = $compile(templateTinyTrigger)(scope);
217 | element.after(elementTinyTrigger);
218 | elementTinyTrigger.bind("click", function (ev) {
219 | //show color picker beneath the input
220 | var $wrapper = closestFunc(angular.element(ev.target), 'color-picker-wrapper'),
221 | wrapperPrev = prevFunc($wrapper[0]),
222 | top = wrapperPrev.getBoundingClientRect().top,
223 | height = wrapperPrev.getBoundingClientRect().height;
224 | top = top + $window.pageYOffset;
225 |
226 | elementColorPicker.removeClass('hide');
227 | elementColorPicker[0].style.top = top + height + 'px';
228 | elementColorPicker[0].style.left = wrapperPrev.getBoundingClientRect().left + 'px';
229 | ev.stopPropagation();
230 | });
231 |
232 | $compile(content)(scope);
233 | } else {
234 | //replace element with the color picker
235 | template = templateInline + template;
236 | elementColorPicker = $compile(template)(scope);
237 | element.replaceWith(elementColorPicker);
238 | elementColorPicker.find('cp-color').on('click', function (ev) {
239 | ngModel.$setViewValue(angular.element(ev.target).attr('color'));
240 | ev.stopPropagation();
241 | });
242 | }
243 | }
244 | //when clicking somewhere on the screen / body -> hide the color picker
245 | $document.bind("click", function (ev) {
246 | var i,
247 | docChildren = $document.find('body').children();
248 | for (i = 0; i < docChildren.length; i++) {
249 | if (docChildren[i].getAttribute("class") && docChildren[i].getAttribute("class").indexOf('color-picker-wrapper body') !== -1) {
250 | angular.element(docChildren[i]).addClass('hide');
251 | }
252 | }
253 | });
254 | }
255 | };
256 | };
257 | angular.module('colorpicker-dr', []).directive('colorPicker',['$compile', '$document', '$window', directive]);
258 | }());
259 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "author": "Daniel Reznick",
3 | "name": "angular-colorpicker-dr",
4 | "description": "The color picker for AngularJS - Native / Simple / Cool. No other dependencies are needed at all.",
5 | "version": "0.1.0",
6 | "homepage": "http://vedmack.github.io/angular-colorpicker/",
7 | "repository": {
8 | "type": "git",
9 | "url": "https://github.com/vedmack/angular-colorpicker/"
10 | },
11 | "main": [
12 | "angular-colorpicker-dr.js",
13 | "angular-colorpicker-dr.css"
14 | ],
15 | "ignore": [],
16 | "dependencies": {
17 | "angular": ">=1.3.0"
18 | },
19 | "keywords": [
20 | "angular",
21 | "color-picker",
22 | "colorpicker",
23 | "directive",
24 | "module"
25 | ],
26 | "license": "MIT"
27 | }
--------------------------------------------------------------------------------
/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Angular Color Picker by Daniel Reznick
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
89 |
90 |
91 |
92 |
93 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
Angular Color Picker
105 |
The color picker for AngularJS - Native / Simple / Cool
106 |
113 |
114 |
115 |
116 |
117 |
Using with an input
118 |
119 |
120 |
121 |
122 | <input color-picker ng-model="colorValueInput">
123 |
124 |
125 |
126 |
127 |
Replacing a div (or any other container) with an inline color picker
128 |
129 |
value : {{colorValueInline}}
130 |
131 |
132 |
133 | <div color-picker ng-model="colorValueInline"></div>
134 |
135 |
136 |
137 |
138 |
Replacing any HTML element with a cool tiny trigger (click on the little colored square)
139 |
140 |
value : {{colorValueTinyTrigger}}
141 |
142 |
143 |
144 | <input color-picker tiny-trigger="true" ng-model="colorValueTinyTrigger">
145 |
146 |
147 |
148 |
149 |
Coloring the input with the selected color
150 |
151 |
152 |
153 |
154 | <input color-picker color-me="true" ng-model="colorValueInputColor">
155 |
156 |
157 |
158 |
159 |
160 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-colorpicker-dr",
3 | "version": "0.1.0",
4 | "author": {
5 | "name": "Daniel Reznick",
6 | "url": "https://github.com/vedmack"
7 | },
8 | "license": "MIT"
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/vedmack/angular-colorpicker.git"
12 | },
13 | "homepage": "http://vedmack.github.io/angular-colorpicker/",
14 | "bugs": {
15 | "url": "https://github.com/vedmack/angular-colorpicker/issues"
16 | },
17 | "main": "jquery.dataTables.yadcf.js",
18 | "files": [
19 | "angular-colorpicker-dr.js",
20 | "angular-colorpicker-dr.css"
21 | ],
22 | "description": "The color picker for AngularJS - Native / Simple / Cool. No other dependencies are needed at all.",
23 | "keywords": [
24 | "angular",
25 | "color-picker",
26 | "colorpicker",
27 | "directive",
28 | "module"
29 | ],
30 | "dependencies": {
31 | "angular": ">=1.3.0"
32 | },
33 | }
34 |
--------------------------------------------------------------------------------