beautiful_scaffold 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2c5cc9830b52e9bdc57663e3e93779e3457502e4f3656f0c541b8213775edca
4
- data.tar.gz: 03260e7d438e1aa4c9161a5fdf1b221fd21c2acc4625857ac00eadf4686ac04c
3
+ metadata.gz: 29b4c80363aba59d47f1219a1dbc4b205a149b0d2745f6a295e1511a2898d96f
4
+ data.tar.gz: 13fe2f58f7b2a30e7eff49e55ab8d8ec1ac5e7d77f78b41f50ec18919fb2cb98
5
5
  SHA512:
6
- metadata.gz: d95e8b02e11a731844977432a230d83b200da69018184d3583a3ade48f448face2799f8e76bcb01ee13b40b7166813f0921fe57442db6fa7f18ec23eb6b62f79
7
- data.tar.gz: 7ab3d32603cf3c89f6c34a7d5798610b60ccbf701a3c8583eee89bdabadb0a090c96436e8e17c11f2c9d41d7ba4262820414b1096e54124df2b02cccaf9b777e
6
+ metadata.gz: ebd54c4c42924851fb5039d1edf3a749ff0b153f605cd1b9671c0a292d030a43d839bac61b8e830b3733d35694425a602f63f24fa81a357bd099dd1f12d91a43
7
+ data.tar.gz: 370ee3d28e84836c4f81d7dbedd894c5ccd56997d00e598d10959375c0037b5c8ce4802a28d1e6f819532c57b6d929583e3649a1d5cd8045f5bba225262bed2b
data/CHANGELOG CHANGED
@@ -4,6 +4,20 @@
4
4
 
5
5
  * bugfix
6
6
 
7
+
8
+ == Soon
9
+
10
+ ActionText / trix.
11
+
12
+ == 2.0.2
13
+
14
+ * enhancement
15
+ * Native html colorpicker
16
+
17
+ * bugfix
18
+ * Datetime picker for model form
19
+ * Display price in model form
20
+
7
21
  == 2.0.1
8
22
 
9
23
  * enhancement
@@ -1,3 +1,3 @@
1
1
  module BeautifulScaffold
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -63,7 +63,6 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
63
63
  bc_css = [
64
64
  "beautiful-scaffold.css.scss",
65
65
  "tagit-dark-grey.css",
66
- "colorpicker.css",
67
66
  "bootstrap-wysihtml5.css"
68
67
  ]
69
68
 
@@ -81,7 +80,6 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
81
80
  if !engine_name.blank?
82
81
  ['beautiful-scaffold',
83
82
  'tagit-dark-grey',
84
- 'colorpicker',
85
83
  'bootstrap-wysihtml5'].each do |fileassets|
86
84
  gsub_file File.join(stylesheetspath_dest, "application-bs.scss"), " *= require #{fileassets}", " *= require #{engine_name}#{fileassets}"
87
85
  end
@@ -103,7 +101,6 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
103
101
  "jquery-barcode.js",
104
102
  "jstree.min.js",
105
103
  "tagit.js",
106
- "bootstrap-colorpicker.js",
107
104
  "a-wysihtml5-0.3.0.min.js",
108
105
  "bootstrap-wysihtml5.js",
109
106
  "fixed_menu.js"
@@ -115,7 +112,6 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
115
112
 
116
113
  if !engine_name.blank?
117
114
  ['a-wysihtml5-0.3.0.min',
118
- 'bootstrap-colorpicker',
119
115
  'bootstrap-datetimepicker-for-beautiful-scaffold',
120
116
  'bootstrap-wysihtml5',
121
117
  'tagit.js',
@@ -4,7 +4,6 @@
4
4
  //= require popper
5
5
  //= require bootstrap-sprockets
6
6
  //= require a-wysihtml5-0.3.0.min
7
- //= require bootstrap-colorpicker
8
7
  //= require moment
9
8
  //= require moment/fr
10
9
  //= require tempusdominus-bootstrap-4.js
@@ -51,9 +51,8 @@ function bs_init(){
51
51
  $('.tagit-input').addClass("form-control");
52
52
  });
53
53
 
54
- // Wysiwyg and color field
54
+ // Wysiwyg field
55
55
  $('.wysiwyg-editor').wysihtml5({"html": true});
56
- $('.color').colorpicker({format: 'rgba'});
57
56
 
58
57
  // Processing
