Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip deprecated keyboards #147

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions cdn/dev/keyboard-search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ var embed_query_x = embed_query == '' ? '' : '&'+embed_query;

var counter = 0;

function getCurrentPath(q, page) {
function getCurrentPath(q, page, obsolete) {
var r = q.match(/^(c|l)\:(id)\:(.+)$/);
obsolete = obsolete ? '&obsolete=1' : '';
if(r && r[1].charAt(0) == 'c') {
return '/keyboards/countries/'+r[3]+'?page='+page;
return '/keyboards/countries/'+r[3]+'?page='+page+obsolete;
} else if(r && r[1].charAt(0) == 'l') {
return '/keyboards/languages/'+r[3]+'?page='+page;
return '/keyboards/languages/'+r[3]+'?page='+page+obsolete;
} else {
return '/keyboards?q='+encodeURIComponent(q)+'&page='+page;
return '/keyboards?q='+encodeURIComponent(q)+'&page='+page+obsolete;
}
}

Expand All @@ -30,6 +31,8 @@ function wrapSearch(localCounter, updateHistory) {
var page = parseInt(document.f.page.value, 10);
if(isNaN(page) || page < 1 || page > 999) page = 1;

var obsolete = document.f.obsolete.value == 1;

var q = document.f.q.value.trim();
// Workaround for HTML form encoding spaces with "+", which breaks keyboard searches
q = q.replace(/\+/g, ' ');
Expand All @@ -50,14 +53,18 @@ function wrapSearch(localCounter, updateHistory) {
url += '&embed='+embed;
}

if(obsolete) {
url += '&obsolete='+obsolete;
}

if(detail_page) {
location.href = getCurrentPath(q, page);
location.href = getCurrentPath(q, page, obsolete);
return false;
}

var xhr = createCORSRequest('GET', url);

var currentPath = getCurrentPath(q, page);
var currentPath = getCurrentPath(q, page, obsolete);

xhr.onload = function() {
if(counter > localCounter) {
Expand All @@ -69,11 +76,11 @@ function wrapSearch(localCounter, updateHistory) {

//hide_loading();
$('#search-box').removeClass('searching');
currentPath = getCurrentPath(q, page);
currentPath = getCurrentPath(q, page, obsolete);
if(updateHistory) {
history.pushState({q: q, text: responseText}, q + ' - Keyboard search', currentPath);
history.pushState({q: q, obsolete: obsolete, text: responseText}, q + ' - Keyboard search', currentPath);
}
process_response(q, xhr.responseText);
process_response(q, obsolete, xhr.responseText);
// process the response.
};

Expand All @@ -94,13 +101,13 @@ function wrapSearch(localCounter, updateHistory) {

window.onpopstate = function(e) {
if(e.state) {
process_response(e.state.q, e.state.text);
process_response(e.state.q, e.state.obsolete, e.state.text);
$('#search-q').val(e.state.q);
return true;
} else return false;
};

function process_response(q, res) {
function process_response(q, obsolete, res) {
var resultsElement = $('#search-results');
res = JSON.parse(res);
resultsElement.empty();
Expand Down Expand Up @@ -197,18 +204,18 @@ function process_response(q, res) {
});

if(res.context.totalPages > 1) {
buildPager(res, q).appendTo(resultsElement);
buildPager(res, q, obsolete).appendTo(resultsElement);
}
} else {
$('<h3>').addClass('red').text("No matches found for '"+qq+"'").appendTo(resultsElement);
}
}

function buildPager(res, q) {
function buildPager(res, q, obsolete) {
var pager = $('<div class="pager">');
function appendPager(pager, text, page) {
if(page != res.context.pageNumber && page > 0 && page <= res.context.totalPages) {
$('<a>'+text+'</a>').attr('href', getCurrentPath(q, page)).click((event) => goToPage(event, q, page)).appendTo(pager);
$('<a>'+text+'</a>').attr('href', getCurrentPath(q, page, obsolete)).click((event) => goToPage(event, q, page)).appendTo(pager);
} else {
$('<span>'+text+'</span>').appendTo(pager);
}
Expand Down Expand Up @@ -275,25 +282,28 @@ var load_search_count = 0, load_search = function() {
});
}

var init = function(value, page, updateHistory) {
var init = function(value, page, obsolete, updateHistory) {
page = parseInt(page, 10);
if(isNaN(page)) page = 1;
document.f.q.value = decodeURIComponent(value);
document.f.page.value = page;
document.f.obsolete.value = obsolete;

search(!!updateHistory);
return value != '';
}

// Get initial search

var page = 1, q = '', params = location.search.substr(1).split('&');
var page = 1, obsolete = 0, q = '', params = location.search.substr(1).split('&');
for(var i = 0; i < params.length; i++) {
var p = params[i].split('=');
if(p.length == 2 && p[0] == 'q') {
q = decodeURIComponent(p[1]);
} else if(p.length == 2 && p[0] == 'page') {
page = decodeURIComponent(p[1]);
} else if(p.length == 2 && p[0] == 'obsolete') {
obsolete = decodeURIComponent(p[1]);
}
}

Expand All @@ -307,7 +317,7 @@ var load_search_count = 0, load_search = function() {
}
}

return init(q, page);
return init(q, page, obsolete);
};

window.addEventListener('load', load_search, false);
10 changes: 10 additions & 0 deletions downloads/archive/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
<li><a href="<?= KeymanHosts::Instance()->downloads_keyman_com ?>/developer/stable/8.0.360.0/keymandeveloper-8.0.360.0.exe">Keyman Developer 8.0.360.0 Download</a> (Online static activation required)</li>
</ul>

<h2 class="red underline">Obsolete Keyboards</h2>

<p>Keyboards that are non-Unicode or older versions may be downloaded from the following link. Generally, unless you know you have a specific
need for an older keyboard, you should download the latest version from the <a href='/keyboards/'>Keyboard Search</a>. Note that the search
for obsolete keyboards will return both current and obsolete keyboards.</p>

<ul>
<li><a href='/keyboards/?obsolete=1'>Obsolete keyboard search</a></li>
</ul>

<h2 class="red underline">Static activation license keys</h2>

<p>Keyman Desktop 9.0 and earlier versions are now available for free. We have made special builds of two older versions of Keyman Desktop available which do not require any activation: 9.0.528.0 and 8.0.361.0. These are feature identical to the Professional Editions.</p>
Expand Down
1 change: 1 addition & 0 deletions keyboards/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<form method='get' action='/keyboards' name='f'>
<input id="search-q" type="text" placeholder="Enter language or keyboard" name="q" autofocus>
<input id="search-f" type="image" src="<?= cdn('img/search-button.png"') ?>" value="Search" onclick="return do_search()">
<input id="search-obsolete" type="hidden" name="obsolete" value="0">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the keyboard search in /_includes/2020/templates/Menu.php also get updated (phone-menu and top-menu1)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is the only interface where obsolete keyboard searches will be possible; if the field is missing, then it's treated as 0

<input id="search-page" type="hidden" name="page" value="1">
</form>
</div>
Expand Down