1function debounce(func, wait, immediate) { 2 var timeout; 3 return function () { 4 var context = this, args = arguments; 5 var later = function () { 6 timeout = null; 7 if (!immediate) func.apply(context, args); 8 }; 9 var callNow = immediate && !timeout; 10 clearTimeout(timeout); 11 timeout = setTimeout(later, wait); 12 if (callNow) func.apply(context, args); 13 }; 14}; 15 16function validateEmail(email) { 17 var testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i; 18 return testEmail.test(email.trim()); 19} 20 21function reloadNewsFeedItemActivity(instance) { 22 var container = $(instance).parents('.upvotes-and-comments-placeholder'); 23 var containerReloadUrl = container.data('reload-url') 24 var containerReloadTemplate = container.data('reload-template') 25 $.getJSON(containerReloadUrl, function (data) { 26 var tmpl = $.templates(containerReloadTemplate); 27 var html = tmpl.render(data); 28 container.find('.toolbar').replaceWith($(html).find('.toolbar')); 29 container.find('.comments-container').replaceWith($(html).find('.comments-container')); 30 setupCommentsAndUpvotes(); 31 }); 32} 33 34function setupCommentsAndUpvotes() { 35 autosize($('textarea')); 36 jQuery('.publication-time').timeago(); 37 38 $('.toolbar .comments').unbind("click").click(function () { 39 $(this).parents('.newsfeed-item').find('.comment textarea').focus(); 40 }); 41 42 $('textarea').unbind("keyup").keyup(function () { 43 44 $('.comment').removeClass('active'); 45 if ($(this).val().trim().length > 0) { 46 $(this).parent().find('.controls').show(); 47 $(this).parents('.comment').find('.comment-posted').fadeOut(); 48 } else { 49 $(this).parent().find('.controls').hide(); 50 } 51 }); 52 53 $('.comments-container .comment .cancel-comment').unbind("click").click(function () { 54 if (confirm("Are you sure you want to cancel?")) { 55 $('.comment').removeClass('active'); 56 $(this).parents('.comment').find('textarea').val(''); 57 $(this).parents('.comment').find('.controls').fadeOut(); 58 $(this).parents('.comment').find('.new-comment.reply').fadeOut(); 59 } 60 }); 61 62 $('.comments-container .comment .reply-comment').unbind("click").click(function () { 63 $(this).parents('.comments-list').find('.new-comment.reply').fadeOut(); 64 $(this).parents('.comment').find('.new-comment').fadeIn(); 65 $(this).parents('.comment').find('textarea').show(); 66 $(this).parents('.comment').find('textarea').focus(); 67 $(this).parents('.comment').find('.comment-posted').fadeOut(); 68 }); 69 70 $('.comments-container .comment .submit-comment').unbind("click").click(function () { 71 72 var editable = $(this).parents('.comments-container').hasClass('editable'); 73 74 if (editable || $(this).parents('.comment').hasClass('active')) { 75 var podcastOwnerId = $(this).parents('.comment').find('input[name=podcastOwnerId]'); 76 var targetIdInput = $(this).parents('.comment').find('input[name=targetId]'); 77 var targetTypeInput = $(this).parents('.comment').find('input[name=targetType]'); 78 var parentCommentIdInput = $(this).parents('.comment').find('input[name=parentCommentId]'); 79 var textInput = $(this).parents('.comment').find('textarea'); 80 var nameInput = $(this).parents('.comment').find('input[name=name]'); 81 var emailInput = $(this).parents('.comment').find('input[name=email]'); 82 83 if (editable || (nameInput.val().trim().length > 0 && (emailInput.val().trim().length > 0 && validateEmail(emailInput.val())))) { 84 85 var self = this; 86 87 $.post($(this).data('url'), 88 { 89 PodcastOwnerId: podcastOwnerId.val(), 90 targetId: targetIdInput.val(), 91 targetType: targetTypeInput.val(), 92 parentCommentId: parentCommentIdInput.val(), 93 authorName: nameInput.val().trim(), 94 authorEmail: emailInput.val().trim(), 95 text: textInput.val().trim(), 96 }, 97 function (response) { 98 if (editable) { 99 reloadNewsFeedItemActivity(self); 100 } 101 } 102 ); 103 104 if (!editable) { 105 $(self).parents('.comment').find('.comment-posted').fadeIn(); 106 $(self).parents('.comment').find('textarea').val(''); 107 $(self).parents('.comment').find('.new-comment.reply').find('textarea').hide(); 108 $(self).parents('.comment').find('input[name=name]').val(''); 109 $(self).parents('.comment').find('input[name=email]').val(''); 110 $(self).parents('.comment').find('.controls').fadeOut(); 111 $('.comment').removeClass('active'); 112 } 113 } else { 114 if (nameInput.val().trim().length === 0) { 115 nameInput.effect("shake"); 116 } 117 118 if (emailInput.val().trim().length === 0 || !validateEmail(emailInput.val())) { 119 emailInput.effect("shake"); 120 } 121 } 122 } else { 123 $('.comment').removeClass('active'); 124 $(this).parents('.comment').addClass('active'); 125 $(this).parents('.comment').find('input[name=name]').focus(); 126 } 127 }); 128 129 $('.comments-container .comment .comment-delete-action').unbind("click").click(function () { 130 131 if (confirm("Are you sure you want to delete this comment?")) { 132 var self = this; 133 134 var url = $(this).data('url'); 135 var id = $(this).parents('.comment').data('id'); 136 137 $.post(url, { id: id }, 138 function (response) { 139 //$(self).parents('.comment[data-id=' + id + ']').remove(); 140 reloadNewsFeedItemActivity(self); 141 } 142 ); 143 } 144 }); 145 146 147 $('.comments-container .comment .comment-approve-action').unbind("click").click(function () { 148 149 var self = this; 150 151 var url = $(this).data('url'); 152 var id = $(this).parents('.comment').data('id'); 153 154 $.post(url, { id: id }, 155 function (response) { 156 reloadNewsFeedItemActivity(self); 157 } 158 ); 159 }); 160 161 $('.comments-container .comment .comment-block-action').unbind("click").click(function () { 162 163 if (confirm("Are you sure you want to delete this comment and block an author?")) { 164 165 var self = this; 166 167 var url = $(this).data('url'); 168 var id = $(this).parents('.comment').data('id'); 169 170 $.post(url, { id: id }, 171 function (response) { 172 reloadNewsFeedItemActivity(self); 173 } 174 ); 175 } 176 }); 177 178 $('.likes .upvote').unbind("click").click(function () { 179 180 var self = this; 181 182 $.post($(this).data('url'), 183 { 184 podcastOwnerId: $(this).data('owner-id'), 185 targetId: $(this).data('target-id'), 186 targetType: $(this).data('target-type') 187 }, 188 function (response) { 189 190 } 191 ); 192 193 var currentLikes = $(self).parent().find('.likes-count').text().trim(); 194 195 if (currentLikes.length === 0) { 196 $(self).parent().find('.likes-count').text(1) 197 } else { 198 var currentLikesCount = parseInt(currentLikes); 199 200 if ($(self).hasClass('upvoted')) { 201 currentLikesCount--; 202 } else { 203 currentLikesCount++; 204 } 205 206 if (currentLikesCount == 0) { 207 $(self).parent().find('.likes-count').text(''); 208 } else { 209 $(self).parent().find('.likes-count').text(currentLikesCount); 210 } 211 } 212 213 $(self).toggleClass('upvoted'); 214 }); 215}
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.