2015-02-24 00:33:29 -05:00
var FFZ = window . FrankerFaceZ ,
constants = require ( "../constants" ) ,
2015-06-05 03:59:28 -04:00
utils = require ( "../utils" ) ,
2015-02-24 00:33:29 -05:00
2015-07-06 00:09:21 -04:00
BANNED _SETS = { "00000turbo" : true } ;
2015-02-24 00:33:29 -05:00
// -------------------
// Initialization
// -------------------
2015-08-04 01:43:08 -04:00
FFZ . basic _settings . replace _twitch _menu = {
type : "boolean" ,
category : "Chat" ,
name : "Unified Emoticons Menu" ,
help : "Completely replace the default Twitch emoticon menu and display global emoticons in the My Emoticons menu." ,
get : function ( ) {
return this . settings . replace _twitch _menu && this . settings . global _emotes _in _menu && this . settings . emoji _in _menu ;
} ,
set : function ( val ) {
this . settings . set ( 'replace_twitch_menu' , val ) ;
this . settings . set ( 'global_emotes_in_menu' , val ) ;
this . settings . set ( 'emoji_in_menu' , val ) ;
}
} ;
2015-07-13 21:52:44 -04:00
FFZ . settings _info . replace _twitch _menu = {
type : "boolean" ,
value : false ,
category : "Chat Input" ,
name : "Replace Twitch Emoticon Menu" ,
help : "Completely replace the default Twitch emoticon menu." ,
on _update : function ( val ) {
document . body . classList . toggle ( "ffz-menu-replace" , val ) ;
}
} ;
2015-02-26 00:42:11 -05:00
FFZ . settings _info . global _emotes _in _menu = {
type : "boolean" ,
value : false ,
2015-07-13 21:52:44 -04:00
category : "Chat Input" ,
2015-02-26 00:42:11 -05:00
name : "Display Global Emotes in My Emotes" ,
help : "Display the global Twitch emotes in the My Emoticons menu."
} ;
2015-07-06 00:09:21 -04:00
FFZ . settings _info . emoji _in _menu = {
type : "boolean" ,
2016-03-23 19:28:22 -04:00
value : true ,
2015-07-06 00:09:21 -04:00
2015-07-13 21:52:44 -04:00
category : "Chat Input" ,
2015-07-06 00:09:21 -04:00
name : "Display Emoji in My Emotes" ,
help : "Display the supported emoji images in the My Emoticons menu."
} ;
2015-07-13 21:52:44 -04:00
FFZ . settings _info . emote _menu _collapsed = {
2016-07-13 02:31:26 -04:00
storage _key : "ffz_setting_my_emoticons_collapsed_sections" ,
2015-07-13 21:52:44 -04:00
value : [ ] ,
visible : false
}
2016-03-23 19:28:22 -04:00
FFZ . settings _info . favorite _emotes = {
2016-07-13 02:31:26 -04:00
value : { } ,
visible : false
2016-03-23 19:28:22 -04:00
}
2015-02-24 00:33:29 -05:00
FFZ . prototype . setup _my _emotes = function ( ) {
2015-06-05 03:59:28 -04:00
this . _twitch _badges = { } ;
2015-07-31 21:40:51 -04:00
this . _twitch _badges [ "--global--" ] = "//cdn.frankerfacez.com/script/twitch_logo.png" ;
this . _twitch _badges [ "--turbo-faces--" ] = this . _twitch _badges [ "turbo" ] = "//cdn.frankerfacez.com/script/turbo_badge.png" ;
2015-02-24 00:33:29 -05:00
}
// -------------------
// Menu Page
// -------------------
2015-07-31 21:40:51 -04:00
FFZ . menu _pages . myemotes = {
2015-02-24 00:33:29 -05:00
name : "My Emoticons" ,
icon : constants . EMOTE ,
2016-03-31 19:47:17 -04:00
has _sets : function ( view ) {
2015-06-10 18:46:04 -04:00
var user = this . get _user ( ) ,
2016-03-31 19:47:17 -04:00
tmi = view && view . get ( 'controller.currentRoom.tmiSession' ) ,
2015-06-10 18:46:04 -04:00
ffz _sets = user && this . users [ user . login ] && this . users [ user . login ] . sets || [ ] ,
2015-08-28 22:54:12 -04:00
twitch _sets = ( tmi && tmi . getEmotes ( ) || { 'emoticon_sets' : { } } ) [ 'emoticon_sets' ] ,
sk = twitch _sets && Object . keys ( twitch _sets ) ;
2015-06-10 18:46:04 -04:00
2015-08-28 22:54:12 -04:00
if ( sk && ! this . settings . global _emotes _in _menu && sk . indexOf ( '0' ) !== - 1 )
sk . removeObject ( '0' ) ;
2016-03-31 19:47:17 -04:00
return ffz _sets . length || ( sk && sk . length ) ;
} ,
visible : function ( view ) {
2016-04-11 18:57:25 -04:00
return this . settings . emoji _in _menu || FFZ . menu _pages . myemotes . has _sets . call ( this , view ) ;
2015-02-24 00:33:29 -05:00
} ,
2016-07-13 02:31:26 -04:00
default _page : function ( ) {
for ( var key in this . settings . favorite _emotes )
if ( this . settings . favorite _emotes [ key ] && this . settings . favorite _emotes [ key ] . length )
return 'favorites' ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
return 'all' ;
} ,
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
pages : {
favorites : {
name : "Favorites" ,
sort _order : 1 ,
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
render : function ( view , container ) {
FFZ . menu _pages . myemotes . render _lists . call ( this , view , container , true ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
var el = document . createElement ( "div" ) ;
el . className = "emoticon-grid ffz-no-emotes center" ;
el . innerHTML = "You have no favorite emoticons.<br> <img src=\"//cdn.frankerfacez.com/emoticon/26608/2\"><br>To make an emote a favorite, find it on the <nobr>All Emoticons</nobr> tab and <nobr>" + ( constants . IS _OSX ? '⌘' : 'Ctrl' ) + "-Click</nobr> it." ;
container . appendChild ( el ) ;
}
} ,
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
all : {
name : "All Emoticons" ,
sort _order : 2 ,
2016-03-23 19:28:22 -04:00
2016-03-31 19:47:17 -04:00
visible : function ( view ) {
2016-04-11 18:57:25 -04:00
return FFZ . menu _pages . myemotes . has _sets . call ( this , view ) ;
2016-03-31 19:47:17 -04:00
} ,
2016-07-13 02:31:26 -04:00
render : function ( view , container ) {
FFZ . menu _pages . myemotes . render _lists . call ( this , view , container , false ) ;
}
} ,
emoji : {
name : "Emoji" ,
sort _order : 3 ,
visible : function ( ) { return this . settings . emoji _in _menu } ,
render : function ( view , container ) {
var sets = [ ] ;
for ( var cat in constants . EMOJI _CATEGORIES ) {
var menu = FFZ . menu _pages . myemotes . draw _emoji . call ( this , view , cat , false ) ;
if ( menu )
sets . push ( [ cat , menu ] ) ;
}
sets . sort ( function ( a , b ) {
var an = a [ 0 ] , bn = b [ 0 ] ;
if ( an < bn ) return - 1 ;
if ( an > bn ) return 1 ;
return 0 ;
} ) ;
for ( var i = 0 ; i < sets . length ; i ++ )
container . appendChild ( sets [ i ] [ 1 ] ) ;
}
}
} ,
render _lists : function ( view , container , favorites _only ) {
var tmi = view . get ( 'controller.currentRoom.tmiSession' ) ,
2016-03-23 19:28:22 -04:00
twitch _sets = ( tmi && tmi . getEmotes ( ) || { 'emoticon_sets' : { } } ) [ 'emoticon_sets' ] ,
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
user = this . get _user ( ) ,
ffz _sets = this . getEmotes ( user && user . login , null ) ,
sets = [ ] ;
// Start with Twitch Sets
for ( var set _id in twitch _sets ) {
if ( ! twitch _sets . hasOwnProperty ( set _id ) || ( ! this . settings . global _emotes _in _menu && set _id === '0' ) )
continue ;
var favorites _list = this . settings . favorite _emotes [ "twitch-" + set _id ] ;
if ( favorites _only && ( ! favorites _list || ! favorites _list . length ) )
continue ;
var set = twitch _sets [ set _id ] ;
if ( ! set . length )
continue ;
var menu = FFZ . menu _pages . myemotes . draw _twitch _set . call ( this , view , set _id , set , favorites _only ) ;
if ( menu )
sets . push ( [ this . _twitch _set _to _channel [ set _id ] , menu ] ) ;
}
// Emoji~!
if ( favorites _only && this . settings . emoji _in _menu ) {
var favorites _list = this . settings . favorite _emotes [ "emoji" ] ;
if ( favorites _list && favorites _list . length ) {
var menu = FFZ . menu _pages . myemotes . draw _emoji . call ( this , view , null , favorites _only ) ;
if ( menu )
sets . push ( [ "emoji" , menu ] ) ;
}
}
// Now, FFZ!
for ( var i = 0 ; i < ffz _sets . length ; i ++ ) {
var set _id = ffz _sets [ i ] ,
set = this . emote _sets [ set _id ] ,
menu _id = set . hasOwnProperty ( 'source_ext' ) ? 'ffz-ext-' + set . source _ext + '-' + set . source _id : 'ffz-' + set . id ,
favorites _list = this . settings . favorite _emotes [ menu _id ] ;
if ( favorites _only && ( ! favorites _list || ! favorites _list . length ) )
continue ;
if ( ! set || ! set . count || ( ! this . settings . global _emotes _in _menu && this . default _sets . indexOf ( set _id ) !== - 1 ) )
continue ;
var menu = FFZ . menu _pages . myemotes . draw _ffz _set . call ( this , view , set , favorites _only ) ;
if ( menu )
sets . push ( [ set . title . toLowerCase ( ) , menu ] ) ;
}
if ( ! sets . length )
return false ;
// Finally, sort and add them all.
sets . sort ( function ( a , b ) {
var an = a [ 0 ] , bn = b [ 0 ] ;
if ( an === "turbo" || an === "--turbo-faces--" )
an = "zza|" + an ;
else if ( an === "global" || ( an && an . substr ( 0 , 16 ) === "global emoticons" ) || an === "--global--" )
an = "zzy|" + an ;
else if ( an . substr ( 0 , 5 ) === "emoji" )
an = "zzz|" + an ;
if ( bn === "turbo" || bn === "--turbo-faces--" )
bn = "zza|" + bn ;
else if ( bn === "global" || ( bn && bn . substr ( 0 , 16 ) === "global emoticons" ) || bn === "--global--" )
bn = "zzy|" + bn ;
else if ( bn . substr ( 0 , 5 ) === "emoji" )
bn = "zzz|" + bn ;
if ( an < bn ) return - 1 ;
if ( an > bn ) return 1 ;
return 0 ;
} ) ;
if ( favorites _only ) {
var grid = document . createElement ( 'div' ) ;
grid . className = 'emoticon-grid favorites-grid' ;
for ( var i = 0 ; i < sets . length ; i ++ )
grid . appendChild ( sets [ i ] [ 1 ] ) ;
container . appendChild ( grid ) ;
} else
for ( var i = 0 ; i < sets . length ; i ++ )
container . appendChild ( sets [ i ] [ 1 ] ) ;
return true ;
2015-06-05 03:59:28 -04:00
} ,
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
toggle _section : function ( heading , container ) {
2015-07-13 21:52:44 -04:00
var menu = heading . parentElement ,
set _id = menu . getAttribute ( 'data-set' ) ,
collapsed _list = this . settings . emote _menu _collapsed ,
2016-03-23 19:28:22 -04:00
is _collapsed = collapsed _list . indexOf ( set _id ) === - 1 ;
2015-07-13 21:52:44 -04:00
2016-03-23 19:28:22 -04:00
if ( ! is _collapsed )
2015-07-13 21:52:44 -04:00
collapsed _list . removeObject ( set _id ) ;
else
collapsed _list . push ( set _id ) ;
2016-03-23 19:28:22 -04:00
this . settings . set ( 'emote_menu_collapsed' , collapsed _list , true ) ;
2015-07-13 21:52:44 -04:00
menu . classList . toggle ( 'collapsed' , ! is _collapsed ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( is _collapsed )
menu . appendChild ( container ) ;
else
menu . removeChild ( container ) ;
2015-07-13 21:52:44 -04:00
} ,
2016-03-23 19:28:22 -04:00
draw _emoji : function ( view , cat , favorites _only ) {
2015-07-06 00:09:21 -04:00
var heading = document . createElement ( 'div' ) ,
2015-07-13 21:52:44 -04:00
menu = document . createElement ( 'div' ) ,
2016-07-13 02:31:26 -04:00
menu _id = 'emoji' + ( cat ? '-' + cat : '' ) ,
emotes = favorites _only ? document . createDocumentFragment ( ) : document . createElement ( 'div' ) ,
collapsed = ! favorites _only && this . settings . emote _menu _collapsed . indexOf ( menu _id ) === - 1 ,
2015-08-28 22:54:12 -04:00
f = this ,
2016-03-23 19:28:22 -04:00
settings = this . settings . parse _emoji || 1 ,
2015-08-28 22:54:12 -04:00
2016-07-13 02:31:26 -04:00
favorites = this . settings . favorite _emotes [ "emoji" ] || [ ] ,
c = 0 ;
2015-07-06 00:09:21 -04:00
2016-07-13 02:31:26 -04:00
menu . className = 'emoticon-grid' ;
menu . setAttribute ( 'data-set' , menu _id ) ;
2015-07-06 00:09:21 -04:00
2016-07-13 02:31:26 -04:00
if ( ! favorites _only ) {
heading . className = 'heading' ;
heading . innerHTML = '<span class="right">Unicode</span>' + ( cat ? utils . sanitize ( constants . EMOJI _CATEGORIES [ cat ] ) : 'Emoji' ) ;
heading . style . backgroundImage = 'url("' + constants . SERVER + 'emoji/' + ( settings === 3 ? 'one/' : ( settings === 2 ? 'noto-' : 'tw/' ) ) + ( constants . EMOJI _LOGOS [ cat ] || '1f4af' ) + '.svg")' ;
heading . style . backgroundSize = "18px" ;
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
menu . classList . add ( 'collapsable' ) ;
menu . appendChild ( heading ) ;
menu . classList . toggle ( 'collapsed' , collapsed ) ;
2016-03-23 19:28:22 -04:00
heading . addEventListener ( 'click' , function ( ) { FFZ . menu _pages . myemotes . toggle _section . bind ( f ) ( this , emotes ) ; } ) ;
2016-07-13 02:31:26 -04:00
}
2015-08-02 02:41:03 -04:00
2015-07-06 00:09:21 -04:00
var set = [ ] ;
2015-08-28 22:54:12 -04:00
2015-07-06 00:09:21 -04:00
for ( var eid in this . emoji _data )
set . push ( this . emoji _data [ eid ] ) ;
2015-08-02 02:41:03 -04:00
2015-07-06 00:09:21 -04:00
set . sort ( function ( a , b ) {
2015-08-28 22:54:12 -04:00
var an = ( a . name || "" ) . toLowerCase ( ) ,
bn = ( b . name || "" ) . toLowerCase ( ) ;
2015-07-06 00:09:21 -04:00
if ( an < bn ) return - 1 ;
else if ( an > bn ) return 1 ;
if ( a . raw < b . raw ) return - 1 ;
if ( a . raw > b . raw ) return 1 ;
return 0 ;
} ) ;
2015-08-02 02:41:03 -04:00
2015-07-06 00:09:21 -04:00
for ( var i = 0 ; i < set . length ; i ++ ) {
var emoji = set [ i ] ,
2015-08-28 22:54:12 -04:00
em = document . createElement ( 'span' ) ;
2016-03-23 19:28:22 -04:00
if ( ( cat && cat !== emoji . cat ) || ( settings === 1 && ! emoji . tw ) || ( settings === 2 && ! emoji . noto ) || ( settings === 3 && ! emoji . one ) )
2015-08-28 22:54:12 -04:00
continue ;
2015-07-06 00:09:21 -04:00
2016-03-23 19:28:22 -04:00
var is _favorite = favorites . indexOf ( emoji . raw ) !== - 1 ,
2016-07-13 02:31:26 -04:00
src = settings === 3 ? emoji . one _src : ( settings === 2 ? emoji . noto _src : emoji . tw _src ) ,
2015-11-14 23:52:49 -05:00
image = this . settings . emote _image _hover ? '<img class="emoticon ffz-image-hover" src="' + src + '">' : '' ;
2016-07-13 02:31:26 -04:00
if ( favorites _only && ! is _favorite )
continue ;
2016-03-23 19:28:22 -04:00
em . className = 'emoticon emoji ffz-tooltip ffz-can-favorite' ;
2016-07-13 02:31:26 -04:00
em . classList . toggle ( 'ffz-favorite' , is _favorite ) ;
em . classList . toggle ( 'ffz-is-favorite' , favorites _only ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
em . setAttribute ( 'data-ffz-emoji' , emoji . code ) ;
em . alt = emoji . raw ;
2016-03-23 19:28:22 -04:00
em . addEventListener ( 'click' , this . _add _emote . bind ( this , view , emoji . raw , "emoji" , emoji . raw ) ) ;
2015-08-02 02:41:03 -04:00
2015-11-14 23:52:49 -05:00
em . style . backgroundImage = 'url("' + src + '")' ;
2015-08-28 22:54:12 -04:00
em . style . backgroundSize = "18px" ;
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
c ++ ;
2016-03-23 19:28:22 -04:00
emotes . appendChild ( em ) ;
2015-07-06 00:09:21 -04:00
}
2016-07-13 02:31:26 -04:00
if ( ! c )
return ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only )
return emotes ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( ! collapsed )
menu . appendChild ( emotes ) ;
2016-03-23 19:28:22 -04:00
2015-07-06 00:09:21 -04:00
return menu ;
} ,
2016-03-23 19:28:22 -04:00
draw _twitch _set : function ( view , set _id , set , favorites _only ) {
2015-06-05 03:59:28 -04:00
var heading = document . createElement ( 'div' ) ,
menu = document . createElement ( 'div' ) ,
2016-07-13 02:31:26 -04:00
emotes = favorites _only ? document . createDocumentFragment ( ) : document . createElement ( 'div' ) ,
collapsed = ! favorites _only && this . settings . emote _menu _collapsed . indexOf ( 'twitch-' + set _id ) === - 1 ,
2015-07-13 21:52:44 -04:00
f = this ,
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
channel _id = this . _twitch _set _to _channel [ set _id ] , title ,
2016-07-13 02:31:26 -04:00
favorites = this . settings . favorite _emotes [ "twitch-" + set _id ] || [ ] ,
c = 0 ;
2015-07-31 21:40:51 -04:00
2016-07-13 02:31:26 -04:00
menu . className = 'emoticon-grid' ;
2015-07-13 21:52:44 -04:00
menu . setAttribute ( 'data-set' , 'twitch-' + set _id ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( ! favorites _only ) {
if ( channel _id === "twitch_unknown" )
title = "Unknown Channel" ;
else if ( channel _id === "--global--" )
title = "Global Emoticons" ;
else if ( channel _id === "turbo" || channel _id === "--turbo-faces--" )
title = "Twitch Turbo" ;
else
title = FFZ . get _capitalization ( channel _id , function ( name ) {
heading . innerHTML = '<span class="right">Twitch</span>' + utils . sanitize ( name ) ;
} ) ;
heading . className = 'heading' ;
heading . innerHTML = '<span class="right">Twitch</span>' + utils . sanitize ( title ) ;
if ( this . _twitch _badges [ channel _id ] )
heading . style . backgroundImage = 'url("' + this . _twitch _badges [ channel _id ] + '")' ;
else {
var f = this ;
utils . api . get ( "chat/" + channel _id + "/badges" , null , { version : 3 } )
. done ( function ( data ) {
if ( data . subscriber && data . subscriber . image ) {
f . _twitch _badges [ channel _id ] = data . subscriber . image ;
localStorage . ffzTwitchBadges = JSON . stringify ( f . _twitch _badges ) ;
heading . style . backgroundImage = 'url("' + data . subscriber . image + '")' ;
}
} ) ;
}
menu . classList . add ( 'collapsable' ) ;
menu . appendChild ( heading ) ;
menu . classList . toggle ( 'collapsed' , collapsed ) ;
heading . addEventListener ( 'click' , function ( ) { FFZ . menu _pages . myemotes . toggle _section . bind ( f ) ( this , emotes ) ; } ) ;
}
2015-02-26 17:27:39 -05:00
2015-07-06 00:09:21 -04:00
set . sort ( function ( a , b ) {
var an = a . code . toLowerCase ( ) ,
bn = b . code . toLowerCase ( ) ;
if ( an < bn ) return - 1 ;
else if ( an > bn ) return 1 ;
if ( a . id < b . id ) return - 1 ;
if ( a . id > b . id ) return 1 ;
return 0 ;
} ) ;
2015-06-05 03:59:28 -04:00
for ( var i = 0 ; i < set . length ; i ++ ) {
var emote = set [ i ] ,
2015-07-06 00:09:21 -04:00
code = constants . KNOWN _CODES [ emote . code ] || emote . code ,
2016-07-13 02:31:26 -04:00
is _favorite = favorites . indexOf ( emote . id ) !== - 1 ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only && ! is _favorite )
continue ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
var em = document . createElement ( 'span' ) ,
2016-03-23 19:28:22 -04:00
img _set = 'image-set(url("' + constants . TWITCH _BASE + emote . id + '/1.0") 1x, url("' + constants . TWITCH _BASE + emote . id + '/2.0") 2x)' ;
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
em . className = 'emoticon ffz-tooltip ffz-can-favorite' ;
2016-07-13 02:31:26 -04:00
em . setAttribute ( 'data-emote' , emote . id ) ;
em . alt = code ;
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
em . classList . toggle ( 'ffz-favorite' , is _favorite ) ;
em . classList . toggle ( 'ffz-is-favorite' , favorites _only ) ;
em . classList . toggle ( 'ffz-tooltip-no-credit' , ! favorites _only ) ;
2015-07-06 00:09:21 -04:00
if ( this . settings . replace _bad _emotes && constants . EMOTE _REPLACEMENTS [ emote . id ] ) {
em . style . backgroundImage = 'url("' + constants . EMOTE _REPLACEMENT _BASE + constants . EMOTE _REPLACEMENTS [ emote . id ] + '")' ;
} else {
2015-11-14 23:52:49 -05:00
em . style . backgroundImage = 'url("' + constants . TWITCH _BASE + emote . id + '/1.0")' ;
2015-07-06 00:09:21 -04:00
em . style . backgroundImage = '-webkit-' + img _set ;
em . style . backgroundImage = '-moz-' + img _set ;
em . style . backgroundImage = '-ms-' + img _set ;
2016-03-23 19:28:22 -04:00
em . style . backgroundImage = img _set ;
2015-07-06 00:09:21 -04:00
}
2015-02-24 00:33:29 -05:00
2015-08-28 22:54:12 -04:00
em . addEventListener ( "click" , function ( id , c , e ) {
2015-08-02 02:41:03 -04:00
e . preventDefault ( ) ;
if ( ( e . shiftKey || e . shiftLeft ) && f . settings . clickable _emoticons )
window . open ( "https://twitchemotes.com/emote/" + id ) ;
else
2016-03-23 19:28:22 -04:00
this . _add _emote ( view , c , "twitch-" + set _id , id , e ) ;
2015-08-28 22:54:12 -04:00
} . bind ( this , emote . id , code ) ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
c ++ ;
2016-03-23 19:28:22 -04:00
emotes . appendChild ( em ) ;
2015-06-05 03:59:28 -04:00
}
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( ! c )
return ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only )
return emotes ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( ! collapsed )
menu . appendChild ( emotes ) ;
2016-03-23 19:28:22 -04:00
2015-06-05 03:59:28 -04:00
return menu ;
} ,
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
draw _ffz _set : function ( view , set , favorites _only ) {
2015-06-05 03:59:28 -04:00
var heading = document . createElement ( 'div' ) ,
menu = document . createElement ( 'div' ) ,
2016-07-13 02:31:26 -04:00
emote _container = favorites _only ? document . createDocumentFragment ( ) : document . createElement ( 'div' ) ,
2015-07-13 21:52:44 -04:00
f = this ,
2015-10-24 22:44:00 -04:00
emotes = [ ] ,
menu _id = set . hasOwnProperty ( 'source_ext' ) ? 'ffz-ext-' + set . source _ext + '-' + set . source _id : 'ffz-' + set . id ,
2016-07-13 02:31:26 -04:00
favorites = this . settings . favorite _emotes [ menu _id ] || [ ] ,
c = 0 ,
2016-03-23 19:28:22 -04:00
icon = set . icon || ( set . hasOwnProperty ( 'source_ext' ) && '//cdn.frankerfacez.com/emoji/tw-1f4ac.svg' ) || '//cdn.frankerfacez.com/script/devicon.png' ,
2016-07-13 02:31:26 -04:00
collapsed = ! favorites _only && this . settings . emote _menu _collapsed . indexOf ( menu _id ) === - 1 ;
2016-03-23 19:28:22 -04:00
menu . className = 'emoticon-grid' ;
2016-07-13 02:31:26 -04:00
menu . setAttribute ( 'data-set' , menu _id ) ;
2015-02-26 17:27:39 -05:00
2016-07-13 02:31:26 -04:00
if ( ! favorites _only ) {
menu . classList . add ( 'collapsable' ) ;
2015-10-24 22:44:00 -04:00
2016-07-13 02:31:26 -04:00
heading . className = 'heading' ;
heading . innerHTML = '<span class="right">' + ( utils . sanitize ( set . source ) || 'FrankerFaceZ' ) + '</span>' + set . title ;
2015-02-26 17:27:39 -05:00
2016-07-13 02:31:26 -04:00
heading . style . backgroundImage = 'url("' + icon + '")' ;
if ( icon . indexOf ( '.svg' ) !== - 1 )
heading . style . backgroundSize = "18px" ;
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
menu . appendChild ( heading ) ;
menu . classList . toggle ( 'collapsed' , collapsed ) ;
heading . addEventListener ( 'click' , function ( ) { FFZ . menu _pages . myemotes . toggle _section . bind ( f ) ( this , emote _container ) ; } ) ;
}
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
for ( var emote _id in set . emoticons )
set . emoticons . hasOwnProperty ( emote _id ) && ! set . emoticons [ emote _id ] . hidden && emotes . push ( set . emoticons [ emote _id ] ) ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
emotes . sort ( function ( a , b ) {
var an = a . name . toLowerCase ( ) ,
bn = b . name . toLowerCase ( ) ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
if ( an < bn ) return - 1 ;
else if ( an > bn ) return 1 ;
if ( a . id < b . id ) return - 1 ;
if ( a . id > b . id ) return 1 ;
return 0 ;
} ) ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
for ( var i = 0 ; i < emotes . length ; i ++ ) {
var emote = emotes [ i ] ,
2016-07-13 02:31:26 -04:00
is _favorite = favorites . indexOf ( emote . id ) !== - 1 ;
2015-06-05 03:59:28 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only && ! is _favorite )
continue ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
var em = document . createElement ( 'span' ) ,
2015-06-05 03:59:28 -04:00
img _set = 'image-set(url("' + emote . urls [ 1 ] + '") 1x' ;
if ( emote . urls [ 2 ] )
img _set += ', url("' + emote . urls [ 2 ] + '") 2x' ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
if ( emote . urls [ 4 ] )
img _set += ', url("' + emote . urls [ 4 ] + '") 4x' ;
2015-02-24 00:33:29 -05:00
2015-06-05 03:59:28 -04:00
img _set += ')' ;
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
em . className = 'emoticon ffz-tooltip ffz-can-favorite' ;
2016-07-13 02:31:26 -04:00
em . classList . toggle ( 'ffz-favorite' , is _favorite ) ;
em . classList . toggle ( 'ffz-is-favorite' , favorites _only ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
em . setAttribute ( 'data-ffz-emote' , emote . id ) ;
em . setAttribute ( 'data-ffz-set' , set . id ) ;
2016-03-23 19:28:22 -04:00
2015-06-05 03:59:28 -04:00
em . style . backgroundImage = 'url("' + emote . urls [ 1 ] + '")' ;
em . style . backgroundImage = '-webkit-' + img _set ;
em . style . backgroundImage = '-moz-' + img _set ;
em . style . backgroundImage = '-ms-' + img _set ;
2016-03-23 19:28:22 -04:00
em . style . backgroundImage = img _set ;
2015-02-24 00:33:29 -05:00
2015-06-05 03:59:28 -04:00
if ( emote . height )
2016-03-23 19:28:22 -04:00
em . style . height = ( 10 + emote . height ) + "px" ;
2015-06-05 03:59:28 -04:00
if ( emote . width )
2016-03-23 19:28:22 -04:00
em . style . width = ( 10 + emote . width ) + "px" ;
2015-02-24 00:33:29 -05:00
2015-08-02 02:41:03 -04:00
em . addEventListener ( "click" , function ( id , code , e ) {
e . preventDefault ( ) ;
2015-10-27 14:25:13 -04:00
if ( ( e . shiftKey || e . shiftLeft ) && f . settings . clickable _emoticons ) {
var url ;
if ( set . hasOwnProperty ( 'source_ext' ) ) {
var api = f . _apis [ set . source _ext ] ;
if ( api && api . emote _url _generator )
url = api . emote _url _generator ( set . source _id , id ) ;
} else
url = "https://www.frankerfacez.com/emoticons/" + id ;
if ( url )
window . open ( url ) ;
} else
2016-03-23 19:28:22 -04:00
this . _add _emote ( view , code , menu _id , id , e ) ;
2015-08-02 02:41:03 -04:00
} . bind ( this , emote . id , emote . name ) ) ;
2015-02-26 17:27:39 -05:00
2016-07-13 02:31:26 -04:00
c ++ ;
2016-03-23 19:28:22 -04:00
emote _container . appendChild ( em ) ;
}
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( ! c )
return ;
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( favorites _only )
return emote _container ;
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( ! collapsed )
menu . appendChild ( emote _container ) ;
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
return menu ;
2015-06-05 03:59:28 -04:00
}
} ;