jqr-helpers 1.0.18 → 1.0.19

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -49,6 +49,8 @@ the dialog content from a remote route)
49
49
  * `tab_container` - create a tab container
50
50
  * `date_picker_tag` - create a date picker
51
51
  * `buttonset` - create a radio button set
52
+ * `will_paginate_ajax` - create a will_paginate interface that uses Ajax to
53
+ replace the paginated contents.
52
54
 
53
55
  There are two sets of options that recur throughout the methods here:
54
56
 
@@ -57,35 +59,35 @@ There are two sets of options that recur throughout the methods here:
57
59
  These are parameters to pass to the `jQuery.dialog()` function.
58
60
  See <http://api.jqueryui.com/dialog/>.
59
61
 
60
- An extra custom option is `:title` - setting it to `false` will hide the
61
- title bar.
62
+ Additional or changed options:
62
63
 
63
- Another thing to note is the special values for buttons. Usually the buttons
64
- must have JavaScript callbacks, but 99% of the time you want the classic
65
- OK and Cancel buttons. Passing `submit` and `close` as the values
66
- of the buttons (or the values of the "click" attribute of the buttons)
67
- will do just that - submit the form inside the dialog or close it.
64
+ * `:title` - setting this to `false` will hide the title bar.
65
+ * `:buttons`: Usually the buttons must have JavaScript callbacks, but 99% of the
66
+ time you want the classic OK and Cancel buttons. Passing `submit` and `close`
67
+ as the values of the buttons (or the values of the "click" attribute of the
68
+ buttons) will do just that - submit the form inside the dialog or close it.
68
69
 
69
70
  Example:
70
71
 
71
72
  button_to_dialog('my-dialog-id', 'Open Dialog', :buttons =>
72
73
  {'OK' => 'submit', 'Cancel' => 'close'})
73
74
 
74
- You can also use a special option, `:default_buttons => true`, as a shortcut
75
- to the above buttons, since it's so common to have an OK and Cancel
76
- button.
77
-
78
- Another option is `:close_x => true` - this will print a green X at the top
75
+ * `:default_buttons`: This is a special option which acts as a shortcut
76
+ to the above example, since it's so common to have an OK and Cancel button.
77
+ * `:close_x => true`: this will print a green X at the top
79
78
  right of the dialog. Generally this is used when `:title => false`.
80
-
81
- Another option is `:data` - this accepts a hash of string/value pairs. When this
79
+ *`:data`: this accepts a hash of string/value pairs. When this
82
80
  is given, jqr-helpers will search the dialog for input fields whose names
83
81
  match the keys and populate them with the values. This is helpful when you want
84
82
  to pass data to a local dialog but don't want to mess around with saving data
85
83
  attributes and callbacks. When using a remote dialog it's easier to just pass
86
84
  the data into the URL and have Rails populate it on the server side.
85
+ *`:throbber`: For remote dialogs only. This can be `:small`, `:large`, or
86
+ `:none`. By default it is `:large`, indicating a throbber that goes in front
87
+ of the screen. `:small` would be a small inline throbber next to the button or
88
+ link that called the dialog, and `:none` shows no throbber at all.
87
89
 
88
- Note about dialog ID - you can always pass in the special value `:next` for
90
+ A note about dialog ID - you can always pass in the special value `:next` for
89
91
  this. This will use whatever element is just after the clicked element
90
92
  for the dialog contents. This can be useful for printing simple dialogs inside a
91
93
  foreach loop that shouldn't require a totally separate route + view.
@@ -126,6 +128,13 @@ other elements.
126
128
  this indicates that the dialog should be closed when the request completes
127
129
  successfully. This is true by default for forms and false for
128
130
  other elements.
131
+ * `:scroll_to` (Boolean) - if given, the element that was updated or inserted
132
+ will be scrolled into view (i.e. its top will be aligned with the top of the
133
+ page).
134
+ *`:throbber` (String) - This can be `:small`, `:large`, or
135
+ `:none`. By default it is `:small`, indicating a throbber that goes in front
136
+ of the screen. `:small` would be a small inline throbber next to the button or
137
+ link that called the dialog, and `:none` shows no throbber at all.
129
138
 
130
139
  ## Panel Renderers ##
131
140
 
@@ -149,6 +158,12 @@ populated.
149
158
  * `jqr.beforedialogopen` - for remote dialogs, this is triggered when the
