cff-admin-scripts.js
315 lines
| 1 | jQuery(document).ready(function($) { |
| 2 | |
| 3 | //Tooltips |
| 4 | jQuery('#cff-admin .cff-tooltip-link').click(function(){ |
| 5 | jQuery(this).closest('tr, h3, div').find('.cff-tooltip').slideToggle(); |
| 6 | }); |
| 7 | |
| 8 | //Toggle Access Token field |
| 9 | if( jQuery('#cff_show_access_token').is(':checked') ) jQuery('.cff-access-token-hidden').show(); |
| 10 | jQuery('#cff_show_access_token').change(function(){ |
| 11 | jQuery('.cff-access-token-hidden').fadeToggle(); |
| 12 | }); |
| 13 | |
| 14 | |
| 15 | //Is this a page, group or profile? |
| 16 | var cff_page_type = jQuery('.cff-page-type select').val(), |
| 17 | $cff_page_type_options = jQuery('.cff-page-options'), |
| 18 | $cff_profile_error = jQuery('.cff-profile-error.cff-page-type'), |
| 19 | $cff_group_error = jQuery('.cff-group-error.cff-page-type'); |
| 20 | |
| 21 | //Should we show anything initially? |
| 22 | if(cff_page_type !== 'page') $cff_page_type_options.hide(); |
| 23 | if(cff_page_type == 'profile') $cff_profile_error.show(); |
| 24 | if(cff_page_type == 'group') $cff_group_error.show(); |
| 25 | |
| 26 | //When page type is changed show the relevant item |
| 27 | jQuery('.cff-page-type').change(function(){ |
| 28 | cff_page_type = jQuery('.cff-page-type select').val(); |
| 29 | |
| 30 | if( cff_page_type !== 'page' ) { |
| 31 | $cff_page_type_options.hide(); |
| 32 | if( cff_page_type == 'profile' ) { |
| 33 | $cff_profile_error.show(); |
| 34 | $cff_group_error.hide(); |
| 35 | } else if( cff_page_type == 'group' ) { |
| 36 | $cff_group_error.show(); |
| 37 | $cff_profile_error.hide(); |
| 38 | } else { |
| 39 | $cff_group_error.hide(); |
| 40 | $cff_profile_error.hide(); |
| 41 | } |
| 42 | |
| 43 | } else { |
| 44 | $cff_page_type_options.show(); |
| 45 | $cff_profile_error.hide(); |
| 46 | $cff_group_error.hide(); |
| 47 | } |
| 48 | }); |
| 49 | |
| 50 | |
| 51 | //Post limit manual setting |
| 52 | var cff_limit_setting = jQuery('#cff_limit_setting').val(), |
| 53 | cff_post_limit = jQuery('#cff_post_limit').val(), |
| 54 | $cff_limit_manual_settings = jQuery('#cff_limit_manual_settings'); |
| 55 | if( typeof cff_post_limit === 'undefined' ) cff_post_limit = ''; |
| 56 | |
| 57 | //Should we show anything initially? |
| 58 | if(cff_limit_setting == 'auto') $cff_limit_manual_settings.hide(); |
| 59 | if(cff_post_limit.length > 0){ |
| 60 | $cff_limit_manual_settings.show(); |
| 61 | jQuery('#cff_limit_setting').val('manual'); |
| 62 | } |
| 63 | |
| 64 | jQuery('#cff_limit_setting').change(function(){ |
| 65 | cff_limit_setting = jQuery('#cff_limit_setting').val(); |
| 66 | |
| 67 | if(cff_limit_setting == 'auto'){ |
| 68 | $cff_limit_manual_settings.hide(); |
| 69 | jQuery('#cff_post_limit').val(''); |
| 70 | } else { |
| 71 | $cff_limit_manual_settings.show(); |
| 72 | } |
| 73 | }); |
| 74 | |
| 75 | |
| 76 | //Header icon |
| 77 | //Icon type |
| 78 | //Check the saved icon type on page load and display it |
| 79 | jQuery('#cff-header-icon-example').removeClass().addClass('fa fa-' + jQuery('#cff-header-icon').val() ); |
| 80 | //Change the header icon when selected from the list |
| 81 | jQuery('#cff-header-icon').change(function() { |
| 82 | var $self = jQuery(this); |
| 83 | |
| 84 | jQuery('#cff-header-icon-example').removeClass().addClass('fa fa-' + $self.val() ); |
| 85 | }); |
| 86 | |
| 87 | |
| 88 | //Test Facebook API connection button |
| 89 | jQuery('#cff-api-test').click(function(e){ |
| 90 | e.preventDefault(); |
| 91 | //Show the JSON |
| 92 | jQuery('#cff-api-test-result textarea').css('display', 'block'); |
| 93 | }); |
| 94 | |
| 95 | |
| 96 | //If '__ days ago' date is selected then show 'Translate this' |
| 97 | var $cffTranslateDate = jQuery('#cff-translate-date'); |
| 98 | |
| 99 | if ( jQuery("#cff-date-formatting option:selected").val() == '1' ) $cffTranslateDate.show(); |
| 100 | |
| 101 | jQuery("#cff-date-formatting").change(function() { |
| 102 | if ( jQuery("#cff-date-formatting option:selected").val() == '1' ) { |
| 103 | $cffTranslateDate.fadeIn(); |
| 104 | } else { |
| 105 | $cffTranslateDate.fadeOut(); |
| 106 | } |
| 107 | }); |
| 108 | |
| 109 | //Selecting a post style |
| 110 | jQuery('.cff-post-style').click(function(){ |
| 111 | var $self = jQuery(this); |
| 112 | $('.cff_post_style').trigger('change'); |
| 113 | $self.addClass('cff-layout-selected').find('#cff_post_style').attr('checked', 'checked'); |
| 114 | $self.siblings().removeClass('cff-layout-selected'); |
| 115 | }); |
| 116 | function cffChangePostStyleSettings() { |
| 117 | setTimeout(function(){ |
| 118 | jQuery('.cff-post-style-settings').hide(); |
| 119 | jQuery('.cff-post-style-settings.cff-'+jQuery('.cff_post_style:checked').val()).show(); |
| 120 | }, 1); |
| 121 | } |
| 122 | cffChangePostStyleSettings(); |
| 123 | jQuery('.cff_post_style').change(cffChangePostStyleSettings); |
| 124 | |
| 125 | //Add the color picker |
| 126 | if( jQuery('.cff-colorpicker').length > 0 ) jQuery('.cff-colorpicker').wpColorPicker(); |
| 127 | |
| 128 | |
| 129 | //Mobile width |
| 130 | var cff_feed_width = jQuery('#cff-admin #cff_feed_width').val(), |
| 131 | $cff_width_options = jQuery('#cff-admin #cff_width_options'); |
| 132 | |
| 133 | if (typeof cff_feed_width !== 'undefined') { |
| 134 | //Show initially if a width is set |
| 135 | if(cff_feed_width.length > 1 && cff_feed_width !== '100%') $cff_width_options.show(); |
| 136 | |
| 137 | jQuery('#cff_feed_width').change(function(){ |
| 138 | cff_feed_width = jQuery(this).val(); |
| 139 | |
| 140 | if( cff_feed_width.length < 2 || cff_feed_width == '100%' ) { |
| 141 | $cff_width_options.slideUp(); |
| 142 | } else { |
| 143 | $cff_width_options.slideDown(); |
| 144 | } |
| 145 | }); |
| 146 | } |
| 147 | |
| 148 | //Scroll to hash for quick links |
| 149 | jQuery('#cff-admin a').click(function() { |
| 150 | if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { |
| 151 | var target = jQuery(this.hash); |
| 152 | target = target.length ? target : this.hash.slice(1); |
| 153 | if (target.length) { |
| 154 | jQuery('html,body').animate({ |
| 155 | scrollTop: target.offset().top |
| 156 | }, 500); |
| 157 | return false; |
| 158 | } |
| 159 | } |
| 160 | }); |
| 161 | |
| 162 | //Shortcode tooltips |
| 163 | jQuery('#cff-admin label').click(function(){ |
| 164 | var $el = jQuery(this); |
| 165 | var $cff_shortcode = $el.siblings('.cff_shortcode'); |
| 166 | if($cff_shortcode.is(':visible')){ |
| 167 | $el.siblings('.cff_shortcode').css('display','none'); |
| 168 | } else { |
| 169 | $el.siblings('.cff_shortcode').css('display','block'); |
| 170 | } |
| 171 | }); |
| 172 | jQuery('#cff-admin th').hover(function(){ |
| 173 | if( jQuery(this).find('.cff_shortcode').length > 0 ){ |
| 174 | jQuery(this).find('label').append('<code class="cff_shortcode_symbol">[]</code>'); |
| 175 | } |
| 176 | }, function(){ |
| 177 | jQuery(this).find('.cff_shortcode_symbol').remove(); |
| 178 | }); |
| 179 | jQuery('#cff-admin label').hover(function(){ |
| 180 | if( jQuery(this).siblings('.cff_shortcode').length > 0 ){ |
| 181 | jQuery(this).attr('title', 'Click for shortcode option'); |
| 182 | } |
| 183 | }, function(){}); |
| 184 | |
| 185 | //Open/close the expandable option sections |
| 186 | jQuery('.cff-expandable-options').hide(); |
| 187 | jQuery('.cff-expand-button a').on('click', function(e){ |
| 188 | e.preventDefault(); |
| 189 | var $self = jQuery(this); |
| 190 | $self.parent().next('.cff-expandable-options').toggle(); |
| 191 | if( $self.text().indexOf('Show') !== -1 ){ |
| 192 | $self.text( $self.text().replace('Show', 'Hide') ); |
| 193 | } else { |
| 194 | $self.text( $self.text().replace('Hide', 'Show') ); |
| 195 | } |
| 196 | }); |
| 197 | |
| 198 | //Facebook login |
| 199 | $('#cff_fb_login').on('click', function(){ |
| 200 | $('#cff_fb_login_modal').show(); |
| 201 | }); |
| 202 | $('#cff_admin_cancel_btn').on('click', function(){ |
| 203 | $('#cff_fb_login_modal').hide(); |
| 204 | }); |
| 205 | $('.cff-modal-close, #cff-close-modal-primary-button').on('click', function(){ |
| 206 | $('.cff_modal_tokens').hide(); |
| 207 | }); |
| 208 | $('#cff_fb_show_tokens').on('click', function(){ |
| 209 | $('.cff_modal_tokens, .cff-groups-list').show(); |
| 210 | $('#cff-group-installation').hide(); |
| 211 | }); |
| 212 | |
| 213 | //Select a page for token |
| 214 | $('.cff-managed-page').on('click', function(){ |
| 215 | $('#cff-insert-token, .cff-insert-reviews-token, .cff-insert-both-tokens').removeAttr('disabled'); |
| 216 | |
| 217 | $('#cff_token_expiration_note').show(); |
| 218 | |
| 219 | $(this).siblings().removeClass('cff-page-selected'); |
| 220 | $(this).addClass('cff-page-selected'); |
| 221 | }); |
| 222 | |
| 223 | //Insert Page Access Token |
| 224 | $('#cff-insert-token').on('click', function(){ |
| 225 | $('#cff_access_token').val( $('.cff-page-selected').attr('data-token') ).addClass('cff-success'); |
| 226 | if( $('#cff_page_id').val().trim() == '' ) $('#cff_page_id').val( $('.cff-page-selected').attr('data-page-id') ); |
| 227 | |
| 228 | if( $(this).hasClass('cff-group-btn') ){ |
| 229 | $('.cff-groups-list').hide(); |
| 230 | $('#cff-group-installation').show(); |
| 231 | |
| 232 | //Show directions for either group admin or member |
| 233 | if( $('.cff-page-selected').hasClass('cff-group-admin') ){ |
| 234 | $('#cff-group-admin-directions').show(); |
| 235 | $('#cff-group-member-directions').hide(); |
| 236 | } else { |
| 237 | $('#cff-group-admin-directions').hide(); |
| 238 | $('#cff-group-member-directions').show(); |
| 239 | } |
| 240 | |
| 241 | //Change page type to be group |
| 242 | $('#cff_page_type').val('group'); |
| 243 | $('.cff-page-options').hide(); |
| 244 | |
| 245 | //Dynamically create group edit link |
| 246 | var cffGroupEditLink = 'https://facebook.com/groups/'+$('.cff-page-selected').attr('data-page-id')+'/edit'; |
| 247 | $('#cff-group-installation #cff-group-edit').attr('href', cffGroupEditLink); |
| 248 | } else { |
| 249 | $('.cff_modal_tokens').hide(); |
| 250 | } |
| 251 | |
| 252 | location.hash = "cffnomodal"; |
| 253 | }); |
| 254 | |
| 255 | //Show the modal by default, but hide if the "cffnomodal" class is added to prevent it showing after saving settings |
| 256 | if( location.hash !== '#cffnomodal' ){ |
| 257 | $('.cff_modal_tokens').removeClass('cffnomodal'); |
| 258 | } |
| 259 | |
| 260 | //Switch Page/Group app button in modal |
| 261 | jQuery("#cff_login_type").change(function() { |
| 262 | if ( jQuery("#cff_login_type option:selected").val() == 'group' ) { |
| 263 | jQuery('#cff_page_app').hide(); |
| 264 | jQuery('#cff_group_app').css('display', 'inline-block'); |
| 265 | } else { |
| 266 | jQuery('#cff_page_app').css('display', 'inline-block'); |
| 267 | jQuery('#cff_group_app').hide(); |
| 268 | } |
| 269 | }); |
| 270 | |
| 271 | //Load the admin share widgets |
| 272 | $('#cff-admin-show-share-links').on('click', function(){ |
| 273 | $(this).fadeOut(); |
| 274 | 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>'); |
| 275 | |
| 276 | setTimeout(function(){ |
| 277 | $('#cff-admin-share-links').addClass('cff-show'); |
| 278 | }, 500); |
| 279 | }); |
| 280 | |
| 281 | //Group app setup screenshot |
| 282 | jQuery('#cff-group-app-tooltip').hover(function(){ |
| 283 | jQuery('#cff-group-app-screenshot').fadeIn(100); |
| 284 | }, function(){ |
| 285 | jQuery('#cff-group-app-screenshot').fadeOut(100); |
| 286 | }); |
| 287 | |
| 288 | //Remove any duplicate groups |
| 289 | jQuery('.cff-group-admin').each(function(){ |
| 290 | jQuery('.cff-groups-list #' + jQuery(this).attr('id') ).eq(1).hide(); |
| 291 | }); |
| 292 | |
| 293 | |
| 294 | //Show/hide mobile column setting |
| 295 | var cff_masonry_desktop_col = jQuery('#cff_cols').val(), |
| 296 | $cff_mobile_col_settings = jQuery('.cff-mobile-col-settings'); |
| 297 | if( typeof cff_post_limit === 'undefined' ) cff_masonry_desktop_col = '1'; |
| 298 | |
| 299 | //Should we show anything initially? |
| 300 | if( cff_masonry_desktop_col == '1' ) $cff_mobile_col_settings.hide(); |
| 301 | if( parseInt(cff_masonry_desktop_col) > 1 ){ |
| 302 | $cff_mobile_col_settings.show(); |
| 303 | } |
| 304 | |
| 305 | jQuery('#cff_cols').change(function(){ |
| 306 | cff_cols_num = parseInt( jQuery('#cff_cols').val() ); |
| 307 | |
| 308 | if(cff_cols_num > 1){ |
| 309 | $cff_mobile_col_settings.slideDown(200); |
| 310 | } else { |
| 311 | $cff_mobile_col_settings.slideUp(200); |
| 312 | } |
| 313 | }); |
| 314 | |
| 315 | }); |