indvd00m@0
|
1 |
CKEDITOR.dialog.add('crossreference-anchor-dialog', function(editor) {
|
indvd00m@0
|
2 |
|
indvd00m@0
|
3 |
var config = editor.config.crossreference;
|
indvd00m@0
|
4 |
|
indvd00m@0
|
5 |
var generateUUID = function() {
|
indvd00m@0
|
6 |
var d = new Date().getTime();
|
indvd00m@0
|
7 |
if(window.performance && typeof window.performance.now === "function"){
|
indvd00m@0
|
8 |
d += performance.now(); // use high-precision timer if available
|
indvd00m@0
|
9 |
}
|
indvd00m@0
|
10 |
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
indvd00m@0
|
11 |
var r = (d + Math.random()*16)%16 | 0;
|
indvd00m@0
|
12 |
d = Math.floor(d/16);
|
indvd00m@0
|
13 |
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
|
indvd00m@0
|
14 |
});
|
indvd00m@0
|
15 |
return uuid;
|
indvd00m@0
|
16 |
};
|
indvd00m@0
|
17 |
|
indvd00m@0
|
18 |
return {
|
indvd00m@0
|
19 |
title : editor.lang.crossreference.anchor,
|
indvd00m@0
|
20 |
minWidth : 400,
|
indvd00m@0
|
21 |
minHeight : 150,
|
indvd00m@0
|
22 |
|
indvd00m@0
|
23 |
contents : [
|
indvd00m@0
|
24 |
{
|
indvd00m@0
|
25 |
id : 'tab-main',
|
indvd00m@0
|
26 |
label : editor.lang.crossreference.anchor,
|
indvd00m@0
|
27 |
elements : [
|
indvd00m@0
|
28 |
{
|
indvd00m@0
|
29 |
type : 'vbox',
|
indvd00m@0
|
30 |
widths : [ '100%' ],
|
indvd00m@0
|
31 |
children : [
|
indvd00m@0
|
32 |
{
|
indvd00m@0
|
33 |
type : 'html',
|
indvd00m@0
|
34 |
id : 'description',
|
indvd00m@0
|
35 |
html : '<div style="white-space: normal; text-align: justify;">' + editor.lang.crossreference.anchorDescription + '</div>',
|
indvd00m@0
|
36 |
},
|
indvd00m@0
|
37 |
{
|
indvd00m@0
|
38 |
type : 'select',
|
indvd00m@0
|
39 |
id : 'type',
|
indvd00m@0
|
40 |
width: '100%',
|
indvd00m@0
|
41 |
label : editor.lang.crossreference.anchorType,
|
indvd00m@0
|
42 |
items : [],
|
indvd00m@0
|
43 |
required: true,
|
indvd00m@0
|
44 |
items : [['']],
|
indvd00m@0
|
45 |
onLoad: function() {
|
indvd00m@0
|
46 |
this.getInputElement().setStyle('width', '100%');
|
indvd00m@0
|
47 |
for (var typeName in config.types) {
|
indvd00m@0
|
48 |
var type = config.types[typeName];
|
indvd00m@0
|
49 |
var label = type.name;
|
indvd00m@0
|
50 |
if (type.allowCreateAnchors == false)
|
indvd00m@0
|
51 |
continue;
|
indvd00m@0
|
52 |
this.add(label, type.type);
|
indvd00m@0
|
53 |
}
|
indvd00m@0
|
54 |
},
|
indvd00m@0
|
55 |
setup: function(element) {
|
indvd00m@0
|
56 |
this.setValue(element.getAttribute('cross-reference'));
|
indvd00m@0
|
57 |
},
|
indvd00m@0
|
58 |
commit: function(element) {
|
indvd00m@0
|
59 |
element.setAttribute('cross-reference', this.getValue());
|
indvd00m@0
|
60 |
element.setAttribute('cross-anchor', '');
|
indvd00m@0
|
61 |
}
|
indvd00m@0
|
62 |
},
|
indvd00m@0
|
63 |
{
|
indvd00m@0
|
64 |
type : 'text',
|
indvd00m@0
|
65 |
id : 'name',
|
indvd00m@0
|
66 |
width: '100%',
|
indvd00m@0
|
67 |
label : editor.lang.crossreference.anchorName,
|
indvd00m@0
|
68 |
required: true,
|
indvd00m@0
|
69 |
setup: function(element) {
|
indvd00m@0
|
70 |
this.setValue(element.getAttribute('cross-name'));
|
indvd00m@0
|
71 |
},
|
indvd00m@0
|
72 |
commit: function(element) {
|
indvd00m@0
|
73 |
element.setAttribute('cross-name', this.getValue());
|
indvd00m@0
|
74 |
}
|
indvd00m@0
|
75 |
}
|
indvd00m@0
|
76 |
]
|
indvd00m@0
|
77 |
}
|
indvd00m@0
|
78 |
]
|
indvd00m@0
|
79 |
}
|
indvd00m@0
|
80 |
],
|
indvd00m@0
|
81 |
|
indvd00m@0
|
82 |
onLoad : function() {
|
indvd00m@0
|
83 |
|
indvd00m@0
|
84 |
},
|
indvd00m@0
|
85 |
|
indvd00m@0
|
86 |
onShow : function() {
|
indvd00m@0
|
87 |
var selection = editor.getSelection();
|
indvd00m@0
|
88 |
this.element = selection.getStartElement();
|
indvd00m@0
|
89 |
if (this.element)
|
indvd00m@0
|
90 |
this.element = this.element.getAscendant('a', true);
|
indvd00m@0
|
91 |
if (!this.element || this.element.getName() != 'a') {
|
indvd00m@0
|
92 |
this.element = editor.document.createElement('a');
|
indvd00m@0
|
93 |
var guid = generateUUID();
|
indvd00m@0
|
94 |
this.element.setAttribute('cross-guid', guid);
|
indvd00m@0
|
95 |
this.insertMode = true;
|
indvd00m@0
|
96 |
} else {
|
indvd00m@0
|
97 |
this.insertMode = false;
|
indvd00m@0
|
98 |
}
|
indvd00m@0
|
99 |
|
indvd00m@0
|
100 |
if (!this.insertMode)
|
indvd00m@0
|
101 |
this.setupContent(this.element);
|
indvd00m@0
|
102 |
},
|
indvd00m@0
|
103 |
|
indvd00m@0
|
104 |
onOk : function() {
|
indvd00m@0
|
105 |
if (!this.getValueOf('tab-main', 'type'))
|
indvd00m@0
|
106 |
return;
|
indvd00m@0
|
107 |
|
indvd00m@0
|
108 |
this.commitContent(this.element);
|
indvd00m@0
|
109 |
|
indvd00m@0
|
110 |
if (this.insertMode)
|
indvd00m@0
|
111 |
editor.insertElement(this.element);
|
indvd00m@0
|
112 |
|
indvd00m@0
|
113 |
editor.execCommand('update-crossreferences');
|
indvd00m@0
|
114 |
}
|
indvd00m@0
|
115 |
|
indvd00m@0
|
116 |
};
|
indvd00m@0
|
117 |
});
|