-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmDimension.js
More file actions
105 lines (74 loc) · 2.52 KB
/
Copy pathfmDimension.js
File metadata and controls
105 lines (74 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* fmDimension - jQuery plugin 0.1pre
*
* Copyright (c) 2013 Fabio Michelucci <fmichelucci@gmail.com>
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function( $ ){
var settings = {
dimension: 'h', //Per default la dimensione da calcolare è la larghezza w, h: height, w&h entambe le dimensioni
depElements: { horizontal:[], vertical:[]}, //Elementi da considerare durante il calcolo
perfercScrollbar: false
};
var $fmdimension = {
reference: $(window),
computeHeight: function(ref, vertical ){
var $h = ref.height(), l = vertical.length, h = 0;
if ( l > 0 ) {
for (var i = 0; i < l; i++) {
h += $(vertical[i]).innerHeight();
}
}
return $h-h;
},
computeWidth: function( ref, horizontal ){
var $w = ref.width(), l = horizontal.length, w = 0;
if ( l > 0 ) {
for (var i = 0; i < l; i++) {
w += $(horizontal[i]).innerWidth();
}
}
return $w-w;
},
setDimension: function( element, options ){
if ( options ) { $.extend( settings, options )};
switch( options.dimension ) {
case 'w':
element.innerWidth( $fmdimension.computeWidth( $fmdimension.reference, options.depElements.horizontal ) -15);
break;
case 'h':
element.innerHeight( $fmdimension.computeHeight( $fmdimension.reference, options.depElements.vertival ) );
break;
case 'w&h':
element.innerHeight( $fmdimension.computeHeight( $fmdimension.reference, options.depElements.vertical ) );
element.innerWidth( $fmdimension.computeWidth( $fmdimension.reference, options.depElements.horizontal ) );
break;
default:
element.innerHeight( $fmdimension.computeHeight( $fmdimension.reference, options.depElements.vertical ) );
}
},
run: function( options ){
var _self = $(this);
$fmdimension.setDimension( _self, options );
$fmdimension.reference.resize( function(){
$fmdimension.setDimension( _self, options );
});
return _self;
}
};
//Plugin namespace
$.fn.fmdimension = function(method) {
// Method calling logic
if ( $fmdimension[method] ) {
return $fmdimension[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return $fmdimension.run.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.fmdimension' );
}
};
})( jQuery );