Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dux committed Jul 14, 2024
1 parent efefcef commit ed095c5
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 11 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="demo/fez.png" align="right" />
<img src="demo/fez.png" align="right" style="max-width: 110px; position: relative; z-index: 1;" />

# FEZ - Custom DOM Elements

Expand All @@ -14,14 +14,11 @@ Latest version of libs are baked in Fez distro.

It uses minimal abstraction. You will learn to use it in 3 minutes, just look at example, it includes all you need to know.

## How to install?
## How to install and test?

Add `<script src="https://cdn.jsdelivr.net/gh/dux/fez-custom-dom-elements@latest/dist/fez.js"></script>`

To start

* define [Fez tag](https://dux.github.io/fez/)
* add HTML. YOu can copy&paste from examples, must work.
* Add `<script src="https://cdn.jsdelivr.net/gh/dux/fez-custom-dom-elements@latest/dist/fez.js"></script>` to header
* define Fez tag JS, [copy from here](https://dux.github.io/fez/)
* add HTML and hit refresh

## Little more details

Expand Down
154 changes: 154 additions & 0 deletions demo/fez/slider.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# it must have div an then div, so we can read real height and animate height change
# <ui-slider dotts="true" arrows="true" next="5000">
# <div>
# <div data-question="Tip">
# <h2>...</h2>

Fez 'ui-slider', class extends FezBase
@css = """
.parent {
overflow: hidden;
.slides {
display: flex;
flex-direction: row;
transition: transform 0.3s ease-in-out, height .6s ease;
width: 100%;
height: var(--height);
gap: var(--gap);
& > div {
flex: 1;
min-width: var(--width);
max-width: var(--width);
}
}
}
.dotts {
margin-top: calc(var(--gap) / 1.2);
display: flex;
justify-content: center;
gap: 7px;
span {
min-width: 15px;
min-height: 15px;
border: 2px solid var(--base-color);
border-radius: 10px;
cursor: pointer;
&:hover, &.active {
border: 7px solid var(--base-color);
}
}
}
.arrow {
position: relative;
& > div {
width: 25px;
height: 25px;
border-top: 5px solid var(--base-color);
border-left: 5px solid var(--base-color);
position: absolute;
top: calc(var(--height) / 2 - 13px);
z-index: 1;
transition: all 0.3s ease-in-out;
cursor: pointer;
&:hover {
border-color: var(--green-6);
}
&.left {
left: 0;
transform: rotate(-45deg);
margin-left: calc(var(--gap) * -1.3);
}
&.right {
right: 0;
margin-right: calc(var(--gap) * -1.3);
transform: rotate(135deg);
}
}
}
"""

setFrame: (num) =>
if typeof num == 'number'
@currentSlide = num
else
num = @currentSlide

window.requestAnimationFrame =>
slidesRoot = @$root.find('.slides')
sliderWidth = slidesRoot.width()
sliderNode = slidesRoot.find("& > div:nth-child(#{num+1}) > div")
sliderHeight = sliderNode[0].getBoundingClientRect().height

@$root.css('--width', "#{sliderWidth}px")
@$root.css('--height', "#{sliderHeight}px")
@$root.css('--gap', "#{@gap}px")

offset = num * (sliderWidth + @gap)
slidesRoot.css('transform', "translateX(-#{offset}px)")

@$root.find(".dot-#{num}").activate()

num

nextSlide: () =>
@currentSlide = if @slides[@currentSlide + 1] then @currentSlide + 1 else 0
@setFrame()

prevSlide: () =>
@currentSlide = if @currentSlide > 0 then @currentSlide - 1 else @slides.length - 1
@setFrame()

connect: (props) =>
@gap = parseInt(props.gap || 30)
@slides = @$root.find('&>div').get()

# this will allow dinamic slide height
for slide in @slides
@$root.append $('<div />').append(slide)

@html """
{{if @props.arrows}}
<div class="arrow">
<div class="left" onmousedown="$$.prevSlide(true)"></div>
<div class="right" onmousedown="$$.nextSlide(true)"></div>
</div>
{{/if}}
<div class="parent">
<div class="slides">
<slot />
</div>
</div>
{{if @props.dotts}}
<div class="dotts">
{{each @slides as el, i}}
<span class="dot-{{i}}" onmousedown="$$.setFrame({{i}})"></span>
{{/each}}
</div>
{{/if}}
"""

@$root.first('img').one 'load', @setFrame

@setFrame(0)
# sometimes does not get height
setTimeout =>
@setFrame(0)
, 100

Pubsub.sub 'window-resize', $.throttle(@setFrame, 300)

if props.next
props.next = setInterval @nextSlide, parseInt(props.next)
@$root.one 'click', ()=>clearInterval(props.next)


Empty file added demo/fez/slider.html
Empty file.
4 changes: 2 additions & 2 deletions demo/fez/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Fez('ui-todo', class extends FezBase {
}

animate(node) {
// same as in svelte, uf you define fez-use="methodName", method will be called when node is added to dom.
// same as in Svelte, uf you define fez-use="methodName", method will be called when node is added to dom.
// in this case, we animate show new node
$(node)
.css('display', 'block')
Expand All @@ -74,7 +74,7 @@ Fez('ui-todo', class extends FezBase {
}

connect() {
// creates reactive store, that calls this.html() state refresh after every data set
// creates reactive store. calls this.html() to refresh state, after every data set
// you can pass function as argument to change default reactive behaviour
this.data = this.reactiveStore({})

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>
<a target="repo" href="https://github.com/dux/fez">GitHub repo</a>
</h1>

<p>Fez was created by <a href="https://github.com/dux/">@dux</a> in 2024. Latest update was <script>document.write(timeSince('Sun Jul 14 18:01:09 2024 +0200'))</script>.
<p>Fez was created by <a href="https://github.com/dux/">@dux</a> in 2024. Latest update was <script>document.write(timeSince('Sun Jul 14 18:04:58 2024 +0200'))</script>.


<script src="./demo/fez/todo.js"></script>
Expand Down

0 comments on commit ed095c5

Please sign in to comment.