|
14 | 14 | // CONFIRMATION PUBLIC CLASS DEFINITION |
15 | 15 | // =============================== |
16 | 16 | var Confirmation = function (element, options) { |
| 17 | + options.trigger = 'click'; |
| 18 | + |
17 | 19 | this.init('confirmation', element, options); |
18 | 20 |
|
| 21 | + // keep trace of selectors |
| 22 | + this.options._isDelegate = false; |
| 23 | + if (options.selector) { // container of buttons |
| 24 | + this.options._selector = this._options._selector = options._root_selector +' '+ options.selector; |
| 25 | + } |
| 26 | + else if (options._selector) { // children of container |
| 27 | + this.options._selector = options._selector; |
| 28 | + this.options._isDelegate = true; |
| 29 | + } |
| 30 | + else { // standalone |
| 31 | + this.options._selector = options._root_selector; |
| 32 | + } |
| 33 | + |
19 | 34 | var that = this; |
20 | 35 |
|
21 | 36 | if (!this.options.selector) { |
22 | | - // get existing href and target |
23 | | - if (this.$element.attr('href')) { |
24 | | - this.options.href = this.$element.attr('href'); |
25 | | - this.$element.removeAttr('href'); |
26 | | - if (this.$element.attr('target')) { |
27 | | - this.options.target = this.$element.attr('target'); |
| 37 | + // store copied attributes |
| 38 | + this.options._attributes = {}; |
| 39 | + if (this.options.copyAttributes) { |
| 40 | + if (typeof this.options.copyAttributes === 'string') { |
| 41 | + this.options.copyAttributes = this.options.copyAttributes.split(' '); |
28 | 42 | } |
29 | 43 | } |
| 44 | + else { |
| 45 | + this.options.copyAttributes = []; |
| 46 | + } |
| 47 | + |
| 48 | + this.options.copyAttributes.forEach(function(attr) { |
| 49 | + this.options._attributes[attr] = this.$element.attr(attr); |
| 50 | + }, this); |
30 | 51 |
|
31 | 52 | // cancel original event |
32 | 53 | this.$element.on(that.options.trigger, function(e, ack) { |
|
60 | 81 | if ($(that.options._selector).is(e.target)) { |
61 | 82 | return; |
62 | 83 | } |
63 | | - |
| 84 | + |
64 | 85 | // close all popover already initialized |
65 | 86 | $(that.options._selector).filter(function() { |
66 | 87 | return $(this).data('bs.confirmation') !== undefined; |
|
78 | 99 | placement: 'top', |
79 | 100 | title: 'Are you sure?', |
80 | 101 | html: true, |
81 | | - href: false, |
82 | 102 | popout: false, |
83 | 103 | singleton: false, |
84 | | - target: '_self', |
| 104 | + copyAttributes: 'href target', |
85 | 105 | onConfirm: $.noop, |
86 | 106 | onCancel: $.noop, |
87 | 107 | btnOkClass: 'btn-xs btn-primary', |
|
111 | 131 | return Confirmation.DEFAULTS; |
112 | 132 | }; |
113 | 133 |
|
114 | | - // custom init keeping trace of selectors |
115 | | - Confirmation.prototype.init = function(type, element, options) { |
116 | | - options.trigger = 'click'; |
117 | | - |
118 | | - $.fn.popover.Constructor.prototype.init.call(this, type, element, options); |
119 | | - |
120 | | - this.options._isDelegate = false; |
121 | | - if (options.selector) { // container of buttons |
122 | | - this.options._selector = this._options._selector = options._root_selector +' '+ options.selector; |
123 | | - } |
124 | | - else if (options._selector) { // children of container |
125 | | - this.options._selector = options._selector; |
126 | | - this.options._isDelegate = true; |
127 | | - } |
128 | | - else { // standalone |
129 | | - this.options._selector = options._root_selector; |
130 | | - } |
131 | | - }; |
132 | | - |
133 | 134 | Confirmation.prototype.setContent = function () { |
134 | 135 | var that = this, |
135 | 136 | $tip = this.tip(), |
|
141 | 142 | $tip.find('[data-apply="confirmation"]') |
142 | 143 | .addClass(o.btnOkClass) |
143 | 144 | .html(o.btnOkLabel) |
| 145 | + .attr(this.options._attributes) |
144 | 146 | .prepend($('<i></i>').addClass(o.btnOkIcon), ' ') |
145 | 147 | .off('click') |
146 | 148 | .one('click', function(e) { |
|
150 | 152 | that.$element.confirmation('hide'); |
151 | 153 | }); |
152 | 154 |
|
153 | | - // add href to confirm button if needed |
154 | | - if (o.href && o.href != "#") { |
155 | | - $tip.find('[data-apply="confirmation"]').attr({ |
156 | | - href: o.href, |
157 | | - target: o.target |
158 | | - }); |
159 | | - } |
160 | | - |
161 | 155 | // configure 'cancel' button |
162 | 156 | $tip.find('[data-dismiss="confirmation"]') |
163 | 157 | .addClass(o.btnCancelClass) |
|
0 commit comments