Skip to content

Commit

Permalink
Merge pull request #339 from sjrd/scam-alert-banner
Browse files Browse the repository at this point in the history
Add scam banner.
  • Loading branch information
bishabosha authored Mar 19, 2024
2 parents d8e91cd + e158cfa commit 0e23f43
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 2 deletions.
1 change: 1 addition & 0 deletions _data/messages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scam-banner: "**⚠️ Beware of Scams**: since Feb 2024, scammers are using [fake Scala websites to sell courses](https://www.scala-lang.org/blog/2024/03/01/fake-scala-courses.html), please check you are using an official source."
8 changes: 8 additions & 0 deletions _includes/alert-banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% comment %}use the variable 'message' to include markdown text to display in the alert.{% endcomment %}

<header id="site-header" class="header-home">
<div class="alert-warning" data-message_id="{{include.message_id}}">
<p>{{include.message|markdownify}}</p>
<span class="hide-with-preference"><i class="fa fa-close"></i></span>
</div>
</header>
4 changes: 2 additions & 2 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<body>

{% include alert-banner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}

<div id="wrap">
{% include navbar.html %}
<div id="main" class="container clear-top">
Expand All @@ -17,5 +19,3 @@
</body>

</html>


1 change: 1 addition & 0 deletions _layouts/frontpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% include head.html %}

<body class="home">
{% include alert-banner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}
<div id="wrap">
<div id="main">
<div class="splash">
Expand Down
51 changes: 51 additions & 0 deletions resources/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ $grey-color-light: lighten($grey-color, 40%);
$grey-color-medium: lighten($grey-color, 7%);
$grey-color-dark: darken($grey-color, 25%);

$warning-bg: #ffa500;
$warning-link: #185eb3;
$warning-text: #000;

// Width of the content area
$content-width: 800px;

Expand All @@ -53,6 +57,53 @@ $fa-font-path: "./../../bower_components/font-awesome/fonts";
// Import partials from `sass_dir` (defaults to `_sass`)
@import "base";

#site-header {
background: $gray-darker;
.alert-warning {
text-align: center;
padding: 8px 0;
/*transition: $base-transition;*/
position: relative;
font-size: 16px;
/*@include bp(medium) {
padding: 10px 40px;
}*/

background: $warning-bg;
color: $warning-text;

a {
color: $warning-link;
font-weight: bold;
text-decoration: underline;

&:active,
&:focus,
&:hover {
text-decoration: none;
}
}

p {
margin: 0;
}

span {
position: absolute;
right: 20px;
top: 3px;
z-index: 1;
cursor: pointer;
font-size: 22px;
opacity: 0.6;
/*transition: $base-transition;*/
&:hover {
opacity: 1;
}
}
}
}

.home #main {
overflow-x: hidden;
}
Expand Down
63 changes: 63 additions & 0 deletions resources/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
* Document initialization
**************************/

// Browser Storage Support (https://stackoverflow.com/a/41462752/2538602)
function storageAvailable(type) {
try {
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
}
catch (e) {
return false;
}
}

$(document).ready(function(){
/* SEARCH FUNCTIONALITY */
var search = $('.search input');
Expand Down Expand Up @@ -83,4 +97,53 @@ $(document).ready(function(){
}
$('#modal-description').modal('hide');
});

// --- Preferences stored in localStorage ---

const Storage = (namespace) => {
return ({
getPreference(key, defaultValue) {
const res = localStorage.getItem(`${namespace}.${key}`);
return res === null ? defaultValue : res;
},
setPreference(key, value, onChange) {
const old = this.getPreference(key, null);
if (old !== value) { // activate effect only if value changed.
localStorage.setItem(`${namespace}.${key}`, value);
onChange(old);
}
}
});
};

function setupAlertCancel(alert, storage) {
const messageId = alert.data('message_id');
let onHide = () => {};
if (messageId) {
const key = `alert.${messageId}`;
const isHidden = storage.getPreference(key, 'show') === 'hidden';
if (isHidden) {
alert.hide();
}
onHide = () => storage.setPreference(key, 'hidden', _ => {});
}


alert.find('.hide-with-preference').click(function() {
alert.hide(), onHide();
});
}

function setupAllAlertCancels(storage) {
var alertBanners = $(".alert-warning");
if (alertBanners.length) {
setupAlertCancel(alertBanners, storage);
}
}

if (storageAvailable('localStorage')) {
const PreferenceStorage = Storage('ch.epfl.scala.preferences');
setupAllAlertCancels(PreferenceStorage);
}

});

0 comments on commit 0e23f43

Please sign in to comment.