Rich Redmine Wiki Editor

nothing to write

Stan na 13-02-2015. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Rich Redmine Wiki Editor
// @namespace    d.hatena.ne.jp/den8/
// @version      1.0.2
// @description  nothing to write
// @author       k.bigwheel
// @match        http*/edit
// @grant        none
// @require      http://code.jquery.com/jquery-2.1.3.min.js
// @licence      GPLv2
// ==/UserScript==

function moveEditor(parentDiv) {
    var editorFrame = $("<div></div>");
    var editor = $("form.edit_content#wiki_form");
    editor.detach();
    editorFrame.append(editor);
    editorFrame.css("width", "50%");
    editorFrame.css("float", "left");
    parentDiv.append(editorFrame);
}    

function movePreview(parentDiv) {
    var preview = $("div#preview");
    preview.detach();
    preview.css("width", "50%");
    preview.css("float", "right");
    preview.css("overflow", "scroll");
    preview.css("height", "600px");
    preview.css("resize", "vertical");
    parentDiv.append(preview);
}

function renderPreview() {
    $("form.edit_content>p>a").click();
}

$(document).ready(function() {
    if ($('meta[name="description"]').attr("content") == "Redmine") {
        var newFrame = $("<div></div>");
        $("div#content h2").after(newFrame);
        
        moveEditor(newFrame);
        movePreview(newFrame);
        
        // http://memocarilog.info/jquery/7203 ここで言及されてるideom
        // 本当は直近でリクエストを出した直後の場合、出したリクエストがまだ帰ってきていない場合、
        // リクエストが帰ってきた直後の場合などはリクエストを出さないようにしたほうがRedMineへの負荷は下がるが
        // そこまでするの面倒。それ用のプラグインかライブラリが間違いなくあるはずなのでそれを使う。
        var timer = false;
        $("textarea#content_text").keyup(function() {
            if (timer !== false)
                clearTimeout(timer);
            timer = setTimeout(renderPreview, 1000);
        });
        
        renderPreview(); // 最初から描画しておく
    }
});