This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
83 lines (74 loc) · 2.22 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var app = window.app = angular.module('app', [])
app.controller('AppCtrl', ['$scope', 'Range', 'RollDices', function ($scope, Range, RollDices) {
$scope.Range = Range
$scope.amountOfDices = 1
$scope.rolls = []
$scope.addRoll = function () {
var dices = RollDices($scope.amountOfDices)
var successes = dices.filter(function (d) {
return d >= 5
}).length
var slip = $scope.amountOfDices / 2 <= dices.filter(function (d) {
return d == 1
}).length
var crit = slip && successes == 0
$scope.rolls.unshift({
dices: dices,
successes: successes,
slip: slip,
crit: crit,
date: Date.now()
})
$('#amountOfDices').focus();
}
$scope.diceClass = function (value) {
var good = {
'bg-success': true
}
var bad = {
'bg-danger': true
}
return value >= 5 ? good : value == 1 ? bad : 0
}
}])
app.factory('Range', [function () {
return function (min, max, step) {
step = step || 1
var input = []
for (var i = min; i <= max; i = i + step) {
input.push(i)
}
return input
}
}])
app.factory('RollDices', ['Random', function (Random) {
return function (amountOfDices) {
var dices = []
for (var i = 0; i < amountOfDices; i++) {
dices.push(Random(1,6))
}
return dices
}
}])
app.factory('Random', [function () {
return function randomIntFromInterval(min,max) {
return Math.floor(Math.random()*(max-min+1)+min)
}
}])
// Sidenav affixing
setTimeout(function () {
var $sideBar = $('#sidebar')
$sideBar.affix({
offset: {
top: function () {
var offsetTop = $sideBar.offset().top
var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10)
var navOuterHeight = $('.bs-docs-nav').height()
return (this.top = offsetTop - navOuterHeight - sideBarMargin)
},
// bottom: function () {
// return (this.bottom = $('.bs-docs-footer').outerHeight(true))
// }
}
})
}, 100)