Skip to content

Commit

Permalink
работа с DOM переведена на JQuery (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geksanit committed Jan 16, 2018
1 parent 11daf50 commit b0c5dcf
Show file tree
Hide file tree
Showing 27 changed files with 22,337 additions and 1,758 deletions.
44 changes: 25 additions & 19 deletions frontend/components/slider/slider.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
// slider
const sliderChange = function sliderChange(element) {
const { value } = element;
const width = element.parentElement.clientWidth - 20;
const min = element.attributes.min.value;
const max = element.attributes.max.value;
element.previousElementSibling.innerText = value;
element.previousElementSibling.style.left = `${((width / (max - min)) * (value - min)) - 8.75}px`;
};
/* global $ */
import convertRemToPixels from '../../scripts/convertRemToPixels';

const sliderInput = function sliderInput(event) {
sliderChange(event.target);
};
class Slider {
constructor(element) {
this.$element = $(element);
this.$parent = this.$element.parent();
this.$view = this.$parent.find('.slider__view');
this.$line = this.$parent.find('.slider__line');
this.sliderChange.call(this);
this.$element.on('input.slider', this.sliderChange.bind(this));
}
sliderChange() {
const { $element } = this;
const width = $element.width() - convertRemToPixels(1.25);
const value = $element.val();
const min = this.$element.prop('min');
const max = this.$element.prop('max');
const newLeft = ((width / (max - min)) * (value - min)) - convertRemToPixels(0.625);
this.$view.text(value).css({ left: newLeft });
const newWidth = ((width / (max - min)) * (value - min)) + convertRemToPixels(0.625);
this.$line.width(newWidth);
}
}

(function initSliders() {
const elements = document.querySelectorAll('.js-slider__input');
elements.forEach((element) => {
sliderChange(element);
element.oninput = sliderInput;
});
}());
let sliders = [];
$('.js-slider__input').each((index, element) => sliders.push(new Slider(element)));
18 changes: 14 additions & 4 deletions frontend/components/slider/slider.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ mixin slider(options)
if (!options || (typeof(options) !== 'object'))
- options = {}
- options.min = options.min || 0
- options.max = options.max || 10
- options.value = options.value || Math.ceil((options.max - options.min) / 2)
- options.max = options.max || 100
- options.value = options.value || 0
- options.mix = options.mix || ''

div(class = "slider " + options.mix)
.slider__view #{options.value}
div(class = "slider slider_color_" + options.color + " " + options.mix)
if (options.view)
.slider__view #{options.value}
if (options.line)
.slider__line
input(class = "slider__input js-slider__input" type = "range" min = options.min max = options.max value = options.value)
if (options.numbers)
.slider__numbers
div 0
div 25
div 50
div 75
div 100
86 changes: 52 additions & 34 deletions frontend/components/slider/slider.styl
Original file line number Diff line number Diff line change
@@ -1,58 +1,71 @@
slider($font, $color, $white, $gray)
slider($font, $blue, $orange, $gray, $white)
$color = $blue[0]
// track - линия
$track-color = $gray[1]
// thumb - ползунок
$thumb-color = $color[0]
$thumb-radius = 10px
$thumb-size = 20px
$thumb-radius = 0.625rem
$thumb-size = 1.25rem
h = 0.31rem

track()
width 100%
height 5px
border-radius 5px
height h
border-radius h
background-color $track-color
cursor pointer

thumb()
margin-top -7.5px
margin-top -0.5rem
height $thumb-size
width $thumb-size
border-radius $thumb-radius
background $thumb-color
background $color
cursor pointer

.slider
position relative
font-family $font, Arial, sans-serif
font-weight 700
width 100%

&__view
position absolute
width 35px
height 24px
background-color $thumb-color
border-radius 5px
width 2.2rem
height 1.5rem
background-color $color
border-radius h
top 0
left 50% - 17.5px
left 50%
color $white
text-align center
line-height 24px
line-height 1.5rem

&::after
content ''
bottom -2px
left 15.7px
bottom -0.125rem
left 1rem
position absolute
width 5px
height 5px
width h
height h
background-color inherit
transform rotate(-45deg)

&__line
background-color $color
width 0.625rem
height h
border-radius h
position absolute
top 2.44rem
left 0
pointer-events none

&__input
-webkit-appearance none
-moz-appearance none
width 100%
margin 39px 0 0 0
margin 0
padding-top 2.44rem
background-color transparent

&:focus
outline none
Expand All @@ -71,20 +84,25 @@ slider($font, $color, $white, $gray)
thumb()
border none

&::-ms-track
track()
background transparent
border-color transparent
border-width $thumb-size 0
color transparent
&__numbers
padding 0.44rem 0.125rem 0 0.125rem
color $gray[1]
font-size 0.625rem
display flex
justify-content space-between

&_color_orange
$color = $orange[0]

&::-ms-fill-lower
background yellow
border-radius 10px
& ^[0]

&::-ms-fill-upper
background $track-color
border-radius 10px
&__view, &__line
background-color $color

&::-ms-thumb
thumb()
&__input

&::-webkit-slider-thumb
background $color

&::-moz-range-thumb
background $color
32 changes: 16 additions & 16 deletions frontend/components/standart-button/standart-button.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// ripple effect
const rippleEffect = function rippleEffect(event) {
const div = document.createElement('div');
div.id = 'ripple';
div.style.top = `${event.pageY - 25}px`;
div.style.left = `${event.pageX - 25}px`;
/* global $ */
import convertRemToPixels from '../../scripts/convertRemToPixels';

document.body.appendChild(div);
setTimeout(() => { document.body.removeChild(div); }, 550);
};

(function initButtons() {
const elements = document.querySelectorAll('.standart-button');
elements.forEach((element) => {
element.onclick = rippleEffect;
});
}());
class Button {
constructor(element) {
this.$element = $(element).on('click.standart-button', this.rippleEffect.bind(this));
this.size = convertRemToPixels(2);
}
rippleEffect(event) {
const $div = $('<div/>').attr('id', 'button__ripple');
$div.css({ top: `${event.offsetY - this.size}px`, left: `${event.offsetX - this.size}px` });
this.$element.append($div);
setTimeout(() => $div.remove(), 550);
}
}
let buttons = [];
$('.standart-button').each((index, element) => buttons.push(new Button(element)));
56 changes: 24 additions & 32 deletions frontend/components/standart-button/standart-button.styl
Original file line number Diff line number Diff line change
Expand Up @@ -16,75 +16,67 @@ standart-button($font, $blue, $orange, $gray, $white)

setColor($_color)
border-color $_color[0]
box-shadow 0 3px 0 $_color[1]
box-shadow 0 0.2rem 0 $_color[1]
color $_color[0]

&:hover
background-color $_color[0]

&.standart-button_size_small
box-shadow 0 2px 0 $_color[1]
box-shadow 0 0.125rem 0 $_color[1]

.standart-button
position relative
width 118px
height 32px
width 7.375rem
height 2rem
box-sizing border-box
border-radius 3px
border-radius 0.2rem
border-style solid
border-width 1px
outline none
overflow hidden
font-family $font, Arial, sans-serif
font-weight 900
font-size 12px
font-size 0.75rem
text-transform uppercase
text-align center
vertical-align middle
background-color $white
border-color $blue[0]
box-shadow 0 3px 0 $blue[1]
box-shadow 0 0.2rem 0 $blue[1]
color $blue[0]

&:hover
background-color $blue[0]
color $white
color white
cursor pointer

&:active
bottom -4px
bottom -0.25rem
box-shadow none
border-style solid
border-width 1px

&_size_small
width 78px
height 22px
font-size 10px
box-shadow 0 2px 0 $blue[1]
width 4.875rem
height 1.375rem
font-size 0.625rem
box-shadow 0 0.125rem 0 $blue[1]

&_color_orange
setColor($orange)

&:disabled
border-color $gray[2]
box-shadow 0 3px 0 darken($gray[2], 20)
color $gray[2]
setColor($gray)

&:hover
background-color $gray[2]
color $white
background-color $white

&.standart-button_size_small
box-shadow 0 2px 0 darken($gray[2], 20)


#ripple
position absolute
top 100px
left 100px
width 50px
height @width
border-radius @width
background-color $white
animation ripple 0.5s forwards
pointer-events none
#button__ripple
position absolute
width 4rem
height @width
border-radius 100%
background-color $white
animation ripple 0.7s forwards
pointer-events none
6 changes: 3 additions & 3 deletions frontend/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ html
+standart-button({ mix:'button-mix', title:'clear', size:'small' })
.container
.label speed
+slider({ mix:'slider-mix', min: 1, max: 10, value: 1 })
+slider({ mix:'slider-mix', min: 1, max: 10, value: 1, line: true, view: true })
.container
.label width
+slider({ mix:'slider-mix', min: 0, max: 100, value: 10 })
+slider({ mix:'slider-mix', min: 0, max: 100, value: 10, line: true, view: true })
.container
.label height
+slider({ mix:'slider-mix', min: 0, max: 100, value: 10 })
+slider({ mix:'slider-mix', min: 0, max: 100, value: 10, line: true, view: true })
.container
.status

Expand Down
2 changes: 1 addition & 1 deletion frontend/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ body
standart-button($font, $blue, $orange, $gray, $white)

@import './components/slider/slider.styl'
slider($font, $blue, $white, $gray)
slider($font, $blue, $orange, $gray, $white)
1 change: 0 additions & 1 deletion frontend/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './index.styl';
import './favicons/favicons';
import './components/slider/slider';
import './components/standart-button/standart-button';
import Controller from './mvc/controller/Controller.ts';

const controller = new Controller();
Loading

0 comments on commit b0c5dcf

Please sign in to comment.