Skip to content

Commit

Permalink
Revert "Make AlpineJS CSP friendly (#6442)"
Browse files Browse the repository at this point in the history
This reverts commit 6a15bb0.
  • Loading branch information
escattone authored Jan 13, 2025
1 parent 05d1116 commit a036731
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 130 deletions.
4 changes: 1 addition & 3 deletions kitsune/sumo/static/sumo/js/alpine.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Alpine from "@alpinejs/csp";
import Alpine from 'alpinejs';
import trackEvent from "sumo/js/analytics";
// we need to import surveyForm here so it's available to Alpine components
import surveyForm from "sumo/js/survey_form";

window.Alpine = Alpine;
// Add trackEvent to the window object so it's available to Alpine components
Expand Down
105 changes: 0 additions & 105 deletions kitsune/sumo/static/sumo/js/survey_form.js

This file was deleted.

60 changes: 49 additions & 11 deletions kitsune/wiki/jinja2/wiki/includes/survey_form.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
<div class="survey-container" x-data="surveyForm" data-survey-type="{{ survey_type }}">
<div class="survey-container" x-data="{
selectedReason: '',
comment: '',
maxLength: 600,
hasError: false,
responseMessage: null,
validateForm() {
this.hasError = this.selectedReason === 'other' && !this.comment.trim();
return !this.hasError;
},
handleSubmit() {
if (this.validateForm()) {
trackEvent('article_survey_submitted', {
survey_type: '{{ survey_type }}',
reason: this.selectedReason
});
return true; // Allow HTMX to proceed with submission
}
return false;
},
closeSurvey() {
const surveyType = '{{ survey_type }}'.trim();
if (surveyType) {
trackEvent('article_survey_closed', { survey_type: surveyType });
}
document.querySelector('.document-vote').remove();
}
}" x-init="
const surveyType = '{{ survey_type }}'.trim();
if (surveyType) {
trackEvent('article_survey_opened', { survey_type: surveyType });
}
responseMessage = $refs.messageData.value;
if (responseMessage) {
setTimeout(() => {
closeSurvey();
}, 5000);
}
">
<input type="hidden" x-ref="messageData" value="{{ response_message if response_message else '' }}">
<template x-if="responseMessage">
<div class="survey-message">
<p x-text="responseMessage"></p>
</div>
</template>

<template x-if="formVisible">
<form hx-post="{{ action_url }}" hx-target=".survey-container" hx-trigger="submit">
<template x-if="!responseMessage">
<form hx-post="{{ action_url }}" hx-target=".survey-container" @submit.prevent="handleSubmit()" hx-trigger="submit">
{% csrf_token %}
<input type="hidden" name="vote_id" value="{{ vote_id }}" />
<input type="hidden" name="revision_id" value="{{ revision_id }}" />
Expand All @@ -18,22 +56,22 @@ <h3 class="sumo-card-heading text-center">
<ul id="{{ survey_type }}-contents">
{% for option in survey_options %}
<li class="field is-condensed radio">
<input type="radio"
name="{{ survey_type }}-reason"
value="{{ option.value }}"
id="{{ survey_type }}_{{ loop.index }}" />
<input type="radio" name="{{ survey_type }}-reason" value="{{ option.value }}"
id="{{ survey_type }}_{{ loop.index }}" x-model="selectedReason" />
<label for="{{ survey_type }}_{{ loop.index }}">{{ option.text }}</label>
</li>
{% endfor %}
</ul>
<p class="comments-label align-start">
{{ _('Comments') }}
<span x-show="isOtherSelected" class="required-text">{{ _('Required') }}</span>
<span x-show="selectedReason === 'other'" class="required-text">{{ _('Required') }}</span>
</p>
<textarea name="comment"
placeholder="{{ _('To protect your privacy, please do not include any personal information.') }}"></textarea>
placeholder="{{ _('To protect your privacy, please do not include any personal information.') }}"
x-model="comment" :required="selectedReason === 'other'" :disabled="selectedReason !== 'other'"
@input="if (comment.length > maxLength) comment = comment.slice(0, maxLength)"></textarea>
<p class="character-counter">
<span x-text="remainingChars"></span> {{ _('characters remaining.') }}
<span x-text="maxLength - comment.length"></span> {{ _('characters remaining.') }}
</p>
<p class="error-text" x-show="hasError" style="display: none; color: red;">{{ _('Please provide more details.') }}
</p>
Expand All @@ -42,7 +80,7 @@ <h3 class="sumo-card-heading text-center">
{{ _('Cancel') }}
</button>
<button class="sumo-button button-sm primary-button" type="submit"
x-bind:disabled="isSubmitDisabled">
:disabled="!selectedReason || (selectedReason === 'other' && !comment.trim())">
{{ _('Submit') }}
</button>
</div>
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
},
"license": "MPL-2.0",
"dependencies": {
"@alpinejs/csp": "^3.14.8",
"@babel/runtime": "^7.20.13",
"@urql/svelte": "^3.0.3",
"alpinejs": "^3.14.7",
"codemirror": "^5.65.11",
"d3": "^3.5.17",
"graphql": "^16.8.1",
Expand Down

0 comments on commit a036731

Please sign in to comment.