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
|
<script type="text/javascript">
// <![CDATA[
// Delay response
Ajax.Request.prototype.originalInitialize = Ajax.Request.prototype.initialize;
Ajax.Request.prototype.initialize = function(url, options) {
options.onSuccess = options.onSuccess.wrap(function(proceed, request, json) {
proceed.curry(request, json).delay(1);
});
this.originalInitialize(url, options);
}
// Mock ajax response
Ajax.Response.prototype._getHeaderJSON = function() {
var nbElements = 12;
var template = '<li></li>';
var from = this.request.parameters.from;
var to = Math.min(nbElements, this.request.parameters.to);
var html = $R(from, to).inject("", function(html, n) { return html + template.gsub("XX", n); });
return {html: html, from: from, to: to, more: to != nbElements};
}
var carousel = null;
function runTest() {
updateCarouselSize();
carousel = new UI.Ajax.Carousel("horizontal_carousel", {url: "carousel/test/fixtures/ajax_carousel_content.html", elementSize:250})
.observe("request:started", function() {
$('spinner').show().morph("opacity:0.8", {duration:0.5});
})
.observe("request:ended", function() {
$('spinner').morph("opacity:0", {duration:0.5, afterFinish: function(obj) { obj.element.hide(); }});
});
}
function resized() {
updateCarouselSize();
if (carousel)
carousel.updateSize();
}
function updateCarouselSize() {
var dim = document.viewport.getDimensions();
dim.width -= 20;
$("horizontal_carousel").style.width = dim.width + "px";
$$("#horizontal_carousel .container").first().style.width = (dim.width - 680) + "px";
}
Event.observe(window, "load", runTest);
Event.observe(window, "resize", resized);
// ]]>
</script> |
Partager