X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e6e83eed52400d6e8a6ee6339cbe212c8cac1f90..e16c2ba3a8b07ced3d7a1c53834985775e9c7c51:/modules/documentHistory/documentHistory.js diff --git a/modules/documentHistory/documentHistory.js b/modules/documentHistory/documentHistory.js index 05cddbc..d5f20d4 100644 --- a/modules/documentHistory/documentHistory.js +++ b/modules/documentHistory/documentHistory.js @@ -15,25 +15,29 @@ return function(sandbox) { } var itemViews = []; - var addHistoryItem = function(item) { + var addHistoryItem = function(item, options) { historyItems.add(item); var view = new itemView(item); itemViews.push(view); - domNodes.itemList.append(view.dom); + domNodes.itemList.prepend(view.dom); + if(options.animate) { + view.dom.hide().slideDown(); + } } var toggleItemViews = function(toggle) { itemViews.forEach(function(view) { - view.toggle(toggle); + if(!historyItems.selected(view.item)) + view.toggle(toggle); }); } var historyItems = { _itemsById: {}, _selected: [], - select: function(id) { + select: function(item) { if(this._selected.length < 2) { - this._selected.push(id); + this._selected.push(item.version); if(this._selected.length === 2) toggleItemViews(false); return true; @@ -41,49 +45,49 @@ return function(sandbox) { return false; }, unselect: function(item) { - this._selected = _.without(this._selected, id); + this._selected = _.without(this._selected, item.version); if(this._selected.length < 2) toggleItemViews(true); }, add: function(item) { - this._itemsById[item.id] = item; + this._itemsById[item.version] = item; }, selected: function(item) { - return _.contains(_selected, item.id); + return _.contains(this._selected, item.version); } }; var itemView = function(item) { this.item = item; this.dom = $(this.template(item)); - this.dom.on('click', this.onItemClicked); + this.dom.on('click', _.bind(this.onItemClicked, this)); }; itemView.prototype.template = _.template(itemTemplateSrc); itemView.prototype.onItemClicked = function() { - if(historyItems.selected(item)) { - historyItems.unselect(item); + if(historyItems.selected(this.item)) { + historyItems.unselect(this.item); this.dimItem(); - } else if(historyItems.select(item)) { + } else if(historyItems.select(this.item)) { this.highlightItem(); } }; itemView.prototype.highlightItem = function() { - + this.dom.addClass('highlighted'); }; itemView.prototype.dimItem = function() { - + this.dom.removeClass('highlighted'); }; itemView.prototype.toggle = function(toggle) { - + this.dom.toggleClass('disabled', !toggle); }; return { - start: function() { sandbox.publish('ready'); }, - setHistory: function(history) { + start: function() { sandbox.publish('ready'); }, + addHistory: function(history, options) { history.forEach(function(historyItem) { - addHistoryItem(historyItem); + addHistoryItem(historyItem, options || {}); }); }, getView: function() {