Skip to content

Commit 78e9819

Browse files
Ben RubinBen Rubin
authored andcommitted
small style change
stop propagation of events use function to get tree controller. This is needed because sub nested items to not have access to the tree until they are rendered.
1 parent 0b529a7 commit 78e9819

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/js/branch.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ var BRANCH_ARROW_TEMPLATE = angular.element('<div class="md-branch-icon-containe
1818
function branchDirective($parse, $document, $compile) {
1919
return {
2020
restrict: 'E',
21-
multiElement: true,
21+
// multiElement: true,
2222
require: ['mdBranch', '?^mdBranch', '?^mdTree', '?^mdBranchTemplates'],
2323
priority: 1000,
2424
terminal: true,
2525
transclude: 'element',
26-
$$tlb: true,
26+
// $$tlb: true,
2727
compile: compile,
2828
controller: 'BranchController'
2929
};
@@ -214,7 +214,8 @@ function branchDirective($parse, $document, $compile) {
214214
};
215215

216216
updateScope(scope, index);
217-
scope.$element = clone; // attach element to scope so it can be acced in controller
217+
scope.$element = clone; // attach element to scope so it can be accessed in controller
218+
218219
parentNode.appendChild(clone[0]);
219220
});
220221
return block;
@@ -242,12 +243,13 @@ function branchDirective($parse, $document, $compile) {
242243

243244
// --- Controller ---
244245

245-
246+
var cid = 0;
246247
/*@ngInject*/
247248
function branchController($scope, $mdUtil, $animateCss) {
248249
/*jshint validthis: true*/
249250
var vm = this;
250251
var isOpen = false;
252+
var _id = cid++;
251253

252254
// injected $element is holds refernce to the comment. heres how to get arround this
253255
var $element = $scope.$element;
@@ -273,29 +275,20 @@ function branchController($scope, $mdUtil, $animateCss) {
273275
}
274276
});
275277

276-
// register branch if tree controller is accesable
277-
function registerBranch() {
278-
vm.treeCtrl.registerBranch(vm.treeCtrl.hashGetter($scope[$scope.repeatName]), {
279-
setSelected: setSelected
280-
});
281-
setSelected(vm.treeCtrl.selected[vm.treeCtrl.hashGetter($scope[$scope.repeatName])] !== undefined);
282-
}
283-
284-
285278

286279
function handleClick(e) {
287280
// toggel branch
288281
if (e.target.classList.contains('md-branch-icon-container')) {
289282
toggleBranchClick(e);
283+
e.stopPropagation();
290284
return;
291285
}
292286

293287
// handle select
294288
var isSelect = $element.attr('select') !== undefined;
295289
if (isSelect && branchContainsElement(e.target)) {
296290
var selected = $element.attr('selected') !== undefined;
297-
findTree();
298-
vm.treeCtrl.toggleSelect(!selected, vm.treeCtrl.hashGetter($scope[$scope.repeatName]), $scope[$scope.repeatName]);
291+
getTreeCtrl().toggleSelect(!selected, getTreeCtrl().hashGetter($scope[$scope.repeatName]), $scope[$scope.repeatName]);
299292

300293
$element.attr('selected', !selected);
301294
if (e.target.classList.contains('md-container')) { // clicked on checkbox
@@ -304,9 +297,10 @@ function branchController($scope, $mdUtil, $animateCss) {
304297
// if multiple is enabled add this to selection
305298
// otherwise single select
306299
}
307-
300+
e.stopPropagation();
308301
} else {
309302
toggleBranchClick(e);
303+
e.stopPropagation();
310304
}
311305
}
312306

@@ -339,7 +333,7 @@ function branchController($scope, $mdUtil, $animateCss) {
339333
function open(noAnimation) {
340334
if (isOpen) { return; }
341335
isOpen = true;
342-
findTree();
336+
// findTree();
343337
reconnectScope();
344338
vm.startWatching();
345339
$element.toggleClass('md-no-animation', noAnimation || false);
@@ -389,22 +383,30 @@ function branchController($scope, $mdUtil, $animateCss) {
389383

390384
// nested, nested branches cannot access the tree controller due to their parents not being added to the dom.
391385
// To fix this we will walk the dom to find the tree and grab its controller
392-
function findTree() {
393-
if (vm.treeCtrl) { return; }
386+
function getTreeCtrl() {
387+
if (vm.treeCtrl) { return vm.treeCtrl; }
394388

395389
var parent = $element[0].parentNode;
396390
while (parent && parent !== document.body) {
397391
if (parent.nodeName === 'MD-TREE') {
398392
vm.treeCtrl = angular.element(parent).controller('mdTree');
399393
registerBranch();
400-
return;
394+
return vm.treeCtrl;
401395
}
402396
parent = parent.parentNode;
403397
}
404398

405399
console.error('`<md-branch>` element is not nested in a `<md-tree>` element. Selection will not work');
406400
}
407401

402+
// register branch if tree controller is accesable
403+
function registerBranch() {
404+
vm.treeCtrl.registerBranch(vm.treeCtrl.hashGetter($scope[$scope.repeatName]), {
405+
setSelected: setSelected
406+
});
407+
setSelected(vm.treeCtrl.selected[vm.treeCtrl.hashGetter($scope[$scope.repeatName])] !== undefined);
408+
}
409+
408410

409411
// remove scope from parents reference so it is not used in digest
410412
function disconnectScope() {

src/style-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ md-branch.md-THEME_NAME-theme {
4040
&[selected] > .md-branch-inner {
4141
.checkbox-icon {
4242
border-color: '{{foreground-2}}';
43-
background-color: '{{primary-color}}';
43+
background-color: '{{primary-color-0.87}}';
4444

4545
&:after {
46-
border-color: '{{primary-contrast}}';
46+
border-color: '{{primary-contrast-0.87}}';
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)