| @@ -1,271 +1,83 @@ | ||
| 1 | -( function( $ ) { | |
| 2 | - $( document ).ready( function() { | |
| 3 | - | |
| 4 | - /* Apply network settings */ | |
| 5 | - $( 'input[name="pdfprnt_network_apply"]' ).on( 'change', function() { | |
| 6 | - if ( $( this ).is( ':checked' ) ) { | |
| 7 | - var $input = $( this ); | |
| 8 | - | |
| 9 | - switch( $input.val() ) { | |
| 10 | - case 'off': | |
| 11 | - $( '.bws_network_apply_all, .pdfprnt-table-settings, #bws_settings_tabs li:not(.bws-tab-settings):not(.bws-tab-license)' ).hide(); | |
| 12 | - break; | |
| 13 | - case 'default': | |
| 14 | - $( '.bws_network_apply_all' ).hide(); | |
| 15 | - $( '.pdfprnt-table-settings, .pdfprnt-table-settings, #bws_settings_tabs li:not(.bws-tab-settings):not(.bws-tab-license)' ).show(); | |
| 16 | - break; | |
| 17 | - case 'all': | |
| 18 | - $( '.bws_network_apply_all, .pdfprnt-table-settings, #bws_settings_tabs li:not(.bws-tab-settings):not(.bws-tab-license)' ).show(); | |
| 19 | - break; | |
| 20 | - } | |
| 21 | - } | |
| 22 | - } ).trigger( 'change' ); | |
| 23 | - | |
| 24 | - /* Button Image */ | |
| 25 | - $( 'input[name="pdfprnt_button_image[pdf]"], input[name="pdfprnt_button_image[print]"]' ).on( 'change', function() { | |
| 26 | - if ( $( this ).is( ':checked' ) ) { | |
| 27 | - var $input = $( this ), | |
| 28 | - button = $input.attr( 'data-button' ), | |
| 29 | - image_block = $( '.pdfprnt-image-' + button ), | |
| 30 | - image = image_block.find( 'img' ), | |
| 31 | - file_input = $( '#pdfprnt-button-image-file-' + button ); | |
| 32 | - | |
| 33 | - switch( $input.val() ) { | |
| 34 | - case 'none': | |
| 35 | - image_block.hide(); | |
| 36 | - file_input.hide(); | |
| 37 | - break; | |
| 38 | - case 'default': | |
| 39 | - file_input.hide(); | |
| 40 | - image.attr( 'src', image.attr( 'data-default-src' ) ); | |
| 41 | - image_block.show(); | |
| 42 | - break; | |
| 43 | - case 'custom': | |
| 44 | - file_input.show(); | |
| 45 | - image.attr( 'src', image.attr( 'data-custom-src' ) ); | |
| 46 | - image_block.show(); | |
| 47 | - break; | |
| 48 | - } | |
| 49 | - | |
| 50 | - if ( $( 'input[name^="pdfprnt_button_image"][value="custom"]:checked' ).length > 0 ) { | |
| 51 | - $( '#pdfprnt-image-info' ).show(); | |
| 52 | - } else { | |
| 53 | - $( '#pdfprnt-image-info' ).hide(); | |
| 54 | - } | |
| 55 | - } | |
| 56 | - } ).trigger( 'change' ); | |
| 57 | - | |
| 58 | - /* Default PDF File Name */ | |
| 59 | - $( 'input[name="pdfprnt_select_file_name"]' ).on('change', function() { | |
| 60 | - if ( $( this ).filter( ':checked' ).val() == 0 ) { | |
| 61 | - $( "#pdfprnt-file-name-wrap" ).show(); | |
| 62 | - } else { | |
| 63 | - $( "#pdfprnt-file-name-wrap" ).hide(); | |
| 64 | - } | |
| 65 | - }).trigger('change'); | |
| 66 | - | |
| 67 | - /* Featured Image Size */ | |
| 68 | - $( 'input[name="pdfprnt_show_featured_image"]' ).on('change', function() { | |
| 69 | - if ( $( this ).is( ':checked' ) ) { | |
| 70 | - $( "#pdfprnt_featured_image_size_wrap" ).show(); | |
| 71 | - } else { | |
| 72 | - $( "#pdfprnt_featured_image_size_wrap" ).hide(); | |
| 73 | - } | |
| 74 | - }).trigger('change'); | |
| 75 | - | |
| 76 | - /* Watermark Protection */ | |
| 77 | - $( 'input[name="pdfprnt_select_watermark"]' ).on('change', function() { | |
| 78 | - var watermark = $( this ).filter( ':checked' ).val(); | |
| 79 | - | |
| 80 | - switch( watermark ) { | |
| 81 | - case 'none': | |
| 82 | - $( '#pdfprnt-watermark-text-wrap, #pdfprnt-watermark-file-wrap, #pdfprnt_watermark_opacity' ).hide(); | |
| 83 | - break; | |
| 84 | - case 'text': | |
| 85 | - $( '#pdfprnt-watermark-text-wrap, #pdfprnt_watermark_opacity' ).show(); | |
| 86 | - $( '#pdfprnt-watermark-file-wrap' ).hide(); | |
| 87 | - break; | |
| 88 | - case 'image': | |
| 89 | - $( '#pdfprnt-watermark-text-wrap' ).hide(); | |
| 90 | - $( '#pdfprnt-watermark-file-wrap, #pdfprnt_watermark_opacity' ).show(); | |
| 91 | - break; | |
| 92 | - } | |
| 93 | - }).trigger('change'); | |
| 94 | - | |
| 95 | - /* Watermark Opacity */ | |
| 96 | - $( '#pdfprnt_watermark_opacity_slider' ).slider({ | |
| 97 | - value : $( '#pdfprnt-watermark-opacity' ).val(), | |
| 98 | - min : 0.1, | |
| 99 | - max : 1, | |
| 100 | - step : 0.05, | |
| 101 | - create : function( event, ui ) { | |
| 102 | - $( '#pdfprnt_watermark_opacity_value' ).text( '[' + $( this ).slider( 'value' ) + ']' ); | |
| 103 | - $( '#pdfprnt-watermark-opacity' ).hide(); | |
| 104 | - }, | |
| 105 | - slide : function( event, ui ) { | |
| 106 | - $( '#gglmps_zoom_value' ).text( '[' + ui.value + ']' ); | |
| 107 | - }, | |
| 108 | - change: function( event, ui ) { | |
| 109 | - $( '#pdfprnt-watermark-opacity' ).val( ui.value ); | |
| 110 | - $( '#pdfprnt_watermark_opacity_value' ).text( '[' + ui.value + ']' ); | |
| 111 | - } | |
| 112 | - }); | |
| 113 | - | |
| 114 | - /* Additional Elements */ | |
| 115 | - $( 'input[name="pdfprnt_image_to_pdf"]' ).on('change', function() { | |
| 116 | - if ( $( this ).is( ':checked' ) ) { | |
| 117 | - $( "#pdfprnt_additional_elements_wrap, #pdfprnt_woocommerce_product_details_wrap, #pdfprnt_watermark_protection_wrap, #pdfprnt_watermark_opacity, #pdfprnt_prevent_copying_wrap, #pdfprnt_additional_fonts_wrap, #pdfprnt_default_css_wrap, #pdfprnt_print_shortcodes_wrap, #pdfprnt_remove_links_wrap, #pdfprnt-disable-links, #pdfprnt_custom_css_wrap" ).hide(); | |
| 118 | - } else { | |
| 119 | - $( "#pdfprnt_additional_elements_wrap, #pdfprnt_woocommerce_product_details_wrap, #pdfprnt_watermark_protection_wrap, #pdfprnt_prevent_copying_wrap, #pdfprnt_additional_fonts_wrap, #pdfprnt_default_css_wrap, #pdfprnt_print_shortcodes_wrap, #pdfprnt_remove_links_wrap, #pdfprnt-disable-links, #pdfprnt_custom_css_wrap" ).show(); | |
| 120 | - } | |
| 121 | - }).trigger('change'); | |
| 122 | - | |
| 123 | - | |
| 124 | - /** | |
| 125 | - * Add All select * | |
| 126 | - */ | |
| 127 | - $( '.pdfprnt_role' ).on( 'change', function() { | |
| 128 | - var checkboxes = $( '.pdfprnt_role' ); | |
| 129 | - if ( checkboxes.filter( ':checked' ).length == checkboxes.length ) { | |
| 130 | - $( '.pdfprnt_select_all' ).prop( 'checked', true ); | |
| 131 | - } else { | |
| 132 | - $( '.pdfprnt_select_all' ).prop( 'checked', false ); | |
| 133 | - } | |
| 134 | - } ).trigger( 'change' ); | |
| 135 | - | |
| 136 | - $( '.pdfprnt_select_all' ).on( 'change', function() { | |
| 137 | - if ( $( this ).is( ':checked' ) ) { | |
| 138 | - $( '.pdfprnt_role' ).prop( 'checked', true ); | |
| 139 | - } else { | |
| 140 | - $( '.pdfprnt_role' ).prop( 'checked', false ); | |
| 141 | - } | |
| 142 | - } ); | |
| 143 | - | |
| 144 | - /* Ajax request for loading of additional fonts */ | |
| 145 | - var input = $( 'input[name="pdfprnt_load_fonts"]' ); | |
| 146 | - input.click( function() { | |
| 147 | - input.attr( 'disabled', true ); | |
| 148 | - $.ajax( { | |
| 149 | - url: ajaxurl, | |
| 150 | - type: "POST", | |
| 151 | - data: { action: 'pdfprnt_load_fonts', pdfprnt_ajax_nonce: pdfprnt_var['ajax_nonce'], is_network_admin: $( 'body' ).hasClass( 'network-admin' ) }, | |
| 152 | - beforeSend: function() { | |
| 153 | - $( '#pdfprnt_font_loader' ).css( 'display', 'inline-block' ); | |
| 154 | - $( '.updated, .error' ).hide(); | |
| 155 | - $( '<div class="updated fade"><p><strong>' + pdfprnt_var['loading_fonts'] + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 156 | - /* display 'warning'-window while fonts loading */ | |
| 157 | - window.onbeforeunload = function( e ) { | |
| 158 | - if ( $( '#pdfprnt_font_loader' ).is( ':visible' ) ) | |
| 159 | - return true; | |
| 160 | - }; | |
| 161 | - }, | |
| 162 | - success: function( result ) { | |
| 163 | - $( '#pdfprnt_font_loader, .updated, .error' ).hide(); | |
| 164 | - try { | |
| 165 | - var message = $.parseJSON( result ); | |
| 166 | - } catch ( e ) { | |
| 167 | - $( '<div class="error"><p><strong>' + result + pdfprnt_var['need_reload'] + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 168 | - input.attr( 'disabled', false ); | |
| 169 | - return false; | |
| 170 | - } | |
| 171 | - if ( message['done'] ) { | |
| 172 | - $( '<div class="updated fade"><p><strong>' + message['done'] + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 173 | - $( '#pdfprnt_load_fonts_button' ).hide(); | |
| 174 | - } | |
| 175 | - if ( message['error'] ) { | |
| 176 | - $( '<div class="error"><p><strong>' + message['error'] + pdfprnt_var['need_reload'] + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 177 | - input.attr( 'disabled', false ); | |
| 178 | - } | |
| 179 | - } | |
| 180 | - } ); | |
| 181 | - return false; | |
| 182 | - } ); | |
| 183 | - | |
| 184 | - /* Ajax request for upgrading of mPDF library */ | |
| 185 | - var button = $( 'input[name="pdfprnt_upgrade_library"]' ); | |
| 186 | - button.click( function() { | |
| 187 | - button.attr( 'disabled', true ); | |
| 188 | - $.ajax( { | |
| 189 | - url: ajaxurl, | |
| 190 | - type: "POST", | |
| 191 | - data: { action: 'pdfprnt_upgrade_library', pdfprnt_ajax_nonce: pdfprnt_var['ajax_nonce'], is_network_admin: $( 'body' ).hasClass( 'network-admin' ) }, | |
| 192 | - beforeSend: function() { | |
| 193 | - $( '#pdfprnt_library_loader' ).css( 'display', 'inline-block' ); | |
| 194 | - $( '.updated, .error' ).hide(); | |
| 195 | - $( '<div class="updated fade"><p><strong>' + pdfprnt_var['loading_mpdf'] + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 196 | - }, | |
| 197 | - success: function( result ) { | |
| 198 | - $( '#pdfprnt_library_loader, .updated, .error' ).hide(); | |
| 199 | - try { | |
| 200 | - var message = $.parseJSON( result ); | |
| 201 | - } catch ( e ) { | |
| 202 | - $( '<div class="error"><p><strong>' + result + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 203 | - input.attr( 'disabled', false ); | |
| 204 | - return false; | |
| 205 | - } | |
| 206 | - if ( message['done'] ) { | |
| 207 | - $( '<div class="updated fade"><p><strong>' + message['done'] + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 208 | - } | |
| 209 | - if ( message['error'] ) { | |
| 210 | - $( '<div class="error"><p><strong>' + message['error'] + '</strong></p></div>' ).insertAfter( ".pdfprnt-title" ); | |
| 211 | - button.attr( 'disabled', false ); | |
| 212 | - } | |
| 213 | - } | |
| 214 | - } ); | |
| 215 | - return false; | |
| 216 | - } ); | |
| 217 | - | |
| 218 | - /* add css highlighter*/ | |
| 219 | - if ( $( 'input[name="pdfprnt_use_custom_css"]' ).length ) { | |
| 220 | - var textarea = $( '#pdfprnt_custom_css_code_wrap' ), | |
| 221 | - add_editor = false; | |
| 222 | - if ( textarea.is( ':visible' ) && ! textarea.parents( 'body' ).hasClass( 'rtl' ) && ! add_editor ) { /* excluding .rtl pages because codeMirror doesn`t work properly in case textarea is inside table td */ | |
| 223 | - pdfprnt_add_editor(); | |
| 224 | - add_editor = true; | |
| 225 | - } | |
| 226 | - $( 'input[name="pdfprnt_use_custom_css"]' ).click( function() { | |
| 227 | - if ( $( this ).is( ':checked' ) && ! $( this ).parents( 'body' ).hasClass( 'rtl' ) ) { /* excluding .rtl pages because codeMirror doesn`t work properly in case textarea is inside table td */ | |
| 228 | - textarea.show(); | |
| 229 | - if ( ! add_editor ) { | |
| 230 | - pdfprnt_add_editor(); | |
| 231 | - add_editor = true; | |
| 232 | - } | |
| 233 | - } else if ( $( this ).is( ':checked' ) && $( this ).parents( 'body' ).hasClass( 'rtl' ) ) { /* excluding .rtl pages because codeMirror doesn`t work properly in case textarea is inside table td */ | |
| 234 | - textarea.show(); | |
| 235 | - } else { | |
| 236 | - textarea.hide(); | |
| 237 | - } | |
| 238 | - } ); | |
| 239 | - } | |
| 240 | - | |
| 241 | - /* Custom Fields tab accordion */ | |
| 242 | - $( function() { | |
| 243 | - $( "#pdfprnt-accordion" ).accordion({ | |
| 244 | - heightStyle: "content", | |
| 245 | - collapsible: true | |
| 246 | - }); | |
| 247 | - } ); | |
| 248 | - $( '.pdfprnt-class-delete' ).click( function(){ | |
| 249 | - $( this ).prev().find( 'input' ).val( '' ); | |
| 250 | - }); | |
| 251 | - } ); | |
| 252 | -} )( jQuery ); | |
| 253 | - | |
| 254 | -/* Initialize CSS highlighter */ | |
| 255 | -function pdfprnt_add_editor() { | |
| 256 | - if ( 'function' == typeof wp.CodeMirror || 'function' == typeof CodeMirror ) { | |
| 257 | - var CodeMirrorFunc = ( | |
| 258 | - typeof wp.CodeMirror != 'undefined' | |
| 259 | - ) ? wp.CodeMirror : CodeMirror; | |
| 260 | - var editor = CodeMirrorFunc.fromTextArea( | |
| 261 | - document.getElementById( "pdfprnt_custom_css_code" ), { | |
| 262 | - mode: "css", | |
| 263 | - theme: "default", | |
| 264 | - styleActiveLine: true, | |
| 265 | - matchBrackets: true, | |
| 266 | - lineNumbers: true, | |
| 267 | - lineWrapping: true | |
| 268 | - } | |
| 269 | - ); | |
| 270 | - } | |
| 271 | -} | |
| 1 | +/** | |
| 2 | + * Functionality for settings page | |
| 3 | + */ | |
| 4 | +(function($) { | |
| 5 | + $(document).ready( function() { | |
| 6 | + /** | |
| 7 | + * For responsive design | |
| 8 | + */ | |
| 9 | + pdfprnt_add_labels(); | |
| 10 | + $( window ).resize( function() { | |
| 11 | + pdfprnt_add_labels(); | |
| 12 | + }); | |
| 13 | + /** | |
| 14 | + * Ajax request for load additional fonts | |
| 15 | + */ | |
| 16 | + var input = $( 'input[name="pdfprnt_load_fonts"]' ); | |
| 17 | + input.click( function() { | |
| 18 | + input.attr( 'disabled', true ); | |
| 19 | + $.ajax({ | |
| 20 | + url: ajaxurl, | |
| 21 | + type: "POST", | |
| 22 | + data: { action: 'pdfprnt_load_fonts', pdfprnt_ajax_nonce: pdfprnt_var['ajax_nonce'] }, | |
| 23 | + beforeSend: function() { | |
| 24 | + $( '#pdfprnt_font_loader' ).show(); | |
| 25 | + $( '.updated, .error' ).hide(); | |
| 26 | + $( '<div class="updated fade"><p><strong>' + pdfprnt_var['loading_fonts'] + '.</strong></p></div>' ).insertAfter( ".nav-tab-wrapper" ); | |
| 27 | + /* display 'warning'-window while fonts loading */ | |
| 28 | + window.onbeforeunload = function(e) { | |
| 29 | + if ( $( '#pdfprnt_font_loader' ).is( ':visible' ) ) | |
| 30 | + return true; | |
| 31 | + }; | |
| 32 | + }, | |
| 33 | + success: function( result ) { | |
| 34 | + $( '#pdfprnt_font_loader, .updated, .error' ).hide(); | |
| 35 | + var message = $.parseJSON( result ); | |
| 36 | + if ( message['done'] ) { | |
| 37 | + $( '<div class="updated fade"><p><strong>' + message['done'] + '.</strong></p></div>' ).insertAfter( ".nav-tab-wrapper" ); | |
| 38 | + $( '#pdfprnt_load_fonts_button' ).hide(); | |
| 39 | + } | |
| 40 | + if ( message['error'] ) { | |
| 41 | + $( '<div class="error"><p><strong>' + message['error'] + '.</strong></p></div>' ).insertAfter( ".nav-tab-wrapper" ); | |
| 42 | + input.attr( 'disabled', false ); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + }); | |
| 46 | + return false; | |
| 47 | + }); | |
| 48 | + /** | |
| 49 | + + Display notices | |
| 50 | + */ | |
| 51 | + $( '#pdfprnt_settings_form input, #pdfprnt_settings_form select' ).bind( "change click select", function() { | |
| 52 | + if ( $( this ).attr( 'type' ) != 'submit' ) { | |
| 53 | + $( '.updated.fade, .error' ).hide(); | |
| 54 | + $( '#pdfprnt_settings_notice' ).show(); | |
| 55 | + }; | |
| 56 | + }); | |
| 57 | + }); | |
| 58 | +})(jQuery); | |
| 59 | + | |
| 60 | +/** | |
| 61 | + * Add labels to 'position of buttons'-table on settings page | |
| 62 | + */ | |
| 63 | +function pdfprnt_add_labels() { | |
| 64 | + (function($) { | |
| 65 | + var labels = [], | |
| 66 | + i = 0; | |
| 67 | + if ( $(window).width() <= 785 ) { | |
| 68 | + if ( ! $( '.pdfprnt_label' ).length ) { | |
| 69 | + /* get text of column headers */ | |
| 70 | + $( '.pdfprnt_table_head' ).children().each( function() { | |
| 71 | + labels[i] = $(this).text(); | |
| 72 | + i ++; | |
| 73 | + }); | |
| 74 | + /* add labels */ | |
| 75 | + for ( i = 1; i < 5; i ++ ) { | |
| 76 | + html = '<label class="pdfprnt_label">' + labels[ i - 1 ] +'</label>'; | |
| 77 | + $( '.pdfprnt_pdf_buttton td:nth-child(' + i + '), .pdfprnt_print_buttton td:nth-child(' + i + ')' ).append( html ); | |
| 78 | + $( '.pdfprnt_position_buttton td:nth-child(' + i + ')' ).prepend( html ); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + } | |
| 82 | + })(jQuery); | |
| 83 | +} | |