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

implement basic lazy-load of images #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 17 additions & 3 deletions static/js/moonstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ function collapseRefresh(){
}
}

function lazyLoad(cnt)
{
if(!cnt) cnt = ".panel-collapse.in";
$(cnt + ' img.munin-graph').each(function()
{
var src = $(this).data('src');
if(src) this.src = src;
});
}

$(document).ready(function() {
collapseRefresh();

Expand Down Expand Up @@ -103,9 +113,11 @@ $("a").on('click', function(e) {
if(this.pathname == location.pathname){
e.preventDefault();
var top = $(hash).offset().top - 5;
var collapse = $("#body-" + hash.substring(1));
var slctr = "#body-" + hash.substring(1);
var collapse = $(slctr);
if(!$(this).attr("data-toggle") || !collapse || !collapse.hasClass("collapse") || (collapse.hasClass("collapse") && !collapse.hasClass("in"))){
collapse.collapse('show');
lazyLoad(slctr);
$('html, body').animate({
scrollTop: top
}, 500, function(){
Expand All @@ -121,12 +133,14 @@ $(document).ready(function() {
if (location.hash){
var hash = location.hash;
var top = $(hash).offset().top - 5;
var collapse = $("#body-" + hash.substring(1));
var slctr = "#body-" + hash.substring(1);
var collapse = $(slctr);
if (collapse){
collapse.collapse('show');
lazyLoad(slctr);
}
$('html, body').animate({
scrollTop: top
}, 500);
}
});
});
8 changes: 4 additions & 4 deletions templates/munin-categoryview.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
</ol>
<a href="<TMPL_VAR NAME="URLX">">
<TMPL_IF NAME="TIMEDAY">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</TMPL_IF>
<TMPL_IF NAME="TIMEWEEK">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</TMPL_IF>
<TMPL_IF NAME="TIMEMONTH">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGMONTH">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGMONTH">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</TMPL_IF>
<TMPL_IF NAME="TIMEYEAR">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGYEAR">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGYEAR">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</TMPL_IF>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/munin-comparison-day.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<li><TMPL_IF NAME="URL1"><a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">"></TMPL_IF><TMPL_VAR ESCAPE="HTML" NAME="LABEL"><TMPL_IF NAME="URL1"></a></TMPL_IF></li>
</ol>
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</a>
</div>
</TMPL_IF>
Expand Down
2 changes: 1 addition & 1 deletion templates/munin-comparison-month.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<li><TMPL_IF NAME="URL1"><a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">"></TMPL_IF><TMPL_VAR ESCAPE="HTML" NAME="LABEL"><TMPL_IF NAME="URL1"></a></TMPL_IF></li>
</ol>
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGMONTH">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGMONTH">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</a>
</div>
</TMPL_IF>
Expand Down
2 changes: 1 addition & 1 deletion templates/munin-comparison-week.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<li><TMPL_IF NAME="URL1"><a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">"></TMPL_IF><TMPL_VAR ESCAPE="HTML" NAME="LABEL"><TMPL_IF NAME="URL1"></a></TMPL_IF></li>
</ol>
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</a>
</div>
</TMPL_IF>
Expand Down
2 changes: 1 addition & 1 deletion templates/munin-comparison-year.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<li><TMPL_IF NAME="URL1"><a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">"></TMPL_IF><TMPL_VAR ESCAPE="HTML" NAME="LABEL"><TMPL_IF NAME="URL1"></a></TMPL_IF></li>
</ol>
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGYEAR">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGYEAR">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</a>
</div>
</TMPL_IF>
Expand Down
4 changes: 2 additions & 2 deletions templates/munin-nodeview.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
<div class="row">
<div class="col-md-6">
<a href="<TMPL_VAR NAME="URLX">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="IMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="NAME">" />
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="IMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="NAME">" />
</a>
</div>
<div class="col-md-6">
<a href="<TMPL_VAR NAME="URLX">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="IMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="NAME">" />
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="IMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="NAME">" />
</a>
</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions templates/munin-problemview.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
<div class="row">
<div class="col-md-6">
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</a>
</div>
<div class="col-md-6">
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">" />
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">" />
</a>
</div>
</div>
Expand Down Expand Up @@ -80,12 +80,12 @@
<div class="row">
<div class="col-md-6">
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</a>
</div>
<div class="col-md-6">
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">" />
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">" />
</a>
</div>
</div>
Expand Down Expand Up @@ -124,12 +124,12 @@
<div class="row">
<div class="col-md-6">
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGDAY">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">"/>
</a>
</div>
<div class="col-md-6">
<a href="<TMPL_VAR NAME="R_PATH">/<TMPL_VAR NAME="URL">">
<img class="img-responsive munin-graph" src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">" />
<img class="img-responsive munin-graph" data-src="<TMPL_VAR NAME="CIMGWEEK">" alt="<TMPL_VAR ESCAPE="HTML" NAME="LABEL">" />
</a>
</div>
</div>
Expand Down