Skip to content

Commit

Permalink
fix a couple of linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Recidvst committed Oct 17, 2023
1 parent cf6758a commit 2b8af83
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 49 deletions.
4 changes: 0 additions & 4 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ Scrub({
alt: ['Image number 1 alt', 'Image number 2 alt'],
})
Scrub('#slider2')
Scrub({
target: '.slider3',
height: '800px',
})

// Scrub('nonexistent');
44 changes: 24 additions & 20 deletions example/scrub.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ var Scrub = (function () {
}
if (scrubSlider != undefined) {
var createScrubImages = function createScrubImages(el, type, index) {
var scrubImage
var imgSrc
var scrubCont
var resizeFn
if (type == 'DIV') {
// clone div
var scrubImage = el.cloneNode(true)
scrubImage = el.cloneNode(true)
el.parentNode.removeChild(el)
// inject scrub container
var scrubCont = document.createElement('div')
scrubCont = document.createElement('div')
scrubCont.className =
index == 0 ? 'scrub-content scrub-left' : 'scrub-content scrub-right'
scrubCont.style.width = parseInt(sliderWidth / 2) + 'px'
Expand All @@ -117,7 +121,7 @@ var Scrub = (function () {
}
// if src specified manually
if (scrubArg.src != null) {
var imgSrc = index == 0 ? scrubArg.src[0] : scrubArg.src[1]
imgSrc = index == 0 ? scrubArg.src[0] : scrubArg.src[1]
scrubImage.style.backgroundImage = 'url(' + imgSrc + ')'
}
scrubCont.appendChild(scrubImage)
Expand All @@ -132,25 +136,25 @@ var Scrub = (function () {
}

// handle resize
var reziseFn = debounce(function (scrubImage) {
var reziseFn = debounce(function (img) {
var newSliderWidth = scrubSlider.offsetWidth
scrubCont.style.width = parseInt(newSliderWidth / 2) + 'px'
scrubImage.style.width = newSliderWidth + 'px'
img.style.width = newSliderWidth + 'px'
}, 500)
window.addEventListener('resize', function (e) {
reziseFn(scrubImage)
})
} else if (type == 'IMG') {
// clone div
var scrubImage = document.createElement('div')
var imgSrc = el.getAttribute('src')
scrubImage = document.createElement('div')
imgSrc = el.getAttribute('src')
// if src specified manually
if (scrubArg.src != null) {
imgSrc = index == 0 ? scrubArg.src[0] : scrubArg.src[1]
}
el.parentNode.removeChild(el)
// inject scrub container
var scrubCont = document.createElement('div')
scrubCont = document.createElement('div')
scrubCont.className =
index == 0 ? 'scrub-content scrub-left' : 'scrub-content scrub-right'
scrubCont.style.width = parseInt(sliderWidth / 2) + 'px'
Expand All @@ -165,13 +169,13 @@ var Scrub = (function () {
scrubCont.appendChild(scrubImage)

// handle resize
var reziseFn = debounce(function (scrubImage) {
var reziserFn = debounce(function (img) {
var newSliderWidth = scrubSlider.offsetWidth
scrubCont.style.width = parseInt(newSliderWidth / 2) + 'px'
scrubImage.style.width = newSliderWidth + 'px'
img.style.width = newSliderWidth + 'px'
}, 500)
window.addEventListener('resize', function (e) {
reziseFn(scrubImage)
reziserFn(scrubImage)
})
}
}
Expand Down Expand Up @@ -199,13 +203,13 @@ var Scrub = (function () {
)
}
}
utilityFn(function (scrubSlider) {
utilityFn(function (slider) {
// add scrub control/handle
var scrubHandle = document.createElement('div')
scrubHandle.className = 'sliding handleOn '
scrubHandle.innerHTML =
'<span class="sliding-left"></span><span class="sliding-right"></span>'
scrubSlider.appendChild(scrubHandle)
slider.appendChild(scrubHandle)

// remove handle if specified
if (scrubArg.handle == false) {
Expand All @@ -214,22 +218,22 @@ var Scrub = (function () {
}

// scrub slider main action fn
var mover = debounce(function (pos, full, slider) {
var mover = debounce(function (pos, full, sldr) {
if (scrubHandle) {
var shrink = full - pos
var sliding = slider.querySelectorAll('.sliding')
var sliding = sldr.querySelectorAll('.sliding')
sliding[0].style.left = (pos > 0 ? pos : 0) + 'px'
var contentLeft = slider.querySelectorAll('.scrub-left')
var contentLeft = sldr.querySelectorAll('.scrub-left')
contentLeft[0].style.width = (pos > 0 ? pos : 0) + 'px'
var contentRight = slider.querySelectorAll('.scrub-right')
var contentRight = sldr.querySelectorAll('.scrub-right')
contentRight[0].style.width = (shrink > 0 ? shrink : 0) + 'px'
}
}, 1)
// add mousemove listener
scrubSlider.addEventListener('mousemove', function (e) {
slider.addEventListener('mousemove', function (e) {
var mousePosition = e.clientX - this.offsetLeft
var fullWidth = scrubSlider.offsetWidth
mover(mousePosition, fullWidth, scrubSlider)
var fullWidth = slider.offsetWidth
mover(mousePosition, fullWidth, slider)
})
})
} catch (e) {
Expand Down
5 changes: 0 additions & 5 deletions src/js/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,4 @@ Scrub({

Scrub('#slider2')

Scrub({
target: '.slider3',
height: '800px',
})

// Scrub('nonexistent');
44 changes: 24 additions & 20 deletions src/js/scrub.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ function Scrub(scrubArg) {
var scrubChildren = scrubSlider.children

function createScrubImages(el, type, index) {
var scrubImage
var imgSrc
var scrubCont
var resizeFn
if (type == 'DIV') {
// clone div
var scrubImage = el.cloneNode(true)
scrubImage = el.cloneNode(true)
el.parentNode.removeChild(el)
// inject scrub container
var scrubCont = document.createElement('div')
scrubCont = document.createElement('div')
scrubCont.className =
index == 0 ? 'scrub-content scrub-left' : 'scrub-content scrub-right'
scrubCont.style.width = parseInt(sliderWidth / 2) + 'px'
Expand All @@ -109,7 +113,7 @@ function Scrub(scrubArg) {
}
// if src specified manually
if (scrubArg.src != null) {
var imgSrc = index == 0 ? scrubArg.src[0] : scrubArg.src[1]
imgSrc = index == 0 ? scrubArg.src[0] : scrubArg.src[1]
scrubImage.style.backgroundImage = 'url(' + imgSrc + ')'
}
scrubCont.appendChild(scrubImage)
Expand All @@ -124,25 +128,25 @@ function Scrub(scrubArg) {
}

// handle resize
var reziseFn = debounce(function (scrubImage) {
var reziseFn = debounce(function (img) {
var newSliderWidth = scrubSlider.offsetWidth
scrubCont.style.width = parseInt(newSliderWidth / 2) + 'px'
scrubImage.style.width = newSliderWidth + 'px'
img.style.width = newSliderWidth + 'px'
}, 500)
window.addEventListener('resize', function (e) {
reziseFn(scrubImage)
})
} else if (type == 'IMG') {
// clone div
var scrubImage = document.createElement('div')
var imgSrc = el.getAttribute('src')
scrubImage = document.createElement('div')
imgSrc = el.getAttribute('src')
// if src specified manually
if (scrubArg.src != null) {
imgSrc = index == 0 ? scrubArg.src[0] : scrubArg.src[1]
}
el.parentNode.removeChild(el)
// inject scrub container
var scrubCont = document.createElement('div')
scrubCont = document.createElement('div')
scrubCont.className =
index == 0 ? 'scrub-content scrub-left' : 'scrub-content scrub-right'
scrubCont.style.width = parseInt(sliderWidth / 2) + 'px'
Expand All @@ -157,13 +161,13 @@ function Scrub(scrubArg) {
scrubCont.appendChild(scrubImage)

// handle resize
var reziseFn = debounce(function (scrubImage) {
var reziserFn = debounce(function (img) {
var newSliderWidth = scrubSlider.offsetWidth
scrubCont.style.width = parseInt(newSliderWidth / 2) + 'px'
scrubImage.style.width = newSliderWidth + 'px'
img.style.width = newSliderWidth + 'px'
}, 500)
window.addEventListener('resize', function (e) {
reziseFn(scrubImage)
reziserFn(scrubImage)
})
}
}
Expand All @@ -184,13 +188,13 @@ function Scrub(scrubArg) {
}
}

utilityFn(function (scrubSlider) {
utilityFn(function (slider) {
// add scrub control/handle
var scrubHandle = document.createElement('div')
scrubHandle.className = 'sliding handleOn '
scrubHandle.innerHTML =
'<span class="sliding-left"></span><span class="sliding-right"></span>'
scrubSlider.appendChild(scrubHandle)
slider.appendChild(scrubHandle)

// remove handle if specified
if (scrubArg.handle == false) {
Expand All @@ -199,22 +203,22 @@ function Scrub(scrubArg) {
}

// scrub slider main action fn
var mover = debounce(function (pos, full, slider) {
var mover = debounce(function (pos, full, sldr) {
if (scrubHandle) {
var shrink = full - pos
var sliding = slider.querySelectorAll('.sliding')
var sliding = sldr.querySelectorAll('.sliding')
sliding[0].style.left = (pos > 0 ? pos : 0) + 'px'
var contentLeft = slider.querySelectorAll('.scrub-left')
var contentLeft = sldr.querySelectorAll('.scrub-left')
contentLeft[0].style.width = (pos > 0 ? pos : 0) + 'px'
var contentRight = slider.querySelectorAll('.scrub-right')
var contentRight = sldr.querySelectorAll('.scrub-right')
contentRight[0].style.width = (shrink > 0 ? shrink : 0) + 'px'
}
}, 1)
// add mousemove listener
scrubSlider.addEventListener('mousemove', function (e) {
slider.addEventListener('mousemove', function (e) {
var mousePosition = e.clientX - this.offsetLeft
var fullWidth = scrubSlider.offsetWidth
mover(mousePosition, fullWidth, scrubSlider)
var fullWidth = slider.offsetWidth
mover(mousePosition, fullWidth, slider)
})
})
} catch (e) {
Expand Down

0 comments on commit 2b8af83

Please sign in to comment.