FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
roadmap/app/javascript/src/utils/links.js at api-patch · DMPRoadmap/roadmap · GitHub
DMPRoadmap
roadmap
Repository navigation
Code
Issues
300
(300)
Pull requests
49
(49)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
roadmap
/
app
/
javascript
/
src
/
utils
/
links.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (90 loc) · 3.23 KB
Breadcrumbs
roadmap
/
app
/
javascript
/
src
/
utils
/
links.js
Copy path
File metadata and controls
96 lines (90 loc) · 3.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import
'number-to-text/converters/en-us'
;
import
{
convertToText
}
from
'number-to-text/index'
;
import
{
isFunction
}
from
'./isType'
;
const
getLinks
=
(
elem
)
=>
$
(
elem
)
.
find
(
'.link'
)
.
map
(
(
i
,
el
)
=>
{
const
link
=
$
(
el
)
;
// toggleValidations(link);
const
linkVal
=
link
.
find
(
'input[name="link_link"]'
)
.
val
(
)
;
const
textVal
=
link
.
find
(
'input[name="link_text"]'
)
.
val
(
)
;
if
(
linkVal
||
textVal
)
{
return
{
link
:
linkVal
,
text
:
textVal
}
;
}
// If linkVal and textVal are empty trigger delete handler
link
.
find
(
'.delete'
)
.
first
(
)
.
trigger
(
'click'
)
;
return
undefined
;
}
)
.
get
(
)
;
/*
* Iterates through any links class found and for each one found,
* executes the function cb by passing two parameters: the data-context value
* and value param being an Array of link objects (e.g. [{ link: String, text: String }, ...])
* that represent the values for the input texts introduced.
*/
export
const
eachLinks
=
(
cb
)
=>
{
if
(
isFunction
(
cb
)
)
{
$
(
'.links'
)
.
each
(
(
i
,
el
)
=>
{
cb
(
$
(
el
)
.
attr
(
'data-context'
)
,
getLinks
(
el
)
)
;
}
)
;
}
return
eachLinks
;
}
;
eachLinks
.
done
=
(
cb
)
=>
{
if
(
isFunction
(
cb
)
)
{
cb
(
)
;
}
}
;
$
(
(
)
=>
{
const
regExp
=
/
(
[
^
\d
]
*
)
(
\d
)
+
/
;
const
replacer
=
(
match
,
p1
,
p2
)
=>
`
${
p1
}
${
(
p2
*
1
)
+
1
}
`
;
const
replacerFor
=
(
i
,
el
)
=>
$
(
el
)
.
attr
(
'for'
,
$
(
el
)
.
attr
(
'for'
)
.
replace
(
regExp
,
replacer
)
)
;
const
replacerId
=
(
i
,
el
)
=>
$
(
el
)
.
attr
(
'id'
,
$
(
el
)
.
attr
(
'id'
)
.
replace
(
regExp
,
replacer
)
)
;
const
changeIds
=
(
jqueryElem
)
=>
{
jqueryElem
.
find
(
'label'
)
.
each
(
replacerFor
)
;
jqueryElem
.
find
(
'input[type="text"]'
)
.
each
(
replacerId
)
;
}
;
const
clearVals
=
(
jqueryElem
)
=>
{
jqueryElem
.
find
(
'input[type="text"]'
)
.
each
(
(
i
,
el
)
=>
{
$
(
el
)
.
val
(
''
)
;
}
)
;
}
;
const
linksLength
=
(
jqueryElem
)
=>
jqueryElem
.
closest
(
'.links'
)
.
find
(
'.link'
)
.
length
;
const
maxNumberLinks
=
(
jqueryElem
)
=>
jqueryElem
.
closest
(
'.links'
)
.
attr
(
'data-max-number-links'
)
*
1
;
$
(
'.links'
)
.
on
(
'click'
,
'.new'
,
(
e
)
=>
{
e
.
preventDefault
(
)
;
const
target
=
$
(
e
.
target
)
;
const
max
=
maxNumberLinks
(
target
)
;
const
nbrLinks
=
linksLength
(
target
)
;
if
(
nbrLinks
<
max
)
{
const
lastLink
=
target
.
closest
(
'.links'
)
.
find
(
'.link'
)
.
last
(
)
;
const
clonedLink
=
lastLink
.
clone
(
)
;
changeIds
(
clonedLink
)
;
clearVals
(
clonedLink
)
;
lastLink
.
after
(
clonedLink
)
;
// Hide the add link if we have now reached the limit
if
(
nbrLinks
+
1
>=
max
)
{
$
(
target
)
.
closest
(
'.links'
)
.
find
(
'a.new'
)
.
addClass
(
'hide'
)
;
}
}
}
)
;
$
(
'.links'
)
.
on
(
'click'
,
'.delete'
,
(
e
)
=>
{
e
.
preventDefault
(
)
;
const
target
=
$
(
e
.
target
)
;
const
max
=
maxNumberLinks
(
target
)
;
const
nbrLinks
=
linksLength
(
target
)
;
if
(
nbrLinks
>
1
)
{
// If this brought us below the max nbr of links then show the add new link
if
(
(
nbrLinks
-
1
)
<
max
)
{
target
.
closest
(
'.links'
)
.
find
(
'a.new'
)
.
removeClass
(
'hide'
)
;
}
target
.
closest
(
'.link'
)
.
remove
(
)
;
}
else
{
const
link
=
target
.
closest
(
'.link'
)
;
clearVals
(
link
)
;
}
}
)
;
$
(
'.links'
)
.
find
(
'.max-number-links'
)
.
each
(
(
i
,
el
)
=>
{
const
target
=
$
(
el
)
;
const
max
=
target
.
closest
(
'.links'
)
.
attr
(
'data-max-number-links'
)
;
target
.
text
(
convertToText
(
max
)
.
toLowerCase
(
)
)
;
}
)
;
}
)
;
export
{
eachLinks
as
default
}
;
Back
|
FazBrowse Home
|
New Git URL