diff options
| author | adamhrv <adam@ahprojects.com> | 2018-12-15 19:57:49 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2018-12-15 19:57:49 +0100 |
| commit | 82b2c0b5d6d7baccbe4d574d96e18fe2078047d7 (patch) | |
| tree | a8784b7ec2bc5a0451c252f66a6b786f3a2504f5 /server/app/static/js/app.js | |
| parent | 8e978af21c2b29f678a09701afb3ec7d65d0a6ab (diff) | |
| parent | c5b02ffab8d388e8a2925e51736b902a48a95e71 (diff) | |
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'server/app/static/js/app.js')
| -rw-r--r-- | server/app/static/js/app.js | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/server/app/static/js/app.js b/server/app/static/js/app.js new file mode 100644 index 00000000..454d5c37 --- /dev/null +++ b/server/app/static/js/app.js @@ -0,0 +1,158 @@ +var app = (function(){ + + var app = {} + + app.init = function(){ + upload.init() + app.bind() + app.build() + app.resize() + app.route() + } + app.bind = function(){ + $(window).on('resize', app.resize) + $(".about_button").on('click', app.about_show) + $(".privacy_button").on('click', app.privacy_show) + $(".modal").on('click', app.modal_hide) + $(".modal .btn").on('click', app.modal_hide) + $(".modal .inner").on('click', preventDefault) + $("#destroy_data").on('click', app.destroyData) + $("#show_all_results").on('click', app.showAllResults) + } + app.build = function(){ + var items = JSON.parse(decodeEntities($("#dropdown_options").html())) + var $dropdown = $("#dropdown") + var options = Object.keys(items).sort().map(key => { + var item = items[key] + var option = document.createElement('option') + option.value = item.name + option.innerHTML = item.title + if (item.selected) option.selected = true + $dropdown.append(option) + }) + var loader = new Image () + loader.src = '/static/img/loader.gif' + } + app.resize = function(){ + var $el = $('#photo_area') + var w = $el.width() + $el.height($el.width()) + } + app.route = function(){ + const path = window.location.pathname.split('/') + path.shift() + switch (path[0]) { + case 'd': + app.processingComplete(path[1], true) // public + break + case 'p': + app.processingComplete(path[1], false) // private + break + case 'about': + app.about_show() + break + case 'privacy': + app.privacy_show() + break + default: + // load index, default state + break + } + } + + /* upload UI changes */ + + app.didPickPhoto = function(){ + $('#upload_controls').fadeIn() + $('#user_photo_canvas').show() + $('#take_photo_btn').hide() + } + app.didClickUpload = function(){ + $('#upload_controls').slideUp('fast') + $('#user_photo_canvas').hide() + $('#preloader_anim').fadeIn('fast') + $('#progress').fadeIn() + } + app.uploadDidComplete = function(){ + $('#preloader_anim').hide() + $('#progress').hide() + } + app.uploadDidComplete = function(){ + // $('#preloader_anim').hide() + // $('#progress').hide() + } + app.updateProgress = function(message, percentage){ + message = message || "Processing..." + percentage = percentage || 0 + $("#progress").html(message) + } + app.processingComplete = function(uuid, is_public){ + $('#preloader_anim').hide() + $('#progress').hide() + // + $("header h2").html("Your dull result") + $(".upload_view").hide() + $(".results_view").show() + var endpoint = is_public ? 'json' : 'json_private' + $.getJSON('/static/media/' + endpoint + '/' + uuid + '.json', function(data){ + console.log(data) + var template = $("#result_template").html() + var final_result = new Image + final_result.src = data.files[data.files.length-1].fn + $(".final_result").empty() + $(".all_results").empty() + $(".final_result").append(final_result) + data.files.forEach(function(file){ + var t = template.replace(/{img}/, file.fn).replace(/{title}/, file.title) + $(".all_results").append(t) + }) + $(".result_view").show() + $(".permalink").attr('href', window.location.href) + }).fail(function(){ + console.log('error fetching json') + window.location.href = '/' + }) + } + var detailed = false + app.showAllResults = function(){ + if (!detailed) { + detailed = true + $(this).html('Hide') + $(".all_results").fadeIn('fast') + } else { + detailed = false + $(this).html('Detailed Analysis') + $(".all_results").slideUp('fast') + } + } + app.destroyData = function(){ + var uuid = window.location.pathname.split('/')[2] + var confirmed = confirm("Do you really want to delete your dull dream?") + if (confirmed) { + $.get( [window.location.pathname, 'destroy'].join('/').replace('//', '/') ).always(function(){ + alert('Dull dream deleted!') + window.location.href = '/' + }) + } + } + + /* modals */ + + app.about_show = function(e){ + e.preventDefault() + $(".about_view").addClass('visible') + } + app.privacy_show = function(e){ + e.preventDefault() + $(".privacy_view").addClass('visible') + } + app.modal_hide = function(e){ + e.preventDefault() + e.stopPropagation() + $(".modal").removeClass('visible') + } + + document.addEventListener('DOMContentLoaded', app.init) + + return app +})()
\ No newline at end of file |
