home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_605 < prev    next >
Encoding:
Text File  |  2010-11-24  |  1.4 KB  |  53 lines

  1. /*
  2.  * images management
  3.  * Copyright 2008 Kovid Goyal
  4.  * License: GNU GPL v3
  5.  */
  6.  
  7. function scale_images() {
  8.     $("img:visible").each(function() {
  9.         var img = $(this);
  10.         var offset = img.offset();
  11.         var avail_width = window.innerWidth - offset.left - 5;
  12.         var avail_height = window.innerHeight - 5;
  13.         img.css('width', img.data('orig-width'));
  14.         img.css('height', img.data('orig-height'));
  15.         var width = img.width();
  16.         var height = img.height();
  17.         var ratio = 0;
  18.  
  19.         if (width > avail_width) {
  20.             ratio = avail_width / width;
  21.             img.css('width', avail_width+'px');
  22.             img.css('height', (ratio*height) + 'px');
  23.             height = height * ratio;
  24.             width = width * ratio;
  25.         }
  26.  
  27.         if (height > avail_height) {
  28.             ratio = avail_height / height;
  29.             img.css('height', avail_height);
  30.             img.css('width', width * ratio);
  31.         }
  32.         //window.py_bridge.debug(window.getComputedStyle(this, '').getPropertyValue('max-width'));
  33.     });
  34. }
  35.  
  36. function store_original_size_attributes() {
  37.     $("img").each(function() {
  38.         var img = $(this);
  39.         img.data('orig-width', img.css('width'));
  40.         img.data('orig-height', img.css('height'));
  41.     });
  42. }
  43.  
  44. function setup_image_scaling_handlers() {
  45.    store_original_size_attributes();
  46.    scale_images();
  47.    $(window).resize(function(){
  48.         scale_images();
  49.    });
  50. }
  51.  
  52.  
  53.