DEV: remove `showHtml` jQuery plugin (#15316)

This commit is contained in:
Penar Musaraj 2021-12-15 13:13:06 -05:00 committed by GitHub
parent 102fa71ef3
commit 9fd92f329e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 70 deletions

View File

@ -163,7 +163,7 @@ export default class PostCooked {
} }
this.expanding = true; this.expanding = true;
const blockQuote = $aside[0].querySelector("blockquote");
$aside.data("expanded", !$aside.data("expanded")); $aside.data("expanded", !$aside.data("expanded"));
const finished = () => (this.expanding = false); const finished = () => (this.expanding = false);
@ -171,14 +171,13 @@ export default class PostCooked {
if ($aside.data("expanded")) { if ($aside.data("expanded")) {
this._updateQuoteElements($aside, "chevron-up"); this._updateQuoteElements($aside, "chevron-up");
// Show expanded quote // Show expanded quote
const $blockQuote = $("> blockquote", $aside); $aside.data("original-contents", blockQuote.innerHTML);
$aside.data("original-contents", $blockQuote.html());
const originalText = const originalText =
$blockQuote.text().trim() || blockQuote.textContent.trim() ||
$("> blockquote", this.attrs.cooked).text().trim(); this.attrs.cooked.querySelector("blockquote").textContent.trim();
$blockQuote.html(spinnerHTML); blockQuote.innerHTML = spinnerHTML;
let topicId = this.attrs.topicId; let topicId = this.attrs.topicId;
if ($aside.data("topic")) { if ($aside.data("topic")) {
@ -205,26 +204,24 @@ export default class PostCooked {
highlightHTML(div, originalText, { highlightHTML(div, originalText, {
matchCase: true, matchCase: true,
}); });
$blockQuote.showHtml(div, "fast", finished);
blockQuote.innerHTML = "";
blockQuote.appendChild(div);
finished();
}) })
.catch((e) => { .catch((e) => {
if ([403, 404].includes(e.jqXHR.status)) { if ([403, 404].includes(e.jqXHR.status)) {
const icon = e.jqXHR.status === 403 ? "lock" : "far-trash-alt"; const icon = e.jqXHR.status === 403 ? "lock" : "far-trash-alt";
$blockQuote.showHtml( blockQuote.innerHTML = `<div class='expanded-quote icon-only'>${iconHTML(
$(`<div class='expanded-quote'>${iconHTML(icon)}</div>`), icon
"fast", )}</div>`;
finished
);
} }
}); });
} else { } else {
// Hide expanded quote // Hide expanded quote
this._updateQuoteElements($aside, "chevron-down"); this._updateQuoteElements($aside, "chevron-down");
$("blockquote", $aside).showHtml( blockQuote.innerHTML = $aside.data("original-contents");
$aside.data("original-contents"), finished();
"fast",
finished
);
} }
return false; return false;
} }

View File

@ -46,7 +46,6 @@ module.exports = function (defaults) {
app.import(vendorJs + "jquery.fileupload-process.js"); app.import(vendorJs + "jquery.fileupload-process.js");
app.import(vendorJs + "jquery.autoellipsis-1.0.10.js"); app.import(vendorJs + "jquery.autoellipsis-1.0.10.js");
app.import(vendorJs + "caret_position.js"); app.import(vendorJs + "caret_position.js");
app.import(vendorJs + "show-html.js");
app.import("node_modules/ember-source/dist/ember-template-compiler.js", { app.import("node_modules/ember-source/dist/ember-template-compiler.js", {
type: "test", type: "test",
}); });

View File

@ -27,7 +27,6 @@
//= require lodash.js //= require lodash.js
//= require itsatrap.js //= require itsatrap.js
//= require rsvp.js //= require rsvp.js
//= require show-html.js
//= require uppy.js //= require uppy.js
//= require buffered-proxy //= require buffered-proxy
//= require jquery.autoellipsis-1.0.10 //= require jquery.autoellipsis-1.0.10

View File

@ -20,7 +20,6 @@
//= require lodash.js //= require lodash.js
//= require itsatrap.js //= require itsatrap.js
//= require rsvp.js //= require rsvp.js
//= require show-html.js
//= require uppy.js //= require uppy.js
//= require buffered-proxy //= require buffered-proxy
//= require jquery.autoellipsis-1.0.10 //= require jquery.autoellipsis-1.0.10

View File

@ -290,6 +290,16 @@ $quote-share-maxwidth: 150px;
animation: heartBump 0.4s; animation: heartBump 0.4s;
} }
@keyframes slideout {
from {
max-height: 60px;
}
to {
max-height: 9999px;
}
}
// we use aside to hold expandable quotes (versus, say, static blockquotes) // we use aside to hold expandable quotes (versus, say, static blockquotes)
aside.quote { aside.quote {
margin-top: 1em; margin-top: 1em;
@ -317,6 +327,17 @@ aside.quote {
// blockquote is docked within aside for content // blockquote is docked within aside for content
blockquote { blockquote {
margin-top: 0; margin-top: 0;
.expanded-quote {
overflow: hidden;
animation: slideout 1s ease-in-out;
&.icon-only {
text-align: center;
font-size: var(--font-up-4);
padding-top: 0.5em;
padding-bottom: 0.5em;
color: var(--primary-medium);
}
}
} }
} }

View File

@ -23,7 +23,9 @@ function cleanUpPolls() {
} }
function initializePolls(api) { function initializePolls(api) {
const register = getRegister(api); const register = getRegister(api),
pollGroupableUserFields = api.container.lookup("site-settings:main")
.poll_groupable_user_fields;
cleanUpPolls(); cleanUpPolls();
api.modifyClass("controller:topic", { api.modifyClass("controller:topic", {
@ -108,10 +110,7 @@ function initializePolls(api) {
vote, vote,
hasSavedVote: vote.length > 0, hasSavedVote: vote.length > 0,
titleHTML: titleElement?.outerHTML, titleHTML: titleElement?.outerHTML,
groupableUserFields: ( groupableUserFields: (pollGroupableUserFields || "")
api.container.lookup("site-settings:main")
.poll_groupable_user_fields || ""
)
.split("|") .split("|")
.filter(Boolean), .filter(Boolean),
}; };

View File

@ -1,45 +0,0 @@
// Animates the dimensional changes resulting from altering element contents
// Usage examples:
// $("#myElement").showHtml("new HTML contents");
// $("div").showHtml("new HTML contents", 400);
// $(".className").showHtml("new HTML contents", 400,
// function() {/* on completion */});
(function($)
{
$.fn.showHtml = function(html, speed, callback)
{
return this.each(function()
{
// The element to be modified
var el = $(this);
// Preserve the original values of width and height - they'll need
// to be modified during the animation, but can be restored once
// the animation has completed.
var finish = {width: this.style.width, height: this.style.height};
// The original width and height represented as pixel values.
// These will only be the same as `finish` if this element had its
// dimensions specified explicitly and in pixels. Of course, if that
// was done then this entire routine is pointless, as the dimensions
// won't change when the content is changed.
var cur = {width: el.width()+'px', height: el.height()+'px'};
// Modify the element's contents. Element will resize.
el.html(html);
// Capture the final dimensions of the element
// (with initial style settings still in effect)
var next = {width: el.width()+'px', height: el.height()+'px'};
el .css(cur) // restore initial dimensions
.animate(next, speed, function() // animate to final dimensions
{
el.css(finish); // restore initial style settings
if ( $.isFunction(callback) ) callback();
});
});
};
})(jQuery);