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

Replaced search form with Quicksearch (https://github.com/riklomas/qu… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
152 changes: 152 additions & 0 deletions js/quicksearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
//As seen in https://github.com/riklomas/quicksearch

(function($, window, document, undefined) {
$.fn.quicksearch = function (target, opt) {

var timeout, cache, rowcache, jq_results, val = '', e = this, options = $.extend({
delay: 100,
selector: null,
stripeRows: null,
loader: null,
noResults: '',
bind: 'keyup',
onBefore: function () {
return;
},
onAfter: function () {
return;
},
show: function () {
this.style.display = "";
},
hide: function () {
this.style.display = "none";
},
prepareQuery: function (val) {
return val.toLowerCase().split(' ');
},
testQuery: function (query, txt, _row) {
for (var i = 0; i < query.length; i += 1) {
if (txt.indexOf(query[i]) === -1) {
return false;
}
}
return true;
}
}, opt);

this.go = function () {

var i = 0,
noresults = true,
query = options.prepareQuery(val),
val_empty = (val.replace(' ', '').length === 0);

for (var i = 0, len = rowcache.length; i < len; i++) {
if (val_empty || options.testQuery(query, cache[i], rowcache[i])) {
options.show.apply(rowcache[i]);
noresults = false;
} else {
options.hide.apply(rowcache[i]);
}
}

if (noresults) {
this.results(false);
} else {
this.results(true);
this.stripe();
}

this.loader(false);
options.onAfter();

return this;
};

this.stripe = function () {

if (typeof options.stripeRows === "object" && options.stripeRows !== null)
{
var joined = options.stripeRows.join(' ');
var stripeRows_length = options.stripeRows.length;

jq_results.not(':hidden').each(function (i) {
$(this).removeClass(joined).addClass(options.stripeRows[i % stripeRows_length]);
});
}

return this;
};

this.strip_html = function (input) {
var output = input.replace(new RegExp('<[^<]+\>', 'g'), "");
output = $.trim(output.toLowerCase());
return output;
};

this.results = function (bool) {
if (typeof options.noResults === "string" && options.noResults !== "") {
if (bool) {
$(options.noResults).hide();
} else {
$(options.noResults).show();
}
}
return this;
};

this.loader = function (bool) {
if (typeof options.loader === "string" && options.loader !== "") {
(bool) ? $(options.loader).show() : $(options.loader).hide();
}
return this;
};

this.cache = function () {

jq_results = $(target);

if (typeof options.noResults === "string" && options.noResults !== "") {
jq_results = jq_results.not(options.noResults);
}

var t = (typeof options.selector === "string") ? jq_results.find(options.selector) : $(target).not(options.noResults);
cache = t.map(function () {
return e.strip_html(this.innerHTML);
});

rowcache = jq_results.map(function () {
return this;
});

return this.go();
};

this.trigger = function () {
this.loader(true);
options.onBefore();

window.clearTimeout(timeout);
timeout = window.setTimeout(function () {
e.go();
}, options.delay);

return this;
};

this.cache();
this.results(true);
this.stripe();
this.loader(false);

return this.each(function () {
$(this).bind(options.bind, function () {
val = $(this).val();
e.trigger();
});
});

};

}(jQuery, this, document));
29 changes: 22 additions & 7 deletions startpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
<script src="js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
<script src="js/ui.js" type="text/javascript"></script>
<!-- Original Design: [email protected] | Recode/enhancement: [email protected] -->
<script type="text/javascript" src="js/quicksearch.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a').each(function(){
$(this).attr('target','_blank');
});
$('input.filter').quicksearch('.main li');
$('input.filter').quicksearch('.unix li');
$('input.filter').quicksearch('.utils li');
$('input.filter').quicksearch('.forums li');
$('input.filter').quicksearch('.gfx li');
$('input.filter').quicksearch('.bits li');
$('input.filter').focus();
});
</script>
</head>
<body>
<div id="container">
Expand Down Expand Up @@ -57,13 +72,13 @@
<li><a href="https://thepiratebay.sx">piratebay</a><li>
</ul>
</div>
<div class="PS1"><p class="at">@</p><p class="amper">~</p>
<form id="search" action="https://startpage.com/do/search">
<input type="hidden" name="hl" value="cz" />
<input maxlength="250" size="40" tabindex="1" name="q" value="" />
<input type="submit" value="go" name="btnG" />
</form>
</div>
<div class="PS1"><p class="at">@</p><p class="amper">~</p>
<div class="filter_box">
<form>
grep " <input type="text" class="filter" /> "
</form>
</div>
</div>
</div>
</body>
</html>