Reduce future changes to the javascript code of the download page

Drop unnecessary code used in other pages
Load download links from links already on the page
This commit is contained in:
Saivann 2015-02-19 09:14:39 -05:00
parent 297afbedc9
commit 20d456204e
4 changed files with 141 additions and 124 deletions

View file

@ -14,7 +14,8 @@
<!--[if lt IE 8]>{% lesscss ie.css %}<script type="text/javascript" src="/js/ie.js"></script><![endif]--> <!--[if lt IE 8]>{% lesscss ie.css %}<script type="text/javascript" src="/js/ie.js"></script><![endif]-->
{% if page.lang == 'ar' or page.lang == 'fa' %}{% lesscss rtl.less %}{% endif %} {% if page.lang == 'ar' or page.lang == 'fa' %}{% lesscss rtl.less %}{% endif %}
{% if page.lang == 'bg' or page.lang == 'el' or page.lang == 'ko' or page.lang == 'hi' or page.lang == 'pl' or page.lang == 'sl' or page.lang == 'ro' or page.lang == 'ru' or page.lang == 'tr' or page.lang == 'uk' or page.lang == 'zh_CN' or page.lang == 'zh_TW' %}{% lesscss sans.less %}{% endif %} {% if page.lang == 'bg' or page.lang == 'el' or page.lang == 'ko' or page.lang == 'hi' or page.lang == 'pl' or page.lang == 'sl' or page.lang == 'ro' or page.lang == 'ru' or page.lang == 'tr' or page.lang == 'uk' or page.lang == 'zh_CN' or page.lang == 'zh_TW' %}{% lesscss sans.less %}{% endif %}
<script type="text/javascript" src="/js/main.js"></script> <script type="text/javascript" src="/js/base.js"></script>
{% if page.id != 'download' %}<script type="text/javascript" src="/js/main.js"></script>{% endif %}
<link rel="shortcut icon" href="/favicon.png"> <link rel="shortcut icon" href="/favicon.png">
<link rel="apple-touch-icon-precomposed" href="/img/icons/logo_ios.png"/> <link rel="apple-touch-icon-precomposed" href="/img/icons/logo_ios.png"/>
</head> </head>

View file

