Skip to content

Commit

Permalink
Merge pull request #59 from yadimon/dev
Browse files Browse the repository at this point in the history
Panels.remove method added
  • Loading branch information
bmuenzenmeyer authored Feb 16, 2018
2 parents 9cff0c6 + 9d7bbd6 commit 19dc08d
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions src/js/panels.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,44 @@

var Panels = {

panels: [],
panels: [],

count: function () {
return this.panels.length;
},
count: function() {
return this.panels.length;
},

get: function () {
return JSON.parse(JSON.stringify(this.panels));
},
get: function() {
return JSON.parse(JSON.stringify(this.panels));
},

add: function (panel) {
add: function(panel) {

// if ID already exists in panels array ignore the add()
for (i = 0; i < this.panels.length; ++i) {
if (panel.id === this.panels[i].id) {
return;
}
}
// if ID already exists in panels array ignore the add()
for (var i = 0; i < this.panels.length; ++i) {
if (panel.id === this.panels[i].id) {
return;
}
}

// it wasn't found so push the tab onto the tabs
this.panels.push(panel);
// it wasn't found so push the tab onto the tabs
this.panels.push(panel);

}
},

remove: function(id) {
var panels = this.panels;
for (var i = panels.length - 1; i >= 0; i--) {
if (panels[i].id === id){
var panelToRemove = panels[i];
panels.splice(i, 1);
//if removed panel was default, set first panel as new default, if exists
if (panelToRemove.default && panels.length){
panels[0].default = true;
}
return; //should be no more panels with the same id
}
}
}

};

Expand Down

0 comments on commit 19dc08d

Please sign in to comment.