added hd images feature

This commit is contained in:
Bachir Soussi Chiadmi
2017-07-01 16:23:39 +02:00
parent 7d5c19f9fd
commit 647981c4c7
3 changed files with 67 additions and 3 deletions
+7
View File
@@ -202,3 +202,10 @@ $paper-height: $page-height + ( $edge * 2 );
*/ */
-webkit-region-break-before: always; -webkit-region-break-before: always;
} }
img.missing-hd{
opacity: 0.5;
border: 1mm red solid;
}
+51
View File
@@ -8,3 +8,54 @@ $(function() {
$("#master-page").attr("data-width", $(".paper:first-child").width()).hide(); $("#master-page").attr("data-width", $(".paper:first-child").width()).hide();
}); });
// __ ______
// / / / / __ \
// / /_/ / / / /
// / __ / /_/ /
// /_/ /_/_____/
var len;
var switchedLen = 0;
function imageExists($elmt, src, callback) {
var img = new Image();
img.onload = function() { callback($elmt, src, true); };
img.onerror = function() { callback($elmt, src, false); };
img.src = src;
}
function switchHD($img, src, exists) {
// console.log('src=' + src + ', exists=' + exists);
if(exists){
$img.attr('src', src);
}else{
console.error('src '+src+' does not exists');
$img.addClass('missing-hd');
}
switchedLen++;
// console.log('len : '+len+" | switchedLen : "+switchedLen);
if(len == switchedLen)
console.log('HD assets enabled');
}
function enableHD(){
console.log('enabling HD assets');
len = $('img').length;
$('img').each(function(index, el) {
// console.log('img', el);
var $img = $(el);
var src = $img.attr('src');
// console.log('src BEFORE',src);
src = src.replace('assets', 'assets-hd');
src = src.replace('-preview', '');
// console.log('src AFTER', src);
// $img.attr('src', src);
imageExists($img, src, switchHD);
// console.log('--');
});
}
+8 -2
View File
@@ -35,10 +35,16 @@ _ERROR_PREF = '\033[1m[!!]\033[0m '
print("Building book") print("Building book")
def main(): def main():
# clean build directory # clean build directory
if os.path.isdir(_BUILD_d): if not os.path.isdir(_BUILD_d):
shutil.rmtree(_BUILD_d, ignore_errors=True) # shutil.rmtree(_BUILD_d, ignore_errors=True)
os.mkdir(_BUILD_d) os.mkdir(_BUILD_d)
if os.path.isdir(os.path.join(_BUILD_d, 'assets')):
shutil.rmtree(os.path.join(_BUILD_d, 'assets'), ignore_errors=True)
if os.path.isfile(os.path.join(_BUILD_d, 'stories.html')):
shutil.rmtree(os.path.join(_BUILD_d, 'stories.html'), ignore_errors=True)
print('Hyphen has fr language') print('Hyphen has fr language')
print('fr' in pyphen.LANGUAGES) print('fr' in pyphen.LANGUAGES)