使用 jeditable 和 autogrow 的问题

发布于 2024-07-06 13:33:11 字数 872 浏览 15 评论 0原文

我使用 jQuery 和 CakePHP 开发一个 Web 项目。 我使用 jeditable 作为就地编辑插件。 对于文本区域,我使用 autogrow 插件 扩展它。

嗯,我对此有两个问题:

  • 首先,自动增长仅适用于 Firefox,不适用于 IE、Safari、Opera 和 Chrome。
  • 其次,我需要 jeditable 的回调事件,当它完成显示编辑组件时,重新计算 scrollbar

我对Javascript不太熟悉,所以我无法自己扩展/更正这两个库。 有没有人使用另一个js库进行自动增长文本区域的就地编辑(没有像TinyMCE这样的完整编辑器,我需要纯文本的解决方案)?

我还发现 Growfield,它适用于其他浏览器,但没有可编辑的集成...

(对不起我的英语)

I work on a Webproject using jQuery and CakePHP. I use jeditable as an inplace edit plugin. For textareas I extend it using the autogrow plugin.

Well, I have two problems with this:

  • First, autogrow does only work on Firefox, not on IE, Safari, Opera and Chrome.
  • Second, I need a callback event for jeditable, when its finished showing the edit-component, to recalculate the scrollbar

Im not so familiar with Javascript, so i can't extend/correct this two libraries by my own. Has anyone used another js-library for inplace edit with auto growing textareas (no complete editors like TinyMCE, I need a solution for plain text)?

I also found Growfield, it would work for other browsers, but there's no jeditable integration...

(sorry for my english)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

栖迟 2024-07-13 13:33:11

我在任何浏览器中使用 Autogrow 和 jeditable 都没有发现任何问题,但这里是 Growfield 和 jeditable 的实现。 它的工作方式与 jeditable 的 Autogrow 插件非常相似。 您为 jeditable 创建一个特殊的输入类型,然后将 .growfield() 应用于它。 必要的 JavaScript 如下,演示可以在这里

<script type="text/javascript">
/*  This is the growfield integration into jeditable
    You can use almost any field plugin you'd like if you create an input type for it.
    It just needs the "element" function (to create the editable field) and the "plugin"
    function which applies the effect to the field.  This is very close to the code in the
    jquery.jeditable.autogrow.js input type that comes with jeditable.
 */
$.editable.addInputType('growfield', {
    element : function(settings, original) {
        var textarea = $('<textarea>');
        if (settings.rows) {
            textarea.attr('rows', settings.rows);
        } else {
            textarea.height(settings.height);
        }
        if (settings.cols) {
            textarea.attr('cols', settings.cols);
        } else {
            textarea.width(settings.width);
        }
        // will execute when textarea is rendered
        textarea.ready(function() {
            // implement your scroll pane code here
        });
        $(this).append(textarea);
        return(textarea);
    },
    plugin : function(settings, original) {
        // applies the growfield effect to the in-place edit field
        $('textarea', this).growfield(settings.growfield);
    }
});

/* jeditable initialization */
$(function() {
    $('.editable_textarea').editable('postto.html', {
        type: "growfield", // tells jeditable to use your growfield input type from above
        submit: 'OK', // this and below are optional
        tooltip: "Click to edit...",
        onblur: "ignore",
        growfield: { } // use this to pass options to the growfield that gets created
    });
})

I didn't see any problems using Autogrow with jeditable in any browsers but here is an implementation of Growfield with jeditable. It works much in the same way that the Autogrow plugin for jeditable does. You create a special input type for jeditable and just apply .growfield() to it. The necessary javascript is below, a demo can be found here.

<script type="text/javascript">
/*  This is the growfield integration into jeditable
    You can use almost any field plugin you'd like if you create an input type for it.
    It just needs the "element" function (to create the editable field) and the "plugin"
    function which applies the effect to the field.  This is very close to the code in the
    jquery.jeditable.autogrow.js input type that comes with jeditable.
 */
