X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fforms%2Fdialogs%2Fbutton.js;h=730864f6ce5e1948327da81fa5d9033dc3d71db3;hb=refs%2Ftags%2Fv3.5.1;hp=3e024760bc0c5a9c4e0cd09d2914cd03e9aba73f;hpb=9afde8772159bd3436f1f5b7862960307710ae5a;p=ckeditor.git diff --git a/_source/plugins/forms/dialogs/button.js b/_source/plugins/forms/dialogs/button.js index 3e02476..730864f 100644 --- a/_source/plugins/forms/dialogs/button.js +++ b/_source/plugins/forms/dialogs/button.js @@ -1,9 +1,26 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.dialog.add( 'button', function( editor ) { + function commitAttributes( element ) + { + var val = this.getValue(); + if ( val ) + { + element.attributes[ this.id ] = val; + if ( this.id == 'name' ) + element.attributes[ 'data-cke-saved-name' ] = val; + } + else + { + delete element.attributes[ this.id ]; + if ( this.id == 'name' ) + delete element.attributes[ 'data-cke-saved-name' ]; + } + } + return { title : editor.lang.button.title, minWidth : 350, @@ -24,19 +41,25 @@ CKEDITOR.dialog.add( 'button', function( editor ) }, onOk : function() { - var editor, + var editor = this.getParentEditor(), element = this.button, isInsertMode = !element; + var fake = element ? CKEDITOR.htmlParser.fragment.fromHtml( element.getOuterHtml() ).children[ 0 ] + : new CKEDITOR.htmlParser.element( 'input' ); + this.commitContent( fake ); + + var writer = new CKEDITOR.htmlParser.basicWriter(); + fake.writeHtml( writer ); + var newElement = CKEDITOR.dom.element.createFromHtml( writer.getHtml(), editor.document ); + if ( isInsertMode ) + editor.insertElement( newElement ); + else { - editor = this.getParentEditor(); - element = editor.document.createElement( 'input' ); + newElement.replace( element ); + editor.getSelection().selectElement( newElement ); } - - if ( isInsertMode ) - editor.insertElement( element ); - this.commitContent( { element : element } ); }, contents : [ { @@ -45,7 +68,7 @@ CKEDITOR.dialog.add( 'button', function( editor ) title : editor.lang.button.title, elements : [ { - id : '_cke_saved_name', + id : 'name', type : 'text', label : editor.lang.common.name, 'default' : '', @@ -56,18 +79,7 @@ CKEDITOR.dialog.add( 'button', function( editor ) element.getAttribute( 'name' ) || '' ); }, - commit : function( data ) - { - var element = data.element; - - if ( this.getValue() ) - element.data( 'cke-saved-name', this.getValue() ); - else - { - element.data( 'cke-saved-name', false ); - element.removeAttribute( 'name' ); - } - } + commit : commitAttributes }, { id : 'value', @@ -79,15 +91,7 @@ CKEDITOR.dialog.add( 'button', function( editor ) { this.setValue( element.getAttribute( 'value' ) || '' ); }, - commit : function( data ) - { - var element = data.element; - - if ( this.getValue() ) - element.setAttribute( 'value', this.getValue() ); - else - element.removeAttribute( 'value' ); - } + commit : commitAttributes }, { id : 'type', @@ -105,28 +109,7 @@ CKEDITOR.dialog.add( 'button', function( editor ) { this.setValue( element.getAttribute( 'type' ) || '' ); }, - commit : function( data ) - { - var element = data.element; - - if ( CKEDITOR.env.ie ) - { - var elementType = element.getAttribute( 'type' ); - var currentType = this.getValue(); - - if ( currentType != elementType ) - { - var replace = CKEDITOR.dom.element.createFromHtml( '', editor.document ); - element.copyAttributes( replace, { type : 1 } ); - replace.replace( element ); - editor.getSelection().selectElement( replace ); - data.element = replace; - } - } - else - element.setAttribute( 'type', this.getValue() ); - } + commit : commitAttributes } ] }