PageSourceSearch

https://plusofon.ru/comm/js/jquery/jquery.tg.js?1050

js plusofon.ru collected 2026-10-05 06:05:45 UTC 20,950 bytes, 583 lines download raw bytes

1//
2// version = '0011 2023-03-31'
3// 
4
5/*!
6 * jquery.drag.js 0.0.1 - https://github.com/yckart/jquery.drag_drop.js
7 * Makes elements draggable.
8 *
9 * Copyright (c) 2013 Yannick Albert (http://yckart.com)
10 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
11 * 2013/02/09
12*/
13// 0.0.1.1	ldn - Пропуск drag на элементах форм
14;(function($, window, document, undefined) {
15    var pluginName = "drag",
16        defaults = {
17            onDrag: function(event, elem) {},
18            onMove: function(event, elem) {},
19            onDrop: function(event, elem) {}
20        },
21        Plugin = function(elem, options) {
22            options = $.extend({}, defaults, options);
23            var doc = $(document),
24                $elem = $(elem),
25                offset = null;
26
27            var start = function(e) {
28                //console.log(e);
29                //console.log(e.target.nodeName);
30				// 0.0.1.1	ldn - Пропуск drag на элементах форм
31            	var node = e.target.nodeName;
32            	if(node == 'A' || node == 'INPUT' || node == 'SELECT' || node == 'TEXTAREA')
33            		return;
34            	
35                var pos = $elem.offset();
36                offset = {
37                    x: e.pageX - (parseFloat($elem.css('left')) || 0),
38                    y: e.pageY - (parseFloat($elem.css('top')) || 0)
39                };
40
41                options.onDrag(e, elem);
42                doc.on("mousemove.draggable", moveMe);
43                doc.on("mouseup", end);
44
45               	e.preventDefault();
46            };
47
48            var moveMe = function(e) {
49                $elem.stop().css({
50                    top: e.pageY - offset.y,
51                    left: e.pageX - offset.x
52                });
53                options.onMove(e, elem);
54            };
55
56            var end = function(e) {
57                options.onDrop(e, elem);
58                doc.off("mousemove.draggable", moveMe);
59            };
60
61            $elem.on("mousedown", start);
62        };
63
64    $.fn[pluginName] = function(options) {
65        return this.each(function() {
66            new Plugin(this, options);
67        });
68    };
69}(jQuery, window, document));
70
71
72/*!
73 * jquery.drop.js 0.0.1 - https://github.com/yckart/jquery.drag_drop.js
74 * Makes elements droppable.
75 *
76 * Copyright (c) 2013 Yannick Albert (http://yckart.com)
77 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
78 * 2013/02/09
79*/
80;(function($, window, document, undefined) {
81    var pluginName = "drop",
82        Plugin = function(elem, fn) {
83            var $elem = $(elem),
84                offset = null,
85                state = false;
86
87            var drop = function(e) {
88                var offset = $elem.offset(),
89                    dimensions = {
90                        left: offset.left - $(document).scrollLeft(),
91                        top: offset.top - $(document).scrollTop(),
92                        right: offset.left + $elem.width(),
93                        bottom: offset.top + $elem.height()
94                    };
95
96                // Has the mouse dragged into the drop zone?
97                var in_item = (dimensions.left <= e.clientX) && (e.clientX <= dimensions.right) && (dimensions.top <= e.clientY) && (e.clientY <= dimensions.bottom);
98
99                // Update the drop zone class accordingly.
100                if (in_item) {
101                    fn(e, elem);
102                }
103            };
104            $(document).on("mouseup", drop);
105        };
106
107
108    $.fn[pluginName] = function(fn) {
109        return this.each(function() {
110            new Plugin(this, fn);
111        });
112    };
113}(jQuery, window, document));
114
115
116(function($){
117	// очистка select-а
118	$.fn.clearSelect = function() {
119		return this.each(function() {
120			if(this.tagName=='SELECT') {
121				this.options.length = 0;
122				$(this).attr('disabled','disabled');
123			}
124		});
125	}
126	// заполнение select-а
127	$.fn.fillSelect = function(dataArray,prevsel) {
128		return this.clearSelect().each(function() {
129			if(this.tagName=='SELECT') {
130				var currentSelect = this;
131				$.each(dataArray, function(index,data) {
132					var option = new Option(data.mess_header, data.id);
133					option.selected = (prevsel && prevsel==data.id) ? 'selected' : '';
134					if($.support.cssFloat) {
135						currentSelect.add(option,null);
136					}
137					else {
138						currentSelect.add(option);
139					}
140				});
141				if(this.options.length) {
142					// * 20130411 jq.1.8.3 fix
143					$(this).removeAttr('disabled');
144				}
145			}
146		});
147	}
148
149	//вызов autocomplete()
150	$.fn.autocomplete_i = function() {
151		return this.each(function() {
152			var param = $(this).attr('id').replace('p__','');
153			$(this).autocomplete({
154				serviceUrl: '/',
155				params: {
156					"id":TG_curid?TG_curid:1,
157					"clas":"json",
158					"func":"findtext",
159					"param":param
160				},
161				onSelect: function(value, data) {
162					//value - mess_header выбранного объекта
163					//value - id выбранного объекта
164					
165					//var url = '/?id='+TG_curid+'&oneblock='+TG_curid+'&action=process&p__'+param+'='+value;
166					//url = url.replace(/ /g,'%20');
167					//$('#block_'+TG_curid).load(url);
168					
169					//var url = '/?id='+TG_curid+'&oneblock='+'812'+'&cur_id=' + data;
170					//$('#block_812').load(url);
171				}
172			});
173		});
174	}
175
176	
177	//переход tab-ом по radio-кнопкам
178	$.fn.radioTabbable = function () {
179		var groups = [];
180		// group the inputs by name
181		$(this).each(function () {
182			var el = this;
183			var thisGroup = groups[el.name] = (groups[el.name] || []);
184			thisGroup.push(el);
185		});
186		$(this).on('keydown', function (e) {
187			setTimeout(function () {
188				var el = e.target;
189				var thisGroup = groups[el.name] = (groups[el.name] || []);
190				var indexOfTarget = thisGroup.indexOf(e.target);
191
192				if (e.keyCode === 9) {
193					if (indexOfTarget < (thisGroup.length - 1) && !(e.shiftKey)) {
194						thisGroup[indexOfTarget + 1].focus();
195					}
196					else if (indexOfTarget > 0 && e.shiftKey) {
197						thisGroup[indexOfTarget - 1].focus();
198					}
199				}
200			});
201		});
202	};	
203	
204})(jQuery);
205
206//
207//замена зависимых select-ов
208//
209function changeselects(obj) {
210	var th = (obj && obj.tagName=='SELECT') ? obj : this;
211	var sel = (th.selectedIndex>=0) ? th.options[th.selectedIndex] : null;
212	var id = (sel) ? parseInt(sel.value) : 0;
213	var nextselect = $(th).attr('data-nextselect');
214	var nextselected = $(th).attr('data-nextselected');
215  	var nextobj = ($('#p__'+nextselect).size()) ? $('#p__'+nextselect) : $('#c__'+nextselect);
216
217	if(id==0 || (sel && $(sel).attr('data-cl_code_is'))) {
218		nextobj.clearSelect();
219		if($(nextobj).attr('data-nextselect'))
220			$(nextobj).change();
221	}
222	else {
223		var desc = nextobj.attr('title') ? nextobj.attr('title') : '';
224		$.ajax({
225			url: '/?clas=json&func=getchilds',
226			dataType: 'json',
227			data: {id:id, desc:desc},
228			success: function(data) {
229				if(data.length > 0) {
230					var domnextobj = $(nextobj).get(0);
231					var prevsel = (domnextobj && domnextobj.selectedIndex>=0) ? domnextobj.options[domnextobj.selectedIndex].value : 0;
232		  			nextobj.fillSelect(data,nextselected ? nextselected : prevsel);
233		  		}
234	  			else
235					nextobj.clearSelect();
236				if($(nextobj).attr('data-nextselect'))
237					$(nextobj).change();
238			}
239		});
240	}
241}
242
243
244//
245//показ формы для режима debug
246//
247TG_formcnt = new Array();	// счетчик элементов форм для режима debug
248function debugformcreate(event) {
249	if(this == event.target) {
250		var param = $(this).attr('param');				// имя параметра или атрибута
251		var cur_id = $(this).attr('cur_id');			// id текущего блока-объекта
252		var obj = $(this).next();						// td со значением параметра или элементом формы
253		var fid = $(this).parent().parent().parent().parent().attr('id'); 	//css-id формы td-tr-tbody-table-form
254		var sbm = $('#' + fid + ' input[type="submit"]');					// кнопка submit формы
255		if($(this).attr('savehtml')) {
256			TG_formcnt[fid] = TG_formcnt[fid] ? TG_formcnt[fid]-1 : 1;	// счетчик элементов в форме
257			obj.html($(this).attr('savehtml'));							// восстанавливаем html td
258			$(this).removeAttr('savehtml');
259		}
260		else {
261			TG_formcnt[fid] = TG_formcnt[fid] ? TG_formcnt[fid]+1 : 1;	// счетчик элементов в форме
262			$(this).attr('savehtml',obj.html());						// запоминаем значение html td в атрибуте td
263			obj.html('<img src="/comm/images/loading1.gif">');
264			obj.load('/?id=' + TG_jmid + '&action=get_form_element&cur_id=' + cur_id + '&param=' + param);
265		}
266		if(TG_formcnt[fid])
267			sbm.show();	// отображаем submit
268		else
269			sbm.hide();	// прячем submit
270	}
271	return false;
272}
273
274//
275//ввод формы для режима debug
276//
277function debugsubmit() {
278	var form_id = '#' + $(this).attr('id');				// css-id формы
279	var block_id = '#' + $(this).attr('data-block');	// css-id блока с html-кодом
280	if(!block_id)
281		return false;
282	$(block_id).addClass('debugloading');
283	$(this).ajaxSubmit({
284		success:function() {
285			var block_css = $(form_id).find('input[name="p__block_css"]');
286			if(block_css.length)
287				$(block_id).attr('style',block_css.val());
288			var view_class_block = $(form_id).find('input[name="p__view_class_block"]');
289			if(view_class_block.length)
290				$(block_id).attr('class','block_is ' + view_class_block.val());
291			if($(form_id).find('select[name="p__block_pos"]').length)
292				window.location = document.location;
293				
294			var cur_id  = $(form_id).find('input[name="cur_id"]').attr('value');
295			var page_id = $(form_id).find('input[name="page_id"]').attr('value');
296			var gethtml = '/?noredirect=1&id=' + page_id + '&oneblock=' + cur_id;
297			if(cur_id && page_id)
298				$(block_id).load(gethtml, function(){$(this).removeClass('debugloading');});
299		}
300	});
301	return false;
302}
303
304
305function load_childs_pages() {
306	//var blockMessageId = $(this).parent().attr('data-rel');
307	var blockMessageId = $(this).closest('[data-rel]').attr('data-rel');
308	
309	var blockDiv;
310	obj = $(this);
311	while(obj = obj.parent()) {
312		if(typeof(obj.attr('id')) != 'undefined' && obj.attr('id').indexOf('block_') >= 0) {
313			blockDiv = obj.attr('id');
314			break;
315		}
316	}
317	if(blockMessageId && blockDiv)
318		$('#' + blockDiv).load($(this).attr('href') + '&oneblock=' + blockMessageId);
319	return false;
320}
321
322var ajaxInProgress = false;
323
324function load_moreloaded() {
325	ajaxInProgress = true;
326	var blockDiv;
327	obj = $(this);
328	while(obj = obj.parent()) {
329		if(typeof(obj.attr('id')) != 'undefined' && obj.attr('id').indexOf('block_') >= 0) {
330			blockDiv = obj.attr('id');
331			break;
332		}
333	}
334	if(blockDiv) {
335		var onePageContainer = $('#' + blockDiv).find('.moreLoadedCell');
336		var loadingLinkContainer = $('#' + blockDiv).find('.arch_standart');
337		loadingLinkContainer.html($('#loading').html());
338		$.ajax({
339			url: $(this).attr('data-href'),
340			dataType: 'html',
341			success: function(data) {
342				var queryResultObject = $('<div>' + data + '</div>');
343				var onePageHtml = queryResultObject.find('.moreLoadedCell').html();
344				var loadingLinkHtml = queryResultObject.find('.arch_standart').html();
345				onePageContainer.append($(onePageHtml));
346				loadingLinkContainer.html(loadingLinkHtml ? loadingLinkHtml : '<div></div>'); // удаляем кнопку на последней страницы
347		        ajaxInProgress = false;
348				//console.log(data);
349				if(typeof(load_moreloaded_callback)=='function')
350					load_moreloaded_callback(blockDiv);
351			}
352		});
353	}	
354	return false;
355}
356
357// checkssetall - устанавливает / сбрасывает массив checkbox-ов для одного параметра (mchecks, checks)
358// pname - имя параметра
359// act=set - установить все checked
360// act=unset - сбросить все checked
361// act=invert - инвертировать все checked
362//
363function checkssetall(pname,act) {
364	var checks = $.find('input[type="checkbox"][name^="p__'+pname+'"]');
365	for(i=0;i<checks.length;++i) {
366		if(act=='set')
367			checks[i].checked = true;
368		else if(act=='unset')
369			checks[i].checked = false;
370		else if(act=='invert')
371			checks[i].checked = !checks[i].checked;
372	}
373}
374
375var DoneInsertPos = 0;
376function insert_pos_to(any) {
377	//$('div.insert_pos1').appendTo('div#insert_pos1');
378	if(!DoneInsertPos || any) {
379		var divs = $('div[class*=insert_pos]');
380		DoneInsertPos = 1;
381		if(divs){
382			for(i=0;i<divs.length;++i){
383				classes = divs[i].className.split(' ');
384				for(j=0;j<classes.length;++j) {
385					if(classes[j].indexOf('insert_pos') >= 0) {
386						//2016-10-31
387						$('div#' + classes[j]).html('');
388						$(divs[i]).appendTo('div#' + classes[j]);
389						break;
390					}
391				}
392			}
393		}
394	}
395}
396
397
398
399$(document).ready(function() {
400	//переход tab-ом по radio-кнопкам
401	$('.label_radio input').radioTabbable();
402
403	//для режима debug
404	$('.debugtags').off('click');
405	$('.debugtags').on('click', debugformcreate);
406	$('.debugform').off('submit');
407	$('.debugform').on('submit', debugsubmit);
408	$('.debughide').click(function(){
409		$(this).parent().parent().hide();
410	});
411	$('.debugtoggle').off('click');
412	$('.debugtoggle').click(function(){
413		var title = $(this).attr('title');
414		$(this).attr('title', (title=='открыть' ? 'закрыть' : 'открыть'));
415		if($(this).text().substring(0,1) == '+')	
416			$(this).text($(this).text().replace('+','--'));
417		else
418			$(this).text($(this).text().replace('--','+'));
419		$('#' + $(this).attr('data-block')).toggle();
420	});
421	$('.debugblock').each(function(){
422		var curOffset = $(this).offset();
423		var width = $(this).width();
424		if(width>500) width = 500;
425		$(this).css({'position': 'absolute', 'left': curOffset.left+'px', 'top': curOffset.top+'px', 'width':width+'px'}).appendTo('body');
426	});
427	$('.debugblock').drag({debug:true});
428	$('.debugblock').click(function(){
429		$('.debugblock').removeClass('debugblock_current');
430		$(this).addClass('debugblock_current');
431	});
432	$('.debugblock').hover(function() {
433		$('#block_' + $(this).attr('data-block')).addClass('debugblock_hover');
434	}, function() {
435		$('.block_is').removeClass('debugblock_hover');
436	});
437
438
439	//обновляем зависимые select-ы
440	$('select[nextselect]').change();
441
442	//автозаполняемые input-ы
443	$('.autocomplete-i').autocomplete_i();
444
445	//архив со списком страниц	
446	$('body').on('click','.link_childs_pages',load_childs_pages);
447
448	//архив показать еще
449	$('body').on('click','.link_moreloaded',load_moreloaded);
450
451	//для загрузки при рулоне
452	if($('.arch_scrollloaded').length != 0) {
453		$(window).scroll(function() {
454			//if($(document).height() - $(window).height() <= $(window).scrollTop() + 50 && !ajaxInProgress) {
455			if($(document).height() - $(window).height() <= $(window).scrollTop() + $(document).height()*0.1 && !ajaxInProgress) {
456	        	$('.arch_scrollloaded .link_moreloaded').trigger( 'click');
457	        }
458		});
459	}
460	
461	//вставка блоков с классом inser_pos_XXX в div с id-м inser_pos_XXX
462	insert_pos_to(0);
463
464	//2014-05-11
465	//картинки с классом prettyphotoimg делаются ссылками Ð
465½Ð° себя
466	//ссылки с классом prettyphotomodal открываются в модальном окне ссылка указывается так:
467	//href="/?id=XXX&oneblock=YYY&ajax=true&width=360&height=490"
468	//начальные установки можно переопределить с помощью var prettyphotoSettings
469	//требуются jquery.prettyPhoto.js и prettyPhoto.css
470	if(typeof($.prettyPhoto)=='object') {
471		var defsettings = {
472			theme: 'light_nodetail',
473			slideshow: false,
474			overlay_gallery: false,
475			show_title: false,
476			keyboard_shortcuts: false,
477			autoplay_slideshow: false
478		};
479		$("img.prettyphotoimg").wrap(function() {
480			return '<a class="'+$(this).attr('class')+'" href="'+$(this).attr('src')+'" title="'+$(this).attr('alt')+'"/>';
481		});
482		$("a.prettyphotoimg").prettyPhoto((typeof(prettyphotoSettings)!='undefined') ? prettyphotoSettings : defsettings);
483		$("a.prettyphotomodal").prettyPhoto((typeof(prettyphotoSettings)!='undefined') ? prettyphotoSettings : defsettings);
484	}
485
486	//2014-10-22
487	//список pretty_photo v.15, ограничение числа фото задается настройкой per_page, кнопка "показать еще" 
488	$('.prettyphoto_more a').click(function(){
489		var next_page = $(this).attr('data-next-page');
490		var block = $(this).attr('data-block');
491		$('#' + block + ' div[data-for-page='+next_page+']').slideDown().removeClass('divhidden');
492		$(this).attr('data-next-page',++next_page);
493		if(!$('#' + block + ' div[data-for-page='+next_page+']').size())
494			$(this).parent().remove();
495		return false;
496	});
497
498	//2013-12-11
499	//ui jquery datepicker для дат с модификатором fedatepicker=1 и editformat=
500	if(typeof($.datepicker)=='object') {
501		$('body').on('focus', '.tdatepicker', function() {
502			$(this).datepicker();
503		});
504	}
505
506	//2013-12-13
507	//inputmask
508	if(typeof($.inputmask)=='object') {
509		$.extend($.inputmask.defaults.definitions, {
510			'f': {
511				'validator': '[А-Яа-яЁё -]',
512				'cardinality': 1,
513				'prevalidator': null
514			}
515		});
516		$('body').on('focus', 'input[data-inputmask]', function() {
517			$(this).inputmask();
518		});
519	}
520
521
522	//2014-05-10
523	//ajaxform
524	$('body').off('submit','.ajaxform');
525	$('body').on('submit','.ajaxform', function(e) {
526		var form_id = $(this).attr('id').replace('form_','');
527		if(!formcheck(this))
528			return false;
529		e.preventDefault();
530		$(this).ajaxSubmit({
531			// функция, вызываемая перед передачей
532			beforeSubmit: function(arr, form, options) { 
533				var form_id = form.attr('id').replace('form_','');
534				// console.log( form_id );
535				$('#blockform_' + form_id).append('<div class="form_loading_info"></div>');
536				//$('#form_' + form_id).trigger('formBeforeSubmit', {arr:arr, form:form, options:options});
537				/* вызов обработчика
538				$(document).on('formBeforeSubmit', function(event, data) {
539					alert(data.options.target);
540				});
541				*/
542				form.find(":submit").prop('disabled', true);	// 20230331
543				return true; //false to cancel submit
544			},
545			// функция, вызываемая при получении ответа
546			success: function(responseText, statusText, xhr, form) {
547				// for normal html responses, the first argument to the success callback is the XMLHttpRequest object's responseText property 
548				// if the ajaxSubmit method was passed an Options Object with the dataType property set to 'xml' then the first argument to the success callback is the XMLHttpRequest object's responseXML property 
549				// if the ajaxSubmit method was passed an Options Object with the dataType property set to 'json' then the first argument to the success callback is the json data object returned by the server
550				// alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); 
551				// console.log( form.attr('id') );
552			},
553			uploadProgress: function(event, position, total, percentComplete) {
554				$('#blockform_' + form_id + ' .form_progress').show();
555				$('#blockform_' + form_id + ' .form_bar').width(percentComplete + '%');
556				$('#blockform_' + form_id + ' .form_percent').html(percentComplete + '%');
557			},
558    		// элемент, который будет обновлен по ответу сервера
559			target: '#blockform_' + form_id,
560        	replaceTarget: 'replaceWith',
561			timeout: 300000 
562		});
563	});
564
565	// 2019-11-27
566	// блоки с классом ajaxload подгружаются ajax-ом после загрузки страницы (антикэш)
567	// 2021-09-17 * data-ajaxpath для обращения к ЧПУ с oneblock 
568	$('.ajaxload').each(function(){
569		var th = $(this);
570		// var uri = window.location.pathname+'?id='+TG_curid+'&oneblock='+th.attr('data-block-id');
571		var uri = '/' + (th.attr('data-ajaxpath') !== undefined ? th.attr('data-ajaxpath') : '') +'?id='+TG_curid+'&oneblock='+th.attr('data-block-id');
572		$.ajax({
573			// url: '/?id='+TG_curid+'&oneblock='+th.attr('data-block-id'),
574			url: uri,
575			dataType: 'html',
576			success: function(data) {
577				th.html(data);
578			}
579		});
580	});
581
582
583});

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.