From 11e13b32bb0e8626cd012f5570416e9ec12bd682 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Wed, 28 Aug 2019 21:23:41 +0300 Subject: [PATCH] Inline auto complete for issue (#) in wiki-edit fields --- app/helpers/application_helper.rb | 2 +- app/helpers/custom_fields_helper.rb | 12 +++++- app/views/documents/_form.html.erb | 7 +++- app/views/issues/_edit.html.erb | 8 +++- app/views/issues/_form.html.erb | 9 +++-- app/views/issues/bulk_edit.html.erb | 7 +++- app/views/journals/_notes_form.html.erb | 11 ++++-- app/views/layouts/base.html.erb | 2 +- app/views/messages/_form.html.erb | 8 +++- app/views/news/_form.html.erb | 9 ++++- app/views/news/show.html.erb | 7 +++- app/views/wiki/edit.html.erb | 9 ++++- public/javascripts/application.js | 49 +++++++++++++++++++++++++ public/javascripts/tribute-3.7.3.min.js | 2 + public/stylesheets/application.css | 8 ++++ public/stylesheets/tribute-3.7.3.css | 27 ++++++++++++++ 16 files changed, 155 insertions(+), 22 deletions(-) create mode 100644 public/javascripts/tribute-3.7.3.min.js create mode 100644 public/stylesheets/tribute-3.7.3.css diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4da08c2ca..ce4672876 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1569,7 +1569,7 @@ module ApplicationHelper # Returns the javascript tags that are included in the html layout head def javascript_heads - tags = javascript_include_tag('jquery-2.2.4-ui-1.11.0-ujs-5.2.3', 'application', 'responsive') + tags = javascript_include_tag('jquery-2.2.4-ui-1.11.0-ujs-5.2.3', 'tribute-3.7.3.min', 'application', 'responsive') unless User.current.pref.warn_on_leaving_unsaved == '0' tags << "\n".html_safe + javascript_tag("$(window).on('load', function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") end diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 655492e0a..00140396d 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -80,13 +80,21 @@ module CustomFieldsHelper # Return custom field html tag corresponding to its format def custom_field_tag(prefix, custom_value) css = "#{custom_value.custom_field.field_format}_cf" - css += ' wiki-edit' if custom_value.custom_field.full_text_formatting? + data = nil + if custom_value.custom_field.full_text_formatting? + css += ' wiki-edit' + data = { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => custom_value.customized.project, :q => '') + } if custom_value.customized && custom_value.customized.project + end custom_value.custom_field.format.edit_tag self, custom_field_tag_id(prefix, custom_value.custom_field), custom_field_tag_name(prefix, custom_value.custom_field), custom_value, - :class => css + :class => css, + :data => data end # Return custom field name tag diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb index bd3b7cd9f..b8b8c8404 100644 --- a/app/views/documents/_form.html.erb +++ b/app/views/documents/_form.html.erb @@ -3,7 +3,12 @@

<%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %>

<%= f.text_field :title, :required => true, :size => 60 %>

-

<%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %>

+

<%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit', + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + } +%>

<% @document.custom_field_values.each do |value| %>

<%= custom_field_tag_with_label :document, value %>

diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb index 3afaee4ca..00dcac5fb 100644 --- a/app/views/issues/_edit.html.erb +++ b/app/views/issues/_edit.html.erb @@ -29,7 +29,12 @@ <% end %> <% if @issue.notes_addable? %>
<%= l(:field_notes) %> - <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit', :no_label => true %> + <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit', + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @issue.project, :q => '') + }, + :no_label => true %> <%= wikitoolbar_for 'issue_notes', preview_issue_path(:project_id => @project, :issue_id => @issue) %> <% if @issue.safe_attribute? 'private_notes' %> @@ -76,4 +81,3 @@ <%= hidden_field_tag 'issue_count', @issue_count if @issue_count %> <% end %> - diff --git a/app/views/issues/_form.html.erb b/app/views/issues/_form.html.erb index 5bc98ebbd..fdf729140 100644 --- a/app/views/issues/_form.html.erb +++ b/app/views/issues/_form.html.erb @@ -34,11 +34,12 @@ <%= f.label_for_field :description, :required => @issue.required_attribute?('description') %> <%= link_to_function content_tag(:span, l(:button_edit), :class => 'icon icon-edit'), '$(this).hide(); $("#issue_description_and_toolbar").show()' unless @issue.new_record? %> <%= content_tag 'span', :id => "issue_description_and_toolbar", :style => (@issue.new_record? ? nil : 'display:none') do %> - <%= f.text_area :description, - :cols => 60, + <%= f.text_area :description, :cols => 60, :accesskey => accesskey(:edit), :class => 'wiki-edit', :rows => [[10, @issue.description.to_s.length / 50].max, 20].min, - :accesskey => accesskey(:edit), - :class => 'wiki-edit', + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @issue.project, :q => '') + }, :no_label => true %> <% end %>

diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index 468bee148..f5590e9bc 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -194,7 +194,12 @@
<%= l(:field_notes) %> -<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> +<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit', + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + } +%> <%= wikitoolbar_for 'notes' %> <% if @safe_attributes.include?('private_notes') %> diff --git a/app/views/journals/_notes_form.html.erb b/app/views/journals/_notes_form.html.erb index eecc31da9..aeb4b6a93 100644 --- a/app/views/journals/_notes_form.html.erb +++ b/app/views/journals/_notes_form.html.erb @@ -3,10 +3,13 @@ :method => 'put', :id => "journal-#{@journal.id}-form") do %> <%= label_tag "notes", l(:description_notes), :class => "hidden-for-sighted", :for => "journal_#{@journal.id}_notes" %> - <%= text_area_tag 'journal[notes]', @journal.notes, - :id => "journal_#{@journal.id}_notes", - :class => 'wiki-edit', - :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %> + <%= text_area_tag 'journal[notes]', @journal.notes, :id => "journal_#{@journal.id}_notes", :class => 'wiki-edit', + :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min), + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + } + %> <% if @journal.safe_attribute? 'private_notes' %> <%= hidden_field_tag 'journal[private_notes]', '0' %> <%= check_box_tag 'journal[private_notes]', '1', @journal.private_notes, :id => "journal_#{@journal.id}_private_notes" %> diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index 7572dff5d..1ed1032e9 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -9,7 +9,7 @@ <%= csrf_meta_tag %> <%= favicon %> -<%= stylesheet_link_tag 'jquery/jquery-ui-1.11.0', 'application', 'responsive', :media => 'all' %> +<%= stylesheet_link_tag 'jquery/jquery-ui-1.11.0', 'tribute-3.7.3', 'application', 'responsive', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> <%= heads_for_theme %> diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb index adba05224..7d3a9c59f 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/messages/_form.html.erb @@ -23,7 +23,13 @@

<%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %> -<%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %>

+<%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content', + :accesskey => accesskey(:edit), + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + } +%>

<%= wikitoolbar_for 'message_content', preview_board_message_path(:board_id => @board, :id => @message) %> diff --git a/app/views/news/_form.html.erb b/app/views/news/_form.html.erb index dbf21df48..58f68e1b2 100644 --- a/app/views/news/_form.html.erb +++ b/app/views/news/_form.html.erb @@ -3,8 +3,13 @@

<%= f.text_field :title, :required => true, :size => 60 %>

<%= f.text_area :summary, :cols => 60, :rows => 2 %>

-

<%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit' %>

+

<%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit', + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + } +%>

<%= render :partial => 'attachments/form', :locals => {:container => @news} %>

-<%= wikitoolbar_for 'news_description', preview_news_path(:project_id => @project, :id => @news) %> \ No newline at end of file +<%= wikitoolbar_for 'news_description', preview_news_path(:project_id => @project, :id => @news) %> diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index 932bf0083..04ea54a0a 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -53,7 +53,12 @@

<%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %>

