splendeo-lightbox2_helpers 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +15 -0
- data/init.rb +1 -0
- data/lib/lightbox2_helpers/form_helpers.rb +55 -0
- data/lib/lightbox2_helpers/includes_helper.rb +20 -0
- data/lib/lightbox2_helpers/lightbox2_helpers.rb +15 -0
- data/lib/lightbox2_helpers.rb +34 -0
- data/public/images/lightbox2_helpers/bullet.gif +0 -0
- data/public/images/lightbox2_helpers/close.gif +0 -0
- data/public/images/lightbox2_helpers/closelabel.gif +0 -0
- data/public/images/lightbox2_helpers/download-icon.gif +0 -0
- data/public/images/lightbox2_helpers/loading.gif +0 -0
- data/public/images/lightbox2_helpers/nextlabel.gif +0 -0
- data/public/images/lightbox2_helpers/prevlabel.gif +0 -0
- data/public/javascripts/lightbox2_helpers/builder.js +136 -0
- data/public/javascripts/lightbox2_helpers/effects.js +1122 -0
- data/public/javascripts/lightbox2_helpers/lightbox.js +497 -0
- data/public/stylesheets/lightbox2_helpers/lightbox.css +27 -0
- metadata +70 -0
data/README
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/lightbox2_helpers.rb"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Various helpers available for use in your view
|
2
|
+
module Lightbox2Helpers::FormHelpers
|
3
|
+
|
4
|
+
# Similar to link_to, but tweaked so it uses lightbox2
|
5
|
+
#
|
6
|
+
# == Signatures
|
7
|
+
#
|
8
|
+
# link_to_lightbox2(name, options = {}, html_options = nil)
|
9
|
+
# link_to_libhgbox2(options = {}, html_options = nil) do
|
10
|
+
# # name
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# == Options
|
14
|
+
# link_to_lightbox uses link_to internally, so it should accept all parameters accepted by link_to. Plus two new ones.
|
15
|
+
#
|
16
|
+
# === :title
|
17
|
+
# Used as a caption on the picture's image. Can be left blank.
|
18
|
+
#
|
19
|
+
# <%= link_to_lightbox2 "Show the picture", "/images/picture.jpg", :title => "a nice picture" %>
|
20
|
+
#
|
21
|
+
# === :group
|
22
|
+
# It will be possible to iterate over links of the same "group" (with "next", "previous" links)
|
23
|
+
#
|
24
|
+
# <%= link_to_lightbox2 :group => "avatars" do %>
|
25
|
+
# This is also part of the link <%= image_tag "picture.jpg">
|
26
|
+
# <% end %>
|
27
|
+
#
|
28
|
+
# == Warning about html_options :rel
|
29
|
+
# * link_to_lightbox2 will override :rel if you use it as a parameter on html_options.
|
30
|
+
def link_to_lightbox2(*args, &block)
|
31
|
+
if block_given?
|
32
|
+
options = args.first || {}
|
33
|
+
html_options = args.second || {}
|
34
|
+
else
|
35
|
+
name = args.first
|
36
|
+
options = args.second || {}
|
37
|
+
html_options = args.third || {}
|
38
|
+
end
|
39
|
+
|
40
|
+
if options[:group]
|
41
|
+
html_options.merge {:rel => "lightbox[#{options[:group]}]"}
|
42
|
+
else
|
43
|
+
html_options.merge {:rel => "lightbox"}
|
44
|
+
end
|
45
|
+
|
46
|
+
html_options.merge {:title => options[:title]} if options[:title]
|
47
|
+
|
48
|
+
if block_given?
|
49
|
+
return concat(link_to(capture(&block), options, html_options))
|
50
|
+
else
|
51
|
+
return link_to (name, options, html_options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Lightbox2Helpers::IncludesHelper
|
2
|
+
# returns the selected lightbox2_helpers stylesheet (not an array)
|
3
|
+
def lightbox2_helpers_stylesheets()
|
4
|
+
"lightbox2_helpers/lightbox.css"
|
5
|
+
end
|
6
|
+
|
7
|
+
# returns an array of javascripts needed
|
8
|
+
def lightbox2_helpers_javascripts()
|
9
|
+
["lightbox2_helpers/lightbox2_helpers"]
|
10
|
+
end
|
11
|
+
|
12
|
+
# returns html necessary to load javascript and css to make lightbox2_helpers work
|
13
|
+
def lightbox2_helpers_includes(*args)
|
14
|
+
return "" if @lhs_already_included
|
15
|
+
@lhs_already_included=true
|
16
|
+
|
17
|
+
javascript_include_tag(*lightbox2_helpers_javascripts ) + "\n" +
|
18
|
+
stylesheet_link_tag(*lightbox2_helpers_stylesheets ) + "\n"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lightbox2Helpers
|
2
|
+
VERSION = '0.5'
|
3
|
+
|
4
|
+
# Returns the default_options hash. These options are by default provided to every calendar_date_select control, unless otherwise overrided.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# # At the bottom of config/environment.rb:
|
8
|
+
# Lightbox2Helper.default_options.update(
|
9
|
+
# ... whatever options you want to inser here
|
10
|
+
# )
|
11
|
+
def self.default_options
|
12
|
+
@default_options ||= { }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "lightbox2_helpers/lightbox2_helpers.rb"
|
2
|
+
require "lightbox2_helpers/form_helpers.rb"
|
3
|
+
require "lightbox2_helpers/includes_helper.rb"
|
4
|
+
|
5
|
+
if Object.const_defined?(:Rails) && File.directory?(Rails.root.to_s + "/public")
|
6
|
+
ActionView::Helpers::FormHelper.send(:include, Lightbox2Helpers::FormHelpers)
|
7
|
+
ActionView::Base.send(:include, Lightbox2Helpers::FormHelpers)
|
8
|
+
ActionView::Base.send(:include, Lightbox2Helpers::IncludesHelper)
|
9
|
+
|
10
|
+
# egarcia: all this is adapted from calendar_date_select, so I'm not touching it
|
11
|
+
# Filthy backwards compatibility hooks... grumble
|
12
|
+
if ([Rails::VERSION::MAJOR, Rails::VERSION::MINOR] <=> [2, 2]) == -1
|
13
|
+
ActionView::Helpers::InstanceTag.class_eval do
|
14
|
+
def self.new_with_backwards_compatibility(object_name, method_name, template_object, object = nil)
|
15
|
+
new(object_name, method_name, template_object, nil, object)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
else
|
20
|
+
ActionView::Helpers::InstanceTag.class_eval do
|
21
|
+
class << self; alias new_with_backwards_compatibility new; end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# install files
|
26
|
+
unless File.exists?(RAILS_ROOT + '/public/javascripts/lightbox2_helpers/lightbox.js')
|
27
|
+
['/public', '/public/javascripts/lightbox2_helpers', '/public/stylesheets/lightbox2_helpers', '/public/images/lightbox2_helpers'].each do |dir|
|
28
|
+
source = File.dirname(__FILE__) + "/../#{dir}"
|
29
|
+
dest = RAILS_ROOT + dir
|
30
|
+
FileUtils.mkdir_p(dest)
|
31
|
+
FileUtils.cp(Dir.glob(source+'/*.*'), dest)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,136 @@
|
|
1
|
+
// script.aculo.us builder.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
|
2
|
+
|
3
|
+
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
4
|
+
//
|
5
|
+
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
6
|
+
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
7
|
+
|
8
|
+
var Builder = {
|
9
|
+
NODEMAP: {
|
10
|
+
AREA: 'map',
|
11
|
+
CAPTION: 'table',
|
12
|
+
COL: 'table',
|
13
|
+
COLGROUP: 'table',
|
14
|
+
LEGEND: 'fieldset',
|
15
|
+
OPTGROUP: 'select',
|
16
|
+
OPTION: 'select',
|
17
|
+
PARAM: 'object',
|
18
|
+
TBODY: 'table',
|
19
|
+
TD: 'table',
|
20
|
+
TFOOT: 'table',
|
21
|
+
TH: 'table',
|
22
|
+
THEAD: 'table',
|
23
|
+
TR: 'table'
|
24
|
+
},
|
25
|
+
// note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
|
26
|
+
// due to a Firefox bug
|
27
|
+
node: function(elementName) {
|
28
|
+
elementName = elementName.toUpperCase();
|
29
|
+
|
30
|
+
// try innerHTML approach
|
31
|
+
var parentTag = this.NODEMAP[elementName] || 'div';
|
32
|
+
var parentElement = document.createElement(parentTag);
|
33
|
+
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
|
34
|
+
parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
|
35
|
+
} catch(e) {}
|
36
|
+
var element = parentElement.firstChild || null;
|
37
|
+
|
38
|
+
// see if browser added wrapping tags
|
39
|
+
if(element && (element.tagName.toUpperCase() != elementName))
|
40
|
+
element = element.getElementsByTagName(elementName)[0];
|
41
|
+
|
42
|
+
// fallback to createElement approach
|
43
|
+
if(!element) element = document.createElement(elementName);
|
44
|
+
|
45
|
+
// abort if nothing could be created
|
46
|
+
if(!element) return;
|
47
|
+
|
48
|
+
// attributes (or text)
|
49
|
+
if(arguments[1])
|
50
|
+
if(this._isStringOrNumber(arguments[1]) ||
|
51
|
+
(arguments[1] instanceof Array) ||
|
52
|
+
arguments[1].tagName) {
|
53
|
+
this._children(element, arguments[1]);
|
54
|
+
} else {
|
55
|
+
var attrs = this._attributes(arguments[1]);
|
56
|
+
if(attrs.length) {
|
57
|
+
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
|
58
|
+
parentElement.innerHTML = "<" +elementName + " " +
|
59
|
+
attrs + "></" + elementName + ">";
|
60
|
+
} catch(e) {}
|
61
|
+
element = parentElement.firstChild || null;
|
62
|
+
// workaround firefox 1.0.X bug
|
63
|
+
if(!element) {
|
64
|
+
element = document.createElement(elementName);
|
65
|
+
for(attr in arguments[1])
|
66
|
+
element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
|
67
|
+
}
|
68
|
+
if(element.tagName.toUpperCase() != elementName)
|
69
|
+
element = parentElement.getElementsByTagName(elementName)[0];
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
// text, or array of children
|
74
|
+
if(arguments[2])
|
75
|
+
this._children(element, arguments[2]);
|
76
|
+
|
77
|
+
return element;
|
78
|
+
},
|
79
|
+
_text: function(text) {
|
80
|
+
return document.createTextNode(text);
|
81
|
+
},
|
82
|
+
|
83
|
+
ATTR_MAP: {
|
84
|
+
'className': 'class',
|
85
|
+
'htmlFor': 'for'
|
86
|
+
},
|
87
|
+
|
88
|
+
_attributes: function(attributes) {
|
89
|
+
var attrs = [];
|
90
|
+
for(attribute in attributes)
|
91
|
+
attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
|
92
|
+
'="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'"') + '"');
|
93
|
+
return attrs.join(" ");
|
94
|
+
},
|
95
|
+
_children: function(element, children) {
|
96
|
+
if(children.tagName) {
|
97
|
+
element.appendChild(children);
|
98
|
+
return;
|
99
|
+
}
|
100
|
+
if(typeof children=='object') { // array can hold nodes and text
|
101
|
+
children.flatten().each( function(e) {
|
102
|
+
if(typeof e=='object')
|
103
|
+
element.appendChild(e)
|
104
|
+
else
|
105
|
+
if(Builder._isStringOrNumber(e))
|
106
|
+
element.appendChild(Builder._text(e));
|
107
|
+
});
|
108
|
+
} else
|
109
|
+
if(Builder._isStringOrNumber(children))
|
110
|
+
element.appendChild(Builder._text(children));
|
111
|
+
},
|
112
|
+
_isStringOrNumber: function(param) {
|
113
|
+
return(typeof param=='string' || typeof param=='number');
|
114
|
+
},
|
115
|
+
build: function(html) {
|
116
|
+
var element = this.node('div');
|
117
|
+
$(element).update(html.strip());
|
118
|
+
return element.down();
|
119
|
+
},
|
120
|
+
dump: function(scope) {
|
121
|
+
if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
|
122
|
+
|
123
|
+
var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
|
124
|
+
"BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
|
125
|
+
"FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
|
126
|
+
"KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
|
127
|
+
"PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
|
128
|
+
"TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
|
129
|
+
|
130
|
+
tags.each( function(tag){
|
131
|
+
scope[tag] = function() {
|
132
|
+
return Builder.node.apply(Builder, [tag].concat($A(arguments)));
|
133
|
+
}
|
134
|
+
});
|
135
|
+
}
|
136
|
+
}
|