tb_events 1.1.2 → 1.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/admin/events/application.js +16 -0
  3. data/app/assets/javascripts/{calendar_events.js → admin/events/calendar_events.js} +0 -0
  4. data/app/assets/javascripts/{spud/admin → admin/events}/calendars.js +0 -0
  5. data/app/assets/stylesheets/admin/events/application.css +4 -0
  6. data/app/assets/{javascripts/spud/events.js → stylesheets/admin/events/calendar_events.css} +0 -0
  7. data/app/assets/stylesheets/{spud → admin/events}/calendars.css +13 -27
  8. data/app/controllers/admin/calendars_controller.rb +1 -1
  9. data/app/helpers/admin/calendars_helper.rb +4 -4
  10. data/app/helpers/calendars_helper.rb +35 -42
  11. data/app/models/spud/spud_calendar_event_model.rb +2 -7
  12. data/app/models/spud_calendar.rb +18 -2
  13. data/app/views/admin/calendar_events/_calendar.html.erb +10 -4
  14. data/app/views/admin/calendar_events/_form.html.erb +15 -97
  15. data/app/views/admin/calendar_events/index.html.erb +18 -11
  16. data/app/views/admin/calendars/_calendar_legend.html.erb +5 -4
  17. data/app/views/admin/calendars/_form.html.erb +4 -19
  18. data/config/locales/en.yml +9 -0
  19. data/db/migrate/20140730182213_remove_color_from_spud_calendars.rb +8 -0
  20. data/lib/spud_events/calendar_builder.rb +1 -1
  21. data/lib/spud_events/engine.rb +2 -6
  22. data/lib/spud_events/version.rb +1 -1
  23. metadata +17 -47
  24. data/app/assets/javascripts/calendars.js +0 -2
  25. data/app/assets/javascripts/spud/admin/calendar_events.js +0 -2
  26. data/app/assets/javascripts/spud/admin/events.js +0 -51
  27. data/app/assets/lib/colorpicker/colorpicker.css +0 -164
  28. data/app/assets/lib/colorpicker/colorpicker.js +0 -484
  29. data/app/assets/lib/colorpicker/images/blank.gif +0 -0
  30. data/app/assets/lib/colorpicker/images/colorpicker_background.png +0 -0
  31. data/app/assets/lib/colorpicker/images/colorpicker_hex.png +0 -0
  32. data/app/assets/lib/colorpicker/images/colorpicker_hsb_b.png +0 -0
  33. data/app/assets/lib/colorpicker/images/colorpicker_hsb_h.png +0 -0
  34. data/app/assets/lib/colorpicker/images/colorpicker_hsb_s.png +0 -0
  35. data/app/assets/lib/colorpicker/images/colorpicker_indic.gif +0 -0
  36. data/app/assets/lib/colorpicker/images/colorpicker_overlay.png +0 -0
  37. data/app/assets/lib/colorpicker/images/colorpicker_rgb_b.png +0 -0
  38. data/app/assets/lib/colorpicker/images/colorpicker_rgb_g.png +0 -0
  39. data/app/assets/lib/colorpicker/images/colorpicker_rgb_r.png +0 -0
  40. data/app/assets/lib/colorpicker/images/colorpicker_select.gif +0 -0
  41. data/app/assets/lib/colorpicker/images/colorpicker_submit.png +0 -0
  42. data/app/assets/lib/colorpicker/images/custom_background.png +0 -0
  43. data/app/assets/lib/colorpicker/images/custom_hex.png +0 -0
  44. data/app/assets/lib/colorpicker/images/custom_hsb_b.png +0 -0
  45. data/app/assets/lib/colorpicker/images/custom_hsb_h.png +0 -0
  46. data/app/assets/lib/colorpicker/images/custom_hsb_s.png +0 -0
  47. data/app/assets/lib/colorpicker/images/custom_indic.gif +0 -0
  48. data/app/assets/lib/colorpicker/images/custom_rgb_b.png +0 -0
  49. data/app/assets/lib/colorpicker/images/custom_rgb_g.png +0 -0
  50. data/app/assets/lib/colorpicker/images/custom_rgb_r.png +0 -0
  51. data/app/assets/lib/colorpicker/images/custom_submit.png +0 -0
  52. data/app/assets/lib/colorpicker/images/select.png +0 -0
  53. data/app/assets/lib/colorpicker/images/select2.png +0 -0
  54. data/app/assets/lib/colorpicker/images/slider.png +0 -0
  55. data/app/assets/stylesheets/spud/admin/events.css +0 -16
  56. data/app/assets/stylesheets/spud/calendar_events.css +0 -18
  57. data/app/assets/stylesheets/spud/events.css +0 -4