59
58
  $(document).on('click', '#checkall', function(){
@@ -1,21 +1,22 @@
1
1
  function datetimepicker_init(){
2
- $('.tpicker').datetimepicker({ format: 'LT' }).on('change.datetimepicker', function(elt){
3
- console.log('===============> time');
4
- console.log(elt);
5
- console.log($(elt.target).attr('data-field'));
2
+ $('.tpicker').datetimepicker({ format: 'LT', widgetPositioning: {
3
+ horizontal: 'auto',
4
+ vertical: 'auto'
5
+ } });
6
+ $('.tpicker').on('change.datetimepicker', function(elt){
6
7
  var eltid = $(elt.target).attr('data-field');
7
- $('#' + eltid + '_4i').val(elt.date.hour());
8
- $('#' + eltid + '_5i').val(elt.date.minute());
8
+ $('#' + eltid + '4i').val(elt.date.hour());
9
+ $('#' + eltid + '5i').val(elt.date.minute());
9
10
  });
10
-
11
- $('.dpicker').datetimepicker({ format: 'L' }).on('change.datetimepicker', function(elt){
12
- console.log('===============> date');
13
- console.log(elt);
14
- console.log($(elt.target).attr('data-field'));
11
+ $('.dpicker').datetimepicker({ format: 'L', widgetPositioning: {
12
+ horizontal: 'auto',
13
+ vertical: 'auto'
14
+ } });
15
+ $('.dpicker').on('change.datetimepicker', function(elt){
15
16
  var eltid = $(elt.target).attr('data-field');
16
- $('#' + eltid + '_3i').val(elt.date.date());
17
- $('#' + eltid + '_2i').val(elt.date.month()+1);
18
- $('#' + eltid + '_1i').val(elt.date.year());
17
+ $('#' + eltid + '3i').val(elt.date.date());
18
+ $('#' + eltid + '2i').val(elt.date.month()+1);
19
+ $('#' + eltid + '1i').val(elt.date.year());
19
20
  });
20
21
  $(document).on('click', '.dpicker', function(e){
21
22
  $(this).datetimepicker('show');
@@ -24,6 +25,6 @@ function datetimepicker_init(){
24
25
  $(this).datetimepicker('show');
25
26
  });
26
27
  $(".datetimepicker-input").each(function(i, elt){
27
- $(elt).removeAttr("name");
28
+ $(elt).removeAttr("name");
28
29
  });
29
30
  }
@@ -12,7 +12,6 @@
12
12
  *= require jquery-ui
13
13
  *= require beautiful-scaffold
14
14
  *= require tagit-dark-grey
15
- *= require colorpicker
16
15
  *= require bootstrap-wysihtml5
17
16
  *= require themes/default/style
18
17
  */
@@ -201,4 +201,10 @@ div.fixed.hide-menu{
201
201
 
202
202
  .title-index{
203
203
  font-size: 30px;
204
- }
204
+ }
205
+
206
+ .overview-color{
207
+ display:inline-block;
208
+ width: 40px;
209
+ height: 24px;
210
+ }
@@ -14,39 +14,47 @@
14
14
  <div class="form-group">
15
15
  <%%= f.label :<%= attribute.name %>, <%= i18n_t_a(singular_table_name, attribute.name) %>.capitalize, :class => "control-label" %>
16
16
  <div class="input-group">
17
- <span class="input-group-addon">$</span><%%= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => "form-control" %>
17
+ <span class="input-group-text">$</span><%%= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => "form-control" %>
18
18
  </div>
19
19
  </div>
20
- <%- elsif @beautiful_attributes.include?(attribute.name + ':date') -%>
20
+ <%- elsif (datetime_field = @beautiful_attributes.include?(attribute.name + ':datetime')) || @beautiful_attributes.include?(attribute.name + ':date') -%>
21
21
  <div class="form-group">
22
22
  <%%= f.label :<%= attribute.name %>, <%= i18n_t_a(singular_table_name, attribute.name) %>.capitalize, :class => "control-label" %>
23
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(3i)]" id="<%= singular_table_name %>_<%= attribute.name %>_3i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.day rescue "" end %>" />
24
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(2i)]" id="<%= singular_table_name %>_<%= attribute.name %>_2i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.mon rescue "" end %>" />
25
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(1i)]" id="<%= singular_table_name %>_<%= attribute.name %>_1i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.year rescue "" end %>" />
26
- <div class="input-group">
27
- <%%= f.text_field :<%= attribute.name %>, :value => (begin @<%= singular_table_name %>.<%= attribute.name %>.strftime("%d/%m/%Y") rescue "" end), :class => "dpicker form-control" %><span class="input-group-addon"><i class="fa fa-calendar"></i></span>
28
- </div>
29
- </div>
30
- <%- elsif @beautiful_attributes.include?(attribute.name + ':datetime') -%>
31
- <div class="form-group">
32
- <%%= f.label :<%= attribute.name %>, <%= i18n_t_a(singular_table_name, attribute.name) %>.capitalize, :class => "control-label" %>
33
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(3i)]" id="<%= singular_table_name %>_<%= attribute.name %>_3i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.day rescue "" end %>" />
34
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(2i)]" id="<%= singular_table_name %>_<%= attribute.name %>_2i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.mon rescue "" end %>" />
35
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(1i)]" id="<%= singular_table_name %>_<%= attribute.name %>_1i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.year rescue "" end %>" />
36
- <div class="input-group">
37
- <%%= f.text_field :<%= attribute.name %>, :value => (begin @<%= singular_table_name %>.<%= attribute.name %>.strftime("%d/%m/%Y") rescue "" end), :class => "dpicker form-control" %><span class="input-group-addon"><i class="fa fa-calendar"></i></span>
38
- </div>
39
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(4i)]" id="<%= singular_table_name %>_<%= attribute.name %>_4i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.min rescue "" end %>" />
40
- <input type="hidden" name="<%= singular_table_name %>[<%= attribute.name %>(5i)]" id="<%= singular_table_name %>_<%= attribute.name %>_5i" value="<%%= begin @<%= singular_table_name %>.<%= attribute.name %>.hour rescue "" end %>" />
41
- <div class="input-group">
42
- <%%= f.text_field :<%= attribute.name %>, :value => (begin @<%= singular_table_name %>.<%= attribute.name %>.strftime("%H:%M") rescue "" end), :class => "tpicker form-control" %><span class="input-group-addon"><i class="fa fa-clock-o"></i></span>
43
- </div>
23
+ <% if datetime_field %>
24
+ <div class="row">
25
+ <% end %>
26
+ <div id="container_<%= singular_table_name %>_<%= attribute.name %>_dp" data-field="<%= singular_table_name %>_<%= attribute.name %>_input_" class="input-group input-datetime dpicker <%= (datetime_field ? 'col-sm' : '') %>" data-target-input="nearest">
27
+ <%%= f.text_field :<%= attribute.name %>, :value => (begin @<%= singular_table_name %>.<%= attribute.name %>.strftime("%d/%m/%Y") rescue "" end),
28
+ :class => "form-control datetimepicker-input",
29
+ "data-target" => "#container_<%= singular_table_name %>_<%= attribute.name %>_dp",
30
+ "data-id" => "<%= singular_table_name %>_<%= attribute.name %>_input_", id: nil %>
31
+ <div class="input-group-append" data-target="container_<%= singular_table_name %>_<%= attribute.name %>_dp" data-toggle="datetimepicker">
32
+ <span class="input-group-text"><i class="fa fa-calendar"></i></span>
33
+ </div>
34
+ </div>
35
+ <% if datetime_field %>
36
+ <div id="container_<%= singular_table_name %>_<%= attribute.name %>_tp" data-field="<%= singular_table_name %>_<%= attribute.name %>_input_" class="input-group input-datetime tpicker col-sm" data-target-input="nearest">
37
+ <%%= f.text_field :<%= attribute.name %>, :value => (begin @<%= singular_table_name %>.<%= attribute.name %>.strftime("%H:%M") rescue "" end),
38
+ :class => "form-control datetimepicker-input",
39
+ "data-target" => "#container_<%= singular_table_name %>_<%= attribute.name %>_tp",
40
+ "data-id" => "<%= singular_table_name %>_<%= attribute.name %>_input_", id: nil %>
41
+ <div class="input-group-append" data-target="container_<%= singular_table_name %>_<%= attribute.name %>_tp" data-toggle="datetimepicker">
42
+ <span class="input-group-text"><i class="fa fa-clock"></i></span>
43
+ </div>
44
+ </div>
45
+ <% end %>
46
+ <%% ["year","mon","day" <%= datetime_field ? ',"min","hour"' : '' %>].each_with_index do |meth, i| %>
47
+ <%%= f.hidden_field("<%= attribute.name %>(#{i+1}i)", value: @<%= singular_table_name %>.<%= attribute.name %>&.send(meth), id: "<%= singular_table_name %>_<%= attribute.name %>_input_#{i+1}i") %>
48
+ <%% end %>
49
+ <% if datetime_field %>
50
+ </div>
51
+ <% end %>
44
52
  </div>
