refinerycms-page-images 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +20 -9
  3. data/Gemfile +22 -51
  4. data/Rakefile +2 -0
  5. data/app/assets/javascripts/refinery/page-image-picker.js.erb +173 -150
  6. data/app/assets/stylesheets/refinery/page-image-picker.css.scss +6 -0
  7. data/app/views/refinery/admin/pages/tabs/_images.html.erb +2 -1
  8. data/app/views/refinery/admin/pages/tabs/_images_field.html.erb +15 -3
  9. data/config/locales/bg.yml +1 -0
  10. data/config/locales/cs.yml +1 -0
  11. data/config/locales/de.yml +3 -1
  12. data/config/locales/en.yml +2 -0
  13. data/config/locales/es.yml +19 -0
  14. data/config/locales/fr.yml +1 -0
  15. data/config/locales/ja.yml +18 -0
  16. data/config/locales/nl.yml +1 -0
  17. data/config/locales/pt-BR.yml +1 -0
  18. data/config/locales/ru.yml +1 -0
  19. data/config/locales/sk.yml +1 -0
  20. data/lib/generators/refinery/templates/config/initializers/refinery/page_images.rb.erb +2 -0
  21. data/lib/refinery/page_images.rb +15 -2
  22. data/lib/refinery/page_images/configuration.rb +25 -1
  23. data/lib/refinery/page_images/engine.rb +17 -19
  24. data/lib/refinery/page_images/extension.rb +2 -2
  25. data/readme.md +48 -2
  26. data/refinerycms-page-images.gemspec +7 -8
  27. data/spec/factories/page-images.rb +2 -2
  28. data/spec/features/attach_page_images_spec.rb +58 -0
  29. data/spec/lib/refinery/initializer_spec.rb +42 -0
  30. data/spec/models/refinery/blog_spec.rb +3 -3
  31. data/spec/models/refinery/page_spec.rb +26 -16
  32. data/spec/spec_helper.rb +21 -46
  33. metadata +43 -82
  34. data/spec/requests/attach_page_images_spec.rb +0 -29
  35. data/spec/support/database_cleaner.rb +0 -17
  36. data/spec/support/devise.rb +0 -8
  37. data/spec/support/refinery.rb +0 -6
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d734dccd4a97c7c04d9752e6cfd85cb2b6266997
4
+ data.tar.gz: beeee224e8b42b0425e26a3e3e8a49c09aba4e3e
5
+ SHA512:
6
+ metadata.gz: 515f2c187884f0a6157d5a05fdadf9f2a88c83b77216cafb8091fab7eceb090e12a3f1402c2e56e0eb8ad270ab321c70f8b7af1fd0e399dedf282e1deac74819
7
+ data.tar.gz: 3a35eaefb138d3104354a442ac6df63c5313a46ba56ec7fc981edf9c9a0e9552daf35a8bf302fa056a5b95852fd527894b5f964c0b6dded04c5f508415952864
data/.travis.yml CHANGED
@@ -1,16 +1,27 @@
1
+ language: ruby
2
+ bundler_args: --without development
1
3
  before_script:
2
- - "bundle exec rake refinery:testing:dummy_app > /dev/null"
3
- script: "bundle exec rspec ./spec"
4
+ - "sh -e /etc/init.d/xvfb start"
5
+ - "bundle exec rake refinery:testing:dummy_app"
6
+ script:
7
+ - "DISPLAY=:99.0 bundle exec rspec spec"
4
8
  notifications:
5
- email:
6
- - parndt@gmail.com
7
- - ugis.ozolss@gmail.com
9
+ email: true
10
+ irc:
11
+ use_notice: true
12
+ skip_join: true
13
+ channels:
14
+ - "irc.freenode.org#refinerycms"
15
+ campfire:
16
+ on_success: always
17
+ on_failure: always
18
+ rooms:
19
+ - secure: "X5X39BTgXacSdc32F8mIjJKPqm5dZzmgZfJ14qYpJeMETTdA5JfByt2uCfU8\njJkkxT+XGWta0bSSlRIHQJO6pK26U94A95VYDX0jNuneKEnsoAsqJ6U0VY6v\nH5oxXMAZ2perP/FH9ZsPNR+ulyFfbMQCeGPJw5AXKZQqzf6qPOI="
8
20
  env:
