thd/web/js/jquery-tooltip/lib/jquery.bgiframe.js
author Gautier Thibault <gthibault@universcine.com>
Tue, 22 Sep 2009 16:40:38 +0200
changeset 35 94a1dc255022
permissions -rw-r--r--
Commit the all thd project created with the framework symfony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     1
/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     2
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     3
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     4
 *
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     5
 * $LastChangedDate: 2007-06-20 03:23:36 +0200 (Mi, 20 Jun 2007) $
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     6
 * $Rev: 2110 $
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     7
 *
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     8
 * Version 2.1
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
     9
 */
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    10
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    11
(function($){
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    12
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    13
/**
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    14
 * The bgiframe is chainable and applies the iframe hack to get 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    15
 * around zIndex issues in IE6. It will only apply itself in IE 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    16
 * and adds a class to the iframe called 'bgiframe'. The iframe
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    17
 * is appeneded as the first child of the matched element(s) 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    18
 * with a tabIndex and zIndex of -1.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    19
 * 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    20
 * By default the plugin will take borders, sized with pixel units,
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    21
 * into account. If a different unit is used for the border's width,
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    22
 * then you will need to use the top and left settings as explained below.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    23
 *
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    24
 * NOTICE: This plugin has been reported to cause perfromance problems
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    25
 * when used on elements that change properties (like width, height and
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    26
 * opacity) a lot in IE6. Most of these problems have been caused by 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    27
 * the expressions used to calculate the elements width, height and 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    28
 * borders. Some have reported it is due to the opacity filter. All 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    29
 * these settings can be changed if needed as explained below.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    30
 *
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    31
 * @example $('div').bgiframe();
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    32
 * @before <div><p>Paragraph</p></div>
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    33
 * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    34
 *
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    35
 * @param Map settings Optional settings to configure the iframe.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    36
 * @option String|Number top The iframe must be offset to the top
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    37
 * 		by the width of the top border. This should be a negative 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    38
 *      number representing the border-top-width. If a number is 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    39
 * 		is used here, pixels will be assumed. Otherwise, be sure
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    40
 *		to specify a unit. An expression could also be used. 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    41
 * 		By default the value is "auto" which will use an expression 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    42
 * 		to get the border-top-width if it is in pixels.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    43
 * @option String|Number left The iframe must be offset to the left
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    44
 * 		by the width of the left border. This should be a negative 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    45
 *      number representing the border-left-width. If a number is 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    46
 * 		is used here, pixels will be assumed. Otherwise, be sure
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    47
 *		to specify a unit. An expression could also be used. 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    48
 * 		By default the value is "auto" which will use an expression 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    49
 * 		to get the border-left-width if it is in pixels.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    50
 * @option String|Number width This is the width of the iframe. If
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    51
 *		a number is used here, pixels will be assume. Otherwise, be sure
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    52
 * 		to specify a unit. An experssion could also be used.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    53
 *		By default the value is "auto" which will use an experssion
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    54
 * 		to get the offsetWidth.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    55
 * @option String|Number height This is the height of the iframe. If
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    56
 *		a number is used here, pixels will be assume. Otherwise, be sure
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    57
 * 		to specify a unit. An experssion could also be used.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    58
 *		By default the value is "auto" which will use an experssion
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    59
 * 		to get the offsetHeight.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    60
 * @option Boolean opacity This is a boolean representing whether or not
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    61
 * 		to use opacity. If set to true, the opacity of 0 is applied. If
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    62
 *		set to false, the opacity filter is not applied. Default: true.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    63
 * @option String src This setting is provided so that one could change 
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    64
 *		the src of the iframe to whatever they need.
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    65
 *		Default: "javascript:false;"
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    66
 *
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    67
 * @name bgiframe
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    68
 * @type jQuery
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    69
 * @cat Plugins/bgiframe
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    70
 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    71
 */
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    72
$.fn.bgIframe = $.fn.bgiframe = function(s) {
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    73
	// This is only for IE6
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    74
	if ( $.browser.msie && parseInt($.browser.version) <= 6 ) {
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    75
		s = $.extend({
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    76
			top     : 'auto', // auto == .currentStyle.borderTopWidth
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    77
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    78
			width   : 'auto', // auto == offsetWidth
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    79
			height  : 'auto', // auto == offsetHeight
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    80
			opacity : true,
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    81
			src     : 'javascript:false;'
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    82
		}, s || {});
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    83
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    84
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    85
		               'style="display:block;position:absolute;z-index:-1;'+
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    86
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    87
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    88
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    89
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    90
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    91
					'"/>';
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    92
		return this.each(function() {
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    93
			if ( $('> iframe.bgiframe', this).length == 0 )
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    94
				this.insertBefore( document.createElement(html), this.firstChild );
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    95
		});
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    96
	}
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    97
	return this;
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    98
};
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
    99
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
   100
// Add browser.version if it doesn't exist
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
   101
if (!$.browser.version)
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
   102
	$.browser.version = navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1];
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
   103
94a1dc255022 Commit the all thd project created with the framework symfony
Gautier Thibault <gthibault@universcine.com>
parents:
diff changeset
   104
})(jQuery);