/wp-content/plugins/instagram-feed/js/sb-instagram-admin.js

https://gitlab.com/najomie/fit-hippie · JavaScript · 89 lines · 63 code · 17 blank · 9 comment · 23 complexity · 357ed33a19274ed675f3c3fd0990e07b MD5 · raw file

  1. jQuery(document).ready(function($) {
  2. //Autofill the token and id
  3. var hash = window.location.hash,
  4. token = hash.substring(14),
  5. id = token.split('.')[0];
  6. //If there's a hash then autofill the token and id
  7. if(hash){
  8. $('#sbi_config').append('<div id="sbi_config_info"><p><b>Access Token: </b><input type="text" size=58 readonly value="'+token+'" onclick="this.focus();this.select()" title="To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac)."></p><p><b>User ID: </b><input type="text" size=12 readonly value="'+id+'" onclick="this.focus();this.select()" title="To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac)."></p><p><i class="fa fa-clipboard" aria-hidden="true"></i>&nbsp; <b><span style="color: red;">Important:</span> Copy and paste</b> these into the fields below and click <b>"Save Changes"</b>.</p></div>');
  9. }
  10. //Tooltips
  11. jQuery('#sbi_admin .sbi_tooltip_link').click(function(){
  12. jQuery(this).siblings('.sbi_tooltip').slideToggle();
  13. });
  14. //Shortcode labels
  15. jQuery('#sbi_admin label').click(function(){
  16. var $sbi_shortcode = jQuery(this).siblings('.sbi_shortcode');
  17. if($sbi_shortcode.is(':visible')){
  18. jQuery(this).siblings('.sbi_shortcode').css('display','none');
  19. } else {
  20. jQuery(this).siblings('.sbi_shortcode').css('display','block');
  21. }
  22. });
  23. jQuery('#sbi_admin label').hover(function(){
  24. if( jQuery(this).siblings('.sbi_shortcode').length > 0 ){
  25. jQuery(this).attr('title', 'Click for shortcode option').append('<code class="sbi_shortcode_symbol">[]</code>');
  26. }
  27. }, function(){
  28. jQuery(this).find('.sbi_shortcode_symbol').remove();
  29. });
  30. //Add the color picker
  31. if( jQuery('.sbi_colorpick').length > 0 ) jQuery('.sbi_colorpick').wpColorPicker();
  32. //Check User ID is numeric
  33. jQuery("#sb_instagram_user_id").change(function() {
  34. var sbi_user_id = jQuery('#sb_instagram_user_id').val(),
  35. $sbi_user_id_error = $(this).closest('td').find('.sbi_user_id_error');
  36. if (sbi_user_id.match(/[^0-9, _.-]/)) {
  37. $sbi_user_id_error.fadeIn();
  38. } else {
  39. $sbi_user_id_error.fadeOut();
  40. }
  41. });
  42. //Mobile width
  43. var sb_instagram_feed_width = jQuery('#sbi_admin #sb_instagram_width').val(),
  44. sb_instagram_width_unit = jQuery('#sbi_admin #sb_instagram_width_unit').val(),
  45. $sb_instagram_width_options = jQuery('#sbi_admin #sb_instagram_width_options');
  46. if (typeof sb_instagram_feed_width !== 'undefined') {
  47. //Show initially if a width is set
  48. if( (sb_instagram_feed_width.length > 1 && sb_instagram_width_unit == 'px') || (sb_instagram_feed_width !== '100' && sb_instagram_width_unit == '%') ) $sb_instagram_width_options.show();
  49. jQuery('#sbi_admin #sb_instagram_width, #sbi_admin #sb_instagram_width_unit').change(function(){
  50. sb_instagram_feed_width = jQuery('#sbi_admin #sb_instagram_width').val();
  51. sb_instagram_width_unit = jQuery('#sbi_admin #sb_instagram_width_unit').val();
  52. if( sb_instagram_feed_width.length < 2 || (sb_instagram_feed_width == '100' && sb_instagram_width_unit == '%') ) {
  53. $sb_instagram_width_options.slideUp();
  54. } else {
  55. $sb_instagram_width_options.slideDown();
  56. }
  57. });
  58. }
  59. //Scroll to hash for quick links
  60. jQuery('#sbi_admin a').click(function() {
  61. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  62. var target = jQuery(this.hash);
  63. target = target.length ? target : this.hash.slice(1);
  64. if (target.length) {
  65. jQuery('html,body').animate({
  66. scrollTop: target.offset().top
  67. }, 500);
  68. return false;
  69. }
  70. }
  71. });
  72. });