refinerycms-page-images 0.9.9 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,29 +1,6 @@
1
1
  <div class='wym_skin_refinery page_part' id='page_image_picker'>
2
- <div class='wym_area_top'>
3
- <span class='clearfix label_inline_with_link'>
4
- <%= link_to 'Add Image',
5
- insert_admin_images_url(
6
- :dialog => true,
7
- :width => 950,
8
- :height => 510,
9
- :callback => "image_added"
10
- ),
11
- :id => "add_image_link" %>
12
- </span>
13
- </div>
14
- <div class='wym_box field images_field'>
15
- <ul id='page_images' class='clearfix'>
16
- <%= f.fields_for :images do |image_form| %>
17
- <li id='image_<%= image_form.object.id %>'>
18
- <%= image_form.hidden_field :id %>
19
- <%= image_fu image_form.object, '135x135#c' %>
20
- </li>
21
- <% end %>
22
- <li class='empty'>
23
- <%= hidden_field_tag "#{f.object.class.name.underscore}[images_attributes][#{f.object.images.size}][id]" %>
24
- </li>
25
- </ul>
26
- </div>
2
+ <%= render :partial => '/admin/pages/tabs/images_bar' %>
3
+ <%= render :partial => '/admin/pages/tabs/images_field' %>
27
4
  </div>
28
5
 
29
6
  <% content_for :stylesheets do %>
@@ -0,0 +1,12 @@
1
+ <div class='wym_area_top'>
2
+ <span class='clearfix label_inline_with_link'>
3
+ <%= link_to 'Add Image',
4
+ insert_admin_images_url(
5
+ :dialog => true,
6
+ :width => 950,
7
+ :height => 510,
8
+ :callback => "image_added"
9
+ ),
10
+ :id => "add_image_link" %>
11
+ </span>
12
+ </div>
@@ -0,0 +1,30 @@
1
+ <div class='wym_box field images_field'>
2
+ <ul id='page_images' class='clearfix'>
3
+ <%= f.fields_for :images do |image_form| %>
4
+ <li id='image_<%= image_form.object.id %>'>
5
+ <%= image_form.hidden_field :id %>
6
+ <%= image_fu image_form.object, '135x135#c' %>
7
+ <% if RefinerySetting.find_or_set(:page_images_captions, false) %>
8
+ <div class='textarea_wrapper_for_wym'>
9
+ <% index = image_form.object_name.split('[').last.split(']').first.to_i %>
10
+ <%= text_area_tag "#{f.object_name}[images_attributes][#{index}][caption]",
11
+ f.object.caption_for_image_index(index),
12
+ :style => 'display: none',
13
+ :id => "page_captions_#{index}" %>
14
+ </div>
15
+ <% end %>
16
+ </li>
17
+ <% end %>
18
+ <li class='empty'>
19
+ <%= hidden_field_tag "#{f.object.class.name.underscore}[images_attributes][#{f.object.images.size}][id]" %>
20
+ <% if RefinerySetting.find_or_set(:page_images_captions, false) %>
21
+ <div class='textarea_wrapper_for_wym'>
22
+ <%= text_area_tag "#{f.object_name}[images_attributes][#{f.object.images.size}][caption]",
23
+ '',
24
+ :style => 'display: none',
25
+ :id => "page_captions_#{f.object.images.size}" %>
26
+ </div>
27
+ <% end %>
28
+ </li>
29
+ </ul>
30
+ </div>
@@ -0,0 +1,9 @@
1
+ class AddCaptionToImagePages < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :image_pages, :caption, :text
4
+ end
5
+
6
+ def self.down
7
+ remove_column :image_pages, :caption
8
+ end
9
+ end
data/lib/gemspec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- version = '0.9.9'
2
+ version = '1.0'
3
3
  raise "Could not get version so gemspec can not be built" if version.nil?
4
4
  files = (Dir.glob("*") | Dir.glob("**/*")).reject{|f| f =~ %r{.gem(spec)?$}}
5
5
 
@@ -16,11 +16,22 @@ module Refinery
16
16
  accepts_nested_attributes_for :images, :allow_destroy => false
17
17
 
18
18
  def images_attributes=(data)
19
- self.images.clear
20
- data.reject!{|i, d| d['id'].blank?}
21
- self.images += (0..(data.length-1)).collect { |i|
22
- (Image.find(data[i.to_s]['id'].to_i) rescue nil)
23
- }.compact
19
+ ImagePage.delete_all(:page_id => self.id)
20
+
21
+ (0..(data.length-1)).each do |i|
22
+ unless (image_data = data[i.to_s]).nil? or image_data['id'].blank?
23
+ image_page = self.image_pages.new(:image_id => image_data['id'].to_i, :position => i)
24
+ # Add caption if supported
25
+ if RefinerySetting.find_or_set(:page_images_captions, false)
26
+ image_page.caption = image_data['caption']
27
+ end
28
+ self.image_pages << image_page
29
+ end
30
+ end
31
+ end
32
+
33
+ def caption_for_image_index(index)
34
+ self.image_pages[index].try(:caption).presence || ""
24
35
  end
25
36
  end
26
37
  end
@@ -22,6 +22,10 @@ $(document).ready(function(){
22
22
  });
23
23
 
24
24
  reset_functionality = function() {
25
+ WYMeditor.onload_functions.push(function(){
26
+ $('.wym_box').css({'width':null});
27
+ });
28
+
25
29
  $("#page_images").sortable({
26
30
  'tolerance': 'pointer'
27
31
  , 'placeholder': 'placeholder'
@@ -30,8 +34,8 @@ reset_functionality = function() {
30
34
  , stop: reindex_images
31
35
  });
32
36
 
33
- $('#content #page_images li:not(.empty)').each(function(index, li) {
34
- $(this).hover(function(e){
37
+ $('#content #page_images li:not(.empty)').live('hover', function(e) {
38
+ if (e.type == 'mouseenter' || e.type == 'mouseover') {
35
39
  if ((image_actions = $(this).find('.image_actions')).length == 0) {
36
40
  image_actions = $("<div class='image_actions'></div>");
37
41
  img_delete = $("<img src='/images/refinery/icons/delete.png' width='16' height='16' />");
@@ -41,13 +45,17 @@ reset_functionality = function() {
41
45
  reindex_images();
42
46
  });
43
47
 
44
- image_actions.appendTo($(li));
48
+ img_caption = $("<img src='/images/refinery/icons/user_comment.png' width='16' height='16' class='caption' />");
49
+ img_caption.appendTo(image_actions);
50
+ img_caption.click(open_image_caption);
51
+
52
+ image_actions.appendTo($(this));
45
53
  }
46
54
 
47
55
  image_actions.show();
48
- }, function(e) {
56
+ } else if (e.type == 'mouseleave' || e.type == 'mouseout') {
49
57
  $(this).find('.image_actions').hide();
50
- });
58
+ }
51
59
  });
52
60
 
53
61
  reindex_images();
@@ -70,9 +78,56 @@ image_added = function(image) {
70
78
  reset_functionality();
71
79
  }
72
80
 
81
+ open_image_caption = function(e) {
82
+ // move the textarea out of the list item, and then move the textarea back into it when we click done.
83
+ (list_item = $(this).parents('li')).addClass('current_caption_list_item');
84
+ textarea = list_item.find('.textarea_wrapper_for_wym > textarea');
85
+
86
+ textarea.after($("<div class='form-actions'><div class='form-actions-left'><a class='button'>Done</a></div></div>"));
87
+ textarea.parent().dialog({
88
+ title: 'Add Caption'
89
+ , modal: true
90
+ , resizable: false
91
+ , autoOpen: true
92
+ , width: 928
93
+ , height: 530
94
+ });
95
+
96
+ $('.ui-dialog:visible .ui-dialog-titlebar-close, .ui-dialog:visible .form-actions a.button')
97
+ .bind('click',
98
+ $.proxy(function(e) {
99
+ // first, update the editor because we're blocking event bubbling (third argument to bind set to false).
100
+ $(this).data('wymeditor').update();
101
+ $(this).removeClass('wymeditor')
102
+ .removeClass('active_rotator_wymeditor');
103
+
104
+ $this_parent = $(this).parent();
105
+ $this_parent.appendTo('li.current_caption_list_item').dialog('close').data('dialog', null);
106
+ $this_parent.find('.form-actions').remove();
107
+ $this_parent.find('.wym_box').remove();
108
+ $this_parent.css('height', 'auto');
109
+ $this_parent.removeClass('ui-dialog-content').removeClass('ui-widget-content');
110
+
111
+ $('li.current_caption_list_item').removeClass('current_caption_list_item');
112
+
113
+ $('.ui-dialog, .ui-widget-overlay:visible').remove();
114
+ }, textarea)
115
+ , false);
116
+
117
+ textarea.addClass('wymeditor active_rotator_wymeditor widest').wymeditor(wymeditor_boot_options);
118
+ }
119
+
73
120
  reindex_images = function() {
74
- $('#page_images li input:hidden').each(function(i, input){
121
+ $('#page_images li textarea:hidden').each(function(i, input){
122
+ // make the image's name consistent with its position.
123
+ parts = $(input).attr('name').split(']');
124
+ parts[1] = ('[' + i);
125
+ $(input).attr('name', parts.join(']'));
75
126
 
127
+ // make the image's id consistent with its position.
128
+ $(input).attr('id', $(input).attr('id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_'+i));
129
+ });
130
+ $('#page_images li input:hidden').each(function(i, input){
76
131
  // make the image's name consistent with its position.
77
132
  parts = $(input).attr('name').split(']');
78
133
  parts[1] = ('[' + i);
@@ -13,34 +13,40 @@
13
13
  margin-right: 18px;
14
14
  }
15
15
  #page_images {
16
- width: 100%;
16
+ width: 100%;
17
17
  }
18
18
  #page_images li {
19
- margin-right: 20px;
20
- position: relative;
21
- margin-bottom: 10px;
22
- margin-top: 10px;
19
+ margin-right: 20px;
20
+ position: relative;
21
+ margin-bottom: 10px;
22
+ margin-top: 10px;
23
23
  }
24
24
  #page_images li .image_actions {
25
- background: white;
26
- position: absolute;
27
- padding: 3px;
28
- left: 0px;
29
- top: 0px;
25
+ background: white;
26
+ position: absolute;
27
+ padding: 3px;
28
+ left: 0px;
29
+ top: 0px;
30
+ width: 135px;
31
+ }
32
+ #page_images > li .image_actions img.caption {
33
+ position: absolute;
34
+ right: 3px;
35
+ top: 3px;
30
36
  }
31
37
  #page_images li * {
32
- cursor: move;
38
+ cursor: move;
33
39
  }
34
40
  #page_images li .image_actions * {
35
- cursor: pointer;
41
+ cursor: pointer;
36
42
  }
37
43
  #content ul.ui-sortable li {
38
- border: 0px none;
39
- background: none !important;
44
+ border: 0px none;
45
+ background: none !important;
40
46
  }
