Skip to content

Commit ee92fdf

Browse files
committed
support inline display of the dialog
1 parent 9a33735 commit ee92fdf

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ Use :allow_blank for a "not recurring" option:
5252
f.select_recurring :current_existing_rule, nil, :allow_blank => true
5353
```
5454

55+
Use :data attribute to position the recurring select dialog inline (after the select input):
56+
57+
```ruby
58+
f.select_recurring :current_existing_rule, nil, { :allow_blank => true }, { data: { recurring_select_position: 'inline' } }
59+
```
60+
5561

5662
### Additional Helpers
5763

app/assets/javascripts/recurring_select_dialog.js.coffee.erb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@ window.RecurringSelectDialog =
22
class RecurringSelectDialog
33
constructor: (@recurring_selector) ->
44
@current_rule = @recurring_selector.recurring_select('current_rule')
5+
@position = @recurring_selector.data('recurring-select-position') ? 'fixed'
6+
57
@initDialogBox()
68
if not @current_rule.hash? or not @current_rule.hash.rule_type?
79
@freqChanged()
8-
else
10+
else if @position != 'inline'
911
setTimeout @positionDialogVert, 10 # allow initial render
1012

13+
if @position != 'fixed'
14+
$('body').on 'click.recurring_select_cancel', (e) =>
15+
unless $(e.target).closest('.rs_dialog_content').length
16+
@cancel(e)
17+
$('body').off('click.recurring_select_cancel')
18+
19+
1120
initDialogBox: ->
1221
$(".rs_dialog_holder").remove()
1322

14-
open_in = $("body")
23+
open_in = if @position == 'inline'
24+
@recurring_selector.parent()
25+
else
26+
$("body")
27+
1528
open_in = $(".ui-page-active") if $(".ui-page-active").length
1629
open_in.append @template()
1730
@outer_holder = $(".rs_dialog_holder")
31+
@outer_holder.addClass @position
1832
@inner_holder = @outer_holder.find ".rs_dialog"
1933
@content = @outer_holder.find ".rs_dialog_content"
20-
@positionDialogVert(true)
34+
@positionDialogVert(true) unless @position == 'inline'
2135
@mainEventInit()
2236
@freqInit()
2337
@summaryInit()
@@ -49,7 +63,8 @@ window.RecurringSelectDialog =
4963
@content.css {"width": "auto"}
5064
@inner_holder.trigger "recurring_select:dialog_positioned"
5165

52-
cancel: =>
66+
cancel: (e) =>
67+
e.preventDefault() if e
5368
@outer_holder.remove()
5469
@recurring_selector.recurring_select('cancel')
5570

@@ -250,7 +265,7 @@ window.RecurringSelectDialog =
250265
@current_rule.str = $.fn.recurring_select.texts["daily"]
251266
@initDailyOptions()
252267
@summaryUpdate()
253-
@positionDialogVert()
268+
@positionDialogVert() unless @position == 'inline'
254269

255270
intervalChanged: (event) =>
256271
@current_rule.str = null

app/assets/stylesheets/recurring_select.scss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ select {
2828
option.bold {font-weight:bold; color:red;}
2929
}
3030

31-
.rs_dialog_holder { position:fixed; left:0px; right:0px; top:0px; bottom:0px; padding-left:50%; background-color:rgba(255,255,255,0.2); z-index:50;
31+
.rs_dialog_holder {
32+
background-color:rgba(255,255,255,0.2);
33+
34+
&.fixed {
35+
position:fixed; left:0px; right:0px; top:0px; bottom:0px; padding-left:50%; z-index:50;
36+
.rs_dialog { margin-left:-125px; }
37+
}
38+
3239
.rs_dialog { background-color:#f6f6f6; border:1px solid #acacac; @include shadows(1px, 3px, 8px, rgba(0,0,0,0.25)); @include rounded_corners(7px);
33-
display:inline-block; min-width:200px; margin-left:-125px; overflow:hidden; position:relative;
40+
display:inline-block; min-width:200px; overflow:hidden; position:relative;
3441
.rs_dialog_content { padding:10px;
3542
h1 { font-size:16px; padding:0px; margin:0 0 10px 0;
3643
a {float:right; display:inline-block; height:16px; width:16px; background-image:image-url("recurring_select/cancel.png"); background-position:center; background-repeat:no-repeat;}

0 commit comments

Comments
 (0)