Commit 9076194b91ae9ff560675f70dffcb7ee0cf4a85a
1 parent
caabb1a5
Exists in
master
and in
10 other branches
Resolve pequenos 'warnings' do jshint/jslint.
Showing
1 changed file
with
40 additions
and
45 deletions
Show diff stats
js/main.js
| 1 | +/* global Handlebars, $ */ | ||
| 1 | // The template code | 2 | // The template code |
| 2 | var templateSource = document.getElementById('proposal-template').innerHTML; | 3 | var templateSource = document.getElementById('proposal-template').innerHTML; |
| 3 | 4 | ||
| @@ -10,8 +11,6 @@ var resultsTemplate = Handlebars.compile(document.getElementById('results').inne | @@ -10,8 +11,6 @@ var resultsTemplate = Handlebars.compile(document.getElementById('results').inne | ||
| 10 | // The div/container that we are going to display the results in | 11 | // The div/container that we are going to display the results in |
| 11 | var resultsPlaceholder = document.getElementById('proposal-result'); | 12 | var resultsPlaceholder = document.getElementById('proposal-result'); |
| 12 | 13 | ||
| 13 | -var topics; | ||
| 14 | - | ||
| 15 | var logged_in = false; | 14 | var logged_in = false; |
| 16 | 15 | ||
| 17 | var loginButton; | 16 | var loginButton; |
| @@ -48,8 +47,8 @@ $.getJSON(noosferoAPI) | @@ -48,8 +47,8 @@ $.getJSON(noosferoAPI) | ||
| 48 | navigateTo(window.location.hash); | 47 | navigateTo(window.location.hash); |
| 49 | 48 | ||
| 50 | //Actions for links | 49 | //Actions for links |
| 51 | - $( '#nav-proposal-categories a' ).on('click touchstart', function(event){ | ||
| 52 | - event.preventDefault(); | 50 | + $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ |
| 51 | + e.preventDefault(); | ||
| 53 | 52 | ||
| 54 | var $link = $(this); | 53 | var $link = $(this); |
| 55 | 54 | ||
| @@ -57,8 +56,8 @@ $.getJSON(noosferoAPI) | @@ -57,8 +56,8 @@ $.getJSON(noosferoAPI) | ||
| 57 | updateHash($link.attr('href')); | 56 | updateHash($link.attr('href')); |
| 58 | }); | 57 | }); |
| 59 | 58 | ||
| 60 | - $( '#nav-proposal-group a' ).on('click touchstart', function(event){ | ||
| 61 | - event.preventDefault(); | 59 | + $( '#nav-proposal-group a' ).on('click touchstart', function(e){ |
| 60 | + e.preventDefault(); | ||
| 62 | 61 | ||
| 63 | var $link = $(this); | 62 | var $link = $(this); |
| 64 | 63 | ||
| @@ -66,26 +65,26 @@ $.getJSON(noosferoAPI) | @@ -66,26 +65,26 @@ $.getJSON(noosferoAPI) | ||
| 66 | updateHash($link.attr('href')); | 65 | updateHash($link.attr('href')); |
| 67 | }); | 66 | }); |
| 68 | 67 | ||
| 69 | - $( '.proposal-item a' ).on('click touchstart', function(event){ | 68 | + $( '.proposal-item a' ).on('click touchstart', function(e){ |
| 69 | + e.preventDefault(); | ||
| 70 | + | ||
| 70 | var $link = $(this); | 71 | var $link = $(this); |
| 71 | - var item = $link.data('target'); | ||
| 72 | 72 | ||
| 73 | // Update URL and Navigate | 73 | // Update URL and Navigate |
| 74 | updateHash($link.attr('href')); | 74 | updateHash($link.attr('href')); |
| 75 | }); | 75 | }); |
| 76 | 76 | ||
| 77 | - $( '.proposal-category a' ).on('click touchstart', function(event){ | ||
| 78 | - event.preventDefault(); | 77 | + $( '.proposal-category a' ).on('click touchstart', function(e){ |
| 78 | + e.preventDefault(); | ||
| 79 | 79 | ||
| 80 | var $link = $(this); | 80 | var $link = $(this); |
| 81 | - var item = $link.data('target'); | ||
| 82 | 81 | ||
| 83 | // Update URL and Navigate | 82 | // Update URL and Navigate |
| 84 | updateHash($link.attr('href')); | 83 | updateHash($link.attr('href')); |
| 85 | }); | 84 | }); |
| 86 | 85 | ||
| 87 | - $( '.proposal-category .go-back' ).on('click touchstart', function(event){ | ||
| 88 | - event.preventDefault(); | 86 | + $( '.proposal-category .go-back' ).on('click touchstart', function(e){ |
| 87 | + e.preventDefault(); | ||
| 89 | 88 | ||
| 90 | var oldHash = window.location.hash; | 89 | var oldHash = window.location.hash; |
| 91 | var regexSubpages = /sobre-o-programa$/; | 90 | var regexSubpages = /sobre-o-programa$/; |
| @@ -121,7 +120,6 @@ $.getJSON(noosferoAPI) | @@ -121,7 +120,6 @@ $.getJSON(noosferoAPI) | ||
| 121 | e.preventDefault(); | 120 | e.preventDefault(); |
| 122 | 121 | ||
| 123 | var $link = $(this); | 122 | var $link = $(this); |
| 124 | - var item = $link.data('target'); | ||
| 125 | 123 | ||
| 126 | // Update URL and Navigate | 124 | // Update URL and Navigate |
| 127 | updateHash($link.attr('href')); | 125 | updateHash($link.attr('href')); |
| @@ -131,7 +129,6 @@ $.getJSON(noosferoAPI) | @@ -131,7 +129,6 @@ $.getJSON(noosferoAPI) | ||
| 131 | e.preventDefault(); | 129 | e.preventDefault(); |
| 132 | 130 | ||
| 133 | var $link = $(this); | 131 | var $link = $(this); |
| 134 | - var item = $link.data('target'); | ||
| 135 | 132 | ||
| 136 | // Update URL and Navigate | 133 | // Update URL and Navigate |
| 137 | updateHash($link.attr('href')); | 134 | updateHash($link.attr('href')); |
| @@ -176,7 +173,7 @@ $.getJSON(noosferoAPI) | @@ -176,7 +173,7 @@ $.getJSON(noosferoAPI) | ||
| 176 | url: host + '/api/v1/articles/' + proposal_id + '/children', | 173 | url: host + '/api/v1/articles/' + proposal_id + '/children', |
| 177 | data: $('#'+this.id).serialize() + '&private_token=' + private_token + '&fields=id&article[name]=article_' + guid() | 174 | data: $('#'+this.id).serialize() + '&private_token=' + private_token + '&fields=id&article[name]=article_' + guid() |
| 178 | }) | 175 | }) |
| 179 | - .done(function( data ) { | 176 | + .done(function( /*data*/ ) { |
| 180 | form.reset(); | 177 | form.reset(); |
| 181 | $form.hide(); | 178 | $form.hide(); |
| 182 | $form.siblings('.success-sent').show(); | 179 | $form.siblings('.success-sent').show(); |
| @@ -231,7 +228,7 @@ function loadRandomProposal(topic_id, private_token) { | @@ -231,7 +228,7 @@ function loadRandomProposal(topic_id, private_token) { | ||
| 231 | value: $(this).data('vote-value'), | 228 | value: $(this).data('vote-value'), |
| 232 | private_token: private_token | 229 | private_token: private_token |
| 233 | } | 230 | } |
| 234 | - }).done(function( data ) { | 231 | + }).done(function( /*data*/ ) { |
| 235 | loadRandomProposal(topic_id, private_token); | 232 | loadRandomProposal(topic_id, private_token); |
| 236 | }); | 233 | }); |
| 237 | e.preventDefault(); | 234 | e.preventDefault(); |
| @@ -267,45 +264,21 @@ function loadRandomProposal(topic_id, private_token) { | @@ -267,45 +264,21 @@ function loadRandomProposal(topic_id, private_token) { | ||
| 267 | $('.experience-proposal-container').show(); | 264 | $('.experience-proposal-container').show(); |
| 268 | $('.talk-proposal-container').show(); | 265 | $('.talk-proposal-container').show(); |
| 269 | } | 266 | } |
| 270 | - | 267 | + |
| 271 | e.preventDefault(); | 268 | e.preventDefault(); |
| 272 | }); | 269 | }); |
| 273 | }); | 270 | }); |
| 274 | } | 271 | } |
| 275 | 272 | ||
| 276 | -jQuery(document).ready(function($) { | 273 | +$(document).ready(function($) { |
| 277 | if($.cookie('_dialoga_session')) { | 274 | if($.cookie('_dialoga_session')) { |
| 278 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); | 275 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); |
| 279 | - $.getJSON(url).done(function( data ) { | 276 | + $.getJSON(url).done(function( /*data*/ ) { |
| 280 | logged_in = true; | 277 | logged_in = true; |
| 281 | private_token = $.cookie('_dialoga_session'); | 278 | private_token = $.cookie('_dialoga_session'); |
| 282 | }); | 279 | }); |
| 283 | } | 280 | } |
| 284 | -}); | ||
| 285 | 281 | ||
| 286 | -function loginCallback(loggedIn, token) { | ||
| 287 | - logged_in = loggedIn; | ||
| 288 | - $('.login .message').text(''); | ||
| 289 | - | ||
| 290 | - if(logged_in) { | ||
| 291 | - if(token){ | ||
| 292 | - private_token = token; | ||
| 293 | - } | ||
| 294 | - loginButton.siblings('.save-article-form').show(); | ||
| 295 | - loginButton.siblings('.save-article-form .message').show(); | ||
| 296 | - loginButton.siblings('.login-container').hide(); | ||
| 297 | - $.cookie('_dialoga_session', private_token); | ||
| 298 | - } else { | ||
| 299 | - loginButton.siblings('.save-article-form').hide(); | ||
| 300 | - loginButton.siblings('.login-container').show(); | ||
| 301 | - } | ||
| 302 | -} | ||
| 303 | - | ||
| 304 | -function oauthPluginHandleLoginResult(loggedIn, token) { | ||
| 305 | - loginCallback(loggedIn, token); | ||
| 306 | -} | ||
| 307 | - | ||
| 308 | -jQuery(document).ready(function($) { | ||
| 309 | $(document).on('click', '.login-action', function(e) { | 282 | $(document).on('click', '.login-action', function(e) { |
| 310 | var message = $('.login .message'); | 283 | var message = $('.login .message'); |
| 311 | message.hide(); | 284 | message.hide(); |
| @@ -319,7 +292,7 @@ jQuery(document).ready(function($) { | @@ -319,7 +292,7 @@ jQuery(document).ready(function($) { | ||
| 319 | } | 292 | } |
| 320 | }).done(function(data) { | 293 | }).done(function(data) { |
| 321 | loginCallback(true, data.private_token); | 294 | loginCallback(true, data.private_token); |
| 322 | - }).fail(function(data) { | 295 | + }).fail(function( /*data*/ ) { |
| 323 | message.show(); | 296 | message.show(); |
| 324 | message.text('Não foi possível logar'); | 297 | message.text('Não foi possível logar'); |
| 325 | }); | 298 | }); |
| @@ -327,6 +300,28 @@ jQuery(document).ready(function($) { | @@ -327,6 +300,28 @@ jQuery(document).ready(function($) { | ||
| 327 | }); | 300 | }); |
| 328 | }); | 301 | }); |
| 329 | 302 | ||
| 303 | +function loginCallback(loggedIn, token) { | ||
| 304 | + logged_in = loggedIn; | ||
| 305 | + $('.login .message').text(''); | ||
| 306 | + | ||
| 307 | + if(logged_in) { | ||
| 308 | + if(token){ | ||
| 309 | + private_token = token; | ||
| 310 | + } | ||
| 311 | + loginButton.siblings('.save-article-form').show(); | ||
| 312 | + loginButton.siblings('.save-article-form .message').show(); | ||
| 313 | + loginButton.siblings('.login-container').hide(); | ||
| 314 | + $.cookie('_dialoga_session', private_token); | ||
| 315 | + } else { | ||
| 316 | + loginButton.siblings('.save-article-form').hide(); | ||
| 317 | + loginButton.siblings('.login-container').show(); | ||
| 318 | + } | ||
| 319 | +} | ||
| 320 | + | ||
| 321 | +// function oauthPluginHandleLoginResult(loggedIn, token) { | ||
| 322 | +// loginCallback(loggedIn, token); | ||
| 323 | +// } | ||
| 324 | + | ||
| 330 | function guid() { | 325 | function guid() { |
| 331 | function s4() { | 326 | function s4() { |
| 332 | return Math.floor((1 + Math.random()) * 0x10000) | 327 | return Math.floor((1 + Math.random()) * 0x10000) |