Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Syndication Links support #331

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Classic editor support
Firestorm980 committed Jun 28, 2024
commit d1a332a596f00721506f811a013e69d0ba470592
62 changes: 62 additions & 0 deletions assets/js/admin-autoshare-for-twitter-classic-editor.js
Original file line number Diff line number Diff line change
@@ -243,6 +243,64 @@
}
}

function addSyndicatedLinks( data ) {
if ( ! data ) {
return;
}

// Get the Syndication URL inputs.
const syndicationUrlInputs = Array.from(
document.querySelectorAll( 'input[name="syndication_urls[]"]' )
);

// Bail if there are no Syndication URL inputs.
if ( ! syndicationUrlInputs.length ) {
return;
}

// Get the URLs from the status messages.
// We'll use these to compare and populate the Syndication URL inputs.
const statusMessagesUrls = Array.from(document.querySelectorAll('.autoshare-for-twitter-status-logs-wrapper a')).map( ( link ) => {
return link.getAttribute('href');
} );

// Get the existing URLs from the Syndication URL inputs.
const syndicationUrlInputsUrls = syndicationUrlInputs.map(
( input ) => {
return input.value;
}
);

// Get the Syndication URL list.
const syndicationUrlList = document.querySelector(
'.syndication_url_list ul'
);

statusMessagesUrls.forEach( ( url ) => {
// If the URL is already in the Syndication URL inputs, bail.
if ( syndicationUrlInputsUrls.includes( url ) ) {
return;
}

// Create the Syndication URL input list item.
const syndicationUrlInputListItem = document.createElement( 'li' );

// Create the Syndication URL input.
const syndicationUrlInput = document.createElement( 'input' );
syndicationUrlInput.classList.add( 'widefat' );
syndicationUrlInput.type = 'text';
syndicationUrlInput.name = 'syndication_urls[]';
syndicationUrlInput.value = url;

// Append the Syndication URL input to the Syndication URL list.
syndicationUrlInputListItem.appendChild( syndicationUrlInput );
syndicationUrlList.appendChild( syndicationUrlInputListItem );

// Add the URL to the Syndication URL inputs URLs so we don't repeat ourselves.
syndicationUrlInputsUrls.push( url );
} );
}

// Tweet Now functionality.
$('#tweet_now').on('click', function () {
$('#autoshare-for-twitter-error-message').html('');
@@ -272,9 +330,13 @@
(false === response.success &&
false === response.data.is_retweeted))
) {
console.log({ data: response.data })
$('.autoshare-for-twitter-status-logs-wrapper').html(
response.data.message
);

addSyndicatedLinks( response.data );

if (response.data.is_retweeted) {
$tweetText.val(''); // Reset the tweet text.
}