| @@ 107-169 (lines=63) @@ | ||
| 104 | * Adds the font-families to the font-family dropdown |
|
| 105 | * and instantiates selectWoo. |
|
| 106 | */ |
|
| 107 | renderFontSelector: function() { |
|
| 108 | ||
| 109 | var control = this, |
|
| 110 | selector = control.selector + ' .font-family select', |
|
| 111 | data = [], |
|
| 112 | standardFonts = [], |
|
| 113 | googleFonts = [], |
|
| 114 | value = control.getValue(), |
|
| 115 | fonts = control.getFonts(), |
|
| 116 | fontSelect; |
|
| 117 | ||
| 118 | // Format standard fonts as an array. |
|
| 119 | if ( ! _.isUndefined( fonts.standard ) ) { |
|
| 120 | _.each( fonts.standard, function( font ) { |
|
| 121 | standardFonts.push({ |
|
| 122 | id: font.family.replace( /"/g, ''' ), |
|
| 123 | text: font.label |
|
| 124 | }); |
|
| 125 | }); |
|
| 126 | } |
|
| 127 | ||
| 128 | // Format google fonts as an array. |
|
| 129 | if ( ! _.isUndefined( fonts.standard ) ) { |
|
| 130 | _.each( fonts.google, function( font ) { |
|
| 131 | googleFonts.push({ |
|
| 132 | id: font.family, |
|
| 133 | text: font.label |
|
| 134 | }); |
|
| 135 | }); |
|
| 136 | } |
|
| 137 | ||
| 138 | // Combine forces and build the final data. |
|
| 139 | data = [ |
|
| 140 | { text: 'Standard Fonts', children: standardFonts }, |
|
| 141 | { text: 'Google Fonts', children: googleFonts } |
|
| 142 | ]; |
|
| 143 | ||
| 144 | // Instantiate selectWoo with the data. |
|
| 145 | fontSelect = jQuery( selector ).selectWoo({ |
|
| 146 | data: data |
|
| 147 | }); |
|
| 148 | ||
| 149 | // Set the initial value. |
|
| 150 | if ( value['font-family'] ) { |
|
| 151 | fontSelect.val( value['font-family'].replace( /'/g, '"' ) ).trigger( 'change' ); |
|
| 152 | } |
|
| 153 | ||
| 154 | // When the value changes |
|
| 155 | fontSelect.on( 'change', function() { |
|
| 156 | ||
| 157 | // Set the value. |
|
| 158 | control.saveValue( 'font-family', jQuery( this ).val() ); |
|
| 159 | ||
| 160 | // Re-init the font-backup selector. |
|
| 161 | control.renderBackupFontSelector(); |
|
| 162 | ||
| 163 | // Re-init variants selector. |
|
| 164 | control.renderVariantSelector(); |
|
| 165 | ||
| 166 | // Re-init subsets selector. |
|
| 167 | control.renderSubsetSelector(); |
|
| 168 | }); |
|
| 169 | }, |
|
| 170 | ||
| 171 | /** |
|
| 172 | * Adds the font-families to the font-family dropdown |
|
| @@ 99-161 (lines=63) @@ | ||
| 96 | * Adds the font-families to the font-family dropdown |
|
| 97 | * and instantiates selectWoo. |
|
| 98 | */ |
|
| 99 | renderFontSelector: function() { |
|
| 100 | ||
| 101 | var control = this, |
|
| 102 | selector = control.selector + ' .font-family select', |
|
| 103 | data = [], |
|
| 104 | standardFonts = [], |
|
| 105 | googleFonts = [], |
|
| 106 | value = control.setting._value, |
|
| 107 | fonts = control.getFonts(), |
|
| 108 | fontSelect; |
|
| 109 | ||
| 110 | // Format standard fonts as an array. |
|
| 111 | if ( ! _.isUndefined( fonts.standard ) ) { |
|
| 112 | _.each( fonts.standard, function( font ) { |
|
| 113 | standardFonts.push({ |
|
| 114 | id: font.family.replace( /"/g, ''' ), |
|
| 115 | text: font.label |
|
| 116 | }); |
|
| 117 | }); |
|
| 118 | } |
|
| 119 | ||
| 120 | // Format google fonts as an array. |
|
| 121 | if ( ! _.isUndefined( fonts.google ) ) { |
|
| 122 | _.each( fonts.google, function( font ) { |
|
| 123 | googleFonts.push({ |
|
| 124 | id: font.family, |
|
| 125 | text: font.family |
|
| 126 | }); |
|
| 127 | }); |
|
| 128 | } |
|
| 129 | ||
| 130 | // Combine forces and build the final data. |
|
| 131 | data = [ |
|
| 132 | { text: kirkiL10n.standardFonts, children: standardFonts }, |
|
| 133 | { text: kirkiL10n.googleFonts, children: googleFonts } |
|
| 134 | ]; |
|
| 135 | ||
| 136 | // Instantiate selectWoo with the data. |
|
| 137 | fontSelect = jQuery( selector ).selectWoo({ |
|
| 138 | data: data |
|
| 139 | }); |
|
| 140 | ||
| 141 | // Set the initial value. |
|
| 142 | if ( value['font-family'] ) { |
|
| 143 | fontSelect.val( value['font-family'].replace( /'/g, '"' ) ).trigger( 'change' ); |
|
| 144 | } |
|
| 145 | ||
| 146 | // When the value changes |
|
| 147 | fontSelect.on( 'change', function() { |
|
| 148 | ||
| 149 | // Set the value. |
|
| 150 | control.saveValue( 'font-family', jQuery( this ).val() ); |
|
| 151 | ||
| 152 | // Re-init the font-backup selector. |
|
| 153 | control.renderBackupFontSelector(); |
|
| 154 | ||
| 155 | // Re-init variants selector. |
|
| 156 | control.renderVariantSelector(); |
|
| 157 | ||
| 158 | // Re-init subsets selector. |
|
| 159 | control.renderSubsetSelector(); |
|
| 160 | }); |
|
| 161 | }, |
|
| 162 | ||
| 163 | /** |
|
| 164 | * Adds the font-families to the font-family dropdown |
|