Commit 17f979a551d45521631a6c8de68f4938c03492cf
1 parent
93a2aad6
Exists in
master
and in
10 other branches
removed spaces at the end of lines
Showing
1 changed file
with
100 additions
and
100 deletions
Show diff stats
js/main.js
@@ -3,20 +3,20 @@ define(['handlebars'], function(Handlebars){ | @@ -3,20 +3,20 @@ define(['handlebars'], function(Handlebars){ | ||
3 | /* global Handlebars, $ */ | 3 | /* global Handlebars, $ */ |
4 | // The template code | 4 | // The template code |
5 | var templateSource = document.getElementById('proposal-template').innerHTML; | 5 | var templateSource = document.getElementById('proposal-template').innerHTML; |
6 | - | 6 | + |
7 | // compile the template | 7 | // compile the template |
8 | var template = Handlebars.compile(templateSource); | 8 | var template = Handlebars.compile(templateSource); |
9 | var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); | 9 | var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); |
10 | var loginTemplate = Handlebars.compile(document.getElementById('login').innerHTML); | 10 | var loginTemplate = Handlebars.compile(document.getElementById('login').innerHTML); |
11 | var resultsTemplate = Handlebars.compile(document.getElementById('results').innerHTML); | 11 | var resultsTemplate = Handlebars.compile(document.getElementById('results').innerHTML); |
12 | - | 12 | + |
13 | // The div/container that we are going to display the results in | 13 | // The div/container that we are going to display the results in |
14 | var resultsPlaceholder = document.getElementById('proposal-result'); | 14 | var resultsPlaceholder = document.getElementById('proposal-result'); |
15 | - | 15 | + |
16 | var logged_in = false; | 16 | var logged_in = false; |
17 | - | 17 | + |
18 | var loginButton; | 18 | var loginButton; |
19 | - | 19 | + |
20 | var participa = true; | 20 | var participa = true; |
21 | if(participa){ | 21 | if(participa){ |
22 | var host = 'http://www.participa.br'; | 22 | var host = 'http://www.participa.br'; |
@@ -29,10 +29,10 @@ define(['handlebars'], function(Handlebars){ | @@ -29,10 +29,10 @@ define(['handlebars'], function(Handlebars){ | ||
29 | var proposal_discussion = '632'; //local serpro | 29 | var proposal_discussion = '632'; //local serpro |
30 | //var proposal_discussion = '401'; //casa | 30 | //var proposal_discussion = '401'; //casa |
31 | } | 31 | } |
32 | - | 32 | + |
33 | // Load data from localhost when it is dev env. | 33 | // Load data from localhost when it is dev env. |
34 | var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + private_token + '&fields=id,children,categories,abstract,body,title,image,url'; | 34 | var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + private_token + '&fields=id,children,categories,abstract,body,title,image,url'; |
35 | - | 35 | + |
36 | $.getJSON(noosferoAPI) | 36 | $.getJSON(noosferoAPI) |
37 | .done(function( data ) { | 37 | .done(function( data ) { |
38 | data.host = host; | 38 | data.host = host; |
@@ -40,66 +40,66 @@ define(['handlebars'], function(Handlebars){ | @@ -40,66 +40,66 @@ define(['handlebars'], function(Handlebars){ | ||
40 | resultsPlaceholder.innerHTML = template(data); | 40 | resultsPlaceholder.innerHTML = template(data); |
41 | $('.login-container').html(loginTemplate()); | 41 | $('.login-container').html(loginTemplate()); |
42 | $('.countdown').maxlength({text: '%left caracteres restantes'}); | 42 | $('.countdown').maxlength({text: '%left caracteres restantes'}); |
43 | - | 43 | + |
44 | navigateTo(window.location.hash); | 44 | navigateTo(window.location.hash); |
45 | - | 45 | + |
46 | //Actions for links | 46 | //Actions for links |
47 | $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ | 47 | $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ |
48 | e.preventDefault(); | 48 | e.preventDefault(); |
49 | - | 49 | + |
50 | var $link = $(this); | 50 | var $link = $(this); |
51 | - | 51 | + |
52 | // Update URL and Navigate | 52 | // Update URL and Navigate |
53 | updateHash($link.attr('href')); | 53 | updateHash($link.attr('href')); |
54 | }); | 54 | }); |
55 | - | 55 | + |
56 | $( '#nav-proposal-group a' ).on('click touchstart', function(e){ | 56 | $( '#nav-proposal-group a' ).on('click touchstart', function(e){ |
57 | e.preventDefault(); | 57 | e.preventDefault(); |
58 | - | 58 | + |
59 | var $link = $(this); | 59 | var $link = $(this); |
60 | - | 60 | + |
61 | // Update URL and Navigate | 61 | // Update URL and Navigate |
62 | updateHash($link.attr('href')); | 62 | updateHash($link.attr('href')); |
63 | }); | 63 | }); |
64 | - | 64 | + |
65 | $( '.proposal-item a' ).on('click touchstart', function(e){ | 65 | $( '.proposal-item a' ).on('click touchstart', function(e){ |
66 | e.preventDefault(); | 66 | e.preventDefault(); |
67 | - | 67 | + |
68 | var $link = $(this); | 68 | var $link = $(this); |
69 | - | 69 | + |
70 | // Update URL and Navigate | 70 | // Update URL and Navigate |
71 | updateHash($link.attr('href')); | 71 | updateHash($link.attr('href')); |
72 | }); | 72 | }); |
73 | - | 73 | + |
74 | $( '.proposal-category a' ).on('click touchstart', function(e){ | 74 | $( '.proposal-category a' ).on('click touchstart', function(e){ |
75 | e.preventDefault(); | 75 | e.preventDefault(); |
76 | - | 76 | + |
77 | var $link = $(this); | 77 | var $link = $(this); |
78 | - | 78 | + |
79 | // Update URL and Navigate | 79 | // Update URL and Navigate |
80 | updateHash($link.attr('href')); | 80 | updateHash($link.attr('href')); |
81 | }); | 81 | }); |
82 | - | 82 | + |
83 | $( '.proposal-category .go-back' ).on('click touchstart', function(e){ | 83 | $( '.proposal-category .go-back' ).on('click touchstart', function(e){ |
84 | e.preventDefault(); | 84 | e.preventDefault(); |
85 | - | 85 | + |
86 | var oldHash = window.location.hash; | 86 | var oldHash = window.location.hash; |
87 | var regexSubpages = /sobre-o-programa$/; | 87 | var regexSubpages = /sobre-o-programa$/; |
88 | var isSubpage = regexSubpages.exec(oldHash) !== null; | 88 | var isSubpage = regexSubpages.exec(oldHash) !== null; |
89 | var newHash = '#/temas'; // default page | 89 | var newHash = '#/temas'; // default page |
90 | - | 90 | + |
91 | if(isSubpage){ | 91 | if(isSubpage){ |
92 | // return to proposal page | 92 | // return to proposal page |
93 | newHash = oldHash.split('/sobre-o-programa')[0]; | 93 | newHash = oldHash.split('/sobre-o-programa')[0]; |
94 | } | 94 | } |
95 | - | 95 | + |
96 | // Update URL and Navigate | 96 | // Update URL and Navigate |
97 | updateHash(newHash); | 97 | updateHash(newHash); |
98 | }); | 98 | }); |
99 | - | 99 | + |
100 | $( '.send-button a' ).on('click touchstart', function(e){ | 100 | $( '.send-button a' ).on('click touchstart', function(e){ |
101 | e.preventDefault(); | 101 | e.preventDefault(); |
102 | - | 102 | + |
103 | //display form to send proposal (or login form for non-logged users) | 103 | //display form to send proposal (or login form for non-logged users) |
104 | var $this = $(this); | 104 | var $this = $(this); |
105 | loginButton = $this.parents('.send-button'); | 105 | loginButton = $this.parents('.send-button'); |
@@ -107,41 +107,41 @@ define(['handlebars'], function(Handlebars){ | @@ -107,41 +107,41 @@ define(['handlebars'], function(Handlebars){ | ||
107 | $this.parents('.success-proposal-sent').hide(); | 107 | $this.parents('.success-proposal-sent').hide(); |
108 | loginCallback(logged_in); | 108 | loginCallback(logged_in); |
109 | }); | 109 | }); |
110 | - | 110 | + |
111 | $( '#display-contrast' ).on('click touchstart', function(e){ | 111 | $( '#display-contrast' ).on('click touchstart', function(e){ |
112 | e.preventDefault(); | 112 | e.preventDefault(); |
113 | $('#proposal-result').toggleClass('contrast'); | 113 | $('#proposal-result').toggleClass('contrast'); |
114 | }); | 114 | }); |
115 | - | 115 | + |
116 | $( '.show_body a' ).on('click touchstart', function(e){ | 116 | $( '.show_body a' ).on('click touchstart', function(e){ |
117 | e.preventDefault(); | 117 | e.preventDefault(); |
118 | - | 118 | + |
119 | var $link = $(this); | 119 | var $link = $(this); |
120 | - | 120 | + |
121 | // Update URL and Navigate | 121 | // Update URL and Navigate |
122 | updateHash($link.attr('href')); | 122 | updateHash($link.attr('href')); |
123 | }); | 123 | }); |
124 | - | 124 | + |
125 | $( '.go-to-proposal-button a' ).on('click touchstart', function(e){ | 125 | $( '.go-to-proposal-button a' ).on('click touchstart', function(e){ |
126 | e.preventDefault(); | 126 | e.preventDefault(); |
127 | - | 127 | + |
128 | var $link = $(this); | 128 | var $link = $(this); |
129 | - | 129 | + |
130 | // Update URL and Navigate | 130 | // Update URL and Navigate |
131 | updateHash($link.attr('href')); | 131 | updateHash($link.attr('href')); |
132 | }); | 132 | }); |
133 | - | 133 | + |
134 | $( '.proposal-selection' ).change(function(e){ | 134 | $( '.proposal-selection' ).change(function(e){ |
135 | e.preventDefault(); | 135 | e.preventDefault(); |
136 | - | 136 | + |
137 | display_proposal('proposal-item-' + this.value); | 137 | display_proposal('proposal-item-' + this.value); |
138 | }); | 138 | }); |
139 | - | 139 | + |
140 | var availableTags = [ ]; | 140 | var availableTags = [ ]; |
141 | $('#proposal-group li a').each(function(){ | 141 | $('#proposal-group li a').each(function(){ |
142 | availableTags.push({ label: $(this).text(), value: $(this).attr('href')}); | 142 | availableTags.push({ label: $(this).text(), value: $(this).attr('href')}); |
143 | }); | 143 | }); |
144 | - | 144 | + |
145 | $( '#search-input' ).autocomplete({ | 145 | $( '#search-input' ).autocomplete({ |
146 | source: availableTags, | 146 | source: availableTags, |
147 | minLength: 3, | 147 | minLength: 3, |
@@ -155,8 +155,8 @@ define(['handlebars'], function(Handlebars){ | @@ -155,8 +155,8 @@ define(['handlebars'], function(Handlebars){ | ||
155 | results: function() {} | 155 | results: function() {} |
156 | } | 156 | } |
157 | }); | 157 | }); |
158 | - | ||
159 | - | 158 | + |
159 | + | ||
160 | $('.save-article-form').submit(function (e) { | 160 | $('.save-article-form').submit(function (e) { |
161 | e.preventDefault(); | 161 | e.preventDefault(); |
162 | var proposal_id = this.id.split('-').pop(); | 162 | var proposal_id = this.id.split('-').pop(); |
@@ -182,33 +182,33 @@ define(['handlebars'], function(Handlebars){ | @@ -182,33 +182,33 @@ define(['handlebars'], function(Handlebars){ | ||
182 | message.text('Não foi possível enviar.'); | 182 | message.text('Não foi possível enviar.'); |
183 | }); | 183 | }); |
184 | }); | 184 | }); |
185 | - | 185 | + |
186 | }) | 186 | }) |
187 | .fail(function( jqxhr, textStatus, error ) { | 187 | .fail(function( jqxhr, textStatus, error ) { |
188 | var err = textStatus + ', ' + error; | 188 | var err = textStatus + ', ' + error; |
189 | console.log( 'Request Failed: ' + err ); | 189 | console.log( 'Request Failed: ' + err ); |
190 | }); | 190 | }); |
191 | - | 191 | + |
192 | function loadRandomProposal(topic_id, private_token) { | 192 | function loadRandomProposal(topic_id, private_token) { |
193 | var $noProposals = $('.no-proposals'); | 193 | var $noProposals = $('.no-proposals'); |
194 | var $loading = $('.loading'); | 194 | var $loading = $('.loading'); |
195 | var $randomProposal = $('.random-proposal'); | 195 | var $randomProposal = $('.random-proposal'); |
196 | var $body = $(document.body); | 196 | var $body = $(document.body); |
197 | - | 197 | + |
198 | // reset view | 198 | // reset view |
199 | $noProposals.hide(); | 199 | $noProposals.hide(); |
200 | $loading.show(); | 200 | $loading.show(); |
201 | $randomProposal.html(''); | 201 | $randomProposal.html(''); |
202 | - | 202 | + |
203 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | 203 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; |
204 | $.getJSON(url).done(function( data ) { | 204 | $.getJSON(url).done(function( data ) { |
205 | $loading.hide(); | 205 | $loading.hide(); |
206 | - | 206 | + |
207 | if(data.articles.length === 0) { | 207 | if(data.articles.length === 0) { |
208 | $noProposals.show(); | 208 | $noProposals.show(); |
209 | return; | 209 | return; |
210 | } | 210 | } |
211 | - | 211 | + |
212 | var article = data.articles[0]; | 212 | var article = data.articles[0]; |
213 | $randomProposal.html(supportProposalTemplate(article)); | 213 | $randomProposal.html(supportProposalTemplate(article)); |
214 | $body.off('click', '.vote-actions .skip'); | 214 | $body.off('click', '.vote-actions .skip'); |
@@ -230,30 +230,30 @@ define(['handlebars'], function(Handlebars){ | @@ -230,30 +230,30 @@ define(['handlebars'], function(Handlebars){ | ||
230 | }); | 230 | }); |
231 | e.preventDefault(); | 231 | e.preventDefault(); |
232 | }); | 232 | }); |
233 | - | 233 | + |
234 | $body.off('click', '.vote-result'); | 234 | $body.off('click', '.vote-result'); |
235 | $body.on('click', '.vote-result', function(e) { | 235 | $body.on('click', '.vote-result', function(e) { |
236 | - | 236 | + |
237 | var $this = $(this); | 237 | var $this = $(this); |
238 | var $proposalDetail = $this.parents('.proposal-detail'); | 238 | var $proposalDetail = $this.parents('.proposal-detail'); |
239 | var $resultsContainer = $proposalDetail.find('.results-container'); | 239 | var $resultsContainer = $proposalDetail.find('.results-container'); |
240 | - | 240 | + |
241 | // $resultsContainer.toggle(); | 241 | // $resultsContainer.toggle(); |
242 | // $resultsContainer.toggleClass('hide'); | 242 | // $resultsContainer.toggleClass('hide'); |
243 | - | 243 | + |
244 | if($resultsContainer.css('display') === 'none') { | 244 | if($resultsContainer.css('display') === 'none') { |
245 | - | 245 | + |
246 | $resultsContainer.find('.loading').show(); | 246 | $resultsContainer.find('.loading').show(); |
247 | $resultsContainer.find('.results-content').hide(); | 247 | $resultsContainer.find('.results-content').hide(); |
248 | - | 248 | + |
249 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=10&order=votes_score&fields=id,name,abstract,votes_for,votes_against&content_type=ProposalsDiscussionPlugin::Proposal'; | 249 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=10&order=votes_score&fields=id,name,abstract,votes_for,votes_against&content_type=ProposalsDiscussionPlugin::Proposal'; |
250 | $.getJSON(url).done(function( data ) { | 250 | $.getJSON(url).done(function( data ) { |
251 | - | 251 | + |
252 | $resultsContainer.html(resultsTemplate(data)); | 252 | $resultsContainer.html(resultsTemplate(data)); |
253 | $resultsContainer.find('.loading').hide(); | 253 | $resultsContainer.find('.loading').hide(); |
254 | $resultsContainer.find('.results-content').show(); | 254 | $resultsContainer.find('.results-content').show(); |
255 | $resultsContainer.show(); | 255 | $resultsContainer.show(); |
256 | - | 256 | + |
257 | // scroll to the end | 257 | // scroll to the end |
258 | $('html, body').animate({ | 258 | $('html, body').animate({ |
259 | scrollTop: $(document).height() | 259 | scrollTop: $(document).height() |
@@ -266,12 +266,12 @@ define(['handlebars'], function(Handlebars){ | @@ -266,12 +266,12 @@ define(['handlebars'], function(Handlebars){ | ||
266 | $('.talk-proposal-container').show(); | 266 | $('.talk-proposal-container').show(); |
267 | $resultsContainer.hide(); | 267 | $resultsContainer.hide(); |
268 | } | 268 | } |
269 | - | 269 | + |
270 | e.preventDefault(); | 270 | e.preventDefault(); |
271 | }); | 271 | }); |
272 | }); | 272 | }); |
273 | } | 273 | } |
274 | - | 274 | + |
275 | $(document).ready(function($) { | 275 | $(document).ready(function($) { |
276 | if($.cookie('_dialoga_session')) { | 276 | if($.cookie('_dialoga_session')) { |
277 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); | 277 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); |
@@ -280,7 +280,7 @@ define(['handlebars'], function(Handlebars){ | @@ -280,7 +280,7 @@ define(['handlebars'], function(Handlebars){ | ||
280 | private_token = $.cookie('_dialoga_session'); | 280 | private_token = $.cookie('_dialoga_session'); |
281 | }); | 281 | }); |
282 | } | 282 | } |
283 | - | 283 | + |
284 | $(document).on('click', '.login-action', function(e) { | 284 | $(document).on('click', '.login-action', function(e) { |
285 | var message = $('.login .message'); | 285 | var message = $('.login .message'); |
286 | message.hide(); | 286 | message.hide(); |
@@ -301,11 +301,11 @@ define(['handlebars'], function(Handlebars){ | @@ -301,11 +301,11 @@ define(['handlebars'], function(Handlebars){ | ||
301 | e.preventDefault(); | 301 | e.preventDefault(); |
302 | }); | 302 | }); |
303 | }); | 303 | }); |
304 | - | 304 | + |
305 | function loginCallback(loggedIn, token) { | 305 | function loginCallback(loggedIn, token) { |
306 | logged_in = loggedIn; | 306 | logged_in = loggedIn; |
307 | $('.login .message').text(''); | 307 | $('.login .message').text(''); |
308 | - | 308 | + |
309 | if(logged_in) { | 309 | if(logged_in) { |
310 | if(token){ | 310 | if(token){ |
311 | private_token = token; | 311 | private_token = token; |
@@ -323,7 +323,7 @@ define(['handlebars'], function(Handlebars){ | @@ -323,7 +323,7 @@ define(['handlebars'], function(Handlebars){ | ||
323 | function oauthPluginHandleLoginResult(loggedIn, token) { | 323 | function oauthPluginHandleLoginResult(loggedIn, token) { |
324 | loginCallback(loggedIn, token); | 324 | loginCallback(loggedIn, token); |
325 | } | 325 | } |
326 | - | 326 | + |
327 | function guid() { | 327 | function guid() { |
328 | function s4() { | 328 | function s4() { |
329 | return Math.floor((1 + Math.random()) * 0x10000) | 329 | return Math.floor((1 + Math.random()) * 0x10000) |
@@ -331,7 +331,7 @@ define(['handlebars'], function(Handlebars){ | @@ -331,7 +331,7 @@ define(['handlebars'], function(Handlebars){ | ||
331 | .substring(1); | 331 | .substring(1); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | - | 334 | + |
335 | function display_category_tab(){ | 335 | function display_category_tab(){ |
336 | $('#proposal-group').hide(); | 336 | $('#proposal-group').hide(); |
337 | $('#proposal-categories').show(); | 337 | $('#proposal-categories').show(); |
@@ -340,22 +340,22 @@ define(['handlebars'], function(Handlebars){ | @@ -340,22 +340,22 @@ define(['handlebars'], function(Handlebars){ | ||
340 | $('.proposal-category-items').hide(); | 340 | $('.proposal-category-items').hide(); |
341 | $('.proposal-category .arrow-box').hide(); | 341 | $('.proposal-category .arrow-box').hide(); |
342 | $('.proposal-detail').hide(); | 342 | $('.proposal-detail').hide(); |
343 | - | 343 | + |
344 | $('#content').show(); | 344 | $('#content').show(); |
345 | $('nav').show(); | 345 | $('nav').show(); |
346 | } | 346 | } |
347 | - | 347 | + |
348 | function display_proposals_tab(){ | 348 | function display_proposals_tab(){ |
349 | $('#proposal-categories').hide(); | 349 | $('#proposal-categories').hide(); |
350 | $('#proposal-group').show(); | 350 | $('#proposal-group').show(); |
351 | $('#nav-proposal-group a').addClass('active'); | 351 | $('#nav-proposal-group a').addClass('active'); |
352 | $('#nav-proposal-categories a').removeClass('active'); | 352 | $('#nav-proposal-categories a').removeClass('active'); |
353 | $('.proposal-item p').dotdotdot(); | 353 | $('.proposal-item p').dotdotdot(); |
354 | - | 354 | + |
355 | $('#content').show(); | 355 | $('#content').show(); |
356 | $('nav').show(); | 356 | $('nav').show(); |
357 | } | 357 | } |
358 | - | 358 | + |
359 | function display_proposal(proposal_id){ | 359 | function display_proposal(proposal_id){ |
360 | $('#proposal-categories').hide(); | 360 | $('#proposal-categories').hide(); |
361 | $('#proposal-group').hide(); | 361 | $('#proposal-group').hide(); |
@@ -364,7 +364,7 @@ define(['handlebars'], function(Handlebars){ | @@ -364,7 +364,7 @@ define(['handlebars'], function(Handlebars){ | ||
364 | $('.make-proposal-form').hide(); | 364 | $('.make-proposal-form').hide(); |
365 | $('.login-container').hide(); | 365 | $('.login-container').hide(); |
366 | $('.proposal-detail').hide(); | 366 | $('.proposal-detail').hide(); |
367 | - | 367 | + |
368 | $('.proposal-detail-base').hide(); | 368 | $('.proposal-detail-base').hide(); |
369 | $('#' + proposal_id).show(); | 369 | $('#' + proposal_id).show(); |
370 | $('.proposal-header').show(); | 370 | $('.proposal-header').show(); |
@@ -375,11 +375,11 @@ define(['handlebars'], function(Handlebars){ | @@ -375,11 +375,11 @@ define(['handlebars'], function(Handlebars){ | ||
375 | $('.results-container .results-content').hide(); | 375 | $('.results-container .results-content').hide(); |
376 | $('.experience-proposal-container').show(); | 376 | $('.experience-proposal-container').show(); |
377 | $('.talk-proposal-container').show(); | 377 | $('.talk-proposal-container').show(); |
378 | - | 378 | + |
379 | var topic_id = proposal_id.split('-').pop(); | 379 | var topic_id = proposal_id.split('-').pop(); |
380 | loadRandomProposal(topic_id, private_token); | 380 | loadRandomProposal(topic_id, private_token); |
381 | } | 381 | } |
382 | - | 382 | + |
383 | function display_proposal_detail(){ | 383 | function display_proposal_detail(){ |
384 | $('#proposal-categories').hide(); | 384 | $('#proposal-categories').hide(); |
385 | $('#proposal-group').hide(); | 385 | $('#proposal-group').hide(); |
@@ -392,13 +392,13 @@ define(['handlebars'], function(Handlebars){ | @@ -392,13 +392,13 @@ define(['handlebars'], function(Handlebars){ | ||
392 | $('.results-container').hide(); | 392 | $('.results-container').hide(); |
393 | $('.experience-proposal-container').hide(); | 393 | $('.experience-proposal-container').hide(); |
394 | $('.talk-proposal-container').hide(); | 394 | $('.talk-proposal-container').hide(); |
395 | - | 395 | + |
396 | $('.body').show(); | 396 | $('.body').show(); |
397 | } | 397 | } |
398 | - | 398 | + |
399 | function display_proposal_by_category(item){ | 399 | function display_proposal_by_category(item){ |
400 | var $item = $('#' + item); | 400 | var $item = $('#' + item); |
401 | - | 401 | + |
402 | if($item.hasClass('proposal-category-items')){ | 402 | if($item.hasClass('proposal-category-items')){ |
403 | //Display Topics or Discussion by category | 403 | //Display Topics or Discussion by category |
404 | $('nav').show(); | 404 | $('nav').show(); |
@@ -415,13 +415,13 @@ define(['handlebars'], function(Handlebars){ | @@ -415,13 +415,13 @@ define(['handlebars'], function(Handlebars){ | ||
415 | $('#proposal-category-' + categorySlug).find('.arrow-box').show(); | 415 | $('#proposal-category-' + categorySlug).find('.arrow-box').show(); |
416 | } | 416 | } |
417 | } | 417 | } |
418 | - | 418 | + |
419 | var BARRA_ADDED = false; | 419 | var BARRA_ADDED = false; |
420 | function addBarraDoGoverno(){ | 420 | function addBarraDoGoverno(){ |
421 | console.log('add barra'); | 421 | console.log('add barra'); |
422 | - | 422 | + |
423 | if( BARRA_ADDED ) { return; } | 423 | if( BARRA_ADDED ) { return; } |
424 | - | 424 | + |
425 | var HTML_BODY_PREPEND = '' + | 425 | var HTML_BODY_PREPEND = '' + |
426 | '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + | 426 | '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + |
427 | '<ul id="menu-barra-temp" style="list-style:none;">' + | 427 | '<ul id="menu-barra-temp" style="list-style:none;">' + |
@@ -429,11 +429,11 @@ define(['handlebars'], function(Handlebars){ | @@ -429,11 +429,11 @@ define(['handlebars'], function(Handlebars){ | ||
429 | '<li><a style="font-family:sans,sans-serif; text-decoration:none; color:white;" href="http://epwg.governoeletronico.gov.br/barra/atualize.html">Atualize sua Barra de Governo</a></li>' + | 429 | '<li><a style="font-family:sans,sans-serif; text-decoration:none; color:white;" href="http://epwg.governoeletronico.gov.br/barra/atualize.html">Atualize sua Barra de Governo</a></li>' + |
430 | '</ul>' + | 430 | '</ul>' + |
431 | '</div>'; | 431 | '</div>'; |
432 | - | 432 | + |
433 | var HTML_BODY_APPEND = ''+ | 433 | var HTML_BODY_APPEND = ''+ |
434 | '<div id="footer-brasil"></div>' + | 434 | '<div id="footer-brasil"></div>' + |
435 | '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; | 435 | '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; |
436 | - | 436 | + |
437 | var STYLE_TEMA_AZUL = '' + | 437 | var STYLE_TEMA_AZUL = '' + |
438 | '<style>'+ | 438 | '<style>'+ |
439 | '#footer-brasil {'+ | 439 | '#footer-brasil {'+ |
@@ -446,88 +446,88 @@ define(['handlebars'], function(Handlebars){ | @@ -446,88 +446,88 @@ define(['handlebars'], function(Handlebars){ | ||
446 | 'width: auto;'+ | 446 | 'width: auto;'+ |
447 | '}'+ | 447 | '}'+ |
448 | '<style>'; | 448 | '<style>'; |
449 | - | 449 | + |
450 | var $body = $(document.body); | 450 | var $body = $(document.body); |
451 | $body.prepend(HTML_BODY_PREPEND); | 451 | $body.prepend(HTML_BODY_PREPEND); |
452 | $body.append(HTML_BODY_APPEND); | 452 | $body.append(HTML_BODY_APPEND); |
453 | $body.append(STYLE_TEMA_AZUL); | 453 | $body.append(STYLE_TEMA_AZUL); |
454 | - | 454 | + |
455 | BARRA_ADDED = true; | 455 | BARRA_ADDED = true; |
456 | } | 456 | } |
457 | - | 457 | + |
458 | function updateHash(hash){ | 458 | function updateHash(hash){ |
459 | var id = hash.replace(/^.*#/, ''); | 459 | var id = hash.replace(/^.*#/, ''); |
460 | var elem = document.getElementById(id); | 460 | var elem = document.getElementById(id); |
461 | - | 461 | + |
462 | // preserve the query param | 462 | // preserve the query param |
463 | // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ | 463 | // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ |
464 | // hash += '?barra=false'; | 464 | // hash += '?barra=false'; |
465 | // } | 465 | // } |
466 | - | 466 | + |
467 | if ( !elem ) { | 467 | if ( !elem ) { |
468 | window.location.hash = hash; | 468 | window.location.hash = hash; |
469 | return; | 469 | return; |
470 | } | 470 | } |
471 | - | 471 | + |
472 | elem.id = id+'-tmp'; | 472 | elem.id = id+'-tmp'; |
473 | window.location.hash = hash; | 473 | window.location.hash = hash; |
474 | elem.id = id; | 474 | elem.id = id; |
475 | } | 475 | } |
476 | - | 476 | + |
477 | function locationHashChanged(){ | 477 | function locationHashChanged(){ |
478 | var hash = window.location.hash; | 478 | var hash = window.location.hash; |
479 | navigateTo(hash); | 479 | navigateTo(hash); |
480 | } | 480 | } |
481 | - | 481 | + |
482 | var HIDE_BARRA_DO_GOVERNO = false; | 482 | var HIDE_BARRA_DO_GOVERNO = false; |
483 | function navigateTo(hash){ | 483 | function navigateTo(hash){ |
484 | var regexProposals = /#\/programas/; | 484 | var regexProposals = /#\/programas/; |
485 | var regexCategory = /#\/temas/; | 485 | var regexCategory = /#\/temas/; |
486 | var regexHideBarra = /barra=false$/; | 486 | var regexHideBarra = /barra=false$/; |
487 | - | 487 | + |
488 | if( !(regexHideBarra.exec(hash) !== null) && !HIDE_BARRA_DO_GOVERNO ){ | 488 | if( !(regexHideBarra.exec(hash) !== null) && !HIDE_BARRA_DO_GOVERNO ){ |
489 | addBarraDoGoverno(); | 489 | addBarraDoGoverno(); |
490 | }else{ | 490 | }else{ |
491 | HIDE_BARRA_DO_GOVERNO = true; | 491 | HIDE_BARRA_DO_GOVERNO = true; |
492 | } | 492 | } |
493 | - | 493 | + |
494 | // remove query params | 494 | // remove query params |
495 | hash = hash.split('?')[0]; | 495 | hash = hash.split('?')[0]; |
496 | - | 496 | + |
497 | var parts = hash.split('/'); | 497 | var parts = hash.split('/'); |
498 | - | 498 | + |
499 | var isProposal = regexProposals.exec(hash) !== null; | 499 | var isProposal = regexProposals.exec(hash) !== null; |
500 | var isCategory = regexCategory.exec(hash) !== null; | 500 | var isCategory = regexCategory.exec(hash) !== null; |
501 | - | 501 | + |
502 | if( isProposal ){ | 502 | if( isProposal ){ |
503 | - | ||
504 | - // go to proposal | 503 | + |
504 | + // go to proposal | ||
505 | var proposalId = parts[2]; | 505 | var proposalId = parts[2]; |
506 | navigateToProposal(proposalId); | 506 | navigateToProposal(proposalId); |
507 | } | 507 | } |
508 | - | 508 | + |
509 | if( isCategory ){ | 509 | if( isCategory ){ |
510 | - | ||
511 | - // go to category | 510 | + |
511 | + // go to category | ||
512 | var categoryId = parts[3]; | 512 | var categoryId = parts[3]; |
513 | navigateToCategory(categoryId); | 513 | navigateToCategory(categoryId); |
514 | } | 514 | } |
515 | - | 515 | + |
516 | // default | 516 | // default |
517 | if( !isProposal && !isCategory ){ | 517 | if( !isProposal && !isCategory ){ |
518 | // show the 'index' -> category tab | 518 | // show the 'index' -> category tab |
519 | display_category_tab(); | 519 | display_category_tab(); |
520 | } | 520 | } |
521 | - | 521 | + |
522 | $('html, body').animate({ scrollTop: 0 }, 'fast'); | 522 | $('html, body').animate({ scrollTop: 0 }, 'fast'); |
523 | } | 523 | } |
524 | - | ||
525 | - function navigateToProposal(proposalId){ | 524 | + |
525 | + function navigateToProposal(proposalId){ | ||
526 | if(proposalId === undefined){ | 526 | if(proposalId === undefined){ |
527 | display_proposals_tab(); | 527 | display_proposals_tab(); |
528 | }else{ | 528 | }else{ |
529 | display_proposal('proposal-item-' + proposalId); | 529 | display_proposal('proposal-item-' + proposalId); |
530 | - | 530 | + |
531 | // show sub-page | 531 | // show sub-page |
532 | var regexSubpages = /sobre-o-programa$/; | 532 | var regexSubpages = /sobre-o-programa$/; |
533 | var m; | 533 | var m; |
@@ -536,7 +536,7 @@ define(['handlebars'], function(Handlebars){ | @@ -536,7 +536,7 @@ define(['handlebars'], function(Handlebars){ | ||
536 | } | 536 | } |
537 | } | 537 | } |
538 | } | 538 | } |
539 | - | 539 | + |
540 | function navigateToCategory(categoryId){ | 540 | function navigateToCategory(categoryId){ |
541 | if(categoryId === undefined){ | 541 | if(categoryId === undefined){ |
542 | display_category_tab(); | 542 | display_category_tab(); |
@@ -544,7 +544,7 @@ define(['handlebars'], function(Handlebars){ | @@ -544,7 +544,7 @@ define(['handlebars'], function(Handlebars){ | ||
544 | display_proposal_by_category('proposal-item-' + categoryId); | 544 | display_proposal_by_category('proposal-item-' + categoryId); |
545 | } | 545 | } |
546 | } | 546 | } |
547 | - | 547 | + |
548 | if('onhashchange' in window){ | 548 | if('onhashchange' in window){ |
549 | window.onhashchange = locationHashChanged; | 549 | window.onhashchange = locationHashChanged; |
550 | }else{ | 550 | }else{ |