Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8e07711d
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8e07711d
编写于
12月 14, 2017
作者:
P
Patrik Bóna
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not enable disabled elements for XHR redirects
Fixes #29473.
上级
8541394e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
2 deletion
+37
-2
actionview/app/assets/javascripts/rails-ujs/features/disable.coffee
.../app/assets/javascripts/rails-ujs/features/disable.coffee
+10
-1
actionview/test/ujs/public/test/data-disable.js
actionview/test/ujs/public/test/data-disable.js
+17
-0
actionview/test/ujs/public/test/settings.js
actionview/test/ujs/public/test/settings.js
+4
-0
actionview/test/ujs/server.rb
actionview/test/ujs/server.rb
+6
-1
未找到文件。
actionview/app/assets/javascripts/rails-ujs/features/disable.coffee
浏览文件 @
8e07711d
...
...
@@ -8,7 +8,12 @@ Rails.handleDisabledElement = (e) ->
# Unified function to enable an element (link, button and form)
Rails
.
enableElement
=
(
e
)
->
element
=
if
e
instanceof
Event
then
e
.
target
else
e
if
e
instanceof
Event
return
if
isXhrRedirect
(
e
)
element
=
e
.
target
else
element
=
e
if
matches
(
element
,
Rails
.
linkDisableSelector
)
enableLinkElement
(
element
)
else
if
matches
(
element
,
Rails
.
buttonDisableSelector
)
or
matches
(
element
,
Rails
.
formEnableSelector
)
...
...
@@ -80,3 +85,7 @@ enableFormElement = (element) ->
setData
(
element
,
'ujs:enable-with'
,
null
)
# clean up cache
element
.
disabled
=
false
setData
(
element
,
'ujs:disabled'
,
null
)
isXhrRedirect
=
(
event
)
->
xhr
=
event
.
detail
?
[
0
]
xhr
?
.
getResponseHeader
(
"X-Xhr-Redirect"
)
?
actionview/test/ujs/public/test/data-disable.js
浏览文件 @
8e07711d
...
...
@@ -320,3 +320,20 @@ asyncTest('button[data-remote][data-disable] re-enables when `ajax:error` event
start
()
},
30
)
})
asyncTest
(
'
do not enable elements for XHR redirects
'
,
6
,
function
()
{
var
link
=
$
(
'
a[data-disable]
'
).
attr
(
'
data-remote
'
,
true
).
attr
(
'
href
'
,
'
/echo?with_xhr_redirect=true
'
)
App
.
checkEnabledState
(
link
,
'
Click me
'
)
link
.
bindNative
(
'
ajax:send
'
,
function
()
{
App
.
checkDisabledState
(
link
,
'
Click me
'
)
})
.
triggerNative
(
'
click
'
)
setTimeout
(
function
()
{
App
.
checkDisabledState
(
link
,
'
Click me
'
)
start
()
},
30
)
})
actionview/test/ujs/public/test/settings.js
浏览文件 @
8e07711d
var
App
=
App
||
{}
var
Turbolinks
=
Turbolinks
||
{}
App
.
assertCallbackInvoked
=
function
(
callbackName
)
{
ok
(
true
,
callbackName
+
'
callback should have been invoked
'
)
...
...
@@ -116,3 +117,6 @@ $.fn.extend({
return
this
}
})
Turbolinks
.
clearCache
=
function
()
{}
Turbolinks
.
visit
=
function
()
{}
actionview/test/ujs/server.rb
浏览文件 @
8e07711d
...
...
@@ -64,7 +64,12 @@ def echo
if
params
[
:content_type
]
&&
params
[
:content
]
render
inline:
params
[
:content
],
content_type:
params
[
:content_type
]
elsif
request
.
xhr?
render
json:
JSON
.
generate
(
data
)
if
params
[
:with_xhr_redirect
]
response
.
set_header
(
"X-Xhr-Redirect"
,
"http://example.com/"
)
render
inline:
%{Turbolinks.clearCache()\nTurbolinks.visit("http://example.com/", {"action":"replace"})}
else
render
json:
JSON
.
generate
(
data
)
end
elsif
params
[
:iframe
]
payload
=
JSON
.
generate
(
data
).
gsub
(
"<"
,
"<"
).
gsub
(
">"
,
">"
)
html
=
<<-
HTML
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录