-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added autocomplete templating feature.
- Loading branch information
1 parent
cd36772
commit 7211a96
Showing
6 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<div id="editor1" ></div> | ||
|
||
<script> | ||
if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) { | ||
bender.ignore(); | ||
} | ||
|
||
CKEDITOR.replace( 'editor1', { | ||
width: 600, | ||
on: { | ||
instanceReady: function( evt ) { | ||
var template = '<strong>{name}</strong>'; | ||
new CKEDITOR.plugins.autocomplete( evt.editor, getTextTestCallback(), dataCallback, null, template ); | ||
} | ||
} | ||
} ); | ||
|
||
function getTextTestCallback() { | ||
return function( range ) { | ||
return CKEDITOR.plugins.textMatch.match( range, matchCallback ); | ||
}; | ||
} | ||
|
||
function matchCallback( text, offset ) { | ||
var left = text.slice( 0, offset ), | ||
match = left.match( new RegExp( '@\\w*$' ) ); | ||
|
||
if ( !match ) { | ||
return null; | ||
} | ||
|
||
return { start: match.index, end: offset }; | ||
} | ||
|
||
function dataCallback( query, range, callback ) { | ||
callback( [ { id: 1, name: '@anna' } ] ); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@bender-tags: 4.10.0, bug, 1987 | ||
@bender-ui: collapsed | ||
@bender-ckeditor-plugins: wysiwygarea, toolbar, basicstyles, autocomplete, textmatch | ||
|
||
1. Focus the editor. | ||
1. Type `@`. | ||
1. Wait until dropdown show up and press `enter`. | ||
|
||
## Expected | ||
|
||
Inserted name is bolded. | ||
|
||
## Unexpected | ||
|
||
Inserted name is a plain text. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<div id="editor1"></div> | ||
|
||
<script> | ||
if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) { | ||
bender.ignore(); | ||
} | ||
|
||
CKEDITOR.replace( 'editor1', { | ||
width: 600, | ||
on: { | ||
instanceReady: function( evt ) { | ||
var template = '<li data-id="{id}">item: <strong>{name}</strong></li>'; | ||
new CKEDITOR.plugins.autocomplete( evt.editor, getTextTestCallback(), dataCallback, template ); | ||
} | ||
} | ||
} ); | ||
|
||
function getTextTestCallback() { | ||
return function( range ) { | ||
return CKEDITOR.plugins.textMatch.match( range, matchCallback ); | ||
}; | ||
} | ||
|
||
function matchCallback( text, offset ) { | ||
var left = text.slice( 0, offset ), | ||
match = left.match( new RegExp( '@\\w*$' ) ); | ||
|
||
if ( !match ) { | ||
return null; | ||
} | ||
|
||
return { | ||
start: match.index, | ||
end: offset | ||
}; | ||
} | ||
|
||
function dataCallback( query, range, callback ) { | ||
callback( [ { | ||
id: 1, | ||
name: 'anna' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'john' | ||
} | ||
] ); | ||
} | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@bender-tags: 4.10.0, bug, 1987 | ||
@bender-ui: collapsed | ||
@bender-ckeditor-plugins: wysiwygarea, toolbar, basicstyles, autocomplete, textmatch | ||
|
||
1. Focus the editor. | ||
1. Type `@`. | ||
|
||
## Expected | ||
|
||
* Dropdown contains **bolded** names. | ||
* All are prefixed with "item: " string. | ||
|
||
## Unexpected | ||
|
||
* Names inside dropdown are plain text. | ||
* Names are not prefixed with "item: " string. |