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
1da2f6eb
Commit
1da2f6eb
authored
May 15, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev
parent
7d2f62b9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
54 deletions
+54
-54
image.js
src/module/image.js
+54
-54
No files found.
src/module/image.js
View file @
1da2f6eb
KityMinder
.
registerModule
(
"image"
,
function
()
{
function
loadImageSize
(
url
,
callback
)
{
var
img
=
document
.
createElement
(
'img'
);
KityMinder
.
registerModule
(
"image"
,
function
()
{
function
loadImageSize
(
url
,
callback
)
{
var
img
=
document
.
createElement
(
'img'
);
img
.
onload
=
function
()
{
callback
(
img
.
width
,
img
.
height
);
callback
(
img
.
width
,
img
.
height
);
};
img
.
onerror
=
function
()
{
callback
(
null
);
callback
(
null
);
};
img
.
src
=
url
;
}
function
fitImageSize
(
width
,
height
,
maxWidth
,
maxHeight
)
{
function
fitImageSize
(
width
,
height
,
maxWidth
,
maxHeight
)
{
var
ratio
=
width
/
height
,
fitRatio
=
maxWidth
/
maxHeight
;
// 宽高比大于最大尺寸的宽高比,以宽度为标准适应
if
(
ratio
>
fitRatio
&&
width
>
maxWidth
)
{
if
(
ratio
>
fitRatio
&&
width
>
maxWidth
)
{
width
=
maxWidth
;
height
=
maxWidth
/
ratio
;
}
else
if
(
height
>
maxHeight
)
{
}
else
if
(
height
>
maxHeight
)
{
height
=
maxHeight
;
width
=
maxHeight
/
ratio
;
}
...
...
@@ -34,98 +34,98 @@ KityMinder.registerModule( "image", function () {
"maxImageHeight"
:
200
},
"commands"
:
{
"image"
:
kity
.
createClass
(
"ImageCommand"
,
{
"image"
:
kity
.
createClass
(
"ImageCommand"
,
{
base
:
Command
,
execute
:
function
(
km
,
url
)
{
execute
:
function
(
km
,
url
)
{
var
nodes
=
km
.
getSelectedNodes
();
loadImageSize
(
url
,
function
(
width
,
height
)
{
if
(
!
width
)
return
;
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
n
.
setData
(
'image'
,
url
);
n
.
setData
(
'imageWidth'
,
width
);
n
.
setData
(
'imageHeight'
,
height
);
km
.
updateLayout
(
n
);
}
);
}
);
loadImageSize
(
url
,
function
(
width
,
height
)
{
if
(
!
width
)
return
;
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
n
.
setData
(
'image'
,
url
);
n
.
setData
(
'imageWidth'
,
width
);
n
.
setData
(
'imageHeight'
,
height
);
km
.
updateLayout
(
n
);
});
});
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
var
nodes
=
km
.
getSelectedNodes
(),
result
=
0
;
if
(
nodes
.
length
===
0
)
{
if
(
nodes
.
length
===
0
)
{
return
-
1
;
}
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
if
(
n
&&
n
.
getData
(
'image'
)
)
{
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
if
(
n
&&
n
.
getData
(
'image'
)
)
{
result
=
0
;
return
false
;
}
}
);
});
return
result
;
},
queryValue
:
function
(
km
)
{
queryValue
:
function
(
km
)
{
var
node
=
km
.
getSelectedNode
();
return
node
.
getData
(
'image'
);
return
node
.
getData
(
'image'
);
}
}
),
"removeimage"
:
kity
.
createClass
(
"RemoveImageCommand"
,
{
}),
"removeimage"
:
kity
.
createClass
(
"RemoveImageCommand"
,
{
base
:
Command
,
execute
:
function
(
km
)
{
execute
:
function
(
km
)
{
var
nodes
=
km
.
getSelectedNodes
();
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
n
.
setData
(
'image'
);
km
.
updateLayout
(
n
);
}
);
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
n
.
setData
(
'image'
);
km
.
updateLayout
(
n
);
});
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
var
nodes
=
km
.
getSelectedNodes
();
if
(
nodes
.
length
==
0
)
{
if
(
nodes
.
length
==
0
)
{
return
-
1
;
}
var
image
=
false
;
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
if
(
n
.
getData
(
'image'
)
)
{
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
if
(
n
.
getData
(
'image'
)
)
{
image
=
true
;
return
false
;
}
}
);
if
(
image
)
{
});
if
(
image
)
{
return
0
;
}
return
-
1
;
}
}
)
})
},
"events"
:
{
"RenderNodeTop"
:
function
(
e
)
{
"RenderNodeTop"
:
function
(
e
)
{
var
node
=
e
.
node
,
url
=
node
.
getData
(
'image'
);
url
=
node
.
getData
(
'image'
);
var
link
,
img
,
size
,
currentBox
;
if
(
url
)
{
if
(
url
)
{
size
=
fitImageSize
(
node
.
getData
(
'imageWidth'
),
node
.
getData
(
'imageHeight'
),
this
.
getOptions
(
'maxImageWidth'
),
this
.
getOptions
(
'maxImageHeight'
)
);
node
.
getData
(
'imageWidth'
),
node
.
getData
(
'imageHeight'
),
this
.
getOptions
(
'maxImageWidth'
),
this
.
getOptions
(
'maxImageHeight'
)
);
img
=
new
kity
.
Image
(
url
,
size
.
width
,
size
.
height
);
img
=
new
kity
.
Image
(
url
,
size
.
width
,
size
.
height
);
link
=
new
kity
.
HyperLink
(
url
);
link
.
addShape
(
img
);
link
.
setTarget
(
'_blank'
);
link
.
setStyle
(
'cursor'
,
'pointer'
);
link
=
new
kity
.
HyperLink
(
url
);
link
.
addShape
(
img
);
link
.
setTarget
(
'_blank'
);
link
.
setStyle
(
'cursor'
,
'pointer'
);
currentBox
=
node
.
getContRc
().
getBoundaryBox
();
node
.
getContRc
().
addShape
(
link
.
setTranslate
(
0
,
currentBox
.
y
-
size
.
height
)
);
node
.
getContRc
().
addShape
(
link
.
setTranslate
(
0
,
currentBox
.
y
-
size
.
height
)
);
}
}
}
};
}
);
\ No newline at end of file
});
\ 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