From ad056e69d5949923938e79ce45d546101ab3f4f6 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 16 Aug 2018 21:25:45 -0500 Subject: [PATCH 1/5] utility.js: simplify even/odd table row striping. --- app/javascript/src/javascripts/common.js | 4 ---- app/javascript/src/javascripts/saved_searches.js | 4 +--- app/javascript/src/javascripts/utility.js | 9 --------- app/javascript/src/styles/common/tables.scss | 2 +- app/views/artist_versions/_revert_listing.html.erb | 2 +- app/views/artist_versions/_standard_listing.html.erb | 2 +- 6 files changed, 4 insertions(+), 19 deletions(-) diff --git a/app/javascript/src/javascripts/common.js b/app/javascript/src/javascripts/common.js index c6428f0e4..9c5a3b900 100644 --- a/app/javascript/src/javascripts/common.js +++ b/app/javascript/src/javascripts/common.js @@ -2,10 +2,6 @@ import Cookie from './cookie' import Utility from './utility' $(function() { - // Table striping - $(".striped tbody tr:even").addClass("even"); - $(".striped tbody tr:odd").addClass("odd"); - // Account notices $("#hide-sign-up-notice").click(function(e) { $("#sign-up-notice").hide(); diff --git a/app/javascript/src/javascripts/saved_searches.js b/app/javascript/src/javascripts/saved_searches.js index 4f0e0bc48..af0069c45 100644 --- a/app/javascript/src/javascripts/saved_searches.js +++ b/app/javascript/src/javascripts/saved_searches.js @@ -1,10 +1,8 @@ -import Utility from './utility' - let SavedSearch = {}; SavedSearch.initialize_all = function() { if ($("#c-saved-searches").length) { - Utility.sorttable($("#c-saved-searches table")); + $("#c-saved-searches table").stupidtable(); } } diff --git a/app/javascript/src/javascripts/utility.js b/app/javascript/src/javascripts/utility.js index 246b6c676..1fb3c7879 100644 --- a/app/javascript/src/javascripts/utility.js +++ b/app/javascript/src/javascripts/utility.js @@ -103,15 +103,6 @@ Utility.regexp_escape = function(string) { return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); } -Utility.sorttable = function(table) { - table.stupidtable(); - table.bind("aftertablesort", function(event, data) { - $("#c-saved-searches table tbody tr").removeClass("even odd"); - $("#c-saved-searches table tbody tr:even").addClass("even"); - $("#c-saved-searches table tbody tr:odd").addClass("odd"); - }); -}; - $.fn.selectRange = function(start, end) { return this.each(function() { if (this.setSelectionRange) { diff --git a/app/javascript/src/styles/common/tables.scss b/app/javascript/src/styles/common/tables.scss index 1d200e64b..8f68b7bba 100644 --- a/app/javascript/src/styles/common/tables.scss +++ b/app/javascript/src/styles/common/tables.scss @@ -35,7 +35,7 @@ table.striped { } } - tr.even { + tr:nth-child(even) { background-color: #FAFAFA; } } diff --git a/app/views/artist_versions/_revert_listing.html.erb b/app/views/artist_versions/_revert_listing.html.erb index 1a4381650..b73fb7112 100644 --- a/app/views/artist_versions/_revert_listing.html.erb +++ b/app/views/artist_versions/_revert_listing.html.erb @@ -19,7 +19,7 @@ <% @artist_versions.each do |artist_version| %> - + <% if artist_version.visible? %> <%= link_to artist_version.name, artist_path(artist_version.artist_id) %> <%= artist_version_other_names_diff(artist_version) %> diff --git a/app/views/artist_versions/_standard_listing.html.erb b/app/views/artist_versions/_standard_listing.html.erb index dfe57a2c7..7e71b6bd4 100644 --- a/app/views/artist_versions/_standard_listing.html.erb +++ b/app/views/artist_versions/_standard_listing.html.erb @@ -16,7 +16,7 @@ <% @artist_versions.each do |artist_version| %> - + <% if artist_version.visible? %> <%= link_to artist_version.name, artist_path(artist_version.artist_id) %> From dfffabd66270fba9bdc5651aee2aa0544ddcc2dc Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 16 Aug 2018 22:03:50 -0500 Subject: [PATCH 2/5] utility.js: replace Utility.scroll_to with Element.scrollIntoView. https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView https://caniuse.com/#feat=scrollintoview --- app/javascript/src/javascripts/comments.js | 2 +- app/javascript/src/javascripts/notes.js | 2 +- app/javascript/src/javascripts/utility.js | 18 ------------------ app/views/forum_posts/new.js.erb | 4 +--- app/views/forum_topics/show.html.erb | 6 +----- 5 files changed, 4 insertions(+), 28 deletions(-) diff --git a/app/javascript/src/javascripts/comments.js b/app/javascript/src/javascripts/comments.js index 9347e24b7..88cacd24f 100644 --- a/app/javascript/src/javascripts/comments.js +++ b/app/javascript/src/javascripts/comments.js @@ -39,7 +39,7 @@ Comment.show_new_comment_form = function(e) { $(e.target).hide(); var $form = $(e.target).closest("div.new-comment").find("form"); $form.show(); - Utility.scroll_to($form); + $form[0].scrollIntoView(false); e.preventDefault(); } diff --git a/app/javascript/src/javascripts/notes.js b/app/javascript/src/javascripts/notes.js index 43f4a6586..7e42aba87 100644 --- a/app/javascript/src/javascripts/notes.js +++ b/app/javascript/src/javascripts/notes.js @@ -145,7 +145,7 @@ let Note = { Note.Body.show(note_id); $(".note-box-highlighted").removeClass("note-box-highlighted"); $note_box.addClass("note-box-highlighted"); - Utility.scroll_to($note_box); + $note_box[0].scrollIntoView(false); }, resize_inner_border: function($note_box) { diff --git a/app/javascript/src/javascripts/utility.js b/app/javascript/src/javascripts/utility.js index 1fb3c7879..8d83ce3bb 100644 --- a/app/javascript/src/javascripts/utility.js +++ b/app/javascript/src/javascripts/utility.js @@ -12,24 +12,6 @@ Utility.test_max_width = function(width) { return mq.matches; } -Utility.scrolling = false; - -Utility.scroll_to = function(element) { - if (Utility.scrolling) { - return; - } else { - Utility.scrolling = true; - } - - var top = null; - if (typeof element === "number") { - top = element; - } else { - top = element.offset().top - 10; - } - $('html, body').animate({scrollTop: top}, 300, "linear", function() {Utility.scrolling = false;}); -} - Utility.notice_timeout_id = undefined; Utility.notice = function(msg, permanent) { diff --git a/app/views/forum_posts/new.js.erb b/app/views/forum_posts/new.js.erb index fe0a171da..92bcc3378 100644 --- a/app/views/forum_posts/new.js.erb +++ b/app/views/forum_posts/new.js.erb @@ -4,7 +4,5 @@ if ($("#forum_post_body").val().length > 0) { } $("#forum_post_body").val(msg); $("#topic-response").show(); -$('html, body').animate({ - scrollTop: $("#forum_post_body").offset().top - 100 -}, 500); +document.body.scrollIntoView(false); $("#forum_post_body").selectEnd(); diff --git a/app/views/forum_topics/show.html.erb b/app/views/forum_topics/show.html.erb index 97598ef62..ce5a027d2 100644 --- a/app/views/forum_topics/show.html.erb +++ b/app/views/forum_topics/show.html.erb @@ -49,11 +49,7 @@ $(function() { $("#new-response-link").click(function(e) { $("#topic-response").show(); - - $('html, body').animate({ - scrollTop: $("#forum_post_body").offset().top - 100 - }, 500); - + document.body.scrollIntoView(false); e.preventDefault(); }) }); From 21895ef0aa0327fcbbf277a29db983a4ef0d3245 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 16 Aug 2018 22:39:01 -0500 Subject: [PATCH 3/5] utility.js: simplify $.fn.selectEnd(). Remove createTextRange fallback; setSelectionRange is supported by all modern browsers. https://caniuse.com/#feat=input-selection --- app/javascript/src/javascripts/utility.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/app/javascript/src/javascripts/utility.js b/app/javascript/src/javascripts/utility.js index 8d83ce3bb..0b391fe07 100644 --- a/app/javascript/src/javascripts/utility.js +++ b/app/javascript/src/javascripts/utility.js @@ -85,26 +85,11 @@ Utility.regexp_escape = function(string) { return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); } -$.fn.selectRange = function(start, end) { - return this.each(function() { - if (this.setSelectionRange) { - this.focus(); - this.setSelectionRange(start, end); - } else if (this.createTextRange) { - var range = this.createTextRange(); - range.collapse(true); - range.moveEnd('character', end); - range.moveStart('character', start); - range.select(); - } - }); -}; - $.fn.selectEnd = function() { - if (this.length) { - this.selectRange(this.val().length, this.val().length); - } - return this; + return this.each(function() { + this.focus(); + this.setSelectionRange(this.value.length, this.value.length); + }) } $(function() { From e9d6a0fda6de71a4efbcca22b92376e3f6c41685 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 16 Aug 2018 23:17:43 -0500 Subject: [PATCH 4/5] utility.js: remove dead Utility.without function. --- app/javascript/src/javascripts/utility.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/javascript/src/javascripts/utility.js b/app/javascript/src/javascripts/utility.js index 0b391fe07..35ade85ec 100644 --- a/app/javascript/src/javascripts/utility.js +++ b/app/javascript/src/javascripts/utility.js @@ -71,16 +71,6 @@ Utility.intersect = function(a, b) { return result; } -Utility.without = function(array, element) { - var temp = []; - $.each(array, function(i, v) { - if (v !== element) { - temp.push(v); - } - }); - return temp; -} - Utility.regexp_escape = function(string) { return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); } From f85b34cd9ff77cc9fb9e44dae26e306f7447a7c9 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 17 Aug 2018 16:19:29 -0500 Subject: [PATCH 5/5] shortcuts.js: simplify scroll up/down hotkeys. --- app/javascript/src/javascripts/shortcuts.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/javascript/src/javascripts/shortcuts.js b/app/javascript/src/javascripts/shortcuts.js index 476ed6be7..f7898677d 100644 --- a/app/javascript/src/javascripts/shortcuts.js +++ b/app/javascript/src/javascripts/shortcuts.js @@ -43,16 +43,11 @@ Shortcuts.initialize_data_shortcuts = function() { }; Shortcuts.nav_scroll_down = function() { - var scroll_top = $(window).scrollTop() + ($(window).height() * 0.15); - $(window).scrollTop(scroll_top); + window.scrollBy(0, $(window).height() * 0.15); } Shortcuts.nav_scroll_up = function() { - var scroll_top = $(window).scrollTop() - ($(window).height() * 0.15); - if (scroll_top < 0) { - scroll_top = 0; - } - $(window).scrollTop(scroll_top); + window.scrollBy(0, $(window).height() * -0.15); } $(document).ready(function() {