-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue-move-dom.js
42 lines (35 loc) · 1.12 KB
/
vue-move-dom.js
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
/*! Copyright (c) 2016 Naufal Rabbani (http://github.com/BosNaufal)
* Licensed Under MIT (http://opensource.org/licenses/MIT)
*
* Version 0.0.1
*
* Just Simplify the original project from: https://github.com/rhyzx/vue-transfer-dom/
* Make it smaller and change some writing behavior
*
*/
Vue.directive('move-dom',{
bind: function() {
var me = this;
// Prepare the container
var container = me.expression == 'v'+me.name
// the default is body
? document.body
// but it can spesified by expression
: document.body.querySelector(me.expression);
// make an anchor
var anchor = Vue.util.createAnchor('v-move-dom');
// put the anchor to container
container.appendChild(anchor);
// Initial new fragment
var newFrag = new Vue.FragmentFactory(me.vm,me.el);
// Create a new fragment and copy All data VM instance including event, ect.
me.frag = newFrag.create(me._host, me._scope, me._frag);
// before() functions from Vue Util dom which is included in fragment.js
// to insert the fragment before the anchor
me.frag.before(anchor);
},
unbind: function() {
// Remove the fragment
this.frag.remove();
}
});