PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/squirrly-seo/themes/default/js/sq_blocksettingsseo.js

https://gitlab.com/memuller.web/wp_site
JavaScript | 307 lines | 227 code | 48 blank | 32 comment | 25 complexity | 858ad328b02eb21a8bcd2debfd76aedb MD5 | raw file
  1. if (jQuery('#sq_settings').length > 0) {
  2. sq_blocksettingsseo();
  3. } else {
  4. jQuery(document).ready(function () {
  5. sq_blocksettingsseo();
  6. });
  7. }
  8. function sq_blocksettingsseo() {
  9. ///////////////////////////////
  10. var snippet_timeout;
  11. //switch click
  12. jQuery('#sq_settings_form').find('input[name=sq_auto_title],input[name=sq_auto_description]').bind('click', function () {
  13. sq_getSnippet();
  14. });
  15. //Custom title/description
  16. jQuery('#sq_customize').bind('click', function () {
  17. jQuery('#sq_customize_settings').show();
  18. jQuery('#sq_snippet_disclaimer').show();
  19. jQuery('#sq_title_description_keywords').addClass('sq_custom_title');
  20. });
  21. jQuery('.sq_checkissues').bind('click', function () {
  22. location.href = '?page=sq_seo&action=sq_checkissues&nonce=' + jQuery('#sq_settings_form').find('input[name=nonce]').val();
  23. });
  24. //Listen the title field imput for snippet preview
  25. jQuery('#sq_settings').find('input[name=sq_fp_title]').bind('keyup', function () {
  26. if (snippet_timeout) {
  27. clearTimeout(snippet_timeout);
  28. }
  29. snippet_timeout = setTimeout(function () {
  30. sq_submitSettings();
  31. sq_getSnippet();
  32. }, 1000);
  33. sq_trackLength(jQuery(this), 'title');
  34. });
  35. //Listen the description field imput for snippet preview
  36. jQuery('#sq_settings').find('textarea[name=sq_fp_description]').bind('keyup', function () {
  37. if (snippet_timeout) {
  38. clearTimeout(snippet_timeout);
  39. }
  40. snippet_timeout = setTimeout(function () {
  41. sq_submitSettings();
  42. sq_getSnippet();
  43. }, 1000);
  44. sq_trackLength(jQuery(this), 'description');
  45. });
  46. jQuery('#sq_settings').find('input[name=sq_fp_keywords]').bind('keyup', function () {
  47. if (snippet_timeout) {
  48. clearTimeout(snippet_timeout);
  49. }
  50. snippet_timeout = setTimeout(function () {
  51. sq_submitSettings();
  52. }, 1000);
  53. });
  54. //Squirrly On/Off
  55. if (jQuery('#sq_settings').find('input[name=sq_auto_seo]').length > 0) {
  56. sq_getSnippet();
  57. }
  58. //Listen the favicon switch
  59. jQuery('#sq_auto_favicon1').bind('click', function () {
  60. jQuery('#sq_favicon').slideDown('fast');
  61. });
  62. jQuery('#sq_auto_favicon0').bind('click', function () {
  63. jQuery('#sq_favicon').slideUp('fast');
  64. });
  65. //Listen the favicon switch
  66. jQuery('#sq_auto_sitemap1').bind('click', function () {
  67. jQuery('#sq_sitemap').slideDown('fast');
  68. });
  69. jQuery('#sq_auto_sitemap0').bind('click', function () {
  70. jQuery('#sq_sitemap').slideUp('fast');
  71. });
  72. jQuery('#sq_auto_jsonld1').bind('click', function () {
  73. jQuery('#sq_jsonld').slideDown('fast');
  74. });
  75. jQuery('#sq_auto_jsonld0').bind('click', function () {
  76. jQuery('#sq_jsonld').slideUp('fast');
  77. });
  78. jQuery('.sq_social_link').bind('click', function () {
  79. var previewtop = jQuery('#sq_social_media_accounts').offset().top - 100;
  80. jQuery('html,body').animate({scrollTop: previewtop}, 1000);
  81. });
  82. //If select all options in sitemap
  83. jQuery('#sq_selectall').click(function () { //on click
  84. if (this.checked) { // check select status
  85. jQuery('#sq_sitemap_buid input').each(function () { //loop through each checkbox
  86. this.checked = true; //select all checkboxes with class "checkbox1"
  87. });
  88. } else {
  89. jQuery('#sq_sitemap_buid input').each(function () { //loop through each checkbox
  90. this.checked = false; //deselect all checkboxes with class "checkbox1"
  91. });
  92. }
  93. });
  94. //Listen the Squirrly Auto seo switch ON
  95. jQuery('#sq_use_on').bind('click', function () {
  96. jQuery('#sq_settings .sq_seo_switch_condition').show();
  97. jQuery('#sq_title_description_keywords').slideDown('fast');
  98. jQuery('#sq_social_media').slideDown('fast');
  99. if (jQuery('#sq_settings').find('input[name=sq_auto_sitemap]:checked').val() == 1) {
  100. jQuery('#sq_sitemap').slideDown('fast');
  101. }
  102. if (jQuery('#sq_settings').find('input[name=sq_auto_favicon]:checked').val() == 1) {
  103. jQuery('#sq_favicon').slideDown('fast');
  104. }
  105. if (jQuery('#sq_settings').find('input[name=sq_jsonld]:checked').val() == 1) {
  106. jQuery('#sq_jsonld').slideDown('fast');
  107. }
  108. if (parseInt(jQuery('.sq_count').html()) > 0) {
  109. var notif = (parseInt(jQuery('.sq_count').html()) - 1);
  110. if (notif > 0) {
  111. jQuery('.sq_count').html(notif);
  112. } else {
  113. jQuery('.sq_count').html(notif);
  114. jQuery('.sq_count').hide();
  115. }
  116. }
  117. jQuery('#sq_fix_auto').slideUp('show');
  118. });
  119. //Listen the Squirrly Auto seo switch OFF
  120. jQuery('#sq_use_off').bind('click', function () {
  121. jQuery('#sq_settings .sq_seo_switch_condition').hide();
  122. jQuery('#sq_title_description_keywords').slideUp('fast');
  123. jQuery('#sq_social_media').slideUp('fast');
  124. jQuery('#sq_favicon').slideUp('fast');
  125. jQuery('#sq_sitemap').slideUp('fast');
  126. jQuery('#sq_jsonld').slideUp('fast');
  127. if (parseInt(jQuery('.sq_count').html()) >= 0) {
  128. var notif = (parseInt(jQuery('.sq_count').html()) + 1);
  129. if (notif > 0) {
  130. jQuery('.sq_count').html(notif).show();
  131. }
  132. }
  133. jQuery('#sq_fix_auto').slideDown('show');
  134. });
  135. ///////////////////////////////
  136. ////////////////////FIX ACTIONS
  137. //FIX Google settings
  138. jQuery('#sq_google_index1').bind('click', function () {
  139. if (parseInt(jQuery('.sq_count').html()) > 0) {
  140. var notif = (parseInt(jQuery('.sq_count').html()) - 1);
  141. if (notif > 0) {
  142. jQuery('.sq_count').html(notif);
  143. } else {
  144. jQuery('.sq_count').html(notif);
  145. jQuery('.sq_count').hide();
  146. }
  147. }
  148. jQuery('#sq_fix_private').slideUp('show');
  149. });
  150. jQuery('#sq_google_index0').bind('click', function () {
  151. if (parseInt(jQuery('.sq_count').html()) >= 0) {
  152. var notif = (parseInt(jQuery('.sq_count').html()) + 1);
  153. if (notif > 0) {
  154. jQuery('.sq_count').html(notif).show();
  155. }
  156. }
  157. jQuery('#sq_fix_private').slideDown('show');
  158. });
  159. //JsonLD switch types
  160. jQuery('.sq_jsonld_type').bind('change', function () {
  161. jQuery('.sq_jsonld_types').hide();
  162. jQuery('.sq_jsonld_' + jQuery('#sq_settings').find('select[name=sq_jsonld_type] option:selected').val()).show();
  163. });
  164. //////////////////////////////////////////
  165. //Upload image from library
  166. jQuery('#sq_json_imageselect').bind('click', function (event) {
  167. var frame;
  168. event.preventDefault();
  169. // If the media frame already exists, reopen it.
  170. if (frame) {
  171. frame.open();
  172. return;
  173. }
  174. // Create a new media frame
  175. frame = wp.media({
  176. title: 'Select or Upload Media Of Your Chosen Persuasion',
  177. button: {
  178. text: 'Use this media'
  179. },
  180. multiple: false // Set to true to allow multiple files to be selected
  181. });
  182. // When an image is selected in the media frame...
  183. frame.on('select', function () {
  184. // Get media attachment details from the frame state
  185. var attachment = frame.state().get('selection').first().toJSON();
  186. // Send the attachment URL to our custom image input field.
  187. jQuery('input[name=sq_jsonld_logo]').val(attachment.url);
  188. });
  189. // Finally, open the modal on click
  190. frame.open();
  191. });
  192. }
  193. //Submit the settings
  194. function sq_submitSettings() {
  195. var sq_sitemap = [];
  196. var serialize = jQuery('#sq_settings').find('input[class=sq_sitemap]').serializeArray()
  197. jQuery(serialize).each(function () {
  198. sq_sitemap.push(jQuery(this).attr('value'));
  199. });
  200. var sq_sitemap_show = [];
  201. var serialize = jQuery('#sq_settings').find('input[class=sq_sitemap_show]').serializeArray()
  202. jQuery(serialize).each(function () {
  203. sq_sitemap_show.push(jQuery(this).attr('value'));
  204. });
  205. jQuery.post(
  206. sqQuery.ajaxurl,
  207. {
  208. action: 'sq_settingsseo_update',
  209. // --
  210. sq_use: jQuery('#sq_settings').find('input[name=sq_use]:checked').val(),
  211. sq_auto_title: jQuery('#sq_settings').find('input[name=sq_auto_title]:checked').val(),
  212. sq_auto_description: jQuery('#sq_settings').find('input[name=sq_auto_description]:checked').val(),
  213. sq_auto_canonical: jQuery('#sq_settings').find('input[name=sq_auto_canonical]:checked').val(),
  214. sq_auto_meta: jQuery('#sq_settings').find('input[name=sq_auto_meta]:checked').val(),
  215. sq_auto_favicon: jQuery('#sq_settings').find('input[name=sq_auto_favicon]:checked').val(),
  216. sq_auto_facebook: jQuery('#sq_settings').find('input[name=sq_auto_facebook]:checked').val(),
  217. sq_auto_twitter: jQuery('#sq_settings').find('input[name=sq_auto_twitter]:checked').val(),
  218. sq_auto_twittersize: jQuery('#sq_settings').find('input[name=sq_auto_twittersize]:checked').val(),
  219. sq_og_locale: jQuery('#sq_settings').find('select[name=sq_og_locale] option:selected').val(),
  220. //--
  221. sq_twitter_account: jQuery('#sq_settings').find('input[name=sq_twitter_account]').val(),
  222. sq_facebook_account: jQuery('#sq_settings').find('input[name=sq_facebook_account]').val(),
  223. sq_google_plus: jQuery('#sq_settings').find('input[name=sq_google_plus]').val(),
  224. sq_linkedin_account: jQuery('#sq_settings').find('input[name=sq_linkedin_account]').val(),
  225. //--
  226. sq_auto_sitemap: jQuery('#sq_settings').find('input[name=sq_auto_sitemap]:checked').val(),
  227. sq_auto_feed: jQuery('#sq_settings').find('input[name=sq_auto_feed]:checked').val(),
  228. sq_sitemap: sq_sitemap,
  229. sq_sitemap_show: sq_sitemap_show,
  230. sq_sitemap_frequency: jQuery('#sq_settings').find('select[name=sq_sitemap_frequency] option:selected').val(),
  231. sq_sitemap_ping: jQuery('#sq_settings').find('input[name=sq_sitemap_ping]:checked').val(),
  232. // --
  233. sq_auto_jsonld: jQuery('#sq_settings').find('input[name=sq_auto_jsonld]:checked').val(),
  234. sq_jsonld_type: jQuery('#sq_settings').find('select[name=sq_jsonld_type] option:selected').val(),
  235. sq_jsonld_name: jQuery('#sq_settings').find('input[name=sq_jsonld_name]').val(),
  236. sq_jsonld_jobTitle: jQuery('#sq_settings').find('input[name=sq_jsonld_jobTitle]').val(),
  237. sq_jsonld_logo: jQuery('#sq_settings').find('input[name=sq_jsonld_logo]').val(),
  238. sq_jsonld_telephone: jQuery('#sq_settings').find('input[name=sq_jsonld_telephone]').val(),
  239. sq_jsonld_contactType: jQuery('#sq_settings').find('select[name=sq_jsonld_contactType] option:selected').val(),
  240. sq_jsonld_description: jQuery('#sq_settings').find('textarea[name=sq_jsonld_description]').val(),
  241. //--
  242. sq_auto_seo: jQuery('#sq_settings').find('input[name=sq_auto_seo]:checked').val(),
  243. sq_fp_title: jQuery('#sq_settings').find('input[name=sq_fp_title]').val(),
  244. sq_fp_description: jQuery('#sq_settings').find('textarea[name=sq_fp_description]').val(),
  245. sq_fp_keywords: jQuery('#sq_settings').find('input[name=sq_fp_keywords]').val(),
  246. // --
  247. ignore_warn: jQuery('#sq_settings').find('input[name=ignore_warn]:checked').val(),
  248. // --
  249. sq_google_analytics: jQuery('#sq_settings').find('input[name=sq_google_analytics]').val(),
  250. sq_facebook_insights: jQuery('#sq_settings').find('input[name=sq_facebook_insights]').val(),
  251. sq_facebook_analytics: jQuery('#sq_settings').find('input[name=sq_facebook_analytics]').val(),
  252. sq_pinterest: jQuery('#sq_settings').find('input[name=sq_pinterest]').val(),
  253. // --
  254. nonce: sqQuery.nonce
  255. }
  256. ).done(function () {
  257. showSaved(2000);
  258. }, 'json');
  259. }