From 7c8824ded0b946388aab32974e3c3bf9e0242161 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Fri, 18 Jul 2014 14:42:51 -0700 Subject: [PATCH 01/11] fix shorten IA for new IA API --- share/spice/shorten/shorten.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/share/spice/shorten/shorten.js b/share/spice/shorten/shorten.js index 48101379b9..e329712cff 100644 --- a/share/spice/shorten/shorten.js +++ b/share/spice/shorten/shorten.js @@ -13,16 +13,20 @@ function ddg_spice_shorten(api_result) { } Spice.add({ - data : api_result, - header1 : "Shortened Link (is.gd)", - sourceUrl : "http://is.gd/", - sourceName : "is.gd", + id: 'shorten', + data: api_result, + header1: "Shortened Link (is.gd)", + meta: { + sourceUrl : "http://is.gd/", + sourceName : "is.gd", + }, templates: { - item: Spice.shorten.shorten, - detail: Spice.shorten.shorten + group: 'base', + options: { + content: Spice.shorten.shorten + } }, - - favicon_style : "inline" + favicon_style : "inline" }); // If we displayed an input box, make sure we focus on it. From c5251030bbaa39962f7b739be0250e57bfd67d48 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Fri, 18 Jul 2014 21:04:07 -0700 Subject: [PATCH 02/11] use closure & callback for shorten.js & fixes --- share/spice/shorten/shorten.js | 66 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/share/spice/shorten/shorten.js b/share/spice/shorten/shorten.js index e329712cff..069fe15285 100644 --- a/share/spice/shorten/shorten.js +++ b/share/spice/shorten/shorten.js @@ -1,37 +1,37 @@ -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; + } - // Exit immediately if we find an error message. - if (!api_result || !api_result.shorturl || api_result.errorcode) { - return; - } - - // 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; - } + // 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; + } - Spice.add({ - id: 'shorten', - data: api_result, - header1: "Shortened Link (is.gd)", - meta: { - sourceUrl : "http://is.gd/", - sourceName : "is.gd", - }, - templates: { - group: 'base', - options: { - content: Spice.shorten.shorten - } - }, - favicon_style : "inline" - }); + Spice.add({ + id: 'shorten', + data: api_result, + name: 'Shortened Link (is.gd)', + meta: { + sourceUrl : 'http://is.gd/', + sourceName : 'is.gd', + }, + templates: { + group: 'text', + options: { + content: Spice.shorten.shorten + } + }, + }); - // If we displayed an input box, make sure we focus on it. - var url = $("input#shorten-url"); - url.click(function() { - url.focus().select(); - }).click(); -} + // 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)) From e4efe7d25b5a70ed43b2cdc9aca4b26ead4939cc Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Sat, 19 Jul 2014 12:10:35 -0700 Subject: [PATCH 03/11] use new css for shorten IA --- share/spice/shorten/shorten.css | 15 +++++++++------ share/spice/shorten/shorten.handlebars | 6 +++--- share/spice/shorten/shorten.js | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/share/spice/shorten/shorten.css b/share/spice/shorten/shorten.css index 370d05dd82..171ca19a2a 100644 --- a/share/spice/shorten/shorten.css +++ b/share/spice/shorten/shorten.css @@ -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.5; + font-size: 1.25em; + vertical-align: baseline; } - -div.clear { - clear: both; -} \ No newline at end of file diff --git a/share/spice/shorten/shorten.handlebars b/share/spice/shorten/shorten.handlebars index 9c363cb389..4fb68b776d 100644 --- a/share/spice/shorten/shorten.handlebars +++ b/share/spice/shorten/shorten.handlebars @@ -1,5 +1,5 @@ {{#if mobile}} - Share: {{shorturl}} + Shortened URL: {{shorturl}} {{else}} - Share: -{{/if}} \ No newline at end of file + Shortened URL: +{{/if}} diff --git a/share/spice/shorten/shorten.js b/share/spice/shorten/shorten.js index 069fe15285..fff34f314a 100644 --- a/share/spice/shorten/shorten.js +++ b/share/spice/shorten/shorten.js @@ -3,7 +3,7 @@ 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; + return Spice.failed('shorten'); } // Check if it is a mobile browser (needs work). This was inspired by is.gd. @@ -29,7 +29,7 @@ }); // If we displayed an input box, make sure we focus on it. - var url = $('input#shorten-url'); + var url = $('.zci--shorten input.tag'); url.click(function() { url.focus().select(); }).click(); From 81d178286b900d1230310a38329e94e2a0381918 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Mon, 21 Jul 2014 14:05:02 -0700 Subject: [PATCH 04/11] remove shorten mobile special case --- share/spice/shorten/shorten.handlebars | 6 +----- share/spice/shorten/shorten.js | 8 +------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/share/spice/shorten/shorten.handlebars b/share/spice/shorten/shorten.handlebars index 4fb68b776d..89c2e5838f 100644 --- a/share/spice/shorten/shorten.handlebars +++ b/share/spice/shorten/shorten.handlebars @@ -1,5 +1 @@ -{{#if mobile}} - Shortened URL: {{shorturl}} -{{else}} - Shortened URL: -{{/if}} +Shortened URL: diff --git a/share/spice/shorten/shorten.js b/share/spice/shorten/shorten.js index fff34f314a..35ff6f608b 100644 --- a/share/spice/shorten/shorten.js +++ b/share/spice/shorten/shorten.js @@ -6,12 +6,6 @@ return Spice.failed('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; - } - Spice.add({ id: 'shorten', data: api_result, @@ -34,4 +28,4 @@ url.focus().select(); }).click(); } -}(this)) +}(this)); From 3673e8318ae752a5cc49030222b11b5cefa39e96 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Wed, 23 Jul 2014 13:39:41 -0700 Subject: [PATCH 05/11] remove is.gd tag from shorten name --- share/spice/shorten/shorten.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/spice/shorten/shorten.js b/share/spice/shorten/shorten.js index 35ff6f608b..0289752002 100644 --- a/share/spice/shorten/shorten.js +++ b/share/spice/shorten/shorten.js @@ -9,7 +9,7 @@ Spice.add({ id: 'shorten', data: api_result, - name: 'Shortened Link (is.gd)', + name: 'Shortened Link', meta: { sourceUrl : 'http://is.gd/', sourceName : 'is.gd', From db713e50979539881ef509c814d14b1e9b40d42c Mon Sep 17 00:00:00 2001 From: Usman Raza Date: Wed, 30 Jul 2014 00:51:46 +0500 Subject: [PATCH 06/11] renamed handlebars to content --- .../{dictionary_definition.handlebars => content.handlebars} | 0 share/spice/dictionary/definition/dictionary_definition.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename share/spice/dictionary/definition/{dictionary_definition.handlebars => content.handlebars} (100%) diff --git a/share/spice/dictionary/definition/dictionary_definition.handlebars b/share/spice/dictionary/definition/content.handlebars similarity index 100% rename from share/spice/dictionary/definition/dictionary_definition.handlebars rename to share/spice/dictionary/definition/content.handlebars diff --git a/share/spice/dictionary/definition/dictionary_definition.js b/share/spice/dictionary/definition/dictionary_definition.js index b32355799b..ca55a25876 100644 --- a/share/spice/dictionary/definition/dictionary_definition.js +++ b/share/spice/dictionary/definition/dictionary_definition.js @@ -70,7 +70,7 @@ var ddg_spice_dictionary = { templates: { group: 'base', options: { - content: Spice.dictionary_definition.dictionary_definition + content: Spice.dictionary_definition.content } } }); From eb8f8f894b714997536984cf1c042a1c4d961035 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Wed, 30 Jul 2014 12:46:12 -0700 Subject: [PATCH 07/11] use spice to/from trickery to workaround nginx https://github.com/duckduckgo/zeroclickinfo-spice/pull/974#issuecomment-49613154 --- lib/DDG/Spice/Shorten.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/DDG/Spice/Shorten.pm b/lib/DDG/Spice/Shorten.pm index 490e3730a5..742033c7e2 100644 --- a/lib/DDG/Spice/Shorten.pm +++ b/lib/DDG/Spice/Shorten.pm @@ -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://$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; From ff6b0eb9942f4015d5fa39d88bcc86ca384e2cfa Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Fri, 1 Aug 2014 10:44:06 -0700 Subject: [PATCH 08/11] urlencode shorten spice to --- lib/DDG/Spice/Shorten.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DDG/Spice/Shorten.pm b/lib/DDG/Spice/Shorten.pm index 742033c7e2..6a93aa7961 100644 --- a/lib/DDG/Spice/Shorten.pm +++ b/lib/DDG/Spice/Shorten.pm @@ -16,7 +16,7 @@ attribution github => ['https://github.com/danjarvis','Dan Jarvis'], twitter => ['http://twitter.com/danjarvis','danjarvis']; spice from => '([^/]+)/(.*)'; -spice to => 'http://is.gd/create.php?format=json&url=$1://$2&callback={{callback}}'; +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 { From ed65b929bd536bfd327ca81b2b51b36b8ef9b0ba Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Fri, 1 Aug 2014 10:50:00 -0700 Subject: [PATCH 09/11] fix shorten tests and guard regex --- lib/DDG/Spice/Shorten.pm | 2 +- t/Shorten.t | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/DDG/Spice/Shorten.pm b/lib/DDG/Spice/Shorten.pm index 6a93aa7961..89927b9e71 100644 --- a/lib/DDG/Spice/Shorten.pm +++ b/lib/DDG/Spice/Shorten.pm @@ -20,7 +20,7 @@ spice to => 'http://is.gd/create.php?format=json&url=$1%3A%2F%2F$2&callback={{ca triggers any => 'shorten', 'shorten url', 'short url', 'url shorten'; handle remainder => sub { - m|(https?)(?:://)?(.+)| =~ shift; + m|(https?)?(?:://)?(.+)| =~ shift; return (defined $1 ? $1 : 'http'), $2 if defined $2; return; }; diff --git a/t/Shorten.t b/t/Shorten.t index 2878b046f3..f056e2e8f2 100644 --- a/t/Shorten.t +++ b/t/Shorten.t @@ -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', ), ); From 10b12f29b830ef409d252eb77ec0a5bfff283f28 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Fri, 1 Aug 2014 11:04:50 -0700 Subject: [PATCH 10/11] i.e. makes me sad --- share/spice/shorten/shorten.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/spice/shorten/shorten.css b/share/spice/shorten/shorten.css index 171ca19a2a..5212cd9a42 100644 --- a/share/spice/shorten/shorten.css +++ b/share/spice/shorten/shorten.css @@ -6,5 +6,5 @@ user-select: text; line-height: 1.5; font-size: 1.25em; - vertical-align: baseline; + vertical-align: middle } From 4f07b8173f9e481aa28bf08e8fdf722bb948cb15 Mon Sep 17 00:00:00 2001 From: moollaza Date: Tue, 5 Aug 2014 21:41:40 +0000 Subject: [PATCH 11/11] shorten line-height to prevent IE vertical scroll/drag --- share/spice/shorten/shorten.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/spice/shorten/shorten.css b/share/spice/shorten/shorten.css index 5212cd9a42..aa6dbb8d23 100644 --- a/share/spice/shorten/shorten.css +++ b/share/spice/shorten/shorten.css @@ -4,7 +4,7 @@ -moz-user-select: text; -ms-user-select: text; user-select: text; - line-height: 1.5; + line-height: 1; font-size: 1.25em; vertical-align: middle }