I have a function that returns an array of colors:
default: function () { // Get our colours array var colours = [service.kits.kit.colour1, service.kits.kit.colour2, service.kits.kit.colour3]; // If our third colour is blank if (!colours[2]) { // Is our first or second colour white var isWhite = colours[0] === 'ffffff' || colours[1] === 'ffffff'; // Set our thrid colour colours[2] = isWhite ? 'a6a6a6' : 'ffffff'; } // Return our colours return colours; },
which I then use like this:
// Checks to see what colour was selected for Colour 1 and 2 and sets the 3rd colour var setSelectedColours = function () { // Get our default colours var colours = service.colours.default(); // Apply to our selected colours service.colours.selected = angular.copy(colours); service.colours.selectedLeisure = angular.copy(colours); };
I have a directive that I use to replace colors, which looks like this:
.directive('colourSwapper', function () { return { restrict: 'A', controller: 'ColourSwapperController', link: function (scope, element, attrs, controller) { // Get to see if we are working with the leisure colours or not var leisurewear = attrs.hasOwnProperty('leisurewear'); // Create our function element.bind('click', function (e) { // Apply the scope scope.$apply(function () { // Use the algorithm for leisurwear items controller.swapColours(leisurewear); }); // Prevent any other actions e.preventDefault(); }); } }; })
pretty straight forward. The function for replacing colors is held in my controller, for example:
.controller('ColourSwapperController', ['ConfiguratorService', function (shared) { var self = this;
Now it is a little more complicated. There are 3 colors, they can be arranged so that color 3 can only be in position 1 and 2, but colors 1 and 2 can be in any position.
If the colors are intended for leisure, then the same rule applies , but a different color is placed between each step at position 0 (if this color is not already selected and is in position 1 or 2).
My function works fine, but it is linear in that if the button is pressed, it will always go in one direction. I would like it to go in two directions, so there is a back and forth button that cancels the function.
Does anyone know how I can do this with my current function?