Module: Sweetify::SweetAlert
- Defined in:
- lib/sweetify/sweetalert.rb
Instance Method Summary collapse
-
#sweetalert(text, title = '', opts = {}) ⇒ Object
Display an alert with a text and an optional title Default without an specific type.
-
#sweetalert_error(text, title = '', opts = {}) ⇒ Object
Error Alert.
-
#sweetalert_info(text, title = '', opts = {}) ⇒ Object
Information Alert.
-
#sweetalert_success(text, title = '', opts = {}) ⇒ Object
Success Alert.
-
#sweetalert_warning(text, title = '', opts = {}) ⇒ Object
Warning Alert.
Instance Method Details
#sweetalert(text, title = '', opts = {}) ⇒ Object
Display an alert with a text and an optional title Default without an specific type
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sweetify/sweetalert.rb', line 9 def sweetalert(text, title = '', opts = {}) opts = { showConfirmButton: false, timer: 2000, allowOutsideClick: true, confirmButtonText: 'OK' }.merge(opts) opts[:text] = text opts[:title] = title if opts[:button] opts[:showConfirmButton] = true opts[:confirmButtonText] = opts[:button] if opts[:button].is_a?(String) opts.delete(:button) end if opts[:persistent] opts[:showConfirmButton] = true opts[:allowOutsideClick] = false opts[:timer] = nil opts[:confirmButtonText] = opts[:persistent] if opts[:persistent].is_a?(String) opts.delete(:persistent) end # sweetalert changes if Sweetify.sweetalert_library == 'sweetalert' opts[:icon] = opts.delete(:type) opts[:closeOnClickOutside] = opts.delete(:allowOutsideClick) if opts.delete(:showConfirmButton) opts[:button] = opts[:confirmButtonText] else opts[:button] = false end end flash_config(opts) end |
#sweetalert_error(text, title = '', opts = {}) ⇒ Object
Error Alert
76 77 78 79 |
# File 'lib/sweetify/sweetalert.rb', line 76 def sweetalert_error(text, title = '', opts = {}) opts[:type] = :error sweetalert(text, title, opts) end |
#sweetalert_info(text, title = '', opts = {}) ⇒ Object
Information Alert
56 57 58 59 |
# File 'lib/sweetify/sweetalert.rb', line 56 def sweetalert_info(text, title = '', opts = {}) opts[:type] = :info sweetalert(text, title, opts) end |
#sweetalert_success(text, title = '', opts = {}) ⇒ Object
Success Alert
66 67 68 69 |
# File 'lib/sweetify/sweetalert.rb', line 66 def sweetalert_success(text, title = '', opts = {}) opts[:type] = :success sweetalert(text, title, opts) end |
#sweetalert_warning(text, title = '', opts = {}) ⇒ Object
Warning Alert
86 87 88 89 |
# File 'lib/sweetify/sweetalert.rb', line 86 def sweetalert_warning(text, title = '', opts = {}) opts[:type] = :warning sweetalert(text, title, opts) end |