150
159
  link or button is clicked to open the dialog but before the request is sent out.
151
160
 
161
+ ## will_paginate ##
162
+
163
+ jqr-helpers supports an Ajax version of [will_paginate](https://github.com/mislav/will_paginate).
164
+ This replaces each link with an Ajax link and will load the content of the page
165
+ into the supplied element.
166
+
152
167
  ***
153
168
 
154
169
  jqr-helpers was developed by [Wishabi](http://www.wishabi.com).
@@ -1,11 +1,20 @@
1
1
  (function($) {
2
2
  function showThrobber(element) {
3
- $(element).after("<img src='/images/jqr-helpers/throbber.gif' class='throbber'/>");
3
+ switch ($(element).data('throbber')) {
4
+ case 'none':
5
+ return;
6
+ case 'large':
7
+ $(document.body).append('<div id="ujs-dialog-throbber">');
8
+ break;
9
+ default: // small or not given
10
+ $(element).after("<img src='/images/jqr-helpers/throbber.gif' class='throbber'/>");
11
+ }
4
12
  $(element).attr('disabled', 'disabled');
5
13
  }
6
14
 
7
15
  function hideThrobber(element) {
8
16
  $(element).nextAll('.throbber').remove();
17
+ $('#ujs-dialog-throbber').remove();
9
18
  $(element).removeAttr('disabled');
10
19
  }
11
20
 
@@ -27,11 +36,13 @@
27
36
  $(this).css('maxHeight', ($(window).height() * 0.8) + 'px');
28
37
  if ($(this).parent().height() > $(window).height()) {
29
38
  $(this).height($(window).height() * 0.8);
30
- $(this).parent().css('top',
31
- Math.max(($(window).height() - $(this).parent().height()) / 2, 1)
32
- );
33
39
  $(this).css('overflow-y', 'auto');
34
40
  }
41
+ $(this).parent().position({
42
+ my: 'center',
43
+ at: 'center',
44
+ of: $(window)
45
+ });
35
46
  var x = $(this).find('.ujs-dialog-x');
36
47
  if (x.length) {
37
48
  $(this).parent().append(x); // to keep it fixed to the dialog
@@ -93,7 +104,7 @@
93
104
  if (url) {
94
105
  $(this).trigger('jqr.beforedialogopen');
95
106
  $(document.body).append('<div class="ui-widget-overlay ui-front">');
96
- $(document.body).append('<div id="remote-dialog-throbber">');
107
+ showThrobber(ujsDialogElement);
97
108
  var closeX = $(this).data('close-x');
98
109
  if (dialogElement.length == 0) {
99
110
  $('body').append("<div id='" + dialogID + "'>");
@@ -104,7 +115,8 @@
104
115
  dialogElement.prepend('<span class="ujs-dialog-x"></span>');
105
116
  }
106
117
  $('.ui-widget-overlay').remove();
107
- $('#remote-dialog-throbber').remove();
118
+ hideThrobber(ujsDialogElement);
119
+ $('#ujs-dialog-throbber').remove();
108
120
  $(this).dialog(dialogOptions);
109
121
  $(dialogElement).trigger('jqr.load');
110
122
  });
@@ -216,13 +228,24 @@
216
228
  break;
217
229
  }
218
230
  target.effect('highlight');
231
+ if (element.data('scroll-to')) {
232
+ target[0].scrollIntoView(true);
233
+ }
219
234
  }
220
235
  return false;
221
236
  }
222
237
 
223
238
  function ujsAjaxError(evt, xhr, status, error) {
224
239
  alert(error || 'An error occurred.');
225
- hideThrobber(this);
240
+ var element = $(this);
241
+ if (element.data('real-element')) {
242
+ element = $('#' + element.data('real-element'));
243
+ }
244
+ var disableElement = element;
245
+ if (element.is('form') &&
246
+ $(ujsSubmitElement).parents('form').index(element) >= 0)
247
+ disableElement = ujsSubmitElement;
248
+ hideThrobber(disableElement);
226
249
  }
227
250
 
228
251
  function ujsConfirmClick() {
@@ -22,4 +22,15 @@
22
22
 
23
23
  form.ujs-ajax {
24
24
  display: inline;
25
- }
25
+ }
26
+
27
+ #ujs-dialog-throbber {
28
+ background-image: url('/images/jqr-helpers/throbber_large.gif');
29
+ position: fixed;
30
+ top: 48%;
31
+ left: 48%;
32
+ z-index: 200;
33
+ width: 48px;
34
+ height: 48px;
35
+ }
36
+
@@ -201,7 +201,7 @@
201
201
  </div>
