mirror of https://gitlab.com/tildes/tildes.git
Deimos
6 years ago
30 changed files with 502 additions and 369 deletions
-
9tildes/static/js/behaviors/auto-focus.js
-
12tildes/static/js/behaviors/autocomplete-chip-clear.js
-
208tildes/static/js/behaviors/autocomplete-input.js
-
69tildes/static/js/behaviors/autocomplete-menu-item.js
-
16tildes/static/js/behaviors/autocomplete-menu.js
-
4tildes/static/js/behaviors/autoselect-input.js
-
8tildes/static/js/behaviors/autosubmit-on-change.js
-
25tildes/static/js/behaviors/cancel-button.js
-
27tildes/static/js/behaviors/comment-collapse-all-button.js
-
20tildes/static/js/behaviors/comment-collapse-button.js
-
17tildes/static/js/behaviors/comment-expand-all-button.js
-
69tildes/static/js/behaviors/comment-label-button.js
-
29tildes/static/js/behaviors/comment-parent-button.js
-
60tildes/static/js/behaviors/comment-reply-button.js
-
8tildes/static/js/behaviors/confirm-leave-page-unsaved.js
-
12tildes/static/js/behaviors/ctrl-enter-submit-form.js
-
16tildes/static/js/behaviors/external-links-new-tabs.js
-
8tildes/static/js/behaviors/fadeout-parent-on-success.js
-
8tildes/static/js/behaviors/hide-sidebar-if-open.js
-
6tildes/static/js/behaviors/hide-sidebar-no-preventdefault.js
-
16tildes/static/js/behaviors/markdown-edit-tab.js
-
18tildes/static/js/behaviors/markdown-preview-tab.js
-
13tildes/static/js/behaviors/prevent-double-submit.js
-
4tildes/static/js/behaviors/remove-on-click.js
-
4tildes/static/js/behaviors/remove-on-success.js
-
4tildes/static/js/behaviors/sidebar-toggle.js
-
10tildes/static/js/behaviors/tab.js
-
38tildes/static/js/behaviors/theme-selector.js
-
16tildes/static/js/behaviors/time-period-select.js
-
117tildes/static/js/scripts.js
@ -1,11 +1,14 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-auto-focus]', function() { |
|||
$input = $(this); |
|||
$.onmount("[data-js-auto-focus]", function() { |
|||
var $input = $(this); |
|||
|
|||
// just calling .focus() will place the cursor at the start of the field,
|
|||
// so un-setting and re-setting the value moves the cursor to the end
|
|||
var original_val = $input.val(); |
|||
$input.focus().val('').val(original_val); |
|||
$input |
|||
.focus() |
|||
.val("") |
|||
.val(original_val); |
|||
}); |
@ -1,11 +1,15 @@ |
|||
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-autocomplete-menu]', function() { |
|||
var $autocompleteContainer = $(this).parents('[data-js-autocomplete-container]').first(); |
|||
var $chips = $autocompleteContainer.find('[data-js-autocomplete-chips]').first(); |
|||
$.onmount("[data-js-autocomplete-menu]", function() { |
|||
var $autocompleteContainer = $(this) |
|||
.parents("[data-js-autocomplete-container]") |
|||
.first(); |
|||
var $chips = $autocompleteContainer.find("[data-js-autocomplete-chips]").first(); |
|||
|
|||
$(this).children('[data-js-autocomplete-menu-item]').each(function(index, $menuItem) { |
|||
$menuItem.setAttribute('tabindex', $chips.children().length + index); |
|||
}); |
|||
$(this) |
|||
.children("[data-js-autocomplete-menu-item]") |
|||
.each(function(index, $menuItem) { |
|||
$menuItem.setAttribute("tabindex", $chips.children().length + index); |
|||
}); |
|||
}); |
@ -1,8 +1,8 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-autoselect-input]', function() { |
|||
$(this).click(function(event) { |
|||
$.onmount("[data-js-autoselect-input]", function() { |
|||
$(this).click(function() { |
|||
$(this).select(); |
|||
}); |
|||
}); |
@ -1,8 +1,10 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-autosubmit-on-change]', function() { |
|||
$(this).change(function(event) { |
|||
$(this).closest('form').submit(); |
|||
$.onmount("[data-js-autosubmit-on-change]", function() { |
|||
$(this).change(function() { |
|||
$(this) |
|||
.closest("form") |
|||
.submit(); |
|||
}); |
|||
}); |
@ -1,28 +1,31 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-cancel-button]', function() { |
|||
$(this).click(function(event) { |
|||
var $parentForm = $(this).closest('form'); |
|||
$.onmount("[data-js-cancel-button]", function() { |
|||
$(this).click(function() { |
|||
var $parentForm = $(this).closest("form"); |
|||
|
|||
var shouldRemove = true; |
|||
|
|||
// confirm removal if the form specifies to
|
|||
var confirmPrompt = $parentForm.attr('data-js-confirm-cancel'); |
|||
var confirmPrompt = $parentForm.attr("data-js-confirm-cancel"); |
|||
if (confirmPrompt) { |
|||
// only prompt if any of the inputs aren't empty
|
|||
$nonEmptyFields = $parentForm.find('input,textarea') |
|||
.filter(function() { return $(this).val(); }); |
|||
var $nonEmptyFields = $parentForm.find("input,textarea").filter(function() { |
|||
return $(this).val(); |
|||
}); |
|||
|
|||
if ($nonEmptyFields.length > 0) { |
|||
var shouldRemove = window.confirm(confirmPrompt); |
|||
shouldRemove = window.confirm(confirmPrompt); |
|||
} else { |
|||
var shouldRemove = true; |
|||
shouldRemove = true; |
|||
} |
|||
} else { |
|||
var shouldRemove = true; |
|||
} |
|||
|
|||
if (shouldRemove) { |
|||
$(this).closest('form').remove(); |
|||
$(this) |
|||
.closest("form") |
|||
.remove(); |
|||
} |
|||
}); |
|||
}); |
@ -1,21 +1,24 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-comment-collapse-all-button]', function() { |
|||
$(this).click(function(event) { |
|||
$.onmount("[data-js-comment-collapse-all-button]", function() { |
|||
$(this).click(function() { |
|||
// first uncollapse any individually collapsed comments
|
|||
$('.is-comment-collapsed-individual').each( |
|||
function(idx, child) { |
|||
$(child).find( |
|||
'[data-js-comment-collapse-button]:first').trigger('click'); |
|||
}); |
|||
$(".is-comment-collapsed-individual").each(function(idx, child) { |
|||
$(child) |
|||
.find("[data-js-comment-collapse-button]:first") |
|||
.trigger("click"); |
|||
}); |
|||
|
|||
// then collapse all first-level replies
|
|||
$('.comment[data-comment-depth="1"]:not(.is-comment-collapsed)').each( |
|||
function(idx, child) { |
|||
$(child).find( |
|||
'[data-js-comment-collapse-button]:first').trigger('click'); |
|||
}); |
|||
$('.comment[data-comment-depth="1"]:not(.is-comment-collapsed)').each(function( |
|||
idx, |
|||
child |
|||
) { |
|||
$(child) |
|||
.find("[data-js-comment-collapse-button]:first") |
|||
.trigger("click"); |
|||
}); |
|||
|
|||
$(this).blur(); |
|||
}); |
|||
|
@ -1,13 +1,16 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-comment-expand-all-button]', function() { |
|||
$(this).click(function(event) { |
|||
$('.is-comment-collapsed, .is-comment-collapsed-individual').each( |
|||
function(idx, child) { |
|||
$(child).find( |
|||
'[data-js-comment-collapse-button]:first').trigger('click'); |
|||
}); |
|||
$.onmount("[data-js-comment-expand-all-button]", function() { |
|||
$(this).click(function() { |
|||
$(".is-comment-collapsed, .is-comment-collapsed-individual").each(function( |
|||
idx, |
|||
child |
|||
) { |
|||
$(child) |
|||
.find("[data-js-comment-collapse-button]:first") |
|||
.trigger("click"); |
|||
}); |
|||
|
|||
$(this).blur(); |
|||
}); |
|||
|
@ -1,14 +1,14 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-confirm-leave-page-unsaved]', function() { |
|||
$form = $(this); |
|||
$.onmount("[data-js-confirm-leave-page-unsaved]", function() { |
|||
var $form = $(this); |
|||
$form.areYouSure(); |
|||
|
|||
// Fixes a strange interaction between Intercooler and AreYouSure, where
|
|||
// submitting a form by using the keyboard to push the submit button would
|
|||
// trigger a confirmation prompt before leaving the page.
|
|||
$form.on('success.ic', function() { |
|||
$form.removeClass('dirty'); |
|||
$form.on("success.ic", function() { |
|||
$form.removeClass("dirty"); |
|||
}); |
|||
}); |
@ -1,11 +1,15 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-ctrl-enter-submit-form]', function() { |
|||
$.onmount("[data-js-ctrl-enter-submit-form]", function() { |
|||
$(this).keydown(function(event) { |
|||
if ((event.ctrlKey || event.metaKey) && |
|||
(event.keyCode == 13 || event.keyCode == 10)) { |
|||
$(this).closest('form').submit(); |
|||
if ( |
|||
(event.ctrlKey || event.metaKey) && |
|||
(event.keyCode == 13 || event.keyCode == 10) |
|||
) { |
|||
$(this) |
|||
.closest("form") |
|||
.submit(); |
|||
} |
|||
}); |
|||
}); |
@ -1,12 +1,14 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-external-links-new-tabs]', function() { |
|||
$.onmount("[data-js-external-links-new-tabs]", function() { |
|||
// Open external links in topic, comment, and message text in new tabs
|
|||
$(this).find('a').each(function() { |
|||
if (this.host !== window.location.host) { |
|||
$(this).attr('target', '_blank'); |
|||
$(this).attr('rel', 'noopener'); |
|||
} |
|||
}); |
|||
$(this) |
|||
.find("a") |
|||
.each(function() { |
|||
if (this.host !== window.location.host) { |
|||
$(this).attr("target", "_blank"); |
|||
$(this).attr("rel", "noopener"); |
|||
} |
|||
}); |
|||
}); |
@ -1,8 +1,10 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-fadeout-parent-on-success]', function() { |
|||
$(this).on('after.success.ic', function() { |
|||
$(this).parent().fadeOut('fast'); |
|||
$.onmount("[data-js-fadeout-parent-on-success]", function() { |
|||
$(this).on("after.success.ic", function() { |
|||
$(this) |
|||
.parent() |
|||
.fadeOut("fast"); |
|||
}); |
|||
}); |
@ -1,12 +1,12 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-hide-sidebar-if-open]', function() { |
|||
$(this).on('click', function(event) { |
|||
if ($('#sidebar').hasClass('is-sidebar-displayed')) { |
|||
$.onmount("[data-js-hide-sidebar-if-open]", function() { |
|||
$(this).on("click", function(event) { |
|||
if ($("#sidebar").hasClass("is-sidebar-displayed")) { |
|||
event.preventDefault(); |
|||
event.stopPropagation(); |
|||
$('#sidebar').removeClass('is-sidebar-displayed'); |
|||
$("#sidebar").removeClass("is-sidebar-displayed"); |
|||
} |
|||
}); |
|||
}); |
@ -1,8 +1,8 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-hide-sidebar-no-preventdefault]', function() { |
|||
$(this).on('click', function(event) { |
|||
$('#sidebar').removeClass('is-sidebar-displayed'); |
|||
$.onmount("[data-js-hide-sidebar-no-preventdefault]", function() { |
|||
$(this).on("click", function() { |
|||
$("#sidebar").removeClass("is-sidebar-displayed"); |
|||
}); |
|||
}); |
@ -1,13 +1,17 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-markdown-edit-tab]', function() { |
|||
$(this).click(function(event) { |
|||
var $editTextarea = $(this).closest('form').find('[name="markdown"]'); |
|||
var $previewDiv = $(this).closest('form').find('.form-markdown-preview'); |
|||
$.onmount("[data-js-markdown-edit-tab]", function() { |
|||
$(this).click(function() { |
|||
var $editTextarea = $(this) |
|||
.closest("form") |
|||
.find('[name="markdown"]'); |
|||
var $previewDiv = $(this) |
|||
.closest("form") |
|||
.find(".form-markdown-preview"); |
|||
|
|||
$editTextarea.removeClass('d-none'); |
|||
$previewDiv.addClass('d-none'); |
|||
$editTextarea.removeClass("d-none"); |
|||
$previewDiv.addClass("d-none"); |
|||
$previewDiv.empty(); |
|||
}); |
|||
}); |
@ -1,19 +1,20 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-prevent-double-submit]', function() { |
|||
$(this).on('beforeSend.ic', function(evt, elt, data, settings, xhr, requestId) { |
|||
$.onmount("[data-js-prevent-double-submit]", function() { |
|||
/* eslint-disable-next-line no-unused-vars */ |
|||
$(this).on("beforeSend.ic", function(evt, elt, data, settings, xhr, requestId) { |
|||
var $form = $(this); |
|||
|
|||
if ($form.attr('data-js-submitting') !== undefined) { |
|||
if ($form.attr("data-js-submitting") !== undefined) { |
|||
xhr.abort(); |
|||
return false; |
|||
} else { |
|||
$form.attr('data-js-submitting', true); |
|||
$form.attr("data-js-submitting", true); |
|||
} |
|||
}); |
|||
|
|||
$(this).on('complete.ic', function() { |
|||
$(this).removeAttr('data-js-submitting'); |
|||
$(this).on("complete.ic", function() { |
|||
$(this).removeAttr("data-js-submitting"); |
|||
}); |
|||
}); |
@ -1,8 +1,8 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-remove-on-click]', function() { |
|||
$(this).on('click', function() { |
|||
$.onmount("[data-js-remove-on-click]", function() { |
|||
$(this).on("click", function() { |
|||
$(this).remove(); |
|||
}); |
|||
}); |
@ -1,8 +1,8 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-remove-on-success]', function() { |
|||
$(this).on('after.success.ic', function() { |
|||
$.onmount("[data-js-remove-on-success]", function() { |
|||
$(this).on("after.success.ic", function() { |
|||
$(this).remove(); |
|||
}); |
|||
}); |
@ -1,11 +1,11 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-sidebar-toggle]', function() { |
|||
$.onmount("[data-js-sidebar-toggle]", function() { |
|||
$(this).click(function(event) { |
|||
event.preventDefault(); |
|||
event.stopPropagation(); |
|||
|
|||
$('#sidebar').toggleClass('is-sidebar-displayed'); |
|||
$("#sidebar").toggleClass("is-sidebar-displayed"); |
|||
}); |
|||
}); |
@ -1,9 +1,11 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-tab]', function() { |
|||
$(this).click(function(event) { |
|||
$(this).siblings().removeClass('active'); |
|||
$(this).addClass('active'); |
|||
$.onmount("[data-js-tab]", function() { |
|||
$(this).click(function() { |
|||
$(this) |
|||
.siblings() |
|||
.removeClass("active"); |
|||
$(this).addClass("active"); |
|||
}); |
|||
}); |
@ -1,40 +1,48 @@ |
|||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount('[data-js-theme-selector]', function() { |
|||
$.onmount("[data-js-theme-selector]", function() { |
|||
$(this).change(function(event) { |
|||
event.preventDefault(); |
|||
|
|||
// hide any IC change message
|
|||
$(this).parent().find('.form-status').hide(); |
|||
$(this) |
|||
.parent() |
|||
.find(".form-status") |
|||
.hide(); |
|||
|
|||
var new_theme = $(this).val(); |
|||
var selected_text = $(this).find('option:selected').text(); |
|||
var $setDefaultButton = $('#button-set-default-theme'); |
|||
var selected_text = $(this) |
|||
.find("option:selected") |
|||
.text(); |
|||
var $setDefaultButton = $("#button-set-default-theme"); |
|||
|
|||
// persist the new theme for the user in their cookie
|
|||
document.cookie = 'theme=' + new_theme + ';' + |
|||
'path=/;max-age=315360000;secure;domain=' + |
|||
document.cookie = |
|||
"theme=" + |
|||
new_theme + |
|||
";" + |
|||
"path=/;max-age=315360000;secure;domain=" + |
|||
document.location.hostname; |
|||
|
|||
// remove any theme classes currently on the body
|
|||
$body = $('body').first(); |
|||
var bodyClasses = $body[0].className.split(' '); |
|||
for (i = 0; i < bodyClasses.length; i++) { |
|||
cls = bodyClasses[i]; |
|||
if (cls.indexOf('theme-') === 0) { |
|||
var $body = $("body").first(); |
|||
var bodyClasses = $body[0].className.split(" "); |
|||
for (var i = 0; i < bodyClasses.length; i++) { |
|||
var cls = bodyClasses[i]; |
|||
if (cls.indexOf("theme-") === 0) { |
|||
$body.removeClass(cls); |
|||
} |
|||
} |
|||
|
|||
// add the class for the new theme to the body
|
|||
$body.addClass('theme-' + new_theme); |
|||
$body.addClass("theme-" + new_theme); |
|||
|
|||
// set visibility of 'Set as account default' button
|
|||
if (selected_text.indexOf('account default') === -1) { |
|||
$setDefaultButton.removeClass('d-none'); |
|||
if (selected_text.indexOf("account default") === -1) { |
|||
$setDefaultButton.removeClass("d-none"); |
|||
} else { |
|||
$setDefaultButton.addClass('d-none'); |
|||
$setDefaultButton.addClass("d-none"); |
|||
} |
|||
}); |
|||
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue