diff --git a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_button.coffee b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_button.coffee index 1b151b40b..77f5b18f6 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_button.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_button.coffee @@ -30,11 +30,12 @@ class App.UiElement.richtext.additions.RichTextToolButton html: true animation: false delay: 0 - placement: 'auto' + placement: 'top' theme: 'dark' content: content - container: 'body' - template: '' + container: '.page-content .main' + viewport: { selector: '.page-content .main', padding: 10 } + template: '' hash diff --git a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_popup.coffee b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_popup.coffee index 5f993f8bd..3af77d412 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_popup.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/_rich_text_tool_popup.coffee @@ -40,6 +40,16 @@ class App.UiElement.richtext.additions.RichTextToolPopup extends App.ControllerF $(@event.currentTarget).on('hidden.bs.popover', (e) => @willClose(e)) + $(document).on('click', @onClickingBackround) + + onClickingBackround: (e) => + return true if @el[0].contains(e.target) + + e.preventDefault() + e.stopPropagation() + + $(@event.currentTarget).popover('destroy') + getAjaxAttributes: (field, attributes) -> @delegate?.getAjaxAttributes?(field, attributes) @@ -152,5 +162,5 @@ class App.UiElement.richtext.additions.RichTextToolPopup extends App.ControllerF textEditor = $(@event.currentTarget).closest('.richtext.form-control').find('[contenteditable]') textEditor.find('span.highlight-emulator').contents().unwrap() + $(document).off('click', @onClickingBackround) $(@event.currentTarget).off('hidden.bs.popover') - $(e.currentTarget).popover('destroy') diff --git a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_answer.coffee b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_answer.coffee index 775ba50a8..8045aff2c 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_answer.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_answer.coffee @@ -21,6 +21,10 @@ class App.UiElement.richtext.additions.RichTextToolPopupAnswer extends App.UiEle apply: (callback) -> id = @el.find('input').val() object = App.KnowledgeBaseAnswerTranslation.find(id) + + if !object + return + textEditor = $(@event.currentTarget).closest('.richtext.form-control').find('[contenteditable]') switch @selection.type @@ -33,8 +37,15 @@ class App.UiElement.richtext.additions.RichTextToolPopupAnswer extends App.UiEle when 'caret' newElem = $('') @applyOnto(newElem, object, object.title) - @selection.dom[0].splitText(@selection.offset) - newElem.insertAfter(@selection.dom) + + selectionElem = @selection.dom[0] + + if selectionElem.splitText + @selection.dom[0].splitText(@selection.offset) + newElem.insertAfter(@selection.dom) + else + newElem.prependTo(@selection.dom) + when 'range' placeholder = textEditor.find('span.highlight-emulator') newElem = $('') diff --git a/app/assets/javascripts/app/lib/mixins/popover_providable.coffee b/app/assets/javascripts/app/lib/mixins/popover_providable.coffee index 40e013f21..3e11b50b4 100644 --- a/app/assets/javascripts/app/lib/mixins/popover_providable.coffee +++ b/app/assets/javascripts/app/lib/mixins/popover_providable.coffee @@ -50,7 +50,7 @@ App.PopoverProvidable = anyPopoversDestroy: -> # do not remove permanent .popover--notifications widget - $('.popover:not(.popover--notifications)').remove() + $('.popover:not(.popover--notifications,.popover--richtextpopover)').remove() extended: -> @include InstanceMethods