/** * @copyright Commercial License By LeoTheme.Com * @email leotheme.com * @visit http://www.leotheme.com */ $(document).ready(function(){ $("#pcategories").closest(".form-group").hide(); $("#ptype").closest(".form-group").hide(); $("#pproductids").closest(".form-group").hide(); $("#pmanufacturers").closest(".form-group").hide(); $( "#source option:selected" ).each(function() { $("#limit").closest(".form-group").hide(); var val = $(this).val(); $("#"+val).closest(".form-group").show(500); if( val != 'pproductids'){ $("#limit").closest(".form-group").show(500); } }); $("#source").change(function(){ $("#pcategories").closest(".form-group").hide(); $("#ptype").closest(".form-group").hide(); $("#pproductids").closest(".form-group").hide(); $("#pmanufacturers").closest(".form-group").hide(); $("#limit").closest(".form-group").hide(); var val = $(this).val(); $("#"+val).closest(".form-group").show(500); if(val != 'pproductids') $("#limit").closest(".form-group").show(500); }); //for imageproduct widget $("#ip_pcategories").closest(".form-group").hide(); $("#ip_pproductids").closest(".form-group").hide(); $( "#ip_source option:selected" ).each(function() { var val = $(this).val(); $("#"+val).closest(".form-group").show(); }); $("#ip_source").change(function(){ $("#ip_pcategories").closest(".form-group").hide(); $("#ip_pproductids").closest(".form-group").hide(); var val = $(this).val(); $("#"+val).closest(".form-group").show(500); }); //done for imageproduct widget //for category_image widget //hide checkbox of root node $("input[type=checkbox]", "#image_cate_tree").first().hide(); var root_id = $("input[type=checkbox]", "#image_cate_tree").first().val(); Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); } var selected_images = {}; if($("#category_img").val()){ selected_images = JSON.parse($("#category_img").val()); } $("input[type=checkbox]", "#image_cate_tree").click(function(){ if($(this).is(":checked")){ //find parent category //all parent category must be not checked var check = checkParentNodes($(this)); if(!check){ $(this).prop("checked",false); alert("All parent of this category must be not checked"); } }else{ $(".list-image-"+$(this).val()).remove(); delete selected_images[$(this).val()]; } }); $(".list-image a").click(function(){ var selText = $(this).text(); $(this).parents('.btn-group').find('.dropdown-toggle').html(selText+' '); $(this).parents('.btn-group').find('.dropdown-menu').hide(); if(selText != "none"){ cate_id = $(this).parents('.btn-group').find('.dropdown-toggle').closest("li").find("input[type=checkbox]").val(); selected_images[cate_id] = selText.trim(); } return false; }); $(".dropdown-toggle").click(function(){ $(this).parents('.btn-group').find('.dropdown-menu').show(); return false; }); $(".list-image .dropdown-menu").mouseleave(function(){ $(".list-image .dropdown-menu").hide(); return false; }); $('[name="saveleowidget"].sub_categories').click( function(){ $("#category_img").val(JSON.stringify(selected_images)); }); $('[name="saveandstayleowidget"].sub_categories').click( function(){ $("#category_img").val(JSON.stringify(selected_images)); }); // show selected_image when loaded page $("input[type=checkbox]", $(".form-select-icon")).each(function(){ if($(this).val() != root_id){ listImage = $(".list-image","#list_image_wrapper").clone(1); listImage.addClass("list-image-"+$(this).val()); listImage.appendTo($(this).closest("li").find("span").first()); } for(var key in selected_images){ if(key == $(this).val()){ image_name = selected_images[key]; listImage.find(".dropdown-toggle").html(image_name+' '); break; } } //$(this).closest("ul.tree").css("display", "none"); }); //$("ul.tree").css("display", "none"); function checkParentNodes(obj){ var flag = true; if(parent = obj.closest("ul").closest("li").find("input[type=checkbox]")){ if(parent.val() != root_id){ if($("input[value=" + parent.val() + "]","#image_cate_tree").is(":checked")){ flag = false; }else{ flag = checkParentNodes(parent); } } } return flag; } //update link type _updateLinkType(); $("#link_type").on('change',_updateLinkType); var array_id_lang = []; if (typeof list_id_lang !== "undefined") { array_id_lang = $.parseJSON(list_id_lang); } //hiden tmp form $('.tmp').each(function(){ if($(this).closest(".translatable-field").length) { // console.log($(this).closest(".form-group")); // console.log($(this).closest(".form-group").closest(".form-group")); if($(this).hasClass('element')) { var id = $(this).attr('id'); id = id.substring(0, id.lastIndexOf('_')); var index = id.substring(id.lastIndexOf('_')+1);; // console.log(index); $(this).closest(".form-group").parents(".form-group").addClass('element-tmp hidden element-'+index); } else { $(this).closest(".form-group").parents(".form-group").addClass('parent-tmp hidden'); } if(!$(this).closest(".form-group").find('.copy_lang_value').length) $(this).closest(".form-group").append(""); } else { if($(this).hasClass('element')) { var id = $(this).attr('id'); if(array_id_lang.length == 1 && $(this).hasClass('element-lang')) { // console.log(array_id_lang.length); id = id.substring(0, id.lastIndexOf('_')); } var index = id.substring(id.lastIndexOf('_')+1);; // console.log(index); $(this).closest(".form-group").addClass('element-tmp hidden element-'+index); } else { $(this).closest(".form-group").addClass('parent-tmp hidden'); } } }); //display link group when edit block link if ($('#list_id_link').length && $('#list_id_link').val() != '') { var list_id_link = $('#list_id_link').val().split(','); var button_tmp = "
"; button_tmp += "
"; button_tmp += "
"; button_tmp += ""; button_tmp += ""; button_tmp += '
'; button_tmp += '
'; button_tmp += ''; $.each(list_id_link, function( index, value ) { if (value != '') { //$("[id^=text_link_"+value+"]"); // if($("[id^=text_link_"+value+"]").closest('.form-group').find('.translatable-field').length) // $("[id^=text_link_"+value+"]").closest('.form-group').parents('.element-tmp').before('