| 1 |
(function ( $ ) { |
| 2 |
|
| 3 |
// Enable social sharing |
| 4 |
$('body').on('change', '#enable_share', function(e) { |
| 5 |
var target = $(this).closest('.cmb2-metabox').find('.cmb-row:not(.cmb2-id-enable-share)'); |
| 6 |
|
| 7 |
if( $(this).prop('checked') ) { |
| 8 |
target.slideDown('fast'); |
| 9 |
} else { |
| 10 |
target.slideUp('fast'); |
| 11 |
} |
| 12 |
|
| 13 |
}); |
| 14 |
|
| 15 |
// Initialize social settings visibility |
| 16 |
if( $('#enable_share').prop('checked') ) { |
| 17 |
$('#cmb2-metabox-social-settings').find('.cmb-row:not(.cmb2-id-enable-share)').show(); |
| 18 |
} else { |
| 19 |
$('#cmb2-metabox-social-settings').find('.cmb-row:not(.cmb2-id-enable-share)').hide(); |
| 20 |
} |
| 21 |
|
| 22 |
// Update social buttons preview |
| 23 |
function gamipress_update_social_buttons_preview() { |
| 24 |
|
| 25 |
// Get social networks selected |
| 26 |
var social_networks = []; |
| 27 |
|
| 28 |
$('input[name="social_networks[]"]:checked').each(function() { |
| 29 |
social_networks.push( $(this).val() ); |
| 30 |
}); |
| 31 |
|
| 32 |
// Get style selected |
| 33 |
var style = $('input[name="social_button_style"]:checked').val(); |
| 34 |
|
| 35 |
$('#social_buttons_preview').find('.gamipress-share-button').each(function() { |
| 36 |
|
| 37 |
$(this) |
| 38 |
.removeClass('gamipress-share-button-square') |
| 39 |
.removeClass('gamipress-share-button-rounded') |
| 40 |
.removeClass('gamipress-share-button-circle') |
| 41 |
.addClass('gamipress-share-button-' + style); |
| 42 |
|
| 43 |
if( social_networks.indexOf( $(this).data('network') ) !== -1 ) { |
| 44 |
$(this).show(); |
| 45 |
} else { |
| 46 |
$(this).hide(); |
| 47 |
} |
| 48 |
}); |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
// Initialize preview |
| 53 |
gamipress_update_social_buttons_preview(); |
| 54 |
|
| 55 |
// On change a social input, update the buttons preview |
| 56 |
$('body').on('change', 'input[name="social_networks[]"], input[name="social_button_style"]', function(e) { |
| 57 |
gamipress_update_social_buttons_preview(); |
| 58 |
}); |
| 59 |
|
| 60 |
// Send test email click |
| 61 |
$('#achievement-earned-email-send, #step-completed-email-send, #points-award-completed-email-send, #points-deduct-completed-email-send, #rank-earned-email-send, #rank-requirement-completed-email-send').on('click', function(e) { |
| 62 |
e.preventDefault(); |
| 63 |
|
| 64 |
var $this = $(this); |
| 65 |
|
| 66 |
$this.prop( 'disabled', true ); |
| 67 |
|
| 68 |
$this.parent().append('<span class="spinner is-active" style="float:none;"></span>'); |
| 69 |
|
| 70 |
$.ajax({ |
| 71 |
url: $this.attr('href'), |
| 72 |
method: 'get', |
| 73 |
success: function( response ) { |
| 74 |
$this.prop( 'disabled', false ); |
| 75 |
$this.parent().find('.spinner').remove(); |
| 76 |
$this.parent().append('<span class="send-response" ' + ( ! response.success ? 'style="color: #a00;' : '' ) + '">' + response.data + '</span>'); |
| 77 |
|
| 78 |
setTimeout(function() { |
| 79 |
$this.parent().find('.send-response').remove(); |
| 80 |
}, 3000); |
| 81 |
}, |
| 82 |
error: function( response ) { |
| 83 |
$this.prop( 'disabled', false ); |
| 84 |
$this.parent().find('.spinner').remove(); |
| 85 |
$this.parent().append('<span class="send-response" style="color: #a00;">' + response.data + '</span>'); |
| 86 |
|
| 87 |
setTimeout(function() { |
| 88 |
$this.parent().find('.send-response').remove(); |
| 89 |
}, 3000); |
| 90 |
} |
| 91 |
|
| 92 |
}); |
| 93 |
}); |
| 94 |
|
| 95 |
// Disable achievement earned email |
| 96 |
$('#disable_achievement_earned_email').on('change', function() { |
| 97 |
var target = $('.cmb2-id-achievement-earned-email-subject, .cmb2-id-achievement-earned-email-content'); |
| 98 |
|
| 99 |
if( $(this).prop('checked') ) { |
| 100 |
target.slideUp().addClass('cmb2-tab-ignore'); |
| 101 |
} else { |
| 102 |
target.slideDown().removeClass('cmb2-tab-ignore'); |
| 103 |
} |
| 104 |
} ); |
| 105 |
|
| 106 |
if( $('#disable_achievement_earned_email').prop('checked') ) { |
| 107 |
$('.cmb2-id-achievement-earned-email-subject, .cmb2-id-achievement-earned-email-content').hide().addClass('cmb2-tab-ignore'); |
| 108 |
} |
| 109 |
|
| 110 |
// Disable step completed email |
| 111 |
$('#disable_step_completed_email').on('change', function() { |
| 112 |
var target = $('.cmb2-id-step-completed-email-subject, .cmb2-id-step-completed-email-content'); |
| 113 |
|
| 114 |
if( $(this).prop('checked') ) { |
| 115 |
target.slideUp().addClass('cmb2-tab-ignore'); |
| 116 |
} else { |
| 117 |
target.slideDown().removeClass('cmb2-tab-ignore'); |
| 118 |
} |
| 119 |
} ); |
| 120 |
|
| 121 |
if( $('#disable_step_completed_email').prop('checked') ) { |
| 122 |
$('.cmb2-id-step-completed-email-subject, .cmb2-id-step-completed-email-content').hide().addClass('cmb2-tab-ignore'); |
| 123 |
} |
| 124 |
|
| 125 |
// Disable points awards completed email |
| 126 |
$('#disable_points_award_completed_email').on('change', function() { |
| 127 |
var target = $('.cmb2-id-points-award-completed-email-subject, .cmb2-id-points-award-completed-email-content'); |
| 128 |
|
| 129 |
if( $(this).prop('checked') ) { |
| 130 |
target.slideUp().addClass('cmb2-tab-ignore'); |
| 131 |
} else { |
| 132 |
target.slideDown().removeClass('cmb2-tab-ignore'); |
| 133 |
} |
| 134 |
} ); |
| 135 |
|
| 136 |
if( $('#disable_points_award_completed_email').prop('checked') ) { |
| 137 |
$('.cmb2-id-points-award-completed-email-subject, .cmb2-id-points-award-completed-email-content').hide().addClass('cmb2-tab-ignore'); |
| 138 |
} |
| 139 |
|
| 140 |
// Disable points deducts completed email |
| 141 |
$('#disable_points_deduct_completed_email').on('change', function() { |
| 142 |
var target = $('.cmb2-id-points-deduct-completed-email-subject, .cmb2-id-points-deduct-completed-email-content'); |
| 143 |
|
| 144 |
if( $(this).prop('checked') ) { |
| 145 |
target.slideUp().addClass('cmb2-tab-ignore'); |
| 146 |
} else { |
| 147 |
target.slideDown().removeClass('cmb2-tab-ignore'); |
| 148 |
} |
| 149 |
} ); |
| 150 |
|
| 151 |
if( $('#disable_points_deduct_completed_email').prop('checked') ) { |
| 152 |
$('.cmb2-id-points-deduct-completed-email-subject, .cmb2-id-points-deduct-completed-email-content').hide().addClass('cmb2-tab-ignore'); |
| 153 |
} |
| 154 |
|
| 155 |
// Disable rank earned email |
| 156 |
$('#disable_rank_earned_email').on('change', function() { |
| 157 |
var target = $('.cmb2-id-rank-earned-email-subject, .cmb2-id-rank-earned-email-content'); |
| 158 |
|
| 159 |
if( $(this).prop('checked') ) { |
| 160 |
target.slideUp().addClass('cmb2-tab-ignore'); |
| 161 |
} else { |
| 162 |
target.slideDown().removeClass('cmb2-tab-ignore'); |
| 163 |
} |
| 164 |
} ); |
| 165 |
|
| 166 |
if( $('#disable_rank_earned_email').prop('checked') ) { |
| 167 |
$('.cmb2-id-rank-earned-email-subject, .cmb2-id-rank-earned-email-content').hide().addClass('cmb2-tab-ignore'); |
| 168 |
} |
| 169 |
|
| 170 |
// Disable rank requirement completed email |
| 171 |
$('#disable_rank_requirement_completed_email').on('change', function() { |
| 172 |
var target = $('.cmb2-id-rank-requirement-completed-email-subject, .cmb2-id-rank-requirement-completed-email-content'); |
| 173 |
|
| 174 |
if( $(this).prop('checked') ) { |
| 175 |
target.slideUp().addClass('cmb2-tab-ignore'); |
| 176 |
} else { |
| 177 |
target.slideDown().removeClass('cmb2-tab-ignore'); |
| 178 |
} |
| 179 |
} ); |
| 180 |
|
| 181 |
if( $('#disable_rank_requirement_completed_email').prop('checked') ) { |
| 182 |
$('.cmb2-id-rank-requirement-completed-email-subject, .cmb2-id-rank-requirement-completed-email-content').hide().addClass('cmb2-tab-ignore'); |
| 183 |
} |
| 184 |
|
| 185 |
// Automatic updates |
| 186 |
$('#automatic_updates').on('change', function() { |
| 187 |
var target = $('.cmb2-id-automatic-updates-plugins'); |
| 188 |
|
| 189 |
if( target.length ) { |
| 190 |
if( $(this).prop('checked') ) { |
| 191 |
target.slideDown(); |
| 192 |
} else { |
| 193 |
target.slideUp(); |
| 194 |
} |
| 195 |
} |
| 196 |
} ); |
| 197 |
|
| 198 |
if( ! $('#automatic_updates').prop('checked') ) { |
| 199 |
$('.cmb2-id-automatic-updates-plugins').hide(); |
| 200 |
} |
| 201 |
|
| 202 |
// Fixed action buttons on settings |
| 203 |
$(window).on('scroll', function(e) { |
| 204 |
|
| 205 |
if( $(window).scrollTop() + $(window).height() > $(document).height() - 70 ) { |
| 206 |
$('.gamipress_settings input[name="submit-cmb"]').parent().removeClass('gamipress-sticky-bar') |
| 207 |
} else { |
| 208 |
$('.gamipress_settings input[name="submit-cmb"]').parent().addClass('gamipress-sticky-bar') |
| 209 |
} |
| 210 |
|
| 211 |
}); |
| 212 |
|
| 213 |
$(window).trigger('scroll') |
| 214 |
|
| 215 |
})( jQuery ); |
| 216 |
|
| 217 |
|