|
|
|
@ -10,9 +10,10 @@ var _followsPerPage = 200;
@@ -10,9 +10,10 @@ var _followsPerPage = 200;
|
|
|
|
|
var _maxFollowingPages = 50; |
|
|
|
|
var _followingSeqNum = 0; |
|
|
|
|
var _followSuggestions = []; |
|
|
|
|
var _searchingPartialUsers = ""; |
|
|
|
|
var _searchingPartialName = ''; |
|
|
|
|
var _searchKeypressTimer = undefined; |
|
|
|
|
var _lastSearchUsersResults = []; |
|
|
|
|
var _lastSearchUsersResultsRemovedFromDHTgetQueue = true; |
|
|
|
|
var _lastLoadFromDhtTime = 0; |
|
|
|
|
|
|
|
|
|
var twisterFollowingO = undefined; |
|
|
|
@ -578,101 +579,96 @@ function processWhoToFollowSuggestion(suggestion, followedBy) {
@@ -578,101 +579,96 @@ function processWhoToFollowSuggestion(suggestion, followedBy) {
|
|
|
|
|
console.warn('nothing to proceed: no twisters to follow was suggested'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function closeSearchDialog() |
|
|
|
|
{ |
|
|
|
|
$(".userMenu-search-field").siblings().slideUp( "fast" ); |
|
|
|
|
removeUsersFromDhtgetQueue( _lastSearchUsersResults ); |
|
|
|
|
_lastSearchUsersResults = []; |
|
|
|
|
function closeSearchDialog(event) { |
|
|
|
|
var elemEvent = event ? $(event.target) : this; |
|
|
|
|
elemEvent.siblings('.search-results').slideUp('fast'); |
|
|
|
|
if (!_lastSearchUsersResultsRemovedFromDHTgetQueue) { |
|
|
|
|
removeUsersFromDhtgetQueue(_lastSearchUsersResults); |
|
|
|
|
_lastSearchUsersResultsRemovedFromDHTgetQueue = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function userSearchKeypress(event) { |
|
|
|
|
var partialName = $(".userMenu-search-field").val().toLowerCase(); |
|
|
|
|
var searchResults = $(".search-results"); |
|
|
|
|
|
|
|
|
|
if ( partialName.substr( 0, 1 ) == '#' ) { |
|
|
|
|
var elemEvent = $(event.target); |
|
|
|
|
var partialName = elemEvent.val().toLowerCase(); |
|
|
|
|
|
|
|
|
|
if(searchResults.is(":visible")) |
|
|
|
|
searchResults.slideUp( "fast" ); |
|
|
|
|
|
|
|
|
|
if ( event.which == 13 ) |
|
|
|
|
window.location.hash = '#hashtag?hashtag=' + encodeURIComponent(partialName.substr(1)); |
|
|
|
|
if (event.data.hashtags && partialName[0] === '#') { |
|
|
|
|
var searchResults = elemEvent.siblings('.search-results'); |
|
|
|
|
if (searchResults.is(':visible')) |
|
|
|
|
searchResults.slideUp('fast'); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( partialName.substr( 0, 1 ) == '@' ) { |
|
|
|
|
partialName = partialName.substr( 1 ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//var partialName = item.val();
|
|
|
|
|
var words = partialName.match(/\b\w+/g); |
|
|
|
|
if (words && words.length) { |
|
|
|
|
partialName = words.pop(); |
|
|
|
|
|
|
|
|
|
if( !partialName.length ) { |
|
|
|
|
closeSearchDialog(); |
|
|
|
|
} else { |
|
|
|
|
if( _searchKeypressTimer !== undefined ) |
|
|
|
|
if (typeof _searchKeypressTimer !== 'undefined') |
|
|
|
|
clearTimeout(_searchKeypressTimer); |
|
|
|
|
|
|
|
|
|
if( _searchingPartialUsers.length ) { |
|
|
|
|
_searchingPartialUsers = partialName; |
|
|
|
|
if (_searchingPartialName.length) { |
|
|
|
|
_searchingPartialName = partialName; |
|
|
|
|
} else { |
|
|
|
|
_searchKeypressTimer = setTimeout( function() { |
|
|
|
|
_searchKeypressTimer = setTimeout(function () { |
|
|
|
|
_searchKeypressTimer = undefined; |
|
|
|
|
searchPartialUsername(partialName); |
|
|
|
|
event.data.partialName = partialName; |
|
|
|
|
searchPartialUsername(event); |
|
|
|
|
}, 600); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else |
|
|
|
|
closeSearchDialog(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function searchPartialUsername(event) { |
|
|
|
|
_searchingPartialName = event.data.partialName; |
|
|
|
|
twisterRpc('listusernamespartial', [event.data.partialName, 10], |
|
|
|
|
function(event, ret) { |
|
|
|
|
if (event.data.partialName !== _searchingPartialName) |
|
|
|
|
setTimeout(searchPartialUsername, 100, event); |
|
|
|
|
else { |
|
|
|
|
if (!_lastSearchUsersResultsRemovedFromDHTgetQueue) |
|
|
|
|
removeUsersFromDhtgetQueue(_lastSearchUsersResults); |
|
|
|
|
else |
|
|
|
|
_lastSearchUsersResultsRemovedFromDHTgetQueue = false; |
|
|
|
|
_lastSearchUsersResults = ret; |
|
|
|
|
|
|
|
|
|
if (ret && ret.length) { |
|
|
|
|
if (event.data.handleRet) |
|
|
|
|
event.data.handleRet(event, ret); |
|
|
|
|
} else { |
|
|
|
|
if (event.data.handleRetZero) |
|
|
|
|
event.data.handleRetZero(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function searchPartialUsername(partialName) { |
|
|
|
|
_searchingPartialUsers = partialName; |
|
|
|
|
twisterRpc("listusernamespartial", [partialName,10], |
|
|
|
|
function(partialName, ret) { |
|
|
|
|
processDropdownUserResults(partialName, ret) |
|
|
|
|
}, partialName, |
|
|
|
|
function(cbArg, ret) { |
|
|
|
|
console.log("ajax error:" + ret); |
|
|
|
|
}, {}); |
|
|
|
|
_searchingPartialName = ''; |
|
|
|
|
} |
|
|
|
|
}, event, |
|
|
|
|
function(req, ret) {console.warn('ajax error:' + ret.message);}, null |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function processDropdownUserResults(partialName, results){ |
|
|
|
|
function processDropdownUserResults(event, results) { |
|
|
|
|
var container = $('.userMenu-search-profiles').empty(); |
|
|
|
|
var template = $('#search-profile-template').children(); |
|
|
|
|
|
|
|
|
|
if( partialName != _searchingPartialUsers ) { |
|
|
|
|
searchPartialUsername( _searchingPartialUsers ); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
for (var i = 0; i < results.length; i++) { |
|
|
|
|
if (results[i] === defaultScreenName) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
removeUsersFromDhtgetQueue( _lastSearchUsersResults ); |
|
|
|
|
_lastSearchUsersResults = results; |
|
|
|
|
|
|
|
|
|
var typeaheadAccounts = $(".userMenu-search-profiles"); |
|
|
|
|
var template = $("#search-profile-template").detach(); |
|
|
|
|
|
|
|
|
|
typeaheadAccounts.empty(); |
|
|
|
|
typeaheadAccounts.append(template); |
|
|
|
|
|
|
|
|
|
if( results.length ) { |
|
|
|
|
for( var i = 0; i < results.length; i++ ) { |
|
|
|
|
if( results[i] == defaultScreenName ) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
var resItem = template.clone(true); |
|
|
|
|
resItem.removeAttr('id'); |
|
|
|
|
resItem.show(); |
|
|
|
|
resItem.find(".mini-profile-info").attr("data-screen-name", results[i]); |
|
|
|
|
resItem.find(".mini-screen-name b").text(results[i]); |
|
|
|
|
resItem.find("a.open-profile-modal").attr("href",$.MAL.userUrl(results[i])); |
|
|
|
|
getAvatar(results[i],resItem.find(".mini-profile-photo")); |
|
|
|
|
getFullname(results[i],resItem.find(".mini-profile-name")); |
|
|
|
|
resItem.appendTo(typeaheadAccounts); |
|
|
|
|
if (followingUsers.indexOf(results[i]) >= 0) |
|
|
|
|
toggleFollowButton(results[i], true); |
|
|
|
|
} |
|
|
|
|
var item = template.clone(true); |
|
|
|
|
item.find('.mini-profile-info').attr('data-screen-name', results[i]); |
|
|
|
|
item.find('.mini-screen-name b').text(results[i]); |
|
|
|
|
item.find('a.open-profile-modal').attr('href', $.MAL.userUrl(results[i])); |
|
|
|
|
getAvatar(results[i], item.find('.mini-profile-photo')); |
|
|
|
|
getFullname(results[i], item.find('.mini-profile-name')); |
|
|
|
|
item.appendTo(container); |
|
|
|
|
|
|
|
|
|
$.MAL.searchUserListLoaded(); |
|
|
|
|
} else { |
|
|
|
|
closeSearchDialog(); |
|
|
|
|
if (followingUsers.indexOf(results[i]) !== -1) |
|
|
|
|
toggleFollowButton(results[i], true); |
|
|
|
|
} |
|
|
|
|
_searchingPartialUsers = ""; |
|
|
|
|
|
|
|
|
|
$.MAL.searchUserListLoaded(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function userClickFollow(e) { |
|
|
|
@ -700,10 +696,13 @@ function userClickFollow(e) {
@@ -700,10 +696,13 @@ function userClickFollow(e) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function initUserSearch() { |
|
|
|
|
var $userSearchField = $( ".userMenu-search-field" ); |
|
|
|
|
$userSearchField.keyup( userSearchKeypress ); |
|
|
|
|
$userSearchField.bind( "click", userSearchKeypress ); |
|
|
|
|
$(".userMenu-search").clickoutside( closeSearchDialog ); |
|
|
|
|
var elem = $('.userMenu-search-field') |
|
|
|
|
.on('click input', |
|
|
|
|
{hashtags: true, handleRet: processDropdownUserResults, |
|
|
|
|
handleRetZero: closeSearchDialog}, userSearchKeypress) |
|
|
|
|
.on('keyup', userSearchEnter) |
|
|
|
|
; |
|
|
|
|
$('.userMenu-search').clickoutside(closeSearchDialog.bind(elem)); |
|
|
|
|
|
|
|
|
|
// following stuff should be moved to special function
|
|
|
|
|
$('button.follow').on('click', userClickFollow); |
|
|
|
@ -716,6 +715,14 @@ function initUserSearch() {
@@ -716,6 +715,14 @@ function initUserSearch() {
|
|
|
|
|
; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function userSearchEnter(event) { |
|
|
|
|
if (event.which === 13) { |
|
|
|
|
var str = $(event.target).val().toLowerCase().trim(); |
|
|
|
|
if (str[0] === '#') |
|
|
|
|
window.location.hash = '#hashtag?hashtag=' + encodeURIComponent(str.slice(1)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function followingListPublicCheckbox(e) { |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
|
|
|
|
|