@@ -1,7 +1,8 @@
1
1
  <li id="spud_events_admin_calendar_legend_<%= calendar.id %>" class="spud_events_admin_calendar_legend_item">
2
- <%= content_tag :span, calendar.title, :style => "background-color: \##{calendar.color};color:\##{calendar_fore_color(calendar.color)}"%>
3
- <div class="spud_events_admin_calendar_actions">
4
- <%= link_to 'edit', edit_admin_calendar_path(calendar), :class => "btn btn-mini" %>
5
- <%= link_to 'delete', admin_calendar_path(calendar), :remote => true, :data => {:confirm => "This action can't be undone. Would you like to remove the calendar \"#{calendar.title}\"?"}, :method => :delete, :class => 'js-spud-calendar-delete-action btn btn-mini btn-danger' %>
2
+ <div class="spud_events_admin_calendar_actions pull-right">
3
+ <%= link_to 'edit', edit_admin_calendar_path(calendar), :class => "btn btn-sm btn-default" %>
4
+ <%= link_to 'delete', admin_calendar_path(calendar), :remote => true, :data => {:confirm => "This action can't be undone. Would you like to remove the calendar \"#{calendar.title}\"?"}, :method => :delete, :class => 'js-spud-calendar-delete-action btn btn-sm btn-danger' %>
6
5
  </div>
6
+ <%= content_tag :span, calendar.title, :style => "background-color: \##{calendar.color}", :class => 'label' %>
7
+ <div class="clearfix"></div>
7
8
  </li>
@@ -1,20 +1,5 @@
1
- <%= form_for @calendar, :url => (@calendar.new_record? ? admin_calendars_path : admin_calendar_path(@calendar)),:html=>{:class=>"form-horizontal"} do |f| %>
2
- <%= error_messages_for(f.object) %>
3
- <div class="control-group">
4
- <%= f.label :title,:class => "control-label" %>
5
- <div class="controls">
6
- <%= f.text_field :title %>
7
- </div>
8
- </div>
9
- <div class="control-group">
10
- <%= f.label :color,:class => "control-label" %>
11
- <div class="controls">
12
- <%= f.hidden_field :color %>
13
- <div class="spud_events_admin_color_picker"></div>
14
- </div>
15
- </div>
16
- <div class="form-actions">
17
- <%= f.submit "Save", :class=>"btn btn-primary"%> or <%=link_to "cancel", admin_list_spud_calendar_events_path, :class => "btn" %>
18
- </div>
19
-
1
+ <%= form_for @calendar, :url => (@calendar.new_record? ? admin_calendars_path : admin_calendar_path(@calendar)), :builder => TbCore::FormBuilder, :html => {:class => "form-horizontal"} do |f| %>
2
+ <%= tb_form_errors(f.object) %>
3
+ <%= f.tb_text_field :title %>
4
+ <%= f.tb_save_buttons('Calendar', admin_list_spud_calendar_events_path) %>
20
5
  <% end %>
@@ -0,0 +1,9 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ activerecord:
6
+ attributes:
7
+ spud_calendar_event:
8
+ spud_calendar_id: 'Calendar'
9
+
@@ -0,0 +1,8 @@
1
+ class RemoveColorFromSpudCalendars < ActiveRecord::Migration
2
+ def up
3
+ remove_column :spud_calendars, :color
4
+ end
5
+ def down
6
+ add_column :spud_calendars, :color, 'binary(6)'
7
+ end
8
+ end
@@ -23,7 +23,7 @@ private
23
23
 
24
24
  def header
25
25
  content_tag :tr do
26
- @headers.map { |day| content_tag :th, day }.join.html_safe
26
+ @headers.map { |day| content_tag :th, day, :class => 'day-header' }.join.html_safe
27
27
  end
28
28
  end
29
29
 
@@ -12,12 +12,8 @@ module SpudEvents
12
12
  end
13
13
 
14
14
  initializer :assets do |config|
15
- Spud::Core.append_admin_javascripts('spud/admin/events')
16
- Spud::Core.append_admin_stylesheets('spud/admin/events')
17
- Rails.application.config.assets.precompile += [
18
- "spud/events.*",
19
- "spud/admin/events.*"
20
- ]
15
+ Spud::Core.append_admin_stylesheets('admin/events/application')
16
+ Spud::Core.append_admin_javascripts('admin/events/application')
21
17
  end
22
18
  end
23
19
  end
@@ -1,3 +1,3 @@
1
1
  module SpudEvents
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0.beta1"
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Westlake Design
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-01 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tb_core
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
@@ -160,44 +160,12 @@ files:
160
160
  - README.md
161
161
  - Rakefile
162
162
  - app/assets/images/spud/admin/events_thumb.png
