PluginProbe
Powerkit – Supercharge your WordPress Site / 2.9.0
Powerkit – Supercharge your WordPress Site v2.9.0
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / post-format-ui / admin / js / admin-powerkit-post-format-ui.js

admin-powerkit-post-format-ui.js in Powerkit – Supercharge your WordPress Site 2.9.0, at modules/post-format-ui/admin/js/admin-powerkit-post-format-ui.js

243 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 ( function( $ ) {
4
5 /*
6 * Post Format UI
7 */
8 $( function() {
9
10 /*
11 * Post Format Switcher
12 */
13 $( document ).on( 'click change', '.post-format, .editor-post-format select', function( event ) {
14 $( '.postbox[id*=powerkit-post-format]' ).hide();
15 $( '.postbox[id=powerkit-post-format-' + $( this ).val() + ']' ).show();
16 });
17
18 /*
19 * Media ( Audio / Video ) ------------------------------------------------------------------------
20 */
21
22 /*
23 * Media Placeholder
24 */
25 $( document ).on( 'keyup', '.pk-post-format-media .search-input', function( event ){
26
27 var canvas = $( this ).closest( '.pk-post-format-media' ).find( '.canvas' );
28
29 $( canvas ).addClass( 'load' ).html( '<span class="spinner is-active"></span>' );
30
31 jQuery.post( powerkit_post_format_ui.url, {
32 url: $( this ).val(),
33 nonce: powerkit_post_format_ui.nonce,
34 action: 'pk_media_oembed'
35 }, function( response ) {
36 $( canvas ).removeClass( 'load' ).html( response );
37 });
38
39 return false;
40 });
41
42 /*
43 * Gallery ----------------------------------------------------------------------------------
44 */
45
46 /*
47 * Gallery Ids Helper
48 */
49 function powerkitUIGalleryIds( action, id ) {
50 var obj = $( '.pk-post-format-gallery-settings' );
51 var ids = $( obj ).val().split( ',' );
52
53 switch ( action ) {
54 case 'add':
55 ids.push( id.toString() );
56 break;
57 case 'delete':
58 delete ids.splice( ids.indexOf( id.toString() ), 1 );
59 break;
60 default:
61 return ids;
62 break;
63 }
64
65 $( obj ).val( ids.join( ',' ) );
66
67 return ids;
68 }
69
70 /*
71 * Gallery Modal
72 */
73 var powerkitUIGalleryModal = function(){
74
75 /*
76 * Create a new media frame
77 */
78 var galleryModal = wp.media( {
79 title: $( '.pk-post-format-gallery-settings' ).data( 'title' ),
80 button: {
81 text: $( '.pk-post-format-gallery-settings' ).data( 'button' ),
82 },
83 library : { type : 'image' },
84 multiple: true
85 } );
86
87 // When an image is selected in the media frame...
88 galleryModal.on( 'select', function() {
89 var attachments = galleryModal.state().get('selection').toJSON();
90
91 for ( var prop in attachments ) {
92 if ( typeof attachments[prop].id == 'undefined' ) {
93 continue;
94 }
95
96 var attachment_id = attachments[prop].id;
97 var attachment_src = attachments[prop].url;
98
99 // Check selected.
100 if( typeof attachments[prop].selected != 'undefined' ) {
101 continue;
102 }
103
104 // Set thumbnail src.
105 if ( typeof attachments[prop].sizes.thumbnail != 'undefined' ) {
106 attachment_src = attachments[prop].sizes.thumbnail.url;
107 }
108
109 // Add id to selected.
110 powerkitUIGalleryIds( 'add', attachment_id );
111
112 // Add attachment.
113 var attachment = $( '<div class="pk-post-format-gallery-attachment"></div>' ).appendTo( '.pk-post-format-gallery-attachments' );
114
115 $( attachment ).attr( 'data-id', attachment_id );
116 $( attachment ).append( '<input name="pk-post-format-gallery[]" type="hidden">' );
117 $( attachment ).find( 'input' ).attr( 'value', attachment_id );
118 $( attachment ).append( '<div class="thumbnail"><img></div>' );
119 $( attachment ).find( 'img' ).attr( 'src', attachment_src );
120 $( attachment ).append( '<div class="actions"><a href="#" class="pk-post-format-gallery-remove"></div>' );
121 $( attachment ).find( '.actions a' ).attr( 'data-id', attachment_id );
122 }
123
124 galleryModal.close();
125 });
126
127
128 /*
129 * Library handler
130 */
131 var galleryLibrary = wp.media.view.Attachment.Library;
132
133 wp.media.view.Attachment.Library = galleryLibrary.extend({
134 render: function() {
135
136 // vars
137 var selected = powerkitUIGalleryIds();
138 var id = this.model.attributes.id;
139
140 // select
141 if( selected && id && selected.indexOf( id.toString() ) > -1 ) {
142 this.model.attributes.selected = true;
143 this.$el.addClass( 'pk-post-format-selected' );
144 }
145
146 return galleryLibrary.prototype.render.apply( this, arguments );
147 }
148 });
149
150 /*
151 * Open modal.
152 */
153 galleryModal.open();
154 }
155
156 /*
157 * Gallery Sortable
158 */
159 $( '.pk-post-format-gallery-attachments' ).sortable({
160 placeholder: 'pk-post-format-highlight'
161 });
162 $( '.pk-post-format-gallery-attachments' ).disableSelection();
163
164 /*
165 * Gallery Modal Open
166 */
167 $( document ).on( 'click', '.pk-post-format-gallery-add', function( event ){
168 powerkitUIGalleryModal();
169
170 return false;
171 });
172
173 /*
174 * Gallery Remove Attachment
175 */
176 $( document ).on( 'click', '.pk-post-format-gallery-remove', function( event ){
177 var id = $( this ).data( 'id' );
178
179 $( this ).closest( '.pk-post-format-gallery-attachment' ).remove();
180
181 powerkitUIGalleryIds( 'delete', id );
182
183 return false;
184 });
185
186 /*
187 * Gallery Open Info
188 */
189 $( document ).on( 'click', '.pk-post-format-gallery-attachment', function( event ){
190 if ( 'none' === $( '.pk-post-format-gallery-side-inner' ).css( 'display' ) ) {
191 $( '.pk-post-format-gallery-side-inner' ).animate( { width: 'toggle' } );
192 }
193
194 // Get Ajax.
195 jQuery.post( powerkit_post_format_ui.url, {
196 id: $( this ).data( 'id' ),
197 nonce: powerkit_post_format_ui.nonce,
198 action: 'pk_gallery_attachment'
199 }, function( response ) {
200 $( '.pk-post-format-gallery-side-data' ).html( response );
201 });
202
203 $( this ).siblings().removeClass( 'pk-post-format-selected' );
204 $( this ).addClass( 'pk-post-format-selected' ).parent().addClass( 'pk-post-format-open' );
205
206 return false;
207 });
208
209 /*
210 * Gallery Update Info
211 */
212 $( document ).on( 'click', '.pk-post-format-gallery-update', function( event ){
213 var data = $( '.pk-post-format-gallery-side-data' ).find( ':input' ).serialize();
214
215 // Update Ajax.
216 $( '.pk-post-format-gallery-side-toolbar .spinner' ).addClass( 'is-active' );
217
218 jQuery.post( powerkit_post_format_ui.url, data, function( response ) {
219 $( '.pk-post-format-gallery-side-toolbar .spinner' ).removeClass( 'is-active' );
220 });
221
222 return false;
223 });
224
225 /*
226 * Gallery Close Info
227 */
228 $( document ).on( 'click', '.pk-post-format-gallery-close', function( event ){
229 if ( 'none' !== $( '.pk-post-format-gallery-side-inner' ).css( 'display' ) ) {
230 $( '.pk-post-format-gallery-side-inner' ).animate( { width: 'toggle' } );
231 }
232
233 $( '.pk-post-format-gallery-side-data' ).html( '<span class="spinner"></span>' );
234
235 $( '*' ).removeClass( 'pk-post-format-open pk-post-format-selected' );
236
237 return false;
238 });
239
240 } );
241
242 } )( jQuery );
243