asimryu

app.js

Jan 10th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. // app.js
  2. var slide = $("header > img");
  3. var sno = 0;
  4. var eno = slide.length - 1;
  5.  
  6. if( eno ) {
  7. for( var i=0; i<=eno; i++ ){
  8. var pointer = "<span>●</span>";
  9. $(".pointer").append(pointer);
  10. }
  11. }
  12.  
  13. var pointers = $(".pointer span");
  14. $( pointers[sno] ).addClass("active");
  15.  
  16. $("header").on("click",function(){
  17. $( slide[sno] ).animate({
  18. left:"940px",
  19. opacity: 0
  20. },1000,function(){
  21. $(this).css({left:"-940px"});
  22. });
  23. sno++;
  24. if( sno > eno ) sno = 0;
  25. $( slide[sno] ).animate({
  26. left:"0",
  27. opacity: 1
  28. },1000,function(){
  29. $(".pointer span").removeClass("active");
  30. $( pointers[sno] ).addClass("active");
  31. });
  32. });
  33.  
  34. var timer = setInterval(function(){
  35. $("header").click();
  36. },2000);
  37.  
  38. $("nav > ul > li").hover(
  39. function(){
  40. $(this).children("ul").slideDown();
  41. },
  42. function(){
  43. $(this).children("ul").slideUp("fast");
  44. }
  45. );
  46.  
  47. var page = 1;
  48. function list(){
  49. $.getJSON("list.php?start="+page,function(d){
  50. if( ! d ) return;
  51. for(var i=0; i<d.length; i++){
  52. var tr = "<tr>";
  53. tr += "<td class='name'>" + d[i].name + "</td>";
  54. tr += "<td class='phone'>" + d[i].phone + "</td>";
  55. tr += "<td class='birth'>" + d[i].birth + "</td>";
  56. tr += "<td class='email'>" + d[i].email + "</td>";
  57. tr += "<td data-id='" + d[i].id + "'><button class='edit btn btn-info btn-sm'><span class='glyphicon glyphicon-pencil'></span>수정</button> <button class='remove btn btn-danger btn-sm'><span class='glyphicon glyphicon-trash'></span>삭제</button></td>";
  58. tr += "</tr>";
  59. $("#list tr:last").after(tr);
  60. }
  61. });
  62. }
  63. list();
  64.  
  65. $(window).scroll(function(){
  66. var dh = $(document).height();
  67. var wh = $(window).height();
  68. var st = $(window).scrollTop();
  69. var sp = wh + st;
  70. if( (dh-sp)/dh === 0 ){
  71. page++;
  72. list();
  73. }
  74. });
  75.  
  76.  
  77.  
  78. $("#list").on("click",".remove",function(){
  79. var id = $(this).parent("td").attr("data-id");
  80. var del = confirm("정말 지울까요?");
  81. if( ! del ) return;
  82. var data = {"act":"delete","id":id};
  83. $.post("action.php",data,function(r){
  84. if( r == "1" ) {
  85. location.reload();
  86. } else {
  87. alert("삭제 실패");
  88. }
  89. });
  90. });
  91.  
  92.  
  93. $("#list").on("click",".edit",function(){
  94. var id = $(this).parent("td").attr("data-id");
  95. if( ! id ) return;
  96. var tr = $(this).parent("td").parent("tr");
  97. var name = $(tr).children(".name").text();
  98. var phone = $(tr).children(".phone").text();
  99. var birth = $(tr).children(".birth").text();
  100. var email = $(tr).children(".email").text();
  101. if( ! name || ! phone || ! birth || ! email ) return;
  102. $("#name").val(name);
  103. $("#phone").val(phone);
  104. $("#birth").val(birth);
  105. $("#email").val(email);
  106. $("#pop").dialog();
  107. });
  108.  
  109. /*
  110. var app = angular.module("myApp",[]);
  111. app.controller("myPeople",function($scope,$http){
  112. $http.get("list.php").then(
  113. function(p){
  114. $scope.people = p.data;
  115. }
  116. );
  117. });
  118. */
  119.  
  120. $("#pop").hide();
  121.  
  122. $(".add").on("click",function(){
  123. $("#pop").dialog({
  124. width: 500,
  125. height: 450,
  126. title: "친구추가",
  127. modal: true,
  128. buttons: {
  129. "등록": function(){
  130. var data = {};
  131. data.name = $("#name").val();
  132. data.phone = $("#phone").val();
  133. data.birth = $("#birth").val();
  134. data.email = $("#email").val();
  135. if( ! data.name || ! data.phone || ! data.birth || ! data.email ) return;
  136. data.act = "insert";
  137. $.post("action.php",data,function(r){
  138. if( r == "1" ) {
  139. location.reload();
  140. } else {
  141. alert("등록 실패" + r);
  142. }
  143. });
  144. },
  145. "닫기": function(){
  146. $(this).dialog("close");
  147. }
  148. }
  149. });
  150. });
Advertisement
Add Comment
Please, Sign In to add comment