Merge pull request #3818 from evazion/fix-utility-js
Cleanup utility.js
This commit is contained in:
@@ -39,7 +39,7 @@ Comment.show_new_comment_form = function(e) {
|
|||||||
$(e.target).hide();
|
$(e.target).hide();
|
||||||
var $form = $(e.target).closest("div.new-comment").find("form");
|
var $form = $(e.target).closest("div.new-comment").find("form");
|
||||||
$form.show();
|
$form.show();
|
||||||
Utility.scroll_to($form);
|
$form[0].scrollIntoView(false);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import Cookie from './cookie'
|
|||||||
import Utility from './utility'
|
import Utility from './utility'
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
// Table striping
|
|
||||||
$(".striped tbody tr:even").addClass("even");
|
|
||||||
$(".striped tbody tr:odd").addClass("odd");
|
|
||||||
|
|
||||||
// Account notices
|
// Account notices
|
||||||
$("#hide-sign-up-notice").click(function(e) {
|
$("#hide-sign-up-notice").click(function(e) {
|
||||||
$("#sign-up-notice").hide();
|
$("#sign-up-notice").hide();
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ let Note = {
|
|||||||
Note.Body.show(note_id);
|
Note.Body.show(note_id);
|
||||||
$(".note-box-highlighted").removeClass("note-box-highlighted");
|
$(".note-box-highlighted").removeClass("note-box-highlighted");
|
||||||
$note_box.addClass("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) {
|
resize_inner_border: function($note_box) {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import Utility from './utility'
|
|
||||||
|
|
||||||
let SavedSearch = {};
|
let SavedSearch = {};
|
||||||
|
|
||||||
SavedSearch.initialize_all = function() {
|
SavedSearch.initialize_all = function() {
|
||||||
if ($("#c-saved-searches").length) {
|
if ($("#c-saved-searches").length) {
|
||||||
Utility.sorttable($("#c-saved-searches table"));
|
$("#c-saved-searches table").stupidtable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,16 +43,11 @@ Shortcuts.initialize_data_shortcuts = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Shortcuts.nav_scroll_down = function() {
|
Shortcuts.nav_scroll_down = function() {
|
||||||
var scroll_top = $(window).scrollTop() + ($(window).height() * 0.15);
|
window.scrollBy(0, $(window).height() * 0.15);
|
||||||
$(window).scrollTop(scroll_top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Shortcuts.nav_scroll_up = function() {
|
Shortcuts.nav_scroll_up = function() {
|
||||||
var scroll_top = $(window).scrollTop() - ($(window).height() * 0.15);
|
window.scrollBy(0, $(window).height() * -0.15);
|
||||||
if (scroll_top < 0) {
|
|
||||||
scroll_top = 0;
|
|
||||||
}
|
|
||||||
$(window).scrollTop(scroll_top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|||||||
@@ -12,24 +12,6 @@ Utility.test_max_width = function(width) {
|
|||||||
return mq.matches;
|
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_timeout_id = undefined;
|
||||||
|
|
||||||
Utility.notice = function(msg, permanent) {
|
Utility.notice = function(msg, permanent) {
|
||||||
@@ -89,49 +71,15 @@ Utility.intersect = function(a, b) {
|
|||||||
return result;
|
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) {
|
Utility.regexp_escape = function(string) {
|
||||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
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) {
|
|
||||||
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() {
|
$.fn.selectEnd = function() {
|
||||||
if (this.length) {
|
return this.each(function() {
|
||||||
this.selectRange(this.val().length, this.val().length);
|
this.focus();
|
||||||
}
|
this.setSelectionRange(this.value.length, this.value.length);
|
||||||
return this;
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ table.striped {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tr.even {
|
tr:nth-child(even) {
|
||||||
background-color: #FAFAFA;
|
background-color: #FAFAFA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @artist_versions.each do |artist_version| %>
|
<% @artist_versions.each do |artist_version| %>
|
||||||
<tr class="<%= cycle 'even', 'odd' %>">
|
<tr>
|
||||||
<% if artist_version.visible? %>
|
<% if artist_version.visible? %>
|
||||||
<td><%= link_to artist_version.name, artist_path(artist_version.artist_id) %></td>
|
<td><%= link_to artist_version.name, artist_path(artist_version.artist_id) %></td>
|
||||||
<td class="col-expand"><%= artist_version_other_names_diff(artist_version) %></td>
|
<td class="col-expand"><%= artist_version_other_names_diff(artist_version) %></td>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @artist_versions.each do |artist_version| %>
|
<% @artist_versions.each do |artist_version| %>
|
||||||
<tr class="<%= cycle 'even', 'odd' %>">
|
<tr>
|
||||||
<% if artist_version.visible? %>
|
<% if artist_version.visible? %>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to artist_version.name, artist_path(artist_version.artist_id) %>
|
<%= link_to artist_version.name, artist_path(artist_version.artist_id) %>
|
||||||
|
|||||||
@@ -4,7 +4,5 @@ if ($("#forum_post_body").val().length > 0) {
|
|||||||
}
|
}
|
||||||
$("#forum_post_body").val(msg);
|
$("#forum_post_body").val(msg);
|
||||||
$("#topic-response").show();
|
$("#topic-response").show();
|
||||||
$('html, body').animate({
|
document.body.scrollIntoView(false);
|
||||||
scrollTop: $("#forum_post_body").offset().top - 100
|
|
||||||
}, 500);
|
|
||||||
$("#forum_post_body").selectEnd();
|
$("#forum_post_body").selectEnd();
|
||||||
|
|||||||
@@ -49,11 +49,7 @@
|
|||||||
$(function() {
|
$(function() {
|
||||||
$("#new-response-link").click(function(e) {
|
$("#new-response-link").click(function(e) {
|
||||||
$("#topic-response").show();
|
$("#topic-response").show();
|
||||||
|
document.body.scrollIntoView(false);
|
||||||
$('html, body').animate({
|
|
||||||
scrollTop: $("#forum_post_body").offset().top - 100
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user