From 9585a1877b7b10600f2f8ca92139da15e4180697 Mon Sep 17 00:00:00 2001 From: JesseWeinstein Date: Mon, 10 Nov 2014 23:16:31 -0800 Subject: [PATCH 1/3] Split bookmarklet_url literal string into lines To improve the readabilit of diffs that modify it, per https://github.com/diaspora/diaspora/pull/5384#issuecomment-62443426 --- app/helpers/application_helper.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2a8999d3b..a51b99a53 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,7 +22,24 @@ module ApplicationHelper end def bookmarklet_url( height = 400, width = 620) - "javascript:(function(){f='#{AppConfig.pod_uri.to_s}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'¬es='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=1&';a=function(){if(!window.open(f+'noui=1&jump=doclose','diasporav1','location=yes,links=no,scrollbars=yes,toolbar=no,width=#{width},height=#{height}'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()" + "javascript:(function(){" \ + "f='#{AppConfig.pod_uri.to_s}bookmarklet" \ + "?url='+encodeURIComponent(window.location.href)" \ + "+'&title='+encodeURIComponent(document.title)" \ + "+'¬es='+encodeURIComponent(''+" \ + "(window.getSelection?window.getSelection():" \ + "document.getSelection?document.getSelection():" \ + "document.selection.createRange().text))" \ + "+'&v=1&';" \ + "a=function(){" \ + "if(!window.open(f+'noui=1&jump=doclose'," \ + "'diasporav1'," \ + "'location=yes,links=no,scrollbars=yes,toolbar=no,width=#{width},height=#{height}'))" \ + "location.href=f+'jump=yes'};" \ + "if(/Firefox/.test(navigator.userAgent)){" \ + "setTimeout(a,0)" \ + "}else{a()}" \ + "})()" end def contacts_link From ea33ef9e0b37d759523744e72ea7ee3c00c18f04 Mon Sep 17 00:00:00 2001 From: JesseWeinstein Date: Mon, 10 Nov 2014 23:24:23 -0800 Subject: [PATCH 2/3] Add Markdown to generated post Switch to using content parameter, which doesn't alter its value, unlike the other ones. Use a H2 header for the document.title, quote the selected text, and put the URL at the bottom, in a separate paragraph. --- app/helpers/application_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a51b99a53..1197a0e3d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,12 +24,12 @@ module ApplicationHelper def bookmarklet_url( height = 400, width = 620) "javascript:(function(){" \ "f='#{AppConfig.pod_uri.to_s}bookmarklet" \ - "?url='+encodeURIComponent(window.location.href)" \ - "+'&title='+encodeURIComponent(document.title)" \ - "+'¬es='+encodeURIComponent(''+" \ + "?content='+encodeURIComponent('##%20'+document.title+" \ + "'\n>%20'+" "(window.getSelection?window.getSelection():" \ "document.getSelection?document.getSelection():" \ - "document.selection.createRange().text))" \ + "document.selection.createRange().text)" \ + "+'\n\n'+window.location.href)" \ "+'&v=1&';" \ "a=function(){" \ "if(!window.open(f+'noui=1&jump=doclose'," \ From fb51e9aa43246a174661f7b0e1fee4494aedcade Mon Sep 17 00:00:00 2001 From: JesseWeinstein Date: Mon, 10 Nov 2014 23:41:34 -0800 Subject: [PATCH 3/3] Only include the quote markdown if needed Intentionally do a converting-comparison against the empty string, to see if text is selected. --- app/helpers/application_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1197a0e3d..cb7d284c0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -23,12 +23,12 @@ module ApplicationHelper def bookmarklet_url( height = 400, width = 620) "javascript:(function(){" \ + "t=(window.getSelection?window.getSelection():" \ + "document.getSelection?document.getSelection():" \ + "document.selection.createRange().text);" \ "f='#{AppConfig.pod_uri.to_s}bookmarklet" \ "?content='+encodeURIComponent('##%20'+document.title+" \ - "'\n>%20'+" - "(window.getSelection?window.getSelection():" \ - "document.getSelection?document.getSelection():" \ - "document.selection.createRange().text)" \ + "(t!=''?('\n>%20'+t):'')" \ "+'\n\n'+window.location.href)" \ "+'&v=1&';" \ "a=function(){" \