ckeditor/plugins/crossreference/dialogs/crossreference-anchor.js
changeset 0 44d330dccc59
child 5 c925ae656709
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ckeditor/plugins/crossreference/dialogs/crossreference-anchor.js	Thu Dec 15 18:10:20 2016 +0300
     1.3 @@ -0,0 +1,117 @@
     1.4 +CKEDITOR.dialog.add('crossreference-anchor-dialog', function(editor) {
     1.5 +	
     1.6 +	var config = editor.config.crossreference;
     1.7 +	
     1.8 +	var generateUUID = function() {
     1.9 +		var d = new Date().getTime();
    1.10 +		if(window.performance && typeof window.performance.now === "function"){
    1.11 +			d += performance.now(); // use high-precision timer if available
    1.12 +		}
    1.13 +		var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    1.14 +			var r = (d + Math.random()*16)%16 | 0;
    1.15 +			d = Math.floor(d/16);
    1.16 +			return (c=='x' ? r : (r&0x3|0x8)).toString(16);
    1.17 +		});
    1.18 +		return uuid;
    1.19 +	};
    1.20 +	
    1.21 +	return {
    1.22 +		title : editor.lang.crossreference.anchor,
    1.23 +		minWidth : 400,
    1.24 +		minHeight : 150,
    1.25 +		
    1.26 +		contents : [ 
    1.27 +			{
    1.28 +				id : 'tab-main',
    1.29 +				label : editor.lang.crossreference.anchor,
    1.30 +				elements : [ 
    1.31 +					{
    1.32 +						type : 'vbox',
    1.33 +						widths : [ '100%' ],
    1.34 +						children : [
    1.35 +							{
    1.36 +								type : 'html',
    1.37 +								id : 'description',
    1.38 +								html : '<div style="white-space: normal; text-align: justify;">' + editor.lang.crossreference.anchorDescription + '</div>',
    1.39 +							},
    1.40 +							{
    1.41 +								type : 'select',
    1.42 +								id : 'type',
    1.43 +								width: '100%',
    1.44 +								label : editor.lang.crossreference.anchorType,
    1.45 +								items : [],
    1.46 +								required: true,
    1.47 +								items : [['']],
    1.48 +								onLoad: function() {
    1.49 +									this.getInputElement().setStyle('width', '100%');
    1.50 +									for (var typeName in config.types) {
    1.51 +										var type = config.types[typeName];
    1.52 +										var label = type.name;
    1.53 +										if (type.allowCreateAnchors == false)
    1.54 +											continue;
    1.55 +										this.add(label, type.type);
    1.56 +									}
    1.57 +								},
    1.58 +								setup: function(element) {
    1.59 +									this.setValue(element.getAttribute('cross-reference'));
    1.60 +								},
    1.61 +								commit: function(element) {
    1.62 +									element.setAttribute('cross-reference', this.getValue());
    1.63 +									element.setAttribute('cross-anchor', '');
    1.64 +								}
    1.65 +							},
    1.66 +							{
    1.67 +								type : 'text',
    1.68 +								id : 'name',
    1.69 +								width: '100%',
    1.70 +								label : editor.lang.crossreference.anchorName,
    1.71 +								required: true,
    1.72 +								setup: function(element) {
    1.73 +									this.setValue(element.getAttribute('cross-name'));
    1.74 +								},
    1.75 +								commit: function(element) {
    1.76 +									element.setAttribute('cross-name', this.getValue());
    1.77 +								}
    1.78 +							}
    1.79 +						]
    1.80 +					} 
    1.81 +				]
    1.82 +			} 
    1.83 +		],
    1.84 +		
    1.85 +		onLoad : function() {
    1.86 +		
    1.87 +		},
    1.88 +		
    1.89 +		onShow : function() {
    1.90 +			var selection = editor.getSelection();
    1.91 +			this.element = selection.getStartElement();
    1.92 +			if (this.element)
    1.93 +				this.element = this.element.getAscendant('a', true);
    1.94 +			if (!this.element || this.element.getName() != 'a') {
    1.95 +				this.element = editor.document.createElement('a');
    1.96 +				var guid = generateUUID();
    1.97 +				this.element.setAttribute('cross-guid', guid);
    1.98 +				this.insertMode = true;
    1.99 +			} else {
   1.100 +				this.insertMode = false;
   1.101 +			}
   1.102 +			
   1.103 +			if (!this.insertMode)
   1.104 +				this.setupContent(this.element);
   1.105 +		},
   1.106 +		
   1.107 +		onOk : function() {
   1.108 +			if (!this.getValueOf('tab-main', 'type'))
   1.109 +				return;
   1.110 +			
   1.111 +			this.commitContent(this.element);
   1.112 +			
   1.113 +			if (this.insertMode)
   1.114 +				editor.insertElement(this.element);
   1.115 +			
   1.116 +			editor.execCommand('update-crossreferences');
   1.117 +		}
   1.118 +		
   1.119 +	};
   1.120 +});