| 1 |
// $Id: $
|
| 2 |
|
| 3 |
(function($) {
|
| 4 |
var runonce = true;
|
| 5 |
var saved_html = '';
|
| 6 |
var old_html = '';
|
| 7 |
$.fn.fadeTransition = function(options) {
|
| 8 |
return this.each(function() {
|
| 9 |
$.fadeTransition(this, options);
|
| 10 |
});
|
| 11 |
};
|
| 12 |
|
| 13 |
$.fadeTransition = function(container, options) {
|
| 14 |
var settings = {
|
| 15 |
'html': '',
|
| 16 |
'speed': 'normal',
|
| 17 |
'first': null,
|
| 18 |
'second': null
|
| 19 |
};
|
| 20 |
if (options) {
|
| 21 |
$.extend(settings, options);
|
| 22 |
}
|
| 23 |
old_html = saved_html;
|
| 24 |
saved_html = settings.html;
|
| 25 |
|
| 26 |
var first = settings.first;
|
| 27 |
var second = settings.second;
|
| 28 |
var temp;
|
| 29 |
|
| 30 |
if ((typeof first == 'undefined') || (typeof second == 'undefined')) {
|
| 31 |
return true;
|
| 32 |
}
|
| 33 |
|
| 34 |
if (runonce) {
|
| 35 |
$(container).css({'position': 'relative'});
|
| 36 |
first.css({'z-index': '2', 'position': 'absolute', 'width': '100%'}).hide();
|
| 37 |
second.css({'z-index': '1', 'position': 'absolute', 'width': '100%'}).hide();
|
| 38 |
runonce = false;
|
| 39 |
};
|
| 40 |
|
| 41 |
setTimeout(function() {
|
| 42 |
first.html(settings.html).fadeIn(settings.speed, function() {
|
| 43 |
removeFilter($(this)[0]);
|
| 44 |
});
|
| 45 |
second.fadeOut(settings.speed, function() {
|
| 46 |
$(this).html(settings.html);
|
| 47 |
});
|
| 48 |
|
| 49 |
if (settings.html.length >= old_html.length) {
|
| 50 |
var containerHeight = first[0].offsetHeight > second[0].offsetHeight ? first[0].offsetHeight : second[0].offsetHeight;
|
| 51 |
var containerWidth = first[0].offsetWidth > second[0].offsetWidth ? first[0].offsetWidth : second[0].offsetWidth;
|
| 52 |
}
|
| 53 |
else {
|
| 54 |
var containerHeight = first[0].offsetHeight < second[0].offsetHeight ? first[0].offsetHeight : second[0].offsetHeight;
|
| 55 |
var containerWidth = first[0].offsetWidth < second[0].offsetWidth ? first[0].offsetWidth : second[0].offsetWidth;
|
| 56 |
}
|
| 57 |
$(container).animate({'height': containerHeight, 'width': containerWidth});
|
| 58 |
}, 100);
|
| 59 |
|
| 60 |
$(first).show();
|
| 61 |
|
| 62 |
// Interchange first and seconds.
|
| 63 |
temp = first;
|
| 64 |
first = second;
|
| 65 |
second = temp;
|
| 66 |
};
|
| 67 |
|
| 68 |
})(jQuery);
|
| 69 |
|
| 70 |
/**
|
| 71 |
* Remove Opacity-Filter in IE.
|
| 72 |
*/
|
| 73 |
function removeFilter(element) {
|
| 74 |
if (element.style.removeAttribute){
|
| 75 |
element.style.removeAttribute('filter');
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|