Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json_field
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
json_field
Commits
b5e188d2
Commit
b5e188d2
authored
11 months ago
by
Patrick Kenny
Browse files
Options
Downloads
Plain Diff
Merge branch 'eslint' into '8.x-1.x'
fix eslint test See merge request
!29
parents
c4adef48
0bb98b67
No related branches found
No related tags found
No related merge requests found
Pipeline
#183455
failed
11 months ago
Stage: build
Stage: validate
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+2
-0
2 additions, 0 deletions
.gitlab-ci.yml
assets/js/json_field.js
+7
-9
7 additions, 9 deletions
assets/js/json_field.js
modules/json_field_widget/assets/js/json_widget.js
+27
-23
27 additions, 23 deletions
modules/json_field_widget/assets/js/json_widget.js
with
36 additions
and
32 deletions
.gitlab-ci.yml
+
2
−
0
View file @
b5e188d2
...
...
@@ -26,6 +26,8 @@ composer-lint:
allow_failure
:
false
cspell
:
allow_failure
:
false
eslint
:
allow_failure
:
false
phpcs
:
allow_failure
:
false
phpstan
:
...
...
This diff is collapsed.
Click to expand it.
assets/js/json_field.js
+
7
−
9
View file @
b5e188d2
...
...
@@ -4,15 +4,14 @@
*/
(
function
(
$
,
Drupal
,
drupalSettings
,
once
)
{
'
use strict
'
;
var
options
=
$
.
extend
(
drupalSettings
.
json_field
,
const
options
=
$
.
extend
(
drupalSettings
.
json_field
,
// Merge strings on top of drupalSettings so that they are not mutable.
{
strings
:
{
quickEdit
:
Drupal
.
t
(
'
Quick edit
'
)
}
}
quickEdit
:
Drupal
.
t
(
'
Quick edit
'
)
,
}
,
}
,
);
/**
...
...
@@ -21,12 +20,11 @@
* @type {Drupal~behavior}
*/
Drupal
.
behaviors
.
json_field
=
{
attach
:
function
(
context
)
{
attach
(
context
)
{
// Initialize the Quick Edit app once per page load.
$
(
once
(
'
json-field-init
'
,
'
pre.json-field
'
,
context
)).
each
(
function
()
{
$
(
this
).
parent
().
JSONView
(
$
(
this
).
parent
().
find
(
'
pre code
'
).
text
());
});
}
}
,
};
})(
jQuery
,
Drupal
,
drupalSettings
,
once
);
This diff is collapsed.
Click to expand it.
modules/json_field_widget/assets/js/json_widget.js
+
27
−
23
View file @
b5e188d2
...
...
@@ -4,13 +4,10 @@
*/
(
function
(
$
,
Drupal
,
drupalSettings
)
{
'
use strict
'
;
function
parseJson
(
string
)
{
try
{
return
JSON
.
parse
(
string
);
}
catch
(
e
)
{
}
catch
(
e
)
{
return
null
;
}
}
...
...
@@ -22,44 +19,51 @@
*/
Drupal
.
behaviors
.
json_widget
=
{
attach
(
context
)
{
$
(
once
(
'
json-editor
'
,
'
[data-json-editor]
'
,
context
))
.
each
(
function
(
index
,
element
)
{
var
$textarea
=
$
(
element
);
var
hash
=
$textarea
.
attr
(
'
data-json-editor
'
);
var
options
=
drupalSettings
.
json_field
[
hash
];
var
data
=
$textarea
.
val
()
;
var
json
=
parseJson
(
data
);
$
(
once
(
'
json-editor
'
,
'
[data-json-editor]
'
,
context
))
.
each
(
function
(
index
,
element
)
{
const
$textarea
=
$
(
element
);
const
hash
=
$textarea
.
attr
(
'
data-json-editor
'
);
const
options
=
drupalSettings
.
json_field
[
hash
];
const
data
=
$textarea
.
val
ue
;
const
json
=
parseJson
(
data
);
if
(
options
||
data
)
{
var
$editor
=
$
(
Drupal
.
theme
(
'
jsonEditorWrapper
'
,
'
json-editor-
'
+
$textarea
.
attr
(
'
name
'
)));
const
$editor
=
$
(
Drupal
.
theme
(
'
jsonEditorWrapper
'
,
`json-editor-
${
$textarea
.
attr
(
'
name
'
)}
`
,
),
);
$textarea
.
addClass
(
'
js-hide
'
);
$textarea
.
after
(
$editor
);
var
instanceOptions
=
{
const
instanceOptions
=
{
// Copy the data as-is in the textarea regardless of the
// validity of the JSON.
onChange
:
function
()
{
onChange
()
{
$textarea
.
text
(
jsonEditor
.
getText
());
}
}
,
};
if
(
options
.
schema
)
{
instanceOptions
.
schema
=
parseJson
(
options
.
schema
);
}
var
jsonEditor
=
new
JSONEditor
(
$editor
[
0
],
Object
.
assign
({},
options
,
instanceOptions
));
const
jsonEditor
=
new
JSONEditor
(
$editor
[
0
],
{
...
options
,
...
instanceOptions
,
});
if
(
json
)
{
jsonEditor
.
set
(
json
);
}
else
{
}
else
{
jsonEditor
.
setText
(
data
);
}
}
});
}
},
);
},
};
Drupal
.
theme
.
jsonEditorWrapper
=
function
(
id
)
{
return
'
<div style="width:100%;height:500px" id="
'
+
id
+
'
"></div>
'
;
}
return
`<div style="width:100%;height:500px" id="
${
id
}
"></div>`
;
};
})(
jQuery
,
Drupal
,
drupalSettings
);
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