PageSourceSearch

https://cm-ourique.pt/includes/js/jquery.fakecrop.js

js cm-ourique.pt collected 2026-09-24 18:48:05 UTC 4,439 bytes, 153 lines download raw bytes

1/***
2 * jquery.fakecrop.js
3 * Copyright (c) 2012 Vuong Nguyen
4 * http://vuongnguyen.com 
5 */
6(function ($) {
7	var methods = {
8		ratio : function (args) {
9			var item = args.item,
10				settings = args.settings;
11			return { w : item.width()/settings.wrapperWidth, 
12					h : item.height()/settings.wrapperHeight };
13		},
14		center : function (longVal, shortVal) {
15			return parseInt((longVal-shortVal)/2, 10);
16		},
17		scaleToFill : function (args) {
18			var item = args.item,
19			settings = args.settings,
20			ratio = settings.ratio,
21			width = item.width(),
22			height = item.height(),
23			offset = {top: 0, left: 0};
24			
25			if (ratio.h > ratio.w) {
26				width = settings.wrapperWidth;
27				height = height / ratio.w;
28				if (settings.center) {
29					offset.top = methods.center(width, height);
30				}
31			} else {
32				height = settings.wrapperHeight;
33				width = width / ratio.h;
34				if (settings.center) {
35					offset.left = methods.center(height, width);
36				}
37			}
38			
39			if (settings.center) {
40				args.wrapper.css('position', 'relative');
41				item.css({
42					'position' : 'absolute',
43					'top' : ['-', offset.top, 'px'].join(''),
44					'left' : offset.left + 'px'
45				});
46			}
47			
48			return item.height(height).attr('height', height + 'px')
49						.width(width).attr('width', width + 'px');
50		},
51		scaleToFit : function (args) {
52			var item = args.item,
53				settings = args.settings,
54				ratio = settings.ratio,
55				width = item.width(),
56				height = item.height(),
57				offset = {top: 0, left: 0};
58			
59			if (ratio.h > ratio.w) {
60				height = settings.wrapperHeight,
61				width = parseInt((item.width() * settings.wrapperHeight)/item.height(), 10);
62				if (settings.center) {
63					offset.left = methods.center(height, width);
64				}
65			} else {
66				height = parseInt((item.height() * settings.wrapperWidth)/item.width(), 10),
67				width = settings.wrapperWidth;
68				if (settings.center) {
69					offset.top = methods.center(width, height);
70				}
71			}
72
73			args.wrapper.css({
74				'width' : (settings.squareWidth ? settings.wrapperWidth : width) + 'px',
75				'height' : settings.wrapperHeight + 'px'
76			});
77			
78			if (settings.center) {
79				args.wrapper.css('position', 'relative');
80				item.css({
81					'position' : 'absolute',
82					'top' : offset.top +'px',
83					'left' : offset.left + 'px'
84				});
85			}
86			return item.height(height).attr('height', height + 'px')
87						.width(width).attr('width', width + 'px');
88		},
89		init : function (options) {
90			var settings = $.extend({
91				wrapperSelector : null,
92				wrapperWidth : 100,
93				wrapperHeight : 100,
94				center : true,
95				fill : true,
96				initClass : 'fc-init',
97				doneEvent : 'fakedropdone',
98				squareWidth : true
99			}, options),
100			_init = function () {
101				var item = $(this),
102					wrapper = settings.wrapperSelector ? item.closest(settings.wrapperSelector) : item.parent(),
103					args = { item : item,
104							settings : settings,
105							wrapper : wrapper }; 
106					settings.ratio = methods.ratio(args);
107					if (settings.fill) {
108						wrapper.css({
109							'overflow' : 'hidden',
110							'width' : settings.wrapperWidth + 'px',
111							'height' : settings.wrapperHeight + 'px'
112						});
113						methods.scaleToFill(args);
114					} else {
115						methods.scaleToFit(args);
116					}
117					
118					item.data('fc.settings', settings)
119						.addClass(settings.initClass) // Add class to container after initialization
120						.trigger(settings.doneEvent); // Publish an event to announce that fakecrop in initialized
121			},
122			images = this.filter('img'),
123			others = this.filter(':not(img)');
124			if (images.length) {
125				images.bind('load', function () {
126					_init.call(this);
127					this.style.display = 'inline';
128				}).each(function () {
129					// trick from paul irish's https://gist.github.com/797120/7176db676f1e0e20d7c23933f9fc655c2f120c58
130					if (this.complete || this.complete === undefined) {
131						var src = this.src;
132						this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
133						this.src = src;
134						this.style.display = 'none';
135					}
136				});
137			}
138			if (others.length) {
139				others.each(_init);
140			}
141			return this;
142		}	
143	};
144	$.fn.fakecrop = function (method) {
145		if (methods[method]) {
146			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
147		} else if (typeof method === 'object' || !method) {
148			return methods.init.apply(this, arguments);
149		} else {
150			$.error('Method ' + method + ' does not exist on jQuery.fakecrop');
151		} 
152	};
153})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.