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
5343aade
Commit
5343aade
authored
Dec 19, 2013
by
Akikonata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
https://github.com/kitygraph/kityminder
into dev
parents
87a53298
d9a86469
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
203 additions
and
18 deletions
+203
-18
.jshintrc
.jshintrc
+1
-0
dev.html
demo/dev.html
+43
-5
dev.php
dist/dev.php
+2
-0
kity
kity
+1
-1
kityminder.js
src/core/kityminder.js
+129
-11
minderevent.js
src/core/minderevent.js
+26
-1
mindernode.js
src/core/mindernode.js
+1
-0
No files found.
.jshintrc
View file @
5343aade
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
"predef" : [
"predef" : [
"kity",
"kity",
"MinderNode",
"MinderNode",
"MinderEvent",
"require",
"require",
"km",
"km",
"console",
"console",
...
...
demo/dev.html
View file @
5343aade
...
@@ -10,12 +10,50 @@
...
@@ -10,12 +10,50 @@
</body>
</body>
<script>
<script>
var
minder
=
new
km
.
KityMinder
();
var
minder
=
new
km
.
KityMinder
();
var
node1
=
new
km
.
MinderNode
().
pipe
(
function
()
{
this
.
setData
(
'x'
,
100
);
function
allEvent
()
{
this
.
setData
(
'y'
,
100
);
var
events
=
'click mousedown mouseup keydown keyup keypress dblclick interactchange contentchange selectionchange import'
.
split
(
' '
);
this
.
setData
(
'text'
,
"this is a text"
);
var
pharseEvents
=
[];
for
(
var
i
=
0
;
i
<
events
.
length
;
i
++
)
{
pharseEvents
.
push
(
'before'
+
events
[
i
]);
pharseEvents
.
push
(
'pre'
+
events
[
i
]);
pharseEvents
.
push
(
events
[
i
]);
}
return
pharseEvents
.
join
(
' '
);
}
minder
.
on
(
allEvent
(),
function
(
e
)
{
console
.
log
(
e
.
type
);
});
minder
.
importData
({
data
:
{
x
:
50
,
y
:
50
,
text
:
'center'
,
},
children
:
[{
data
:
{
x
:
200
,
y
:
50
,
text
:
'child1'
}
},{
data
:
{
x
:
200
,
y
:
100
,
text
:
'child2'
},
children
:
[{
data
:
{
x
:
350
,
y
:
100
,
text
:
'leaf'
}
}]
}]
});
});
minder
.
getRoot
().
insertChild
(
node1
);
minder
.
update
();
minder
.
update
();
//console.log(minder.exportData());
</script>
</script>
</html>
</html>
\ No newline at end of file
dist/dev.php
View file @
5343aade
...
@@ -10,6 +10,8 @@ $dependency = Array(
...
@@ -10,6 +10,8 @@ $dependency = Array(
$content
=
""
;
$content
=
""
;
header
(
'Content-Type: text/javascript'
);
foreach
(
$dependency
as
$index
=>
$dep
)
{
foreach
(
$dependency
as
$index
=>
$dep
)
{
echo
file_get_contents
(
"../
$dep
"
)
.
"
\n\n
"
;
echo
file_get_contents
(
"../
$dep
"
)
.
"
\n\n
"
;
}
}
\ No newline at end of file
kity
@
b6f3e999
Subproject commit
7f8b3b2743aa0ce609a3e8406d9efe8aa117accc
Subproject commit
b6f3e9996353a089e7b78f603a66668a6a7354a3
src/core/kityminder.js
View file @
5343aade
...
@@ -171,31 +171,149 @@ kity.extendClass(KityMinder, {
...
@@ -171,31 +171,149 @@ kity.extendClass(KityMinder, {
// 事件机制
// 事件机制
kity
.
extendClass
(
KityMinder
,
{
kity
.
extendClass
(
KityMinder
,
{
_initEvents
:
function
()
{
_initEvents
:
function
()
{
this
.
_eventCallbacks
=
{};
this
.
_bindPaperEvents
();
this
.
_bindKeyboardEvents
();
},
},
on
:
function
(
name
,
callback
)
{
// TODO: mousemove lazy bind
_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
(
executeEvent
);
if
(
~
'mousedown mouseup keydown keyup'
.
indexOf
(
e
.
type
))
{
this
.
_interactChange
(
e
);
}
},
_interactChange
:
function
(
e
)
{
var
minder
=
this
;
clearTimeout
(
this
.
interactTimeout
);
this
.
interactTimeout
=
setTimeout
(
function
()
{
var
canceled
=
minder
.
_fire
(
new
MinderEvent
(
'beforeinteractchange'
));
if
(
canceled
)
{
return
;
}
minder
.
_fire
(
new
MinderEvent
(
'preinteractchange'
));
minder
.
_fire
(
new
MinderEvent
(
'interactchange'
));
},
300
);
},
_listen
:
function
(
type
,
callback
)
{
var
callbacks
=
this
.
_eventCallbacks
[
type
]
||
(
this
.
_eventCallbacks
[
type
]
=
[]);
callbacks
.
push
(
callback
);
},
_fire
:
function
(
e
)
{
var
callbacks
=
this
.
_eventCallbacks
[
e
.
type
];
if
(
!
callbacks
)
{
return
false
;
}
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
=
new
MinderEvent
(
type
,
params
);
this
.
_fire
(
e
);
return
this
;
}
}
});
});
// 导入导出
// 导入导出
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
(
treeData
)
{
function
importToNode
(
treeData
,
node
)
{
var
data
=
treeData
.
data
;
for
(
var
field
in
data
)
{
node
.
setData
(
field
,
data
[
field
]);
}
var
childrenTreeData
=
treeData
.
children
;
if
(
!
childrenTreeData
)
return
;
for
(
var
i
=
0
;
i
<
childrenTreeData
.
length
;
i
++
)
{
var
childNode
=
new
MinderNode
();
importToNode
(
childrenTreeData
[
i
],
childNode
);
node
.
appendChild
(
childNode
);
}
}
var
params
=
{
importData
:
treeData
};
var
canceled
=
this
.
_fire
(
new
MinderEvent
(
'beforeimport'
,
params
,
true
));
if
(
canceled
)
return
this
;
this
.
_fire
(
new
MinderEvent
(
'preimport'
,
params
,
false
));
while
(
this
.
root
.
getChildren
().
length
)
{
this
.
root
.
removeChild
(
0
);
}
importToNode
(
treeData
,
this
.
root
);
this
.
_fire
(
new
MinderEvent
(
'import'
,
params
,
false
));
return
this
;
}
}
});
});
...
...
src/core/minderevent.js
View file @
5343aade
var
MinderEvent
=
kity
.
createClass
(
'MindEvent'
,
{
var
MinderEvent
=
kity
.
createClass
(
'MindEvent'
,
{
constructor
:
function
(
type
,
params
,
cancelable
)
{
params
=
params
||
{};
kity
.
Utils
.
extend
(
this
,
params
);
this
.
type
=
type
;
this
.
cancelable
=
cancelable
||
false
;
if
(
params
.
targetShape
)
{
this
.
targetNode
=
params
.
targetShape
.
minderNode
||
null
;
}
},
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 @
5343aade
...
@@ -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