ckeditor/plugins/crossreference/README.md
author indvdum (gotoindvdum[at]gmail[dot]com)
Wed, 21 Dec 2016 17:20:19 +0300
changeset 5 c925ae656709
parent 2 467e24fbc60e
permissions -rw-r--r--
Update crossreference plugin
indvd00m@0
     1
CrossReference Plugin for CKEditor 4
indvd00m@0
     2
=================================
indvd00m@0
     3
indvd00m@0
     4
Adds cross references links with optional auto-numeration for chapters, images, tables and references. Other types of references can be defined in config.
indvd00m@0
     5
indvd00m@2
     6
## Online demo
indvd00m@2
     7
indvdum@5
     8
Try the plugin demo at <http://indvd00m.com/crossreference-demo/>.
indvdum@5
     9
indvdum@5
    10
## CKEditor plugin page
indvdum@5
    11
indvdum@5
    12
http://ckeditor.com/addon/crossreference
indvdum@5
    13
indvdum@5
    14
## Requirements
indvdum@5
    15
indvdum@5
    16
CrossReference Plugin require CKEditor 4.5+ version and dependent from plugins: dialog, notification.
indvdum@5
    17
indvdum@5
    18
## Installation
indvdum@5
    19
indvdum@5
    20
 1. Download the plugin: https://github.com/indvd00m/crossreference/releases.
indvdum@5
    21
 
indvdum@5
    22
 2. Extract (decompress) the downloaded file into the plugins folder of your
indvdum@5
    23
	CKEditor installation.
indvdum@5
    24
	Example: http://example.com/ckeditor/plugins/crossreference
indvdum@5
    25
	
indvdum@5
    26
 3. Enable the plugin by using the extraPlugins configuration setting.
indvdum@5
    27
	Example: CKEDITOR.config.extraPlugins = 'crossreference';
indvd00m@2
    28
indvd00m@0
    29
## Description
indvd00m@0
    30
indvd00m@0
    31
Two main conceptions - anchor and link to anchor. There are 4 type of references defined by default: chapter, image, table, reference. Example of anchor of type `image` in raw html:
indvd00m@0
    32
```html
indvd00m@0
    33
<a 
indvd00m@0
    34
	class="cross-reference cross-anchor" 
indvd00m@0
    35
	cross-reference="image" 
indvd00m@0
    36
	cross-anchor="" 
indvd00m@0
    37
	cross-guid="7d24373b-0756-481d-bf97-5a17ffdf3a28" 
indvd00m@0
    38
	cross-name="Experimental result" 
indvd00m@0
    39
	cross-number="1" 
indvd00m@0
    40
	name="image-7d24373b-0756-481d-bf97-5a17ffdf3a28"
indvd00m@0
    41
	>
indvd00m@0
    42
		Fig. 1. Experimental result.
indvd00m@0
    43
</a>
indvd00m@0
    44
```
indvd00m@0
    45
Example of link to this anchor in raw html:
indvd00m@0
    46
```html
indvd00m@0
    47
<a 
indvd00m@0
    48
	class="cross-reference cross-link" 
indvd00m@0
    49
	cross-reference="image" 
indvd00m@0
    50
	cross-link="" 
indvd00m@0
    51
	cross-guid="7d24373b-0756-481d-bf97-5a17ffdf3a28" 
indvd00m@0
    52
	cross-name="Experimental result" 
indvd00m@0
    53
	cross-number="1" 
indvd00m@0
    54
	href="#image-7d24373b-0756-481d-bf97-5a17ffdf3a28" 
indvd00m@0
    55
	title="Fig. 1. Experimental result."
indvd00m@0
    56
	>
indvd00m@0
    57
		1
indvd00m@0
    58
</a>
indvd00m@0
    59
```
indvd00m@0
    60
After every inserting of anchor or links to anchor all references will be updated to be a concerted. Or you can manually update cross-references by selecting option in menu (for example after deleting of anchors).
indvd00m@0
    61
indvd00m@0
    62
## Configuration
indvd00m@0
    63
indvd00m@0
    64
You can switch which types is active by config option `config.crossreference.activeTypes = ['type1', 'type2']`. You can define other types also.
indvd00m@0
    65
indvd00m@0
    66
