jquery ui portlet 中的可编辑内容

发布于 2024-12-17 19:40:21 字数 793 浏览 2 评论 0原文

我正在尝试创建具有可编辑内容(例如文本区域或选择框)的 jquery ui portlet。 到目前为止我还没有成功。

我尝试使 portlet 成为“内容可编辑”,如下所示:

<div class="portlet">
    <div class="portlet-header">News</div>
    <div class="portlet-content" contenteditable="true">
     Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</div>
</div>

然后,可以通过将内容剪切并粘贴到其中来更改 portlet 内容,但不能通过键盘进行更改。

我还尝试添加一个文本区域:

<div class="portlet">
    <div class="portlet-header">Feeds</div>
    <div class="portlet-content">
        <textarea>bla bla bla</textarea>
    </div>
</div>

同样,文本区域可以通过剪切和粘贴内容来更改,但不能通过键盘。

我没有找到任何这样做的例子。这有可能吗?

如果有人知道如何在没有 jquery ui 的情况下做到这一点,我很乐意了解这一点。

I'm trying to create jquery ui portlets with editable content (for example a textarea or select boxes).
So far I didn't succeed.

I tried to make the portlet "contenteditable" like this:

<div class="portlet">
    <div class="portlet-header">News</div>
    <div class="portlet-content" contenteditable="true">
     Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</div>
</div>

The portlet content is then changeable by cut&pasting things into it, but not via keyboard.

I also tried to add a textarea:

<div class="portlet">
    <div class="portlet-header">Feeds</div>
    <div class="portlet-content">
        <textarea>bla bla bla</textarea>
    </div>
</div>

Again the textarea is changeable by cut&pasting things into it, but not via keyboard.

I didn't find any examples that do this. Is this possible at all?

If someone knows a way how to do this without jquery ui I'd be happy to learn about that.

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

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

发布评论

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

评论(1

请止步禁区 2024-12-24 19:40:21

我自己使用 jeditable 找到了解决方案:

javascript:

    // handle autogrow editable areas in portlets
    $(".autogrow").editable(function(value, settings) { 
         console.log(this);
         console.log(value);
         console.log(settings);
         return(value);
      }, { 
         indicator : "Saving...",
         tooltip   : "Click to edit...",
         type      : 'autogrow',
         submit    : 'OK',
         cancel    : 'cancel',
         autogrow : {
               lineHeight : 16,
               minHeight  : 32
            }
    });

html:

    <div class="portlet">
      <div class="portlet-header">jeditable autogrow portlet</div>
      <div class="portlet-content" >
        <div>
          <pre class="autogrow" id="paragraph1">
          editable text area inside of portlet
          </pre>
        </div>
      </div>
    </div>

我仍然遇到的唯一问题问题是无法通过用鼠标单击文本光标来将其放置到正确的位置进行编辑。进入编辑模式后,您只能使用键盘移动文本光标。
对于 portlet 之外的自动增长区域来说,情况有所不同。
如果有人提示如何解决这个问题?

更新
我终于找到了最后一个问题的简单原因(无法将光标放置在
通过在 portlet 中的可编辑区域内单击鼠标):
只是不要使用官方 portlet 演示 中使用的“disableSelection()”。

$(function() {
    $( ".column" ).sortable({
        connectWith: ".column"
    });

    $( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
        .find( ".portlet-header" )
        .addClass( "ui-widget-header ui-corner-all" )
        .prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
        .end()
        .find( ".portlet-content" );

    $( ".portlet-header .ui-icon" ).click(function() {
        $( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
        $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
    });

    //COMMENT THIS OUT: $( ".column" ).disableSelection();
});

I found a solution myself by using jeditable:

javascript:

    // handle autogrow editable areas in portlets
    $(".autogrow").editable(function(value, settings) { 
         console.log(this);
         console.log(value);
         console.log(settings);
         return(value);
      }, { 
         indicator : "Saving...",
         tooltip   : "Click to edit...",
         type      : 'autogrow',
         submit    : 'OK',
         cancel    : 'cancel',
         autogrow : {
               lineHeight : 16,
               minHeight  : 32
            }
    });

html:

    <div class="portlet">
      <div class="portlet-header">jeditable autogrow portlet</div>
      <div class="portlet-content" >
        <div>
          <pre class="autogrow" id="paragraph1">
          editable text area inside of portlet
          </pre>
        </div>
      </div>
    </div>

The only problem I'm still having is that it's not possible to put the text cursor to the right position for editing by clicking it to that position with the mouse. Once you're in edit mode you can only move the text cursor with the keyboard.
That's different for autogrow areas outside of portlets.
If anyone has a hint how to fix that?

UPDATE:
I finally found the simple cause for the last problem (not being able to place the cursor
via mouse clicks inside the jeditable areas in portlets):
just don't use "disableSelection()" as used in the official portlet demo.

$(function() {
    $( ".column" ).sortable({
        connectWith: ".column"
    });

    $( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
        .find( ".portlet-header" )
        .addClass( "ui-widget-header ui-corner-all" )
        .prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
        .end()
        .find( ".portlet-content" );

    $( ".portlet-header .ui-icon" ).click(function() {
        $( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
        $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
    });

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