PageSourceSearch

https://wmr.tokyo/wp-content/themes/affinger/js/st-load-more.js?ver=7.0.6

js wmr.tokyo collected 2026-10-05 07:46:40 UTC 3,014 bytes, 141 lines download raw bytes

1;(function (window, document, $, ST, undefined) {
2	'use strict';
3
4	var LoadMore = (function () {
5		/**
6		 * @param {jQuery} $element
7		 *
8		 * @constructor
9		 */
10		function LoadMore($element) {
11			var self = this;
12
13			this._$element = $element;
14			this._$state   = $();
15			this._handlers = {
16				onClick: function (event) {
17					self.onClick(event);
18				}
19			};
20		}
21
22		/**
23		 * @param {Object<string, *>} data
24		 */
25		LoadMore.prototype.update = function (data) {
26			var $html;
27			var $content;
28			var $target;
29
30			this._$element.data('st-load-more', data.options);
31
32			$html = $(data.html);
33
34			$content = $html.find('[data-st-load-more-content]')
35				.addBack()
36				.filter('[data-st-load-more-content]');
37
38			$content = $content.length ? $content.children() : $html;
39			$target  = $('[data-st-load-more-id="' + this._$element.attr('data-st-load-more-controls') + '"]');
40
41			if ($target.length) {
42				$target.append($content);
43			}
44
45			if (!data.has_next) {
46				this.removeEventListeners();
47				this._$element.remove();
48			}
49		};
50
51		/**
52		 * @param {Event} event
53		 */
54		LoadMore.prototype.onClick = function (event) {
55			var self = this;
56			var data;
57
58			event.preventDefault();
59			event.stopImmediatePropagation();
60
61			self._$element.prop('disabled', true);
62			self._$state.addClass('is-loading');
63
64			data = self._$element.data('st-load-more');
65
66			$.ajax({
67				url    : ST.ajax_url,
68				headers: {
69					'X-Requested-With': 'XMLHttpRequest'
70				},
71				type   : 'GET',
72				data   : data
73			})
74				.done(function (response) {
75					if (!response.success) {
76						return;
77					}
78
79					self.update(response.data);
80				})
81				.fail(function (jqXHR, textStatus, errorThrown) {
82				})
83				.always(function () {
84					self._$state.removeClass('is-loading');
85
86					self._$element.prop('disabled', false);
87				});
88		};
89
90		LoadMore.prototype.prepareStateImage = function () {
91			var state;
92			var $state;
93			var $img;
94
95			state = (this._$element.attr('data-st-load-more-loading-img') || '').trim();
96
97			if (state === '') {
98				return;
99			}
100
101			$img = $('<img />', {src: state});
102
103			$state = $('<div></div>', {'class': 'load-more-state'})
104				.append($img);
105
106			this._$element.after($state);
107
108			this._$state = $state;
109		};
110
111		LoadMore.prototype.addEventListeners = function () {
112			this._$element.on('click', this._handlers.onClick);
113		};
114
115		LoadMore.prototype.removeEventListeners = function () {
116			this._$element.off('click', this._handlers.onClick);
117		};
118
119		LoadMore.prototype.initialize = function () {
120			this.prepareStateImage();
121			this.addEventListeners();
122		};
123
124		return LoadMore;
125	}());
126
127	function onReady() {
128		var loadMores = [];
129
130		$('[data-st-load-more]').each(function () {
131			var $element = $(this);
132			var loadMore = new LoadMore($element);
133
134			loadMores.push(loadMore);
135
136			loadMore.initialize();
137		});
138	}
139
140	$(onReady);
141}(window, window.document, jQuery, ST));

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.