### Default config:
indvd00m@0
    67
indvd00m@0
    68
```javascript
indvd00m@0
    69
{
indvd00m@0
    70
	activeTypes: ['chapter', 'image', 'table', 'reference'],
indvd00m@0
    71
	overrideTypes: false,
indvd00m@0
    72
	types: {
indvd00m@0
    73
		chapter: {
indvd00m@0
    74
			name: 'Chapter',
indvd00m@0
    75
			anchorTextTemplate: '${number}. ${name}.',
indvd00m@0
    76
			linkTextTemplate: '${number}',
indvd00m@0
    77
			numeration: {
indvd00m@0
    78
				enabled: true,
indvd00m@0
    79
				firstNumber: '1',
indvd00m@0
    80
				increase: function(number) {
indvd00m@0
    81
					var n = parseInt(number);
indvd00m@0
    82
					return ++n;
indvd00m@0
    83
				}
indvd00m@0
    84
			},
indvd00m@0
    85
			anchorsProvider: 'default',
indvd00m@0
    86
			allowCreateAnchors: true,
indvd00m@0
    87
			groupAnchors: false
indvd00m@0
    88
		},
indvd00m@0
    89
		image: {
indvd00m@0
    90
			name: 'Figure',
indvd00m@0
    91
			anchorTextTemplate: 'Fig. ${number}. ${name}.',
indvd00m@0
    92
			linkTextTemplate: '${number}',
indvd00m@0
    93
			numeration: {
indvd00m@0
    94
				enabled: true,
indvd00m@0
    95
				firstNumber: '1',
indvd00m@0
    96
				increase: function(number) {
indvd00m@0
    97
					var n = parseInt(number);
indvd00m@0
    98
					return ++n;
indvd00m@0
    99
				}
indvd00m@0
   100
			},
indvd00m@0
   101
			anchorsProvider: 'default',
indvd00m@0
   102
			allowCreateAnchors: true,
indvd00m@0
   103
			groupAnchors: false
indvd00m@0
   104
		},
indvd00m@0
   105
		table: {
indvd00m@0
   106
			name: 'Table',
indvd00m@0
   107
			anchorTextTemplate: 'Table ${number}. ${name}.',
indvd00m@0
   108
			linkTextTemplate: '${number}',
indvd00m@0
   109
			numeration: {
indvd00m@0
   110
				enabled: true,
indvd00m@0
   111
				firstNumber: '1',
indvd00m@0
   112
				increase: function(number) {
indvd00m@0
   113
					var n = parseInt(number);
indvd00m@0
   114
					return ++n;
indvd00m@0
   115
				}
indvd00m@0
   116
			},
indvd00m@0
   117
			anchorsProvider: 'default',
indvd00m@0
   118
			allowCreateAnchors: true,
indvd00m@0
   119
			groupAnchors: false
indvd00m@0
   120
		},
indvd00m@0
   121
		reference: {
indvd00m@0
   122
			name: 'Reference',
indvd00m@0
   123
			anchorTextTemplate: '[${number}] ${name}.',
indvd00m@0
   124
			linkTextTemplate: '[${number}]',
indvd00m@0
   125
			numeration: {
indvd00m@0
   126
				enabled: true,
indvd00m@0
   127
				firstNumber: '1',
indvd00m@0
   128
				increase: function(number) {
indvd00m@0
   129
					var n = parseInt(number);
indvd00m@0
   130
					return ++n;
indvd00m@0
   131
				}
indvd00m@0
   132
			},
indvd00m@0
   133
			anchorsProvider: 'default',
indvd00m@0
   134
			allowCreateAnchors: true,
indvd00m@0
   135
			groupAnchors: false
indvd00m@0
   136
		}
indvd00m@0
   137
	}
indvd00m@0
   138
}
indvd00m@0
   139
```
indvd00m@0
   140
| Property | Description | Type | Default value |
indvd00m@0
   141
| --- | --- | --- | --- |
indvd00m@0
   142
| `activeTypes` | Which type of anchors would be activated. | Array | `['chapter', 'image', 'table', 'reference']` |
indvd00m@0
   143
| `overrideTypes` | If you define your own types, enabling this option lead to mixing of your types with types from default config which not yet defined in your config. | Boolean | false |
indvdum@5
   144
