/** * @author https://www.cosmosfarm.com */ /** * inViewport jQuery plugin by Roko C.B. * http://stackoverflow.com/a/26831113/383904 Returns a callback function with * an argument holding the current amount of px an element is visible in * viewport (The min returned value is 0 (element outside of viewport) */ (function($, win){ $.fn.kboardViewport = function(cb){ return this.each(function(i, el){ function visPx(){ var elH = $(el).outerHeight(), H = $(win).height(), r = el.getBoundingClientRect(), t = r.top, b = r.bottom; return cb.call(el, Math.max(0, t > 0 ? Math.min(elH, H - t) : (b < H ? b : H))); } visPx(); $(win).on("resize scroll", visPx); }); }; }(jQuery, window)); var kboard_ajax_lock = false; jQuery(document).ready(function(){ var kboard_mod = jQuery('input[name=mod]', '.kboard-form').val(); if(kboard_mod == 'editor'){ if(kboard_current.use_tree_category == 'yes'){ kboard_tree_category_parents(); } if(kboard_current.use_editor == 'snote'){ // summernote jQuery('.summernote').each(function(){ var height = parseInt(jQuery(this).height()); var placeholder = jQuery(this).attr('placeholder'); var lang = 'en-US'; if(kboard_settings.locale == 'ko_KR'){ lang = 'ko-KR'; } else if(kboard_settings.locale == 'ja'){ lang = 'ja-JP'; } jQuery(this).summernote({ toolbar: [ ['style', ['style']], ['fontsize', ['fontsize']], ['font', ['bold', 'italic', 'underline', 'clear']], ['fontname', ['fontname']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['height', ['height']], ['table', ['table']], ['insert', ['link', 'picture', 'hr']], ['view', ['fullscreen', 'codeview']], ['help', ['help']] ], fontNames: ['Arial', 'Arial Black', 'Comic Sans MS', 'Courier New', 'Helvetica Neue', 'Helvetica', 'Impact', 'Lucida Grande', 'Tahoma', 'Times New Roman', 'Verdana', 'Nanum Gothic', 'Malgun Gothic', 'Noto Sans KR', 'Apple SD Gothic Neo'], fontNamesIgnoreCheck: ['Arial', 'Arial Black', 'Comic Sans MS', 'Courier New', 'Helvetica Neue', 'Helvetica', 'Impact', 'Lucida Grande', 'Tahoma', 'Times New Roman', 'Verdana', 'Nanum Gothic', 'Malgun Gothic', 'Noto Sans KR', 'Apple SD Gothic Neo'], fontSizes: ['8','9','10','11','12','13','14','15','16','17','18','19','20','24','30','36','48','64','82','150'], lang: lang, height: height, placeholder: placeholder }); }); } } }); function kboard_tree_category_search(index, value){ var length = jQuery('.kboard-search-option-wrap').length; var tree_category_index = parseInt(index) +1; if(value){ jQuery('input[name="kboard_search_option[tree_category_'+index+'][value]"]').val(value); } else{ jQuery('input[name="kboard_search_option[tree_category_'+index+'][value]"]').val(''); } for(var i=tree_category_index; i<=length; i++){ jQuery('.kboard-search-option-wrap-'+i).remove(); } jQuery('#kboard-tree-category-search-form-'+kboard_current.board_id).submit(); return false; } function kboard_tree_category_parents(){ if(kboard_current.use_tree_category){ var tree_category = kboard_current.tree_category; var tree_category_name; var tree_category_index = 1; tree_category_name = 'kboard_option_tree_category_'; jQuery('.kboard-tree-category-wrap').prepend(''); jQuery('#kboard-tree-category-'+tree_category_index).append(''); jQuery('#kboard-tree-category-'+tree_category_index).after(''); jQuery('#kboard-tree-category-'+tree_category_index).change(function(){ kboard_tree_category_children(this.value, tree_category_index, tree_category_name); jQuery('#kboard-tree-category-search-form-'+kboard_current.board_id).submit(); }); jQuery.each(tree_category, function(index, element){ if(!element.parent_id){ jQuery('#kboard-tree-category-'+tree_category_index).append(''); } }); kboard_tree_category_selected(tree_category_index, tree_category_name); } } function kboard_tree_category_children(category_id, tree_category_index, tree_category_name){ var tree_category = kboard_current.tree_category; var length = jQuery('.kboard-tree-category').length; var check = 0; for(var i=tree_category_index+1; i<=length; i++){ jQuery('.kboard-tree-category-'+i).remove(); jQuery('.kboard-tree-category-hidden-'+i).remove(); } jQuery.each(tree_category, function(index, element){ if(jQuery('#kboard-tree-category-'+tree_category_index).val() == element.id){ jQuery('#'+tree_category_name+tree_category_index).val(element.category_name); } }); if(jQuery('#kboard-tree-category-'+tree_category_index).val()){ jQuery.each(tree_category, function(index, element){ if(category_id === element.parent_id){ if(check==0){ jQuery('#kboard-tree-category-'+tree_category_index).after(''); jQuery('#kboard-tree-category-'+(tree_category_index+1)).append(''); jQuery('#kboard-tree-category-'+(tree_category_index+1)).after(''); jQuery('#kboard-tree-category-'+(tree_category_index+1)).change(function(){ kboard_tree_category_children(this.value, (tree_category_index+1), tree_category_name); jQuery('#kboard-tree-category-search-form-'+kboard_current.board_id).submit(); }); } check++; jQuery('#kboard-tree-category-'+(tree_category_index+1)).append(''); } }); kboard_tree_category_selected(tree_category_index+1, tree_category_name); } else{ for(var i=tree_category_index; i<=length; i++){ jQuery('.kboard-tree-category-hidden-'+i).val(''); jQuery('.kboard-tree-category-hidden-'+(i+1)).remove(); } } if(jQuery('.kboard-tree-category-search').length){ jQuery('input[name="kboard_search_option[tree_category_'+tree_category_index+'][value]"').val(jQuery('#'+tree_category_name+tree_category_index).val()); jQuery('input[name="kboard_search_option[tree_category_'+tree_category_index+'][key]"').val('tree_category_'+tree_category_index); } } function kboard_tree_category_selected(tree_category_index, tree_category_name){ var check = jQuery('#tree-category-check-'+tree_category_index).val(); if(check){ jQuery('#kboard-tree-category-'+tree_category_index+' option').each(function(index, element){ if(jQuery(element).text() == check){ jQuery(element).attr('selected', 'selected'); kboard_tree_category_children(this.value, tree_category_index, tree_category_name); } }); } return false; } function kboard_editor_open_media(){ var w = 900; var h = 500; var media_popup_url = kboard_current.add_media_url; if(kboard_current.board_id){ if(jQuery('#kboard_media_wrapper').length){ jQuery('#kboard_media_wrapper').show(); jQuery('#kboard_media_wrapper').html(jQuery('').attr('src', media_popup_url)); jQuery('#kboard_media_background').show(); } else{ var wrapper = jQuery('
'); var background = jQuery('').css({opacity:'0.5'}).click(function(){ kboard_media_close(); }); function init_window_size(){ if(window.innerWidth <= 900){ wrapper.css({left:0, top:0, margin:'10px', width:(window.innerWidth-20), height:(window.innerHeight-20)}); } else{ wrapper.css({left:'50%', top:'50%', margin:0, 'margin-left':(w/2)*-1, 'margin-top':(h/2)*-1, width:w, height:h}); } } init_window_size(); jQuery(window).resize(init_window_size); wrapper.html(jQuery('').attr('src', media_popup_url)); jQuery('body').append(background); jQuery('body').append(wrapper); if(!jQuery('input[name="media_group"]').filter(function(){return this.value==kboard_settings.media_group}).length){ jQuery('[name="board_id"]').parents('form').append(jQuery('').val(kboard_settings.media_group)); } } } } function kboard_editor_insert_media(url){ if(kboard_current.use_editor == 'snote'){ // summernote jQuery('#kboard_content').summernote('editor.saveRange'); jQuery('#kboard_content').summernote('editor.restoreRange'); jQuery('#kboard_content').summernote('editor.focus'); jQuery('#kboard_content').summernote('editor.pasteHTML', "