Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Alternative to #8

Merged
merged 4 commits into from Mar 13, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions alternative_to/spice.html
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Alternative.to test</title>
<script src="spice.js"></script>
<script type="text/javascript">
function nra(items) {
document.getElementById('a').innerHTML = items[0]['a'];
}
</script>
</head>
<body>
<div id="a"></div>
<script src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-min.js"></script>
<script src="http://yui.yahooapis.com/2.9.0/build/dom/dom-min.js"></script>
<script src="http://thor.duckduckgo.com/iat/software/firefox/?platform=linux&license=free"></script>
</body>
</html>
49 changes: 49 additions & 0 deletions alternative_to/spice.js
@@ -0,0 +1,49 @@
d = document;
function nrat(alts)
{
// console.log(alts);
var out, tmp;
out = "";

// validity check
if (alts['Items']) {

for (i in alts['Items']) {
var item = alts['Items'][i];

wrapper = d.createElement("div");
box = d.createElement("div");

link = d.createElement("a");
link.href = item['Url'];
link.innerHTML = item['Name'];

img = d.createElement("img");
img.src = item['IconUrl'];

box.appendChild(img);
box.appendChild(d.createElement("br"));
box.appendChild(link);

YAHOO.util.Dom.setStyle(box, "text-align", "center");

YAHOO.util.Dom.setStyle(box, "float", "left");
YAHOO.util.Dom.setStyle(box, "margin", "10px");
YAHOO.util.Dom.setStyle(box, "width", "60px");

wrapper.appendChild(box);

out += wrapper.innerHTML;

}

items = new Array();
items[0] = new Array();
items[0]['a'] = out;
items[0]['h'] = '';
items[0]['s'] = 'AlternativeTo';
items[0]['u'] = alts['Url'];
nra(items);
}
}

1 change: 1 addition & 0 deletions alternative_to/spice.namespace
@@ -0,0 +1 @@
at
26 changes: 26 additions & 0 deletions alternative_to/spice.pl
@@ -0,0 +1,26 @@
if ($q_check_lc =~ /^(?:(free|opensource|commercial))?\s*(?:alternatives?\s*to\s*)?([\w\-]+)(?:\sfor\s(.*))?$/i) {
#$call_extf = qq(/js/nrat.js);
if ($1 and $4) {
# license and platform specified - queries like:
# -> free alternative to firefox for mac
# -> opensource matlab for linux
$call_ext = qq(/iat/software/$3/?platform=$4&license=$1);
} elsif ($1) {
# lincense secified only:
# -> free nod32
# -> opensource alternative to omnigraffle
$call_ext = qq(/iat/software/$3/?license=$1);
} elsif ($4) {
# platform specified:
# -> TextMate for windows
# -> alternative to vim for linux
$call_ext = qq(/iat/software/$3/?platform=$4);
} elsif($2) {
# license and platform not specified
# in this case we need to match 'alternative(s) to':
# -> alternative to firefox
$call_ext = qq(/iat/software/$3);
}
$is_kill_pre_results = 1;
}