Ticket #5654: 5654_5.patch

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