window_rails 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == v0.2.4
2
+ * Add #resize_to_fit, #auto_resize and #center_window methods
3
+
1
4
  == v0.2.3
2
5
  * Add config directory to gemspec
3
6
  * Provide Rails 3 compatible routing
@@ -13,5 +13,5 @@ module WindowRails
13
13
  end
14
14
  end
15
15
 
16
- VERSION = Version.new('0.2.3')
16
+ VERSION = Version.new('0.2.4')
17
17
  end
@@ -156,15 +156,48 @@ module WindowRailsGenerators
156
156
  # win:: Name of window
157
157
  # Updates the contents of the window. If no window name is provided, the topmost window
158
158
  # will be updated
159
- def update_window_contents(key, win, options)
160
- window(win) << ".html(window.window_rails_contents[#{format_type_to_js(key.to_s)}]);"
161
- nil
159
+ def update_window_contents(key, win, options=nil)
160
+ window(win) << ".html('<div id=\"#{win}_wr_content\">' + window.window_rails_contents[#{format_type_to_js(key.to_s)}] + '</div>');"
161
+ end
162
+
163
+ # win:: Name of window
164
+ # padding:: Extra padding to add to calculated height and width
165
+ def resize_to_fit(win, padding=75)
166
+ if(padding.is_a?(Hash))
167
+ w_pad = padding[:width_pad]
168
+ h_pad = padding[:height_pad]
169
+ else
170
+ w_pad = h_pad = padding
171
+ end
172
+ auto_resize(win, h_pad, :height)
173
+ auto_resize(win, w_pad, :width)
174
+ center_window(win)
175
+ end
176
+
177
+ # win:: Name of window
178
+ # Recenters window
179
+ def center_window(win)
180
+ window(win) << ".dialog('option', 'position', 'center');"
181
+ end
182
+
183
+ # win:: Name of window
184
+ # extra_padding:: Extra padding to add to calculated size
185
+ # args:: Symbols for what to resize. Valid: :height and :width
186
+ def auto_resize(win, extra_padding, *args)
187
+ win = win.start_with?('#') ? win : "##{win}"
188
+ args.each do |item|
189
+ self << "
190
+ if(jQuery('#{win}').#{item}() < jQuery('#{win}_wr_content').#{item}() || jQuery('#{win}').#{item}() > jQuery('#{win}_wr_content').#{item}() + #{extra_padding.to_i}){"
191
+ window(win) << ".dialog('option', '#{item}', jQuery('#{win}_wr_content').#{item}() + #{extra_padding.to_i});"
192
+ self << "
193
+ }"
194
+ end
162
195
  end
163
196
 
164
197
  # win:: Name of window
165
198
  # Will focus the window. If no name provided, topmost window will be focused
166
199
  def focus_window(win=nil)
167
- window(win) << '.dialog("focus");'
200
+ window(win) << '.dialog().dialog("focus");'
168
201
  nil
169
202
  end
170
203
 
@@ -223,19 +256,16 @@ module WindowRailsGenerators
223
256
  jQuery.get(
224
257
  '#{options.delete(:url)}',
225
258
  function(data){
226
- window.window_rails_windows['#{win}']
259
+ jQuery('##{win}_wr_content')
227
260
  .html(data)
228
261
  .dialog(#{format_type_to_js(options)})
229
262
  .dialog('open');
230
263
  }
231
- );
264
+ )
232
265
  "
233
266
  else
234
- self << "
235
- window.window_rails_windows['#{win}']
236
- .html(window.window_rails_contents['#{key}'])
237
- .dialog(#{format_type_to_js(options)});
238
- "
267
+ window(win) << ".dialog(#{format_type_to_js(options)});"
268
+ update_window_contents(key, win)
239
269
  end
240
270
  nil
241
271
  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: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
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: 2011-10-21 00:00:00 -07:00
18
+ date: 2011-10-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency