topical media & game development
lib-js-code-jquery.scrollable-1.0.2.js / js
jquery.scrollable 1.0.2. Put your HTML scroll.
Copyright (c) 2009 Tero Piirainen
http://flowplayer.org/tools/scrollable.html
Dual licensed under MIT and GPL 2+ licenses
http://www.opensource.org/licenses
Launch : March 2008
Version : 1.0.2 - Tue Feb 24 2009 10:52:08 GMT-0000 (GMT+00:00)
(function(.isFunction(fn)) {
try {
return fn.call(self, arg);
} catch (error) {
if (opts.alert) {
alert("Error calling scrollable." + name + ": " + error);
} else {
throw error;
}
return false;
}
}
return true;
}
var current = null;
// constructor
function Scrollable(root, conf) {
// current instance
var self = this;
if (!current) { current = self; }
// horizontal flag
var horizontal = !conf.vertical;
// wrap (root elements for items)
var wrap = $(conf.items, root);
// current index
var index = 0;
// get handle to navigational elements
var navi = root.siblings(conf.navi).eq(0);
var prev = root.siblings(conf.prev).eq(0);
var next = root.siblings(conf.next).eq(0);
var prevPage = root.siblings(conf.prevPage).eq(0);
var nextPage = root.siblings(conf.nextPage).eq(0);
// methods
.isFunction(time)) {
fn = time;
time = conf.speed;
}
if (i < 0) { i = 0; }
if (i > self.getSize() - conf.size) { return self; }
var item = self.getItems().eq(i);
if (!item.length) { return self; }
// onBeforeSeek
if (fireEvent(conf, "onBeforeSeek", self, i) === false) {
return self;
}
if (horizontal) {
var left = -(item.outerWidth(true) * i);
wrap.animate({left: left}, time, conf.easing, fn ? function() { fn.call(self); } : null);
} else {
var top = -(item.outerHeight(true) * i); // wrap.offset().top - item.offset().top;
wrap.animate({top: top}, time, conf.easing, fn ? function() { fn.call(self); } : null);
}
// navi status update
if (navi.length) {
var klass = conf.activeClass;
var page = Math.ceil(i / conf.size);
page = Math.min(page, navi.children().length - 1);
navi.children().removeClass(klass).eq(page).addClass(klass);
}
// prev buttons disabled flag
if (i === 0) {
prev.add(prevPage).addClass(conf.disabledClass);
} else {
prev.add(prevPage).removeClass(conf.disabledClass);
}
// next buttons disabled flag
if (i >= self.getSize() - conf.size) {
next.add(nextPage).addClass(conf.disabledClass);
} else {
next.add(nextPage).removeClass(conf.disabledClass);
}
current = self;
index = i;
// onSeek after index being updated
fireEvent(conf, "onSeek", self, i);
return self;
},
move: function(offset, time, fn) {
var to = index + offset;
if (conf.loop && to > (self.getSize() - conf.size)) {
to = 0;
}
return this.seekTo(to, time, fn);
},
next: function(time, fn) {
return this.move(1, time, fn);
},
prev: function(time, fn) {
return this.move(-1, time, fn);
},
movePage: function(offset, time, fn) {
return this.move(conf.size * offset, time, fn);
},
setPage: function(page, time, fn) {
var size = conf.size;
var index = size * page;
var lastPage = index + size >= this.getSize();
if (lastPage) {
index = this.getSize() - conf.size;
}
return this.seekTo(index, time, fn);
},
prevPage: function(time, fn) {
return this.setPage(this.getPageIndex() - 1, time, fn);
},
nextPage: function(time, fn) {
return this.setPage(this.getPageIndex() + 1, time, fn);
},
begin: function(time, fn) {
return this.seekTo(0, time, fn);
},
end: function(time, fn) {
return this.seekTo(this.getSize() - conf.size, time, fn);
},
reload: function() {
return load();
},
click: function(index, time, fn) {
var item = self.getItems().eq(index);
var klass = conf.activeClass;
if (!item.hasClass(klass) && (index >= 0 || index < this.getSize())) {
self.getItems().removeClass(klass);
item.addClass(klass);
var delta = Math.floor(conf.size / 2);
var to = index - delta;
// next to last item must work
if (to > self.getSize() - conf.size) { to--; }
if (to !== index) {
return this.seekTo(to, time, fn);
}
}
return self;
}
});
// mousewheel
if (.fn.mousewheel)) {
root.bind("mousewheel.scrollable", function(e, delta) {
// opera goes to opposite direction
var step = .extend(opts, conf);
this.each(function() {
var el = new Scrollable(this, opts);
this.data("scrollable", el);
});
return this;
};
})(jQuery);
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.