1 /*! Copyright 2012, Ben Lin (http://dreamerslab.com/)
2 * Licensed under the MIT License (LICENSE.txt).
6 * Requires: jQuery >= 1.2.3
8 ;( function ( factory ) {
9 if ( typeof define === 'function' && define.amd ) {
10 // AMD. Register module depending on jQuery using requirejs define.
11 define( ['jquery'], factory );
17 $.fn.addBack = $.fn.addBack || $.fn.andSelf;
21 actual : function ( method, options ){
22 // check if the jQuery method exist
24 throw '$.actual => The jQuery method "' + method + '" you called does not exist';
30 includeMargin : false,
34 var configs = $.extend( defaults, options );
36 var $target = this.eq( 0 );
39 if( configs.clone === true ){
41 var style = 'position: absolute !important; top: -1000 !important; ';
43 // this is useful with css3pie
46 attr( 'style', style ).
50 restore = function (){
51 // remove DOM element after getting the width
60 // get all hidden parents
61 $hidden = $target.parents().addBack().filter( ':hidden' );
62 style += 'visibility: hidden !important; display: ' + configs.display + ' !important; ';
64 if( configs.absolute === true ) style += 'position: absolute !important; ';
66 // save the origin style props
67 // set the hidden el css to be got the actual value later
68 $hidden.each( function (){
69 // Save original style. If no style was set, attr() returns undefined
70 var $this = $( this );
71 var thisStyle = $this.attr( 'style' );
73 tmp.push( thisStyle );
74 // Retain as much of the original style as possible, if there is one
75 $this.attr( 'style', thisStyle ? thisStyle + ';' + style : style );
79 restore = function (){
80 // restore origin style values
81 $hidden.each( function ( i ){
82 var $this = $( this );
85 if( _tmp === undefined ){
86 $this.removeAttr( 'style' );
88 $this.attr( 'style', _tmp );
95 // get the actual value with user specific methed
96 // it can be 'width', 'height', 'outerWidth', 'innerWidth'... etc
97 // configs.includeMargin only works for 'outerWidth' and 'outerHeight'
98 var actual = /(outer)/.test( method ) ?
99 $target[ method ]( configs.includeMargin ) :
103 // IMPORTANT, this plugin only return the value of the first element