| 1 |
// $Id: live.js,v 1.1 2008/06/28 18:41:15 Gurpartap Exp $
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Fade Transition plugin. (c) 2008 Gurpartap Singh.
|
| 5 |
*/
|
| 6 |
(function($) {
|
| 7 |
var runonce = true;
|
| 8 |
var saved_html = '';
|
| 9 |
var old_html = '';
|
| 10 |
$.fn.fadeTransition = function(options) {
|
| 11 |
return this.each(function() {
|
| 12 |
$.fadeTransition(this, options);
|
| 13 |
});
|
| 14 |
};
|
| 15 |
|
| 16 |
$.fadeTransition = function(container, options) {
|
| 17 |
var settings = {
|
| 18 |
'html': '',
|
| 19 |
'speed': 'normal',
|
| 20 |
'first': null,
|
| 21 |
'second': null
|
| 22 |
};
|
| 23 |
if (options) {
|
| 24 |
$.extend(settings, options);
|
| 25 |
}
|
| 26 |
old_html = saved_html;
|
| 27 |
saved_html = settings.html;
|
| 28 |
|
| 29 |
var first = settings.first;
|
| 30 |
var second = settings.second;
|
| 31 |
var temp;
|
| 32 |
|
| 33 |
if ((typeof first == 'undefined') || (typeof second == 'undefined')) {
|
| 34 |
return true;
|
| 35 |
}
|
| 36 |
|
| 37 |
if (runonce) {
|
| 38 |
$(container).css({'position': 'relative'});
|
| 39 |
first.css({'z-index': '2', 'position': 'absolute', 'width': '100%'}).hide();
|
| 40 |
second.css({'z-index': '1', 'position': 'absolute', 'width': '100%'}).hide();
|
| 41 |
runonce = false;
|
| 42 |
};
|
| 43 |
|
| 44 |
setTimeout(function() {
|
| 45 |
first.html(settings.html).fadeIn(settings.speed, function() {
|
| 46 |
removeFilter($(this)[0]);
|
| 47 |
});
|
| 48 |
second.fadeOut(settings.speed, function() {
|
| 49 |
$(this).html(settings.html);
|
| 50 |
});
|
| 51 |
|
| 52 |
if (settings.html.length >= old_html.length) {
|
| 53 |
var containerHeight = first[0].offsetHeight > second[0].offsetHeight ? first[0].offsetHeight : second[0].offsetHeight;
|
| 54 |
var containerWidth = first[0].offsetWidth > second[0].offsetWidth ? first[0].offsetWidth : second[0].offsetWidth;
|
| 55 |
}
|
| 56 |
else {
|
| 57 |
var containerHeight = first[0].offsetHeight < second[0].offsetHeight ? first[0].offsetHeight : second[0].offsetHeight;
|
| 58 |
var containerWidth = first[0].offsetWidth < second[0].offsetWidth ? first[0].offsetWidth : second[0].offsetWidth;
|
| 59 |
}
|
| 60 |
$(container).animate({'height': containerHeight, 'width': containerWidth});
|
| 61 |
}, 100);
|
| 62 |
|
| 63 |
$(first).show();
|
| 64 |
|
| 65 |
// Interchange first and seconds.
|
| 66 |
temp = first;
|
| 67 |
first = second;
|
| 68 |
second = temp;
|
| 69 |
};
|
| 70 |
|
| 71 |
})(jQuery);
|
| 72 |
|
| 73 |
/**
|
| 74 |
* Remove Opacity-Filter in IE.
|
| 75 |
*/
|
| 76 |
function removeFilter(element) {
|
| 77 |
if (element.style.removeAttribute){
|
| 78 |
element.style.removeAttribute('filter');
|
| 79 |
}
|
| 80 |
}
|
| 81 |
|
| 82 |
Drupal.behaviors.liveWhoisPreview = function() {
|
| 83 |
$('#whois-whois-form input#edit-whois-submit').bind('click', updateWhoisPreview);
|
| 84 |
|
| 85 |
function updateWhoisPreview() {
|
| 86 |
var preview_button = $(this);
|
| 87 |
var address = $('input#edit-whois-address').val() || '';
|
| 88 |
var captcha_response = $('input#edit-captcha-response').val() || '';
|
| 89 |
var captcha_token = $('input#edit-captcha-token').val() || '';
|
| 90 |
|
| 91 |
var whois_div = $('div#live-whois-preview');
|
| 92 |
var whois_div_background = $('div#live-whois-preview-background');
|
| 93 |
var progress_panel = $('<div class="live-progress-panel">Loading...</div>');
|
| 94 |
|
| 95 |
$.ajax({
|
| 96 |
type: "POST",
|
| 97 |
url: Drupal.settings.basePath + 'index.php?q=whois',
|
| 98 |
data: {
|
| 99 |
address: address,
|
| 100 |
captcha_response: captcha_response,
|
| 101 |
captcha_token: captcha_token
|
| 102 |
},
|
| 103 |
dataType: 'json',
|
| 104 |
timeout: 5000,
|
| 105 |
beforeSend: function() {
|
| 106 |
progress_panel.appendTo('body').hide().fadeIn(200);
|
| 107 |
},
|
| 108 |
success: function(data){
|
| 109 |
if (typeof data['html'] == 'undefined' || data['html'] != 0) {
|
| 110 |
$('div#live-preview-container').slideDown().fadeTransition({
|
| 111 |
html: data['html'],
|
| 112 |
first: whois_div,
|
| 113 |
second: whois_div_background
|
| 114 |
});
|
| 115 |
}
|
| 116 |
setTimeout(function() {
|
| 117 |
progress_panel.fadeTo(500, 0, function() {
|
| 118 |
$(this).remove();
|
| 119 |
});
|
| 120 |
}, 500);
|
| 121 |
},
|
| 122 |
error: function() {
|
| 123 |
progress_panel.html('Error requesting data!');
|
| 124 |
|
| 125 |
whois_div.parent().slideUp();
|
| 126 |
|
| 127 |
setTimeout(function() {
|
| 128 |
progress_panel.fadeTo(1500, 0, function() {
|
| 129 |
$(this).remove();
|
| 130 |
});
|
| 131 |
}, 2500);
|
| 132 |
}
|
| 133 |
});
|
| 134 |
return false;
|
| 135 |
}
|
| 136 |
}
|