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
8b7c0bfa
Commit
8b7c0bfa
authored
Dec 20, 2013
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
History Module
parent
0718e9b6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
244 additions
and
15 deletions
+244
-15
history.html
demo/history.html
+86
-0
dev.php
dist/dev.php
+5
-1
kityminder.js
src/core/kityminder.js
+8
-11
_example.js
src/module/_example.js
+2
-2
history.js
src/module/history.js
+143
-1
No files found.
demo/history.html
0 → 100644
View file @
8b7c0bfa
<!DOCTYPE html>
<html>
<head>
<script
src=
"../kity/dist/kitygraph.all.js"
></script>
<script
src=
"../dist/dev.php"
></script>
</head>
<body>
</body>
<script>
KityMinder
.
registerModule
(
"Test"
,
function
()
{
var
AppendCommand
=
kity
.
createClass
({
base
:
Command
,
execute
:
function
(
km
,
str
)
{
km
.
text
=
km
.
text
+
str
;
this
.
appendLength
=
str
.
length
;
},
revert
:
function
(
km
)
{
km
.
text
=
km
.
text
.
substr
(
0
,
km
.
text
.
length
-
this
.
appendLength
);
}
});
var
DeleteCommand
=
kity
.
createClass
({
base
:
Command
,
execute
:
function
(
km
,
count
)
{
this
.
deleted
=
km
.
text
.
substr
(
km
.
text
.
length
-
count
);
km
.
text
=
km
.
text
.
substr
(
0
,
km
.
text
.
length
-
count
);
},
revert
:
function
(
km
)
{
km
.
text
+=
this
.
deleted
;
}
});
var
BatchCommand
=
kity
.
createClass
({
base
:
Command
,
execute
:
function
(
km
)
{
var
combines
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
cmd
;
while
(
combines
.
length
)
{
cmd
=
combines
.
shift
().
split
(
':'
);
switch
(
cmd
[
0
])
{
case
'a'
:
km
.
execCommand
(
'append'
,
cmd
[
1
]);
break
;
case
'd'
:
km
.
execCommand
(
'delete'
,
cmd
[
1
]);
break
;
}
}
}
});
return
{
commands
:
{
'append'
:
AppendCommand
,
'delete'
:
DeleteCommand
,
'batch'
:
BatchCommand
}
}
});
minder
=
new
km
.
KityMinder
();
minder
.
text
=
""
;
function
run
(
name
)
{
minder
.
execCommand
.
apply
(
minder
,
arguments
);
console
.
log
(
name
,
': '
,
minder
.
text
);
}
run
(
'append'
,
'techird'
);
run
(
'append'
,
' good '
);
run
(
'batch'
,
'a:good '
,
'a:study'
);
run
(
'undo'
);
run
(
'redo'
);
run
(
'undo'
);
run
(
'redo'
);
run
(
'delete'
,
5
);
run
(
'undo'
);
</script>
</html>
\ No newline at end of file
dist/dev.php
View file @
8b7c0bfa
...
@@ -21,5 +21,9 @@ $content = "";
...
@@ -21,5 +21,9 @@ $content = "";
header
(
'Content-Type: text/javascript; charset=utf-8'
);
header
(
'Content-Type: text/javascript; charset=utf-8'
);
foreach
(
$dependency
as
$index
=>
$dep
)
{
foreach
(
$dependency
as
$index
=>
$dep
)
{
if
(
$_GET
[
'join'
]
!=
null
)
{
echo
file_get_contents
(
"../
$dep
"
)
.
"
\n\n
"
;
echo
file_get_contents
(
"../
$dep
"
)
.
"
\n\n
"
;
}
else
{
echo
"document.write('<script charset=utf-8 src=
\"
../
$dep
\"
></script>');"
;
}
}
}
\ No newline at end of file
src/core/kityminder.js
View file @
8b7c0bfa
...
@@ -78,25 +78,22 @@ kity.extendClass( KityMinder, ( function () {
...
@@ -78,25 +78,22 @@ kity.extendClass( KityMinder, ( function () {
var
me
=
this
;
var
me
=
this
;
var
_action
=
new
_commands
[
name
]();
var
_action
=
new
_commands
[
name
]();
var
args
=
arguments
;
var
cmdArgs
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
args
[
0
]
=
this
;
var
_sendingArgs
=
(
function
()
{
var
_args
=
[];
for
(
var
i
=
1
;
i
<
args
.
length
;
i
++
)
{
_args
.
push
(
args
[
i
]
);
}
return
_args
;
}
)();
var
eventParams
=
{
var
eventParams
=
{
command
:
_action
,
command
:
_action
,
commandName
:
name
,
commandName
:
name
,
commandArgs
:
_sending
Args
commandArgs
:
cmd
Args
};
};
var
canceled
=
me
.
_fire
(
new
MinderEvent
(
'beforecommand'
,
eventParams
,
true
)
);
var
canceled
=
me
.
_fire
(
new
MinderEvent
(
'beforecommand'
,
eventParams
,
true
)
);
if
(
!
canceled
)
{
if
(
!
canceled
)
{
me
.
_fire
(
new
MinderEvent
(
"precommand"
,
eventParams
,
false
)
);
me
.
_fire
(
new
MinderEvent
(
"precommand"
,
eventParams
,
false
)
);
_action
.
execute
.
apply
(
_action
,
args
);
_action
.
execute
.
apply
(
_action
,
[
this
].
concat
(
cmdArgs
)
);
me
.
_fire
(
new
MinderEvent
(
"command"
,
eventParams
,
false
)
);
me
.
_fire
(
new
MinderEvent
(
"command"
,
eventParams
,
false
)
);
if
(
_action
.
isContentChanged
()
)
{
if
(
_action
.
isContentChanged
()
)
{
...
...
src/module/_example.js
View file @
8b7c0bfa
...
@@ -78,12 +78,12 @@ KityMinder.registerModule( "ExampleModule", function () {
...
@@ -78,12 +78,12 @@ KityMinder.registerModule( "ExampleModule", function () {
"beforecommand"
:
function
(
e
)
{
"beforecommand"
:
function
(
e
)
{
// e.cancel() 方法可以阻止 before 事件进入下个阶段
// e.cancel() 方法可以阻止 before 事件进入下个阶段
// e.cancelImmediately() 方法可以阻止当前回调后的回调执行,并且阻止事件进入下个阶段
// e.cancelImmediately() 方法可以阻止当前回调后的回调执行,并且阻止事件进入下个阶段
console
.
log
(
e
.
type
+
' fired'
);
//
console.log( e.type + ' fired' );
},
},
"command"
:
function
(
e
)
{
"command"
:
function
(
e
)
{
// 命令执行后的事件
// 命令执行后的事件
console
.
log
(
e
.
type
+
' fired'
);
//
console.log( e.type + ' fired' );
},
},
"contentchange"
:
function
(
e
)
{
"contentchange"
:
function
(
e
)
{
...
...
src/module/history.js
View file @
8b7c0bfa
KityMinder
.
registerModule
(
"HistoryModule"
,
function
()
{
KityMinder
.
registerModule
(
"HistoryModule"
,
function
()
{
var
Stack
=
kity
.
createClass
(
"Stack"
,
{
constructor
:
function
(
size
)
{
this
.
size
=
size
||
Number
.
MAX_VALUE
;
this
.
length
=
0
;
},
push
:
function
(
elem
)
{
if
(
this
.
length
===
this
.
size
)
{
this
.
shift
();
}
this
[
this
.
length
++
]
=
elem
;
},
top
:
function
()
{
return
this
[
this
.
length
-
1
];
},
pop
:
function
()
{
return
this
[
--
this
.
length
];
},
empty
:
function
()
{
return
this
.
length
===
0
;
},
clear
:
function
()
{
this
.
length
=
0
;
},
splice
:
function
()
{
// just to make stack array-like
}
}
);
function
getStack
(
km
,
type
)
{
var
stacks
=
km
.
_hisoryStacks
||
(
km
.
_hisoryStacks
=
{}
);
return
stacks
[
type
]
||
(
stacks
[
type
]
=
new
Stack
()
);
}
function
markExecuting
(
km
,
command
)
{
km
.
_commandExecuting
=
command
;
}
function
getExecuting
(
km
)
{
return
km
.
_commandExecuting
||
null
;
}
function
markRedoing
(
km
,
redoing
)
{
km
.
_redoing
=
redoing
;
}
function
isRedoing
(
km
)
{
return
km
.
_redoing
;
}
function
shouldIgnore
(
cmdName
)
{
return
cmdName
==
'undo'
||
cmdName
==
'redo'
;
}
function
getCommandContext
(
e
)
{
return
{
return
{
"commands"
:
{
name
:
e
.
commandName
,
args
:
e
.
commandArgs
,
command
:
e
.
command
};
}
var
UndoCommand
=
kity
.
createClass
(
"UndoCommand"
,
{
base
:
Command
,
execute
:
function
(
km
)
{
var
undoStack
=
getStack
(
km
,
"undo"
),
redoStack
=
getStack
(
km
,
"redo"
),
contextStack
,
context
;
if
(
!
undoStack
.
empty
()
)
{
contextStack
=
undoStack
.
pop
();
redoStack
.
push
(
contextStack
);
for
(
var
i
=
contextStack
.
length
-
1
;
i
>=
0
;
i
--
)
{
context
=
contextStack
[
i
];
context
.
command
.
revert
(
km
);
}
}
},
queryState
:
function
(
km
)
{
return
getStack
(
km
,
'undo'
).
empty
()
?
-
1
:
0
;
}
}
);
var
RedoCommand
=
kity
.
createClass
(
"RedoCommand"
,
{
base
:
Command
,
execute
:
function
(
km
)
{
var
undoStack
=
getStack
(
km
,
"undo"
),
redoStack
=
getStack
(
km
,
"redo"
),
contextStack
,
context
;
if
(
!
redoStack
.
empty
()
)
{
contextStack
=
redoStack
.
pop
();
undoStack
.
push
(
contextStack
);
markRedoing
(
km
,
true
);
for
(
var
i
=
0
;
i
<
contextStack
.
length
;
i
++
)
{
context
=
contextStack
[
i
];
context
.
command
.
execute
.
apply
(
context
.
command
,
[
km
].
concat
(
context
.
args
)
);
}
markRedoing
(
km
,
false
);
}
},
queryState
:
function
(
km
)
{
return
getStack
(
km
,
'redo'
).
empty
()
?
-
1
:
0
;
}
}
);
return
{
"commands"
:
{
"undo"
:
UndoCommand
,
"redo"
:
RedoCommand
},
},
"events"
:
{
"events"
:
{
"beforecommand"
:
function
(
e
)
{
if
(
isRedoing
(
this
)
)
{
e
.
cancel
();
}
},
"precommand"
:
function
(
e
)
{
if
(
shouldIgnore
(
e
.
commandName
)
)
return
;
var
undoStack
=
getStack
(
this
,
"undo"
),
redoStack
=
getStack
(
this
,
"redo"
),
contextStack
;
if
(
getExecuting
(
this
)
===
null
)
{
markExecuting
(
this
,
e
.
command
);
undoStack
.
push
(
new
Stack
()
);
redoStack
.
clear
();
}
contextStack
=
undoStack
.
top
();
contextStack
.
push
(
getCommandContext
(
e
)
);
},
"command"
:
function
(
e
)
{
if
(
shouldIgnore
(
e
.
commandName
)
)
return
;
if
(
getExecuting
(
this
)
===
e
.
command
)
{
markExecuting
(
this
,
null
);
}
}
}
}
};
};
}
);
}
);
\ No newline at end of file
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