summaryrefslogtreecommitdiff
path: root/plugins/forms/dialogs/button.js
diff options
context:
space:
mode:
authorlsces <lester@lsces.co.uk>2013-07-15 14:18:47 +0100
committerlsces <lester@lsces.co.uk>2013-07-15 14:18:47 +0100
commitde6d09676a9527919813a4474cc28af554a35fe1 (patch)
treea2b3c2ddf01eca1600e130125733d324b59744bb /plugins/forms/dialogs/button.js
parent1d0d1733baef4dbab3f8cd7d7150a55ef2828464 (diff)
downloadckeditor-de6d09676a9527919813a4474cc28af554a35fe1.tar.gz
ckeditor-de6d09676a9527919813a4474cc28af554a35fe1.tar.bz2
ckeditor-de6d09676a9527919813a4474cc28af554a35fe1.zip
Upgrade to CKEditor V4
Directory structure changed so many files removed and replace in a new location This batch is the actuall file changes
Diffstat (limited to 'plugins/forms/dialogs/button.js')
-rw-r--r--plugins/forms/dialogs/button.js104
1 files changed, 99 insertions, 5 deletions
diff --git a/plugins/forms/dialogs/button.js b/plugins/forms/dialogs/button.js
index 6030fd4..0abc6eb 100644
--- a/plugins/forms/dialogs/button.js
+++ b/plugins/forms/dialogs/button.js
@@ -1,6 +1,100 @@
-/*
-Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
-For licensing, see LICENSE.html or http://ckeditor.com/license
-*/
+/**
+ * @license 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' ];
+ }
+ }
-CKEDITOR.dialog.add('button',function(a){function b(c){var e=this;var d=e.getValue();if(d){c.attributes[e.id]=d;if(e.id=='name')c.attributes['data-cke-saved-name']=d;}else{delete c.attributes[e.id];if(e.id=='name')delete c.attributes['data-cke-saved-name'];}};return{title:a.lang.button.title,minWidth:350,minHeight:150,onShow:function(){var e=this;delete e.button;var c=e.getParentEditor().getSelection().getSelectedElement();if(c&&c.is('input')){var d=c.getAttribute('type');if(d in {button:1,reset:1,submit:1}){e.button=c;e.setupContent(c);}}},onOk:function(){var c=this.getParentEditor(),d=this.button,e=!d,f=d?CKEDITOR.htmlParser.fragment.fromHtml(d.getOuterHtml()).children[0]:new CKEDITOR.htmlParser.element('input');this.commitContent(f);var g=new CKEDITOR.htmlParser.basicWriter();f.writeHtml(g);var h=CKEDITOR.dom.element.createFromHtml(g.getHtml(),c.document);if(e)c.insertElement(h);else{h.replace(d);c.getSelection().selectElement(h);}},contents:[{id:'info',label:a.lang.button.title,title:a.lang.button.title,elements:[{id:'name',type:'text',label:a.lang.common.name,'default':'',setup:function(c){this.setValue(c.data('cke-saved-name')||c.getAttribute('name')||'');},commit:b},{id:'value',type:'text',label:a.lang.button.text,accessKey:'V','default':'',setup:function(c){this.setValue(c.getAttribute('value')||'');},commit:b},{id:'type',type:'select',label:a.lang.button.type,'default':'button',accessKey:'T',items:[[a.lang.button.typeBtn,'button'],[a.lang.button.typeSbm,'submit'],[a.lang.button.typeRst,'reset']],setup:function(c){this.setValue(c.getAttribute('type')||'');},commit:b}]}]};});
+ return {
+ title: editor.lang.forms.button.title,
+ minWidth: 350,
+ minHeight: 150,
+ onShow: function() {
+ delete this.button;
+ var element = this.getParentEditor().getSelection().getSelectedElement();
+ if ( element && element.is( 'input' ) ) {
+ var type = element.getAttribute( 'type' );
+ if ( type in { button:1,reset:1,submit:1 } ) {
+ this.button = element;
+ this.setupContent( element );
+ }
+ }
+ },
+ onOk: function() {
+ 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 {
+ newElement.replace( element );
+ editor.getSelection().selectElement( newElement );
+ }
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.button.title,
+ title: editor.lang.forms.button.title,
+ elements: [
+ {
+ id: 'name',
+ type: 'text',
+ label: editor.lang.common.name,
+ 'default': '',
+ setup: function( element ) {
+ this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
+ },
+ commit: commitAttributes
+ },
+ {
+ id: 'value',
+ type: 'text',
+ label: editor.lang.forms.button.text,
+ accessKey: 'V',
+ 'default': '',
+ setup: function( element ) {
+ this.setValue( element.getAttribute( 'value' ) || '' );
+ },
+ commit: commitAttributes
+ },
+ {
+ id: 'type',
+ type: 'select',
+ label: editor.lang.forms.button.type,
+ 'default': 'button',
+ accessKey: 'T',
+ items: [
+ [ editor.lang.forms.button.typeBtn, 'button' ],
+ [ editor.lang.forms.button.typeSbm, 'submit' ],
+ [ editor.lang.forms.button.typeRst, 'reset' ]
+ ],
+ setup: function( element ) {
+ this.setValue( element.getAttribute( 'type' ) || '' );
+ },
+ commit: commitAttributes
+ }
+ ]
+ }
+ ]
+ };
+});