Commit 1ac5135310a32febbe0b83236b2e1adfea13898b
1 parent
13e18eaf
Exists in
jasmine-testing
Refactory Url object and require.js deps to another paths configurations
Showing
4 changed files
with
71 additions
and
61 deletions
Show diff stats
index.html
| ... | ... | @@ -14,32 +14,46 @@ |
| 14 | 14 | */ |
| 15 | 15 | var Url = (function(){ |
| 16 | 16 | |
| 17 | + var _base = ''; | |
| 18 | + | |
| 17 | 19 | return { |
| 18 | 20 | |
| 19 | 21 | initBase: function(){ |
| 20 | - var base = window.location.href; | |
| 22 | + _base = window.location.href; | |
| 21 | 23 | var host = window.location.host; |
| 22 | 24 | var regex = new RegExp(".*" + host + '/', "g"); |
| 23 | 25 | |
| 24 | 26 | if(host){ |
| 25 | - base = base.replace(regex,''); | |
| 27 | + _base = _base.replace(regex,''); | |
| 26 | 28 | }else{ |
| 27 | - base = base.replace('index.html',''); | |
| 29 | + _base = _base.replace('index.html',''); | |
| 30 | + } | |
| 31 | + return this; | |
| 32 | + }, | |
| 33 | + getBase: function(){ | |
| 34 | + | |
| 35 | + if(!_base){ | |
| 36 | + this.initBase(); | |
| 28 | 37 | } |
| 29 | - return base | |
| 38 | + | |
| 39 | + return _base; | |
| 30 | 40 | }, |
| 31 | 41 | removeUrlParameters: function(full_url){ |
| 42 | + full_url = full_url || _base; | |
| 32 | 43 | var url_base = full_url.split('#').shift(); |
| 33 | 44 | return url_base; |
| 34 | 45 | }, |
| 35 | 46 | addBaseUrl: function(filename){ |
| 36 | - var base = window.location.href; | |
| 47 | + base = window.location.href; | |
| 37 | 48 | if(base.match(/file:/) || filename.match(/http:/)){ |
| 38 | 49 | base = ''; |
| 39 | 50 | }else{ |
| 40 | 51 | base = this.removeUrlParameters(base) + '/'; |
| 41 | 52 | } |
| 42 | 53 | return base + filename; |
| 54 | + }, | |
| 55 | + toString: function(){ | |
| 56 | + return this.getBase(); | |
| 43 | 57 | } |
| 44 | 58 | } |
| 45 | 59 | |
| ... | ... | @@ -75,12 +89,21 @@ |
| 75 | 89 | function loadJavaScriptAsync(file_path){ |
| 76 | 90 | } |
| 77 | 91 | |
| 78 | - function loadRequireJS(){ | |
| 92 | + function loadRequireJS(onLoad){ | |
| 79 | 93 | var head = document.getElementsByTagName('head')[0]; |
| 80 | 94 | var script_element = document.createElement('script'); |
| 81 | 95 | script_element.type = 'text/javascript'; |
| 82 | 96 | script_element.src = makeJSURL('js/require.js'); |
| 83 | - script_element.setAttribute('data-main', makeJSURL('js/requirejs-config.js')); | |
| 97 | + // script_element.setAttribute('data-main', makeJSURL('js/requirejs-config.js')); | |
| 98 | + if(onLoad instanceof Function){ | |
| 99 | + script_element.onreadystatechange = function(){ | |
| 100 | + if (this.readyState == 'complete'){ | |
| 101 | + onload(); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + script_element.addEventListener('load', onLoad); | |
| 105 | + } | |
| 106 | + | |
| 84 | 107 | head.appendChild(script_element); |
| 85 | 108 | } |
| 86 | 109 | loadCSSFiles(); |
| ... | ... | @@ -197,7 +220,7 @@ |
| 197 | 220 | <div class="info">Ela se tornará pública em até 24 horas após o envio e poderá ser apoiada por outros participantes.</div> |
| 198 | 221 | <div class="send-proposal-button send-button"><a href="#"><span>Envie Sua Proposta</span></a></div> |
| 199 | 222 | <div class="login-container hide">Login</div> |
| 200 | - <form class="make-proposal-form save-article-form hide" id="make-proposal-form-{{id}}" action="{{proposal_action ../article . }}" method="post"> | |
| 223 | + <form class="make-proposal-form save-article-form hide" id="make-proposal-form-{{id}}" action="{{proposal_action ../article . }}"> | |
| 201 | 224 | <div class="message hide"></div> |
| 202 | 225 | <div> |
| 203 | 226 | <div><label for="article_abstract">Descrição</label></div> |
| ... | ... | @@ -230,7 +253,7 @@ |
| 230 | 253 | <p>Esta história pode nos ajudar a melhorar a nossa ação e não será divulgada.</p> |
| 231 | 254 | <div class="send-experience-button send-button"><a href="#"><span>Envie Sua Experiência</span></a></div> |
| 232 | 255 | <div class="login-container hide">Login</div> |
| 233 | - <form class="make-experience-form save-article-form hide" id="make-experience-form-{{id}}" action="/api/v1/articles/{{id}}/children" method="post"> | |
| 256 | + <form class="make-experience-form save-article-form hide" id="make-experience-form-{{id}}" action="/api/v1/articles/{{id}}/children"> | |
| 234 | 257 | <div class="message hide"></div> |
| 235 | 258 | <div> |
| 236 | 259 | <div> |
| ... | ... | @@ -258,7 +281,7 @@ |
| 258 | 281 | <div class="date"><i class="fa fa-calendar"></i> 17/06/2015</div><div class="time"><i class="fa fa-clock-o"></i> 19:00</div> |
| 259 | 282 | </li> |
| 260 | 283 | <li> |
| 261 | - <span>Tereza Campello</span> | |
| 284 | + <span>Teresa Campello</span> | |
| 262 | 285 | <span>Desenvolvimento Social</span> |
| 263 | 286 | <div class="date"><i class="fa fa-calendar"></i> 18/06/2015</div><div class="time"><i class="fa fa-clock-o"></i> 19:00</div> |
| 264 | 287 | </li> |
| ... | ... | @@ -333,17 +356,22 @@ |
| 333 | 356 | </div> |
| 334 | 357 | <div class="oauth"> |
| 335 | 358 | <div class="label">Acessar com:</div> |
| 336 | - <a href="http://www.participa.br/plugin/oauth_client/facebook?oauth_client_popup=true&id=1" target="_blank" class="facebook oauth-login">Facebook</a> | |
| 337 | - <a href="http://www.participa.br/plugin/oauth_client/google_oauth2?oauth_client_popup=true&id=2" target="_blank" class="google oauth-login">Google +</a> | |
| 359 | + <a href="/plugin/oauth_client/facebook?oauth_client_popup=true&id=1" target="_blank" class="facebook">Facebook</a> | |
| 360 | + <a href="/plugin/oauth_client/google_oauth2?oauth_client_popup=true&id=2" target="_blank" class="google">Google +</a> | |
| 338 | 361 | <a href="http://www.participa.br/account/signup" target="_blank" class="new-user">Cadastrar</a> |
| 339 | 362 | </div> |
| 340 | 363 | </form> |
| 341 | 364 | </script> |
| 342 | 365 | |
| 343 | - <script type='text/javascript' > | |
| 344 | - loadRequireJS(); | |
| 345 | - </script> | |
| 366 | + <script type='text/javascript'> | |
| 367 | + loadRequireJS(function(){ | |
| 368 | + | |
| 369 | + require([ Url.getBase()+'/js/requirejs-config' ], function(){ | |
| 370 | + requirejs(['proposal_app','main']); | |
| 371 | + }); | |
| 346 | 372 | |
| 373 | + }); | |
| 374 | + </script> | |
| 347 | 375 | |
| 348 | 376 | </body> |
| 349 | 377 | ... | ... |
js/main.js
| 1 | -define(['handlebars','handlebars_helpers'], function(Handlebars){ | |
| 1 | +define(['handlebars_helpers','jquery_ui','jquery_slick', 'jquery_maxlength', 'layout'], function(Handlebars){ | |
| 2 | 2 | |
| 3 | 3 | /* global Handlebars, $ */ |
| 4 | 4 | // The template code |
| ... | ... | @@ -43,11 +43,6 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 43 | 43 | |
| 44 | 44 | Main.navigateTo(window.location.hash); |
| 45 | 45 | |
| 46 | - $('.oauth-login').on('click touchstart', function(e) { | |
| 47 | - Main.oauthClientAction($(this).attr('href')); | |
| 48 | - e.preventDefault(); | |
| 49 | - }); | |
| 50 | - | |
| 51 | 46 | //Actions for links |
| 52 | 47 | $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ |
| 53 | 48 | e.preventDefault(); |
| ... | ... | @@ -372,7 +367,6 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 372 | 367 | $('.results-container').hide(); |
| 373 | 368 | $('.experience-proposal-container').hide(); |
| 374 | 369 | $('.talk-proposal-container').hide(); |
| 375 | - $('#proposal-item-' + proposal_id + '.proposal-detail').show(); | |
| 376 | 370 | $('#proposal-item-' + proposal_id + ' .body').show(); |
| 377 | 371 | |
| 378 | 372 | var url = host + '/api/v1/articles/' + proposal_id + '?private_token=' + private_token + '&fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; |
| ... | ... | @@ -502,13 +496,17 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 502 | 496 | $('html, body').animate({ scrollTop: 0 }, 'fast'); |
| 503 | 497 | }, |
| 504 | 498 | navigateToProposal: function(proposalId){ |
| 505 | - var regexSubpages = /sobre-o-programa$/; | |
| 506 | 499 | if(proposalId === undefined){ |
| 507 | 500 | this.display_proposals_tab(); |
| 508 | - }else if(regexSubpages.exec(window.location.hash) == null){ | |
| 509 | - this.display_proposal('proposal-item-' + proposalId); | |
| 510 | 501 | }else{ |
| 511 | - this.display_proposal_detail(proposalId); | |
| 502 | + this.display_proposal('proposal-item-' + proposalId); | |
| 503 | + | |
| 504 | + // show sub-page | |
| 505 | + var regexSubpages = /sobre-o-programa$/; | |
| 506 | + var m; | |
| 507 | + if((m = regexSubpages.exec(window.location.hash)) !== null ){ | |
| 508 | + this.display_proposal_detail(proposalId); | |
| 509 | + } | |
| 512 | 510 | } |
| 513 | 511 | }, |
| 514 | 512 | navigateToCategory: function(categoryId){ |
| ... | ... | @@ -517,23 +515,6 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 517 | 515 | }else{ |
| 518 | 516 | this.display_proposal_by_category('proposal-item-' + categoryId); |
| 519 | 517 | } |
| 520 | - }, | |
| 521 | - oauthClientAction: function(url) { | |
| 522 | - var child = window.open(url, "_blank"); | |
| 523 | - var interval = setInterval(function() { | |
| 524 | - try { | |
| 525 | - if(!child.closed) { | |
| 526 | - child.postMessage({ message: "requestOauthClientPluginResult" }, "*"); | |
| 527 | - } | |
| 528 | - } | |
| 529 | - catch(e) { | |
| 530 | - // we're here when the child window has been navigated away or closed | |
| 531 | - if (child.closed) { | |
| 532 | - clearInterval(interval); | |
| 533 | - return; | |
| 534 | - } | |
| 535 | - } | |
| 536 | - }, 300); | |
| 537 | 518 | } |
| 538 | 519 | } |
| 539 | 520 | })(); |
| ... | ... | @@ -569,12 +550,9 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 569 | 550 | }); |
| 570 | 551 | }); |
| 571 | 552 | |
| 572 | - window.addEventListener("message", function(ev) { | |
| 573 | - if (ev.data.message === "oauthClientPluginResult") { | |
| 574 | - Main.loginCallback(ev.data.logged_in, ev.data.private_token); | |
| 575 | - ev.source.close(); | |
| 576 | - } | |
| 577 | - }); | |
| 553 | + window.oauthPluginHandleLoginResult = function(loggedIn, token) { | |
| 554 | + Main.loginCallback(loggedIn, token); | |
| 555 | + } | |
| 578 | 556 | |
| 579 | 557 | if('onhashchange' in window){ |
| 580 | 558 | window.onhashchange = function(){ | ... | ... |
js/proposal-app.js
js/requirejs-config.js
| 1 | +var base,test = ''; | |
| 2 | + | |
| 1 | 3 | if(window.Url){ |
| 2 | - var base = Url.initBase(); | |
| 3 | - base = Url.removeUrlParameters(base) + '/js/'; | |
| 4 | + var base = Url.initBase().removeUrlParameters()+'/js/'; | |
| 4 | 5 | }else{ |
| 5 | 6 | base = '../js' |
| 7 | + test = window.location.href.replace(/\/\w*\.html/g,''); | |
| 6 | 8 | } |
| 7 | 9 | |
| 8 | 10 | requirejs.config({ |
| ... | ... | @@ -15,30 +17,35 @@ requirejs.config({ |
| 15 | 17 | handlebars: 'handlebars-v3.0.1', |
| 16 | 18 | handlebars_helpers: 'handlebars-helpers', |
| 17 | 19 | jquery_maxlength: 'jquery.maxlength.min', |
| 18 | - slick: 'slick.min', | |
| 20 | + jquery_slick: 'slick.min', | |
| 19 | 21 | layout: 'layout', |
| 20 | 22 | main: 'main', |
| 21 | - proposal_app: 'proposal-app' | |
| 23 | + proposal_app: 'proposal-app', | |
| 24 | + test:test | |
| 22 | 25 | }, |
| 23 | 26 | shim: { |
| 24 | 27 | 'handlebars':{ |
| 25 | 28 | deps: ['jquery'], |
| 26 | 29 | exports: 'Handlebars' |
| 27 | 30 | }, |
| 31 | + 'handlebars_helpers':{ | |
| 32 | + deps: ['handlebars'], | |
| 33 | + exports: 'Handlebars' | |
| 34 | + }, | |
| 28 | 35 | 'jquery_ui': { |
| 29 | 36 | deps: ['jquery'] |
| 30 | 37 | }, |
| 31 | 38 | 'layout': { |
| 32 | 39 | deps: ['jquery'] |
| 33 | 40 | }, |
| 34 | - 'jquery_maxlength': { | |
| 41 | + 'jquery_maxlength':{ | |
| 35 | 42 | deps: ['jquery'] |
| 36 | 43 | }, |
| 37 | - 'slick': { | |
| 44 | + 'jquery_cookie':{ | |
| 38 | 45 | deps: ['jquery'] |
| 39 | 46 | }, |
| 40 | - 'handlebars_helpers':{ | |
| 41 | - deps: ['handlebars'] | |
| 47 | + 'jquery_slick': { | |
| 48 | + deps: ['jquery'] | |
| 42 | 49 | }, |
| 43 | 50 | 'proposal_app' :{ |
| 44 | 51 | deps: ['jquery'], |
| ... | ... | @@ -46,6 +53,3 @@ requirejs.config({ |
| 46 | 53 | } |
| 47 | 54 | } |
| 48 | 55 | }); |
| 49 | - | |
| 50 | -requirejs(['jquery', 'proposal_app', 'jquery_ui','handlebars_helpers']); | |
| 51 | -requirejs(['slick', 'jquery_maxlength', 'layout','main']); | ... | ... |