javascript - "lock" a portion of HTML in wysiHTML5 - Stack Overflow

I'm usingfor an editor in my code base and I'd like to "lock" portions of the cod

I'm using for an editor in my code base and I'd like to "lock" portions of the code to not be editable, like so:

<form>
<textarea id="wysihtml5-textarea" placeholder="Enter your text ..." autofocus>

<div>Some Editable Text here :) </div>

<div class="lockedForEditing" contenteditable="false">YOU CAN'T EDIT ME!!!</div>

<div>Some More editable code here </div>

</textarea>
</form>

Does anyone know if this is possible? I've tried several ways so far with no success. I've also not seen anything in the documentation. If this isn't possible, do you know a similar editor where it is possible?

I'm using https://github./xing/wysihtml5 for an editor in my code base and I'd like to "lock" portions of the code to not be editable, like so:

<form>
<textarea id="wysihtml5-textarea" placeholder="Enter your text ..." autofocus>

<div>Some Editable Text here :) </div>

<div class="lockedForEditing" contenteditable="false">YOU CAN'T EDIT ME!!!</div>

<div>Some More editable code here </div>

</textarea>
</form>

Does anyone know if this is possible? I've tried several ways so far with no success. I've also not seen anything in the documentation. If this isn't possible, do you know a similar editor where it is possible?

Share Improve this question asked Feb 12, 2013 at 0:30 BradBrad 6,3627 gold badges34 silver badges45 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You have to make block "locked" after you have inserted. There are several issues to handle:

1. On insertion of locked element

I assume, it will be via insertHTML mand.

editor.poser.mands.exec('insertHTML', lockedhtml);
$(editor.poser.iframe).contents().find('.lockedForEditing').attr('contenteditable', 'false');

2. On initialization of wysihtml

i.e. locked element is in the contents of text area. First you need to add your "lockedForEditing" class to whitelist in wysihtml rules. then after poser initialized you need to lock elements.

editor.on('load', function(){
   $(editor.poser.iframe).contents().find('.lockedForEditing').attr('contenteditable', 'false');
});

3. Prevent contenteditable mands affect contents of locked element

If user selects all text inside poser and styles it, your locked element's content will also be affected even contenteditable attribute is false. So you need to use CSS to make text inside locked element not-selectable

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

An humble advise, instead of using div tag for your locked element, you may prefer section tag, which you reserve for lock.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745431486a4627410.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信