| 1 |
$ = jQuery.noConflict(); |
| 2 |
jQuery(document).ready(function($) { |
| 3 |
$(document).on('click', '.photonic-helper input[type="button"]', function() { |
| 4 |
$('.photonic-waiting').show(); |
| 5 |
var formValues = $('#photonic-helper-form').serialize(); |
| 6 |
var result = $(this).closest('.photonic-helper-area').find('.result'); |
| 7 |
var nextToken = $(this).data('photonicToken') === undefined ? '' : '&nextPageToken=' + $(this).data('photonicToken'); |
| 8 |
$.post(ajaxurl, "action=photonic_invoke_helper&helper=" + this.id + '&' + formValues + nextToken, function(data) { |
| 9 |
if (data.trim().length >= 3 && data.trim().substr(0,3) === '<tr') { |
| 10 |
$($(result).find('input[type="button"]')[0]).closest('tr').remove(); |
| 11 |
$(result).find('table').append($(data)); |
| 12 |
} |
| 13 |
else { |
| 14 |
$(result).html(data); |
| 15 |
} |
| 16 |
$('.photonic-waiting').hide(); |
| 17 |
}); |
| 18 |
}); |
| 19 |
|
| 20 |
window.photonicSaveToken = function photonicSaveToken(e) { |
| 21 |
e.preventDefault(); |
| 22 |
$('.photonic-waiting').show(); |
| 23 |
var provider = $(this).data('photonicProvider'); |
| 24 |
var token = $('#' + provider + '-token').text(); |
| 25 |
var tokenSecret = $('#' + provider + '-token-secret').text(); |
| 26 |
var tokenExpiresIn = $('#' + provider + '-token-expires-in').val(); |
| 27 |
var tokenClientId = $('#' + provider + '-token-client-id').val(); |
| 28 |
var tokenUser = $('#' + provider + '-token-user').text(); |
| 29 |
var args = {'action': 'photonic_save_token', 'provider': provider, 'token': token, 'secret': tokenSecret, 'expires_in': tokenExpiresIn, 'client_id': tokenClientId, 'user': tokenUser }; |
| 30 |
$.post(ajaxurl, args, function (data) { |
| 31 |
window.location.replace(data); |
| 32 |
}); |
| 33 |
}; |
| 34 |
|
| 35 |
window.photonicParseUrl = function (url, prop) { |
| 36 |
var params = {}; |
| 37 |
var search = decodeURIComponent( url.slice( url.indexOf( '?' ) + 1 ) ); |
| 38 |
var definitions = search.split( '&' ); |
| 39 |
|
| 40 |
definitions.forEach( function( val, key ) { |
| 41 |
var parts = val.split( '=', 2 ); |
| 42 |
params[ parts[ 0 ] ] = parts[ 1 ]; |
| 43 |
} ); |
| 44 |
|
| 45 |
return ( prop && prop in params ) ? params[ prop ] : params; |
| 46 |
}; |
| 47 |
|
| 48 |
$('.photonic-picasa-refresh, .photonic-google-refresh').click(function(e) { |
| 49 |
e.preventDefault(); |
| 50 |
$('.photonic-waiting').show(); |
| 51 |
var provider = $(this).hasClass('photonic-picasa-refresh') ? 'picasa' : 'google'; |
| 52 |
var result = $('#' + provider + '-result'); |
| 53 |
var args = {'action': 'photonic_obtain_token', 'provider': provider, 'code': $('#photonic-' + provider + '-oauth-code').val(), 'state': $('#photonic-' + provider + '-oauth-state').val() }; |
| 54 |
$.post(ajaxurl, args, function(data) { |
| 55 |
data = $.parseJSON(data); |
| 56 |
$(this).remove(); |
| 57 |
$("<span class='photonic-helper-button photonic-helper-button-disabled'>" + |
| 58 |
Photonic_Admin_JS.obtain_token === undefined ? 'Step 2: Obtain Token' : Photonic_Admin_JS.obtain_token + |
| 59 |
'</span>').insertBefore(result); |
| 60 |
$(result).html('<strong>Refresh Token:</strong> <code id="' + provider + '-token">' + data['refresh_token'] + '</code>'); |
| 61 |
var a = $("<a href='#' class='button button-primary photonic-save-token' data-photonic-provider='" + provider + "'>Save Token</a>"); |
| 62 |
a.insertAfter(result); |
| 63 |
a.on('click', photonicSaveToken); |
| 64 |
$('.photonic-waiting').hide(); |
| 65 |
}); |
| 66 |
}); |
| 67 |
|
| 68 |
$('.photonic-zenfolio-delete').click(function(e) { |
| 69 |
e.preventDefault(); |
| 70 |
var $clicked = $(this); |
| 71 |
$('.photonic-waiting').show(); |
| 72 |
var result = $('#zenfolio-result'); |
| 73 |
var args = {'action': 'photonic_delete_token', 'provider': 'zenfolio'}; |
| 74 |
$.post(ajaxurl, args, function(data) { |
| 75 |
$clicked.remove(); |
| 76 |
$(result).html('<strong>Stored authentication credentials deleted</strong>'); |
| 77 |
$('.photonic-waiting').hide(); |
| 78 |
}); |
| 79 |
}); |
| 80 |
|
| 81 |
$('.photonic-token-request').click(function(e) { |
| 82 |
e.preventDefault(); |
| 83 |
$('.photonic-waiting').show(); |
| 84 |
var args = {'action': 'photonic_obtain_token', 'provider': $(this).data('photonicProvider') }; |
| 85 |
$.post(ajaxurl, args, function(data) { |
| 86 |
window.location.replace(data); |
| 87 |
}); |
| 88 |
}); |
| 89 |
|
| 90 |
$("[data-photonic-provider='zenfolio']").click(function(e) { |
| 91 |
e.preventDefault(); |
| 92 |
$('.photonic-waiting').show(); |
| 93 |
var args = {'action': 'photonic_obtain_token', 'provider': $(this).data('photonicProvider'), 'password': $('[name="zenfolio-password"]').val()}; |
| 94 |
$.post(ajaxurl, args, function(data) { |
| 95 |
$('#zenfolio-result').html(data); |
| 96 |
$('.photonic-waiting').hide(); |
| 97 |
}); |
| 98 |
}); |
| 99 |
|
| 100 |
$('.photonic-save-token').on('click', photonicSaveToken); |
| 101 |
|
| 102 |
$(document).on('click', '.photonic-shortcode-replace', function(e) { |
| 103 |
e.preventDefault(); |
| 104 |
var params = photonicParseUrl($(this).attr('href')); |
| 105 |
var args = {'action': 'replace_shortcode_individual', 'photonic_post_id': params.photonic_post_id}; |
| 106 |
var input = $('<input>').attr('type', 'hidden').attr('name', 'action').val('replace_shortcode_individual'); |
| 107 |
var $form = $('form[name="photonic-helper-form"]'); |
| 108 |
$form.append(input); |
| 109 |
|
| 110 |
input = $('<input>').attr('type', 'hidden').attr('name', 'photonic_post_id').val(params.photonic_post_id); |
| 111 |
$form.append(input); |
| 112 |
$form.submit(); |
| 113 |
}); |
| 114 |
|
| 115 |
$('button.photonic-notice-dismiss').click(function(e) { |
| 116 |
e.preventDefault(); |
| 117 |
var $clicked = $(this); |
| 118 |
var $notice = $clicked.parents('.notice'); |
| 119 |
var dismissible = $clicked.attr('data-photonic-dismissible'); |
| 120 |
var args = { action: 'photonic_dismiss_warning', dismissible: dismissible }; |
| 121 |
$.post(ajaxurl, args, function(data) { |
| 122 |
var response = JSON.parse(data); |
| 123 |
response = Object.keys(response); |
| 124 |
if (response.indexOf(dismissible) > -1) { |
| 125 |
$notice.fadeOut(); |
| 126 |
} |
| 127 |
}); |
| 128 |
}); |
| 129 |
}); |
| 130 |
|