Module: Card::Set::All::RichHtml::Modal::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod021-standard/all/rich_html/modal.rb

Constant Summary collapse

{ small: "sm", medium: nil, large: "lg", full: "full" }.freeze
{ class: "_close-modal", "data-dismiss": "modal",
"data-cy": "close-modal" }.freeze

Instance Method Summary collapse

Instance Method Details

#add_modal_size_class(classes, size) ⇒ Object



106
107
108
109
110
111
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 106

def add_modal_size_class classes, size
  size = normalize_modal_size_class size
  return if size == :medium || size.blank?

  classes << "modal-#{MODAL_SIZE[size]}"
end

#cast_model_option(val) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 27

def cast_model_option val
  case val
  when Symbol
    cast_model_option_symbol val
  when Proc
    val.call(self)
  else
    val
  end
end

#cast_model_option_symbol(val) ⇒ Object



38
39
40
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 38

def cast_model_option_symbol val
  respond_to?(val) ? send(val) : val
end

#close_modal_windowObject



117
118
119
120
121
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 117

def close_modal_window
  link_to icon_tag(:close), path: "",
                            class: "_close-modal close",
                            "data-dismiss": "modal"
end


50
51
52
53
54
55
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 50

def modal_close_button link_text="Close", opts={}
  classes = opts.delete(:class)
  button_opts = opts.merge(MODAL_CLOSE_OPTS)
  add_class button_opts, classes if classes
  button_tag link_text, button_opts
end


97
98
99
100
101
102
103
104
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 97

def modal_dialog_classes opts
  classes = [classy("modal-dialog")]
  return classes unless opts.present?

  add_modal_size_class classes, opts.delete(:size)
  classes << "modal-dialog-centered" if opts.delete(:vertically_centered)
  classes.join " "
end


82
83
84
85
86
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 82

def modal_link text=nil, opts={}
  opts = modal_link_opts(opts)
  opts[:path][:layout] ||= :modal
  link_to text, opts
end


88
89
90
91
92
93
94
95
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 88

def modal_link_opts opts
  add_class opts, "slotter"
  opts.reverse_merge! path: {},
                      "data-slotter-mode": "modal",
                      "data-modal-class": modal_dialog_classes(opts),
                      remote: true
  opts
end


57
58
59
60
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 57

def modal_submit_button opts={}
  add_class opts, "submit-button _close-modal"
  submit_button opts
end

#normalize_modal_option(key, opts) ⇒ Object



21
22
23
24
25
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 21

def normalize_modal_option key, opts
  val = opts[key]
  return render("modal_#{key}") unless val
  cast_model_option val
end

#normalize_modal_size_class(size) ⇒ Object



113
114
115
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 113

def normalize_modal_size_class size
  size.in?(MODAL_SIZE.keys) ? size : cast_model_option(size)
end

#pop_out_modal_windowObject



123
124
125
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 123

def pop_out_modal_window
  link_to icon_tag(:new_window), path: {}, class: "pop-out-modal close"
end


46
47
48
# File 'tmpsets/set/mod021-standard/all/rich_html/modal.rb', line 46

def show_in_modal_link link_text, body
  link_to_view :modal, link_text, "data-modal-body": body, "data-slotter-mode": "modal"
end