@@ -18,13 +18,13 @@ function setFontSettingsPerLine() {
1818
1919 // Default font settings from the current UI controls
2020 var currentFont = {
21- font_family : $ ( '#fontFamily option:selected' ) . text ( ) ,
22- font_style : $ ( '#fontStyle option:selected' ) . text ( ) ,
23- font_size : $ ( '#fontSize' ) . val ( ) ,
24- font_inverted : $ ( '#fontInverted' ) . is ( ':checked' ) ,
21+ family : $ ( '#fontFamily option:selected' ) . text ( ) ,
22+ style : $ ( '#fontStyle option:selected' ) . text ( ) ,
23+ size : $ ( '#fontSize' ) . val ( ) ,
24+ inverted : $ ( '#fontInverted' ) . is ( ':checked' ) ,
2525 align : $ ( 'input[name=fontAlign]:checked' ) . val ( ) ,
2626 line_spacing : $ ( 'input[name=lineSpacing]:checked' ) . val ( ) ,
27- font_color : $ ( '# fontColor' ) . val ( )
27+ color : $ ( 'input[name= fontColor]:checked ' ) . val ( )
2828 } ;
2929
3030 // Create lines in the <option> with id #lineSelect
@@ -92,29 +92,29 @@ $(document).ready(function () {
9292 if ( isNaN ( idx ) || ! fontSettingsPerLine || ! fontSettingsPerLine [ idx ] ) return ;
9393 var fs = fontSettingsPerLine [ idx ] ;
9494 // Only set font family and get styles if font family is changed
95- if ( fs . font_family !== $ ( '#fontFamily option:selected' ) . text ( ) ) {
95+ if ( fs . family !== $ ( '#fontFamily option:selected' ) . text ( ) ) {
9696 // Set font family
97- $ ( '#fontFamily' ) . val ( fs . font_family ) ;
97+ $ ( '#fontFamily' ) . val ( fs . family ) ;
9898 // Set font style
99- updateStyles ( fs . font_style ) ;
99+ updateStyles ( fs . style ) ;
100100 }
101101 else {
102102 // Only set font style
103- $ ( '#fontStyle' ) . val ( fs . font_style ) ;
103+ $ ( '#fontStyle' ) . val ( fs . style ) ;
104104 }
105105 // Set font size
106- $ ( '#fontSize' ) . val ( fs . font_size ) ;
106+ $ ( '#fontSize' ) . val ( fs . size ) ;
107107 // Set alignment
108108 $ ( 'input[name=fontAlign]' ) . prop ( 'checked' , false ) . parent ( ) . removeClass ( 'active' ) ;
109109 $ ( 'input[name=fontAlign][value="' + fs . align + '"]' ) . prop ( 'checked' , true ) . parent ( ) . addClass ( 'active' ) ;
110110 // Set line spacing
111111 $ ( 'input[name=lineSpacing]' ) . prop ( 'checked' , false ) . parent ( ) . removeClass ( 'active' ) ;
112112 $ ( 'input[name=lineSpacing][value="' + fs . line_spacing + '"]' ) . prop ( 'checked' , true ) . parent ( ) . addClass ( 'active' ) ;
113113 // Set font inversion
114- $ ( '#fontInverted' ) . prop ( 'checked' , fs . font_inverted ) ;
114+ $ ( '#fontInverted' ) . prop ( 'checked' , fs . inverted ) ;
115115 // Set font color
116116 $ ( 'input[name=fontColor]' ) . prop ( 'checked' , false ) . parent ( ) . removeClass ( 'active' ) ;
117- $ ( 'input[name=fontColor][value="' + fs . font_color + '"]' ) . prop ( 'checked' , true ) . parent ( ) . addClass ( 'active' ) ;
117+ $ ( 'input[name=fontColor][value="' + fs . color + '"]' ) . prop ( 'checked' , true ) . parent ( ) . addClass ( 'active' ) ;
118118 } ) ;
119119
120120 // When the user changes the caret/selection in the textarea, update #lineSelect and font controls
@@ -201,6 +201,7 @@ function updateStyles(style = null) {
201201 }
202202 } ) ;
203203 styleSelect . trigger ( "change" ) ;
204+ preview ( ) ;
204205 }
205206 } ) ;
206207}
@@ -503,7 +504,7 @@ function restoreAllSettingsFromLocalStorage() {
503504 if ( this . type === 'checkbox' || this . type === 'radio' ) {
504505 $ ( this ) . prop ( 'checked' , ! ! data [ key ] ) ;
505506 if ( this . type === 'radio' ) {
506- if ( $ ( this ) . val ( ) == data [ key ] ) $ ( this ) . prop ( 'checked' , true ) ;
507+ $ ( this ) . prop ( 'checked' , $ ( this ) . val ( ) == data [ key ] ) ;
507508 }
508509 } else {
509510 $ ( this ) . val ( data [ key ] ) ;
@@ -564,11 +565,15 @@ function resetSettings() {
564565function set_all_inputs_default ( force = false ) {
565566 // Iterate over those <input> that have a data-default propery and set the value if empty
566567 $ ( 'input[data-default], select[data-default], textarea[data-default]' ) . each ( function ( ) {
567- if ( ! $ ( this ) . val ( ) || force ) {
568+ if ( this . type === 'checkbox' || this . type === 'radio' ) {
569+ $ ( this ) . prop ( 'checked' , $ ( this ) . data ( 'default' ) == 1 || $ ( this ) . data ( 'default' ) === true ) ;
570+ }
571+ else if ( this . type === 'select-one' || this . type === 'number' ) {
568572 $ ( this ) . val ( $ ( this ) . data ( 'default' ) ) ;
573+
569574 }
570- if ( this . type === 'checkbox' ) {
571- $ ( this ) . prop ( 'checked' , $ ( this ) . data ( 'default' ) == 1 || $ ( this ) . data ( 'default' ) === true ) ;
575+ else if ( ! $ ( this ) . val ( ) || force ) {
576+ $ ( this ) . val ( $ ( this ) . data ( 'default' ) ) ;
572577 }
573578 } ) ;
574579}
@@ -582,6 +587,7 @@ window.onload = function () {
582587
583588 // Restore settings on load
584589 restoreAllSettingsFromLocalStorage ( ) ;
590+
585591 // Save on change
586592 $ ( document ) . on ( 'change input' , 'input, select, textarea' , function ( ) {
587593 saveAllSettingsToLocalStorage ( ) ;
0 commit comments