45
53
  <%- elsif @beautiful_attributes.include?(attribute.name + ':color') -%>
46
54
  <div class="form-group">
47
55
  <%%= f.label :<%= attribute.name %>, <%= i18n_t_a(singular_table_name, attribute.name) %>.capitalize, :class => "control-label" %>
48
- <div class="input-group color" data-color="<%%= (@<%= model %>.<%= attribute.name %> || "rgba(0, 0, 0)") %>" data-color-format="rgba">
49
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => "form-control" %><span class="input-group-addon"><i style="background-color: rgb(0, 0, 0)"></i></span>
56
+ <div class="input-group">
57
+ <%%= f.color_field :<%= attribute.name %>, :class => "form-control" %>
50
58
  </div>
51
59
  </div>
52
60
  <%- else -%>
@@ -10,6 +10,8 @@
10
10
  <%% else %>
11
11
  <%%= t(:any, :default => "Any") %>
12
12
  <%% end %>
13
+ <%- elsif @beautiful_attributes.include?(attribute.name + ':color') -%>
14
+ <span class="overview-color" style="background-color:<%%= <%= singular_table_name %>.<%= attribute.name %> %>;">&nbsp;</span>
13
15
  <%- else -%>
14
16
  <%%= <%= singular_table_name %>.<%= attribute.name %> %>
