MediaWiki:Common.js: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
No edit summary
 
(62 intermediate revisions by the same user not shown)
Line 30: Line 30:
             }else if(typeof arg2 == 'function'){
             }else if(typeof arg2 == 'function'){
                 sR.thisCallArgs.callback = arg2;
                 sR.thisCallArgs.callback = arg2;
if(typeof arg3 == 'function'){
sR.thisCallArgs.callback_ticking = arg3;
}
             }else if(typeof arg2 == 'undefined') {
             }else if(typeof arg2 == 'undefined') {
                 sR.thisCallArgs.easing = sR.defaults.easing;     
                 sR.thisCallArgs.easing = sR.defaults.easing;     
             }
             }
             if(typeof arg3 == 'function') {
             if(typeof arg3 == 'function' && typeof arg2 != 'function') {
                 sR.thisCallArgs.callback = arg3;
                 sR.thisCallArgs.callback = arg3;
             }else if(typeof arg3 == 'undefined' && typeof arg2 != 'function'){
             }else if(typeof arg2 != 'function'){
                 sR.thisCallArgs.callback = sR.defaults.callback;     
                 sR.thisCallArgs.callback = sR.defaults.callback;     
             }
             }
if(typeof arg4 == 'function') {
if(typeof arg4 == 'function') {
                 sR.thisCallArgs.callback_ticking = arg4;
                 sR.thisCallArgs.callback_ticking = arg4;
             }else{
             }else if(typeof arg4 == 'undefined' && (typeof arg2 != 'function' || typeof arg3 != 'function')){  
sR.thisCallArgs.callback_ticking = sR.defaults.callback_ticking;  
sR.thisCallArgs.callback_ticking = sR.defaults.callback_ticking;  
}
}
             var $cells = $(this).find('td');
             var $cells = $(this).children('td');
             $cells.wrapInner('<div class="slideRowUp" />');
             $cells.wrapInner('<div class="slideRowUp" />');
             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,
step: function(now, tween){
progress: function(ani, num, rem){
alert("in progress");
wrappersCounterTicking++;
if(typeof sR.thisCallArgs.callback_ticking == "function")
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);
}
}
}
}).parent().animate({
}).parent().animate({
paddingTop: '0px',
paddingTop: '0px',
paddingBottom: '0px'},{
paddingBottom: '0px'
},{
complete: function () {
complete: function () {
$(this).children('.slideRowUp').replaceWith($(this).children('.slideRowUp').contents());
$(this).children('.slideRowUp').replaceWith($(this).children('.slideRowUp').contents());
$(this).parent().css({'display':'none'});
$(this).parent().css({'display':'none'});
$(this).css({'padding': currentPadding});
$(this).css({'padding': currentPadding});
}
wrappersCounter++;
});
if(wrappersCounter == $cellContentWrappers.length-1 && typeof sR.thisCallArgs.callback == 'function') {
            var wait = setInterval(function () {
                if($cellContentWrappers.is(':animated') === false) {
                    clearInterval(wait);
                    if(typeof sR.thisCallArgs.callback == 'function') {
                         sR.thisCallArgs.callback.call(this);
                         sR.thisCallArgs.callback.call(this);
                     }
                     }
                }
},
            }, 100);                                                                                                  
});                                                                                            
             return $(this);
             return $(this);
         },
         },
Line 90: Line 97:
             }else if(typeof arg2 == 'function'){
             }else if(typeof arg2 == 'function'){
                 sR.thisCallArgs.callback = arg2;
                 sR.thisCallArgs.callback = arg2;
if(typeof arg3 == 'function'){
sR.thisCallArgs.callback_ticking = arg3;
}
             }else if(typeof arg2 == 'undefined') {
             }else if(typeof arg2 == 'undefined') {
                 sR.thisCallArgs.easing = sR.defaults.easing;     
                 sR.thisCallArgs.easing = sR.defaults.easing;     
             }
             }
             if(typeof arg3 == 'function') {
             if(typeof arg3 == 'function' && typeof arg2 != 'function') {
                 sR.thisCallArgs.callback = arg3;
                 sR.thisCallArgs.callback = arg3;
             }else if(typeof arg3 == 'undefined' && typeof arg2 != 'function'){
             }else if(typeof arg2 != 'function'){
                 sR.thisCallArgs.callback = sR.defaults.callback;     
                 sR.thisCallArgs.callback = sR.defaults.callback;     
             }
             }
