├── .gitignore
├── tests
├── woody.jpg
├── logoimgliquid.png
├── reset.css
├── imgLiquid_simple.html
├── imgLiquid_anim.html
├── imgLiquid_full.html
├── imgLiquid_Responsive.html
├── imgLiquid_importants.html
├── imgLiquid_changeImg.html
├── imgLiquid_visible.html
├── imgLiquid_aligns.html
├── imgLiquid_Min.html
├── imgLiquid.html
└── imgLiquid_Recall.html
├── bower.json
├── license.txt
├── imgLiquid.jquery.json
├── README.md
└── js
├── imgLiquid-min.js
└── imgLiquid.js
/.gitignore:
--------------------------------------------------------------------------------
1 | examples
--------------------------------------------------------------------------------
/tests/woody.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karacas/imgLiquid/HEAD/tests/woody.jpg
--------------------------------------------------------------------------------
/tests/logoimgliquid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karacas/imgLiquid/HEAD/tests/logoimgliquid.png
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "imgLiquid",
3 | "version": "0.9.944",
4 | "main": "js/imgLiquid.js",
5 | "dependencies": {"jquery": ">=1.8.1"},
6 | "ignore": ["**/.*", "node_modules", "components", "tests", "examples"]
7 | }
8 |
--------------------------------------------------------------------------------
/tests/reset.css:
--------------------------------------------------------------------------------
1 | html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outline:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Alejandro Emparan
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/imgLiquid.jquery.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "imgLiquid",
3 | "version": "0.9.944",
4 | "title": "imgLiquid",
5 | "description": "A jQuery Plugin to resize images to fit in a container.",
6 | "homepage": "https://github.com/karacas/imgLiquid",
7 | "docs": "https://github.com/karacas/imgLiquid",
8 | "demo": "http://goo.gl/Wk8bU",
9 | "licenses": [{
10 | "type": "MIT",
11 | "url": "https://raw.github.com/karacas/imgLiquid/master/license.txt"
12 | }],
13 | "keywords": ["resize", "image", "images", "fit", "responsive", "fill", "container", "img", "thumbnails"],
14 | "author": {
15 | "name": "Alejandro Emparan",
16 | "url": "https://github.com/karacas"
17 | },
18 | "maintainers": [{
19 | "name": "Alejandro Emparan",
20 | "url": "https://github.com/karacas"
21 | }],
22 | "repository": {
23 | "type": "git",
24 | "url": "git://github.com/karacas/imgLiquid.git"
25 | },
26 | "bugs": "https://github.com/karacas/imgLiquid/issues",
27 | "dependencies": {
28 | "jquery": ">=1.8.1"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/imgLiquid_simple.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |

33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/tests/imgLiquid_anim.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |

43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/tests/imgLiquid_full.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
27 |
28 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |

53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | imgLiquid v0.9.944 / 11-04-2013
4 | ##### A jQuery Plugin to resize images to fit in a container.
5 | Alejandro Emparan (karacas) / @krc_ale
6 | Dual licensed under the MIT and GPL licenses.
7 | ##
8 | # Usage
9 |
10 | #### Include:
11 | ```html
12 |
13 | ```
14 |
15 | #### js:
16 | ```js
17 | $(document).ready(function() {
18 | $(".imgLiquidFill").imgLiquid();
19 | });
20 | ```
21 |
22 | #### Html:
23 | ```html
24 |
25 |

26 |
27 | ```
28 | #### View in action:
29 | http://jsfiddle.net/karacas/3CRx7/#base
30 |
31 | http://codepen.io/karacas/pen/nlugd
32 |
33 |
34 | ### Features:
35 | ```
36 | - Uses CSS Background-size when is available. (new!)
37 | - Bootstrap compatible.
38 | - Lightweight: < 2.0KBs gzipped.
39 | - Fill / Crop.
40 | - Align.
41 | - Responsive.
42 | - Svg support.
43 | - CallBacks.
44 | - HTML5 data-* attributes.
45 | - All browsers (Incl. ie6).
46 | ```
47 |
48 | ### Options:
49 | ```
50 |
51 | >js
52 | fill: true,
53 | verticalAlign: // 'center' // 'top' // 'bottom' // '50%' // '10%'
54 | horizontalAlign: // 'center' // 'left' // 'right' // '50%' // '10%'
55 |
56 | //CallBacks
57 | onStart: function(){},
58 | onFinish: function(){},
59 | onItemStart: function(index, container, img){},
60 | onItemFinish: function(index, container, img){}
61 |
62 | >hml5 data attr (overwrite js options)
63 | data-imgLiquid-fill="true"
64 | data-imgLiquid-horizontalAlign="center"
65 | data-imgLiquid-verticalAlign="50%"
66 |
67 | ```
68 |
--------------------------------------------------------------------------------
/tests/imgLiquid_Responsive.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
29 |
73 |
74 |
75 |
76 |
77 |
78 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/tests/imgLiquid_importants.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | imgLiquid Jquery Plugin
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
27 |
28 |
29 |
30 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/tests/imgLiquid_changeImg.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
29 |
30 |
31 |
32 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | Change Image
84 |
85 |
86 |
87 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/tests/imgLiquid_visible.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
30 |
31 |
32 |
33 |
73 |
74 |
75 |
76 |
77 |
78 | Show
79 |
80 |
81 |
88 |
89 |
96 |
97 |
104 |
105 |
106 |
113 |
114 |
121 |
122 |
129 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/js/imgLiquid-min.js:
--------------------------------------------------------------------------------
1 | var imgLiquid=imgLiquid||{VER:"0.9.944"};imgLiquid.bgs_Available=!1,imgLiquid.bgs_CheckRunned=!1,imgLiquid.injectCss=".imgLiquid img {visibility:hidden}",function(i){function t(){if(!imgLiquid.bgs_CheckRunned){imgLiquid.bgs_CheckRunned=!0;var t=i('');i("body").append(t),!function(){var i=t[0];if(i&&window.getComputedStyle){var e=window.getComputedStyle(i,null);e&&e.backgroundSize&&(imgLiquid.bgs_Available="cover"===e.backgroundSize)}}(),t.remove()}}i.fn.extend({imgLiquid:function(e){this.defaults={fill:!0,verticalAlign:"center",horizontalAlign:"center",useBackgroundSize:!0,useDataHtmlAttr:!0,responsive:!0,delay:0,fadeInTime:0,removeBoxBackground:!0,hardPixels:!0,responsiveCheckTime:500,timecheckvisibility:500,onStart:null,onFinish:null,onItemStart:null,onItemFinish:null,onItemError:null},t();var a=this;return this.options=e,this.settings=i.extend({},this.defaults,this.options),this.settings.onStart&&this.settings.onStart(),this.each(function(t){function e(){-1===u.css("background-image").indexOf(encodeURI(c.attr("src")))&&u.css({"background-image":'url("'+encodeURI(c.attr("src"))+'")'}),u.css({"background-size":g.fill?"cover":"contain","background-position":(g.horizontalAlign+" "+g.verticalAlign).toLowerCase(),"background-repeat":"no-repeat"}),i("a:first",u).css({display:"block",width:"100%",height:"100%"}),i("img",u).css({display:"none"}),g.onItemFinish&&g.onItemFinish(t,u,c),u.addClass("imgLiquid_bgSize"),u.addClass("imgLiquid_ready"),l()}function d(){function e(){c.data("imgLiquid_error")||c.data("imgLiquid_loaded")||c.data("imgLiquid_oldProcessed")||(u.is(":visible")&&c[0].complete&&c[0].width>0&&c[0].height>0?(c.data("imgLiquid_loaded",!0),setTimeout(r,t*g.delay)):setTimeout(e,g.timecheckvisibility))}if(c.data("oldSrc")&&c.data("oldSrc")!==c.attr("src")){var a=c.clone().removeAttr("style");return a.data("imgLiquid_settings",c.data("imgLiquid_settings")),c.parent().prepend(a),c.remove(),c=a,c[0].width=0,setTimeout(d,10),void 0}return c.data("imgLiquid_oldProcessed")?(r(),void 0):(c.data("imgLiquid_oldProcessed",!1),c.data("oldSrc",c.attr("src")),i("img:not(:first)",u).css("display","none"),u.css({overflow:"hidden"}),c.fadeTo(0,0).removeAttr("width").removeAttr("height").css({visibility:"visible","max-width":"none","max-height":"none",width:"auto",height:"auto",display:"block"}),c.on("error",n),c[0].onerror=n,e(),o(),void 0)}function o(){(g.responsive||c.data("imgLiquid_oldProcessed"))&&c.data("imgLiquid_settings")&&(g=c.data("imgLiquid_settings"),u.actualSize=u.get(0).offsetWidth+u.get(0).offsetHeight/1e4,u.sizeOld&&u.actualSize!==u.sizeOld&&r(),u.sizeOld=u.actualSize,setTimeout(o,g.responsiveCheckTime))}function n(){c.data("imgLiquid_error",!0),u.addClass("imgLiquid_error"),g.onItemError&&g.onItemError(t,u,c),l()}function s(){var i={};if(a.settings.useDataHtmlAttr){var t=u.attr("data-imgLiquid-fill"),e=u.attr("data-imgLiquid-horizontalAlign"),d=u.attr("data-imgLiquid-verticalAlign");("true"===t||"false"===t)&&(i.fill=Boolean("true"===t)),void 0===e||"left"!==e&&"center"!==e&&"right"!==e&&-1===e.indexOf("%")||(i.horizontalAlign=e),void 0===d||"top"!==d&&"bottom"!==d&&"center"!==d&&-1===d.indexOf("%")||(i.verticalAlign=d)}return imgLiquid.isIE&&a.settings.ieFadeInDisabled&&(i.fadeInTime=0),i}function r(){var i,e,a,d,o,n,s,r,m=0,h=0,f=u.width(),v=u.height();void 0===c.data("owidth")&&c.data("owidth",c[0].width),void 0===c.data("oheight")&&c.data("oheight",c[0].height),g.fill===f/v>=c.data("owidth")/c.data("oheight")?(i="100%",e="auto",a=Math.floor(f),d=Math.floor(f*(c.data("oheight")/c.data("owidth")))):(i="auto",e="100%",a=Math.floor(v*(c.data("owidth")/c.data("oheight"))),d=Math.floor(v)),o=g.horizontalAlign.toLowerCase(),s=f-a,"left"===o&&(h=0),"center"===o&&(h=.5*s),"right"===o&&(h=s),-1!==o.indexOf("%")&&(o=parseInt(o.replace("%",""),10),o>0&&(h=.01*s*o)),n=g.verticalAlign.toLowerCase(),r=v-d,"left"===n&&(m=0),"center"===n&&(m=.5*r),"bottom"===n&&(m=r),-1!==n.indexOf("%")&&(n=parseInt(n.replace("%",""),10),n>0&&(m=.01*r*n)),g.hardPixels&&(i=a,e=d),c.css({width:i,height:e,"margin-left":Math.floor(h),"margin-top":Math.floor(m)}),c.data("imgLiquid_oldProcessed")||(c.fadeTo(g.fadeInTime,1),c.data("imgLiquid_oldProcessed",!0),g.removeBoxBackground&&u.css("background-image","none"),u.addClass("imgLiquid_nobgSize"),u.addClass("imgLiquid_ready")),g.onItemFinish&&g.onItemFinish(t,u,c),l()}function l(){t===a.length-1&&a.settings.onFinish&&a.settings.onFinish()}var g=a.settings,u=i(this),c=i("img:first",u);return c.length?(c.data("imgLiquid_settings")?(u.removeClass("imgLiquid_error").removeClass("imgLiquid_ready"),g=i.extend({},c.data("imgLiquid_settings"),a.options)):g=i.extend({},a.settings,s()),c.data("imgLiquid_settings",g),g.onItemStart&&g.onItemStart(t,u,c),imgLiquid.bgs_Available&&g.useBackgroundSize?e():d(),void 0):(n(),void 0)})}})}(jQuery),!function(){var i=imgLiquid.injectCss,t=document.getElementsByTagName("head")[0],e=document.createElement("style");e.type="text/css",e.styleSheet?e.styleSheet.cssText=i:e.appendChild(document.createTextNode(i)),t.appendChild(e)}();
--------------------------------------------------------------------------------
/tests/imgLiquid_aligns.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
29 |
30 |
31 |
32 |
71 |
72 |
73 |
74 |
75 |
82 |
89 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
111 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
133 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
155 |
162 |
163 |
164 |
165 |
166 |
--------------------------------------------------------------------------------
/tests/imgLiquid_Min.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | Fork me on GitHub
76 |
77 |

78 |
jQuery plugin to resize images to fit in a container.
79 |
All of the images src of Woody's are the same.
80 |
More info & usage in gitHub.
81 |
82 |
83 |
84 | ImageBox fill: true
85 |
92 |
93 |
100 |
101 |
108 |
109 |
110 |
111 | ImageBox fill: false
112 |
119 |
120 |
127 |
128 |
135 |
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/tests/imgLiquid.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
29 |
69 |
70 |
71 |
72 |
73 |
74 | Fork me on GitHub
75 |
76 |

77 |
jQuery plugin to resize images to fit in a container.
78 |
All of the images src of Woody's are the same.
79 |
More info & usage in gitHub.
80 |
81 |
82 |
83 | ImageBox fill: true
84 |
91 |
92 |
99 |
100 |
107 |
108 |
109 |
110 | ImageBox fill: false
111 |
118 |
119 |
126 |
127 |
134 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/tests/imgLiquid_Recall.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | imgLiquid Jquery Plugin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
65 |
66 |
67 |
68 |
102 |
103 |
104 |
105 |
106 |
115 |
116 |
117 |
118 | OLD
119 |
126 |
127 |
128 |
135 |
142 |
143 |
144 |
145 |
146 |
147 | NEW
148 |
155 |
156 |
157 |
164 |
171 |
172 |
173 |
174 |
175 |
--------------------------------------------------------------------------------
/js/imgLiquid.js:
--------------------------------------------------------------------------------
1 | /*!
2 | imgLiquid v0.9.944 / 03-05-2013
3 | jQuery plugin to resize images to fit in a container.
4 | Copyright (c) 2012 Alejandro Emparan (karacas) @krc_ale
5 | Dual licensed under the MIT and GPL licenses
6 | https://github.com/karacas/imgLiquid
7 | **/
8 | /*
9 | ex:
10 | $('.imgLiquid').imgLiquid({fill:true});
11 |
12 | // OPTIONS:
13 |
14 | > js:
15 | fill: true,
16 | verticalAlign: // 'center' // 'top' // 'bottom' // '50%' // '10%'
17 | horizontalAlign: // 'center' // 'left' // 'right' // '50%' // '10%'
18 |
19 | > CallBacks:
20 | onStart: function(){},
21 | onFinish: function(){},
22 | onItemStart: function(index, container, img){},
23 | onItemFinish: function(index, container, img){}
24 |
25 | > hml5 data attr (overwrite all)
26 | data-imgLiquid-fill='true'
27 | data-imgLiquid-horizontalAlign='center'
28 | data-imgLiquid-verticalAlign='center'
29 | */
30 | //
31 |
32 |
33 | var imgLiquid = imgLiquid || {VER: '0.9.944'};
34 | imgLiquid.bgs_Available = false;
35 | imgLiquid.bgs_CheckRunned = false;
36 | imgLiquid.injectCss = '.imgLiquid img {visibility:hidden}';
37 |
38 |
39 | (function ($) {
40 |
41 | // ___________________________________________________________________
42 |
43 | function checkBgsIsavailable() {
44 | if (imgLiquid.bgs_CheckRunned) return;
45 | else imgLiquid.bgs_CheckRunned = true;
46 |
47 | var spanBgs = $('');
48 | $('body').append(spanBgs);
49 |
50 | !function () {
51 | var bgs_Check = spanBgs[0];
52 | if (!bgs_Check || !window.getComputedStyle) return;
53 | var compStyle = window.getComputedStyle(bgs_Check, null);
54 | if (!compStyle || !compStyle.backgroundSize) return;
55 | imgLiquid.bgs_Available = (compStyle.backgroundSize === 'cover');
56 | }();
57 |
58 | spanBgs.remove();
59 | }
60 |
61 |
62 |
63 |
64 |
65 | // ___________________________________________________________________
66 |
67 | $.fn.extend({
68 | imgLiquid: function (options) {
69 |
70 | this.defaults = {
71 | fill: true,
72 | verticalAlign: 'center', // 'top' // 'bottom' // '50%' // '10%'
73 | horizontalAlign: 'center', // 'left' // 'right' // '50%' // '10%'
74 | useBackgroundSize: true,
75 | useDataHtmlAttr: true,
76 |
77 | responsive: true, /* Only for use with BackgroundSize false (or old browsers) */
78 | delay: 0, /* Only for use with BackgroundSize false (or old browsers) */
79 | fadeInTime: 0, /* Only for use with BackgroundSize false (or old browsers) */
80 | removeBoxBackground: true, /* Only for use with BackgroundSize false (or old browsers) */
81 | hardPixels: true, /* Only for use with BackgroundSize false (or old browsers) */
82 | responsiveCheckTime: 500, /* Only for use with BackgroundSize false (or old browsers) */ /* time to check div resize */
83 | timecheckvisibility: 500, /* Only for use with BackgroundSize false (or old browsers) */ /* time to recheck if visible/loaded */
84 |
85 | // CALLBACKS
86 | onStart: null, // no-params
87 | onFinish: null, // no-params
88 | onItemStart: null, // params: (index, container, img )
89 | onItemFinish: null, // params: (index, container, img )
90 | onItemError: null // params: (index, container, img )
91 | };
92 |
93 |
94 | checkBgsIsavailable();
95 | var imgLiquidRoot = this;
96 |
97 | // Extend global settings
98 | this.options = options;
99 | this.settings = $.extend({}, this.defaults, this.options);
100 |
101 | // CallBack
102 | if (this.settings.onStart) this.settings.onStart();
103 |
104 |
105 |
106 |
107 | // ___________________________________________________________________
108 |
109 | return this.each(function ($i) {
110 |
111 | // MAIN >> each for image
112 |
113 | var settings = imgLiquidRoot.settings,
114 | $imgBoxCont = $(this),
115 | $img = $('img:first',$imgBoxCont);
116 | if (!$img.length) {onError(); return;}
117 |
118 |
119 | // Extend settings
120 | if (!$img.data('imgLiquid_settings')) {
121 | // First time
122 | settings = $.extend({}, imgLiquidRoot.settings, getSettingsOverwrite());
123 | } else {
124 | // Recall
125 | // Remove Classes
126 | $imgBoxCont.removeClass('imgLiquid_error').removeClass('imgLiquid_ready');
127 | settings = $.extend({}, $img.data('imgLiquid_settings'), imgLiquidRoot.options);
128 | }
129 | $img.data('imgLiquid_settings', settings);
130 |
131 |
132 | // Start CallBack
133 | if (settings.onItemStart) settings.onItemStart($i, $imgBoxCont, $img); /* << CallBack */
134 |
135 |
136 | // Process
137 | if (imgLiquid.bgs_Available && settings.useBackgroundSize)
138 | processBgSize();
139 | else
140 | processOldMethod();
141 |
142 |
143 | // END MAIN <<
144 |
145 |
146 |
147 |
148 | // ___________________________________________________________________
149 |
150 | function processBgSize() {
151 |
152 | // Check change img src
153 | if ($imgBoxCont.css('background-image').indexOf(encodeURI($img.attr('src'))) === -1) {
154 | // Change
155 | $imgBoxCont.css({'background-image': 'url("' + encodeURI($img.attr('src')) + '")'});
156 | }
157 |
158 | $imgBoxCont.css({
159 | 'background-size': (!settings.fill && $img[0].width <= $imgBoxCont.width() && $img[0].height <= $imgBoxCont.height()) ? 'auto' : (settings.fill) ? 'cover' : 'contain',
160 | 'background-position': (settings.horizontalAlign + ' ' + settings.verticalAlign).toLowerCase(),
161 | 'background-repeat': 'no-repeat'
162 | });
163 |
164 | $('a:first', $imgBoxCont).css({
165 | 'display': 'block',
166 | 'width': '100%',
167 | 'height': '100%'
168 | });
169 |
170 | $('img', $imgBoxCont).css({'display': 'none'});
171 |
172 | if (settings.onItemFinish) settings.onItemFinish($i, $imgBoxCont, $img); /* << CallBack */
173 |
174 | $imgBoxCont.addClass('imgLiquid_bgSize');
175 | $imgBoxCont.addClass('imgLiquid_ready');
176 | checkFinish();
177 | }
178 |
179 |
180 |
181 |
182 | // ___________________________________________________________________
183 |
184 | function processOldMethod() {
185 |
186 | // Check change img src
187 | if ($img.data('oldSrc') && $img.data('oldSrc') !== $img.attr('src')) {
188 |
189 | /* Clone & Reset img */
190 | var $imgCopy = $img.clone().removeAttr('style');
191 | $imgCopy.data('imgLiquid_settings', $img.data('imgLiquid_settings'));
192 | $img.parent().prepend($imgCopy);
193 | $img.remove();
194 | $img = $imgCopy;
195 | $img[0].width = 0;
196 |
197 | // Bug ie with > if (!$img[0].complete && $img[0].width) onError();
198 | setTimeout(processOldMethod, 10);
199 | return;
200 | }
201 |
202 |
203 | // Reproceess?
204 | if ($img.data('imgLiquid_oldProcessed')) {
205 | makeOldProcess(); return;
206 | }
207 |
208 |
209 | // Set data
210 | $img.data('imgLiquid_oldProcessed', false);
211 | $img.data('oldSrc', $img.attr('src'));
212 |
213 |
214 | // Hide others images
215 | $('img:not(:first)', $imgBoxCont).css('display', 'none');
216 |
217 |
218 | // CSSs
219 | $imgBoxCont.css({'overflow': 'hidden'});
220 | $img.fadeTo(0, 0).removeAttr('width').removeAttr('height').css({
221 | 'visibility': 'visible',
222 | 'max-width': 'none',
223 | 'max-height': 'none',
224 | 'width': 'auto',
225 | 'height': 'auto',
226 | 'display': 'block'
227 | });
228 |
229 |
230 | // CheckErrors
231 | $img.on('error', onError);
232 | $img[0].onerror = onError;
233 |
234 |
235 | // loop until load
236 | function onLoad() {
237 | if ($img.data('imgLiquid_error') || $img.data('imgLiquid_loaded') || $img.data('imgLiquid_oldProcessed')) return;
238 | if ($imgBoxCont.is(':visible') && $img[0].complete && $img[0].width > 0 && $img[0].height > 0) {
239 | $img.data('imgLiquid_loaded', true);
240 | setTimeout(makeOldProcess, $i * settings.delay);
241 | } else {
242 | setTimeout(onLoad, settings.timecheckvisibility);
243 | }
244 | }
245 |
246 |
247 | onLoad();
248 | checkResponsive();
249 | }
250 |
251 |
252 |
253 |
254 | // ___________________________________________________________________
255 |
256 | function checkResponsive() {
257 |
258 | /* Only for oldProcessed method (background-size dont need) */
259 |
260 | if (!settings.responsive && !$img.data('imgLiquid_oldProcessed')) return;
261 | if (!$img.data('imgLiquid_settings')) return;
262 |
263 | settings = $img.data('imgLiquid_settings');
264 |
265 | $imgBoxCont.actualSize = $imgBoxCont.get(0).offsetWidth + ($imgBoxCont.get(0).offsetHeight / 10000);
266 | if ($imgBoxCont.sizeOld && $imgBoxCont.actualSize !== $imgBoxCont.sizeOld) makeOldProcess();
267 |
268 | $imgBoxCont.sizeOld = $imgBoxCont.actualSize;
269 | setTimeout(checkResponsive, settings.responsiveCheckTime);
270 | }
271 |
272 |
273 |
274 |
275 | // ___________________________________________________________________
276 |
277 | function onError() {
278 | $img.data('imgLiquid_error', true);
279 | $imgBoxCont.addClass('imgLiquid_error');
280 | if (settings.onItemError) settings.onItemError($i, $imgBoxCont, $img); /* << CallBack */
281 | checkFinish();
282 | }
283 |
284 |
285 |
286 |
287 | // ___________________________________________________________________
288 |
289 | function getSettingsOverwrite() {
290 | var SettingsOverwrite = {};
291 |
292 | if (imgLiquidRoot.settings.useDataHtmlAttr) {
293 | var dif = $imgBoxCont.attr('data-imgLiquid-fill'),
294 | ha = $imgBoxCont.attr('data-imgLiquid-horizontalAlign'),
295 | va = $imgBoxCont.attr('data-imgLiquid-verticalAlign');
296 |
297 | if (dif === 'true' || dif === 'false') SettingsOverwrite.fill = Boolean (dif === 'true');
298 | if (ha !== undefined && (ha === 'left' || ha === 'center' || ha === 'right' || ha.indexOf('%') !== -1)) SettingsOverwrite.horizontalAlign = ha;
299 | if (va !== undefined && (va === 'top' || va === 'bottom' || va === 'center' || va.indexOf('%') !== -1)) SettingsOverwrite.verticalAlign = va;
300 | }
301 |
302 | if (imgLiquid.isIE && imgLiquidRoot.settings.ieFadeInDisabled) SettingsOverwrite.fadeInTime = 0; //ie no anims
303 | return SettingsOverwrite;
304 | }
305 |
306 |
307 |
308 |
309 |
310 | // ___________________________________________________________________
311 |
312 | function makeOldProcess() { /* Only for old browsers, or useBackgroundSize seted false */
313 |
314 | // Calculate size
315 | var w, h, wn, hn, ha, va, hdif, vdif,
316 | margT = 0,
317 | margL = 0,
318 | $imgCW = $imgBoxCont.width(),
319 | $imgCH = $imgBoxCont.height();
320 |
321 |
322 | // Save original sizes
323 | if ($img.data('owidth') === undefined) $img.data('owidth', $img[0].width);
324 | if ($img.data('oheight') === undefined) $img.data('oheight', $img[0].height);
325 |
326 |
327 | // Compare ratio
328 | if (!settings.fill && $img.data('owidth') <= $imgCW && $img.data('oheight') <= $imgCH) {
329 | w = 'auto';
330 | h = 'auto';
331 | wn = $img.data('owidth');
332 | hn = $img.data('oheight');
333 | } else {
334 | if (settings.fill === ($imgCW / $imgCH) >= ($img.data('owidth') / $img.data('oheight'))) {
335 | w = '100%';
336 | h = 'auto';
337 | wn = Math.floor($imgCW);
338 | hn = Math.floor($imgCW * ($img.data('oheight') / $img.data('owidth')));
339 | } else {
340 | w = 'auto';
341 | h = '100%';
342 | wn = Math.floor($imgCH * ($img.data('owidth') / $img.data('oheight')));
343 | hn = Math.floor($imgCH);
344 | }
345 | }
346 |
347 | // Align X
348 | ha = settings.horizontalAlign.toLowerCase();
349 | hdif = $imgCW - wn;
350 | if (ha === 'left') margL = 0;
351 | if (ha === 'center') margL = hdif * 0.5;
352 | if (ha === 'right') margL = hdif;
353 | if (ha.indexOf('%') !== -1){
354 | ha = parseInt (ha.replace('%',''), 10);
355 | if (ha > 0) margL = hdif * ha * 0.01;
356 | }
357 |
358 |
359 | // Align Y
360 | va = settings.verticalAlign.toLowerCase();
361 | vdif = $imgCH - hn;
362 | if (va === 'top') margT = 0;
363 | if (va === 'center') margT = vdif * 0.5;
364 | if (va === 'bottom') margT = vdif;
365 | if (va.indexOf('%') !== -1){
366 | va = parseInt (va.replace('%',''), 10);
367 | if (va > 0) margT = vdif * va * 0.01;
368 | }
369 |
370 |
371 | // Add Css
372 | if (settings.hardPixels) {w = wn; h = hn;}
373 | $img.css({
374 | 'width': w,
375 | 'height': h,
376 | 'margin-left': Math.floor(margL),
377 | 'margin-top': Math.floor(margT)
378 | });
379 |
380 |
381 | // FadeIn > Only first time
382 | if (!$img.data('imgLiquid_oldProcessed')) {
383 | $img.fadeTo(settings.fadeInTime, 1);
384 | $img.data('imgLiquid_oldProcessed', true);
385 | if (settings.removeBoxBackground) $imgBoxCont.css('background-image', 'none');
386 | $imgBoxCont.addClass('imgLiquid_nobgSize');
387 | $imgBoxCont.addClass('imgLiquid_ready');
388 | }
389 |
390 |
391 | if (settings.onItemFinish) settings.onItemFinish($i, $imgBoxCont, $img); /* << CallBack */
392 | checkFinish();
393 | }
394 |
395 |
396 |
397 |
398 | // ___________________________________________________________________
399 |
400 | function checkFinish() { /* Check callBack */
401 | if ($i === imgLiquidRoot.length - 1) if (imgLiquidRoot.settings.onFinish) imgLiquidRoot.settings.onFinish();
402 | }
403 |
404 |
405 | });
406 | }
407 | });
408 | })(jQuery);
409 |
410 |
411 |
412 | // Inject css styles ______________________________________________________
413 | !function () {
414 | var css = imgLiquid.injectCss,
415 | head = document.getElementsByTagName('head')[0],
416 | style = document.createElement('style');
417 | style.type = 'text/css';
418 | if (style.styleSheet) {
419 | style.styleSheet.cssText = css;
420 | } else {
421 | style.appendChild(document.createTextNode(css));
422 | }
423 | head.appendChild(style);
424 | }();
425 |
--------------------------------------------------------------------------------