Remove "find in page" functionality.

This was a source of user confusion and didn't provide that much value.

(imported from commit fbe9405d8bc4cb6661baa7fe7583eab5ed73d886)
This commit is contained in:
Luke Faraone 2013-02-28 15:11:53 -05:00
parent 1650dba322
commit d88107567a
4 changed files with 4 additions and 168 deletions

View File

@ -16,8 +16,6 @@
<div id="search_arrows"> <div id="search_arrows">
<input class="search-query" id="search_query" type="text" placeholder="Search…" <input class="search-query" id="search_query" type="text" placeholder="Search…"
autocomplete="off"> autocomplete="off">
<button class="btn search_button search_button_middle" type="button" id="search_up"><i class="icon-chevron-up"></i></button>
<button class="btn search_button search_button_middle" type="button" id="search_down"><i class="icon-chevron-down"></i></button>
<button class="btn search_button" type="button" id="search_exit"><i class="icon-remove"></i></button> <button class="btn search_button" type="button" id="search_exit"><i class="icon-remove"></i></button>
</div> </div>
</form> </form>

View File

@ -61,11 +61,6 @@ function process_hotkey(e) {
compose.cancel(); compose.cancel();
} }
} }
// Keycode 13 is Return.
if ((code === 13) && $("#search_query").is(":focus")) {
// Pass it along to the search up button.
$("#search_up").focus();
}
// Let the browser handle the key normally. // Let the browser handle the key normally.
return false; return false;
} }
@ -127,13 +122,8 @@ function process_hotkey(e) {
compose.set_mode('private'); compose.set_mode('private');
return true; return true;
case 13: // Enter: respond to message (unless we need to do something else) case 13: // Enter: respond to message (unless we need to do something else)
if (search.keyboard_currently_finding()) { respond_to_message();
// Pass through to our searchbox (to advance to next result) return true;
return false;
} else {
respond_to_message();
return true;
}
case 114: // 'r': respond to message case 114: // 'r': respond to message
respond_to_message(); respond_to_message();
return true; return true;

View File

@ -274,9 +274,6 @@ exports.activate = function (operators, opts) {
allow_collapse = opts.allow_collapse; allow_collapse = opts.allow_collapse;
// Before we clear the table, check if anything was highlighted.
var highlighted = search.something_is_highlighted();
clear_table('zfilt'); clear_table('zfilt');
narrowed_msg_list = new MessageList('zfilt'); narrowed_msg_list = new MessageList('zfilt');
current_msg_list = narrowed_msg_list; current_msg_list = narrowed_msg_list;
@ -326,11 +323,6 @@ exports.activate = function (operators, opts) {
reset_load_more_status(); reset_load_more_status();
maybe_select_closest(); maybe_select_closest();
// If anything was highlighted before, try to rehighlight it.
if (highlighted) {
search.update_highlight_on_narrow();
}
// Put the narrow operators in the URL fragment and search bar // Put the narrow operators in the URL fragment and search bar
hashchange.save_narrow(operators); hashchange.save_narrow(operators);
$('#search_query').val(unparse(operators)); $('#search_query').val(unparse(operators));
@ -406,8 +398,6 @@ exports.deactivate = function () {
// view since leaving it the old selected id might no longer be there // view since leaving it the old selected id might no longer be there
home_msg_list.select_id(home_msg_list.selected_id(), {then_scroll: true, use_closest: true}); home_msg_list.select_id(home_msg_list.selected_id(), {then_scroll: true, use_closest: true});
search.update_highlight_on_narrow();
hashchange.save_narrow(); hashchange.save_narrow();
$("ul.filters li").removeClass('active-filter'); $("ul.filters li").removeClass('active-filter');

View File

@ -24,9 +24,6 @@ function get_person(obj) {
function render_object_in_parts(obj) { function render_object_in_parts(obj) {
// N.B. action is *not* escaped by the caller // N.B. action is *not* escaped by the caller
switch (obj.action) { switch (obj.action) {
case 'search':
return {prefix: 'Find', query: get_query(obj), suffix: 'in page'};
case 'stream': case 'stream':
return {prefix: 'Narrow to stream', query: get_query(obj), suffix: ''}; return {prefix: 'Narrow to stream', query: get_query(obj), suffix: ''};
@ -68,11 +65,9 @@ exports.update_typeahead = function () {
return {action: 'sender', query: elt}; return {action: 'sender', query: elt};
}); });
var options = streams.concat(people).concat(senders); var options = streams.concat(people).concat(senders);
// The first slot is reserved for "narrow to messages containing x", // The first slot is reserved for "narrow to messages containing x".
// and the last one for "Find in page"
// (this is updated in the source function for our typeahead as well) // (this is updated in the source function for our typeahead as well)
options.unshift({action: 'operators', query: '', operators: []}); options.unshift({action: 'operators', query: '', operators: []});
options.push({action: 'search', query: ''});
mapped = {}; mapped = {};
labels = []; labels = [];
@ -89,8 +84,6 @@ function narrow_or_search_for_term(item) {
ui.change_tab_to('#home'); ui.change_tab_to('#home');
switch (obj.action) { switch (obj.action) {
case 'search': case 'search':
$("#search_up").focus();
exports.search_button_handler(true);
return obj.query; return obj.query;
case 'stream': case 'stream':
@ -165,7 +158,7 @@ function update_buttons_with_focus(focused) {
} }
// Shrink the searchbox to make room for the buttons. // Shrink the searchbox to make room for the buttons.
var new_width = search_query.width() - var new_width = search_query.width() -
$('.search_button').outerWidth(true)*3; $('.search_button').outerWidth(true);
search_query.width(new_width-1); search_query.width(new_width-1);
$("#search_arrows").addClass("input-append"); $("#search_arrows").addClass("input-append");
$('.search_button').show(); $('.search_button').show();
@ -173,7 +166,6 @@ function update_buttons_with_focus(focused) {
// Hide buttons. // Hide buttons.
$('#search_query').width(''); $('#search_query').width('');
$("#search_arrows").removeClass("input-append"); $("#search_arrows").removeClass("input-append");
$("#search_up, #search_down").removeAttr("disabled");
$('.search_button').blur().hide(); $('.search_button').blur().hide();
} }
} }
@ -187,7 +179,6 @@ exports.initialize = function () {
source: function (query, process) { source: function (query, process) {
// Delete our old search queries (one for find-in-page, one for operators) // Delete our old search queries (one for find-in-page, one for operators)
delete mapped[labels.shift()]; // Operators delete mapped[labels.shift()]; // Operators
delete mapped[labels.pop()]; // Find-in-page
// Add an entry for narrow by operators. // Add an entry for narrow by operators.
var operators = narrow.parse(query); var operators = narrow.parse(query);
@ -196,17 +187,6 @@ exports.initialize = function () {
mapped[label] = obj; mapped[label] = obj;
labels.unshift(label); labels.unshift(label);
// Add an entry for find-in-page.
obj = {action: 'search', query: query};
if (operators.length > 0 && operators[0][0] !== 'search') {
// We have operators other than a search term.
// Disable find-in-page.
obj.disabled = true;
}
label = render_object(obj);
mapped[label] = obj;
labels.push(label);
return labels; return labels;
}, },
items: 4, items: 4,
@ -266,8 +246,6 @@ exports.initialize = function () {
// Some of these functions don't actually need to be exported, // Some of these functions don't actually need to be exported,
// but the code was moved here from elsewhere, and it would be // but the code was moved here from elsewhere, and it would be
// more work to re-order everything and make them private. // more work to re-order everything and make them private.
$('#search_up' ).on('click', function () { exports.search_button_handler(true); });
$('#search_down' ).on('click', function () { exports.search_button_handler(false); });
$('#search_exit' ).on('click', exports.clear_search); $('#search_exit' ).on('click', exports.clear_search);
var query = $('#search_query'); var query = $('#search_query');
@ -305,109 +283,9 @@ function match_on_visible_text(row, search_term) {
.text().toLowerCase().indexOf(search_term) !== -1; .text().toLowerCase().indexOf(search_term) !== -1;
} }
function disable_search_arrows_if(condition, affected_arrows) {
var i, button;
for (i = 0; i < affected_arrows.length; i++) {
button = $("#search_" + affected_arrows[i]);
if (condition) {
button.attr("disabled", "disabled");
} else {
button.removeAttr("disabled");
}
}
}
function search(term, highlighted_message, reverse) {
// term: case-insensitive text to search for
// highlighted_message: the current location of the pointer. Ignored
// on cached queries
// reverse: boolean as to whether the search is forward or backwards
//
// returns a message object containing the search term.
var previous_header_matched = false;
var focused_table = $('table.focused_table');
if ((term !== cached_term) || (cached_table[0] !== focused_table[0])) {
cached_term = term;
cached_matches = [];
cached_index = null;
cached_table = focused_table;
var selected_zid = rows.id(highlighted_message);
focused_table.find('.message_row, .recipient_row').each(function (index, row) {
row = $(row);
if (previous_header_matched || (match_on_visible_text(row, term))) {
previous_header_matched = false;
if (row.hasClass("recipient_row")) {
previous_header_matched = true;
} else {
cached_matches.push(row);
var zid = rows.id(row);
if ((reverse && (zid <= selected_zid)) ||
(!reverse && (zid >= selected_zid) && !cached_index)) {
// Keep track of the closest match going up or down.
cached_index = cached_matches.length - 1;
}
}
}
});
disable_search_arrows_if(cached_matches.length === 0, ["up", "down"]);
return cached_matches[cached_index];
}
if (reverse) {
if (cached_index > 0) {
cached_index--;
}
} else {
if (cached_index < cached_matches.length - 1) {
cached_index++;
}
}
disable_search_arrows_if(cached_matches.length === 0, ["up", "down"]);
disable_search_arrows_if(cached_index === 0, ["up"]);
disable_search_arrows_if(cached_index === cached_matches.length - 1, ["down"]);
return cached_matches[cached_index];
}
function highlight_match(row, search_term) {
$('table tr').removeHighlight();
row.find('.message_content').highlight(search_term);
row = row.prev('.recipient_row');
if ((row.length !== 0) && (match_on_visible_text(row, search_term))) {
row.find('.message_label_clickable').highlight(search_term);
}
}
exports.search_button_handler = function (reverse) {
search_active = true;
var query = $('#search_query').val().toLowerCase();
var res = search(query, current_msg_list.selected_row(), reverse);
if (!res) {
return;
}
current_msg_list.select_id(rows.id(res));
highlight_match(res, query);
scroll_to_selected();
};
function clear_search_cache() {
cached_term = "";
}
exports.focus_search = function () { exports.focus_search = function () {
// The search bar is not focused yet, but will be. // The search bar is not focused yet, but will be.
update_buttons_with_focus(true); update_buttons_with_focus(true);
disable_search_arrows_if(false, ["up", "down"]);
}; };
exports.initiate_search = function () { exports.initiate_search = function () {
@ -421,26 +299,6 @@ exports.clear_search = function () {
$('table tr').removeHighlight(); $('table tr').removeHighlight();
$('#search_query').blur(); $('#search_query').blur();
exports.update_button_visibility(); exports.update_button_visibility();
clear_search_cache();
};
exports.something_is_highlighted = function () {
return $(".highlight").length > 0;
};
exports.update_highlight_on_narrow = function () {
highlight_match(current_msg_list.selected_row(), cached_term);
clear_search_cache();
};
exports.keyboard_currently_finding = function () {
// This is somewhat subtle because it doesn't actually mean
// "is a find in progress" -- it means "is the keyboard
// currently driving a find"
// (If you have a Find going and you just click the button,
// the focus goes away and this starts being False,
// even though a find is still active.)
return $('.search_button').is(':focus');
}; };
return exports; return exports;