if(typeof arg4 == 'function') {
if(typeof arg4 == 'function') {
                 sR.thisCallArgs.callback_ticking = arg4;
                 sR.thisCallArgs.callback_ticking = arg4;
             }else{
             }else if(typeof arg4 == 'undefined' && (typeof arg2 != 'function' || typeof arg3 != 'function')){
sR.thisCallArgs.callback_ticking = sR.defaults.callback_ticking;  
sR.thisCallArgs.callback_ticking = sR.defaults.callback_ticking;  
}
}
             var $cells = $(this).find('td');
             var $cells = $(this).children('td');
             $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({
duration: sR.thisCallArgs.slideSpeed,
duration: sR.thisCallArgs.slideSpeed,
easing: sR.thisCallArgs.easing,
easing: sR.thisCallArgs.easing,
complete: function() { $(this).replaceWith( $(this).contents()); },
complete: function() {
step: function(now, tween){
if(typeof sR.thisCallArgs.callback_ticking == "function")
$(this).replaceWith( $(this).contents());
wrappersCounter++;
if(wrappersCounter == $cellContentWrappers.length-1 && typeof sR.thisCallArgs.callback == 'function') {
                        sR.thisCallArgs.callback.call(this);
                    }
},
progress: function(ani, num, rem){
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);
}
}
}
});
});
            var wait = setInterval(function () {
                if($cellContentWrappers.is(':animated') === false) {
                    clearInterval(wait);
                    if(typeof sR.thisCallArgs.callback == 'function') {
                        sR.thisCallArgs.callback.call(this);
                    }
                }
            }, 100);
             return $(this);
             return $(this);
         }
         }
Line 131: Line 145:
};
};


