Skip to content

Commit d93cbf7

Browse files
Bryce JohnsonBryce Johnson
Bryce Johnson
authored and
Bryce Johnson
committed
last commit: 2014-03-04
1 parent 5e72e25 commit d93cbf7

File tree

9 files changed

+198
-75
lines changed

9 files changed

+198
-75
lines changed

css/build/prefixed/style.css

+8-1
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,18 @@ table {
347347
/*** FLEXBOX ****/
348348
/* Layout rules divide the page into sections, such as 'header', 'footer', 'sidebar' and 'main content'. Layouts hold one or more modules together. This is the time to use ID's and to set width, float, and height properties. Generally, a layout style only has a single selector: a single ID or class name. */
349349
.container {
350-
margin: 4em auto; }
350+
min-height: 500px;
351+
float: right; }
351352

352353
label {
353354
display: block; }
354355

356+
input {
357+
width: 50px; }
358+
359+
.flex-item {
360+
border-radius: 5px; }
361+
355362
/*
356363
357364
%font1 {

css/build/style.css

+8-1
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,18 @@ table {
347347
/*** FLEXBOX ****/
348348
/* Layout rules divide the page into sections, such as 'header', 'footer', 'sidebar' and 'main content'. Layouts hold one or more modules together. This is the time to use ID's and to set width, float, and height properties. Generally, a layout style only has a single selector: a single ID or class name. */
349349
.container {
350-
margin: 4em auto; }
350+
min-height: 500px;
351+
float: right; }
351352

352353
label {
353354
display: block; }
354355

356+
input {
357+
width: 50px; }
358+
359+
.flex-item {
360+
border-radius: 5px; }
361+
355362
/*
356363
357364
%font1 {

gruntfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module.exports = function(grunt) {
7676
grunt.loadNpmTasks('grunt-contrib-sass');
7777
grunt.loadNpmTasks('grunt-typescript');
7878
grunt.loadNpmTasks('grunt-shell');
79+
grunt.loadNpmTasks('grunt-karma');
7980

8081
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
8182
grunt

index.html

+22-13
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
$(function() {
1717

1818
var flexboxApp = new flexbox.view.FlexContainer();
19-
console.log(flexboxApp);
2019
ko.applyBindings(flexboxApp);
21-
22-
20+
console.log(flexboxApp);
21+
2322
});
23+
24+
2425
</script>
2526

2627
</head>
@@ -53,6 +54,17 @@
5354

5455
</div>
5556

57+
<div data-bind="visible:true"class="item-defaults">
58+
<h2>item defaults</h2>
59+
<button data-bind="click:resetItemProps, text:defaultBtnText">reset item defaults</button>
60+
<label for="">flex-grow: <input type="text" data-bind="value:iPropsDefault.flexGrow"></label>
61+
<label for="">flex-shrink: <input type="text" data-bind="value:iPropsDefault.flexShrink"></label>
62+
<label for="">flex-basis<input type="text" data-bind="value:iPropsDefault.flexBasis"></label>
63+
<label for="">align-self: <select type="text" data-bind="options:alignSelfOptions, value:iPropsDefault.alignSelf"></select></label>
64+
65+
66+
67+
</div>
5668

5769
<div class="code-box">
5870
<code>
@@ -72,11 +84,11 @@
7284
<code>
7385
<pre>
7486
.flex-items-default {
75-
flex-grow: <span data-bind="text:iPropsCurrent.flexGrow"></span>
76-
flex-shrink: <span data-bind="text:iPropsCurrent.flexShrink"></span>
77-
flex-basis: <span data-bind="text:iPropsCurrent.flexBasis"></span>
78-
order: <span data-bind="text:iPropsCurrent.order"></span>
79-
align-self: <span data-bind="text:iPropsCurrent.alignSelf"></span>
87+
flex-grow: <span data-bind="text:iPropsDefault.flexGrow"></span>
88+
flex-shrink: <span data-bind="text:iPropsDefault.flexShrink"></span>
89+
flex-basis: <span data-bind="text:iPropsDefault.flexBasis"></span>
90+
order: <span data-bind="text:iPropsDefault.order"></span>
91+
align-self: <span data-bind="text:iPropsDefault.alignSelf"></span>
8092

8193
}
8294
</pre>
@@ -86,7 +98,7 @@
8698
</div>
8799

88100
<script type="template/knockout" id="flex-list">
89-
<div data-bind="style:{
101+
<div class="flex-item" data-bind="style:{
90102
backgroundColor:iPropsCurrent.backgroundColor,
91103
height:iPropsCurrent.height,
92104
margin:iPropsCurrent.margin,
@@ -100,7 +112,7 @@
100112
<label for="">flex-shrink: <input type="text" data-bind="value:iPropsCurrent.flexShrink"></label>
101113
<label for="">flex-basis: <input type="text" data-bind="value:iPropsCurrent.flexBasis"></label>
102114
<label for="">align-self: <input type="text" data-bind="value:iPropsCurrent.alignSelf"></label>
103-
115+
<a href="#" data-bind="click:destroySelf">destroy self</a>
104116

105117
</div>
106118
</script>
@@ -109,8 +121,5 @@
109121

110122

111123

112-
113-
114-
115124
</body>
116125
</html>

js/main.js

+59-23
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@ var flexbox;
33
(function (_model) {
44
var FlexItem = (function () {
55
function FlexItem(model, index) {
6-
this.index = index;
7-
8-
this.iPropsDefault = {
9-
order: "1",
10-
flexGrow: "1",
11-
flexShrink: "0",
12-
flexBasis: "300px",
13-
alignSelf: "center",
14-
width: "300px",
15-
height: "300px",
16-
backgroundColor: "tomato",
17-
margin: "10px"
18-
};
19-
6+
this.index = ko.observable(index);
7+
this.model = model;
8+
console.log(model);
209
this.iPropsCurrent = {
2110
order: ko.observable("1"),
2211
flexGrow: ko.observable("1"),
@@ -29,6 +18,20 @@ var flexbox;
2918
margin: ko.observable("10px")
3019
};
3120
}
21+
FlexItem.prototype.resetProps = function () {
22+
var currentProps = this.iPropsCurrent;
23+
var newProps = this.model.iPropsDefault;
24+
currentProps.flexGrow(newProps.flexGrow());
25+
currentProps.flexShrink(newProps.flexShrink());
26+
currentProps.flexBasis(newProps.flexBasis());
27+
currentProps.alignSelf(newProps.alignSelf());
28+
};
29+
30+
FlexItem.prototype.destroySelf = function () {
31+
var index = parseInt(this.index(), 10);
32+
console.log(index);
33+
this.model.destroyItem(index);
34+
};
3235
return FlexItem;
3336
})();
3437
_model.FlexItem = FlexItem;
@@ -40,14 +43,29 @@ var flexbox;
4043
(function (view) {
4144
var FlexContainer = (function () {
4245
function FlexContainer() {
43-
this.items = ko.observableArray([
44-
new flexbox.model.FlexItem(this, 1),
45-
new flexbox.model.FlexItem(this, 2)
46-
]);
46+
this.items = ko.observableArray([]);
4747

48-
this.codeBox = ko.observableArray([
49-
new flexbox.view.CodeBox(this, 1)
50-
]);
48+
this.iPropsDefault = {
49+
order: ko.observable("1"),
50+
flexGrow: ko.observable("1"),
51+
flexShrink: ko.observable("1"),
52+
flexBasis: ko.observable("300px"),
53+
alignSelf: ko.observable("center"),
54+
width: ko.observable("300px"),
55+
height: ko.observable("300px"),
56+
backgroundColor: "blue",
57+
margin: "10px"
58+
};
59+
60+
this.defaultBtnText = ko.computed(function () {
61+
var def = this.iPropsDefault;
62+
63+
if (def.flexGrow() === '1' && def.flexShrink() === '1' && def.flexBasis() === "300px" && def.alignSelf() === "center") {
64+
return "reset all items";
65+
} else {
66+
return "update item defaults";
67+
}
68+
}, this);
5169

5270
this.cPropsDefault = {
5371
display: "flex",
@@ -74,24 +92,42 @@ var flexbox;
7492
this.justifyContentOptions = ['flex-start', 'flex-end', 'center', 'space-between', 'space-around'];
7593
this.alignItemsOptions = ['flex-start', 'flex-end', 'center', 'baseline', 'stretch'];
7694
this.alignContentOptions = ['flex-start', 'flex-end', 'center', 'space-between', 'space-around', 'stretch'];
95+
this.alignSelfOptions = ['auto', 'flex-start', 'flex-end', 'center', 'baseline', 'stretch', 'inherit'];
7796
}
7897
FlexContainer.prototype.newItem = function () {
7998
var index = this.getItemIndex();
8099
var newItem = new flexbox.model.FlexItem(this, index);
81100
this.items.push(newItem);
82-
console.log('new item added');
83101
};
84102

85103
FlexContainer.prototype.oneLessItem = function () {
86104
this.items.pop();
87-
console.log('newest item removed');
88105
};
89106

90107
FlexContainer.prototype.getItemIndex = function () {
91108
var currentLength = this.items().length;
92109
return currentLength + 1;
93110
};
94111

112+
FlexContainer.prototype.resetItemProps = function () {
113+
var array = this.items();
114+
for (var i = 0; i < array.length; i++) {
115+
array[i].resetProps();
116+
}
117+
};
118+
FlexContainer.prototype.destroyItem = function (index) {
119+
var self = this;
120+
self.items.splice((index - 1), 1);
121+
(function () {
122+
var array = self.items();
123+
for (var i = 0; i < array.length; i++) {
124+
var newIndex = i + 1;
125+
var stringIndex = newIndex.toString();
126+
array[i].index(stringIndex);
127+
}
128+
})();
129+
};
130+
95131
FlexContainer.prototype.resetContainerProps = function () {
96132
};
97133
return FlexContainer;

package.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
"grunt-contrib-jshint": "~0.8.0",
1212
"grunt-autoprefixer": "~0.6.4",
1313
"grunt-typescript": "~0.2.8",
14-
"grunt-shell": "~0.6.4"
14+
"grunt-shell": "~0.6.4",
15+
"karma-chrome-launcher": "~0.1.2",
16+
"karma-firefox-launcher": "~0.1.3",
17+
"karma-script-launcher": "~0.1.0",
18+
"karma-html2js-preprocessor": "~0.1.0",
19+
"karma-jasmine": "~0.1.5",
20+
"requirejs": "~2.1.11",
21+
"karma-requirejs": "~0.2.1",
22+
"karma-coffee-preprocessor": "~0.1.3",
23+
"karma-phantomjs-launcher": "~0.1.2",
24+
"karma": "~0.10.9",
25+
"grunt-karma": "~0.6.2"
1526
}
1627
}

scss/global/_layout.scss

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
/* Layout rules divide the page into sections, such as 'header', 'footer', 'sidebar' and 'main content'. Layouts hold one or more modules together. This is the time to use ID's and to set width, float, and height properties. Generally, a layout style only has a single selector: a single ID or class name. */
22