9
21
  - DB=postgresql
10
22
  - DB=mysql
11
23
  rvm:
12
- - 1.8.7
13
- - 1.9.2
24
+ - 2.0.0
14
25
  - 1.9.3
15
- - rbx
16
- - jruby
26
+ - rbx-19mode
27
+ - jruby-19mode
data/Gemfile CHANGED
@@ -2,62 +2,30 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'refinerycms', '~> 2.0.1'
5
+ gem 'refinerycms', '~> 2.1.0'
6
+ gem 'refinerycms-testing', '~> 2.1.0', :group => :test
6
7
 
7
- group :development, :test do
8
- gem 'refinerycms-testing', '~> 2.0.0'
8
+ # Database Configuration
9
+ unless ENV['TRAVIS']
10
+ gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
11
+ gem 'sqlite3', :platform => :ruby
9
12
  end
10
13
 
11
- group :development, :test do
12
- require 'rbconfig'
13
-
14
- platforms :jruby do
15
- gem 'activerecord-jdbcsqlite3-adapter'
16
- gem 'activerecord-jdbcmysql-adapter'
17
- gem 'activerecord-jdbcpostgresql-adapter'
18
- gem 'jruby-openssl'
19
- end
20
-
21
- unless defined?(JRUBY_VERSION)
22
- gem 'sqlite3'
23
- gem 'mysql2'
24
- gem 'pg'
25
- end
26
-
27
- platforms :mswin, :mingw do
28
- gem 'win32console'
29
- gem 'rb-fchange', '~> 0.0.5'
30
- gem 'rb-notifu', '~> 0.0.4'
31
- end
14
+ if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
15
+ gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
16
+ gem 'jdbc-mysql', '= 5.1.13', :platform => :jruby
17
+ gem 'mysql2', :platform => :ruby
18
+ end
32
19
 
33
- platforms :ruby do
34
- gem 'spork', '0.9.0.rc9'
35
- gem 'guard-spork'
20
+ if !ENV['TRAVIS'] || ENV['DB'] == 'postgresql'
21
+ gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
22
+ gem 'pg', :platform => :ruby
23
+ end
36
24
 
37
- unless ENV['TRAVIS']
38
- if RbConfig::CONFIG['target_os'] =~ /darwin/i
39
- gem 'rb-fsevent', '>= 0.3.9'
40
- gem 'growl', '~> 1.0.3'
41
- end
42
- if RbConfig::CONFIG['target_os'] =~ /linux/i
43
- gem 'rb-inotify', '>= 0.5.1'
44
- gem 'libnotify', '~> 0.1.3'
45
- gem 'therubyracer', '~> 0.9.9'
46
- end
47
- end
48
- end
25
+ gem 'jruby-openssl', :platform => :jruby
49
26
 
50
- platforms :jruby do
51
- unless ENV['TRAVIS']
52
- if RbConfig::CONFIG['target_os'] =~ /darwin/i
53
- gem 'growl', '~> 1.0.3'
54
- end
55
- if RbConfig::CONFIG['target_os'] =~ /linux/i
56
- gem 'rb-inotify', '>= 0.5.1'
57
- gem 'libnotify', '~> 0.1.3'
58
- end
59
- end
60
- end
27
+ group :test do
28
+ gem 'poltergeist'
61
29
  end
62
30
 
63
31
  # Refinery/rails should pull in the proper versions of these
@@ -67,4 +35,7 @@ group :assets do
67
35
  gem 'uglifier'
68
36
  end
69
37
 
