Wikidotedit

Ozone and Programming
aa

WIKIDOT.modules.PageEditModule = {};
WIKIDOT.modules.PageEditModule.vars = {
    editMode: "page",
    stopCounterFlag: false,
    inputFlag: false,
    lastInput: (new Date()).getTime(),
    savedSource: "",
    handSaveDraft: false
};
WIKIDOT.modules.PageEditModule.listeners = {
    cancel: function(d, a) {
        var c = YAHOO.util.Event.removeListener(window, "beforeunload", WIKIDOT.modules.PageEditModule.listeners.leaveConfirm);
        YAHOO.util.Event.removeListener(window, "unload", WIKIDOT.modules.PageEditModule.listeners.leavePage);
        if ($("wikidot-disable-locks-flag")) {
            window.location.href = "/" + WIKIREQUEST.info.requestPageName;
            return
        }
        var b = new Object();
        if (WIKIREQUEST.info.pageId) {
            b.page_id = WIKIREQUEST.info.pageId
        }
        b.lock_id = WIKIDOT.page.vars.editlock.id;
        b.lock_secret = WIKIDOT.page.vars.editlock.secret;
        b.wiki_page = WIKIREQUEST.info.requestPageName;
        b.action = "WikiPageAction";
        b.event = "removePageEditLock";
        b.leave_draft = a;
        OZONE.ajax.requestModule("Empty", b, WIKIDOT.modules.PageEditModule.callbacks.cancel)
    },
    cancelWithDeleteDraftConfirmation: function(a) {
        var b = OZONE.utils.formToArray("edit-page-form");
        b.action = "WikiPageAction";
        b.event = "checkDraftExists";
        b.wiki_page = WIKIREQUEST.info.requestPageName;
        b.lock_id = WIKIDOT.page.vars.editlock.id;
        if (WIKIREQUEST.info.pageId) {
            b.page_id = WIKIREQUEST.info.pageId
        }
        OZONE.ajax.requestModule("Empty", b, WIKIDOT.modules.PageEditModule.callbacks.cancelWithDeleteDraftConfirmation)
    },
    cancelAndDeleteDraft: function(a) {
        WIKIDOT.modules.PageEditModule.listeners.cancel(a, false)
    },
    cancelAndLeaveDraft: function(a) {
        WIKIDOT.modules.PageEditModule.listeners.cancel(a, true)
    },
    preview: function(a) {
        var b = OZONE.utils.formToArray("edit-page-form");
        b.mode = WIKIDOT.modules.PageEditModule.vars.editMode;
        b.revision_id = WIKIDOT.page.vars.editlock.revisionId;
        b.page_unix_name = WIKIREQUEST.info.requestPageName;
        if (WIKIREQUEST.info.pageId) {
            b.pageId = WIKIREQUEST.info.pageId
        }
        OZONE.ajax.requestModule("edit/PagePreviewModule", b, WIKIDOT.modules.PageEditModule.callbacks.preview)
    },
    save: function(d, a) {
        var c = jQuery("#edit-page-form input[name='form-file-still-uploading']");
        if (c && (jQuery(c).val() > 0)) {
            if (!a) {
                var b = new OZONE.dialogs.WaitBox();
                b.content = "At least one file is still being uploaded, please wait.";
                b.show();
                jQuery(c).change(function() {
                    WIKIDOT.modules.PageEditModule.listeners.save(d, true)
                });
                WIKIDOT.modules.PageEditModule.utils.timerStop()
            }
            return false
        }
        var b = new OZONE.dialogs.WaitBox();
        b.content = "Saving page...";
        b.show();
        var f = OZONE.utils.formToArray("edit-page-form");
        f.action = "WikiPageAction";
        f.event = "savePage";
        f.mode = WIKIDOT.modules.PageEditModule.vars.editMode;
        f.wiki_page = WIKIREQUEST.info.requestPageName;
        f.lock_id = WIKIDOT.page.vars.editlock.id;
        if (WIKIREQUEST.info.pageId) {
            f.page_id = WIKIREQUEST.info.pageId
        }
        f.lock_secret = WIKIDOT.page.vars.editlock.secret;
        f.revision_id = WIKIDOT.page.vars.editlock.revisionId;
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "section") {
            f.range_start = WIKIDOT.page.vars.editlock.rangeStart;
            f.range_end = WIKIDOT.page.vars.editlock.rangeEnd
        }
        try {
            path = location.href.toString();
            if (zz = path.match(/\/tags\/([^\/]+)/)) {
                f.tags = decodeURIComponent(zz[1])
            }
        } catch (d) {}
        try {
            path = location.href.toString();
            if (zz = path.match(/\/parentPage\/([^\/]+)/)) {
                f.parentPage = decodeURIComponent(zz[1])
            }
        } catch (d) {}
        OZONE.ajax.requestModule("Empty", f, WIKIDOT.modules.PageEditModule.callbacks.save)
    },
    saveAndContinue: function(b) {
        var a = new OZONE.dialogs.WaitBox();
        a.content = "Saving page...";
        a.show();
        var c = OZONE.utils.formToArray("edit-page-form");
        c.action = "WikiPageAction";
        c.event = "savePage";
        c.mode = WIKIDOT.modules.PageEditModule.vars.editMode;
        c.wiki_page = WIKIREQUEST.info.requestPageName;
        c.lock_id = WIKIDOT.page.vars.editlock.id;
        if (WIKIREQUEST.info.pageId) {
            c.page_id = WIKIREQUEST.info.pageId
        }
        c.lock_secret = WIKIDOT.page.vars.editlock.secret;
        c.revision_id = WIKIDOT.page.vars.editlock.revisionId;
        c.and_continue = "yes";
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "section") {
            c.range_start = WIKIDOT.page.vars.editlock.rangeStart;
            c.range_end = WIKIDOT.page.vars.editlock.rangeEnd
        }
        OZONE.ajax.requestModule("Empty", c, WIKIDOT.modules.PageEditModule.callbacks.saveAndContinue)
    },
    saveDraft: function() {
        WIKIDOT.modules.PageEditModule.vars.handSaveDraft = true;
        var a = new OZONE.dialogs.WaitBox();
        a.content = "Saving draft...";
        a.show();
        WIKIDOT.modules.PageEditModule.utils.synchronize()
    },
    changeInput: function(a) {
        WIKIDOT.modules.PageEditModule.vars.inputFlag = true;
        WIKIDOT.modules.PageEditModule.vars.lastInput = (new Date()).getTime();
        WIKIDOT.modules.PageEditModule.utils.timerSetTimeLeft(15 * 60)
    },
    leaveConfirm: function(a) {
        if (YAHOO.env.ua.ie) {
            return
        }
        if (WIKIDOT.modules.PageEditModule.utils.sourceChanged()) {
            a.returnValue = "If you leave this page, all the unsaved changes will be lost."
        }
    },
    leavePage: function(b) {
        var a = new Object();
        a.action = "WikiPageAction";
        a.event = "removePageEditLock";
        a.lock_id = WIKIDOT.page.vars.editlock.id;
        a.lock_secret = WIKIDOT.page.vars.editlock.secret;
        OZONE.ajax.requestModule("Empty", a, WIKIDOT.modules.PageEditModule.callbacks.forcePageEditLockRemove)
    },
    forcePageEditLockRemove: function(a) {
        WIKIDOT.page.vars.forceLockFlag = true;
        OZONE.dialog.cleanAll();
        WIKIDOT.page.listeners.editClick(null)
    },
    forceLockIntercept: function(a) {
        var b = new Object();
        b.action = "WikiPageAction";
        b.event = "forceLockIntercept";
        b.mode = WIKIDOT.modules.PageEditModule.vars.editMode;
        b.wiki_page = WIKIREQUEST.info.requestPageName;
        if (WIKIREQUEST.info.pageId) {
            b.page_id = WIKIREQUEST.info.pageId
        }
        b.lock_id = WIKIDOT.page.vars.editlock.id;
        b.lock_secret = WIKIDOT.page.vars.editlock.secret;
        b.revision_id = WIKIDOT.page.vars.editlock.revisionId;
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "section") {
            b.range_start = WIKIDOT.page.vars.editlock.rangeStart;
            b.range_end = WIKIDOT.page.vars.editlock.rangeEnd
        }
        OZONE.ajax.requestModule("Empty", b, WIKIDOT.modules.PageEditModule.callbacks.forceLockIntercept)
    },
    recreateExpiredLock: function(a) {
        var b = new Object();
        b.action = "WikiPageAction";
        b.event = "recreateExpiredLock";
        b.mode = WIKIDOT.modules.PageEditModule.vars.editMode;
        b.wiki_page = WIKIREQUEST.info.requestPageName;
        b.lock_id = WIKIDOT.page.vars.editlock.id;
        if (WIKIREQUEST.info.pageId) {
            b.page_id = WIKIREQUEST.info.pageId
        }
        b.lock_secret = WIKIDOT.page.vars.editlock.secret;
        b.revision_id = WIKIDOT.page.vars.editlock.revisionId;
        b.since_last_input = 0;
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "section") {
            b.range_start = WIKIDOT.page.vars.editlock.rangeStart;
            b.range_end = WIKIDOT.page.vars.editlock.rangeEnd
        }
        OZONE.ajax.requestModule("Empty", b, WIKIDOT.modules.PageEditModule.callbacks.recreateExpiredLock)
    },
    templateChange: function(c) {
        if (!$("page-templates")) {
            return
        }
        var a = $("page-templates").value;
        var d = true;
        if (WIKIDOT.modules.PageEditModule.utils.sourceChanged()) {
            d = confirm("It seems you have already changed the page.\nChanging the initial template now will reset the edited page.\nDo you want to change the initial content?")
        }
        if (d) {
            WIKIDOT.modules.PageEditModule.vars.templateId = a;
            if (a == null || a == "") {
                $("edit-page-textarea").value = ""
            } else {
                var b = new Object();
                b.page_id = a;
                OZONE.ajax.requestModule("edit/TemplateSourceModule", b, WIKIDOT.modules.PageEditModule.callbacks.templateChange)
            }
        } else {
            $("page-templates").value = WIKIDOT.modules.PageEditModule.vars.templateId
        }
    },
    viewDiff: function(a) {
        var b = OZONE.utils.formToArray("edit-page-form");
        b.mode = WIKIDOT.modules.PageEditModule.vars.editMode;
        b.revision_id = WIKIDOT.page.vars.editlock.revisionId;
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "section") {
            b.range_start = WIKIDOT.page.vars.editlock.rangeStart;
            b.range_end = WIKIDOT.page.vars.editlock.rangeEnd
        }
        OZONE.ajax.requestModule("edit/PageEditDiffModule", b, WIKIDOT.modules.PageEditModule.callbacks.viewDiff)
    },
    confirmExpiration: function(a) {
        WIKIDOT.modules.PageEditModule.utils.deactivateAll();
        OZONE.dialog.cleanAll()
    },
    closeDiffView: function(a) {
        OZONE.visuals.scrollTo("action-area");
        setTimeout('$("view-diff-div").innerHTML=""', 250)
    },
    confirmCaptcha: function(a) {
        document.getElementById("recaptcha_challenge_field").value = document.getElementById("captcha-iframe").contentWindow.document.getElementById("recaptcha_challenge_field").value;
        document.getElementById("recaptcha_response_field").value = document.getElementById("captcha-iframe").contentWindow.document.getElementById("recaptcha_response_field").value;
        WIKIDOT.modules.PageEditModule.listeners.save()
    },
    loadDraft: function(a) {
        jQuery("#edit-page-textarea").text(WIKIDOT.page.vars.draftText);
        jQuery("#edit-page-title").val(WIKIDOT.page.vars.draftTitle);
        keyBindSavePage();
        OZONE.dialog.cleanAll();
        jQuery("body").scrollTo("#edit-page-textarea")
    }
};
WIKIDOT.modules.PageEditModule.callbacks = {
    preview: function(b) {
        if (!WIKIDOT.utils.handleError(b)) {
            return
        }
        var c = document.getElementById("preview-message").innerHTML;
        OZONE.utils.setInnerHTMLContent("action-area-top", c);
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "section") {
            OZONE.utils.setInnerHTMLContent("edit-section-content", b.body.replace(/id="/g, 'id="prev06-'));
            YAHOO.util.Dom.setY("action-area-top", YAHOO.util.Dom.getY("edit-section-content"));
            OZONE.visuals.scrollTo("edit-section-content")
        }
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "page") {
            var d = b.title;
            OZONE.utils.setInnerHTMLContent("page-title", d);
            OZONE.visuals.scrollTo("header");
            $j("#page-content").html($j("<div>" + b.body + "</div>").remove("script").html())
        }
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "append") {
            var a = $("append-preview-div");
            if (!a) {
                a = document.createElement("div");
                a.id = "append-preview-div";
                $("page-content").appendChild(a)
            }
            a.innerHTML = b.body.replace(/id="/g, 'id="prev06-');
            OZONE.visuals.scrollTo("append-preview-div");
            YAHOO.util.Dom.setY("action-area-top", YAHOO.util.Dom.getY("append-preview-div"))
        }
        WIKIDOT.modules.PageEditModule.utils.stripAnchors("page-content", "action-area")
    },
    viewDiff: function(a) {
        if (!WIKIDOT.utils.handleError(a)) {
            return
        }
        $j("#view-diff-div").html(a.body);
        OZONE.visuals.scrollTo("view-diff-div")
    },
    save: function(d) {
        $j("#edit-page-form.data-form .form-message").empty();
        $j("#edit-page-form.data-form .has-error").removeClass("has-error");
        $j(".form-table .form-error").removeClass("form-error");
        if (d.status == "form_errors") {
            var f = d.errors;
            for (var b in f) {
                $j(".field-" + b).addClass("form-error");
                $j(".field-" + b).parents(".form-group").addClass("has-error");
                $j(".field-" + b + " .form-message").append(f[b])
            }
            keyBindSavePage();
            OZONE.dialog.cleanAll();
            return
        }
        if (d.status == "need_captcha") {
            keyBindSavePage();
            $j("#edit-page-captcha").html(d.captcha);
            $j("body").scrollTo("#edit-page-captcha");
            $j("#edit-page-form input[name=mathCaptchaResult]").focus();
            OZONE.dialog.cleanAll();
            return
        }
        if (!WIKIDOT.utils.handleError(d)) {
            return
        }
        if (d.noLockError) {
            WIKIDOT.modules.PageEditModule.utils.timerStop();
            var a = new OZONE.dialogs.ErrorDialog();
            a.content = d.body;
            a.show();
            if (d.nonrecoverable == true) {
                WIKIDOT.modules.PageEditModule.utils.deactivateAll()
            }
            return
        }
        WIKIDOT.modules.PageEditModule.utils.timerStop();
        var c = new OZONE.dialogs.SuccessBox();
        c.timeout = 10000;
        c.content = "Page saved!";
        c.show();
        var e = WIKIREQUEST.info.requestPageName;
        if (d.pageUnixName) {
            e = d.pageUnixName
        }
        YAHOO.util.Event.removeListener(window, "beforeunload", WIKIDOT.modules.PageEditModule.listeners.leaveConfirm);
        YAHOO.util.Event.removeListener(window, "unload", WIKIDOT.modules.PageEditModule.listeners.leavePage);
        window.location.href = "/" + e
    },
    saveAndContinue: function(c) {
        if (!WIKIDOT.utils.handleError(c)) {
            return
        }
        if (c.noLockError) {
            WIKIDOT.modules.PageEditModule.utils.timerStop();
            var a = OZONE.dialog.factory.boxcontainer();
            a.setContent(c.body);
            a.showContent();
            if (c.nonrecoverable == true) {
                WIKIDOT.modules.PageEditModule.utils.deactivateAll()
            }
            return
        }
        var b = new OZONE.dialogs.SuccessBox();
        b.content = "Page saved!";
        b.show();
        setTimeout("OZONE.dialog.cleanAll()", 1000);
        WIKIDOT.modules.PageEditModule.utils.updateSavedSource();
        WIKIDOT.page.vars.editlock.revisionId = c.revisionId
    },
    cancel: function(a) {
        if (!WIKIDOT.utils.handleError(a)) {
            return
        }
        window.location.href = "/" + WIKIREQUEST.info.requestPageName
    },
    cancelWithDeleteDraftConfirmation: function(b) {
        if (!WIKIDOT.utils.handleError(b)) {
            return
        }
        if (b.draftExists == true) {
            var a = new OZONE.dialogs.Dialog();
            a.title = "Draft Exists";
            a.content = "<p>You have saved draft. Select one option</p>";
            a.buttons = ["Cancel and Delete Draft", "Cancel and Leave Draft"];
            a.addButtonListener("Cancel and Delete Draft", WIKIDOT.modules.PageEditModule.listeners.cancelAndDeleteDraft);
            a.addButtonListener("Cancel and Leave Draft", WIKIDOT.modules.PageEditModule.listeners.cancelAndLeaveDraft);
            a.show()
        } else {
            WIKIDOT.modules.PageEditModule.listeners.cancel("", false)
        }
        setTimeout("", 10000)
    },
    forcePageEditLockRemove: function(a) {
        if (!WIKIDOT.utils.handleError(a)) {
            return
        }
        WIKIDOT.page.listeners.editClick(null)
    },
    forceLockIntercept: function(c) {
        if (!WIKIDOT.utils.handleError(c)) {
            return
        }
        if (c.error) {
            alert("Unexpected error");
            return
        }
        if (c.nonrecoverable == true) {
            var a = OZONE.dialog.factory.boxcontainer();
            a.setContent(c.body);
            a.showContent()
        }
        WIKIDOT.modules.PageEditModule.utils.timerSetTimeLeft(c.timeLeft);
        WIKIDOT.modules.PageEditModule.utils.timerStart();
        WIKIDOT.page.vars.editlock.id = c.lock_id;
        WIKIDOT.page.vars.editlock.secret = c.lock_secret;
        var b = new OZONE.dialogs.SuccessBox();
        b.content = "Lock successfully acquired";
        b.show()
    },
    synchronize: function(c) {
        if (c.savedDraft == "true" && WIKIDOT.modules.PageEditModule.vars.handSaveDraft == true) {
            WIKIDOT.modules.PageEditModule.vars.handSaveDraft = false;
            var b = new OZONE.dialogs.SuccessBox();
            b.content = "Draft saved.";
            b.show()
        }
        if (!WIKIDOT.utils.handleError(c)) {
            return
        }
        if (c.noLockError) {
            OZONE.dialog.factory.shader().show();
            var a = OZONE.dialog.factory.boxcontainer();
            a.setContent(c.body);
            a.showContent();
            if (c.nonrecoverable == true) {
                WIKIDOT.modules.PageEditModule.utils.deactivateAll()
            }
            WIKIDOT.modules.PageEditModule.utils.timerStop();
            YAHOO.util.Event.removeListener(window, "beforeunload", WIKIDOT.modules.PageEditModule.listeners.leaveConfirm);
            YAHOO.util.Event.removeListener(window, "unload", WIKIDOT.modules.PageEditModule.listeners.leavePage);
            return
        }
        if (c.lockRecreated) {
            WIKIDOT.page.vars.editlock.id = c.lockId;
            WIKIDOT.page.vars.editlock.secret = c.lockSecret
        }
        WIKIDOT.modules.PageEditModule.utils.timerSetTimeLeft(c.timeLeft)
    },
    lockExpired: function(b) {
        if (!WIKIDOT.utils.handleError(b)) {
            return
        }
        OZONE.dialog.factory.shader().show();
        var a = OZONE.dialog.factory.boxcontainer();
        a.setContent(b.body);
        a.showContent()
    },
    recreateExpiredLock: function(c) {
        if (!WIKIDOT.utils.handleError(c)) {
            return
        }
        if (!c.lockRecreated) {
            OZONE.dialog.factory.shader().show();
            var a = OZONE.dialog.factory.boxcontainer();
            a.setContent(c.body);
            a.showContent()
        } else {
            WIKIDOT.page.vars.editlock.id = c.lockId;
            WIKIDOT.page.vars.editlock.secret = c.lockSecret;
            WIKIDOT.modules.PageEditModule.utils.timerSetTimeLeft(c.timeLeft);
            WIKIDOT.modules.PageEditModule.utils.timerStart();
            WIKIDOT.modules.PageEditModule.vars.lastInput = (new Date()).getTime();
            var b = new OZONE.dialogs.SuccessBox();
            b.content = "Lock successfully acquired.";
            b.show()
        }
    },
    templateChange: function(a) {
        if (!WIKIDOT.utils.handleError(a)) {
            return
        }
        if (a.body != null && a.body != "") {
            $("edit-page-textarea").value = a.body
        }
    }
};
WIKIDOT.modules.PageEditModule.utils = {
    sourceChanged: function() {
        var b = OZONE.utils.formToArray("edit-page-form");
        return (WIKIDOT.modules.PageEditModule.vars.savedSource != b.source)
    },
    updateSavedSource: function() {
        var b = OZONE.utils.formToArray("edit-page-form");
        WIKIDOT.modules.PageEditModule.vars.savedSource = b.source
    },
    stripAnchors: function(c, f) {
        var d = $(c);
        var b;
        if (f) {
            f = $(f);
            b = $j(f)
        }
        if (d) {
            var e = d.getElementsByTagName("a");
            for (i = 0; i < e.length; i++) {
                if (!f || $j(e[i]).parents().index(b) < 0) {
                    var a = e[i].href;
                    if (a == "javascript:;") {
                        continue
                    }
                    e[i].onclick = null;
                    e[i].target = "_blank";
                    YAHOO.util.Event.purgeElement(e[i])
                }
            }
        }
    },
    stripAnchorsAll: function() {
        WIKIDOT.modules.PageEditModule.utils.stripAnchors("html-body", "action-area")
    },
    leavePageWarning: function() {
        alert('Please do not leave the page while editing it.\nTo cancel the edit and lose your changes, click the "Cancel" button below the edit area.')
    },
    updateActiveButtons: function() {
        var a = $("edit-save-continue-button");
        if (a) {
            a.disabled = false;
            YAHOO.util.Dom.removeClass(a, "disabled")
        }
        $("edit-save-button").disabled = false;
        YAHOO.util.Dom.removeClass($("edit-save-button"), "disabled")
    },
    deactivateAll: function() {
        var a;
        a = $("edit-save-continue-button");
        if (a) {
            a.disabled = true
        }
        $("edit-save-button").disabled = true;
        jQuery("#lock-info").hide();
        jQuery("#edit-page-form").unbind("keydown change", WIKIDOT.modules.PageEditModule.listeners.changeInput);
        YAHOO.util.Event.removeListener(window, "beforeunload", WIKIDOT.modules.PageEditModule.listeners.leaveConfirm);
        YAHOO.util.Event.removeListener(window, "unload", WIKIDOT.modules.PageEditModule.listeners.leavePage);
        WIKIDOT.modules.PageEditModule.vars.stopCounterFlag = true
    },
    timerSetTimeLeft: function(a) {
        WIKIDOT.modules.PageEditModule.vars.lockExpire = (new Date()).getTime() + a * 1000
    },
    timerTick: function() {
        var b = WIKIDOT.modules.PageEditModule.vars.lockExpire - (new Date()).getTime();
        b = Math.round(b * 0.001);
        if (b < 0) {
            b = 0
        }
        jQuery("#lock-timer").text(b);
        if (b <= 0) {
            WIKIDOT.modules.PageEditModule.utils.lockExpired();
            return
        }
        var a = (new Date()).getTime() - WIKIDOT.modules.PageEditModule.vars.lockLastUpdated;
        if (a * 0.001 >= 60 || (b < 60 && WIKIDOT.modules.PageEditModule.vars.inputFlag)) {
            WIKIDOT.modules.PageEditModule.vars.inputFlag = false;
            WIKIDOT.modules.PageEditModule.vars.lockLastUpdated = (new Date()).getTime();
            WIKIDOT.modules.PageEditModule.utils.synchronize()
        }
    },
    timerStart: function() {
        if ($("wikidot-disable-locks-flag")) {
            return
        }
        WIKIDOT.modules.PageEditModule.vars.timerId = setInterval("WIKIDOT.modules.PageEditModule.utils.timerTick()", 1000)
    },
    timerStop: function() {
        if ($("wikidot-disable-locks-flag")) {
            return
        }
        clearInterval(WIKIDOT.modules.PageEditModule.vars.timerId)
    },
    synchronize: function() {
        if ($("wikidot-disable-locks-flag")) {
            return
        }
        var a = Math.round(((new Date()).getTime() - WIKIDOT.modules.PageEditModule.vars.lastInput) * 0.001);
        var b = OZONE.utils.formToArray("edit-page-form");
        b.action = "WikiPageAction";
        b.event = "synchronize";
        b.mode = WIKIDOT.modules.PageEditModule.vars.editMode;
        b.wiki_page = WIKIREQUEST.info.requestPageName;
        b.lock_id = WIKIDOT.page.vars.editlock.id;
        if (WIKIREQUEST.info.pageId) {
            b.page_id = WIKIREQUEST.info.pageId
        }
        b.lock_secret = WIKIDOT.page.vars.editlock.secret;
        b.revision_id = WIKIDOT.page.vars.editlock.revisionId;
        b.since_last_input = a;
        if (WIKIDOT.modules.PageEditModule.vars.editMode == "section") {
            b.range_start = WIKIDOT.page.vars.editlock.rangeStart;
            b.range_end = WIKIDOT.page.vars.editlock.rangeEnd
        }
        OZONE.ajax.requestModule("Empty", b, WIKIDOT.modules.PageEditModule.callbacks.synchronize)
    },
    lockExpired: function() {
        WIKIDOT.modules.PageEditModule.utils.timerStop();
        OZONE.ajax.requestModule("edit/LockExpiredWinModule", null, WIKIDOT.modules.PageEditModule.callbacks.lockExpired)
    },
    displayCaptchaDialog: function(a) {}
};
WIKIDOT.modules.PageEditModule.init = function() {
    if (WIKIDOT.page.vars.locked != true) {
        WIKIDOT.modules.PageEditModule.vars.editMode = editMode;
        YAHOO.util.Event.addListener("update-lock", "click", WIKIDOT.modules.PageEditModule.utils.synchronize);
        jQuery("#edit-page-form").bind("keydown change", WIKIDOT.modules.PageEditModule.listeners.changeInput);
        YAHOO.util.Event.addListener(window, "beforeunload", WIKIDOT.modules.PageEditModule.listeners.leaveConfirm);
        YAHOO.util.Event.addListener(window, "unload", WIKIDOT.modules.PageEditModule.listeners.leavePage);
        if (WIKIREQUEST.autoEdit != true) {
            WIKIDOT.modules.PageEditModule.utils.stripAnchorsAll()
        }
        WIKIDOT.modules.PageEditModule.utils.updateSavedSource();
        WIKIDOT.modules.PageEditModule.utils.updateActiveButtons();
        var g = window.location.pathname;
        var b;
        if (b = g.match(/^\/[a-z0-9\-:]+\/edit\/true\/t\/([0-9]+)/)) {
            var d = b[1];
            $("page-templates").value = d
        }
        try {
            if (b = g.match(/\/title\/([^\/]+)/)) {
                $("edit-page-title").value = decodeURIComponent(b[1])
            }
        } catch (f) {}
        if (!WIKIREQUEST.info.pageId) {
            WIKIDOT.modules.PageEditModule.listeners.templateChange(null)
        }
        WIKIDOT.modules.PageEditModule.utils.timerSetTimeLeft(60 * 15);
        WIKIDOT.modules.PageEditModule.vars.lockLastUpdated = (new Date().getTime());
        WIKIDOT.modules.PageEditModule.utils.timerStart();
        var h = $j("#edit-page-form.data-form");
        if (h.length > 0) {
            (function() {
                var e = $j;
                e(".dataform-pagepath-chooser", h).each(function() {
                    var q = e(this);
                    var k = e("input.dataform-pagepath-category", q).val();
                    var l = function() {
                        return e("input.dataform-pagepath-value", q).val()
                    };
                    var n = function(t) {
                        var t = t || "";
                        e("input.dataform-pagepath-value", q).val(t)
                    };
                    var o = function(t) {
                        return t.parent().children("select")
                    };
                    var s = function() {
                        var t = e("input.dataform-pagepath-max-level", q).val();
                        var u = e(".dataform-pagepath-chooser select", h).length;
                        if (t == 0) {
                            return false
                        }
                        return u >= t
                    };
                    var j = function(u, t, y) {
                        var x = e(u);
                        x.children().remove();
                        x.append('<option value=""/>');
                        if (t) {
                            for (var w = 0; w < t.length; w++) {
                                var v = t[w].unix_name;
                                var A = t[w].title;
                                var z = e("<option/>");
                                z.text(A);
                                z.attr("value", t[w].unix_name);
                                if (y == t[w].unix_name) {
                                    z.attr("selected", "selected")
                                }
                                x.append(z)
                            }
                        }
                        x.append('<option value="+" style="border-top: 1px #666 solid; font-weight: bold">Create new</option>')
                    };
                    var p = function(t, w) {
                        var t = e(t);
                        var v = o(t).val() || k + ":_root";
                        var u = {
                            s: WIKIREQUEST.info.siteId,
                            module: "PageLookupQModule",
                            q: k + ":",
                            parent: v
                        };
                        e.getJSON("/quickmodule.php", u, function(y, z) {
                            var x = e("<select/>").addClass("dataform-pagepath-select-children-of-" + v.replace(":", "---"));
                            j(x, y.pages);
                            t.text("");
                            if (v != k + ":_root") {
                                t.text(" / ")
                            }
                            x.change(m);
                            t.append(x);
                            t.append("<span/>");
                            if (typeof(w) == "function") {
                                w(x)
                            }
                        })
                    };
                    var r = function(t) {
                        var u = new Array();
                        e("option", t).each(function() {
                            var w = e(this).text();
                            var v = e(this).attr("value");
                            if (v != "+" && v != "") {
                                u.push({
                                    unix_name: v,
                                    title: w
                                })
                            }
                        });
                        return u
                    };
                    var m = function() {
                        var t = e(this);
                        var v = t.parent().children("span");
                        var u = t.val();
                        if (u == "+") {
                            v.text("");
                            var w = t.parent();
                            w.append(e('<input type="text" class="text" value="New item"/>').keypress(function(x) {
                                if ((x.which || x.keycode) == 13) {
                                    var z = e(this).val();
                                    var A = o(o(v).parent()).val();
                                    if (typeof(A) == "undefined") {
                                        A = ""
                                    }
                                    e("a", w).remove();
                                    e("input", w).replaceWith("<span>Creating...</span>");
                                    var y = {
                                        action: "DataFormAction",
                                        event: "newPage",
                                        category: k,
                                        parent: A,
                                        title: z
                                    };
                                    OZONE.ajax.requestModule("Empty", y, function(C) {
                                        var B = C.fullname;
                                        e("span", w).remove();
                                        p(t.parent(), function(E) {
                                            e("option[value='" + B + "']", E).attr("selected", "selected");
                                            E.val(B);
                                            E.change();
                                            var D = r(E);
                                            e("." + E.attr("class"), h).not(E).each(function() {
                                                j(e(this), D, e(this).val())
                                            })
                                        })
                                    })
                                }
                            }));
                            w.append(" ");
                            w.append(e('<a href="javascript:;">[x]</a>').click(function() {
                                t.show();
                                e("option[selected]", t).removeAttr("selected");
                                e("input", w).remove();
                                e(this).remove()
                            }));
                            t.hide();
                            e("input", w).focus().select()
                        } else {
                            if (u == "") {
                                v.text("");
                                n(o(o(v).parent()).val())
                            } else {
                                n(u);
                                v.text("");
                                if (!s()) {
                                    v.text(" / Loading...");
                                    p(v, u)
                                }
                            }
                        }
                    };
                    e("select", q).change(m)
                });
                e(".dataform-file-chooser", h).each(function() {
                    var n;
                    var l = e(this);
                    var r = e("div.input-group", l);
                    var s = e('<form method="POST" enctype="multipart/form-data"><input name="file" type="file"/></form>');
                    var m = e("input", s);
                    var v = e(l).parents("form#edit-page-form").children("input[name='form-file-still-uploading']");
                    var w = e.parseJSON(e(".dataform-file-data", l).text());
                    var u = function(y) {
                        return '<span class="input-group-addon progress"></span><span class="form-control">' + (y || "") + "</span>"
                    };
                    var j = function() {
                        var A = e(m).val().split("\\").pop();
                        e("#background-file-upload").append(s);
                        e(v).val(parseInt(v.val()) + 1);
                        e(r).html(u(A)).append(k({
                            text_cancel: p
                        }));
                        var y = function(E, B, D, C) {
                            e(".progress", l).text(C + "%")
                        };
                        var z = function(B, C) {
                            switch (B.status) {
                                case "ok":
                                    e(".dataform-file-value", l).val(w.field_id + "@" + A);
                                    t();
                                    break;
                                default:
                                    o();
                                    alert(B.message);
                                    break
                            }
                            e(v).val(parseInt(v.val()) - 1).trigger("change")
                        };
                        require(["jquery.form"], function() {
                            n = e(s).ajaxSubmit({
                                url: "/ajax-module-connector.php",
                                dataType: "json",
                                data: {
                                    wikidot_token7: e.cookie("wikidot_token7"),
                                    moduleName: "Empty",
                                    action: "DataFormFileAction",
                                    event: "uploadFile",
                                    field_id: w.field_id
                                },
                                uploadProgress: y,
                                success: z
                            })
                        })
                    };
                    var t = function() {
                        var y = e(".dataform-file-value", l).val().split("@").pop();
                        e(r).html(u(y)).append(k({
                            text_reset: o
                        }));
                        e(".progress", l).addClass("glyphicon glyphicon-ok")
                    };
                    var q = function() {
                        e(m).click()
                    };
                    var o = function() {
                        e(".dataform-file-value", l).val(w.value);
                        if (w["default"] != "") {
                            e(r).html(u(w["default"])).append(k({
                                text_delete: x
                            }))
                        } else {
                            e(r).html(u()).append(k({
                                text_upload: q
                            }))
                        }
                    };
                    var x = function() {
                        e(".dataform-file-value", l).val("@");
                        e(r).html(u()).append(k({
                            text_upload: q,
                            text_reset: o
                        }))
                    };
                    var p = function() {
                        n.data("jqxhr").abort();
                        e(v).val(parseInt(v.val()) - 1).trigger("change");
                        o()
                    };
                    var k = function(z) {
                        btn_group = e('<span class="input-group-btn">');
                        for (var y in z) {
                            e(btn_group).append(e('<button class="btn btn-default" type="button">' + w[y] + "</button>").bind("click", z[y]))
                        }
                        return btn_group
                    };
                    e(m).bind("change", j);
                    o()
                })
            })()
        } else {
            WIKIDOT.Editor.init("edit-page-textarea", "wd-editor-toolbar-panel")
        }
        var a = new OZONE.forms.lengthLimiter("edit-page-comments", "comments-charleft", 200);
        if (WIKIDOT.page.vars.draft) {
            var c = new OZONE.dialogs.Dialog();
            c.title = "Draft Exists";
            c.content = "<p>You have saved the draft of this page. Do you want to edit the draft? Please note that editing and saving the original will discard all changes saved in draft.</p>";
            c.buttons = ["Edit Original", "Edit Draft"];
            c.addButtonListener("Edit Draft", WIKIDOT.modules.PageEditModule.listeners.loadDraft);
            c.addButtonListener("Edit Original", function() {
                keyBindSavePage();
                OZONE.dialog.cleanAll();
                jQuery("body").scrollTo("#edit-page-textarea")
            });
            c.show();
            jQuery("body").scrollTo(".owindow", 0, {
                offset: -window.innerHeight / 2
            })
        } else {
            OZONE.dialog.cleanAll();
            keyBindSavePage();
            OZONE.dialog.hovertip.hideAll()
        }
        jQuery("#edit-page-textarea").focus()
    }
};
setTimeout("WIKIDOT.modules.PageEditModule.init()", 10);
特に指定がない限り、このサイトのコンテンツには次のライセンスが適用されます: Creative Commons Attribution-ShareAlike 3.0 License