X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=_source%2Fplugins%2Flink%2Fdialogs%2Flink.js;h=118d1b08c0009db020775680196a16fe3d603b5b;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=94ee042e9ba10b218a5f7ef0807f108c3e1bd856;hpb=4e90e78dc97789709ee7404359a5517540c27553;p=ckeditor.git
diff --git a/_source/plugins/link/dialogs/link.js b/_source/plugins/link/dialogs/link.js
index 94ee042..118d1b0 100644
--- a/_source/plugins/link/dialogs/link.js
+++ b/_source/plugins/link/dialogs/link.js
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
+Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
@@ -235,37 +235,51 @@ CKEDITOR.dialog.add( 'link', function( editor )
advAttr( 'advTabIndex', 'tabindex' );
advAttr( 'advTitle', 'title' );
advAttr( 'advContentType', 'type' );
- advAttr( 'advCSSClasses', 'class' );
+ CKEDITOR.plugins.link.synAnchorSelector ?
+ retval.adv.advCSSClasses = getLinkClass( element )
+ : advAttr( 'advCSSClasses', 'class' );
advAttr( 'advCharset', 'charset' );
advAttr( 'advStyles', 'style' );
advAttr( 'advRel', 'rel' );
}
// Find out whether we have any anchors in the editor.
- // Get all IMG elements in CK document.
- var elements = editor.document.getElementsByTag( 'img' ),
- realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
- anchors = retval.anchors = [];
+ var anchors = retval.anchors = [],
+ i, count, item;
- for ( var i = 0; i < elements.count() ; i++ )
+ // For some browsers we set contenteditable="false" on anchors, making document.anchors not to include them, so we must traverse the links manually (#7893).
+ if ( CKEDITOR.plugins.link.emptyAnchorFix )
{
- var item = elements.getItem( i );
- if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' )
- anchors.push( editor.restoreRealElement( item ) );
+ var links = editor.document.getElementsByTag( 'a' );
+ for ( i = 0, count = links.count(); i < count; i++ )
+ {
+ item = links.getItem( i );
+ if ( item.data( 'cke-saved-name' ) || item.hasAttribute( 'name' ) )
+ anchors.push( { name : item.data( 'cke-saved-name' ) || item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) } );
+ }
+ }
+ else
+ {
+ var anchorList = new CKEDITOR.dom.nodeList( editor.document.$.anchors );
+ for ( i = 0, count = anchorList.count(); i < count; i++ )
+ {
+ item = anchorList.getItem( i );
+ anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
+ }
}
- for ( i = 0 ; i < realAnchors.count() ; i++ )
- anchors.push( realAnchors.getItem( i ) );
-
- for ( i = 0 ; i < anchors.length ; i++ )
+ if ( CKEDITOR.plugins.link.fakeAnchor )
{
- item = anchors[ i ];
- anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
+ var imgs = editor.document.getElementsByTag( 'img' );
+ for ( i = 0, count = imgs.count(); i < count; i++ )
+ {
+ if ( ( item = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, imgs.getItem( i ) ) ) )
+ anchors.push( { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) } );
+ }
}
// Record down the selected element in the dialog.
this._.selectedElement = element;
-
return retval;
};
@@ -369,6 +383,12 @@ CKEDITOR.dialog.add( 'link', function( editor )
return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
}
+ function getLinkClass( ele )
+ {
+ var className = ele.getAttribute( 'class' );
+ return className ? className.replace( /\s*(?:cke_anchor_empty|cke_anchor)(?:\s*$)?/g, '' ) : '';
+ }
+
var commonLang = editor.lang.common,
linkLang = editor.lang.link;
@@ -483,6 +503,11 @@ CKEDITOR.dialog.add( 'link', function( editor )
dialog.getValueOf( 'info', 'linkType' ) != 'url' )
return true;
+ if ( (/javascript\:/).test( this.getValue() ) ) {
+ alert( commonLang.invalidValue );
+ return false;
+ }
+
if ( this.getDialog().fakeObj ) // Edit Anchor.
return true;
@@ -633,7 +658,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
type : 'html',
id : 'noAnchors',
style : 'text-align: center;',
- html : '
' + CKEDITOR.tools.htmlEncode( linkLang.noAnchors ) + '
',
+ html : '' + CKEDITOR.tools.htmlEncode( linkLang.noAnchors ) + '
',
// Focus the first element defined in above html.
focus : true,
setup : function( data )
@@ -1139,6 +1164,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
label : linkLang.styles,
'default' : '',
id : 'advStyles',
+ validate : CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),
setup : setupAdvParams,
commit : commitAdvParams
}
@@ -1151,8 +1177,6 @@ CKEDITOR.dialog.add( 'link', function( editor )
],
onShow : function()
{
- this.fakeObj = false;
-
var editor = this.getParentEditor(),
selection = editor.getSelection(),
element = null;
@@ -1160,14 +1184,6 @@ CKEDITOR.dialog.add( 'link', function( editor )
// Fill in all the relevant fields if there's already one link selected.
if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )
selection.selectElement( element );
- else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )
- && element.data( 'cke-real-element-type' )
- && element.data( 'cke-real-element-type' ) == 'anchor' )
- {
- this.fakeObj = element;
- element = editor.restoreRealElement( this.fakeObj );
- selection.selectElement( this.fakeObj );
- }
else
element = null;
@@ -1188,7 +1204,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
{
case 'url':
var protocol = ( data.url && data.url.protocol != undefined ) ? data.url.protocol : 'http://',
- url = ( data.url && data.url.url ) || '';
+ url = ( data.url && CKEDITOR.tools.trim( data.url.url ) ) || '';
attributes[ 'data-cke-saved-href' ] = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
break;
case 'anchor':
@@ -1302,10 +1318,7 @@ CKEDITOR.dialog.add( 'link', function( editor )
advAttr( 'advAccessKey', 'accessKey' );
if ( data.adv[ 'advName' ] )
- {
attributes[ 'name' ] = attributes[ 'data-cke-saved-name' ] = data.adv[ 'advName' ];
- attributes[ 'class' ] = ( attributes[ 'class' ] ? attributes[ 'class' ] + ' ' : '' ) + 'cke_anchor';
- }
else
removeAttributes = removeAttributes.concat( [ 'data-cke-saved-name', 'name' ] );
@@ -1320,14 +1333,15 @@ CKEDITOR.dialog.add( 'link', function( editor )
}
+ var selection = editor.getSelection();
+
// Browser need the "href" fro copy/paste link to work. (#6641)
attributes.href = attributes[ 'data-cke-saved-href' ];
if ( !this._.selectedElement )
{
// Create element if current selection is collapsed.
- var selection = editor.getSelection(),
- ranges = selection.getRanges( true );
+ var ranges = selection.getRanges( true );
if ( ranges.length == 1 && ranges[0].collapsed )
{
// Short mailto link text view (#5736).
@@ -1350,25 +1364,12 @@ CKEDITOR.dialog.add( 'link', function( editor )
href = element.data( 'cke-saved-href' ),
textView = element.getHtml();
- // IE BUG: Setting the name attribute to an existing link doesn't work.
- // Must re-create the link from weired syntax to workaround.
- if ( CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) && attributes.name != element.getAttribute( 'name' ) )
- {
- var newElement = new CKEDITOR.dom.element( '',
- editor.document );
-
- selection = editor.getSelection();
-
- element.copyAttributes( newElement, { name : 1 } );
- element.moveChildren( newElement );
- newElement.replace( element );
- element = newElement;
-
- selection.selectElement( element );
- }
-
element.setAttributes( attributes );
element.removeAttributes( removeAttributes );
+
+ if ( data.adv && data.adv.advName && CKEDITOR.plugins.link.synAnchorSelector )
+ element.addClass( element.getChildCount() ? 'cke_anchor' : 'cke_anchor_empty' );
+
// Update text view when user changes protocol (#4612).
if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 )
{
@@ -1376,15 +1377,8 @@ CKEDITOR.dialog.add( 'link', function( editor )
element.setHtml( data.type == 'email' ?
data.email.address : attributes[ 'data-cke-saved-href' ] );
}
- // Make the element display as an anchor if a name has been set.
- if ( element.getAttribute( 'name' ) )
- element.addClass( 'cke_anchor' );
- else
- element.removeClass( 'cke_anchor' );
-
- if ( this.fakeObj )
- editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
+ selection.selectElement( element );
delete this._.selectedElement;
}
},