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,29 +148,29 @@ function () { ...@@ -146,29 +148,29 @@ 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');
// If we have reached the last speed entry, and the focus
// changes to the next element, we need to hide the speeds speedLinks.last().on('blur', function () {
// control drop-down. // If we have reached the last speed entry, and the focus
state.videoSpeedControl.el.removeClass('open'); // changes to the next element, we need to hide the speeds
}); // control drop-down.
state.videoSpeedControl.videoSpeedsEl.find('a.speed_link:first') state.videoSpeedControl.el.removeClass('open');
.on('blur', function () { });
// This flag will indicate that the focus to the next speedLinks.first().on('blur', function () {
// element that will receive it is comming from the first // This flag will indicate that the focus to the next
// speed entry. // element that will receive it is comming from the first
// // speed entry.
// This flag will be used to correctly handle scenario of //
// tabbing backwards. // This flag will be used to correctly handle scenario of
state.firstSpeedBlur = true; // tabbing backwards.
}); state.firstSpeedBlur = true;
state.videoSpeedControl.videoSpeedsEl.find('a.speed_link') });
.on('focus', function () { speedLinks.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