diff options
Diffstat (limited to 'js/gui')
-rw-r--r-- | js/gui/ExternSubscription.js | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/js/gui/ExternSubscription.js b/js/gui/ExternSubscription.js index c54316c4a..5cbff409f 100644 --- a/js/gui/ExternSubscription.js +++ b/js/gui/ExternSubscription.js @@ -12,13 +12,47 @@ * 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"]'); @@ -32,5 +66,5 @@ } }); -})(document, url, $); +})(window, document, navigator, url, $); |