-
Notifications
You must be signed in to change notification settings - Fork 19
HW1 #22
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
HW1 #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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>'); | ||
|
|
||
|
|
@@ -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(); | ||
| } | ||
| }); | ||
|
|
@@ -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()); | ||
|
|
@@ -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); | ||
| 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); | ||
|
|
@@ -72,38 +78,41 @@ | |
|
|
||
| function open() { | ||
| $dropdown.removeClass('no_transition'); | ||
| $dropdown.data('status', 'open")' | ||
| $dropdown.data('status', "open"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -115,9 +124,9 @@ | |
| }); | ||
|
|
||
| $toggle.on('click', toggleDropdown); | ||
| this.open = open; | ||
| this.close = close; | ||
| this.setDropdownHeight = setDropdownHeight; | ||
| this.open = open(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment.
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.