33
.container {
4-
5-
margin:4em auto;
6-
4+
min-height:500px;
5+
float:right;
76
}
87

98
label {
109
display:block;
1110
}
11+
12+
input {
13+
14+
width:50px;
15+
16+
}
17+
18+
.flex-item {
19+
20+
border-radius:5px;
21+
22+
}

ts/model/Item.ts

+22-20
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,14 @@ module flexbox {
55
export class FlexItem {
66

77
model: any;
8-
index: number;
9-
iPropsDefault: {};
10-
iPropsCurrent: {};
11-
12-
constructor(model: any, index: number) {
13-
14-
this.index = index;
15-
16-
this.iPropsDefault = {
17-
order: "1",
18-
flexGrow: "1",
19-
flexShrink: "0",
20-
flexBasis: "300px",
21-
alignSelf: "center",
22-
width: "300px",
23-
height: "300px",
24-
backgroundColor: "tomato",
25-
margin: "10px"
26-
};
8+
index: any;
9+
iPropsCurrent: any;
10+
11+
constructor(model: any, index: any) {
2712

13+
this.index = ko.observable(index);
14+
this.model = model;
15+
console.log(model);
2816
this.iPropsCurrent = {
2917
order: ko.observable("1"),
3018
flexGrow: ko.observable("1"),
@@ -38,11 +26,25 @@ module flexbox {
3826
};
3927

4028

41-
//flexbox within a flexbox?
4229

30+
}
4331

32+
resetProps(): void {
33+
var currentProps = this.iPropsCurrent;
34+
var newProps = this.model.iPropsDefault;
35+
currentProps.flexGrow(newProps.flexGrow());
36+
currentProps.flexShrink(newProps.flexShrink());
37+
currentProps.flexBasis(newProps.flexBasis());
38+
currentProps.alignSelf(newProps.alignSelf());
39+
}
4440

41+
destroySelf(): void {
42+
var index = parseInt(this.index(),10);
43+
console.log(index);
44+
this.model.destroyItem(index);
45+
4546
}
47+
4648
}
4749

4850
}

0 commit comments

Comments
 (0)