$.fn.slideRow = function(method,arg1,arg2,arg3) {
$.fn.slideRow = function(method,arg1,arg2,arg3,arg4) {
     if(typeof method != 'undefined') {
     if(typeof method != 'undefined') {
         if(sR.methods[method]) {
         if(sR.methods[method]) {
Line 161: Line 175:


var item = {
var item = {
id: id,
                id: id,
number: i,
level: 0,
level: 0,
parent: parent,
parent: parent,
Line 167: Line 182:
el: $el,
el: $el,
left: 0,
left: 0,
width: $el.width() + 12
                width: $el.width() + 12,
                opened: true,
                parentOpened: function() {
this.opened = true;
                    this.children.forEach(function (child) {
child.parentOpened();
});
                },
                slideUp: function() {
                    this.opened = false;
                   
                    var lineUpdateUp = setInterval(function () {
                        updateLines(item);
                    }, 1);
                    $("." + this.el.attr("data-tt-id")).slideRow("up", 400, function () { clearInterval(lineUpdateUp); updateLines(); });
                },
                slideDown: function() {
                    this.opened = true;
this.children.forEach(function (child) {
                        child.parentOpened();
                    });
                    var lineUpdateDown = setInterval(function () {
                        updateLines(item);
                    }, 1);
                    $("." + this.el.attr("data-tt-id")).slideRow("down", 400, function () { clearInterval(lineUpdateDown); updateLines(); });
                }
};
};


Line 188: 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 207: Line 247:
item.el.closest("tr").addClass("level" + item.level);
item.el.closest("tr").addClass("level" + item.level);
 
if(item.parent == undefined)
            var odd = true;
item.el.closest("tr").addClass("odd");
var odd = true;
if (item.children.length > 0) {
if (item.children.length > 0) {
item.children.forEach(function (child) {
item.children.forEach(function (child) {
if(odd)
if(odd)
Line 222: Line 260:
});
});
item.opened = true;
item.el.addClass("tt-parent");
item.el.addClass("tt-parent");
item.showChildren = true;
var className = item.el.attr("data-tt-id");
var className = item.el.attr("data-tt-id");
//item.el.closest("tr").addClass(className);
                var children = item.children.slice();
 
var children = item.children.slice();
while(children.length > 0) {
while(children.length > 0)
{
children[0].el.closest("tr").addClass(className);
children[0].el.closest("tr").addClass(className);
if(children[0].children.length > 0)
if(children[0].children.length > 0)
Line 237: Line 272:
children.shift();
children.shift();
}
}
//$("." + className).wrapAll("<span id='children_group_" + item.el.attr("data-tt-id") + "'></col>");
}
}
});
});
Line 249: Line 282:
}
}
if(item.el.attr("data-invisible") == "true")
if(item.el.attr("data-invisible") == "true") {
{
                item.el.hide();
item.el.hide();
return ;
return ;
}
}
Line 260: 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 272: Line 305:
});
});
function updateLines()
function updateLines(limited) {
{
//Update height of all items
//Update height of all items
items.forEach(function (item) {
items.forEach(function (item) {
if (item.parent === undefined) {
if (item.parent === undefined) {
return;
return;
}
}
if(limited !== undefined && item.level != limited.level)
return ;
if(item.el.attr("data-invisible") == "true")
if(item.el.attr("data-invisible") == "true")
Line 297: Line 331:
$table.on("click", "div.tt div.content", function (e) {
$table.on("click", "div.tt div.content", function (e) {
var $el = $(e.currentTarget).closest(".tt");
            var $el = $(e.currentTarget).closest(".tt");
var $tr = $el.closest("tr");
var id = $el.data('tt-id');
var id = $el.data('tt-id');
var item = index[id];
var item = index[id];


if (item.showChildren === true) {
            if (item.opened === true) {
// hide all children
                // hide all children
item.showChildren = false;
                item.slideUp();
            } else {
                // show direct children
item.slideDown();


/*function hide(parentId) {
                window.location.hash = '#' + $el.attr("data-tt-id");
var item = index[parentId];
            }
item.children.forEach(function (child) {
if (child.showChildren !== undefined) {
child.showChildren = false;
}
 
$(child.el).closest("tr").addClass("tt-hide");
hide(child.id);
});
}
 
hide(id);*/
$("." + $el.attr("data-tt-id")).slideRow("up", 400, function(){updateLines()}, function(){updateLines()});
}
else {
// show direct children
item.showChildren = true;
/*item.children.forEach(function (child) {
$(child.el).closest("tr").removeClass("tt-hide");
});*/
window.location.hash = '#' + $el.attr("data-tt-id");
$("." + $el.attr("data-tt-id")).slideRow("down", 400, function(){updateLines()}, function(){updateLines()});
}
updateLines();
updateLines();
});
});
Line 340: Line 354:
items.forEach(function (item) {
items.forEach(function (item) {
if(item.children.length > 0) {
if(item.children.length > 0) {
if (item.el.attr("data-hide") == "true" || (item.el.attr("data-hide") != "true" && item.parent != undefined)) {
if (item.el.attr("data-hide") == "true" || (item.parent != undefined && item.el.attr("data-hide") != "false")) {
//item.el.find(".content").click();
                    if (window.location.hash != "#" + item.el.attr("data-tt-id") && (item.parent != undefined && window.location.hash != "#" + item.parent.el.attr("data-tt-id"))) {
if(window.location.hash != "#" + item.el.attr("data-tt-id"))
item.opened = false;
{
//item.el.hide();
item.showChildren = false;
$("." + item.el.attr("data-tt-id")).hide();
$("." + item.el.attr("data-tt-id")).hide();
}else{
                    } else {
item.showChildren = true;
                        item.opened = true;
}
$('html, body').animate({
scrollTop: item.el.offset().top-100
}, 200);
//item.el.show();
                    }
}
}
}
}
Confirmedusers, editor, Administrators
886

edits