$ = jQuery.noConflict(); jQuery(document).ready(function($) { $(document).on('click', '.photonic-helper-box input[type="button"]', function() { $('.photonic-waiting').show(); var formValues = $('#photonic-helper-form').serialize(); var result = $($(this).parents('.photonic-helper-box')[0]).find('.result'); var nextToken = $(this).data('photonicToken') === undefined ? '' : '&nextPageToken=' + $(this).data('photonicToken'); $.post(ajaxurl, "action=photonic_invoke_helper&helper=" + this.id + '&' + formValues + nextToken, function(data) { if (data.trim().length >= 3 && data.trim().substr(0,3) === '" + Photonic_Admin_JS.obtain_token === undefined ? 'Step 2: Obtain Token' : Photonic_Admin_JS.obtain_token + '').insertBefore(result); $(result).html('Refresh Token: ' + data['refresh_token'] + ''); var a = $("Save Token"); a.insertAfter(result); a.on('click', photonicSaveToken); $('.photonic-waiting').hide(); }); }); $('.photonic-zenfolio-delete').click(function(e) { e.preventDefault(); var $clicked = $(this); $('.photonic-waiting').show(); var result = $('#zenfolio-result'); var args = {'action': 'photonic_delete_token', 'provider': 'zenfolio'}; $.post(ajaxurl, args, function(data) { $clicked.remove(); $(result).html('Stored authentication credentials deleted'); $('.photonic-waiting').hide(); }); }); $('.photonic-token-request').click(function(e) { e.preventDefault(); $('.photonic-waiting').show(); var args = {'action': 'photonic_obtain_token', 'provider': $(this).data('photonicProvider') }; $.post(ajaxurl, args, function(data) { window.location.replace(data); }); }); $("[data-photonic-provider='zenfolio']").click(function(e) { e.preventDefault(); $('.photonic-waiting').show(); var args = {'action': 'photonic_obtain_token', 'provider': $(this).data('photonicProvider'), 'password': $('[name="zenfolio-password"]').val()}; $.post(ajaxurl, args, function(data) { $('#zenfolio-result').html(data); $('.photonic-waiting').hide(); }); }); $('.photonic-save-token').on('click', photonicSaveToken); $(document).on('click', '.photonic-shortcode-replace', function(e) { e.preventDefault(); var params = photonicParseUrl($(this).attr('href')); var args = {'action': 'replace_shortcode_individual', 'photonic_post_id': params.photonic_post_id}; var input = $('').attr('type', 'hidden').attr('name', 'action').val('replace_shortcode_individual'); var $form = $('form[name="photonic-helper-form"]'); $form.append(input); input = $('').attr('type', 'hidden').attr('name', 'photonic_post_id').val(params.photonic_post_id); $form.append(input); $form.submit(); }); $('button.photonic-notice-dismiss').click(function(e) { e.preventDefault(); var $clicked = $(this); var $notice = $clicked.parents('.notice'); var dismissible = $clicked.attr('data-photonic-dismissible'); var args = { action: 'photonic_dismiss_warning', dismissible: dismissible }; $.post(ajaxurl, args, function(data) { var response = JSON.parse(data); response = Object.keys(response); if (response.indexOf(dismissible) > -1) { $notice.fadeOut(); } }); }); });