Commit ffe3e53562be6db0c97493761da6cc77f087038a
1 parent
b341c320
Exists in
build2
build do javascript e do css
Showing
6 changed files
with
1782 additions
and
1588 deletions
Show diff stats
.gitignore
gulpfile.js
| 1 | 1 | 'use strict'; |
| 2 | +/* global require, __dirname, console */ | |
| 2 | 3 | |
| 3 | 4 | var gulp = require('gulp'); |
| 4 | 5 | // var sass = require('gulp-sass'); |
| ... | ... | @@ -14,23 +15,180 @@ var connect = require('gulp-connect'); |
| 14 | 15 | |
| 15 | 16 | gulp.task('sass', function() { |
| 16 | 17 | return sass('./sass/style.sass') |
| 17 | - .on('error', function (err) { | |
| 18 | + .on('error', function(err) { | |
| 18 | 19 | console.error('Error', err.message); |
| 19 | 20 | }) |
| 20 | 21 | .pipe(gulp.dest('.')) |
| 21 | 22 | .pipe(connect.reload()); |
| 22 | 23 | }); |
| 23 | 24 | |
| 24 | -gulp.task('watch', function () { | |
| 25 | +gulp.task('watch', function() { | |
| 25 | 26 | gulp.watch('./sass/**/*.sass', ['sass']); |
| 26 | 27 | }); |
| 27 | 28 | |
| 28 | 29 | gulp.task('connect', function() { |
| 29 | 30 | connect.server({ |
| 30 | - port: 8080, | |
| 31 | + port: 3000, | |
| 31 | 32 | root: [__dirname], |
| 32 | 33 | livereload: true |
| 33 | 34 | }); |
| 34 | 35 | }); |
| 35 | 36 | |
| 36 | -gulp.task('default', ['sass','connect','watch']); | |
| 37 | +gulp.task('connect_dist', ['clean', 'copyResources', 'sass', 'compileJS', 'htmlReplace'], function() { | |
| 38 | + connect.server({ | |
| 39 | + port: 3000, | |
| 40 | + root: ['./dist'], | |
| 41 | + livereload: false | |
| 42 | + }); | |
| 43 | +}); | |
| 44 | + | |
| 45 | + | |
| 46 | +gulp.task('default', ['sass', 'connect', 'watch']); | |
| 47 | + | |
| 48 | +//var htmlusemin = require('gulp-usemin-html'); | |
| 49 | +var useRef = require('gulp-useref'); | |
| 50 | +var minifyCss = require('gulp-minify-css'); | |
| 51 | +var rev = require('gulp-rev'); | |
| 52 | +var revReplace = require('gulp-rev-replace'); | |
| 53 | +var uglify = require('gulp-uglify'); | |
| 54 | +var gulpif = require('gulp-if'); | |
| 55 | +var filter = require('gulp-filter'); | |
| 56 | +var sourcemaps = require('gulp-sourcemaps'); | |
| 57 | +var requirejsOptimize = require('gulp-requirejs-optimize'); | |
| 58 | +var concat = require('gulp-concat'); | |
| 59 | +var copy = require('gulp-copy'); | |
| 60 | +var add = require("gulp-add"); | |
| 61 | + | |
| 62 | +gulp.task('copyResources', function(){ | |
| 63 | + gulp.src(["./*.html", "style.css", "./fonts/**/*.*", "./favicon.ico", "./images/**/*.*"]) | |
| 64 | + .pipe(copy('dist/')); | |
| 65 | +}); | |
| 66 | + | |
| 67 | + | |
| 68 | +gulp.task('compileJS', function() { | |
| 69 | + var mainInit = | |
| 70 | + "require.config({ paths: { \"main\": \"main-bundled\" }});require([\"main\"]);"; | |
| 71 | + return gulp.src('js/main.js') | |
| 72 | + //.pipe(sourcemaps.init()) | |
| 73 | + .pipe(requirejsOptimize({ | |
| 74 | + baseUrl: 'js', | |
| 75 | + name: 'main', | |
| 76 | + //generateSourceMaps: true, | |
| 77 | + optimize: "none", | |
| 78 | + preserveLicenseComments: false, | |
| 79 | + findNestedDependencies: true, | |
| 80 | + mainConfigFile: 'js/main.js', | |
| 81 | + paths: { | |
| 82 | + requireLib: "require", | |
| 83 | + jquery: 'jquery-2.1.3.min', | |
| 84 | + jquery_xdomainrequest: 'jquery.xdomainrequest.min', | |
| 85 | + jquery_ui: 'jquery-ui-1.11.4.custom/jquery-ui.min', | |
| 86 | + jquery_cookie: 'jquery.cookie', | |
| 87 | + jquery_timeago: 'jquery.timeago', | |
| 88 | + jquery_timeago_pt: 'jquery.timeago.pt-br', | |
| 89 | + jquery_simplePagination: 'jquery.simplePagination', | |
| 90 | + jquery_equalHeights: 'jquery.equalHeights', | |
| 91 | + jquery_footable: 'footable', | |
| 92 | + handlebars: 'handlebars-v3.0.1', | |
| 93 | + handlebars_helpers: 'handlebars-helpers', | |
| 94 | + jquery_maxlength: 'jquery.maxlength.min', | |
| 95 | + slick: 'slick.min', | |
| 96 | + fastclick: 'fastclick.min', | |
| 97 | + layout: 'layout', | |
| 98 | + main: 'main', | |
| 99 | + proposal_app: 'proposal-app' | |
| 100 | + }, | |
| 101 | + shim: { | |
| 102 | + 'handlebars':{ | |
| 103 | + deps: ['jquery'], | |
| 104 | + exports: 'Handlebars' | |
| 105 | + }, | |
| 106 | + 'jquery_xdomainrequest': { | |
| 107 | + deps: ['jquery'] | |
| 108 | + }, | |
| 109 | + 'jquery_cookie': { | |
| 110 | + deps: ['jquery'] | |
| 111 | + }, | |
| 112 | + 'jquery_timeago': { | |
| 113 | + deps: ['jquery'] | |
| 114 | + }, | |
| 115 | + 'jquery_timeago_pt': { | |
| 116 | + deps: ['jquery_timeago'] | |
| 117 | + }, | |
| 118 | + 'jquery_simplePagination': { | |
| 119 | + deps: ['jquery'] | |
| 120 | + }, | |
| 121 | + 'jquery_equalHeights': { | |
| 122 | + deps: ['jquery'] | |
| 123 | + }, | |
| 124 | + 'footable': { | |
| 125 | + deps: ['jquery'] | |
| 126 | + }, | |
| 127 | + 'jquery_ui': { | |
| 128 | + deps: ['jquery'] | |
| 129 | + }, | |
| 130 | + 'layout': { | |
| 131 | + deps: ['jquery'] | |
| 132 | + }, | |
| 133 | + 'jquery_maxlength': { | |
| 134 | + deps: ['jquery'] | |
| 135 | + }, | |
| 136 | + 'slick': { | |
| 137 | + deps: ['jquery'] | |
| 138 | + }, | |
| 139 | + 'fastclick': { | |
| 140 | + deps: ['jquery'] | |
| 141 | + }, | |
| 142 | + 'handlebars_helpers':{ | |
| 143 | + deps: ['handlebars'] | |
| 144 | + }, | |
| 145 | + 'proposal_app' :{ | |
| 146 | + deps: ['jquery'], | |
| 147 | + exports: 'ProposalApp' | |
| 148 | + } | |
| 149 | + }, | |
| 150 | + include: ["requireLib"], | |
| 151 | + out: "dist/main.min.js" | |
| 152 | + }).on('error', function(error) { | |
| 153 | + console.log(error); | |
| 154 | + })) | |
| 155 | + .pipe(add('dist/main-init.js', mainInit)) | |
| 156 | + .pipe(concat('dist/main-bundled.js')) | |
| 157 | + //.pipe(sourcemaps.write('./')) | |
| 158 | + .pipe(gulp.dest('./')); | |
| 159 | +}); | |
| 160 | + | |
| 161 | + | |
| 162 | +gulp.task('htmlReplace', ['clean', 'sass', 'copyResources', 'compileJS'],function() { | |
| 163 | + var assets; | |
| 164 | + var jsFilter = filter("./dist/main-bundled.js"); | |
| 165 | + var cssFilter = filter("dist/*.css"); | |
| 166 | + return gulp.src('dist/index.html') | |
| 167 | + .pipe(assets = useRef.assets()) | |
| 168 | + .pipe(sourcemaps.init()) | |
| 169 | + .pipe(rev()) | |
| 170 | + .pipe(gulpif('*.js', uglify())) | |
| 171 | + .pipe(assets.restore()) | |
| 172 | + .pipe(useRef()) | |
| 173 | + .pipe(revReplace()) | |
| 174 | + .pipe(gulpif('*.css', minifyCss({ | |
| 175 | + sourceMap: true | |
| 176 | + }))) | |
| 177 | + | |
| 178 | + .pipe(assets.restore()) | |
| 179 | + .pipe(useRef()) | |
| 180 | + .pipe(revReplace()) | |
| 181 | + .pipe(sourcemaps.write('./')) | |
| 182 | + .pipe(assets.restore()) | |
| 183 | + .pipe(gulp.dest('dist/')); | |
| 184 | +}); | |
| 185 | + | |
| 186 | +var del = require('del'); | |
| 187 | + | |
| 188 | +gulp.task('clean', function(cb) { | |
| 189 | + del([ | |
| 190 | + 'dist/*.*' | |
| 191 | + ], cb); | |
| 192 | +}); | |
| 193 | + | |
| 194 | +gulp.task('build', ['clean', 'copyResources', 'sass', 'compileJS', 'htmlReplace']); | ... | ... |
index.html
| ... | ... | @@ -10,7 +10,9 @@ |
| 10 | 10 | |
| 11 | 11 | <link rel="icon" type="image/x-icon" href="data:image/png;base64,iVBORw0KGgo="> |
| 12 | 12 | |
| 13 | - <link rel="stylesheet" href="style.css"> | |
| 13 | + <!-- build:css style.min.css --> | |
| 14 | + <link rel="stylesheet" href="style.css"/> | |
| 15 | + <!-- endbuild --> | |
| 14 | 16 | |
| 15 | 17 | <script type="text/javascript"> |
| 16 | 18 | /** |
| ... | ... | @@ -631,9 +633,13 @@ |
| 631 | 633 | <a href="#/artigo/107880">Termos de uso</a> |
| 632 | 634 | </div> |
| 633 | 635 | |
| 634 | - <script type="text/javascript"> | |
| 635 | - loadRequireJS(); | |
| 636 | - </script> | |
| 636 | + <!-- build:remove --> | |
| 637 | + <script type="text/javascript" src="js/require.js" data-main="js/requirejs-config.js"></script> | |
| 638 | + <!-- endbuild --> | |
| 639 | + | |
| 640 | + <!-- build:js main-bundled.min.js --> | |
| 641 | + <script type="text/javascript" src="main-bundled.js"></script> | |
| 642 | + <!-- endbuild --> | |
| 637 | 643 | |
| 638 | 644 | <script src="http://captcha2.servicoscorporativos.serpro.gov.br/js/captcha.serpro.gov.br.js"></script> |
| 639 | 645 | ... | ... |
js/jquery.timeago.pt-br.js
| 1 | -// Brazilian Portuguese | |
| 2 | -jQuery.timeago.settings.strings = { | |
| 3 | - prefixAgo: "há", | |
| 4 | - prefixFromNow: "em", | |
| 5 | - suffixAgo: null, | |
| 6 | - suffixFromNow: null, | |
| 7 | - seconds: "alguns segundos", | |
| 8 | - minute: "um minuto", | |
| 9 | - minutes: "%d minutos", | |
| 10 | - hour: "uma hora", | |
| 11 | - hours: "%d horas", | |
| 12 | - day: "um dia", | |
| 13 | - days: "%d dias", | |
| 14 | - month: "um mês", | |
| 15 | - months: "%d meses", | |
| 16 | - year: "um ano", | |
| 17 | - years: "%d anos" | |
| 18 | -}; | |
| 1 | +define(['jquery'], function(jQuery){ | |
| 2 | + // Brazilian Portuguese | |
| 3 | + jQuery.timeago.settings.strings = { | |
| 4 | + prefixAgo: "há", | |
| 5 | + prefixFromNow: "em", | |
| 6 | + suffixAgo: null, | |
| 7 | + suffixFromNow: null, | |
| 8 | + seconds: "alguns segundos", | |
| 9 | + minute: "um minuto", | |
| 10 | + minutes: "%d minutos", | |
| 11 | + hour: "uma hora", | |
| 12 | + hours: "%d horas", | |
| 13 | + day: "um dia", | |
| 14 | + days: "%d dias", | |
| 15 | + month: "um mês", | |
| 16 | + months: "%d meses", | |
| 17 | + year: "um ano", | |
| 18 | + years: "%d anos" | |
| 19 | + }; | |
| 20 | + | |
| 21 | +}); | ... | ... |
js/main.js
| 1 | 1 | /* global define */ |
| 2 | -define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers', 'piwik'], function($, Handlebars, FastClick, ProposalApp){ | |
| 3 | - // 'use strict'; | |
| 4 | - | |
| 5 | - // The template code | |
| 6 | - var templateSource = $('#proposal-template').html(); | |
| 7 | - | |
| 8 | - // compile the template | |
| 9 | - var template = Handlebars.compile(templateSource); | |
| 10 | - var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); | |
| 11 | - var loginTemplate = Handlebars.compile(document.getElementById('login-template').innerHTML); | |
| 12 | - var resultsTemplate = Handlebars.compile(document.getElementById('results-template').innerHTML); | |
| 13 | - var articleTemplate = Handlebars.compile(document.getElementById('article-template').innerHTML); | |
| 14 | - var calendarTemplate = Handlebars.compile(document.getElementById('calendar-template').innerHTML); | |
| 15 | - | |
| 16 | - // The div/container that we are going to display the results in | |
| 17 | - var resultsPlaceholder = document.getElementById('proposal-result'); | |
| 18 | - | |
| 19 | - var logged_in = false; | |
| 20 | - | |
| 21 | - var loginButton; | |
| 22 | - | |
| 23 | - var lastHash = window.location.hash; | |
| 24 | - | |
| 25 | - var host = 'http://login.dialoga.gov.br'; | |
| 26 | - var serpro_captcha_clienteId = 'fdbcdc7a0b754ee7ae9d865fda740f17'; | |
| 27 | - var dialoga_community = 19195; | |
| 28 | - var proposal_discussion = '103358'; //participa | |
| 29 | - var cat_saude = 180; | |
| 30 | - // var cat_seguranca_publica = 182; | |
| 31 | - // var cat_educacao = 181; | |
| 32 | - // var cat_reducao_da_pobreza = 183; | |
| 33 | - var recaptchaSiteKey = '6LcLPAcTAAAAAKsd0bxY_TArhD_A7OL19SRCW7_i'; | |
| 34 | - | |
| 35 | - // There are two modes for development | |
| 36 | - // 1: Remote API | |
| 37 | - // 2: Local API with proposal database | |
| 38 | - // For (1) use port 3000 -> rails s | |
| 39 | - // For (2) use port 3001 -> rails s -p 3001 | |
| 40 | - // | |
| 41 | - // For (2) set at /etc/hosts: | |
| 42 | - // | |
| 43 | - //127.0.0.1 participa.br | |
| 44 | - //127.0.0.1 dialoga.gov.br | |
| 45 | - //127.0.0.1 login.dialoga.gov.br | |
| 46 | - //127.0.0.1 noosfero.com | |
| 47 | - //Detects for localhost settings | |
| 48 | - var patt = new RegExp(':300[0-2]/'); | |
| 49 | - var localDevelopment = false; | |
| 50 | - | |
| 51 | - if(patt.test(window.location.href)){ | |
| 52 | - localDevelopment = true; | |
| 53 | - patt = new RegExp(':3000/'); | |
| 2 | +define( | |
| 3 | + [ | |
| 4 | + 'jquery', 'handlebars', 'fastclick', | |
| 5 | + 'proposal_app', 'handlebars_helpers', | |
| 6 | + 'piwik', 'jquery_maxlength', 'jquery_xdomainrequest', | |
| 7 | + 'jquery_footable', 'jquery_simplePagination', | |
| 8 | + 'jquery_equalHeights', 'jquery_ui', | |
| 9 | + 'jquery_timeago', 'jquery_timeago_pt' | |
| 10 | + ], | |
| 11 | + function($, Handlebars, FastClick, ProposalApp){ | |
| 12 | + // 'use strict'; | |
| 13 | + | |
| 14 | + // The template code | |
| 15 | + var templateSource = $('#proposal-template').html(); | |
| 16 | + | |
| 17 | + // compile the template | |
| 18 | + var template = Handlebars.compile(templateSource); | |
| 19 | + var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); | |
| 20 | + var loginTemplate = Handlebars.compile(document.getElementById('login-template').innerHTML); | |
| 21 | + var resultsTemplate = Handlebars.compile(document.getElementById('results-template').innerHTML); | |
| 22 | + var articleTemplate = Handlebars.compile(document.getElementById('article-template').innerHTML); | |
| 23 | + var calendarTemplate = Handlebars.compile(document.getElementById('calendar-template').innerHTML); | |
| 24 | + | |
| 25 | + // The div/container that we are going to display the results in | |
| 26 | + var resultsPlaceholder = document.getElementById('proposal-result'); | |
| 27 | + | |
| 28 | + var logged_in = false; | |
| 29 | + | |
| 30 | + var loginButton; | |
| 31 | + | |
| 32 | + var lastHash = window.location.hash; | |
| 33 | + | |
| 34 | + var host = 'http://login.dialoga.gov.br'; | |
| 35 | + var serpro_captcha_clienteId = 'fdbcdc7a0b754ee7ae9d865fda740f17'; | |
| 36 | + var dialoga_community = 19195; | |
| 37 | + var proposal_discussion = '103358'; //participa | |
| 38 | + var cat_saude = 180; | |
| 39 | + // var cat_seguranca_publica = 182; | |
| 40 | + // var cat_educacao = 181; | |
| 41 | + // var cat_reducao_da_pobreza = 183; | |
| 42 | + var recaptchaSiteKey = '6LcLPAcTAAAAAKsd0bxY_TArhD_A7OL19SRCW7_i'; | |
| 43 | + | |
| 44 | + // There are two modes for development | |
| 45 | + // 1: Remote API | |
| 46 | + // 2: Local API with proposal database | |
| 47 | + // For (1) use port 3000 -> rails s | |
| 48 | + // For (2) use port 3001 -> rails s -p 3001 | |
| 49 | + // | |
| 50 | + // For (2) set at /etc/hosts: | |
| 51 | + // | |
| 52 | + //127.0.0.1 participa.br | |
| 53 | + //127.0.0.1 dialoga.gov.br | |
| 54 | + //127.0.0.1 login.dialoga.gov.br | |
| 55 | + //127.0.0.1 noosfero.com | |
| 56 | + //Detects for localhost settings | |
| 57 | + var patt = new RegExp(':300[0-2]/'); | |
| 58 | + var localDevelopment = false; | |
| 54 | 59 | |
| 55 | 60 | if(patt.test(window.location.href)){ |
| 56 | - host = 'http://login.dialoga.gov.br'; | |
| 57 | - }else if (new RegExp(':3001/').test(window.location.href)){ | |
| 58 | - host = 'http://noosfero.com:3001'; | |
| 59 | - // dialoga_community = 104; | |
| 60 | - // proposal_discussion = '413'; //Eugênio | |
| 61 | - // proposal_discussion = '392'; //Evandro | |
| 62 | - // cat_saude = 23; | |
| 63 | - recaptchaSiteKey = '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-'; //http://noosfero.com/ | |
| 64 | - } else { //ABNER | |
| 65 | - host = 'http://local.abner.com:3002'; | |
| 66 | - dialoga_community = 105; | |
| 67 | - proposal_discussion = '392'; //Evandro | |
| 68 | - recaptchaSiteKey = '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-'; //http://noosfero.com/ | |
| 69 | - cat_saude = 23; | |
| 61 | + localDevelopment = true; | |
| 62 | + patt = new RegExp(':3000/'); | |
| 63 | + | |
| 64 | + if(patt.test(window.location.href)){ | |
| 65 | + host = 'http://login.dialoga.gov.br'; | |
| 66 | + }else if (new RegExp(':3001/').test(window.location.href)){ | |
| 67 | + host = 'http://noosfero.com:3001'; | |
| 68 | + // dialoga_community = 104; | |
| 69 | + // proposal_discussion = '413'; //Eugênio | |
| 70 | + // proposal_discussion = '392'; //Evandro | |
| 71 | + // cat_saude = 23; | |
| 72 | + recaptchaSiteKey = '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-'; //http://noosfero.com/ | |
| 73 | + } else { //ABNER | |
| 74 | + host = 'http://local.abner.com:3002'; | |
| 75 | + dialoga_community = 105; | |
| 76 | + proposal_discussion = '392'; //Evandro | |
| 77 | + recaptchaSiteKey = '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-'; //http://noosfero.com/ | |
| 78 | + cat_saude = 23; | |
| 79 | + } | |
| 70 | 80 | } |
| 71 | - } | |
| 72 | - | |
| 73 | 81 | |
| 74 | - var BARRA_ADDED = false; | |
| 75 | - var HIDE_BARRA_DO_GOVERNO = false; | |
| 76 | 82 | |
| 77 | - var Main; | |
| 78 | - window.Main = Main = (function(){ | |
| 83 | + var BARRA_ADDED = false; | |
| 84 | + var HIDE_BARRA_DO_GOVERNO = false; | |
| 79 | 85 | |
| 80 | - var API = { | |
| 81 | - articles: '', | |
| 82 | - proposals: '/api/v1/articles/{topic_id}/children', | |
| 86 | + var Main; | |
| 87 | + window.Main = Main = (function(){ | |
| 83 | 88 | |
| 84 | - }; | |
| 89 | + var API = { | |
| 90 | + articles: '', | |
| 91 | + proposals: '/api/v1/articles/{topic_id}/children', | |
| 85 | 92 | |
| 86 | - API.getProposalsURL = function (topicId){ | |
| 87 | - return host + replace(API.proposals, '{topic_id}', topicId); | |
| 88 | - }; | |
| 89 | - | |
| 90 | - function replace(str, pattern, value){ | |
| 91 | - return str.replace(new RegExp(pattern, 'g'), value); | |
| 92 | - } | |
| 93 | + }; | |
| 93 | 94 | |
| 94 | - function fillSignupForm(signupForm, user) { | |
| 95 | - signupForm.find('#signup-user_email').val(user.email); | |
| 96 | - signupForm.find('#signup-user_email').attr('disabled', true); | |
| 97 | - signupForm.find('#signup-user_name').val(user.login); | |
| 98 | - signupForm.find('#user_oauth_signup_token').val(user.signup_token); | |
| 99 | - signupForm.find('#user_oauth_providers').val(user.oauth_providers); | |
| 100 | - signupForm.find('div.password').hide(); | |
| 101 | - signupForm.find('div.password-confirmation').hide(); | |
| 102 | - signupForm.find('#signup-user_password').attr('required', false); | |
| 103 | - signupForm.find('#user_password_confirmation').attr('required', false); | |
| 104 | - }; | |
| 105 | - | |
| 106 | - return { | |
| 107 | - private_token: null, | |
| 108 | - getProposalId: function() { | |
| 109 | - var regexProposals = /\d.*\/propostas\/*.*/; | |
| 110 | - var proposalId = 0; | |
| 111 | - | |
| 112 | - var hasProposal = regexProposals.test(location.hash); | |
| 113 | - if( hasProposal ){ | |
| 114 | - var regexExtractProposal = /propostas\/*.*/; | |
| 115 | - proposalId = regexExtractProposal.exec(location.hash)[0].split('/')[1]; | |
| 95 | + API.getProposalsURL = function (topicId){ | |
| 96 | + return host + replace(API.proposals, '{topic_id}', topicId); | |
| 97 | + }; | |
| 116 | 98 | |
| 117 | - } | |
| 99 | + function replace(str, pattern, value){ | |
| 100 | + return str.replace(new RegExp(pattern, 'g'), value); | |
| 101 | + } | |
| 118 | 102 | |
| 119 | - return proposalId; | |
| 120 | - }, | |
| 121 | - loadRandomProposal: function (topic_id, force) { | |
| 122 | - /*var private_token = window.Main.private_token;*/ | |
| 123 | - var $noProposals = $('.no-proposals'); | |
| 124 | - var $loading = $('.loading'); | |
| 125 | - var $randomProposal = $('.random-proposal'); | |
| 126 | - var $body = $(document.body); | |
| 127 | - var contextMain = this; | |
| 103 | + function fillSignupForm(signupForm, user) { | |
| 104 | + signupForm.find('#signup-user_email').val(user.email); | |
| 105 | + signupForm.find('#signup-user_email').attr('disabled', true); | |
| 106 | + signupForm.find('#signup-user_name').val(user.login); | |
| 107 | + signupForm.find('#user_oauth_signup_token').val(user.signup_token); | |
| 108 | + signupForm.find('#user_oauth_providers').val(user.oauth_providers); | |
| 109 | + signupForm.find('div.password').hide(); | |
| 110 | + signupForm.find('div.password-confirmation').hide(); | |
| 111 | + signupForm.find('#signup-user_password').attr('required', false); | |
| 112 | + signupForm.find('#user_password_confirmation').attr('required', false); | |
| 113 | + }; | |
| 128 | 114 | |
| 129 | - // reset view | |
| 130 | - $noProposals.hide(); | |
| 131 | - $loading.show(); | |
| 132 | - $randomProposal.html(''); | |
| 115 | + return { | |
| 116 | + private_token: null, | |
| 117 | + getProposalId: function() { | |
| 118 | + var regexProposals = /\d.*\/propostas\/*.*/; | |
| 119 | + var proposalId = 0; | |
| 133 | 120 | |
| 134 | - var url = API.getProposalsURL(topic_id); | |
| 135 | - var childId = this.getProposalId(); | |
| 121 | + var hasProposal = regexProposals.test(location.hash); | |
| 122 | + if( hasProposal ){ | |
| 123 | + var regexExtractProposal = /propostas\/*.*/; | |
| 124 | + proposalId = regexExtractProposal.exec(location.hash)[0].split('/')[1]; | |
| 136 | 125 | |
| 137 | - if(childId !== 0 && !force){ | |
| 138 | - url += '/' + childId; | |
| 139 | 126 | } |
| 140 | - //url += '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,slug,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | |
| 141 | - url += '?limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,slug,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | |
| 142 | - | |
| 143 | - $.getJSON(url).done(function( data ) { | |
| 144 | - $loading.hide(); | |
| 145 | - $('.support-proposal .alert').hide(); | |
| 146 | 127 | |
| 147 | - data.articles = data.articles || [data.article]; | |
| 148 | - if(data.articles.length === 0) { | |
| 149 | - $noProposals.show(); | |
| 150 | - return; | |
| 128 | + return proposalId; | |
| 129 | + }, | |
| 130 | + loadRandomProposal: function (topic_id, force) { | |
| 131 | + /*var private_token = window.Main.private_token;*/ | |
| 132 | + var $noProposals = $('.no-proposals'); | |
| 133 | + var $loading = $('.loading'); | |
| 134 | + var $randomProposal = $('.random-proposal'); | |
| 135 | + var $body = $(document.body); | |
| 136 | + var contextMain = this; | |
| 137 | + | |
| 138 | + // reset view | |
| 139 | + $noProposals.hide(); | |
| 140 | + $loading.show(); | |
| 141 | + $randomProposal.html(''); | |
| 142 | + | |
| 143 | + var url = API.getProposalsURL(topic_id); | |
| 144 | + var childId = this.getProposalId(); | |
| 145 | + | |
| 146 | + if(childId !== 0 && !force){ | |
| 147 | + url += '/' + childId; | |
| 151 | 148 | } |
| 149 | + //url += '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,slug,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | |
| 150 | + url += '?limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,slug,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | |
| 152 | 151 | |
| 153 | - var article = data.articles[0]; | |
| 154 | - var parentTitle = $('#proposal-item-'+topic_id).find('.proposal-header .title').text(); | |
| 155 | - article.parent = {id: topic_id, title: parentTitle}; | |
| 156 | - $randomProposal.html(supportProposalTemplate(article)); | |
| 157 | - $body.off('click', '.vote-actions .skip'); | |
| 158 | - $body.on('click', '.vote-actions .skip', function(e) { | |
| 159 | - e.preventDefault(); | |
| 160 | - contextMain.loadRandomProposal(topic_id, true); | |
| 161 | - }); | |
| 162 | - $body.off('click', '.vote-actions .vote-action'); | |
| 163 | - $body.on('click', '.vote-actions .vote-action', function(e) { | |
| 164 | - e.preventDefault(); | |
| 165 | - | |
| 166 | - //Helps to prevent more than one vote per proposal | |
| 167 | - var $button = $(this); | |
| 168 | - var $proposal = $button.closest('.random-proposal'); | |
| 152 | + $.getJSON(url).done(function( data ) { | |
| 153 | + $loading.hide(); | |
| 154 | + $('.support-proposal .alert').hide(); | |
| 169 | 155 | |
| 170 | - if(!logged_in) { | |
| 171 | - $(this).closest('.require-login-container').find('.button-send a').click(); | |
| 156 | + data.articles = data.articles || [data.article]; | |
| 157 | + if(data.articles.length === 0) { | |
| 158 | + $noProposals.show(); | |
| 172 | 159 | return; |
| 173 | 160 | } |
| 174 | 161 | |
| 175 | - if(ProposalApp.hasProposalbeenVoted(article.id)){ | |
| 176 | - // console.debug("Proposta " + article.id + " já havia sido votada"); | |
| 177 | - Main.displaySuccess($button.closest('.support-proposal .section-content'), 'Seu voto já foi computado nesta proposta', 800); | |
| 162 | + var article = data.articles[0]; | |
| 163 | + var parentTitle = $('#proposal-item-'+topic_id).find('.proposal-header .title').text(); | |
| 164 | + article.parent = {id: topic_id, title: parentTitle}; | |
| 165 | + $randomProposal.html(supportProposalTemplate(article)); | |
| 166 | + $body.off('click', '.vote-actions .skip'); | |
| 167 | + $body.on('click', '.vote-actions .skip', function(e) { | |
| 168 | + e.preventDefault(); | |
| 178 | 169 | contextMain.loadRandomProposal(topic_id, true); |
| 179 | - return; | |
| 180 | - } | |
| 170 | + }); | |
| 171 | + $body.off('click', '.vote-actions .vote-action'); | |
| 172 | + $body.on('click', '.vote-actions .vote-action', function(e) { | |
| 173 | + e.preventDefault(); | |
| 174 | + | |
| 175 | + //Helps to prevent more than one vote per proposal | |
| 176 | + var $button = $(this); | |
| 177 | + var $proposal = $button.closest('.random-proposal'); | |
| 181 | 178 | |
| 182 | - $.ajax({ | |
| 183 | - type: 'post', | |
| 184 | - url: host + '/api/v1/articles/' + article.id + '/vote', | |
| 185 | - data: { | |
| 186 | - value: $(this).data('vote-value'), | |
| 187 | - private_token: Main.private_token | |
| 179 | + if(!logged_in) { | |
| 180 | + $(this).closest('.require-login-container').find('.button-send a').click(); | |
| 181 | + return; | |
| 188 | 182 | } |
| 189 | - }).done(function(data) { | |
| 190 | - if(data.vote) { | |
| 191 | - // Main.displaySuccess($button.closest('.support-proposal .section-content'), '', 800); | |
| 192 | - $proposal.find('.abstract').hide(); | |
| 193 | - $proposal.find('.vote-actions .like').hide(); | |
| 194 | - $proposal.find('.vote-actions .dislike').hide(); | |
| 195 | - // $proposal.find('.vote-actions .vote-result').hide(); | |
| 196 | - var $successPanel = $('.success-panel').clone(); | |
| 197 | - $successPanel.find('.icon').addClass('icon-proposal-sent'); | |
| 198 | - $successPanel.find('.message').html('Voto realizado com sucesso'); | |
| 199 | - $successPanel.removeClass('hide'); | |
| 200 | - $proposal.prepend($successPanel); | |
| 201 | - $successPanel.show(); | |
| 202 | - // $successPanel.css('top', Math.max(0, (($proposal.height() - $successPanel.outerHeight()) / 2) + $proposal.offset().top) + 'px'); | |
| 203 | - // $successPanel.css('left', Math.max(0, (($proposal.width() - $successPanel.outerWidth()) / 2) + $proposal.offset().left) + 'px'); | |
| 204 | - } else { | |
| 205 | - $proposal.find('.abstract').hide(); | |
| 206 | - $proposal.find('.vote-actions .like').hide(); | |
| 207 | - $proposal.find('.vote-actions .dislike').hide(); | |
| 208 | - | |
| 209 | - var $successPanel = $('.success-panel').clone(); | |
| 210 | - // $successPanel.find('.icon').addClass('icon-proposal-sent'); | |
| 211 | - $successPanel.find('.message').html('Seu voto já foi computado nesta proposta'); | |
| 212 | - $successPanel.removeClass('hide'); | |
| 213 | - $proposal.prepend($successPanel); | |
| 214 | - $successPanel.show(); | |
| 215 | - // Main.displaySuccess($button.closest('.support-proposal .section-content'), , 800); | |
| 216 | - // $successPanel.find('.message').html('Seu voto já foi computado nesta proposta'); | |
| 183 | + | |
| 184 | + if(ProposalApp.hasProposalbeenVoted(article.id)){ | |
| 185 | + // console.debug("Proposta " + article.id + " já havia sido votada"); | |
| 186 | + Main.displaySuccess($button.closest('.support-proposal .section-content'), 'Seu voto já foi computado nesta proposta', 800); | |
| 187 | + contextMain.loadRandomProposal(topic_id, true); | |
| 188 | + return; | |
| 217 | 189 | } |
| 218 | - // ProposalApp.addVotedProposal(article.id); | |
| 219 | - // contextMain.loadRandomProposal(topic_id, true); | |
| 190 | + | |
| 191 | + $.ajax({ | |
| 192 | + type: 'post', | |
| 193 | + url: host + '/api/v1/articles/' + article.id + '/vote', | |
| 194 | + data: { | |
| 195 | + value: $(this).data('vote-value'), | |
| 196 | + private_token: Main.private_token | |
| 197 | + } | |
| 198 | + }).done(function(data) { | |
| 199 | + if(data.vote) { | |
| 200 | + // Main.displaySuccess($button.closest('.support-proposal .section-content'), '', 800); | |
| 201 | + $proposal.find('.abstract').hide(); | |
| 202 | + $proposal.find('.vote-actions .like').hide(); | |
| 203 | + $proposal.find('.vote-actions .dislike').hide(); | |
| 204 | + // $proposal.find('.vote-actions .vote-result').hide(); | |
| 205 | + var $successPanel = $('.success-panel').clone(); | |
| 206 | + $successPanel.find('.icon').addClass('icon-proposal-sent'); | |
| 207 | + $successPanel.find('.message').html('Voto realizado com sucesso'); | |
| 208 | + $successPanel.removeClass('hide'); | |
| 209 | + $proposal.prepend($successPanel); | |
| 210 | + $successPanel.show(); | |
| 211 | + // $successPanel.css('top', Math.max(0, (($proposal.height() - $successPanel.outerHeight()) / 2) + $proposal.offset().top) + 'px'); | |
| 212 | + // $successPanel.css('left', Math.max(0, (($proposal.width() - $successPanel.outerWidth()) / 2) + $proposal.offset().left) + 'px'); | |
| 213 | + } else { | |
| 214 | + $proposal.find('.abstract').hide(); | |
| 215 | + $proposal.find('.vote-actions .like').hide(); | |
| 216 | + $proposal.find('.vote-actions .dislike').hide(); | |
| 217 | + | |
| 218 | + var $successPanel = $('.success-panel').clone(); | |
| 219 | + // $successPanel.find('.icon').addClass('icon-proposal-sent'); | |
| 220 | + $successPanel.find('.message').html('Seu voto já foi computado nesta proposta'); | |
| 221 | + $successPanel.removeClass('hide'); | |
| 222 | + $proposal.prepend($successPanel); | |
| 223 | + $successPanel.show(); | |
| 224 | + // Main.displaySuccess($button.closest('.support-proposal .section-content'), , 800); | |
| 225 | + // $successPanel.find('.message').html('Seu voto já foi computado nesta proposta'); | |
| 226 | + } | |
| 227 | + // ProposalApp.addVotedProposal(article.id); | |
| 228 | + // contextMain.loadRandomProposal(topic_id, true); | |
| 229 | + }); | |
| 220 | 230 | }); |
| 221 | - }); | |
| 222 | 231 | |
| 223 | - $body.off('click', '.vote-result'); | |
| 224 | - $body.on('click', '.vote-result', function(e) { | |
| 225 | - // e.preventDefault(); | |
| 232 | + $body.off('click', '.vote-result'); | |
| 233 | + $body.on('click', '.vote-result', function(e) { | |
| 234 | + // e.preventDefault(); | |
| 226 | 235 | |
| 227 | - var $this = $(this); | |
| 228 | - var $proposalDetail = $this.parents('.proposal-detail'); | |
| 229 | - var $resultsContainer = $proposalDetail.find('.results-container'); | |
| 236 | + var $this = $(this); | |
| 237 | + var $proposalDetail = $this.parents('.proposal-detail'); | |
| 238 | + var $resultsContainer = $proposalDetail.find('.results-container'); | |
| 230 | 239 | |
| 231 | - if($resultsContainer.css('display') === 'none') { | |
| 232 | - Main.loadRanking($resultsContainer, topic_id, 1); | |
| 233 | - } else { | |
| 234 | - $proposalDetail.find('.experience-proposal-container').show(); | |
| 235 | - $proposalDetail.find('.talk-proposal-container').show(); | |
| 236 | - $resultsContainer.hide(); | |
| 240 | + if($resultsContainer.css('display') === 'none') { | |
| 241 | + Main.loadRanking($resultsContainer, topic_id, 1); | |
| 242 | + } else { | |
| 243 | + $proposalDetail.find('.experience-proposal-container').show(); | |
| 244 | + $proposalDetail.find('.talk-proposal-container').show(); | |
| 245 | + $resultsContainer.hide(); | |
| 237 | 246 | |
| 238 | - // remove '/resultados' from URL | |
| 239 | - window.location.hash = window.location.hash.split('/resultados')[0]; | |
| 240 | - e.preventDefault(); | |
| 241 | - } | |
| 247 | + // remove '/resultados' from URL | |
| 248 | + window.location.hash = window.location.hash.split('/resultados')[0]; | |
| 249 | + e.preventDefault(); | |
| 250 | + } | |
| 251 | + }); | |
| 252 | + | |
| 253 | + }).fail(function(){ | |
| 254 | + $loading.hide(); | |
| 255 | + $('.support-proposal .alert').show(); | |
| 242 | 256 | }); |
| 257 | + }, | |
| 258 | + loadRanking: function($resultsContainer, topic_id, page) { | |
| 259 | + $resultsContainer.find('.loading').show(); | |
| 260 | + $resultsContainer.find('.results-content').hide(); | |
| 261 | + | |
| 262 | + var per_page = 10; | |
| 263 | + var parentId = topic_id; | |
| 264 | + //var url = host + '/api/v1/proposals_discussion_plugin/' + topic_id + '/ranking' + '?private_token=' + Main.private_token + '&per_page='+per_page+'&page='+page; | |
| 265 | + var url = host + '/api/v1/proposals_discussion_plugin/' + topic_id + '/ranking' + '?per_page='+per_page+'&page='+page; | |
| 266 | + $.getJSON(url).done(function( data, stats, xhr ) { | |
| 267 | + data.pagination = { | |
| 268 | + total: parseInt(xhr.getResponseHeader('Total')), | |
| 269 | + per_page: parseInt(xhr.getResponseHeader('Per-Page')), | |
| 270 | + page: page, | |
| 271 | + }; | |
| 272 | + | |
| 273 | + // hack: add more info to result table | |
| 274 | + var $header = $resultsContainer.closest('.categories').find('.proposal-header'); | |
| 275 | + data.title = $header.find('.title').text(); | |
| 276 | + data.topic_id = $header.find('a').attr('href').match(/\d+/)[0]; | |
| 277 | + | |
| 278 | + $resultsContainer.html(resultsTemplate(data)); | |
| 279 | + $resultsContainer.find('.loading').hide(); | |
| 280 | + $resultsContainer.find('.results-content').show(); | |
| 281 | + $resultsContainer.find('.timeago').timeago(); | |
| 282 | + $resultsContainer.show(); | |
| 283 | + $resultsContainer.find('.footable').footable(); // must be called on visible elements. | |
| 284 | + | |
| 285 | + | |
| 286 | + if(data.pagination.total > data.pagination.per_page) { | |
| 287 | + $resultsContainer.find('.paging').pagination({ | |
| 288 | + items: data.pagination.total, | |
| 289 | + itemsOnPage: data.pagination.per_page, | |
| 290 | + currentPage: data.pagination.page, | |
| 291 | + prevText: '«', | |
| 292 | + nextText: '»', | |
| 293 | + cssStyle: 'compact-theme', | |
| 294 | + onPageClick: function(page, e) { | |
| 295 | + Main.loadRanking($resultsContainer, topic_id, page); | |
| 296 | + e.preventDefault(); | |
| 297 | + } | |
| 298 | + }); | |
| 299 | + } | |
| 300 | + $resultsContainer.find('.abstract-text .truncated').click(function() { | |
| 301 | + $(this).toggleClass('truncated'); | |
| 302 | + }); | |
| 303 | + | |
| 304 | + var scrollTop = $(document).height(); | |
| 305 | + var proposalOffset = $resultsContainer.offset(); | |
| 306 | + if(proposalOffset){ | |
| 307 | + scrollTop = proposalOffset.top; | |
| 308 | + } | |
| 243 | 309 | |
| 244 | - }).fail(function(){ | |
| 245 | - $loading.hide(); | |
| 246 | - $('.support-proposal .alert').show(); | |
| 310 | + // scroll to the end | |
| 311 | + $('html, body').animate({scrollTop: scrollTop }, 'fast'); | |
| 247 | 312 | }); |
| 248 | - }, | |
| 249 | - loadRanking: function($resultsContainer, topic_id, page) { | |
| 250 | - $resultsContainer.find('.loading').show(); | |
| 251 | - $resultsContainer.find('.results-content').hide(); | |
| 252 | - | |
| 253 | - var per_page = 10; | |
| 254 | - var parentId = topic_id; | |
| 255 | - //var url = host + '/api/v1/proposals_discussion_plugin/' + topic_id + '/ranking' + '?private_token=' + Main.private_token + '&per_page='+per_page+'&page='+page; | |
| 256 | - var url = host + '/api/v1/proposals_discussion_plugin/' + topic_id + '/ranking' + '?per_page='+per_page+'&page='+page; | |
| 257 | - $.getJSON(url).done(function( data, stats, xhr ) { | |
| 258 | - data.pagination = { | |
| 259 | - total: parseInt(xhr.getResponseHeader('Total')), | |
| 260 | - per_page: parseInt(xhr.getResponseHeader('Per-Page')), | |
| 261 | - page: page, | |
| 262 | - }; | |
| 263 | - | |
| 264 | - // hack: add more info to result table | |
| 265 | - var $header = $resultsContainer.closest('.categories').find('.proposal-header'); | |
| 266 | - data.title = $header.find('.title').text(); | |
| 267 | - data.topic_id = $header.find('a').attr('href').match(/\d+/)[0]; | |
| 268 | - | |
| 269 | - $resultsContainer.html(resultsTemplate(data)); | |
| 270 | - $resultsContainer.find('.loading').hide(); | |
| 271 | - $resultsContainer.find('.results-content').show(); | |
| 272 | - $resultsContainer.find('.timeago').timeago(); | |
| 273 | - $resultsContainer.show(); | |
| 274 | - $resultsContainer.find('.footable').footable(); // must be called on visible elements. | |
| 275 | - | |
| 276 | - | |
| 277 | - if(data.pagination.total > data.pagination.per_page) { | |
| 278 | - $resultsContainer.find('.paging').pagination({ | |
| 279 | - items: data.pagination.total, | |
| 280 | - itemsOnPage: data.pagination.per_page, | |
| 281 | - currentPage: data.pagination.page, | |
| 282 | - prevText: '«', | |
| 283 | - nextText: '»', | |
| 284 | - cssStyle: 'compact-theme', | |
| 285 | - onPageClick: function(page, e) { | |
| 286 | - Main.loadRanking($resultsContainer, topic_id, page); | |
| 287 | - e.preventDefault(); | |
| 288 | - } | |
| 289 | - }); | |
| 313 | + $('.experience-proposal-container').hide(); | |
| 314 | + $('.talk-proposal-container').hide(); | |
| 315 | + }, | |
| 316 | + loginCallback: function(loggedIn, token, user) { | |
| 317 | + logged_in = loggedIn; | |
| 318 | + var requireLoginContainer; | |
| 319 | + $('.login .message').text(''); | |
| 320 | + if(loginButton){ | |
| 321 | + requireLoginContainer = loginButton.closest('.require-login-container'); | |
| 290 | 322 | } |
| 291 | - $resultsContainer.find('.abstract-text .truncated').click(function() { | |
| 292 | - $(this).toggleClass('truncated'); | |
| 293 | - }); | |
| 294 | 323 | |
| 295 | - var scrollTop = $(document).height(); | |
| 296 | - var proposalOffset = $resultsContainer.offset(); | |
| 297 | - if(proposalOffset){ | |
| 298 | - scrollTop = proposalOffset.top; | |
| 324 | + if(user && !Main.getUser()) { | |
| 325 | + Main.setUser(user); | |
| 299 | 326 | } |
| 300 | 327 | |
| 301 | - // scroll to the end | |
| 302 | - $('html, body').animate({scrollTop: scrollTop }, 'fast'); | |
| 303 | - }); | |
| 304 | - $('.experience-proposal-container').hide(); | |
| 305 | - $('.talk-proposal-container').hide(); | |
| 306 | - }, | |
| 307 | - loginCallback: function(loggedIn, token, user) { | |
| 308 | - logged_in = loggedIn; | |
| 309 | - var requireLoginContainer; | |
| 310 | - $('.login .message').text(''); | |
| 311 | - if(loginButton){ | |
| 312 | - requireLoginContainer = loginButton.closest('.require-login-container'); | |
| 313 | - } | |
| 314 | - | |
| 315 | - if(user && !Main.getUser()) { | |
| 316 | - Main.setUser(user); | |
| 317 | - } | |
| 318 | - | |
| 319 | - if(logged_in) { | |
| 320 | - Main.showLogout(); | |
| 321 | - if(token){ | |
| 322 | - Main.private_token = token; | |
| 323 | - } | |
| 328 | + if(logged_in) { | |
| 329 | + Main.showLogout(); | |
| 330 | + if(token){ | |
| 331 | + Main.private_token = token; | |
| 332 | + } | |
| 324 | 333 | |
| 325 | - $.cookie('_dialoga_session', Main.private_token); | |
| 334 | + $.cookie('_dialoga_session', Main.private_token); | |
| 326 | 335 | |
| 327 | - if(requireLoginContainer){ | |
| 328 | - // requireLoginContainer = $('.require-login-container'); | |
| 329 | - requireLoginContainer.find('.require-login').show(); | |
| 330 | - requireLoginContainer.find('.require-login .message').show(); | |
| 331 | - requireLoginContainer.find('.login-container').hide(); | |
| 336 | + if(requireLoginContainer){ | |
| 337 | + // requireLoginContainer = $('.require-login-container'); | |
| 338 | + requireLoginContainer.find('.require-login').show(); | |
| 339 | + requireLoginContainer.find('.require-login .message').show(); | |
| 340 | + requireLoginContainer.find('.login-container').hide(); | |
| 332 | 341 | |
| 333 | - $('#login-panel').hide(); | |
| 342 | + $('#login-panel').hide(); | |
| 343 | + } | |
| 344 | + } else if (user) { | |
| 345 | + // fluxo signup vindo das caixas de login dentro dos programas | |
| 346 | + if(requireLoginContainer.length > 0){ | |
| 347 | + var loginContainer = requireLoginContainer.find('.login-container'); | |
| 348 | + loginContainer.show(); | |
| 349 | + loginContainer.find('.new-user').click(); | |
| 350 | + var $signupForm = loginContainer.find('#signup-form'); | |
| 351 | + fillSignupForm($signupForm, user); | |
| 352 | + } else { //signup botão Entrar principal vindo de OAUTH | |
| 353 | + $('#login-panel').find('a.new-user').click(); | |
| 354 | + var $signupForm = $('#login-panel #signup-form'); | |
| 355 | + fillSignupForm($signupForm, user); | |
| 356 | + } | |
| 357 | + } else { | |
| 358 | + requireLoginContainer.find('.require-login').hide(); | |
| 359 | + requireLoginContainer.find('.login-container').show(); | |
| 360 | + Main.showLogin(); | |
| 334 | 361 | } |
| 335 | - } else if (user) { | |
| 336 | - // fluxo signup vindo das caixas de login dentro dos programas | |
| 337 | - if(requireLoginContainer.length > 0){ | |
| 338 | - var loginContainer = requireLoginContainer.find('.login-container'); | |
| 339 | - loginContainer.show(); | |
| 340 | - loginContainer.find('.new-user').click(); | |
| 341 | - var $signupForm = loginContainer.find('#signup-form'); | |
| 342 | - fillSignupForm($signupForm, user); | |
| 343 | - } else { //signup botão Entrar principal vindo de OAUTH | |
| 344 | - $('#login-panel').find('a.new-user').click(); | |
| 345 | - var $signupForm = $('#login-panel #signup-form'); | |
| 346 | - fillSignupForm($signupForm, user); | |
| 362 | + }, | |
| 363 | + guid: function() { | |
| 364 | + function s4() { | |
| 365 | + return Math.floor((1 + Math.random()) * 0x10000) | |
| 366 | + .toString(16) | |
| 367 | + .substring(1); | |
| 347 | 368 | } |
| 348 | - } else { | |
| 349 | - requireLoginContainer.find('.require-login').hide(); | |
| 350 | - requireLoginContainer.find('.login-container').show(); | |
| 351 | - Main.showLogin(); | |
| 352 | - } | |
| 353 | - }, | |
| 354 | - guid: function() { | |
| 355 | - function s4() { | |
| 356 | - return Math.floor((1 + Math.random()) * 0x10000) | |
| 357 | - .toString(16) | |
| 358 | - .substring(1); | |
| 359 | - } | |
| 360 | - return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | |
| 361 | - }, | |
| 362 | - display_article: function(article_id, backTo) { | |
| 363 | - //var url = host + '/api/v1/articles/' + article_id + '?private_token=' + Main.private_token; | |
| 364 | - var url = host + '/api/v1/articles/' + article_id; | |
| 365 | - $.getJSON(url).done(function( data ) { | |
| 366 | - $('#article-container .article-content').html(articleTemplate(data.article)); | |
| 367 | - $('#article-container').show(); | |
| 368 | - $('#proposal-categories').hide(); | |
| 369 | - $('#proposal-group').hide(); | |
| 370 | - $('nav').hide(); | |
| 371 | - $('#content').hide(); | |
| 372 | - $('.content').removeClass('background'); /* Remove class background*/ | |
| 373 | - $('#article-container .go-back').attr('href', backTo); | |
| 374 | - }); | |
| 375 | - }, | |
| 376 | - // inicio Eduardo | |
| 377 | - randomProposalByTheme: function(themeClasses) { | |
| 378 | - $('#proposal-group .proposal-list .proposal-item').hide(); | |
| 379 | - $.each(themeClasses, function(i, themeClass) { | |
| 380 | - var proposalsByTheme = $('#proposal-group .proposal-list .proposal-item').find('.' + themeClass); | |
| 381 | - var randomizedIndex = Math.floor(Math.random() * proposalsByTheme.length); | |
| 382 | - var proposalToShow = $(proposalsByTheme[randomizedIndex]).parents().filter('.proposal-item'); | |
| 383 | - $(proposalToShow).show(); | |
| 384 | - }); | |
| 385 | - }, | |
| 386 | - display_category_tab: function(){ | |
| 387 | - // $('#proposal-group').hide(); | |
| 388 | - this.randomProposalByTheme(['category-saude', 'category-seguranca-publica', 'category-educacao', 'category-reducao-da-pobreza']); | |
| 389 | - $('#proposal-group').show(); /* Show random proposals*/ | |
| 390 | - $('.content').addClass('background'); /* Add class background */ | |
| 391 | - $('#proposal-categories').show(); | |
| 392 | - $('#nav-proposal-categories a').addClass('active'); | |
| 393 | - $('#nav-proposal-group a').removeClass('active'); | |
| 394 | - $('.proposal-category-items').hide(); | |
| 395 | - $('.proposal-category .arrow-box').hide(); | |
| 396 | - $('.proposal-detail').hide().removeClass('hide'); | |
| 397 | - $('#article-container').hide(); | |
| 398 | - | |
| 399 | - $('#content').show(); | |
| 400 | - $('nav').show(); | |
| 401 | - | |
| 402 | - this.computeBoxHeight(); | |
| 403 | - }, | |
| 404 | - display_proposals_tab: function(){ | |
| 405 | - // $('#proposal-categories').hide(); | |
| 406 | - // this.randomProposalByTheme(['category-saude', 'category-seguranca-publica', 'category-educacao', 'category-reducao-da-pobreza']); | |
| 407 | - $('.proposal-item').show(); /* Show all programs */ | |
| 408 | - $('#proposal-group').show(); | |
| 409 | - $('#proposal-categories').show(); | |
| 410 | - $('.proposal-category-items').hide(); | |
| 411 | - $('.proposal-detail').hide().removeClass('hide'); | |
| 412 | - $('#nav-proposal-group a').addClass('active'); | |
| 413 | - $('#nav-proposal-categories a').removeClass('active'); | |
| 414 | - $('#content').show(); | |
| 415 | - $('.content').addClass('background'); /* Add class background */ | |
| 416 | - $('#article-container').hide(); | |
| 417 | - $('nav').show(); | |
| 418 | - $('html, body').animate({ scrollTop: $('#proposal-group').offset().top }, 'fast'); | |
| 419 | - | |
| 420 | - this.computeBoxHeight(); | |
| 421 | - }, | |
| 422 | - // fim Eduardo | |
| 423 | - display_proposal: function(proposal_id){ | |
| 424 | - $('#proposal-categories').hide(); | |
| 425 | - $('#proposal-group').hide(); | |
| 426 | - $('.proposal-category-items').hide(); /* Hide Category Items */ | |
| 427 | - $('.content').removeClass('background'); /* Remove class background*/ | |
| 428 | - $('nav').hide(); | |
| 429 | - $('#content').hide(); | |
| 430 | - $('#article-container').hide(); | |
| 431 | - // $('.make-proposal-form').hide(); | |
| 432 | - // $('.login-container').hide(); | |
| 433 | - $('.proposal-detail').hide().removeClass('hide'); // hide all proposals | |
| 434 | - // $('.proposal-detail-base').hide(); | |
| 435 | - var $proposal = $('#' + proposal_id); | |
| 436 | - $proposal.find('.proposal-detail-base').hide(); | |
| 437 | - $proposal.show(); | |
| 438 | - $proposal.find('.proposal-header').show(); | |
| 439 | - $proposal.find('.make-proposal-container').show(); | |
| 440 | - $proposal.find('.support-proposal-container').show(); | |
| 441 | - $proposal.find('.results-container').hide(); | |
| 442 | - $proposal.find('.results-container .loading').hide(); | |
| 443 | - $proposal.find('.results-container .results-content').hide(); | |
| 444 | - $proposal.find('.experience-proposal-container').show(); | |
| 445 | - $proposal.find('.talk-proposal-container').show(); | |
| 446 | - $proposal.find('.calendar').hide(); | |
| 447 | - var active_category = ''; | |
| 448 | - var category_id; | |
| 449 | - switch($proposal.find('.categories').attr('class')) { | |
| 450 | - case 'categories saude': | |
| 451 | - active_category = 'saude'; | |
| 452 | - category_id = 180; | |
| 453 | - break; | |
| 454 | - case 'categories educacao': | |
| 455 | - active_category = 'educacao'; | |
| 456 | - category_id = 181; | |
| 457 | - break; | |
| 458 | - case 'categories seguranca-publica': | |
| 459 | - active_category = 'seguranca-publica'; | |
| 460 | - category_id = 182; | |
| 461 | - break; | |
| 462 | - case 'categories reducao-da-pobreza': | |
| 463 | - active_category = 'reducao-da-pobreza'; | |
| 464 | - category_id = 183; | |
| 465 | - break; | |
| 466 | - } | |
| 467 | - | |
| 468 | - var topic_id = proposal_id.split('-').pop(); | |
| 469 | - this.loadRandomProposal(topic_id); | |
| 470 | - Main.display_events(category_id, active_category); | |
| 471 | - }, | |
| 472 | - display_proposal_detail: function(proposal_id){ | |
| 473 | - $('.content').removeClass('background'); /* Remove class background */ | |
| 474 | - $('#proposal-categories').hide(); | |
| 475 | - $('#proposal-group').hide(); | |
| 476 | - $('nav').hide(); | |
| 477 | - $('#content').hide(); | |
| 478 | - $('#article-container').hide(); | |
| 479 | - var $proposal = $('#proposal-item-' + proposal_id); | |
| 480 | - $proposal.find('.proposal-header').hide(); | |
| 481 | - $proposal.find('.make-proposal-container').hide(); | |
| 482 | - $proposal.find('.support-proposal-container').hide(); | |
| 483 | - $proposal.find('.results-container').hide(); | |
| 484 | - $proposal.find('.experience-proposal-container').hide(); | |
| 485 | - $proposal.find('.talk-proposal-container').hide(); | |
| 486 | - $proposal.find('.body').show(); | |
| 487 | - $proposal.show(); | |
| 488 | - | |
| 489 | - //var url = host + '/api/v1/articles/' + proposal_id + '?private_token=' + Main.private_token + '&fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; | |
| 490 | - var url = host + '/api/v1/articles/' + proposal_id + '?fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; | |
| 491 | - $.getJSON(url).done(function( data ) { | |
| 492 | - $('#proposal-item-' + proposal_id + ' .body-content').replaceWith(data.article.body); | |
| 493 | - }) | |
| 494 | - .fail(function( jqxhr, textStatus, error ) { | |
| 495 | - var err = textStatus + ', ' + error; | |
| 496 | - console.error( 'Request Failed: ' + err ); | |
| 497 | - }); | |
| 498 | - }, | |
| 499 | - display_proposal_by_category: function(item){ | |
| 500 | - var $item = $('#' + item); | |
| 501 | - | |
| 502 | - if($item.hasClass('proposal-category-items')){ | |
| 503 | - //Display Topics or Discussion by category | |
| 504 | - $('nav').show(); | |
| 505 | - $('#content').show(); | |
| 369 | + return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | |
| 370 | + }, | |
| 371 | + display_article: function(article_id, backTo) { | |
| 372 | + //var url = host + '/api/v1/articles/' + article_id + '?private_token=' + Main.private_token; | |
| 373 | + var url = host + '/api/v1/articles/' + article_id; | |
| 374 | + $.getJSON(url).done(function( data ) { | |
| 375 | + $('#article-container .article-content').html(articleTemplate(data.article)); | |
| 376 | + $('#article-container').show(); | |
| 377 | + $('#proposal-categories').hide(); | |
| 378 | + $('#proposal-group').hide(); | |
| 379 | + $('nav').hide(); | |
| 380 | + $('#content').hide(); | |
| 381 | + $('.content').removeClass('background'); /* Remove class background*/ | |
| 382 | + $('#article-container .go-back').attr('href', backTo); | |
| 383 | + }); | |
| 384 | + }, | |
| 385 | + // inicio Eduardo | |
| 386 | + randomProposalByTheme: function(themeClasses) { | |
| 387 | + $('#proposal-group .proposal-list .proposal-item').hide(); | |
| 388 | + $.each(themeClasses, function(i, themeClass) { | |
| 389 | + var proposalsByTheme = $('#proposal-group .proposal-list .proposal-item').find('.' + themeClass); | |
| 390 | + var randomizedIndex = Math.floor(Math.random() * proposalsByTheme.length); | |
| 391 | + var proposalToShow = $(proposalsByTheme[randomizedIndex]).parents().filter('.proposal-item'); | |
| 392 | + $(proposalToShow).show(); | |
| 393 | + }); | |
| 394 | + }, | |
| 395 | + display_category_tab: function(){ | |
| 396 | + // $('#proposal-group').hide(); | |
| 397 | + this.randomProposalByTheme(['category-saude', 'category-seguranca-publica', 'category-educacao', 'category-reducao-da-pobreza']); | |
| 398 | + $('#proposal-group').show(); /* Show random proposals*/ | |
| 399 | + $('.content').addClass('background'); /* Add class background */ | |
| 506 | 400 | $('#proposal-categories').show(); |
| 507 | 401 | $('#nav-proposal-categories a').addClass('active'); |
| 508 | 402 | $('#nav-proposal-group a').removeClass('active'); |
| 509 | - $('#proposal-group').hide(); /* Hide section "Programas" */ | |
| 510 | - $('.content').addClass('background'); /* Add class background */ | |
| 511 | 403 | $('.proposal-category-items').hide(); |
| 404 | + $('.proposal-category .arrow-box').hide(); | |
| 512 | 405 | $('.proposal-detail').hide().removeClass('hide'); |
| 513 | 406 | $('#article-container').hide(); |
| 514 | - $item.toggle( 'blind', 200, function () { | |
| 515 | - var itemOffset = $item.offset(); | |
| 516 | - if(itemOffset){ | |
| 517 | - $('html, body').animate({ scrollTop: itemOffset.top }, 'fast'); | |
| 518 | - } | |
| 519 | - } ); | |
| 520 | - $('.proposal-category .arrow-box').hide(); | |
| 521 | - var categorySlug = $item.data('category'); | |
| 522 | - $('#proposal-category-' + categorySlug).find('.arrow-box').show(); | |
| 523 | 407 | |
| 524 | - this.computeBoxHeight(); | |
| 525 | - | |
| 526 | - } | |
| 527 | - }, | |
| 528 | - addBarraDoGoverno: function(){ | |
| 529 | - | |
| 530 | - if( BARRA_ADDED ) { return; } | |
| 531 | - | |
| 532 | - var HTML_BODY_PREPEND = '' + | |
| 533 | - '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + | |
| 534 | - '<ul id="menu-barra-temp" style="list-style:none;">' + | |
| 535 | - '<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> ' + | |
| 536 | - '<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>' + | |
| 537 | - '</ul>' + | |
| 538 | - '</div>'; | |
| 539 | - | |
| 540 | - var HTML_BODY_APPEND = ''+ | |
| 541 | - '<footer id="footer-brasil"></footer>' + | |
| 542 | - '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; | |
| 543 | - | |
| 544 | - var STYLE_TEMA_AZUL = '' + | |
| 545 | - '<style>'+ | |
| 546 | - '#footer-brasil {'+ | |
| 547 | - 'background: none repeat scroll 0% 0% #0042b1;'+ | |
| 548 | - 'padding: 1em 0px;'+ | |
| 549 | - 'max-width: 100%;'+ | |
| 550 | - 'margin-top: 40px;'+ | |
| 551 | - '}'+ | |
| 552 | - '#barra-brasil ul {'+ | |
| 553 | - 'width: auto;'+ | |
| 554 | - '}'+ | |
| 555 | - '<style>'; | |
| 556 | - | |
| 557 | - var $body = $(document.body); | |
| 558 | - $body.prepend(HTML_BODY_PREPEND); | |
| 559 | - $body.append(HTML_BODY_APPEND); | |
| 560 | - $body.append(STYLE_TEMA_AZUL); | |
| 561 | - | |
| 562 | - BARRA_ADDED = true; | |
| 563 | - }, | |
| 564 | - updateHash: function(hash){ | |
| 565 | - var id = hash.replace(/^.*#/, ''); | |
| 566 | - var elem = document.getElementById(id); | |
| 567 | - | |
| 568 | - // preserve the query param | |
| 569 | - // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ | |
| 570 | - // hash += '?barra=false'; | |
| 571 | - // } | |
| 572 | - | |
| 573 | - if ( !elem ) { | |
| 574 | - window.location.hash = hash; | |
| 575 | - return; | |
| 576 | - } | |
| 408 | + $('#content').show(); | |
| 409 | + $('nav').show(); | |
| 577 | 410 | |
| 578 | - elem.id = id+'-tmp'; | |
| 579 | - window.location.hash = hash; | |
| 580 | - elem.id = id; | |
| 581 | - }, | |
| 582 | - locationHashChanged: function(){ | |
| 583 | - var hash = window.location.hash; | |
| 584 | - this.navigateTo(hash, lastHash); | |
| 585 | - lastHash = hash; | |
| 586 | - }, | |
| 587 | - navigateTo: function(hash, lastHash) { | |
| 588 | - | |
| 589 | - var scrollTop = 0; | |
| 590 | - var $nav = $('nav[role="tabpanel"]'); | |
| 591 | - var navOffset = $nav.offset(); | |
| 592 | - | |
| 593 | - var regexProposals = /#\/programas/; | |
| 594 | - var regexCategory = /#\/temas/; | |
| 595 | - var regexPropostas = /\/propostas\//; | |
| 596 | - var regexHideBarra = /barra=false$/; | |
| 597 | - var regexArticle = /#\/artigo/; | |
| 598 | - var regexResultados = /resultados$/; | |
| 599 | - var regexSobreOPrograma = /sobre-o-programa$/; | |
| 600 | - var regexActivateUser = /#\/activate/; | |
| 601 | - var regexChangeUserPassword = /#\/trocar_senha/; | |
| 602 | - | |
| 603 | - if( (regexHideBarra.exec(hash) === null) && !HIDE_BARRA_DO_GOVERNO ){ | |
| 604 | - this.addBarraDoGoverno(); | |
| 605 | - }else{ | |
| 606 | - HIDE_BARRA_DO_GOVERNO = true; | |
| 607 | - } | |
| 411 | + this.computeBoxHeight(); | |
| 412 | + }, | |
| 413 | + display_proposals_tab: function(){ | |
| 414 | + // $('#proposal-categories').hide(); | |
| 415 | + // this.randomProposalByTheme(['category-saude', 'category-seguranca-publica', 'category-educacao', 'category-reducao-da-pobreza']); | |
| 416 | + $('.proposal-item').show(); /* Show all programs */ | |
| 417 | + $('#proposal-group').show(); | |
| 418 | + $('#proposal-categories').show(); | |
| 419 | + $('.proposal-category-items').hide(); | |
| 420 | + $('.proposal-detail').hide().removeClass('hide'); | |
| 421 | + $('#nav-proposal-group a').addClass('active'); | |
| 422 | + $('#nav-proposal-categories a').removeClass('active'); | |
| 423 | + $('#content').show(); | |
| 424 | + $('.content').addClass('background'); /* Add class background */ | |
| 425 | + $('#article-container').hide(); | |
| 426 | + $('nav').show(); | |
| 427 | + $('html, body').animate({ scrollTop: $('#proposal-group').offset().top }, 'fast'); | |
| 608 | 428 | |
| 609 | - // remove query params | |
| 610 | - hash = hash.split('?')[0]; | |
| 429 | + this.computeBoxHeight(); | |
| 430 | + }, | |
| 431 | + // fim Eduardo | |
| 432 | + display_proposal: function(proposal_id){ | |
| 433 | + $('#proposal-categories').hide(); | |
| 434 | + $('#proposal-group').hide(); | |
| 435 | + $('.proposal-category-items').hide(); /* Hide Category Items */ | |
| 436 | + $('.content').removeClass('background'); /* Remove class background*/ | |
| 437 | + $('nav').hide(); | |
| 438 | + $('#content').hide(); | |
| 439 | + $('#article-container').hide(); | |
| 440 | + // $('.make-proposal-form').hide(); | |
| 441 | + // $('.login-container').hide(); | |
| 442 | + $('.proposal-detail').hide().removeClass('hide'); // hide all proposals | |
| 443 | + // $('.proposal-detail-base').hide(); | |
| 444 | + var $proposal = $('#' + proposal_id); | |
| 445 | + $proposal.find('.proposal-detail-base').hide(); | |
| 446 | + $proposal.show(); | |
| 447 | + $proposal.find('.proposal-header').show(); | |
| 448 | + $proposal.find('.make-proposal-container').show(); | |
| 449 | + $proposal.find('.support-proposal-container').show(); | |
| 450 | + $proposal.find('.results-container').hide(); | |
| 451 | + $proposal.find('.results-container .loading').hide(); | |
| 452 | + $proposal.find('.results-container .results-content').hide(); | |
| 453 | + $proposal.find('.experience-proposal-container').show(); | |
| 454 | + $proposal.find('.talk-proposal-container').show(); | |
| 455 | + $proposal.find('.calendar').hide(); | |
| 456 | + var active_category = ''; | |
| 457 | + var category_id; | |
| 458 | + switch($proposal.find('.categories').attr('class')) { | |
| 459 | + case 'categories saude': | |
| 460 | + active_category = 'saude'; | |
| 461 | + category_id = 180; | |
| 462 | + break; | |
| 463 | + case 'categories educacao': | |
| 464 | + active_category = 'educacao'; | |
| 465 | + category_id = 181; | |
| 466 | + break; | |
| 467 | + case 'categories seguranca-publica': | |
| 468 | + active_category = 'seguranca-publica'; | |
| 469 | + category_id = 182; | |
| 470 | + break; | |
| 471 | + case 'categories reducao-da-pobreza': | |
| 472 | + active_category = 'reducao-da-pobreza'; | |
| 473 | + category_id = 183; | |
| 474 | + break; | |
| 475 | + } | |
| 611 | 476 | |
| 612 | - var parts = hash.split('/'); | |
| 477 | + var topic_id = proposal_id.split('-').pop(); | |
| 478 | + this.loadRandomProposal(topic_id); | |
| 479 | + Main.display_events(category_id, active_category); | |
| 480 | + }, | |
| 481 | + display_proposal_detail: function(proposal_id){ | |
| 482 | + $('.content').removeClass('background'); /* Remove class background */ | |
| 483 | + $('#proposal-categories').hide(); | |
| 484 | + $('#proposal-group').hide(); | |
| 485 | + $('nav').hide(); | |
| 486 | + $('#content').hide(); | |
| 487 | + $('#article-container').hide(); | |
| 488 | + var $proposal = $('#proposal-item-' + proposal_id); | |
| 489 | + $proposal.find('.proposal-header').hide(); | |
| 490 | + $proposal.find('.make-proposal-container').hide(); | |
| 491 | + $proposal.find('.support-proposal-container').hide(); | |
| 492 | + $proposal.find('.results-container').hide(); | |
| 493 | + $proposal.find('.experience-proposal-container').hide(); | |
| 494 | + $proposal.find('.talk-proposal-container').hide(); | |
| 495 | + $proposal.find('.body').show(); | |
| 496 | + $proposal.show(); | |
| 497 | + | |
| 498 | + //var url = host + '/api/v1/articles/' + proposal_id + '?private_token=' + Main.private_token + '&fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; | |
| 499 | + var url = host + '/api/v1/articles/' + proposal_id + '?fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; | |
| 500 | + $.getJSON(url).done(function( data ) { | |
| 501 | + $('#proposal-item-' + proposal_id + ' .body-content').replaceWith(data.article.body); | |
| 502 | + }) | |
| 503 | + .fail(function( jqxhr, textStatus, error ) { | |
| 504 | + var err = textStatus + ', ' + error; | |
| 505 | + console.error( 'Request Failed: ' + err ); | |
| 506 | + }); | |
| 507 | + }, | |
| 508 | + display_proposal_by_category: function(item){ | |
| 509 | + var $item = $('#' + item); | |
| 510 | + | |
| 511 | + if($item.hasClass('proposal-category-items')){ | |
| 512 | + //Display Topics or Discussion by category | |
| 513 | + $('nav').show(); | |
| 514 | + $('#content').show(); | |
| 515 | + $('#proposal-categories').show(); | |
| 516 | + $('#nav-proposal-categories a').addClass('active'); | |
| 517 | + $('#nav-proposal-group a').removeClass('active'); | |
| 518 | + $('#proposal-group').hide(); /* Hide section "Programas" */ | |
| 519 | + $('.content').addClass('background'); /* Add class background */ | |
| 520 | + $('.proposal-category-items').hide(); | |
| 521 | + $('.proposal-detail').hide().removeClass('hide'); | |
| 522 | + $('#article-container').hide(); | |
| 523 | + $item.toggle( 'blind', 200, function () { | |
| 524 | + var itemOffset = $item.offset(); | |
| 525 | + if(itemOffset){ | |
| 526 | + $('html, body').animate({ scrollTop: itemOffset.top }, 'fast'); | |
| 527 | + } | |
| 528 | + } ); | |
| 529 | + $('.proposal-category .arrow-box').hide(); | |
| 530 | + var categorySlug = $item.data('category'); | |
| 531 | + $('#proposal-category-' + categorySlug).find('.arrow-box').show(); | |
| 613 | 532 | |
| 614 | - var isProposal = regexProposals.exec(hash) !== null; | |
| 615 | - var isCategory = regexCategory.exec(hash) !== null; | |
| 616 | - var isArticle = regexArticle.exec(hash) !== null; | |
| 617 | - var isPropostas = regexPropostas.exec(hash) !== null; | |
| 618 | - var isResultados = regexResultados.exec(hash) !== null; | |
| 619 | - var isSobreOPrograma = regexSobreOPrograma.exec(hash) !== null; | |
| 620 | - var isActivateUser = regexActivateUser.exec(hash) !== null; | |
| 621 | - var isChangeUserPassword = regexChangeUserPassword.exec(hash) !== null; | |
| 533 | + this.computeBoxHeight(); | |
| 622 | 534 | |
| 623 | - if(isArticle) { | |
| 624 | - this.display_article(hash.split('/')[2], lastHash); | |
| 625 | - } | |
| 535 | + } | |
| 536 | + }, | |
| 537 | + addBarraDoGoverno: function(){ | |
| 538 | + | |
| 539 | + if( BARRA_ADDED ) { return; } | |
| 540 | + | |
| 541 | + var HTML_BODY_PREPEND = '' + | |
| 542 | + '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + | |
| 543 | + '<ul id="menu-barra-temp" style="list-style:none;">' + | |
| 544 | + '<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> ' + | |
| 545 | + '<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>' + | |
| 546 | + '</ul>' + | |
| 547 | + '</div>'; | |
| 548 | + | |
| 549 | + var HTML_BODY_APPEND = ''+ | |
| 550 | + '<footer id="footer-brasil"></footer>' + | |
| 551 | + '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; | |
| 552 | + | |
| 553 | + var STYLE_TEMA_AZUL = '' + | |
| 554 | + '<style>'+ | |
| 555 | + '#footer-brasil {'+ | |
| 556 | + 'background: none repeat scroll 0% 0% #0042b1;'+ | |
| 557 | + 'padding: 1em 0px;'+ | |
| 558 | + 'max-width: 100%;'+ | |
| 559 | + 'margin-top: 40px;'+ | |
| 560 | + '}'+ | |
| 561 | + '#barra-brasil ul {'+ | |
| 562 | + 'width: auto;'+ | |
| 563 | + '}'+ | |
| 564 | + '<style>'; | |
| 626 | 565 | |
| 627 | - var proposalTitle; | |
| 566 | + var $body = $(document.body); | |
| 567 | + $body.prepend(HTML_BODY_PREPEND); | |
| 568 | + $body.append(HTML_BODY_APPEND); | |
| 569 | + $body.append(STYLE_TEMA_AZUL); | |
| 628 | 570 | |
| 629 | - if( isProposal ){ | |
| 571 | + BARRA_ADDED = true; | |
| 572 | + }, | |
| 573 | + updateHash: function(hash){ | |
| 574 | + var id = hash.replace(/^.*#/, ''); | |
| 575 | + var elem = document.getElementById(id); | |
| 630 | 576 | |
| 631 | - // go to proposal | |
| 632 | - var proposalId = parts[2]; | |
| 633 | - this.navigateToProposal(proposalId); | |
| 577 | + // preserve the query param | |
| 578 | + // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ | |
| 579 | + // hash += '?barra=false'; | |
| 580 | + // } | |
| 634 | 581 | |
| 635 | - var $proposal = $('#proposal-item-' + proposalId); | |
| 636 | - proposalTitle = $proposal.find('.title').text(); | |
| 637 | - var proposalOffset = $proposal.offset(); | |
| 582 | + if ( !elem ) { | |
| 583 | + window.location.hash = hash; | |
| 584 | + return; | |
| 585 | + } | |
| 638 | 586 | |
| 639 | - if(proposalOffset){ | |
| 640 | - scrollTop = proposalOffset.top; | |
| 587 | + elem.id = id+'-tmp'; | |
| 588 | + window.location.hash = hash; | |
| 589 | + elem.id = id; | |
| 590 | + }, | |
| 591 | + locationHashChanged: function(){ | |
| 592 | + var hash = window.location.hash; | |
| 593 | + this.navigateTo(hash, lastHash); | |
| 594 | + lastHash = hash; | |
| 595 | + }, | |
| 596 | + navigateTo: function(hash, lastHash) { | |
| 597 | + | |
| 598 | + var scrollTop = 0; | |
| 599 | + var $nav = $('nav[role="tabpanel"]'); | |
| 600 | + var navOffset = $nav.offset(); | |
| 601 | + | |
| 602 | + var regexProposals = /#\/programas/; | |
| 603 | + var regexCategory = /#\/temas/; | |
| 604 | + var regexPropostas = /\/propostas\//; | |
| 605 | + var regexHideBarra = /barra=false$/; | |
| 606 | + var regexArticle = /#\/artigo/; | |
| 607 | + var regexResultados = /resultados$/; | |
| 608 | + var regexSobreOPrograma = /sobre-o-programa$/; | |
| 609 | + var regexActivateUser = /#\/activate/; | |
| 610 | + var regexChangeUserPassword = /#\/trocar_senha/; | |
| 611 | + | |
| 612 | + if( (regexHideBarra.exec(hash) === null) && !HIDE_BARRA_DO_GOVERNO ){ | |
| 613 | + this.addBarraDoGoverno(); | |
| 641 | 614 | }else{ |
| 642 | - if(navOffset){ | |
| 643 | - scrollTop = navOffset.top; | |
| 644 | - } else { | |
| 645 | - scrollTop = $('#proposal-group').offset().top; | |
| 646 | - } | |
| 615 | + HIDE_BARRA_DO_GOVERNO = true; | |
| 647 | 616 | } |
| 648 | 617 | |
| 649 | - if(isResultados){ | |
| 650 | - var $resultsContainer = $proposal.find('.results-container'); | |
| 618 | + // remove query params | |
| 619 | + hash = hash.split('?')[0]; | |
| 651 | 620 | |
| 652 | - if($resultsContainer.css('display') === 'none') { | |
| 653 | - Main.loadRanking($resultsContainer, proposalId, 1); | |
| 654 | - } else { | |
| 655 | - $proposal.find('.experience-proposal-container').show(); | |
| 656 | - $proposal.find('.talk-proposal-container').show(); | |
| 657 | - $resultsContainer.hide(); | |
| 658 | - } | |
| 621 | + var parts = hash.split('/'); | |
| 659 | 622 | |
| 660 | - proposalOffset = $resultsContainer.offset(); | |
| 661 | - if(proposalOffset){ | |
| 662 | - scrollTop = proposalOffset.top; | |
| 663 | - } | |
| 623 | + var isProposal = regexProposals.exec(hash) !== null; | |
| 624 | + var isCategory = regexCategory.exec(hash) !== null; | |
| 625 | + var isArticle = regexArticle.exec(hash) !== null; | |
| 626 | + var isPropostas = regexPropostas.exec(hash) !== null; | |
| 627 | + var isResultados = regexResultados.exec(hash) !== null; | |
| 628 | + var isSobreOPrograma = regexSobreOPrograma.exec(hash) !== null; | |
| 629 | + var isActivateUser = regexActivateUser.exec(hash) !== null; | |
| 630 | + var isChangeUserPassword = regexChangeUserPassword.exec(hash) !== null; | |
| 631 | + | |
| 632 | + if(isArticle) { | |
| 633 | + this.display_article(hash.split('/')[2], lastHash); | |
| 664 | 634 | } |
| 665 | 635 | |
| 636 | + var proposalTitle; | |
| 637 | + | |
| 638 | + if( isProposal ){ | |
| 639 | + | |
| 640 | + // go to proposal | |
| 641 | + var proposalId = parts[2]; | |
| 642 | + this.navigateToProposal(proposalId); | |
| 666 | 643 | |
| 667 | - if(isPropostas){ | |
| 668 | - var $propostasContainer = $proposal.find('.support-proposal-container'); | |
| 644 | + var $proposal = $('#proposal-item-' + proposalId); | |
| 645 | + proposalTitle = $proposal.find('.title').text(); | |
| 646 | + var proposalOffset = $proposal.offset(); | |
| 669 | 647 | |
| 670 | - proposalOffset = $propostasContainer.offset(); | |
| 671 | 648 | if(proposalOffset){ |
| 672 | 649 | scrollTop = proposalOffset.top; |
| 650 | + }else{ | |
| 651 | + if(navOffset){ | |
| 652 | + scrollTop = navOffset.top; | |
| 653 | + } else { | |
| 654 | + scrollTop = $('#proposal-group').offset().top; | |
| 655 | + } | |
| 673 | 656 | } |
| 674 | - | |
| 675 | - } | |
| 676 | - } | |
| 677 | - | |
| 678 | - var categorySlug; | |
| 679 | 657 | |
| 680 | - if( isCategory ){ | |
| 658 | + if(isResultados){ | |
| 659 | + var $resultsContainer = $proposal.find('.results-container'); | |
| 681 | 660 | |
| 682 | - // go to category | |
| 683 | - categorySlug = parts[2]; | |
| 684 | - var categoryId = parts[3]; | |
| 685 | - this.navigateToCategory(categoryId); | |
| 661 | + if($resultsContainer.css('display') === 'none') { | |
| 662 | + Main.loadRanking($resultsContainer, proposalId, 1); | |
| 663 | + } else { | |
| 664 | + $proposal.find('.experience-proposal-container').show(); | |
| 665 | + $proposal.find('.talk-proposal-container').show(); | |
| 666 | + $resultsContainer.hide(); | |
| 667 | + } | |
| 686 | 668 | |
| 687 | - var $category = $('#proposal-item-' + categoryId); | |
| 688 | - var categoryOffset = $category.offset(); | |
| 689 | - if(categoryOffset){ | |
| 690 | - scrollTop = categoryOffset.top; | |
| 691 | - }else{ | |
| 692 | - if(navOffset){ | |
| 693 | - scrollTop = navOffset.top; | |
| 669 | + proposalOffset = $resultsContainer.offset(); | |
| 670 | + if(proposalOffset){ | |
| 671 | + scrollTop = proposalOffset.top; | |
| 672 | + } | |
| 694 | 673 | } |
| 695 | - } | |
| 696 | - } | |
| 697 | 674 | |
| 698 | - // default | |
| 699 | - if( !isProposal && !isCategory ){ | |
| 700 | - // show the 'index' -> category tab | |
| 701 | - this.display_category_tab(); | |
| 702 | - } | |
| 703 | 675 | |
| 704 | - if(isActivateUser){ | |
| 705 | - var code = parts.pop(); | |
| 706 | - Main.activateUser(code); | |
| 707 | - } | |
| 676 | + if(isPropostas){ | |
| 677 | + var $propostasContainer = $proposal.find('.support-proposal-container'); | |
| 708 | 678 | |
| 709 | - if(isChangeUserPassword){ | |
| 710 | - var code = parts.pop(); | |
| 711 | - Main.changeUserPassword(code); | |
| 712 | - } | |
| 679 | + proposalOffset = $propostasContainer.offset(); | |
| 680 | + if(proposalOffset){ | |
| 681 | + scrollTop = proposalOffset.top; | |
| 682 | + } | |
| 683 | + | |
| 684 | + } | |
| 685 | + } | |
| 713 | 686 | |
| 714 | - // [BEGIN] Tracking | |
| 715 | - if (window._paq){ | |
| 716 | - // _paq.push(['trackEvent', 'NavegarPara', hash || '/']); | |
| 717 | - // _paq.push(['setDocumentTitle', document.domain + '/' + hash]); | |
| 718 | - // _paq.push(['trackPageView']); | |
| 687 | + var categorySlug; | |
| 719 | 688 | |
| 720 | - var trackPageTitle = ''; | |
| 721 | - if(isArticle){ | |
| 722 | - trackPageTitle = 'Página: Sobre'; | |
| 723 | - } | |
| 689 | + if( isCategory ){ | |
| 724 | 690 | |
| 725 | - if(isProposal){ | |
| 691 | + // go to category | |
| 692 | + categorySlug = parts[2]; | |
| 693 | + var categoryId = parts[3]; | |
| 694 | + this.navigateToCategory(categoryId); | |
| 726 | 695 | |
| 727 | - if( proposalTitle ){ | |
| 728 | - trackPageTitle = 'Programa: ' + proposalTitle + ' / Início'; | |
| 696 | + var $category = $('#proposal-item-' + categoryId); | |
| 697 | + var categoryOffset = $category.offset(); | |
| 698 | + if(categoryOffset){ | |
| 699 | + scrollTop = categoryOffset.top; | |
| 729 | 700 | }else{ |
| 730 | - trackPageTitle = 'todos os programas'; | |
| 701 | + if(navOffset){ | |
| 702 | + scrollTop = navOffset.top; | |
| 703 | + } | |
| 731 | 704 | } |
| 705 | + } | |
| 732 | 706 | |
| 733 | - if(isResultados){ | |
| 734 | - trackPageTitle += ' / Resultados' ; | |
| 735 | - } | |
| 707 | + // default | |
| 708 | + if( !isProposal && !isCategory ){ | |
| 709 | + // show the 'index' -> category tab | |
| 710 | + this.display_category_tab(); | |
| 711 | + } | |
| 736 | 712 | |
| 737 | - if(isSobreOPrograma){ | |
| 738 | - trackPageTitle += ' / Conheça o programa' ; | |
| 739 | - } | |
| 713 | + if(isActivateUser){ | |
| 714 | + var code = parts.pop(); | |
| 715 | + Main.activateUser(code); | |
| 740 | 716 | } |
| 741 | 717 | |
| 742 | - if(isCategory){ | |
| 743 | - trackPageTitle = 'Tema: ' + categorySlug; | |
| 718 | + if(isChangeUserPassword){ | |
| 719 | + var code = parts.pop(); | |
| 720 | + Main.changeUserPassword(code); | |
| 744 | 721 | } |
| 745 | 722 | |
| 746 | - window._paq.push(['trackPageView', trackPageTitle]); | |
| 747 | - // console.log('tracked page view', trackPageTitle); | |
| 748 | - } | |
| 749 | - // [END] Tracking | |
| 750 | - | |
| 751 | - $('html, body').animate({ scrollTop: scrollTop }, 'fast'); | |
| 752 | - }, | |
| 753 | - navigateToProposal: function(proposalId){ | |
| 754 | - var regexSobreOPrograma = /sobre-o-programa$/; | |
| 755 | - if(proposalId === undefined){ | |
| 756 | - this.display_proposals_tab(); | |
| 757 | - }else if(regexSobreOPrograma.exec(window.location.hash) === null){ | |
| 758 | - this.display_proposal('proposal-item-' + proposalId); | |
| 759 | - }else{ | |
| 760 | - this.display_proposal_detail(proposalId); | |
| 761 | - } | |
| 762 | - }, | |
| 763 | - navigateToCategory: function(categoryId){ | |
| 764 | - if(categoryId === undefined){ | |
| 765 | - this.display_category_tab(); | |
| 766 | - }else{ | |
| 767 | - this.display_proposal_by_category('proposal-item-' + categoryId); | |
| 768 | - } | |
| 769 | - }, | |
| 770 | - oauthClientAction: function(url) { | |
| 771 | - var child = window.open(url, '_blank'); | |
| 772 | - var interval = setInterval(function() { | |
| 773 | - try { | |
| 774 | - if(!child.closed) { | |
| 775 | - child.postMessage({ | |
| 776 | - message: 'requestOauthClientPluginResult' | |
| 777 | - }, '*'); | |
| 723 | + // [BEGIN] Tracking | |
| 724 | + if (window._paq){ | |
| 725 | + // _paq.push(['trackEvent', 'NavegarPara', hash || '/']); | |
| 726 | + // _paq.push(['setDocumentTitle', document.domain + '/' + hash]); | |
| 727 | + // _paq.push(['trackPageView']); | |
| 728 | + | |
| 729 | + var trackPageTitle = ''; | |
| 730 | + if(isArticle){ | |
| 731 | + trackPageTitle = 'Página: Sobre'; | |
| 732 | + } | |
| 733 | + | |
| 734 | + if(isProposal){ | |
| 735 | + | |
| 736 | + if( proposalTitle ){ | |
| 737 | + trackPageTitle = 'Programa: ' + proposalTitle + ' / Início'; | |
| 738 | + }else{ | |
| 739 | + trackPageTitle = 'todos os programas'; | |
| 740 | + } | |
| 741 | + | |
| 742 | + if(isResultados){ | |
| 743 | + trackPageTitle += ' / Resultados' ; | |
| 744 | + } | |
| 745 | + | |
| 746 | + if(isSobreOPrograma){ | |
| 747 | + trackPageTitle += ' / Conheça o programa' ; | |
| 778 | 748 | } |
| 779 | 749 | } |
| 780 | - catch(e) { | |
| 781 | - // we're here when the child window has been navigated away or closed | |
| 782 | - if (child.closed) { | |
| 783 | - clearInterval(interval); | |
| 784 | - return; | |
| 785 | - } | |
| 750 | + | |
| 751 | + if(isCategory){ | |
| 752 | + trackPageTitle = 'Tema: ' + categorySlug; | |
| 786 | 753 | } |
| 787 | - }, 300); | |
| 788 | - }, | |
| 789 | - displaySuccess: function(container, text, timeout, iconClass) { | |
| 790 | - timeout = typeof timeout !== 'undefined' ? timeout : 2000; | |
| 791 | - container.css('opacity', 0.1); | |
| 792 | - var successPanel = $('.success-panel').clone(); | |
| 793 | - successPanel.find('.icon').addClass(iconClass); | |
| 794 | - successPanel.find('.message').html(text); | |
| 795 | - successPanel.appendTo(container.closest('.categories')); | |
| 796 | - successPanel.show(); | |
| 797 | - successPanel.css('top', Math.max(0, ((container.height() - successPanel.outerHeight()) / 2) + container.offset().top) + 'px'); | |
| 798 | - successPanel.css('left', Math.max(0, ((container.width() - successPanel.outerWidth()) / 2) + container.offset().left) + 'px'); | |
| 799 | - | |
| 800 | - setTimeout(function() { | |
| 801 | - successPanel.hide(); | |
| 802 | - container.css('opacity', 1); | |
| 803 | - successPanel.remove(); | |
| 804 | - }, timeout); | |
| 805 | - }, | |
| 806 | - setUser: function(user){ | |
| 807 | - this.user = user; | |
| 808 | - }, | |
| 809 | - getUser: function(){ | |
| 810 | - return this.user; | |
| 811 | - }, | |
| 812 | - showLogin: function(){ | |
| 813 | - $('#login-button').show(); | |
| 814 | - $('#logout-button').hide(); | |
| 815 | - }, | |
| 816 | - showLogout: function(){ | |
| 817 | - $('#login-button').hide(); | |
| 818 | - var name = ''; | |
| 819 | - var user = Main.getUser(); | |
| 820 | - if(user){ | |
| 821 | - if(user.person && user.person.name){ | |
| 822 | - name = user.person.name + ' - '; | |
| 823 | - }else{ | |
| 824 | - name = user.login + ' - '; | |
| 754 | + | |
| 755 | + window._paq.push(['trackPageView', trackPageTitle]); | |
| 756 | + // console.log('tracked page view', trackPageTitle); | |
| 825 | 757 | } |
| 758 | + // [END] Tracking | |
| 826 | 759 | |
| 827 | - } | |
| 828 | - $('#logout-button .name').text(name); | |
| 829 | - $('#logout-button').show(); | |
| 830 | - }, | |
| 831 | - responseToText: function(responseJSONmessage){ | |
| 832 | - var o = JSON.parse(responseJSONmessage); | |
| 833 | - var msg = ''; | |
| 834 | - var fn; | |
| 835 | - | |
| 836 | - for (var key in o) { | |
| 837 | - if (o[key] instanceof Array) { | |
| 838 | - fn = key; | |
| 839 | - for (var i = 0; i < o[key].length; i++) { | |
| 840 | - msg += fn + ' ' + o[key][i] + '</br>'; | |
| 841 | - } | |
| 760 | + $('html, body').animate({ scrollTop: scrollTop }, 'fast'); | |
| 761 | + }, | |
| 762 | + navigateToProposal: function(proposalId){ | |
| 763 | + var regexSobreOPrograma = /sobre-o-programa$/; | |
| 764 | + if(proposalId === undefined){ | |
| 765 | + this.display_proposals_tab(); | |
| 766 | + }else if(regexSobreOPrograma.exec(window.location.hash) === null){ | |
| 767 | + this.display_proposal('proposal-item-' + proposalId); | |
| 768 | + }else{ | |
| 769 | + this.display_proposal_detail(proposalId); | |
| 842 | 770 | } |
| 843 | - } | |
| 844 | - msg = msg.replace(/login incorrect format/g,"campo \"nome do usuário\" está com formato inválido. O mesmo só pode ser composto por letras minúsculas, números, '_' e '-'. Adicionalmente não é permitido usar acentuação nem começar com '_' ou '-'"); | |
| 845 | - msg = msg.replace('password_confirmation', 'campo "confirmação da senha"'); | |
| 846 | - msg = msg.replace(/password/g, 'campo "senha"'); | |
| 847 | - msg = msg.replace(/login/g, 'campo "nome de usuário"'); | |
| 848 | - msg = msg.replace('email', 'campo "e-mail"'); | |
| 849 | - msg = msg.substring(0, msg.length - 5) + '.'; | |
| 850 | - return msg; | |
| 851 | - }, | |
| 852 | - display_events: function(cat_id, active_category) { | |
| 853 | - //var url = host + '/api/v1/communities/' + dialoga_community + '/articles?categories_ids[]=' + cat_id + '&content_type=Event&private_token=' + '375bee7e17d0021af7160ce664874618'; | |
| 854 | - var url = host + '/api/v1/communities/' + dialoga_community + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; | |
| 855 | - $.getJSON(url).done(function (data) { | |
| 856 | - | |
| 857 | - if(data.articles.length === 0){ | |
| 858 | - return; | |
| 771 | + }, | |
| 772 | + navigateToCategory: function(categoryId){ | |
| 773 | + if(categoryId === undefined){ | |
| 774 | + this.display_category_tab(); | |
| 775 | + }else{ | |
| 776 | + this.display_proposal_by_category('proposal-item-' + categoryId); | |
| 859 | 777 | } |
| 778 | + }, | |
| 779 | + oauthClientAction: function(url) { | |
| 780 | + var child = window.open(url, '_blank'); | |
| 781 | + var interval = setInterval(function() { | |
| 782 | + try { | |
| 783 | + if(!child.closed) { | |
| 784 | + child.postMessage({ | |
| 785 | + message: 'requestOauthClientPluginResult' | |
| 786 | + }, '*'); | |
| 787 | + } | |
| 788 | + } | |
| 789 | + catch(e) { | |
| 790 | + // we're here when the child window has been navigated away or closed | |
| 791 | + if (child.closed) { | |
| 792 | + clearInterval(interval); | |
| 793 | + return; | |
| 794 | + } | |
| 795 | + } | |
| 796 | + }, 300); | |
| 797 | + }, | |
| 798 | + displaySuccess: function(container, text, timeout, iconClass) { | |
| 799 | + timeout = typeof timeout !== 'undefined' ? timeout : 2000; | |
| 800 | + container.css('opacity', 0.1); | |
| 801 | + var successPanel = $('.success-panel').clone(); | |
| 802 | + successPanel.find('.icon').addClass(iconClass); | |
| 803 | + successPanel.find('.message').html(text); | |
| 804 | + successPanel.appendTo(container.closest('.categories')); | |
| 805 | + successPanel.show(); | |
| 806 | + successPanel.css('top', Math.max(0, ((container.height() - successPanel.outerHeight()) / 2) + container.offset().top) + 'px'); | |
| 807 | + successPanel.css('left', Math.max(0, ((container.width() - successPanel.outerWidth()) / 2) + container.offset().left) + 'px'); | |
| 808 | + | |
| 809 | + setTimeout(function() { | |
| 810 | + successPanel.hide(); | |
| 811 | + container.css('opacity', 1); | |
| 812 | + successPanel.remove(); | |
| 813 | + }, timeout); | |
| 814 | + }, | |
| 815 | + setUser: function(user){ | |
| 816 | + this.user = user; | |
| 817 | + }, | |
| 818 | + getUser: function(){ | |
| 819 | + return this.user; | |
| 820 | + }, | |
| 821 | + showLogin: function(){ | |
| 822 | + $('#login-button').show(); | |
| 823 | + $('#logout-button').hide(); | |
| 824 | + }, | |
| 825 | + showLogout: function(){ | |
| 826 | + $('#login-button').hide(); | |
| 827 | + var name = ''; | |
| 828 | + var user = Main.getUser(); | |
| 829 | + if(user){ | |
| 830 | + if(user.person && user.person.name){ | |
| 831 | + name = user.person.name + ' - '; | |
| 832 | + }else{ | |
| 833 | + name = user.login + ' - '; | |
| 834 | + } | |
| 860 | 835 | |
| 861 | - // FIXME fix api and remove this | |
| 862 | - var article;//data.articles[0]; | |
| 863 | - for(var i=0; i<data.articles.length; i++) { | |
| 864 | - if($.grep(data.articles[i].categories, function(e){ return e.id == cat_id; }).length>0) { | |
| 865 | - article = data.articles[i]; | |
| 836 | + } | |
| 837 | + $('#logout-button .name').text(name); | |
| 838 | + $('#logout-button').show(); | |
| 839 | + }, | |
| 840 | + responseToText: function(responseJSONmessage){ | |
| 841 | + var o = JSON.parse(responseJSONmessage); | |
| 842 | + var msg = ''; | |
| 843 | + var fn; | |
| 844 | + | |
| 845 | + for (var key in o) { | |
| 846 | + if (o[key] instanceof Array) { | |
| 847 | + fn = key; | |
| 848 | + for (var i = 0; i < o[key].length; i++) { | |
| 849 | + msg += fn + ' ' + o[key][i] + '</br>'; | |
| 850 | + } | |
| 866 | 851 | } |
| 867 | 852 | } |
| 853 | + msg = msg.replace(/login incorrect format/g,"campo \"nome do usuário\" está com formato inválido. O mesmo só pode ser composto por letras minúsculas, números, '_' e '-'. Adicionalmente não é permitido usar acentuação nem começar com '_' ou '-'"); | |
| 854 | + msg = msg.replace('password_confirmation', 'campo "confirmação da senha"'); | |
| 855 | + msg = msg.replace(/password/g, 'campo "senha"'); | |
| 856 | + msg = msg.replace(/login/g, 'campo "nome de usuário"'); | |
| 857 | + msg = msg.replace('email', 'campo "e-mail"'); | |
| 858 | + msg = msg.substring(0, msg.length - 5) + '.'; | |
| 859 | + return msg; | |
| 860 | + }, | |
| 861 | + display_events: function(cat_id, active_category) { | |
| 862 | + //var url = host + '/api/v1/communities/' + dialoga_community + '/articles?categories_ids[]=' + cat_id + '&content_type=Event&private_token=' + '375bee7e17d0021af7160ce664874618'; | |
| 863 | + var url = host + '/api/v1/communities/' + dialoga_community + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; | |
| 864 | + $.getJSON(url).done(function (data) { | |
| 868 | 865 | |
| 869 | - var dt = article.start_date; | |
| 870 | - var date = dt.substr(8, 2) + '/' + dt.substr(5, 2) + '/' + dt.substr(0, 4); | |
| 871 | - var dd = new Date(dt); | |
| 872 | - var time = dd.getHours() + ':' + (dd.getMinutes()<10?'0':'') + dd.getMinutes(); | |
| 873 | - var params = {event: article, date: date, time: time, category: article.categories[0].name, category_class: active_category}; | |
| 874 | - //$.getJSON(host+'/api/v1/articles/'+article.id+'/followers?private_token=' + '375bee7e17d0021af7160ce664874618' + '&_='+new Date().getTime()).done(function (data) { | |
| 875 | - $.getJSON(host+'/api/v1/articles/'+article.id+'/followers?_='+new Date().getTime()).done(function (data) { | |
| 876 | - //FIXME do not depend on this request | |
| 877 | - params.total_followers = data.total_followers; | |
| 878 | - $('.calendar-container').html(calendarTemplate(params)); | |
| 879 | - $('.calendar-container .calendar.' + active_category).show(); | |
| 880 | - // $('.calendar-container .calendar').slick(); | |
| 881 | - | |
| 882 | - $(document).off('click', '#talk__button-participate'); | |
| 883 | - $(document).on('click', '#talk__button-participate', function(e) { | |
| 884 | - e.preventDefault(); | |
| 885 | - var $bt = $(this); | |
| 886 | - if(!logged_in) { | |
| 887 | - $('#login-button').click(); | |
| 888 | - $('html, body').animate({scrollTop: 0}, 'fast'); | |
| 889 | - } else { | |
| 890 | - $.ajax({ | |
| 891 | - type: 'post', | |
| 892 | - url: host + '/api/v1/articles/' + $(this).data('event-id') + '/follow', | |
| 893 | - data: { | |
| 894 | - private_token: Main.private_token | |
| 895 | - } | |
| 896 | - }).done(function(data) { | |
| 897 | - var message = 'Sua participação foi registrada com sucesso'; | |
| 898 | - if(!data.success) { | |
| 899 | - message = 'Sua participação já foi registrada'; | |
| 900 | - } else { | |
| 901 | - var value= $bt.closest('.talk__participate').find('.talk__value'); | |
| 902 | - value.text(parseInt(value.text()) + 1); | |
| 903 | - } | |
| 904 | - Main.displaySuccess($bt.closest('.talk__participate'), message, 2000, 'icon-proposal-sent'); | |
| 905 | - }); | |
| 866 | + if(data.articles.length === 0){ | |
| 867 | + return; | |
| 868 | + } | |
| 869 | + | |
| 870 | + // FIXME fix api and remove this | |
| 871 | + var article;//data.articles[0]; | |
| 872 | + for(var i=0; i<data.articles.length; i++) { | |
| 873 | + if($.grep(data.articles[i].categories, function(e){ return e.id == cat_id; }).length>0) { | |
| 874 | + article = data.articles[i]; | |
| 906 | 875 | } |
| 907 | - }); | |
| 876 | + } | |
| 877 | + | |
| 878 | + var dt = article.start_date; | |
| 879 | + var date = dt.substr(8, 2) + '/' + dt.substr(5, 2) + '/' + dt.substr(0, 4); | |
| 880 | + var dd = new Date(dt); | |
| 881 | + var time = dd.getHours() + ':' + (dd.getMinutes()<10?'0':'') + dd.getMinutes(); | |
| 882 | + var params = {event: article, date: date, time: time, category: article.categories[0].name, category_class: active_category}; | |
| 883 | + //$.getJSON(host+'/api/v1/articles/'+article.id+'/followers?private_token=' + '375bee7e17d0021af7160ce664874618' + '&_='+new Date().getTime()).done(function (data) { | |
| 884 | + $.getJSON(host+'/api/v1/articles/'+article.id+'/followers?_='+new Date().getTime()).done(function (data) { | |
| 885 | + //FIXME do not depend on this request | |
| 886 | + params.total_followers = data.total_followers; | |
| 887 | + $('.calendar-container').html(calendarTemplate(params)); | |
| 888 | + $('.calendar-container .calendar.' + active_category).show(); | |
| 889 | + // $('.calendar-container .calendar').slick(); | |
| 890 | + | |
| 891 | + $(document).off('click', '#talk__button-participate'); | |
| 892 | + $(document).on('click', '#talk__button-participate', function(e) { | |
| 893 | + e.preventDefault(); | |
| 894 | + var $bt = $(this); | |
| 895 | + if(!logged_in) { | |
| 896 | + $('#login-button').click(); | |
| 897 | + $('html, body').animate({scrollTop: 0}, 'fast'); | |
| 898 | + } else { | |
| 899 | + $.ajax({ | |
| 900 | + type: 'post', | |
| 901 | + url: host + '/api/v1/articles/' + $(this).data('event-id') + '/follow', | |
| 902 | + data: { | |
| 903 | + private_token: Main.private_token | |
| 904 | + } | |
| 905 | + }).done(function(data) { | |
| 906 | + var message = 'Sua participação foi registrada com sucesso'; | |
| 907 | + if(!data.success) { | |
| 908 | + message = 'Sua participação já foi registrada'; | |
| 909 | + } else { | |
| 910 | + var value= $bt.closest('.talk__participate').find('.talk__value'); | |
| 911 | + value.text(parseInt(value.text()) + 1); | |
| 912 | + } | |
| 913 | + Main.displaySuccess($bt.closest('.talk__participate'), message, 2000, 'icon-proposal-sent'); | |
| 914 | + }); | |
| 915 | + } | |
| 916 | + }); | |
| 908 | 917 | |
| 918 | + }); | |
| 909 | 919 | }); |
| 910 | - }); | |
| 911 | - }, | |
| 912 | - reloadCaptcha: function(element) { | |
| 913 | - var $element = $(element); | |
| 914 | - if($element.data('captcha')){ | |
| 915 | - $element.data('captcha').recarregar(); | |
| 916 | - } | |
| 917 | - }, | |
| 918 | - initCaptcha: function(element) { | |
| 919 | - var $element = $(element); | |
| 920 | - if($element.data('captcha')) return; | |
| 921 | - | |
| 922 | - $element.val(''); | |
| 923 | - var oCaptcha_serpro_gov_br = new captcha_serpro_gov_br(); | |
| 924 | - $element.data('captcha', oCaptcha_serpro_gov_br); | |
| 925 | - oCaptcha_serpro_gov_br.clienteId = serpro_captcha_clienteId; | |
| 926 | - if(!localDevelopment) { | |
| 927 | - oCaptcha_serpro_gov_br.url = "/serprocaptcha" | |
| 928 | - } | |
| 929 | - oCaptcha_serpro_gov_br.criarUI(element, 'css', 'serpro_captcha_component_', Main.guid()); | |
| 930 | - }, | |
| 931 | - computeBoxHeight: function(){ | |
| 932 | - var hPerLineOnTitle = 25; | |
| 933 | - var hPerLineOnParagraph = 20; | |
| 934 | - var maxLinesByParagraph = 0; | |
| 935 | - var maxLinesByTitle = 0; | |
| 936 | - var $visibleProposals = $('.proposal-list .proposal-item:visible'); | |
| 937 | - | |
| 938 | - // get the bigger paragraph | |
| 939 | - $visibleProposals.each(function(index, proposalItemEl){ | |
| 940 | - var $proposalItemEl = $(proposalItemEl); | |
| 941 | - var $paragraph = $proposalItemEl.find('p'); | |
| 942 | - var lines = Main.computeLines($paragraph); | |
| 943 | - if(lines > maxLinesByParagraph ){ | |
| 944 | - maxLinesByParagraph = lines; | |
| 920 | + }, | |
| 921 | + reloadCaptcha: function(element) { | |
| 922 | + var $element = $(element); | |
| 923 | + if($element.data('captcha')){ | |
| 924 | + $element.data('captcha').recarregar(); | |
| 945 | 925 | } |
| 946 | - }); | |
| 947 | - // console.log('maxLinesByParagraph', maxLinesByParagraph); | |
| 948 | - | |
| 949 | - // get the bigger title | |
| 950 | - $visibleProposals.each(function(index, proposalItemEl){ | |
| 951 | - var $proposalItemEl = $(proposalItemEl); | |
| 952 | - var $title = $proposalItemEl.find('.box__title'); | |
| 953 | - var lines = Main.computeLines($title); | |
| 954 | - if(lines > maxLinesByTitle ){ | |
| 955 | - maxLinesByTitle = lines; | |
| 926 | + }, | |
| 927 | + initCaptcha: function(element) { | |
| 928 | + var $element = $(element); | |
| 929 | + if($element.data('captcha')) return; | |
| 930 | + | |
| 931 | + $element.val(''); | |
| 932 | + var oCaptcha_serpro_gov_br = new captcha_serpro_gov_br(); | |
| 933 | + $element.data('captcha', oCaptcha_serpro_gov_br); | |
| 934 | + oCaptcha_serpro_gov_br.clienteId = serpro_captcha_clienteId; | |
| 935 | + if(!localDevelopment) { | |
| 936 | + oCaptcha_serpro_gov_br.url = "/serprocaptcha" | |
| 956 | 937 | } |
| 957 | - }); | |
| 958 | - // console.log('maxLinesByTitle', maxLinesByTitle); | |
| 938 | + oCaptcha_serpro_gov_br.criarUI(element, 'css', 'serpro_captcha_component_', Main.guid()); | |
| 939 | + }, | |
| 940 | + computeBoxHeight: function(){ | |
| 941 | + var hPerLineOnTitle = 25; | |
| 942 | + var hPerLineOnParagraph = 20; | |
| 943 | + var maxLinesByParagraph = 0; | |
| 944 | + var maxLinesByTitle = 0; | |
| 945 | + var $visibleProposals = $('.proposal-list .proposal-item:visible'); | |
| 946 | + | |
| 947 | + // get the bigger paragraph | |
| 948 | + $visibleProposals.each(function(index, proposalItemEl){ | |
| 949 | + var $proposalItemEl = $(proposalItemEl); | |
| 950 | + var $paragraph = $proposalItemEl.find('p'); | |
| 951 | + var lines = Main.computeLines($paragraph); | |
| 952 | + if(lines > maxLinesByParagraph ){ | |
| 953 | + maxLinesByParagraph = lines; | |
| 954 | + } | |
| 955 | + }); | |
| 956 | + // console.log('maxLinesByParagraph', maxLinesByParagraph); | |
| 957 | + | |
| 958 | + // get the bigger title | |
| 959 | + $visibleProposals.each(function(index, proposalItemEl){ | |
| 960 | + var $proposalItemEl = $(proposalItemEl); | |
| 961 | + var $title = $proposalItemEl.find('.box__title'); | |
| 962 | + var lines = Main.computeLines($title); | |
| 963 | + if(lines > maxLinesByTitle ){ | |
| 964 | + maxLinesByTitle = lines; | |
| 965 | + } | |
| 966 | + }); | |
| 967 | + // console.log('maxLinesByTitle', maxLinesByTitle); | |
| 959 | 968 | |
| 960 | - $visibleProposals.each(function(index, proposalItemEl){ | |
| 961 | - var $proposalItemEl = $(proposalItemEl); | |
| 962 | - var $title = $proposalItemEl.find('.box__title'); | |
| 963 | - var $paragraph = $proposalItemEl.find('p'); | |
| 969 | + $visibleProposals.each(function(index, proposalItemEl){ | |
| 970 | + var $proposalItemEl = $(proposalItemEl); | |
| 971 | + var $title = $proposalItemEl.find('.box__title'); | |
| 972 | + var $paragraph = $proposalItemEl.find('p'); | |
| 964 | 973 | |
| 965 | - var newTitleHeight = maxLinesByTitle * hPerLineOnTitle; | |
| 966 | - var newParagraphHeight = maxLinesByParagraph * hPerLineOnParagraph; | |
| 974 | + var newTitleHeight = maxLinesByTitle * hPerLineOnTitle; | |
| 975 | + var newParagraphHeight = maxLinesByParagraph * hPerLineOnParagraph; | |
| 967 | 976 | |
| 968 | - $title.css('height', newTitleHeight + 'px'); | |
| 969 | - $paragraph.css('height', newParagraphHeight + 'px'); | |
| 970 | - }); | |
| 977 | + $title.css('height', newTitleHeight + 'px'); | |
| 978 | + $paragraph.css('height', newParagraphHeight + 'px'); | |
| 979 | + }); | |
| 971 | 980 | |
| 972 | - // recalc box heights | |
| 973 | - var setAsPx = true; | |
| 974 | - $visibleProposals.equalHeights(setAsPx); | |
| 975 | - }, | |
| 976 | - computeLines: function ($el) { | |
| 977 | - // reset height | |
| 978 | - $el.height('auto'); | |
| 979 | - | |
| 980 | - var divHeight = $el.height(); | |
| 981 | - var lineHeight = parseInt($el.css('lineHeight')); | |
| 982 | - var lines = Math.ceil(divHeight / lineHeight); | |
| 983 | - return lines; | |
| 984 | - }, | |
| 985 | - handleLoginSuccess: function (e, data){ | |
| 986 | - if(data.person){ | |
| 987 | - Main.setUser({person: data.person}); | |
| 988 | - } | |
| 989 | - Main.loginCallback(data.activated, data.private_token); | |
| 990 | - }, | |
| 991 | - handleLoginFail: function (e){ | |
| 992 | - console.error('handleLoginFail', e); | |
| 993 | - }, | |
| 994 | - changeUserPassword: function(code){ | |
| 995 | - if(!code || code.length == 0) return; | |
| 996 | - var $loginPanel = $('#login-panel'); | |
| 997 | - $loginPanel.show(); | |
| 998 | - $loginPanel.find('#login-form').hide(); | |
| 999 | - var $newPasswordForm = $loginPanel.find('#new-password-form'); | |
| 1000 | - $newPasswordForm.find('#new-password-code').val(code); | |
| 1001 | - $newPasswordForm.show(); | |
| 1002 | - }, | |
| 1003 | - activateUser: function(code){ | |
| 1004 | - | |
| 1005 | - /** | |
| 1006 | - * @TODO Import database of dialoga.gov.br into local | |
| 1007 | - * and test the activation with new url | |
| 1008 | - */ | |
| 1009 | - if(code && code.length > 0){ | |
| 1010 | - $.ajax({ | |
| 1011 | - method: 'PATCH', | |
| 1012 | - url:host+'/api/v1/activate', | |
| 1013 | - data: { | |
| 1014 | - private_token: Main.private_token, | |
| 1015 | - activation_code: code | |
| 1016 | - }, | |
| 1017 | - success:function(response, textStatus, xhr){ | |
| 1018 | - | |
| 1019 | - if(xhr != 202){ | |
| 1020 | - $('.activate-message').html('Usuário ativado com sucesso') | |
| 1021 | - .removeClass('alert-danger') | |
| 1022 | - .addClass('alert-success') | |
| 1023 | - .show(); | |
| 1024 | - | |
| 1025 | - $(document).trigger('login:success', response); | |
| 1026 | - } | |
| 981 | + // recalc box heights | |
| 982 | + var setAsPx = true; | |
| 983 | + $visibleProposals.equalHeights(setAsPx); | |
| 984 | + }, | |
| 985 | + computeLines: function ($el) { | |
| 986 | + // reset height | |
| 987 | + $el.height('auto'); | |
| 988 | + | |
| 989 | + var divHeight = $el.height(); | |
| 990 | + var lineHeight = parseInt($el.css('lineHeight')); | |
| 991 | + var lines = Math.ceil(divHeight / lineHeight); | |
| 992 | + return lines; | |
| 993 | + }, | |
| 994 | + handleLoginSuccess: function (e, data){ | |
| 995 | + if(data.person){ | |
| 996 | + Main.setUser({person: data.person}); | |
| 997 | + } | |
| 998 | + Main.loginCallback(data.activated, data.private_token); | |
| 999 | + }, | |
| 1000 | + handleLoginFail: function (e){ | |
| 1001 | + console.error('handleLoginFail', e); | |
| 1002 | + }, | |
| 1003 | + changeUserPassword: function(code){ | |
| 1004 | + if(!code || code.length == 0) return; | |
| 1005 | + var $loginPanel = $('#login-panel'); | |
| 1006 | + $loginPanel.show(); | |
| 1007 | + $loginPanel.find('#login-form').hide(); | |
| 1008 | + var $newPasswordForm = $loginPanel.find('#new-password-form'); | |
| 1009 | + $newPasswordForm.find('#new-password-code').val(code); | |
| 1010 | + $newPasswordForm.show(); | |
| 1011 | + }, | |
| 1012 | + activateUser: function(code){ | |
| 1013 | + | |
| 1014 | + /** | |
| 1015 | + * @TODO Import database of dialoga.gov.br into local | |
| 1016 | + * and test the activation with new url | |
| 1017 | + */ | |
| 1018 | + if(code && code.length > 0){ | |
| 1019 | + $.ajax({ | |
| 1020 | + method: 'PATCH', | |
| 1021 | + url:host+'/api/v1/activate', | |
| 1022 | + data: { | |
| 1023 | + private_token: Main.private_token, | |
| 1024 | + activation_code: code | |
| 1025 | + }, | |
| 1026 | + success:function(response, textStatus, xhr){ | |
| 1027 | + | |
| 1028 | + if(xhr != 202){ | |
| 1029 | + $('.activate-message').html('Usuário ativado com sucesso') | |
| 1030 | + .removeClass('alert-danger') | |
| 1031 | + .addClass('alert-success') | |
| 1032 | + .show(); | |
| 1033 | + | |
| 1034 | + $(document).trigger('login:success', response); | |
| 1035 | + } | |
| 1027 | 1036 | |
| 1028 | - }, | |
| 1029 | - error:function(xhr, textStatus, errorTrown){ | |
| 1030 | - if(xhr.status == 412){ | |
| 1031 | - $('.activate-message').html('<strong>Erro:</strong> O código de ativação é inválido') | |
| 1032 | - .removeClass('alert-success') | |
| 1033 | - .addClass('alert-danger') | |
| 1034 | - .show(); | |
| 1037 | + }, | |
| 1038 | + error:function(xhr, textStatus, errorTrown){ | |
| 1039 | + if(xhr.status == 412){ | |
| 1040 | + $('.activate-message').html('<strong>Erro:</strong> O código de ativação é inválido') | |
| 1041 | + .removeClass('alert-success') | |
| 1042 | + .addClass('alert-danger') | |
| 1043 | + .show(); | |
| 1044 | + } | |
| 1035 | 1045 | } |
| 1036 | - } | |
| 1037 | - }); | |
| 1046 | + }); | |
| 1047 | + } | |
| 1038 | 1048 | } |
| 1039 | - } | |
| 1040 | - }; | |
| 1041 | - })(); | |
| 1042 | - | |
| 1043 | - | |
| 1044 | - var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + Main.private_token + '&fields=id,children,categories,abstract,title,image,url,setting,position'; | |
| 1045 | - | |
| 1046 | - $.getJSON(noosferoAPI) | |
| 1047 | - .done(function( data ) { | |
| 1048 | - data.host = host; | |
| 1049 | - data.private_token = Main.private_token; | |
| 1049 | + }; | |
| 1050 | + })(); | |
| 1050 | 1051 | |
| 1051 | - // check youtube iframe | |
| 1052 | - function forceWmodeIframe(article){ | |
| 1053 | - var abstract = article.abstract; | |
| 1054 | - // console.log('article.abstract', article.abstract); | |
| 1055 | 1052 | |
| 1056 | - var patternIframe = '<iframe src="'; | |
| 1057 | - var indexOfIframe = abstract.indexOf(patternIframe); | |
| 1053 | + var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + Main.private_token + '&fields=id,children,categories,abstract,title,image,url,setting,position'; | |
| 1058 | 1054 | |
| 1059 | - if(indexOfIframe === -1){ | |
| 1060 | - return; | |
| 1061 | - } | |
| 1055 | + $.getJSON(noosferoAPI) | |
| 1056 | + .done(function( data ) { | |
| 1057 | + data.host = host; | |
| 1058 | + data.private_token = Main.private_token; | |
| 1062 | 1059 | |
| 1063 | - var startSrcUrl = indexOfIframe + patternIframe.length; | |
| 1064 | - var endSrcUrl = abstract.indexOf('"', startSrcUrl); | |
| 1065 | - var url = abstract.substring(startSrcUrl , endSrcUrl); | |
| 1066 | - // console.log('url', url); | |
| 1060 | + // check youtube iframe | |
| 1061 | + function forceWmodeIframe(article){ | |
| 1062 | + var abstract = article.abstract; | |
| 1063 | + // console.log('article.abstract', article.abstract); | |
| 1067 | 1064 | |
| 1068 | - if(url.indexOf('wmode=opaque') !== -1){ | |
| 1069 | - // already in opaque mode | |
| 1070 | - // console.debug('already in opaque mode'); | |
| 1071 | - return; | |
| 1072 | - } | |
| 1073 | - var c = ''; | |
| 1074 | - if(url.indexOf('?') !== -1){ | |
| 1075 | - c = '&'; | |
| 1076 | - } | |
| 1065 | + var patternIframe = '<iframe src="'; | |
| 1066 | + var indexOfIframe = abstract.indexOf(patternIframe); | |
| 1077 | 1067 | |
| 1078 | - var resultUrl = url + c + 'wmode=opaque'; | |
| 1079 | - article.abstract = abstract.replace(url, resultUrl); | |
| 1080 | - // console.log('article.abstract', article.abstract); | |
| 1081 | - } | |
| 1082 | - | |
| 1083 | - forceWmodeIframe(data.article); | |
| 1068 | + if(indexOfIframe === -1){ | |
| 1069 | + return; | |
| 1070 | + } | |
| 1084 | 1071 | |
| 1085 | - function removeStylefromIframe (article){ | |
| 1086 | - var abstract = article.abstract; | |
| 1072 | + var startSrcUrl = indexOfIframe + patternIframe.length; | |
| 1073 | + var endSrcUrl = abstract.indexOf('"', startSrcUrl); | |
| 1074 | + var url = abstract.substring(startSrcUrl , endSrcUrl); | |
| 1075 | + // console.log('url', url); | |
| 1087 | 1076 | |
| 1088 | - var patternIframe = 'style="'; | |
| 1089 | - var indexOfIframe = abstract.indexOf('<iframe'); | |
| 1090 | - var indexOfStyleOnIframe = abstract.indexOf('style="', indexOfIframe); | |
| 1077 | + if(url.indexOf('wmode=opaque') !== -1){ | |
| 1078 | + // already in opaque mode | |
| 1079 | + // console.debug('already in opaque mode'); | |
| 1080 | + return; | |
| 1081 | + } | |
| 1082 | + var c = ''; | |
| 1083 | + if(url.indexOf('?') !== -1){ | |
| 1084 | + c = '&'; | |
| 1085 | + } | |
| 1091 | 1086 | |
| 1092 | - if(indexOfStyleOnIframe === -1){ | |
| 1093 | - return; | |
| 1087 | + var resultUrl = url + c + 'wmode=opaque'; | |
| 1088 | + article.abstract = abstract.replace(url, resultUrl); | |
| 1089 | + // console.log('article.abstract', article.abstract); | |
| 1094 | 1090 | } |
| 1095 | 1091 | |
| 1096 | - var startStyleContent = indexOfStyleOnIframe + patternIframe.length; | |
| 1097 | - var endStyleContent = abstract.indexOf('"', startStyleContent); | |
| 1098 | - var style = abstract.substring(startStyleContent , endStyleContent); | |
| 1099 | - // console.log('style', style); | |
| 1092 | + forceWmodeIframe(data.article); | |
| 1100 | 1093 | |
| 1101 | - article.abstract = abstract.replace(style, ''); | |
| 1102 | - // console.log('article.abstract', article.abstract); | |
| 1103 | - } | |
| 1094 | + function removeStylefromIframe (article){ | |
| 1095 | + var abstract = article.abstract; | |
| 1104 | 1096 | |
| 1105 | - removeStylefromIframe(data.article); | |
| 1097 | + var patternIframe = 'style="'; | |
| 1098 | + var indexOfIframe = abstract.indexOf('<iframe'); | |
| 1099 | + var indexOfStyleOnIframe = abstract.indexOf('style="', indexOfIframe); | |
| 1106 | 1100 | |
| 1107 | - resultsPlaceholder.innerHTML = template(data); | |
| 1108 | - $('.login-container').html(loginTemplate()); | |
| 1109 | - $('.countdown').maxlength({text: '%left caracteres restantes'}); | |
| 1101 | + if(indexOfStyleOnIframe === -1){ | |
| 1102 | + return; | |
| 1103 | + } | |
| 1110 | 1104 | |
| 1111 | - $(document).on('click', '.oauth-login', function (e){ | |
| 1112 | - Main.oauthClientAction($(this).attr('href')); | |
| 1113 | - e.preventDefault(); | |
| 1114 | - }); | |
| 1105 | + var startStyleContent = indexOfStyleOnIframe + patternIframe.length; | |
| 1106 | + var endStyleContent = abstract.indexOf('"', startStyleContent); | |
| 1107 | + var style = abstract.substring(startStyleContent , endStyleContent); | |
| 1108 | + // console.log('style', style); | |
| 1115 | 1109 | |
| 1116 | - // create login panel on header | |
| 1117 | - (function (){ | |
| 1118 | - var loginPanelId = '#login-panel'; | |
| 1119 | - var $loginPanel = $(loginPanelId); | |
| 1120 | - $loginPanel.hide(); | |
| 1121 | - $loginPanel.removeClass('hide'); | |
| 1122 | - $loginPanel.append(loginTemplate()); | |
| 1123 | - $loginPanel.find('.actions') | |
| 1124 | - .removeClass('col-sm-4') | |
| 1125 | - .addClass('col-sm-12'); | |
| 1126 | - $loginPanel.find('.oauth') | |
| 1127 | - .removeClass('col-sm-8') | |
| 1128 | - .addClass('col-sm-12'); | |
| 1129 | - $loginPanel.find('.new-user').parent() | |
| 1130 | - .removeClass('col-sm-4') | |
| 1131 | - .addClass('col-sm-12'); | |
| 1132 | - | |
| 1133 | - if(logged_in){ | |
| 1134 | - Main.showLogout(); | |
| 1110 | + article.abstract = abstract.replace(style, ''); | |
| 1111 | + // console.log('article.abstract', article.abstract); | |
| 1135 | 1112 | } |
| 1136 | 1113 | |
| 1137 | - $(document).on('click', '#login-button', function (e){ | |
| 1114 | + removeStylefromIframe(data.article); | |
| 1115 | + | |
| 1116 | + resultsPlaceholder.innerHTML = template(data); | |
| 1117 | + $('.login-container').html(loginTemplate()); | |
| 1118 | + $('.countdown').maxlength({text: '%left caracteres restantes'}); | |
| 1119 | + | |
| 1120 | + $(document).on('click', '.oauth-login', function (e){ | |
| 1121 | + Main.oauthClientAction($(this).attr('href')); | |
| 1138 | 1122 | e.preventDefault(); |
| 1139 | - loginButton = $(this); | |
| 1140 | - $loginPanel.toggle(); | |
| 1141 | 1123 | }); |
| 1142 | 1124 | |
| 1143 | - // handle click on elsewhere (out of loginPanel) | |
| 1144 | - $(document).click(function(e){ | |
| 1145 | - var $target = $(e.target); | |
| 1125 | + // create login panel on header | |
| 1126 | + (function (){ | |
| 1127 | + var loginPanelId = '#login-panel'; | |
| 1128 | + var $loginPanel = $(loginPanelId); | |
| 1129 | + $loginPanel.hide(); | |
| 1130 | + $loginPanel.removeClass('hide'); | |
| 1131 | + $loginPanel.append(loginTemplate()); | |
| 1132 | + $loginPanel.find('.actions') | |
| 1133 | + .removeClass('col-sm-4') | |
| 1134 | + .addClass('col-sm-12'); | |
| 1135 | + $loginPanel.find('.oauth') | |
| 1136 | + .removeClass('col-sm-8') | |
| 1137 | + .addClass('col-sm-12'); | |
| 1138 | + $loginPanel.find('.new-user').parent() | |
| 1139 | + .removeClass('col-sm-4') | |
| 1140 | + .addClass('col-sm-12'); | |
| 1141 | + | |
| 1142 | + if(logged_in){ | |
| 1143 | + Main.showLogout(); | |
| 1144 | + } | |
| 1146 | 1145 | |
| 1147 | - var isLoginButton = ($target.attr('id') === 'login-button'); | |
| 1148 | - var isLoginButtonIcon = $target.hasClass('icon-login'); | |
| 1149 | - var requireLogin = $target.hasClass('require-main-login'); | |
| 1150 | - var isChildOfPanel = ($target.closest(loginPanelId).length !== 0); | |
| 1146 | + $(document).on('click', '#login-button', function (e){ | |
| 1147 | + e.preventDefault(); | |
| 1148 | + loginButton = $(this); | |
| 1149 | + $loginPanel.toggle(); | |
| 1150 | + }); | |
| 1151 | 1151 | |
| 1152 | - if( !isLoginButton && !isLoginButtonIcon && !isChildOfPanel && !requireLogin ){ | |
| 1153 | - $loginPanel.hide(); | |
| 1154 | - } | |
| 1155 | - }); | |
| 1152 | + // handle click on elsewhere (out of loginPanel) | |
| 1153 | + $(document).click(function(e){ | |
| 1154 | + var $target = $(e.target); | |
| 1156 | 1155 | |
| 1157 | - // handle esc | |
| 1158 | - $(document).keyup(function(e) { | |
| 1156 | + var isLoginButton = ($target.attr('id') === 'login-button'); | |
| 1157 | + var isLoginButtonIcon = $target.hasClass('icon-login'); | |
| 1158 | + var requireLogin = $target.hasClass('require-main-login'); | |
| 1159 | + var isChildOfPanel = ($target.closest(loginPanelId).length !== 0); | |
| 1159 | 1160 | |
| 1160 | - // escape key maps to keycode `27` | |
| 1161 | - if (e.keyCode === 27) { // ESC | |
| 1162 | - $loginPanel.hide(); | |
| 1163 | - } | |
| 1164 | - }); | |
| 1161 | + if( !isLoginButton && !isLoginButtonIcon && !isChildOfPanel && !requireLogin ){ | |
| 1162 | + $loginPanel.hide(); | |
| 1163 | + } | |
| 1164 | + }); | |
| 1165 | 1165 | |
| 1166 | - $('.participar').removeClass('hide'); | |
| 1167 | - })(); | |
| 1166 | + // handle esc | |
| 1167 | + $(document).keyup(function(e) { | |
| 1168 | 1168 | |
| 1169 | - Main.navigateTo(window.location.hash); | |
| 1169 | + // escape key maps to keycode `27` | |
| 1170 | + if (e.keyCode === 27) { // ESC | |
| 1171 | + $loginPanel.hide(); | |
| 1172 | + } | |
| 1173 | + }); | |
| 1170 | 1174 | |
| 1171 | - //Actions for links | |
| 1172 | - $( '#nav-proposal-categories a' ).on('click', function(e){ | |
| 1173 | - e.preventDefault(); | |
| 1175 | + $('.participar').removeClass('hide'); | |
| 1176 | + })(); | |
| 1174 | 1177 | |
| 1175 | - var $link = $(this); | |
| 1178 | + Main.navigateTo(window.location.hash); | |
| 1176 | 1179 | |
| 1177 | - // Update URL and Navigate | |
| 1178 | - Main.updateHash($link.attr('href')); | |
| 1180 | + //Actions for links | |
| 1181 | + $( '#nav-proposal-categories a' ).on('click', function(e){ | |
| 1182 | + e.preventDefault(); | |
| 1179 | 1183 | |
| 1180 | - }); | |
| 1184 | + var $link = $(this); | |
| 1181 | 1185 | |
| 1182 | - $( '#nav-proposal-group a' ).on('click', function(e){ | |
| 1183 | - e.preventDefault(); | |
| 1186 | + // Update URL and Navigate | |
| 1187 | + Main.updateHash($link.attr('href')); | |
| 1184 | 1188 | |
| 1185 | - var $link = $(this); | |
| 1189 | + }); | |
| 1186 | 1190 | |
| 1187 | - // Update URL and Navigate | |
| 1188 | - Main.updateHash($link.attr('href')); | |
| 1189 | - }); | |
| 1191 | + $( '#nav-proposal-group a' ).on('click', function(e){ | |
| 1192 | + e.preventDefault(); | |
| 1190 | 1193 | |
| 1191 | - $( '.proposal-item a' ).on('click', function(e){ | |
| 1192 | - e.preventDefault(); | |
| 1194 | + var $link = $(this); | |
| 1193 | 1195 | |
| 1194 | - var $link = $(this); | |
| 1196 | + // Update URL and Navigate | |
| 1197 | + Main.updateHash($link.attr('href')); | |
| 1198 | + }); | |
| 1195 | 1199 | |
| 1196 | - // Update URL and Navigate | |
| 1197 | - Main.updateHash($link.attr('href')); | |
| 1198 | - }); | |
| 1200 | + $( '.proposal-item a' ).on('click', function(e){ | |
| 1201 | + e.preventDefault(); | |
| 1199 | 1202 | |
| 1200 | - $( '.proposal-category a' ).on('click', function(e){ | |
| 1201 | - e.preventDefault(); | |
| 1203 | + var $link = $(this); | |
| 1202 | 1204 | |
| 1203 | - var $link = $(this); | |
| 1205 | + // Update URL and Navigate | |
| 1206 | + Main.updateHash($link.attr('href')); | |
| 1207 | + }); | |
| 1204 | 1208 | |
| 1205 | - // Update URL and Navigate | |
| 1206 | - Main.updateHash($link.attr('href')); | |
| 1207 | - }); | |
| 1209 | + $( '.proposal-category a' ).on('click', function(e){ | |
| 1210 | + e.preventDefault(); | |
| 1208 | 1211 | |
| 1209 | - $( '.proposal-category .go-back' ).on('click', function(e){ | |
| 1210 | - e.preventDefault(); | |
| 1212 | + var $link = $(this); | |
| 1211 | 1213 | |
| 1212 | - var oldHash = window.location.hash; | |
| 1213 | - var regexSobreOPrograma = /sobre-o-programa$/; | |
| 1214 | - var isSubpage = regexSobreOPrograma.exec(oldHash) !== null; | |
| 1215 | - var newHash = '#/temas'; // default page | |
| 1214 | + // Update URL and Navigate | |
| 1215 | + Main.updateHash($link.attr('href')); | |
| 1216 | + }); | |
| 1216 | 1217 | |
| 1217 | - if(isSubpage){ | |
| 1218 | - // return to proposal page | |
| 1219 | - newHash = oldHash.split('/sobre-o-programa')[0]; | |
| 1220 | - }else{ | |
| 1221 | - var $link = $(this).siblings('.proposal-link'); | |
| 1222 | - newHash = $link.attr('href'); | |
| 1223 | - } | |
| 1218 | + $( '.proposal-category .go-back' ).on('click', function(e){ | |
| 1219 | + e.preventDefault(); | |
| 1224 | 1220 | |
| 1225 | - // Update URL and Navigate | |
| 1226 | - Main.updateHash(newHash); | |
| 1227 | - }); | |
| 1221 | + var oldHash = window.location.hash; | |
| 1222 | + var regexSobreOPrograma = /sobre-o-programa$/; | |
| 1223 | + var isSubpage = regexSobreOPrograma.exec(oldHash) !== null; | |
| 1224 | + var newHash = '#/temas'; // default page | |
| 1228 | 1225 | |
| 1229 | - $( '.button-send a' ).on('click', function(e){ | |
| 1230 | - e.preventDefault(); | |
| 1226 | + if(isSubpage){ | |
| 1227 | + // return to proposal page | |
| 1228 | + newHash = oldHash.split('/sobre-o-programa')[0]; | |
| 1229 | + }else{ | |
| 1230 | + var $link = $(this).siblings('.proposal-link'); | |
| 1231 | + newHash = $link.attr('href'); | |
| 1232 | + } | |
| 1231 | 1233 | |
| 1232 | - //display form to send proposal (or login form for non-logged users) | |
| 1233 | - var $this = $(this); | |
| 1234 | - loginButton = $this.closest('.button-send'); | |
| 1235 | - loginButton.hide(); | |
| 1236 | - $this.closest('.success-proposal-sent').hide(); | |
| 1237 | - var $wrapper = $this.closest('.make-proposal'); | |
| 1238 | - $wrapper.find('.subtitle').show(); | |
| 1239 | - $wrapper.find('.info').show(); | |
| 1240 | - Main.loginCallback(logged_in); | |
| 1241 | - }); | |
| 1234 | + // Update URL and Navigate | |
| 1235 | + Main.updateHash(newHash); | |
| 1236 | + }); | |
| 1242 | 1237 | |
| 1243 | - $( '#display-contrast' ).on('click', function(e){ | |
| 1244 | - e.preventDefault(); | |
| 1245 | - $('body').toggleClass('contraste'); | |
| 1238 | + $( '.button-send a' ).on('click', function(e){ | |
| 1239 | + e.preventDefault(); | |
| 1246 | 1240 | |
| 1247 | - if($.cookie){ | |
| 1248 | - var isContrasted = $('body').hasClass('contraste'); | |
| 1249 | - $.cookie('dialoga_contraste', isContrasted); | |
| 1250 | - } | |
| 1251 | - }); | |
| 1241 | + //display form to send proposal (or login form for non-logged users) | |
| 1242 | + var $this = $(this); | |
| 1243 | + loginButton = $this.closest('.button-send'); | |
| 1244 | + loginButton.hide(); | |
| 1245 | + $this.closest('.success-proposal-sent').hide(); | |
| 1246 | + var $wrapper = $this.closest('.make-proposal'); | |
| 1247 | + $wrapper.find('.subtitle').show(); | |
| 1248 | + $wrapper.find('.info').show(); | |
| 1249 | + Main.loginCallback(logged_in); | |
| 1250 | + }); | |
| 1252 | 1251 | |
| 1253 | - $( '.show_body' ).on('click', function(e){ | |
| 1254 | - e.preventDefault(); | |
| 1252 | + $( '#display-contrast' ).on('click', function(e){ | |
| 1253 | + e.preventDefault(); | |
| 1254 | + $('body').toggleClass('contraste'); | |
| 1255 | 1255 | |
| 1256 | - var $link = $(this).find('a'); | |
| 1256 | + if($.cookie){ | |
| 1257 | + var isContrasted = $('body').hasClass('contraste'); | |
| 1258 | + $.cookie('dialoga_contraste', isContrasted); | |
| 1259 | + } | |
| 1260 | + }); | |
| 1257 | 1261 | |
| 1258 | - // Update URL and Navigate | |
| 1259 | - Main.updateHash($link.attr('href')); | |
| 1260 | - }); | |
| 1262 | + $( '.show_body' ).on('click', function(e){ | |
| 1263 | + e.preventDefault(); | |
| 1261 | 1264 | |
| 1262 | - $( '.go-to-proposal-button a' ).on('click', function(e){ | |
| 1263 | - e.preventDefault(); | |
| 1265 | + var $link = $(this).find('a'); | |
| 1264 | 1266 | |
| 1265 | - var $link = $(this); | |
| 1267 | + // Update URL and Navigate | |
| 1268 | + Main.updateHash($link.attr('href')); | |
| 1269 | + }); | |
| 1266 | 1270 | |
| 1267 | - // Update URL and Navigate | |
| 1268 | - Main.updateHash($link.attr('href')); | |
| 1269 | - }); | |
| 1271 | + $( '.go-to-proposal-button a' ).on('click', function(e){ | |
| 1272 | + e.preventDefault(); | |
| 1270 | 1273 | |
| 1271 | - $( '.proposal-selection' ).change(function(){ | |
| 1272 | - // Update URL and Navigate | |
| 1273 | - Main.updateHash('#/programas/' + this.value); | |
| 1274 | - $(this).val($(this).data('proposal')).trigger('chosen:updated'); | |
| 1275 | - }); | |
| 1274 | + var $link = $(this); | |
| 1276 | 1275 | |
| 1277 | - var availableTags = [ ]; | |
| 1278 | - $('#proposal-group li a').each(function(){ | |
| 1279 | - availableTags.push({ label: $(this).text(), value: $(this).attr('href')}); | |
| 1280 | - }); | |
| 1276 | + // Update URL and Navigate | |
| 1277 | + Main.updateHash($link.attr('href')); | |
| 1278 | + }); | |
| 1281 | 1279 | |
| 1282 | - $( '#search-input' ).autocomplete({ | |
| 1283 | - source: availableTags, | |
| 1284 | - minLength: 3, | |
| 1285 | - select: function( event, ui ) { | |
| 1286 | - Main.updateHash(ui.item.value); | |
| 1287 | - return false; | |
| 1288 | - }, | |
| 1289 | - appendTo: '#search-input-container', | |
| 1290 | - messages: { | |
| 1291 | - noResults: '', | |
| 1292 | - results: function() {} | |
| 1293 | - } | |
| 1294 | - }); | |
| 1280 | + $( '.proposal-selection' ).change(function(){ | |
| 1281 | + // Update URL and Navigate | |
| 1282 | + Main.updateHash('#/programas/' + this.value); | |
| 1283 | + $(this).val($(this).data('proposal')).trigger('chosen:updated'); | |
| 1284 | + }); | |
| 1295 | 1285 | |
| 1286 | + var availableTags = [ ]; | |
| 1287 | + $('#proposal-group li a').each(function(){ | |
| 1288 | + availableTags.push({ label: $(this).text(), value: $(this).attr('href')}); | |
| 1289 | + }); | |
| 1296 | 1290 | |
| 1297 | - $('.save-article-form').submit(function (e) { | |
| 1298 | - e.preventDefault(); | |
| 1299 | - // var proposal_id = this.id.split('-').pop(); | |
| 1300 | - // var form = this; | |
| 1301 | - var $form = $(this); | |
| 1302 | - var $description = $form.find('#article_abstract'); | |
| 1303 | - var $message = $form.find('.message'); | |
| 1304 | - | |
| 1305 | - // validation | |
| 1306 | - if( $description.val().length === 0 ){ | |
| 1307 | - $message.text('O campo "descrição" é obrigatório.'); | |
| 1308 | - return false; | |
| 1309 | - } | |
| 1291 | + $( '#search-input' ).autocomplete({ | |
| 1292 | + source: availableTags, | |
| 1293 | + minLength: 3, | |
| 1294 | + select: function( event, ui ) { | |
| 1295 | + Main.updateHash(ui.item.value); | |
| 1296 | + return false; | |
| 1297 | + }, | |
| 1298 | + appendTo: '#search-input-container', | |
| 1299 | + messages: { | |
| 1300 | + noResults: '', | |
| 1301 | + results: function() {} | |
| 1302 | + } | |
| 1303 | + }); | |
| 1310 | 1304 | |
| 1311 | - // reset messages | |
| 1312 | - $message.hide(); | |
| 1313 | - $message.text(''); | |
| 1314 | 1305 | |
| 1315 | - // handle 'loading' | |
| 1316 | - var $submitButton = $form.find('.make-proposal-button'); | |
| 1317 | - $submitButton.hide(); | |
| 1318 | - // $loading.show(); | |
| 1319 | - | |
| 1320 | - $.ajax({ | |
| 1321 | - type: 'post', | |
| 1322 | - url: host + $form.attr('action'), | |
| 1323 | - data: $form.serialize() + '&private_token=' + Main.private_token + '&fields=id&article[name]=article_' + Main.guid() | |
| 1324 | - }) | |
| 1325 | - .done(function( /*data*/ ) { | |
| 1326 | - $form[0].reset(); | |
| 1327 | - $form.hide(); | |
| 1328 | - $form.siblings('.success-sent').show(); | |
| 1329 | - $form.siblings('.subtitle').hide(); | |
| 1330 | - $form.siblings('.info').hide(); | |
| 1331 | - Main.displaySuccess($form.closest('.make-proposal .section-content'), 'Proposta enviada com sucesso', 2000, 'icon-proposal-sent'); | |
| 1332 | - }) | |
| 1333 | - .fail(function( jqxhr, textStatus, error ) { | |
| 1334 | - var err = textStatus + ', ' + error; | |
| 1335 | - console.error( 'Request Failed: ' + err ); | |
| 1336 | - $message.show(); | |
| 1337 | - $message.text('Não foi possível enviar.'); | |
| 1338 | - }) | |
| 1339 | - .always(function(){ | |
| 1340 | - $submitButton.show(); | |
| 1341 | - // $loading.hide(); | |
| 1306 | + $('.save-article-form').submit(function (e) { | |
| 1307 | + e.preventDefault(); | |
| 1308 | + // var proposal_id = this.id.split('-').pop(); | |
| 1309 | + // var form = this; | |
| 1310 | + var $form = $(this); | |
| 1311 | + var $description = $form.find('#article_abstract'); | |
| 1312 | + var $message = $form.find('.message'); | |
| 1313 | + | |
| 1314 | + // validation | |
| 1315 | + if( $description.val().length === 0 ){ | |
| 1316 | + $message.text('O campo "descrição" é obrigatório.'); | |
| 1317 | + return false; | |
| 1318 | + } | |
| 1319 | + | |
| 1320 | + // reset messages | |
| 1321 | + $message.hide(); | |
| 1322 | + $message.text(''); | |
| 1323 | + | |
| 1324 | + // handle 'loading' | |
| 1325 | + var $submitButton = $form.find('.make-proposal-button'); | |
| 1326 | + $submitButton.hide(); | |
| 1327 | + // $loading.show(); | |
| 1328 | + | |
| 1329 | + $.ajax({ | |
| 1330 | + type: 'post', | |
| 1331 | + url: host + $form.attr('action'), | |
| 1332 | + data: $form.serialize() + '&private_token=' + Main.private_token + '&fields=id&article[name]=article_' + Main.guid() | |
| 1333 | + }) | |
| 1334 | + .done(function( /*data*/ ) { | |
| 1335 | + $form[0].reset(); | |
| 1336 | + $form.hide(); | |
| 1337 | + $form.siblings('.success-sent').show(); | |
| 1338 | + $form.siblings('.subtitle').hide(); | |
| 1339 | + $form.siblings('.info').hide(); | |
| 1340 | + Main.displaySuccess($form.closest('.make-proposal .section-content'), 'Proposta enviada com sucesso', 2000, 'icon-proposal-sent'); | |
| 1341 | + }) | |
| 1342 | + .fail(function( jqxhr, textStatus, error ) { | |
| 1343 | + var err = textStatus + ', ' + error; | |
| 1344 | + console.error( 'Request Failed: ' + err ); | |
| 1345 | + $message.show(); | |
| 1346 | + $message.text('Não foi possível enviar.'); | |
| 1347 | + }) | |
| 1348 | + .always(function(){ | |
| 1349 | + $submitButton.show(); | |
| 1350 | + // $loading.hide(); | |
| 1351 | + }); | |
| 1342 | 1352 | }); |
| 1353 | + }) | |
| 1354 | + .fail(function( jqxhr, textStatus, error ) { | |
| 1355 | + var err = textStatus + ', ' + error; | |
| 1356 | + console.error( 'Request Failed: ' + err ); | |
| 1343 | 1357 | }); |
| 1344 | - }) | |
| 1345 | - .fail(function( jqxhr, textStatus, error ) { | |
| 1346 | - var err = textStatus + ', ' + error; | |
| 1347 | - console.error( 'Request Failed: ' + err ); | |
| 1348 | - }); | |
| 1349 | 1358 | |
| 1350 | - $(document).ready(function($) { | |
| 1359 | + $(document).ready(function($) { | |
| 1351 | 1360 | |
| 1352 | - FastClick.attach(document.body); | |
| 1361 | + FastClick.attach(document.body); | |
| 1353 | 1362 | |
| 1354 | - if($.cookie) { | |
| 1363 | + if($.cookie) { | |
| 1355 | 1364 | |
| 1356 | - // session | |
| 1357 | - if($.cookie('_dialoga_session')){ | |
| 1358 | - var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); | |
| 1359 | - $.getJSON(url).done(function( data ) { | |
| 1360 | - logged_in = true; | |
| 1361 | - Main.private_token = $.cookie('_dialoga_session'); | |
| 1365 | + // session | |
| 1366 | + if($.cookie('_dialoga_session')){ | |
| 1367 | + var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); | |
| 1368 | + $.getJSON(url).done(function( data ) { | |
| 1369 | + logged_in = true; | |
| 1370 | + Main.private_token = $.cookie('_dialoga_session'); | |
| 1362 | 1371 | |
| 1363 | - if(data && data.user){ | |
| 1364 | - Main.setUser(data.user); | |
| 1365 | - Main.showLogout(); | |
| 1366 | - } | |
| 1367 | - }); | |
| 1368 | - } | |
| 1372 | + if(data && data.user){ | |
| 1373 | + Main.setUser(data.user); | |
| 1374 | + Main.showLogout(); | |
| 1375 | + } | |
| 1376 | + }); | |
| 1377 | + } | |
| 1369 | 1378 | |
| 1370 | - // contrast | |
| 1371 | - var isContrasted = $.cookie('dialoga_contraste'); | |
| 1372 | - if(isContrasted === 'true'){ | |
| 1373 | - // remove all classes 'contraste' and add only one 'contraste' | |
| 1374 | - $('body').addClass('contraste'); | |
| 1379 | + // contrast | |
| 1380 | + var isContrasted = $.cookie('dialoga_contraste'); | |
| 1381 | + if(isContrasted === 'true'){ | |
| 1382 | + // remove all classes 'contraste' and add only one 'contraste' | |
| 1383 | + $('body').addClass('contraste'); | |
| 1384 | + } | |
| 1375 | 1385 | } |
| 1376 | - } | |
| 1377 | 1386 | |
| 1378 | - $(document).on('login:success', Main.handleLoginSuccess); | |
| 1379 | - $(document).on('login:fail', Main.handleLoginFail); | |
| 1387 | + $(document).on('login:success', Main.handleLoginSuccess); | |
| 1388 | + $(document).on('login:fail', Main.handleLoginFail); | |
| 1380 | 1389 | |
| 1381 | - $(document).on('click', '.login-action', function(e) { | |
| 1382 | - e.preventDefault(); | |
| 1390 | + $(document).on('click', '.login-action', function(e) { | |
| 1391 | + e.preventDefault(); | |
| 1383 | 1392 | |
| 1384 | - var $this = $(this); // button | |
| 1385 | - var $form = $this.closest('#login-form'); | |
| 1386 | - var $message = $form.find('.message'); | |
| 1387 | - $message.text('').hide(); | |
| 1393 | + var $this = $(this); // button | |
| 1394 | + var $form = $this.closest('#login-form'); | |
| 1395 | + var $message = $form.find('.message'); | |
| 1396 | + $message.text('').hide(); | |
| 1388 | 1397 | |
| 1389 | - loginButton = $this; | |
| 1398 | + loginButton = $this; | |
| 1390 | 1399 | |
| 1391 | - $.ajax({ | |
| 1392 | - type: 'post', | |
| 1393 | - url: host + '/api/v1/login', | |
| 1394 | - data: $form.serialize(), | |
| 1395 | - xhrFields: { | |
| 1396 | - //withCredentials: true | |
| 1397 | - } | |
| 1398 | - }).done(function(data) { | |
| 1400 | + $.ajax({ | |
| 1401 | + type: 'post', | |
| 1402 | + url: host + '/api/v1/login', | |
| 1403 | + data: $form.serialize(), | |
| 1404 | + xhrFields: { | |
| 1405 | + //withCredentials: true | |
| 1406 | + } | |
| 1407 | + }).done(function(data) { | |
| 1399 | 1408 | |
| 1400 | - var $sectionContent = $form.closest('.section-content'); | |
| 1401 | - if($sectionContent && $sectionContent.length > 0){ | |
| 1402 | - Main.displaySuccess($sectionContent, 'Login efetuado com sucesso', 1000, 'icon-login-success'); | |
| 1403 | - } | |
| 1409 | + var $sectionContent = $form.closest('.section-content'); | |
| 1410 | + if($sectionContent && $sectionContent.length > 0){ | |
| 1411 | + Main.displaySuccess($sectionContent, 'Login efetuado com sucesso', 1000, 'icon-login-success'); | |
| 1412 | + } | |
| 1404 | 1413 | |
| 1405 | - var $loginPanel = $form.closest('#login-panel'); | |
| 1406 | - if($loginPanel && $loginPanel.length > 0){ | |
| 1407 | - $loginPanel.hide(); | |
| 1408 | - } | |
| 1414 | + var $loginPanel = $form.closest('#login-panel'); | |
| 1415 | + if($loginPanel && $loginPanel.length > 0){ | |
| 1416 | + $loginPanel.hide(); | |
| 1417 | + } | |
| 1409 | 1418 | |
| 1410 | - $(document).trigger('login:success', data); | |
| 1411 | - }).fail(function(data) { | |
| 1419 | + $(document).trigger('login:success', data); | |
| 1420 | + }).fail(function(data) { | |
| 1412 | 1421 | |
| 1413 | - $message.show(); | |
| 1414 | - if(data.status === 401){ | |
| 1415 | - $message.text('Nome de usuário, e-mail ou senha incorretos, não foi possível acessar.'); | |
| 1416 | - }else{ | |
| 1417 | - $message.text('Um erro inesperado ocorreu'); | |
| 1418 | - } | |
| 1422 | + $message.show(); | |
| 1423 | + if(data.status === 401){ | |
| 1424 | + $message.text('Nome de usuário, e-mail ou senha incorretos, não foi possível acessar.'); | |
| 1425 | + }else{ | |
| 1426 | + $message.text('Um erro inesperado ocorreu'); | |
| 1427 | + } | |
| 1419 | 1428 | |
| 1420 | - $(document).trigger('login:fail', data); | |
| 1429 | + $(document).trigger('login:fail', data); | |
| 1430 | + }); | |
| 1421 | 1431 | }); |
| 1422 | - }); | |
| 1423 | 1432 | |
| 1424 | - $(document).on('click', '.social .fb-share', function(e) { | |
| 1425 | - e.preventDefault(); | |
| 1426 | - var link = $(this).attr('href'); | |
| 1427 | - FB.ui({ | |
| 1428 | - method: 'feed', | |
| 1429 | - link: link, | |
| 1430 | - name: $(this).data('name') || 'Dialoga Brasil', | |
| 1431 | - caption: $(this).data('caption') || 'dialoga.gov.br', | |
| 1432 | - description: $(this).data('description'), | |
| 1433 | - }, function(response){ | |
| 1434 | - console.log('response', response); | |
| 1433 | + $(document).on('click', '.social .fb-share', function(e) { | |
| 1434 | + e.preventDefault(); | |
| 1435 | + var link = $(this).attr('href'); | |
| 1436 | + FB.ui({ | |
| 1437 | + method: 'feed', | |
| 1438 | + link: link, | |
| 1439 | + name: $(this).data('name') || 'Dialoga Brasil', | |
| 1440 | + caption: $(this).data('caption') || 'dialoga.gov.br', | |
| 1441 | + description: $(this).data('description'), | |
| 1442 | + }, function(response){ | |
| 1443 | + console.log('response', response); | |
| 1444 | + }); | |
| 1435 | 1445 | }); |
| 1436 | - }); | |
| 1437 | 1446 | |
| 1438 | - $(document).on('click', 'a.forgot-password', function(e) { | |
| 1439 | - var loginForm = $(this).parents('#login-form'); | |
| 1440 | - var $forgotPasswordForm = loginForm.siblings('#forgot-password-form'); | |
| 1441 | - loginForm.hide(); | |
| 1442 | - $forgotPasswordForm.show(); | |
| 1447 | + $(document).on('click', 'a.forgot-password', function(e) { | |
| 1448 | + var loginForm = $(this).parents('#login-form'); | |
| 1449 | + var $forgotPasswordForm = loginForm.siblings('#forgot-password-form'); | |
| 1450 | + loginForm.hide(); | |
| 1451 | + $forgotPasswordForm.show(); | |
| 1443 | 1452 | |
| 1444 | - Main.initCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | |
| 1453 | + Main.initCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | |
| 1445 | 1454 | |
| 1446 | - var $message = $forgotPasswordForm.find('.message'); | |
| 1447 | - $message.html(''); | |
| 1448 | - $message.hide(); | |
| 1449 | - $forgotPasswordForm.find('#forgot-password-value').val(''); | |
| 1455 | + var $message = $forgotPasswordForm.find('.message'); | |
| 1456 | + $message.html(''); | |
| 1457 | + $message.hide(); | |
| 1458 | + $forgotPasswordForm.find('#forgot-password-value').val(''); | |
| 1450 | 1459 | |
| 1451 | - e.preventDefault(); | |
| 1452 | - }); | |
| 1460 | + e.preventDefault(); | |
| 1461 | + }); | |
| 1453 | 1462 | |
| 1454 | - $(document).on('click', '.cancel-new-password', function(e) { | |
| 1455 | - var newPasswordForm = $(this).parents('#new-password-form'); | |
| 1456 | - var loginForm = newPasswordForm.siblings('#login-form'); | |
| 1457 | - loginForm.show(); | |
| 1458 | - newPasswordForm.hide(); | |
| 1459 | - }); | |
| 1463 | + $(document).on('click', '.cancel-new-password', function(e) { | |
| 1464 | + var newPasswordForm = $(this).parents('#new-password-form'); | |
| 1465 | + var loginForm = newPasswordForm.siblings('#login-form'); | |
| 1466 | + loginForm.show(); | |
| 1467 | + newPasswordForm.hide(); | |
| 1468 | + }); | |
| 1460 | 1469 | |
| 1461 | - $(document).on('click', '.confirm-new-password', function(e) { | |
| 1462 | - var $newPasswordForm = $(this).parents('#new-password-form'); | |
| 1463 | - $.ajax({ | |
| 1464 | - method: 'PATCH', | |
| 1465 | - url:host+'/api/v1/new_password', | |
| 1466 | - data: { | |
| 1467 | - code: $newPasswordForm.find('#new-password-code').val(), | |
| 1468 | - password: $newPasswordForm.find('#new-password').val(), | |
| 1469 | - password_confirmation: $newPasswordForm.find('#new-password-confirmation').val() | |
| 1470 | - }, | |
| 1471 | - }).done(function(data) { | |
| 1472 | - $newPasswordForm.find('.cancel-new-password').click(); | |
| 1473 | - var $message = $newPasswordForm.siblings('#login-form').find('.message-success'); | |
| 1474 | - $message.html('Senha alterada com sucesso.'); | |
| 1475 | - $message.show(); | |
| 1476 | - window.location.hash = '/'; | |
| 1477 | - }).fail(function() { | |
| 1478 | - var $message = $newPasswordForm.find('.message'); | |
| 1479 | - $message.html('Não foi possível trocar a senha com os dados informados.'); | |
| 1480 | - $message.show(); | |
| 1470 | + $(document).on('click', '.confirm-new-password', function(e) { | |
| 1471 | + var $newPasswordForm = $(this).parents('#new-password-form'); | |
| 1472 | + $.ajax({ | |
| 1473 | + method: 'PATCH', | |
| 1474 | + url:host+'/api/v1/new_password', | |
| 1475 | + data: { | |
| 1476 | + code: $newPasswordForm.find('#new-password-code').val(), | |
| 1477 | + password: $newPasswordForm.find('#new-password').val(), | |
| 1478 | + password_confirmation: $newPasswordForm.find('#new-password-confirmation').val() | |
| 1479 | + }, | |
| 1480 | + }).done(function(data) { | |
| 1481 | + $newPasswordForm.find('.cancel-new-password').click(); | |
| 1482 | + var $message = $newPasswordForm.siblings('#login-form').find('.message-success'); | |
| 1483 | + $message.html('Senha alterada com sucesso.'); | |
| 1484 | + $message.show(); | |
| 1485 | + window.location.hash = '/'; | |
| 1486 | + }).fail(function() { | |
| 1487 | + var $message = $newPasswordForm.find('.message'); | |
| 1488 | + $message.html('Não foi possível trocar a senha com os dados informados.'); | |
| 1489 | + $message.show(); | |
| 1490 | + }); | |
| 1491 | + e.preventDefault(); | |
| 1481 | 1492 | }); |
| 1482 | - e.preventDefault(); | |
| 1483 | - }); | |
| 1484 | 1493 | |
| 1485 | - $(document).on('click', '.confirm-forgot-password', function(e) { | |
| 1486 | - var $forgotPasswordForm = $(this).parents('#forgot-password-form'); | |
| 1487 | - var $inputValue = $forgotPasswordForm.find('#forgot-password-value'); | |
| 1488 | - var forgotPasswordFormData = $forgotPasswordForm.serialize(); | |
| 1489 | - $.ajax({ | |
| 1490 | - method: 'post', | |
| 1491 | - url:host+'/api/v1/forgot_password', | |
| 1492 | - data: forgotPasswordFormData, | |
| 1493 | - }).done(function(data) { | |
| 1494 | - $forgotPasswordForm.find('.cancel-forgot-password').click(); | |
| 1495 | - var $message = $forgotPasswordForm.siblings('#login-form').find('.message-success'); | |
| 1496 | - $message.html('Verifique seu email para efetuar a troca da senha.'); | |
| 1497 | - $message.show(); | |
| 1498 | - }).fail(function(data) { | |
| 1499 | - console.log(data.responseJSON); | |
| 1500 | - | |
| 1501 | - Main.reloadCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | |
| 1502 | - var $message = $forgotPasswordForm.find('.message'); | |
| 1503 | - $message.html('Não foi possível requisitar a troca de senha para os dados informados.'); | |
| 1504 | - $message.show(); | |
| 1494 | + $(document).on('click', '.confirm-forgot-password', function(e) { | |
| 1495 | + var $forgotPasswordForm = $(this).parents('#forgot-password-form'); | |
| 1496 | + var $inputValue = $forgotPasswordForm.find('#forgot-password-value'); | |
| 1497 | + var forgotPasswordFormData = $forgotPasswordForm.serialize(); | |
| 1498 | + $.ajax({ | |
| 1499 | + method: 'post', | |
| 1500 | + url:host+'/api/v1/forgot_password', | |
| 1501 | + data: forgotPasswordFormData, | |
| 1502 | + }).done(function(data) { | |
| 1503 | + $forgotPasswordForm.find('.cancel-forgot-password').click(); | |
| 1504 | + var $message = $forgotPasswordForm.siblings('#login-form').find('.message-success'); | |
| 1505 | + $message.html('Verifique seu email para efetuar a troca da senha.'); | |
| 1506 | + $message.show(); | |
| 1507 | + }).fail(function(data) { | |
| 1508 | + console.log(data.responseJSON); | |
| 1509 | + | |
| 1510 | + Main.reloadCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | |
| 1511 | + var $message = $forgotPasswordForm.find('.message'); | |
| 1512 | + $message.html('Não foi possível requisitar a troca de senha para os dados informados.'); | |
| 1513 | + $message.show(); | |
| 1514 | + }); | |
| 1515 | + e.preventDefault(); | |
| 1505 | 1516 | }); |
| 1506 | - e.preventDefault(); | |
| 1507 | - }); | |
| 1508 | 1517 | |
| 1509 | - $(document).on('click', '.cancel-forgot-password', function(e) { | |
| 1510 | - var forgotPasswordForm = $(this).parents('#forgot-password-form'); | |
| 1511 | - var loginForm = forgotPasswordForm.siblings('#login-form'); | |
| 1512 | - loginForm.show(); | |
| 1513 | - forgotPasswordForm.hide(); | |
| 1514 | - }); | |
| 1518 | + $(document).on('click', '.cancel-forgot-password', function(e) { | |
| 1519 | + var forgotPasswordForm = $(this).parents('#forgot-password-form'); | |
| 1520 | + var loginForm = forgotPasswordForm.siblings('#login-form'); | |
| 1521 | + loginForm.show(); | |
| 1522 | + forgotPasswordForm.hide(); | |
| 1523 | + }); | |
| 1515 | 1524 | |
| 1516 | - $(document).on('click', '.new-user', function(e) { | |
| 1517 | - var message = $('.signup .message'); | |
| 1518 | - message.hide(); | |
| 1519 | - message.text(''); | |
| 1525 | + $(document).on('click', '.new-user', function(e) { | |
| 1526 | + var message = $('.signup .message'); | |
| 1527 | + message.hide(); | |
| 1528 | + message.text(''); | |
| 1520 | 1529 | |
| 1521 | - var loginForm = $(this).parents('#login-form'); | |
| 1522 | - var signupForm = loginForm.siblings('#signup-form'); | |
| 1523 | - window.signupForm = signupForm; | |
| 1530 | + var loginForm = $(this).parents('#login-form'); | |
| 1531 | + var signupForm = loginForm.siblings('#signup-form'); | |
| 1532 | + window.signupForm = signupForm; | |
| 1524 | 1533 | |
| 1525 | - loginForm.hide(); | |
| 1526 | - signupForm.show(); | |
| 1534 | + loginForm.hide(); | |
| 1535 | + signupForm.show(); | |
| 1527 | 1536 | |
| 1528 | - signupForm.find('.password').show(); | |
| 1529 | - signupForm.find('.password-confirmation').show(); | |
| 1537 | + signupForm.find('.password').show(); | |
| 1538 | + signupForm.find('.password-confirmation').show(); | |
| 1530 | 1539 | |
| 1531 | - signupForm.find('signup-user_password').attr('required', true); | |
| 1532 | - signupForm.find('#user_password_confirmation').attr('required', true); | |
| 1540 | + signupForm.find('signup-user_password').attr('required', true); | |
| 1541 | + signupForm.find('#user_password_confirmation').attr('required', true); | |
| 1533 | 1542 | |
| 1534 | - loginForm.find('.message').hide(); | |
| 1535 | - signupForm.find('#serpro_captcha').val(''); | |
| 1543 | + loginForm.find('.message').hide(); | |
| 1544 | + signupForm.find('#serpro_captcha').val(''); | |
| 1536 | 1545 | |
| 1537 | - signupForm.find('#signup-user_email').val(''); | |
| 1538 | - signupForm.find('#signup-user_email').attr('disabled', false); | |
| 1539 | - signupForm.find('#signup-user_name').val(''); | |
| 1540 | - signupForm.find('#user_password_confirmation').val(''); | |
| 1541 | - signupForm.find('#signup-user_password').val(''); | |
| 1542 | - signupForm.find('#captcha_text').val(''); | |
| 1543 | - signupForm.find('#user_terms_accepted').removeAttr('checked'); | |
| 1546 | + signupForm.find('#signup-user_email').val(''); | |
| 1547 | + signupForm.find('#signup-user_email').attr('disabled', false); | |
| 1548 | + signupForm.find('#signup-user_name').val(''); | |
| 1549 | + signupForm.find('#user_password_confirmation').val(''); | |
| 1550 | + signupForm.find('#signup-user_password').val(''); | |
| 1551 | + signupForm.find('#captcha_text').val(''); | |
| 1552 | + signupForm.find('#user_terms_accepted').removeAttr('checked'); | |
| 1544 | 1553 | |
| 1545 | - Main.initCaptcha(signupForm.find('#serpro_captcha')[0]); | |
| 1554 | + Main.initCaptcha(signupForm.find('#serpro_captcha')[0]); | |
| 1546 | 1555 | |
| 1547 | - e.preventDefault(); | |
| 1548 | - }); | |
| 1556 | + e.preventDefault(); | |
| 1557 | + }); | |
| 1549 | 1558 | |
| 1550 | - $(document).on('click', '.cancel-signup', function(e) { | |
| 1551 | - var signupForm = $(this).parents('#signup-form'); | |
| 1552 | - signupForm.find('#user_oauth_providers').val(''); | |
| 1553 | - signupForm.hide(); | |
| 1554 | - signupForm.siblings('#login-form').show(); | |
| 1555 | - e.preventDefault(); | |
| 1556 | - }); | |
| 1559 | + $(document).on('click', '.cancel-signup', function(e) { | |
| 1560 | + var signupForm = $(this).parents('#signup-form'); | |
| 1561 | + signupForm.find('#user_oauth_providers').val(''); | |
| 1562 | + signupForm.hide(); | |
| 1563 | + signupForm.siblings('#login-form').show(); | |
| 1564 | + e.preventDefault(); | |
| 1565 | + }); | |
| 1557 | 1566 | |
| 1558 | - $(document).on('click', '.confirm-signup', function(e) { | |
| 1567 | + $(document).on('click', '.confirm-signup', function(e) { | |
| 1559 | 1568 | |
| 1560 | - var $button = $(this); | |
| 1561 | - var $signupForm = $(this).parents('form.signup'); | |
| 1562 | - var $inputEmail = $signupForm.find('#signup-user_email'); | |
| 1563 | - var $inputUsername = $signupForm.find('#signup-user_name'); | |
| 1564 | - var $inputPassword = $signupForm.find('#signup-user_password'); | |
| 1565 | - var $inputPasswordConfirmation = $signupForm.find('#user_password_confirmation'); | |
| 1566 | - var $inputAcceptation = $signupForm.find('#user_terms_accepted'); | |
| 1567 | - var $inputCaptcha = $signupForm.find('#captcha_text'); | |
| 1569 | + var $button = $(this); | |
| 1570 | + var $signupForm = $(this).parents('form.signup'); | |
| 1571 | + var $inputEmail = $signupForm.find('#signup-user_email'); | |
| 1572 | + var $inputUsername = $signupForm.find('#signup-user_name'); | |
| 1573 | + var $inputPassword = $signupForm.find('#signup-user_password'); | |
| 1574 | + var $inputPasswordConfirmation = $signupForm.find('#user_password_confirmation'); | |
| 1575 | + var $inputAcceptation = $signupForm.find('#user_terms_accepted'); | |
| 1576 | + var $inputCaptcha = $signupForm.find('#captcha_text'); | |
| 1568 | 1577 | |
| 1569 | - // clear messages | |
| 1570 | - var message = $('.signup .message'); | |
| 1571 | - message.hide(); | |
| 1572 | - message.text(''); | |
| 1578 | + // clear messages | |
| 1579 | + var message = $('.signup .message'); | |
| 1580 | + message.hide(); | |
| 1581 | + message.text(''); | |
| 1573 | 1582 | |
| 1574 | - // Validate form | |
| 1575 | - var hasEmail = $inputEmail && $inputEmail.val().length > 0; | |
| 1576 | - var hasUsername = $inputUsername && $inputUsername.val().length > 0; | |
| 1583 | + // Validate form | |
| 1584 | + var hasEmail = $inputEmail && $inputEmail.val().length > 0; | |
| 1585 | + var hasUsername = $inputUsername && $inputUsername.val().length > 0; | |
| 1577 | 1586 | |
| 1578 | - var isOAUTH = $signupForm.find('#user_oauth_providers').val() !== ''; | |
| 1587 | + var isOAUTH = $signupForm.find('#user_oauth_providers').val() !== ''; | |
| 1579 | 1588 | |
| 1580 | - var hasPassword = true; | |
| 1581 | - var hasPasswordConfirmation = true; | |
| 1582 | - var hasPasswordEquals = true; | |
| 1589 | + var hasPassword = true; | |
| 1590 | + var hasPasswordConfirmation = true; | |
| 1591 | + var hasPasswordEquals = true; | |
| 1583 | 1592 | |
| 1584 | - if(! isOAUTH){ | |
| 1585 | - hasPassword = $inputPassword && $inputPassword.val().length > 0; | |
| 1586 | - hasPasswordConfirmation = $inputPasswordConfirmation && $inputPasswordConfirmation.val().length > 0; | |
| 1587 | - hasPasswordEquals = $inputPassword.val() === $inputPasswordConfirmation.val(); | |
| 1588 | - } | |
| 1593 | + if(! isOAUTH){ | |
| 1594 | + hasPassword = $inputPassword && $inputPassword.val().length > 0; | |
| 1595 | + hasPasswordConfirmation = $inputPasswordConfirmation && $inputPasswordConfirmation.val().length > 0; | |
| 1596 | + hasPasswordEquals = $inputPassword.val() === $inputPasswordConfirmation.val(); | |
| 1597 | + } | |
| 1589 | 1598 | |
| 1590 | - var hasAcceptation = $inputAcceptation.prop('checked'); | |
| 1591 | - var hasCaptcha = $inputCaptcha.val().length > 0; | |
| 1592 | - var hasError = (!hasEmail || !hasUsername || !hasPassword || !hasPasswordConfirmation || !hasPasswordEquals || !hasAcceptation || !hasCaptcha); | |
| 1599 | + var hasAcceptation = $inputAcceptation.prop('checked'); | |
| 1600 | + var hasCaptcha = $inputCaptcha.val().length > 0; | |
| 1601 | + var hasError = (!hasEmail || !hasUsername || !hasPassword || !hasPasswordConfirmation || !hasPasswordEquals || !hasAcceptation || !hasCaptcha); | |
| 1593 | 1602 | |
| 1594 | - if(hasError){ | |
| 1603 | + if(hasError){ | |
| 1595 | 1604 | |
| 1596 | - if ($signupForm[0].checkValidity() || !hasAcceptation) { // force check of HTML5 validation | |
| 1597 | - e.preventDefault(); | |
| 1605 | + if ($signupForm[0].checkValidity() || !hasAcceptation) { // force check of HTML5 validation | |
| 1606 | + e.preventDefault(); | |
| 1598 | 1607 | |
| 1599 | - var messageErrors = []; | |
| 1608 | + var messageErrors = []; | |
| 1600 | 1609 | |
| 1601 | 1610 | |
| 1602 | - messageErrors.push('<ul>'); // start a HTML list | |
| 1611 | + messageErrors.push('<ul>'); // start a HTML list | |
| 1603 | 1612 | |
| 1604 | - if (!hasEmail){ | |
| 1605 | - messageErrors.push('<li>O e-mail é um campo obrigatório.</li>'); | |
| 1606 | - } | |
| 1613 | + if (!hasEmail){ | |
| 1614 | + messageErrors.push('<li>O e-mail é um campo obrigatório.</li>'); | |
| 1615 | + } | |
| 1607 | 1616 | |
| 1608 | - if (!hasUsername){ | |
| 1609 | - messageErrors.push('<li>O nome de usuário é um campo obrigatório.</li>'); | |
| 1610 | - } | |
| 1617 | + if (!hasUsername){ | |
| 1618 | + messageErrors.push('<li>O nome de usuário é um campo obrigatório.</li>'); | |
| 1619 | + } | |
| 1620 | + | |
| 1621 | + if(!isOAUTH){ | |
| 1622 | + if (!hasPassword){ | |
| 1623 | + messageErrors.push('<li>A senha é um campo obrigatório.</li>'); | |
| 1624 | + } | |
| 1625 | + | |
| 1626 | + if (!hasPasswordConfirmation){ | |
| 1627 | + messageErrors.push('<li>A confirmação da senha é um campo obrigatório.</li>'); | |
| 1628 | + } | |
| 1611 | 1629 | |
| 1612 | - if(!isOAUTH){ | |
| 1613 | - if (!hasPassword){ | |
| 1614 | - messageErrors.push('<li>A senha é um campo obrigatório.</li>'); | |
| 1630 | + if (!hasPasswordEquals){ | |
| 1631 | + messageErrors.push('<li>A senha e confirmação da senha devem ser iguais.</li>'); | |
| 1632 | + } | |
| 1615 | 1633 | } |
| 1616 | 1634 | |
| 1617 | - if (!hasPasswordConfirmation){ | |
| 1618 | - messageErrors.push('<li>A confirmação da senha é um campo obrigatório.</li>'); | |
| 1635 | + if (!hasAcceptation){ | |
| 1636 | + messageErrors.push('<li>Você deve ler e aceitar os termos de uso.</li>'); | |
| 1619 | 1637 | } |
| 1620 | 1638 | |
| 1621 | - if (!hasPasswordEquals){ | |
| 1622 | - messageErrors.push('<li>A senha e confirmação da senha devem ser iguais.</li>'); | |
| 1639 | + if (!hasCaptcha){ | |
| 1640 | + messageErrors.push('<li>O ReCaptcha é um campo obrigatório.</li>'); | |
| 1623 | 1641 | } |
| 1624 | - } | |
| 1625 | 1642 | |
| 1626 | - if (!hasAcceptation){ | |
| 1627 | - messageErrors.push('<li>Você deve ler e aceitar os termos de uso.</li>'); | |
| 1628 | - } | |
| 1643 | + messageErrors.push('</ul>'); // close the paragraph | |
| 1629 | 1644 | |
| 1630 | - if (!hasCaptcha){ | |
| 1631 | - messageErrors.push('<li>O ReCaptcha é um campo obrigatório.</li>'); | |
| 1645 | + messageErrors = messageErrors.join('<br/>'); | |
| 1646 | + message.html($(messageErrors)); | |
| 1647 | + message.show(); | |
| 1632 | 1648 | } |
| 1649 | + } else { | |
| 1650 | + e.preventDefault(); | |
| 1651 | + // show loading | |
| 1652 | + var $loading = $('.login-container .loading'); | |
| 1653 | + $loading.show(); | |
| 1654 | + var signup_form_data = $signupForm.serialize(); | |
| 1655 | + if(! new RegExp('email=').test(signup_form_data)){ | |
| 1656 | + signup_form_data += "&email=" + $inputEmail.val(); | |
| 1657 | + } | |
| 1658 | + $.ajax({ | |
| 1659 | + type: 'post', | |
| 1660 | + contentType: 'application/x-www-form-urlencoded', | |
| 1661 | + url: host + '/api/v1/register', | |
| 1662 | + data: signup_form_data, | |
| 1663 | + }) | |
| 1664 | + .done(function (data){ | |
| 1665 | + $signupForm.hide(); | |
| 1666 | + $signupForm.removeClass('hide'); | |
| 1667 | + var $sectionContent = $button.closest('.section-content'); | |
| 1633 | 1668 | |
| 1634 | - messageErrors.push('</ul>'); // close the paragraph | |
| 1635 | - | |
| 1636 | - messageErrors = messageErrors.join('<br/>'); | |
| 1637 | - message.html($(messageErrors)); | |
| 1638 | - message.show(); | |
| 1639 | - } | |
| 1640 | - } else { | |
| 1641 | - e.preventDefault(); | |
| 1642 | - // show loading | |
| 1643 | - var $loading = $('.login-container .loading'); | |
| 1644 | - $loading.show(); | |
| 1645 | - var signup_form_data = $signupForm.serialize(); | |
| 1646 | - if(! new RegExp('email=').test(signup_form_data)){ | |
| 1647 | - signup_form_data += "&email=" + $inputEmail.val(); | |
| 1648 | - } | |
| 1649 | - $.ajax({ | |
| 1650 | - type: 'post', | |
| 1651 | - contentType: 'application/x-www-form-urlencoded', | |
| 1652 | - url: host + '/api/v1/register', | |
| 1653 | - data: signup_form_data, | |
| 1654 | - }) | |
| 1655 | - .done(function (data){ | |
| 1656 | - $signupForm.hide(); | |
| 1657 | - $signupForm.removeClass('hide'); | |
| 1658 | - var $sectionContent = $button.closest('.section-content'); | |
| 1659 | - | |
| 1660 | - if(data.activated) { | |
| 1661 | - if($sectionContent && $sectionContent.length > 0){ | |
| 1662 | - Main.displaySuccess($sectionContent, 'Cadastro efetuado com sucesso', 1000, 'icon-user-created'); | |
| 1669 | + if(data.activated) { | |
| 1670 | + if($sectionContent && $sectionContent.length > 0){ | |
| 1671 | + Main.displaySuccess($sectionContent, 'Cadastro efetuado com sucesso', 1000, 'icon-user-created'); | |
| 1672 | + } | |
| 1673 | + $(document).trigger('login:success', data); | |
| 1674 | + } else { | |
| 1675 | + $signupForm.find('.cancel-signup').click(); | |
| 1676 | + $signupForm.hide(); | |
| 1677 | + var $message = $signupForm.siblings('#login-form').find('.message-success'); | |
| 1678 | + $message.html('Cadastro efetuado com sucesso.<br/>Verifique seu email para confirmar o cadastro.'); | |
| 1679 | + $message.show(); | |
| 1663 | 1680 | } |
| 1664 | - $(document).trigger('login:success', data); | |
| 1665 | - } else { | |
| 1666 | - $signupForm.find('.cancel-signup').click(); | |
| 1667 | - $signupForm.hide(); | |
| 1668 | - var $message = $signupForm.siblings('#login-form').find('.message-success'); | |
| 1669 | - $message.html('Cadastro efetuado com sucesso.<br/>Verifique seu email para confirmar o cadastro.'); | |
| 1670 | - $message.show(); | |
| 1671 | - } | |
| 1672 | - }) | |
| 1673 | - .fail(function (data) { | |
| 1674 | - var msg = ''; | |
| 1675 | - Main.reloadCaptcha($signupForm.find('#serpro_captcha')[0]); | |
| 1676 | - | |
| 1677 | - if(data.responseJSON){ | |
| 1678 | - try{ | |
| 1679 | - msg = Main.responseToText(data.responseJSON.message); | |
| 1680 | - }catch(ex){ | |
| 1681 | - var ptBR = {}; | |
| 1682 | - // (Invalid request) email can't be saved | |
| 1683 | - ptBR['(Invalid request) email can\'t be saved'] = 'E-mail inválido.'; | |
| 1684 | - // (Invalid request) login can't be saved | |
| 1685 | - ptBR['(Invalid request) login can\'t be saved'] = 'Nome de usuário inválido.'; | |
| 1686 | - ptBR['Please solve the test in order to register.'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.'; | |
| 1687 | - ptBR['Wrong captcha text, please try again'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.'; | |
| 1688 | - ptBR['Internal captcha validation error'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.'; | |
| 1681 | + }) | |
| 1682 | + .fail(function (data) { | |
| 1683 | + var msg = ''; | |
| 1684 | + Main.reloadCaptcha($signupForm.find('#serpro_captcha')[0]); | |
| 1685 | + | |
| 1686 | + if(data.responseJSON){ | |
| 1687 | + try{ | |
| 1688 | + msg = Main.responseToText(data.responseJSON.message); | |
| 1689 | + }catch(ex){ | |
| 1690 | + var ptBR = {}; | |
| 1691 | + // (Invalid request) email can't be saved | |
| 1692 | + ptBR['(Invalid request) email can\'t be saved'] = 'E-mail inválido.'; | |
| 1693 | + // (Invalid request) login can't be saved | |
| 1694 | + ptBR['(Invalid request) login can\'t be saved'] = 'Nome de usuário inválido.'; | |
| 1695 | + ptBR['Please solve the test in order to register.'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.'; | |
| 1696 | + ptBR['Wrong captcha text, please try again'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.'; | |
| 1697 | + ptBR['Internal captcha validation error'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.'; | |
| 1698 | + msg = '<br/><br/>'; | |
| 1699 | + msg += ptBR[data.responseJSON.message] || data.responseJSON.message; | |
| 1700 | + } | |
| 1701 | + }else{ | |
| 1689 | 1702 | msg = '<br/><br/>'; |
| 1690 | - msg += ptBR[data.responseJSON.message] || data.responseJSON.message; | |
| 1703 | + msg += 'Erro na comunicação com o servidor.'; | |
| 1691 | 1704 | } |
| 1692 | - }else{ | |
| 1693 | - msg = '<br/><br/>'; | |
| 1694 | - msg += 'Erro na comunicação com o servidor.'; | |
| 1705 | + message.html('<p>Não foi possível efetuar o cadastro:' + msg + '</p>'); | |
| 1706 | + message.show(); | |
| 1707 | + $(document).trigger('login:fail', data); | |
| 1695 | 1708 | } |
| 1696 | - message.html('<p>Não foi possível efetuar o cadastro:' + msg + '</p>'); | |
| 1697 | - message.show(); | |
| 1698 | - $(document).trigger('login:fail', data); | |
| 1699 | - } | |
| 1700 | - ) | |
| 1701 | - .always(function (data) { | |
| 1702 | - $loading.hide(); | |
| 1703 | - if(!data || data.activated) { | |
| 1704 | - $signupForm.show(); | |
| 1709 | + ) | |
| 1710 | + .always(function (data) { | |
| 1711 | + $loading.hide(); | |
| 1712 | + if(!data || data.activated) { | |
| 1713 | + $signupForm.show(); | |
| 1714 | + } | |
| 1705 | 1715 | } |
| 1706 | - } | |
| 1707 | - ); | |
| 1708 | - } | |
| 1709 | - }); | |
| 1716 | + ); | |
| 1717 | + } | |
| 1718 | + }); | |
| 1710 | 1719 | |
| 1711 | - var popupCenter = function(url, title, w, h) { | |
| 1712 | - var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left; | |
| 1713 | - var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top; | |
| 1720 | + var popupCenter = function(url, title, w, h) { | |
| 1721 | + var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left; | |
| 1722 | + var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top; | |
| 1714 | 1723 | |
| 1715 | - var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; | |
| 1716 | - var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; | |
| 1724 | + var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; | |
| 1725 | + var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; | |
| 1717 | 1726 | |
| 1718 | - var left = ((width / 2) - (w / 2)) + dualScreenLeft; | |
| 1719 | - var top = ((height / 3) - (h / 3)) + dualScreenTop; | |
| 1727 | + var left = ((width / 2) - (w / 2)) + dualScreenLeft; | |
| 1728 | + var top = ((height / 3) - (h / 3)) + dualScreenTop; | |
| 1720 | 1729 | |
| 1721 | - var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); | |
| 1730 | + var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); | |
| 1722 | 1731 | |
| 1723 | - // Puts focus on the newWindow | |
| 1724 | - if (window.focus) { | |
| 1725 | - newWindow.focus(); | |
| 1726 | - } | |
| 1727 | - }; | |
| 1732 | + // Puts focus on the newWindow | |
| 1733 | + if (window.focus) { | |
| 1734 | + newWindow.focus(); | |
| 1735 | + } | |
| 1736 | + }; | |
| 1728 | 1737 | |
| 1729 | - $(document).on('click', '.social a.popup', {}, function popUp(e) { | |
| 1730 | - var self = $(this); | |
| 1731 | - popupCenter(self.attr('href'), self.find('.rrssb-text').html(), 580, 470); | |
| 1732 | - e.preventDefault(); | |
| 1733 | - }); | |
| 1738 | + $(document).on('click', '.social a.popup', {}, function popUp(e) { | |
| 1739 | + var self = $(this); | |
| 1740 | + popupCenter(self.attr('href'), self.find('.rrssb-text').html(), 580, 470); | |
| 1741 | + e.preventDefault(); | |
| 1742 | + }); | |
| 1734 | 1743 | |
| 1735 | - $(document).on('click', '#logout-button', function (e){ | |
| 1736 | - $.removeCookie('_dialoga_session'); | |
| 1737 | - $.removeCookie('votedProposals'); | |
| 1738 | - $.removeCookie('*'); | |
| 1739 | - logged_in = false; | |
| 1740 | - Main.showLogin(); | |
| 1741 | - if(window.location.hash.indexOf('/resultados') !== -1){ | |
| 1742 | - window.location.hash = window.location.hash.split('/resultados')[0]; | |
| 1743 | - }else{ | |
| 1744 | - location.reload(); | |
| 1745 | - } | |
| 1746 | - e.preventDefault(); | |
| 1747 | - }); | |
| 1744 | + $(document).on('click', '#logout-button', function (e){ | |
| 1745 | + $.removeCookie('_dialoga_session'); | |
| 1746 | + $.removeCookie('votedProposals'); | |
| 1747 | + $.removeCookie('*'); | |
| 1748 | + logged_in = false; | |
| 1749 | + Main.showLogin(); | |
| 1750 | + if(window.location.hash.indexOf('/resultados') !== -1){ | |
| 1751 | + window.location.hash = window.location.hash.split('/resultados')[0]; | |
| 1752 | + }else{ | |
| 1753 | + location.reload(); | |
| 1754 | + } | |
| 1755 | + e.preventDefault(); | |
| 1756 | + }); | |
| 1757 | + | |
| 1758 | + // hack-fix to support z-index over video/iframe | |
| 1759 | + // function checkIframes () { | |
| 1748 | 1760 | |
| 1749 | - // hack-fix to support z-index over video/iframe | |
| 1750 | - // function checkIframes () { | |
| 1761 | + // $('iframe').each(function(){ | |
| 1762 | + // var $iframe = $(this); | |
| 1763 | + // var url = $iframe.attr('src'); | |
| 1764 | + // var c = '?'; | |
| 1751 | 1765 | |
| 1752 | - // $('iframe').each(function(){ | |
| 1753 | - // var $iframe = $(this); | |
| 1754 | - // var url = $iframe.attr('src'); | |
| 1755 | - // var c = '?'; | |
| 1766 | + // if(url.indexOf("youtube") === -1){ | |
| 1767 | + // // is not a iframe of youtube | |
| 1768 | + // // console.debug('is not a iframe of youtube'); | |
| 1769 | + // return; | |
| 1770 | + // } | |
| 1756 | 1771 | |
| 1757 | - // if(url.indexOf("youtube") === -1){ | |
| 1758 | - // // is not a iframe of youtube | |
| 1759 | - // // console.debug('is not a iframe of youtube'); | |
| 1760 | - // return; | |
| 1761 | - // } | |
| 1772 | + // if(url.indexOf("wmode=opaque") !== -1){ | |
| 1773 | + // // already in opaque mode | |
| 1774 | + // // console.debug('already in opaque mode'); | |
| 1775 | + // return; | |
| 1776 | + // } | |
| 1762 | 1777 | |
| 1763 | - // if(url.indexOf("wmode=opaque") !== -1){ | |
| 1764 | - // // already in opaque mode | |
| 1765 | - // // console.debug('already in opaque mode'); | |
| 1766 | - // return; | |
| 1767 | - // } | |
| 1778 | + // if(url.indexOf('?') !== -1){ | |
| 1779 | + // c = '&'; | |
| 1780 | + // } | |
| 1768 | 1781 | |
| 1769 | - // if(url.indexOf('?') !== -1){ | |
| 1770 | - // c = '&'; | |
| 1771 | - // } | |
| 1782 | + // $iframe.attr("src",url+c+"wmode=opaque"); | |
| 1783 | + // // console.debug('iframe changed to opaque mode'); | |
| 1784 | + // }); | |
| 1772 | 1785 | |
| 1773 | - // $iframe.attr("src",url+c+"wmode=opaque"); | |
| 1774 | - // // console.debug('iframe changed to opaque mode'); | |
| 1775 | - // }); | |
| 1786 | + // setTimeout(checkIframes, 500); | |
| 1787 | + // } | |
| 1788 | + // checkIframes(); | |
| 1776 | 1789 | |
| 1777 | - // setTimeout(checkIframes, 500); | |
| 1778 | - // } | |
| 1779 | - // checkIframes(); | |
| 1790 | + }); | |
| 1780 | 1791 | |
| 1781 | - }); | |
| 1792 | + window.addEventListener('message', function(ev) { | |
| 1793 | + if (ev.data.message === 'oauthClientPluginResult') { | |
| 1794 | + Main.loginCallback(ev.data.logged_in, ev.data.private_token, ev.data.user); | |
| 1795 | + ev.source.close(); | |
| 1796 | + } | |
| 1797 | + }); | |
| 1782 | 1798 | |
| 1783 | - window.addEventListener('message', function(ev) { | |
| 1784 | - if (ev.data.message === 'oauthClientPluginResult') { | |
| 1785 | - Main.loginCallback(ev.data.logged_in, ev.data.private_token, ev.data.user); | |
| 1786 | - ev.source.close(); | |
| 1799 | + if('onhashchange' in window){ | |
| 1800 | + window.onhashchange = function(){ | |
| 1801 | + Main.locationHashChanged.apply(Main); | |
| 1802 | + }; | |
| 1803 | + }else{ | |
| 1804 | + console.warn('The browser not supports the hashchange event!'); | |
| 1787 | 1805 | } |
| 1788 | - }); | |
| 1789 | 1806 | |
| 1790 | - if('onhashchange' in window){ | |
| 1791 | - window.onhashchange = function(){ | |
| 1792 | - Main.locationHashChanged.apply(Main); | |
| 1793 | - }; | |
| 1794 | - }else{ | |
| 1795 | - console.warn('The browser not supports the hashchange event!'); | |
| 1796 | - } | |
| 1807 | + // Handle resize event | |
| 1808 | + (function($,sr){ | |
| 1797 | 1809 | |
| 1798 | - // Handle resize event | |
| 1799 | - (function($,sr){ | |
| 1810 | + // debouncing function from John Hann | |
| 1811 | + // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ | |
| 1812 | + var debounce = function (func, threshold, execAsap) { | |
| 1813 | + var timeout; | |
| 1800 | 1814 | |
| 1801 | - // debouncing function from John Hann | |
| 1802 | - // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ | |
| 1803 | - var debounce = function (func, threshold, execAsap) { | |
| 1804 | - var timeout; | |
| 1815 | + return function debounced () { | |
| 1816 | + var obj = this, args = arguments; | |
| 1805 | 1817 | |
| 1806 | - return function debounced () { | |
| 1807 | - var obj = this, args = arguments; | |
| 1818 | + function delayed () { | |
| 1819 | + if (!execAsap){ | |
| 1820 | + func.apply(obj, args); | |
| 1821 | + } | |
| 1822 | + timeout = null; | |
| 1823 | + } | |
| 1808 | 1824 | |
| 1809 | - function delayed () { | |
| 1810 | - if (!execAsap){ | |
| 1825 | + if (timeout){ | |
| 1826 | + clearTimeout(timeout); | |
| 1827 | + }else if (execAsap){ | |
| 1811 | 1828 | func.apply(obj, args); |
| 1812 | 1829 | } |
| 1813 | - timeout = null; | |
| 1814 | - } | |
| 1815 | 1830 | |
| 1816 | - if (timeout){ | |
| 1817 | - clearTimeout(timeout); | |
| 1818 | - }else if (execAsap){ | |
| 1819 | - func.apply(obj, args); | |
| 1820 | - } | |
| 1821 | - | |
| 1822 | - timeout = setTimeout(delayed, threshold || 100); | |
| 1831 | + timeout = setTimeout(delayed, threshold || 100); | |
| 1832 | + }; | |
| 1823 | 1833 | }; |
| 1824 | - }; | |
| 1825 | 1834 | |
| 1826 | - // smartresize | |
| 1827 | - jQuery.fn[sr] = function(fn){ | |
| 1828 | - return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); | |
| 1829 | - }; | |
| 1835 | + // smartresize | |
| 1836 | + jQuery.fn[sr] = function(fn){ | |
| 1837 | + return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); | |
| 1838 | + }; | |
| 1830 | 1839 | |
| 1831 | - })(jQuery, 'smartresize'); | |
| 1840 | + })(jQuery, 'smartresize'); | |
| 1832 | 1841 | |
| 1833 | - $(window).smartresize(function(){ | |
| 1834 | - // console.log('window resized'); | |
| 1835 | - Main.computeBoxHeight(); | |
| 1836 | - }); | |
| 1842 | + $(window).smartresize(function(){ | |
| 1843 | + // console.log('window resized'); | |
| 1844 | + Main.computeBoxHeight(); | |
| 1845 | + }); | |
| 1837 | 1846 | |
| 1838 | - return Main; | |
| 1847 | + return Main; | |
| 1839 | 1848 | }); | ... | ... |
package.json
| ... | ... | @@ -13,9 +13,23 @@ |
| 13 | 13 | "gulp-sass": "^2.0.1" |
| 14 | 14 | }, |
| 15 | 15 | "devDependencies": { |
| 16 | + "del": "^1.2.0", | |
| 16 | 17 | "gulp": "^3.9.0", |
| 18 | + "gulp-add": "0.0.2", | |
| 19 | + "gulp-concat": "^2.6.0", | |
| 17 | 20 | "gulp-connect": "^2.2.0", |
| 18 | - "gulp-ruby-sass": "^1.0.5" | |
| 21 | + "gulp-copy": "0.0.2", | |
| 22 | + "gulp-filter": "^3.0.0", | |
| 23 | + "gulp-if": "^1.2.5", | |
| 24 | + "gulp-minify-css": "^1.2.0", | |
| 25 | + "gulp-pipemin": "^2.2.3", | |
| 26 | + "gulp-requirejs-optimize" : "jridgewell/gulp-requirejs-optimize", | |
| 27 | + "gulp-rev": "^5.1.0", | |
| 28 | + "gulp-rev-replace": "^0.4.2", | |
| 29 | + "gulp-ruby-sass": "^1.0.5", | |
| 30 | + "gulp-sourcemaps": "^1.5.2", | |
| 31 | + "gulp-uglify": "^1.2.0", | |
| 32 | + "gulp-useref": "^1.2.0" | |
| 19 | 33 | }, |
| 20 | 34 | "scripts": { |
| 21 | 35 | "test": "echo \"Error: no test specified\" && exit 1" | ... | ... |