Fix a minor bug with downloads not working in the popup window. (#6)
Jeremy D

Jeremy D commited on 2023-03-29 18:35:55
Showing 3 changed files, with 41 additions and 31 deletions.


* Fix a minor bug with downloads not working in the popup window.

* Try to fix some eslint issues

* Try again

* Single quotes
... ...
@@ -30,5 +30,11 @@ module.exports = {
30 30
 				'args' : 'none'
31 31
 			}
32 32
 		]
33
+	},
34
+	'globals': {
35
+		'smf_scripturl': 'readonly',
36
+		'txt_devtools_menu': 'readonly',
37
+		'smc_PopupMenu': 'readonly',
38
+		'allow_xhjr_credentials': 'readonly'
33 39
 	}
34 40
 };
... ...
@@ -2,9 +2,9 @@
2 2
  * Javascript for DevTools.
3 3
  * @package DevTools
4 4
  * @author SleePy <sleepy @ simplemachines (dot) org>
5
- * @copyright 2022
5
+ * @copyright 2023
6 6
  * @license 3-Clause BSD https://opensource.org/licenses/BSD-3-Clause
7
- * @version 1.0
7
+ * @version 1.1
8 8
  */
9 9
 
10 10
 /* Load up some logic for devtools once we are ready */
... ...
@@ -19,13 +19,13 @@ $(document).ready(function() {
19 19
 	dev_menu.add('devtools', smf_scripturl + '?action=devtools');
20 20
 
21 21
 	/* Ensures admin login works */
22
-	$("div#devtools_menu").on("submit", "#frmLogin", {form: "div#devtools_menu #frmLogin"}, devtools_formhandler);
22
+	$('div#devtools_menu').on('submit', '#frmLogin', {form: 'div#devtools_menu #frmLogin'}, devtools_formhandler);
23 23
 
24 24
 	/* Ensures the hooks form works */
25
-	$("div#devtools_menu").on("submit", "#HooksList", {form: "div#devtools_menu #HooksList", frame: "div#devtools_container"}, devtools_formhandler);
25
+	$('div#devtools_menu').on('submit', '#HooksList', {form: 'div#devtools_menu #HooksList', frame: 'div#devtools_container'}, devtools_formhandler);
26 26
 
27 27
 	/* Fixes links on the popup to use ajax */
28
-	$("div#devtools_menu").on("click", "a",  devtools_links);
28
+	$('div#devtools_menu').on('click', 'a',  devtools_links);
29 29
 });
30 30
 
31 31
 /* Ensures admin login works */
... ...
@@ -33,55 +33,55 @@ function devtools_formhandler(e) {
33 33
 	e.preventDefault();
34 34
 	e.stopPropagation();
35 35
 
36
-	let form = $(e.data.form ?? "div#devtools_menu #frmLogin");
36
+	let form = $(e.data.form ?? 'div#devtools_menu #frmLogin');
37 37
 	let formData = form.serializeArray();
38 38
 
39 39
 	/* Inject the button/input that was clicked */
40 40
 	formData.push({ name: e.originalEvent.submitter.name, value: e.originalEvent.submitter.value });
41 41
 
42 42
 	$.ajax({
43
-		url: form.prop("action") + ";ajax",
44
-		method: "POST",
43
+		url: form.prop('action') + ';ajax',
44
+		method: 'POST',
45 45
 		headers: {
46
-			"X-SMF-AJAX": 1
46
+			'X-SMF-AJAX': 1
47 47
 		},
48 48
 		xhrFields: {
49
-			withCredentials: typeof allow_xhjr_credentials !== "undefined" ? allow_xhjr_credentials : false
49
+			withCredentials: typeof allow_xhjr_credentials !== 'undefined' ? allow_xhjr_credentials : false
50 50
 		},
51 51
 		data: formData,
52 52
 		success: function(data, status, xhr) {
53 53
 			if (typeof(e.data) !== 'undefined' && typeof(e.data.frame) !== 'undefined' && e.data.frame.length > 0) {
54 54
 				$(document).find(e.data.frame).html($(data).html());
55 55
 			}
56
-			else if (data.indexOf("<bo" + "dy") > -1) {
56
+			else if (data.indexOf('<bo' + 'dy') > -1) {
57 57
 				document.open();
58 58
 				document.write(data);
59 59
 				document.close();
60 60
 			}
61
-			else if (data.indexOf("<form") > -1) {
61
+			else if (data.indexOf('<form') > -1) {
62 62
 				form.html($(data).html());
63 63
 			}
64
-			else if ($(data).find(".roundframe").length > 0) {
65
-				form.parent().html($(data).find(".roundframe").html());
64
+			else if ($(data).find('.roundframe').length > 0) {
65
+				form.parent().html($(data).find('.roundframe').html());
66 66
 			}
67 67
 			else {
68 68
 				form.parent().html($(data).html());
69 69
 			}
70 70
 
71
-			($("div#devtools_menu").data("scrollable")).resize();
71
+			($('div#devtools_menu').data('scrollable')).resize();
72 72
 			checkSuccessFailPrompt(data);
73 73
 		},
74 74
 		error: function(xhr) {
75 75
 			var data = xhr.responseText;
76
-			if (data.indexOf("<bo" + "dy") > -1) {
76
+			if (data.indexOf('<bo' + 'dy') > -1) {
77 77
 				document.open();
78 78
 				document.write(data);
79 79
 				document.close();
80 80
 			}
81 81
 			else
82
-				form.parent().html($(data).filter("#fatal_error").html());
82
+				form.parent().html($(data).filter('#fatal_error').html());
83 83
 
84
-			($("div#devtools_menu").data("scrollable")).resize();
84
+			($('div#devtools_menu').data('scrollable')).resize();
85 85
 			checkSuccessFailPrompt(data);
86 86
 		}
87 87
 	});
... ...
@@ -91,23 +91,27 @@ function devtools_formhandler(e) {
91 91
 
92 92
 /* Fixes links on the popup to use ajax */
93 93
 function devtools_links(e) {
94
+	// If we need to skip the popup window, don't do anything.
95
+	if ($(this).attr('data-nopopup') && ($(this).attr('data-nopopup')) == 'true')
96
+		return;
97
+
94 98
 	e.preventDefault();
95 99
 	e.stopPropagation();
96 100
 
97 101
 	let currentLink = e.currentTarget.href;
98
-	let contentBox = $("div#devtools_menu .overview");
102
+	let contentBox = $('div#devtools_menu .overview');
99 103
 
100 104
 	$.ajax({
101
-		url: currentLink + ";ajax",
102
-		method: "GET",
105
+		url: currentLink + ';ajax',
106
+		method: 'GET',
103 107
 		headers: {
104
-			"X-SMF-AJAX": 1
108
+			'X-SMF-AJAX': 1
105 109
 		},
106 110
 		xhrFields: {
107
-			withCredentials: typeof allow_xhjr_credentials !== "undefined" ? allow_xhjr_credentials : false
111
+			withCredentials: typeof allow_xhjr_credentials !== 'undefined' ? allow_xhjr_credentials : false
108 112
 		},
109 113
 		success: function(data, status, xhr) {
110
-			if (data.indexOf("<bo" + "dy") > -1) {
114
+			if (data.indexOf('<bo' + 'dy') > -1) {
111 115
 				document.open();
112 116
 				document.write(data);
113 117
 				document.close();
... ...
@@ -115,20 +119,20 @@ function devtools_links(e) {
115 119
 			else
116 120
 				contentBox.html(data);
117 121
 
118
-			($("div#devtools_menu").data("scrollable")).resize();
122
+			($('div#devtools_menu').data('scrollable')).resize();
119 123
 			checkSuccessFailPrompt(data);
120 124
 		},
121 125
 		error: function(xhr) {
122 126
 			var data = xhr.responseText;
123
-			if (data.indexOf("<bo" + "dy") > -1) {
127
+			if (data.indexOf('<bo' + 'dy') > -1) {
124 128
 				document.open();
125 129
 				document.write(data);
126 130
 				document.close();
127 131
 			}
128 132
 			else
129
-				contentBox.html($(data).filter("#fatal_error").html());
133
+				contentBox.html($(data).filter('#fatal_error').html());
130 134
 
131
-			($("div#devtools_menu").data("scrollable")).resize();
135
+			($('div#devtools_menu').data('scrollable')).resize();
132 136
 			checkSuccessFailPrompt(data);
133 137
 		}
134 138
 	});
... ...
@@ -139,9 +143,9 @@ function checkSuccessFailPrompt(data)
139 143
 {
140 144
 	if ($(data).find('#devtool_success').length > 0)
141 145
 	{
142
-		$("#devtool_success").fadeOut(2000, function() {
146
+		$('#devtool_success').fadeOut(2000, function() {
143 147
 			$(this).remove();
144
-			($("div#devtools_menu").data("scrollable")).resize();
148
+			($('div#devtools_menu').data('scrollable')).resize();
145 149
 		});
146 150
 	}
147 151
 }
148 152
\ No newline at end of file
... ...
@@ -204,7 +204,7 @@ class DevToolsFiles
204 204
 
205 205
 		foreach ($this->providers as $provider)
206 206
 			foreach ($this->extensions as $ext)
207
-				$actions[$ext . $provider] = '<a href="' . $this->scripturl . '?action=devtools;area=files;sa=archive;package=' . $package['filename'] . ';extension=' . $ext . ';provider=' . $provider . '" class="button floatnone">' . $this->dt->txt('devtools_extension_' . $ext) . '</a>';
207
+				$actions[$ext . $provider] = '<a href="' . $this->scripturl . '?action=devtools;area=files;sa=archive;package=' . $package['filename'] . ';extension=' . $ext . ';provider=' . $provider . '" class="button floatnone" data-nopopup="true">' . $this->dt->txt('devtools_extension_' . $ext) . '</a>';
208 208
 
209 209
 		return implode('', $actions);
210 210
 	}
211 211