最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show TextAngular toolbar only when editor is in focus for multiple editors with 1 toolbar - Stack Overflow

programmeradmin3浏览0评论

I have multiple editors with one toolbar. Initially I have just one editor and add say second and third based on the click of a button in the toolbar. The toolbar is on the top of the 1st editor and the subsequent editors that gets added are stacked one below the other.

The problems I have are:

  1. How do I show the toolbar when any of the editor is in focus?

  2. How do I move the toolbar on top of the editor in focus?

I have multiple editors with one toolbar. Initially I have just one editor and add say second and third based on the click of a button in the toolbar. The toolbar is on the top of the 1st editor and the subsequent editors that gets added are stacked one below the other.

The problems I have are:

  1. How do I show the toolbar when any of the editor is in focus?

  2. How do I move the toolbar on top of the editor in focus?

Share Improve this question edited Nov 21, 2014 at 22:11 Reza Shirazian 2,3531 gold badge23 silver badges31 bronze badges asked Nov 21, 2014 at 21:41 NaveenNaveen 231 silver badge3 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

To fix problem 1, add some custom CSS Like this:

.ta-toolbar{
  display: none;
}
.ta-toolbar.focussed{
  display: block;
}

The focussed class is added to the toolbar when any of it's linked editors are focussed into.

To fix problem 2 is probably a little more tricky and will require some extra work. The steps are:

  1. Watch for a focus on any of the editors.
  2. When this happens, change the position of the toolbar to relative to the current editor - at this point both will have the focussed class (use absolute positioning probably).

If someone needs an example for a simpler scenario. To put the toolbar somewhere else one can use something like:

<div text-angular-toolbar class="toolbar" name="toolbar" ta-toolbar="[['h1', 'h2', 'p', 'pre', 'quote', 'bold', 'italics', 'underline', 'ul', 'ol', 'justifyLeft', 'justifyCenter', 'justifyRight', 'indent', 'outdent', 'insertImage']]"></div>
<div style="overflow: auto; width: 100%; height: 100%; max-width: 700px; max-height: 750px; background-color: #FFFFFF;">
    <div text-angular ta-target-toolbars="toolbar" ng-model="htmlContent"></div>
</div>

Perhaps for someone this es in handy.

To expound on Simeon's answer:

You can add a unique class or ID to a container around each text-angular editor thus restricting the rules only to that editor. For example:

.editor1.ta-toolbar{
  display: none;
}
.editor1.ta-toolbar.focussed{
  display: block;
}
.editor2.ta-toolbar{
  display: none;
}
.editor2.ta-toolbar.focussed{
  display: block;
}

Or if you are using SASS or SCSS you can simplify it as:

.editor1, .editor2
  .ta-toolbar
    display: none
    &.focused
      display: block

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论