Skip to content
This repository

JSHint file #9

Closed
wants to merge 4 commits into from

2 participants

Nick Schonning Mathias Bynens
Nick Schonning
  • Normalize mixed spaces and tabs to all tabs
  • Adds Use Strict directive
  • Strict equality comparisons
  • Bump version to 0.0.7
  • Re-minify using http://refresh-sf.com/yui/
Mathias Bynens mathiasbynens commented on the diff
jquery.details.js
((6 lines not shown))
114 114 // Wrap child text nodes in a `span` element
115 115 $detailsNotSummaryContents.filter(function() {
116 116 // Only keep the node in the collection if it’s a text node containing more than only whitespace
117 117 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character
118   - return this.nodeType == 3 && /[^ \t\n\f\r]/.test(this.data);
  118 + return this.nodeType === 3 && /[^ \t\n\f\r]/.test(this.data);
1
Mathias Bynens Owner

Why? A strict equality check is not needed (overkill) here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mathias Bynens mathiasbynens commented on the diff
jquery.details.js
@@ -110,12 +110,12 @@
110 110 }
111 111
112 112 // Look for direct child text nodes
113   - if ($detailsNotSummary.length != $detailsNotSummaryContents.length) {
  113 + if ($detailsNotSummary.length !== $detailsNotSummaryContents.length) {
1
Mathias Bynens Owner

Why? A strict equality check is not needed (overkill) here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mathias Bynens mathiasbynens commented on the diff
jquery.details.js
@@ -131,7 +131,7 @@
131 131 // Toggle the `open` and `aria-expanded` attributes and the `open` property of the `details` element and display the additional info
132 132 toggleOpen($details, $detailsSummary, $detailsNotSummary, true);
133 133 }).keyup(function(event) {
134   - if (32 == event.keyCode || (13 == event.keyCode && !isOpera)) {
  134 + if (event.keyCode === 32 || (event.keyCode === 13 && !isOpera)) {
1
Mathias Bynens Owner

Why? A strict equality check is not needed (overkill) here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mathias Bynens mathiasbynens commented on the diff
jquery.details.js
((3 lines not shown))
2 2 ;(function(document, $) {
3   -
  3 + "use strict";
1
Mathias Bynens Owner

Why? I don’t think strict mode matters for this code, or does it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mathias Bynens

I don’t “mix tabs and spaces” — I use tabs for indentation and spaces for presentational indentation. That way, the source code looks like I intended it to, regardless of editor settings.

Nick Schonning

Since the var goes from line 5 to 47, I think it is seeing that as one "line" so even turning on SmartTabs still causes it to give the warning.
Strict was mostly about style, but those comparisons don't need type coercion.
JSHint is more about style than function, but most of the rules can be all opted out selectively using a /* jshint */ directive at the top.

Nick Schonning

Closing since it has been 3 months and no response

Nick Schonning nschonni deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 56 additions and 56 deletions. Show diff stats Hide diff stats

  1. +54 54 jquery.details.js
  2. +2 2 jquery.details.min.js
108 jquery.details.js
... ... @@ -1,49 +1,49 @@
1   -/*! http://mths.be/details v0.0.6 by @mathias | includes http://mths.be/noselect v1.0.3 */
  1 +/*! http://mths.be/details v0.0.7 by @mathias | includes http://mths.be/noselect v1.0.3 */
2 2 ;(function(document, $) {
3   -
  3 + "use strict";
4 4 var proto = $.fn,
5   - details,
6   - // :'(
7   - isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]',
8   - // Feature test for native `<details>` support
9   - isDetailsSupported = (function(doc) {
10   - var el = doc.createElement('details'),
11   - fake,
12   - root,
13   - diff;
14   - if (!('open' in el)) {
15   - return false;
16   - }
17   - root = doc.body || (function() {
18   - var de = doc.documentElement;
19   - fake = true;
20   - return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild);
21   - }());
22   - el.innerHTML = '<summary>a</summary>b';
23   - el.style.display = 'block';
24   - root.appendChild(el);
25   - diff = el.offsetHeight;
26   - el.open = true;
27   - diff = diff != el.offsetHeight;
28   - root.removeChild(el);
29   - if (fake) {
30   - root.parentNode.removeChild(root);
31   - }
32   - return diff;
33   - }(document)),
34   - toggleOpen = function($details, $detailsSummary, $detailsNotSummary, toggle) {
35   - var isOpen = typeof $details.attr('open') == 'string',
36   - close = isOpen && toggle || !isOpen && !toggle;
37   - if (close) {
38   - $details.removeClass('open').prop('open', false).triggerHandler('close.details');
39   - $detailsSummary.attr('aria-expanded', false);
40   - $detailsNotSummary.hide();
41   - } else {
42   - $details.addClass('open').prop('open', true).triggerHandler('open.details');
43   - $detailsSummary.attr('aria-expanded', true);
44   - $detailsNotSummary.show();
45   - }
46   - };
  5 + details,
  6 + // :'(
  7 + isOpera = Object.prototype.toString.call(window.opera) === '[object Opera]',
  8 + // Feature test for native `<details>` support
  9 + isDetailsSupported = (function(doc) {
  10 + var el = doc.createElement('details'),
  11 + fake,
  12 + root,
  13 + diff;
  14 + if (!('open' in el)) {
  15 + return false;
  16 + }
  17 + root = doc.body || (function() {
  18 + var de = doc.documentElement;
  19 + fake = true;
  20 + return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild);
  21 + }());
  22 + el.innerHTML = '<summary>a</summary>b';
  23 + el.style.display = 'block';
  24 + root.appendChild(el);
  25 + diff = el.offsetHeight;
  26 + el.open = true;
  27 + diff = diff !== el.offsetHeight;
  28 + root.removeChild(el);
  29 + if (fake) {
  30 + root.parentNode.removeChild(root);
  31 + }
  32 + return diff;
  33 + }(document)),
  34 + toggleOpen = function($details, $detailsSummary, $detailsNotSummary, toggle) {
  35 + var isOpen = typeof $details.attr('open') === 'string',
  36 + close = isOpen && toggle || !isOpen && !toggle;
  37 + if (close) {
  38 + $details.removeClass('open').prop('open', false).triggerHandler('close.details');
  39 + $detailsSummary.attr('aria-expanded', false);
  40 + $detailsNotSummary.hide();
  41 + } else {
  42 + $details.addClass('open').prop('open', true).triggerHandler('open.details');
  43 + $detailsSummary.attr('aria-expanded', true);
  44 + $detailsNotSummary.show();
  45 + }
  46 + };
47 47
48 48 /* http://mths.be/noselect v1.0.3 */
49 49 proto.noSelect = function() {
@@ -71,7 +71,7 @@
71 71
72 72 return this.each(function() {
73 73 var $details = $(this),
74   - $summary = $('summary', $details).first();
  74 + $summary = $('summary', $details).first();
75 75 $summary.attr({
76 76 'role': 'button',
77 77 'aria-expanded': $details.prop('open')
@@ -96,12 +96,12 @@
96 96
97 97 // Store a reference to the current `details` element in a variable
98 98 var $details = $(this),
99   - // Store a reference to the `summary` element of the current `details` element (if any) in a variable
100   - $detailsSummary = $('summary', $details).first(),
101   - // Do the same for the info within the `details` element
102   - $detailsNotSummary = $details.children(':not(summary)'),
103   - // This will be used later to look for direct child text nodes
104   - $detailsNotSummaryContents = $details.contents(':not(summary)');
  99 + // Store a reference to the `summary` element of the current `details` element (if any) in a variable
  100 + $detailsSummary = $('summary', $details).first(),
  101 + // Do the same for the info within the `details` element
  102 + $detailsNotSummary = $details.children(':not(summary)'),
  103 + // This will be used later to look for direct child text nodes
  104 + $detailsNotSummaryContents = $details.contents(':not(summary)');
105 105
106 106 // If there is no `summary` in the current `details` element…
107 107 if (!$detailsSummary.length) {
@@ -110,12 +110,12 @@
110 110 }
111 111
112 112 // Look for direct child text nodes
113   - if ($detailsNotSummary.length != $detailsNotSummaryContents.length) {
  113 + if ($detailsNotSummary.length !== $detailsNotSummaryContents.length) {
114 114 // Wrap child text nodes in a `span` element
115 115 $detailsNotSummaryContents.filter(function() {
116 116 // Only keep the node in the collection if it’s a text node containing more than only whitespace
117 117 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character
118   - return this.nodeType == 3 && /[^ \t\n\f\r]/.test(this.data);
  118 + return this.nodeType === 3 && /[^ \t\n\f\r]/.test(this.data);
119 119 }).wrap('<span>');
120 120 // There are now no direct child text nodes anymore — they’re wrapped in `span` elements
121 121 $detailsNotSummary = $details.children(':not(summary)');
@@ -131,7 +131,7 @@
131 131 // Toggle the `open` and `aria-expanded` attributes and the `open` property of the `details` element and display the additional info
132 132 toggleOpen($details, $detailsSummary, $detailsNotSummary, true);
133 133 }).keyup(function(event) {
134   - if (32 == event.keyCode || (13 == event.keyCode && !isOpera)) {
  134 + if (event.keyCode === 32 || (event.keyCode === 13 && !isOpera)) {
135 135 // Space or Enter is pressed — trigger the `click` event on the `summary` element
136 136 // Opera already seems to trigger the `click` event when Enter is pressed
137 137 event.preventDefault();
4 jquery.details.min.js
... ... @@ -1,2 +1,2 @@
1   -/*! http://mths.be/details v0.0.6 by @mathias | includes http://mths.be/noselect v1.0.3 */
2   -;(function(a,$){var e=$.fn,d,c=Object.prototype.toString.call(window.opera)=='[object Opera]',f=(function(k){var i=k.createElement('details'),h,g,j;if(!('open' in i)){return false}g=k.body||(function(){var l=k.documentElement;h=true;return l.insertBefore(k.createElement('body'),l.firstElementChild||l.firstChild)}());i.innerHTML='<summary>a</summary>b';i.style.display='block';g.appendChild(i);j=i.offsetHeight;i.open=true;j=j!=i.offsetHeight;g.removeChild(i);if(h){g.parentNode.removeChild(g)}return j}(a)),b=function(h,k,j,g){var i=typeof h.attr('open')=='string',l=i&&g||!i&&!g;if(l){h.removeClass('open').prop('open',false).triggerHandler('close.details');k.attr('aria-expanded',false);j.hide()}else{h.addClass('open').prop('open',true).triggerHandler('open.details');k.attr('aria-expanded',true);j.show()}};e.noSelect=function(){var g='none';return this.bind('selectstart dragstart mousedown',function(){return false}).css({MozUserSelect:g,msUserSelect:g,webkitUserSelect:g,userSelect:g})};if(f){d=e.details=function(){return this.each(function(){var h=$(this),g=$('summary',h).first();g.attr({role:'button','aria-expanded':h.prop('open')}).on('click',function(){var i=h.prop('open');g.attr('aria-expanded',!i);h.triggerHandler((i?'close':'open')+'.details')})})};d.support=f}else{d=e.details=function(){return this.each(function(){var g=$(this),i=$('summary',g).first(),h=g.children(':not(summary)'),j=g.contents(':not(summary)');if(!i.length){i=$('<summary>').text('Details').prependTo(g)}if(h.length!=j.length){j.filter(function(){return this.nodeType==3&&/[^ \t\n\f\r]/.test(this.data)}).wrap('<span>');h=g.children(':not(summary)')}b(g,i,h);i.attr('role','button').noSelect().prop('tabIndex',0).on('click',function(){i.focus();b(g,i,h,true)}).keyup(function(k){if(32==k.keyCode||(13==k.keyCode&&!c)){k.preventDefault();i.click()}})})};d.support=f}}(document,jQuery));
  1 +/*! http://mths.be/details v0.0.7 by @mathias | includes http://mths.be/noselect v1.0.3 */
  2 +;(function(a,f){var e=f.fn,d,c=Object.prototype.toString.call(window.opera)==='[object Opera]',g=(function(l){var j=l.createElement('details'),i,h,k;if(!('open' in j)){return false;}h=l.body||(function(){var m=l.documentElement;i=true;return m.insertBefore(l.createElement('body'),m.firstElementChild||m.firstChild);}());j.innerHTML='<summary>a</summary>b';j.style.display='block';h.appendChild(j);k=j.offsetHeight;j.open=true;k=k!==j.offsetHeight;h.removeChild(j);if(i){h.parentNode.removeChild(h);}return k;}(a)),b=function(i,l,k,h){var j=typeof i.attr('open')==='string',m=j&&h||!j&&!h;if(m){i.removeClass('open').prop('open',false).triggerHandler('close.details');l.attr('aria-expanded',false);k.hide();}else{i.addClass('open').prop('open',true).triggerHandler('open.details');l.attr('aria-expanded',true);k.show();}};e.noSelect=function(){var h='none';return this.bind('selectstart dragstart mousedown',function(){return false;}).css({'MozUserSelect':h,'msUserSelect':h,'webkitUserSelect':h,'userSelect':h});};if(g){d=e.details=function(){return this.each(function(){var i=f(this),h=f('summary',i).first();h.attr({'role':'button','aria-expanded':i.prop('open')}).on('click',function(){var j=i.prop('open');h.attr('aria-expanded',!j);i.triggerHandler((j?'close':'open')+'.details');});});};d.support=g;}else{d=e.details=function(){return this.each(function(){var h=f(this),j=f('summary',h).first(),i=h.children(':not(summary)'),k=h.contents(':not(summary)');if(!j.length){j=f('<summary>').text('Details').prependTo(h);}if(i.length!==k.length){k.filter(function(){return this.nodeType===3&&/[^ \t\n\f\r]/.test(this.data);}).wrap('<span>');i=h.children(':not(summary)');}b(h,j,i);j.attr('role','button').noSelect().prop('tabIndex',0).on('click',function(){j.focus();b(h,j,i,true);}).keyup(function(l){if(l.keyCode===32||(l.keyCode===13&&!c)){l.preventDefault();j.click();}});});};d.support=g;}}(document,jQuery));

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.