window_rails 0.1.0 → 0.1.1
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/CHANGELOG.rdoc +6 -0
- data/README.rdoc +10 -6
- data/files/javascripts/window.js +12 -4
- data/lib/window_rails/version.rb +1 -1
- data/lib/window_rails/window_rails_generators.rb +55 -12
- data/lib/window_rails/window_rails_view.rb +7 -3
- metadata +8 -7
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== v0.1.1
|
2
|
+
* Proper rails loading when included via gem
|
3
|
+
* Fix for window jumping when constraints applied
|
4
|
+
* Fix for #observe_dynamically_loaded_field when using a function instead of callback
|
5
|
+
* Make IFrame usage optional
|
6
|
+
|
1
7
|
== v0.1.0
|
2
8
|
* Lots of cleanup
|
3
9
|
* Better builders available
|
data/README.rdoc
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
++ Important note ++
|
2
|
-
|
3
|
-
This is still in its infancy and is pretty unstable. This will be removed once it's ready
|
4
|
-
for initial release.
|
5
|
-
|
6
1
|
== WindowRails
|
7
2
|
|
8
3
|
WindowRails is a plugin for Rails that provides easy to use AJAXy windows. It is based
|
9
4
|
completely on {Prototype Window}[http://prototype-window.xilinus.com/] with helpers for
|
10
5
|
Rails to make it easy to use from a Rails app.
|
11
6
|
|
7
|
+
== Configuration
|
8
|
+
|
9
|
+
After install, add these in the head of your application.html.erb file:
|
10
|
+
|
11
|
+
<%= javascript_include_tag 'window_rails/window' %>
|
12
|
+
<%= stylesheet_link_tag *%w(/themes/alphacube /themes/default /themes/alert) %>
|
13
|
+
|
14
|
+
Alphacube is the default theme used by window_rails. Be sure to add the css link if you plan on using other themes.
|
15
|
+
|
12
16
|
=== Basic examples to get you started
|
13
17
|
|
14
18
|
==== Linking to a window
|
@@ -65,4 +69,4 @@ Rails to make it easy to use from a Rails app.
|
|
65
69
|
== License
|
66
70
|
|
67
71
|
* Prototype Window was released under the MIT license
|
68
|
-
* WindowRails continues on under the MIT license
|
72
|
+
* WindowRails continues on under the MIT license
|
data/files/javascripts/window.js
CHANGED
@@ -287,8 +287,13 @@ Window.prototype = {
|
|
287
287
|
},
|
288
288
|
|
289
289
|
setAjaxContent: function(url, options, showCentered, showModal) {
|
290
|
-
|
291
|
-
|
290
|
+
if(showCentered){
|
291
|
+
this.showFunction = showCentered ? "showCenter" : "show";
|
292
|
+
this.showModal = showModal || false;
|
293
|
+
} else {
|
294
|
+
this.showFunction = null;
|
295
|
+
this.showModal = null;
|
296
|
+
}
|
292
297
|
|
293
298
|
options = options || {};
|
294
299
|
|
@@ -309,7 +314,9 @@ Window.prototype = {
|
|
309
314
|
if (this.onComplete)
|
310
315
|
this.onComplete(originalRequest);
|
311
316
|
this.onComplete = null;
|
312
|
-
this
|
317
|
+
if(this.showFunction){
|
318
|
+
this[this.showFunction](this.showModal)
|
319
|
+
}
|
313
320
|
},
|
314
321
|
|
315
322
|
setURL: function(url) {
|
@@ -537,8 +544,9 @@ Window.prototype = {
|
|
537
544
|
if (this.constraint && this.useLeft && this.useTop) {
|
538
545
|
var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
|
539
546
|
|
547
|
+
// the -10 gives a bit of pad to reduce window from jumping screen
|
540
548
|
if (left < this.constraintPad.left)
|
541
|
-
left = this.constraintPad.left;
|
549
|
+
left = this.constraintPad.left - 10;
|
542
550
|
if (left + this.width + this.widthE + this.widthW > width - this.constraintPad.right)
|
543
551
|
left = width - this.constraintPad.right - this.width - this.widthE - this.widthW;
|
544
552
|
}
|
data/lib/window_rails/version.rb
CHANGED
@@ -54,6 +54,10 @@ module WindowRailsGenerators
|
|
54
54
|
self << check_for_window(win, error){ update_window_contents(content, win) }
|
55
55
|
end
|
56
56
|
|
57
|
+
# name:: Name of the window
|
58
|
+
# error:: Will throw an alert if window is not found
|
59
|
+
# Checks for a window of the given name. If a block is provided, it will be executed
|
60
|
+
# if the window is found
|
57
61
|
def check_for_window(name, error)
|
58
62
|
if(name.blank?)
|
59
63
|
self << "if(Windows.windows.values().size() > 0){"
|
@@ -65,13 +69,18 @@ module WindowRailsGenerators
|
|
65
69
|
self << "else { alert('Unexpected error. Failed to locate window for output.'); }" if error
|
66
70
|
end
|
67
71
|
|
72
|
+
# Simply wraps a block within an else statement
|
68
73
|
def else_block
|
69
74
|
self << "else {"
|
70
75
|
yield if block_given?
|
71
76
|
self << "}"
|
72
77
|
end
|
73
78
|
|
74
|
-
|
79
|
+
# content:: String content
|
80
|
+
# win:: Name of window
|
81
|
+
# Updates the contents of the window. If no window name is provided, the topmost window
|
82
|
+
# will be updated
|
83
|
+
def update_window_contents(content, win=nil)
|
75
84
|
unless(win.blank?)
|
76
85
|
self << "Windows.getWindowByName('#{escape_javascript(win)}').setHTMLContent('#{escape_javascript(content)}');"
|
77
86
|
else
|
@@ -79,7 +88,9 @@ module WindowRailsGenerators
|
|
79
88
|
end
|
80
89
|
end
|
81
90
|
|
82
|
-
|
91
|
+
# win:: Name of window
|
92
|
+
# Will focus the window. If no name provided, topmost window will be focused
|
93
|
+
def focus_window(win=nil)
|
83
94
|
unless(win.blank?)
|
84
95
|
self << "Windows.focus(Windows.getWindowByName('#{escape_javascript(win)}').getId());"
|
85
96
|
else
|
@@ -87,13 +98,27 @@ module WindowRailsGenerators
|
|
87
98
|
end
|
88
99
|
end
|
89
100
|
|
101
|
+
# content:: String content
|
102
|
+
# win:: Name of window
|
103
|
+
# options:: Options to be passed onto window
|
104
|
+
# Creates a new window. Generally this should not be called,
|
105
|
+
# rather #open_window should be used
|
90
106
|
def create_window(content, win, options)
|
91
107
|
self << "var myWin = new Window({#{options.map{|k,v|"#{escape_javascript(k.to_s)}:'#{escape_javascript(v.to_s)}'"}.join(', ')}});"
|
92
108
|
self << "Windows.registerByName('#{escape_javascript(win)}', myWin);" unless win.blank?
|
93
|
-
|
109
|
+
if(content.is_a?(Hash) && content[:url])
|
110
|
+
self << "myWin.setAjaxContent('#{escape_javascript(content[:url])}');"
|
111
|
+
elsif(!content.blank?)
|
112
|
+
self << "myWin.setHTMLContent('#{escape_javascript(content.to_s)}');"
|
113
|
+
end
|
94
114
|
self << "myWin.setCloseCallback(function(win){ win.destroy(); return true; });"
|
95
115
|
end
|
96
116
|
|
117
|
+
# win:: Name of window
|
118
|
+
# modal:: True if window should be modal
|
119
|
+
# Shows the window centered on the screen. If no window name is provided
|
120
|
+
# it will default to the last created window. Generally this should not
|
121
|
+
# be called, rather #open_window should be used
|
97
122
|
def show_window(win, modal)
|
98
123
|
s = nil
|
99
124
|
unless(win.blank?)
|
@@ -104,6 +129,10 @@ module WindowRailsGenerators
|
|
104
129
|
self << "#{s}.showCenter(#{modal ? 'true' : 'false'});"
|
105
130
|
end
|
106
131
|
|
132
|
+
# win:: Name of window
|
133
|
+
# constraints:: Constaint hash {:left, :right, :top, :bottom}
|
134
|
+
# Sets the constraints on the window. Generally this should not be used,
|
135
|
+
# rather #open_window should be used
|
107
136
|
def apply_window_constraints(win, constraints)
|
108
137
|
opts = {:left => 0, :right => 0, :top => 0, :bottom => 0}
|
109
138
|
opts.merge!(constraints) if constraints.is_a?(Hash)
|
@@ -118,15 +147,23 @@ module WindowRailsGenerators
|
|
118
147
|
|
119
148
|
# content:: Content for window
|
120
149
|
# options:: Hash of options
|
121
|
-
# * modal -> Window should be modal
|
122
|
-
# * window -> Name to reference window (used for easy updating and closing)
|
123
|
-
# * constraints -> Hash containing top,left,right,bottom values for padding from edges. False value will turn off constraints (window can travel out of viewport)
|
124
|
-
# *
|
125
|
-
# * width -> Width of the window
|
126
|
-
# * height -> Height of the window
|
127
|
-
# * className -> Theme name for the window
|
128
|
-
# * no_update -> Set to true to force creation of a new window even if window of same name already exists (defaults to false)
|
129
|
-
# Creates a new window and displays it at the center of the viewport.
|
150
|
+
# * :modal -> Window should be modal
|
151
|
+
# * :window -> Name to reference window (used for easy updating and closing)
|
152
|
+
# * :constraints -> Hash containing top,left,right,bottom values for padding from edges. False value will turn off constraints (window can travel out of viewport)
|
153
|
+
# * :iframe -> URL to load within an IFrame in the window
|
154
|
+
# * :width -> Width of the window
|
155
|
+
# * :height -> Height of the window
|
156
|
+
# * :className -> Theme name for the window
|
157
|
+
# * :no_update -> Set to true to force creation of a new window even if window of same name already exists (defaults to false)
|
158
|
+
# Creates a new window and displays it at the center of the viewport. Content can be provided as
|
159
|
+
# a string, or as a Hash. If :url is defined, the window will be loaded with the contents of the request. If not, the hash
|
160
|
+
# will be passed to #render and the string will be displayed.
|
161
|
+
# Important note:
|
162
|
+
# There are two ways to load remote content. The first is to use :url => 'http://host/page.html' for content. This will
|
163
|
+
# load the contents directly into the window. The second is to set content to nil and pass :iframe => 'http://host/page.html'
|
164
|
+
# in the options. This later form will load the contents within an IFrame in the window. This is useful in that it will
|
165
|
+
# be isolated from the current page, but this isolation means it cannot communicate with other windows on the page (including
|
166
|
+
# its own).
|
130
167
|
def open_window(content, options={})
|
131
168
|
modal = options.delete(:modal)
|
132
169
|
win = options.delete(:window)
|
@@ -198,10 +235,16 @@ module WindowRailsGenerators
|
|
198
235
|
end
|
199
236
|
end
|
200
237
|
|
238
|
+
# field_id:: DOM ID of form element to observe
|
239
|
+
# options:: Options
|
240
|
+
# Helper for observing fields that have been dynamically loaed into the DOM. Works like
|
241
|
+
# #observe_field but not as full featured.
|
201
242
|
def observe_dynamically_loaded_field(field_id, options={})
|
202
243
|
f = options.delete(:function)
|
203
244
|
unless(f)
|
204
245
|
f = "function(event){ new Ajax.Request('#{escape_javascript(@context.url_for(options[:url]).to_s)}', {asynchronous:true, evalScripts:true,parameters:'#{escape_javascript(options[:with].to_s)}='+$('#{escape_javascript(options[:with].to_s)}').getValue()})}"
|
246
|
+
else
|
247
|
+
f = "function(event){ #{f}; }"
|
205
248
|
end
|
206
249
|
self << "if($('#{escape_javascript(field_id.to_s)}')){ $('#{escape_javascript(field_id.to_s)}').observe('change', #{f}); }"
|
207
250
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module WindowRailsView
|
2
2
|
|
3
3
|
# name:: Name of the link
|
4
|
-
# options:: Hash of
|
5
|
-
#
|
4
|
+
# options:: Hash of options values.
|
5
|
+
# Creates a link to a window. Content is defined by a url in the options hash using :url or :iframe.
|
6
|
+
# If :url is used, the content is loaded into the window within the page. If :iframe is used
|
7
|
+
# the content is loaded into the window within an IFrame on the page. Generally, if you are calling
|
8
|
+
# a method that simply renders out a partial, you want to use :url. If you are calling something
|
9
|
+
# that returns an entire page, :iframe will likely be the ticket.
|
6
10
|
def link_to_window(name, options={})
|
7
|
-
link_to_remote(name, :url => {:controller => :window_rails, :action => :open_window, :window_url => url_for(options.delete(:url)), :window_options => options})
|
11
|
+
link_to_remote(name, :url => {:controller => :window_rails, :action => :open_window, :window_url => url_for(options.delete(:url)), :iframe_url => url_for(options.delete(:iframe)), :window_options => options})
|
8
12
|
end
|
9
13
|
|
10
14
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: window_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Roberts
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-17 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,10 +26,11 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 5
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
version: "2.3"
|
33
34
|
type: :runtime
|
34
35
|
version_requirements: *id001
|
35
36
|
description: Windows for Rails
|