forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixDialogButtons.coffee
More file actions
38 lines (34 loc) · 1.35 KB
/
Copy pathfixDialogButtons.coffee
File metadata and controls
38 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
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
define [
'jquery'
'underscore'
'compiled/fn/preventDefault'
'jqueryui/dialog'
], ($, _, preventDefault) ->
$.fn.fixDialogButtons = ->
this.each ->
$dialog = $(this)
$buttons = $dialog.find(".button-container:last .btn, button[type=submit]")
if $buttons.length
$dialog.find(".button-container:last, button[type=submit]").hide()
buttons = $.map $buttons.toArray(), (button) ->
$button = $(button)
classes = $button.attr('class') ? ''
id = $button.attr('id')
# if you add the class 'dialog_closer' to any of the buttons,
# clicking it will cause the dialog to close
if $button.is('.dialog_closer')
$button.off '.fixdialogbuttons'
$button.on 'click.fixdialogbuttons', preventDefault -> $dialog.dialog('close')
if $button.prop('type') is 'submit' && $button[0].form
classes += ' button_type_submit'
return {
text: $button.text()
"data-text-while-loading": $button.data("textWhileLoading")
click: -> $button.click()
class: classes
id: id
}
# put the primary button(s) on the far right
buttons = _.sortBy buttons, (button) ->
if button.class.match(/btn-primary/) then 1 else 0
$dialog.dialog "option", "buttons", buttons