1/** 2 * @version $Id: k2.js 1919 2013-02-11 19:02:02Z joomlaworks $ 3 * @package K2 4 * @author JoomlaWorks http://www.joomlaworks.net 5 * @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved. 6 * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html 7 */ 8 9var $K2 = jQuery.noConflict(); 10 11$K2(document).ready(function(){ 12 13 // Generic function to get URL params passed in .js script include 14 function getUrlParams(targetScript, varName) { 15 var scripts = document.getElementsByTagName('script'); 16 var scriptCount = scripts.length; 17 for (var a = 0; a < scriptCount; a++) { 18 var scriptSrc = scripts[a].src; 19 if (scriptSrc.indexOf(targetScript) >= 0) { 20 varName = varName.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 21 var re = new RegExp("[\\?&]" + varName + "=([^&#]*)"); 22 var parsedVariables = re.exec(scriptSrc); 23 if (parsedVariables !== null) { 24 return parsedVariables[1]; 25 } 26 } 27 } 28 } 29 30 // Set the site root path 31 var K2SitePath = getUrlParams('k2.js', 'sitepath'); 32 33 // Comments 34 $K2('#comment-form').submit(function(event){ 35 event.preventDefault(); 36 $K2('#formLog').empty().addClass('formLogLoading'); 37 $K2.ajax({ 38 url: $K2('#comment-form').attr('action'), 39 type: 'post', 40 dataType: 'json', 41 data: $K2('#comment-form').serialize(), 42 success: function(response){ 43 $K2('#formLog').removeClass('formLogLoading').html(response.message); 44 if(typeof(Recaptcha) != "undefined"){ 45 Recaptcha.reload(); 46 } 47 if (response.refresh) { 48 window.location.reload(); 49 } 50 } 51 }); 52 }); 53 54 $K2('.commentRemoveLink').click(function(event){ 55 event.preventDefault(); 56 var element = $K2(this); 57 $K2(element).parent().addClass('commentToolbarLoading'); 58 $K2.ajax({ 59 url: $K2(element).attr('href'), 60 type: 'post', 61 data: $K2('#comment-form input:last').serialize(), 62 success: function(response){ 63 $K2(element).parent().removeClass('commentToolbarLoading'); 64 if(response=='true'){ 65 $K2(element).parent().parent().remove(); 66 } 67 } 68 }); 69 }); 70 71 $K2('.commentApproveLink').click(function(event){ 72 event.preventDefault(); 73 var element = $K2(this); 74 $K2(element).parent().addClass('commentToolbarLoading'); 75 $K2.ajax({ 76 url: $K2(element).attr('href'), 77 type: 'post', 78 data: $K2('#comment-form input:last').serialize(), 79 success: function(response){ 80 $K2(element).parent().removeClass('commentToolbarLoading'); 81 if(response=='true'){ 82 $K2(element).parent().parent().removeClass('unpublishedComment'); 83 } 84 } 85 }); 86 }); 87 88 $K2('.k2ReportUserButton').click(function(event){ 89 event.preventDefault(); 90 if (confirm(K2Language[0])) { 91 var element = $K2(this); 92 $K2(element).parent().addClass('commentToolbarLoading'); 93 $K2.ajax({ 94 url: $K2(element).attr('href'), 95 type: 'GET', 96 success: function(response){ 97 $K2(element).parent().removeClass('commentToolbarLoading'); 98 alert(response); 99 } 100 }); 101 } 102 103 }); 104 105 $K2('#k2ReportCommentForm').submit(function(event){ 106 event.preventDefault(); 107 $K2('#formLog').empty().addClass('formLogLoading'); 108 $K2.ajax({ 109 url: $K2('#k2ReportCommentForm').attr('action'), 110 type: 'post', 111 data: $K2('#k2ReportCommentForm').serialize(), 112 success: function(response){ 113 $K2('#formLog').removeClass('formLogLoading').html(response); 114 if(typeof(Recaptcha) != "undefined"){ 115 Recaptcha.reload(); 116 } 117 } 118 }); 119 }); 120 121 // Text Resizer 122 $K2('#fontDecrease').click(function(event){ 123 event.preventDefault(); 124 $K2('.itemFullText').removeClass('largerFontSize'); 125 $K2('.itemFullText').addClass('smallerFontSize'); 126 }); 127 $K2('#fontIncrease').click(function(event){ 128 event.preventDefault(); 129 $K2('.itemFullText').removeClass('smallerFontSize'); 130 $K2('.itemFullText').addClass('largerFontSize'); 131 }); 132 133 // Smooth Scroll 134 $K2('.k2Anchor').click(function(event){ 135 event.preventDefault(); 136 var target = this.hash; 137 $K2('html, body').stop().animate({ 138 scrollTop: $K2(target).offset().top 139 }, 500); 140 }); 141 142 // Rating 143 $K2('.itemRatingForm a').click(function(event){ 144 event.preventDefault(); 145 var itemID = $K2(this).attr('rel'); 146 var log = $K2('#itemRatingLog' + itemID).empty().addClass('formLogLoading'); 147 var rating = $K2(this).html(); 148 $K2.ajax({ 149 url: K2SitePath+"index.php?option=com_k2&view=item&task=vote&format=raw&user_rating=" + rating + "&itemID=" + itemID, 150 type: 'get', 151 success: function(response){ 152 log.removeClass('formLogLoading'); 153 log.html(response); 154 $K2.ajax({ 155 url: K2SitePath+"index.php?option=com_k2&view=item&task=getVotesPercentage&format=raw&itemID=" + itemID, 156 type: 'get', 157 success: function(percentage){ 158 $K2('#itemCurrentRating' + itemID).css('width', percentage + "%"); 159 setTimeout(function(){ 160 $K2.ajax({ 161 url: K2SitePath+"index.php?option=com_k2&view=item&task=getVotesNum&format=raw&itemID=" + itemID, 162 type: 'get', 163 success: function(response){ 164 log.html(response); 165 } 166 }); 167 }, 2000); 168 } 169 }); 170 } 171 }); 172 }); 173 174 // Classic popup 175 $K2('.classicPopup').click(function(event){ 176 event.preventDefault(); 177 if($K2(this).attr('rel')){ 178 var json = $K2(this).attr('rel'); 179 json = json.replace(/'/g, '"'); 180 var options = $K2.parseJSON(json); 181 } else { 182 var options = {x:900,y:600}; /* use some default values if not defined */ 183 } 184 window.open($K2(this).attr('href'),'K2PopUpWindow','width='+options.x+',height='+options.y+',menubar=yes,resizable=yes'); 185 }); 186 187 // Live search 188 $K2('div.k2LiveSearchBlock form input[name=searchword]').keyup(function(event){ 189 var parentElement = $K2(this).parent().parent(); 190 if($K2(this).val().length>3 && event.key!='enter'){ 191 $K2(this).addClass('k2SearchLoading'); 192 parentElement.find('.k2LiveSearchResults').css('display','none').empty(); 193 parentElement.find('input[name=t]').val($K2.now()); 194 parentElement.find('input[name=format]').val('raw'); 195 var url = 'index.php?option=com_k2&view=itemlist&task=search&' + parentElement.find('form').serialize(); 196 parentElement.find('input[name=format]').val('html'); 197 $K2.ajax({ 198 url: url, 199 type: 'get', 200 success: function(response){ 201 parentElement.find('.k2LiveSearchResults').html(response); 202 parentElement.find('input[name=searchword]').removeClass('k2SearchLoading'); 203 parentElement.find('.k2LiveSearchResults').css('display', 'block'); 204 } 205 }); 206 } else { 207 parentElement.find('.k2LiveSearchResults').css('display','none').empty(); 208 } 209 }); 210 211 // Calendar 212 if($K2().jquery > '1.9.0') { 213 $K2('.k2CalendarBlock').on('click', '.calendarNavLink', function(event){ 214 event.preventDefault(); 215 var parentElement = $K2(this).parent().parent().parent().parent(); 216 var url = $K2(this).attr('href'); 217 parentElement.empty().addClass('k2CalendarLoader'); 218 $K2.ajax({ 219 url: url, 220 type: 'post', 221 success: function(response){ 222 parentElement.html(response); 223 parentElement.removeClass('k2CalendarLoader'); 224 } 225 }); 226 }); 227 } 228 else { 229 $K2('a.calendarNavLink').live('click', function(event){ 230 event.preventDefault(); 231 var parentElement = $K2(this).parent().parent().parent().parent(); 232 var url = $K2(this).attr('href'); 233 parentElement.empty().addClass('k2CalendarLoader'); 234 $K2.ajax({ 235 url: url, 236 type: 'post', 237 success: function(response){ 238 parentElement.html(response); 239 parentElement.removeClass('k2CalendarLoader'); 240 } 241 }); 242 }); 243 } 244 245 // Generic Element Scroller (use .k2Scroller in the container and .k2ScrollerElement for each contained element) 246 $K2('.k2Scroller').css('width',($K2('.k2Scroller').find('.k2ScrollerElement:first').outerWidth(true))*$K2('.k2Scroller').children('.k2ScrollerElement').length); 247 248}); 249 250// Equal block heights for the "default" view 251$K2(window).load(function () { 252 var blocks = $K2('.subCategory, .k2EqualHeights'); 253 var maxHeight = 0; 254 blocks.each(function(){ 255 maxHeight = Math.max(maxHeight, parseInt($K2(this).css('height'))); 256 }); 257 blocks.css('height', maxHeight); 258});
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.