Skip to content

Commit cef90f9

Browse files
author
Adem
committed
latest
1 parent 354facf commit cef90f9

File tree

3 files changed

+120
-31
lines changed

3 files changed

+120
-31
lines changed

gulpfile.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// variables
2+
var jsBuildName = 'stack-up.js';
3+
4+
var coffeeSourcePath = 'assets/coffee/';
5+
var coffeeSources = [
6+
'num',
7+
'utils',
8+
];
9+
10+
function coffeeSourcesArray() {
11+
return coffeeSources.map(function(coffee) {
12+
return coffeeSourcePath + coffee + '.coffee';
13+
});
14+
}
15+
16+
// Gulp object declarations.
17+
var gulp = require('gulp');
18+
19+
var coffee = require('gulp-coffee');
20+
var coffeeConfig = {
21+
bare: true
22+
};
23+
24+
var concat = require('gulp-concat');
25+
26+
var sass = require('gulp-sass');
27+
var sassConfig = {
28+
outputStyle: 'compressed'
29+
};
30+
31+
var uglify = require('gulp-uglify');
32+
var uglifyConfig = {
33+
preserveComments: 'license'
34+
};
35+
36+
var util = require('gulp-util');
37+
38+
// Gulp tasks.
39+
gulp.task('default', function() {});
40+
41+
gulp.task('coffee', function() {
42+
gulp.src(coffeeSourcesArray())
43+
.pipe(coffee(coffeeConfig).on('error', util.log))
44+
.pipe(concat(jsBuildName).on('error', util.log))
45+
.pipe(uglify(uglifyConfig).on('error', util.log))
46+
.pipe(gulp.dest('build/assets/js'));
47+
});
48+
49+
gulp.task('sass', function() {
50+
gulp.src('assets/sass/**/*.sass')
51+
.pipe(sass(sassConfig).on('error', util.log))
52+
.pipe(gulp.dest('build/assets/css'));
53+
});
54+
55+
gulp.task('watch', function() {
56+
gulp.watch('assets/sass/**/*.sass', ['sass']);
57+
gulp.watch(coffeeSourcesArray(), ['coffee']);
58+
});

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "stack-up",
3+
"author": "Andrew Prasetya",
4+
"version": "1.0.0",
5+
"description": "A simple and fast JavaScript plugin to help you create fixed-width, variable-height grid layout.",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/heyadem/stack-up.git"
9+
},
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/heyadem/stack-up/issues"
13+
},
14+
"homepage": "https://github.com/heyadem/stack-up#readme",
15+
"devDependencies": {
16+
"gulp": "*",
17+
"gulp-coffee": "^2.3.2",
18+
"gulp-concat": "^2.6.0",
19+
"gulp-htmlmin": "^2.0.0",
20+
"gulp-sass": "^2.3.2",
21+
"gulp-uglify": "^2.0.0",
22+
"gulp-util": "^3.0.7"
23+
}
24+
}

stack-up.coffee

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
# Licensed under the MIT license - http://opensource.org/licenses/MIT
22
# Copyright (C) 2016 Andrew Prasetya
3+
# Version: Thu 6 Oct 12:44:15 2016
34

45
class @StackUp
56

67
containerElement: undefined
7-
itemElements: undefined
8-
containerHeight: 0
9-
containerWidth: 0
10-
items: [] # format: [index][item, itemHeight, left, top]
11-
numberOfColumns: 0
12-
boundary: height: 0, width: 0
8+
itemElements : undefined
9+
containerHeight : 0
10+
containerWidth : 0
11+
items : [] # format: [index][item, itemHeight, left, top]
12+
numberOfColumns : 0
13+
boundary : height: 0, width: 0
1314

1415
config:
15-
containerSelector: undefined
16-
itemsSelector: undefined
17-
boundary: window
18-
columnWidth: 320
19-
gutter: 18
20-
isFluid: false
21-
layout: 'ordinal'
22-
numberOfColumns: 3
16+
containerSelector : undefined
17+
itemsSelector : undefined
18+
boundary : window
19+
columnWidth : 320
20+
gutter : 18
21+
isFluid : false
22+
layout : 'ordinal'
23+
numberOfColumns : 3
2324
resizeDebounceDelay: 350
2425
moveItem: (item, left, top, callback) ->
2526
item.style.left = left + 'px'
26-
item.style.top = top + 'px'
27+
item.style.top = top + 'px'
2728
callback()
2829
scaleContainer: (container, width, height, callback) ->
2930
container.style.height = height + 'px'
30-
container.style.width = width + 'px'
31+
container.style.width = width + 'px'
3132
callback()
3233

