spina 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of spina might be problematic. Click here for more details.

Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -12
  3. data/Rakefile +1 -0
  4. data/app/assets/fonts/spina/ics_spina.eot +0 -0
  5. data/app/assets/fonts/spina/ics_spina.svg +5 -3
  6. data/app/assets/fonts/spina/ics_spina.ttf +0 -0
  7. data/app/assets/fonts/spina/ics_spina.woff +0 -0
  8. data/app/assets/icons/spina/lock.svg +3 -0
  9. data/app/assets/icons/spina/preview/ics_spina-preview.html +16 -1
  10. data/app/assets/javascripts/spina/admin/application.coffee.erb +3 -25
  11. data/app/assets/javascripts/spina/admin/navigation.coffee +7 -0
  12. data/app/assets/javascripts/spina/admin/pages.coffee.erb +1 -13
  13. data/app/assets/javascripts/spina/admin/trix.coffee.erb +2 -1
  14. data/app/assets/stylesheets/spina/_admin_editing.sass +0 -4
  15. data/app/assets/stylesheets/spina/_buttons.sass +8 -8
  16. data/app/assets/stylesheets/spina/_configuration.sass +5 -1
  17. data/app/assets/stylesheets/spina/_custom_animations.sass +26 -26
  18. data/app/assets/stylesheets/spina/_fonts.sass +5 -1
  19. data/app/assets/stylesheets/spina/_forms.sass +66 -33
  20. data/app/assets/stylesheets/spina/_gallery.sass +32 -15
  21. data/app/assets/stylesheets/spina/_ics_spina.scss +1 -0
  22. data/app/assets/stylesheets/spina/_login.sass +10 -4
  23. data/app/assets/stylesheets/spina/_mixins.sass +5 -0
  24. data/app/assets/stylesheets/spina/_modal.sass +4 -4
  25. data/app/assets/stylesheets/spina/_notifications.sass +5 -5
  26. data/app/assets/stylesheets/spina/_sortable_lists.sass +9 -9
  27. data/app/assets/stylesheets/spina/_tables.sass +9 -9
  28. data/app/assets/stylesheets/spina/_wizard.sass +5 -5
  29. data/app/assets/stylesheets/spina/admin/application.sass +4 -1
  30. data/app/assets/stylesheets/spina/application.sass +0 -1
  31. data/app/assets/stylesheets/spina.sass +23 -27
  32. data/app/controllers/spina/admin/accounts_controller.rb +2 -7
  33. data/app/controllers/spina/admin/admin_controller.rb +8 -3
  34. data/app/controllers/spina/admin/attachments_controller.rb +0 -2
  35. data/app/controllers/spina/admin/navigations_controller.rb +3 -2
  36. data/app/controllers/spina/admin/pages_controller.rb +7 -8
  37. data/app/controllers/spina/admin/password_resets_controller.rb +49 -0
  38. data/app/controllers/spina/admin/photos_controller.rb +15 -34
  39. data/app/controllers/spina/admin/sessions_controller.rb +1 -1
  40. data/app/controllers/spina/admin/users_controller.rb +8 -9
  41. data/app/controllers/spina/application_controller.rb +3 -9
  42. data/app/controllers/spina/pages_controller.rb +3 -3
  43. data/app/helpers/spina/admin/pages_helper.rb +16 -23
  44. data/app/mailers/spina/user_mailer.rb +21 -0
  45. data/app/models/concerns/spina/optionable.rb +12 -0
  46. data/app/models/concerns/spina/part.rb +5 -1
  47. data/app/models/concerns/spina/partable.rb +20 -5
  48. data/app/models/concerns/spina/photo_collectable.rb +24 -0
  49. data/app/models/spina/account.rb +16 -6
  50. data/app/models/spina/layout_part.rb +1 -0
  51. data/app/models/spina/option.rb +17 -0
  52. data/app/models/spina/page.rb +36 -63
  53. data/app/models/spina/page_part.rb +1 -0
  54. data/app/models/spina/photo_collection.rb +1 -13
  55. data/app/models/spina/structure_item.rb +4 -8
  56. data/app/models/spina/structure_part.rb +2 -13
  57. data/app/models/spina/user.rb +1 -0
  58. data/app/presenters/spina/pages/menu_presenter.rb +18 -49
  59. data/app/views/layouts/spina/mail.html.erb +1 -0
  60. data/app/views/spina/admin/page_partables/{colors → options}/_form.html.haml +2 -3
  61. data/app/views/spina/admin/page_partables/photo_collections/_form.html.haml +7 -7
  62. data/app/views/spina/admin/page_partables/structures/_form.html.haml +7 -8
  63. data/app/views/spina/admin/pages/_form.html.haml +2 -2
  64. data/app/views/spina/admin/pages/_form_advanced.html.haml +2 -2
  65. data/app/views/spina/admin/password_resets/edit.html.haml +13 -0
  66. data/app/views/spina/admin/password_resets/new.html.haml +13 -0
  67. data/app/views/spina/admin/photos/_photo.html.haml +2 -1
  68. data/app/views/spina/admin/photos/{_wysihtml5_select.html.haml → _trix_select.html.haml} +2 -4
  69. data/app/views/spina/admin/photos/create.js.erb +3 -5
  70. data/app/views/spina/admin/photos/{wysihtml5_infinite_scroll.js.erb → trix_infinite_scroll.js.erb} +0 -2
  71. data/app/views/spina/admin/photos/{wysihtml5_insert.js.coffee → trix_insert.js.erb} +2 -2
  72. data/app/views/spina/admin/photos/trix_select.js.erb +3 -0
  73. data/app/views/spina/admin/sessions/new.html.haml +3 -1
  74. data/app/views/spina/admin/shared/_primary_navigation.html.haml +1 -1
  75. data/app/views/spina/admin/shared/_rich_text_field.html.haml +2 -1
  76. data/app/views/spina/admin/structure_items/_fields.html.haml +3 -3
  77. data/app/views/spina/admin/structure_partables/lines/_form.html.haml +5 -2
  78. data/app/views/spina/admin/structure_partables/options/_form.html.haml +7 -0
  79. data/app/views/spina/admin/structure_partables/photo_collections/_form.html.haml +12 -9
  80. data/app/views/spina/admin/structure_partables/photos/_form.html.haml +10 -7
  81. data/app/views/spina/admin/structure_partables/texts/_form.html.haml +5 -2
  82. data/app/views/spina/admin/users/_form.html.haml +1 -1
  83. data/app/views/spina/shared/_admin_bar.html.haml +1 -1
  84. data/app/views/spina/shared/_navigation.html.haml +1 -1
  85. data/app/views/spina/user_mailer/forgot_password.html.erb +1 -0
  86. data/app/views/spina/user_mailer/forgot_password.txt.erb +1 -0
  87. data/config/locales/en.yml +10 -0
  88. data/config/locales/nl.yml +2 -0
  89. data/config/routes.rb +5 -9
  90. data/db/migrate/1_create_spina_tables.rb +8 -7
  91. data/db/migrate/2_create_spina_translation_tables.rb +7 -26
  92. data/db/migrate/3_create_spina_navigations.rb +1 -1
  93. data/db/migrate/4_add_password_reset_token_to_spina_users.rb +6 -0
  94. data/db/migrate/5_remove_translated_columns.rb +11 -0
  95. data/db/migrate/6_create_spina_options.rb +8 -0
  96. data/lib/generators/spina/install_generator.rb +0 -22
  97. data/lib/generators/spina/templates/app/views/default/shared/_navigation.html.haml +1 -1
  98. data/lib/generators/spina/templates/app/views/demo/shared/_navigation.html.haml +1 -1
  99. data/lib/generators/spina/templates/config/initializers/themes/default.rb +9 -0
  100. data/lib/generators/spina/templates/config/initializers/themes/demo.rb +1 -9
  101. data/lib/spina/engine.rb +4 -3
  102. data/lib/spina/theme.rb +2 -1
  103. data/lib/spina/version.rb +1 -1
  104. data/lib/spina.rb +0 -23
  105. metadata +32 -69
  106. data/app/assets/images/spina/marker.png +0 -0
  107. data/app/assets/images/spina/mask.png +0 -0
  108. data/app/assets/images/spina/wheel.png +0 -0
  109. data/app/assets/stylesheets/spina/_cards.sass +0 -54
  110. data/app/assets/stylesheets/spina/_farbtastic.sass +0 -37
  111. data/app/assets/stylesheets/spina/_wysihtml5.sass +0 -79
  112. data/app/assets/stylesheets/spina/wysihtml5_textarea.sass +0 -14
  113. data/app/controllers/spina/admin/page_parts_controller.rb +0 -11
  114. data/app/helpers/spina/application_helper.rb +0 -30
  115. data/app/models/spina/ability.rb +0 -20
  116. data/app/models/spina/color.rb +0 -7
  117. data/app/presenters/spina/pages/breadcrumb.rb +0 -102
  118. data/app/views/layouts/spina/email.html.erb +0 -124
  119. data/app/views/spina/admin/layout_partables/colors/_form.html.haml +0 -4
  120. data/app/views/spina/admin/page_parts/_wysihtml5_link.html.haml +0 -12
  121. data/app/views/spina/admin/page_parts/insert_wysihtml5_link.js +0 -5
  122. data/app/views/spina/admin/page_parts/wysihtml5_link.js +0 -2
  123. data/app/views/spina/admin/photos/create_and_select.js.erb +0 -7
  124. data/app/views/spina/admin/photos/create_multiple.js.erb +0 -4
  125. data/app/views/spina/admin/photos/wysihtml5_select.js.erb +0 -3
  126. data/vendor/assets/javascripts/spina/jquery.farbtastic.js +0 -345
  127. data/vendor/assets/javascripts/spina/morris.js +0 -1767
  128. data/vendor/assets/javascripts/spina/raphael.js +0 -8111
  129. data/vendor/assets/javascripts/spina/wysihtml5.js +0 -269
  130. data/vendor/assets/javascripts/spina/wysihtml5_parser_rules.js +0 -551
  131. data/vendor/assets/stylesheets/spina/_morris.scss +0 -2
