mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-07 01:15:09 +00:00
HTML composition, take 2
Monotone-Parent: dbd490c81ea6cac4c12b2e17661e2fef43219e68 Monotone-Revision: 0801dc9f1e4fdc49ea44fc0450fb025c2639ed26 Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-06-25T19:18:02 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
CKEDITOR.dialog.add( 'anchor', function( editor )
|
||||
{
|
||||
// Function called in onShow to load selected element.
|
||||
var loadElements = function( editor, selection, element )
|
||||
{
|
||||
this.editMode = true;
|
||||
this.editObj = element;
|
||||
|
||||
var attributeValue = this.editObj.getAttribute( 'name' );
|
||||
if ( attributeValue )
|
||||
this.setValueOf( 'info','txtName', attributeValue );
|
||||
else
|
||||
this.setValueOf( 'info','txtName', "" );
|
||||
};
|
||||
|
||||
return {
|
||||
title : editor.lang.anchor.title,
|
||||
minWidth : 300,
|
||||
minHeight : 60,
|
||||
onOk : function()
|
||||
{
|
||||
// Always create a new anchor, because of IE BUG.
|
||||
var name = this.getValueOf( 'info', 'txtName' ),
|
||||
element = CKEDITOR.env.ie ?
|
||||
editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) :
|
||||
editor.document.createElement( 'a' );
|
||||
|
||||
// Move contents and attributes of old anchor to new anchor.
|
||||
if ( this.editMode )
|
||||
{
|
||||
this.editObj.copyAttributes( element, { name : 1 } );
|
||||
this.editObj.moveChildren( element );
|
||||
}
|
||||
|
||||
// Set name.
|
||||
element.removeAttribute( '_cke_saved_name' );
|
||||
element.setAttribute( 'name', name );
|
||||
|
||||
// Insert a new anchor.
|
||||
var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' );
|
||||
if ( !this.editMode )
|
||||
editor.insertElement( fakeElement );
|
||||
else
|
||||
{
|
||||
fakeElement.replace( this.fakeObj );
|
||||
editor.getSelection().selectElement( fakeElement );
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
onShow : function()
|
||||
{
|
||||
this.editObj = false;
|
||||
this.fakeObj = false;
|
||||
this.editMode = false;
|
||||
|
||||
var selection = editor.getSelection();
|
||||
var element = selection.getSelectedElement();
|
||||
if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
|
||||
{
|
||||
this.fakeObj = element;
|
||||
element = editor.restoreRealElement( this.fakeObj );
|
||||
loadElements.apply( this, [ editor, selection, element ] );
|
||||
selection.selectElement( this.fakeObj );
|
||||
}
|
||||
this.getContentElement( 'info', 'txtName' ).focus();
|
||||
},
|
||||
contents : [
|
||||
{
|
||||
id : 'info',
|
||||
label : editor.lang.anchor.title,
|
||||
accessKey : 'I',
|
||||
elements :
|
||||
[
|
||||
{
|
||||
type : 'text',
|
||||
id : 'txtName',
|
||||
label : editor.lang.anchor.name,
|
||||
validate : function()
|
||||
{
|
||||
if ( !this.getValue() )
|
||||
{
|
||||
alert( editor.lang.anchor.errorName );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
} );
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 184 B |
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
CKEDITOR.plugins.add( 'link',
|
||||
{
|
||||
init : function( editor )
|
||||
{
|
||||
// Add the link and unlink buttons.
|
||||
editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link' ) );
|
||||
editor.addCommand( 'anchor', new CKEDITOR.dialogCommand( 'anchor' ) );
|
||||
editor.addCommand( 'unlink', new CKEDITOR.unlinkCommand() );
|
||||
editor.ui.addButton( 'Link',
|
||||
{
|
||||
label : editor.lang.link.toolbar,
|
||||
command : 'link'
|
||||
} );
|
||||
editor.ui.addButton( 'Unlink',
|
||||
{
|
||||
label : editor.lang.unlink,
|
||||
command : 'unlink'
|
||||
} );
|
||||
editor.ui.addButton( 'Anchor',
|
||||
{
|
||||
label : editor.lang.anchor.toolbar,
|
||||
command : 'anchor'
|
||||
} );
|
||||
CKEDITOR.dialog.add( 'link', this.path + 'dialogs/link.js' );
|
||||
CKEDITOR.dialog.add( 'anchor', this.path + 'dialogs/anchor.js' );
|
||||
|
||||
// Add the CSS styles for anchor placeholders.
|
||||
editor.addCss(
|
||||
'img.cke_anchor' +
|
||||
'{' +
|
||||
'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' +
|
||||
'background-position: center center;' +
|
||||
'background-repeat: no-repeat;' +
|
||||
'border: 1px solid #a9a9a9;' +
|
||||
'width: 18px;' +
|
||||
'height: 18px;' +
|
||||
'}\n' +
|
||||
'a.cke_anchor' +
|
||||
'{' +
|
||||
'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' +
|
||||
'background-position: 0 center;' +
|
||||
'background-repeat: no-repeat;' +
|
||||
'border: 1px solid #a9a9a9;' +
|
||||
'padding-left: 18px;' +
|
||||
'}'
|
||||
);
|
||||
|
||||
// Register selection change handler for the unlink button.
|
||||
editor.on( 'selectionChange', function( evt )
|
||||
{
|
||||
/*
|
||||
* Despite our initial hope, document.queryCommandEnabled() does not work
|
||||
* for this in Firefox. So we must detect the state by element paths.
|
||||
*/
|
||||
var command = editor.getCommand( 'unlink' ),
|
||||
element = evt.data.path.lastElement.getAscendant( 'a', true );
|
||||
if ( element && element.getName() == 'a' && element.getAttribute( 'href' ) )
|
||||
command.setState( CKEDITOR.TRISTATE_OFF );
|
||||
else
|
||||
command.setState( CKEDITOR.TRISTATE_DISABLED );
|
||||
} );
|
||||
|
||||
// If the "menu" plugin is loaded, register the menu items.
|
||||
if ( editor.addMenuItems )
|
||||
{
|
||||
editor.addMenuItems(
|
||||
{
|
||||
anchor :
|
||||
{
|
||||
label : editor.lang.anchor.menu,
|
||||
command : 'anchor',
|
||||
group : 'anchor'
|
||||
},
|
||||
|
||||
link :
|
||||
{
|
||||
label : editor.lang.link.menu,
|
||||
command : 'link',
|
||||
group : 'link',
|
||||
order : 1
|
||||
},
|
||||
|
||||
unlink :
|
||||
{
|
||||
label : editor.lang.unlink,
|
||||
command : 'unlink',
|
||||
group : 'link',
|
||||
order : 5
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If the "contextmenu" plugin is loaded, register the listeners.
|
||||
if ( editor.contextMenu )
|
||||
{
|
||||
editor.contextMenu.addListener( function( element, selection )
|
||||
{
|
||||
if ( !element )
|
||||
return null;
|
||||
|
||||
var isAnchor = ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' );
|
||||
|
||||
if ( !isAnchor )
|
||||
{
|
||||
if ( !( element = element.getAscendant( 'a', true ) ) )
|
||||
return null;
|
||||
|
||||
isAnchor = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) );
|
||||
}
|
||||
|
||||
return isAnchor ?
|
||||
{ anchor : CKEDITOR.TRISTATE_OFF } :
|
||||
{ link : CKEDITOR.TRISTATE_OFF, unlink : CKEDITOR.TRISTATE_OFF };
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
afterInit : function( editor )
|
||||
{
|
||||
// Register a filter to displaying placeholders after mode change.
|
||||
|
||||
var dataProcessor = editor.dataProcessor,
|
||||
dataFilter = dataProcessor && dataProcessor.dataFilter;
|
||||
|
||||
if ( dataFilter )
|
||||
{
|
||||
dataFilter.addRules(
|
||||
{
|
||||
elements :
|
||||
{
|
||||
a : function( element )
|
||||
{
|
||||
var attributes = element.attributes;
|
||||
if ( attributes.name && !attributes.href )
|
||||
return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' );
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
requires : [ 'fakeobjects' ]
|
||||
} );
|
||||
|
||||
CKEDITOR.unlinkCommand = function(){};
|
||||
CKEDITOR.unlinkCommand.prototype =
|
||||
{
|
||||
/** @ignore */
|
||||
exec : function( editor )
|
||||
{
|
||||
/*
|
||||
* execCommand( 'unlink', ... ) in Firefox leaves behind <span> tags at where
|
||||
* the <a> was, so again we have to remove the link ourselves. (See #430)
|
||||
*
|
||||
* TODO: Use the style system when it's complete. Let's use execCommand()
|
||||
* as a stopgap solution for now.
|
||||
*/
|
||||
var selection = editor.getSelection(),
|
||||
bookmarks = selection.createBookmarks(),
|
||||
ranges = selection.getRanges(),
|
||||
rangeRoot,
|
||||
element;
|
||||
|
||||
for ( var i = 0 ; i < ranges.length ; i++ )
|
||||
{
|
||||
rangeRoot = ranges[i].getCommonAncestor( true );
|
||||
element = rangeRoot.getAscendant( 'a', true );
|
||||
if ( !element )
|
||||
continue;
|
||||
ranges[i].selectNodeContents( element );
|
||||
}
|
||||
|
||||
selection.selectRanges( ranges );
|
||||
editor.document.$.execCommand( 'unlink', false, null );
|
||||
selection.selectBookmarks( bookmarks );
|
||||
}
|
||||
};
|
||||
|
||||
CKEDITOR.tools.extend( CKEDITOR.config,
|
||||
{
|
||||
linkShowAdvancedTab : true,
|
||||
linkShowTargetTab : true
|
||||
} );
|
||||
Reference in New Issue
Block a user