Commit 17f979a551d45521631a6c8de68f4938c03492cf

Authored by Evandro Junior
1 parent 93a2aad6

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