15
17
  <%- end -%>
@@ -7,6 +7,8 @@
7
7
  <%%= t((@<%= singular_table_name %>.<%= attribute.name %> ? "yes".to_sym : "no".to_sym)) %>
8
8
  <%- elsif @beautiful_attributes.include?(attribute.name + ':references') -%>
9
9
  <%%= (@<%= singular_table_name %>.<%= attribute.name %>.nil? ? "" : @<%= singular_table_name %>.<%= attribute.name %>.caption) %>
10
+ <%- elsif @beautiful_attributes.include?(attribute.name + ':color') -%>
11
+ <span class="overview-color" style="background-color:<%%= @<%= singular_table_name %>.<%= attribute.name %> %>;">&nbsp;</span>
10
12
  <%- else -%>
11
13
  <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
12
14
  <%- end -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beautiful_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Claudel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-18 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Beautiful Scaffold generate a complete scaffold (sort, export, paginate
14
14
  and filter data) http://beautiful-scaffold.rivsc.ovh
@@ -43,7 +43,6 @@ files:
43
43
  - lib/generators/templates/app/assets/javascripts/advanced.js
44
44
  - lib/generators/templates/app/assets/javascripts/application-bs.js
45
45
  - lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js
46
- - lib/generators/templates/app/assets/javascripts/bootstrap-colorpicker.js
47
46
  - lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js
48
47
  - lib/generators/templates/app/assets/javascripts/bootstrap-wysihtml5.js
49
48
  - lib/generators/templates/app/assets/javascripts/fixed_menu.js
@@ -54,7 +53,6 @@ files:
54
53
  - lib/generators/templates/app/assets/stylesheets/application-bs.css
55
54
  - lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss
56
55
  - lib/generators/templates/app/assets/stylesheets/bootstrap-wysihtml5.css
57
- - lib/generators/templates/app/assets/stylesheets/colorpicker.css
58
56
  - lib/generators/templates/app/assets/stylesheets/tagit-dark-grey.css
59
57
  - lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png
60
58
  - lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png
