Advertisement
rudy317

recipe/assets/scripts/main.js

Jul 3rd, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. jQuery(function($){
  2. $("#recipe_rating").bind( "rated", function(){
  3. $(this).rateit( "readonly", true );
  4.  
  5. var form = {
  6. action: "r_rate_recipe",
  7. rid: $(this).data('rid'),
  8. rating: $(this).rateit( 'value' )
  9. };
  10.  
  11. $.post( recipe_obj.ajax_url, form, function(data){
  12.  
  13. });
  14. });
  15.  
  16. var featured_frame = wp.media({
  17. title: 'Select or Upload Media',
  18. button: {
  19. text: 'Use this media'
  20. },
  21. multiple: false
  22. });
  23.  
  24. $("#recipe-img-upload-btn").on('click', function(e){
  25. e.preventDefault();
  26. featured_frame.open();
  27. });
  28.  
  29. featured_frame.on('select', function(){
  30. var atachment = featured_frame.state().get('selection').first().toJSON();
  31. $("#recipe-img-preview").attr('src', attachment.url );
  32. $("#r_inputImgID").val(attachment.id);
  33. });
  34.  
  35. $("#recipe-form").on( "submit", function(e){
  36. e.preventDefault();
  37.  
  38. $(this).hide();
  39. $("#recipe-status").html('<div class="alert alert-info text-center">Please wait!</div>');
  40.  
  41. var form = {
  42. action: "r_submit_user_recipe",
  43. content: tinymce.activeEditor.getContent(),
  44. title: $("#r_inputTitle").val(),
  45. ingredients: $("#r_inputIngredients").val(),
  46. time: $("#r_inputTime").val(),
  47. utensils: $("#r_inputUtensils").val(),
  48. level: $("#r_inputLevel").val(),
  49. meal_type: $("#r_inputMealType").val(),
  50. attachment_id: $("r_inputImgID").val()
  51. };
  52.  
  53. $.post( recipe_obj.ajax_url, form ).always(function(data){
  54. if( data.status == 2 ){
  55. $('#recipe-status').html('<div class="alert alert-success">Recipe submitted successfully!</div>');
  56. }else{
  57. $('#recipe-status').html(
  58. '<div class="alert alert-danger">Unable to submit recipe. Please fill in all fields.</div>'
  59. );
  60. $("#recipe-form").show();
  61. }
  62. });
  63. });
  64.  
  65. $("#register-form").on('submit', function(e){
  66. e.preventDefault();
  67.  
  68. $("#register-status").html('<div class="alert alert-info">Please wait while your account is being created.</div>'
  69. );
  70. $(this).hide();
  71.  
  72. var form = {
  73. action: "recipe_create_account",
  74. name: $("#register-form-name").val(),
  75. username: $("#register-form-username").val(),
  76. email: $("#register-form-email").val(),
  77. pass: $("#register-form-password").val(),
  78. confirm_pass: $("#register-form-repassword").val(),
  79. _wpnonce: $("#_wpnonce").val()
  80. };
  81.  
  82. $.post(recipe_obj.ajax_url, form).always(function(response){
  83. if(response.status == 2){
  84. $("#register-status").html('<div class="alert alert-success">Account created!</div>');
  85. location.href = recipe_obj.home_url;
  86. }else{
  87. $("#register-status").html(
  88. '<div class="alert alert-danger">' +
  89. 'Unable to create an account. Please try again with a different username/email' +
  90. '</div>'
  91. );
  92. $("#register-form").show();
  93. }
  94. });
  95.  
  96. });
  97.  
  98. $("#login-form").on('submit', function(e){
  99. e.preventDefault();
  100.  
  101. $("#login-status").html('<div class="alert alert-info">Please wait while we log you in.</div>'
  102. );
  103. $(this).hide();
  104.  
  105. var form = {
  106. _wpnonce: $("#_wpnonce").val(),
  107. action: "recipe_user_login",
  108. username: $("#login-form-username").val(),
  109. pass: $("#login-form-password").val()
  110.  
  111. };
  112.  
  113. $.post(recipe_obj.ajax_url, form).always(function(data){
  114. if(data.status == 2 ){
  115. $("#login-status").html('<div class="alert alert-success">Success!</div>');
  116. location.href = recipe_obj.home_url;
  117. }else{
  118. $("#login-status").html(
  119. '<div class="alert alert-danger">' +
  120. 'Unable to login. Please try again with a different username/email' +
  121. '</div>'
  122. );
  123. $("#login-form").show();
  124. }
  125. });
  126.  
  127. });
  128. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement