Commit fe4f32cff6963a67f4828e5d11338d2e29e8829b
1 parent
692325d6
Exists in
master
and in
28 other branches
Replaced lightbox to colorbox on New conten link
(ActionItem2382)
Showing
8 changed files
with
75 additions
and
4 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +module ColorboxHelper | ||
2 | + | ||
3 | + def colorbox_close_button(text, options = {}) | ||
4 | + button(:close, text, '#', colorbox_options(options, :close)) | ||
5 | + end | ||
6 | + | ||
7 | + def colorbox_button(type, label, url, options = {}) | ||
8 | + button(type, label, url, colorbox_options(options)) | ||
9 | + end | ||
10 | + | ||
11 | + # options must be an HTML options hash as passed to link_to etc. | ||
12 | + # | ||
13 | + # returns a new hash with colorbox class added. Keeps existing classes. | ||
14 | + def colorbox_options(options, type=nil) | ||
15 | + the_class = 'colorbox' | ||
16 | + the_class += "-#{type.to_s}" unless type.nil? | ||
17 | + the_class << " #{options[:class]}" if options.has_key?(:class) | ||
18 | + options.merge(:class => the_class) | ||
19 | + end | ||
20 | + | ||
21 | +end |
app/views/cms/select_article_type.rhtml
app/views/cms/view.rhtml
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <% button_bar(:style => 'margin-bottom: 1em;') do %> | 5 | <% button_bar(:style => 'margin-bottom: 1em;') do %> |
6 | <% parent_id = ((@article && @article.allow_children?) ? @article : nil) %> | 6 | <% parent_id = ((@article && @article.allow_children?) ? @article : nil) %> |
7 | 7 | ||
8 | - <%= lightbox_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %> | 8 | + <%= colorbox_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %> |
9 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor', :action => "index") %> | 9 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor', :action => "index") %> |
10 | <% end %> | 10 | <% end %> |
11 | 11 |
app/views/content_viewer/_article_toolbar.rhtml
@@ -33,7 +33,7 @@ | @@ -33,7 +33,7 @@ | ||
33 | :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)), | 33 | :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)), |
34 | :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }), | 34 | :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }), |
35 | :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> | 35 | :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> |
36 | - <%= lightbox_remote_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) %> | 36 | + <%= colorbox_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) %> |
37 | <% end %> | 37 | <% end %> |
38 | 38 | ||
39 | <% if @page.accept_uploads? && @page.allow_create?(user) %> | 39 | <% if @page.accept_uploads? && @page.allow_create?(user) %> |
app/views/content_viewer/view_page.rhtml
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | <div id="article-toolbar"></div> | 9 | <div id="article-toolbar"></div> |
10 | 10 | ||
11 | <script type="text/javascript"> | 11 | <script type="text/javascript"> |
12 | - <%= remote_function :update => "article-toolbar", :url => @page.url.merge({ :toolbar => true, :only_path => true }), :complete => "$$('#article-toolbar .remote-lbOn').each(function(link) { new lightbox(link); }); jQuery('#article-toolbar .simplemenu-trigger').click(function(e) { e.stopPropagation(); })" %> | 12 | + <%= remote_function :update => "article-toolbar", :url => @page.url.merge({ :toolbar => true, :only_path => true }) %> |
13 | </script> | 13 | </script> |
14 | 14 | ||
15 | <% if !@page.tags.empty? %> | 15 | <% if !@page.tags.empty? %> |
public/javascripts/application.js
@@ -863,3 +863,21 @@ function facet_options_toggle(id, url) { | @@ -863,3 +863,21 @@ function facet_options_toggle(id, url) { | ||
863 | } | 863 | } |
864 | }); | 864 | }); |
865 | } | 865 | } |
866 | + | ||
867 | +jQuery(function($) { | ||
868 | + $('.colorbox').live('click', function() { | ||
869 | + $.fn.colorbox({ | ||
870 | + href:$(this).attr('href'), | ||
871 | + maxWidth: '500', | ||
872 | + maxHeight: '550', | ||
873 | + open:true | ||
874 | + }); | ||
875 | + return false; | ||
876 | + }); | ||
877 | + | ||
878 | + $('.colorbox-close').live('click', function() { | ||
879 | + $.colorbox.close(); | ||
880 | + return false; | ||
881 | + }); | ||
882 | + | ||
883 | +}); |
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class ColorboxHelperTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + include ColorboxHelper | ||
6 | + | ||
7 | + should 'provide the needed files' do | ||
8 | + assert File.exists?(File.join(RAILS_ROOT, 'public', 'stylesheets', 'colorbox.css')), 'colorbox.css expected to be in public/stylesheets, but not found' | ||
9 | + assert File.exists?(File.join(RAILS_ROOT, 'public', 'javascripts', 'colorbox.js')), 'colorbox.js expected to be in public/javascripts, but not found' | ||
10 | + end | ||
11 | + | ||
12 | + should 'provide link to close colorbox' do | ||
13 | + expects(:button).with(:close, 'text', '#', has_entries({ :class => 'colorbox-close', :id => 'my-id' })).returns('[close-colorbox]') | ||
14 | + | ||
15 | + assert_equal '[close-colorbox]', colorbox_close_button('text', :id => 'my-id') | ||
16 | + end | ||
17 | + | ||
18 | + should 'merge existing :class option in colorbox_close_button' do | ||
19 | + expects(:button).with(:close, 'text', '#', has_entries({ :class => 'colorbox-close my-class', :id => 'my-id' })).returns('[close-colorbox]') | ||
20 | + | ||
21 | + assert_equal '[close-colorbox]', colorbox_close_button('text', :class => 'my-class', :id => 'my-id' ) | ||
22 | + end | ||
23 | + | ||
24 | + should 'provide colorbox_button' do | ||
25 | + expects(:button).with('type', 'label', { :action => 'popup'}, has_entries({ :class => 'colorbox' })).returns('[button]') | ||
26 | + | ||
27 | + assert_equal '[button]', colorbox_button('type', 'label', { :action => 'popup'}) | ||
28 | + end | ||
29 | + | ||
30 | +end |