mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Calculate where to scroll to based off the position in the div
Also, only scroll if not currently visible.
This commit is contained in:
parent
c3e25e9e07
commit
0c2514d13e
@ -15,20 +15,20 @@
|
|||||||
var menus = $('#vakata-contextmenu').find("ul ul");
|
var menus = $('#vakata-contextmenu').find("ul ul");
|
||||||
|
|
||||||
menus.each(function(i){
|
menus.each(function(i){
|
||||||
var col = "1",
|
var col = "1",
|
||||||
count = $(menus[i]).find('li').length;
|
count = $(menus[i]).find('li').length;
|
||||||
|
|
||||||
//Assign columns to menus over 10 items long
|
//Assign columns to menus over 10 items long
|
||||||
if(count > 20){
|
if(count > 20){
|
||||||
col = "3";
|
col = "3";
|
||||||
}else if(count > 10){
|
}else if(count > 10){
|
||||||
col = "2";
|
col = "2";
|
||||||
}
|
}
|
||||||
|
|
||||||
$(menus[i]).addClass('col-' + col).removeClass('right');
|
$(menus[i]).addClass('col-' + col).removeClass('right');
|
||||||
|
|
||||||
//Remove "right" class that jstree adds on mouseenter
|
//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");
|
$(this).parent('ul').removeClass("right");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -38,7 +38,7 @@
|
|||||||
config.plugins.push('contextmenu');
|
config.plugins.push('contextmenu');
|
||||||
config.contextmenu = {
|
config.contextmenu = {
|
||||||
'items': function(node) {
|
'items': function(node) {
|
||||||
|
|
||||||
var menuitems = {
|
var menuitems = {
|
||||||
'edit': {
|
'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'),
|
'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
|
// Build a list for allowed children as submenu entries
|
||||||
var pagetype = node.data('pagetype'),
|
var pagetype = node.data('pagetype'),
|
||||||
id = node.data('id'),
|
id = node.data('id'),
|
||||||
@ -100,13 +100,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if(hasAllowedChildren) {
|
if(hasAllowedChildren) {
|
||||||
menuitems['addsubpage'] = {
|
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'),
|
'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
|
'submenu': menuAllowedChildren
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
menuitems['duplicate'] = {
|
menuitems['duplicate'] = {
|
||||||
'label': ss.i18n._t('Tree.Duplicate'),
|
'label': ss.i18n._t('Tree.Duplicate'),
|
||||||
@ -116,7 +116,7 @@
|
|||||||
'action': function(obj) {
|
'action': function(obj) {
|
||||||
$('.cms-container').entwine('.ss').loadPanel(
|
$('.cms-container').entwine('.ss').loadPanel(
|
||||||
$.path.addSearchParams(
|
$.path.addSearchParams(
|
||||||
ss.i18n.sprintf(self.data('urlDuplicate'), obj.data('id')),
|
ss.i18n.sprintf(self.data('urlDuplicate'), obj.data('id')),
|
||||||
self.data('extraParams')
|
self.data('extraParams')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -126,7 +126,7 @@
|
|||||||
'action': function(obj) {
|
'action': function(obj) {
|
||||||
$('.cms-container').entwine('.ss').loadPanel(
|
$('.cms-container').entwine('.ss').loadPanel(
|
||||||
$.path.addSearchParams(
|
$.path.addSearchParams(
|
||||||
ss.i18n.sprintf(self.data('urlDuplicatewithchildren'), obj.data('id')),
|
ss.i18n.sprintf(self.data('urlDuplicatewithchildren'), obj.data('id')),
|
||||||
self.data('extraParams')
|
self.data('extraParams')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -136,23 +136,33 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
return menuitems;
|
return menuitems;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return config;
|
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({
|
// Scroll tree down to context of the current page, if it isn't
|
||||||
scrollTop: self.offset().top - (panel.height() / 2)
|
// already visible
|
||||||
}, 'slow');
|
$('.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));
|
}(jQuery));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user