|
|
@ -126,72 +126,6 @@ define(['taskbar'], function(taskbar) {
|
|
|
|
composer.posts[post_uuid].modified = true;
|
|
|
|
composer.posts[post_uuid].modified = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function getUniqueUserslugs() {
|
|
|
|
|
|
|
|
var postContainer = $('#post-container');
|
|
|
|
|
|
|
|
if(postContainer.length) {
|
|
|
|
|
|
|
|
var elements = $('#post-container li[data-userslug]');
|
|
|
|
|
|
|
|
if(!elements.length) {
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var slugs = [];
|
|
|
|
|
|
|
|
for(var i=0; i<elements.length; ++i) {
|
|
|
|
|
|
|
|
var slug = $(elements[i]).attr('data-userslug');
|
|
|
|
|
|
|
|
if(slugs.indexOf('@' + slug) === -1) {
|
|
|
|
|
|
|
|
slugs.push('@' + slug);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return slugs;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(bodyEl).autocomplete({
|
|
|
|
|
|
|
|
source: function(request, response) {
|
|
|
|
|
|
|
|
var term = request.term;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cursorPosition = $(bodyEl).getCursorPosition();
|
|
|
|
|
|
|
|
term = term.substr(0, cursorPosition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var lastMention = term.lastIndexOf('@');
|
|
|
|
|
|
|
|
if(lastMention !== -1) {
|
|
|
|
|
|
|
|
term = term.substr(lastMention);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var userslugs = getUniqueUserslugs();
|
|
|
|
|
|
|
|
userslugs = userslugs.filter(function(slug) {
|
|
|
|
|
|
|
|
return term && slug.indexOf(term) === 0;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response(userslugs);
|
|
|
|
|
|
|
|
$('.ui-autocomplete a').attr('href', '#');
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
focus: function(event, ui) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
select: function(event, ui) {
|
|
|
|
|
|
|
|
var cursorPosition = $(bodyEl).getCursorPosition();
|
|
|
|
|
|
|
|
var upToCursor = $(bodyEl).val().substr(0, cursorPosition);
|
|
|
|
|
|
|
|
var index = upToCursor.lastIndexOf('@');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(index !== -1) {
|
|
|
|
|
|
|
|
var firstPart = $(bodyEl).val().substr(0, index);
|
|
|
|
|
|
|
|
var lastPart = $(bodyEl).val().substr(cursorPosition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(bodyEl).val(firstPart + ui.item.value + lastPart);
|
|
|
|
|
|
|
|
$(bodyEl).selectRange(index + ui.item.value.length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
position: { my : "left bottom", at: "left bottom" }
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postContainer.on('click', '.action-bar button', function() {
|
|
|
|
postContainer.on('click', '.action-bar button', function() {
|
|
|
|
var action = $(this).attr('data-action');
|
|
|
|
var action = $(this).attr('data-action');
|
|
|
|
|
|
|
|
|
|
|
|