Ticket #5654: 5654.patch

File 5654.patch, 6.9 KB (added by Sa'ar Zac Elias, 14 years ago)
  • _source/lang/en.js

     
    755755        {
    756756                ltr : 'Text direction from left to right',
    757757                rtl : 'Text direction from right to left'
     758        },
     759
     760        placeholder :
     761        {
     762                title           : 'Placeholder Properties',
     763                toolbar         : 'Create Placeholder',
     764                text            : 'Placeholder Text',
     765                edit            : 'Edit Placeholder',
     766                textMissing     : 'The placeholder text field must contain a string.'
    758767        }
    759768};
  • _source/plugins/placeholder/dialogs/placeholder.js

     
     1/*
     2 * Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
     3 * For licensing, see LICENSE.html or http://ckeditor.com/license
     4 */
     5
     6(function()
     7{
     8        function placeHolderDialog( editor, isEdit )
     9        {
     10
     11                var lang = editor.lang.placeholder,
     12                        generalLabel = editor.lang.common.generalTab;
     13                return {
     14                        title : lang.title,
     15                        minWidth : 300,
     16                        minHeight : 80,
     17                        contents :
     18                        [
     19                                {
     20                                        id : 'info',
     21                                        label : generalLabel,
     22                                        title : generalLabel,
     23                                        elements :
     24                                        [
     25                                                {
     26                                                        id : 'text',
     27                                                        type : 'text',
     28                                                        style : 'width: 100%;',
     29                                                        label : lang.text,
     30                                                        'default' : '',
     31                                                        required : true,
     32                                                        validate : CKEDITOR.dialog.validate.notEmpty( lang.textMissing ),
     33                                                        setup : function( element )
     34                                                        {
     35                                                                if ( isEdit )
     36                                                                        this.setValue( element.getText().slice( 2, -2 ) );
     37                                                        },
     38                                                        commit : function( element )
     39                                                        {
     40                                                                var text = '[[' + this.getValue() + ']]';
     41                                                                // The place holder must be recreated.
     42                                                                CKEDITOR.plugins.placeholder.createPlaceHolder( editor, element, text );
     43                                                        }
     44                                                }
     45                                        ]
     46                                }
     47                        ],
     48                        onShow : function()
     49                        {
     50                                this._element = isEdit && editor.getSelection().getRanges()[0].getTouchedStartNode();
     51                                this.setupContent( this._element );
     52                        },
     53                        onOk : function()
     54                        {
     55                                this.commitContent( this._element );
     56                                delete this._element;
     57                        }
     58                };
     59        }
     60
     61        CKEDITOR.dialog.add( 'createplaceholder', function( editor )
     62                {
     63                        return placeHolderDialog( editor );
     64                });
     65        CKEDITOR.dialog.add( 'editplaceholder', function( editor )
     66                {
     67                        return placeHolderDialog( editor, 1 );
     68                });
     69} )();
  • _source/plugins/placeholder/plugin.js

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: _source\plugins\placeholder\placeholder.gif
    ___________________________________________________________________
    Added: svn:mime-type
       + application/octet-stream
    
     
     1/*
     2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6/**
     7 * @fileOverview The "placeholder" plugin.
     8 *
     9 */
     10
     11(function()
     12{
     13        var placeHolderRegex = /^\[\[[^\]]+\]\]$/,
     14                placeHolderReplace = /\[\[[^\]]+\]\]/g;
     15        CKEDITOR.plugins.add( 'placeholder',
     16        {
     17                requires : [ 'dialog' ],
     18
     19                init : function( editor )
     20                {
     21                        var lang = editor.lang.placeholder;
     22
     23                        editor.addCommand( 'createplaceholder', new CKEDITOR.dialogCommand( 'createplaceholder' ) );
     24                        editor.addCommand( 'editplaceholder', new CKEDITOR.dialogCommand( 'editplaceholder' ) );
     25
     26                        editor.ui.addButton( 'CreatePlaceHolder',
     27                        {
     28                                label : lang.toolbar,
     29                                command :'createplaceholder',
     30                                icon : this.path + '/placeholder.gif'
     31                        });
     32
     33                        if ( editor.addMenuItems )
     34                        {
     35                                editor.addMenuGroup( 'placeholder', 20 );
     36                                editor.addMenuItems(
     37                                        {
     38                                                editplaceholder :
     39                                                {
     40                                                        label : lang.edit,
     41                                                        command : 'editplaceholder',
     42                                                        group : 'placeholder',
     43                                                        order : 1
     44                                                }
     45                                        } );
     46
     47                                if ( editor.contextMenu )
     48                                {
     49                                        editor.contextMenu.addListener( function( element, selection )
     50                                                {
     51                                                        if ( !element || !element.hasAttribute( '_cke_placeholder' ) )
     52                                                                return null;
     53
     54                                                        return { editplaceholder : CKEDITOR.TRISTATE_OFF };
     55                                                } );
     56                                }
     57                        }
     58
     59                        editor.addCss(
     60                                '.cke_placeholder' +
     61                                '{' +
     62                                        'background-color: #ffff00;' +
     63                                        ( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) +
     64                                '}'
     65                        );
     66
     67                        editor.on( 'contentDom', function()
     68                                {
     69                                        editor.document.getBody().on( 'resizestart', function( evt )
     70                                                {
     71                                                        if ( editor.getSelection().getSelectedElement().hasAttribute( '_cke_placeholder' ) )
     72                                                                evt.data.preventDefault();
     73                                                });
     74                                });
     75
     76                        CKEDITOR.dialog.add( 'createplaceholder', this.path + 'dialogs/placeholder.js' );
     77                        CKEDITOR.dialog.add( 'editplaceholder', this.path + 'dialogs/placeholder.js' );
     78                },
     79                afterInit : function( editor )
     80                {
     81                        var dataProcessor = editor.dataProcessor,
     82                                dataFilter = dataProcessor && dataProcessor.dataFilter;
     83                                htmlFilter = dataProcessor && dataProcessor.htmlFilter;
     84
     85                        if ( dataFilter )
     86                        {
     87                                dataFilter.addRules(
     88                                {
     89                                        text : function( text )
     90                                        {
     91                                                return text.replace( placeHolderReplace, function( match )
     92                                                        {
     93                                                                return CKEDITOR.plugins.placeholder.createPlaceHolder( editor, null, match, 1 );
     94                                                        });
     95                                        }
     96                                });
     97                        }
     98
     99                        if ( htmlFilter )
     100                        {
     101                                htmlFilter.addRules(
     102                                {
     103                                        elements :
     104                                        {
     105                                                'span' : function( element )
     106                                                {
     107                                                        if ( element.attributes && element.attributes._cke_placeholder )
     108                                                                delete element.name;
     109                                                }
     110                                        }
     111                                });
     112                        }
     113                }
     114        });
     115})();
     116
     117CKEDITOR.plugins.placeholder =
     118{
     119        createPlaceHolder : function( editor, oldElement, text, isGet )
     120        {
     121                var element = new CKEDITOR.dom.element( 'span', editor.document );
     122                element.setAttributes(
     123                        {
     124                                contentEditable : 'false',
     125                                _cke_placeholder        : 1,
     126                                'class'         : 'cke_placeholder'
     127                        }
     128                );
     129
     130                text && element.setText( text );
     131
     132                if ( isGet )
     133                        return element.getOuterHtml();
     134
     135                if ( oldElement )
     136                {
     137                        if ( CKEDITOR.env.ie )
     138                        {
     139                                element.insertAfter( oldElement );
     140                                // Some time is required for IE before the element is removed.
     141                                setTimeout( function()
     142                                        {
     143                                                oldElement.remove();
     144                                                element.focus();
     145                                        }, 10 );
     146                        }
     147                        else
     148                                element.replace( oldElement );
     149                }
     150                else
     151                        editor.insertElement( element );
     152        }
     153};
     154 No newline at end of file
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy