prototype.js ¤ò¤Á¤ã¤ó¤È(»Å»ö¤Ç)»È¤Ã¤Æ¤ß¤è¤¦¤È¤¤¤¦»ö¤Ç¥´¥Ë¥ç¥´¥Ë¥ç¤·¤¿¥á¥â¡£

¤ä¤ê¤¿¤¤»ö¤ÏÄ̾ï¤Î¥Æ¥­¥¹¥È¤òÊÔ½¸²Äǽ¤Ë¤·¤Æ Ajax ¤ÇÊݸ¤Ã¤Æ¤¤¤¦¤¢¤ê¤¬¤Á(¡©)¤Ê»ö¡£
¤Ç¡¢»È¤¤Êý¤ÎÊÙ¶¯¤¬¤Æ¤é½ñ¤¤¤¿¥³¡¼¥É¤ò¤Î¤»¤Æ¤ª¤¯¤È°Ê²¼¤Î¤è¤¦¤Ê´¶¤¸

var Editable = Class.create();

Editable.prototype = {
    initialize: function(text, url) {
        this.view = $(text);
        this.url = url;
        Element.show(this.view);
        this.editor = document.createElement('input');
        this.editor.type = "text";
        Element.hide(this.editor);
        this.view.parentNode.appendChild(this.editor);
        Event.observe(this.view, 'dblclick', this.showEditor.bindAsEventListener(this), false);
        Event.observe(this.editor, 'blur', this.editDone.bindAsEventListener(this), false);
    },

    showEditor: function() {
        Position.clone(this.view, this.editor);
        this.editor.value = this.view.innerHTML;
        Element.toggle(this.view, this.editor);
        Field.focus(this.editor);
    },

    editDone: function() {
        Element.toggle(this.view, this.editor);
        var parameters = encodeURIComponent(this.view.id) + "=" + encodeURIComponent(this.editor.value);
        new Ajax.Request(this.url, {
            method: 'post',
            asynchronous: true,
            parameters: parameters,
            onLoading: function() {
                this.view.innerHTML = "saving...";
            }.bind(this),
            onSuccess: function() {
                this.view.innerHTML = this.editor.value;
            }.bind(this)
        });
    }
};
¤³¤ì¤ò¡¢editable.js ¤È¤·¤ÆÊݸ¤·¤Æ¡¢°Ê²¼¤Î¤è¤¦¤Ë¸Æ¤Ó½Ð¤¹¤È¥À¥Ö¥ë¥¯¥ê¥Ã¥¯¤ÇÊÔ½¸²Äǽ¡¢ÊÔ½¸¤¬½ª¤ï¤Ã¤¿¤éÊ̤ΤȤ³¤ò¥¯¥ê¥Ã¥¯¤ÇÊݸ¤Ã¤Æ¤ÊµóÆ°¤Ë¤Ê¤ê¤Þ¤¹¡£

<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="editable.js"></script>
<title></title>
</head>
<body>
<div id="editText" style="border: 1px solid #000000; width: 300px;">Hello World!</div>
<script type="text/javascript">
new Editable('editText', '/path/to/save.app');
</script>
</body>
</html>

/path/to/save.app ¤¬¥ê¥¯¥¨¥¹¥È¤ò¼õ¤±¤È¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ë¤Ê¤ê¤Þ¤¹¡£
¥¢¥×¥ê¦¤Ë¤Ï <id>=<ÃÍ> ¤Ã¤Æ´¶¤¸¤ÇÃͤ¬ÅϤäƤ­¤Þ¤¹¡£
prototype.js »È¤¦¤È¥³¡¼¥É¤¬¥¹¥Ã¥­¥ê¤·¤ÆÀº¿À±ÒÀ¸¾å¤è¤í¤·¤¤¤Ç¤¹¤Ê¡£¡£