Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 4031 Bytes
1 | # QuietLightwindow |
2 | |
3 | module QuietLightwindow |
4 | mattr_accessor :default_options |
5 | |
6 | # Define the "uses_lightwindow" controller method. |
7 | # |
8 | module ClassMethods |
9 | def uses_lightwindow( filter_options = {} ) |
10 | |
11 | # Work in conjunction with Quiet Prototype if present, so that multiple |
12 | # quiet_... plugins can work together without potentially each including |
13 | # prototype independently, so it ends up included over and over again. |
14 | # |
15 | # If you want to use Lightwindow and Prototype for different sets of |
16 | # actions, call uses_lightwindow first, then uses_prototype, specifying |
17 | # a union of the actions required for both Lightwindow and Prototype in |
18 | # that second call. |
19 | |
20 | have_quiet_prototype = respond_to?( :uses_prototype ) |
21 | uses_prototype( filter_options ) if ( have_quiet_prototype ) |
22 | |
23 | proc = Proc.new do | c | |
24 | c.instance_variable_set( :@uses_lightwindow, true ) |
25 | c.instance_variable_set( :@have_quiet_prototype, true ) |
26 | end |
27 | |
28 | before_filter( proc, filter_options ) |
29 | end |
30 | end |
31 | |
32 | # Add in the class methods and establish the helper calls when the module |
33 | # gets included. |
34 | # |
35 | def self.included( base ) |
36 | base.extend( ClassMethods ) |
37 | base.helper( QuietLightwindowHelper ) |
38 | end |
39 | |
40 | # The helper module - methods for use within views. |
41 | # |
42 | module QuietLightwindowHelper |
43 | |
44 | # Include Lightwindow only if used for the current view, according to the |
45 | # Controller. Invoke using "<%= include_quiet_lightwindow_if_used -%>" from |
46 | # within the HEAD section of an XHTML view. If you want your HTML output |
47 | # to be nice and tidy in terms of indentation :-) then pass a string in |
48 | # the optional parameter - it will be inserted before each "<script>" tag |
49 | # in the returned HTML fragment. |
50 | # |
51 | # If using Quiet Prototype, then this plugin is called to include the |
52 | # Prototype library which Lightwindow requires. Your layout must use the |
53 | # "<%= include_prototype_if_used %>" directive or an equivalent *before* |
54 | # it includes Lightwindow. |
55 | # |
56 | # Note that a trailing newline *is* output so you can call the helper with |
57 | # the "-%>" closing ERB tag (as shown in the previous paragraph) to avoid |
58 | # inserting a single blank line into your output in the event that the |
59 | # plugin is *not* used by the current view. |
60 | # |
61 | def include_lightwindow_if_used( line_prefix = '' ) |
62 | return unless using_quiet_lightwindow? |
63 | |
64 | close = 'Close' |
65 | loading_or = 'Loading or' |
66 | cancel = 'cancel' |
67 | |
68 | if ( defined?( I18n ) ) |
69 | close = I18n.translate( :'pond.quiet_lightwindow.close', :default => close ) |
70 | loading_or = I18n.translate( :'pond.quiet_lightwindow.loading_or', :default => loading_or ) |
71 | cancel = I18n.translate( :'pond.quiet_lightwindow.cancel', :default => cancel ) |
72 | end |
73 | |
74 | script = <<JAVASCRIPT |
75 | var lightwindow_i18n = { |
76 | close: "#{ ERB::Util.j( close ) }", |
77 | loading_or: "#{ ERB::Util.j( loading_or ) }", |
78 | cancel: "#{ ERB::Util.j( cancel ) }" |
79 | } |
80 | JAVASCRIPT |
81 | |
82 | data = javascript_tag( script.chop ) |
83 | data << "\n" << javascript_include_tag( :defaults ) unless have_quiet_prototype? |
84 | data << "\n" << javascript_include_tag( 'lightwindow/lightwindow' ) |
85 | data << "\n" << stylesheet_link_tag( 'lightwindow/lightwindow' ) |
86 | |
87 | data.gsub( /^/, line_prefix ) + "\n" |
88 | end |
89 | |
90 | # Returns 'true' if configured to use the Lightwindow library for the view |
91 | # related to the current request. See the "uses_lightwindow" class method for |
92 | # more information. |
93 | # |
94 | def using_quiet_lightwindow? |
95 | ! @uses_lightwindow.nil? |
96 | end |
97 | |
98 | # Is "Quiet Prototype" available for including the Prototype library? |
99 | # |
100 | def have_quiet_prototype? |
101 | ! @have_quiet_prototype.nil? |
102 | end |
103 | end |
104 | end |
105 | |
106 | # Install the controller and helper methods. |
107 | |
108 | ActionController::Base.send( :include, QuietLightwindow ) |
109 | ActionView::Base.send :include, QuietLightwindow::QuietLightwindowHelper |