70
- gem 'jquery-rails'
38
+ # Load local gems according to Refinery developer preference.
39
+ if File.exist? local_gemfile = File.expand_path('../.gemfile', __FILE__)
40
+ eval File.read(local_gemfile)
41
+ end
data/Rakefile CHANGED
@@ -17,3 +17,5 @@ Refinery::Testing::Railtie.load_tasks
17
17
  Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
18
18
 
19
19
  load File.expand_path('../tasks/rspec.rake', __FILE__)
20
+
21
+ task :default => :spec
@@ -1,167 +1,190 @@
1
- $(document).ready(function(){
2
- $('#custom_images_tab a').click(function(){
3
- if (!(picker = $('#page_image_picker')).data('size-applied')){
4
- wym_box = $('.page_part:first .wym_box');
5
- iframe = $('.page_part:first iframe');
6
- picker.css({
7
- height: wym_box.height()
8
- , width: wym_box.width()
9
- }).data('size-applied', true).corner('tr 5px').corner('bottom 5px').find('.wym_box').css({
10
- backgroundColor: 'white'
11
- , height: iframe.height() + $('.page_part:first .wym_area_top').height() - parseInt($('.wym_area_top .label_inline_with_link a').css('lineHeight'))
12
- , width: iframe.width() - 20
13
- , 'border-color': iframe.css('border-top-color')
14
- , 'border-style': iframe.css('border-top-style')
15
- , 'border-width': iframe.css('border-top-width')
16
- , padding: '0px 10px 0px 10px'
17
- });
18
- }
19
- });
1
+ <%# encoding: utf-8 %>
2
+ var image_added; // Global callback
3
+ (function($) {
4
+ var reset_functionality, open_image_caption, reindex_images,
5
+ template_li, wysiwyg_enabled, input_type;
6
+ $(document).ready(function(){
7
+ var picker = $('#page_image_picker');
8
+ input_type = picker.data('input-type');
9
+ wysiwyg_enabled = input_type == 'wym';
10
+
11
+ $('#custom_images_tab a').click(function(){
12
+ if (!picker.data('size-applied') && wysiwyg_enabled){
13
+ var wym_box = $('.page_part:first .wym_box'),
14
+ iframe = $('.page_part:first iframe');
15
+ picker.css({
16
+ height: wym_box.height()
17
+ , width: wym_box.width()
18
+ }).data('size-applied', true).corner('tr 5px').corner('bottom 5px').find('.wym_box').css({
19
+ backgroundColor: 'white'
20
+ , height: iframe.height() + $('.page_part:first .wym_area_top').height() - parseInt($('.wym_area_top .label_inline_with_link a').css('lineHeight'))
21
+ , width: iframe.width() - 20
22
+ , 'border-color': iframe.css('border-top-color')
23
+ , 'border-style': iframe.css('border-top-style')
24
+ , 'border-width': iframe.css('border-top-width')
25
+ , padding: '0px 10px 0px 10px'
26
+ });
27
+ }
28
+ });
20
29
 
21
- // Webkit browsers don't like the textarea being moved around the DOM,
22
- // they ignore the new contents. This is fixed below by adding a hidden
23
- // field that stays in place.
24
- $('#content #page_images li textarea:hidden').each(function(index) {
25
- var old_name = $(this).attr('name');
26
- $(this).attr('data-old-id', $(this).attr('id'));
27
- $(this).attr('name', 'ignore_me_' + index);
28
- $(this).attr('id', 'ignore_me_' + index);
29
-
30
- var hidden = $('<input>')
31
- .addClass('caption')
32
- .attr('type', 'hidden')
33
- .attr('name', old_name)
34
- .attr('id', $(this).attr('data-old-id'))
35
- .val($(this).val());
36
-
37
- $(this).parents('li').first().append(hidden);
38
- });
30
+ // Webkit browsers don't like the textarea being moved around the DOM,
31
+ // they ignore the new contents. This is fixed below by adding a hidden
32
+ // field that stays in place.
33
+ $('#page_images li textarea:hidden').each(function(index) {
34
+ var old_name = $(this).attr('name'),
35
+ $this = $(this);
36
+ $this.attr('data-old-id', $this.attr('id'));
37
+ $this.attr('name', 'ignore_me_' + index);
38
+ $this.attr('id', 'ignore_me_' + index);
39
+
40
+ var hidden = $('<input>')
41
+ .addClass('caption')
42
+ .attr('type', 'hidden')
43
+ .attr('name', old_name)
44
+ .attr('id', $this.attr('data-old-id'))
45
+ .val($this.val());
46
+
47
+ $this.parents('li').first().append(hidden);
48
+ });
39
49
 
40
- reset_functionality();
41
- });
50
+ reset_functionality();
42
51
 
43
- reset_functionality = function() {
44
- WYMeditor.onload_functions.push(function(){
45
- $('.wym_box').css({'width':null});
46
- });
47
52
 
48
- $("#page_images").sortable({
49
- 'tolerance': 'pointer'
50
- , 'placeholder': 'placeholder'
51
- , 'cursor': 'drag'
52
- , 'items': 'li'
53
- , stop: reindex_images
53
+ // Once the plugin has init'd everything, remove the template UI
54
+ $('.page-images-caption-modal').hide();
55
+ template_li = $('#page_images .js-page-images-template').detach();
54
56
  });
55
57
 
56
- $('#content #page_images li:not(.empty)').live('hover', function(e) {
57
- if (e.type == 'mouseenter' || e.type == 'mouseover') {
58
- if ((image_actions = $(this).find('.image_actions')).length == 0) {
59
- image_actions = $("<div class='image_actions'></div>");
60
- img_delete = $("<img src='/assets/refinery/icons/delete.png' width='16' height='16' />");
61
- img_delete.appendTo(image_actions);
62
- img_delete.click(function() {
63
- $(this).parents('li').first().remove();
64
- reindex_images();
65
- });
58
+ reset_functionality = function() {
59
+ if(wysiwyg_enabled) {
60
+ WYMeditor.onload_functions.push(function(){
61
+ $('.wym_box').css({'width':null});
62
+ });
63
+ }
64
+
65
+ $("#page_images").sortable({
66
+ 'tolerance': 'pointer'
67
+ , 'placeholder': 'placeholder'
68
+ , 'cursor': 'drag'
69
+ , 'items': 'li'
70
+ , stop: reindex_images
71
+ });
66
72
 
67
- if ($(this).find('textarea.page_caption').length > 0) {
68
- img_caption = $("<img src='/assets/refinery/icons/user_comment.png' width='16' height='16' class='caption' />");
69
- img_caption.appendTo(image_actions);
70
- img_caption.click(open_image_caption);
71
- } else {
72
- image_actions.addClass('no_captions');
73
+ $('#page_images').on('mouseenter mouseleave', 'li', function(e) {
74
+ var $this = $(this),
75
+ image_actions = $this.find('.image_actions');
76
+ if (e.type == 'mouseenter') {
77
+ if (image_actions.length == 0) {
78
+ image_actions = $("<div class='image_actions'></div>");
79
+ var img_delete = $("<img src='<%= image_path('refinery/icons/delete.png') %>' width='16' height='16' />");
80
+ img_delete.appendTo(image_actions);
81
+ img_delete.click(function() {
82
+ $(this).parents('li').first().remove();
83
+ reindex_images();
84
+ });
85
+
86
+ if ($this.find('textarea.page_caption').length > 0) {
87
+ var img_caption = $("<img src='<%= image_path('refinery/icons/user_comment.png') %>' width='16' height='16' class='caption' />");
88
+ img_caption.appendTo(image_actions);
89
+ img_caption.click(open_image_caption);
90
+ } else {
91
+ image_actions.addClass('no_captions');
92
+ }
93
+
94
+ image_actions.appendTo($this);
73
95
  }
74
96
 
75
- image_actions.appendTo($(this));
97
+ image_actions.show();
98
+ } else if (e.type == 'mouseleave') {
99
+ image_actions.hide();
76
100
  }
101
+ });
102
+
103
+ reindex_images();
104
+ };
105
+
106
+ image_added = function(image) {
107
+ var current_list_item = template_li.clone(),
108
+ image_id = $(image).attr('id').replace('image_', '');
109
+ current_list_item.find('input:hidden:first').val(image_id);
110
+
111
+ $("<img />").attr({
112
+ title: $(image).attr('title')
113
+ , alt: $(image).attr('alt')
114
+ , src: $(image).attr('data-grid') // use 'grid' size that is built into Refinery CMS (135x135#c).
115
+ }).appendTo(current_list_item);
116
+
117
+ current_list_item.attr('id', 'image_' + image_id).removeClass('empty');
118
+
119
+ current_list_item.appendTo($('#page_images'));
120
+ reset_functionality();
121
+ };
122
+
123
+ open_image_caption = function(e) {
124
+ var list_item = $(this).closest('li'),
125
+ textarea = list_item.find('.page-images-caption-modal > textarea'),
126
+ textarea_wrapper = textarea.parent(),
127
+ modal_size = {
128
+ textarea: { width: 400, height: 'auto' },
129
+ wym: { width: 928, height: 530 }
130
+ };
131
+
132
+ textarea_wrapper.find('.js-page-images-done').on('click', function() {
133
+ textarea_wrapper.dialog("close");
134
+ });
135
+
136
+ var close_handler = function() {
137
+ if(wysiwyg_enabled) {
138
+ textarea.data('wymeditor').update();
139
+ }
140
+
141
+ $('li.current_caption_list_item').removeClass('current_caption_list_item');
142
+ $('#' + textarea.attr('data-old-id')).val(textarea.val());
143
+ textarea_wrapper.dialog('destroy');
144
+ };
145
+
146
+ // move the textarea out of the list item, and then move the textarea back into it when we click done.
147
+ list_item.addClass('current_caption_list_item');
148
+ textarea_wrapper.dialog({
149
+ title: "<%= I18n.t('refinery.js.admin.page_images.add_caption') %>"
150
+ , modal: true
151
+ , resizable: false
152
+ , autoOpen: true
153
+ , width: modal_size[input_type].width
154
+ , height: modal_size[input_type].height
155
+ , close: close_handler
156
+ });
77
157
 
78
- image_actions.show();
79
- } else if (e.type == 'mouseleave' || e.type == 'mouseout') {
80
- $(this).find('.image_actions').hide();
158
+ if(wysiwyg_enabled) {
159
+ textarea.addClass('wymeditor active_rotator_wymeditor widest').wymeditor(wymeditor_boot_options);
81
160
  }
82
- });
161
+ else {
162
+ textarea.show();
163
+ }
164
+ };
83
165
 
84
- reindex_images();
85
- }
86
-
87
- image_added = function(image) {
88
- new_list_item = (current_list_item = $('li.empty')).clone();
89
- image_id = $(image).attr('id').replace('image_', '');
90
- current_list_item.find('input:hidden:first').val(image_id);
91
-
92
- $("<img />").attr({
93
- title: $(image).attr('title')
94
- , alt: $(image).attr('alt')
95
- , src: $(image).attr('data-grid') // use 'grid' size that is built into Refinery CMS (135x135#c).
96
- }).appendTo(current_list_item);
97
-
98
- current_list_item.attr('id', 'image_' + image_id).removeClass('empty');
99
-
100
- new_list_item.appendTo($('#page_images'));
101
- reset_functionality();
102
- }
103
-
104
- open_image_caption = function(e) {
105
- // move the textarea out of the list item, and then move the textarea back into it when we click done.
106
- (list_item = $(this).parents('li').first()).addClass('current_caption_list_item');
107
- textarea = list_item.find('.textarea_wrapper_for_wym > textarea');
108
-
109
- textarea.after($("<div class='form-actions'><div class='form-actions-left'><a class='button'><%= I18n.t('refinery.js.admin.page_images.done') %></a></div></div>"));
110
- textarea.parent().dialog({
111
- title: "<%= I18n.t('refinery.js.admin.page_images.add_caption') %>"
112
- , modal: true
113
- , resizable: false
114
- , autoOpen: true
115
- , width: 928
116
- , height: 530
117
- });
118
-
119
- $('.ui-dialog:visible .ui-dialog-titlebar-close, .ui-dialog:visible .form-actions a.button')
120
- .on('click',
121
- $.proxy(function(e) {
122
- // first, update the editor because we're blocking event bubbling (third argument to bind set to false).
123
- $(this).data('wymeditor').update();
124
- $(this).removeClass('wymeditor')
125
- .removeClass('active_rotator_wymeditor');
126
-
127
- $this_parent = $(this).parent();
128
- $this_parent.appendTo('li.current_caption_list_item').dialog('close').data('dialog', null);
129
- $this_parent.find('.form-actions').remove();
130
- $this_parent.find('.wym_box').remove();
131
- $this_parent.css('height', 'auto');
132
- $this_parent.removeClass('ui-dialog-content').removeClass('ui-widget-content');
133
-
134
- $('li.current_caption_list_item').removeClass('current_caption_list_item');
135
-
136
- $('.ui-dialog, .ui-widget-overlay:visible').remove();
137
-
138
- $('#' + $(this).attr('data-old-id')).val($(this).val());
139
- }, textarea)
140
- );
141
-
142
- textarea.addClass('wymeditor active_rotator_wymeditor widest').wymeditor(wymeditor_boot_options);
143
- }
144
-
145
- reindex_images = function() {
146
- $('#page_images li textarea:hidden').each(function(i, input){
147
- // make the image's name consistent with its position.
148
- parts = $(input).attr('name').split('_');
149
- parts[2] = ('' + i);
150
- $(input).attr('name', parts.join('_'));
151
-
152
- // make the image's id consistent with its position.
153
- $(input).attr('id', $(input).attr('id').replace(/_\d/, '_' + i));
154
- $(input).attr('data-old-id', $(input).attr('data-old-id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_' + i));
155
- });
156
- $('#page_images li').each(function(i, li){
157
- $('input:hidden', li).each(function() {
166
+ reindex_images = function() {
167
+ $('#page_images li textarea:hidden').each(function(i, input){
158
168
  // make the image's name consistent with its position.
159
- parts = $(this).attr('name').split(']');
160
- parts[1] = ('[' + i);
161
- $(this).attr('name', parts.join(']'));
169
+ var parts = $(input).attr('name').split('_');
170
+ parts[2] = ('' + i);
171
+ $(input).attr('name', parts.join('_'));
162
172
 
163
173
  // make the image's id consistent with its position.
164
- $(this).attr('id', $(this).attr('id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_'+i));
174
+ $(input).attr('id', $(input).attr('id').replace(/_\d/, '_' + i));
175
+ $(input).attr('data-old-id', $(input).attr('data-old-id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_' + i));
165
176
  });
166
- });
167
- }
177
+ $('#page_images li').each(function(i, li){
178
+ $('input:hidden', li).each(function() {
179
+ var $this = $(this);
180
+ // make the image's name consistent with its position.
181
+ var parts = $this.attr('name').split(']');
182
+ parts[1] = ('[' + i);
183
+ $this.attr('name', parts.join(']'));
184
+
185
+ // make the image's id consistent with its position.
186
+ $this.attr('id', $this.attr('id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_'+i));
187
+ });
188
+ });
189
+ }
190
+ })(jQuery);