jQuery(document).ready(function($) { // random number generator function randomString(len, charSet) { charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var randomString = ''; for (var i = 0; i < len; i++) { var randomPoz = Math.floor(Math.random() * charSet.length); randomString += charSet.substring(randomPoz,randomPoz+1); } return randomString; } ///////////////// pricing tables listing page //////////////////////// $('.appts-shortcode-readonly > input[type="text"]').focus(function(){ $(this).select(); }); // do the necessary actions according the data-action type for table listings $('.appts-table-action').on('click', function(){ if (confirm($(this).data('confirm'))) { var $postid = $(this).data('postid'), table_action = $(this).data('action_to_perform'); $.ajax({ url : ajaxurl, type: 'post', data: { action : 'backend_ajax', _action : table_action, table_id: $postid, _wpnonce: appts_backend_ajax.ajax_nonce }, beforeSend: function(){ $('.appts-backend-ajax-loader-div').show(); }, complete: function(){ $('.appts-backend-ajax-loader-div').hide(); }, success: function (response){ window.location.replace(response); } }); } }); ///////////////// pricing tables listing page ends //////////////////////// // tab actions $('.appts-tab').on('click', function() { $('.appts-tab').removeClass('appts-active'); $(this).addClass('appts-active'); var current_id = $(this).attr('id'); $('.appts-tab-content').hide(); $('.' + current_id).show(); codeMirrorDisplay(); }); // select change option for dropdown change option ( template selections and template selection ) $('.appts-img-selector').on('change', function() { var selected_img = $(this).find('option:selected').data('src'); $(this).closest('.appts-input-wrap').find('.appts-img-selector-media img').attr('src', selected_img); }); $('#appts-single-form').on('change', '.appts-ribbon-settings', function() { var selected_div = $(this).find('option:selected').data('select'); if (selected_div == 'appts-text-sign') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); $(this).closest('.appts-inner-tab-content').find('.appts-text-image-sign').show(); } if (selected_div == 'appts--sign') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.appts-text-image-sign').hide(); } }); $('#appts-single-form').on('change', '.appts-price-settings', function(){ var selected_div = $(this).find('option:selected').data('select'); if (selected_div == 'appts-price') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if (selected_div == 'appts-price-html') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } }); $('#appts-single-form').on('change', '.appts-custom-image-color-settings', function(){ var selected_div = $(this).find('option:selected').data('select'); if (selected_div == 'appts-bg-image') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if (selected_div == 'appts-bg-color') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if(selected_div == 'appts-none'){ $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); } }); $('#appts-admin-main-wrapper').on('change', '.appts-row-option', function(){ var selected_div = $(this).find('option:selected').data('select'); if (selected_div == 'appts-html') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if (selected_div == 'appts-button') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } }); $('#appts-admin-main-wrapper').on('change', '.appts-popup-content-selection-options', function(){ var selected_div = $(this).find('option:selected').data('select'); if (selected_div == 'appts-fontawesome') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if (selected_div == 'appts-typicons') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if (selected_div == 'appts-icomoon') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if (selected_div == 'appts-material') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } if (selected_div == 'appts-linecon') { $(this).closest('.appts-inner-tab-content').find('.appts-select-common-div').hide(); $(this).closest('.appts-inner-tab-content').find('.' + selected_div).show(); } }); // checkbox selection hide show $('.appts-checkbox-option').on('click', function() { if ($(this).is(':checked')) { $(this).closest('.appts-checkbox-selection-wrap').find(".appts-checkbox-options-show").show(); // checked } else { $(this).closest('.appts-checkbox-selection-wrap').find(".appts-checkbox-options-show").hide(); // unchecked } }); // slide toggle function show/hide for table columns $('#appts-single-form').on('click', '.appts-column-header', function(){ $(this).closest('.appts-settings-wrapper').find('.appts-column-content').slideToggle('slow', function(){ $(this).closest('.appts-settings-wrapper').find('.appts-column-hide-show').toggleClass('appts-active', $(this).is(':visible')); }); }); $('#appts-single-form').on('click', '.appts-inner-tab-header-title', function(){ $(this).closest('.appts-col-box').find('.appts-inner-tab-content').slideToggle('slow', function() { $(this).closest('.appts-col-box').find('.appts-inner-tab-header-title').toggleClass('appts-active', $(this).is(':visible')); }); }); // date picker $('#appts-single-form').on('focus',".appts-date-time-picker", function(){ $(this).datetimepicker({ dateFormat: 'yy/mm/dd' }); }); //wordpress color picker action $('.appts-admin-main-wrapper').on('hover',".appts-default-colorpicker", function(){ $(this).wpColorPicker(); }); // media upload function // http://dobsondev.com/2015/01/23/using-the-wordpress-media-uploader/ // http://stackoverflow.com/questions/20101909/wordpress-media-uploader-with-size-select $('.appts-admin-main-wrapper').on('click', '.appts-common-image-upload', function(e) { var mediaUploader; var $this = $(this); var container = $this.closest('.appts-image-upload').find('.appts-image-selection-append'); $this.closest('.appts-image-upload').find('.appts-image-selection-append .appts-image-sizes-selection').remove(); // Extend the wp.media object mediaUploader = wp.media.frames.file_frame = wp.media({ title: 'Choose Image', button: { text: 'Insert' }, multiple: false }); // When a file is selected, grab the image sizes URLs and set it as the select option fields mediaUploader.on('select', function() { var attachment = mediaUploader.state().get('selection').first().toJSON(); var sizes = typeof attachment.sizes !== 'undefined' ? attachment.sizes : null, selectOptions = ''; for (var x in sizes) { selectOptions += ''; } //generate html options to append if (selectOptions !== '') { var dropdown_selection = "
"; container.append(dropdown_selection); } $this.closest('.appts-image-upload').find('input[type=text]').val(attachment.url); }); // Open the uploader dialog mediaUploader.open(); e.preventDefault(); }); $('#appts-single-form').on('change', '.appts-image-sizes-selection', function() { var $image_url = $(this).val(); $(this).closest('.appts-image-upload').find('input[type=text]').val($image_url); }); $('#appts-single-form').on('click', function(){ $('.appts-column-settings-columns-wrapper').sortable({ items: '.appts-column-wrapper', handle: '.appts-column-header', tolerance: 'pointer', cursor: "move", update: function() { rearrangeColumnsIndex(); } }); $('.appts-settings-wrapper-body').sortable({ items:'.appts-col-box', handle: '.appts-inner-tab-header-title', containment: 'parent', tolerance: 'pointer', cursor: "move", }); $('.appts-column-footer-rows').sortable({ items:'.appts-footer-col-box', containment: 'parent', handle: '.appts-inner-tab-header-title', tolerance: 'pointer', cursor: "move", }); }); // http://stackoverflow.com/questions/9374894/can-codemirror-find-textareas-by-class function codeMirrorDisplay() { var $codeMirrorEditors = $('.appts-common-textarea'); $codeMirrorEditors.each(function(i, el) { var $active_element = $(el); if ($active_element.data('cm')) { $active_element.data('cm').doc.cm.toTextArea(); } var codeMirrorEditor = CodeMirror.fromTextArea(el, { lineNumbers: true, lineWrapping: true, theme: 'eclipse' }); $active_element.data('cm', codeMirrorEditor); }); } function rearrangeColumnsIndex() { var column_outer_wrapper = $('#appts-single-form').find('.appts-columns-editor-outer-wrapper'), columns = column_outer_wrapper.find('.appts-column-wrapper'); for (var i = 0; i