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

Commit

Permalink
Merge branch 'master' into brian/play-button
Browse files Browse the repository at this point in the history
  • Loading branch information
bsstoner committed Aug 6, 2014
2 parents a9a4503 + e8d50e4 commit 1105890
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 50 deletions.
10 changes: 5 additions & 5 deletions lib/DDG/Spice/Shorten.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ category "computing_tools";
attribution github => ['https://github.com/danjarvis','Dan Jarvis'],
twitter => ['http://twitter.com/danjarvis','danjarvis'];

spice to => 'http://is.gd/create.php?format=json&url=$1&callback={{callback}}';
spice from => '([^/]+)/(.*)';
spice to => 'http://is.gd/create.php?format=json&url=$1%3A%2F%2F$2&callback={{callback}}';
triggers any => 'shorten', 'shorten url', 'short url', 'url shorten';

handle remainder => sub {
my ($longUri) = shift;

return $longUri if $longUri;
return;
m|(https?)?(?:://)?(.+)| =~ shift;
return (defined $1 ? $1 : 'http'), $2 if defined $2;
return;
};

1;
2 changes: 1 addition & 1 deletion share/spice/dictionary/definition/dictionary_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var ddg_spice_dictionary = {
templates: {
group: 'base',
options: {
content: Spice.dictionary_definition.dictionary_definition
content: Spice.dictionary_definition.content
}
}
});
Expand Down
15 changes: 9 additions & 6 deletions share/spice/shorten/shorten.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#shorten-url {
text-align: center;
.zci--shorten input.tag {
-webkit-user-select: text;
-khtml-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
line-height: 1;
font-size: 1.25em;
vertical-align: middle
}

div.clear {
clear: both;
}
6 changes: 1 addition & 5 deletions share/spice/shorten/shorten.handlebars
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{{#if mobile}}
Share: <a id="shorten-url-mobile" href="{{shorturl}}">{{shorturl}}</a>
{{else}}
Share: <input id="shorten-url" readonly="readonly" value="{{shorturl}}">
{{/if}}
Shortened URL: <input id='shorten-url' class='tag' readonly='readonly' value='{{shorturl}}'>
56 changes: 27 additions & 29 deletions share/spice/shorten/shorten.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
function ddg_spice_shorten(api_result) {
(function(env) {
"use strict";
env.ddg_spice_shorten = function (api_result) {
// Exit immediately if we find an error message.
if (!api_result || !api_result.shorturl || api_result.errorcode) {
return Spice.failed('shorten');
}

// Exit immediately if we find an error message.
if (!api_result || !api_result.shorturl || api_result.errorcode) {
return;
}
Spice.add({
id: 'shorten',
data: api_result,
name: 'Shortened Link',
meta: {
sourceUrl : 'http://is.gd/',
sourceName : 'is.gd',
},
templates: {
group: 'text',
options: {
content: Spice.shorten.shorten
}
},
});

// Check if it is a mobile browser (needs work). This was inspired by is.gd.
api_result.mobile = false;
if(window.navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) {
api_result.mobile = true;
// If we displayed an input box, make sure we focus on it.
var url = $('.zci--shorten input.tag');
url.click(function() {
url.focus().select();
}).click();
}

Spice.add({
data : api_result,
header1 : "Shortened Link (is.gd)",
sourceUrl : "http://is.gd/",
sourceName : "is.gd",
templates: {
item: Spice.shorten.shorten,
detail: Spice.shorten.shorten
},

favicon_style : "inline"
});

// If we displayed an input box, make sure we focus on it.
var url = $("input#shorten-url");
url.click(function() {
url.focus().select();
}).click();
}
}(this));
12 changes: 8 additions & 4 deletions t/Shorten.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ use DDG::Test::Spice;
ddg_spice_test(
[qw( DDG::Spice::Shorten )],
'short url http://www.duckduckgo.com/about.html' => test_spice(
'/js/spice/shorten/http%3A%2F%2Fwww.duckduckgo.com%2Fabout.html',
'/js/spice/shorten/http/www.duckduckgo.com%2Fabout.html',
call_type => 'include',
caller => 'DDG::Spice::Shorten'
),
'shorten http://www.duckduckgo.com/about.html' => test_spice(
'/js/spice/shorten/http%3A%2F%2Fwww.duckduckgo.com%2Fabout.html',
'/js/spice/shorten/http/www.duckduckgo.com%2Fabout.html',
call_type => 'include',
caller => 'DDG::Spice::Shorten'
),
'url shorten http://www.duckduckgo.com/about.html' => test_spice(
'/js/spice/shorten/http%3A%2F%2Fwww.duckduckgo.com%2Fabout.html',
'/js/spice/shorten/http/www.duckduckgo.com%2Fabout.html',
call_type => 'include',
caller => 'DDG::Spice::Shorten'
),
'url shorten www.github.com/explore' => test_spice(
'/js/spice/shorten/www.github.com%2Fexplore',
'/js/spice/shorten/http/www.github.com%2Fexplore',
caller => 'DDG::Spice::Shorten',
),
'shorten duckduckgo.com' => test_spice(
'/js/spice/shorten/http/duckduckgo.com',
caller => 'DDG::Spice::Shorten',
),
);
Expand Down

0 comments on commit 1105890

Please sign in to comment.