1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-27 21:05:53 +00:00

Refactored Ember hooks to reduce code duplication.

This commit is contained in:
SirStendec 2014-03-27 23:24:57 -04:00
parent 664a19bbd3
commit faece54a91

153
script.js
View file

@ -447,44 +447,46 @@ ffz.prototype.do_imgur = function(room, album, data) {
// Ember Hooks // Ember Hooks
// ----------------- // -----------------
ffz.prototype.add_badge = function(sender, badges) {
// Is the sender a donor?
if ( ! this.check_donor(sender) )
return;
// Create the FFZ Donor badge.
var c = document.createElement('span');
c.className = 'badge-container tooltip';
c.setAttribute('title', 'FFZ Donor');
var b = document.createElement('div');
b.className = 'badge ffz-donor';
c.appendChild(b);
c.appendChild(document.createTextNode(' '));
// Figure out where to place the badge.
var before = badges.find('.badge-container').filter(function(i) {
var t = this.title.toLowerCase();
return t == "subscriber" || t == "turbo";
}).first();
if ( before.length )
before.before(c);
else
badges.append(c);
}
ffz.prototype.modify_lines = function() { ffz.prototype.modify_lines = function() {
var f = this; var f = this;
App.LineView.reopen({ App.LineView.reopen({
didInsertElement: function() { didInsertElement: function() {
this._super(); this._super();
// Check for Donor Messages f.add_badge(this.get('context.model.from'), this.$('.badges'));
var sender = this.get('context.model.from');
if ( ! f.check_donor(sender) )
return;
// Create the FFZ Donor badge.
var c = document.createElement('span');
c.className = 'badge-container tooltip';
c.setAttribute('title', 'FFZ Donor');
var b = document.createElement('div');
b.className = 'badge ffz-donor';
c.appendChild(b);
c.appendChild(document.createTextNode(' '));
// Get the badge list.
var badges = this.$('.badges');
var before = badges.find('.badge-container').filter(function(i) {
var t = this.title.toLowerCase();
return t == "subscriber" || t == "turbo";
}).first();
if ( before.length )
before.before(c);
else
badges.append(c);
} }
}); });
} }
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,48 +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);
tmiRoom: Ember.computed(function(key, val) {
if ( arguments.length > 1 ) {
this.tmiRoom = val;
if ( f.alive )
f.alter_tmi(this.id, val);
}
return undefined;
})
});
}
i.reopen({ this._modify_room(i);
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(vwrs) {
var f = this; var f = this;
App.Room.Viewers.reopen({ 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;
@ -557,22 +542,22 @@ ffz.prototype.modify_viewers = function() {
return undefined; return undefined;
}) })
}); });
}
ffz.prototype.modify_viewers = function() {
this._modify_viewers(App.Room.Viewers);
}; };
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
// ----------------- // -----------------