-
-
+
+
+ +
+ Parity: {{testCtrl.parity}}
+ Position: {{testCtrl.position}}
+ Position: {{testCtrl.position}}
+
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 + '