Mercurial > hg > LGSearch
comparison search.js @ 6:4b9ae7d500f9
add example page, modify password popup
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 14 Oct 2015 11:01:26 +0200 |
parents | c9363a90b8b5 |
children | 23dcd1b5e9c4 |
comparison
equal
deleted
inserted
replaced
5:1cf7bb8db5dd | 6:4b9ae7d500f9 |
---|---|
1 $(document).ready(function(){ | 1 |
2 initSection(); | |
3 }); | |
4 function initSection(){ //Hide sections if there are more than 5 | 2 function initSection(){ //Hide sections if there are more than 5 |
5 $("td div.section").hide(); | 3 $("td div.section").hide(); |
6 for(var i=1; i<=5; i++){ | 4 for(var i=1; i<=5; i++){ |
7 $("td div.section:nth-child("+i+")").show(); | 5 $("td div.section:nth-child("+i+")").show(); |
8 } | 6 } |
27 } | 25 } |
28 $(this).html("+"); | 26 $(this).html("+"); |
29 } | 27 } |
30 }); | 28 }); |
31 } | 29 } |
30 | |
31 function submitenter(e) | |
32 { | |
33 var keycode; | |
34 if (window.event) keycode = window.event.keyCode; | |
35 else if (e) keycode = e.which; | |
36 else return true; | |
37 | |
38 if (keycode == 13) { | |
39 checkPassword(); | |
40 return false; | |
41 } else { | |
42 return true; | |
43 } | |
44 } | |
45 | |
46 function checkPassword() { | |
47 var password = document.getElementById("pass").value; | |
48 $.ajax({ | |
49 url : 'search_function.php', | |
50 async : false, | |
51 type : 'POST', | |
52 data : 'func=checkPassword'+'&password='+password, | |
53 success: function (e) { | |
54 }, | |
55 error: function (e) { | |
56 alert("Internal error when checking password."); | |
57 } | |
58 }).done(function(result) { | |
59 //console.log("password checking result: "+result); | |
60 if (result == 1) { | |
61 closePopup(); | |
62 $("#search").show(); | |
63 } else { | |
64 // still showing popup | |
65 alert("Wrong password!"); | |
66 showPopup(); | |
67 $("#search").hide(); | |
68 } | |
69 }); | |
70 }; | |
71 | |
72 function showPopup() { | |
73 // clear previous input | |
74 if (document.getElementById("pass")) { | |
75 document.getElementById("pass").value = ""; | |
76 document.getElementById("popup").style.display = "block"; | |
77 } | |
78 } | |
79 function closePopup() { | |
80 if (document.getElementById("pass")) { | |
81 document.getElementById("popup").style.display = "none"; | |
82 } | |
83 } |