Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf07405b

Browse files
committed
Ditch the [].forEach.call(NodeList) hack
Making the code more sensible and future-proof. Switching to usingcustom forEach method instead of the [].forEach.call(NodeList) hack.
1 parentb67a9af commitf07405b

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

‎client/src/helpers.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* exported addEvent, removeEvent, getChildren, setAttributes, addClass, removeClass */
1+
/* exported addEvent, removeEvent, getChildren, setAttributes, addClass, removeClass, forEach */
22
// fn arg can be an object or a function, thanks to handleEvent
33
// read more at: http://www.thecssninja.com/javascript/handleevent
44
varaddEvent=function(el,evt,fn,bubble){
@@ -84,4 +84,11 @@ var addEvent = function (el, evt, fn, bubble) {
8484
removeClass=function(el,cls){
8585
varreg=newRegExp("(\\s|^)"+cls+"(\\s|$)");
8686
el.className=el.className.replace(reg," ").replace(/(^\s*)|(\s*$)/g,"");
87+
},
88+
89+
// forEach method that passes back the stuff we need
90+
forEach=function(array,callback,scope){
91+
for(vari=0;i<array.length;i++){
92+
callback.call(scope,i,array[i]);
93+
}
8794
};

‎client/src/responsive-nav.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@
279279
},
280280

281281
_closeOnNavClick:function(){
282-
if(opts.closeOnNavClick&&"querySelectorAll"indocument&&Array.prototype.forEach){
282+
if(opts.closeOnNavClick&&"querySelectorAll"indocument){
283283
varlinks=nav.querySelectorAll("a"),
284284
self=this;
285-
[].forEach.call(links,function(el,i){
285+
forEach(links,function(i,el){
286286
addEvent(links[i],"click",function(){
287287
if(isMobile){
288288
self.toggle();

‎responsive-nav.js‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! responsive-nav.js 1.0.31
1+
/*! responsive-nav.js 1.0.32
22
* https://github.com/viljamis/responsive-nav.js
33
* http://responsive-nav.com
44
*
@@ -33,7 +33,7 @@
3333
returnthis;
3434
};
3535
}
36-
/* exported addEvent, removeEvent, getChildren, setAttributes, addClass, removeClass */
36+
/* exported addEvent, removeEvent, getChildren, setAttributes, addClass, removeClass, forEach */
3737
// fn arg can be an object or a function, thanks to handleEvent
3838
// read more at: http://www.thecssninja.com/javascript/handleevent
3939
varaddEvent=function(el,evt,fn,bubble){
@@ -119,6 +119,13 @@
119119
removeClass=function(el,cls){
120120
varreg=newRegExp("(\\s|^)"+cls+"(\\s|$)");
121121
el.className=el.className.replace(reg," ").replace(/(^\s*)|(\s*$)/g,"");
122+
},
123+
124+
// forEach method that passes back the stuff we need
125+
forEach=function(array,callback,scope){
126+
for(vari=0;i<array.length;i++){
127+
callback.call(scope,i,array[i]);
128+
}
122129
};
123130

124131
varnav,
@@ -385,10 +392,10 @@
385392
},
386393

387394
_closeOnNavClick:function(){
388-
if(opts.closeOnNavClick&&"querySelectorAll"indocument&&Array.prototype.forEach){
395+
if(opts.closeOnNavClick&&"querySelectorAll"indocument){
389396
varlinks=nav.querySelectorAll("a"),
390397
self=this;
391-
[].forEach.call(links,function(el,i){
398+
forEach(links,function(i,el){
392399
addEvent(links[i],"click",function(){
393400
if(isMobile){
394401
self.toggle();

‎responsive-nav.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp