Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
I
i20rzslider
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jedife
i20rzslider
Commits
8cbdc467
Commit
8cbdc467
authored
Sep 22, 2016
by
Valentin Hervieu
Committed by
GitHub
Sep 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(keyboardSupport): Prevent losing focus when slider is rerendered (#415)
Fix #411
parent
8af61742
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
11 deletions
+71
-11
rzslider.js
dist/rzslider.js
+25
-5
rzslider.min.js
dist/rzslider.min.js
+2
-2
rzslider.js
src/rzslider.js
+24
-4
specific-test.js
tests/specs/keyboard-controls/specific-test.js
+20
-0
No files found.
dist/rzslider.js
View file @
8cbdc467
/*! angularjs-slider - v5.5.0 -
/*! angularjs-slider - v5.5.0 -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
https://github.com/angular-slider/angularjs-slider -
https://github.com/angular-slider/angularjs-slider -
2016-09-
06
*/
2016-09-
22
*/
/*jslint unparam: true */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
/*global angular: false, console: false, define, module */
(
function
(
root
,
factory
)
{
(
function
(
root
,
factory
)
{
...
@@ -304,6 +304,11 @@
...
@@ -304,6 +304,11 @@
*/
*/
this
.
cmbLabelShown
=
false
;
this
.
cmbLabelShown
=
false
;
/**
* Internal variable to keep track of the focus element
*/
this
.
currentFocusElement
=
null
;
// Slider DOM elements wrapped in jqLite
// Slider DOM elements wrapped in jqLite
this
.
fullBar
=
null
;
// The whole slider bar
this
.
fullBar
=
null
;
// The whole slider bar
this
.
selBar
=
null
;
// Highlight between two handles
this
.
selBar
=
null
;
// Highlight between two handles
...
@@ -413,6 +418,7 @@
...
@@ -413,6 +418,7 @@
this
.
scope
.
$on
(
'$destroy'
,
function
()
{
this
.
scope
.
$on
(
'$destroy'
,
function
()
{
self
.
unbindEvents
();
self
.
unbindEvents
();
angular
.
element
(
$window
).
off
(
'resize'
,
calcDimFn
);
angular
.
element
(
$window
).
off
(
'resize'
,
calcDimFn
);
self
.
currentFocusElement
=
null
;
});
});
},
},
...
@@ -577,7 +583,7 @@
...
@@ -577,7 +583,7 @@
else
{
else
{
this
.
customTrFn
=
function
(
modelValue
)
{
this
.
customTrFn
=
function
(
modelValue
)
{
if
(
this
.
options
.
bindIndexForStepsArray
)
if
(
this
.
options
.
bindIndexForStepsArray
)
return
this
.
getStepValue
(
modelValue
)
return
this
.
getStepValue
(
modelValue
)
;
return
modelValue
;
return
modelValue
;
};
};
}
}
...
@@ -605,6 +611,14 @@
...
@@ -605,6 +611,14 @@
this
.
manageEventsBindings
();
this
.
manageEventsBindings
();
this
.
setDisabledState
();
this
.
setDisabledState
();
this
.
calcViewDimensions
();
this
.
calcViewDimensions
();
this
.
refocusPointerIfNeeded
();
},
refocusPointerIfNeeded
:
function
()
{
if
(
this
.
currentFocusElement
)
{
this
.
onPointerFocus
(
this
.
currentFocusElement
.
pointer
,
this
.
currentFocusElement
.
ref
);
this
.
focusElement
(
this
.
currentFocusElement
.
pointer
)
}
},
},
/**
/**
...
@@ -1070,7 +1084,7 @@
...
@@ -1070,7 +1084,7 @@
};
};
}
}
if
(
this
.
options
.
autoHideLimitLabels
)
{
if
(
this
.
options
.
autoHideLimitLabels
)
{
this
.
shFloorCeil
();
this
.
shFloorCeil
();
}
}
},
},
...
@@ -1092,7 +1106,7 @@
...
@@ -1092,7 +1106,7 @@
backgroundColor
:
pointercolor
backgroundColor
:
pointercolor
};
};
}
}
if
(
this
.
options
.
autoHideLimitLabels
)
{
if
(
this
.
options
.
autoHideLimitLabels
)
{
this
.
shFloorCeil
();
this
.
shFloorCeil
();
}
}
...
@@ -1695,6 +1709,11 @@
...
@@ -1695,6 +1709,11 @@
pointer
.
on
(
'keyup'
,
angular
.
bind
(
this
,
this
.
onKeyUp
));
pointer
.
on
(
'keyup'
,
angular
.
bind
(
this
,
this
.
onKeyUp
));
this
.
firstKeyDown
=
true
;
this
.
firstKeyDown
=
true
;
pointer
.
addClass
(
'rz-active'
);
pointer
.
addClass
(
'rz-active'
);
this
.
currentFocusElement
=
{
pointer
:
pointer
,
ref
:
ref
};
},
},
onKeyUp
:
function
()
{
onKeyUp
:
function
()
{
...
@@ -1707,6 +1726,7 @@
...
@@ -1707,6 +1726,7 @@
pointer
.
off
(
'keyup'
);
pointer
.
off
(
'keyup'
);
this
.
tracking
=
''
;
this
.
tracking
=
''
;
pointer
.
removeClass
(
'rz-active'
);
pointer
.
removeClass
(
'rz-active'
);
this
.
currentFocusElement
=
null
},
},
/**
/**
...
@@ -1925,7 +1945,7 @@
...
@@ -1925,7 +1945,7 @@
newMinValue
=
this
.
options
.
minLimit
;
newMinValue
=
this
.
options
.
minLimit
;
newMaxValue
=
newMinValue
+
this
.
dragging
.
difference
;
newMaxValue
=
newMinValue
+
this
.
dragging
.
difference
;
}
}
if
(
this
.
options
.
maxLimit
!=
null
&&
newMaxValue
>
this
.
options
.
maxLimit
){
if
(
this
.
options
.
maxLimit
!=
null
&&
newMaxValue
>
this
.
options
.
maxLimit
)
{
newMaxValue
=
this
.
options
.
maxLimit
;
newMaxValue
=
this
.
options
.
maxLimit
;
newMinValue
=
newMaxValue
-
this
.
dragging
.
difference
;
newMinValue
=
newMaxValue
-
this
.
dragging
.
difference
;
}
}
...
...
dist/rzslider.min.js
View file @
8cbdc467
This diff is collapsed.
Click to expand it.
src/rzslider.js
View file @
8cbdc467
...
@@ -308,6 +308,11 @@
...
@@ -308,6 +308,11 @@
*/
*/
this
.
cmbLabelShown
=
false
;
this
.
cmbLabelShown
=
false
;
/**
* Internal variable to keep track of the focus element
*/
this
.
currentFocusElement
=
null
;
// Slider DOM elements wrapped in jqLite
// Slider DOM elements wrapped in jqLite
this
.
fullBar
=
null
;
// The whole slider bar
this
.
fullBar
=
null
;
// The whole slider bar
this
.
selBar
=
null
;
// Highlight between two handles
this
.
selBar
=
null
;
// Highlight between two handles
...
@@ -417,6 +422,7 @@
...
@@ -417,6 +422,7 @@
this
.
scope
.
$on
(
'$destroy'
,
function
()
{
this
.
scope
.
$on
(
'$destroy'
,
function
()
{
self
.
unbindEvents
();
self
.
unbindEvents
();
angular
.
element
(
$window
).
off
(
'resize'
,
calcDimFn
);
angular
.
element
(
$window
).
off
(
'resize'
,
calcDimFn
);
self
.
currentFocusElement
=
null
;
});
});
},
},
...
@@ -581,7 +587,7 @@
...
@@ -581,7 +587,7 @@
else
{
else
{
this
.
customTrFn
=
function
(
modelValue
)
{
this
.
customTrFn
=
function
(
modelValue
)
{
if
(
this
.
options
.
bindIndexForStepsArray
)
if
(
this
.
options
.
bindIndexForStepsArray
)
return
this
.
getStepValue
(
modelValue
)
return
this
.
getStepValue
(
modelValue
)
;
return
modelValue
;
return
modelValue
;
};
};
}
}
...
@@ -609,6 +615,14 @@
...
@@ -609,6 +615,14 @@
this
.
manageEventsBindings
();
this
.
manageEventsBindings
();
this
.
setDisabledState
();
this
.
setDisabledState
();
this
.
calcViewDimensions
();
this
.
calcViewDimensions
();
this
.
refocusPointerIfNeeded
();
},
refocusPointerIfNeeded
:
function
()
{
if
(
this
.
currentFocusElement
)
{
this
.
onPointerFocus
(
this
.
currentFocusElement
.
pointer
,
this
.
currentFocusElement
.
ref
);
this
.
focusElement
(
this
.
currentFocusElement
.
pointer
)
}
},
},
/**
/**
...
@@ -1074,7 +1088,7 @@
...
@@ -1074,7 +1088,7 @@
};
};
}
}
if
(
this
.
options
.
autoHideLimitLabels
)
{
if
(
this
.
options
.
autoHideLimitLabels
)
{
this
.
shFloorCeil
();
this
.
shFloorCeil
();
}
}
},
},
...
@@ -1096,7 +1110,7 @@
...
@@ -1096,7 +1110,7 @@
backgroundColor
:
pointercolor
backgroundColor
:
pointercolor
};
};
}
}
if
(
this
.
options
.
autoHideLimitLabels
)
{
if
(
this
.
options
.
autoHideLimitLabels
)
{
this
.
shFloorCeil
();
this
.
shFloorCeil
();
}
}
...
@@ -1699,6 +1713,11 @@
...
@@ -1699,6 +1713,11 @@
pointer
.
on
(
'keyup'
,
angular
.
bind
(
this
,
this
.
onKeyUp
));
pointer
.
on
(
'keyup'
,
angular
.
bind
(
this
,
this
.
onKeyUp
));
this
.
firstKeyDown
=
true
;
this
.
firstKeyDown
=
true
;
pointer
.
addClass
(
'rz-active'
);
pointer
.
addClass
(
'rz-active'
);
this
.
currentFocusElement
=
{
pointer
:
pointer
,
ref
:
ref
};
},
},
onKeyUp
:
function
()
{
onKeyUp
:
function
()
{
...
@@ -1711,6 +1730,7 @@
...
@@ -1711,6 +1730,7 @@
pointer
.
off
(
'keyup'
);
pointer
.
off
(
'keyup'
);
this
.
tracking
=
''
;
this
.
tracking
=
''
;
pointer
.
removeClass
(
'rz-active'
);
pointer
.
removeClass
(
'rz-active'
);
this
.
currentFocusElement
=
null
},
},
/**
/**
...
@@ -1929,7 +1949,7 @@
...
@@ -1929,7 +1949,7 @@
newMinValue
=
this
.
options
.
minLimit
;
newMinValue
=
this
.
options
.
minLimit
;
newMaxValue
=
newMinValue
+
this
.
dragging
.
difference
;
newMaxValue
=
newMinValue
+
this
.
dragging
.
difference
;
}
}
if
(
this
.
options
.
maxLimit
!=
null
&&
newMaxValue
>
this
.
options
.
maxLimit
){
if
(
this
.
options
.
maxLimit
!=
null
&&
newMaxValue
>
this
.
options
.
maxLimit
)
{
newMaxValue
=
this
.
options
.
maxLimit
;
newMaxValue
=
this
.
options
.
maxLimit
;
newMinValue
=
newMaxValue
-
this
.
dragging
.
difference
;
newMinValue
=
newMaxValue
-
this
.
dragging
.
difference
;
}
}
...
...
tests/specs/keyboard-controls/specific-test.js
View file @
8cbdc467
...
@@ -241,6 +241,26 @@
...
@@ -241,6 +241,26 @@
helper
.
pressKeydown
(
helper
.
slider
.
minH
,
'RIGHT'
);
helper
.
pressKeydown
(
helper
.
slider
.
minH
,
'RIGHT'
);
expect
(
helper
.
scope
.
slider
.
value
).
to
.
equal
(
90
);
expect
(
helper
.
scope
.
slider
.
value
).
to
.
equal
(
90
);
});
});
it
(
'should refocus the slider after a reset if needed and still handle keyboard'
,
function
()
{
var
sliderConf
=
{
value
:
90
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
1
}
};
helper
.
createSlider
(
sliderConf
);
//try to move minH right
helper
.
slider
.
minH
.
triggerHandler
(
'focus'
);
helper
.
slider
.
resetSlider
();
helper
.
pressKeydown
(
helper
.
slider
.
minH
,
'RIGHT'
);
expect
(
document
.
activeElement
).
to
.
equal
(
helper
.
slider
.
minH
[
0
]);
expect
(
helper
.
scope
.
slider
.
value
).
to
.
equal
(
91
);
});
});
});
describe
(
'Right to left Keyboard controls - specific tests'
,
function
()
{
describe
(
'Right to left Keyboard controls - specific tests'
,
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment