Skip to content

Commit 70215a4

Browse files
committed
feat: 移除 jquery
1 parent db6cb22 commit 70215a4

File tree

7 files changed

+90
-104
lines changed

7 files changed

+90
-104
lines changed

pom.xml

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<groupId>io.jenkins.plugins</groupId>
1111
<artifactId>dingding-notifications</artifactId>
12-
<version>2.7.1-SNAPSHOT</version>
12+
<version>2.7.1</version>
1313
<packaging>hpi</packaging>
1414
<properties>
1515
<jenkins.version>2.432</jenkins.version>
@@ -40,7 +40,7 @@
4040
<developerConnection>scm:git:git@github.com:jenkinsci/dingtalk-plugin.git
4141
</developerConnection>
4242
<url>https://github.com/jenkinsci/dingtalk-plugin</url>
43-
<tag>dingding-notifications-2.6.1</tag>
43+
<tag>dingding-notifications-2.7.1</tag>
4444
</scm>
4545

4646
<dependencies>
@@ -49,11 +49,6 @@
4949
<artifactId>workflow-cps</artifactId>
5050
<version>3565.v4b_d9b_8c29a_b_3</version>
5151
</dependency>
52-
<dependency>
53-
<groupId>io.jenkins.plugins</groupId>
54-
<artifactId>jquery3-api</artifactId>
55-
<version>3.7.1-1</version>
56-
</dependency>
5752
<dependency>
5853
<groupId>com.google.code.gson</groupId>
5954
<artifactId>gson</artifactId>

src/main/resources/io/jenkins/plugins/DingTalkNotifierConfig/config.jelly

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<f:entry title="停用" field="disabled">
1717
<f:checkbox checked="${instance.getDisabled()}"/>
1818
</f:entry>
19-
<f:entry title="禁用内置消息" field="raw" class="notifier-config-raw">
19+
<f:entry title="禁用内置消息" field="raw" class="dt-notifier-config-raw">
2020
<f:checkbox checked="${instance.getRaw()}"/>
2121
</f:entry>
2222
<f:entry title="通知时机" field="noticeOccasions">
@@ -36,12 +36,12 @@
3636
</j:scope>
3737
</j:forEach>
3838
</f:entry>
39-
<div class="raw-content">
39+
<div class="dt-raw-content-custom" style="display: none;">
4040
<f:entry field="message" title="自定义消息">
4141
<f:textarea/>
4242
</f:entry>
4343
</div>
44-
<div class="none-raw-content">
44+
<div class="dt-raw-content-builtin">
4545
<f:entry title="通知人" field="at">
4646
<f:checkbox title="atAll" field="atAll"/>
4747
<f:textarea field="atMobile"/>

src/main/resources/io/jenkins/plugins/DingTalkProxyConfig/config.jelly

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
33

4-
<div id="proxyConfigContainer">
4+
<div id="dt-proxyConfigContainer">
55
<f:entry title="代理类型" field="type">
66
<f:enum>
77
${it.name()}

src/main/resources/io/jenkins/plugins/DingTalkRobotConfig/config.jelly

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
data-validate-button-descriptor-url="${descriptor.descriptorFullUrl}"
5454
data-validate-button-method="test"
5555
data-validate-button-with="${with}"
56+
onclick="validateRobotConfig(this)"
5657
/>
5758
</div>
5859
</div>

src/main/resources/io/jenkins/plugins/DingTalkSecurityPolicyConfig/config.jelly

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<j:set var="type" value="${instance.getType()}"/>
55
<j:set var="desc" value="${instance.getDesc()}"/>
66

7-
<div class="security-config-container">
7+
<div class="dt-security-config-container">
88
<f:entry title="${desc}" field="value"
99
help="${type == 'KEY' ? '/descriptor/io.jenkins.plugins.DingTalkSecurityPolicyConfig/help/key' : null}">
1010
<f:textbox name="value"/>