$.editable.addInputType('growfield', {
    element : function(settings, original) {
        var textarea = $('<textarea>');
        if (settings.rows) {
            textarea.attr('rows', settings.rows);
        } else {
            textarea.height(settings.height);
        }
        if (settings.cols) {
            textarea.attr('cols', settings.cols);
        } else {
            textarea.width(settings.width);
        }
        // will execute when textarea is rendered
        textarea.ready(function() {
            // implement your scroll pane code here
        });
        $(this).append(textarea);
        return(textarea);
    },
    plugin : function(settings, original) {
        // applies the growfield effect to the in-place edit field
        $('textarea', this).growfield(settings.growfield);
    }
});

/* jeditable initialization */
$(function() {
    $('.editable_textarea').editable('postto.html', {
        type: "growfield", // tells jeditable to use your growfield input type from above
        submit: 'OK', // this and below are optional
        tooltip: "Click to edit...",
        onblur: "ignore",
        growfield: { } // use this to pass options to the growfield that gets created
    });
})

与君绝 2024-07-13 13:33:11

knight_killer:自动增长仅适用于 FireFox,这是什么意思? 我刚刚使用 FF3、FF2、Safari、IE7 和 Chrome 进行了测试。 与所有这些都工作得很好。 我没有可用的 Opera。

Alex:有 Growfield Jeditable 自定义输入的下载链接吗? 我想从我的博客链接它。 真是太棒了!

knight_killer: What do you mean Autogrow works only with FireFox? I just tested with FF3, FF2, Safari, IE7 and Chrome. Works fine with all of them. I did not have Opera available.

Alex: Is there a download link for your Growfield Jeditable custom input? I would like to link it from my blog. It is really great!

荭秂 2024-07-13 13:33:11

Mika Tuupola:如果你对我修改后的jeditable(添加了两个回调事件)感兴趣,你可以在这里获取。 如果您能在 jeditable 的官方版本中提供这些事件,那就太好了!

这是我的(简化的)集成代码。 我使用这些事件的目的不仅仅是为了悬停效果。 这只是一个用例。

$('.edit_memo').editable('/cakephp/efforts/updateValue', {
  id            : 'data[Effort][id]',
  name          : 'data[Effort][value]',
  type          : 'growfield',
  cancel        : 'Abort',
  submit        : 'Save',
  tooltip       : 'click to edit',
  indicator     : "<span class='save'>saving...</span>",
  onblur        : 'ignore',
  placeholder   : '<span class="hint"><click to edit></span>',
  loadurl       : '/cakephp/efforts/getValue',
  loadtype      : 'POST',
  loadtext      : 'loading...',
  width         : 447,
  onreadytoedit : function(value){
    $(this).removeClass('edit_memo_hover'); //remove css hover effect
  },
  onfinishededit : function(value){
    $(this).addClass('edit_memo_hover'); //add css hover effect
  }
});

Mika Tuupola: If you are Interested in my modified jeditable (added two callback events), you can get it here. It would be great if you would provide these events in your official version of jeditable!

Here is my (simplified) integration code. I use the events for more then just for the hover effect. It's just one usecase.

$('.edit_memo').editable('/cakephp/efforts/updateValue', {
  id            : 'data[Effort][id]',
  name          : 'data[Effort][value]',
  type          : 'growfield',
  cancel        : 'Abort',
  submit        : 'Save',
  tooltip       : 'click to edit',
  indicator     : "<span class='save'>saving...</span>",
  onblur        : 'ignore',
  placeholder   : '<span class="hint"><click to edit></span>',
  loadurl       : '/cakephp/efforts/getValue',
  loadtype      : 'POST',
  loadtext      : 'loading...',
  width         : 447,
  onreadytoedit : function(value){
    $(this).removeClass('edit_memo_hover'); //remove css hover effect
  },
  onfinishededit : function(value){
    $(this).addClass('edit_memo_hover'); //add css hover effect
  }
});
梦回旧景 2024-07-13 13:33:11

谢谢亚历克斯!你的growfield插件可以工作。
与此同时,我设法解决了另一个问题。 我使用了另一个 Scroll-Library 并将回调事件侵入 jeditable-plugin 。 这并没有我想象的那么难...

Thank you Alex! Your growfield-Plugin works.
In meantime I managed to solve the other problem. I took another Scroll-Library and hacked a callback event into the jeditable-plugin. It was not that hard as I thought...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文