PageSourceSearch

https://muzkom.ru/local/js/disAjaxWin/jquery.disAjaxWin.js?164540135413700

js muzkom.ru collected 2026-10-06 10:06:25 UTC 13,700 bytes, 491 lines download raw bytes

1/*! Copyright (c) 2012-2017 Алексеенко Сергей Александрович <[email protected]>
2 *
3 *
4 * Version: 2.4
5 *
6 * Методы вызова:
7 $.disAjaxWin("Урл скрипта",{options})
8 $(element).disAjaxWin("Урл скрипта",{options}) - Позиционирование будет по элементу
9
10 Опции:
11 id: "id окна" - Это если надо несколько окон одновременно (по умолчанию ничего)
12 title: "Заголовок окна"
13 width: "Ширина окна"
14 data: {param1:'value1', param2:'value2'} или 'param1=value1&param2=value2' - Данные для отправки POST (по умолчанию false, и запрос идет как GET);
15 shadow: "Y|N" - Показывать тень (По умолчанию Y)
16 close_on_shadow: "Y|N" - Закрывать или не закрывать окно по клику по тени (по умолчанию Y)
17 show_close: "Y|N" - Показыавать или не показыать кнопку закрытия окна (по умолчанию Y)
18 style: "name" - Наименование стиля окна (по умолчанию ничего - стандартное окно)
19 success:function(){} - функция после открытия окна, т.е после выполнения аякса
20 close:function(){} - функция после закрытия окна
21 confirmClose: "Текст" - Подтверждение закрытия окна
22 position: "center|top" - Позиция окна
23 preload_img_container: "string" - Изображение, которое должно быть загружено до отображения окна, для корректности расчетов положения окна
24 */
25(function($) {
26	var
27		id, //ID окна
28		style, //Стиль окна
29		disAjaxWin = [], //Объект окно
30		disAjaxWin_overlay = [], //Объект в котором находится окно
31		disAjaxWin_body = [], //Объект тело окна
32		disAjaxWin_close = [], //Объект кнопка закрытия окна
33		disAjaxWin_title = [], //Объект заголовок окна
34		disAjaxWinShadow = [], //Объект тень окна
35		disAjaxWinTemp, //Объект темп
36		disAjaxWinTemp_body, //Объект тело темп
37		disBlock = 0, //Блокировка
38		element, //Элемент по которорому позиционируется окно
39		top,
40		left,
41		scroll_top = 0,
42		arrOptions = [], // Массив опций
43		defaultOptions = {
44			id:"none_id",
45			data:false,
46			title:"",
47			width:"",
48			shadow:"Y",
49			close_on_shadow:"Y",
50			show_close: "N",
51			success:function(){},
52			close:function(){},
53			confirmClose:"",
54			content:"ajax",
55			remove:true,
56			overlay:true,
57			preload_img_container:"",
58			position:"center",
59			adapt_width: 0,
60			style: 'clear'
61		};
62
63	$.fn.disAjaxWin = function(content,options) {
64
65		options = $.extend({}, defaultOptions, options);
66		id = options.id;
67
68		if(content instanceof Object)
69		{
70			options.content = "object";
71			//options.remove = false;
72		}
73
74		arrOptions[id] = options;
75		if(arrOptions[id].style!=='') style = " "+arrOptions[id].style+"_disAjaxWin";
76
77		$.disAjaxWin.close(id);
78		$.disAjaxWin.init();
79
80		element = $(this);
81
82		$("body").addClass("loading");
83
84		if(options.content==="object")
85		{
86			$.disAjaxWin.content(id, content.clone().removeClass("hidden").show());
87			//content.remove();
88		}
89		else if(options.content==="html")
90		{
91			$.disAjaxWin.content(id,content);
92		}
93		else if(options.content==="ajax")
94		{
95			if (disBlock===1) return false;
96			disBlock = 1;
97
98			var type = "GET", data = false;
99			if(options.data) {
100				type = "POST";
101				data = options.data;
102			}
103
104			$.ajax({
105				url: content,
106				type: type,
107				data: data,
108				cache: false,
109				success: function(html){
110					$.disAjaxWin.content(id,html);
111				}
112			}).fail(function(html) {
113				$.disAjaxWin.content(id,"Ошибка получения контента, обратитесь к администратору\n<br><code>" + html.responseText + "</code>");
114			});
115		}
116
117		return element;
118	};
119
120	$.disAjaxWin = function(content,options)
121	{
122		$().disAjaxWin(content,options);
123	};
124
125	$.disAjaxWin.content = function(c_id,html)
126	{
127		if(html==="") {
128			arrOptions[c_id].title = "Ошибка!";
129			html = "<div align='center' style='width:200px; color:red; font-weight:bold;'>- Нет данных -</div>";
130		}
131
132		disAjaxWin_body[c_id].html(html);
133
134		if(element.length)
135		{
136			var element_title = element.attr("title");
137			if(element_title!=='') $.disAjaxWin.title(element_title);
138		}
139		if($('.disTitle:first',disAjaxWin_body[c_id]).length) {
140			$.disAjaxWin.title($('.disTitle:first', disAjaxWin_body[c_id]).text());
141			$('.disTitle:first', disAjaxWin_body[c_id]).hide();
142		}
143		if(arrOptions[c_id].title !== "") {
144			$.disAjaxWin.title(arrOptions[c_id].title);
145		}
146
147		var show = function(){
148			$("body").removeClass("loading");
149
150			if(arrOptions[c_id].shadow === "Y")
151			{
152				disAjaxWinShadow[c_id].css({opacity:0}).show().animate({opacity: 1}, 200);
153			}
154			$.disAjaxWin.show();
155
156			setTimeout(function(){disBlock = 0;}, 200);
157
158			if(arrOptions[c_id] !== undefined && arrOptions[c_id].success !== undefined){
159				arrOptions[c_id].success();
160			}
161		};
162
163		var src;
164		if(arrOptions[c_id].preload_img_container)
165		{
166			$(arrOptions[c_id].preload_img_container, disAjaxWin_body[c_id]).each(function(){
167				src = $(this).attr('src');
168				return false;
169			});
170		}
171		if(src && src !== 'undefined')
172		{
173			var img = new Image();
174			img.onload = function () {
175				this.onload = this.onerror = null;
176				show();
177			};
178			img.src = src;
179		}
180		else
181		{
182			show();
183		}
184	};
185
186	$.disAjaxWin.show = function()
187	{
188		var right = "auto", bottom = "auto";
189
190		if(element.length)
191		{
192			if(arrOptions[id].overlay)
193			{
194				disAjaxWin_overlay[id].css({'position':'absolute', "overflow":"visible", "top":0, "left":0}).show();
195			}
196			top = element.offset().top;
197			left = element.offset().left;
198		}
199		else
200		{
201			if(arrOptions[id].overlay)
202			{
203				if(!$('body.disAjaxWin-lock').length && $(document).height()>$(window).height())
204				{
205					scroll_top = $(window).scrollTop();
206					$('body').css({'padding-right':"+="+$.scrollbarWidth(), 'margin-top':"-="+scroll_top}).addClass('disAjaxWin-lock');
207				}
208				disAjaxWin_overlay[id].show();
209			}
210
211			if($(window).width() <= arrOptions[id].adapt_width)
212			{
213				left = 0;
214				right = 0;
215
216				if((disAjaxWin[id].outerHeight(true))>$(window).height())
217				{
218					top = 0;
219				}
220				else
221				{
222					top = (($(window).height()-disAjaxWin[id].outerHeight(true))/2);
223				}
224			}
225			else
226			{
227				if(arrOptions[id].position==="center")
228				{
229					if((disAjaxWin[id].outerHeight(true))>$(window).height())
230					{
231						top = 0;
232					}
233					else
234					{
235						top = (($(window).height()-disAjaxWin[id].outerHeight(true))/2);
236					}
237
238					if(!arrOptions[id].overlay)
239					{
240						if((disAjaxWin[id].outerHeight(true))<$(window).height())
241						{
242							disAjaxWin[id].css({"position":"fixed"});
243						}
244						else
245						{
246							disAjaxWin[id].css({"position":"absolute"});
247							top = top+$(window).scrollTop();
248						}
249					}
250				}
251				else
252				{
253					if(arrOptions[id].position==="top") top = 10;
254				}
255
256				left = (($(window).width()-disAjaxWin[id].outerWidth(true))/2)+$(window).scrollLeft();
257			}
258		}
259
260		if(disAjaxWin[id].is(":hidden"))
261		{
262			disAjaxWin[id].css({"top":top, "left":left, "right": right, "bottom": bottom}).show();
263			setTimeout(function(){
264				disAjaxWin[id].addClass('active');
265			}, 10);
266		}
267		else
268		{
269			disAjaxWin[id].css({"top":top, "left":left, "right": right, "bottom": bottom});
270		}
271	};
272
273	$.disAjaxWin.resize = function(c_id){
274		if(c_id === '') c_id = "none_id";
275
276		var right = "auto", bottom = "auto";
277
278		if($('div#disAjaxWin' + c_id).length)
279		{
280			if($(window).width() <= arrOptions[c_id].adapt_width)
281			{
282				left = 0;
283				top = 0;
284				right = 0;
285				bottom = 'auto';
286			}
287			else
288			{
289				if((disAjaxWin[c_id].outerHeight(true)) > $(window).height())
290				{
291					top = 0;
292				}
293				else
294				{
295					top = (($(window).height() - disAjaxWin[c_id].outerHeight(true)) / 2);
296				}
297
298				if(!arrOptions[c_id].overlay)
299				{
300					if((disAjaxWin[c_id].outerHeight(true)) < $(window).height())
301					{
302						disAjaxWin[c_id].css({"position":"fixed"});
303					}
304					else
305					{
306						disAjaxWin[c_id].css({"position":"absolute"});
307						top = top + $(window).scrollTop();
308					}
309				}
310
311				left = (($(window).width() - disAjaxWin[c_id].outerWidth(true)) / 2) + $(window).scrollLeft();
312			}
313
314			disAjaxWin[c_id].css({"top":top, "left":left, "right": right, "bottom": bottom});
315		}
316	};
317
318	$.disAjaxWin.temp_close = function() {
319		disAjaxWinTemp_body.empty();
320		disAjaxWinTemp.css({"width":"auto","height":"auto"});
321	};
322
323	$.disAjaxWin.close = function(c_id) {
324		if(c_id==='') c_id = "none_id";
325		if($('div#disAjaxWin'+c_id).length)
326		{
327			if(arrOptions[c_id].confirmClose) {
328				if(!confirm(arrOptions[c_id].confirmClose)) return false;
329				arrOptions[c_id].confirmClose = "";
330			}
331			if(arrOptions[c_id].close !== undefined){
332				arrOptions[c_id].close();
333			}
334
335			if(arrOptions[c_id].remove)
336			{
337				disAjaxWin[c_id].remove();
338				if(arrOptions[id].overlay) disAjaxWin_overlay[c_id].remove();
339				disAjaxWinShadow[c_id].animate({opacity: 0}, 200, function(){
340					$(this).remove();
341				})
342			}
343			else
344			{
345				disAjaxWin[c_id].hide();
346				if(arrOptions[c_id].overlay) disAjaxWin_overlay[c_id].hide();
347				disAjaxWinShadow[c_id].animate({opacity: 0}, 200, function(){
348					$(this).hide();
349				});
350			}
351
352			if(arrOptions[c_id].overlay)
353			{
354				if(!$('.disAjaxWinOverlay:visible').length && $('body.disAjaxWin-lock').length)
355				{
356					$('body').css({'padding-right':"-=" + $.scrollbarWidth(), 'margin-top':"+=" + scroll_top}).removeClass('disAjaxWin-lock');
357					$(window).scrollTop(scroll_top);
358				}
359			}
360		}
361	};
362
363	$.disAjaxWin.title = function(title) {
364		disAjaxWin_title[id].html(title).show();
365	};
366
367	//Изменяем заголок у открытого окна
368	$.disAjaxWin.retitle = function(c_id, title){
369		if(c_id === '') c_id = "none_id";
370		if(title === '')
371		{
372			disAjaxWin_title[c_id].hide();
373		}
374		else
375		{
376			disAjaxWin_title[c_id].html(title).show();
377		}
378	};
379
380	$.scrollbarWidth = function() {
381		var parent = $('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo('body'),
382			width = parent.children().innerWidth() - parent.children().height(99).innerWidth();
383
384		parent.remove();
385
386		return width;
387	};
388
389	//Функция Установки опций по умолчанию
390	$.disAjaxWin.setOptions = function(setOptions) {
391		defaultOptions = $.extend({}, defaultOptions, setOptions); //Объединяем опции
392	};
393
394	//Устанавливаем функцию выполняющуюся после закрытия
395	$.disAjaxWin.onClose = function(c_id, func) {
396		if(c_id==='') c_id = "none_id";
397		arrOptions[c_id].close = func;
398	};
399
400	//Устанавливаем подтверждение на закрытие окна
401	$.disAjaxWin.confirmClose = function(c_id, text) {
402		if(c_id==='') c_id = "none_id";
403		arrOptions[c_id].confirmClose = text;
404	};
405
406	$.disAjaxWin.init = function(){
407		var _id = id;
408
409		if(!$('#disAjaxWin'+_id).length)
410		{
411			$(document.body).append('<div id="disAjaxWinShadow'+_id+'" class="disAjaxWinShadow'+style.replace("_disAjaxWin","_disAjaxWinShadow")+'"></div>'+
412				'<div id="disAjaxWin'+_id+'" class="disAjaxWin_wrap'+style+'">'+
413				'<div class="disAjaxWin">'+
414				'<div class="dis-TL">'+
415				'<div class="dis-TR">'+
416				'<div class="dis-TC">'+
417				'<div class="dis-btnClose"></div>'+
418				'<div class="dis-title"></div>'+
419				'</div>'+
420				'</div>'+
421				'</div>'+
422				'<div class="dis-CL">'+
423				'<div class="dis-CR">'+
424				'<div class="dis-CC">'+
425				'<div class="dis-body"></div>'+
426				'</div>'+
427				'</div>'+
428				'</div>'+
429				'<div class="dis-BL">'+
430				'<div class="dis-BR">'+
431				'<div class="dis-BC"></div>'+
432				'</div>'+
433				'</div>'+
434				'</div>'+
435				'</div>');
436
437			//$('div#disAjaxWin'+_id).draggable({handle:".dis-TL"});
438
439			disAjaxWin[_id] = $('div#disAjaxWin'+_id);
440			disAjaxWin_body[_id] = $('div#disAjaxWin'+_id+' .dis-body');
441			disAjaxWin_close[_id] = $('div#disAjaxWin'+_id+' .dis-btnClose');
442			disAjaxWin_title[_id] = $('div#disAjaxWin'+_id+' .dis-title');
443			disAjaxWinShadow[_id] = $('div#disAjaxWinShadow'+_id);
444
445			if(arrOptions[_id].overlay)
446			{
447				disAjaxWin[_id].wrap('<div id="disAjaxWinOverlay'+_id+'" class="disAjaxWinOverlay"></div>');
448				disAjaxWin_overlay[_id] = $('div#disAjaxWinOverlay'+_id);
449			}
450
451			if(arrOptions[_id].width) {
452				disAjaxWin[_id].width(arrOptions[_id].width);
453			}
454
455			if(arrOptions[_id].close_on_shadow==="Y") {
456				if(arrOptions[_id].overlay)
457				{
458					disAjaxWin_overlay[_id].on('click',function(e){
459						if($(e.target).hasClass('disAjaxWinOverlay')) {
460							$.disAjaxWin.close(_id);
461						}
462					});
463					disAjaxWin[_id].on('click',function(e){
464						if($(e.target).hasClass('disAjaxWin_wrap')) {
465							$.disAjaxWin.close(_id);
466						}
467					});
468				}
469				else
470				{
471					disAjaxWinShadow[_id].on('click',function(){
472						$.disAjaxWin.close(_id);
473					});
474				}
475			}
476			if(arrOptions[_id].show_close==="Y") {
477				disAjaxWin_close[_id].on('click',function(){
478					$.disAjaxWin.close(_id);
479				});
480			}
481			else disAjaxWin_close[_id].hide();
482
483			disAjaxWin_close[_id].hover(
484				function(){$(this).addClass("dis-btnClose-hover");},
485				function(){$(this).removeClass("dis-btnClose-hover");}
486			)
487		}
488
489		if(!$('#disAjax_indicator').length) $("body").append('<div id="disAjax_indicator"><div></div></div>');
490	};
491})(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.