diff --git a/controller.js b/controller.js index 9354734..5657118 100644 --- a/controller.js +++ b/controller.js @@ -1,4 +1,75 @@ -angular.module('test', []) -.controller('testController', ['$scope', function($scope) { - -}]); \ No newline at end of file +(function() { + 'use strict'; + angular.module('test', []) + .controller('testController', ['$scope', function($scope) { + var testCtrl = this; + testCtrl.parity = 'both'; + testCtrl.position = 'left'; + }]) + .directive('swNumberList', function() { + return { + template: '
', + restrict: 'E', + scope: { + min: '@', + max: '@', + parity: '@', + position: '@' + }, + link: function(scope, element, attrs) { + var $numBox = element.children('div'), + listNumbers = function () { + var min = parseInt(attrs.min, 10), + max = parseInt(attrs.max, 10), + parity = attrs.parity || 'both', + displayNumbers = function() { + var increment, mod2Min, mod2Max, i, html = ''; + increment = 1; + if (parity !== 'both') { + increment = 2; + mod2Min = min%2; + mod2Max = max%2; + if ((mod2Min === 0 && parity === 'odd') || (mod2Min > 0 && parity === 'even')) { + min += 1; + } + if ((mod2Max === 0 && parity === 'odd') || (mod2Max > 0 && parity === 'even')) { + max -= 1; + } + } + + for (i=min; i<=max; i+=increment) { + html += i + '
'; + } + + $numBox.html(html); + }; + + $numBox.empty(); + + if (isNaN(min) || isNaN(max)) { + return; + } + + if (min > max) { + $numBox.html('Min value must be greater than Max value.'); + return; + } + + parity = ['both', 'odd', 'even'].indexOf(parity.toLowerCase()) >= 0 ? parity.toLowerCase() : 'both'; + + displayNumbers(); + }; + + if ($numBox.length > 0) { + attrs.$observe('min', listNumbers); + attrs.$observe('max', listNumbers); + attrs.$observe('parity', listNumbers); + attrs.$observe('position', function(value) { + value = ['left', 'right'].indexOf(value.toLowerCase()) >= 0 ? value.toLowerCase() : 'left'; + $numBox.css('text-align', value); + }); + } + } + }; + }); +}()); \ No newline at end of file diff --git a/index.html b/index.html index 4079a43..60d8573 100644 --- a/index.html +++ b/index.html @@ -5,27 +5,34 @@ - +
- - + +
- - - + + + +
+

+
+ Parity: {{testCtrl.parity}}
+ Position: {{testCtrl.position}}
- - + +
+
+
diff --git a/styles.css b/styles.css index 49ac741..0aaff23 100644 --- a/styles.css +++ b/styles.css @@ -10,6 +10,7 @@ html, body { max-width: 920px; margin-left: auto; margin-right: auto; + overflow-y: auto; } .container { @@ -26,4 +27,12 @@ html, body { .buttons-holder { float: right; +} + +.swnl-numbers-container { + padding: 10px; + margin: 10px; + color: white; + font-size: 1.5em; + font-weight: bold; } \ No newline at end of file