PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.8.6
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.8.6
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 1.8.6, at js/script.js

109 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 try {
36 var message = $.parseJSON( result );
37 } catch ( e ) {
38 $( '<div class="error"><p><strong>' + result + pdfprnt_var['need_reload'] + '.</strong></p></div>' ).insertAfter( ".nav-tab-wrapper" );
39 input.attr( 'disabled', false );
40 return false;
41 }
42 if ( message['done'] ) {
43 $( '<div class="updated fade"><p><strong>' + message['done'] + '.</strong></p></div>' ).insertAfter( ".nav-tab-wrapper" );
44 $( '#pdfprnt_load_fonts_button' ).hide();
45 }
46 if ( message['error'] ) {
47 $( '<div class="error"><p><strong>' + message['error'] + pdfprnt_var['need_reload'] + '.</strong></p></div>' ).insertAfter( ".nav-tab-wrapper" );
48 input.attr( 'disabled', false );
49 }
50 }
51 });
52 return false;
53 });
54
55 if ( $( 'input[name="pdfprnt_use_custom_styles"]' ).length ) {
56 var textarea = $( '.pdfprnt_custom_styles' ),
57 add_editor = false;
58 if ( textarea.is( ':visible' ) && ! add_editor ) {
59 pdfprnt_add_editor();
60 add_editor = true;
61 }
62 $( 'input[name="pdfprnt_use_custom_styles"]' ).click( function() {
63 if ( $( this ).is( ':checked' ) ) {
64 textarea.show();
65 if ( ! add_editor ) {
66 pdfprnt_add_editor();
67 add_editor = true;
68 }
69 } else
70 textarea.hide();
71 });
72 }
73 });
74 })(jQuery);
75
76 /**
77 * Add labels to 'position of buttons'-table on settings page
78 */
79 function pdfprnt_add_labels() {
80 (function($) {
81 var labels = [],
82 i = 0;
83 if ( $(window).width() <= 785 ) {
84 if ( ! $( '.pdfprnt_label' ).length ) {
85 /* get text of column headers */
86 $( '.pdfprnt_table_head' ).children().each( function() {
87 labels[i] = $(this).text();
88 i ++;
89 });
90 /* add labels */
91 for ( i = 1; i < 5; i ++ ) {
92 html = '<label class="pdfprnt_label">' + labels[ i - 1 ] +'</label>';
93 $( '.pdfprnt_pdf_buttton td:nth-child(' + i + '), .pdfprnt_print_buttton td:nth-child(' + i + ')' ).append( html );
94 $( '.pdfprnt_position_buttton td:nth-child(' + i + ')' ).prepend( html );
95 }
96 }
97 }
98 })(jQuery);
99 }
100
101 /**
102 * Initialize CSS highlighter
103 */
104 function pdfprnt_add_editor() {
105 var editor = CodeMirror.fromTextArea(
106 document.getElementById( "pdfprnt_custom_styles" ),
107 { lineNumbers: true, mode: "text/css" }
108 );
109 }