// Effect drag category $( function() { $( ".library-header-menu-cover" ).draggable({ refreshPositions: true, drag: function( event, ui ) { var right = $(ui.helper[0]).parent().width() - $(ui.helper[0]).width(); ui.position.left = Math.max( right , ui.position.left ); ui.position.left = Math.min( 0, ui.position.left ); ui.position.top = 0; } }); } ); $(document).ready(function(){ // Effect show search $("#library-search-input").click(function(event) { //$(".library-search-result").fadeIn(); $(".library-search-container .shadow-overlap").fadeIn(); $(".library-search-icon").addClass('flipper-icon'); }); $(".library-search-container .shadow-overlap").click(function(event) { $(".library-search-result").fadeOut(); $(".library-search-container .shadow-overlap").fadeOut(); $(".library-search-icon").removeClass('flipper-icon'); }); $(".library-search-icon").click(function(event) { if( $(this).hasClass('flipper-icon') ){ $(".library-search-container .shadow-overlap").trigger('click'); }else{ $("#library-search-input").trigger('click'); } }); // Start Search var timeSearch; $("#library-search-input").keyup(function(event) { var keyWord = $(this).val(); if(event.keyCode == 13){ if(keyWord.trim() != ""){ window.location.href = urlConfig('Common/Course?searchname='+keyWord); }else{ return false; } }else{ clearTimeout(timeSearch); timeSearch = setTimeout(function(){ // Show result if(keyWord != "" && keyWord != undefined){ $.ajax({ url: urlConfig("library-search"), data: { key_word : keyWord }, type:"POST" }).success(function(data) { $(".library-search-result").fadeIn(); $('.library-search-result').html(data); $(".library-search-result .result-product").fadeIn(200); }); } }, 300); } }); $(document).on('click','.btn-suggest-vocabulary',function(){ if(checkSuggestProduct()){ var vocabularyName = $('#suggest-product-name').val(); var idea = $('#suggest-product-description').val(); var source = $('#suggest-product-document').val(); var token = $('input[name="suggest_token"]').val(); if(vocabularyName.trim() != "" && idea.trim() != ""){ $('#modal-suggest-product').modal('hide'); $(".library-search-container .shadow-overlap").trigger('click'); $.ajax({ url: urlConfig("suggest-vocabulary"), data: { vocabulary_name : vocabularyName, vocabulary_idea : idea, vocabulary_document : source, suggest_token : token, }, type:"POST" }).success(function(data) { $("body").append(''+data[1]+''); $(".toast-msg").fadeIn(400,function(){ setTimeout(function(){ $(".toast-msg").fadeOut(function(){ $(".toast-msg").remove(); }); }, 2000); }); }); } } }); }); // Check sugget product $(document).on('change keyup', ".suggest-product-input", function(){ if(checkSuggestProduct()){ $('.suggest-product-bottom button').addClass('button-active'); }else{ $('.suggest-product-bottom button').removeClass('button-active'); } }); function checkSuggestProduct(){ var productName = $("#suggest-product-name").val(); var productDes = $("#suggest-product-description").val(); if(productName != "" && productDes != ""){ return true; } return false; } var tUser; var isStoped = false; function stopGetUserProduct() { isStoped = true; clearTimeout(tUser); } function getUserProduct(){ if(!isStoped){ tUser = setTimeout(function(){ var link = $('.product-user').attr('link') $.ajax({ url: link, data: { }, type: "POST" }).success(function(data) { if(data != ''){ $('.product-user').css({'bottom':'-200px','opacity':0}); $('.product-user').html(data); $('.product-user').animate({'bottom':'15px','opacity':0.9}, 1300); setTimeout(function(){ $('.product-user').animate({'bottom':'-200px','opacity':0}, 1300); getUserProduct(); },15000) } }); },15000); } }