Skip to main content
Code Review

Return to Question

Notice removed Draw attention by Community Bot
Bounty Ended with no winning answer by Community Bot
edited tags
Link
konijn
  • 34.2k
  • 5
  • 70
  • 267
added 1 character in body
Source Link

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?

Tweeted twitter.com/#!/StackCodeReview/status/468151632166141953
Notice added Draw attention by superluminary
Bounty Started worth 50 reputation by superluminary
added 717 characters in body
Source Link

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);
 }
 };
});
deleted 14 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
Loading
default

AltStyle によって変換されたページ (->オリジナル) /