Calculate where to scroll to based off the position in the div

Also, only scroll if not currently visible.
This commit is contained in:
Simon Welsh 2013-10-10 15:42:49 +13:00
parent c3e25e9e07
commit 0c2514d13e

View File

@ -15,20 +15,20 @@
var menus = $('#vakata-contextmenu').find("ul ul");
menus.each(function(i){
var col = "1",
var col = "1",
count = $(menus[i]).find('li').length;
//Assign columns to menus over 10 items long
if(count > 20){
col = "3";
col = "3";
}else if(count > 10){
col = "2";
col = "2";
}
$(menus[i]).addClass('col-' + col).removeClass('right');
//Remove "right" class that jstree adds on mouseenter
$(menus[i]).find('li').on("mouseenter", function (e) {
$(menus[i]).find('li').on("mouseenter", function (e) {
$(this).parent('ul').removeClass("right");
});
});
@ -38,7 +38,7 @@
config.plugins.push('contextmenu');
config.contextmenu = {
'items': function(node) {
var menuitems = {
'edit': {
'label': ss.i18n._t('Tree.EditPage', 'Edit page', 100, 'Used in the context menu when right-clicking on a page node in the CMS tree'),
@ -64,7 +64,7 @@
}
};
}
// Build a list for allowed children as submenu entries
var pagetype = node.data('pagetype'),
id = node.data('id'),
@ -100,13 +100,13 @@
}
};
});
if(hasAllowedChildren) {
menuitems['addsubpage'] = {
'label': ss.i18n._t('Tree.AddSubPage', 'Add page under this page', 100, 'Used in the context menu when right-clicking on a page node in the CMS tree'),
'submenu': menuAllowedChildren
};
}
}
menuitems['duplicate'] = {
'label': ss.i18n._t('Tree.Duplicate'),
@ -116,7 +116,7 @@
'action': function(obj) {
$('.cms-container').entwine('.ss').loadPanel(
$.path.addSearchParams(
ss.i18n.sprintf(self.data('urlDuplicate'), obj.data('id')),
ss.i18n.sprintf(self.data('urlDuplicate'), obj.data('id')),
self.data('extraParams')
)
);
@ -126,7 +126,7 @@
'action': function(obj) {
$('.cms-container').entwine('.ss').loadPanel(
$.path.addSearchParams(
ss.i18n.sprintf(self.data('urlDuplicatewithchildren'), obj.data('id')),
ss.i18n.sprintf(self.data('urlDuplicatewithchildren'), obj.data('id')),
self.data('extraParams')
)
);
@ -136,23 +136,33 @@
};
return menuitems;
}
}
};
return config;
}
});
// Scroll tree down to context of the current page
$('.cms-tree a.jstree-clicked').entwine({
onmatch: function(){
var self = this,
panel = self.parents('.cms-panel-content');
panel.animate({
scrollTop: self.offset().top - (panel.height() / 2)
}, 'slow');
}
});
// Scroll tree down to context of the current page, if it isn't
// already visible
$('.cms-tree a.jstree-clicked').entwine({
onmatch: function(){
var self = this,
panel = self.parents('.cms-panel-content'),
scrollTo;
if(self.offset().top < 0 ||
self.offset().top > panel.height() - self.height()) {
// Current scroll top + our current offset top is our
// position in the panel
scrollTo = panel.scrollTop() + self.offset().top
+ (panel.height() / 2);
panel.animate({
scrollTop: scrollTo
}, 'slow');
}
}
});
});
}(jQuery));