src/main/webapp/scripts/notifierConfig.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
(function($) {
2-
$(function() {
3-
$(document).on('change', '.notifier-config-raw input[name="_.raw"]',
4-
function(event) {
5-
if (event.target.checked) {
6-
$('.raw-content').css('display', '')
7-
$('.none-raw-content').css('display', 'none')
8-
} else {
9-
$('.raw-content').css('display', 'none')
10-
$('.none-raw-content').css('display', '')
11-
}
12-
})
13-
})
1+
window.addEventListener('load', function () {
2+
document.querySelector(
3+
'.dt-notifier-config-raw input[name="_.raw"]'
4+
).addEventListener('change',
5+
function (event) {
6+
console.log(document.querySelector('.raw-content'))
7+
if (event.target.checked) {
8+
document.querySelector('.dt-raw-content-builtin').style.display = 'none'
9+
document.querySelector('.dt-raw-content-custom').style.display = ''
10+
} else {
11+
document.querySelector('.dt-raw-content-builtin').style.display = ''
12+
document.querySelector('.dt-raw-content-custom').style.display = 'none'
13+
}
14+
})
15+
})
1416

15-
})(jQuery3 || jQuery)
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,84 @@
1-
(function ($) {
2-
if (!$) {
3-
throw new Error('jQuery 插件加载失败将无法校验机器人配置,但不影响正常使用')
4-
}
5-
6-
$(function () {
7-
$(document).on('click', '.robot-config-validate-btn', validateRobotConfig)
8-
})
9-
10-
function applyErrorMessage(elt, rsp) {
11-
if (rsp.status == 200) {
12-
elt.innerHTML = rsp.responseText
13-
} else {
14-
var id = 'valerr' + (iota++)
15-
elt.innerHTML = '<a href="" onclick="document.getElementById(\'' + id
16-
+ '\').style.display=\'block\';return false">ERROR</a><div id="'
17-
+ id + '" style="display:none">' + rsp.responseText + '</div>'
18-
var error = document.getElementById('error-description') // cf. oops.jelly
19-
if (error) {
20-
var div = document.getElementById(id)
21-
while (div.firstElementChild) {
22-
div.removeChild(div.firstElementChild)
23-
}
24-
div.appendChild(error)
1+
function applyErrorMessage(elt, rsp) {
2+
if (rsp.status == 200) {
3+
elt.innerHTML = rsp.responseText
4+
} else {
5+
var id = 'valerr' + (iota++)
6+
elt.innerHTML = '<a href="" onclick="document.getElementById(\'' + id
7+
+ '\').style.display=\'block\';return false">ERROR</a><div id="'
8+
+ id + '" style="display:none">' + rsp.responseText + '</div>'
9+
var error = document.getElementById('error-description') // cf. oops.jelly
10+
if (error) {
11+
var div = document.getElementById(id)
12+
while (div.firstElementChild) {
13+
div.removeChild(div.firstElementChild)
2514
}
15+
div.appendChild(error)
2616
}
27-
Behaviour.applySubtree(elt)
2817
}
18+
Behaviour.applySubtree(elt)
19+
}
2920

30-
async function validateRobotConfig() {
31-
var $btn = $(this)
21+
async function validateRobotConfig(btn) {
22+
var checkUrl = btn.dataset['validateButtonDescriptorUrl'] +
23+
'/' +
24+
btn.dataset['validateButtonMethod']
3225

33-
var checkUrl = $btn.attr('data-validate-button-descriptor-url') +
34-
'/' +
35-
$btn.attr('data-validate-button-method')
26+
var $robot = btn.closest('.robot-config-container')
27+
var $msg = $robot.querySelector('.robot-config-validate-msg')
3628

37-
var $robot = $btn.parents('.robot-config-container')
38-
var $msg = $robot.find('.robot-config-validate-msg')
29+
$msg.innerHTML = ''
3930

40-
$msg.empty()
31+
var url = new URL(checkUrl, window.location.origin)
32+
getParameters($robot).forEach(function (v, k) {
33+
url.searchParams.set(k, v)
34+
})
4135

42-
var url = new URL(checkUrl, window.location.origin)
43-
getParameters($robot).forEach(function (v, k) {
44-
url.searchParams.set(k, v)
45-
})
36+
var res = await fetch(url, {
37+
method: 'GET'
38+
})
4639

47-
var res = await fetch(url, {
48-
method: 'GET'
49-
})
40+
var resText = await res.text()
41+
applyErrorMessage($msg, {
42+
status: res.status,
43+
responseText: resText
44+
})
45+
}
5046

51-
var resText = await res.text()
52-
applyErrorMessage($msg.get(0), {
53-
status: res.status,
54-
responseText: resText
55-
})
47+
function getParameters($robot) {
48+
/**
49+
* 代理信息
50+
*/
51+
var $proxy = document.querySelector('#dt-proxyConfigContainer')
52+
var proxyConfig = {
53+
type: $proxy.querySelector('select[name="type"]').value,
54+
host: $proxy.querySelector('input[name="host"]').value,
55+
port: $proxy.querySelector('input[name="port"]').value
5656
}
5757

58-
function getParameters($robot) {
59-
/**
60-
* 代理信息
61-
*/
62-
var $proxy = $('#proxyConfigContainer')
63-
var proxyConfig = {
64-
type: $proxy.find('select[name="type"]').val(),
65-
host: $proxy.find('input[name="host"]').val(),
66-
port: $proxy.find('input[name="port"]').val()
67-
}
58+
/**
59+
* 机器人配置
60+
*/
61+
var id = $robot.querySelector('input[name="id"]').value
62+
var name = $robot.querySelector('input[name="name"]').value
63+
var webhook = $robot.querySelector('input[name="webhook"]').value
64+
// 安全策略
65+
var securityPolicyConfigs = []
6866

69-
/**
70-
* 机器人配置
71-
*/
72-
var id = $robot.find('input[name="id"]').val()
73-
var name = $robot.find('input[name="name"]').val()
74-
var webhook = $robot.find('input[name="webhook"]').val()
75-
// 安全策略
76-
var securityPolicyConfigs = $.map(
77-
$robot.find('.security-config-container'),
78-
function (t) {
79-
return {
80-
type: $(t).find('input[name=type]').val(),
81-
value: $(t).find('input[name=value]').val()
82-
}
67+
$robot.querySelectorAll('.dt-security-config-container').forEach(
68+
function (item) {
69+
securityPolicyConfigs.push({
70+
type: item.querySelector('input[name=type]').value,
71+
value: item.querySelector('input[name=value]').value
8372
})
73+
})
8474

85-
var params = new URLSearchParams()
75+
var params = new URLSearchParams()
8676

87-
params.set('id', id)
88-
params.set('name', name)
89-
params.set('webhook', webhook)
90-
params.set('securityPolicyConfigs', JSON.stringify(securityPolicyConfigs))
91-
params.set('proxy', JSON.stringify(proxyConfig))
77+
params.set('id', id)
78+
params.set('name', name)
79+
params.set('webhook', webhook)
80+
params.set('securityPolicyConfigs', JSON.stringify(securityPolicyConfigs))
81+
params.set('proxy', JSON.stringify(proxyConfig))
9282

93-
return params
94-
}
95-
})(jQuery3 || jQuery)
83+
return params
84+
}

0 commit comments

Comments
 (0)