beautiful_scaffold 2.0.0.pre → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG +45 -0
  4. data/Gemfile +5 -4
  5. data/README.rdoc +22 -4
  6. data/Rakefile +0 -3
  7. data/beautiful_scaffold.gemspec +0 -2
  8. data/lib/beautiful_scaffold/version.rb +1 -1
  9. data/lib/generators/USAGE +25 -11
  10. data/lib/generators/beautiful_cancancan_generator.rb +51 -0
  11. data/lib/generators/beautiful_jointable_generator.rb +3 -5
  12. data/lib/generators/beautiful_locale_generator.rb +15 -13
  13. data/lib/generators/beautiful_migration_generator.rb +3 -1
  14. data/lib/generators/beautiful_scaffold_common_methods.rb +10 -2
  15. data/lib/generators/beautiful_scaffold_generator.rb +2 -10
  16. data/lib/generators/beautiful_sorcery_generator.rb +137 -0
  17. data/lib/generators/beautiful_storage_generator.rb +61 -0
  18. data/lib/generators/templates/app/assets/javascripts/application-bs.js +0 -2
  19. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +15 -30
  20. data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +16 -15
  21. data/lib/generators/templates/app/assets/stylesheets/application-bs.css +0 -2
  22. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +9 -1
  23. data/lib/generators/templates/app/controllers/user_sessions_controller.rb +20 -0
  24. data/lib/generators/templates/app/helpers/beautiful_helper.rb +19 -5
  25. data/lib/generators/templates/app/locales/beautiful_scaffold.en.yml +8 -0
  26. data/lib/generators/templates/app/locales/beautiful_scaffold.fr.yml +9 -1
  27. data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +9 -2
  28. data/lib/generators/templates/app/mailers/user_mailer.rb +13 -0
  29. data/lib/generators/templates/app/models/ability.rb +39 -0
  30. data/lib/generators/templates/app/models/concerns/caption_concern.rb +1 -1
  31. data/lib/generators/templates/app/models/user.rb +11 -0
  32. data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +3 -3
  33. data/lib/generators/templates/app/views/layout.html.erb +12 -2
  34. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.html.erb +16 -0
  35. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.text.erb +9 -0
  36. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.html.erb +16 -0
  37. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.text.erb +8 -0
  38. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.html.erb +19 -0
  39. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.text.erb +8 -0
  40. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.html.erb +19 -0
  41. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.text.erb +8 -0
  42. data/lib/generators/templates/app/views/login_logout/user_sessions/_form.html.erb +15 -0
  43. data/lib/generators/templates/app/views/login_logout/user_sessions/new.html.erb +3 -0
  44. data/lib/generators/templates/app/views/partials/_form_field.html.erb +33 -25
  45. data/lib/generators/templates/app/views/partials/_index_column.html.erb +2 -0
  46. data/lib/generators/templates/app/views/partials/_login_logout_register.html.erb +7 -0
  47. data/lib/generators/templates/app/views/partials/_show_field.html.erb +2 -0
  48. metadata +23 -15
  49. data/Gemfile.lock +0 -209
  50. data/lib/generators/beautiful_devisecancan_generator.rb +0 -128
  51. data/lib/generators/templates/app/assets/javascripts/bootstrap-colorpicker.js +0 -520
  52. data/lib/generators/templates/app/assets/javascripts/tagit.js +0 -489
  53. data/lib/generators/templates/app/assets/stylesheets/colorpicker.css +0 -127
  54. data/lib/generators/templates/app/assets/stylesheets/tagit-dark-grey.css +0 -135
  55. data/lib/generators/templates/app/views/partials/_register_form.html.erb +0 -44
  56. data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +0 -18
  57. data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +0 -19
  58. data/lib/generators/templates/lib/custom_failure.rb +0 -15
