diff options
| author | lsces <lester@lsces.co.uk> | 2013-07-15 14:18:47 +0100 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2013-07-15 14:18:47 +0100 |
| commit | de6d09676a9527919813a4474cc28af554a35fe1 (patch) | |
| tree | a2b3c2ddf01eca1600e130125733d324b59744bb /plugins/forms/dialogs | |
| parent | 1d0d1733baef4dbab3f8cd7d7150a55ef2828464 (diff) | |
| download | ckeditor-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')
| -rw-r--r-- | plugins/forms/dialogs/button.js | 104 | ||||
| -rw-r--r-- | plugins/forms/dialogs/checkbox.js | 134 | ||||
| -rw-r--r-- | plugins/forms/dialogs/form.js | 155 | ||||
| -rw-r--r-- | plugins/forms/dialogs/hiddenfield.js | 89 | ||||
| -rw-r--r-- | plugins/forms/dialogs/radio.js | 119 | ||||
| -rw-r--r-- | plugins/forms/dialogs/select.js | 510 | ||||
| -rw-r--r-- | plugins/forms/dialogs/textarea.js | 122 | ||||
| -rw-r--r-- | plugins/forms/dialogs/textfield.js | 186 |
8 files changed, 1376 insertions, 43 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
+ }
+ ]
+ }
+ ]
+ };
+});
diff --git a/plugins/forms/dialogs/checkbox.js b/plugins/forms/dialogs/checkbox.js index 45c8760..b24656a 100644 --- a/plugins/forms/dialogs/checkbox.js +++ b/plugins/forms/dialogs/checkbox.js @@ -1,6 +1,130 @@ -/*
-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( 'checkbox', function( editor ) {
+ return {
+ title: editor.lang.forms.checkboxAndRadio.checkboxTitle,
+ minWidth: 350,
+ minHeight: 140,
+ onShow: function() {
+ delete this.checkbox;
-CKEDITOR.dialog.add('checkbox',function(a){return{title:a.lang.checkboxAndRadio.checkboxTitle,minWidth:350,minHeight:140,onShow:function(){var c=this;delete c.checkbox;var b=c.getParentEditor().getSelection().getSelectedElement();if(b&&b.getAttribute('type')=='checkbox'){c.checkbox=b;c.setupContent(b);}},onOk:function(){var b,c=this.checkbox,d=!c;if(d){b=this.getParentEditor();c=b.document.createElement('input');c.setAttribute('type','checkbox');b.insertElement(c);}this.commitContent({element:c});},contents:[{id:'info',label:a.lang.checkboxAndRadio.checkboxTitle,title:a.lang.checkboxAndRadio.checkboxTitle,startupFocus:'txtName',elements:[{id:'txtName',type:'text',label:a.lang.common.name,'default':'',accessKey:'N',setup:function(b){this.setValue(b.data('cke-saved-name')||b.getAttribute('name')||'');},commit:function(b){var c=b.element;if(this.getValue())c.data('cke-saved-name',this.getValue());else{c.data('cke-saved-name',false);c.removeAttribute('name');}}},{id:'txtValue',type:'text',label:a.lang.checkboxAndRadio.value,'default':'',accessKey:'V',setup:function(b){var c=b.getAttribute('value');this.setValue(CKEDITOR.env.ie&&c=='on'?'':c);},commit:function(b){var c=b.element,d=this.getValue();if(d&&!(CKEDITOR.env.ie&&d=='on'))c.setAttribute('value',d);else if(CKEDITOR.env.ie){var e=new CKEDITOR.dom.element('input',c.getDocument());c.copyAttributes(e,{value:1});e.replace(c);a.getSelection().selectElement(e);b.element=e;}else c.removeAttribute('value');}},{id:'cmbSelected',type:'checkbox',label:a.lang.checkboxAndRadio.selected,'default':'',accessKey:'S',value:'checked',setup:function(b){this.setValue(b.getAttribute('checked'));},commit:function(b){var c=b.element;if(CKEDITOR.env.ie){var d=!!c.getAttribute('checked'),e=!!this.getValue();if(d!=e){var f=CKEDITOR.dom.element.createFromHtml('<input type="checkbox"'+(e?' checked="checked"':'')+'/>',a.document);c.copyAttributes(f,{type:1,checked:1});f.replace(c);a.getSelection().selectElement(f);b.element=f;}}else{var g=this.getValue();if(g)c.setAttribute('checked','checked');else c.removeAttribute('checked');}}}]}]};});
+ var element = this.getParentEditor().getSelection().getSelectedElement();
+
+ if ( element && element.getAttribute( 'type' ) == 'checkbox' ) {
+ this.checkbox = element;
+ this.setupContent( element );
+ }
+ },
+ onOk: function() {
+ var editor,
+ element = this.checkbox,
+ isInsertMode = !element;
+
+ if ( isInsertMode ) {
+ editor = this.getParentEditor();
+ element = editor.document.createElement( 'input' );
+ element.setAttribute( 'type', 'checkbox' );
+ editor.insertElement( element );
+ }
+ this.commitContent({ element: element } );
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.checkboxAndRadio.checkboxTitle,
+ title: editor.lang.forms.checkboxAndRadio.checkboxTitle,
+ startupFocus: 'txtName',
+ elements: [
+ {
+ id: 'txtName',
+ type: 'text',
+ label: editor.lang.common.name,
+ 'default': '',
+ accessKey: 'N',
+ setup: function( element ) {
+ this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
+ },
+ commit: function( data ) {
+ var element = data.element;
+
+ // IE failed to update 'name' property on input elements, protect it now.
+ if ( this.getValue() )
+ element.data( 'cke-saved-name', this.getValue() );
+ else {
+ element.data( 'cke-saved-name', false );
+ element.removeAttribute( 'name' );
+ }
+ }
+ },
+ {
+ id: 'txtValue',
+ type: 'text',
+ label: editor.lang.forms.checkboxAndRadio.value,
+ 'default': '',
+ accessKey: 'V',
+ setup: function( element ) {
+ var value = element.getAttribute( 'value' );
+ // IE Return 'on' as default attr value.
+ this.setValue( CKEDITOR.env.ie && value == 'on' ? '' : value );
+ },
+ commit: function( data ) {
+ var element = data.element,
+ value = this.getValue();
+
+ if ( value && !( CKEDITOR.env.ie && value == 'on' ) )
+ element.setAttribute( 'value', value );
+ else {
+ if ( CKEDITOR.env.ie ) {
+ // Remove attribute 'value' of checkbox (#4721).
+ var checkbox = new CKEDITOR.dom.element( 'input', element.getDocument() );
+ element.copyAttributes( checkbox, { value:1 } );
+ checkbox.replace( element );
+ editor.getSelection().selectElement( checkbox );
+ data.element = checkbox;
+ } else
+ element.removeAttribute( 'value' );
+ }
+ }
+ },
+ {
+ id: 'cmbSelected',
+ type: 'checkbox',
+ label: editor.lang.forms.checkboxAndRadio.selected,
+ 'default': '',
+ accessKey: 'S',
+ value: "checked",
+ setup: function( element ) {
+ this.setValue( element.getAttribute( 'checked' ) );
+ },
+ commit: function( data ) {
+ var element = data.element;
+
+ if ( CKEDITOR.env.ie ) {
+ var isElementChecked = !!element.getAttribute( 'checked' ),
+ isChecked = !!this.getValue();
+
+ if ( isElementChecked != isChecked ) {
+ var replace = CKEDITOR.dom.element.createFromHtml( '<input type="checkbox"' + ( isChecked ? ' checked="checked"' : '' )
+ + '/>', editor.document );
+
+ element.copyAttributes( replace, { type:1,checked:1 } );
+ replace.replace( element );
+ editor.getSelection().selectElement( replace );
+ data.element = replace;
+ }
+ } else {
+ var value = this.getValue();
+ if ( value )
+ element.setAttribute( 'checked', 'checked' );
+ else
+ element.removeAttribute( 'checked' );
+ }
+ }
+ }
+ ]
+ }
+ ]
+ };
+});
diff --git a/plugins/forms/dialogs/form.js b/plugins/forms/dialogs/form.js index 8b4e90f..58bf9a3 100644 --- a/plugins/forms/dialogs/form.js +++ b/plugins/forms/dialogs/form.js @@ -1,6 +1,151 @@ -/*
-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( 'form', function( editor ) {
+ var autoAttributes = { action:1,id:1,method:1,enctype:1,target:1 };
-CKEDITOR.dialog.add('form',function(a){var b={action:1,id:1,method:1,enctype:1,target:1};return{title:a.lang.form.title,minWidth:350,minHeight:200,onShow:function(){var e=this;delete e.form;var c=e.getParentEditor().getSelection().getStartElement(),d=c&&c.getAscendant('form',true);if(d){e.form=d;e.setupContent(d);}},onOk:function(){var c,d=this.form,e=!d;if(e){c=this.getParentEditor();d=c.document.createElement('form');!CKEDITOR.env.ie&&d.append(c.document.createElement('br'));}if(e)c.insertElement(d);this.commitContent(d);},onLoad:function(){function c(e){this.setValue(e.getAttribute(this.id)||'');};function d(e){var f=this;if(f.getValue())e.setAttribute(f.id,f.getValue());else e.removeAttribute(f.id);};this.foreach(function(e){if(b[e.id]){e.setup=c;e.commit=d;}});},contents:[{id:'info',label:a.lang.form.title,title:a.lang.form.title,elements:[{id:'txtName',type:'text',label:a.lang.common.name,'default':'',accessKey:'N',setup:function(c){this.setValue(c.data('cke-saved-name')||c.getAttribute('name')||'');},commit:function(c){if(this.getValue())c.data('cke-saved-name',this.getValue());else{c.data('cke-saved-name',false);c.removeAttribute('name');}}},{id:'action',type:'text',label:a.lang.form.action,'default':'',accessKey:'T'},{type:'hbox',widths:['45%','55%'],children:[{id:'id',type:'text',label:a.lang.common.id,'default':'',accessKey:'I'},{id:'enctype',type:'select',label:a.lang.form.encoding,style:'width:100%',accessKey:'E','default':'',items:[[''],['text/plain'],['multipart/form-data'],['application/x-www-form-urlencoded']]}]},{type:'hbox',widths:['45%','55%'],children:[{id:'target',type:'select',label:a.lang.common.target,style:'width:100%',accessKey:'M','default':'',items:[[a.lang.common.notSet,''],[a.lang.common.targetNew,'_blank'],[a.lang.common.targetTop,'_top'],[a.lang.common.targetSelf,'_self'],[a.lang.common.targetParent,'_parent']]},{id:'method',type:'select',label:a.lang.form.method,accessKey:'M','default':'GET',items:[['GET','get'],['POST','post']]}]}]}]};});
+ return {
+ title: editor.lang.forms.form.title,
+ minWidth: 350,
+ minHeight: 200,
+ onShow: function() {
+ delete this.form;
+
+ var path = this.getParentEditor().elementPath(),
+ form = path.contains( 'form', 1 );
+
+ if ( form ) {
+ this.form = form;
+ this.setupContent( form );
+ }
+ },
+ onOk: function() {
+ var editor,
+ element = this.form,
+ isInsertMode = !element;
+
+ if ( isInsertMode ) {
+ editor = this.getParentEditor();
+ element = editor.document.createElement( 'form' );
+ !CKEDITOR.env.ie && element.append( editor.document.createElement( 'br' ) );
+ }
+
+ if ( isInsertMode )
+ editor.insertElement( element );
+ this.commitContent( element );
+ },
+ onLoad: function() {
+ function autoSetup( element ) {
+ this.setValue( element.getAttribute( this.id ) || '' );
+ }
+
+ function autoCommit( element ) {
+ if ( this.getValue() )
+ element.setAttribute( this.id, this.getValue() );
+ else
+ element.removeAttribute( this.id );
+ }
+
+ this.foreach( function( contentObj ) {
+ if ( autoAttributes[ contentObj.id ] ) {
+ contentObj.setup = autoSetup;
+ contentObj.commit = autoCommit;
+ }
+ });
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.form.title,
+ title: editor.lang.forms.form.title,
+ elements: [
+ {
+ id: 'txtName',
+ type: 'text',
+ label: editor.lang.common.name,
+ 'default': '',
+ accessKey: 'N',
+ setup: function( element ) {
+ this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.data( 'cke-saved-name', this.getValue() );
+ else {
+ element.data( 'cke-saved-name', false );
+ element.removeAttribute( 'name' );
+ }
+ }
+ },
+ {
+ id: 'action',
+ type: 'text',
+ label: editor.lang.forms.form.action,
+ 'default': '',
+ accessKey: 'T'
+ },
+ {
+ type: 'hbox',
+ widths: [ '45%', '55%' ],
+ children: [
+ {
+ id: 'id',
+ type: 'text',
+ label: editor.lang.common.id,
+ 'default': '',
+ accessKey: 'I'
+ },
+ {
+ id: 'enctype',
+ type: 'select',
+ label: editor.lang.forms.form.encoding,
+ style: 'width:100%',
+ accessKey: 'E',
+ 'default': '',
+ items: [
+ [ '' ],
+ [ 'text/plain' ],
+ [ 'multipart/form-data' ],
+ [ 'application/x-www-form-urlencoded' ]
+ ]
+ }
+ ]
+ },
+ {
+ type: 'hbox',
+ widths: [ '45%', '55%' ],
+ children: [
+ {
+ id: 'target',
+ type: 'select',
+ label: editor.lang.common.target,
+ style: 'width:100%',
+ accessKey: 'M',
+ 'default': '',
+ items: [
+ [ editor.lang.common.notSet, '' ],
+ [ editor.lang.common.targetNew, '_blank' ],
+ [ editor.lang.common.targetTop, '_top' ],
+ [ editor.lang.common.targetSelf, '_self' ],
+ [ editor.lang.common.targetParent, '_parent' ]
+ ]
+ },
+ {
+ id: 'method',
+ type: 'select',
+ label: editor.lang.forms.form.method,
+ accessKey: 'M',
+ 'default': 'GET',
+ items: [
+ [ 'GET', 'get' ],
+ [ 'POST', 'post' ]
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ };
+});
diff --git a/plugins/forms/dialogs/hiddenfield.js b/plugins/forms/dialogs/hiddenfield.js index 0bce0cf..601a088 100644 --- a/plugins/forms/dialogs/hiddenfield.js +++ b/plugins/forms/dialogs/hiddenfield.js @@ -1,6 +1,85 @@ -/*
-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( 'hiddenfield', function( editor ) {
+ return {
+ title: editor.lang.forms.hidden.title,
+ hiddenField: null,
+ minWidth: 350,
+ minHeight: 110,
+ onShow: function() {
+ delete this.hiddenField;
-CKEDITOR.dialog.add('hiddenfield',function(a){return{title:a.lang.hidden.title,hiddenField:null,minWidth:350,minHeight:110,onShow:function(){var e=this;delete e.hiddenField;var b=e.getParentEditor(),c=b.getSelection(),d=c.getSelectedElement();if(d&&d.data('cke-real-element-type')&&d.data('cke-real-element-type')=='hiddenfield'){e.hiddenField=d;d=b.restoreRealElement(e.hiddenField);e.setupContent(d);c.selectElement(e.hiddenField);}},onOk:function(){var g=this;var b=g.getValueOf('info','_cke_saved_name'),c=g.getValueOf('info','value'),d=g.getParentEditor(),e=CKEDITOR.env.ie&&!(CKEDITOR.document.$.documentMode>=8)?d.document.createElement('<input name="'+CKEDITOR.tools.htmlEncode(b)+'">'):d.document.createElement('input');e.setAttribute('type','hidden');g.commitContent(e);var f=d.createFakeElement(e,'cke_hidden','hiddenfield');if(!g.hiddenField)d.insertElement(f);else{f.replace(g.hiddenField);d.getSelection().selectElement(f);}return true;},contents:[{id:'info',label:a.lang.hidden.title,title:a.lang.hidden.title,elements:[{id:'_cke_saved_name',type:'text',label:a.lang.hidden.name,'default':'',accessKey:'N',setup:function(b){this.setValue(b.data('cke-saved-name')||b.getAttribute('name')||'');},commit:function(b){if(this.getValue())b.setAttribute('name',this.getValue());else b.removeAttribute('name');}},{id:'value',type:'text',label:a.lang.hidden.value,'default':'',accessKey:'V',setup:function(b){this.setValue(b.getAttribute('value')||'');},commit:function(b){if(this.getValue())b.setAttribute('value',this.getValue());else b.removeAttribute('value');}}]}]};});
+ var editor = this.getParentEditor(),
+ selection = editor.getSelection(),
+ element = selection.getSelectedElement();
+
+ if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'hiddenfield' ) {
+ this.hiddenField = element;
+ element = editor.restoreRealElement( this.hiddenField );
+ this.setupContent( element );
+ selection.selectElement( this.hiddenField );
+ }
+ },
+ onOk: function() {
+ var name = this.getValueOf( 'info', '_cke_saved_name' ),
+ value = this.getValueOf( 'info', 'value' ),
+ editor = this.getParentEditor(),
+ element = CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) ? editor.document.createElement( '<input name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) : editor.document.createElement( 'input' );
+
+ element.setAttribute( 'type', 'hidden' );
+ this.commitContent( element );
+ var fakeElement = editor.createFakeElement( element, 'cke_hidden', 'hiddenfield' );
+ if ( !this.hiddenField )
+ editor.insertElement( fakeElement );
+ else {
+ fakeElement.replace( this.hiddenField );
+ editor.getSelection().selectElement( fakeElement );
+ }
+ return true;
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.hidden.title,
+ title: editor.lang.forms.hidden.title,
+ elements: [
+ {
+ id: '_cke_saved_name',
+ type: 'text',
+ label: editor.lang.forms.hidden.name,
+ 'default': '',
+ accessKey: 'N',
+ setup: function( element ) {
+ this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.setAttribute( 'name', this.getValue() );
+ else {
+ element.removeAttribute( 'name' );
+ }
+ }
+ },
+ {
+ id: 'value',
+ type: 'text',
+ label: editor.lang.forms.hidden.value,
+ 'default': '',
+ accessKey: 'V',
+ setup: function( element ) {
+ this.setValue( element.getAttribute( 'value' ) || '' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.setAttribute( 'value', this.getValue() );
+ else
+ element.removeAttribute( 'value' );
+ }
+ }
+ ]
+ }
+ ]
+ };
+});
diff --git a/plugins/forms/dialogs/radio.js b/plugins/forms/dialogs/radio.js index 4a05d9b..ebdf951 100644 --- a/plugins/forms/dialogs/radio.js +++ b/plugins/forms/dialogs/radio.js @@ -1,6 +1,115 @@ -/*
-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( 'radio', function( editor ) {
+ return {
+ title: editor.lang.forms.checkboxAndRadio.radioTitle,
+ minWidth: 350,
+ minHeight: 140,
+ onShow: function() {
+ delete this.radioButton;
-CKEDITOR.dialog.add('radio',function(a){return{title:a.lang.checkboxAndRadio.radioTitle,minWidth:350,minHeight:140,onShow:function(){var c=this;delete c.radioButton;var b=c.getParentEditor().getSelection().getSelectedElement();if(b&&b.getName()=='input'&&b.getAttribute('type')=='radio'){c.radioButton=b;c.setupContent(b);}},onOk:function(){var b,c=this.radioButton,d=!c;if(d){b=this.getParentEditor();c=b.document.createElement('input');c.setAttribute('type','radio');}if(d)b.insertElement(c);this.commitContent({element:c});},contents:[{id:'info',label:a.lang.checkboxAndRadio.radioTitle,title:a.lang.checkboxAndRadio.radioTitle,elements:[{id:'name',type:'text',label:a.lang.common.name,'default':'',accessKey:'N',setup:function(b){this.setValue(b.data('cke-saved-name')||b.getAttribute('name')||'');},commit:function(b){var c=b.element;if(this.getValue())c.data('cke-saved-name',this.getValue());else{c.data('cke-saved-name',false);c.removeAttribute('name');}}},{id:'value',type:'text',label:a.lang.checkboxAndRadio.value,'default':'',accessKey:'V',setup:function(b){this.setValue(b.getAttribute('value')||'');},commit:function(b){var c=b.element;if(this.getValue())c.setAttribute('value',this.getValue());else c.removeAttribute('value');}},{id:'checked',type:'checkbox',label:a.lang.checkboxAndRadio.selected,'default':'',accessKey:'S',value:'checked',setup:function(b){this.setValue(b.getAttribute('checked'));},commit:function(b){var c=b.element;if(!(CKEDITOR.env.ie||CKEDITOR.env.opera)){if(this.getValue())c.setAttribute('checked','checked');else c.removeAttribute('checked');}else{var d=c.getAttribute('checked'),e=!!this.getValue();if(d!=e){var f=CKEDITOR.dom.element.createFromHtml('<input type="radio"'+(e?' checked="checked"':'')+'></input>',a.document);c.copyAttributes(f,{type:1,checked:1});f.replace(c);a.getSelection().selectElement(f);b.element=f;}}}}]}]};});
+ var element = this.getParentEditor().getSelection().getSelectedElement();
+ if ( element && element.getName() == 'input' && element.getAttribute( 'type' ) == 'radio' ) {
+ this.radioButton = element;
+ this.setupContent( element );
+ }
+ },
+ onOk: function() {
+ var editor,
+ element = this.radioButton,
+ isInsertMode = !element;
+
+ if ( isInsertMode ) {
+ editor = this.getParentEditor();
+ element = editor.document.createElement( 'input' );
+ element.setAttribute( 'type', 'radio' );
+ }
+
+ if ( isInsertMode )
+ editor.insertElement( element );
+ this.commitContent({ element: element } );
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.checkboxAndRadio.radioTitle,
+ title: editor.lang.forms.checkboxAndRadio.radioTitle,
+ elements: [
+ {
+ id: 'name',
+ type: 'text',
+ label: editor.lang.common.name,
+ 'default': '',
+ accessKey: 'N',
+ setup: function( element ) {
+ this.setValue( element.data( 'cke-saved-name' ) || 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' );
+ }
+ }
+ },
+ {
+ id: 'value',
+ type: 'text',
+ label: editor.lang.forms.checkboxAndRadio.value,
+ 'default': '',
+ accessKey: 'V',
+ setup: function( element ) {
+ this.setValue( element.getAttribute( 'value' ) || '' );
+ },
+ commit: function( data ) {
+ var element = data.element;
+
+ if ( this.getValue() )
+ element.setAttribute( 'value', this.getValue() );
+ else
+ element.removeAttribute( 'value' );
+ }
+ },
+ {
+ id: 'checked',
+ type: 'checkbox',
+ label: editor.lang.forms.checkboxAndRadio.selected,
+ 'default': '',
+ accessKey: 'S',
+ value: "checked",
+ setup: function( element ) {
+ this.setValue( element.getAttribute( 'checked' ) );
+ },
+ commit: function( data ) {
+ var element = data.element;
+
+ if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera ) ) {
+ if ( this.getValue() )
+ element.setAttribute( 'checked', 'checked' );
+ else
+ element.removeAttribute( 'checked' );
+ } else {
+ var isElementChecked = element.getAttribute( 'checked' );
+ var isChecked = !!this.getValue();
+
+ if ( isElementChecked != isChecked ) {
+ var replace = CKEDITOR.dom.element.createFromHtml( '<input type="radio"' + ( isChecked ? ' checked="checked"' : '' )
+ + '></input>', editor.document );
+ element.copyAttributes( replace, { type:1,checked:1 } );
+ replace.replace( element );
+ editor.getSelection().selectElement( replace );
+ data.element = replace;
+ }
+ }
+ }
+ }
+ ]
+ }
+ ]
+ };
+});
diff --git a/plugins/forms/dialogs/select.js b/plugins/forms/dialogs/select.js index 37ec6d4..53aaf58 100644 --- a/plugins/forms/dialogs/select.js +++ b/plugins/forms/dialogs/select.js @@ -1,9 +1,503 @@ -/*
-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( 'select', function( editor ) {
+ // Add a new option to a SELECT object (combo or list).
+ function addOption( combo, optionText, optionValue, documentObject, index ) {
+ combo = getSelect( combo );
+ var oOption;
+ if ( documentObject )
+ oOption = documentObject.createElement( "OPTION" );
+ else
+ oOption = document.createElement( "OPTION" );
-CKEDITOR.dialog.add('select',function(a){function b(k,l,m,n,o){k=j(k);var p;if(n)p=n.createElement('OPTION');else p=document.createElement('OPTION');if(k&&p&&p.getName()=='option'){if(CKEDITOR.env.ie){if(!isNaN(parseInt(o,10)))k.$.options.add(p.$,o);else k.$.options.add(p.$);p.$.innerHTML=l.length>0?l:'';p.$.value=m;}else{if(o!==null&&o<k.getChildCount())k.getChild(o<0?0:o).insertBeforeMe(p);else k.append(p);p.setText(l.length>0?l:'');p.setValue(m);}}else return false;return p;};function c(k){k=j(k);var l=g(k);for(var m=k.getChildren().count()-1;m>=0;m--){if(k.getChild(m).$.selected)k.getChild(m).remove();}h(k,l);};function d(k,l,m,n){k=j(k);if(l<0)return false;var o=k.getChild(l);o.setText(m);o.setValue(n);return o;};function e(k){k=j(k);while(k.getChild(0)&&k.getChild(0).remove()){}};function f(k,l,m){k=j(k);var n=g(k);if(n<0)return false;var o=n+l;o=o<0?0:o;o=o>=k.getChildCount()?k.getChildCount()-1:o;if(n==o)return false;var p=k.getChild(n),q=p.getText(),r=p.getValue();p.remove();p=b(k,q,r,!m?null:m,o);h(k,o);return p;};function g(k){k=j(k);return k?k.$.selectedIndex:-1;};function h(k,l){k=j(k);if(l<0)return null;var m=k.getChildren().count();k.$.selectedIndex=l>=m?m-1:l;return k;};function i(k){k=j(k);return k?k.getChildren():false;};function j(k){if(k&&k.domId&&k.getInputElement().$)return k.getInputElement();else if(k&&k.$)return k;return false;};return{title:a.lang.select.title,minWidth:CKEDITOR.env.ie?460:395,minHeight:CKEDITOR.env.ie?320:300,onShow:function(){var n=this;delete n.selectBox;n.setupContent('clear');var k=n.getParentEditor().getSelection().getSelectedElement();if(k&&k.getName()=='select'){n.selectBox=k;n.setupContent(k.getName(),k);var l=i(k);for(var m=0;m<l.count();m++)n.setupContent('option',l.getItem(m));}},onOk:function(){var k=this.getParentEditor(),l=this.selectBox,m=!l;if(m)l=k.document.createElement('select');this.commitContent(l);if(m){k.insertElement(l);if(CKEDITOR.env.ie){var n=k.getSelection(),o=n.createBookmarks();setTimeout(function(){n.selectBookmarks(o);},0);}}},contents:[{id:'info',label:a.lang.select.selectInfo,title:a.lang.select.selectInfo,accessKey:'',elements:[{id:'txtName',type:'text',widths:['25%','75%'],labelLayout:'horizontal',label:a.lang.common.name,'default':'',accessKey:'N',style:'width:350px',setup:function(k,l){if(k=='clear')this.setValue(this['default']||'');else if(k=='select')this.setValue(l.data('cke-saved-name')||l.getAttribute('name')||'');},commit:function(k){if(this.getValue())k.data('cke-saved-name',this.getValue());
-else{k.data('cke-saved-name',false);k.removeAttribute('name');}}},{id:'txtValue',type:'text',widths:['25%','75%'],labelLayout:'horizontal',label:a.lang.select.value,style:'width:350px','default':'',className:'cke_disabled',onLoad:function(){this.getInputElement().setAttribute('readOnly',true);},setup:function(k,l){if(k=='clear')this.setValue('');else if(k=='option'&&l.getAttribute('selected'))this.setValue(l.$.value);}},{type:'hbox',widths:['175px','170px'],children:[{id:'txtSize',type:'text',labelLayout:'horizontal',label:a.lang.select.size,'default':'',accessKey:'S',style:'width:175px',validate:function(){var k=CKEDITOR.dialog.validate.integer(a.lang.common.validateNumberFailed);return this.getValue()===''||k.apply(this);},setup:function(k,l){if(k=='select')this.setValue(l.getAttribute('size')||'');if(CKEDITOR.env.webkit)this.getInputElement().setStyle('width','86px');},commit:function(k){if(this.getValue())k.setAttribute('size',this.getValue());else k.removeAttribute('size');}},{type:'html',html:'<span>'+CKEDITOR.tools.htmlEncode(a.lang.select.lines)+'</span>'}]},{type:'html',html:'<span>'+CKEDITOR.tools.htmlEncode(a.lang.select.opAvail)+'</span>'},{type:'hbox',widths:['115px','115px','100px'],children:[{type:'vbox',children:[{id:'txtOptName',type:'text',label:a.lang.select.opText,style:'width:115px',setup:function(k,l){if(k=='clear')this.setValue('');}},{type:'select',id:'cmbName',label:'',title:'',size:5,style:'width:115px;height:75px',items:[],onChange:function(){var k=this.getDialog(),l=k.getContentElement('info','cmbValue'),m=k.getContentElement('info','txtOptName'),n=k.getContentElement('info','txtOptValue'),o=g(this);h(l,o);m.setValue(this.getValue());n.setValue(l.getValue());},setup:function(k,l){if(k=='clear')e(this);else if(k=='option')b(this,l.getText(),l.getText(),this.getDialog().getParentEditor().document);},commit:function(k){var l=this.getDialog(),m=i(this),n=i(l.getContentElement('info','cmbValue')),o=l.getContentElement('info','txtValue').getValue();e(k);for(var p=0;p<m.count();p++){var q=b(k,m.getItem(p).getValue(),n.getItem(p).getValue(),l.getParentEditor().document);if(n.getItem(p).getValue()==o){q.setAttribute('selected','selected');q.selected=true;}}}}]},{type:'vbox',children:[{id:'txtOptValue',type:'text',label:a.lang.select.opValue,style:'width:115px',setup:function(k,l){if(k=='clear')this.setValue('');}},{type:'select',id:'cmbValue',label:'',size:5,style:'width:115px;height:75px',items:[],onChange:function(){var k=this.getDialog(),l=k.getContentElement('info','cmbName'),m=k.getContentElement('info','txtOptName'),n=k.getContentElement('info','txtOptValue'),o=g(this);
-h(l,o);m.setValue(l.getValue());n.setValue(this.getValue());},setup:function(k,l){var n=this;if(k=='clear')e(n);else if(k=='option'){var m=l.getValue();b(n,m,m,n.getDialog().getParentEditor().document);if(l.getAttribute('selected')=='selected')n.getDialog().getContentElement('info','txtValue').setValue(m);}}}]},{type:'vbox',padding:5,children:[{type:'button',id:'btnAdd',style:'',label:a.lang.select.btnAdd,title:a.lang.select.btnAdd,style:'width:100%;',onClick:function(){var k=this.getDialog(),l=k.getParentEditor(),m=k.getContentElement('info','txtOptName'),n=k.getContentElement('info','txtOptValue'),o=k.getContentElement('info','cmbName'),p=k.getContentElement('info','cmbValue');b(o,m.getValue(),m.getValue(),k.getParentEditor().document);b(p,n.getValue(),n.getValue(),k.getParentEditor().document);m.setValue('');n.setValue('');}},{type:'button',id:'btnModify',label:a.lang.select.btnModify,title:a.lang.select.btnModify,style:'width:100%;',onClick:function(){var k=this.getDialog(),l=k.getContentElement('info','txtOptName'),m=k.getContentElement('info','txtOptValue'),n=k.getContentElement('info','cmbName'),o=k.getContentElement('info','cmbValue'),p=g(n);if(p>=0){d(n,p,l.getValue(),l.getValue());d(o,p,m.getValue(),m.getValue());}}},{type:'button',id:'btnUp',style:'width:100%;',label:a.lang.select.btnUp,title:a.lang.select.btnUp,onClick:function(){var k=this.getDialog(),l=k.getContentElement('info','cmbName'),m=k.getContentElement('info','cmbValue');f(l,-1,k.getParentEditor().document);f(m,-1,k.getParentEditor().document);}},{type:'button',id:'btnDown',style:'width:100%;',label:a.lang.select.btnDown,title:a.lang.select.btnDown,onClick:function(){var k=this.getDialog(),l=k.getContentElement('info','cmbName'),m=k.getContentElement('info','cmbValue');f(l,1,k.getParentEditor().document);f(m,1,k.getParentEditor().document);}}]}]},{type:'hbox',widths:['40%','20%','40%'],children:[{type:'button',id:'btnSetValue',label:a.lang.select.btnSetValue,title:a.lang.select.btnSetValue,onClick:function(){var k=this.getDialog(),l=k.getContentElement('info','cmbValue'),m=k.getContentElement('info','txtValue');m.setValue(l.getValue());}},{type:'button',id:'btnDelete',label:a.lang.select.btnDelete,title:a.lang.select.btnDelete,onClick:function(){var k=this.getDialog(),l=k.getContentElement('info','cmbName'),m=k.getContentElement('info','cmbValue'),n=k.getContentElement('info','txtOptName'),o=k.getContentElement('info','txtOptValue');c(l);c(m);n.setValue('');o.setValue('');}},{id:'chkMulti',type:'checkbox',label:a.lang.select.chkMulti,'default':'',accessKey:'M',value:'checked',setup:function(k,l){if(k=='select')this.setValue(l.getAttribute('multiple'));
-if(CKEDITOR.env.webkit)this.getElement().getParent().setStyle('vertical-align','middle');},commit:function(k){if(this.getValue())k.setAttribute('multiple',this.getValue());else k.removeAttribute('multiple');}}]}]}]};});
+ if ( combo && oOption && oOption.getName() == 'option' ) {
+ if ( CKEDITOR.env.ie ) {
+ if ( !isNaN( parseInt( index, 10 ) ) )
+ combo.$.options.add( oOption.$, index );
+ else
+ combo.$.options.add( oOption.$ );
+
+ oOption.$.innerHTML = optionText.length > 0 ? optionText : '';
+ oOption.$.value = optionValue;
+ } else {
+ if ( index !== null && index < combo.getChildCount() )
+ combo.getChild( index < 0 ? 0 : index ).insertBeforeMe( oOption );
+ else
+ combo.append( oOption );
+
+ oOption.setText( optionText.length > 0 ? optionText : '' );
+ oOption.setValue( optionValue );
+ }
+ } else
+ return false;
+
+ return oOption;
+ }
+ // Remove all selected options from a SELECT object.
+ function removeSelectedOptions( combo ) {
+ combo = getSelect( combo );
+
+ // Save the selected index
+ var iSelectedIndex = getSelectedIndex( combo );
+
+ // Remove all selected options.
+ for ( var i = combo.getChildren().count() - 1; i >= 0; i-- ) {
+ if ( combo.getChild( i ).$.selected )
+ combo.getChild( i ).remove();
+ }
+
+ // Reset the selection based on the original selected index.
+ setSelectedIndex( combo, iSelectedIndex );
+ }
+ //Modify option from a SELECT object.
+ function modifyOption( combo, index, title, value ) {
+ combo = getSelect( combo );
+ if ( index < 0 )
+ return false;
+ var child = combo.getChild( index );
+ child.setText( title );
+ child.setValue( value );
+ return child;
+ }
+
+ function removeAllOptions( combo ) {
+ combo = getSelect( combo );
+ while ( combo.getChild( 0 ) && combo.getChild( 0 ).remove() ) {
+ /*jsl:pass*/
+ }
+ }
+ // Moves the selected option by a number of steps (also negative).
+ function changeOptionPosition( combo, steps, documentObject ) {
+ combo = getSelect( combo );
+ var iActualIndex = getSelectedIndex( combo );
+ if ( iActualIndex < 0 )
+ return false;
+
+ var iFinalIndex = iActualIndex + steps;
+ iFinalIndex = ( iFinalIndex < 0 ) ? 0 : iFinalIndex;
+ iFinalIndex = ( iFinalIndex >= combo.getChildCount() ) ? combo.getChildCount() - 1 : iFinalIndex;
+
+ if ( iActualIndex == iFinalIndex )
+ return false;
+
+ var oOption = combo.getChild( iActualIndex ),
+ sText = oOption.getText(),
+ sValue = oOption.getValue();
+
+ oOption.remove();
+
+ oOption = addOption( combo, sText, sValue, ( !documentObject ) ? null : documentObject, iFinalIndex );
+ setSelectedIndex( combo, iFinalIndex );
+ return oOption;
+ }
+
+ function getSelectedIndex( combo ) {
+ combo = getSelect( combo );
+ return combo ? combo.$.selectedIndex : -1;
+ }
+
+ function setSelectedIndex( combo, index ) {
+ combo = getSelect( combo );
+ if ( index < 0 )
+ return null;
+ var count = combo.getChildren().count();
+ combo.$.selectedIndex = ( index >= count ) ? ( count - 1 ) : index;
+ return combo;
+ }
+
+ function getOptions( combo ) {
+ combo = getSelect( combo );
+ return combo ? combo.getChildren() : false;
+ }
+
+ function getSelect( obj ) {
+ if ( obj && obj.domId && obj.getInputElement().$ ) // Dialog element.
+ return obj.getInputElement();
+ else if ( obj && obj.$ )
+ return obj;
+ return false;
+ }
+
+ return {
+ title: editor.lang.forms.select.title,
+ minWidth: CKEDITOR.env.ie ? 460 : 395,
+ minHeight: CKEDITOR.env.ie ? 320 : 300,
+ onShow: function() {
+ delete this.selectBox;
+ this.setupContent( 'clear' );
+ var element = this.getParentEditor().getSelection().getSelectedElement();
+ if ( element && element.getName() == "select" ) {
+ this.selectBox = element;
+ this.setupContent( element.getName(), element );
+
+ // Load Options into dialog.
+ var objOptions = getOptions( element );
+ for ( var i = 0; i < objOptions.count(); i++ )
+ this.setupContent( 'option', objOptions.getItem( i ) );
+ }
+ },
+ onOk: function() {
+ var editor = this.getParentEditor(),
+ element = this.selectBox,
+ isInsertMode = !element;
+
+ if ( isInsertMode )
+ element = editor.document.createElement( 'select' );
+ this.commitContent( element );
+
+ if ( isInsertMode ) {
+ editor.insertElement( element );
+ if ( CKEDITOR.env.ie ) {
+ var sel = editor.getSelection(),
+ bms = sel.createBookmarks();
+ setTimeout( function() {
+ sel.selectBookmarks( bms );
+ }, 0 );
+ }
+ }
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.select.selectInfo,
+ title: editor.lang.forms.select.selectInfo,
+ accessKey: '',
+ elements: [
+ {
+ id: 'txtName',
+ type: 'text',
+ widths: [ '25%', '75%' ],
+ labelLayout: 'horizontal',
+ label: editor.lang.common.name,
+ 'default': '',
+ accessKey: 'N',
+ style: 'width:350px',
+ setup: function( name, element ) {
+ if ( name == 'clear' )
+ this.setValue( this[ 'default' ] || '' );
+ else if ( name == 'select' ) {
+ this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
+ }
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.data( 'cke-saved-name', this.getValue() );
+ else {
+ element.data( 'cke-saved-name', false );
+ element.removeAttribute( 'name' );
+ }
+ }
+ },
+ {
+ id: 'txtValue',
+ type: 'text',
+ widths: [ '25%', '75%' ],
+ labelLayout: 'horizontal',
+ label: editor.lang.forms.select.value,
+ style: 'width:350px',
+ 'default': '',
+ className: 'cke_disabled',
+ onLoad: function() {
+ this.getInputElement().setAttribute( 'readOnly', true );
+ },
+ setup: function( name, element ) {
+ if ( name == 'clear' )
+ this.setValue( '' );
+ else if ( name == 'option' && element.getAttribute( 'selected' ) )
+ this.setValue( element.$.value );
+ }
+ },
+ {
+ type: 'hbox',
+ widths: [ '175px', '170px' ],
+ children: [
+ {
+ id: 'txtSize',
+ type: 'text',
+ labelLayout: 'horizontal',
+ label: editor.lang.forms.select.size,
+ 'default': '',
+ accessKey: 'S',
+ style: 'width:175px',
+ validate: function() {
+ var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );
+ return ( ( this.getValue() === '' ) || func.apply( this ) );
+ },
+ setup: function( name, element ) {
+ if ( name == 'select' )
+ this.setValue( element.getAttribute( 'size' ) || '' );
+ if ( CKEDITOR.env.webkit )
+ this.getInputElement().setStyle( 'width', '86px' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.setAttribute( 'size', this.getValue() );
+ else
+ element.removeAttribute( 'size' );
+ }
+ },
+ {
+ type: 'html',
+ html: '<span>' + CKEDITOR.tools.htmlEncode( editor.lang.forms.select.lines ) + '</span>'
+ }
+ ]
+ },
+ {
+ type: 'html',
+ html: '<span>' + CKEDITOR.tools.htmlEncode( editor.lang.forms.select.opAvail ) + '</span>'
+ },
+ {
+ type: 'hbox',
+ widths: [ '115px', '115px', '100px' ],
+ children: [
+ {
+ type: 'vbox',
+ children: [
+ {
+ id: 'txtOptName',
+ type: 'text',
+ label: editor.lang.forms.select.opText,
+ style: 'width:115px',
+ setup: function( name, element ) {
+ if ( name == 'clear' )
+ this.setValue( "" );
+ }
+ },
+ {
+ type: 'select',
+ id: 'cmbName',
+ label: '',
+ title: '',
+ size: 5,
+ style: 'width:115px;height:75px',
+ items: [],
+ onChange: function() {
+ var dialog = this.getDialog(),
+ values = dialog.getContentElement( 'info', 'cmbValue' ),
+ optName = dialog.getContentElement( 'info', 'txtOptName' ),
+ optValue = dialog.getContentElement( 'info', 'txtOptValue' ),
+ iIndex = getSelectedIndex( this );
+
+ setSelectedIndex( values, iIndex );
+ optName.setValue( this.getValue() );
+ optValue.setValue( values.getValue() );
+ },
+ setup: function( name, element ) {
+ if ( name == 'clear' )
+ removeAllOptions( this );
+ else if ( name == 'option' )
+ addOption( this, element.getText(), element.getText(), this.getDialog().getParentEditor().document );
+ },
+ commit: function( element ) {
+ var dialog = this.getDialog(),
+ optionsNames = getOptions( this ),
+ optionsValues = getOptions( dialog.getContentElement( 'info', 'cmbValue' ) ),
+ selectValue = dialog.getContentElement( 'info', 'txtValue' ).getValue();
+
+ removeAllOptions( element );
+
+ for ( var i = 0; i < optionsNames.count(); i++ ) {
+ var oOption = addOption( element, optionsNames.getItem( i ).getValue(), optionsValues.getItem( i ).getValue(), dialog.getParentEditor().document );
+ if ( optionsValues.getItem( i ).getValue() == selectValue ) {
+ oOption.setAttribute( 'selected', 'selected' );
+ oOption.selected = true;
+ }
+ }
+ }
+ }
+ ]
+ },
+ {
+ type: 'vbox',
+ children: [
+ {
+ id: 'txtOptValue',
+ type: 'text',
+ label: editor.lang.forms.select.opValue,
+ style: 'width:115px',
+ setup: function( name, element ) {
+ if ( name == 'clear' )
+ this.setValue( "" );
+ }
+ },
+ {
+ type: 'select',
+ id: 'cmbValue',
+ label: '',
+ size: 5,
+ style: 'width:115px;height:75px',
+ items: [],
+ onChange: function() {
+ var dialog = this.getDialog(),
+ names = dialog.getContentElement( 'info', 'cmbName' ),
+ optName = dialog.getContentElement( 'info', 'txtOptName' ),
+ optValue = dialog.getContentElement( 'info', 'txtOptValue' ),
+ iIndex = getSelectedIndex( this );
+
+ setSelectedIndex( names, iIndex );
+ optName.setValue( names.getValue() );
+ optValue.setValue( this.getValue() );
+ },
+ setup: function( name, element ) {
+ if ( name == 'clear' )
+ removeAllOptions( this );
+ else if ( name == 'option' ) {
+ var oValue = element.getValue();
+ addOption( this, oValue, oValue, this.getDialog().getParentEditor().document );
+ if ( element.getAttribute( 'selected' ) == 'selected' )
+ this.getDialog().getContentElement( 'info', 'txtValue' ).setValue( oValue );
+ }
+ }
+ }
+ ]
+ },
+ {
+ type: 'vbox',
+ padding: 5,
+ children: [
+ {
+ type: 'button',
+ id: 'btnAdd',
+ style: '',
+ label: editor.lang.forms.select.btnAdd,
+ title: editor.lang.forms.select.btnAdd,
+ style: 'width:100%;',
+ onClick: function() {
+ //Add new option.
+ var dialog = this.getDialog(),
+ parentEditor = dialog.getParentEditor(),
+ optName = dialog.getContentElement( 'info', 'txtOptName' ),
+ optValue = dialog.getContentElement( 'info', 'txtOptValue' ),
+ names = dialog.getContentElement( 'info', 'cmbName' ),
+ values = dialog.getContentElement( 'info', 'cmbValue' );
+
+ addOption( names, optName.getValue(), optName.getValue(), dialog.getParentEditor().document );
+ addOption( values, optValue.getValue(), optValue.getValue(), dialog.getParentEditor().document );
+
+ optName.setValue( "" );
+ optValue.setValue( "" );
+ }
+ },
+ {
+ type: 'button',
+ id: 'btnModify',
+ label: editor.lang.forms.select.btnModify,
+ title: editor.lang.forms.select.btnModify,
+ style: 'width:100%;',
+ onClick: function() {
+ //Modify selected option.
+ var dialog = this.getDialog(),
+ optName = dialog.getContentElement( 'info', 'txtOptName' ),
+ optValue = dialog.getContentElement( 'info', 'txtOptValue' ),
+ names = dialog.getContentElement( 'info', 'cmbName' ),
+ values = dialog.getContentElement( 'info', 'cmbValue' ),
+ iIndex = getSelectedIndex( names );
+
+ if ( iIndex >= 0 ) {
+ modifyOption( names, iIndex, optName.getValue(), optName.getValue() );
+ modifyOption( values, iIndex, optValue.getValue(), optValue.getValue() );
+ }
+ }
+ },
+ {
+ type: 'button',
+ id: 'btnUp',
+ style: 'width:100%;',
+ label: editor.lang.forms.select.btnUp,
+ title: editor.lang.forms.select.btnUp,
+ onClick: function() {
+ //Move up.
+ var dialog = this.getDialog(),
+ names = dialog.getContentElement( 'info', 'cmbName' ),
+ values = dialog.getContentElement( 'info', 'cmbValue' );
+
+ changeOptionPosition( names, -1, dialog.getParentEditor().document );
+ changeOptionPosition( values, -1, dialog.getParentEditor().document );
+ }
+ },
+ {
+ type: 'button',
+ id: 'btnDown',
+ style: 'width:100%;',
+ label: editor.lang.forms.select.btnDown,
+ title: editor.lang.forms.select.btnDown,
+ onClick: function() {
+ //Move down.
+ var dialog = this.getDialog(),
+ names = dialog.getContentElement( 'info', 'cmbName' ),
+ values = dialog.getContentElement( 'info', 'cmbValue' );
+
+ changeOptionPosition( names, 1, dialog.getParentEditor().document );
+ changeOptionPosition( values, 1, dialog.getParentEditor().document );
+ }
+ }
+ ]
+ }
+ ]
+ },
+ {
+ type: 'hbox',
+ widths: [ '40%', '20%', '40%' ],
+ children: [
+ {
+ type: 'button',
+ id: 'btnSetValue',
+ label: editor.lang.forms.select.btnSetValue,
+ title: editor.lang.forms.select.btnSetValue,
+ onClick: function() {
+ //Set as default value.
+ var dialog = this.getDialog(),
+ values = dialog.getContentElement( 'info', 'cmbValue' ),
+ txtValue = dialog.getContentElement( 'info', 'txtValue' );
+ txtValue.setValue( values.getValue() );
+ }
+ },
+ {
+ type: 'button',
+ id: 'btnDelete',
+ label: editor.lang.forms.select.btnDelete,
+ title: editor.lang.forms.select.btnDelete,
+ onClick: function() {
+ // Delete option.
+ var dialog = this.getDialog(),
+ names = dialog.getContentElement( 'info', 'cmbName' ),
+ values = dialog.getContentElement( 'info', 'cmbValue' ),
+ optName = dialog.getContentElement( 'info', 'txtOptName' ),
+ optValue = dialog.getContentElement( 'info', 'txtOptValue' );
+
+ removeSelectedOptions( names );
+ removeSelectedOptions( values );
+
+ optName.setValue( "" );
+ optValue.setValue( "" );
+ }
+ },
+ {
+ id: 'chkMulti',
+ type: 'checkbox',
+ label: editor.lang.forms.select.chkMulti,
+ 'default': '',
+ accessKey: 'M',
+ value: "checked",
+ setup: function( name, element ) {
+ if ( name == 'select' )
+ this.setValue( element.getAttribute( 'multiple' ) );
+ if ( CKEDITOR.env.webkit )
+ this.getElement().getParent().setStyle( 'vertical-align', 'middle' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.setAttribute( 'multiple', this.getValue() );
+ else
+ element.removeAttribute( 'multiple' );
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ };
+});
diff --git a/plugins/forms/dialogs/textarea.js b/plugins/forms/dialogs/textarea.js index 0ea4e72..87eb2f3 100644 --- a/plugins/forms/dialogs/textarea.js +++ b/plugins/forms/dialogs/textarea.js @@ -1,6 +1,118 @@ -/*
-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( 'textarea', function( editor ) {
+ return {
+ title: editor.lang.forms.textarea.title,
+ minWidth: 350,
+ minHeight: 220,
+ onShow: function() {
+ delete this.textarea;
-CKEDITOR.dialog.add('textarea',function(a){return{title:a.lang.textarea.title,minWidth:350,minHeight:220,onShow:function(){var c=this;delete c.textarea;var b=c.getParentEditor().getSelection().getSelectedElement();if(b&&b.getName()=='textarea'){c.textarea=b;c.setupContent(b);}},onOk:function(){var b,c=this.textarea,d=!c;if(d){b=this.getParentEditor();c=b.document.createElement('textarea');}this.commitContent(c);if(d)b.insertElement(c);},contents:[{id:'info',label:a.lang.textarea.title,title:a.lang.textarea.title,elements:[{id:'_cke_saved_name',type:'text',label:a.lang.common.name,'default':'',accessKey:'N',setup:function(b){this.setValue(b.data('cke-saved-name')||b.getAttribute('name')||'');},commit:function(b){if(this.getValue())b.data('cke-saved-name',this.getValue());else{b.data('cke-saved-name',false);b.removeAttribute('name');}}},{type:'hbox',widths:['50%','50%'],children:[{id:'cols',type:'text',label:a.lang.textarea.cols,'default':'',accessKey:'C',style:'width:50px',validate:CKEDITOR.dialog.validate.integer(a.lang.common.validateNumberFailed),setup:function(b){var c=b.hasAttribute('cols')&&b.getAttribute('cols');this.setValue(c||'');},commit:function(b){if(this.getValue())b.setAttribute('cols',this.getValue());else b.removeAttribute('cols');}},{id:'rows',type:'text',label:a.lang.textarea.rows,'default':'',accessKey:'R',style:'width:50px',validate:CKEDITOR.dialog.validate.integer(a.lang.common.validateNumberFailed),setup:function(b){var c=b.hasAttribute('rows')&&b.getAttribute('rows');this.setValue(c||'');},commit:function(b){if(this.getValue())b.setAttribute('rows',this.getValue());else b.removeAttribute('rows');}}]},{id:'value',type:'textarea',label:a.lang.textfield.value,'default':'',setup:function(b){this.setValue(b.$.defaultValue);},commit:function(b){b.$.value=b.$.defaultValue=this.getValue();}}]}]};});
+ var element = this.getParentEditor().getSelection().getSelectedElement();
+ if ( element && element.getName() == "textarea" ) {
+ this.textarea = element;
+ this.setupContent( element );
+ }
+ },
+ onOk: function() {
+ var editor,
+ element = this.textarea,
+ isInsertMode = !element;
+
+ if ( isInsertMode ) {
+ editor = this.getParentEditor();
+ element = editor.document.createElement( 'textarea' );
+ }
+ this.commitContent( element );
+
+ if ( isInsertMode )
+ editor.insertElement( element );
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.textarea.title,
+ title: editor.lang.forms.textarea.title,
+ elements: [
+ {
+ id: '_cke_saved_name',
+ type: 'text',
+ label: editor.lang.common.name,
+ 'default': '',
+ accessKey: 'N',
+ setup: function( element ) {
+ this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.data( 'cke-saved-name', this.getValue() );
+ else {
+ element.data( 'cke-saved-name', false );
+ element.removeAttribute( 'name' );
+ }
+ }
+ },
+ {
+ type: 'hbox',
+ widths: [ '50%', '50%' ],
+ children: [
+ {
+ id: 'cols',
+ type: 'text',
+ label: editor.lang.forms.textarea.cols,
+ 'default': '',
+ accessKey: 'C',
+ style: 'width:50px',
+ validate: CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ),
+ setup: function( element ) {
+ var value = element.hasAttribute( 'cols' ) && element.getAttribute( 'cols' );
+ this.setValue( value || '' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.setAttribute( 'cols', this.getValue() );
+ else
+ element.removeAttribute( 'cols' );
+ }
+ },
+ {
+ id: 'rows',
+ type: 'text',
+ label: editor.lang.forms.textarea.rows,
+ 'default': '',
+ accessKey: 'R',
+ style: 'width:50px',
+ validate: CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ),
+ setup: function( element ) {
+ var value = element.hasAttribute( 'rows' ) && element.getAttribute( 'rows' );
+ this.setValue( value || '' );
+ },
+ commit: function( element ) {
+ if ( this.getValue() )
+ element.setAttribute( 'rows', this.getValue() );
+ else
+ element.removeAttribute( 'rows' );
+ }
+ }
+ ]
+ },
+ {
+ id: 'value',
+ type: 'textarea',
+ label: editor.lang.forms.textfield.value,
+ 'default': '',
+ setup: function( element ) {
+ this.setValue( element.$.defaultValue );
+ },
+ commit: function( element ) {
+ element.$.value = element.$.defaultValue = this.getValue();
+ }
+ }
+
+ ]
+ }
+ ]
+ };
+});
diff --git a/plugins/forms/dialogs/textfield.js b/plugins/forms/dialogs/textfield.js index 23ee866..e612f9f 100644 --- a/plugins/forms/dialogs/textfield.js +++ b/plugins/forms/dialogs/textfield.js @@ -1,6 +1,182 @@ -/*
-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( 'textfield', function( editor ) {
+ var autoAttributes = { value:1,size:1,maxLength:1 };
-CKEDITOR.dialog.add('textfield',function(a){var b={value:1,size:1,maxLength:1},c={text:1,password:1};return{title:a.lang.textfield.title,minWidth:350,minHeight:150,onShow:function(){var e=this;delete e.textField;var d=e.getParentEditor().getSelection().getSelectedElement();if(d&&d.getName()=='input'&&(c[d.getAttribute('type')]||!d.getAttribute('type'))){e.textField=d;e.setupContent(d);}},onOk:function(){var d,e=this.textField,f=!e;if(f){d=this.getParentEditor();e=d.document.createElement('input');e.setAttribute('type','text');}if(f)d.insertElement(e);this.commitContent({element:e});},onLoad:function(){var d=function(f){var g=f.hasAttribute(this.id)&&f.getAttribute(this.id);this.setValue(g||'');},e=function(f){var g=f.element,h=this.getValue();if(h)g.setAttribute(this.id,h);else g.removeAttribute(this.id);};this.foreach(function(f){if(b[f.id]){f.setup=d;f.commit=e;}});},contents:[{id:'info',label:a.lang.textfield.title,title:a.lang.textfield.title,elements:[{type:'hbox',widths:['50%','50%'],children:[{id:'_cke_saved_name',type:'text',label:a.lang.textfield.name,'default':'',accessKey:'N',setup:function(d){this.setValue(d.data('cke-saved-name')||d.getAttribute('name')||'');},commit:function(d){var e=d.element;if(this.getValue())e.data('cke-saved-name',this.getValue());else{e.data('cke-saved-name',false);e.removeAttribute('name');}}},{id:'value',type:'text',label:a.lang.textfield.value,'default':'',accessKey:'V'}]},{type:'hbox',widths:['50%','50%'],children:[{id:'size',type:'text',label:a.lang.textfield.charWidth,'default':'',accessKey:'C',style:'width:50px',validate:CKEDITOR.dialog.validate.integer(a.lang.common.validateNumberFailed)},{id:'maxLength',type:'text',label:a.lang.textfield.maxChars,'default':'',accessKey:'M',style:'width:50px',validate:CKEDITOR.dialog.validate.integer(a.lang.common.validateNumberFailed)}],onLoad:function(){if(CKEDITOR.env.ie7Compat)this.getElement().setStyle('zoom','100%');}},{id:'type',type:'select',label:a.lang.textfield.type,'default':'text',accessKey:'M',items:[[a.lang.textfield.typeText,'text'],[a.lang.textfield.typePass,'password']],setup:function(d){this.setValue(d.getAttribute('type'));},commit:function(d){var e=d.element;if(CKEDITOR.env.ie){var f=e.getAttribute('type'),g=this.getValue();if(f!=g){var h=CKEDITOR.dom.element.createFromHtml('<input type="'+g+'"></input>',a.document);e.copyAttributes(h,{type:1});h.replace(e);a.getSelection().selectElement(h);d.element=h;}}else e.setAttribute('type',this.getValue());}}]}]};});
+ var acceptedTypes = { email:1,password:1,search:1,tel:1,text:1,url:1 };
+
+ function autoCommit( data ) {
+ var element = data.element;
+ var value = this.getValue();
+
+ value ? element.setAttribute( this.id, value ) : element.removeAttribute( this.id );
+ }
+
+ function autoSetup( element ) {
+ var value = element.hasAttribute( this.id ) && element.getAttribute( this.id );
+ this.setValue( value || '' );
+ }
+
+ return {
+ title: editor.lang.forms.textfield.title,
+ minWidth: 350,
+ minHeight: 150,
+ onShow: function() {
+ delete this.textField;
+
+ var element = this.getParentEditor().getSelection().getSelectedElement();
+ if ( element && element.getName() == "input" && ( acceptedTypes[ element.getAttribute( 'type' ) ] || !element.getAttribute( 'type' ) ) ) {
+ this.textField = element;
+ this.setupContent( element );
+ }
+ },
+ onOk: function() {
+ var editor = this.getParentEditor(),
+ element = this.textField,
+ isInsertMode = !element;
+
+ if ( isInsertMode ) {
+ element = editor.document.createElement( 'input' );
+ element.setAttribute( 'type', 'text' );
+ }
+
+ var data = { element: element };
+
+ if ( isInsertMode )
+ editor.insertElement( data.element );
+
+ this.commitContent( data );
+
+ // Element might be replaced by commitment.
+ if ( !isInsertMode )
+ editor.getSelection().selectElement( data.element );
+ },
+ onLoad: function() {
+ this.foreach( function( contentObj ) {
+ if ( contentObj.getValue ) {
+ if ( !contentObj.setup )
+ contentObj.setup = autoSetup;
+ if ( !contentObj.commit )
+ contentObj.commit = autoCommit;
+ }
+ });
+ },
+ contents: [
+ {
+ id: 'info',
+ label: editor.lang.forms.textfield.title,
+ title: editor.lang.forms.textfield.title,
+ elements: [
+ {
+ type: 'hbox',
+ widths: [ '50%', '50%' ],
+ children: [
+ {
+ id: '_cke_saved_name',
+ type: 'text',
+ label: editor.lang.forms.textfield.name,
+ 'default': '',
+ accessKey: 'N',
+ setup: function( element ) {
+ this.setValue( element.data( 'cke-saved-name' ) || 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' );
+ }
+ }
+ },
+ {
+ id: 'value',
+ type: 'text',
+ label: editor.lang.forms.textfield.value,
+ 'default': '',
+ accessKey: 'V',
+ commit: function( data ) {
+ if ( CKEDITOR.env.ie && !this.getValue() ) {
+ var element = data.element,
+ fresh = new CKEDITOR.dom.element( 'input', editor.document );
+ element.copyAttributes( fresh, { value:1 } );
+ fresh.replace( element );
+ data.element = fresh;
+ } else
+ autoCommit.call( this, data );
+ }
+ }
+ ]
+ },
+ {
+ type: 'hbox',
+ widths: [ '50%', '50%' ],
+ children: [
+ {
+ id: 'size',
+ type: 'text',
+ label: editor.lang.forms.textfield.charWidth,
+ 'default': '',
+ accessKey: 'C',
+ style: 'width:50px',
+ validate: CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed )
+ },
+ {
+ id: 'maxLength',
+ type: 'text',
+ label: editor.lang.forms.textfield.maxChars,
+ 'default': '',
+ accessKey: 'M',
+ style: 'width:50px',
+ validate: CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed )
+ }
+ ],
+ onLoad: function() {
+ // Repaint the style for IE7 (#6068)
+ if ( CKEDITOR.env.ie7Compat )
+ this.getElement().setStyle( 'zoom', '100%' );
+ }
+ },
+ {
+ id: 'type',
+ type: 'select',
+ label: editor.lang.forms.textfield.type,
+ 'default': 'text',
+ accessKey: 'M',
+ items: [
+ [ editor.lang.forms.textfield.typeEmail, 'email' ],
+ [ editor.lang.forms.textfield.typePass, 'password' ],
+ [ editor.lang.forms.textfield.typeSearch, 'search' ],
+ [ editor.lang.forms.textfield.typeTel, 'tel' ],
+ [ editor.lang.forms.textfield.typeText, 'text' ],
+ [ editor.lang.forms.textfield.typeUrl, 'url' ]
+ ],
+ setup: function( element ) {
+ this.setValue( element.getAttribute( 'type' ) );
+ },
+ commit: function( data ) {
+ var element = data.element;
+
+ if ( CKEDITOR.env.ie ) {
+ var elementType = element.getAttribute( 'type' );
+ var myType = this.getValue();
+
+ if ( elementType != myType ) {
+ var replace = CKEDITOR.dom.element.createFromHtml( '<input type="' + myType + '"></input>', editor.document );
+ element.copyAttributes( replace, { type:1 } );
+ replace.replace( element );
+ data.element = replace;
+ }
+ } else
+ element.setAttribute( 'type', this.getValue() );
+ }
+ }
+ ]
+ }
+ ]
+ };
+});
|
