Thành viên:Mxn/warnclosing.js

/* 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.";
    }
});

 

Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia