-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added first version of the tooltip widget
- added system to copy default images and javascripts on plugin installation git-svn-id: https://rails-widgets.googlecode.com/svn/trunk@30 dbc01b36-f746-0410-8b88-c76c4e1ff24b
- Loading branch information
paolo
committed
Oct 13, 2007
1 parent
9df0d54
commit 5cd9931
Showing
9 changed files
with
155 additions
and
21 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
# Install hook code here | ||
def copy_image(name) | ||
def copy(file_name, from_dir, to_dir) | ||
from = File.expand_path(File.join(from_dir,file_name)) | ||
to = File.expand_path(File.join(to_dir, file_name)) | ||
puts "copy #{from} to #{to}" | ||
end | ||
|
||
def copy_image(file_name) | ||
plugin_images = File.join(File.dirname(__FILE__), 'images') | ||
app_images = File.join(RAILS_ROOT, 'public/images/widgets') | ||
from = File.expand_path(File.join(plugin_images,name)) | ||
to = File.expand_path(File.join(app_images,name)) | ||
puts "copy #{from} to #{to}" | ||
copy file_name, plugin_images, app_images | ||
end | ||
|
||
copy_image 'tooltip_arrow.gif' | ||
def copy_javascript(file_name) | ||
plugin_javascripts = File.join(File.dirname(__FILE__), 'javascript') | ||
app_javascripts = File.join(RAILS_ROOT, 'public/javascript/widgets') | ||
copy file_name, plugin_javascripts, app_javascripts | ||
end | ||
|
||
copy_image 'tooltip_arrow.gif' | ||
copy_image 'tooltip_image.gif' | ||
copy_javascript 'tooltip.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// tooltip widget | ||
function toggleTooltip(event, element) { | ||
var __x = Event.pointerX(event); | ||
var __y = Event.pointerY(event); | ||
//alert(__x+","+__y); | ||
element.style.top = __y + 5; | ||
element.style.left = __x - 40; | ||
element.toggle(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ActionView | ||
module Helpers | ||
module AssetTagHelper | ||
def javascript_include_tag_with_widgets(*sources) | ||
sources << 'widgets/tooltip' | ||
javascript_include_tag_without_widgets(*sources) | ||
end | ||
alias_method_chain :javascript_include_tag, :widgets | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<style lang="text/css"> | ||
.tooltip { | ||
position: absolute; | ||
background-image: url(/images/widgets/tooltip_arrow.gif); | ||
background-repeat: no-repeat; | ||
} | ||
|
||
.tooltip_content { | ||
padding: 20px; | ||
margin-top: 20px; | ||
background-color: fdf389; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Widgets | ||
module TooltipHelper | ||
include CssTemplate | ||
|
||
def tooltip(name=nil, opts={}, &proc) | ||
opts[:id] ||= rand(1000) | ||
name ||= image_tag('widgets/tooltip_image.gif', :border => 0) | ||
@_binding = proc.binding | ||
|
||
out default_css unless @_tooltip_css_done | ||
@_tooltip_css_done = true | ||
|
||
out tooltip_link(opts[:id],name) | ||
out javascript_tag(tooltip_link_function(opts[:id])) | ||
out render_tooltip(name, capture(&proc), opts) | ||
nil | ||
end | ||
|
||
def tooltip_link(id, name) | ||
link_to name, '#', :id => "#{id}_tooltip_link" | ||
end | ||
|
||
def tooltip_link_function(id) | ||
"$('#{id}_tooltip_link').observe('click', function(event){toggleTooltip(event, $('#{id}_tooltip'))});" | ||
end | ||
|
||
def close_tooltip_link(id, message) | ||
message ||= 'close' | ||
link_to_function message, "$('#{id}_tooltip').hide()" | ||
end | ||
|
||
def render_tooltip(name, content, opts) | ||
html = tag('div', {:id => "#{opts[:id]}_tooltip", :class=>'tooltip', :style => 'display:none'}, true) | ||
html << tag('div', {:id => "#{opts[:id]}_tooltip_content", :class=>'tooltip_content'},true) | ||
html << content | ||
html << '<small>' + close_tooltip_link(opts[:id], opts[:close_message]) + '</small>' | ||
html << '</div></div>' | ||
html | ||
end | ||
|
||
# return the name of the erb to parse for the default css generation | ||
def css_template_filename | ||
'tooltip.css.erb' | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require File.dirname(__FILE__) + '/test_helper' | ||
|
||
class TooltipHelperTest < Test::Unit::TestCase | ||
attr_accessor :params | ||
include ActionView::Helpers::TagHelper | ||
include ActionView::Helpers::TextHelper | ||
include ActionView::Helpers::UrlHelper | ||
include ActionView::Helpers::CaptureHelper | ||
include Widgets::TooltipHelper | ||
|
||
def setup | ||
@params = {} | ||
end | ||
|
||
def test_presence_of_instance_methods | ||
%w{tooltip}.each do |instance_method| | ||
assert respond_to?(instance_method), "#{instance_method} is not defined after including the helper" | ||
end | ||
end | ||
|
||
def test_tooltip_link_function | ||
expected = "$('one_tooltip_link').observe('click', function(event){toggleTooltip(event, $('one_tooltip'))});" | ||
assert_equal expected.strip, tooltip_link_function(:one); | ||
|
||
expected = "$('two_tooltip_link').observe('click', function(event){toggleTooltip(event, $('two_tooltip'))});" | ||
assert_equal expected.strip, tooltip_link_function(:two); | ||
end | ||
|
||
def test_close_tooltip_link | ||
expected = "<a href=\"#\" onclick=\"$('first_tooltip').hide(); return false;\">close</a>" | ||
assert_equal expected.strip, close_tooltip_link(:first); | ||
|
||
expected = "<a href=\"#\" onclick=\"$('second_tooltip').hide(); return false;\">chiudi</a>" | ||
assert_equal expected.strip, close_tooltip_link(:second, 'chiudi'); | ||
end | ||
|
||
end |