Skip to content

Commit

Permalink
#47: Run Prittier on all Javascripts to clean up code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfranco committed Dec 19, 2024
1 parent 36cc918 commit a5766fb
Show file tree
Hide file tree
Showing 8 changed files with 1,040 additions and 763 deletions.
4 changes: 2 additions & 2 deletions assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* This file will be included onto the page via the importmap() Twig function,
* which should already be in your base.html.twig.
*/
import './styles/app.css';
import 'bookmarks'
import "./styles/app.css";
import "bookmarks";
55 changes: 31 additions & 24 deletions assets/bookmarks.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
import './styles/bookmarks.css';
import $ from 'jquery';
import "./styles/bookmarks.css";
import $ from "jquery";

$(function() { // on DOM ready
$(function () {
// on DOM ready

$('.save_course a').click(function () {
var clickedAnchor = $(this);
var courseId = $(this).siblings('input[name=course_id]').val();

$.ajax({
url: clickedAnchor.attr('href'),
success: function () {
if (clickedAnchor.hasClass('save')) {
bookmarks_show_forget(courseId);
} else {
bookmarks_show_save(courseId);
}
}

});
return false;
});
$(".save_course a").click(function () {
var clickedAnchor = $(this);
var courseId = $(this).siblings("input[name=course_id]").val();

$.ajax({
url: clickedAnchor.attr("href"),
success: function () {
if (clickedAnchor.hasClass("save")) {
bookmarks_show_forget(courseId);
} else {
bookmarks_show_save(courseId);
}
},
});
return false;
});
});

function bookmarks_show_save(courseId) {
$('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.save').show();
$('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.forget').hide();
$('.save_course input[name=course_id][value="' + courseId + '"]')
.siblings("a.save")
.show();
$('.save_course input[name=course_id][value="' + courseId + '"]')
.siblings("a.forget")
.hide();
}
function bookmarks_show_forget(courseId) {
$('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.save').hide();
$('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.forget').show();
$('.save_course input[name=course_id][value="' + courseId + '"]')
.siblings("a.save")
.hide();
$('.save_course input[name=course_id][value="' + courseId + '"]')
.siblings("a.forget")
.show();
}
96 changes: 50 additions & 46 deletions assets/email_controls.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,102 @@
import $ from 'jquery';

$('document').ready(function() {
import $ from "jquery";

$("document").ready(function () {
/*********************************************************
* Email controls
*********************************************************/
$(".email_dialog").each(function() {
$(".email_dialog").each(function () {
var button = $(this).siblings(".email_button");
var emailDialog = $(this).dialog({
autoOpen: false,
width: 700,
modal: true
});
autoOpen: false,
width: 700,
modal: true,
});

button.data("emailDialog", emailDialog);
});
$(".email_button").click(function(){
var emailDialog = $(this).data('emailDialog');
$(".email_button").click(function () {
var emailDialog = $(this).data("emailDialog");
emailDialog.dialog("open");

// Store the original subject.
var field = emailDialog.find('input[name=subject]');
if (!field.data('orig')) {
field.data('orig', field.val());
var field = emailDialog.find("input[name=subject]");
if (!field.data("orig")) {
field.data("orig", field.val());
}

// Store the original message.
var field = emailDialog.find('textarea[name=message]');
if (!field.data('orig')) {
field.data('orig', field.val());
var field = emailDialog.find("textarea[name=message]");
if (!field.data("orig")) {
field.data("orig", field.val());
}

return false;
});

$(".email_dialog form").submit(function() {
$(".email_dialog form").submit(function () {
var to = $(this).find("input[name=to]").val();
to = to.replace(/^\s*/, '').replace(/\s*$/, '');
to = to.replace(/^\s*/, "").replace(/\s*$/, "");

if (!to.length) {
if (!confirm("You didn't specify a recipient.\n\nClick 'Cancel' to add one or 'Ok' to send only to yourself.")) {
if (
!confirm(
"You didn't specify a recipient.\n\nClick 'Cancel' to add one or 'Ok' to send only to yourself."
)
) {
return false;
}
}
if (to.length && !validateEmail(to)) {
alert("It doesn't look like you specified a valid email address in the 'To:' field.");
alert(
"It doesn't look like you specified a valid email address in the 'To:' field."
);
return false;
}

// Submit the form asynchronously, clear the to & body, then close.
var form = $(this);
var emailDialog = form.parents('.email_dialog');
var emailDialog = form.parents(".email_dialog");

$.ajax({
type: "POST",
url: form.attr('action'),
url: form.attr("action"),
data: form.serialize(),
success: function (data, textStatus, req) {
if (data.length) {
alert(data);
}

// Clear the form.
form.find('input[name=to]').val('');
form.find("input[name=to]").val("");

var field = form.find('input[name=subject]');
field.val(field.data('orig'));
var field = form.find("input[name=subject]");
field.val(field.data("orig"));

var field = form.find('textarea[name=message]');
field.val(field.data('orig'));
var field = form.find("textarea[name=message]");
field.val(field.data("orig"));
},
error: function(req, textStatus, errorThrown) {
emailDialog.dialog('open');
error: function (req, textStatus, errorThrown) {
emailDialog.dialog("open");
alert("Couldn't send email.\n\n" + req.responseText);
}
},
});

// Close the dialog.
emailDialog.dialog('close');
emailDialog.dialog("close");
return false;
});

});

/**
* Validate the email field
*
* @param string emailString
* @return boolean
*/
function validateEmail (emailString) {
* Validate the email field
*
* @param string emailString
* @return boolean
*/
function validateEmail(emailString) {
var addresses = emailString.split(",");
for (var i = 0; i < addresses.length; i++) {
var address = addresses[i].replace(/^\s*/, '').replace(/\s*$/, '');
var address = addresses[i].replace(/^\s*/, "").replace(/\s*$/, "");
if (!validateEmailAddress(address)) {
return false;
}
Expand All @@ -101,13 +105,13 @@ function validateEmail (emailString) {
}

/**
* Validate an email address.
* By "sectrean" at http://stackoverflow.com/questions/46155/validate-email-address-in-javascript/46181#46181
*
* @param string email
* @return boolean
*/
function validateEmailAddress (email) {
* Validate an email address.
* By "sectrean" at http://stackoverflow.com/questions/46155/validate-email-address-in-javascript/46181#46181
*
* @param string email
* @return boolean
*/
function validateEmailAddress(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return email.match(re);
}
Loading

0 comments on commit a5766fb

Please sign in to comment.