| `types` | Types definition. | Object | see [Example of type definition](https://github.com/indvd00m/crossreference#example-of-type-definition) section|
indvd00m@0
   145
indvd00m@0
   146
### Example of type definition
indvd00m@0
   147
indvd00m@0
   148
```javascript
indvd00m@0
   149
image: {
indvd00m@0
   150
	name: 'Figure',
indvd00m@0
   151
	anchorTextTemplate: 'Fig. ${number}. ${name}.',
indvd00m@0
   152
	linkTextTemplate: '${number}',
indvd00m@0
   153
	numeration: {
indvd00m@0
   154
		enabled: true,
indvd00m@0
   155
		firstNumber: '1',
indvd00m@0
   156
		increase: function(number) {
indvd00m@0
   157
			var n = parseInt(number);
indvd00m@0
   158
			return ++n;
indvd00m@0
   159
		}
indvd00m@0
   160
	},
indvd00m@0
   161
	anchorsProvider: 'default',
indvd00m@0
   162
	allowCreateAnchors: true,
indvd00m@0
   163
	groupAnchors: false
indvd00m@0
   164
}
indvd00m@0
   165
```
indvd00m@0
   166
| Property | Description | Type | Required |
indvd00m@0
   167
| --- | --- | --- | --- |
indvd00m@0
   168
| `name` | Type name. | String | Yes |
indvd00m@0
   169
| `anchorTextTemplate` | Template for anchor text. This text will be put in `a` tag. You can use variables in format `${variableName}`. Variables is a properties of an anchor object (see [Example of an anchor object](https://github.com/indvd00m/crossreference#example-of-an-anchor-object) section). | String | No |
indvd00m@0
   170
| `linkTextTemplate` | Template for link text. This text will be put in `a` tag. You can use variables in format `${variableName}`. Variables is a properties of an anchor object (see [Example of an anchor object](https://github.com/indvd00m/crossreference#example-of-an-anchor-object) section). | String | No |
indvd00m@2
   171
| `numeration` | Definition of type numeration. See [Example of a numeration definition](https://github.com/indvd00m/crossreference#example-of-a-numeration-definition) section. | Object | No |
indvdum@5
   172
| `anchorsProvider` | See [Example of type with anchors provider](https://github.com/indvd00m/crossreference#example-of-type-with-anchors-provider) section. | String `'default'` or function | No |
indvd00m@0
   173
| `allowCreateAnchors` | Can user create anchors of this type in anchors dialog. | Boolean | No |
indvd00m@0
   174
| `groupAnchors` | If `true`, anchors can be filtered by group in link dialog. | Boolean | No |
indvd00m@0
   175
indvd00m@0
   176
### Example of a numeration definition
indvd00m@0
   177
indvd00m@0
   178
```javascript
indvd00m@0
   179
numeration: {
indvd00m@0
   180
	enabled: true,
indvd00m@0
   181
	firstNumber: '1',
indvd00m@0
   182
	increase: function(number) {
indvd00m@0
   183
		var n = parseInt(number);
indvd00m@0
   184
		return ++n;
indvd00m@0
   185
	}
indvd00m@0
   186
}
indvd00m@0
   187
```
indvd00m@0
   188
| Property | Description | Type |
indvd00m@0
   189
| --- | --- | --- |
indvd00m@0
   190
| `enabled` | Enabling/disabling numeration of anchors. | Boolean |
indvd00m@0
   191
| `firstNumber` | First number. For example you may define `firstNumber` as `I` for Roman numerals. | String |
indvd00m@0
   192
| `increase` | Function which must return number (as string) which is next after `number` argument (string). | Function |
indvd00m@0
   193
indvd00m@0
   194
### Example of an anchor object
indvd00m@0
   195
indvd00m@0
   196
JSON object:
indvd00m@0
   197
indvd00m@0
   198
```javascript
indvd00m@0
   199
{
indvd00m@0
   200
	type: 'image',
indvd00m@0
   201
	guid: '7d24373b-0756-481d-bf97-5a17ffdf3a28',
indvd00m@0
   202
	name: 'Experimental result',
indvd00m@0
   203
	number: '1',
indvd00m@0
   204
	text: 'Fig. 1. Experimental result.',
indvd00m@0
   205
	groupName: 'Group name',
indvd00m@0
   206
	groupGuid: '6c848dff-cde3-421f-b926-695c8de37d80'
indvd00m@0
   207
}
indvd00m@0
   208
```
indvd00m@0
   209
| Property | Description | Type | Required |
indvd00m@0
   210
| --- | --- | --- | --- |
indvd00m@0
   211
| `type` | Type name of this anchor (`config.types.typeName`). | String | Yes |
indvd00m@0
   212
| `guid` | Unique guid of this anchor. | String | Yes |
indvd00m@0
   213
| `name` | Name of this anchor. | String | Yes |
indvd00m@0
   214
| `number` | Number of this anchor (if type contains numeration definition). | String | Depends of type |
indvd00m@0
   215
| `text` | Text of this anchor. Optional property because of text will generated by `type.anchorTextTemplate` template. | String | No |
indvd00m@0
   216
| `groupName` | Name of anchor group. | String | No |
indvd00m@0
   217
| `groupGuid` | Unique guid of anchor group. | String | No |
indvd00m@0
   218
indvd00m@0
   219
### Example of type with anchors provider
indvd00m@0
   220
indvd00m@0
   221
You can define your own anchors provider. By default plugin search anchors in content of editor and use this anchors for links. But if you want refer to anchors outside of editor you can define another type of anchor with `anchorsProvider` function.
indvd00m@0
   222
indvd00m@0
   223
```javascript
indvd00m@0
   224
myType: {
indvd00m@0
   225
	name: 'My type',
indvd00m@0
   226
	anchorTextTemplate: '${name}',
indvd00m@0
   227
	linkTextTemplate: '${name}',
indvd00m@0
   228
	anchorsProvider: function(callback, editorAnchors, type, editor) {
indvd00m@0
   229
		var anchors = [];
indvd00m@0
   230
		anchors.push({
indvd00m@0
   231
			type: 'myType',
indvd00m@0
   232
			guid: '7d24373b-0756-481d-bf97-5a17ffdf3a28',
indvd00m@0
   233
			name: 'Anchor name',
indvd00m@0
   234
			number: '1'
indvd00m@0
   235
		});
indvd00m@0
   236
		callback(anchors);
indvd00m@0
   237
	},
indvd00m@0
   238
	allowCreateAnchors: false,
indvd00m@0
   239
	groupAnchors: false
indvd00m@0
   240
},
indvd00m@0
   241
```
indvd00m@0
   242
indvd00m@0
   243
`anchorsProvider` method attributes:
indvd00m@0
   244
indvd00m@0
   245
| Name | Description | Type |
indvd00m@0
   246
| --- | --- | --- |
indvd00m@0
   247
| `callback` | Callback method which must be called with arrays of anchors as argument. | Function |
indvd00m@0
   248
| `editorAnchors` | Anchors of this type (`myType` in this case) which already contains in editor. You can merge this anchors with your own anchors if need. | Array |
indvd00m@0
   249
| `type` | Type definition (Object `myType` in this case). | Object |
indvd00m@0
   250
| `editor` | Instance of ckeditor. | Object |
indvd00m@0
   251
indvd00m@0
   252
indvd00m@0
   253
## Roadmap
indvd00m@0
   254
indvd00m@0
   255
See https://github.com/indvd00m/crossreference/issues.
indvd00m@0
   256
indvd00m@0
   257
## Icons:
indvd00m@2
   258
indvd00m@2
   259
https://icons8.com/web-app/21792/unicast
indvd00m@2
   260
indvd00m@0
   261
https://icons8.com/web-app/15117/anchor
indvd00m@0
   262
indvd00m@0
   263
https://icons8.com/web-app/38051/link
indvd00m@0
   264
indvd00m@0
   265
https://icons8.com/web-app/21100/refresh
indvd00m@0
   266
indvd00m@0
   267
## License & Author
indvd00m@0
   268
indvd00m@0
   269
CrossReference Plugin is distributed under GPL/LGPL/MPL. For license terms, see LICENSE.md.
indvd00m@0
   270
indvd00m@0
   271
CrossReference Plugin is written by David E. Veliev.