Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 75 additions & 4 deletions controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,75 @@
angular.module('test', [])
.controller('testController', ['$scope', function($scope) {

}]);
(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: '<div class="swnl-numbers-container"></div>',
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 + '<br>';
}

$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);
});
}
}
};
});
}());
23 changes: 15 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,34 @@
<script type="text/javascript" src="controller.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body ng-app="test" ng-controller="testController">
<body ng-app="test" ng-controller="testController as testCtrl">
<div class="content">
<header class="controls-holder container">
<div class="numbers-holder">
<input type="number" placeholder="Min number">
<input type="number" placeholder="Max number">
<input type="number" placeholder="Min number" ng-model="testCtrl.min">
<input type="number" placeholder="Max number" ng-model="testCtrl.max">
</div>
<div class="buttons-holder">
<button>Show all numbers</button>
<button>Show even numbers</button>
<button>Show odd numbers</button>
<button ng-click="testCtrl.parity = 'both'">Show all numbers</button>
<button ng-click="testCtrl.parity = 'even'">Show even numbers</button>
<button ng-click="testCtrl.parity = 'odd'">Show odd numbers</button>
</div>
<br><br>
<div>
Parity: <strong>{{testCtrl.parity}}</strong><br>
Position: <strong>{{testCtrl.position}}</strong>
</div>
</header>
<div class="results-space container">
<div class="buttons-holder">
<button>Display on the left</button>
<button>Display on the right</button>
<button ng-click="testCtrl.position = 'left'">Display on the left</button>
<button ng-click="testCtrl.position = 'right'">Display on the right</button>
</div>
</div>


<div class="list">
<sw-number-list min="{{testCtrl.min}}" max="{{testCtrl.max}}" parity="{{testCtrl.parity}}" position="{{testCtrl.position}}"></sw-number-list>
<!-- INSERT THE NUMBERS HERE. YOU ARE ALLOWED THE MODIFY OTHER PARTS OF THE CODE -->
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ html, body {
max-width: 920px;
margin-left: auto;
margin-right: auto;
overflow-y: auto;
}

.container {
Expand All @@ -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;
}