mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-28 15:27:43 +00:00
Refactored Ember hooks to reduce code duplication.
This commit is contained in:
parent
664a19bbd3
commit
faece54a91
1 changed files with 69 additions and 84 deletions
125
script.js
125
script.js
|
@ -447,14 +447,9 @@ ffz.prototype.do_imgur = function(room, album, data) {
|
||||||
// Ember Hooks
|
// Ember Hooks
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
ffz.prototype.modify_lines = function() {
|
ffz.prototype.add_badge = function(sender, badges) {
|
||||||
var f = this;
|
// Is the sender a donor?
|
||||||
App.LineView.reopen({
|
if ( ! this.check_donor(sender) )
|
||||||
didInsertElement: function() {
|
|
||||||
this._super();
|
|
||||||
// Check for Donor Messages
|
|
||||||
var sender = this.get('context.model.from');
|
|
||||||
if ( ! f.check_donor(sender) )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Create the FFZ Donor badge.
|
// Create the FFZ Donor badge.
|
||||||
|
@ -467,8 +462,7 @@ ffz.prototype.modify_lines = function() {
|
||||||
c.appendChild(b);
|
c.appendChild(b);
|
||||||
c.appendChild(document.createTextNode(' '));
|
c.appendChild(document.createTextNode(' '));
|
||||||
|
|
||||||
// Get the badge list.
|
// Figure out where to place the badge.
|
||||||
var badges = this.$('.badges');
|
|
||||||
var before = badges.find('.badge-container').filter(function(i) {
|
var before = badges.find('.badge-container').filter(function(i) {
|
||||||
var t = this.title.toLowerCase();
|
var t = this.title.toLowerCase();
|
||||||
return t == "subscriber" || t == "turbo";
|
return t == "subscriber" || t == "turbo";
|
||||||
|
@ -478,13 +472,21 @@ ffz.prototype.modify_lines = function() {
|
||||||
before.before(c);
|
before.before(c);
|
||||||
else
|
else
|
||||||
badges.append(c);
|
badges.append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
ffz.prototype.modify_lines = function() {
|
||||||
|
var f = this;
|
||||||
|
App.LineView.reopen({
|
||||||
|
didInsertElement: function() {
|
||||||
|
this._super();
|
||||||
|
f.add_badge(this.get('context.model.from'), this.$('.badges'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ffz.prototype.modify_room = function() {
|
ffz.prototype._modify_room = function(room) {
|
||||||
var f = this;
|
var f = this;
|
||||||
App.Room.reopen({
|
room.reopen({
|
||||||
init: function() {
|
init: function() {
|
||||||
this._super();
|
this._super();
|
||||||
if ( f.alive )
|
if ( f.alive )
|
||||||
|
@ -506,18 +508,31 @@ ffz.prototype.modify_room = function() {
|
||||||
return this._super(e);
|
return this._super(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ffz.prototype.modify_room = function() {
|
||||||
|
this._modify_room(App.Room);
|
||||||
|
|
||||||
var inst = App.Room.instances;
|
var inst = App.Room.instances;
|
||||||
for(var n in inst) {
|
for(var n in inst) {
|
||||||
if ( ! inst.hasOwnProperty(n) ) continue;
|
if ( ! inst.hasOwnProperty(n) ) continue;
|
||||||
var i = inst[n];
|
var i = inst[n];
|
||||||
if ( f.alive )
|
if ( this.alive )
|
||||||
f.add_channel(i.id, i);
|
this.add_channel(i.id, i);
|
||||||
|
|
||||||
if ( i.tmiRoom && f.alive )
|
if ( i.tmiRoom && this.alive )
|
||||||
f.alter_tmi(i.id, i.tmiRoom);
|
this.alter_tmi(i.id, i.tmiRoom);
|
||||||
else if ( i.viewers ) {
|
else if ( i.viewers )
|
||||||
i.viewers.reopen({
|
this._modify_viewers(i.viewers);
|
||||||
|
|
||||||
|
this._modify_room(i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ffz.prototype._modify_viewers = function(vwrs) {
|
||||||
|
var f = this;
|
||||||
|
vwrs.reopen({
|
||||||
tmiRoom: Ember.computed(function(key, val) {
|
tmiRoom: Ember.computed(function(key, val) {
|
||||||
if ( arguments.length > 1 ) {
|
if ( arguments.length > 1 ) {
|
||||||
this.tmiRoom = val;
|
this.tmiRoom = val;
|
||||||
|
@ -527,52 +542,22 @@ ffz.prototype.modify_room = function() {
|
||||||
return undefined;
|
return undefined;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
i.reopen({
|
|
||||||
willDestroy: function() {
|
|
||||||
this._super();
|
|
||||||
if ( f.alive ) f.remove_channel(this.id);
|
|
||||||
},
|
|
||||||
send: function(e) {
|
|
||||||
if ( f.alive && (e.substr(0,5) == "/ffz " || e == '/ffz') ) {
|
|
||||||
this.set("messageToSend", "");
|
|
||||||
f.run_command(this, e);
|
|
||||||
} else
|
|
||||||
return this._super(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ffz.prototype.modify_viewers = function() {
|
ffz.prototype.modify_viewers = function() {
|
||||||
var f = this;
|
this._modify_viewers(App.Room.Viewers);
|
||||||
App.Room.Viewers.reopen({
|
|
||||||
tmiRoom: Ember.computed(function(key, val) {
|
|
||||||
if ( arguments.length > 1 ) {
|
|
||||||
this.tmiRoom = val;
|
|
||||||
if ( f.alive )
|
|
||||||
f.alter_tmi(this.id, val);
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
})
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ffz.prototype.modify_emotes = function() {
|
|
||||||
|
ffz.prototype._modify_emotes = function(ec) {
|
||||||
var f = this;
|
var f = this;
|
||||||
App.EmoticonsController.reopen({
|
ec.reopen({
|
||||||
_emoticons: [],
|
_emoticons: [],
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
this._super();
|
this._super();
|
||||||
if ( f.alive ) {
|
if ( f.alive )
|
||||||
f.manager = this;
|
f.get_manager(this);
|
||||||
for(var key in f.emotesets) {
|
|
||||||
if ( f.emotesets.hasOwnProperty(key) )
|
|
||||||
this.emoticonSets[key] = f.emotesets[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
emoticons: Ember.computed(function(key, val) {
|
emoticons: Ember.computed(function(key, val) {
|
||||||
|
@ -583,27 +568,27 @@ ffz.prototype.modify_emotes = function() {
|
||||||
return f.alive ? _.union(this._emoticons, f.emoticons) : this._emoticons;
|
return f.alive ? _.union(this._emoticons, f.emoticons) : this._emoticons;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ffz.prototype.modify_emotes = function() {
|
||||||
|
this._modify_emotes(App.EmoticonsController);
|
||||||
|
|
||||||
var ec = App.__container__.lookup("controller:emoticons");
|
var ec = App.__container__.lookup("controller:emoticons");
|
||||||
if ( ! ec ) return;
|
if ( ! ec ) return;
|
||||||
|
|
||||||
f.manager = ec;
|
this._modify_emotes(ec);
|
||||||
for(var key in f.emotesets)
|
this.get_manager(ec);
|
||||||
if ( f.emotesets.hasOwnProperty(key) )
|
|
||||||
ec.emoticonSets[key] = f.emotesets[key];
|
|
||||||
|
|
||||||
ec.reopen({
|
|
||||||
_emoticons: ec.emoticons,
|
|
||||||
emoticons: Ember.computed(function(key, val) {
|
|
||||||
if ( arguments.length > 1 ) {
|
|
||||||
this._emoticons = val;
|
|
||||||
f.log("Twitch standard emoticons loaded.");
|
|
||||||
}
|
|
||||||
return f.alive ? _.union(this._emoticons, f.emoticons) : this._emoticons;
|
|
||||||
})
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ffz.prototype.get_manager = function(manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
for(var key in this.emotesets) {
|
||||||
|
if ( this.emotesets.hasOwnProperty(key) )
|
||||||
|
manager.emoticonSets[key] = this.emotesets[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// Channel Management
|
// Channel Management
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue