Commit b85ba2b2066b765c9ea3c2bc5f0b51ce7068a521
1 parent
0a4ffde6
Exists in
master
and in
8 other branches
Fix cross domain ajax request for IE
Showing
3 changed files
with
355 additions
and
344 deletions
Show diff stats
@@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
1 | +/*! | ||
2 | + * jQuery-ajaxTransport-XDomainRequest - v1.0.3 - 2014-06-06 | ||
3 | + * https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest | ||
4 | + * Copyright (c) 2014 Jason Moon (@JSONMOON) | ||
5 | + * Licensed MIT (/blob/master/LICENSE.txt) | ||
6 | + */ | ||
7 | +(function(a){if(typeof define==='function'&&define.amd){define(['jquery'],a)}else if(typeof exports==='object'){module.exports=a(require('jquery'))}else{a(jQuery)}}(function($){if($.support.cors||!$.ajaxTransport||!window.XDomainRequest){return}var n=/^https?:\/\//i;var o=/^get|post$/i;var p=new RegExp('^'+location.protocol,'i');$.ajaxTransport('* text html xml json',function(j,k,l){if(!j.crossDomain||!j.async||!o.test(j.type)||!n.test(j.url)||!p.test(j.url)){return}var m=null;return{send:function(f,g){var h='';var i=(k.dataType||'').toLowerCase();m=new XDomainRequest();if(/^\d+$/.test(k.timeout)){m.timeout=k.timeout}m.ontimeout=function(){g(500,'timeout')};m.onload=function(){var a='Content-Length: '+m.responseText.length+'\r\nContent-Type: '+m.contentType;var b={code:200,message:'success'};var c={text:m.responseText};try{if(i==='html'||/text\/html/i.test(m.contentType)){c.html=m.responseText}else if(i==='json'||(i!=='text'&&/\/json/i.test(m.contentType))){try{c.json=$.parseJSON(m.responseText)}catch(e){b.code=500;b.message='parseerror'}}else if(i==='xml'||(i!=='text'&&/\/xml/i.test(m.contentType))){var d=new ActiveXObject('Microsoft.XMLDOM');d.async=false;try{d.loadXML(m.responseText)}catch(e){d=undefined}if(!d||!d.documentElement||d.getElementsByTagName('parsererror').length){b.code=500;b.message='parseerror';throw'Invalid XML: '+m.responseText;}c.xml=d}}catch(parseMessage){throw parseMessage;}finally{g(b.code,b.message,c,a)}};m.onprogress=function(){};m.onerror=function(){g(500,'error',{text:m.responseText})};if(k.data){h=($.type(k.data)==='string')?k.data:$.param(k.data)}m.open(j.type,j.url);m.send(h)},abort:function(){if(m){m.abort()}}}})})); | ||
0 | \ No newline at end of file | 8 | \ No newline at end of file |
js/main.js
@@ -30,6 +30,349 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ | @@ -30,6 +30,349 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ | ||
30 | //var proposal_discussion = '401'; //casa | 30 | //var proposal_discussion = '401'; //casa |
31 | } | 31 | } |
32 | 32 | ||
33 | + var BARRA_ADDED = false; | ||
34 | + var HIDE_BARRA_DO_GOVERNO = false; | ||
35 | + | ||
36 | + Main = (function(){ | ||
37 | + | ||
38 | + return { | ||
39 | + loadRandomProposal: function (topic_id, private_token) { | ||
40 | + var $noProposals = $('.no-proposals'); | ||
41 | + var $loading = $('.loading'); | ||
42 | + var $randomProposal = $('.random-proposal'); | ||
43 | + var $body = $(document.body); | ||
44 | + var contextMain = this; | ||
45 | + | ||
46 | + // reset view | ||
47 | + $noProposals.hide(); | ||
48 | + $loading.show(); | ||
49 | + $randomProposal.html(''); | ||
50 | + | ||
51 | + 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'; | ||
52 | + $.getJSON(url).done(function( data ) { | ||
53 | + $loading.hide(); | ||
54 | + | ||
55 | + if(data.articles.length === 0) { | ||
56 | + $noProposals.show(); | ||
57 | + return; | ||
58 | + } | ||
59 | + | ||
60 | + var article = data.articles[0]; | ||
61 | + $randomProposal.html(supportProposalTemplate(article)); | ||
62 | + $body.off('click', '.vote-actions .skip'); | ||
63 | + $body.on('click', '.vote-actions .skip', function(e) { | ||
64 | + contextMain.loadRandomProposal(topic_id, private_token); | ||
65 | + e.preventDefault(); | ||
66 | + }); | ||
67 | + $body.off('click', '.vote-actions .like'); | ||
68 | + $body.on('click', '.vote-actions .like', function(e) { | ||
69 | + //Helps to prevent more than one vote per proposal | ||
70 | + if(ProposalApp.hasProposalbeenVoted(article.id)){ | ||
71 | + console.log("Proposta " + article.id + " já havia sido votada"); | ||
72 | + contextMain.loadRandomProposal(topic_id, private_token); | ||
73 | + e.preventDefault(); | ||
74 | + return; | ||
75 | + } | ||
76 | + $.ajax({ | ||
77 | + type: 'post', | ||
78 | + url: host + '/api/v1/articles/' + article.id + '/vote', | ||
79 | + data: { | ||
80 | + value: $(this).data('vote-value'), | ||
81 | + private_token: private_token | ||
82 | + } | ||
83 | + }).done(function( /*data*/ ) { | ||
84 | + ProposalApp.addVotedProposal(article.id); | ||
85 | + contextMain.loadRandomProposal(topic_id, private_token); | ||
86 | + }); | ||
87 | + e.preventDefault(); | ||
88 | + }); | ||
89 | + | ||
90 | + $body.off('click', '.vote-result'); | ||
91 | + $body.on('click', '.vote-result', function(e) { | ||
92 | + | ||
93 | + var $this = $(this); | ||
94 | + var $proposalDetail = $this.parents('.proposal-detail'); | ||
95 | + var $resultsContainer = $proposalDetail.find('.results-container'); | ||
96 | + | ||
97 | + // $resultsContainer.toggle(); | ||
98 | + // $resultsContainer.toggleClass('hide'); | ||
99 | + | ||
100 | + if($resultsContainer.css('display') === 'none') { | ||
101 | + | ||
102 | + $resultsContainer.find('.loading').show(); | ||
103 | + $resultsContainer.find('.results-content').hide(); | ||
104 | + | ||
105 | + 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'; | ||
106 | + $.getJSON(url).done(function( data ) { | ||
107 | + | ||
108 | + $resultsContainer.html(resultsTemplate(data)); | ||
109 | + $resultsContainer.find('.loading').hide(); | ||
110 | + $resultsContainer.find('.results-content').show(); | ||
111 | + $resultsContainer.show(); | ||
112 | + | ||
113 | + // scroll to the end | ||
114 | + $('html, body').animate({ | ||
115 | + scrollTop: $(document).height() | ||
116 | + }, 'fast'); | ||
117 | + }); | ||
118 | + $('.experience-proposal-container').hide(); | ||
119 | + $('.talk-proposal-container').hide(); | ||
120 | + } else { | ||
121 | + $('.experience-proposal-container').show(); | ||
122 | + $('.talk-proposal-container').show(); | ||
123 | + $resultsContainer.hide(); | ||
124 | + } | ||
125 | + | ||
126 | + e.preventDefault(); | ||
127 | + }); | ||
128 | + }); | ||
129 | + }, | ||
130 | + | ||
131 | + loginCallback: function(loggedIn, token) { | ||
132 | + logged_in = loggedIn; | ||
133 | + $('.login .message').text(''); | ||
134 | + | ||
135 | + if(logged_in) { | ||
136 | + if(token){ | ||
137 | + private_token = token; | ||
138 | + } | ||
139 | + loginButton.siblings('.save-article-form').show(); | ||
140 | + loginButton.siblings('.save-article-form .message').show(); | ||
141 | + loginButton.siblings('.login-container').hide(); | ||
142 | + $.cookie('_dialoga_session', private_token); | ||
143 | + } else { | ||
144 | + loginButton.siblings('.save-article-form').hide(); | ||
145 | + loginButton.siblings('.login-container').show(); | ||
146 | + } | ||
147 | + }, | ||
148 | + guid: function() { | ||
149 | + function s4() { | ||
150 | + return Math.floor((1 + Math.random()) * 0x10000) | ||
151 | + .toString(16) | ||
152 | + .substring(1); | ||
153 | + } | ||
154 | + return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
155 | + }, | ||
156 | + display_category_tab: function(){ | ||
157 | + $('#proposal-group').hide(); | ||
158 | + $('#proposal-categories').show(); | ||
159 | + $('#nav-proposal-categories a').addClass('active'); | ||
160 | + $('#nav-proposal-group a').removeClass('active'); | ||
161 | + $('.proposal-category-items').hide(); | ||
162 | + $('.proposal-category .arrow-box').hide(); | ||
163 | + $('.proposal-detail').hide(); | ||
164 | + | ||
165 | + $('#content').show(); | ||
166 | + $('nav').show(); | ||
167 | + }, | ||
168 | + display_proposals_tab: function(){ | ||
169 | + $('#proposal-categories').hide(); | ||
170 | + $('#proposal-group').show(); | ||
171 | + $('#nav-proposal-group a').addClass('active'); | ||
172 | + $('#nav-proposal-categories a').removeClass('active'); | ||
173 | + $('#content').show(); | ||
174 | + $('nav').show(); | ||
175 | + }, | ||
176 | + display_proposal: function(proposal_id){ | ||
177 | + $('#proposal-categories').hide(); | ||
178 | + $('#proposal-group').hide(); | ||
179 | + $('nav').hide(); | ||
180 | + $('#content').hide(); | ||
181 | + $('.make-proposal-form').hide(); | ||
182 | + $('.login-container').hide(); | ||
183 | + $('.proposal-detail').hide(); | ||
184 | + $('.proposal-detail-base').hide(); | ||
185 | + $('#' + proposal_id).show(); | ||
186 | + $('.proposal-header').show(); | ||
187 | + $('.make-proposal-container').show(); | ||
188 | + $('.support-proposal-container').show(); | ||
189 | + $('.results-container').hide(); | ||
190 | + $('.results-container .loading').hide(); | ||
191 | + $('.results-container .results-content').hide(); | ||
192 | + $('.experience-proposal-container').show(); | ||
193 | + $('.talk-proposal-container').show(); | ||
194 | + $('.calendar').slick(); | ||
195 | + var topic_id = proposal_id.split('-').pop(); | ||
196 | + this.loadRandomProposal(topic_id, private_token); | ||
197 | + }, | ||
198 | + display_proposal_detail: function(proposal_id){ | ||
199 | + $('#proposal-categories').hide(); | ||
200 | + $('#proposal-group').hide(); | ||
201 | + $('nav').hide(); | ||
202 | + $('#content').hide(); | ||
203 | + $('.make-proposal-form').hide(); | ||
204 | + $('.proposal-header').hide(); | ||
205 | + $('.make-proposal-container').hide(); | ||
206 | + $('.support-proposal-container').hide(); | ||
207 | + $('.results-container').hide(); | ||
208 | + $('.experience-proposal-container').hide(); | ||
209 | + $('.talk-proposal-container').hide(); | ||
210 | + $('#proposal-item-' + proposal_id + '.proposal-detail').show(); | ||
211 | + $('#proposal-item-' + proposal_id + ' .body').show(); | ||
212 | + | ||
213 | + var url = host + '/api/v1/articles/' + proposal_id + '?private_token=' + private_token + '&fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; | ||
214 | + $.getJSON(url).done(function( data ) { | ||
215 | + $('#proposal-item-' + proposal_id + ' .body-content').replaceWith(data.article.body); | ||
216 | + }) | ||
217 | + .fail(function( jqxhr, textStatus, error ) { | ||
218 | + var err = textStatus + ', ' + error; | ||
219 | + console.log( 'Request Failed: ' + err ); | ||
220 | + }); | ||
221 | + }, | ||
222 | + display_proposal_by_category: function(item){ | ||
223 | + var $item = $('#' + item); | ||
224 | + | ||
225 | + if($item.hasClass('proposal-category-items')){ | ||
226 | + //Display Topics or Discussion by category | ||
227 | + $('nav').show(); | ||
228 | + $('#content').show(); | ||
229 | + $('#proposal-categories').show(); | ||
230 | + $('#nav-proposal-categories a').addClass('active'); | ||
231 | + $('#nav-proposal-group a').removeClass('active'); | ||
232 | + $('.proposal-category-items').hide(); | ||
233 | + $('.proposal-detail').hide(); | ||
234 | + $item.toggle( 'blind', 1000 ); | ||
235 | + $('.proposal-category .arrow-box').hide(); | ||
236 | + var categorySlug = $item.data('category'); | ||
237 | + $('#proposal-category-' + categorySlug).find('.arrow-box').show(); | ||
238 | + } | ||
239 | + }, | ||
240 | + addBarraDoGoverno: function(){ | ||
241 | + | ||
242 | + if( BARRA_ADDED ) { return; } | ||
243 | + | ||
244 | + var HTML_BODY_PREPEND = '' + | ||
245 | + '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + | ||
246 | + '<ul id="menu-barra-temp" style="list-style:none;">' + | ||
247 | + '<li style="display:inline; float:left;padding-right:10px; margin-right:10px; border-right:1px solid #EDEDED"><a href="http://brasil.gov.br" style="font-family:sans,sans-serif; text-decoration:none; color:white;">Portal do Governo Brasileiro</a></li> ' + | ||
248 | + '<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>' + | ||
249 | + '</ul>' + | ||
250 | + '</div>'; | ||
251 | + | ||
252 | + var HTML_BODY_APPEND = ''+ | ||
253 | + '<div id="footer-brasil"></div>' + | ||
254 | + '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; | ||
255 | + | ||
256 | + var STYLE_TEMA_AZUL = '' + | ||
257 | + '<style>'+ | ||
258 | + '#footer-brasil {'+ | ||
259 | + 'background: none repeat scroll 0% 0% #0042b1;'+ | ||
260 | + 'padding: 1em 0px;'+ | ||
261 | + 'max-width: 100%;'+ | ||
262 | + 'margin-top: 40px;'+ | ||
263 | + '}'+ | ||
264 | + '#barra-brasil ul {'+ | ||
265 | + 'width: auto;'+ | ||
266 | + '}'+ | ||
267 | + '<style>'; | ||
268 | + | ||
269 | + var $body = $(document.body); | ||
270 | + $body.prepend(HTML_BODY_PREPEND); | ||
271 | + $body.append(HTML_BODY_APPEND); | ||
272 | + $body.append(STYLE_TEMA_AZUL); | ||
273 | + | ||
274 | + BARRA_ADDED = true; | ||
275 | + }, | ||
276 | + updateHash: function(hash){ | ||
277 | + var id = hash.replace(/^.*#/, ''); | ||
278 | + var elem = document.getElementById(id); | ||
279 | + | ||
280 | + // preserve the query param | ||
281 | + // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ | ||
282 | + // hash += '?barra=false'; | ||
283 | + // } | ||
284 | + | ||
285 | + if ( !elem ) { | ||
286 | + window.location.hash = hash; | ||
287 | + return; | ||
288 | + } | ||
289 | + | ||
290 | + elem.id = id+'-tmp'; | ||
291 | + window.location.hash = hash; | ||
292 | + elem.id = id; | ||
293 | + }, | ||
294 | + locationHashChanged: function(){ | ||
295 | + var hash = window.location.hash; | ||
296 | + this.navigateTo(hash); | ||
297 | + }, | ||
298 | + navigateTo: function(hash){ | ||
299 | + var regexProposals = /#\/programas/; | ||
300 | + var regexCategory = /#\/temas/; | ||
301 | + var regexHideBarra = /barra=false$/; | ||
302 | + | ||
303 | + if( !(regexHideBarra.exec(hash) !== null) && !HIDE_BARRA_DO_GOVERNO ){ | ||
304 | + this.addBarraDoGoverno(); | ||
305 | + }else{ | ||
306 | + HIDE_BARRA_DO_GOVERNO = true; | ||
307 | + } | ||
308 | + | ||
309 | + // remove query params | ||
310 | + hash = hash.split('?')[0]; | ||
311 | + | ||
312 | + var parts = hash.split('/'); | ||
313 | + | ||
314 | + var isProposal = regexProposals.exec(hash) !== null; | ||
315 | + var isCategory = regexCategory.exec(hash) !== null; | ||
316 | + | ||
317 | + if( isProposal ){ | ||
318 | + | ||
319 | + // go to proposal | ||
320 | + var proposalId = parts[2]; | ||
321 | + this.navigateToProposal(proposalId); | ||
322 | + } | ||
323 | + | ||
324 | + if( isCategory ){ | ||
325 | + | ||
326 | + // go to category | ||
327 | + var categoryId = parts[3]; | ||
328 | + this.navigateToCategory(categoryId); | ||
329 | + } | ||
330 | + | ||
331 | + // default | ||
332 | + if( !isProposal && !isCategory ){ | ||
333 | + // show the 'index' -> category tab | ||
334 | + this.display_category_tab(); | ||
335 | + } | ||
336 | + | ||
337 | + $('html, body').animate({ scrollTop: 0 }, 'fast'); | ||
338 | + }, | ||
339 | + navigateToProposal: function(proposalId){ | ||
340 | + var regexSubpages = /sobre-o-programa$/; | ||
341 | + if(proposalId === undefined){ | ||
342 | + this.display_proposals_tab(); | ||
343 | + }else if(regexSubpages.exec(window.location.hash) == null){ | ||
344 | + this.display_proposal('proposal-item-' + proposalId); | ||
345 | + }else{ | ||
346 | + this.display_proposal_detail(proposalId); | ||
347 | + } | ||
348 | + }, | ||
349 | + navigateToCategory: function(categoryId){ | ||
350 | + if(categoryId === undefined){ | ||
351 | + this.display_category_tab(); | ||
352 | + }else{ | ||
353 | + this.display_proposal_by_category('proposal-item-' + categoryId); | ||
354 | + } | ||
355 | + }, | ||
356 | + oauthClientAction: function(url) { | ||
357 | + var child = window.open(url, "_blank"); | ||
358 | + var interval = setInterval(function() { | ||
359 | + try { | ||
360 | + if(!child.closed) { | ||
361 | + child.postMessage({ message: "requestOauthClientPluginResult" }, "*"); | ||
362 | + } | ||
363 | + } | ||
364 | + catch(e) { | ||
365 | + // we're here when the child window has been navigated away or closed | ||
366 | + if (child.closed) { | ||
367 | + clearInterval(interval); | ||
368 | + return; | ||
369 | + } | ||
370 | + } | ||
371 | + }, 300); | ||
372 | + } | ||
373 | + } | ||
374 | + })(); | ||
375 | + | ||
33 | // Load data from localhost when it is dev env. | 376 | // 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,title,image,url,setting,position'; | 377 | var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + private_token + '&fields=id,children,categories,abstract,title,image,url,setting,position'; |
35 | 378 | ||
@@ -195,349 +538,6 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ | @@ -195,349 +538,6 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ | ||
195 | console.log( 'Request Failed: ' + err ); | 538 | console.log( 'Request Failed: ' + err ); |
196 | }); | 539 | }); |
197 | 540 | ||
198 | - var BARRA_ADDED = false; | ||
199 | - var HIDE_BARRA_DO_GOVERNO = false; | ||
200 | - | ||
201 | - Main = (function(){ | ||
202 | - | ||
203 | - return { | ||
204 | - loadRandomProposal: function (topic_id, private_token) { | ||
205 | - var $noProposals = $('.no-proposals'); | ||
206 | - var $loading = $('.loading'); | ||
207 | - var $randomProposal = $('.random-proposal'); | ||
208 | - var $body = $(document.body); | ||
209 | - var contextMain = this; | ||
210 | - | ||
211 | - // reset view | ||
212 | - $noProposals.hide(); | ||
213 | - $loading.show(); | ||
214 | - $randomProposal.html(''); | ||
215 | - | ||
216 | - 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'; | ||
217 | - $.getJSON(url).done(function( data ) { | ||
218 | - $loading.hide(); | ||
219 | - | ||
220 | - if(data.articles.length === 0) { | ||
221 | - $noProposals.show(); | ||
222 | - return; | ||
223 | - } | ||
224 | - | ||
225 | - var article = data.articles[0]; | ||
226 | - $randomProposal.html(supportProposalTemplate(article)); | ||
227 | - $body.off('click', '.vote-actions .skip'); | ||
228 | - $body.on('click', '.vote-actions .skip', function(e) { | ||
229 | - contextMain.loadRandomProposal(topic_id, private_token); | ||
230 | - e.preventDefault(); | ||
231 | - }); | ||
232 | - $body.off('click', '.vote-actions .like'); | ||
233 | - $body.on('click', '.vote-actions .like', function(e) { | ||
234 | - //Helps to prevent more than one vote per proposal | ||
235 | - if(ProposalApp.hasProposalbeenVoted(article.id)){ | ||
236 | - console.log("Proposta " + article.id + " já havia sido votada"); | ||
237 | - contextMain.loadRandomProposal(topic_id, private_token); | ||
238 | - e.preventDefault(); | ||
239 | - return; | ||
240 | - } | ||
241 | - $.ajax({ | ||
242 | - type: 'post', | ||
243 | - url: host + '/api/v1/articles/' + article.id + '/vote', | ||
244 | - data: { | ||
245 | - value: $(this).data('vote-value'), | ||
246 | - private_token: private_token | ||
247 | - } | ||
248 | - }).done(function( /*data*/ ) { | ||
249 | - ProposalApp.addVotedProposal(article.id); | ||
250 | - contextMain.loadRandomProposal(topic_id, private_token); | ||
251 | - }); | ||
252 | - e.preventDefault(); | ||
253 | - }); | ||
254 | - | ||
255 | - $body.off('click', '.vote-result'); | ||
256 | - $body.on('click', '.vote-result', function(e) { | ||
257 | - | ||
258 | - var $this = $(this); | ||
259 | - var $proposalDetail = $this.parents('.proposal-detail'); | ||
260 | - var $resultsContainer = $proposalDetail.find('.results-container'); | ||
261 | - | ||
262 | - // $resultsContainer.toggle(); | ||
263 | - // $resultsContainer.toggleClass('hide'); | ||
264 | - | ||
265 | - if($resultsContainer.css('display') === 'none') { | ||
266 | - | ||
267 | - $resultsContainer.find('.loading').show(); | ||
268 | - $resultsContainer.find('.results-content').hide(); | ||
269 | - | ||
270 | - 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'; | ||
271 | - $.getJSON(url).done(function( data ) { | ||
272 | - | ||
273 | - $resultsContainer.html(resultsTemplate(data)); | ||
274 | - $resultsContainer.find('.loading').hide(); | ||
275 | - $resultsContainer.find('.results-content').show(); | ||
276 | - $resultsContainer.show(); | ||
277 | - | ||
278 | - // scroll to the end | ||
279 | - $('html, body').animate({ | ||
280 | - scrollTop: $(document).height() | ||
281 | - }, 'fast'); | ||
282 | - }); | ||
283 | - $('.experience-proposal-container').hide(); | ||
284 | - $('.talk-proposal-container').hide(); | ||
285 | - } else { | ||
286 | - $('.experience-proposal-container').show(); | ||
287 | - $('.talk-proposal-container').show(); | ||
288 | - $resultsContainer.hide(); | ||
289 | - } | ||
290 | - | ||
291 | - e.preventDefault(); | ||
292 | - }); | ||
293 | - }); | ||
294 | - }, | ||
295 | - | ||
296 | - loginCallback: function(loggedIn, token) { | ||
297 | - logged_in = loggedIn; | ||
298 | - $('.login .message').text(''); | ||
299 | - | ||
300 | - if(logged_in) { | ||
301 | - if(token){ | ||
302 | - private_token = token; | ||
303 | - } | ||
304 | - loginButton.siblings('.save-article-form').show(); | ||
305 | - loginButton.siblings('.save-article-form .message').show(); | ||
306 | - loginButton.siblings('.login-container').hide(); | ||
307 | - $.cookie('_dialoga_session', private_token); | ||
308 | - } else { | ||
309 | - loginButton.siblings('.save-article-form').hide(); | ||
310 | - loginButton.siblings('.login-container').show(); | ||
311 | - } | ||
312 | - }, | ||
313 | - guid: function() { | ||
314 | - function s4() { | ||
315 | - return Math.floor((1 + Math.random()) * 0x10000) | ||
316 | - .toString(16) | ||
317 | - .substring(1); | ||
318 | - } | ||
319 | - return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
320 | - }, | ||
321 | - display_category_tab: function(){ | ||
322 | - $('#proposal-group').hide(); | ||
323 | - $('#proposal-categories').show(); | ||
324 | - $('#nav-proposal-categories a').addClass('active'); | ||
325 | - $('#nav-proposal-group a').removeClass('active'); | ||
326 | - $('.proposal-category-items').hide(); | ||
327 | - $('.proposal-category .arrow-box').hide(); | ||
328 | - $('.proposal-detail').hide(); | ||
329 | - | ||
330 | - $('#content').show(); | ||
331 | - $('nav').show(); | ||
332 | - }, | ||
333 | - display_proposals_tab: function(){ | ||
334 | - $('#proposal-categories').hide(); | ||
335 | - $('#proposal-group').show(); | ||
336 | - $('#nav-proposal-group a').addClass('active'); | ||
337 | - $('#nav-proposal-categories a').removeClass('active'); | ||
338 | - $('#content').show(); | ||
339 | - $('nav').show(); | ||
340 | - }, | ||
341 | - display_proposal: function(proposal_id){ | ||
342 | - $('#proposal-categories').hide(); | ||
343 | - $('#proposal-group').hide(); | ||
344 | - $('nav').hide(); | ||
345 | - $('#content').hide(); | ||
346 | - $('.make-proposal-form').hide(); | ||
347 | - $('.login-container').hide(); | ||
348 | - $('.proposal-detail').hide(); | ||
349 | - $('.proposal-detail-base').hide(); | ||
350 | - $('#' + proposal_id).show(); | ||
351 | - $('.proposal-header').show(); | ||
352 | - $('.make-proposal-container').show(); | ||
353 | - $('.support-proposal-container').show(); | ||
354 | - $('.results-container').hide(); | ||
355 | - $('.results-container .loading').hide(); | ||
356 | - $('.results-container .results-content').hide(); | ||
357 | - $('.experience-proposal-container').show(); | ||
358 | - $('.talk-proposal-container').show(); | ||
359 | - $('.calendar').slick(); | ||
360 | - var topic_id = proposal_id.split('-').pop(); | ||
361 | - this.loadRandomProposal(topic_id, private_token); | ||
362 | - }, | ||
363 | - display_proposal_detail: function(proposal_id){ | ||
364 | - $('#proposal-categories').hide(); | ||
365 | - $('#proposal-group').hide(); | ||
366 | - $('nav').hide(); | ||
367 | - $('#content').hide(); | ||
368 | - $('.make-proposal-form').hide(); | ||
369 | - $('.proposal-header').hide(); | ||
370 | - $('.make-proposal-container').hide(); | ||
371 | - $('.support-proposal-container').hide(); | ||
372 | - $('.results-container').hide(); | ||
373 | - $('.experience-proposal-container').hide(); | ||
374 | - $('.talk-proposal-container').hide(); | ||
375 | - $('#proposal-item-' + proposal_id + '.proposal-detail').show(); | ||
376 | - $('#proposal-item-' + proposal_id + ' .body').show(); | ||
377 | - | ||
378 | - var url = host + '/api/v1/articles/' + proposal_id + '?private_token=' + private_token + '&fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; | ||
379 | - $.getJSON(url).done(function( data ) { | ||
380 | - $('#proposal-item-' + proposal_id + ' .body-content').replaceWith(data.article.body); | ||
381 | - }) | ||
382 | - .fail(function( jqxhr, textStatus, error ) { | ||
383 | - var err = textStatus + ', ' + error; | ||
384 | - console.log( 'Request Failed: ' + err ); | ||
385 | - }); | ||
386 | - }, | ||
387 | - display_proposal_by_category: function(item){ | ||
388 | - var $item = $('#' + item); | ||
389 | - | ||
390 | - if($item.hasClass('proposal-category-items')){ | ||
391 | - //Display Topics or Discussion by category | ||
392 | - $('nav').show(); | ||
393 | - $('#content').show(); | ||
394 | - $('#proposal-categories').show(); | ||
395 | - $('#nav-proposal-categories a').addClass('active'); | ||
396 | - $('#nav-proposal-group a').removeClass('active'); | ||
397 | - $('.proposal-category-items').hide(); | ||
398 | - $('.proposal-detail').hide(); | ||
399 | - $item.toggle( 'blind', 1000 ); | ||
400 | - $('.proposal-category .arrow-box').hide(); | ||
401 | - var categorySlug = $item.data('category'); | ||
402 | - $('#proposal-category-' + categorySlug).find('.arrow-box').show(); | ||
403 | - } | ||
404 | - }, | ||
405 | - addBarraDoGoverno: function(){ | ||
406 | - | ||
407 | - if( BARRA_ADDED ) { return; } | ||
408 | - | ||
409 | - var HTML_BODY_PREPEND = '' + | ||
410 | - '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + | ||
411 | - '<ul id="menu-barra-temp" style="list-style:none;">' + | ||
412 | - '<li style="display:inline; float:left;padding-right:10px; margin-right:10px; border-right:1px solid #EDEDED"><a href="http://brasil.gov.br" style="font-family:sans,sans-serif; text-decoration:none; color:white;">Portal do Governo Brasileiro</a></li> ' + | ||
413 | - '<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>' + | ||
414 | - '</ul>' + | ||
415 | - '</div>'; | ||
416 | - | ||
417 | - var HTML_BODY_APPEND = ''+ | ||
418 | - '<div id="footer-brasil"></div>' + | ||
419 | - '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; | ||
420 | - | ||
421 | - var STYLE_TEMA_AZUL = '' + | ||
422 | - '<style>'+ | ||
423 | - '#footer-brasil {'+ | ||
424 | - 'background: none repeat scroll 0% 0% #0042b1;'+ | ||
425 | - 'padding: 1em 0px;'+ | ||
426 | - 'max-width: 100%;'+ | ||
427 | - 'margin-top: 40px;'+ | ||
428 | - '}'+ | ||
429 | - '#barra-brasil ul {'+ | ||
430 | - 'width: auto;'+ | ||
431 | - '}'+ | ||
432 | - '<style>'; | ||
433 | - | ||
434 | - var $body = $(document.body); | ||
435 | - $body.prepend(HTML_BODY_PREPEND); | ||
436 | - $body.append(HTML_BODY_APPEND); | ||
437 | - $body.append(STYLE_TEMA_AZUL); | ||
438 | - | ||
439 | - BARRA_ADDED = true; | ||
440 | - }, | ||
441 | - updateHash: function(hash){ | ||
442 | - var id = hash.replace(/^.*#/, ''); | ||
443 | - var elem = document.getElementById(id); | ||
444 | - | ||
445 | - // preserve the query param | ||
446 | - // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ | ||
447 | - // hash += '?barra=false'; | ||
448 | - // } | ||
449 | - | ||
450 | - if ( !elem ) { | ||
451 | - window.location.hash = hash; | ||
452 | - return; | ||
453 | - } | ||
454 | - | ||
455 | - elem.id = id+'-tmp'; | ||
456 | - window.location.hash = hash; | ||
457 | - elem.id = id; | ||
458 | - }, | ||
459 | - locationHashChanged: function(){ | ||
460 | - var hash = window.location.hash; | ||
461 | - this.navigateTo(hash); | ||
462 | - }, | ||
463 | - navigateTo: function(hash){ | ||
464 | - var regexProposals = /#\/programas/; | ||
465 | - var regexCategory = /#\/temas/; | ||
466 | - var regexHideBarra = /barra=false$/; | ||
467 | - | ||
468 | - if( !(regexHideBarra.exec(hash) !== null) && !HIDE_BARRA_DO_GOVERNO ){ | ||
469 | - this.addBarraDoGoverno(); | ||
470 | - }else{ | ||
471 | - HIDE_BARRA_DO_GOVERNO = true; | ||
472 | - } | ||
473 | - | ||
474 | - // remove query params | ||
475 | - hash = hash.split('?')[0]; | ||
476 | - | ||
477 | - var parts = hash.split('/'); | ||
478 | - | ||
479 | - var isProposal = regexProposals.exec(hash) !== null; | ||
480 | - var isCategory = regexCategory.exec(hash) !== null; | ||
481 | - | ||
482 | - if( isProposal ){ | ||
483 | - | ||
484 | - // go to proposal | ||
485 | - var proposalId = parts[2]; | ||
486 | - this.navigateToProposal(proposalId); | ||
487 | - } | ||
488 | - | ||
489 | - if( isCategory ){ | ||
490 | - | ||
491 | - // go to category | ||
492 | - var categoryId = parts[3]; | ||
493 | - this.navigateToCategory(categoryId); | ||
494 | - } | ||
495 | - | ||
496 | - // default | ||
497 | - if( !isProposal && !isCategory ){ | ||
498 | - // show the 'index' -> category tab | ||
499 | - this.display_category_tab(); | ||
500 | - } | ||
501 | - | ||
502 | - $('html, body').animate({ scrollTop: 0 }, 'fast'); | ||
503 | - }, | ||
504 | - navigateToProposal: function(proposalId){ | ||
505 | - var regexSubpages = /sobre-o-programa$/; | ||
506 | - if(proposalId === undefined){ | ||
507 | - this.display_proposals_tab(); | ||
508 | - }else if(regexSubpages.exec(window.location.hash) == null){ | ||
509 | - this.display_proposal('proposal-item-' + proposalId); | ||
510 | - }else{ | ||
511 | - this.display_proposal_detail(proposalId); | ||
512 | - } | ||
513 | - }, | ||
514 | - navigateToCategory: function(categoryId){ | ||
515 | - if(categoryId === undefined){ | ||
516 | - this.display_category_tab(); | ||
517 | - }else{ | ||
518 | - this.display_proposal_by_category('proposal-item-' + categoryId); | ||
519 | - } | ||
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 | - } | ||
538 | - } | ||
539 | - })(); | ||
540 | - | ||
541 | 541 | ||
542 | $(document).ready(function($) { | 542 | $(document).ready(function($) { |
543 | if($.cookie('_dialoga_session')) { | 543 | if($.cookie('_dialoga_session')) { |
js/requirejs-config.js
@@ -9,6 +9,7 @@ requirejs.config({ | @@ -9,6 +9,7 @@ requirejs.config({ | ||
9 | waitSeconds: 0, | 9 | waitSeconds: 0, |
10 | paths: { | 10 | paths: { |
11 | jquery: 'jquery-2.1.3.min', | 11 | jquery: 'jquery-2.1.3.min', |
12 | + jquery_xdomainrequest: 'jquery.xdomainrequest.min', | ||
12 | jquery_ui: 'jquery-ui-1.11.4.custom/jquery-ui.min', | 13 | jquery_ui: 'jquery-ui-1.11.4.custom/jquery-ui.min', |
13 | jquery_cookie: 'jquery.cookie', | 14 | jquery_cookie: 'jquery.cookie', |
14 | handlebars: 'handlebars-v3.0.1', | 15 | handlebars: 'handlebars-v3.0.1', |
@@ -24,6 +25,9 @@ requirejs.config({ | @@ -24,6 +25,9 @@ requirejs.config({ | ||
24 | deps: ['jquery'], | 25 | deps: ['jquery'], |
25 | exports: 'Handlebars' | 26 | exports: 'Handlebars' |
26 | }, | 27 | }, |
28 | + 'jquery_xdomainrequest': { | ||
29 | + deps: ['jquery'] | ||
30 | + }, | ||
27 | 'jquery_ui': { | 31 | 'jquery_ui': { |
28 | deps: ['jquery'] | 32 | deps: ['jquery'] |
29 | }, | 33 | }, |
@@ -46,5 +50,5 @@ requirejs.config({ | @@ -46,5 +50,5 @@ requirejs.config({ | ||
46 | } | 50 | } |
47 | }); | 51 | }); |
48 | 52 | ||
49 | -requirejs(['jquery', 'proposal_app', 'jquery_ui','handlebars_helpers']); | 53 | +requirejs(['jquery', 'proposal_app', 'jquery_ui', 'jquery_xdomainrequest', 'handlebars_helpers']); |
50 | requirejs(['slick', 'jquery_maxlength', 'layout','main']); | 54 | requirejs(['slick', 'jquery_maxlength', 'layout','main']); |