$_msg_use_alternative_link = 'Please go to the following link destination: $1';
$_msg_general_error = 'An error occurred while processing.';
+$_msg_edit_cancel_confirm = 'The text you have entered will be discarded. Is it OK?';
+$_msg_edit_unloadbefore_message = 'Data you have entered will not be saved.';
+
///////////////////////////////////////
// Symbols
$_symbol_anchor = '†';
$_msg_use_alternative_link = 'リンク先の機能をご利用ください: $1';
$_msg_general_error = '処理中にエラーが発生しました。';
+$_msg_edit_cancel_confirm = '編集中のテキストは破棄されます。よろしいですか ?';
+$_msg_edit_unloadbefore_message = '入力したデータは保存されません。';
+
///////////////////////////////////////
// Symbols
$_symbol_anchor = '†';
*/
function get_html_scripting_data()
{
- global $ticket_link_sites;
+ global $ticket_link_sites, $plugin;
if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) {
return '';
}
$site_props = <<<EOS
<div data-key="site-props" data-value="$props_json"></div>
EOS;
+ $h_plugin = htmlsc($plugin);
+ $plugin_prop = <<<EOS
+<input type="hidden" class="plugin-name" value="$h_plugin" />
+EOS;
+
// AutoTicketLink
$filtered_ticket_link_sites = array();
foreach ($ticket_link_sites as $s) {
$data = <<<EOS
<div id="pukiwiki-site-properties" style="display:none;">
$site_props
+$plugin_prop
$ticketlink_data
</div>
EOS;
global $whatsnew, $_btn_template, $_btn_load, $load_template_func;
global $notimeupdate;
global $_title_list, $_label_template_pages;
+ global $_msg_edit_cancel_confirm, $_msg_edit_unloadbefore_message;
global $rule_page;
$script = get_base_uri();
// 'margin-bottom', 'float:left', and 'margin-top'
// are for layout of 'cancel button'
+ $h_msg_edit_cancel_confirm = htmlsc($_msg_edit_cancel_confirm);
+ $h_msg_edit_unloadbefore_message = htmlsc($_msg_edit_unloadbefore_message);
$body = <<<EOD
<div class="edit_form">
- <form action="$script" method="post" style="margin-bottom:0px;">
+ <form action="$script" method="post" class="_plugin_edit_edit_form" style="margin-bottom:0px;">
$template
$addtag
<input type="hidden" name="cmd" value="edit" />
<input type="hidden" name="page" value="$s_page" />
<input type="hidden" name="digest" value="$s_digest" />
+ <input type="hidden" id="_msg_edit_cancel_confirm" value="$h_msg_edit_cancel_confirm" />
+ <input type="hidden" id="_msg_edit_unloadbefore_message" value="$h_msg_edit_unloadbefore_message" />
<textarea name="msg" rows="$rows" cols="$cols">$s_postdata</textarea>
<br />
<div style="float:left;">
</div>
<textarea name="original" rows="1" cols="1" style="display:none">$s_original</textarea>
</form>
- <form action="$script" method="post" style="margin-top:0px;">
+ <form action="$script" method="post" class="_plugin_edit_cancel" style="margin-top:0px;">
<input type="hidden" name="cmd" value="edit" />
<input type="hidden" name="page" value="$s_page" />
<input type="submit" name="cancel" value="$_btn_cancel" accesskey="c" />
var target = document.getElementById('body');
walkElement(target);
}
+ function confirmEditFormLeaving() {
+ function trim(s) {
+ if (typeof s !== 'string') {
+ return s;
+ }
+ return s.replace(/^\s+|\s+$/g, '');
+ }
+ if (!document.querySelector) return;
+ var canceled = false;
+ var pluginNameE = document.querySelector('#pukiwiki-site-properties .plugin-name');
+ if (!pluginNameE) return;
+ var originalText = null;
+ if (pluginNameE.value !== 'edit') return;
+ var editForm = document.querySelector('.edit_form form._plugin_edit_edit_form');
+ if (!editForm) return;
+ var cancelMsgE = editForm.querySelector('#_msg_edit_cancel_confirm');
+ var unloadBeforeMsgE = editForm.querySelector('#_msg_edit_unloadbefore_message');
+ var textArea = editForm.querySelector('textarea[name="msg"]');
+ if (!textArea) return;
+ originalText = textArea.value;
+ var cancelForm = document.querySelector('.edit_form form._plugin_edit_cancel');
+ var submited = false;
+ editForm.addEventListener('submit', function() {
+ canceled = false;
+ submited = true;
+ });
+ cancelForm.addEventListener('submit', function() {
+ submited = false;
+ canceled = false;
+ if (trim(textArea.value) === trim(originalText)) {
+ canceled = true;
+ return false;
+ }
+ var message = 'The text you have entered will be discarded. Is it OK?';
+ if (cancelMsgE && cancelMsgE.value) {
+ message = cancelMsgE.value;
+ }
+ if (window.confirm(message)) { // eslint-disable-line no-alert
+ // Execute "Cancel"
+ canceled = true;
+ return true;
+ }
+ return false;
+ });
+ window.addEventListener('beforeunload', function(e) {
+ if (canceled) return;
+ if (submited) return;
+ if (trim(textArea.value) === trim(originalText)) return;
+ var message = 'Data you have entered will not be saved.';
+ if (unloadBeforeMsgE && unloadBeforeMsgE.value) {
+ message = unloadBeforeMsgE.value;
+ }
+ e.returnValue = message;
+ }, false);
+ }
setYourName();
autoTicketLink();
+ confirmEditFormLeaving();
});