Skip to content

Commit

Permalink
SAK-32147 Make sure to wait for all images to load (sakaiproject#3862)
Browse files Browse the repository at this point in the history
Use https://github.com/alexanderdickson/waitForImages to ensure all the
images have loaded before trigerring print.
  • Loading branch information
adrianfish authored Feb 6, 2017
1 parent 5a3c2bc commit 3e3cc4c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
1 change: 1 addition & 0 deletions roster2/src/webapp/WEB-INF/bootstrap.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<script type="text/javascript" src="/library/webjars/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="/library/webjars/jquery-i18n-properties/1.2.2/jquery.i18n.properties.min.js"></script>
<script type="text/javascript" src="/library/webjars/jquery-migrate/1.4.0/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/sakai-roster2-tool/lib/jquery.waitforimages.min.js"></script>
<script type="text/javascript" src="/profile2-tool/javascript/profile2-eb.js"></script>
<script type="text/javascript" src="/sakai-roster2-tool/lib/handlebars.runtime-v2.0.0.js"></script>
<script type="text/javascript" src="/sakai-roster2-tool/templates.js"></script>
Expand Down
63 changes: 33 additions & 30 deletions roster2/src/webapp/js/roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@

e.preventDefault();
roster.renderMembership({renderAll: true, callback: function () {
window.print();
}});

//$(window).on('load', function () {
$('#roster-members').waitForImages(function () {
window.print();
});
}});
});
};

Expand Down Expand Up @@ -452,38 +456,39 @@
hoverIntent: true,
activation: 'toggle'
});
});

if (roster.nextPage === 0 || options.renderAll) {
// We've just pulled the first page ...
if (roster.currentState === roster.STATE_OVERVIEW) {
// ... and are in OVERVIEW mode, so switch the link back on
$('#navbar_overview_link > span > a').click(function (e) {
return roster.switchState(roster.STATE_OVERVIEW);
});
} else if (roster.currentState === roster.STATE_ENROLLMENT_STATUS) {
// ... and are in ENROLLMENT_STATUS mode, so switch the link back on
$('#navbar_enrollment_status_link > span > a').click(function (e) {
return roster.switchState(roster.STATE_ENROLLMENT_STATUS);
});
if (roster.nextPage === 0 || options.renderAll) {
// We've just pulled the first page ...
if (roster.currentState === roster.STATE_OVERVIEW) {
// ... and are in OVERVIEW mode, so switch the link back on
$('#navbar_overview_link > span > a').click(function (e) {
return roster.switchState(roster.STATE_OVERVIEW);
});
} else if (roster.currentState === roster.STATE_ENROLLMENT_STATUS) {
// ... and are in ENROLLMENT_STATUS mode, so switch the link back on
$('#navbar_enrollment_status_link > span > a').click(function (e) {
return roster.switchState(roster.STATE_ENROLLMENT_STATUS);
});
}
}
}

if (options.userIds) {
$(window).off('scroll.roster');
} else {
if (!options.renderAll) {
roster.nextPage += 1;
$(window).off('scroll.roster').on('scroll.roster', roster.getScrollFunction(options.forceOfficialPicture, undefined, enrollmentsMode));
if (options.userIds) {
$(window).off('scroll.roster');
} else {
if (!options.renderAll) {
roster.nextPage += 1;
$(window).off('scroll.roster').on('scroll.roster', roster.getScrollFunction(options.forceOfficialPicture, undefined, enrollmentsMode));
}
}
}

loadImage.hide();
loadImage.hide();

if (options.callback) {
options.callback();
}
},
if (options.callback) {
options.callback();
}
});

},
error: function (jqXHR, textStatus, errorThrown) {

console.log('Failed to get membership data. textStatus: ' + textStatus + '. errorThrown: ' + errorThrown);
Expand Down Expand Up @@ -609,9 +614,7 @@
roster.getRoleFragments = function (roleCounts) {

return Object.keys(roleCounts).map(function (key) {
console.log('roleCounts:' + roleCounts[key]);
var frag = roster.i18n.role_breakdown_fragment.replace(/\{0\}/, roleCounts[key]);
console.log(frag.replace(/\{1\}/, '<span class="role">' + key + '</span>'));
return frag.replace(/\{1\}/, '<span class="role">' + key + '</span>');
}).join(", ");
};
Expand Down
2 changes: 2 additions & 0 deletions roster2/src/webapp/lib/jquery.waitforimages.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e3cc4c

Please sign in to comment.