indvd00m@0: CKEDITOR.dialog.add('crossreference-link-dialog', function(editor) { indvd00m@0: indvd00m@0: var config = editor.config.crossreference; indvd00m@0: indvd00m@0: var updateAnchors = function(dialog) { indvd00m@0: dialog.setState(CKEDITOR.DIALOG_STATE_BUSY); indvd00m@0: indvd00m@0: dialog.anchors = []; indvd00m@0: dialog.anchorsByGuid = {}; indvd00m@0: dialog.anchorsGroupNameByGuid = {}; indvd00m@0: indvd00m@0: var type = null; indvd00m@0: var typeName = dialog.getValueOf('tab-main', 'type'); indvd00m@0: if (typeName) indvd00m@0: type = config.types[typeName]; indvd00m@0: indvd00m@0: dialog.setValueOf('tab-main', 'filter', ''); indvd00m@0: indvd00m@0: var anchorSelect = dialog.getContentElement('tab-main', 'anchor'); indvd00m@0: anchorSelect.clear(); indvd00m@0: anchorSelect.add('', ''); indvd00m@0: indvd00m@0: var anchorGroupSelect = dialog.getContentElement('tab-main', 'anchorGroup'); indvd00m@0: anchorGroupSelect.clear(); indvd00m@0: anchorGroupSelect.add('', ''); indvd00m@0: if (type && type.groupAnchors == true) indvd00m@0: anchorGroupSelect.getElement().show(); indvd00m@0: else indvd00m@0: anchorGroupSelect.getElement().hide(); indvd00m@0: indvd00m@0: config.findAnchors(config, editor, type, function(anchors) { indvd00m@0: dialog.anchors = anchors; indvd00m@0: dialog.anchorsByGuid = {}; indvd00m@0: dialog.anchorsGroupNameByGuid = {}; indvd00m@0: indvd00m@0: for (var i = 0; i < anchors.length; i++) { indvd00m@0: var anchor = anchors[i]; indvd00m@0: var guid = anchor.guid; indvd00m@0: var label = anchor.text; indvd00m@0: anchorSelect.add(label, guid); indvd00m@0: indvd00m@0: if (type.groupAnchors == true && anchor.groupGuid) { indvd00m@0: dialog.anchorsGroupNameByGuid[anchor.groupGuid] = anchor.groupName; indvd00m@0: } indvd00m@0: dialog.anchorsByGuid[guid] = anchor; indvd00m@0: } indvd00m@0: indvd00m@0: if (type && type.groupAnchors == true) { indvd00m@0: for (var groupGuid in dialog.anchorsGroupNameByGuid) { indvd00m@0: var groupName = dialog.anchorsGroupNameByGuid[groupGuid]; indvd00m@0: anchorGroupSelect.add(groupName, groupGuid); indvd00m@0: } indvd00m@0: } indvd00m@0: indvd00m@0: // fix   and others indvd00m@0: $('option', anchorSelect.getInputElement().$).each(function() { indvd00m@0: var option = $(this); indvd00m@0: var text = option.text(); indvd00m@0: option.html(text); indvd00m@0: }); indvd00m@0: indvd00m@0: if (!dialog.insertMode) indvd00m@0: anchorSelect.setup(dialog.element); indvd00m@0: indvd00m@0: dialog.setState(CKEDITOR.DIALOG_STATE_IDLE); indvd00m@0: }); indvd00m@0: }; indvd00m@0: indvd00m@0: var filterAnchors = function(dialog) { indvd00m@0: var filter = dialog.getValueOf('tab-main', 'filter'); indvd00m@0: if (filter) indvd00m@0: filter = filter.trim().toLowerCase(); indvd00m@0: else indvd00m@0: filter = ''; indvd00m@0: indvd00m@0: var type = null; indvd00m@0: var typeName = dialog.getValueOf('tab-main', 'type'); indvd00m@0: if (typeName) indvd00m@0: type = config.types[typeName]; indvd00m@0: indvd00m@0: var groupGuid = null; indvd00m@0: if (type && type.groupAnchors == true) indvd00m@0: groupGuid = dialog.getValueOf('tab-main', 'anchorGroup'); indvd00m@0: indvd00m@0: var anchorSelect = dialog.getContentElement('tab-main', 'anchor'); indvd00m@0: var prevValue = anchorSelect.getValue(); indvd00m@0: var selected = null; indvd00m@0: $('option', anchorSelect.getInputElement().$).each(function() { indvd00m@0: var option = $(this); indvd00m@0: var guid = option.val(); indvd00m@0: var anchor = dialog.anchorsByGuid[guid]; indvd00m@0: var text = option.text(); indvd00m@0: indvd00m@0: var matches = filter.length == 0 || text.toLowerCase().indexOf(filter) != -1; indvd00m@0: if (groupGuid) indvd00m@0: matches = matches && anchor && anchor.groupGuid == groupGuid; indvd00m@0: indvd00m@0: if (matches) { indvd00m@0: option.removeAttr('disabled', 'disabled'); indvd00m@0: if (selected == null) indvd00m@0: selected = option.val(); indvd00m@0: else if (guid == prevValue) indvd00m@0: selected = option.val(); indvd00m@0: } else { indvd00m@0: option.attr('disabled', 'disabled'); indvd00m@0: } indvd00m@0: }); indvd00m@0: anchorSelect.setValue(selected); indvd00m@0: }; indvd00m@0: indvd00m@0: return { indvd00m@0: title : editor.lang.crossreference.link, 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.link, 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.linkDescription + '
', 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: 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: this.add(label, type.type); indvd00m@0: } indvd00m@0: }, indvd00m@0: onChange: function() { indvd00m@0: updateAnchors(this.getDialog()); 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-link', ''); indvd00m@0: } indvd00m@0: }, indvd00m@0: { indvd00m@0: type : 'select', indvd00m@0: id : 'anchorGroup', indvd00m@0: width: '100%', indvd00m@0: label : editor.lang.crossreference.anchorGroup, indvd00m@0: required: false, indvd00m@0: items : [['']], indvd00m@0: onLoad: function() { indvd00m@0: this.getInputElement().setStyle('width', '100%'); indvd00m@0: }, indvd00m@0: onChange: function() { indvd00m@0: filterAnchors(this.getDialog()); indvd00m@0: } indvd00m@0: }, indvd00m@0: { indvd00m@0: type : 'text', indvd00m@0: id : 'filter', indvd00m@0: width: '100%', indvd00m@0: label : editor.lang.crossreference.linkFilter, indvd00m@0: onKeyUp : function() { indvd00m@0: filterAnchors(this.getDialog()); indvd00m@0: } indvd00m@0: }, indvd00m@0: { indvd00m@0: type : 'select', indvd00m@0: id : 'anchor', indvd00m@0: width: '100%', indvd00m@0: label : editor.lang.crossreference.anchor, indvd00m@0: required: true, indvd00m@0: items : [['']], indvd00m@0: onLoad: function() { indvd00m@0: this.getInputElement().setStyle('width', '100%'); indvd00m@0: }, indvd00m@0: setup: function(element) { indvd00m@0: this.setValue(element.getAttribute('cross-guid')); indvd00m@0: }, indvd00m@0: commit: function(element) { indvd00m@0: element.setAttribute('cross-guid', 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); indvd00m@0: if (!this.element || this.element.getName() != 'a') { indvd00m@0: this.element = editor.document.createElement('a'); indvd00m@0: this.element.setAttribute('cross-link', ''); indvd00m@0: this.insertMode = true; indvd00m@0: } else { indvd00m@0: this.insertMode = false; indvd00m@0: } indvd00m@0: indvd00m@0: if (this.insertMode) indvd00m@0: updateAnchors(this); indvd00m@0: 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: if (!this.getValueOf('tab-main', 'anchor')) 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: });