mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
more topic searching work (working example, needs UX tie-in)
This commit is contained in:
@@ -445,16 +445,25 @@ var socket,
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#search-form').on('submit', function (e) {
|
require(['search'], function(search) {
|
||||||
e.preventDefault();
|
$('#search-form').on('submit', function (e) {
|
||||||
var input = $(this).find('input'),
|
e.preventDefault();
|
||||||
term = input.val();
|
var input = $(this).find('input'),
|
||||||
|
term = input.val();
|
||||||
|
|
||||||
|
|
||||||
require(['search'], function(search) {
|
|
||||||
search.query(term, function() {
|
search.query(term, function() {
|
||||||
input.val('');
|
input.val('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.topic-search')
|
||||||
|
.on('click', '.prev', function() {
|
||||||
|
search.topicDOM.prev();
|
||||||
|
})
|
||||||
|
.on('click', '.next', function() {
|
||||||
|
search.topicDOM.next();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ define('search', ['navigator'], function(nav) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
/* globals socket, ajaxify */
|
/* globals socket, ajaxify */
|
||||||
|
|
||||||
var Search = {};
|
var Search = {
|
||||||
|
current: {}
|
||||||
|
};
|
||||||
|
|
||||||
Search.query = function(term, callback) {
|
Search.query = function(term, callback) {
|
||||||
// Detect if a tid was specified
|
// Detect if a tid was specified
|
||||||
@@ -25,30 +27,62 @@ define('search', ['navigator'], function(nav) {
|
|||||||
tid: tid,
|
tid: tid,
|
||||||
term: term
|
term: term
|
||||||
}, function(err, pids) {
|
}, function(err, pids) {
|
||||||
var args = arguments;
|
callback(err);
|
||||||
|
|
||||||
// Sort pids numerically & store
|
// Sort pids numerically & store
|
||||||
Search.results = pids.sort(function(a, b) {
|
Search.current = {
|
||||||
return a-b;
|
results: pids.sort(function(a, b) {
|
||||||
});
|
return a-b;
|
||||||
|
}),
|
||||||
|
tid: tid,
|
||||||
|
term: term
|
||||||
|
};
|
||||||
|
|
||||||
if (!err && !ajaxify.currentPage.match(new RegExp('^topic/' + tid))) {
|
Search.topicDOM.update(0);
|
||||||
ajaxify.go('topic/' + tid, function() {
|
|
||||||
if (callback) callback.apply(null, args);
|
|
||||||
Search.highlightResult(0);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (callback) callback.apply(null, args);
|
|
||||||
Search.highlightResult(0);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Search.highlightResult = function(index) {
|
Search.checkPagePresence = function(tid, callback) {
|
||||||
socket.emit('posts.getPidIndex', Search.results[index], function(err, postIndex) {
|
if (!ajaxify.currentPage.match(new RegExp('^topic/' + tid))) {
|
||||||
nav.scrollToPost(postIndex-1, true); // why -1? Ask @barisusakli
|
ajaxify.go('topic/' + tid, callback);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Search.topicDOM = {};
|
||||||
|
Search.topicDOM.start = function() {
|
||||||
|
var topicSearchEl = $('.topic-search');
|
||||||
|
|
||||||
|
topicSearchEl.find('.count').html('1 / ' + Search.current.results.length);
|
||||||
|
topicSearchEl.removeClass('hidden');
|
||||||
|
Search.checkPagePresence(Search.current.tid, function() {
|
||||||
|
Search.highlightResult(0);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Search.topicDOM.prev = function() {
|
||||||
|
Search.topicDOM.update((Search.current.index === 0) ? Search.current.results.length-1 : Search.current.index-1);
|
||||||
|
};
|
||||||
|
|
||||||
|
Search.topicDOM.next = function() {
|
||||||
|
Search.topicDOM.update((Search.current.index === Search.current.results.length-1) ? 0 : Search.current.index+1);
|
||||||
|
};
|
||||||
|
|
||||||
|
Search.topicDOM.update = function(index) {
|
||||||
|
var topicSearchEl = $('.topic-search');
|
||||||
|
|
||||||
|
Search.current.index = index;
|
||||||
|
|
||||||
|
topicSearchEl.find('.count').html((index+1) + ' / ' + Search.current.results.length);
|
||||||
|
topicSearchEl.removeClass('hidden');
|
||||||
|
Search.checkPagePresence(Search.current.tid, function() {
|
||||||
|
socket.emit('posts.getPidIndex', Search.current.results[index], function(err, postIndex) {
|
||||||
|
nav.scrollToPost(postIndex-1, true); // why -1? Ask @barisusakli
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return Search;
|
return Search;
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user