summaryrefslogtreecommitdiffstats
path: root/js/gui
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-02-28 15:29:18 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-02-28 15:29:18 +0100
commitb6e2211c2493b426243e38b83e630a95a75e50f2 (patch)
tree8d04a5cc92a5a62097c9472493c294e8c935a68d /js/gui
parentcd04e2768b6f3ae5d4b921d713e3414ecd14724f (diff)
automatically register content handler for feeds in firefox
Diffstat (limited to 'js/gui')
-rw-r--r--js/gui/ExternSubscription.js42
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, $);