• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiondcc6b19cb04618da87a41965a10db2f48b37c25e (tree)
Zeit2017-11-06 08:15:18
Autorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2453 Show alert message for leaving page action on editing

Ändern Zusammenfassung

Diff

--- a/en.lng.php
+++ b/en.lng.php
@@ -59,6 +59,9 @@ $_msg_unsupported_webbrowser = 'This function doesn\'t support your current Web
5959 $_msg_use_alternative_link = 'Please go to the following link destination: $1';
6060 $_msg_general_error = 'An error occurred while processing.';
6161
62+$_msg_edit_cancel_confirm = 'The text you have entered will be discarded. Is it OK?';
63+$_msg_edit_unloadbefore_message = 'Data you have entered will not be saved.';
64+
6265 ///////////////////////////////////////
6366 // Symbols
6467 $_symbol_anchor = '&dagger;';
--- a/ja.lng.php
+++ b/ja.lng.php
@@ -61,6 +61,9 @@ $_msg_unsupported_webbrowser = 'この機能はお使いのWebブラウザには
6161 $_msg_use_alternative_link = 'リンク先の機能をご利用ください: $1';
6262 $_msg_general_error = '処理中にエラーが発生しました。';
6363
64+$_msg_edit_cancel_confirm = '編集中のテキストは破棄されます。よろしいですか ?';
65+$_msg_edit_unloadbefore_message = '入力したデータは保存されません。';
66+
6467 ///////////////////////////////////////
6568 // Symbols
6669 $_symbol_anchor = '&dagger;';
--- a/lib/html.php
+++ b/lib/html.php
@@ -218,7 +218,7 @@ function _decorate_Nth_word($matches)
218218 */
219219 function get_html_scripting_data()
220220 {
221- global $ticket_link_sites;
221+ global $ticket_link_sites, $plugin;
222222 if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) {
223223 return '';
224224 }
@@ -243,6 +243,11 @@ EOS;
243243 $site_props = <<<EOS
244244 <div data-key="site-props" data-value="$props_json"></div>
245245 EOS;
246+ $h_plugin = htmlsc($plugin);
247+ $plugin_prop = <<<EOS
248+<input type="hidden" class="plugin-name" value="$h_plugin" />
249+EOS;
250+
246251 // AutoTicketLink
247252 $filtered_ticket_link_sites = array();
248253 foreach ($ticket_link_sites as $s) {
@@ -259,6 +264,7 @@ EOS;
259264 $data = <<<EOS
260265 <div id="pukiwiki-site-properties" style="display:none;">
261266 $site_props
267+$plugin_prop
262268 $ticketlink_data
263269 </div>
264270 EOS;
@@ -273,6 +279,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
273279 global $whatsnew, $_btn_template, $_btn_load, $load_template_func;
274280 global $notimeupdate;
275281 global $_title_list, $_label_template_pages;
282+ global $_msg_edit_cancel_confirm, $_msg_edit_unloadbefore_message;
276283 global $rule_page;
277284
278285 $script = get_base_uri();
@@ -381,14 +388,18 @@ EOD;
381388
382389 // 'margin-bottom', 'float:left', and 'margin-top'
383390 // are for layout of 'cancel button'
391+ $h_msg_edit_cancel_confirm = htmlsc($_msg_edit_cancel_confirm);
392+ $h_msg_edit_unloadbefore_message = htmlsc($_msg_edit_unloadbefore_message);
384393 $body = <<<EOD
385394 <div class="edit_form">
386- <form action="$script" method="post" style="margin-bottom:0px;">
395+ <form action="$script" method="post" class="_plugin_edit_edit_form" style="margin-bottom:0px;">
387396 $template
388397 $addtag
389398 <input type="hidden" name="cmd" value="edit" />
390399 <input type="hidden" name="page" value="$s_page" />
391400 <input type="hidden" name="digest" value="$s_digest" />
401+ <input type="hidden" id="_msg_edit_cancel_confirm" value="$h_msg_edit_cancel_confirm" />
402+ <input type="hidden" id="_msg_edit_unloadbefore_message" value="$h_msg_edit_unloadbefore_message" />
392403 <textarea name="msg" rows="$rows" cols="$cols">$s_postdata</textarea>
393404 <br />
394405 <div style="float:left;">
@@ -399,7 +410,7 @@ $template
399410 </div>
400411 <textarea name="original" rows="1" cols="1" style="display:none">$s_original</textarea>
401412 </form>
402- <form action="$script" method="post" style="margin-top:0px;">
413+ <form action="$script" method="post" class="_plugin_edit_cancel" style="margin-top:0px;">
403414 <input type="hidden" name="cmd" value="edit" />
404415 <input type="hidden" name="page" value="$s_page" />
405416 <input type="submit" name="cancel" value="$_btn_cancel" accesskey="c" />
--- a/skin/main.js
+++ b/skin/main.js
@@ -220,6 +220,63 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
220220 var target = document.getElementById('body');
221221 walkElement(target);
222222 }
223+ function confirmEditFormLeaving() {
224+ function trim(s) {
225+ if (typeof s !== 'string') {
226+ return s;
227+ }
228+ return s.replace(/^\s+|\s+$/g, '');
229+ }
230+ if (!document.querySelector) return;
231+ var canceled = false;
232+ var pluginNameE = document.querySelector('#pukiwiki-site-properties .plugin-name');
233+ if (!pluginNameE) return;
234+ var originalText = null;
235+ if (pluginNameE.value !== 'edit') return;
236+ var editForm = document.querySelector('.edit_form form._plugin_edit_edit_form');
237+ if (!editForm) return;
238+ var cancelMsgE = editForm.querySelector('#_msg_edit_cancel_confirm');
239+ var unloadBeforeMsgE = editForm.querySelector('#_msg_edit_unloadbefore_message');
240+ var textArea = editForm.querySelector('textarea[name="msg"]');
241+ if (!textArea) return;
242+ originalText = textArea.value;
243+ var cancelForm = document.querySelector('.edit_form form._plugin_edit_cancel');
244+ var submited = false;
245+ editForm.addEventListener('submit', function() {
246+ canceled = false;
247+ submited = true;
248+ });
249+ cancelForm.addEventListener('submit', function(e) {
250+ submited = false;
251+ canceled = false;
252+ if (trim(textArea.value) === trim(originalText)) {
253+ canceled = true;
254+ return false;
255+ }
256+ var message = 'The text you have entered will be discarded. Is it OK?';
257+ if (cancelMsgE && cancelMsgE.value) {
258+ message = cancelMsgE.value;
259+ }
260+ if (window.confirm(message)) { // eslint-disable-line no-alert
261+ // Execute "Cancel"
262+ canceled = true;
263+ return true;
264+ }
265+ e.preventDefault();
266+ return false;
267+ });
268+ window.addEventListener('beforeunload', function(e) {
269+ if (canceled) return;
270+ if (submited) return;
271+ if (trim(textArea.value) === trim(originalText)) return;
272+ var message = 'Data you have entered will not be saved.';
273+ if (unloadBeforeMsgE && unloadBeforeMsgE.value) {
274+ message = unloadBeforeMsgE.value;
275+ }
276+ e.returnValue = message;
277+ }, false);
278+ }
223279 setYourName();
224280 autoTicketLink();
281+ confirmEditFormLeaving();
225282 });