diff --git a/src/noosfero-spb/noosfero-spb-theme/theme.js b/src/noosfero-spb/noosfero-spb-theme/theme.js index 5ab2919..2ff2b86 100644 --- a/src/noosfero-spb/noosfero-spb-theme/theme.js +++ b/src/noosfero-spb/noosfero-spb-theme/theme.js @@ -1,303 +1,313 @@ -function alignBlocks(containerIndex){ - //Needed to save the original reference to jQuery(this) - jt = jQuery(this); - longerBlock = 0; - jt.find(".block-outer").each(function () { - if(jQuery(this).height() > longerBlock) - longerBlock = jQuery(this).height(); - }); +/* globals jQuery */ - jt.find("#block-48504 .block-inner-2").height(492); - jt.find("#block-55304 .block-inner-2").height(378); - - //Aligns the blocks in the most common situations - jt.find(".block-outer").height(longerBlock); - //Only used for blocks with video, since it uses the size of the iframe - if(jt.find("iframe").length > 0){ - jt.find(".block-inner-1 .block-inner-2").each(function (idx) { - if(idx==2){ - jQuery(this).height(jt.find("iframe").height()); - } - }); - } -} +// Theme namespace +var SPBNoosferoTheme = {}; -(function($) { - // Run code - if($.cookie("high_contrast") === 'true'){ - $( "body" ).toggleClass( "contraste" ); - } - $( "#siteaction-contraste a" ).click(function() { - $( "body" ).toggleClass( "contraste" ); - if($('body').hasClass('contraste')){ - $.cookie('high_contrast', 'true', {path: '/'}); - } else { - $.cookie('high_contrast', null, { path: '/' }); - } - }); - - $( ".profile-image" ).prepend( "" ); - //insere a mensagem no bloco de trilhas na página inicial// - $( ".action-home-index #content .community-track-plugin_track-card-list-block .track_list" ).prepend( "Construa seu caminho de participação na elaboração de políticas públicas..." ); - //insere a mensagem no bloco de comunidades na página inicial// - $( ".action-home-index #content .communities-block .block-inner-2>div" ).prepend( "Participe dos dialogos entre governo e sociedade em comunidades temáticas..." ); - $( ".action-home-index #content .communities-block .block-inner-2>div.block-footer-content .msg_block" ).remove(); - $('.container-block-plugin_container-block').each(alignBlocks); - - $('#block-48500 > .block-inner-1 > .block-inner-2').append('
'); +// Add in jQuery a method that executes a given function only if there is a filled query result +jQuery.fn.doOnce = function( func ) { + this.length && func.apply( this ); + return this; +} +// Animate Organization Ratings additional informations form +SPBNoosferoTheme.OrganizationRatings = (function($) { + 'use strict'; + // Add a question mark next to each form field, so when user mouse over it, + // it displays some userfull information about the field + function setTooltipContent() { + $('span.star-tooltip').html('?'); + } -// Foco no botao de busca + // Given the current state of the form(hidden or in display) + // change the arrow image and animte its state change + function animateExtraFields(additionalFields, arrow) { + var innerHeight = additionalFields[0].offsetHeight; + + // If in display, puts the down arrow and hide the form + if(additionalFields.height() !== 0) { + arrow.attr('class', 'comments-arrow-down'); + additionalFields.animate({height: 0}); + } else { // if the form is hidden, puts the up arrow and display the form + arrow.attr('class', 'comments-arrow-up'); + additionalFields.animate({ + height: additionalFields.get(0).scrollHeight + }, 1000 ); + } -$('#link-buscar').click(function(e) { - e.defaultPrevented(); - window.location.hash = '#portal-searchbox'; - $('.searchField').focus() -}) + // Fix for the arrow change on the additional informations, it prevents the institution modal + // from killing the entire page. When the form had their status changed, the institution modal + // tended to cover the page even if it was not in display + document.getElementById('institution_modal').style.display = 'none'; + } -})(jQuery); + // Set additional informations form up and down arrows click event + function setArrowDirection() { + var reportForm = $('div.star-comment-container'); + var parent = reportForm.parent(); + reportForm.detach(); // Remove form from the page DOM + + // Apply arrows click event + var additionalDataBar = reportForm.find('div.comments-display-fields'); + additionalDataBar.on('click', function() { + var arrow = additionalDataBar.find('span[class*="comments-arrow"]'); + var additionalFields = reportForm.find('.comments-software-extra-fields'); + animateExtraFields(additionalFields, arrow); + }); + // Add the form back to the page + parent.append(reportForm); + } -// Efeito Fade nos box de softwares -(function($){ - "use strict";// Make javascript less intolerant to errors + function initialize() { + $('div.star-rate-form').doOnce(function() { + setTooltipContent(); + setArrowDirection(); + }); + } - var TRANSITION_TIME = 250;// milliseconds + return { + init: initialize + }; +}) (jQuery); - function show_finality() { - var finality = $(this).children(".software-block-finality"); +// Fade effect on software blocks of portal homepage +SPBNoosferoTheme.HighlightedSoftwaresBlock = (function($) { + 'use strict'; - //finality.stop().fadeTo(TRANSITION_TIME,1); + function showFinality() { + var finality = $(this).children('div.software-block-finality'); finality.stop().fadeTo('fast', 1); - //finality.stop().animate({"top" : "0%"}, TRANSITION_TIME); } - function hide_finality() { - var finality = $(this).children(".software-block-finality"); - - //finality.stop().fadeTo(TRANSITION_TIME,0); + function hideFinality() { + var finality = $(this).children('div.software-block-finality'); finality.stop().fadeTo('fast', 0); - //finality.stop().animate({"top" : "100%"}, TRANSITION_TIME); } - function move_article_buttons(){ - var article_actions = $('#article-actions').clone(); - var report = $('.report-abuse-action').remove(); - var suggest = $('.icon-suggest').remove(); + // Set the mouse over and out event in each of the finality blocks in the page + function setFadeInOutFinality(){ + $('#boxes div.software-block-finality').css({'opacity':0, 'top':0}); + var softwaresBlocks = $('#boxes div.software-block'); - - $(article_actions).find('.icon-edit, .icon-new, .icon-delete, .icon-locale').remove(); - $('.article-body').append(article_actions); + softwaresBlocks.mouseover(showFinality); + softwaresBlocks.mouseout(hideFinality); } - function add_link_to_article_div(){ - var list = $('.display-content-block').find('li'); + function initialize() { + $('#boxes .box-1 div.softwares-block').doOnce(function() { + setFadeInOutFinality(); + }); + } - list.each(function(){ - var link = $(this).find('.title').find('a').attr('href'); - var text = $(this).find('.lead').find('p').text(); + return { + init: initialize + }; +}) (jQuery); + + +SPBNoosferoTheme.NoosferoHTMLAdjusts = (function($) { + 'use strict'; + + // Take each list item from the block and apply to its lead the same link as its title + // then wraps the list item inside a new div with class notice-item + function insertLinksAndWrapsOnHomeNews(){ + var news = $('div.display-content-block').find('li'); + var parent = news.parent(); + news.detach(); + news.each(function(){ + //add link on lead + var link = $(this).find('div.title a').attr('href'); + var lead = $(this).find('div.lead'); var leadLink = $(''); leadLink.attr('href', link); - leadLink.text(text); + leadLink.text(lead.find('p').text()); + lead.html(leadLink); - $(this).find('.lead').html(leadLink); + //add wraps to improve styling + $(this).find('div:gt(0)').wrapAll(''); + $(this).find('.notice-item div:gt(0)').wrapAll(''); }); + + parent.append(news); } - function insert_notice_div(){ - var notice = $('.display-content-block').find('li'); - notice.each(function(){ - var $set = $(this).children(); - for(var i=1, len = $set.length; i < len; i+=5){ - $set.slice(i, i+5).wrapAll(''); - } - for(var i=2, len = $set.length; i < len; i+=3){ - $set.slice(i, i+3).wrapAll(''); + // Add a toggle tooltip to all span with title attribute + function addTooltips(){ + $('#content span[title]').doOnce(function(){ + this.attr('data-toggle', 'tooltip'); + this.tooltip(); + }); + } + + // Make the link next to a popover span show the popover when it is clicked + function addPopovers() { + var span = $('span[data-toggle="popover"]'); + var place = span.attr('data-placement'); + var elementClass = span.attr('data-class'); + + span.doOnce(function(){ + var popover = this.popover({ + html:true, + placement: place, + content: function() { + return $(this).next().html(); } - //$('').wrap($(this).find( '.image', '.title', '.lead', '.read_more')); + }) + .data('bs.popover'); + + if(popover) { + popover.tip() + .addClass(elementClass); + + // Make the link show the span popover when it is clicked + $('a.toggle-popover').on('click',function() { + span.trigger('click'); + }); + } }); + } + function moveBreadcrumbs() { + $('div.breadcrumbs-plugin_content-breadcrumbs-block').doOnce(function() { + this.insertBefore('#content-inner'); + $(' ').insertBefore(this.find('div.block-inner-2').children().first()); + }); } - //toggle filter options in catalog page - function setFilterCategoriesOptionClass() { - var filterOptions = $("#filter-categories-option"); - filterOptions.addClass("animated slideInDown"); + function removeButtons(){ + $('#article-actions').doOnce(function() { + $(this).children('.icon-spread, .icon-locale, .report-abuse-action, .icon-clone').remove(); + }); + + $('div.page-members-header').doOnce(function() { + $(this).find('.report-abuse-action').remove(); + }); } + // Put the focus on the search form when user click on the "go to search link" + function searchLinkApplyFocusToItsForm() { + $('#link-buscar').click(function(e) { + e.defaultPrevented(); + $('.searchField').focus(); + }); + } + + function initialize() { + insertLinksAndWrapsOnHomeNews(); + addTooltips(); + addPopovers(); + moveBreadcrumbs(); + searchLinkApplyFocusToItsForm(); + removeButtons(); + } + + return { + init: initialize + }; + +}) (jQuery); + +// Software catalog category filter toggle functionality +SPBNoosferoTheme.SoftwareCatalog = (function($) { + 'use strict'; + + // Apply the toggle animation on the category filter based on its current status function toggleFilterOptions(){ - var filterOptions = $("#filter-categories-option"); - var filterHeight = filterOptions[0].scrollHeight; - var showOptions = $("#filter-option-catalog-software"); - var hideOptions = $("#filter-option-catalog-close"); - if(hideOptions.is(":visible")){ - //filterOptions.slideUp(function() { - showOptions.show(); - hideOptions.hide(); - //}); + var filter = document.getElementById('filter-catalog-software'); + var filterOptions = $(filter.children[0]); // filter categories + var filterHeight = filterOptions[0].scrollHeight; // filter categories height to be used when displaying it + var showOptions = $(filter.children[1]); // Show categories div, has a click event + var hideOptions = $(filter.children[2]); // Hide categories div, has a click event + + // If the hide categories div is visible and it is clicked, + // hide the categories and display the show categories div + if(hideOptions.is(':visible')){ + showOptions.show(); + hideOptions.hide(); + filterOptions.animate({ height: 0 },500); - } - else { + } else { // The user clicked on the show categories div, then show the categories and the "hide categories div" showOptions.hide(); hideOptions.show(); + filterOptions.animate({ height: filterHeight },500); } } - function setEvents(){ - // Fade css - $('.software-block-finality').css({'opacity':0, 'top':0}); - // End Fade CSS - var software_block = $('.software-block'); - software_block.mouseover(show_finality); - software_block.mouseout(hide_finality); - - var showOptions = $("#filter-option-catalog-software"); - var hideOptions = $("#filter-option-catalog-close"); - showOptions.click(toggleFilterOptions); - hideOptions.click(toggleFilterOptions); - } - - /* Finds all uploaded files from manuals page and sets its names on the right format */ - function set_uploaded_files_names() { - try { - var article = document.getElementById('article'); - var folderList = article.getElementsByClassName('folder-content')[0]; - var folderItens = folderList.getElementsByClassName('item-description'); - - for(var i = 0, var loop_length = folderItens.length; i < loop_length; i++) { - split_file_extension(folderItens[i].getElementsByTagName('a')[0]); - } - } catch(e) { + // If there is a software catalog on the page, add its category filter toggle animation + function initialize() { + var filter = document.getElementById('filter-catalog-software'); + if (filter) { + //toggle filter options in catalog page + filter.children[0].setAttribute('class', 'animated slideInDown'); + $(filter.children[1]).click(toggleFilterOptions); + $(filter.children[2]).click(toggleFilterOptions); } } + return { + init: initialize + }; +}) (jQuery); + +SPBNoosferoTheme.NoosferoFoldersContent = (function($) { + 'use strict'; + /* Splits a file name from its extension. Example: example.pdf becomes example - PDF */ function split_file_extension(element) { var tokens = element.innerHTML.split('.'); - if(tokens.length == 2) { - var fileName = tokens[0]; - var fileExtension = tokens[1].toUpperCase(); - element.innerHTML = fileName + " - " + fileExtension; - } - } - - function set_tooltip_content() { - $('.star-tooltip').html("?"); - } - function set_arrow_direction() { - var additional_data_bar = $('.comments-display-fields'); - - additional_data_bar.on('click', function() { - var arrow = additional_data_bar.find('span[class*="comments-arrow"]'); - var additional_fields = $('.comments-software-extra-fields'); - - if (additional_fields) { - animateExtraFields(additional_fields, arrow); - } - }); - } - - - function animateExtraFields(additional_fields, arrow) { - var innerHeight = additional_fields[0].offsetHeight; - - if(additional_fields.height() !== 0) { - arrow.attr('class', "comments-arrow-down"); - additional_fields.animate({height: 0}); - } else { - arrow.attr('class', "comments-arrow-up"); - additional_fields.animate({height: additional_fields.get(0).scrollHeight}, 1000 ); + if(tokens.length > 1) { + var fileExtension = tokens.pop().toUpperCase(); + var fileName = tokens.join('.'); + element.innerHTML = fileName + ' - ' + fileExtension; } - - // Fix for the arrow change on modal display to block, killing the entire page - $("#institution_modal").css({'display':'none'}); - } - - - function set_use_report_content() { - $('.profile-homepage .organization-average-rating-container .rate-this-organization a').html('Avalie este software'); - $('.make-report-block .make-report-container .button-bar a span').html('Avalie este software'); - $('.star-rate-data .star-rate-form.rating-cooldown .button-bar a span').html('Avalie este software'); - $('.make-report-block .make-report-container .make-report-message').html('Relate sua experiência ou do órgão/empresa com relação ao software.'); - $('.ratings-list .see-more a.icon-arrow-right-p').html('veja todos os relatos'); - $('.main-content .star-rate-data .star-rate-form .star-comment-container .button-bar input').attr('value', 'Enviar'); - $('.main-content .star-rate-data .star-rate-form .star-rate-text').html('Avalie este software'); - $('.main-content .star-rate-data .star-rate-form .star-comment-container .formlabel').html('Depoimento sobre o software'); - $('.star-rate-form .star-comment-container .comments-display-fields span#comments-additional-information').html('Dados adicionais (órgãos e empresas)'); - $('.star-rate-form .star-comment-container .comments-software-extra-fields #input_institution_comments label').html('Nome do órgão ou empresa'); - $('.star-rate-form .star-comment-container .comments-software-extra-fields .comments-software-people-benefited label').html('Número de beneficiados'); - $('.star-rate-form .star-comment-container .comments-software-extra-fields .comments-software-saved-values label').html('Recursos economizados'); } - function add_tooltips(){ - $('#content span[title]').attr("data-toggle","tooltip"); + /* Finds all uploaded files from manuals page and sets its names on the right format */ + function set_uploaded_files_names() { + try { + var article = document.getElementById('article'); + var folderList = article.getElementsByClassName('folder-content')[0]; + var folderItens = folderList.getElementsByClassName('item-description'); - $('[data-toggle="tooltip"]').tooltip(); - } + for(var i = 0, loop_length = folderItens.length; i < loop_length; i++) { + split_file_extension(folderItens[i].getElementsByTagName('a')[0]); + } + } catch(e) { - function add_popovers() { - var span = $('span[data-toggle="popover"]'); - var place = span.attr("data-placement"); - var elementClass = span.attr("data-class"); - if(span){ - var popover = span.popover({ - html:true, - placement: place, - content: function() { - return $(this).next().html(); - } - }) - .data('bs.popover'); } - if(popover) { - popover.tip() - .addClass(elementClass); - $('a.toggle-popover').on("click",function() { - span.trigger("click"); - }); - } - } - - function move_breadcrumbs() { - $('.breadcrumbs-plugin_content-breadcrumbs-block').prependTo('#wrap-2'); - $(' ').insertBefore($('.breadcrumbs-plugin_content-breadcrumbs-block .block-inner-2').children().first()); } - // temporary solution for the suspension_point in some buttons - function remove_suspension_points_in_buttons() { - $(".template-kind a span:contains('...')").each(function(index, element) { - element.innerHTML = element.innerHTML.replace(/(\...)/, ""); - }); - } - - // temporary solution for the text in send_email buttons - function replace_send_email_button_text() { - $('.action-profile-members .page-members-header .icon-menu-mail').html('Contatar administradores'); + function initialize() { + set_uploaded_files_names(); } - $(document).ready(function(){ - add_tooltips(); - add_popovers(); - move_article_buttons(); - move_breadcrumbs(); - insert_notice_div(); - set_uploaded_files_names(); - set_tooltip_content(); - set_arrow_direction(); - set_use_report_content(); - setEvents(); - remove_suspension_points_in_buttons(); - replace_send_email_button_text(); - }); -})(jQuery); + return { + init: initialize + }; + +}) (jQuery); + +// Theme javascript bootstrap +(function(jQuery) { + 'use strict'; + + // Initialize everything + $(document).ready(function() { + SPBNoosferoTheme.OrganizationRatings.init(); + SPBNoosferoTheme.HighlightedSoftwaresBlock.init(); + SPBNoosferoTheme.NoosferoHTMLAdjusts.init(); + SPBNoosferoTheme.SoftwareCatalog.init(); + SPBNoosferoTheme.NoosferoFoldersContent.init(); + }); +}) (jQuery); -- libgit2 0.21.2