| 1 |
( function( $ ) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
$( function() { |
| 5 |
|
| 6 |
/* Set all variables to be used in scope */ |
| 7 |
var powerkitFontsMediaFrame; |
| 8 |
|
| 9 |
/* Add Font Link */ |
| 10 |
$( document ).on( 'click', '.upload-font-container .upload-font-link', function( event ) { |
| 11 |
|
| 12 |
event.preventDefault(); |
| 13 |
|
| 14 |
var parentContainer = $( this ).parents( '.upload-font-container' ); |
| 15 |
|
| 16 |
// Options. |
| 17 |
var options = { |
| 18 |
title: powerkitFonts.title, |
| 19 |
button: { |
| 20 |
text: powerkitFonts.button, |
| 21 |
}, |
| 22 |
library: { |
| 23 |
type: parentContainer.data( 'type' ) |
| 24 |
}, |
| 25 |
multiple: false |
| 26 |
}; |
| 27 |
|
| 28 |
powerkitFontsMediaFrame = wp.media( options ); |
| 29 |
|
| 30 |
// When an image is selected in the media frame... |
| 31 |
powerkitFontsMediaFrame.on( 'select', function() { |
| 32 |
|
| 33 |
// Get media attachment details from the frame state. |
| 34 |
var attachment = powerkitFontsMediaFrame.state().get( 'selection' ).first().toJSON(); |
| 35 |
|
| 36 |
parentContainer.find( '.filename' ).val( attachment.filename ).change(); |
| 37 |
parentContainer.find( '.uploaded-font-id' ).val( attachment.id ).change(); |
| 38 |
parentContainer.find( '.upload-font-link' ).addClass( 'hidden' ); |
| 39 |
parentContainer.find( '.delete-font-link' ).removeClass( 'hidden' ); |
| 40 |
|
| 41 |
powerkitFontsMediaFrame.close(); |
| 42 |
} ); |
| 43 |
|
| 44 |
powerkitFontsMediaFrame.open(); |
| 45 |
} ); |
| 46 |
|
| 47 |
|
| 48 |
/* Delete Font Link */ |
| 49 |
$( document ).on( 'click', '.upload-font-container .delete-font-link', function( event ) { |
| 50 |
event.preventDefault(); |
| 51 |
|
| 52 |
var parentContainer = $( this ).parents( '.upload-font-container' ); |
| 53 |
parentContainer.find( '.filename' ).val( '' ).change(); |
| 54 |
parentContainer.find( '.uploaded-font-id' ).val( '' ).change(); |
| 55 |
parentContainer.find( '.upload-font-link' ).removeClass( 'hidden' ); |
| 56 |
parentContainer.find( '.delete-font-link' ).addClass( 'hidden' ); |
| 57 |
} ); |
| 58 |
|
| 59 |
/* Delete alert */ |
| 60 |
$( document ).on( 'click', '.powerkit-fonts-delete', function( event ) { |
| 61 |
return confirm( powerkitFonts.delete ) ? true : false; |
| 62 |
} ); |
| 63 |
|
| 64 |
/* View code */ |
| 65 |
$( document ).find( '.powerkit-fonts-view-code' ).each( function( index, el ) { |
| 66 |
|
| 67 |
var obj = $( el ).closest( 'tr' ).next(); |
| 68 |
|
| 69 |
// Reset td padding. |
| 70 |
$( obj ).find( 'td' ).css( 'padding', 0 ); |
| 71 |
|
| 72 |
// Show tr. |
| 73 |
$( obj ).removeClass( 'hidden' ); |
| 74 |
|
| 75 |
// Set height textarea. |
| 76 |
$( obj ).find( 'textarea' ).css( 'min-height', '110px' ).height( 110 ); |
| 77 |
} ); |
| 78 |
|
| 79 |
/* View code slide toggle */ |
| 80 |
$( document ).on( 'click', '.powerkit-fonts-view-code', function( event ) { |
| 81 |
|
| 82 |
$( this ).closest( 'tr' ).prevAll().find( '.template-box' ).slideUp(); |
| 83 |
$( this ).closest( 'tr' ).next().nextAll().find( '.template-box' ).slideUp(); |
| 84 |
|
| 85 |
$( this ).closest( 'tr' ).next().find( '.template-box' ).slideToggle(); |
| 86 |
|
| 87 |
return false; |
| 88 |
} ); |
| 89 |
|
| 90 |
/* View code outside */ |
| 91 |
$( document ).on( 'click', function( event ) { |
| 92 |
|
| 93 |
if ( !$( event.target ).closest( '.wp-list-table' ).length ) { |
| 94 |
|
| 95 |
$( '.template-box' ).slideUp(); |
| 96 |
} |
| 97 |
} ); |
| 98 |
|
| 99 |
} ); |
| 100 |
|
| 101 |
} )( jQuery ); |