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

Upgrade JavaScript code Using ES6 Concepts #167

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
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
97 changes: 55 additions & 42 deletions docs/_layouts/listing.html
Keerthivardhan1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

<script>

/*

This part of code deals with Google Analytics. It initializes Google Analytics tracking on a website.

*/

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
Expand All @@ -16,42 +22,51 @@
ga('create', 'UA-2010376-29', 'auto');
ga('send', 'pageview');

/*
getUrlVars :-

function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
This function extracts the parameters from the URL of the current web page and returns them as an object with key-value pairs.

*/

const getUrlVars = () =>{
const vars= {};
const hashes= window.location.href.slice(window.location.href.indexOf('?')+ 1).split('&');
for(const hash of hashes){
const [key , value]= hash.split('=');
vars[key]=value;
}
return vars;
}

function UpdateQueryString(key, value, url) {
if (!url) url = window.location.href;
var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
/*
UpdateQueryString :-

The purpose of this function is to update the query string of a given URL.
The function then returns the updated URL. If no changes are made to the URL, the original URL is returned.

*/

const UpdateQueryString = (key, value, url = window.location.href) => {
const re = new RegExp(`([?|&])${key}=.*?(&|#|$)(.*)`, 'gi');
if (re.test(url)) {
if (typeof value !== 'undefined' && value !== null)
return url.replace(re, '$1' + key + "=" + value + '$2$3');
return url.replace(re, `$1${key}=${value}$2$3`);
else {
var hash = url.split('#');
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
const [baseUrl , hash] = url.split('#');
url = baseUrl.replace(re, '$1$3').replace(/(&|\?)$/, '');
if ( hash !== 'undefined' && hash !== null)
url += `#${hash}`;
return url;
}
}
else {
if (typeof value !== 'undefined' && value !== null) {
var separator = url.indexOf('?') !== -1 ? '&' : '?',
hash = url.split('#');
url = hash[0] + separator + key + '=' + value;
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
const separator = url.indexOf('?') !== -1 ? '&' : '?';
const [baseUrl , hash] = url.split('#');
url = `${baseUrl}${separator}${key}=${value}` ;
if ( hash !== 'undefined' && hash !== null)
url += `#${hash}`;
return url;
}
else
Expand All @@ -61,34 +76,32 @@

document.write("<style>.thumbnailbox { display: none; }</style>");

function RemoveQueryString(param1) {
var quer = param1
const RemoveQueryString = (param1) => {
const quer = param1
location.href=location.href.replace(/&?quer=([^&]$|[^&]*)/i, "");
}
}

var topic = getUrlVars()["topic"];
var language = getUrlVars()["language"];
var medium = getUrlVars()["medium"];
const topic = getUrlVars()["topic"];
const language = getUrlVars()["language"];
const medium = getUrlVars()["medium"];

if (topic === undefined && medium === undefined && language === undefined) {
document.write("<style>.thumbnailbox { display: block; }</style>");
document.write("<style>.thumbnailbox { display: block; }</style>") ;
}
else {
document.write("<style>");
if (topic != undefined) {document.write("."+topic)};
if (medium != undefined) {document.write("."+medium)};
if (language != undefined) {document.write("."+language)};
document.write(" { display: block; }</style>");
};

document.write("<style>");
if (topic != undefined) {document.write(" .resourcenavtopicknown");}
else {document.write(" .resourcenavtopicunknown");};
if (medium != undefined) {document.write(", .resourcenavmediumknown");}
else {document.write(", .resourcenavmediumunknown");};
if (language != undefined) {document.write(", .resourcenavlanguageknown");}
else {document.write(", .resourcenavlanguageunknown");};
document.write(" { display: block; }</style>");
document.write("{ display: block; }</style>");
}

document.write(`<style> ${topic ? " .resourcenavtopicknown" : " .resourcenavtopicunknown"}
${medium ? ", .resourcenavmediumknown" : ", .resourcenavmediumunknown"}
${language ? ", .resourcenavlanguageknown" : ", .resourcenavlanguageunknown"}
{ display: block; }
</style>`);

</script>

{% endif %}
Expand Down
146 changes: 75 additions & 71 deletions docs/_layouts/resource.html
Original file line number Diff line number Diff line change
@@ -1,107 +1,111 @@
<html>
<head>
<title>{{ page.title }} | Creative Commons</title>
<html xmlns:dct="http://www.w3.org/1999/xhtml">
<head>
<title>{{ page.title }} | Creative Commons</title>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
<script>
/*

This part of code deals with Google Analytics. It initializes Google Analytics tracking on a website.

*/

ga('create', 'UA-2010376-29', 'auto');
ga('send', 'pageview');
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

</script>
ga('create', 'UA-2010376-29', 'auto');
ga('send', 'pageview');

<link rel="stylesheet" type="text/css" href="/style.css" />
{% if page.downloadurl %}
</script>

<link rel="stylesheet" type="text/css" href="/style.css" />
{% if page.downloadurl %}
{% if page.repourl %}
<style>#downloadbuttonholder { width: 440px; }</style>
<style>#downloadbuttonholder { width: 440px; }</style>
{% else %}
<style>#downloadbuttonholder { width: 220px; }</style>
<style>#downloadbuttonholder { width: 220px; }</style>
{% endif %}
{% elsif page.repourl %}
{% elsif page.repourl %}
<style>#downloadbuttonholder { width: 220px; }</style>
{% endif %}
{% endif %}

{% if page.repourl contains 'layervault.com' %}
{% if page.repourl contains 'layervault.com' %}
<style>.downloadbutton.repository {background-image: url("/images/layervault.png")}</style>
{% endif %}
{% if page.repourl contains 'github.com' %}
{% endif %}

{% if page.repourl contains 'github.com' %}
<style>.downloadbutton.repository {background-image: url("/images/github.png")}</style>
{% endif %}
{% endif %}

</head>
<body>
</head>
<body>

{% include header.html %}
{% include header.html %}

<h1><a href="/">Creative Commons Resource Archive</a></h1>
<h1><a href="/">Creative Commons Resource Archive</a></h1>

<h2 style="text-align: center; ">{{ page.title }}</a></h3>
<h2 style="text-align: center; ">{{ page.title }}</a></h3>

{% if page.embed %}
<div align="center">{{ page.embed }}</div>
{% else %}
{% if page.downloadurl %}
<a href="{{ page.downloadurl }}" target="_blank">
{% endif %}
{% if page.embed %}
<div align="center">{{ page.embed }}</div>
{% else %}
{% if page.downloadurl %}
<a href="{{ page.downloadurl }}" target="_blank"></a>
{% endif %}

{% if page.image-full %}
{% if page.image-full %}
<div id="preview" style="background-image: url({{page.image-full}})"></div>
{% else %}
{% else %}
<div id="preview"></div>
{% endif %}
{% endif %}

{% if page.downloadurl %}
{% if page.downloadurl %}
</a>
{% endif %}
{% endif %}
{% if page.downloadurl or page.repourl %}
<div id="downloadbuttonholder">
{% endif %}

{% if page.downloadurl %}
<a href="{{ page.downloadurl }}" target="_blank">
<div class="downloadbutton">
{% if page.medium == "website" or page.medium == "course" %}
<p>Visit</p>
{% else %}
<p>Download</p>
{% endif %}
{% endif %}
{% if page.downloadurl or page.repourl %}
<div id="downloadbuttonholder">
{% endif %}

{% if page.downloadurl %}
<a href="{{ page.downloadurl }}" target="_blank">
<div class="downloadbutton">
{% if page.medium == "website" or page.medium == "course" %}
<p>Visit</p>
{% else %}
<p>Download</p>
{% endif %}
</div>
</a>
{% endif %}


{% if page.downloadurl or page.repourl %}
</div>
</a>
{% endif %}
{% endif %}

<div style="clear: both;"></div>

{% if page.downloadurl or page.repourl %}
<div id="longdescription">
{{content}}
</div>
{% endif %}

<div style="clear: both;"></div>

<div id="longdescription">
{{content}}
</div>


{% if page.license %}


{% if page.license %}
{% if page.license == 'CC0' %}
<p align="center"><a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"><img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" /></a>
<br />
To the extent possible under law, <span property="dct:publisher">{{ page.author }}</span> has waived all copyright and related or neighboring rights to <a href="{{ page.downloadurl}}"dct:title">{{ page.title }}</a>.</p>

<p align="center"><a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"><img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" /></a><br />
To the extent possible under law, <span property="dct:publisher">{{ page.author }}</span> has waived all copyright and related or neighboring rights to <a href="{{ page.downloadurl}}" dct:title="{{ page.title }}">{{ page.title }}</a>.
</p>
{% else %}

<p align="center"><a rel="license" href="http://creativecommons.org/licenses/{{ page.license | remove: 'CC ' | downcase | replace: ' ', '/' }}/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/{{ page.license | remove: 'CC ' | downcase | replace: ' ', '/' }}/88x31.png" /></a><br />

{% if page.downloadurl %}<a href="{{ page.downloadurl }}" rel="cc:attributionURL">{% endif %}<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">{{ page.title }}</span>{% if page.downloadurl %}</a>{% endif %}{% if page.author %} by <span xmlns:cc="http://creativecommons.org/ns#" property="cc:attributionName" >{{ page.author }}</span>{% endif %} is licensed under <a rel="license" href="http://creativecommons.org/licenses/{{ page.license | remove: 'CC ' | downcase | replace: ' ', '/' }}/">{{ page.license }}</a>.</p>
<p align="center"><a rel="license" href="http://creativecommons.org/licenses/{{ page.license | remove: 'CC ' | downcase | replace: ' ', '/' }}/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/{{ page.license | remove: 'CC ' | downcase | replace: ' ', '/' }}/88x31.png" /></a><br />
{% if page.downloadurl %}<a href="{{ page.downloadurl }}" rel="cc:attributionURL">{% endif %}<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">{{ page.title }}</span>{% if page.downloadurl %}</a>{% endif %}{% if page.author %} by <span xmlns:cc="http://creativecommons.org/ns#" property="cc:attributionName" >{{ page.author }}</span>{% endif %} is licensed under <a rel="license" href="http://creativecommons.org/licenses/{{ page.license | remove: 'CC ' | downcase | replace: ' ', '/' }}/">{{ page.license }}</a>.
</p>

{% endif %}
{% endif %}
{% endif %}



</body>
Expand Down
58 changes: 29 additions & 29 deletions docs/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@

<div id="resourcenavbar">

<div class="resourcenav resourcenavtopicknown">
<h2>Topic</h2>
<p><script>document.write(topic);</script> [<a onclick="location.href=location.href.replace(/&?topic=([^&]$|[^&]*)/i, '');" href="#">x</a>]</p>
</div>
<div class="resourcenav resourcenavtopicknown">
<h2>Topic</h2>
<p><script>document.write(topic);</script> [<a onclick="location.href=location.href.replace(/&?topic=([^&]$|[^&]*)/i, '');" href="#">x</a>]</p>
</div>

<div class="resourcenav resourcenavtopicunknown">
<h2>Topic</h2>
<ul>
{% for topic in site.data.topics %}
<li><a onclick="window.location.search += '&topic={{ topic.string }}';" href="#">{{ topic.name }}</a></li>
{% endfor %}
</ul>
</div>
<div class="resourcenav resourcenavtopicunknown">
<h2>Topic</h2>
<ul>
{% for topic in site.data.topics %}
<li><a onclick="window.location.search += '&topic={{ topic.string }}';" href="#">{{ topic.name }}</a></li>
{% endfor %}
</ul>
</div>

<div class="resourcenav resourcenavmediumknown">
<h2>Medium</h2>
<p><script>document.write(medium);</script> [<a onclick="location.href=location.href.replace(/&?medium=([^&]$|[^&]*)/i, '');" href="#">x</a>]</p>
<p></p>
</div>
<div class="resourcenav resourcenavmediumknown">
<h2>Medium</h2>
<p><script>document.write(medium);</script> [<a onclick="location.href=location.href.replace(/&?medium=([^&]$|[^&]*)/i, '');" href="#">x</a>]</p>
<p></p>
</div>

<div class="resourcenav resourcenavmediumunknown">
<h2>Medium</h2>
<ul>
{% for medium in site.data.media %}
<li><a onclick="window.location.search += '&medium={{ medium.string }}';" href="#">{{ medium.name }}</a></li>
{% endfor %}
</ul>
</div>
<div class="resourcenav resourcenavmediumunknown">
<h2>Medium</h2>
<ul>
{% for medium in site.data.media %}
<li><a onclick="window.location.search += '&medium={{ medium.string }}';" href="#">{{ medium.name }}</a></li>
{% endfor %}
</ul>
</div>

<div class="resourcenav resourcenavlanguageknown">
<h2>Language</h2>
<p><script>document.write(language);</script> [<a onclick="location.href=location.href.replace(/&?language=([^&]$|[^&]*)/i, '');" href="#">x</a>]</p>
</div>
<div class="resourcenav resourcenavlanguageknown">
<h2>Language</h2>
<p><script>document.write(language);</script> [<a onclick="location.href=location.href.replace(/&?language=([^&]$|[^&]*)/i, '');" href="#">x</a>]</p>
</div>

<div class="resourcenav resourcenavlanguageunknown">
<h2>Language</h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/cc-licenses-poster.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
Poster outlining what each CC license allows users to do. Available in PDF and SVG formats.

<ul>
<li><a href="http://creativecommons.pl/2012/06/plakat-o-licencjach-cc/">Polish</li>
<li><a href="http://creativecommons.pl/2012/06/plakat-o-licencjach-cc/">Polish</a></li>
<li><a href="http://creativecommons.pl/2012/06/open-poster-about-cc-licenses/">English</a></li>
</ul>
Loading