Skip to content

Commit a1e9ed8

Browse files
committed
removing methods to right prop
1 parent d376ada commit a1e9ed8

File tree

6 files changed

+31
-5255
lines changed

6 files changed

+31
-5255
lines changed

dist/placeload.js

Lines changed: 12 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/placeload.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/placeload.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ <h2 class="user__name"><a href="#">Sr. João</a></h2>
6464
<script>
6565
const user = Placeload
6666
.$('.user-placeload')
67-
.config({speed: '2s'})
68-
.line((element) => element.width(300).height(200))
69-
.config({spaceBetween: '10px'})
67+
.config({ speed: '2s' })
68+
.line((element) => element.width(100).height(200))
69+
.config({ spaceBetween: '10px' })
7070
.line((element) => element.width(100).height(20))
71-
.config({spaceBetween: '10px', right: true})
71+
.config({ spaceBetween: '10px' })
7272
.line((element) => element.width(50).height(20))
7373
.fold(
7474
(err) => console.log('error: ', err),

lib/placeload.js

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ const Right = Either.Right
66
const Left = Either.Left
77

88
const Placeload = {
9-
$: (x) => utils(getHoldersElements(x), selector(x))
9+
$: (x) => utils(boxElements(x), selector(x))
1010
}
1111

1212
// selector :: String -> Either
1313
const selector = (x) => {
1414
const element = document.querySelector(x)
15-
if(element)
16-
return Right(element)
17-
return Left(`Don\' found ${x} element`)
15+
return element ? Right(element) : Left(`Don\'t found ${x} element`)
1816
}
1917

20-
// getHoldersElements :: String -> Either
21-
const getHoldersElements = (x) => {
18+
// boxElements :: String -> IO
19+
const boxElements = (x) => {
2220
return IO(() => {
23-
return selector(x).chain((container) => {
21+
return selector(x).chain(container => {
2422
const elementPlaceload = styl(document.createElement('div')).addClass('placeload-background').toDOM()
2523
container.appendChild(elementPlaceload)
2624
return Right({
@@ -32,12 +30,11 @@ const getHoldersElements = (x) => {
3230
})
3331
}
3432

35-
// place :: IO -> Object
33+
// place :: IO -> IO(Node(DOM)) -> Object
3634
const utils = (_IO, container) => {
3735
return ({
3836
config: (configs) => utils(configIO(_IO, configs), container),
3937
line: f => utils(drawIO(f, _IO), container),
40-
spaceBetween: size => utils(drawIO({spaceBetween: size}, _IO), container),
4138
fold: (err, succ) => {
4239
_IO.runIO().either(err, succ)
4340
return {
@@ -52,7 +49,7 @@ const utils = (_IO, container) => {
5249
})
5350
}
5451

55-
// drawIO :: F -> IO -> F(IO)
52+
// drawIO :: Function -> IO -> Function(IO)
5653
const drawIO = (f, _IO) => {
5754
return _IO.map((elements) => {
5855
return elements.map(el => {
@@ -66,11 +63,11 @@ const drawIO = (f, _IO) => {
6663

6764
// elementStyle :: Object(DOM Elements) -> Node(DOM) -> Object (fn, fn, ...)
6865
const elementStyle = (elements, newElement) => ({
69-
width: (size) => elementStyle(createElemFolk(elements, newElement, 'width', size), newElement),
70-
height: (size) => elementStyle(createElemFolk(elements, newElement, 'height', size), newElement)
66+
width: (size) => elementStyle(newBoxStyled(elements, newElement, 'width', size), newElement),
67+
height: (size) => elementStyle(newBoxStyled(elements, newElement, 'height', size), newElement)
7168
})
7269

73-
// configIO :: IO -> IO
70+
// configIO :: IO -> Object -> IO
7471
const configIO = (_IO, config) => {
7572
return _IO.map(element => {
7673
return element.chain(elem => {
@@ -83,43 +80,16 @@ const configIO = (_IO, config) => {
8380
.marginTop(placeloadHeight)
8481
.addClass('placeload-masker').toDOM()
8582

86-
if (stylWithDefault.right) {
87-
runDrawRightLine(elem, stylWithDefault).runIO()
88-
} else {
89-
styl(elem.placeload).height(`${newHeightToPlaceload}px`)
90-
}
83+
styl(elem.placeload).height(`${newHeightToPlaceload}px`)
9184
elem.placeload.style.animationDuration = stylWithDefault.speed
9285
elem.placeload.appendChild(newElement)
9386
return element
9487
})
9588
})
9689
}
9790

98-
const runDrawRightLine = (elem, stylWithDefault) => {
99-
return IO(() => {
100-
const lastChild = elem.elems[elem.elems.length - 2]
101-
const itemToRight = elem.elems[elem.elems.length - 1]
102-
const elementRow = styl(document.createElement('div'))
103-
.addClass('placeload-masker')
104-
.width('100%')
105-
.height('10px')
106-
.marginTop('20px')
107-
.marginLeft(lastChild.style.marginLeft).toDOM()
108-
109-
styl(lastChild).hide()
110-
styl(itemToRight)
111-
.width(stylWithDefault.marginLeft)
112-
.height(itemToRight.style.marginTop)
113-
.marginLeft(lastChild.style.marginLeft)
114-
.marginTop(lastChild.style.marginTop)
115-
116-
styl(elem.placeload).height(`${parseInt(lastChild.style.marginTop) + parseInt(lastChild.style.height)}px`)
117-
elem.placeload.appendChild(elementRow)
118-
})
119-
}
120-
121-
// createElemFolk :: Either -> Node(DOM) -> prop -> value -> Object(DOM Elements)
122-
const createElemFolk = (elements, newElement, prop, value) => {
91+
// newBoxStyled :: Either -> Node(DOM) -> String -> String -> Object(DOM Elements)
92+
const newBoxStyled = (elements, newElement, prop, value) => {
12393
return elements.map(elem => {
12494
const height = elem.placeload.style.height || 0
12595
switch (prop) {

0 commit comments

Comments
 (0)