163
- - app/assets/javascripts/calendar_events.js
164
- - app/assets/javascripts/calendars.js
165
- - app/assets/javascripts/spud/admin/calendar_events.js
166
- - app/assets/javascripts/spud/admin/calendars.js
167
- - app/assets/javascripts/spud/admin/events.js
168
- - app/assets/javascripts/spud/events.js
169
- - app/assets/lib/colorpicker/colorpicker.css
170
- - app/assets/lib/colorpicker/colorpicker.js
171
- - app/assets/lib/colorpicker/images/blank.gif
172
- - app/assets/lib/colorpicker/images/colorpicker_background.png
173
- - app/assets/lib/colorpicker/images/colorpicker_hex.png
174
- - app/assets/lib/colorpicker/images/colorpicker_hsb_b.png
175
- - app/assets/lib/colorpicker/images/colorpicker_hsb_h.png
176
- - app/assets/lib/colorpicker/images/colorpicker_hsb_s.png
177
- - app/assets/lib/colorpicker/images/colorpicker_indic.gif
178
- - app/assets/lib/colorpicker/images/colorpicker_overlay.png
179
- - app/assets/lib/colorpicker/images/colorpicker_rgb_b.png
180
- - app/assets/lib/colorpicker/images/colorpicker_rgb_g.png
181
- - app/assets/lib/colorpicker/images/colorpicker_rgb_r.png
182
- - app/assets/lib/colorpicker/images/colorpicker_select.gif
183
- - app/assets/lib/colorpicker/images/colorpicker_submit.png
184
- - app/assets/lib/colorpicker/images/custom_background.png
185
- - app/assets/lib/colorpicker/images/custom_hex.png
186
- - app/assets/lib/colorpicker/images/custom_hsb_b.png
187
- - app/assets/lib/colorpicker/images/custom_hsb_h.png
188
- - app/assets/lib/colorpicker/images/custom_hsb_s.png
189
- - app/assets/lib/colorpicker/images/custom_indic.gif
190
- - app/assets/lib/colorpicker/images/custom_rgb_b.png
191
- - app/assets/lib/colorpicker/images/custom_rgb_g.png
192
- - app/assets/lib/colorpicker/images/custom_rgb_r.png
193
- - app/assets/lib/colorpicker/images/custom_submit.png
194
- - app/assets/lib/colorpicker/images/select.png
195
- - app/assets/lib/colorpicker/images/select2.png
196
- - app/assets/lib/colorpicker/images/slider.png
197
- - app/assets/stylesheets/spud/admin/events.css
198
- - app/assets/stylesheets/spud/calendar_events.css
199
- - app/assets/stylesheets/spud/calendars.css
200
- - app/assets/stylesheets/spud/events.css
163
+ - app/assets/javascripts/admin/events/application.js
164
+ - app/assets/javascripts/admin/events/calendar_events.js
165
+ - app/assets/javascripts/admin/events/calendars.js
166
+ - app/assets/stylesheets/admin/events/application.css
167
+ - app/assets/stylesheets/admin/events/calendar_events.css
168
+ - app/assets/stylesheets/admin/events/calendars.css
201
169
  - app/controllers/admin/calendar_events_controller.rb
202
170
  - app/controllers/admin/calendars_controller.rb
203
171
  - app/controllers/calendar_events_controller.rb
@@ -220,11 +188,13 @@ files:
220
188
  - app/views/calendar_events/index.html.erb
221
189
  - app/views/calendar_events/show.html.erb
222
190
  - app/views/calendars/show.html.erb
191
+ - config/locales/en.yml
223
192
  - config/routes.rb
224
193
  - db/migrate/20120216191833_create_spud_calendars.rb
225
194
  - db/migrate/20120216192531_create_spud_calendar_events.rb
226
195
  - db/migrate/20130214131628_add_location_to_spud_calendar_event.rb
227
196
  - db/migrate/20140723203144_add_identifier_to_spud_calendars.rb
197
+ - db/migrate/20140730182213_remove_color_from_spud_calendars.rb
228
198
  - lib/spud_events/calendar_builder.rb
229
199
  - lib/spud_events/configuration.rb
230
200
  - lib/spud_events/engine.rb
@@ -244,12 +214,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
214
  version: '0'
245
215
  required_rubygems_version: !ruby/object:Gem::Requirement
246
216
  requirements:
247
- - - ">="
217
+ - - ">"
248
218
  - !ruby/object:Gem::Version
249
- version: '0'
219
+ version: 1.3.1
250
220
  requirements: []
251
221
  rubyforge_project:
252
- rubygems_version: 2.4.6
222
+ rubygems_version: 2.4.3
253
223
  signing_key:
