PageSourceSearch

https://bhalat.com.ua/bitrix/js/api.core/alert.js?17653593367820

js bhalat.com.ua collected 2026-10-07 19:42:12 UTC 7,820 bytes, 263 lines download raw bytes

1/*!
2 * $.fn.apiAlert
3 */
4(function ($, undefined ) {
5
6	"use strict"; // Hide scope, no $ conflict
7
8	var defaults = {
9		type: 'alert', //['confirm','prompt']
10		class: 'info', //['info', 'error', 'warning', 'success']
11		//single: true,
12		close: true,
13		theme: 'default', //['jbox', 'noty', 'sweetalert', 'dark', 'uikit2', 'bootstrap4']
14		title: '',
15		content: '',
16		width: 350,
17		timeout: 0,
18		showIcon: false,
19		hideButtons: false,
20		labels: {
21			ok: 'OK',
22			cancel: 'Cancel',
23		},
24		header: {
25			text: '',
26			align: 'center', //left|center|right
27		},
28		footer: {
29			text: '',
30			align: 'center', //left|center|right
31		},
32		input: {
33			class: '',
34			text: '',
35			placeholder: ''
36		},
37		form: {
38			text: '',
39		},
40		load: {
41			url: '',
42			data: {},
43			callback: function (responseText, textStatus, jqXHR) {
44				//console.info(responseText);
45				//console.info(textStatus);
46			}
47		},
48		callback: {
49			onConfirm: function (isConfirm) {
50				console.info('isConfirm', isConfirm);
51			},
52			onPrompt: function (isPrompt, data) {
53				data = data || {};
54				console.info('isPrompt', isPrompt);
55				console.info('isPromptData', data);
56			},
57			onShow: function () {}, //TODO
58			onClose: function () {},//TODO
59		}
60	};
61
62	var methods = {
63
64		init: function (params) {
65
66			var $html = $('html');
67			var options = $.extend(true, {}, defaults, params);
68
69			if (!this.data('apiAlert')) {
70				this.data('apiAlert', options);
71
72				// код плагина
73				if (options.type === 'confirm') {
74					//if(!options.title)
75					//options.title = 'Are you sure?';
76				}
77
78				if (!$html.hasClass('api-alert-init'))
79					$html.addClass('api-alert-init');
80
81				//api_alert_alert
82				$html.addClass('api_alert_active');
83
84				if (!$('.api_alert_overlay').length) {
85					$('body').append('<div class="api_alert_overlay"/>');
86				}
87
88				var html = '';
89				var alertId = '#apiAlert' + ($('.api_alert').length + 1);
90
91				html += '<div id="' + alertId.replace('#', '') + '" class="api_alert api_alert_' + options.class + ' api_alert_theme_' + options.theme + ' api_alert_type_' + options.type + '">';
92				html += '<div class="api_alert_dialog">';
93				html += '<div class="api_alert_close api_icon_close">&#10005;</div>';
94
95				if (options.header.text.length) {
96					html += '<div class="api_alert_header" style="text-align: ' + options.header.align + '">' + options.header.text + '</div>';
97				}
98
99				//start content
100				html += '<div class="api_alert_content">';
101
102				if (options.showIcon) {
103					html += '<div class="api_alert_icon"></div>';
104				}
105
106				if (options.title.length) {
107					html += '<div class="api_title">' + options.title + '</div>';
108				}
109
110				//START content!!!
111				html += '<div class="api_content">' + options.content;
112
113				if (options.input.text.length) {
114					html += '<div class="api_input"><input type="text" value="' + options.input.text + '" class="' + options.input.class + '" placeholder="' + options.input.placeholder + '"></div>';
115				}
116
117				if (options.type === 'prompt') {
118					if (options.form.text.length) {
119						html += options.form.text;
120					}
121					else {
122						html += '<div class="api_input"><input type="text" value="' + options.input.text + '" class="' + options.input.class + '" placeholder="' + options.input.placeholder + '"></div>';
123					}
124				}
125
126				//{{buttons}}
127				if (!options.hideButtons)
128					html += '<div class="api_buttons">{{buttons}}</div>';
129
130				//END content!!!
131				html += '</div>';
132
133				if (options.footer.text.length) {
134					html += '<div class="api_alert_footer" style="text-align: ' + options.footer.align + '">' + options.footer.text + '</div>';
135				}
136
137				html += '</div>';
138				html += '</div>';
139
140				//Replace buttons
141				switch (options.type) {
142					case "confirm":
143						html = html.replace("{{buttons}}", '<button type="button" class="api_button api_button_primary api_alert_confirm">{{ok}}</button><button type="button" class="api_button api_alert_close">{{cancel}}</button>');
144						html = html.replace("{{ok}}", options.labels.ok).replace("{{cancel}}", options.labels.cancel);
145						break;
146					case "prompt":
147						html = html.replace("{{buttons}}", '<button type="button" class="api_button api_button_primary api_alert_prompt">{{ok}}</button><button type="button" class="api_button api_alert_close">{{cancel}}</button>');
148						html = html.replace("{{ok}}", options.labels.ok).replace("{{cancel}}", options.labels.cancel);
149						break;
150					case "alert":
151					default:
152						html = html.replace("{{buttons}}", '<button type="button" class="api_button api_button_primary api_alert_close">{{ok}}</button>');
153						html = html.replace("{{ok}}", options.labels.ok);
154						break;
155				}
156
157				//Show alert
158				$('body').append(html);
159				$(alertId).find('.api_alert_dialog').width(options.width);
160				$(alertId).show();
161
162				options.id = alertId;
163				$.fn.apiAlert('resize', options);
164
165				$(window).on('resize', function () {
166					$.fn.apiAlert('resize', options);
167				});
168
169				//close
170				$(alertId).on('click', '.api_alert_close', function () {
171					if (options.type === 'confirm') {
172						options.callback.onConfirm.call(options, false);
173					}
174					methods.close(alertId);
175				});
176
177				//confirm
178				$(alertId).on('click', '.api_alert_confirm', function () {
179					options.callback.onConfirm.call(options, true);
180					if (options.close) {
181						methods.close(alertId);
182					}
183				});
184
185				//prompt
186				$(alertId).on('click', '.api_alert_prompt', function () {
187
188					var promptData = {};
189					var promptForm = $(alertId + ' form');
190					var promptInput = $(alertId + ' input[type=text]');
191
192					if (promptForm.length)
193						promptData = promptForm.serializeArray();
194					else if (promptInput.length)
195						promptData = promptInput.val();
196
197					options.callback.onPrompt.call(options, true, promptData);
198					if (options.close) {
199						methods.close(alertId);
200					}
201				});
202
203				//$.load()
204				if (options.load.url.length) {
205					$(alertId).find('.api_content').html('<div class="api_alert_busy"></div>');
206					$(alertId).find('.api_alert_header, .api_alert_footer').hide();
207
208					$(alertId).find('.api_content').load(
209						 options.load.url,
210						 options.load.data,
211						 function (responseText, textStatus, jqXHR) {
212							 $(alertId).find('.api_alert_header, .api_alert_footer').show();
213							 $.fn.apiAlert('resize', options);
214							 options.load.callback.call(options, responseText, textStatus, jqXHR);
215						 }
216					);
217				}
218
219			}
220
221			return this;
222		},
223		close: function (alertId) {
224			$(alertId).hide().remove();
225			if (!$('.api_alert').length) {
226				$('.api_alert_overlay').hide().remove();
227				$('html').removeClass('api_alert_active');
228			}
229		},
230		resize: function (options) {
231
232			var dialog = options.id + ' .api_alert_dialog';
233
234			var dh = $(dialog).outerHeight(),
235				 pad = parseInt($(dialog).css('margin-top'), 10) + parseInt($(dialog).css('margin-bottom'), 10);
236
237			if ((dh + pad) < window.innerHeight) {
238				$(dialog).css({top: (window.innerHeight - (dh + pad)) / 2});
239			} else {
240				$(dialog).css({top: ''}, 100);
241			}
242
243		},
244
245		showWait: function (alertId) {
246			$(alertId).find('.api_alert_content').append('<div class="api_alert_wait"></div>');
247		},
248		hideWait: function (alertId) {
249			$(alertId).find('.api_alert_wait').remove();
250		},
251	};
252
253	$.fn.apiAlert = function (method) {
254		if (methods[method]) {
255			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
256		} else if (typeof method === 'object' || !method) {
257			return methods.init.apply(this, arguments);
258		} else {
259			$.error('Error! Method "' + method + '" not found in plugin $.fn.apiAlert');
260		}
261	};
262
263})(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.