mirror of https://github.com/freeCodeCamp/devdocs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.1 KiB
101 lines
2.1 KiB
11 years ago
|
class app.views.SidebarHover extends app.View
|
||
|
@itemClass: '_list-hover'
|
||
|
|
||
|
@events:
|
||
|
focus: 'onFocus'
|
||
|
blur: 'onBlur'
|
||
|
mouseover: 'onMouseover'
|
||
|
mouseout: 'onMouseout'
|
||
|
scroll: 'onScroll'
|
||
|
click: 'onClick'
|
||
|
|
||
|
@routes:
|
||
|
after: 'onRoute'
|
||
|
|
||
|
constructor: (@el) ->
|
||
|
unless isPointerEventsSupported()
|
||
|
delete @constructor.events.mouseover
|
||
|
super
|
||
|
|
||
|
show: (el) ->
|
||
|
unless el is @cursor
|
||
|
@hide()
|
||
9 years ago
|
if @isTarget(el) and @isTruncated(el.lastElementChild or el)
|
||
11 years ago
|
@cursor = el
|
||
|
@clone = @makeClone @cursor
|
||
|
$.append document.body, @clone
|
||
9 years ago
|
@offsetTop ?= @el.offsetTop
|
||
11 years ago
|
@position()
|
||
|
return
|
||
|
|
||
|
hide: ->
|
||
|
if @cursor
|
||
|
$.remove @clone
|
||
|
@cursor = @clone = null
|
||
|
return
|
||
|
|
||
|
position: =>
|
||
|
if @cursor
|
||
10 years ago
|
rect = $.rect(@cursor)
|
||
|
if rect.top >= @offsetTop
|
||
|
@clone.style.top = rect.top + 'px'
|
||
|
@clone.style.left = rect.left + 'px'
|
||
11 years ago
|
else
|
||
|
@hide()
|
||
|
return
|
||
|
|
||
|
makeClone: (el) ->
|
||
9 years ago
|
clone = el.cloneNode(true)
|
||
11 years ago
|
clone.classList.add 'clone'
|
||
|
clone
|
||
|
|
||
|
isTarget: (el) ->
|
||
10 years ago
|
el?.classList?.contains @constructor.itemClass
|
||
11 years ago
|
|
||
11 years ago
|
isSelected: (el) ->
|
||
|
el.classList.contains 'active'
|
||
|
|
||
11 years ago
|
isTruncated: (el) ->
|
||
10 years ago
|
el.scrollWidth > el.offsetWidth
|
||
11 years ago
|
|
||
|
onFocus: (event) =>
|
||
|
@focusTime = Date.now()
|
||
|
@show event.target
|
||
|
return
|
||
|
|
||
|
onBlur: =>
|
||
|
@hide()
|
||
|
return
|
||
|
|
||
|
onMouseover: (event) =>
|
||
11 years ago
|
if @isTarget(event.target) and not @isSelected(event.target) and @mouseActivated()
|
||
11 years ago
|
@show event.target
|
||
|
return
|
||
|
|
||
|
onMouseout: (event) =>
|
||
|
if @isTarget(event.target) and @mouseActivated()
|
||
|
@hide()
|
||
|
return
|
||
|
|
||
|
mouseActivated: ->
|
||
|
# Skip mouse events caused by focus events scrolling the sidebar.
|
||
|
not @focusTime or Date.now() - @focusTime > 500
|
||
|
|
||
|
onScroll: =>
|
||
|
@position()
|
||
|
return
|
||
|
|
||
|
onClick: (event) =>
|
||
|
if event.target is @clone
|
||
|
$.click @cursor
|
||
|
return
|
||
|
|
||
|
onRoute: =>
|
||
|
@hide()
|
||
|
return
|
||
|
|
||
|
isPointerEventsSupported = ->
|
||
|
el = document.createElement 'div'
|
||
|
el.style.cssText = 'pointer-events: auto'
|
||
|
el.style.pointerEvents is 'auto'
|