Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.35 KB | None | 0 0
  1. $(document).ready(function(){
  2. $('.login-box').click(function(){
  3. $('.login-overlay').fadeToggle(100);
  4. $('.login-form,.register-form,.post-form,.announcement-form,.comment-form,.password-form').hide();
  5. $('.login-form').show();
  6. });
  7. $('.register-box').click(function(){
  8. $('.login-overlay').fadeToggle(100);
  9. $('.login-form,.register-form,.post-form,.announcement-form,.comment-form,.password-form').hide();
  10. $('.register-form').show();
  11. });
  12. $('.login-close').click(function(){
  13. //hides our login / register forms on close
  14. $('.login-overlay').fadeToggle(100);
  15. $('.login-form,.register-form,.post-form,.announcement-form,.comment-form,.password-form ').hide();
  16. //clear form as well
  17. $('input').each(function(){
  18. $(this).val('');
  19. });
  20. $('textarea').val('');
  21. });
  22. $('#login-activate').click(function(){
  23. //shows login form
  24. $('.login-form,.register-form,.post-form,.announcement-form,.comment-form,.password-form').fadeOut(300);
  25. setTimeout(function(){ $('.login-form').fadeIn(300); }, 300);
  26. });
  27. $('#submit-logged,.submit-logged').click(function(){
  28. $('.login-overlay').fadeToggle(100);
  29. $('.login-form,.register-form,.post-form,.announcement-form,.comment-form,.password-form').hide();
  30. $('.post-form').show();
  31. });
  32. $('#submit-unregistered').click(function(){
  33. $('.login-overlay').fadeToggle(100);
  34. $('.login-form,.register-form,.post-form,.announcement-form,.comment-form,.password-form').hide();
  35. $('.login-form').show();
  36. });
  37.  
  38. //for tag search, puts tag into searchbar
  39. $('.tag').click(function(){ //when clicking on our tag
  40. var tag = $(this).html(); //get tag value
  41. $("input[name='search']").val(tag); //set the search for our tag
  42. $('#searchform').submit(); //submits our search
  43. });
  44.  
  45. //dashbaord controlling logic
  46. $('#control-statistics,#control-posts,#control-comments,#control-users,#control-tags').click(function(){
  47. $('.nav > li').removeClass('active');
  48. $(this).addClass('active');
  49. var cls = $(this).attr('id');
  50. var toshow = cls.substr(cls.indexOf('-') + 1);
  51. $('.content-statistics,.content-posts,.content-comments,.content-users,.content-tags').hide();
  52. $('.content-' + toshow + '').show();
  53. $('.graph').show();
  54. });
  55.  
  56. //handler to submit search on 'enter'
  57. $("input").keypress(function(event) {
  58. if (event.which == 13) {
  59. if($('.login-overlay').is(':hidden') || $('#dailyID').attr('type') == 'hidden'){ //only submit search if our overlays aren't showing
  60. event.preventDefault();
  61. $("#searchform").submit();
  62. }else {
  63. //submit default
  64. }
  65. }
  66. });
  67.  
  68. $('#do-logout').click(function(){
  69. $.ajax({
  70. type: 'POST',
  71. url: '/processes/logout.php',
  72. cache: false,
  73. success: function (data) {
  74. location.href = '/';
  75. }
  76. });
  77. });
  78.  
  79. //description count
  80. $('textarea[name="description"]').keyup(function(event){
  81. var area = $(this).val();
  82. var arealength = $(this).val().length;
  83.  
  84. //sets color to be more visible if we're typing
  85. if(arealength > 0){
  86. $('.desc-count').css('color', '#565656');
  87. }else{
  88. $('.desc-count').css('color', '#ccc');
  89. }
  90.  
  91. if(arealength > 600){
  92. arealength = 600;
  93. area = area.substring(area, arealength - 1); //trims string if over length
  94. }
  95. $('.desc-count').html('(' + arealength + ' / 600)');
  96. $(this).val(area);
  97. });
  98.  
  99. //title count
  100. $('input[name="title"]').keyup(function(event){
  101. var input = $(this).val();
  102. var inputlength = $(this).val().length;
  103.  
  104. //sets color to be more visible if we're typing
  105. if(inputlength > 0){
  106. $('.title-count').css('color', '#565656');
  107. }else{
  108. $('.title-count').css('color', '#ccc');
  109. }
  110.  
  111. if(inputlength > 80){
  112. inputlength = 80;
  113. input = input.substring(input, inputlength - 1); //trims string if over length
  114. }
  115. $('.title-count').html('(' + inputlength + ' / 80)');
  116. $(this).val(input);
  117. });
  118.  
  119. //comment count
  120. $('textarea[name="comment"]').keyup(function(event){
  121. var input = $(this).val();
  122. var inputlength = $(this).val().length;
  123.  
  124. //sets color to be more visible if we're typing
  125. if(inputlength > 0){
  126. $('.comment-count').css('color', '#565656');
  127. }else{
  128. $('.comment-count').css('color', '#ccc');
  129. }
  130.  
  131. if(inputlength > 600){
  132. inputlength = 600;
  133. input = input.substring(input, inputlength - 1); //trims string if over length
  134. }
  135. $('.comment-count').html('(' + inputlength + ' / 600)');
  136. $(this).val(input);
  137. });
  138.  
  139.  
  140. //edit annoucement handler
  141. $('#edit-announcement').click(function(){
  142. $('.login-overlay').fadeToggle(100);
  143. $('.register-form').hide();
  144. $('.login-form').hide();
  145. $('.post-form').hide();
  146. var announcementtext = $('.announcement-para').text();
  147. $('#idDailyAnnouncement').val(announcementtext);
  148. $('.announcement-form').show();
  149. });
  150.  
  151. //gets our tags ready
  152. $('#idPostTags').keypress(function(event){
  153. var tags = $(this).val();
  154. if(event.which == 35){
  155. var strlength = tags.length;
  156. if(strlength > 1){
  157. var tags = tags + ',';
  158. }
  159. }else{
  160. var tags = tags.split(/[\s,]+/, 5), $t; //splits up our tags and limits to 5
  161. tags.join('').split(''); //gets rid of empty tags
  162. for ($t = 0; $t < tags.length; $t++){
  163. if((tags[$t].indexOf('#') === -1) && tags[$t] != ''){
  164. tags[$t] = '#' + tags[$t];
  165. }
  166. }
  167. }
  168. $(this).val(tags);
  169. });
  170.  
  171. //play video logic
  172. $('.content').on('click', 'i.pe-7s-play', function(){
  173. console.log('clicked');
  174. var videoid = $(this).attr('id');
  175. if( $("." + videoid + "").css('display') == 'none') {
  176. $("." + videoid + "").show();
  177. }
  178. else if( $("." + videoid + "").css('display') == 'block'){
  179. $("." + videoid + "").hide();
  180. $('.video-container').hide(); // hides all containers by default
  181. }
  182. });
  183.  
  184. $('.col-md-8').on('click', '.upvote', function() {
  185. if( $('#navUsername').length ){
  186. $(this).addClass('update-count');
  187. var vote = $(this).attr('data-vote');
  188. if($(this).attr('data-postID')){
  189. var postID = $(this).attr('data-postID');
  190. voteFormPosts(vote, postID);
  191. var message = '<div class="alert-message success-message"><div class="card feed"><p>Post Upvoted!</p></div></div>'
  192. var message = $(message);
  193. message.insertBefore('.card.post' + postID + '');
  194. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  195. }else if($(this).attr('data-commentID')){
  196. var commentID = $(this).attr('data-commentID');
  197. voteFormComments(vote, commentID);
  198. var message = '<div class="alert-message success-message"><div class="card feed"><p>Comment Upvoted!</p></div></div>'
  199. var message = $(message);
  200. message.insertBefore('.content.comment' + commentID + '');
  201. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  202. }
  203. }else{
  204. if($(this).attr('data-postID')) {
  205. var postID = $(this).attr('data-postID');
  206. var message = '<div class="alert-message delete-message"><div class="card feed"><p>You must be logged in to vote!</p></div></div>'
  207. var message = $(message);
  208. message.insertBefore('.card.post' + postID + '');
  209. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  210. }else if($(this).attr('data-commentID')){
  211. var commentID = $(this).attr('data-commentID');
  212. var message = '<div class="alert-message delete-message"><div class="card feed"><p>You must be logged in to vote!</p></div></div>'
  213. var message = $(message);
  214. message.insertBefore('.content.comment' + commentID + '');
  215. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  216. }
  217. }
  218. }).on('click', '.downvote', function(){
  219. if( $('#navUsername').length ){
  220. $(this).addClass('update-count');
  221. var vote = $(this).attr('data-vote');
  222. if($(this).attr('data-postID')){
  223. var postID = $(this).attr('data-postID');
  224. voteFormPosts(vote, postID);
  225. var message = '<div class="alert-message success-message"><div class="card feed"><p>Post Downvoted!</p></div></div>'
  226. var message = $(message);
  227. message.insertBefore('.card.post' + postID + '');
  228. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  229. }else if($(this).attr('data-commentID')){
  230. var commentID = $(this).attr('data-commentID');
  231. voteFormComments(vote, commentID);
  232. var message = '<div class="alert-message success-message"><div class="card feed"><p>Comment Downvoted!</p></div></div>'
  233. var message = $(message);
  234. message.insertBefore('.content.comment' + commentID + '');
  235. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  236. }
  237. }else{
  238. if($(this).attr('data-postID')) {
  239. var postID = $(this).attr('data-postID');
  240. var message = '<div class="alert-message delete-message"><div class="card feed"><p>You must be logged in to vote!</p></div></div>'
  241. var message = $(message);
  242. message.insertBefore('.card.post' + postID + '');
  243. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  244. }else if($(this).attr('data-commentID')) {
  245. var commentID = $(this).attr('data-commentID');
  246. var message = '<div class="alert-message delete-message"><div class="card feed"><p>You must be logged in to vote!</p></div></div>'
  247. var message = $(message);
  248. message.insertBefore('.content.comment' + commentID + '');
  249. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  250. }
  251. }
  252. });
  253.  
  254. function voteFormPosts(vote, postID) {
  255. $.ajax({
  256. type: 'POST',
  257. url: 'processes/votes.php',
  258. data: {vote: vote, postID: postID},
  259. cache: false,
  260. success: function (data) {
  261. $('.update-count').parent('span').parent('div').children('small').html(data);
  262. $('.update-count').removeClass('update-count');
  263. }
  264. });
  265. }
  266.  
  267. function voteFormComments(vote, commentID) {
  268. $.ajax({
  269. type: 'POST',
  270. url: 'processes/commentvotes.php',
  271. data: {vote: vote, commentID: commentID},
  272. cache: false,
  273. success: function (data) {
  274. $('.update-count').parent('span').parent('div').children('small').html(data);
  275. $('.update-count').removeClass('update-count');
  276. }
  277. });
  278. }
  279.  
  280. $('#comment-form-submit').click(function(){
  281. var comment = $(this).prev('.form-group').children('textarea[name="comment"]').val();
  282. var postID = $(this).prev('.form-group').children('input[name="postID"]').val();
  283. $.ajax({
  284. type: 'POST',
  285. url: '/processes/newcomment.php',
  286. data: {comment: comment, postID: postID},
  287. cache: false,
  288. success: function (data) {
  289. $('textarea[name="comment"]').parent('.form-group').prepend('<div class="alert-message success-message"><div class="card feed"><p>Comment Posted!</p></div></div>');
  290. setTimeout(function(){ location.reload(); },1000);
  291. }
  292. });
  293. });
  294.  
  295. var xhr;
  296.  
  297. $('input[name="user-filter-search"]').keyup(function(event) {
  298. var usersearch = $(this).val();
  299. if(xhr){
  300. xhr.abort();
  301. }
  302. xhr = $.ajax({
  303. type: 'POST',
  304. url: '/processes/users.php',
  305. data: {search: usersearch},
  306. cache: false,
  307. success: function (data) {
  308. $('.content-users .col-md-8').html(data);
  309. },
  310. error: function (data) {
  311. console.log(data);
  312. }
  313. });
  314. });
  315.  
  316. $('#post-form-submit').click(function(){
  317. var posttitle = $('input[name="title"]').val();
  318. var postdescription = $('textarea[name="description"]').val();
  319. var postlink = $('input[name="link"]').val();
  320. var primarycategory = $('select[name="primary-category"]').val();
  321. var secondarycategory = $('select[name="secondary-category"]').val();
  322. var posttags = $('input[name="tags"]').val();
  323. var postpostid = $('input[name="postid"]').val();
  324. if(posttags.length < 3){
  325. $('#post-form').prepend('<div class="alert-message delete-message"><div class="card feed"><p>Tags cannot be empty!</p></div></div>');
  326. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  327. }else{
  328. $.ajax({
  329. type: 'POST',
  330. url: '/processes/newpost.php',
  331. data: {postTitle:posttitle,postDescription:postdescription,postLink: postlink,primaryCategory:primarycategory,secondaryCategory:secondarycategory,postTags:posttags,postID:postpostid},
  332. cache: false,
  333. dataType: 'json',
  334. success: function (data) {
  335. console.log(data);
  336. console.log(data['success']);
  337. if(data['success']){
  338. //redirects to post page after successful post
  339. //console.log(data);
  340. $('#post-form').prepend('<div class="alert-message success-message"><div class="card feed"><p>' + data['message'] + '</p></div></div>');
  341. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  342. setTimeout(function(){ $('.login-overlay').fadeOut(500); location.href = '/post.php?postID=' + data['post'] + ''; }, 2500);
  343.  
  344. }else{
  345. //throws error if post isn't completed
  346. $('#post-form div').first().prepend('<div class="alert-message delete-message"><div class="card feed"><p>'+data['message']+'</p></div></div>'); //shows error message
  347. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  348. }
  349. },
  350. error: function (data) {
  351. console.log('Error'+data);
  352. }
  353. });
  354. }
  355. });
  356.  
  357. $('#update-announcement').click(updateAnnouncement);
  358. function updateAnnouncement(){
  359. var announcement = $('textarea[name="announcement"]').val();
  360. jQuery.ajax({
  361. type: 'POST',
  362. url: '/processes/newpost.php',
  363. data: {announcement:announcement},
  364. cache: false,
  365. success: function(data) {
  366. $('.announcement-para').html(data);
  367. $('#announcement-form').prepend('<div class="alert-message success-message"><div class="card feed"><p>The Daily Announcement has been updated!</p></div></div>');
  368. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  369. setTimeout(function(){ $('.login-overlay').fadeOut(500); }, 3500);
  370. }
  371. });
  372. }
  373.  
  374. $('#update-comment').click(updateComment);
  375. function updateComment() {
  376. var commentID = $('textarea[name="updatecomment"]').attr('id');
  377. var commentData = $('textarea[name="updatecomment"]').val();
  378. $.ajax({
  379. type: 'POST',
  380. url: '/processes/newcomment.php?update',
  381. data: {commentID: commentID, comment: commentData},
  382. cache: false,
  383. success: function (data) {
  384. $('p[data-commentid="'+commentID+'"]').html(data);
  385. $('.comment-form,.login-overlay').hide();
  386. $('.col-md-8').prepend('<div class="alert-message edit-message"><div class="card feed"><p>Comment Updated!</p></div></div>'); //shows success message
  387. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  388. }
  389. });
  390. }
  391.  
  392. function fadeAlert(){
  393. $('.alert-message').slideUp(500);
  394. setTimeout(function(){$('.alert-message').remove();},500);
  395. }
  396.  
  397. //ban / promote logic
  398. $('.ban-user').click(function(){
  399. var banid = $(this).attr('data-banID');
  400. $.ajax({
  401. type: 'POST',
  402. url: '/processes/users.php',
  403. data: {banID: banid},
  404. cache: false,
  405. success: function (data) {
  406. $('span[data-banID="'+banid+'"').parent('.card').parent('.col-md-4').remove(); //removes deleted card
  407. $('.col-md-8').prepend('<div class="alert-message edit-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  408. setTimeout(fadeAlert, 10000); //sets timeout to fade message
  409. }
  410. });
  411. });
  412. $('.mod-user').click(function(){
  413. var userid = $(this).attr('data-modID');
  414. $.ajax({
  415. type: 'POST',
  416. url: '/processes/users.php',
  417. data: {modID: userid},
  418. cache: false,
  419. success: function (data) {
  420. $('#title' + userid + '').css('color', '#9b3e7c');
  421. $('.img' + userid + '').attr('src', '/images/snigger-admin.png');
  422. $('.col-md-8').prepend('<div class="alert-message mod-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  423. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  424. }
  425. });
  426. });
  427. $('.adm-user').click(function(){
  428. var userid = $(this).attr('data-admID');
  429. $.ajax({
  430. type: 'POST',
  431. url: '/processes/users.php',
  432. data: {admID: userid},
  433. cache: false,
  434. success: function (data) {
  435. $('#title' + userid + '').css('color', '#d63346');
  436. $('.img' + userid + '').attr('src', '/images/snigger-admin.png');
  437. $('.col-md-8').prepend('<div class="alert-message delete-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  438. setTimeout(fadeAlert, 5000); //sets timeout to fade message
  439. }
  440. });
  441. });
  442. $('.reg-user').click(function(){
  443. var userid = $(this).attr('data-regID');
  444. $.ajax({
  445. type: 'POST',
  446. url: '/processes/users.php',
  447. data: {regID: userid},
  448. cache: false,
  449. success: function (data) {
  450. $('#title' + userid + '').css('color', '#606060');
  451. $('.img' + userid + '').attr('src', '/images/snigger-default.png');
  452. $('.col-md-8').prepend('<div class="alert-message edit-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  453. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  454. }
  455. });
  456. });
  457. $('.colorID').click(function(){
  458. var colorid = $(this).prev().val();
  459. var tagid = $(this).attr('data-tagid');
  460. $(this).parent('div.colorselector').css('background-color', colorid);
  461. $(this).prev().css('background-color', colorid);
  462. $.ajax({
  463. type: 'POST',
  464. url: '/processes/tags.php',
  465. data: {colorid: colorid,tagid: tagid},
  466. cache: false,
  467. success: function (data) {
  468. $('.wrapper-tags.col-md-12').prepend('<div class="alert-message edit-message col-md-12"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  469. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  470. }
  471. });
  472. });
  473.  
  474. //edit / delete logic
  475. $('.col-md-8.wrapper-posts').on('click', 'span.starID', function(){
  476. var postid = $(this).attr('data-postid');
  477. var count = $('.featured-count').html();
  478. var newcount = parseInt(count) + 1;
  479. $.ajax({
  480. type: 'POST',
  481. url: '/processes/newpost.php',
  482. data: {featureid: postid},
  483. cache: false,
  484. success: function (data) {
  485. if(data == 'Post removed from Featured!'){
  486. $('.starID[data-postid="' + postid + '"').css('color', '#606060');
  487. }else{
  488. $('.starID[data-postid="' + postid + '"').css('color', '#E2BE00');
  489. }
  490. $('.featured-count').html(newcount);
  491. $('.col-md-8').prepend('<div class="alert-message feature-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  492. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  493. }
  494. });
  495. }).on('click', 'span.editID', function(){
  496. if( $(this).attr('data-postid') ){
  497. var postid = $(this).attr('data-postid');
  498. $.ajax({
  499. type: 'POST',
  500. url: '/processes/newpost.php?editpost',
  501. data: {editID: postid},
  502. dataType: 'json',
  503. cache: false,
  504. success: function (data) {
  505. $('input[name="title"]').val(data.postTitle);
  506. $('textarea[name="description"]').val(data.postDesc);
  507. $('input[name="link"]').val(data.postLink);
  508. $('input[name="tags"]').val(data.postTags);
  509. $('input[name="postid"]').val(postid);
  510. $('select[name="primary-category"]').val(data.postPrimaryCategory);
  511. $('select[name="secondary-category"]').val(data.postSecondaryCategory);
  512. $('.title-bar h4').html('Edit Post');
  513. $('.login-form').hide();
  514. $('.post-form,.login-overlay').show();
  515. },
  516. error: function(data) {
  517. console.log('Error');
  518. console.log(data);
  519. }
  520.  
  521. });
  522. } else if( $(this).attr('data-commentid') ) {
  523. var commentid = $(this).attr('data-commentid');
  524. var text = $('p[data-commentid="'+commentid+'"]').text();
  525. }
  526.  
  527. if ( $(this).attr('data-commentid') ){
  528. $('.login-form').hide();
  529. $('.comment-form,.login-overlay').show();
  530. $('textarea[name="updatecomment"]').val(text).attr('id', commentid);
  531. }
  532. }).on('click', 'span.deleteID', function(){
  533. if( $(this).attr('data-postid') ){
  534. var postid = $(this).attr('data-postid');
  535. $.ajax({
  536. type: 'POST',
  537. url: '/processes/newpost.php?delpost',
  538. data: {delpost: postid},
  539. cache: false,
  540. success: function (data) {
  541. $('.post'+postid+'').remove(); //remove post as its deleted
  542. $('.wrapper-posts .col-md-8').prepend('<div class="alert-message delete-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  543. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  544. }
  545. });
  546. } else if( $(this).attr('data-commentid') ) {
  547. var commentid = $(this).attr('data-commentid');
  548. $.ajax({
  549. type: 'POST',
  550. url: '/processes/newcomment.php',
  551. data: {delID: commentid},
  552. cache: false,
  553. success: function (data) {
  554. $('.comment'+commentid+'').remove(); //remove comment as its deleted
  555. $('.col-md-8').prepend('<div class="alert-message delete-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  556. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  557. }
  558. });
  559. }
  560. });
  561. $('#clear-featured').click(function(){
  562. $.ajax({
  563. type: 'POST',
  564. url: '/processes/newpost.php',
  565. data: {clearfeatured: true},
  566. cache: false,
  567. success: function (data) {
  568. $('.featured-count').html('0');
  569. $('.starID').css('color', '#606060');
  570. $('.col-md-8.wrapper-posts').prepend('<div class="alert-message feature-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  571. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  572. }
  573. });
  574. });
  575. $('#register-form-submit').click(function(){
  576. var username = $('input[name="regusername"]').val();
  577. var email = $('input[name="regemail"]').val();
  578. var pass1 = $('input[name="regpassword"]').val();
  579. var pass2 = $('input[name="regpassword2"]').val();
  580. if( $('input[name="terms"]').is(':checked') ){
  581. var checked = true;
  582. }else{
  583. checked = false;
  584. }
  585.  
  586. if(!checked){
  587. $('#register-form').prepend('<div class="alert-message delete-message"><div class="card feed"><p>You must agree to our Terms of Use and Privacy Policy before you can register!</p></div></div>'); //if not checked
  588. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  589. }else if(pass1 != pass2){
  590. $('#register-form').prepend('<div class="alert-message delete-message"><div class="card feed"><p>Your passwords do not match!</p></div></div>'); //if passwords do not match
  591. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  592. }else if(!isEmail(email)){
  593. $('#register-form').prepend('<div class="alert-message delete-message"><div class="card feed"><p>Your email is not in the correct format!</p></div></div>'); //if passwords do not match
  594. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  595. }else{
  596. //disables button so we can't submit more than once
  597. $(this).addClass('disabled');
  598. //checks for users already in use or banned users
  599. $.ajax({
  600. url: '/processes/register.php',
  601. type: 'POST',
  602. //dataType: 'json',
  603. data: {preusername: username, preemail: email},
  604. cache: false,
  605. success: function (data) {
  606. // if no errors proceed with registration
  607. if(data == 'Do Register'){
  608. $.ajax({
  609. url: '/processes/register.php',
  610. type: 'POST',
  611. //dataType: 'json',
  612. data: {username: username, email: email, password: pass1, password2: pass2},
  613. cache: false,
  614. success: function (data) {
  615. //console.log(data);
  616. $('#register-form').prepend('<div class="alert-message success-message"><div class="card feed"><p>'+data+'</p></div></div>');
  617. $('#register-form-submit').removeClass('disabled');
  618. }
  619. });
  620. }else{
  621. $('#register-form').prepend('<div class="alert-message delete-message"><div class="card feed"><p>'+data+'</p></div></div>');
  622. $('#register-form-submit').removeClass('disabled');
  623. setTimeout(fadeAlert, 3000); //sets timeout to fade message
  624.  
  625. }
  626. }
  627. });
  628. }
  629.  
  630. function isEmail(email) {
  631. var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  632. return regex.test(email);
  633. }
  634. });
  635.  
  636. //login form
  637. $('#login-form-submit').click(function(){
  638. var username = $('input[name="username"]').val();
  639. var password = $('input[name="password"]').val();
  640. if(!username || !password){
  641. $('#login-form').prepend('<div class="alert-message delete-message"><div class="card feed"><p>Please use both a username and password to login!</p></div></div>'); //if not checked
  642. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  643. }else{
  644. $(this).addClass('disabled');
  645. $.ajax({
  646. url: '/processes/login.php',
  647. type: 'POST',
  648. //dataType: 'json',
  649. data: {username: username, password: password},
  650. cache: false,
  651. success: function (data) {
  652. console.log(data);
  653. if(data == 'Login Successful! Redirecting to home...'){
  654. $('#login-form').prepend('<div class="alert-message success-message"><div class="card feed"><p>'+data+'</p></div></div>');
  655. location.href = '/'; //redirect home
  656.  
  657. }else{
  658. $('#login-form').prepend('<div class="alert-message delete-message"><div class="card feed"><p>'+data+'</p></div></div>');
  659. $('#login-form-submit').removeClass('disabled');
  660. setTimeout(fadeAlert, 2000); //sets timeout to fade message
  661. }
  662. }
  663. });
  664. }
  665. });
  666.  
  667. var offset = 0; //default offset
  668. $('#LoadPosts').click(function(){
  669. var url = location.href;
  670. var type = url.substring(url.indexOf('?')+1);
  671. offset = offset + 5; //number of results per click
  672. $.ajax({
  673. url: '/processes/posts.php?' + type + '',
  674. type: 'POST',
  675. dataType: 'html',
  676. data: {offset:offset},
  677. cache: false,
  678. success: function (data) {
  679. console.log(data);
  680. delete data.category; //removes category from our data object
  681. $('.col-md-8 .posts-content').append(data).append( $('#LoadPosts') );
  682. if(($('#LoadPosts').prev().text() == 'Featured posts are updated daily. Check back later!') || $('#LoadPosts').prev().text() == 'No more posts can be loaded. Try a different section and post something!'){
  683. $('#LoadPosts').remove();
  684. }
  685. }
  686. });
  687. });
  688.  
  689. $('#forgot-password').click(function(){
  690. $('.login-form').fadeOut(300);
  691. setTimeout(function(){ $('.password-form').fadeIn(300); }, 300);
  692. });
  693.  
  694. $('#reset-pass-submit').click(function(){
  695. //$(this).addClass('disabled');
  696. var username = $('input[name="resetusername"]').val();
  697. $.ajax({
  698. url: '/processes/register.php',
  699. type: 'POST',
  700. dataType: 'html',
  701. data: {resetusername:username},
  702. cache: false,
  703. success: function (data) {
  704. $('#password-form').prepend('<div class="alert-message success-message"><div class="card feed"><p>'+data+'</p></div></div>'); //shows success message
  705. //setTimeout(fadeAlert, 4000); //sets timeout to fade message
  706. //setTimeout(function(){ $('.login-overlay').fadeOut(500); }, 4500);
  707. //$(this).removeClass('disabled');
  708. }
  709. });
  710. });
  711.  
  712.  
  713. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  714. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  715. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  716. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  717.  
  718. ga('create', 'UA-58626363-2', 'auto');
  719. ga('send', 'pageview');
  720. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement