From fccabf9983c0792d55cf7c86862b7a3770f8d1e0 Mon Sep 17 00:00:00 2001
From: Benjamin Neff <benjamin@coding4coffee.ch>
Date: Mon, 19 Sep 2016 02:19:38 +0200
Subject: [PATCH] Extract mobile bookmarklet JS to file

---
 app/assets/javascripts/mobile/bookmarklet.js  | 21 +++++++++++++++++++
 .../status_messages/bookmarklet.mobile.haml   | 16 +-------------
 config/application.rb                         |  1 +
 3 files changed, 23 insertions(+), 15 deletions(-)
 create mode 100644 app/assets/javascripts/mobile/bookmarklet.js

diff --git a/app/assets/javascripts/mobile/bookmarklet.js b/app/assets/javascripts/mobile/bookmarklet.js
new file mode 100644
index 0000000000..94822c2efa
--- /dev/null
+++ b/app/assets/javascripts/mobile/bookmarklet.js
@@ -0,0 +1,21 @@
+// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
+
+$(document).ready(function() {
+  function publisherContent(params) {
+    if (params.content) {
+      return params.content;
+    }
+
+    var content = params.title + " - " + params.url;
+    if (params.notes.length > 0) {
+      content += " - " + params.notes;
+    }
+    return content;
+  }
+
+  var content = publisherContent(gon.preloads.bookmarklet);
+  if (content.length > 0) {
+    $("#status_message_text").val(content);
+  }
+});
+// @license-end
diff --git a/app/views/status_messages/bookmarklet.mobile.haml b/app/views/status_messages/bookmarklet.mobile.haml
index e6c6227c2c..0dafbc9911 100644
--- a/app/views/status_messages/bookmarklet.mobile.haml
+++ b/app/views/status_messages/bookmarklet.mobile.haml
@@ -4,18 +4,4 @@
 
 = render :partial => 'publisher/publisher', :locals => { :aspect => :profile, :selected_aspects => @aspects,  :aspect_ids => @aspect_ids }
 
-:javascript
-  var contents = "#{escape_javascript params[:content]}";
-  if(!contents){
-    contents  = "#{escape_javascript params[:title]} - #{escape_javascript params[:url]}";
-    var notes = "#{escape_javascript params[:notes]}";
-    if (notes.length > 0){
-      contents += " - " + notes;
-    }
-  }
-
-  $(document).ready(function() {
-    if (contents.length > 0) {
-      $("#status_message_text").val(contents);
-    }
-  });
+= javascript_include_tag "mobile/bookmarklet"
diff --git a/config/application.rb b/config/application.rb
index ca30da2753..1e5e33cbfe 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -75,6 +75,7 @@ module Diaspora
       jquery-textchange.js
       main.js
       jsxc.js
+      mobile/bookmarklet.js
       mobile/mobile.js
       people.js
       publisher.js
-- 
GitLab