app/assets/javascripts/stable/stable.js in stable-rails-0.0.3 vs app/assets/javascripts/stable/stable.js in stable-rails-0.0.4
- old
+ new
@@ -1,44 +1,56 @@
(function($) {
$.fn.stable = function() {
return this.each(function() {
var stable = $(this);
+
+ var initialized = stable.hasClass('on');
+
+ if (initialized) {
+ // reset
+ stable.removeClass('on');
+ $('.scroll-vertical div', stable).height('auto');
+ $('.scroll-horizontal div', stable).width('auto');
+ }
+
var top_left_cell = $('.c-left .t-header', stable);
$('.scroll-vertical div', stable).height($('.c-right', stable).height());
$('.scroll-horizontal div', stable).width($('.c-right', stable).width()+$('.c-left', stable).width()+15);
stable.css('padding-bottom', top_left_cell.outerHeight());
stable.css('padding-right', top_left_cell.outerWidth()+15);
stable.addClass('on');
- // Para el Scroll VERTICAL
- $('.scroll-vertical', stable).scroll(function(){
- $('.vertical', stable).scrollTop($(this).scrollTop());
- });
+ if (!initialized) {
+ // Para el Scroll VERTICAL
+ $('.scroll-vertical', stable).scroll(function(){
+ $('.vertical', stable).scrollTop($(this).scrollTop());
+ });
- // Para el Scroll HORIZONTAL
- $('.scroll-horizontal', stable).scroll(function(){
- $('.horizontal', stable).scrollLeft($(this).scrollLeft());
- });
+ // Para el Scroll HORIZONTAL
+ $('.scroll-horizontal', stable).scroll(function(){
+ $('.horizontal', stable).scrollLeft($(this).scrollLeft());
+ });
- // Para la tabla
- $('.mask', stable).mousewheel(function(event, delta, deltaX, deltaY) {
- if (!stable.hasClass('on')) return;
+ // Para la tabla
+ $('.mask', stable).mousewheel(function(event, delta, deltaX, deltaY) {
+ if (!stable.hasClass('on')) return;
- var newLeft = $('.horizontal', stable).scrollLeft() + 25 * deltaX;
- var newTop = $('.vertical', stable).scrollTop() - 25 * deltaY;
+ var newLeft = $('.horizontal', stable).scrollLeft() + 25 * deltaX;
+ var newTop = $('.vertical', stable).scrollTop() - 25 * deltaY;
- $('.horizontal', stable).scrollLeft(newLeft);
- $('.vertical', stable).scrollTop(newTop);
+ $('.horizontal', stable).scrollLeft(newLeft);
+ $('.vertical', stable).scrollTop(newTop);
- $('.scroll-horizontal', stable).scrollLeft(newLeft);
- $('.scroll-vertical', stable).scrollTop(newTop);
+ $('.scroll-horizontal', stable).scrollLeft(newLeft);
+ $('.scroll-vertical', stable).scrollTop(newTop);
- event.preventDefault();
- });
+ event.preventDefault();
+ });
+ }
});
};
$(function(){
$('.stable').stable();