/** * File meta-box script. * * Theme Post/Page Meta Box enhancements for a better user experience. * * @package Business_Aarambha */ ( function( $ ) { "use strict"; // Welcome Page Tabs $('ul.metabox-tab-nav li').on( 'click', function (e) { window.localStorage.setItem('active_metabox_tab', $(e.target).data('tab')); let tab_id = $(this).data('tab'); $('ul.metabox-tab-nav li').removeClass('active'); $('.setting-tab').removeClass('active'); $(this).addClass('active'); $("#" + tab_id).addClass('active'); }); // Store tab data value in local storage let active_metabox_tab = window.localStorage.getItem('active_metabox_tab'); // Add Active Class in both tab and content with browser refresh if (active_metabox_tab) { $('ul.metabox-tab-nav li').removeClass('active'); $('.setting-tab').removeClass('active'); $('ul.metabox-tab-nav li[data-tab="'+active_metabox_tab+'"]').addClass('active'); $("#"+active_metabox_tab).addClass('active'); localStorage.removeItem('active_metabox_tab'); } else { $('ul.metabox-tab-nav li[data-tab="setting-tab-1"]').addClass('active'); $("#setting-tab-1").addClass('active'); } // New Media Uploader $( document.body ).on( 'click', '.custom_media_upload', function( event ) { var $el = $( this ); var $media_type = $el.data( 'multimedia' ); // Image Uploader var file_frame; var file_target_input = $el.parent().find( '.custom_media_input' ).val(); var file_target_preview = $el.parent().find( '.custom_media_preview' ); event.preventDefault(); // Create the media frame. file_frame = wp.media.frames.media_file = wp.media({ // Set the title of the modal. title: $el.data( 'choose' ), button: { text: $el.data( 'update' ) }, states: [ new wp.media.controller.Library({ title: $el.data( 'choose' ), library: wp.media.query({ type: 'image' }), multiple: $media_type }) ] }); if ( $media_type === true ) { // For Gallery // When an image is selected, run a callback. file_frame.on( 'select', function() { // Get the attachment from the modal frame. var selection = file_frame.state().get('selection'); selection.map( function( attachment ) { attachment = attachment.toJSON(); if ( attachment.id ) { file_target_input = file_target_input ? file_target_input + "," + attachment.id : attachment.id; file_target_preview.append('\