summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/protected_tags
diff options
context:
space:
mode:
authorKushal Pandya <kushal@gitlab.com>2017-04-06 14:47:50 +0530
committerKushal Pandya <kushal@gitlab.com>2017-04-06 14:47:50 +0530
commitcd5b36d04e79ed8fcd649127e0d47e09ec325242 (patch)
tree9569170b1318739dfa19c07e54065b9a4e810ed8 /app/assets/javascripts/protected_tags
parent3c414a9fa92e48ca021c1671fca9ad096a34d1c4 (diff)
downloadgitlab-ce-cd5b36d04e79ed8fcd649127e0d47e09ec325242.tar.gz
Add constructor doc, toggle helper
Diffstat (limited to 'app/assets/javascripts/protected_tags')
-rw-r--r--app/assets/javascripts/protected_tags/protected_tag_dropdown.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/app/assets/javascripts/protected_tags/protected_tag_dropdown.js b/app/assets/javascripts/protected_tags/protected_tag_dropdown.js
index 9be9e2bea6f..9c78f2816a4 100644
--- a/app/assets/javascripts/protected_tags/protected_tag_dropdown.js
+++ b/app/assets/javascripts/protected_tags/protected_tag_dropdown.js
@@ -1,4 +1,10 @@
export default class ProtectedTagDropdown {
+ /**
+ * @param {Object} options containing
+ * `$dropdown` target element
+ * `onSelect` event callback
+ * $dropdown must be an element created using `dropdown_tag()` rails helper
+ */
constructor(options) {
this.onSelect = options.onSelect;
this.$dropdown = options.$dropdown;
@@ -10,7 +16,7 @@ export default class ProtectedTagDropdown {
this.bindEvents();
// Hide footer
- this.$dropdownFooter.addClass('hidden');
+ this.toggleFooter(true);
}
buildDropdown() {
@@ -58,18 +64,22 @@ export default class ProtectedTagDropdown {
}
toggleCreateNewButton(tagName) {
- this.selectedTag = {
- title: tagName,
- id: tagName,
- text: tagName,
- };
-
if (tagName) {
+ this.selectedTag = {
+ title: tagName,
+ id: tagName,
+ text: tagName,
+ };
+
this.$dropdownContainer
.find('.create-new-protected-tag code')
.text(tagName);
}
- this.$dropdownFooter.toggleClass('hidden', !tagName);
+ this.toggleFooter(!tagName);
+ }
+
+ toggleFooter(toggleState) {
+ this.$dropdownFooter.toggleClass('hidden', toggleState);
}
}