X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flink%2Fdialogs%2Fanchor.js;h=2611c8c5e93d2b17d90c5df8900c229c6fcba458;hb=3fe9cac293e090ea459a3ee10d78cbe9e1dd0e03;hp=1b3515c5e812553dddc22659a7cd9f9e72cb5d86;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/plugins/link/dialogs/anchor.js b/_source/plugins/link/dialogs/anchor.js index 1b3515c..2611c8c 100644 --- a/_source/plugins/link/dialogs/anchor.js +++ b/_source/plugins/link/dialogs/anchor.js @@ -1,73 +1,119 @@ /* -Copyright (c) 2003-2010, 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 */ CKEDITOR.dialog.add( 'anchor', function( editor ) { // Function called in onShow to load selected element. - var loadElements = function( editor, selection, element ) + var loadElements = function( element ) { - this.editMode = true; - this.editObj = element; + this._.selectedElement = element; - var attributeValue = this.editObj.getAttribute( 'name' ); - if ( attributeValue ) - this.setValueOf( 'info','txtName', attributeValue ); - else - this.setValueOf( 'info','txtName', "" ); + var attributeValue = element.data( 'cke-saved-name' ); + this.setValueOf( 'info','txtName', attributeValue || '' ); }; + function createFakeAnchor( editor, anchor ) + { + return editor.createFakeElement( anchor, 'cke_anchor', 'anchor' ); + } + 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( '' ) : - editor.document.createElement( 'a' ); + var name = CKEDITOR.tools.trim( this.getValueOf( 'info', 'txtName' ) ); + var attributes = + { + id : name, + name : name, + 'data-cke-saved-name' : name + }; - // Move contents and attributes of old anchor to new anchor. - if ( this.editMode ) + if ( this._.selectedElement ) { - this.editObj.copyAttributes( element, { name : 1 } ); - this.editObj.moveChildren( element ); + if ( this._.selectedElement.data( 'cke-realelement' ) ) + { + var newFake = createFakeAnchor( editor, editor.document.createElement( 'a', { attributes: attributes } ) ); + newFake.replace( this._.selectedElement ); + } + else + this._.selectedElement.setAttributes( attributes ); } - - // 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 ); + var sel = editor.getSelection(), + range = sel && sel.getRanges()[ 0 ]; + + // Empty anchor + if ( range.collapsed ) + { + if ( CKEDITOR.plugins.link.synAnchorSelector ) + attributes[ 'class' ] = 'cke_anchor_empty'; + + if ( CKEDITOR.plugins.link.emptyAnchorFix ) + { + attributes[ 'contenteditable' ] = 'false'; + attributes[ 'data-cke-editable' ] = 1; + } + + var anchor = editor.document.createElement( 'a', { attributes: attributes } ); + + // Transform the anchor into a fake element for browsers that need it. + if ( CKEDITOR.plugins.link.fakeAnchor ) + anchor = createFakeAnchor( editor, anchor ); + + range.insertNode( anchor ); + } + else + { + if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) + attributes['class'] = 'cke_anchor'; + + // Apply style. + var style = new CKEDITOR.style( { element : 'a', attributes : attributes } ); + style.type = CKEDITOR.STYLE_INLINE; + style.apply( editor.document ); + } } + }, - return true; + onHide : function() + { + delete this._.selectedElement; }, + onShow : function() { - this.editObj = false; - this.fakeObj = false; - this.editMode = false; + var selection = editor.getSelection(), + fullySelected = selection.getSelectedElement(), + partialSelected; - var selection = editor.getSelection(); - var element = selection.getSelectedElement(); - if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) + // Detect the anchor under selection. + if ( fullySelected ) { - this.fakeObj = element; - element = editor.restoreRealElement( this.fakeObj ); - loadElements.apply( this, [ editor, selection, element ] ); - selection.selectElement( this.fakeObj ); + if ( CKEDITOR.plugins.link.fakeAnchor ) + { + var realElement = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected ); + realElement && loadElements.call( this, realElement ); + this._.selectedElement = fullySelected; + } + else if ( fullySelected.is( 'a' ) && fullySelected.hasAttribute( 'name' ) ) + loadElements.call( this, fullySelected ); } + else + { + partialSelected = CKEDITOR.plugins.link.getSelectedLink( editor ); + if ( partialSelected ) + { + loadElements.call( this, partialSelected ); + selection.selectElement( partialSelected ); + } + } + this.getContentElement( 'info', 'txtName' ).focus(); }, contents : [ @@ -81,6 +127,7 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) type : 'text', id : 'txtName', label : editor.lang.anchor.name, + required: true, validate : function() { if ( !this.getValue() )