<%= form_tag({:controller => 'comments', :action => 'create', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %>
- <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %> + <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit', + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + } + %> <%= wikitoolbar_for 'comment_comments', preview_news_path(:project_id => @project, :id => @news) %>

<%= submit_tag l(:button_add) %>

diff --git a/app/views/wiki/edit.html.erb b/app/views/wiki/edit.html.erb index 60a2f6596..0e1c23cc4 100644 --- a/app/views/wiki/edit.html.erb +++ b/app/views/wiki/edit.html.erb @@ -13,8 +13,13 @@ <%= error_messages_for 'content' %>
-<%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, - :class => 'wiki-edit', :accesskey => accesskey(:edit) %> +<%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :accesskey => accesskey(:edit), + :class => 'wiki-edit', + :data => { + :auto_complete => true, + :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + } +%> <% if @page.safe_attribute_names.include?('parent_id') && @wiki.pages.any? %> <%= fields_for @page do |fp| %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a3fc9248d..0868f971a 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -995,6 +995,7 @@ function setupAttachmentDetail() { $(window).resize(setFilecontentContainerHeight); } + $(function () { $('[title]').tooltip({ show: { @@ -1006,6 +1007,51 @@ $(function () { } }); }); + +function inlineAutoComplete(element) { + 'use strict'; + // do not attach if Tribute is already initialized + if (element.dataset.tribute === 'true') {return;} + + const issuesUrl = element.dataset.issuesUrl; + const usersUrl = element.dataset.usersUrl; + + const remoteSearch = function(url, cb) { + const xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function () + { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + var data = JSON.parse(xhr.responseText); + cb(data); + } else if (xhr.status === 403) { + cb([]); + } + } + }; + xhr.open("GET", url, true); + xhr.send(); + }; + + const tribute = new Tribute({ + trigger: '#', + values: function (text, cb) { + remoteSearch(issuesUrl + text, function (issues) { + return cb(issues); + }); + }, + lookup: 'label', + fillAttr: 'label', + requireLeadingSpace: true, + selectTemplate: function (issue) { + return '#' + issue.original.id; + } + }); + + tribute.attach(element); +} + + $(document).ready(setupAjaxIndicator); $(document).ready(hideOnLoad); $(document).ready(addFormObserversForDoubleSubmit); @@ -1013,3 +1059,6 @@ $(document).ready(defaultFocus); $(document).ready(setupAttachmentDetail); $(document).ready(setupTabs); $(document).ready(setupFilePreviewNavigation); +$(document).on('focus', '[data-auto-complete=true]', function(event) { + inlineAutoComplete(event.target); +}); diff --git a/public/javascripts/tribute-3.7.3.min.js b/public/javascripts/tribute-3.7.3.min.js new file mode 100644 index 000000000..7b84f9a59 --- /dev/null +++ b/public/javascripts/tribute-3.7.3.min.js @@ -0,0 +1,2 @@ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Tribute=e()}}(function(){return function o(u,a,l){function s(t,e){if(!a[t]){if(!u[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var r=a[t]={exports:{}};u[t][0].call(r.exports,function(e){return s(u[t][1][e]||e)},r,r.exports,o,u,a,l)}return a[t].exports}for(var c="function"==typeof require&&require,e=0;e",post:u.current.collection.searchOpts.post||"",skip:u.current.collection.searchOpts.skip,extract:function(e){if("string"==typeof u.current.collection.lookup)return e[u.current.collection.lookup];if("function"==typeof u.current.collection.lookup)return u.current.collection.lookup(e,u.current.mentionText);throw new Error("Invalid lookup attribute, lookup must be string or function.")}});u.current.filteredItems=t;var n=u.menu.querySelector("ul");if(u.range.positionMenuAtCaret(o),!t.length){var i=new CustomEvent("tribute-no-match",{detail:u.menu});return u.current.element.dispatchEvent(i),void("function"==typeof u.current.collection.noMatchTemplate&&!u.current.collection.noMatchTemplate()||!u.current.collection.noMatchTemplate?u.hideMenu():"function"==typeof u.current.collection.noMatchTemplate?n.innerHTML=u.current.collection.noMatchTemplate():n.innerHTML=u.current.collection.noMatchTemplate)}u.current.collection.menuItemLimit&&(t=t.slice(0,u.current.collection.menuItemLimit)),n.innerHTML="";var r=u.range.getDocument().createDocumentFragment();t.forEach(function(e,t){var n=u.range.getDocument().createElement("li");n.setAttribute("data-index",t),n.addEventListener("mousemove",function(e){var t=a(u._findLiTarget(e.target),2),n=(t[0],t[1]);0!==e.movementY&&u.events.setActiveLi(n)}),u.menuSelected===t&&(n.className=u.current.collection.selectClass),n.innerHTML=u.current.collection.menuItemTemplate(e),r.appendChild(n)}),n.appendChild(r)}};"function"==typeof this.current.collection.values?this.current.collection.values(this.current.mentionText,t):t(this.current.collection.values)}}},{key:"_findLiTarget",value:function(e){if(!e)return[];var t=e.getAttribute("data-index");return t?[e,t]:this._findLiTarget(e.parentNode)}},{key:"showMenuForCollection",value:function(e,t){e!==document.activeElement&&this.placeCaretAtEnd(e),this.current.collection=this.collection[t||0],this.current.externalTrigger=!0,(this.current.element=e).isContentEditable?this.insertTextAtCursor(this.current.collection.trigger):this.insertAtCaret(e,this.current.collection.trigger),this.showMenuFor(e)}},{key:"placeCaretAtEnd",value:function(e){if(e.focus(),void 0!==window.getSelection&&void 0!==document.createRange){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n.removeAllRanges(),n.addRange(t)}else if(void 0!==document.body.createTextRange){var i=document.body.createTextRange();i.moveToElementText(e),i.collapse(!1),i.select()}}},{key:"insertTextAtCursor",value:function(e){var t,n;(n=(t=window.getSelection()).getRangeAt(0)).deleteContents();var i=document.createTextNode(e);n.insertNode(i),n.selectNodeContents(i),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}},{key:"insertAtCaret",value:function(e,t){var n=e.scrollTop,i=e.selectionStart,r=e.value.substring(0,i),o=e.value.substring(e.selectionEnd,e.value.length);e.value=r+t+o,i+=t.length,e.selectionStart=i,e.selectionEnd=i,e.focus(),e.scrollTop=n}},{key:"hideMenu",value:function(){this.menu&&(this.menu.style.cssText="display: none;",this.isActive=!1,this.menuSelected=0,this.current={})}},{key:"selectItemAtIndex",value:function(e,t){if("number"==typeof(e=parseInt(e))&&!isNaN(e)){var n=this.current.filteredItems[e],i=this.current.collection.selectTemplate(n);null!==i&&this.replaceText(i,t,n)}}},{key:"replaceText",value:function(e,t,n){this.range.replaceTriggerText(e,!0,!0,t,n)}},{key:"_append",value:function(e,t,n){if("function"==typeof e.values)throw new Error("Unable to append to values, as it is a function.");e.values=n?t:e.values.concat(t)}},{key:"append",value:function(e,t,n){var i=parseInt(e);if("number"!=typeof i)throw new Error("please provide an index for the collection to update.");var r=this.collection[i];this._append(r,t,n)}},{key:"appendCurrent",value:function(e,t){if(!this.isActive)throw new Error("No active state. Please use append instead and pass an index.");this._append(this.current.collection,e,t)}},{key:"detach",value:function(e){if(!e)throw new Error("[Tribute] Must pass in a DOM node or NodeList.");if("undefined"!=typeof jQuery&&e instanceof jQuery&&(e=e.get()),e.constructor===NodeList||e.constructor===HTMLCollection||e.constructor===Array)for(var t=e.length,n=0;n'+(this.current.collection.trigger+e.original[this.current.collection.fillAttr])+"":this.current.collection.trigger+e.original[this.current.collection.fillAttr]}},{key:"defaultMenuItemTemplate",value:function(e){return e.string}},{key:"inputTypes",value:function(){return["TEXTAREA","INPUT"]}}]),B}();n.default=o,t.exports=n.default},{"./TributeEvents":2,"./TributeMenuEvents":3,"./TributeRange":4,"./TributeSearch":5,"./utils":7}],2:[function(e,t,n){"use strict";function i(e,t){for(var n=0;n container for the click");n.selectItemAtIndex(i.getAttribute("data-index"),t),n.hideMenu()}else n.current.element&&!n.current.externalTrigger&&(n.current.externalTrigger=!1,setTimeout(function(){return n.hideMenu()}))}},{key:"keyup",value:function(e,t){if(e.inputEvent&&(e.inputEvent=!1),e.updateSelection(this),27!==t.keyCode){if(!e.tribute.allowSpaces&&e.tribute.hasTrailingSpace)return e.tribute.hasTrailingSpace=!1,e.commandEvent=!0,void e.callbacks().space(t,this);if(!e.tribute.isActive)if(e.tribute.autocompleteMode)e.callbacks().triggerChar(t,this,"");else{var n=e.getKeyCode(e,this,t);if(isNaN(n)||!n)return;var i=e.tribute.triggers().find(function(e){return e.charCodeAt(0)===n});void 0!==i&&e.callbacks().triggerChar(t,this,i)}((e.tribute.current.trigger||e.tribute.autocompleteMode)&&!1===e.commandEvent||e.tribute.isActive&&8===t.keyCode)&&e.tribute.showMenuFor(this,!0)}}},{key:"shouldDeactivate",value:function(t){if(!this.tribute.isActive)return!1;if(0!==this.tribute.current.mentionText.length)return!1;var n=!1;return r.keys().forEach(function(e){t.keyCode===e.key&&(n=!0)}),!n}},{key:"getKeyCode",value:function(e,t,n){var i=e.tribute,r=i.range.getTriggerInfo(!1,i.hasTrailingSpace,!0,i.allowSpaces,i.autocompleteMode);return!!r&&r.mentionTriggerChar.charCodeAt(0)}},{key:"updateSelection",value:function(e){this.tribute.current.element=e;var t=this.tribute.range.getTriggerInfo(!1,this.tribute.hasTrailingSpace,!0,this.tribute.allowSpaces,this.tribute.autocompleteMode);t&&(this.tribute.current.selectedPath=t.mentionSelectedPath,this.tribute.current.mentionText=t.mentionText,this.tribute.current.selectedOffset=t.mentionSelectedOffset)}},{key:"callbacks",value:function(){var o=this;return{triggerChar:function(e,t,n){var i=o.tribute;i.current.trigger=n;var r=i.collection.find(function(e){return e.trigger===n});i.current.collection=r,i.inputEvent&&i.showMenuFor(t,!0)},enter:function(e,t){o.tribute.isActive&&o.tribute.current.filteredItems&&(e.preventDefault(),e.stopPropagation(),setTimeout(function(){o.tribute.selectItemAtIndex(o.tribute.menuSelected,e),o.tribute.hideMenu()},0))},escape:function(e,t){o.tribute.isActive&&(e.preventDefault(),e.stopPropagation(),o.tribute.isActive=!1,o.tribute.hideMenu())},tab:function(e,t){o.callbacks().enter(e,t)},space:function(e,t){o.tribute.isActive&&(o.tribute.spaceSelectsMatch?o.callbacks().enter(e,t):o.tribute.allowSpaces||(e.stopPropagation(),setTimeout(function(){o.tribute.hideMenu(),o.tribute.isActive=!1},0)))},up:function(e,t){if(o.tribute.isActive&&o.tribute.current.filteredItems){e.preventDefault(),e.stopPropagation();var n=o.tribute.current.filteredItems.length,i=o.tribute.menuSelected;i>>0;e&&(this.tribute.menuSelected=parseInt(e));for(var i=0;iu.bottom){var a=o.bottom-u.bottom;this.tribute.menu.scrollTop+=a}else if(o.tope.width&&(t.left||t.right),i=window.innerHeight>e.height&&(t.top||t.bottom);(n||i)&&(u.tribute.menu.style.cssText="display: none",u.positionMenuAtCaret(r))},0)}else this.tribute.menu.style.cssText="display: none"}},{key:"selectElement",value:function(e,t,n){var i,r=e;if(t)for(var o=0;oMath.ceil(o+n),bottom:s>Math.ceil(u+i),left:cparseInt(u.height)&&(o.overflowY="scroll")):o.overflow="hidden",r.textContent=e.value.substring(0,t),"INPUT"===e.nodeName&&(r.textContent=r.textContent.replace(/\s/g," "));var a=this.getDocument().createElement("span");a.textContent=e.value.substring(t)||".",r.appendChild(a);var l=e.getBoundingClientRect(),s=document.documentElement,c=(window.pageXOffset||s.scrollLeft)-(s.clientLeft||0),d=(window.pageYOffset||s.scrollTop)-(s.clientTop||0),f={top:l.top+d+a.offsetTop+parseInt(u.borderTopWidth)+parseInt(u.fontSize)-e.scrollTop,left:l.left+c+a.offsetLeft+parseInt(u.borderLeftWidth)},h=window.innerWidth,p=window.innerHeight,v=this.getMenuDimensions(),m=this.isMenuOffScreen(f,v);m.right&&(f.right=h-f.left,f.left="auto");var g=this.tribute.menuContainer?this.tribute.menuContainer.offsetHeight:this.getDocument().body.offsetHeight;if(m.bottom){var b=g-(p-(this.tribute.menuContainer?this.tribute.menuContainer.getBoundingClientRect():this.getDocument().body.getBoundingClientRect()).top);f.bottom=b+(p-l.top-a.offsetTop),f.top="auto"}return(m=this.isMenuOffScreen(f,v)).left&&(f.left=h>v.width?c+h-v.width:c,delete f.right),m.top&&(f.top=p>v.height?d+p-v.height:d,delete f.bottom),this.getDocument().body.removeChild(r),f}},{key:"getContentEditableCaretPosition",value:function(e){var t,n,i="sel_".concat((new Date).getTime(),"_").concat(Math.random().toString().substr(2)),r=this.getWindowSelection(),o=r.getRangeAt(0);(n=this.getDocument().createRange()).setStart(r.anchorNode,e),n.setEnd(r.anchorNode,e),n.collapse(!1),(t=this.getDocument().createElement("span")).id=i,t.appendChild(this.getDocument().createTextNode("\ufeff")),n.insertNode(t),r.removeAllRanges(),r.addRange(o);var u=t.getBoundingClientRect(),a=document.documentElement,l=(window.pageXOffset||a.scrollLeft)-(a.clientLeft||0),s=(window.pageYOffset||a.scrollTop)-(a.clientTop||0),c={left:u.left+l,top:u.top+t.offsetHeight+s},d=window.innerWidth,f=window.innerHeight,h=this.getMenuDimensions(),p=this.isMenuOffScreen(c,h);p.right&&(c.left="auto",c.right=d-u.left-l);var v=this.tribute.menuContainer?this.tribute.menuContainer.offsetHeight:this.getDocument().body.offsetHeight;if(p.bottom){var m=v-(f-(this.tribute.menuContainer?this.tribute.menuContainer.getBoundingClientRect():this.getDocument().body.getBoundingClientRect()).top);c.top="auto",c.bottom=m+(f-u.top)}return(p=this.isMenuOffScreen(c,h)).left&&(c.left=d>h.width?l+d-h.width:l,delete c.right),p.top&&(c.top=f>h.height?s+f-h.height:s,delete c.bottom),t.parentNode.removeChild(t),c}},{key:"scrollIntoView",value:function(e){var t,n=this.menu;if(void 0!==n){for(;void 0===t||0===t.height;)if(0===(t=n.getBoundingClientRect()).height&&(void 0===(n=n.childNodes[0])||!n.getBoundingClientRect))return;var i=t.top,r=i+t.height;if(i<0)window.scrollTo(0,window.pageYOffset+t.top-20);else if(r>window.innerHeight){var o=window.pageYOffset+t.top-20;100e.length-n)){for(var o,u,a=t[i],l=e.indexOf(a,n);-1>>0,r=arguments[1],o=0;o