From e709ebbdee01968d32e8e725f2c0426491643c66 Mon Sep 17 00:00:00 2001 From: Caio SBA Date: Mon, 14 Feb 2011 06:18:31 -0300 Subject: [PATCH] Turning article images zoomable --- app/helpers/application_helper.rb | 19 +++++++++++++++++++ app/models/environment.rb | 3 ++- app/views/content_viewer/view_page.rhtml | 1 + features/clickable_images.feature | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ features/step_definitions/noosfero_steps.rb | 23 +++++++++++++++++++++++ features/step_definitions/selenium_steps.rb | 5 +++++ public/images/fancybox/blank.gif | Bin 0 -> 43 bytes public/images/fancybox/fancy_close.png | Bin 0 -> 1517 bytes public/images/fancybox/fancy_loading.png | Bin 0 -> 10195 bytes public/images/fancybox/fancy_nav_left.png | Bin 0 -> 1446 bytes public/images/fancybox/fancy_nav_right.png | Bin 0 -> 1454 bytes public/images/fancybox/fancy_shadow_e.png | Bin 0 -> 107 bytes public/images/fancybox/fancy_shadow_n.png | Bin 0 -> 106 bytes public/images/fancybox/fancy_shadow_ne.png | Bin 0 -> 347 bytes public/images/fancybox/fancy_shadow_nw.png | Bin 0 -> 324 bytes public/images/fancybox/fancy_shadow_s.png | Bin 0 -> 111 bytes public/images/fancybox/fancy_shadow_se.png | Bin 0 -> 352 bytes public/images/fancybox/fancy_shadow_sw.png | Bin 0 -> 340 bytes public/images/fancybox/fancy_shadow_w.png | Bin 0 -> 103 bytes public/images/fancybox/fancy_title_left.png | Bin 0 -> 503 bytes public/images/fancybox/fancy_title_main.png | Bin 0 -> 96 bytes public/images/fancybox/fancy_title_over.png | Bin 0 -> 70 bytes public/images/fancybox/fancy_title_right.png | Bin 0 -> 506 bytes public/images/fancybox/fancybox-x.png | Bin 0 -> 203 bytes public/images/fancybox/fancybox-y.png | Bin 0 -> 176 bytes public/images/fancybox/fancybox.png | Bin 0 -> 15287 bytes public/images/zoom.png | Bin 0 -> 420 bytes public/javascripts/application.js | 6 ++++++ public/javascripts/jquery.fancybox-1.3.4.pack.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ public/stylesheets/application.css | 37 +++++++++++++++++++++++++++++++++++++ public/stylesheets/fancybox.css | 359 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/application_helper_test.rb | 17 +++++++++++++++++ 32 files changed, 565 insertions(+), 1 deletion(-) create mode 100644 features/clickable_images.feature create mode 100644 public/images/fancybox/blank.gif create mode 100644 public/images/fancybox/fancy_close.png create mode 100644 public/images/fancybox/fancy_loading.png create mode 100644 public/images/fancybox/fancy_nav_left.png create mode 100644 public/images/fancybox/fancy_nav_right.png create mode 100644 public/images/fancybox/fancy_shadow_e.png create mode 100644 public/images/fancybox/fancy_shadow_n.png create mode 100644 public/images/fancybox/fancy_shadow_ne.png create mode 100644 public/images/fancybox/fancy_shadow_nw.png create mode 100644 public/images/fancybox/fancy_shadow_s.png create mode 100644 public/images/fancybox/fancy_shadow_se.png create mode 100644 public/images/fancybox/fancy_shadow_sw.png create mode 100644 public/images/fancybox/fancy_shadow_w.png create mode 100644 public/images/fancybox/fancy_title_left.png create mode 100644 public/images/fancybox/fancy_title_main.png create mode 100644 public/images/fancybox/fancy_title_over.png create mode 100644 public/images/fancybox/fancy_title_right.png create mode 100644 public/images/fancybox/fancybox-x.png create mode 100644 public/images/fancybox/fancybox-y.png create mode 100644 public/images/fancybox/fancybox.png create mode 100644 public/images/zoom.png create mode 100644 public/javascripts/jquery.fancybox-1.3.4.pack.js create mode 100644 public/stylesheets/fancybox.css diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5525dda..df6899d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1190,4 +1190,23 @@ module ApplicationHelper task.information[:message] % values end + def add_zoom_to_images + if environment.enabled?(:show_zoom_button_on_article_images) + stylesheet_link_tag('fancybox') + + javascript_include_tag('jquery.fancybox-1.3.4.pack') + + javascript_tag("jQuery(function($) { + $('#article .article-body img').each( function(index) { + var original = original_image_dimensions($(this).attr('src')); + if ($(this).width() < original['width'] || $(this).height() < original['height']) { + $(this).wrap('
'); + $(this).parent('.zoomable-image').attr('style', $(this).attr('style')); + $(this).attr('style', ''); + $(this).after(\'%s'); + } + }); + $('.zoomify-image').fancybox(); + });" % _('Zoom in')) + end + end + end diff --git a/app/models/environment.rb b/app/models/environment.rb index 365cff8..eef1e14 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -108,7 +108,8 @@ class Environment < ActiveRecord::Base 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"), 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'), 'show_balloon_with_profile_links_when_clicked' => _('Show a balloon with profile links when a profile image is clicked'), - 'xmpp_chat' => _('XMPP/Jabber based chat') + 'xmpp_chat' => _('XMPP/Jabber based chat'), + 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images') } end diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 2a8bc2d..78a60b0 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -135,3 +135,4 @@
+<%= add_zoom_to_images %> diff --git a/features/clickable_images.feature b/features/clickable_images.feature new file mode 100644 index 0000000..b508b35 --- /dev/null +++ b/features/clickable_images.feature @@ -0,0 +1,50 @@ +Feature: clickable images + As a visitor + I want to zoom in article images + + Background: + Given feature "show_zoom_button_on_article_images" is enabled on environment + And the following users + | login | + | booking | + + @selenium + Scenario: show link if image is scaled + Given the following article with image + | owner | name | image | dimensions | + | booking | small | rails.png | 20x20 | + When I go to /booking/small + Then I should see "Zoom in" + + @selenium + Scenario: not show link if image is not scaled + Given the following article with image + | owner | name | image | dimensions | + | booking | real | rails.png | 50x64 | + When I go to /booking/real + Then I should not see "Zoom in" + + @selenium + Scenario: not show link if image does not have dimensions set + Given the following article with image + | owner | name | image | + | booking | not set | rails.png | + When I go to /booking/not-set + Then I should not see "Zoom in" + + @selenium + Scenario: copy style from image + Given the following article with image + | owner | name | image | style | dimensions | + | booking | with style | rails.png | float: right | 25x32 | + When I go to /booking/with-style + Then "zoomable-image" should be right aligned + + @selenium + Scenario: zoom image + Given the following article with image + | owner | name | image | dimensions | + | booking | zoom | rails.png | 25x32 | + When I go to /booking/zoom + And I follow "Zoom in" + Then the "#fancybox-wrap" should be visible diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 7356c7f..8124bf2 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -83,6 +83,29 @@ Given /^the following files$/ do |table| end end +Given /^the following articles? with images?$/ do |table| + table.hashes.each do |item| + owner = Profile[item[:owner]] + file = item[:image] + img = { :src => "/images/#{file}", :alt => file } + img[:width] = item[:dimensions].split('x')[0] if item[:dimensions] + img[:height] = item[:dimensions].split('x')[1] if item[:dimensions] + img[:style] = item[:style] if item[:style] + img_tag = " owner, :name => item[:name], :body => img_tag) + if item[:parent] + article.parent = Article.find_by_slug(item[:parent]) + end + article.save! + if item[:homepage] + owner.home_page = article + owner.save! + end + end +end + Given /^the following products?$/ do |table| table.hashes.each do |item| data = item.dup diff --git a/features/step_definitions/selenium_steps.rb b/features/step_definitions/selenium_steps.rb index 30accda..62eb790 100644 --- a/features/step_definitions/selenium_steps.rb +++ b/features/step_definitions/selenium_steps.rb @@ -80,6 +80,11 @@ Then /^there should be ([1-9][0-9]*) "([^\"]*)" within "([^\"]*)"$/ do |number, response.selenium.get_xpath_count("//*[contains(@class,'#{parent_class}')]//*[contains(@class,'#{child_class}')]").to_i.should be(number.to_i) end +Then /^"([^\"]*)" should be (left|right) aligned$/ do |element_class, align| + # Using xpath is the only way to count + response.selenium.get_xpath_count("//*[contains(@class,'#{element_class}') and contains(@style,'float: #{align}')]").to_i.should be(1) +end + #### Noosfero specific steps #### Then /^the select for category "([^\"]*)" should be visible$/ do |name| diff --git a/public/images/fancybox/blank.gif b/public/images/fancybox/blank.gif new file mode 100644 index 0000000..35d42e8 Binary files /dev/null and b/public/images/fancybox/blank.gif differ diff --git a/public/images/fancybox/fancy_close.png b/public/images/fancybox/fancy_close.png new file mode 100644 index 0000000..0703530 Binary files /dev/null and b/public/images/fancybox/fancy_close.png differ diff --git a/public/images/fancybox/fancy_loading.png b/public/images/fancybox/fancy_loading.png new file mode 100644 index 0000000..2503017 Binary files /dev/null and b/public/images/fancybox/fancy_loading.png differ diff --git a/public/images/fancybox/fancy_nav_left.png b/public/images/fancybox/fancy_nav_left.png new file mode 100644 index 0000000..ebaa6a4 Binary files /dev/null and b/public/images/fancybox/fancy_nav_left.png differ diff --git a/public/images/fancybox/fancy_nav_right.png b/public/images/fancybox/fancy_nav_right.png new file mode 100644 index 0000000..873294e Binary files /dev/null and b/public/images/fancybox/fancy_nav_right.png differ diff --git a/public/images/fancybox/fancy_shadow_e.png b/public/images/fancybox/fancy_shadow_e.png new file mode 100644 index 0000000..2eda089 Binary files /dev/null and b/public/images/fancybox/fancy_shadow_e.png differ diff --git a/public/images/fancybox/fancy_shadow_n.png b/public/images/fancybox/fancy_shadow_n.png new file mode 100644 index 0000000..69aa10e Binary files /dev/null and b/public/images/fancybox/fancy_shadow_n.png differ diff --git a/public/images/fancybox/fancy_shadow_ne.png b/public/images/fancybox/fancy_shadow_ne.png new file mode 100644 index 0000000..79f6980 Binary files /dev/null and b/public/images/fancybox/fancy_shadow_ne.png differ diff --git a/public/images/fancybox/fancy_shadow_nw.png b/public/images/fancybox/fancy_shadow_nw.png new file mode 100644 index 0000000..7182cd9 Binary files /dev/null and b/public/images/fancybox/fancy_shadow_nw.png differ diff --git a/public/images/fancybox/fancy_shadow_s.png b/public/images/fancybox/fancy_shadow_s.png new file mode 100644 index 0000000..d8858bf Binary files /dev/null and b/public/images/fancybox/fancy_shadow_s.png differ diff --git a/public/images/fancybox/fancy_shadow_se.png b/public/images/fancybox/fancy_shadow_se.png new file mode 100644 index 0000000..541e3ff Binary files /dev/null and b/public/images/fancybox/fancy_shadow_se.png differ diff --git a/public/images/fancybox/fancy_shadow_sw.png b/public/images/fancybox/fancy_shadow_sw.png new file mode 100644 index 0000000..b451689 Binary files /dev/null and b/public/images/fancybox/fancy_shadow_sw.png differ diff --git a/public/images/fancybox/fancy_shadow_w.png b/public/images/fancybox/fancy_shadow_w.png new file mode 100644 index 0000000..8a4e4a8 Binary files /dev/null and b/public/images/fancybox/fancy_shadow_w.png differ diff --git a/public/images/fancybox/fancy_title_left.png b/public/images/fancybox/fancy_title_left.png new file mode 100644 index 0000000..6049223 Binary files /dev/null and b/public/images/fancybox/fancy_title_left.png differ diff --git a/public/images/fancybox/fancy_title_main.png b/public/images/fancybox/fancy_title_main.png new file mode 100644 index 0000000..8044271 Binary files /dev/null and b/public/images/fancybox/fancy_title_main.png differ diff --git a/public/images/fancybox/fancy_title_over.png b/public/images/fancybox/fancy_title_over.png new file mode 100644 index 0000000..d9f458f Binary files /dev/null and b/public/images/fancybox/fancy_title_over.png differ diff --git a/public/images/fancybox/fancy_title_right.png b/public/images/fancybox/fancy_title_right.png new file mode 100644 index 0000000..e36d9db Binary files /dev/null and b/public/images/fancybox/fancy_title_right.png differ diff --git a/public/images/fancybox/fancybox-x.png b/public/images/fancybox/fancybox-x.png new file mode 100644 index 0000000..c2130f8 Binary files /dev/null and b/public/images/fancybox/fancybox-x.png differ diff --git a/public/images/fancybox/fancybox-y.png b/public/images/fancybox/fancybox-y.png new file mode 100644 index 0000000..7ef399b Binary files /dev/null and b/public/images/fancybox/fancybox-y.png differ diff --git a/public/images/fancybox/fancybox.png b/public/images/fancybox/fancybox.png new file mode 100644 index 0000000..65e14f6 Binary files /dev/null and b/public/images/fancybox/fancybox.png differ diff --git a/public/images/zoom.png b/public/images/zoom.png new file mode 100644 index 0000000..750e6bd Binary files /dev/null and b/public/images/zoom.png differ diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 8e8c537..7369c39 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -667,3 +667,9 @@ function add_comment_reply_form(button, comment_id) { } return f; } + +function original_image_dimensions(src) { + var img = new Image(); + img.src = src; + return { 'width' : img.width, 'height' : img.height }; +} diff --git a/public/javascripts/jquery.fancybox-1.3.4.pack.js b/public/javascripts/jquery.fancybox-1.3.4.pack.js new file mode 100644 index 0000000..c41676c --- /dev/null +++ b/public/javascripts/jquery.fancybox-1.3.4.pack.js @@ -0,0 +1,46 @@ +/* + * FancyBox - jQuery Plugin + * Simple and fancy lightbox alternative + * + * Examples and documentation at: http://fancybox.net + * + * Copyright (c) 2008 - 2010 Janis Skarnelis + * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. + * + * Version: 1.3.4 (11/11/2010) + * Requires: jQuery v1.3+ + * + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + */ + +;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("
")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('

The requested content cannot be loaded.
Please try again later.

'); +F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)|| +c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick= +false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('
').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel", +function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='';P="";b.each(e.swf,function(x,H){C+='';P+=" "+x+'="'+H+'"'});C+='";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win== +"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('
');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor, +opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length? +d.titlePosition=="float"?'
'+s+'
':'
'+s+"
":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding}); +y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height== +i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents()); +f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode== +37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto"); +s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('').appendTo(j); +f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c); +j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type== +"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"), +10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)}; +b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k= +0,C=a.length;ko.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+ +1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h= +true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1; +b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5- +d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('
'),t=b('
'),u=b('
'),f=b('
'));D=b('
').append('
').appendTo(f); +D.append(j=b('
'),E=b(''),n=b('
'),z=b(''),A=b(''));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()}); +b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('').prependTo(D)}}}; +b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing", +easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 9b31e6c..47b2e48 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1010,6 +1010,43 @@ code input { display: none; } +.zoomable-image { + position: relative; + display: inline-block; +} + +/* IE 7 hack to simulate inline-block */ +.msie7 .zoomable-image { + zoom: 1; + *display: inline; +} + +.zoomify-image { + position: absolute; + left: 0; + top: 0; + display: block; + width: 100%; + height: 16px; + text-align: right; + background: transparent url(/images/black-alpha-pixel.png); + border-bottom: 1px solid #333; +} + +#article .zoomify-image { + text-decoration: none; + color: #fff; +} + +.zoomify-image span { + font-size: 10px; + line-height: 16px; + padding-right: 16px; + border-bottom: 1px solid #eee; + display: block; + background: transparent url(/images/zoom.png) right center no-repeat; +} + /* * * Comments * * */ .comments { } diff --git a/public/stylesheets/fancybox.css b/public/stylesheets/fancybox.css new file mode 100644 index 0000000..a29f95b --- /dev/null +++ b/public/stylesheets/fancybox.css @@ -0,0 +1,359 @@ +/* + * FancyBox - jQuery Plugin + * Simple and fancy lightbox alternative + * + * Examples and documentation at: http://fancybox.net + * + * Copyright (c) 2008 - 2010 Janis Skarnelis + * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. + * + * Version: 1.3.4 (11/11/2010) + * Requires: jQuery v1.3+ + * + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + */ + +#fancybox-loading { + position: fixed; + top: 50%; + left: 50%; + width: 40px; + height: 40px; + margin-top: -20px; + margin-left: -20px; + cursor: pointer; + overflow: hidden; + z-index: 1104; + display: none; +} + +#fancybox-loading div { + position: absolute; + top: 0; + left: 0; + width: 40px; + height: 480px; + background-image: url('../images/fancybox/fancybox.png'); +} + +#fancybox-overlay { + position: absolute; + top: 0; + left: 0; + width: 100%; + z-index: 1100; + display: none; +} + +#fancybox-tmp { + padding: 0; + margin: 0; + border: 0; + overflow: auto; + display: none; +} + +#fancybox-wrap { + position: absolute; + top: 0; + left: 0; + padding: 20px; + z-index: 1101; + outline: none; + display: none; +} + +#fancybox-outer { + position: relative; + width: 100%; + height: 100%; + background: #fff; +} + +#fancybox-content { + width: 0; + height: 0; + padding: 0; + outline: none; + position: relative; + overflow: hidden; + z-index: 1102; + border: 0px solid #fff; +} + +#fancybox-hide-sel-frame { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: transparent; + z-index: 1101; +} + +#fancybox-close { + position: absolute; + top: -15px; + right: -15px; + width: 30px; + height: 30px; + background: transparent url('../images/fancybox/fancybox.png') -40px 0px; + cursor: pointer; + z-index: 1103; + display: none; +} + +#fancybox-error { + color: #444; + font: normal 12px/20px Arial; + padding: 14px; + margin: 0; +} + +#fancybox-img { + width: 100%; + height: 100%; + padding: 0; + margin: 0; + border: none; + outline: none; + line-height: 0; + vertical-align: top; +} + +#fancybox-frame { + width: 100%; + height: 100%; + border: none; + display: block; +} + +#fancybox-left, #fancybox-right { + position: absolute; + bottom: 0px; + height: 100%; + width: 35%; + cursor: pointer; + outline: none; + background: transparent url('../images/fancybox/blank.gif'); + z-index: 1102; + display: none; +} + +#fancybox-left { + left: 0px; +} + +#fancybox-right { + right: 0px; +} + +#fancybox-left-ico, #fancybox-right-ico { + position: absolute; + top: 50%; + left: -9999px; + width: 30px; + height: 30px; + margin-top: -15px; + cursor: pointer; + z-index: 1102; + display: block; +} + +#fancybox-left-ico { + background-image: url('../images/fancybox/fancybox.png'); + background-position: -40px -30px; +} + +#fancybox-right-ico { + background-image: url('../images/fancybox/fancybox.png'); + background-position: -40px -60px; +} + +#fancybox-left:hover, #fancybox-right:hover { + visibility: visible; /* IE6 */ +} + +#fancybox-left:hover span { + left: 20px; +} + +#fancybox-right:hover span { + left: auto; + right: 20px; +} + +.fancybox-bg { + position: absolute; + padding: 0; + margin: 0; + border: 0; + width: 20px; + height: 20px; + z-index: 1001; +} + +#fancybox-bg-n { + top: -20px; + left: 0; + width: 100%; + background-image: url('../images/fancybox/fancybox-x.png'); +} + +#fancybox-bg-ne { + top: -20px; + right: -20px; + background-image: url('../images/fancybox/fancybox.png'); + background-position: -40px -162px; +} + +#fancybox-bg-e { + top: 0; + right: -20px; + height: 100%; + background-image: url('../images/fancybox/fancybox-y.png'); + background-position: -20px 0px; +} + +#fancybox-bg-se { + bottom: -20px; + right: -20px; + background-image: url('../images/fancybox/fancybox.png'); + background-position: -40px -182px; +} + +#fancybox-bg-s { + bottom: -20px; + left: 0; + width: 100%; + background-image: url('../images/fancybox/fancybox-x.png'); + background-position: 0px -20px; +} + +#fancybox-bg-sw { + bottom: -20px; + left: -20px; + background-image: url('../images/fancybox/fancybox.png'); + background-position: -40px -142px; +} + +#fancybox-bg-w { + top: 0; + left: -20px; + height: 100%; + background-image: url('../images/fancybox/fancybox-y.png'); +} + +#fancybox-bg-nw { + top: -20px; + left: -20px; + background-image: url('../images/fancybox/fancybox.png'); + background-position: -40px -122px; +} + +#fancybox-title { + font-family: Helvetica; + font-size: 12px; + z-index: 1102; +} + +.fancybox-title-inside { + padding-bottom: 10px; + text-align: center; + color: #333; + background: #fff; + position: relative; +} + +.fancybox-title-outside { + padding-top: 10px; + color: #fff; +} + +.fancybox-title-over { + position: absolute; + bottom: 0; + left: 0; + color: #FFF; + text-align: left; +} + +#fancybox-title-over { + padding: 10px; + background-image: url('../images/fancybox/fancy_title_over.png'); + display: block; +} + +.fancybox-title-float { + position: absolute; + left: 0; + bottom: -20px; + height: 32px; +} + +#fancybox-title-float-wrap { + border: none; + border-collapse: collapse; + width: auto; +} + +#fancybox-title-float-wrap td { + border: none; + white-space: nowrap; +} + +#fancybox-title-float-left { + padding: 0 0 0 15px; + background: url('../images/fancybox/fancybox.png') -40px -90px no-repeat; +} + +#fancybox-title-float-main { + color: #FFF; + line-height: 29px; + font-weight: bold; + padding: 0 0 3px 0; + background: url('../images/fancybox/fancybox-x.png') 0px -40px; +} + +#fancybox-title-float-right { + padding: 0 0 0 15px; + background: url('../images/fancybox/fancybox.png') -55px -90px no-repeat; +} + +/* IE6 */ + +.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_close.png', sizingMethod='scale'); } + +.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_nav_left.png', sizingMethod='scale'); } +.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_nav_right.png', sizingMethod='scale'); } + +.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_title_over.png', sizingMethod='scale'); zoom: 1; } +.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_title_left.png', sizingMethod='scale'); } +.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_title_main.png', sizingMethod='scale'); } +.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_title_right.png', sizingMethod='scale'); } + +.fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame { + height: expression(this.parentNode.clientHeight + "px"); +} + +#fancybox-loading.fancybox-ie6 { + position: absolute; margin-top: 0; + top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'); +} + +#fancybox-loading.fancybox-ie6 div { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_loading.png', sizingMethod='scale'); } + +/* IE6, IE7, IE8 */ + +.fancybox-ie .fancybox-bg { background: transparent !important; } + +.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_n.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_ne.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_e.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_se.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_s.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_sw.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_w.png', sizingMethod='scale'); } +.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/fancybox/fancy_shadow_nw.png', sizingMethod='scale'); } diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 2ba8945..58452a7 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -593,6 +593,20 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_match person.name, task_information(task) end + should 'return nil when :show_zoom_button_on_article_images is not enabled in environment' do + env = Environment.default + env.stubs(:enabled?).with(:show_zoom_button_on_article_images).returns(false) + stubs(:environment).returns(env) + assert_nil add_zoom_to_images + end + + should 'return code when :show_zoom_button_on_article_images is enabled in environment' do + env = Environment.default + env.stubs(:enabled?).with(:show_zoom_button_on_article_images).returns(true) + stubs(:environment).returns(env) + assert_not_nil add_zoom_to_images + end + protected def url_for(args = {}) @@ -604,6 +618,9 @@ class ApplicationHelperTest < Test::Unit::TestCase def javascript_tag(any) '' end + def javascript_include_tag(any) + '' + end def link_to(label, action, options = {}) label end -- libgit2 0.21.2