X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fforms%2Fdialogs%2Fbutton.js;h=b7ae7f7c80d3ca4fde34587a45929654181ef552;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=dc718d7761f0de9ba3fdeeb9a5d50efd3518b1d0;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/forms/dialogs/button.js b/_source/plugins/forms/dialogs/button.js index dc718d7..b7ae7f7 100644 --- a/_source/plugins/forms/dialogs/button.js +++ b/_source/plugins/forms/dialogs/button.js @@ -1,9 +1,26 @@ /* -Copyright (c) 2003-2009, 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( '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, @@ -12,10 +29,10 @@ CKEDITOR.dialog.add( 'button', function( editor ) { delete this.button; var element = this.getParentEditor().getSelection().getSelectedElement(); - if ( element && element.getName() == "input" ) + if ( element && element.is( 'input' ) ) { var type = element.getAttribute( 'type' ); - if ( type == "button" || type == "reset" || type == "submit" ) + if ( type in { button:1, reset:1, submit:1 } ) { this.button = element; this.setupContent( element ); @@ -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,29 +68,18 @@ 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' : '', setup : function( element ) { this.setValue( - element.getAttribute( '_cke_saved_name' ) || + element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' ); }, - commit : function( data ) - { - var element = data.element; - - if ( this.getValue() ) - element.setAttribute( '_cke_saved_name', this.getValue() ); - else - { - element.removeAttribute( '_cke_saved_name' ); - 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 } ] }