Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
320b1166
Commit
320b1166
authored
Oct 14, 2016
by
baiyaaaaa
Committed by
GitHub
Oct 14, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #402 from QingWei-Li/fix/clickoutside
optimize clickoutside
parents
576c21af
a7a777dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
src/utils/clickoutside.js
src/utils/clickoutside.js
+8
-3
No files found.
src/utils/clickoutside.js
View file @
320b1166
import
{
on
,
off
}
from
'
wind-dom/src/event
'
;
import
{
on
}
from
'
wind-dom/src/event
'
;
const
nodeList
=
[];
on
(
document
,
'
click
'
,
e
=>
{
nodeList
.
forEach
(
node
=>
node
[
clickoutsideContext
].
documentHandler
(
e
));
});
/**
/**
* v-clickoutside
* v-clickoutside
* @desc 点击元素外面才会触发的事件
* @desc 点击元素外面才会触发的事件
...
@@ -12,6 +16,7 @@ const clickoutsideContext = '@@clickoutsideContext';
...
@@ -12,6 +16,7 @@ const clickoutsideContext = '@@clickoutsideContext';
export
default
{
export
default
{
bind
(
el
,
binding
,
vnode
)
{
bind
(
el
,
binding
,
vnode
)
{
const
id
=
nodeList
.
push
(
el
)
-
1
;
const
documentHandler
=
function
(
e
)
{
const
documentHandler
=
function
(
e
)
{
if
(
!
vnode
.
context
||
if
(
!
vnode
.
context
||
el
.
contains
(
e
.
target
)
||
el
.
contains
(
e
.
target
)
||
...
@@ -24,11 +29,11 @@ export default {
...
@@ -24,11 +29,11 @@ export default {
}
}
};
};
el
[
clickoutsideContext
]
=
{
el
[
clickoutsideContext
]
=
{
id
,
documentHandler
,
documentHandler
,
methodName
:
binding
.
expression
,
methodName
:
binding
.
expression
,
bindingFn
:
binding
.
value
bindingFn
:
binding
.
value
};
};
on
(
document
,
'
click
'
,
documentHandler
);
},
},
update
(
el
,
binding
)
{
update
(
el
,
binding
)
{
...
@@ -37,7 +42,7 @@ export default {
...
@@ -37,7 +42,7 @@ export default {
},
},
unbind
(
el
)
{
unbind
(
el
)
{
off
(
document
,
'
click
'
,
el
[
clickoutsideContext
].
documentHandler
);
nodeList
.
splice
(
el
[
clickoutsideContext
].
id
,
1
);
},
},
install
(
Vue
)
{
install
(
Vue
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment