Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds 'serialization' functionality #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions app/scripts/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ angular.module('nouislider', [])
end: "@"
callback: "@"
margin: "@"
connect: "@"
orientation: "@"
lowerTooltipTarget: '='
lowerTooltipMethod: '&'
lowerTooltipFormat: '='
upperTooltipTarget: '='
upperTooltipMethod: '&'
upperTooltipFormat: '='
direction: "@"
ngModel: "="
ngFrom: "="
ngTo: "="
Expand All @@ -18,19 +27,42 @@ angular.module('nouislider', [])

callback = if scope.callback then scope.callback else 'slide'

setupTooltip = (target, method, format, config, handle) ->
linkConfig = {}
atLeastOne = false
if target
linkConfig.target = target
atLeastOne = true
if method and method()
linkConfig.method = method()
atLeastOne = true
if format
linkConfig.format = format
atLeastOne = true
if atLeastOne
if !config.serialization
config.serialization = {}
config.serialization[handle or 'lower'] = [$.Link(linkConfig)]

if scope.ngFrom? and scope.ngTo?
fromParsed = null
toParsed = null

slider.noUiSlider
config = {
start: [scope.ngFrom or scope.start, scope.ngTo or scope.end]
step: parseFloat(scope.step or 1)
connect: true
margin: parseFloat(scope.margin or 0)
orientation: scope.orientation or "horizontal"
direction: scope.direction or "ltr"
range:
min: [parseFloat scope.start]
max: [parseFloat scope.end]
}
setupTooltip(scope.lowerTooltipTarget, scope.lowerTooltipMethod, scope.lowerTooltipFormat, config)
setupTooltip(scope.upperTooltipTarget, scope.upperTooltipMethod, scope.upperTooltipFormat, config, 'upper')

slider.noUiSlider config

slider.on callback, ->
[from, to] = slider.val()
Expand All @@ -55,12 +87,20 @@ angular.module('nouislider', [])
else
parsedValue = null

slider.noUiSlider
config = {
start: [scope.ngModel or scope.start],
step: parseFloat(scope.step or 1)
connect: scope.connect or false
orientation: scope.orientation or "horizontal"
direction: scope.direction or "ltr"
range:
min: [parseFloat scope.start]
max: [parseFloat scope.end]
}

setupTooltip(scope.lowerTooltipTarget, scope.lowerTooltipMethod, scope.lowerTooltipFormat, config)

slider.noUiSlider config

slider.on callback, ->
parsedValue = parseFloat slider.val()
Expand Down
56 changes: 50 additions & 6 deletions src/nouislider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/nouislider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.