mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
username mention auto completes
This commit is contained in:
@@ -115,14 +115,70 @@ define(['taskbar'], function(taskbar) {
|
|||||||
} else {
|
} else {
|
||||||
titleEl.val(postData.title);
|
titleEl.val(postData.title);
|
||||||
titleEl.prop('readOnly', false);
|
titleEl.prop('readOnly', false);
|
||||||
}
|
}$
|
||||||
|
|
||||||
bodyEl.val(postData.body);
|
bodyEl.val(postData.body);
|
||||||
|
|
||||||
|
|
||||||
postContainer.on('change', 'input, textarea', function() {
|
postContainer.on('change', 'input, textarea', function() {
|
||||||
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 lastMention = request.term.lastIndexOf('@');
|
||||||
|
if(lastMention !== -1) {
|
||||||
|
term = request.term.substr(lastMention);
|
||||||
|
}
|
||||||
|
|
||||||
|
var userslugs = getUniqueUserslugs();
|
||||||
|
userslugs = userslugs.filter(function(slug) {
|
||||||
|
return term && slug.indexOf(term) === 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
response(userslugs);
|
||||||
|
$('.ui-autocomplete a').attr('href', '#');
|
||||||
|
},
|
||||||
|
response: function(event, ui) {
|
||||||
|
var content = $(bodyEl).val();
|
||||||
|
var lastIndex = content.lastIndexOf('@');
|
||||||
|
if(content === '@') {
|
||||||
|
content = '';
|
||||||
|
} else if(lastIndex !== -1) {
|
||||||
|
content = content.substr(0, lastIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var i=0; i<ui.content.length; ++i) {
|
||||||
|
ui.content[i].value = content + ui.content[i].value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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');
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- TODO : this has to be refactored, maybe configured from ACP? -baris -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
<ul id="post-container" class="posts" data-tid="{topic_id}">
|
<ul id="post-container" class="posts" data-tid="{topic_id}">
|
||||||
<!-- BEGIN posts -->
|
<!-- BEGIN posts -->
|
||||||
<li class="row post-row infiniteloaded" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.username}" data-index="{posts.index}" data-deleted="{posts.deleted}" itemscope itemtype="http://schema.org/Comment">
|
<li class="row post-row infiniteloaded" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.username}" data-userslug="{posts.userslug}" data-index="{posts.index}" data-deleted="{posts.deleted}" itemscope itemtype="http://schema.org/Comment">
|
||||||
<a id="post_anchor_{posts.pid}" name="{posts.pid}"></a>
|
<a id="post_anchor_{posts.pid}" name="{posts.pid}"></a>
|
||||||
|
|
||||||
<meta itemprop="datePublished" content="{posts.relativeTime}">
|
<meta itemprop="datePublished" content="{posts.relativeTime}">
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user