jqr-helpers 1.0.3 → 1.0.4
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/Readme.md +3 -2
- data/app/assets/javascripts/jqr-helpers.js +24 -15
- data/jqr-helpers.gemspec +1 -1
- data/lib/jqr-helpers/helpers.rb +16 -0
- data/lib/jqr-helpers/version.rb +1 -1
- metadata +1 -1
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
|
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
|
-
|
194
|
-
$('.ujs-
|
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
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
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
|
-
|
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
data/lib/jqr-helpers/helpers.rb
CHANGED
@@ -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).
|
data/lib/jqr-helpers/version.rb
CHANGED