From 7d2f1b15945aa67337b0797e77754f498e2b0fe2 Mon Sep 17 00:00:00 2001 From: Yuki Date: Mon, 11 May 2015 11:28:24 +0530 Subject: [PATCH 1/7] Non-blocking image load --- app/assets/javascripts/settings.coffee | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/settings.coffee b/app/assets/javascripts/settings.coffee index 6142a7dd..595511ba 100644 --- a/app/assets/javascripts/settings.coffee +++ b/app/assets/javascripts/settings.coffee @@ -4,15 +4,28 @@ evt.preventDefault() $("button[data-target=#modal-passwd]").trigger 'click' +readImage = (file, callback) -> + fr = new FileReader() + fr.addEventListener "load", (e) -> + callback e.target.result + fr.readAsBinaryString file + +freeURL = () -> + +if window.URL? or window.webkitURL? + readImage = (file, callback) -> + callback (window.URL || window.webkitURL).createObjectURL file + freeURL = (url) -> + URL.revokeObjectURL url + # Profile pic ($ document).on 'change', 'input#user_profile_picture[type=file]', -> - input = ($ this)[0] + input = this ($ '#profile-picture-crop-controls').slideUp 400, -> if input.files and input.files[0] - fr = new FileReader() - ($ fr).on 'load', (e) -> + readImage input.files[0], (src) -> cropper = ($ '#profile-picture-cropper') preview = ($ '#profile-picture-preview') @@ -30,6 +43,9 @@ # marginTop: '-' + Math.round(ry * data.y) + 'px' cropper.on 'load', -> + if ({}.toString).call(src) == "[object URL]" + freeURL src + side = if cropper[0].naturalWidth > cropper[0].naturalHeight cropper[0].naturalHeight else @@ -48,17 +64,14 @@ ($ '#profile-picture-crop-controls')[0].dataset.bound = true ($ '#profile-picture-crop-controls').slideDown() - cropper.attr 'src', e.target.result - - fr.readAsDataURL(input.files[0]) + cropper.attr 'src', src ($ document).on 'change', 'input#user_profile_header[type=file]', -> - input = ($ this)[0] + input = this ($ '#profile-header-crop-controls').slideUp 400, -> if input.files and input.files[0] - fr = new FileReader() - ($ fr).on 'load', (e) -> + readImage input.files[0], (src) -> cropper = ($ '#profile-header-cropper') preview = ($ '#profile-header-preview') @@ -69,6 +82,9 @@ ($ '#crop_h_h').val Math.floor(data.h / data.scale) cropper.on 'load', -> + if ({}.toString).call(src) == "[object URL]" + freeURL src + cropper.guillotine width: 1500 height: 350 @@ -82,6 +98,4 @@ ($ '#profile-header-crop-controls')[0].dataset.bound = true ($ '#profile-header-crop-controls').slideDown() - cropper.attr 'src', e.target.result - - fr.readAsDataURL(input.files[0]) + cropper.attr 'src', src From 580e64540382e499c18d66507480361f226f98ef Mon Sep 17 00:00:00 2001 From: Yuki Date: Mon, 11 May 2015 12:31:48 +0530 Subject: [PATCH 2/7] Fix ban.js throwing errors --- app/assets/javascripts/moderation/ban.coffee | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/moderation/ban.coffee b/app/assets/javascripts/moderation/ban.coffee index 87ec6555..ebb4d7b8 100644 --- a/app/assets/javascripts/moderation/ban.coffee +++ b/app/assets/javascripts/moderation/ban.coffee @@ -1,5 +1,7 @@ -$(document).on "DOMContentLoaded", -> +load = -> parent = $ "#ban-control-super" + return unless parent.length > 0 + parent.find('#_ban').on "change", (event) -> $t = $ this if $t.is(":checked") @@ -56,3 +58,9 @@ $(document).on "DOMContentLoaded", -> console.log jqxhr, status, error showNotification "An error occurred, a developer should check the console for details", false complete: (jqxhr, status) -> + +$(document).on "DOMContentLoaded", -> + load() + +$(document).on "page:load", -> + load() From 2e89758c374e694b574fa534c31f3693ee9dca09 Mon Sep 17 00:00:00 2001 From: Yuki Date: Wed, 27 May 2015 11:11:38 +0530 Subject: [PATCH 3/7] few JS fixes and header parallax (closes #53) --- .../javascripts/application.js.erb.coffee | 7 ++-- app/assets/javascripts/user.coffee | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/application.js.erb.coffee b/app/assets/javascripts/application.js.erb.coffee index e322e7fb..1cfd3fa2 100644 --- a/app/assets/javascripts/application.js.erb.coffee +++ b/app/assets/javascripts/application.js.erb.coffee @@ -45,9 +45,10 @@ _ready = -> if typeof sweetAlertInitialize != "undefined" sweetAlertInitialize() - particleground document.getElementById('particles'), - dotColor: '#5e35b1' - lineColor: '#5e35b1' + if document.getElementById('particles')? + particleground document.getElementById('particles'), + dotColor: '#5e35b1' + lineColor: '#5e35b1' $(document).ready _ready $(document).on 'page:load', _ready diff --git a/app/assets/javascripts/user.coffee b/app/assets/javascripts/user.coffee index e12e0407..b08b15f2 100644 --- a/app/assets/javascripts/user.coffee +++ b/app/assets/javascripts/user.coffee @@ -51,3 +51,39 @@ $(document).on "click", "a[data-action=report-user]", (ev) -> btn = $(this) target = btn[0].dataset.target reportDialog "user", target, -> btn.button "reset" + +# parallax +PARALLAX_PREFIX = undefined +if typeof document.documentElement.style.webkitTransform == "string" + PARALLAX_PREFIX = "webkit" +if typeof document.documentElement.style.mozTransform == "string" + PARALLAX_PREFIX = "moz" +if typeof document.documentElement.style.oTransform == "string" + PARALLAX_PREFIX = "o" +if typeof document.documentElement.style.msTransform == "string" + PARALLAX_PREFIX = "ms" +if typeof document.documentElement.style.khtmlTransform == "string" + PARALLAX_PREFIX = "khtml" +if typeof document.documentElement.style.transform == "string" + PARALLAX_PREFIX = "" + +HEADER_PARALLAX = undefined + +if PARALLAX_PREFIX? + PARALLAX_CSS = "transform" + if PARALLAX_PREFIX.length + PARALLAX_CSS = PARALLAX_PREFIX + PARALLAX_CSS.charAt(0).toUpperCase() + PARALLAX_CSS.slice(1) + + window.HEADER_PARALLAX_INERTIA = 0.4; + + HEADER_PARALLAX = -> + header = $("#profile--header:not(.profile--no-header) img")[0] + return unless header? + top = (document.body || document.documentElement).scrollTop * HEADER_PARALLAX_INERTIA + header.style[PARALLAX_CSS] = "translate3d(0px, #{top}px, 0px)"; + + $(window).on "scroll", (event) -> + HEADER_PARALLAX() + +$(document).ready -> + HEADER_PARALLAX() if HEADER_PARALLAX? From b1ad14caf0eeb79eb104cb681ec12cf8782a0624 Mon Sep 17 00:00:00 2001 From: Georg G Date: Wed, 27 May 2015 16:18:08 +0200 Subject: [PATCH 4/7] swapped || order --- app/assets/javascripts/user.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/user.coffee b/app/assets/javascripts/user.coffee index b08b15f2..5985d652 100644 --- a/app/assets/javascripts/user.coffee +++ b/app/assets/javascripts/user.coffee @@ -79,7 +79,7 @@ if PARALLAX_PREFIX? HEADER_PARALLAX = -> header = $("#profile--header:not(.profile--no-header) img")[0] return unless header? - top = (document.body || document.documentElement).scrollTop * HEADER_PARALLAX_INERTIA + top = (document.documentElement || document.body).scrollTop * HEADER_PARALLAX_INERTIA header.style[PARALLAX_CSS] = "translate3d(0px, #{top}px, 0px)"; $(window).on "scroll", (event) -> From 76be03be665ad546c1cc9493520ae1c12b2f71ed Mon Sep 17 00:00:00 2001 From: Yuki Date: Thu, 28 May 2015 06:49:55 +0530 Subject: [PATCH 5/7] Fix header parallax (assigned a variable called 'top' which is read only, caused issues with firefox and blink/webkit browsers IDK why it worked in local test envs, but this should fix it) --- app/assets/javascripts/user.coffee | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/user.coffee b/app/assets/javascripts/user.coffee index 5985d652..0d7432ea 100644 --- a/app/assets/javascripts/user.coffee +++ b/app/assets/javascripts/user.coffee @@ -53,7 +53,7 @@ $(document).on "click", "a[data-action=report-user]", (ev) -> reportDialog "user", target, -> btn.button "reset" # parallax -PARALLAX_PREFIX = undefined +PARALLAX_PREFIX = null if typeof document.documentElement.style.webkitTransform == "string" PARALLAX_PREFIX = "webkit" if typeof document.documentElement.style.mozTransform == "string" @@ -67,7 +67,7 @@ if typeof document.documentElement.style.khtmlTransform == "string" if typeof document.documentElement.style.transform == "string" PARALLAX_PREFIX = "" -HEADER_PARALLAX = undefined +HEADER_PARALLAX = null if PARALLAX_PREFIX? PARALLAX_CSS = "transform" @@ -78,12 +78,18 @@ if PARALLAX_PREFIX? HEADER_PARALLAX = -> header = $("#profile--header:not(.profile--no-header) img")[0] - return unless header? - top = (document.documentElement || document.body).scrollTop * HEADER_PARALLAX_INERTIA - header.style[PARALLAX_CSS] = "translate3d(0px, #{top}px, 0px)"; + if header? + headerOffset = document.body.scrollTop * HEADER_PARALLAX_INERTIA + header.style[PARALLAX_CSS] = "translate3d(0px, #{headerOffset}px, 0px)"; + return # coffee doesn't have !-> to prevent returning like LiveScript has, god I miss livescript ;-; + # also no := to set global variables :-( + # or var-iables = varIables :-(( + # or fun! = fun() :-((( $(window).on "scroll", (event) -> HEADER_PARALLAX() + return $(document).ready -> HEADER_PARALLAX() if HEADER_PARALLAX? + return From b90702967382f063c8cfc4bd8be5d248b0a768c7 Mon Sep 17 00:00:00 2001 From: Yuki Date: Sat, 30 May 2015 06:38:49 +0530 Subject: [PATCH 6/7] and apparently browser variety is a good thing --- app/assets/javascripts/user.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/user.coffee b/app/assets/javascripts/user.coffee index 0d7432ea..5a2cf991 100644 --- a/app/assets/javascripts/user.coffee +++ b/app/assets/javascripts/user.coffee @@ -79,7 +79,7 @@ if PARALLAX_PREFIX? HEADER_PARALLAX = -> header = $("#profile--header:not(.profile--no-header) img")[0] if header? - headerOffset = document.body.scrollTop * HEADER_PARALLAX_INERTIA + headerOffset = Math.max(window.pageYOffset, window.scrollY, document.documentElement.scrollTop) * HEADER_PARALLAX_INERTIA header.style[PARALLAX_CSS] = "translate3d(0px, #{headerOffset}px, 0px)"; return # coffee doesn't have !-> to prevent returning like LiveScript has, god I miss livescript ;-; # also no := to set global variables :-( From 1796283ace6f36a412f8d06f99585e267dff1d13 Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Mon, 1 Jun 2015 15:39:23 +0200 Subject: [PATCH 7/7] change tab titles --- app/views/discover/index.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/discover/index.html.haml b/app/views/discover/index.html.haml index 18f46562..525f572e 100644 --- a/app/views/discover/index.html.haml +++ b/app/views/discover/index.html.haml @@ -16,13 +16,13 @@ %ul.nav.nav-tabs{role: "tablist"} %li.active{role: "presentation"} %a{href: "#answers", role: "tab", aria: {controls: "answers"}, data: {toggle: "tab"}} - Answers + Most Liked %li{role: "presentation"} %a{href: "#questions", role: "tab", aria: {controls: "questions"}, data: {toggle: "tab"}} - Questions + Most Answers %li{role: "presentation"} %a{href: "#comments", role: "tab", aria: {controls: "comments"}, data: {toggle: "tab"}} - Most Comments + Most Controversial .tab-content.discover = render 'discover/tab_answers', answers: @popular_answers = render 'discover/tab_questions', questions: @popular_questions @@ -37,7 +37,7 @@ New Users %li{role: "presentation"} %a{href: "#asked", role: "tab", aria: {controls: "asked"}, data: {toggle: "tab"}} - Most Asked Questions + Active Askers %li{role: "presentation"} %a{href: "#answered", role: "tab", aria: {controls: "answered"}, data: {toggle: "tab"}} Most Answers