PageSourceSearch

https://sbschool.org/js/frontend/forums.js

js sbschool.org collected 2026-10-03 21:38:52 UTC 6,209 bytes, 175 lines download raw bytes

1/* ----------------------------------------------------------------------------------------------------------------------- */
2/* Create/Edit Thread/Reply JS ------------------------------------------------------------------------------------------- */
3/* ----------------------------------------------------------------------------------------------------------------------- */
4if($('#add-topic-form').length) {
5	/* --------------------------------------------------------------------------------- */
6	/* Bulk Upload Handling ------------------------------------------------------------ */
7	/* --------------------------------------------------------------------------------- */
8	function check_photo_status() {
9		if($("#photos-table tbody tr").length == 0) {
10			$("#photos-table").hide();
11		} else {
12			$("#photos-table").show();
13		}
14		do_image_table_draggable();
15	}
16	check_photo_status();
17
18	function do_image_table_draggable() {
19		$("#photos-table").tableDnD({
20			onDragClass: "dragClass",
21			dragHandle: "dragHandle",
22			onDrop: function(table, row) {
23				x = 0;
24				$('#photos-table .table-image-row').each(function() {
25					$(this).find('input, textarea').each(function() {
26						$(this).attr('name','images['+x+']['+$(this).attr('data-name')+']');
27					});
28					x++;
29				});
30			}
31		});
32	}
33
34
35	// Tell FileDrop we want to integrate with jQuery
36	fd.jQuery();
37
38	var options = {
39		iframe: {url: file_upload_submit_url+'&do_file_upload=1'},
40		multiple: true
41	};
42
43	$('#photo-upload-progress').css({'opacity':0});
44
45	$('#upload-photos-button')
46		// Create FileDrop on the first node in this collection.
47		.filedrop(options)
48		.on('fdsend', function (jQueryEvent, files) {
49			// 'fd' prefix is added to all FileDrop events that
50			// are triggered on the zone element.
51			files.each(function (file) {
52				// Reset the progress when a new upload starts:
53				file.event('sendXHR', function () {
54					$('#photo-upload-progress').css({'opacity':1});
55					$('#photo-upload-progress-bar').css({'width':0});
56				});
57
58				// Update progress when browser reports it:
59				file.event('progress', function (current, total) {
60					var width = current / total * 100 + '%'
61					$('#photo-upload-progress-bar').css({'width':width});
62				});
63
64				file.sendTo(file_upload_submit_url+'&do_file_upload=1');
65			});
66		})
67		.on('filedone', function (e, file, xhr) {
68			$('#photo-upload-progress').css({'opacity':0});
69			$('#photo-upload-progress-bar').css({'width':0});
70
71			var response = $.parseJSON(xhr.responseText);
72			if(response.errors) {
73				showAlert(response.errors,'bad');
74
75			} else if(response.name) {
76
77				response.pending = 1;
78				response.active = 1;
79				response.path = '/'+response.path;
80
81				has_file_uploads = 1;
82				add_photo_to_table(response);
83				check_photo_status();
84
85			} else {
86				showAlert('There was a problem uploading your file.','bad');
87			}
88		})
89		.on('fileerror', function (e, file, xhrError, xhr) {
90			showAlert('Error uploading ' + file.name + ': ' + xhr.status + ', ' + xhr.statusText,'bad');
91		})
92		.on('fdiframedone', function (e, xhr) {
93			showAlert('Done uploading via <iframe>, response:\n\n' + xhr.responseText);
94		});
95
96	$("#upload-photos-button .button").click(function() { return false; });
97
98
99	/* --------------------------------------------------------------------------------- */
100	/* Parse/Add Images to Slideshow Table --------------------------------------------- */
101	/* --------------------------------------------------------------------------------- */
102	function add_photo_to_table(data) {
103		var table = $("#photos-table");
104
105		var x = $('.table-image-row').length;
106
107		if(data.name && data.path) {
108			var html = '<tr class="table-image-row">';
109			html += '<td class="dragHandle"><input type="hidden" data-name="path" name="images['+x+'][path]" value="'+data.path+'" /><input type="hidden" data-name="name" name="images['+x+'][name]" value="'+data.name+'" /><input type="hidden" class="pending-field" data-name="pending" name="images['+x+'][pending]" value="'+(data.pending?data.pending:0)+'" /><img src="'+shared_root+'/images/icons/icon_drag.gif" alt="" border="0" /></td>';
110			html += '<td><img src="'+(data.path.indexOf('static-gallery')>=0?'http://'+domain:'')+data.path+data.name+'" width="100" /></td>';
111			// html += '<td><textarea data-name="caption" class="caption-textarea" name="images['+x+'][caption]">'+(data.caption?data.caption:'')+'</textarea></td>';
112			html += '<td><a href="#" class="button delete-image small">Remove</a></td>';
113			html += '</tr>';
114
115			$(table).find('tbody').append(html);
116			check_photo_status();
117		}
118	}
119
120	$(document).on('click','.delete-image',function(e) {
121		e.preventDefault();
122		var row = $(this).closest('tr');
123		var field = $(this).closest('td').find('.delete-image-checkbox');
124		swal({
125			title: 'Are you sure you want to remove this photo?',
126			text: '',
127			type: 'warning',
128			showCancelButton: true,
129			confirmButtonColor: "#DD6B55",
130			confirmButtonText: "Yes, remove it!",
131			closeOnConfirm: true
132		},function(){
133			$(row).fadeOut('slow',function() {
134				$(this).remove();
135				check_photo_status();
136			});
137		});
138
139		return false;
140	});
141
142	if(gallery_data.images) {
143		for(i=0;i<gallery_data.images.length;i++) {
144			if(gallery_data.images[i]) {
145				add_photo_to_table(gallery_data.images[i]);
146			}
147		}
148	}
149}
150
151if($('.delete-thread-button').length) {
152	$(document).on('click','.delete-thread-button',function(e) {
153		e.preventDefault();
154		var thehref = $(this).attr('href');
155
156		swal({
157			title: 'Are you sure you want to delete this thread?',
158			text: 'This cannot be undone!',
159			type: 'warning',
160			showCancelButton: true,
161			confirmButtonColor: "#DD6B55",
162			confirmButtonText: "Yes, delete it!",
163			closeOnConfirm: true
164		},function(){
165			window.location.href = thehref;
166		});
167
168		return false;
169	});
170}
171
172
173/* --------------------------------------------------------------------------------- */
174/* Mosaic Handling ----------------------------------------------------------------- */
175/* --------------------------------------------------------------------------------- */

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.