diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php
index cd373c63..918796a4 100644
--- a/ext/autocomplete/main.php
+++ b/ext/autocomplete/main.php
@@ -13,15 +13,27 @@ class AutoComplete extends Extension {
if(!isset($_GET["s"])) return;
//$limit = 0;
+ $cache_key = "autocomplete-" . strtolower($_GET["s"]);
$limitSQL = "";
$SQLarr = array("search"=>$_GET["s"]."%");
if(isset($_GET["limit"]) && $_GET["limit"] !== 0){
$limitSQL = "LIMIT :limit";
$SQLarr['limit'] = $_GET["limit"];
+ $cache_key .= "-" . $_GET["limit"];
}
- $res = $database->get_col(
- "SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 $limitSQL", $SQLarr);
+ $res = $database->cache->get($cache_key);
+ if(!$res) {
+ $res = $database->get_pairs($database->scoreql_to_sql("
+ SELECT tag, count
+ FROM tags
+ WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:search)
+ AND count > 0
+ ORDER BY count DESC
+ $limitSQL"), $SQLarr
+ );
+ $database->cache->set($cache_key, $res, 600);
+ }
$page->set_mode("data");
$page->set_type("application/json");
diff --git a/ext/autocomplete/script.js b/ext/autocomplete/script.js
new file mode 100644
index 00000000..87ccbf93
--- /dev/null
+++ b/ext/autocomplete/script.js
@@ -0,0 +1,58 @@
+$(function(){
+ $('[name=search]').tagit({
+ singleFieldDelimiter: ' ',
+ beforeTagAdded: function(event, ui) {
+ // give special class to negative tags
+ if(ui.tagLabel[0] === '-') {
+ ui.tag.addClass('tag-negative');
+ }else{
+ ui.tag.addClass('tag-positive');
+ }
+ },
+ autocomplete : ({
+ source: function (request, response) {
+ var isNegative = (request.term[0] === '-');
+ $.ajax({
+ url: base_href + '/api/internal/autocomplete',
+ data: {'s': (isNegative ? request.term.substring(1) : request.term)},
+ dataType : 'json',
+ type : 'GET',
+ success : function (data) {
+ response($.map(data, function (count, item) {
+ item = (isNegative ? '-'+item : item);
+ return {
+ label : item + ' ('+count+')',
+ value : item
+ }
+ }));
+ },
+ error : function (request, status, error) {
+ alert(error);
+ }
+ });
+ },
+ minLength: 1
+ })
+ });
+
+ $('.ui-autocomplete-input').keydown(function(e) {
+ var keyCode = e.keyCode || e.which;
+
+ //Stop tags containing space.
+ if(keyCode == 32) {
+ e.preventDefault();
+
+ $('[name=search]').tagit('createTag', $(this).val());
+ $(this).autocomplete('close');
+ } else if (keyCode == 9) {
+ e.preventDefault();
+
+ var tag = $('.tagit-autocomplete[style*=\"display: block\"] > li:first').text();
+ if(tag){
+ $('[name=search]').tagit('createTag', tag);
+ $('.ui-autocomplete-input').autocomplete('close');
+ $('.ui-autocomplete-input').val(''); //If tag already exists, make sure to remove duplicate.
+ }
+ }
+ });
+});
\ No newline at end of file
diff --git a/ext/autocomplete/style.css b/ext/autocomplete/style.css
index 582af002..019bb7fd 100644
--- a/ext/autocomplete/style.css
+++ b/ext/autocomplete/style.css
@@ -2,7 +2,7 @@
.tagit { background: white !important; border: 1px solid grey !important; cursor: text; }
.tagit-choice { cursor: initial; }
-input[name=search] ~ input[type=submit] { display: block !important; }
+input[name=search] ~ input[type=submit] { display: inline-block !important; }
.tag-negative { background: #ff8080 !important; }
.tag-positive { background: #40bf40 !important; }
\ No newline at end of file
diff --git a/ext/autocomplete/theme.php b/ext/autocomplete/theme.php
index 3b5a4af5..462d2bfd 100644
--- a/ext/autocomplete/theme.php
+++ b/ext/autocomplete/theme.php
@@ -7,68 +7,7 @@ class AutoCompleteTheme extends Themelet {
$page->add_html_header("");
$page->add_html_header("");
- $page->add_html_header('');
+ $page->add_html_header('');
$page->add_html_header("");
-
- $page->add_html_header("");
}
}
diff --git a/ext/home/style.css b/ext/home/style.css
new file mode 100644
index 00000000..dba7e859
--- /dev/null
+++ b/ext/home/style.css
@@ -0,0 +1,13 @@
+div#front-page h1 {font-size: 4em; margin-top: 2em; margin-bottom: 0px; text-align: center; border: none; background: none; box-shadow: none; -webkit-box-shadow: none; -moz-box-shadow: none;}
+div#front-page {text-align:center;}
+.space {margin-bottom: 1em;}
+div#front-page div#links a {margin: 0 0.5em;}
+div#front-page li {list-style-type: none; margin: 0;}
+@media (max-width: 800px) {
+ div#front-page h1 {font-size: 3em; margin-top: 0.5em; margin-bottom: 0.5em;}
+ #counter {display: none;}
+}
+
+div#front-page > #search > form { margin: 0 auto; }
+div#front-page > #search > form > ul { width: 225px; vertical-align: middle; display: inline-block; }
+div#front-page > #search > form > input[type=submit]{ padding: 4px 6px; }
diff --git a/ext/home/theme.php b/ext/home/theme.php
index 6c51c73d..a833e962 100644
--- a/ext/home/theme.php
+++ b/ext/home/theme.php
@@ -5,6 +5,7 @@ class HomeTheme extends Themelet {
$page->set_mode("data");
$hh = "";
$page->add_auto_html_headers();
+ ksort($page->html_headers);
foreach($page->html_headers as $h) {$hh .= $h;}
$page->set_data(<<
@@ -14,17 +15,6 @@ class HomeTheme extends Themelet {
$hh
-
$body