From b6e2211c2493b426243e38b83e630a95a75e50f2 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 28 Feb 2015 15:29:18 +0100 Subject: automatically register content handler for feeds in firefox --- js/build/app.js | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'js/build/app.js') diff --git a/js/build/app.js b/js/build/app.js index ae9ed83d6..ce18cc904 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -1,4 +1,4 @@ -(function(window, document, angular, $, OC, csrfToken, url, undefined){ +(function(navigator, window, document, angular, $, OC, csrfToken, url, undefined){ 'use strict'; @@ -1968,13 +1968,47 @@ app.service('SettingsResource', ["$http", "BASE_URL", function ($http, BASE_URL) * This prefills the add feed section if an external link has ?subsribe_to * filled out */ -(function (document, url, $, undefined) { +(function (window, document, navigator, url, $, undefined) { 'use strict'; + // register reader as feed reader in firefox + var location = window.location; + var storage = window.localStorage; + + // if isContentHandlerRegistered is not implemented (Firefox I'm looking + // at you) we use localstorage to prevent registering the feed reader twice + var isRegistered = function (mime, url) { + if (navigator.isContentHandlerRegistered) { + return navigator.isContentHandlerRegistered(mime, url) === 'new'; + } else { + return storage.getItem('registeredHandler') !== url; + } + }; + + var registerHandler = function (mime, url, title) { + if (navigator.registerContentHandler && !isRegistered(mime, url)) { + navigator.registerContentHandler(mimeType, subscribeUrl, title); + if (!navigator.isContentHandlerRegistered) { + storage.setItem('registeredHandler', url); + } + } + }; + + var cleanUrl = location.protocol + '//' + location.host + location.pathname; + + var subscribeUrl = cleanUrl + '?subscribe_to=%s'; + var mimeType = 'application/vnd.mozilla.maybe.feed'; + var title = 'ownCloud News @ ' + cleanUrl; + + registerHandler(mimeType, subscribeUrl, title); + + $(document).ready(function () { - var subscription = url('?subscribe_to'); + var subscription = window.decodeURIComponent(url('?subscribe_to')); + + console.log(subscription); - if (subscription) { + if (subscription && subscription !== 'null') { $('#new-feed').show(); var input = $('input[ng-model="Navigation.feed.url"]'); @@ -1988,7 +2022,7 @@ app.service('SettingsResource', ["$http", "BASE_URL", function ($http, BASE_URL) } }); -})(document, url, $); +})(window, document, navigator, url, $); /** @@ -2881,4 +2915,4 @@ app.directive('newsTriggerClick', function () { }); -})(window, document, angular, jQuery, OC, oc_requesttoken, url); \ No newline at end of file +})(navigator, window, document, angular, jQuery, OC, oc_requesttoken, url); \ No newline at end of file -- cgit v1.2.3