@@ -1,124 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
-
6
- <!-- Facebook sharing information tags -->
7
- <!-- <meta property="og:title" content="Spina" /> -->
8
-
9
- <title><%= message.subject %></title>
10
-
11
- </head>
12
-
13
- <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="width: 100% !important; -webkit-text-size-adjust: none; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; background-color: #FAFAFA;" bgcolor="#FAFAFA">
14
- <center>
15
- <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" style="height: 100% !important; width: 100% !important; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; background-color: #FAFAFA;" bgcolor="#FAFAFA">
16
- <tr>
17
- <td align="center" valign="top" style="border-collapse: collapse;">
18
- <table border="0" cellpadding="10" cellspacing="0" width="600" style="background-color: #FAFAFA;" bgcolor="#FAFAFA">
19
- <tr>
20
- <td valign="top" class="preheaderContent" style="border-collapse: collapse;"></td>
21
- </tr>
22
- </table>
23
-
24
- <!-- // End Template Preheader \\ -->
25
- <table border="0" cellpadding="0" cellspacing="0" width="240" style="border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: #FFFFFF;" bgcolor="#FFFFFF">
26
- <tr>
27
- <td align="left" valign="top" style="border-collapse: collapse;">
28
- <!-- // Begin Template Header \\ -->
29
- <table border="0" cellpadding="0" cellspacing="0" width="240" style="background-color: #FFFFFF; border-bottom-width: 0;" bgcolor="#FFFFFF">
30
- <tr>
31
- <td class="headerContent" style="border-collapse: collapse; color: #202020; font-family: Arial; font-size: 34px; font-weight: bold; line-height: 100%; text-align: left; vertical-align: middle; padding-top: 20px; padding-right: 0; padding-bottom: 0; padding-left: 20px;" align="left" valign="middle">
32
- <!-- // Begin Module: Standard Header Image \\ -->
33
-
34
- <% if attachments['logo.jpg'] %>
35
- <%= image_tag attachments['logo.jpg'].url, style: 'max-width: 240px; height: auto; line-height: 100%; outline: none; text-decoration: none; border-top-width: 0; border-right-width: 0; border-bottom-width: 0; border-left-width: 0;' %>
36
- <% end %>
37
- <!-- // End Module: Standard Header Image \\ -->
38
- </td>
39
- </tr>
40
- </table>
41
-
42
- <!-- // End Template Header \\ -->
43
- </td>
44
- </tr>
45
-
46
- <tr>
47
- <td align="center" valign="top" style="border-collapse: collapse;">
48
- <!-- // Begin Template Body \\ -->
49
- <table border="0" cellpadding="0" cellspacing="0" width="600">
50
- <tr>
51
- <td valign="top" class="bodyContent" style="border-collapse: collapse; background-color: #FFFFFF;" bgcolor="#FFFFFF">
52
- <!-- // Begin Module: Standard Content \\ -->
53
- <table border="0" cellpadding="20" cellspacing="0" width="100%">
54
- <tr>
55
- <td valign="top" style="border-collapse: collapse;">
56
- <div mc:edit="std_content00" style="color: #505050; font-family: Arial; font-size: 14px; line-height: 150%; text-align: left;" align="left">
57
-
58
- <%= yield %>
59
-
60
- <p> Met vriendelijke groet,</p>
61
-
62
- <p>
63
- <% if @current_account.name %>
64
- <%= @current_account.name %>
65
- <br/>
66
- <% end %>
67
- <% if @current_account.address %>
68
- <%= @current_account.address %>
69
- <br/>
70
- <% end %>
71
- <% if @current_account.postal_code %>
72
- <%= @current_account.postal_code %>
73
- <br/>
74
- <% end %>
75
- <% if @current_account.city %>
76
- <%= @current_account.city %>
77
- <br/>
78
- <% end %>
79
- <% if @current_account.phone %>
80
- <%= @current_account.phone %>
81
- <br/>
82
- <% end %>
83
- <% if @current_account.email %>
84
- <%= @current_account.email %>
85
- <br/>
86
- <% end %>
87
- </p>
88
- <br/>
89
-
90
- </div>
91
- </td>
92
- </tr>
93
- </table>
94
- <!-- // End Module: Standard Content \\ -->
95
- </td>
96
- </tr>
97
- </table>
98
- <!-- // End Template Body \\ -->
99
- </td>
100
- </tr>
101
- </table>
102
- <br />
103
- </td>
104
- </tr>
105
- </table>
106
- </center>
107
-
108
- <style type="text/css">
109
- body { width: 100% !important; }
110
- .ReadMsgBody { width: 100% !important; }
111
- .ExternalClass { width: 100% !important; }
112
- body { -webkit-text-size-adjust: none !important; }
113
- body { margin: 0 !important; padding: 0 !important; }
114
- img { border: 0 !important; height: auto !important; line-height: 100% !important; outline: none !important; text-decoration: none !important; }
115
- #backgroundTable { height: 100% !important; margin: 0 !important; padding: 0 !important; width: 100% !important; }
116
- body { background-color: #FAFAFA !important; }
117
- #backgroundTable { background-color: #FAFAFA !important; }
118
- .preheaderContent div a:visited { color: #336699 !important; font-weight: normal !important; text-decoration: underline !important; }
119
- .headerContent a:visited { color: #336699 !important; font-weight: normal !important; text-decoration: underline !important; }
120
- .bodyContent div a:visited { color: #336699 !important; font-weight: normal !important; text-decoration: underline !important; }
121
- .footerContent div a:visited { color: #336699 !important; font-weight: normal !important; text-decoration: underline !important; }
122
- </style>
123
- </body>
124
- </html>
@@ -1,4 +0,0 @@
1
- = f.fields_for :layout_partable, f.object.layout_partable do |ff|
2
- .colorpicker
3
- = ff.text_field :content, placeholder: f.object.title
4
- .colorpicker-container
@@ -1,12 +0,0 @@
1
- .modal
2
- = form_tag spina.wysihtml5_link_admin_page_parts_path(params[:object_id]), method: :post, remote: true do
3
- %header
4
- = link_to "", "#", class: 'close_modal', data: {dismiss: 'modal', icon: 'm'}
5
- %h3=t 'spina.wysiwyg.insert_link'
6
-
7
- %section
8
- = text_field_tag :link, nil, placeholder: "URL"
9
-
10
- %footer
11
- = link_to t('spina.cancel'), "#", data: {dismiss: 'modal'}
12
- = button_tag t('spina.wysiwyg.insert_link'), type: 'submit', class: 'primary', data: {icon: 't '}
@@ -1,5 +0,0 @@
1
- var editor = $(".wysihtml5-container[data-object-id=<%= params[:object_id] %>]").data('wysihtml5');
2
- editor.focus();
3
- editor.composer.commands.exec("createLink", { href: "<%= params[:link] %>", target: "_self" });
4
- editor.focus();
5
- $.hideModal();
@@ -1,2 +0,0 @@
1
- var modal = $("<%= j render 'wysihtml5_link' %>");
2
- modal.modal();
@@ -1,7 +0,0 @@
1
- <% if @photo.new_record? %>
2
- alert("<%= I18n.t 'spina.photos.cannot_be_created' %> <%= j @photo.errors.full_messages.join(', ').html_safe %>");
3
- <% else %>
4
- $item = $("<%=j render partial: 'spina/admin/photos/photo_uploaded', object: @photo %>");
5
- $(".gallery-prepend-image .infinite-scroll").prepend($item);
6
- $(".gallery-prepend-image .infinite-scroll .item:first-child").click();
7
- <% end %>
@@ -1,4 +0,0 @@
1
- <% @photos.each do |photo| %>
2
- $item = $("<%=j render partial: 'spina/admin/photos/photo', object: photo %>");
3
- $(".gallery-prepend-image .infinite-scroll").prepend($item);
4
- <% end %>
@@ -1,3 +0,0 @@
1
- var modal = $("<%= j render 'wysihtml5_select' %>");
2
- modal.modal();
3
- $(document).trigger('page:change');
@@ -1,345 +0,0 @@
1
- /**
2
- * Farbtastic Color Picker 1.2
3
- * © 2008 Steven Wittens
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- */
19
-
20
- jQuery.fn.farbtastic = function (callback) {
21
- $.farbtastic(this, callback);
22
- return this;
23
- };
24
-
25
- jQuery.farbtastic = function (container, callback) {
26
- var container = $(container).get(0);
27
- return container.farbtastic || (container.farbtastic = new jQuery._farbtastic(container, callback));
28
- }
29
-
30
- jQuery._farbtastic = function (container, callback) {
31
- // Store farbtastic object
32
- var fb = this;
33
-
34
- // Insert markup
35
- $(container).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');
36
- var e = $('.farbtastic', container);
37
- fb.wheel = $('.wheel', container).get(0);
38
- // Dimensions
39
- fb.radius = 84;
40
- fb.square = 100;
41
- fb.width = 194;
42
-
43
- // Fix background PNGs in IE6
44
- if (navigator.appVersion.match(/MSIE [0-6]\./)) {
45
- $('*', e).each(function () {
46
- if (this.currentStyle.backgroundImage != 'none') {
47
- var image = this.currentStyle.backgroundImage;
48
- image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
49
- $(this).css({
50
- 'backgroundImage': 'none',
51
- 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
52
- });
53
- }
54
- });
55
- }
56
-
57
- /**
58
- * Link to the given element(s) or callback.
59
- */
60
- fb.linkTo = function (callback) {
61
- // Unbind previous nodes
62
- if (typeof fb.callback == 'object') {
63
- $(fb.callback).unbind('keyup', fb.updateValue);
64
- }
65
-
66
- // Reset color
67
- fb.color = null;
68
-
69
- // Bind callback or elements
70
- if (typeof callback == 'function') {
71
- fb.callback = callback;
72
- }
73
- else if (typeof callback == 'object' || typeof callback == 'string') {
74
- fb.callback = $(callback);
75
- fb.callback.bind('keyup', fb.updateValue);
76
- if (fb.callback.get(0).value) {
77
- fb.setColor(fb.callback.get(0).value);
78
- }
79
- }
80
- return this;
81
- }
82
- fb.updateValue = function (event) {
83
- if (this.value && this.value != fb.color) {
84
- fb.setColor(this.value);
85
- }
86
- }
87
-
88
- /**
89
- * Change color with HTML syntax #123456
90
- */
91
- fb.setColor = function (color) {
92
- var unpack = fb.unpack(color);
93
- if (fb.color != color && unpack) {
94
- fb.color = color;
95
- fb.rgb = unpack;
96
- fb.hsl = fb.RGBToHSL(fb.rgb);
97
- fb.updateDisplay();
98
- }
99
- return this;
100
- }
101
-
102
- /**
103
- * Change color with HSL triplet [0..1, 0..1, 0..1]
104
- */
105
- fb.setHSL = function (hsl) {
106
- fb.hsl = hsl;
107
- fb.rgb = fb.HSLToRGB(hsl);
108
- fb.color = fb.pack(fb.rgb);
109
- fb.updateDisplay();
110
- return this;
111
- }
112
-
113
- /////////////////////////////////////////////////////
114
-
115
- /**
116
- * Retrieve the coordinates of the given event relative to the center
117
- * of the widget.
118
- */
119
- fb.widgetCoords = function (event) {
120
- var x, y;
121
- var el = event.target || event.srcElement;
122
- var reference = fb.wheel;
123
-
124
- if (typeof event.offsetX != 'undefined') {
125
- // Use offset coordinates and find common offsetParent
126
- var pos = { x: event.offsetX, y: event.offsetY };
127
-
128
- // Send the coordinates upwards through the offsetParent chain.
129
- var e = el;
130
- while (e) {
131
- e.mouseX = pos.x;
132
- e.mouseY = pos.y;
133
- pos.x += e.offsetLeft;
134
- pos.y += e.offsetTop;
135
- e = e.offsetParent;
136
- }
137
-
138
- // Look for the coordinates starting from the wheel widget.
139
- var e = reference;
140
- var offset = { x: 0, y: 0 }
141
- while (e) {
142
- if (typeof e.mouseX != 'undefined') {
143
- x = e.mouseX - offset.x;
144
- y = e.mouseY - offset.y;
145
- break;
146
- }
147
- offset.x += e.offsetLeft;
148
- offset.y += e.offsetTop;
149
- e = e.offsetParent;
150
- }
151
-
152
- // Reset stored coordinates
153
- e = el;
154
- while (e) {
155
- e.mouseX = undefined;
156
- e.mouseY = undefined;
157
- e = e.offsetParent;
158
- }
159
- }
160
- else {
161
- // Use absolute coordinates
162
- var pos = fb.absolutePosition(reference);
163
- x = (event.pageX || 0*(event.clientX + $('html').get(0).scrollLeft)) - pos.x;
164
- y = (event.pageY || 0*(event.clientY + $('html').get(0).scrollTop)) - pos.y;
165
- }
166
- // Subtract distance to middle
167
- return { x: x - fb.width / 2, y: y - fb.width / 2 };
168
- }
169
-
170
- /**
171
- * Mousedown handler
172
- */
173
- fb.mousedown = function (event) {
174
- // Capture mouse
175
- if (!document.dragging) {
176
- $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup);
177
- document.dragging = true;
178
- }
179
-
180
- // Check which area is being dragged
181
- var pos = fb.widgetCoords(event);
182
- fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square;
183
-
184
- // Process
185
- fb.mousemove(event);
186
- return false;
187
- }
188
-
189
- /**
190
- * Mousemove handler
191
- */
192
- fb.mousemove = function (event) {
193
- // Get coordinates relative to color picker center
194
- var pos = fb.widgetCoords(event);
195
-
196
- // Set new HSL parameters
197
- if (fb.circleDrag) {
198
- var hue = Math.atan2(pos.x, -pos.y) / 6.28;
199
- if (hue < 0) hue += 1;
200
- fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]);
201
- }
202
- else {
203
- var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5));
204
- var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5));
205
- fb.setHSL([fb.hsl[0], sat, lum]);
206
- }
207
- return false;
208
- }
209
-
210
- /**
211
- * Mouseup handler
212
- */
213
- fb.mouseup = function () {
214
- // Uncapture mouse
215
- $(document).unbind('mousemove', fb.mousemove);
216
- $(document).unbind('mouseup', fb.mouseup);
217
- document.dragging = false;
218
- }
219
-
220
- /**
221
- * Update the markers and styles
222
- */
223
- fb.updateDisplay = function () {
224
- // Markers
225
- var angle = fb.hsl[0] * 6.28;
226
- $('.h-marker', e).css({
227
- left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px',
228
- top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px'
229
- });
230
-
231
- $('.sl-marker', e).css({
232
- left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px',
233
- top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px'
234
- });
235
-
236
- // Saturation/Luminance gradient
237
- $('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5])));
238
-
239
- // Linked elements or callback
240
- if (typeof fb.callback == 'object') {
241
- // Set background/foreground color
242
- $(fb.callback).css({
243
- backgroundColor: fb.color,
244
- color: fb.hsl[2] > 0.5 ? '#000' : '#fff'
245
- });
246
-
247
- // Change linked value
248
- $(fb.callback).each(function() {
249
- if (this.value && this.value != fb.color) {
250
- this.value = fb.color;
251
- }
252
- });
253
- }
254
- else if (typeof fb.callback == 'function') {
255
- fb.callback.call(fb, fb.color);
256
- }
257
- }
258
-
259
- /**
260
- * Get absolute position of element
261
- */
262
- fb.absolutePosition = function (el) {
263
- var r = { x: el.offsetLeft, y: el.offsetTop };
264
- // Resolve relative to offsetParent
265
- if (el.offsetParent) {
266
- var tmp = fb.absolutePosition(el.offsetParent);
267
- r.x += tmp.x;
268
- r.y += tmp.y;
269
- }
270
- return r;
271
- };
272
-
273
- /* Various color utility functions */
274
- fb.pack = function (rgb) {
275
- var r = Math.round(rgb[0] * 255);
276
- var g = Math.round(rgb[1] * 255);
277
- var b = Math.round(rgb[2] * 255);
278
- return '#' + (r < 16 ? '0' : '') + r.toString(16) +
279
- (g < 16 ? '0' : '') + g.toString(16) +
280
- (b < 16 ? '0' : '') + b.toString(16);
281
- }
282
-
283
- fb.unpack = function (color) {
284
- if (color.length == 7) {
285
- return [parseInt('0x' + color.substring(1, 3)) / 255,
286
- parseInt('0x' + color.substring(3, 5)) / 255,
287
- parseInt('0x' + color.substring(5, 7)) / 255];
288
- }
289
- else if (color.length == 4) {
290
- return [parseInt('0x' + color.substring(1, 2)) / 15,
291
- parseInt('0x' + color.substring(2, 3)) / 15,
292
- parseInt('0x' + color.substring(3, 4)) / 15];
293
- }
294
- }
295
-
296
- fb.HSLToRGB = function (hsl) {
297
- var m1, m2, r, g, b;
298
- var h = hsl[0], s = hsl[1], l = hsl[2];
299
- m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s;
300
- m1 = l * 2 - m2;
301
- return [this.hueToRGB(m1, m2, h+0.33333),
302
- this.hueToRGB(m1, m2, h),
303
- this.hueToRGB(m1, m2, h-0.33333)];
304
- }
305
-
306
- fb.hueToRGB = function (m1, m2, h) {
307
- h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
308
- if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
309
- if (h * 2 < 1) return m2;
310
- if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
311
- return m1;
312
- }
313
-
314
- fb.RGBToHSL = function (rgb) {
315
- var min, max, delta, h, s, l;
316
- var r = rgb[0], g = rgb[1], b = rgb[2];
317
- min = Math.min(r, Math.min(g, b));
318
- max = Math.max(r, Math.max(g, b));
319
- delta = max - min;
320
- l = (min + max) / 2;
321
- s = 0;
322
- if (l > 0 && l < 1) {
323
- s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
324
- }
325
- h = 0;
326
- if (delta > 0) {
327
- if (max == r && max != g) h += (g - b) / delta;
328
- if (max == g && max != b) h += (2 + (b - r) / delta);
329
- if (max == b && max != r) h += (4 + (r - g) / delta);
330
- h /= 6;
331
- }
332
- return [h, s, l];
333
- }
334
-
335
- // Install mousedown handler (the others are set on the document on-demand)
336
- $('*', e).mousedown(fb.mousedown);
337
-
338
- // Init color
339
- fb.setColor('#000000');
340
-
341
- // Set linked elements/callback
342
- if (callback) {
343
- fb.linkTo(callback);
344
- }
345
- }