202
202
 
203
203
  <div id="footer">
204
- Generated on Tue Dec 31 12:22:37 2013 by
204
+ Generated on Fri Jan 3 15:22:08 2014 by
205
205
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
206
206
  0.8.7.3 (ruby-1.9.3).
207
207
  </div>
@@ -106,7 +106,7 @@
106
106
  </div>
107
107
 
108
108
  <div id="footer">
109
- Generated on Tue Dec 31 12:22:36 2013 by
109
+ Generated on Fri Jan 3 15:22:08 2014 by
110
110
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
111
111
  0.8.7.3 (ruby-1.9.3).
112
112
  </div>
@@ -452,7 +452,7 @@ be passed as is into the HTML &lt;li&gt; tag.</p>
452
452
  </div>
453
453
 
454
454
  <div id="footer">
455
- Generated on Tue Dec 31 12:22:36 2013 by
455
+ Generated on Fri Jan 3 15:22:08 2014 by
456
456
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
457
457
  0.8.7.3 (ruby-1.9.3).
458
458
  </div>
@@ -431,6 +431,30 @@ using content already on the page.</p>
431
431
  <p>Print a tab container.</p>
432
432
  </div></span>
433
433
 
434
+ </li>
435
+
436
+
437
+ <li class="public ">
438
+ <span class="summary_signature">
439
+
440
+ <a href="#will_paginate_ajax-instance_method" title="#will_paginate_ajax (instance method)">- (String) <strong>will_paginate_ajax</strong>(collection, to_update, options = {}) </a>
441
+
442
+
443
+
444
+ </span>
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+ <span class="summary_desc"><div class='inline'>
455
+ <p>Create a will_paginate pagination interface which runs via Ajax.</p>
456
+ </div></span>
457
+
434
458
  </li>
435
459
 
436
460
 
@@ -482,12 +506,12 @@ using content already on the page.</p>
482
506
  <pre class="lines">
483
507
 
484
508
 
485
- 311
486
- 312
487
- 313</pre>
509
+ 313
510
+ 314
511
+ 315</pre>
488
512
  </td>
489
513
  <td>
490
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 311</span>
514
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 313</span>
491
515
 
492
516
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid__random_string'>_random_string</span>
493
517
  <span class='const'>SecureRandom</span><span class='period'>.</span><span class='id identifier rubyid_hex'>hex</span><span class='lparen'>(</span><span class='int'>16</span><span class='rparen'>)</span>
@@ -597,8 +621,6 @@ button_to, so it can be used inside forms.</p>
597
621
  <pre class="lines">
598
622
 
599
623
 
600
- 186
601
- 187
602
624
  188
603
625
  189
604
626
  190
@@ -610,10 +632,12 @@ button_to, so it can be used inside forms.</p>
610
632
  196
611
633
  197
612
634
  198
613
- 199</pre>
635
+ 199
636
+ 200
637
+ 201</pre>
614
638
  </td>
615
639
  <td>
616
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 186</span>
640
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 188</span>
617
641
 
618
642
  <span class='kw'>def</span> <span class='id identifier rubyid_button_to_ajax'>button_to_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_body'>body</span><span class='comma'>,</span> <span class='id identifier rubyid_url'>url</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
619
643
 
@@ -876,14 +900,14 @@ using content already on the page.</p>
876
900
  <pre class="lines">
877
901
 
878
902
 
879
- 153
880
- 154
881
903
  155
882
904
  156
883
- 157</pre>
905
+ 157
906
+ 158
907
+ 159</pre>
884
908
  </td>
885
909
  <td>
886
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 153</span>
910
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 155</span>
887
911
 
888
912
  <span class='kw'>def</span> <span class='id identifier rubyid_button_to_remote_dialog'>button_to_remote_dialog</span><span class='lparen'>(</span><span class='id identifier rubyid_url'>url</span><span class='comma'>,</span> <span class='id identifier rubyid_html_content'>html_content</span><span class='comma'>,</span> <span class='id identifier rubyid_dialog_options'>dialog_options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span>
889
913
  <span class='id identifier rubyid_html_options'>html_options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
@@ -994,18 +1018,18 @@ then be passed into jQuery's buttonset() method.</p>
994
1018
  <pre class="lines">
995
1019
 
996
1020
 
997
- 299
998
- 300
999
1021
  301
1000
1022
  302
1001
1023
  303
1002
1024
  304
1003
1025
  305
1004
1026
  306
1005
- 307</pre>
1027
+ 307
1028
+ 308
1029
+ 309</pre>
1006
1030
  </td>
1007
1031
  <td>
1008
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 299</span>
1032
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 301</span>
1009
1033
 
1010
1034
  <span class='kw'>def</span> <span class='id identifier rubyid_buttonset'>buttonset</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_values'>values</span><span class='comma'>,</span> <span class='id identifier rubyid_selected'>selected</span><span class='op'>=</span><span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_html_options'>html_options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
1011
1035
  <span class='id identifier rubyid_html_options'>html_options</span><span class='lbracket'>[</span><span class='symbol'>:class</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>'</span></span>
@@ -1256,18 +1280,18 @@ the date and the jQuery date format to be the same.</p>
1256
1280
  <pre class="lines">
1257
1281
 
1258
1282
 
1259
- 282
1260
- 283
1261
1283
  284
1262
1284
  285
1263
1285
  286
1264
1286
  287
1265
1287
  288
1266
1288
  289
1267
- 290</pre>
1289
+ 290
1290
+ 291
1291
+ 292</pre>
1268
1292
  </td>
1269
1293
  <td>
1270
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 282</span>
1294
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 284</span>
1271
1295
 
1272
1296
  <span class='kw'>def</span> <span class='id identifier rubyid_date_picker_tag'>date_picker_tag</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>=</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_today'>today</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_html_options'>html_options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
1273
1297
  <span class='id identifier rubyid_format'>format</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:format</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%Y-%m-%d</span><span class='tstring_end'>'</span></span>
@@ -1351,8 +1375,6 @@ form_for instead of form_tag.</p>
1351
1375
  <pre class="lines">
1352
1376
 
1353
1377
 
1354
- 222
1355
- 223
1356
1378
  224
1357
1379
  225
1358
1380
  226
@@ -1361,10 +1383,12 @@ form_for instead of form_tag.</p>
1361
1383
  229
1362
1384
  230
1363
1385
  231
1364
- 232</pre>
1386
+ 232
1387
+ 233
1388
+ 234</pre>
1365
1389
  </td>
1366
1390
  <td>
1367
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 222</span>
1391
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 224</span>
1368
1392
 
1369
1393
  <span class='kw'>def</span> <span class='id identifier rubyid_form_for_ajax'>form_for_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_record'>record</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
1370
1394
  <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:remote</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
@@ -1460,8 +1484,6 @@ form_tag with :remote =&gt; true.</p>
1460
1484
  <pre class="lines">
1461
1485
 
1462
1486
 
1463
- 206
1464
- 207
1465
1487
  208
1466
1488
  209
1467
1489
  210
@@ -1469,10 +1491,12 @@ form_tag with :remote =&gt; true.</p>
1469
1491
  212
1470
1492
  213
1471
1493
  214
1472
- 215</pre>
1494
+ 215
1495
+ 216
1496
+ 217</pre>
1473
1497
  </td>
1474
1498
  <td>
1475
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 206</span>
1499
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 208</span>
1476
1500
 
1477
1501
  <span class='kw'>def</span> <span class='id identifier rubyid_form_tag_ajax'>form_tag_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_url'>url</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
1478
1502
 
@@ -1585,8 +1609,6 @@ used for the body.</p>
1585
1609
  <pre class="lines">
1586
1610
 
1587
1611
 
1588
- 167
1589
- 168
1590
1612
  169
1591
1613
  170
1592
1614
  171
@@ -1596,10 +1618,12 @@ used for the body.</p>
1596
1618
  175
1597
1619
  176
1598
1620
  177
1599
- 178</pre>
1621
+ 178
1622
+ 179
1623
+ 180</pre>
1600
1624
  </td>
1601
1625
  <td>
1602
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 167</span>
1626
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 169</span>
1603
1627
 
1604
1628
  <span class='kw'>def</span> <span class='id identifier rubyid_link_to_ajax'>link_to_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_body'>body</span><span class='comma'>,</span> <span class='id identifier rubyid_url'>url</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
1605
1629
  <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
@@ -1946,7 +1970,9 @@ pass :div, :span, etc.</p>
1946
1970
  141
1947
1971
  142
1948
1972
  143
1949
- 144</pre>
1973
+ 144
1974
+ 145
1975
+ 146</pre>
1950
1976
  </td>
1951
1977
  <td>
1952
1978
  <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 132</span>
@@ -1959,6 +1985,8 @@ pass :div, :span, etc.</p>
1959
1985
  <span class='id identifier rubyid_dialog_options'>dialog_options</span> <span class='op'>=</span> <span class='id identifier rubyid_html_content'>html_content</span>
1960
1986
  <span class='id identifier rubyid_html_content'>html_content</span> <span class='op'>=</span> <span class='id identifier rubyid_capture'>capture</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
1961
1987
  <span class='kw'>end</span>
1988
+ <span class='id identifier rubyid_html_options'>html_options</span><span class='lbracket'>[</span><span class='symbol'>:data-throbber</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span>
1989
+ <span class='id identifier rubyid_dialog_options'>dialog_options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:throbber</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>large</span><span class='tstring_end'>'</span></span>
1962
1990
 
1963
1991
  <span class='id identifier rubyid_html_options'>html_options</span><span class='lbracket'>[</span><span class='symbol'>:data-dialog-url</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_url'>url</span>
1964
1992
  <span class='id identifier rubyid_link_to_dialog'>link_to_dialog</span><span class='lparen'>(</span><span class='const'>Helpers</span><span class='period'>.</span><span class='id identifier rubyid__random_string'>_random_string</span><span class='comma'>,</span> <span class='id identifier rubyid_html_content'>html_content</span><span class='comma'>,</span>
@@ -2050,8 +2078,6 @@ URL).</p>
2050
2078
  <pre class="lines">
2051
2079
 
2052
2080
 
2053
- 247
2054
- 248
2055
2081
  249
2056
2082
  250
2057
2083
  251
@@ -2074,10 +2100,12 @@ URL).</p>
2074
2100
  268
2075
2101
  269
2076
2102
  270
2077
- 271</pre>
2103
+ 271
2104
+ 272
2105
+ 273</pre>
2078
2106
  </td>
2079
2107
  <td>
2080
- <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 247</span>
2108
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 249</span>
2081
2109
 
2082
2110
  <span class='kw'>def</span> <span class='id identifier rubyid_tab_container'>tab_container</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_html_options'>html_options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
2083
2111
  <span class='id identifier rubyid_renderer'>renderer</span> <span class='op'>=</span> <span class='const'>PanelRenderer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
@@ -2107,6 +2135,137 @@ URL).</p>
2107
2135
  </td>
2108
2136
  </tr>
2109
2137
  </table>
2138
+ </div>
2139
+
2140
+ <div class="method_details ">
2141
+ <h3 class="signature " id="will_paginate_ajax-instance_method">
2142
+
2143
+ - (<tt>String</tt>) <strong>will_paginate_ajax</strong>(collection, to_update, options = {})
2144
+
2145
+
2146
+
2147
+
2148
+
2149
+ </h3><div class="docstring">
2150
+ <div class="discussion">
2151
+
2152
+ <p>Create a will_paginate pagination interface which runs via Ajax.</p>
2153
+
2154
+
2155
+ </div>
2156
+ </div>
2157
+ <div class="tags">
2158
+ <p class="tag_title">Parameters:</p>
2159
+ <ul class="param">
2160
+
2161
+ <li>
2162
+
2163
+ <span class='name'>collection</span>
2164
+
2165
+
2166
+ <span class='type'>(<tt>Array|ActiveRecord::Relation</tt>)</span>
2167
+
2168
+
2169
+
2170
+ &mdash;
2171
+ <div class='inline'>
2172
+ <p>the will_paginate collection.</p>
2173
+ </div>
2174
+
2175
+ </li>
2176
+
2177
+ <li>
2178
+
2179
+ <span class='name'>to_update</span>
2180
+
2181
+
2182
+ <span class='type'>(<tt>String</tt>)</span>
2183
+
2184
+
2185
+
2186
+ &mdash;
2187
+ <div class='inline'>
2188
+ <p>the selector to use to update the content - either a “.class” or “#id”
2189
+ selector.</p>
2190
+ </div>
2191
+
2192
+ </li>
2193
+
2194
+ <li>
2195
+
2196
+ <span class='name'>options</span>
2197
+
2198
+
2199
+ <span class='type'>(<tt>Hash</tt>)</span>
2200
+
2201
+
2202
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
2203
+
2204
+
2205
+ &mdash;
2206
+ <div class='inline'>
2207
+ <p>options passed through to will_paginate</p>
2208
+ </div>
2209
+
2210
+ </li>
2211
+
2212
+ </ul>
2213
+
2214
+ <p class="tag_title">Returns:</p>
2215
+ <ul class="return">
2216
+
2217
+ <li>
2218
+
2219
+
2220
+ <span class='type'>(<tt>String</tt>)</span>
2221
+
2222
+
2223
+
2224
+ </li>
2225
+
2226
+ </ul>
2227
+
2228
+ </div><table class="source_code">
2229
+ <tr>
2230
+ <td>
2231
+ <pre class="lines">
2232
+
2233
+
2234
+ 383
2235
+ 384
2236
+ 385
2237
+ 386
2238
+ 387
2239
+ 388
2240
+ 389
2241
+ 390
2242
+ 391
2243
+ 392
2244
+ 393
2245
+ 394
2246
+ 395
2247
+ 396</pre>
2248
+ </td>
2249
+ <td>
2250
+ <pre class="code"><span class="info file"># File 'lib/jqr-helpers/helpers.rb', line 383</span>
2251
+
2252
+ <span class='kw'>def</span> <span class='id identifier rubyid_will_paginate_ajax'>will_paginate_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_collection'>collection</span><span class='comma'>,</span> <span class='id identifier rubyid_to_update'>to_update</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
2253
+ <span class='kw'>if</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='const'>AjaxLinkRenderer</span><span class='rparen'>)</span>
2254
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:data-type</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>html</span><span class='tstring_end'>'</span></span>
2255
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:data-result-method</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>update</span><span class='tstring_end'>'</span></span>
2256
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:data-selector</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_to_update'>to_update</span>
2257
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:data-remote</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
2258
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:data-scroll-to</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
2259
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:data-throbber</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:throbber</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>large</span><span class='tstring_end'>'</span></span>
2260
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:renderer</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='const'>AjaxLinkRenderer</span>
2261
+ <span class='id identifier rubyid_will_paginate'>will_paginate</span><span class='lparen'>(</span><span class='id identifier rubyid_collection'>collection</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
2262
+ <span class='kw'>else</span>
2263
+ <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>will_paginate not installed!</span><span class='tstring_end'>'</span></span>
2264
+ <span class='kw'>end</span>
2265
+ <span class='kw'>end</span></pre>
2266
+ </td>
2267
+ </tr>
2268
+ </table>
2110
2269
  </div>
2111
2270
 
2112
2271
  </div>
@@ -2114,7 +2273,7 @@ URL).</p>
2114
2273
  </div>
2115
2274
 
2116
2275
  <div id="footer">
2117
- Generated on Tue Dec 31 12:22:36 2013 by
2276
+ Generated on Fri Jan 3 15:22:08 2014 by
2118
2277
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
2119
2278
  0.8.7.3 (ruby-1.9.3).
2120
2279
  </div>
@@ -92,7 +92,7 @@
92
92
  <dt id="VERSION-constant" class="">VERSION =
93
93
 
94
94
  </dt>
95
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1.0.18</span><span class='tstring_end'>'</span></span></pre></dd>
95
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1.0.19</span><span class='tstring_end'>'</span></span></pre></dd>
96
96
 
97
97
  </dl>
98
98
 
@@ -108,7 +108,7 @@
108
108
  </div>
109
109
 
110
110
  <div id="footer">
111
- Generated on Tue Dec 31 12:22:36 2013 by
111
+ Generated on Fri Jan 3 15:22:08 2014 by
112
112
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
113
113
  0.8.7.3 (ruby-1.9.3).
114
114
  </div>
@@ -114,7 +114,7 @@
114
114
  </div>
115
115
 
116
116
  <div id="footer">
117
- Generated on Tue Dec 31 12:22:36 2013 by
117
+ Generated on Fri Jan 3 15:22:08 2014 by
118
118
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
119
119
  0.8.7.3 (ruby-1.9.3).
120
120
  </div>
data/doc/JqrHelpers.html CHANGED
@@ -110,7 +110,7 @@
110
110
  </div>
111
111
 
112
112
  <div id="footer">
113
- Generated on Tue Dec 31 12:22:36 2013 by
113
+ Generated on Fri Jan 3 15:22:08 2014 by
114
114
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
115
115
  0.8.7.3 (ruby-1.9.3).
116
116
  </div>
data/doc/_index.html CHANGED
@@ -174,7 +174,7 @@
174
174
  </div>
175
175
 
176
176
  <div id="footer">
177
- Generated on Tue Dec 31 12:22:36 2013 by
177
+ Generated on Fri Jan 3 15:22:08 2014 by
178
178
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
179
179
  0.8.7.3 (ruby-1.9.3).
180
180
  </div>
data/doc/index.html CHANGED
@@ -174,7 +174,7 @@
174
174
  </div>
175
175
 
176
176
  <div id="footer">
177
- Generated on Tue Dec 31 12:22:36 2013 by
177
+ Generated on Fri Jan 3 15:22:08 2014 by
178
178
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
179
179
  0.8.7.3 (ruby-1.9.3).
180
180
  </div>
data/doc/method_list.html CHANGED
@@ -149,6 +149,12 @@
149
149
  </li>
150
150
 
151
151
 
152
+ <li class="r2 ">
153
+ <span class='object_link'><a href="JqrHelpers/Helpers.html#will_paginate_ajax-instance_method" title="JqrHelpers::Helpers#will_paginate_ajax (method)">#will_paginate_ajax</a></span>
154
+ <small>JqrHelpers::Helpers</small>
155
+ </li>
156
+
157
+
152
158
  </ul>
153
159
  </div>
154
160
  </body>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Tue Dec 31 12:22:36 2013 by
106
+ Generated on Fri Jan 3 15:22:08 2014 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.7.3 (ruby-1.9.3).
109
109
  </div>
data/jqr-helpers.gemspec CHANGED
@@ -1,8 +1,8 @@
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.18'
5
- s.date = '2013-12-31'
4
+ s.version = '1.0.19'
5
+ s.date = '2014-01-03'
6
6
  s.summary = 'Helpers to print unobtrusive jQuery-UI tags.'
7
7
  s.description = <<-EOF
8
8
  This gem adds helper methods to create unobtrusive jQuery code. It outputs
@@ -15,6 +15,7 @@ EOF
15
15
  s.files = `git ls-files`.split($/)
16
16
  s.homepage = 'https://github.com/wishabi/jqr-helpers'
17
17
  s.license = 'MIT'
18
+ s.requirements << 'Optionally install will_paginate to allow Ajax pagination'
18
19
 
19
20
  s.add_dependency 'rails', '>= 3.0'
20
21
  s.add_development_dependency 'yard'
@@ -137,6 +137,8 @@ module JqrHelpers
137
137
  dialog_options = html_content
138
138
  html_content = capture(&block)
139
139
  end
140
+ html_options[:'data-throbber'] =
141
+ dialog_options.delete(:throbber) || 'large'
140
142
 
141
143
  html_options[:'data-dialog-url'] = url
142
144
  link_to_dialog(Helpers._random_string, html_content,
@@ -312,6 +314,89 @@ module JqrHelpers
312
314
  SecureRandom.hex(16)
313
315
  end
314
316
 
317
+ # Only run this code if will_paginate is installed
318
+ begin
319
+ require 'will_paginate/view_helpers'
320
+ require 'will_paginate/view_helpers/action_view'
321
+
322
+ # Define a link renderer to use with will_paginate.
323
+ class AjaxLinkRenderer < WillPaginate::ActionView::LinkRenderer
324
+
325
+ # Returns the subset of +options+ this instance was initialized with
326
+ # that represent HTML attributes for the container element of pagination
327
+ # links.
328
+ def container_attributes
329
+ @container_attributes ||=
330
+ @options.except(*(WillPaginate::ViewHelpers.pagination_options.keys +
331
+ _ajax_keys + [:renderer] - [:class]))
332
+ end
333
+
334
+ protected
335
+
336
+ def page_number(page)
337
+ ajax_options = @options.slice(*_ajax_keys)
338
+ if page == current_page
339
+ tag(:em, page, :class => 'current')
340
+ else
341
+ link(page, page,
342
+ ajax_options.merge(:class => 'ujs-ajax', :rel => rel_value(page)))
343
+ end
344
+ end
345
+
346
+ def previous_or_next_page(page, text, classname)
347
+ ajax_options = @options.slice(*_ajax_keys)
348
+ if page
349
+ link(text, page,
350
+ ajax_options.merge(:class => "#{classname} ujs-ajax"))
351
+ else
352
+ tag(:span, text,
353
+ ajax_options.merge(:class => "#{classname} disabled"))
354
+ end
355
+ end
356
+
357
+ private
358
+
359
+ # Option keys used exclusively for jqr-helpers Ajax stuff.
360
+ # @return [Array<Symbol>]
361
+ def _ajax_keys
362
+ [
363
+ :'data-type',
364
+ :'data-result-method',
365
+ :'data-selector',
366
+ :'data-remote',
367
+ :'data-scroll-to',
368
+ :'data-throbber'
369
+ ]
370
+ end
371
+
372
+ end
373
+ rescue # no will_paginate installed
374
+ end
375
+
376
+ # Create a will_paginate pagination interface which runs via Ajax. If
377
+ # will_paginate is not in the Gemfile or gem environment, this will
378
+ # throw an error.
379
+ # @param collection [Array|ActiveRecord::Relation] the
380
+ # will_paginate collection.
381
+ # @param to_update [String] the selector to use to update the content -
382
+ # either a ".class" or "#id" selector.
383
+ # @param options [Hash] options passed through to will_paginate
384
+ # @return [String]
385
+ def will_paginate_ajax(collection, to_update, options={})
386
+ if defined?(AjaxLinkRenderer)
387
+ options[:'data-type'] = 'html'
388
+ options[:'data-result-method'] = 'update'
389
+ options[:'data-selector'] = to_update
390
+ options[:'data-remote'] = true
391
+ options[:'data-scroll-to'] = true
392
+ options[:'data-throbber'] = options[:throbber] || 'large'
393
+ options[:renderer] = AjaxLinkRenderer
394
+ will_paginate(collection, options)
395
+ else
396
+ raise 'will_paginate not installed!'
397
+ end
398
+ end
399
+
315
400
  private
316
401
 
317
402
  # @param format [String] the Rails date format to map
@@ -368,6 +453,8 @@ module JqrHelpers
368
453
  new_options[:'data-close-dialog'] = options.delete(:close_dialog)
369
454
  new_options[:'data-use-dialog-opener'] = options.delete(:use_dialog_opener)
370
455
  new_options[:'data-refresh'] = true if options.delete(:refresh)
456
+ new_options[:'data-scroll-to'] = true if options.delete(:scroll_to)
457
+ new_options[:'data-throbber'] = options.delete(:throbber) || 'small'
371
458
 
372
459
  [:update, :append, :delete].each do |result_method|
373
460
  selector = options.delete(result_method)
@@ -1,5 +1,5 @@
1
1
  module JqrHelpers
2
2
  module Rails
3
- VERSION = '1.0.18'
3
+ VERSION = '1.0.19'
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: jqr-helpers
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.18
5
+ version: 1.0.19
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Orner
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-31 00:00:00.000000000 Z
12
+ date: 2014-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -56,6 +56,7 @@ files:
56
56
  - Readme.md
57
57
  - app/assets/images/jqr-helpers/close.png
58
58
  - app/assets/images/jqr-helpers/throbber.gif
59
+ - app/assets/images/jqr-helpers/throbber_large.gif
59
60
  - app/assets/javascripts/jqr-helpers.js
60
61
  - app/assets/stylesheets/jqr-helpers.css
61
62
  - doc/JqrHelpers.html
@@ -105,7 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  - - ! '>='
106
107
  - !ruby/object:Gem::Version
107
108
  version: '0'
108
- requirements: []
109
+ requirements:
110
+ - Optionally install will_paginate to allow Ajax pagination
109
111
  rubyforge_project:
110
112
  rubygems_version: 1.8.25
111
113
  signing_key: