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
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
app.views.TagFollowingList = app.views.Base.extend({
templateName: "tag_following_list",
className : "sub_nav",
id : "tags_list",
tagName : "ul",
events: {
"submit form": "createTagFollowing"
},
initialize : function(){
this.collection.on("add", this.appendTagFollowing, this);
this.collection.on("reset", this.postRenderTemplate, this);
},
postRenderTemplate : function() {
// add the whole sorted collection without handling each item separately
this.collection.each(function(tag) {
this.$el.prepend(new app.views.TagFollowing({
model: tag
}).render().el);
}, this);
},
setupAutoSuggest : function() {
new Diaspora.TagsAutocomplete(this.$("input"), {
selectionAdded: _.bind(this.suggestSelection, this)
});
},
presenter : function() {
return this.defaultPresenter();
},
suggestSelection : function(elem) {
this.$(".tag_input").val($(elem[0]).text().substring(2));
elem.remove();
this.createTagFollowing();
},
createTagFollowing: function(evt) {
if(evt){ evt.preventDefault(); }
var name = this.$(".tag_input").val();
// compare tag_text_regexp in app/models/acts_as_taggable_on-tag.rb
var normalizedName = (name === "<3" ? name : name.replace(
new RegExp("[^" + PosixBracketExpressions.alnum + "_\\-]+", "gi"), "").toLowerCase());
this.collection.create({"name":normalizedName});
this.$(".tag_input").val("");
return this;
},
appendTagFollowing: function(tag) {
// insert new tag in the order of the collection
var modelIndex = this.collection.indexOf(tag);
var prevModel = this.collection.at(modelIndex + 1); // prev in alphabet, +1 (next) in reverse sorted list
if (prevModel) {
var prevModelDom = this.$("#tag-following-" + prevModel.get("name"));
if (prevModelDom.length > 0) {
prevModelDom.after(new app.views.TagFollowing({
model: tag
}).render().el);
return;
}
}
// we have no previous Model and no View, so just prepend to the list
this.$el.prepend(new app.views.TagFollowing({
model: tag
}).render().el);
},
hideFollowedTags: function() {
this.$el.empty();
},
});
// @license-end
|