| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * Display the media uploader. |
| 6 | 6 | * |
| 7 | 7 | * @since 1.0.0 |
| 8 | 8 | */ |
| 9 | - function ayg_render_media_uploader( $elem ) { | |
| 9 | + function ayg_render_media_uploader( $elem ) { | |
| 10 | 10 | var file_frame, attachment; |
| 11 | 11 | |
| 12 | 12 | // If an instance of file_frame already exists, then we can open it rather than creating a new instance |
| 13 | 13 | if ( file_frame ) { |
| @@ -41,18 +41,8 @@ | ||
| 41 | 41 | file_frame.open(); |
| 42 | 42 | }; |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | - * Close the popup. | |
| 46 | - * | |
| 47 | - * @since 1.0.0 | |
| 48 | - */ | |
| 49 | - function ayg_modal_hide() { | |
| 50 | - $( '.ayg-modal' ).hide(); | |
| 51 | - $( 'html' ).removeClass( 'ayg-no-scroll' ); | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | 45 | * Get Youtube playlist ID from Youtube URL. |
| 56 | 46 | * |
| 57 | 47 | * @since 1.0.0 |
| 58 | 48 | * @param {string} url - URL from which to extract the ID. |
| @@ -133,8 +123,19 @@ | ||
| 133 | 123 | * |
| 134 | 124 | * @since 1.0.0 |
| 135 | 125 | */ |
| 136 | 126 | $(function() { |
| 127 | + // Common: Initialize the color picker | |
| 128 | + $( '.ayg-color-picker' ).wpColorPicker(); | |
| 129 | + | |
| 130 | + // Common: Init the popup. | |
| 131 | + if ( $.fn.magnificPopup ) { | |
| 132 | + $( '.ayg-modal-button' ).magnificPopup({ | |
| 133 | + type: 'inline', | |
| 134 | + mainClass: 'mfp-fade' | |
| 135 | + }); | |
| 136 | + } | |
| 137 | + | |
| 137 | 138 | // Dashboard: Save API Key |
| 138 | 139 | $( '#ayg-button-save-api-key' ).on( 'click', function( e ) { |
| 139 | 140 | e.preventDefault(); |
| 140 | 141 | |
| @@ -164,9 +165,11 @@ | ||
| 164 | 165 | e.preventDefault(); |
| 165 | 166 | |
| 166 | 167 | // Attributes |
| 167 | 168 | var props = {}; |
| 169 | + var popup = 0; | |
| 168 | 170 | |
| 171 | + // Loop through all editor fields | |
| 169 | 172 | $( '.ayg-editor-control', '#ayg-shortcode-builder' ).each(function() { |
| 170 | 173 | var $elem = $( this ).find( '.ayg-editor-field' ); |
| 171 | 174 | var type = $elem.attr( 'type' ); |
| 172 | 175 | var key = $elem.attr( 'name' ); |
| @@ -172,8 +175,14 @@ | ||
| 172 | 175 | var key = $elem.attr( 'name' ); |
| 173 | 176 | var value = $elem.val(); |
| 174 | 177 | var def = $elem.data( 'default' ); |
| 175 | 178 | |
| 179 | + // Skip popup field | |
| 180 | + if ( 'popup' == key ) { | |
| 181 | + popup = $elem.is( ':checked' ) ? 1 : 0; | |
| 182 | + return true; // continue | |
| 183 | + } | |
| 184 | + | |
| 176 | 185 | // field type = checkbox |
| 177 | 186 | if ( 'checkbox' == type ) { |
| 178 | 187 | value = $elem.is( ':checked' ) ? 1 : 0; |
| 179 | 188 | } |
| @@ -217,9 +226,16 @@ | ||
| 217 | 226 | props[ key ] = value; |
| 218 | 227 | } |
| 219 | 228 | }); |
| 220 | 229 | |
| 230 | + // If popup is enabled and type is video, force theme to popup | |
| 231 | + if ( popup && props.hasOwnProperty( 'type' ) && 'video' == props.type ) { | |
| 232 | + props.theme = 'popup'; | |
| 233 | + } | |
| 234 | + | |
| 235 | + // Build attributes string | |
| 221 | 236 | var attrs = ''; |
| 237 | + | |
| 222 | 238 | for ( var key in props ) { |
| 223 | 239 | if ( props.hasOwnProperty( key ) ) { |
| 224 | 240 | attrs += ( ' ' + key + '="' + props[ key ] + '"' ); |
| 225 | 241 | } |
| @@ -226,26 +242,10 @@ | ||
| 226 | 242 | } |
| 227 | 243 | |
| 228 | 244 | // Shortcode output |
| 229 | 245 | $( '#aiovg-shortcode').val( '[automatic_youtube_gallery' + attrs + ']' ); |
| 230 | - | |
| 231 | - // Initialize the popup | |
| 232 | - $( 'html' ).addClass( 'ayg-no-scroll' ); | |
| 233 | - $( '#ayg-shortcode-modal' ).show(); | |
| 234 | 246 | }); |
| 235 | 247 | |
| 236 | - // Dashboard: Close the shortcode builder popup | |
| 237 | - $( '.ayg-modal-close' ).on( 'click', function( e ) { | |
| 238 | - e.preventDefault(); | |
| 239 | - ayg_modal_hide(); | |
| 240 | - }); | |
| 241 | - | |
| 242 | - $( '.ayg-modal-content' ).on( 'click', function( e ) { | |
| 243 | - if ( $( e.target ).hasClass( 'ayg-modal-content' ) ) { | |
| 244 | - ayg_modal_hide(); | |
| 245 | - }; | |
| 246 | - }); | |
| 247 | - | |
| 248 | 248 | // Editor: Toggle between field sections |
| 249 | 249 | $( document ).on( 'click', '.ayg-editor-section-header', function( e ) { |
| 250 | 250 | var $elem = $( this ).parent(); |
| 251 | 251 | |
| @@ -261,48 +261,58 @@ | ||
| 261 | 261 | .find( '.ayg-editor-controls' ) |
| 262 | 262 | .slideToggle(); |
| 263 | 263 | }); |
| 264 | 264 | |
| 265 | - // Editor: Show/Hide fields based on the selected source 'type' | |
| 266 | - $( document ).on( 'change', '.ayg-editor-field-type', function( e ) { | |
| 267 | - var type = $( this ).val(); | |
| 268 | - var $elem = $( this ).closest( '.ayg-editor' ); | |
| 265 | + // Editor: Toggle fields based on the source type | |
| 266 | + $( document ).on( 'change', '.ayg-editor-field-type', function() { | |
| 267 | + var $container = $( this ).closest( '.ayg-editor' ); | |
| 268 | + var value = $( this ).val(); | |
| 269 | 269 | |
| 270 | - $elem.removeClass(function( index, classes ) { | |
| 270 | + $container.removeClass(function( index, classes ) { | |
| 271 | 271 | var matches = classes.match( /\ayg-editor-field-type-\S+/ig ); |
| 272 | - return ( matches ) ? matches.join(' ') : ''; | |
| 272 | + return ( matches ) ? matches.join( ' ' ) : ''; | |
| 273 | 273 | }); |
| 274 | 274 | |
| 275 | - $elem.addClass( 'ayg-editor-field-type-' + type ); | |
| 275 | + $container.addClass( 'ayg-editor-field-type-' + value ); | |
| 276 | 276 | }); |
| 277 | 277 | |
| 278 | - // Editor: Show/Hide fields based on the selected theme | |
| 279 | - $( document ).on( 'change', '.ayg-editor-field-theme', function( e ) { | |
| 280 | - var theme = $( this ).val(); | |
| 281 | - var $elem = $( this ).closest( '.ayg-editor' ); | |
| 278 | + // Editor: Toggle fields based on the theme | |
| 279 | + $( document ).on( 'change', '.ayg-editor-field-theme', function() { | |
| 280 | + var $container = $( this ).closest( '.ayg-editor' ); | |
| 281 | + var value = $( this ).val(); | |
| 282 | 282 | |
| 283 | - $elem.removeClass(function( index, classes ) { | |
| 283 | + $container.removeClass(function( index, classes ) { | |
| 284 | 284 | var matches = classes.match( /\ayg-editor-field-theme-\S+/ig ); |
| 285 | - return ( matches ) ? matches.join(' ') : ''; | |
| 285 | + return ( matches ) ? matches.join( ' ' ) : ''; | |
| 286 | 286 | }); |
| 287 | 287 | |
| 288 | - $elem.addClass( 'ayg-editor-field-theme-' + theme ); | |
| 288 | + $container.addClass( 'ayg-editor-field-theme-' + value ); | |
| 289 | 289 | }); |
| 290 | 290 | |
| 291 | - // Settings: Initialize the color picker | |
| 292 | - $( '.ayg-color-picker', '#ayg-settings' ).wpColorPicker(); | |
| 291 | + // Settings: Toggle fields based on the theme | |
| 292 | + $( 'tr.theme select', '#ayg-settings' ).on( 'change', function() { | |
| 293 | + var $container = $( '#ayg-settings' ); | |
| 294 | + var value = $( this ).val(); | |
| 293 | 295 | |
| 294 | - // Settings: Show/Hide fields based on the selected theme | |
| 295 | - $( 'tr.theme', '#ayg-settings' ).find( 'select' ).on( 'change', function() { | |
| 296 | - var theme = $( this ).val(); | |
| 297 | - var $elem = $( '#ayg-settings' ); | |
| 296 | + $container.removeClass(function( index, classes ) { | |
| 297 | + var matches = classes.match( /theme-\S+/ig ); | |
| 298 | + return ( matches ) ? matches.join( ' ' ) : ''; | |
| 299 | + }); | |
| 298 | 300 | |
| 299 | - $elem.removeClass(function( index, classes ) { | |
| 300 | - var matches = classes.match( /\ayg-settings-theme-\S+/ig ); | |
| 301 | - return ( matches ) ? matches.join(' ') : ''; | |
| 301 | + $container.addClass( 'theme-' + value ); | |
| 302 | + }); | |
| 303 | + | |
| 304 | + // Settings: Toggle fields based on the player type | |
| 305 | + $( 'tr.player_type input[type="radio"]', '#ayg-settings' ).on( 'change', function() { | |
| 306 | + var $container = $( '#ayg-settings' ); | |
| 307 | + var value = $container.find( 'tr.player_type input[type="radio"]:checked' ).val(); | |
| 308 | + | |
| 309 | + $container.removeClass(function( index, classes ) { | |
| 310 | + var matches = classes.match( /player_type-\S+/ig ); | |
| 311 | + return ( matches ) ? matches.join( ' ' ) : ''; | |
| 302 | 312 | }); |
| 303 | 313 | |
| 304 | - $elem.addClass( 'ayg-settings-theme-' + theme ); | |
| 314 | + $container.addClass( 'player_type-' + value ); | |
| 305 | 315 | }); |
| 306 | 316 | |
| 307 | 317 | // Settings: Browse button |
| 308 | 318 | $( '.ayg-settings-browse' ).on( 'click', function( e ) { |
| @@ -333,47 +343,7 @@ | ||
| 333 | 343 | ayg_widget_color_picker( $( this ) ); |
| 334 | 344 | }); |
| 335 | 345 | |
| 336 | 346 | $( document ).on( 'widget-added widget-updated', on_ayg_widget_update ); |
| 337 | - | |
| 338 | - // Gutenberg: Toggle fields or panels based on the selected source type | |
| 339 | - if ( 'undefined' !== typeof wp && 'undefined' !== typeof wp['hooks'] ) { | |
| 340 | - wp.hooks.addFilter( 'ayg_block_toggle_controls', 'automatic-youtube-gallery/block', function( value, control, attributes ) { | |
| 341 | - switch ( control ) { | |
| 342 | - case 'channel': | |
| 343 | - if ( 'livestream' == attributes.type ) { | |
| 344 | - value = true; | |
| 345 | - } | |
| 346 | - break; | |
| 347 | - case 'cache': | |
| 348 | - case 'player_title': | |
| 349 | - case 'player_description': | |
| 350 | - case 'loop': | |
| 351 | - if ( 'livestream' == attributes.type ) { | |
| 352 | - value = false; | |
| 353 | - } | |
| 354 | - break; | |
| 355 | - case 'autoadvance': | |
| 356 | - if ( 'video' == attributes.type || 'livestream' == attributes.type ) { | |
| 357 | - value = false; | |
| 358 | - } | |
| 359 | - break; | |
| 360 | - } | |
| 361 | - | |
| 362 | - return value; | |
| 363 | - }); | |
| 364 | - | |
| 365 | - wp.hooks.addFilter( 'ayg_block_toggle_panels', 'automatic-youtube-gallery/block', function( value, panel, attributes ) { | |
| 366 | - switch ( panel ) { | |
| 367 | - case 'gallery': | |
| 368 | - if ( 'livestream' == attributes.type ) { | |
| 369 | - value = false; | |
| 370 | - } | |
| 371 | - break; | |
| 372 | - } | |
| 373 | - | |
| 374 | - return value; | |
| 375 | - }); | |
| 376 | - } | |
| 377 | 347 | }); |
| 378 | 348 | |
| 379 | 349 | })( jQuery ); |