From 6f0f9d372cf76a1da72701fd3a0cc8becfd0b1f9 Mon Sep 17 00:00:00 2001 From: Kunj Date: Thu, 18 Apr 2019 16:47:20 +0530 Subject: [PATCH 1/2] Create itemsModel.js --- assets/itemsModel.js | 126 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 assets/itemsModel.js diff --git a/assets/itemsModel.js b/assets/itemsModel.js new file mode 100644 index 0000000..fb0c64b --- /dev/null +++ b/assets/itemsModel.js @@ -0,0 +1,126 @@ +define([ + 'core/js/adapt', + 'core/js/models/componentModel' +], function(Adapt, ComponentModel) { + + var ItemsModel = ComponentModel.extend({ + + reset: function(type, force) { + this.resetItems(); + ComponentModel.prototype.reset.call(this, type, force); + }, + + resetItems: function() { + _.each(this.get('_items'), function(item) { + item._isVisited = false; + item._isActive = false; + }); + }, + + getItemCount: function() { + return this.get('_items').length; + }, + + getItem: function(index) { + return this.get('_items')[index]; + }, + + getVisitedItems: function() { + return _.filter(this.get('_items'), function(item) { + return item._isVisited; + }); + }, + + setItemVisited: function(index) { + var item = this.get('_items')[index]; + if (item) { + item._isVisited = true; + } + }, + + areAllIItemsCompleted: function() { + return (this.getVisitedItems().length === this.getItemCount()); + }, + + checkCompletionStatus: function() { + if (this.areAllIItemsCompleted()) { + this.setCompletionStatus(); + } + }, + + resetActiveItems: function(trigger) { + var items = this.get('_items'); + + _.each(items, function(item) { + item._isActive = false; + }); + + if (trigger !== false) { + this.trigger('change:_items:_isActive', this, items); + } + }, + + getActiveItems: function() { + return _.filter(this.get('_items'), function(item) { + return item._isActive; + }); + }, + + getFirstActiveItem: function() { + return this.getActiveItems()[0]; + }, + + getActiveItemsCount: function() { + return this.getActiveItems().length; + }, + + getActiveItemsIndexes: function() { + var indexes = []; + var items = this.get('_items'); + + for (var i = 0, l = items.length; i < l; i++) { + if (items[i]._isActive) { + indexes.push(i); + } + } + + return indexes; + }, + + getFirstActiveItemIndex: function() { + return this.getActiveItemsIndexes()[0]; + }, + + setItemActive: function(index, trigger) { + var items = this.get('_items'); + var item = items[index]; + + if (item === undefined) return false; + + item._isActive = true; + if (trigger !== false) { + this.trigger('change:_items:_isActive', this, items); + } + + return item; + }, + + setItemInactive: function(index, trigger) { + var items = this.get('_items'); + var item = items[index]; + + if (item === undefined) return false; + + item._isActive = false; + if (trigger !== false) { + this.trigger('change:_items:_isActive', this, items); + } + + return item; + } + + }); + + return ItemsModel; + +}); From 40e2c417d17f81fa07a75da4afe1b72506cbb17b Mon Sep 17 00:00:00 2001 From: Kunj Date: Fri, 19 Apr 2019 14:51:03 +0530 Subject: [PATCH 2/2] Update flippableCardView.js --- js/flippableCardView.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/js/flippableCardView.js b/js/flippableCardView.js index 860f49a..fb03059 100644 --- a/js/flippableCardView.js +++ b/js/flippableCardView.js @@ -62,15 +62,13 @@ define([ }, ctrlFocus: function(index) { - var item = this.model.getItem(index); + var item = this.model.getItem(index), + card = this.$cards.eq(index); if (item._isActive) { - this.$cards.eq(index).find('.title-inner').a11y_cntrl(!item._isOverlapping); - this.$cards.eq(index).find('.body-inner').a11y_cntrl(!item._isOverlapping); - this.$cards.eq(index).find('.show-more-btn').a11y_cntrl(item._isOverlapping); + card.find('.title-inner, .body-inner').a11y_cntrl(!item._isOverlapping); + card.find('.show-more-btn').a11y_cntrl(item._isOverlapping); } else { - this.$cards.eq(index).find('.title-inner').a11y_cntrl(false); - this.$cards.eq(index).find('.body-inner').a11y_cntrl(false); - this.$cards.eq(index).find('.show-more-btn').a11y_cntrl(false); + card.find('.title-inner, .body-inner, .show-more-btn').a11y_cntrl(false); } },