| 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 |
} |
| 84 |
|