Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

placement:auto and tags no longer need to use jquery-ui.autocomplete #133

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions static/lib/composer/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ define('composer/autocomplete', ['composer/preview'], function(preview) {
autocomplete.init = function(postContainer, post_uuid) {
var element = postContainer.find('.write');
var dropdownClass = 'composer-autocomplete-dropdown-' + post_uuid;
var timer;

if (!element.length) {
/**
Expand All @@ -34,26 +33,14 @@ define('composer/autocomplete', ['composer/preview'], function(preview) {
element: element,
strategies: [],
options: {
placement: 'auto',
style: {
'z-index': 20000,
},
className: dropdownClass + ' dropdown-menu textcomplete-dropdown',
}
};

element.on('keyup', function () {
clearTimeout(timer);
timer = setTimeout(function () {
var dropdown = document.querySelector('.' + dropdownClass);
var pos = dropdown.getBoundingClientRect();

var margin = parseFloat(dropdown.style.marginTop, 10) || 0;

var offset = window.innerHeight + margin - 10 - pos.bottom;
dropdown.style.marginTop = Math.min(offset, 0) + 'px';
}, 0);
});

$(window).trigger('composer:autocomplete:init', data);

autocomplete._active[post_uuid] = autocomplete.setup(data);
Expand Down Expand Up @@ -84,6 +71,15 @@ define('composer/autocomplete', ['composer/preview'], function(preview) {
var textcomplete = new window.Textcomplete(editor, {
dropdown: data.options,
});

// hack till https://github.com/yuku/textcomplete/issues/166
var _getCursorOffset = editor.getCursorOffset;
editor.getCursorOffset = function () {
var offset = _getCursorOffset.apply(editor, arguments);
offset.clientTop = offset.top;
return offset;
};

textcomplete.register(data.strategies);
textcomplete.on('rendered', function () {
if (textcomplete.dropdown.items.length) {
Expand Down
28 changes: 2 additions & 26 deletions static/lib/composer/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*globals ajaxify, define, config, socket, app, utils*/

define('composer/tags', function() {
define('composer/tags', [ 'autocomplete' ], function(autocomplete) {
var tags = {};

tags.init = function(postContainer, postData) {
Expand Down Expand Up @@ -51,31 +51,7 @@ define('composer/tags', function() {
var input = postContainer.find('.bootstrap-tagsinput input');
toggleTagInput(postContainer, postData, ajaxify.data);

app.loadJQueryUI(function() {
input.autocomplete({
delay: 100,
position: { my: "left bottom", at: "left top", collision: "flip" },
appendTo: postContainer.find('.bootstrap-tagsinput'),
open: function() {
$(this).autocomplete('widget').css('z-index', 20000);
},
source: function(request, response) {
socket.emit('topics.autocompleteTags', {query: request.term, cid: postData.cid}, function(err, tags) {
if (err) {
return app.alertError(err.message);
}
if (tags) {
response(tags);
}
$('.ui-autocomplete a').attr('data-ajaxify', 'false');
});
},
select: function(event, ui) {
// when autocomplete is selected from the dropdown simulate a enter key down to turn it into a tag
triggerEnter(input);
}
});
});
autocomplete.tag(input);

input.attr('tabIndex', tagEl.attr('tabIndex'));
input.on('blur', function() {
Expand Down