Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var svg_image = document.getElementsByTagName('image');
- var svg_count = 0;
- var svg_count_done = 0;
- if ( svg_image.length > 0 ) {
- svg_finish = 0;
- svg_count_done = 0;
- for(var si = 0; si < svg_image.length; si++ ) {
- var svg_image_href = svg_image[si].getAttribute('xlink:href');
- console.log( svg_image_href );
- if ( (svg_image_href == '') || (svg_image_href == null) || (svg_image_href == undefined)) {
- svg_image_href = svg_image[si].getAttribute('href');
- }
- var new_image_href = resolvePath(svg_image_href, opf.manifest[opf.spine[ this_chapter ]].href );
- var img_ext = new_image_href.substring( new_image_href.lastIndexOf('.') + 1 );
- var this_image = svg_image[si];
- $.ajax({
- url: new_image_href,
- beforeSend: function ( xhr ) { xhr.overrideMimeType("text/plain; charset=x-user-defined"); }
- })
- .done(function ( data2 ) {
- svg_count_done++;
- var image_el = document.createElement("IMG");
- var img_data = do_decrypt( book_key, data2, 'binary');
- image_el.setAttribute('class','svg-image');
- svg_count++;
- image_el.setAttribute('id','svg'+svg_count);
- image_el.setAttribute("src", 'data:image/'+img_ext+';base64,'+img_data );
- console.log('svg_length:'+img_data.length);
- var this_parent = this_image.parentNode; // the SVG
- var parent_parent = this_parent.parentNode; // SVG's parent
- parent_parent.insertBefore(image_el, this_parent);
- $('img#svg'+svg_count).load(function(){
- if ( $(this).width() > (colwidth) ) {
- var ori_width = $(this).width();
- var ori_height = $(this).height();
- var resize_ratio = (colwidth) / ori_width;
- $(this).width( colwidth );
- $(this).height( ori_height * resize_ratio );
- }
- if ( $(this).height() > (colheight) ) {
- var ori_width = $(this).width();
- var ori_height = $(this).height();
- var resize_ratio = (colheight) / ori_height;
- $(this).height( colheight );
- $(this).width( ori_width * resize_ratio );
- }
- });
- delete img_data;
- delete image_el;
- delete this_parent;
- delete parent_parent;
- })
- .fail(function(){
- svg_count_done++;
- })
- .always(function(){
- console.log('svg_count_done:'+svg_count_done +' svg_image.length:'+svg_image.length);
- if ( svg_count_done == svg_image.length ) {
- svg_finish = 1;
- $('svg').hide();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement