MediaWiki:Gadget-warnclosing.js

Từ điển mở Wiktionary

Chú ý: Sau khi lưu trang này, phải xóa bộ nhớ đệm (cache) của trình duyệt để những thay đổi hiện ra

  • Firefox / Safari: Nhấn giữ phím Shift trong khi nhấn Tải lại (Reload), hoặc nhấn tổ hợp Ctrl-F5 hay Ctrl-R (⌘R trên Mac)
  • Google Chrome: Nhấn tổ hợp Ctrl-Shift-R (⇧⌘R trên Mac)
  • Internet Explorer / Edge: Nhấn giữ phím Ctrl trong khi nhấn Làm tươi (Refresh), hoặc nhấn tổ hợp Ctrl-F5
  • Opera: Nhấn tổ hợp Ctrl-F5.
// **********************************************************************
// **                 ***WARNING GLOBAL GADGET FILE***                 **
// **             changes to this file affect many users.              **
// **           please discuss on the talk page before editing         **
// **                                                                  **
// **********************************************************************
// Imported from [[w:Thành viên:Mxn/warnclosing.js]], version as of: 2007-01-23T01:08
// Warn when closing an edited page

// Generalized version of hookEvent() in wikibits.js
var hookEvent = function (hookTarget, hookName, hookFunct) {
    if (!hookTarget) return;
    if (hookTarget.addEventListener) {
        hookTarget.addEventListener(hookName, hookFunct, false);
    }
    else if (hookTarget.attachEvent) {
        hookTarget.attachEvent("on" + hookName, hookFunct);
    }
}
 
// Record original text and attach onsubmit event to the form
editFormSubmitting = false;
$(function () {
    var editForm = document.getElementById("editform");
    var editBox = document.getElementById("wpTextbox1");
    if (!editForm || !editBox) return;
 
    wpTextbox1_orig = editBox.value;
    hookEvent(editForm, "submit", function () {
        editFormSubmitting = true;
    });
});
 
// Warn if text has changed or changes are being previewed
hookEvent(window, "beforeunload", function (e) {
    e = (window.event) ? window.event : e;
    var editBox = document.getElementById("wpTextbox1");
    if (editFormSubmitting || !editBox || !wpTextbox1_orig) return;
 
    var preview = document.getElementById("wikiPreview");
    var previewNote = getElementsByClassName(preview, "div", "previewnote");
    var isPreview = previewNote && previewNote.length > 0;
    var textChanged = editBox.value != wpTextbox1_orig;
    if (isPreview || textChanged) {
        return e.returnValue = "Tất cả các sửa đổi sẽ bị hủy vì bạn chưa lưu trang.";
    }
});