History

Use Array.includes and String.includes

Simon Legner committed 2 years ago

Commit 82fd7e61 parent f36465910 files · +27 −49Browse files

Unified · Split

10 files
  1. assets/javascripts/app/app.js +4 −8
  2. assets/javascripts/app/searcher.js +1 −1
  3. assets/javascripts/app/settings.js +3 −3
  4. assets/javascripts/debug.js +1 −1
  5. assets/javascripts/lib/events.js +2 −2
  6. assets/javascripts/lib/page.js +1 −1
  7. assets/javascripts/lib/util.js +9 −27
  8. assets/javascripts/views/layout/mobile.js +3 −3
  9. assets/javascripts/views/layout/settings.js +1 −1
  10. assets/javascripts/views/list/list_focus.js +2 −2
assets/javascripts/app/app.js+4−8
@@ -119,7 +119,7 @@ class App extends Events { · 118 unmodified lines
119 bootAll() {119 bootAll() {
120 const docs = this.settings.getDocs();120 const docs = this.settings.getDocs();
121 for (var doc of this.DOCS) {121 for (var doc of this.DOCS) {
122 (docs.indexOf(doc.slug) >= 0 ? this.docs : this.disabledDocs).add(doc);122 (docs.includes(doc.slug) ? this.docs : this.disabledDocs).add(doc);
123 }123 }
124 this.migrateDocs();124 this.migrateDocs();
125 this.docs.load(this.start.bind(this), this.onBootError.bind(this), {125 this.docs.load(this.start.bind(this), this.onBootError.bind(this), {
@@ -267,7 +267,7 @@ class App extends Events { · 141 unmodified lines
267 return;267 return;
268 }268 }
269 const tips = this.settings.getTips();269 const tips = this.settings.getTips();
270 if (tips.indexOf(tip) === -1) {270 if (!tips.includes(tip)) {
271 tips.push(tip);271 tips.push(tip);
272 this.settings.setTips(tips);272 this.settings.setTips(tips);
273 new app.views.Tip(tip);273 new app.views.Tip(tip);
@@ -358,11 +358,7 @@ Please check your browser extensions/addons. `); · 84 unmodified lines
358 358
359 isAppError(error, file) {359 isAppError(error, file) {
360 // Ignore errors from external scripts.360 // Ignore errors from external scripts.
361 return (361 return file && file.includes("devdocs") && file.endsWith(".js");
362 file &&
363 file.indexOf("devdocs") !== -1 &&
364 file.indexOf(".js") === file.length - 3
365 );
366 }362 }
367 363
368 isSupportedBrowser() {364 isSupportedBrowser() {
@@ -414,7 +410,7 @@ Please check your browser extensions/addons. `); · 45 unmodified lines
414 isInvalidLocation() {410 isInvalidLocation() {
415 return (411 return (
416 this.config.env === "production" &&412 this.config.env === "production" &&
417 location.host.indexOf(app.config.production_host) !== 0413 !location.host.startsWith(app.config.production_host)
418 );414 );
419 }415 }
420}416}
assets/javascripts/app/searcher.js+1−1
@@ -106,7 +106,7 @@ function scoreExactMatch() { · 105 unmodified lines
106}106}
107 107
108function fuzzyMatch() {108function fuzzyMatch() {
109 if (valueLength <= queryLength || value.indexOf(query) >= 0) {109 if (valueLength <= queryLength || value.includes(query)) {
110 return;110 return;
111 }111 }
112 if (!(match = fuzzyRegexp.exec(value))) {112 if (!(match = fuzzyRegexp.exec(value))) {
assets/javascripts/app/settings.js+3−3
@@ -109,7 +109,7 @@ app.Settings = class Settings { · 108 unmodified lines
109 $.arrayDelete(layout, "");109 $.arrayDelete(layout, "");
110 110
111 if (enable) {111 if (enable) {
112 if (layout.indexOf(name) === -1) {112 if (!layout.includes(name)) {
113 layout.push(name);113 layout.push(name);
114 }114 }
115 } else {115 } else {
@@ -125,7 +125,7 @@ app.Settings = class Settings { · 9 unmodified lines
125 125
126 hasLayout(name) {126 hasLayout(name) {
127 const layout = (this.store.get("layout") || "").split(" ");127 const layout = (this.store.get("layout") || "").split(" ");
128 return layout.indexOf(name) !== -1;128 return layout.includes(name);
129 }129 }
130 130
131 setSize(value) {131 setSize(value) {
@@ -155,7 +155,7 @@ app.Settings = class Settings { · 23 unmodified lines
155 }155 }
156 for (key in data) {156 for (key in data) {
157 value = data[key];157 value = data[key];
158 if (Settings.PREFERENCE_KEYS.indexOf(key) !== -1) {158 if (Settings.PREFERENCE_KEYS.includes(key)) {
159 this.set(key, value);159 this.set(key, value);
160 }160 }
161 }161 }
assets/javascripts/debug.js+1−1
@@ -75,7 +75,7 @@ this.viewTree = function (view, level, visited) { · 74 unmodified lines
75 if (visited == null) {75 if (visited == null) {
76 visited = [];76 visited = [];
77 }77 }
78 if (visited.indexOf(view) >= 0) {78 if (visited.includes(view)) {
79 return;79 return;
80 }80 }
81 visited.push(view);81 visited.push(view);
assets/javascripts/lib/events.js+2−2
@@ -1,6 +1,6 @@
1class Events {1class Events {
2 on(event, callback) {2 on(event, callback) {
3 if (event.indexOf(" ") >= 0) {3 if (event.includes(" ")) {
4 for (var name of event.split(" ")) {4 for (var name of event.split(" ")) {
5 this.on(name, callback);5 this.on(name, callback);
6 }6 }
@@ -14,7 +14,7 @@ class Events { · 7 unmodified lines
14 14
15 off(event, callback) {15 off(event, callback) {
16 let callbacks, index;16 let callbacks, index;
17 if (event.indexOf(" ") >= 0) {17 if (event.includes(" ")) {
18 for (var name of event.split(" ")) {18 for (var name of event.split(" ")) {
19 this.off(name, callback);19 this.off(name, callback);
20 }20 }
assets/javascripts/lib/page.js+1−1
@@ -284,7 +284,7 @@ var onclick = function (event) { · 283 unmodified lines
284};284};
285 285
286var isSameOrigin = (url) =>286var isSameOrigin = (url) =>
287 url.indexOf(`${location.protocol}//${location.hostname}`) === 0;287 url.startsWith(`${location.protocol}//${location.hostname}`);
288 288
289var updateCanonicalLink = function () {289var updateCanonicalLink = function () {
290 if (!this.canonicalLink) {290 if (!this.canonicalLink) {
assets/javascripts/lib/util.js+9−27
@@ -61,7 +61,7 @@ $.on = function (el, event, callback, useCapture) { · 60 unmodified lines
61 if (useCapture == null) {61 if (useCapture == null) {
62 useCapture = false;62 useCapture = false;
63 }63 }
64 if (event.indexOf(" ") >= 0) {64 if (event.includes(" ")) {
65 for (var name of event.split(" ")) {65 for (var name of event.split(" ")) {
66 $.on(el, name, callback);66 $.on(el, name, callback);
67 }67 }
@@ -74,7 +74,7 @@ $.off = function (el, event, callback, useCapture) { · 6 unmodified lines
74 if (useCapture == null) {74 if (useCapture == null) {
75 useCapture = false;75 useCapture = false;
76 }76 }
77 if (event.indexOf(" ") >= 0) {77 if (event.includes(" ")) {
78 for (var name of event.split(" ")) {78 for (var name of event.split(" ")) {
79 $.off(el, name, callback);79 $.off(el, name, callback);
80 }80 }
@@ -520,55 +520,37 @@ $.popup = function (value) { · 439 unmodified lines
520 520
521let isMac = null;521let isMac = null;
522$.isMac = () =>522$.isMac = () =>
523 isMac != null523 isMac != null ? isMac : (isMac = navigator.userAgent.includes("Mac"));
524 ? isMac
525 : (isMac =
526 (navigator.userAgent != null
527 ? navigator.userAgent.indexOf("Mac")
528 : undefined) >= 0);
529 524
530let isIE = null;525let isIE = null;
531$.isIE = () =>526$.isIE = () =>
532 isIE != null527 isIE != null
533 ? isIE528 ? isIE
534 : (isIE =529 : (isIE =
535 (navigator.userAgent != null530 navigator.userAgent.includes("MSIE") ||
536 ? navigator.userAgent.indexOf("MSIE")531 navigator.userAgent.includes("rv:11.0"));
537 : undefined) >= 0 ||
538 (navigator.userAgent != null
539 ? navigator.userAgent.indexOf("rv:11.0")
540 : undefined) >= 0);
541 532
542let isChromeForAndroid = null;533let isChromeForAndroid = null;
543$.isChromeForAndroid = () =>534$.isChromeForAndroid = () =>
544 isChromeForAndroid != null535 isChromeForAndroid != null
545 ? isChromeForAndroid536 ? isChromeForAndroid
546 : (isChromeForAndroid =537 : (isChromeForAndroid =
547 (navigator.userAgent != null538 navigator.userAgent.includes("Android") &&
548 ? navigator.userAgent.indexOf("Android")
549 : undefined) >= 0 &&
550 /Chrome\/([.0-9])+ Mobile/.test(navigator.userAgent));539 /Chrome\/([.0-9])+ Mobile/.test(navigator.userAgent));
551 540
552let isAndroid = null;541let isAndroid = null;
553$.isAndroid = () =>542$.isAndroid = () =>
554 isAndroid != null543 isAndroid != null
555 ? isAndroid544 ? isAndroid
556 : (isAndroid =545 : (isAndroid = navigator.userAgent.includes("Android"));
557 (navigator.userAgent != null
558 ? navigator.userAgent.indexOf("Android")
559 : undefined) >= 0);
560 546
561let isIOS = null;547let isIOS = null;
562$.isIOS = () =>548$.isIOS = () =>
563 isIOS != null549 isIOS != null
564 ? isIOS550 ? isIOS
565 : (isIOS =551 : (isIOS =
566 (navigator.userAgent != null552 navigator.userAgent.includes("iPhone") ||
567 ? navigator.userAgent.indexOf("iPhone")553 navigator.userAgent.includes("iPad"));
568 : undefined) >= 0 ||
569 (navigator.userAgent != null
570 ? navigator.userAgent.indexOf("iPad")
571 : undefined) >= 0);
572 554
573$.overlayScrollbarsEnabled = function () {555$.overlayScrollbarsEnabled = function () {
574 if (!$.isMac()) {556 if (!$.isMac()) {
assets/javascripts/views/layout/mobile.js+3−3
@@ -24,9 +24,9 @@ app.views.Mobile = class Mobile extends app.View { · 23 unmodified lines
24 .matches ||24 .matches ||
25 // Need to sniff the user agent because some Android and Windows Phone devices don't take25 // Need to sniff the user agent because some Android and Windows Phone devices don't take
26 // resolution (dpi) into account when reporting device width/height.26 // resolution (dpi) into account when reporting device width/height.
27 (navigator.userAgent.indexOf("Android") !== -1 &&27 (navigator.userAgent.includes("Android") &&
28 navigator.userAgent.indexOf("Mobile") !== -1) ||28 navigator.userAgent.includes("Mobile")) ||
29 navigator.userAgent.indexOf("IEMobile") !== -129 navigator.userAgent.includes("IEMobile")
30 );30 );
31 } catch (error) {31 } catch (error) {
32 return false;32 return false;
assets/javascripts/views/layout/settings.js+1−1
@@ -65,7 +65,7 @@ app.views.Settings = class Settings extends app.View { · 64 unmodified lines
65 (() => {65 (() => {
66 const result = [];66 const result = [];
67 for (var doc of app.docs.all()) {67 for (var doc of app.docs.all()) {
68 if (docs.indexOf(doc.slug) === -1) {68 if (!docs.includes(doc.slug)) {
69 result.push(doc);69 result.push(doc);
70 }70 }
71 }71 }
assets/javascripts/views/list/list_focus.js+2−2
@@ -56,7 +56,7 @@ app.views.ListFocus = class ListFocus extends app.View { · 55 unmodified lines
56 return this.findNext(cursor);56 return this.findNext(cursor);
57 } else if (next.tagName === "DIV") {57 } else if (next.tagName === "DIV") {
58 // sub-list58 // sub-list
59 if (cursor.className.indexOf(" open") >= 0) {59 if (cursor.className.includes(" open")) {
60 return this.findFirst(next) || this.findNext(next);60 return this.findFirst(next) || this.findNext(next);
61 } else {61 } else {
62 return this.findNext(next);62 return this.findNext(next);
@@ -96,7 +96,7 @@ app.views.ListFocus = class ListFocus extends app.View { · 33 unmodified lines
96 return this.findPrev(cursor);96 return this.findPrev(cursor);
97 } else if (prev.tagName === "DIV") {97 } else if (prev.tagName === "DIV") {
98 // sub-list98 // sub-list
99 if (prev.previousSibling.className.indexOf("open") >= 0) {99 if (prev.previousSibling.className.includes("open")) {
100 return this.findLast(prev) || this.findPrev(prev);100 return this.findLast(prev) || this.findPrev(prev);
101 } else {101 } else {
102 return this.findPrev(prev);102 return this.findPrev(prev);