forked from memberful/memberful-wp
-
Notifications
You must be signed in to change notification settings - Fork 0
MR-31: Lite version of paywall #9
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
Open
av3nger
wants to merge
20
commits into
main
Choose a base branch
from
feature/MR-31-paywall
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ad56416
Create and register paywall config
av3nger 28c461e
Render function + three layout templates
av3nger df0ee89
Prepare render for paywal config
av3nger d335a33
Add builder UI
av3nger dc8d456
Fix phpcs warnings
av3nger a403643
Boilerplate paywal preview
av3nger 28a9230
Drop custom CSS field from the builder
av3nger e8a69d8
Adjust UI/UX
av3nger 03db76c
Save work in progress
av3nger e978111
Adjust styles
av3nger 03978ab
Fix flagged issues
av3nger b8e2df8
Fix issues
av3nger 70af3b5
Improve post edit screen
av3nger 3b40da0
Fix code audit issues
av3nger e2a8617
Fix flagged issues
av3nger e50f529
Fix FOC issue
av3nger cfef9f6
Improve paywall logic
av3nger 4c5ec31
Improve paywall banner theme compatibility
av3nger d1740cf
Fix another round of flagged issues
av3nger 0e59044
Fix save button
av3nger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
wordpress/wp-content/plugins/memberful-wp/js/src/paywall-banner.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * Memberful paywall banner - measure-based full-bleed. | ||
| * | ||
| * Pure CSS can't make a banner span the visible viewport when the post column | ||
| * is offset by a sidebar (classic themes with non-centered content). This | ||
| * script measures the banner's parent against documentElement.clientWidth and | ||
| * applies inline margin/width so the banner reaches both viewport edges | ||
| * exactly. Runs synchronously from a footer enqueue so first paint is correct | ||
| * (no flash of off-center content). | ||
| */ | ||
| ( function () { | ||
| 'use strict'; | ||
|
|
||
| function measure( banner ) { | ||
| var parent = banner.parentElement; | ||
| if ( ! parent ) { | ||
| return; | ||
| } | ||
|
|
||
| // Reset any previous measurement so parent rect reflects natural flow. | ||
| banner.style.marginInlineStart = ''; | ||
| banner.style.marginInlineEnd = ''; | ||
| banner.style.width = ''; | ||
|
|
||
| var viewportWidth = document.documentElement.clientWidth; | ||
| var parentRect = parent.getBoundingClientRect(); | ||
|
|
||
| var startMargin = -parentRect.left; | ||
| var endMargin = parentRect.right - viewportWidth; | ||
|
|
||
| banner.style.marginInlineStart = startMargin + 'px'; | ||
| banner.style.marginInlineEnd = endMargin + 'px'; | ||
| banner.style.width = viewportWidth + 'px'; | ||
| } | ||
|
|
||
| function init() { | ||
| var banners = document.querySelectorAll( '.memberful-paywall--banner' ); | ||
| if ( ! banners.length ) { | ||
| return; | ||
| } | ||
|
|
||
| banners.forEach( function ( banner ) { | ||
| measure( banner ); | ||
|
|
||
| var pending = null; | ||
| var schedule = function () { | ||
| if ( pending !== null ) { | ||
| return; | ||
| } | ||
| pending = window.requestAnimationFrame( function () { | ||
| pending = null; | ||
| measure( banner ); | ||
| } ); | ||
| }; | ||
|
|
||
| window.addEventListener( 'resize', schedule, { passive: true } ); | ||
|
|
||
| if ( typeof ResizeObserver !== 'undefined' && banner.parentElement ) { | ||
| new ResizeObserver( schedule ).observe( banner.parentElement ); | ||
| } | ||
| } ); | ||
| } | ||
|
|
||
| if ( document.readyState === 'loading' ) { | ||
| document.addEventListener( 'DOMContentLoaded', init ); | ||
| } else { | ||
| init(); | ||
| } | ||
| } )(); |
114 changes: 114 additions & 0 deletions
114
wordpress/wp-content/plugins/memberful-wp/js/src/paywall-builder.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| jQuery(function ($) { | ||
| const $form = $('.memberful-paywall-builder__panel[data-panel="builder"]'); | ||
| const $modeInputs = $('input[name="memberful_paywall[mode]"]'); | ||
| const $panels = $('.memberful-paywall-builder__panel'); | ||
| const $preview = $('#memberful-paywall-preview'); | ||
| const $colorInput = $('.memberful-paywall-builder__color'); | ||
|
|
||
| const preview = window.memberfulPaywallPreview || {}; | ||
| const DEBOUNCE_MS = 250; | ||
|
|
||
| let debounceTimer = null; | ||
| let requestSeq = 0; | ||
|
|
||
| $colorInput.wpColorPicker({ | ||
| change: function () { | ||
| setTimeout(scheduleRefresh, 0); | ||
| }, | ||
| clear: function () { | ||
| setTimeout(scheduleRefresh, 0); | ||
| }, | ||
| }); | ||
|
|
||
| function applyMode(mode) { | ||
| $panels.each(function () { | ||
| this.style.display = this.dataset.panel === mode ? '' : 'none'; | ||
| }); | ||
| } | ||
|
|
||
| $modeInputs.on('change', function () { | ||
| if (!this.checked) { | ||
| return; | ||
| } | ||
|
|
||
| applyMode(this.value); | ||
|
|
||
| if (this.value === 'builder') { | ||
| refreshPreview(); | ||
| } | ||
| }); | ||
|
|
||
| applyMode($modeInputs.filter(':checked').val() || 'builder'); | ||
|
|
||
| function collectConfig() { | ||
| return { | ||
| mode: $('input[name="memberful_paywall[mode]"]:checked').val() || 'builder', | ||
| layout: $('input[name="memberful_paywall[layout]"]:checked').val() || 'card', | ||
| heading: $('#memberful-paywall-heading').val() || '', | ||
| heading_tag: $('#memberful-paywall-heading-tag').val() || 'h2', | ||
| subheading: $('#memberful-paywall-subheading').val() || '', | ||
| features: $('#memberful-paywall-features').val() || '', | ||
| button_label: $('#memberful-paywall-button-label').val() || '', | ||
| subscribe_url: $('#memberful-paywall-subscribe-url').val() || '', | ||
| sign_in_url: $('#memberful-paywall-signin-url').val() || '', | ||
| brand_color: $colorInput.val() || '', | ||
| button_shape: $('#memberful-paywall-button-shape').val() || 'rounded', | ||
| }; | ||
| } | ||
|
|
||
| function refreshPreview() { | ||
| if (!preview.ajaxUrl || !preview.action || !preview.nonce || !$preview.length) { | ||
| return; | ||
| } | ||
|
|
||
| clearTimeout(debounceTimer); | ||
|
|
||
| const seq = ++requestSeq; | ||
| const body = new URLSearchParams(); | ||
| body.set('action', preview.action); | ||
| body.set('nonce', preview.nonce); | ||
|
|
||
| const config = collectConfig(); | ||
| Object.keys(config).forEach(function (key) { | ||
| body.append('config[' + key + ']', config[key]); | ||
| }); | ||
|
|
||
| fetch(preview.ajaxUrl, { | ||
| method: 'POST', | ||
| credentials: 'same-origin', | ||
| headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, | ||
| body: body.toString(), | ||
| }) | ||
| .then(function (res) { | ||
| if (!res.ok) { | ||
| throw new Error('Request failed: ' + res.status); | ||
| } | ||
|
|
||
| return res.json(); | ||
| }) | ||
| .then(function (json) { | ||
| if (seq !== requestSeq) { | ||
| return; | ||
| } | ||
|
|
||
| if (json && json.success && json.data && json.data.html) { | ||
| $preview.attr('srcdoc', json.data.html); | ||
| } | ||
| }) | ||
| .catch(function (err) { | ||
| console.error('Paywall preview failed', err); | ||
| }); | ||
| } | ||
|
|
||
| function scheduleRefresh() { | ||
| clearTimeout(debounceTimer); | ||
| debounceTimer = setTimeout(refreshPreview, DEBOUNCE_MS); | ||
| } | ||
|
|
||
| $form.on('input', 'input[type="text"], input[type="url"], textarea', scheduleRefresh); | ||
| $form.on('change', 'input[type="radio"], select', refreshPreview); | ||
|
|
||
| if (($modeInputs.filter(':checked').val() || 'builder') === 'builder') { | ||
| refreshPreview(); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.