jqr-helpers 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -44,7 +44,8 @@ the dialog content from a remote route)
44
44
  * `button_to_ajax` - send an Ajax request when a button is clicked
45
45
  * `form_tag_ajax` - send an Ajax request when a form is submitted
46
46
  * `form_for_ajax` - ditto but using Rails's `form_for` helper
47
- * `tab_container` - create a tab container.
47
+ * `tab_container` - create a tab container
48
+ * `date_picker_tag` - create a date picker
48
49
 
49
50
  There are two sets of options that recur throughout the methods here:
50
51
 
@@ -131,7 +132,7 @@ This allows you to loop through the tabs in an intuitive and concise way.
131
132
  There are two special events triggered by jqr-helpers:
132
133
 
133
134
  * `jqr.load` - this is triggered when a remote call populates an element with
134
- data. The scope for the callback is the element which has just had data
135
+ data. The target for the event is the element which has just had data
135
136
  populated.
136
137
  * `jqr.beforedialogopen` - for remote dialogs, this is triggered when the
137
138
  link or button is clicked to open the dialog but before the request is sent out.
@@ -190,28 +190,35 @@
190
190
  return false;
191
191
  }
192
192
 
193
- $(function() {
194
- $('.ujs-tab-container', this).each(function() {
193
+ function ujsLoadPlugins(event) {
194
+ $('.ujs-date-picker', event.target).each(function() {
195
+ var options = $(this).data('date-options');
196
+ $(this).datepicker(options);
197
+ });
198
+ $('.ujs-tab-container', event.target).each(function() {
195
199
  var options = $(this).data('tab-options');
196
200
  options = $.extend(options, {
197
- beforeLoad: function(event, ui) {
198
- if (ui.tab.data('loaded')) {
199
- event.preventDefault();
200
- return;
201
+ beforeLoad: function(event, ui) {
202
+ if (ui.tab.data('loaded')) {
203
+ event.preventDefault();
204
+ return;
205
+ }
206
+ ui.jqXHR.success(function() {
207
+ ui.tab.data('loaded', true);
208
+ });
209
+ $(ui.panel).html('Loading...');
210
+ ui.jqXHR.fail(function(jqXHR, textStatus, errorThrown) {
211
+ ui.panel.html('Error loading the tab: ' + errorThrown);
212
+ });
201
213
  }
202
- ui.jqXHR.success(function() {
203
- ui.tab.data('loaded', true);
204
- });
205
- $(ui.panel).html('Loading...');
206
- ui.jqXHR.fail(function(jqXHR, textStatus, errorThrown) {
207
- ui.panel.html('Error loading the tab: ' + errorThrown);
208
- });
209
- }
210
- });
214
+ });
211
215
  $(this).tabs(options);
212
216
  });
217
+ }
213
218
 
219
+ $(function() {
214
220
  if ($().on) { // newer jQueries
221
+ $(document).on('jqr.load', ujsLoadPlugins);
215
222
  $(document).on('click', '.ujs-dialog', ujsDialogClick);
216
223
  $(document).on('click', '.ujs-dialog-close, .ujs-dialog-x',
217
224
  ujsDialogCloseClick);
@@ -221,6 +228,7 @@
221
228
  $(document).on('click', '[data-ujs-confirm=true]', ujsConfirmClick);
222
229
  }
223
230
  else {
231
+ $(document).live('jrq.load', ujsLoadPlugins);
224
232
  $('.ujs-dialog').live('click', ujsDialogClick);
225
233
  $('.ujs-dialog-close, .ujs-dialog-x').live('click', ujsDialogCloseClick);
226
234
  $('.ujs-ajax').live('ajax:beforeSend', ujsAjaxBeforeSend);
@@ -228,6 +236,7 @@
228
236
  $('.ujs-ajax').live('ajax:error', ujsAjaxError);
229
237
  $('[data-ujs-confirm=true]').live('click', ujsConfirmClick);
230
238
  }
239
+ $('body').trigger('jqr.load');
231
240
 
232
241
  });
233
242
 
data/jqr-helpers.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jqr-helpers'
3
3
  s.require_paths = %w(. lib lib/jqr-helpers)
4
- s.version = '1.0.3'
4
+ s.version = '1.0.4'
5
5
  s.date = '2013-11-19'
6
6
  s.summary = 'Helpers to print unobtrusive jQuery-UI tags.'
7
7
  s.description = <<-EOF
@@ -266,6 +266,22 @@ module JqrHelpers
266
266
  end
267
267
  end
268
268
 
269
+ # Create a date picker field. The attributes given are passed to
270
+ # text_field_tag. Note that Ruby and jQuery date formats are different.
271
+ # You will need to format the "value" parameter to match whatever format you
272
+ # are passing into the "options" parameter.
273
+ # @param name [String] the name of the form element.
274
+ # @param value [Date] the initial value.
275
+ # @param options [Hash] options to be passed to datepicker().
276
+ # @param html_options [Hash] options to be passed to text_field_tag.
277
+ # @return [String]
278
+ def date_picker_tag(name, value, options={}, html_options={})
279
+ html_options[:'data-date-options'] = options.to_json
280
+ html_options[:class] ||= ''
281
+ html_options[:class] << ' ujs-date-picker'
282
+ text_field_tag(name, value, html_options)
283
+ end
284
+
269
285
  private
270
286
 
271
287
  # Process options related to Ajax requests (e.g. button_to_ajax).
@@ -1,5 +1,5 @@
1
1
  module JqrHelpers
2
2
  module Rails
3
- VERSION = '1.0.3'
3
+ VERSION = '1.0.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jqr-helpers
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.3
5
+ version: 1.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Orner