Commit b583a4e7 by Valera Rozuvan

Optimizing code. Caching an element selector.

parent 99ae6377
...@@ -77,6 +77,8 @@ function () { ...@@ -77,6 +77,8 @@ function () {
* @returns {undefined} * @returns {undefined}
*/ */
function _bindHandlers(state) { function _bindHandlers(state) {
var speedLinks;
state.videoSpeedControl.videoSpeedsEl.find('a') state.videoSpeedControl.videoSpeedsEl.find('a')
.on('click', state.videoSpeedControl.changeVideoSpeed); .on('click', state.videoSpeedControl.changeVideoSpeed);
...@@ -146,15 +148,16 @@ function () { ...@@ -146,15 +148,16 @@ function () {
// ****************************** // ******************************
// Attach 'focus', and 'blur' events to elements which represent // Attach 'focus', and 'blur' events to elements which represent
// individual speed entries. // individual speed entries.
state.videoSpeedControl.videoSpeedsEl.find('a.speed_link:last') speedLinks = state.videoSpeedControl.videoSpeedsEl
.on('blur', function () { .find('a.speed_link');
speedLinks.last().on('blur', function () {
// If we have reached the last speed entry, and the focus // If we have reached the last speed entry, and the focus
// changes to the next element, we need to hide the speeds // changes to the next element, we need to hide the speeds
// control drop-down. // control drop-down.
state.videoSpeedControl.el.removeClass('open'); state.videoSpeedControl.el.removeClass('open');
}); });
state.videoSpeedControl.videoSpeedsEl.find('a.speed_link:first') speedLinks.first().on('blur', function () {
.on('blur', function () {
// This flag will indicate that the focus to the next // This flag will indicate that the focus to the next
// element that will receive it is comming from the first // element that will receive it is comming from the first
// speed entry. // speed entry.
...@@ -163,8 +166,7 @@ function () { ...@@ -163,8 +166,7 @@ function () {
// tabbing backwards. // tabbing backwards.
state.firstSpeedBlur = true; state.firstSpeedBlur = true;
}); });
state.videoSpeedControl.videoSpeedsEl.find('a.speed_link') speedLinks.on('focus', function () {
.on('focus', function () {
// Clear the flag which is only set when we are un-focusing // Clear the flag which is only set when we are un-focusing
// (the blur event) from the first speed entry. // (the blur event) from the first speed entry.
state.firstSpeedBlur = false; state.firstSpeedBlur = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment