From 8709c45d30dc6ada3f065a8892f0aaf173cd997d Mon Sep 17 00:00:00 2001 From: Dennis Schubert <mail@dennis-schubert.de> Date: Thu, 12 Jul 2018 23:50:32 +0200 Subject: [PATCH] Move the protocol handler into a proper helper module Previous file history in 80dfdcd6afb600b400c7bccd427918658feebdf3, couldn't keep it. --- .../javascripts/helpers/protocol_handler.js | 22 +++++++++++++++++++ app/assets/javascripts/main.js | 2 +- app/assets/javascripts/protocol-handler.js | 17 -------------- 3 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 app/assets/javascripts/helpers/protocol_handler.js delete mode 100644 app/assets/javascripts/protocol-handler.js diff --git a/app/assets/javascripts/helpers/protocol_handler.js b/app/assets/javascripts/helpers/protocol_handler.js new file mode 100644 index 0000000000..6d9368979f --- /dev/null +++ b/app/assets/javascripts/helpers/protocol_handler.js @@ -0,0 +1,22 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +Diaspora.ProtocolHandler = { + register: function() { + if (typeof (window.navigator.registerProtocolHandler) !== "function") { + return false; + } + + var protocol = location.protocol; + var slashes = protocol.concat("//"); + var host = slashes.concat(window.location.hostname); + + if (location.port) { + host = host.concat(":" + location.port); + } + + window.navigator.registerProtocolHandler("web+diaspora", host.concat("/link?q=%s"), document.title); + return true; + } +}; + +Diaspora.ProtocolHandler.register(); diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 563bbc3151..e359ad7c2d 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -45,5 +45,5 @@ //= require api/authorization_page //= require bootstrap-markdown/bootstrap-markdown //= require helpers/markdown_editor +//= require helpers/protocol_handler //= require jquery.are-you-sure -//= require protocol-handler diff --git a/app/assets/javascripts/protocol-handler.js b/app/assets/javascripts/protocol-handler.js deleted file mode 100644 index 6afedf4094..0000000000 --- a/app/assets/javascripts/protocol-handler.js +++ /dev/null @@ -1,17 +0,0 @@ -// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later - -function registerDiasporaLinksProtocol() { - var protocol = location.protocol; - var slashes = protocol.concat("//"); - var host = slashes.concat(window.location.hostname); - - if (location.port) { - host = host.concat(":" + location.port); - } - - window.navigator.registerProtocolHandler("web+diaspora", host.concat("/link?q=%s"), document.title); -} - -if (typeof (window.navigator.registerProtocolHandler) === "function") { - registerDiasporaLinksProtocol(); -} -- GitLab