Skip to content

Commit

Permalink
MDL-46116 mod_imscp: Display first item with content on load.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Balch committed Nov 11, 2014
1 parent 949c66a commit 581e247
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions mod/imscp/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ M.mod_imscp.init = function(Y) {

Y.use('yui2-resize', 'yui2-dragdrop', 'yui2-container', 'yui2-button', 'yui2-layout', 'yui2-treeview', 'yui2-json', 'yui2-event', function(Y) {

var imscp_activate_item_by_index = function(index) {
imscp_activate_item(Y.YUI2.widget.TreeView.getNode('imscp_tree', index));
}

var imscp_activate_item = function(node) {
if (!node) {
return;
Expand All @@ -56,8 +60,13 @@ M.mod_imscp.init = function(Y) {
var old = Y.YUI2.util.Dom.get('imscp_object');
if (old) {
content.replaceChild(obj, old);
} else if (obj) {
content.appendChild(obj);
} else {
old = Y.YUI2.util.Dom.get('imscp_child_list');
if (old) {
content.replaceChild(obj, old);
} else {
content.appendChild(obj);
}
}
imscp_resize_frame();

Expand Down Expand Up @@ -141,6 +150,17 @@ M.mod_imscp.init = function(Y) {
}
};

var imscp_firstlinked = function(node) {
// Return first item with an href
if (node.href) {
return node;
} else if (node.children) {
return imscp_firstlinked(node.children[0]);
} else {
return null
}
};

var imscp_up = function(node) {
if (node.depth > 0) {
return node.parent;
Expand Down Expand Up @@ -273,7 +293,7 @@ M.mod_imscp.init = function(Y) {
});

// finally activate the first item
imscp_activate_item(tree.getRoot().children[0]);
imscp_activate_item(imscp_firstlinked(tree.getRoot().children[0]));

// resizing
imscp_resize_layout(false);
Expand Down

0 comments on commit 581e247

Please sign in to comment.