@ -30,21 +30,21 @@ lin64: "linux64.tar.gz"
<img src="/img/os/med_win.png" alt="windows"> <img src="/img/os/med_win.png" alt="windows">
<span> <span>
<a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64exe }}" id="downloadwinexe">Windows</a> <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64exe }}" id="downloadwinexe">Windows</a>
<span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64exe }}">64 bit</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win32exe }}">32 bit</a></span> <span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64exe }}" id="win64exe">64 bit</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win32exe }}" id="win32exe">32 bit</a></span>
</span> </span>
</div> </div>
<div> <div>
<img src="/img/os/med_win.png" alt="windows"> <img src="/img/os/med_win.png" alt="windows">
<span> <span>
<a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64zip }}" id="downloadwinzip">Windows (zip)</a> <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64zip }}" id="downloadwinzip">Windows (zip)</a>
<span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64zip }}">64 bit</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win32zip }}">32 bit</a></span> <span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64zip }}" id="win64zip">64 bit</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win32zip }}" id="win32zip">32 bit</a></span>
</span> </span>
</div> </div>
<div> <div>
<img src="/img/os/med_osx.png" alt="osx"> <img src="/img/os/med_osx.png" alt="osx">
<span> <span>
<a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}{{ page.macdmg }}">Mac OS X</a> <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}{{ page.macdmg }}">Mac OS X</a>
<span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}{{ page.macdmg }}">dmg</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.mactar }}">tar.gz</a></span> <span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}{{ page.macdmg }}" id="macdmg">dmg</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.mactar }}" id="mactar">tar.gz</a></span>
</span> </span>
</div> </div>
</div> </div>
@ -53,7 +53,7 @@ lin64: "linux64.tar.gz"
<img src="/img/os/med_linux.png" alt="linux"> <img src="/img/os/med_linux.png" alt="linux">
<span> <span>
<a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin64 }}" id="downloadlin">Linux (tgz)</a> <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin64 }}" id="downloadlin">Linux (tgz)</a>
<span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin64 }}">64 bit</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin32 }}">32 bit</a></span> <span><a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin64 }}" id="lin64">64 bit</a> - <a href="{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin32 }}" id="lin32">32 bit</a></span>
</span> </span>
</div> </div>
<div> <div>
@ -93,28 +93,36 @@ var but = document.getElementById('downloadbutton');
var linkwinexe = document.getElementById('downloadwinexe'); var linkwinexe = document.getElementById('downloadwinexe');
var linkwinzip = document.getElementById('downloadwinzip'); var linkwinzip = document.getElementById('downloadwinzip');
var linklin = document.getElementById('downloadlin'); var linklin = document.getElementById('downloadlin');
var hrefwin64exe = document.getElementById('win64exe').href;
var hrefwin32exe = document.getElementById('win32exe').href;
var hrefwin64zip = document.getElementById('win64zip').href;
var hrefwin32zip = document.getElementById('win32zip').href;
var hrefmacdmg = document.getElementById('macdmg').href;
var hrefmactar = document.getElementById('mactar').href;
var hreflin64 = document.getElementById('lin64').href;
var hreflin32 = document.getElementById('lin32').href;
switch (os) { switch (os) {
case 'windows64': case 'windows64':
but.getElementsByTagName('IMG')[0].src = '/img/os/but_windows.svg'; but.getElementsByTagName('IMG')[0].src = '/img/os/but_windows.svg';
but.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64exe }}'; but.href = hrefwin64exe;
linkwinexe.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64exe }}'; linkwinexe.href = hrefwin64exe;
linkwinzip.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win64zip }}'; linkwinzip.href = hrefwin64zip;
break; break;
case 'windows32': case 'windows32':
but.getElementsByTagName('IMG')[0].src = '/img/os/but_windows.svg'; but.getElementsByTagName('IMG')[0].src = '/img/os/but_windows.svg';
but.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win32exe }}'; but.href = hrefwin32exe;
linkwinexe.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win32exe }}'; linkwinexe.href = hrefwin32exe;
linkwinzip.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.win32zip }}'; linkwinzip.href = hrefwin32zip;
break; break;
case 'linux64': case 'linux64':
but.getElementsByTagName('IMG')[0].src = '/img/os/but_linux.png'; but.getElementsByTagName('IMG')[0].src = '/img/os/but_linux.png';
but.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin64 }}'; but.href = hreflin64;
linklin.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin64 }}'; linklin.href = hreflin64;
break; break;
case 'linux32': case 'linux32':
but.getElementsByTagName('IMG')[0].src = '/img/os/but_linux.png'; but.getElementsByTagName('IMG')[0].src = '/img/os/but_linux.png';
but.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin32 }}'; but.href = hreflin32;
linklin.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}-{{ page.lin32 }}'; linklin.href = hreflin32;
break; break;
case 'ubuntu': case 'ubuntu':
but.getElementsByTagName('IMG')[0].src = '/img/os/but_ubuntu.svg'; but.getElementsByTagName('IMG')[0].src = '/img/os/but_ubuntu.svg';
@ -122,7 +130,7 @@ case 'ubuntu':
break; break;
case 'mac': case 'mac':
but.getElementsByTagName('IMG')[0].src = '/img/os/but_mac.svg'; but.getElementsByTagName('IMG')[0].src = '/img/os/but_mac.svg';
but.href = '{{ PATH_PREFIX }}/{{ FILE_PREFIX }}{{ page.macdmg }}'; but.href = hrefmacdmg;
break; break;
} }
</script> </script>

113
js/base.js Normal file
View file

