@@ -18,12 +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 ( ) ,
26- line_spacing : $ ( 'input[name=lineSpacing]:checked' ) . val ( )
26+ line_spacing : $ ( 'input[name=lineSpacing]:checked' ) . val ( ) ,
27+ color : $ ( 'input[name=fontColor]:checked' ) . val ( )
2728 } ;
2829
2930 // Create lines in the <option> with id #lineSelect
@@ -91,26 +92,29 @@ $(document).ready(function () {
9192 if ( isNaN ( idx ) || ! fontSettingsPerLine || ! fontSettingsPerLine [ idx ] ) return ;
9293 var fs = fontSettingsPerLine [ idx ] ;
9394 // Only set font family and get styles if font family is changed
94- if ( fs . font_family !== $ ( '#fontFamily option:selected' ) . text ( ) ) {
95+ if ( fs . family !== $ ( '#fontFamily option:selected' ) . text ( ) ) {
9596 // Set font family
96- $ ( '#fontFamily' ) . val ( fs . font_family ) ;
97+ $ ( '#fontFamily' ) . val ( fs . family ) ;
9798 // Set font style
98- updateStyles ( fs . font_style ) ;
99+ updateStyles ( fs . style ) ;
99100 }
100101 else {
101102 // Only set font style
102- $ ( '#fontStyle' ) . val ( fs . font_style ) ;
103+ $ ( '#fontStyle' ) . val ( fs . style ) ;
103104 }
104105 // Set font size
105- $ ( '#fontSize' ) . val ( fs . font_size ) ;
106+ $ ( '#fontSize' ) . val ( fs . size ) ;
106107 // Set alignment
107108 $ ( 'input[name=fontAlign]' ) . prop ( 'checked' , false ) . parent ( ) . removeClass ( 'active' ) ;
108109 $ ( 'input[name=fontAlign][value="' + fs . align + '"]' ) . prop ( 'checked' , true ) . parent ( ) . addClass ( 'active' ) ;
109110 // Set line spacing
110111 $ ( 'input[name=lineSpacing]' ) . prop ( 'checked' , false ) . parent ( ) . removeClass ( 'active' ) ;
111112 $ ( 'input[name=lineSpacing][value="' + fs . line_spacing + '"]' ) . prop ( 'checked' , true ) . parent ( ) . addClass ( 'active' ) ;
112113 // Set font inversion
113- $ ( '#fontInverted' ) . prop ( 'checked' , fs . font_inverted ) ;
114+ $ ( '#fontInverted' ) . prop ( 'checked' , fs . inverted ) ;
115+ // Set font color
116+ $ ( 'input[name=fontColor]' ) . prop ( 'checked' , false ) . parent ( ) . removeClass ( 'active' ) ;
117+ $ ( 'input[name=fontColor][value="' + fs . color + '"]' ) . prop ( 'checked' , true ) . parent ( ) . addClass ( 'active' ) ;
114118 } ) ;
115119
116120 // When the user changes the caret/selection in the textarea, update #lineSelect and font controls
@@ -197,6 +201,7 @@ function updateStyles(style = null) {
197201 }
198202 } ) ;
199203 styleSelect . trigger ( "change" ) ;
204+ preview ( ) ;
200205 }
201206 } ) ;
202207}
@@ -401,7 +406,7 @@ function updatePrinterStatus() {
401406 if ( printerPath ) {
402407 printerPath . textContent = printer_status . path || 'Unknown' ;
403408 }
404- if ( printer_status [ 'red_support' ] === true && $ ( '#labelSize option:selected' ) . val ( ) . includes ( 'red' ) ) {
409+ if ( $ ( '#labelSize option:selected' ) . val ( ) . includes ( 'red' ) ) {
405410 $ ( ".red-support" ) . show ( ) ;
406411 } else {
407412 $ ( '#print_color_black' ) . prop ( 'active' , true ) ;
@@ -499,7 +504,7 @@ function restoreAllSettingsFromLocalStorage() {
499504 if ( this . type === 'checkbox' || this . type === 'radio' ) {
500505 $ ( this ) . prop ( 'checked' , ! ! data [ key ] ) ;
501506 if ( this . type === 'radio' ) {
502- if ( $ ( this ) . val ( ) == data [ key ] ) $ ( this ) . prop ( 'checked' , true ) ;
507+ $ ( this ) . prop ( 'checked' , $ ( this ) . val ( ) == data [ key ] ) ;
503508 }
504509 } else {
505510 $ ( this ) . val ( data [ key ] ) ;
@@ -560,11 +565,15 @@ function resetSettings() {
560565function set_all_inputs_default ( force = false ) {
561566 // Iterate over those <input> that have a data-default propery and set the value if empty
562567 $ ( 'input[data-default], select[data-default], textarea[data-default]' ) . each ( function ( ) {
563- 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' ) {
564572 $ ( this ) . val ( $ ( this ) . data ( 'default' ) ) ;
573+
565574 }
566- if ( this . type === 'checkbox' ) {
567- $ ( this ) . prop ( 'checked' , $ ( this ) . data ( 'default' ) == 1 || $ ( this ) . data ( 'default' ) === true ) ;
575+ else if ( ! $ ( this ) . val ( ) || force ) {
576+ $ ( this ) . val ( $ ( this ) . data ( 'default' ) ) ;
568577 }
569578 } ) ;
570579}
@@ -578,6 +587,7 @@ window.onload = function () {
578587
579588 // Restore settings on load
580589 restoreAllSettingsFromLocalStorage ( ) ;
590+
581591 // Save on change
582592 $ ( document ) . on ( 'change input' , 'input, select, textarea' , function ( ) {
583593 saveAllSettingsToLocalStorage ( ) ;
0 commit comments