PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.12.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.12.0
4.12.0 4.10.0 4.9.0 4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / admin / assets / js / cff-admin-scripts.js
custom-facebook-feed / admin / assets / js Last commit date
about.js 2 weeks ago admin-notifications.js 2 weeks ago builders-preview-handler.js 2 weeks ago callout.js 2 weeks ago cff-admin-scripts.js 2 weeks ago divi-handler.min.js 2 weeks ago extensions.js 2 weeks ago oembeds.js 2 weeks ago settings.js 2 weeks ago smash-usage-session.js 2 weeks ago support.js 2 weeks ago vue.min.js 2 weeks ago
cff-admin-scripts.js
1459 lines
1 jQuery(document).ready(function($) {
2 //Dismiss Review Notice
3 jQuery(document).on('click', '.cff_notice_dismiss', function(event) {
4 event.preventDefault();
5 $.ajax({
6 url : cffA.ajax_url,
7 type : 'post',
8 data : {
9 action : 'cff_review_notice_dismiss',
10 cff_nonce: cffA.cff_nonce
11 }
12 });
13 const elem = jQuery(this);
14 setTimeout(function() {
15 const url = elem.attr('href');
16 if(url) {
17 const target = elem.attr('target') || '_self';
18 window.open(url, target);
19 }
20 }, 100);
21 });
22 //Tooltips
23 jQuery('#cff-admin .cff-tooltip-link').on('click', function(){
24 jQuery(this).closest('tr, h3, div').find('.cff-tooltip').slideToggle();
25 });
26
27 //Toggle Access Token field
28 if( jQuery('#cff_show_access_token').is(':checked') ) jQuery('.cff-access-token-hidden').show();
29 jQuery('#cff_show_access_token').on('change', function(){
30 jQuery('.cff-access-token-hidden').fadeToggle();
31 });
32
33
34 $(document).on('click', '#cff-dismiss-header-notice', function() {
35 $.ajax({
36 url : cffA.ajax_url,
37 type : 'post',
38 data : {
39 action : 'cff_dismiss_upgrade_notice',
40 cff_nonce: cffA.cff_nonce
41 },
42 success : function(data) {
43 if ( data.success == true ) {
44 $('#cff-header-upgrade-notice').slideUp();
45 $("#cff-builder-app").removeClass('cff-builder-app-lite-dismiss');
46 }
47 },
48 error : function(e) {
49 console.log(e);
50 }
51 });
52 });
53
54 $('body').on('click','.cff-dismissible .notice-dismiss',function() {
55 $.ajax({
56 url : cffA.ajax_url,
57 type : 'post',
58 data : {
59 action : 'cff_dismiss_custom_cssjs_notice',
60 cff_nonce: cffA.cff_nonce
61 },
62 success : function(data) {
63 },
64 error : function(e) {
65 console.log(e);
66 }
67 });
68 });
69
70 //The "cff_ppca_access_token_invalid" transient is set if the access token doesn't match the ID specified. Use an Ajax call to check whether that transient is set, and if so, then displays a notice under the access token field. This used so we don't need to make an API call every time the page loads. It stores the value in this transient and checks it via ajax.
71 $.ajax({
72 url : cffA.ajax_url,
73 type : 'get',
74 data : {
75 action : 'cff_ppca_token_check_flag',
76 cff_nonce: cffA.cff_nonce
77
78 },
79 success : function(data) {
80 if( data ) $('.cff-ppca-check-notice.cff-error').show();
81 },
82 error : function(e) {
83 console.log(e);
84 }
85 });
86
87 //If no transient exists (eg. after the settings are saved) then check the API to see whether the ID and token match
88 if( typeof jQuery('#cff_access_token').attr('data-check-ppca') !== 'undefined' ){
89
90 var page_id = $('#cff-admin #cff_page_id').val(),
91 access_token = $('#cff-admin #cff_access_token').val();
92
93 if( page_id.indexOf(',') == -1 && access_token.indexOf(',') == -1 ){
94 var ppca_check_url = 'https://graph.facebook.com/v8.0/'+page_id+'/posts?limit=1&access_token='+access_token;
95
96 $.ajax({
97 url: ppca_check_url,
98 type: 'GET',
99 dataType: "jsonp",
100 cache: false,
101 success: function(data) {
102 if (typeof data.error !== 'undefined') {
103 if( data.error.message.indexOf('Public Content') !== -1 ){
104 //If the API response shows a PPCA error then show the notice below the access token field
105 $('.cff-ppca-check-notice.cff-error').show();
106
107 //Store the API response in a transient which is then checked above on line 29
108 $.ajax({
109 url : cffA.ajax_url,
110 type : 'post',
111 data : {
112 action : 'cff_ppca_token_set_flag'
113 },
114 success : function(data) {
115 //Access token transient set
116 },
117 error : function(e) {
118 console.log(e);
119 }
120 });
121 }
122 } else {
123 //If the API response shows a good token then display a success notice instead
124 $('#cff-admin #cff_access_token').after('<div class="cff-ppca-check-notice cff-success" style="display: block;"><i class="fa fa-check-circle"></i>&nbsp; Valid Access Token</div>');
125 }
126 },
127 error: function(xhr,textStatus,e) {
128 console.log(e);
129
130 return;
131 }
132 }); //End ajax
133 }
134 }
135
136 //Is this a page, group or profile?
137 var cff_page_type = jQuery('.cff-page-type select').val(),
138 $cff_page_type_options = jQuery('.cff-page-options'),
139 $cff_profile_error = jQuery('.cff-profile-error.cff-page-type'),
140 $cff_group_error = jQuery('.cff-group-error.cff-page-type');
141
142 //Should we show anything initially?
143 if(cff_page_type !== 'page') $cff_page_type_options.hide();
144 if(cff_page_type == 'profile') $cff_profile_error.show();
145 if(cff_page_type == 'group') $cff_group_error.show();
146
147 //When page type is changed show the relevant item
148 jQuery('.cff-page-type').on('change', function(){
149 cff_page_type = jQuery('.cff-page-type select').val();
150
151 if( cff_page_type !== 'page' ) {
152 $cff_page_type_options.hide();
153 if( cff_page_type == 'profile' ) {
154 $cff_profile_error.show();
155 $cff_group_error.hide();
156 } else if( cff_page_type == 'group' ) {
157 $cff_group_error.show();
158 $cff_profile_error.hide();
159 } else {
160 $cff_group_error.hide();
161 $cff_profile_error.hide();
162 }
163
164 } else {
165 $cff_page_type_options.show();
166 $cff_profile_error.hide();
167 $cff_group_error.hide();
168 }
169 });
170
171
172 //Post limit manual setting
173 var cff_limit_setting = jQuery('#cff_limit_setting').val(),
174 cff_post_limit = jQuery('#cff_post_limit').val(),
175 $cff_limit_manual_settings = jQuery('#cff_limit_manual_settings');
176 if( typeof cff_post_limit === 'undefined' ) cff_post_limit = '';
177
178 //Should we show anything initially?
179 if(cff_limit_setting == 'auto') $cff_limit_manual_settings.hide();
180 if(cff_post_limit.length > 0){
181 $cff_limit_manual_settings.show();
182 jQuery('#cff_limit_setting').val('manual');
183 }
184
185 jQuery('#cff_limit_setting').on('change', function(){
186 cff_limit_setting = jQuery('#cff_limit_setting').val();
187
188 if(cff_limit_setting == 'auto'){
189 $cff_limit_manual_settings.hide();
190 jQuery('#cff_post_limit').val('');
191 } else {
192 $cff_limit_manual_settings.show();
193 }
194 });
195
196 //Header Type Selection
197 var cff_header_type = jQuery('.cff-header-type select').val(),
198 $cff_facebook_header_options = jQuery('.cff-facebook-header'),
199 $cff_text_header_options = jQuery('.cff-text-header');
200
201 //Should we show anything initially?
202 if(cff_header_type !== 'visual') $cff_facebook_header_options.hide();
203 if(cff_header_type !== 'text') $cff_text_header_options.hide();
204
205 //When Header type is changed show the relevant item
206 jQuery('.cff-header-type').on('change', function(){
207 cff_header_type = jQuery('.cff-header-type select').val();
208
209 if( cff_header_type !== 'visual' ) {
210 $cff_facebook_header_options.hide();
211 $cff_text_header_options.show();
212 } else {
213 $cff_facebook_header_options.show();
214 $cff_text_header_options.hide();
215 }
216 });
217
218 //Header icon
219 //Icon type
220 //Check the saved icon type on page load and display it
221 jQuery('#cff-header-icon-example').removeClass().addClass('fa fa-' + jQuery('#cff-header-icon').val() );
222 //Change the header icon when selected from the list
223 jQuery('#cff-header-icon').on('change', function() {
224 var $self = jQuery(this);
225
226 jQuery('#cff-header-icon-example').removeClass().addClass('fa fa-' + $self.val() );
227 });
228
229
230 //Test Facebook API connection button
231 jQuery('#cff-api-test').on('click', function(e){
232 e.preventDefault();
233 //Show the JSON
234 jQuery('#cff-api-test-result textarea').css('display', 'block');
235 });
236
237
238 //If '__ days ago' date is selected then show 'Translate this'
239 var $cffTranslateDate = jQuery('#cff-translate-date');
240
241 if ( jQuery("#cff-date-formatting option:selected").val() == '1' ) $cffTranslateDate.show();
242
243 jQuery("#cff-date-formatting").on('change', function() {
244 if ( jQuery("#cff-date-formatting option:selected").val() == '1' ) {
245 $cffTranslateDate.fadeIn();
246 } else {
247 $cffTranslateDate.fadeOut();
248 }
249 });
250
251 //Selecting a post style
252 jQuery('.cff-post-style').on('click', function(){
253 var $self = jQuery(this);
254 $('.cff_post_style').trigger('change');
255 $self.addClass('cff-layout-selected').find('#cff_post_style').attr('checked', 'checked');
256 $self.siblings().removeClass('cff-layout-selected');
257 });
258 function cffChangePostStyleSettings() {
259 setTimeout(function(){
260 jQuery('.cff-post-style-settings').hide();
261 jQuery('.cff-post-style-settings.cff-'+jQuery('.cff_post_style:checked').val()).show();
262 }, 1);
263 }
264 cffChangePostStyleSettings();
265 jQuery('.cff_post_style').on('change', cffChangePostStyleSettings);
266
267 //Add the color picker
268 if( jQuery('.cff-colorpicker').length > 0 ) jQuery('.cff-colorpicker').wpColorPicker();
269
270
271 //Mobile width
272 var cff_feed_width = jQuery('#cff-admin #cff_feed_width').val(),
273 $cff_width_options = jQuery('#cff-admin #cff_width_options');
274
275 if (typeof cff_feed_width !== 'undefined') {
276 //Show initially if a width is set
277 if(cff_feed_width.length > 1 && cff_feed_width !== '100%') $cff_width_options.show();
278
279 jQuery('#cff_feed_width').on('change', function(){
280 cff_feed_width = jQuery(this).val();
281
282 if( cff_feed_width.length < 2 || cff_feed_width == '100%' ) {
283 $cff_width_options.slideUp();
284 } else {
285 $cff_width_options.slideDown();
286 }
287 });
288 }
289
290 //Scroll to hash for quick links
291 jQuery('#cff-admin a').on('click', function() {
292 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
293 var target = jQuery(this.hash);
294 target = target.length ? target : this.hash.slice(1);
295 if (target.length) {
296 jQuery('html,body').animate({
297 scrollTop: target.offset().top
298 }, 500);
299 return false;
300 }
301 }
302 });
303
304 //Shortcode tooltips
305 jQuery('#cff-admin label').on('click', function(){
306 var $el = jQuery(this);
307 var $cff_shortcode = $el.siblings('.cff_shortcode');
308 if($cff_shortcode.is(':visible')){
309 $el.siblings('.cff_shortcode').css('display','none');
310 } else {
311 $el.siblings('.cff_shortcode').css('display','block');
312 }
313 });
314 jQuery('#cff-admin th').on('hover', function(){
315 if( jQuery(this).find('.cff_shortcode').length > 0 ){
316 jQuery(this).find('label').append('<code class="cff_shortcode_symbol">[]</code>');
317 }
318 }, function(){
319 jQuery(this).find('.cff_shortcode_symbol').remove();
320 });
321 jQuery('#cff-admin label').on('hover', function(){
322 if( jQuery(this).siblings('.cff_shortcode').length > 0 ){
323 jQuery(this).attr('title', 'Click for shortcode option');
324 }
325 }, function(){});
326
327 //Open/close the expandable option sections
328 jQuery('.cff-expandable-options').hide();
329 jQuery('.cff-expand-button a').on('click', function(e){
330 e.preventDefault();
331 var $self = jQuery(this);
332 $self.parent().next('.cff-expandable-options').toggle();
333 if( $self.text().indexOf('Show') !== -1 ){
334 $self.text( $self.text().replace('Show', 'Hide') );
335 } else {
336 $self.text( $self.text().replace('Hide', 'Show') );
337 }
338 });
339
340 function cffToggleNummobile() {
341 if (jQuery('#cff_show_num_mobile').is(':checked')) {
342 jQuery('#cff_show_num_mobile').closest('td').find('.cff-mobile-col-settings').slideDown();
343 } else {
344 jQuery('#cff_show_num_mobile').closest('td').find('.cff-mobile-col-settings').slideUp(function(){
345 jQuery('#cff_num_mobile').val('');
346 });
347 }
348 }
349 cffToggleNummobile();
350 jQuery('#cff_show_num_mobile').on('change', cffToggleNummobile);
351
352 //Facebook login
353 $('#cff_fb_login').on('click', function(){
354 $('#cff_fb_login_modal').show();
355 });
356 $('#cff_admin_cancel_btn').on('click', function(){
357 $('#cff_fb_login_modal').hide();
358 });
359 $('.cff-modal-close, #cff-close-modal-primary-button').on('click', function(){
360 $('.cff_modal_tokens').hide();
361 });
362 $('#cff_fb_show_tokens').on('click', function(){
363 $('.cff_modal_tokens, .cff-groups-list').show();
364 $('#cff-group-installation').hide();
365 });
366
367 //Select a page for token
368 $('.cff-managed-page').on('click', function(){
369 $('#cff-insert-token, .cff-insert-reviews-token, .cff-insert-both-tokens').removeAttr('disabled');
370
371 $('#cff_token_expiration_note').show();
372
373 var $self = $(this);
374 if( $self.hasClass('cff-page-selected') ){
375 $self.removeClass('cff-page-selected');
376 } else {
377 $self.addClass('cff-page-selected');
378 }
379 });
380
381
382
383
384
385 //Connect Accounts array object
386 var cff_connected_accounts = {},
387 cff_multifeed_enabled = false,
388 cff_remove_primary_text = 'Remove as Primary Feed',
389 cff_add_primary_text = 'Make Primary Feed';
390
391 if( $('#cff_page_id').hasClass('cff_multifeed_enabled') ) cff_multifeed_enabled = true;
392 if( cff_multifeed_enabled ){
393 cff_remove_primary_text = 'Remove from Primary Feed';
394 cff_add_primary_text = 'Add to Primary Feed';
395 }
396
397 //If there are accounts displayed then assign them to the connected accounts array
398 var cff_connected_accounts_val = $('#cff_connected_accounts').val();
399 if( cff_connected_accounts_val !== '' && cff_connected_accounts_val !== '{}' && typeof cff_connected_accounts_val !== 'undefined' ){
400
401 cff_connected_accounts = cff_connected_accounts_val.replace(/\\"/g, '"');
402 cff_connected_accounts = JSON.parse(cff_connected_accounts);
403
404 createAccountHTML(cff_connected_accounts);
405 }
406
407 //Insert Page Access Token
408 $('#cff-insert-token, #cff-insert-all-tokens').on('click', function(){
409
410 if( $(this).hasClass('cff_connect_all') ) $('.cff-managed-page').addClass('cff-page-selected');
411
412 var $selectedPage = $('.cff-page-selected'),
413 selectedPageId = $selectedPage.attr('data-page-id'),
414 selectedPageToken = $selectedPage.attr('data-token');
415
416 //Add ID to setting
417 if( $('#cff_page_id').val().trim() == '' ){
418 $('#cff_page_id').val( selectedPageId ).addClass('cff-success');
419 cffAddCurIdLabel($('.cff-page-selected').first().find('.cff-page-info-name').text(), $('.cff-page-selected').first().find('.cff-page-avatar').attr('src'));
420 }
421
422 //Add token to setting
423 if( $('#cff_access_token').val().trim() == '' || $('#cff_access_token').hasClass('cff-replace-token') ){
424 //If multifeed then add ID to front so it's assigned to that ID in the feed
425 if( $('#cff_page_id').hasClass('cff_multifeed_enabled') ) selectedPageToken = selectedPageId + ':' + selectedPageToken;
426
427 $('#cff_access_token').val( selectedPageToken ).addClass('cff-success');
428 }
429
430 if( $(this).hasClass('cff-group-btn') ){
431 $('.cff-groups-list').hide();
432 $('#cff-group-installation').show();
433
434 //Show directions for either group admin or member
435 if( $('.cff-page-selected').hasClass('cff-group-admin') ){
436 $('#cff-group-admin-directions').show();
437 $('#cff-group-member-directions').hide();
438 } else {
439 $('#cff-group-admin-directions').hide();
440 $('#cff-group-member-directions').show();
441 }
442
443 //Change page type to be group
444 $('#cff_page_type').val('group');
445 $('.cff-page-options').hide();
446
447 //Dynamically create group edit link
448 var cffGroupEditLink = 'https://facebook.com/groups/'+selectedPageId+'/edit';
449 $('#cff-group-installation #cff-group-edit').attr('href', cffGroupEditLink);
450 } else {
451 $('.cff_modal_tokens').hide();
452 }
453
454 // cff_connected_accounts
455 $('.cff-managed-pages').find('.cff-page-selected').each(function(){
456 var $page = $(this);
457
458 addConnectedAccounts(
459 $page.attr('data-page-id'),
460 $page.find('.cff-page-info-name').text(),
461 $page.attr('data-pagetype'),
462 $page.attr('data-token'),
463 $page.find('.cff-page-avatar').attr('src')
464 );
465
466 });
467
468 location.hash = "cffnomodal";
469 });
470
471 //Manually connect account
472 //Step 1
473 $('#cff_manual_account_button, #cff-admin .cff_manual_back').on('click', function(e){
474 e.preventDefault();
475 if( !$(this).hasClass('cff_manual_back') ) $('#cff_manual_account').toggle();
476 $('#cff_manual_account_step_1').show();
477 $('#cff_manual_account_step_2').hide();
478 });
479 //Step 2
480 jQuery("#cff_manual_account_type").on('change', function() {
481 cff_go_to_step_2();
482 });
483 $('#cff-admin .cff_manual_forward').on('click', function(){
484 if( $("#cff_manual_account_type option:selected").val() ){
485 cff_go_to_step_2();
486 } else {
487 $("#cff_manual_account_type").addClass('cff_error');
488 setTimeout(function(){ $("#cff_manual_account_type").removeClass('cff_error'); }, 500);
489 }
490 });
491 function cff_go_to_step_2(){
492 $('#cff_manual_account_step_2').attr('class', 'cff_account_type_'+jQuery("#cff_manual_account_type option:selected").val() );
493
494 $('#cff_manual_account_step_1').hide();
495 $('#cff_manual_account_step_2').show();
496 }
497
498 //Add account
499 $('#cff_manual_account_step_2 input[type=submit]').on('click', function(e){
500 e.preventDefault();
501
502 var $cff_manual_account = $('#cff_manual_account');
503
504 addConnectedAccounts(
505 $cff_manual_account.find('#cff_manual_account_id').val(),
506 $cff_manual_account.find('#cff_manual_account_name').val(),
507 $cff_manual_account.find('#cff_manual_account_type').val(),
508 $cff_manual_account.find('#cff_manual_account_token').val(),
509 false
510 );
511 });
512
513 //Only enable manual account submit button if ID/token fields have values
514 $('#cff_manual_account_id, #cff_manual_account_token').on('input', function() {
515 if( $('#cff_manual_account_id').val() == '' || $('#cff_manual_account_token').val() == '' ){
516 $('#cff_manual_account_step_2 #submit').attr('disabled', true);
517 } else {
518 $('#cff_manual_account_step_2 #submit').removeAttr('disabled');
519 }
520 });
521
522 //Show raw account data (can be used for exporting/importing accounts in bulk)
523 $('#cff_export_accounts').on('click', function(e){
524 e.preventDefault();
525 $('#cff_export_accounts_wrap').toggle();
526 });
527
528
529 function addConnectedAccounts(id, name, pagetype, accesstoken, avatar=false){
530
531 if( pagetype == 'page' ) avatar = '';
532
533 id = cffStripURLParts(id);
534
535 //Add to connected accounts array
536 cff_connected_accounts[id] = {
537 id: id,
538 name: encodeURI( name ),
539 pagetype: pagetype,
540 accesstoken: accesstoken,
541 avatar: avatar
542 };
543
544 //Update setting on page
545 $('#cff_connected_accounts').val( JSON.stringify(cff_connected_accounts) );
546
547 //Add HTML to page
548 createAccountHTML(cff_connected_accounts);
549 }
550
551 function removeConnectedAccount($account){
552 //Remove account from array
553 delete cff_connected_accounts[$account.attr('data-page-id')];
554
555 //Update setting on page
556 $('#cff_connected_accounts').val( JSON.stringify(cff_connected_accounts) );
557
558 //Remove it from primary feed if it's in there
559 removePrimaryAcount($account);
560
561 //Remove account element from page
562 $account.remove();
563 }
564
565 function cffStripURLParts(string){
566 if (typeof string === 'undefined') {
567 return '';
568 }
569 //If user pastes their full URL into the Page ID field then strip it out
570 var cff_facebook_string = 'facebook.com',
571 hasURL = (string.indexOf(cff_facebook_string) > -1);
572 if (hasURL) {
573 var stringArr = string.split('?')[0].replace(/\/$/, '').split('/');
574 string = stringArr[stringArr.length-1].replace(/[\.\/]/,'');
575 }
576
577 return string;
578 }
579
580 function createAccountHTML(cff_connected_accounts){
581
582 var accountsHTML = '';
583
584 //Loop through accounts and create HTML
585 for (var key in cff_connected_accounts) {
586 if (cff_connected_accounts.hasOwnProperty(key)) {
587
588 var id = cffStripURLParts(cff_connected_accounts[key]['id']),
589 name = decodeURI(cff_connected_accounts[key]['name']),
590 pagetype = cff_connected_accounts[key]['pagetype'],
591 accesstoken = cff_connected_accounts[key]['accesstoken'],
592 avatar = cff_connected_accounts[key]['avatar'],
593 cff_account_active = '',
594 no_avatar = false;
595
596 if( (!avatar || avatar == 'false' ) && pagetype == 'group' ) no_avatar = true;
597 if( !avatar || avatar == '' ) avatar = 'https://graph.facebook.com/'+id+'/picture';
598
599 //If it's in use then mark it as primary/active
600 if( $('#cff_page_id').val().indexOf(id) !== -1 ) cff_account_active = ' cff_account_active';
601
602 accountsHTML += '<div class="cff_connected_account cff_account_type_'+pagetype+cff_account_active+'" id="cff_connected_account_'+id+'" data-accesstoken="'+accesstoken+'" data-pagetype="'+pagetype+'" data-page-id="'+id+'">' +
603 '<div class="cff_ca_info">' +
604 '<div class="cff_ca_delete"><a href="JavaScript:void(0);" class="cff_delete_account"><i class="fa fa-times"></i><span class="cff_remove_text">Remove</span></a></div>'+
605 '<div class="cff_ca_username">';
606 ( no_avatar ) ? accountsHTML += '' : accountsHTML += '<img class="cff_ca_avatar" src="'+avatar+'">';
607 accountsHTML += '<strong><span class="cff_ca_fullname">'+name+'</span><span class="cff_ca_pagetype">'+pagetype+' ID: '+id+'</span></strong>' +
608 '</div>' +
609 '<div class="cff_ca_actions">' +
610 '<a href="JavaScript:void(0);" class="cff_make_primary">';
611 if( cff_account_active !== '' ){
612 accountsHTML += '<i class="fa fa-minus-circle" aria-hidden="true"></i>'+cff_remove_primary_text;
613 } else {
614 accountsHTML += '<i class="fa fa-plus-circle" aria-hidden="true"></i>'+cff_add_primary_text;
615 }
616 accountsHTML += '</a>';
617
618 if( $('#cff_page_access_token').length && pagetype == 'page' ) accountsHTML += '<a href="JavaScript:void(0);" class="cff_make_reviews"><i class="fa fa-star" aria-hidden="true"></i>Use for Reviews Feed</a>';
619
620 accountsHTML += '<a class="cff_ca_token_shortcode" href="JavaScript:void(0);"><i class="fa fa-chevron-circle-right" aria-hidden="true"></i>Add to another Feed</a>' +
621 '<p class="cff_ca_show_token"><a href="javascript:void(0);" id="cff_ca_show_token_'+id+'"><i class="fa fa-ellipsis-h" style="margin: 0; font-size: 12px;" aria-hidden="true"></i></a></p>' +
622 '</div>' +
623 '<div class="cff_ca_shortcode">' +
624 '<p>Copy and paste this shortcode into your page or widget area:<br>' +
625 '<code>[custom-facebook-feed account="'+id+'" pagetype="'+pagetype+'"]</code>' +
626 '</p>';
627 if( cff_multifeed_enabled ) accountsHTML += '<p>To add multiple accounts in the same feed, simply separate them using commas:<br>' +
628 '<code>[custom-facebook-feed account="'+id+', account_2, account_3"]</code>' +
629 '</p>';
630 accountsHTML += '<p>Click <a href="https://smashballoon.com/custom-facebook-feed/docs/shortcodes/?utm_campaign=facebook-free&utm_source=admin-scripts&utm_medium=docs" target="_blank">here</a> to learn more about shortcodes</p>' +
631 '</div>' +
632 '<div class="cff_ca_accesstoken">' +
633 '<span class="cff_ca_token_label">Access Token:</span><input type="text" class="cff_ca_token" value="'+accesstoken+'" readonly="readonly" onclick="this.focus();this.select()" title="To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).">' +
634 '</div>' +
635 '</div>' +
636 '</div>';
637 }
638 }
639
640 //Add HTML to page
641 $('#cff_connected_accounts_wrap').html(accountsHTML);
642
643 //Add Raw Data button
644 $('.cff_connected_actions').show();
645
646 }
647
648 function removePrimaryAcount($account){
649 //Remove ID/token from fields
650 if( $account.hasClass('cff_account_active') ){
651
652 var selected_id = $account.attr('data-page-id'),
653 selected_token = $account.attr('data-accesstoken');
654
655 //Remove as primary account
656 cffLabelAsPrimary($account);
657
658 $('#cff_primary_account_label').hide();
659
660 if( cff_multifeed_enabled ){
661
662 //Find the ID from the removed account and remove it from the ID field
663 var updatedIdVal = $('#cff_page_id').val().replace(selected_id, '');
664 //Remove any stray commas left over
665 updatedIdVal = updatedIdVal.replace(',,', '').replace(' ,', '').replace(/^, |, $/g,'');
666
667 $('#cff_page_id').val( updatedIdVal ).removeClass('cff-success');
668
669 //Remove Token
670 // var updatedTokenVal = $('#cff_access_token').val().replace(selected_id+':'+selected_token, '').replace(selected_token, '');
671 var updatedTokenVal = $('#cff_access_token').val().replace(selected_id+':'+selected_token, '');
672 //Remove any stray commas left over
673 updatedTokenVal = updatedTokenVal.replace(',,', '').replace(' ,', '').replace(':,', ':').replace(/^, |, $/g,'');
674
675 $('#cff_access_token').val( updatedTokenVal ).removeClass('cff-success');
676
677
678 } else {
679
680 //Revert ID/token fields back to previous values
681 $('#cff_page_id').val( $('#cff_page_id').attr('data-page-id') ).removeClass('cff-success');
682 $('#cff_access_token').val( $('#cff_access_token').attr('data-accesstoken') ).removeClass('cff-success');
683
684 }
685 }
686 }
687
688
689 var $body = $('body');
690 //Show Access Token
691 $body.on('click', '.cff_ca_show_token a', function(e) {
692 e.preventDefault();
693 jQuery(this).closest('.cff_ca_info').find('.cff_ca_accesstoken').slideToggle(200);
694 });
695 $body.on('click', '.cff_ca_token_shortcode, .cff_make_primary, .cff_make_reviews', function (event) {
696 event.preventDefault();
697 var $clicked = $(event.target);
698 //Show shortcode
699 if( $clicked.hasClass('cff_ca_token_shortcode') ) {
700 jQuery(this).closest('.cff_ca_info').find('.cff_ca_shortcode').slideToggle(200);
701 }
702 //Make Reviews account
703 if( $clicked.hasClass('cff_make_reviews') ){
704 $('#cff_page_access_token').val( $clicked.closest('.cff_connected_account').attr('data-accesstoken') ).addClass('cff-success');
705 }
706 //Make primary account
707 if( $clicked.hasClass('cff_make_primary') ){
708 var $selected_account = $clicked.closest('.cff_connected_account'),
709 selected_id = $selected_account.attr('data-page-id'),
710 selected_token = $selected_account.attr('data-accesstoken');
711
712
713 //Remove ID/token from fields
714 if( $selected_account.hasClass('cff_account_active') ){
715
716 removePrimaryAcount($selected_account);
717
718 //Add ID/token to fields
719 } else {
720
721 //Add as primary account
722 cffLabelAsPrimary($selected_account, true);
723
724 //Add ID/token to fields
725 if( cff_multifeed_enabled ){
726
727 //Add ID to existing IDs already in field
728 var id_sep = ', ',
729 existing_id = $('#cff_page_id').val().trim(),
730 existing_token = $('#cff_access_token').val().trim();
731
732 if( existing_id == '' ) id_sep = '';
733 $('#cff_page_id').val( existing_id + id_sep + selected_id ).addClass('cff-success');
734
735 //Change to multiple token format
736 var token_format = '';
737 if( existing_token !== '' ) token_format += existing_token + ', ';
738 token_format += selected_id + ':' + selected_token;
739
740 $('#cff_access_token').val( token_format ).addClass('cff-success');
741
742 } else {
743
744 //Replace existing ID and token
745 $('#cff_page_id').val( selected_id ).addClass('cff-success');
746 $('#cff_access_token').val( selected_token ).addClass('cff-success');
747
748 //Remove active account class from other accounts
749 $selected_account.siblings().each(function(){
750 cffLabelAsPrimary($(this));
751 });
752
753 }
754
755
756 }
757 }
758 });
759 //Remove account
760 $body.on('click', '.cff_delete_account', function(){
761 removeConnectedAccount( $(this).closest('.cff_connected_account') );
762 });
763
764 //Change button label when adding/removing as primary account
765 function cffLabelAsPrimary($account, makePrimary=false){
766 if( makePrimary ){
767 $account.addClass('cff_account_active').find('.cff_make_primary').html('<i class="fa fa-minus-circle" aria-hidden="true"></i>'+cff_remove_primary_text);
768
769 if( $account.length > 0 ) cffAddCurIdLabel($account.find('.cff_ca_fullname').text(), $account.find('.cff_ca_avatar').attr('src'));
770
771 } else {
772 $account.removeClass('cff_account_active').find('.cff_make_primary').html('<i class="fa fa-plus-circle" aria-hidden="true"></i>'+cff_add_primary_text);
773 }
774 }
775
776 function cffAddCurIdLabel(name, avatar){
777 var account_img = '',
778 account_name = '<span>' + name + '</span>';
779 if( avatar !== undefined ) account_img = '<img src="' + avatar + '" />';
780
781 $('#cff_primary_account_label').show().html( account_img + account_name );
782 }
783
784 //Label a primary account when page is first loaded
785 var cff_current_page_id = $('#cff_page_id').val(),
786 cff_current_page_id_arr = [];
787 if( typeof cff_current_page_id !== 'undefined' ) var cff_current_page_id_arr = cff_current_page_id.split(',');
788
789 if( cff_current_page_id_arr.length > 1 ){
790 for (var i = 0; i < cff_current_page_id_arr.length; i++) {
791 cffLabelAsPrimary( $('#cff_connected_account_' + cffValidateID( cff_current_page_id_arr[i] ) ), true );
792 }
793 } else {
794 cffLabelAsPrimary( $('#cff_connected_account_' + cffValidateID( cff_current_page_id ) ), true );
795 }
796 //Make sure ID is a valid string
797 function cffValidateID(id){
798 if( typeof id === 'undefined' || id == '' ) return;
799
800 //Remove slashes from end
801 id = cffStripURLParts( id.replace(/\/$/, "").trim() );
802 //Only return if it contains numbers/letters
803 if( id.match("^[A-Za-z0-9]+$") ) return id;
804 }
805
806 //Show the modal by default, but hide if the "cffnomodal" class is added to prevent it showing after saving settings
807 if( location.hash !== '#cffnomodal' ){
808 $('.cff_modal_tokens').removeClass('cffnomodal');
809 }
810
811 //Switch Page/Group app button in modal
812 jQuery("#cff_login_type").on('change', function() {
813 if ( jQuery("#cff_login_type option:selected").val() == 'group' ) {
814 jQuery('#cff_page_app').hide();
815 jQuery('#cff_group_app').css('display', 'inline-block');
816 } else {
817 jQuery('#cff_page_app').css('display', 'inline-block');
818 jQuery('#cff_group_app').hide();
819 }
820 });
821
822 //Load the admin share widgets
823 $('#cff-admin-show-share-links').on('click', function(){
824 $(this).fadeOut();
825 if( $('#cff-admin-share-links iframe').length == 0 ) $('#cff-admin-share-links').html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="https://wordpress.org/plugins/custom-facebook-feed/" data-text="Display your Facebook posts on your site your way using the Custom Facebook Feed WordPress plugin!" data-via="smashballoon" data-dnt="true">Tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?"http":"https";if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document, "script", "twitter-wjs");</script> <style type="text/css"> #twitter-widget-0{float: left; width: 82px !important;}.IN-widget{margin-right: 20px;}</style> <div id="fb-root" style="display: none;"></div><script>(function(d, s, id){var js, fjs=d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js=d.createElement(s); js.id=id; js.src="//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0"; fjs.parentNode.insertBefore(js, fjs);}(document, "script", "facebook-jssdk"));</script> <div class="fb-like" data-href="https://wordpress.org/plugins/custom-facebook-feed/" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true" style="display: block; float: left; margin-right: 5px;"></div><script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US </script> <script type="IN/Share" data-url="https://wordpress.org/plugins/custom-facebook-feed/"></script></div>');
826
827 setTimeout(function(){
828 $('#cff-admin-share-links').addClass('cff-show');
829 }, 500);
830 });
831
832 //Group app setup screenshot
833 jQuery('#cff-group-app-tooltip').on('hover', function(){
834 jQuery('#cff-group-app-screenshot').fadeIn(100);
835 }, function(){
836 jQuery('#cff-group-app-screenshot').fadeOut(100);
837 });
838
839 //Remove any duplicate groups
840 jQuery('.cff-group-admin').each(function(){
841 jQuery('.cff-groups-list #' + jQuery(this).attr('id') ).eq(1).hide();
842 });
843
844
845 //Show/hide mobile column setting
846 var cff_masonry_desktop_col = jQuery('#cff_cols').val(),
847 $cff_mobile_col_settings = jQuery('.cff-mobile-col-settings');
848 if( typeof cff_post_limit === 'undefined' ) cff_masonry_desktop_col = '1';
849
850 //Should we show anything initially?
851 if( cff_masonry_desktop_col == '1' ) $cff_mobile_col_settings.hide();
852 if( parseInt(cff_masonry_desktop_col) > 1 ){
853 $cff_mobile_col_settings.show();
854 }
855
856 jQuery('#cff_cols').on('change', function(){
857 cff_cols_num = parseInt( jQuery('#cff_cols').val() );
858
859 if(cff_cols_num > 1){
860 $cff_mobile_col_settings.slideDown(200);
861 } else {
862 $cff_mobile_col_settings.slideUp(200);
863 }
864 });
865
866 // notices
867
868 if (jQuery('#cff-notice-bar').length) {
869 jQuery('#wpadminbar').after(jQuery('#cff-notice-bar'));
870 jQuery('#wpcontent').css('padding-left', 0);
871 jQuery('#wpbody').css('padding-left', '20px');
872 jQuery('#cff-notice-bar').show();
873 }
874
875 jQuery('#cff-notice-bar .dismiss').on('click', function(e) {
876 e.preventDefault();
877 jQuery('#cff-notice-bar').remove();
878 jQuery.ajax({
879 url: cffA.ajax_url,
880 type: 'post',
881 data: {
882 action : 'cff_lite_dismiss',
883 cff_nonce: cffA.cff_nonce
884 },
885 success: function (data) {
886 }
887 });
888 });
889
890 jQuery('#cff-oembed-disable').on('click', function(e) {
891 e.preventDefault();
892 jQuery(this).addClass( 'loading' ).html('<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
893 jQuery.ajax({
894 url: cffA.ajax_url,
895 type: 'post',
896 data: {
897 action : 'cff_oembed_disable',
898 cff_nonce: cffA.cff_nonce
899 },
900 success: function (data) {
901 jQuery('#cff-oembed-disable').closest('p').html(data);
902 }
903 });
904
905 });
906
907 jQuery('.cff_show_gdpr_list').on('click', function(){
908 jQuery(this).closest('div').find('.cff_gdpr_list').slideToggle();
909 });
910 //Selecting a post style
911 jQuery('#cff_gdpr_setting').on('change', function(){
912 console.log('Slim Shady')
913 cffCheckGdprSetting( jQuery(this).val() );
914 });
915 function cffCheckGdprSetting(option) {
916 if( option == 'yes' ){
917 jQuery('.cff_gdpr_yes').show();
918 jQuery('.cff_gdpr_no, .cff_gdpr_auto').hide();
919 }
920 if( option == 'no' ){
921 jQuery('.cff_gdpr_no').show();
922 jQuery('.cff_gdpr_yes, .cff_gdpr_auto').hide();
923 }
924 if( option == 'auto' ){
925 jQuery('.cff_gdpr_auto').show();
926 jQuery('.cff_gdpr_yes, .cff_gdpr_no').hide();
927 }
928 }
929 cffCheckGdprSetting(jQuery('#cff_gdpr_setting').val());
930
931 //sb_instagram_enable_email_report
932 function cffToggleEmail() {
933 if (jQuery('#cff_enable_email_report').is(':checked')) {
934 jQuery('#cff_enable_email_report').closest('td').find('.cff_box').slideDown();
935 } else {
936 jQuery('#cff_enable_email_report').closest('td').find('.cff_box').slideUp();
937 }
938 }cffToggleEmail();
939 jQuery('#cff_enable_email_report').on('change', cffToggleEmail);
940 if (jQuery('#cff-goto').length) {
941 jQuery('#cff-goto').closest('tr').addClass('cff-goto');
942 $('html, body').animate({
943 scrollTop: $('#cff-goto').offset().top - 200
944 }, 500);
945 }
946
947 jQuery('.cff-error-directions .cff-reconnect').on('click', function(){
948 event.preventDefault();
949 jQuery('.cff_admin_btn').trigger('click');
950 });
951 jQuery('.cff-clear-errors-visit-page').on('click', function(event) {
952 event.preventDefault();
953 var $btn = jQuery(this);
954 $btn.prop( 'disabled', true ).addClass( 'loading' ).html('<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
955 $.ajax({
956 url : cffA.ajax_url,
957 type : 'post',
958 data : {
959 action : 'cff_reset_log'
960 },
961 success : function(data) {
962 window.location.href = $btn.attr('data-url');
963 },
964 error : function(data) {
965 window.location.href = $btn.attr('data-url');
966 }
967 }); // ajax call
968 });
969
970 /* removing padding */
971 if (jQuery('#cff-admin-about').length) {
972 jQuery('#wpcontent').css('padding', 0);
973 }
974
975 //Click event for other plugins in menu
976 $('.cff_get_sbr, .cff_get_sbi, .cff_get_cff, .cff_get_ctf, .cff_get_yt, .cff_get_tiktok').parent().on('click', function(e){
977 e.preventDefault();
978
979 // remove the already opened modal
980 jQuery('#cff-op-modals').remove();
981
982 // prepend the modal wrapper
983 $('#wpbody-content').prepend('<div class="cff-fb-source-ctn sb-fs-boss cff-fb-center-boss" id="cff-op-modals"><i class="fa fa-spinner fa-spin cff-loader" aria-hidden="true"></i></div>');
984
985 // determine the plugin name
986 var $self = $(this).find('span'),
987 sb_get_plugin = 'twitter';
988
989 if( $self.hasClass('cff_get_cff') ){
990 sb_get_plugin = 'facebook';
991 } else if( $self.hasClass('cff_get_sbi') ){
992 sb_get_plugin = 'instagram';
993 } else if( $self.hasClass('cff_get_yt') ){
994 sb_get_plugin = 'youtube';
995 } else if( $self.hasClass('cff_get_sbr') ){
996 sb_get_plugin = 'reviews';
997 } else if( $self.hasClass('cff_get_tiktok') ){
998 sb_get_plugin = 'tiktok';
999 }
1000
1001 // send the ajax request to load plugin name and others data
1002 $.ajax({
1003 url : cffA.ajax_url,
1004 type : 'post',
1005 data : {
1006 action : 'sb_other_plugins_modal',
1007 plugin : sb_get_plugin,
1008 cff_nonce : cffA.cff_nonce,
1009
1010 },
1011 success : function(data) {
1012 if ( data.success == true ) {
1013 $('#cff-op-modals').html(data.data.output);
1014 }
1015 },
1016 error : function(e) {
1017 console.log(e);
1018 }
1019 });
1020 });
1021
1022 /**
1023 * Install other plugin on modal
1024 *
1025 * @since 4.0
1026 */
1027 $(document).on('click', '#cff_install_op_btn', function() {
1028 let self = $(this);
1029 let pluginAtts = self.data('plugin-atts');
1030 if ( pluginAtts.step == 'install' ) {
1031 pluginAtts.plugin = pluginAtts.download_plugin
1032 }
1033 let loader = '<span class="cff-btn-spinner"><svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="20px" height="20px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve"><path fill="#fff" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform></path></svg></span>';
1034 self.prepend(loader);
1035
1036 // send the ajax request to install or activate the plugin
1037 $.ajax({
1038 url : cffA.ajax_url,
1039 type : 'post',
1040 data : {
1041 action : pluginAtts.action,
1042 nonce : pluginAtts.nonce,
1043 plugin : pluginAtts.plugin,
1044 download_plugin : pluginAtts.download_plugin,
1045 type : 'plugin',
1046 },
1047 success : function(data) {
1048 if ( data.success == true ) {
1049 self.find('.cff-btn-spinner').remove();
1050 self.attr('disabled', 'disabled');
1051
1052 if ( pluginAtts.step == 'install' ) {
1053 self.html( data.data.msg );
1054 } else {
1055 self.html( data.data );
1056 }
1057 }
1058 },
1059 error : function(e) {
1060 console.log(e);
1061 }
1062 });
1063 });
1064
1065 jQuery('body').on('click', '#cff_review_consent_yes', function(e) {
1066 let reviewStep1 = jQuery('.cff_review_notice_step_1, .cff_review_step1_notice');
1067 let reviewStep2 = jQuery('.cff_notice.cff_review_notice, .rn_step_2');
1068
1069 reviewStep1.hide();
1070 reviewStep2.show();
1071
1072 $.ajax({
1073 url : cffA.ajax_url,
1074 type : 'post',
1075 data : {
1076 action : 'cff_review_notice_consent_update',
1077 consent : 'yes'
1078 },
1079 success : function(data) {
1080 }
1081 }); // ajax call
1082
1083 });
1084
1085 jQuery('body').on('click', '#cff_review_consent_no', function(e) {
1086 let reviewStep1 = jQuery('.cff_review_notice_step_1, #cff-notifications');
1087 reviewStep1.hide();
1088
1089 $.ajax({
1090 url : cffA.ajax_url,
1091 type : 'post',
1092 data : {
1093 action : 'cff_review_notice_consent_update',
1094 consent : 'no'
1095 },
1096 success : function(data) {
1097 }
1098 }); // ajax call
1099
1100 });
1101
1102 //Close the modal if clicking anywhere outside it
1103 jQuery('body').on('click', '#cff-op-modals', function(e){
1104 if (e.target !== this) return;
1105 jQuery('#cff-op-modals').remove();
1106 });
1107 jQuery('body').on('click', '.cff-fb-popup-cls', function(e){
1108 jQuery('#cff-op-modals').remove();
1109 });
1110
1111 //Add class to Pro menu item
1112 $('.cff_get_pro').parent().attr({'class':'cff_get_pro_highlight', 'target':'_blank'});
1113
1114 // Locator
1115 jQuery('.cff-locator-more').click(function(e) {
1116 e.preventDefault();
1117 jQuery(this).closest('td').find('.cff-full-wrap').show();
1118 jQuery(this).closest('td').find('.cff-condensed-wrap').hide();
1119 jQuery(this).remove();
1120 });
1121
1122
1123 //cff_reset_log
1124 var $cffClearLog = $('#cff_reset_log');
1125
1126 $cffClearLog.on('click', function(event) {
1127 event.preventDefault();
1128
1129 jQuery('#cff-clear-cache-success').remove();
1130 jQuery(this).prop("disabled",true);
1131
1132 $.ajax({
1133 url : cffA.ajax_url,
1134 type : 'post',
1135 data : {
1136 action : 'cff_clear_error_log'
1137 },
1138 success : function(data) {
1139 $cffClearLog.prop('disabled',false);
1140 if(data=='1') {
1141 $cffClearLog.after('<i id="cff-clear-cache-success" class="fa fa-check-circle cff-success"></i>');
1142 } else {
1143 $cffClearLog.after('<span>error</span>');
1144 }
1145 }
1146 }); // ajax call
1147 }); // clear_error_log click
1148
1149 // oEmbed Reconnect
1150 $(document).on('click', '.sb-reconnect-oembed', function() {
1151 let oembedConnectUrl = cff_admin.oembed_connectionURL.connect,
1152 appendURL = cff_admin.oembed_connectionURL.stateURL;
1153
1154 const urlParams = {
1155 'cff_con': cff_admin.oembed_connectionURL.cff_con,
1156 'state': "{'{url=" + appendURL + "}'}"
1157 }
1158
1159 let form = document.createElement('form');
1160 form.setAttribute('method', 'post');
1161 form.setAttribute('action', oembedConnectUrl);
1162
1163 for (const key in urlParams) {
1164 if (urlParams.hasOwnProperty(key)) {
1165 let hiddenField = document.createElement('input');
1166 hiddenField.setAttribute('type', 'hidden');
1167 hiddenField.setAttribute('name', key);
1168 hiddenField.setAttribute('value', urlParams[key]);
1169 form.appendChild(hiddenField);
1170 }
1171 }
1172
1173 document.body.appendChild(form);
1174
1175 // Same one-shot marker the oEmbeds page sets: the connect service returns none of our
1176 // parameters, so without it the returned token is refused on return. Only leave the site
1177 // once the marker is recorded, or the whole Facebook round-trip is wasted.
1178 $.post( cff_admin.ajax_url, {
1179 action: 'cff_oembed_connect_init',
1180 nonce: cff_admin.nonce
1181 } ).done( function( res ) {
1182 if ( res && res.success ) {
1183 form.submit();
1184 } else {
1185 console.error( 'CFF: could not record oEmbed connect start', res );
1186 }
1187 } ).fail( function( err ) {
1188 console.error( 'CFF: could not record oEmbed connect start', err );
1189 } );
1190 });
1191
1192 $(document).on('click', '#oembed_api_change_reconnect .cff-notice-dismiss', function(e) {
1193 e.preventDefault();
1194 $('#oembed_api_change_reconnect').remove();
1195 });
1196
1197 });
1198
1199
1200
1201 /* global smash_admin, jconfirm, wpCookies, Choices, List */
1202
1203 (function($) {
1204
1205 'use strict';
1206
1207 // Global settings access.
1208 var s;
1209
1210 // Admin object.
1211 var SmashCFFAdmin = {
1212
1213 // Settings.
1214 settings: {
1215 iconActivate: '<i class="fa fa-toggle-on fa-flip-horizontal" aria-hidden="true"></i>',
1216 iconDeactivate: '<i class="fa fa-toggle-on" aria-hidden="true"></i>',
1217 iconInstall: '<i class="fa fa-cloud-download" aria-hidden="true"></i>',
1218 iconSpinner: '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>',
1219 mediaFrame: false
1220 },
1221
1222 /**
1223 * Start the engine.
1224 *
1225 * @since 1.3.9
1226 */
1227 init: function() {
1228
1229 // Settings shortcut.
1230 s = this.settings;
1231
1232 // Document ready.
1233 $( document ).ready( SmashCFFAdmin.ready );
1234
1235 // Addons List.
1236 SmashCFFAdmin.initAddons();
1237 },
1238
1239 /**
1240 * Document ready.
1241 *
1242 * @since 1.3.9
1243 */
1244 ready: function() {
1245
1246 // Action available for each binding.
1247 $( document ).trigger( 'smashReady' );
1248 },
1249
1250 //--------------------------------------------------------------------//
1251 // Addons List.
1252 //--------------------------------------------------------------------//
1253
1254 /**
1255 * Element bindings for Addons List page.
1256 *
1257 * @since 1.3.9
1258 */
1259 initAddons: function() {
1260
1261 // Some actions have to be delayed to document.ready.
1262 $( document ).on( 'smashReady', function() {
1263
1264 // Only run on the addons page.
1265 if ( ! $( '#cff-admin-addons' ).length ) {
1266 return;
1267 }
1268
1269 // Display all addon boxes as the same height.
1270 if( $( '#cff-admin-about.cff-admin-wrap').length ){
1271 $( '#cff-admin-about .addon-item .details' ).matchHeight( { byrow: false, property: 'height' } );
1272 }
1273
1274 // Addons searching.
1275 if ( $('#cff-admin-addons-list').length ) {
1276 var addonSearch = new List( 'cff-admin-addons-list', {
1277 valueNames: [ 'addon-name' ]
1278 } );
1279
1280 $( '#cff-admin-addons-search' ).on( 'keyup', function () {
1281 var searchTerm = $( this ).val(),
1282 $heading = $( '#addons-heading' );
1283
1284 if ( searchTerm ) {
1285 $heading.text( cff_admin.addon_search );
1286 }
1287 else {
1288 $heading.text( $heading.data( 'text' ) );
1289 }
1290
1291 addonSearch.search( searchTerm );
1292 } );
1293 }
1294 });
1295
1296 // Toggle an addon state.
1297 $( document ).on( 'click', '#cff-admin-addons .addon-item button, .cff-notice-admin-btn', function( event ) {
1298
1299 event.preventDefault();
1300
1301 if ( $( this ).hasClass( 'disabled' ) ) {
1302 return false;
1303 }
1304
1305 SmashCFFAdmin.addonToggle( $( this ) );
1306 });
1307 },
1308 /**
1309 * Return possible plugins/addons URLs
1310 *
1311 * @since 1.3.9
1312 */
1313 filterPossibleAddonInstallation : function() {
1314 return cff_admin?.smashPlugins
1315 ? Object.values(cff_admin?.smashPlugins).map((singlePlugin) => singlePlugin.download_plugin)
1316 : [];
1317 },
1318 /**
1319 * Toggle addon state.
1320 *
1321 * @since 1.3.9
1322 */
1323 addonToggle: function( $btn ) {
1324
1325 var $addon = $btn.closest( '.addon-item' ),
1326 plugin = $btn.attr( 'data-plugin' ),
1327 plugin_type = $btn.attr( 'data-type' ),
1328 action,
1329 cssClass,
1330 statusText,
1331 buttonText,
1332 errorText,
1333 successText;
1334
1335 if ( $btn.hasClass( 'status-go-to-url' ) ) {
1336 const possibleUrls = this.filterPossibleAddonInstallation();
1337 const gotoUrl = $btn.attr('data-plugin');
1338 if (possibleUrls.includes(gotoUrl)) {
1339 window.open(gotoUrl, '_blank');
1340 }
1341 return;
1342 }
1343
1344 $btn.prop( 'disabled', true ).addClass( 'loading' );
1345 $btn.html( s.iconSpinner );
1346
1347 if ( $btn.hasClass( 'status-active' ) ) {
1348 // Deactivate.
1349 action = 'cff_deactivate_addon';
1350 cssClass = 'status-inactive';
1351 if ( plugin_type === 'plugin' ) {
1352 cssClass += ' button button-secondary';
1353 }
1354 statusText = cff_admin.addon_inactive;
1355 buttonText = cff_admin.addon_activate;
1356 if ( plugin_type === 'addon' ) {
1357 buttonText = s.iconActivate + buttonText;
1358 }
1359 errorText = s.iconDeactivate + cff_admin.addon_deactivate;
1360
1361 } else if ( $btn.hasClass( 'status-inactive' ) ) {
1362 // Activate.
1363 action = 'cff_activate_addon';
1364 cssClass = 'status-active';
1365 if ( plugin_type === 'plugin' ) {
1366 cssClass += ' button button-secondary disabled';
1367 }
1368 statusText = cff_admin.addon_active;
1369 buttonText = cff_admin.addon_deactivate;
1370 if ( plugin_type === 'addon' ) {
1371 buttonText = s.iconDeactivate + buttonText;
1372 } else if ( plugin_type === 'plugin' ) {
1373 buttonText = cff_admin.addon_activated;
1374 }
1375 errorText = s.iconActivate + cff_admin.addon_activate;
1376
1377 } else if ( $btn.hasClass( 'status-download' ) ) {
1378 // Install & Activate.
1379 action = 'cff_install_addon';
1380 cssClass = 'status-active';
1381 if ( plugin_type === 'plugin' ) {
1382 cssClass += ' button disabled';
1383 }
1384 statusText = cff_admin.addon_active;
1385 buttonText = cff_admin.addon_activated;
1386 if ( plugin_type === 'addon' ) {
1387 buttonText = s.iconActivate + cff_admin.addon_deactivate;
1388 }
1389 errorText = s.iconInstall + cff_admin.addon_activate;
1390
1391 } else {
1392 return;
1393 }
1394
1395 var data = {
1396 action: action,
1397 nonce : cff_admin.nonce,
1398 plugin: plugin,
1399 type : plugin_type
1400 };
1401 $.post( cff_admin.ajax_url, data, function( res ) {
1402 console.log(res)
1403 if ( res.success ) {
1404 if ( 'cff_install_addon' === action ) {
1405 $btn.attr( 'data-plugin', res.data.basename );
1406 successText = res.data.msg;
1407 if ( ! res.data.is_activated ) {
1408 cssClass = 'status-inactive';
1409 if ( plugin_type === 'plugin' ) {
1410 cssClass = 'button';
1411 }
1412 statusText = cff_admin.addon_inactive;
1413 buttonText = s.iconActivate + cff_admin.addon_activate;
1414 }
1415 } else {
1416 successText = res.data;
1417 }
1418 $addon.find( '.actions' ).append( '<div class="msg success">'+successText+'</div>' );
1419 $addon.find( 'span.status-label' )
1420 .removeClass( 'status-active status-inactive status-download' )
1421 .addClass( cssClass )
1422 .removeClass( 'button button-primary button-secondary disabled' )
1423 .text( statusText );
1424 $btn
1425 .removeClass( 'status-active status-inactive status-download' )
1426 .removeClass( 'button button-primary button-secondary disabled' )
1427 .addClass( cssClass ).html( buttonText );
1428 } else {
1429 if ( 'download_failed' === res.data[0].code ) {
1430 if ( plugin_type === 'addon' ) {
1431 $addon.find( '.actions' ).append( '<div class="msg error">'+cff_admin.addon_error+'</div>' );
1432 } else {
1433 $addon.find( '.actions' ).append( '<div class="msg error">'+cff_admin.plugin_error+'</div>' );
1434 }
1435 } else {
1436 $addon.find( '.actions' ).append( '<div class="msg error">'+res.data+'</div>' );
1437 }
1438 $btn.html( errorText );
1439 }
1440
1441 $btn.prop( 'disabled', false ).removeClass( 'loading' );
1442
1443 // Automatically clear addon messages after 3 seconds.
1444 setTimeout( function() {
1445 $( '.addon-item .msg' ).remove();
1446 }, 3000 );
1447
1448 }).fail( function( xhr ) {
1449 console.log( xhr.responseText );
1450 });
1451 },
1452
1453 };
1454
1455 SmashCFFAdmin.init();
1456
1457 window.SmashCFFAdmin = SmashCFFAdmin;
1458
1459 })( jQuery );