Commit 6c6eede3 authored by campaign's avatar campaign

添加hyperlink

parent 72fcba5d
( function () {
//todo 这里先写死成中文
var content = '<div class="hyperlink-content" style="padding:20px;width:360px;">';
content += '<p><label>输入链接: <input id="hyperlink_href" style="width:90%;" /></label></p>';
content += '<p style="text-align:right"><button id="hyperlink_insert">插入</button></p>';
content += '</div>';
KM.registerWidget( 'hyperlink', {
tpl: content,
initContent: function ( km ) {
var lang = km.getLang( 'dialogs.hyperlink' ),
html;
if ( lang ) {
html = $.parseTmpl( this.tpl, lang );
}
this.root().html( html );
},
initEvent: function ( km, $w ) {
$w.find('#hyperlink_insert').on('click',function(){
km.execCommand('hyperlink',$w.find('#hyperlink_href').val());
$w.kmui().hide();
});
var url = km.queryCommandValue('hyperlink');
$w.find('#hyperlink_href').val(url || '')
},
width: 400
} );
} )();
\ No newline at end of file
/**
* 开发版本的文件导入
*/
( function () {
(function (){
var paths = new Array(
'core/kityminder.js', 'core/utils.js', 'core/command.js', 'core/node.js', 'core/module.js', 'core/event.js', 'core/minder.js', 'core/minder.data.js', 'core/minder.event.js', 'core/minder.module.js', 'core/minder.command.js', 'core/minder.node.js', 'core/keymap.js', 'core/minder.lang.js', 'core/minder.defaultoptions.js', 'core/minder.preference.js', 'core/browser.js', 'module/geometry.js', 'module/history.js', 'module/icon.js', 'module/layout.js', 'module/layout.default.js', 'module/layout.bottom.js', 'core/minder.select.js', 'module/view.js', 'module/dragtree.js', 'module/dropfile.js', 'module/keyboard.js', 'module/select.js', 'module/history.js', 'module/editor.js', 'module/editor.range.js', 'module/editor.receiver.js', 'module/editor.selection.js', 'module/basestyle.js', 'module/font.js', 'module/zoom.js', 'module/nodetext.js', 'module/hyperlink.js', 'ui/jquery-ui-1.10.4.custom.min.js', 'ui/widget.js', 'ui/button.js', 'ui/toolbar.js', 'ui/menu.js', 'ui/dropmenu.js', 'ui/splitbutton.js', 'ui/colorsplitbutton.js', 'ui/popup.js', 'ui/scale.js', 'ui/colorpicker.js', 'ui/combobox.js', 'ui/buttoncombobox.js', 'ui/modal.js', 'ui/tooltip.js', 'ui/tab.js', 'ui/separator.js', 'ui/scale.js', 'adapter/utils.js', 'adapter/adapter.js', 'adapter/button.js', 'adapter/combobox.js', 'adapter/saveto.js', 'adapter/view.js', 'adapter/tooltips.js', 'adapter/layout.js', 'adapter/node.js', 'adapter/contextmenu.js', 'adapter/dialog.js', 'protocal/xmind.js', 'protocal/freemind.js', 'protocal/mindmanager.js', 'protocal/plain.js', 'protocal/json.js', 'protocal/png.js', 'protocal/svg.js'
'core/kityminder.js'
,'core/utils.js'
,'core/command.js'
,'core/node.js'
,'core/module.js'
,'core/event.js'
,'core/minder.js'
,'core/minder.data.js'
,'core/minder.event.js'
,'core/minder.module.js'
,'core/minder.command.js'
,'core/minder.node.js'
,'core/keymap.js'
,'core/minder.lang.js'
,'core/minder.defaultoptions.js'
,'core/minder.preference.js'
,'core/browser.js'
,'module/geometry.js'
,'module/history.js'
,'module/icon.js'
,'module/layout.js'
,'module/layout.default.js'
,'module/layout.bottom.js'
,'core/minder.select.js'
,'module/view.js'
,'module/dragtree.js'
,'module/dropfile.js'
,'module/keyboard.js'
,'module/select.js'
,'module/history.js'
,'module/editor.js'
,'module/editor.range.js'
,'module/editor.receiver.js'
,'module/editor.selection.js'
,'module/basestyle.js'
,'module/font.js'
,'module/zoom.js'
,'module/nodetext.js'
,'module/hyperlink.js'
,'ui/jquery-ui-1.10.4.custom.min.js'
,'ui/widget.js'
,'ui/button.js'
,'ui/toolbar.js'
,'ui/menu.js'
,'ui/dropmenu.js'
,'ui/splitbutton.js'
,'ui/colorsplitbutton.js'
,'ui/popup.js'
,'ui/scale.js'
,'ui/colorpicker.js'
,'ui/combobox.js'
,'ui/buttoncombobox.js'
,'ui/modal.js'
,'ui/tooltip.js'
,'ui/tab.js'
,'ui/separator.js'
,'ui/scale.js'
,'adapter/utils.js'
,'adapter/adapter.js'
,'adapter/button.js'
,'adapter/combobox.js'
,'adapter/saveto.js'
,'adapter/view.js'
,'adapter/tooltips.js'
,'adapter/layout.js'
,'adapter/node.js'
,'adapter/contextmenu.js'
,'adapter/dialog.js'
,'adapter/hyperlink.js'
,'protocal/xmind.js'
,'protocal/freemind.js'
,'protocal/mindmanager.js'
,'protocal/plain.js'
,'protocal/json.js'
,'protocal/png.js'
,'protocal/svg.js'
),
baseURL = 'src/';
for ( var i = 0, pi; pi = paths[ i++ ]; ) {
document.write( '<script type="text/javascript" src="' + baseURL + pi + '"></script>' );
for (var i=0,pi;pi = paths[i++];) {
document.write('<script type="text/javascript" src="'+ baseURL + pi +'"></script>');
}
} )();
\ No newline at end of file
})();
......@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏
toolbars: [
'hand zoom-in zoom-out expand contract | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node | preference | help'
'hand zoom-in zoom-out expand contract | undo redo | bold italic | fontfamily fontsize forecolor | saveto | hyperlink unhyperlink | markers | node | preference | help'
]
//只读模式,默认是false
//readOnly: true
......
KM.registerToolbarUI( 'bold italic redo undo',
KM.registerToolbarUI( 'bold italic redo undo unhyperlink',
function ( name ) {
var me = this;
var $btn = $.kmuibutton( {
......
KM.registerToolbarUI( 'hyperlink', function ( name ) {
var me = this,
currentRange, $dialog,
opt = {
title: this.getLang( 'tooltips' )[ name ] || '',
url: me.getOptions( 'KITYMINDER_HOME_URL' ) + 'dialogs/' + name + '/' + name + '.js'
};
var $btn = $.kmuibutton( {
icon: name,
title: this.getLang( 'tooltips' )[ name ] || ''
} );
//加载模版数据
utils.loadFile( document, {
src: opt.url,
tag: "script",
type: "text/javascript",
defer: "defer"
}, function () {
$dialog = $.kmuimodal( opt );
$dialog.attr( 'id', 'kmui-dialog-' + name ).addClass( 'kmui-dialog-' + name )
.find( '.kmui-modal-body' ).addClass( 'kmui-dialog-' + name + '-body' );
$dialog.kmui().on( 'beforeshow', function () {
var $root = this.root(),
win = null,
offset = null;
if ( !$root.parent()[ 0 ] ) {
me.$container.find( '.kmui-dialog-container' ).append( $root );
}
KM.setWidgetBody( name, $dialog, me );
} ).attachTo( $btn);
} );
me.on( 'interactchange', function () {
var state = this.queryCommandState( name );
$btn.kmui().disabled( state == -1 ).active( state == 1 )
} );
return $btn;
} );
......@@ -82,7 +82,9 @@ KityMinder.registerModule( "TextEditModule", function () {
if(node){
if ( this.isSingleSelect() && node.isSelected()) {
var keyCode = e.originEvent.keyCode;
if(!keymap.notContentInput[keyCode]){
if(!keymap.notContentInput[keyCode] && range.nativeSel.rangeCount != 0){
var nativeRange = range.nativeSel.getRangeAt(0);
if(nativeRange && (nativeRange.startContainer === receiver.container || receiver.container.contains(nativeRange.startContainer )))
km.setStatus('textedit')
}
}
......
......@@ -2,24 +2,18 @@ KityMinder.registerModule( "hyperlink", function () {
return {
"commands": {
"createlink" : kity.createClass( "hyperlink", {
"hyperlink" : kity.createClass( "hyperlink", {
base: Command,
execute: function (url) {
execute: function (km,url) {
var nodes = km.getSelectedNodes();
if ( this.queryState( 'hyperlink' ) == 1 ) {
utils.each( nodes, function ( i, n ) {
n.setData( 'hyperlink' );
} )
} else {
utils.each( nodes, function ( i, n ) {
n.setData( 'hyperlink', url );
km.updateLayout(n)
} )
}
},
queryState: function () {
queryState: function (km) {
var nodes = km.getSelectedNodes(),
result = 0;
if ( nodes.length == 0 ) {
......@@ -32,19 +26,39 @@ KityMinder.registerModule( "hyperlink", function () {
}
} );
return result;
},
queryValue : function (km) {
if ( km.queryCommandState( 'hyperlink' ) == 1 ) {
var node = km.getSelectedNode();
return node.getData( 'hyperlink' );
}
}
} ),
"unhyperlink" : kity.createClass( "hyperlink", {
base: Command,
execute: function (km) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'hyperlink' );
km.updateLayout(n)
} )
}
} )
},
"events": {
"RenderNodeRight": function ( e ) {
var node = e.node,url;
if(url = node.getData('h')){
if(url = node.getData('hyperlink')){
var link = new kity.HyperLink(url);
var rect = new kity.Rect();
var box = node.getContRc().getBoundaryBox();
rect.setWidth(10).setHeight(10).fill('#ccc').setPosition(box.x + box.width + 2,rect.getHeight()/-2);
link.appendChild(rect);
node.getContRc().appendChild(link);
var style = this.getCurrentLayoutStyle()[ node.getType() ];
rect.setWidth(10).setHeight(10).fill('#ccc').setPosition(box.x + box.width + style.spaceLeft,rect.getHeight()/-2);
link.addShape(rect);
link.setTarget('_blank');
link.setStyle('cursor','pointer');
node.getContRc().addShape(link);
}
}
......
......@@ -41,3 +41,10 @@
.kmui-btn-toolbar .kmui-btn .kmui-icon-contract {
background: url(../images/contract.png) no-repeat 2px 2px;
}
.kmui-btn-toolbar .kmui-btn .kmui-icon-hyperlink {
background: url(../images/contract.png) no-repeat 2px 2px;
}
.kmui-btn-toolbar .kmui-btn .kmui-icon-unhyperlink {
background: url(../images/contract.png) no-repeat 2px 2px;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment