PageSourceSearch

https://oceanexpert.net/js/bootstrap-confirmation.js

js oceanexpert.net collected 2026-10-02 18:20:01 UTC 7,455 bytes, 276 lines download raw bytes

1/* ===========================================================
2 * bootstrap-confirmation.js v1.0.1
3 * http://ethaizone.github.io/Bootstrap-Confirmation/
4 * ===========================================================
5 * Copyright 2013 Nimit Suwannagate <[email protected]>
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * =========================================================== */
19
20
21!function ($) {
22
23	"use strict"; // jshint ;_;
24
25
26 /* CONFIRMATION PUBLIC CLASS DEFINITION
27	* =============================== */
28
29	//var for check event at body can have only one.
30	var event_body = false;
31
32	var Confirmation = function (element, options) {
33		var that = this;
34
35		// remove href attribute of button
36		$(element).removeAttr('href')
37
38		this.init('confirmation', element, options)
39
40		$(element).on('show', function(e) {
41			var options = that.options;
42			var all = options.all_selector;
43			if(options.singleton) {
44				$(all).not(that.$element).confirmation('hide');
45			}
46		});
47
48		$(element).on('shown', function(e) {
49			var options = that.options;
50			var all = options.all_selector;
51			$(this).next('.popover').one('click.dismiss.confirmation', '[data-dismiss="confirmation"]', $.proxy(that.hide, that))
52			if(that.isPopout()) {
53				if(!event_body) {
54					event_body = $('body').on('click', function (e) {
55						if($(all).is(e.target)) return;
56						if($(all).has(e.target).length) return;
57						if($(all).next('div').has(e.target).length) return;
58
59						$(all).confirmation('hide');
60						$('body').unbind(e);
61						event_body = false;
62
63						return;
64					});
65				}
66			}
67		});
68	}
69
70
71	/* NOTE: CONFIRMATION EXTENDS BOOTSTRAP-TOOLTIP.js
72		 ========================================== */
73
74	Confirmation.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
75
76		constructor: Confirmation
77
78		, setContent: function () {
79				var $tip = this.tip()
80					, $btnOk = this.btnOk()
81					, $btnCancel = this.btnCancel()
82					, title = this.getTitle()
83					, href = this.getHref()
84					, target = this.getTarget()
85					, $e = this.$element
86					, btnOkClass = this.getBtnOkClass()
87					, btnCancelClass = this.getBtnCancelClass()
88					, btnOkLabel = this.getBtnOkLabel()
89					, btnCancelLabel = this.getBtnCancelLabel()
90					, o = this.options
91
92				$tip.find('.popover-title').text(title)
93
94				$btnOk.addClass(btnOkClass).html(btnOkLabel).attr('href', href).attr('target', target).on('click', o.onConfirm)
95				$btnCancel.addClass(btnCancelClass).html(btnCancelLabel).on('click', o.onCancel)
96
97				$tip.removeClass('fade top bottom left right in')
98			}
99
100		, hasContent: function () {
101				return this.getTitle()
102			}
103
104		, isPopout: function () {
105				var popout
106					, $e = this.$element
107					, o = this.options
108
109				popout = $e.attr('data-popout') || (typeof o.popout == 'function' ? o.popout.call($e[0]) :	o.popout)
110
111				if(popout == 'false') popout = false;
112
113				return popout
114			}
115
116
117		, getHref: function () {
118				var href
119					, $e = this.$element
120					, o = this.options
121
122				href = $e.attr('data-href') || (typeof o.href == 'function' ? o.href.call($e[0]) :	o.href)
123
124				return href
125			}
126
127		, getTarget: function () {
128				var target
129					, $e = this.$element
130					, o = this.options
131
132				target = $e.attr('data-target') || (typeof o.target == 'function' ? o.target.call($e[0]) :	o.target)
133
134				return target
135			}
136
137		, getBtnOkClass: function () {
138				var btnOkClass
139					, $e = this.$element
140					, o = this.options
141
142				btnOkClass = $e.attr('data-btnOkClass') || (typeof o.btnOkClass == 'function' ? o.btnOkClass.call($e[0]) :	o.btnOkClass)
143
144				return btnOkClass
145			}
146
147		, getBtnCancelClass: function () {
148				var btnCancelClass
149					, $e = this.$element
150					, o = this.options
151
152				btnCancelClass = $e.attr('data-btnCancelClass') || (typeof o.btnCancelClass == 'function' ? o.btnCancelClass.call($e[0]) :	o.btnCancelClass)
153
154				return btnCancelClass
155			}
156
157		, getBtnOkLabel: function () {
158				var btnOkLabel
159					, $e = this.$element
160					, o = this.options
161
162				btnOkLabel = $e.attr('data-btnOkLabel') || (typeof o.btnOkLabel == 'function' ? o.btnOkLabel.call($e[0]) :	o.btnOkLabel)
163
164				return btnOkLabel
165			}
166
167		, getBtnCancelLabel: function () {
168				var btnCancelLabel
169					, $e = this.$element
170					, o = this.options
171
172				btnCancelLabel = $e.attr('data-btnCancelLabel') || (typeof o.btnCancelLabel == 'function' ? o.btnCancelLabel.call($e[0]) :	o.btnCancelLabel)
173
174				return btnCancelLabel
175			}
176
177		, tip: function () {
178				this.$tip = this.$tip || $(this.options.template)
179				return this.$tip
180			}
181
182		, btnOk: function () {
183				var $tip = this.tip()
184				return $tip.find('.popover-content > div > a:not([data-dismiss="confirmation"])')
185			}
186
187		, btnCancel: function () {
188				var $tip = this.tip()
189				return $tip.find('.popover-content > div > a[data-dismiss="confirmation"]')
190			}
191
192		, hide: function () {
193				var $btnOk = this.btnOk()
194					, $btnCancel = this.btnCancel()
195
196				$.fn.tooltip.Constructor.prototype.hide.call(this)
197
198				$btnOk.off('click')
199				$btnCancel.off('click')
200
201				return this
202			}
203
204		, destroy: function () {
205				this.hide().$element.off('.' + this.type).removeData(this.type)
206			}
207
208        , setOptions: function (newOptions) {
209                this.options = $.extend({}, this.options, newOptions || {});
210			}
211
212	})
213
214
215 /* CONFIRMATION PLUGIN DEFINITION
216	* ======================= */
217
218	var old = $.fn.confirmation
219
220	$.fn.confirmation = function (option, param) {
221		var that = this
222		return this.each(function () {
223			var $this = $(this)
224				, data = $this.data('confirmation')
225				, options = typeof option == 'object' && option
226			options = options || {}
227			options.all_selector = that.selector
228			if (!data) $this.data('confirmation', (data = new Confirmation(this, options)))
229			if (typeof option == 'string') {
230                if (option === 'option') {
231                    data.setOptions(param)
232                } else {
233                    data[option]();
234                }
235            }
236		})
237	}
238
239	$.fn.confirmation.Constructor = Confirmation
240
241	$.fn.confirmation.defaults = $.extend({} , $.fn.tooltip.defaults, {
242		placement: 'top'
243		, trigger: 'click'
244		, target : '_self'
245		, href   : '#'
246		, title: 'Are you sure?'
247		, template: '<div class="popover">' +
248				'<div class="arrow"></div>' +
249				'<h3 class="popover-title"></h3>' +
250				'<div class="popover-content text-center">' +
251				'<div class="btn-group">' +
252				'<a class="btn btn-small" href="" target=""></a>' +
253				'<a class="btn btn-small" data-dismiss="confirmation"></a>' +
254				'</div>' +
255				'</div>' +
256				'</div>'
257		, btnOkClass:  'btn-primary'
258		, btnCancelClass:  ''
259		, btnOkLabel: '<i class="icon-ok-sign icon-white"></i> Yes'
260		, btnCancelLabel: '<i class="icon-remove-sign"></i>
260 No'
261		, singleton: false
262		, popout: false
263		, onConfirm: function(){}
264		, onCancel: function(){}
265	})
266
267
268 /* POPOVER NO CONFLICT
269	* =================== */
270
271	$.fn.confirmation.noConflict = function () {
272		$.fn.confirmation = old
273		return this
274	}
275
276}(window.jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.