МедијаВики:Gadget-LongEditSummaries.js

Од Википедија — слободната енциклопедија

Напомена: По објавувањето може да треба да го исчистите меѓускладот (кеш) на прелистувачот за да можете ги видите промените.

  • Firefox / Safari: Држете Shift и стиснете на Превчитај (Reload) или притиснете Ctrl-F5 или Ctrl-R (⌘-R на Mac);
  • Google Chrome: Притиснете Ctrl-Shift-R (⌘-R на Mac)
  • Internet Explorer / Edge: Држете Ctrl додека притискате на Refresh или притиснете Ctrl-F5.
  • Opera: Стиснете на Ctrl-F5.
// LIMIT EDIT SUMMARIES TO EXACTLY 250 UTF-8 BYTES
// see EditPage::importFormData() in MediaWiki source for the source of the limit
// created by Ilmari Karonen and Remember_the_dot

$(function() {
    var wpSummary = document.getElementById("wpSummary")
    if (wpSummary) {
        var adjustMaxLength = function () {
            // subtract the number of UTF-8 continuation bytes (0x80-0xBF) from the maxlength
            var maxLength = 250 - encodeURI(wpSummary.value).split(/%[89AB]/i).length + 1
            wpSummary.maxLength = maxLength
            
            // the last character or group might've pushed us over; if so, inform the user
            var errorMessage = document.getElementById("editSummaryTooLong")
            if (wpSummary.value.length > maxLength) {
                if (!errorMessage) {
                    wpSummary.style.border = "3px solid red"
                    document.getElementById("wpSave").disabled = true
                    var editSummaryTooLong = document.createElement("div")
                    editSummaryTooLong.id = "editSummaryTooLong"
                    editSummaryTooLong.style.color = "red"
                    editSummaryTooLong.style.fontWeight = "bold"
                    editSummaryTooLong.appendChild(document.createTextNode("Описот ви е предолг."))
                    var wpMinoredit = document.getElementById("wpMinoredit")
                    wpMinoredit.parentNode.insertBefore(editSummaryTooLong, wpMinoredit)
                }
            } else {
                if (errorMessage) {
                    wpSummary.style.border = ""
                    document.getElementById("wpSave").disabled = false
                    errorMessage.parentNode.removeChild(errorMessage)
                }
            }
            oldValue = wpSummary.value
        }
        wpSummary.addEventListener("keyup", adjustMaxLength)
        wpSummary.addEventListener("change", adjustMaxLength)
        adjustMaxLength()
    }
})