2015-02-08 02:01:09 -05:00
|
|
|
var FFZ = window.FrankerFaceZ,
|
|
|
|
constants = require('../constants');
|
2015-01-20 01:53:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// Initializer
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
FFZ.prototype.setup_menu = function() {
|
|
|
|
this.log("Installing mouse-up event to auto-close menus.");
|
|
|
|
var f = this;
|
|
|
|
|
|
|
|
jQuery(document).mouseup(function(e) {
|
|
|
|
var popup = f._popup, parent;
|
|
|
|
if ( ! popup ) return;
|
|
|
|
popup = jQuery(popup);
|
|
|
|
parent = popup.parent();
|
|
|
|
|
|
|
|
if ( ! parent.is(e.target) && parent.has(e.target).length === 0 ) {
|
|
|
|
popup.remove();
|
|
|
|
delete f._popup;
|
2015-02-08 02:01:09 -05:00
|
|
|
f._popup_kill && f._popup_kill();
|
|
|
|
delete f._popup_kill;
|
2015-01-20 01:53:18 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-08 02:01:09 -05:00
|
|
|
FFZ.menu_pages = {};
|
|
|
|
|
|
|
|
|
2015-01-20 01:53:18 -05:00
|
|
|
// --------------------
|
|
|
|
// Create Menu
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
FFZ.prototype.build_ui_popup = function(view) {
|
|
|
|
var popup = this._popup;
|
|
|
|
if ( popup ) {
|
|
|
|
popup.parentElement.removeChild(popup);
|
|
|
|
delete this._popup;
|
2015-02-08 02:01:09 -05:00
|
|
|
this._popup_kill && this._popup_kill();
|
|
|
|
delete this._popup_kill;
|
2015-01-20 01:53:18 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start building the DOM.
|
|
|
|
var container = document.createElement('div'),
|
2015-02-08 02:01:09 -05:00
|
|
|
inner = document.createElement('div'),
|
|
|
|
menu = document.createElement('ul'),
|
|
|
|
|
|
|
|
dark = (this.has_bttv ? BetterTTV.settings.get('darkenedMode') : false);
|
2015-01-20 01:53:18 -05:00
|
|
|
|
|
|
|
container.className = 'emoticon-selector chat-menu ffz-ui-popup';
|
|
|
|
inner.className = 'emoticon-selector-box dropmenu';
|
|
|
|
container.appendChild(inner);
|
|
|
|
|
2015-02-08 02:01:09 -05:00
|
|
|
container.classList.toggle('dark', dark);
|
|
|
|
|
|
|
|
// Render Menu
|
|
|
|
menu.className = 'menu clearfix';
|
|
|
|
inner.appendChild(menu);
|
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
var heading = document.createElement('li');
|
|
|
|
heading.className = 'title';
|
|
|
|
heading.innerHTML = "<span>" + (constants.DEBUG ? "[DEV] " : "") + "FrankerFaceZ</span>";
|
|
|
|
menu.appendChild(heading);
|
2015-02-08 02:01:09 -05:00
|
|
|
|
|
|
|
var sub_container = document.createElement('div');
|
|
|
|
sub_container.className = 'ffz-ui-menu-page';
|
|
|
|
inner.appendChild(sub_container);
|
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
var menu_pages = [];
|
2015-02-08 02:01:09 -05:00
|
|
|
for(var key in FFZ.menu_pages) {
|
2015-02-24 00:33:29 -05:00
|
|
|
if ( ! FFZ.menu_pages.hasOwnProperty(key) )
|
|
|
|
continue;
|
|
|
|
|
2015-02-08 02:01:09 -05:00
|
|
|
var page = FFZ.menu_pages[key];
|
|
|
|
if ( !page || (page.hasOwnProperty("visible") && (!page.visible || (typeof page.visible == "function" && !page.visible.bind(this)()))) )
|
|
|
|
continue;
|
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
menu_pages.push([page.sort_order || 0, key, page]);
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_pages.sort(function(a,b) {
|
|
|
|
if ( a[0] < b[0] ) return 1;
|
|
|
|
else if ( a[0] > b[0] ) return -1;
|
|
|
|
|
|
|
|
var al = a[1].toLowerCase(),
|
|
|
|
bl = b[1].toLowerCase();
|
|
|
|
|
|
|
|
if ( al < bl ) return 1;
|
|
|
|
if ( al > bl ) return -1;
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
for(var i=0; i < menu_pages.length; i++) {
|
|
|
|
var key = menu_pages[i][1],
|
|
|
|
page = menu_pages[i][2],
|
|
|
|
el = document.createElement('li'),
|
2015-02-08 02:01:09 -05:00
|
|
|
link = document.createElement('a');
|
|
|
|
|
|
|
|
el.className = 'item';
|
|
|
|
el.id = "ffz-menu-page-" + key;
|
|
|
|
link.title = page.name;
|
|
|
|
link.innerHTML = page.icon;
|
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
jQuery(link).tipsy();
|
|
|
|
|
2015-02-08 02:01:09 -05:00
|
|
|
link.addEventListener("click", this._ui_change_page.bind(this, view, menu, sub_container, key));
|
|
|
|
|
|
|
|
el.appendChild(link);
|
|
|
|
menu.appendChild(el);
|
2015-01-27 17:05:51 -05:00
|
|
|
}
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2015-02-08 02:01:09 -05:00
|
|
|
// Render Current Page
|
|
|
|
this._ui_change_page(view, menu, sub_container, this._last_page || "channel");
|
2015-01-20 01:53:18 -05:00
|
|
|
|
|
|
|
// Add the menu to the DOM.
|
|
|
|
this._popup = container;
|
2015-02-10 01:34:23 -05:00
|
|
|
sub_container.style.maxHeight = Math.max(100, view.$().height() - 162) + "px";
|
2015-01-20 01:53:18 -05:00
|
|
|
view.$('.chat-interface').append(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-08 02:01:09 -05:00
|
|
|
FFZ.prototype._ui_change_page = function(view, menu, container, page) {
|
|
|
|
this._last_page = page;
|
|
|
|
container.innerHTML = "";
|
2015-02-24 00:33:29 -05:00
|
|
|
container.setAttribute('data-page', page);
|
2015-02-08 02:01:09 -05:00
|
|
|
|
|
|
|
var els = menu.querySelectorAll('li.active');
|
|
|
|
for(var i=0; i < els.length; i++)
|
|
|
|
els[i].classList.remove('active');
|
|
|
|
|
|
|
|
var el = menu.querySelector('#ffz-menu-page-' + page);
|
|
|
|
if ( el )
|
|
|
|
el.classList.add('active');
|
|
|
|
else
|
|
|
|
this.log("No matching page: " + page);
|
|
|
|
|
|
|
|
FFZ.menu_pages[page].render.bind(this)(view, container);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------
|
2015-02-24 00:33:29 -05:00
|
|
|
// Favorites Page
|
2015-02-08 02:01:09 -05:00
|
|
|
// --------------------
|
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
FFZ.prototype._tokenize_message = function(message, room_id) {
|
|
|
|
var lc = App.__container__.lookup('controller:line'),
|
|
|
|
rc = App.__container__.lookup('controller:room'),
|
|
|
|
room = this.rooms[room_id],
|
|
|
|
user = this.get_user();
|
2015-02-08 02:01:09 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
if ( ! lc || ! rc || ! room )
|
|
|
|
return [message];
|
2015-02-08 02:01:09 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
rc.set('model', room.room);
|
|
|
|
lc.set('parentController', rc);
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
var model = {
|
|
|
|
from: user && user.login || "FrankerFaceZ",
|
|
|
|
message: message,
|
|
|
|
tags: {
|
|
|
|
emotes: room.room.tmiSession._emotesParser.parseEmotesTag(message)
|
2015-02-08 02:01:09 -05:00
|
|
|
}
|
2015-02-24 00:33:29 -05:00
|
|
|
};
|
2015-02-08 02:01:09 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
lc.set('model', model);
|
2015-02-08 02:01:09 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
var tokens = lc.get('tokenizedMessage');
|
2015-02-08 02:01:09 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
lc.set('model', null);
|
|
|
|
rc.set('model', null);
|
|
|
|
lc.set('parentController', null);
|
2015-02-08 02:01:09 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
return tokens;
|
|
|
|
}
|
2015-02-08 02:01:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*FFZ.menu_pages.favorites = {
|
|
|
|
render: function(view, container) {
|
2015-02-24 00:33:29 -05:00
|
|
|
// Get the current room.
|
|
|
|
var room_id = view.get('controller.currentRoom.id');
|
|
|
|
|
|
|
|
|
2015-02-08 02:01:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
name: "Favorites",
|
|
|
|
icon: constants.HEART
|
|
|
|
};*/
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// Channel Page
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
FFZ.menu_pages.channel = {
|
|
|
|
render: function(view, inner) {
|
|
|
|
// Get the current room.
|
|
|
|
var room_id = view.get('controller.currentRoom.id'),
|
|
|
|
room = this.rooms[room_id];
|
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
// Basic Emote Sets
|
|
|
|
this._emotes_for_sets(inner, view, room && room.menu_sets || []);
|
2015-02-08 02:01:09 -05:00
|
|
|
|
|
|
|
// Feature Friday!
|
|
|
|
this._feature_friday_ui(room_id, inner, view);
|
|
|
|
},
|
|
|
|
|
|
|
|
name: "Channel",
|
|
|
|
icon: constants.ZREKNARF
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-20 01:53:18 -05:00
|
|
|
// --------------------
|
|
|
|
// Emotes for Sets
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
FFZ.prototype._emotes_for_sets = function(parent, view, sets, header, btn) {
|
|
|
|
if ( header != null ) {
|
|
|
|
var el_header = document.createElement('div');
|
|
|
|
el_header.className = 'list-header';
|
|
|
|
el_header.appendChild(document.createTextNode(header));
|
|
|
|
|
|
|
|
if ( btn )
|
|
|
|
el_header.appendChild(btn);
|
|
|
|
|
|
|
|
parent.appendChild(el_header);
|
|
|
|
}
|
|
|
|
|
|
|
|
var grid = document.createElement('div'), c = 0;
|
|
|
|
grid.className = 'emoticon-grid';
|
|
|
|
|
|
|
|
for(var i=0; i < sets.length; i++) {
|
|
|
|
var set = this.emote_sets[sets[i]];
|
|
|
|
if ( ! set || ! set.emotes )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for(var eid in set.emotes) {
|
2015-02-24 00:33:29 -05:00
|
|
|
if ( ! set.emotes.hasOwnProperty(eid) )
|
|
|
|
continue;
|
|
|
|
|
2015-01-20 01:53:18 -05:00
|
|
|
var emote = set.emotes[eid];
|
|
|
|
if ( !set.emotes.hasOwnProperty(eid) || emote.hidden )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
c++;
|
|
|
|
var s = document.createElement('span');
|
|
|
|
s.className = 'emoticon tooltip';
|
|
|
|
s.style.backgroundImage = 'url("' + emote.url + '")';
|
|
|
|
s.style.width = emote.width + "px";
|
|
|
|
s.style.height = emote.height + "px";
|
|
|
|
s.title = emote.name;
|
|
|
|
s.addEventListener('click', this._add_emote.bind(this, view, emote.name));
|
|
|
|
grid.appendChild(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !c ) {
|
|
|
|
grid.innerHTML = "This channel has no emoticons.";
|
|
|
|
grid.className = "chat-menu-content ffz-no-emotes center";
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.appendChild(grid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FFZ.prototype._add_emote = function(view, emote) {
|
2015-02-24 00:33:29 -05:00
|
|
|
var input_el, text, room;
|
|
|
|
|
|
|
|
if ( this.has_bttv ) {
|
|
|
|
input_el = view.get('element').querySelector('textarea');
|
|
|
|
text = input_el.value;
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
} else {
|
|
|
|
room = view.get('controller.currentRoom');
|
|
|
|
text = room.get('messageToSend') || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
text += (text && text.substr(-1) !== " " ? " " : "") + (emote.name || emote);
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2015-02-24 00:33:29 -05:00
|
|
|
if ( input_el )
|
|
|
|
input_el.value = text;
|
|
|
|
else
|
|
|
|
room.set('messageToSend', text);
|
2015-01-12 17:58:07 -05:00
|
|
|
}
|