Last active
August 29, 2015 14:06
-
-
Save pommiegranit/a6d02c99fad594e07112 to your computer and use it in GitHub Desktop.
Part of the enhanced comments plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
// move the buried comments to the bottom of the list | |
if ( encom.buried == 'bottom' ) { | |
var comments = $(encom.comment + '.buried').detach(); | |
$(encom.container).append( comments ); | |
} | |
// remove buried comments | |
if ( encom.buried == 'remove' ) { | |
$(encom.comment + '.buried').remove(); | |
} | |
// move the featured images to the top of the list | |
if ( encom.featured == 'top' ) { | |
var comments = $(encom.comment + '.featured').detach(); | |
$(encom.container).prepend( comments ); | |
} | |
// if hideform then show the add comment link | |
if ( encom.hideform ) { | |
$('li.tab-add-comment').show(); | |
$('#respond').hide(); | |
} else { | |
$('li.tab-add-comment').hide(); | |
} | |
// add the tabs | |
if ( encom.showtabs ) { | |
var tab_c = encom.tabclasses.split(','); | |
tab_c.unshift('all'); | |
var tab_h = encom.tabheadings.split(','); | |
tab_h.unshift('All'); | |
var tabs_html = '<ul class="comment-tabs">'; | |
for (i=0;i<tab_c.length;i++) { | |
// only add a tab if it has comments | |
if ( tab_c[i] == 'all' || $(encom.comment + '.' + tab_c[i]).length > 0 ) { | |
tabs_html = tabs_html + '<li class="tab-' + tab_c[i] + '"><a class="tab-link" href="#' + tab_c[i] + '">' + tab_h[i] + '</a></li>'; | |
} else { | |
// if empty tab is showfirst then change to 'all' | |
if ( encom.showfirst == tab_c[i] ) { | |
encom.showfirst = 'all'; | |
} | |
} | |
} | |
tabs_html = tabs_html + '<li class="tab-add-comment"><a href="#add-comment">Add Comment</a></li></ul>'; | |
// add tab containers | |
//$(tabs_html).insertAfter( '.comments-title' ); | |
$( encom.container ).before( tabs_html ); | |
// show 'showfirst' list of comments | |
showcomments(encom.showfirst); | |
} | |
// move comment form to top if necessary | |
if ( encom.commentform == 'top' ) { | |
$(encom.container).before( $('#respond') ); | |
} | |
// switching to view all comments | |
$('a.tab-link').click(function(event){ | |
var tab_class = event.target.getAttribute('href').replace('#',''); | |
showcomments( tab_class ); | |
event.preventDefault(); | |
}); | |
// show comment form | |
$('a[href="#add-comment"]').click(function(event){ | |
event.preventDefault(); | |
$('#respond').toggle(); | |
}); | |
// this caters for any handlers being on the <a> link (Isola does this) | |
$('a.comment-reply-link').parent().click(function(event){ | |
event.preventDefault(); | |
$('#respond').show(); | |
}); | |
}); | |
function showcomments(show_class){ | |
// if all then just show all, otherwise just show class | |
if (show_class=='all') { | |
jQuery(encom.comment).show(); | |
} else { | |
jQuery(encom.comment).hide(); | |
jQuery(encom.comment + '.' + show_class).show(); | |
} | |
// set correct tab to active | |
jQuery('.comment-tabs li').removeClass('active'); | |
jQuery('li.tab-' + show_class).addClass('active'); | |
// if we are hiding the form then hide when we change tabs | |
if ( encom.hideform ) jQuery('#respond').hide(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type='text/javascript'> | |
/* <![CDATA[ */ | |
var encom = { | |
"container":"ol.comment-list", | |
"comment":"li.comment", | |
"featured":"top", | |
"buried":"remove", | |
"commentform":"top", | |
"hideform":"1", | |
"showtabs":"1", | |
"tabclasses":"featured,bypostauthor", | |
"tabheadings":"Featured,Author", | |
"showfirst":"featured" | |
}; | |
/* ]]> */ | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encom_enqueue_scripts() { | |
global $encom_default; | |
/* only need to enqueue if a single page */ | |
if ( !is_admin() ) { | |
// Register the init script | |
wp_register_script( 'encom_init', plugins_url( 'js/init.js', __FILE__ ), array('jquery'), null, true ); | |
// Now we can localize the script with our data. | |
$encom_array = get_option( 'enhanced_comments_settings' , $encom_default ); | |
wp_localize_script( 'encom_init', 'encom', $encom_array ); | |
// Enqueue the scripts. | |
wp_enqueue_script( 'encom_init' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts' , 'encom_enqueue_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment