/
tag-drop.js.es6
139 lines (115 loc) · 3.21 KB
/
tag-drop.js.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { setting } from 'discourse/lib/computed';
import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNameBindings: [':tag-drop', 'tag::no-category', 'tags:has-drop','categoryStyle','tagClass'],
categoryStyle: setting('category_style'), // match the category-drop style
currentCategory: Em.computed.or('secondCategory', 'firstCategory'),
showFilterByTag: setting('show_filter_by_tag'),
showTagDropdown: Em.computed.and('showFilterByTag', 'tags'),
tagId: null,
tagName: 'li',
@computed('site.top_tags')
tags(topTags) {
if (this.siteSettings.tags_sort_alphabetically && topTags) {
return topTags.sort();
} else {
return topTags;
}
},
@computed('expanded')
expandedIcon(expanded) {
return expanded ? 'caret-down' : 'caret-right';
},
@computed('tagId')
tagClass() {
if (this.get('tagId')) {
return "tag-" + this.get('tagId');
} else {
return "tag_all";
}
},
@computed('firstCategory', 'secondCategory')
allTagsUrl() {
if (this.get('currentCategory')) {
return this.get('currentCategory.url') + "?allTags=1";
} else {
return "/";
}
},
@computed('tag')
allTagsLabel() {
return I18n.t("tagging.selector_all_tags");
},
@computed('tagId')
noTagsSelected() {
return this.get('tagId') === 'none';
},
@computed('firstCategory', 'secondCategory')
noTagsUrl() {
var url = '/tags';
if (this.get('currentCategory')) {
url += this.get('currentCategory.url');
}
return url + '/none';
},
@computed('tag')
noTagsLabel() {
return I18n.t("tagging.selector_no_tags");
},
@computed('tag')
dropdownButtonClass() {
let result = 'badge-category category-dropdown-button';
if (Em.isNone(this.get('tag'))) {
result += ' home';
}
return result;
},
@computed('tag')
clickEventName() {
return "click.tag-drop-" + (this.get('tag') || "all");
},
actions: {
expand: function() {
var self = this;
if(!this.get('renderTags')){
this.set('renderTags',true);
Em.run.next(function(){
self.send('expand');
});
return;
}
if (this.get('expanded')) {
this.close();
return;
}
if (this.get('tags')) {
this.set('expanded', true);
}
var $dropdown = this.$()[0];
this.$('a[data-drop-close]').on('click.tag-drop', function() {
self.close();
});
Em.run.next(function(){
self.$('.cat a').add('html').on(self.get('clickEventName'), function(e) {
var $target = $(e.target),
closest = $target.closest($dropdown);
if ($(e.currentTarget).hasClass('badge-wrapper')){
self.close();
}
return ($(e.currentTarget).hasClass('badge-category') || (closest.length && closest[0] === $dropdown)) ? true : self.close();
});
});
}
},
removeEvents: function(){
$('html').off(this.get('clickEventName'));
this.$('a[data-drop-close]').off('click.tag-drop');
},
close: function() {
this.removeEvents();
this.set('expanded', false);
},
willDestroyElement: function() {
this.removeEvents();
}
});