Is it good to ceatecreate all these little helper methods, or should I be splitting my code out into smaller pieces?
Is it good to ceate all these little helper methods, or should I be splitting my code out into smaller pieces?
Is it good to create all these little helper methods, or should I be splitting my code out into smaller pieces?
Is it good to ceate all these little helper methods, or should I be splitting my code out into smaller pieces?
myApp.directive('dropdown', function () {
return {
scope: true,
link: function (scope, element) {
scope.visiblevar menu = false;element.find('ul');
var menubody = elementangular.findelement('ul''body');
var unfold = angular.element("<a href='#'><i/></a>");
element.prependvar toggleVisible = function (unfold); {
unfold scope.onmenu.visible = !scope.menu.visible;
scope.$apply('click',);
};
var unsetVisible = function () {
scope.menu.visible = !scope.visible;false;
scope.$apply();
});
var showMenu = function () {
if (scope.menu.visible) {
menu.show();
} else {
menu.hide();
}
};
var toggleChevron = function () {
var c;
if (scope.menu.visible) {
c = 'fa-caret-up';
} else {
c = 'fa-caret-down';
}
unfold.find('i').attr('class', c);
};
var escapeKey = function (e) {
if (e.which === 27) {
unsetVisible();
}
};
var chevronClick = function (e) {
toggleVisible();
e.stopPropagation();
};
element.prepend(unfold);
scope.menu = {visible: false};
unfold.on('click', chevronClick);
body.on('click', unsetVisible);
body.on('keyup', escapeKey);
scope.$watch('visible''menu.visible', showMenu);
scope.$watch('visible''menu.visible', toggleChevron);
}
};
});
myApp.directive('dropdown', function () {
return {
scope: true,
link: function (scope, element) {
scope.visible = false;
var menu = element.find('ul');
var unfold = angular.element("<a href='#'><i/></a>");
element.prepend(unfold);
unfold.on('click', function () {
scope.visible = !scope.visible;
scope.$apply();
});
var showMenu = function () {
if (scope.visible) {
menu.show();
} else {
menu.hide();
}
};
var toggleChevron = function () {
var c;
if (scope.visible) {
c = 'fa-caret-up';
} else {
c = 'fa-caret-down';
}
unfold.find('i').attr('class', c);
};
scope.$watch('visible', showMenu);
scope.$watch('visible', toggleChevron);
}
};
});
Is it good to ceate all these little helper methods, or should I be splitting my code out into smaller pieces?
myApp.directive('dropdown', function () {
return {
scope: true,
link: function (scope, element) {
var menu = element.find('ul');
var body = angular.element('body');
var unfold = angular.element("<a href='#'><i/></a>");
var toggleVisible = function () {
scope.menu.visible = !scope.menu.visible;
scope.$apply();
};
var unsetVisible = function () {
scope.menu.visible = false;
scope.$apply();
};
var showMenu = function () {
if (scope.menu.visible) {
menu.show();
} else {
menu.hide();
}
};
var toggleChevron = function () {
var c;
if (scope.menu.visible) {
c = 'fa-caret-up';
} else {
c = 'fa-caret-down';
}
unfold.find('i').attr('class', c);
};
var escapeKey = function (e) {
if (e.which === 27) {
unsetVisible();
}
};
var chevronClick = function (e) {
toggleVisible();
e.stopPropagation();
};
element.prepend(unfold);
scope.menu = {visible: false};
unfold.on('click', chevronClick);
body.on('click', unsetVisible);
body.on('keyup', escapeKey);
scope.$watch('menu.visible', showMenu);
scope.$watch('menu.visible', toggleChevron);
}
};
});