javascripts/right-tabs-src.js in right-rails-0.4.0 vs javascripts/right-tabs-src.js in right-rails-0.4.1
- old
+ new
@@ -26,10 +26,13 @@
selected: null, // the index of the currently opened tab, by default will check url, cookies or set 0
disabled: [], // list of disabled tab indexes
closable: false, // set true if you want a close icon on your tabs
+ loop: false, // put a delay in ms to make it autostart the slideshow loop
+ loopPause: true, // make the loop get paused when user hovers the tabs with mouse
+
url: false, // a common remote tabs url template, should have the %{id} placeholder
cache: false, // marker if the remote tabs should be cached
Xhr: null, // the xhr addtional options
Cookie: null // set the cookie options if you'd like to keep the last selected tab index in cookies
@@ -758,9 +761,81 @@
} catch(e) { if (!Browser.OLD) throw(e) }
}
return result;
+ }
+
+}})());
+
+/**
+ * This module handles the slide-show loop feature for the Tabs
+ *
+ * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
+ */
+Tabs.include((function() {
+ var old_initialize = Tabs.prototype.initialize;
+
+return {
+ /**
+ * Overloading the constructor to start the slideshow loop automatically
+ *
+ */
+ initialize: function() {
+ old_initialize.apply(this, arguments);
+
+ if (this.options.loop) {
+ this.startLoop();
+ }
+ },
+
+ /**
+ * Starts the slideshow loop
+ *
+ * @param Number optional delay in ms
+ * @return Tabs this
+ */
+ startLoop: function(delay) {
+ if (isNumber(delay)) this.options.loop = delay;
+
+ // attaching the loop pause feature
+ if (this.options.loopPause) {
+ this._stopLoop = this._stopLoop || this.stopLoop.bind(this);
+ this._startLoop = this._startLoop || this.startLoop.bind(this);
+
+ this.element
+ .stopObserving('mouseover', this._stopLoop)
+ .stopObserving('mouseout', this._startLoop)
+ .on({
+ mouseover: this._stopLoop,
+ mouseout: this._startLoop
+ });
+ }
+
+ if (this.timer) this.timer.stop();
+
+ this.timer = function() {
+ var enabled = this.tabs.filter('enabled');
+ var current = this.tabs.first('current');
+ var next = enabled[enabled.indexOf(current)+1];
+
+ this.show(next || enabled.first());
+
+ }.bind(this).periodical(this.options.loop);
+
+ return this;
+ },
+
+ /**
+ * Stops the slideshow loop
+ *
+ * @return Tabs this
+ */
+ stopLoop: function() {
+ if (this.timer) {
+ this.timer.stop();
+ this.timer = null;
+ }
}
}})());
/**
\ No newline at end of file