jQuery.fn.extend({
checkvote: function(e){
if(e){
e.preventDefault();
}
var $this = $(this);
if(!$this.hasClass('loaded')){
$this.addClass('loaded');
$.ajax({
type: "POST",
url: '/ho-tro/checkvote.php',
data: {id: $this.data('id')},
success: function($response){
if($response == 'true'){
$this.show();
}else{
$this.hide();
}
},
error: function(){
}
});
$this.hide();
}
},
});
$(document).ready(function() {
$(".hd-sidebar h5").click(function (){
var $this = $(this);
$this.parents('li').removeClass('opened');
$(".hd-sidebar ul ul").slideUp();
if (!$this.next().is(":visible") && $this.parent().hasClass('haschild')) {
$this.next().slideDown();
$this.parent().addClass('opened');
}
});
$('[data-toggle="artviewdrop"]').click(function(e){
e.preventDefault();
var $this = $(this),
$id = $this.data('id');
if(!$this.hasClass('loaded')){
$this.addClass('loaded');
$.ajax({
type: "POST",
url: $this.data('action'),
data: {id: $id},
dataType: 'json',
success: function($response){
var $htmlid = 'hdad-content-'+$id;
var $artcontent = $('
'+$response.content+'
');
$artcontent.insertAfter($this);
$artcontent.find('[data-toggle="artvotecheck"]').checkvote();
$this.data('target', $htmlid).addClass('opened');
},
error: function(){
$this.removeClass('loaded');
}
});
}else{
var $content = $('#'+$this.data('target'));
if($this.hasClass('opened')){
$content.hide();
$this.removeClass('opened');
}else{
$content.show();
$this.addClass('opened');
}
}
});
$('[data-toggle="moresearch"]').click(function(e){
e.preventDefault();
var $this = $(this),
$page = $this.data('page');
if(!$this.hasClass('loaded')){
$this.addClass('loaded');
$.ajax({
type: "POST",
url: $this.data('action'),
data: {title: $this.data('title'), page: $page},
success: function($response){
if($response){
var $artcontent = $($response),
$nextpage = $page + 1;
$('.hd-search-item').last().after($artcontent);
$this.data('page', $nextpage);
if($nextpage >= $this.data('maxpage')){
$this.hide();
}
}else{
$this.hide();
}
$this.removeClass('loaded');
},
error: function(){
$this.removeClass('loaded');
}
});
}
});
$('[data-toggle="artvotecheck"]').checkvote();
$('body').on('click', '[data-toggle="artvote"]', function(e){
e.preventDefault();
var $this = $(this);
if(!$this.hasClass('loaded')){
$this.addClass('loaded');
$.ajax({
type: "POST",
url: '/ho-tro/vote.php',
data: {id: $this.data('id'), value: $this.data('value')},
success: function($response){
},
error: function(){
}
});
$this.parent().html('Cảm ơn!');
}
});
$('body').on('click', '.hdr-list input[type="radio"]', function(e){
var $this = $(this),
$step = $this.parents('.hdr-step'),
$nextstep = $('.hdr-step:eq('+$step.data('step')+')');
$step.find('.hdrs-choose').html($step.find('[for="'+$this.attr('id')+'"]').text());
$step.removeClass('active').addClass('selected');
if($nextstep.length == 1){
$nextstep.removeClass('selected').addClass('active').removeClass('hdr-step-hide');
$nextstep.find('input[type="radio"]').prop('checked', false);
}
switch($step.data('type')){
case 'rtype':
case 'fcate':
$.ajax({
type: "POST",
url: '/ho-tro/loadcate.php',
data: {type: $step.data('type'), value: $this.val()},
dataType: 'JSON',
success: function($response){
switch($response.status){
case 'success':
var $hdrlist = $nextstep.find('.hdr-list'), $k, $empty = true;
$hdrlist.empty();
for($k in $response.items){
$hdrlist.append($response.items[$k]);
$empty = false;
}
if($empty){
var $nextsteps = $('.hdr-step:gt('+($step.data('step') - 1)+')');
$nextsteps.removeClass('selected').removeClass('active').addClass('hdr-step-hide');
$('.hdr-step[data-type="rsubmit"]').removeClass('hdr-step-hide');
$('.hdr-scate-box').hide();
}
break;
case 'fail':
show_message('Lỗi', $response.message);
break;
}
},
error: function(){
show_message('Lỗi', 'Gặp lỗi trong khi cung cấp thông tin');
}
});
break;
case 'scate':
$.ajax({
type: "POST",
url: '/ho-tro/loadcate.php',
data: {type: $step.data('type'), value: $this.val()},
dataType: 'JSON',
success: function($response){
switch($response.status){
case 'success':
$('.hdr-scate-box').html($response.message).show();
$('.hdr-step[data-type="rsubmit"]').removeClass('hdr-step-hide');
break;
case 'fail':
show_message('Lỗi', $response.message);
break;
}
},
error: function(){
show_message('Lỗi', 'Gặp lỗi trong khi cung cấp thông tin');
}
});
break;
}
});
$('body').on('click', '.hdrs-choose', function(e){
var $this = $(this),
$step = $this.parents('.hdr-step'),
$nextsteps = $('.hdr-step:gt('+($step.data('step') - 1)+')');
$nextsteps.removeClass('selected').removeClass('active').addClass('hdr-step-hide');
$step.find('input[type="radio"]').prop('checked', false);
$step.removeClass('selected').addClass('active');
});
$('.hdr-continue').click(function(e){
e.preventDefault();
$('.hd-issue').hide();
$('.hd-help').show();
var form = $(this).parents('form');
var email = form.find('[name="emailAsk"]');
if (email.length && email.val()) {
$.post('/ho-tro/get-user-data.php', {email: email.val()}, function (response) {
if (typeof response.data !== 'undefined') {
form.find('[name="email"]').val(response.data.email);
form.find('[name="phone"]').val(response.data.phone);
//form.find('[name="email"]').attr('disabled', 'disabled');
} else {
form.find('[name="email"]').val('');
form.find('[name="phone"]').val('');
show_message('Lỗi', 'Không tìm thấy tài khoản yêu cầu');
}
}, 'JSON');
}
});
$('.hdr-back').click(function(e){
e.preventDefault();
$('.hd-issue').show();
$('.hd-help').hide();
});
$('#hdr-form').submit(function(e){
e.preventDefault();
});
$('#hdr-form').validate({
rules: {
email: {
required: true,
remote: {
url: '/ho-tro/check-user.php',
method: 'POST',
},
},
phone: {
required: true
},
title: {
required: true
},
content: {
required: true
},
content: {
required: true
},
},
messages: {
email: {
required: 'Bạn chưa nhập email',
email: 'Địa chỉ email không hợp lệ',
},
phone: {
required: 'Bạn chưa nhập số điện thoại',
phone: 'Số điện thoại không hợp lệ',
},
title: {
required: 'Bạn chưa nhập tiêu đề'
},
content: {
required: 'Bạn chưa nhập nội dung cần hỗ trợ',
}
},
errorElement: 'div',
errorPlacement: function(place, element){
place.addClass('error-message').appendTo(element.closest('div'));
},
highlight: function(element, errorClass, validClass) {
if (element.type === "radio") {
this.findByName(element.name).addClass(errorClass).removeClass(validClass);
}else if(element.type === "select-one" || element.type === "select-multiple"){
var $element = $(element);
$element.addClass(errorClass).removeClass(validClass);
var $next = $element.next();
if($next.length > 0 && $next.hasClass('select2')){
$next.addClass(errorClass).removeClass(validClass);
}
}else{
$(element).addClass(errorClass).removeClass(validClass);
}
},
unhighlight: function( element, errorClass, validClass ) {
if (element.type === "radio") {
this.findByName(element.name).addClass(validClass).removeClass(errorClass);
}else if(element.type === "select-one" || element.type === "select-multiple"){
var $element = $(element);
$element.addClass(validClass).removeClass(errorClass);
var $next = $element.next();
if($next.length > 0 && $next.hasClass('select2')){
$next.addClass(validClass).removeClass(errorClass);
}
}else{
$(element).addClass(validClass).removeClass(errorClass);
}
},
submitHandler: function(form){
var $thisForm = $(form);
if($thisForm.valid() && !$thisForm.hasClass('loading')){
$thisForm.addClass('loading');
var $formData = new window.FormData(form);
$.ajax({
type: "POST",
url: $thisForm.attr('action'),
data: $formData,
dataType: 'JSON',
processData: false,
contentType: false,
success: function ($response) {
if($response.status == 'success'){
$('.hd-content').html($response.message);
$('body,html').scrollTop(0);
}else {
show_message('Lỗi', $response.message);
}
$thisForm.removeClass('loading');
},
error:function(){
$thisForm.removeClass('loading');
}
});
}
return false;
}
});
$('#hdr-image').change(function() {
var $filename = $('#hdr-image').val().split('.'),
$ext = $filename.pop();
$filename = $filename.join('.');
if($filename.length > 50){
$filename = $filename.substring(0, 45)+'...'+$ext;
}else{
$filename = $filename+'.'+$ext;
}
$('label[for="hdr-image"]').html($filename);
});
if ($('.hd-video-wr').length > 0) {
$('.hd-video-wr').slick({
slidesToShow: 3,
slidesToScroll: 1,
autoplay: false,
autoplaySpeed: 10000,
prevArrow: '',
nextArrow: '',
responsive: [
{
breakpoint: 991,
settings: {
slidesToShow: 3,
slidesToScroll: 1,
infinite: true,
dots: false
}
},
{
breakpoint: 800,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
},
{
breakpoint: 640,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
// You can unslick at a given breakpoint now by adding:
// settings: "unslick"
// instead of a settings object
]
});
}
$('.play-video').click(function(e){
var $this = $(this),
$ytid = $this.data('ytid'),
$ltmodal = $('#videoModal');
if (window.innerWidth < 480) {
$ltmodal.find('#ltplayer').html('');
} else {
$ltmodal.find('#ltplayer').html('');
}
$ltmodal.modal('show');
});
});
$(document).ready(function () {
$('body').on('click','.mobile-button', function () {
$(this).parent().toggleClass('hd-sidebar-open');
$('body').toggleClass('hd-sidebar-body-open');
});
$( "body" ).on( "click",".fa-bars", function () {
$(this).parent().toggleClass('hd-sidebar-open');
$('body').toggleClass('hd-sidebar-body-open');
});
var W = $(window).outerWidth();
var H = $(window).outerHeight();
if(W < 640){
$('#search').appendTo("#header .wrapper");
}
var Bar = $('.sidebar-first').outerHeight();
if(Bar < H){
console.log(2);
$('.sidebar-first').css({'overflow':'visible'})
$('.mobile-button').css({'right':'-45px','top':'12px'});
}else {
$('.sidebar-first').css({'overflow-y':'scroll','overflow-x':'hidden'});
$('.mobile-button').css({'right':'0px','top':'1px'});
console.log(3);
}
$('#header .course-menu').append('');
var nav = $('#header');
$(window).scroll(function () {
if ($(this).scrollTop() > 90) {
nav.addClass("f-nav");
} else {
nav.removeClass("f-nav");
}
});
});