This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b7239c
commit c241b6c
Showing
5 changed files
with
119 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = | ||
Focus: require './focus' | ||
Popup: require './popup' | ||
Size: require './size' | ||
Focus: require './focus' | ||
Popup: require './popup' | ||
Scroll: require './scroll' | ||
Size: require './size' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
core = require 'open.client/core' | ||
|
||
|
||
### | ||
Extends a view to make it scrollable. | ||
### | ||
module.exports = class ScrollController | ||
constructor: (view) -> | ||
|
||
# Add the scroll property. | ||
unless view.scroll?.onChanged? | ||
view.addProps | ||
scroll: null # Gets or sets the scroll behavior of the content (values: null, 'x', 'y' or 'xy'). | ||
|
||
# Sycers. | ||
sync = -> core.util.syncScroll view.el, view.scroll() | ||
|
||
# Wire up events. | ||
# - Handler: Validate property. | ||
view.scroll.onChanging (e) -> | ||
value = e.newValue | ||
value = value?.toLowerCase() | ||
throw "'#{value}' not valid scroll value (x,y or xy)" if not isValid value | ||
e.newValue = value | ||
|
||
# - Handler: Sync state on scroll changed. | ||
view.scroll.onChanged sync | ||
|
||
# Finish up. | ||
sync() | ||
|
||
|
||
# PRIVATE -------------------------------------------------------------------------- | ||
|
||
|
||
isValid = (value) -> return true if value is valid for valid in ['x', 'y', 'xy'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
describe 'controls/controllers/scroll', -> | ||
View = null | ||
Scroll = null | ||
|
||
class MyView extends core.mvc.View | ||
defaults: | ||
scroll: 'y' | ||
|
||
class MyScrollView extends MyView | ||
constructor: (props = {}) -> | ||
super | ||
new Scroll @ | ||
|
||
|
||
|
||
beforeEach -> | ||
View = core.mvc.View | ||
Scroll = controls.controllers.Scroll | ||
|
||
it 'exists', -> | ||
expect(Scroll).toBeDefined() | ||
|
||
it 'adds a [scroll] property function to a view', -> | ||
view = new View() | ||
expect(view.scroll).not.toBeDefined() | ||
new Scroll(view) | ||
expect(view.scroll.onChanged instanceof Function).toEqual true | ||
|
||
it 'keeps a pre-defined [scroll] property', -> | ||
view = new MyView() | ||
new Scroll view | ||
expect(view.scroll()).toEqual 'y' | ||
|
||
|
||
it 'converts property to lower case', -> | ||
view = new MyScrollView() | ||
view.scroll 'XY' | ||
expect(view.scroll()).toEqual 'xy' | ||
|
||
it 'throws if a non valid valid is passed', -> | ||
view = new MyScrollView() | ||
view.scroll 'z' | ||
|
||
|
||
describe 'delegate to syncScroll() method', -> | ||
callArgs = -> core.util.syncScroll.mostRecentCall.args | ||
beforeEach -> | ||
|
||
it 'syncs scroll on construction', -> | ||
spyOn(core.util, 'syncScroll') | ||
view = new MyScrollView() | ||
args = callArgs() | ||
|
||
expect(core.util.syncScroll.callCount).toEqual 1 | ||
expect(args[0]).toEqual view.el | ||
expect(args[1]).toEqual 'y' | ||
|
||
it 'syncs on property changed', -> | ||
view = new MyScrollView() | ||
|
||
spyOn(core.util, 'syncScroll') | ||
view.scroll 'x' | ||
args = callArgs() | ||
|
||
expect(core.util.syncScroll.callCount).toEqual 1 | ||
expect(args[0]).toEqual view.el | ||
expect(args[1]).toEqual 'x' | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters