diff --git a/CHANGES.md b/CHANGES.md index c06429c2624..ebf1136d63c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ New Features: Fixed Issues: * [#10612](http://dev.ckeditor.com/ticket/10612): Internet Explorer 11 compatibility issues. +* [#10862](http://dev.ckeditor.com/ticket/10862): Placeholder plugin was rewritten as a widget in order to fix it. * [#10831](http://dev.ckeditor.com/ticket/10831): Image2: Merged `image2inline` and `image2block` into `image2` widget. * [#10835](http://dev.ckeditor.com/ticket/10835): Image2: Improved visibility of the resize handler. * [#10836](http://dev.ckeditor.com/ticket/10836): Image2: Preserve custom mouse cursor while resizing the image. diff --git a/plugins/placeholder/dialogs/placeholder.js b/plugins/placeholder/dialogs/placeholder.js index 2789246cee6..a1cc82acccb 100644 --- a/plugins/placeholder/dialogs/placeholder.js +++ b/plugins/placeholder/dialogs/placeholder.js @@ -1,61 +1,49 @@ -/** + +/** * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ -(function() { - function placeholderDialog( editor, isEdit ) { +/** + * @fileOverview Definition for placeholder plugin dialog. + * + */ + +'use strict'; + +CKEDITOR.dialog.add( 'placeholder', function( editor ) { + var lang = editor.lang.placeholder, + generalLabel = editor.lang.common.generalTab, + validNameRegex = /^[^\[\]\<\>]+$/; - var lang = editor.lang.placeholder, - generalLabel = editor.lang.common.generalTab; - return { - title: lang.title, - minWidth: 300, - minHeight: 80, - contents: [ - { + return { + title: lang.title, + minWidth: 300, + minHeight: 80, + contents: [ + { id: 'info', label: generalLabel, title: generalLabel, elements: [ + // Dialog window UI elements. { - id: 'text', - type: 'text', - style: 'width: 100%;', - label: lang.text, - 'default': '', - required: true, - validate: CKEDITOR.dialog.validate.notEmpty( lang.textMissing ), - setup: function( element ) { - if ( isEdit ) - this.setValue( element.getText().slice( 2, -2 ) ); - }, - commit: function( element ) { - var text = '[[' + this.getValue() + ']]'; - // The placeholder must be recreated. - CKEDITOR.plugins.placeholder.createPlaceholder( editor, element, text ); + id: 'name', + type: 'text', + style: 'width: 100%;', + label: lang.name, + 'default': '', + required: true, + validate: CKEDITOR.dialog.validate.regex( validNameRegex, lang.invalidName ), + setup: function( widget ) { + this.setValue( widget.data.name ); + }, + commit: function( widget ) { + widget.setData( 'name', this.getValue() ); + } } - } ] } - ], - onShow: function() { - if ( isEdit ) - this._element = CKEDITOR.plugins.placeholder.getSelectedPlaceHolder( editor ); - - this.setupContent( this._element ); - }, - onOk: function() { - this.commitContent( this._element ); - delete this._element; - } - }; - } - - CKEDITOR.dialog.add( 'createplaceholder', function( editor ) { - return placeholderDialog( editor ); - }); - CKEDITOR.dialog.add( 'editplaceholder', function( editor ) { - return placeholderDialog( editor, 1 ); - }); -})(); + ] + }; +} ); \ No newline at end of file diff --git a/plugins/placeholder/lang/_translationstatus.txt b/plugins/placeholder/lang/_translationstatus.txt deleted file mode 100644 index 24d039b4548..00000000000 --- a/plugins/placeholder/lang/_translationstatus.txt +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. -For licensing, see LICENSE.md or http://ckeditor.com/license - -bg.js Found: 5 Missing: 0 -cs.js Found: 5 Missing: 0 -cy.js Found: 5 Missing: 0 -da.js Found: 5 Missing: 0 -de.js Found: 5 Missing: 0 -el.js Found: 5 Missing: 0 -eo.js Found: 5 Missing: 0 -et.js Found: 5 Missing: 0 -fa.js Found: 5 Missing: 0 -fi.js Found: 5 Missing: 0 -fr.js Found: 5 Missing: 0 -he.js Found: 5 Missing: 0 -hr.js Found: 5 Missing: 0 -it.js Found: 5 Missing: 0 -nb.js Found: 5 Missing: 0 -nl.js Found: 5 Missing: 0 -no.js Found: 5 Missing: 0 -pl.js Found: 5 Missing: 0 -tr.js Found: 5 Missing: 0 -ug.js Found: 5 Missing: 0 -uk.js Found: 5 Missing: 0 -vi.js Found: 3 Missing: 2 -zh-cn.js Found: 5 Missing: 0 diff --git a/plugins/placeholder/lang/bg.js b/plugins/placeholder/lang/bg.js deleted file mode 100644 index 992014ca350..00000000000 --- a/plugins/placeholder/lang/bg.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'bg', { - title: 'Настройки на контейнера', - toolbar: 'Нов контейнер', - text: 'Текст за контейнера', - edit: 'Промяна на контейнер', - textMissing: 'Контейнера трябва да съдържа текст.' -}); diff --git a/plugins/placeholder/lang/cs.js b/plugins/placeholder/lang/cs.js deleted file mode 100644 index 195f1cf3f17..00000000000 --- a/plugins/placeholder/lang/cs.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'cs', { - title: 'Vlastnosti vyhrazeného prostoru', - toolbar: 'Vytvořit vyhrazený prostor', - text: 'Vyhrazený text', - edit: 'Upravit vyhrazený prostor', - textMissing: 'Vyhrazený prostor musí obsahovat text.' -}); diff --git a/plugins/placeholder/lang/cy.js b/plugins/placeholder/lang/cy.js deleted file mode 100644 index 151ce561572..00000000000 --- a/plugins/placeholder/lang/cy.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'cy', { - title: 'Priodweddau\'r Daliwr Geiriau', - toolbar: 'Creu Daliwr Geiriau', - text: 'Testun y Daliwr Geiriau', - edit: 'Golygu\'r Dailwr Geiriau', - textMissing: 'Mae\'n rhaid i\'r daliwr geiriau gynnwys testun.' -}); diff --git a/plugins/placeholder/lang/da.js b/plugins/placeholder/lang/da.js deleted file mode 100644 index 55c85c1015a..00000000000 --- a/plugins/placeholder/lang/da.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'da', { - title: 'Egenskaber for pladsholder', - toolbar: 'Opret pladsholder', - text: 'Tekst til pladsholder', - edit: 'Rediger pladsholder', - textMissing: 'Pladsholder skal indeholde tekst' -}); diff --git a/plugins/placeholder/lang/de.js b/plugins/placeholder/lang/de.js deleted file mode 100644 index 661f992bfd4..00000000000 --- a/plugins/placeholder/lang/de.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'de', { - title: 'Platzhalter Einstellungen', - toolbar: 'Platzhalter erstellen', - text: 'Platzhalter Text', - edit: 'Platzhalter bearbeiten', - textMissing: 'Der Platzhalter muss einen Text beinhalten.' -}); diff --git a/plugins/placeholder/lang/el.js b/plugins/placeholder/lang/el.js deleted file mode 100644 index b5f5bbee926..00000000000 --- a/plugins/placeholder/lang/el.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'el', { - title: 'Ιδιότητες Υποκατάστατου Κειμένου', - toolbar: 'Δημιουργία Υποκατάσταστου Κειμένου', - text: 'Υποκαθιστόμενο Κείμενο', - edit: 'Επεξεργασία Υποκατάσταστου Κειμένου', - textMissing: 'Πρέπει να υπάρχει υποκαθιστόμενο κείμενο.' -}); diff --git a/plugins/placeholder/lang/en.js b/plugins/placeholder/lang/en.js index 61b8185c304..b3217ff3b00 100644 --- a/plugins/placeholder/lang/en.js +++ b/plugins/placeholder/lang/en.js @@ -1,12 +1,11 @@ -/** +/** * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ CKEDITOR.plugins.setLang( 'placeholder', 'en', { title: 'Placeholder Properties', - toolbar: 'Create Placeholder', - text: 'Placeholder Text', - edit: 'Edit Placeholder', - textMissing: 'The placeholder must contain text.' + toolbar: 'Placeholder', + name: 'Placeholder Name', + invalidName: 'The placeholder can not be empty and can not contain any of following characters: [, ], <, >' }); diff --git a/plugins/placeholder/lang/eo.js b/plugins/placeholder/lang/eo.js deleted file mode 100644 index 6a383e4c1b6..00000000000 --- a/plugins/placeholder/lang/eo.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'eo', { - title: 'Atributoj de la rezervita spaco', - toolbar: 'Krei la rezervitan spacon', - text: 'Texto de la rezervita spaco', - edit: 'Modifi la rezervitan spacon', - textMissing: 'La rezervita spaco devas enteni tekston.' -}); diff --git a/plugins/placeholder/lang/et.js b/plugins/placeholder/lang/et.js deleted file mode 100644 index aa730b9bdd5..00000000000 --- a/plugins/placeholder/lang/et.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'et', { - title: 'Kohahoidja omadused', - toolbar: 'Kohahoidja loomine', - text: 'Kohahoidja tekst', - edit: 'Kohahoidja muutmine', - textMissing: 'Kohahoidja peab sisaldama teksti.' -}); diff --git a/plugins/placeholder/lang/fa.js b/plugins/placeholder/lang/fa.js deleted file mode 100644 index d5dea48daa9..00000000000 --- a/plugins/placeholder/lang/fa.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'fa', { - title: 'ویژگی‌های محل نگهداری', - toolbar: 'ایجاد یک محل نگهداری', - text: 'متن محل نگهداری', - edit: 'ویرایش محل نگهداری', - textMissing: 'محل نگهداری باید محتوی متن باشد.' -}); diff --git a/plugins/placeholder/lang/fi.js b/plugins/placeholder/lang/fi.js deleted file mode 100644 index 03a58765d17..00000000000 --- a/plugins/placeholder/lang/fi.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'fi', { - title: 'Paikkamerkin ominaisuudet', - toolbar: 'Luo paikkamerkki', - text: 'Paikkamerkin teksti', - edit: 'Muokkaa paikkamerkkiä', - textMissing: 'Paikkamerkin täytyy sisältää tekstiä' -}); diff --git a/plugins/placeholder/lang/fr.js b/plugins/placeholder/lang/fr.js deleted file mode 100644 index 8664bc13136..00000000000 --- a/plugins/placeholder/lang/fr.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'fr', { - title: 'Propriétés de l\'Espace réservé', - toolbar: 'Créer l\'Espace réservé', - text: 'Texte de l\'Espace réservé', - edit: 'Modifier l\'Espace réservé', - textMissing: 'L\'Espace réservé doit contenir du texte.' -}); diff --git a/plugins/placeholder/lang/he.js b/plugins/placeholder/lang/he.js deleted file mode 100644 index ea444ba3d3f..00000000000 --- a/plugins/placeholder/lang/he.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'he', { - title: 'מאפייני שומר מקום', - toolbar: 'צור שומר מקום', - text: 'תוכן שומר המקום', - edit: 'ערוך שומר מקום', - textMissing: 'שומר המקום חייב להכיל טקסט.' -}); diff --git a/plugins/placeholder/lang/hr.js b/plugins/placeholder/lang/hr.js deleted file mode 100644 index 2d344ba17bf..00000000000 --- a/plugins/placeholder/lang/hr.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'hr', { - title: 'Svojstva rezerviranog mjesta', - toolbar: 'Napravi rezervirano mjesto', - text: 'Tekst rezerviranog mjesta', - edit: 'Uredi rezervirano mjesto', - textMissing: 'Rezervirano mjesto mora sadržavati tekst.' -}); diff --git a/plugins/placeholder/lang/it.js b/plugins/placeholder/lang/it.js deleted file mode 100644 index 42fc0807d8d..00000000000 --- a/plugins/placeholder/lang/it.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'it', { - title: 'Proprietà segnaposto', - toolbar: 'Crea segnaposto', - text: 'Testo segnaposto', - edit: 'Modifica segnaposto', - textMissing: 'Il segnaposto deve contenere del testo.' -}); diff --git a/plugins/placeholder/lang/nb.js b/plugins/placeholder/lang/nb.js deleted file mode 100644 index 7a6cd69188c..00000000000 --- a/plugins/placeholder/lang/nb.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'nb', { - title: 'Egenskaper for plassholder', - toolbar: 'Opprett plassholder', - text: 'Tekst for plassholder', - edit: 'Rediger plassholder', - textMissing: 'Plassholderen må inneholde tekst.' -}); diff --git a/plugins/placeholder/lang/nl.js b/plugins/placeholder/lang/nl.js deleted file mode 100644 index a31ae63f7ed..00000000000 --- a/plugins/placeholder/lang/nl.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'nl', { - title: 'Eigenschappen placeholder', - toolbar: 'Placeholder aanmaken', - text: 'Placeholder tekst', - edit: 'Placeholder wijzigen', - textMissing: 'De placeholder moet tekst bevatten.' -}); diff --git a/plugins/placeholder/lang/no.js b/plugins/placeholder/lang/no.js deleted file mode 100644 index b9f02e4d10e..00000000000 --- a/plugins/placeholder/lang/no.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'no', { - title: 'Egenskaper for plassholder', - toolbar: 'Opprett plassholder', - text: 'Tekst for plassholder', - edit: 'Rediger plassholder', - textMissing: 'Plassholderen må inneholde tekst.' -}); diff --git a/plugins/placeholder/lang/pl.js b/plugins/placeholder/lang/pl.js deleted file mode 100644 index 215daa5f694..00000000000 --- a/plugins/placeholder/lang/pl.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'pl', { - title: 'Właściwości wypełniacza', - toolbar: 'Utwórz wypełniacz', - text: 'Tekst wypełnienia', - edit: 'Edytuj wypełnienie', - textMissing: 'Wypełnienie musi posiadać jakiś tekst.' -}); diff --git a/plugins/placeholder/lang/tr.js b/plugins/placeholder/lang/tr.js deleted file mode 100644 index 162ee60c3a8..00000000000 --- a/plugins/placeholder/lang/tr.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'tr', { - title: 'Yer tutucu özellikleri', - toolbar: 'Yer tutucu oluşturun', - text: 'Yer tutucu metini', - edit: 'Yer tutucuyu düzenle', - textMissing: 'Yer tutucu metin içermelidir.' -}); diff --git a/plugins/placeholder/lang/ug.js b/plugins/placeholder/lang/ug.js deleted file mode 100644 index 2a18d1abb4a..00000000000 --- a/plugins/placeholder/lang/ug.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'ug', { - title: 'ئورۇن بەلگە خاسلىقى', - toolbar: 'ئورۇن بەلگە قۇر', - text: 'ئورۇن بەلگە تېكىستى', - edit: 'ئورۇن بەلگە تەھرىر', - textMissing: 'ئورۇن بەلگىسىدە چوقۇم تېكىست بولۇشى لازىم' -}); diff --git a/plugins/placeholder/lang/uk.js b/plugins/placeholder/lang/uk.js deleted file mode 100644 index 3b94d646390..00000000000 --- a/plugins/placeholder/lang/uk.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'uk', { - title: 'Налаштування Заповнювача', - toolbar: 'Створити Заповнювач', - text: 'Текст Заповнювача', - edit: 'Редагувати Заповнювач', - textMissing: 'Заповнювач повинен містити текст.' -}); diff --git a/plugins/placeholder/lang/vi.js b/plugins/placeholder/lang/vi.js deleted file mode 100644 index 0abc1de8c2c..00000000000 --- a/plugins/placeholder/lang/vi.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'vi', { - title: 'Thuộc tính đặt chỗ', - toolbar: 'Tạo đặt chỗ', - text: 'Văn bản đặt chỗ', - edit: 'Edit Placeholder', // MISSING - textMissing: 'The placeholder must contain text.' // MISSING -}); diff --git a/plugins/placeholder/lang/zh-cn.js b/plugins/placeholder/lang/zh-cn.js deleted file mode 100644 index 2d226a7ca55..00000000000 --- a/plugins/placeholder/lang/zh-cn.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or http://ckeditor.com/license - */ - -CKEDITOR.plugins.setLang( 'placeholder', 'zh-cn', { - title: '占位符属性', - toolbar: '创建占位符', - text: '占位符文字', - edit: '编辑占位符', - textMissing: '占位符必需包含有文字' -}); diff --git a/plugins/placeholder/plugin.js b/plugins/placeholder/plugin.js index f49ccb02171..62f71fa7215 100644 --- a/plugins/placeholder/plugin.js +++ b/plugins/placeholder/plugin.js @@ -1,4 +1,5 @@ -/** + +/** * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ @@ -8,136 +9,71 @@ * */ +'use strict'; + (function() { - var placeholderReplaceRegex = /\[\[[^\]]+\]\]/g; CKEDITOR.plugins.add( 'placeholder', { - requires: 'dialog', - lang: 'en,bg,cs,cy,da,de,el,eo,et,fa,fi,fr,he,hr,it,ku,nb,nl,no,pl,tr,ug,uk,vi,zh-cn', // %REMOVE_LINE_CORE% + requires: 'widget,dialog', + lang: 'en', // %REMOVE_LINE_CORE% icons: 'placeholder', // %REMOVE_LINE_CORE% hidpi: true, // %REMOVE_LINE_CORE% + onLoad: function() { - CKEDITOR.addCss( '.cke_placeholder' + - '{' + - 'background-color: #ffff00;' + - ( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) + - '}' - ); + // Register styles for placeholder widget frame. + CKEDITOR.addCss( '.cke_placeholder{background-color:#ff0}' ); }, - init: function( editor ) { - var lang = editor.lang.placeholder; - - editor.addCommand( 'createplaceholder', new CKEDITOR.dialogCommand( 'createplaceholder' ) ); - editor.addCommand( 'editplaceholder', new CKEDITOR.dialogCommand( 'editplaceholder' ) ); - editor.ui.addButton && editor.ui.addButton( 'CreatePlaceholder', { - label: lang.toolbar, - command: 'createplaceholder', - toolbar: 'insert,5', - icon: 'placeholder' - }); - - if ( editor.addMenuItems ) { - editor.addMenuGroup( 'placeholder', 20 ); - editor.addMenuItems({ - editplaceholder: { - label: lang.edit, - command: 'editplaceholder', - group: 'placeholder', - order: 1, - icon: 'placeholder' - } - }); - - if ( editor.contextMenu ) { - editor.contextMenu.addListener( function( element, selection ) { - if ( !element || !element.data( 'cke-placeholder' ) ) - return null; - - return { editplaceholder: CKEDITOR.TRISTATE_OFF }; - }); + init: function( editor ) { + // Register dialog. + CKEDITOR.dialog.add( 'placeholder', this.path + 'dialogs/placeholder.js' ); + + // Put ur init code here. + editor.widgets.add( 'placeholder', { + // Widget code. + button: editor.lang.placeholder.toolbar, + dialog: 'placeholder', + // We need to have wrapping element, otherwise there are issues in + // add dialog. + template: '[[]]', + + downcast: function() { + return new CKEDITOR.htmlParser.text( '[[' + this.data.name + ']]' ); + }, + + init: function() { + // Note that placeholder markup characters are stripped for the name. + this.setData( 'name', this.element.getText().slice( 2, -2 ) ); + }, + + data: function( data ) { + this.element.setText( '[[' + this.data.name + ']]' ); } - } - - editor.on( 'doubleclick', function( evt ) { - if ( CKEDITOR.plugins.placeholder.getSelectedPlaceHolder( editor ) ) - evt.data.dialog = 'editplaceholder'; - }); - - editor.on( 'contentDom', function() { - editor.editable().on( 'resizestart', function( evt ) { - if ( editor.getSelection().getSelectedElement().data( 'cke-placeholder' ) ) - evt.data.preventDefault(); - }); - }); - - CKEDITOR.dialog.add( 'createplaceholder', this.path + 'dialogs/placeholder.js' ); - CKEDITOR.dialog.add( 'editplaceholder', this.path + 'dialogs/placeholder.js' ); + } ); }, - afterInit: function( editor ) { - var dataProcessor = editor.dataProcessor, - dataFilter = dataProcessor && dataProcessor.dataFilter, - htmlFilter = dataProcessor && dataProcessor.htmlFilter; - - if ( dataFilter ) { - dataFilter.addRules({ - text: function( text ) { - return text.replace( placeholderReplaceRegex, function( match ) { - return CKEDITOR.plugins.placeholder.createPlaceholder( editor, null, match, 1 ); - }); - } - }); - } - if ( htmlFilter ) { - htmlFilter.addRules({ - elements: { - 'span': function( element ) { - if ( element.attributes && element.attributes[ 'data-cke-placeholder' ] ) - delete element.name; - } - } - }); - } + afterInit: function( editor ) { + var placeholderReplaceRegex = /\[\[([^\[\]])+\]\]/g; + + editor.dataProcessor.dataFilter.addRules( { + text: function( text ) { + return text.replace( placeholderReplaceRegex, function( match ) { + // Creating widget code. + var widgetWrapper = null, + innerElement = new CKEDITOR.htmlParser.element( 'span', { + 'class': 'cke_placeholder' + } ); + + // Adds placeholder identifier as innertext. + innerElement.add( new CKEDITOR.htmlParser.text( match ) ); + widgetWrapper = editor.widgets.wrapElement( innerElement, 'placeholder' ); + + // Return outerhtml of widget wrapper so it will be placed + // as replacement. + return widgetWrapper.getOuterHtml(); + } ); + } + } ); } - }); -})(); + } ); -CKEDITOR.plugins.placeholder = { - createPlaceholder: function( editor, oldElement, text, isGet ) { - var element = new CKEDITOR.dom.element( 'span', editor.document ); - element.setAttributes({ - contentEditable: 'false', - 'data-cke-placeholder': 1, - 'class': 'cke_placeholder' - }); - - text && element.setText( text ); - - if ( isGet ) - return element.getOuterHtml(); - - if ( oldElement ) { - if ( CKEDITOR.env.ie ) { - element.insertAfter( oldElement ); - // Some time is required for IE before the element is removed. - setTimeout( function() { - oldElement.remove(); - element.focus(); - }, 10 ); - } else - element.replace( oldElement ); - } else - editor.insertElement( element ); - - return null; - }, - - getSelectedPlaceHolder: function( editor ) { - var range = editor.getSelection().getRanges()[ 0 ]; - range.shrink( CKEDITOR.SHRINK_TEXT ); - var node = range.startContainer; - while ( node && !( node.type == CKEDITOR.NODE_ELEMENT && node.data( 'cke-placeholder' ) ) ) - node = node.getParent(); - return node; - } -}; +})(); diff --git a/plugins/placeholder/samples/placeholder.html b/plugins/placeholder/samples/placeholder.html index cf542432e49..f4bf2860c69 100644 --- a/plugins/placeholder/samples/placeholder.html +++ b/plugins/placeholder/samples/placeholder.html @@ -49,7 +49,7 @@

CKEDITOR.replace( 'editor1', { extraPlugins: 'placeholder', - toolbar: [ [ 'Source', 'CreatePlaceholder' ] ] + toolbar: [ [ 'Source', 'Bold' ], [ 'Placeholder' ] ] });