41
47
  #content #page_images.ui-sortable li.placeholder {
42
- width: 135px;
43
- height: 135px;
48
+ width: 135px;
49
+ height: 135px;
44
50
  }
45
51
 
46
52
  a#add_image_link {
data/readme.md CHANGED
@@ -17,7 +17,7 @@ Page Images allows you to relate one or more images to any page in Refinery whic
17
17
 
18
18
  Add this line to your applications `Gemfile`
19
19
 
20
- gem 'refinerycms-page-images', '~> 0.9.9'
20
+ gem 'refinerycms-page-images', '~> 1.0'
21
21
 
22
22
  Next run
23
23
 
@@ -29,11 +29,11 @@ Now when you start up your Refinery application, edit a page and there should be
29
29
 
30
30
  If you get an error like
31
31
 
32
- uninitialized constant Refinery::Pages::Tab
32
+ uninitialized constant Refinery::Pages::Tab
33
33
 
34
34
  It means your Refinery version isn't new enough. To fix that you need to update the Refinery CMS `Gemfile` line to this
35
35
 
36
- gem 'refinerycms', :git => "git://github.com/resolve/refinerycms.git"
36
+ gem 'refinerycms', '~> 0.9.9'
37
37
 
38
38
  Then run:
39
39
 
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-page-images
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 9
8
- - 9
9
- version: 0.9.9
4
+ prerelease:
5
+ version: "1.0"
10
6
  platform: ruby
11
7
  authors:
12
8
  - Resolve Digital
@@ -16,7 +12,7 @@ autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
14
 
19
- date: 2010-12-31 00:00:00 +13:00
15
+ date: 2011-01-31 00:00:00 +13:00
20
16
  default_executable:
21
17
  dependencies:
22
18
  - !ruby/object:Gem::Dependency
@@ -27,10 +23,6 @@ dependencies:
27
23
  requirements:
28
24
  - - ">="
29
25
  - !ruby/object:Gem::Version
30
- segments:
31
- - 0
32
- - 9
33
- - 9
34
26
  version: 0.9.9
35
27
  type: :runtime
36
28
  version_requirements: *id001
@@ -46,7 +38,10 @@ files:
46
38
  - readme.md
47
39
  - app/models/image_page.rb
48
40
  - app/views/admin/pages/tabs/_images.html.erb
49
- - db/migrate/create_page_images.rb
41
+ - app/views/admin/pages/tabs/_images_bar.html.erb
42
+ - app/views/admin/pages/tabs/_images_field.html.erb
43
+ - db/migrate/20101014230041_create_page_images.rb
44
+ - db/migrate/20101014230042_add_caption_to_image_pages.rb
50
45
  - lib/gemspec.rb
51
46
  - lib/generators/refinerycms_page_images_generator.rb
52
47
  - lib/refinerycms-page-images.rb
@@ -66,21 +61,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
61
  requirements:
67
62
  - - ">="
68
63
  - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
64
  version: "0"
72
65
  required_rubygems_version: !ruby/object:Gem::Requirement
73
66
  none: false
74
67
  requirements:
75
68
  - - ">="
76
69
  - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
70
  version: "0"
80
71
  requirements: []
81
72
 
82
73
  rubyforge_project:
83
- rubygems_version: 1.3.7
74
+ rubygems_version: 1.5.0
84
75
  signing_key:
85
76
  specification_version: 3
86
77
  summary: Page Images Engine for Refinery CMS