@@ -1,520 +0,0 @@
1
- /* =========================================================
2
- * bootstrap-colorpicker.js
3
- * http://www.eyecon.ro/bootstrap-colorpicker
4
- * =========================================================
5
- * Copyright 2012 Stefan Petre
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- * ========================================================= */
19
-
20
- !function( $ ) {
21
-
22
- // Color object
23
-
24
- var Color = function(val) {
25
- this.value = {
26
- h: 1,
27
- s: 1,
28
- b: 1,
29
- a: 1
30
- };
31
- this.setColor(val);
32
- };
33
-
34
- Color.prototype = {
35
- constructor: Color,
36
-
37
- //parse a string to HSB
38
- setColor: function(val){
39
- val = val.toLowerCase();
40
- var that = this;
41
- $.each( CPGlobal.stringParsers, function( i, parser ) {
42
- var match = parser.re.exec( val ),
43
- values = match && parser.parse( match ),
44
- space = parser.space||'rgba';
45
- if ( values ) {
46
- if (space == 'hsla') {
47
- that.value = CPGlobal.RGBtoHSB.apply(null, CPGlobal.HSLtoRGB.apply(null, values));
48
- } else {
49
- that.value = CPGlobal.RGBtoHSB.apply(null, values);
50
- }
51
- return false;
52
- }
53
- });
54
- },
55
-
56
- setHue: function(h) {
57
- this.value.h = 1- h;
58
- },
59
-
60
- setSaturation: function(s) {
61
- this.value.s = s;
62
- },
63
-
64
- setLightness: function(b) {
65
- this.value.b = 1- b;
66
- },
67
-
68
- setAlpha: function(a) {
69
- this.value.a = parseInt((1 - a)*100, 10)/100;
70
- },
71
-
72
- // HSBtoRGB from RaphaelJS
73
- // https://github.com/DmitryBaranovskiy/raphael/
74
- toRGB: function(h, s, b, a) {
75
- if (!h) {
76
- h = this.value.h;
77
- s = this.value.s;
78
- b = this.value.b;
79
- }
80
- h *= 360;
81
- var R, G, B, X, C;
82
- h = (h % 360) / 60;
83
- C = b * s;
84
- X = C * (1 - Math.abs(h % 2 - 1));
85
- R = G = B = b - C;
86
-
87
- h = ~~h;
88
- R += [C, X, 0, 0, X, C][h];
89
- G += [X, C, C, X, 0, 0][h];
90
- B += [0, 0, X, C, C, X][h];
91
- return {
92
- r: Math.round(R*255),
93
- g: Math.round(G*255),
94
- b: Math.round(B*255),
95
- a: a||this.value.a
96
- };
97
- },
98
-
99
- toHex: function(h, s, b, a){
100
- var rgb = this.toRGB(h, s, b, a);
101
- return '#'+((1 << 24) | (parseInt(rgb.r) << 16) | (parseInt(rgb.g) << 8) | parseInt(rgb.b)).toString(16).substr(1);
102
- },
103
-
104
- toHSL: function(h, s, b, a){
105
- if (!h) {
106
- h = this.value.h;
107
- s = this.value.s;
108
- b = this.value.b;
109
- }
110
- var H = h,
111
- L = (2 - s) * b,
112
- S = s * b;
113
- if (L > 0 && L <= 1) {
114
- S /= L;
115
- } else {
116
- S /= 2 - L;
117
- }
118
- L /= 2;
119
- if (S > 1) {
120
- S = 1;
121
- }
122
- return {
123
- h: H,
124
- s: S,
125
- l: L,
126
- a: a||this.value.a
127
- };
128
- }
129
- };
130
-
131
- // Picker object
132
-
133
- var Colorpicker = function(element, options){
134
- this.element = $(element);
135
- var format = options.format||this.element.data('color-format')||'hex';
136
- this.format = CPGlobal.translateFormats[format];
137
- this.isInput = this.element.is('input');
138
- this.component = this.element.is('.color') ? this.element.find('.input-group-addon') : false;
139
-
140
- this.picker = $(CPGlobal.template)
141
- .appendTo('body')
142
- .on('mousedown', $.proxy(this.mousedown, this));
143
-
144
- if (this.isInput) {
145
- this.element.on({
146
- 'focus': $.proxy(this.show, this),
147
- 'keyup': $.proxy(this.update, this)
148
- });
149
- } else if (this.component){
150
- this.component.on({
151
- 'click': $.proxy(this.show, this)
152
- });
153
- } else {
154
- this.element.on({
155
- 'click': $.proxy(this.show, this)
156
- });
157
- }
158
- if (format == 'rgba' || format == 'hsla') {
159
- this.picker.addClass('alpha');
160
- this.alpha = this.picker.find('.colorpicker-alpha')[0].style;
161
- }
162
-
163
- if (this.component){
164
- this.picker.find('.colorpicker-color').hide();
165
- this.preview = this.element.find('i')[0].style;
166
- } else {
167
- this.preview = this.picker.find('div:last')[0].style;
168
- }
169
-
170
- this.base = this.picker.find('div:first')[0].style;
171
- this.update();
172
- };
173
-
174
- Colorpicker.prototype = {
175
- constructor: Colorpicker,
176
-
177
- show: function(e) {
178
- this.picker.show();
179
- this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
180
- this.place();
181
- $(window).on('resize', $.proxy(this.place, this));
182
- if (!this.isInput) {
183
- if (e) {
184
- e.stopPropagation();
185
- e.preventDefault();
186
- }
187
- }
188
- $(document).on({
189
- 'mousedown': $.proxy(this.hide, this)
190
- });
191
- this.element.trigger({
192
- type: 'show',
193
- color: this.color
194
- });
195
- },
196
-
197
- update: function(){
198
- this.color = new Color(this.isInput ? this.element.prop('value') : this.element.data('color'));
199
- this.picker.find('i')
200
- .eq(0).css({left: this.color.value.s*100, top: 100 - this.color.value.b*100}).end()
201
- .eq(1).css('top', 100 * (1 - this.color.value.h)).end()
202
- .eq(2).css('top', 100 * (1 - this.color.value.a));
203
- this.previewColor();
204
- },
205
-
206
- hide: function(){
207
- this.picker.hide();
208
- $(window).off('resize', this.place);
209
- if (!this.isInput) {
210
- $(document).off({
211
- 'mousedown': this.hide
212
- });
213
- if (this.component){
214
- this.element.find('input').prop('value', this.format.call(this));
215
- }
216
- this.element.data('color', this.format.call(this));
217
- } else {
218
- this.element.prop('value', this.format.call(this));
219
- }
220
- this.element.trigger({
221
- type: 'hide',
222
- color: this.color
223
- });
224
- },
225
-
226
- place: function(){
227
- var offset = this.component ? this.component.offset() : this.element.offset();
228
- this.picker.css({
229
- top: offset.top + this.height,
230
- left: offset.left
231
- });
232
- },
233
-
234
- //preview color change
235
- previewColor: function(){
236
- this.preview.backgroundColor = this.format.call(this);
237
- //set the color for brightness/saturation slider
238
- this.base.backgroundColor = this.color.toHex(this.color.value.h, 1, 1, 1);
239
- //set te color for alpha slider
240
- if (this.alpha) {
241
- this.alpha.backgroundColor = this.color.toHex();
242
- }
243
- },
244
-
245
- pointer: null,
246
-
247
- slider: null,
248
-
249
- mousedown: function(e){
250
- e.stopPropagation();
251
- e.preventDefault();
252
-
253
- var target = $(e.target);
254
-
255
- //detect the slider and set the limits and callbacks
256
- var zone = target.closest('div');
257
- if (!zone.is('.colorpicker')) {
258
- if (zone.is('.colorpicker-saturation')) {
259
- this.slider = $.extend({}, CPGlobal.sliders['saturation']);
260
- }
261
- else if (zone.is('.colorpicker-hue')) {
262
- this.slider = $.extend({}, CPGlobal.sliders['hue']);
263
- }
264
- else if (zone.is('.colorpicker-alpha')) {
265
- this.slider = $.extend({}, CPGlobal.sliders['alpha']);
266
- }
267
- var offset = zone.offset();
268
- //reference to knob's style
269
- this.slider.knob = zone.find('i')[0].style;
270
- this.slider.left = e.pageX - offset.left;
271
- this.slider.top = e.pageY - offset.top;
272
- this.pointer = {
273
- left: e.pageX,
274
- top: e.pageY
275
- };
276
- //trigger mousemove to move the knob to the current position
277
- $(document).on({
278
- mousemove: $.proxy(this.mousemove, this),
279
- mouseup: $.proxy(this.mouseup, this)
280
- }).trigger('mousemove');
281
- }
282
- return false;
283
- },
284
-
285
- mousemove: function(e){
286
- e.stopPropagation();
287
- e.preventDefault();
288
- var left = Math.max(
289
- 0,
290
- Math.min(
291
- this.slider.maxLeft,
292
- this.slider.left + ((e.pageX||this.pointer.left) - this.pointer.left)
293
- )
294
- );
295
- var top = Math.max(
296
- 0,
297
- Math.min(
298
- this.slider.maxTop,
299
- this.slider.top + ((e.pageY||this.pointer.top) - this.pointer.top)
300
- )
301
- );
302
- this.slider.knob.left = left + 'px';
303
- this.slider.knob.top = top + 'px';
304
- if (this.slider.callLeft) {
305
- this.color[this.slider.callLeft].call(this.color, left/100);
306
- }
307
- if (this.slider.callTop) {
308
- this.color[this.slider.callTop].call(this.color, top/100);
309
- }
310
- this.previewColor();
311
- this.element.trigger({
312
- type: 'changeColor',
313
- color: this.color
314
- });
315
- return false;
316
- },
317
-
318
- mouseup: function(e){
319
- e.stopPropagation();
320
- e.preventDefault();
321
- $(document).off({
322
- mousemove: this.mousemove,
323
- mouseup: this.mouseup
324
- });
325
- return false;
326
- }
327
- }
328
-
329
- $.fn.colorpicker = function ( option ) {
330
- return this.each(function () {
331
- var $this = $(this),
332
- data = $this.data('colorpicker'),
333
- options = typeof option == 'object' && option;
334
- if (!data) {
335
- $this.data('colorpicker', (data = new Colorpicker(this, $.extend({}, $.fn.colorpicker.defaults,options))));
336
- }
337
- if (typeof option == 'string') data[option]();
338
- });
339
- };
340
-
341
- $.fn.colorpicker.defaults = {
342
- };
343
-
344
- $.fn.colorpicker.Constructor = Colorpicker;
345
-
346
- var CPGlobal = {
347
-
348
- // translate a format from Color object to a string
349
- translateFormats: {
350
- 'rgb': function(){
351
- var rgb = this.color.toRGB();
352
- return 'rgb('+rgb.r+','+rgb.g+','+rgb.b+')';
353
- },
354
-
355
- 'rgba': function(){
356
- var rgb = this.color.toRGB();
357
- return 'rgba('+rgb.r+','+rgb.g+','+rgb.b+','+rgb.a+')';
358
- },
359
-
360
- 'hsl': function(){
361
- var hsl = this.color.toHSL();
362
- return 'hsl('+Math.round(hsl.h*360)+','+Math.round(hsl.s*100)+'%,'+Math.round(hsl.l*100)+'%)';
363
- },
364
-
365
- 'hsla': function(){
366
- var hsl = this.color.toHSL();
367
- return 'hsla('+Math.round(hsl.h*360)+','+Math.round(hsl.s*100)+'%,'+Math.round(hsl.l*100)+'%,'+hsl.a+')';
368
- },
369
-
370
- 'hex': function(){
371
- return this.color.toHex();
372
- }
373
- },
374
-
375
- sliders: {
376
- saturation: {
377
- maxLeft: 100,
378
- maxTop: 100,
379
- callLeft: 'setSaturation',
380
- callTop: 'setLightness'
381
- },
382
-
383
- hue: {
384
- maxLeft: 0,
385
- maxTop: 100,
386
- callLeft: false,
387
- callTop: 'setHue'
388
- },
389
-
390
- alpha: {
391
- maxLeft: 0,
392
- maxTop: 100,
393
- callLeft: false,
394
- callTop: 'setAlpha'
395
- }
396
- },
397
-
398
- // HSBtoRGB from RaphaelJS
399
- // https://github.com/DmitryBaranovskiy/raphael/
400
- RGBtoHSB: function (r, g, b, a){
401
- r /= 255;
402
- g /= 255;
403
- b /= 255;
404
-
405
- var H, S, V, C;
406
- V = Math.max(r, g, b);
407
- C = V - Math.min(r, g, b);
408
- H = (C == 0 ? null :
409
- V == r ? (g - b) / C :
410
- V == g ? (b - r) / C + 2 :
411
- (r - g) / C + 4
412
- );
413
- H = ((H + 360) % 6) * 60 / 360;
414
- S = C == 0 ? 0 : C / V;
415
- return {h: H||1, s: S, b: V, a: a||1};
416
- },
417
-
418
- HueToRGB: function (p, q, h) {
419
- if (h < 0)
420
- h += 1;
421
- else if (h > 1)
422
- h -= 1;
423
-
424
- if ((h * 6) < 1)
425
- return p + (q - p) * h * 6;
426
- else if ((h * 2) < 1)
427
- return q;
428
- else if ((h * 3) < 2)
429
- return p + (q - p) * ((2 / 3) - h) * 6;
430
- else
431
- return p;
432
- },
433
-
434
- HSLtoRGB: function (h, s, l, a)
435
- {
436
-
437
- if (s < 0)
438
- s = 0;
439
-
440
- if (l <= 0.5)
441
- var q = l * (1 + s);
442
- else
443
- var q = l + s - (l * s);
444
-
445
- var p = 2 * l - q;
446
-
447
- var tr = h + (1 / 3);
448
- var tg = h;
449
- var tb = h - (1 / 3);
450
-
451
- var r = Math.round(CPGlobal.HueToRGB(p, q, tr) * 255);
452
- var g = Math.round(CPGlobal.HueToRGB(p, q, tg) * 255);
453
- var b = Math.round(CPGlobal.HueToRGB(p, q, tb) * 255);
454
- return [r, g, b, a||1];
455
- },
456
-
457
- // a set of RE's that can match strings and generate color tuples.
458
- // from John Resig color plugin
459
- // https://github.com/jquery/jquery-color/
460
- stringParsers: [
461
- {
462
- re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
463
- parse: function( execResult ) {
464
- return [
465
- execResult[ 1 ],
466
- execResult[ 2 ],
467
- execResult[ 3 ],
468
- execResult[ 4 ]
469
- ];
470
- }
471
- }, {
472
- re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
473
- parse: function( execResult ) {
474
- return [
475
- 2.55 * execResult[1],
476
- 2.55 * execResult[2],
477
- 2.55 * execResult[3],
478
- execResult[ 4 ]
479
- ];
480
- }
481
- }, {
482
- re: /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
483
- parse: function( execResult ) {
484
- return [
485
- parseInt( execResult[ 1 ], 16 ),
486
- parseInt( execResult[ 2 ], 16 ),
487
- parseInt( execResult[ 3 ], 16 )
488
- ];
489
- }
490
- }, {
491
- re: /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
492
- parse: function( execResult ) {
493
- return [
494
- parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
495
- parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
496
- parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
497
- ];
498
- }
499
- }, {
500
- re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
501
- space: 'hsla',
502
- parse: function( execResult ) {
503
- return [
504
- execResult[1]/360,
505
- execResult[2] / 100,
506
- execResult[3] / 100,
507
- execResult[4]
508
- ];
509
- }
510
- }
511
- ],
512
- template: '<div class="colorpicker dropdown-menu">'+
513
- '<div class="colorpicker-saturation"><i><b></b></i></div>'+
514
- '<div class="colorpicker-hue"><i></i></div>'+
515
- '<div class="colorpicker-alpha"><i></i></div>'+
516
- '<div class="colorpicker-color"><div /></div>'+
517
- '</div>'
518
- };
519
-
520
- }( window.jQuery )
@@ -1,127 +0,0 @@
1
- /*!
2
- * Colorpicker for Bootstrap
3
- *
4
- * Copyright 2012 Stefan Petre
5
- * Licensed under the Apache License v2.0
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- */
9
- .colorpicker-saturation {
10
- width: 100px;
11
- height: 100px;
12
- background-image: url(/assets/saturation.png);
13
- cursor: crosshair;
14
- float: left;
15
- }
16
- .colorpicker-saturation i {
17
- display: block;
18
- height: 5px;
19
- width: 5px;
20
- border: 1px solid #000;
21
- -webkit-border-radius: 5px;
22
- -moz-border-radius: 5px;
23
- border-radius: 5px;
24
- position: absolute;
25
- top: 0;
26
- left: 0;
27
- margin: -4px 0 0 -4px;
28
- }
29
- .colorpicker-saturation i b {
30
- display: block;
31
- height: 5px;
32
- width: 5px;
33
- border: 1px solid #fff;
34
- -webkit-border-radius: 5px;
35
- -moz-border-radius: 5px;
36
- border-radius: 5px;
37
- }
38
- .colorpicker-hue, .colorpicker-alpha {
39
- width: 15px;
40
- height: 100px;
41
- float: left;
42
- cursor: row-resize;
43
- margin-left: 4px;
44
- margin-bottom: 4px;
45
- }
46
- .colorpicker-hue i, .colorpicker-alpha i {
47
- display: block;
48
- height: 1px;
49
- background: #000;
50
- border-top: 1px solid #fff;
51
- position: absolute;
52
- top: 0;
53
- left: 0;
54
- width: 100%;
55
- margin-top: -1px;
56
- }
57
- .colorpicker-hue {
58
- background-image: url(/assets/hue.png);
59
- }
60
- .colorpicker-alpha {
61
- background-image: url(/assets/alpha.png);
62
- display: none;
63
- }
64
- .colorpicker {
65
- *zoom: 1;
66
- top: 0;
67
- left: 0;
68
- padding: 4px;
69
- min-width: 120px;
70
- margin-top: 1px;
71
- -webkit-border-radius: 4px;
72
- -moz-border-radius: 4px;
73
- border-radius: 4px;
74
- }
75
- .colorpicker:before, .colorpicker:after {
76
- display: table;
77
- content: "";
78
- }
79
- .colorpicker:after {
80
- clear: both;
81
- }
82
- .colorpicker:before {
83
- content: '';
84
- display: inline-block;
85
- border-left: 7px solid transparent;
86
- border-right: 7px solid transparent;
87
- border-bottom: 7px solid #ccc;
88
- border-bottom-color: rgba(0, 0, 0, 0.2);
89
- position: absolute;
90
- top: -7px;
91
- left: 6px;
92
- }
93
- .colorpicker:after {
94
- content: '';
95
- display: inline-block;
96
- border-left: 6px solid transparent;
97
- border-right: 6px solid transparent;
98
- border-bottom: 6px solid #ffffff;
99
- position: absolute;
100
- top: -6px;
101
- left: 7px;
102
- }
103
- .colorpicker div {
104
- position: relative;
105
- }
106
- .colorpicker.alpha {
107
- min-width: 140px;
108
- }
109
- .colorpicker.alpha .colorpicker-alpha {
110
- display: block;
111
- }
112
- .colorpicker-color {
113
- height: 10px;
114
- margin-top: 5px;
115
- clear: both;
116
- background-image: url(/assets/alpha.png);
117
- background-position: 0 100%;
118
- }
119
- .colorpicker-color div {
120
- height: 10px;
121
- }
122
- .input-group.color .input-group-addon i, .input-group.color .input-group-addon i {
123
- display: block;
124
- cursor: pointer;
125
- width: 16px;
126
- height: 16px;
127
- }