/** * Upload Option * Allows window.send_to_editor to function properly using a private post_id * Dependencies: $, Media Upload, Thickbox * Credits: OptionTree **/ jQuery(document).ready(function( $ ) { //Theme loader var ajaxloader = ''; //Function to refresh select2 on every ajax request function alanah_select2() { //Apply select2 on google fonts if( $( '.alanah_fonts' ).length ) { $( '.alanah_fonts', '.alanah_fonts_style', '.alanah_fonts_weight' ).select2( 'destroy' ); $( '.alanah_fonts' ).select2(); $( '.alanah_fonts_style', '.alanah_fonts_weight' ).select2( { minimumResultsForSearch: -1 } ); //$( '.alanah_fonts_weight' ).select2( { minimumResultsForSearch: -1 } ); } } $( '.upload_button' ).on( 'click', function( e ) { e.preventDefault(); var SELF = $(this); var formfield = SELF.closest( '.inline-element' ).find( '.upload' ); var formID = SELF.attr( 'rel' ); var btnContent = true; //Open Media Manager if already defined var image_frame; if(image_frame){ image_frame.open(); } //Define media manager if not // Define image_frame as wp.media object image_frame = wp.media({ title: ctadmin_text.media, multiple : false, library : { type : 'image', } }); image_frame.on('close',function() { // On close, get selections and save to the hidden input // plus other AJAX stuff to refresh the image preview var attachment = image_frame.state().get('selection').first().toJSON(); var itemurl = attachment.url; var itemid = attachment.id; var image = /(^.*\.jpg|jpeg|png|gif|ico*)/gi; var document = /(^.*\.pdf|doc|docx|ppt|pptx|odt*)/gi; var audio = /(^.*\.mp3|m4a|ogg|wav*)/gi; var video = /(^.*\.mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2*)/gi; if ( itemurl.match( image ) ) { var imghtml = ''; if( $( formfield ).closest( '.sizeguide' ).length ) imghtml = 'width="220"'; btnContent = ''; } else { btnContent = '
'+html+'
'; } formfield.val(itemurl); if( SELF.closest( '.inline-element' ).find( '.uploadid' ).length ) { SELF.closest( '.inline-element' ).find( '.uploadid' ).val( itemid ); } if( $( formfield ).closest( '.singleproduct' ).length ) { //Reset Remove and Instruction SELF.closest( '.singleproduct' ).find( '.howto' ).remove(); SELF.closest( '.singleproduct' ).find( '.removep' ).remove(); SELF.html( '' ); SELF.closest( 'p' ).after( '

'+ctadmin_text.clickimg+'

' ); SELF.closest( 'p' ).next( 'p' ).after( '

'+ctadmin_text.remove+'

' ); } else { formfield.prev('div').slideDown().html(btnContent); } }); image_frame.open(); }); $( '.postbox .inline-element' ).on( 'click', '.remove', function( e ) { e.preventDefault(); var _self = $(this); if( _self.closest( '.singleproduct' ).length ) { _self.closest( '.inline-element' ).find( '.upload' ).val( '' ); _self.closest( '.inline-element' ).find( '.uploadid' ).val( '' ); _self.closest( '.singleproduct' ).find( '#hover' ).html( 'Set hover image' ); _self.closest( '.singleproduct' ).find( '.howto' ).remove(); _self.closest( 'p' ).remove(); } else { _self.hide(); _self.closest( '.screenshot' ).next('.upload').val( '' ) ; _self.closest('.screenshot').slideUp(); } }); /* Promo banner in admin panel */ $('.promo-text-wrapper .close-btn').click(function(){ var confirmIt = confirm( ctadmin_text.yousure ); if(!confirmIt) return; var widgetBlock = $(this).parent(); var data = { 'action':'et_close_promo', 'close': widgetBlock.attr('data-etag') }; widgetBlock.hide(); $.ajax({ url: ajaxurl, data: data, success: function(response){ widgetBlock.remove(); }, error: function(data) { alert( ctadmin_text.delerror ); widgetBlock.show(); } }); }); var theme_settings = $('#prima-theme-settings'); // Only show the background color input when the background color option type is Color (Hex) $('.background-option-types').each(function() { showHideHexColor($(this)); $(this).change( function() { showHideHexColor( $(this) ) }); }); // Add color picker to color input boxes. if( $( 'input.color-picker' ).length ) { $('input.color-picker').wpColorPicker(); } //Activate Tabs on ciest settings if( $( "#alanah_tabs" ).length ) { $( "#alanah_tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" ); $( "#alanah_tabs li" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" ); } //Select2 alanah_select2(); //Update Font style and weight on google font change event $( '.alanah_fonts' ).on( 'change', function(){ var SELF = $(this); var currentfont = SELF.val(); var ajaxurl = $( '.ajaxurl' ).val(); if( currentfont !== '' ) { //Ajax Loader SELF.closest( 'p' ).append( ajaxloader ); $.ajax({ type: 'POST', url: ajaxurl, async: true, data: { 'action': 'alanah_update_gfonts', 'currentfont': currentfont }, success: function( data ) { //Remove Loader SELF.closest( 'p' ).find( '.svgloader' ).remove(); if( data ) { var explorer = data.split( '--SEPERATOR--' ); SELF.closest( 'p' ).find( '.alanah_fonts_style' ).html( explorer[0] ); SELF.closest( 'p' ).find( '.alanah_fonts_weight' ).html( explorer[1] ); alanah_select2(); } }, error: function ( request, status, error ) { //Remove Loader SELF.closest( 'p' ).find( '.svgloader' ).remove(); condole.log( 'Error: '+request.responseText ); } }); } }); //Update Font weight on google font style change event $( '.alanah_fonts_style' ).on( 'change', function(){ var SELF = $(this); var currentfont = SELF.closest( 'p' ).find( '.alanah_fonts' ).val(); var currentstyle = SELF.val(); var ajaxurl = $( '.ajaxurl' ).val(); //Ajax Loader SELF.closest( 'p' ).append( ajaxloader ); $.ajax({ type: 'POST', url: ajaxurl, data: { 'action': 'alanah_update_gfonts_weight', 'currentfont': currentfont, 'currentstyle': currentstyle }, success: function( data ) { //Remove Loader SELF.closest( 'p' ).find( '.svgloader' ).remove(); if( data ) { SELF.closest( 'p' ).find( '.alanah_fonts_weight' ).html( data ); alanah_select2(); } }, error: function ( request, status, error ) { //Remove Loader SELF.closest( 'p' ).find( '.svgloader' ).remove(); console.log( 'Error: '+request.responseText ); } }); }); //Background type selector $( '.alanah_bgtype' ).on( 'change', function(){ if( $(this).val() == 'image' ) { $( '.bgtypecolor' ).hide(); $( '.bgtypeimg' ).fadeIn(); } else { $( '.bgtypeimg' ).hide(); $( '.bgtypecolor' ).fadeIn(); } }); //Update Alanah Options $( 'form.alanah_options input[type="submit"]' ).on( 'click', function( e ) { e.preventDefault(); //Get form data var FORM = $( 'form.alanah_options' ); var formobj = FORM.get(0); var formdata = new FormData( formobj ); //Add Ajax Loader FORM.find( '.ajaxrespond' ).html( ajaxloader ); //Get response texts var successresp = FORM.find( '.successresp' ).val(); var errorresp = FORM.find( '.errorresp' ).val(); //Reset Response Classes FORM.find( '.ajaxrespond' ).removeClass( 'success' ); FORM.find( '.ajaxrespond' ).removeClass( 'error' ); //Add Action for wp-ajax request handler formdata.append( 'action', 'alanah_options_data' ); //Ajax Url var ajaxurl = FORM.find( '.ajaxurl' ).val(); $.ajax({ type: 'POST', url: ajaxurl, async: true, data: formdata, processData: false, contentType: false, success: function(data){ FORM.find( '.ajaxrespond' ).addClass( 'success' ); FORM.find( '.ajaxrespond' ).html( successresp ); }, error: function (request, status, error) { FORM.find( '.ajaxrespond' ).addClass( 'error' ); FORM.find( '.ajaxrespond' ).html( errorresp ); } }); }); //Add theme pro button function show_pro_button() { if( $( 'body.theme-alanah .theme-about .theme-info' ).length ) { $( 'body.theme-alanah .theme-about .theme-info' ).append( '

Get pro

' ); } } show_pro_button(); $( 'body.theme-alanah #alanah-action' ).on( 'click', function() { setTimeout( function(){ show_pro_button(); }, 500); }); });