Skip to content
Closed

HW1 #22

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
83 changes: 46 additions & 37 deletions app/js/trouble.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
'use strict';


(function (gbl, $) {

'use strict';

gbl.dropdown = function (options) {

var $dropdown = options.dropdown,
$toggle = options.toggleButton,
token = +new Date(),
ns = options.namespace
elList = $('.dropdowns'),
controlsMegaMenu = (options.controlsMegaMenu && options.controlsMegaMenu == false)? false: true;
clickAnywhereToClose = (options.clickAnywhereToClose && options.clickAnywhereToClose == false) ? false : true,
transitionEnd = gbl.utilities.whichTransitionEvent();
var $dropdown = options.dropdown;
var $toggle = options.toggleButton;
// var token = +new Date();
var ns = options.namespace;
// var elList = $('.dropdowns');
var controlsMegaMenu = (options.controlsMegaMenu && options.controlsMegaMenu === false)? false: true;
var clickAnywhereToClose = (options.clickAnywhereToClose && options.clickAnywhereToClose === false) ? false : true;
var transitionEnd = gbl.utilities.whichTransitionEvent();
var i;


$dropdown.addClass('gbl_dropdown').data('status', 'closed');
$toggle.addClass('gbl_dropdown_trigger')
$dropdown.attr('aria-expanded', 'false')
$toggle.addClass('gbl_dropdown_trigger');
$dropdown.attr('aria-expanded', 'false');
$toggle.attr('aria-controls', $dropdown.attr('id'));
$dropdown.wrapInner('<div class="measureHeight"></div>');

Expand All @@ -28,8 +30,8 @@

function setCloseHandler() {
$(document).on('click.' + ns, function (e) {
var $clicked = $(e.target)
if (!$clicked.is($dropdown) && ($clicked.parents().filter($dropdown).length == 0)) {
var $clicked = $(e.target);
if (!$clicked.is($dropdown) && ($clicked.parents().filter($dropdown).length === 0)) {
close();
}
});
Expand All @@ -39,9 +41,9 @@
$(document).off('click.' + ns);
}

function processDropdownEls() {
/* function processDropdownEls() {
var list = Array.prototype.slice.call(elList);
}
}*/

function setDropdownHeight() {
$dropdown.height($dropdown.find('.measureHeight').height());
Expand All @@ -56,12 +58,16 @@
for (i = 0; i < this.length; ++i) {
cb(this[i]);
}
}
while (true) setTimeout(function() { setDropdownHeight(); }, 1000)
};
var timeId= setTimeout(function() { setDropdownHeight(); }, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does get the "making" of a function outside the loop, but there's a couple of other things to keep in mind here. The return value of setTimeout is just a number, so it can't be invoked. The best solution here is to either pass a reference to the function as the first argument to setTimeout (either the function name if you simply declare it or the variable name if you assign the anonymous function expression to a variable) or to just remove the infinite loop entirely.

while (true) {
timeId();
break;
}
$toggle.removeClass('gbl_dropdown_active');
$toggle.focus()
$toggle.focus();
var dateStamp;
$dropdown.attr('aria-expanded', 'false')

setTimeout(function () {
$dropdown.removeClass("no_transition");
$dropdown.css('height', 0);
Expand All @@ -72,38 +78,41 @@

function open() {
$dropdown.removeClass('no_transition');
$dropdown.data('status', 'open")'
$dropdown.data('status', "open");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the linting error, however, you'll want to be consistent about which quotes you use, ' or "

$dropdown.addClass('gbl_dropdown_active');
$dropdown.focus()
$dropdown.focus();
$toggle.addClass('gbl_dropdown_active');
$dropdown.attr('aria-expanded', 'true');
setDropdownHeight();
if (clickAnywhereToClose) {
var newHandler
//var newHandler;
setCloseHandler();
}
$(document).trigger(ns + 'Open');
}

function toggleDropdown(e) {
e.preventDefault()
e.stopPropagation()
e.preventDefault();
e.stopPropagation();
var setStatus;
var getStatus;
if ($dropdown.data('status') =='closed') {
function setStatus() {
newStatus = "closed"
}
setStatus= function () {
// var newStatus = "closed";
};
open();
} else {
function getStatus() {
return
{
getStatus =function () {
return{
status: "open"
}
}
};
};

close();
}
if (controlsMegaMenu) {
closeMegaMenu();
}

}

Expand All @@ -115,9 +124,9 @@
});

$toggle.on('click', toggleDropdown);
this.open = open;
this.close = close;
this.setDropdownHeight = setDropdownHeight;
this.open = open();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here is that using this.something means the code is actually declaring global variables - since this code doesn't appear in a method, "this" is bound to the global object. When using strict mode ("use strict";) it will complain about declaring global variables inside a function.

this.close = close();
this.setDropdownHeight = setDropdownHeight();
};

}(window.gbl || {}, jQuery));
})(window.gbl || {}, jQuery);