1/** 2 * Hide Show Comment 3 * 4 * @author Haris Ainur Rozak 5 * @since 0.1 6 */ 7;(function($) { 8 9 $.WPHSC = function(el, opt) 10 { 11 var base = this; 12 13 base.el = el; 14 base.$el = $(base.el); 15 16 base.$wpComment = base.$el.find('.hsc-comment-class'); 17 18 // if wp function comment_class() is not implement 19 if(base.$wpComment.length <= 0 && opt.loadMoreIdentifier != '') 20 { 21 base.$wpComment = base.$el.find(opt.loadMoreIdentifier); 22 } 23 24 var mainContainer = base.$wpComment.first(); 25 26 mainContainer.parent().first().wrap('<div class="hsc-comment-container" />'); 27 base.$container = base.$wpComment.parent().first().parent('.hsc-comment-container'); 28 29 base.count = base.$wpComment.length; 30 31 base.initialize = function() 32 { 33 if (window.location.hash) 34 { 35 base.hash = window.location.hash.substring(1); 36 } 37 else 38 { 39 base.hash = 'undefined'; 40 } 41 42 if(opt.hideShow) base.hideShow(); 43 if(opt.loadMore) 44 { 45 if(base.hash == 'undefined' || base.hash == 'comments') base.loadMore(); 46 } 47 } 48 49 base.hideShow = function() 50 { 51 if(opt.hideShowIdentifierMode == 'auto') 52 { 53 $(opt.hideShowHtml).insertBefore(base.$container); 54 } 55 else 56 { 57 base.$hideShowIdentifier = $(opt.hideShowIdentifier); 58 base.$hideShowIdentifier.wrapInner('<div class="hsc-comment-container" />'); 59 60 base.$containerIdentifier = base.$hideShowIdentifier.children('.hsc-comment-container'); 61 var mainContainer = base.$containerIdentifier.first(); 62 63 $(opt.hideShowHtml).insertBefore(mainContainer); 64 } 65 66 base.$btnHideShow = $('#hsc-btn-hideshow'); 67 base.$countHideShow = $('#hsc-count-hideshow'); 68 69 // collecting all .hsc-comment-container 70 base.$containerAll = $('.hsc-comment-container'); 71 72 // show if hash defined 73 if(base.hash == 'undefined') 74 { 75 base.$containerAll.css('display','none'); 76 } 77 else 78 { 79 base.$btnHideShow.html('<span>' + opt.hideShowTextHide + '</span>'); 80 base.$btnHideShow.addClass('active'); 81 base.$countHideShow.addClass('active'); 82 } 83 84 // button 85 base.$btnHideShow.click(function(){ 86 if($(this).hasClass('active')) 87 { 88 base.$btnHideShow.html('<span>' + opt.hideShowTextShow + '</span>'); 89 hideContainer(); 90 } 91 else 92 { 93 base.$btnHideShow.html('<span>' + opt.hideShowTextHide + '</span>'); 94 showContainer(); 95 } 96 }) 97 98 // count 99 base.$countHideShow.click(function(){ 100 if($(this).hasClass('active')) 101 { 102 hideContainer(); 103 } 104 else 105 { 106 showContainer(); 107 } 108 }) 109 110 function showContainer() 111 { 112 var animation = opt.hideShowAnimation; 113 114 base.$btnHideShow.addClass('active'); 115 base.$countHideShow.addClass('active'); 116 117 if(animation == 'slide') 118 { 119 base.$containerAll.slideDown(); 120 } 121 else if(animation == 'fade') 122 { 123 base.$containerAll.fadeIn(); 124 } 125 else 126 { 127 base.$containerAll.show(); 128 } 129 } 130 131 function hideContainer() 132 { 133 var animation = opt.hideShowAnimation; 134 135 base.$btnHideShow.removeClass('active'); 136 base.$countHideShow.removeClass('active'); 137 138 if(animation == 'slide') 139 { 140 base.$containerAll.slideUp(); 141 } 142 else if(animation == 'fade') 143 { 144 base.$containerAll.fadeOut(); 145 } 146 else 147 { 148 base.$containerAll.hide(); 149 } 150 } 151 } 152 153 base.loadMore = function() 154 { 155 $(base.$container).children().append(opt.loadMoreHtml); 156 157 base.$btnLoadMore = $('#hsc-btn-loadmore'); 158 base.$wpComment.css('display','none'); 159 160 count = 0; 161 162 doLoadMore(true); 163 164 base.$btnLoadMore.click(function(){ 165 doLoadMore(); 166 }) 167 168 function doLoadMore(isFirst) 169 { 170 var animation = isFirst ? 'none' : opt.loadMoreAnimation; 171 172 for (var i = 1; i <= opt.loadMoreCount; i++) 173 { 174 if(animation == 'slide') 175 { 176 base.$wpComment.eq(count++).slideDown(); 177 } 178 else if(animation == 'fade') 179 { 180 base.$wpComment.eq(count++).fadeIn(); 181 } 182 else 183 { 184 base.$wpComment.eq(count++).show(); 185 } 186 }; 187 188 if(count >= base.count) 189 { 190 base.$btnLoadMore.remove(); 191 } 192 } 193 } 194 } 195 196 197 /** 198 * Implementation 199 * 200 * @since 0.1 201 */ 202 $.WPHSC.defaults = { 203 'hideShow': true, 204 'hideShowHtml': "<a href='javascript:;' id='hsc-btn-hideshow'><span>Comment</span></a>", 205 'hideShowTextShow': "Show Comment", 206 'hideShowTextHide': "Hide Comment", 207 'hideShowIdentifierMode': 'auto', // auto, manual 208 'hideShowIdentifier': '#comments', 209 'hideShowAnimation': 'none',
210 'loadMore': true, 211 'loadMoreHtml': "<a href='javascript:;' id='hsc-btn-loadmore'><span>Load More</span></a>", 212 'loadMoreCount': 3, 213 'loadMoreAnimation': 'none' 214 } 215 216 $.fn.WPHSC = function(options) 217 { 218 var base = this; 219 var opt = $.extend({}, $.WPHSC.defaults, options); 220 var plugin = new $.WPHSC(base, opt); 221 222 base.each(function() { 223 plugin.initialize(); 224 }); 225 226 return base; 227 }; 228 229})(jQuery); 230 231 232// Run 233jQuery(document).ready(function($){ 234 var hsc = $('body').WPHSC({ 235 'hideShow': hide_show, 236 'hideShowHtml': hsc_hideshow_print, 237 'hideShowTextShow': hsc_show_button_text, 238 'hideShowTextHide': hsc_hide_button_text, 239 'hideShowIdentifierMode': identifier_type, 240 'hideShowIdentifier': comment_identifier, 241 'loadMoreIdentifier': loadmore_identifier, 242 'hideShowAnimation': hide_show_animation, 243 'loadMore': load_more, 244 'loadMoreHtml': hsc_loadmore_print, 245 'loadMoreCount': loadmore_load_number, 246 'loadMoreAnimation': load_more_animation 247 }); 248});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.