| Module | MediaHelper |
| In: |
app/helpers/media_helper.rb
|
# File app/helpers/media_helper.rb, line 176
176: def audio_for object, options = {}
177: audio = object.respond_to?(:audio) ? object.audio : object
178: options = { :title => '<h2> Audio </h2>' }.merge(options)
179: unless audio.empty?
180: result = options[:title] + "\n"
181: result << "<ul>\n"
182: audio.each do |sound|
183: name = sound.primary_names
184: result << "\t<li>" + link_for( sound, :name => name ) + "<br/>\n"
185: result << "\t" + audio_player_for( sound ) + "</li>\n"
186: end
187: result << "</ul>\n"
188: else
189: return nil
190: end
191: result
192: end
This function is essentially a wrapper for embed_quicktime_player, its main function is to set the height of the player to show the controls and add alt & title information.
# File app/helpers/media_helper.rb, line 196
196: def audio_player_for audio, options = {}
197: options = { :height => 20,
198: :alt => audio.description,
199: :title => audio.description
200: }.merge(options)
201:
202: embed_quicktime_player audio, options
203: end
Create photo notes which can be edited by clicking/draging - using javascript (see PhotoNotes.v1.js & PhotoNotes.v1.css).
# File app/helpers/media_helper.rb, line 91
91: def editable_image_notes_for image, options = {}
92: function = "addEvent(window, 'load', function() {
93:
94: // create the PhotoNote container
95: var container = document.getElementById('PhotoContainer');
96: if (!container) return false;
97: notes = new PhotoNoteContainer(container);
98:
99: // hack the width of the div into shape because divs naturally expand horizontally
100: var image = document.getElementById('fn-image');
101: container.style.width = image.offsetWidth + 'px';
102:
103: // get the dimensions of the container div
104: var container_height = container.offsetHeight / 100;
105: var container_width = container.offsetWidth / 100;\n"
106:
107: # create the notes
108: image.image_notes.each do |note|
109: # if the image_note has dimensions for a box create a photo note
110: if note.left && note.top && note.width && note.height
111: function += "var size = new PhotoNoteRect(" + note.left.to_i.to_s + " * container_width, " + note.top.to_i.to_s + " * container_height, " + note.width.to_i.to_s + " * container_width, " + note.height.to_i.to_s + " * container_height);
112: var note = new PhotoNote('" + note.subject.primary_names + "',1, size);
113:
114: // implement the save/delete functions
115: note.onsave = notes.SaveNoteToDB(" + image.id.to_s + ", " + note.subject_id.to_s + ", '" + note.subject_type.to_s + "');
116: note.ondelete = notes.DeleteNoteFromDB(" + image.id.to_s + ", " + note.subject_id.to_s + ", '" + note.subject_type.to_s + "');
117:
118: // add it to the container
119: notes.AddNote(note);"
120: end
121: end
122:
123: function += "});"
124: javascript_tag function
125: end
Embeds a quicktime player as an object/embed. The first argument is either a string which contains the location of the media file or an object which has a file_column field named "url".
# File app/helpers/media_helper.rb, line 218
218: def embed_quicktime_player src, options = {}
219: options = { :controller => 'true',
220: :autoplay => 'false',
221: :loop => 'false'
222: }.merge(options)
223: options.each do |option|
224: unless option.is_a?(String)
225: options[option[0]] = option[1].to_s # convert all values to strings for use in embed_code (particularly booleans)
226: end
227: end
228:
229: unless src.is_a?(String)
230: src = url_for_file_column src, "url"
231: end
232:
233: width = options[:width]? 'width="' + options[:width] + '" ' : ''
234: height = options[:height]? 'height="' + options[:height] + '" ' : ''
235: alt = options[:alt]? 'alt="' + options[:alt] + '" ' : ''
236: title = options[:title]? 'title="' + options[:title] + '" ' : ''
237:
238: embed_code = '<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"' + height + width + alt + title + 'codebase="http://www.apple.com/qtactivex/qtplugin.cab">
239: <param name="src" value="'+ src + '">
240: <param name="autoplay" value="'+ options[:autoplay] + '">
241: <param name="controller" value="'+ options[:controller] + '">
242: <param name="loop" value="'+ options[:loop] + '">
243: <EMBED src="' + src + '" autoplay="' + options[:autoplay] + '"' + height + width + alt + title + 'controller="'+ options[:controller] + '" loop="'+ options[:loop] + '" pluginspage="http://www.apple.com/quicktime/download/">
244: </EMBED>
245: </OBJECT>'
246: end
Create CSS only image notes (see photos.css for style definitions). There is a similar function in lightbox_plus.js to produce these notes using javascript for lightboxed images.
# File app/helpers/media_helper.rb, line 76
76: def image_notes_for image, options = {}
77: result = ""
78: image.image_notes.each do |note|
79: if note.left && note.top && note.width && note.height
80: result << '<div class="box" id="' + note.subject_type + '_' + note.subject_id.to_s + '" style="position: absolute; left: ' + note.left.to_s + '%; top: '+ note.top.to_s + '%; width : ' + note.width.to_s + '%; height: ' + note.height.to_s + '%;">
81: <div class="note" style ="left: 0%; top: 100%; min-width: 100%;">' +
82: '<p>' + note.subject.primary_names + '</p>' +
83: '</div>
84: </div>'
85: end
86: end
87: result
88: end
object may either be an object which has many images, or it may be an array of images already
# File app/helpers/media_helper.rb, line 128
128: def images_for object, options = {}
129: images = object.respond_to?(:images) ? object.images : object
130: options = { :title => '<h2> Photos </h2>' }.merge(options)
131: unless images.empty?
132: result = options[:title] + "\n"
133: options.delete :title
134:
135: images.each do |image|
136: result << "\t" + thumbnail_for(image, options) + "\n"
137: end
138: else
139: return nil
140: end
141: result
142: end
Displays thumbnails/players/links for all media (images, sounds, videos). Most commonly used in the ‘show’ view for entities which have media associated.
# File app/helpers/media_helper.rb, line 5
5: def media_for thing, options = {}
6: options = { :image_options => {} }.merge options
7: unless options[:images]
8: Image.with_scope(self.controller.accessible(:images)) do
9: options[:images] = thing.images.find(:all) rescue []
10: end
11: end
12:
13: unless options[:audio]
14: Audio.with_scope(self.controller.accessible(:audio)) do
15: options[:audio] = thing.audio.find(:all) rescue []
16: end
17: end
18:
19: unless options[:videos]
20: Video.with_scope(self.controller.accessible(:videos)) do
21: options[:videos] = thing.videos.find(:all) rescue []
22: end
23: end
24:
25: unless options[:images].empty? && options[:audio].empty? && options[:videos].empty?
26: result = ""
27: unless options[:images].empty?
28: result << images_for( options[:images], options[:image_options] )
29: end
30: unless options[:audio].empty?
31: result << audio_for( options[:audio] )
32: end
33: unless options[:videos].empty?
34: result << videos_for( options[:videos] )
35: end
36: else
37: return nil
38: end
39: result
40: end
Creates a thumbnail for an Image object by default it will be linked, specify :link => false as an option to disable the link Any options or html_options which are valid for link_to should also work as expected for linked images.
# File app/helpers/media_helper.rb, line 44
44: def thumbnail_for image, options = {}, html_options = {}
45: return "" if image.nil?
46: options = { :link => true, :block_sorrow => true }.merge(options)
47: html_options = { :rel => 'lightbox1' }.merge(html_options)
48: alt = options[:alt]? options[:alt] : image.description
49: title = options[:title]? options[:title] : alt
50:
51: unless options[:block_sorrow] && image.sorrow == 1
52: image_tag = image_tag( url_for_image_column( image, "url", :name => 'thumb'), :id => image.id, :alt => alt, :title => title )
53: else
54: image_tag = image_tag( '/images/sorrow.png', :id => image.id, :alt => alt, :title => title )
55: html_options = html_options.merge(:image => url_for_image_column( image, "url", :name => 'display'))
56: end
57:
58: unless options[:link]
59: return image_tag
60: end
61:
62: # set 'name' to the image tage so that link_for will display the image instead of a text link
63: # this will clobber any name key in the options hash (which doesn't seem like a problem to me)
64: options = options.merge(:name => image_tag)
65:
66: # don't pass these options to link_for
67: options.delete :alt
68: options.delete :title
69: options.delete :link
70:
71: link_for image, options, html_options
72: end
# File app/helpers/media_helper.rb, line 144
144: def thumbnails_for images, options = {}
145: unless images.empty?
146: result = ""
147: images.each do |image|
148: result << "\t" + thumbnail_for(image) + "\n"
149: end
150: else
151: return nil
152: end
153: result
154: end
This function is essentially a wrapper for embed_quicktime_player, its main function is to set the size of the player and add alt & title information.
# File app/helpers/media_helper.rb, line 207
207: def video_player_for video, options = {}
208: options = { :width => video.width,
209: :height => video.height ? video.height + 20 : nil,
210: :alt => video.description,
211: :title => video.description
212: }.merge(options)
213: embed_quicktime_player video, options
214: end
object may either be an object which has many videos, or it may be simply be an array of videos
# File app/helpers/media_helper.rb, line 159
159: def videos_for object, options = {}
160: videos = object.respond_to?(:videos) ? object.videos : object
161: options = { :title => '<h2> Videos </h2>' }.merge(options)
162: unless videos.empty?
163: result = options[:title] + "\n"
164: result << "<ul>\n"
165: videos.each do |video|
166: name = video.primary_names
167: result << "\t<li>" + link_for( video, :name => name ) + "</li>\n"
168: end
169: result << "</ul>\n"
170: else
171: return nil
172: end
173: result
174: end