Skip to content

Commit

Permalink
Avoid duplicate code and non-reusable functions with hardcoded variables
Browse files Browse the repository at this point in the history
  • Loading branch information
saivann committed Jun 26, 2015
1 parent 17886b6 commit 3d9c178
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
15 changes: 1 addition & 14 deletions _templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,8 @@
layout: base
id: index
---
<script>
function loadMainVideo() {
var p = document.getElementById('mainvideo'),
t = p.getElementsByTagName('DIV')[0],
nd = document.createElement('IFRAME');
nd.src = '//www.youtube.com/embed/Gc2en3nHxA4?rel=0&amp;showinfo=0&amp;wmode=opaque&amp;autoplay=1{% if page.lang != 'en' %}&amp;cc_load_policy=1&amp;hl={{ page.lang }}&amp;cc_lang_pref={{ page.lang }}{% endif %}';
nd.setAttribute('frameborder', 0);
nd.setAttribute('allowfullscreen', true);
t.innerHTML = '';
t.appendChild(nd);
p.onclick = '';
}
</script>
<p class="mainsummary">{% translate listintro %}</p>
<div class="mainvideo" id="mainvideo" onclick="loadMainVideo();"><div>
<div class="mainvideo"><div onclick="loadYoutubeVideo(event);" data-youtubeurl="//www.youtube.com/embed/Gc2en3nHxA4?rel=0&amp;showinfo=0&amp;wmode=opaque&amp;autoplay=1{% if page.lang != 'en' %}&amp;cc_load_policy=1&amp;hl={{ page.lang }}&amp;cc_lang_pref={{ page.lang }}{% endif %}">
<img src="/img/video/video_wuc.jpg" alt="Youtube video">
<div class="mainvideoicon"></div>
<div class="mainvideoiconhover"></div>
Expand Down
15 changes: 1 addition & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,8 @@
id: index
title: Bitcoin
---
<script>
function loadMainVideo() {
var p = document.getElementById('mainvideo'),
t = p.getElementsByTagName('DIV')[0],
nd = document.createElement('IFRAME');
nd.src = '//www.youtube.com/embed/Gc2en3nHxA4?rel=0&amp;showinfo=0&amp;wmode=opaque&amp;autoplay=1{% if page.lang != 'en' %}&amp;cc_load_policy=1&amp;hl={{ page.lang }}&amp;cc_lang_pref={{ page.lang }}{% endif %}';
nd.setAttribute('frameborder', 0);
nd.setAttribute('allowfullscreen', true);
t.innerHTML = '';
t.appendChild(nd);
p.onclick = '';
}
</script>
<p class="mainsummary">{% translate listintro %}</p>
<div class="mainvideo" id="mainvideo" onclick="loadMainVideo();"><div>
<div class="mainvideo"><div onclick="loadYoutubeVideo(event);" data-youtubeurl="//www.youtube.com/embed/Gc2en3nHxA4?rel=0&amp;showinfo=0&amp;wmode=opaque&amp;autoplay=1{% if page.lang != 'en' %}&amp;cc_load_policy=1&amp;hl={{ page.lang }}&amp;cc_lang_pref={{ page.lang }}{% endif %}">
<img src="/img/video/video_wuc.jpg" alt="Youtube video">
<div class="mainvideoicon"></div>
<div class="mainvideoiconhover"></div>
Expand Down
13 changes: 13 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ for (var i = 0, n = domPrefixes.length; i < n; i++) {
return false;
}

function loadYoutubeVideo(e) {
// Load Youtube video on target node on click.
var t = getEventTarget(e),
nd = document.createElement('IFRAME');
while (t.getAttribute('data-youtubeurl') === null || t.getAttribute('data-youtubeurl') === '') t = t.parentNode;
nd.src = t.getAttribute('data-youtubeurl');
nd.setAttribute('frameborder', 0);
nd.setAttribute('allowfullscreen', true);
t.innerHTML = '';
t.appendChild(nd);
t.onclick = '';
}

function boxShow(e) {
// Display the box content when the user click a box on the "Secure your wallet" page.
var p = t = getEventTarget(e);
Expand Down

0 comments on commit 3d9c178

Please sign in to comment.