Skip to content

Commit

Permalink
ENHANCEMENT Added children toggle actions to CMS menu, fixed menu lin…
Browse files Browse the repository at this point in the history
…k update behaviour when records change
  • Loading branch information
chillu committed Jan 5, 2012
1 parent 095602b commit 6edf055
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 14 deletions.
2 changes: 2 additions & 0 deletions admin/css/ie7.css
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
html { overflow: hidden; }

.field input.text, .field textarea, .field .TreeDropdownField { padding-left: 0; padding-right: 0; }
11 changes: 7 additions & 4 deletions admin/css/screen.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed admin/images/sprites/32x32-s8fc6dac693.png
Binary file not shown.
Binary file added admin/images/sprites/32x32-sad4b9dcce6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added admin/images/sprites/32x32/menu-arrow-down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added admin/images/sprites/32x32/menu-arrow-up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion admin/javascript/LeftAndMain.EditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@
isChanged: function() {
if(typeof tinyMCE == 'undefined') return;

return tinyMCE.getInstanceById(this.attr('id')).isDirty();
var inst = tinyMCE.getInstanceById(this.attr('id'));
return inst ? inst.isDirty() : false;
},

resetChanged: function() {
Expand Down
37 changes: 34 additions & 3 deletions admin/javascript/LeftAndMain.Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,27 @@
});

$('.cms-menu-list li').entwine({
onmatch: function() {
if(this.find('ul').length) {
this.find('a:first').append('<span class="toggle-children"><span class="toggle-children-icon"></span></span>');
}
},
toggle: function() {
this[this.hasClass('opened') ? 'close' : 'open']();
},
/**
* "Open" is just a visual state, and unrelated to "current".
* More than one item can be open at the same time.
*/
open: function() {
var parent = this.getMenuItem();
if(parent) parent.open();
this.addClass('opened').find('ul').show();
this.find('.toggle-children').addClass('opened');
},
close: function() {
this.removeClass('opened').find('ul').hide();
this.find('.toggle-children').removeClass('opened');
},
select: function() {
var parent = this.getMenuItem();
Expand All @@ -100,7 +111,13 @@
// Remove "current" class from all siblings and their children
this.siblings().removeClass('current').close();
this.siblings().find('li').removeClass('current');
if(parent) parent.addClass('current').siblings().removeClass('current');
if(parent) {
var parentSiblings = parent.siblings();
parent.addClass('current');
parentSiblings.removeClass('current').close();
parentSiblings.find('li').removeClass('current').close();
}

this.getMenu().updateItems();

this.trigger('select');
Expand Down Expand Up @@ -148,9 +165,19 @@
}
});

$('.cms-menu-list li .toggle-children').entwine({
onclick: function(e) {
var li = this.closest('li');
li.toggle();
return false; // prevent wrapping link event to fire
}
});

$('.cms-menu-list #Menu-CMSPageSettingsController, .cms-menu-list #Menu-CMSPageHistoryController, .cms-menu-list #Menu-CMSPageEditController').entwine({
setRecordID: function(id) {
// Only applies to edit forms relating to page elements
if(!$('.cms-content').is('.CMSMain')) return;

var link = this.find('a:first'), href = link.attr("href").split('/')
// Assumes that current ID will always be the last URL segment (and not a query parameter)
href[href.length -1] = id;
Expand All @@ -160,8 +187,12 @@

$('.cms-menu-list #Menu-CMSPageAddController').entwine({
setRecordID: function(id) {
var link = this.find('a:first');
link.attr('href', link.attr('href').replace('/\?.*/', '?ParentID=' . id));
// Only applies to edit forms relating to page elements
if(!$('.cms-content').is('.CMSMain')) return;

var link = this.find('a:first'), href = link.attr('href');
if(!href.match(/\?/)) href += '?';
link.attr('href', href.replace(/\?.*$/, '?ParentID=' + id));
}
});

Expand Down
35 changes: 30 additions & 5 deletions admin/scss/_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,38 @@
}

.icon {
display: block;
display: inline-block;
float: left;
margin: 4px 10px 0 4px;

@include opacity(0.7);
}

.text {
display: block;
display: inline-block;
float: left;
}

.toggle-children {
display: inline-block;
float: right;
width: 20px;
height: 100%;
cursor: pointer;

.toggle-children-icon {
display: inline-block;
width: 8px;
height: 8px;
background: sprite($sprites32, menu-arrow-down) no-repeat;
vertical-align: middle;
}

&.opened {
.toggle-children-icon {
background: sprite($sprites32, menu-arrow-up) no-repeat;
}
}
}
}

Expand Down Expand Up @@ -280,8 +303,10 @@
}

&.collapsed {
li .text {
display: none;
li {
.text, .toggle-children {
display: none;
}
}

li > li {
Expand Down
4 changes: 4 additions & 0 deletions admin/scss/ie7.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
html {
overflow: hidden;
}

.field {
input.text,
textarea,
Expand Down
2 changes: 1 addition & 1 deletion admin/templates/Includes/LeftAndMain_Menu.ss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</a>
</li>
<li class="first <% if Top.class == 'CMSPageAddController' %>current<% end_if %>" id="Menu-CMSPageAddController">
<a href="admin/page/add/show/$Top.CurrentPageID">
<a href="admin/page/add/?ParentID=$Top.CurrentPageID">
<span class="text">Add pages</span>
</a>
</li>
Expand Down

0 comments on commit 6edf055

Please sign in to comment.