Skip to content

Commit 0552e2b

Browse files
committed
Fixed Chrome bug needing indexOf method instead and sorted toggle auto save out properly.
1 parent 510b19d commit 0552e2b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

coffeescript/tyto.coffee

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ define ['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
1515
tyto = (options) ->
1616
return new tyto() unless this instanceof tyto
1717
config = if options isnt `undefined` then options else config
18-
this.config = config
18+
this.config = if window.localStorage.tyto isnt `undefined` then JSON.parse window.localStorage.tyto else config
1919
this.modals = {}
2020
this.undo = {}
21-
this._autoSave = config.autoSave
21+
this._autoSave = this.config.autoSave
2222
this._bindPageEvents()
2323
if config.showIntroModalOnLoad and config.introModalId
2424
this.modals.introModal = $ '#' + config.introModalId
@@ -110,8 +110,6 @@ define ['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
110110
tyto.saveBarn()
111111
, 5000)
112112
if window.localStorage and window.localStorage.tyto
113-
tyto.config = JSON.parse window.localStorage.tyto
114-
tyto._loadBarnJSON JSON.parse window.localStorage.tyto
115113
setUpLS()
116114
else if window.localStorage
117115
$('#cookie-banner').removeClass('hide').find('[data-action="cookie-close"]').on 'click', (e)->
@@ -308,6 +306,7 @@ define ['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
308306
tyto.notify 'auto-save: ON', 2000
309307
else
310308
tyto.notify 'auto-save: OFF', 2000
309+
window.localStorage.setItem 'tyto', JSON.stringify tyto._createBarnJSON()
311310
tyto::_resizeColumns = ->
312311
tyto = this
313312
if tyto.element.find('.column').length > 0
@@ -334,10 +333,11 @@ define ['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
334333
items = []
335334
columnitems = $(column).find('.tyto-item')
336335
$.each columnitems, (index, item) ->
336+
isCollapsed = if item.querySelector('.action-icons .collapser').className.indexOf('plus') isnt -1 then true else false
337337
items.push
338338
content: item.querySelector('.tyto-item-content').innerHTML.toString().trim()
339339
title: item.querySelector('.tyto-item-title').innerHTML.toString().trim()
340-
collapsed: item.querySelector('.action-icons .collapser').className.contains 'plus'
340+
collapsed: isCollapsed
341341
itemboardJSON.columns.push title: columnTitle, items: items
342342
itemboardJSON
343343
tyto::_loadBarnJSON = (json) ->

js/tyto.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ define(['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
1818
return new tyto();
1919
}
2020
config = options !== undefined ? options : config;
21-
this.config = config;
21+
this.config = window.localStorage.tyto !== undefined ? JSON.parse(window.localStorage.tyto) : config;
2222
this.modals = {};
2323
this.undo = {};
24-
this._autoSave = config.autoSave;
24+
this._autoSave = this.config.autoSave;
2525
this._bindPageEvents();
2626
if (config.showIntroModalOnLoad && config.introModalId) {
2727
this.modals.introModal = $('#' + config.introModalId);
@@ -157,8 +157,6 @@ define(['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
157157
});
158158
};
159159
if (window.localStorage && window.localStorage.tyto) {
160-
tyto.config = JSON.parse(window.localStorage.tyto);
161-
tyto._loadBarnJSON(JSON.parse(window.localStorage.tyto));
162160
setUpLS();
163161
} else if (window.localStorage) {
164162
$('#cookie-banner').removeClass('hide').find('[data-action="cookie-close"]').on('click', function(e) {
@@ -471,10 +469,11 @@ define(['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
471469
$('[data-action="toggleautosave"] i').toggleClass('fa-check-square-o fa-square-o');
472470
tyto._autoSave = !tyto._autoSave;
473471
if (tyto._autoSave) {
474-
return tyto.notify('auto-save: ON', 2000);
472+
tyto.notify('auto-save: ON', 2000);
475473
} else {
476-
return tyto.notify('auto-save: OFF', 2000);
474+
tyto.notify('auto-save: OFF', 2000);
477475
}
476+
return window.localStorage.setItem('tyto', JSON.stringify(tyto._createBarnJSON()));
478477
};
479478
tyto.prototype._resizeColumns = function() {
480479
var correctWidth;
@@ -510,10 +509,12 @@ define(['jquery', 'jqueryUI', 'config', 'handlebars', 'text!templates/tyto/colum
510509
items = [];
511510
columnitems = $(column).find('.tyto-item');
512511
$.each(columnitems, function(index, item) {
512+
var isCollapsed;
513+
isCollapsed = item.querySelector('.action-icons .collapser').className.indexOf('plus') !== -1 ? true : false;
513514
return items.push({
514515
content: item.querySelector('.tyto-item-content').innerHTML.toString().trim(),
515516
title: item.querySelector('.tyto-item-title').innerHTML.toString().trim(),
516-
collapsed: item.querySelector('.action-icons .collapser').className.contains('plus')
517+
collapsed: isCollapsed
517518
});
518519
});
519520
return itemboardJSON.columns.push({

0 commit comments

Comments
 (0)