Ticket #5654: 5654_4.patch

File 5654_4.patch, 10.2 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/placeholder/lang/en.js

     
     1/*
     2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6CKEDITOR.plugins.setLang( 'placeholder', 'en',
     7{
     8        placeholder :
     9        {
     10                title           : 'Placeholder Properties',
     11                toolbar         : 'Create Placeholder',
     12                text            : 'Placeholder Text',
     13                edit            : 'Edit Placeholder',
     14                textMissing     : 'The placeholder must contain text.'
     15        }
     16});
  • _samples/placeholder.html

     
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<!--
     3Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
     4For licensing, see LICENSE.html or http://ckeditor.com/license
     5-->
     6<html xmlns="http://www.w3.org/1999/xhtml">
     7<head>
     8        <title>Placeholder Plugin - CKEditor Sample</title>
     9        <meta content="text/html; charset=utf-8" http-equiv="content-type" />
     10        <!-- CKReleaser %REMOVE_LINE%
     11        <script type="text/javascript" src="../ckeditor.js"></script>
     12        CKReleaser %REMOVE_START% -->
     13        <script type="text/javascript" src="../ckeditor_source.js"></script>
     14        <!-- CKReleaser %REMOVE_END% -->
     15        <script src="sample.js" type="text/javascript"></script>
     16        <link href="sample.css" rel="stylesheet" type="text/css" />
     17</head>
     18<body>
     19        <h1>
     20                CKEditor Sample
     21        </h1>
     22        <!-- This <div> holds alert messages to be display in the sample page. -->
     23        <div id="alerts">
     24                <noscript>
     25                        <p>
     26                                <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
     27                                support, like yours, you should still see the contents (HTML data) and you should
     28                                be able to edit it normally, without a rich editor interface.
     29                        </p>
     30                </noscript>
     31        </div>
     32        <form action="sample_posteddata.php" method="post">
     33                <p>
     34                        In this sample the Placeholder plugin is available.<br />
     35                        It replaces text in the format of <code>[[text]]</code> to uneditable sections, and lets the user edit them and create new ones using a dialog.</p>
     36                <p>
     37                        <label for="editor1">
     38                                With default configuration:</label><br />
     39                        <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is a [[placeholder]]. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;. &lt;/p&gt;</textarea>
     40                        <script type="text/javascript">
     41                        //<![CDATA[
     42
     43                                CKEDITOR.replace( 'editor1', {
     44                                        extraPlugins : 'placeholder',
     45                                        toolbar : [ [ 'Source', 'CreatePlaceholder' ] ]
     46                                });
     47
     48                        //]]>
     49                        </script>
     50                </p>
     51                <p>
     52                        <input type="submit" value="Submit" />
     53                </p>
     54        </form>
     55        <div id="footer">
     56                <hr />
     57                <p>
     58                        CKEditor - The text editor for Internet - <a href="http://ckeditor.com/">http://ckeditor.com</a>
     59                </p>
     60                <p id="copy">
     61                        Copyright &copy; 2003-2010, <a href="http://cksource.com/">CKSource</a> - Frederico
     62                        Knabben. All rights reserved.
     63                </p>
     64        </div>
     65</body>
     66</html>
  • _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 placeholder 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} )();
  • _samples/index.html

     
    4242                <li><a href="output_xhtml.html">Output XHTML</a></li>
    4343                <li><a href="output_html.html">Output HTML</a></li>
    4444                <li><a href="autogrow.html">AutoGrow plugin</a></li>
     45                <li><a href="placeholder.html">Placeholder plugin</a></li>
    4546        </ul>
    4647        <div id="footer">
    4748                <hr />
  • _source/plugins/placeholder/plugin.js

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