MediaWiki:Common.js: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 4: Line 4:
     defaults: {
     defaults: {
         slideSpeed: 400,
         slideSpeed: 400,
         easing: true,
         easing: false,
         callback: false,
         callback: false,
callback_ticking: false
callback_ticking: false
Line 10: Line 10:
     thisCallArgs: {
     thisCallArgs: {
         slideSpeed: 400,
         slideSpeed: 400,
         easing: true,
         easing: false,
         callback: false,
         callback: false,
callback_ticking: false
callback_ticking: false
Line 53: Line 53:
             var currentPadding = $cells.css('padding');
             var currentPadding = $cells.css('padding');
             $cellContentWrappers = $(this).find('.slideRowUp');
             $cellContentWrappers = $(this).find('.slideRowUp');
var wrappersCounterTicking = 0;
var wrappersCounter = 0;
             $cellContentWrappers.slideUp({
             $cellContentWrappers.slideUp({
duration: sR.thisCallArgs.slideSpeed,
duration: sR.thisCallArgs.slideSpeed,
easing: sR.thisCallArgs.easing,
easing: sR.thisCallArgs.easing,
progress: function(ani, num, rem){
progress: function(ani, num, rem){
if(typeof sR.thisCallArgs.callback_ticking == "function"){
wrappersCounterTicking++;
if(wrappersCounterTicking == $cellContentWrappers.length)
wrappersCounterTicking = 0;
if(wrappersCounterTicking == $cellContentWrappers.length-1 && typeof sR.thisCallArgs.callback_ticking == "function"){
sR.thisCallArgs.callback_ticking.call(this);
sR.thisCallArgs.callback_ticking.call(this);
}
}
Line 69: Line 74:
$(this).parent().css({'display':'none'});
$(this).parent().css({'display':'none'});
$(this).css({'padding': currentPadding});
$(this).css({'padding': currentPadding});
if(typeof sR.thisCallArgs.callback == 'function') {
wrappersCounter++;
if(wrappersCounter == $cellContentWrappers.length-1 && typeof sR.thisCallArgs.callback == 'function') {
                         sR.thisCallArgs.callback.call(this);
                         sR.thisCallArgs.callback.call(this);
                     }
                     }
Line 111: Line 117:
             $cells.wrapInner('<div class="slideRowDown" style="display:none;" />');
             $cells.wrapInner('<div class="slideRowDown" style="display:none;" />');
             $cellContentWrappers = $cells.find('.slideRowDown');
             $cellContentWrappers = $cells.find('.slideRowDown');
var wrappersCounterTicking = 0;
var wrappersCounter = 0;
             $(this).show();
             $(this).show();
             $cellContentWrappers.slideDown({
             $cellContentWrappers.slideDown({
Line 116: Line 124:
easing: sR.thisCallArgs.easing,
easing: sR.thisCallArgs.easing,
complete: function() {
complete: function() {
$(this).replaceWith( $(this).contents());
$(this).replaceWith( $(this).contents());
if(typeof sR.thisCallArgs.callback == 'function') {
wrappersCounter++;
if(wrappersCounter == $cellContentWrappers.length-1 && typeof sR.thisCallArgs.callback == 'function') {
                         sR.thisCallArgs.callback.call(this);
                         sR.thisCallArgs.callback.call(this);
                     }
                     }
},
},
progress: function(ani, num, rem){
progress: function(ani, num, rem){
if(typeof sR.thisCallArgs.callback_ticking == "function"){
wrappersCounterTicking++;
if(wrappersCounterTicking == $cellContentWrappers.length)
wrappersCounterTicking = 0;
if(wrappersCounterTicking == $cellContentWrappers.length-1 && typeof sR.thisCallArgs.callback_ticking == "function"){
sR.thisCallArgs.callback_ticking.call(this);
sR.thisCallArgs.callback_ticking.call(this);
}
}
Line 163: Line 176:
var item = {
var item = {
                 id: id,
                 id: id,
                index: i,
number: i,
level: 0,
level: 0,
parent: parent,
parent: parent,
Line 172: Line 185:
                 opened: true,
                 opened: true,
                 parentOpened: function() {
                 parentOpened: function() {
                    if (this.opened) {
this.opened = true;
                        this.el.show();
                    }
                    this.children.forEach(function (child) {
                        child.parentOpened();
                    });
                },
                parentClosed: function() {
                    this.el.hide();
                     this.children.forEach(function (child) {
                     this.children.forEach(function (child) {
                        child.parentClosed();
child.parentOpened();
                    });
});
                },
                show: function() {
                    this.opened = true;
                    this.el.show();
                    this.children.forEach(function (child) {
                        child.parentOpened();
                    });
                 },
                 },
                 slideUp: function() {
                 slideUp: function() {
                     this.opened = true;
                     this.opened = false;
                     this.children.forEach(function (child) {
                      
                        child.parentOpened();
                    });
                     var lineUpdateUp = setInterval(function () {
                     var lineUpdateUp = setInterval(function () {
                         updateLines(item);
                         updateLines(item);
Line 202: Line 198:
                     $("." + this.el.attr("data-tt-id")).slideRow("up", 400, function () { clearInterval(lineUpdateUp); updateLines(); });
                     $("." + this.el.attr("data-tt-id")).slideRow("up", 400, function () { clearInterval(lineUpdateUp); updateLines(); });
                 },
                 },
                 hide: function() {
                 slideDown: function() {
                     this.opened = false;
                     this.opened = true;
                    this.el.hide();
this.children.forEach(function (child) {
                    this.children.forEach(function (child) {
                         child.parentOpened();
                         child.parentClosed();
                     });
                     });
                },
                slideDown: function() {
                    this.opened = false;
                     var lineUpdateDown = setInterval(function () {
                     var lineUpdateDown = setInterval(function () {
                         updateLines(item);
                         updateLines(item);
Line 236: Line 228:
item.left = 0;
item.left = 0;
if (item.parent !== undefined) {
if (item.parent !== undefined) {
                 item.left = item.parent.left + item.parent.width;
                 item.left = item.parent.left + Math.min(item.level > 1 ? 30 : 60, item.parent.width);
}
}
});
});
Line 256: Line 248:
item.el.closest("tr").addClass("level" + item.level);
item.el.closest("tr").addClass("level" + item.level);


             if (item.index % 2 == 0)
             var odd = true;
                item.el.closest("tr").addClass("even");
            else
                item.el.closest("tr").addClass("odd");
if (item.children.length > 0) {
if (item.children.length > 0) {
item.children.forEach(function (child) {
if(odd)
child.el.closest("tr").addClass("odd");
else
child.el.closest("tr").addClass("even");
odd = !odd;
});
item.opened = true;
item.el.addClass("tt-parent");
item.el.addClass("tt-parent");
var className = item.el.attr("data-tt-id");
var className = item.el.attr("data-tt-id");
Line 284: Line 283:
if(item.el.attr("data-invisible") == "true") {
if(item.el.attr("data-invisible") == "true") {
                 item.hide();
                 item.el.hide();
return ;
return ;
}
}
Line 293: Line 292:
var parentPos = parent.el.position();
var parentPos = parent.el.position();
var height = childPos.top - parentPos.top;
var height = childPos.top - parentPos.top;
var width = item.left - parent.left - parent.width/2;
var parentConnectionPosX = Math.min(item.level > 1 ? 15 : 30, parent.width/2);
var left = parent.left - item.left + (parent.width / 2);
var width = item.left - parent.left - parentConnectionPosX;
var left = parent.left - item.left + (parentConnectionPosX);


var $tail = $('<div class="tail"></div>').css({
var $tail = $('<div class="tail"></div>').css({
Line 337: Line 337:
             if (item.opened === true) {
             if (item.opened === true) {
                 // hide all children
                 // hide all children
                 item.slideDown();
                 item.slideUp();
             } else {
             } else {
                 // show direct children
                 // show direct children
                item.slideUp();
item.slideDown();


                 window.location.hash = '#' + $el.attr("data-tt-id");
                 window.location.hash = '#' + $el.attr("data-tt-id");
Line 355: Line 355:
if(item.children.length > 0) {
if(item.children.length > 0) {
if (item.el.attr("data-hide") == "true" || (item.parent != undefined && item.el.attr("data-hide") != "false")) {
if (item.el.attr("data-hide") == "true" || (item.parent != undefined && item.el.attr("data-hide") != "false")) {
                     if (window.location.hash != "#" + item.el.attr("data-tt-id")) {
                     if (window.location.hash != "#" + item.el.attr("data-tt-id") && (item.parent != undefined && window.location.hash != "#" + item.parent.el.attr("data-tt-id"))) {
                        item.hide();
item.opened = false;
//item.el.hide();
$("." + item.el.attr("data-tt-id")).hide();
                     } else {
                     } else {
                         item.show();
                         item.opened = true;
$('html, body').animate({
scrollTop: item.el.offset().top-100
}, 200);
//item.el.show();
                     }
                     }
}
}
Confirmedusers, editor, Administrators
886

edits