3334
constructor: (properties) ->
@@ -36,10 +37,10 @@ class @StackUp
3637
initialize: ->
3738
window.addEventListener 'resize', @resizeHandler
3839
@boundaryUpdate()
39-
# Update grid selectors. - reset
40+
# update grid selectors. - reset
4041
@updateSelectors()
4142
@populateItems()
42-
# Update grid selectors. - stacking
43+
# update grid selectors. - stacking
4344
@updateNumberOfColumns()
4445
@applyLayout()
4546
@draw()
@@ -48,12 +49,13 @@ class @StackUp
4849
if @config.boundary isnt window
4950
style = @config.boundary.currentStyle || window.getComputedStyle(@config.boundary)
5051
horizontalPaddings = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight)
51-
verticalPaddings = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom)
52-
@boundary.height = @config.boundary.offsetHeight - verticalPaddings
53-
@boundary.width = @config.boundary.offsetWidth - horizontalPaddings
52+
verticalPaddings = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom)
53+
@boundary.height = @config.boundary.offsetHeight - verticalPaddings
54+
@boundary.width = @config.boundary.offsetWidth - horizontalPaddings
5455
else
5556
@boundary.height = window.innerHeight
56-
@boundary.width = window.innerWidth
57+
@boundary.width = window.innerWidth
58+
this
5759

5860
resizeDebounceTimeout: undefined
5961
resizeDebounce: (fn, delay) ->
@@ -67,16 +69,18 @@ class @StackUp
6769
@boundaryUpdate()
6870
@resizeDebounce @resizeComplete, @config.resizeDebounceDelay
6971

70-
# Update grid selectors. (1) - reset
71-
# Required stackgrid.initialize to be called first.
72+
# update grid selectors. (1) - reset
73+
# required stack-up.initialize to be called first.
7274
updateSelectors: ->
7375
@containerElement = document.querySelector @config.containerSelector
7476
@itemElements = document.querySelectorAll "#{@config.containerSelector} > #{@config.itemsSelector}"
77+
this
7578

7679
# This only updates @items, it does not update the selectors.
7780
appendItem: (item) ->
7881
item.style.width = "#{@config.columnWidth}px"
7982
@items.push [item, item.offsetHeight, 0, 0]
83+
this
8084

8185
# Populate grid items. (2) - reset
8286
populateItems: ->
@@ -93,7 +97,7 @@ class @StackUp
9397
numberOfColumns = 1 if @items.length and numberOfColumns <= 0
9498
return numberOfColumns
9599

96-
# Update _grid.numberOfColumns. (3) - stack
100+
# update _grid.numberOfColumns. (3) - stack
97101
updateNumberOfColumns: ->
98102
@numberOfColumns = @calculateNumberOfColumns()
99103

@@ -106,7 +110,7 @@ class @StackUp
106110
callback = ->
107111
@config.moveItem item[0], item[2], item[3], callback for item, index in @items
108112

109-
# Stack (4)
113+
# stack (4)
110114
# Layout updates the _grid.containerHeight and updates _grid.items.
111115
layout:
112116
columnPointer: 0
@@ -122,7 +126,6 @@ class @StackUp
122126
c.containerHeight = @stack[c.layout.columnPointer] if @stack[c.layout.columnPointer] > c.containerHeight
123127
c.layout.columnPointer++
124128
c.layout.columnPointer = 0 if c.layout.columnPointer >= c.numberOfColumns
125-
126129
loop: ->
127130
@plot i for i in [0..@context.items.length - 1]
128131
optimized:
@@ -145,21 +148,23 @@ class @StackUp
145148
@layout[@config.layout].context = this
146149
@layout[@config.layout].setup()
147150
@layout[@config.layout].loop() if @items.length
151+
this
148152

149153
resetLayout: ->
150-
@containerHeight = 0
154+
@containerHeight = 0
151155
@layout.columnPointer = 0
156+
this
152157

153158
# This should be called when any item are being modified, added, or removed.
154159
reset: ->
155-
@containerWidth = 0
160+
@containerWidth = 0
156161
@containerHeight = 0
157-
@items = []
162+
@items = []
158163
@updateSelectors()
159164
@populateItems()
160165
@resetLayout()
161166
@restack()
162-
return
167+
this
163168

164169
append: (item, callback) ->
165170
itemIndex = @items.length
@@ -169,9 +174,11 @@ class @StackUp
169174
@draw()
170175
else
171176
@restack()
177+
this
172178

173179
restack: ->
174180
@updateNumberOfColumns()
175181
@resetLayout()
176182
@applyLayout()
177183
@draw()
184+
this

0 commit comments

Comments
 (0)