PageSourceSearch

https://yarwiki.ru/js/plugins/presenter-4.1.js

js yarwiki.ru collected 2026-10-02 10:33:53 UTC 13,626 bytes, 400 lines download raw bytes

1(function ($) {
2
3	var className = 'presenter';
4	var defaultOptions = {
5		requestUrl: {
6			getMediaObjects: '/presenter-ajax/get-media-objects/',
7			getObjects: '/presenter-ajax/get-objects/',
8			getRelObjects: '/presenter-ajax/get-rel-objects/',
9			reloadFilter: '/presenter-ajax/reload-filter/',
10			setFilter: '/presenter-ajax/set-filter/'
11		},
12		requestUrlPrefix: ''
13	};
14	var methods = {
15		init: function (inputOptions) {
16			return this.each(function () {
17				var options = $.extend({}, defaultOptions, inputOptions);
18				var $this = $(this);
19				var data = $this.data(className);
20				if (!data) {
21					$this.data(className, {
22						$elem: $this,
23						options: options
24					});
25				}
26			});
27		},
28		// ---------------------------------------------------------------------
29		addMarkedObject: function (objectId) {
30			return this.each(function () {
31				var $this = $(this);
32				var objectsIds = $this.presenter('getMarkedObjectsIds');
33				if (objectsIds.indexOf(objectId) === -1) {
34					objectsIds.push(objectId);
35				}
36				$this.attr('data-marked-objects-ids', objectsIds.length ? objectsIds.join(',') : '').presenter('toggleMarkedObjectsMenu', objectsIds.length ? true : false);
37			});
38		},
39		find: function (elem) {
40			return this.each(function () {
41				$(this).attr('data-page', 1).presenter('_find', elem);
42			});
43		},
44		getMarkedObjectsIds: function () {
45			var result = [];
46			var objectsIds = $(this).attr('data-marked-objects-ids');
47			if ((objectsIds !== undefined) && objectsIds) {
48				result = objectsIds.split(',');
49			}
50			return result;
51		},
52		getParams: function () {
53			var $this = $(this);
54			var result = {};
55
56			if ($this.attr('data-limit') !== undefined) {
57				result['limit'] = $this.attr('data-limit');
58			}
59			if ($this.attr('data-model-alias') !== undefined) {
60				result['modelAlias'] = $this.attr('data-model-alias');
61			}
62			if ($this.attr('data-object-id') !== undefined) {
63				result['objectId'] = $this.attr('data-object-id');
64			}
65			if ($this.attr('data-order') !== undefined) {
66				result['order'] = $this.attr('data-order');
67			}
68			if ($this.attr('data-rel-model-alias') !== undefined) {
69				result['relModelAlias'] = $this.attr('data-rel-model-alias');
70			}
71			if ($this.attr('data-rel-object-id') !== undefined) {
72				result['relObjectId'] = $this.attr('data-rel-object-id');
73			}
74			if ($this.attr('data-page') !== undefined) {
75				result['page'] = $this.attr('data-page');
76			}
77			if ($this.attr('data-structure-view-mode') !== undefined) {
78				result['structureViewMode'] = $this.attr('data-structure-view-mode');
79			}
80			if ($this.attr('data-view-mode') !== undefined) {
81				result['viewMode'] = $this.attr('data-view-mode');
82			}
83
84			result['modes'] = [];
85			if (($this.attr('data-modes') !== undefined) && $this.attr('data-modes')) {
86				result['modes'] = $this.attr('data-modes').split(',');
87			}
88
89			result['scopes'] = [];
90			if (($this.attr('data-scopes') !== undefined) && $this.attr('data-scopes')) {
91				result['scopes'] = $this.attr('data-scopes').split(',');
92			}
93
94			if (($this.attr('data-filter-enabled') !== undefined) && (parseInt($this.attr('data-filter-enabled')) === 1) && !$this.hasClass('js-filter-reloader')) {
95				if ($this.find('form.js-filter').length) {
96					result['filterVals'] = $this.find('form.js-filter').serialize();
97				} else if ($this.find('.js-filter form').length) {
98					result['filterVals'] = $this.find('.js-filter form').serialize();
99				}
100			}
101
102			if ($this.hasClass('js-media-manager')) {
103				result['type'] = 'media_manager';
104				if ($this.attr('data-storage-model-alias') !== undefined) {
105					result['storageModelAlias'] = $this.attr('data-storage-model-alias');
106				}
107				if ($this.attr('data-storage-object-id') !== undefined) {
108					result['storageObjectId'] = $this.attr('data-storage-object-id');
109				}
110			} else if ($this.hasClass('js-rel-objects-presenter')) {
111				result['type'] = 'rel_objects_presenter';
112				if ($this.attr('data-rel-name') !== undefined) {
113					result['relName'] = $this.attr('data-rel-name');
114				}
115			}
116
117			return result;
118		},
119		hasMarkedObjects: function () {
120			var objectsIds = $(this).attr('data-marked-objects-ids');
121			if ((objectsIds !== undefined) && objectsIds) {
122				return (objectsIds.split(',').length > 0);
123			}
124			return false;
125		},
126		markObject: function (elem) {
127			return this.each(function () {
128				var $this = $(this);
129				var $elem = $(elem);
130				var $object = $elem.hasClass('js-object') ? $elem : $elem.closest('.js-object');
131				var objectId = $object.attr('data-object-id');
132				if ($elem[0].tagName.toLowerCase() === 'input') {
133					if ($elem.is(':checked')) {
134						$this.presenter('addMarkedObject', objectId);
135						$object.addClass('marked');
136					} else {
137						$this.presenter('removeMarkedObject', objectId);
138						$object.removeClass('marked');
139					}
140				} else if ($object.hasClass('marked')) {
141					$this.presenter('removeMarkedObject', objectId);
142					$object.removeClass('marked');
143					if ($object.find('.js-object-marker').length) {
144						var $marker = $object.find('.js-object-marker');
145						if ($marker[0].tagName.toLowerCase() === 'input') {
146							$marker.removeAttr('checked').removeProp('checked');
147						}
148					}
149				} else {
150					$this.presenter('addMarkedObject', objectId);
151					$object.addClass('marked');
152					if ($object.find('.js-object-marker').length) {
153						var $marker = $object.find('.js-object-marker');
154						if ($marker[0].tagName.toLowerCase() === 'input') {
155							$marker.attr('checked', true).prop('checked', true);
156						}
157					}
158				}
159				$this.find('.js-object.marked').each(function () {
160					$this.find('.js-object-marker[data-object-id="' + $(this).attr('data-object-id') + '"]').each(function () {
161						var $marker = $(this);
162						if (($marker[0].tagName.toLowerCase() === 'input') && !$marker.is(':checked')) {
163							var $object = $marker.hasClass('js-object') ? $marker : $marker.closest('.js-object');
164							$object.removeClass('marked');
165						}
166					});
167				});
168			});
169		},
170		markObjects: function (elem) {
171			return this.each(function () {
172				var $this = $(this);
173				$this.presenter('resetMarkedObjects');
174				var objectsIds = [];
175				if ($(elem).is(':checked')) {
176					$this.find('.js-object').each(function () {
177						var objectId = $(this).attr('data-object-id');
178						objectsIds.push(objectId);
179						$this.find('.js-object-marker[data-object-id="' + objectId + '"]').each(function () {
180							var $marker = $(this);
181							if ($marker[0].tagName.toLowerCase() === 'input') {
182								$marker.attr('checked', true).prop('checked', true);
183							} else {
184								$marker.addClass('marked');
185							}
186							var $object = $marker.hasClass('js-object') ? $marker : $marker.closest('.js-object');
187							$object.addClass('marked');
188						});
189					});
190				}
191				$this.attr('data-marked-objects-ids', objectsIds.length ? objectsIds.join(',') : '').presenter('toggleMarkedObjectsMenu', objectsIds.length ? true : false);
192			});
193		},
194		reloadFilter: function (elem) {
195			return this.each(function () {
196				var $this = $(this);
197				var options = $this.data(className).options;
198				var modelAlias = $this.hasClass('js-rel-objects-presenter') ? $this.attr('data-rel-model-alias') : $this.attr('data-model-alias');
199				appUtils.executeRequest({
200					$parentElem: $this,
201					data: {
202						modelAlias: modelAlias
203					},
204					elem: elem,
205					result: {
206						action: 'presenter._after-reload-filter',
207						type: 'action'
208					},
209					url: options.requestUrlPrefix + options.requestUrl.reloadFilter
210				});
211			});
212		},
213		removeMarkedObject: function (objectId) {
214			return this.each(function () {
215				var $this = $(this);
216				var objectsIds = $this.presenter('getMarkedObjectsIds');
217				if (objectsIds.indexOf(objectId) !== -1) {
218					objectsIds.splice(objectsIds.indexOf(objectId), 1);
219				}
220				$this.attr('data-marked-objects-ids', objectsIds.length ? objectsIds.join(',') : '').presenter('toggleMarkedObjectsMenu', objectsIds.length ? true : false);
221			});
222		},
223		resetMarkedObjects: function () {
224			return this.each(function () {
225				var $this = $(this);
226				$this.attr('data-marked-objects-ids', '');
227				$this.find('.js-object-marker').each(function () {
228					var $marker = $(this);
229					if ($marker[0].tagName.toLowerCase() === 'input') {
230						$marker.removeAttr('checked').prop('checked', false);
231					} else {
232						$marker.removeClass('marked');
233					}
234					var $object = $marker.hasClass('js-object') ? $marker : $marker.closest('.js-object');
235					$object.removeClass('marked');
236				});
237				$this.presenter('toggleMarkedObjectsMenu', false);
238			});
239		},
240		setFilter: function (elem) {
241			return this.each(function () {
242				var $this = $(this);
243				var options = $this.data(className).options;
244				var $elem = $(elem);
245				var requestData = {
246					flag: (parseInt($elem.attr('data-flag')) === 1) ? 0 : 1,
247					modelAlias: $this.attr('data-model-alias')
248				};
249				if ($this.hasClass('js-rel-objects-presenter')) {
250					requestData['modelAlias'] = $this.attr('data-rel-model-alias');
251				}
252				$this.attr('data-filter-enabled', requestData.flag);
253				appUtils.executeRequest({
254					$parentElem: $this,
255					data: requestData,
256					elem: elem,
257					result: {
258						action: 'presenter._after-set-filter',
259						type: 'action'
260					},
261					url: options.requestUrlPrefix + options.requestUrl.setFilter
262				});
263			});
264		},
265		setLimit: function (elem) {
266			return this.each(function () {
267				$(this).attr('data-limit', parseInt($(elem).val())).presenter('_find', elem);
268			});
269		},
270		setOrder: function (elem, event) {
271			return this.each(function () {
272				var $this = $(this);
273				var $elem = $(elem);
274				var fieldName = $elem.attr('data-field-name');
275				var order = $this.presenter('_decodeOrder', $this.attr('data-order'));
276				if (typeof order[fieldName] === 'undefined') {
277					if (!event.ctrlKey) {
278						order = {};
279						$this.find('.js-order-controls .js-order-control').removeClass('asc desc');
280					}
281					order[fieldName] = 'asc';
282				} else {
283					var orderDirection = (order[fieldName] === 'asc') ? 'desc' : 'asc';
284					if (!event.ctrlKey) {
285						order = {};
286						$this.find('.js-order-controls .js-order-control').removeClass('asc desc');
287					}
288					order[fieldName] = orderDirection;
289				}
290				$this.attr('data-order', $this.presenter('_encodeOrder', order));
291				$this.find('.js-order-controls .js-order-control').each(function () {
292					var fieldName = $(this).attr('data-field-name');
293					if (typeof order[fieldName] !== 'undefined') {
294						$(this).removeClass('asc desc').addClass(order[fieldName]);
295					}
296				});
297				$this.presenter('_find', elem);
298			});
299		},
300		setPage: function (elem) {
301			return this.each(function () {
302				$(this).attr('data-page', $(elem).attr('data-page')).presenter('_find', elem);
303			});
304		},
305		setStructureViewMode: function (elem) {
306			return this.each(function () {
307				$(this).attr('data-structure-view-mode', $(elem).attr('data-structure-view-mode')).presenter('_find', elem);
308			});
309		},
310		setViewMode: function (elem) {
311			return this.each(function () {
312				$(this).attr('data-view-mode', $(elem).attr('data-view-mode')).presenter('_find', elem);
313			});
314		},
315		showMore: function (elem) {
316			return this.each(function () {
317				var $this = $(this);
318				var page = ($this.attr('data-page') !== undefined) ? parseInt($this.attr('data-page')) : 1;
319				$this.attr('data-page', page + 1).presenter('_find', elem);
320			});
321		},
322		toggleMarkedObjectsMenu: function (flag) {
323			return this.each(function () {
324				var $this = $(this);
325				if (flag) {
326					$this.find('.js-marked-objects-menu').addClass('active');
327				} else {
328					$this.find('.js-marked-objects-menu').removeClass('active');
329				}
330			});
331		},
332		_decodeOrder: function (val) {
333			var result = {};
334			var vals = val ? val.split(',') : [];
335			for (var i in vals) {
336				var matches = /^(.+)\-(asc|desc)$/.exec(vals[i]);
337				if (matches !== null) {
338					result[matches[1]] = matches[2];
339				}
340			}
341			return result;
342		},
343		_encodeOrder: function (vals) {
344			var result = [];
345			for (var i in vals) {
346				result.push(i + '-' + vals[i]);
347			}
348			return result.join(',');
349		},
350		_find: function (elem) {
351			return this.each(function () {
352				var $this = $(this);
353				var options = $this.data(className).options;
354				var $elem = null;
355				if ((elem !== undefined) && (elem !== null)) {
356					$elem = $(elem);
357				}
358
359				var requestData = $this.presenter('getParams');
360				requestData['modes'].push('in_array');
361				if (($elem !== null) && $elem.hasClass('js-show-more-control')) {
362					requestData['modes'].push('show_more');
363				}
364
365				var requestUrl = '';
366				if (($this.attr('data-url') !== undefined) && $this.attr('data-url')) {
367					requestUrl = $this.attr('data-url');
368				} else if ($this.hasClass('js-media-manager')) {
369					requestUrl = options.requestUrlPrefix + options.requestUrl.getMediaObjects;
370				} else if ($this.hasClass('js-rel-objects-presenter')) {
371					requestUrl = options.requestUrlPrefix + options.requestUrl.getRelObjects;
372				} else {
373					requestUrl = options.requestUrlPrefix + options.requestUrl.getObjects;
374				}
375
376				appUtils.executeRequest({
377					$parentElem: $this,
378					data: requestData,
379					elem: elem,
380					result: {
381						action: 'presenter._after-find',
382						type: 'action'
383					},
384					url: requestUrl
385				});
386			});
387		}
388	};
389
390	$.fn.presenter = function (param) {
391		if (methods[param]) {
392			return methods[param].apply(this, Array.prototype.slice.call(arguments, 1));
393		} else if ((typeof param === 'object') || !param) {
394			return methods.init.apply(this, arguments);
395		} else {
396			$.error('Method not found [jQuery.' + className + '.' + param + ']');
397		}
398	};
399
400})(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.