diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7c07b0e..64c9d88 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,6 +10,8 @@ module ApplicationHelper include ThickboxHelper + include ColorboxHelper + include BoxesHelper include FormsHelper diff --git a/app/helpers/colorbox_helper.rb b/app/helpers/colorbox_helper.rb new file mode 100644 index 0000000..7002f10 --- /dev/null +++ b/app/helpers/colorbox_helper.rb @@ -0,0 +1,21 @@ +module ColorboxHelper + + def colorbox_close_button(text, options = {}) + button(:close, text, '#', colorbox_options(options, :close)) + end + + def colorbox_button(type, label, url, options = {}) + button(type, label, url, colorbox_options(options)) + end + + # options must be an HTML options hash as passed to link_to etc. + # + # returns a new hash with colorbox class added. Keeps existing classes. + def colorbox_options(options, type=nil) + the_class = 'colorbox' + the_class += "-#{type.to_s}" unless type.nil? + the_class << " #{options[:class]}" if options.has_key?(:class) + options.merge(:class => the_class) + end + +end diff --git a/app/views/cms/select_article_type.rhtml b/app/views/cms/select_article_type.rhtml index 1673dbb..a23281d 100644 --- a/app/views/cms/select_article_type.rhtml +++ b/app/views/cms/select_article_type.rhtml @@ -13,4 +13,4 @@
-<%= lightbox_close_button(_('Cancel')) %> +<%= colorbox_close_button(_('Cancel')) %> diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml index 807ac94..1812d66 100644 --- a/app/views/cms/view.rhtml +++ b/app/views/cms/view.rhtml @@ -5,7 +5,7 @@ <% button_bar(:style => 'margin-bottom: 1em;') do %> <% parent_id = ((@article && @article.allow_children?) ? @article : nil) %> - <%= lightbox_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %> + <%= colorbox_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %> <%= button(:back, _('Back to control panel'), :controller => 'profile_editor', :action => "index") %> <% end %> diff --git a/app/views/content_viewer/_article_toolbar.rhtml b/app/views/content_viewer/_article_toolbar.rhtml index 433f3ba..e4eb602 100644 --- a/app/views/content_viewer/_article_toolbar.rhtml +++ b/app/views/content_viewer/_article_toolbar.rhtml @@ -33,7 +33,7 @@ :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)), :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }), :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> - <%= 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)))) %> + <%= 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)))) %> <% end %> <% if @page.accept_uploads? && @page.allow_create?(user) %> diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 7ba980a..d13e886 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -9,7 +9,7 @@
<% if !@page.tags.empty? %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 671708f..e8b9d41 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -863,3 +863,21 @@ function facet_options_toggle(id, url) { } }); } + +jQuery(function($) { + $('.colorbox').live('click', function() { + $.fn.colorbox({ + href:$(this).attr('href'), + maxWidth: '500', + maxHeight: '550', + open:true + }); + return false; + }); + + $('.colorbox-close').live('click', function() { + $.colorbox.close(); + return false; + }); + +}); diff --git a/test/unit/colorbox_helper_test.rb b/test/unit/colorbox_helper_test.rb new file mode 100644 index 0000000..dc480d5 --- /dev/null +++ b/test/unit/colorbox_helper_test.rb @@ -0,0 +1,30 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ColorboxHelperTest < ActiveSupport::TestCase + + include ColorboxHelper + + should 'provide the needed files' do + assert File.exists?(File.join(RAILS_ROOT, 'public', 'stylesheets', 'colorbox.css')), 'colorbox.css expected to be in public/stylesheets, but not found' + assert File.exists?(File.join(RAILS_ROOT, 'public', 'javascripts', 'colorbox.js')), 'colorbox.js expected to be in public/javascripts, but not found' + end + + should 'provide link to close colorbox' do + expects(:button).with(:close, 'text', '#', has_entries({ :class => 'colorbox-close', :id => 'my-id' })).returns('[close-colorbox]') + + assert_equal '[close-colorbox]', colorbox_close_button('text', :id => 'my-id') + end + + should 'merge existing :class option in colorbox_close_button' do + expects(:button).with(:close, 'text', '#', has_entries({ :class => 'colorbox-close my-class', :id => 'my-id' })).returns('[close-colorbox]') + + assert_equal '[close-colorbox]', colorbox_close_button('text', :class => 'my-class', :id => 'my-id' ) + end + + should 'provide colorbox_button' do + expects(:button).with('type', 'label', { :action => 'popup'}, has_entries({ :class => 'colorbox' })).returns('[button]') + + assert_equal '[button]', colorbox_button('type', 'label', { :action => 'popup'}) + end + +end -- libgit2 0.21.2