Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
module_filter
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
module_filter
Commits
6c8d20bf
Commit
6c8d20bf
authored
1 year ago
by
Stephen Mustgrave
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3338338
: Javascript coding standards (winnow.js and module_filter.js)
parent
154b593e
No related branches found
No related tags found
1 merge request
!28
Issue #3338338: Javascript coding standards (winnow.js and module_filter.js)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/jquery.winnow.js
+105
-84
105 additions, 84 deletions
js/jquery.winnow.js
js/module_filter.js
+11
-13
11 additions, 13 deletions
js/module_filter.js
with
116 additions
and
97 deletions
js/jquery.winnow.js
+
105
−
84
View file @
6c8d20bf
...
...
@@ -3,21 +3,19 @@
* JQuery plugin to filter out elements based on user input.
*/
(
function
(
$
)
{
(
$
=>
{
var
now
=
Date
.
now
||
function
()
{
return
new
Date
().
getTime
();
};
const
now
=
()
=>
new
Date
().
getTime
()
||
Date
.
now
;
function
debounce
(
func
,
wait
,
immediate
)
{
var
timeout
;
var
args
;
var
context
;
var
timestamp
;
var
result
;
let
timeout
;
let
args
;
let
context
;
let
timestamp
;
let
result
;
var
later
=
function
()
{
var
last
=
now
()
-
timestamp
;
const
later
=
()
=>
{
const
last
=
now
()
-
timestamp
;
if
(
last
<
wait
&&
last
>=
0
)
{
timeout
=
setTimeout
(
later
,
wait
-
last
);
...
...
@@ -26,23 +24,25 @@
timeout
=
null
;
if
(
!
immediate
)
{
result
=
func
.
apply
(
context
,
args
);
if
(
!
timeout
)
{
args
=
context
=
null
;
}
// eslint-disable-next-line no-multi-assign
args
=
context
=
null
;
}
}
};
// eslint-disable-next-line func-names
return
function
()
{
context
=
this
;
// eslint-disable-next-line prefer-rest-params
args
=
arguments
;
timestamp
=
now
();
var
callNow
=
immediate
&&
!
timeout
;
const
callNow
=
immediate
&&
!
timeout
;
if
(
!
timeout
)
{
timeout
=
setTimeout
(
later
,
wait
);
}
if
(
callNow
)
{
result
=
func
.
apply
(
context
,
args
);
// eslint-disable-next-line no-multi-assign
args
=
context
=
null
;
}
...
...
@@ -51,7 +51,7 @@
}
function
explode
(
string
)
{
return
string
.
match
(
/
(\w
*
\
:(\w
+|"
[^
"
]
+"
)
*
)
|
\w
+|"
[^
"
]
+"/g
);
return
string
.
match
(
/
(\w
*:
(\w
+|"
[^
"
]
+"
)
*
)
|
\w
+|"
[^
"
]
+"/g
);
}
function
preventEnterKey
(
e
)
{
...
...
@@ -59,10 +59,11 @@
e
.
preventDefault
();
e
.
stopPropagation
();
}
}
;
}
var
Winnow
=
function
(
element
,
selector
,
options
)
{
var
self
=
this
;
// eslint-disable-next-line func-names
const
Winnow
=
function
(
element
,
selector
,
options
)
{
const
self
=
this
;
self
.
element
=
element
;
self
.
selector
=
selector
;
...
...
@@ -89,24 +90,23 @@
self
.
element
.
wrap
(
'
<div class="winnow-input"></div>
'
);
// Add clear button.
self
.
clearButton
=
$
(
'
<a href="#" class="winnow-clear">
'
+
self
.
options
.
clearLabel
+
'
</a>
'
);
self
.
clearButton
=
$
(
`
<a href="#" class="winnow-clear">
${
self
.
options
.
clearLabel
}
</a>
`
);
self
.
clearButton
.
css
({
'
display
'
:
'
inline-block
'
,
'
margin-left
'
:
'
0.75em
'
});
if
(
self
.
element
.
val
()
==
''
)
{
if
(
self
.
element
.
val
()
==
=
''
)
{
self
.
clearButton
.
hide
();
}
self
.
clearButton
.
click
(
function
(
e
)
{
self
.
clearButton
.
click
((
e
)
=>
{
e
.
preventDefault
();
self
.
clearFilter
();
});
self
.
element
.
after
(
self
.
clearButton
);
self
.
element
.
on
({
keyup
:
debounce
(
function
()
{
var
value
=
self
.
element
.
val
();
keyup
:
debounce
(
()
=>
{
const
value
=
self
.
element
.
val
();
if
(
!
value
||
explode
(
value
).
pop
().
slice
(
-
1
)
!==
'
:
'
)
{
// Only filter if we aren't using the operator autocomplete.
self
.
filter
();
...
...
@@ -115,9 +115,9 @@
keydown
:
preventEnterKey
});
self
.
element
.
on
({
keyup
:
function
()
{
keyup
()
{
// Show/hide the clear button.
if
(
self
.
element
.
val
()
!=
''
)
{
if
(
self
.
element
.
val
()
!=
=
''
)
{
self
.
clearButton
.
show
();
}
else
{
...
...
@@ -127,39 +127,41 @@
});
// Autocomplete operators. When last query is ":", return list of available
// operators
with the exception of
"text".
// operators
except
"text".
if
(
typeof
self
.
element
.
autocomplete
===
'
function
'
)
{
var
operators
=
Object
.
keys
(
self
.
getOperators
());
var
source
=
[];
for
(
var
i
in
operators
)
{
if
(
operators
[
i
]
!=
'
text
'
)
{
const
operators
=
Object
.
keys
(
self
.
getOperators
());
const
source
=
[];
for
(
let
i
=
0
;
i
<
operators
.
length
;
i
++
){
const
operator
=
operators
[
i
];
if
(
operator
!==
'
text
'
)
{
source
.
push
({
label
:
operator
s
[
i
]
,
value
:
operator
s
[
i
]
+
'
:
'
label
:
operator
,
value
:
`
${
operator
}
:`
});
}
}
self
.
element
.
autocomplete
({
'
search
'
:
function
(
event
)
{
if
(
explode
(
event
.
target
.
value
).
pop
()
!=
'
:
'
)
{
search
(
event
)
{
if
(
explode
(
event
.
target
.
value
).
pop
()
!=
=
'
:
'
)
{
return
false
;
}
},
'
source
'
:
function
(
request
,
response
)
{
source
(
request
,
response
)
{
return
response
(
source
);
},
'
select
'
:
function
(
event
,
ui
)
{
var
terms
=
explode
(
event
.
target
.
value
);
select
(
event
,
ui
)
{
const
terms
=
explode
(
event
.
target
.
value
);
// Remove the current input.
terms
.
pop
();
// Add the selected item.
terms
.
push
(
ui
.
item
.
value
);
event
.
target
.
value
=
terms
.
join
(
'
'
);
// Return false to tell jQuery UI that we've filled in the value already.
// Return false to tell jQuery UI that we've filled in the value
// already.
return
false
;
},
'
focus
'
:
function
()
{
focus
()
{
return
false
;
}
});
...
...
@@ -168,28 +170,30 @@
self
.
element
.
data
(
'
winnow
'
,
self
);
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
setQueries
=
function
(
string
)
{
var
self
=
this
;
var
strings
=
explode
(
string
);
const
self
=
this
;
const
strings
=
explode
(
string
);
self
.
text
=
string
;
self
.
queries
=
[];
for
(
var
i
in
strings
)
{
// eslint-disable-next-line no-restricted-syntax
for
(
const
i
in
strings
)
{
if
(
strings
.
hasOwnProperty
(
i
))
{
var
query
=
{
operator
:
'
text
'
,
string
:
strings
[
i
]
};
var
operators
=
self
.
getOperators
();
const
query
=
{
operator
:
'
text
'
,
string
:
strings
[
i
]
};
const
operators
=
self
.
getOperators
();
if
(
query
.
string
.
indexOf
(
'
:
'
)
>
0
)
{
var
parts
=
query
.
string
.
split
(
'
:
'
,
2
);
var
operator
=
parts
.
shift
();
const
parts
=
query
.
string
.
split
(
'
:
'
,
2
);
const
operator
=
parts
.
shift
();
if
(
operators
[
operator
]
!==
undefined
)
{
query
.
operator
=
operator
;
query
.
string
=
parts
.
shift
();
}
}
if
(
query
.
string
.
charAt
(
0
)
==
'
"
'
)
{
if
(
query
.
string
.
charAt
(
0
)
==
=
'
"
'
)
{
// Remove wrapping double quotes.
query
.
string
=
query
.
string
.
replace
(
/^"|"$/g
,
''
);
}
...
...
@@ -201,19 +205,22 @@
}
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
buildIndex
=
function
()
{
var
self
=
this
;
const
self
=
this
;
this
.
index
=
[];
// eslint-disable-next-line func-names
$
(
self
.
selector
,
self
.
wrapper
).
each
(
function
(
i
)
{
var
text
=
(
self
.
options
.
textSelector
)
?
$
(
self
.
options
.
textSelector
,
this
).
text
()
:
$
(
this
).
text
();
var
item
=
{
const
text
=
(
self
.
options
.
textSelector
)
?
$
(
self
.
options
.
textSelector
,
this
).
text
()
:
$
(
this
).
text
();
let
item
=
{
key
:
i
,
element
:
$
(
this
),
text
:
text
.
toLowerCase
()
};
for
(
var
j
in
self
.
options
.
buildIndex
)
{
// eslint-disable-next-line guard-for-in,no-restricted-syntax
for
(
const
j
in
self
.
options
.
buildIndex
)
{
item
=
$
.
extend
(
self
.
options
.
buildIndex
[
j
].
apply
(
this
,
[
item
]),
item
);
}
...
...
@@ -224,22 +231,28 @@
return
self
.
trigger
(
'
finishIndexing
'
,
[
self
]);
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
bind
=
function
()
{
var
args
=
arguments
;
args
[
0
]
=
'
winnow:
'
+
args
[
0
];
// eslint-disable-next-line prefer-rest-params
const
args
=
arguments
;
args
[
0
]
=
`winnow:
${
args
[
0
]}
`
;
// eslint-disable-next-line prefer-spread
return
this
.
element
.
bind
.
apply
(
this
.
element
,
args
);
};
Winnow
.
prototype
.
trigger
=
function
(
event
)
{
var
args
=
arguments
;
args
[
0
]
=
'
winnow:
'
+
args
[
0
];
// eslint-disable-next-line func-names
Winnow
.
prototype
.
trigger
=
function
()
{
// eslint-disable-next-line prefer-rest-params
const
args
=
arguments
;
args
[
0
]
=
`winnow:
${
args
[
0
]}
`
;
// eslint-disable-next-line prefer-spread
return
this
.
element
.
trigger
.
apply
(
this
.
element
,
args
);
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
filter
=
function
()
{
var
self
=
this
;
const
self
=
this
;
self
.
results
=
[];
self
.
setQueries
(
self
.
element
.
val
());
...
...
@@ -248,28 +261,27 @@
self
.
buildIndex
();
}
var
start
=
self
.
trigger
(
'
start
'
);
self
.
trigger
(
'
start
'
);
// eslint-disable-next-line func-names
$
.
each
(
self
.
index
,
function
(
key
,
item
)
{
var
$item
=
item
.
element
;
var
operatorMatch
=
true
;
const
$item
=
item
.
element
;
let
operatorMatch
=
true
;
if
(
self
.
text
!=
''
)
{
let
result
;
if
(
self
.
text
!==
''
)
{
operatorMatch
=
false
;
for
(
var
i
in
self
.
queries
)
{
var
query
=
self
.
queries
[
i
];
var
operators
=
self
.
getOperators
();
for
(
let
i
=
0
;
i
<
self
.
queries
.
length
;
i
++
)
{
const
query
=
self
.
queries
[
i
];
const
operators
=
self
.
getOperators
();
if
(
operators
[
query
.
operator
]
!==
undefined
)
{
result
=
operators
[
query
.
operator
].
apply
(
$item
,
[
query
.
string
,
item
]);
if
(
!
result
)
{
// Is not a text match so continue to next query string.
continue
;
if
(
result
)
{
operatorMatch
=
true
;
break
;
}
}
operatorMatch
=
true
;
break
;
}
}
...
...
@@ -284,10 +296,10 @@
$item
.
hide
();
});
var
finish
=
self
.
trigger
(
'
finish
'
,
[
self
.
results
]);
self
.
trigger
(
'
finish
'
,
[
self
.
results
]);
if
(
self
.
options
.
striping
)
{
stripe
();
self
.
stripe
();
}
if
(
self
.
options
.
emptyMessage
)
{
...
...
@@ -300,9 +312,10 @@
}
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
getOperators
=
function
()
{
return
$
.
extend
({},
{
text
:
function
(
string
,
item
)
{
text
(
string
,
item
)
{
if
(
item
.
text
.
indexOf
(
string
)
>=
0
)
{
return
true
;
}
...
...
@@ -310,13 +323,15 @@
},
this
.
options
.
additionalOperators
);
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
processRules
=
function
(
item
)
{
var
self
=
this
;
var
$item
=
item
.
element
;
var
result
=
true
;
const
self
=
this
;
const
$item
=
item
.
element
;
let
result
=
true
;
if
(
self
.
options
.
rules
.
length
>
0
)
{
for
(
var
i
in
self
.
options
.
rules
)
{
// eslint-disable-next-line guard-for-in,no-restricted-syntax
for
(
const
i
in
self
.
options
.
rules
)
{
result
=
self
.
options
.
rules
[
i
].
apply
(
$item
,
[
item
]);
if
(
result
===
false
)
{
break
;
...
...
@@ -327,10 +342,12 @@
return
result
;
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
stripe
=
function
()
{
var
flip
=
{
even
:
'
odd
'
,
odd
:
'
even
'
};
var
stripe
=
'
odd
'
;
const
flip
=
{
even
:
'
odd
'
,
odd
:
'
even
'
};
let
stripe
=
'
odd
'
;
// eslint-disable-next-line func-names
$
.
each
(
this
.
index
,
function
(
key
,
item
)
{
if
(
!
item
.
element
.
is
(
'
:visible
'
))
{
item
.
element
.
removeClass
(
'
odd even
'
).
addClass
(
stripe
);
...
...
@@ -339,6 +356,7 @@
});
};
// eslint-disable-next-line func-names
Winnow
.
prototype
.
clearFilter
=
function
()
{
this
.
element
.
val
(
''
);
this
.
filter
();
...
...
@@ -346,11 +364,14 @@
this
.
element
.
focus
();
};
// eslint-disable-next-line func-names
$
.
fn
.
winnow
=
function
(
selector
,
options
)
{
var
$input
=
this
.
not
(
'
.winnow-processed
'
).
addClass
(
'
winnow-processed
'
);
const
$input
=
this
.
not
(
'
.winnow-processed
'
).
addClass
(
'
winnow-processed
'
);
// eslint-disable-next-line func-names
$input
.
each
(
function
()
{
var
winnow
=
new
Winnow
(
$input
,
selector
,
options
);
// eslint-disable-next-line no-new
new
Winnow
(
$input
,
selector
,
options
);
});
return
this
;
...
...
This diff is collapsed.
Click to expand it.
js/module_filter.js
+
11
−
13
View file @
6c8d20bf
...
...
@@ -2,37 +2,35 @@
* @file
*/
(
function
(
$
,
Drupal
)
{
'
use strict
'
;
((
$
,
Drupal
)
=>
{
Drupal
.
ModuleFilter
=
Drupal
.
ModuleFilter
||
{};
Drupal
.
ModuleFilter
.
localStorage
=
{
getItem
:
function
(
key
)
{
getItem
(
key
)
{
if
(
typeof
Storage
!==
'
undefined
'
)
{
return
localStorage
.
getItem
(
'
moduleFilter.
'
+
key
);
return
localStorage
.
getItem
(
`
moduleFilter.
${
key
}
`
);
}
return
null
;
},
getBoolean
:
function
(
key
)
{
var
item
=
Drupal
.
ModuleFilter
.
localStorage
.
getItem
(
key
);
getBoolean
(
key
)
{
const
item
=
Drupal
.
ModuleFilter
.
localStorage
.
getItem
(
key
);
if
(
item
!=
null
)
{
return
(
item
==
'
true
'
);
return
(
item
==
=
'
true
'
);
}
return
null
;
},
setItem
:
function
(
key
,
data
)
{
setItem
(
key
,
data
)
{
if
(
typeof
Storage
!==
'
undefined
'
)
{
localStorage
.
setItem
(
'
moduleFilter.
'
+
key
,
data
)
localStorage
.
setItem
(
`
moduleFilter.
${
key
}
`
,
data
)
}
},
removeItem
:
function
(
key
)
{
removeItem
(
key
)
{
if
(
typeof
Storage
!==
'
undefined
'
)
{
localStorage
.
removeItem
(
'
moduleFilter.
'
+
key
);
localStorage
.
removeItem
(
`
moduleFilter.
${
key
}
`
);
}
}
};
...
...
@@ -41,7 +39,7 @@
* Filter enhancements.
*/
Drupal
.
behaviors
.
moduleFilter
=
{
attach
:
function
(
context
)
{
attach
(
)
{
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment