library.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Effect drag category
  2. $( function() {
  3. $( ".library-header-menu-cover" ).draggable({
  4. refreshPositions: true,
  5. drag: function( event, ui ) {
  6. var right = $(ui.helper[0]).parent().width() - $(ui.helper[0]).width();
  7. ui.position.left = Math.max( right , ui.position.left );
  8. ui.position.left = Math.min( 0, ui.position.left );
  9. ui.position.top = 0;
  10. }
  11. });
  12. } );
  13. $(document).ready(function(){
  14. // Effect show search
  15. $("#library-search-input").click(function(event) {
  16. //$(".library-search-result").fadeIn();
  17. $(".library-search-container .shadow-overlap").fadeIn();
  18. $(".library-search-icon").addClass('flipper-icon');
  19. });
  20. $(".library-search-container .shadow-overlap").click(function(event) {
  21. $(".library-search-result").fadeOut();
  22. $(".library-search-container .shadow-overlap").fadeOut();
  23. $(".library-search-icon").removeClass('flipper-icon');
  24. });
  25. $(".library-search-icon").click(function(event) {
  26. if( $(this).hasClass('flipper-icon') ){
  27. $(".library-search-container .shadow-overlap").trigger('click');
  28. }else{
  29. $("#library-search-input").trigger('click');
  30. }
  31. });
  32. // Start Search
  33. var timeSearch;
  34. $("#library-search-input").keyup(function(event) {
  35. var keyWord = $(this).val();
  36. if(event.keyCode == 13){
  37. if(keyWord.trim() != ""){
  38. window.location.href = urlConfig('Common/Course?searchname='+keyWord);
  39. }else{
  40. return false;
  41. }
  42. }else{
  43. clearTimeout(timeSearch);
  44. timeSearch = setTimeout(function(){
  45. // Show result
  46. if(keyWord != "" && keyWord != undefined){
  47. $.ajax({
  48. url: urlConfig("library-search"),
  49. data: {
  50. key_word : keyWord
  51. },
  52. type:"POST"
  53. }).success(function(data) {
  54. $(".library-search-result").fadeIn();
  55. $('.library-search-result').html(data);
  56. $(".library-search-result .result-product").fadeIn(200);
  57. });
  58. }
  59. }, 300);
  60. }
  61. });
  62. $(document).on('click','.btn-suggest-vocabulary',function(){
  63. if(checkSuggestProduct()){
  64. var vocabularyName = $('#suggest-product-name').val();
  65. var idea = $('#suggest-product-description').val();
  66. var source = $('#suggest-product-document').val();
  67. var token = $('input[name="suggest_token"]').val();
  68. if(vocabularyName.trim() != "" && idea.trim() != ""){
  69. $('#modal-suggest-product').modal('hide');
  70. $(".library-search-container .shadow-overlap").trigger('click');
  71. $.ajax({
  72. url: urlConfig("suggest-vocabulary"),
  73. data: {
  74. vocabulary_name : vocabularyName,
  75. vocabulary_idea : idea,
  76. vocabulary_document : source,
  77. suggest_token : token,
  78. },
  79. type:"POST"
  80. }).success(function(data) {
  81. $("body").append('<span class="toast-msg">'+data[1]+'</span>');
  82. $(".toast-msg").fadeIn(400,function(){
  83. setTimeout(function(){
  84. $(".toast-msg").fadeOut(function(){
  85. $(".toast-msg").remove();
  86. });
  87. }, 2000);
  88. });
  89. });
  90. }
  91. }
  92. });
  93. });
  94. // Check sugget product
  95. $(document).on('change keyup', ".suggest-product-input", function(){
  96. if(checkSuggestProduct()){
  97. $('.suggest-product-bottom button').addClass('button-active');
  98. }else{
  99. $('.suggest-product-bottom button').removeClass('button-active');
  100. }
  101. });
  102. function checkSuggestProduct(){
  103. var productName = $("#suggest-product-name").val();
  104. var productDes = $("#suggest-product-description").val();
  105. if(productName != "" && productDes != ""){
  106. return true;
  107. }
  108. return false;
  109. }
  110. var tUser;
  111. var isStoped = false;
  112. function stopGetUserProduct() {
  113. isStoped = true;
  114. clearTimeout(tUser);
  115. }
  116. function getUserProduct(){
  117. if(!isStoped){
  118. tUser = setTimeout(function(){
  119. var link = $('.product-user').attr('link')
  120. $.ajax({
  121. url: link,
  122. data: {
  123. },
  124. type: "POST"
  125. }).success(function(data) {
  126. if(data != ''){
  127. $('.product-user').css({'bottom':'-200px','opacity':0});
  128. $('.product-user').html(data);
  129. $('.product-user').animate({'bottom':'15px','opacity':0.9}, 1300);
  130. setTimeout(function(){
  131. $('.product-user').animate({'bottom':'-200px','opacity':0}, 1300);
  132. getUserProduct();
  133. },15000)
  134. }
  135. });
  136. },15000);
  137. }
  138. }