-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmedia-upload-popup.js
136 lines (119 loc) · 4.18 KB
/
media-upload-popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var TaxonomyImagesCreateAssociation;
jQuery( document ).ready( function( $ ) {
var ID = 0, below;
/* Get window that opened the thickbox. */
below = window.dialogArguments || opener || parent || top;
if ( null !== below && 'taxonomyImagesPlugin' in below ) {
/* Set the value of ID. */
if ( 'tt_id' in below.taxonomyImagesPlugin ) {
ID = parseInt( below.taxonomyImagesPlugin.tt_id );
if ( isNaN( ID ) ) {
ID = 0;
}
}
/* Replace term name. */
if ( 'term_name' in below.taxonomyImagesPlugin ) {
$( '.create-association .term-name' ).html( TaxonomyImagesModal.termBefore + below.taxonomyImagesPlugin.term_name + TaxonomyImagesModal.termAfter );
}
}
if ( 0 < ID ) {
$( 'body' ).addClass( 'taxonomy-images-modal' );
var buttons = $( '.taxonomy-images-modal .create-association' );
/* Add hidden input to search form. */
$( '#filter' ).prepend( '<input type="hidden" name="taxonomy_images_plugin" value="' + ID + '" />' );
if ( 'image_id' in below.taxonomyImagesPlugin ) {
buttons.each( function( i, e ) {
var image_id = $( e ).parent().find( '.taxonomy-image-button-image-id' ).val();
if ( image_id == below.taxonomyImagesPlugin.image_id ) {
$( e ).hide();
$( e ).parent().find( '.remove-association' ).css( 'display', 'inline' );
}
} );
}
}
$( '.taxonomy-images-modal' ).on( 'click', '.remove-association', function () {
var button = $( this );
originalText = button.html();
button.html( TaxonomyImagesModal.removing );
$.ajax( {
url: ajaxurl,
type: "POST",
dataType: 'json',
data: {
'action' : 'taxonomy_image_plugin_remove_association',
'wp_nonce' : $( this ).parent().find( '.taxonomy-image-button-nonce-remove' ).val(),
'tt_id' : ID
},
cache: false,
success: function ( response ) {
if ( 'good' === response.status ) {
button.html( TaxonomyImagesModal.removed ).fadeOut( 200, function() {
$( this ).hide();
var selector = parent.document.getElementById( 'taxonomy_image_plugin_' + ID );
$( selector ).attr( 'src', below.taxonomyImagesPlugin.img_src );
$( this ).parent().find( '.create-association' ).show();
$( this ).html( originalText );
} );
}
else if ( 'bad' === response.status ) {
alert( response.why );
}
}
} );
return false;
} );
$( '.taxonomy-images-modal' ).on( 'click', '.create-association', function () {
var button, selector, originalText;
if ( 0 == ID ) {
return;
}
button = $( this );
originalText = button.html();
button.html( TaxonomyImagesModal.associating );
$.ajax( {
url : ajaxurl,
type : "POST",
dataType : 'json',
data: {
'action' : 'taxonomy_image_create_association',
'wp_nonce' : $( this ).parent().find( '.taxonomy-image-button-nonce-create' ).val(),
'attachment_id' : $( this ).parent().find( '.taxonomy-image-button-image-id' ).val(),
'tt_id' : parseInt( ID )
},
success: function ( response ) {
if ( 'good' === response.status ) {
var parent_id = button.parent().attr( 'id' );
/* Set state of all other buttons. */
$( '.taxonomy-image-modal-control' ).each( function( i, e ) {
if ( parent_id == $( e ).attr( 'id' ) ) {
return true;
}
$( e ).find( '.create-association' ).show();
$( e ).find( '.remove-association' ).hide();
} );
selector = parent.document.getElementById( 'taxonomy-image-control-' + ID );
/* Update the image on the screen below */
$( selector ).find( '.taxonomy-image-thumbnail img' ).each( function ( i, e ) {
$( e ).attr( 'src', response.attachment_thumb_src );
} );
/* Show delete control on the screen below */
$( selector ).find( '.remove' ).each( function ( i, e ) {
$( e ).removeClass( 'hide' );
} );
button.show().html( TaxonomyImagesModal.success ).fadeOut( 200, function() {
var remove = button.parent().find( '.remove-association' );
if ( undefined !== remove[0] ) {
$( remove ).css( 'display', 'inline' );
button.hide();
button.html( originalText );
}
} );
}
else if ( 'bad' === response.status ) {
alert( response.why );
}
}
} );
return false;
} );
} );