PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/ajax-load-more/admin/js/admin.js

https://gitlab.com/najomie/ljm
JavaScript | 432 lines | 283 code | 83 blank | 66 comment | 18 complexity | f5a593df8ead9811a95d53e34e4ee5e1 MD5 | raw file
  1. var _alm = _alm || {};
  2. jQuery(document).ready(function($) {
  3. "use strict";
  4. /*
  5. * Tooltipster
  6. * http://iamceege.github.io/tooltipster/
  7. *
  8. * @since 2.8.4
  9. */
  10. $('.tooltip').tooltipster({
  11. delay: 100,
  12. speed: 175,
  13. maxWidth: 400
  14. });
  15. /*
  16. * Button preview pane
  17. * Found on Settings and Shortcode Builder
  18. *
  19. * @since 2.8.4
  20. */
  21. $("select#alm_settings_btn_color").change(function() {
  22. var color = jQuery(this).val();
  23. // Remove other colors
  24. $('.ajax-load-more-wrap.core.preview-pane').removeClass('none');
  25. $('.ajax-load-more-wrap.core').removeClass('default');
  26. $('.ajax-load-more-wrap.core').removeClass('grey');
  27. $('.ajax-load-more-wrap.core').removeClass('purple');
  28. $('.ajax-load-more-wrap.core').removeClass('green');
  29. $('.ajax-load-more-wrap.core').removeClass('red');
  30. $('.ajax-load-more-wrap.core').removeClass('blue');
  31. $('.ajax-load-more-wrap.core').removeClass('white');
  32. $('.ajax-load-more-wrap.core').removeClass('infinite');
  33. $('.ajax-load-more-wrap.core').removeClass('skype');
  34. $('.ajax-load-more-wrap.core').removeClass('ring');
  35. $('.ajax-load-more-wrap.core').removeClass('fading-blocks');
  36. $('.ajax-load-more-wrap.core').removeClass('fading-circles');
  37. $('.ajax-load-more-wrap.core').removeClass('chasing-arrows');
  38. $('.ajax-load-more-wrap.core').addClass(color);
  39. });
  40. $("select#alm_settings_btn_color").click(function(e){
  41. e.preventDefault();
  42. });
  43. $('.alm-template-listing li a').click(function(e){
  44. e.preventDefault();
  45. var el = $(this),
  46. val = el.data('path');
  47. el.parent().parent().next('.template-selection').val(val);
  48. });
  49. $('.alm-template-section-nav li a').click(function(e){
  50. e.preventDefault();
  51. var el = $(this),
  52. index = el.parent().index(),
  53. parent = el.parent().parent().parent('.repeater-wrap');
  54. if(!el.hasClass('active')){
  55. el.parent().addClass('active').siblings().removeClass('active');
  56. $('.alm-template-toggle', parent).hide()
  57. $('.alm-template-toggle', parent).eq(index).show();
  58. }
  59. });
  60. /*
  61. * Mailchimp Signup
  62. * From the setting screen
  63. *
  64. * @since 2.7.2
  65. */
  66. $('form#alm-mc-embedded').submit(function() {
  67. var el = $('#alm-mailing-list'),
  68. email = $('input#mc_email', el).val(),
  69. data_path = $('form', el).data('path');
  70. // update user interface
  71. $('#response', el).fadeIn(250).addClass('loading');
  72. $('#response p', el).html('Adding email address...');
  73. // Verify email address
  74. if(!IsEmail(email)){
  75. $('#response p', el).html('<i class="fa fa-exclamation-circle"></i> Please enter a valid email address.');
  76. $('#response', el).removeClass('loading');
  77. $('#response', el).delay(2000).fadeOut(250);
  78. return false;
  79. }
  80. // Prepare query string and send AJAX request
  81. $.ajax({
  82. url: data_path,
  83. data: 'ajax=true&email=' + escape(email),
  84. success: function(msg) {
  85. $('#response', el).removeClass('loading');
  86. $('#response p', el).html(msg);
  87. },
  88. error: function() {
  89. $('#response', el).removeClass('loading').delay(2000).fadeOut(250);
  90. $('#response p', el).html('There was an error submitting your email address.');
  91. }
  92. });
  93. return false;
  94. });
  95. function IsEmail(email) {
  96. var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  97. return regex.test(email);
  98. }
  99. /*
  100. * _alm.copyToClipboard
  101. * Copy shortcode to clipboard
  102. *
  103. * @since 2.0.0
  104. */
  105. _alm.copyToClipboard = function(text) {
  106. window.prompt ("Copy link to your clipboard: Press Ctrl + C then hit Enter to copy.", text);
  107. }
  108. // Copy link on shortcode builder
  109. $('.output-wrap .copy').click(function(){
  110. var c = $('#shortcode_output').html();
  111. _alm.copyToClipboard(c);
  112. });
  113. // Copy link on repeater templates
  114. $('.alm-dropdown .copy a').click(function(){
  115. var container = $(this).closest('.repeater-wrap'), // find closet wrap
  116. el = container.data('name'); // get template name
  117. if(el === 'default') el = 'template-default';
  118. var c = $('#'+el).val(); // Get textarea val()
  119. _alm.copyToClipboard(c);
  120. });
  121. /*
  122. * Expand/Collapse shortcode headings
  123. *
  124. * @since 2.0.0
  125. */
  126. $(document).on('click', 'h3.heading', function(){
  127. var el = $(this);
  128. if($(el).hasClass('open')){
  129. $(el).next('.expand-wrap').slideDown(100, 'alm_easeInOutQuad', function(){
  130. $(el).removeClass('open');
  131. });
  132. }else{
  133. $(el).next('.expand-wrap').slideUp(100, 'alm_easeInOutQuad', function(){
  134. $(el).addClass('open');
  135. });
  136. }
  137. });
  138. $(document).on('click', '.toggle-all', function(){
  139. var el = $(this);
  140. if($(el).hasClass('closed')){
  141. $(el).removeClass('closed');
  142. $('h3.heading').removeClass('open');
  143. $('.expand-wrap').slideDown(100, 'alm_easeInOutQuad');
  144. }else{
  145. $(el).addClass('closed');
  146. $('h3.heading').addClass('open');
  147. $('.expand-wrap').slideUp(100, 'alm_easeInOutQuad');
  148. }
  149. });
  150. /*
  151. * Activate License
  152. *
  153. * @since 2.8.3
  154. */
  155. var almActivating = false;
  156. $(document).on('click', '.license-btn', function(e){
  157. e.preventDefault();
  158. if(!almActivating){
  159. $('.license-btn-wrap .msg').remove();
  160. almActivating = true;
  161. var el = $(this),
  162. wrap = el.closest('.license-btn-wrap'),
  163. parent = el.closest('.license'),
  164. type = el.data('type'),
  165. item = wrap.data('name'),
  166. url = wrap.data('url'),
  167. upgrade = wrap.data('upgrade-url'),
  168. status = wrap.data('option-status'),
  169. key = wrap.data('option-key'),
  170. license = parent.find('input[type=text]').val();
  171. $('.loading', parent).fadeIn(300);
  172. // Get value from Ajax
  173. $.ajax({
  174. type: 'GET',
  175. url: alm_admin_localize.ajax_admin_url,
  176. dataType: 'json',
  177. data: {
  178. action: 'alm_license_activation',
  179. nonce: alm_admin_localize.alm_admin_nonce,
  180. type: type,
  181. item: item,
  182. status: status,
  183. url: url,
  184. upgrade: upgrade,
  185. key: key,
  186. license: license,
  187. },
  188. success: function(data) {
  189. //console.log(data);
  190. if(data['msg']){
  191. $('.license-btn-wrap', parent).append('<div class="msg">'+data['msg']+'</div>');
  192. }
  193. if(data['license'] === 'valid'){
  194. $('.license-key-field .status', parent).addClass('active').removeClass('inactive').text(alm_admin_localize.active);
  195. $('.license-title .status', parent).addClass('valid').removeClass('invalid');
  196. $('.activate.license-btn', parent).addClass('hide');
  197. $('.deactivate.license-btn', parent).removeClass('hide');
  198. }else{
  199. $('.license-key-field .status', parent).removeClass('active').addClass('inactive').text(alm_admin_localize.inactive);
  200. $('.license-title .status', parent).removeClass('valid').addClass('invalid');
  201. $('.activate.license-btn', parent).removeClass('hide');
  202. $('.deactivate.license-btn', parent).addClass('hide');
  203. }
  204. $('.loading', parent).delay(250).fadeOut(300);
  205. almActivating = false;
  206. },
  207. error: function(xhr, status, error) {
  208. console.log(status);
  209. $('.loading', parent).delay(250).fadeOut(300);
  210. almActivating = false;
  211. }
  212. });
  213. }
  214. });
  215. /*
  216. * Get layout value Ajax
  217. *
  218. * @since 2.8.7
  219. */
  220. $(document).on('click', '.alm-layout-selection li a.layout', function(e){
  221. e.preventDefault();
  222. var el = $(this),
  223. type = el.data('type'),
  224. textarea = el.closest('.repeater-wrap').find('.CodeMirror'),
  225. layout_btn_text = el.html(),
  226. name = el.closest('.repeater-wrap').data('name');
  227. if(!el.hasClass('updating')){
  228. el.addClass('updating').text(alm_admin_localize.applying_layout+"...");
  229. textarea.addClass('loading');
  230. // Get editor ID
  231. var eid = '';
  232. if(name === 'default'){ // Default Template
  233. eid = window['editorDefault'];
  234. }else{ // Repeater Templates
  235. eid = window['editor_'+name]; // Set editor ID
  236. }
  237. // Get value from Ajax
  238. $.ajax({
  239. type: 'GET',
  240. url: alm_admin_localize.ajax_admin_url,
  241. data: {
  242. action: 'alm_layouts_get',
  243. type: type,
  244. nonce: alm_admin_localize.alm_admin_nonce,
  245. },
  246. dataType: "JSON",
  247. success: function(data) {
  248. eid.setValue(data.value);
  249. // Clear button styles
  250. setTimeout(function() {
  251. el.text(alm_admin_localize.template_updated).blur();
  252. setTimeout(function() {
  253. el.removeClass('updating').html(layout_btn_text).blur(); // CLose drop menu
  254. el.closest('.alm-drop-btn').trigger('click');
  255. textarea.removeClass('loading');
  256. }, 400);
  257. }, 400);
  258. },
  259. error: function(xhr, status, error) {
  260. console.log(status);
  261. textarea.removeClass('loading');
  262. }
  263. });
  264. }
  265. });
  266. /*
  267. * Dismiss Sharing (Transient)
  268. *
  269. * @since 2.8.7
  270. */
  271. $(document).on('click', '#alm_dismiss_sharing', function(e){
  272. e.preventDefault();
  273. var el = $(this),
  274. container = el.parent('.group');
  275. // Get value from Ajax
  276. $.ajax({
  277. type: 'POST',
  278. url: alm_admin_localize.ajax_admin_url,
  279. data: {
  280. action: 'alm_dismiss_sharing',
  281. nonce: alm_admin_localize.alm_admin_nonce,
  282. },
  283. success: function(data) {
  284. container.fadeOut();
  285. },
  286. error: function(xhr, status, error) {
  287. console.log(status);
  288. }
  289. });
  290. });
  291. /*
  292. * Scroll to setting section
  293. *
  294. * @since 2.7.3
  295. */
  296. $(document).on('change', '#alm-settings-nav', function(e){
  297. e.preventDefault();
  298. var el = $(this),
  299. index = el.val();
  300. if(index !== '#'){
  301. $('html, body').animate({
  302. scrollTop: $("#alm_OptionsForm h2").eq(index).offset().top - 40
  303. }, 500);
  304. }
  305. });
  306. /*
  307. * equalheight()
  308. *
  309. * @since 2.7.3
  310. */
  311. function equalheight(container){
  312. var currentTallest = 0,
  313. currentRowStart = 0,
  314. rowDivs = new Array(),
  315. $el,
  316. topPosition = 0;
  317. $(container).each(function() {
  318. $el = $(this);
  319. $($el).height('auto')
  320. topPosition = $el.position().top;
  321. if (currentRowStart != topPosition) {
  322. for (var currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
  323. rowDivs[currentDiv].height(currentTallest);
  324. }
  325. rowDivs.length = 0; // empty the array
  326. currentRowStart = topPosition;
  327. currentTallest = $el.height();
  328. rowDivs.push($el);
  329. } else {
  330. rowDivs.push($el);
  331. currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
  332. }
  333. for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
  334. rowDivs[currentDiv].height(currentTallest);
  335. }
  336. });
  337. }
  338. if($('#alm-add-ons').length){
  339. var addOnColumns = $('#alm-add-ons .group .expand-wrap');
  340. $(window).load(function() {
  341. equalheight(addOnColumns);
  342. });
  343. $(window).resize(function() {
  344. setTimeout(function(){
  345. equalheight(addOnColumns);
  346. }, 500);
  347. });
  348. }
  349. });