data/Gemfile.lock DELETED
@@ -1,209 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- beautiful_scaffold (1.0.3)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- actioncable (6.0.3.2)
10
- actionpack (= 6.0.3.2)
11
- nio4r (~> 2.0)
12
- websocket-driver (>= 0.6.1)
13
- actionmailbox (6.0.3.2)
14
- actionpack (= 6.0.3.2)
15
- activejob (= 6.0.3.2)
16
- activerecord (= 6.0.3.2)
17
- activestorage (= 6.0.3.2)
18
- activesupport (= 6.0.3.2)
19
- mail (>= 2.7.1)
20
- actionmailer (6.0.3.2)
21
- actionpack (= 6.0.3.2)
22
- actionview (= 6.0.3.2)
23
- activejob (= 6.0.3.2)
24
- mail (~> 2.5, >= 2.5.4)
25
- rails-dom-testing (~> 2.0)
26
- actionpack (6.0.3.2)
27
- actionview (= 6.0.3.2)
28
- activesupport (= 6.0.3.2)
29
- rack (~> 2.0, >= 2.0.8)
30
- rack-test (>= 0.6.3)
31
- rails-dom-testing (~> 2.0)
32
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
- actiontext (6.0.3.2)
34
- actionpack (= 6.0.3.2)
35
- activerecord (= 6.0.3.2)
36
- activestorage (= 6.0.3.2)
37
- activesupport (= 6.0.3.2)
38
- nokogiri (>= 1.8.5)
39
- actionview (6.0.3.2)
40
- activesupport (= 6.0.3.2)
41
- builder (~> 3.1)
42
- erubi (~> 1.4)
43
- rails-dom-testing (~> 2.0)
44
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
- activejob (6.0.3.2)
46
- activesupport (= 6.0.3.2)
47
- globalid (>= 0.3.6)
48
- activemodel (6.0.3.2)
49
- activesupport (= 6.0.3.2)
50
- activerecord (6.0.3.2)
51
- activemodel (= 6.0.3.2)
52
- activesupport (= 6.0.3.2)
53
- activestorage (6.0.3.2)
54
- actionpack (= 6.0.3.2)
55
- activejob (= 6.0.3.2)
56
- activerecord (= 6.0.3.2)
57
- marcel (~> 0.3.1)
58
- activesupport (6.0.3.2)
59
- concurrent-ruby (~> 1.0, >= 1.0.2)
60
- i18n (>= 0.7, < 2)
61
- minitest (~> 5.1)
62
- tzinfo (~> 1.1)
63
- zeitwerk (~> 2.2, >= 2.2.2)
64
- autoprefixer-rails (9.8.6.1)
65
- execjs
66
- bootstrap (4.3.1)
67
- autoprefixer-rails (>= 9.1.0)
68
- popper_js (>= 1.14.3, < 2)
69
- sassc-rails (>= 2.0.0)
70
- bootstrap4-datetime-picker-rails (0.3.1)
71
- jquery-rails (~> 4.2, >= 4.2.0)
72
- moment-timezone-rails (~> 1.0)
73
- momentjs-rails (>= 2.10.5, <= 3.0.0)
74
- builder (3.2.4)
75
- concurrent-ruby (1.1.7)
76
- crass (1.0.6)
77
- erubi (1.9.0)
78
- execjs (2.7.0)
79
- ffi (1.13.1)
80
- font-awesome-rails (4.7.0.5)
81
- railties (>= 3.2, < 6.1)
82
- globalid (0.4.2)
83
- activesupport (>= 4.2.0)
84
- i18n (1.8.5)
85
- concurrent-ruby (~> 1.0)
86
- jquery-rails (4.3.1)
87
- rails-dom-testing (>= 1, < 3)
88
- railties (>= 4.2.0)
89
- thor (>= 0.14, < 2.0)
90
- jquery-ui-rails (6.0.1)
91
- railties (>= 3.2.16)
92
- loofah (2.6.0)
93
- crass (~> 1.0.2)
94
- nokogiri (>= 1.5.9)
95
- mail (2.7.1)
96
- mini_mime (>= 0.1.1)
97
- marcel (0.3.3)
98
- mimemagic (~> 0.3.2)
99
- method_source (1.0.0)
100
- mimemagic (0.3.5)
101
- mini_mime (1.0.2)
102
- mini_portile2 (2.4.0)
103
- minitest (5.14.1)
104
- moment-timezone-rails (1.0.0)
105
- momentjs-rails (>= 2.10.5, <= 3.0.0)
106
- momentjs-rails (2.20.1)
107
- railties (>= 3.1)
108
- nio4r (2.5.2)
109
- nokogiri (1.10.10)
110
- mini_portile2 (~> 2.4.0)
111
- nokogumbo (2.0.2)
112
- nokogiri (~> 1.8, >= 1.8.4)
113
- pdf-core (0.8.1)
114
- polyamorous (2.3.2)
115
- activerecord (>= 5.2.1)
116
- popper_js (1.16.0)
117
- prawn (2.3.0)
118
- pdf-core (~> 0.8.1)
119
- ttfunk (~> 1.6)
120
- prawn-table (0.2.2)
121
- prawn (>= 1.3.0, < 3.0.0)
122
- rack (2.2.3)
123
- rack-test (1.1.0)
124
- rack (>= 1.0, < 3)
125
- rails (6.0.3.2)
126
- actioncable (= 6.0.3.2)
127
- actionmailbox (= 6.0.3.2)
128
- actionmailer (= 6.0.3.2)
129
- actionpack (= 6.0.3.2)
130
- actiontext (= 6.0.3.2)
131
- actionview (= 6.0.3.2)
132
- activejob (= 6.0.3.2)
133
- activemodel (= 6.0.3.2)
134
- activerecord (= 6.0.3.2)
135
- activestorage (= 6.0.3.2)
136
- activesupport (= 6.0.3.2)
137
- bundler (>= 1.3.0)
138
- railties (= 6.0.3.2)
139
- sprockets-rails (>= 2.0.0)
140
- rails-dom-testing (2.0.3)
141
- activesupport (>= 4.2.0)
142
- nokogiri (>= 1.6)
143
- rails-html-sanitizer (1.3.0)
144
- loofah (~> 2.3)
145
- railties (6.0.3.2)
146
- actionpack (= 6.0.3.2)
147
- activesupport (= 6.0.3.2)
148
- method_source
149
- rake (>= 0.8.7)
150
- thor (>= 0.20.3, < 2.0)
151
- rake (13.0.1)
152
- ransack (2.3.2)
153
- activerecord (>= 5.2.1)
154
- activesupport (>= 5.2.1)
155
- i18n
156
- polyamorous (= 2.3.2)
157
- sanitize (5.2.1)
158
- crass (~> 1.0.2)
159
- nokogiri (>= 1.8.0)
160
- nokogumbo (~> 2.0)
161
- sassc (2.4.0)
162
- ffi (~> 1.9)
163
- sassc-rails (2.1.2)
164
- railties (>= 4.0.0)
165
- sassc (>= 2.0)
166
- sprockets (> 3.0)
167
- sprockets-rails
168
- tilt
169
- sprockets (3.7.2)
170
- concurrent-ruby (~> 1.0)
171
- rack (> 1, < 3)
172
- sprockets-rails (3.2.1)
173
- actionpack (>= 4.0)
174
- activesupport (>= 4.0)
175
- sprockets (>= 3.0.0)
176
- sqlite3 (1.4.2)
177
- thor (0.20.3)
178
- thread_safe (0.3.6)
179
- tilt (2.0.10)
180
- ttfunk (1.6.2.1)
181
- tzinfo (1.2.7)
182
- thread_safe (~> 0.1)
183
- websocket-driver (0.7.3)
184
- websocket-extensions (>= 0.1.0)
185
- websocket-extensions (0.1.5)
186
- will_paginate (3.3.0)
187
- zeitwerk (2.4.0)
188
-
189
- PLATFORMS
190
- ruby
191
-
192
- DEPENDENCIES
193
- beautiful_scaffold!
194
- bootstrap (~> 4.3.1)
195
- bootstrap4-datetime-picker-rails
196
- font-awesome-rails (= 4.7.0.5)
197
- jquery-rails (= 4.3.1)
198
- jquery-ui-rails
199
- momentjs-rails (>= 2.9.0)
200
- prawn
201
- prawn-table
202
- rails (~> 6.0)
203
- ransack
204
- sanitize
205
- sqlite3
206
- will_paginate
207
-
208
- BUNDLED WITH
209
- 2.1.4
@@ -1,128 +0,0 @@
1
- # encoding : utf-8
2
- class BeautifulDevisecancanGenerator < Rails::Generators::Base
3
- require_relative 'beautiful_scaffold_common_methods'
4
- include BeautifulScaffoldCommonMethods
5
-
6
- source_root File.expand_path('../templates', __FILE__)
7
-
8
- argument :model, :type => :string, :desc => "Name of model (downcase singular)"
9
-
10
- def install_devise
11
- view_path = "app/views/"
12
-
13
- gem("devise", "2.1.0")
14
-
15
- inside Rails.root do
16
- run "bundle install"
17
- end
18
-
19
- generate("devise:install")
20
-
21
- for current_env in ['production', 'development', 'test']
22
- inject_into_file("config/environments/#{current_env}.rb", " config.action_mailer.default_url_options = { :host => 'localhost:3000' }", :after => "::Application.configure do\n" )
23
- end
24
-
25
- # Install devise in the model
26
- generate("devise", model)
27
-
28
- # Add :token_authenticatable and :lockable
29
- # In model
30
- inject_into_file( "app/models/#{model}.rb",
31
- ":token_authenticatable, :lockable,",
32
- :after => "devise ")
33
- # In migration
34
- filename = Dir.glob("db/migrate/*_add_devise_to_#{model.pluralize}.rb")[0]
35
- gsub_file filename, /#\s*(t\.integer\s+:failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts)/, '\1'
36
- gsub_file filename, /#\s*(t\.string\s+:unlock_token # Only if unlock strategy is :email or :both)/, '\1'
37
- gsub_file filename, /#\s*(t\.datetime\s+:locked_at)/, '\1'
38
- gsub_file filename, /#\s*(t\.string\s+:authentication_token)/, '\1'
39
-
40
-
41
- # Limited access (Must be commented if use cancan)
42
- inject_into_file("app/controllers/beautiful_controller.rb","before_action :authenticate_#{model}!, :except => [:dashboard]", :after => 'layout "beautiful_layout"' + "\n")
43
-
44
- # Custom redirect
45
- inject_into_file("app/controllers/application_controller.rb","
46
- def after_sign_out_path_for(resource_or_scope)
47
- root_path
48
- end
49
- def after_sign_in_path_for(resource)
50
- root_path
51
- end
52
- def after_sign_up_path_for(resource)
53
- root_path
54
- end
55
- ", :after => "protect_from_forgery\n")
56
- copy_file("lib/custom_failure.rb")
57
- copy_file("app/controllers/registrations_controller.rb")
58
- inject_into_file("config/initializers/devise.rb","
59
- config.warden do |manager|
60
- manager.failure_app = CustomFailure
61
- end
62
- ", :after => "Devise.setup do |config|\n")
63
- inject_into_file("config/application.rb",' #{config.root}/lib', :after => '#{config.root}/app/modules')
64
-
65
- # Use my register controller
66
- inject_into_file("config/routes.rb",
67
- ', :controllers => {:registrations => "registrations"}',
68
- :after => "devise_for :#{model.pluralize}")
69
-
70
-
71
- # Install partials dans layout (forget password, sign_in)
72
- template("#{view_path}partials/_forget_password.html.erb", "#{view_path}layouts/_forget_password.html.erb")
73
- template("#{view_path}partials/_sign_in_sign_out.html.erb", "#{view_path}layouts/_sign_in_sign_out.html.erb")
74
- template("#{view_path}partials/_sign_in_form.html.erb", "#{view_path}layouts/_sign_in_form.html.erb")
75
- template("#{view_path}partials/_register_form.html.erb", "#{view_path}layouts/_register_form.html.erb")
76
-
77
- # Sign in sign out
78
- inject_into_file("#{view_path}layouts/beautiful_layout.html.erb",
79
- "<%= render :partial => 'layouts/sign_in_sign_out' %>",
80
- :after => "<!-- Beautiful_scaffold - Signin - Do not remove -->\n")
81
-
82
- # Modal (forget password)
83
- inject_into_file("#{view_path}layouts/beautiful_layout.html.erb",
84
- " <%= render :partial => 'layouts/forget_password' %>",
85
- :after => "<!-- Beautiful_scaffold - Modal - Do not remove -->\n")
86
- inject_into_file("#{view_path}layouts/beautiful_layout.html.erb",
87
- " <%= render :partial => 'layouts/register_form' %>",
88
- :after => "<!-- Beautiful_scaffold - Modal - Do not remove -->\n")
89
-
90
- end
91
-
92
- def install_cancan
93
- gem("cancan")
94
-
95
- inside Rails.root do
96
- run "bundle install"
97
- end
98
-
99
- generate("cancan:ability")
100
-
101
- inject_into_file("app/models/ability.rb", "
102
- if not user.nil? then
103
- if user.id == 1 then
104
- can :manage, :all
105
- end
106
- end\n", :after => "def initialize(user)\n")
107
-
108
- # current_user method need for CanCan
109
- current_user_method = ""
110
- if model != "user" then
111
- current_user_method = "
112
- def current_user
113
- current_#{model}
114
- end"
115
- end
116
-
117
- # Exception for AccessDenied
118
- inject_into_file("app/controllers/application_controller.rb", "
119
- rescue_from CanCan::AccessDenied do |exception|
120
- redirect_to root_url, :alert => exception.message
121
- end
122
- #{current_user_method}
123
- ", :after => "class ApplicationController < ActionController::Base\n")
124
-
125
- # Access controlled by CanCan (in beautiful_scaffold)
126
- inject_into_file("app/controllers/application_controller.rb", "#", :before => "before_action :authenticate_#{model}!, :except => [:dashboard]")
127
- end
128
- end
@@ -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 )