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