jQuery(document).ready(function($){var doc_id=$('#existing-doc-id').val();$('body').removeClass('no-js').addClass('js');$('.hide-if-no-js').show();if($('body').hasClass('bp-docs-edit')){var lock_data={action:'add_edit_lock',doc_id:doc_id};$.ajax({url:ajaxurl,type:'POST',data:lock_data,success:function(response){return true;}});} $('.doctable').on('click','.bp-docs-attachment-clip',function(e){var att_doc_id=$(e.target).closest('.bp-docs-attachment-clip').attr('id').split('-').pop();var att_doc_drawer=$('#bp-docs-attachment-drawer-'+att_doc_id);att_doc_drawer.slideToggle(400);});$('#doc-attachments-ul > li').each(function(i){$(this).addClass((i+1)%2?'odd':'even');});$('input#doc-permalink').on('keydown',function(e){focus_in_content_area(e);});$('input#doc-title').on('keydown',function(e){if(!document.getElementById('doc-permalink')){focus_in_content_area(e);}});$('.toggle-link').click(function(){var $toggleable=$(this).parents('.toggleable');var $tc=$toggleable.find('.toggle-content');var $ts=$toggleable.find('.toggle-switch');var $pom=$(this).find('.plus-or-minus');if($toggleable.hasClass('toggle-open')){$toggleable.removeClass('toggle-open').addClass('toggle-closed');}else{$toggleable.removeClass('toggle-closed').addClass('toggle-open');} return false;});var $group_enable_toggle=$('#bp-docs-group-enable');$group_enable_toggle.click(function(){if($group_enable_toggle.is(':checked')){$('#group-doc-options').show();}else{$('#group-doc-options').hide();}});var thisaction,showing,hidden;$('#doc-permissions-summary').show();$('#doc-permissions-details').hide();var dpt=$('.doc-permissions-toggle');$(dpt).on('click',function(e){e.preventDefault();thisaction=$(e.target).attr('id').split('-').pop();showing='more'==thisaction?'summary':'details';hidden='summary'==showing?'details':'summary';$('#doc-permissions-'+showing).slideUp(100,function(){$('#doc-permissions-'+hidden).slideDown(100);});});var hidden_tag_counter=0,tag_button_action,$dfsection,$dfsection_tags=$('#docs-filter-section-tags'),$dfsection_tags_list=$dfsection_tags.find('ul#tags-list'),$dfsection_tags_items=$dfsection_tags_list.children('li');$('.docs-filter-section').each(function(){$dfsection=$(this);if(!$dfsection.hasClass('docs-filter-section-open')){$dfsection.hide();}});if($dfsection_tags_items.length>10){tags_section_collapse($dfsection_tags);} $dfsection_tags.on('click','a.tags-action-button',function(e){$dfsection_tags.slideUp(300,function(){tag_button_action=$(e.target).hasClass('tags-unhide')?'expand':'collapse';if('expand'==tag_button_action){tags_section_expand($dfsection_tags);}else if('collapse'==tag_button_action){tags_section_collapse($dfsection_tags);} $dfsection_tags.slideDown();});return false;});$('.docs-filter-title').on('click',function(e){var filter_title=$(this);var filter_title_id=filter_title.attr('id');var filter_id=filter_title_id.replace('docs-filter-title-','');var filter_to_show_id='docs-filter-section-'+filter_id;var showing_filter_id=$('.docs-filter-section-open').attr('id');$('.docs-filter-title').removeClass('current');filter_title.addClass('current');var filter_sections=$('.docs-filter-section');filter_sections.removeClass('docs-filter-section-open');var all_section_slideup=function(){$('.docs-filter-section').slideUp(100);} $.when(all_section_slideup()).done(function(){if(filter_to_show_id!=showing_filter_id){$('#'+filter_to_show_id).fadeIn().addClass('docs-filter-section-open');}});return false;});var searchTerm=bpdocs_get_query_var('s');if(searchTerm){var searchRegExpPattern='(\\w*('+searchTerm.replace(/[-\/\\^$*+?.()|[\]{}]/g,'\\$&')+')\\w*)' var searchRegExp=new RegExp(searchRegExpPattern);$('.doctable tbody .title-cell > a').html(function(index,html){return html.replace(searchTerm,''+searchTerm+'');});$('.bp-docs-attachment-drawer li a').html(function(index,html){var newHtml=html.replace(searchRegExp,function(match,a,b,c){if(''+b+'');});if(newHtml!==html){var $thisDrawer=$(this).closest('.bp-docs-attachment-drawer');if(!$thisDrawer.is(':visible')){var drawerDocId=$thisDrawer.attr('id').substr(26);if(drawerDocId){$('#bp-docs-attachment-clip-'+drawerDocId).trigger('click');}}} return newHtml;});} if(typeof wp!='undefined'&&typeof wp.heartbeat!='undefined'&&typeof bp_docs.pulse!='undefined'){wp.heartbeat.interval(Number(bp_docs.pulse));$.fn.extend({'heartbeat-send':function(){return this.bind('heartbeat-send.buddypress-docs');},});} $(document).on('heartbeat-send.buddypress-docs',function(e,data){data['doc_id']=$('#existing-doc-id').val();});$(document).on('heartbeat-tick',function(e,data){if(!data['bp_docs_bounce']){return;} window.location=data['bp_docs_bounce'];});function tags_section_collapse($section){$section.find('a.tags-hide').remove();$dfsection_tags_items.each(function(k,v){if(k>6){$(v).addClass('hidden-tag');hidden_tag_counter++;}});var st='… '+bp_docs.and_x_more+'';st=st.replace(/%d/,hidden_tag_counter);$dfsection_tags_list.append('