PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.20
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.20
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
photonic / include / scripts / admin / helpers.js

helpers.js in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.20, at include/scripts/admin/helpers.js

127 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 $ = jQuery.noConflict();
2 jQuery(document).ready(function($) {
3 $(document).on('click', '.photonic-helper-box input[type="button"]', function() {
4 $('.photonic-waiting').show();
5 var formValues = $('#photonic-helper-form').serialize();
6 var result = $($(this).parents('.photonic-helper-box')[0]).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]).parents('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 args = {'action': 'photonic_save_token', 'provider': provider, 'token': token, 'secret': tokenSecret };
27 $.post(ajaxurl, args, function(data) {
28 window.location.replace(data);
29 });
30 };
31
32 window.photonicParseUrl = function (url, prop) {
33 var params = {};
34 var search = decodeURIComponent( url.slice( url.indexOf( '?' ) + 1 ) );
35 var definitions = search.split( '&' );
36
37 definitions.forEach( function( val, key ) {
38 var parts = val.split( '=', 2 );
39 params[ parts[ 0 ] ] = parts[ 1 ];
40 } );
41
42 return ( prop && prop in params ) ? params[ prop ] : params;
43 };
44
45 $('.photonic-picasa-refresh, .photonic-google-refresh').click(function(e) {
46 e.preventDefault();
47 $('.photonic-waiting').show();
48 var provider = $(this).hasClass('photonic-picasa-refresh') ? 'picasa' : 'google';
49 var result = $('#' + provider + '-result');
50 var args = {'action': 'photonic_obtain_token', 'provider': provider, 'code': $('#photonic-' + provider + '-oauth-code').val(), 'state': $('#photonic-' + provider + '-oauth-state').val() };
51 $.post(ajaxurl, args, function(data) {
52 data = $.parseJSON(data);
53 $(this).remove();
54 $("<span class='photonic-helper-button photonic-helper-button-disabled'>" +
55 Photonic_Admin_JS.obtain_token === undefined ? 'Step 2: Obtain Token' : Photonic_Admin_JS.obtain_token +
56 '</span>').insertBefore(result);
57 $(result).html('<strong>Refresh Token:</strong> <code id="' + provider + '-token">' + data['refresh_token'] + '</code>');
58 var a = $("<a href='#' class='button button-primary photonic-save-token' data-photonic-provider='" + provider + "'>Save Token</a>");
59 a.insertAfter(result);
60 a.on('click', photonicSaveToken);
61 $('.photonic-waiting').hide();
62 });
63 });
64
65 $('.photonic-zenfolio-delete').click(function(e) {
66 e.preventDefault();
67 var $clicked = $(this);
68 $('.photonic-waiting').show();
69 var result = $('#zenfolio-result');
70 var args = {'action': 'photonic_delete_token', 'provider': 'zenfolio'};
71 $.post(ajaxurl, args, function(data) {
72 $clicked.remove();
73 $(result).html('<strong>Stored authentication credentials deleted</strong>');
74 $('.photonic-waiting').hide();
75 });
76 });
77
78 $('.photonic-token-request').click(function(e) {
79 e.preventDefault();
80 $('.photonic-waiting').show();
81 var args = {'action': 'photonic_obtain_token', 'provider': $(this).data('photonicProvider') };
82 $.post(ajaxurl, args, function(data) {
83 window.location.replace(data);
84 });
85 });
86
87 $("[data-photonic-provider='zenfolio']").click(function(e) {
88 e.preventDefault();
89 $('.photonic-waiting').show();
90 var args = {'action': 'photonic_obtain_token', 'provider': $(this).data('photonicProvider'), 'password': $('[name="zenfolio-password"]').val()};
91 $.post(ajaxurl, args, function(data) {
92 $('#zenfolio-result').html(data);
93 $('.photonic-waiting').hide();
94 });
95 });
96
97 $('.photonic-save-token').on('click', photonicSaveToken);
98
99 $(document).on('click', '.photonic-shortcode-replace', function(e) {
100 e.preventDefault();
101 var params = photonicParseUrl($(this).attr('href'));
102 var args = {'action': 'replace_shortcode_individual', 'photonic_post_id': params.photonic_post_id};
103 var input = $('<input>').attr('type', 'hidden').attr('name', 'action').val('replace_shortcode_individual');
104 var $form = $('form[name="photonic-helper-form"]');
105 $form.append(input);
106
107 input = $('<input>').attr('type', 'hidden').attr('name', 'photonic_post_id').val(params.photonic_post_id);
108 $form.append(input);
109 $form.submit();
110 });
111
112 $('button.photonic-notice-dismiss').click(function(e) {
113 e.preventDefault();
114 var $clicked = $(this);
115 var $notice = $clicked.parents('.notice');
116 var dismissible = $clicked.attr('data-photonic-dismissible');
117 var args = { action: 'photonic_dismiss_warning', dismissible: dismissible };
118 $.post(ajaxurl, args, function(data) {
119 var response = JSON.parse(data);
120 response = Object.keys(response);
121 if (response.indexOf(dismissible) > -1) {
122 $notice.fadeOut();
123 }
124 });
125 });
126 });
127