Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:ExactTarget/fuelux into radio
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeard committed Apr 13, 2015
2 parents 01eee29 + cd25eff commit 5c32d44
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define(function (require) {
};

// programmatically injecting this is so much easier than writing the html by hand 376 times...
$('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id], dt[id]').each(function(i){
$('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id], dt[id]').each(function (i) {
$(this).prepend(['<a class="header-anchor" href="#', this.id, '"><small><span class="glyphicon glyphicon-link"></span></a></small> '].join(''));
});

Expand Down Expand Up @@ -984,7 +984,7 @@ define(function (require) {
log('Updated Event: ', selected);
log($('#myTree1').tree('selectedItems'));
});
$('#myTree1').on('opened.fu.tree', function (event, parentData) {
$('#myTree1').on('disclosedFolder.fu.tree', function (event, parentData) {
log('Opened Event, parent data: ', parentData);
});
$('#myTree1').on('closed.fu.tree', function (event, parentData) {
Expand Down
26 changes: 7 additions & 19 deletions js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,9 @@
});
},

openFolder: function openFolder(el, ignoreRedundantOpens) {
discloseFolder: function discloseFolder(el) {
var $el = $(el);

//don't break the API :| (make this functionally the same as calling 'toggleFolder')
if (!ignoreRedundantOpens && $el.find('.glyphicon-folder-open').length && !this.options.ignoreRedundantOpens) {
this.closeFolder(el);
}

var $branch = $el.closest('.tree-branch');
var $treeFolderContent = $branch.find('.tree-branch-children');
var $treeFolderContentFirstChild = $treeFolderContent.eq(0);
Expand All @@ -238,7 +233,7 @@
this.populate($treeFolderContent);
}

this.$element.trigger('opened.fu.tree', $branch.data());
this.$element.trigger('disclosedFolder.fu.tree', $branch.data());
},

closeFolder: function closeFolder(el) {
Expand Down Expand Up @@ -267,7 +262,7 @@
var $el = $(el);

if ($el.find('.glyphicon-folder-close').length) {
this.openFolder(el);
this.discloseFolder(el);
} else if ($el.find('.glyphicon-folder-open').length) {
this.closeFolder(el);
}
Expand Down Expand Up @@ -384,8 +379,8 @@
self.$element.on('loaded.fu.tree', openReported);

// open all visible folders
self.$element.find(".tree-branch:not('.tree-open, .hidden, .hide')").each(function triggerOpen() {
self.openFolder($(this).find('.tree-branch-header'), true);
self.$element.find(".tree-branch:not('.tree-open, .hide')").each(function triggerOpen() {
self.discloseFolder($(this).find('.tree-branch-header'));
});
},

Expand Down Expand Up @@ -470,6 +465,8 @@

//alias for collapse for consistency. "Collapse" is an ambiguous term (collapse what? All? One specific branch?)
Tree.prototype.closeAll = Tree.prototype.collapse;
//alias for backwards compatibility because there's no reason not to.
Tree.prototype.openFolder = Tree.prototype.discloseFolder;

// TREE PLUGIN DEFINITION

Expand Down Expand Up @@ -501,15 +498,6 @@
folderSelect: true,
itemSelect: true,
/*
* Calling "open" on something, should do that. However, the current API
* instead treats "open" as a "toggle" and will close a folder that is open
* if you call `openFolder` on it. Setting `ignoreRedundantOpens` to `true`
* will make the folder instead ignore the redundant call and stay open.
* This allows you to fix the API until 3.7.x when we can deprecate the switch
* and make `openFolder` behave correctly by default.
*/
ignoreRedundantOpens: false,
/*
* How many times `discloseAll` should be called before a stopping and firing
* an `exceededDisclosuresLimit` event. You can force it to continue by
* listening for this event, setting `ignore-disclosures-limit` to `true` and
Expand Down
5 changes: 1 addition & 4 deletions less/checkbox.less
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@
color: @text-color;
color: rgb(91, 157, 217);
cursor: pointer;
outline-color: rgb(91, 157, 217);
outline-offset: -2px;
outline-style: auto;
outline-width: 5px;
box-shadow: inset 0px 0px 2px 1px rgb(91, 157, 217), 0px 0px 5px 0px rgb(91, 157, 217);
}

&.highlight {
Expand Down
29 changes: 26 additions & 3 deletions test/tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ define(function (require) {
equal(defaults.cacheItems, true, 'cacheItems defaults to true');
equal(defaults.folderSelect, true, 'folderSelect defaults to true');
equal(defaults.itemSelect, true, 'itemSelect defaults to true');
equal(defaults.ignoreRedundantOpens, false, 'ignoreRedundantOpens defaults to false');
equal(defaults.disclosuresUpperLimit, 0, 'disclosuresUpperLimit defaults to 0');
ok(defaults.dataSource, 'dataSource exists by default');
});
Expand Down Expand Up @@ -171,7 +170,7 @@ define(function (require) {
});

$selNode = $tree.find('.tree-branch:eq(1)');
$tree.tree('openFolder', $selNode.find('.tree-branch-name'));
$tree.tree('discloseFolder', $selNode.find('.tree-branch-name'));
equal($selNode.find('.tree-branch-children > li').length, 8, 'Folder has been populated with items/sub-folders');

$tree = $(html).find('#MyTreeSelectableFolder');
Expand All @@ -182,7 +181,7 @@ define(function (require) {
});

$selNode = $tree.find('.tree-branch:eq(1)');
$tree.tree('openFolder', $selNode.find('.tree-branch-header'));
$tree.tree('discloseFolder', $selNode.find('.tree-branch-header'));
equal($selNode.find('.tree-branch-children > li').length, 4, 'Folder has been populated with sub-folders');
});

Expand Down Expand Up @@ -266,6 +265,30 @@ define(function (require) {
equal($tree.tree('selectedItems').length, 0, 'Return no value');
});

test('folders should open and close correctly', function () {
var $tree = $(html).find('#MyTree');

$tree.tree({
dataSource: this.dataSource
});

var $targetBranch = $($tree.find('.tree-branch')[0]);

equal($targetBranch.hasClass('tree-open'), false, 'Branch starts closed');
$tree.tree('discloseFolder', $targetBranch);
equal($targetBranch.hasClass('tree-open'), true, 'discloseFolder opens folder');
$tree.tree('discloseFolder', $targetBranch);
equal($targetBranch.hasClass('tree-open'), true, 'redundant discloseFolder calls leaves folder open');
$tree.tree('closeFolder', $targetBranch);
equal($targetBranch.hasClass('tree-open'), false, 'closeFolder closes folder');
$tree.tree('closeFolder', $targetBranch);
equal($targetBranch.hasClass('tree-open'), false, 'redundant closeFolder calls leaves folder closed');
$tree.tree('toggleFolder', $targetBranch);
equal($targetBranch.hasClass('tree-open'), true, 'toggleFolder on closed folder opens folder');
$tree.tree('toggleFolder', $targetBranch);
equal($targetBranch.hasClass('tree-open'), false, 'toggleFolder on open folder closes folder');
});

asyncTest("should disclose visible folders", function () {
var $tree = $('body').find('#MyTree');

Expand Down

0 comments on commit 5c32d44

Please sign in to comment.