summaryrefslogtreecommitdiff
path: root/js/FeedTree.js
diff options
context:
space:
mode:
authornanaya <[email protected]>2020-07-09 01:48:23 +0900
committernanaya <[email protected]>2020-07-09 01:52:46 +0900
commit8d8affdc453f8cfa5f1b60d2ba90f716202c9b5e (patch)
tree7c6af603d888edd72e34a53f7e6229496995fc5a /js/FeedTree.js
parent68b78ecd3d90fb6cb35d08a96ed74b7a59470c39 (diff)
Store FeedTree data in localStorage
Patching internal functions of dijit.Tree as they don't provide option on where to store the data. It stores to cookies by default but the data can get quite big for hundreds of feeds and exceeds cookies size limit. Not to mention it'll cause the cookie to be sent during any request with nothing handling it server side and just wasting bandwidth. This patch will also migrate current data in cookie to local storage accordingly.
Diffstat (limited to 'js/FeedTree.js')
-rwxr-xr-xjs/FeedTree.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/js/FeedTree.js b/js/FeedTree.js
index 75a3f32a7..74c29d2f7 100755
--- a/js/FeedTree.js
+++ b/js/FeedTree.js
@@ -1,9 +1,42 @@
/* eslint-disable prefer-rest-params */
/* global __, dojo, dijit, define, App, Feeds, CommonDialogs */
-define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], function (declare, domConstruct) {
+define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/cookie", "dijit/Tree", "dijit/Menu"], function (declare, domConstruct, array, cookie) {
return declare("fox.FeedTree", dijit.Tree, {
+ // save state in localStorage instead of cookies
+ // reference: https://stackoverflow.com/a/27968996
+ _saveExpandedNodes: function(){
+ if(this.persist && this.cookieName){
+ var ary = [];
+ for(var id in this._openedNodes){
+ ary.push(id);
+ }
+ // Was:
+ // cookie(this.cookieName, ary.join(","), {expires: 365});
+ localStorage.setItem(this.cookieName, ary.join(","));
+ }
+ },
+ _initState: function(){
+ // summary:
+ // Load in which nodes should be opened automatically
+ this._openedNodes = {};
+ if(this.persist && this.cookieName){
+ // Was:
+ // var oreo = cookie(this.cookieName);
+ var oreo = localStorage.getItem(this.cookieName);
+ // migrate old data if nothing in localStorage
+ if(oreo == null || oreo === '') {
+ oreo = cookie(this.cookieName);
+ cookie(this.cookieName, null, { expires: -1 });
+ }
+ if(oreo){
+ array.forEach(oreo.split(','), function(item){
+ this._openedNodes[item] = true;
+ }, this);
+ }
+ }
+ },
_onContainerKeydown: function(/* Event */ /* e */) {
return; // Stop dijit.Tree from interpreting keystrokes
},