@ -0,0 +1,113 @@
// This file is licensed under the MIT License (MIT) available on
// http://opensource.org/licenses/MIT.
// This file should be used only for javascript code
// necessary for all pages to work properly.
function addEvent(a, b, c) {
// Attach event to a DOM node.
// Ex. addEvent(node,'click',function);
return (a.addEventListener) ? a.addEventListener(b, c, false) : (a.attachEvent) ? a.attachEvent('on' + b, c) : false;
}
function removeEvent(a, b, c) {
// Detach event from a DOM node.
// Ex. removeEvent(node,'click',function);
return (a.removeEventListener) ? a.removeEventListener(b, c, false) : (a.detachEvent) ? a.detachEvent('on' + b, c) : false;
}
function cancelEvent(e) {
// Cancel current event.
// Ex. cancelEvent(event);
if (!e) var e = window.event;
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
}
function getEventTarget(e) {
// Return target DOM node on which the event is triggered.
// Ex. getEventTarget(event);
if (!e) var e = window.event;
return (e.target && e.target.nodeType == 3) ? e.target.parentNode : (e.target) ? e.target : e.srcElement;
}
function getStyle(a, b) {
// Return the value of the computed style on a DOM node.
// Ex. getStyle(node,'padding-bottom');
if (window.getComputedStyle) return document.defaultView.getComputedStyle(a, null).getPropertyValue(b);
var n = b.indexOf('-');
if (n !== -1) b = b.substr(0, n) + b.substr(n + 1, 1).toUpperCase() + b.substr(n + 2);
return a.currentStyle[b];
}
function addClass(node, data) {
// Add class to node.
var cl = node.className.split(' ');
for (var i = 0, n = cl.length; i < n; i++) {
if (cl[i] == data) return;
}
cl.push(data);
node.className = cl.join(' ');
}
function removeClass(node, data) {
// Remove class from node.
var ocl = node.className.split(' ');
var ncl = [];
for (var i = 0, n = ocl.length; i < n; i++) {
if (ocl[i] != data) ncl.push(ocl[i]);
}
node.className = ncl.join(' ');
}
function supportsSVG() {
// Return true if the browser supports SVG.
// Ex. if(!supportsSVG()){..apply png fallback..}
// Old FF 3.5 and Safari 3 versions have svg support, but a very poor one
// http://www.w3.org/TR/SVG11/feature#Image Defeat FF 3.5 only
// http://www.w3.org/TR/SVG11/feature#Animation Defeat Saf 3 but also returns false in IE9
// http://www.w3.org/TR/SVG11/feature#BasicGraphicsAttribute Defeat Saf 3 but also returns false in Chrome and safari4
// http://www.w3.org/TR/SVG11/feature#Text Defeat Saf 3 but also returns false in FF and safari4
if (!document.createElementNS || !document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect) return false;
if (!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1")) return false;
if (!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicGraphicsAttribute", "1.1") && !document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Animation", "1.1") && !document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Text", "1.1")) return false;
return true;
}
function fallbackSVG() {
// Replace all images extensions from .svg to .png if browser doesn't support SVG files.
if (supportsSVG()) return;
for (var i = 0, nd = document.getElementsByTagName('*'), n = nd.length; i < n; i++) {
if (nd[i].nodeName == 'IMG' && /.*\.svg$/.test(nd[i].src)) nd[i].src = nd[i].src.slice(0, -3) + 'png';
if (/\.svg/.test(getStyle(nd[i], 'background-image'))) nd[i].style.backgroundImage = getStyle(nd[i], 'background-image').replace('.svg', '.png');
if (/\.svg/.test(getStyle(nd[i], 'background'))) nd[i].style.background = getStyle(nd[i], 'background').replace('.svg', '.png');
}
}
function mobileMenuShow(e) {
// Show the mobile menu when the visitors touch the menu icon.
var mm = document.getElementById('menusimple');
var ml = document.getElementById('langselect');
var t = document.getElementById('menumobile');
mm.style.display = ml.style.display = (mm.style.display == 'block') ? '' : 'block';
t.parentNode.removeChild(t);
cancelEvent(e);
}
function mobileMenuHover(e) {
// Add a delay before hiding menu for mobiles to prevent accidental clicks.
var p = t = getEventTarget(e);
if (t.nodeName != 'A') return;
while (p.parentNode.nodeName != 'DIV') p = p.parentNode;
while (t.nodeName != 'LI' || t.parentNode != p) t = t.parentNode;
var ul = null;
if (t.getElementsByTagName('UL').length > 0) {
var ul = t.getElementsByTagName('UL')[0];
addClass(ul, 'hover');
}
setTimeout(function() {
for (var i = 0, nd = p.getElementsByTagName('UL'), n = nd.length; i < n; i++) {
if (nd[i] == ul) continue;
removeClass(nd[i], 'hover');
}
}, 1);
}

View file

@ -1,40 +1,8 @@
// This file is licensed under the MIT License (MIT) available on // This file is licensed under the MIT License (MIT) available on
// http://opensource.org/licenses/MIT. // http://opensource.org/licenses/MIT.
function addEvent(a, b, c) { // This file is used for javascript code
// Attach event to a DOM node. // necessary for some pages to work properly.
// Ex. addEvent(node,'click',function);
return (a.addEventListener) ? a.addEventListener(b, c, false) : (a.attachEvent) ? a.attachEvent('on' + b, c) : false;
}
function removeEvent(a, b, c) {
// Detach event from a DOM node.
// Ex. removeEvent(node,'click',function);
return (a.removeEventListener) ? a.removeEventListener(b, c, false) : (a.detachEvent) ? a.detachEvent('on' + b, c) : false;
}
function cancelEvent(e) {
// Cancel current event.
// Ex. cancelEvent(event);
if (!e) var e = window.event;
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
}
function getEventTarget(e) {
// Return target DOM node on which the event is triggered.
// Ex. getEventTarget(event);
if (!e) var e = window.event;
return (e.target && e.target.nodeType == 3) ? e.target.parentNode : (e.target) ? e.target : e.srcElement;
}
function getStyle(a, b) {
// Return the value of the computed style on a DOM node.
// Ex. getStyle(node,'padding-bottom');
if (window.getComputedStyle) return document.defaultView.getComputedStyle(a, null).getPropertyValue(b);
var n = b.indexOf('-');
if (n !== -1) b = b.substr(0, n) + b.substr(n + 1, 1).toUpperCase() + b.substr(n + 2);
return a.currentStyle[b];
}
function getWidth(a) { function getWidth(a) {
// Return the integer value of the computed width of a DOM node. // Return the integer value of the computed width of a DOM node.
@ -71,7 +39,7 @@ while (a.offsetParent) {
return b; return b;
} }
function getTop(a) { function getTop (a) {
// Return the integer value of the computed distance between given node and the browser window. // Return the integer value of the computed distance between given node and the browser window.
// Ex. getTop(node); // Ex. getTop(node);
var b = a.offsetTop; var b = a.offsetTop;
@ -108,26 +76,6 @@ if (getStyle(document.getElementById('detectmobile'), 'display') != 'none') retu
return false; return false;
} }
function addClass(node, data) {
// Add class to node.
var cl = node.className.split(' ');
for (var i = 0, n = cl.length; i < n; i++) {
if (cl[i] == data) return;
}
cl.push(data);
node.className = cl.join(' ');
}
function removeClass(node, data) {
// Remove class from node.
var ocl = node.className.split(' ');
var ncl = [];
for (var i = 0, n = ocl.length; i < n; i++) {
if (ocl[i] != data) ncl.push(ocl[i]);
}
node.className = ncl.join(' ');
}
function scrollToNode(t) { function scrollToNode(t) {
// Scroll to any node on the page. // Scroll to any node on the page.
if (document.body.getAttribute('data-scrollstatus') != null) { if (document.body.getAttribute('data-scrollstatus') != null) {
@ -167,59 +115,6 @@ for (var i = 0, n = domPrefixes.length; i < n; i++) {
return false; return false;
} }
function supportsSVG() {
// Return true if the browser supports SVG.
// Ex. if(!supportsSVG()){..apply png fallback..}
// Old FF 3.5 and Safari 3 versions have svg support, but a very poor one
// http://www.w3.org/TR/SVG11/feature#Image Defeat FF 3.5 only
// http://www.w3.org/TR/SVG11/feature#Animation Defeat Saf 3 but also returns false in IE9
// http://www.w3.org/TR/SVG11/feature#BasicGraphicsAttribute Defeat Saf 3 but also returns false in Chrome and safari4
// http://www.w3.org/TR/SVG11/feature#Text Defeat Saf 3 but also returns false in FF and safari4
if (!document.createElementNS || !document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect) return false;
if (!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1")) return false;
if (!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicGraphicsAttribute", "1.1") && !document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Animation", "1.1") && !document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Text", "1.1")) return false;
return true;
}
function fallbackSVG() {
// Replace all images extensions from .svg to .png if browser doesn't support SVG files.
if (supportsSVG()) return;
for (var i = 0, nd = document.getElementsByTagName('*'), n = nd.length; i < n; i++) {
if (nd[i].nodeName == 'IMG' && /.*\.svg$/.test(nd[i].src)) nd[i].src = nd[i].src.slice(0, -3) + 'png';
if (/\.svg/.test(getStyle(nd[i], 'background-image'))) nd[i].style.backgroundImage = getStyle(nd[i], 'background-image').replace('.svg', '.png');
if (/\.svg/.test(getStyle(nd[i], 'background'))) nd[i].style.background = getStyle(nd[i], 'background').replace('.svg', '.png');
}
}
function mobileMenuShow(e) {
// Show the mobile menu when the visitors touch the menu icon.
var mm = document.getElementById('menusimple');
var ml = document.getElementById('langselect');
var t = document.getElementById('menumobile');
mm.style.display = ml.style.display = (mm.style.display == 'block') ? '' : 'block';
t.parentNode.removeChild(t);
cancelEvent(e);
}
function mobileMenuHover(e) {
// Add a delay before hiding menu for mobiles to prevent accidental clicks.
var p = t = getEventTarget(e);
if (t.nodeName != 'A') return;
while (p.parentNode.nodeName != 'DIV') p = p.parentNode;
while (t.nodeName != 'LI' || t.parentNode != p) t = t.parentNode;
var ul = null;
if (t.getElementsByTagName('UL').length > 0) {
var ul = t.getElementsByTagName('UL')[0];
addClass(ul, 'hover');
}
setTimeout(function() {
for (var i = 0, nd = p.getElementsByTagName('UL'), n = nd.length; i < n; i++) {
if (nd[i] == ul) continue;
removeClass(nd[i], 'hover');
}
}, 1);
}
function boxShow(e) { function boxShow(e) {
// Display the box content when the user click a box on the "Secure your wallet" page. // Display the box content when the user click a box on the "Secure your wallet" page.
var p = t = getEventTarget(e); var p = t = getEventTarget(e);