theme.js
9.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* globals jQuery */
// Theme namespace
var SPBNoosferoTheme = {};
// 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('?');
}
// 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 );
}
// 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';
}
// 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);
}
function initialize() {
$('div.star-rate-form').doOnce(function() {
setTooltipContent();
setArrowDirection();
});
}
return {
init: initialize
};
}) (jQuery);
// Fade effect on software blocks of portal homepage
SPBNoosferoTheme.HighlightedSoftwaresBlock = (function($) {
'use strict';
function showFinality() {
var finality = $(this).children('div.software-block-finality');
finality.stop().fadeTo('fast', 1);
}
function hideFinality() {
var finality = $(this).children('div.software-block-finality');
finality.stop().fadeTo('fast', 0);
}
// 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');
softwaresBlocks.mouseover(showFinality);
softwaresBlocks.mouseout(hideFinality);
}
function initialize() {
$('#boxes .box-1 div.softwares-block').doOnce(function() {
setFadeInOutFinality();
});
}
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 = $('<a></a>');
leadLink.attr('href', link);
leadLink.text(lead.find('p').text());
lead.html(leadLink);
//add wraps to improve styling
$(this).find('div:gt(0)').wrapAll('<div class="notice-item"/>');
$(this).find('.notice-item div:gt(0)').wrapAll('<div class="notice-info"/>');
});
parent.append(news);
}
// 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();
}
})
.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');
$('<span id="breadcrumbs-you-are-here">Você está aqui:</span>').insertBefore(this.find('div.block-inner-2').children().first());
});
}
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 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 { // 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);
}
}
// 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 > 1) {
var fileExtension = tokens.pop().toUpperCase();
var fileName = tokens.join('.');
element.innerHTML = fileName + ' - ' + fileExtension;
}
}
/* 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, loop_length = folderItens.length; i < loop_length; i++) {
split_file_extension(folderItens[i].getElementsByTagName('a')[0]);
}
} catch(e) {
}
}
function initialize() {
set_uploaded_files_names();
}
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);