indvd00m@0: CKEDITOR.dialog.add('crossreference-anchor-dialog', function(editor) {
indvd00m@0:
indvd00m@0: var config = editor.config.crossreference;
indvd00m@0:
indvd00m@0: var generateUUID = function() {
indvd00m@0: var d = new Date().getTime();
indvd00m@0: if(window.performance && typeof window.performance.now === "function"){
indvd00m@0: d += performance.now(); // use high-precision timer if available
indvd00m@0: }
indvd00m@0: var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
indvd00m@0: var r = (d + Math.random()*16)%16 | 0;
indvd00m@0: d = Math.floor(d/16);
indvd00m@0: return (c=='x' ? r : (r&0x3|0x8)).toString(16);
indvd00m@0: });
indvd00m@0: return uuid;
indvd00m@0: };
indvd00m@0:
indvd00m@0: return {
indvd00m@0: title : editor.lang.crossreference.anchor,
indvd00m@0: minWidth : 400,
indvd00m@0: minHeight : 150,
indvd00m@0:
indvd00m@0: contents : [
indvd00m@0: {
indvd00m@0: id : 'tab-main',
indvd00m@0: label : editor.lang.crossreference.anchor,
indvd00m@0: elements : [
indvd00m@0: {
indvd00m@0: type : 'vbox',
indvd00m@0: widths : [ '100%' ],
indvd00m@0: children : [
indvd00m@0: {
indvd00m@0: type : 'html',
indvd00m@0: id : 'description',
indvd00m@0: html : '
' + editor.lang.crossreference.anchorDescription + '
',
indvd00m@0: },
indvd00m@0: {
indvd00m@0: type : 'select',
indvd00m@0: id : 'type',
indvd00m@0: width: '100%',
indvd00m@0: label : editor.lang.crossreference.anchorType,
indvd00m@0: items : [],
indvd00m@0: required: true,
indvd00m@0: items : [['']],
indvd00m@0: onLoad: function() {
indvd00m@0: this.getInputElement().setStyle('width', '100%');
indvd00m@0: for (var typeName in config.types) {
indvd00m@0: var type = config.types[typeName];
indvd00m@0: var label = type.name;
indvd00m@0: if (type.allowCreateAnchors == false)
indvd00m@0: continue;
indvd00m@0: this.add(label, type.type);
indvd00m@0: }
indvd00m@0: },
indvd00m@0: setup: function(element) {
indvd00m@0: this.setValue(element.getAttribute('cross-reference'));
indvd00m@0: },
indvd00m@0: commit: function(element) {
indvd00m@0: element.setAttribute('cross-reference', this.getValue());
indvd00m@0: element.setAttribute('cross-anchor', '');
indvd00m@0: }
indvd00m@0: },
indvd00m@0: {
indvd00m@0: type : 'text',
indvd00m@0: id : 'name',
indvd00m@0: width: '100%',
indvd00m@0: label : editor.lang.crossreference.anchorName,
indvd00m@0: required: true,
indvd00m@0: setup: function(element) {
indvd00m@0: this.setValue(element.getAttribute('cross-name'));
indvd00m@0: },
indvd00m@0: commit: function(element) {
indvd00m@0: element.setAttribute('cross-name', this.getValue());
indvd00m@0: }
indvd00m@0: }
indvd00m@0: ]
indvd00m@0: }
indvd00m@0: ]
indvd00m@0: }
indvd00m@0: ],
indvd00m@0:
indvd00m@0: onLoad : function() {
indvd00m@0:
indvd00m@0: },
indvd00m@0:
indvd00m@0: onShow : function() {
indvd00m@0: var selection = editor.getSelection();
indvd00m@0: this.element = selection.getStartElement();
indvd00m@0: if (this.element)
indvd00m@0: this.element = this.element.getAscendant('a', true);
indvdum@5: if (!this.element || this.element.getName() != 'a' || !this.element.hasAttribute('cross-anchor')) {
indvd00m@0: this.element = editor.document.createElement('a');
indvd00m@0: var guid = generateUUID();
indvd00m@0: this.element.setAttribute('cross-guid', guid);
indvd00m@0: this.insertMode = true;
indvd00m@0: } else {
indvd00m@0: this.insertMode = false;
indvd00m@0: }
indvd00m@0:
indvdum@5: if (this.insertMode)
indvdum@5: this.setValueOf('tab-main', 'name', selection.getSelectedText().trim());
indvdum@5: else
indvd00m@0: this.setupContent(this.element);
indvd00m@0: },
indvd00m@0:
indvd00m@0: onOk : function() {
indvd00m@0: if (!this.getValueOf('tab-main', 'type'))
indvd00m@0: return;
indvd00m@0:
indvd00m@0: this.commitContent(this.element);
indvd00m@0:
indvd00m@0: if (this.insertMode)
indvd00m@0: editor.insertElement(this.element);
indvd00m@0:
indvd00m@0: editor.execCommand('update-crossreferences');
indvd00m@0: }
indvd00m@0:
indvd00m@0: };
indvd00m@0: });