Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
f2d230d1
Commit
f2d230d1
authored
Dec 19, 2013
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event & import & export
parent
d38e61b3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
13 deletions
+140
-13
.jshintrc
.jshintrc
+1
-0
kityminder.js
src/core/kityminder.js
+116
-12
minderevent.js
src/core/minderevent.js
+22
-1
mindernode.js
src/core/mindernode.js
+1
-0
No files found.
.jshintrc
View file @
f2d230d1
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
"predef" : [
"predef" : [
"kity",
"kity",
"MinderNode",
"MinderNode",
"MinderEvent",
"require",
"require",
"km"
"km"
]
]
...
...
src/core/kityminder.js
View file @
f2d230d1
...
@@ -123,19 +123,97 @@ kity.extendClass(KityMinder, {
...
@@ -123,19 +123,97 @@ kity.extendClass(KityMinder, {
// 事件机制
// 事件机制
kity
.
extendClass
(
KityMinder
,
{
kity
.
extendClass
(
KityMinder
,
{
_initEvents
:
function
()
{
_initEvents
:
function
()
{
this
.
_eventCallbacks
=
{};
this
.
_bindPaperEvents
();
this
.
_bindKeyboardEvents
();
},
},
on
:
function
(
name
,
callback
)
{
_bindPaperEvents
:
function
()
{
var
minder
=
this
;
this
.
paper
.
on
(
'click mousedown mouseup mousemove'
,
this
.
_firePharse
.
bind
(
this
));
},
},
once
:
function
(
name
,
callback
)
{
_bindKeyboardEvents
:
function
()
{
var
minder
=
this
;
var
listen
=
function
(
name
,
callback
)
{
if
(
window
.
addEventListener
)
{
window
.
addEventListener
(
name
,
callback
);
}
else
if
(
window
.
attachEvent
)
{
window
.
attachEvent
(
name
,
callback
);
}
};
var
events
=
'keydown keyup keypress'
.
split
(
' '
);
for
(
var
i
=
0
;
i
<
events
.
length
;
i
++
)
{
listen
(
events
[
i
],
this
.
_firePharse
.
bind
(
this
));
}
},
_firePharse
:
function
(
e
)
{
var
beforeEvent
,
preEvent
,
executeEvent
;
beforeEvent
=
new
MinderEvent
(
'before'
+
e
.
type
,
e
,
true
);
if
(
!
this
.
_fire
(
beforeEvent
)
)
{
return
;
}
preEvent
=
new
MinderEvent
(
'pre'
+
e
.
type
,
e
,
false
);
executeEvent
=
new
MinderEvent
(
e
.
type
,
e
,
false
);
this
.
_fire
(
preEvent
);
this
.
_fire
(
beforeEvent
);
if
(
~
'mousedown mouseup keydown keyup'
.
indexOf
(
e
.
type
))
{
this
.
_interactChange
(
e
);
}
},
_interactChange
:
function
(
e
)
{
var
minder
=
this
;
this
.
interactTimeout
=
setTimeout
(
function
()
{
var
canceled
=
minder
.
_fire
(
new
MinderEvent
(
'beforeinteractchange'
));
if
(
canceled
)
{
return
;
}
minder
.
_fire
(
new
MinderEvent
(
'preinteractchange'
));
minder
.
_fire
(
new
MinderEvent
(
'interactchange'
));
},
500
);
},
_listen
:
function
(
type
,
callback
)
{
var
callbacks
=
this
.
_eventCallbacks
[
type
]
||
(
this
.
_eventCallbacks
[
type
]
=
[]);
callbacks
.
push
(
callback
);
},
_fire
:
function
(
e
)
{
var
callbacks
=
this
.
_eventCallbacks
[
e
.
type
];
for
(
var
i
=
0
;
i
<
callbacks
.
length
;
i
++
)
{
callbacks
[
i
].
call
(
this
,
e
);
if
(
e
.
shouldCancelImmediately
())
{
break
;
}
}
return
e
.
shouldCancel
();
},
on
:
function
(
name
,
callback
)
{
var
types
=
name
.
split
(
' '
);
for
(
var
i
=
0
;
i
<
types
.
length
;
i
++
)
{
this
.
_listen
(
types
[
i
],
callback
);
}
return
this
;
},
},
off
:
function
(
name
,
callback
)
{
off
:
function
(
name
,
callback
)
{
var
types
=
name
.
split
(
' '
);
var
i
,
j
,
callbacks
,
removeIndex
;
for
(
i
=
0
;
i
<
types
.
length
;
i
++
)
{
callbacks
=
this
.
_eventCallbacks
[
types
[
i
]
];
if
(
callbacks
)
{
removeIndex
=
null
;
for
(
j
=
0
;
j
<
callbacks
.
length
;
j
++
)
{
if
(
callbacks
[
j
]
==
callback
)
{
removeIndex
=
j
;
}
}
if
(
removeIndex
!==
null
)
{
callbacks
.
splice
(
removeIndex
,
1
);
}
}
}
},
},
fire
:
function
(
name
,
params
)
{
fire
:
function
(
type
,
params
)
{
var
e
=
params
||
{};
e
.
type
=
type
;
this
.
_firePharse
(
e
);
return
this
;
}
}
});
});
...
@@ -161,12 +239,38 @@ kity.extendClass(KityMinder, {
...
@@ -161,12 +239,38 @@ kity.extendClass(KityMinder, {
// 导入导出
// 导入导出
kity
.
extendClass
(
KityMinder
,
{
kity
.
extendClass
(
KityMinder
,
{
export
:
function
()
{
exportData
:
function
(
node
)
{
var
exported
=
{};
node
=
node
||
this
.
getRoot
();
exported
.
data
=
node
.
getData
();
var
childNodes
=
node
.
getChildren
();
if
(
childNodes
.
length
)
{
exported
.
children
=
[];
for
(
var
i
=
0
;
i
<
childNodes
.
length
;
i
++
)
{
exported
.
children
.
push
(
this
.
exportData
(
childNodes
[
i
]));
}
}
return
exported
;
},
},
import
:
function
()
{
importData
:
function
(
data
)
{
function
importToNode
(
data
,
node
)
{
var
children
=
data
.
children
;
delete
data
.
children
;
for
(
var
field
in
data
)
{
node
.
setData
(
field
,
data
[
field
]);
}
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
child
=
new
MinderNode
();
importToNode
(
children
[
i
],
child
);
node
.
appendChild
(
child
);
}
}
while
(
this
.
root
.
getChildren
().
length
)
{
this
.
root
.
removeChild
(
0
);
}
importToNode
(
data
,
this
.
root
);
return
this
;
}
}
});
});
...
...
src/core/minderevent.js
View file @
f2d230d1
var
MinderEvent
=
kity
.
createClass
(
'MindEvent'
,
{
var
MinderEvent
=
kity
.
createClass
(
'MindEvent'
,
{
constructor
:
function
(
type
,
params
,
cancelable
)
{
kity
.
Utils
.
extend
(
this
,
params
||
{});
this
.
type
=
type
;
this
.
cancelable
=
cancelable
||
false
;
},
cancel
:
function
()
{
this
.
canceled
=
true
;
},
cancelImmediately
:
function
()
{
this
.
immediatelyCanceld
=
true
;
this
.
canceled
=
true
;
},
shouldCancel
:
function
()
{
return
this
.
cancelable
&&
this
.
canceled
;
},
shouldCancelImmediately
:
function
()
{
return
this
.
cancelable
&&
this
.
immediatelyCanceld
;
}
});
});
\ No newline at end of file
src/core/mindernode.js
View file @
f2d230d1
...
@@ -5,6 +5,7 @@ var MinderNode = km.MinderNode = kity.createClass("MinderNode", {
...
@@ -5,6 +5,7 @@ var MinderNode = km.MinderNode = kity.createClass("MinderNode", {
this
.
data
=
{};
this
.
data
=
{};
this
.
tnh
=
treeNotifyHandler
;
this
.
tnh
=
treeNotifyHandler
;
this
.
rc
=
new
kity
.
Group
();
this
.
rc
=
new
kity
.
Group
();
this
.
rc
.
minderNode
=
this
;
},
},
getParent
:
function
()
{
getParent
:
function
()
{
...
...
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