PluginProbe ʕ •ᴥ•ʔ
ShareThis Follow Buttons / 1.1.1
ShareThis Follow Buttons v1.1.1
1.4.7 trunk 1.0.1 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
sharethis-follow-buttons / js / admin.js
sharethis-follow-buttons / js Last commit date
admin.js 8 years ago blocks.js 6 years ago meta-box.js 8 years ago set-credentials.js 8 years ago
admin.js
784 lines
1 /**
2 * Follow Buttons.
3 *
4 * @package ShareThisFollowButtons
5 */
6
7 /* exported FollowButtons */
8 var FollowButtons = ( function( $, wp ) {
9 'use strict';
10
11 return {
12 /**
13 * Holds data.
14 */
15 data: {},
16
17 /**
18 * Boot plugin.
19 */
20 boot: function( data ) {
21 this.data = data;
22
23 $( document ).ready( function() {
24 this.init();
25 }.bind( this ) );
26 },
27
28 /**
29 * Initialize plugin.
30 */
31 init: function() {
32 this.$container = $( '.sharethis-wrap' );
33
34 // Get and set current accounts platform configurations to global.
35 this.$config = this.getConfig();
36
37 this.listen();
38 this.createReset();
39
40 // Check if platform has changed its button config.
41 this.checkIfChanged();
42
43 // Check if buttons are enabled or disabled on both ends.
44 this.markSelected();
45
46 // Check for non WP Share Buttons.
47 this.shareButtonsExists();
48 },
49
50 /**
51 * Initiate listeners.
52 */
53 listen: function() {
54 var self = this,
55 timer = '';
56
57 // On off button events.
58 this.$container.on( 'click', '.share-on, .share-off', function() {
59
60 // Revert to default color.
61 $( this ).closest( 'div' ).find( 'div.label-text' ).css( 'color', '#8d8d8d' );
62
63 // Change the input selected color to white.
64 $( this ).find( '.label-text' ).css( 'color', '#ffffff' );
65
66 // If turning on show recommendation notice.
67 if ( $( this ).hasClass( 'share-on' ) ) {
68 self.postPageTriggered();
69 }
70 } );
71
72 // Copy text from read only input fields.
73 this.$container.on( 'click', '#copy-shortcode, #copy-template', function() {
74 self.copyText( $( this ).closest( 'div' ).find( 'input' ) );
75 } );
76
77 // Open close options and update platform and WP on off status.
78 this.$container.on( 'click', '.enable-buttons .share-on, .enable-buttons .share-off', function() {
79 var type = $( this ).find( 'div.label-text' ).html();
80
81 self.updateButtons( 'inline-follow', type, 'click' );
82 } );
83
84 // Toggle button menus when arrows are clicked.
85 this.$container.on( 'click', 'span.st-arrow', function() {
86 var type = $( this ).html();
87
88 self.updateButtons( 'inline-follow', type, '' );
89 } );
90
91 // Click reset buttons.
92 this.$container.on( 'click', 'p.submit #reset', function() {
93 var type = $( this )
94 .closest( 'p.submit' )
95 .prev()
96 .find( '.enable-buttons' )
97 .attr( 'id' );
98
99 self.setDefaults( type );
100 } );
101
102 // Toggle margin control buttons.
103 this.$container.on( 'click', 'button.margin-control-button', function() {
104 var status = $( this ).hasClass( 'active-margin' );
105
106 self.activateMargin( this, status );
107 } );
108
109 // Button alignment.
110 this.$container.on( 'click', '.button-alignment .alignment-button', function() {
111 $( '.button-alignment .alignment-button[data-selected="true"]' )
112 .attr( 'data-selected', 'false' );
113 $( this ).attr( 'data-selected', 'true' );
114
115 self.loadPreview( '' );
116 } );
117
118 $( 'body' ).on( 'click', '.item label', function() {
119 var checked = $( this ).siblings( 'input' ).is( ':checked' );
120
121 $( '.sharethis-inline-follow-buttons' ).removeClass( 'st-has-labels' );
122
123 if ( ! checked ) {
124 $( this ).closest( '.st-radio-config' ).find( '.item' ).each( function() {
125 $( this ).find( 'input' ).prop( 'checked', false );
126 } );
127
128 $( this ).siblings( 'input' ).prop( 'checked', true );
129 }
130
131 self.loadPreview( '' );
132 } );
133
134 // All levers.
135 this.$container.on( 'click', '.item div.switch', function() {
136 self.loadPreview( '' );
137 } );
138
139 // CTA text.
140 this.$container.on( 'keyup', '.cta-text input', function() {
141 self.loadPreview( '' );
142 } );
143
144 // Minimum count.
145 this.$container.on( 'change', '#radius-selector', function() {
146 self.loadPreview( '' );
147 } );
148
149 // Add profile to network.
150 this.$container.on( 'keyup', '#st-network-urls .center-align .profile_link', function() {
151 clearTimeout( timer );
152
153 timer = setTimeout( function() {
154 self.loadPreview( '' );
155 }.bind( this ), 1000 );
156 } );
157
158 // Select or deselect a network.
159 this.$container.on( 'click', '.follow-buttons .follow-button', function() {
160 var selection = $( this ).attr( 'data-selected' ),
161 follow = $( this ).attr( 'data-network' );
162
163 if ( 'true' === selection ) {
164 $( this ).attr( 'data-selected', 'false' );
165 $( '.center-align[data-network="' + follow + '"]' ).attr( 'data-selected', 'false' );
166 $( '.sharethis-selected-networks > div > div[data-network="' + follow + '"]' ).remove();
167 } else {
168 $( this ).attr( 'data-selected', 'true' );
169 $( '.center-align[data-network="' + follow + '"]' ).attr( 'data-selected', 'true' );
170 $( '.sharethis-selected-networks > div' ).append( '<div class="st-btn" data-network="' + follow + '" style="display: inline-block;"></div>' );
171 }
172
173 self.loadPreview( '' );
174 } );
175
176 // Add class to preview when scrolled to.
177 $( window ).on( 'scroll', function() {
178 if ( undefined === $( '.selected-button' ).offset() ) {
179 return;
180 }
181
182 var stickyTop = $( '.selected-button' ).offset().top;
183
184 if ( $( window ).scrollTop() >= stickyTop ) {
185 $( '.sharethis-selected-networks' ).addClass( 'sharethis-prev-stick' );
186 } else {
187 $( '.sharethis-selected-networks' ).removeClass( 'sharethis-prev-stick' );
188 }
189 } );
190
191 // Submit configurations.
192 $( '.sharethis-wrap form' ).submit( function() {
193 self.loadPreview( 'submit', 'inline-follow' );
194 } );
195
196 // Tooltip.
197 this.$container.on( 'mouseover', '.tooltip-icon', function() {
198 var tooltip = $( this ).attr( 'data-tooltip' ),
199 position = $( this ).position(),
200 leftPos = position.left + 20,
201 topPos = position.top - 20;
202
203 $( '.tooltip-message-over' ).fadeIn( 500 ).html( tooltip ).css( { 'top': topPos + 'px', 'left': leftPos + 'px' } );
204 } );
205
206 // Tooltip out.
207 this.$container.on( 'mouseleave', '.tooltip-icon', function() {
208 $( '.tooltip-message-over' ).fadeOut( 500 );
209 } );
210
211 // Close notice.
212 $( 'body' ).on( 'click', '.notice-dismiss', function() {
213 $( this ).parent( '.notice.is-dismissible' ).hide();
214 } );
215 },
216
217 /**
218 * Change font color of selected buttons.
219 * Also decide whether to update WP enable / disable status or just show / hide menu options.
220 */
221 markSelected: function() {
222 var iConfigSet = null !== this.$config && undefined !== this.$config[ 'inline-follow-buttons' ],
223 iturnOn,
224 iturnOff,
225 inlineFollowEnable;
226
227 // Check if api call is successful and if inline buttons are enabled. Use WP data base if not.
228 if ( iConfigSet ) {
229 inlineFollowEnable = this.$config[ 'inline-follow-buttons' ][ 'enabled' ]; // Dot notation cannot be used due to dashes in name.
230 } else {
231 if ( undefined !== this.data.buttonConfig[ 'inline-follow' ] ) {
232 inlineFollowEnable = this.data.buttonConfig[ 'inline-follow' ][ 'enabled' ];
233 }
234 }
235
236 // Decide whether to update WP database or just show / hide menu options.
237 if ( ! iConfigSet || (
238 undefined !== this.data.buttonConfig[ 'inline-follow' ] && this.data.buttonConfig[ 'inline-follow' ][ 'enabled' ] === this.$config[ 'inline-follow-buttons' ][ 'enabled' ] ) ) { // Dot notation cannot be used due to dashes in name.
239 iturnOn = 'show';
240 iturnOff = 'hide';
241 } else {
242 iturnOn = 'On';
243 iturnOff = 'Off';
244 }
245
246 // If enabled show button configuration.
247 if ( 'true' === inlineFollowEnable || true === inlineFollowEnable ) {
248 $( '.inline-follow-platform' ).css( 'display', 'table-footer-group' );
249 this.updateButtons( 'inline-follow', iturnOn );
250 $( '#inline-follow label.share-on input' ).prop( 'checked', true );
251 } else {
252 $( '.inline-follow-platform' ).hide();
253 this.updateButtons( 'inline-follow', iturnOff );
254 $( '#inline-follow label.share-off input' ).prop( 'checked', true );
255 }
256
257 // Change button font color based on status.
258 $( '.share-on input:checked, .share-off input:checked' ).closest( 'label' ).find( 'span.label-text' ).css( 'color', '#ffffff' );
259 },
260
261 /**
262 * Check the platform has updated the button configs.
263 */
264 checkIfChanged: function() {
265 var iTs = this.$config[ 'inline-follow-buttons' ],
266 myITs = this.data.buttonConfig[ 'inline-follow' ];
267
268 // Set variables if array exists.
269 if ( undefined !== iTs ) {
270 iTs = iTs[ 'updated_at' ];
271
272 if ( undefined !== iTs ) {
273 iTs = iTs.toString();
274 }
275 }
276
277 if ( undefined !== myITs ) {
278 myITs = myITs[ 'updated_at' ];
279 }
280
281 // If platform has updated the button config or platform configs are broken use WP config.
282 if ( iTs !== myITs || undefined === this.data.buttonConfig ) {
283 this.setConfigFields( 'inline-follow', this.$config[ 'inline-follow-buttons' ], 'platform' );
284 } else {
285 this.loadPreview( 'initial', '' );
286 }
287 },
288
289 /**
290 * Show button configuration.
291 *
292 * @param button
293 * @param type
294 * @param event
295 */
296 updateButtons: function( button, type, event ) {
297 var pTypes = [ 'show', 'On', '', 'true' ],
298 aTypes = [ 'show', 'hide', '', '' ],
299 timer = '';
300
301 // If not one of the show types then hide.
302 if ( -1 !== $.inArray( type, pTypes ) ) {
303
304 // Show the button configs.
305 $( '.sharethis-wrap form .form-table tr' ).not( ':eq(0)' ).show();
306
307 // Show the submit / reset buttons.
308 $( '.sharethis-wrap form .submit' ).show();
309
310 // Change the icon next to title.
311 $( '.sharethis-wrap h2 span' ).html( '&#9660;' );
312
313 // Platform config.
314 $( '.inline-follow-platform' ).css( 'display', 'table-footer-group' );
315
316 if ( 'click' === event ) {
317 this.loadPreview( 'turnon', button );
318 }
319 } else {
320
321 // Hide the button configs.
322 $( '.sharethis-wrap form .form-table tr' ).not( ':eq(0)' ).hide();
323
324 // Hide the submit / reset buttons.
325 $( '.sharethis-wrap form .submit' ).hide();
326
327 // Change the icon next to title.
328 $( '.sharethis-wrap h2 span' ).html( '&#9658;' );
329
330 // Platform config.
331 $( '.inline-follow-platform' ).hide();
332
333 if ( 'click' === event ) {
334 this.loadPreview( 'turnoff', 'inline-follow' );
335 }
336 }
337 },
338
339 /**
340 * Copy text to clipboard
341 *
342 * @param copiedText
343 */
344 copyText: function( copiedText ) {
345 copiedText.select();
346 document.execCommand( 'copy' );
347 },
348
349 /**
350 * Add the reset buttons to share buttons menu
351 */
352 createReset: function() {
353 var button = '<input type="button" id="reset" class="button button-primary" value="Reset">',
354 newButtons = $( '.sharethis-wrap form .submit' ).append( button ).clone();
355 },
356
357 /**
358 * Set to default settings when reset is clicked.
359 *
360 * @param type
361 */
362 setDefaults: function( type ) {
363 wp.ajax.post( 'set_follow_default_settings', {
364 type: type,
365 nonce: this.data.nonce
366 } ).always( function() {
367 if ( 'both' !== type ) {
368 location.href = location.pathname + '?page=sharethis-follow-buttons&reset=' + type;
369 } else {
370 location.reload();
371 }
372 } );
373 },
374
375 /**
376 * Get current config data from user.
377 */
378 getConfig: function() {
379 var result = null;
380 $.ajax( {
381 url: 'https://platform-api.sharethis.com/v1.0/property/?secret=' + this.data.secret + '&id=' + this.data.propertyid,
382 method: 'GET',
383 async: false,
384 contentType: 'application/json; charset=utf-8',
385 success: function( results ) {
386 result = results;
387 }
388 } );
389
390 return result;
391 },
392
393 /**
394 * Activate specified option margin controls and show/hide
395 *
396 * @param marginButton
397 * @param status
398 */
399 activateMargin: function( marginButton, status ) {
400 if ( ! status ) {
401 $( marginButton ).addClass( 'active-margin' ).find( 'span.margin-on-off' ).html( 'On' );
402 $( marginButton ).siblings( 'div.margin-input-fields' ).show().find( 'input' ).prop( 'disabled', false );
403 } else {
404 $( marginButton ).removeClass( 'active-margin' ).find( 'span.margin-on-off' ).html( 'Off' );
405 $( marginButton ).siblings( 'div.margin-input-fields' ).hide().find( 'input' ).prop( 'disabled', true );
406 }
407 },
408
409 /**
410 * Set the settings fields for the button configurations.
411 *
412 * @param button
413 */
414 setConfigFields: function( button, config, type ) {
415 var size,
416 button = 'inline-follow';
417
418 if ( '' === config ) {
419 config = this.data.buttonConfig[ button ];
420 }
421
422 if ( undefined === config ) {
423 return;
424 }
425
426 $( '.follow-buttons .follow-button' ).each( function() {
427 $( this ).attr( 'data-selected', false );
428 } );
429
430 // Follows.
431 $.each( config[ 'networks' ], function( index, value ) {
432 $( '.follow-buttons .follow-button[data-network="' + value + '"]' ).attr( 'data-selected', 'true' );
433 $( '#st-network-urls .center-align[data-network="' + value + '"]' ).attr( 'data-selected', 'true' );
434 } );
435
436 // Alignment.
437 $( '.button-alignment .alignment-button[data-selected="true"]' ).attr( 'data-selected', 'false' );
438 $( '.button-alignment .alignment-button[data-alignment="' + config[ 'alignment' ] + '"]' ).attr( 'data-selected', 'true' );
439
440 // Label Position.
441 $( '.label-position .item input' ).prop( 'checked', false );
442 $( '.label-position #' + config['action_pos'] ).siblings( 'input' ).prop( 'checked', true );
443
444 // Profiles.
445 $.each( config.profiles, function( name, value ) {
446 $( '#st-network-urls .center-align[data-network="' + name + '"]' ).find( 'input.profile_link' ).val( value );
447 } );
448
449 // CTA.
450 $( 'div.call-to-action' ).find( 'input' ).prop( 'checked', ( 'false' !== config['action_enable'] && false !== config['action_enable'] ) );
451 $( '.cta-text input' ).val( config.action );
452
453 // Corners.
454 if ( parseInt( config.radius.toString().replace( 'px', '' ) ) > $( '#' + button + ' #radius-selector' ).attr( 'max' ) ) {
455 $( '#' + button + ' #radius-selector' ).attr( 'max', config.radius.toString().replace( 'px', '' ) );
456 $( '#' + button + ' #radius-selector' ).val( config.radius.toString().replace( 'px', '' ) );
457 } else {
458 $( '#' + button + ' #radius-selector' ).val( config.radius.toString().replace( 'px', '' ) );
459 }
460
461 // Size.
462 $( '.button-size .item input' ).prop( 'checked', false );
463
464 if ( '32' === config.size.toString() ) {
465 size = '#small';
466 }
467
468 if ( '40' === config.size.toString() ) {
469 size = '#medium';
470 }
471
472 if ( '48' === config.size.toString() ) {
473 size = '#large';
474 }
475
476 $( '.button-size ' + size ).siblings( 'input' ).prop( 'checked', true );
477
478 // Extra spacing.
479 $( 'div.extra-spacing' ).find( 'input' ).prop( 'checked', ( 0 !== config.spacing && '0' !== config.spacing ) );
480
481 if ( 'platform' === type ) {
482 this.loadPreview( 'initial-platform', button );
483 }
484 },
485
486 /**
487 * Check if share buttons are active and plugin doesn't exist.
488 */
489 shareButtonsExists: function() {
490 var needPlugin = ( ( undefined !== this.$config[ 'inline-share-buttons' ] || undefined !== this.$config[ 'sticky-share-buttons' ] ) && false === this.data.shareButtons );
491
492 if ( needPlugin ) {
493 this.$container.before(
494 '<div class="notice notice-error is-dismissible">' +
495 '<p>' +
496 'It appears you have share buttons enabled in your account, but do not have the ' +
497 '<strong>' +
498 'ShareThis Share Buttons' +
499 '</strong>' +
500 ' WordPress plugin installed or activated!' +
501 '</p>' +
502 '<p>' +
503 'Please go here: ' +
504 '<a href="https://wordpress.org/plugins/sharethis-share-buttons/" target="_blank">' +
505 'https://wordpress.org/plugins/sharethis-share-buttons/' +
506 '</a>' +
507 ' to download our plugin and utilize our Share Buttons with the power of WordPress!' +
508 '</p>' +
509 '</div>'
510 );
511 }
512 },
513
514 /**
515 * Check if share buttons are active and plugin doesn't exist.
516 */
517 postPageTriggered: function() {
518 if ( 0 === $( '.notice.follow-notice' ).length ) {
519 this.$container.before(
520 '<div class="notice notice-info is-dismissible follow-notice">' +
521 '<p>' +
522 'We recommending adding Follow Buttons to the header, footer or if available your sidebars if you are also using Share Buttons. You can do this with our' +
523 ' <a href="' + this.data.url + '/wp-admin/widgets.php">' +
524 'Widget' +
525 '</a>' +
526 ', Shortcode, or Template code.' +
527 '</p>' +
528 '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>' +
529 '</div>'
530 );
531 }
532 },
533
534 /**
535 * Load preview buttons.
536 *
537 * @param type
538 * @param button
539 */
540 loadPreview: function( type, button ) {
541 if ( 'initial' === type ) {
542 this.setConfigFields( 'inline-follow', '', '' );
543 }
544
545 var bAlignment = $( '.button-alignment .alignment-button[data-selected="true"]' ).attr( 'data-alignment' ),
546 self = this,
547 bSize = $( '.button-size .item input:checked' ).siblings( 'label' ).html(),
548 actionCopy = $( '.cta-text input' ).val(),
549 enableAction = $( '.cta-on-off' )
550 .find( 'input' )
551 .is( ':checked' ),
552 extraSpacing = $( '.extra-spacing' )
553 .find( 'input' )
554 .is( ':checked' ),
555 bRadius = $( '#radius-selector' ).val() + 'px',
556 lPosition = $( '.label-position .item input:checked' ).siblings( 'label' ).html(),
557 follows = [],
558 size,
559 spacing = 0,
560 padding,
561 fontSize,
562 config,
563 beforeConfig,
564 theFirst = false,
565 wpConfig,
566 timer = '',
567 upConfig,
568 theData,
569 enabled = false,
570 networkName,
571 networkProfile,
572 profiles = {};
573
574 if ( undefined !== lPosition ) {
575 lPosition = lPosition.toLowerCase();
576 }
577
578 $( '#st-network-urls .center-align[data-selected="true"]' ).each( function( index ) {
579 networkName = $( this ).attr( 'data-network' );
580 networkProfile = $( this ).find( '.profile_link' ).val();
581 profiles[ networkName ] = networkProfile;
582 } );
583
584 if ( 'Small' === bSize ) {
585 size = 32;
586 fontSize = 11;
587 padding = 8;
588
589 $( '#radius-selector' ).attr( 'max', 16 );
590 }
591
592 if ( 'Medium' === bSize ) {
593 size = 40;
594 fontSize = 12;
595 padding = 10;
596
597 $( '#radius-selector' ).attr( 'max', 20 );
598 }
599
600 if ( 'Large' === bSize ) {
601 size = 48;
602 fontSize = 16;
603 padding = 12;
604
605 $( '#radius-selector' ).attr( 'max', 26 );
606 }
607
608 if ( extraSpacing ) {
609 spacing = 8;
610 }
611
612 if ( 'initial' === type && undefined !== this.data.buttonConfig[ 'inline-follow' ][ 'networks' ] ) {
613 follows = this.data.buttonConfig[ 'inline-follow' ][ 'networks' ];
614 } else {
615 $( '.sharethis-selected-networks > div .st-btn' ).each( function( index ) {
616 follows[ index ] = $( this ).attr( 'data-network' );
617 } );
618 }
619
620 if ( 'sync-platform' === type && undefined !== this.$config[ 'inline-follow-buttons' ] ) {
621 follows = this.$config[ 'inline-follow-buttons' ][ 'networks' ];
622 }
623
624 // If newly turned on use selected networks.
625 if ( 'turnon' === type || undefined !== this.data.buttonConfig[ button ] && undefined === this.data.buttonConfig[ button ]['networks'] ) {
626 follows = [];
627
628 $( '.follow-buttons .follow-button[data-selected="true"]' ).each( function( index ) {
629 follows[ index ] = $( this ).attr( 'data-network' );
630 } );
631 }
632
633 if ( 'submit' === type ) {
634 follows = [];
635
636 $( '.sharethis-selected-networks > div .st-btn' ).each( function( index ) {
637 follows[ index ] = $( this ).attr( 'data-network' );
638 } );
639 }
640
641 // If submited or turned on make sure enabled setting is set properly.
642 if ( undefined !== this.$config[ 'inline-follow-buttons' ] && undefined !== this.$config[ 'inline-follow-buttons' ][ 'enabled' ] ) {
643 enabled = 'true' === this.$config[ 'inline-follow-buttons' ][ 'enabled' ] ||
644 true === this.$config[ 'inline-follow-buttons' ][ 'enabled' ] ||
645 true === this.$tempEnable;
646 } else {
647 enabled = false;
648 }
649
650 config = {
651 action: actionCopy,
652 action_enable: enableAction,
653 alignment: bAlignment,
654 networks: follows,
655 size: size,
656 radius: bRadius,
657 padding: padding,
658 action_pos: lPosition,
659 fontsize: fontSize,
660 spacing: spacing,
661 enabled: enabled,
662 profiles: profiles,
663 fade_in: false
664 };
665
666 // Set config for initial post.
667 beforeConfig = config;
668
669 if ( 'submit' === type || 'initial-platform' === type || 'turnon' === type || 'turnoff' === type ) {
670
671 // If submiting WP keep platform timestamp if exists.
672 if ( 'submit' === type && undefined !== this.$config[ 'inline-follow-buttons' ] && undefined !== this.$config[ 'inline-follow-buttons' ][ 'updated_at' ] ) {
673 config[ 'updated_at' ] = this.$config[ 'inline-follow-buttons' ][ 'updated_at' ];
674 }
675
676 // If platform different from WP.
677 if ( 'initial-platform' === type ) {
678 config = this.$config[ 'inline-follow-buttons' ];
679
680 if ( undefined === this.data.buttonConfig || true === this.data.buttonConfig ) {
681 theFirst = 'upgrade';
682 }
683 }
684
685 // If first load ever.
686 if ( 'initial-platform' === type && undefined !== this.data.buttonConfig[ 'inline-follow' ] && undefined === this.data.buttonConfig[ 'inline-follow' ][ 'updated_at' ] && undefined !== this.$config[ 'inline-follow-buttons' ][ 'updated_at' ] ) {
687 config = beforeConfig;
688 config.updated_at = this.$config[ 'inline-follow-buttons' ][ 'updated_at' ];
689 config.networks = this.data.buttonConfig[ 'inline-follow' ][ 'networks' ];
690 }
691
692 if ( 'turnon' === type ) {
693 config.enabled = true;
694 config.networks = [ 'facebook', 'twitter', 'instagram', 'youtube' ];
695
696 $.each( config.networks, function( index, value ) {
697 $( '.follow-buttons .follow-button[data-selected="' + value + '"]' ).attr( 'data-selected', 'true' );
698 } );
699
700 // Set temp enable to true.
701 this.$tempEnable = true;
702 }
703
704 if ( 'turnoff' === type ) {
705 config.enabled = false;
706
707 // Set temp enable to false.
708 this.$tempEnable = false;
709 }
710
711 if ( 'upgrade' === theFirst ) {
712 upConfig = {
713 'inline-follow': this.$config[ 'inline-follow-buttons' ]
714 };
715
716 wp.ajax.post( 'set_follow_button_config', {
717 button: 'platform',
718 config: upConfig,
719 first: theFirst,
720 type: 'login',
721 nonce: this.data.nonce
722 } ).always( function( results ) {
723 location.reload();
724 }.bind( this ) );
725 } else {
726 wp.ajax.post( 'set_follow_button_config', {
727 button: button,
728 config: config,
729 first: false,
730 nonce: this.data.nonce
731 } ).always( function( results ) {
732
733 if ( 'initial-platform' !== type || (
734 undefined !== this.data.buttonConfig[ button ] && undefined === this.data.buttonConfig[ button ][ 'updated_at' ]
735 ) ) {
736 config.enabled = 'true' === config.enabled || true === config.enabled;
737
738 delete config.container;
739 delete config.id;
740 delete config[ 'has_spacing' ];
741 delete config[ 'fade_in' ];
742 delete config[ 'show_mobile_buttons' ];
743
744 theData = JSON.stringify( {
745 'secret': this.data.secret,
746 'id': this.data.propertyid,
747 'product': 'inline-follow-buttons',
748 'config': config
749 } );
750
751 // Send new button status value.
752 $.ajax( {
753 url: 'https://platform-api.sharethis.com/v1.0/property/product',
754 method: 'POST',
755 async: false,
756 contentType: 'application/json; charset=utf-8',
757 data: theData,
758 success: function() {
759 if ( 'turnon' === type ) {
760 location.reload();
761 }
762 }
763 } );
764 }
765 }.bind( this ) );
766 }
767 }
768
769 $( '.sharethis-inline-follow-buttons' ).html( '' );
770
771 window.__sharethis__.href = 'https://www.sharethis.com/';
772 window.__sharethis__.load( 'inline-follow-buttons', config );
773
774 $( '.sharethis-selected-networks > div .st-btn' ).show();
775
776 $( '.sharethis-selected-networks > div' ).sortable( {
777 stop: function( event, ui ) {
778 self.loadPreview( '' );
779 }
780 } );
781 }
782 };
783 } )( window.jQuery, window.wp );
784