Skip to content

Commit 91751f1

Browse files
committed
Need to expand sections as you pass over them.
* As you move elements, the sections near the drop target expand permanently.
1 parent d75e3b1 commit 91751f1

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

app/assets/javascripts/cms/new-sitemap.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,34 +161,53 @@ Sitemap.prototype.move_to = function(node_id, target_node_id, position) {
161161
};
162162

163163
// @param [Selector] A selected link (<a>)
164-
Sitemap.prototype.isOpen = function(link){
164+
Sitemap.prototype.isOpen = function(link) {
165165
return link.siblings('ul').hasClass('in') == true
166166
};
167167

168168
// @param [Selector] link A selected link (<a>)
169169
// @param [String] icon The full name of the icon (icon-folder-open)
170-
Sitemap.prototype.changeIcon = function(link, icon){
170+
Sitemap.prototype.changeIcon = function(link, icon) {
171171
link.find('i:first').attr('class', icon);
172172
};
173173

174174
// @param [Number] id
175-
Sitemap.prototype.openedSection = function(id){
175+
Sitemap.prototype.saveAsOpened = function(id) {
176176
$.cookieSet.add(Sitemap.STATE, id);
177177
};
178-
Sitemap.prototype.closedSection = function(id){
178+
Sitemap.prototype.closedSection = function(id) {
179179
$.cookieSet.remove(Sitemap.STATE, id);
180180
};
181181

182182
// Reopen all sections that the user was last working with.
183-
Sitemap.prototype.restoreOpenState = function(){
183+
Sitemap.prototype.restoreOpenState = function() {
184184
var section_ids = $.cookieSet.get(Sitemap.STATE);
185-
_.each(section_ids, function(id){
185+
_.each(section_ids, function(id) {
186186
var link = $('.selectable[data-type="section"][data-id=' + id + ']');
187187
sitemap.changeIcon(link, 'icon-folder-open');
188188
$(link.data('target')).addClass('in');
189189
});
190190
};
191191

192+
// @param [Selector] link
193+
// @param [Boolean] forceOpen (Optional: false) Whether to manually force open the section
194+
Sitemap.prototype.open = function(link, forceOpen) {
195+
forceOpen = forceOpen || false;
196+
// Ignore requests to open non-sections, or those already open.
197+
if (link.data('type') == 'section' && !$(link.data('target')).hasClass('in')) {
198+
this.changeIcon(link, 'icon-folder-open');
199+
this.saveAsOpened(link.data('id'));
200+
if(forceOpen){
201+
$(link.data('target')).collapse('show');
202+
}
203+
}
204+
205+
};
206+
207+
Sitemap.prototype.close = function(link) {
208+
this.closedSection(link.data('id'));
209+
this.changeIcon(link, 'icon-folder-close');
210+
};
192211
var sitemap = new Sitemap();
193212

194213
$(function() {
@@ -209,24 +228,27 @@ $(function() {
209228
var parent_section = ui.item.parents('ul:first');
210229
var moving_node_id = ui.item.children('a:first').data('node-id');
211230
sitemap.move_to(moving_node_id, parent_section.data('node-id'), ui.item.index() + 1);
231+
},
232+
233+
// As we move items around, expand (permanently) the surrounding lists to provide drop targets.
234+
change: function(event, ui) {
235+
var previousLink = $(ui.placeholder.prev().children('a')[0]);
236+
sitemap.open(previousLink, true);
237+
var nextLink = $(ui.placeholder.next().children('a')[0]);
238+
sitemap.open(nextLink, true);
239+
212240
}
213241
});
214-
215242
});
216243

217244
// Change the folder icon when they are opened/closed.
218245
$(function() {
219246
sitemap.restoreOpenState();
220-
console.log("On page load, these sections should be open", $.cookie('sitemap.opened'));
221247
$('a[data-toggle="collapse"]').click(function() {
222248
if (sitemap.isOpen($(this))) {
223-
// console.log("Section", $(this).data('id'), "was closed.");
224-
sitemap.closedSection($(this).data('id'));
225-
sitemap.changeIcon($(this), 'icon-folder-close');
249+
sitemap.close($(this));
226250
} else {
227-
// console.log("Section", $(this).data('id'), "was opened.");
228-
sitemap.openedSection($(this).data('id'));
229-
sitemap.changeIcon($(this), 'icon-folder-open');
251+
sitemap.open($(this));
230252
}
231253
});
232254
});

todo_ui_Revamp.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ Tasks:
33
- Move sitemap items
44
-- [BUG] After moving a node, the section_node_ids are probably wrong. This means moving a node twice won't work (though it will appear to).
55
-- It's hard visually to drop items into a section (especially if empty). (Should create obvious drop targets when you start dragging).
6-
-- Need to expand sections as you pass over them.
76
-- Need an image/section name for hover element when it leaves a parent section.
87

98
## UI Merge
109

11-
* Move/drag/drop sections
1210
* Audit/Delete/merge js/cms/sitemap.js.erb
1311
* No visual indicator of an empty section
1412
* page_editor.css/page_content_editing.css shouldn't have been deleted during the bootstrap UI merge.

0 commit comments

Comments
 (0)