Added large flags to the WYSIWYG editor's dropdown.

master
Pacman Ghost 2 years ago
parent 569edbc48a
commit 8388cec67e
  1. 53
      vasl_templates/webapp/static/html-editor.js
  2. 2
      vasl_templates/webapp/static/trumbowyg/plugins/flags.css
  3. 38
      vasl_templates/webapp/static/trumbowyg/plugins/flags.js
  4. 2
      vasl_templates/webapp/tests/test_snippets.py

@ -232,6 +232,7 @@ function initVictoryConditionsTrumbowyg()
function updateTrumbowygFlagsDropdown( $ctrl ) function updateTrumbowygFlagsDropdown( $ctrl )
{ {
// FUDGE! For convenience, we show the flags for the current players at the start of the dropdown list, // FUDGE! For convenience, we show the flags for the current players at the start of the dropdown list,
// and while we can do this in makeDropdown() in our plugin, this only happens once for the Victory Conditions // and while we can do this in makeDropdown() in our plugin, this only happens once for the Victory Conditions
// control. There doesn't seem to be a way to dynamically generate the list each time it drops down, // control. There doesn't seem to be a way to dynamically generate the list each time it drops down,
@ -251,26 +252,48 @@ function updateTrumbowygFlagsDropdown( $ctrl )
return ; return ;
// remove the dropdown's flag buttons from the DOM // remove the dropdown's flag buttons from the DOM
var $btns = {} ; var $btns = { small: {}, large: {} } ;
$dropdown.find( "button" ).detach().each( function() { $dropdown.find( "button" ).detach().each( function() {
var nat = $(this).find( "img" ).data( "nat" ) ; var $img = $(this).find( "img" ) ;
$btns[ nat ] = $(this) ; var nat = $img.data( "nat" ) ;
var size ;
if ( $img.hasClass( "small" ) )
size = "small" ;
else if ( $img.hasClass( "large" ) )
size = "large" ;
else {
console.log( "INTERNAL ERROR: Unknown flag type:", $img ) ;
return ;
}
$btns[ size ][ nat ] = $(this) ;
} ) ; } ) ;
// add the flag buttons back into the DOM // add the flag buttons back into the DOM
plugin.nationalities.forEach( function( nat ) { var clearLeft = false ;
if ( nat === nat1 || nat === nat2 ) function addButton( $btn ) {
if ( ! $btn )
return ; return ;
var $btn = $btns[ nat ] ; if ( clearLeft ) {
if ( $btn ) $btn.css( "clear", "left" ) ;
$dropdown.append( $btn ) ; clearLeft = false ;
} ) ; }
var $btn = $btns[ nat2 ] ; $dropdown.append( $btn ) ;
if ( $btn ) }
$dropdown.prepend( $btn ) ; function addButtons( size ) {
$btn = $btns[ nat1 ] ; Object.values( $btns[size] ).forEach( function( $btn ) {
if ( $btn ) $btn.css( "clear", "none" ) ;
$dropdown.prepend( $btn ) ; } ) ;
addButton( $btns[size][ nat1 ] ) ;
addButton( $btns[size][ nat2 ] ) ;
plugin.nationalities.forEach( function( nat ) {
if ( nat === nat1 || nat === nat2 )
return ;
addButton( $btns[size][ nat ] ) ;
} ) ;
}
addButtons( "small" ) ;
clearLeft = true ;
addButtons( "large" ) ;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

@ -3,3 +3,5 @@
float: left ; float: left ;
line-height: 30px ; line-height: 30px ;
} }
.trumbowyg-dropdown-flags img.small { width: 11px ; height: 11px ; }
.trumbowyg-dropdown-flags img.large { width: 13px ; height: 13px ; }

@ -31,23 +31,29 @@
var flags = [] ; var flags = [] ;
// add an entry for each nationality // add an entry for each nationality
$.each( plugin.nationalities, function( index, nat ) { function addFlags( isSmall ) {
var displayName = get_nationality_display_name( nat ) ; $.each( plugin.nationalities, function( index, nat ) {
trumbowyg.addBtnDef( nat, { var key = nat + "-" + (isSmall ? "small" : "large") ;
fn: function () { var displayName = get_nationality_display_name( nat ) ;
var url = plugin.makeFlagHtml( nat, false ) ; var size = isSmall ? 11 : 13 ;
var size = 11 ; trumbowyg.addBtnDef( key, {
var html = "<img src='" + url + "?prefh=" + size + "' width='" + size + "' height='" + size + "'>" ; fn: function () {
trumbowyg.execCmd( "insertHtml", html ) ; var url = plugin.makeFlagHtml( nat, false ) ;
}, var html = "<img src='" + url + "?prefh=" + size + "' width='" + size + "' height='" + size + "'>" ;
hasIcon: false, trumbowyg.execCmd( "insertHtml", html ) ;
title: "<img src='" + plugin.makeFlagHtml(nat,true) + "'" + },
" title='" + displayName + "'" + hasIcon: false,
" data-nat='" + nat + "'" + title: "<img src='" + plugin.makeFlagHtml(nat,true) + "'" +
">" , " class='" + (isSmall ? "small" : "large") + "'" +
" title='" + displayName + "'" +
" data-nat='" + nat + "'" +
">" ,
} ) ;
flags.push( key ) ;
} ) ; } ) ;
flags.push( nat ) ; }
} ) ; addFlags( true ) ;
addFlags( false ) ;
return flags ; return flags ;
} }

@ -555,7 +555,7 @@ def test_player_flags_in_trumbowyg( webapp, webdriver ):
def insert_flag( nat ): def insert_flag( nat ):
find_child( "#panel-vc .trumbowyg-flags-button" ).click() find_child( "#panel-vc .trumbowyg-flags-button" ).click()
wait_for_elem( 2, "#panel-vc .trumbowyg-dropdown-flags" ) wait_for_elem( 2, "#panel-vc .trumbowyg-dropdown-flags" )
find_child( "button.trumbowyg-{}-dropdown-button".format( nat ) ).click() find_child( "button.trumbowyg-{}-small-dropdown-button".format( nat ) ).click()
def wait_for_flag( expected ): def wait_for_flag( expected ):
if expected.search( unload_trumbowyg( editor ) ): if expected.search( unload_trumbowyg( editor ) ):
return True return True

Loading…
Cancel
Save