PageSourceSearch

https://cortexmed.ru/local/js/basic/ajax.js

js cortexmed.ru collected 2026-10-08 04:40:53 UTC 14,086 bytes, 557 lines download raw bytes

1;(function(w, $) {
2	var _all = [], db = document.body;
3	var _get_node = function(node, params) {
4		node = typeof(node)=='string' ? document.getElementById(node) : node;
5		var n = _all.length, i;
6		for(i = 0; i < n; i++)
7		if((node == _all[i].node)&&(_all[i].constructor == _jajax))
8			return _all[i];
9		params = params || {};
10		_all[n] = new _jajax(node, params);			
11		return _all[n];	
12	}
13	var _jajax = function(node, params) {
14		var opts;
15		
16		this.node = node;		// a или div
17		this.button = null; 	// a
18		this.container = null; 	// div
19		this.ajax_call_id = '';	// запросить область
20		this.forms = [];		// forms в контейнере form[class~"formClass"]
21		this.hrefs = [];		// ссылки в контейнере a[class~"linkClass"]
22		this.bBind = false;		
23		this.curUrl = '';
24		this.params = null;
25		this.holded = false;
26
27		var container = null, href, rel, pos;
28		if(node.tagName.toLowerCase()=='a') {
29			this.button = node;
30			href = this.node.href;
31			if(href.length > 0) {
32				pos = href.indexOf('#');
33				if(pos >= 0) {
34					rel = href.substr(pos + 1);
35					href = href.substr(0, pos);
36				}
37				if(rel.length > 0) 
38					container = document.getElementById(rel);
39			}
40			
41			if(href.length <= 0) {
42				href = window.location.href;
43				pos = href.indexOf('#');
44				if(pos >= 0) href = href.substr(0, pos);
45			}
46			
47			if(!container) {
48				this._popup = true;
49				container = document.getElementById('_jajax__container');
50				if(!container) {
51					container = document.body.appendChild($.sigma.tag('div'));
52					container.id = '_jajax__container';
53				}
54			}
55			container.style.display = 'none';
56			this.container = container;
57		}
58		else
59			this.container = node;
60			
61		this.params = $.sigma.getOpts(this.container, params, 'ac');
62		if(this.button) 
63			this.params = $.sigma.getOpts(this.button, params, 'ac');
64		if(this.params.id)
65			this.ajax_call_id = this.params.id;
66			
67		this.init();
68	};
69	_jajax.prototype.isHolded = function(val) {
70		if(typeof(val)!='undefined') this.holded = !!val; 
71		return this.holded; 
72	}
73	_jajax.prototype.init = function() {
74		var that = this, p;
75		this.wait.apply(that);
76		
77		if(this.button != null) {
78			this.attach(this.button, 'click', function(e) {
79				$.magnificPopup({
80					items: {
81						src: '#'+that.container.id,
82						type: 'inline'
83					}
84				});
85			});
86			/*
87			$(this.link()).click(function() {
88				that.load(this.href, function() {
89					if(this.isPopup()) {
90						var size = $.sigma.getClientSize(), w = this.params.maxWidth;
91						if((w<=0) || (w>size.width)) w = size.width;
92						$.modal.openPopup(this.container(), {width: w, css: this.params.popupCss});
93					}	
94				});
95				return false;
96			}); */
97		}
98	}
99	_jajax.prototype.wait = function() {
100		var that = this;
101		if(that.params.wait > 0)
102			setTimeout(function() {
103				that.load();
104			}, that.params.wait);
105		else {
106			that.load();
107		}
108	}
109	_jajax.prototype.load = function(url, callback) {
110		if(this.isHolded()) return;
111		
112		var pageSrc = url || this.params.pageSrc, 
113			pos = pageSrc.indexOf('#'), that = this, 
114			div = (this.link()&& !$.modal.isOpened()) ? this.link() : this.container(); 
115		if(pageSrc.length <= 0) return;
116		
117		if(pos >= 0) pageSrc = pageSrc.substr(0, pos);
118		if(this.params.reqSfx.length && pageSrc.length) {
119			if(pageSrc.indexOf(this.params.reqSfx) < 0) {
120				pageSrc += (pageSrc.indexOf('?') >= 0) ? '&' : '?';
121				pageSrc += this.params.reqSfx;
122			}
123		}
124		this.curUrl = pageSrc;
125		
126		if(pageSrc.length > 0) {
127			Loading(div, {text:' ',opacity:0.8}).show();
128			this.isHolded(true);
129			$.ajax({
130				url: pageSrc,
131				method: 'GET',
132				success: function(strHtml) {
133					$(that.container()).html(strHtml);
134					that.initObj();
135					$(document).trigger('bx.ready', that.container());
136					Loading(div).hide();
137					that.isHolded(false);
138					if(typeof(callback)=='function')
139						callback.call(that);
140				},
141				dataType: 'html'
142			});
143		}
144		else {
145			that.initObj();
146		}
147	}
148	_jajax.prototype.getData = function() {
149		var child = this.container().getElementsByTagName('form')[0],
150			data = null;
151		if(child) data = $.sigma.getOpts(child, {}, 'ad');
152		return data;
153	}
154	 
155	_jajax.prototype.init = function(url, bFull) {
156		var i, n, child, val;
157		val = parseInt(this.opts.enabled);
158		if(isNaN(val) || (val <= 0)) return;
159		
160		if(!this.opts.id.length) return;
161		this.id = this.opts.id;
162		
163		this.forms = this.select('form', this.opts.formClass);
164		this.hrefs = this.select('a', this.opts.linkClass);
165		
166		return this;
167	}
168	_jajax.prototype.bind = function(back) 
169	{
170		var that = this;
171		back = back || false;
172		$(this.params.findLink, this.container()).each(function() {
173			if(this.tagName.toLowerCase()=='a') 
174				$(this).click(function() { that.load(this.href); return false; });
175		});
176		if(this.link() == null) { 
177			$(this.params.findPopup, this.container()).each(function() { 
178				if(this.tagName.toLowerCase()=='a') {
179					var area = new _jajax(this, that.params, that);
180					$(this).unbind('areaback areaload')
181						.bind('areaback areaload', function(e, data) 
182					{
183						$(that.target()).trigger(e.type, data);
184						e.stopPropagation();
185					});
186					area.init();
187				}
188			});
189		}
190		$(this.params.findForm, this.container()).each(function() {
191			if(this.tagName.toLowerCase()=='form') {
192				$(this).bind('submit', function() {
193					Loading(that.container(), {text:' ',opacity:0.8}).show();
194					$(this).ajaxSubmit({
195						success: function(html) {
196							$(that.container()).html(html); 
197							that.initObj(true); 
198							$(document).trigger('bx.ready', that.container());
199							Loading(that.container()).hide();
200						},
201						beforeSerialize: function(form, options) {
202							if(that.params.reqSfx.length) {
203								if(options.url.indexOf(that.params.reqSfx) < 0) {
204									options.url += (options.url.indexOf('?') >= 0) ? '&' : '?';
205									options.url += that.params.reqSfx;
206								}
207							}			
208							return true;
209						},
210						dataType: 'html',
211						timeout: 10000
212					});
213					return false;
214				});
215			}
216		});
217
218		this.params.maxHeight = parseInt(this.params.maxHeight);
219		if(false && !isNaN(this.params.maxHeight) && this.params.maxHeight && !this.isPopup()) 
220		{
221			var c = this.container(), h,
222				hi = parseInt($.sigma.getRTStyle(c, 'height').match(/^([0-9]+)/)[1]);
223			c.style.height = 'auto';
224			$(c).removeClass('have-scroll');
225			h = c.scrollHeight;
226			if(c.scrollHeight > this.params.maxHeight) {
227				$(c).animate({height:this.params.maxHeight+2}, 400, function() {
228					$(c).addClass('have-scroll');
229				});
230			}
231			else {
232				$(c).animate({height:c.scrollHeight+2}, 400, function() {
233					$(c).css({height:'auto'}).removeClass('have-scroll');
234				});
235			}
236		}
237
238		var data = this.getData();
239		$(this.target()).trigger(back ? 'areaback' : 'areaload', data);
240		if(this.isPopup()) {
241			if(data && (parseInt(data.status)==this.params.closeStatus)) 
242			{
243				$.modal.closePopup();
244				if(this.parent) this.parent.load();
245			}	
246		}
247	}
248	
249	_jajax.prototype.select = function(tag, cssName) {
250		var i, child, cname, res = [];
251		cssName = cssName || '';
252		child = this.node.getElementsByTagName(tag);
253		for(i in child) 
254		if(child[i].nodeType == 1) {
255			var found = true;
256			if(cssName.length) {
257				cname = ' ' + child[i].className + ' ';
258				found = (cname.indexOf(' ' + cssName + ' ')>=0);
259			}
260			if(found) res[res.length] = child[i];
261		}
262		return res;
263	}
264	_jajax.prototype.values = function (form, values) {
265		if(form.elements) {
266			for(var i = 0; i < form.elements.length; i++) {
267				var el = form.elements[i];
268				if (el.disabled || !el.type)
269					continue;
270
271				switch(el.type.toLowerCase()) { 
272					case 'text':
273					case 'textarea':
274					case 'password':
275					case 'hidden':
276					case 'select-one': 
277						//if(el.value.length)
278							values[values.length] = {name : el.name, value : el.value}; 
279						break;
280					case 'radio':
281					case 'checkbox':
282						if(el.checked)
283							values[values.length] = {name : el.name, value : el.value};
284						break;
285					case 'select-multiple':
286						for (var j = 0; j < el.options.length; j++)
287						{
288							if (el.options[j].selected)
289								values[values.length] = {name : el.name, value : el.options[j].value};
290						}
291						break;
292					default:
293						break;
294				}
295			} 
296		}
297	}
298	_jajax.prototype.values2get = function (values) {
299		var res = '', i;
300		for(i = 0; i < values.length; i++) {
301			if(res.length > 0) res += '&';
302			res += (values[i].name + '=' + encodeURIComponent(values[i].value));
303		}
304		return res;
305	}
306	_jajax.prototype.values2post = function (values) {
307		var post = [];
308		var current = post;
309		var i = 0;
310
311		while(i < values.length) {
312			var p = values[i].name.indexOf('[');
313			if(p == -1) {
314				current[values[i].name] = values[i].value;
315				current = post;
316				i++;
317			} 
318			else {
319				var name = values[i].name.substring(0, p);
320				var rest = values[i].name.substring(p+1);
321				if(!current[name])
322					current[name] = [];
323
324				var pp = rest.indexOf(']');
325				if(pp == -1) {
326					current = post;
327					i++;
328				} else if(pp == 0) {
329					current = current[name];
330					values[i].name = '' + current.length;
331				} else {
332					current = current[name];
333					values[i].name = rest.substring(0, pp) + rest.substring(pp+1);
334				}
335			}
336		}
337		return post;
338	};
339	_jajax.prototype.get = function(url, bFull) {
340		var that = this;
341		url = url || window.location.href;
342		if(url.indexOf('?') >= 0) url += '&';
343		else url += '?';
344		url += 'USE_AJAX=Y&ajax_call_id='+this.ajax_call_id;
345
346		Loading(this.node).show();
347		this.send({
348			url: url, 
349			method: 'GET', 
350			callback: function(html, status) {
351				Loading(that.node).hide();
352				if(status == 200) {
353					$(that.node).html(html); 
354					$(document).trigger('bx.ready', that.node);
355				}	
356			}
357		});
358		
359		return false;
360	}
361	_jajax.prototype.post = function(form, bFull) {
362		var values = [ 
363				{name: 'USE_AJAX', value: 'Y'}, 
364				{name: 'ajax_call_id', value: this.ajax_call_id} 
365			], 
366			method = form.method || '', 
367			action = form.action || '', 
368			request, that = this;
369
370		this.values(form, values);
371		request = null;
372		method = method.toUpperCase() == 'POST' ? 'POST' : 'GET';
373		
374		if(action.length <= 0)
375			action = window.location.href;
376		if(method != 'POST') {
377			request = this.values2get(values);
378			if(request.length > 0) {
379				if(action.indexOf('?') >= 0) action += '&';
380				else action += '?';
381				action += request;
382			}
383			request = null;
384		}
385		else 
386			request = this.values2get(values);
387		
388		Loading(this.node).show();	
389		this.send({
390			url: action, 
391			method: method, 
392			callback: function(html, status) {
393				Loading(that.node).hide();
394				if(status == 200) {
395					$(that.node).html(html); 
396					if(that.bBind) that.bind(); 
397					$(document).trigger('bx.ready', that.node);
398				}	
399			}, 
400			data: request
401		});
402		
403		return false;
404	}
405	_jajax.prototype.attach = function(elem, evType, fn) {
406	    if (elem.addEventListener)
407	        elem.addEventListener(evType, fn, false);
408	    else if (elem.attachEvent)
409	        //elem.attachEvent('on' + evType, fn)
410			elem.attachEvent("on"+evType, function(e) { return fn.apply(elem, [e]) })
411	    else
412	        elem['on' + evType] = fn
413	}
414	
415	_jajax.prototype.bind = function() {
416		var i, elem, n, that = this;
417		for(i in this.forms) {
418			elem = this.forms[i];
419			this.attach(elem, 'submit', 
420				function(e) { e.preventDefault(); return that.submit(this); });
421		}
422		for(i in this.hrefs) {
423			elem = this.hrefs[i];
424			this.attach(elem, 'click', 
425				function(e) { return that.click(this); });
426		}
427		this.bBind = true;
428	}
429	_jajax.prototype.submit = function(form) {
430		return this.post(form);
431	}
432	_jajax.prototype.click = function(a) {
433		
434		return false;
435	}
436
437	_jajax.prototype.send = function(request) {
438		var handle, that = this;
439		request.data = request.data || null;
440
441		if (window.XMLHttpRequest) {
442			try {handle = new XMLHttpRequest();} catch(e){}
443		}
444		else if (window.ActiveXObject) {
445			try {handle = new ActiveXObject("Microsoft.XMLHTTP");} catch(e){}
446			if (!handle)
447				try {handle = new ActiveXObject("Msxml2.XMLHTTP");} catch (e){}
448		}
449			
450		if(!handle) return false;
451		if(typeof(request.callback) == 'function') {
452			handle.onreadystatechange = function() {
453				if (handle.readyState==4) {
454					request.callback.apply(that, [handle.responseText, handle.status]);
455				}
456			}
457		}
458
459		//handle.setRequestHeader('Content-Type', 'text/html');
460		handle.open(request.method, request.url, true);
461		if(request.method == 'POST') {
462			handle.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
463		}
464		handle.send(request.data);
465	}
466	_jajax.prototype.prepare = function(data, prefix) {
467		var res = '';
468		if (null != data) {
469			for(var i in data) {
470				if (res.length > 0) res += '&';
471				var name = encodeURIComponent(i);
472				if(prefix) name = prefix + '[' + name + ']';
473				if(typeof data[i] == 'object')
474					res += this.prepare(data[i], name)
475				else
476					res += name + '=' + encodeURIComponent(data[i])
477			}
478		}
479		return res;
480	}
481	
482	jAjax = function(node, params) {
483		return _get_node(node, params);
484	}
485	
486	$.fn.jAjax = function(params) 
487	{
488		var params = $.extend({}, {
489			formClass: '',
490			linkClass: 'ajax-link',
491			wait: 10,
492			pageSrc: '',
493			popupCss: 'popup-layer',
494			id: ''
495		}, params);
496
497		return this.each(function() {
498			var ajax = jAjax(this, params);
499			ajax.bind();
500
501			//$(this).data('area', area);
502			$(this).bind('geturl', function(e, url) {
503				url = url || ajax.curUrl;
504				ajax.get(url);
505			});
506		});
507	}
508}(window, jQuery));
509
510/*
511
512jAjax
513jAjax = {
514	
515	get: 
516}
517
518Функции JS для каталога
519/local/js/common.js
520	- аякс (ready, ajax_call_id, to, popup)
521	- подгрузка элементов (авто, по нажатию на кнопку)
522	- телефон
523
524	
525var jPhone = function(id, params) { 
526	params = {
527		'ru': 7,
528		'by': 375,
529		'kz': 7,
530		'ua': 380
531	}
532}
533jPhone {
534	
535}
536
537	- дата
538/local/js/list.js
539/local/js/list.js
540/local/js/shop.js
541
542основана на role="element"
543role="buy-button"
544
545var jElement = function(id) {
546	
547}
548var jCatalog = function(id) {
549	
550}
551
552
5531. Покладка товаров в корзину
5542. Фильтр товаров
5553. Подгрузка товаров
556
557*/

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.