/** * @version $Id: k2.js 1965 2013-04-29 16:01:44Z lefteris.kavadas $ * @package K2 * @author JoomlaWorks http://www.joomlaworks.net * @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved. * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html */ var K2JVersion; var selectsInstance; $K2(document).ready(function() { // Set the selects instance to allow inheritance of jQuery chosen bindings if ( typeof (K2JVersion) !== 'undefined' && K2JVersion === '30') { selectsInstance = jQuery; } else { selectsInstance = $K2; } // Generic function to get URL params passed in .js script include function getUrlParams(targetScript, varName) { var scripts = document.getElementsByTagName('script'); var scriptCount = scripts.length; for (var a = 0; a < scriptCount; a++) { var scriptSrc = scripts[a].src; if (scriptSrc.indexOf(targetScript) >= 0) { varName = varName.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var re = new RegExp("[\\?&]" + varName + "=([^]*)"); var parsedVariables = re.exec(scriptSrc); if (parsedVariables !== null) { return parsedVariables[1]; } } } } // Set the site root path var K2SitePath = getUrlParams('k2.js', 'sitepath'); // Common functions $K2('#jToggler').click(function() { if ($K2(this).attr('checked')) { $K2('input[id^=cb]').attr('checked', true); $K2('input[name=boxchecked]').val($K2('input[id^=cb]:checked').length); } else { $K2('input[id^=cb]').attr('checked', false); $K2('input[name=boxchecked]').val('0'); } }); $K2('#k2SubmitButton').click(function() { this.form.submit(); }); $K2('#k2ResetButton').click(function(event) { event.preventDefault(); $K2('.k2AdminTableFilters input').val(''); $K2('.k2AdminTableFilters option').removeAttr('selected'); this.form.submit(); }); selectsInstance('.k2AdminTableFilters select').change(function() { this.form.submit(); }); // View specific functions if ($K2('#k2AdminContainer').length > 0) { var view = $K2('#k2AdminContainer input[name=view]').val(); } else { var view = $K2('#k2FrontendContainer input[name=view]').val(); } $K2('.k2ReportUserButton').click(function(event) { event.preventDefault(); if (view == 'comments') { var alert = K2Language[2]; } else { var alert = K2Language[0]; } if (confirm(alert)) { window.location.href = $K2(this).attr('href'); } }); switch(view) { case 'comments': var flag = false; $K2('.editComment').click(function(event) { event.preventDefault(); if (flag) { alert(K2Language[0]); return; } flag = true; var commentID = $K2(this).attr('rel'); var target = $K2('#k2Comment' + commentID + ' .commentText'); var value = target.text(); $K2('#k2Comment' + commentID + ' input').val(value); target.empty(); var textarea = $K2('', { name : 'comment', rows : '5', cols : '40' }); textarea.html(value).appendTo(target); textarea.focus(); $K2('#k2Comment' + commentID + ' .commentToolbar a').css('display', 'inline'); $K2(this).css('display', 'none'); }); $K2('.closeComment').click(function(event) { event.preventDefault(); flag = false; var commentID = $K2(this).attr('rel'); var target = $K2('#k2Comment' + commentID + ' .commentText'); var value = $K2('#k2Comment' + commentID + ' input').val(); target.html(value); $K2('#k2Comment' + commentID + ' .commentToolbar a').css('display', 'none'); $K2('#k2Comment' + commentID + ' .commentToolbar a.editComment').css('display', 'inline'); }); $K2('.saveComment').click(function(event) { event.preventDefault(); flag = false; var commentID = $K2(this).attr('rel'); var target = $K2('#k2Comment' + commentID + ' .commentText'); var value = $K2('#k2Comment' + commentID + ' .commentText textarea').val(); $K2('#task').val('saveComment'); $K2('#commentID').val(commentID); $K2('#commentText').val(value); var log = $K2('#k2Comment' + commentID + ' .k2CommentsLog'); log.addClass('k2CommentsLoader'); $K2.ajax({ url : 'index.php', type : 'post', dataType : 'json', data : $K2('#adminForm').serialize(), success : function(result) { target.html(result.comment); $K2('#k2Comment' + commentID + ' input').val(result.comment); $K2('#task').val(''); log.removeClass('k2CommentsLoader').html(result.message).delay(3000).fadeOut(); } }); $K2('#k2Comment' + commentID + ' .commentToolbar a').css('display', 'none'); $K2('#k2Comment' + commentID + ' .commentToolbar a.editComment').css('display', 'inline'); }); if ($K2('input[name=isSite]').val() == 1) { $K2('.k2CommentsPagination a').click(function(event) { var url = $K2(this).attr('href').split('limitstart='); event.preventDefault(); $K2('input[name=limitstart]').val(url[1]); Joomla.submitform(); }); } break; case 'extrafield': if ($K2('#groups').val() > 0) { $K2('#groupContainer').fadeOut(0); } selectsInstance('#groups').change(function() { var selectedValue = selectsInstance(this).val(); if (selectedValue == 0) { $K2('#group').val(''); $K2('#isNew').val('1'); $K2('#groupContainer').fadeIn('slow'); } else { $K2('#groupContainer').fadeOut('slow', function() { $K2('#group').val(selectedValue); $K2('#isNew').val('0'); }); } }); if ($K2('input[name=id]').val()) { newField = 0; } else { newField = 1; } if (!newField) { var values = $K2.parseJSON($K2('#value').val()); } else { var values = new Array(); values[0] = " "; } renderExtraFields($K2('#type').val(), values, newField); selectsInstance('#type').change(function() { var selectedType = selectsInstance(this).val(); $K2('#k2ExtraFieldsShowNullFlag').fadeOut('slow'); $K2('#k2ExtraFieldsDisplayInFrontEndFlag').fadeOut('slow'); $K2('#k2ExtraFieldsRequiredFlag').fadeOut('slow'); $K2('#exFieldsTypesDiv').fadeOut('slow', function() { $K2('#exFieldsTypesDiv').empty(); renderExtraFields(selectedType, values, newField); $K2('#exFieldsTypesDiv').fadeIn('slow'); if(selectedType === 'select' || selectedType === 'multipleSelect') { $K2('#k2ExtraFieldsShowNullFlag').fadeIn('slow'); } if(selectedType !== 'header') { $K2('#k2ExtraFieldsRequiredFlag').fadeIn('slow'); } if(selectedType === 'header') { $K2('#k2ExtraFieldsDisplayInFrontEndFlag').fadeIn('slow'); } }); }); extraFieldsImage(); break; case 'usergroup': var value = $K2('input[name=categories]:checked').val(); if (value == 'all') { selectsInstance('#paramscategories').attr('disabled', 'disabled'); selectsInstance('#paramscategories option').each(function() { selectsInstance(this).attr('disabled', 'disabled'); selectsInstance(this).attr('selected', 'selected'); }); } else if (value == 'none') { selectsInstance('#paramscategories').attr('disabled', 'disabled'); selectsInstance('#paramscategories option').each(function() { selectsInstance(this).attr('disabled', 'disabled'); selectsInstance(this).removeAttr('selected'); }); } else { selectsInstance('#paramscategories').removeAttr('disabled'); selectsInstance('#paramscategories option').each(function() { selectsInstance(this).removeAttr('disabled'); }); } selectsInstance('#categories-all').click(function() { selectsInstance('#paramscategories').attr('disabled', 'disabled'); selectsInstance('#paramscategories option').each(function() { selectsInstance(this).attr('disabled', 'disabled'); selectsInstance(this).attr('selected', 'selected'); }); selectsInstance("#paramscategories").trigger("liszt:updated"); }); selectsInstance('#categories-none').click(function() { selectsInstance('#paramscategories').attr('disabled', 'disabled'); selectsInstance('#paramscategories option').each(function() { selectsInstance(this).attr('disabled', 'disabled'); selectsInstance(this).removeAttr('selected'); }); selectsInstance("#paramscategories").trigger("liszt:updated"); }); selectsInstance('#categories-select').click(function() { selectsInstance('#paramscategories').removeAttr('disabled'); selectsInstance('#paramscategories option').each(function() { selectsInstance(this).removeAttr('disabled'); }); selectsInstance("#paramscategories").trigger("liszt:updated"); }); break; case 'category': $K2('#k2Accordion').accordion({ collapsible : true, autoHeight : false }); $K2('#k2Tabs').tabs(); $K2('#k2ImageBrowseServer').click(function(event) { event.preventDefault(); SqueezeBox.initialize(); SqueezeBox.fromElement(this, { handler : 'iframe', url : K2BasePath + 'index.php?option=com_k2&view=media&type=image&tmpl=component&fieldID=existingImageValue', size : { x : 800, y : 434 } }); }); break; case 'item': $K2('#k2Accordion').accordion({ collapsible : true, autoHeight : false }); $K2('#k2Tabs').tabs(); if ( typeof (K2ActiveVideoTab) === 'undefined') { $K2('#k2VideoTabs').tabs(); } else { $K2('#k2VideoTabs').tabs({ selected : K2ActiveVideoTab }); } $K2('#k2ToggleSidebar').click(function(event) { event.preventDefault(); $K2('#adminFormK2Sidebar').toggle(); }); $K2('#catid option[disabled]').css('color', '#808080'); setTimeout(function() { initExtraFieldsEditor(); }, 1000); $K2('.deleteAttachmentButton').click(function(event) { event.preventDefault(); if (confirm(K2Language[3])) { var element = $K2(this).parent().parent(); var url = $K2(this).attr('href'); $K2.ajax({ url : url, type : 'get', success : function() { $K2(element).fadeOut('fast', function() { $K2(element).remove(); }); } }); } }); $K2('#resetHitsButton').click(function(event) { event.preventDefault(); Joomla.submitbutton('resetHits'); }); $K2('#resetRatingButton').click(function(event) { event.preventDefault(); Joomla.submitbutton('resetRating'); }); $K2('#addAttachmentButton').click(function(event) { event.preventDefault(); addAttachment(); }); $K2('#newTagButton').click(function() { var log = $K2('#tagsLog'); log.empty().addClass('tagsLoading'); var tag = $K2('#tag').val(); var url = 'index.php?option=com_k2&view=item&task=tag&tag=' + tag; $K2.ajax({ url : url, type : 'get', dataType : 'json', success : function(response) { if (response.status == 'success') { var option = $K2('', { value : response.id }).html(response.name).appendTo($K2('#tags')); } log.html(response.msg); log.removeClass('tagsLoading'); } }); }); $K2('#addTagButton').click(function() { $K2('#tags option:selected').each(function() { $K2(this).appendTo($K2('#selectedTags')); }); }); $K2('#removeTagButton').click(function() { $K2('#selectedTags option:selected').each(function(el) { $K2(this).appendTo($K2('#tags')); }); }); selectsInstance('#catid').change(function() { if (selectsInstance(this).find('option:selected').attr('disabled')) { alert(K2Language[4]); selectsInstance(this).val('0'); return; } var selectedValue = $K2(this).val(); var url = K2BasePath + 'index.php?option=com_k2&view=item&task=extraFields&cid=' + selectedValue + '&id=' + $K2('input[name=id]').val(); $K2('#extraFieldsContainer').fadeOut('slow', function() { $K2.ajax({ url : url, type : 'get', success : function(response) { $K2('#extraFieldsContainer').html(response); initExtraFieldsEditor(); $K2('img.calendar').each(function() { inputFieldID = $K2(this).prev().attr('id'); imgFieldID = $K2(this).attr('id'); Calendar.setup({ inputField : inputFieldID, ifFormat : "%Y-%m-%d", button : imgFieldID, align : "Tl", singleClick : true }); }); $K2('#extraFieldsContainer').fadeIn('slow'); } }); }); }); $K2('#k2ImageBrowseServer').click(function(event) { event.preventDefault(); SqueezeBox.initialize(); SqueezeBox.fromElement(this, { handler : 'iframe', url : K2BasePath + 'index.php?option=com_k2&view=media&type=image&tmpl=component&fieldID=existingImageValue', size : { x : 800, y : 434 } }); }); $K2('#k2MediaBrowseServer').click(function(event) { event.preventDefault(); SqueezeBox.initialize(); SqueezeBox.fromElement(this, { handler : 'iframe', url : K2BasePath + 'index.php?option=com_k2&view=media&type=video&tmpl=component&fieldID=remoteVideo', size : { x : 800, y : 434 } }); }); $K2('#itemAttachments').on('click', '.k2AttachmentBrowseServer', function(event) { event.preventDefault(); var k2ActiveAttachmentField = $K2(this).next(); k2ActiveAttachmentField.attr('id', 'k2ActiveAttachment'); SqueezeBox.initialize(); SqueezeBox.fromElement(this, { handler : 'iframe', url : K2BasePath + 'index.php?option=com_k2&view=media&type=attachment&tmpl=component&fieldID=k2ActiveAttachment', size : { x : 800, y : 434 }, onClose : function() { k2ActiveAttachmentField.removeAttr('id'); } }); }); $K2('.tagRemove').click(function(event) { event.preventDefault(); $K2(this).parent().remove(); }); $K2('ul.tags').click(function() { $K2('#search-field').focus(); }); $K2('#search-field').keypress(function(event) { if (event.which == '13') { if ($K2(this).val() != '') { $K2('