• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revision56b4beda04a1b6068ae5bffcb2c60d8209911957 (tree)
Time2018-04-28 05:47:24
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2468 Show alert message for leaving page action on edit-preview

Change Summary

Incremental Difference

--- a/lib/html.php
+++ b/lib/html.php
@@ -47,7 +47,7 @@ function catbody($title, $page, $body)
4747
4848 $_page = isset($vars['page']) ? $vars['page'] : '';
4949 $r_page = pagename_urlencode($_page);
50-
50+ $is_edit_preview = isset($vars['preview']);
5151 // Canonical URL
5252 $canonical_url = get_page_uri($_page, PKWK_URI_ABSOLUTE);
5353
@@ -187,7 +187,7 @@ function catbody($title, $page, $body)
187187 }
188188 }
189189 // Embed Scripting data
190- $html_scripting_data = get_html_scripting_data($_page);
190+ $html_scripting_data = get_html_scripting_data($_page, $is_edit_preview);
191191
192192 // Compat: 'HTML convert time' without time about MenuBar and skin
193193 $taketime = elapsedtime();
@@ -217,8 +217,11 @@ function _decorate_Nth_word($matches)
217217
218218 /**
219219 * Get data used by JavaScript modules
220+ *
221+ * @param $page page name
222+ * @param $in_editing true if preview in editing
220223 */
221-function get_html_scripting_data($page)
224+function get_html_scripting_data($page, $in_editing)
222225 {
223226 global $ticket_link_sites, $plugin;
224227 global $external_link_cushion_page, $external_link_cushion;
@@ -256,6 +259,11 @@ EOS;
256259 $page_name_data = <<<EOS
257260 <input type="hidden" class="page-name" value="$h_page_name" />
258261 EOS;
262+ // Page is editing (preview)
263+ $in_editing_value = ($plugin === 'edit' && $in_editing) ? 'true' : 'false';
264+ $page_edit_data = <<<EOS
265+<input type="hidden" class="page-in-edit" value="$in_editing_value" />
266+EOS;
259267 // AutoTicketLink
260268 $filtered_ticket_link_sites = array();
261269 foreach ($ticket_link_sites as $s) {
@@ -293,6 +301,7 @@ EOS;
293301 $site_props
294302 $plugin_prop
295303 $page_name_data
304+$page_edit_data
296305 $ticketlink_data
297306 $external_link_cushion_data
298307 $topicpath_data
--- a/skin/main.js
+++ b/skin/main.js
@@ -253,6 +253,11 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
253253 var textArea = editForm.querySelector('textarea[name="msg"]');
254254 if (!textArea) return;
255255 originalText = textArea.value;
256+ var isPreview = false;
257+ var inEditE = document.querySelector('#pukiwiki-site-properties .page-in-edit');
258+ if (inEditE && inEditE.value) {
259+ isPreview = (inEditE.value === 'true');
260+ }
256261 var cancelForm = document.querySelector('.edit_form form._plugin_edit_cancel');
257262 var submited = false;
258263 editForm.addEventListener('submit', function() {
@@ -281,7 +286,9 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
281286 window.addEventListener('beforeunload', function(e) {
282287 if (canceled) return;
283288 if (submited) return;
284- if (trim(textArea.value) === trim(originalText)) return;
289+ if (!isPreview) {
290+ if (trim(textArea.value) === trim(originalText)) return;
291+ }
285292 var message = 'Data you have entered will not be saved.';
286293 if (unloadBeforeMsgE && unloadBeforeMsgE.value) {
287294 message = unloadBeforeMsgE.value;
Show on old repository browser