254
224
  specification_version: 4
255
225
  summary: Twice Baked Events engine
@@ -1,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.
@@ -1,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.
@@ -1,51 +0,0 @@
1
- //= require colorpicker/colorpicker
2
- //= require_self
3
-
4
- var Spud = Spud || {};
5
- Spud.Admin = Spud.Admin || {};
6
-
7
- Spud.Admin.Events = new function(){
8
- var self = this;
9
-
10
- self.init = function(){
11
- // Wd.Admin.tinyMce();
12
- self.configureColorPicker();
13
- self.attachCalendarDeleteFX();
14
- };
15
-
16
- self.configureColorPicker = function(){
17
- var $colorPickers = $('.spud_events_admin_color_picker'),
18
- $calendarColor = $('#spud_calendar_color');
19
-
20
- if($colorPickers.size() > 0) {
21
- $colorPickers.css('backgroundColor', '#' + $calendarColor.val());
22
- $colorPickers.ColorPicker({
23
- color: $calendarColor.val(),
24
- onShow: function (colpkr) {
25
- $(colpkr).fadeIn(500);
26
- return false;
27
- },
28
- onHide: function (colpkr) {
29
- $(colpkr).fadeOut(500);
30
- return false;
31
- },
32
- onChange: function (hsb, hex, rgb) {
33
-
34
- $colorPickers.css('backgroundColor', '#' + hex);
35
- $calendarColor.attr('value', hex);
36
- }
37
- });
38
- }
39
- };
40
-
41
- self.attachCalendarDeleteFX = function() {
42
- $(document).on('ajax:succes','.js-spud-calendar-delete-action', function() {
43
- $(this).closest('.spud_events_admin_calendar_legend_item').fadeOut(500, function(){ $(this).remove(); });
44
- });
45
- };
46
- };
47
-
48
- $(function() {
49
- Spud.Admin.Events.init();
50
- });
51
-
@@ -1,164 +0,0 @@
1
- .colorpicker {
2
- width: 356px;
3
- height: 176px;
4
- overflow: hidden;
5
- position: absolute;
6
- background: url(/assets/colorpicker/images/colorpicker_background.png);
7
- font-family: Arial, Helvetica, sans-serif;
8
- display: none;
9
- }
10
- .colorpicker_color {
11
- width: 150px;
12
- height: 150px;
13
- left: 14px;
14
- top: 13px;
15
- position: absolute;
16
- background: #f00;
17
- overflow: hidden;
18
- cursor: crosshair;
19
- }
20
- .colorpicker_color div {
21
- position: absolute;
22
- top: 0;
23
- left: 0;
24
- width: 150px;
25
- height: 150px;
26
- background: url(/assets/colorpicker/images/colorpicker_overlay.png);
27
- }
28
- .colorpicker_color div div {
29
- position: absolute;
30
- top: 0;
31
- left: 0;
32
- width: 11px;
33
- height: 11px;
34
- overflow: hidden;
35
- background: url(/assets/colorpicker/images/colorpicker_select.gif);
36
- margin: -5px 0 0 -5px;
37
- }
38
- .colorpicker_hue {
39
- position: absolute;
40
- top: 13px;
41
- left: 171px;
42
- width: 35px;
43
- height: 150px;
44
- cursor: n-resize;
45
- }
46
- .colorpicker_hue div {
47
- position: absolute;
48
- width: 35px;
49
- height: 9px;
50
- overflow: hidden;
51
- background: url(/assets/colorpicker/images/colorpicker_indic.gif) left top;
52
- margin: -4px 0 0 0;
53
- left: 0px;
54
- }
55
- .colorpicker_new_color {
56
- position: absolute;
57
- width: 60px;
58
- height: 30px;
59
- left: 213px;
60
- top: 13px;
61
- background: #f00;
62
- }
63
- .colorpicker_current_color {
64
- position: absolute;
65
- width: 60px;
66
- height: 30px;
67
- left: 283px;
68
- top: 13px;
69
- background: #f00;
70
- }
71
- .colorpicker input {
72
- background-color: transparent;
73
- border: 1px solid transparent;
74
- position: absolute;
75
- font-size: 10px;
76
- font-family: Arial, Helvetica, sans-serif;
77
- color: #898989;
78
- top: 4px;
79
- right: 11px;
80
- text-align: right;
81
- margin: 0;
82
- padding: 0;
83
- height: 11px;
84
- }
85
- .colorpicker_hex {
86
- position: absolute;
87
- width: 72px;
88
- height: 22px;
89
- background: url(/assets/colorpicker/images/colorpicker_hex.png) top;
90
- left: 212px;
91
- top: 142px;
92
- }
93
- .colorpicker_hex input {
94
- right: 6px;
95
- }
96
- .colorpicker_field {
97
- height: 22px;
98
- width: 62px;
99
- background-position: top;
100
- position: absolute;
101
- }
102
- .colorpicker_field span {
103
- position: absolute;
104
- width: 12px;
105
- height: 22px;
106
- overflow: hidden;
107
- top: 0;
108
- right: 0;
109
- cursor: n-resize;
110
- }
111
- .colorpicker_field input{
112
- width:auto;
113
- }
114
- .colorpicker_rgb_r {
115
- background-image: url(/assets/colorpicker/images/colorpicker_rgb_r.png);
116
- top: 52px;
117
- left: 212px;
118
- }
119
- .colorpicker_rgb_g {
120
- background-image: url(/assets/colorpicker/images/colorpicker_rgb_g.png);
121
- top: 82px;
122
- left: 212px;
123
- }
124
- .colorpicker_rgb_b {
125
- background-image: url(/assets/colorpicker/images/colorpicker_rgb_b.png);
126
- top: 112px;
127
- left: 212px;
128
- }
129
- .colorpicker_hsb_h {
130
- background-image: url(/assets/colorpicker/images/colorpicker_hsb_h.png);
131
- top: 52px;
132
- left: 282px;
133
- }
134
- .colorpicker_hsb_s {
135
- background-image: url(/assets/colorpicker/images/colorpicker_hsb_s.png);
136
- top: 82px;
137
- left: 282px;
138
- }
139
- .colorpicker_hsb_b {
140
- background-image: url(/assets/colorpicker/images/colorpicker_hsb_b.png);
141
- top: 112px;
142
- left: 282px;
143
- }
144
- .colorpicker_submit {
145
- position: absolute;
146
- width: 22px;
147
- height: 22px;
148
- background: url(/assets/colorpicker/images/colorpicker_submit.png) top;
149
- left: 322px;
150
- top: 142px;
151
- overflow: hidden;
152
- }
153
- .colorpicker_focus {
154
- background-position: center;
155
- }
156
- .colorpicker_hex.colorpicker_focus {
157
- background-position: bottom;
158
- }
159
- .colorpicker_submit.colorpicker_focus {
160
- background-position: bottom;
161
- }
162
- .colorpicker_slider {
163
- background-position: bottom;
164
- }
@@ -1,484 +0,0 @@
1
- /**
2
- *
3
- * Color picker
4
- * Author: Stefan Petre www.eyecon.ro
5
- *
6
- * Dual licensed under the MIT and GPL licenses
7
- *
8
- */
9
- (function ($) {
10
- var ColorPicker = function () {
11
- var
12
- ids = {},
13
- inAction,
14
- charMin = 65,
15
- visible,
16
- tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
17
- defaults = {
18
- eventName: 'click',
19
- onShow: function () {},
20
- onBeforeShow: function(){},
21
- onHide: function () {},
22
- onChange: function () {},
23
- onSubmit: function () {},
24
- color: 'ff0000',
25
- livePreview: true,
26
- flat: false
27
- },
28
- fillRGBFields = function (hsb, cal) {
29
- var rgb = HSBToRGB(hsb);
30
- $(cal).data('colorpicker').fields
31
- .eq(1).val(rgb.r).end()
32
- .eq(2).val(rgb.g).end()
33
- .eq(3).val(rgb.b).end();
34
- },
35
- fillHSBFields = function (hsb, cal) {
36
- $(cal).data('colorpicker').fields
37
- .eq(4).val(hsb.h).end()
38
- .eq(5).val(hsb.s).end()
39
- .eq(6).val(hsb.b).end();
40
- },
41
- fillHexFields = function (hsb, cal) {
42
- $(cal).data('colorpicker').fields
43
- .eq(0).val(HSBToHex(hsb)).end();
44
- },
45
- setSelector = function (hsb, cal) {
46
- $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
47
- $(cal).data('colorpicker').selectorIndic.css({
48
- left: parseInt(150 * hsb.s/100, 10),
49
- top: parseInt(150 * (100-hsb.b)/100, 10)
50
- });
51
- },
52
- setHue = function (hsb, cal) {
53
- $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
54
- },
55
- setCurrentColor = function (hsb, cal) {
56
- $(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
57
- },
58
- setNewColor = function (hsb, cal) {
59
- $(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
60
- },
61
- keyDown = function (ev) {
62
- var pressedKey = ev.charCode || ev.keyCode || -1;
63
- if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
64
- return false;
65
- }
66
- var cal = $(this).parent().parent();
67
- if (cal.data('colorpicker').livePreview === true) {
68
- change.apply(this);
69
- }
70
- },
71
- change = function (ev) {
72
- var cal = $(this).parent().parent(), col;
73
- if (this.parentNode.className.indexOf('_hex') > 0) {
74
- cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
75
- } else if (this.parentNode.className.indexOf('_hsb') > 0) {
76
- cal.data('colorpicker').color = col = fixHSB({
77
- h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
78
- s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
79
- b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
80
- });
81
- } else {
82
- cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
83
- r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
84
- g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
85
- b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
86
- }));
87
- }
88
- if (ev) {
89
- fillRGBFields(col, cal.get(0));
90
- fillHexFields(col, cal.get(0));
91
- fillHSBFields(col, cal.get(0));
92
- }
93
- setSelector(col, cal.get(0));
94
- setHue(col, cal.get(0));
95
- setNewColor(col, cal.get(0));
96
- cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
97
- },
98
- blur = function (ev) {
99
- var cal = $(this).parent().parent();
100
- cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
101
- },
102
- focus = function () {
103
- charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
104
- $(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
105
- $(this).parent().addClass('colorpicker_focus');
106
- },
107
- downIncrement = function (ev) {
108
- var field = $(this).parent().find('input').focus();
109
- var current = {
110
- el: $(this).parent().addClass('colorpicker_slider'),
111
- max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
112
- y: ev.pageY,
113
- field: field,
114
- val: parseInt(field.val(), 10),
115
- preview: $(this).parent().parent().data('colorpicker').livePreview
116
- };
117
- $(document).bind('mouseup', current, upIncrement);
118
- $(document).bind('mousemove', current, moveIncrement);
119
- },
120
- moveIncrement = function (ev) {
121
- ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
122
- if (ev.data.preview) {
123
- change.apply(ev.data.field.get(0), [true]);
124
- }
125
- return false;
126
- },
127
- upIncrement = function (ev) {
128
- change.apply(ev.data.field.get(0), [true]);
129
- ev.data.el.removeClass('colorpicker_slider').find('input').focus();
130
- $(document).unbind('mouseup', upIncrement);
131
- $(document).unbind('mousemove', moveIncrement);
132
- return false;
133
- },
134
- downHue = function (ev) {
135
- var current = {
136
- cal: $(this).parent(),
137
- y: $(this).offset().top
138
- };
139
- current.preview = current.cal.data('colorpicker').livePreview;
140
- $(document).bind('mouseup', current, upHue);
141
- $(document).bind('mousemove', current, moveHue);
142
- },
143
- moveHue = function (ev) {
144
- change.apply(
145
- ev.data.cal.data('colorpicker')
146
- .fields
147
- .eq(4)
148
- .val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
149
- .get(0),
150
- [ev.data.preview]
151
- );
152
- return false;
153
- },
154
- upHue = function (ev) {
155
- fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
156
- fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
157
- $(document).unbind('mouseup', upHue);
158
- $(document).unbind('mousemove', moveHue);
159
- return false;
160
- },
161
- downSelector = function (ev) {
162
- var current = {
163
- cal: $(this).parent(),
164
- pos: $(this).offset()
165
- };
166
- current.preview = current.cal.data('colorpicker').livePreview;
167
- $(document).bind('mouseup', current, upSelector);
168
- $(document).bind('mousemove', current, moveSelector);
169
- },
170
- moveSelector = function (ev) {
171
- change.apply(
172
- ev.data.cal.data('colorpicker')
173
- .fields
174
- .eq(6)
175
- .val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
176
- .end()
177
- .eq(5)
178
- .val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
179
- .get(0),
180
- [ev.data.preview]
181
- );
182
- return false;
183
- },
184
- upSelector = function (ev) {
185
- fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
186
- fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
187
- $(document).unbind('mouseup', upSelector);
188
- $(document).unbind('mousemove', moveSelector);
189
- return false;
190
- },
191
- enterSubmit = function (ev) {
192
- $(this).addClass('colorpicker_focus');
193
- },
194
- leaveSubmit = function (ev) {
195
- $(this).removeClass('colorpicker_focus');
196
- },
197
- clickSubmit = function (ev) {
198
- var cal = $(this).parent();
199
- var col = cal.data('colorpicker').color;
200
- cal.data('colorpicker').origColor = col;
201
- setCurrentColor(col, cal.get(0));
202
- cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
203
- },
204
- show = function (ev) {
205
- var cal = $('#' + $(this).data('colorpickerId'));
206
- cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
207
- var pos = $(this).offset();
208
- var viewPort = getViewport();
209
- var top = pos.top + this.offsetHeight;
210
- var left = pos.left;
211
- if (top + 176 > viewPort.t + viewPort.h) {
212
- top -= this.offsetHeight + 176;
213
- }
214
- if (left + 356 > viewPort.l + viewPort.w) {
215
- left -= 356;
216
- }
217
- cal.css({left: left + 'px', top: top + 'px'});
218
- if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
219
- cal.show();
220
- }
221
- $(document).bind('mousedown', {cal: cal}, hide);
222
- return false;
223
- },
224
- hide = function (ev) {
225
- if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
226
- if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
227
- ev.data.cal.hide();
228
- }
229
- $(document).unbind('mousedown', hide);
230
- }
231
- },
232
- isChildOf = function(parentEl, el, container) {
233
- if (parentEl == el) {
234
- return true;
235
- }
236
- if (parentEl.contains) {
237
- return parentEl.contains(el);
238
- }
239
- if ( parentEl.compareDocumentPosition ) {
240
- return !!(parentEl.compareDocumentPosition(el) & 16);
241
- }
242
- var prEl = el.parentNode;
243
- while(prEl && prEl != container) {
244
- if (prEl == parentEl)
245
- return true;
246
- prEl = prEl.parentNode;
247
- }
248
- return false;
249
- },
250
- getViewport = function () {
251
- var m = document.compatMode == 'CSS1Compat';
252
- return {
253
- l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
254
- t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
255
- w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
256
- h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
257
- };
258
- },
259
- fixHSB = function (hsb) {
260
- return {
261
- h: Math.min(360, Math.max(0, hsb.h)),
262
- s: Math.min(100, Math.max(0, hsb.s)),
263
- b: Math.min(100, Math.max(0, hsb.b))
264
- };
265
- },
266
- fixRGB = function (rgb) {
267
- return {
268
- r: Math.min(255, Math.max(0, rgb.r)),
269
- g: Math.min(255, Math.max(0, rgb.g)),
270
- b: Math.min(255, Math.max(0, rgb.b))
271
- };
272
- },
273
- fixHex = function (hex) {
274
- var len = 6 - hex.length;
275
- if (len > 0) {
276
- var o = [];
277
- for (var i=0; i<len; i++) {
278
- o.push('0');
279
- }
280
- o.push(hex);
281
- hex = o.join('');
282
- }
283
- return hex;
284
- },
285
- HexToRGB = function (hex) {
286
- var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
287
- return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
288
- },
289
- HexToHSB = function (hex) {
290
- return RGBToHSB(HexToRGB(hex));
291
- },
292
- RGBToHSB = function (rgb) {
293
- var hsb = {
294
- h: 0,
295
- s: 0,
296
- b: 0
297
- };
298
- var min = Math.min(rgb.r, rgb.g, rgb.b);
299
- var max = Math.max(rgb.r, rgb.g, rgb.b);
300
- var delta = max - min;
301
- hsb.b = max;
302
- if (max != 0) {
303
-
304
- }
305
- hsb.s = max != 0 ? 255 * delta / max : 0;
306
- if (hsb.s != 0) {
307
- if (rgb.r == max) {
308
- hsb.h = (rgb.g - rgb.b) / delta;
309
- } else if (rgb.g == max) {
310
- hsb.h = 2 + (rgb.b - rgb.r) / delta;
311
- } else {
312
- hsb.h = 4 + (rgb.r - rgb.g) / delta;
313
- }
314
- } else {
315
- hsb.h = -1;
316
- }
317
- hsb.h *= 60;
318
- if (hsb.h < 0) {
319
- hsb.h += 360;
320
- }
321
- hsb.s *= 100/255;
322
- hsb.b *= 100/255;
323
- return hsb;
324
- },
325
- HSBToRGB = function (hsb) {
326
- var rgb = {};
327
- var h = Math.round(hsb.h);
328
- var s = Math.round(hsb.s*255/100);
329
- var v = Math.round(hsb.b*255/100);
330
- if(s == 0) {
331
- rgb.r = rgb.g = rgb.b = v;
332
- } else {
333
- var t1 = v;
334
- var t2 = (255-s)*v/255;
335
- var t3 = (t1-t2)*(h%60)/60;
336
- if(h==360) h = 0;
337
- if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
338
- else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
339
- else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
340
- else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
341
- else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
342
- else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
343
- else {rgb.r=0; rgb.g=0; rgb.b=0}
344
- }
345
- return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
346
- },
347
- RGBToHex = function (rgb) {
348
- var hex = [
349
- rgb.r.toString(16),
350
- rgb.g.toString(16),
351
- rgb.b.toString(16)
352
- ];
353
- $.each(hex, function (nr, val) {
354
- if (val.length == 1) {
355
- hex[nr] = '0' + val;
356
- }
357
- });
358
- return hex.join('');
359
- },
360
- HSBToHex = function (hsb) {
361
- return RGBToHex(HSBToRGB(hsb));
362
- },
363
- restoreOriginal = function () {
364
- var cal = $(this).parent();
365
- var col = cal.data('colorpicker').origColor;
366
- cal.data('colorpicker').color = col;
367
- fillRGBFields(col, cal.get(0));
368
- fillHexFields(col, cal.get(0));
369
- fillHSBFields(col, cal.get(0));
370
- setSelector(col, cal.get(0));
371
- setHue(col, cal.get(0));
372
- setNewColor(col, cal.get(0));
373
- };
374
- return {
375
- init: function (opt) {
376
- opt = $.extend({}, defaults, opt||{});
377
- if (typeof opt.color == 'string') {
378
- opt.color = HexToHSB(opt.color);
379
- } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
380
- opt.color = RGBToHSB(opt.color);
381
- } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
382
- opt.color = fixHSB(opt.color);
383
- } else {
384
- return this;
385
- }
386
- return this.each(function () {
387
- if (!$(this).data('colorpickerId')) {
388
- var options = $.extend({}, opt);
389
- options.origColor = opt.color;
390
- var id = 'collorpicker_' + parseInt(Math.random() * 1000);
391
- $(this).data('colorpickerId', id);
392
- var cal = $(tpl).attr('id', id);
393
- if (options.flat) {
394
- cal.appendTo(this).show();
395
- } else {
396
- cal.appendTo(document.body);
397
- }
398
- options.fields = cal
399
- .find('input')
400
- .bind('keyup', keyDown)
401
- .bind('change', change)
402
- .bind('blur', blur)
403
- .bind('focus', focus);
404
- cal
405
- .find('span').bind('mousedown', downIncrement).end()
406
- .find('>div.colorpicker_current_color').bind('click', restoreOriginal);
407
- options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
408
- options.selectorIndic = options.selector.find('div div');
409
- options.el = this;
410
- options.hue = cal.find('div.colorpicker_hue div');
411
- cal.find('div.colorpicker_hue').bind('mousedown', downHue);
412
- options.newColor = cal.find('div.colorpicker_new_color');
413
- options.currentColor = cal.find('div.colorpicker_current_color');
414
- cal.data('colorpicker', options);
415
- cal.find('div.colorpicker_submit')
416
- .bind('mouseenter', enterSubmit)
417
- .bind('mouseleave', leaveSubmit)
418
- .bind('click', clickSubmit);
419
- fillRGBFields(options.color, cal.get(0));
420
- fillHSBFields(options.color, cal.get(0));
421
- fillHexFields(options.color, cal.get(0));
422
- setHue(options.color, cal.get(0));
423
- setSelector(options.color, cal.get(0));
424
- setCurrentColor(options.color, cal.get(0));
425
- setNewColor(options.color, cal.get(0));
426
- if (options.flat) {
427
- cal.css({
428
- position: 'relative',
429
- display: 'block'
430
- });
431
- } else {
432
- $(this).bind(options.eventName, show);
433
- }
434
- }
435
- });
436
- },
437
- showPicker: function() {
438
- return this.each( function () {
439
- if ($(this).data('colorpickerId')) {
440
- show.apply(this);
441
- }
442
- });
443
- },
444
- hidePicker: function() {
445
- return this.each( function () {
446
- if ($(this).data('colorpickerId')) {
447
- $('#' + $(this).data('colorpickerId')).hide();
448
- }
449
- });
450
- },
451
- setColor: function(col) {
452
- if (typeof col == 'string') {
453
- col = HexToHSB(col);
454
- } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
455
- col = RGBToHSB(col);
456
- } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
457
- col = fixHSB(col);
458
- } else {
459
- return this;
460
- }
461
- return this.each(function(){
462
- if ($(this).data('colorpickerId')) {
463
- var cal = $('#' + $(this).data('colorpickerId'));
464
- cal.data('colorpicker').color = col;
465
- cal.data('colorpicker').origColor = col;
466
- fillRGBFields(col, cal.get(0));
467
- fillHSBFields(col, cal.get(0));
468
- fillHexFields(col, cal.get(0));
469
- setHue(col, cal.get(0));
470
- setSelector(col, cal.get(0));
471
- setCurrentColor(col, cal.get(0));
472
- setNewColor(col, cal.get(0));
473
- }
474
- });
475
- }
476
- };
477
- }();
478
- $.fn.extend({
479
- ColorPicker: ColorPicker.init,
480
- ColorPickerHide: ColorPicker.hidePicker,
481
- ColorPickerShow: ColorPicker.showPicker,
482
- ColorPickerSetColor: ColorPicker.setColor
483
- });
484
- })(jQuery)