PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 2.4.1
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v2.4.1
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / js / script.js

script.js in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 2.4.1, at js/script.js

269 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 } );
249 } )( jQuery );
250
251 /* Initialize CSS highlighter */
252 function pdfprnt_add_editor() {
253 if ( 'function' == typeof wp.CodeMirror || 'function' == typeof CodeMirror ) {
254 var CodeMirrorFunc = (
255 typeof wp.CodeMirror != 'undefined'
256 ) ? wp.CodeMirror : CodeMirror;
257 var editor = CodeMirrorFunc.fromTextArea(
258 document.getElementById( "pdfprnt_custom_css_code" ), {
259 mode: "css",
260 theme: "default",
261 styleActiveLine: true,
262 matchBrackets: true,
263 lineNumbers: true,
264 lineWrapping: true
265 }
266 );
267 }
268 }
269