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

Commit

Permalink
Merge pull request #1012 from krgn/add-itemSelect-option
Browse files Browse the repository at this point in the history
add itemSelect option and associated test cases to tree.js
  • Loading branch information
futuremint committed Jan 30, 2015
2 parents d07b42e + bb6bc72 commit 7937ff5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
12 changes: 10 additions & 2 deletions js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
this.$element = $(element);
this.options = $.extend({}, $.fn.tree.defaults, options);

this.$element.on('click.fu.tree', '.tree-item', $.proxy( function(ev) { this.selectItem(ev.currentTarget); } ,this));
if( this.options.itemSelect ){
this.$element.on('click.fu.tree', '.tree-item', $.proxy( function(ev) { this.selectItem(ev.currentTarget); } ,this));
}

this.$element.on('click.fu.tree', '.tree-branch-name', $.proxy( function(ev) { this.openFolder(ev.currentTarget); }, this));

if( this.options.folderSelect ){
Expand Down Expand Up @@ -147,6 +150,8 @@
},

selectItem: function (el) {
if(!this.options.itemSelect) return;

var $el = $(el);
var selData = $el.data();
var $all = this.$element.find('.tree-selected');
Expand Down Expand Up @@ -249,6 +254,8 @@
},

selectFolder: function (clickedElement) {
if(!this.options.folderSelect) return;

var $clickedElement = $(clickedElement);
var $clickedBranch = $clickedElement.closest('.tree-branch');
var $selectedBranch = this.$element.find('.tree-branch.tree-selected');
Expand Down Expand Up @@ -349,7 +356,8 @@
dataSource: function(options, callback){},
multiSelect: false,
cacheItems: true,
folderSelect: true
folderSelect: true,
itemSelect: true
};

$.fn.tree.Constructor = Tree;
Expand Down
24 changes: 24 additions & 0 deletions test/tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ define(function(require){
equal($tree.tree('selectedItems').length, 1, 'Return single selected value');
});

test("should not allow selecting items if disabled", function() {
var $tree = $(html).find('#MyTree');

$tree.tree({
dataSource: this.dataSource,
itemSelect: false
});

$tree.tree('selectItem', $tree.find('.tree-item:eq(1)'));
equal($tree.tree('selectedItems').length, 0, 'Return no value');
});

test("should not allow selecting folders if disabled", function() {
var $tree = $(html).find('#MyTree');

$tree.tree({
dataSource: this.dataSource,
folderSelect: false
});

$tree.tree('selectFolder', $tree.find('.tree-branch-name:eq(1)'));
equal($tree.tree('selectedItems').length, 0, 'Return no value');
});

test("should destroy control", function () {
var $tree = $(html).find('#MyTree');

Expand Down

0 comments on commit 7937ff5

Please sign in to comment.